ExtControls.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:27k
源码类别:

界面编程

开发平台:

Visual C++

  1. // This is part of the Professional User Interface Suite library.
  2. // Copyright (C) 2001-2009 FOSS Software, Inc.
  3. // All rights reserved.
  4. //
  5. // http://www.prof-uis.com
  6. // mailto:support@prof-uis.com
  7. //
  8. // This source code can be used, modified and redistributed
  9. // under the terms of the license agreement that is included
  10. // in the Professional User Interface Suite package.
  11. //
  12. // Warranties and Disclaimers:
  13. // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
  14. // INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  16. // IN NO EVENT WILL FOSS SOFTWARE INC. BE LIABLE FOR ANY DIRECT,
  17. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES,
  18. // INCLUDING DAMAGES FOR LOSS OF PROFITS, LOSS OR INACCURACY OF DATA,
  19. // INCURRED BY ANY PERSON FROM SUCH PERSON'S USAGE OF THIS SOFTWARE
  20. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  21. #include "stdafx.h"
  22. #if (!defined __EXT_CONTROLS_H)
  23. #include <ExtControls.h>
  24. #endif // (!defined __EXT_CONTROLS_H)
  25. #if (!defined __EXT_TOOLCONTROLBAR_H)
  26. #include <ExtToolControlBar.h>
  27. #endif
  28. #if (!defined __EXT_PAINT_MANAGER_H)
  29. #include <ExtPaintManager.h>
  30. #endif
  31. #if (!defined __ExtCmdManager_H)
  32. #include <ExtCmdManager.h>
  33. #endif
  34. #if (!defined __EXT_POPUP_MENU_WND_H)
  35. #include <ExtPopupMenuWnd.h>
  36. #endif
  37. #if (!defined __PROF_UIS_RES_PM_H)
  38. #include <Resources/ResPM/ResPM.h>
  39. #endif
  40. #if( !defined __EXTMINIDOCKFRAMEWND_H)
  41. #include "ExtMiniDockFrameWnd.h"
  42. #endif
  43. #if( !defined __EXT_MEMORY_DC_H)
  44. #include "ExtMemoryDC.h"
  45. #endif
  46. #if (!defined __EXT_GROUPBOX_H)
  47. #include <ExtGroupBox.h>
  48. #endif
  49. #if (!defined __EXT_PROGRESS_WND_H)
  50. #include <ExtProgressWnd.h>
  51. #endif
  52. #if (!defined __EXT_LABEL_H)
  53. #include <ExtLabel.h>
  54. #endif
  55. #if (!defined __EXT_SCROLLWND_H)
  56. #include <ExtScrollWnd.h>
  57. #endif 
  58. #if (!defined __EXT_COMBO_BOX_H)
  59. #include <ExtComboBox.h>
  60. #endif
  61. #if (!defined __EXT_SPIN_H)
  62. #include <ExtSpinWnd.h>
  63. #endif
  64. #if (!defined __EXT_BUTTON_H)
  65. #include <ExtButton.h>
  66. #endif
  67. #include <Resources/Resource.h>
  68. #ifdef _DEBUG
  69. #define new DEBUG_NEW
  70. #undef THIS_FILE
  71. static char THIS_FILE[] = __FILE__;
  72. #endif
  73. void SubclassChildControls( 
  74. HWND hWndParent 
  75. )
  76. {
  77. if( hWndParent == NULL 
  78. || (!::IsWindow( hWndParent ))
  79. )
  80. return;  
  81. HWND hWnd = ::GetWindow( hWndParent, GW_CHILD ); 
  82. HWND hWndLast = NULL;
  83. CPtrArray arrGroupBoxes;
  84. while( hWnd != NULL )
  85. {
  86. TCHAR szCompare[512] = _T("");
  87. ::GetClassName(
  88. hWnd,
  89. szCompare,
  90. sizeof( szCompare )/sizeof( szCompare[0] )
  91. );
  92. static const TCHAR szStatic[] = _T("STATIC");
  93. static const TCHAR szEdit[] = _T("EDIT");
  94. static const TCHAR szComboBox[] = _T("COMBOBOX");
  95. static const TCHAR szButton[] = _T("BUTTON");
  96. static const TCHAR szProgress[] = _T("PROGRESS");
  97. static const TCHAR szScrollBar[] = _T("SCROLLBAR");
  98. static const TCHAR szSpin[] = _T("MSCTLS_UPDOWN32");
  99. // static
  100. if( _tcsicmp( szCompare, szStatic ) == 0 )
  101. {
  102. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtLabel ); 
  103. }
  104. // edit
  105. else if( _tcsicmp( szCompare, szEdit ) == 0 )
  106. {
  107. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtEdit );
  108. }
  109. // combobox
  110. else if( _tcsicmp( szCompare, szComboBox ) == 0 )
  111. {
  112. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtComboBox );
  113. }
  114. // button
  115. else if( _tcsicmp( szCompare, szButton ) == 0 )
  116. {
  117. CWnd * pWnd = CWnd::FromHandlePermanent( hWnd ); 
  118. if( pWnd == NULL ) 
  119. {
  120. #ifdef BS_TYPEMASK
  121. ASSERT( BS_TYPEMASK == 0x0000000FL );
  122. #endif
  123. __EXT_MFC_LONG_PTR dwWndStyle = ::__EXT_MFC_GetWindowLong( hWnd, GWL_STYLE );
  124. __EXT_MFC_LONG_PTR dwWndType = ( dwWndStyle & 0x0000000FL );
  125. if( dwWndType == BS_PUSHBUTTON 
  126. || dwWndType == BS_DEFPUSHBUTTON 
  127. )
  128. {
  129. // regular button
  130. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtButton );
  131. }
  132. else if( dwWndType == BS_AUTOCHECKBOX
  133. || dwWndType == BS_CHECKBOX
  134. || dwWndType == BS_AUTO3STATE
  135. || dwWndType == BS_3STATE
  136. )
  137. {
  138. // check box
  139. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtCheckBox );
  140. }
  141. else if( dwWndType == BS_AUTORADIOBUTTON
  142. || dwWndType == BS_RADIOBUTTON
  143. )
  144. {
  145. // radio button
  146. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtRadioButton );
  147. }
  148. else if( dwWndType == BS_GROUPBOX )
  149. {
  150. // group box
  151. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtGroupBox );
  152. arrGroupBoxes.Add( LPVOID( hWnd ) );
  153. ::InvalidateRect( hWnd, NULL, TRUE );
  154. } // if( pWnd == NULL )
  155. }
  156. #ifndef __EXT_MFC_NO_PROGRESS_WND
  157. else if( _tcsicmp( szCompare, szProgress ) == 0 )
  158. {
  159. // progress bar
  160. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtProgressWnd );
  161. }
  162. #endif
  163. else if( _tcsicmp( szCompare, szScrollBar ) == 0 )
  164. {
  165. // scroll bar
  166. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtScrollBar );
  167. #ifndef __EXT_MFC_NO_SPIN
  168. else if( _tcsicmp( szCompare, szSpin ) == 0 )
  169. {
  170. // spin button
  171. __EXT_SUBCLASS_PROFUISCTRL( hWnd, CExtSpinWnd );
  172. #endif
  173. hWndLast = hWnd;
  174. hWnd = ::GetWindow( hWnd, GW_HWNDNEXT );  
  175. } // while( hWnd != NULL )
  176. if( hWndLast != NULL
  177. && arrGroupBoxes.GetSize() > 0
  178. )
  179. {
  180. // move all the group boxes to the back by changing the tab order at runtime
  181. HWND hWndPrev = hWndLast;
  182. while( arrGroupBoxes.GetSize() > 0 )
  183. {
  184. HWND hWnd = (HWND) arrGroupBoxes.GetAt( 0 );
  185. if( hWnd != NULL 
  186. && ::IsWindow( hWnd )
  187. )
  188. {
  189. ::SetWindowPos(
  190. hWnd,
  191. hWndPrev,
  192. 0,0,
  193. 0,0,
  194. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE
  195. );
  196. hWndPrev = hWnd;
  197. }
  198. arrGroupBoxes.RemoveAt( 0 );
  199. }
  200. }
  201. }
  202. void SubclassChildControls( 
  203. const CWnd * pWndParent
  204. )
  205. {
  206. if( pWndParent == NULL )
  207. return;
  208. SubclassChildControls( pWndParent->GetSafeHwnd() );
  209. }
  210. void SubclassChildControls( 
  211. const CWnd & wndParent
  212. )
  213. {
  214. SubclassChildControls( wndParent.GetSafeHwnd() );
  215. }
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CExtWSGripper for the CExtWS template
  218. IMPLEMENT_DYNCREATE( CExtWSGripper, CWnd );
  219. CExtWSGripper::CExtWSGripper()
  220. {
  221. }
  222. CExtPaintManager * CExtWSGripper::PmBridge_GetPM() const
  223. {
  224. ASSERT_VALID( this );
  225. return g_PaintManager.GetPM();
  226. }
  227. void CExtWSGripper::DoPaint( CDC * pDC )
  228. {
  229. ASSERT( pDC != NULL );
  230. ASSERT( pDC->GetSafeHdc() != NULL );
  231. bool bTransparent = false;
  232. if( PmBridge_GetPM()->GetCb2DbTransparentMode(this) )
  233. {
  234. if( PmBridge_GetPM()->PaintDockerBkgnd( true, *pDC, this ) )
  235. bTransparent = true;
  236. }
  237. if( ! bTransparent )
  238. {
  239. CRect rcClient;
  240. GetClientRect( &rcClient );
  241. pDC->FillSolidRect(
  242. &rcClient,
  243. PmBridge_GetPM()->GetColor( CExtPaintManager::CLR_3DFACE_OUT, this ) 
  244. );
  245. }
  246. int nOldBkMode = pDC->SetBkMode(TRANSPARENT);
  247. CWnd * pWnd = GetParent();
  248. ASSERT( pWnd != NULL );
  249. ASSERT_VALID( pWnd );
  250. if( ! pWnd->IsZoomed() )
  251. {
  252. CRect rcClient;
  253. GetClientRect( &rcClient );
  254. PmBridge_GetPM()->PaintResizingGripper(
  255. *pDC,
  256. rcClient,
  257. this
  258. );
  259. }
  260. pDC->SetBkMode(nOldBkMode);
  261. PmBridge_GetPM()->OnPaintSessionComplete( this );
  262. }
  263. LRESULT CExtWSGripper::WindowProc(
  264. UINT message,
  265. WPARAM wParam,
  266. LPARAM lParam
  267. {
  268. if( message == WM_NCHITTEST )
  269. {
  270. CWnd * pWnd = GetParent();
  271. ASSERT( pWnd != NULL );
  272. ASSERT_VALID( pWnd );
  273. if( pWnd->IsZoomed() )
  274. return HTNOWHERE;
  275. __EXT_MFC_LONG_PTR dwExStyle = ::__EXT_MFC_GetWindowLong( pWnd->GetSafeHwnd(), GWL_EXSTYLE );
  276. bool bRTL = ( (dwExStyle & WS_EX_LAYOUTRTL) != 0 ) ? true : false;
  277. return bRTL 
  278. ? HTBOTTOMLEFT 
  279. : HTBOTTOMRIGHT;
  280. }
  281.   if( message == WM_CREATE )
  282. {
  283. LRESULT lResult = CWnd::WindowProc( message, wParam, lParam );
  284. CRect rcClient;
  285. GetClientRect( &rcClient );
  286.  
  287. POINT ptCorners[] =
  288. {
  289. {
  290. rcClient.left,
  291. rcClient.bottom
  292. },
  293. {
  294. rcClient.right,
  295. rcClient.bottom
  296. },
  297. {
  298. rcClient.right,
  299. rcClient.top
  300. },
  301. };
  302. HRGN hRgn = ::CreatePolygonRgn( ptCorners, sizeof(ptCorners)/sizeof(ptCorners[0]), ALTERNATE );
  303. SetWindowRgn( hRgn, TRUE );
  304. return lResult;
  305. }
  306. if( message == WM_MOUSEACTIVATE )
  307. return MA_NOACTIVATEANDEAT;
  308. if( message == WM_ERASEBKGND )
  309. return 0L;
  310. if( message == WM_PRINTCLIENT )
  311. {
  312. CDC * pDC = CDC::FromHandle( (HDC)wParam );
  313. DoPaint( pDC );
  314. return (!0);
  315. }
  316. if( message == WM_PAINT )
  317. {
  318. ASSERT_VALID( this );
  319. CPaintDC dcPaint( this );
  320. CRect rcClient;
  321. GetClientRect( &rcClient );
  322. CExtMemoryDC dc(
  323. &dcPaint,
  324. &rcClient
  325. );
  326. DoPaint( &dc );
  327. return 0L;
  328. }
  329. return CWnd::WindowProc( message, wParam, lParam );
  330. }
  331. #if (!defined __EXT_MFC_NO_THEME_SWITCHER_TOOLBAR)
  332. /////////////////////////////////////////////////////////////////////////////
  333. // CExtThemeSwitcherToolButton
  334. IMPLEMENT_DYNCREATE( CExtThemeSwitcherToolButton, CExtBarButton )
  335. CExtThemeSwitcherToolButton::CExtThemeSwitcherToolButton(
  336. CExtToolControlBar * pBar, // = NULL
  337. UINT nCmdID, // = ID_SEPARATOR
  338. UINT nStyle // = 0
  339. )
  340. : CExtBarButton( pBar, nCmdID, nStyle )
  341. {
  342. }
  343. CExtThemeSwitcherToolButton::~CExtThemeSwitcherToolButton()
  344. {
  345. }
  346. void CExtThemeSwitcherToolButton::OnUpdateCmdUI(
  347. CWnd * pTarget,
  348. BOOL bDisableIfNoHndler,
  349. int nIndex
  350. )
  351. {
  352. ASSERT_VALID( this );
  353. ASSERT_VALID( GetBar() );
  354. ASSERT_VALID( pTarget );
  355. pTarget;
  356. bDisableIfNoHndler;
  357. nIndex;
  358. ((CExtThemeSwitcherToolControlBar*)GetBar()) ->
  359. ThemeSwitcher_OnButtonUpdate( this );
  360. }
  361. void CExtThemeSwitcherToolButton::OnDeliverCmd()
  362. {
  363. ASSERT_VALID( this );
  364. ASSERT_VALID( GetBar() );
  365. if( GetBar()->OnDeliverCmd( this ) )
  366. return;
  367. if( ! CExtCmdManager::IsCommand( GetCmdID(false) ) )
  368. return;
  369. ((CExtThemeSwitcherToolControlBar*)GetBar()) ->
  370. ThemeSwitcher_OnButtonInvoke( this );
  371. }
  372. BOOL CExtThemeSwitcherToolButton::PutToPopupMenu(
  373. CExtPopupMenuWnd * pPopup
  374. )
  375. {
  376. ASSERT_VALID( this );
  377. ASSERT( pPopup != NULL );
  378. ASSERT( pPopup->GetSafeHwnd() == NULL );
  379. ASSERT( CtrlGet() == NULL );
  380. if( (GetStyle()&TBBS_HIDDEN) != 0 )
  381. return TRUE;
  382. if( IsSeparator() )
  383. return CExtBarButton::PutToPopupMenu( pPopup );
  384. ASSERT( ! IsAbleToTrackMenu() );
  385. CExtToolControlBar * pBar = GetBar();
  386. ASSERT_VALID( pBar );
  387. CExtCmdItem * pCmdItem =
  388. g_CmdManager->CmdGetPtr(
  389. g_CmdManager->ProfileNameFromWnd( pBar->GetSafeHwnd() ),
  390. GetCmdID( false )
  391. );
  392. ASSERT( pCmdItem != NULL );
  393. HWND hWndCmdReceiver = pBar->GetSafeHwnd();
  394. int nCheck = ( (GetStyle()&TBBS_CHECKED) != 0 ) ? 1 : 0;
  395. // const CExtCmdIcon & _icon = GetIcon();
  396. CExtCmdIcon _icon;
  397. // CExtCmdIcon _cmdIconEmpty, * pCmdIcon = ((CExtThemeSwitcherToolControlBar*)pBar)->ThemeSwitcher_GetMenuIconByToolBarCmdID(GetCmdID(false));
  398. // const CExtCmdIcon & _icon = ( pCmdIcon != NULL ) ? ( * pCmdIcon ) : _cmdIconEmpty;
  399. CExtSafeString strButtonText;
  400. if( (pPopup->TrackFlagsGet()&TPMX_PALETTE) == 0 )
  401. strButtonText = pCmdItem->m_sMenuText;
  402. if( ! pPopup->ItemInsertCommand(
  403. ((CExtThemeSwitcherToolControlBar*)pBar)->ThemeSwitcher_GetMenuCmdIDByToolBarCmdID(GetCmdID( false )), //GetCmdID( false ),
  404. -1,
  405. strButtonText.IsEmpty() ? NULL : LPCTSTR(strButtonText),
  406. NULL,
  407. _icon,
  408. nCheck,
  409. hWndCmdReceiver
  410. )
  411. )
  412. {
  413. ASSERT( FALSE );
  414. return FALSE;
  415. }
  416. CExtPopupMenuWnd::MENUITEMDATA & mi = 
  417. pPopup->ItemGetInfo( pPopup->ItemGetCount() - 1 );
  418. mi.Enable( IsEnabled() );
  419. mi.SetNoCmdUI( true );
  420. if( ! pCmdItem->m_sTipTool.IsEmpty() )
  421. mi.SetCustomTip( LPCTSTR(pCmdItem->m_sTipTool) );
  422. return TRUE;
  423. }
  424. /////////////////////////////////////////////////////////////////////////////
  425. // CExtThemeSwitcherToolControlBar
  426. IMPLEMENT_DYNCREATE( CExtThemeSwitcherToolControlBar, CExtToolControlBar )
  427. CExtThemeSwitcherToolControlBar::CExtThemeSwitcherToolControlBar()
  428. : m_eTIS_PopupMenu( CExtThemeSwitcherToolControlBar::__ETIS_16x16 )
  429. , m_eTIS_ToolBar( CExtThemeSwitcherToolControlBar::__ETIS_24x24 )
  430. , m_bCommandProfileInitialized( false )
  431. , m_nMenuMarkerID( ID_EXT_PM_MENU_MARKER_THEME_CHANGER )
  432. , m_bEnableOffice2007r3( false )
  433. {
  434. #if (!defined __EXT_MFC_NO_CUSTOMIZE)
  435. m_bCustomizationAllowed = false;
  436. #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
  437. m_strCommandProfileName.Format(
  438. _T("ThemeSwitcherToolControlBar-%p"),
  439. this
  440. );
  441. }
  442. CExtThemeSwitcherToolControlBar::~CExtThemeSwitcherToolControlBar()
  443. {
  444. }
  445. BEGIN_MESSAGE_MAP( CExtThemeSwitcherToolControlBar, CExtToolControlBar )
  446. //{{AFX_MSG_MAP(CExtThemeSwitcherToolControlBar)
  447. //}}AFX_MSG_MAP
  448. END_MESSAGE_MAP()
  449. CExtBarButton * CExtThemeSwitcherToolControlBar::OnCreateBarCommandBtn(
  450. UINT nCmdID,
  451. UINT nStyle // = 0
  452. )
  453. {
  454. ASSERT_VALID( this );
  455. CExtBarButton * pTBB = new CExtThemeSwitcherToolButton( this, nCmdID, nStyle );
  456. ASSERT_VALID( pTBB );
  457. return pTBB;
  458. }
  459. bool CExtThemeSwitcherToolControlBar::ThemeSwitcherInit(
  460. CExtThemeSwitcherToolControlBar::e_ThemeIconSize_t _eTIS_PopupMenu, // = __ETIS_16x16
  461. CExtThemeSwitcherToolControlBar::e_ThemeIconSize_t _eTIS_ToolBar // = __ETIS_24x24
  462. )
  463. {
  464. ASSERT_VALID( this );
  465. if( GetSafeHwnd() == NULL )
  466. return false;
  467. static const UINT g_arrToolBarResources[] =
  468. {
  469. IDB_EXT_PM_16x16,
  470. IDB_EXT_PM_24x24,
  471. IDB_EXT_PM_32x32,
  472. };
  473. if( ! m_bCommandProfileInitialized )
  474. {
  475. g_CmdManager->CmdRemoveAll( LPCTSTR(m_strCommandProfileName) );
  476. m_mapCmd2RTC.RemoveAll();
  477. m_mapCmdID2ThemeType.RemoveAll();
  478. m_listCmdSequence.RemoveAll();
  479. int nToolBarIndex, nToolBarCount = sizeof(g_arrToolBarResources) / sizeof(g_arrToolBarResources[0]);
  480. for( nToolBarIndex = 0; nToolBarIndex < nToolBarCount; nToolBarIndex ++ )
  481. {
  482. m_arrMapsTT[nToolBarIndex].RemoveAll();
  483. UINT nToolBarResourceID = g_arrToolBarResources[nToolBarIndex];
  484. HRSRC hRsrcCommands = NULL;
  485. HINSTANCE hInstResourceCommands =
  486. g_ResourceManager->FindResourceHandle(
  487. RT_TOOLBAR,
  488. nToolBarResourceID,
  489. NULL,
  490. &hRsrcCommands
  491. );
  492. if( hInstResourceCommands == NULL )
  493. return false;
  494. HRSRC hRsrcBitmap = NULL;
  495. HINSTANCE hInstResourceBitmap =
  496. g_ResourceManager->FindResourceHandle(
  497. RT_BITMAP,
  498. nToolBarResourceID,
  499. NULL,
  500. &hRsrcBitmap
  501. );
  502. if( hInstResourceBitmap == NULL )
  503. return false;
  504. ASSERT( hRsrcBitmap != NULL );
  505. CExtCmdProfile::MFC_TOOLBAR_LOADER _loader(
  506. hInstResourceCommands,
  507. hRsrcCommands,
  508. hInstResourceBitmap,
  509. hRsrcBitmap,
  510. COLORREF(-1L)
  511. );
  512. if( _loader.IsEmpty() )
  513. return false;
  514. int nButtonIdx = 0, nCommandIdx, nCommandCount = _loader.GetCommandCount();
  515. ASSERT( nCommandCount > 0 );
  516. for( nCommandIdx = 0; nCommandIdx < nCommandCount; nCommandIdx++ )
  517. {
  518. UINT nCommandCmdID = _loader.GetCommandIdAt( nCommandIdx );
  519. if( nCommandCmdID == ID_SEPARATOR )
  520. {
  521. if( nToolBarIndex == 0 )
  522. m_listCmdSequence.AddHead( UINT(ID_SEPARATOR) );
  523. continue;
  524. }
  525. CExtCmdIcon * pIcon = new CExtCmdIcon;
  526. UINT nButtonCmdID =
  527. _loader.ExtractButtonData( nButtonIdx ++, *pIcon );
  528. ASSERT( nButtonCmdID == nCommandCmdID );
  529. if( pIcon->IsEmpty() )
  530. {
  531. ASSERT( FALSE );
  532. delete pIcon;
  533. continue;
  534. }
  535. CRuntimeClass * pRTC = NULL;
  536. switch( nButtonCmdID )
  537. {
  538. case ID_EXT_PM_THEME_Office2000:
  539. pRTC = RUNTIME_CLASS(CExtPaintManager);
  540. break;
  541. case ID_EXT_PM_THEME_OfficeXP:
  542. pRTC = RUNTIME_CLASS(CExtPaintManagerXP);
  543. break;
  544. case ID_EXT_PM_THEME_Office2003:
  545. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2003);
  546. break;
  547. case ID_EXT_PM_THEME_Office2003NoThemes:
  548. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2003NoThemes);
  549. break;
  550. case ID_EXT_PM_THEME_Studio2005:
  551. pRTC = RUNTIME_CLASS(CExtPaintManagerStudio2005);
  552. break;
  553. case ID_EXT_PM_THEME_Studio2008:
  554. pRTC = RUNTIME_CLASS(CExtPaintManagerStudio2008);
  555. break;
  556. case ID_EXT_PM_THEME_NativeXP:
  557. pRTC = RUNTIME_CLASS(CExtPaintManagerNativeXP);
  558. break;
  559. case ID_EXT_PM_THEME_Office2007_R1:
  560. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R1);
  561. break;
  562. case ID_EXT_PM_THEME_Office2007_R2_LunaBlue:
  563. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R2_LunaBlue);
  564. break;
  565. case ID_EXT_PM_THEME_Office2007_R2_Obsidian:
  566. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R2_Obsidian);
  567. break;
  568. case ID_EXT_PM_THEME_Office2007_R2_Silver:
  569. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R2_Silver);
  570. break;
  571. case ID_EXT_PM_THEME_Office2007_R3_LunaBlue:
  572. if( ! m_bEnableOffice2007r3 )
  573. {
  574. delete pIcon;
  575. continue;
  576. }
  577. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R3_LunaBlue);
  578. break;
  579. case ID_EXT_PM_THEME_Office2007_R3_Obsidian:
  580. if( ! m_bEnableOffice2007r3 )
  581. {
  582. delete pIcon;
  583. continue;
  584. }
  585. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R3_Obsidian);
  586. break;
  587. case ID_EXT_PM_THEME_Office2007_R3_Silver:
  588. if( ! m_bEnableOffice2007r3 )
  589. {
  590. delete pIcon;
  591. continue;
  592. }
  593. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2007_R3_Silver);
  594. break;
  595. case ID_EXT_PM_THEME_Office2010_R1:
  596. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2010_R1);
  597. break;
  598. case ID_EXT_PM_THEME_Office2010_R2_Blue:
  599. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2010_R2_Blue);
  600. break;
  601. case ID_EXT_PM_THEME_Office2010_R2_Silver:
  602. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2010_R2_Silver);
  603. break;
  604. case ID_EXT_PM_THEME_Office2010_R2_Black:
  605. pRTC = RUNTIME_CLASS(CExtPaintManagerOffice2010_R2_Black);
  606. break;
  607. } // switch( nButtonCmdID )
  608. CExtCmdItem * pCmdItem =
  609. g_CmdManager->CmdAllocPtr(
  610. LPCTSTR(m_strCommandProfileName)
  611. );
  612. if( pCmdItem == NULL )
  613. {
  614. ASSERT(FALSE);
  615. delete pIcon;
  616. continue;
  617. }
  618. pCmdItem->StateSetBasic();
  619. UINT nSavedCmdID = pCmdItem->m_nCmdID;
  620. pCmdItem->m_nCmdID = nButtonCmdID;
  621. pCmdItem->TipsLoad();
  622. pCmdItem->m_nCmdID = nSavedCmdID;
  623. pCmdItem->m_sMenuText
  624. = pCmdItem->m_sTipTool
  625. = pCmdItem->m_sTipStatus;
  626. VERIFY(
  627. g_CmdManager->CmdSetIcon(
  628. LPCTSTR(m_strCommandProfileName),
  629. pCmdItem->m_nCmdID,
  630. pIcon,
  631. true
  632. )
  633. );
  634. if( pRTC != NULL )
  635. {
  636. m_mapCmd2RTC.SetAt( pCmdItem->m_nCmdID, pRTC );
  637. }
  638. m_mapCmdID2ThemeType.SetAt( pCmdItem->m_nCmdID, nButtonCmdID );
  639. m_arrMapsTT[nToolBarIndex].SetAt( nButtonCmdID, pCmdItem->m_nCmdID );
  640. if( nToolBarIndex == 0 )
  641. m_listCmdSequence.AddHead( nButtonCmdID );
  642. } // for( nCommandIdx = 0; nCommandIdx < nCommandCount; nCommandIdx++ )
  643. } // for( nToolBarIndex = 0; nToolBarIndex < nToolBarCount; nToolBarIndex ++ )
  644. m_bCommandProfileInitialized = true;
  645. } // if( ! m_bCommandProfileInitialized )
  646. int nCmdIndex, nCmdCount = int( m_listCmdSequence.GetCount() );
  647. if( nCmdCount == 0 )
  648. return false;
  649. m_eTIS_PopupMenu = _eTIS_PopupMenu;
  650. m_eTIS_ToolBar = _eTIS_ToolBar;
  651. UINT * pArr = NULL;
  652. bool bButtonsInitialized = false;
  653. try
  654. {
  655. SetButtons();
  656. POSITION pos = m_listCmdSequence.GetHeadPosition();
  657. pArr = new UINT [ nCmdCount ];
  658. for( nCmdIndex = 0; nCmdIndex < nCmdCount; nCmdIndex++ )
  659. {
  660. UINT nMarkerCmdID = m_listCmdSequence.GetNext( pos );
  661. UINT nEffectiveCmdID = ID_SEPARATOR;
  662. if( nMarkerCmdID != ID_SEPARATOR )
  663. {
  664. VERIFY(
  665. m_arrMapsTT[ int(m_eTIS_ToolBar) ].
  666. Lookup( nMarkerCmdID, nEffectiveCmdID
  667. )
  668. );
  669. }
  670. pArr[ nCmdIndex ] = nEffectiveCmdID;
  671. } // for( nCmdIndex = 0; nCmdIndex < nCmdCount; nCmdIndex++ )
  672. bButtonsInitialized = SetButtons( pArr, nCmdCount ) ? true : false;
  673. }
  674. catch( CException * pException )
  675. {
  676. pException->Delete();
  677. }
  678. catch( ... )
  679. {
  680. }
  681. if( pArr != NULL )
  682. delete [] pArr;
  683. if( ! bButtonsInitialized )
  684. return false;
  685. return true;
  686. }
  687. bool CExtThemeSwitcherToolControlBar::OnHookWndMsg(
  688. LRESULT & lResult,
  689. HWND hWndHooked,
  690. UINT nMessage,
  691. WPARAM & wParam,
  692. LPARAM & lParam
  693. )
  694. {
  695. __PROF_UIS_MANAGE_STATE;
  696. MSG msg;
  697. ::memset( &msg, 0, sizeof(MSG) );
  698. msg.hwnd = hWndHooked;
  699. msg.message = nMessage;
  700. msg.wParam = wParam;
  701. msg.lParam = lParam;
  702. if( PreTranslateMessage( &msg ) )
  703. return true;
  704. return 
  705. CExtHookSink::OnHookWndMsg(
  706. lResult,
  707. hWndHooked,
  708. nMessage,
  709. wParam,
  710. lParam
  711. );
  712. }
  713. BOOL CExtThemeSwitcherToolControlBar::PreTranslateMessage( MSG * pMsg )
  714. {
  715. if( m_bCommandProfileInitialized
  716. && GetSafeHwnd() != NULL
  717. && pMsg->message == CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel
  718. )
  719. {
  720. CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
  721. reinterpret_cast
  722. < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
  723. ( pMsg->wParam );
  724. ASSERT( pData != NULL );
  725. CExtPopupMenuWnd * pPopup = pData->m_pPopup;
  726. ASSERT( pPopup != NULL );
  727. #if (!defined __EXT_MFC_NO_CUSTOMIZE)
  728. bool bCustomizeMode = false;
  729. CExtPopupMenuWnd * pTestPopup = pPopup;
  730. for( ; pTestPopup != NULL ; pTestPopup = pTestPopup->GetParentMenuWnd() )
  731. {
  732. if( (pPopup->TrackFlagsGet()&TPMX_CUSTOMIZE_MODE) != 0 )
  733. {
  734. bCustomizeMode = true;
  735. break;
  736. }
  737. }
  738. if( ! bCustomizeMode )
  739. {
  740. CExtCustomizeSite * pSite =
  741. CExtCustomizeSite::GetCustomizeSite( m_hWnd );
  742. if( pSite != NULL )
  743. {
  744. bCustomizeMode = pSite->IsCustomizeMode();
  745. if( ! bCustomizeMode )
  746. bCustomizeMode = ( pSite->DraggedNodeGet() != NULL ) ? true : false;
  747. }
  748. }
  749. if( ! bCustomizeMode )
  750. #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
  751. {
  752. for( ; true; )
  753. {
  754. INT nReplacePos =
  755. pPopup->ItemFindPosForCmdID( m_nMenuMarkerID );
  756. if( nReplacePos < 0 )
  757. break;
  758. pData->m_bMenuChanged = true;
  759. pPopup->ItemRemove( nReplacePos );
  760. INT nIndex, nCount = GetButtonsCount();
  761. for( nIndex = 0; nIndex < nCount; nIndex++ )
  762. {
  763. CExtBarButton * pQueueTBB = GetButton( nIndex );
  764. ASSERT_VALID( pQueueTBB );
  765. CExtThemeSwitcherToolButton * pTBB =
  766. DYNAMIC_DOWNCAST(
  767. CExtThemeSwitcherToolButton,
  768. pQueueTBB
  769. );
  770. if( pTBB == NULL )
  771. continue;
  772. ThemeSwitcher_OnButtonUpdate( pTBB );
  773. pTBB->PutToPopupMenu( pPopup );
  774. } // for( nIndex = 0; nIndex < nCount; nIndex++ )
  775. }
  776. }
  777. }
  778. return FALSE;
  779. }
  780. BOOL CExtThemeSwitcherToolControlBar::OnCmdMsg(
  781. UINT nID,
  782. int nCode,
  783. void * pExtra,
  784. AFX_CMDHANDLERINFO * pHandlerInfo
  785. )
  786. {
  787. ASSERT_VALID( this );
  788. nID;
  789. nCode;
  790. pExtra;
  791. pHandlerInfo;
  792. return FALSE;
  793. }
  794. void CExtThemeSwitcherToolControlBar::PreSubclassWindow()
  795. {
  796. CExtToolControlBar::PreSubclassWindow();
  797. VERIFY(
  798. g_CmdManager->ProfileSetup(
  799. LPCTSTR(m_strCommandProfileName),
  800. m_hWnd
  801. )
  802. );
  803. m_bCommandProfileInitialized = false;
  804. PostMessage( (WM_USER+765) );
  805. }
  806. void CExtThemeSwitcherToolControlBar::PostNcDestroy()
  807. {
  808. RemoveAllWndHooks();
  809. m_bCommandProfileInitialized = false;
  810. m_mapCmd2RTC.RemoveAll();
  811. m_mapCmdID2ThemeType.RemoveAll();
  812. m_arrMapsTT[0].RemoveAll();
  813. m_arrMapsTT[1].RemoveAll();
  814. m_arrMapsTT[2].RemoveAll();
  815. m_listCmdSequence.RemoveAll();
  816. VERIFY(
  817. g_CmdManager->ProfileDestroy(
  818. LPCTSTR(m_strCommandProfileName),
  819. true
  820. )
  821. );
  822. CExtToolControlBar::PostNcDestroy();
  823. }
  824. LRESULT CExtThemeSwitcherToolControlBar::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
  825. {
  826. if( message == WM_COMMAND )
  827. {
  828. UINT nCmdID = ThemeSwitcher_GetToolBarCmdIDByMenuCmdID( UINT(wParam) );
  829. int nButtonIndex = CommandToIndex( nCmdID );
  830. if( nButtonIndex >= 0 )
  831. {
  832. CExtThemeSwitcherToolButton * pTBB =
  833. DYNAMIC_DOWNCAST(
  834. CExtThemeSwitcherToolButton,
  835. GetButton( nButtonIndex )
  836. );
  837. if( pTBB != NULL )
  838. {
  839. ThemeSwitcher_OnButtonInvoke( pTBB );
  840. return 0;
  841. }
  842. }
  843. }
  844. else if( message == (WM_USER+765) )
  845. {
  846. HWND hWnd = ::GetParent( m_hWnd );
  847. for( ; hWnd != NULL; hWnd = ::GetParent( hWnd ) )
  848. {
  849. __EXT_MFC_LONG_PTR dwStyle = ::__EXT_MFC_GetWindowLong( hWnd, GWL_STYLE );
  850. if( (dwStyle&WS_CHILD) == 0 )
  851. {
  852. CWnd * pWndPermanent = CWnd::FromHandlePermanent( hWnd );
  853. if( pWndPermanent != NULL
  854. && pWndPermanent->IsKindOf( RUNTIME_CLASS( CExtMiniDockFrameWnd ) )
  855. )
  856. continue;
  857. SetupHookWndSink( hWnd );
  858. break;
  859. }
  860. }
  861. }
  862. LRESULT lResult = CExtToolControlBar::WindowProc( message, wParam, lParam );
  863. return lResult;
  864. }
  865. void CExtThemeSwitcherToolControlBar::ThemeSwitcher_OnButtonInvoke(
  866. CExtThemeSwitcherToolButton * pTBB
  867. )
  868. {
  869. ASSERT_VALID( this );
  870. ASSERT_VALID( pTBB );
  871. ASSERT( LPVOID(pTBB->GetBar()) == LPVOID(this) );
  872. UINT nCmdID = pTBB->GetCmdID(false);
  873. UINT nCurrPmID = UINT( PmBridge_GetPM()->OnQueryPaintManagerName() );
  874. UINT nBasicID = ID_SEPARATOR;
  875. m_mapCmdID2ThemeType.Lookup( nCmdID, nBasicID );
  876. if( nCurrPmID == nBasicID )
  877. return;
  878. CRuntimeClass * pRTC = NULL;
  879. if( ! m_mapCmd2RTC.Lookup( nCmdID, pRTC ) )
  880. return;
  881. g_PaintManager.InstallPaintManager( pRTC );
  882. //  if( m_pDockSite->GetSafeHwnd() != NULL )
  883. //  {
  884. //  m_pDockSite->RecalcLayout();
  885. //  m_pDockSite->RedrawWindow(
  886. //  NULL,
  887. //  NULL,
  888. //  RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE
  889. //  | RDW_FRAME | RDW_ALLCHILDREN
  890. //  );
  891. //  CExtControlBar::stat_RedrawFloatingFrames( m_pDockSite );
  892. //  CExtControlBar::stat_RecalcBarMetrics( m_pDockSite );
  893. //  } // if( m_pDockSite->GetSafeHwnd() != NULL )
  894. //  else
  895. //  {
  896. //  } // else from if( m_pDockSite->GetSafeHwnd() != NULL )
  897. }
  898. void CExtThemeSwitcherToolControlBar::ThemeSwitcher_OnButtonUpdate(
  899. CExtThemeSwitcherToolButton * pTBB
  900. )
  901. {
  902. ASSERT_VALID( this );
  903. ASSERT_VALID( pTBB );
  904. ASSERT( LPVOID(pTBB->GetBar()) == LPVOID(this) );
  905. bool bRedrawButton = false;
  906. UINT nCmdID = pTBB->GetCmdID(false);
  907. CRuntimeClass * pRTC = NULL;
  908. if( m_mapCmd2RTC.Lookup( nCmdID, pRTC ) )
  909. {
  910. if( pTBB->IsDisabled() )
  911. {
  912. bRedrawButton = true;
  913. pTBB->ModifyStyle( 0, TBBS_DISABLED );
  914. }
  915. CExtPaintManager::e_paint_manager_name_t ePMN =
  916. PmBridge_GetPM()->OnQueryPaintManagerName();
  917. UINT nCheckID = 0;
  918. if( ! m_arrMapsTT[m_eTIS_ToolBar].Lookup( UINT(ePMN), nCheckID ) )
  919. return;
  920. if( nCheckID == nCmdID )
  921. {
  922. if( (pTBB->GetStyle()&TBBS_CHECKED) == 0 )
  923. {
  924. bRedrawButton = true;
  925. pTBB->ModifyStyle( TBBS_CHECKED );
  926. }
  927. }
  928. else
  929. {
  930. if( (pTBB->GetStyle()&TBBS_CHECKED) != 0 )
  931. {
  932. bRedrawButton = true;
  933. pTBB->ModifyStyle( 0, TBBS_CHECKED );
  934. }
  935. }
  936. }
  937. else
  938. {
  939. if( (pTBB->GetStyle()&TBBS_CHECKED) != 0 )
  940. {
  941. bRedrawButton = true;
  942. pTBB->ModifyStyle( 0, TBBS_CHECKED );
  943. }
  944. if( ! pTBB->IsDisabled() )
  945. {
  946. bRedrawButton = true;
  947. pTBB->ModifyStyle( TBBS_DISABLED );
  948. }
  949. }
  950. if( bRedrawButton
  951. && (pTBB->GetStyle()&TBBS_HIDDEN) == 0
  952. && pTBB->IsVisible()
  953. )
  954. pTBB->RedrawButton( false );
  955. }
  956. UINT CExtThemeSwitcherToolControlBar::ThemeSwitcher_GetMenuCmdIDByToolBarCmdID(
  957. UINT nCmdID
  958. )
  959. {
  960. ASSERT_VALID( this );
  961. if( nCmdID == ID_SEPARATOR || (! CExtCmdManager::IsCommand( nCmdID ) ) )
  962. return 0;
  963. UINT nBasicID = ID_SEPARATOR;
  964. if( ! m_mapCmdID2ThemeType.Lookup(nCmdID,nBasicID) )
  965. return 0;
  966. UINT nEffectiveID = ID_SEPARATOR;
  967. if( ! m_arrMapsTT[int(m_eTIS_PopupMenu)].Lookup(nBasicID,nEffectiveID) )
  968. return 0;
  969. return nEffectiveID;
  970. }
  971. UINT CExtThemeSwitcherToolControlBar::ThemeSwitcher_GetToolBarCmdIDByMenuCmdID(
  972. UINT nCmdID
  973. )
  974. {
  975. ASSERT_VALID( this );
  976. if( nCmdID == ID_SEPARATOR || (! CExtCmdManager::IsCommand( nCmdID ) ) )
  977. return 0;
  978. UINT nBasicID = ID_SEPARATOR;
  979. if( ! m_mapCmdID2ThemeType.Lookup(nCmdID,nBasicID) )
  980. return 0;
  981. UINT nEffectiveID = ID_SEPARATOR;
  982. if( ! m_arrMapsTT[int(m_eTIS_ToolBar)].Lookup(nBasicID,nEffectiveID) )
  983. return 0;
  984. return nEffectiveID;
  985. }
  986. #endif // (!defined __EXT_MFC_NO_THEME_SWITCHER_TOOLBAR)