]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
made the log dialog resizeable (again?)
[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
1e6feb95
VZ
25#if wxUSE_TOOLBAR
26
10b959e3
JS
27#include "wx/bitmap.h"
28#include "wx/list.h"
29#include "wx/control.h"
30
8a0681f9
VZ
31class WXDLLEXPORT wxToolBarBase;
32class WXDLLEXPORT wxToolBarToolBase;
1c383dba
VZ
33
34// ----------------------------------------------------------------------------
35// constants
36// ----------------------------------------------------------------------------
37
f39f9220 38WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
10b959e3
JS
39WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
40WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
41
8a0681f9 42enum wxToolBarToolStyle
1c383dba
VZ
43{
44 wxTOOL_STYLE_BUTTON = 1,
45 wxTOOL_STYLE_SEPARATOR = 2,
46 wxTOOL_STYLE_CONTROL
47};
10b959e3 48
1c383dba 49// ----------------------------------------------------------------------------
8a0681f9
VZ
50// wxToolBarTool is a toolbar element.
51//
52// It has a unique id (except for the separators which always have id -1), the
53// style (telling whether it is a normal button, separator or a control), the
54// state (toggled or not, enabled or not) and short and long help strings. The
55// default implementations use the short help string for the tooltip text which
56// is popped up when the mouse pointer enters the tool and the long help string
57// for the applications status bar.
1c383dba 58// ----------------------------------------------------------------------------
4fcd73bd 59
8a0681f9 60class WXDLLEXPORT wxToolBarToolBase : public wxObject
10b959e3 61{
1c383dba
VZ
62public:
63 // ctors & dtor
64 // ------------
65
8a0681f9
VZ
66 wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL,
67 int id = wxID_SEPARATOR,
68 const wxBitmap& bitmap1 = wxNullBitmap,
69 const wxBitmap& bitmap2 = wxNullBitmap,
70 bool toggle = FALSE,
71 wxObject *clientData = (wxObject *) NULL,
72 const wxString& shortHelpString = wxEmptyString,
73 const wxString& longHelpString = wxEmptyString)
74 : m_shortHelpString(shortHelpString),
75 m_longHelpString(longHelpString)
76 {
77 m_tbar = tbar;
78 m_id = id;
79 m_clientData = clientData;
80
81 m_bitmap1 = bitmap1;
82 m_bitmap2 = bitmap2;
83
84 m_isToggle = toggle;
85 m_enabled = TRUE;
86 m_toggled = FALSE;
87
88 m_toolStyle = id == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR
89 : wxTOOL_STYLE_BUTTON;
90 }
91
92 wxToolBarToolBase(wxToolBarBase *tbar, wxControl *control)
93 {
94 m_tbar = tbar;
95 m_control = control;
96 m_id = control->GetId();
97
98 m_isToggle = FALSE;
99 m_enabled = TRUE;
100 m_toggled = FALSE;
101
102 m_toolStyle = wxTOOL_STYLE_CONTROL;
103 }
104
105 ~wxToolBarToolBase();
1c383dba
VZ
106
107 // accessors
108 // ---------
109
8a0681f9
VZ
110 // general
111 int GetId() const { return m_id; }
1c383dba
VZ
112
113 wxControl *GetControl() const
114 {
8a0681f9 115 wxASSERT_MSG( IsControl(), _T("this toolbar tool is not a control") );
1c383dba
VZ
116
117 return m_control;
118 }
10b959e3 119
8a0681f9
VZ
120 wxToolBarBase *GetToolBar() const { return m_tbar; }
121
122 // style
123 int IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
124 int IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
125 int IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
126 int GetStyle() const { return m_toolStyle; }
127
128 // state
129 bool IsEnabled() const { return m_enabled; }
130 bool IsToggled() const { return m_toggled; }
131 bool CanBeToggled() const { return m_isToggle; }
132
133 // attributes
134 const wxBitmap& GetBitmap1() const { return m_bitmap1; }
135 const wxBitmap& GetBitmap2() const { return m_bitmap2; }
136
137 const wxBitmap& GetBitmap() const
138 { return IsToggled() ? m_bitmap2 : m_bitmap1; }
139
140 wxString GetShortHelp() const { return m_shortHelpString; }
141 wxString GetLongHelp() const { return m_longHelpString; }
142
143 wxObject *GetClientData() const
144 {
6fd5fa4f
VZ
145 if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
146 {
2063a4a0 147 return (wxObject*)m_control->GetClientData();
6fd5fa4f
VZ
148 }
149 else
150 {
151 return m_clientData;
152 }
8a0681f9
VZ
153 }
154
155 // modifiers: return TRUE if the state really changed
156 bool Enable(bool enable);
157 bool Toggle(bool toggle);
158 bool SetToggle(bool toggle);
159 bool SetShortHelp(const wxString& help);
160 bool SetLongHelp(const wxString& help);
161
162 void Toggle() { Toggle(!IsToggled()); }
163
164 void SetBitmap1(const wxBitmap& bmp) { m_bitmap1 = bmp; }
165 void SetBitmap2(const wxBitmap& bmp) { m_bitmap2 = bmp; }
166
6fd5fa4f
VZ
167 void SetClientData(wxObject *clientData)
168 {
169 if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
170 {
171 m_control->SetClientData(clientData);
172 }
173 else
174 {
175 m_clientData = clientData;
176 }
177 }
178
8a0681f9
VZ
179 // add tool to/remove it from a toolbar
180 virtual void Detach() { m_tbar = (wxToolBarBase *)NULL; }
181 virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
182
183protected:
184 wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
185
186 int m_toolStyle; // see enum wxToolBarToolStyle
187 int m_id; // the tool id, wxID_SEPARATOR for separator
1c383dba
VZ
188
189 // as controls have their own client data, no need to waste memory
190 union
191 {
192 wxObject *m_clientData;
193 wxControl *m_control;
194 };
195
8a0681f9
VZ
196 // tool state
197 bool m_toggled;
198 bool m_isToggle;
199 bool m_enabled;
1c383dba 200
8a0681f9
VZ
201 // normal and toggles bitmaps
202 wxBitmap m_bitmap1;
203 wxBitmap m_bitmap2;
1c383dba 204
8a0681f9
VZ
205 // short and long help strings
206 wxString m_shortHelpString;
207 wxString m_longHelpString;
10b959e3
JS
208};
209
8a0681f9 210// a list of toolbar tools
f6bcfd97 211WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
8a0681f9 212
1c383dba
VZ
213// ----------------------------------------------------------------------------
214// the base class for all toolbars
215// ----------------------------------------------------------------------------
216
10b959e3
JS
217class WXDLLEXPORT wxToolBarBase : public wxControl
218{
1c383dba
VZ
219public:
220 wxToolBarBase();
8a0681f9 221 virtual ~wxToolBarBase();
10b959e3 222
1c383dba
VZ
223 // toolbar construction
224 // --------------------
10b959e3 225
3ca6a5f0
BP
226 // the most commonly used version of AddTool()
227 wxToolBarToolBase *AddTool(int id,
228 const wxBitmap& bitmap,
229 const wxString& shortHelpString = wxEmptyString,
230 const wxString& longHelpString = wxEmptyString)
231 {
232 return AddTool(id, bitmap, wxNullBitmap, FALSE, NULL,
233 shortHelpString, longHelpString);
234 }
235
1c383dba
VZ
236 // If pushedBitmap is NULL, a reversed version of bitmap is created and
237 // used as the pushed/toggled image. If toggle is TRUE, the button toggles
238 // between the two states.
8a0681f9
VZ
239 wxToolBarToolBase *AddTool(int id,
240 const wxBitmap& bitmap,
33ac7e6f 241 const wxBitmap& pushedBitmap,
8a0681f9
VZ
242 bool toggle = FALSE,
243 wxObject *clientData = NULL,
244 const wxString& shortHelpString = wxEmptyString,
245 const wxString& longHelpString = wxEmptyString)
246 {
247 return AddTool(id, bitmap, pushedBitmap, toggle,
248 -1, -1, clientData, shortHelpString, longHelpString);
249 }
250
251 // the old version of AddTool() kept for compatibility
252 virtual wxToolBarToolBase *AddTool
253 (
254 int id,
1c383dba 255 const wxBitmap& bitmap,
8a0681f9
VZ
256 const wxBitmap& pushedBitmap,
257 bool toggle,
258 wxCoord xPos,
1c383dba
VZ
259 wxCoord yPos = -1,
260 wxObject *clientData = NULL,
261 const wxString& helpString1 = wxEmptyString,
8a0681f9
VZ
262 const wxString& helpString2 = wxEmptyString
263 );
264
265 // insert the new tool at the given position, if pos == GetToolsCount(), it
266 // is equivalent to AddTool()
267 virtual wxToolBarToolBase *InsertTool
268 (
269 size_t pos,
270 int id,
271 const wxBitmap& bitmap,
272 const wxBitmap& pushedBitmap = wxNullBitmap,
273 bool toggle = FALSE,
274 wxObject *clientData = NULL,
275 const wxString& help1 = wxEmptyString,
276 const wxString& help2 = wxEmptyString
277 );
278
279 // add an arbitrary control to the toolbar, return TRUE if ok (notice that
280 // the control will be deleted by the toolbar and that it will also adjust
281 // its position/size)
1c383dba
VZ
282 //
283 // NB: the control should have toolbar as its parent
8a0681f9
VZ
284 virtual wxToolBarToolBase *AddControl(wxControl *control);
285 virtual wxToolBarToolBase *InsertControl(size_t pos, wxControl *control);
10b959e3 286
8a0681f9
VZ
287 // add a separator to the toolbar
288 virtual wxToolBarToolBase *AddSeparator();
289 virtual wxToolBarToolBase *InsertSeparator(size_t pos);
290
291 // remove the tool from the toolbar: the caller is responsible for actually
292 // deleting the pointer
293 virtual wxToolBarToolBase *RemoveTool(int id);
294
295 // delete tool either by index or by position
296 virtual bool DeleteToolByPos(size_t pos);
297 virtual bool DeleteTool(int id);
298
299 // delete all tools
1c383dba 300 virtual void ClearTools();
10b959e3 301
1c383dba
VZ
302 // must be called after all buttons have been created to finish toolbar
303 // initialisation
8a0681f9 304 virtual bool Realize();
10b959e3 305
1c383dba
VZ
306 // tools state
307 // -----------
10b959e3 308
8a0681f9
VZ
309 virtual void EnableTool(int id, bool enable);
310 virtual void ToggleTool(int id, bool toggle);
b02da6b1 311
1c383dba 312 // Set this to be togglable (or not)
8a0681f9
VZ
313 virtual void SetToggle(int id, bool toggle);
314
6fd5fa4f
VZ
315 // set/get tools client data (not for controls)
316 virtual wxObject *GetToolClientData(int id) const;
317 virtual void SetToolClientData(int id, wxObject *clientData);
10b959e3 318
8a0681f9
VZ
319 // return TRUE if the tool is toggled
320 virtual bool GetToolState(int id) const;
321
322 virtual bool GetToolEnabled(int id) const;
81d66cf3 323
8a0681f9
VZ
324 virtual void SetToolShortHelp(int id, const wxString& helpString);
325 virtual wxString GetToolShortHelp(int id) const;
326 virtual void SetToolLongHelp(int id, const wxString& helpString);
327 virtual wxString GetToolLongHelp(int id) const;
10b959e3 328
1c383dba
VZ
329 // margins/packing/separation
330 // --------------------------
10b959e3 331
1c383dba
VZ
332 virtual void SetMargins(int x, int y);
333 void SetMargins(const wxSize& size)
334 { SetMargins((int) size.x, (int) size.y); }
8a0681f9
VZ
335 virtual void SetToolPacking(int packing)
336 { m_toolPacking = packing; }
337 virtual void SetToolSeparation(int separation)
338 { m_toolSeparation = separation; }
10b959e3 339
e1190518 340 virtual wxSize GetToolMargins() { return GetMargins(); }
1c383dba
VZ
341 virtual int GetToolPacking() { return m_toolPacking; }
342 virtual int GetToolSeparation() { return m_toolSeparation; }
10b959e3 343
ef7eaedd 344 // for compatibility
0ea48a1f 345 wxSize GetMargins() const { return wxSize(m_xMargin, m_yMargin); }
ef7eaedd 346
8a0681f9
VZ
347 // toolbar geometry
348 // ----------------
349
350 // set the number of toolbar rows
351 virtual void SetRows(int nRows);
352
353 // the toolbar can wrap - limit the number of columns or rows it may take
1c383dba
VZ
354 void SetMaxRowsCols(int rows, int cols)
355 { m_maxRows = rows; m_maxCols = cols; }
356 int GetMaxRows() const { return m_maxRows; }
357 int GetMaxCols() const { return m_maxCols; }
10b959e3 358
8a0681f9
VZ
359 // get/set the size of the bitmaps used by the toolbar: should be called
360 // before adding any tools to the toolbar
1c383dba
VZ
361 virtual void SetToolBitmapSize(const wxSize& size)
362 { m_defaultWidth = size.x; m_defaultHeight = size.y; };
363 virtual wxSize GetToolBitmapSize() const
364 { return wxSize(m_defaultWidth, m_defaultHeight); }
10b959e3 365
8a0681f9
VZ
366 // the button size in some implementations is bigger than the bitmap size:
367 // get the total button size (by default the same as bitmap size)
1c383dba 368 virtual wxSize GetToolSize() const
8a0681f9 369 { return GetToolBitmapSize(); } ;
10b959e3 370
8a0681f9
VZ
371 // returns a (non separator) tool containing the point (x, y) or NULL if
372 // there is no tool at this point (corrdinates are client)
373 virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
374 wxCoord y) const = 0;
375
376 // event handlers
377 // --------------
10b959e3 378
1c383dba 379 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
10b959e3 380
1c383dba 381 // Only allow toggle if returns TRUE. Call when left button up.
8a0681f9 382 virtual bool OnLeftClick(int id, bool toggleDown);
b02da6b1 383
1c383dba 384 // Call when right button down.
8a0681f9 385 virtual void OnRightClick(int id, long x, long y);
10b959e3 386
1c383dba
VZ
387 // Called when the mouse cursor enters a tool bitmap.
388 // Argument is -1 if mouse is exiting the toolbar.
8a0681f9 389 virtual void OnMouseEnter(int id);
1c383dba
VZ
390
391 // more deprecated functions
392 // -------------------------
393
394#if WXWIN_COMPATIBILITY
395 void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
396 long GetDefaultWidth() const { return m_defaultWidth; }
397 long GetDefaultHeight() const { return m_defaultHeight; }
398 int GetDefaultButtonWidth() const { return (int) GetDefaultButtonSize().x; };
399 int GetDefaultButtonHeight() const { return (int) GetDefaultButtonSize().y; };
400 virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
401 virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); }
402 virtual wxSize GetDefaultButtonSize() const { return GetToolSize(); }
1c383dba
VZ
403#endif // WXWIN_COMPATIBILITY
404
405 // implementation only from now on
406 // -------------------------------
407
8a0681f9 408 size_t GetToolsCount() const { return m_tools.GetCount(); }
1c383dba 409
8a0681f9 410 void OnIdle(wxIdleEvent& event);
1c383dba 411
8a0681f9
VZ
412 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
413 virtual void DoToolbarUpdates();
b02da6b1 414
1e6feb95
VZ
415 // don't want toolbars to accept the focus by tabbing to them
416 virtual bool AcceptsFocusFromKeyboard() const { return FALSE; }
4f430439 417
8a0681f9
VZ
418protected:
419 // to implement in derived classes
420 // -------------------------------
1c383dba 421
8a0681f9
VZ
422 // the tool is not yet inserted into m_tools list when this function is
423 // called and will only be added to it if this function succeeds
424 virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 425
8a0681f9
VZ
426 // the tool is still in m_tools list when this function is called, it will
427 // only be deleted from it if it succeeds
428 virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 429
8a0681f9
VZ
430 // called when the tools enabled flag changes
431 virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
1c383dba 432
8a0681f9
VZ
433 // called when the tool is toggled
434 virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
1c383dba 435
8a0681f9
VZ
436 // called when the tools "can be toggled" flag changes
437 virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
10b959e3 438
8a0681f9
VZ
439 // the functions to create toolbar tools
440 virtual wxToolBarToolBase *CreateTool(int id,
441 const wxBitmap& bitmap1,
442 const wxBitmap& bitmap2,
443 bool toggle,
444 wxObject *clientData,
445 const wxString& shortHelpString,
446 const wxString& longHelpString) = 0;
447 virtual wxToolBarToolBase *CreateTool(wxControl *control) = 0;
1c383dba 448
8a0681f9
VZ
449 // helper functions
450 // ----------------
1c383dba 451
8a0681f9
VZ
452 // find the tool by id
453 wxToolBarToolBase *FindById(int id) const;
1c383dba 454
8a0681f9
VZ
455 // the list of all our tools
456 wxToolBarToolsList m_tools;
1c383dba 457
8a0681f9
VZ
458 // the offset of the first tool
459 int m_xMargin;
460 int m_yMargin;
10b959e3 461
8a0681f9
VZ
462 // the maximum number of toolbar rows/columns
463 int m_maxRows;
464 int m_maxCols;
1c383dba 465
8a0681f9
VZ
466 // the tool packing and separation
467 int m_toolPacking,
468 m_toolSeparation;
1c383dba 469
8a0681f9
VZ
470 // the size of the toolbar bitmaps
471 wxCoord m_defaultWidth, m_defaultHeight;
1c383dba
VZ
472
473private:
10b959e3 474 DECLARE_EVENT_TABLE()
12ed316d 475 DECLARE_CLASS(wxToolBarBase)
10b959e3
JS
476};
477
1e6feb95
VZ
478#endif // wxUSE_TOOLBAR
479
10b959e3 480#endif
34138703 481 // _WX_TBARBASE_H_
10b959e3 482