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