home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / csttlbr2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  56.5 KB  |  2,356 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. #include "stdafx.h"
  20. #include "csttlbr2.h"
  21. #include "toolbar2.h"
  22. #include "mainfrm.h"
  23. #include "edcombtb.h"
  24.       
  25. #define IDT_DRAGTOOLBAR_DRAGGING 16415
  26. #define DRAGTOOLBAR_DRAGGING_DELAY 100
  27. #define IDT_TABHAVEFOCUS 16416
  28. #define TABHAVEFOCUS_DELAY 100
  29.  
  30. #define CUSTTOOLBARID 33333
  31. #define CUTOFF_ON_ANIM_RESIZE 12
  32.  
  33. #ifdef XP_WIN16
  34. LRESULT CNetscapeControlBar::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
  35. {
  36.     ASSERT_VALID(this);
  37.  
  38.     // parent notification messages are just passed to parent of control bar
  39.     switch (nMsg)
  40.     {
  41.     case WM_COMMAND:
  42.         return CWnd::WindowProc(nMsg, wParam, lParam);
  43.         break;
  44.         
  45.     case WM_DRAWITEM:
  46.     case WM_MEASUREITEM:
  47.     case WM_DELETEITEM:
  48.     case WM_COMPAREITEM:
  49.     case WM_VKEYTOITEM:
  50.     case WM_CHARTOITEM:
  51.     case WM_VBXEVENT:
  52.         return GetOwner()->SendMessage(nMsg, wParam, lParam);
  53.     }
  54.     return CWnd::WindowProc(nMsg, wParam, lParam);
  55. }
  56. #endif
  57.  
  58. // Class:  CToolbarWindow
  59. //
  60. // The window that resides within the Tabbed toolbar.  It holds the toolbar
  61. // passed in by the user of the customizable toolbar
  62.  
  63.  
  64. // Function - CToolbarWindow
  65. //
  66. // Constructor
  67. // 
  68. // Arguments - None
  69. //
  70. // Returns - Nothing
  71. CToolbarWindow::CToolbarWindow(CWnd *pToolbar, int nToolbarStyle, int nNoviceHeight, int nAdvancedHeight,
  72.                                HTAB_BITMAP nHTab)
  73. {
  74.     m_pToolbar = pToolbar;
  75.     m_nNoviceHeight = nNoviceHeight;
  76.     m_nAdvancedHeight = nAdvancedHeight;
  77.     m_nToolbarStyle = nToolbarStyle;
  78.     m_nHTab = nHTab;
  79. }
  80.  
  81. CToolbarWindow::~CToolbarWindow()
  82. {
  83. }
  84.  
  85. CWnd * CToolbarWindow::GetToolbar(void)
  86. {
  87.     
  88.     return m_pToolbar;    
  89.     
  90. }
  91.  
  92. int CToolbarWindow::GetHeight(void)
  93. {
  94.     return(m_nToolbarStyle == TB_PICTURESANDTEXT ? m_nNoviceHeight : m_nAdvancedHeight);
  95. }
  96.  
  97.  
  98. // End of CToolbarWindow implementation
  99.  
  100. // Class:  CButtonToolbarWindow
  101. //
  102.  
  103. CButtonToolbarWindow::CButtonToolbarWindow(CWnd *pToolbar, int nToolbarStyle, int nNoviceHeight, int nAdvancedHeight,
  104.                                            HTAB_BITMAP nHTab) 
  105. : CToolbarWindow(pToolbar, nToolbarStyle, nNoviceHeight, nAdvancedHeight, nHTab)
  106. {
  107. }
  108.  
  109. void CButtonToolbarWindow::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  110. {
  111.  
  112.     ((CNSToolbar2*)GetToolbar())->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  113. }
  114.  
  115. void CButtonToolbarWindow::SetToolbarStyle(int nToolbarStyle)
  116. {
  117.  
  118.     CToolbarWindow::SetToolbarStyle(nToolbarStyle);
  119.     ((CNSToolbar2*)GetToolbar())->SetToolbarStyle(nToolbarStyle);
  120.  
  121. }
  122.  
  123. int CButtonToolbarWindow::GetHeight(void)
  124. {
  125.     return(((CNSToolbar2*)GetToolbar())->GetHeight());
  126. }
  127.  
  128. // Class:  CControlBarToolbarWindow
  129. //
  130. CControlBarToolbarWindow::CControlBarToolbarWindow(CWnd *pToolbar, int nToolbarStyle, int nNoviceHeight, int nAdvancedHeight,
  131.                                            HTAB_BITMAP nHTab) 
  132. : CToolbarWindow(pToolbar, nToolbarStyle, nNoviceHeight, nAdvancedHeight, nHTab)
  133. {
  134. }
  135.  
  136. // cast to CComboToolbar because these functions don't exist in Win16.  Will need a better solution later.
  137. int CControlBarToolbarWindow::GetHeight(void)
  138. {
  139. /*    CRect rect;
  140.     m_pToolbar->GetWindowRect(&rect);*/
  141.     CSize size;
  142.  
  143. #ifdef EDITOR // jevering says this is the right ifdef here
  144. #ifdef XP_WIN32     
  145.     size = ((CComboToolBar*)m_pToolbar)->CalcDynamicLayout( 32500, LM_STRETCH | LM_HORZ);
  146. #else
  147.     size = ((CComboToolBar*)m_pToolbar)->CalcDynamicLayout( 32500, 0);      
  148. #endif
  149. #endif /* EDITOR */
  150.  
  151.     return (size.cy);
  152. }
  153.  
  154. void CControlBarToolbarWindow::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  155. {
  156. #ifdef MOZ_MAIL_NEWS
  157.     ((CComboToolBar*)GetToolbar())->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  158. #endif /* MOZ_MAIL_NEWS */   
  159. }
  160.  
  161.  
  162.  
  163. #define OPEN_BUTTON_WIDTH 9
  164. #define CLOSED_BUTTON_WIDTH 40
  165. #define CLOSED_BUTTON_HEIGHT 10
  166. #define DT_RIGHT_MARGIN 1        //Margin between end of toolbar and right border of Navigator
  167. #define DRAGGING_BORDER_HEIGHT 2
  168. #define NOTOOL -1
  169.  
  170. #define HTAB_TOP_START 0
  171. #define HTAB_TOP_HEIGHT 7
  172. #define HTAB_MIDDLE_START 8
  173. #define HTAB_MIDDLE_HEIGHT 6
  174. #define HTAB_BOTTOM_START 15
  175. #define HTAB_BOTTOM_HEIGHT 3
  176.  
  177. HBITMAP                m_hTabBitmap = NULL;
  178. int                    nTabBitmapRefCount = 0;
  179. //////////////////////////////////////////////////////////////////////////
  180. //                    Class CDragToolbar
  181. //////////////////////////////////////////////////////////////////////////
  182.  
  183. CDragToolbar::CDragToolbar()
  184. {
  185.     m_bIsOpen = TRUE;
  186.     m_bIsShowing = TRUE;
  187.     m_pToolbar = NULL;
  188.     m_bDragging = FALSE;
  189.     m_bMouseDown = FALSE;
  190.     m_bMouseInTab = FALSE;
  191.     m_pAnimation = NULL;
  192.     m_bEraseBackground = TRUE;
  193.     m_nToolID = NOTOOL;
  194.     
  195.  
  196. }
  197.  
  198. CDragToolbar::~CDragToolbar()
  199. {
  200.  
  201.     if(m_pToolbar != NULL)
  202.     {
  203.         delete m_pToolbar;
  204.     }
  205.  
  206.     nTabBitmapRefCount--;
  207.  
  208.     if(nTabBitmapRefCount == 0)
  209.     {
  210.         if(m_hTabBitmap)
  211.             DeleteObject(m_hTabBitmap);
  212.     }
  213. }
  214.  
  215.  
  216. int CDragToolbar::Create(CWnd *pParent, CToolbarWindow *pToolbar)
  217. {
  218.     CRect rect(0, 0, 0, 0);
  219.  
  220.     m_pToolbar = pToolbar;
  221.  
  222.     CBrush brush;
  223.  
  224.     if (!CWnd::Create(theApp.NSToolBarClass, NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, rect,
  225.         pParent, 0))
  226.     {
  227.         return 0;
  228.     }
  229.  
  230.     pToolbar->GetToolbar()->SetOwner(GetParentFrame());
  231.     pToolbar->GetToolbar()->SetParent(this);
  232.  
  233.     m_eHTabType = pToolbar->GetHTab();
  234.  
  235.     HINSTANCE hInst = AfxGetResourceHandle();
  236.     CDC *pDC = GetDC();
  237.  
  238. //    CGenericFrame *pGenFrame = (CGenericFrame*)GetParentFrame();
  239. //    HPALETTE hPalette = ((CDCCX*)pGenFrame->GetMainContext())->GetPalette();
  240.  
  241.     if(nTabBitmapRefCount == 0)
  242.     {
  243.         WFE_InitializeUIPalette(pDC->m_hDC);
  244. //        HPALETTE hPalette = WFE_GetUIPalette();
  245.         m_hTabBitmap = WFE_LoadTransparentBitmap( hInst, pDC->m_hDC, sysInfo.m_clrBtnFace, RGB(255, 0, 255),
  246.                                                   WFE_GetUIPalette(GetParentFrame( )), IDB_VERTICALTAB);
  247.     }
  248.     nTabBitmapRefCount++;
  249.  
  250.     ReleaseDC(pDC);
  251.  
  252.     m_toolTip.Create(this, TTS_ALWAYSTIP);
  253.     CRect tipRect(0, 0, OPEN_BUTTON_WIDTH,GetToolbarHeight());
  254.     m_toolTip.AddTool(this, m_tabTip, &tipRect,  1);
  255.     m_toolTip.Activate(TRUE);
  256.     m_toolTip.SetDelayTime(250);
  257.  
  258.     return 1;
  259. }
  260.  
  261. void CDragToolbar::SetTabTip(CString tabTip)
  262. {
  263.  
  264.     m_tabTip = tabTip;
  265.  
  266.     m_toolTip.UpdateTipText(m_tabTip, this, 1);
  267. }
  268.  
  269. CWnd *CDragToolbar::GetToolbar(void)
  270. {
  271.     return m_pToolbar->GetToolbar();
  272.  
  273. }
  274.  
  275. int  CDragToolbar::GetToolbarHeight(void)
  276. {
  277.     int height = m_pToolbar->GetHeight();
  278.  
  279.     if(m_pAnimation != NULL)
  280.     {
  281.     
  282.         CSize size;
  283.         m_pAnimation->GetSize( size, FALSE );
  284.                 
  285.         int diff = size.cy - height + 2;
  286.         if (diff > 0)
  287.         {
  288.             if (diff > CUTOFF_ON_ANIM_RESIZE)
  289.             {
  290.                 m_pAnimation->SetBitmap( TRUE );
  291.                 m_pAnimation->GetSize( size, TRUE );
  292.                 diff = size.cy - height + 2;
  293.  
  294.                 if (diff < 0)
  295.                     diff = 0;
  296.             }
  297.         }
  298.         else diff = 0;
  299.  
  300.         height += diff;
  301.     }
  302.  
  303.     return height;
  304. }
  305.  
  306. void CDragToolbar::SetToolbarStyle(int nToolbarStyle)
  307. {
  308.     m_pToolbar->SetToolbarStyle(nToolbarStyle);
  309.     // may need to change tool rect
  310.     CRect tipRect(0, 0, OPEN_BUTTON_WIDTH, GetToolbarHeight());
  311.     m_toolTip.SetToolRect(this, 1, &tipRect);
  312.  
  313. }
  314.  
  315. void CDragToolbar::SetAnimation(CAnimationBar2 *pAnimation)
  316. {
  317.     m_pAnimation = pAnimation;
  318.     
  319.     CRect rect;
  320.     GetClientRect(&rect);
  321.  
  322.     int toolbarHeight = m_pToolbar->GetHeight();
  323.     int tempHeight = toolbarHeight;
  324.     
  325.     if(m_pAnimation != NULL)
  326.     {
  327.         m_pAnimation->SetOwner(this);
  328.         m_pAnimation->SetParent(this);
  329.  
  330.         CSize size;
  331.         pAnimation->GetSize( size, FALSE );
  332.                 
  333.         int diff = size.cy - toolbarHeight + 2;
  334.        
  335.         if (diff > 0)
  336.         {
  337.             if (diff > CUTOFF_ON_ANIM_RESIZE)
  338.             {
  339.                 pAnimation->SetBitmap( TRUE ); // Small bitmap
  340.                 
  341.                 pAnimation->GetSize( size, TRUE );
  342.                 
  343.                 diff = size.cy - toolbarHeight + 2;
  344.                 if (diff < 0)  // Resize to accommodate small bitmap if necessary
  345.                     diff = 0; 
  346.             }
  347.             else pAnimation->SetBitmap( FALSE );
  348.             
  349.             if (diff > 0)
  350.             {
  351.                 toolbarHeight += diff;
  352.                 SetWindowPos(NULL, 0, 0, rect.Width(), toolbarHeight, SWP_NOMOVE | SWP_NOZORDER);
  353.                 GetParentFrame()->RecalcLayout();
  354.                 
  355.                 if (m_bDragging)
  356.                 {
  357.                     SetWindowPos(NULL, 0, 0, rect.Width(), toolbarHeight + DRAGGING_BORDER_HEIGHT, SWP_NOMOVE | SWP_NOZORDER);
  358.                 }
  359.                 
  360.             }
  361.         }
  362.         else pAnimation->SetBitmap( FALSE ); // Big bitmap
  363.  
  364.         // The toolbar's width will change.  This could affect its height.
  365.  
  366.         CNSToolbar2* theBar = (CNSToolbar2*)(m_pToolbar->GetNSToolbar());
  367.         if (theBar)
  368.           theBar->WidthChanged(size.cx);
  369.  
  370.         // If the toolbar's height INCREASED, then perhaps the large animation will now fit.
  371.         // Simply perform the check all over again.
  372.         if (m_pToolbar->GetHeight() > tempHeight)
  373.         {
  374.             SetAnimation(pAnimation);
  375.             return;
  376.         }
  377.     }
  378.     
  379.     ArrangeToolbar(rect.Width(), toolbarHeight + (m_bDragging ? DRAGGING_BORDER_HEIGHT : 0));
  380.     RedrawWindow();
  381. }
  382.  
  383. void CDragToolbar::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  384. {
  385.  
  386.     m_pToolbar->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  387. }
  388.  
  389. //////////////////////////////////////////////////////////////////////////
  390. //                    Messages for CDragToolbar
  391. //////////////////////////////////////////////////////////////////////////
  392.  
  393. BEGIN_MESSAGE_MAP(CDragToolbar, CWnd)
  394.     //{{AFX_MSG_MAP(CControlBar)
  395.     ON_WM_SIZE()
  396.     ON_WM_PAINT()
  397.     ON_WM_ERASEBKGND()
  398.     ON_WM_LBUTTONDOWN()
  399.     ON_WM_LBUTTONUP()
  400.     ON_WM_MOUSEMOVE()
  401.     ON_WM_TIMER()
  402.     ON_WM_PALETTECHANGED()
  403.     ON_WM_SYSCOLORCHANGE()
  404.     //}}AFX_MSG_MAP
  405. END_MESSAGE_MAP()
  406.  
  407. void CDragToolbar::OnSize( UINT nType, int cx, int cy )
  408. {
  409.     if(m_pToolbar)
  410.     {
  411.         ArrangeToolbar(cx, cy);
  412.     }
  413. }
  414.  
  415. void CDragToolbar::OnPaint(void)
  416. {
  417.  
  418.     CPaintDC dcPaint(this);    // device context for painting
  419.     CRect rect;
  420.  
  421.     GetClientRect(&rect);
  422.  
  423.     ;
  424.     COLORREF rgbOldBk = ::SetBkColor(dcPaint.m_hDC, sysInfo.m_clrBtnFace);
  425.  
  426.     // Use our background color
  427.     HBRUSH brFace = sysInfo.m_hbrBtnFace;
  428.     ::FillRect(dcPaint.m_hDC, &rect, brFace);
  429.  
  430.     CDC *pDC = &dcPaint;
  431.     HPALETTE hOldPal = ::SelectPalette(pDC->m_hDC, WFE_GetUIPalette(GetParentFrame()), FALSE);
  432.  
  433.     if(m_hTabBitmap != NULL)
  434.     {
  435.  
  436.         // Create a scratch DC and select our bitmap into it.
  437.         CDC * pBmpDC = new CDC;
  438.         pBmpDC->CreateCompatibleDC(pDC);
  439.  
  440.  
  441.         HBITMAP hOldBmp = (HBITMAP)::SelectObject(pBmpDC->m_hDC ,m_hTabBitmap);
  442.         HPALETTE hOldPalette = ::SelectPalette(pBmpDC->m_hDC, WFE_GetUIPalette(NULL), TRUE);
  443.         ::RealizePalette(pBmpDC->m_hDC);
  444.         CPoint bitmapStart(!m_bMouseInTab ? 0 : OPEN_BUTTON_WIDTH ,HTAB_TOP_START);
  445.  
  446.         //First do top of the tab
  447.  
  448.         ::BitBlt(pDC->m_hDC, 0, 0, OPEN_BUTTON_WIDTH, HTAB_TOP_HEIGHT,
  449.                    pBmpDC->m_hDC, bitmapStart.x, bitmapStart.y, SRCCOPY);
  450.     
  451.         //Now do the middle portion of the tab
  452.         int y = HTAB_TOP_HEIGHT;
  453.  
  454.         bitmapStart.y = HTAB_MIDDLE_START;
  455.  
  456.         while(y < rect.bottom - HTAB_BOTTOM_HEIGHT)
  457.         {
  458.             ::BitBlt(pDC->m_hDC, 0, y, OPEN_BUTTON_WIDTH, HTAB_MIDDLE_HEIGHT,
  459.                        pBmpDC->m_hDC, bitmapStart.x, bitmapStart.y, SRCCOPY);
  460.  
  461.             y += HTAB_MIDDLE_HEIGHT;
  462.  
  463.         }
  464.  
  465.         // Now do the bottom of the tab
  466.         y = rect.bottom - HTAB_BOTTOM_HEIGHT;
  467.  
  468.         bitmapStart.y = HTAB_BOTTOM_START;
  469.  
  470.         ::BitBlt(pDC->m_hDC, 0, y, OPEN_BUTTON_WIDTH, HTAB_BOTTOM_HEIGHT,
  471.                    pBmpDC->m_hDC, bitmapStart.x, bitmapStart.y, SRCCOPY);
  472.  
  473.  
  474.         // Cleanup
  475.         ::SelectObject(pBmpDC->m_hDC, hOldBmp);
  476.         ::SelectPalette(pBmpDC->m_hDC, hOldPalette, TRUE);
  477.         ::SelectPalette(pDC->m_hDC, hOldPal, TRUE);
  478.         pBmpDC->DeleteDC();
  479.         delete pBmpDC;
  480.     }
  481.  
  482.     if(m_bDragging)
  483.     {
  484.         CBrush brush(RGB(0, 0, 0));
  485.         CBrush *pOldBrush = (CBrush*)dcPaint.SelectObject(&brush);
  486.  
  487.         //rect.left += OPEN_BUTTON_WIDTH;
  488.  
  489.         dcPaint.FrameRect(&rect, &brush);
  490.  
  491.         dcPaint.SelectObject(pOldBrush);
  492.         brush.DeleteObject();
  493.     }
  494.     ::SetBkColor(dcPaint.m_hDC, rgbOldBk);
  495.  
  496. }
  497.  
  498. void CDragToolbar::OnShowWindow( BOOL bShow, UINT nStatus )
  499. {
  500.     m_bEraseBackground = bShow;
  501. }
  502.  
  503. BOOL CDragToolbar::OnEraseBkgnd( CDC* pDC )
  504. {
  505.     if ( m_bEraseBackground ) {
  506.         m_bEraseBackground = FALSE;
  507.         return (BOOL) Default();
  508.     } else {
  509.         return TRUE;
  510.     }
  511. }
  512.  
  513. void CDragToolbar::OnLButtonDown(UINT nFlags, CPoint point)
  514. {
  515.     MSG msg = *(GetCurrentMessage());
  516.     m_toolTip.RelayEvent(&msg);
  517.  
  518.     m_mouseDownPoint = point;
  519.     m_bMouseDown = TRUE;
  520.     //this doesn't mean we are going to drag, just that if we start moving we are dragging
  521.     CWnd::OnLButtonDown(nFlags, point);
  522.  
  523. }
  524.  
  525. void CDragToolbar::OnLButtonUp(UINT nFlags, CPoint point)
  526. {
  527.  
  528.     MSG msg = *(GetCurrentMessage());
  529.     m_toolTip.RelayEvent(&msg);
  530.  
  531.     if(m_bDragging)
  532.     {
  533.         StopDragging();
  534.     }
  535.     else if(m_bMouseDown && point.x >= 0 && point.x <= OPEN_BUTTON_WIDTH)
  536.     {
  537.         GetParent()->SendMessage(CT_HIDETOOLBAR, 0, (LPARAM)m_hWnd);
  538.     }
  539.     m_bMouseDown = FALSE;
  540.  
  541.     //ReleaseCapture();
  542. }
  543.  
  544. void CDragToolbar::OnMouseMove(UINT nFlags, CPoint point)
  545. {
  546.  
  547.     if(nFlags & MK_LBUTTON)
  548.     {
  549.     //    if(!GetCapture())
  550.     //        SetCapture();
  551.         
  552.         if(m_bDragging || (m_bMouseDown && (abs(m_mouseDownPoint.x - point.x) > 3 || abs(m_mouseDownPoint.y - point.y) > 3)))
  553.         {
  554.             if(!m_bDragging)
  555.             {
  556.                 CRect clientRect;
  557.                 GetClientRect(&clientRect);
  558.                 MapWindowPoints(GetParent(), clientRect);
  559.                 m_bDragging =TRUE;    
  560.                 m_nDragTimer = SetTimer(IDT_DRAGTOOLBAR_DRAGGING, DRAGTOOLBAR_DRAGGING_DELAY, NULL);
  561.                 //Create dragging border
  562.                 MoveWindow(clientRect.left, clientRect.top, clientRect.Width(), clientRect.Height() + DRAGGING_BORDER_HEIGHT);
  563.  
  564.                 RedrawWindow();
  565.             }
  566.  
  567.             CPoint diffPoint;
  568.  
  569.             diffPoint.x =  (point.x - m_mouseDownPoint.x);
  570.             diffPoint.y =  (point.y - m_mouseDownPoint.y);
  571.  
  572.             MapWindowPoints(GetParent(), &diffPoint, 1);
  573.             
  574.             CRect parentRect;
  575.             GetParent()->GetWindowRect(&parentRect);
  576.         
  577.             GetCursorPos(&point);
  578.             
  579.             if(point.x - m_mouseDownPoint.x < parentRect.left)
  580.                 diffPoint.x = 0;
  581.  
  582.             if(point.y - m_mouseDownPoint.y < parentRect.top)
  583.                 diffPoint.y = 0;
  584.         
  585.             if(parentRect.PtInRect(point))
  586.             {
  587.                 GetParent()->SendMessage(CT_DRAGTOOLBAR, (WPARAM) m_hWnd, MAKELPARAM(diffPoint.x, diffPoint.y));
  588.             }
  589.             else
  590.             {
  591.                 //if we aren't in the rect, we will treat this like a mouse up.
  592.                 StopDragging();
  593.             }
  594.         }
  595.     }
  596.     else
  597.     {
  598.         m_toolTip.Activate(TRUE);
  599.         MSG msg = *(GetCurrentMessage());
  600.         m_toolTip.RelayEvent(&msg);
  601.  
  602.     }
  603.  
  604.     CheckIfMouseInTab(point);
  605. }
  606.  
  607. void CDragToolbar::OnTimer( UINT  nIDEvent )
  608. {
  609.  
  610.     CRect rect;
  611.     GetWindowRect(&rect);
  612.     POINT pt;
  613.     GetCursorPos(&pt);
  614.  
  615.     if(nIDEvent == IDT_DRAGTOOLBAR_DRAGGING)
  616.     {
  617.  
  618.         //Give some room on the left border
  619.         rect.left -=5;
  620.         BOOL bMouseInToolbar = PtInRect(&rect, pt);
  621.  
  622.         SHORT sMouseState;
  623.         BOOL bMouseDown;
  624.  
  625.         //check to see if the mouse is up.  If it is, we need to go back in place.
  626.         if(!GetSystemMetrics(SM_SWAPBUTTON))
  627.             sMouseState = GetAsyncKeyState(VK_LBUTTON);
  628.         else
  629.             sMouseState = GetAsyncKeyState(VK_RBUTTON);
  630.  
  631.         bMouseDown = sMouseState & 0x8000;
  632.  
  633.         if((m_bDragging && !bMouseInToolbar) || (m_bDragging && !bMouseDown))
  634.         {
  635.             m_bMouseDown = FALSE;
  636.             StopDragging();
  637.             KillTimer(m_nDragTimer);
  638.         }
  639.     }
  640.     else if(nIDEvent == IDT_TABHAVEFOCUS)
  641.     {
  642.         rect.right = rect.left + OPEN_BUTTON_WIDTH;
  643.         BOOL bMouseInTab = PtInRect(&rect, pt);        
  644.         if(m_bMouseInTab && !bMouseInTab)
  645.         {
  646.             ScreenToClient(&rect);
  647.             KillTimer(m_nTabFocusTimer);
  648.             m_bMouseInTab = FALSE;
  649.             InvalidateRect(&rect, FALSE);
  650.         }
  651.     }
  652.     CWnd::OnTimer(nIDEvent);
  653.  
  654. }
  655.  
  656. void CDragToolbar::OnPaletteChanged( CWnd* pFocusWnd )
  657. {
  658.     Invalidate();
  659.  
  660. }
  661.  
  662. void CDragToolbar::OnSysColorChange( )
  663. {
  664.     if(nTabBitmapRefCount > 0)
  665.     {
  666.         if(m_hTabBitmap)
  667.             DeleteObject(m_hTabBitmap);
  668.         HINSTANCE hInst = AfxGetResourceHandle();
  669.         HDC hDC = ::GetDC(m_hWnd);
  670.         m_hTabBitmap = WFE_LoadTransparentBitmap(hInst, hDC, sysInfo.m_clrBtnFace, 
  671.             RGB(255, 0, 255), WFE_GetUIPalette(GetParentFrame()), IDB_VERTICALTAB);
  672.             
  673.         ::ReleaseDC(m_hWnd, hDC);
  674.         Invalidate();
  675.     }
  676. }
  677.  
  678.  
  679. //////////////////////////////////////////////////////////////////////////
  680. //                    CDragToolbar Helpers
  681. //////////////////////////////////////////////////////////////////////////
  682.  
  683. void CDragToolbar::ArrangeToolbar(int nWidth, int nHeight)
  684. {
  685.     if (nHeight == 0)
  686.         return;
  687.  
  688.     CRect animRect, clientRect;
  689.    
  690.     int toolbarHeight = m_pToolbar->GetHeight();    
  691.  
  692.     if(m_pAnimation != NULL)
  693.     {
  694.          m_pAnimation->GetClientRect(&animRect);
  695.  
  696.         m_pAnimation->SetWindowPos(NULL, nWidth - animRect.Width() - DT_RIGHT_MARGIN, (nHeight - animRect.Height()) / 2, animRect.Width(), animRect.Height(), 
  697.                                      SWP_NOZORDER|SWP_NOSIZE);
  698.         nWidth -=animRect.Width();
  699.     }
  700.  
  701.     m_pToolbar->GetToolbar()->MoveWindow(OPEN_BUTTON_WIDTH, (nHeight - toolbarHeight) / 2, nWidth - OPEN_BUTTON_WIDTH - DT_RIGHT_MARGIN, toolbarHeight);
  702.     
  703.     CNSToolbar2* theBar = (CNSToolbar2*)(m_pToolbar->GetNSToolbar());
  704.     if (theBar)
  705.         theBar->WidthChanged(m_pAnimation? animRect.Width() : 0);
  706. }
  707.  
  708. void CDragToolbar::StopDragging(void)
  709. {
  710.     ReleaseCapture();
  711.     m_bDragging = FALSE;
  712.     CRect clientRect;
  713.     GetClientRect(&clientRect);
  714.     MapWindowPoints(GetParent(), clientRect);
  715.     //Remove dragging border
  716.     MoveWindow(clientRect.left, clientRect.top, clientRect.Width(), clientRect.Height() - DRAGGING_BORDER_HEIGHT);
  717.     RedrawWindow();
  718.     GetParent()->SendMessage(CT_DRAGTOOLBAR_OVER, 0, (LPARAM)m_hWnd);
  719. }
  720.  
  721. void CDragToolbar::CheckIfMouseInTab(CPoint point)
  722. {
  723.     if(!m_bMouseInTab)
  724.     {
  725.         CRect clientRect, clientInWinRect;
  726.         GetClientRect(&clientRect);
  727.         clientRect.right = OPEN_BUTTON_WIDTH;
  728.         clientInWinRect = clientRect;
  729.         ClientToScreen(&clientInWinRect);
  730.         //Make consistent with dragging
  731.         clientInWinRect.left -=5;
  732.         ClientToScreen(&point);
  733.         if(PtInRect(&clientInWinRect, point))
  734.         {
  735.             m_bMouseInTab = TRUE;
  736.             m_nTabFocusTimer = SetTimer(IDT_TABHAVEFOCUS, TABHAVEFOCUS_DELAY, NULL);
  737.             InvalidateRect(clientRect, FALSE);
  738.         }
  739.     }
  740. }
  741.  
  742. //////////////////////////////////////////////////////////////////////////
  743. //                    Class  CCustToolbarExternalTab
  744. //////////////////////////////////////////////////////////////////////////
  745.  
  746. CCustToolbarExternalTab::CCustToolbarExternalTab(CWnd *pOwner, HTAB_BITMAP eHTabType, UINT nTabTip, UINT nTabID)
  747. {
  748.     m_pOwner = pOwner;
  749.     m_eHTabType = eHTabType;
  750.     m_tabTip.LoadString(nTabTip);
  751.     m_nTabID = nTabID;
  752. }
  753.  
  754. CWnd *CCustToolbarExternalTab::GetOwner(void)
  755. {
  756.     return m_pOwner;
  757. }
  758.  
  759. HTAB_BITMAP CCustToolbarExternalTab::GetHTabType(void)
  760. {
  761.     return m_eHTabType;
  762. }
  763.  
  764. CString & CCustToolbarExternalTab::GetTabTip (void)
  765.     return m_tabTip;
  766. }
  767.  
  768. UINT CCustToolbarExternalTab::GetTabID(void)
  769. {
  770.     return m_nTabID;
  771. }
  772.  
  773. //////////////////////////////////////////////////////////////////////////
  774. //                    Class  CCustToolbar
  775. //////////////////////////////////////////////////////////////////////////
  776.  
  777. #define SPACE_BETWEEN_TOOLBARS 2
  778.  
  779. CCustToolbar::CCustToolbar(int nNumToolbars)
  780. {
  781.     m_bEraseBackground = TRUE;
  782.     m_nNumToolbars = nNumToolbars;
  783.     m_pParent = NULL;
  784.     m_nActiveToolbars = 0;
  785.     m_nNumOpen = 0;
  786.     m_nNumShowing = 0;
  787.     m_pToolbarArray = new CDragToolbar*[nNumToolbars];
  788.     m_pHiddenToolbarArray = new CDragToolbar*[nNumToolbars];
  789.     for(int i = 0; i < nNumToolbars; i++)
  790.     {
  791.         m_pToolbarArray[i] = NULL;
  792.         m_pHiddenToolbarArray[i] = NULL;
  793.     }
  794.  
  795.     m_pAnimation = NULL;
  796.     m_nAnimationPos = -1;
  797.     m_oldDragPoint.x = m_oldDragPoint.y = -1;
  798.     m_bSaveToolbarInfo = TRUE;
  799.     m_nTabHaveFocusTimer = 0;
  800.     m_nMouseOverTab = -1;
  801.     m_bBottomBorder = FALSE;
  802. }
  803.  
  804. CCustToolbar::~CCustToolbar()
  805. {
  806.     int i;
  807.  
  808.     for(i = 0; i < m_nNumToolbars; i++)
  809.     {
  810.         if(m_pToolbarArray[i] != NULL)
  811.         {
  812.             delete m_pToolbarArray[i];
  813.         }
  814.  
  815.         if(m_pHiddenToolbarArray[i] != NULL)
  816.         {
  817.             delete m_pHiddenToolbarArray[i];
  818.         }
  819.     }
  820.     delete [] m_pToolbarArray;
  821.     delete [] m_pHiddenToolbarArray;
  822.  
  823.     //delete everything in external tabl array
  824.     int nExtTabSize = m_externalTabArray.GetSize();
  825.     for(i = 0; i < nExtTabSize; i++)
  826.     {
  827.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab*)m_externalTabArray[i];
  828.         delete pExtTab;
  829.     }
  830.  
  831.     m_externalTabArray.RemoveAll();
  832.  
  833.     for(i = 0; i < 4; i++)
  834.     {
  835.         if(m_pHorizTabArray[i] )
  836.         {
  837.             ::DeleteObject(m_pHorizTabArray[i]);
  838.             m_pHorizTabArray[i] = NULL;
  839.         }
  840.     }
  841.  
  842.     if(m_pAnimation)
  843.         delete m_pAnimation;
  844.  
  845.  
  846. }
  847.  
  848.  
  849. int CCustToolbar::Create(CFrameWnd* pParent, BOOL bHasAnimation)
  850. {
  851.     DWORD dwStyle;
  852.     CRect rect;
  853.  
  854.     ASSERT_VALID(pParent);   // must have a parent
  855.  
  856. //    dwStyle &= ~CBRS_ALL;
  857. #ifdef WIN32
  858.     dwStyle = CBRS_ALIGN_TOP|CCS_NOPARENTALIGN|CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE|CBRS_SIZE_DYNAMIC;
  859. #else
  860.     dwStyle = CBRS_TOP; //Align top
  861. #endif
  862.     // create the HWND
  863.     //rect.SetRectEmpty();
  864.     rect.SetRect(0,0, 100, 100);
  865.     CBrush brush;
  866.  
  867.     if (!CWnd::Create(theApp.NSToolBarClass, NULL, dwStyle | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, rect,
  868.         pParent, CUSTTOOLBARID))
  869.     {
  870.         return 0;
  871.     }
  872.     // Note: Parent must resize itself for control bar to be resized
  873.  
  874. #ifdef WIN32
  875.     SetBarStyle(CBRS_ALIGN_TOP );
  876.     pParent->ShowControlBar(this, TRUE, FALSE);
  877. #endif
  878.     m_pParent=pParent;
  879.  
  880. //    CreateToolbars(m_nNumToolbars);
  881.  
  882.     if(bHasAnimation)
  883.     {
  884.         CRect animRect(0, 0, 45, 35);
  885.         m_pAnimation = new CAnimationBar2;
  886.         
  887.         CBrush brush2;
  888.  
  889.         m_pAnimation->Create(AfxRegisterWndClass(0 ,
  890.                 theApp.LoadStandardCursor(IDC_ARROW), 
  891.                 (HBRUSH)(COLOR_BTNFACE + 1)), NULL, WS_CHILD | WS_CLIPSIBLINGS,
  892.                  animRect, this, 0, NULL);
  893.  
  894.         m_pAnimation->ShowWindow(SW_HIDE);
  895.  
  896.     }
  897.  
  898.     m_pHorizTabArray[LARGE_FIRST] = CreateHorizTab(IDB_LARGE_HFTAB);
  899.     m_pHorizTabArray[LARGE_OTHER] = CreateHorizTab(IDB_LARGE_HTAB);
  900.     m_pHorizTabArray[SMALL_FIRST] = CreateHorizTab(IDB_SMALL_HFTAB);
  901.     m_pHorizTabArray[SMALL_OTHER] = CreateHorizTab(IDB_SMALL_HTAB);
  902.  
  903.     m_toolTip.Create(this, TTS_ALWAYSTIP);
  904.     m_toolTip.Activate(TRUE);
  905.     m_toolTip.SetDelayTime(250);
  906.  
  907.     return 1;
  908. }
  909.  
  910. void CCustToolbar::AddNewWindow(UINT nToolbarID, CToolbarWindow* pWindow, int nPosition, int nNoviceHeight, int nAdvancedHeight,
  911.                                 UINT nTabBitmapIndex, CString tabTip, BOOL bIsNoviceMode, BOOL bIsOpen, BOOL bIsAnimation)
  912. {
  913.  
  914.     if(m_pToolbarArray[nPosition] != NULL || nPosition < 0 || nPosition >= m_nNumToolbars)
  915.         nPosition = FindFirstAvailablePosition();
  916.  
  917.     CDragToolbar *pDragToolbar = new CDragToolbar;
  918.  
  919.     if(pDragToolbar->Create(this, pWindow))
  920.     {
  921.         m_nNumShowing++;
  922.         m_pToolbarArray[nPosition] = pDragToolbar;
  923.         pWindow->GetToolbar()->ShowWindow(SW_SHOW);
  924.         pDragToolbar->SetOpen(bIsOpen);
  925.         pDragToolbar->SetTabTip(tabTip);
  926.         pDragToolbar->SetToolbarID(nToolbarID);
  927.  
  928.         if(bIsOpen)
  929.         {
  930.             pDragToolbar->ShowWindow(SW_SHOW);
  931.             m_nNumOpen++;
  932.             if(nPosition < m_nAnimationPos || m_nAnimationPos == -1)
  933.             {
  934.                 if(m_nAnimationPos != -1)
  935.                 {
  936.                     m_pToolbarArray[m_nAnimationPos]->SetAnimation(NULL);
  937.                 }
  938.                 m_pToolbarArray[nPosition]->SetAnimation(m_pAnimation);
  939.                 if(m_pAnimation)
  940.                     m_pAnimation->ShowWindow(SW_SHOW);
  941.                 m_nAnimationPos = nPosition;
  942.                 
  943.             }
  944.         }
  945.  
  946.         m_nActiveToolbars++;
  947.  
  948.  
  949.         m_pParent->RecalcLayout();
  950.     }
  951.  
  952. }
  953.  
  954. void CCustToolbar::StopAnimation(void)
  955. {
  956.     if(m_pAnimation)
  957.         m_pAnimation->StopAnimation();
  958.  
  959. }
  960.  
  961. void CCustToolbar::StartAnimation()
  962. {
  963.     if(m_pAnimation)
  964.         m_pAnimation->StartAnimation();
  965. }
  966.  
  967. //This is if the window is showing, not if it is iconified
  968. BOOL CCustToolbar::IsWindowShowing(CWnd *pToolbar)
  969. {
  970.     int nIndex = FindDragToolbarFromWindow(pToolbar, m_pToolbarArray);
  971.     return (nIndex != -1);
  972. }
  973.  
  974. BOOL CCustToolbar::IsWindowShowing(UINT nToolbarID)
  975. {
  976.     int nIndex = FindDragToolbarFromID(nToolbarID, m_pToolbarArray);
  977.     return (nIndex != -1);
  978. }
  979.  
  980. BOOL CCustToolbar::IsWindowIconized(CWnd *pToolbar)
  981. {
  982.     int nIndex;
  983.  
  984.     nIndex = FindDragToolbarFromWindow(pToolbar, m_pToolbarArray);
  985.     if(nIndex == -1)
  986.     {
  987.         nIndex = FindDragToolbarFromWindow(pToolbar, m_pHiddenToolbarArray);
  988.         if(nIndex != -1)
  989.             return !m_pHiddenToolbarArray[nIndex]->GetOpen();
  990.     }
  991.     else
  992.         return !m_pToolbarArray[nIndex]->GetOpen();
  993.  
  994.     return TRUE;
  995.     
  996. }
  997.  
  998. int     CCustToolbar::GetWindowPosition(CWnd *pToolbar)
  999. {
  1000.     int nIndex;
  1001.  
  1002.     nIndex = FindDragToolbarFromWindow(pToolbar, m_pToolbarArray);
  1003.     if(nIndex == -1)
  1004.         nIndex = FindDragToolbarFromWindow(pToolbar, m_pHiddenToolbarArray);
  1005.     return nIndex;
  1006. }
  1007.  
  1008. void CCustToolbar::ShowDragToolbar(int nIndex, BOOL bShow)
  1009. {
  1010.     if(bShow)
  1011.     {
  1012.         if(nIndex != -1)
  1013.         {
  1014.             if(m_pHiddenToolbarArray[nIndex]->GetOpen())
  1015.                 m_nNumOpen++;
  1016.             m_nNumShowing++;
  1017.             m_nActiveToolbars++;
  1018.             m_pToolbarArray[nIndex] = m_pHiddenToolbarArray[nIndex];
  1019.             m_pHiddenToolbarArray[nIndex] = NULL;
  1020.             m_pToolbarArray[nIndex]->GetToolbar()->ShowWindow(SW_SHOW);
  1021.             if(m_pToolbarArray[nIndex]->GetOpen()){
  1022.                 CheckAnimationChangedToolbar(m_pToolbarArray[nIndex], nIndex, TRUE);
  1023.                 m_pToolbarArray[nIndex]->ShowWindow(SW_SHOW);
  1024.             }
  1025.         }
  1026.  
  1027.  
  1028.     }
  1029.     else
  1030.     {
  1031.         if(nIndex != -1)
  1032.         {
  1033.             if(m_pToolbarArray[nIndex]->GetOpen())
  1034.                 m_nNumOpen--;
  1035.             m_nNumShowing--;
  1036.             m_nActiveToolbars--;
  1037.             m_pHiddenToolbarArray[nIndex] = m_pToolbarArray[nIndex];
  1038.             m_pToolbarArray[nIndex] = NULL;
  1039.             m_pHiddenToolbarArray[nIndex]->ShowWindow(SW_HIDE);
  1040.             m_pHiddenToolbarArray[nIndex]->GetToolbar()->ShowWindow(SW_HIDE);
  1041.             CheckAnimationChangedToolbar(m_pHiddenToolbarArray[nIndex], nIndex, FALSE);
  1042.  
  1043.         }
  1044.     }
  1045.     m_pParent->RecalcLayout();
  1046.     RedrawWindow();
  1047. }
  1048.  
  1049. void CCustToolbar::ShowToolbar(CWnd *pToolbar, BOOL bShow)
  1050. {
  1051.     int nIndex = FindDragToolbarFromWindow(pToolbar, bShow ? m_pHiddenToolbarArray : m_pToolbarArray);
  1052.  
  1053.     if(nIndex != -1)
  1054.         ShowDragToolbar(nIndex, bShow);
  1055.  
  1056. }
  1057.  
  1058. void CCustToolbar::ShowToolbar(UINT nToolbarID, BOOL bShow)
  1059. {
  1060.     int nIndex = FindDragToolbarFromID(nToolbarID, bShow ? m_pHiddenToolbarArray : m_pToolbarArray);
  1061.  
  1062.     if(nIndex != -1)
  1063.         ShowDragToolbar(nIndex, bShow);
  1064. }
  1065.  
  1066. void CCustToolbar::RenameToolbar(UINT nOldID, UINT nNewID, UINT nNewToolTipID)
  1067. {
  1068.     int nIndex = FindDragToolbarFromID(nOldID, m_pToolbarArray);
  1069.     CDragToolbar *pToolbar = NULL;
  1070.  
  1071.     if(nIndex != -1)
  1072.         pToolbar = m_pToolbarArray[nIndex];
  1073.     else
  1074.     {
  1075.         nIndex = FindDragToolbarFromID(nOldID, m_pHiddenToolbarArray);
  1076.         if(nIndex != -1)
  1077.             pToolbar = m_pHiddenToolbarArray[nIndex];
  1078.     }
  1079.  
  1080.     if(pToolbar != NULL)
  1081.     {
  1082.         pToolbar->SetToolbarID(nNewID);
  1083.         CString tipStr;
  1084.         tipStr.LoadString(nNewToolTipID);
  1085.         pToolbar->SetTabTip(tipStr);
  1086.  
  1087.     }
  1088. }
  1089.  
  1090.  
  1091. CWnd *CCustToolbar::GetToolbar(UINT nToolbarID)
  1092. {
  1093.     int nIndex;
  1094.  
  1095.     nIndex = FindDragToolbarFromID(nToolbarID, m_pHiddenToolbarArray);
  1096.     
  1097.     if(nIndex == -1)
  1098.     {
  1099.         nIndex = FindDragToolbarFromID(nToolbarID, m_pToolbarArray);
  1100.  
  1101.         if(nIndex != -1)
  1102.             return m_pToolbarArray[nIndex]->GetToolbar();
  1103.     }
  1104.     else
  1105.         return m_pHiddenToolbarArray[nIndex]->GetToolbar();
  1106.  
  1107.     return NULL;
  1108.     
  1109. }
  1110.    
  1111. // Function    - CalcDynamicLayout
  1112. //
  1113. // Tells the framework how big this controlbar needs to be.  The height is based on the
  1114. // heights of the toolbars.  The width is set to 32767 which sets the width to the width
  1115. // of our parent
  1116. //
  1117. // Arguments - both are disregarded
  1118. //
  1119. // Returns - the dimensions we need to draw ourself
  1120. CSize CCustToolbar::CalcDynamicLayout(int nLength, DWORD dwMode )
  1121. {
  1122.  
  1123.     int height=0;
  1124.  
  1125.     for(int i = 0; i < m_nNumToolbars; i++)
  1126.     {
  1127.         if(m_pToolbarArray[i] != NULL)
  1128.         {
  1129.              if(m_pToolbarArray[i]->GetOpen())
  1130.              {
  1131.                  height += m_pToolbarArray[i]->GetToolbarHeight() + SPACE_BETWEEN_TOOLBARS; 
  1132.              }
  1133.         }
  1134.     }
  1135.  
  1136. //    height += (m_nNumOpen ) * SPACE_BETWEEN_TOOLBARS;
  1137.  
  1138.     if(m_nNumOpen != m_nActiveToolbars && m_nNumShowing != 0 || m_externalTabArray.GetSize() > 0)
  1139.         height += CLOSED_BUTTON_HEIGHT + SPACE_BETWEEN_TOOLBARS;
  1140.  
  1141.     //because all closed tabs may have changed position, read the tools
  1142.     if(height >= CLOSED_BUTTON_HEIGHT)
  1143.         ChangeToolTips(height);
  1144.  
  1145.     if(m_bBottomBorder)
  1146.         // if we have a bottom border then add space for separator
  1147.         height += SPACE_BETWEEN_TOOLBARS;
  1148.  
  1149.     return CSize(32767, height);
  1150.  
  1151. }
  1152.  
  1153. void CCustToolbar::SetToolbarStyle(int nToolbarStyle)
  1154. {
  1155.  
  1156.     for(int i = 0; i < m_nNumToolbars; i++)
  1157.     {
  1158.         if(m_pToolbarArray[i] != NULL)
  1159.         {
  1160.             m_pToolbarArray[i]->SetToolbarStyle( nToolbarStyle );
  1161.         }
  1162.     }
  1163.     
  1164.     if( m_nAnimationPos != -1 )
  1165.     {
  1166.         // Reset the animation (height change)
  1167.         m_pToolbarArray[m_nAnimationPos]->SetAnimation( m_pAnimation );
  1168.     }
  1169.     
  1170.     m_pParent->RecalcLayout();
  1171.     RedrawWindow();
  1172.  
  1173.  
  1174. }
  1175.  
  1176. void CCustToolbar::OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler )
  1177. {
  1178.     for(int i = 0; i < m_nNumToolbars; i++)
  1179.     {
  1180.         if(m_pToolbarArray[i] != NULL)
  1181.         {
  1182.             m_pToolbarArray[i]->OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  1183.         }
  1184.     }
  1185. }
  1186.  
  1187. void CCustToolbar::Customize(CLinkToolbar *pLinkToolbar, int nSelectedButton)
  1188. {
  1189. }
  1190.  
  1191. BOOL CCustToolbar::GetSaveToolbarInfo(void)
  1192. {
  1193.     return m_bSaveToolbarInfo;
  1194. }
  1195.  
  1196. void CCustToolbar::SetSaveToolbarInfo(BOOL bSaveToolbarInfo)
  1197. {
  1198.  
  1199.     m_bSaveToolbarInfo = bSaveToolbarInfo;
  1200. }
  1201.  
  1202. void CCustToolbar::SetNewParentFrame(CFrameWnd *pParent)
  1203. {
  1204.     if(m_pParent == pParent)
  1205.         return;
  1206.  
  1207. #ifdef XP_WIN32
  1208.     if(m_pParent)
  1209.         m_pParent->RemoveControlBar(this);
  1210. #endif
  1211.  
  1212.     SetParent(pParent);
  1213.  
  1214. #ifdef XP_WIN32
  1215.     if(pParent)
  1216.         pParent->AddControlBar(this);
  1217. #endif
  1218.  
  1219.     m_pParent = pParent;
  1220.  
  1221. }
  1222.  
  1223. void CCustToolbar::AddExternalTab(CWnd *pOwner, HTAB_BITMAP eHTabType, UINT nTipID, UINT nTabID)
  1224. {
  1225.     CCustToolbarExternalTab *pExtTab = new CCustToolbarExternalTab(pOwner, eHTabType, nTipID, nTabID);
  1226.  
  1227.     m_externalTabArray.Add(pExtTab);
  1228.  
  1229.     RedrawWindow();
  1230. }
  1231.  
  1232. void CCustToolbar::RemoveExternalTab(UINT nTabID)
  1233. {
  1234.  
  1235.     int nSize = m_externalTabArray.GetSize();
  1236.  
  1237.     for(int i = 0; i < nSize; i++)
  1238.     {
  1239.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab *)m_externalTabArray[i];
  1240.  
  1241.         if(pExtTab->GetTabID() == nTabID){
  1242.             m_externalTabArray.RemoveAt(i);
  1243.             delete pExtTab;
  1244.             RedrawWindow();
  1245.             return;
  1246.         }
  1247.     }
  1248.  
  1249. }
  1250.  
  1251. void CCustToolbar::SetBottomBorder(BOOL bBottomBorder)
  1252. {
  1253.     m_bBottomBorder = bBottomBorder;
  1254.  
  1255. }
  1256.  
  1257.  
  1258. //////////////////////////////////////////////////////////////////////////
  1259. //                    Messages for CCustToolbar
  1260. //////////////////////////////////////////////////////////////////////////
  1261.  
  1262. BEGIN_MESSAGE_MAP(CCustToolbar, CControlBar)
  1263.     //{{AFX_MSG_MAP(CControlBar)
  1264.     ON_WM_SIZE()
  1265.     ON_WM_PAINT()
  1266.     ON_WM_ERASEBKGND()
  1267.     ON_WM_LBUTTONUP()
  1268.     ON_WM_LBUTTONDOWN()
  1269.     ON_WM_MOUSEMOVE()
  1270.     ON_MESSAGE(CT_HIDETOOLBAR, OnHideToolbar)
  1271.     ON_MESSAGE(CT_DRAGTOOLBAR, OnDragToolbar)
  1272.     ON_MESSAGE(CT_DRAGTOOLBAR_OVER, OnDragToolbarOver)
  1273.     ON_MESSAGE(CT_CUSTOMIZE, OnCustomize)
  1274. #ifndef WIN32
  1275.     ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  1276. #endif
  1277.     ON_WM_TIMER()
  1278.     ON_WM_PALETTECHANGED()
  1279.     //}}AFX_MSG_MAP
  1280. END_MESSAGE_MAP()
  1281.  
  1282. void CCustToolbar::OnSize( UINT nType, int cx, int cy )
  1283. {
  1284.     CDragToolbar *pToolbar;
  1285.     int nToolbarHeight;
  1286.  
  1287.     int yStart=(m_nNumOpen == 0) ? 0 : SPACE_BETWEEN_TOOLBARS;
  1288.  
  1289.     BOOL bWindowsShown = FALSE;
  1290.  
  1291.     int nWidth;
  1292.  
  1293.     for(int i=0; i<m_nNumToolbars; i++)
  1294.     {
  1295.         nWidth = cx;
  1296.  
  1297.         if(m_pToolbarArray[i] != NULL)
  1298.         {
  1299.             pToolbar = m_pToolbarArray[i];
  1300.             nToolbarHeight = pToolbar->GetToolbarHeight();
  1301.             
  1302.             if(pToolbar->GetOpen())
  1303.             {
  1304.  
  1305.                 pToolbar->MoveWindow(0, yStart, nWidth, nToolbarHeight);
  1306.  
  1307.                 yStart += nToolbarHeight + SPACE_BETWEEN_TOOLBARS;
  1308.             }
  1309.         }
  1310.     }
  1311. }
  1312.  
  1313. void CCustToolbar::OnPaint()
  1314. {
  1315.     CRect rcClient, updateRect, toolbarRect, intersectRect;
  1316.  
  1317.     GetClientRect(&rcClient);
  1318.     GetUpdateRect(&updateRect);
  1319.  
  1320.     CPaintDC dcPaint(this);    // device context for painting
  1321.  
  1322.     HDC hSrcDC = dcPaint.m_hDC;
  1323.  
  1324.     HPALETTE hPalette = WFE_GetUIPalette(GetParentFrame());
  1325.  
  1326.     HPALETTE hOldPalette;
  1327.     HDC hMemDC = ::CreateCompatibleDC(hSrcDC);
  1328.     HBITMAP hbmMem = CreateCompatibleBitmap(hSrcDC,
  1329.                                     rcClient.Width(),
  1330.                                     rcClient.Height());
  1331.  
  1332.     COLORREF rgbOldBk = ::SetBkColor(hMemDC, sysInfo.m_clrBtnFace);
  1333.  
  1334.     //
  1335.     // Select the bitmap into the off-screen DC.
  1336.     //
  1337.  
  1338.     HBITMAP hbmOld;
  1339.     hbmOld = (HBITMAP)::SelectObject(hMemDC, hbmMem);
  1340.  
  1341.     // Use our background color
  1342.         // Use the button face color as our background
  1343.     HBRUSH brFace = ::CreateSolidBrush(RGB(128, 128, 128));
  1344.  
  1345.     int nExternalTabArrSize = m_externalTabArray.GetSize();
  1346.  
  1347.     CRect clientCopy = rcClient;
  1348.  
  1349.     if(m_nNumOpen != m_nActiveToolbars || nExternalTabArrSize > 0)
  1350.     {
  1351.         clientCopy.bottom -= CLOSED_BUTTON_HEIGHT;
  1352.     }
  1353.     ::FillRect(hMemDC, clientCopy, brFace);
  1354.     ::DeleteObject(brFace);
  1355.  
  1356.     if(m_nNumOpen != m_nActiveToolbars || nExternalTabArrSize > 0)
  1357.     {
  1358.         clientCopy.top = clientCopy.bottom;
  1359.         clientCopy.bottom += CLOSED_BUTTON_HEIGHT;
  1360.         ::FillRect(hMemDC, clientCopy, sysInfo.m_hbrBtnFace);
  1361.     }
  1362.  
  1363.     int nClosedStartX = 0;
  1364.     int nStartY = 0;
  1365.  
  1366.     if(m_nNumOpen != 0)
  1367.     {
  1368.         DrawSeparator(hMemDC, rcClient.left, rcClient.right, nStartY, TRUE);
  1369.     }
  1370.     else
  1371.     {
  1372.         DrawSeparator(hMemDC, rcClient.left, rcClient.right, nStartY, FALSE);
  1373.     }
  1374.     nStartY += SPACE_BETWEEN_TOOLBARS;
  1375.  
  1376.     //These are the number of each button we've seen so far as compared to m_nNumOpen which is
  1377.     //the total number of toolbars we know are showing
  1378.     int nNumClosedButtons = 0;
  1379.     int nNumOpenButtons = 0;
  1380.  
  1381.     int nBottom = m_bBottomBorder ? rcClient.bottom - SPACE_BETWEEN_TOOLBARS : rcClient.bottom;
  1382.  
  1383.     for(int i = 0; i < m_nNumToolbars; i++)
  1384.     {
  1385.         if(m_pToolbarArray[i] != NULL) 
  1386.         {
  1387.             if(m_pToolbarArray[i]->GetOpen())
  1388.             {
  1389.                 int nToolbarHeight = m_pToolbarArray[i]->GetToolbarHeight();
  1390.  
  1391.                 nStartY += nToolbarHeight;
  1392.                 nNumOpenButtons++;
  1393.  
  1394.                 if(nNumOpenButtons != m_nNumOpen)
  1395.                 {
  1396.                     DrawSeparator(hMemDC, rcClient.left, rcClient.right, nStartY, TRUE);
  1397.                 }
  1398.                 else
  1399.                 {
  1400.                     DrawSeparator(hMemDC, rcClient.left, rcClient.right, nStartY, FALSE);
  1401.                 }
  1402.  
  1403.                 nStartY +=SPACE_BETWEEN_TOOLBARS;
  1404.             }
  1405.             else
  1406.             {
  1407.                 HTAB_BITMAP tabType = m_pToolbarArray[i]->GetHTabType();
  1408.  
  1409.                 DrawClosedTab(hSrcDC, hMemDC, tabType, nNumClosedButtons, i == m_nMouseOverTab,
  1410.                               nClosedStartX, nBottom);
  1411.  
  1412.  
  1413.                 nClosedStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nClosedStartX);
  1414.                 nNumClosedButtons++;
  1415.                 
  1416.             }
  1417.         }
  1418.     }
  1419.  
  1420.  
  1421.     for(int j = 0; j < nExternalTabArrSize; j++)
  1422.     {
  1423.         HTAB_BITMAP tabType;
  1424.  
  1425.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab *)m_externalTabArray[j];
  1426.  
  1427.         tabType = pExtTab->GetHTabType();
  1428.  
  1429.         DrawClosedTab(hSrcDC, hMemDC, tabType, nNumClosedButtons, j + m_nNumToolbars == m_nMouseOverTab,
  1430.                       nClosedStartX, nBottom);
  1431.  
  1432.         nClosedStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nClosedStartX);
  1433.         nNumClosedButtons++;
  1434.     }
  1435.  
  1436.     if(m_bBottomBorder)
  1437.         DrawSeparator(hMemDC, rcClient.left, rcClient.right, rcClient.bottom - 2, TRUE);
  1438.     
  1439.     ::BitBlt(hSrcDC, 0, 0, rcClient.Width(), rcClient.Height(), hMemDC, 0, 0,
  1440.                     SRCCOPY);
  1441.  
  1442.      ::SetBkColor(hMemDC, rgbOldBk);
  1443.  
  1444.     ::SelectObject(hMemDC, hbmOld);
  1445.     ::DeleteObject(hbmMem);
  1446.  
  1447.     ::DeleteDC(hMemDC);
  1448. }
  1449.  
  1450. void CCustToolbar::OnShowWindow( BOOL bShow, UINT nStatus )
  1451. {
  1452.     m_bEraseBackground = bShow;
  1453. }
  1454.  
  1455. BOOL CCustToolbar::OnEraseBkgnd( CDC* pDC )
  1456. {
  1457.     if ( m_bEraseBackground ) {
  1458.         m_bEraseBackground = FALSE;
  1459.         return (BOOL) Default();
  1460.     } else {
  1461.         return TRUE;
  1462.     }
  1463. }
  1464.  
  1465. void CCustToolbar::OnLButtonUp(UINT nFlags, CPoint point)
  1466. {
  1467.     
  1468.     int nResult;
  1469.  
  1470.     MSG msg = *(GetCurrentMessage());
  1471.     m_toolTip.RelayEvent(&msg);
  1472.  
  1473.     if((nResult = CheckClosedButtons(point)) != -1)
  1474.     {
  1475.         if(nResult < m_nNumToolbars)
  1476.             OpenDragToolbar(nResult);
  1477.         // then we must have clicked on one of the external tabs
  1478.         else
  1479.             OpenExternalTab(nResult - m_nNumToolbars);
  1480.  
  1481.     }
  1482. }
  1483.  
  1484. void CCustToolbar::OnLButtonDown(UINT nFlags, CPoint point)
  1485. {
  1486.  
  1487.     MSG msg = *(GetCurrentMessage());
  1488.     m_toolTip.RelayEvent(&msg);
  1489.  
  1490.     CWnd::OnLButtonDown(nFlags, point);
  1491. }
  1492.  
  1493. void CCustToolbar::OnMouseMove(UINT nFlags, CPoint point)
  1494. {
  1495.     m_toolTip.Activate(TRUE);
  1496.     MSG msg = *(GetCurrentMessage());
  1497.     m_toolTip.RelayEvent(&msg);
  1498.  
  1499.     CRect clientRect;
  1500.  
  1501.     GetClientRect(&clientRect);
  1502.     if(m_nNumOpen != m_nNumToolbars)
  1503.     {
  1504.         clientRect.top = clientRect.bottom - CLOSED_BUTTON_HEIGHT;
  1505.         if(PtInRect(&clientRect, point))
  1506.         {
  1507.             int nMouseOverTab = CheckClosedButtons(point);
  1508.  
  1509.             if(m_nMouseOverTab != nMouseOverTab)
  1510.             {
  1511.                 m_nMouseOverTab= nMouseOverTab;
  1512.                 if(m_nTabHaveFocusTimer == 0)
  1513.                     m_nTabHaveFocusTimer = SetTimer(IDT_TABHAVEFOCUS, TABHAVEFOCUS_DELAY, NULL);
  1514.                 InvalidateRect(clientRect);
  1515.             }
  1516.         }
  1517.     }
  1518.     CWnd::OnMouseMove(nFlags, point);
  1519. }
  1520.  
  1521. LRESULT CCustToolbar::OnHideToolbar(WPARAM wParam, LPARAM lParam)
  1522. {
  1523.  
  1524.     HWND hwnd = (HWND)lParam;
  1525.     CDragToolbar *pToolbar = (CDragToolbar*)CWnd::FromHandlePermanent(hwnd);
  1526.  
  1527.     pToolbar->SetOpen(FALSE);
  1528.     pToolbar->ShowWindow(SW_HIDE);
  1529.     m_nNumOpen--;
  1530.  
  1531.     int nIndex = FindIndex(pToolbar);
  1532.     CheckAnimationChangedToolbar(pToolbar, nIndex, FALSE);
  1533.  
  1534.     m_pParent->RecalcLayout();
  1535.     RedrawWindow();
  1536.  
  1537.     return 1;
  1538. }
  1539.  
  1540. LRESULT CCustToolbar::OnDragToolbar(WPARAM wParam, LPARAM lParam)
  1541. {
  1542.  
  1543.     HWND hwnd = (HWND)wParam;
  1544.     CPoint point;
  1545.  
  1546.     point.x = LOWORD(lParam);
  1547.     point.y = HIWORD(lParam);
  1548.  
  1549.  
  1550.     CDragToolbar *pToolbar = (CDragToolbar*)CWnd::FromHandlePermanent(hwnd);
  1551.  
  1552.     CRect rect;
  1553.     pToolbar->GetWindowRect(&rect);
  1554.  
  1555.     //if the point is not in our rect, we don't want to move the window
  1556.     CRect clientRect;
  1557.     GetClientRect(&clientRect);
  1558.     if(m_nNumOpen != m_nActiveToolbars)
  1559.     {
  1560.         clientRect.bottom -=  CLOSED_BUTTON_HEIGHT;
  1561.     }
  1562.     //take into account the height plus the 2 pixels we added on earlier
  1563.     clientRect.bottom -= rect.Height() - DRAGGING_BORDER_HEIGHT;
  1564.  
  1565.     if(!clientRect.PtInRect(point))
  1566.         return 1;
  1567.  
  1568.     pToolbar->SetWindowPos(NULL, 0, point.y, rect.Width(), rect.Height(), SWP_NOSIZE );
  1569.     ScreenToClient(&rect);
  1570.  
  1571.     if(m_oldDragPoint.x != -1 && m_oldDragPoint.y != -1)
  1572.     {
  1573.         int nDir;
  1574.  
  1575.         nDir = m_oldDragPoint.y - point.y;
  1576.  
  1577.         //dragging down
  1578.         if(nDir < 0)
  1579.         {
  1580.             CWnd *pChild = FindToolbarFromPoint(CPoint(0, point.y + rect.Height() - 5), pToolbar);
  1581.             if(pChild != NULL && pChild != pToolbar && pChild != this)
  1582.             {
  1583.                 SwitchChildren((CDragToolbar*)pToolbar, (CDragToolbar*)pChild, -1, point.y);
  1584.  
  1585.             }
  1586.         }//dragging up
  1587.         else if(nDir > 0)
  1588.         {
  1589.             CWnd *pChild = FindToolbarFromPoint(CPoint(0, point.y + 5), pToolbar);
  1590.             if(pChild != NULL && pChild != pToolbar && pChild != this)
  1591.             {
  1592.                 SwitchChildren((CDragToolbar*)pToolbar, (CDragToolbar*)pChild, 1, point.y);
  1593.  
  1594.             }
  1595.         }
  1596.  
  1597.     }
  1598.  
  1599.     m_oldDragPoint = point;
  1600.  
  1601.     return 1;
  1602. }
  1603.  
  1604. LRESULT CCustToolbar::OnDragToolbarOver(WPARAM wParam, LPARAM lParam)
  1605. {
  1606.  
  1607.     HWND hwnd = (HWND)lParam;
  1608.     CDragToolbar *pToolbar = (CDragToolbar*)CWnd::FromHandlePermanent(hwnd);
  1609.  
  1610.     int nIndex = FindIndex(pToolbar);
  1611.  
  1612.     if(nIndex != -1)
  1613.     {
  1614.         int nYStart = (m_nNumOpen == 0) ? 0 : SPACE_BETWEEN_TOOLBARS;
  1615.         for(int i = 0; i < nIndex; i++)
  1616.         {
  1617.             if(m_pToolbarArray[i] != NULL && m_pToolbarArray[i]->GetOpen())
  1618.             {
  1619.                 nYStart += m_pToolbarArray[i]->GetToolbarHeight() + SPACE_BETWEEN_TOOLBARS;
  1620.             }
  1621.  
  1622.         }
  1623.         pToolbar->SetWindowPos(NULL, 0, nYStart, 0, 0, SWP_NOSIZE); 
  1624.  
  1625.     }
  1626.  
  1627.     GetParentFrame()->RecalcLayout();
  1628.  
  1629.     return 1;
  1630. }
  1631.  
  1632. LRESULT CCustToolbar::OnCustomize(WPARAM wParam, LPARAM lParam)
  1633. {
  1634.  
  1635.     CLinkToolbar *pToolbar = (CLinkToolbar *)CWnd::FromHandlePermanent((HWND)lParam);
  1636.     int nButton = LOWORD(wParam);
  1637.  
  1638.     Customize(pToolbar, wParam);
  1639.     return 1;
  1640. }
  1641.  
  1642. void CCustToolbar::OnTimer( UINT  nIDEvent )
  1643. {
  1644.  
  1645.     CRect rect;
  1646.     GetWindowRect(&rect);
  1647.     POINT pt;
  1648.     GetCursorPos(&pt);
  1649.  
  1650.  
  1651.  
  1652.     if(nIDEvent == IDT_TABHAVEFOCUS)
  1653.     {
  1654.         rect.top = rect.bottom - CLOSED_BUTTON_HEIGHT;
  1655.         BOOL bMouseInTabs = PtInRect(&rect, pt);        
  1656.         if(!bMouseInTabs)
  1657.         {
  1658.             ScreenToClient(&rect);
  1659.             KillTimer(m_nTabHaveFocusTimer);
  1660.             m_nTabHaveFocusTimer = 0;
  1661.             m_nMouseOverTab = -1;
  1662.             InvalidateRect(&rect, FALSE);
  1663.         }
  1664.     }
  1665.     CWnd::OnTimer(nIDEvent);
  1666.  
  1667. }
  1668. #ifndef WIN32
  1669. LRESULT CCustToolbar::OnSizeParent(WPARAM wParam, LPARAM lParam)
  1670. {
  1671.     m_sizeFixedLayout = CalcDynamicLayout(0, 0);
  1672.     return CControlBar::OnSizeParent(wParam, lParam);
  1673. }
  1674. #endif
  1675.  
  1676.  
  1677. void CCustToolbar::OnPaletteChanged( CWnd* pFocusWnd )
  1678. {
  1679.         Invalidate();
  1680. }
  1681.  
  1682. //////////////////////////////////////////////////////////////////////////
  1683. //                    CCustToolbar Helper Functions
  1684. //////////////////////////////////////////////////////////////////////////
  1685.  
  1686. int CCustToolbar::CheckOpenButtons(CPoint point)
  1687. {
  1688.  
  1689.     if(point.x < 0 || point.x > OPEN_BUTTON_WIDTH)
  1690.     {
  1691.         return -1;
  1692.     }
  1693.  
  1694.     int nStartY = 0;
  1695.     int nToolbarHeight;
  1696.  
  1697.     for(int i = 0; i < m_nNumToolbars; i++)
  1698.     {
  1699.         if(m_pToolbarArray[i] != NULL && m_pToolbarArray[i]->GetOpen())
  1700.         {
  1701.             nToolbarHeight = m_pToolbarArray[i]->GetToolbarHeight();
  1702.  
  1703.             if(point.y >= nStartY && point.y <= nStartY + nToolbarHeight)
  1704.             {
  1705.                 return i;
  1706.             }
  1707.  
  1708.             nStartY += nToolbarHeight + SPACE_BETWEEN_TOOLBARS;
  1709.         }
  1710.     }
  1711.  
  1712.     return -1;
  1713.  
  1714. }
  1715.  
  1716. int CCustToolbar::CheckClosedButtons(CPoint point)
  1717. {
  1718.  
  1719.     CRect rcClient;
  1720.  
  1721.     GetClientRect(&rcClient);
  1722.  
  1723.     int nStartX = 0;
  1724.     int nNumClosedButtons = 0;
  1725.  
  1726.     for(int i = 0; i < m_nNumToolbars; i++)
  1727.     {
  1728.         if(m_pToolbarArray[i] != NULL && !m_pToolbarArray[i]->GetOpen())
  1729.         {
  1730.             HTAB_BITMAP tabType = m_pToolbarArray[i]->GetHTabType();
  1731.             if(PointInClosedTab(point, tabType, nNumClosedButtons, nStartX, rcClient.bottom))
  1732.                 return i;
  1733.  
  1734.             nStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nStartX);
  1735.             nNumClosedButtons++;
  1736.         }
  1737.     }
  1738.  
  1739.     int nExtTabSize = m_externalTabArray.GetSize();
  1740.  
  1741.     for(int j = 0; j < nExtTabSize; j++)
  1742.     {
  1743.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab *)m_externalTabArray[j];
  1744.  
  1745.         HTAB_BITMAP tabType = pExtTab->GetHTabType();
  1746.         if(PointInClosedTab(point, tabType, nNumClosedButtons, nStartX, rcClient.bottom))
  1747.             return j + m_nNumToolbars;
  1748.  
  1749.  
  1750.         nStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nStartX);
  1751.  
  1752.  
  1753.         nNumClosedButtons++;
  1754.     }
  1755.  
  1756.     return -1;
  1757.  
  1758. }
  1759.  
  1760. BOOL CCustToolbar::PointInClosedTab(CPoint point, HTAB_BITMAP tabType, int nNumClosedButtons, int nStartX, int nBottom)
  1761. {
  1762.     CRgn rgn;
  1763.  
  1764.     GetClosedButtonRegion(tabType, nNumClosedButtons, rgn);
  1765.     rgn.OffsetRgn(nStartX, nBottom - CLOSED_BUTTON_HEIGHT);
  1766.     if(rgn.PtInRegion(point))
  1767.     {
  1768.         rgn.DeleteObject();
  1769.         return TRUE;
  1770.     }
  1771.     rgn.DeleteObject();
  1772.     return FALSE;
  1773. }
  1774.  
  1775. // if bToolbarSeparator is true then draw a grey line and a white line.  If it's false then it is the
  1776. // separator between the last toolbar and the closed buttons so draw a grey line and a black line
  1777. void CCustToolbar::DrawSeparator(HDC hDC, int nStartX, int nEndX, int nStartY, BOOL bToolbarSeparator)
  1778. {
  1779.  
  1780.     HPEN pen = ::CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
  1781.     HPEN pOldPen = (HPEN)::SelectObject(hDC, pen);
  1782.  
  1783. #if defined (WIN32)
  1784.     ::MoveToEx(hDC, nStartX, nStartY, NULL);
  1785. #else
  1786.     ::MoveTo(hDC, nStartX, nStartY);
  1787. #endif
  1788.  
  1789.     ::LineTo(hDC, nEndX, nStartY);
  1790.  
  1791.     ::SelectObject(hDC, pOldPen);
  1792.  
  1793.     ::DeleteObject(pen);
  1794.  
  1795.     if(bToolbarSeparator)
  1796.     {       
  1797.     #if defined(WIN32)
  1798.         pen = ::CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHILIGHT));
  1799.     #else
  1800.         pen = ::CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT)); 
  1801.     #endif
  1802.     
  1803.     }
  1804.     else
  1805.     {
  1806.         pen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  1807.     }
  1808.  
  1809.     ::SelectObject(hDC, pen);
  1810.  
  1811. #if defined (WIN32)
  1812.     ::MoveToEx(hDC, nStartX, nStartY + 1, NULL);
  1813. #else
  1814.     ::MoveTo(hDC, nStartX, nStartY + 1);
  1815. #endif
  1816.  
  1817.     ::LineTo(hDC, nEndX, nStartY + 1);
  1818.  
  1819.     ::SelectObject(hDC, pOldPen);
  1820.     ::DeleteObject(pen);
  1821.  
  1822.  
  1823. }
  1824.  
  1825. //if dir < 0 then move pSwitch above pOriginal.  If dir > 0 then move pSwitch below pOriginal
  1826. void CCustToolbar::SwitchChildren(CDragToolbar *pOriginal, CDragToolbar *pSwitch, int dir, 
  1827.                                   int topYPoint)
  1828. {
  1829.     int nOriginalPos = FindIndex(pOriginal);
  1830.     int nSwitchPos = FindIndex (pSwitch);
  1831.  
  1832.     if(nOriginalPos == -1 || nSwitchPos == -1)
  1833.         return;
  1834.  
  1835.     //if we've already switched these two (i.e. moving down and pOriginal already below pSwitch
  1836.     //then don't continue
  1837.     if((dir <0 && nOriginalPos > nSwitchPos) || (dir > 0 && nSwitchPos > nOriginalPos))
  1838.         return;
  1839.  
  1840.     m_pToolbarArray[nOriginalPos] = pSwitch;
  1841.     m_pToolbarArray[nSwitchPos] = pOriginal;
  1842.  
  1843.     if((nSwitchPos == m_nAnimationPos && dir > 0) ||
  1844.        (nOriginalPos == m_nAnimationPos && dir < 0))
  1845.     {
  1846.         // The animation is hopping from one toolbar to another.
  1847.         // These two toolbars could change their heights following
  1848.         // the movement of the animation.  In this case, we care
  1849.         // about the one being dragged.  It had a silly drag border
  1850.         // appended to its height... we need to keep that around.
  1851.         // pOriginal is the one being dragged.
  1852.         int height = pOriginal->GetToolbarHeight();
  1853.  
  1854.         if(dir < 0)
  1855.         {
  1856.             // Moving down.  Animation leaves the bar being dragged
  1857.             // and hops onto the new one.  The bar being dragged
  1858.             // could shrink in size.
  1859.             pOriginal->SetAnimation(NULL);            // Order of these is relevant.
  1860.             pSwitch->SetAnimation(m_pAnimation);    // Dont want to have anim. on two simult.
  1861.         }
  1862.         else 
  1863.         {
  1864.             // Moving up.  Animation pops onto the bar being dragged
  1865.             // and leaves the old one.  The bar being dragged could
  1866.             // expand.
  1867.             pSwitch->SetAnimation(NULL);            // Order of these is relevant.
  1868.             pOriginal->SetAnimation(m_pAnimation);    // Dont want to have anim. on two simult.
  1869.         }
  1870.         
  1871.         CRect clientRect;
  1872.         pOriginal->GetClientRect(&clientRect);
  1873.         MapWindowPoints(this, clientRect);
  1874.  
  1875.         // We recalced our layout to accommodate the animation.
  1876.         // Append the dragging_border_height back in if the height changed.
  1877.         int newHeight = pOriginal->GetToolbarHeight();
  1878.  
  1879.         // Now the window has to be moved to the correct yPoint location.  
  1880.                 
  1881.         if ((newHeight < height) && (pOriginal->GetMouseOffsetWithinToolbar() > newHeight))
  1882.         {
  1883.             // If the window shrank, then the user's drag pointer may become
  1884.             // invalid. Therefore for this case only, we have to move the toolbar
  1885.             // so that it is still underneath the user's drag pointer.
  1886.  
  1887.             // Preserve the yoffset from the bottom of the drag. (Hey, gotta
  1888.             // do something...)
  1889.             // Toolbar moves down by the difference in the two heights.
  1890.             int diff = height - newHeight;
  1891.             if (diff > newHeight)    // Handle the (rare and highly improbable)
  1892.             {                        // case where the toolbar more than halves its height
  1893.                 
  1894.                 topYPoint += pOriginal->GetMouseOffsetWithinToolbar() - newHeight/2;
  1895.                 // In this (preposterously rare) case, snap the toolbar so that it is
  1896.                 // sitting with its halfway point (vertically) under the mouse pointer.
  1897.                 // Adjust our cached mouse offset
  1898.                 pOriginal->SetMouseOffsetWithinToolbar(newHeight/2);
  1899.             }
  1900.             else 
  1901.             {
  1902.                 topYPoint += diff;
  1903.  
  1904.                 // Adjust our cached mouse offset
  1905.                 pOriginal->SetMouseOffsetWithinToolbar(pOriginal->GetMouseOffsetWithinToolbar() - 
  1906.                                                         diff);
  1907.             }
  1908.         }
  1909.         
  1910.         // Set the new position and size
  1911.         pOriginal->SetWindowPos(NULL, clientRect.left, topYPoint, clientRect.Width(), newHeight + DRAGGING_BORDER_HEIGHT, SWP_NOZORDER);    
  1912.     }
  1913.  
  1914.     int nYStart = (m_nNumOpen == 0) ? 0 : SPACE_BETWEEN_TOOLBARS;
  1915.     for(int i = 0; i < nOriginalPos; i++)
  1916.     {
  1917.         if(m_pToolbarArray[i] != NULL && m_pToolbarArray[i]->GetOpen())
  1918.         {
  1919.             nYStart += m_pToolbarArray[i]->GetToolbarHeight() + SPACE_BETWEEN_TOOLBARS;
  1920.         }
  1921.     }
  1922.  
  1923.     pSwitch->SetWindowPos(&wndBottom, 0, nYStart, 0, 0, SWP_NOSIZE); 
  1924. }
  1925.  
  1926. //Finds the child window that is at the given point that is not pIgnore.  If this
  1927. //child doesn't exist, NULL is returned.
  1928. CDragToolbar *CCustToolbar::FindToolbarFromPoint(CPoint point, CDragToolbar *pIgnore)
  1929. {
  1930.     for(int i = 0; i < m_nNumToolbars; i++)
  1931.     {
  1932.         if(m_pToolbarArray[i] != NULL && m_pToolbarArray[i] != pIgnore && m_pToolbarArray[i]->GetOpen())
  1933.         {
  1934.             CRect clientRect;
  1935.  
  1936.             MapWindowPoints(m_pToolbarArray[i], &point, 1);
  1937.             m_pToolbarArray[i]->GetClientRect(&clientRect);
  1938.  
  1939.             if(clientRect.PtInRect(point))
  1940.                 return m_pToolbarArray[i];
  1941.         }
  1942.     }
  1943.  
  1944.     return NULL;
  1945. }
  1946.  
  1947. int CCustToolbar::FindIndex(CDragToolbar *pToolbar)
  1948. {
  1949.  
  1950.     for(int i = 0; i < m_nNumToolbars; i++)
  1951.     {
  1952.  
  1953.         if(m_pToolbarArray[i] == pToolbar)
  1954.             return i;
  1955.  
  1956.     }
  1957.     
  1958.     return -1;
  1959. }
  1960.  
  1961. //Finds the first showing toolbar after the given index
  1962. int CCustToolbar::FindFirstShowingToolbar(int nIndex)
  1963. {
  1964.     for(int i = nIndex + 1; i < m_nNumToolbars; i++)
  1965.     {
  1966.         if(m_pToolbarArray[i] != NULL && m_pToolbarArray[i]->GetOpen())
  1967.             return i;
  1968.     }
  1969.  
  1970.     return -1;
  1971.  
  1972. }
  1973.  
  1974. HBITMAP CCustToolbar::GetClosedButtonBitmap(HTAB_BITMAP tabType, int nNumClosedButtons)
  1975. {
  1976.     switch(tabType)
  1977.     {
  1978.         case eLARGE_HTAB:
  1979.             if(nNumClosedButtons == 0)
  1980.                 return m_pHorizTabArray[LARGE_FIRST];
  1981.             else
  1982.                 return m_pHorizTabArray[LARGE_OTHER];;
  1983.             break;
  1984.         case eSMALL_HTAB:
  1985.             if(nNumClosedButtons == 0)
  1986.                 return m_pHorizTabArray[SMALL_FIRST];
  1987.             else
  1988.                 return m_pHorizTabArray[SMALL_OTHER];
  1989.     
  1990.     }
  1991.  
  1992.     return NULL;
  1993. }
  1994.  
  1995. int CCustToolbar::GetNextClosedButtonX(HTAB_BITMAP tabType, int nNumClosedButtons, int nClosedStartX)
  1996. {
  1997.  
  1998.     switch(tabType)
  1999.     {
  2000.         case eLARGE_HTAB:
  2001.             if(nNumClosedButtons == 0)
  2002.                 return 53;
  2003.             else
  2004.                 return 56;
  2005.             break;
  2006.         case eSMALL_HTAB:
  2007.             if(nNumClosedButtons == 0)
  2008.                 return 29;
  2009.             else
  2010.                 return 33;
  2011.             break;
  2012.     }
  2013.  
  2014.     return 0;
  2015.  
  2016. }
  2017.  
  2018. void  CCustToolbar::GetClosedButtonRegion(HTAB_BITMAP tabType, int nNumClosedButtons, CRgn &rgn)
  2019. {
  2020.  
  2021.     POINT ptArray[4];
  2022.  
  2023.     switch(tabType)
  2024.     {
  2025.         case eLARGE_HTAB:
  2026.             if(nNumClosedButtons == 0)
  2027.             {
  2028.                 ptArray[0].x = 0;
  2029.                 ptArray[0].y = 0;
  2030.                 ptArray[1].x = 62;
  2031.                 ptArray[1].y = 0;
  2032.                 ptArray[2].x = 53;
  2033.                 ptArray[2].y = 9;
  2034.                 ptArray[3].x = 0;
  2035.                 ptArray[3].y = 9;
  2036.             }
  2037.             else
  2038.             {
  2039.                 ptArray[0].x = 9;
  2040.                 ptArray[0].y = 0;
  2041.                 ptArray[1].x = 65;
  2042.                 ptArray[1].y = 0;
  2043.                 ptArray[2].x = 56;
  2044.                 ptArray[2].y = 9;
  2045.                 ptArray[3].x = 0;
  2046.                 ptArray[3].y = 9;
  2047.             }
  2048.             break;
  2049.         case eSMALL_HTAB:
  2050.             if(nNumClosedButtons == 0)
  2051.             {
  2052.                 ptArray[0].x = 0;
  2053.                 ptArray[0].y = 0;
  2054.                 ptArray[1].x = 38;
  2055.                 ptArray[1].y = 0;
  2056.                 ptArray[2].x = 29;
  2057.                 ptArray[2].y = 9;
  2058.                 ptArray[3].x = 0;
  2059.                 ptArray[3].y = 9;
  2060.             }
  2061.             else
  2062.             {
  2063.                 ptArray[0].x = 9;
  2064.                 ptArray[0].y = 0;
  2065.                 ptArray[1].x = 42;
  2066.                 ptArray[1].y = 0;
  2067.                 ptArray[2].x = 33;
  2068.                 ptArray[2].y = 9;
  2069.                 ptArray[3].x = 0;
  2070.                 ptArray[3].y = 9;
  2071.             }
  2072.             break;
  2073.     }
  2074.     rgn.CreatePolygonRgn(ptArray, 4, WINDING);
  2075. }
  2076.  
  2077. HBITMAP CCustToolbar::CreateHorizTab(UINT nID)
  2078. {
  2079.  
  2080.     HINSTANCE hInst = AfxGetResourceHandle();
  2081.     HDC hDC = ::GetDC(m_hWnd);
  2082.  
  2083.     HPALETTE hOldPalette = ::SelectPalette(hDC, WFE_GetUIPalette(GetParentFrame()), FALSE);
  2084.  
  2085.     HBITMAP bitmap = wfe_LoadBitmap(hInst, hDC, MAKEINTRESOURCE(nID));
  2086.  
  2087.     ::SelectPalette(hDC, hOldPalette, TRUE);
  2088.     ::ReleaseDC(m_hWnd, hDC);
  2089.  
  2090.     return bitmap;
  2091. }
  2092.  
  2093. int CCustToolbar::FindDragToolbarFromWindow(CWnd *pWindow, CDragToolbar **pToolbarArray)
  2094. {
  2095.  
  2096.     for(int i = 0; i < m_nNumToolbars; i++)
  2097.     {
  2098.         if(pToolbarArray[i] != NULL)
  2099.         {
  2100.             if(pToolbarArray[i]->GetToolbar() == pWindow)
  2101.                 return i;
  2102.         }
  2103.     }
  2104.  
  2105.     return -1;
  2106.  
  2107.  
  2108. }
  2109.  
  2110. int CCustToolbar::FindDragToolbarFromID(UINT nToolbarID, CDragToolbar **pToolbarArray)
  2111. {
  2112.  
  2113.     for(int i = 0; i < m_nNumToolbars; i++)
  2114.     {
  2115.         if(pToolbarArray[i] != NULL)
  2116.         {
  2117.             if(pToolbarArray[i]->GetToolbarID() == nToolbarID)
  2118.                 return i;
  2119.         }
  2120.     }
  2121.  
  2122.     return -1;
  2123.  
  2124.  
  2125. }
  2126.  
  2127. void CCustToolbar::OpenDragToolbar(int nIndex)
  2128. {
  2129.     m_pToolbarArray[nIndex]->SetOpen(TRUE);
  2130.     m_pToolbarArray[nIndex]->ShowWindow(SW_SHOW);
  2131.  
  2132.     CheckAnimationChangedToolbar(m_pToolbarArray[nIndex], nIndex, TRUE);
  2133.  
  2134.     m_nNumOpen++;
  2135.     m_pParent->RecalcLayout();
  2136.     RedrawWindow();
  2137. }
  2138.  
  2139. void CCustToolbar::OpenExternalTab(int nIndex)
  2140. {
  2141.     if( nIndex >= 0 && nIndex < m_externalTabArray.GetSize())
  2142.     {
  2143.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab*)m_externalTabArray[nIndex];
  2144.         pExtTab->GetOwner()->SendMessage(WM_COMMAND, IDC_COLLAPSE);
  2145.         m_externalTabArray.RemoveAt(nIndex);
  2146.         delete pExtTab;
  2147.         m_pParent->RecalcLayout();
  2148.         RedrawWindow();
  2149.     }
  2150. }
  2151.  
  2152. // Checks to see if the animation has to go on a different toolbar.  If bOpen is TRUE,
  2153. // this checks to see if opening toolbar gets the animation.  If bOpen is FALSE, and
  2154. // pToolbar has the animation, it removes it and finds the new toolbar to give it to
  2155. void CCustToolbar::CheckAnimationChangedToolbar(CDragToolbar *pToolbar, int nIndex, BOOL bOpen)
  2156. {
  2157.  
  2158.     if(bOpen)
  2159.     {
  2160.         if(nIndex < m_nAnimationPos || m_nAnimationPos == -1)
  2161.         {
  2162.             if(m_nAnimationPos != -1)
  2163.             {
  2164.                 m_pToolbarArray[m_nAnimationPos]->SetAnimation(NULL);
  2165.             }
  2166.             else
  2167.             {
  2168.                 if(m_pAnimation)
  2169.                     m_pAnimation->ShowWindow(SW_SHOW);
  2170.             }
  2171.             pToolbar->SetAnimation(m_pAnimation);
  2172.             m_nAnimationPos = nIndex;
  2173.         }
  2174.     }
  2175.     else
  2176.     {
  2177.         if(nIndex == m_nAnimationPos)
  2178.         {
  2179.             //This sets m_nAnimationPos to -1 if everything is closed
  2180.             int nFirstShowing = FindFirstShowingToolbar(nIndex);
  2181.             m_nAnimationPos = nFirstShowing;
  2182.  
  2183.             if(m_nAnimationPos != -1)
  2184.             {
  2185.                 m_pToolbarArray[m_nAnimationPos]->SetAnimation(m_pAnimation);
  2186.             }
  2187.             else
  2188.             {
  2189.                 if(m_pAnimation)
  2190.                     m_pAnimation->ShowWindow(SW_HIDE);
  2191.             }
  2192.  
  2193.             pToolbar->SetAnimation(NULL);
  2194.         }
  2195.  
  2196.     }
  2197.  
  2198. }
  2199.  
  2200. void CCustToolbar::ChangeToolTips(int nHeight)
  2201. {
  2202.     CDragToolbar *pToolbar = NULL;
  2203.     int i;
  2204.  
  2205.     // First remove all tools
  2206.     for(i = 0; i < m_nNumToolbars; i++)
  2207.     {
  2208.         if(m_pToolbarArray[i] != NULL)
  2209.             pToolbar = (CDragToolbar *) m_pToolbarArray[i];
  2210.         else if(m_pHiddenToolbarArray[i] != NULL)
  2211.             pToolbar = (CDragToolbar *) m_pHiddenToolbarArray[i];
  2212.  
  2213.         if(pToolbar != NULL && pToolbar->GetToolID() != NOTOOL)
  2214.         {
  2215. #ifdef XP_WIN32
  2216.             m_toolTip.DelTool(this, pToolbar->GetToolID());
  2217. #else
  2218.             m_toolTip.DelTool(m_hWnd, pToolbar->GetToolID());
  2219. #endif
  2220.  
  2221.             pToolbar->SetToolID(NOTOOL);
  2222.         }
  2223.     }
  2224.  
  2225.     int nExtTabSize = m_externalTabArray.GetSize();
  2226.  
  2227.     for(i = 0 ; i < nExtTabSize; i ++)
  2228.     {
  2229.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab *)m_externalTabArray[i];
  2230.  
  2231. #ifdef XP_WIN32
  2232.         m_toolTip.DelTool(this, pExtTab->GetToolID());
  2233. #else
  2234.         m_toolTip.DelTool(m_hWnd, pExtTab->GetToolID());
  2235. #endif
  2236.  
  2237.         pExtTab->SetToolID(NOTOOL);
  2238.     }
  2239.  
  2240.     // Now Set the Tools for those toolbars that are visible and closed
  2241.     int nNumClosedButtons = 0;
  2242.     int nClosedStartX = 0;
  2243.     CRect toolRect;
  2244.  
  2245.     for(int j = 0; j < m_nNumToolbars; j++)
  2246.     {
  2247.         pToolbar = (CDragToolbar *) m_pToolbarArray[j];
  2248.  
  2249.         if(pToolbar && !pToolbar->GetOpen())
  2250.         {
  2251.             HTAB_BITMAP tabType = pToolbar->GetHTabType();
  2252.             FindToolRect(toolRect, tabType, nClosedStartX, nHeight - CLOSED_BUTTON_HEIGHT, nNumClosedButtons); 
  2253.             nClosedStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nClosedStartX);
  2254.             nNumClosedButtons++;
  2255.             m_toolTip.AddTool(this, pToolbar->GetTabTip(), &toolRect, nNumClosedButtons);
  2256.             pToolbar->SetToolID(nNumClosedButtons);
  2257.         }
  2258.     }
  2259.  
  2260.  
  2261.     for(int k = 0; k < nExtTabSize; k++)
  2262.     {
  2263.         CCustToolbarExternalTab *pExtTab = (CCustToolbarExternalTab *)m_externalTabArray[k];
  2264.  
  2265.         HTAB_BITMAP tabType = pExtTab->GetHTabType();
  2266.         FindToolRect(toolRect, tabType, nClosedStartX, nHeight - CLOSED_BUTTON_HEIGHT, nNumClosedButtons); 
  2267.         nClosedStartX += GetNextClosedButtonX(tabType, nNumClosedButtons, nClosedStartX);
  2268.         nNumClosedButtons++;
  2269.         m_toolTip.AddTool(this, pExtTab->GetTabTip(), &toolRect, nNumClosedButtons);
  2270.         pExtTab->SetToolID(nNumClosedButtons);
  2271.  
  2272.     }
  2273.  
  2274. }
  2275.  
  2276. void CCustToolbar::FindToolRect(CRect &toolRect, HTAB_BITMAP eTabType, int nStartX, int nStartY, int nButtonNum)
  2277. {
  2278.     switch(eTabType)
  2279.     {
  2280.         case eLARGE_HTAB:
  2281.             if(nButtonNum == 0)
  2282.             {
  2283.                 toolRect.SetRect(nStartX, nStartY, nStartX + 53, nStartY + 9);
  2284.             }
  2285.             else
  2286.             {
  2287.                 toolRect.SetRect(nStartX + 9, nStartY, nStartX + 56, nStartY + 9);
  2288.             }
  2289.             break;
  2290.         case eSMALL_HTAB:
  2291.             if(nButtonNum == 0)
  2292.             {
  2293.                 toolRect.SetRect(nStartX, nStartY, nStartX + 29, nStartY + 9);
  2294.             }
  2295.             else
  2296.             {
  2297.                 toolRect.SetRect(nStartX + 9, nStartY, nStartX + 33, nStartY +  9);
  2298.             }
  2299.             break;
  2300.     }
  2301.  
  2302.  
  2303. }
  2304.  
  2305. int  CCustToolbar::FindFirstAvailablePosition(void)
  2306. {
  2307.  
  2308.     for(int i = 0; i < m_nNumToolbars; i++)
  2309.     {
  2310.  
  2311.         if(m_pHiddenToolbarArray[i] == NULL && m_pToolbarArray[i] == NULL)
  2312.             return i;
  2313.     }
  2314.  
  2315.     return -1;
  2316.  
  2317. }
  2318.  
  2319. void CCustToolbar::DrawClosedTab(HDC hCompatibleDC, HDC hDestDC, HTAB_BITMAP tabType, int nNumClosedButtons,
  2320.                                  BOOL bMouseOver, int nStartX, int nBottom)
  2321. {
  2322.  
  2323.     HBITMAP hBitmap = GetClosedButtonBitmap(tabType, nNumClosedButtons);
  2324.  
  2325.     if(hBitmap != NULL)
  2326.     {
  2327.  
  2328.         // Create a scratch DC and select our bitmap into it.
  2329.         HDC pBmpDC  = ::CreateCompatibleDC(hCompatibleDC);
  2330.  
  2331.         HBITMAP hOldBmp = (HBITMAP)::SelectObject(pBmpDC , hBitmap);
  2332.         // Get the image dimensions
  2333.         CSize sizeImg;
  2334.         BITMAP bmp;
  2335.  
  2336.         ::GetObject(hBitmap, sizeof(bmp), &bmp);
  2337.         sizeImg.cx = bmp.bmWidth;
  2338.         sizeImg.cy = CLOSED_BUTTON_HEIGHT;
  2339.         
  2340.         CPoint bitmapStart(0, !bMouseOver ? 0 : CLOSED_BUTTON_HEIGHT);
  2341.  
  2342.         ::FEU_TransBlt( hDestDC, nStartX, nBottom - sizeImg.cy, sizeImg.cx, sizeImg.cy,
  2343.                         pBmpDC, bitmapStart.x, bitmapStart.y, WFE_GetUIPalette(GetParentFrame()), PALETTERGB(255, 0, 255) );
  2344.  
  2345.         // Cleanup
  2346.         ::SelectObject(pBmpDC, hOldBmp);
  2347.         DeleteDC(pBmpDC);
  2348.  
  2349.     
  2350.     }
  2351.  
  2352.  
  2353.  
  2354. }
  2355.