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