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