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