]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/tbargtk.cpp
added virtual wxFrame::FindItemInMenuBar(): overriding it in wxMDIParentFrame allows...
[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
729b4756
RR
190//-----------------------------------------------------------------------------
191// "right-click"
192//-----------------------------------------------------------------------------
193extern "C" {
194static gboolean gtk_toolbar_tool_rclick_callback(GtkWidget *WXUNUSED(widget),
195 GdkEventButton *event,
196 wxToolBarToolBase *tool)
197{
198 if (event->button != 3)
199 return FALSE;
200
201 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
202
203 if (tbar->m_blockEvent) return TRUE;
204
205 if (g_blockEventsOnDrag) return TRUE;
206 if (!tool->IsEnabled()) return TRUE;
207
208 tbar->OnRightClick( tool->GetId(), (int)event->x, (int)event->y );
209
210 return TRUE;
211}
212}
213
2f2aa628 214//-----------------------------------------------------------------------------
a8945eef 215// "enter_notify_event" / "leave_notify_event"
2f2aa628
RR
216//-----------------------------------------------------------------------------
217
865bb325 218extern "C" {
248bcf0a 219static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
a8945eef
MB
220 GdkEventCrossing *gdk_event,
221 wxToolBarTool *tool )
314055fa 222{
1144d24d 223 if (g_blockEventsOnDrag) return TRUE;
248bcf0a 224
8a0681f9 225 wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
248bcf0a 226
47c93b63 227 // emit the event
a8945eef
MB
228 if( gdk_event->type == GDK_ENTER_NOTIFY )
229 tb->OnMouseEnter( tool->GetId() );
230 else
231 tb->OnMouseEnter( -1 );
248bcf0a 232
1144d24d 233 return FALSE;
314055fa 234}
865bb325 235}
314055fa 236
86b65467
RR
237extern "C" {
238static
239void gtktoolwidget_size_callback( GtkWidget *widget,
240 GtkAllocation *alloc,
241 wxWindow *win )
242{
243 // this shouldn't happen...
244 if (win->GetParent()->m_wxwindow) return;
f4322df6 245
86b65467
RR
246 wxSize size = win->GetEffectiveMinSize();
247 if (size.y != alloc->height)
248 {
249 GtkAllocation alloc2;
250 alloc2.x = alloc->x;
251 alloc2.y = (alloc->height - size.y + 3) / 2;
252 alloc2.width = alloc->width;
253 alloc2.height = size.y;
254 gtk_widget_size_allocate( widget, &alloc2 );
255 }
256}
257}
bf9e3e73
RR
258//-----------------------------------------------------------------------------
259// InsertChild callback for wxToolBar
260//-----------------------------------------------------------------------------
261
8a0681f9
VZ
262static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
263 wxWindow* WXUNUSED(child) )
bf9e3e73 264{
47c93b63 265 // we don't do anything here
bf9e3e73
RR
266}
267
8a0681f9
VZ
268// ----------------------------------------------------------------------------
269// wxToolBarTool
270// ----------------------------------------------------------------------------
c801d85f 271
8a0681f9
VZ
272void wxToolBarTool::Init()
273{
274 m_item =
eba91e51 275 m_image = NULL;
8a0681f9 276}
c801d85f 277
8a0681f9 278wxToolBarToolBase *wxToolBar::CreateTool(int id,
e76c0b5f 279 const wxString& text,
8a0681f9
VZ
280 const wxBitmap& bitmap1,
281 const wxBitmap& bitmap2,
e76c0b5f 282 wxItemKind kind,
8a0681f9
VZ
283 wxObject *clientData,
284 const wxString& shortHelpString,
285 const wxString& longHelpString)
286{
e76c0b5f 287 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
8a0681f9
VZ
288 clientData, shortHelpString, longHelpString);
289}
b1da76e1 290
07d02e9e
VZ
291wxToolBarToolBase *
292wxToolBar::CreateTool(wxControl *control, const wxString& label)
c801d85f 293{
07d02e9e 294 return new wxToolBarTool(this, control, label);
fc008f25 295}
c801d85f 296
8a0681f9
VZ
297//-----------------------------------------------------------------------------
298// wxToolBar construction
299//-----------------------------------------------------------------------------
300
301void wxToolBar::Init()
c801d85f 302{
8a0681f9 303 m_toolbar = (GtkToolbar *)NULL;
91af0895 304 m_blockEvent = false;
d2c0a964
RD
305 m_defaultWidth = 32;
306 m_defaultHeight = 32;
fc008f25 307}
c801d85f 308
a3622daa 309wxToolBar::~wxToolBar()
c801d85f 310{
fc008f25 311}
c801d85f 312
8a0681f9
VZ
313bool wxToolBar::Create( wxWindow *parent,
314 wxWindowID id,
315 const wxPoint& pos,
316 const wxSize& size,
317 long style,
318 const wxString& name )
c801d85f 319{
bf9e3e73 320 m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
a3622daa 321
8a0681f9
VZ
322 if ( !PreCreation( parent, pos, size ) ||
323 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
4dcaf11a 324 {
223d09f6 325 wxFAIL_MSG( wxT("wxToolBar creation failed") );
c801d85f 326
91af0895 327 return false;
8a0681f9 328 }
a3622daa 329
d408730c
VZ
330 FixupStyle();
331
9e691f46 332 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
e76c0b5f 333 GtkSetStyle();
99e8cb50 334
2b5f62a0
VZ
335 // Doesn't work this way.
336 // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
337 // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
a3622daa 338
8a0681f9 339 SetToolSeparation(7);
3502e687
RR
340
341 if (style & wxTB_DOCKABLE)
342 {
343 m_widget = gtk_handle_box_new();
f03fc89f
VZ
344 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
345 gtk_widget_show( GTK_WIDGET(m_toolbar) );
8a0681f9 346
f03fc89f 347 if (style & wxTB_FLAT)
858b5bdd 348 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
3502e687
RR
349 }
350 else
248bcf0a
RD
351 {
352 m_widget = gtk_event_box_new();
353 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
354 ConnectWidget( m_widget );
355 gtk_widget_show(GTK_WIDGET(m_toolbar));
3502e687 356 }
8a0681f9 357
9e691f46 358 // FIXME: there is no such function for toolbars in 2.0
68567a96 359#if 0
858b5bdd
RR
360 if (style & wxTB_FLAT)
361 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
9e691f46 362#endif
be25e480 363
f03fc89f 364 m_parent->DoAddChild( this );
8a0681f9 365
abdeb9e7 366 PostCreation(size);
a3622daa 367
91af0895 368 return true;
fc008f25 369}
c801d85f 370
48468900
RR
371GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const
372{
373 return GTK_WIDGET(m_toolbar)->window;
374}
375
e76c0b5f
VZ
376void wxToolBar::GtkSetStyle()
377{
378 GtkOrientation orient;
379 GtkToolbarStyle style;
380 GetGtkStyle(GetWindowStyle(), &orient, &style);
381
382 gtk_toolbar_set_orientation(m_toolbar, orient);
383 gtk_toolbar_set_style(m_toolbar, style);
8c4e2405 384 gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
e76c0b5f
VZ
385}
386
387void wxToolBar::SetWindowStyleFlag( long style )
388{
389 wxToolBarBase::SetWindowStyleFlag(style);
8ad31f9d 390
e76c0b5f
VZ
391 if ( m_toolbar )
392 GtkSetStyle();
393}
394
8a0681f9 395bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 396{
8c4e2405 397 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
248bcf0a 398
8a0681f9
VZ
399 if ( tool->IsButton() )
400 {
2b5f62a0
VZ
401 if ( !HasFlag(wxTB_NOICONS) )
402 {
403 wxBitmap bitmap = tool->GetNormalBitmap();
c801d85f 404
91af0895 405 wxCHECK_MSG( bitmap.Ok(), false,
2b5f62a0 406 wxT("invalid bitmap for wxToolBar icon") );
a3622daa 407
eba91e51
PC
408 tool->m_image = gtk_image_new();
409 tool->SetImage(bitmap);
248bcf0a 410
eba91e51 411 gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
2b5f62a0 412 }
8a0681f9 413 }
c801d85f 414
8c4e2405
PC
415 const int posGtk = int(pos);
416
8a0681f9
VZ
417 switch ( tool->GetStyle() )
418 {
419 case wxTOOL_STYLE_BUTTON:
38762f09
VZ
420 // for a radio button we need the widget which starts the radio
421 // group it belongs to, i.e. the first radio button immediately
422 // preceding this one
8a0681f9 423 {
38762f09
VZ
424 GtkWidget *widget = NULL;
425
426 if ( tool->IsRadio() )
427 {
98fc1d65
MB
428 wxToolBarToolsList::compatibility_iterator node
429 = wxToolBarToolsList::compatibility_iterator();
17a1ebd1
VZ
430 if ( pos )
431 node = m_tools.Item(pos - 1);
222ed1d6 432
38762f09
VZ
433 while ( node )
434 {
17a1ebd1
VZ
435 wxToolBarTool *toolNext = (wxToolBarTool *)node->GetData();
436 if ( !toolNext->IsRadio() )
38762f09
VZ
437 break;
438
17a1ebd1 439 widget = toolNext->m_item;
38762f09
VZ
440
441 node = node->GetPrevious();
442 }
443
444 if ( !widget )
445 {
446 // this is the first button in the radio button group,
447 // it will be toggled automatically by GTK so bring the
448 // internal flag in sync
91af0895 449 tool->Toggle(true);
38762f09
VZ
450 }
451 }
452
453 tool->m_item = gtk_toolbar_insert_element
454 (
455 m_toolbar,
456 tool->GetGtkChildType(),
457 widget,
458 tool->GetLabel().empty()
459 ? NULL
fab591c5 460 : (const char*) wxGTK_CONV( tool->GetLabel() ),
38762f09
VZ
461 tool->GetShortHelp().empty()
462 ? NULL
fab591c5 463 : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
38762f09 464 "", // tooltip_private_text (?)
eba91e51 465 tool->m_image,
38762f09
VZ
466 (GtkSignalFunc)gtk_toolbar_callback,
467 (gpointer)tool,
6a1359c0 468 posGtk
38762f09
VZ
469 );
470
eba91e51 471 wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
99e8cb50 472
9fa72bd2
MR
473 g_signal_connect (tool->m_item, "enter_notify_event",
474 G_CALLBACK (gtk_toolbar_tool_callback),
475 tool);
476 g_signal_connect (tool->m_item, "leave_notify_event",
477 G_CALLBACK (gtk_toolbar_tool_callback),
478 tool);
729b4756
RR
479 g_signal_connect(tool->m_item, "button-press-event",
480 G_CALLBACK (gtk_toolbar_tool_rclick_callback),
481 tool);
8a0681f9 482 }
8a0681f9
VZ
483 break;
484
485 case wxTOOL_STYLE_SEPARATOR:
6a1359c0 486 gtk_toolbar_insert_space( m_toolbar, posGtk );
8a0681f9
VZ
487
488 // skip the rest
91af0895 489 return true;
bf9e3e73 490
8a0681f9
VZ
491 case wxTOOL_STYLE_CONTROL:
492 gtk_toolbar_insert_widget(
493 m_toolbar,
494 tool->GetControl()->m_widget,
495 (const char *) NULL,
496 (const char *) NULL,
6a1359c0 497 posGtk
8a0681f9 498 );
f4322df6 499
86b65467
RR
500 // connect after in order to correct size_allocate events
501 g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate",
502 G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl());
f4322df6 503
8a0681f9
VZ
504 break;
505 }
bf9e3e73 506
bf9e3e73 507 GtkRequisition req;
2afa14f2
OK
508 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
509 (m_widget, &req );
00655497 510 m_width = req.width + m_xMargin;
6f67eafe 511 m_height = req.height + 2*m_yMargin;
9f884528 512 InvalidateBestSize();
bf9e3e73 513
91af0895 514 return true;
bf9e3e73
RR
515}
516
4a64a89c 517bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 518{
8c4e2405 519 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
c801d85f 520
8a0681f9 521 switch ( tool->GetStyle() )
97d7bfb8 522 {
8a0681f9
VZ
523 case wxTOOL_STYLE_CONTROL:
524 tool->GetControl()->Destroy();
525 break;
97d7bfb8 526
8a0681f9
VZ
527 case wxTOOL_STYLE_BUTTON:
528 gtk_widget_destroy( tool->m_item );
529 break;
97d7bfb8 530
4a64a89c
RD
531 case wxTOOL_STYLE_SEPARATOR:
532 gtk_toolbar_remove_space( m_toolbar, pos );
533 break;
8a0681f9 534 }
c801d85f 535
9f884528 536 InvalidateBestSize();
91af0895 537 return true;
fc008f25 538}
46dc76ba 539
8a0681f9
VZ
540// ----------------------------------------------------------------------------
541// wxToolBar tools state
542// ----------------------------------------------------------------------------
543
544void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
c801d85f 545{
8c4e2405 546 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
8a0681f9 547
8a0681f9 548 if (tool->m_item)
fab591c5 549 {
8a0681f9 550 gtk_widget_set_sensitive( tool->m_item, enable );
fab591c5 551 }
fc008f25 552}
c801d85f 553
248bcf0a 554void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
c801d85f 555{
8c4e2405 556 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
8a0681f9
VZ
557
558 GtkWidget *item = tool->m_item;
559 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
1144d24d 560 {
eba91e51 561 tool->SetImage(tool->GetBitmap());
c801d85f 562
91af0895 563 m_blockEvent = true;
8a0681f9 564
e343da37 565 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(item), toggle );
248bcf0a 566
91af0895 567 m_blockEvent = false;
1144d24d 568 }
fc008f25 569}
c801d85f 570
8a0681f9
VZ
571void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
572 bool WXUNUSED(toggle))
c801d85f 573{
8a0681f9
VZ
574 // VZ: absolutely no idea about how to do it
575 wxFAIL_MSG( _T("not implemented") );
fc008f25 576}
c801d85f 577
8a0681f9
VZ
578// ----------------------------------------------------------------------------
579// wxToolBar geometry
580// ----------------------------------------------------------------------------
581
582wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
583 wxCoord WXUNUSED(y)) const
c801d85f 584{
8a0681f9
VZ
585 // VZ: GTK+ doesn't seem to have such thing
586 wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
587
588 return (wxToolBarToolBase *)NULL;
fc008f25 589}
c801d85f 590
1144d24d 591void wxToolBar::SetMargins( int x, int y )
c801d85f 592{
8a0681f9
VZ
593 wxCHECK_RET( GetToolsCount() == 0,
594 wxT("wxToolBar::SetMargins must be called before adding tools.") );
248bcf0a 595
1144d24d
RR
596 m_xMargin = x;
597 m_yMargin = y;
fc008f25 598}
c801d85f 599
cf4219e7 600void wxToolBar::SetToolSeparation( int separation )
c801d85f 601{
9e691f46 602 // FIXME: this function disappeared
68567a96 603#if 0
1144d24d 604 gtk_toolbar_set_space_size( m_toolbar, separation );
9e691f46
VZ
605#endif
606
8a0681f9 607 m_toolSeparation = separation;
1144d24d
RR
608}
609
a1f79c1e
VZ
610void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
611{
8c4e2405 612 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
a1f79c1e
VZ
613
614 if ( tool )
615 {
616 (void)tool->SetShortHelp(helpString);
617 gtk_tooltips_set_tip(m_toolbar->tooltips, tool->m_item,
fab591c5 618 wxGTK_CONV( helpString ), "");
a1f79c1e
VZ
619 }
620}
621
bbd321ff
RD
622void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
623{
624 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
625 if ( tool )
626 {
627 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
628
629 tool->SetNormalBitmap(bitmap);
630 tool->SetImage(tool->GetBitmap());
f4322df6 631 }
bbd321ff
RD
632}
633
634void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
635{
636 wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
637 if ( tool )
638 {
639 wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
640
641 tool->SetDisabledBitmap(bitmap);
642 tool->SetImage(tool->GetBitmap());
f4322df6 643 }
bbd321ff
RD
644}
645
8a0681f9
VZ
646// ----------------------------------------------------------------------------
647// wxToolBar idle handling
648// ----------------------------------------------------------------------------
1144d24d 649
9b7e522a
RR
650void wxToolBar::OnInternalIdle()
651{
1417c811
RR
652 // Check if we have to show window now
653 if (GtkShowFromOnIdle()) return;
f4322df6 654
9b7e522a
RR
655 wxCursor cursor = m_cursor;
656 if (g_globalCursor.Ok()) cursor = g_globalCursor;
657
f7a11f8c 658 if (cursor.Ok())
9b7e522a 659 {
f7a11f8c 660 /* I now set the cursor the anew in every OnInternalIdle call
8a0681f9
VZ
661 as setting the cursor in a parent window also effects the
662 windows above so that checking for the current cursor is
663 not possible. */
85ec2f26
RR
664
665 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
9b7e522a 666 {
8a0681f9
VZ
667 /* if the toolbar is dockable, then m_widget stands for the
668 GtkHandleBox widget, which uses its own window so that we
669 can set the cursor for it. if the toolbar is not dockable,
670 m_widget comes from m_toolbar which uses its parent's
671 window ("windowless windows") and thus we cannot set the
672 cursor. */
673 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
674 }
675
222ed1d6 676 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
677 while ( node )
678 {
679 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
680 node = node->GetNext();
681
682 GtkWidget *item = tool->m_item;
683 if ( item )
684 {
685 GdkWindow *window = item->window;
686
687 if ( window )
688 {
689 gdk_window_set_cursor( window, cursor.GetCursor() );
690 }
691 }
9b7e522a
RR
692 }
693 }
694
e39af974
JS
695 if (wxUpdateUIEvent::CanUpdate(this))
696 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
9b7e522a
RR
697}
698
9d522606
RD
699
700// ----------------------------------------------------------------------------
701
702// static
703wxVisualAttributes
704wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
705{
9d522606 706 return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
9d522606
RD
707}
708
a1f79c1e 709#endif // wxUSE_TOOLBAR_NATIVE