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