]> git.saurik.com Git - wxWidgets.git/blame - src/common/tbarbase.cpp
add more virtual border drawing functions used by frame decorations code
[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
e76c0b5f
VZ
126wxToolBarToolBase *wxToolBarBase::DoAddTool(int id,
127 const wxString& label,
128 const wxBitmap& bitmap,
129 const wxBitmap& bmpDisabled,
130 wxItemKind kind,
131 const wxString& shortHelp,
132 const wxString& longHelp,
133 wxObject *clientData,
134 wxCoord WXUNUSED(xPos),
135 wxCoord WXUNUSED(yPos))
10b959e3 136{
9f884528 137 InvalidateBestSize();
e76c0b5f
VZ
138 return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled,
139 kind, shortHelp, longHelp, clientData);
10b959e3
JS
140}
141
8a0681f9
VZ
142wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos,
143 int id,
e76c0b5f 144 const wxString& label,
8a0681f9 145 const wxBitmap& bitmap,
e76c0b5f
VZ
146 const wxBitmap& bmpDisabled,
147 wxItemKind kind,
148 const wxString& shortHelp,
149 const wxString& longHelp,
150 wxObject *clientData)
10b959e3 151{
8a0681f9
VZ
152 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
153 _T("invalid position in wxToolBar::InsertTool()") );
154
e76c0b5f
VZ
155 wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind,
156 clientData, shortHelp, longHelp);
8a0681f9 157
dd91da4e 158 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
159 {
160 delete tool;
161
162 return NULL;
163 }
164
dd91da4e
VZ
165 return tool;
166}
167
168wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool)
169{
170 return InsertTool(GetToolsCount(), tool);
171}
172
173wxToolBarToolBase *
174wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool)
175{
176 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
177 _T("invalid position in wxToolBar::InsertTool()") );
178
179 if ( !tool || !DoInsertTool(pos, tool) )
180 {
181 return NULL;
182 }
183
8a0681f9
VZ
184 m_tools.Insert(pos, tool);
185
186 return tool;
10b959e3
JS
187}
188
8a0681f9 189wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control)
10b959e3 190{
8a0681f9 191 return InsertControl(GetToolsCount(), control);
10b959e3
JS
192}
193
8a0681f9 194wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control)
10b959e3 195{
8a0681f9
VZ
196 wxCHECK_MSG( control, (wxToolBarToolBase *)NULL,
197 _T("toolbar: can't insert NULL control") );
198
199 wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL,
200 _T("control must have toolbar as parent") );
201
202 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
203 _T("invalid position in wxToolBar::InsertControl()") );
204
205 wxToolBarToolBase *tool = CreateTool(control);
206
dd91da4e 207 if ( !InsertTool(pos, tool) )
8a0681f9
VZ
208 {
209 delete tool;
210
211 return NULL;
212 }
213
8a0681f9 214 return tool;
10b959e3
JS
215}
216
fba2d5e6
RR
217wxControl *wxToolBarBase::FindControl( int id )
218{
222ed1d6 219 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
fba2d5e6
RR
220 node;
221 node = node->GetNext() )
222 {
652ab153
VZ
223 const wxToolBarToolBase * const tool = node->GetData();
224 if ( tool->IsControl() )
fba2d5e6 225 {
652ab153
VZ
226 wxControl * const control = tool->GetControl();
227
228 if ( !control )
229 {
230 wxFAIL_MSG( _T("NULL control in toolbar?") );
231 }
232 else if ( control->GetId() == id )
233 {
234 // found
fba2d5e6 235 return control;
652ab153 236 }
fba2d5e6
RR
237 }
238 }
239
240 return NULL;
241}
242
8a0681f9 243wxToolBarToolBase *wxToolBarBase::AddSeparator()
10b959e3 244{
8a0681f9 245 return InsertSeparator(GetToolsCount());
10b959e3
JS
246}
247
8a0681f9 248wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos)
10b959e3 249{
8a0681f9
VZ
250 wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
251 _T("invalid position in wxToolBar::InsertSeparator()") );
252
253 wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR,
e76c0b5f 254 wxEmptyString,
8a0681f9 255 wxNullBitmap, wxNullBitmap,
e76c0b5f 256 wxITEM_SEPARATOR, (wxObject *)NULL,
8a0681f9
VZ
257 wxEmptyString, wxEmptyString);
258
259 if ( !tool || !DoInsertTool(pos, tool) )
10b959e3 260 {
8a0681f9
VZ
261 delete tool;
262
263 return NULL;
10b959e3 264 }
8a0681f9
VZ
265
266 m_tools.Insert(pos, tool);
267
268 return tool;
10b959e3
JS
269}
270
8a0681f9 271wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)
10b959e3 272{
8a0681f9 273 size_t pos = 0;
222ed1d6 274 wxToolBarToolsList::compatibility_iterator node;
8a0681f9 275 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
10b959e3 276 {
8a0681f9
VZ
277 if ( node->GetData()->GetId() == id )
278 break;
279
280 pos++;
10b959e3 281 }
10b959e3 282
8a0681f9 283 if ( !node )
10b959e3 284 {
8a0681f9
VZ
285 // don't give any error messages - sometimes we might call RemoveTool()
286 // without knowing whether the tool is or not in the toolbar
287 return (wxToolBarToolBase *)NULL;
10b959e3 288 }
10b959e3 289
8a0681f9
VZ
290 wxToolBarToolBase *tool = node->GetData();
291 if ( !DoDeleteTool(pos, tool) )
292 {
293 return (wxToolBarToolBase *)NULL;
294 }
10b959e3 295
222ed1d6 296 m_tools.Erase(node);
10b959e3 297
8a0681f9 298 return tool;
10b959e3
JS
299}
300
8a0681f9 301bool wxToolBarBase::DeleteToolByPos(size_t pos)
10b959e3 302{
331c9f56 303 wxCHECK_MSG( pos < GetToolsCount(), false,
8a0681f9 304 _T("invalid position in wxToolBar::DeleteToolByPos()") );
10b959e3 305
222ed1d6 306 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
10b959e3 307
8a0681f9
VZ
308 if ( !DoDeleteTool(pos, node->GetData()) )
309 {
331c9f56 310 return false;
8a0681f9
VZ
311 }
312
222ed1d6
MB
313 delete node->GetData();
314 m_tools.Erase(node);
8a0681f9 315
331c9f56 316 return true;
10b959e3
JS
317}
318
8a0681f9 319bool wxToolBarBase::DeleteTool(int id)
10b959e3 320{
8a0681f9 321 size_t pos = 0;
222ed1d6 322 wxToolBarToolsList::compatibility_iterator node;
8a0681f9
VZ
323 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
324 {
325 if ( node->GetData()->GetId() == id )
326 break;
327
328 pos++;
329 }
330
331 if ( !node || !DoDeleteTool(pos, node->GetData()) )
332 {
331c9f56 333 return false;
8a0681f9
VZ
334 }
335
222ed1d6
MB
336 delete node->GetData();
337 m_tools.Erase(node);
8a0681f9 338
331c9f56 339 return true;
10b959e3
JS
340}
341
8a0681f9 342wxToolBarToolBase *wxToolBarBase::FindById(int id) const
10b959e3 343{
8a0681f9
VZ
344 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
345
222ed1d6 346 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
347 node;
348 node = node->GetNext() )
349 {
350 tool = node->GetData();
351 if ( tool->GetId() == id )
352 {
353 // found
354 break;
355 }
d9739886
VZ
356
357 tool = NULL;
8a0681f9
VZ
358 }
359
360 return tool;
10b959e3
JS
361}
362
331c9f56
VZ
363void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool)
364{
365 wxCHECK_RET( tool, _T("NULL tool in wxToolBarTool::UnToggleRadioGroup") );
366
367 if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO )
368 return;
369
370 wxToolBarToolsList::compatibility_iterator node = m_tools.Find(tool);
371 wxCHECK_RET( node, _T("invalid tool in wxToolBarTool::UnToggleRadioGroup") );
372
373 wxToolBarToolsList::compatibility_iterator nodeNext = node->GetNext();
374 while ( nodeNext )
375 {
4e115ed2 376 wxToolBarToolBase *toolNext = nodeNext->GetData();
331c9f56 377
4e115ed2 378 if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO )
331c9f56
VZ
379 break;
380
4e115ed2 381 if ( toolNext->Toggle(false) )
214b9484 382 {
4e115ed2 383 DoToggleTool(toolNext, false);
214b9484 384 }
331c9f56
VZ
385
386 nodeNext = nodeNext->GetNext();
387 }
388
389 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
390 while ( nodePrev )
391 {
4e115ed2 392 wxToolBarToolBase *toolNext = nodePrev->GetData();
331c9f56 393
4e115ed2 394 if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO )
331c9f56
VZ
395 break;
396
4e115ed2 397 if ( toolNext->Toggle(false) )
214b9484 398 {
4e115ed2 399 DoToggleTool(toolNext, false);
214b9484 400 }
331c9f56
VZ
401
402 nodePrev = nodePrev->GetPrevious();
403 }
404}
405
8a0681f9 406void wxToolBarBase::ClearTools()
10b959e3 407{
a3e9caa2
RD
408 while ( GetToolsCount() )
409 {
410 DeleteToolByPos(0);
411 }
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
b2e3be1c 425 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2ab82214
VZ
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 541 wxToolBarToolBase *tool = FindById(id);
525d8583 542 wxCHECK_MSG( tool, wxEmptyString, _T("no such tool") );
8a0681f9
VZ
543
544 return tool->GetShortHelp();
10b959e3
JS
545}
546
8a0681f9 547wxString wxToolBarBase::GetToolLongHelp(int id) const
10b959e3 548{
8a0681f9 549 wxToolBarToolBase *tool = FindById(id);
525d8583 550 wxCHECK_MSG( tool, wxEmptyString, _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
434c6c9f 668#if wxUSE_IMAGE
c229e50d
JS
669
670/*
671 * Make a greyed-out image suitable for disabled buttons.
672 * This code is adapted from wxNewBitmapButton in FL.
673 */
674
434c6c9f 675bool wxCreateGreyedImage(const wxImage& src, wxImage& dst)
c229e50d 676{
434c6c9f 677 dst = src.Copy();
c229e50d 678
434c6c9f
VZ
679 unsigned char rBg, gBg, bBg;
680 if ( src.HasMask() )
062b84dd 681 {
434c6c9f
VZ
682 src.GetOrFindMaskColour(&rBg, &gBg, &bBg);
683 dst.SetMaskColour(rBg, gBg, bBg);
062b84dd
VZ
684 }
685 else // assuming the pixels along the edges are of the background color
686 {
434c6c9f
VZ
687 rBg = src.GetRed(0, 0);
688 gBg = src.GetGreen(0, 0);
689 bBg = src.GetBlue(0, 0);
062b84dd
VZ
690 }
691
434c6c9f 692 const wxColour colBg(rBg, gBg, bBg);
c229e50d 693
434c6c9f
VZ
694 const wxColour colDark = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
695 const wxColour colLight = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
c229e50d 696
434c6c9f
VZ
697 // Second attempt, just making things monochrome
698 const int width = src.GetWidth();
699 const int height = src.GetHeight();
700
701 for ( int x = 0; x < width; x++ )
702 {
703 for ( int y = 0; y < height; y++ )
704 {
705 const int r = src.GetRed(x, y);
706 const int g = src.GetGreen(x, y);
707 const int b = src.GetBlue(x, y);
708
709 if ( r == rBg && g == gBg && b == bBg )
710 {
711 // Leave the background colour as-is
712 continue;
713 }
714
715 // Change light things to the background colour
716 wxColour col;
717 if ( r >= (colLight.Red() - 50) &&
718 g >= (colLight.Green() - 50) &&
719 b >= (colLight.Blue() - 50) )
720 {
721 col = colBg;
722 }
723 else // Change dark things to really dark
724 {
725 col = colDark;
726 }
727
728 dst.SetRGB(x, y, col.Red(), col.Green(), col.Blue());
729 }
730 }
c229e50d 731
331c9f56 732 return true;
c229e50d
JS
733}
734
434c6c9f
VZ
735#endif // wxUSE_IMAGE
736
8a0681f9 737#endif // wxUSE_TOOLBAR