home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / toolbar2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.2 KB  |  257 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. // Creates a class that will represent the new toolbar which can hold
  20. // the new buttons for the customizable toolbar.
  21.  
  22.  
  23. #ifndef _TOOLBAR2_H
  24. #define _TOOLBAR2_H
  25.  
  26. #include <afxwin.h>
  27. #include <afxext.h>
  28. #include <afxpriv.h>
  29. #include <afxole.h>
  30. #include <afxdisp.h>
  31. #include <afxodlgs.h>
  32. #ifdef _WIN32
  33. #include <afxcmn.h>
  34. #endif
  35.  
  36. #include "tlbutton.h"
  37. #include "csttlbr2.h"
  38.  
  39. #define TOOLBAR_WIDTH_CHANGED (WM_USER + 31)
  40. #define TOOLBAR_BUTTON_ADD (WM_USER + 40)
  41. #define TOOLBAR_BUTTON_REMOVE (WM_USER + 41)
  42. #define TOOLBAR_BUTTON_DELETED (WM_USER + 42)
  43.  
  44. class CToolbarDropSource : public COleDropSource {
  45. public:
  46.     CToolbarDropSource() {}
  47.     SCODE GiveFeedback( DROPEFFECT dropEffect);
  48.  
  49. };
  50.  
  51. class CCustToolbar;
  52.  
  53.  
  54. class CNSToolbar2 : public CWnd {
  55. //DECLARE_DYNCREATE(CNSToolbar2)
  56.  
  57. protected:
  58.     BOOL             m_bEraseBackground;
  59.  
  60.     int                 m_nMaxButtons;        // The maximum number of buttons this toolbar can hold
  61.     BOOL             m_nToolbarStyle;        // whether we are in novice or advanced mode
  62.     int                 m_nPicturesAndTextHeight;    // Our height when we are in novice mode
  63.     int                 m_nPicturesHeight;
  64.     int                 m_nTextHeight;    // Our height when we are in advanced mode
  65.     CToolbarButton** m_pButtonArray;    // The array of toolbar buttons
  66.     int                 m_nNumButtons;        // The number of buttons we currently hold
  67.     int                 m_nHeight;            // Our current height
  68.     int                 m_nWidth;            // Our current required width given all of the buttons
  69.  
  70.     BOOL             m_bDragging;        // Are we currently dragging a button
  71.     int                 m_nDraggingButton; // Index of button we are dragging
  72.     CPoint              m_draggingPoint;    // Point we started dragging from
  73.     CCustToolbar*    m_pCustToolbar;    // A pointer to the customizable toolbar it belongs to
  74.     
  75.     int                 m_nMaxButtonWidth; // The width of the widest button
  76.     int                 m_nMaxButtonHeight;// The height of the tallest button
  77.     HBITMAP             m_hBitmap;            // Bitmap to be used for toolbar (doesn't have to have one);
  78.     CPtrArray         m_pHiddenButtons;  // Buttons we are keeping track of but aren't currently showing;
  79.     BOOL             m_bButtonsSameWidth;// Are all the buttons the width of the largest one or
  80.                                         // their own individual widths
  81.     UINT             m_nBitmapID;        // The toolbar's bitmap
  82. public:
  83.     CNSToolbar2(){}
  84.     CNSToolbar2(int nMaxButtons, int nToolbarStyle, int nPicturesAndTextHeight, int nPicturesHeight, int nTextHeight);
  85.     ~CNSToolbar2();
  86.  
  87.     int Create(CWnd *pParent);
  88.  
  89.     virtual void AddButtonAtIndex(CToolbarButton *pButton, int index = -1, BOOL bNotify = TRUE);
  90.     virtual int AddButtonAtPoint(CToolbarButton *pButton, CPoint point, BOOL bAddButton = TRUE);
  91.     
  92.     virtual void AddButton(CToolbarButton* pButton, int index = -1) { AddButtonAtIndex(pButton, index); }
  93.  
  94.     void AddHiddenButton(CToolbarButton *pButton);
  95.  
  96.     CToolbarButton* RemoveButton(int nIndex, BOOL bNotify = TRUE);
  97.     CToolbarButton* RemoveButton(CToolbarButton *pButton);
  98.     CToolbarButton* RemoveButtonByCommand(UINT nCommand);
  99.  
  100.     void DecrementButtonCount() { m_nNumButtons--; }
  101.  
  102.     void HideButtonByCommand(UINT nCommand);
  103.     void ShowButtonByCommand(UINT nCommand, int nPos);
  104.  
  105.     void RemoveAllButtons(void);
  106.     CToolbarButton *ReplaceButton(UINT nCommand, CToolbarButton *pNewButton);
  107.     void ReplaceButton(UINT nOldCommand, UINT nNewCommand);
  108.  
  109.     CToolbarButton* GetNthButton(int nIndex);
  110.     CToolbarButton* GetButton(UINT nID);  //Added by cmanske
  111.  
  112.     int GetNumButtons(void);
  113.  
  114.     void SetBitmap(UINT nBitmapID);
  115.     void SetBitmap(char *pBitmapFile);
  116.     HBITMAP GetBitmap(void);
  117.  
  118.     // Sets each buttons bitmap to be nWidth by nHeight;
  119.     void SetBitmapSize(int nWidth, int nHeight);
  120.  
  121.     void SetToolbarStyle(int nToolbarStyle);
  122.     BOOL GetToolbarStyle(void) {return m_nToolbarStyle;}
  123.     void LayoutButtons(void);
  124.     virtual void LayoutButtons(int nStartIndex);
  125.     virtual void WidthChanged(int width) {};  // used by personal toolbar.
  126.  
  127.     BOOL GetButtonRect(UINT nID, RECT *pRect);
  128.  
  129.     void SetCustomizableToolbar(CCustToolbar* pCustToolbar);
  130.     CCustToolbar *GetCustomizableToolbar(void);
  131.  
  132.     virtual int GetHeight(void);
  133.     int GetWidth(void);
  134.  
  135.     void SetButtonsSameWidth(BOOL bButtonsSameWidth);
  136.     BOOL GetButtonsSameWidth(void) { return m_bButtonsSameWidth; }
  137.  
  138.     void ReplaceButtonBitmapIndex(UINT nID, UINT nIndex);
  139.  
  140.     BOOL OnCommand( WPARAM wParam, LPARAM lParam );
  141.     virtual BOOL OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult );
  142.  
  143.     void OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler );
  144.  
  145.     // Set a button to do its command on button down instead of button up
  146.     BOOL SetDoOnButtonDownByCommand(UINT nCommand, BOOL bDoOnButtonDown);
  147.  
  148.     // Generated message map functions
  149.     //{{AFX_MSG(CNSToolbar2)
  150.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  151.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  152.     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  153.     afx_msg LRESULT OnButtonDrag(WPARAM, LPARAM); 
  154.     afx_msg void OnShowWindow( BOOL bShow, UINT nStatus );
  155.     afx_msg BOOL OnEraseBkgnd( CDC* pDC );
  156.     afx_msg void OnPaint(void);
  157.     afx_msg LRESULT OnToolbarButtonSizeChanged(WPARAM, LPARAM);
  158.     afx_msg void OnPaletteChanged( CWnd* pFocusWnd );
  159.     afx_msg void OnSysColorChange( );
  160.     //}}AFX_MSG
  161.     DECLARE_MESSAGE_MAP()
  162.  
  163. protected:
  164.     int  FindButton(CPoint point);
  165.     int  FindButton(CWnd *pButton);
  166.     int     FindButton(UINT nCommand);
  167.     void MoveButton(int nIndex);
  168.     BOOL CheckMaxButtonSizeChanged(CToolbarButton *pButton, BOOL bAdd);
  169.     void ChangeButtonSizes(void);
  170.     BOOL FindLargestButton(void);
  171.     //Given an index, this says where a button starts and where it ends
  172.     void GetButtonXPosition(int nSelection,int & nStart,int & nEnd);
  173.     int FindButtonFromBoundary(int boundary, BOOL bIsBefore);
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. };
  181.  
  182.  
  183.  
  184. class CCommandToolbarDropTarget : public COleDropTarget
  185. {
  186.     public:
  187.         CCommandToolbarDropTarget() {}
  188.      
  189.     protected:
  190.         virtual DROPEFFECT OnDragEnter(CWnd * pWnd,
  191.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point);
  192.         virtual DROPEFFECT OnDragOver(CWnd * pWnd,
  193.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point );
  194.         virtual BOOL OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  195.             DROPEFFECT dropEffect, CPoint point);
  196.  
  197.     private:
  198.  
  199. };
  200.  
  201. class CCommandToolbar : public CNSToolbar2 {
  202.  
  203. //private:
  204.     CCommandToolbarDropTarget m_DropTarget;
  205.  
  206. public:
  207.     CCommandToolbar(int nMaxButtons, int nToolbarStyle, int nPicturesAndTextHeight, int nPicturesHeight,
  208.                     int nTextHeight);
  209.  
  210.     int Create(CWnd *pParent);
  211.     virtual int GetHeight(void);
  212.  
  213.     // Generated message map functions
  214.     //{{AFX_MSG(CCommandToolbar)
  215.         afx_msg int OnCreate ( LPCREATESTRUCT );
  216.     //}}AFX_MSG
  217.     DECLARE_MESSAGE_MAP()
  218.  
  219. };
  220.  
  221.  
  222. class CToolbarControlBar : public CControlBar {
  223.  
  224. protected:
  225.     CNSToolbar2 *m_pToolbar;
  226.     BOOL m_bEraseBackground;
  227.  
  228. public:
  229.     CToolbarControlBar();
  230.     ~CToolbarControlBar();
  231.  
  232.     //Creation
  233.     int Create(CFrameWnd *pParent, DWORD dwStyle, UINT nID );
  234.  
  235.     //Positioning/Resizing
  236.     virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode ); 
  237.  
  238.     virtual void OnUpdateCmdUI( CFrameWnd* pTarget, BOOL bDisableIfNoHndler );
  239.  
  240.     void SetToolbar(CNSToolbar2 *pToolbar) { m_pToolbar = pToolbar; }
  241.     CNSToolbar2* GetToolbar(void) { return m_pToolbar; }
  242.  
  243.     // Generated message map functions
  244.     //{{AFX_MSG(CToolbarControlBar)
  245.     afx_msg void OnShowWindow( BOOL bShow, UINT nStatus );
  246.     afx_msg BOOL OnEraseBkgnd( CDC* pDC );
  247.     afx_msg void OnSize( UINT nType, int cx, int cy );
  248.     afx_msg void OnPaint(void);
  249. #ifndef WIN32
  250.     afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
  251. #endif
  252.     //}}AFX_MSG
  253.     DECLARE_MESSAGE_MAP()
  254.  };
  255.  
  256. #endif
  257.