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