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