]>
Commit | Line | Data |
---|---|---|
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 | // Copyright: (c) Julian Smart | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_TBARBASE_H_ | |
12 | #define _WX_TBARBASE_H_ | |
13 | ||
14 | // ---------------------------------------------------------------------------- | |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
18 | #include "wx/defs.h" | |
19 | ||
20 | #if wxUSE_TOOLBAR | |
21 | ||
22 | #include "wx/bitmap.h" | |
23 | #include "wx/list.h" | |
24 | #include "wx/control.h" | |
25 | ||
26 | class WXDLLIMPEXP_FWD_CORE wxToolBarBase; | |
27 | class WXDLLIMPEXP_FWD_CORE wxToolBarToolBase; | |
28 | class WXDLLIMPEXP_FWD_CORE wxImage; | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // constants | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | extern WXDLLIMPEXP_DATA_CORE(const char) wxToolBarNameStr[]; | |
35 | extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize; | |
36 | extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition; | |
37 | ||
38 | enum wxToolBarToolStyle | |
39 | { | |
40 | wxTOOL_STYLE_BUTTON = 1, | |
41 | wxTOOL_STYLE_SEPARATOR = 2, | |
42 | wxTOOL_STYLE_CONTROL | |
43 | }; | |
44 | ||
45 | // ---------------------------------------------------------------------------- | |
46 | // wxToolBarTool is a toolbar element. | |
47 | // | |
48 | // It has a unique id (except for the separators which always have id wxID_ANY), the | |
49 | // style (telling whether it is a normal button, separator or a control), the | |
50 | // state (toggled or not, enabled or not) and short and long help strings. The | |
51 | // default implementations use the short help string for the tooltip text which | |
52 | // is popped up when the mouse pointer enters the tool and the long help string | |
53 | // for the applications status bar. | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject | |
57 | { | |
58 | public: | |
59 | // ctors & dtor | |
60 | // ------------ | |
61 | ||
62 | // generic ctor for any kind of tool | |
63 | wxToolBarToolBase(wxToolBarBase *tbar = NULL, | |
64 | int toolid = wxID_SEPARATOR, | |
65 | const wxString& label = wxEmptyString, | |
66 | const wxBitmap& bmpNormal = wxNullBitmap, | |
67 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
68 | wxItemKind kind = wxITEM_NORMAL, | |
69 | wxObject *clientData = NULL, | |
70 | const wxString& shortHelpString = wxEmptyString, | |
71 | const wxString& longHelpString = wxEmptyString) | |
72 | : m_label(label), | |
73 | m_shortHelpString(shortHelpString), | |
74 | m_longHelpString(longHelpString) | |
75 | { | |
76 | Init | |
77 | ( | |
78 | tbar, | |
79 | toolid == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR | |
80 | : wxTOOL_STYLE_BUTTON, | |
81 | toolid == wxID_ANY ? wxWindow::NewControlId() | |
82 | : toolid, | |
83 | kind | |
84 | ); | |
85 | ||
86 | m_clientData = clientData; | |
87 | ||
88 | m_bmpNormal = bmpNormal; | |
89 | m_bmpDisabled = bmpDisabled; | |
90 | } | |
91 | ||
92 | // ctor for controls only | |
93 | wxToolBarToolBase(wxToolBarBase *tbar, | |
94 | wxControl *control, | |
95 | const wxString& label) | |
96 | : m_label(label) | |
97 | { | |
98 | Init(tbar, wxTOOL_STYLE_CONTROL, control->GetId(), wxITEM_MAX); | |
99 | ||
100 | m_control = control; | |
101 | } | |
102 | ||
103 | virtual ~wxToolBarToolBase(); | |
104 | ||
105 | // accessors | |
106 | // --------- | |
107 | ||
108 | // general | |
109 | int GetId() const { return m_id; } | |
110 | ||
111 | wxControl *GetControl() const | |
112 | { | |
113 | wxASSERT_MSG( IsControl(), wxT("this toolbar tool is not a control") ); | |
114 | ||
115 | return m_control; | |
116 | } | |
117 | ||
118 | wxToolBarBase *GetToolBar() const { return m_tbar; } | |
119 | ||
120 | // style/kind | |
121 | bool IsStretchable() const { return m_stretchable; } | |
122 | bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; } | |
123 | bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; } | |
124 | bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; } | |
125 | bool IsStretchableSpace() const { return IsSeparator() && IsStretchable(); } | |
126 | int GetStyle() const { return m_toolStyle; } | |
127 | wxItemKind GetKind() const | |
128 | { | |
129 | wxASSERT_MSG( IsButton(), wxT("only makes sense for buttons") ); | |
130 | ||
131 | return m_kind; | |
132 | } | |
133 | ||
134 | void MakeStretchable() | |
135 | { | |
136 | wxASSERT_MSG( IsSeparator(), "only separators can be stretchable" ); | |
137 | ||
138 | m_stretchable = true; | |
139 | } | |
140 | ||
141 | // state | |
142 | bool IsEnabled() const { return m_enabled; } | |
143 | bool IsToggled() const { return m_toggled; } | |
144 | bool CanBeToggled() const | |
145 | { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } | |
146 | ||
147 | // attributes | |
148 | const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; } | |
149 | const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; } | |
150 | ||
151 | const wxBitmap& GetBitmap() const | |
152 | { return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); } | |
153 | ||
154 | const wxString& GetLabel() const { return m_label; } | |
155 | ||
156 | const wxString& GetShortHelp() const { return m_shortHelpString; } | |
157 | const wxString& GetLongHelp() const { return m_longHelpString; } | |
158 | ||
159 | wxObject *GetClientData() const | |
160 | { | |
161 | if ( m_toolStyle == wxTOOL_STYLE_CONTROL ) | |
162 | { | |
163 | return (wxObject*)m_control->GetClientData(); | |
164 | } | |
165 | else | |
166 | { | |
167 | return m_clientData; | |
168 | } | |
169 | } | |
170 | ||
171 | // modifiers: return true if the state really changed | |
172 | virtual bool Enable(bool enable); | |
173 | virtual bool Toggle(bool toggle); | |
174 | virtual bool SetToggle(bool toggle); | |
175 | virtual bool SetShortHelp(const wxString& help); | |
176 | virtual bool SetLongHelp(const wxString& help); | |
177 | ||
178 | void Toggle() { Toggle(!IsToggled()); } | |
179 | ||
180 | virtual void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; } | |
181 | virtual void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; } | |
182 | ||
183 | virtual void SetLabel(const wxString& label) { m_label = label; } | |
184 | ||
185 | void SetClientData(wxObject *clientData) | |
186 | { | |
187 | if ( m_toolStyle == wxTOOL_STYLE_CONTROL ) | |
188 | { | |
189 | m_control->SetClientData(clientData); | |
190 | } | |
191 | else | |
192 | { | |
193 | m_clientData = clientData; | |
194 | } | |
195 | } | |
196 | ||
197 | // add tool to/remove it from a toolbar | |
198 | virtual void Detach() { m_tbar = NULL; } | |
199 | virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; } | |
200 | ||
201 | #if wxUSE_MENUS | |
202 | // these methods are only for tools of wxITEM_DROPDOWN kind (but even such | |
203 | // tools can have a NULL associated menu) | |
204 | virtual void SetDropdownMenu(wxMenu *menu); | |
205 | wxMenu *GetDropdownMenu() const { return m_dropdownMenu; } | |
206 | #endif | |
207 | ||
208 | protected: | |
209 | // common part of all ctors | |
210 | void Init(wxToolBarBase *tbar, | |
211 | wxToolBarToolStyle style, | |
212 | int toolid, | |
213 | wxItemKind kind) | |
214 | { | |
215 | m_tbar = tbar; | |
216 | m_toolStyle = style; | |
217 | m_id = toolid; | |
218 | m_kind = kind; | |
219 | ||
220 | m_clientData = NULL; | |
221 | ||
222 | m_stretchable = false; | |
223 | m_toggled = false; | |
224 | m_enabled = true; | |
225 | ||
226 | #if wxUSE_MENUS | |
227 | m_dropdownMenu = NULL; | |
228 | #endif | |
229 | ||
230 | } | |
231 | ||
232 | wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL) | |
233 | ||
234 | // tool parameters | |
235 | wxToolBarToolStyle m_toolStyle; | |
236 | wxWindowIDRef m_id; // the tool id, wxID_SEPARATOR for separator | |
237 | wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO | |
238 | ||
239 | // as controls have their own client data, no need to waste memory | |
240 | union | |
241 | { | |
242 | wxObject *m_clientData; | |
243 | wxControl *m_control; | |
244 | }; | |
245 | ||
246 | // true if this tool is stretchable: currently is only value for separators | |
247 | bool m_stretchable; | |
248 | ||
249 | // tool state | |
250 | bool m_toggled; | |
251 | bool m_enabled; | |
252 | ||
253 | // normal and disabled bitmaps for the tool, both can be invalid | |
254 | wxBitmap m_bmpNormal; | |
255 | wxBitmap m_bmpDisabled; | |
256 | ||
257 | // the button label | |
258 | wxString m_label; | |
259 | ||
260 | // short and long help strings | |
261 | wxString m_shortHelpString; | |
262 | wxString m_longHelpString; | |
263 | ||
264 | #if wxUSE_MENUS | |
265 | wxMenu *m_dropdownMenu; | |
266 | #endif | |
267 | ||
268 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolBarToolBase) | |
269 | }; | |
270 | ||
271 | // a list of toolbar tools | |
272 | WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList); | |
273 | ||
274 | // ---------------------------------------------------------------------------- | |
275 | // the base class for all toolbars | |
276 | // ---------------------------------------------------------------------------- | |
277 | ||
278 | class WXDLLIMPEXP_CORE wxToolBarBase : public wxControl | |
279 | { | |
280 | public: | |
281 | wxToolBarBase(); | |
282 | virtual ~wxToolBarBase(); | |
283 | ||
284 | // toolbar construction | |
285 | // -------------------- | |
286 | ||
287 | // the full AddTool() function | |
288 | // | |
289 | // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap | |
290 | // is created and used as the disabled image. | |
291 | wxToolBarToolBase *AddTool(int toolid, | |
292 | const wxString& label, | |
293 | const wxBitmap& bitmap, | |
294 | const wxBitmap& bmpDisabled, | |
295 | wxItemKind kind = wxITEM_NORMAL, | |
296 | const wxString& shortHelp = wxEmptyString, | |
297 | const wxString& longHelp = wxEmptyString, | |
298 | wxObject *data = NULL) | |
299 | { | |
300 | return DoAddTool(toolid, label, bitmap, bmpDisabled, kind, | |
301 | shortHelp, longHelp, data); | |
302 | } | |
303 | ||
304 | // the most common AddTool() version | |
305 | wxToolBarToolBase *AddTool(int toolid, | |
306 | const wxString& label, | |
307 | const wxBitmap& bitmap, | |
308 | const wxString& shortHelp = wxEmptyString, | |
309 | wxItemKind kind = wxITEM_NORMAL) | |
310 | { | |
311 | return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp); | |
312 | } | |
313 | ||
314 | // add a check tool, i.e. a tool which can be toggled | |
315 | wxToolBarToolBase *AddCheckTool(int toolid, | |
316 | const wxString& label, | |
317 | const wxBitmap& bitmap, | |
318 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
319 | const wxString& shortHelp = wxEmptyString, | |
320 | const wxString& longHelp = wxEmptyString, | |
321 | wxObject *data = NULL) | |
322 | { | |
323 | return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_CHECK, | |
324 | shortHelp, longHelp, data); | |
325 | } | |
326 | ||
327 | // add a radio tool, i.e. a tool which can be toggled and releases any | |
328 | // other toggled radio tools in the same group when it happens | |
329 | wxToolBarToolBase *AddRadioTool(int toolid, | |
330 | const wxString& label, | |
331 | const wxBitmap& bitmap, | |
332 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
333 | const wxString& shortHelp = wxEmptyString, | |
334 | const wxString& longHelp = wxEmptyString, | |
335 | wxObject *data = NULL) | |
336 | { | |
337 | return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_RADIO, | |
338 | shortHelp, longHelp, data); | |
339 | } | |
340 | ||
341 | ||
342 | // insert the new tool at the given position, if pos == GetToolsCount(), it | |
343 | // is equivalent to AddTool() | |
344 | virtual wxToolBarToolBase *InsertTool | |
345 | ( | |
346 | size_t pos, | |
347 | int toolid, | |
348 | const wxString& label, | |
349 | const wxBitmap& bitmap, | |
350 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
351 | wxItemKind kind = wxITEM_NORMAL, | |
352 | const wxString& shortHelp = wxEmptyString, | |
353 | const wxString& longHelp = wxEmptyString, | |
354 | wxObject *clientData = NULL | |
355 | ); | |
356 | ||
357 | virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool); | |
358 | virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool); | |
359 | ||
360 | // add an arbitrary control to the toolbar (notice that the control will be | |
361 | // deleted by the toolbar and that it will also adjust its position/size) | |
362 | // | |
363 | // the label is optional and, if specified, will be shown near the control | |
364 | // NB: the control should have toolbar as its parent | |
365 | virtual wxToolBarToolBase * | |
366 | AddControl(wxControl *control, const wxString& label = wxEmptyString); | |
367 | ||
368 | virtual wxToolBarToolBase * | |
369 | InsertControl(size_t pos, wxControl *control, | |
370 | const wxString& label = wxEmptyString); | |
371 | ||
372 | // get the control with the given id or return NULL | |
373 | virtual wxControl *FindControl( int toolid ); | |
374 | ||
375 | // add a separator to the toolbar | |
376 | virtual wxToolBarToolBase *AddSeparator(); | |
377 | virtual wxToolBarToolBase *InsertSeparator(size_t pos); | |
378 | ||
379 | // add a stretchable space to the toolbar: this is similar to a separator | |
380 | // except that it's always blank and that all the extra space the toolbar | |
381 | // has is [equally] distributed among the stretchable spaces in it | |
382 | virtual wxToolBarToolBase *AddStretchableSpace(); | |
383 | virtual wxToolBarToolBase *InsertStretchableSpace(size_t pos); | |
384 | ||
385 | // remove the tool from the toolbar: the caller is responsible for actually | |
386 | // deleting the pointer | |
387 | virtual wxToolBarToolBase *RemoveTool(int toolid); | |
388 | ||
389 | // delete tool either by index or by position | |
390 | virtual bool DeleteToolByPos(size_t pos); | |
391 | virtual bool DeleteTool(int toolid); | |
392 | ||
393 | // delete all tools | |
394 | virtual void ClearTools(); | |
395 | ||
396 | // must be called after all buttons have been created to finish toolbar | |
397 | // initialisation | |
398 | // | |
399 | // derived class versions should call the base one first, before doing | |
400 | // platform-specific stuff | |
401 | virtual bool Realize(); | |
402 | ||
403 | // tools state | |
404 | // ----------- | |
405 | ||
406 | virtual void EnableTool(int toolid, bool enable); | |
407 | virtual void ToggleTool(int toolid, bool toggle); | |
408 | ||
409 | // Set this to be togglable (or not) | |
410 | virtual void SetToggle(int toolid, bool toggle); | |
411 | ||
412 | // set/get tools client data (not for controls) | |
413 | virtual wxObject *GetToolClientData(int toolid) const; | |
414 | virtual void SetToolClientData(int toolid, wxObject *clientData); | |
415 | ||
416 | // returns tool pos, or wxNOT_FOUND if tool isn't found | |
417 | virtual int GetToolPos(int id) const; | |
418 | ||
419 | // return true if the tool is toggled | |
420 | virtual bool GetToolState(int toolid) const; | |
421 | ||
422 | virtual bool GetToolEnabled(int toolid) const; | |
423 | ||
424 | virtual void SetToolShortHelp(int toolid, const wxString& helpString); | |
425 | virtual wxString GetToolShortHelp(int toolid) const; | |
426 | virtual void SetToolLongHelp(int toolid, const wxString& helpString); | |
427 | virtual wxString GetToolLongHelp(int toolid) const; | |
428 | ||
429 | virtual void SetToolNormalBitmap(int WXUNUSED(id), | |
430 | const wxBitmap& WXUNUSED(bitmap)) {} | |
431 | virtual void SetToolDisabledBitmap(int WXUNUSED(id), | |
432 | const wxBitmap& WXUNUSED(bitmap)) {} | |
433 | ||
434 | ||
435 | // margins/packing/separation | |
436 | // -------------------------- | |
437 | ||
438 | virtual void SetMargins(int x, int y); | |
439 | void SetMargins(const wxSize& size) | |
440 | { SetMargins((int) size.x, (int) size.y); } | |
441 | virtual void SetToolPacking(int packing) | |
442 | { m_toolPacking = packing; } | |
443 | virtual void SetToolSeparation(int separation) | |
444 | { m_toolSeparation = separation; } | |
445 | ||
446 | virtual wxSize GetToolMargins() const { return wxSize(m_xMargin, m_yMargin); } | |
447 | virtual int GetToolPacking() const { return m_toolPacking; } | |
448 | virtual int GetToolSeparation() const { return m_toolSeparation; } | |
449 | ||
450 | // toolbar geometry | |
451 | // ---------------- | |
452 | ||
453 | // set the number of toolbar rows | |
454 | virtual void SetRows(int nRows); | |
455 | ||
456 | // the toolbar can wrap - limit the number of columns or rows it may take | |
457 | void SetMaxRowsCols(int rows, int cols) | |
458 | { m_maxRows = rows; m_maxCols = cols; } | |
459 | int GetMaxRows() const { return m_maxRows; } | |
460 | int GetMaxCols() const { return m_maxCols; } | |
461 | ||
462 | // get/set the size of the bitmaps used by the toolbar: should be called | |
463 | // before adding any tools to the toolbar | |
464 | virtual void SetToolBitmapSize(const wxSize& size) | |
465 | { m_defaultWidth = size.x; m_defaultHeight = size.y; } | |
466 | virtual wxSize GetToolBitmapSize() const | |
467 | { return wxSize(m_defaultWidth, m_defaultHeight); } | |
468 | ||
469 | // the button size in some implementations is bigger than the bitmap size: | |
470 | // get the total button size (by default the same as bitmap size) | |
471 | virtual wxSize GetToolSize() const | |
472 | { return GetToolBitmapSize(); } | |
473 | ||
474 | // returns a (non separator) tool containing the point (x, y) or NULL if | |
475 | // there is no tool at this point (coordinates are client) | |
476 | virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, | |
477 | wxCoord y) const = 0; | |
478 | ||
479 | // find the tool by id | |
480 | wxToolBarToolBase *FindById(int toolid) const; | |
481 | ||
482 | // return true if this is a vertical toolbar, otherwise false | |
483 | bool IsVertical() const; | |
484 | ||
485 | // these methods allow to access tools by their index in the toolbar | |
486 | size_t GetToolsCount() const { return m_tools.GetCount(); } | |
487 | const wxToolBarToolBase *GetToolByPos(int pos) const { return m_tools[pos]; } | |
488 | ||
489 | #if WXWIN_COMPATIBILITY_2_8 | |
490 | // the old versions of the various methods kept for compatibility | |
491 | // don't use in the new code! | |
492 | // -------------------------------------------------------------- | |
493 | wxDEPRECATED_INLINE( | |
494 | wxToolBarToolBase *AddTool(int toolid, | |
495 | const wxBitmap& bitmap, | |
496 | const wxBitmap& bmpDisabled, | |
497 | bool toggle = false, | |
498 | wxObject *clientData = NULL, | |
499 | const wxString& shortHelpString = wxEmptyString, | |
500 | const wxString& longHelpString = wxEmptyString) | |
501 | , | |
502 | return AddTool(toolid, wxEmptyString, | |
503 | bitmap, bmpDisabled, | |
504 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, | |
505 | shortHelpString, longHelpString, clientData); | |
506 | ) | |
507 | wxDEPRECATED_INLINE( | |
508 | wxToolBarToolBase *AddTool(int toolid, | |
509 | const wxBitmap& bitmap, | |
510 | const wxString& shortHelpString = wxEmptyString, | |
511 | const wxString& longHelpString = wxEmptyString) | |
512 | , | |
513 | return AddTool(toolid, wxEmptyString, | |
514 | bitmap, wxNullBitmap, wxITEM_NORMAL, | |
515 | shortHelpString, longHelpString, NULL); | |
516 | ) | |
517 | wxDEPRECATED_INLINE( | |
518 | wxToolBarToolBase *AddTool(int toolid, | |
519 | const wxBitmap& bitmap, | |
520 | const wxBitmap& bmpDisabled, | |
521 | bool toggle, | |
522 | wxCoord xPos, | |
523 | wxCoord yPos = wxDefaultCoord, | |
524 | wxObject *clientData = NULL, | |
525 | const wxString& shortHelp = wxEmptyString, | |
526 | const wxString& longHelp = wxEmptyString) | |
527 | , | |
528 | return DoAddTool(toolid, wxEmptyString, bitmap, bmpDisabled, | |
529 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, | |
530 | shortHelp, longHelp, clientData, xPos, yPos); | |
531 | ) | |
532 | wxDEPRECATED_INLINE( | |
533 | wxToolBarToolBase *InsertTool(size_t pos, | |
534 | int toolid, | |
535 | const wxBitmap& bitmap, | |
536 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
537 | bool toggle = false, | |
538 | wxObject *clientData = NULL, | |
539 | const wxString& shortHelp = wxEmptyString, | |
540 | const wxString& longHelp = wxEmptyString) | |
541 | , | |
542 | return InsertTool(pos, toolid, wxEmptyString, bitmap, bmpDisabled, | |
543 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, | |
544 | shortHelp, longHelp, clientData); | |
545 | ) | |
546 | #endif // WXWIN_COMPATIBILITY_2_8 | |
547 | ||
548 | // event handlers | |
549 | // -------------- | |
550 | ||
551 | // NB: these functions are deprecated, use EVT_TOOL_XXX() instead! | |
552 | ||
553 | // Only allow toggle if returns true. Call when left button up. | |
554 | virtual bool OnLeftClick(int toolid, bool toggleDown); | |
555 | ||
556 | // Call when right button down. | |
557 | virtual void OnRightClick(int toolid, long x, long y); | |
558 | ||
559 | // Called when the mouse cursor enters a tool bitmap. | |
560 | // Argument is wxID_ANY if mouse is exiting the toolbar. | |
561 | virtual void OnMouseEnter(int toolid); | |
562 | ||
563 | // more deprecated functions | |
564 | // ------------------------- | |
565 | ||
566 | // use GetToolMargins() instead | |
567 | wxSize GetMargins() const { return GetToolMargins(); } | |
568 | ||
569 | // Tool factories, | |
570 | // helper functions to create toolbar tools | |
571 | // ------------------------- | |
572 | virtual wxToolBarToolBase *CreateTool(int toolid, | |
573 | const wxString& label, | |
574 | const wxBitmap& bmpNormal, | |
575 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
576 | wxItemKind kind = wxITEM_NORMAL, | |
577 | wxObject *clientData = NULL, | |
578 | const wxString& shortHelp = wxEmptyString, | |
579 | const wxString& longHelp = wxEmptyString) = 0; | |
580 | ||
581 | virtual wxToolBarToolBase *CreateTool(wxControl *control, | |
582 | const wxString& label) = 0; | |
583 | ||
584 | // this one is not virtual but just a simple helper/wrapper around | |
585 | // CreateTool() for separators | |
586 | wxToolBarToolBase *CreateSeparator() | |
587 | { | |
588 | return CreateTool(wxID_SEPARATOR, | |
589 | wxEmptyString, | |
590 | wxNullBitmap, wxNullBitmap, | |
591 | wxITEM_SEPARATOR, NULL, | |
592 | wxEmptyString, wxEmptyString); | |
593 | } | |
594 | ||
595 | ||
596 | // implementation only from now on | |
597 | // ------------------------------- | |
598 | ||
599 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
600 | virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) ; | |
601 | ||
602 | // don't want toolbars to accept the focus | |
603 | virtual bool AcceptsFocus() const { return false; } | |
604 | ||
605 | #if wxUSE_MENUS | |
606 | // Set dropdown menu | |
607 | bool SetDropdownMenu(int toolid, wxMenu *menu); | |
608 | #endif | |
609 | ||
610 | protected: | |
611 | // choose the default border for this window | |
612 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
613 | ||
614 | // to implement in derived classes | |
615 | // ------------------------------- | |
616 | ||
617 | // create a new toolbar tool and add it to the toolbar, this is typically | |
618 | // implemented by just calling InsertTool() | |
619 | virtual wxToolBarToolBase *DoAddTool | |
620 | ( | |
621 | int toolid, | |
622 | const wxString& label, | |
623 | const wxBitmap& bitmap, | |
624 | const wxBitmap& bmpDisabled, | |
625 | wxItemKind kind, | |
626 | const wxString& shortHelp = wxEmptyString, | |
627 | const wxString& longHelp = wxEmptyString, | |
628 | wxObject *clientData = NULL, | |
629 | wxCoord xPos = wxDefaultCoord, | |
630 | wxCoord yPos = wxDefaultCoord | |
631 | ); | |
632 | ||
633 | // the tool is not yet inserted into m_tools list when this function is | |
634 | // called and will only be added to it if this function succeeds | |
635 | virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0; | |
636 | ||
637 | // the tool is still in m_tools list when this function is called, it will | |
638 | // only be deleted from it if it succeeds | |
639 | virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0; | |
640 | ||
641 | // called when the tools enabled flag changes | |
642 | virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0; | |
643 | ||
644 | // called when the tool is toggled | |
645 | virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0; | |
646 | ||
647 | // called when the tools "can be toggled" flag changes | |
648 | virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0; | |
649 | ||
650 | ||
651 | // helper functions | |
652 | // ---------------- | |
653 | ||
654 | // call this from derived class ctor/Create() to ensure that we have either | |
655 | // wxTB_HORIZONTAL or wxTB_VERTICAL style, there is a lot of existing code | |
656 | // which randomly checks either one or the other of them and gets confused | |
657 | // if neither is set (and making one of them 0 is not an option neither as | |
658 | // then the existing tests would break down) | |
659 | void FixupStyle(); | |
660 | ||
661 | // un-toggle all buttons in the same radio group | |
662 | void UnToggleRadioGroup(wxToolBarToolBase *tool); | |
663 | ||
664 | // make the size of the buttons big enough to fit the largest bitmap size | |
665 | void AdjustToolBitmapSize(); | |
666 | ||
667 | // calls InsertTool() and deletes the tool if inserting it failed | |
668 | wxToolBarToolBase *DoInsertNewTool(size_t pos, wxToolBarToolBase *tool) | |
669 | { | |
670 | if ( !InsertTool(pos, tool) ) | |
671 | { | |
672 | delete tool; | |
673 | return NULL; | |
674 | } | |
675 | ||
676 | return tool; | |
677 | } | |
678 | ||
679 | // the list of all our tools | |
680 | wxToolBarToolsList m_tools; | |
681 | ||
682 | // the offset of the first tool | |
683 | int m_xMargin; | |
684 | int m_yMargin; | |
685 | ||
686 | // the maximum number of toolbar rows/columns | |
687 | int m_maxRows; | |
688 | int m_maxCols; | |
689 | ||
690 | // the tool packing and separation | |
691 | int m_toolPacking, | |
692 | m_toolSeparation; | |
693 | ||
694 | // the size of the toolbar bitmaps | |
695 | wxCoord m_defaultWidth, m_defaultHeight; | |
696 | ||
697 | private: | |
698 | DECLARE_EVENT_TABLE() | |
699 | wxDECLARE_NO_COPY_CLASS(wxToolBarBase); | |
700 | }; | |
701 | ||
702 | // deprecated function for creating the image for disabled buttons, use | |
703 | // wxImage::ConvertToGreyscale() instead | |
704 | #if WXWIN_COMPATIBILITY_2_8 | |
705 | ||
706 | wxDEPRECATED( bool wxCreateGreyedImage(const wxImage& in, wxImage& out) ); | |
707 | ||
708 | #endif // WXWIN_COMPATIBILITY_2_8 | |
709 | ||
710 | ||
711 | #endif // wxUSE_TOOLBAR | |
712 | ||
713 | #endif | |
714 | // _WX_TBARBASE_H_ | |
715 |