]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/tbargtk.cpp
Fixes to warnings about assigning unused values.
[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
8a0681f9
VZ
131 GtkWidget *m_item;
132 GtkWidget *m_pixmap;
133
134protected:
135 void Init();
136};
137
138// ----------------------------------------------------------------------------
139// wxWin macros
140// ----------------------------------------------------------------------------
141
2eb10e2a 142IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
8a0681f9
VZ
143
144// ============================================================================
145// implementation
146// ============================================================================
147
c801d85f 148//-----------------------------------------------------------------------------
2f2aa628 149// "clicked" (internal from gtk_toolbar)
c801d85f
KB
150//-----------------------------------------------------------------------------
151
8a0681f9
VZ
152static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
153 wxToolBarTool *tool )
c801d85f 154{
248bcf0a 155 if (g_isIdle)
59fe1666
RR
156 wxapp_install_idle_handler();
157
8a0681f9 158 wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
248bcf0a 159
9864c56d 160 if (tbar->m_blockEvent) return;
acfd422a 161
1144d24d 162 if (g_blockEventsOnDrag) return;
8a0681f9 163 if (!tool->IsEnabled()) return;
a3622daa 164
8a0681f9 165 if (tool->CanBeToggled())
248bcf0a 166 {
8a0681f9
VZ
167 tool->Toggle();
168
169 wxBitmap bitmap = tool->GetBitmap();
170 if ( bitmap.Ok() )
171 {
85eb36c2 172 GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
8a0681f9
VZ
173
174 GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
175 : (GdkBitmap *)NULL;
176
85eb36c2 177 gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
8a0681f9 178 }
38762f09
VZ
179
180 if ( tool->IsRadio() && !tool->IsToggled() )
181 {
182 // radio button went up, don't report this as a wxWin event
183 return;
184 }
85eb36c2 185 }
a3622daa 186
6bb7cee4
VZ
187 if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() )
188 {
189 // revert back
190 tool->Toggle();
191
192 wxBitmap bitmap = tool->GetBitmap();
193 if ( bitmap.Ok() )
194 {
195 GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
196
197 GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
198 : (GdkBitmap *)NULL;
199
200 gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
201 }
202 }
fc008f25 203}
c801d85f 204
2f2aa628 205//-----------------------------------------------------------------------------
a8945eef 206// "enter_notify_event" / "leave_notify_event"
2f2aa628
RR
207//-----------------------------------------------------------------------------
208
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
RR
226}
227
bf9e3e73
RR
228//-----------------------------------------------------------------------------
229// InsertChild callback for wxToolBar
230//-----------------------------------------------------------------------------
231
8a0681f9
VZ
232static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
233 wxWindow* WXUNUSED(child) )
bf9e3e73 234{
47c93b63 235 // we don't do anything here
bf9e3e73
RR
236}
237
8a0681f9
VZ
238// ----------------------------------------------------------------------------
239// wxToolBarTool
240// ----------------------------------------------------------------------------
c801d85f 241
8a0681f9
VZ
242void wxToolBarTool::Init()
243{
244 m_item =
245 m_pixmap = (GtkWidget *)NULL;
246}
c801d85f 247
8a0681f9 248wxToolBarToolBase *wxToolBar::CreateTool(int id,
e76c0b5f 249 const wxString& text,
8a0681f9
VZ
250 const wxBitmap& bitmap1,
251 const wxBitmap& bitmap2,
e76c0b5f 252 wxItemKind kind,
8a0681f9
VZ
253 wxObject *clientData,
254 const wxString& shortHelpString,
255 const wxString& longHelpString)
256{
e76c0b5f 257 return new wxToolBarTool(this, id, text, bitmap1, bitmap2, kind,
8a0681f9
VZ
258 clientData, shortHelpString, longHelpString);
259}
b1da76e1 260
8a0681f9 261wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
c801d85f 262{
8a0681f9 263 return new wxToolBarTool(this, control);
fc008f25 264}
c801d85f 265
8a0681f9
VZ
266//-----------------------------------------------------------------------------
267// wxToolBar construction
268//-----------------------------------------------------------------------------
269
270void wxToolBar::Init()
c801d85f 271{
8a0681f9 272 m_toolbar = (GtkToolbar *)NULL;
9864c56d 273 m_blockEvent = FALSE;
d2c0a964
RD
274 m_defaultWidth = 32;
275 m_defaultHeight = 32;
fc008f25 276}
c801d85f 277
a3622daa 278wxToolBar::~wxToolBar()
c801d85f 279{
fc008f25 280}
c801d85f 281
8a0681f9
VZ
282bool wxToolBar::Create( wxWindow *parent,
283 wxWindowID id,
284 const wxPoint& pos,
285 const wxSize& size,
286 long style,
287 const wxString& name )
c801d85f 288{
1144d24d 289 m_needParent = TRUE;
bf9e3e73 290 m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
a3622daa 291
8a0681f9
VZ
292 if ( !PreCreation( parent, pos, size ) ||
293 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
4dcaf11a 294 {
223d09f6 295 wxFAIL_MSG( wxT("wxToolBar creation failed") );
c801d85f 296
8a0681f9
VZ
297 return FALSE;
298 }
a3622daa 299
9e691f46
VZ
300#ifdef __WXGTK20__
301 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
e76c0b5f 302 GtkSetStyle();
99e8cb50 303
2b5f62a0
VZ
304 // Doesn't work this way.
305 // GtkToolbarSpaceStyle space_style = GTK_TOOLBAR_SPACE_EMPTY;
306 // gtk_widget_style_set (GTK_WIDGET (m_toolbar), "space_style", &space_style, NULL);
9e691f46 307#else
e76c0b5f
VZ
308 GtkOrientation orient;
309 GtkToolbarStyle gtkStyle;
310 GetGtkStyle(style, &orient, &gtkStyle);
311
312 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new(orient, gtkStyle) );
9e691f46 313#endif
a3622daa 314
8a0681f9 315 SetToolSeparation(7);
3502e687
RR
316
317 if (style & wxTB_DOCKABLE)
318 {
319 m_widget = gtk_handle_box_new();
f03fc89f
VZ
320 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
321 gtk_widget_show( GTK_WIDGET(m_toolbar) );
8a0681f9 322
f03fc89f 323 if (style & wxTB_FLAT)
858b5bdd 324 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
3502e687
RR
325 }
326 else
248bcf0a
RD
327 {
328 m_widget = gtk_event_box_new();
329 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
330 ConnectWidget( m_widget );
331 gtk_widget_show(GTK_WIDGET(m_toolbar));
3502e687 332 }
8a0681f9 333
1144d24d 334 gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
8a0681f9 335
9e691f46
VZ
336 // FIXME: there is no such function for toolbars in 2.0
337#ifndef __WXGTK20__
858b5bdd
RR
338 if (style & wxTB_FLAT)
339 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
9e691f46 340#endif
be25e480 341
f03fc89f 342 m_parent->DoAddChild( this );
8a0681f9 343
abdeb9e7 344 PostCreation(size);
a3622daa 345
1144d24d 346 return TRUE;
fc008f25 347}
c801d85f 348
e76c0b5f
VZ
349void wxToolBar::GtkSetStyle()
350{
351 GtkOrientation orient;
352 GtkToolbarStyle style;
353 GetGtkStyle(GetWindowStyle(), &orient, &style);
354
355 gtk_toolbar_set_orientation(m_toolbar, orient);
356 gtk_toolbar_set_style(m_toolbar, style);
357}
358
359void wxToolBar::SetWindowStyleFlag( long style )
360{
361 wxToolBarBase::SetWindowStyleFlag(style);
362
363 if ( m_toolbar )
364 GtkSetStyle();
365}
366
8a0681f9 367bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
c801d85f 368{
8a0681f9 369 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
c801d85f 370
2b5f62a0 371#ifndef __WXGTK20__
6a1359c0
VZ
372 // if we have inserted a space before all the tools we must change the GTK
373 // index by 1
374 size_t posGtk = m_xMargin > 1 ? pos + 1 : pos;
2b5f62a0
VZ
375#else
376 size_t posGtk = pos;
377#endif
248bcf0a 378
8a0681f9
VZ
379 if ( tool->IsButton() )
380 {
2b5f62a0
VZ
381 if ( !HasFlag(wxTB_NOICONS) )
382 {
383 wxBitmap bitmap = tool->GetNormalBitmap();
c801d85f 384
2b5f62a0
VZ
385 wxCHECK_MSG( bitmap.Ok(), FALSE,
386 wxT("invalid bitmap for wxToolBar icon") );
a3622daa 387
2b5f62a0
VZ
388 wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
389 wxT("wxToolBar doesn't support GdkBitmap") );
03f38c58 390
2b5f62a0
VZ
391 wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE,
392 wxT("wxToolBar::Add needs a wxBitmap") );
248bcf0a 393
2b5f62a0 394 GtkWidget *tool_pixmap = (GtkWidget *)NULL;
248bcf0a 395
2b5f62a0 396 GdkPixmap *pixmap = bitmap.GetPixmap();
a3622daa 397
2b5f62a0
VZ
398 GdkBitmap *mask = (GdkBitmap *)NULL;
399 if ( bitmap.GetMask() )
400 mask = bitmap.GetMask()->GetBitmap();
248bcf0a 401
2b5f62a0
VZ
402 tool_pixmap = gtk_pixmap_new( pixmap, mask );
403 gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
248bcf0a 404
2b5f62a0 405 gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
a3622daa 406
2b5f62a0
VZ
407 tool->m_pixmap = tool_pixmap;
408 }
8a0681f9 409 }
c801d85f 410
8a0681f9
VZ
411 switch ( tool->GetStyle() )
412 {
413 case wxTOOL_STYLE_BUTTON:
38762f09
VZ
414 // for a radio button we need the widget which starts the radio
415 // group it belongs to, i.e. the first radio button immediately
416 // preceding this one
8a0681f9 417 {
38762f09
VZ
418 GtkWidget *widget = NULL;
419
420 if ( tool->IsRadio() )
421 {
98fc1d65
MB
422 wxToolBarToolsList::compatibility_iterator node
423 = wxToolBarToolsList::compatibility_iterator();
222ed1d6
MB
424 if ( pos ) node = m_tools.Item(pos - 1);
425
38762f09
VZ
426 while ( node )
427 {
428 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
429 if ( !tool->IsRadio() )
430 break;
431
432 widget = tool->m_item;
433
434 node = node->GetPrevious();
435 }
436
437 if ( !widget )
438 {
439 // this is the first button in the radio button group,
440 // it will be toggled automatically by GTK so bring the
441 // internal flag in sync
442 tool->Toggle(TRUE);
443 }
444 }
445
446 tool->m_item = gtk_toolbar_insert_element
447 (
448 m_toolbar,
449 tool->GetGtkChildType(),
450 widget,
451 tool->GetLabel().empty()
452 ? NULL
fab591c5 453 : (const char*) wxGTK_CONV( tool->GetLabel() ),
38762f09
VZ
454 tool->GetShortHelp().empty()
455 ? NULL
fab591c5 456 : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
38762f09
VZ
457 "", // tooltip_private_text (?)
458 tool->m_pixmap,
459 (GtkSignalFunc)gtk_toolbar_callback,
460 (gpointer)tool,
6a1359c0 461 posGtk
38762f09
VZ
462 );
463
464 if ( !tool->m_item )
465 {
466 wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
467
468 return FALSE;
469 }
99e8cb50 470
38762f09 471 gtk_signal_connect( GTK_OBJECT(tool->m_item),
248bcf0a 472 "enter_notify_event",
38762f09
VZ
473 GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
474 (gpointer)tool );
475 gtk_signal_connect( GTK_OBJECT(tool->m_item),
248bcf0a 476 "leave_notify_event",
38762f09
VZ
477 GTK_SIGNAL_FUNC(gtk_toolbar_tool_callback),
478 (gpointer)tool );
8a0681f9 479 }
8a0681f9
VZ
480 break;
481
482 case wxTOOL_STYLE_SEPARATOR:
6a1359c0 483 gtk_toolbar_insert_space( m_toolbar, posGtk );
8a0681f9
VZ
484
485 // skip the rest
486 return TRUE;
bf9e3e73 487
8a0681f9
VZ
488 case wxTOOL_STYLE_CONTROL:
489 gtk_toolbar_insert_widget(
490 m_toolbar,
491 tool->GetControl()->m_widget,
492 (const char *) NULL,
493 (const char *) NULL,
6a1359c0 494 posGtk
8a0681f9
VZ
495 );
496 break;
497 }
bf9e3e73 498
bf9e3e73 499 GtkRequisition req;
2afa14f2
OK
500 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
501 (m_widget, &req );
00655497 502 m_width = req.width + m_xMargin;
6f67eafe 503 m_height = req.height + 2*m_yMargin;
9f884528 504 InvalidateBestSize();
bf9e3e73 505
bf9e3e73
RR
506 return TRUE;
507}
508
9c2882d9 509bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
c801d85f 510{
8a0681f9 511 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
c801d85f 512
8a0681f9 513 switch ( tool->GetStyle() )
97d7bfb8 514 {
8a0681f9
VZ
515 case wxTOOL_STYLE_CONTROL:
516 tool->GetControl()->Destroy();
517 break;
97d7bfb8 518
8a0681f9
VZ
519 case wxTOOL_STYLE_BUTTON:
520 gtk_widget_destroy( tool->m_item );
521 break;
97d7bfb8 522
8a0681f9
VZ
523 //case wxTOOL_STYLE_SEPARATOR: -- nothing to do
524 }
c801d85f 525
9f884528 526 InvalidateBestSize();
1144d24d 527 return TRUE;
fc008f25 528}
46dc76ba 529
8a0681f9
VZ
530// ----------------------------------------------------------------------------
531// wxToolBar tools state
532// ----------------------------------------------------------------------------
533
534void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
c801d85f 535{
8a0681f9
VZ
536 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
537
8a0681f9 538 if (tool->m_item)
fab591c5 539 {
8a0681f9 540 gtk_widget_set_sensitive( tool->m_item, enable );
fab591c5 541 }
fc008f25 542}
c801d85f 543
248bcf0a 544void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
c801d85f 545{
8a0681f9
VZ
546 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
547
548 GtkWidget *item = tool->m_item;
549 if ( item && GTK_IS_TOGGLE_BUTTON(item) )
1144d24d 550 {
8a0681f9
VZ
551 wxBitmap bitmap = tool->GetBitmap();
552 if ( bitmap.Ok() )
553 {
554 GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
555
556 GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
557 : (GdkBitmap *)NULL;
558
559 gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
1144d24d 560 }
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