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