]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/tbargtk.cpp
Really don't do anything (including not setting the
[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/menu.h"
39
40
41 /* XPM */
42 static const char *arrow_down_xpm[] = {
43 /* columns rows colors chars-per-pixel */
44 "7 7 2 1",
45 " c None",
46 ". c Black",
47 /* pixels */
48 " ",
49 " ",
50 " ",
51 ".......",
52 " ..... ",
53 " ... ",
54 " . "
55 };
56
57
58 // ----------------------------------------------------------------------------
59 // globals
60 // ----------------------------------------------------------------------------
61
62 // data
63 extern bool g_blockEventsOnDrag;
64 extern wxCursor g_globalCursor;
65
66 // ----------------------------------------------------------------------------
67 // private functions
68 // ----------------------------------------------------------------------------
69
70 // translate wxWidgets toolbar style flags to GTK orientation and style
71 static void GetGtkStyle(long style,
72 GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
73 {
74 *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
75
76
77 if ( style & wxTB_TEXT )
78 {
79 *gtkStyle = style & wxTB_NOICONS
80 ? GTK_TOOLBAR_TEXT
81 : (
82 style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ :
83 GTK_TOOLBAR_BOTH);
84 }
85 else // no text, hence we must have the icons or what would we show?
86 {
87 *gtkStyle = GTK_TOOLBAR_ICONS;
88 }
89 }
90
91 // ----------------------------------------------------------------------------
92 // wxToolBarTool
93 // ----------------------------------------------------------------------------
94
95 class wxToolBarTool : public wxToolBarToolBase
96 {
97 public:
98 wxToolBarTool(wxToolBar *tbar,
99 int id,
100 const wxString& label,
101 const wxBitmap& bitmap1,
102 const wxBitmap& bitmap2,
103 wxItemKind kind,
104 wxObject *clientData,
105 const wxString& shortHelpString,
106 const wxString& longHelpString)
107 : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
108 clientData, shortHelpString, longHelpString)
109 {
110 Init();
111 }
112
113 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
114 : wxToolBarToolBase(tbar, control, label)
115 {
116 Init();
117 }
118
119 // is this a radio button?
120 //
121 // unlike GetKind(), can be called for any kind of tools, not just buttons
122 bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; }
123
124 // this is only called for the normal buttons, i.e. not separators nor
125 // controls
126 GtkToolbarChildType GetGtkChildType() const
127 {
128 switch ( GetKind() )
129 {
130 case wxITEM_CHECK:
131 return GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
132
133 case wxITEM_RADIO:
134 return GTK_TOOLBAR_CHILD_RADIOBUTTON;
135
136 default:
137 wxFAIL_MSG( _T("unknown toolbar child type") );
138 // fall through
139
140 case wxITEM_NORMAL:
141 return GTK_TOOLBAR_CHILD_BUTTON;
142 }
143 }
144
145 void SetImage(const wxBitmap& bitmap)
146 {
147 if (bitmap.Ok())
148 {
149 // setting from pixmap doesn't seem to work right, but pixbuf works well
150 gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
151 }
152 }
153
154 GtkWidget *m_item;
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 *WXUNUSED(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->GetEventHandler()->ProcessEvent(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 extern "C" {
341 static
342 void gtktoolwidget_size_callback( GtkWidget *widget,
343 GtkAllocation *alloc,
344 wxWindow *win )
345 {
346 // this shouldn't happen...
347 if (win->GetParent()->m_wxwindow) return;
348
349 wxSize size = win->GetEffectiveMinSize();
350 if (size.y != alloc->height)
351 {
352 GtkAllocation alloc2;
353 alloc2.x = alloc->x;
354 alloc2.y = (alloc->height - size.y + 3) / 2;
355 alloc2.width = alloc->width;
356 alloc2.height = size.y;
357 gtk_widget_size_allocate( widget, &alloc2 );
358 }
359 }
360 }
361 //-----------------------------------------------------------------------------
362 // InsertChild callback for wxToolBar
363 //-----------------------------------------------------------------------------
364
365 static void wxInsertChildInToolBar( wxWindow* WXUNUSED(parent),
366 wxWindow* WXUNUSED(child) )
367 {
368 // we don't do anything here
369 }
370
371 // ----------------------------------------------------------------------------
372 // wxToolBarTool
373 // ----------------------------------------------------------------------------
374
375 void wxToolBarTool::Init()
376 {
377 m_item =
378 m_image = NULL;
379 }
380
381 wxToolBarToolBase *wxToolBar::CreateTool(int id,
382 const wxString& text,
383 const wxBitmap& bitmap1,
384 const wxBitmap& bitmap2,
385 wxItemKind kind,
386 wxObject *clientData,
387 const wxString& shortHelpString,
388 const wxString& longHelpString)
389 {
390 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
391 clientData, shortHelpString, longHelpString);
392 }
393
394 wxToolBarToolBase *
395 wxToolBar::CreateTool(wxControl *control, const wxString& label)
396 {
397 return new wxToolBarTool(this, control, label);
398 }
399
400 //-----------------------------------------------------------------------------
401 // wxToolBar construction
402 //-----------------------------------------------------------------------------
403
404 void wxToolBar::Init()
405 {
406 m_toolbar = (GtkToolbar *)NULL;
407 m_blockEvent = false;
408 m_defaultWidth = 32;
409 m_defaultHeight = 32;
410 }
411
412 wxToolBar::~wxToolBar()
413 {
414 }
415
416 bool wxToolBar::Create( wxWindow *parent,
417 wxWindowID id,
418 const wxPoint& pos,
419 const wxSize& size,
420 long style,
421 const wxString& name )
422 {
423 m_insertCallback = wxInsertChildInToolBar;
424
425 if ( !PreCreation( parent, pos, size ) ||
426 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
427 {
428 wxFAIL_MSG( wxT("wxToolBar creation failed") );
429
430 return false;
431 }
432
433 FixupStyle();
434
435 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
436 GtkSetStyle();
437
438 // Doesn't work this way.
439 // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
440 // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
441
442 SetToolSeparation(7);
443
444 if (style & wxTB_DOCKABLE)
445 {
446 m_widget = gtk_handle_box_new();
447 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
448 gtk_widget_show( GTK_WIDGET(m_toolbar) );
449
450 if (style & wxTB_FLAT)
451 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
452 }
453 else
454 {
455 m_widget = gtk_event_box_new();
456 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
457 ConnectWidget( m_widget );
458 gtk_widget_show(GTK_WIDGET(m_toolbar));
459 }
460
461 // FIXME: there is no such function for toolbars in 2.0
462 #if 0
463 if (style & wxTB_FLAT)
464 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
465 #endif
466
467 m_parent->DoAddChild( this );
468
469 PostCreation(size);
470
471 return true;
472 }
473
474 GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const
475 {
476 return GTK_WIDGET(m_toolbar)->window;
477 }
478
479 void wxToolBar::GtkSetStyle()
480 {
481 GtkOrientation orient;
482 GtkToolbarStyle style;
483 GetGtkStyle(GetWindowStyle(), &orient, &style);
484
485 gtk_toolbar_set_orientation(m_toolbar, orient);
486 gtk_toolbar_set_style(m_toolbar, style);
487 gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
488 }
489
490 void wxToolBar::SetWindowStyleFlag( long style )
491 {
492 wxToolBarBase::SetWindowStyleFlag(style);
493
494 if ( m_toolbar )
495 GtkSetStyle();
496 }
497
498 bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
499 {
500 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
501
502 if ( tool->IsButton() )
503 {
504 if ( !HasFlag(wxTB_NOICONS) )
505 {
506 wxBitmap bitmap = tool->GetNormalBitmap();
507
508 wxCHECK_MSG( bitmap.Ok(), false,
509 wxT("invalid bitmap for wxToolBar icon") );
510
511 tool->m_image = gtk_image_new();
512 tool->SetImage(bitmap);
513
514 gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
515 }
516 }
517
518 int posGtk = 0;
519 if (pos > 0)
520 {
521 size_t i;
522 for (i = 0; i < pos; i++)
523 {
524 posGtk++;
525
526
527 // if we have a dropdown menu, we use 2 GTK tools
528 // internally
529 wxToolBarToolsList::compatibility_iterator node = m_tools.Item( i );
530 wxToolBarTool *tool = (wxToolBarTool*) node->GetData();
531 if (tool->IsButton() && (tool->GetKind() == wxITEM_DROPDOWN))
532 posGtk++;
533 }
534 }
535
536
537 switch ( tool->GetStyle() )
538 {
539 case wxTOOL_STYLE_BUTTON:
540 // for a radio button we need the widget which starts the radio
541 // group it belongs to, i.e. the first radio button immediately
542 // preceding this one
543 {
544 GtkWidget *widget = NULL;
545
546 if ( tool->IsRadio() )
547 {
548 wxToolBarToolsList::compatibility_iterator node
549 = wxToolBarToolsList::compatibility_iterator();
550 if ( pos )
551 node = m_tools.Item(pos - 1);
552
553 while ( node )
554 {
555 wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData();
556 if ( !toolNext->IsRadio() )
557 break;
558
559 widget = toolNext->m_item;
560
561 node = node->GetPrevious();
562 }
563
564 if ( !widget )
565 {
566 // this is the first button in the radio button group,
567 // it will be toggled automatically by GTK so bring the
568 // internal flag in sync
569 tool->Toggle(true);
570 }
571 }
572
573 tool->m_item = gtk_toolbar_insert_element
574 (
575 m_toolbar,
576 tool->GetGtkChildType(),
577 widget,
578 tool->GetLabel().empty()
579 ? NULL
580 : (const char*) wxGTK_CONV( tool->GetLabel() ),
581 tool->GetShortHelp().empty()
582 ? NULL
583 : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
584 "", // tooltip_private_text (?)
585 tool->m_image,
586 (GtkSignalFunc)gtk_toolbar_callback,
587 (gpointer)tool,
588 posGtk
589 );
590
591 wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
592
593 g_signal_connect (tool->m_item, "enter_notify_event",
594 G_CALLBACK (gtk_toolbar_tool_callback),
595 tool);
596 g_signal_connect (tool->m_item, "leave_notify_event",
597 G_CALLBACK (gtk_toolbar_tool_callback),
598 tool);
599 g_signal_connect(tool->m_item, "button-press-event",
600 G_CALLBACK (gtk_toolbar_tool_rclick_callback),
601 tool);
602
603 if (tool->GetKind() == wxITEM_DROPDOWN)
604 {
605 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data( arrow_down_xpm );
606 GtkWidget *dropdown = gtk_toggle_button_new();
607 GtkWidget *image = gtk_image_new_from_pixbuf( pixbuf );
608 gtk_widget_show( image );
609 gtk_container_add( GTK_CONTAINER(dropdown), image );
610
611 if (GetWindowStyle() & wxTB_FLAT)
612 gtk_button_set_relief( GTK_BUTTON(dropdown), GTK_RELIEF_NONE );
613 GTK_WIDGET_UNSET_FLAGS (dropdown, GTK_CAN_FOCUS);
614 gtk_widget_show( dropdown );
615
616 g_signal_connect (dropdown, "enter_notify_event",
617 G_CALLBACK (gtk_toolbar_buddy_enter_callback),
618 tool->m_item);
619 g_signal_connect (dropdown, "leave_notify_event",
620 G_CALLBACK (gtk_toolbar_buddy_leave_callback),
621 tool->m_item);
622 g_signal_connect(dropdown, "button-press-event",
623 G_CALLBACK (gtk_toolbar_dropdown_lclick_callback),
624 tool);
625
626 GtkRequisition req;
627 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(tool->m_item) )->size_request )
628 (tool->m_item, &req );
629 gtk_widget_set_size_request( dropdown, -1, req.height );
630
631 gtk_toolbar_insert_widget(
632 m_toolbar,
633 dropdown,
634 (const char *) NULL,
635 (const char *) NULL,
636 posGtk+1
637 );
638 }
639 }
640 break;
641
642 case wxTOOL_STYLE_SEPARATOR:
643 gtk_toolbar_insert_space( m_toolbar, posGtk );
644
645 // skip the rest
646 return true;
647
648 case wxTOOL_STYLE_CONTROL:
649 gtk_toolbar_insert_widget(
650 m_toolbar,
651 tool->GetControl()->m_widget,
652 (const char *) NULL,
653 (const char *) NULL,
654 posGtk
655 );
656
657 // connect after in order to correct size_allocate events
658 g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate",
659 G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl());
660
661 break;
662 }
663
664 GtkRequisition req;
665 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
666 (m_widget, &req );
667 m_width = req.width + m_xMargin;
668 m_height = req.height + 2*m_yMargin;
669 InvalidateBestSize();
670
671 return true;
672 }
673
674 bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
675 {
676 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
677
678 switch ( tool->GetStyle() )
679 {
680 case wxTOOL_STYLE_CONTROL:
681 tool->GetControl()->Destroy();
682 break;
683
684 case wxTOOL_STYLE_BUTTON:
685 gtk_widget_destroy( tool->m_item );
686 break;
687
688 case wxTOOL_STYLE_SEPARATOR:
689 gtk_toolbar_remove_space( m_toolbar, pos );
690 break;
691 }
692
693 InvalidateBestSize();
694 return true;
695 }
696
697 // ----------------------------------------------------------------------------
698 // wxToolBar tools state
699 // ----------------------------------------------------------------------------
700
701 void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
702 {
703 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
704
705 if (tool->m_item)
706 {
707 gtk_widget_set_sensitive( tool->m_item, enable );
708 }
709 }
710
711 void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
712 {
713 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
714
715 GtkWidget *item = tool->m_item;
716 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
717 {
718 tool->SetImage(tool->GetBitmap());
719
720 m_blockEvent = true;
721
722 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
723
724 m_blockEvent = false;
725 }
726 }
727
728 void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
729 bool WXUNUSED(toggle))
730 {
731 // VZ: absolutely no idea about how to do it
732 wxFAIL_MSG( _T("not implemented") );
733 }
734
735 // ----------------------------------------------------------------------------
736 // wxToolBar geometry
737 // ----------------------------------------------------------------------------
738
739 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
740 wxCoord WXUNUSED(y)) const
741 {
742 // VZ: GTK+ doesn't seem to have such thing
743 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
744
745 return (wxToolBarToolBase *)NULL;
746 }
747
748 void wxToolBar::SetMargins( int x, int y )
749 {
750 wxCHECK_RET( GetToolsCount() == 0,
751 wxT("wxToolBar::SetMargins must be called before adding tools.") );
752
753 m_xMargin = x;
754 m_yMargin = y;
755 }
756
757 void wxToolBar::SetToolSeparation( int separation )
758 {
759 // FIXME: this function disappeared
760 #if 0
761 gtk_toolbar_set_space_size( m_toolbar, separation );
762 #endif
763
764 m_toolSeparation = separation;
765 }
766
767 void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
768 {
769 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
770
771 if ( tool )
772 {
773 (void)tool->SetShortHelp(helpString);
774 gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
775 wxGTK_CONV( helpString ), "");
776 }
777 }
778
779 void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
780 {
781 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
782 if ( tool )
783 {
784 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
785
786 tool->SetNormalBitmap(bitmap);
787 tool->SetImage(tool->GetBitmap());
788 }
789 }
790
791 void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
792 {
793 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
794 if ( tool )
795 {
796 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
797
798 tool->SetDisabledBitmap(bitmap);
799 tool->SetImage(tool->GetBitmap());
800 }
801 }
802
803 // ----------------------------------------------------------------------------
804 // wxToolBar idle handling
805 // ----------------------------------------------------------------------------
806
807 void wxToolBar::OnInternalIdle()
808 {
809 // Check if we have to show window now
810 if (GtkShowFromOnIdle()) return;
811
812 wxCursor cursor = m_cursor;
813 if (g_globalCursor.Ok()) cursor = g_globalCursor;
814
815 if (cursor.Ok())
816 {
817 /* I now set the cursor the anew in every OnInternalIdle call
818 as setting the cursor in a parent window also effects the
819 windows above so that checking for the current cursor is
820 not possible. */
821
822 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
823 {
824 /* if the toolbar is dockable, then m_widget stands for the
825 GtkHandleBox widget, which uses its own window so that we
826 can set the cursor for it. if the toolbar is not dockable,
827 m_widget comes from m_toolbar which uses its parent's
828 window ("windowless windows") and thus we cannot set the
829 cursor. */
830 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
831 }
832
833 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
834 while ( node )
835 {
836 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
837 node = node->GetNext();
838
839 GtkWidget *item = tool->m_item;
840 if ( item )
841 {
842 GdkWindow *window = item->window;
843
844 if ( window )
845 {
846 gdk_window_set_cursor( window, cursor.GetCursor() );
847 }
848 }
849 }
850 }
851
852 if (wxUpdateUIEvent::CanUpdate(this))
853 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
854 }
855
856
857 // ----------------------------------------------------------------------------
858
859 // static
860 wxVisualAttributes
861 wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
862 {
863 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
864 }
865
866 #endif // wxUSE_TOOLBAR_NATIVE