]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/tbargtk.cpp
get rid of several dozen of warnings when using g++ >= 4.2 about string literals...
[wxWidgets.git] / src / gtk / tbargtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/tbargtk.cpp
3 // Purpose: GTK toolbar
4 // Author: Robert Roebling
5 // Modified: 13.12.99 by VZ to derive from wxToolBarBase
6 // RCS-ID: $Id$
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #if wxUSE_TOOLBAR_NATIVE
15
16 #include "wx/toolbar.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/menu.h"
20 #endif
21
22 // FIXME: Use GtkImage instead of GtkPixmap. Use the new toolbar API for when gtk runtime is new enough?
23 // Beware that the new and old toolbar API may not be mixed in usage.
24 #undef GTK_DISABLE_DEPRECATED
25
26 #include "wx/gtk/private.h"
27
28 /* XPM */
29 static const char *arrow_down_xpm[] = {
30 /* columns rows colors chars-per-pixel */
31 "7 7 2 1",
32 " c None",
33 ". c Black",
34 /* pixels */
35 " ",
36 " ",
37 " ",
38 ".......",
39 " ..... ",
40 " ... ",
41 " . "
42 };
43
44
45 // ----------------------------------------------------------------------------
46 // globals
47 // ----------------------------------------------------------------------------
48
49 // data
50 extern bool g_blockEventsOnDrag;
51 extern wxCursor g_globalCursor;
52
53 // ----------------------------------------------------------------------------
54 // private functions
55 // ----------------------------------------------------------------------------
56
57 // translate wxWidgets toolbar style flags to GTK orientation and style
58 static void GetGtkStyle(long style,
59 GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
60 {
61 *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
62
63
64 if ( style & wxTB_TEXT )
65 {
66 *gtkStyle = style & wxTB_NOICONS
67 ? GTK_TOOLBAR_TEXT
68 : (
69 style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ :
70 GTK_TOOLBAR_BOTH);
71 }
72 else // no text, hence we must have the icons or what would we show?
73 {
74 *gtkStyle = GTK_TOOLBAR_ICONS;
75 }
76 }
77
78 // ----------------------------------------------------------------------------
79 // wxToolBarTool
80 // ----------------------------------------------------------------------------
81
82 class wxToolBarTool : public wxToolBarToolBase
83 {
84 public:
85 wxToolBarTool(wxToolBar *tbar,
86 int id,
87 const wxString& label,
88 const wxBitmap& bitmap1,
89 const wxBitmap& bitmap2,
90 wxItemKind kind,
91 wxObject *clientData,
92 const wxString& shortHelpString,
93 const wxString& longHelpString)
94 : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
95 clientData, shortHelpString, longHelpString)
96 {
97 Init();
98 }
99
100 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
101 : wxToolBarToolBase(tbar, control, label)
102 {
103 Init();
104 // Hold a reference to keep control alive until DoInsertTool() is
105 // called, or if RemoveTool() is called (see DoDeleteTool)
106 g_object_ref(control->m_widget);
107 // release reference when gtk_widget_destroy() is called on control
108 g_signal_connect(
109 control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);
110 }
111
112 // is this a radio button?
113 //
114 // unlike GetKind(), can be called for any kind of tools, not just buttons
115 bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; }
116
117 // this is only called for the normal buttons, i.e. not separators nor
118 // controls
119 GtkToolbarChildType GetGtkChildType() const
120 {
121 switch ( GetKind() )
122 {
123 case wxITEM_CHECK:
124 return GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
125
126 case wxITEM_RADIO:
127 return GTK_TOOLBAR_CHILD_RADIOBUTTON;
128
129 default:
130 wxFAIL_MSG( _T("unknown toolbar child type") );
131 // fall through
132
133 case wxITEM_DROPDOWN:
134 case wxITEM_NORMAL:
135 return GTK_TOOLBAR_CHILD_BUTTON;
136 }
137 }
138
139 void SetImage(const wxBitmap& bitmap)
140 {
141 if (bitmap.Ok())
142 {
143 // setting from pixmap doesn't seem to work right, but pixbuf works well
144 gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
145 }
146 }
147
148 // the toolbar element for button tools or a GtkAlignment containing the
149 // control for control tools
150 GtkWidget *m_item;
151 // dropdown element for button tools
152 GtkWidget *m_itemDropdown;
153
154 // a GtkImage containing the image for a button-type tool, may be NULL
155 GtkWidget *m_image;
156
157 protected:
158 void Init();
159 };
160
161 // ----------------------------------------------------------------------------
162 // wxWin macros
163 // ----------------------------------------------------------------------------
164
165 IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
166
167 // ============================================================================
168 // implementation
169 // ============================================================================
170
171 //-----------------------------------------------------------------------------
172 // "clicked" (internal from gtk_toolbar)
173 //-----------------------------------------------------------------------------
174
175 extern "C" {
176 static void gtk_toolbar_callback( GtkWidget *widget,
177 wxToolBarTool *tool )
178 {
179 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
180
181 if (tbar->m_blockEvent) return;
182
183 if (g_blockEventsOnDrag) return;
184 if (!tool->IsEnabled()) return;
185
186 if (tool->CanBeToggled())
187 {
188 if (tool->IsRadio() &&
189 gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget)) &&
190 tool->IsToggled())
191 {
192 // pressed an already pressed radio button
193 return;
194 }
195
196 tool->Toggle();
197
198 tool->SetImage(tool->GetBitmap());
199
200 if ( tool->IsRadio() && !tool->IsToggled() )
201 {
202 // radio button went up, don't report this as a wxWin event
203 return;
204 }
205 }
206
207 if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() )
208 {
209 // revert back
210 tool->Toggle();
211
212 tool->SetImage(tool->GetBitmap());
213 }
214 }
215 }
216
217 //-----------------------------------------------------------------------------
218 // "right-click"
219 //-----------------------------------------------------------------------------
220 extern "C" {
221 static gboolean gtk_toolbar_tool_rclick_callback(GtkWidget *WXUNUSED(widget),
222 GdkEventButton *event,
223 wxToolBarToolBase *tool)
224 {
225 if (event->button != 3)
226 return FALSE;
227
228 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
229
230 if (tbar->m_blockEvent) return TRUE;
231
232 if (g_blockEventsOnDrag) return TRUE;
233 if (!tool->IsEnabled()) return TRUE;
234
235 tbar->OnRightClick( tool->GetId(), (int)event->x, (int)event->y );
236
237 return TRUE;
238 }
239 }
240
241 //-----------------------------------------------------------------------------
242 // "enter_notify_event" / "leave_notify_event" from dropdown
243 //-----------------------------------------------------------------------------
244
245 extern "C" {
246 static gint gtk_toolbar_buddy_enter_callback( GtkWidget *WXUNUSED(widget),
247 GdkEventCrossing *WXUNUSED(gdk_event),
248 GtkWidget *tool )
249 {
250 guint8 state = GTK_WIDGET_STATE( tool );
251 state |= GTK_STATE_PRELIGHT;
252 gtk_widget_set_state( tool, (GtkStateType) state );
253 return FALSE;
254 }
255
256 static gint gtk_toolbar_buddy_leave_callback( GtkWidget *WXUNUSED(widget),
257 GdkEventCrossing *WXUNUSED(gdk_event),
258 GtkWidget *tool )
259 {
260 guint8 state = GTK_WIDGET_STATE( tool );
261 state &= ~GTK_STATE_PRELIGHT;
262 gtk_widget_set_state( tool, (GtkStateType) state );
263 return FALSE;
264 }
265 }
266
267 //-----------------------------------------------------------------------------
268 // "left-click" on dropdown
269 //-----------------------------------------------------------------------------
270
271 extern "C"
272 {
273 static void gtk_pop_tb_hide_callback( GtkWidget *WXUNUSED(menu), GtkToggleButton *button )
274 {
275 gtk_toggle_button_set_active( button, FALSE );
276 }
277
278 static gboolean gtk_toolbar_dropdown_lclick_callback(GtkWidget *widget,
279 GdkEventButton *event,
280 wxToolBarToolBase *tool)
281 {
282 if (event->button != 1)
283 return FALSE;
284
285 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
286
287 if (tbar->m_blockEvent) return FALSE;
288
289 if (g_blockEventsOnDrag) return FALSE;
290 if (!tool->IsEnabled()) return FALSE;
291
292 wxCommandEvent evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, tool->GetId() );
293 if ( tbar->HandleWindowEvent(evt) )
294 {
295 return TRUE;
296 }
297
298 wxMenu * const menu = tool->GetDropdownMenu();
299 if (!menu)
300 return TRUE;
301
302 // simulate press
303 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(widget), TRUE );
304
305 g_signal_connect (menu->m_menu, "hide",
306 G_CALLBACK (gtk_pop_tb_hide_callback),
307 widget);
308
309 tbar->PopupMenu( menu, widget->allocation.x,
310 widget->allocation.y + widget->allocation.height );
311
312
313 return TRUE;
314 }
315 }
316
317 //-----------------------------------------------------------------------------
318 // "enter_notify_event" / "leave_notify_event"
319 //-----------------------------------------------------------------------------
320
321 extern "C" {
322 static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
323 GdkEventCrossing *gdk_event,
324 wxToolBarTool *tool )
325 {
326 if (g_blockEventsOnDrag) return TRUE;
327
328 wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
329
330 // emit the event
331 if( gdk_event->type == GDK_ENTER_NOTIFY )
332 tb->OnMouseEnter( tool->GetId() );
333 else
334 tb->OnMouseEnter( -1 );
335
336 return FALSE;
337 }
338 }
339
340 //-----------------------------------------------------------------------------
341 // "size_request" from m_toolbar
342 //-----------------------------------------------------------------------------
343
344 extern "C" {
345 static void
346 size_request(GtkWidget*, GtkRequisition* req, wxToolBar* win)
347 {
348 const wxSize margins = win->GetMargins();
349 req->width += margins.x;
350 req->height += 2 * margins.y;
351 }
352 }
353
354 //-----------------------------------------------------------------------------
355 // InsertChild callback for wxToolBar
356 //-----------------------------------------------------------------------------
357
358 static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
359 wxWindow* /* child */)
360 {
361 // Child widget will be inserted into GtkToolbar by DoInsertTool()
362 }
363
364 // ----------------------------------------------------------------------------
365 // wxToolBarTool
366 // ----------------------------------------------------------------------------
367
368 void wxToolBarTool::Init()
369 {
370 m_item =
371 m_itemDropdown =
372 m_image = NULL;
373 }
374
375 wxToolBarToolBase *wxToolBar::CreateTool(int id,
376 const wxString& text,
377 const wxBitmap& bitmap1,
378 const wxBitmap& bitmap2,
379 wxItemKind kind,
380 wxObject *clientData,
381 const wxString& shortHelpString,
382 const wxString& longHelpString)
383 {
384 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
385 clientData, shortHelpString, longHelpString);
386 }
387
388 wxToolBarToolBase *
389 wxToolBar::CreateTool(wxControl *control, const wxString& label)
390 {
391 return new wxToolBarTool(this, control, label);
392 }
393
394 //-----------------------------------------------------------------------------
395 // wxToolBar construction
396 //-----------------------------------------------------------------------------
397
398 void wxToolBar::Init()
399 {
400 m_toolbar = (GtkToolbar *)NULL;
401 m_blockEvent = false;
402 m_defaultWidth = 32;
403 m_defaultHeight = 32;
404 }
405
406 wxToolBar::~wxToolBar()
407 {
408 }
409
410 bool wxToolBar::Create( wxWindow *parent,
411 wxWindowID id,
412 const wxPoint& pos,
413 const wxSize& size,
414 long style,
415 const wxString& name )
416 {
417 m_insertCallback = wxInsertChildInToolBar;
418
419 if ( !PreCreation( parent, pos, size ) ||
420 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
421 {
422 wxFAIL_MSG( wxT("wxToolBar creation failed") );
423
424 return false;
425 }
426
427 FixupStyle();
428
429 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
430 GtkSetStyle();
431
432 // Doesn't work this way.
433 // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
434 // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
435
436 SetToolSeparation(7);
437
438 if (style & wxTB_DOCKABLE)
439 {
440 m_widget = gtk_handle_box_new();
441 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
442 gtk_widget_show( GTK_WIDGET(m_toolbar) );
443
444 if (style & wxTB_FLAT)
445 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
446 }
447 else
448 {
449 m_widget = gtk_event_box_new();
450 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
451 ConnectWidget( m_widget );
452 gtk_widget_show(GTK_WIDGET(m_toolbar));
453 }
454
455 // FIXME: there is no such function for toolbars in 2.0
456 #if 0
457 if (style & wxTB_FLAT)
458 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
459 #endif
460
461 m_parent->DoAddChild( this );
462
463 PostCreation(size);
464
465 g_signal_connect_after(m_toolbar, "size_request",
466 G_CALLBACK(size_request), this);
467
468 return true;
469 }
470
471 GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
472 {
473 return GTK_WIDGET(m_toolbar)->window;
474 }
475
476 void wxToolBar::GtkSetStyle()
477 {
478 GtkOrientation orient;
479 GtkToolbarStyle style;
480 GetGtkStyle(GetWindowStyle(), &orient, &style);
481
482 gtk_toolbar_set_orientation(m_toolbar, orient);
483 gtk_toolbar_set_style(m_toolbar, style);
484 gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
485 }
486
487 void wxToolBar::SetWindowStyleFlag( long style )
488 {
489 wxToolBarBase::SetWindowStyleFlag(style);
490
491 if ( m_toolbar )
492 GtkSetStyle();
493 }
494
495 bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
496 {
497 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
498
499 if ( tool->IsButton() )
500 {
501 if ( !HasFlag(wxTB_NOICONS) )
502 {
503 wxBitmap bitmap = tool->GetNormalBitmap();
504
505 wxCHECK_MSG( bitmap.Ok(), false,
506 wxT("invalid bitmap for wxToolBar icon") );
507
508 tool->m_image = gtk_image_new();
509 tool->SetImage(bitmap);
510
511 gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
512 }
513 }
514
515 int posGtk = 0;
516 if ( pos > 0 )
517 {
518 for ( size_t i = 0; i < pos; i++ )
519 {
520 posGtk++;
521
522 // if we have a dropdown menu, we use 2 GTK tools internally
523 wxToolBarToolsList::compatibility_iterator node = m_tools.Item( i );
524 wxToolBarTool * const tool2 = (wxToolBarTool*) node->GetData();
525 if ( tool2->IsButton() && tool2->GetKind() == wxITEM_DROPDOWN )
526 posGtk++;
527 }
528 }
529
530
531 switch ( tool->GetStyle() )
532 {
533 case wxTOOL_STYLE_BUTTON:
534 // for a radio button we need the widget which starts the radio
535 // group it belongs to, i.e. the first radio button immediately
536 // preceding this one
537 {
538 GtkWidget *widget = NULL;
539
540 if ( tool->IsRadio() )
541 {
542 wxToolBarToolsList::compatibility_iterator node
543 = wxToolBarToolsList::compatibility_iterator();
544 if ( pos )
545 node = m_tools.Item(pos - 1);
546
547 while ( node )
548 {
549 wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData();
550 if ( !toolNext->IsRadio() )
551 break;
552
553 widget = toolNext->m_item;
554
555 node = node->GetPrevious();
556 }
557
558 if ( !widget )
559 {
560 // this is the first button in the radio button group,
561 // it will be toggled automatically by GTK so bring the
562 // internal flag in sync
563 tool->Toggle(true);
564 }
565 }
566
567 tool->m_item = gtk_toolbar_insert_element
568 (
569 m_toolbar,
570 tool->GetGtkChildType(),
571 widget,
572 tool->GetLabel().empty()
573 ? NULL
574 : (const char*) wxGTK_CONV( tool->GetLabel() ),
575 tool->GetShortHelp().empty()
576 ? NULL
577 : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
578 "", // tooltip_private_text (?)
579 tool->m_image,
580 (GtkSignalFunc)gtk_toolbar_callback,
581 (gpointer)tool,
582 posGtk
583 );
584
585 wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
586
587 g_signal_connect (tool->m_item, "enter_notify_event",
588 G_CALLBACK (gtk_toolbar_tool_callback),
589 tool);
590 g_signal_connect (tool->m_item, "leave_notify_event",
591 G_CALLBACK (gtk_toolbar_tool_callback),
592 tool);
593 g_signal_connect(tool->m_item, "button-press-event",
594 G_CALLBACK (gtk_toolbar_tool_rclick_callback),
595 tool);
596
597 if (tool->GetKind() == wxITEM_DROPDOWN)
598 {
599 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data( arrow_down_xpm );
600 GtkWidget *dropdown = gtk_toggle_button_new();
601 GtkWidget *image = gtk_image_new_from_pixbuf( pixbuf );
602 gtk_widget_show( image );
603 gtk_container_add( GTK_CONTAINER(dropdown), image );
604 g_object_unref(pixbuf);
605
606 if (GetWindowStyle() & wxTB_FLAT)
607 gtk_button_set_relief( GTK_BUTTON(dropdown), GTK_RELIEF_NONE );
608 GTK_WIDGET_UNSET_FLAGS (dropdown, GTK_CAN_FOCUS);
609 gtk_widget_show( dropdown );
610
611 g_signal_connect (dropdown, "enter_notify_event",
612 G_CALLBACK (gtk_toolbar_buddy_enter_callback),
613 tool->m_item);
614 g_signal_connect (dropdown, "leave_notify_event",
615 G_CALLBACK (gtk_toolbar_buddy_leave_callback),
616 tool->m_item);
617 g_signal_connect(dropdown, "button-press-event",
618 G_CALLBACK (gtk_toolbar_dropdown_lclick_callback),
619 tool);
620
621 GtkRequisition req;
622 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(tool->m_item) )->size_request )
623 (tool->m_item, &req );
624 gtk_widget_set_size_request( dropdown, -1, req.height );
625
626 gtk_toolbar_insert_widget(m_toolbar, dropdown, NULL, NULL,
627 posGtk + 1);
628 tool->m_itemDropdown = dropdown;
629 }
630 }
631 break;
632
633 case wxTOOL_STYLE_SEPARATOR:
634 gtk_toolbar_insert_space( m_toolbar, posGtk );
635 break;
636
637 case wxTOOL_STYLE_CONTROL:
638 GtkWidget * const align = gtk_alignment_new(0.5, 0.5, 0, 0);
639 gtk_widget_show(align);
640 gtk_container_add(GTK_CONTAINER(align),
641 tool->GetControl()->m_widget);
642 gtk_toolbar_insert_widget(m_toolbar, align, NULL, NULL, posGtk);
643
644 // remember the container we're in so that we could remove
645 // ourselves from it when we're detached from the toolbar
646 tool->m_item = align;
647 break;
648 }
649
650 InvalidateBestSize();
651
652 return true;
653 }
654
655 bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
656 {
657 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
658
659 switch ( tool->GetStyle() )
660 {
661 case wxTOOL_STYLE_CONTROL:
662 // don't destroy the control here as we can be called from
663 // RemoveTool() and then we need to keep the control alive;
664 // while if we're called from DeleteTool() the control will
665 // be destroyed when wxToolBarToolBase itself is deleted
666 gtk_container_remove(
667 GTK_CONTAINER(tool->m_item), tool->GetControl()->m_widget);
668 // fall through
669
670 case wxTOOL_STYLE_BUTTON:
671 gtk_widget_destroy( tool->m_item );
672 tool->m_item = NULL;
673 if (tool->m_itemDropdown)
674 {
675 gtk_widget_destroy(tool->m_itemDropdown);
676 tool->m_itemDropdown = NULL;
677 }
678 break;
679
680 case wxTOOL_STYLE_SEPARATOR:
681 gtk_toolbar_remove_space( m_toolbar, pos );
682 break;
683
684 default:
685 wxFAIL_MSG( "unknown tool style" );
686 return false;
687 }
688
689 InvalidateBestSize();
690 return true;
691 }
692
693 // ----------------------------------------------------------------------------
694 // wxToolBar tools state
695 // ----------------------------------------------------------------------------
696
697 void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
698 {
699 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
700
701 if (tool->m_item)
702 {
703 gtk_widget_set_sensitive( tool->m_item, enable );
704 }
705 }
706
707 void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
708 {
709 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
710
711 GtkWidget *item = tool->m_item;
712 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
713 {
714 tool->SetImage(tool->GetBitmap());
715
716 m_blockEvent = true;
717
718 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
719
720 m_blockEvent = false;
721 }
722 }
723
724 void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
725 bool WXUNUSED(toggle))
726 {
727 // VZ: absolutely no idea about how to do it
728 wxFAIL_MSG( _T("not implemented") );
729 }
730
731 // ----------------------------------------------------------------------------
732 // wxToolBar geometry
733 // ----------------------------------------------------------------------------
734
735 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
736 wxCoord WXUNUSED(y)) const
737 {
738 // VZ: GTK+ doesn't seem to have such thing
739 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
740
741 return (wxToolBarToolBase *)NULL;
742 }
743
744 void wxToolBar::SetMargins( int x, int y )
745 {
746 wxCHECK_RET( GetToolsCount() == 0,
747 wxT("wxToolBar::SetMargins must be called before adding tools.") );
748
749 m_xMargin = x;
750 m_yMargin = y;
751 }
752
753 void wxToolBar::SetToolSeparation( int separation )
754 {
755 // FIXME: this function disappeared
756 #if 0
757 gtk_toolbar_set_space_size( m_toolbar, separation );
758 #endif
759
760 m_toolSeparation = separation;
761 }
762
763 void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
764 {
765 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
766
767 if ( tool )
768 {
769 (void)tool->SetShortHelp(helpString);
770 gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
771 wxGTK_CONV( helpString ), "");
772 }
773 }
774
775 void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
776 {
777 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
778 if ( tool )
779 {
780 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
781
782 tool->SetNormalBitmap(bitmap);
783 tool->SetImage(tool->GetBitmap());
784 }
785 }
786
787 void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
788 {
789 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
790 if ( tool )
791 {
792 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
793
794 tool->SetDisabledBitmap(bitmap);
795 tool->SetImage(tool->GetBitmap());
796 }
797 }
798
799 // ----------------------------------------------------------------------------
800 // wxToolBar idle handling
801 // ----------------------------------------------------------------------------
802
803 void wxToolBar::OnInternalIdle()
804 {
805 // Check if we have to show window now
806 if (GtkShowFromOnIdle()) return;
807
808 wxCursor cursor = m_cursor;
809 if (g_globalCursor.Ok()) cursor = g_globalCursor;
810
811 if (cursor.Ok())
812 {
813 /* I now set the cursor the anew in every OnInternalIdle call
814 as setting the cursor in a parent window also effects the
815 windows above so that checking for the current cursor is
816 not possible. */
817
818 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
819 {
820 /* if the toolbar is dockable, then m_widget stands for the
821 GtkHandleBox widget, which uses its own window so that we
822 can set the cursor for it. if the toolbar is not dockable,
823 m_widget comes from m_toolbar which uses its parent's
824 window ("windowless windows") and thus we cannot set the
825 cursor. */
826 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
827 }
828
829 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
830 while ( node )
831 {
832 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
833 node = node->GetNext();
834
835 GtkWidget *item = tool->m_item;
836 if ( item )
837 {
838 GdkWindow *window = item->window;
839
840 if ( window )
841 {
842 gdk_window_set_cursor( window, cursor.GetCursor() );
843 }
844 }
845 }
846 }
847
848 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
849 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
850 }
851
852
853 // ----------------------------------------------------------------------------
854
855 // static
856 wxVisualAttributes
857 wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
858 {
859 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
860 }
861
862 #endif // wxUSE_TOOLBAR_NATIVE