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