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