ExtPopupMenuWnd.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:735k
- return;
- if( bAdvOperation && ( GetSite().GetAnimated() == NULL ) )
- {
- m_AnimationType = __AT_CONTENT_DISPLAY;
- HWND hWndOwn = m_hWnd;
- _StartAnimation();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- _tipWnd.Hide();
- }
- CExtPopupMenuTipWnd::e_tip_style_t CExtPopupMenuWnd::_CoolTipGetStyle() const
- {
- ASSERT_VALID( this );
- if( _IsPalette() )
- return g_eTtsPaletteMenu;
- return g_eTtsClassicMenu;
- }
- CMap < CExtPopupMenuWnd *, CExtPopupMenuWnd *, INT, INT > CExtPopupMenuWnd::ItemFocusTracker_t::g_map;
- CExtPopupMenuWnd::ItemFocusTracker_t::ItemFocusTracker_t( const CExtPopupMenuWnd & _Popup )
- : m_Popup( _Popup )
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- FocusChangingRegister();
- }
- CExtPopupMenuWnd::ItemFocusTracker_t::ItemFocusTracker_t( const CExtPopupMenuWnd * pPopup )
- : m_Popup( *pPopup )
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- FocusChangingRegister();
- }
- CExtPopupMenuWnd::ItemFocusTracker_t::~ItemFocusTracker_t()
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- FocusChangingUnRegister();
- }
- void CExtPopupMenuWnd::ItemFocusTracker_t::FocusChangingRegister()
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- INT i = 0;
- if( g_map.Lookup(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) ),
- i
- )
- )
- {
- ASSERT( i >= 1 );
- i++;
- }
- else
- i = 1;
- g_map.SetAt(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) ),
- i
- );
- }
- void CExtPopupMenuWnd::ItemFocusTracker_t::FocusChangingUnRegister()
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- INT i = 0;
- if( ! g_map.Lookup(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) ),
- i
- )
- )
- return;
- ASSERT( i >= 1 );
- i--;
- if( i == 0 )
- g_map.RemoveKey(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) )
- );
- else
- g_map.SetAt(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) ),
- i
- );
- }
- bool CExtPopupMenuWnd::ItemFocusTracker_t::FocusChangingIsRegistered()
- {
- ASSERT_VALID( ( &(m_Popup) ) );
- INT i = 0;
- if( g_map.Lookup(
- const_cast < CExtPopupMenuWnd * > ( &(m_Popup) ),
- i
- )
- )
- {
- ASSERT( i >= 1 );
- return true;
- }
- else
- return false;
- }
- bool CExtPopupMenuWnd::ItemFocusTracker_t::FocusChangingIsInProgress( const CExtPopupMenuWnd * pPopup )
- {
- if( pPopup == NULL )
- return false;
- ASSERT_VALID( pPopup );
- INT i = 0;
- if( ! g_map.Lookup(
- const_cast < CExtPopupMenuWnd * > ( pPopup ),
- i
- )
- )
- return false;
- ASSERT( i >= 1 );
- return true;
- }
- bool CExtPopupMenuWnd::_ItemFocusChangingIsInProgress() const
- {
- ASSERT_VALID( this );
- if( _CancelingGet() )
- return false;
- bool bRetVal = CExtPopupMenuWnd::ItemFocusTracker_t::FocusChangingIsInProgress( this );
- return bRetVal;
- }
- void CExtPopupMenuWnd::_ItemFocusCancel(
- BOOL bRepaint,
- BOOL bCancelTip, // = TRUE
- BOOL bDelayHiding // = FALSE
- )
- {
- ASSERT_VALID( this );
- if( !_FindCustomizeMode() )
- {
- HWND hWndOwn = m_hWnd;
- if( bCancelTip )
- _CoolTipHide();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- if( m_nCurIndex != IDX_NOTHING )
- {
- CRect rcCurrItem;
- _GetItemRect( m_nCurIndex, rcCurrItem );
- if( ! rcCurrItem.IsRectEmpty() )
- InvalidateRect( &rcCurrItem );
- }
- ItemFocusTracker_t _ift( this );
- if( m_nCurIndex < 0 )
- {
- m_nCurIndex = IDX_NOTHING;
- } // if( m_nCurIndex < 0 )
- else
- {
- ASSERT( m_nCurIndex < m_items_all.GetSize() );
- MENUITEMDATA & mi = ItemGetInfo(m_nCurIndex);
- if( mi.IsInplaceEdit() )
- {
- mi.SetTempSelectedInplaceEditText( NULL );
- CWnd * pWndInplace = mi.GetInplaceEditPtr();
- if( pWndInplace != NULL )
- {
- ASSERT_VALID( pWndInplace );
- ASSERT( pWndInplace->GetSafeHwnd() != NULL && (::IsWindow(pWndInplace->GetSafeHwnd())) );
- if( (pWndInplace->GetStyle() & WS_VISIBLE) != 0 )
- pWndInplace->ShowWindow( SW_HIDE );
- } // if( pWndInplace != NULL )
- }
- mi.SetSelected( false );
- ITEMCOVERINGNOTIFICATON _icn(
- this,
- NULL,
- ITEMCOVERINGNOTIFICATON::__EICN_CANCEL,
- m_nCurIndex
- );
- m_nCurIndex = IDX_NOTHING;
- HWND hWndOwn = m_hWnd;
- _icn.Notify();
- m_bSuspendTips = _icn.m_bSuspendTips;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- if( mi.IsPopup() )
- {
- CExtPopupMenuWnd * pPopup = mi.GetPopup();
- ASSERT_VALID( pPopup );
- if( bDelayHiding && (! pPopup->m_bDelayedHiding ) && pPopup->GetSafeHwnd() != NULL )
- {
- pPopup->m_bDelayedHiding = true;
- ASSERT( g_nTimeDelayedHiding > 0 );
- pPopup->SetTimer( ID_TIMER_ITEM_HIDE_DELAY, g_nTimeDelayedHiding, NULL );
- }
- else
- {
- INT nSaved = pPopup->m_nFadeOutAnimationStepCount;
- pPopup->m_nFadeOutAnimationStepCount = -1;
- pPopup->_OnCancelMode();
- pPopup->m_nFadeOutAnimationStepCount = nSaved;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- }
- } // else from if( m_nCurIndex < 0 )
- // update status bar message
- CWnd * pWndOwner = GetOwner();
- if( pWndOwner != NULL )
- CExtControlBar::stat_SetMessageString( pWndOwner );
- if( bRepaint && ::IsWindowVisible(GetSafeHwnd()) )
- {
- CClientDC dc( this );
- _DoPaint( dc );
- }
- _ift.FocusChangingUnRegister();
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- _KeyTipsShow( true );
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- KillTimer( ID_TIMER_AUTO_EXPAND );
- }
- bool CExtPopupMenuWnd::_CanStartLevelTracking()
- {
- ASSERT_VALID( this );
- return true;
- }
- bool CExtPopupMenuWnd::_OnMouseWheel(
- WPARAM wParam,
- LPARAM lParam,
- bool & bNoEat
- )
- {
- ASSERT_VALID( this );
- if( _IsResizingMode() )
- {
- bNoEat = false;
- return true;
- }
- TranslateMouseWheelEventData_t _td( this, wParam, lParam, bNoEat );
- if( _td.Notify() )
- {
- bNoEat = _td.m_bNoEat;
- return true;
- }
- return true;
- }
- const UINT CExtPopupMenuWnd::g_nMsgInstantiatePopupMenu =
- ::RegisterWindowMessage(
- _T("CExtPopupMenuWnd::g_nMsgInstantiatePopupMenu")
- );
- CExtPopupMenuWnd::INSTANTIATEPOPUPMENUNOTIFICATION::INSTANTIATEPOPUPMENUNOTIFICATION(
- CRuntimeClass * pMenuRTC,
- CObject * pQuerySrc,
- LPARAM lParam
- )
- : m_pMenuRTC( pMenuRTC )
- , m_pQuerySrc( pQuerySrc )
- , m_lParam( lParam )
- , m_pCreatedPopupMenuInstance( NULL )
- {
- }
- void CExtPopupMenuWnd::INSTANTIATEPOPUPMENUNOTIFICATION::Notify( HWND hWndNotifyTarget )
- {
- ASSERT( hWndNotifyTarget != NULL && ::IsWindow( hWndNotifyTarget ) );
- ::SendMessage( hWndNotifyTarget, CExtPopupMenuWnd::g_nMsgInstantiatePopupMenu, (*this), 0L );
- }
- CExtPopupMenuWnd::INSTANTIATEPOPUPMENUNOTIFICATION::
- operator WPARAM()
- {
- return WPARAM( this );
- }
- CExtPopupMenuWnd::INSTANTIATEPOPUPMENUNOTIFICATION &
- CExtPopupMenuWnd::INSTANTIATEPOPUPMENUNOTIFICATION::
- FromWPARAM( WPARAM wParam )
- {
- INSTANTIATEPOPUPMENUNOTIFICATION * pIPMN =
- reinterpret_cast < INSTANTIATEPOPUPMENUNOTIFICATION * > ( wParam );
- ASSERT( pIPMN != NULL );
- return (*pIPMN);
- }
- CExtPopupMenuWnd * CExtPopupMenuWnd::InstantiatePopupMenu(
- HWND hWndNotifyTarget,
- CRuntimeClass * pMenuRTC,
- CObject * pQuerySrc,
- LPARAM lParam // = 0L
- )
- {
- ASSERT( pMenuRTC != NULL );
- ASSERT( pMenuRTC->IsDerivedFrom(RUNTIME_CLASS(CExtPopupMenuWnd)) );
- if( hWndNotifyTarget != NULL && ::IsWindow( hWndNotifyTarget ) )
- {
- HWND hWnd = hWndNotifyTarget;
- for( ; hWnd != NULL; )
- {
- INSTANTIATEPOPUPMENUNOTIFICATION _ipmn( pMenuRTC, pQuerySrc, lParam );
- _ipmn.Notify( hWndNotifyTarget );
- if( _ipmn.m_pCreatedPopupMenuInstance != NULL )
- {
- ASSERT_VALID( _ipmn.m_pCreatedPopupMenuInstance );
- ASSERT( _ipmn.m_pCreatedPopupMenuInstance->IsKindOf( pMenuRTC ) );
- return _ipmn.m_pCreatedPopupMenuInstance;
- }
- __EXT_MFC_LONG_PTR dwStyle = ::__EXT_MFC_GetWindowLong( hWnd, GWL_STYLE );
- if( ( dwStyle & WS_CHILD ) == 0 )
- {
- CWnd * pWnd = CWnd::FromHandlePermanent( hWnd );
- if( pWnd != NULL && pWnd->IsKindOf( RUNTIME_CLASS(CFrameWnd) ) )
- {
- pWnd = pWnd->GetParentFrame();
- if( pWnd != NULL )
- {
- hWnd = pWnd->m_hWnd;
- continue;
- }
- }
- break;
- } // if( ( dwStyle & WS_CHILD ) == 0 )
- hWnd = ::GetParent( hWnd );
- } // for( ; hWnd != NULL; )
- } // if( hWndNotifyTarget != NULL && ::IsWindow( hWndNotifyTarget ) )
- CExtPopupMenuWnd * pPopup = STATIC_DOWNCAST( CExtPopupMenuWnd, pMenuRTC->CreateObject() );
- ASSERT_VALID( pPopup );
- return pPopup;
- }
- CSize CExtPopupMenuWnd::ResizingMinSizeGet() const
- {
- ASSERT_VALID( this );
- return m_sizeResizingMin;
- }
- void CExtPopupMenuWnd::ResizingMinSizeSet( CSize _size )
- {
- ASSERT_VALID( this );
- m_sizeResizingMin = _size;
- }
- CSize CExtPopupMenuWnd::ResizingMaxSizeGet() const
- {
- ASSERT_VALID( this );
- return m_sizeResizingMax;
- }
- void CExtPopupMenuWnd::ResizingMaxSizeSet( CSize _size )
- {
- ASSERT_VALID( this );
- m_sizeResizingMax = _size;
- }
- bool CExtPopupMenuWnd::_IsResizingMode() const
- {
- ASSERT_VALID( this );
- return m_bHelperResizingMode;
- }
- void CExtPopupMenuWnd::_DoResizing(
- CPoint ptScreenClick,
- bool bVerticalOnlyResizing
- )
- {
- ASSERT_VALID( this );
- _ItemFocusCancel( TRUE, TRUE );
- _SetCapture();
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- _KeyTipsShow( false );
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- HWND hWndOwn = GetSafeHwnd();
- ASSERT( hWndOwn != NULL && ::IsWindow( hWndOwn ) );
- bool bReCreateShadow = ( m_ctrlShadow.GetSafeHwnd() != NULL ) ? true : false;
- MSG msg;
- CPoint ptMove;
- CSize _sizeMin( ResizingMinSizeGet() ), _sizeMax( ResizingMaxSizeGet() ),
- _sizeShift, _sizeLast, _sizeCurrent, _sizeInitial, _sizeAdjust, _sizeControlAdjust,
- _sizeClientCurrent, _sizeClientInitial( m_rcClient.right - m_rcClient.left, m_rcClient.bottom - m_rcClient.top );
- CRect rcWnd;
- GetWindowRect( &rcWnd );
- _sizeLast = _sizeCurrent = _sizeInitial = rcWnd.Size();
- ::SetCapture( hWndOwn );
- while( ::IsWindow( hWndOwn ) && _IsResizingMode() )
- {
- ::WaitMessage();
- if( ! ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- continue;
- switch( msg.message )
- {
- case WM_LBUTTONUP:
- case WM_NCLBUTTONUP:
- case WM_MBUTTONUP:
- case WM_NCMBUTTONUP:
- case WM_RBUTTONUP:
- case WM_NCRBUTTONUP:
- case WM_KEYDOWN:
- ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE );
- case WM_CANCELMODE:
- case WM_ACTIVATEAPP:
- m_bHelperResizingMode = false;
- continue;
- case WM_MOUSEMOVE:
- {
- ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE );
- if( ! ::GetCursorPos( &ptMove ) )
- continue;
- if( bVerticalOnlyResizing )
- _sizeShift.cx = 0;
- else
- _sizeShift.cx = ptMove.x - ptScreenClick.x;
- _sizeShift.cy = ptMove.y - ptScreenClick.y;
- _sizeCurrent = _sizeInitial + _sizeShift;
- _sizeAdjust = _sizeCurrent;
- _sizeCurrent.cx = max( _sizeCurrent.cx, _sizeMin.cx );
- _sizeCurrent.cy = max( _sizeCurrent.cy, _sizeMin.cy );
- _sizeCurrent.cx = min( _sizeCurrent.cx, _sizeMax.cx );
- _sizeCurrent.cy = min( _sizeCurrent.cy, _sizeMax.cy );
- if( _sizeLast == _sizeCurrent )
- continue;
- _sizeAdjust -= _sizeCurrent;
- _sizeControlAdjust = _sizeCurrent - _sizeLast;
- _sizeLast = _sizeCurrent;
- rcWnd.right = rcWnd.left + _sizeCurrent.cx;
- rcWnd.bottom = rcWnd.top + _sizeCurrent.cy;
- _sizeClientCurrent = _sizeClientInitial + _sizeShift - _sizeAdjust;
- m_rcClient.right = m_rcClient.left + _sizeClientCurrent.cx;
- m_rcClient.bottom = m_rcClient.top + _sizeClientCurrent.cy;
- _DoAdjustControlMetrics( _sizeControlAdjust );
- if( bReCreateShadow )
- m_ctrlShadow.DestroyWindow();
- MoveWindow( &rcWnd, FALSE );
- if( bReCreateShadow )
- m_ctrlShadow.Create( hWndOwn, PmBridge_GetPM()->GetMenuShadowSize() );
- _SyncItems();
- _RecalcLayoutImpl();
- RedrawWindow(
- NULL,
- NULL,
- RDW_INVALIDATE|RDW_ERASE
- //|RDW_UPDATENOW|RDW_ERASENOW
- |RDW_FRAME|RDW_ALLCHILDREN
- );
- CExtPaintManager::stat_PassPaintMessages();
- }
- continue;
- } // switch( msg.message )
- if( ! ::AfxGetThread() -> PumpMessage() )
- {
- m_bHelperResizingMode = false;
- break;
- }
- } // while( ::IsWindow( hWndOwn ) && _IsResizingMode() )
- ::ReleaseCapture();
- }
- void CExtPopupMenuWnd::_DoAdjustControlMetrics(
- CSize _sizeAdjust
- )
- {
- ASSERT_VALID( this );
- _sizeAdjust;
- }
- bool CExtPopupMenuWnd::_OnMouseMove(
- UINT nFlags,
- CPoint point,
- bool & bNoEat
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return false;
- if( ! m_bAnimFinished )
- return true;
- if( _IsResizingMode() )
- {
- bNoEat = true;
- return false;
- }
- CExtPopupMenuSite & _site = GetSite();
- if( _site.IsShutdownMode()
- || _site.IsEmpty()
- || _site.GetAnimated() != NULL
- )
- return true;
- TranslateMouseMoveEventData_t _td( this, nFlags, point, bNoEat );
- if( _td.Notify() )
- {
- bNoEat = _td.m_bNoEat;
- return true;
- }
- CPoint ptScreenClick( point );
- ClientToScreen( &ptScreenClick );
- HWND hWndFromPoint = ::WindowFromPoint( ptScreenClick );
- if( hWndFromPoint != NULL
- && (::__EXT_MFC_GetWindowLong(hWndFromPoint,GWL_STYLE)&WS_CHILD) != 0
- && ::GetParent(hWndFromPoint) == m_hWnd
- )
- {
- CWnd * pWnd = CWnd::FromHandlePermanent( hWndFromPoint );
- if( pWnd != NULL )
- {
- int nCount = ItemGetCount();
- for( int i = 0; i < nCount; i++ )
- {
- MENUITEMDATA & mi = ItemGetInfo( i );
- if( !mi.IsInplaceEdit() )
- continue;
- if( ((LPVOID)mi.GetInplaceEditPtr()) != ((LPVOID)pWnd) )
- continue;
- if( m_nCurIndex == i )
- break;
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet( i, FALSE, TRUE, TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- break;
- } // for( int i = 0; i < nCount; i++ )
- } // if( pWnd != NULL )
- bNoEat = true;
- return false;
- }
- HWND hWndFocus = ::GetFocus();
- if( hWndFocus != NULL
- && (::__EXT_MFC_GetWindowLong(hWndFocus,GWL_STYLE)&WS_CHILD) != 0
- && ::GetParent(hWndFocus) == m_hWnd
- )
- return true;
- if( !_PtInWndArea(point) )
- {
- if( m_pWndParentMenu != NULL
- && m_pWndParentMenu->GetSafeHwnd() != NULL
- )
- {
- ASSERT_VALID( m_pWndParentMenu );
- CPoint point = ptScreenClick;
- m_pWndParentMenu->ScreenToClient( &point );
- if( ptScreenClick == m_ptTrackWatched )
- {
- m_ptTrackWatched.x = m_ptTrackWatched.y = 0;
- return true;
- }
- HWND hWndOwn = m_hWnd;
- if( m_pWndParentMenu->_OnMouseMove(
- nFlags,
- point,
- bNoEat
- )
- )
- {
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- m_nLastMousePick = IDX_NOTHING;
- if( bNoEat )
- return false;
- if( ::IsWindow(hWndOwn)
- && ((::__EXT_MFC_GetClassLong(hWndOwn,GWL_STYLE))&WS_VISIBLE) != 0
- )
- _OnCancelMode();
- return true;
- }
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- if( GetSite().GetCapture() == this )
- {
- HWND hWndTest = hWndFromPoint;
- for( ; true; )
- {
- if( (::__EXT_MFC_GetWindowLong(hWndTest,GWL_STYLE)&WS_CHILD) != 0 )
- hWndTest = ::GetParent( hWndTest );
- else
- break;
- }
- CWnd * pWndTest = CWnd::FromHandlePermanent( hWndTest );
- CExtPopupMenuWnd * pPopup = DYNAMIC_DOWNCAST( CExtPopupMenuWnd, pWndTest );
- if( pPopup != NULL )
- {
- bool bAllowReAssignCapture = false;
- CExtPopupMenuWnd * pTestPopup = pPopup;
- for( ; pTestPopup != NULL; pTestPopup = pTestPopup->GetParentMenuWnd() )
- {
- if( pTestPopup == this )
- {
- bAllowReAssignCapture = true;
- break;
- }
- }
- if( bAllowReAssignCapture )
- {
- CExtPopupMenuWnd * pPrevPopup = NULL;
- pTestPopup = pPopup;
- for( ; pTestPopup != NULL; )
- {
- pTestPopup->m_nDelayedFocusItemIndex = IDX_NOTHING;
- pTestPopup->KillTimer( ID_TIMER_ITEM_FOCUS_DELAY );
- pTestPopup->KillTimer( ID_TIMER_ITEM_HIDE_DELAY );
- pTestPopup->m_bDelayedHiding = false;
- pTestPopup->m_nLastMousePick = IDX_NOTHING;
- if( pPrevPopup != NULL )
- {
- INT nIndex, nCount = pTestPopup->ItemGetCount();
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- MENUITEMDATA & _mii = pTestPopup->ItemGetInfo( nIndex );
- if( ! _mii.IsPopup() )
- continue;
- CExtPopupMenuWnd * pChildPopup = _mii.GetPopup();
- if( pChildPopup == pPrevPopup )
- {
- if( pTestPopup->m_nCurIndex != nIndex )
- {
- pTestPopup->_ItemFocusSet( nIndex, TRUE, TRUE, FALSE, FALSE );
- pTestPopup->m_nLastMousePick = nIndex;
- }
- break;
- }
- }
- }
- pPrevPopup = pTestPopup;
- pTestPopup = pTestPopup->GetParentMenuWnd();
- }
- //::ReleaseCapture();
- pPopup->_SetCapture();
- CPoint point = ptScreenClick;
- pPopup->ScreenToClient( &point );
- return true; //pPopup->_OnMouseMove( nFlags, point, bNoEat );
- }
- }
- HWND hWndOwn = m_hWnd;
- if( m_nCurIndex >= 0 && m_nLastMousePick >= 0 )
- {
- MENUITEMDATA & _mii = ItemGetInfo( m_nCurIndex );
- if( ! _mii.IsPopup() )
- {
- _ItemFocusCancel( TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- else
- {
- if( _mii.GetPopup()->m_nCurIndex < 0 )
- {
- _ItemFocusCancel( TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- } // if( ! _mii.IsPopup() )
- } // if( m_nCurIndex >= 0 && m_nLastMousePick >= 0 )
- else if( m_nCurIndex != IDX_NOTHING )
- {
- bool bAlt =
- ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 )
- ? true : false;
- if( (! bAlt) && (TrackFlagsGet()&TPMX_SELECT_ANY) == 0 && m_nLastMousePick != IDX_NOTHING )
- _ItemFocusCancel( TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- } // else if( m_nCurIndex != IDX_NOTHING )
- } // if( m_nCurIndex >= 0 && m_nLastMousePick >= 0 )
- m_nLastMousePick = IDX_NOTHING;
- return false;
- }
- int nCurIndex = _HitTest(point);
- if( nCurIndex == IDX_EXPAND )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusCancel( TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- _SetCapture();
- if( g_bMenuDelayExpanding )
- {
- // _SetCapture();
- if( m_nWaitingExpandTickCount == 0 )
- {
- SetTimer(
- ID_TIMER_DELAY_EXPAND,
- ID_TOTAL_DELAY_EXPAND/ID_FREQ_DELAY_EXPAND,
- NULL
- );
- m_nWaitingExpandTickCount = 1;
- }
- } // if( g_bMenuDelayExpanding )
- return true;
- }
- if( _IsTearOff() && nCurIndex == IDX_TEAROFF )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusCancel( TRUE, FALSE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- _SetCapture();
- HCURSOR hCursor = ::LoadCursor( NULL, IDC_SIZEALL );
- ASSERT( hCursor != NULL );
- ::SetCursor( hCursor );
- if( g_bMenuShowCoolTips
- && GetSite().GetCapture() == this
- )
- {
- CRect rcItem;
- _GetItemRect(nCurIndex,rcItem);
- ClientToScreen( &rcItem );
- bool bShowTip = (!m_bSuspendTips);
- CExtPopupMenuTipWnd & _tipWnd = GetTip();
- if( _tipWnd.GetSafeHwnd() != NULL )
- {
- CRect rcExcludeArea = _tipWnd.GetExcludeArea();
- if( rcExcludeArea == rcItem )
- bShowTip = false;
- } // if( _tipWnd.GetSafeHwnd() != NULL )
- if( bShowTip )
- {
- CExtSafeString sTipText;
- g_ResourceManager->LoadString( sTipText, ID_EXT_TEAR_OFF_MENU_TIP );
- if( sTipText.IsEmpty() )
- sTipText = _T("Drag to make this menu float");
- _tipWnd.SetText( sTipText );
- _tipWnd.SetTipStyle(
- g_eTtsTearOffCaption // _CoolTipGetStyle()
- );
- VERIFY(
- _tipWnd.Show(
- this,
- rcItem
- )
- );
- } // if( bShowTip )
- }
- return true;
- }
- HWND hWndOwn = m_hWnd;
- if( _StartScrolling(nCurIndex) )
- return true;
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- // if( m_nCurIndex == IDX_RIBBON_FILE_MENU_OPTIONS_BUTTON
- // || m_nCurIndex == IDX_RIBBON_FILE_MENU_EXIT_BUTTON
- // )
- if( m_nCurIndex != nCurIndex )
- {
- CRect rcCurrItem;
- _GetItemRect( m_nCurIndex, rcCurrItem );
- if( ! rcCurrItem.IsRectEmpty() )
- InvalidateRect( &rcCurrItem );
- }
- if( nCurIndex == IDX_RIBBON_FILE_MENU_OPTIONS_BUTTON
- || nCurIndex == IDX_RIBBON_FILE_MENU_EXIT_BUTTON
- )
- {
- if( m_nCurIndex >= 0
- && ItemGetInfo( m_nCurIndex ).IsPopup()
- && ItemGetInfo( m_nCurIndex ).GetPopup()->GetSafeHwnd() != NULL
- )
- return true;
- CRect rcCurrItem;
- _GetItemRect( nCurIndex, rcCurrItem );
- InvalidateRect( &rcCurrItem );
- _ItemFocusCancel( FALSE, TRUE );
- m_nCurIndex = nCurIndex;
- _SetCapture();
- return true;
- }
- if( nCurIndex >= 0 )
- {
- #ifdef _DEBUG
- int nCountOfItems = (int)m_items_all.GetSize();
- ASSERT( nCurIndex < nCountOfItems );
- #endif // _DEBUG
- MENUITEMDATA & mi = ItemGetInfo(nCurIndex);
- if( ( ( ! mi.IsEnabled() ) && ( ! g_bShowCoolTipsOverDisabledItems ) )
- || mi.IsSeparator()
- )
- {
- _ItemFocusCancel( TRUE, TRUE, TRUE );
- _SetCapture();
- return false;
- }
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- const CExtCustomizeCmdTreeNode * pNode =
- mi.GetCmdNode();
- if( pNode != NULL )
- {
- ASSERT_VALID( pNode );
- if( (pNode->GetFlags() & __ECTN_TBB_SEPARATED_DROPDOWN) != 0 )
- {
- bool bRTL = OnQueryLayoutRTL();
- CRect rcDD;
- _GetItemRect( nCurIndex, rcDD, false );
- if( bRTL )
- rcDD.right = rcDD.left + __EXT_MENU_POPUP_ARROW_AREA_DX;
- else
- rcDD.left = rcDD.right - __EXT_MENU_POPUP_ARROW_AREA_DX;
- if( ! rcDD.PtInRect( point ) )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusDelay();
- // bool bFocusAreadySet = false;
- // if( mi.IsPopup() )
- // _ItemFocusDelay( nCurIndex, &bFocusAreadySet );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- // if( ! bFocusAreadySet )
- // {
- _SetCapture();
- _ItemFocusSet(
- nCurIndex,
- FALSE,
- TRUE,
- FALSE
- );
- Invalidate( FALSE );
- // }
- if( g_bMenuShowCoolTips
- && (! m_bSuspendTips )
- // && nCurIndex != nOldCurIndex
- // && GetSite().GetCapture() == this
- && mi.GetPopup()->GetSafeHwnd() == NULL
- )
- {
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- bool bInitCoolTip = true;
- if( _IsRibbonMode() )
- {
- if( mi.KeyTipGetWnd( true )->GetSafeHwnd() != NULL
- || mi.KeyTipGetWnd( false )->GetSafeHwnd() != NULL
- )
- bInitCoolTip = false;
- else
- {
- CExtPopupScreenTipWnd & _wndScreenTip = GetScreenTip();
- if( mi.InitSceenTip( _wndScreenTip ) )
- bInitCoolTip = false;
- }
- } // if( _IsRibbonMode() )
- if( bInitCoolTip )
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- {
- CExtSafeString sTipText;
- mi.GetTip( sTipText );
- if( ! sTipText.IsEmpty() )
- {
- CRect rcItem;
- _GetItemRect(nCurIndex,rcItem);
- ClientToScreen( &rcItem );
- CExtPopupMenuTipWnd & _tipWnd = GetTip();
- _tipWnd.SetText( sTipText );
- _tipWnd.SetTipStyle( _CoolTipGetStyle() );
- VERIFY(
- _tipWnd.Show(
- this,
- rcItem
- )
- );
- } // if( ! sTipText.IsEmpty() )
- } // if( bInitCoolTip )
- } // if( g_bMenuShowCoolTips ....
- return true;
- }
- else
- if( m_nCurIndex != nCurIndex )
- _ItemFocusCancel( TRUE, TRUE );
- if( mi.GetPopup()->GetSafeHwnd() != NULL )
- return false;
- m_nCurIndex = IDX_NOTHING;
- }
- } // if( pNode != NULL )
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- int nOldCurIndex = m_nCurIndex;
- if( nOldCurIndex != nCurIndex )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusDelay();
- bool bFocusAreadySet = false;
- if( mi.IsPopup() )
- _ItemFocusDelay( nCurIndex, &bFocusAreadySet );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- if( ! bFocusAreadySet )
- {
- _SetCapture();
- _ItemFocusSet( nCurIndex, FALSE, TRUE, FALSE, TRUE );
- }
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- m_nLastMousePick = nCurIndex;
- MENUITEMDATA & mi = ItemGetInfo(nCurIndex);
- if( (! bFocusAreadySet ) && mi.IsPopup() )
- {
- CExtPopupMenuTipWnd & _tipWnd = GetTip();
- _tipWnd.Hide();
- if( mi.GetPopup()->GetSafeHwnd() == NULL )
- {
- _ItemFocusDelay( nCurIndex );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- return true;
- }
- if( g_bMenuShowCoolTips
- && (! m_bSuspendTips )
- && nCurIndex != nOldCurIndex
- && GetSite().GetCapture() == this
- )
- {
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- bool bInitCoolTip = true;
- if( _IsRibbonMode() )
- {
- if( mi.KeyTipGetWnd( true )->GetSafeHwnd() != NULL
- || mi.KeyTipGetWnd( false )->GetSafeHwnd() != NULL
- )
- bInitCoolTip = false;
- else
- {
- CExtPopupScreenTipWnd & _wndScreenTip = GetScreenTip();
- if( mi.InitSceenTip( _wndScreenTip ) )
- bInitCoolTip = false;
- }
- } // if( _IsRibbonMode() )
- if( bInitCoolTip )
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- {
- CExtSafeString sTipText;
- mi.GetTip( sTipText );
- if( ! sTipText.IsEmpty() )
- {
- CRect rcItem;
- _GetItemRect(nCurIndex,rcItem);
- ClientToScreen( &rcItem );
- CExtPopupMenuTipWnd & _tipWnd = GetTip();
- _tipWnd.SetText( sTipText );
- _tipWnd.SetTipStyle( _CoolTipGetStyle() );
- VERIFY(
- _tipWnd.Show(
- this,
- rcItem
- )
- );
- } // if( ! sTipText.IsEmpty() )
- } // if( bInitCoolTip )
- } // if( g_bMenuShowCoolTips ....
- } // if( nOldCurIndex != nCurIndex )
- return (nOldCurIndex == nCurIndex) ? false : true;
- } // if( nCurIndex >= 0 )
- return false;
- }
- void CExtPopupMenuWnd::_ItemFocusDelay(
- int nItemIndex, // = IDX_NOTHING
- bool * p_bFocusAreadySet // = NULL
- )
- {
- ASSERT_VALID( this );
- if( p_bFocusAreadySet != NULL )
- (*p_bFocusAreadySet) = false;
- HWND hWndOwn = m_hWnd;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- if( nItemIndex >= 0 )
- {
- MENUITEMDATA & mii = ItemGetInfo( nItemIndex );
- if( mii.IsPopup() )
- {
- CExtPopupMenuWnd * pPopup = mii.GetPopup();
- ASSERT_VALID( pPopup );
- bool bPopupAlreadyOpen = false;
- if( pPopup->GetSafeHwnd() != NULL )
- {
- int nCount = ItemGetCount();
- for( int i = 0; i < nCount; i++ )
- {
- MENUITEMDATA & mii_child = ItemGetInfo( i );
- if( i == nItemIndex )
- continue;
- if( ! mii_child.IsPopup() )
- continue;
- CExtPopupMenuWnd * pChildPopup = mii_child.GetPopup();
- ASSERT_VALID( pChildPopup );
- if( pChildPopup->GetSafeHwnd() == NULL )
- continue;
- INT nSaved = pChildPopup->m_nFadeOutAnimationStepCount;
- pChildPopup->m_nFadeOutAnimationStepCount = -1;
- pChildPopup->_OnCancelMode();
- pChildPopup->m_nFadeOutAnimationStepCount = nSaved;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- bPopupAlreadyOpen = true;
- pPopup->m_bDelayedHiding = false;
- pPopup->KillTimer( ID_TIMER_ITEM_HIDE_DELAY );
- pPopup->_ItemFocusCancel( TRUE, FALSE, FALSE );
- {
- CClientDC dc( pPopup );
- pPopup->_DoPaint( dc );
- }
- pPopup->_SetCapture();
- m_nDelayedFocusItemIndex = IDX_NOTHING;
- KillTimer( ID_TIMER_DELAY_EXPAND );
- if( m_nCurIndex >= 0 )
- {
- MENUITEMDATA & mii_old = ItemGetInfo( m_nCurIndex );
- mii_old.SetSelected( false );
- }
- m_nCurIndex = nItemIndex;
- mii.SetSelected( true );
- {
- CClientDC dc( this );
- _DoPaint( dc );
- }
- if( p_bFocusAreadySet != NULL )
- (*p_bFocusAreadySet) = true;
- return;
- }
- }
- }
- ItemFocusTracker_t _ift( this );
- if( m_nDelayedFocusItemIndex != nItemIndex )
- {
- if( m_nDelayedFocusItemIndex >= 0 )
- KillTimer( ID_TIMER_ITEM_FOCUS_DELAY );
- //m_nDelayedFocusItemIndex = IDX_NOTHING;
- }
- if( nItemIndex < 0 )
- {
- m_nDelayedFocusItemIndex = IDX_NOTHING;
- return;
- }
- if( m_nDelayedFocusItemIndex == nItemIndex )
- return;
- ASSERT( nItemIndex>=0 && nItemIndex<m_items_all.GetSize() );
- m_nDelayedFocusItemIndex = nItemIndex;
- ASSERT( ItemGetInfo(m_nDelayedFocusItemIndex).IsPopup() );
- ITEMCOVERINGNOTIFICATON _icn(
- this,
- NULL,
- ITEMCOVERINGNOTIFICATON::__EICN_DELAY,
- m_nDelayedFocusItemIndex
- );
- _icn.Notify();
- m_bSuspendTips = _icn.m_bSuspendTips;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- KillTimer( ID_TIMER_AUTO_EXPAND );
- ASSERT( g_nTimeDelayedDisplaying > 0 );
- SetTimer( ID_TIMER_ITEM_FOCUS_DELAY, g_nTimeDelayedDisplaying, NULL );
- _ift.FocusChangingUnRegister();
- }
- int CExtPopupMenuWnd::_GetMaxScrollPos()
- {
- ASSERT_VALID( this );
- ASSERT( m_bScrollingAvailable );
- CRect rcClient;
- _GetClientRect( &rcClient );
- int nClientHeight =
- rcClient.Height();
- CRect rcMB = OnQueryMenuBorderMetrics();
- int nMenuShadowSize = OnQueryMenuShadowSize();
- int nMaxScrollPos = m_sizeFullItems.cy;
- nMaxScrollPos += rcMB.top + rcMB.bottom;
- nMaxScrollPos += nMenuShadowSize;
- nMaxScrollPos -= nClientHeight;
- //ASSERT( nMaxScrollPos > 0 );
- nMaxScrollPos = max( 0, nMaxScrollPos );
- if( m_bExpandAvailable )
- nMaxScrollPos += _GetSpecBtnHeight(); // xpand btn
- if( _IsTearOff() )
- nMaxScrollPos += _GetTearOffCaptionHeight();
- return -nMaxScrollPos;
- }
- void CExtPopupMenuWnd::OnTimer(__EXT_MFC_UINT_PTR nIDEvent)
- {
- ASSERT_VALID( this );
- switch( nIDEvent )
- {
- case ID_TIMER_AUTO_EXPAND:
- {
- if( m_nCurIndex >= 0 )
- {
- MENUITEMDATA & mii = ItemGetInfo( m_nCurIndex );
- if( mii.IsInplaceEdit() )
- {
- CWnd * pWnd = mii.GetInplaceEditPtr();
- if( pWnd->GetSafeHwnd() != NULL
- && ::GetFocus() == pWnd->m_hWnd
- )
- return;
- }
- if( mii.IsPopup()
- && mii.GetPopup()->GetSafeHwnd() != NULL
- )
- {
- KillTimer( nIDEvent );
- return;
- }
- }
- KillTimer( nIDEvent );
- _DoExpand();
- }
- return;
- case ID_TIMER_FADE_OUT_ANIMATION:
- {
- if( m_nFadeOutAnimationStepIndex < m_nFadeOutAnimationStepCount )
- {
- CExtPopupMenuWnd * pPopup;
- for( pPopup = this; pPopup != NULL; pPopup = pPopup->m_pWndParentMenu )
- {
- if( pPopup->GetSafeHwnd() == NULL )
- continue;
- ASSERT( g_PaintManager.m_pfnSetLayeredWindowAttributes != NULL );
- if( (pPopup->GetStyle()&WS_VISIBLE) == 0 )
- continue;
- if( m_nFadeOutAnimationStepIndex == 0 )
- {
- pPopup->m_bHelperAnimationControllerDetected = true;
- if( (pPopup->GetExStyle()&(__EXT_MFC_WS_EX_LAYERED|WS_EX_TRANSPARENT)) != (__EXT_MFC_WS_EX_LAYERED|WS_EX_TRANSPARENT) )
- pPopup->ModifyStyleEx( 0, (__EXT_MFC_WS_EX_LAYERED|WS_EX_TRANSPARENT) );
- pPopup->EnableWindow( FALSE );
- }
- BYTE nAlpha = (BYTE)
- ::MulDiv(
- m_nFadeOutAnimationStepCount - m_nFadeOutAnimationStepIndex - 1,
- 255,
- m_nFadeOutAnimationStepCount
- );
- g_PaintManager.m_pfnSetLayeredWindowAttributes( pPopup->m_hWnd, 0, nAlpha, __EXT_MFC_LWA_ALPHA );
- if( pPopup->m_ctrlShadow.GetSafeHwnd() != NULL
- && (pPopup->m_ctrlShadow.GetStyle()&WS_VISIBLE)
- )
- pPopup->m_ctrlShadow.UpdateWindowLayer( nAlpha );
- CExtPaintManager::stat_PassPaintMessages();
- } // for( pPopup = this; pPopup != NULL; pPopup = pPopup->m_pWndParentMenu )
- m_nFadeOutAnimationStepIndex ++;
- } // if( m_nFadeOutAnimationStepIndex < m_nFadeOutAnimationStepCount )
- else
- {
- KillTimer( nIDEvent );
- if( m_ctrlShadow.GetSafeHwnd() != NULL )
- m_ctrlShadow.DestroyWindow();
- CExtPopupMenuWnd * pPopup = this;
- for( ; pPopup != NULL; )
- {
- VERIFY( pPopup->_BuildItems( NULL, true ) );
- //pPopup->_DeleteFadeOutMenu();
- if( pPopup->m_ctrlShadow.GetSafeHwnd() != NULL
- && (pPopup->m_ctrlShadow.GetStyle()&WS_VISIBLE)
- )
- pPopup->m_ctrlShadow.DestroyWindow();
- HWND hWnd = pPopup->m_hWnd;
- pPopup = pPopup->m_pWndParentMenu;
- ::DestroyWindow( hWnd );
- }
- } // else from if( m_nFadeOutAnimationStepIndex < m_nFadeOutAnimationStepCount )
- }
- return;
- case ID_TIMER_DELAY_EXPAND:
- {
- if( m_nWaitingExpandTickCount <
- ID_TOTAL_DELAY_EXPAND
- )
- {
- if( m_nWaitingExpandTickCount <= 1 )
- m_nWaitingExpandTickCount = 0;
- m_nWaitingExpandTickCount +=
- ID_FREQ_DELAY_EXPAND;
- return;
- }
- VERIFY( KillTimer(ID_TIMER_DELAY_EXPAND) );
- m_nWaitingExpandTickCount = 0;
- if( m_bExpandAvailable
- && (!m_bExpandWasPressed)
- && ( GetSite().GetAnimated() == NULL )
- )
- { // if expand can be performed
- CPoint point;
- if( ! ::GetCursorPos(&point) )
- return;
- ScreenToClient( &point );
- CRect rcExpand;
- _GetItemRect( IDX_EXPAND, rcExpand );
- if( rcExpand.PtInRect(point) )
- _DoExpand();
- } // if expand can be performed
- }
- return;
- case ID_TIMER_SCROLLING:
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusDelay();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- if( m_nCurIndex >= 0 )
- {
- _ItemFocusCancel(TRUE);
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- CPoint point;
- if( ! ::GetCursorPos(&point) )
- return;
- ScreenToClient( &point );
- m_nScrollingDirection = 0;
- CRect rcItem;
- _GetItemRect(IDX_SCROLL_TOP,rcItem);
- if( m_nAcceleratedPixelsPerStepCurrent > g_nAcceleratedPixelsPerStepMax )
- m_nAcceleratedPixelsPerStepCurrent = g_nAcceleratedPixelsPerStepMax;
- if( rcItem.PtInRect(point) )
- {
- m_nScrollingDirection = m_nAcceleratedPixelsPerStepCurrent; // __SCROLLING_PIXEL_STEP
- }
- else
- {
- _GetItemRect(IDX_SCROLL_BOTTOM,rcItem);
- if( rcItem.PtInRect(point) )
- m_nScrollingDirection = -m_nAcceleratedPixelsPerStepCurrent; // (-__SCROLLING_PIXEL_STEP);
- }
- m_nDyScrollOffset += m_nScrollingDirection;
- bool bKillThisTimer =
- (m_nScrollingDirection == 0) ? true : false;
- if( m_nDyScrollOffset > 0 )
- {
- m_nDyScrollOffset = 0;
- bKillThisTimer = true;
- }
- else
- {
- int nMaxScrollPos = _GetMaxScrollPos();
- if( m_nDyScrollOffset < nMaxScrollPos )
- {
- m_nDyScrollOffset = nMaxScrollPos;
- bKillThisTimer = true;
- }
- }
- if( bKillThisTimer )
- {
- VERIFY( KillTimer(ID_TIMER_SCROLLING) );
- m_nAcceleratedPixelsPerStepCurrent = __SCROLLING_PIXEL_STEP;
- m_nAcceleratedMilliSecondsPassed = 0;
- m_nScrollingDirection = 0;
- }
- else
- {
- if( g_bUseAcceleratedMenuScrolling )
- {
- INT nAcceleratedIncreasePercent = g_nAcceleratedIncreasePercent;
- INT nAcceleratedIncreaseStep = g_nAcceleratedIncreaseStep;
- if( nAcceleratedIncreaseStep >= 0
- && nAcceleratedIncreasePercent > 0
- )
- {
- if( m_nAcceleratedMilliSecondsPassed >= nAcceleratedIncreaseStep )
- {
- m_nAcceleratedMilliSecondsPassed = 0;
- INT nStepPx =
- ::MulDiv(
- m_nAcceleratedPixelsPerStepCurrent,
- 100,
- __SCROLLING_PIXEL_STEP
- );
- nStepPx +=
- ::MulDiv(
- nStepPx,
- nAcceleratedIncreasePercent,
- 100
- );
- m_nAcceleratedPixelsPerStepCurrent =
- ::MulDiv(
- nStepPx,
- __SCROLLING_PIXEL_STEP,
- 100
- );
- } // if( m_nAcceleratedMilliSecondsPassed >= nAcceleratedIncreaseStep )
- else
- {
- m_nAcceleratedMilliSecondsPassed += ID_PERIOD_SCROLLING;
- } // else from if( m_nAcceleratedMilliSecondsPassed >= nAcceleratedIncreaseStep )
- }
- } // if( g_bUseAcceleratedMenuScrolling )
- }
- _CachedRectsEmpty();
- Invalidate( FALSE );
- }
- return;
- case ID_TIMER_ITEM_HIDE_DELAY:
- {
- KillTimer( nIDEvent );
- if( ! m_bDelayedHiding )
- return;
- INT nSaved = m_nFadeOutAnimationStepCount;
- m_nFadeOutAnimationStepCount = -1;
- _OnCancelMode();
- m_nFadeOutAnimationStepCount = nSaved;
- return;
- }
- case ID_TIMER_ITEM_FOCUS_DELAY:
- {
- if( GetSite().GetAnimated() != NULL )
- return;
- KillTimer( nIDEvent );
- if( GetSite().IsShutdownMode() )
- return;
- Invalidate( FALSE );
- if( m_nDelayedFocusItemIndex >= 0 )
- {
- ASSERT( m_nDelayedFocusItemIndex>=0 && m_nDelayedFocusItemIndex<m_items_all.GetSize() );
- ASSERT( ItemGetInfo(m_nDelayedFocusItemIndex).IsPopup() );
- CRect rcItem;
- _GetItemRect(m_nDelayedFocusItemIndex,rcItem);
- CPoint point;
- if( ! ::GetCursorPos( &point ) )
- return;
- ScreenToClient( &point );
- if( rcItem.PtInRect(point) )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet(
- m_nDelayedFocusItemIndex,
- TRUE,
- TRUE,
- FALSE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return;
- }
- } // if( m_nDelayedFocusItemIndex >= 0 )
- m_nDelayedFocusItemIndex = IDX_NOTHING;
- }
- return;
-
- default:
- CExtPopupBaseWnd::OnTimer(nIDEvent);
- break; // default
- } // switch( nIDEvent )
- }
- CExtPopupMenuWnd * CExtPopupMenuWnd::_GetCapture()
- {
- if( (TrackFlagsGet()&TPMX_NO_SITE) != 0 )
- return this;
- return GetSite().GetCapture();
- }
- void CExtPopupMenuWnd::_SetCapture()
- {
- ASSERT_VALID( this );
- if( (TrackFlagsGet()&TPMX_NO_SITE) != 0 )
- return;
- ASSERT( !_FindCustomizeMode() );
- CExtPopupMenuSite & _site = GetSite();
- if( GetSafeHwnd() != NULL )
- {
- ASSERT( ::IsWindow(GetSafeHwnd()) );
- _site.SetCapture( this );
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- _KeyTipsShow( true );
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- }
- else
- _site.SetCapture( NULL );
- }
- void CExtPopupMenuWnd::_ReleaseCapture()
- {
- ASSERT_VALID( this );
- ASSERT( !_FindCustomizeMode() );
- CExtPopupMenuSite & _site = GetSite();
- if( _site.IsEmpty()
- || _site.IsShutdownMode()
- )
- return;
- if( _site.GetCapture() == this )
- _site.SetCapture( NULL );
- }
- int CExtPopupMenuWnd::_GetNextItem(
- next_item_t nit
- )
- {
- ASSERT_VALID( this );
- int nCountOfItems = (int)m_items_all.GetSize();
- bool bCanExpand = false;
- if( m_bExpandAvailable
- && (!m_bExpandWasPressed)
- )
- {
- if( IsAllItemsRarelyUsed() )
- return IDX_EXPAND;
- bCanExpand = true;
- }
- if( nit == __NI_NOTHING
- || nCountOfItems == 0
- )
- {
- if( bCanExpand )
- return IDX_EXPAND;
- return IDX_NOTHING;
- }
- if( nit == __NI_ANY
- && m_nCurIndex >= 0
- )
- return m_nCurIndex;
- if( m_nCurIndex < 0 )
- {
- INT iter = 0;
- for( ; iter < m_items_all.GetSize(); ++iter )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsEnabled()
- && mi.IsDisplayed()
- )
- return mi.GetIndex();
- }
- if( bCanExpand )
- return IDX_EXPAND;
- return IDX_NOTHING;
- } // if( m_nCurIndex < 0 )
- if( nit == __NI_ROW_NEXT )
- {
- if( nCountOfItems < 2 )
- {
- if( bCanExpand )
- return IDX_EXPAND;
- return IDX_NOTHING;
- }
- INT iter = m_nCurIndex;
- if( ! ItemGetInfo( iter ).IsIconMode() )
- return _GetNextItem( __NI_NEXT );
- CRect rcCurrItem;
- _GetItemRect( iter, rcCurrItem, false );
- for( ; iter < m_items_all.GetSize(); ++iter )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsDisplayed()
- && ItemPaletteRowWrapGet( iter )
- )
- {
- ++iter;
- break;
- }
- }
- int nPotentialIdx = IDX_NOTHING;
- for( ; iter < m_items_all.GetSize(); ++iter )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( (! mi.IsEnabled() )
- || (! mi.IsDisplayed() )
- )
- continue;
- CRect rcItem;
- _GetItemRect( iter, rcItem, false );
- if( rcItem.left >= rcCurrItem.left )
- return mi.GetIndex();
- else if(
- ItemPaletteRowWrapGet( iter )
- && nPotentialIdx != IDX_NOTHING
- )
- break;
- nPotentialIdx = iter;
- }
- if( nPotentialIdx == IDX_NOTHING
- && bCanExpand
- )
- return IDX_EXPAND;
- return nPotentialIdx;
- } // if( nit == __NI_ROW_NEXT )
- if( nit == __NI_ROW_PREV )
- {
- if( nCountOfItems < 2 )
- return IDX_NOTHING;
- INT iter = m_nCurIndex;
- if( ! ItemGetInfo( iter ).IsIconMode() )
- return _GetNextItem( __NI_PREV );
- CRect rcCurrItem;
- _GetItemRect( iter, rcCurrItem, false );
- for( ; (iter+1) > 0; --iter )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsDisplayed()
- && ItemPaletteRowWrapGet( iter )
- && iter != m_nCurIndex
- )
- break;
- }
- int nPotentialIdx = IDX_NOTHING;
- for( ; (iter+1) > 0; --iter )
- {
- if( ItemPaletteRowWrapGet( iter )
- && nPotentialIdx != IDX_NOTHING
- )
- break;
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( (! mi.IsEnabled() )
- || (! mi.IsDisplayed() )
- )
- continue;
- CRect rcItem;
- _GetItemRect( iter, rcItem, false );
- if( rcItem.right <= rcCurrItem.right )
- return mi.GetIndex();
- nPotentialIdx = iter;
- }
- if( nPotentialIdx == IDX_NOTHING
- && bCanExpand
- )
- return IDX_EXPAND;
- return nPotentialIdx;
- } // if( nit == __NI_ROW_PREV )
- if( nit == __NI_NEXT )
- {
- if( nCountOfItems < 2 )
- {
- if( bCanExpand )
- return IDX_EXPAND;
- return IDX_NOTHING;
- }
- INT iter = m_nCurIndex + 1;
- for( ; iter < m_items_all.GetSize(); ++iter )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsEnabled() && mi.IsDisplayed() )
- return mi.GetIndex();
- }
- if( bCanExpand )
- return IDX_EXPAND;
- if( m_nCurIndex == 0 )
- return IDX_NOTHING;
- iter = 0;
- INT iter2 = m_nCurIndex - 1;
- do
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsEnabled() && mi.IsDisplayed() )
- return mi.GetIndex();
- iter++;
- } while( iter != iter2 );
- return IDX_NOTHING;
- } // if( nit == __NI_NEXT )
- if( nit == __NI_PREV )
- {
- if( nCountOfItems < 2 )
- return IDX_NOTHING;
- if( m_nCurIndex != 0 )
- {
- int nIndex = m_nCurIndex - 1;
- INT iter = nIndex;
- for( ; true; )
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsEnabled() && mi.IsDisplayed() )
- return mi.GetIndex();
- if( nIndex == 0 )
- break;
- --iter;
- --nIndex;
- }
- } // if( m_nCurIndex != 0 )
- int nIndex = m_nCurIndex + 1;
- INT iter2 = nIndex;
- INT iter = INT(m_items_all.GetSize()) - 1;
- do
- {
- MENUITEMDATA & mi = ItemGetInfo( iter );
- if( mi.IsEnabled() && mi.IsDisplayed() )
- return mi.GetIndex();
- iter--;
- } while( iter != iter2 );
- return IDX_NOTHING;
- } // if( nit == __NI_PREV )
- return IDX_NOTHING;
- }
- const ACCEL * CExtPopupMenuWnd::_GetTranslatedContextHelpAccel() const
- {
- if( ! g_bTranslateContextHelpCmd )
- return NULL;
- return &g_accelContextHelp;
- }
- bool CExtPopupMenuWnd::_OnKeyDown(
- UINT nChar,
- UINT nRepCnt,
- UINT nFlags,
- bool & bNoEat
- )
- {
- ASSERT_VALID( this );
- nFlags;
- ASSERT( m_hWndCmdReceiver != NULL );
- ASSERT( ::IsWindow(m_hWndCmdReceiver) );
- nRepCnt;
- if( GetSafeHwnd() == NULL )
- return true;
- if( ! m_bAnimFinished )
- return true;
- if( _IsResizingMode() )
- return true;
- CExtPopupMenuSite & _site = GetSite();
- if( _site.IsShutdownMode()
- || _site.IsEmpty()
- || _site.GetAnimated() != NULL
- )
- return true;
- TranslateKeyboardEventData_t _td( this, nChar, nRepCnt, nFlags, bNoEat );
- if( _td.Notify() )
- {
- bNoEat = _td.m_bNoEat;
- return true;
- }
- bool bAlt =
- ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 )
- ? true : false;
- bool bCtrl =
- ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 )
- ? true : false;
- bool bShift =
- ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 )
- ? true : false;
- HWND hWndFocus = ::GetFocus();
- if( hWndFocus != NULL
- && (::__EXT_MFC_GetWindowLong(hWndFocus,GWL_STYLE)&WS_CHILD) != 0
- && ::GetParent(hWndFocus) == m_hWnd
- && ( nChar != VK_RETURN
- || m_nCurIndex < 0
- || (! ItemGetInfo(m_nCurIndex).IsInplaceEdit() )
- )
- )
- {
- if( bAlt )
- PostMessage( WM_CANCELMODE );
- else if( nChar == VK_ESCAPE )
- SetFocus();
- else if( (nChar == VK_INSERT || nChar == _T('C')) && bCtrl )
- ::SendMessage( hWndFocus, WM_COPY, 0, 0 );
- else if( ( nChar == _T('X') && bCtrl )
- || ( nChar == VK_DELETE && bShift )
- )
- ::SendMessage( hWndFocus, WM_CUT, 0, 0 );
- else if( ( nChar == _T('V') && bCtrl )
- || ( nChar == VK_INSERT && bShift )
- )
- ::SendMessage( hWndFocus, WM_PASTE, 0, 0 );
- else if( nChar == VK_DELETE )
- ::SendMessage( hWndFocus, CExtPopupMenuWnd::CInPlaceEditWnd::g_nMsgDeleteSelection, 0, 0 );
- else if( nChar == _T('A') && bCtrl )
- ::SendMessage( hWndFocus, CExtPopupMenuWnd::CInPlaceEditWnd::g_nMsgSelectAll, 0, 0 );
- else
- bNoEat = true;
- return (!bNoEat);
- }
- next_item_t nit = __NI_NOTHING;
- if( nChar == VK_TAB && (! ( bCtrl || bAlt ) ) )
- {
- if( _IsPalette()
- && ItemGetCount() > 0
- && m_nCurIndex >= 0
- && m_nCurIndex <= (ItemGetCount() - 1)
- && ItemGetInfo(m_nCurIndex).IsToolButton()
- )
- nChar = bShift ? VK_LEFT : VK_RIGHT;
- else
- nChar = bShift ? VK_UP : VK_DOWN;
- }
- bool bRTL = OnQueryLayoutRTL();
- if( bRTL
- && ( nChar == VK_LEFT
- || nChar == VK_RIGHT
- )
- )
- nChar = (nChar == VK_LEFT) ? VK_RIGHT : VK_LEFT;
- switch( nChar )
- {
- case VK_MENU:
- _EndSequence();
- return true;
- case VK_SPACE:
- return true;
- case VK_F4:
- {
- if( m_nCurIndex < 0 )
- return true;
- MENUITEMDATA & mi = ItemGetInfo( m_nCurIndex );
- if( mi.IsExtraMark() )
- return true;
- if( ! ( mi.IsInplaceEdit() && mi.IsPopup() ) )
- return true;
- if( mi.GetPopup()->GetSafeHwnd() == NULL )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet(
- m_nCurIndex,
- TRUE,
- TRUE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- return true;
- }
- case VK_RETURN:
- {
- if( m_nCurIndex < 0 )
- {
- INT nPos = ItemDefaultFind();
- if( nPos < 0 )
- return true; // break;
- _ItemFocusSet(
- nPos,
- FALSE,
- TRUE,
- TRUE
- );
- }
- MENUITEMDATA & mi = ItemGetInfo( m_nCurIndex );
- if( mi.IsInplaceEdit() )
- {
- CWnd * pWndInplace = mi.GetInplaceEditPtr();
- if( pWndInplace != NULL )
- {
- ASSERT_VALID( pWndInplace );
- ASSERT( pWndInplace->GetSafeHwnd() != NULL && (::IsWindow(pWndInplace->GetSafeHwnd())) );
- if( mi.IsAllowInplaceEditActivation() )
- {
- if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- {
- CRect rcInplaceEdit;
- _GetItemRect( m_nCurIndex, rcInplaceEdit );
- rcInplaceEdit =
- mi.AdjustInplaceEditRect(
- rcInplaceEdit,
- OnQueryLayoutRTL()
- );
- pWndInplace->SetWindowPos(
- NULL,
- rcInplaceEdit.left, rcInplaceEdit.top,
- rcInplaceEdit.Width(), rcInplaceEdit.Height(),
- SWP_NOZORDER|SWP_NOOWNERZORDER
- |SWP_NOACTIVATE|SWP_SHOWWINDOW
- );
- pWndInplace->SetFocus();
- } // if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- else
- {
- bNoEat = true;
- return false;
- }
- } // if( mi.IsAllowInplaceEditActivation() )
- } // if( pWndInplace != NULL )
- return true;
- }
- if( mi.IsExtraMark() && (! _FindHelpMode() ) )
- {
- ASSERT( mi.GetExtraMarkCallback() != NULL );
- mi.GetExtraMarkCallback()( this, &mi );
- CClientDC dc( this );
- _DoPaint( dc );
- return true;
- } // if( mi.IsExtraMark() ....
- if( mi.IsExecutableCmdID()
- || ( mi.IsPopup()
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- && mi.GetCmdNode() != NULL
- && (mi.GetCmdNode()->GetFlags()&__ECTN_TBB_SEPARATED_DROPDOWN) != 0
- && (mi.GetCmdNode()->GetFlags()&(__ECTN_TBB_COLOR|__ECTN_TBB_UNDO_REDO)) != 0
- #else // (!defined __EXT_MFC_NO_CUSTOMIZE)
- && ( mi.GetPopup()->IsKindOf( RUNTIME_CLASS(CExtPopupColorMenuWnd) )
- #if (!defined __EXT_MFC_NO_UNDO_REDO_POPUP)
- || mi.GetPopup()->IsKindOf( RUNTIME_CLASS(CExtPopupUndoRedoMenuWnd) )
- #endif // (!defined __EXT_MFC_NO_UNDO_REDO_POPUP)
- )
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- )
- )
- {
- if( !( mi.GetCmdDeliverCb() != NULL
- && mi.GetCmdDeliverCb()( this, &mi )
- )
- )
- {
- _CancelingSet();
- _EndSequenceEx( mi );
- }
- return true;
- }
- } // case VK_RETURN
- case VK_RIGHT:
- {
- if( _IsPalette()
- && ItemGetCount() > 0
- && m_nCurIndex >= 0
- && m_nCurIndex <= (ItemGetCount() - 1)
- && (! ItemGetInfo(m_nCurIndex).IsPopup() )
- )
- {
- nit = __NI_NEXT;
- break;
- }
- bool bSendChangeMenu = false;
- if( m_nCurIndex < 0 )
- {
- if( m_items_all.GetSize() == 0 )
- return true; // false;
- // nit = __NI_ANY;
- bSendChangeMenu = true;
- }
- else
- {
- MENUITEMDATA & mi = ItemGetInfo(m_nCurIndex);
- if( !mi.IsPopup() )
- {
- bSendChangeMenu = true;
- }
- else
- {
- if( mi.GetPopup()->GetSafeHwnd() == NULL )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusDelay();
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- _ItemFocusSet(
- m_nCurIndex,
- TRUE,
- TRUE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- }
- }
- if( bSendChangeMenu && nChar==VK_RIGHT )
- {
- ASSERT( m_hWndCmdReceiver != NULL );
- ASSERT( ::IsWindow(m_hWndCmdReceiver) );
- if( CExtToolControlBar::g_bMenuTracking )
- ::PostMessage(
- m_hWndCmdReceiver,
- bRTL ? CExtPopupMenuWnd::g_nMsgPopupPrev : CExtPopupMenuWnd::g_nMsgPopupNext,
- 0,
- LPARAM( this )
- );
- return true;
- }
- }
- break; // case VK_RIGHT
- case VK_ESCAPE:
- if( m_bTopLevel )
- {
- _EndSequence();
- return true;
- }
- case VK_LEFT:
- if( nChar == VK_LEFT
- && _IsPalette()
- && ItemGetCount() > 0
- && m_nCurIndex >= 0
- )
- {
- nit = __NI_PREV;
- break;
- }
- else if( m_pWndParentMenu == NULL )
- {
- if( CExtToolControlBar::g_bMenuTracking )
- ::PostMessage(
- m_hWndCmdReceiver,
- bRTL ? CExtPopupMenuWnd::g_nMsgPopupNext : CExtPopupMenuWnd::g_nMsgPopupPrev,
- 0,
- LPARAM( this )
- );
- return true;
- }
- else
- {
- ASSERT( !m_bTopLevel );
- int nParentCurIndex =
- m_pWndParentMenu->m_nCurIndex;
- ASSERT(
- nParentCurIndex >= 0
- &&
- nParentCurIndex <=
- m_pWndParentMenu->m_items_all.GetSize()
- );
- HWND hWndOwn = m_hWnd;
- //::ReleaseCapture();
- m_pWndParentMenu->_SetCapture();
- m_pWndParentMenu->_ItemFocusCancel(
- FALSE
- );
- m_pWndParentMenu->_ItemFocusSet(
- nParentCurIndex,
- FALSE,
- TRUE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- m_pWndParentMenu->_SetCapture();
- return true;
- }
- // case VK_ESCAPE:
- // _EndSequence();
- // return true;
-
- case VK_UP:
- if( nChar == VK_UP
- && ItemGetCount() > 0
- && 0 <= m_nCurIndex
- && m_nCurIndex < ItemGetCount()
- && (! ItemGetInfo(m_nCurIndex).IsIconMode() )
- )
- nit = __NI_PREV;
- else
- nit = _IsPalette() ? __NI_ROW_PREV : __NI_PREV;
- break; // case VK_UP
- case VK_DOWN:
- if( IsKeyPressed( VK_CONTROL ) )
- {
- if( m_bExpandAvailable )
- _DoExpand();
- return true;
- }
- if( ItemGetCount() > 0
- && 0 <= m_nCurIndex
- && m_nCurIndex < ItemGetCount()
- && (! ItemGetInfo(m_nCurIndex).IsIconMode() )
- )
- nit = __NI_NEXT;
- else
- nit = _IsPalette() ? __NI_ROW_NEXT : __NI_NEXT;
- break; // case VK_DOWN
- case VK_NEXT:
- nit = __NI_PAGE_DOWN;
- break; // case VK_NEXT
- case VK_PRIOR:
- nit = __NI_PAGE_UP;
- break; // case VK_PRIOR
- default:
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- if( _KeyTipsEnabledGet() )
- { // BLOCK: key tip processing
- if( ( _T('A') <= nChar && nChar <= _T('Z') )
- || ( _T('0') <= nChar && nChar <= _T('9') )
- )
- {
- if( _KeyTipsTranslate( nChar ) )
- return true;
- }
- } // BLOCK: key tip processing
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- { // BLOCK: try analyze quick char access
- if( IsKeyPressed(VK_SHIFT)
- || IsKeyPressed(VK_CONTROL)
- // || IsKeyPressed(VK_MENU)
- // || ( (nFlags & (1<<29)) != 0 ) // ALT pressed?
- )
- return false;
- BYTE lpKeyState[256];
- ::GetKeyboardState( lpKeyState );
- UINT wScanCode = ::MapVirtualKey( nChar, 0 );
- HKL hKeyboardLayout =
- ::GetKeyboardLayout(
- ( ::AfxGetThread() ) -> m_nThreadID
- );
- #if (defined _UNICODE)
- TCHAR szChar[2] = { _T(' '), _T(' ') };
- ::ToUnicodeEx( nChar, wScanCode, lpKeyState, szChar, 1, 1, hKeyboardLayout );
- WORD nMapped = WORD( szChar[0] );
- #else
- WORD nMapped = 0;
- ::ToAsciiEx( nChar, wScanCode, lpKeyState, &nMapped, 1, hKeyboardLayout );
- //TCHAR szChar[2] = { (TCHAR)nMapped, _T(' ') };
- #endif
- BOOL bSearchDisplayedOnly = FALSE;
- INT nNextIdx =
- ItemFindByAccessChar(
- (TCHAR)nMapped,
- m_nCurIndex,
- TRUE,
- bSearchDisplayedOnly
- );
- if( (! bSearchDisplayedOnly )
- && nNextIdx >= 0
- && m_bExpandAvailable
- && (! m_bExpandWasPressed )
- )
- {
- MENUITEMDATA & miNext = ItemGetInfo( nNextIdx );
- if( (! miNext.IsDisplayed() )
- && ( ItemFindByAccessChar(
- (TCHAR)nMapped,
- nNextIdx,
- TRUE,
- bSearchDisplayedOnly
- ) >= 0
- || miNext.IsPopup()
- )
- )
- {
- KillTimer( ID_TIMER_DELAY_EXPAND );
- bool bSavedMenuExpandAnimation = g_bMenuExpandAnimation;
- g_bMenuExpandAnimation = false;
- _DoExpand();
- _EndAnimation();
- KillTimer( ID_TIMER_ANIMATION );
- m_bAnimFinished = true;
- GetSite().SetAnimated( NULL );
- _DoReCreateShadows();
- g_bMenuExpandAnimation = bSavedMenuExpandAnimation;
- CClientDC dc( this );
- _DoPaint( dc );
- }
- if( miNext.IsPopup() )
- {
- _ItemFocusSet( nNextIdx, TRUE, TRUE, TRUE );
- return true;
- }
- }
- if( nNextIdx < 0
- && m_nCurIndex >= 0
- && ItemFindByAccessChar(
- (TCHAR)nMapped,
- -1,
- TRUE,
- bSearchDisplayedOnly
- )
- == m_nCurIndex
- )
- { // if only 1 with this char
- MENUITEMDATA & mi = ItemGetInfo( m_nCurIndex );
- if( mi.IsInplaceEdit() && (!mi.IsPopup()) )
- {
- CWnd * pWndInplace = mi.GetInplaceEditPtr();
- if( pWndInplace != NULL )
- {
- ASSERT_VALID( pWndInplace );
- ASSERT( pWndInplace->GetSafeHwnd() != NULL && (::IsWindow(pWndInplace->GetSafeHwnd())) );
- if( mi.IsAllowInplaceEditActivation() )
- {
- if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- {
- CRect rcInplaceEdit;
- _GetItemRect( m_nCurIndex, rcInplaceEdit );
- rcInplaceEdit =
- mi.AdjustInplaceEditRect(
- rcInplaceEdit,
- OnQueryLayoutRTL()
- );
- pWndInplace->SetWindowPos(
- NULL,
- rcInplaceEdit.left, rcInplaceEdit.top,
- rcInplaceEdit.Width(), rcInplaceEdit.Height(),
- SWP_NOZORDER|SWP_NOOWNERZORDER
- |SWP_NOACTIVATE|SWP_SHOWWINDOW
- );
- } // if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- pWndInplace->SetFocus();
- } // if( mi.IsAllowInplaceEditActivation() )
- } // if( pWndInplace != NULL )
- return true;
- } // if( mi.IsInplaceEdit() && (!mi.IsPopup()) )
- if( mi.IsExtraMark() && (! _FindHelpMode() ) )
- {
- ASSERT( mi.GetExtraMarkCallback() != NULL );
- mi.GetExtraMarkCallback()( this, &mi );
- CClientDC dc( this );
- _DoPaint( dc );
- return true;
- } // if( mi.IsExtraMark() ...
- if( mi.IsPopup() )
- {
- _ItemFocusSet( m_nCurIndex, TRUE, TRUE );
- return true;
- }
- if( mi.IsExecutableCmdID() )
- {
- if( !( mi.GetCmdDeliverCb() != NULL
- && mi.GetCmdDeliverCb()( this, &mi )
- )
- )
- _EndSequenceEx( mi );
- return true;
- } // if( mi.IsExecutableCmdID() )
- } // if only 1 with this char
- if( m_nCurIndex != nNextIdx
- && nNextIdx >= 0
- )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet( nNextIdx, TRUE, TRUE );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- if( ItemFindByAccessChar(
- (TCHAR)nMapped,
- nNextIdx
- ) < 0
- )
- { // if only 1 with this char
- MENUITEMDATA & mi =
- ItemGetInfo( nNextIdx );
- if( mi.IsInplaceEdit() && (!mi.IsPopup()) )
- {
- CWnd * pWndInplace = mi.GetInplaceEditPtr();
- if( pWndInplace != NULL )
- {
- ASSERT_VALID( pWndInplace );
- ASSERT( pWndInplace->GetSafeHwnd() != NULL && (::IsWindow(pWndInplace->GetSafeHwnd())) );
- if( mi.IsAllowInplaceEditActivation() )
- {
- if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- {
- CRect rcInplaceEdit;
- _GetItemRect( nNextIdx, rcInplaceEdit );
- rcInplaceEdit =
- mi.AdjustInplaceEditRect(
- rcInplaceEdit,
- OnQueryLayoutRTL()
- );
- pWndInplace->SetWindowPos(
- NULL,
- rcInplaceEdit.left, rcInplaceEdit.top,
- rcInplaceEdit.Width(), rcInplaceEdit.Height(),
- SWP_NOZORDER|SWP_NOOWNERZORDER
- |SWP_NOACTIVATE|SWP_SHOWWINDOW
- );
- } // if( (pWndInplace->GetStyle() & WS_VISIBLE) == 0 )
- pWndInplace->SetFocus();
- } // if( mi.IsAllowInplaceEditActivation() )
- } // if( pWndInplace != NULL )
- return true;
- } // if( mi.IsInplaceEdit() && (!mi.IsPopup()) )
- if( mi.IsExtraMark() && (! _FindHelpMode() ) )
- {
- ASSERT( mi.GetExtraMarkCallback() != NULL );
- mi.GetExtraMarkCallback()( this, &mi );
- CClientDC dc( this );
- _DoPaint( dc );
- return true;
- } // if( mi.IsExtraMark() ...
- if( mi.IsExecutableCmdID()
- //&& ( ! mi.IsPopup() )
- && _GetCapture() == this
- )
- {
- if( !( mi.GetCmdDeliverCb() != NULL
- && mi.GetCmdDeliverCb()( this, &mi )
- )
- )
- {
- _CancelingSet();
- _EndSequenceEx( mi );
- }
- return true;
- } // if( mi.IsExecutableCmdID() )
- } // if only 1 with this char
- return true;
- }
- } // BLOCK: try analyze quick char access
- { // BLOCK: help key processing
- const ACCEL * pAccel = _GetTranslatedContextHelpAccel();
- if( m_nCurIndex >= 0
- && pAccel != NULL
- && nChar == WPARAM(pAccel->key)
- && (pAccel->fVirt&(FSHIFT|FCONTROL|FALT)) ==
- ( 0
- | ( bShift ? (FSHIFT) : 0 )
- | ( bCtrl ? (FCONTROL) : 0 )
- | ( bAlt ? (FALT) : 0 )
- )
- )
- {
- MENUITEMDATA & mi = ItemGetInfo( m_nCurIndex );
- if( ( ! mi.IsPopup() ) && ( ! mi.IsExtraMark() ) )
- {
- UINT nHitTestCmdID = mi.GetCmdID();
- bNoEat = false;
- _EndSequence();
- ::AfxGetApp()->WinHelp( nHitTestCmdID, HELP_CONTEXT );
- return true;
- } // if( ( ! mi.IsPopup() ) && ( ! mi.IsExtraMark() ) )
- } // if( m_nCurIndex >= 0 ...
- } // BLOCK: help key processing
- } // switch( nChar )
- if( nit != __NI_NOTHING )
- {
- int nItemIndex = _GetNextItem(nit);
- if( m_items_all.GetSize() > 0
- && nItemIndex >= 0
- && nItemIndex != m_nCurIndex
- )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet(
- nItemIndex,
- FALSE,
- TRUE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- return true; // false;
- }
- if( nItemIndex == IDX_EXPAND )
- {
- ASSERT( m_bExpandAvailable );
- ASSERT( !m_bExpandWasPressed );
- int nItemIndex = m_nCurIndex;
- HWND hWndOwn = m_hWnd;
- _DoExpand();
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- if( nItemIndex >= 0 )
- {
- HWND hWndOwn = m_hWnd;
- _ItemFocusSet(
- nItemIndex,
- FALSE,
- //m_bAnimFinished
- ( GetSite().GetAnimated() == NULL )
- ? TRUE : FALSE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- int i = _GetNextItem(__NI_NEXT);
- _ItemFocusSet(
- (i>0) ? i : nItemIndex,
- FALSE,
- //m_bAnimFinished
- ( GetSite().GetAnimated() == NULL )
- ? TRUE : FALSE
- );
- if( ! ::IsWindow( hWndOwn ) )
- return true;
- }
- return true;
- }
- } // if( nit != __NI_NOTHING )
- return false;
- }
- INT CExtPopupMenuWnd::ItemFindByText(
- __EXT_MFC_SAFE_LPCTSTR sText,
- INT nStartIdx, // = -1
- BOOL bRestartAt0 // = TRUE
- ) const
- {
- bRestartAt0;
- ASSERT_VALID( this );
- if( sText == NULL || sText[0] == _T(' ') )
- {
- ASSERT( FALSE );
- return -1;
- }
- int nCount = (int)m_items_all.GetSize(); //ItemGetCount();
- int nIdx = (nStartIdx >= 0) ? (nStartIdx + 1) : 0;
- for( ; nIdx < nCount; nIdx++ )
- {
- const MENUITEMDATA & mi = ItemGetInfo(nIdx);
- // if( !mi.AccelCharIsSet() )
- // continue;
- // if( !mi.IsDisplayed() )
- // continue;
- // if( !mi.IsEnabled() )
- // continue;
- if( _tcscmp( sText, mi.GetText() ) == 0 )
- {
- if( nStartIdx != nIdx )
- return nIdx;
- }
- } // for( nIdx = nStartIdx; nIdx < nCount; nIdx++ )
- if( nStartIdx == 0 )
- return -1;
- for( nIdx = 0; nIdx<nStartIdx; nIdx++ )
- {
- const MENUITEMDATA & mi = ItemGetInfo(nIdx);
- // if( !mi.AccelCharIsSet() )
- // continue;
- // if( !mi.IsDisplayed() )
- // continue;
- // if( !mi.IsEnabled() )
- // continue;
- if( _tcscmp( sText, mi.GetText() ) == 0 )
- {
- if( nStartIdx != nIdx )
- return nIdx;
- }
- } // for( nIdx = 0; nIdx<nStartIdx; nIdx++ )
- return -1;
- }
- INT CExtPopupMenuWnd::ItemFindByAccessChar(
- __EXT_MFC_SAFE_TCHAR chrAccess,
- INT nStartIdx, // = -1
- BOOL bRestartAt0, // = TRUE
- BOOL bSearchDisplayedOnly // = TRUE
- ) const
- {
- ASSERT_VALID( this );
- if( chrAccess == _T(' ') )
- return -1;
- TCHAR szChar[2] = { chrAccess, _T(' ') };
- ::CharUpper( szChar );
- int cAccelSearch = szChar[0];
- if( cAccelSearch == _T(' ') )
- return -1;
- int nCount = (int)m_items_all.GetSize(); //ItemGetCount();
- int nIdx = ( nStartIdx >= 0 ) ? ( nStartIdx + 1 ) : 0;
- if( nIdx >= nCount && bRestartAt0 )
- nIdx = 0;
- for( ; nIdx < nCount; nIdx++ )
- {
- const MENUITEMDATA & mi = ItemGetInfo(nIdx);
- if( ! mi.AccelCharIsSet() )
- continue;
- if( ! mi.IsDisplayed() )
- {
- if( bSearchDisplayedOnly )
- continue;
- }
- if( ! mi.IsEnabled() )
- continue;
- TCHAR cAccel = mi.AccelCharGet();
- if( cAccelSearch == cAccel )
- {
- if( nStartIdx != nIdx )
- return nIdx;
- }
- } // for( nIdx = nStartIdx; nIdx < nCount; nIdx++ )
- if( nStartIdx == 0 )
- return -1;
- for( nIdx = 0; nIdx<nStartIdx; nIdx++ )
- {
- const MENUITEMDATA & mi = ItemGetInfo(nIdx);
- if( ! mi.AccelCharIsSet() )
- continue;
- if( ! mi.IsDisplayed() )
- {
- if( bSearchDisplayedOnly )
- continue;
- }
- if( ! mi.IsEnabled() )
- continue;
- TCHAR cAccel = mi.AccelCharGet();
- if( cAccelSearch == cAccel )
- {
- if( nStartIdx != nIdx )
- return nIdx;
- }
- } // for( nIdx = 0; nIdx<nStartIdx; nIdx++ )
- return -1;
- }
- BOOL CExtPopupMenuWnd::IsCmdKeyActivation(
- LPARAM lParam // = 0
- )
- {
- if( (lParam & (1<<29)) != 0 ) // ALT pressed?
- return TRUE;
-
- static int nTestKeys[] = {
- VK_MENU,VK_RMENU,VK_LMENU,
- VK_CONTROL,VK_RCONTROL,VK_LCONTROL,
- VK_SHIFT,VK_RSHIFT,VK_LSHIFT
- };
- for( int i=0; i<sizeof(nTestKeys)/sizeof(int); i++ )
- {
- if( IsKeyPressed(nTestKeys[i]) )
- {
- // if( nTestKeys[i] == VK_CONTROL
- // || nTestKeys[i] == VK_RCONTROL
- // || nTestKeys[i] == VK_LCONTROL
- // )
- // {
- // if( IsKeyPressed(VK_DOWN) )
- // return FALSE;
- // }
- return TRUE;
- }
- }
- return FALSE;
- }
- INT CExtPopupMenuWnd::ItemGetCount() const
- {
- ASSERT_VALID( this );
- INT nCountOfItems = INT(m_items_all.GetSize());
- return nCountOfItems;
- }
- INT CExtPopupMenuWnd::ItemFindPosForCmdID(
- UINT nCmdID,
- INT nPosStart // = -1
- ) const
- {
- ASSERT_VALID( this );
- INT nPos = (nPosStart < 0) ? 0 : nPosStart + 1;
- INT nCount = ItemGetCount();
- for( ; nPos < nCount; nPos++ )
- {
- UINT nCmdID2 = ItemGetCmdID( nPos );
- if( nCmdID == nCmdID2 )
- return nPos;
- }
- return -1; // not found
- }
- UINT CExtPopupMenuWnd::ItemGetCmdID( // menu_item_type_t values can be returned
- INT nPos
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return TYPE_SEPARATOR;
- }
- const MENUITEMDATA & mi = ItemGetInfo(nPos);
- UINT nCmdID = mi.GetCmdID();
- return nCmdID;
- }
- bool CExtPopupMenuWnd::ItemSetPopupIcon(
- INT nPos,
- HICON hIcon // = NULL // no icon by default
- )
- {
- ASSERT_VALID( this );
- CExtCmdIcon _icon;
- if( hIcon != NULL )
- _icon.AssignFromHICON( hIcon, false );
- return ItemSetPopupIcon( nPos, _icon );
- }
- bool CExtPopupMenuWnd::ItemSetPopupIcon(
- INT nPos,
- const CExtCmdIcon & _icon
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return false;
- }
- MENUITEMDATA & mi = ItemGetInfo( nPos );
- return mi.SetPopupIcon( _icon );
- }
- bool CExtPopupMenuWnd::ItemSetPopupText(
- INT nPos,
- __EXT_MFC_SAFE_LPCTSTR sText // NULL if empty
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return false;
- }
- MENUITEMDATA & mi = ItemGetInfo(nPos);
- if( !mi.SetPopupText( sText ) )
- return false;
- mi.MeasureItem( NULL );
- return true;
- }
- bool CExtPopupMenuWnd::ItemSetPopupAccelText(
- INT nPos,
- __EXT_MFC_SAFE_LPCTSTR sText // NULL if empty
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return false;
- }
- MENUITEMDATA & mi = ItemGetInfo(nPos);
- bool bRetVal = mi.SetPopupAccelText( sText );
- if( bRetVal )
- _SyncItems();
- return bRetVal;
- }
- CExtCmdIcon & CExtPopupMenuWnd::ItemGetIcon( INT nPos )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- static CExtCmdIcon g_EmptyIcon;
- return g_EmptyIcon;
- }
- const MENUITEMDATA & mi = ItemGetInfo(nPos);
- CExtCmdIcon & _icon = ((MENUITEMDATA &)mi).GetIcon();
- return _icon;
- }
- const CExtCmdIcon & CExtPopupMenuWnd::ItemGetIcon( INT nPos ) const
- {
- ASSERT_VALID( this );
- return
- ( const_cast < CExtPopupMenuWnd * > ( this ) )
- -> ItemGetIcon( nPos );
- }
- CExtPopupMenuWnd::MENUITEMDATA & CExtPopupMenuWnd::ItemGetInfo( INT nPos )
- {
- ASSERT_VALID( this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- AfxThrowNotSupportedException();
- }
- return _GetItemRef( nPos );
- }
- const CExtPopupMenuWnd::MENUITEMDATA & CExtPopupMenuWnd::ItemGetInfo( INT nPos ) const
- {
- ASSERT_VALID( this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- AfxThrowNotSupportedException();
- }
- return _GetItemRef( nPos );
- }
- CExtSafeString CExtPopupMenuWnd::ItemGetText( INT nPos ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return CExtSafeString( _T("") );
- }
- const MENUITEMDATA & mi = ItemGetInfo( nPos );
- return CExtSafeString( mi.GetText() );
- }
- CExtSafeString CExtPopupMenuWnd::ItemGetAccelText( INT nPos ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return CExtSafeString( _T("") );
- }
- const MENUITEMDATA & mi = ItemGetInfo(nPos);
- return CExtSafeString( mi.GetAccelText() );
- }
- bool CExtPopupMenuWnd::ItemIsDisplayed(
- INT nPos
- ) const
- {
- const MENUITEMDATA & mi = ItemGetInfo( nPos );
- return mi.IsDisplayed();
- }
- void CExtPopupMenuWnd::ItemSetDisplayed(
- INT nPos,
- bool bForceDisplayed // = true
- )
- {
- MENUITEMDATA & mi = ItemGetInfo( nPos );
- mi.SetForceDisplayed( bForceDisplayed );
- _SyncItems();
- }
- CExtPopupMenuWnd * CExtPopupMenuWnd::ItemGetPopup(
- INT nPos
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- const CExtPopupMenuWnd * pChild =
- ( (const CExtPopupMenuWnd *) this) ->
- ItemGetPopup( nPos );
- if( pChild == NULL )
- return NULL;
- return
- const_cast
- < CExtPopupMenuWnd * >
- (pChild);
- }
- CExtPopupMenuWnd::TEAROFFNOTIFICATON *
- CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- g_pCurrentTEAROFFNOTIFICATON = NULL;
- CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- TEAROFFNOTIFICATON(
- CExtPopupMenuWnd * pPopup,
- const POINT & ptScreenStartPos
- )
- : m_hWndTearOff( NULL )
- , m_hWndHelperPopup( pPopup->GetSafeHwnd() )
- , m_hWndHelperFloat( NULL )
- , m_bHelperForceFloatInvisible( false )
- , m_pPopup( pPopup )
- , m_pHelperTearOffBar( NULL )
- , m_ptScreenStartPos( ptScreenStartPos )
- , m_sizeTearOffArea( 5, 5 )
- , m_rcHelperScreenStartArea( ptScreenStartPos, ptScreenStartPos )
- , m_rcCustomFloatPos( 0, 0, 0, 0 )
- , m_bHelperMenuAreasUpdated( false )
- , m_eTONT( CExtPopupMenuWnd::__ETONT_BEGIN )
- , m_bCanceled( false )
- , m_bFinished( false )
- {
- m_rcHelperScreenStartArea.InflateRect( m_sizeTearOffArea );
- ASSERT_VALID( m_pPopup );
- ASSERT( m_hWndHelperPopup != NULL && ::IsWindow(m_hWndHelperPopup) );
- }
- CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- ~TEAROFFNOTIFICATON()
- {
- CExtHookSink::RemoveAllWndHooks();
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- Notify()
- {
- HWND hWndNotifyTarget = m_pPopup->GetCmdReceiverHWND();
- if( hWndNotifyTarget == NULL || (! ::IsWindow(hWndNotifyTarget) ) )
- return false;
- m_eTONT = CExtPopupMenuWnd::__ETONT_BEGIN;
- ::SendMessage(
- hWndNotifyTarget,
- CExtPopupMenuWnd::g_nMsgTearOff,
- *this,
- 0L
- );
- if( m_hWndTearOff == NULL
- || (! ::IsWindow(m_hWndTearOff) )
- || m_bCanceled
- )
- return false;
- m_pHelperTearOffBar = NULL;
- CWnd * pWnd = CWnd::FromHandlePermanent( m_hWndTearOff );
- if( pWnd != NULL )
- {
- m_pHelperTearOffBar =
- DYNAMIC_DOWNCAST( CExtControlBar, pWnd );
- if( m_pHelperTearOffBar != NULL )
- {
- if( m_pHelperTearOffBar->m_pDockSite == NULL )
- {
- ASSERT( FALSE );
- m_pHelperTearOffBar = NULL;
- }
- }
- }
- return DoDefaultTearOff();
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- DoDefaultTearOff()
- {
- g_pCurrentTEAROFFNOTIFICATON = this;
- m_eTONT = CExtPopupMenuWnd::__ETONT_UPDATE;
- m_bHelperForceFloatInvisible = false;
- if( m_hWndHelperFloat == NULL )
- {
- if( m_pHelperTearOffBar != NULL )
- {
- if( m_pHelperTearOffBar->IsFloating() )
- m_hWndHelperFloat =
- m_pHelperTearOffBar->
- GetParentFrame()->
- GetSafeHwnd();
- } // if( m_pHelperTearOffBar != NULL )
- else
- m_hWndHelperFloat = m_hWndTearOff;
- } // if( m_hWndHelperFloat == NULL )
- if( m_hWndHelperFloat != NULL )
- {
- ASSERT( m_hWndHelperFloat != NULL && ::IsWindow(m_hWndHelperFloat) );
- CExtHookSink::SetupHookWndSink( m_hWndHelperFloat );
- } // if( m_hWndHelperFloat != NULL )
- for( ; !( m_bFinished || m_bCanceled); )
- {
- if( ! ::IsWindow(m_hWndHelperPopup) )
- break;
- if( ! ::IsWindow(m_hWndTearOff) )
- {
- m_bFinished = false;
- m_bCanceled = true;
- break;
- }
- CExtPopupMenuWnd::PassMsgLoop( false );
- DoStep();
- CExtPaintManager::stat_PassPaintMessages();
- } // for( ; !( m_bFinished || m_bCanceled); )
- ::ReleaseCapture();
- CExtHookSink::RemoveAllWndHooks();
- if( ::IsWindow(m_hWndHelperPopup) )
- {
- ASSERT_VALID( m_pPopup );
- HWND hWndNotifyTarget = m_pPopup->GetCmdReceiverHWND();
- if( hWndNotifyTarget != NULL && ::IsWindow(hWndNotifyTarget) )
- {
- m_eTONT = CExtPopupMenuWnd::__ETONT_FINISH;
- ::SendMessage(
- hWndNotifyTarget,
- CExtPopupMenuWnd::g_nMsgTearOff,
- *this,
- 0L
- );
- } // if( hWndNotifyTarget != NULL && ::IsWindow(hWndNotifyTarget) )
- if( ::IsWindow(m_hWndHelperPopup) )
- {
- ASSERT_VALID( m_pPopup );
- if( (m_pPopup->GetStyle()&WS_VISIBLE) == 0 )
- {
- CExtToolControlBar::_CloseCustomMenusAll();
- CExtPopupMenuWnd::CancelMenuTracking();
- if( CExtToolControlBar::g_bMenuTracking )
- CExtToolControlBar::_CloseTrackingMenus();
- } // if( (m_pPopup->GetStyle()&WS_VISIBLE) == 0 )
- } // if( ::IsWindow(m_hWndHelperPopup) )
- } // if( ::IsWindow(m_hWndHelperPopup) )
- if( LPVOID(g_pCurrentTEAROFFNOTIFICATON) == LPVOID(this) )
- g_pCurrentTEAROFFNOTIFICATON = NULL;
- return m_bFinished;
- }
- void CExtPopupMenuWnd::TEAROFFNOTIFICATON::DoStep(
- bool bFinalStep // = false
- )
- {
- bFinalStep;
- if( m_bFinished )
- return;
- if( (! ::IsWindow(m_hWndTearOff) )
- || (! ::IsWindow(m_hWndHelperPopup) )
- || ( m_pPopup == NULL )
- || ( CWnd::FromHandlePermanent(m_hWndHelperPopup) != m_pPopup )
- )
- return;
- ASSERT_VALID( m_pPopup );
- HWND hWndNotifyTarget = m_pPopup->GetCmdReceiverHWND();
- ASSERT( hWndNotifyTarget != NULL && ::IsWindow(hWndNotifyTarget) );
- m_eTONT = CExtPopupMenuWnd::__ETONT_UPDATE;
- ::SendMessage(
- hWndNotifyTarget,
- CExtPopupMenuWnd::g_nMsgTearOff,
- *this,
- 0L
- );
- if( m_pHelperTearOffBar != NULL
- && m_pHelperTearOffBar->GetSafeHwnd() != NULL
- && m_pHelperTearOffBar->m_pDockSite->GetSafeHwnd() != NULL
- )
- {
- ASSERT_VALID( m_pHelperTearOffBar );
- ASSERT( m_pHelperTearOffBar->GetSafeHwnd() == m_hWndTearOff );
- ASSERT_VALID( m_pHelperTearOffBar->m_pDockSite );
- CPoint ptCursorScreen;
- if( ! ::GetCursorPos( &ptCursorScreen ) )
- {
- m_bCanceled = true;
- return;
- }
- if( PtInTearOffArea(ptCursorScreen) )
- {
- if( (m_pPopup->GetStyle()&WS_VISIBLE) == 0 )
- {
- if( m_pHelperTearOffBar->IsVisible() )
- m_pHelperTearOffBar->m_pDockSite->
- ShowControlBar( m_pHelperTearOffBar, FALSE, FALSE );
- m_bHelperForceFloatInvisible = true;
- CExtPaintManager::stat_PassPaintMessages();
- m_pPopup->SetWindowPos(
- NULL, 0, 0, 0, 0,
- SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOREDRAW
- |SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOSIZE
- // |SWP_NOSENDCHANGING
- );
- CExtPopupMenuWnd * pPopup = m_pPopup->GetParentMenuWnd();
- for( int iNL = 0; pPopup != NULL; pPopup = pPopup->GetParentMenuWnd(), iNL++ )
- {
- pPopup->m_ShadowCMBA.PostReShadow();
- pPopup->m_ShadowMain.PostReShadow();
- CClientDC dc( pPopup );
- pPopup->_DoPaint( dc );
- }
- CClientDC dc( m_pPopup );
- m_pPopup->_DoPaint( dc );
- m_bHelperForceFloatInvisible = false;
- } // if( (m_pPopup->GetStyle()&WS_VISIBLE) == 0 )
- if( m_pPopup->m_ctrlShadow.GetSafeHwnd() != NULL
- && (m_pPopup->m_ctrlShadow.GetStyle()&WS_VISIBLE) == 0
- )
- m_pPopup->m_ctrlShadow.ShowWindow( SW_SHOWNA );
- } // if( PtInTearOffArea(ptCursorScreen) )
- else
- {
- bool bDoRecreateShadow = false;
- if( ! m_bHelperMenuAreasUpdated )
- {
- m_bHelperMenuAreasUpdated = true;
- if( m_pHelperTearOffBar->IsVisible() )
- {
- m_pHelperTearOffBar->m_pDockSite->
- ShowControlBar( m_pHelperTearOffBar, FALSE, FALSE );
- CExtPaintManager::stat_PassPaintMessages();
- bDoRecreateShadow = true;
- if( m_pHelperTearOffBar->IsFloating() )
- {
- CRect rcFloatingArea;
- m_pHelperTearOffBar->GetParentFrame()->
- GetWindowRect( &rcFloatingArea );
- if( ! m_pPopup->_IsFloatingAreaInstersectsWithMenu(
- rcFloatingArea
- )
- )
- bDoRecreateShadow = false;
- } // if( m_pHelperTearOffBar->IsFloating() )
- } // if( m_pHelperTearOffBar->IsVisible() )
- } // if( ! m_bHelperMenuAreasUpdated )
- #if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- if( (! m_pHelperTearOffBar->IsFixedDockStyle())
- && ( m_pHelperTearOffBar->AutoHideModeGet() )
- )
- {
- m_pHelperTearOffBar->AutoHideModeSet( false, false, true, true );
- bDoRecreateShadow = true;
- }
- #endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- if( bDoRecreateShadow )
- {
- CExtPaintManager::stat_PassPaintMessages();
- m_pPopup->_DoReCreateShadows();
- }
- { // block
- CExtPopupMenuWnd * pPopup = m_pPopup;
- for( ; pPopup != NULL; pPopup = pPopup->GetParentMenuWnd() )
- {
- if( ( pPopup->GetStyle() & WS_VISIBLE ) != 0
- && pPopup->m_ctrlShadow.GetSafeHwnd() != NULL
- )
- {
- CExtPaintManager::stat_PassPaintMessages();
- pPopup->m_ctrlShadow.SetWindowPos(
- pPopup, 0, 0, 0, 0,
- SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW
- );
- }
- }
- } // block
- if( (m_pPopup->GetStyle()&WS_VISIBLE) != 0 )
- m_pPopup->ShowWindow( SW_HIDE );
- if( m_pPopup->m_ctrlShadow.GetSafeHwnd() != NULL
- && (m_pPopup->m_ctrlShadow.GetStyle()&WS_VISIBLE) != 0
- )
- m_pPopup->m_ctrlShadow.ShowWindow( SW_HIDE );
- CPoint ptFloat(
- ptCursorScreen.x - 30,
- ptCursorScreen.y - 10
- );
- CRect rcParentFrame;
- m_pHelperTearOffBar->GetParentFrame()->GetWindowRect( &rcParentFrame );
- if( rcParentFrame.TopLeft() != ptFloat )
- {
- CExtPaintManager::stat_PassPaintMessages();
- m_pHelperTearOffBar->FloatControlBar(
- ptFloat
- );
- }
- if( m_hWndHelperFloat == NULL
- && m_pHelperTearOffBar != NULL
- && m_pHelperTearOffBar->IsFloating()
- )
- {
- m_hWndHelperFloat =
- m_pHelperTearOffBar->
- GetParentFrame()->
- GetSafeHwnd();
- ASSERT(
- m_hWndHelperFloat != NULL
- && ::IsWindow( m_hWndHelperFloat )
- );
- CExtHookSink::SetupHookWndSink( m_hWndHelperFloat );
- } // if( m_hWndHelperFloat == NULL )
- if( ! m_pHelperTearOffBar->IsVisible() )
- m_pHelperTearOffBar->m_pDockSite->
- ShowControlBar( m_pHelperTearOffBar, TRUE, FALSE );
- CRect rcTearOffBar;
- m_pHelperTearOffBar->GetWindowRect( &rcTearOffBar );
- CExtPopupMenuWnd * pPopup = m_pPopup;
- for( int iNL = 0; pPopup != NULL; pPopup = pPopup->GetParentMenuWnd(), iNL++ )
- {
- if( (pPopup->GetStyle()&WS_VISIBLE) == 0 )
- continue;
- CRect rcPopup;
- pPopup->GetWindowRect( &rcPopup );
- CRect rcIntersecton;
- if( ! rcIntersecton.IntersectRect(
- &rcTearOffBar,
- &rcPopup
- )
- )
- continue;
- CClientDC dc( pPopup );
- pPopup->_DoPaint( dc );
- }
- } // else from if( PtInTearOffArea(ptCursorScreen) )
- } // if( m_pHelperTearOffBar != NULL ...
- else
- {
- m_bCanceled = true; // this mode not supported yet
- return;
- } // else from if( m_pHelperTearOffBar != NULL ...
- if( ::GetCapture() != m_hWndTearOff )
- ::SetCapture( m_hWndTearOff );
- }
- bool CExtPopupMenuWnd::_IsFloatingAreaInstersectsWithMenu(
- const RECT & rcFloatingArea,
- bool bAnalyzeParents // = true
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CRect rcWnd;
- ::GetWindowRect( GetSafeHwnd(), &rcWnd );
- CRect rcIntersecton;
- if( rcIntersecton.IntersectRect(
- &rcWnd,
- &rcFloatingArea
- )
- )
- return true;
- if( ! bAnalyzeParents )
- return false;
- const CExtPopupMenuWnd * pParentMenuWnd = GetParentMenuWnd();
- if( pParentMenuWnd == NULL )
- return false;
- return
- pParentMenuWnd->_IsFloatingAreaInstersectsWithMenu(
- rcFloatingArea,
- true
- );
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- PtInTearOffArea( const POINT & ptScreen ) const
- {
- ASSERT( m_sizeTearOffArea.cx >= 0 && m_sizeTearOffArea.cy >= 0 );
- bool bRetVal =
- m_rcHelperScreenStartArea.PtInRect( ptScreen )
- ? true : false;
- if( bRetVal )
- return true;
- if( ! ::IsWindow( m_hWndHelperPopup ) )
- return false;
- ASSERT_VALID( m_pPopup );
- CRect rcTearOff;
- m_pPopup->_GetItemRect( CExtPopupMenuWnd::IDX_TEAROFF, rcTearOff, false );
- m_pPopup->ClientToScreen( &rcTearOff );
- rcTearOff.InflateRect( 0, 15 );
- bRetVal =
- rcTearOff.PtInRect( ptScreen )
- ? true : false;
- return bRetVal;
- }
- CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- operator WPARAM() const
- {
- return WPARAM( this );
- }
- CExtPopupMenuWnd::TEAROFFNOTIFICATON *
- CExtPopupMenuWnd::TEAROFFNOTIFICATON::
- FromWPARAM( WPARAM wParam )
- {
- TEAROFFNOTIFICATON * pTON =
- reinterpret_cast < TEAROFFNOTIFICATON * > ( wParam );
- ASSERT( pTON != NULL );
- return pTON;
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::_OnMouseWheel(
- WPARAM wParam,
- LPARAM lParam
- )
- {
- __PROF_UIS_MANAGE_STATE;
- wParam;
- lParam;
- if( LPVOID(g_pCurrentTEAROFFNOTIFICATON) != LPVOID(this) )
- return false;
- return true;
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::_OnMouseMove(
- UINT nFlags,
- CPoint point
- )
- {
- __PROF_UIS_MANAGE_STATE;
- nFlags;
- point;
- if( LPVOID(g_pCurrentTEAROFFNOTIFICATON) != LPVOID(this) )
- return false;
- DoStep( true );
- return true;
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::_OnMouseClick(
- UINT nFlags,
- CPoint point
- )
- {
- __PROF_UIS_MANAGE_STATE;
- nFlags;
- point;
- if( LPVOID(g_pCurrentTEAROFFNOTIFICATON) != LPVOID(this) )
- return false;
- switch( nFlags)
- {
- case WM_NCLBUTTONUP:
- case WM_NCRBUTTONUP:
- case WM_NCMBUTTONUP:
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- case WM_MBUTTONUP:
- DoStep( true );
- m_bFinished = true;
- if( ::IsWindow( m_hWndHelperPopup ) )
- ::PostMessage( m_hWndHelperPopup, WM_CANCELMODE, 0L, 0L );
- break;
- }
- return true;
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::_OnKeyDown(
- UINT nChar,
- UINT nRepCnt,
- UINT nFlags
- )
- {
- __PROF_UIS_MANAGE_STATE;
- nChar;
- nRepCnt;
- nFlags;
- if( LPVOID(g_pCurrentTEAROFFNOTIFICATON) != LPVOID(this) )
- return false;
- DoStep( true );
- m_bFinished = true;
- if( ::IsWindow( m_hWndHelperPopup ) )
- ::PostMessage( m_hWndHelperPopup, WM_CANCELMODE, 0L, 0L );
- return true;
- }
- bool CExtPopupMenuWnd::TEAROFFNOTIFICATON::OnHookWndMsg(
- LRESULT & lResult,
- HWND hWndHooked,
- UINT nMessage,
- WPARAM & wParam,
- LPARAM & lParam
- )
- {
- __PROF_UIS_MANAGE_STATE;
- if( m_hWndHelperFloat != NULL
- && ::IsWindow( m_hWndHelperFloat )
- && m_hWndHelperPopup != NULL
- && ::IsWindow( m_hWndHelperPopup )
- )
- {
- ASSERT_VALID( m_pPopup );
- bool bUpdateShadows = false;
- m_bHelperForceFloatInvisible = false;
- switch( nMessage )
- {
- case WM_SHOWWINDOW:
- bUpdateShadows = true;
- if( wParam == 0 )
- m_bHelperForceFloatInvisible = true;
- break;
- case WM_SIZE:
- case WM_WINDOWPOSCHANGED:
- if( m_pHelperTearOffBar == NULL )
- {
- __EXT_MFC_LONG_PTR dwStyle = ::__EXT_MFC_GetWindowLong(m_hWndHelperFloat,GWL_STYLE);
- bUpdateShadows = ( (dwStyle&WS_VISIBLE) != 0 ) ? true : false;
- }
- break;
- default:
- if( nMessage == CExtPopupMenuWnd::g_nMsgCustomFloatPos )
- {
- if( ((HWND)wParam) == m_hWndHelperFloat )
- {
- bUpdateShadows = true;
- LPRECT pRectCustomFloatPos = (LPRECT)lParam;
- ASSERT( pRectCustomFloatPos != NULL );
- m_rcCustomFloatPos = (*pRectCustomFloatPos);
- } // if( ((HWND)wParam) == m_hWndHelperFloat )
- } // if( nMessage == CExtPopupMenuWnd::g_nMsgCustomFloatPos )
- break;
- } // switch( nMessage )
- if( bUpdateShadows )
- {
- lResult =
- CExtHookSink::OnHookWndMsg(
- lResult,
- hWndHooked,
- nMessage,
- wParam,
- lParam
- );
- CExtPopupMenuWnd * pPopup = m_pPopup;
- for( ; pPopup != NULL;
- pPopup = pPopup->GetParentMenuWnd()
- )
- {
- if( ! pPopup->_IsPopupWithShadows() )
- continue;
- pPopup->Invalidate();
- }
- m_rcCustomFloatPos.SetRectEmpty();
- CExtPaintManager::stat_PassPaintMessages();
- return true;
- } // if( bUpdateShadows )
- }
- return
- CExtHookSink::OnHookWndMsg(
- lResult,
- hWndHooked,
- nMessage,
- wParam,
- lParam
- );
- }
- void CExtPopupMenuWnd::_DoReCreateShadows()
- {
- ASSERT( GetSafeHwnd() != NULL );
- m_ShadowMain.Destroy();
- m_ShadowCMBA.Destroy();
- if( m_ctrlShadow.GetSafeHwnd() == NULL )
- ShowWindow( SW_HIDE );
- CExtPopupMenuWnd * pWndParentMenu = GetParentMenuWnd();
- if( pWndParentMenu == NULL )
- {
- CWnd * pWndTLP = GetTopLevelParent();
- if( pWndTLP != NULL )
- pWndTLP->UpdateWindow();
- CExtPaintManager::stat_PassPaintMessages();
- }
- else
- {
- ASSERT( pWndParentMenu->GetSafeHwnd() != NULL );
- pWndParentMenu->_DoReCreateShadows();
- }
- SetWindowPos(
- NULL, 0, 0, 0, 0,
- SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOREDRAW
- |SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOSIZE
- // |SWP_NOSENDCHANGING
- );
- CClientDC dc( this );
- _DoPaint( dc );
- }
- void CExtPopupMenuWnd::_DoTearOff()
- {
- ASSERT_VALID( this );
- ASSERT( ! _FindCustomizeMode() );
- POINT ptScreen = { 0, 0 };
- if( ! ::GetCursorPos( &ptScreen ) )
- return;
- _CoolTipHide();
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- _KeyTipsShow( false );
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- TEAROFFNOTIFICATON _ton( this, ptScreen );
- _ton.Notify();
- }
- void CExtPopupMenuWnd::_DoExpand()
- {
- ASSERT_VALID( this );
- ASSERT( ! _FindCustomizeMode() );
- HWND hWndOwn = m_hWnd;
- _ItemFocusDelay();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- _CoolTipHide( false );
- if( ! ::IsWindow( hWndOwn ) )
- return;
- if( ( GetSite().GetAnimated() != NULL )
- || _CoolTipIsVisible()
- )
- return;
- m_bHelperReCreateDynamicShadowAtTheEndOfNearestAnimation = false;
- bool bDynamicShadowMode = false;
- if( m_ctrlShadow.GetSafeHwnd() != NULL )
- {
- bDynamicShadowMode = true;
- m_bHelperReCreateDynamicShadowAtTheEndOfNearestAnimation = true;
- }
- ASSERT( m_bExpandAvailable );
- ASSERT( !m_bExpandWasPressed );
- ASSERT( ::IsWindow(GetSafeHwnd()) );
- ASSERT( ( GetSite().GetAnimated() == NULL ) );
- m_bExpandWasPressed = true;
- CSize m_sizeFullItems2 = m_sizeFullItems;
- _SyncItems();
- _RecalcLayoutImpl();
- if( m_sizeFullItems != m_sizeFullItems2)
- { // if size of all items was changed
- // ASSERT(
- // m_sizeFullItems.cx >= m_sizeFullItems2.cx
- // && m_sizeFullItems.cy >= m_sizeFullItems2.cy
- // );
- CRect rcWndOld;
- GetWindowRect( &rcWndOld );
-
- VERIFY(
- SetWindowRgn(
- NULL,
- FALSE
- )
- );
- if( ! bDynamicShadowMode )
- {
- ShowWindow( SW_HIDE );
- ASSERT( !IsWindowVisible() );
- } // if( ! bDynamicShadowMode )
- if( !rcWndOld.IsRectEmpty() )
- {
- CWnd * pWndTLP = GetTopLevelParent();
- if( pWndTLP != NULL )
- {
- ASSERT_VALID( pWndTLP );
- if( pWndTLP->IsWindowVisible() )
- {
- CRect rcTLP;
- pWndTLP->GetWindowRect( &rcTLP );
- if( !rcTLP.IsRectEmpty() )
- {
- CRect rcIntersection;
- if( rcIntersection.IntersectRect(
- &rcTLP,
- &rcWndOld
- )
- )
- pWndTLP->UpdateWindow();
- } // if( !rcTLP.IsRectEmpty() )
- } // if( pWndTLP->IsWindowVisible() )
- } // if( pWndTLP != NULL )
- } // if( !rcWndOld.IsRectEmpty() )
- _FreeWinObjects();
- ASSERT( GetSafeHwnd() != NULL && ::IsWindow(GetSafeHwnd()) );
- ASSERT( ( GetSite().GetAnimated() == NULL ) );
- m_bAnimFinished = false;
- m_AnimationType = __AT_CONTENT_DISPLAY;
- ASSERT( GetSafeHwnd() != NULL && ::IsWindow(GetSafeHwnd()) );
- // adjust screen position
- CRect rcWnd = _CalcTrackRect();
-
- ASSERT( GetSafeHwnd() != NULL && ::IsWindow(GetSafeHwnd()) );
- if( rcWnd.top != rcWndOld.top
- && rcWnd.bottom != rcWndOld.bottom
- && m_ctrlShadow.GetSafeHwnd() != NULL
- )
- {
- m_ctrlShadow.DestroyWindow();
- m_bHelperReCreateDynamicShadowAtTheEndOfNearestAnimation = false;
- }
- if( m_rgnWnd.GetSafeHandle() != NULL )
- {
- ASSERT( m_bExcludeAreaSpec );
- ASSERT( m_bCombineWithEA );
- ASSERT( m_eCombineAlign != __CMBA_NONE );
- CRgn rgnTmp;
- VERIFY( rgnTmp.CreateRectRgn(0,0,0,0) );
- rgnTmp.CopyRgn( &m_rgnWnd );
- ASSERT( rgnTmp.GetSafeHandle() != NULL );
- VERIFY(
- SetWindowRgn(
- (HRGN)rgnTmp.Detach(),
- FALSE
- )
- );
- } // if( m_rgnWnd.GetSafeHandle() != NULL )
-
- m_bAnimFinished = true;
- m_ePlaySoundOnAnimationFinished =
- CExtSoundPlayer::__ON_MENU_EXPAND_CLICKED;
- m_AnimationType =
- g_bMenuExpandAnimation
- ? __AT_CONTENT_EXPAND
- : __AT_CONTENT_DISPLAY
- ;
- HWND hWndOwn = m_hWnd;
- _StartAnimation();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- if( m_AnimationType == __AT_NONE )
- {
- m_AnimationType = __AT_CONTENT_DISPLAY;
- _StartAnimation();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- ASSERT( m_AnimationType == __AT_CONTENT_DISPLAY );
- }
- if( m_bScrollingAvailable
- || _IsTearOff()
- )
- _RecalcLayoutImpl();
- SetWindowPos(
- NULL,
- rcWnd.left, rcWnd.top, rcWnd.Width(), rcWnd.Height(),
- SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOZORDER
- );
- ASSERT( IsWindowVisible() );
- } // if size of all items was changed
- else
- UpdateWindow();
- ASSERT( m_hWndCmdReceiver != NULL );
- ASSERT( ::IsWindow(m_hWndCmdReceiver) );
- ::SendMessage(
- m_hWndCmdReceiver,
- g_nMsgNotifyMenuExpanded,
- 0,
- LPARAM( this )
- );
- // if( bRestoreShadow )
- // {
- // CExtPopupMenuWnd * pPopup = this;
- // HWND hWndOwn = m_hWnd;
- // for( ; true; )
- // {
- // PassMsgLoop( false );
- // if( ! ::IsWindow(hWndOwn) )
- // return;
- // CWnd * pWndPermanent = CWnd::FromHandlePermanent( hWndOwn );
- // if( pWndPermanent == NULL )
- // return;
- // if( pWndPermanent != pPopup )
- // return;
- // if( m_bAnimFinished )
- // break;
- // }
- // if( m_ctrlShadow.GetSafeHwnd() != NULL )
- // m_ctrlShadow.DestroyWindow();
- // m_ctrlShadow.Create( m_hWnd, PmBridge_GetPM()->GetMenuShadowSize() );
- // }
- }
- bool CExtPopupMenuWnd::IsAllItemsRarelyUsed() const
- {
- ASSERT_VALID( this );
- INT _iter = 0;
- for( ; _iter < m_items_all.GetSize(); ++_iter )
- {
- const MENUITEMDATA & mi = ItemGetInfo( _iter );
- if( mi.IsDisplayed() || mi.IsExtraMark() )
- return false;
- } // for( ; _iter != m_items_all.end(); ++_iter )
- return true;
- }
- void CExtPopupMenuWnd::_SyncItems()
- {
- ASSERT_VALID( this );
- ASSERT( m_hWndCmdReceiver != NULL );
- ASSERT( ::IsWindow(m_hWndCmdReceiver) );
- if( _IsPalette() )
- {
- _SyncItemsPalette();
- return;
- }
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- DWORD dwTrackFlags = TrackFlagsGet();
- INT nIconAreaWidthLager = __EXT_MENU_ICON_CX + __EXT_MENU_GAP * 2;
- nIconAreaWidthLager = pPM->UiScalingDo( nIconAreaWidthLager, CExtPaintManager::__EUIST_X );
- int nItemIndex = 0, nItemCount = (int)m_items_all.GetSize();
- for( ; nItemIndex < nItemCount; nItemIndex++ )
- {
- MENUITEMDATA & _mii = ItemGetInfo( nItemIndex );
- int nWidth = _mii.GetIconAreaWidth();
- nIconAreaWidthLager =
- max( nIconAreaWidthLager, nWidth );
- _mii.CacheRectsEmpty();
- } // for( ; nItemIndex < nItemCount; nItemIndex++ )
- nIconAreaWidthLager =
- max( nIconAreaWidthLager, pPM->GetMenuIconAreaWidth() );
- for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++ )
- {
- MENUITEMDATA & _mii = ItemGetInfo( nItemIndex );
- _mii.UpdateIconAreaWidth( nIconAreaWidthLager );
- } // for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++ )
- m_bExpandAvailable = false;
- // m_sizeFullItems.cx = m_sizeFullItems.cy = 1; // - 2.28
- m_sizeFullItems.cx = m_sizeFullItems.cy = 0; // + 2.28
- bool bFullViewMode =
- ( m_bExpandWasPressed
- || ( (dwTrackFlags&TPMX_NO_HIDE_RARELY) != 0 )
- ) ? true : false;
- int nSeparatorIndex = -1;
- int nDisplayedCount = 0;
- for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++ )
- {
- MENUITEMDATA & _mii = ItemGetInfo( nItemIndex );
- _mii.SetIndex( nItemIndex );
- if( bFullViewMode )
- {
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- if( _mii.IsPopup() )
- {
- ASSERT( _mii.GetPopup() != NULL );
- _mii.GetPopup()->_SyncItems();
- } // if( _mii.IsPopup() )
- } // if( bFullViewMode )
- else
- {
- if( _mii.IsPopup() )
- {
- ASSERT( _mii.GetPopup() != NULL );
- _mii.GetPopup()->_SyncItems();
- CExtCmdItem * pCmdItem = _mii.GetCmd();
- if( pCmdItem != NULL )
- {
- bool bRarelyUsed =
- ( (!_FindCustomizeMode())
- && pCmdItem->StateIsRarelyUsed()
- ) ? true : false;
- if( bRarelyUsed )
- {
- _mii.SetDisplayed( false );
- } // if( bRarelyUsed )
- else
- {
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- nSeparatorIndex = -1;
- } // else from if( bRarelyUsed )
- } // if( pCmdItem != NULL )
- else if( _mii.IsAllItemsRarelyUsed() )
- {
- _mii.SetDisplayed( false );
- } // else if( _mii.IsAllItemsRarelyUsed() )
- else
- { // if at least one displayed
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- nSeparatorIndex = -1;
- } // if at least one displayed
- } // if( _mii.IsPopup() )
- else if( _mii.IsSeparator() )
- {
- if( nSeparatorIndex >= 0 || nDisplayedCount == 0 )
- {
- _mii.SetDisplayed( false );
- } // if( nSeparatorIndex >= 0 || nDisplayedCount == 0 )
- else
- {
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- nSeparatorIndex = nItemIndex;
- } // else from if( nSeparatorIndex >= 0 || nDisplayedCount == 0 )
- } // else if( _mii.IsSeparator() )
- else
- { // if command item
- CExtCmdItem * pCmdItem = _mii.GetCmd();
- if( pCmdItem == NULL || _mii.IsExtraMark() )
- {
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- nSeparatorIndex = -1;
- } // if( pCmdItem == NULL || _mii.IsExtraMark() )
- else if( pCmdItem->StateIsRarelyUsed() )
- {
- _mii.SetDisplayed( false );
- } // else if( pCmdItem->StateIsRarelyUsed() )
- else
- { // if basic command or frequently used
- _mii.SetDisplayed( true );
- nDisplayedCount ++;
- nSeparatorIndex = -1;
- } // if basic command or frequently used
- } // if command item
- } // else from if( bFullViewMode )
- if( _mii.IsDisplayed() )
- {
- m_sizeFullItems.cy += _mii.GetMeasuredHeight();
- int nMeasuredWidth = _mii.GetMeasuredWidth();
- if( m_sizeFullItems.cx < nMeasuredWidth )
- m_sizeFullItems.cx = nMeasuredWidth;
- } // if( _mii.IsDisplayed() )
- else
- {
- ASSERT( ! m_bExpandWasPressed );
- m_bExpandAvailable = true;
- } // else from if( _mii.IsDisplayed() )
- } // for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++ )
- if( nSeparatorIndex >= 0 )
- { // remove last separator
- ASSERT( ! bFullViewMode );
- MENUITEMDATA & _mii = ItemGetInfo( nSeparatorIndex );
- ASSERT( _mii.IsSeparator() );
- ASSERT( _mii.IsDisplayed() );
- _mii.SetDisplayed( false );
- m_sizeFullItems.cy -= _mii.GetMeasuredHeight();
- } // if( nSeparatorIndex >= 0 )
- if( GetSafeHwnd() != NULL
- && IsSyncFullRowItems()
- )
- {
- CRect rcMB = OnQueryMenuBorderMetrics();
- CRect rcClient;
- _GetClientRect( &rcClient );
- m_sizeFullItems.cx = rcClient.Width() - rcMB.left - rcMB.right;
- }
- static const INT nMixDx = 80;
- if( m_sizeFullItems.cx < nMixDx )
- m_sizeFullItems.cx = nMixDx;
- }
- void CExtPopupMenuWnd::_SyncItemsPalette()
- {
- ASSERT_VALID( this );
- ASSERT( m_hWndCmdReceiver != NULL );
- ASSERT( ::IsWindow(m_hWndCmdReceiver) );
- m_bExpandAvailable = false;
- m_sizeFullItems.cx = m_sizeFullItems.cy = 0;
- int nItemIndex = 0, nCountOfItems = (int)m_items_all.GetSize();
- for( nItemIndex = 0; nItemIndex < nCountOfItems; nItemIndex++ )
- {
- MENUITEMDATA & _mii = ItemGetInfo( nItemIndex );
- _mii.CacheRectsEmpty();
- _mii.SetToolButton();
- bool bIconMode = true;
- #if (!defined __EXT_MFC_NO_CUSTOMIZE)
- CExtCustomizeCmdTreeNode * pNode = _mii.GetCmdNode();
- if( pNode != NULL )
- {
- DWORD dwDipslayStyle = pNode->GetFlags() & __ECTN_DISPLAY_MASK;
- if( dwDipslayStyle == __ECTN_DISPLAY_TEXT_AND_IMAGE
- || dwDipslayStyle == __ECTN_DISPLAY_TEXTONLY_ALWAYS
- )
- bIconMode = false;
- }
- else
- #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
- {
- LPCTSTR strText = _mii.GetText();
- if( strText != NULL
- && _tcslen( strText ) > 0
- )
- bIconMode = false;
- }
- _mii.SetIconMode( bIconMode );
- _mii.SetIndex( nItemIndex );
- _mii.SetDisplayed( true );
- _mii.UpdateIconAreaWidth( 0 );
- _mii.MeasureItem( NULL );
- if( _mii.IsPopup() )
- {
- ASSERT( _mii.GetPopup() != NULL );
- _mii.GetPopup()->_SyncItems();
- } // if( _mii.IsPopup() )
- } // for( nItemIndex = 0; nItemIndex < nCountOfItems; nItemIndex++ )
- CRect rcMB = OnQueryMenuBorderMetrics();
- int x = 0, y = 0;
- int xRow = x, dyRow = 0, dxMaxRow = 0, nRowStart = 0;
- for( nItemIndex = 0; nItemIndex < nCountOfItems; nItemIndex++ )
- {
- MENUITEMDATA & mi = ItemGetInfo( nItemIndex );
- if( ! mi.IsDisplayed() )
- continue;
- bool bWrap = _IsPaletteItemWrap( nItemIndex );
- const RECT & rcBase = mi.GetBaseRect();
- if( mi.IsSeparator() )
- bWrap = true;
- int nWidth = rcBase.right - rcBase.left;
- int nHeight = rcBase.bottom-rcBase.top;
- dyRow = max( dyRow, nHeight );
- xRow += nWidth;
- if( mi.IsInplaceEdit() )
- xRow += (nItemIndex == 0) ? __EXT_MENU_GAP : (__EXT_MENU_GAP*2);
- // else
- // xRow += (nRowStart == nItemIndex) ? 0 : __EXT_MENU_GAP;
- xRow += 2;
- dxMaxRow = max( dxMaxRow, xRow );
- if( bWrap )
- {
- dxMaxRow = max( dxMaxRow, xRow );
- xRow = x;
- y += dyRow;
- dyRow = 0;
- if( mi.IsSeparator() )
- y +=
- PmBridge_GetPM()->GetSeparatorHeight()
- + __EXT_MENU_GAP
- ;
- nRowStart = nItemIndex + 1;
- }
- } // for( nItemIndex = 0; nItemIndex < nCountOfItems; nItemIndex++ )
- dxMaxRow = max( dxMaxRow, xRow );
- m_sizeFullItems.cx = dxMaxRow + rcMB.left + rcMB.right + __EXT_MENU_GAP;
- m_sizeFullItems.cy = y + dyRow + __EXT_MENU_GAP;
- if( m_sizeFullItems.cx < 20 )
- m_sizeFullItems.cx = 20;
- if( m_sizeFullItems.cy < 10 )
- m_sizeFullItems.cy = 10;
- }
- void CExtPopupMenuWnd::ResetPaletteWrapping(
- bool bCreateToolBarWrapping, // = false
- int nIndexFirst, // = 0
- int nIndexLast // = -1
- )
- {
- ASSERT_VALID( this );
- if( ! _IsPalette() )
- return;
- int nCountOfItems = ItemGetCount();
- if( nCountOfItems == 0 )
- return;
- if( nIndexFirst < 0 || nIndexFirst >= nCountOfItems )
- return;
- if( nIndexLast < 0 || nIndexLast >= nCountOfItems )
- nIndexLast = nCountOfItems - 1;
- if( nIndexFirst >= nIndexLast )
- return;
- int nIndex, nSummaryWidth = 0;
- static const int nAdjustStep = __EXT_MENU_GAP*2;
- for( nIndex = nIndexFirst; nIndex <= nIndexLast; nIndex ++ )
- {
- MENUITEMDATA & mi = ItemGetInfo( nIndex );
- mi.SetToolWrap( false );
- if( ! bCreateToolBarWrapping )
- continue;
- if( mi.IsSeparator() )
- continue;
- int nWidth = mi.GetBaseRect().Width() + nAdjustStep;
- nSummaryWidth += nWidth;
- } // for( nIndex = nIndexFirst; nIndex <= nIndex; nIndex ++ )
- if( ! bCreateToolBarWrapping )
- return;
- static const int nAdjustWidth = 150;
- if( nSummaryWidth < nAdjustWidth )
- return;
- int dxRow = 0;
- int nApproxRowWidth = ::MulDiv( nSummaryWidth, 25, 100 );
- if( nApproxRowWidth < nAdjustWidth )
- nApproxRowWidth = nAdjustWidth;
- for( nIndex = nIndexFirst; nIndex <= nIndexLast; nIndex ++ )
- {
- MENUITEMDATA & mi = ItemGetInfo( nIndex );
- if( mi.IsSeparator() )
- {
- dxRow = 0;
- continue;
- }
- int nWidth = mi.GetBaseRect().Width() + nAdjustStep;
- if( dxRow >= nApproxRowWidth
- //|| nIndex == nIndexLast
- )
- {
- if( nIndex > nIndexFirst
- //&& nIndex != nIndexLast
- )
- {
- MENUITEMDATA & mi = ItemGetInfo( nIndex - 1 );
- mi.SetToolWrap( true );
- dxRow = nWidth;
- continue;
- }
- mi.SetToolWrap( true );
- dxRow = 0;
- continue;
- }
- dxRow += nWidth;
- } // for( nIndex = nIndexFirst; nIndex <= nIndex; nIndex ++ )
- }
- const CExtPopupMenuWnd * CExtPopupMenuWnd::ItemGetPopup(
- INT nPos
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount();
- if( nPos < 0 || nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return NULL;
- }
- const MENUITEMDATA & mi = ItemGetInfo(nPos);
- /*
- UINT nCmdID = mi.GetCmdID();
- if( nCmdID != TYPE_POPUP )
- return NULL;
- ASSERT( mi.IsPopup() );
- */
- if( !mi.IsPopup() )
- return NULL;
- return mi.GetPopup();
- }
- BOOL CExtPopupMenuWnd::ItemRemove(
- INT nPos // = -1 // remove all
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- if( nPos < 0 )
- {
- if( ! _BuildItems( NULL, false ) )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- _SyncItems();
- return TRUE;
- } // if( nPos < 0 )
- INT nCountOfItems = ItemGetCount();
- if( nPos >= nCountOfItems )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- MENUITEMDATA & mi = ItemGetInfo(nPos);
- if( mi.IsPopup() )
- {
- mi.GetPopup()->_OnCancelMode();
- VERIFY( mi.GetPopup()->_BuildItems( NULL, false ) );
- mi.DestroyPopup();
- }
- m_items_all.RemoveAt( nPos );
- ASSERT( nCountOfItems == m_items_all.GetSize() + 1 );
- m_nCurIndex = -1;
- _SyncItems();
- return TRUE;
- }
- INT CExtPopupMenuWnd::ItemRemoveAllSeparators()
- {
- ASSERT_VALID( this );
- ASSERT( GetTrackingMenu() != this );
- INT nCountOfItems = ItemGetCount(), nIndex = 0, nCountRemoved = 0;
- for( ; nIndex < nCountOfItems; )
- {
- MENUITEMDATA & mi = ItemGetInfo(nIndex);
- if( mi.IsSeparator() )
- {
- m_items_all.RemoveAt( nIndex );
- nCountOfItems --;
- nCountRemoved ++;
- }
- else
- nIndex ++;
- }
- m_nCurIndex = -1;
- if( nCountRemoved > 0 )
- _SyncItems();
- return nCountRemoved;
- }
- BOOL CExtPopupMenuWnd::ItemInsertSpecPopup( // insert specific popup implementation
- CExtPopupMenuWnd * pSpecPopup,
- INT nPos, // = -1 // append
- __EXT_MFC_SAFE_LPCTSTR sText, // = NULL
- HICON hIcon // = NULL
- )
- {
- ASSERT_VALID( this );
- ASSERT( pSpecPopup != NULL );
- CExtCmdIcon icon;
- if( hIcon != NULL )
- icon.AssignFromHICON( hIcon, false );
- return
- ItemInsertSpecPopup( // insert specific popup implementation
- pSpecPopup,
- nPos,
- sText,
- icon
- );
- }
- BOOL CExtPopupMenuWnd::ItemInsertSpecPopup( // insert specific popup implementation
- CExtPopupMenuWnd * pSpecPopup,
- INT nPos, // -1 - append
- __EXT_MFC_SAFE_LPCTSTR sText,
- const CExtCmdIcon & icon
- )
- {
- ASSERT_VALID( this );