]> git.saurik.com Git - wxWidgets.git/blob - src/msw/tbar95.cpp
fixup authorship
[wxWidgets.git] / src / msw / tbar95.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/tbar95.cpp
3 // Purpose: wxToolBar
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "tbar95.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/dynarray.h"
36 #include "wx/settings.h"
37 #include "wx/bitmap.h"
38 #include "wx/dcmemory.h"
39 #include "wx/control.h"
40 #endif
41
42 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
43
44 #include "wx/toolbar.h"
45 #include "wx/sysopt.h"
46
47 #include "wx/msw/private.h"
48
49 #if wxUSE_UXTHEME
50 #include "wx/msw/uxtheme.h"
51 #endif
52
53 // include <commctrl.h> "properly"
54 #include "wx/msw/wrapcctl.h"
55
56 #include "wx/app.h" // for GetComCtl32Version
57
58 // ----------------------------------------------------------------------------
59 // constants
60 // ----------------------------------------------------------------------------
61
62 // these standard constants are not always defined in compilers headers
63
64 // Styles
65 #ifndef TBSTYLE_FLAT
66 #define TBSTYLE_LIST 0x1000
67 #define TBSTYLE_FLAT 0x0800
68 #endif
69
70 #ifndef TBSTYLE_TRANSPARENT
71 #define TBSTYLE_TRANSPARENT 0x8000
72 #endif
73
74 #ifndef TBSTYLE_TOOLTIPS
75 #define TBSTYLE_TOOLTIPS 0x0100
76 #endif
77
78 // Messages
79 #ifndef TB_GETSTYLE
80 #define TB_SETSTYLE (WM_USER + 56)
81 #define TB_GETSTYLE (WM_USER + 57)
82 #endif
83
84 #ifndef TB_HITTEST
85 #define TB_HITTEST (WM_USER + 69)
86 #endif
87
88 // these values correspond to those used by comctl32.dll
89 #define DEFAULTBITMAPX 16
90 #define DEFAULTBITMAPY 15
91 #define DEFAULTBUTTONX 24
92 #define DEFAULTBUTTONY 24
93 #define DEFAULTBARHEIGHT 27
94
95 // ----------------------------------------------------------------------------
96 // wxWin macros
97 // ----------------------------------------------------------------------------
98
99 IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
100
101 /*
102 TOOLBAR PROPERTIES
103 tool
104 bitmap
105 bitmap2
106 tooltip
107 longhelp
108 radio (bool)
109 toggle (bool)
110 separator
111 style ( wxNO_BORDER | wxTB_HORIZONTAL)
112 bitmapsize
113 margins
114 packing
115 separation
116
117 dontattachtoframe
118 */
119
120 BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
121 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
122 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged)
123 END_EVENT_TABLE()
124
125 // ----------------------------------------------------------------------------
126 // private classes
127 // ----------------------------------------------------------------------------
128
129 class wxToolBarTool : public wxToolBarToolBase
130 {
131 public:
132 wxToolBarTool(wxToolBar *tbar,
133 int id,
134 const wxString& label,
135 const wxBitmap& bmpNormal,
136 const wxBitmap& bmpDisabled,
137 wxItemKind kind,
138 wxObject *clientData,
139 const wxString& shortHelp,
140 const wxString& longHelp)
141 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
142 clientData, shortHelp, longHelp)
143 {
144 m_nSepCount = 0;
145 }
146
147 wxToolBarTool(wxToolBar *tbar, wxControl *control)
148 : wxToolBarToolBase(tbar, control)
149 {
150 m_nSepCount = 1;
151 }
152
153 virtual void SetLabel(const wxString& label)
154 {
155 if ( label == m_label )
156 return;
157
158 wxToolBarToolBase::SetLabel(label);
159
160 // we need to update the label shown in the toolbar because it has a
161 // pointer to the internal buffer of the old label
162 //
163 // TODO: use TB_SETBUTTONINFO
164 }
165
166 // set/get the number of separators which we use to cover the space used by
167 // a control in the toolbar
168 void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
169 size_t GetSeparatorsCount() const { return m_nSepCount; }
170
171 private:
172 size_t m_nSepCount;
173
174 DECLARE_NO_COPY_CLASS(wxToolBarTool)
175 };
176
177
178 // ============================================================================
179 // implementation
180 // ============================================================================
181
182 // ----------------------------------------------------------------------------
183 // wxToolBarTool
184 // ----------------------------------------------------------------------------
185
186 wxToolBarToolBase *wxToolBar::CreateTool(int id,
187 const wxString& label,
188 const wxBitmap& bmpNormal,
189 const wxBitmap& bmpDisabled,
190 wxItemKind kind,
191 wxObject *clientData,
192 const wxString& shortHelp,
193 const wxString& longHelp)
194 {
195 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
196 clientData, shortHelp, longHelp);
197 }
198
199 wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
200 {
201 return new wxToolBarTool(this, control);
202 }
203
204 // ----------------------------------------------------------------------------
205 // wxToolBar construction
206 // ----------------------------------------------------------------------------
207
208 void wxToolBar::Init()
209 {
210 m_hBitmap = 0;
211
212 m_nButtons = 0;
213
214 m_defaultWidth = DEFAULTBITMAPX;
215 m_defaultHeight = DEFAULTBITMAPY;
216
217 m_pInTool = 0;
218 }
219
220 bool wxToolBar::Create(wxWindow *parent,
221 wxWindowID id,
222 const wxPoint& pos,
223 const wxSize& size,
224 long style,
225 const wxString& name)
226 {
227 // common initialisation
228 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
229 return false;
230
231 // MSW-specific initialisation
232 if ( !MSWCreateToolbar(pos, size) )
233 return false;
234
235 wxSetCCUnicodeFormat(GetHwnd());
236
237 // set up the colors and fonts
238 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
239 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
240
241 // workaround for flat toolbar on Windows XP classic style
242 #if wxUSE_UXTHEME
243 if ( style & wxTB_FLAT )
244 {
245 wxUxThemeEngine *p = wxUxThemeEngine::Get();
246 if ( !p || !p->IsThemeActive() )
247 {
248 DWORD dwToolbarStyle;
249
250 dwToolbarStyle = (DWORD)::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L );
251
252 if ((dwToolbarStyle & TBSTYLE_FLAT) == 0)
253 {
254 dwToolbarStyle |= TBSTYLE_FLAT;
255 ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, (LPARAM)dwToolbarStyle );
256 }
257 }
258 }
259 #endif
260
261 return true;
262 }
263
264 bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size)
265 {
266 if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, size) )
267 return false;
268
269 // toolbar-specific post initialisation
270 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
271
272 return true;
273 }
274
275 void wxToolBar::Recreate()
276 {
277 const HWND hwndOld = GetHwnd();
278 if ( !hwndOld )
279 {
280 // we haven't been created yet, no need to recreate
281 return;
282 }
283
284 // get the position and size before unsubclassing the old toolbar
285 const wxPoint pos = GetPosition();
286 const wxSize size = GetSize();
287
288 UnsubclassWin();
289
290 if ( !MSWCreateToolbar(pos, size) )
291 {
292 // what can we do?
293 wxFAIL_MSG( _T("recreating the toolbar failed") );
294
295 return;
296 }
297
298 // reparent all our children under the new toolbar
299 for ( wxWindowList::compatibility_iterator node = m_children.GetFirst();
300 node;
301 node = node->GetNext() )
302 {
303 wxWindow *win = node->GetData();
304 if ( !win->IsTopLevel() )
305 ::SetParent(GetHwndOf(win), GetHwnd());
306 }
307
308 // only destroy the old toolbar now -- after all the children had been
309 // reparented
310 ::DestroyWindow(hwndOld);
311
312 // it is for the old bitmap control and can't be used with the new one
313 if ( m_hBitmap )
314 {
315 ::DeleteObject((HBITMAP) m_hBitmap);
316 m_hBitmap = 0;
317 }
318
319 Realize();
320 UpdateSize();
321 }
322
323 wxToolBar::~wxToolBar()
324 {
325 // we must refresh the frame size when the toolbar is deleted but the frame
326 // is not - otherwise toolbar leaves a hole in the place it used to occupy
327 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
328 if ( frame && !frame->IsBeingDeleted() )
329 {
330 frame->SendSizeEvent();
331 }
332
333 if ( m_hBitmap )
334 {
335 ::DeleteObject((HBITMAP) m_hBitmap);
336 }
337 }
338
339 wxSize wxToolBar::DoGetBestSize() const
340 {
341 wxSize sizeBest = GetToolSize();
342 sizeBest.x *= GetToolsCount();
343
344 // reverse horz and vertical components if necessary
345 return HasFlag(wxTB_VERTICAL) ? wxSize(sizeBest.y, sizeBest.x) : sizeBest;
346 }
347
348 WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const
349 {
350 // toolbars never have border, giving one to them results in broken
351 // appearance
352 WXDWORD msStyle = wxControl::MSWGetStyle
353 (
354 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
355 );
356
357 // always include this one, it never hurts and setting it later only if we
358 // do have tooltips wouldn't work
359 msStyle |= TBSTYLE_TOOLTIPS;
360
361 if ( style & (wxTB_FLAT | wxTB_HORZ_LAYOUT) )
362 {
363 // static as it doesn't change during the program lifetime
364 static int s_verComCtl = wxTheApp->GetComCtl32Version();
365
366 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
367 // style with 6.00 (part of Windows XP) leads to the toolbar with
368 // incorrect background colour - and not using it still results in the
369 // correct (flat) toolbar, so don't use it there
370 if ( s_verComCtl > 400 && s_verComCtl < 600 )
371 {
372 msStyle |= TBSTYLE_FLAT | TBSTYLE_TRANSPARENT;
373 }
374
375 if ( s_verComCtl >= 470 && style & wxTB_HORZ_LAYOUT )
376 {
377 msStyle |= TBSTYLE_LIST;
378 }
379 }
380
381 if ( style & wxTB_NODIVIDER )
382 msStyle |= CCS_NODIVIDER;
383
384 if ( style & wxTB_NOALIGN )
385 msStyle |= CCS_NOPARENTALIGN;
386
387 if ( style & wxTB_VERTICAL )
388 msStyle |= CCS_VERT;
389
390 return msStyle;
391 }
392
393 // ----------------------------------------------------------------------------
394 // adding/removing tools
395 // ----------------------------------------------------------------------------
396
397 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
398 {
399 // nothing special to do here - we really create the toolbar buttons in
400 // Realize() later
401 tool->Attach(this);
402
403 InvalidateBestSize();
404 return true;
405 }
406
407 bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
408 {
409 // the main difficulty we have here is with the controls in the toolbars:
410 // as we (sometimes) use several separators to cover up the space used by
411 // them, the indices are not the same for us and the toolbar
412
413 // first determine the position of the first button to delete: it may be
414 // different from pos if we use several separators to cover the space used
415 // by a control
416 wxToolBarToolsList::compatibility_iterator node;
417 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
418 {
419 wxToolBarToolBase *tool2 = node->GetData();
420 if ( tool2 == tool )
421 {
422 // let node point to the next node in the list
423 node = node->GetNext();
424
425 break;
426 }
427
428 if ( tool2->IsControl() )
429 {
430 pos += ((wxToolBarTool *)tool2)->GetSeparatorsCount() - 1;
431 }
432 }
433
434 // now determine the number of buttons to delete and the area taken by them
435 size_t nButtonsToDelete = 1;
436
437 // get the size of the button we're going to delete
438 RECT r;
439 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) )
440 {
441 wxLogLastError(_T("TB_GETITEMRECT"));
442 }
443
444 int width = r.right - r.left;
445
446 if ( tool->IsControl() )
447 {
448 nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount();
449
450 width *= nButtonsToDelete;
451 }
452
453 // do delete all buttons
454 m_nButtons -= nButtonsToDelete;
455 while ( nButtonsToDelete-- > 0 )
456 {
457 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) )
458 {
459 wxLogLastError(wxT("TB_DELETEBUTTON"));
460
461 return false;
462 }
463 }
464
465 tool->Detach();
466
467 // and finally reposition all the controls after this button (the toolbar
468 // takes care of all normal items)
469 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
470 {
471 wxToolBarToolBase *tool2 = node->GetData();
472 if ( tool2->IsControl() )
473 {
474 int x;
475 wxControl *control = tool2->GetControl();
476 control->GetPosition(&x, NULL);
477 control->Move(x - width, wxDefaultCoord);
478 }
479 }
480
481 InvalidateBestSize();
482 return true;
483 }
484
485 bool wxToolBar::Realize()
486 {
487 const size_t nTools = GetToolsCount();
488 if ( nTools == 0 )
489 {
490 // nothing to do
491 return true;
492 }
493
494 const bool isVertical = HasFlag(wxTB_VERTICAL);
495
496 bool doRemap, doRemapBg, doTransparent;
497 if (wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 2)
498 {
499 doRemapBg = doRemap = false;
500 doTransparent = true;
501 }
502 else
503 { doRemap = !wxSystemOptions::HasOption(wxT("msw.remap"))
504 || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1;
505 doRemapBg = !doRemap;
506 doTransparent = false;
507 }
508
509 // delete all old buttons, if any
510 for ( size_t pos = 0; pos < m_nButtons; pos++ )
511 {
512 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
513 {
514 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
515 }
516 }
517
518 // First, add the bitmap: we use one bitmap for all toolbar buttons
519 // ----------------------------------------------------------------
520
521 wxToolBarToolsList::compatibility_iterator node;
522 int bitmapId = 0;
523
524 wxSize sizeBmp;
525 if ( HasFlag(wxTB_NOICONS) )
526 {
527 // no icons, don't leave space for them
528 sizeBmp.x =
529 sizeBmp.y = 0;
530 }
531 else // do show icons
532 {
533 // if we already have a bitmap, we'll replace the existing one --
534 // otherwise we'll install a new one
535 HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap;
536
537 sizeBmp.x = m_defaultWidth;
538 sizeBmp.y = m_defaultHeight;
539
540 const wxCoord totalBitmapWidth = m_defaultWidth * nTools,
541 totalBitmapHeight = m_defaultHeight;
542
543 // Create a bitmap and copy all the tool bitmaps to it
544 wxMemoryDC dcAllButtons;
545 wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
546 dcAllButtons.SelectObject(bitmap);
547 if (doTransparent)
548 dcAllButtons.SetBackground(*wxTRANSPARENT_BRUSH);
549 else
550 dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH);
551 dcAllButtons.Clear();
552
553 m_hBitmap = bitmap.GetHBITMAP();
554 HBITMAP hBitmap = (HBITMAP)m_hBitmap;
555
556 if (doRemapBg)
557 {
558 dcAllButtons.SelectObject(wxNullBitmap);
559
560 // Even if we're not remapping the bitmap
561 // content, we still have to remap the background.
562 hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
563 totalBitmapWidth, totalBitmapHeight);
564
565 dcAllButtons.SelectObject(bitmap);
566 }
567
568 // the button position
569 wxCoord x = 0;
570
571 // the number of buttons (not separators)
572 int nButtons = 0;
573
574 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
575 {
576 wxToolBarToolBase *tool = node->GetData();
577 if ( tool->IsButton() )
578 {
579 const wxBitmap& bmp = tool->GetNormalBitmap();
580 if ( bmp.Ok() )
581 {
582 int xOffset = wxMax(0, (m_defaultWidth - bmp.GetWidth())/2);
583 int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2);
584 // notice the last parameter: do use mask
585 dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, true);
586 }
587 else
588 {
589 wxFAIL_MSG( _T("invalid tool button bitmap") );
590 }
591
592 // still inc width and number of buttons because otherwise the
593 // subsequent buttons will all be shifted which is rather confusing
594 // (and like this you'd see immediately which bitmap was bad)
595 x += m_defaultWidth;
596 nButtons++;
597 }
598 }
599
600 dcAllButtons.SelectObject(wxNullBitmap);
601
602 // don't delete this HBITMAP!
603 bitmap.SetHBITMAP(0);
604
605 if (doRemap)
606 {
607 // Map to system colours
608 hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
609 totalBitmapWidth, totalBitmapHeight);
610 }
611
612 bool addBitmap = true;
613
614 if ( oldToolBarBitmap )
615 {
616 #ifdef TB_REPLACEBITMAP
617 if ( wxTheApp->GetComCtl32Version() >= 400 )
618 {
619 TBREPLACEBITMAP replaceBitmap;
620 replaceBitmap.hInstOld = NULL;
621 replaceBitmap.hInstNew = NULL;
622 replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
623 replaceBitmap.nIDNew = (UINT) hBitmap;
624 replaceBitmap.nButtons = nButtons;
625 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
626 0, (LPARAM) &replaceBitmap) )
627 {
628 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
629 }
630
631 ::DeleteObject(oldToolBarBitmap);
632
633 // already done
634 addBitmap = false;
635 }
636 else
637 #endif // TB_REPLACEBITMAP
638 {
639 // we can't replace the old bitmap, so we will add another one
640 // (awfully inefficient, but what else to do?) and shift the bitmap
641 // indices accordingly
642 addBitmap = true;
643
644 bitmapId = m_nButtons;
645 }
646 }
647
648 if ( addBitmap ) // no old bitmap or we can't replace it
649 {
650 TBADDBITMAP addBitmap;
651 addBitmap.hInst = 0;
652 addBitmap.nID = (UINT) hBitmap;
653 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
654 (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
655 {
656 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
657 }
658 }
659 }
660
661 // don't call SetToolBitmapSize() as we don't want to change the values of
662 // m_defaultWidth/Height
663 if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0,
664 MAKELONG(sizeBmp.x, sizeBmp.y)) )
665 {
666 wxLogLastError(_T("TB_SETBITMAPSIZE"));
667 }
668
669 // Next add the buttons and separators
670 // -----------------------------------
671
672 TBBUTTON *buttons = new TBBUTTON[nTools];
673
674 // this array will hold the indices of all controls in the toolbar
675 wxArrayInt controlIds;
676
677 bool lastWasRadio = false;
678 int i = 0;
679 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
680 {
681 wxToolBarToolBase *tool = node->GetData();
682
683 // don't add separators to the vertical toolbar with old comctl32.dll
684 // versions as they didn't handle this properly
685 if ( isVertical && tool->IsSeparator() &&
686 wxTheApp->GetComCtl32Version() <= 472 )
687 {
688 continue;
689 }
690
691
692 TBBUTTON& button = buttons[i];
693
694 wxZeroMemory(button);
695
696 bool isRadio = false;
697 switch ( tool->GetStyle() )
698 {
699 case wxTOOL_STYLE_CONTROL:
700 button.idCommand = tool->GetId();
701 // fall through: create just a separator too
702
703 case wxTOOL_STYLE_SEPARATOR:
704 button.fsState = TBSTATE_ENABLED;
705 button.fsStyle = TBSTYLE_SEP;
706 break;
707
708 case wxTOOL_STYLE_BUTTON:
709 if ( !HasFlag(wxTB_NOICONS) )
710 button.iBitmap = bitmapId;
711
712 if ( HasFlag(wxTB_TEXT) )
713 {
714 const wxString& label = tool->GetLabel();
715 if ( !label.empty() )
716 {
717 button.iString = (int)label.c_str();
718 }
719 }
720
721 button.idCommand = tool->GetId();
722
723 if ( tool->IsEnabled() )
724 button.fsState |= TBSTATE_ENABLED;
725 if ( tool->IsToggled() )
726 button.fsState |= TBSTATE_CHECKED;
727
728 switch ( tool->GetKind() )
729 {
730 case wxITEM_RADIO:
731 button.fsStyle = TBSTYLE_CHECKGROUP;
732
733 if ( !lastWasRadio )
734 {
735 // the first item in the radio group is checked by
736 // default to be consistent with wxGTK and the menu
737 // radio items
738 button.fsState |= TBSTATE_CHECKED;
739
740 tool->Toggle(true);
741 }
742
743 isRadio = true;
744 break;
745
746 case wxITEM_CHECK:
747 button.fsStyle = TBSTYLE_CHECK;
748 break;
749
750 default:
751 wxFAIL_MSG( _T("unexpected toolbar button kind") );
752 // fall through
753
754 case wxITEM_NORMAL:
755 button.fsStyle = TBSTYLE_BUTTON;
756 }
757
758 bitmapId++;
759 break;
760 }
761
762 lastWasRadio = isRadio;
763
764 i++;
765 }
766
767 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS, (WPARAM)i, (LPARAM)buttons) )
768 {
769 wxLogLastError(wxT("TB_ADDBUTTONS"));
770 }
771
772 delete [] buttons;
773
774 // Deal with the controls finally
775 // ------------------------------
776
777 // adjust the controls size to fit nicely in the toolbar
778 int y = 0;
779 size_t index = 0;
780 for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
781 {
782 wxToolBarToolBase *tool = node->GetData();
783
784 // we calculate the running y coord for vertical toolbars so we need to
785 // get the items size for all items but for the horizontal ones we
786 // don't need to deal with the non controls
787 bool isControl = tool->IsControl();
788 if ( !isControl && !isVertical )
789 continue;
790
791 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
792 // latter only appeared in v4.70 of comctl32.dll
793 RECT r;
794 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT,
795 index, (LPARAM)(LPRECT)&r) )
796 {
797 wxLogLastError(wxT("TB_GETITEMRECT"));
798 }
799
800 if ( !isControl )
801 {
802 // can only be control if isVertical
803 y += r.bottom - r.top;
804
805 continue;
806 }
807
808 wxControl *control = tool->GetControl();
809
810 wxSize size = control->GetSize();
811
812 // the position of the leftmost controls corner
813 int left = wxDefaultCoord;
814
815 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
816 #ifdef TB_SETBUTTONINFO
817 // available in headers, now check whether it is available now
818 // (during run-time)
819 if ( wxTheApp->GetComCtl32Version() >= 471 )
820 {
821 // set the (underlying) separators width to be that of the
822 // control
823 TBBUTTONINFO tbbi;
824 tbbi.cbSize = sizeof(tbbi);
825 tbbi.dwMask = TBIF_SIZE;
826 tbbi.cx = (WORD)size.x;
827 if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO,
828 tool->GetId(), (LPARAM)&tbbi) )
829 {
830 // the id is probably invalid?
831 wxLogLastError(wxT("TB_SETBUTTONINFO"));
832 }
833 }
834 else
835 #endif // comctl32.dll 4.71
836 // TB_SETBUTTONINFO unavailable
837 {
838 // try adding several separators to fit the controls width
839 int widthSep = r.right - r.left;
840 left = r.left;
841
842 TBBUTTON tbb;
843 wxZeroMemory(tbb);
844 tbb.idCommand = 0;
845 tbb.fsState = TBSTATE_ENABLED;
846 tbb.fsStyle = TBSTYLE_SEP;
847
848 size_t nSeparators = size.x / widthSep;
849 for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
850 {
851 if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON,
852 index, (LPARAM)&tbb) )
853 {
854 wxLogLastError(wxT("TB_INSERTBUTTON"));
855 }
856
857 index++;
858 }
859
860 // remember the number of separators we used - we'd have to
861 // delete all of them later
862 ((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
863
864 // adjust the controls width to exactly cover the separators
865 control->SetSize((nSeparators + 1)*widthSep, wxDefaultCoord);
866 }
867
868 // position the control itself correctly vertically
869 int height = r.bottom - r.top;
870 int diff = height - size.y;
871 if ( diff < 0 )
872 {
873 // the control is too high, resize to fit
874 control->SetSize(wxDefaultCoord, height - 2);
875
876 diff = 2;
877 }
878
879 int top;
880 if ( isVertical )
881 {
882 left = 0;
883 top = y;
884
885 y += height + 2*GetMargins().y;
886 }
887 else // horizontal toolbar
888 {
889 if ( left == wxDefaultCoord )
890 left = r.left;
891
892 top = r.top;
893 }
894
895 control->Move(left, top + (diff + 1) / 2);
896 }
897
898 // the max index is the "real" number of buttons - i.e. counting even the
899 // separators which we added just for aligning the controls
900 m_nButtons = index;
901
902 if ( !isVertical )
903 {
904 if ( m_maxRows == 0 )
905 {
906 // if not set yet, only one row
907 SetRows(1);
908 }
909 }
910 else if ( m_nButtons > 0 ) // vertical non empty toolbar
911 {
912 if ( m_maxRows == 0 )
913 {
914 // if not set yet, have one column
915 SetRows(m_nButtons);
916 }
917 }
918
919 InvalidateBestSize();
920 return true;
921 }
922
923 // ----------------------------------------------------------------------------
924 // message handlers
925 // ----------------------------------------------------------------------------
926
927 bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id)
928 {
929 wxToolBarToolBase *tool = FindById((int)id);
930 if ( !tool )
931 return false;
932
933 bool toggled = false; // just to suppress warnings
934
935 if ( tool->CanBeToggled() )
936 {
937 LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
938 toggled = (state & TBSTATE_CHECKED) != 0;
939
940 // ignore the event when a radio button is released, as this doesn't seem to
941 // happen at all, and is handled otherwise
942 if ( tool->GetKind() == wxITEM_RADIO && !toggled )
943 return true;
944
945 tool->Toggle(toggled);
946 UnToggleRadioGroup(tool);
947 }
948
949 // OnLeftClick() can veto the button state change - for buttons which
950 // may be toggled only, of couse
951 if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() )
952 {
953 // revert back
954 tool->Toggle(!toggled);
955
956 ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
957 }
958
959 return true;
960 }
961
962 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
963 WXLPARAM lParam,
964 WXLPARAM *WXUNUSED(result))
965 {
966 #if wxUSE_TOOLTIPS
967 // First check if this applies to us
968 NMHDR *hdr = (NMHDR *)lParam;
969
970 // the tooltips control created by the toolbar is sometimes Unicode, even
971 // in an ANSI application - this seems to be a bug in comctl32.dll v5
972 UINT code = hdr->code;
973 if ( (code != (UINT) TTN_NEEDTEXTA) && (code != (UINT) TTN_NEEDTEXTW) )
974 return false;
975
976 HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
977 if ( toolTipWnd != hdr->hwndFrom )
978 return false;
979
980 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
981 int id = (int)ttText->hdr.idFrom;
982
983 wxToolBarToolBase *tool = FindById(id);
984 if ( !tool )
985 return false;
986
987 return HandleTooltipNotify(code, lParam, tool->GetShortHelp());
988 #else
989 return false;
990 #endif
991 }
992
993 // ----------------------------------------------------------------------------
994 // toolbar geometry
995 // ----------------------------------------------------------------------------
996
997 void wxToolBar::SetToolBitmapSize(const wxSize& size)
998 {
999 wxToolBarBase::SetToolBitmapSize(size);
1000
1001 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
1002 }
1003
1004 void wxToolBar::SetRows(int nRows)
1005 {
1006 if ( nRows == m_maxRows )
1007 {
1008 // avoid resizing the frame uselessly
1009 return;
1010 }
1011
1012 // TRUE in wParam means to create at least as many rows, FALSE -
1013 // at most as many
1014 RECT rect;
1015 ::SendMessage(GetHwnd(), TB_SETROWS,
1016 MAKEWPARAM(nRows, !(GetWindowStyle() & wxTB_VERTICAL)),
1017 (LPARAM) &rect);
1018
1019 m_maxRows = nRows;
1020
1021 UpdateSize();
1022 }
1023
1024 // The button size is bigger than the bitmap size
1025 wxSize wxToolBar::GetToolSize() const
1026 {
1027 // TB_GETBUTTONSIZE is supported from version 4.70
1028 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
1029 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
1030 && !defined (__DIGITALMARS__)
1031 if ( wxTheApp->GetComCtl32Version() >= 470 )
1032 {
1033 DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0);
1034
1035 return wxSize(LOWORD(dw), HIWORD(dw));
1036 }
1037 else
1038 #endif // comctl32.dll 4.70+
1039 {
1040 // defaults
1041 return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
1042 }
1043 }
1044
1045 static
1046 wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools,
1047 size_t index )
1048 {
1049 wxToolBarToolsList::compatibility_iterator current = tools.GetFirst();
1050
1051 for ( ; current != 0; current = current->GetNext() )
1052 {
1053 if ( index == 0 )
1054 return current->GetData();
1055
1056 wxToolBarTool *tool = (wxToolBarTool *)current->GetData();
1057 size_t separators = tool->GetSeparatorsCount();
1058
1059 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
1060 // otherwise, skip as many items as the separator count, plus the
1061 // control itself
1062 index -= separators ? separators + 1 : 1;
1063 }
1064
1065 return 0;
1066 }
1067
1068 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
1069 {
1070 POINT pt;
1071 pt.x = x;
1072 pt.y = y;
1073 int index = (int)::SendMessage(GetHwnd(), TB_HITTEST, 0, (LPARAM)&pt);
1074 // MBN: when the point ( x, y ) is close to the toolbar border
1075 // TB_HITTEST returns m_nButtons ( not -1 )
1076 if ( index < 0 || (size_t)index >= m_nButtons )
1077 {
1078 // it's a separator or there is no tool at all there
1079 return (wxToolBarToolBase *)NULL;
1080 }
1081
1082 // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
1083 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
1084 if ( wxTheApp->GetComCtl32Version() >= 471 )
1085 {
1086 return m_tools.Item((size_t)index)->GetData();
1087 }
1088 else
1089 #endif
1090 {
1091 return GetItemSkippingDummySpacers( m_tools, (size_t) index );
1092 }
1093 }
1094
1095 void wxToolBar::UpdateSize()
1096 {
1097 // the toolbar size changed
1098 ::SendMessage(GetHwnd(), TB_AUTOSIZE, 0, 0);
1099
1100 // we must also refresh the frame after the toolbar size (possibly) changed
1101 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
1102 if ( frame )
1103 {
1104 frame->SendSizeEvent();
1105 }
1106 }
1107
1108 // ----------------------------------------------------------------------------
1109 // toolbar styles
1110 // ---------------------------------------------------------------------------
1111
1112 void wxToolBar::SetWindowStyleFlag(long style)
1113 {
1114 // the style bits whose changes force us to recreate the toolbar
1115 static const long MASK_NEEDS_RECREATE = wxTB_TEXT | wxTB_NOICONS;
1116
1117 const long styleOld = GetWindowStyle();
1118
1119 wxToolBarBase::SetWindowStyleFlag(style);
1120
1121 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1122 // also fatal as we'd then try to recreate the toolbar when it's just being
1123 // created
1124 if ( GetToolsCount() &&
1125 (style & MASK_NEEDS_RECREATE) != (styleOld & MASK_NEEDS_RECREATE) )
1126 {
1127 // to remove the text labels, simply re-realizing the toolbar is enough
1128 // but I don't know of any way to add the text to an existing toolbar
1129 // other than by recreating it entirely
1130 Recreate();
1131 }
1132 }
1133
1134 // ----------------------------------------------------------------------------
1135 // tool state
1136 // ----------------------------------------------------------------------------
1137
1138 void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
1139 {
1140 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
1141 (WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0));
1142 }
1143
1144 void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle)
1145 {
1146 ::SendMessage(GetHwnd(), TB_CHECKBUTTON,
1147 (WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0));
1148 }
1149
1150 void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
1151 {
1152 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1153 // without, so we really need to delete the button and recreate it here
1154 wxFAIL_MSG( _T("not implemented") );
1155 }
1156
1157 // ----------------------------------------------------------------------------
1158 // event handlers
1159 // ----------------------------------------------------------------------------
1160
1161 // Responds to colour changes, and passes event on to children.
1162 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent& event)
1163 {
1164 wxRGBToColour(m_backgroundColour, ::GetSysColor(COLOR_BTNFACE));
1165
1166 // Remap the buttons
1167 Realize();
1168
1169 // Relayout the toolbar
1170 int nrows = m_maxRows;
1171 m_maxRows = 0; // otherwise SetRows() wouldn't do anything
1172 SetRows(nrows);
1173
1174 Refresh();
1175
1176 // let the event propagate further
1177 event.Skip();
1178 }
1179
1180 void wxToolBar::OnMouseEvent(wxMouseEvent& event)
1181 {
1182 if (event.Leaving() && m_pInTool)
1183 {
1184 OnMouseEnter( -1 );
1185 event.Skip();
1186 return;
1187 }
1188
1189 if (event.RightDown())
1190 {
1191 // For now, we don't have an id. Later we could
1192 // try finding the tool.
1193 OnRightClick((int)-1, event.GetX(), event.GetY());
1194 }
1195 else
1196 {
1197 event.Skip();
1198 }
1199 }
1200
1201 bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam)
1202 {
1203 // calculate our minor dimension ourselves - we're confusing the standard
1204 // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks
1205 RECT r;
1206 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) )
1207 {
1208 int w, h;
1209
1210 if ( GetWindowStyle() & wxTB_VERTICAL )
1211 {
1212 w = r.right - r.left;
1213 if ( m_maxRows )
1214 {
1215 w *= (m_nButtons + m_maxRows - 1)/m_maxRows;
1216 }
1217 h = HIWORD(lParam);
1218 }
1219 else
1220 {
1221 w = LOWORD(lParam);
1222 if (HasFlag( wxTB_FLAT ))
1223 h = r.bottom - r.top - 3;
1224 else
1225 h = r.bottom - r.top;
1226 if ( m_maxRows )
1227 {
1228 // FIXME: hardcoded separator line height...
1229 h += HasFlag(wxTB_NODIVIDER) ? 4 : 6;
1230 h *= m_maxRows;
1231 }
1232 }
1233
1234 if ( MAKELPARAM(w, h) != lParam )
1235 {
1236 // size really changed
1237 SetSize(w, h);
1238 }
1239
1240 // message processed
1241 return true;
1242 }
1243
1244 return false;
1245 }
1246
1247 bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
1248 {
1249 // erase any dummy separators which we used for aligning the controls if
1250 // any here
1251
1252 // first of all, do we have any controls at all?
1253 wxToolBarToolsList::compatibility_iterator node;
1254 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1255 {
1256 if ( node->GetData()->IsControl() )
1257 break;
1258 }
1259
1260 if ( !node )
1261 {
1262 // no controls, nothing to erase
1263 return false;
1264 }
1265
1266 // prepare the DC on which we'll be drawing
1267 wxClientDC dc(this);
1268 dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID));
1269 dc.SetPen(*wxTRANSPARENT_PEN);
1270
1271 RECT r;
1272 if ( !::GetUpdateRect(GetHwnd(), &r, FALSE) )
1273 {
1274 // nothing to redraw anyhow
1275 return false;
1276 }
1277
1278 wxRect rectUpdate;
1279 wxCopyRECTToRect(r, rectUpdate);
1280
1281 dc.SetClippingRegion(rectUpdate);
1282
1283 // draw the toolbar tools, separators &c normally
1284 wxControl::MSWWindowProc(WM_PAINT, wParam, lParam);
1285
1286 // for each control in the toolbar find all the separators intersecting it
1287 // and erase them
1288 //
1289 // NB: this is really the only way to do it as we don't know if a separator
1290 // corresponds to a control (i.e. is a dummy one) or a real one
1291 // otherwise
1292 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1293 {
1294 wxToolBarToolBase *tool = node->GetData();
1295 if ( tool->IsControl() )
1296 {
1297 // get the control rect in our client coords
1298 wxControl *control = tool->GetControl();
1299 wxRect rectCtrl = control->GetRect();
1300
1301 // iterate over all buttons
1302 TBBUTTON tbb;
1303 int count = ::SendMessage(GetHwnd(), TB_BUTTONCOUNT, 0, 0);
1304 for ( int n = 0; n < count; n++ )
1305 {
1306 // is it a separator?
1307 if ( !::SendMessage(GetHwnd(), TB_GETBUTTON,
1308 n, (LPARAM)&tbb) )
1309 {
1310 wxLogDebug(_T("TB_GETBUTTON failed?"));
1311
1312 continue;
1313 }
1314
1315 if ( tbb.fsStyle != TBSTYLE_SEP )
1316 continue;
1317
1318 // get the bounding rect of the separator
1319 RECT r;
1320 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT,
1321 n, (LPARAM)&r) )
1322 {
1323 wxLogDebug(_T("TB_GETITEMRECT failed?"));
1324
1325 continue;
1326 }
1327
1328 // does it intersect the control?
1329 wxRect rectItem;
1330 wxCopyRECTToRect(r, rectItem);
1331 if ( rectCtrl.Intersects(rectItem) )
1332 {
1333 // yes, do erase it!
1334 dc.DrawRectangle(rectItem);
1335
1336 // Necessary in case we use a no-paint-on-size
1337 // style in the parent: the controls can disappear
1338 control->Refresh(false);
1339 }
1340 }
1341 }
1342 }
1343
1344 return true;
1345 }
1346
1347 void wxToolBar::HandleMouseMove(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam)
1348 {
1349 wxCoord x = GET_X_LPARAM(lParam),
1350 y = GET_Y_LPARAM(lParam);
1351 wxToolBarToolBase* tool = FindToolForPosition( x, y );
1352
1353 // cursor left current tool
1354 if( tool != m_pInTool && !tool )
1355 {
1356 m_pInTool = 0;
1357 OnMouseEnter( -1 );
1358 }
1359
1360 // cursor entered a tool
1361 if( tool != m_pInTool && tool )
1362 {
1363 m_pInTool = tool;
1364 OnMouseEnter( tool->GetId() );
1365 }
1366 }
1367
1368 WXLRESULT wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1369 {
1370 switch ( nMsg )
1371 {
1372 case WM_SIZE:
1373 if ( HandleSize(wParam, lParam) )
1374 return 0;
1375 break;
1376
1377 case WM_MOUSEMOVE:
1378 // we don't handle mouse moves, so always pass the message to
1379 // wxControl::MSWWindowProc
1380 HandleMouseMove(wParam, lParam);
1381 break;
1382
1383 case WM_PAINT:
1384 if ( HandlePaint(wParam, lParam) )
1385 return 0;
1386 }
1387
1388 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
1389 }
1390
1391 // ----------------------------------------------------------------------------
1392 // private functions
1393 // ----------------------------------------------------------------------------
1394
1395 WXHBITMAP wxToolBar::MapBitmap(WXHBITMAP bitmap, int width, int height)
1396 {
1397 MemoryHDC hdcMem;
1398
1399 if ( !hdcMem )
1400 {
1401 wxLogLastError(_T("CreateCompatibleDC"));
1402
1403 return bitmap;
1404 }
1405
1406 SelectInHDC bmpInHDC(hdcMem, (HBITMAP)bitmap);
1407
1408 if ( !bmpInHDC )
1409 {
1410 wxLogLastError(_T("SelectObject"));
1411
1412 return bitmap;
1413 }
1414
1415 wxCOLORMAP *cmap = wxGetStdColourMap();
1416
1417 for ( int i = 0; i < width; i++ )
1418 {
1419 for ( int j = 0; j < height; j++ )
1420 {
1421 COLORREF pixel = ::GetPixel(hdcMem, i, j);
1422
1423 for ( size_t k = 0; k < wxSTD_COL_MAX; k++ )
1424 {
1425 COLORREF col = cmap[k].from;
1426 if ( abs(GetRValue(pixel) - GetRValue(col)) < 10 &&
1427 abs(GetGValue(pixel) - GetGValue(col)) < 10 &&
1428 abs(GetBValue(pixel) - GetBValue(col)) < 10 )
1429 {
1430 ::SetPixel(hdcMem, i, j, cmap[k].to);
1431 break;
1432 }
1433 }
1434 }
1435 }
1436
1437 return bitmap;
1438
1439 // VZ: I leave here my attempts to map the bitmap to the system colours
1440 // faster by using BitBlt() even though it's broken currently - but
1441 // maybe someone else can finish it? It should be faster than iterating
1442 // over all pixels...
1443 #if 0
1444 MemoryHDC hdcMask, hdcDst;
1445 if ( !hdcMask || !hdcDst )
1446 {
1447 wxLogLastError(_T("CreateCompatibleDC"));
1448
1449 return bitmap;
1450 }
1451
1452 // create the target bitmap
1453 HBITMAP hbmpDst = ::CreateCompatibleBitmap(hdcDst, width, height);
1454 if ( !hbmpDst )
1455 {
1456 wxLogLastError(_T("CreateCompatibleBitmap"));
1457
1458 return bitmap;
1459 }
1460
1461 // create the monochrome mask bitmap
1462 HBITMAP hbmpMask = ::CreateBitmap(width, height, 1, 1, 0);
1463 if ( !hbmpMask )
1464 {
1465 wxLogLastError(_T("CreateBitmap(mono)"));
1466
1467 ::DeleteObject(hbmpDst);
1468
1469 return bitmap;
1470 }
1471
1472 SelectInHDC bmpInDst(hdcDst, hbmpDst),
1473 bmpInMask(hdcMask, hbmpMask);
1474
1475 // for each colour:
1476 for ( n = 0; n < NUM_OF_MAPPED_COLOURS; n++ )
1477 {
1478 // create the mask for this colour
1479 ::SetBkColor(hdcMem, ColorMap[n].from);
1480 ::BitBlt(hdcMask, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);
1481
1482 // replace this colour with the target one in the dst bitmap
1483 HBRUSH hbr = ::CreateSolidBrush(ColorMap[n].to);
1484 HGDIOBJ hbrOld = ::SelectObject(hdcDst, hbr);
1485
1486 ::MaskBlt(hdcDst, 0, 0, width, height,
1487 hdcMem, 0, 0,
1488 hbmpMask, 0, 0,
1489 MAKEROP4(PATCOPY, SRCCOPY));
1490
1491 (void)::SelectObject(hdcDst, hbrOld);
1492 ::DeleteObject(hbr);
1493 }
1494
1495 ::DeleteObject((HBITMAP)bitmap);
1496
1497 return (WXHBITMAP)hbmpDst;
1498 #endif // 0
1499 }
1500
1501 #endif // wxUSE_TOOLBAR && Win95
1502