home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / toolbar2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  29.5 KB  |  1,339 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // implements the CNSToolbar2 class
  20.  
  21. #include "stdafx.h"
  22. #include "toolbar2.h"
  23.  
  24. #define SPACE_BETWEEN_BUTTONS 2
  25. #define LEFT_TOOLBAR_MARGIN 10
  26.  
  27.  
  28. //IMPLEMENT_DYNCREATE(CNSToolbar2, CWnd)
  29.  
  30.  
  31. SCODE CToolbarDropSource::GiveFeedback(DROPEFFECT dropEffect)
  32. {
  33.   if(dropEffect == DROPEFFECT_MOVE)
  34.   {
  35.        SetCursor(theApp.LoadCursor( IDC_MOVEBUTTON));
  36. #ifdef WIN32
  37.        return NO_ERROR;
  38. #else
  39.        return NOERROR;
  40. #endif
  41.  
  42.   }
  43.      return COleDropSource::GiveFeedback(dropEffect);
  44.  }
  45.  
  46.  
  47.  
  48. // Function - CNSToolbar2
  49. //
  50. // Constructor
  51. // 
  52. // Arguments - nMaxButtons        the maximum # of buttons we can manage
  53. //               bNoviceMode        whether or not we are in Novice Mode
  54. //               nNoviceSize        our height in Novice Mode
  55. //               nAdvancedSize    our height in Advanced Mode
  56. //
  57. // Returns - Nothing
  58. CNSToolbar2::CNSToolbar2(int nMaxButtons, int nToolbarStyle, int nPicturesAndTextHeight, int nPicturesHeight,
  59.                          int nTextHeight)
  60. {
  61.  
  62.     m_nMaxButtons = nMaxButtons;
  63.     m_nToolbarStyle = nToolbarStyle;
  64.     m_nPicturesAndTextHeight = nPicturesAndTextHeight;
  65.     m_nPicturesHeight = nPicturesHeight;
  66.     m_nTextHeight = nTextHeight;
  67.  
  68.     m_pButtonArray = new CToolbarButton*[nMaxButtons];
  69.     m_nNumButtons = 0;
  70.  
  71.     m_bDragging = FALSE;
  72.     m_pCustToolbar = NULL;
  73.     m_nMaxButtonWidth = 0;
  74.     m_nMaxButtonHeight = 0;
  75.  
  76.     m_nHeight = GetHeight();
  77.     m_nWidth = 0;
  78.     m_hBitmap = NULL;
  79.     m_nBitmapID = 0;
  80.     m_bButtonsSameWidth = TRUE;
  81.  
  82. }
  83.  
  84. CNSToolbar2::~CNSToolbar2()
  85. {
  86.     if(m_hBitmap != NULL)
  87.         ::DeleteObject(m_hBitmap);
  88.  
  89.     int i;
  90.  
  91.     for( i = 0; i < m_nNumButtons; i++)
  92.         delete m_pButtonArray[i];
  93.  
  94.     int nCount = m_pHiddenButtons.GetSize();
  95.  
  96.     for(i = 0; i < nCount; i++)
  97.     {
  98.         CToolbarButton * pButton = (CToolbarButton*)m_pHiddenButtons[i];
  99.         delete pButton;
  100.     }
  101.  
  102.     m_pHiddenButtons.RemoveAll();
  103.  
  104.     delete [] m_pButtonArray;
  105. }
  106.  
  107.  
  108. // Function - Create
  109. //
  110. // Creates a CNSToolbar2
  111. // 
  112. // Arguments - pParent            the parent window
  113. //
  114. // Returns - Non-zero if successful, 0 if failure
  115. int CNSToolbar2::Create(CWnd *pParent)
  116. {
  117.     CRect rect;
  118.  
  119.     rect.SetRectEmpty();
  120.     CBrush brush;
  121.  
  122.     BOOL bResult = CWnd::Create( theApp.NSToolBarClass, NULL, 
  123.              WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  124.              rect, pParent, 0, NULL);
  125.  
  126.     if(bResult)
  127.     {
  128.         HDC hDC = ::GetDC(m_hWnd);
  129.         WFE_InitializeUIPalette(hDC);
  130.         ::ReleaseDC(m_hWnd, hDC);
  131.     }
  132.     return bResult;
  133. }
  134.  
  135. // Function - Add
  136. //
  137. // Adds a button to the toolbar in position nIndex and layouts the buttons
  138. // 
  139. // 
  140. // Arguments - pButton            the button to add
  141. //               nIndex            the index to add it to
  142. //
  143. // Returns - nothing
  144. void CNSToolbar2::AddButtonAtIndex(CToolbarButton *pButton, int nIndex, BOOL bNotify)
  145. {
  146.     // for the moment, don't allow more than m_nMaxButtons.  However, eventually keep track of
  147.     // all items, but just make room for first m_nMaxButtons.
  148.     ASSERT( nIndex >= -1 && nIndex <= m_nNumButtons);
  149.  
  150.  
  151.     //if the button is already on the toolbar, remove it
  152.     int nPos;
  153.     if((nPos = FindButton(pButton)) != -1)
  154.     {
  155.         RemoveButton(nPos);
  156.         if(nPos < nIndex)
  157.             nIndex--;
  158.     }
  159.  
  160.     // if we are going to overflow, just remove the last one.
  161.     if(m_nNumButtons >= m_nMaxButtons && nIndex < m_nMaxButtons)
  162.         delete(RemoveButton(m_nMaxButtons - 1));
  163.  
  164.     if( nIndex == -1)
  165.     {
  166.         nIndex = m_nNumButtons;
  167.     }
  168.  
  169.     for(int i = m_nNumButtons; i > nIndex; i--)
  170.     {
  171.         m_pButtonArray[i] = m_pButtonArray[i - 1] ;
  172.         // new button id will have to be set
  173.     }
  174.  
  175.     m_pButtonArray[i] = pButton;
  176.     if(bNotify)
  177.         SendMessage(CASTUINT(TOOLBAR_BUTTON_ADD), (WPARAM) i, (LPARAM)pButton->m_hWnd);
  178.  
  179.     m_nNumButtons++;
  180.  
  181.     if(CheckMaxButtonSizeChanged(pButton, TRUE))
  182.     {
  183.         ChangeButtonSizes();
  184.         LayoutButtons(-1);
  185.         GetParentFrame()->RecalcLayout();
  186.     }
  187.     else
  188.     {
  189.         int nWidth;
  190.         
  191.         if(!m_bButtonsSameWidth)
  192.         {
  193.             CSize size = pButton->GetRequiredButtonSize();
  194.             nWidth = size.cx;
  195.         }
  196.         else
  197.             nWidth = m_nMaxButtonWidth;
  198.  
  199.         //make sure it's the size of the largest button so far
  200.         pButton->SetButtonSize(CSize(nWidth, m_nMaxButtonHeight));
  201.  
  202.         LayoutButtons(nIndex - 1);
  203.     }
  204. }
  205.  
  206. // bAddButton refers to whether or not the button is actually added.
  207. // It might be false if you wish to know what position it would be added to.
  208. int CNSToolbar2::AddButtonAtPoint(CToolbarButton *pButton, CPoint point, BOOL bAddButton)
  209. {
  210.  
  211.     int nStartX = 0;
  212.  
  213.     RECT buttonRect;
  214.  
  215.     for(int i = 0; i< m_nNumButtons; i++)
  216.     {
  217.         m_pButtonArray[i]->GetClientRect(&buttonRect);
  218.         m_pButtonArray[i]->MapWindowPoints(this, &buttonRect);
  219.  
  220.         nStartX += (buttonRect.right - buttonRect.left) + SPACE_BETWEEN_BUTTONS;
  221.         if(point.x < nStartX) break;
  222.  
  223.     }
  224.  
  225.     if(bAddButton)
  226.         AddButtonAtIndex(pButton, i);
  227.  
  228.     return i;
  229. }
  230.  
  231. void CNSToolbar2::AddHiddenButton(CToolbarButton *pButton)
  232. {
  233.     m_pHiddenButtons.Add(pButton);
  234.  
  235. }
  236.  
  237. // Function - Remove
  238. //
  239. // Removes the button at the given index and redoes the button layout
  240. // 
  241. // Arguments -  nIndex            the index to remove from
  242. //
  243. // Returns - the button being removed
  244. CToolbarButton* CNSToolbar2::RemoveButton(int nIndex, BOOL bNotify)
  245. {
  246.     ASSERT( nIndex < m_nMaxButtons);
  247.     ASSERT( nIndex >=0 && nIndex < m_nNumButtons);
  248.  
  249.     CToolbarButton *pButton = m_pButtonArray[nIndex];
  250.     if(bNotify)
  251.         SendMessage(CASTUINT(TOOLBAR_BUTTON_REMOVE), (WPARAM)nIndex, (LPARAM)pButton->m_hWnd);
  252.  
  253.     for(int i = nIndex; i < m_nNumButtons - 1; i++)
  254.     {
  255.         m_pButtonArray[i] = m_pButtonArray[i+1];
  256.         // new button id will have to be set
  257.     }
  258.  
  259.     m_nNumButtons--;
  260.  
  261.     pButton->MoveWindow(0,0,0,0);
  262.     
  263.     if(CheckMaxButtonSizeChanged(pButton, FALSE))
  264.     {
  265.         ChangeButtonSizes();
  266.         LayoutButtons(-1);
  267.         GetParentFrame()->RecalcLayout();
  268.     }
  269.     else
  270.     {
  271.         //make sure it's the size of the largest button so far
  272.         LayoutButtons(nIndex - 1);
  273.     }
  274.  
  275.  
  276.     return pButton;
  277.  
  278. }
  279.  
  280. // Function - Remove
  281. //
  282. // Removes the given button from the toolbar and redoes the button layout
  283. // 
  284. // Arguments -  pButton        the button to remove
  285. //
  286. // Returns - the button being removed or NULL if that button can't be found
  287. CToolbarButton* CNSToolbar2::RemoveButton(CToolbarButton *pButton)
  288. {
  289.  
  290.     for(int i = 0; i < m_nNumButtons; i++)
  291.     {
  292.         if(m_pButtonArray[i] == pButton)
  293.         {
  294.             return RemoveButton(i);
  295.         }
  296.     }
  297.  
  298.     return NULL;
  299. }
  300.  
  301. CToolbarButton* CNSToolbar2::RemoveButtonByCommand(UINT nCommand)
  302. {
  303.  
  304.     for(int i = 0; i < m_nNumButtons; i++)
  305.     {
  306.         if(m_pButtonArray[i]->GetButtonCommand() == nCommand)
  307.         {
  308.             return RemoveButton(i);
  309.         }
  310.     }
  311.  
  312.     return NULL;
  313. }
  314.  
  315. void CNSToolbar2::HideButtonByCommand(UINT nCommand)
  316. {
  317.  
  318.     for(int i = 0; i < m_nNumButtons; i++)
  319.     {
  320.         if(m_pButtonArray[i]->GetButtonCommand() == nCommand)
  321.         {
  322.             m_pHiddenButtons.Add(RemoveButton(i));
  323.         }
  324.     }
  325.  
  326. }
  327.  
  328. void CNSToolbar2::ShowButtonByCommand(UINT nCommand, int nPos)
  329. {
  330.  
  331.     int nCount = m_pHiddenButtons.GetSize();
  332.  
  333.     for(int i = 0; i < nCount; i++)
  334.     {
  335.         CToolbarButton *pButton = (CToolbarButton*)m_pHiddenButtons[i];
  336.  
  337.         if(pButton->GetButtonCommand() == nCommand)
  338.         {
  339.             m_pHiddenButtons.RemoveAt(i, 1);
  340.             AddButton(pButton, nPos);
  341.             return;
  342.         }
  343.     }
  344.  
  345. }
  346.  
  347. void CNSToolbar2::RemoveAllButtons(void)
  348. {
  349.     for(int i = m_nNumButtons - 1; i >= 0; i--)
  350.     {
  351.         delete(m_pButtonArray[i]);
  352.     }
  353.  
  354.     m_nNumButtons = 0;
  355.  
  356.     m_nMaxButtonWidth = 0;
  357.     m_nMaxButtonHeight = 0;
  358.  
  359.     m_nWidth = 0;
  360.  
  361.     RedrawWindow();
  362. }
  363.  
  364. CToolbarButton *CNSToolbar2::ReplaceButton(UINT nCommand, CToolbarButton *pNewButton)
  365. {
  366.  
  367.     for(int i = 0; i < m_nNumButtons; i++)
  368.     {
  369.         if(m_pButtonArray[i]->GetButtonCommand() == nCommand)
  370.         {
  371.             CToolbarButton *pOldButton = m_pButtonArray[i];
  372.             m_pButtonArray[i] = pNewButton;
  373.             pOldButton->ShowWindow(SW_HIDE);
  374.             pOldButton->SetParent(NULL);
  375.             pOldButton->SetOwner(NULL);
  376.  
  377.             pNewButton->SetParent(this);
  378.             pNewButton->SetOwner(this);
  379.             pNewButton->ShowWindow(SW_SHOWNA);
  380.  
  381.             if(CheckMaxButtonSizeChanged(pNewButton, TRUE))
  382.             {
  383.                 ChangeButtonSizes();
  384.                 LayoutButtons(-1);
  385.                 GetParentFrame()->RecalcLayout();
  386.             }
  387.             else
  388.             {
  389.                 //make sure it's the size of the largest button so far
  390.                 pNewButton->SetButtonSize(CSize(m_nMaxButtonWidth, m_nMaxButtonHeight));
  391.                 LayoutButtons(i - 1);
  392.             }
  393.  
  394.             return pOldButton;
  395.         }
  396.     }
  397.     return NULL;
  398.  
  399. }
  400.  
  401. void CNSToolbar2::ReplaceButton(UINT nOldCommand, UINT nNewCommand)
  402. {
  403.  
  404.     int nCount = m_pHiddenButtons.GetSize();
  405.  
  406.     for(int i = 0; i < nCount; i++)
  407.     {
  408.         CToolbarButton *pButton = (CToolbarButton*)m_pHiddenButtons[i];
  409.  
  410.         if(pButton->GetButtonCommand() == nNewCommand)
  411.         {
  412.             m_pHiddenButtons.RemoveAt(i, 1);
  413.             CToolbarButton *pHideButton = ReplaceButton(nOldCommand, pButton);
  414.             if(pHideButton)
  415.                 m_pHiddenButtons.Add(pHideButton);
  416.         }
  417.     }
  418.  
  419. }
  420.  
  421.  
  422. CToolbarButton* CNSToolbar2::GetNthButton(int nIndex)
  423. {
  424.     ASSERT( nIndex < m_nMaxButtons);
  425.     ASSERT( nIndex >=0 && nIndex < m_nNumButtons);
  426.  
  427.     return(m_pButtonArray[nIndex]);
  428. }
  429.  
  430. CToolbarButton* CNSToolbar2::GetButton(UINT nID)
  431. {
  432.     int nIndex = FindButton(nID);
  433.  
  434.     if(nIndex != -1)
  435.     {
  436.         return m_pButtonArray[nIndex];
  437.     }
  438.     else
  439.         return NULL;
  440.  
  441. }
  442.  
  443. int CNSToolbar2::GetNumButtons(void)
  444. {
  445.     return m_nNumButtons;
  446. }
  447.  
  448. void CNSToolbar2::SetBitmap(UINT nBitmapID)
  449. {
  450.     HINSTANCE hInst = AfxGetResourceHandle();
  451.  
  452.     if(m_hBitmap != NULL)
  453.         ::DeleteObject(m_hBitmap);
  454.  
  455.     if(nBitmapID == 0)
  456.         return;
  457.  
  458.     m_nBitmapID = nBitmapID;
  459.  
  460.     CDC *pDC = GetDC();
  461.     WFE_InitializeUIPalette(pDC->GetSafeHdc());
  462.  
  463.     m_hBitmap = WFE_LoadTransparentBitmap(hInst, pDC->m_hDC, 
  464.                 sysInfo.m_clrBtnFace, RGB(255, 0, 255), WFE_GetUIPalette(GetParentFrame()), nBitmapID);
  465.     ReleaseDC(pDC);
  466.  
  467. }
  468.  
  469. void CNSToolbar2::SetBitmap(char *pBitmapFile)
  470. {
  471.     HINSTANCE hInst = AfxGetResourceHandle();
  472.  
  473.     if(m_hBitmap != NULL)
  474.         ::DeleteObject(m_hBitmap);
  475.  
  476.     m_hBitmap = WFE_LoadBitmapFromFile(pBitmapFile);
  477. }
  478.  
  479.  
  480.  
  481. HBITMAP CNSToolbar2::GetBitmap(void)
  482. {
  483.     return m_hBitmap;
  484. }
  485.  
  486. // Function - ChangeSize
  487. //
  488. // Changes the mode of the toolbar and changes the mode of each button and then
  489. // lays each button out again
  490. // 
  491. // Arguments -  bNoviceMode        whether or not we are in novice mode
  492. //
  493. // Returns - nothing
  494. void CNSToolbar2::SetToolbarStyle(int nToolbarStyle)
  495. {
  496.     if(m_nToolbarStyle != nToolbarStyle)
  497.     {
  498.         m_nToolbarStyle = nToolbarStyle;
  499.  
  500.         int i;
  501.  
  502.         for(i = 0; i < m_nNumButtons; i++)
  503.         {
  504.             m_pButtonArray[i]->SetButtonMode(nToolbarStyle);
  505.         }
  506.  
  507.         int nCount = m_pHiddenButtons.GetSize();
  508.  
  509.         for(i = 0; i < nCount; i++)
  510.         {
  511.             ((CToolbarButton*)m_pHiddenButtons[i])->SetButtonMode(nToolbarStyle);
  512.         }
  513.  
  514.         FindLargestButton();
  515.         ChangeButtonSizes();
  516.  
  517.         m_nHeight = GetHeight();
  518.  
  519.         LayoutButtons(-1);
  520.         RedrawWindow();
  521.     }
  522. }
  523.  
  524. void CNSToolbar2::SetBitmapSize(int nWidth, int nHeight)
  525. {
  526.     for(int i = 0; i < m_nNumButtons; i++)
  527.     {
  528.         m_pButtonArray[i]->SetBitmapSize( CSize(nWidth, nHeight));
  529.     }
  530.  
  531.     FindLargestButton();
  532.     ChangeButtonSizes();
  533.     LayoutButtons(-1);
  534.  
  535. }
  536.  
  537. void CNSToolbar2::LayoutButtons(void)
  538. {
  539.     LayoutButtons(-1);
  540. }
  541.  
  542. int CNSToolbar2::GetHeight(void)
  543. {
  544.     return m_nMaxButtonHeight;
  545. }
  546.  
  547. int CNSToolbar2::GetWidth(void)
  548. {
  549.     return m_nWidth;
  550. }
  551.  
  552. void CNSToolbar2::SetButtonsSameWidth(BOOL bButtonsSameWidth)
  553. {
  554.     m_bButtonsSameWidth = bButtonsSameWidth;
  555.     LayoutButtons(-1);
  556. }
  557.  
  558. void CNSToolbar2::ReplaceButtonBitmapIndex(UINT nID, UINT nIndex)
  559. {
  560.  
  561.     int nButtonIndex = FindButton(nID);
  562.  
  563.     if(nButtonIndex != -1)
  564.     {
  565.         CToolbarButton *pButton = m_pButtonArray[nButtonIndex];
  566.         pButton->ReplaceBitmapIndex(nIndex);
  567.     }
  568.  
  569. }
  570.  
  571.  
  572. void CNSToolbar2::GetButtonXPosition(int nSelection,int & nStart,int & nEnd)
  573. {
  574.     if(nSelection >= 0 && nSelection < m_nNumButtons && m_pButtonArray[nSelection] != NULL)
  575.     {
  576.         CRect buttonRect;
  577.  
  578.         m_pButtonArray[nSelection]->GetClientRect(&buttonRect);
  579.         m_pButtonArray[nSelection]->MapWindowPoints(this, &buttonRect);
  580.  
  581.         nStart = buttonRect.left;
  582.         nEnd = buttonRect.right;
  583.     }
  584. }
  585.  
  586. // If bIsBefore is TRUE, finds the button before the one that occurs completely after boundary
  587. // if bIsBefore is FALSE, finds the button after the one the occurs completely before boundary
  588. // returns -1 if nothing fulfills these conditions
  589. int CNSToolbar2::FindButtonFromBoundary(int boundary, BOOL bIsBefore)
  590. {
  591.  
  592.     for(int i = 0; i < m_nNumButtons; i++)
  593.     {
  594.         CRect buttonRect;
  595.  
  596.         m_pButtonArray[i]->GetClientRect(&buttonRect);
  597.         m_pButtonArray[i]->MapWindowPoints(this, &buttonRect);
  598.         
  599.         if(bIsBefore)
  600.         {
  601.             if(buttonRect.left >= boundary)
  602.             {
  603.                 return(i == 0 ? -1 : i - 1);
  604.             }
  605.         }
  606.         else
  607.         {
  608.             if(buttonRect.right >= boundary)
  609.                 return i;
  610.         }
  611.     }
  612.  
  613.     return -1;
  614.  
  615. }
  616.  
  617.  
  618. void CNSToolbar2::SetCustomizableToolbar(CCustToolbar* pCustToolbar)
  619. {
  620.     m_pCustToolbar = pCustToolbar;
  621. }
  622.  
  623. CCustToolbar *CNSToolbar2::GetCustomizableToolbar(void)
  624. {
  625.  
  626.     return m_pCustToolbar;
  627. }
  628.  
  629. BOOL CNSToolbar2::OnCommand( WPARAM wParam, LPARAM lParam )
  630. {
  631.  
  632.     return((BOOL)GetParentFrame()->SendMessage(WM_COMMAND, wParam, lParam));
  633. }
  634.  
  635. void CNSToolbar2::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  636. {
  637.     for(int i = 0; i < m_nNumButtons; i++)
  638.     {
  639.         if(m_pButtonArray[i]->NeedsUpdate())
  640.         {
  641.             m_pButtonArray[i]->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  642.         }
  643.     }
  644. }
  645.  
  646. BOOL CNSToolbar2::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult )
  647. {
  648.     NMHDR *hdr = (NMHDR*)lParam;
  649.     if(hdr->code == TTN_NEEDTEXT)
  650.     {
  651.         int command = (int) wParam;
  652.         UINT hi = HIWORD(wParam);
  653.         UINT type = TTN_NEEDTEXT;
  654.         return TRUE;
  655.     }
  656. #ifdef _WIN32
  657.     else
  658.         return (CWnd::OnNotify(wParam, lParam, pResult));
  659. #else
  660.     return FALSE;
  661. #endif
  662. }
  663.  
  664. BOOL CNSToolbar2::SetDoOnButtonDownByCommand(UINT nCommand, BOOL bDoOnButtonDown)
  665. {
  666.  
  667.     for(int i = 0; i < m_nNumButtons; i++)
  668.     {
  669.         if(m_pButtonArray[i]->GetButtonCommand() == nCommand)
  670.         {
  671.             m_pButtonArray[i]->SetDoOnButtonDown(bDoOnButtonDown);
  672.             return TRUE;
  673.         }
  674.     }
  675.  
  676.     return FALSE;
  677. }
  678.  
  679. //////////////////////////////////////////////////////////////////////////
  680. //                    Messages for CNSToolbar2
  681. //////////////////////////////////////////////////////////////////////////
  682.  
  683. BEGIN_MESSAGE_MAP(CNSToolbar2, CWnd)
  684.     //{{AFX_MSG_MAP(CWnd)
  685.     ON_WM_LBUTTONDOWN()
  686.     ON_WM_LBUTTONUP()
  687.     ON_WM_MOUSEMOVE()
  688.     ON_MESSAGE(NSBUTTONDRAGGING, OnButtonDrag)
  689.     ON_WM_SHOWWINDOW()
  690.     ON_WM_ERASEBKGND()
  691.     ON_WM_PAINT()
  692.     ON_MESSAGE(TB_SIZECHANGED, OnToolbarButtonSizeChanged)
  693.     ON_WM_PALETTECHANGED()
  694.     ON_WM_SYSCOLORCHANGE()
  695.     //}}AFX_MSG_MAP
  696.  
  697. END_MESSAGE_MAP()
  698.  
  699. // Function - OnLButtonDown
  700. //
  701. // If the mouse click occured on a button then we may need to move the button
  702. // Otherwise we pass the click on to our parent because we may need to move the
  703. // toolbar
  704. // 
  705. // Arguments -  none
  706. //
  707. // Returns - nothing
  708. void CNSToolbar2::OnLButtonDown(UINT nFlags, CPoint point)
  709. {
  710.     MapWindowPoints(GetParent(), &point, 1);
  711.     GetParent()->SendMessage(WM_LBUTTONDOWN, nFlags, MAKELPARAM(point.x, point.y));
  712. }
  713.  
  714. void CNSToolbar2::OnMouseMove(UINT nFlags, CPoint point)
  715. {
  716.     MapWindowPoints(GetParent(), &point, 1);
  717.     GetParent()->SendMessage(WM_MOUSEMOVE, nFlags, MAKELPARAM(point.x, point.y));
  718. }
  719.  
  720. void CNSToolbar2::OnLButtonUp(UINT nFlags, CPoint point)
  721. {
  722.     MapWindowPoints(GetParent(), &point, 1);
  723.     GetParent()->SendMessage(WM_LBUTTONUP, nFlags, MAKELPARAM(point.x, point.y));
  724. }
  725.  
  726. LRESULT CNSToolbar2::OnButtonDrag(WPARAM wParam, LPARAM lParam)
  727. {
  728.     HWND hWnd = (HWND) lParam;
  729.  
  730.     CWnd *pButton = CWnd::FromHandle(hWnd);
  731.  
  732.     int nButtonIndex = FindButton(pButton);
  733.  
  734.     if(nButtonIndex != -1)
  735.     {
  736.         MoveButton(nButtonIndex);
  737.     }
  738.  
  739.     return 1;
  740. }
  741.  
  742. void CNSToolbar2::OnShowWindow( BOOL bShow, UINT nStatus )
  743. {
  744.     m_bEraseBackground = bShow;
  745. }
  746.  
  747. BOOL CNSToolbar2::OnEraseBkgnd( CDC* pDC )
  748. {
  749.     if ( m_bEraseBackground ) {
  750.         m_bEraseBackground = FALSE;
  751.         return (BOOL) Default();
  752.     } else {
  753.         return TRUE;
  754.     }
  755. }
  756.  
  757. void CNSToolbar2::OnPaint(void)
  758. {
  759.     CRect rcClient, updateRect, buttonRect, intersectRect;
  760.     
  761.     GetClientRect(&rcClient);
  762.     GetUpdateRect(&updateRect);
  763.  
  764.     CPaintDC dcPaint(this);
  765.     
  766.     // Use our background color
  767.     ::FillRect(dcPaint.m_hDC, &rcClient, sysInfo.m_hbrBtnFace);
  768.  
  769.     for (int i = 0; i < m_nNumButtons; i++)
  770.     {
  771.         m_pButtonArray[i]->GetClientRect(&buttonRect);
  772.  
  773.         m_pButtonArray[i]->MapWindowPoints(this, &buttonRect);
  774.  
  775.         if(intersectRect.IntersectRect(updateRect, buttonRect))
  776.         {
  777.             MapWindowPoints(m_pButtonArray[i], &intersectRect);
  778.             m_pButtonArray[i]->RedrawWindow(&intersectRect);
  779.         }
  780.  
  781.     }
  782.  
  783. }
  784.  
  785. LRESULT CNSToolbar2::OnToolbarButtonSizeChanged(WPARAM wParam, LPARAM lParam)
  786. {
  787.  
  788.     HWND hWnd = (HWND) lParam;
  789.  
  790.     CToolbarButton *pButton = (CToolbarButton*)CWnd::FromHandle(hWnd);
  791.  
  792.     int nButtonIndex = FindButton(pButton);
  793.  
  794.     if(nButtonIndex != -1)
  795.     {
  796.         if(CheckMaxButtonSizeChanged(pButton, TRUE) || CheckMaxButtonSizeChanged(pButton, FALSE))
  797.         {
  798.             ChangeButtonSizes();
  799.             LayoutButtons(-1);
  800.             GetParentFrame()->RecalcLayout();
  801.             GetParent()->SendMessage(CASTUINT(TOOLBAR_WIDTH_CHANGED), 0, LPARAM(m_hWnd));
  802.         }
  803.     }
  804.  
  805.  
  806.     return 1;
  807. }
  808.  
  809.  
  810.  
  811. void CNSToolbar2::OnPaletteChanged( CWnd* pFocusWnd )
  812. {
  813.     if (pFocusWnd != this) {
  814.         Invalidate();
  815.     }
  816. }
  817.   
  818. void CNSToolbar2::OnSysColorChange( )
  819. {
  820.     if(m_nBitmapID != 0)
  821.     {
  822.         SetBitmap(m_nBitmapID);
  823.  
  824.         CToolbarButton *pButton;
  825.  
  826.         for(int i = 0; i < m_nNumButtons; i++)
  827.         {
  828.             pButton = m_pButtonArray[i];
  829.             pButton->SetBitmap(m_hBitmap, TRUE);
  830.         }
  831.  
  832.         int nHiddenSize = m_pHiddenButtons.GetSize();
  833.         for(int j = 0; j < nHiddenSize; j++)
  834.         {
  835.             pButton = (CToolbarButton*)m_pHiddenButtons[j];
  836.             pButton->SetBitmap(m_hBitmap, TRUE);
  837.         }
  838.  
  839.         Invalidate();
  840.     }
  841. }
  842.  
  843.  
  844. //////////////////////////////////////////////////////////////////////////
  845. //                        Helper Functions for CNSToolbar2
  846. //////////////////////////////////////////////////////////////////////////
  847.  
  848. // Function - LayoutButtons
  849. //
  850. // Lays out the buttons starting with nStartIndex + 1.  If nStartIndex is not
  851. // 0, this uses nStartIndex's position to figure out the starting point for the
  852. // rest of the buttons.  If it's 0 then it just starts laying them out from 
  853. // LEFT_TOOLBAR_MARGIN
  854. // 
  855. // Arguments - nStartIndex        the index we will start laying out from
  856. //
  857. // Returns - nothing
  858. void CNSToolbar2::LayoutButtons(int nStartIndex)
  859. {
  860.     int nStartX = LEFT_TOOLBAR_MARGIN;
  861.     RECT buttonRect;
  862.     CSize buttonSize;
  863.  
  864.     // if it's not 0 then we can use the previous one as a reference point
  865.     if(nStartIndex >= 0)
  866.     {
  867.         m_pButtonArray[nStartIndex]->GetClientRect(&buttonRect);
  868.         m_pButtonArray[nStartIndex]->MapWindowPoints(this, &buttonRect);
  869.  
  870.         nStartX = buttonRect.right + SPACE_BETWEEN_BUTTONS;
  871.     }
  872.  
  873.     for( int i = nStartIndex + 1; i< m_nNumButtons; i++)
  874.     {
  875.         buttonSize = m_pButtonArray[i]->GetButtonSize();
  876.  
  877.         m_pButtonArray[i]->MoveWindow(nStartX, (m_nHeight - buttonSize.cy) / 2,
  878.                                       buttonSize.cx, buttonSize.cy);
  879.  
  880.         nStartX += buttonSize.cx + SPACE_BETWEEN_BUTTONS;
  881.  
  882.     }
  883.     //record the width of our toolbar
  884.     m_nWidth = nStartX;
  885. }
  886.  
  887. // Return the rect of the button with nID in screen coordinates
  888. // Returns TRUE if the button exists, FALSE if it doesn't.
  889. BOOL CNSToolbar2::GetButtonRect(UINT nID, RECT *pRect)
  890. {
  891.     int nIndex = FindButton(nID);
  892.  
  893.     if(nIndex != -1)
  894.     {
  895.         m_pButtonArray[nIndex]->GetWindowRect(pRect);
  896.         return TRUE;
  897.     }
  898.     else
  899.         return FALSE;
  900.  
  901. }
  902.  
  903. // Function - FindButton
  904. //
  905. // Given a point, finds out what button lies underneath that point
  906. // 
  907. // Arguments - point        the point we are looking at
  908. //
  909. // Returns - the index of the button or -1 if the point does not fall over
  910. //             a button
  911.  
  912.  
  913. int CNSToolbar2::FindButton(CPoint point)
  914. {
  915.  
  916.     RECT buttonRect;
  917.  
  918.     for(int i =0 ; i < m_nNumButtons; i++)
  919.     {
  920.         m_pButtonArray[i]->GetClientRect(&buttonRect);
  921.         m_pButtonArray[i]->MapWindowPoints(this, &buttonRect);
  922.  
  923.         if(point.x < buttonRect.left)
  924.         {
  925.             return -1;
  926.         }
  927.  
  928.         if(point.x <= buttonRect.right && point.y >= buttonRect.top &&
  929.             point.y <= buttonRect.bottom)
  930.         {
  931.             return i;
  932.         }
  933.     }
  934.  
  935.     return -1;
  936. }
  937.  
  938. // Function - FindButton
  939. //
  940. // Given a button, finds out what index it is in the button array
  941. // 
  942. // Arguments - pButton        the button whose index we are looking for
  943. //
  944. // Returns - the index of the button or -1 if the button does not exist
  945. //             a button
  946. int  CNSToolbar2::FindButton(CWnd *pButton)
  947. {
  948.  
  949.     for(int i = 0; i< m_nNumButtons; i++)
  950.     {
  951.         if(m_pButtonArray[i] == pButton)
  952.         {
  953.             return i;
  954.         }
  955.     }
  956.     
  957.     return -1;
  958. }
  959.  
  960. int     CNSToolbar2::FindButton(UINT nCommand)
  961. {
  962.     for(int i = 0; i< m_nNumButtons; i++)
  963.     {
  964.         if(m_pButtonArray[i]->GetButtonCommand() == nCommand)
  965.         {
  966.             return i;
  967.         }
  968.     }
  969.     
  970.     return -1;
  971. }
  972.  
  973. void CNSToolbar2::MoveButton(int nIndex)
  974. {
  975.     ASSERT(nIndex >= 0 && nIndex <m_nNumButtons);
  976.  
  977.     COleDataSource * pDataSource = new COleDataSource;  
  978.  
  979.  
  980.     m_pButtonArray[nIndex]->FillInOleDataSource(pDataSource);
  981.  
  982.     CToolbarButton *pButton = m_pButtonArray[nIndex];
  983.  
  984.     // Don't start drag until outside this rect 
  985.  
  986.     RECT rectDragStart;
  987.     pButton->GetClientRect(&rectDragStart);
  988.     pButton->MapWindowPoints(this, &rectDragStart);
  989.  
  990.     DROPEFFECT effect;
  991.     CToolbarDropSource * pDropSource = new CToolbarDropSource;
  992.  
  993.     effect=pDataSource->DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_SCROLL | DROPEFFECT_NONE,
  994.                             &rectDragStart, pDropSource);
  995.     
  996.  
  997.     delete pDropSource;
  998.     delete pDataSource;
  999.  
  1000. }
  1001.  
  1002. BOOL CNSToolbar2::CheckMaxButtonSizeChanged(CToolbarButton *pButton, BOOL bAdd)
  1003. {
  1004.     CSize size = pButton->GetRequiredButtonSize();
  1005.     BOOL bChanged = FALSE;
  1006.  
  1007.     if(bAdd)
  1008.     {
  1009.         if(m_bButtonsSameWidth)
  1010.         {
  1011.             if(size.cx > m_nMaxButtonWidth)
  1012.             {
  1013.                 m_nMaxButtonWidth = size.cx;
  1014.                 bChanged = TRUE;
  1015.             }
  1016.         }
  1017.  
  1018.         if(size.cy > m_nMaxButtonHeight)
  1019.         {
  1020.             m_nMaxButtonHeight = size.cy;
  1021.             m_nHeight = size.cy;
  1022.             bChanged = TRUE;
  1023.         }
  1024.     }
  1025.     else
  1026.     {
  1027.         if((size.cx == m_nMaxButtonWidth && m_bButtonsSameWidth) || size.cy == m_nMaxButtonHeight)
  1028.         {
  1029.             if(FindLargestButton())
  1030.                 bChanged = TRUE;
  1031.         }
  1032.         
  1033.     }
  1034.     return bChanged;
  1035.  
  1036. }
  1037.  
  1038. void CNSToolbar2::ChangeButtonSizes(void)
  1039. {
  1040.     int nWidth;
  1041.  
  1042.     for(int i = 0; i < m_nNumButtons; i++)
  1043.     {
  1044.         if(!m_bButtonsSameWidth)
  1045.         {
  1046.             CSize size = m_pButtonArray[i]->GetRequiredButtonSize();
  1047.             nWidth = size.cx;
  1048.         }
  1049.         else
  1050.             nWidth = m_nMaxButtonWidth;
  1051.  
  1052.         m_pButtonArray[i]->SetButtonSize(CSize(nWidth, m_nMaxButtonHeight));
  1053.     }
  1054. }
  1055.  
  1056. // returns TRUE if either max height or max width changed
  1057. BOOL CNSToolbar2::FindLargestButton(void)
  1058. {
  1059.     int nOldMaxWidth = m_nMaxButtonWidth;
  1060.     int nOldMaxHeight = m_nMaxButtonHeight;
  1061.  
  1062.     m_nMaxButtonHeight = 0;
  1063.  
  1064.     m_nMaxButtonWidth = 0;
  1065.  
  1066.     for(int i = 0; i < m_nNumButtons; i++)
  1067.     {
  1068.         CheckMaxButtonSizeChanged(m_pButtonArray[i], TRUE);
  1069.     }
  1070.  
  1071.     return (((nOldMaxWidth != m_nMaxButtonWidth) && m_bButtonsSameWidth) || nOldMaxHeight != m_nMaxButtonHeight);
  1072.  
  1073. }
  1074. // End CNSToolbar2 implementation
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080. ///////////////////////////////////////////////////////////////////////////
  1081. //                            Class CCommandToolbarDropTarget
  1082. ///////////////////////////////////////////////////////////////////////////
  1083.  
  1084. DROPEFFECT CCommandToolbarDropTarget::OnDragEnter(CWnd * pWnd,    COleDataObject * pDataObject,
  1085.                                                DWORD dwKeyState, CPoint point)
  1086. {
  1087.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  1088.     
  1089.     // We are interested in command buttons
  1090.     if(pDataObject->IsDataAvailable(
  1091.         ::RegisterClipboardFormat(NETSCAPE_COMMAND_BUTTON_FORMAT)))
  1092.     {
  1093.         deReturn = DROPEFFECT_MOVE;
  1094.     }
  1095.  
  1096.     return(deReturn);
  1097.     
  1098. }
  1099.  
  1100. DROPEFFECT CCommandToolbarDropTarget::OnDragOver(CWnd * pWnd, COleDataObject * pDataObject,
  1101.                                               DWORD dwKeyState, CPoint point )
  1102. {
  1103.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  1104.  
  1105.     // We are interested in bookmark buttons
  1106.     if(pDataObject->IsDataAvailable(
  1107.         ::RegisterClipboardFormat(NETSCAPE_COMMAND_BUTTON_FORMAT)))
  1108.     {
  1109.         deReturn = DROPEFFECT_MOVE;
  1110.     }
  1111.  
  1112.     return(deReturn);
  1113.     
  1114. }
  1115.  
  1116. BOOL CCommandToolbarDropTarget::OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  1117.             DROPEFFECT dropEffect, CPoint point)
  1118. {
  1119.     BOOL bRtn = FALSE;
  1120.     
  1121.     // We're interested in bookmark buttons
  1122.     CLIPFORMAT cfCommandButton = ::RegisterClipboardFormat(NETSCAPE_COMMAND_BUTTON_FORMAT);
  1123.     if (pDataObject->IsDataAvailable(cfCommandButton))
  1124.     {
  1125.  
  1126.         HGLOBAL hCommandButton = pDataObject->GetGlobalData(cfCommandButton);
  1127.         LPCOMMANDBUTTONITEM pCommandButtonItem = (LPCOMMANDBUTTONITEM)::GlobalLock(hCommandButton);
  1128.  
  1129.         ASSERT(pCommandButtonItem != NULL);
  1130.  
  1131.         BUTTONITEM buttonInfo = pCommandButtonItem->buttonInfo;
  1132.         ::GlobalUnlock(hCommandButton);
  1133.  
  1134.         CCommandToolbarButton *pCommandButton = (CCommandToolbarButton*)CWnd::FromHandlePermanent(buttonInfo.button);
  1135.  
  1136.         ((CNSToolbar2*)pWnd)->AddButtonAtPoint(pCommandButton, point);
  1137.         return TRUE;
  1138.  
  1139.     }
  1140.     
  1141.     return(bRtn);
  1142. }
  1143.  
  1144. // End CCommandToolbarDropTarget implementation
  1145.  
  1146. ///////////////////////////////////////////////////////////////////////////
  1147. //                            Class CCommandToolbar
  1148. ///////////////////////////////////////////////////////////////////////////
  1149. #define COMMANDTOOLBARSMALLHEIGHT 21
  1150.  
  1151. CCommandToolbar::CCommandToolbar(int nMaxButtons, int nToolbarStyle, int nPicturesAndTextHeight, 
  1152.                                  int nPicturesHeight, int nTextHeight)
  1153.      : CNSToolbar2(nMaxButtons, nToolbarStyle, nPicturesAndTextHeight, nPicturesHeight, nTextHeight)
  1154. {
  1155.     
  1156. }
  1157.  
  1158. int CCommandToolbar::Create(CWnd *pParent)
  1159. {
  1160.  
  1161.     int result = CNSToolbar2::Create(pParent);
  1162.  
  1163.     return result;
  1164. }
  1165.  
  1166. int CCommandToolbar::GetHeight(void)
  1167. {
  1168.  
  1169.     int nHeight = CNSToolbar2::GetHeight();
  1170.  
  1171.     if(m_nToolbarStyle != TB_PICTURESANDTEXT)
  1172.         nHeight = (COMMANDTOOLBARSMALLHEIGHT > nHeight) ? COMMANDTOOLBARSMALLHEIGHT : nHeight;
  1173.       
  1174.     return nHeight;
  1175.  
  1176. }
  1177.  
  1178. ///////////////////////////////////////////////////////////////////////////
  1179. //                        CCommandToolbarBar Messages
  1180. ///////////////////////////////////////////////////////////////////////////
  1181. BEGIN_MESSAGE_MAP(CCommandToolbar, CNSToolbar2)
  1182.     ON_WM_CREATE ( )
  1183. END_MESSAGE_MAP()
  1184.  
  1185. int CCommandToolbar::OnCreate ( LPCREATESTRUCT lpCreateStruct )
  1186. {
  1187.     int iRetVal = CNSToolbar2::OnCreate ( lpCreateStruct );
  1188.  
  1189.     m_DropTarget.Register(this);
  1190.     DragAcceptFiles(FALSE);
  1191.     return iRetVal;
  1192.  
  1193. }
  1194.  
  1195. ///////////////////////////////////////////////////////////////////////////
  1196. //                            Class CToolbarControlBar
  1197. ///////////////////////////////////////////////////////////////////////////
  1198.  
  1199. CToolbarControlBar::CToolbarControlBar(void)
  1200. {
  1201.     m_bEraseBackground = TRUE;
  1202.     m_pToolbar = NULL;
  1203. }
  1204.  
  1205. CToolbarControlBar::~CToolbarControlBar(void)
  1206. {
  1207.     if(m_pToolbar)
  1208.         delete m_pToolbar;
  1209. }
  1210.  
  1211. // Function    - Create
  1212. //
  1213. // Given a parent CFrameWnd, this creates the control bar that will hold all of the tabbed
  1214. // toolbars
  1215. // 
  1216. // Arguments - pParent        the parent frame window
  1217. //
  1218. // Returns - Nonzero if successful, 0 if unsuccessful
  1219. int CToolbarControlBar::Create(CFrameWnd *pParent, DWORD dwStyle, UINT nID )
  1220. {
  1221.     CRect rect;
  1222.  
  1223.     ASSERT_VALID(pParent);   // must have a parent
  1224.  
  1225. //    dwStyle &= ~CBRS_ALL;
  1226.  
  1227. #ifdef _WIN32
  1228.     dwStyle |= CBRS_ALIGN_TOP|CBRS_SIZE_DYNAMIC;
  1229.     m_dwStyle = dwStyle;
  1230. #else
  1231.     dwStyle = 0x2000; //Align top
  1232. #endif
  1233.  
  1234.     // create the HWND
  1235.     rect.SetRectEmpty();
  1236.     CBrush brush;
  1237.     if (!CWnd::Create(theApp.NSToolBarClass, NULL, dwStyle | WS_VISIBLE| WS_CLIPCHILDREN, rect,
  1238.         pParent, nID))
  1239.     {
  1240.         return 0;
  1241.     }
  1242.     // Note: Parent must resize itself for control bar to be resized
  1243. #ifdef _WIN32
  1244.     pParent->ShowControlBar(this, TRUE, FALSE);
  1245.     pParent->RecalcLayout();
  1246.  
  1247. #else
  1248.     ASSERT("That's not" == "16 bit");
  1249. #endif
  1250.     return 1;
  1251. }
  1252.  
  1253. CSize CToolbarControlBar::CalcDynamicLayout(int nLength, DWORD dwMode )
  1254. {
  1255.     if(m_pToolbar)
  1256.         return CSize(32767, m_pToolbar->GetHeight());
  1257.     else
  1258.         return CSize(32767, 0);
  1259.  
  1260. }
  1261.  
  1262. void CToolbarControlBar::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  1263. {
  1264.     if(m_pToolbar)
  1265.         m_pToolbar->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  1266. }
  1267.  
  1268. BEGIN_MESSAGE_MAP(CToolbarControlBar, CControlBar)
  1269.     //{{AFX_MSG_MAP(CWnd)
  1270.     ON_WM_SIZE()
  1271.     ON_WM_PAINT()
  1272.     ON_WM_SHOWWINDOW()
  1273.     ON_WM_ERASEBKGND()
  1274. #ifndef WIN32
  1275.     ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  1276. #endif
  1277.  
  1278.     //}}AFX_MSG_MAP
  1279. END_MESSAGE_MAP()
  1280.  
  1281. void CToolbarControlBar::OnSize( UINT nType, int cx, int cy )
  1282. {
  1283.     CWnd *pChild = GetWindow(GW_CHILD);
  1284.  
  1285.     if(pChild)
  1286.     {
  1287.         pChild->MoveWindow(0, 0, cx, cy, FALSE);
  1288.     }
  1289. }
  1290.  
  1291. void CToolbarControlBar::OnPaint(void)
  1292. {
  1293.     CRect rcClient, updateRect, toolbarRect, intersectRect;
  1294.  
  1295.     GetClientRect(&rcClient);
  1296.     GetUpdateRect(&updateRect);
  1297.     m_pToolbar->GetClientRect(&toolbarRect);
  1298.  
  1299.     CPaintDC dcPaint(this);
  1300.  
  1301.     // Use our background color
  1302.     ::FillRect(dcPaint.m_hDC, &rcClient, sysInfo.m_hbrBtnFace);
  1303.  
  1304. #ifdef _WIN32
  1305.     DrawBorders(&dcPaint, rcClient);
  1306. #endif
  1307.  
  1308.     m_pToolbar->MapWindowPoints(this, &toolbarRect);
  1309.  
  1310.     if(intersectRect.IntersectRect(updateRect, toolbarRect))
  1311.     {
  1312.         MapWindowPoints(m_pToolbar, &intersectRect);
  1313.         m_pToolbar->RedrawWindow(&intersectRect);
  1314.     }
  1315. }
  1316.  
  1317. void CToolbarControlBar::OnShowWindow( BOOL bShow, UINT nStatus )
  1318. {
  1319.     m_bEraseBackground = bShow;
  1320. }
  1321.  
  1322. BOOL CToolbarControlBar::OnEraseBkgnd( CDC* pDC )
  1323. {
  1324.     if ( m_bEraseBackground ) {
  1325.         m_bEraseBackground = FALSE;
  1326.         return (BOOL) Default();
  1327.     } else {
  1328.         return TRUE;
  1329.     }
  1330. }
  1331.  
  1332. #ifndef WIN32
  1333. LRESULT CToolbarControlBar::OnSizeParent(WPARAM wParam, LPARAM lParam)
  1334. {
  1335.     m_sizeFixedLayout = CalcDynamicLayout(0, 0);
  1336.     return CControlBar::OnSizeParent(wParam, lParam);
  1337. }
  1338. #endif
  1339.