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