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