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