]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
3 | // Purpose: GTK toolbar | |
4 | // Author: Robert Roebling | |
32e9da8b | 5 | // RCS-ID: $Id$ |
c801d85f | 6 | // Copyright: (c) Robert Roebling |
a3622daa | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "tbargtk.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/toolbar.h" | |
15 | ||
314055fa RR |
16 | //----------------------------------------------------------------------------- |
17 | // data | |
18 | //----------------------------------------------------------------------------- | |
19 | ||
20 | extern bool g_blockEventsOnDrag; | |
21 | ||
c801d85f KB |
22 | //----------------------------------------------------------------------------- |
23 | // wxToolBarTool | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject) | |
a3622daa VZ |
27 | |
28 | wxToolBarTool::wxToolBarTool( wxToolBar *owner, int theIndex, | |
03f38c58 VZ |
29 | const wxBitmap& bitmap1, const wxBitmap& bitmap2, |
30 | bool toggle, | |
31 | wxObject *clientData, | |
32 | const wxString& shortHelpString, | |
33 | const wxString& longHelpString, | |
34 | GtkWidget *item ) | |
c801d85f KB |
35 | { |
36 | m_owner = owner; | |
37 | m_index = theIndex; | |
38 | m_bitmap1 = bitmap1; | |
39 | m_bitmap2 = bitmap2; | |
40 | m_isToggle = toggle; | |
41 | m_enabled = TRUE; | |
42 | m_toggleState = FALSE; | |
43 | m_shortHelpString = shortHelpString; | |
44 | m_longHelpString = longHelpString; | |
45 | m_isMenuCommand = TRUE; | |
46 | m_clientData = clientData; | |
47 | m_deleteSecondBitmap = FALSE; | |
fc008f25 RR |
48 | m_item = item; |
49 | } | |
c801d85f | 50 | |
a3622daa | 51 | wxToolBarTool::~wxToolBarTool() |
c801d85f | 52 | { |
fc008f25 | 53 | } |
c801d85f KB |
54 | |
55 | //----------------------------------------------------------------------------- | |
2f2aa628 | 56 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
57 | //----------------------------------------------------------------------------- |
58 | ||
59 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) | |
60 | { | |
314055fa | 61 | if (g_blockEventsOnDrag) return; |
c801d85f | 62 | if (!tool->m_enabled) return; |
a3622daa | 63 | |
c801d85f | 64 | if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState; |
a3622daa | 65 | |
c801d85f | 66 | tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState ); |
fc008f25 | 67 | } |
c801d85f | 68 | |
2f2aa628 RR |
69 | //----------------------------------------------------------------------------- |
70 | // "enter_notify_event" | |
71 | //----------------------------------------------------------------------------- | |
72 | ||
314055fa RR |
73 | static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), |
74 | GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) | |
75 | { | |
76 | if (g_blockEventsOnDrag) return TRUE; | |
77 | ||
78 | tool->m_owner->OnMouseEnter( tool->m_index ); | |
79 | ||
83058c58 | 80 | return FALSE; |
314055fa RR |
81 | } |
82 | ||
2f2aa628 RR |
83 | //----------------------------------------------------------------------------- |
84 | // wxToolBar | |
c801d85f KB |
85 | //----------------------------------------------------------------------------- |
86 | ||
716b7364 | 87 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl) |
c801d85f | 88 | |
a3622daa | 89 | wxToolBar::wxToolBar() |
c801d85f | 90 | { |
fc008f25 | 91 | } |
c801d85f | 92 | |
a3622daa | 93 | wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id, |
c801d85f | 94 | const wxPoint& pos, const wxSize& size, |
debe6624 | 95 | long style, const wxString& name ) |
c801d85f KB |
96 | { |
97 | Create( parent, id, pos, size, style, name ); | |
fc008f25 | 98 | } |
c801d85f | 99 | |
a3622daa | 100 | wxToolBar::~wxToolBar() |
c801d85f | 101 | { |
fc008f25 | 102 | } |
c801d85f | 103 | |
a3622daa | 104 | bool wxToolBar::Create( wxWindow *parent, wxWindowID id, |
c801d85f | 105 | const wxPoint& pos, const wxSize& size, |
debe6624 | 106 | long style, const wxString& name ) |
c801d85f KB |
107 | { |
108 | m_needParent = TRUE; | |
a3622daa | 109 | |
c801d85f KB |
110 | PreCreation( parent, id, pos, size, style, name ); |
111 | ||
112 | m_tools.DeleteContents( TRUE ); | |
a3622daa | 113 | |
68dda785 VZ |
114 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, |
115 | GTK_TOOLBAR_ICONS ) ); | |
a3622daa | 116 | |
32e9da8b RR |
117 | m_widget = GTK_WIDGET(m_toolbar); |
118 | ||
119 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); | |
a3622daa | 120 | |
c801d85f | 121 | PostCreation(); |
a3622daa | 122 | |
c801d85f | 123 | Show( TRUE ); |
a3622daa | 124 | |
c801d85f | 125 | return TRUE; |
fc008f25 | 126 | } |
c801d85f | 127 | |
716b7364 | 128 | bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown ) |
c801d85f | 129 | { |
cf4219e7 | 130 | wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex ); |
c801d85f | 131 | event.SetEventObject(this); |
46dc76ba | 132 | event.SetInt( toolIndex ); |
c801d85f KB |
133 | event.SetExtraLong((long) toggleDown); |
134 | ||
135 | GetEventHandler()->ProcessEvent(event); | |
136 | ||
137 | return TRUE; | |
fc008f25 | 138 | } |
c801d85f | 139 | |
716b7364 | 140 | void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) ) |
c801d85f | 141 | { |
cf4219e7 | 142 | wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex ); |
46dc76ba RR |
143 | event.SetEventObject( this ); |
144 | event.SetInt( toolIndex ); | |
c801d85f KB |
145 | |
146 | GetEventHandler()->ProcessEvent(event); | |
fc008f25 | 147 | } |
c801d85f | 148 | |
716b7364 | 149 | void wxToolBar::OnMouseEnter( int toolIndex ) |
c801d85f | 150 | { |
314055fa | 151 | wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() ); |
c801d85f | 152 | event.SetEventObject(this); |
46dc76ba | 153 | event.SetInt( toolIndex ); |
314055fa | 154 | |
c801d85f | 155 | GetEventHandler()->ProcessEvent(event); |
fc008f25 | 156 | } |
c801d85f | 157 | |
a3622daa | 158 | wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, |
debe6624 JS |
159 | const wxBitmap& pushedBitmap, bool toggle, |
160 | float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData, | |
c801d85f KB |
161 | const wxString& helpString1, const wxString& helpString2 ) |
162 | { | |
03f38c58 VZ |
163 | wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL, |
164 | "invalid bitmap for wxToolBar icon" ); | |
a3622daa | 165 | |
03f38c58 VZ |
166 | wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, |
167 | toggle, clientData, | |
168 | helpString1, helpString2 ); | |
a3622daa | 169 | |
03f38c58 VZ |
170 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL, |
171 | "wxToolBar doesn't support GdkBitmap" ); | |
172 | ||
173 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL, | |
174 | "wxToolBar::Add needs a wxBitmap" ); | |
903f689b | 175 | |
68dda785 | 176 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
903f689b | 177 | |
03f38c58 | 178 | if (TRUE) // FIXME huh? |
903f689b RR |
179 | { |
180 | GdkPixmap *pixmap = bitmap.GetPixmap(); | |
a3622daa | 181 | |
68dda785 VZ |
182 | GdkBitmap *mask = (GdkBitmap *)NULL; |
183 | if ( bitmap.GetMask() ) | |
184 | mask = bitmap.GetMask()->GetBitmap(); | |
903f689b RR |
185 | |
186 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); | |
187 | } | |
188 | ||
c801d85f | 189 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 190 | |
03f38c58 VZ |
191 | GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON |
192 | : GTK_TOOLBAR_CHILD_BUTTON; | |
193 | ||
68dda785 VZ |
194 | GtkWidget *item = gtk_toolbar_append_element |
195 | ( | |
196 | GTK_TOOLBAR(m_toolbar), | |
197 | ctype, | |
198 | (GtkWidget *)NULL, | |
199 | (const char *)NULL, | |
200 | helpString1, | |
201 | "", | |
202 | tool_pixmap, | |
203 | (GtkSignalFunc)gtk_toolbar_callback, | |
204 | (gpointer)tool | |
205 | ); | |
206 | ||
68dda785 | 207 | tool->m_item = item; |
03f38c58 VZ |
208 | |
209 | gtk_signal_connect( GTK_OBJECT(tool->m_item), | |
210 | "enter_notify_event", | |
211 | GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback), | |
212 | (gpointer)tool ); | |
314055fa | 213 | |
a3622daa VZ |
214 | m_tools.Append( tool ); |
215 | ||
c801d85f | 216 | return tool; |
fc008f25 | 217 | } |
c801d85f | 218 | |
03f38c58 | 219 | void wxToolBar::AddSeparator() |
c801d85f KB |
220 | { |
221 | gtk_toolbar_append_space( m_toolbar ); | |
fc008f25 | 222 | } |
c801d85f | 223 | |
03f38c58 | 224 | void wxToolBar::ClearTools() |
c801d85f | 225 | { |
fc008f25 RR |
226 | wxFAIL_MSG( "wxToolBar::ClearTools not implemented" ); |
227 | } | |
c801d85f | 228 | |
03f38c58 | 229 | void wxToolBar::Realize() |
46dc76ba RR |
230 | { |
231 | m_x = 0; | |
232 | m_y = 0; | |
233 | m_width = 100; | |
234 | m_height = 0; | |
235 | ||
236 | wxNode *node = m_tools.First(); | |
237 | while (node) | |
238 | { | |
239 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
240 | if (tool->m_bitmap1.Ok()) | |
241 | { | |
242 | int tool_height = tool->m_bitmap1.GetHeight(); | |
243 | if (tool_height > m_height) m_height = tool_height; | |
fc008f25 | 244 | } |
46dc76ba RR |
245 | |
246 | node = node->Next(); | |
fc008f25 | 247 | } |
46dc76ba RR |
248 | |
249 | m_height += 10; | |
fc008f25 | 250 | } |
46dc76ba | 251 | |
716b7364 | 252 | void wxToolBar::EnableTool(int toolIndex, bool enable) |
c801d85f | 253 | { |
cf4219e7 RR |
254 | wxNode *node = m_tools.First(); |
255 | while (node) | |
256 | { | |
257 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
258 | if (tool->m_index == toolIndex) | |
259 | { | |
260 | tool->m_enabled = enable; | |
261 | return; | |
262 | } | |
263 | node = node->Next(); | |
fc008f25 RR |
264 | } |
265 | ||
266 | wxFAIL_MSG( "wrong toolbar index" ); | |
267 | } | |
c801d85f | 268 | |
fc008f25 | 269 | void wxToolBar::ToggleTool( int toolIndex, bool toggle ) |
c801d85f | 270 | { |
fc008f25 RR |
271 | wxNode *node = m_tools.First(); |
272 | while (node) | |
273 | { | |
274 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
275 | if (tool->m_index == toolIndex) | |
276 | { | |
277 | tool->m_toggleState = toggle; | |
278 | if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item))) | |
279 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle ); | |
280 | return; | |
281 | } | |
282 | node = node->Next(); | |
283 | } | |
284 | ||
285 | wxFAIL_MSG( "wrong toolbar index" ); | |
286 | } | |
c801d85f | 287 | |
fc008f25 | 288 | wxObject *wxToolBar::GetToolClientData( int index ) const |
c801d85f | 289 | { |
cf4219e7 RR |
290 | wxNode *node = m_tools.First(); |
291 | while (node) | |
292 | { | |
293 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
294 | if (tool->m_index == index) return tool->m_clientData;; | |
295 | node = node->Next(); | |
fc008f25 RR |
296 | } |
297 | ||
298 | wxFAIL_MSG( "wrong toolbar index" ); | |
299 | ||
cf4219e7 | 300 | return (wxObject*)NULL; |
fc008f25 | 301 | } |
c801d85f | 302 | |
716b7364 | 303 | bool wxToolBar::GetToolState(int toolIndex) const |
c801d85f | 304 | { |
cf4219e7 RR |
305 | wxNode *node = m_tools.First(); |
306 | while (node) | |
307 | { | |
308 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
309 | if (tool->m_index == toolIndex) return tool->m_toggleState; | |
310 | node = node->Next(); | |
fc008f25 RR |
311 | } |
312 | ||
313 | wxFAIL_MSG( "wrong toolbar index" ); | |
314 | ||
cf4219e7 | 315 | return FALSE; |
fc008f25 | 316 | } |
c801d85f | 317 | |
716b7364 | 318 | bool wxToolBar::GetToolEnabled(int toolIndex) const |
c801d85f | 319 | { |
cf4219e7 RR |
320 | wxNode *node = m_tools.First(); |
321 | while (node) | |
322 | { | |
323 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
324 | if (tool->m_index == toolIndex) return tool->m_enabled; | |
325 | node = node->Next(); | |
fc008f25 RR |
326 | } |
327 | ||
328 | wxFAIL_MSG( "wrong toolbar index" ); | |
329 | ||
cf4219e7 | 330 | return FALSE; |
fc008f25 | 331 | } |
c801d85f | 332 | |
cf4219e7 | 333 | void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) ) |
c801d85f | 334 | { |
03f38c58 | 335 | wxFAIL_MSG( "wxToolBar::SetMargins not implemented" ); |
fc008f25 | 336 | } |
c801d85f | 337 | |
cf4219e7 | 338 | void wxToolBar::SetToolPacking( int WXUNUSED(packing) ) |
c801d85f | 339 | { |
03f38c58 | 340 | wxFAIL_MSG( "wxToolBar::SetToolPacking not implemented" ); |
fc008f25 | 341 | } |
c801d85f | 342 | |
cf4219e7 | 343 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 344 | { |
cf4219e7 | 345 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
fc008f25 | 346 | } |
c801d85f | 347 |