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