OOExToolBar.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. // = oooo oooo
  3. // = oooooo oooooo
  4. // = oo oo oo oo
  5. // = oo oo oo oo
  6. // = oooooo oooooo
  7. // = oooo oooo Copyright ( c ) The Old Ones 1998
  8. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  9. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  10. // General information section.
  11. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  12. // $Author:: $ User who last changed the file
  13. // $Date:: $ Date and time of last check in
  14. // $Revision:: $ Visual SourceSafe version number
  15. // $Workfile:: $ Filename
  16. // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  17. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  18. // History section.
  19. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  20. // $History:: $
  21. // End =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  22. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23. // @doc
  24. // @module OOExToolBar.cpp |
  25. // This module include an improved tool bar.
  26. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  28. // Include file section.
  29. // ------------------------------------------------------------------------
  30. // Precompile header file.
  31. #include "StdAfx.h"
  32. // Base class definition.
  33. #include "OOExToolBar.h"
  34. // Math include file.
  35. #include "math.h"
  36. #include ".\ooextoolbar.h"
  37. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  38. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  39. // Macro and other definition.
  40. // ------------------------------------------------------------------------
  41. #ifdef _DEBUG
  42. #define new DEBUG_NEW
  43. #undef THIS_FILE
  44. static char THIS_FILE[] = __FILE__;
  45. #endif
  46. IMPLEMENT_DYNAMIC( COOExToolBar, CToolBar )
  47. BEGIN_MESSAGE_MAP( COOExToolBar, CToolBar )
  48. //{{AFX_MSG_MAP( COOExToolBar )
  49. ON_WM_NCCALCSIZE()
  50. ON_WM_CREATE()
  51. ON_WM_NCPAINT()
  52. ON_WM_SYSCOLORCHANGE()
  53. ON_WM_WINDOWPOSCHANGING()
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  57. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  58. // Initialization and destruction method.
  59. // ------------------------------------------------------------------------
  60. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61. // @mfunc: (IMPLEMENTATION)
  62. // <c COOExToolBar>
  63. // This is the main constructor.
  64. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  65. COOExToolBar::COOExToolBar( void )
  66. {
  67. // Set the default flag.
  68. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  69. m_nShowIconMode = 1; // Large icon.
  70. m_bShowIconText = false; // Text.
  71. m_SmallIconSize = CSize( 16, 16 );
  72. m_LargeIconSize = CSize( 32, 32 );
  73. m_bOldFloating=false;
  74. }
  75. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  76. // @mfunc: (IMPLEMENTATION)
  77. // <c COOExToolBar>
  78. // This is the main destructor.
  79. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  80. COOExToolBar::~COOExToolBar( void )
  81. {
  82. // Free the image list associated memory.
  83. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  84. for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
  85. {
  86. if ( m_ImageList[ i ].GetSafeHandle() )
  87. m_ImageList[ i ].DeleteImageList();
  88. }
  89. }
  90. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  91. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  92. // Mode related method.
  93. // ------------------------------------------------------------------------
  94. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  95. // @mfunc: (FUNCTIONAL)
  96. // <c COOExToolBar>
  97. // To view large or small icon.
  98. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  99. void COOExToolBar::SetIconMode(
  100. UINT _nShowIconMode ) // @Parm 0 Small Icon, 1 Large Icon, 2 Extra Large Icon.
  101. {
  102. // Store the new value.
  103. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  104. m_nShowIconMode = _nShowIconMode;
  105. // Load the image list.
  106. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  107. AssignImageList();
  108. // Resize the toolbar.
  109. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  110. ResizeToolBar();
  111. }
  112. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  113. // @mfunc: (FUNCTIONAL)
  114. // <c COOExToolBar>
  115. // To get the large or small icon mode.
  116. // @RDesc 0 Small Icon, 1 Large Icon, 2 Extra Large Icon.
  117. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  118. UINT COOExToolBar::GetIconMode( void ) const
  119. {
  120. return m_nShowIconMode;
  121. }
  122. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  123. // @mfunc: (FUNCTIONAL)
  124. // <c COOExToolBar>
  125. // To set the text on or off.
  126. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  127. void COOExToolBar::SetTextMode(
  128. bool _bShowIconText ) // @Parm True to view the text, false to hide it.
  129. {
  130. // Store the new value.
  131. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  132. m_bShowIconText = _bShowIconText;
  133. // Resize the toolbar.
  134. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  135. ResizeToolBar();
  136. }
  137. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  138. // @mfunc: (FUNCTIONAL)
  139. // <c COOExToolBar>
  140. // To get the text on or off.
  141. // @RDesc True if the text is on, False otherwise.
  142. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  143. bool COOExToolBar::GetTextMode( void ) const
  144. {
  145. return m_bShowIconText;
  146. }
  147. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  148. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  149. // Loading information.
  150. // ------------------------------------------------------------------------
  151. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  152. // @mfunc: (FUNCTIONAL)
  153. // <c COOExToolBar>
  154. // To load the toolbar information.
  155. // @RDesc True if the tool bar is loaded.
  156. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  157. BOOL COOExToolBar::LoadToolBar(
  158. UINT _ResourceId ) // @Parm The toolbar resource id.
  159. {
  160. // Convert the resource id into a resource name and load the toolbar
  161. // using the base class method.
  162. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  163. CString lpszResourceName;
  164. lpszResourceName.Format( "#%d", _ResourceId );
  165. BOOL bReturn = CToolBar::LoadToolBar( lpszResourceName );
  166. // Check if we loaded the toolbar.
  167. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  168. if ( bReturn == FALSE )
  169. {
  170. return bReturn;
  171. }
  172. // Retrieve the height of the toolbar before putting text.
  173. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  174. CToolBarCtrl& bar = GetToolBarCtrl();
  175. int nIndex = 0;
  176. CRect NoTextRc( 0, 0, 0, 0 );
  177. bar.GetItemRect( 0, NoTextRc );
  178. // Set the text for each button.
  179. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  180. TBBUTTON tb;
  181. for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
  182. {
  183. ZeroMemory(&tb, sizeof(TBBUTTON));
  184. bar.GetButton(nIndex, &tb);
  185. // Do we have a separator?
  186. if ( ( tb.fsStyle & TBSTYLE_SEP ) == TBSTYLE_SEP ) {
  187. continue;
  188. }
  189. // Have we got a valid command id?
  190. if ( tb.idCommand == 0 ) {
  191. continue;
  192. }
  193. // Get the resource string if there is one.
  194. CString strText((LPCSTR)tb.idCommand);
  195. LPCTSTR lpszButtonText = NULL;
  196. CString strButtonText(_T(""));
  197. _TCHAR seps[] = _T("\n");
  198. if ( !strText.IsEmpty() ) {
  199. lpszButtonText = _tcstok( ( LPTSTR ) ( LPCTSTR ) strText, seps );
  200. while( lpszButtonText )
  201. {
  202. strButtonText = lpszButtonText;
  203. lpszButtonText = _tcstok( NULL, seps );
  204. }
  205. }
  206. if ( !strButtonText.IsEmpty() ) {
  207. SetButtonText( nIndex, strButtonText );
  208. }
  209. }
  210. // Calculate the effect of the text on the toolbar.
  211. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  212. CRect rc( 0, 0, 0, 0 );
  213. CSize sizeMax( 0, 0 );
  214. for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
  215. {
  216. bar.GetItemRect( nIndex, rc );
  217. rc.NormalizeRect();
  218. sizeMax.cx = __max( rc.Size().cx, sizeMax.cx );
  219. sizeMax.cy = __max( rc.Size().cy, sizeMax.cy );
  220. }
  221. // Resize the toolbar.
  222. // The text width is the maximum width of the bitmap. All toolbar size
  223. // must at least be this width.
  224. // The text height is the height added to the button. Even in large mode
  225. // we must add this text height.
  226. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  227. m_nTextWidth = sizeMax.cx;
  228. m_nTextHeight = sizeMax.cy - ( NoTextRc.Size().cy );
  229. ResizeToolBar();
  230. // Create the needed image list.
  231. // Build the image list.
  232. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  233. CClientDC dc( this );
  234. int nNbBits = dc.GetDeviceCaps( BITSPIXEL );
  235. for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
  236. {
  237. UINT nColorMode = ILC_COLOR;
  238. if ( nNbBits > 8 )
  239. {
  240. nColorMode = ILC_COLORDDB;
  241. }
  242. CSize Size = m_LargeIconSize;
  243. if ( i < 3 )
  244. {
  245. Size = m_SmallIconSize;
  246. }
  247. m_ImageList[ i ].Create( Size.cx, Size.cy, nColorMode | ILC_MASK, bar.GetButtonCount(), 10 );
  248. }
  249. return bReturn;
  250. }
  251. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  252. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  253. // Image list initialization method.
  254. // ------------------------------------------------------------------------
  255. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  256. // @mfunc: (FUNCTIONAL)
  257. // <c COOExToolBar>
  258. // To set the image list.
  259. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  260. void COOExToolBar::SetImageList(
  261. ImageMode_ _Mode, // @Parm The image mode.
  262. CImageList& _rList ) // @Parm The hoover image list.
  263. {
  264. // Store the list handle for future use.
  265. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  266. m_ImageList[ _Mode ].Attach( _rList.Detach() );
  267. }
  268. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  269. // @mfunc: (FUNCTIONAL)
  270. // <c COOExToolBar>
  271. // To set the current mode appropriate image list.
  272. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  273. void COOExToolBar::AssignImageList( void )
  274. {
  275. // Prepare the list associated with the current mode.
  276. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  277. CImageList* pTempHotList;
  278. CImageList* pTempNormalList;
  279. CImageList* pTempDisableList;
  280. if ( m_nShowIconMode == 0 )
  281. {
  282. pTempHotList = &m_ImageList[ SmallHot ];
  283. pTempNormalList = &m_ImageList[ SmallStandard ];
  284. pTempDisableList = &m_ImageList[ SmallDisable ];
  285. }
  286. if ( m_nShowIconMode == 1 )
  287. {
  288. pTempHotList = &m_ImageList[ LargeHot ];
  289. pTempNormalList = &m_ImageList[ LargeStandard ];
  290. pTempDisableList = &m_ImageList[ LargeDisable ];
  291. }
  292. // Set the list in the control.
  293. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  294. SetHotImageList( pTempHotList );
  295. SetStandardImageList( pTempNormalList );
  296. SetDisableImageList( pTempDisableList );
  297. }
  298. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  299. // @mfunc: (FUNCTIONAL)
  300. // <c COOExToolBar>
  301. // To set the image list in the control.
  302. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  303. void COOExToolBar::InitImageList( void )
  304. {
  305. // Set the image list according to the current mode.
  306. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  307. AssignImageList();
  308. }
  309. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  310. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  311. // Private Image list method.
  312. // ------------------------------------------------------------------------
  313. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  314. // @mfunc: (FUNCTIONAL)
  315. // <c COOExToolBar>
  316. // Method to calculate the current size of the button.
  317. // @rdesc The button size.
  318. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  319. CSize COOExToolBar::CalcButtonSize( void )
  320. {
  321. // Calcul the width of the drop button.
  322. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  323. CSize theButtonSize;
  324. if ( m_nShowIconMode == 0 )
  325. {
  326. theButtonSize = CSize( m_SmallIconSize.cx + 8, m_SmallIconSize.cy + 7 );
  327. }
  328. else if ( m_nShowIconMode == 1 )
  329. {
  330. theButtonSize = CSize( m_LargeIconSize.cx + 8, m_LargeIconSize.cy + 7 );
  331. }
  332. // Check the text mode and set or hide the text.
  333. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  334. if ( m_bShowIconText )
  335. {
  336. // The text width is the maximum width of the bitmap. All toolbar size
  337. // must at least be this width.
  338. if ( theButtonSize.cx < m_nTextWidth )
  339. {
  340. theButtonSize.cx = m_nTextWidth;
  341. }
  342. // The text height is the height added to the button. Even in large mode
  343. // we must add this text height.
  344. theButtonSize.cy += m_nTextHeight;
  345. }
  346. return theButtonSize;
  347. }
  348. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  349. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  350. // Image list information method.
  351. // ------------------------------------------------------------------------
  352. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  353. // @mfunc: (FUNCTIONAL)
  354. // <c COOExToolBar>
  355. // To set the hoover image list.
  356. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  357. void COOExToolBar::SetHotImageList(
  358. CImageList* pList ) // @Parm The hoover image list.
  359. {
  360. // Retrieve the tool bar control and set the list reference.
  361. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  362. CWnd* pWnd = &GetToolBarCtrl();
  363. pWnd->SendMessage( TB_SETHOTIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
  364. }
  365. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  366. // @mfunc: (FUNCTIONAL)
  367. // <c COOExToolBar>
  368. // To set the normal image list.
  369. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  370. void COOExToolBar::SetStandardImageList(
  371. CImageList* pList ) // @Parm The normal image list.
  372. {
  373. // Retrieve the tool bar control and set the list reference.
  374. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  375. CWnd* pWnd = &GetToolBarCtrl();
  376. pWnd->SendMessage( TB_SETIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
  377. }
  378. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  379. // @mfunc: (FUNCTIONAL)
  380. // <c COOExToolBar>
  381. // To set the disable image list.
  382. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  383. void COOExToolBar::SetDisableImageList(
  384. CImageList* pList ) // @Parm The normal image list.
  385. {
  386. // Retrieve the tool bar control and set the list reference.
  387. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  388. CWnd* pWnd = &GetToolBarCtrl();
  389. pWnd->SendMessage( TB_SETDISABLEDIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
  390. }
  391. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  392. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  393. // Usefull protected method.
  394. // ------------------------------------------------------------------------
  395. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  396. // @mfunc: (FUNCTIONAL)
  397. // <c COOExToolBar>
  398. // To display the dropdown button for the given button.
  399. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  400. void COOExToolBar::SetButtonDropDown(
  401. int nID ) // @Parm The id to show the drop down.
  402. {
  403. // Change button style to dropdown.
  404. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  405. DWORD dwStyle = GetButtonStyle( CommandToIndex( nID ) );
  406. dwStyle |= TBSTYLE_DROPDOWN;
  407. SetButtonStyle( CommandToIndex( nID ), dwStyle );
  408. // Calculate the drop button size.
  409. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  410. CToolBarCtrl& bar = GetToolBarCtrl();
  411. CSize theStdButtonSize = CalcButtonSize();
  412. CRect rc( 0, 0, 0, 0 );
  413. bar.GetItemRect( CommandToIndex( nID ), rc );
  414. m_nDropButtonSize = rc.Width() - theStdButtonSize.cx;
  415. }
  416. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  417. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  418. // Usefull protected method.
  419. // ------------------------------------------------------------------------
  420. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  421. // @mfunc: (FUNCTIONAL)
  422. // <c COOExToolBar>
  423. // To resieze the toolbar once something change.
  424. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  425. void COOExToolBar::ResizeToolBar( void )
  426. {
  427. // Set the size of the toolbar corresponding to the current mode.
  428. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  429. CSize theSize = ( m_nShowIconMode == 0 ) ? m_SmallIconSize : m_LargeIconSize;
  430. CSize theButtonSize = CalcButtonSize();
  431. // Resize the toolbar and the dock frame.
  432. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  433. SetSizes( theButtonSize, theSize );
  434. MoveWindow( 200, 200, 450, theButtonSize.cy );
  435. SendMessage( WM_SIZE, SIZE_RESTORED );
  436. CFrameWnd* pFrameWnd = GetDockingFrame();
  437. pFrameWnd->DelayRecalcLayout();
  438. }
  439. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  440. // @mfunc: (FUNCTIONAL)
  441. // <c COOExToolBar>
  442. // To draw the gripper on the toolbar.
  443. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  444. void COOExToolBar::DrawGripper(
  445. CDC& dc ) const // @Parm The device context where to draw the gripper.
  446. {
  447. // No gripper if floating
  448. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  449. if( m_dwStyle & CBRS_FLOATING )
  450. {
  451. return;
  452. }
  453. // Retrieve the window coord and calculate the gripper position.
  454. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  455. CRect gripper;
  456. GetWindowRect( gripper );
  457. ScreenToClient( gripper );
  458. gripper.OffsetRect( -gripper.left, -gripper.top );
  459. // Draw it accordingly to the orientation of the toolbar.
  460. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  461. COLORREF clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
  462. COLORREF clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  463. if( m_dwStyle & CBRS_ORIENT_HORZ ) {
  464. // gripper at left
  465. gripper.DeflateRect( 3, 3 );
  466. gripper.right = gripper.left+3;
  467. dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
  468. gripper.OffsetRect(5, 0);
  469. dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
  470. }
  471. else {
  472. // gripper at top
  473. gripper.DeflateRect( 3, 3 );
  474. gripper.bottom = gripper.top+3;
  475. dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
  476. gripper.OffsetRect(0, 5);
  477. dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
  478. }
  479. }
  480. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  481. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  482. // MFC Overloaded method.
  483. // ------------------------------------------------------------------------
  484. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  485. // @mfunc: (FUNCTIONAL)
  486. // <c COOExToolBar>
  487. // Only overloaded to use our cmdui instead of their. This is
  488. // the same code found in CToolBar::OnUpdateCmdUI, but we
  489. // replace the CCmdUI by CCoolCmdUI.
  490. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  491. void COOExToolBar::OnUpdateCmdUI(
  492. CFrameWnd* pTarget, // @Parm ??
  493. BOOL bDisableIfNoHndler ) // @Parm ??
  494. {
  495. CCoolCmdUI state; // this is the only line that's different--PD
  496. state.m_pOther = this;
  497. state.m_nIndexMax = ( UINT ) DefWindowProc( TB_BUTTONCOUNT, 0, 0 );
  498. for ( state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++ )
  499. {
  500. // get button state
  501. TBBUTTON button;
  502. VERIFY( DefWindowProc( TB_GETBUTTON, state.m_nIndex, ( LPARAM ) &button ) );
  503. // TBSTATE_ENABLED == TBBS_DISABLED so invert it
  504. button.fsState ^= TBSTATE_ENABLED;
  505. state.m_nID = button.idCommand;
  506. // ignore separators
  507. if ( !( button.fsStyle & TBSTYLE_SEP ) )
  508. {
  509. // allow the toolbar itself to have update handlers
  510. if ( CWnd::OnCmdMsg( state.m_nID, CN_UPDATE_COMMAND_UI, &state, NULL ) )
  511. continue;
  512. // allow the owner to process the update
  513. state.DoUpdate( pTarget, bDisableIfNoHndler );
  514. }
  515. }
  516. // update the dialog controls added to the toolbar
  517. UpdateDialogControls( pTarget, bDisableIfNoHndler );
  518. }
  519. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  520. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  521. // MFC Message method.
  522. // ------------------------------------------------------------------------
  523. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  524. // @mfunc: (FUNCTIONAL)
  525. // <c COOExToolBar>
  526. // This will draw the gripper on the toolbar then repaints
  527. // client areas.
  528. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  529. void COOExToolBar::OnNcPaint( void )
  530. {
  531. CControlBar::EraseNonClient();
  532. CWindowDC dc( this );
  533. DrawGripper( dc );
  534. CRect pRect;
  535. GetClientRect( &pRect );
  536. InvalidateRect( &pRect, TRUE );
  537. CWnd* pWnd = &GetToolBarCtrl();
  538. pWnd->GetClientRect( &pRect );
  539. pWnd->InvalidateRect( &pRect, TRUE );
  540. DeleteObject( dc );
  541. }
  542. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  543. // @mfunc: (FUNCTIONAL)
  544. // <c COOExToolBar>
  545. // Trap to set the flat bar style.
  546. // @RDesc Nonzero if the toolbar is correctly created.
  547. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  548. int COOExToolBar::OnCreate(
  549. LPCREATESTRUCT lpCreateStruct ) // @Parm Toolbar creation information.
  550. {
  551. // Call the base class method.
  552. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  553. if ( CToolBar::OnCreate( lpCreateStruct ) == -1 )
  554. {
  555. return -1;
  556. }
  557. // Set the style to flat.
  558. // There is a but when docking vertical. The size of the separator
  559. // is not calculate correctly by MFC. Only in style flat.
  560. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  561. ModifyStyle( 0, TBSTYLE_FLAT );
  562. SendMessage( TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS );
  563. // The window is now created.
  564. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  565. return 0;
  566. }
  567. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  568. // @mfunc: (FUNCTIONAL)
  569. // <c COOExToolBar>
  570. // Trap to size correctly the toolbar with the carret.
  571. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  572. void COOExToolBar::OnNcCalcSize(
  573. BOOL bCalcValidRects, // @Parm MFC Specific message.
  574. NCCALCSIZE_PARAMS FAR* lpncsp ) // @Parm MFC Specific message.
  575. {
  576. // No gripper if floating
  577. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  578. if( !( m_dwStyle & CBRS_FLOATING ) )
  579. {
  580. // Adjust non-client area for gripper at left or top.
  581. if( m_dwStyle & CBRS_ORIENT_HORZ ) {
  582. lpncsp->rgrc[0].left += 5;
  583. lpncsp->rgrc[0].right += 5;
  584. }
  585. else {
  586. lpncsp->rgrc[0].top += 5;
  587. lpncsp->rgrc[0].bottom += 5;
  588. }
  589. }
  590. CToolBar::OnNcCalcSize( bCalcValidRects, lpncsp );
  591. }
  592. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  593. // @mfunc: (FUNCTIONAL)
  594. // <c COOExToolBar>
  595. // Call when ever the system color are changing. Trap to rebuild
  596. // the toolbar image list with the good background color.
  597. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  598. void COOExToolBar::OnSysColorChange( void )
  599. {
  600. // Call the base class method.
  601. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  602. CToolBar::OnSysColorChange();
  603. }
  604. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  605. // @mfunc: (FUNCTIONAL)
  606. // <c COOExToolBar>
  607. // Call when the toolbar is moved. There is a bug when the tool
  608. // bar is in flat mode, and in vertical position. The separator
  609. // are not count in the height, so the last button is not completly
  610. // displayed.
  611. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  612. void COOExToolBar::OnWindowPosChanging( LPWINDOWPOS _pWindowPos )
  613. {
  614. // Default processing
  615. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  616. if( m_bOldFloating != ( IsFloating()?true:false ) )
  617. {
  618. m_bOldFloating = !m_bOldFloating;
  619. _pWindowPos->flags |= SWP_DRAWFRAME;
  620. }
  621. CToolBar::OnWindowPosChanging( _pWindowPos );
  622. }
  623. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  624. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  625. // MFC Overloaded method.
  626. // The following stuff is to make the command update UI mechanism
  627. // work properly for flat tool bars. The main idea is to convert
  628. // a "checked" button state into a "pressed" button state. Changed
  629. // lines marked with "PD"
  630. // ------------------------------------------------------------------------
  631. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  632. // @mfunc: (FUNCTIONAL)
  633. // <c CCoolCmdUI>
  634. // Came from Paul Dilascia Article.
  635. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  636. void CCoolCmdUI::Enable( BOOL bOn )
  637. {
  638. m_bEnableChanged = TRUE;
  639. CToolBar* pToolBar = ( CToolBar* ) m_pOther;
  640. ASSERT( pToolBar != NULL );
  641. ASSERT_KINDOF( CToolBar, pToolBar );
  642. ASSERT( m_nIndex < m_nIndexMax );
  643. UINT nNewStyle = pToolBar->GetButtonStyle( m_nIndex ) & ~TBBS_DISABLED;
  644. if ( !bOn )
  645. {
  646. nNewStyle |= TBBS_DISABLED;
  647. // WINBUG: If a button is currently pressed and then is disabled
  648. // COMCTL32.DLL does not unpress the button, even after the mouse
  649. // button goes up! We work around this bug by forcing TBBS_PRESSED
  650. // off when a button is disabled.
  651. nNewStyle &= ~TBBS_PRESSED;
  652. }
  653. ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
  654. pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
  655. }
  656. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  657. // @mfunc: (FUNCTIONAL)
  658. // <c CCoolCmdUI>
  659. // Came from Paul Dilascia Article.
  660. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  661. void CCoolCmdUI::SetCheck( int nCheck )
  662. {
  663. ASSERT( nCheck >= 0 && nCheck <= 2 ); // 0=>off, 1=>on, 2=>indeterminate
  664. CToolBar* pToolBar = ( CToolBar* ) m_pOther;
  665. ASSERT( pToolBar != NULL );
  666. ASSERT_KINDOF( CToolBar, pToolBar );
  667. ASSERT( m_nIndex < m_nIndexMax );
  668. UINT nOldStyle = pToolBar->GetButtonStyle( m_nIndex ); // PD
  669. UINT nNewStyle = nOldStyle &
  670. ~( TBBS_PRESSED | TBBS_INDETERMINATE ); // PD
  671. if ( nCheck == 1 )
  672. nNewStyle |= TBBS_PRESSED; // PD
  673. else if ( nCheck == 2 )
  674. nNewStyle |= TBBS_INDETERMINATE;
  675. // Following is to fix display bug for TBBS_CHECKED:
  676. // If new state is unchecked, repaint--but only if style actually changing.
  677. // (Otherwise will end up with flicker)
  678. //
  679. if ( nNewStyle != nOldStyle ) {
  680. ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
  681. pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
  682. pToolBar->Invalidate();
  683. }
  684. }
  685. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  686. CSize COOExToolBar::CalcDynamicLayout(int nLength, DWORD dwMode)
  687. {
  688. if ((nLength == -1) &&
  689. !(dwMode & LM_MRUWIDTH) && !(dwMode & LM_COMMIT) &&
  690. ((dwMode & LM_HORZDOCK) || (dwMode & LM_VERTDOCK)))
  691. {
  692. return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZDOCK);
  693. }
  694. return CalcLayout(dwMode, nLength);
  695. }
  696. //////////////////
  697. // 1998 Microsoft Systems Journal - Paul DiLascia
  698. // This is the all-important function that gets the true size of a button,
  699. // instead of using m_sizeButton. And it's virtual, so you can override if
  700. // my algorithm doesn't work, as will surely be the case in some circumstances.
  701. //
  702. CSize COOExToolBar::GetButtonSize(TBBUTTON* pData, int iButton)
  703. {
  704. // Get the actual size of the button, not what's in m_sizeButton.
  705. // Make sure to do SendMessage instead of calling MFC's GetItemRect,
  706. // which has all sorts of bad side-effects! (Go ahead, take a look at it.)
  707. //
  708. CRect rc;
  709. SendMessage(TB_GETITEMRECT, iButton, (LPARAM)&rc);
  710. CSize sz = rc.Size();
  711. ////////////////
  712. // Now must do special case for various versions of comctl32.dll,
  713. //
  714. DWORD dwStyle = pData[iButton].fsStyle;
  715. if ((pData[iButton].fsState & TBSTATE_WRAP)) {
  716. if (dwStyle & TBSTYLE_SEP) {
  717. // this is the last separator in the row (eg vertically docked)
  718. // fudge the height, and ignore the width. TB_GETITEMRECT will return
  719. // size = (8 x 22) even for a separator in vertical toolbar
  720. //
  721. sz.cy = sz.cx;
  722. sz.cx = 0; // separator takes no width if it's the last one
  723. } else if (dwStyle & TBSTYLE_DROPDOWN ) {//&&
  724. //!m_bShowDropdownArrowWhenVertical) {
  725. // ignore width of dropdown
  726. sz.cx = 0;
  727. }
  728. }
  729. return sz;
  730. }
  731. //////////////////
  732. // 1998 Microsoft Systems Journal - Paul DiLascia
  733. // I renamed this from _GetButton.
  734. //
  735. void COOExToolBar::GetButton(int nIndex, TBBUTTON* pButton) const
  736. {
  737. CToolBar* pBar = (CToolBar*)this;
  738. VERIFY(pBar->SendMessage(TB_GETBUTTON, nIndex, (LPARAM)pButton));
  739. // TBSTATE_ENABLED == TBBS_DISABLED so invert it
  740. pButton->fsState ^= TBSTATE_ENABLED;
  741. }
  742. //////////////////
  743. // 1998 Microsoft Systems Journal - Paul DiLascia
  744. // I renamed this from _SetButton.
  745. //
  746. void COOExToolBar::SetButton(int nIndex, TBBUTTON* pButton)
  747. {
  748. // get original button state
  749. TBBUTTON button;
  750. VERIFY(SendMessage(TB_GETBUTTON, nIndex, (LPARAM)&button));
  751. // prepare for old/new button comparsion
  752. button.bReserved[0] = 0;
  753. button.bReserved[1] = 0;
  754. // TBSTATE_ENABLED == TBBS_DISABLED so invert it
  755. pButton->fsState ^= TBSTATE_ENABLED;
  756. pButton->bReserved[0] = 0;
  757. pButton->bReserved[1] = 0;
  758. // nothing to do if they are the same
  759. if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
  760. {
  761. // don't redraw everything while setting the button
  762. DWORD dwStyle = GetStyle();
  763. ModifyStyle(WS_VISIBLE, 0);
  764. VERIFY(SendMessage(TB_DELETEBUTTON, nIndex, 0));
  765. VERIFY(SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
  766. ModifyStyle(0, dwStyle & WS_VISIBLE);
  767. // invalidate appropriate parts
  768. if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
  769. ((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
  770. {
  771. // changing a separator
  772. Invalidate(FALSE);
  773. }
  774. else
  775. {
  776. // invalidate just the button
  777. CRect rect;
  778. if (SendMessage(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
  779. InvalidateRect(rect, FALSE); // don't erase background
  780. }
  781. }
  782. }
  783. //////////////////
  784. // 1998 Microsoft Systems Journal - Paul DiLascia
  785. // Make the parent frame my owner. This is important for status bar
  786. // prompts to work.
  787. //
  788. ////////////////////////////////////////////////////////////////
  789. // 1998 Microsoft Systems Journal - Paul DiLascia
  790. // Stuff below is copied from MFC, my mods marked **PD**
  791. #ifdef _MAC
  792. #define CX_OVERLAP 1
  793. #else
  794. #define CX_OVERLAP 0
  795. #endif
  796. CSize COOExToolBar::CalcSize(TBBUTTON* pData, int nCount)
  797. {
  798. ASSERT(pData != NULL && nCount > 0);
  799. CPoint cur(0,0);
  800. CSize sizeResult(0,0);
  801. int cyTallestOnRow = 0;
  802. for (int i = 0; i < nCount; i++)
  803. {
  804. if (pData[i].fsState & TBSTATE_HIDDEN)
  805. continue;
  806. // **PD** Load actual size of button into local var
  807. // that obscures CToolBar::m_sizeButton.
  808. CSize m_sizeButton = GetButtonSize(pData, i);
  809. // **PD** I also changed the logic below to be more correct.
  810. cyTallestOnRow = max(cyTallestOnRow, m_sizeButton.cy);
  811. sizeResult.cx = max(cur.x + m_sizeButton.cx, sizeResult.cx);
  812. sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
  813. cur.x += m_sizeButton.cx - CX_OVERLAP;
  814. if (pData[i].fsState & TBSTATE_WRAP)
  815. {
  816. cur.x = 0;
  817. cur.y += cyTallestOnRow;
  818. cyTallestOnRow = 0;
  819. if (pData[i].fsStyle & TBSTYLE_SEP)
  820. cur.y += m_sizeButton.cy;
  821. }
  822. }
  823. return sizeResult;
  824. }
  825. int COOExToolBar::WrapToolBar(TBBUTTON* pData, int nCount, int nWidth)
  826. {
  827. ASSERT(pData != NULL && nCount > 0);
  828. int nResult = 0;
  829. int x = 0;
  830. for (int i = 0; i < nCount; i++)
  831. {
  832. pData[i].fsState &= ~TBSTATE_WRAP;
  833. if (pData[i].fsState & TBSTATE_HIDDEN)
  834. continue;
  835. int dx, dxNext;
  836. // **PD** Load actual size of button into local var
  837. // that obscures CToolBar::m_sizeButton.
  838. CSize m_sizeButton = GetButtonSize(pData, i);
  839. dx = m_sizeButton.cx;
  840. dxNext = dx - CX_OVERLAP;
  841. if (x + dx > nWidth)
  842. {
  843. BOOL bFound = FALSE;
  844. for (int j = i; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
  845. {
  846. // Find last separator that isn't hidden
  847. // a separator that has a command ID is not
  848. // a separator, but a custom control.
  849. if ((pData[j].fsStyle & TBSTYLE_SEP) &&
  850. (pData[j].idCommand == 0) &&
  851. !(pData[j].fsState & TBSTATE_HIDDEN))
  852. {
  853. bFound = TRUE; i = j; x = 0;
  854. pData[j].fsState |= TBSTATE_WRAP;
  855. nResult++;
  856. break;
  857. }
  858. }
  859. if (!bFound)
  860. {
  861. for (int j = i - 1; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
  862. {
  863. // Never wrap anything that is hidden,
  864. // or any custom controls
  865. if ((pData[j].fsState & TBSTATE_HIDDEN) ||
  866. ((pData[j].fsStyle & TBSTYLE_SEP) &&
  867. (pData[j].idCommand != 0)))
  868. continue;
  869. bFound = TRUE; i = j; x = 0;
  870. pData[j].fsState |= TBSTATE_WRAP;
  871. nResult++;
  872. break;
  873. }
  874. if (!bFound)
  875. x += dxNext;
  876. }
  877. }
  878. else
  879. x += dxNext;
  880. }
  881. return nResult + 1;
  882. }
  883. //////////////////////////////////////////////////////////////////////////
  884. // 1998 Microsoft Systems Journal - Paul DiLascia
  885. // Functions below are NOT modified. They're only here because they
  886. // call the modified functions above, which are NOT virtual.
  887. void COOExToolBar::SizeToolBar(TBBUTTON* pData, int nCount, int nLength, BOOL bVert)
  888. {
  889. ASSERT(pData != NULL && nCount > 0);
  890. if (!bVert)
  891. {
  892. int nMin, nMax, nTarget, nCurrent, nMid;
  893. // Wrap ToolBar as specified
  894. nMax = nLength;
  895. nTarget = WrapToolBar(pData, nCount, nMax);
  896. // Wrap ToolBar vertically
  897. nMin = 0;
  898. nCurrent = WrapToolBar(pData, nCount, nMin);
  899. if (nCurrent != nTarget)
  900. {
  901. while (nMin < nMax)
  902. {
  903. nMid = (nMin + nMax) / 2;
  904. nCurrent = WrapToolBar(pData, nCount, nMid);
  905. if (nCurrent == nTarget)
  906. nMax = nMid;
  907. else
  908. {
  909. if (nMin == nMid)
  910. {
  911. WrapToolBar(pData, nCount, nMax);
  912. break;
  913. }
  914. nMin = nMid;
  915. }
  916. }
  917. }
  918. CSize size = CalcSize(pData, nCount);
  919. WrapToolBar(pData, nCount, size.cx);
  920. }
  921. else
  922. {
  923. CSize sizeMax, sizeMin, sizeMid;
  924. // Wrap ToolBar vertically
  925. WrapToolBar(pData, nCount, 0);
  926. sizeMin = CalcSize(pData, nCount);
  927. // Wrap ToolBar horizontally
  928. WrapToolBar(pData, nCount, 32767);
  929. sizeMax = CalcSize(pData, nCount);
  930. while (sizeMin.cx < sizeMax.cx)
  931. {
  932. sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
  933. WrapToolBar(pData, nCount, sizeMid.cx);
  934. sizeMid = CalcSize(pData, nCount);
  935. if (nLength < sizeMid.cy)
  936. {
  937. if (sizeMin == sizeMid)
  938. {
  939. WrapToolBar(pData, nCount, sizeMax.cx);
  940. return;
  941. }
  942. sizeMin = sizeMid;
  943. }
  944. else if (nLength > sizeMid.cy)
  945. sizeMax = sizeMid;
  946. else
  947. return;
  948. }
  949. }
  950. }
  951. struct _AFX_CONTROLPOS
  952. {
  953. int nIndex, nID;
  954. CRect rectOldPos;
  955. };
  956. CSize COOExToolBar::CalcLayout(DWORD dwMode, int nLength)
  957. {
  958. ASSERT_VALID(this);
  959. ASSERT(::IsWindow(m_hWnd));
  960. if (dwMode & LM_HORZDOCK)
  961. ASSERT(dwMode & LM_HORZ);
  962. int nCount;
  963. TBBUTTON* pData;
  964. CSize sizeResult(0,0);
  965. // Load Buttons
  966. {
  967. nCount = (int)SendMessage(TB_BUTTONCOUNT, 0, 0);
  968. if (nCount != 0)
  969. {
  970. int i;
  971. pData = new TBBUTTON[nCount];
  972. for (i = 0; i < nCount; i++)
  973. GetButton(i, &pData[i]); // **PD** renamed from _GetButton
  974. }
  975. }
  976. if (nCount > 0)
  977. {
  978. if (!(m_dwStyle & CBRS_SIZE_FIXED))
  979. {
  980. BOOL bDynamic = m_dwStyle & CBRS_SIZE_DYNAMIC;
  981. if (bDynamic && (dwMode & LM_MRUWIDTH))
  982. SizeToolBar(pData, nCount, m_nMRUWidth);
  983. else if (bDynamic && (dwMode & LM_HORZDOCK))
  984. SizeToolBar(pData, nCount, 32767);
  985. else if (bDynamic && (dwMode & LM_VERTDOCK))
  986. SizeToolBar(pData, nCount, 0);
  987. else if (bDynamic && (nLength != -1))
  988. {
  989. CRect rect; rect.SetRectEmpty();
  990. CalcInsideRect(rect, (dwMode & LM_HORZ));
  991. BOOL bVert = (dwMode & LM_LENGTHY);
  992. int nLen = nLength + (bVert ? rect.Height() : rect.Width());
  993. SizeToolBar(pData, nCount, nLen, bVert);
  994. }
  995. else if (bDynamic && (m_dwStyle & CBRS_FLOATING))
  996. SizeToolBar(pData, nCount, m_nMRUWidth);
  997. else
  998. SizeToolBar(pData, nCount, (dwMode & LM_HORZ) ? 32767 : 0);
  999. }
  1000. sizeResult = CalcSize(pData, nCount);
  1001. if (dwMode & LM_COMMIT)
  1002. {
  1003. _AFX_CONTROLPOS* pControl = NULL;
  1004. int nControlCount = 0;
  1005. BOOL bIsDelayed = m_bDelayedButtonLayout;
  1006. m_bDelayedButtonLayout = FALSE;
  1007. for(int i = 0; i < nCount; i++)
  1008. if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
  1009. nControlCount++;
  1010. if (nControlCount > 0)
  1011. {
  1012. pControl = new _AFX_CONTROLPOS[nControlCount];
  1013. nControlCount = 0;
  1014. for(int i = 0; i < nCount; i++)
  1015. {
  1016. if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
  1017. {
  1018. pControl[nControlCount].nIndex = i;
  1019. pControl[nControlCount].nID = pData[i].idCommand;
  1020. CRect rect;
  1021. GetItemRect(i, &rect);
  1022. ClientToScreen(&rect);
  1023. pControl[nControlCount].rectOldPos = rect;
  1024. nControlCount++;
  1025. }
  1026. }
  1027. }
  1028. if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
  1029. m_nMRUWidth = sizeResult.cx;
  1030. for (int i = 0; i < nCount; i++)
  1031. SetButton(i, &pData[i]); // **PD** renamed from _SetButton
  1032. if (nControlCount > 0)
  1033. {
  1034. for (int i = 0; i < nControlCount; i++)
  1035. {
  1036. CWnd* pWnd = GetDlgItem(pControl[i].nID);
  1037. if (pWnd != NULL)
  1038. {
  1039. CRect rect;
  1040. pWnd->GetWindowRect(&rect);
  1041. CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
  1042. GetItemRect(pControl[i].nIndex, &rect);
  1043. pt = rect.TopLeft() + pt;
  1044. pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  1045. }
  1046. }
  1047. delete[] pControl;
  1048. }
  1049. m_bDelayedButtonLayout = bIsDelayed;
  1050. }
  1051. delete[] pData;
  1052. }
  1053. //BLOCK: Adjust Margins
  1054. {
  1055. CRect rect; rect.SetRectEmpty();
  1056. CalcInsideRect(rect, (dwMode & LM_HORZ));
  1057. sizeResult.cy -= rect.Height();
  1058. sizeResult.cx -= rect.Width();
  1059. CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
  1060. sizeResult.cx = max(sizeResult.cx, size.cx);
  1061. sizeResult.cy = max(sizeResult.cy, size.cy);
  1062. }
  1063. return sizeResult;
  1064. }
  1065. CSize COOExToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  1066. {
  1067. DWORD dwMode = bStretch ? LM_STRETCH : 0;
  1068. dwMode |= bHorz ? LM_HORZ : 0;
  1069. return CalcLayout(dwMode);
  1070. }
  1071. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1072. // Macro and other definition.
  1073. // ------------------------------------------------------------------------
  1074. IMPLEMENT_DYNAMIC( COOBmpToolBar, COOExToolBar )
  1075. BEGIN_MESSAGE_MAP( COOBmpToolBar, COOExToolBar )
  1076. //{{AFX_MSG_MAP( COOBmpToolBar )
  1077. //}}AFX_MSG_MAP
  1078. ON_WM_ERASEBKGND()
  1079. END_MESSAGE_MAP()
  1080. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1081. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1082. // Initialization and destruction method.
  1083. // ------------------------------------------------------------------------
  1084. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1085. // @mfunc: (IMPLEMENTATION)
  1086. // <c COOBmpToolBar>
  1087. // This is the main constructor.
  1088. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1089. COOBmpToolBar::COOBmpToolBar( void )
  1090. {
  1091. }
  1092. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1093. // @mfunc: (IMPLEMENTATION)
  1094. // <c COOBmpToolBar>
  1095. // This is the main destructor.
  1096. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1097. COOBmpToolBar::~COOBmpToolBar( void )
  1098. {
  1099. }
  1100. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1101. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1102. // Image list initialization method.
  1103. // ------------------------------------------------------------------------
  1104. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1105. // @mfunc: (FUNCTIONAL)
  1106. // <c COOBmpToolBar>
  1107. // To set the image list in the control.
  1108. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1109. void COOBmpToolBar::InitImageList( void )
  1110. {
  1111. // Build the image list.
  1112. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1113. for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
  1114. {
  1115. BuildImageList( m_ImageList[ i ], m_256Image[ i ] );
  1116. }
  1117. // Set the image list according to the current mode.
  1118. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1119. AssignImageList();
  1120. }
  1121. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1122. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1123. // Private Image list method.
  1124. // ------------------------------------------------------------------------
  1125. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1126. // @mfunc: (FUNCTIONAL)
  1127. // <c COOBmpToolBar>
  1128. // To build an image list based on the given bitmap and size.
  1129. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1130. void COOBmpToolBar::BuildImageList(
  1131. CImageList& _rImageList, // @Parm The image list to build.
  1132. const CExBitmap& _rBitmap ) // @Parm The bitmap to put in the image list.
  1133. {
  1134. CBitmap bmpImage;
  1135. bmpImage.LoadBitmap( _rBitmap.m_nResourceId );
  1136. _rImageList.Add( &bmpImage, _rBitmap.m_clrTransparent );
  1137. }
  1138. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1139. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1140. // Image list information method.
  1141. // ------------------------------------------------------------------------
  1142. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1143. // @mfunc: (FUNCTIONAL)
  1144. // <c COOBmpToolBar>
  1145. // To set the small hoover bitmap.
  1146. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1147. void COOBmpToolBar::SetBitmap(
  1148. UINT _nBitmap, // @Parm The bitmap id.
  1149. ImageMode_ _Mode, // @Parm The image mode.
  1150. COLORREF _clrBk, // @Parm The background color.
  1151. bool _b256 ) // @Parm The nb of color.
  1152. {
  1153. // Initialise the bitmap info.
  1154. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1155. if ( _b256 )
  1156. {
  1157. m_256Image[ _Mode ].m_nResourceId = _nBitmap;
  1158. m_256Image[ _Mode ].m_clrTransparent = _clrBk;
  1159. }
  1160. else
  1161. {
  1162. m_16Image[ _Mode ].m_nResourceId = _nBitmap;
  1163. m_16Image[ _Mode ].m_clrTransparent = _clrBk;
  1164. }
  1165. }
  1166. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1167. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1168. // Usefull protected method.
  1169. // ------------------------------------------------------------------------
  1170. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1171. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1172. // MFC Overloaded method.
  1173. // ------------------------------------------------------------------------
  1174. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1175. // Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1176. // MFC Message method.
  1177. // ------------------------------------------------------------------------
  1178. // @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1179. BOOL COOBmpToolBar::OnEraseBkgnd(CDC* pDC)
  1180. {
  1181. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1182. //CBrush brush(RGB(189,184,238)); //(230, 241, 249));//
  1183. //CRect r;
  1184. ////GetClientRect(&r);
  1185. //GetWindowRect( &r );
  1186. //pDC-> FillRect(&r,&brush);
  1187. //return TRUE;
  1188. return COOExToolBar::OnEraseBkgnd(pDC);
  1189. }