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