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