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