]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/tbargtk.cpp
PCH-less compilation fix
[wxWidgets.git] / src / gtk / tbargtk.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/gtk/tbargtk.cpp
c801d85f
KB
3// Purpose: GTK toolbar
4// Author: Robert Roebling
8a0681f9 5// Modified: 13.12.99 by VZ to derive from wxToolBarBase
32e9da8b 6// RCS-ID: $Id$
c801d85f 7// Copyright: (c) Robert Roebling
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
8a0681f9
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
14f355c2
VS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
8a0681f9 22#if wxUSE_TOOLBAR_NATIVE
dcf924a3 23
4e3e485b
WS
24#include "wx/toolbar.h"
25
76b49cf4
WS
26#ifndef WX_PRECOMP
27 #include "wx/frame.h"
28#endif
c801d85f 29
1efb5db8
MR
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
9e691f46 37#include "wx/gtk/private.h"
83624f79 38
8a0681f9
VZ
39// ----------------------------------------------------------------------------
40// globals
41// ----------------------------------------------------------------------------
acfd422a 42
314055fa 43// data
9b7e522a
RR
44extern bool g_blockEventsOnDrag;
45extern wxCursor g_globalCursor;
314055fa 46
e76c0b5f
VZ
47// ----------------------------------------------------------------------------
48// private functions
49// ----------------------------------------------------------------------------
50
77ffb593 51// translate wxWidgets toolbar style flags to GTK orientation and style
e76c0b5f
VZ
52static void GetGtkStyle(long style,
53 GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
54{
7a976304 55 *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
e76c0b5f
VZ
56
57
58 if ( style & wxTB_TEXT )
59 {
99e8cb50
VZ
60 *gtkStyle = style & wxTB_NOICONS
61 ? GTK_TOOLBAR_TEXT
62 : (
99e8cb50 63 style & wxTB_HORZ_LAYOUT ? GTK_TOOLBAR_BOTH_HORIZ :
99e8cb50 64 GTK_TOOLBAR_BOTH);
e76c0b5f
VZ
65 }
66 else // no text, hence we must have the icons or what would we show?
67 {
68 *gtkStyle = GTK_TOOLBAR_ICONS;
69 }
70}
71
8a0681f9
VZ
72// ----------------------------------------------------------------------------
73// wxToolBarTool
74// ----------------------------------------------------------------------------
75
76class wxToolBarTool : public wxToolBarToolBase
77{
78public:
79 wxToolBarTool(wxToolBar *tbar,
80 int id,
e76c0b5f 81 const wxString& label,
8a0681f9
VZ
82 const wxBitmap& bitmap1,
83 const wxBitmap& bitmap2,
e76c0b5f 84 wxItemKind kind,
8a0681f9
VZ
85 wxObject *clientData,
86 const wxString& shortHelpString,
87 const wxString& longHelpString)
e76c0b5f 88 : wxToolBarToolBase(tbar, id, label, bitmap1, bitmap2, kind,
8a0681f9
VZ
89 clientData, shortHelpString, longHelpString)
90 {
91 Init();
92 }
93
07d02e9e
VZ
94 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
95 : wxToolBarToolBase(tbar, control, label)
8a0681f9
VZ
96 {
97 Init();
98 }
99
38762f09
VZ
100 // is this a radio button?
101 //
102 // unlike GetKind(), can be called for any kind of tools, not just buttons
103 bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; }
104
e76c0b5f
VZ
105 // this is only called for the normal buttons, i.e. not separators nor
106 // controls
107 GtkToolbarChildType GetGtkChildType() const
108 {
109 switch ( GetKind() )
110 {
111 case wxITEM_CHECK:
112 return GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
113
114 case wxITEM_RADIO:
115 return GTK_TOOLBAR_CHILD_RADIOBUTTON;
116
117 default:
118 wxFAIL_MSG( _T("unknown toolbar child type") );
119 // fall through
120
121 case wxITEM_NORMAL:
122 return GTK_TOOLBAR_CHILD_BUTTON;
123 }
124 }
125
eba91e51 126 void SetImage(const wxBitmap& bitmap)
ab86c659
VS
127 {
128 if (bitmap.Ok())
129 {
eba91e51
PC
130 // setting from pixmap doesn't seem to work right, but pixbuf works well
131 gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
ab86c659
VS
132 }
133 }
134
8a0681f9 135 GtkWidget *m_item;
eba91e51 136 GtkWidget *m_image;
8a0681f9
VZ
137
138protected:
139 void Init();
140};
141
142// ----------------------------------------------------------------------------
143// wxWin macros
144// ----------------------------------------------------------------------------
145
2eb10e2a 146IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
8a0681f9
VZ
147
148// ============================================================================
149// implementation
150// ============================================================================
151
c801d85f 152//-----------------------------------------------------------------------------
2f2aa628 153// "clicked" (internal from gtk_toolbar)
c801d85f
KB
154//-----------------------------------------------------------------------------
155
865bb325 156extern "C" {
8a0681f9
VZ
157static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
158 wxToolBarTool *tool )
c801d85f 159{
8a0681f9 160 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
248bcf0a 161
9864c56d 162 if (tbar->m_blockEvent) return;
acfd422a 163
1144d24d 164 if (g_blockEventsOnDrag) return;
8a0681f9 165 if (!tool->IsEnabled()) return;
a3622daa 166
8a0681f9 167 if (tool->CanBeToggled())
248bcf0a 168 {
8a0681f9
VZ
169 tool->Toggle();
170
eba91e51 171 tool->SetImage(tool->GetBitmap());
38762f09
VZ
172
173 if ( tool->IsRadio() && !tool->IsToggled() )
174 {
175 // radio button went up, don't report this as a wxWin event
176 return;
177 }
85eb36c2 178 }
a3622daa 179
6bb7cee4
VZ
180 if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() )
181 {
182 // revert back
183 tool->Toggle();
184
eba91e51 185 tool->SetImage(tool->GetBitmap());
6bb7cee4 186 }
fc008f25 187}
865bb325 188}
c801d85f 189
2f2aa628 190//-----------------------------------------------------------------------------
a8945eef 191// "enter_notify_event" / "leave_notify_event"
2f2aa628
RR
192//-----------------------------------------------------------------------------
193
865bb325 194extern "C" {
248bcf0a 195static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
a8945eef
MB
196 GdkEventCrossing *gdk_event,
197 wxToolBarTool *tool )
314055fa 198{
1144d24d 199 if (g_blockEventsOnDrag) return TRUE;
248bcf0a 200
8a0681f9 201 wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
248bcf0a 202
47c93b63 203 // emit the event
a8945eef
MB
204 if( gdk_event->type == GDK_ENTER_NOTIFY )
205 tb->OnMouseEnter( tool->GetId() );
206 else
207 tb->OnMouseEnter( -1 );
248bcf0a 208
1144d24d 209 return FALSE;
314055fa 210}
865bb325 211}
314055fa 212
86b65467
RR
213extern "C" {
214static
215void gtktoolwidget_size_callback( GtkWidget *widget,
216 GtkAllocation *alloc,
217 wxWindow *win )
218{
219 // this shouldn't happen...
220 if (win->GetParent()->m_wxwindow) return;
f4322df6 221
86b65467
RR
222 wxSize size = win->GetEffectiveMinSize();
223 if (size.y != alloc->height)
224 {
225 GtkAllocation alloc2;
226 alloc2.x = alloc->x;
227 alloc2.y = (alloc->height - size.y + 3) / 2;
228 alloc2.width = alloc->width;
229 alloc2.height = size.y;
230 gtk_widget_size_allocate( widget, &alloc2 );
231 }
232}
233}
bf9e3e73
RR
234//-----------------------------------------------------------------------------
235// InsertChild callback for wxToolBar
236//-----------------------------------------------------------------------------
237
8a0681f9
VZ
238static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
239 wxWindow* WXUNUSED(child) )
bf9e3e73 240{
47c93b63 241 // we don't do anything here
bf9e3e73
RR
242}
243
8a0681f9
VZ
244// ----------------------------------------------------------------------------
245// wxToolBarTool
246// ----------------------------------------------------------------------------
c801d85f 247
8a0681f9
VZ
248void wxToolBarTool::Init()
249{
250 m_item =
eba91e51 251 m_image = NULL;
8a0681f9 252}
c801d85f 253
8a0681f9 254wxToolBarToolBase *wxToolBar::CreateTool(int id,
e76c0b5f 255 const wxString& text,
8a0681f9
VZ
256 const wxBitmap& bitmap1,
257 const wxBitmap& bitmap2,
e76c0b5f 258 wxItemKind kind,
8a0681f9
VZ
259 wxObject *clientData,
260 const wxString& shortHelpString,
261 const wxString& longHelpString)
262{
e76c0b5f 263 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
8a0681f9
VZ
264 clientData, shortHelpString, longHelpString);
265}
b1da76e1 266
07d02e9e
VZ
267wxToolBarToolBase *
268wxToolBar::CreateTool(wxControl *control, const wxString& label)
c801d85f 269{
07d02e9e 270 return new wxToolBarTool(this, control, label);
fc008f25 271}
c801d85f 272
8a0681f9
VZ
273//-----------------------------------------------------------------------------
274// wxToolBar construction
275//-----------------------------------------------------------------------------
276
277void wxToolBar::Init()
c801d85f 278{
8a0681f9 279 m_toolbar = (GtkToolbar *)NULL;
91af0895 280 m_blockEvent = false;
d2c0a964
RD
281 m_defaultWidth = 32;
282 m_defaultHeight = 32;
fc008f25 283}
c801d85f 284
a3622daa 285wxToolBar::~wxToolBar()
c801d85f 286{
fc008f25 287}
c801d85f 288
8a0681f9
VZ
289bool wxToolBar::Create( wxWindow *parent,
290 wxWindowID id,
291 const wxPoint& pos,
292 const wxSize& size,
293 long style,
294 const wxString& name )
c801d85f 295{
bf9e3e73 296 m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
a3622daa 297
8a0681f9
VZ
298 if ( !PreCreation( parent, pos, size ) ||
299 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
4dcaf11a 300 {
223d09f6 301 wxFAIL_MSG( wxT("wxToolBar creation failed") );
c801d85f 302
91af0895 303 return false;
8a0681f9 304 }
a3622daa 305
d408730c
VZ
306 FixupStyle();
307
9e691f46 308 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
e76c0b5f 309 GtkSetStyle();
99e8cb50 310
2b5f62a0
VZ
311 // Doesn't work this way.
312 // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
313 // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
a3622daa 314
8a0681f9 315 SetToolSeparation(7);
3502e687
RR
316
317 if (style & wxTB_DOCKABLE)
318 {
319 m_widget = gtk_handle_box_new();
f03fc89f
VZ
320 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
321 gtk_widget_show( GTK_WIDGET(m_toolbar) );
8a0681f9 322
f03fc89f 323 if (style & wxTB_FLAT)
858b5bdd 324 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
3502e687
RR
325 }
326 else
248bcf0a
RD
327 {
328 m_widget = gtk_event_box_new();
329 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
330 ConnectWidget( m_widget );
331 gtk_widget_show(GTK_WIDGET(m_toolbar));
3502e687 332 }
8a0681f9 333
9e691f46 334 // FIXME: there is no such function for toolbars in 2.0
68567a96 335#if 0
858b5bdd
RR
336 if (style & wxTB_FLAT)
337 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
9e691f46 338#endif
be25e480 339
f03fc89f 340 m_parent->DoAddChild( this );
8a0681f9 341
abdeb9e7 342 PostCreation(size);
a3622daa 343
91af0895 344 return true;
fc008f25 345}
c801d85f 346
48468900
RR
347GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const
348{
349 return GTK_WIDGET(m_toolbar)->window;
350}
351
e76c0b5f
VZ
352void wxToolBar::GtkSetStyle()
353{
354 GtkOrientation orient;
355 GtkToolbarStyle style;
356 GetGtkStyle(GetWindowStyle(), &orient, &style);
357
358 gtk_toolbar_set_orientation(m_toolbar, orient);
359 gtk_toolbar_set_style(m_toolbar, style);
8c4e2405 360 gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
e76c0b5f
VZ
361}
362
363void wxToolBar::SetWindowStyleFlag( long style )
364{
365 wxToolBarBase::SetWindowStyleFlag(style);
8ad31f9d 366
e76c0b5f
VZ
367 if ( m_toolbar )
368 GtkSetStyle();
369}
370
8a0681f9 371bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 372{
8c4e2405 373 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
248bcf0a 374
8a0681f9
VZ
375 if ( tool->IsButton() )
376 {
2b5f62a0
VZ
377 if ( !HasFlag(wxTB_NOICONS) )
378 {
379 wxBitmap bitmap = tool->GetNormalBitmap();
c801d85f 380
91af0895 381 wxCHECK_MSG( bitmap.Ok(), false,
2b5f62a0 382 wxT("invalid bitmap for wxToolBar icon") );
a3622daa 383
eba91e51
PC
384 tool->m_image = gtk_image_new();
385 tool->SetImage(bitmap);
248bcf0a 386
eba91e51 387 gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
2b5f62a0 388 }
8a0681f9 389 }
c801d85f 390
8c4e2405
PC
391 const int posGtk = int(pos);
392
8a0681f9
VZ
393 switch ( tool->GetStyle() )
394 {
395 case wxTOOL_STYLE_BUTTON:
38762f09
VZ
396 // for a radio button we need the widget which starts the radio
397 // group it belongs to, i.e. the first radio button immediately
398 // preceding this one
8a0681f9 399 {
38762f09
VZ
400 GtkWidget *widget = NULL;
401
402 if ( tool->IsRadio() )
403 {
98fc1d65
MB
404 wxToolBarToolsList::compatibility_iterator node
405 = wxToolBarToolsList::compatibility_iterator();
17a1ebd1
VZ
406 if ( pos )
407 node = m_tools.Item(pos - 1);
222ed1d6 408
38762f09
VZ
409 while ( node )
410 {
17a1ebd1
VZ
411 wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData();
412 if ( !toolNext->IsRadio() )
38762f09
VZ
413 break;
414
17a1ebd1 415 widget = toolNext->m_item;
38762f09
VZ
416
417 node = node->GetPrevious();
418 }
419
420 if ( !widget )
421 {
422 // this is the first button in the radio button group,
423 // it will be toggled automatically by GTK so bring the
424 // internal flag in sync
91af0895 425 tool->Toggle(true);
38762f09
VZ
426 }
427 }
428
429 tool->m_item = gtk_toolbar_insert_element
430 (
431 m_toolbar,
432 tool->GetGtkChildType(),
433 widget,
434 tool->GetLabel().empty()
435 ? NULL
fab591c5 436 : (const char*) wxGTK_CONV( tool->GetLabel() ),
38762f09
VZ
437 tool->GetShortHelp().empty()
438 ? NULL
fab591c5 439 : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
38762f09 440 "", // tooltip_private_text (?)
eba91e51 441 tool->m_image,
38762f09
VZ
442 (GtkSignalFunc)gtk_toolbar_callback,
443 (gpointer)tool,
6a1359c0 444 posGtk
38762f09
VZ
445 );
446
eba91e51 447 wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
99e8cb50 448
9fa72bd2
MR
449 g_signal_connect (tool->m_item, "enter_notify_event",
450 G_CALLBACK (gtk_toolbar_tool_callback),
451 tool);
452 g_signal_connect (tool->m_item, "leave_notify_event",
453 G_CALLBACK (gtk_toolbar_tool_callback),
454 tool);
8a0681f9 455 }
8a0681f9
VZ
456 break;
457
458 case wxTOOL_STYLE_SEPARATOR:
6a1359c0 459 gtk_toolbar_insert_space( m_toolbar, posGtk );
8a0681f9
VZ
460
461 // skip the rest
91af0895 462 return true;
bf9e3e73 463
8a0681f9
VZ
464 case wxTOOL_STYLE_CONTROL:
465 gtk_toolbar_insert_widget(
466 m_toolbar,
467 tool->GetControl()->m_widget,
468 (const char *) NULL,
469 (const char *) NULL,
6a1359c0 470 posGtk
8a0681f9 471 );
f4322df6 472
86b65467
RR
473 // connect after in order to correct size_allocate events
474 g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate",
475 G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl());
f4322df6 476
8a0681f9
VZ
477 break;
478 }
bf9e3e73 479
bf9e3e73 480 GtkRequisition req;
2afa14f2
OK
481 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
482 (m_widget, &req );
00655497 483 m_width = req.width + m_xMargin;
6f67eafe 484 m_height = req.height + 2*m_yMargin;
9f884528 485 InvalidateBestSize();
bf9e3e73 486
91af0895 487 return true;
bf9e3e73
RR
488}
489
4a64a89c 490bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 491{
8c4e2405 492 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
c801d85f 493
8a0681f9 494 switch ( tool->GetStyle() )
97d7bfb8 495 {
8a0681f9
VZ
496 case wxTOOL_STYLE_CONTROL:
497 tool->GetControl()->Destroy();
498 break;
97d7bfb8 499
8a0681f9
VZ
500 case wxTOOL_STYLE_BUTTON:
501 gtk_widget_destroy( tool->m_item );
502 break;
97d7bfb8 503
4a64a89c
RD
504 case wxTOOL_STYLE_SEPARATOR:
505 gtk_toolbar_remove_space( m_toolbar, pos );
506 break;
8a0681f9 507 }
c801d85f 508
9f884528 509 InvalidateBestSize();
91af0895 510 return true;
fc008f25 511}
46dc76ba 512
8a0681f9
VZ
513// ----------------------------------------------------------------------------
514// wxToolBar tools state
515// ----------------------------------------------------------------------------
516
517void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
c801d85f 518{
8c4e2405 519 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
8a0681f9 520
8a0681f9 521 if (tool->m_item)
fab591c5 522 {
8a0681f9 523 gtk_widget_set_sensitive( tool->m_item, enable );
fab591c5 524 }
fc008f25 525}
c801d85f 526
248bcf0a 527void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
c801d85f 528{
8c4e2405 529 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
8a0681f9
VZ
530
531 GtkWidget *item = tool->m_item;
532 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
1144d24d 533 {
eba91e51 534 tool->SetImage(tool->GetBitmap());
c801d85f 535
91af0895 536 m_blockEvent = true;
8a0681f9 537
e343da37 538 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
248bcf0a 539
91af0895 540 m_blockEvent = false;
1144d24d 541 }
fc008f25 542}
c801d85f 543
8a0681f9
VZ
544void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
545 bool WXUNUSED(toggle))
c801d85f 546{
8a0681f9
VZ
547 // VZ: absolutely no idea about how to do it
548 wxFAIL_MSG( _T("not implemented") );
fc008f25 549}
c801d85f 550
8a0681f9
VZ
551// ----------------------------------------------------------------------------
552// wxToolBar geometry
553// ----------------------------------------------------------------------------
554
555wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
556 wxCoord WXUNUSED(y)) const
c801d85f 557{
8a0681f9
VZ
558 // VZ: GTK+ doesn't seem to have such thing
559 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
560
561 return (wxToolBarToolBase *)NULL;
fc008f25 562}
c801d85f 563
1144d24d 564void wxToolBar::SetMargins( int x, int y )
c801d85f 565{
8a0681f9
VZ
566 wxCHECK_RET( GetToolsCount() == 0,
567 wxT("wxToolBar::SetMargins must be called before adding tools.") );
248bcf0a 568
1144d24d
RR
569 m_xMargin = x;
570 m_yMargin = y;
fc008f25 571}
c801d85f 572
cf4219e7 573void wxToolBar::SetToolSeparation( int separation )
c801d85f 574{
9e691f46 575 // FIXME: this function disappeared
68567a96 576#if 0
1144d24d 577 gtk_toolbar_set_space_size( m_toolbar, separation );
9e691f46
VZ
578#endif
579
8a0681f9 580 m_toolSeparation = separation;
1144d24d
RR
581}
582
a1f79c1e
VZ
583void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
584{
8c4e2405 585 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
a1f79c1e
VZ
586
587 if ( tool )
588 {
589 (void)tool->SetShortHelp(helpString);
590 gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
fab591c5 591 wxGTK_CONV( helpString ), "");
a1f79c1e
VZ
592 }
593}
594
bbd321ff
RD
595void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
596{
597 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
598 if ( tool )
599 {
600 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
601
602 tool->SetNormalBitmap(bitmap);
603 tool->SetImage(tool->GetBitmap());
f4322df6 604 }
bbd321ff
RD
605}
606
607void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
608{
609 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
610 if ( tool )
611 {
612 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
613
614 tool->SetDisabledBitmap(bitmap);
615 tool->SetImage(tool->GetBitmap());
f4322df6 616 }
bbd321ff
RD
617}
618
8a0681f9
VZ
619// ----------------------------------------------------------------------------
620// wxToolBar idle handling
621// ----------------------------------------------------------------------------
1144d24d 622
9b7e522a
RR
623void wxToolBar::OnInternalIdle()
624{
1417c811
RR
625 // Check if we have to show window now
626 if (GtkShowFromOnIdle()) return;
f4322df6 627
9b7e522a
RR
628 wxCursor cursor = m_cursor;
629 if (g_globalCursor.Ok()) cursor = g_globalCursor;
630
f7a11f8c 631 if (cursor.Ok())
9b7e522a 632 {
f7a11f8c 633 /* I now set the cursor the anew in every OnInternalIdle call
8a0681f9
VZ
634 as setting the cursor in a parent window also effects the
635 windows above so that checking for the current cursor is
636 not possible. */
85ec2f26
RR
637
638 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
9b7e522a 639 {
8a0681f9
VZ
640 /* if the toolbar is dockable, then m_widget stands for the
641 GtkHandleBox widget, which uses its own window so that we
642 can set the cursor for it. if the toolbar is not dockable,
643 m_widget comes from m_toolbar which uses its parent's
644 window ("windowless windows") and thus we cannot set the
645 cursor. */
646 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
647 }
648
222ed1d6 649 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
650 while ( node )
651 {
652 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
653 node = node->GetNext();
654
655 GtkWidget *item = tool->m_item;
656 if ( item )
657 {
658 GdkWindow *window = item->window;
659
660 if ( window )
661 {
662 gdk_window_set_cursor( window, cursor.GetCursor() );
663 }
664 }
9b7e522a
RR
665 }
666 }
667
e39af974
JS
668 if (wxUpdateUIEvent::CanUpdate(this))
669 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
9b7e522a
RR
670}
671
9d522606
RD
672
673// ----------------------------------------------------------------------------
674
675// static
676wxVisualAttributes
677wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
678{
9d522606 679 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
9d522606
RD
680}
681
a1f79c1e 682#endif // wxUSE_TOOLBAR_NATIVE