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