]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/tbargtk.cpp
create hatch bitmaps on demand, and dispose of them at termination
[wxWidgets.git] / src / gtk / tbargtk.cpp
... / ...
CommitLineData
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 */
29static 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
50extern bool g_blockEventsOnDrag;
51extern wxCursor g_globalCursor;
52
53// ----------------------------------------------------------------------------
54// private functions
55// ----------------------------------------------------------------------------
56
57// translate wxWidgets toolbar style flags to GTK orientation and style
58static 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
82class wxToolBarTool : public wxToolBarToolBase
83{
84public:
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
145protected:
146 void Init();
147};
148
149// ----------------------------------------------------------------------------
150// wxWin macros
151// ----------------------------------------------------------------------------
152
153IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
154
155// ============================================================================
156// implementation
157// ============================================================================
158
159//-----------------------------------------------------------------------------
160// "clicked" (internal from gtk_toolbar)
161//-----------------------------------------------------------------------------
162
163extern "C" {
164static 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//-----------------------------------------------------------------------------
208extern "C" {
209static 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
233extern "C" {
234static 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
244static 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
259extern "C"
260{
261static void gtk_pop_tb_hide_callback( GtkWidget *WXUNUSED(menu), GtkToggleButton *button )
262{
263 gtk_toggle_button_set_active( button, FALSE );
264}
265
266static 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
309extern "C" {
310static 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
332extern "C" {
333static void
334size_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
346static 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
358void wxToolBarTool::Init()
359{
360 m_item =
361 m_image = NULL;
362}
363
364wxToolBarToolBase *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
377wxToolBarToolBase *
378wxToolBar::CreateTool(wxControl *control, const wxString& label)
379{
380 return new wxToolBarTool(this, control, label);
381}
382
383//-----------------------------------------------------------------------------
384// wxToolBar construction
385//-----------------------------------------------------------------------------
386
387void wxToolBar::Init()
388{
389 m_toolbar = (GtkToolbar *)NULL;
390 m_blockEvent = false;
391 m_defaultWidth = 32;
392 m_defaultHeight = 32;
393}
394
395wxToolBar::~wxToolBar()
396{
397}
398
399bool 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
460GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
461{
462 return GTK_WIDGET(m_toolbar)->window;
463}
464
465void 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
476void wxToolBar::SetWindowStyleFlag( long style )
477{
478 wxToolBarBase::SetWindowStyleFlag(style);
479
480 if ( m_toolbar )
481 GtkSetStyle();
482}
483
484bool 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#if 1
633 GtkWidget* align = gtk_alignment_new(0.5, 0.5, 0, 0);
634 gtk_widget_show(align);
635 gtk_container_add((GtkContainer*)align, tool->GetControl()->m_widget);
636 gtk_toolbar_insert_widget(
637 m_toolbar,
638 align,
639 (const char *) NULL,
640 (const char *) NULL,
641 posGtk
642 );
643#else
644 gtk_toolbar_insert_widget(
645 m_toolbar,
646 tool->GetControl()->m_widget,
647 (const char *) NULL,
648 (const char *) NULL,
649 posGtk
650 );
651#endif
652 // release reference obtained by wxInsertChildInToolBar
653 g_object_unref(tool->GetControl()->m_widget);
654 break;
655 }
656
657 InvalidateBestSize();
658
659 return true;
660}
661
662bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
663{
664 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
665
666 switch ( tool->GetStyle() )
667 {
668 case wxTOOL_STYLE_CONTROL:
669 tool->GetControl()->Destroy();
670 break;
671
672 case wxTOOL_STYLE_BUTTON:
673 gtk_widget_destroy( tool->m_item );
674 break;
675
676 case wxTOOL_STYLE_SEPARATOR:
677 gtk_toolbar_remove_space( m_toolbar, pos );
678 break;
679 }
680
681 InvalidateBestSize();
682 return true;
683}
684
685// ----------------------------------------------------------------------------
686// wxToolBar tools state
687// ----------------------------------------------------------------------------
688
689void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
690{
691 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
692
693 if (tool->m_item)
694 {
695 gtk_widget_set_sensitive( tool->m_item, enable );
696 }
697}
698
699void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
700{
701 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
702
703 GtkWidget *item = tool->m_item;
704 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
705 {
706 tool->SetImage(tool->GetBitmap());
707
708 m_blockEvent = true;
709
710 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
711
712 m_blockEvent = false;
713 }
714}
715
716void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
717 bool WXUNUSED(toggle))
718{
719 // VZ: absolutely no idea about how to do it
720 wxFAIL_MSG( _T("not implemented") );
721}
722
723// ----------------------------------------------------------------------------
724// wxToolBar geometry
725// ----------------------------------------------------------------------------
726
727wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
728 wxCoord WXUNUSED(y)) const
729{
730 // VZ: GTK+ doesn't seem to have such thing
731 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
732
733 return (wxToolBarToolBase *)NULL;
734}
735
736void wxToolBar::SetMargins( int x, int y )
737{
738 wxCHECK_RET( GetToolsCount() == 0,
739 wxT("wxToolBar::SetMargins must be called before adding tools.") );
740
741 m_xMargin = x;
742 m_yMargin = y;
743}
744
745void wxToolBar::SetToolSeparation( int separation )
746{
747 // FIXME: this function disappeared
748#if 0
749 gtk_toolbar_set_space_size( m_toolbar, separation );
750#endif
751
752 m_toolSeparation = separation;
753}
754
755void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
756{
757 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
758
759 if ( tool )
760 {
761 (void)tool->SetShortHelp(helpString);
762 gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
763 wxGTK_CONV( helpString ), "");
764 }
765}
766
767void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
768{
769 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
770 if ( tool )
771 {
772 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
773
774 tool->SetNormalBitmap(bitmap);
775 tool->SetImage(tool->GetBitmap());
776 }
777}
778
779void wxToolBar::SetToolDisabledBitmap( 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->SetDisabledBitmap(bitmap);
787 tool->SetImage(tool->GetBitmap());
788 }
789}
790
791// ----------------------------------------------------------------------------
792// wxToolBar idle handling
793// ----------------------------------------------------------------------------
794
795void wxToolBar::OnInternalIdle()
796{
797 // Check if we have to show window now
798 if (GtkShowFromOnIdle()) return;
799
800 wxCursor cursor = m_cursor;
801 if (g_globalCursor.Ok()) cursor = g_globalCursor;
802
803 if (cursor.Ok())
804 {
805 /* I now set the cursor the anew in every OnInternalIdle call
806 as setting the cursor in a parent window also effects the
807 windows above so that checking for the current cursor is
808 not possible. */
809
810 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
811 {
812 /* if the toolbar is dockable, then m_widget stands for the
813 GtkHandleBox widget, which uses its own window so that we
814 can set the cursor for it. if the toolbar is not dockable,
815 m_widget comes from m_toolbar which uses its parent's
816 window ("windowless windows") and thus we cannot set the
817 cursor. */
818 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
819 }
820
821 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
822 while ( node )
823 {
824 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
825 node = node->GetNext();
826
827 GtkWidget *item = tool->m_item;
828 if ( item )
829 {
830 GdkWindow *window = item->window;
831
832 if ( window )
833 {
834 gdk_window_set_cursor( window, cursor.GetCursor() );
835 }
836 }
837 }
838 }
839
840 if (wxUpdateUIEvent::CanUpdate(this))
841 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
842}
843
844
845// ----------------------------------------------------------------------------
846
847// static
848wxVisualAttributes
849wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
850{
851 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
852}
853
854#endif // wxUSE_TOOLBAR_NATIVE