]> git.saurik.com Git - wxWidgets.git/blame - src/common/tbarbase.cpp
corrected misleading comment about DllGetVersion()
[wxWidgets.git] / src / common / tbarbase.cpp
CommitLineData
10b959e3 1/////////////////////////////////////////////////////////////////////////////
8a0681f9
VZ
2// Name: common/tbarbase.cpp
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
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8a0681f9 21 #pragma implementation "tbarbase.h"
10b959e3
JS
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
8a0681f9 28 #pragma hdrstop
10b959e3
JS
29#endif
30
1e6feb95
VZ
31#if wxUSE_TOOLBAR
32
10b959e3 33#ifndef WX_PRECOMP
f538710f 34 #include "wx/control.h"
10b959e3
JS
35#endif
36
e702ff0f 37#include "wx/frame.h"
434c6c9f
VZ
38
39#if wxUSE_IMAGE
40 #include "wx/image.h"
41 #include "wx/settings.h"
42#endif // wxUSE_IMAGE
e702ff0f 43
68a14aee 44#include "wx/toolbar.h"
10b959e3 45
8a0681f9 46// ----------------------------------------------------------------------------
77ffb593 47// wxWidgets macros
8a0681f9
VZ
48// ----------------------------------------------------------------------------
49
1e6feb95 50BEGIN_EVENT_TABLE(wxToolBarBase, wxControl)
1e6feb95
VZ
51END_EVENT_TABLE()
52
8a0681f9 53#include "wx/listimpl.cpp"
1c383dba 54
8a0681f9 55WX_DEFINE_LIST(wxToolBarToolsList);
10b959e3 56
8a0681f9
VZ
57// ============================================================================
58// implementation
59// ============================================================================
10b959e3 60
8a0681f9
VZ
61// ----------------------------------------------------------------------------
62// wxToolBarToolBase
63// ----------------------------------------------------------------------------
10b959e3 64
cb719f2e 65IMPLEMENT_DYNAMIC_CLASS(wxToolBarToolBase, wxObject)
d6071228 66
8a0681f9 67bool wxToolBarToolBase::Enable(bool enable)
10b959e3 68{
ae291463
JS
69 if ( m_enabled == enable )
70 return false;
71
8a0681f9 72 m_enabled = enable;
10b959e3 73
331c9f56 74 return true;
10b959e3
JS
75}
76
8a0681f9 77bool wxToolBarToolBase::Toggle(bool toggle)
10b959e3 78{
e76c0b5f 79 wxASSERT_MSG( CanBeToggled(), _T("can't toggle this tool") );
8a0681f9 80
ae291463
JS
81 if ( m_toggled == toggle )
82 return false;
83
8a0681f9
VZ
84 m_toggled = toggle;
85
331c9f56 86 return true;
10b959e3
JS
87}
88
8a0681f9 89bool wxToolBarToolBase::SetToggle(bool toggle)
10b959e3 90{
e76c0b5f 91 wxItemKind kind = toggle ? wxITEM_CHECK : wxITEM_NORMAL;
ae291463
JS
92 if ( m_kind == kind )
93 return false;
10b959e3 94
e76c0b5f 95 m_kind = kind;
10b959e3 96
331c9f56 97 return true;
10b959e3
JS
98}
99
8a0681f9 100bool wxToolBarToolBase::SetShortHelp(const wxString& help)
10b959e3 101{
ae291463
JS
102 if ( m_shortHelpString == help )
103 return false;
104
8a0681f9
VZ
105 m_shortHelpString = help;
106
331c9f56 107 return true;
10b959e3
JS
108}
109
8a0681f9 110bool wxToolBarToolBase::SetLongHelp(const wxString& help)
10b959e3 111{
ae291463
JS
112 if ( m_longHelpString == help )
113 return false;
114
8a0681f9
VZ
115 m_longHelpString = help;
116
331c9f56 117 return true;
10b959e3
JS
118}
119
b4efc9b9
WS
120#if WXWIN_COMPATIBILITY_2_2
121
122const wxBitmap& wxToolBarToolBase::GetBitmap1() const
123{
124 return GetNormalBitmap();
125}
126
127const wxBitmap& wxToolBarToolBase::GetBitmap2() const
128{
129 return GetDisabledBitmap();
130}
131
132void wxToolBarToolBase::SetBitmap1(const wxBitmap& bmp)
133{
134 SetNormalBitmap(bmp);
135}
136
137void wxToolBarToolBase::SetBitmap2(const wxBitmap& bmp)
138{
139 SetDisabledBitmap(bmp);
140}
141
142#endif // WXWIN_COMPATIBILITY_2_2
143
8a0681f9
VZ
144// ----------------------------------------------------------------------------
145// wxToolBarBase adding/deleting items
146// ----------------------------------------------------------------------------
ac91b9d2 147
8a0681f9
VZ
148wxToolBarBase::wxToolBarBase()
149{
150 // the list owns the pointers
8a0681f9 151 m_xMargin = m_yMargin = 0;
8a0681f9 152 m_maxRows = m_maxCols = 0;
7b3eaf8f
RR
153 m_toolPacking = m_toolSeparation = 0;
154 m_defaultWidth = 16;
155 m_defaultHeight = 15;
10b959e3
JS
156}
157
e76c0b5f
VZ
158wxToolBarToolBase *wxToolBarBase::DoAddTool(int id,
159 const wxString& label,
160 const wxBitmap& bitmap,
161 const wxBitmap& bmpDisabled,
162 wxItemKind kind,
163 const wxString& shortHelp,
164 const wxString& longHelp,
165 wxObject *clientData,
166 wxCoord WXUNUSED(xPos),
167 wxCoord WXUNUSED(yPos))
10b959e3 168{
9f884528 169 InvalidateBestSize();
e76c0b5f
VZ
170 return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled,
171 kind, shortHelp, longHelp, clientData);
10b959e3
JS
172}
173
8a0681f9
VZ
174wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos,
175 int id,
e76c0b5f 176 const wxString& label,
8a0681f9 177 const wxBitmap& bitmap,
e76c0b5f
VZ
178 const wxBitmap& bmpDisabled,
179 wxItemKind kind,
180 const wxString& shortHelp,
181 const wxString& longHelp,
182 wxObject *clientData)
10b959e3 183{
8a0681f9
VZ
184 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
185 _T("invalid position in wxToolBar::InsertTool()") );
186
e76c0b5f
VZ
187 wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind,
188 clientData, shortHelp, longHelp);
8a0681f9 189
dd91da4e 190 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
191 {
192 delete tool;
193
194 return NULL;
195 }
196
dd91da4e
VZ
197 return tool;
198}
199
200wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool)
201{
202 return InsertTool(GetToolsCount(), tool);
203}
204
205wxToolBarToolBase *
206wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool)
207{
208 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
209 _T("invalid position in wxToolBar::InsertTool()") );
210
211 if ( !tool || !DoInsertTool(pos, tool) )
212 {
213 return NULL;
214 }
215
8a0681f9
VZ
216 m_tools.Insert(pos, tool);
217
218 return tool;
10b959e3
JS
219}
220
8a0681f9 221wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control)
10b959e3 222{
8a0681f9 223 return InsertControl(GetToolsCount(), control);
10b959e3
JS
224}
225
8a0681f9 226wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control)
10b959e3 227{
8a0681f9
VZ
228 wxCHECK_MSG( control, (wxToolBarToolBase *)NULL,
229 _T("toolbar: can't insert NULL control") );
230
231 wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL,
232 _T("control must have toolbar as parent") );
233
234 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
235 _T("invalid position in wxToolBar::InsertControl()") );
236
237 wxToolBarToolBase *tool = CreateTool(control);
238
dd91da4e 239 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
240 {
241 delete tool;
242
243 return NULL;
244 }
245
8a0681f9 246 return tool;
10b959e3
JS
247}
248
fba2d5e6
RR
249wxControl *wxToolBarBase::FindControl( int id )
250{
222ed1d6 251 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
fba2d5e6
RR
252 node;
253 node = node->GetNext() )
254 {
652ab153
VZ
255 const wxToolBarToolBase * const tool = node->GetData();
256 if ( tool->IsControl() )
fba2d5e6 257 {
652ab153
VZ
258 wxControl * const control = tool->GetControl();
259
260 if ( !control )
261 {
262 wxFAIL_MSG( _T("NULL control in toolbar?") );
263 }
264 else if ( control->GetId() == id )
265 {
266 // found
fba2d5e6 267 return control;
652ab153 268 }
fba2d5e6
RR
269 }
270 }
271
272 return NULL;
273}
274
8a0681f9 275wxToolBarToolBase *wxToolBarBase::AddSeparator()
10b959e3 276{
8a0681f9 277 return InsertSeparator(GetToolsCount());
10b959e3
JS
278}
279
8a0681f9 280wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos)
10b959e3 281{
8a0681f9
VZ
282 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
283 _T("invalid position in wxToolBar::InsertSeparator()") );
284
285 wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR,
e76c0b5f 286 wxEmptyString,
8a0681f9 287 wxNullBitmap, wxNullBitmap,
e76c0b5f 288 wxITEM_SEPARATOR, (wxObject *)NULL,
8a0681f9
VZ
289 wxEmptyString, wxEmptyString);
290
291 if ( !tool || !DoInsertTool(pos, tool) )
10b959e3 292 {
8a0681f9
VZ
293 delete tool;
294
295 return NULL;
10b959e3 296 }
8a0681f9
VZ
297
298 m_tools.Insert(pos, tool);
299
300 return tool;
10b959e3
JS
301}
302
8a0681f9 303wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)
10b959e3 304{
8a0681f9 305 size_t pos = 0;
222ed1d6 306 wxToolBarToolsList::compatibility_iterator node;
8a0681f9 307 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
10b959e3 308 {
8a0681f9
VZ
309 if ( node->GetData()->GetId() == id )
310 break;
311
312 pos++;
10b959e3 313 }
10b959e3 314
8a0681f9 315 if ( !node )
10b959e3 316 {
8a0681f9
VZ
317 // don't give any error messages - sometimes we might call RemoveTool()
318 // without knowing whether the tool is or not in the toolbar
319 return (wxToolBarToolBase *)NULL;
10b959e3 320 }
10b959e3 321
8a0681f9
VZ
322 wxToolBarToolBase *tool = node->GetData();
323 if ( !DoDeleteTool(pos, tool) )
324 {
325 return (wxToolBarToolBase *)NULL;
326 }
10b959e3 327
222ed1d6 328 m_tools.Erase(node);
10b959e3 329
8a0681f9 330 return tool;
10b959e3
JS
331}
332
8a0681f9 333bool wxToolBarBase::DeleteToolByPos(size_t pos)
10b959e3 334{
331c9f56 335 wxCHECK_MSG( pos < GetToolsCount(), false,
8a0681f9 336 _T("invalid position in wxToolBar::DeleteToolByPos()") );
10b959e3 337
222ed1d6 338 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
10b959e3 339
8a0681f9
VZ
340 if ( !DoDeleteTool(pos, node->GetData()) )
341 {
331c9f56 342 return false;
8a0681f9
VZ
343 }
344
222ed1d6
MB
345 delete node->GetData();
346 m_tools.Erase(node);
8a0681f9 347
331c9f56 348 return true;
10b959e3
JS
349}
350
8a0681f9 351bool wxToolBarBase::DeleteTool(int id)
10b959e3 352{
8a0681f9 353 size_t pos = 0;
222ed1d6 354 wxToolBarToolsList::compatibility_iterator node;
8a0681f9
VZ
355 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
356 {
357 if ( node->GetData()->GetId() == id )
358 break;
359
360 pos++;
361 }
362
363 if ( !node || !DoDeleteTool(pos, node->GetData()) )
364 {
331c9f56 365 return false;
8a0681f9
VZ
366 }
367
222ed1d6
MB
368 delete node->GetData();
369 m_tools.Erase(node);
8a0681f9 370
331c9f56 371 return true;
10b959e3
JS
372}
373
8a0681f9 374wxToolBarToolBase *wxToolBarBase::FindById(int id) const
10b959e3 375{
8a0681f9
VZ
376 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
377
222ed1d6 378 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
379 node;
380 node = node->GetNext() )
381 {
382 tool = node->GetData();
383 if ( tool->GetId() == id )
384 {
385 // found
386 break;
387 }
d9739886
VZ
388
389 tool = NULL;
8a0681f9
VZ
390 }
391
392 return tool;
10b959e3
JS
393}
394
331c9f56
VZ
395void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool)
396{
397 wxCHECK_RET( tool, _T("NULL tool in wxToolBarTool::UnToggleRadioGroup") );
398
399 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
400 return;
401
402 wxToolBarToolsList::compatibility_iterator node = m_tools.Find(tool);
403 wxCHECK_RET( node, _T("invalid tool in wxToolBarTool::UnToggleRadioGroup") );
404
405 wxToolBarToolsList::compatibility_iterator nodeNext = node->GetNext();
406 while ( nodeNext )
407 {
408 wxToolBarToolBase *tool = nodeNext->GetData();
409
410 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
411 break;
412
214b9484
RD
413 if ( tool->Toggle(false) )
414 {
415 DoToggleTool(tool, false);
416 }
331c9f56
VZ
417
418 nodeNext = nodeNext->GetNext();
419 }
420
421 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
422 while ( nodePrev )
423 {
424 wxToolBarToolBase *tool = nodePrev->GetData();
425
426 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
427 break;
428
214b9484
RD
429 if ( tool->Toggle(false) )
430 {
431 DoToggleTool(tool, false);
432 }
331c9f56
VZ
433
434 nodePrev = nodePrev->GetPrevious();
435 }
436}
437
8a0681f9 438void wxToolBarBase::ClearTools()
10b959e3 439{
222ed1d6 440 WX_CLEAR_LIST(wxToolBarToolsList, m_tools);
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);
1f361cdd 645 if( frame )
66ce9e06 646 {
326a37f1
WS
647 wxString help;
648 wxToolBarToolBase* tool = id == wxID_ANY ? (wxToolBarToolBase*)NULL : FindById(id);
649 if(tool)
650 help = tool->GetLongHelp();
cb719f2e 651 frame->DoGiveHelp( help, id != wxID_ANY );
66ce9e06
VZ
652 }
653
1f361cdd 654 (void)GetEventHandler()->ProcessEvent(event);
8a0681f9
VZ
655}
656
657// ----------------------------------------------------------------------------
658// UI updates
659// ----------------------------------------------------------------------------
660
10b959e3 661// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
e39af974 662void wxToolBarBase::UpdateWindowUI(long flags)
ac91b9d2 663{
e39af974
JS
664 wxWindowBase::UpdateWindowUI(flags);
665
fe5d86ed
RR
666 // There is no sense in updating the toolbar UI
667 // if the parent window is about to get destroyed
5ce61d9f
RR
668 wxWindow *tlw = wxGetTopLevelParent( this );
669 if (tlw && wxPendingDelete.Member( tlw ))
fe5d86ed
RR
670 return;
671
65b17727 672 wxEvtHandler* evtHandler = GetEventHandler() ;
e702ff0f 673
222ed1d6 674 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
675 node;
676 node = node->GetNext() )
ac91b9d2 677 {
8a0681f9 678 int id = node->GetData()->GetId();
ac91b9d2 679
8a0681f9 680 wxUpdateUIEvent event(id);
ac91b9d2
VZ
681 event.SetEventObject(this);
682
8a0681f9 683 if ( evtHandler->ProcessEvent(event) )
ac91b9d2 684 {
8a0681f9
VZ
685 if ( event.GetSetEnabled() )
686 EnableTool(id, event.GetEnabled());
687 if ( event.GetSetChecked() )
688 ToggleTool(id, event.GetChecked());
689#if 0
690 if ( event.GetSetText() )
ac91b9d2 691 // Set tooltip?
8a0681f9 692#endif // 0
ac91b9d2 693 }
ac91b9d2 694 }
10b959e3
JS
695}
696
434c6c9f 697#if wxUSE_IMAGE
c229e50d
JS
698
699/*
700 * Make a greyed-out image suitable for disabled buttons.
701 * This code is adapted from wxNewBitmapButton in FL.
702 */
703
434c6c9f 704bool wxCreateGreyedImage(const wxImage& src, wxImage& dst)
c229e50d 705{
434c6c9f 706 dst = src.Copy();
c229e50d 707
434c6c9f
VZ
708 unsigned char rBg, gBg, bBg;
709 if ( src.HasMask() )
062b84dd 710 {
434c6c9f
VZ
711 src.GetOrFindMaskColour(&rBg, &gBg, &bBg);
712 dst.SetMaskColour(rBg, gBg, bBg);
062b84dd
VZ
713 }
714 else // assuming the pixels along the edges are of the background color
715 {
434c6c9f
VZ
716 rBg = src.GetRed(0, 0);
717 gBg = src.GetGreen(0, 0);
718 bBg = src.GetBlue(0, 0);
062b84dd
VZ
719 }
720
434c6c9f 721 const wxColour colBg(rBg, gBg, bBg);
c229e50d 722
434c6c9f
VZ
723 const wxColour colDark = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
724 const wxColour colLight = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
c229e50d 725
434c6c9f
VZ
726 // Second attempt, just making things monochrome
727 const int width = src.GetWidth();
728 const int height = src.GetHeight();
729
730 for ( int x = 0; x < width; x++ )
731 {
732 for ( int y = 0; y < height; y++ )
733 {
734 const int r = src.GetRed(x, y);
735 const int g = src.GetGreen(x, y);
736 const int b = src.GetBlue(x, y);
737
738 if ( r == rBg && g == gBg && b == bBg )
739 {
740 // Leave the background colour as-is
741 continue;
742 }
743
744 // Change light things to the background colour
745 wxColour col;
746 if ( r >= (colLight.Red() - 50) &&
747 g >= (colLight.Green() - 50) &&
748 b >= (colLight.Blue() - 50) )
749 {
750 col = colBg;
751 }
752 else // Change dark things to really dark
753 {
754 col = colDark;
755 }
756
757 dst.SetRGB(x, y, col.Red(), col.Green(), col.Blue());
758 }
759 }
c229e50d 760
331c9f56 761 return true;
c229e50d
JS
762}
763
434c6c9f
VZ
764#endif // wxUSE_IMAGE
765
8a0681f9 766#endif // wxUSE_TOOLBAR