]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/tbargtk.cpp
added default ctor for wxDirDialog
[wxWidgets.git] / src / gtk1 / tbargtk.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: tbargtk.cpp
3// Purpose: GTK toolbar
4// Author: Robert Roebling
32e9da8b 5// RCS-ID: $Id$
c801d85f 6// Copyright: (c) Robert Roebling
a3622daa 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "tbargtk.h"
12#endif
13
14#include "wx/toolbar.h"
dcf924a3
RR
15
16#if wxUSE_TOOLBAR
17
e702ff0f 18#include "wx/frame.h"
c801d85f 19
83624f79
RR
20#include "glib.h"
21#include "gdk/gdk.h"
22#include "gtk/gtk.h"
23
acfd422a
RR
24//-----------------------------------------------------------------------------
25// idle system
26//-----------------------------------------------------------------------------
27
28extern void wxapp_install_idle_handler();
29extern bool g_isIdle;
30
314055fa
RR
31//-----------------------------------------------------------------------------
32// data
33//-----------------------------------------------------------------------------
34
9b7e522a
RR
35extern bool g_blockEventsOnDrag;
36extern wxCursor g_globalCursor;
314055fa 37
c801d85f 38//-----------------------------------------------------------------------------
2f2aa628 39// "clicked" (internal from gtk_toolbar)
c801d85f
KB
40//-----------------------------------------------------------------------------
41
42static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
43{
59fe1666
RR
44 if (g_isIdle)
45 wxapp_install_idle_handler();
46
47 if (tool->m_owner->m_blockNextEvent)
48 {
49 tool->m_owner->m_blockNextEvent = FALSE;
50 return;
51 }
acfd422a 52
1144d24d
RR
53 if (g_blockEventsOnDrag) return;
54 if (!tool->m_enabled) return;
a3622daa 55
85eb36c2
RR
56 if (tool->m_isToggle)
57 {
58 tool->m_toggleState = !tool->m_toggleState;
59
60 if (tool->m_bitmap2.Ok())
61 {
62 wxBitmap bitmap = tool->m_bitmap1;
63 if (tool->m_toggleState) bitmap = tool->m_bitmap2;
64
65 GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
66
67 GdkBitmap *mask = (GdkBitmap *) NULL;
68 if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
69
70 gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
71 }
72 }
a3622daa 73
1144d24d 74 tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
fc008f25 75}
c801d85f 76
2f2aa628
RR
77//-----------------------------------------------------------------------------
78// "enter_notify_event"
79//-----------------------------------------------------------------------------
80
314055fa
RR
81static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
82 GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool )
83{
acfd422a
RR
84 if (g_isIdle) wxapp_install_idle_handler();
85
1144d24d 86 if (g_blockEventsOnDrag) return TRUE;
b98d804b 87
b98d804b
RR
88
89 wxToolBar *tb = tool->m_owner;
90
c693edf3
RR
91#if (GTK_MINOR_VERSION == 0)
92 /* we grey-out the tip text of disabled tool in GTK 1.0 */
b98d804b
RR
93 if (tool->m_enabled)
94 {
95 if (tb->m_fg->red != 0)
f03fc89f 96 {
b98d804b
RR
97 tb->m_fg->red = 0;
98 tb->m_fg->green = 0;
99 tb->m_fg->blue = 0;
100 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg );
f03fc89f 101
b98d804b 102 gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg );
f03fc89f 103 }
b98d804b
RR
104 }
105 else
106 {
107 if (tb->m_fg->red == 0)
f03fc89f 108 {
b98d804b
RR
109 tb->m_fg->red = 33000;
110 tb->m_fg->green = 33000;
111 tb->m_fg->blue = 33000;
112 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg );
113 gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg );
f03fc89f 114 }
b98d804b 115 }
f7ac40d1 116#endif
b98d804b
RR
117
118 /* emit the event */
314055fa 119
b98d804b 120 tb->OnMouseEnter( tool->m_index );
314055fa 121
1144d24d 122 return FALSE;
314055fa
RR
123}
124
bf9e3e73
RR
125//-----------------------------------------------------------------------------
126// InsertChild callback for wxToolBar
127//-----------------------------------------------------------------------------
128
129static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) )
130{
131 /* we don't do anything here but pray */
132}
133
2f2aa628
RR
134//-----------------------------------------------------------------------------
135// wxToolBar
c801d85f
KB
136//-----------------------------------------------------------------------------
137
716b7364 138IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
c801d85f 139
b1da76e1
RR
140BEGIN_EVENT_TABLE(wxToolBar, wxControl)
141 EVT_IDLE(wxToolBar::OnIdle)
142END_EVENT_TABLE()
143
a3622daa 144wxToolBar::wxToolBar()
c801d85f 145{
fc008f25 146}
c801d85f 147
a3622daa 148wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
c801d85f 149 const wxPoint& pos, const wxSize& size,
debe6624 150 long style, const wxString& name )
c801d85f 151{
1144d24d 152 Create( parent, id, pos, size, style, name );
fc008f25 153}
c801d85f 154
a3622daa 155wxToolBar::~wxToolBar()
c801d85f 156{
83624f79
RR
157 delete m_fg;
158 delete m_bg;
fc008f25 159}
c801d85f 160
a3622daa 161bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
c801d85f 162 const wxPoint& pos, const wxSize& size,
debe6624 163 long style, const wxString& name )
c801d85f 164{
1144d24d 165 m_needParent = TRUE;
59fe1666 166 m_blockNextEvent = FALSE;
bf9e3e73 167 m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
a3622daa 168
4dcaf11a
RR
169 if (!PreCreation( parent, pos, size ) ||
170 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
171 {
223d09f6 172 wxFAIL_MSG( wxT("wxToolBar creation failed") );
4dcaf11a
RR
173 return FALSE;
174 }
c801d85f 175
1144d24d 176 m_tools.DeleteContents( TRUE );
a3622daa 177
1144d24d
RR
178 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL,
179 GTK_TOOLBAR_ICONS ) );
a3622daa 180
00655497 181 m_separation = 7;
1144d24d
RR
182 gtk_toolbar_set_space_size( m_toolbar, m_separation );
183 m_hasToolAlready = FALSE;
3502e687
RR
184
185 if (style & wxTB_DOCKABLE)
186 {
187 m_widget = gtk_handle_box_new();
f03fc89f
VZ
188 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
189 gtk_widget_show( GTK_WIDGET(m_toolbar) );
190
b0795d45 191#if (GTK_MINOR_VERSION > 0)
f03fc89f 192 if (style & wxTB_FLAT)
858b5bdd 193 gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
b0795d45 194#endif
3502e687
RR
195 }
196 else
197 {
198 m_widget = GTK_WIDGET(m_toolbar);
199 }
f03fc89f 200
1144d24d 201 gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
858b5bdd
RR
202
203#if (GTK_MINOR_VERSION > 0)
204 if (style & wxTB_FLAT)
205 gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
206#endif
83624f79
RR
207
208 m_fg = new GdkColor;
209 m_fg->red = 0;
210 m_fg->green = 0;
211 m_fg->blue = 0;
212 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
b46e8696 213
83624f79
RR
214 m_bg = new GdkColor;
215 m_bg->red = 65535;
216 m_bg->green = 65535;
217 m_bg->blue = 50000;
218 gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
b46e8696 219
fac4253c
RR
220#if (GTK_MINOR_VERSION > 0)
221 gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
222
223 GtkStyle *g_style =
224 gtk_style_copy(
225 gtk_widget_get_style(
226 GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
f03fc89f 227
fac4253c
RR
228 g_style->bg[GTK_STATE_NORMAL] = *m_bg;
229 gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
230#else
83624f79 231 gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
fac4253c 232#endif
a3622daa 233
1144d24d
RR
234 m_xMargin = 0;
235 m_yMargin = 0;
236
f03fc89f 237 m_parent->DoAddChild( this );
6ca41e57 238
1144d24d 239 PostCreation();
a3622daa 240
1144d24d 241 Show( TRUE );
a3622daa 242
1144d24d 243 return TRUE;
fc008f25 244}
c801d85f 245
716b7364 246bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
c801d85f 247{
1144d24d
RR
248 wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
249 event.SetEventObject(this);
250 event.SetInt( toolIndex );
251 event.SetExtraLong((long) toggleDown);
c801d85f 252
1144d24d 253 GetEventHandler()->ProcessEvent(event);
c801d85f 254
1144d24d 255 return TRUE;
fc008f25 256}
c801d85f 257
716b7364 258void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
c801d85f 259{
1144d24d
RR
260 wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex );
261 event.SetEventObject( this );
262 event.SetInt( toolIndex );
c801d85f 263
1144d24d 264 GetEventHandler()->ProcessEvent(event);
fc008f25 265}
c801d85f 266
716b7364 267void wxToolBar::OnMouseEnter( int toolIndex )
c801d85f 268{
1144d24d
RR
269 wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() );
270 event.SetEventObject(this);
271 event.SetInt( toolIndex );
314055fa 272
1144d24d 273 GetEventHandler()->ProcessEvent(event);
fc008f25 274}
c801d85f 275
a3622daa 276wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
debe6624 277 const wxBitmap& pushedBitmap, bool toggle,
fd69e87d 278 wxCoord WXUNUSED(xPos), wxCoord WXUNUSED(yPos), wxObject *clientData,
c801d85f
KB
279 const wxString& helpString1, const wxString& helpString2 )
280{
1144d24d
RR
281 m_hasToolAlready = TRUE;
282
283 wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
223d09f6 284 wxT("invalid bitmap for wxToolBar icon") );
a3622daa 285
1144d24d 286 wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
223d09f6 287 wxT("wxToolBar doesn't support GdkBitmap") );
03f38c58 288
1144d24d 289 wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL,
223d09f6 290 wxT("wxToolBar::Add needs a wxBitmap") );
903f689b 291
1144d24d 292 GtkWidget *tool_pixmap = (GtkWidget *)NULL;
903f689b 293
903f689b 294 GdkPixmap *pixmap = bitmap.GetPixmap();
a3622daa 295
68dda785
VZ
296 GdkBitmap *mask = (GdkBitmap *)NULL;
297 if ( bitmap.GetMask() )
298 mask = bitmap.GetMask()->GetBitmap();
903f689b
RR
299
300 tool_pixmap = gtk_pixmap_new( pixmap, mask );
c693edf3 301#if (GTK_MINOR_VERSION > 0)
f7ac40d1 302 gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
c693edf3 303#endif
f7ac40d1 304
1144d24d 305 gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
a3622daa 306
2b1c162e
RR
307 wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
308 toggle, clientData,
309 helpString1, helpString2,
f03fc89f 310 tool_pixmap );
2b1c162e 311
1144d24d
RR
312 GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
313 : GTK_TOOLBAR_CHILD_BUTTON;
03f38c58 314
1144d24d 315 GtkWidget *item = gtk_toolbar_append_element
68dda785 316 (
bf9e3e73 317 m_toolbar,
68dda785
VZ
318 ctype,
319 (GtkWidget *)NULL,
320 (const char *)NULL,
05939a81 321 helpString1.mbc_str(),
68dda785
VZ
322 "",
323 tool_pixmap,
324 (GtkSignalFunc)gtk_toolbar_callback,
325 (gpointer)tool
326 );
327
1144d24d 328 tool->m_item = item;
03f38c58 329
3017f78d
RR
330 GtkRequisition req;
331 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
00655497
RR
332 m_width = req.width + m_xMargin;
333 m_height = req.height + 2*m_yMargin + 4;
3017f78d 334
1144d24d
RR
335 gtk_signal_connect( GTK_OBJECT(tool->m_item),
336 "enter_notify_event",
337 GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
338 (gpointer)tool );
314055fa 339
1144d24d 340 m_tools.Append( tool );
a3622daa 341
1144d24d 342 return tool;
fc008f25 343}
c801d85f 344
bf9e3e73
RR
345bool wxToolBar::AddControl(wxControl *control)
346{
347 wxCHECK_MSG( control, FALSE, wxT("toolbar: can't insert NULL control") );
348
349 wxCHECK_MSG( control->GetParent() == this, FALSE,
350 wxT("control must have toolbar as parent") );
351
352 m_hasToolAlready = TRUE;
353
354 wxToolBarTool *tool = new wxToolBarTool(control);
355
2b8f5a24 356 tool -> m_item = NULL;
bf9e3e73
RR
357 gtk_toolbar_append_widget( m_toolbar, control->m_widget, (const char *) NULL, (const char *) NULL );
358
359 GtkRequisition req;
360 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
00655497
RR
361 m_width = req.width + m_xMargin;
362 m_height = req.height + 2*m_yMargin + 4;
bf9e3e73
RR
363
364 m_tools.Append( tool );
365
366 return TRUE;
367}
368
03f38c58 369void wxToolBar::AddSeparator()
c801d85f 370{
1144d24d 371 gtk_toolbar_append_space( m_toolbar );
fc008f25 372}
c801d85f 373
97d7bfb8
RR
374bool wxToolBar::DeleteTool(int toolIndex)
375{
376 wxNode *node = m_tools.First();
377 while (node)
378 {
379 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
380 if (tool->m_index == toolIndex)
381 {
382 if (tool->m_control)
383 tool->m_control->Destroy();
384 else
385 gtk_widget_destroy( tool->m_item );
386 m_tools.DeleteNode( node );
387
388 return TRUE;
389 }
390 node = node->Next();
391 }
392
393 return FALSE;
394}
395
03f38c58 396void wxToolBar::ClearTools()
c801d85f 397{
223d09f6 398 wxFAIL_MSG( wxT("wxToolBar::ClearTools not implemented") );
fc008f25 399}
c801d85f 400
1144d24d 401bool wxToolBar::Realize()
46dc76ba 402{
1144d24d 403 return TRUE;
fc008f25 404}
46dc76ba 405
716b7364 406void wxToolBar::EnableTool(int toolIndex, bool enable)
c801d85f 407{
1144d24d
RR
408 wxNode *node = m_tools.First();
409 while (node)
410 {
411 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
412 if (tool->m_index == toolIndex)
2b1c162e 413 {
1144d24d 414 tool->m_enabled = enable;
f03fc89f 415
c693edf3
RR
416#if (GTK_MINOR_VERSION > 0)
417 /* we don't disable the tools for GTK 1.0 as the bitmaps don't get
418 greyed anyway and this also disables tooltips */
f03fc89f
VZ
419 if (tool->m_item)
420 gtk_widget_set_sensitive( tool->m_item, enable );
c693edf3 421#endif
f03fc89f 422
1144d24d
RR
423 return;
424 }
425 node = node->Next();
cf4219e7 426 }
fc008f25 427
223d09f6 428 wxFAIL_MSG( wxT("wrong toolbar index") );
fc008f25 429}
c801d85f 430
fc008f25 431void wxToolBar::ToggleTool( int toolIndex, bool toggle )
c801d85f 432{
1144d24d
RR
433 wxNode *node = m_tools.First();
434 while (node)
435 {
436 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
437 if (tool->m_index == toolIndex)
438 {
1144d24d 439 if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item)))
e179bd65
RR
440 {
441 tool->m_toggleState = toggle;
442
443 if (tool->m_bitmap2.Ok())
444 {
445 wxBitmap bitmap = tool->m_bitmap1;
446 if (tool->m_toggleState) bitmap = tool->m_bitmap2;
447
448 GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
449
450 GdkBitmap *mask = (GdkBitmap *) NULL;
451 if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
452
453 gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
454 }
455
59fe1666 456 m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
e179bd65 457
1144d24d 458 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle );
e179bd65
RR
459 }
460
1144d24d
RR
461 return;
462 }
463 node = node->Next();
fc008f25 464 }
fc008f25 465
223d09f6 466 wxFAIL_MSG( wxT("wrong toolbar index") );
fc008f25 467}
c801d85f 468
fc008f25 469wxObject *wxToolBar::GetToolClientData( int index ) const
c801d85f 470{
1144d24d
RR
471 wxNode *node = m_tools.First();
472 while (node)
473 {
474 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
475 if (tool->m_index == index) return tool->m_clientData;;
476 node = node->Next();
477 }
fc008f25 478
223d09f6 479 wxFAIL_MSG( wxT("wrong toolbar index") );
fc008f25 480
1144d24d 481 return (wxObject*)NULL;
fc008f25 482}
c801d85f 483
716b7364 484bool wxToolBar::GetToolState(int toolIndex) const
c801d85f 485{
1144d24d
RR
486 wxNode *node = m_tools.First();
487 while (node)
488 {
489 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
490 if (tool->m_index == toolIndex) return tool->m_toggleState;
491 node = node->Next();
492 }
fc008f25 493
223d09f6 494 wxFAIL_MSG( wxT("wrong toolbar index") );
fc008f25 495
1144d24d 496 return FALSE;
fc008f25 497}
c801d85f 498
716b7364 499bool wxToolBar::GetToolEnabled(int toolIndex) const
c801d85f 500{
1144d24d
RR
501 wxNode *node = m_tools.First();
502 while (node)
503 {
504 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
505 if (tool->m_index == toolIndex) return tool->m_enabled;
506 node = node->Next();
507 }
fc008f25 508
223d09f6 509 wxFAIL_MSG( wxT("wrong toolbar index") );
fc008f25 510
1144d24d 511 return FALSE;
fc008f25 512}
c801d85f 513
1144d24d 514void wxToolBar::SetMargins( int x, int y )
c801d85f 515{
223d09f6 516 wxCHECK_RET( !m_hasToolAlready, wxT("wxToolBar::SetMargins must be called before adding tool.") );
1144d24d 517
00655497 518 if (x > 1) gtk_toolbar_append_space( m_toolbar ); // oh well
1144d24d
RR
519
520 m_xMargin = x;
521 m_yMargin = y;
fc008f25 522}
c801d85f 523
cf4219e7 524void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
c801d85f 525{
223d09f6 526 wxFAIL_MSG( wxT("wxToolBar::SetToolPacking not implemented") );
fc008f25 527}
c801d85f 528
cf4219e7 529void wxToolBar::SetToolSeparation( int separation )
c801d85f 530{
1144d24d
RR
531 gtk_toolbar_set_space_size( m_toolbar, separation );
532 m_separation = separation;
533}
534
535int wxToolBar::GetToolPacking()
536{
537 return 0;
538}
539
540int wxToolBar::GetToolSeparation()
541{
542 return m_separation;
543}
544
545wxString wxToolBar::GetToolLongHelp(int toolIndex)
546{
547 wxNode *node = m_tools.First();
548 while (node)
549 {
550 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
551 if (tool->m_index == toolIndex)
552 {
553 return tool->m_longHelpString;
554 }
555 node = node->Next();
556 }
557
223d09f6 558 wxFAIL_MSG( wxT("wrong toolbar index") );
1144d24d 559
223d09f6 560 return wxT("");
1144d24d
RR
561}
562
563wxString wxToolBar::GetToolShortHelp(int toolIndex)
564{
565 wxNode *node = m_tools.First();
566 while (node)
567 {
568 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
569 if (tool->m_index == toolIndex)
570 {
571 return tool->m_shortHelpString;
572 }
573 node = node->Next();
574 }
575
223d09f6 576 wxFAIL_MSG( wxT("wrong toolbar index") );
1144d24d 577
223d09f6 578 return wxT("");
fc008f25 579}
c801d85f 580
1144d24d
RR
581void wxToolBar::SetToolLongHelp(int toolIndex, const wxString& helpString)
582{
583 wxNode *node = m_tools.First();
584 while (node)
585 {
586 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
587 if (tool->m_index == toolIndex)
588 {
589 tool->m_longHelpString = helpString;
f03fc89f 590 return;
1144d24d
RR
591 }
592 node = node->Next();
593 }
594
223d09f6 595 wxFAIL_MSG( wxT("wrong toolbar index") );
1144d24d
RR
596
597 return;
598}
599
600void wxToolBar::SetToolShortHelp(int toolIndex, const wxString& helpString)
601{
602 wxNode *node = m_tools.First();
603 while (node)
604 {
605 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
606 if (tool->m_index == toolIndex)
607 {
608 tool->m_shortHelpString = helpString;
f03fc89f 609 return;
1144d24d
RR
610 }
611 node = node->Next();
612 }
613
223d09f6 614 wxFAIL_MSG( wxT("wrong toolbar index") );
1144d24d
RR
615
616 return;
617}
618
b1da76e1
RR
619void wxToolBar::OnIdle( wxIdleEvent &WXUNUSED(ievent) )
620{
621 wxEvtHandler* evtHandler = GetEventHandler();
622
623 wxNode* node = m_tools.First();
624 while (node)
625 {
626 wxToolBarTool* tool = (wxToolBarTool*) node->Data();
627
628 wxUpdateUIEvent event( tool->m_index );
629 event.SetEventObject(this);
630
631 if (evtHandler->ProcessEvent( event ))
632 {
633 if (event.GetSetEnabled())
634 EnableTool(tool->m_index, event.GetEnabled());
635 if (event.GetSetChecked())
636 ToggleTool(tool->m_index, event.GetChecked());
637/*
638 if (event.GetSetText())
639 // Set tooltip?
640*/
641 }
642
643 node = node->Next();
644 }
645}
1144d24d 646
9b7e522a
RR
647void wxToolBar::OnInternalIdle()
648{
649 wxCursor cursor = m_cursor;
650 if (g_globalCursor.Ok()) cursor = g_globalCursor;
651
f7a11f8c 652 if (cursor.Ok())
9b7e522a 653 {
f7a11f8c
RR
654 /* I now set the cursor the anew in every OnInternalIdle call
655 as setting the cursor in a parent window also effects the
656 windows above so that checking for the current cursor is
657 not possible. */
85ec2f26
RR
658
659 if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
f7a11f8c
RR
660 {
661 /* if the toolbar is dockable, then m_widget stands for the
662 GtkHandleBox widget, which uses its own window so that we
663 can set the cursor for it. if the toolbar is not dockable,
664 m_widget comes from m_toolbar which uses its parent's
665 window ("windowless windows") and thus we cannot set the
666 cursor. */
667 gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
668 }
9b7e522a
RR
669
670 wxNode *node = m_tools.First();
671 while (node)
672 {
673 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
bf9e3e73
RR
674 node = node->Next();
675
676 if (!tool->m_item || !tool->m_item->window)
677 continue;
9b7e522a 678 else
f7a11f8c 679 gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() );
9b7e522a
RR
680 }
681 }
682
683 UpdateWindowUI();
684}
685
dcf924a3 686#endif