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