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