]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
0b83552a | 2 | // Name: src/gtk1/toolbar.cpp |
c801d85f KB |
3 | // Purpose: GTK toolbar |
4 | // Author: Robert Roebling | |
8a0681f9 | 5 | // Modified: 13.12.99 by VZ to derive from wxToolBarBase |
32e9da8b | 6 | // RCS-ID: $Id$ |
c801d85f | 7 | // Copyright: (c) Robert Roebling |
65571936 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
8a0681f9 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
14f355c2 VS |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
8a0681f9 | 22 | #if wxUSE_TOOLBAR_NATIVE |
dcf924a3 | 23 | |
4e3e485b WS |
24 | #include "wx/toolbar.h" |
25 | ||
76b49cf4 WS |
26 | #ifndef WX_PRECOMP |
27 | #include "wx/frame.h" | |
28 | #endif | |
c801d85f | 29 | |
9e691f46 | 30 | #include <glib.h> |
3cbab641 | 31 | #include "wx/gtk1/private.h" |
83624f79 | 32 | |
8a0681f9 VZ |
33 | // ---------------------------------------------------------------------------- |
34 | // globals | |
35 | // ---------------------------------------------------------------------------- | |
acfd422a | 36 | |
8a0681f9 | 37 | // idle system |
acfd422a RR |
38 | extern void wxapp_install_idle_handler(); |
39 | extern bool g_isIdle; | |
40 | ||
314055fa | 41 | // data |
9b7e522a RR |
42 | extern bool g_blockEventsOnDrag; |
43 | extern wxCursor g_globalCursor; | |
314055fa | 44 | |
e76c0b5f VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // private functions | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
77ffb593 | 49 | // translate wxWidgets toolbar style flags to GTK orientation and style |
e76c0b5f VZ |
50 | static void GetGtkStyle(long style, |
51 | GtkOrientation *orient, GtkToolbarStyle *gtkStyle) | |
52 | { | |
53 | *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL | |
54 | : GTK_ORIENTATION_HORIZONTAL; | |
55 | ||
56 | ||
57 | if ( style & wxTB_TEXT ) | |
58 | { | |
99e8cb50 VZ |
59 | *gtkStyle = style & wxTB_NOICONS |
60 | ? GTK_TOOLBAR_TEXT | |
3cbab641 | 61 | : GTK_TOOLBAR_BOTH; |
e76c0b5f VZ |
62 | } |
63 | else // no text, hence we must have the icons or what would we show? | |
64 | { | |
65 | *gtkStyle = GTK_TOOLBAR_ICONS; | |
66 | } | |
67 | } | |
68 | ||
8a0681f9 VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // wxToolBarTool | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
73 | class wxToolBarTool : public wxToolBarToolBase | |
74 | { | |
75 | public: | |
76 | wxToolBarTool(wxToolBar *tbar, | |
77 | int id, | |
e76c0b5f | 78 | const wxString& label, |
8a0681f9 VZ |
79 | const wxBitmap& bitmap1, |
80 | const wxBitmap& bitmap2, | |
e76c0b5f | 81 | wxItemKind kind, |
8a0681f9 VZ |
82 | wxObject *clientData, |
83 | const wxString& shortHelpString, | |
84 | const wxString& longHelpString) | |
e76c0b5f | 85 | : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
86 | clientData, shortHelpString, longHelpString) |
87 | { | |
88 | Init(); | |
89 | } | |
90 | ||
07d02e9e VZ |
91 | wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) |
92 | : wxToolBarToolBase(tbar, control, label) | |
8a0681f9 VZ |
93 | { |
94 | Init(); | |
95 | } | |
96 | ||
38762f09 VZ |
97 | // is this a radio button? |
98 | // | |
99 | // unlike GetKind(), can be called for any kind of tools, not just buttons | |
100 | bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; } | |
101 | ||
e76c0b5f VZ |
102 | // this is only called for the normal buttons, i.e. not separators nor |
103 | // controls | |
104 | GtkToolbarChildType GetGtkChildType() const | |
105 | { | |
106 | switch ( GetKind() ) | |
107 | { | |
108 | case wxITEM_CHECK: | |
109 | return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
110 | ||
111 | case wxITEM_RADIO: | |
112 | return GTK_TOOLBAR_CHILD_RADIOBUTTON; | |
113 | ||
114 | default: | |
9a83f860 | 115 | wxFAIL_MSG( wxT("unknown toolbar child type") ); |
e76c0b5f VZ |
116 | // fall through |
117 | ||
118 | case wxITEM_NORMAL: | |
119 | return GTK_TOOLBAR_CHILD_BUTTON; | |
120 | } | |
121 | } | |
122 | ||
ab86c659 VS |
123 | void SetPixmap(const wxBitmap& bitmap) |
124 | { | |
a1b806b9 | 125 | if (bitmap.IsOk()) |
ab86c659 VS |
126 | { |
127 | GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() | |
d3b9f782 | 128 | : NULL; |
3cbab641 | 129 | gtk_pixmap_set( GTK_PIXMAP(m_pixmap), bitmap.GetPixmap(), mask ); |
ab86c659 VS |
130 | } |
131 | } | |
132 | ||
8a0681f9 VZ |
133 | GtkWidget *m_item; |
134 | GtkWidget *m_pixmap; | |
135 | ||
136 | protected: | |
137 | void Init(); | |
138 | }; | |
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // wxWin macros | |
142 | // ---------------------------------------------------------------------------- | |
143 | ||
2eb10e2a | 144 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
8a0681f9 VZ |
145 | |
146 | // ============================================================================ | |
147 | // implementation | |
148 | // ============================================================================ | |
149 | ||
c801d85f | 150 | //----------------------------------------------------------------------------- |
2f2aa628 | 151 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
152 | //----------------------------------------------------------------------------- |
153 | ||
865bb325 | 154 | extern "C" { |
8a0681f9 VZ |
155 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), |
156 | wxToolBarTool *tool ) | |
c801d85f | 157 | { |
248bcf0a | 158 | if (g_isIdle) |
59fe1666 RR |
159 | wxapp_install_idle_handler(); |
160 | ||
8a0681f9 | 161 | wxToolBar *tbar = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 162 | |
9864c56d | 163 | if (tbar->m_blockEvent) return; |
acfd422a | 164 | |
1144d24d | 165 | if (g_blockEventsOnDrag) return; |
8a0681f9 | 166 | if (!tool->IsEnabled()) return; |
a3622daa | 167 | |
8a0681f9 | 168 | if (tool->CanBeToggled()) |
248bcf0a | 169 | { |
8a0681f9 VZ |
170 | tool->Toggle(); |
171 | ||
ab86c659 | 172 | tool->SetPixmap(tool->GetBitmap()); |
38762f09 VZ |
173 | |
174 | if ( tool->IsRadio() && !tool->IsToggled() ) | |
175 | { | |
176 | // radio button went up, don't report this as a wxWin event | |
177 | return; | |
178 | } | |
85eb36c2 | 179 | } |
a3622daa | 180 | |
6bb7cee4 VZ |
181 | if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() ) |
182 | { | |
183 | // revert back | |
184 | tool->Toggle(); | |
185 | ||
ab86c659 | 186 | tool->SetPixmap(tool->GetBitmap()); |
6bb7cee4 | 187 | } |
fc008f25 | 188 | } |
865bb325 | 189 | } |
c801d85f | 190 | |
2f2aa628 | 191 | //----------------------------------------------------------------------------- |
a8945eef | 192 | // "enter_notify_event" / "leave_notify_event" |
2f2aa628 RR |
193 | //----------------------------------------------------------------------------- |
194 | ||
865bb325 | 195 | extern "C" { |
248bcf0a | 196 | static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget), |
a8945eef MB |
197 | GdkEventCrossing *gdk_event, |
198 | wxToolBarTool *tool ) | |
314055fa | 199 | { |
acfd422a RR |
200 | if (g_isIdle) wxapp_install_idle_handler(); |
201 | ||
1144d24d | 202 | if (g_blockEventsOnDrag) return TRUE; |
248bcf0a | 203 | |
8a0681f9 | 204 | wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); |
248bcf0a | 205 | |
47c93b63 | 206 | // emit the event |
a8945eef MB |
207 | if( gdk_event->type == GDK_ENTER_NOTIFY ) |
208 | tb->OnMouseEnter( tool->GetId() ); | |
209 | else | |
210 | tb->OnMouseEnter( -1 ); | |
248bcf0a | 211 | |
1144d24d | 212 | return FALSE; |
314055fa | 213 | } |
865bb325 | 214 | } |
314055fa | 215 | |
bf9e3e73 RR |
216 | //----------------------------------------------------------------------------- |
217 | // InsertChild callback for wxToolBar | |
218 | //----------------------------------------------------------------------------- | |
219 | ||
8a0681f9 VZ |
220 | static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), |
221 | wxWindow* WXUNUSED(child) ) | |
bf9e3e73 | 222 | { |
47c93b63 | 223 | // we don't do anything here |
bf9e3e73 RR |
224 | } |
225 | ||
8a0681f9 VZ |
226 | // ---------------------------------------------------------------------------- |
227 | // wxToolBarTool | |
228 | // ---------------------------------------------------------------------------- | |
c801d85f | 229 | |
8a0681f9 VZ |
230 | void wxToolBarTool::Init() |
231 | { | |
232 | m_item = | |
d3b9f782 | 233 | m_pixmap = NULL; |
8a0681f9 | 234 | } |
c801d85f | 235 | |
8a0681f9 | 236 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
e76c0b5f | 237 | const wxString& text, |
8a0681f9 VZ |
238 | const wxBitmap& bitmap1, |
239 | const wxBitmap& bitmap2, | |
e76c0b5f | 240 | wxItemKind kind, |
8a0681f9 VZ |
241 | wxObject *clientData, |
242 | const wxString& shortHelpString, | |
243 | const wxString& longHelpString) | |
244 | { | |
e76c0b5f | 245 | return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind, |
8a0681f9 VZ |
246 | clientData, shortHelpString, longHelpString); |
247 | } | |
b1da76e1 | 248 | |
07d02e9e VZ |
249 | wxToolBarToolBase * |
250 | wxToolBar::CreateTool(wxControl *control, const wxString& label) | |
c801d85f | 251 | { |
07d02e9e | 252 | return new wxToolBarTool(this, control, label); |
fc008f25 | 253 | } |
c801d85f | 254 | |
8a0681f9 VZ |
255 | //----------------------------------------------------------------------------- |
256 | // wxToolBar construction | |
257 | //----------------------------------------------------------------------------- | |
258 | ||
259 | void wxToolBar::Init() | |
c801d85f | 260 | { |
d3b9f782 | 261 | m_toolbar = NULL; |
91af0895 | 262 | m_blockEvent = false; |
d2c0a964 RD |
263 | m_defaultWidth = 32; |
264 | m_defaultHeight = 32; | |
fc008f25 | 265 | } |
c801d85f | 266 | |
a3622daa | 267 | wxToolBar::~wxToolBar() |
c801d85f | 268 | { |
fc008f25 | 269 | } |
c801d85f | 270 | |
8a0681f9 VZ |
271 | bool wxToolBar::Create( wxWindow *parent, |
272 | wxWindowID id, | |
273 | const wxPoint& pos, | |
274 | const wxSize& size, | |
275 | long style, | |
276 | const wxString& name ) | |
c801d85f | 277 | { |
91af0895 | 278 | m_needParent = true; |
bf9e3e73 | 279 | m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar; |
a3622daa | 280 | |
8a0681f9 VZ |
281 | if ( !PreCreation( parent, pos, size ) || |
282 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
4dcaf11a | 283 | { |
223d09f6 | 284 | wxFAIL_MSG( wxT("wxToolBar creation failed") ); |
c801d85f | 285 | |
91af0895 | 286 | return false; |
8a0681f9 | 287 | } |
a3622daa | 288 | |
d408730c VZ |
289 | FixupStyle(); |
290 | ||
e76c0b5f VZ |
291 | GtkOrientation orient; |
292 | GtkToolbarStyle gtkStyle; | |
293 | GetGtkStyle(style, &orient, >kStyle); | |
294 | ||
295 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new(orient, gtkStyle) ); | |
a3622daa | 296 | |
8a0681f9 | 297 | SetToolSeparation(7); |
3502e687 RR |
298 | |
299 | if (style & wxTB_DOCKABLE) | |
300 | { | |
301 | m_widget = gtk_handle_box_new(); | |
f03fc89f VZ |
302 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
303 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); | |
8a0681f9 | 304 | |
f03fc89f | 305 | if (style & wxTB_FLAT) |
858b5bdd | 306 | gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); |
3502e687 RR |
307 | } |
308 | else | |
248bcf0a RD |
309 | { |
310 | m_widget = gtk_event_box_new(); | |
311 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); | |
312 | ConnectWidget( m_widget ); | |
313 | gtk_widget_show(GTK_WIDGET(m_toolbar)); | |
3502e687 | 314 | } |
8a0681f9 | 315 | |
1144d24d | 316 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); |
8a0681f9 | 317 | |
858b5bdd RR |
318 | if (style & wxTB_FLAT) |
319 | gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE ); | |
be25e480 | 320 | |
f03fc89f | 321 | m_parent->DoAddChild( this ); |
8a0681f9 | 322 | |
abdeb9e7 | 323 | PostCreation(size); |
a3622daa | 324 | |
91af0895 | 325 | return true; |
fc008f25 | 326 | } |
c801d85f | 327 | |
e76c0b5f VZ |
328 | void wxToolBar::GtkSetStyle() |
329 | { | |
330 | GtkOrientation orient; | |
331 | GtkToolbarStyle style; | |
332 | GetGtkStyle(GetWindowStyle(), &orient, &style); | |
333 | ||
334 | gtk_toolbar_set_orientation(m_toolbar, orient); | |
335 | gtk_toolbar_set_style(m_toolbar, style); | |
336 | } | |
337 | ||
338 | void wxToolBar::SetWindowStyleFlag( long style ) | |
339 | { | |
340 | wxToolBarBase::SetWindowStyleFlag(style); | |
341 | ||
342 | if ( m_toolbar ) | |
343 | GtkSetStyle(); | |
344 | } | |
345 | ||
8a0681f9 | 346 | bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) |
c801d85f | 347 | { |
8a0681f9 | 348 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 349 | |
6a1359c0 VZ |
350 | // if we have inserted a space before all the tools we must change the GTK |
351 | // index by 1 | |
352 | size_t posGtk = m_xMargin > 1 ? pos + 1 : pos; | |
248bcf0a | 353 | |
8a0681f9 VZ |
354 | if ( tool->IsButton() ) |
355 | { | |
2b5f62a0 VZ |
356 | if ( !HasFlag(wxTB_NOICONS) ) |
357 | { | |
358 | wxBitmap bitmap = tool->GetNormalBitmap(); | |
c801d85f | 359 | |
a1b806b9 | 360 | wxCHECK_MSG( bitmap.IsOk(), false, |
2b5f62a0 | 361 | wxT("invalid bitmap for wxToolBar icon") ); |
a3622daa | 362 | |
91af0895 | 363 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, false, |
2b5f62a0 | 364 | wxT("wxToolBar doesn't support GdkBitmap") ); |
03f38c58 | 365 | |
91af0895 | 366 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, false, |
2b5f62a0 | 367 | wxT("wxToolBar::Add needs a wxBitmap") ); |
248bcf0a | 368 | |
d3b9f782 | 369 | GtkWidget *tool_pixmap = NULL; |
248bcf0a | 370 | |
3cbab641 | 371 | GdkPixmap *pixmap = bitmap.GetPixmap(); |
ab86c659 | 372 | |
d3b9f782 | 373 | GdkBitmap *mask = NULL; |
3cbab641 MR |
374 | if ( bitmap.GetMask() ) |
375 | mask = bitmap.GetMask()->GetBitmap(); | |
a3622daa | 376 | |
3cbab641 MR |
377 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); |
378 | gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE ); | |
248bcf0a | 379 | |
2b5f62a0 | 380 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 381 | |
2b5f62a0 VZ |
382 | tool->m_pixmap = tool_pixmap; |
383 | } | |
8a0681f9 | 384 | } |
c801d85f | 385 | |
8a0681f9 VZ |
386 | switch ( tool->GetStyle() ) |
387 | { | |
388 | case wxTOOL_STYLE_BUTTON: | |
38762f09 VZ |
389 | // for a radio button we need the widget which starts the radio |
390 | // group it belongs to, i.e. the first radio button immediately | |
391 | // preceding this one | |
8a0681f9 | 392 | { |
38762f09 VZ |
393 | GtkWidget *widget = NULL; |
394 | ||
395 | if ( tool->IsRadio() ) | |
396 | { | |
98fc1d65 MB |
397 | wxToolBarToolsList::compatibility_iterator node |
398 | = wxToolBarToolsList::compatibility_iterator(); | |
17a1ebd1 VZ |
399 | if ( pos ) |
400 | node = m_tools.Item(pos - 1); | |
222ed1d6 | 401 | |
38762f09 VZ |
402 | while ( node ) |
403 | { | |
17a1ebd1 VZ |
404 | wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData(); |
405 | if ( !toolNext->IsRadio() ) | |
38762f09 VZ |
406 | break; |
407 | ||
17a1ebd1 | 408 | widget = toolNext->m_item; |
38762f09 VZ |
409 | |
410 | node = node->GetPrevious(); | |
411 | } | |
412 | ||
413 | if ( !widget ) | |
414 | { | |
415 | // this is the first button in the radio button group, | |
416 | // it will be toggled automatically by GTK so bring the | |
417 | // internal flag in sync | |
91af0895 | 418 | tool->Toggle(true); |
38762f09 VZ |
419 | } |
420 | } | |
421 | ||
422 | tool->m_item = gtk_toolbar_insert_element | |
423 | ( | |
424 | m_toolbar, | |
425 | tool->GetGtkChildType(), | |
426 | widget, | |
427 | tool->GetLabel().empty() | |
428 | ? NULL | |
fab591c5 | 429 | : (const char*) wxGTK_CONV( tool->GetLabel() ), |
38762f09 VZ |
430 | tool->GetShortHelp().empty() |
431 | ? NULL | |
fab591c5 | 432 | : (const char*) wxGTK_CONV( tool->GetShortHelp() ), |
38762f09 VZ |
433 | "", // tooltip_private_text (?) |
434 | tool->m_pixmap, | |
435 | (GtkSignalFunc)gtk_toolbar_callback, | |
436 | (gpointer)tool, | |
6a1359c0 | 437 | posGtk |
38762f09 VZ |
438 | ); |
439 | ||
440 | if ( !tool->m_item ) | |
441 | { | |
9a83f860 | 442 | wxFAIL_MSG( wxT("gtk_toolbar_insert_element() failed") ); |
38762f09 | 443 | |
91af0895 | 444 | return false; |
38762f09 | 445 | } |
99e8cb50 | 446 | |
38762f09 | 447 | gtk_signal_connect( GTK_OBJECT(tool->m_item), |
248bcf0a | 448 | "enter_notify_event", |
38762f09 VZ |
449 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
450 | (gpointer)tool ); | |
451 | gtk_signal_connect( GTK_OBJECT(tool->m_item), | |
248bcf0a | 452 | "leave_notify_event", |
38762f09 VZ |
453 | GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback), |
454 | (gpointer)tool ); | |
8a0681f9 | 455 | } |
8a0681f9 VZ |
456 | break; |
457 | ||
458 | case wxTOOL_STYLE_SEPARATOR: | |
6a1359c0 | 459 | gtk_toolbar_insert_space( m_toolbar, posGtk ); |
8a0681f9 VZ |
460 | |
461 | // skip the rest | |
91af0895 | 462 | return true; |
bf9e3e73 | 463 | |
8a0681f9 VZ |
464 | case wxTOOL_STYLE_CONTROL: |
465 | gtk_toolbar_insert_widget( | |
466 | m_toolbar, | |
467 | tool->GetControl()->m_widget, | |
468 | (const char *) NULL, | |
469 | (const char *) NULL, | |
6a1359c0 | 470 | posGtk |
8a0681f9 VZ |
471 | ); |
472 | break; | |
473 | } | |
bf9e3e73 | 474 | |
bf9e3e73 | 475 | GtkRequisition req; |
2afa14f2 OK |
476 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
477 | (m_widget, &req ); | |
00655497 | 478 | m_width = req.width + m_xMargin; |
6f67eafe | 479 | m_height = req.height + 2*m_yMargin; |
9f884528 | 480 | InvalidateBestSize(); |
bf9e3e73 | 481 | |
91af0895 | 482 | return true; |
bf9e3e73 RR |
483 | } |
484 | ||
89954433 | 485 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) |
c801d85f | 486 | { |
8a0681f9 | 487 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
c801d85f | 488 | |
8a0681f9 | 489 | switch ( tool->GetStyle() ) |
97d7bfb8 | 490 | { |
8a0681f9 | 491 | case wxTOOL_STYLE_CONTROL: |
1be45608 VZ |
492 | // don't destroy the control here as we can be called from |
493 | // RemoveTool() and then we need to keep the control alive; | |
494 | // while if we're called from DeleteTool() the control will | |
495 | // be destroyed when wxToolBarToolBase itself is deleted | |
8a0681f9 | 496 | break; |
97d7bfb8 | 497 | |
8a0681f9 VZ |
498 | case wxTOOL_STYLE_BUTTON: |
499 | gtk_widget_destroy( tool->m_item ); | |
500 | break; | |
1be45608 VZ |
501 | |
502 | default: | |
503 | wxFAIL_MSG( "unknown tool style" ); | |
504 | return false; | |
8a0681f9 | 505 | } |
c801d85f | 506 | |
9f884528 | 507 | InvalidateBestSize(); |
91af0895 | 508 | return true; |
fc008f25 | 509 | } |
46dc76ba | 510 | |
8a0681f9 VZ |
511 | // ---------------------------------------------------------------------------- |
512 | // wxToolBar tools state | |
513 | // ---------------------------------------------------------------------------- | |
514 | ||
515 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) | |
c801d85f | 516 | { |
8a0681f9 VZ |
517 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
518 | ||
8a0681f9 | 519 | if (tool->m_item) |
fab591c5 | 520 | { |
8a0681f9 | 521 | gtk_widget_set_sensitive( tool->m_item, enable ); |
fab591c5 | 522 | } |
fc008f25 | 523 | } |
c801d85f | 524 | |
248bcf0a | 525 | void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) |
c801d85f | 526 | { |
8a0681f9 VZ |
527 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
528 | ||
529 | GtkWidget *item = tool->m_item; | |
530 | if ( item && GTK_IS_TOGGLE_BUTTON(item) ) | |
1144d24d | 531 | { |
ab86c659 | 532 | tool->SetPixmap(tool->GetBitmap()); |
c801d85f | 533 | |
91af0895 | 534 | m_blockEvent = true; |
8a0681f9 VZ |
535 | |
536 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle ); | |
248bcf0a | 537 | |
91af0895 | 538 | m_blockEvent = false; |
1144d24d | 539 | } |
fc008f25 | 540 | } |
c801d85f | 541 | |
8a0681f9 VZ |
542 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
543 | bool WXUNUSED(toggle)) | |
c801d85f | 544 | { |
8a0681f9 | 545 | // VZ: absolutely no idea about how to do it |
9a83f860 | 546 | wxFAIL_MSG( wxT("not implemented") ); |
fc008f25 | 547 | } |
c801d85f | 548 | |
8a0681f9 VZ |
549 | // ---------------------------------------------------------------------------- |
550 | // wxToolBar geometry | |
551 | // ---------------------------------------------------------------------------- | |
552 | ||
553 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), | |
554 | wxCoord WXUNUSED(y)) const | |
c801d85f | 555 | { |
8a0681f9 | 556 | // VZ: GTK+ doesn't seem to have such thing |
9a83f860 | 557 | wxFAIL_MSG( wxT("wxToolBar::FindToolForPosition() not implemented") ); |
8a0681f9 | 558 | |
d3b9f782 | 559 | return NULL; |
fc008f25 | 560 | } |
c801d85f | 561 | |
1144d24d | 562 | void wxToolBar::SetMargins( int x, int y ) |
c801d85f | 563 | { |
8a0681f9 VZ |
564 | wxCHECK_RET( GetToolsCount() == 0, |
565 | wxT("wxToolBar::SetMargins must be called before adding tools.") ); | |
248bcf0a | 566 | |
6a1359c0 VZ |
567 | if (x > 1) |
568 | gtk_toolbar_append_space( m_toolbar ); // oh well | |
248bcf0a | 569 | |
1144d24d RR |
570 | m_xMargin = x; |
571 | m_yMargin = y; | |
fc008f25 | 572 | } |
c801d85f | 573 | |
cf4219e7 | 574 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 575 | { |
1144d24d | 576 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
9e691f46 | 577 | |
8a0681f9 | 578 | m_toolSeparation = separation; |
1144d24d RR |
579 | } |
580 | ||
a1f79c1e VZ |
581 | void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) |
582 | { | |
583 | wxToolBarTool *tool = (wxToolBarTool *)FindById(id); | |
584 | ||
585 | if ( tool ) | |
586 | { | |
587 | (void)tool->SetShortHelp(helpString); | |
588 | gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item, | |
fab591c5 | 589 | wxGTK_CONV( helpString ), ""); |
a1f79c1e VZ |
590 | } |
591 | } | |
592 | ||
8a0681f9 VZ |
593 | // ---------------------------------------------------------------------------- |
594 | // wxToolBar idle handling | |
595 | // ---------------------------------------------------------------------------- | |
1144d24d | 596 | |
9b7e522a RR |
597 | void wxToolBar::OnInternalIdle() |
598 | { | |
599 | wxCursor cursor = m_cursor; | |
a1b806b9 | 600 | if (g_globalCursor.IsOk()) cursor = g_globalCursor; |
9b7e522a | 601 | |
a1b806b9 | 602 | if (cursor.IsOk()) |
9b7e522a | 603 | { |
f7a11f8c | 604 | /* I now set the cursor the anew in every OnInternalIdle call |
8a0681f9 VZ |
605 | as setting the cursor in a parent window also effects the |
606 | windows above so that checking for the current cursor is | |
607 | not possible. */ | |
85ec2f26 RR |
608 | |
609 | if (HasFlag(wxTB_DOCKABLE) && (m_widget->window)) | |
9b7e522a | 610 | { |
8a0681f9 VZ |
611 | /* if the toolbar is dockable, then m_widget stands for the |
612 | GtkHandleBox widget, which uses its own window so that we | |
613 | can set the cursor for it. if the toolbar is not dockable, | |
614 | m_widget comes from m_toolbar which uses its parent's | |
615 | window ("windowless windows") and thus we cannot set the | |
616 | cursor. */ | |
617 | gdk_window_set_cursor( m_widget->window, cursor.GetCursor() ); | |
618 | } | |
619 | ||
222ed1d6 | 620 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
621 | while ( node ) |
622 | { | |
623 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
624 | node = node->GetNext(); | |
625 | ||
626 | GtkWidget *item = tool->m_item; | |
627 | if ( item ) | |
628 | { | |
629 | GdkWindow *window = item->window; | |
630 | ||
631 | if ( window ) | |
632 | { | |
633 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
634 | } | |
635 | } | |
9b7e522a RR |
636 | } |
637 | } | |
638 | ||
e39af974 JS |
639 | if (wxUpdateUIEvent::CanUpdate(this)) |
640 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
9b7e522a RR |
641 | } |
642 | ||
9d522606 RD |
643 | |
644 | // ---------------------------------------------------------------------------- | |
645 | ||
646 | // static | |
647 | wxVisualAttributes | |
648 | wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
649 | { | |
9d522606 RD |
650 | wxVisualAttributes attr; |
651 | GtkWidget* widget = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); | |
652 | attr = GetDefaultAttributesFromGTKWidget(widget); | |
653 | gtk_widget_destroy(widget); | |
654 | return attr; | |
9d522606 RD |
655 | } |
656 | ||
a1f79c1e | 657 | #endif // wxUSE_TOOLBAR_NATIVE |