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