]>
Commit | Line | Data |
---|---|---|
10b959e3 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbarbase.h | |
3 | // Purpose: Base class for toolbar classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_TBARBASE_H_ |
13 | #define _WX_TBARBASE_H_ | |
10b959e3 JS |
14 | |
15 | #ifdef __GNUG__ | |
16 | #pragma interface "tbarbase.h" | |
17 | #endif | |
18 | ||
34138703 | 19 | #include "wx/setup.h" |
10b959e3 JS |
20 | #include "wx/defs.h" |
21 | ||
10b959e3 JS |
22 | #include "wx/bitmap.h" |
23 | #include "wx/list.h" | |
24 | #include "wx/control.h" | |
25 | ||
f39f9220 | 26 | WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr; |
10b959e3 JS |
27 | WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize; |
28 | WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition; | |
29 | ||
30 | #define wxTOOL_STYLE_BUTTON 1 | |
31 | #define wxTOOL_STYLE_SEPARATOR 2 | |
32 | ||
4fcd73bd RR |
33 | #ifdef __WXGTK__ |
34 | class WXDLLEXPORT wxToolBar; | |
35 | #endif | |
36 | ||
10b959e3 JS |
37 | class WXDLLEXPORT wxToolBarTool: public wxObject |
38 | { | |
39 | DECLARE_DYNAMIC_CLASS(wxToolBarTool) | |
40 | public: | |
4fcd73bd RR |
41 | wxToolBarTool() {} |
42 | #ifdef __WXGTK__ | |
b02da6b1 | 43 | wxToolBarTool(wxToolBar *owner, |
4fcd73bd | 44 | int theIndex = 0, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap, |
b02da6b1 | 45 | bool toggle = FALSE, wxObject *clientData = (wxObject *) NULL, |
4fcd73bd | 46 | const wxString& shortHelpString = "", const wxString& longHelpString = "", |
85eb36c2 | 47 | GtkWidget *pixmap = (GtkWidget *) NULL ); |
4fcd73bd | 48 | #else |
dbdb39b2 | 49 | wxToolBarTool(int theIndex, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap, |
debe6624 | 50 | bool toggle = FALSE, long xPos = -1, long yPos = -1, |
62448488 | 51 | const wxString& shortHelpString = wxEmptyString, const wxString& longHelpString = wxEmptyString); |
4fcd73bd | 52 | #endif |
10b959e3 | 53 | ~wxToolBarTool (); |
debe6624 | 54 | inline void SetSize( long w, long h ) { m_width = w; m_height = h; } |
10b959e3 JS |
55 | inline long GetWidth () const { return m_width; } |
56 | inline long GetHeight () const { return m_height; } | |
57 | ||
58 | public: | |
59 | int m_toolStyle; | |
60 | wxObject * m_clientData; | |
61 | int m_index; | |
81d66cf3 JS |
62 | long m_x; |
63 | long m_y; | |
64 | long m_width; | |
65 | long m_height; | |
10b959e3 JS |
66 | bool m_toggleState; |
67 | bool m_isToggle; | |
68 | bool m_deleteSecondBitmap; | |
69 | bool m_enabled; | |
70 | wxBitmap m_bitmap1; | |
71 | wxBitmap m_bitmap2; | |
72 | bool m_isMenuCommand; | |
73 | wxString m_shortHelpString; | |
74 | wxString m_longHelpString; | |
4fcd73bd RR |
75 | #ifdef __WXGTK__ |
76 | wxToolBar *m_owner; | |
77 | GtkWidget *m_item; | |
85eb36c2 | 78 | GtkWidget *m_pixmap; |
4fcd73bd | 79 | #endif |
10b959e3 JS |
80 | }; |
81 | ||
82 | class WXDLLEXPORT wxToolBarBase : public wxControl | |
83 | { | |
81d66cf3 | 84 | DECLARE_ABSTRACT_CLASS(wxToolBarBase) |
10b959e3 JS |
85 | public: |
86 | ||
b02da6b1 VZ |
87 | wxToolBarBase(); |
88 | ~wxToolBarBase(); | |
10b959e3 JS |
89 | |
90 | // Handle wxToolBar events | |
91 | ||
92 | // Only allow toggle if returns TRUE. Call when left button up. | |
93 | virtual bool OnLeftClick(int toolIndex, bool toggleDown); | |
94 | ||
95 | // Call when right button down. | |
96 | virtual void OnRightClick(int toolIndex, long x, long y); | |
97 | ||
98 | // Called when the mouse cursor enters a tool bitmap. | |
99 | // Argument is -1 if mouse is exiting the toolbar. | |
100 | virtual void OnMouseEnter(int toolIndex); | |
101 | ||
102 | // If pushedBitmap is NULL, a reversed version of bitmap is | |
103 | // created and used as the pushed/toggled image. | |
104 | // If toggle is TRUE, the button toggles between the two states. | |
debe6624 JS |
105 | virtual wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap, |
106 | bool toggle = FALSE, long xPos = -1, long yPos = -1, wxObject *clientData = NULL, | |
62448488 | 107 | const wxString& helpString1 = wxEmptyString, const wxString& helpString2 = wxEmptyString); |
b02da6b1 VZ |
108 | virtual void AddSeparator(); |
109 | virtual void ClearTools(); | |
10b959e3 | 110 | |
debe6624 JS |
111 | virtual void EnableTool(int toolIndex, bool enable); |
112 | virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on | |
113 | virtual void SetToggle(int toolIndex, bool toggle); // Set this to be togglable (or not) | |
114 | virtual wxObject *GetToolClientData(int index) const; | |
b02da6b1 | 115 | inline wxList& GetTools() const { return (wxList&) m_tools; } |
10b959e3 JS |
116 | |
117 | // After the toolbar has initialized, this is the size the tools take up | |
118 | #if WXWXIN_COMPATIBILITY | |
119 | inline void GetMaxSize ( long * width, long * height ) const | |
120 | { wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; } | |
121 | #endif | |
122 | virtual wxSize GetMaxSize ( void ) const; | |
123 | ||
debe6624 JS |
124 | virtual bool GetToolState(int toolIndex) const; |
125 | virtual bool GetToolEnabled(int toolIndex) const; | |
126 | virtual wxToolBarTool *FindToolForPosition(long x, long y) const; | |
10b959e3 | 127 | |
debe6624 JS |
128 | virtual void SetToolShortHelp(int toolIndex, const wxString& helpString); |
129 | virtual wxString GetToolShortHelp(int toolIndex) const; | |
130 | virtual void SetToolLongHelp(int toolIndex, const wxString& helpString); | |
131 | virtual wxString GetToolLongHelp(int toolIndex) const; | |
10b959e3 | 132 | |
debe6624 | 133 | virtual void SetMargins(int x, int y); |
81d66cf3 | 134 | inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); } |
debe6624 JS |
135 | virtual void SetToolPacking(int packing); |
136 | virtual void SetToolSeparation(int separation); | |
10b959e3 | 137 | |
b02da6b1 VZ |
138 | inline virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); } |
139 | inline virtual int GetToolPacking() { return m_toolPacking; } | |
140 | inline virtual int GetToolSeparation() { return m_toolSeparation; } | |
10b959e3 | 141 | |
81d66cf3 | 142 | virtual void SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; }; |
b02da6b1 | 143 | virtual wxSize GetToolBitmapSize() const { return wxSize(m_defaultWidth, m_defaultHeight); } |
10b959e3 JS |
144 | |
145 | // The button size (in some implementations) is bigger than the bitmap size: this returns | |
146 | // the total button size. | |
b02da6b1 | 147 | virtual wxSize GetToolSize() const { return wxSize(m_defaultWidth, m_defaultHeight); } ; |
10b959e3 JS |
148 | |
149 | // Compatibility | |
150 | #if WXWIN_COMPATIBILITY | |
b02da6b1 VZ |
151 | void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); } |
152 | long GetDefaultWidth() const { return m_defaultWidth; } | |
153 | long GetDefaultHeight() const { return m_defaultHeight; } | |
154 | int GetDefaultButtonWidth() const { return (int) GetDefaultButtonSize().x; }; | |
155 | int GetDefaultButtonHeight() const { return (int) GetDefaultButtonSize().y; }; | |
81d66cf3 | 156 | virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); } |
b02da6b1 VZ |
157 | virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); } |
158 | virtual wxSize GetDefaultButtonSize() const { return GetToolSize(); } | |
10b959e3 JS |
159 | #endif |
160 | ||
161 | // Lay the tools out | |
f03fc89f | 162 | virtual void LayoutTools(); |
b02da6b1 | 163 | |
10b959e3 | 164 | // Add all the buttons: required for Win95. |
b02da6b1 | 165 | virtual bool CreateTools() { return TRUE; } |
10b959e3 | 166 | |
81d66cf3 JS |
167 | // Calls the appropriate function after tools have been created. |
168 | // E.g. Layout, or CreateTools. | |
169 | virtual bool Realize() = 0; | |
170 | ||
10b959e3 JS |
171 | void Command(wxCommandEvent& event); |
172 | ||
173 | // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase | |
174 | // inherits from wxControl. This could have been put into wxToolBarSimple, | |
175 | // but we might want any derived toolbar class to be scrollable. | |
176 | ||
177 | // Number of pixels per user unit (0 or -1 for no scrollbar) | |
178 | // Length of virtual canvas in user units | |
debe6624 JS |
179 | virtual void SetScrollbars(int horizontal, int vertical, |
180 | int x_length, int y_length, | |
181 | int x_pos = 0, int y_pos = 0); | |
10b959e3 JS |
182 | |
183 | // Physically scroll the window | |
debe6624 | 184 | virtual void Scroll(int x_pos, int y_pos); |
10b959e3 | 185 | virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const; |
debe6624 | 186 | virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); |
b02da6b1 | 187 | virtual void AdjustScrollbars(); |
10b959e3 JS |
188 | |
189 | // Prepare the DC by translating it according to the current scroll position | |
190 | virtual void PrepareDC(wxDC& dc); | |
191 | ||
192 | int GetScrollPageSize(int orient) const ; | |
193 | void SetScrollPageSize(int orient, int pageSize); | |
194 | ||
195 | // Get the view start | |
196 | virtual void ViewStart(int *x, int *y) const; | |
197 | ||
198 | // Actual size in pixels when scrolling is taken into account | |
199 | virtual void GetVirtualSize(int *x, int *y) const; | |
200 | ||
201 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
b02da6b1 | 202 | virtual void DoToolbarUpdates(); |
10b959e3 | 203 | |
81d66cf3 JS |
204 | inline void SetMaxRowsCols(int rows, int cols) { m_maxRows = rows; m_maxCols = cols; } |
205 | inline int GetMaxRows() const { return m_maxRows; } | |
206 | inline int GetMaxCols() const { return m_maxCols; } | |
10b959e3 JS |
207 | |
208 | void OnScroll(wxScrollEvent& event); | |
209 | void OnSize(wxSizeEvent& event); | |
210 | void OnIdle(wxIdleEvent& event); | |
211 | ||
10b959e3 JS |
212 | protected: |
213 | wxList m_tools; | |
81d66cf3 JS |
214 | // int m_tilingDirection; |
215 | // int m_rowsOrColumns; | |
216 | int m_maxRows; | |
217 | int m_maxCols; | |
10b959e3 JS |
218 | long m_maxWidth, m_maxHeight; |
219 | int m_currentTool; // Tool where mouse currently is | |
220 | int m_pressedTool; // Tool where mouse pressed | |
221 | int m_xMargin; | |
222 | int m_yMargin; | |
223 | int m_toolPacking; | |
224 | int m_toolSeparation; | |
b02da6b1 VZ |
225 | |
226 | wxCoord m_defaultWidth; | |
227 | wxCoord m_defaultHeight; | |
10b959e3 JS |
228 | |
229 | public: | |
230 | //////////////////////////////////////////////////////////////////////// | |
231 | //// IMPLEMENTATION | |
b02da6b1 | 232 | |
10b959e3 JS |
233 | // Calculate scroll increment |
234 | virtual int CalcScrollInc(wxScrollEvent& event); | |
235 | ||
236 | //////////////////////////////////////////////////////////////////////// | |
237 | //// PROTECTED DATA | |
238 | protected: | |
239 | int m_xScrollPixelsPerLine; | |
240 | int m_yScrollPixelsPerLine; | |
241 | bool m_xScrollingEnabled; | |
242 | bool m_yScrollingEnabled; | |
243 | int m_xScrollPosition; | |
244 | int m_yScrollPosition; | |
245 | bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets | |
246 | int m_xScrollLines; | |
247 | int m_yScrollLines; | |
248 | int m_xScrollLinesPerPage; | |
249 | int m_yScrollLinesPerPage; | |
250 | ||
251 | public: | |
252 | DECLARE_EVENT_TABLE() | |
253 | }; | |
254 | ||
10b959e3 | 255 | #endif |
34138703 | 256 | // _WX_TBARBASE_H_ |
10b959e3 | 257 |