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