1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/msw/tbar95.h
3 // Purpose:     wxToolBar (Windows 95 toolbar) class
4 // Author:      Julian Smart
5 // Modified by:
6 // Created:     01/02/97
7 // RCS-ID:      $Id: tbar95.h 58446 2009-01-26 23:32:16Z VS $
8 // Copyright:   (c) Julian Smart
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_MSW_TBAR95_H_
13 #define _WX_MSW_TBAR95_H_
14 
15 #if wxUSE_TOOLBAR
16 
17 #include "wx/dynarray.h"
18 #include "wx/imaglist.h"
19 
20 class WXDLLEXPORT wxToolBar : public wxToolBarBase
21 {
22 public:
23     // ctors and dtor
wxToolBar()24     wxToolBar() { Init(); }
25 
26     wxToolBar(wxWindow *parent,
27                 wxWindowID id,
28                 const wxPoint& pos = wxDefaultPosition,
29                 const wxSize& size = wxDefaultSize,
30                 long style = wxNO_BORDER | wxTB_HORIZONTAL,
31                 const wxString& name = wxToolBarNameStr)
32     {
33         Init();
34 
35         Create(parent, id, pos, size, style, name);
36     }
37 
38     bool Create(wxWindow *parent,
39                 wxWindowID id,
40                 const wxPoint& pos = wxDefaultPosition,
41                 const wxSize& size = wxDefaultSize,
42                 long style = wxNO_BORDER | wxTB_HORIZONTAL,
43                 const wxString& name = wxToolBarNameStr);
44 
45     virtual ~wxToolBar();
46 
47     // override/implement base class virtuals
48     virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
49 
50     virtual bool Realize();
51 
52     virtual void SetToolBitmapSize(const wxSize& size);
53     virtual wxSize GetToolSize() const;
54 
55     virtual void SetRows(int nRows);
56 
57 #if wxABI_VERSION >= 20802
58     // TODO: In 2.9 these should probably be virtual, and declared in the base class...
59     void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
60     void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
61 #endif
62 
63     // implementation only from now on
64     // -------------------------------
65 
66     virtual void SetWindowStyleFlag(long style);
67 
68     virtual bool MSWCommand(WXUINT param, WXWORD id);
69     virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
70 
71     void OnMouseEvent(wxMouseEvent& event);
72     void OnSysColourChanged(wxSysColourChangedEvent& event);
73     void OnEraseBackground(wxEraseEvent& event);
74 
SetFocus()75     void SetFocus() {}
76 
77     static WXHBITMAP MapBitmap(WXHBITMAP bitmap, int width, int height);
78 
79     // override WndProc mainly to process WM_SIZE
80     virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
81 
82     virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
83 
84 protected:
85     // common part of all ctors
86     void Init();
87 
88     // create the native toolbar control
89     bool MSWCreateToolbar(const wxPoint& pos, const wxSize& size);
90 
91     // recreate the control completely
92     void Recreate();
93 
94     // implement base class pure virtuals
95     virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
96     virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
97 
98     virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
99     virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
100     virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
101 
102     virtual wxToolBarToolBase *CreateTool(int id,
103                                           const wxString& label,
104                                           const wxBitmap& bmpNormal,
105                                           const wxBitmap& bmpDisabled,
106                                           wxItemKind kind,
107                                           wxObject *clientData,
108                                           const wxString& shortHelp,
109                                           const wxString& longHelp);
110     virtual wxToolBarToolBase *CreateTool(wxControl *control);
111 
112     // return the appropriate size and flags for the toolbar control
113     virtual wxSize DoGetBestSize() const;
114 
115     // handlers for various events
116     bool HandleSize(WXWPARAM wParam, WXLPARAM lParam);
117     bool HandlePaint(WXWPARAM wParam, WXLPARAM lParam);
118     void HandleMouseMove(WXWPARAM wParam, WXLPARAM lParam);
119 
120     // should be called whenever the toolbar size changes
121     void UpdateSize();
122 
123     // create m_disabledImgList (but doesn't fill it), set it to NULL if it is
124     // unneeded
125     void CreateDisabledImageList();
126 
127     // get the Windows toolbar style of this control
128     long GetMSWToolbarStyle() const;
129 
130 
131     // the big bitmap containing all bitmaps of the toolbar buttons
132     WXHBITMAP m_hBitmap;
133 
134     // the image list with disabled images, may be NULL if we use
135     // system-provided versions of them
136     wxImageList *m_disabledImgList;
137 
138     // the total number of toolbar elements
139     size_t m_nButtons;
140 
141     // the tool the cursor is in
142     wxToolBarToolBase *m_pInTool;
143 
144 private:
145     // makes sure tool bitmap size is sufficient for all tools
146     void AdjustToolBitmapSize();
147 
148     DECLARE_EVENT_TABLE()
149     DECLARE_DYNAMIC_CLASS(wxToolBar)
150     DECLARE_NO_COPY_CLASS(wxToolBar)
151 };
152 
153 #endif // wxUSE_TOOLBAR
154 
155 #endif // _WX_MSW_TBAR95_H_
156 
157