]> git.saurik.com Git - wxWidgets.git/blame - src/common/tbarbase.cpp
Take basic style into account when applying style sheet
[wxWidgets.git] / src / common / tbarbase.cpp
CommitLineData
10b959e3 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/common/tbarbase.cpp
8a0681f9 3// Purpose: wxToolBarBase implementation
10b959e3 4// Author: Julian Smart
3103e8a9 5// Modified by: VZ at 11.12.99 (wxScrollableToolBar split off)
10b959e3
JS
6// Created: 04/01/98
7// RCS-ID: $Id$
55d99c7a 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
10b959e3
JS
10/////////////////////////////////////////////////////////////////////////////
11
8a0681f9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
10b959e3
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
8a0681f9 24 #pragma hdrstop
10b959e3
JS
25#endif
26
1e6feb95
VZ
27#if wxUSE_TOOLBAR
28
76b49cf4
WS
29#include "wx/toolbar.h"
30
10b959e3 31#ifndef WX_PRECOMP
f538710f 32 #include "wx/control.h"
76b49cf4 33 #include "wx/frame.h"
9eddec69 34 #include "wx/settings.h"
9ac43913
VZ
35 #if WXWIN_COMPATIBILITY_2_8
36 #include "wx/image.h"
37 #endif // WXWIN_COMPATIBILITY_2_8
a9a0ceca 38 #include "wx/menu.h"
155ecd4c 39#endif
e702ff0f 40
8a0681f9 41// ----------------------------------------------------------------------------
77ffb593 42// wxWidgets macros
8a0681f9
VZ
43// ----------------------------------------------------------------------------
44
1e6feb95 45BEGIN_EVENT_TABLE(wxToolBarBase, wxControl)
1e6feb95
VZ
46END_EVENT_TABLE()
47
8a0681f9 48#include "wx/listimpl.cpp"
1c383dba 49
259c43f6 50WX_DEFINE_LIST(wxToolBarToolsList)
10b959e3 51
8a0681f9
VZ
52// ============================================================================
53// implementation
54// ============================================================================
10b959e3 55
8a0681f9
VZ
56// ----------------------------------------------------------------------------
57// wxToolBarToolBase
58// ----------------------------------------------------------------------------
10b959e3 59
cb719f2e 60IMPLEMENT_DYNAMIC_CLASS(wxToolBarToolBase, wxObject)
d6071228 61
a9a0ceca
VZ
62wxToolBarToolBase::~wxToolBarToolBase()
63{
64 delete m_dropdownMenu;
65}
66
67
8a0681f9 68bool wxToolBarToolBase::Enable(bool enable)
10b959e3 69{
ae291463
JS
70 if ( m_enabled == enable )
71 return false;
72
8a0681f9 73 m_enabled = enable;
10b959e3 74
331c9f56 75 return true;
10b959e3
JS
76}
77
8a0681f9 78bool wxToolBarToolBase::Toggle(bool toggle)
10b959e3 79{
e76c0b5f 80 wxASSERT_MSG( CanBeToggled(), _T("can't toggle this tool") );
8a0681f9 81
ae291463
JS
82 if ( m_toggled == toggle )
83 return false;
84
8a0681f9
VZ
85 m_toggled = toggle;
86
331c9f56 87 return true;
10b959e3
JS
88}
89
8a0681f9 90bool wxToolBarToolBase::SetToggle(bool toggle)
10b959e3 91{
e76c0b5f 92 wxItemKind kind = toggle ? wxITEM_CHECK : wxITEM_NORMAL;
ae291463
JS
93 if ( m_kind == kind )
94 return false;
10b959e3 95
e76c0b5f 96 m_kind = kind;
10b959e3 97
331c9f56 98 return true;
10b959e3
JS
99}
100
8a0681f9 101bool wxToolBarToolBase::SetShortHelp(const wxString& help)
10b959e3 102{
ae291463
JS
103 if ( m_shortHelpString == help )
104 return false;
105
8a0681f9
VZ
106 m_shortHelpString = help;
107
331c9f56 108 return true;
10b959e3
JS
109}
110
8a0681f9 111bool wxToolBarToolBase::SetLongHelp(const wxString& help)
10b959e3 112{
ae291463
JS
113 if ( m_longHelpString == help )
114 return false;
115
8a0681f9
VZ
116 m_longHelpString = help;
117
331c9f56 118 return true;
10b959e3
JS
119}
120
a9a0ceca
VZ
121
122void wxToolBarToolBase::SetDropdownMenu(wxMenu* menu)
123{
124 delete m_dropdownMenu;
125 m_dropdownMenu = menu;
126}
127
8a0681f9
VZ
128// ----------------------------------------------------------------------------
129// wxToolBarBase adding/deleting items
130// ----------------------------------------------------------------------------
ac91b9d2 131
8a0681f9
VZ
132wxToolBarBase::wxToolBarBase()
133{
134 // the list owns the pointers
8a0681f9 135 m_xMargin = m_yMargin = 0;
8a0681f9 136 m_maxRows = m_maxCols = 0;
7b3eaf8f
RR
137 m_toolPacking = m_toolSeparation = 0;
138 m_defaultWidth = 16;
139 m_defaultHeight = 15;
10b959e3
JS
140}
141
d408730c
VZ
142void wxToolBarBase::FixupStyle()
143{
144 if ( !HasFlag(wxTB_TOP | wxTB_LEFT | wxTB_RIGHT | wxTB_BOTTOM) )
145 {
146 // this is the default
147 m_windowStyle |= wxTB_TOP;
148 }
149}
150
e76c0b5f
VZ
151wxToolBarToolBase *wxToolBarBase::DoAddTool(int id,
152 const wxString& label,
153 const wxBitmap& bitmap,
154 const wxBitmap& bmpDisabled,
155 wxItemKind kind,
156 const wxString& shortHelp,
157 const wxString& longHelp,
158 wxObject *clientData,
159 wxCoord WXUNUSED(xPos),
160 wxCoord WXUNUSED(yPos))
10b959e3 161{
9f884528 162 InvalidateBestSize();
e76c0b5f
VZ
163 return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled,
164 kind, shortHelp, longHelp, clientData);
10b959e3
JS
165}
166
8a0681f9
VZ
167wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos,
168 int id,
e76c0b5f 169 const wxString& label,
8a0681f9 170 const wxBitmap& bitmap,
e76c0b5f
VZ
171 const wxBitmap& bmpDisabled,
172 wxItemKind kind,
173 const wxString& shortHelp,
174 const wxString& longHelp,
175 wxObject *clientData)
10b959e3 176{
8a0681f9
VZ
177 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
178 _T("invalid position in wxToolBar::InsertTool()") );
179
e76c0b5f
VZ
180 wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind,
181 clientData, shortHelp, longHelp);
8a0681f9 182
dd91da4e 183 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
184 {
185 delete tool;
186
187 return NULL;
188 }
189
dd91da4e
VZ
190 return tool;
191}
192
193wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool)
194{
195 return InsertTool(GetToolsCount(), tool);
196}
197
198wxToolBarToolBase *
199wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool)
200{
201 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
202 _T("invalid position in wxToolBar::InsertTool()") );
203
204 if ( !tool || !DoInsertTool(pos, tool) )
205 {
206 return NULL;
207 }
208
8a0681f9
VZ
209 m_tools.Insert(pos, tool);
210
211 return tool;
10b959e3
JS
212}
213
cdb11cb9
VZ
214wxToolBarToolBase *
215wxToolBarBase::AddControl(wxControl *control, const wxString& label)
10b959e3 216{
cdb11cb9 217 return InsertControl(GetToolsCount(), control, label);
10b959e3
JS
218}
219
cdb11cb9
VZ
220wxToolBarToolBase *
221wxToolBarBase::InsertControl(size_t pos,
222 wxControl *control,
223 const wxString& label)
10b959e3 224{
8a0681f9
VZ
225 wxCHECK_MSG( control, (wxToolBarToolBase *)NULL,
226 _T("toolbar: can't insert NULL control") );
227
228 wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL,
229 _T("control must have toolbar as parent") );
230
231 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
232 _T("invalid position in wxToolBar::InsertControl()") );
233
cdb11cb9 234 wxToolBarToolBase *tool = CreateTool(control, label);
8a0681f9 235
dd91da4e 236 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
237 {
238 delete tool;
239
240 return NULL;
241 }
242
8a0681f9 243 return tool;
10b959e3
JS
244}
245
fba2d5e6
RR
246wxControl *wxToolBarBase::FindControl( int id )
247{
222ed1d6 248 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
fba2d5e6
RR
249 node;
250 node = node->GetNext() )
251 {
652ab153
VZ
252 const wxToolBarToolBase * const tool = node->GetData();
253 if ( tool->IsControl() )
fba2d5e6 254 {
652ab153
VZ
255 wxControl * const control = tool->GetControl();
256
257 if ( !control )
258 {
259 wxFAIL_MSG( _T("NULL control in toolbar?") );
260 }
261 else if ( control->GetId() == id )
262 {
263 // found
fba2d5e6 264 return control;
652ab153 265 }
fba2d5e6
RR
266 }
267 }
268
269 return NULL;
270}
271
8a0681f9 272wxToolBarToolBase *wxToolBarBase::AddSeparator()
10b959e3 273{
8a0681f9 274 return InsertSeparator(GetToolsCount());
10b959e3
JS
275}
276
8a0681f9 277wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos)
10b959e3 278{
8a0681f9
VZ
279 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
280 _T("invalid position in wxToolBar::InsertSeparator()") );
281
282 wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR,
e76c0b5f 283 wxEmptyString,
8a0681f9 284 wxNullBitmap, wxNullBitmap,
e76c0b5f 285 wxITEM_SEPARATOR, (wxObject *)NULL,
8a0681f9
VZ
286 wxEmptyString, wxEmptyString);
287
288 if ( !tool || !DoInsertTool(pos, tool) )
10b959e3 289 {
8a0681f9
VZ
290 delete tool;
291
292 return NULL;
10b959e3 293 }
8a0681f9
VZ
294
295 m_tools.Insert(pos, tool);
296
297 return tool;
10b959e3
JS
298}
299
8a0681f9 300wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)
10b959e3 301{
8a0681f9 302 size_t pos = 0;
222ed1d6 303 wxToolBarToolsList::compatibility_iterator node;
8a0681f9 304 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
10b959e3 305 {
8a0681f9
VZ
306 if ( node->GetData()->GetId() == id )
307 break;
308
309 pos++;
10b959e3 310 }
10b959e3 311
8a0681f9 312 if ( !node )
10b959e3 313 {
8a0681f9
VZ
314 // don't give any error messages - sometimes we might call RemoveTool()
315 // without knowing whether the tool is or not in the toolbar
316 return (wxToolBarToolBase *)NULL;
10b959e3 317 }
10b959e3 318
8a0681f9
VZ
319 wxToolBarToolBase *tool = node->GetData();
320 if ( !DoDeleteTool(pos, tool) )
321 {
322 return (wxToolBarToolBase *)NULL;
323 }
10b959e3 324
222ed1d6 325 m_tools.Erase(node);
10b959e3 326
8a0681f9 327 return tool;
10b959e3
JS
328}
329
8a0681f9 330bool wxToolBarBase::DeleteToolByPos(size_t pos)
10b959e3 331{
331c9f56 332 wxCHECK_MSG( pos < GetToolsCount(), false,
8a0681f9 333 _T("invalid position in wxToolBar::DeleteToolByPos()") );
10b959e3 334
222ed1d6 335 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
10b959e3 336
8a0681f9
VZ
337 if ( !DoDeleteTool(pos, node->GetData()) )
338 {
331c9f56 339 return false;
8a0681f9
VZ
340 }
341
222ed1d6
MB
342 delete node->GetData();
343 m_tools.Erase(node);
8a0681f9 344
331c9f56 345 return true;
10b959e3
JS
346}
347
8a0681f9 348bool wxToolBarBase::DeleteTool(int id)
10b959e3 349{
8a0681f9 350 size_t pos = 0;
222ed1d6 351 wxToolBarToolsList::compatibility_iterator node;
8a0681f9
VZ
352 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
353 {
354 if ( node->GetData()->GetId() == id )
355 break;
356
357 pos++;
358 }
359
360 if ( !node || !DoDeleteTool(pos, node->GetData()) )
361 {
331c9f56 362 return false;
8a0681f9
VZ
363 }
364
222ed1d6
MB
365 delete node->GetData();
366 m_tools.Erase(node);
8a0681f9 367
331c9f56 368 return true;
10b959e3
JS
369}
370
8a0681f9 371wxToolBarToolBase *wxToolBarBase::FindById(int id) const
10b959e3 372{
8a0681f9
VZ
373 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
374
222ed1d6 375 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
376 node;
377 node = node->GetNext() )
378 {
379 tool = node->GetData();
380 if ( tool->GetId() == id )
381 {
382 // found
383 break;
384 }
d9739886
VZ
385
386 tool = NULL;
8a0681f9
VZ
387 }
388
389 return tool;
10b959e3
JS
390}
391
331c9f56
VZ
392void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool)
393{
394 wxCHECK_RET( tool, _T("NULL tool in wxToolBarTool::UnToggleRadioGroup") );
395
396 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
397 return;
398
399 wxToolBarToolsList::compatibility_iterator node = m_tools.Find(tool);
400 wxCHECK_RET( node, _T("invalid tool in wxToolBarTool::UnToggleRadioGroup") );
401
402 wxToolBarToolsList::compatibility_iterator nodeNext = node->GetNext();
403 while ( nodeNext )
404 {
4e115ed2 405 wxToolBarToolBase *toolNext = nodeNext->GetData();
331c9f56 406
4e115ed2 407 if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO )
331c9f56
VZ
408 break;
409
4e115ed2 410 if ( toolNext->Toggle(false) )
214b9484 411 {
4e115ed2 412 DoToggleTool(toolNext, false);
214b9484 413 }
331c9f56
VZ
414
415 nodeNext = nodeNext->GetNext();
416 }
417
418 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
419 while ( nodePrev )
420 {
4e115ed2 421 wxToolBarToolBase *toolNext = nodePrev->GetData();
331c9f56 422
4e115ed2 423 if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO )
331c9f56
VZ
424 break;
425
4e115ed2 426 if ( toolNext->Toggle(false) )
214b9484 427 {
4e115ed2 428 DoToggleTool(toolNext, false);
214b9484 429 }
331c9f56
VZ
430
431 nodePrev = nodePrev->GetPrevious();
432 }
433}
434
8a0681f9 435void wxToolBarBase::ClearTools()
10b959e3 436{
a3e9caa2
RD
437 while ( GetToolsCount() )
438 {
439 DeleteToolByPos(0);
440 }
10b959e3
JS
441}
442
8a0681f9 443bool wxToolBarBase::Realize()
10b959e3 444{
331c9f56 445 return true;
10b959e3
JS
446}
447
8a0681f9 448wxToolBarBase::~wxToolBarBase()
10b959e3 449{
222ed1d6 450 WX_CLEAR_LIST(wxToolBarToolsList, m_tools);
2ab82214
VZ
451
452 // notify the frame that it doesn't have a tool bar any longer to avoid
453 // dangling pointers
b2e3be1c 454 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2ab82214
VZ
455 if ( frame && frame->GetToolBar() == this )
456 {
457 frame->SetToolBar(NULL);
458 }
10b959e3
JS
459}
460
8a0681f9
VZ
461// ----------------------------------------------------------------------------
462// wxToolBarBase tools state
463// ----------------------------------------------------------------------------
10b959e3 464
8a0681f9 465void wxToolBarBase::EnableTool(int id, bool enable)
10b959e3 466{
8a0681f9
VZ
467 wxToolBarToolBase *tool = FindById(id);
468 if ( tool )
10b959e3 469 {
8a0681f9
VZ
470 if ( tool->Enable(enable) )
471 {
472 DoEnableTool(tool, enable);
473 }
10b959e3 474 }
8a0681f9 475}
10b959e3 476
8a0681f9
VZ
477void wxToolBarBase::ToggleTool(int id, bool toggle)
478{
479 wxToolBarToolBase *tool = FindById(id);
480 if ( tool && tool->CanBeToggled() )
10b959e3 481 {
8a0681f9
VZ
482 if ( tool->Toggle(toggle) )
483 {
331c9f56 484 UnToggleRadioGroup(tool);
8a0681f9
VZ
485 DoToggleTool(tool, toggle);
486 }
10b959e3 487 }
10b959e3
JS
488}
489
8a0681f9
VZ
490void wxToolBarBase::SetToggle(int id, bool toggle)
491{
492 wxToolBarToolBase *tool = FindById(id);
493 if ( tool )
10b959e3 494 {
8a0681f9
VZ
495 if ( tool->SetToggle(toggle) )
496 {
497 DoSetToggle(tool, toggle);
498 }
10b959e3 499 }
8a0681f9
VZ
500}
501
502void wxToolBarBase::SetToolShortHelp(int id, const wxString& help)
503{
504 wxToolBarToolBase *tool = FindById(id);
505 if ( tool )
10b959e3 506 {
8a0681f9 507 (void)tool->SetShortHelp(help);
10b959e3 508 }
8a0681f9
VZ
509}
510
511void wxToolBarBase::SetToolLongHelp(int id, const wxString& help)
512{
513 wxToolBarToolBase *tool = FindById(id);
514 if ( tool )
10b959e3 515 {
8a0681f9 516 (void)tool->SetLongHelp(help);
10b959e3 517 }
10b959e3
JS
518}
519
8a0681f9 520wxObject *wxToolBarBase::GetToolClientData(int id) const
10b959e3 521{
8a0681f9
VZ
522 wxToolBarToolBase *tool = FindById(id);
523
524 return tool ? tool->GetClientData() : (wxObject *)NULL;
10b959e3
JS
525}
526
6fd5fa4f
VZ
527void wxToolBarBase::SetToolClientData(int id, wxObject *clientData)
528{
529 wxToolBarToolBase *tool = FindById(id);
530
531 wxCHECK_RET( tool, _T("no such tool in wxToolBar::SetToolClientData") );
532
533 tool->SetClientData(clientData);
534}
535
e6c96a7c
JS
536int wxToolBarBase::GetToolPos(int id) const
537{
538 size_t pos = 0;
222ed1d6 539 wxToolBarToolsList::compatibility_iterator node;
e6c96a7c
JS
540
541 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
542 {
543 if ( node->GetData()->GetId() == id )
544 return pos;
545
546 pos++;
547 }
548
549 return wxNOT_FOUND;
550}
551
8a0681f9 552bool wxToolBarBase::GetToolState(int id) const
10b959e3 553{
8a0681f9 554 wxToolBarToolBase *tool = FindById(id);
331c9f56 555 wxCHECK_MSG( tool, false, _T("no such tool") );
8a0681f9
VZ
556
557 return tool->IsToggled();
10b959e3
JS
558}
559
8a0681f9 560bool wxToolBarBase::GetToolEnabled(int id) const
10b959e3 561{
8a0681f9 562 wxToolBarToolBase *tool = FindById(id);
331c9f56 563 wxCHECK_MSG( tool, false, _T("no such tool") );
8a0681f9
VZ
564
565 return tool->IsEnabled();
10b959e3
JS
566}
567
8a0681f9 568wxString wxToolBarBase::GetToolShortHelp(int id) const
10b959e3 569{
8a0681f9 570 wxToolBarToolBase *tool = FindById(id);
525d8583 571 wxCHECK_MSG( tool, wxEmptyString, _T("no such tool") );
8a0681f9
VZ
572
573 return tool->GetShortHelp();
10b959e3
JS
574}
575
8a0681f9 576wxString wxToolBarBase::GetToolLongHelp(int id) const
10b959e3 577{
8a0681f9 578 wxToolBarToolBase *tool = FindById(id);
525d8583 579 wxCHECK_MSG( tool, wxEmptyString, _T("no such tool") );
10b959e3 580
8a0681f9 581 return tool->GetLongHelp();
10b959e3
JS
582}
583
8a0681f9
VZ
584// ----------------------------------------------------------------------------
585// wxToolBarBase geometry
586// ----------------------------------------------------------------------------
587
588void wxToolBarBase::SetMargins(int x, int y)
10b959e3 589{
8a0681f9
VZ
590 m_xMargin = x;
591 m_yMargin = y;
10b959e3
JS
592}
593
8a0681f9 594void wxToolBarBase::SetRows(int WXUNUSED(nRows))
10b959e3 595{
8a0681f9 596 // nothing
10b959e3
JS
597}
598
8a0681f9
VZ
599// ----------------------------------------------------------------------------
600// event processing
601// ----------------------------------------------------------------------------
602
331c9f56 603// Only allow toggle if returns true
8a0681f9 604bool wxToolBarBase::OnLeftClick(int id, bool toggleDown)
10b959e3 605{
8a0681f9
VZ
606 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id);
607 event.SetEventObject(this);
6bec54e1
VZ
608
609 // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown
610 event.SetInt((int)toggleDown);
611
612 // and SetExtraLong() for backwards compatibility
613 event.SetExtraLong((long)toggleDown);
8a0681f9
VZ
614
615 // Send events to this toolbar instead (and thence up the window hierarchy)
616 GetEventHandler()->ProcessEvent(event);
617
331c9f56 618 return true;
10b959e3
JS
619}
620
8a0681f9
VZ
621// Call when right button down.
622void wxToolBarBase::OnRightClick(int id,
623 long WXUNUSED(x),
624 long WXUNUSED(y))
10b959e3 625{
8a0681f9
VZ
626 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id);
627 event.SetEventObject(this);
628 event.SetInt(id);
629
630 GetEventHandler()->ProcessEvent(event);
631}
43d811ea 632
8a0681f9 633// Called when the mouse cursor enters a tool bitmap (no button pressed).
cb719f2e 634// Argument is wxID_ANY if mouse is exiting the toolbar.
8a0681f9
VZ
635// Note that for this event, the id of the window is used,
636// and the integer parameter of wxCommandEvent is used to retrieve
637// the tool id.
638void wxToolBarBase::OnMouseEnter(int id)
639{
640 wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId());
641 event.SetEventObject(this);
642 event.SetInt(id);
643
8a0681f9 644 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
6d99eb3e 645 if ( frame )
66ce9e06 646 {
326a37f1 647 wxString help;
fa36fe36
VZ
648 if ( id != wxID_ANY )
649 {
650 const wxToolBarToolBase * const tool = FindById(id);
651 if ( tool )
652 help = tool->GetLongHelp();
653 }
654
6d99eb3e
VZ
655 // call DoGiveHelp() even if help string is empty to avoid showing the
656 // help for the previously selected tool when another one is selected
657 frame->DoGiveHelp(help, id != wxID_ANY);
66ce9e06
VZ
658 }
659
1f361cdd 660 (void)GetEventHandler()->ProcessEvent(event);
8a0681f9
VZ
661}
662
663// ----------------------------------------------------------------------------
664// UI updates
665// ----------------------------------------------------------------------------
666
10b959e3 667// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
e39af974 668void wxToolBarBase::UpdateWindowUI(long flags)
ac91b9d2 669{
e39af974
JS
670 wxWindowBase::UpdateWindowUI(flags);
671
632e5b63
VZ
672 // don't waste time updating state of tools in a hidden toolbar
673 if ( !IsShown() )
674 return;
675
fe5d86ed
RR
676 // There is no sense in updating the toolbar UI
677 // if the parent window is about to get destroyed
5ce61d9f
RR
678 wxWindow *tlw = wxGetTopLevelParent( this );
679 if (tlw && wxPendingDelete.Member( tlw ))
fe5d86ed
RR
680 return;
681
65b17727 682 wxEvtHandler* evtHandler = GetEventHandler() ;
e702ff0f 683
222ed1d6 684 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
685 node;
686 node = node->GetNext() )
ac91b9d2 687 {
8a0681f9 688 int id = node->GetData()->GetId();
ac91b9d2 689
8a0681f9 690 wxUpdateUIEvent event(id);
ac91b9d2
VZ
691 event.SetEventObject(this);
692
8a0681f9 693 if ( evtHandler->ProcessEvent(event) )
ac91b9d2 694 {
8a0681f9
VZ
695 if ( event.GetSetEnabled() )
696 EnableTool(id, event.GetEnabled());
697 if ( event.GetSetChecked() )
698 ToggleTool(id, event.GetChecked());
699#if 0
700 if ( event.GetSetText() )
ac91b9d2 701 // Set tooltip?
8a0681f9 702#endif // 0
ac91b9d2 703 }
ac91b9d2 704 }
10b959e3
JS
705}
706
a9a0ceca
VZ
707bool wxToolBarBase::SetDropdownMenu(int toolid, wxMenu* menu)
708{
709 wxToolBarToolBase * const tool = FindById(toolid);
710 wxCHECK_MSG( tool, false, _T("invalid tool id") );
711
712 wxCHECK_MSG( tool->GetKind() == wxITEM_DROPDOWN, false,
713 _T("menu can be only associated with drop down tools") );
714
715 tool->SetDropdownMenu(menu);
716
717 return true;
718}
719
9ac43913 720#if WXWIN_COMPATIBILITY_2_8
c229e50d 721
9ac43913 722bool wxCreateGreyedImage(const wxImage& in, wxImage& out)
c229e50d 723{
9ac43913
VZ
724#if wxUSE_IMAGE
725 out = in.ConvertToGreyscale();
726 if ( out.Ok() )
727 return true;
728#endif // wxUSE_IMAGE
9ac43913 729 return false;
c229e50d
JS
730}
731
9ac43913 732#endif // WXWIN_COMPATIBILITY_2_8
434c6c9f 733
8a0681f9 734#endif // wxUSE_TOOLBAR