1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/tbar95.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && !defined(__SMARTPHONE__)
29 #include "wx/toolbar.h"
32 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
33 #include "wx/dynarray.h"
37 #include "wx/settings.h"
38 #include "wx/bitmap.h"
39 #include "wx/dcmemory.h"
40 #include "wx/control.h"
41 #include "wx/app.h" // for GetComCtl32Version
43 #include "wx/stattext.h"
46 #include "wx/sysopt.h"
48 #include "wx/msw/private.h"
51 #include "wx/msw/uxtheme.h"
54 // this define controls whether the code for button colours remapping (only
55 // useful for 16 or 256 colour images) is active at all, it's always turned off
56 // for CE where it doesn't compile (and is probably not needed anyhow) and may
57 // also be turned off for other systems if you always use 24bpp images and so
60 #define wxREMAP_BUTTON_COLOURS
61 #endif // !__WXWINCE__
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // these standard constants are not always defined in compilers headers
71 #define TBSTYLE_LIST 0x1000
72 #define TBSTYLE_FLAT 0x0800
75 #ifndef TBSTYLE_TRANSPARENT
76 #define TBSTYLE_TRANSPARENT 0x8000
79 #ifndef TBSTYLE_TOOLTIPS
80 #define TBSTYLE_TOOLTIPS 0x0100
85 #define TB_SETSTYLE (WM_USER + 56)
86 #define TB_GETSTYLE (WM_USER + 57)
90 #define TB_HITTEST (WM_USER + 69)
94 #define TB_GETMAXSIZE (WM_USER + 83)
97 // these values correspond to those used by comctl32.dll
98 #define DEFAULTBITMAPX 16
99 #define DEFAULTBITMAPY 15
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
117 style ( wxNO_BORDER | wxTB_HORIZONTAL)
126 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
127 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
128 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged
)
129 EVT_ERASE_BACKGROUND(wxToolBar::OnEraseBackground
)
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 class wxToolBarTool
: public wxToolBarToolBase
139 wxToolBarTool(wxToolBar
*tbar
,
141 const wxString
& label
,
142 const wxBitmap
& bmpNormal
,
143 const wxBitmap
& bmpDisabled
,
145 wxObject
*clientData
,
146 const wxString
& shortHelp
,
147 const wxString
& longHelp
)
148 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
149 clientData
, shortHelp
, longHelp
)
155 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
156 : wxToolBarToolBase(tbar
, control
, label
)
158 if ( IsControl() && !m_label
.empty() )
160 // create a control to render the control's label
161 m_staticText
= new wxStaticText
168 wxALIGN_CENTRE
| wxST_NO_AUTORESIZE
179 virtual ~wxToolBarTool()
184 virtual void SetLabel(const wxString
& label
)
186 if ( label
== m_label
)
189 wxToolBarToolBase::SetLabel(label
);
192 m_staticText
->SetLabel(label
);
194 // we need to update the label shown in the toolbar because it has a
195 // pointer to the internal buffer of the old label
197 // TODO: use TB_SETBUTTONINFO
200 wxStaticText
* GetStaticText()
202 wxASSERT_MSG( IsControl(),
203 _T("only makes sense for embedded control tools") );
208 // set/get the number of separators which we use to cover the space used by
209 // a control in the toolbar
210 void SetSeparatorsCount(size_t count
) { m_nSepCount
= count
; }
211 size_t GetSeparatorsCount() const { return m_nSepCount
; }
215 wxStaticText
*m_staticText
;
217 DECLARE_NO_COPY_CLASS(wxToolBarTool
)
220 // ============================================================================
222 // ============================================================================
224 // ----------------------------------------------------------------------------
226 // ----------------------------------------------------------------------------
228 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
229 const wxString
& label
,
230 const wxBitmap
& bmpNormal
,
231 const wxBitmap
& bmpDisabled
,
233 wxObject
*clientData
,
234 const wxString
& shortHelp
,
235 const wxString
& longHelp
)
237 return new wxToolBarTool(this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
238 clientData
, shortHelp
, longHelp
);
242 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
244 return new wxToolBarTool(this, control
, label
);
247 // ----------------------------------------------------------------------------
248 // wxToolBar construction
249 // ----------------------------------------------------------------------------
251 void wxToolBar::Init()
254 m_disabledImgList
= NULL
;
258 m_defaultWidth
= DEFAULTBITMAPX
;
259 m_defaultHeight
= DEFAULTBITMAPY
;
264 bool wxToolBar::Create(wxWindow
*parent
,
269 const wxString
& name
)
271 // common initialisation
272 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
277 // MSW-specific initialisation
278 if ( !MSWCreateToolbar(pos
, size
) )
281 wxSetCCUnicodeFormat(GetHwnd());
283 // workaround for flat toolbar on Windows XP classic style: we have to set
284 // the style after creating the control; doing it at creation time doesn't work
286 if ( style
& wxTB_FLAT
)
288 LRESULT style
= GetMSWToolbarStyle();
290 if ( !(style
& TBSTYLE_FLAT
) )
291 ::SendMessage(GetHwnd(), TB_SETSTYLE
, 0, style
| TBSTYLE_FLAT
);
293 #endif // wxUSE_UXTHEME
298 bool wxToolBar::MSWCreateToolbar(const wxPoint
& pos
, const wxSize
& size
)
300 if ( !MSWCreateControl(TOOLBARCLASSNAME
, wxEmptyString
, pos
, size
) )
303 // toolbar-specific post initialisation
304 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
306 if ( wxApp::GetComCtl32Version() >= 471 )
307 ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_DRAWDDARROWS
);
312 void wxToolBar::Recreate()
314 const HWND hwndOld
= GetHwnd();
317 // we haven't been created yet, no need to recreate
321 // get the position and size before unsubclassing the old toolbar
322 const wxPoint pos
= GetPosition();
323 const wxSize size
= GetSize();
327 if ( !MSWCreateToolbar(pos
, size
) )
330 wxFAIL_MSG( _T("recreating the toolbar failed") );
335 // reparent all our children under the new toolbar
336 for ( wxWindowList::compatibility_iterator node
= m_children
.GetFirst();
338 node
= node
->GetNext() )
340 wxWindow
*win
= node
->GetData();
341 if ( !win
->IsTopLevel() )
342 ::SetParent(GetHwndOf(win
), GetHwnd());
345 // only destroy the old toolbar now --
346 // after all the children had been reparented
347 ::DestroyWindow(hwndOld
);
349 // it is for the old bitmap control and can't be used with the new one
352 ::DeleteObject((HBITMAP
) m_hBitmap
);
356 if ( m_disabledImgList
)
358 delete m_disabledImgList
;
359 m_disabledImgList
= NULL
;
365 wxToolBar::~wxToolBar()
367 // we must refresh the frame size when the toolbar is deleted but the frame
368 // is not - otherwise toolbar leaves a hole in the place it used to occupy
369 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
370 if ( frame
&& !frame
->IsBeingDeleted() )
371 frame
->SendSizeEvent();
374 ::DeleteObject((HBITMAP
) m_hBitmap
);
376 delete m_disabledImgList
;
379 wxSize
wxToolBar::DoGetBestSize() const
384 if ( !::SendMessage(GetHwnd(), TB_GETMAXSIZE
, 0, (LPARAM
)&size
) )
386 // maybe an old (< 0x400) Windows version? try to approximate the
387 // toolbar size ourselves
388 sizeBest
= GetToolSize();
389 sizeBest
.y
+= 2 * ::GetSystemMetrics(SM_CYBORDER
); // Add borders
390 sizeBest
.x
*= GetToolsCount();
392 // reverse horz and vertical components if necessary
396 sizeBest
.x
= sizeBest
.y
;
402 sizeBest
.x
= size
.cx
;
403 sizeBest
.y
= size
.cy
;
406 if (!IsVertical() && !(GetWindowStyle() & wxTB_NODIVIDER
))
409 CacheBestSize(sizeBest
);
414 WXDWORD
wxToolBar::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
416 // toolbars never have border, giving one to them results in broken
418 WXDWORD msStyle
= wxControl::MSWGetStyle
420 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exstyle
423 if ( !(style
& wxTB_NO_TOOLTIPS
) )
424 msStyle
|= TBSTYLE_TOOLTIPS
;
426 if ( style
& (wxTB_FLAT
| wxTB_HORZ_LAYOUT
) )
428 // static as it doesn't change during the program lifetime
429 static const int s_verComCtl
= wxApp::GetComCtl32Version();
431 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
432 // style with 6.00 (part of Windows XP) leads to the toolbar with
433 // incorrect background colour - and not using it still results in the
434 // correct (flat) toolbar, so don't use it there
435 if ( s_verComCtl
> 400 && s_verComCtl
< 600 )
436 msStyle
|= TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
;
438 if ( s_verComCtl
>= 470 && style
& wxTB_HORZ_LAYOUT
)
439 msStyle
|= TBSTYLE_LIST
;
442 if ( style
& wxTB_NODIVIDER
)
443 msStyle
|= CCS_NODIVIDER
;
445 if ( style
& wxTB_NOALIGN
)
446 msStyle
|= CCS_NOPARENTALIGN
;
448 if ( style
& wxTB_VERTICAL
)
451 if( style
& wxTB_BOTTOM
)
452 msStyle
|= CCS_BOTTOM
;
454 if ( style
& wxTB_RIGHT
)
455 msStyle
|= CCS_RIGHT
;
460 // ----------------------------------------------------------------------------
461 // adding/removing tools
462 // ----------------------------------------------------------------------------
464 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*tool
)
466 // nothing special to do here - we really create the toolbar buttons in
470 InvalidateBestSize();
474 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
476 // the main difficulty we have here is with the controls in the toolbars:
477 // as we (sometimes) use several separators to cover up the space used by
478 // them, the indices are not the same for us and the toolbar
480 // first determine the position of the first button to delete: it may be
481 // different from pos if we use several separators to cover the space used
483 wxToolBarToolsList::compatibility_iterator node
;
484 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
486 wxToolBarToolBase
*tool2
= node
->GetData();
489 // let node point to the next node in the list
490 node
= node
->GetNext();
495 if ( tool2
->IsControl() )
496 pos
+= ((wxToolBarTool
*)tool2
)->GetSeparatorsCount() - 1;
499 // now determine the number of buttons to delete and the area taken by them
500 size_t nButtonsToDelete
= 1;
502 // get the size of the button we're going to delete
504 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
506 wxLogLastError(_T("TB_GETITEMRECT"));
509 int width
= r
.right
- r
.left
;
511 if ( tool
->IsControl() )
513 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
514 width
*= nButtonsToDelete
;
515 tool
->GetControl()->Destroy();
518 // do delete all buttons
519 m_nButtons
-= nButtonsToDelete
;
520 while ( nButtonsToDelete
-- > 0 )
522 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
524 wxLogLastError(wxT("TB_DELETEBUTTON"));
532 // and finally reposition all the controls after this button (the toolbar
533 // takes care of all normal items)
534 for ( /* node -> first after deleted */ ; node
; node
= node
->GetNext() )
536 wxToolBarTool
*tool2
= (wxToolBarTool
*)node
->GetData();
537 if ( tool2
->IsControl() )
540 wxControl
*control
= tool2
->GetControl();
541 control
->GetPosition(&x
, NULL
);
542 control
->Move(x
- width
, wxDefaultCoord
);
544 wxStaticText
* staticText
= tool2
->GetStaticText();
545 staticText
->Move(x
- width
, wxDefaultCoord
);
549 InvalidateBestSize();
554 void wxToolBar::CreateDisabledImageList()
556 if (m_disabledImgList
!= NULL
)
558 delete m_disabledImgList
;
559 m_disabledImgList
= NULL
;
562 // as we can't use disabled image list with older versions of comctl32.dll,
563 // don't even bother creating it
564 if ( wxApp::GetComCtl32Version() >= 470 )
566 // search for the first disabled button img in the toolbar, if any
567 for ( wxToolBarToolsList::compatibility_iterator
568 node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
570 wxToolBarToolBase
*tool
= node
->GetData();
571 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
572 if ( bmpDisabled
.Ok() )
574 m_disabledImgList
= new wxImageList
578 bmpDisabled
.GetMask() != NULL
,
585 // we don't have any disabled bitmaps
589 bool wxToolBar::Realize()
591 const size_t nTools
= GetToolsCount();
596 #ifdef wxREMAP_BUTTON_COLOURS
597 // don't change the values of these constants, they can be set from the
598 // user code via wxSystemOptions
607 // the user-specified option overrides anything, but if it wasn't set, only
608 // remap the buttons on 8bpp displays as otherwise the bitmaps usually look
609 // much worse after remapping
610 static const wxChar
*remapOption
= wxT("msw.remap");
611 const int remapValue
= wxSystemOptions::HasOption(remapOption
)
612 ? wxSystemOptions::GetOptionInt(remapOption
)
613 : wxDisplayDepth() <= 8 ? Remap_Buttons
616 #endif // wxREMAP_BUTTON_COLOURS
618 // delete all old buttons, if any
619 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
621 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
623 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
627 // First, add the bitmap: we use one bitmap for all toolbar buttons
628 // ----------------------------------------------------------------
630 wxToolBarToolsList::compatibility_iterator node
;
634 if ( HasFlag(wxTB_NOICONS
) )
636 // no icons, don't leave space for them
640 else // do show icons
642 // if we already have a bitmap, we'll replace the existing one --
643 // otherwise we'll install a new one
644 HBITMAP oldToolBarBitmap
= (HBITMAP
)m_hBitmap
;
646 sizeBmp
.x
= m_defaultWidth
;
647 sizeBmp
.y
= m_defaultHeight
;
649 const wxCoord totalBitmapWidth
= m_defaultWidth
*
650 wx_truncate_cast(wxCoord
, nTools
),
651 totalBitmapHeight
= m_defaultHeight
;
653 // Create a bitmap and copy all the tool bitmaps into it
654 wxMemoryDC dcAllButtons
;
655 wxBitmap
bitmap(totalBitmapWidth
, totalBitmapHeight
);
656 dcAllButtons
.SelectObject(bitmap
);
658 #ifdef wxREMAP_BUTTON_COLOURS
659 if ( remapValue
!= Remap_TransparentBg
)
660 #endif // wxREMAP_BUTTON_COLOURS
662 // VZ: why do we hardcode grey colour for CE?
663 dcAllButtons
.SetBackground(wxBrush(
665 wxColour(0xc0, 0xc0, 0xc0)
666 #else // !__WXWINCE__
667 GetBackgroundColour()
668 #endif // __WXWINCE__/!__WXWINCE__
670 dcAllButtons
.Clear();
673 m_hBitmap
= bitmap
.GetHBITMAP();
674 HBITMAP hBitmap
= (HBITMAP
)m_hBitmap
;
676 #ifdef wxREMAP_BUTTON_COLOURS
677 if ( remapValue
== Remap_Bg
)
679 dcAllButtons
.SelectObject(wxNullBitmap
);
681 // Even if we're not remapping the bitmap
682 // content, we still have to remap the background.
683 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
684 totalBitmapWidth
, totalBitmapHeight
);
686 dcAllButtons
.SelectObject(bitmap
);
688 #endif // wxREMAP_BUTTON_COLOURS
690 // the button position
693 // the number of buttons (not separators)
696 CreateDisabledImageList();
697 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
699 wxToolBarToolBase
*tool
= node
->GetData();
700 if ( tool
->IsButton() )
702 const wxBitmap
& bmp
= tool
->GetNormalBitmap();
704 const int w
= bmp
.GetWidth();
705 const int h
= bmp
.GetHeight();
709 int xOffset
= wxMax(0, (m_defaultWidth
- w
)/2);
710 int yOffset
= wxMax(0, (m_defaultHeight
- h
)/2);
712 // notice the last parameter: do use mask
713 dcAllButtons
.DrawBitmap(bmp
, x
+ xOffset
, yOffset
, true);
717 wxFAIL_MSG( _T("invalid tool button bitmap") );
720 // also deal with disabled bitmap if we want to use them
721 if ( m_disabledImgList
)
723 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
724 #if wxUSE_IMAGE && wxUSE_WXDIB
725 if ( !bmpDisabled
.Ok() )
727 // no disabled bitmap specified but we still need to
728 // fill the space in the image list with something, so
729 // we grey out the normal bitmap
731 imgGreyed
= bmp
.ConvertToImage().ConvertToGreyscale();
733 #ifdef wxREMAP_BUTTON_COLOURS
734 if ( remapValue
== Remap_Buttons
)
736 // we need to have light grey background colour for
737 // MapBitmap() to work correctly
738 for ( int y
= 0; y
< h
; y
++ )
740 for ( int x
= 0; x
< w
; x
++ )
742 if ( imgGreyed
.IsTransparent(x
, y
) )
743 imgGreyed
.SetRGB(x
, y
,
745 wxLIGHT_GREY
->Green(),
746 wxLIGHT_GREY
->Blue());
750 #endif // wxREMAP_BUTTON_COLOURS
752 bmpDisabled
= wxBitmap(imgGreyed
);
754 #endif // wxUSE_IMAGE
756 #ifdef wxREMAP_BUTTON_COLOURS
757 if ( remapValue
== Remap_Buttons
)
758 MapBitmap(bmpDisabled
.GetHBITMAP(), w
, h
);
759 #endif // wxREMAP_BUTTON_COLOURS
761 m_disabledImgList
->Add(bmpDisabled
);
764 // still inc width and number of buttons because otherwise the
765 // subsequent buttons will all be shifted which is rather confusing
766 // (and like this you'd see immediately which bitmap was bad)
772 dcAllButtons
.SelectObject(wxNullBitmap
);
774 // don't delete this HBITMAP!
775 bitmap
.SetHBITMAP(0);
777 #ifdef wxREMAP_BUTTON_COLOURS
778 if ( remapValue
== Remap_Buttons
)
780 // Map to system colours
781 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
782 totalBitmapWidth
, totalBitmapHeight
);
784 #endif // wxREMAP_BUTTON_COLOURS
786 bool addBitmap
= true;
788 if ( oldToolBarBitmap
)
790 #ifdef TB_REPLACEBITMAP
791 if ( wxApp::GetComCtl32Version() >= 400 )
793 TBREPLACEBITMAP replaceBitmap
;
794 replaceBitmap
.hInstOld
= NULL
;
795 replaceBitmap
.hInstNew
= NULL
;
796 replaceBitmap
.nIDOld
= (UINT
) oldToolBarBitmap
;
797 replaceBitmap
.nIDNew
= (UINT
) hBitmap
;
798 replaceBitmap
.nButtons
= nButtons
;
799 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP
,
800 0, (LPARAM
) &replaceBitmap
) )
802 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
805 ::DeleteObject(oldToolBarBitmap
);
811 #endif // TB_REPLACEBITMAP
813 // we can't replace the old bitmap, so we will add another one
814 // (awfully inefficient, but what else to do?) and shift the bitmap
815 // indices accordingly
818 bitmapId
= m_nButtons
;
822 if ( addBitmap
) // no old bitmap or we can't replace it
824 TBADDBITMAP addBitmap
;
826 addBitmap
.nID
= (UINT
) hBitmap
;
827 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP
,
828 (WPARAM
) nButtons
, (LPARAM
)&addBitmap
) == -1 )
830 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
834 // disable image lists are only supported in comctl32.dll 4.70+
835 if ( wxApp::GetComCtl32Version() >= 470 )
837 HIMAGELIST hil
= m_disabledImgList
838 ? GetHimagelistOf(m_disabledImgList
)
841 // notice that we set the image list even if don't have one right
842 // now as we could have it before and need to reset it in this case
843 HIMAGELIST oldImageList
= (HIMAGELIST
)
844 ::SendMessage(GetHwnd(), TB_SETDISABLEDIMAGELIST
, 0, (LPARAM
)hil
);
846 // delete previous image list if any
848 ::DeleteObject(oldImageList
);
852 // don't call SetToolBitmapSize() as we don't want to change the values of
853 // m_defaultWidth/Height
854 if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0,
855 MAKELONG(sizeBmp
.x
, sizeBmp
.y
)) )
857 wxLogLastError(_T("TB_SETBITMAPSIZE"));
860 // Next add the buttons and separators
861 // -----------------------------------
863 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
865 // this array will hold the indices of all controls in the toolbar
866 wxArrayInt controlIds
;
868 bool lastWasRadio
= false;
870 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
872 wxToolBarToolBase
*tool
= node
->GetData();
874 // don't add separators to the vertical toolbar with old comctl32.dll
875 // versions as they didn't handle this properly
876 if ( IsVertical() && tool
->IsSeparator() &&
877 wxApp::GetComCtl32Version() <= 472 )
882 TBBUTTON
& button
= buttons
[i
];
884 wxZeroMemory(button
);
886 bool isRadio
= false;
887 switch ( tool
->GetStyle() )
889 case wxTOOL_STYLE_CONTROL
:
890 button
.idCommand
= tool
->GetId();
891 // fall through: create just a separator too
893 case wxTOOL_STYLE_SEPARATOR
:
894 button
.fsState
= TBSTATE_ENABLED
;
895 button
.fsStyle
= TBSTYLE_SEP
;
898 case wxTOOL_STYLE_BUTTON
:
899 if ( !HasFlag(wxTB_NOICONS
) )
900 button
.iBitmap
= bitmapId
;
902 if ( HasFlag(wxTB_TEXT
) )
904 const wxString
& label
= tool
->GetLabel();
905 if ( !label
.empty() )
906 button
.iString
= (int)label
.wx_str();
909 button
.idCommand
= tool
->GetId();
911 if ( tool
->IsEnabled() )
912 button
.fsState
|= TBSTATE_ENABLED
;
913 if ( tool
->IsToggled() )
914 button
.fsState
|= TBSTATE_CHECKED
;
916 switch ( tool
->GetKind() )
919 button
.fsStyle
= TBSTYLE_CHECKGROUP
;
923 // the first item in the radio group is checked by
924 // default to be consistent with wxGTK and the menu
926 button
.fsState
|= TBSTATE_CHECKED
;
928 if (tool
->Toggle(true))
930 DoToggleTool(tool
, true);
933 else if (tool
->IsToggled())
935 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
936 int prevIndex
= i
- 1;
939 TBBUTTON
& prevButton
= buttons
[prevIndex
];
940 wxToolBarToolBase
*tool
= nodePrev
->GetData();
941 if ( !tool
->IsButton() || tool
->GetKind() != wxITEM_RADIO
)
944 if ( tool
->Toggle(false) )
945 DoToggleTool(tool
, false);
947 prevButton
.fsState
= TBSTATE_ENABLED
;
948 nodePrev
= nodePrev
->GetPrevious();
957 button
.fsStyle
= TBSTYLE_CHECK
;
961 button
.fsStyle
= TBSTYLE_BUTTON
;
964 case wxITEM_DROPDOWN
:
965 button
.fsStyle
= TBSTYLE_DROPDOWN
;
969 wxFAIL_MSG( _T("unexpected toolbar button kind") );
970 button
.fsStyle
= TBSTYLE_BUTTON
;
978 lastWasRadio
= isRadio
;
983 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS
, (WPARAM
)i
, (LPARAM
)buttons
) )
985 wxLogLastError(wxT("TB_ADDBUTTONS"));
990 // Deal with the controls finally
991 // ------------------------------
993 // adjust the controls size to fit nicely in the toolbar
996 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
998 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1000 // we calculate the running y coord for vertical toolbars so we need to
1001 // get the items size for all items but for the horizontal ones we
1002 // don't need to deal with the non controls
1003 bool isControl
= tool
->IsControl();
1004 if ( !isControl
&& !IsVertical() )
1007 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
1008 // latter only appeared in v4.70 of comctl32.dll
1010 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1011 index
, (LPARAM
)(LPRECT
)&r
) )
1013 wxLogLastError(wxT("TB_GETITEMRECT"));
1018 // can only be control if isVertical
1019 y
+= r
.bottom
- r
.top
;
1024 wxControl
*control
= tool
->GetControl();
1025 wxStaticText
* const staticText
= tool
->GetStaticText();
1027 wxSize size
= control
->GetSize();
1028 wxSize staticTextSize
;
1031 staticTextSize
= staticText
->GetSize();
1032 staticTextSize
.y
+= 3; // margin between control and its label
1035 // the position of the leftmost controls corner
1036 int left
= wxDefaultCoord
;
1038 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
1039 #ifdef TB_SETBUTTONINFO
1040 // available in headers, now check whether it is available now
1041 // (during run-time)
1042 if ( wxApp::GetComCtl32Version() >= 471 )
1044 // set the (underlying) separators width to be that of the
1047 tbbi
.cbSize
= sizeof(tbbi
);
1048 tbbi
.dwMask
= TBIF_SIZE
;
1049 tbbi
.cx
= (WORD
)size
.x
;
1050 if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
1051 tool
->GetId(), (LPARAM
)&tbbi
) )
1053 // the id is probably invalid?
1054 wxLogLastError(wxT("TB_SETBUTTONINFO"));
1058 #endif // comctl32.dll 4.71
1059 // TB_SETBUTTONINFO unavailable
1061 // try adding several separators to fit the controls width
1062 int widthSep
= r
.right
- r
.left
;
1068 tbb
.fsState
= TBSTATE_ENABLED
;
1069 tbb
.fsStyle
= TBSTYLE_SEP
;
1071 size_t nSeparators
= size
.x
/ widthSep
;
1072 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
1074 if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON
,
1075 index
, (LPARAM
)&tbb
) )
1077 wxLogLastError(wxT("TB_INSERTBUTTON"));
1083 // remember the number of separators we used - we'd have to
1084 // delete all of them later
1085 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
1087 // adjust the controls width to exactly cover the separators
1088 size
.x
= (nSeparators
+ 1)*widthSep
;
1089 control
->SetSize(size
.x
, wxDefaultCoord
);
1092 // position the control itself correctly vertically centering it on the
1093 // icon area of the toolbar
1094 int height
= r
.bottom
- r
.top
- staticTextSize
.y
;
1096 int diff
= height
- size
.y
;
1097 if ( diff
< 0 || !HasFlag(wxTB_TEXT
) )
1099 // not enough room for the static text
1103 // recalculate height & diff without the staticText control
1104 height
= r
.bottom
- r
.top
;
1105 diff
= height
- size
.y
;
1108 // the control is too high, resize to fit
1109 control
->SetSize(wxDefaultCoord
, height
- 2);
1114 else // enough space for both the control and the label
1126 y
+= height
+ 2 * GetMargins().y
;
1128 else // horizontal toolbar
1130 if ( left
== wxDefaultCoord
)
1136 control
->Move(left
, top
+ (diff
+ 1) / 2);
1139 staticText
->Move(left
+ (size
.x
- staticTextSize
.x
)/2,
1140 r
.bottom
- staticTextSize
.y
);
1144 // the max index is the "real" number of buttons - i.e. counting even the
1145 // separators which we added just for aligning the controls
1148 if ( !IsVertical() )
1150 if ( m_maxRows
== 0 )
1151 // if not set yet, only one row
1154 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
1156 // if not set yet, have one column
1158 SetRows(m_nButtons
);
1161 InvalidateBestSize();
1167 // ----------------------------------------------------------------------------
1169 // ----------------------------------------------------------------------------
1171 bool wxToolBar::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD id
)
1173 wxToolBarToolBase
*tool
= FindById((int)id
);
1177 bool toggled
= false; // just to suppress warnings
1179 if ( tool
->CanBeToggled() )
1181 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
1182 toggled
= (state
& TBSTATE_CHECKED
) != 0;
1184 // ignore the event when a radio button is released, as this doesn't
1185 // seem to happen at all, and is handled otherwise
1186 if ( tool
->GetKind() == wxITEM_RADIO
&& !toggled
)
1189 tool
->Toggle(toggled
);
1190 UnToggleRadioGroup(tool
);
1193 // OnLeftClick() can veto the button state change - for buttons which
1194 // may be toggled only, of couse
1195 if ( !OnLeftClick((int)id
, toggled
) && tool
->CanBeToggled() )
1198 tool
->Toggle(!toggled
);
1200 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(!toggled
, 0));
1206 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
1208 WXLPARAM
*WXUNUSED(result
))
1210 LPNMHDR hdr
= (LPNMHDR
)lParam
;
1211 if ( hdr
->code
== TBN_DROPDOWN
)
1213 LPNMTOOLBAR tbhdr
= (LPNMTOOLBAR
)lParam
;
1215 wxCommandEvent
evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, tbhdr
->iItem
);
1216 if ( GetEventHandler()->ProcessEvent(evt
) )
1218 // Event got handled, don't display default popup menu
1222 const wxToolBarToolBase
* const tool
= FindById(tbhdr
->iItem
);
1223 wxCHECK_MSG( tool
, false, _T("drop down message for unknown tool") );
1225 wxMenu
* const menu
= tool
->GetDropdownMenu();
1229 // Display popup menu below button
1231 if (::SendMessage(GetHwnd(), TB_GETITEMRECT
, GetToolPos(tbhdr
->iItem
), (LPARAM
)&r
))
1232 PopupMenu(menu
, r
.left
, r
.bottom
);
1238 if( !HasFlag(wxTB_NO_TOOLTIPS
) )
1241 // First check if this applies to us
1243 // the tooltips control created by the toolbar is sometimes Unicode, even
1244 // in an ANSI application - this seems to be a bug in comctl32.dll v5
1245 UINT code
= hdr
->code
;
1246 if ( (code
!= (UINT
) TTN_NEEDTEXTA
) && (code
!= (UINT
) TTN_NEEDTEXTW
) )
1249 HWND toolTipWnd
= (HWND
)::SendMessage(GetHwnd(), TB_GETTOOLTIPS
, 0, 0);
1250 if ( toolTipWnd
!= hdr
->hwndFrom
)
1253 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
1254 int id
= (int)ttText
->hdr
.idFrom
;
1256 wxToolBarToolBase
*tool
= FindById(id
);
1258 return HandleTooltipNotify(code
, lParam
, tool
->GetShortHelp());
1260 wxUnusedVar(lParam
);
1267 // ----------------------------------------------------------------------------
1269 // ----------------------------------------------------------------------------
1271 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1273 wxToolBarBase::SetToolBitmapSize(size
);
1275 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
1278 void wxToolBar::SetRows(int nRows
)
1280 if ( nRows
== m_maxRows
)
1282 // avoid resizing the frame uselessly
1286 // TRUE in wParam means to create at least as many rows, FALSE -
1289 ::SendMessage(GetHwnd(), TB_SETROWS
,
1290 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
1298 // The button size is bigger than the bitmap size
1299 wxSize
wxToolBar::GetToolSize() const
1301 // TB_GETBUTTONSIZE is supported from version 4.70
1302 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
1303 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
1304 && !defined (__DIGITALMARS__)
1305 if ( wxApp::GetComCtl32Version() >= 470 )
1307 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
1309 return wxSize(LOWORD(dw
), HIWORD(dw
));
1312 #endif // comctl32.dll 4.70+
1315 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
1320 wxToolBarToolBase
*GetItemSkippingDummySpacers(const wxToolBarToolsList
& tools
,
1323 wxToolBarToolsList::compatibility_iterator current
= tools
.GetFirst();
1325 for ( ; current
; current
= current
->GetNext() )
1328 return current
->GetData();
1330 wxToolBarTool
*tool
= (wxToolBarTool
*)current
->GetData();
1331 size_t separators
= tool
->GetSeparatorsCount();
1333 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
1334 // otherwise, skip as many items as the separator count, plus the
1336 index
-= separators
? separators
+ 1 : 1;
1342 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1347 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
1349 // MBN: when the point ( x, y ) is close to the toolbar border
1350 // TB_HITTEST returns m_nButtons ( not -1 )
1351 if ( index
< 0 || (size_t)index
>= m_nButtons
)
1352 // it's a separator or there is no tool at all there
1353 return (wxToolBarToolBase
*)NULL
;
1355 // when TB_SETBUTTONINFO is available (both during compile- and run-time),
1356 // we don't use the dummy separators hack
1357 #ifdef TB_SETBUTTONINFO
1358 if ( wxApp::GetComCtl32Version() >= 471 )
1360 return m_tools
.Item((size_t)index
)->GetData();
1363 #endif // TB_SETBUTTONINFO
1365 return GetItemSkippingDummySpacers( m_tools
, (size_t) index
);
1369 void wxToolBar::UpdateSize()
1371 wxPoint pos
= GetPosition();
1372 ::SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
1373 if (pos
!= GetPosition())
1376 // In case Realize is called after the initial display (IOW the programmer
1377 // may have rebuilt the toolbar) give the frame the option of resizing the
1378 // toolbar to full width again, but only if the parent is a frame and the
1379 // toolbar is managed by the frame. Otherwise assume that some other
1380 // layout mechanism is controlling the toolbar size and leave it alone.
1381 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
1382 if ( frame
&& frame
->GetToolBar() == this )
1384 frame
->SendSizeEvent();
1388 // ----------------------------------------------------------------------------
1390 // ---------------------------------------------------------------------------
1392 // get the TBSTYLE of the given toolbar window
1393 long wxToolBar::GetMSWToolbarStyle() const
1395 return ::SendMessage(GetHwnd(), TB_GETSTYLE
, 0, 0L);
1398 void wxToolBar::SetWindowStyleFlag(long style
)
1400 // the style bits whose changes force us to recreate the toolbar
1401 static const long MASK_NEEDS_RECREATE
= wxTB_TEXT
| wxTB_NOICONS
;
1403 const long styleOld
= GetWindowStyle();
1405 wxToolBarBase::SetWindowStyleFlag(style
);
1407 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1408 // also fatal as we'd then try to recreate the toolbar when it's just being
1410 if ( GetToolsCount() &&
1411 (style
& MASK_NEEDS_RECREATE
) != (styleOld
& MASK_NEEDS_RECREATE
) )
1413 // to remove the text labels, simply re-realizing the toolbar is enough
1414 // but I don't know of any way to add the text to an existing toolbar
1415 // other than by recreating it entirely
1420 // ----------------------------------------------------------------------------
1422 // ----------------------------------------------------------------------------
1424 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
1426 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
1427 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
1430 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
1432 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
1433 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
1436 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1438 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1439 // without, so we really need to delete the button and recreate it here
1440 wxFAIL_MSG( _T("not implemented") );
1443 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1445 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1448 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1450 tool
->SetNormalBitmap(bitmap
);
1455 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1457 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1460 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1462 tool
->SetDisabledBitmap(bitmap
);
1467 // ----------------------------------------------------------------------------
1469 // ----------------------------------------------------------------------------
1471 // Responds to colour changes, and passes event on to children.
1472 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1474 wxRGBToColour(m_backgroundColour
, ::GetSysColor(COLOR_BTNFACE
));
1476 // Remap the buttons
1479 // Relayout the toolbar
1480 int nrows
= m_maxRows
;
1481 m_maxRows
= 0; // otherwise SetRows() wouldn't do anything
1486 // let the event propagate further
1490 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
1492 if ( event
.Leaving() )
1496 OnMouseEnter(wxID_ANY
);
1504 if ( event
.RightDown() )
1506 // find the tool under the mouse
1507 wxCoord x
= 0, y
= 0;
1508 event
.GetPosition(&x
, &y
);
1510 wxToolBarToolBase
*tool
= FindToolForPosition(x
, y
);
1511 OnRightClick(tool
? tool
->GetId() : -1, x
, y
);
1519 // This handler is required to allow the toolbar to be set to a non-default
1520 // colour: for example, when it must blend in with a notebook page.
1521 void wxToolBar::OnEraseBackground(wxEraseEvent
& event
)
1523 RECT rect
= wxGetClientRect(GetHwnd());
1524 HDC hdc
= GetHdcOf((*event
.GetDC()));
1527 // we may need to draw themed colour so that we appear correctly on
1528 // e.g. notebook page under XP with themes but only do it if the parent
1529 // draws themed background itself
1530 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1532 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1536 hr
= theme
->DrawThemeParentBackground(GetHwnd(), hdc
, &rect
);
1540 // it can also return S_FALSE which seems to simply say that it
1541 // didn't draw anything but no error really occurred
1543 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1546 #endif // wxUSE_UXTHEME
1548 if ( UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT
) )
1550 // do draw our background
1552 // notice that this 'dumb' implementation may cause flicker for some of
1553 // the controls in which case they should intercept wxEraseEvent and
1554 // process it themselves somehow
1555 AutoHBRUSH
hBrush(wxColourToRGB(GetBackgroundColour()));
1557 wxCHANGE_HDC_MAP_MODE(hdc
, MM_TEXT
);
1558 ::FillRect(hdc
, &rect
, hBrush
);
1560 else // we have no non default background colour
1562 // let the system do it for us
1567 bool wxToolBar::HandleSize(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1569 // calculate our minor dimension ourselves - we're confusing the standard
1570 // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks
1572 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT
, 0, (LPARAM
)&r
) )
1578 w
= r
.right
- r
.left
;
1581 w
*= (m_nButtons
+ m_maxRows
- 1)/m_maxRows
;
1588 if (HasFlag( wxTB_FLAT
))
1589 h
= r
.bottom
- r
.top
- 3;
1591 h
= r
.bottom
- r
.top
;
1594 // FIXME: hardcoded separator line height...
1595 h
+= HasFlag(wxTB_NODIVIDER
) ? 4 : 6;
1600 if ( MAKELPARAM(w
, h
) != lParam
)
1602 // size really changed
1606 // message processed
1613 bool wxToolBar::HandlePaint(WXWPARAM wParam
, WXLPARAM lParam
)
1615 // erase any dummy separators which were used
1616 // for aligning the controls if any here
1618 // first of all, are there any controls at all?
1619 wxToolBarToolsList::compatibility_iterator node
;
1620 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1622 if ( node
->GetData()->IsControl() )
1627 // no controls, nothing to erase
1630 // prepare the DC on which we'll be drawing
1631 wxClientDC
dc(this);
1632 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
1633 dc
.SetPen(*wxTRANSPARENT_PEN
);
1636 if ( !::GetUpdateRect(GetHwnd(), &r
, FALSE
) )
1637 // nothing to redraw anyhow
1641 wxCopyRECTToRect(r
, rectUpdate
);
1643 dc
.SetClippingRegion(rectUpdate
);
1645 // draw the toolbar tools, separators &c normally
1646 wxControl::MSWWindowProc(WM_PAINT
, wParam
, lParam
);
1648 // for each control in the toolbar find all the separators intersecting it
1651 // NB: this is really the only way to do it as we don't know if a separator
1652 // corresponds to a control (i.e. is a dummy one) or a real one
1654 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1656 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1657 if ( tool
->IsControl() )
1659 // get the control rect in our client coords
1660 wxControl
*control
= tool
->GetControl();
1661 wxStaticText
*staticText
= tool
->GetStaticText();
1662 wxRect rectCtrl
= control
->GetRect();
1663 wxRect
rectStaticText(0,0,0,0);
1666 rectStaticText
= staticText
->GetRect();
1669 // iterate over all buttons
1671 int count
= ::SendMessage(GetHwnd(), TB_BUTTONCOUNT
, 0, 0);
1672 for ( int n
= 0; n
< count
; n
++ )
1674 // is it a separator?
1675 if ( !::SendMessage(GetHwnd(), TB_GETBUTTON
,
1678 wxLogDebug(_T("TB_GETBUTTON failed?"));
1683 if ( tbb
.fsStyle
!= TBSTYLE_SEP
)
1686 // get the bounding rect of the separator
1688 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1691 wxLogDebug(_T("TB_GETITEMRECT failed?"));
1696 // does it intersect the control?
1698 wxCopyRECTToRect(r
, rectItem
);
1699 if ( rectCtrl
.Intersects(rectItem
) )
1701 // yes, do erase it!
1702 dc
.DrawRectangle(rectItem
);
1704 // Necessary in case we use a no-paint-on-size
1705 // style in the parent: the controls can disappear
1706 control
->Refresh(false);
1708 if ( staticText
&& rectStaticText
.Intersects(rectItem
) )
1710 // yes, do erase it!
1711 dc
.DrawRectangle(rectItem
);
1713 // Necessary in case we use a no-paint-on-size
1714 // style in the parent: the controls can disappear
1715 staticText
->Refresh(false);
1724 void wxToolBar::HandleMouseMove(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1726 wxCoord x
= GET_X_LPARAM(lParam
),
1727 y
= GET_Y_LPARAM(lParam
);
1728 wxToolBarToolBase
* tool
= FindToolForPosition( x
, y
);
1730 // has the current tool changed?
1731 if ( tool
!= m_pInTool
)
1734 OnMouseEnter(tool
? tool
->GetId() : wxID_ANY
);
1738 WXLRESULT
wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1743 // we don't handle mouse moves, so always pass the message to
1744 // wxControl::MSWWindowProc (HandleMouseMove just calls OnMouseEnter)
1745 HandleMouseMove(wParam
, lParam
);
1749 if ( HandleSize(wParam
, lParam
) )
1755 if ( HandlePaint(wParam
, lParam
) )
1763 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1766 // ----------------------------------------------------------------------------
1767 // private functions
1768 // ----------------------------------------------------------------------------
1770 #ifdef wxREMAP_BUTTON_COLOURS
1772 WXHBITMAP
wxToolBar::MapBitmap(WXHBITMAP bitmap
, int width
, int height
)
1778 wxLogLastError(_T("CreateCompatibleDC"));
1783 SelectInHDC
bmpInHDC(hdcMem
, (HBITMAP
)bitmap
);
1787 wxLogLastError(_T("SelectObject"));
1792 wxCOLORMAP
*cmap
= wxGetStdColourMap();
1794 for ( int i
= 0; i
< width
; i
++ )
1796 for ( int j
= 0; j
< height
; j
++ )
1798 COLORREF pixel
= ::GetPixel(hdcMem
, i
, j
);
1800 for ( size_t k
= 0; k
< wxSTD_COL_MAX
; k
++ )
1802 COLORREF col
= cmap
[k
].from
;
1803 if ( abs(GetRValue(pixel
) - GetRValue(col
)) < 10 &&
1804 abs(GetGValue(pixel
) - GetGValue(col
)) < 10 &&
1805 abs(GetBValue(pixel
) - GetBValue(col
)) < 10 )
1807 if ( cmap
[k
].to
!= pixel
)
1808 ::SetPixel(hdcMem
, i
, j
, cmap
[k
].to
);
1818 #endif // wxREMAP_BUTTON_COLOURS
1820 #endif // wxUSE_TOOLBAR