include wx/control.h for the base class declaration (part of #9931)
[wxWidgets.git] / include / wx / aui / auibar.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/aui/toolbar.h
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
5 // Modified by:
6 // Created: 2008-08-04
7 // RCS-ID: $Id: framemanager.h 53135 2008-04-12 02:31:04Z VZ $
8 // Copyright: (C) Copyright 2005, Kirix Corporation, All Rights Reserved.
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_AUIBAR_H_
13 #define _WX_AUIBAR_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_AUI
18
19 #include "wx/control.h"
20
21 enum wxAuiToolBarStyle
22 {
23 wxAUI_TB_TEXT = 1 << 0,
24 wxAUI_TB_NO_TOOLTIPS = 1 << 1,
25 wxAUI_TB_NO_AUTORESIZE = 1 << 2,
26 wxAUI_TB_GRIPPER = 1 << 3,
27 wxAUI_TB_OVERFLOW = 1 << 4,
28 wxAUI_TB_VERTICAL = 1 << 5,
29 wxAUI_TB_HORZ_TEXT = ((1 << 6) | wxAUI_TB_TEXT),
30 wxAUI_TB_DEFAULT_STYLE = 0
31 };
32
33 enum wxAuiToolBarArtSetting
34 {
35 wxAUI_TBART_SEPARATOR_SIZE = 0,
36 wxAUI_TBART_GRIPPER_SIZE = 1,
37 wxAUI_TBART_OVERFLOW_SIZE = 2
38 };
39
40 enum wxAuiToolBarToolTextOrientation
41 {
42 wxAUI_TBTOOL_TEXT_LEFT = 0, // unused/unimplemented
43 wxAUI_TBTOOL_TEXT_RIGHT = 1,
44 wxAUI_TBTOOL_TEXT_TOP = 2, // unused/unimplemented
45 wxAUI_TBTOOL_TEXT_BOTTOM = 3
46 };
47
48
49 // aui toolbar event class
50
51 class WXDLLIMPEXP_AUI wxAuiToolBarEvent : public wxNotifyEvent
52 {
53 public:
54 wxAuiToolBarEvent(wxEventType command_type = wxEVT_NULL,
55 int win_id = 0)
56 : wxNotifyEvent(command_type, win_id)
57 {
58 is_dropdown_clicked = false;
59 click_pt = wxPoint(-1, -1);
60 rect = wxRect(-1,-1, 0, 0);
61 tool_id = -1;
62 }
63 #ifndef SWIG
64 wxAuiToolBarEvent(const wxAuiToolBarEvent& c) : wxNotifyEvent(c)
65 {
66 is_dropdown_clicked = c.is_dropdown_clicked;
67 click_pt = c.click_pt;
68 rect = c.rect;
69 tool_id = c.tool_id;
70 }
71 #endif
72 wxEvent *Clone() const { return new wxAuiToolBarEvent(*this); }
73
74 bool IsDropDownClicked() const { return is_dropdown_clicked; }
75 void SetDropDownClicked(bool c) { is_dropdown_clicked = c; }
76
77 wxPoint GetClickPoint() const { return click_pt; }
78 void SetClickPoint(const wxPoint& p) { click_pt = p; }
79
80 wxRect GetItemRect() const { return rect; }
81 void SetItemRect(const wxRect& r) { rect = r; }
82
83 int GetToolId() const { return tool_id; }
84 void SetToolId(int id) { tool_id = id; }
85
86 public:
87 bool is_dropdown_clicked;
88 wxPoint click_pt;
89 wxRect rect;
90 int tool_id;
91
92 #ifndef SWIG
93 private:
94 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiToolBarEvent)
95 #endif
96 };
97
98
99 class WXDLLIMPEXP_AUI wxAuiToolBarItem
100 {
101 public:
102
103 wxAuiToolBarItem()
104 {
105 window = NULL;
106 sizer_item = NULL;
107 space_pixels = 0;
108 id = 0;
109 kind = wxITEM_NORMAL;
110 state = 0; // normal, enabled
111 proportion = 0;
112 active = true;
113 dropdown = true;
114 sticky = true;
115 user_data = 0;
116 }
117
118 wxAuiToolBarItem(const wxAuiToolBarItem& c)
119 {
120 Assign(c);
121 }
122
123 wxAuiToolBarItem& operator=(const wxAuiToolBarItem& c)
124 {
125 Assign(c);
126 return *this;
127 }
128
129 void Assign(const wxAuiToolBarItem& c)
130 {
131 window = c.window;
132 label = c.label;
133 bitmap = c.bitmap;
134 disabled_bitmap = c.disabled_bitmap;
135 hover_bitmap = c.hover_bitmap;
136 short_help = c.short_help;
137 long_help = c.long_help;
138 sizer_item = c.sizer_item;
139 min_size = c.min_size;
140 space_pixels = c.space_pixels;
141 id = c.id;
142 kind = c.kind;
143 state = c.state;
144 proportion = c.proportion;
145 active = c.active;
146 dropdown = c.dropdown;
147 sticky = c.sticky;
148 user_data = c.user_data;
149 }
150
151 public:
152
153 wxWindow* window; // item's associated window
154 wxString label; // label displayed on the item
155 wxBitmap bitmap; // item's bitmap
156 wxBitmap disabled_bitmap; // item's disabled bitmap
157 wxBitmap hover_bitmap; // item's hover bitmap
158 wxString short_help; // short help (for tooltip)
159 wxString long_help; // long help (for status bar)
160 wxSizerItem* sizer_item; // sizer item
161 wxSize min_size; // item's minimum size
162 int space_pixels; // size of a spacer
163 int id; // item's id
164 int kind; // item's kind
165 int state; // state
166 int proportion; // proportion
167 bool active; // true if the item is currently active
168 bool dropdown; // true if the item has a dropdown button
169 bool sticky; // overrides button states if true (always active)
170 long user_data; // user-specified data
171 };
172
173 #ifndef SWIG
174 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiToolBarItem, wxAuiToolBarItemArray, WXDLLIMPEXP_AUI);
175 #endif
176
177
178
179
180 // tab art class
181
182 class WXDLLIMPEXP_AUI wxAuiToolBarArt
183 {
184 public:
185
186 wxAuiToolBarArt() { }
187 virtual ~wxAuiToolBarArt() { }
188
189 virtual wxAuiToolBarArt* Clone() = 0;
190 virtual void SetFlags(unsigned int flags) = 0;
191 virtual void SetFont(const wxFont& font) = 0;
192 virtual void SetTextOrientation(int orientation) = 0;
193
194 virtual void DrawBackground(
195 wxDC& dc,
196 wxWindow* wnd,
197 const wxRect& rect) = 0;
198
199 virtual void DrawLabel(
200 wxDC& dc,
201 wxWindow* wnd,
202 const wxAuiToolBarItem& item,
203 const wxRect& rect) = 0;
204
205 virtual void DrawButton(
206 wxDC& dc,
207 wxWindow* wnd,
208 const wxAuiToolBarItem& item,
209 const wxRect& rect) = 0;
210
211 virtual void DrawDropDownButton(
212 wxDC& dc,
213 wxWindow* wnd,
214 const wxAuiToolBarItem& item,
215 const wxRect& rect) = 0;
216
217 virtual void DrawControlLabel(
218 wxDC& dc,
219 wxWindow* wnd,
220 const wxAuiToolBarItem& item,
221 const wxRect& rect) = 0;
222
223 virtual void DrawSeparator(
224 wxDC& dc,
225 wxWindow* wnd,
226 const wxRect& rect) = 0;
227
228 virtual void DrawGripper(
229 wxDC& dc,
230 wxWindow* wnd,
231 const wxRect& rect) = 0;
232
233 virtual void DrawOverflowButton(
234 wxDC& dc,
235 wxWindow* wnd,
236 const wxRect& rect,
237 int state) = 0;
238
239 virtual wxSize GetLabelSize(
240 wxDC& dc,
241 wxWindow* wnd,
242 const wxAuiToolBarItem& item) = 0;
243
244 virtual wxSize GetToolSize(
245 wxDC& dc,
246 wxWindow* wnd,
247 const wxAuiToolBarItem& item) = 0;
248
249 virtual int GetElementSize(int element_id) = 0;
250 virtual void SetElementSize(int element_id, int size) = 0;
251
252 virtual int ShowDropDown(
253 wxWindow* wnd,
254 const wxAuiToolBarItemArray& items) = 0;
255 };
256
257
258
259 class WXDLLIMPEXP_AUI wxAuiDefaultToolBarArt : public wxAuiToolBarArt
260 {
261
262 public:
263
264 wxAuiDefaultToolBarArt();
265 virtual ~wxAuiDefaultToolBarArt();
266
267 virtual wxAuiToolBarArt* Clone();
268 virtual void SetFlags(unsigned int flags);
269 virtual void SetFont(const wxFont& font);
270 virtual void SetTextOrientation(int orientation);
271
272 virtual void DrawBackground(
273 wxDC& dc,
274 wxWindow* wnd,
275 const wxRect& rect);
276
277 virtual void DrawLabel(
278 wxDC& dc,
279 wxWindow* wnd,
280 const wxAuiToolBarItem& item,
281 const wxRect& rect);
282
283 virtual void DrawButton(
284 wxDC& dc,
285 wxWindow* wnd,
286 const wxAuiToolBarItem& item,
287 const wxRect& rect);
288
289 virtual void DrawDropDownButton(
290 wxDC& dc,
291 wxWindow* wnd,
292 const wxAuiToolBarItem& item,
293 const wxRect& rect);
294
295 virtual void DrawControlLabel(
296 wxDC& dc,
297 wxWindow* wnd,
298 const wxAuiToolBarItem& item,
299 const wxRect& rect);
300
301 virtual void DrawSeparator(
302 wxDC& dc,
303 wxWindow* wnd,
304 const wxRect& rect);
305
306 virtual void DrawGripper(
307 wxDC& dc,
308 wxWindow* wnd,
309 const wxRect& rect);
310
311 virtual void DrawOverflowButton(
312 wxDC& dc,
313 wxWindow* wnd,
314 const wxRect& rect,
315 int state);
316
317 virtual wxSize GetLabelSize(
318 wxDC& dc,
319 wxWindow* wnd,
320 const wxAuiToolBarItem& item);
321
322 virtual wxSize GetToolSize(
323 wxDC& dc,
324 wxWindow* wnd,
325 const wxAuiToolBarItem& item);
326
327 virtual int GetElementSize(int element);
328 virtual void SetElementSize(int element_id, int size);
329
330 virtual int ShowDropDown(wxWindow* wnd,
331 const wxAuiToolBarItemArray& items);
332
333 protected:
334
335 wxBitmap m_button_dropdown_bmp;
336 wxBitmap m_disabled_button_dropdown_bmp;
337 wxBitmap m_overflow_bmp;
338 wxBitmap m_disabled_overflow_bmp;
339 wxColour m_base_colour;
340 wxColour m_highlight_colour;
341 wxFont m_font;
342 unsigned int m_flags;
343 int m_text_orientation;
344
345 wxPen m_gripper_pen1;
346 wxPen m_gripper_pen2;
347 wxPen m_gripper_pen3;
348
349 int m_separator_size;
350 int m_gripper_size;
351 int m_overflow_size;
352 };
353
354
355
356
357 class WXDLLIMPEXP_AUI wxAuiToolBar : public wxControl
358 {
359 public:
360
361 wxAuiToolBar(wxWindow* parent,
362 wxWindowID id = -1,
363 const wxPoint& position = wxDefaultPosition,
364 const wxSize& size = wxDefaultSize,
365 long style = wxAUI_TB_DEFAULT_STYLE);
366 ~wxAuiToolBar();
367
368 void SetWindowStyleFlag(long style);
369
370 void SetArtProvider(wxAuiToolBarArt* art);
371 wxAuiToolBarArt* GetArtProvider() const;
372
373 bool SetFont(const wxFont& font);
374
375
376 void AddTool(int tool_id,
377 const wxString& label,
378 const wxBitmap& bitmap,
379 const wxString& short_help_string = wxEmptyString,
380 wxItemKind kind = wxITEM_NORMAL);
381
382 void AddTool(int tool_id,
383 const wxString& label,
384 const wxBitmap& bitmap,
385 const wxBitmap& disabled_bitmap,
386 wxItemKind kind,
387 const wxString& short_help_string,
388 const wxString& long_help_string,
389 wxObject* client_data);
390
391 void AddTool(int tool_id,
392 const wxBitmap& bitmap,
393 const wxBitmap& disabled_bitmap,
394 bool toggle = false,
395 wxObject* client_data = NULL,
396 const wxString& short_help_string = wxEmptyString,
397 const wxString& long_help_string = wxEmptyString)
398 {
399 AddTool(tool_id,
400 wxEmptyString,
401 bitmap,
402 disabled_bitmap,
403 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
404 short_help_string,
405 long_help_string,
406 client_data);
407 }
408
409 void AddLabel(int tool_id,
410 const wxString& label = wxEmptyString,
411 const int width = -1);
412 void AddControl(wxControl* control,
413 const wxString& label = wxEmptyString);
414 void AddSeparator();
415 void AddSpacer(int pixels);
416 void AddStretchSpacer(int proportion = 1);
417
418 bool Realize();
419
420 wxControl* FindControl(int window_id);
421 wxAuiToolBarItem* FindToolByPosition(wxCoord x, wxCoord y) const;
422 wxAuiToolBarItem* FindToolByIndex(int idx) const;
423 wxAuiToolBarItem* FindTool(int tool_id) const;
424
425 void ClearTools() { Clear() ; }
426 void Clear();
427 bool DeleteTool(int tool_id);
428 bool DeleteByIndex(int tool_id);
429
430 size_t GetToolCount() const;
431 int GetToolPos(int tool_id) const { return GetToolIndex(tool_id); }
432 int GetToolIndex(int tool_id) const;
433 bool GetToolFits(int tool_id) const;
434 wxRect GetToolRect(int tool_id) const;
435 bool GetToolFitsByIndex(int tool_id) const;
436 bool GetToolBarFits() const;
437
438 void SetMargins(const wxSize& size) { SetMargins(size.x, size.x, size.y, size.y); }
439 void SetMargins(int x, int y) { SetMargins(x, x, y, y); }
440 void SetMargins(int left, int right, int top, int bottom);
441
442 void SetToolBitmapSize(const wxSize& size);
443 wxSize GetToolBitmapSize() const;
444
445 bool GetOverflowVisible() const;
446 void SetOverflowVisible(bool visible);
447
448 bool GetGripperVisible() const;
449 void SetGripperVisible(bool visible);
450
451 void ToggleTool(int tool_id, bool state);
452 bool GetToolToggled(int tool_id) const;
453
454 void EnableTool(int tool_id, bool state);
455 bool GetToolEnabled(int tool_id) const;
456
457 void SetToolDropDown(int tool_id, bool dropdown);
458 bool GetToolDropDown(int tool_id) const;
459
460 void SetToolBorderPadding(int padding);
461 int GetToolBorderPadding() const;
462
463 void SetToolTextOrientation(int orientation);
464 int GetToolTextOrientation() const;
465
466 void SetToolPacking(int packing);
467 int GetToolPacking() const;
468
469 void SetToolProportion(int tool_id, int proportion);
470 int GetToolProportion(int tool_id) const;
471
472 void SetToolSeparation(int separation);
473 int GetToolSeparation() const;
474
475 void SetToolSticky(int tool_id, bool sticky);
476 bool GetToolSticky(int tool_id) const;
477
478 wxString GetToolLabel(int tool_id) const;
479 void SetToolLabel(int tool_id, const wxString& label);
480
481 wxBitmap GetToolBitmap(int tool_id) const;
482 void SetToolBitmap(int tool_id, const wxBitmap& bitmap);
483
484 wxString GetToolShortHelp(int tool_id) const;
485 void SetToolShortHelp(int tool_id, const wxString& help_string);
486
487 wxString GetToolLongHelp(int tool_id) const;
488 void SetToolLongHelp(int tool_id, const wxString& help_string);
489
490 void SetCustomOverflowItems(const wxAuiToolBarItemArray& prepend,
491 const wxAuiToolBarItemArray& append);
492
493 protected:
494
495 virtual void OnCustomRender(wxDC& WXUNUSED(dc),
496 const wxAuiToolBarItem& WXUNUSED(item),
497 const wxRect& WXUNUSED(rect)) { }
498
499 protected:
500
501 void DoIdleUpdate();
502 void SetOrientation(int orientation);
503 void SetHoverItem(wxAuiToolBarItem* item);
504 void SetPressedItem(wxAuiToolBarItem* item);
505 void RefreshOverflowState();
506
507 int GetOverflowState() const;
508 wxRect GetOverflowRect() const;
509 wxSize GetLabelSize(const wxString& label);
510 wxAuiToolBarItem* FindToolByPositionWithPacking(wxCoord x, wxCoord y) const;
511
512 void DoSetSize(int x,
513 int y,
514 int width,
515 int height,
516 int sizeFlags = wxSIZE_AUTO);
517
518 protected: // handlers
519
520 void OnSize(wxSizeEvent& evt);
521 void OnIdle(wxIdleEvent& evt);
522 void OnPaint(wxPaintEvent& evt);
523 void OnEraseBackground(wxEraseEvent& evt);
524 void OnLeftDown(wxMouseEvent& evt);
525 void OnLeftUp(wxMouseEvent& evt);
526 void OnRightDown(wxMouseEvent& evt);
527 void OnRightUp(wxMouseEvent& evt);
528 void OnMiddleDown(wxMouseEvent& evt);
529 void OnMiddleUp(wxMouseEvent& evt);
530 void OnMotion(wxMouseEvent& evt);
531 void OnLeaveWindow(wxMouseEvent& evt);
532 void OnSetCursor(wxSetCursorEvent& evt);
533
534 protected:
535
536 wxAuiToolBarItemArray m_items; // array of toolbar items
537 wxAuiToolBarArt* m_art; // art provider
538 wxBoxSizer* m_sizer; // main sizer for toolbar
539 wxAuiToolBarItem* m_action_item; // item that's being acted upon (pressed)
540 wxAuiToolBarItem* m_tip_item; // item that has its tooltip shown
541 wxBitmap m_bitmap; // double-buffer bitmap
542 wxSizerItem* m_gripper_sizer_item;
543 wxSizerItem* m_overflow_sizer_item;
544 wxSize m_absolute_min_size;
545 wxPoint m_action_pos; // position of left-mouse down
546 wxAuiToolBarItemArray m_custom_overflow_prepend;
547 wxAuiToolBarItemArray m_custom_overflow_append;
548
549 int m_button_width;
550 int m_button_height;
551 int m_sizer_element_count;
552 int m_left_padding;
553 int m_right_padding;
554 int m_top_padding;
555 int m_bottom_padding;
556 int m_tool_packing;
557 int m_tool_border_padding;
558 int m_tool_text_orientation;
559 int m_overflow_state;
560 bool m_dragging;
561 bool m_gripper_visible;
562 bool m_overflow_visible;
563 long m_style;
564
565 DECLARE_EVENT_TABLE()
566 DECLARE_CLASS(wxAuiToolBar)
567 };
568
569
570
571
572 // wx event machinery
573
574 #ifndef SWIG
575
576 BEGIN_DECLARE_EVENT_TYPES()
577 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, 0)
578 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, 0)
579 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, 0)
580 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, 0)
581 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, 0)
582 END_DECLARE_EVENT_TYPES()
583
584 typedef void (wxEvtHandler::*wxAuiToolBarEventFunction)(wxAuiToolBarEvent&);
585
586 #define wxAuiToolBarEventHandler(func) \
587 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiToolBarEventFunction, &func)
588
589 #define EVT_AUITOOLBAR_TOOL_DROPDOWN(winid, fn) \
590 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, winid, wxAuiToolBarEventHandler(fn))
591 #define EVT_AUITOOLBAR_OVERFLOW_CLICK(winid, fn) \
592 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, winid, wxAuiToolBarEventHandler(fn))
593 #define EVT_AUITOOLBAR_RIGHT_CLICK(winid, fn) \
594 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, winid, wxAuiToolBarEventHandler(fn))
595 #define EVT_AUITOOLBAR_MIDDLE_CLICK(winid, fn) \
596 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, winid, wxAuiToolBarEventHandler(fn))
597 #define EVT_AUITOOLBAR_BEGIN_DRAG(winid, fn) \
598 wx__DECLARE_EVT1(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, winid, wxAuiToolBarEventHandler(fn))
599
600 #else
601
602 // wxpython/swig event work
603 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN;
604 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK;
605 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK;
606 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK;
607 %constant wxEventType wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG;
608
609 %pythoncode {
610 EVT_AUITOOLBAR_TOOL_DROPDOWN = wx.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, 1 )
611 EVT_AUITOOLBAR_OVERFLOW_CLICK = wx.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, 1 )
612 EVT_AUITOOLBAR_RIGHT_CLICK = wx.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, 1 )
613 EVT_AUITOOLBAR_MIDDLE_CLICK = wx.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, 1 )
614 EVT_AUITOOLBAR_BEGIN_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, 1 )
615 }
616 #endif // SWIG
617
618 #endif // wxUSE_AUI
619 #endif // _WX_AUIBAR_H_
620