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