]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
test
[wxWidgets.git] / include / wx / tbarbase.h
CommitLineData
10b959e3 1/////////////////////////////////////////////////////////////////////////////
6d167489 2// Name: wx/tbarbase.h
10b959e3
JS
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
1c383dba 9// Licence: wxWindows licence
10b959e3
JS
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_TBARBASE_H_
13#define _WX_TBARBASE_H_
10b959e3 14
1c383dba
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
10b959e3 19#ifdef __GNUG__
1c383dba 20 #pragma interface "tbarbase.h"
10b959e3
JS
21#endif
22
23#include "wx/defs.h"
24
10b959e3
JS
25#include "wx/bitmap.h"
26#include "wx/list.h"
27#include "wx/control.h"
28
1c383dba
VZ
29class WXDLLEXPORT wxToolBar;
30
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
34
f39f9220 35WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
10b959e3
JS
36WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
37WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
38
1c383dba
VZ
39enum
40{
41 wxTOOL_STYLE_BUTTON = 1,
42 wxTOOL_STYLE_SEPARATOR = 2,
43 wxTOOL_STYLE_CONTROL
44};
10b959e3 45
1c383dba
VZ
46// ----------------------------------------------------------------------------
47// wxToolBarTool is one button/separator/whatever in the toolbar
48// ----------------------------------------------------------------------------
4fcd73bd 49
1c383dba 50class WXDLLEXPORT wxToolBarTool : public wxObject
10b959e3 51{
1c383dba
VZ
52public:
53 // ctors & dtor
54 // ------------
55
56 wxToolBarTool() { }
57
4fcd73bd 58#ifdef __WXGTK__
1c383dba
VZ
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 }
10b959e3
JS
97
98public:
1c383dba
VZ
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
4fcd73bd 126#ifdef __WXGTK__
1c383dba
VZ
127 wxToolBar *m_owner;
128 GtkWidget *m_item;
129 GtkWidget *m_pixmap;
130#endif // GTK
131
132private:
133 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
10b959e3
JS
134};
135
1c383dba
VZ
136// ----------------------------------------------------------------------------
137// the base class for all toolbars
138// ----------------------------------------------------------------------------
139
10b959e3
JS
140class WXDLLEXPORT wxToolBarBase : public wxControl
141{
1c383dba
VZ
142public:
143 wxToolBarBase();
144 ~wxToolBarBase();
10b959e3 145
1c383dba
VZ
146 // toolbar construction
147 // --------------------
10b959e3 148
1c383dba
VZ
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);
10b959e3 161
1c383dba
VZ
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
f76dbc4d 167 virtual bool AddControl(wxControl * WXUNUSED(control)) { return FALSE; }
10b959e3 168
1c383dba
VZ
169 virtual void AddSeparator();
170 virtual void ClearTools();
10b959e3 171
1c383dba
VZ
172 // must be called after all buttons have been created to finish toolbar
173 // initialisation
174 virtual bool Realize() = 0;
10b959e3 175
1c383dba
VZ
176 // tools state
177 // -----------
10b959e3 178
1c383dba 179 virtual void EnableTool(int toolIndex, bool enable);
10b959e3 180
1c383dba
VZ
181 // toggle is TRUE if toggled on
182 virtual void ToggleTool(int toolIndex, bool toggle);
b02da6b1 183
1c383dba
VZ
184 // Set this to be togglable (or not)
185 virtual void SetToggle(int toolIndex, bool toggle);
186 virtual wxObject *GetToolClientData(int index) const;
10b959e3 187
1c383dba
VZ
188 virtual bool GetToolState(int toolIndex) const;
189 virtual bool GetToolEnabled(int toolIndex) const;
190 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
81d66cf3 191
1c383dba
VZ
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;
10b959e3 196
1c383dba
VZ
197 // margins/packing/separation
198 // --------------------------
10b959e3 199
1c383dba
VZ
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);
10b959e3 205
1c383dba
VZ
206 virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
207 virtual int GetToolPacking() { return m_toolPacking; }
208 virtual int GetToolSeparation() { return m_toolSeparation; }
10b959e3 209
1c383dba
VZ
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; }
10b959e3 214
1c383dba
VZ
215 // tool(bar) size
216 // -------------
10b959e3 217
1c383dba
VZ
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); }
10b959e3 222
1c383dba
VZ
223 // After the toolbar has initialized, this is the size the tools take up
224 virtual wxSize GetMaxSize() const;
10b959e3 225
1c383dba
VZ
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); } ;
10b959e3 230
1c383dba
VZ
231 // Handle wxToolBar events
232 // -----------------------
10b959e3 233
1c383dba 234 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
10b959e3 235
1c383dba
VZ
236 // Only allow toggle if returns TRUE. Call when left button up.
237 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
b02da6b1 238
1c383dba
VZ
239 // Call when right button down.
240 virtual void OnRightClick(int toolIndex, long x, long y);
10b959e3 241
1c383dba
VZ
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();
b02da6b1 290
1c383dba
VZ
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);
10b959e3 310
10b959e3 311protected:
1c383dba
VZ
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;
10b959e3
JS
329
330public:
1c383dba
VZ
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:
10b959e3 353 DECLARE_EVENT_TABLE()
1c383dba 354 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
10b959e3
JS
355};
356
10b959e3 357#endif
34138703 358 // _WX_TBARBASE_H_
10b959e3 359