NGenericToolBar.cpp
上传用户:libwxy
上传日期:2007-01-02
资源大小:200k
文件大小:19k
源码类别:

工具条

开发平台:

Visual C++

  1. // NGenericToolBar.cpp: implementation of the CNGenericToolBar class.
  2. //
  3. /*
  4. Copyright (C) 1998 Tony Hoyle (tmh@netfusion.co.uk)
  5. Copyright (C) 1998 George H. Stahl (GStahl@VipMail.Com)
  6. - Added GenericToolBarModifyStyle
  7. This program is free software; you can redistribute it and/or modify it under the terms
  8. of the GNU General Public License as published by the Free Software Foundation; either
  9. version 2 of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along with this program;
  14. if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "NGenericToolBar.h"
  19. #include "afxpriv.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. IMPLEMENT_DYNAMIC(CNGenericToolBar,CToolBar)
  26. BEGIN_MESSAGE_MAP(CNGenericToolBar,CToolBar)
  27. //{{AFX_MSG_MAP(CNGenericToolBar)
  28. ON_WM_CONTEXTMENU()
  29. ON_WM_DESTROY()
  30. ON_WM_PAINT()
  31. ON_WM_NCCALCSIZE()
  32. ON_WM_NCPAINT()
  33. ON_WM_NCHITTEST()
  34. //}}AFX_MSG_MAP
  35. ON_COMMAND(IDM_BUTTONSONLY,OnButtonsOnly)
  36. ON_COMMAND(IDM_BUTTONSANDTEXT,OnTextAndButtons)
  37. ON_COMMAND(IDM_TEXTONLY,OnTextOnly)
  38. ON_COMMAND(IDM_RECALCSIZE,OnRecalcSize)
  39.  END_MESSAGE_MAP()
  40. CArray<CNGenericToolBar*,CNGenericToolBar*> CNGenericToolBar::m_ToolbarList;
  41. BOOL CNGenericToolBar::m_bButtons=FALSE;
  42. BOOL CNGenericToolBar::m_bText=FALSE;
  43. //////////////////////////////////////////////////////////////////////
  44. // Construction/Destruction
  45. //////////////////////////////////////////////////////////////////////
  46. CNGenericToolBar::CNGenericToolBar()
  47. {
  48. m_bHasText=FALSE;
  49. m_bHasBitmaps=TRUE;
  50. m_bForceText=FALSE;
  51. m_bSysMenuIcon=FALSE;
  52. m_dwGenericToolBarStyle = 0x0000;
  53. }
  54. CNGenericToolBar::~CNGenericToolBar()
  55. {
  56. }
  57. void CNGenericToolBar::OnRecalcSize()
  58. {
  59. SettingChange();
  60. RecalcSize();
  61. GetParentFrame()->DelayRecalcLayout();
  62. }
  63. void CNGenericToolBar::SettingChange()
  64. {
  65. TBBUTTON tb;
  66. for(int n=0; n<GetCount(); n++)
  67. {
  68. SendMessage(TB_GETBUTTON,n,(LPARAM)&tb);
  69. tb.iString=m_bText?m_TextIds[n]:-1;
  70. _SetButton(n,&tb);
  71. }
  72. SendMessage(TB_SETMAXTEXTROWS,m_bText||m_bForceText?4:0);
  73. SendMessage(TB_SETBITMAPSIZE,0,m_bButtons&&m_bHasBitmaps?MAKELONG(16,15):0);
  74. SendMessage(TB_AUTOSIZE);
  75. }
  76. BOOL CNGenericToolBar::RecalcSize()
  77. {
  78. CRect rect;
  79. int cx=0,cy=0;
  80. SendMessage(TB_AUTOSIZE);
  81. for(int n=0; n<GetToolBarCtrl().GetButtonCount(); n++)
  82. {
  83. GetItemRect(n,&rect);
  84. if(rect.Width()>cx) cx=rect.Width();
  85. if(rect.Height()>cy) cy=rect.Height();
  86. }
  87. m_sizeButton.cx=cx;
  88. m_sizeButton.cy=cy-2;
  89. m_bDelayedButtonLayout=TRUE;
  90. return TRUE;
  91. }
  92. BOOL CNGenericToolBar::CreateEx(CWnd* pParentWnd, DWORD dwExStyle, DWORD dwStyle, UINT nID, LPCTSTR szTitle)
  93. {
  94. if(!CToolBar::Create(pParentWnd,dwStyle,nID)) return FALSE;
  95. if(szTitle) SetWindowText(szTitle);
  96. m_pParent=pParentWnd;
  97. ModifyStyle(0,dwExStyle);
  98. m_pop.CreatePopupMenu();
  99. m_pop.AppendMenu(MF_STRING,IDM_BUTTONSONLY,"&Buttons");
  100. m_pop.AppendMenu(MF_STRING,IDM_BUTTONSANDTEXT,"Buttons &and Text");
  101. m_pop.AppendMenu(MF_STRING,IDM_TEXTONLY,"&Text");
  102. m_ToolbarList.Add(this);
  103. return TRUE;
  104. }
  105. BOOL CNGenericToolBar::LoadToolBar(LPCTSTR lpszResourceName)
  106. {
  107. if(!CToolBar::LoadToolBar(lpszResourceName)) return FALSE;
  108. CString tmp;
  109. LPCTSTR p,q;
  110. SendMessage(TB_SETMAXTEXTROWS,4);
  111. m_accelList.SetSize(0);
  112. for(int n=0; n<GetCount(); n++)
  113. {
  114. if(GetItemID(n)!=-1)
  115. {
  116. tmp.LoadString(GetItemID(n));
  117. p=tmp;
  118. while(*p && *p!='n')
  119. p++;
  120. if(*p)
  121. {
  122. p++;
  123. while(*p && *p!='n')
  124. p++;
  125. }
  126. if(*p)
  127. {
  128. for(q=p; *q; q++)
  129. {
  130. if(*q=='&')
  131. {
  132. int s=m_accelList.GetSize();
  133. m_accelList.SetSize(s+1);
  134. m_accelList[s].nKey=toupper(*(q+1));
  135. m_accelList[s].nId=GetItemID(n);
  136. break;
  137. }
  138. }
  139. SetButtonText(n,p+1);
  140. m_bHasText=TRUE;
  141. m_bText=TRUE;
  142. }
  143. else
  144. {
  145. if(m_bHasText) SetButtonText(n," ");
  146. }
  147. }
  148. }
  149. TBBUTTON tb;
  150. m_TextIds.SetSize(0);
  151. for(n=0; n<GetCount(); n++)
  152. {
  153. SendMessage(TB_GETBUTTON,n,(LPARAM)&tb);
  154. m_TextIds.Add(tb.iString);
  155. tb.iString=m_bText?m_TextIds[n]:-1;
  156. }
  157. return TRUE;
  158. }
  159. BOOL CNGenericToolBar::SetButtonText(int nIndex, LPCTSTR lpszText)
  160. {
  161. if(!CToolBar::SetButtonText(nIndex,lpszText)) return FALSE;
  162. return RecalcSize();
  163. }
  164. void CNGenericToolBar::OnContextMenu(CWnd* pWnd, CPoint point) 
  165. {
  166. m_pop.CheckMenuItem(IDM_BUTTONSONLY,m_bButtons&&!m_bText?MF_CHECKED:MF_UNCHECKED);
  167. m_pop.CheckMenuItem(IDM_BUTTONSANDTEXT,m_bButtons&&m_bText?MF_CHECKED:MF_UNCHECKED);
  168. m_pop.CheckMenuItem(IDM_TEXTONLY,!m_bButtons&&m_bText?MF_CHECKED:MF_UNCHECKED);
  169. m_pop.EnableMenuItem(IDM_BUTTONSONLY,MF_ENABLED);
  170. m_pop.EnableMenuItem(IDM_BUTTONSANDTEXT,m_bHasText?MF_ENABLED:MF_GRAYED);
  171. m_pop.EnableMenuItem(IDM_TEXTONLY,m_bHasText?MF_ENABLED:MF_GRAYED);
  172. m_pop.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,pWnd);
  173. }
  174. void CNGenericToolBar::OnButtonsOnly()
  175. {
  176. if(!m_bText && m_bButtons) return;
  177. m_bText=FALSE;
  178. m_bButtons=TRUE;
  179. SendToAllToolbars(WM_COMMAND,IDM_RECALCSIZE);
  180. }
  181. void CNGenericToolBar::OnTextOnly()
  182. {
  183. if(m_bText && !m_bButtons) return;
  184. m_bText=TRUE;
  185. m_bButtons=FALSE;
  186. SendToAllToolbars(WM_COMMAND,IDM_RECALCSIZE);
  187. }
  188. void CNGenericToolBar::OnTextAndButtons()
  189. {
  190. if(m_bText && m_bButtons) return;
  191. m_bText=TRUE;
  192. m_bButtons=TRUE;
  193. SendToAllToolbars(WM_COMMAND,IDM_RECALCSIZE);
  194. }
  195. void CNGenericToolBar::OnDestroy() 
  196. {
  197. CToolBar::OnDestroy();
  198. for(int n=0; n<m_ToolbarList.GetSize(); n++)
  199. if(m_ToolbarList[n]==this)
  200. {
  201. m_ToolbarList.RemoveAt(n);
  202. break;
  203. }
  204. }
  205. void CNGenericToolBar::SendToAllToolbars(UINT uMsg, WPARAM wParam, LPARAM lParam)
  206. {
  207. for(int n=0; n<m_ToolbarList.GetSize(); n++)
  208. m_ToolbarList[n]->SendMessage(uMsg,wParam,lParam);
  209. }
  210. void CNGenericToolBar::SetVisualState(BOOL bButtons, BOOL bText)
  211. {
  212. if(!bText && !bButtons) bButtons=TRUE;
  213. m_bText=bText;
  214. m_bButtons=bButtons;
  215. SendToAllToolbars(WM_COMMAND,IDM_RECALCSIZE);
  216. }
  217. BOOL CNGenericToolBar::GetVisualState(BOOL bText)
  218. {
  219. if(bText) return m_bText;
  220. else return m_bButtons;
  221. }
  222. // Borrowed from MFC
  223. void CNGenericToolBar::_SetButton(int nIndex, TBBUTTON* pButton)
  224. {
  225. // get original button state
  226. TBBUTTON button;
  227. VERIFY(DefWindowProc(TB_GETBUTTON, nIndex, (LPARAM)&button));
  228. // prepare for old/new button comparsion
  229. button.bReserved[0] = 0;
  230. button.bReserved[1] = 0;
  231. // TBSTATE_ENABLED == TBBS_DISABLED so invert it
  232. pButton->fsState ^= TBSTATE_ENABLED;
  233. pButton->bReserved[0] = 0;
  234. pButton->bReserved[1] = 0;
  235. // nothing to do if they are the same
  236. if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
  237. {
  238. // don't redraw everything while setting the button
  239. DWORD dwStyle = GetStyle();
  240. ModifyStyle(WS_VISIBLE, 0);
  241. VERIFY(DefWindowProc(TB_DELETEBUTTON, nIndex, 0));
  242. VERIFY(DefWindowProc(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
  243. ModifyStyle(0, dwStyle & WS_VISIBLE);
  244. // invalidate appropriate parts
  245. if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
  246. ((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
  247. {
  248. // changing a separator
  249. Invalidate(FALSE);
  250. }
  251. else
  252. {
  253. // invalidate just the button
  254. CRect rect;
  255. SendMessage(TB_AUTOSIZE);
  256. if (DefWindowProc(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
  257. InvalidateRect(rect, FALSE);    // don't erase background
  258. }
  259. }
  260. }
  261. // Calculate the non-client area - adjusting for grippers
  262. void CNGenericToolBar::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  263. {
  264.      CToolBar::OnNcCalcSize(bCalcValidRects,lpncsp);
  265.      // adjust non-client area for gripper at left or top
  266.      if (m_dwStyle & CBRS_FLOATING)
  267.  {          // no grippers
  268.      }
  269.  else if (m_dwStyle & CBRS_ORIENT_HORZ)
  270.  {
  271.           // move 2 pixels right to make room
  272.           lpncsp->rgrc[0].left += 2;
  273.           lpncsp->rgrc[0].right += 2;
  274.      }
  275.  else
  276.  {          // move 4 pixels downto make room
  277.           lpncsp->rgrc[0].top += 4;
  278.           lpncsp->rgrc[0].bottom += 4;     
  279.  }
  280.  // Adjust for system menu icon
  281.  if(m_bSysMenuIcon)
  282.  {
  283. if(m_dwStyle&CBRS_ORIENT_HORZ)
  284. {
  285.   // move 16 pixels right to make room
  286.   lpncsp->rgrc[0].left += 16;
  287.   lpncsp->rgrc[0].right += 16;
  288. }
  289. else
  290. {    // move 16 pixels downto make room
  291.   lpncsp->rgrc[0].top += 16;
  292.   lpncsp->rgrc[0].bottom += 16;     
  293. }
  294.  }
  295. }
  296. // Draw the gripper at left or top
  297. void CNGenericToolBar::DrawGripper(CWindowDC *pDC, CRect& rectWindow)
  298. {
  299.      // get the gripper rect (1 pixel smaller than toolbar)
  300.      CRect gripper = rectWindow;
  301.      gripper.DeflateRect(1,1);
  302.      if (m_dwStyle & CBRS_FLOATING)
  303.  {          // no grippers
  304.      }
  305.  else if (m_dwStyle & CBRS_ORIENT_HORZ)
  306.  {          // gripper at left
  307.           gripper.right = gripper.left+3;
  308.           pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));
  309.           gripper.OffsetRect(+4,0);
  310.           pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));
  311.           rectWindow.left += 8; 
  312.  } else
  313.  {          // gripper at top
  314.           gripper.bottom = gripper.top+3;
  315.           pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));
  316.           gripper.OffsetRect(0,+4);
  317.           pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));
  318.           rectWindow.top += 8;
  319.      }
  320. }
  321. void CNGenericToolBar::DrawSysMenuIcon(CWindowDC* pDC, CRect& rectWindow)
  322. {
  323. if(!m_bSysMenuIcon) return; // Do nothing if this isn't needed
  324. if(m_dwStyle&CBRS_ORIENT_HORZ)
  325. {
  326. DrawIconEx(*pDC,rectWindow.left+2,rectWindow.top+6,m_hSysMenuIcon,16,16,0,NULL,DI_NORMAL);
  327. m_rectSysMenu.SetRect(rectWindow.left+2,rectWindow.top+6,rectWindow.left+2+16,rectWindow.top+6+16);
  328. rectWindow.left+=16;
  329. }
  330. else
  331. {
  332. DrawIconEx(*pDC,rectWindow.left+12,rectWindow.top+2,m_hSysMenuIcon,16,16,0,NULL,DI_NORMAL);
  333. m_rectSysMenu.SetRect(rectWindow.left+12,rectWindow.top+2,rectWindow.left+12+16,rectWindow.top+2+16);
  334. rectWindow.top+=16;
  335. }
  336. }
  337. // Erase the non-client area (borders) - copied from MFC implementation
  338. void CNGenericToolBar::EraseNonClient(BOOL bRaised)
  339. {
  340.      // get window DC that is clipped to the non-client area
  341.      CWindowDC dc(this);
  342.      CRect rectClient;
  343.      GetClientRect(rectClient);
  344.      CRect rectWindow;
  345.      GetWindowRect(rectWindow);
  346.      ScreenToClient(rectWindow);
  347.      rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
  348.      dc.ExcludeClipRect(rectClient);     // draw borders in non-client area
  349.      rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
  350. DrawBorders(&dc, rectWindow);     // erase parts not drawn
  351.      dc.IntersectClipRect(rectWindow);
  352.      SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);
  353.      DrawGripper(&dc, rectWindow); // <-- my addition to draw gripper}
  354.  DrawSysMenuIcon(&dc, rectWindow); // Draw icon for system menu, if needed
  355. }
  356. BOOL CNGenericToolBar::TranslateMenuChar(UINT nChar)
  357. {
  358. for(int n=0; n<m_accelList.GetSize(); n++)
  359. {
  360. if(m_accelList[n].nKey==(UINT)toupper(nChar))
  361. {
  362. m_pParent->PostMessage(WM_COMMAND,m_accelList[n].nId);
  363. return TRUE;
  364. }
  365. }
  366. return FALSE;
  367. }
  368. BOOL CNGenericToolBar::KeyboardFilter(UINT nChar, UINT nRepCnt, UINT nFlags)
  369. {
  370. return FALSE;
  371. }
  372. void CNGenericToolBar::DrawBorders(CDC* pDC, CRect& rect)
  373. {
  374. ASSERT_VALID(this);
  375. ASSERT_VALID(pDC);
  376. DWORD dwStyle = m_dwStyle;
  377. if (!(dwStyle & CBRS_BORDER_ANY))
  378. return;
  379. // prepare for dark lines
  380. ASSERT(rect.top == 0 && rect.left == 0);
  381. COLORREF clr=GetSysColor(COLOR_3DSHADOW);
  382. if(dwStyle&CBRS_BORDER_RIGHT)
  383. pDC->FillSolidRect(rect.right-1,0,rect.right,rect.bottom,clr); //right
  384. if(dwStyle&CBRS_BORDER_BOTTOM)
  385. pDC->FillSolidRect(0,rect.bottom-1,rect.right,rect.bottom,clr); //bottom
  386. clr=GetSysColor(COLOR_3DHIGHLIGHT);
  387. if(dwStyle&CBRS_BORDER_TOP)
  388. pDC->FillSolidRect(0,0,rect.right,1,clr); //top
  389. if(dwStyle&CBRS_BORDER_LEFT)
  390. pDC->FillSolidRect(0,0,1,rect.bottom,clr); //left
  391. if(dwStyle&CBRS_BORDER_TOP)
  392. rect.top++;
  393. if(dwStyle&CBRS_BORDER_RIGHT)
  394. rect.right--;
  395. if(dwStyle&CBRS_BORDER_BOTTOM)
  396. rect.bottom--;
  397. if(dwStyle&CBRS_BORDER_LEFT)
  398. rect.left++;
  399. }
  400. // Because buttons are transparent, we need to repaint the background
  401. void CNGenericToolBar::RepaintBackground()
  402. {
  403.      // get parent window (there should be one)
  404.      CWnd* pParent = GetParent();
  405.      if (pParent)
  406.  {
  407.           // get rect for this toolbar
  408.           CRect rw; GetWindowRect(&rw);
  409.           // convert rect to parent coords
  410.           CRect rc = rw; pParent->ScreenToClient(&rc);
  411.           // invalidate this part of parent
  412.           pParent->InvalidateRect(&rc);
  413.           // now do all the other toolbars (etc) that belong to the parent
  414.           for (CWnd* pSibling = pParent->GetWindow(GW_CHILD); pSibling; pSibling = pSibling->GetNextWindow(GW_HWNDNEXT))
  415.   {
  416.                // but do not draw ourselves
  417.                if (pSibling == this) continue;
  418.                // convert rect to siblings coords
  419.                CRect rc = rw; pSibling->ScreenToClient(&rc);
  420.                // invalidate this part of sibling
  421.                pSibling->InvalidateRect(&rc);
  422.           }
  423.      }
  424. }
  425. // Draw the separators in the client area
  426. void CNGenericToolBar::DrawSeparators()
  427. {
  428.      // get a dc for the client area
  429.      CClientDC dc(this);
  430.      // draw the separators on it
  431.      DrawSeparators(&dc);
  432. }
  433. // Draw the separators
  434. void CNGenericToolBar::DrawSeparators(CClientDC* pDC)
  435. {
  436.      // horizontal vs vertical
  437.      bool ishorz = (m_dwStyle & CBRS_ORIENT_HORZ) != 0;
  438.      // get number of buttons
  439.      int nIndexMax = (int)DefWindowProc(TB_BUTTONCOUNT, 0, 0);
  440.      int nIndex;
  441.      // try each button
  442.      for (nIndex = 0; nIndex < nIndexMax; nIndex++)
  443.  {
  444.           UINT dwStyle = GetButtonStyle(nIndex);
  445.           UINT wStyle = LOWORD(dwStyle);
  446.           // if it is a separator
  447.           if (wStyle == TBBS_SEPARATOR)
  448.   {
  449.                // get it's rectangle and width
  450.                CRect rect;
  451.                GetItemRect(nIndex,rect);
  452.                // if small enough to be a true separator
  453.                int w = rect.Width();
  454.                if (w <= 8)
  455.    {
  456.                     if (ishorz)
  457. {
  458.                          // draw the separator bar in the middle
  459.                          CRect rectbar = rect;
  460.                          int x = (rectbar.left+rectbar.right)/2;
  461.                          rectbar.left = x-1; rectbar.right = x+1;
  462.  rectbar.top++;
  463.  rectbar.bottom++;
  464.                          pDC->Draw3dRect(rectbar,::GetSysColor(COLOR_3DSHADOW),::GetSysColor(COLOR_3DHILIGHT));
  465.                     }
  466. else
  467. {
  468.                          // draw the separator bar in the middle
  469.                          CRect rectbar = rect;
  470.                          rectbar.left = rectbar.left - m_sizeButton.cx;
  471.                          rectbar.right = rectbar.left + m_sizeButton.cx;
  472.                          rectbar.top = rectbar.bottom+1;
  473.                          rectbar.bottom = rectbar.top+3;
  474.                          int y = (rectbar.top+rectbar.bottom)/2;
  475.                          rectbar.top = y-1; rectbar.bottom = y+1;
  476.                          pDC->Draw3dRect(rectbar,::GetSysColor(COLOR_3DSHADOW),::GetSysColor(COLOR_3DHILIGHT));
  477.                     }
  478.                }
  479.           }
  480.      }
  481. }
  482. // Because buttons are transparent, we need to repaint background if style changes
  483. void CNGenericToolBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  484. {
  485.      static CUIntArray styles;
  486.      // get the number of buttons
  487.      int nIndexMax = (int)DefWindowProc(TB_BUTTONCOUNT, 0, 0);
  488.      int nIndex;
  489.      // save styles
  490.      for (nIndex = 0; nIndex < nIndexMax; nIndex++)
  491.  {
  492.           UINT dwStyle = GetButtonStyle(nIndex);
  493.           styles.SetAtGrow(nIndex,dwStyle);
  494.      }
  495.      // do base class processing
  496.      CToolBar::OnUpdateCmdUI(pTarget,bDisableIfNoHndler);
  497.      // make checked button appear pushed in
  498.      for (nIndex = 0; nIndex < nIndexMax; nIndex++)
  499.  {
  500.           UINT dwStyle = GetButtonStyle(nIndex);
  501.           if (dwStyle & TBBS_DISABLED)
  502.   {
  503.                // don't touch if disabled (avoids flicker)
  504.           } else if (dwStyle & TBBS_CHECKBOX)
  505.   {
  506.                UINT dwStyleWas = dwStyle;
  507.                // if checked, make it pressed, else not pressed
  508.                if (dwStyle & TBBS_CHECKED)
  509.    {
  510.                     dwStyle |= TBBS_PRESSED;
  511.                } else if (!(styles[nIndex]&TBBS_CHECKED) && (styles[nIndex]&TBBS_PRESSED))
  512.    {
  513.                     dwStyle |= TBBS_PRESSED;
  514.                } else
  515.    {
  516.                     dwStyle &= ~TBBS_PRESSED;
  517.                }
  518.                // set new style if changed
  519.                if (dwStyleWas != dwStyle) SetButtonStyle(nIndex,dwStyle);
  520.           }
  521.      }
  522.      // check for changes to style (buttons presssed/released)
  523.      for (nIndex = 0; nIndex < nIndexMax; nIndex++)
  524.  {
  525.           UINT dwStyle = GetButtonStyle(nIndex);
  526.           if (styles[nIndex] != dwStyle)
  527.   {
  528.                // repaint whole toolbar (not just this button)
  529.                Invalidate();
  530.                // no need to check any more
  531.                break;
  532.           }
  533.      }
  534. }
  535. // Because buttons are transparent, we need to repaint background on size or move
  536. void CNGenericToolBar::OnWindowPosChanging(LPWINDOWPOS lpwp)
  537. {
  538.      // default processing
  539.      CToolBar::OnWindowPosChanging(lpwp);
  540.      RepaintBackground();
  541. }
  542. // Paint the toolbar
  543. void CNGenericToolBar::OnPaint()
  544. {
  545.      // standard toolbar
  546.      CToolBar::OnPaint();
  547.      // erase the background
  548.      EraseNonClient(FALSE);
  549.      // plus separators
  550.      DrawSeparators();
  551. }
  552. // Paint the non-client area - copied from MFC implementatios
  553. void CNGenericToolBar::OnNcPaint()
  554. {
  555.      //   EraseNonClient(); don't do it here
  556. }
  557. UINT CNGenericToolBar::OnNcHitTest(CPoint point) 
  558. {
  559. CPoint pt(point);
  560. CRect wRect;
  561. GetWindowRect(wRect);
  562. pt.x-=wRect.left;
  563. pt.y-=wRect.top;
  564. // If SysMenu icon is visible, hittest it specially
  565. if(m_bSysMenuIcon && m_rectSysMenu.PtInRect(pt))
  566. {
  567. OnOverSysMenu();
  568. return HTSYSMENU;
  569. }
  570. return CToolBar::OnNcHitTest(point);
  571. }
  572. BOOL CNGenericToolBar::GenericToolBarModifyStyle(DWORD dwRemove, DWORD dwAdd)
  573. {
  574. DWORD dwStyle = m_dwGenericToolBarStyle;
  575. DWORD dwNewStyle = (dwStyle & ~dwRemove) | dwAdd;
  576. if (dwStyle == dwNewStyle)
  577. return FALSE;
  578. m_dwGenericToolBarStyle = dwNewStyle;
  579. return TRUE;
  580. }