]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ribbon/buttonbar.h
Add XRC handler for wxBannerWindow and a test for it to the xrc sample.
[wxWidgets.git] / include / wx / ribbon / buttonbar.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/buttonbar.h
3 // Purpose: Ribbon control similar to a tool bar
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-07-01
7 // RCS-ID: $Id$
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RIBBON_BUTTON_BAR_H_
12 #define _WX_RIBBON_BUTTON_BAR_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_RIBBON
17
18 #include "wx/ribbon/art.h"
19 #include "wx/ribbon/control.h"
20 #include "wx/dynarray.h"
21
22 class wxRibbonButtonBarButtonBase;
23 class wxRibbonButtonBarLayout;
24 class wxRibbonButtonBarButtonInstance;
25
26 WX_DEFINE_USER_EXPORTED_ARRAY(wxRibbonButtonBarLayout*, wxArrayRibbonButtonBarLayout, class WXDLLIMPEXP_RIBBON);
27 WX_DEFINE_USER_EXPORTED_ARRAY(wxRibbonButtonBarButtonBase*, wxArrayRibbonButtonBarButtonBase, class WXDLLIMPEXP_RIBBON);
28
29 class WXDLLIMPEXP_RIBBON wxRibbonButtonBar : public wxRibbonControl
30 {
31 public:
32 wxRibbonButtonBar();
33
34 wxRibbonButtonBar(wxWindow* parent,
35 wxWindowID id = wxID_ANY,
36 const wxPoint& pos = wxDefaultPosition,
37 const wxSize& size = wxDefaultSize,
38 long style = 0);
39
40 virtual ~wxRibbonButtonBar();
41
42 bool Create(wxWindow* parent,
43 wxWindowID id = wxID_ANY,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0);
47
48 virtual wxRibbonButtonBarButtonBase* AddButton(
49 int button_id,
50 const wxString& label,
51 const wxBitmap& bitmap,
52 const wxString& help_string,
53 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
54 // NB: help_string cannot be optional as that would cause the signature
55 // to be identical to the full version of AddButton when 3 arguments are
56 // given.
57
58 virtual wxRibbonButtonBarButtonBase* AddDropdownButton(
59 int button_id,
60 const wxString& label,
61 const wxBitmap& bitmap,
62 const wxString& help_string = wxEmptyString);
63
64 virtual wxRibbonButtonBarButtonBase* AddHybridButton(
65 int button_id,
66 const wxString& label,
67 const wxBitmap& bitmap,
68 const wxString& help_string = wxEmptyString);
69
70 virtual wxRibbonButtonBarButtonBase* AddToggleButton(
71 int button_id,
72 const wxString& label,
73 const wxBitmap& bitmap,
74 const wxString& help_string = wxEmptyString);
75
76 virtual wxRibbonButtonBarButtonBase* AddButton(
77 int button_id,
78 const wxString& label,
79 const wxBitmap& bitmap,
80 const wxBitmap& bitmap_small = wxNullBitmap,
81 const wxBitmap& bitmap_disabled = wxNullBitmap,
82 const wxBitmap& bitmap_small_disabled = wxNullBitmap,
83 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
84 const wxString& help_string = wxEmptyString,
85 wxObject* client_data = NULL);
86
87 virtual bool Realize();
88 virtual void ClearButtons();
89 virtual bool DeleteButton(int button_id);
90 virtual void EnableButton(int button_id, bool enable = true);
91 virtual void ToggleButton(int button_id, bool checked);
92
93 virtual void SetArtProvider(wxRibbonArtProvider* art);
94 virtual bool IsSizingContinuous() const;
95
96 virtual wxSize GetMinSize() const;
97 protected:
98 friend class wxRibbonButtonBarEvent;
99 virtual wxSize DoGetBestSize() const;
100 wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
101
102 void OnEraseBackground(wxEraseEvent& evt);
103 void OnPaint(wxPaintEvent& evt);
104 void OnSize(wxSizeEvent& evt);
105 void OnMouseMove(wxMouseEvent& evt);
106 void OnMouseEnter(wxMouseEvent& evt);
107 void OnMouseLeave(wxMouseEvent& evt);
108 void OnMouseDown(wxMouseEvent& evt);
109 void OnMouseUp(wxMouseEvent& evt);
110
111 virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
112 wxSize relative_to) const;
113 virtual wxSize DoGetNextLargerSize(wxOrientation direction,
114 wxSize relative_to) const;
115
116 void CommonInit(long style);
117 void MakeLayouts();
118 bool TryCollapseLayout(wxRibbonButtonBarLayout* original, size_t first_btn, size_t* last_button);
119 static wxBitmap MakeResizedBitmap(const wxBitmap& original, wxSize size);
120 static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
121 void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
122 wxRibbonButtonBarButtonState size, wxDC& dc);
123
124 wxArrayRibbonButtonBarLayout m_layouts;
125 wxArrayRibbonButtonBarButtonBase m_buttons;
126 wxRibbonButtonBarButtonInstance* m_hovered_button;
127 wxRibbonButtonBarButtonInstance* m_active_button;
128
129 wxPoint m_layout_offset;
130 wxSize m_bitmap_size_large;
131 wxSize m_bitmap_size_small;
132 int m_current_layout;
133 bool m_layouts_valid;
134 bool m_lock_active_state;
135
136 #ifndef SWIG
137 DECLARE_CLASS(wxRibbonButtonBar)
138 DECLARE_EVENT_TABLE()
139 #endif
140 };
141
142 class WXDLLIMPEXP_RIBBON wxRibbonButtonBarEvent : public wxCommandEvent
143 {
144 public:
145 wxRibbonButtonBarEvent(wxEventType command_type = wxEVT_NULL,
146 int win_id = 0,
147 wxRibbonButtonBar* bar = NULL)
148 : wxCommandEvent(command_type, win_id)
149 , m_bar(bar)
150 {
151 }
152 #ifndef SWIG
153 wxRibbonButtonBarEvent(const wxRibbonButtonBarEvent& e) : wxCommandEvent(e)
154 {
155 m_bar = e.m_bar;
156 }
157 #endif
158 wxEvent *Clone() const { return new wxRibbonButtonBarEvent(*this); }
159
160 wxRibbonButtonBar* GetBar() {return m_bar;}
161 void SetBar(wxRibbonButtonBar* bar) {m_bar = bar;}
162 bool PopupMenu(wxMenu* menu);
163
164 protected:
165 wxRibbonButtonBar* m_bar;
166
167 #ifndef SWIG
168 private:
169 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonButtonBarEvent)
170 #endif
171 };
172
173 #ifndef SWIG
174
175 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBUTTON_CLICKED, wxRibbonButtonBarEvent);
176 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, wxRibbonButtonBarEvent);
177
178 typedef void (wxEvtHandler::*wxRibbonButtonBarEventFunction)(wxRibbonButtonBarEvent&);
179
180 #define wxRibbonButtonBarEventHandler(func) \
181 wxEVENT_HANDLER_CAST(wxRibbonButtonBarEventFunction, func)
182
183 #define EVT_RIBBONBUTTONBAR_CLICKED(winid, fn) \
184 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
185 #define EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(winid, fn) \
186 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
187 #else
188
189 // wxpython/swig event work
190 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_CLICKED;
191 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED;
192
193 %pythoncode {
194 EVT_RIBBONBUTTONBAR_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_CLICKED, 1 )
195 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, 1 )
196 }
197 #endif
198
199 #endif // wxUSE_RIBBON
200
201 #endif // _WX_RIBBON_BUTTON_BAR_H_