]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/tbargtk.cpp
don't use deprecated toolbar API
[wxWidgets.git] / src / gtk / tbargtk.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/tbargtk.cpp
3// Purpose: GTK toolbar
4// Author: Robert Roebling
5// Modified: 13.12.99 by VZ to derive from wxToolBarBase
6// RCS-ID: $Id$
7// Copyright: (c) Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#if wxUSE_TOOLBAR_NATIVE
15
16#include "wx/toolbar.h"
17
18#include "wx/gtk/private.h"
19
20// ----------------------------------------------------------------------------
21// globals
22// ----------------------------------------------------------------------------
23
24// data
25extern bool g_blockEventsOnDrag;
26extern wxCursor g_globalCursor;
27
28// ----------------------------------------------------------------------------
29// wxToolBarTool
30// ----------------------------------------------------------------------------
31
32class wxToolBarTool : public wxToolBarToolBase
33{
34public:
35 wxToolBarTool(wxToolBar *tbar,
36 int id,
37 const wxString& label,
38 const wxBitmap& bitmap1,
39 const wxBitmap& bitmap2,
40 wxItemKind kind,
41 wxObject *clientData,
42 const wxString& shortHelpString,
43 const wxString& longHelpString)
44 : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
45 clientData, shortHelpString, longHelpString)
46 {
47 m_item = NULL;
48 }
49
50 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
51 : wxToolBarToolBase(tbar, control, label)
52 {
53 m_item = NULL;
54 // Hold a reference to keep control alive until DoInsertTool() is
55 // called, or if RemoveTool() is called (see DoDeleteTool)
56 g_object_ref(control->m_widget);
57 // release reference when gtk_widget_destroy() is called on control
58 g_signal_connect(
59 control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
60 }
61
62 void SetImage();
63 void CreateDropDown();
64 void ShowDropdown(GtkToggleButton* button);
65
66 GtkToolItem* m_item;
67};
68
69// ----------------------------------------------------------------------------
70// wxWin macros
71// ----------------------------------------------------------------------------
72
73IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
74
75// ============================================================================
76// implementation
77// ============================================================================
78
79//-----------------------------------------------------------------------------
80// "clicked" from m_item
81//-----------------------------------------------------------------------------
82
83extern "C" {
84static void item_clicked(GtkToolButton*, wxToolBarTool* tool)
85{
86 if (g_blockEventsOnDrag) return;
87
88 tool->GetToolBar()->OnLeftClick(tool->GetId(), false);
89}
90}
91
92//-----------------------------------------------------------------------------
93// "toggled" from m_item
94//-----------------------------------------------------------------------------
95
96extern "C" {
97static void item_toggled(GtkToggleToolButton* button, wxToolBarTool* tool)
98{
99 if (g_blockEventsOnDrag) return;
100
101 const bool active = gtk_toggle_tool_button_get_active(button) != 0;
102 tool->Toggle(active);
103 if (!active && tool->GetKind() == wxITEM_RADIO)
104 return;
105
106 if (!tool->GetToolBar()->OnLeftClick(tool->GetId(), active))
107 {
108 // revert back
109 tool->Toggle();
110 }
111}
112}
113
114//-----------------------------------------------------------------------------
115// "button_press_event" from m_item child
116//-----------------------------------------------------------------------------
117
118extern "C" {
119static gboolean
120button_press_event(GtkWidget*, GdkEventButton* event, wxToolBarTool* tool)
121{
122 if (event->button != 3)
123 return FALSE;
124
125 if (g_blockEventsOnDrag) return TRUE;
126
127 tool->GetToolBar()->OnRightClick(
128 tool->GetId(), int(event->x), int(event->y));
129
130 return TRUE;
131}
132}
133
134//-----------------------------------------------------------------------------
135// "child_detached" from m_widget
136//-----------------------------------------------------------------------------
137
138extern "C" {
139static void child_detached(GtkWidget*, GtkToolbar* toolbar, void*)
140{
141 // disable showing overflow arrow when toolbar is detached,
142 // otherwise toolbar collapses to just an arrow
143 gtk_toolbar_set_show_arrow(toolbar, false);
144}
145}
146
147//-----------------------------------------------------------------------------
148// "child_attached" from m_widget
149//-----------------------------------------------------------------------------
150
151extern "C" {
152static void child_attached(GtkWidget*, GtkToolbar* toolbar, void*)
153{
154 gtk_toolbar_set_show_arrow(toolbar, true);
155}
156}
157
158//-----------------------------------------------------------------------------
159// "enter_notify_event" / "leave_notify_event" from m_item
160//-----------------------------------------------------------------------------
161
162extern "C" {
163static gboolean
164enter_notify_event(GtkWidget*, GdkEventCrossing* event, wxToolBarTool* tool)
165{
166 if (g_blockEventsOnDrag) return TRUE;
167
168 int id = -1;
169 if (event->type == GDK_ENTER_NOTIFY)
170 id = tool->GetId();
171 tool->GetToolBar()->OnMouseEnter(id);
172
173 return FALSE;
174}
175}
176
177//-----------------------------------------------------------------------------
178// "size_request" from m_toolbar
179//-----------------------------------------------------------------------------
180
181extern "C" {
182static void
183size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
184{
185 const wxSize margins = win->GetMargins();
186 req->width += margins.x;
187 req->height += 2 * margins.y;
188}
189}
190
191//-----------------------------------------------------------------------------
192// "expose_event" from GtkImage inside m_item
193//-----------------------------------------------------------------------------
194
195extern "C" {
196static gboolean
197image_expose_event(GtkWidget* widget, GdkEventExpose*, wxToolBarTool* tool)
198{
199 const wxBitmap& bitmap = tool->GetDisabledBitmap();
200 if (tool->IsEnabled() || !bitmap.IsOk())
201 return false;
202
203 // draw disabled bitmap ourselves, GtkImage has no way to specify it
204 const GtkAllocation& alloc = widget->allocation;
205 gdk_draw_pixbuf(
206 widget->window, widget->style->black_gc, bitmap.GetPixbuf(),
207 0, 0,
208 alloc.x + (alloc.width - widget->requisition.width) / 2,
209 alloc.y + (alloc.height - widget->requisition.height) / 2,
210 -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);
211 return true;
212}
213}
214
215//-----------------------------------------------------------------------------
216// "toggled" from dropdown menu button
217//-----------------------------------------------------------------------------
218
219extern "C" {
220static void arrow_toggled(GtkToggleButton* button, wxToolBarTool* tool)
221{
222 if (gtk_toggle_button_get_active(button))
223 {
224 tool->ShowDropdown(button);
225 gtk_toggle_button_set_active(button, false);
226 }
227}
228}
229
230//-----------------------------------------------------------------------------
231// "button_press_event" from dropdown menu button
232//-----------------------------------------------------------------------------
233
234extern "C" {
235static gboolean
236arrow_button_press_event(GtkToggleButton* button, GdkEventButton* event, wxToolBarTool* tool)
237{
238 if (event->button == 1)
239 {
240 g_signal_handlers_block_by_func(button, (void*)arrow_toggled, tool);
241 gtk_toggle_button_set_active(button, true);
242 tool->ShowDropdown(button);
243 gtk_toggle_button_set_active(button, false);
244 g_signal_handlers_unblock_by_func(button, (void*)arrow_toggled, tool);
245 return true;
246 }
247 return false;
248}
249}
250
251//-----------------------------------------------------------------------------
252// InsertChild callback for wxToolBar
253//-----------------------------------------------------------------------------
254
255static void wxInsertChildInToolBar(wxWindow* parent, wxWindow* child)
256{
257 GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
258 gtk_widget_show(align);
259 gtk_container_add(GTK_CONTAINER(align), child->m_widget);
260 GtkToolItem* item = gtk_tool_item_new();
261 gtk_container_add(GTK_CONTAINER(item), align);
262 wxToolBar* tbar = static_cast<wxToolBar*>(parent);
263 // position will be corrected in DoInsertTool if necessary
264 gtk_toolbar_insert(GTK_TOOLBAR(GTK_BIN(tbar->m_widget)->child), item, -1);
265}
266
267// ----------------------------------------------------------------------------
268// wxToolBarTool
269// ----------------------------------------------------------------------------
270
271void wxToolBarTool::SetImage()
272{
273 const wxBitmap& bitmap = GetNormalBitmap();
274 wxCHECK_RET(bitmap.IsOk(), "invalid bitmap for wxToolBar icon");
275
276 GtkWidget* image = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(m_item));
277 // always use pixbuf, because pixmap mask does not
278 // work with disabled images in some themes
279 gtk_image_set_from_pixbuf(GTK_IMAGE(image), bitmap.GetPixbuf());
280}
281
282// helper to create a dropdown menu item
283void wxToolBarTool::CreateDropDown()
284{
285 gtk_tool_item_set_homogeneous(m_item, false);
286 GtkWidget* box;
287 GtkWidget* arrow;
288 if (GetToolBar()->HasFlag(wxTB_LEFT | wxTB_RIGHT))
289 {
290 box = gtk_vbox_new(false, 0);
291 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
292 }
293 else
294 {
295 box = gtk_hbox_new(false, 0);
296 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE);
297 }
298 GtkWidget* tool_button = GTK_BIN(m_item)->child;
299 gtk_widget_reparent(tool_button, box);
300 GtkWidget* arrow_button = gtk_toggle_button_new();
301 gtk_button_set_relief(GTK_BUTTON(arrow_button),
302 gtk_tool_item_get_relief_style(GTK_TOOL_ITEM(m_item)));
303 gtk_container_add(GTK_CONTAINER(arrow_button), arrow);
304 gtk_container_add(GTK_CONTAINER(box), arrow_button);
305 gtk_widget_show_all(box);
306 gtk_container_add(GTK_CONTAINER(m_item), box);
307
308 g_signal_connect(arrow_button, "toggled", G_CALLBACK(arrow_toggled), this);
309 g_signal_connect(arrow_button, "button_press_event",
310 G_CALLBACK(arrow_button_press_event), this);
311}
312
313void wxToolBarTool::ShowDropdown(GtkToggleButton* button)
314{
315 wxToolBarBase* toolbar = GetToolBar();
316 wxCommandEvent event(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, GetId());
317 if (!toolbar->HandleWindowEvent(event))
318 {
319 wxMenu* menu = GetDropdownMenu();
320 if (menu)
321 {
322 const GtkAllocation& alloc = GTK_WIDGET(button)->allocation;
323 int x = alloc.x;
324 int y = alloc.y;
325 if (toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT))
326 x += alloc.width;
327 else
328 y += alloc.height;
329 toolbar->PopupMenu(menu, x, y);
330 }
331 }
332}
333
334wxToolBarToolBase *wxToolBar::CreateTool(int id,
335 const wxString& text,
336 const wxBitmap& bitmap1,
337 const wxBitmap& bitmap2,
338 wxItemKind kind,
339 wxObject *clientData,
340 const wxString& shortHelpString,
341 const wxString& longHelpString)
342{
343 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
344 clientData, shortHelpString, longHelpString);
345}
346
347wxToolBarToolBase *
348wxToolBar::CreateTool(wxControl *control, const wxString& label)
349{
350 return new wxToolBarTool(this, control, label);
351}
352
353//-----------------------------------------------------------------------------
354// wxToolBar construction
355//-----------------------------------------------------------------------------
356
357void wxToolBar::Init()
358{
359 m_toolbar = (GtkToolbar *)NULL;
360 m_tooltips = NULL;
361}
362
363wxToolBar::~wxToolBar()
364{
365 if (m_tooltips)
366 {
367 gtk_object_destroy(GTK_OBJECT(m_tooltips));
368 g_object_unref(m_tooltips);
369 }
370}
371
372bool wxToolBar::Create( wxWindow *parent,
373 wxWindowID id,
374 const wxPoint& pos,
375 const wxSize& size,
376 long style,
377 const wxString& name )
378{
379 m_insertCallback = wxInsertChildInToolBar;
380
381 if ( !PreCreation( parent, pos, size ) ||
382 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
383 {
384 wxFAIL_MSG( wxT("wxToolBar creation failed") );
385
386 return false;
387 }
388
389 FixupStyle();
390
391 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
392 m_tooltips = gtk_tooltips_new();
393 g_object_ref(m_tooltips);
394 gtk_object_sink(GTK_OBJECT(m_tooltips));
395 GtkSetStyle();
396
397 if (style & wxTB_DOCKABLE)
398 {
399 m_widget = gtk_handle_box_new();
400
401 g_signal_connect(m_widget, "child_detached",
402 G_CALLBACK(child_detached), NULL);
403 g_signal_connect(m_widget, "child_attached",
404 G_CALLBACK(child_attached), NULL);
405
406 if (style & wxTB_FLAT)
407 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
408 }
409 else
410 {
411 m_widget = gtk_event_box_new();
412 ConnectWidget( m_widget );
413 }
414 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar));
415 gtk_widget_show(GTK_WIDGET(m_toolbar));
416
417 m_parent->DoAddChild( this );
418
419 PostCreation(size);
420
421 g_signal_connect_after(m_toolbar, "size_request",
422 G_CALLBACK(size_request), this);
423
424 return true;
425}
426
427GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
428{
429 return GTK_WIDGET(m_toolbar)->window;
430}
431
432void wxToolBar::GtkSetStyle()
433{
434 GtkOrientation orient = GTK_ORIENTATION_HORIZONTAL;
435 if (HasFlag(wxTB_LEFT | wxTB_RIGHT))
436 orient = GTK_ORIENTATION_VERTICAL;
437
438 GtkToolbarStyle style = GTK_TOOLBAR_ICONS;
439 if (HasFlag(wxTB_NOICONS))
440 style = GTK_TOOLBAR_TEXT;
441 else if (HasFlag(wxTB_TEXT))
442 {
443 style = GTK_TOOLBAR_BOTH;
444 if (HasFlag(wxTB_HORZ_LAYOUT))
445 style = GTK_TOOLBAR_BOTH_HORIZ;
446 }
447
448 gtk_toolbar_set_orientation(m_toolbar, orient);
449 gtk_toolbar_set_style(m_toolbar, style);
450}
451
452void wxToolBar::SetWindowStyleFlag( long style )
453{
454 wxToolBarBase::SetWindowStyleFlag(style);
455
456 if ( m_toolbar )
457 GtkSetStyle();
458}
459
460bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
461{
462 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
463
464 GSList* radioGroup;
465 switch ( tool->GetStyle() )
466 {
467 case wxTOOL_STYLE_BUTTON:
468 switch (tool->GetKind())
469 {
470 case wxITEM_CHECK:
471 tool->m_item = gtk_toggle_tool_button_new();
472 g_signal_connect(tool->m_item, "toggled",
473 G_CALLBACK(item_toggled), tool);
474 break;
475 case wxITEM_RADIO:
476 radioGroup = GetRadioGroup(pos);
477 if (radioGroup)
478 {
479 // this is the first button in the radio button group,
480 // it will be toggled automatically by GTK so bring the
481 // internal flag in sync
482 tool->Toggle(true);
483 }
484 tool->m_item = gtk_radio_tool_button_new(radioGroup);
485 g_signal_connect(tool->m_item, "toggled",
486 G_CALLBACK(item_toggled), tool);
487 break;
488 default:
489 wxFAIL_MSG("unknown toolbar child type");
490 // fall through
491 case wxITEM_DROPDOWN:
492 case wxITEM_NORMAL:
493 tool->m_item = gtk_tool_button_new(NULL, "");
494 g_signal_connect(tool->m_item, "clicked",
495 G_CALLBACK(item_clicked), tool);
496 break;
497 }
498 if (!HasFlag(wxTB_NOICONS))
499 {
500 GtkWidget* image = gtk_image_new();
501 gtk_tool_button_set_icon_widget(
502 GTK_TOOL_BUTTON(tool->m_item), image);
503 tool->SetImage();
504 gtk_widget_show(image);
505 g_signal_connect(image, "expose_event",
506 G_CALLBACK(image_expose_event), tool);
507 }
508 if (!tool->GetLabel().empty())
509 {
510 gtk_tool_button_set_label(
511 GTK_TOOL_BUTTON(tool->m_item), wxGTK_CONV(tool->GetLabel()));
512 // needed for labels in horizontal toolbar with wxTB_HORZ_LAYOUT
513 gtk_tool_item_set_is_important(tool->m_item, true);
514 }
515 if (!HasFlag(wxTB_NO_TOOLTIPS) && !tool->GetShortHelp().empty())
516 {
517 gtk_tool_item_set_tooltip(tool->m_item,
518 m_tooltips, wxGTK_CONV(tool->GetShortHelp()), "");
519 }
520 g_signal_connect(GTK_BIN(tool->m_item)->child, "button_press_event",
521 G_CALLBACK(button_press_event), tool);
522 g_signal_connect(tool->m_item, "enter_notify_event",
523 G_CALLBACK(enter_notify_event), tool);
524 g_signal_connect(tool->m_item, "leave_notify_event",
525 G_CALLBACK(enter_notify_event), tool);
526
527 if (tool->GetKind() == wxITEM_DROPDOWN)
528 tool->CreateDropDown();
529 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
530 break;
531
532 case wxTOOL_STYLE_SEPARATOR:
533 tool->m_item = gtk_separator_tool_item_new();
534 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
535 break;
536
537 case wxTOOL_STYLE_CONTROL:
538 wxWindow* control = tool->GetControl();
539 if (control->m_widget->parent == NULL)
540 wxInsertChildInToolBar(this, control);
541 tool->m_item = GTK_TOOL_ITEM(control->m_widget->parent->parent);
542 if (gtk_toolbar_get_item_index(m_toolbar, tool->m_item) != int(pos))
543 {
544 g_object_ref(tool->m_item);
545 gtk_container_remove(
546 GTK_CONTAINER(m_toolbar), GTK_WIDGET(tool->m_item));
547 gtk_toolbar_insert(m_toolbar, tool->m_item, int(pos));
548 g_object_unref(tool->m_item);
549 }
550 // Inserted items "slide" into place using an animated effect that
551 // causes multiple size events on the item. Must set size request
552 // to keep item size from getting permanently set too small by the
553 // first of these size events.
554 const wxSize size = control->GetSize();
555 gtk_widget_set_size_request(control->m_widget, size.x, size.y);
556 break;
557 }
558 gtk_widget_show(GTK_WIDGET(tool->m_item));
559
560 InvalidateBestSize();
561
562 return true;
563}
564
565bool wxToolBar::DoDeleteTool(size_t /* pos */, wxToolBarToolBase* toolBase)
566{
567 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
568
569 if (tool->GetStyle() == wxTOOL_STYLE_CONTROL)
570 {
571 // don't destroy the control here as we can be called from
572 // RemoveTool() and then we need to keep the control alive;
573 // while if we're called from DeleteTool() the control will
574 // be destroyed when wxToolBarToolBase itself is deleted
575 GtkWidget* widget = tool->GetControl()->m_widget;
576 gtk_container_remove(GTK_CONTAINER(widget->parent), widget);
577 }
578 gtk_object_destroy(GTK_OBJECT(tool->m_item));
579 tool->m_item = NULL;
580
581 InvalidateBestSize();
582 return true;
583}
584
585GSList* wxToolBar::GetRadioGroup(size_t pos)
586{
587 GSList* radioGroup = NULL;
588 GtkToolItem* item = NULL;
589 if (pos > 0)
590 {
591 item = gtk_toolbar_get_nth_item(m_toolbar, int(pos) - 1);
592 if (!GTK_IS_RADIO_TOOL_BUTTON(item))
593 item = NULL;
594 }
595 if (item == NULL && pos < m_tools.size())
596 {
597 item = gtk_toolbar_get_nth_item(m_toolbar, int(pos));
598 if (!GTK_IS_RADIO_TOOL_BUTTON(item))
599 item = NULL;
600 }
601 if (item)
602 radioGroup = gtk_radio_tool_button_get_group((GtkRadioToolButton*)item);
603 return radioGroup;
604}
605
606// ----------------------------------------------------------------------------
607// wxToolBar tools state
608// ----------------------------------------------------------------------------
609
610void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
611{
612 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
613
614 if (tool->m_item)
615 gtk_widget_set_sensitive(GTK_WIDGET(tool->m_item), enable);
616}
617
618void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
619{
620 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
621
622 if (tool->m_item)
623 {
624 g_signal_handlers_block_by_func(tool->m_item, (void*)item_toggled, tool);
625
626 gtk_toggle_tool_button_set_active(
627 GTK_TOGGLE_TOOL_BUTTON(tool->m_item), toggle);
628
629 g_signal_handlers_unblock_by_func(tool->m_item, (void*)item_toggled, tool);
630 }
631}
632
633void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
634 bool WXUNUSED(toggle))
635{
636 // VZ: absolutely no idea about how to do it
637 wxFAIL_MSG( _T("not implemented") );
638}
639
640// ----------------------------------------------------------------------------
641// wxToolBar geometry
642// ----------------------------------------------------------------------------
643
644wxSize wxToolBar::DoGetBestSize() const
645{
646 // Unfortunately, if overflow arrow is enabled GtkToolbar only reports size
647 // of arrow. To get the real size, the arrow is temporarily disabled here.
648 // This is gross, since it will cause a queue_resize, and could potentially
649 // lead to an infinite loop. But there seems to be no alternative, short of
650 // disabling the arrow entirely.
651 gtk_toolbar_set_show_arrow(m_toolbar, false);
652 const wxSize size = wxToolBarBase::DoGetBestSize();
653 gtk_toolbar_set_show_arrow(m_toolbar, true);
654 return size;
655}
656
657wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
658 wxCoord WXUNUSED(y)) const
659{
660 // VZ: GTK+ doesn't seem to have such thing
661 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
662
663 return (wxToolBarToolBase *)NULL;
664}
665
666void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
667{
668 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
669
670 if ( tool )
671 {
672 (void)tool->SetShortHelp(helpString);
673 if (tool->m_item)
674 {
675 gtk_tool_item_set_tooltip(tool->m_item,
676 m_tooltips, wxGTK_CONV(helpString), "");
677 }
678 }
679}
680
681void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
682{
683 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
684 if ( tool )
685 {
686 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
687
688 tool->SetNormalBitmap(bitmap);
689 tool->SetImage();
690 }
691}
692
693void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
694{
695 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
696 if ( tool )
697 {
698 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
699
700 tool->SetDisabledBitmap(bitmap);
701 }
702}
703
704// ----------------------------------------------------------------------------
705// wxToolBar idle handling
706// ----------------------------------------------------------------------------
707
708void wxToolBar::OnInternalIdle()
709{
710 // Check if we have to show window now
711 if (GtkShowFromOnIdle()) return;
712
713 wxCursor cursor = m_cursor;
714 if (g_globalCursor.Ok()) cursor = g_globalCursor;
715
716 if (cursor.Ok())
717 {
718 /* I now set the cursor the anew in every OnInternalIdle call
719 as setting the cursor in a parent window also effects the
720 windows above so that checking for the current cursor is
721 not possible. */
722
723 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
724 {
725 /* if the toolbar is dockable, then m_widget stands for the
726 GtkHandleBox widget, which uses its own window so that we
727 can set the cursor for it. if the toolbar is not dockable,
728 m_widget comes from m_toolbar which uses its parent's
729 window ("windowless windows") and thus we cannot set the
730 cursor. */
731 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
732 }
733
734 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
735 while ( node )
736 {
737 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
738 node = node->GetNext();
739
740 if (tool->m_item)
741 {
742 GdkWindow* window = GTK_WIDGET(tool->m_item)->window;
743
744 if ( window )
745 {
746 gdk_window_set_cursor( window, cursor.GetCursor() );
747 }
748 }
749 }
750 }
751
752 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
753 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
754}
755
756
757// ----------------------------------------------------------------------------
758
759// static
760wxVisualAttributes
761wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
762{
763 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
764}
765
766#endif // wxUSE_TOOLBAR_NATIVE