home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / tlbutton.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  16.7 KB  |  439 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. // Defines a toolbar button
  20. // Created August 19, 1996 by Scott Putterman
  21.  
  22.  
  23. #ifndef _TLBUTTON_H
  24. #define _TLBUTTON_H
  25.  
  26. #include "winproto.h"
  27.  
  28. #include "tooltip.h"
  29.  
  30.  
  31. #define SHOW_ALL_CHARACTERS -1
  32.  
  33. #define TB_DYNAMIC_TOOLTIP        0x1        //Client fills in tooltip
  34. #define TB_HAS_TIMED_MENU        0x2        //Popup menu shows up on left mouse down after a small period of time
  35. #define TB_HAS_IMMEDIATE_MENU    0x4        //Popup menu shows up on left mouse down immediately
  36. #define TB_HAS_DRAGABLE_MENU    0x8        //Popup menu uses a CDropMenu instead of an HMENU. In order for this
  37.                                         //feature to work, must call SetDropTarget before dragging occurs. And
  38.                                         //the drop target must be derived from CToolbarButtonDropTarget
  39. #define TB_DYNAMIC_STATUS        0x10    //Client fills in status message
  40.  
  41. #define TB_HAS_DROPDOWN_TOOLBAR    0x20        // A CDropDownToolbar shows up on left mouse down (used for Composer only)
  42.  
  43. #define NSBUTTONMENUOPEN   (WM_USER + 1)    // Sent when a button menu is opened and needs to be filled in
  44. #define NSBUTTONDRAGGING   (WM_USER + 2)    // Sent when a button is being dragged
  45. #define NSDRAGMENUOPEN       (WM_USER + 3)    // Sent when a CDrop menu is being opened and needs to be filled in 
  46. #define NSDRAGGINGONBUTTON (WM_USER + 4)    // Sent when something is being dragged ontop of a button
  47.  
  48. #define TB_FILLINTOOLTIP   (WM_USER + 8)    // Sent when a string for a tooltip needs to be filled in
  49. #define TB_FILLINSTATUS       (WM_USER + 9)    // Sent when a string for the status bar needs to be filled in
  50. #define TB_SIZECHANGED       (WM_USER + 30)    // Sent when the button changes size
  51.  
  52. typedef struct {
  53.     HWND button;
  54. } BUTTONITEM;
  55.  
  56. typedef BUTTONITEM * LPBUTTONITEM;
  57.  
  58. #define NETSCAPE_BOOKMARK_BUTTON_FORMAT  "Netscape Bookmark Button Format"
  59.  
  60. typedef struct {
  61.     BOOKMARKITEM bookmark;
  62.     BUTTONITEM     buttonInfo;
  63. } BOOKMARKBUTTONITEM;
  64.  
  65. typedef BOOKMARKBUTTONITEM * LPBOOKMARKBUTTONITEM;
  66.  
  67. #define NETSCAPE_COMMAND_BUTTON_FORMAT  "Netscape Command Button Format"
  68.  
  69. typedef struct {
  70.     UINT         nCommand;
  71.     BUTTONITEM     buttonInfo;
  72. } COMMANDBUTTONITEM;
  73.  
  74. typedef COMMANDBUTTONITEM * LPCOMMANDBUTTONITEM;
  75.  
  76. class CToolbarButton;
  77.  
  78. class CButtonEditWnd : public CEdit
  79. {
  80. protected:
  81.     CToolbarButton *m_pOwner;    
  82. public:
  83.     CButtonEditWnd() { m_pOwner = NULL; }
  84.     ~CButtonEditWnd();
  85.  
  86.     void SetToolbarButtonOwner(CToolbarButton *pOwner);
  87.     virtual BOOL PreTranslateMessage ( MSG * msg );
  88.  
  89. protected:
  90.         // Generated message map functions
  91.     //{{AFX_MSG(CButtonEditWnd)
  92.     afx_msg void OnDestroy();
  93.     afx_msg void OnKillFocus( CWnd* pNewWnd );
  94.     //}}AFX_MSG
  95.     DECLARE_MESSAGE_MAP()
  96.  
  97. };
  98.  
  99. class CToolbarButtonCmdUI : public CCmdUI        
  100. {
  101. public: // re-implementations only
  102.     virtual void Enable(BOOL bOn);
  103.     virtual void SetCheck( int nCheck = 1 );
  104.  
  105.  
  106. };
  107.  
  108. class CDropMenu;
  109. class CToolbarButton;
  110.  
  111. #define CToolbarButtonDropTargetBase    COleDropTarget
  112.  
  113. class CToolbarButtonDropTarget : public CToolbarButtonDropTargetBase
  114. {
  115. protected:
  116.     CToolbarButton *m_pButton;
  117.  
  118. public:
  119.         CToolbarButtonDropTarget(){m_pButton = NULL;}
  120.         void SetButton(CToolbarButton *pButton) { m_pButton = pButton;}
  121.  
  122. protected:
  123.         virtual DROPEFFECT OnDragEnter(CWnd * pWnd,
  124.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point);
  125.         virtual DROPEFFECT OnDragOver(CWnd * pWnd,
  126.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point );
  127.         virtual BOOL OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  128.             DROPEFFECT dropEffect, CPoint point);
  129.         virtual DROPEFFECT ProcessDragEnter(CWnd *pWnd, COleDataObject *pDataObject, 
  130.             DWORD dwKeyState, CPoint point) = 0;
  131.         virtual DROPEFFECT ProcessDragOver(CWnd *pWnd, COleDataObject *pDataObject, 
  132.             DWORD dwKeyState, CPoint point) = 0;
  133.         virtual BOOL ProcessDrop(CWnd *pWnd, COleDataObject *pDataObject, 
  134.             DROPEFFECT dropEffect, CPoint point) = 0;
  135.  
  136.  
  137.     private:
  138.  
  139. }; 
  140.  
  141. class CToolbarButton: public CWnd {
  142.  
  143. public:
  144.     // States for button effects
  145.     enum BTN_STATE {eNORMAL, eDISABLED, eBUTTON_UP, eBUTTON_DOWN, eBUTTON_CHECKED};
  146.  
  147. protected:
  148.     BOOL        m_bIsResourceID;        // does this use a resource or a file
  149.     UINT        m_nBitmapID;            // the resource of the bitmap
  150.     UINT        m_nBitmapIndex;        // the index of the bitmap we wish to show
  151.     LPTSTR        m_pBitmapFile;        // the file in which the bitmap is stored
  152.     LPTSTR        m_pButtonText;        // the text displayed in Novice mode
  153.     LPTSTR        m_pToolTipText;        // the text displayed in the tooltip
  154.     LPTSTR        m_pStatusText;        // the text displayed in the status bar
  155.     int            m_nToolbarStyle;    // whether or not we are in Novice mode
  156.     CSize        m_noviceButtonSize;    // the size of the button in Novice mode
  157.     CSize        m_advancedButtonSize; // the size of the button in Advanced mode
  158.     CSize        m_bitmapSize;            // The size of each bitmap in the resource
  159.     int            m_nMaxTextChars;        // The maximum number of characters of the text shown on button
  160.     int         m_nMinTextChars;        // The minimum number of characters shown on button
  161.     DWORD        m_dwButtonStyle;        // the style of the button
  162.     BTN_STATE    m_eState;                // Current button state
  163.     BOOL        m_bEnabled;            // Is the button enabled
  164.     BOOL        m_bNeedsUpdate;        // Does the button need to be disabled/enabled
  165.     CToolbarButtonCmdUI m_state;
  166.     CMenu        m_menu;                // The menu if the button has one
  167.     CDropMenu*    m_pDropMenu;            // The drop menu if TB_HAS_DRAGABLE_MENU is set
  168.     UINT        m_nCommand;            // command associated with this button
  169.     UINT        m_hMenuTimer;            // The timer we use for starting menu if the button has one
  170.     BOOL        m_bMenuShowing;        // The menu is showing;
  171.     BOOL        m_bButtonDown;        // for every button up there must be a button down if an action 
  172.                                     // is to be taken
  173.     UINT        m_hFocusTimer;        // Timer to see if the button still has focus
  174.     BOOL        m_bHaveFocus;        // Do we have focus
  175.     HBITMAP        m_hBmpImg;            // The loaded bitmap
  176.     BOOL        m_bBitmapFromParent;// Does the parent own the bitmap or do we have to free it.
  177.     IconType    m_nIconType;            // The icon type (BITMAP, LOCAL_FILE, ARBITRARY URL)
  178.     int            m_nChecked;            // Is this button checked
  179.     CNSToolTip2 m_ToolTip;
  180.     BOOL        m_bEraseBackground;
  181.     CToolbarButtonDropTarget *m_pDropTarget;  //if we are a drop target
  182.     BOOL        m_bDraggingOnButton;
  183.     BOOL        m_bPicturesOnly;    // This button only shows pictures
  184.     BOOL        m_bDoOnButtonDown;  // Command is executed on button down instead of usual button up
  185.     CButtonEditWnd* m_pTextEdit;        // If the text can be edited in place we will need this edit window
  186.     BOOL        atMinimalSize;      // TRUE if the button is at its minimal size
  187.     BOOL        atMaximalSize;      // TRUE if the button is at its maximal size
  188.     BOOL        m_bDepressed;        // Is the button depressed and locked.
  189.     BOOL        hasCustomTextColor;    // TRUE if the button has a special text color.
  190.     BOOL        hasCustomBGColor;    // TRUE if the button has a special background color.
  191.     COLORREF    customTextColor;    // Custom Text Color
  192.     COLORREF    customBGColor;        // Custom BG Color
  193.  
  194. public:
  195.  
  196.     CToolbarButton();
  197.     ~CToolbarButton();
  198.  
  199.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  200.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  201.                LPCTSTR pStatusText, UINT nBitmapID, UINT nBitmapIndex,
  202.                CSize m_bitmapSize, BOOL bNeedsUpdate, UINT nCommand, int nMaxTextChars, int nMinTextChars = 0,
  203.                DWORD dwButtonStyle = 0);
  204.  
  205.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  206.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  207.                LPCTSTR pStatusText, LPCTSTR pBitmapFile,
  208.                CSize m_bitmapSize, BOOL bNeedsUpdate, UINT nCommand, int nMaxTextChars, int nMinTextChars = 0,
  209.                DWORD dwButtonStyle = 0);
  210.  
  211.     void SetStyle(DWORD dwButtonStyle);
  212.     void SetText(LPCTSTR pButtonText);
  213.     const char *GetToolTipText(void) { return m_pToolTipText; }
  214.     void SetToolTipText(LPCSTR pToolTipText);
  215.  
  216.     void SetStatusText(LPCSTR pStatusText);
  217.  
  218.     void SetBitmap(HBITMAP hBmpImg, BOOL bParentOwns);
  219.     void ReplaceBitmap(UINT nBitmapID, UINT nBitmapIndex);
  220.     void ReplaceBitmap(LPCTSTR pBitmapFile);
  221.     void ReplaceBitmap(HBITMAP hBmpImg, UINT nBitmapIndex, BOOL bParentOwns);
  222.     void ReplaceBitmapIndex(UINT nBitmapIndex);
  223.  
  224.     virtual void DrawCustomIcon(HDC hDC, int x, int y) {};
  225.     virtual void DrawLocalIcon(HDC hDC, int x, int y) {};
  226.     virtual CSize GetButtonSize(void);
  227.     virtual CSize GetRequiredButtonSize(void);
  228.     virtual CSize GetButtonSizeFromChars(CString s, int c);
  229.     virtual CSize GetMaximalButtonSize(void);
  230.     virtual CSize GetMinimalButtonSize(void);
  231.  
  232.     BOOL AtMinimalSize(void);
  233.     BOOL AtMaximalSize(void);
  234.  
  235.     virtual void CheckForMinimalSize(void);
  236.     virtual void CheckForMaximalSize(void);
  237.  
  238.     BOOL IsResourceID(void) { return m_bIsResourceID; }
  239.     UINT GetBitmapID(void) { return m_nBitmapID; }
  240.     UINT GetBitmapIndex(void) { return m_nBitmapIndex; }
  241.     LPCTSTR GetBitmapFile(void) { return m_pBitmapFile; }
  242.     CSize GetBitmapSize(void) { return m_bitmapSize; }
  243.     int     GetMaxTextCharacters(void) { return m_nMaxTextChars; }
  244.     int GetMinTextCharacters(void) { return m_nMinTextChars; }
  245.  
  246.     BOOL NeedsUpdate(void) { return m_bNeedsUpdate; }
  247.  
  248.     void Enable(BOOL bEnabled) { m_bEnabled = bEnabled; }
  249.     BOOL IsEnabled(void) { return m_bEnabled; }
  250.  
  251.     void SetCheck(int nCheck);
  252.     int  GetCheck(void);
  253.  
  254.     void SetPicturesOnly(int bPicturesOnly);
  255.     void SetButtonMode(int nToolbarStyle);
  256.     void SetState(BTN_STATE eState) { m_eState = eState; }
  257.     void SetMenuShowing(BOOL bMenuShowing) {m_bMenuShowing = bMenuShowing; }
  258.  
  259.     void SetBitmapSize(CSize sizeImage);
  260.     void SetButtonSize(CSize buttonSize);
  261.  
  262.     void SetDropTarget(CToolbarButtonDropTarget *pDropTarget);
  263.     CMenu & GetButtonMenu(void) { return m_menu; }
  264.     UINT GetButtonCommand(void) { return m_nCommand; }
  265.     void SetButtonCommand(UINT nCommand);
  266.  
  267.     virtual void OnAction(void) { }
  268.     virtual void FillInOleDataSource(COleDataSource *pDataSource) {}
  269.     
  270.     void FillInButtonData(LPBUTTONITEM button);
  271.  
  272.     BOOL OnCommand(UINT wParam,LONG lParam);
  273.     virtual BOOL OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult );
  274.  
  275.     virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  276.  
  277.     //called when a button is being dragged
  278.     void ButtonDragged(void);
  279.     
  280.     void SetDoOnButtonDown(BOOL bDoOnButtonDown) {m_bDoOnButtonDown = bDoOnButtonDown;}
  281.     BOOL IsDoOnButtonDown() {return m_bDoOnButtonDown;}
  282.  
  283.     void AddTextEdit(void);
  284.     void RemoveTextEdit(void);
  285.     void SetTextEditText(char *pText);
  286.     char *GetTextEditText(void);
  287.     virtual void EditTextChanged(char *pText);
  288.  
  289.     void SetCustomColors(COLORREF textColor, COLORREF bgColor) { hasCustomBGColor = hasCustomTextColor = TRUE; customTextColor = textColor; customBGColor = bgColor; }
  290.     virtual void UpdateIconInfo() {}
  291.  
  292. protected:
  293.     virtual void DrawPicturesAndTextMode(HDC hDC, CRect rect);
  294.     virtual void DrawPicturesMode(HDC hDC, CRect rect);
  295.     virtual void DrawTextMode(HDC hDC, CRect rect);
  296.     virtual void DrawBitmapOnTop(HDC hDC, CRect rect);
  297.     virtual void DrawBitmapOnSide(HDC hDC, CRect rect);
  298.     virtual void DrawTextOnly(HDC hDC, CRect rect);
  299.     virtual void DrawButtonBitmap(HDC hDC, CRect rcImg);
  300.     virtual void DrawButtonText(HDC hDC, CRect rcTxt, CSize sizeTxt, CString strTxt);
  301.     virtual CSize GetBitmapOnTopSize(CString s, int c);
  302.     virtual CSize GetBitmapOnSideSize(CString s, int c);
  303.     virtual CSize GetBitmapOnlySize(void);
  304.     virtual CSize GetTextOnlySize(CString s, int c);
  305.     virtual void DrawUpButton(HDC hDC, CRect & rect);
  306.     virtual void DrawDownButton(HDC hDC, CRect & rect);
  307.     virtual void DrawCheckedButton(HDC hDC, CRect & rect);
  308.     virtual void RemoveButtonFocus(void);
  309.     virtual BOOL CreateRightMouseMenu(void);
  310.     virtual void DisplayAndTrackMenu(void);
  311.     virtual CWnd* GetMenuParent(void);
  312.     virtual void GetTextRect(CRect &rect);
  313.     virtual void GetPicturesAndTextModeTextRect(CRect &rect);
  314.     virtual void GetPicturesModeTextRect(CRect &rect);
  315.     virtual void GetTextModeTextRect(CRect &rect);
  316.     virtual void GetBitmapOnTopTextRect(CRect &rect);
  317.     virtual void GetTextOnlyTextRect(CRect &rect);
  318.     virtual void GetBitmapOnSideTextRect(CRect &rect);
  319.  
  320.     virtual CPoint RequestMenuPlacement()
  321.     {
  322.         CPoint point(0, GetRequiredButtonSize().cy);
  323.         ClientToScreen(&point);
  324.         return point;
  325.     }
  326.  
  327.     // Generated message map functions
  328.     //{{AFX_MSG(CToolbarButton)
  329.     afx_msg void OnPaint();
  330.     virtual afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  331.     virtual afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  332.     afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  333.     virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  334.     afx_msg UINT OnGetDlgCode( );
  335.     afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
  336.     afx_msg void OnShowWindow( BOOL bShow, UINT nStatus );
  337.     afx_msg BOOL OnEraseBkgnd( CDC* pDC );
  338.     afx_msg void OnCaptureChanged( CWnd* pWnd );
  339.     afx_msg LRESULT OnToolTipNeedText(WPARAM, LPARAM);
  340.     virtual afx_msg void OnTimer( UINT  nIDEvent );
  341.     afx_msg LRESULT OnDragMenuOpen(WPARAM, LPARAM);
  342.     afx_msg LRESULT OnDraggingOnButton(WPARAM, LPARAM);
  343.     afx_msg void OnPaletteChanged( CWnd* pFocusWnd );
  344.     afx_msg void OnSysColorChange();
  345.     afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
  346.  
  347.     //}}AFX_MSG
  348.     DECLARE_MESSAGE_MAP()
  349.  
  350.  
  351. };
  352.  
  353.  
  354. // This class represents a toolbar button that can be dragged via drag and drop
  355. class CDragableToolbarButton: public CToolbarButton {
  356.  
  357. private:
  358.     BOOL    m_bDragging;        //Are we being dragged
  359.     CPoint  m_draggingPoint;    //The original point when we started dragging
  360.  
  361. public:
  362.     CDragableToolbarButton();
  363.  
  364.     virtual void FillInOleDataSource(COleDataSource *pDataSource) = 0;
  365.  
  366. protected:
  367.     // Generated message map functions
  368.     //{{AFX_MSG(CDragableToolbarButton)
  369.     virtual afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  370.     virtual afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  371.     virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  372.     virtual afx_msg void OnTimer( UINT  nIDEvent );
  373.  
  374.     //}}AFX_MSG
  375.     DECLARE_MESSAGE_MAP()
  376.  
  377.  
  378. };
  379.  
  380. // This class represents a toolbar button that cannot be dragged via drag and drop
  381. class CStationaryToolbarButton: public CToolbarButton {
  382.  
  383. public:
  384.     CStationaryToolbarButton() {}
  385.  
  386.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  387.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  388.                LPCTSTR pStatusText, UINT nBitmapID, UINT nBitmapIndex,
  389.                CSize m_bitmapSize, BOOL bNeedsUpdate, UINT nCommand, int nMaxTextChars, 
  390.                DWORD dwButtonStyle = 0, int nMinTextChars = 0);
  391.  
  392.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  393.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  394.                LPCTSTR pStatusText, LPCTSTR pBitmapFile,
  395.                CSize m_bitmapSize, BOOL bNeedsUpdate, UINT nCommand, int nMaxTextChars, 
  396.                DWORD dwButtonStyle = 0, int nMinTextChars = 0);
  397.  
  398. protected:
  399.     // Generated message map functions
  400.     //{{AFX_MSG(CStationaryToolbarButton)
  401.     virtual afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  402.     virtual afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  403.     virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  404.     //}}AFX_MSG
  405.     DECLARE_MESSAGE_MAP()
  406.  
  407. };
  408.  
  409.  
  410.  
  411. class CCommandToolbarButton: public CStationaryToolbarButton {
  412.  
  413. private:
  414.     CWnd *m_pActionOwner;
  415.  
  416. public:
  417.     CCommandToolbarButton(); 
  418.  
  419.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  420.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  421.                LPCTSTR pStatusText, UINT nBitmapID, UINT nBitmapIndex,
  422.                CSize m_bitmapSize, UINT nCommand, int nMaxTextChars, DWORD dwButtonStyle = 0, int nMinTextChars = 0);
  423.  
  424.     int Create(CWnd *pParent, int nToolbarStyle, CSize noviceButtonSize, CSize advancedButtonSize,
  425.                LPCTSTR pButtonText, LPCTSTR pToolTipText, 
  426.                LPCTSTR pStatusText, LPCTSTR pBitmapFile,
  427.                CSize m_bitmapSize, UINT nCommand, int nMaxTextChars, DWORD dwButtonStyle = 0, int nMinTextChars = 0);
  428.  
  429.     virtual void OnAction(void);
  430.  
  431.     virtual void FillInOleDataSource(COleDataSource *pDataSource);
  432.     //Actions will be sent to this owner.  If this function is not used then the
  433.     //message will go to the owner frame.
  434.     virtual void SetActionMessageOwner(CWnd *pActionOwner);
  435. };
  436.  
  437. void WFE_ParseButtonString(UINT nID, CString &statusStr, CString &toolTipStr, CString &textStr);
  438. #endif
  439.