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