]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/tbarbase.h
test
[wxWidgets.git] / include / wx / tbarbase.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/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
12#ifndef _WX_TBARBASE_H_
13#define _WX_TBARBASE_H_
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#ifdef __GNUG__
20 #pragma interface "tbarbase.h"
21#endif
22
23#include "wx/defs.h"
24
25#include "wx/bitmap.h"
26#include "wx/list.h"
27#include "wx/control.h"
28
29class WXDLLEXPORT wxToolBar;
30
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
34
35WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
36WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
37WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
38
39enum
40{
41 wxTOOL_STYLE_BUTTON = 1,
42 wxTOOL_STYLE_SEPARATOR = 2,
43 wxTOOL_STYLE_CONTROL
44};
45
46// ----------------------------------------------------------------------------
47// wxToolBarTool is one button/separator/whatever in the toolbar
48// ----------------------------------------------------------------------------
49
50class WXDLLEXPORT wxToolBarTool : public wxObject
51{
52public:
53 // ctors & dtor
54 // ------------
55
56 wxToolBarTool() { }
57
58#ifdef __WXGTK__
59 wxToolBarTool(wxToolBar *owner,
60 int theIndex = 0,
61 const wxBitmap& bitmap1 = wxNullBitmap,
62 const wxBitmap& bitmap2 = wxNullBitmap,
63 bool toggle = FALSE,
64 wxObject *clientData = (wxObject *) NULL,
65 const wxString& shortHelpString = wxEmptyString,
66 const wxString& longHelpString = wxEmptyString,
67 GtkWidget *pixmap = (GtkWidget *) NULL );
68#else // !GTK
69 wxToolBarTool(int theIndex,
70 const wxBitmap& bitmap1 = wxNullBitmap,
71 const wxBitmap& bitmap2 = wxNullBitmap,
72 bool toggle = FALSE,
73 long xPos = -1,
74 long yPos = -1,
75 const wxString& shortHelpString = wxEmptyString,
76 const wxString& longHelpString = wxEmptyString);
77#endif // GTK/!GTK
78
79 wxToolBarTool(wxControl *control);
80
81 ~wxToolBarTool();
82
83 // accessors
84 // ---------
85
86 void SetSize( long w, long h ) { m_width = w; m_height = h; }
87 long GetWidth() const { return m_width; }
88 long GetHeight() const { return m_height; }
89
90 wxControl *GetControl() const
91 {
92 wxASSERT_MSG( m_toolStyle == wxTOOL_STYLE_CONTROL,
93 _T("this toolbar tool is not a control") );
94
95 return m_control;
96 }
97
98public:
99 int m_toolStyle;
100 int m_index;
101
102 // as controls have their own client data, no need to waste memory
103 union
104 {
105 wxObject *m_clientData;
106 wxControl *m_control;
107 };
108
109 wxCoord m_x;
110 wxCoord m_y;
111 wxCoord m_width;
112 wxCoord m_height;
113
114 bool m_toggleState;
115 bool m_isToggle;
116 bool m_enabled;
117 bool m_isMenuCommand;
118
119 bool m_deleteSecondBitmap;
120 wxBitmap m_bitmap1;
121 wxBitmap m_bitmap2;
122
123 wxString m_shortHelpString;
124 wxString m_longHelpString;
125
126#ifdef __WXGTK__
127 wxToolBar *m_owner;
128 GtkWidget *m_item;
129 GtkWidget *m_pixmap;
130#endif // GTK
131
132private:
133 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
134};
135
136// ----------------------------------------------------------------------------
137// the base class for all toolbars
138// ----------------------------------------------------------------------------
139
140class WXDLLEXPORT wxToolBarBase : public wxControl
141{
142public:
143 wxToolBarBase();
144 ~wxToolBarBase();
145
146 // toolbar construction
147 // --------------------
148
149 // If pushedBitmap is NULL, a reversed version of bitmap is created and
150 // used as the pushed/toggled image. If toggle is TRUE, the button toggles
151 // between the two states.
152 virtual wxToolBarTool *AddTool(int toolIndex,
153 const wxBitmap& bitmap,
154 const wxBitmap& pushedBitmap = wxNullBitmap,
155 bool toggle = FALSE,
156 wxCoord xPos = -1,
157 wxCoord yPos = -1,
158 wxObject *clientData = NULL,
159 const wxString& helpString1 = wxEmptyString,
160 const wxString& helpString2 = wxEmptyString);
161
162 // add an arbitrary control to the toolbar at given index, return TRUE if
163 // ok (notice that the control will be deleted by the toolbar and that it
164 // will also adjust its position/size)
165 //
166 // NB: the control should have toolbar as its parent
167 virtual bool AddControl(wxControl * WXUNUSED(control)) { return FALSE; }
168
169 virtual void AddSeparator();
170 virtual void ClearTools();
171
172 // must be called after all buttons have been created to finish toolbar
173 // initialisation
174 virtual bool Realize() = 0;
175
176 // tools state
177 // -----------
178
179 virtual void EnableTool(int toolIndex, bool enable);
180
181 // toggle is TRUE if toggled on
182 virtual void ToggleTool(int toolIndex, bool toggle);
183
184 // Set this to be togglable (or not)
185 virtual void SetToggle(int toolIndex, bool toggle);
186 virtual wxObject *GetToolClientData(int index) const;
187
188 virtual bool GetToolState(int toolIndex) const;
189 virtual bool GetToolEnabled(int toolIndex) const;
190 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
191
192 virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
193 virtual wxString GetToolShortHelp(int toolIndex) const;
194 virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
195 virtual wxString GetToolLongHelp(int toolIndex) const;
196
197 // margins/packing/separation
198 // --------------------------
199
200 virtual void SetMargins(int x, int y);
201 void SetMargins(const wxSize& size)
202 { SetMargins((int) size.x, (int) size.y); }
203 virtual void SetToolPacking(int packing);
204 virtual void SetToolSeparation(int separation);
205
206 virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
207 virtual int GetToolPacking() { return m_toolPacking; }
208 virtual int GetToolSeparation() { return m_toolSeparation; }
209
210 void SetMaxRowsCols(int rows, int cols)
211 { m_maxRows = rows; m_maxCols = cols; }
212 int GetMaxRows() const { return m_maxRows; }
213 int GetMaxCols() const { return m_maxCols; }
214
215 // tool(bar) size
216 // -------------
217
218 virtual void SetToolBitmapSize(const wxSize& size)
219 { m_defaultWidth = size.x; m_defaultHeight = size.y; };
220 virtual wxSize GetToolBitmapSize() const
221 { return wxSize(m_defaultWidth, m_defaultHeight); }
222
223 // After the toolbar has initialized, this is the size the tools take up
224 virtual wxSize GetMaxSize() const;
225
226 // The button size (in some implementations) is bigger than the bitmap size: this returns
227 // the total button size.
228 virtual wxSize GetToolSize() const
229 { return wxSize(m_defaultWidth, m_defaultHeight); } ;
230
231 // Handle wxToolBar events
232 // -----------------------
233
234 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
235
236 // Only allow toggle if returns TRUE. Call when left button up.
237 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
238
239 // Call when right button down.
240 virtual void OnRightClick(int toolIndex, long x, long y);
241
242 // Called when the mouse cursor enters a tool bitmap.
243 // Argument is -1 if mouse is exiting the toolbar.
244 virtual void OnMouseEnter(int toolIndex);
245
246 // more deprecated functions
247 // -------------------------
248
249#if WXWIN_COMPATIBILITY
250 void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
251 long GetDefaultWidth() const { return m_defaultWidth; }
252 long GetDefaultHeight() const { return m_defaultHeight; }
253 int GetDefaultButtonWidth() const { return (int) GetDefaultButtonSize().x; };
254 int GetDefaultButtonHeight() const { return (int) GetDefaultButtonSize().y; };
255 virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
256 virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); }
257 virtual wxSize GetDefaultButtonSize() const { return GetToolSize(); }
258 void GetMaxSize ( long * width, long * height ) const
259 { wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
260#endif // WXWIN_COMPATIBILITY
261
262 // implementation only from now on
263 // -------------------------------
264
265 wxList& GetTools() const { return (wxList&) m_tools; }
266
267 // Lay the tools out
268 virtual void LayoutTools();
269
270 // Add all the buttons: required for Win95.
271 virtual bool CreateTools() { return TRUE; }
272
273 void Command(wxCommandEvent& event);
274
275 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
276 // inherits from wxControl. This could have been put into wxToolBarSimple,
277 // but we might want any derived toolbar class to be scrollable.
278
279 // Number of pixels per user unit (0 or -1 for no scrollbar)
280 // Length of virtual canvas in user units
281 virtual void SetScrollbars(int horizontal, int vertical,
282 int x_length, int y_length,
283 int x_pos = 0, int y_pos = 0);
284
285 // Physically scroll the window
286 virtual void Scroll(int x_pos, int y_pos);
287 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
288 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
289 virtual void AdjustScrollbars();
290
291 // Prepare the DC by translating it according to the current scroll position
292 virtual void PrepareDC(wxDC& dc);
293
294 int GetScrollPageSize(int orient) const ;
295 void SetScrollPageSize(int orient, int pageSize);
296
297 // Get the view start
298 virtual void ViewStart(int *x, int *y) const;
299
300 // Actual size in pixels when scrolling is taken into account
301 virtual void GetVirtualSize(int *x, int *y) const;
302
303 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
304 virtual void DoToolbarUpdates();
305
306 // event handlers
307 void OnScroll(wxScrollEvent& event);
308 void OnSize(wxSizeEvent& event);
309 void OnIdle(wxIdleEvent& event);
310
311protected:
312 wxList m_tools;
313
314 int m_maxRows;
315 int m_maxCols;
316 long m_maxWidth,
317 m_maxHeight;
318
319 int m_currentTool; // Tool where mouse currently is
320 int m_pressedTool; // Tool where mouse pressed
321
322 int m_xMargin;
323 int m_yMargin;
324 int m_toolPacking;
325 int m_toolSeparation;
326
327 wxCoord m_defaultWidth;
328 wxCoord m_defaultHeight;
329
330public:
331 ////////////////////////////////////////////////////////////////////////
332 //// IMPLEMENTATION
333
334 // Calculate scroll increment
335 virtual int CalcScrollInc(wxScrollEvent& event);
336
337 ////////////////////////////////////////////////////////////////////////
338 //// PROTECTED DATA
339protected:
340 int m_xScrollPixelsPerLine;
341 int m_yScrollPixelsPerLine;
342 bool m_xScrollingEnabled;
343 bool m_yScrollingEnabled;
344 int m_xScrollPosition;
345 int m_yScrollPosition;
346 bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
347 int m_xScrollLines;
348 int m_yScrollLines;
349 int m_xScrollLinesPerPage;
350 int m_yScrollLinesPerPage;
351
352private:
353 DECLARE_EVENT_TABLE()
354 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
355};
356
357#endif
358 // _WX_TBARBASE_H_
359