1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/toolbar.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"
47 #include "wx/dcclient.h"
49 #include "wx/msw/private.h"
50 #include "wx/msw/dc.h"
53 #include "wx/msw/uxtheme.h"
56 // this define controls whether the code for button colours remapping (only
57 // useful for 16 or 256 colour images) is active at all, it's always turned off
58 // for CE where it doesn't compile (and is probably not needed anyhow) and may
59 // also be turned off for other systems if you always use 24bpp images and so
62 #define wxREMAP_BUTTON_COLOURS
63 #endif // !__WXWINCE__
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // these standard constants are not always defined in compilers headers
73 #define TBSTYLE_LIST 0x1000
74 #define TBSTYLE_FLAT 0x0800
77 #ifndef TBSTYLE_TRANSPARENT
78 #define TBSTYLE_TRANSPARENT 0x8000
81 #ifndef TBSTYLE_TOOLTIPS
82 #define TBSTYLE_TOOLTIPS 0x0100
87 #define TB_SETSTYLE (WM_USER + 56)
88 #define TB_GETSTYLE (WM_USER + 57)
92 #define TB_HITTEST (WM_USER + 69)
96 #define TB_GETMAXSIZE (WM_USER + 83)
99 // these values correspond to those used by comctl32.dll
100 #define DEFAULTBITMAPX 16
101 #define DEFAULTBITMAPY 15
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
119 style ( wxNO_BORDER | wxTB_HORIZONTAL)
128 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
129 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
130 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged
)
131 EVT_ERASE_BACKGROUND(wxToolBar::OnEraseBackground
)
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 class wxToolBarTool
: public wxToolBarToolBase
141 wxToolBarTool(wxToolBar
*tbar
,
143 const wxString
& label
,
144 const wxBitmap
& bmpNormal
,
145 const wxBitmap
& bmpDisabled
,
147 wxObject
*clientData
,
148 const wxString
& shortHelp
,
149 const wxString
& longHelp
)
150 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
151 clientData
, shortHelp
, longHelp
)
157 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
158 : wxToolBarToolBase(tbar
, control
, label
)
160 if ( IsControl() && !m_label
.empty() )
162 // create a control to render the control's label
163 m_staticText
= new wxStaticText
170 wxALIGN_CENTRE
| wxST_NO_AUTORESIZE
181 virtual ~wxToolBarTool()
186 virtual void SetLabel(const wxString
& label
)
188 if ( label
== m_label
)
191 wxToolBarToolBase::SetLabel(label
);
194 m_staticText
->SetLabel(label
);
196 // we need to update the label shown in the toolbar because it has a
197 // pointer to the internal buffer of the old label
199 // TODO: use TB_SETBUTTONINFO
202 wxStaticText
* GetStaticText()
204 wxASSERT_MSG( IsControl(),
205 _T("only makes sense for embedded control tools") );
210 // set/get the number of separators which we use to cover the space used by
211 // a control in the toolbar
212 void SetSeparatorsCount(size_t count
) { m_nSepCount
= count
; }
213 size_t GetSeparatorsCount() const { return m_nSepCount
; }
217 wxStaticText
*m_staticText
;
219 DECLARE_NO_COPY_CLASS(wxToolBarTool
)
222 // ============================================================================
224 // ============================================================================
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
230 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
231 const wxString
& label
,
232 const wxBitmap
& bmpNormal
,
233 const wxBitmap
& bmpDisabled
,
235 wxObject
*clientData
,
236 const wxString
& shortHelp
,
237 const wxString
& longHelp
)
239 return new wxToolBarTool(this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
240 clientData
, shortHelp
, longHelp
);
244 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
246 return new wxToolBarTool(this, control
, label
);
249 // ----------------------------------------------------------------------------
250 // wxToolBar construction
251 // ----------------------------------------------------------------------------
253 void wxToolBar::Init()
256 m_disabledImgList
= NULL
;
260 m_defaultWidth
= DEFAULTBITMAPX
;
261 m_defaultHeight
= DEFAULTBITMAPY
;
266 bool wxToolBar::Create(wxWindow
*parent
,
271 const wxString
& name
)
273 // common initialisation
274 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
279 // MSW-specific initialisation
280 if ( !MSWCreateToolbar(pos
, size
) )
283 wxSetCCUnicodeFormat(GetHwnd());
285 // workaround for flat toolbar on Windows XP classic style: we have to set
286 // the style after creating the control; doing it at creation time doesn't work
288 if ( style
& wxTB_FLAT
)
290 LRESULT style
= GetMSWToolbarStyle();
292 if ( !(style
& TBSTYLE_FLAT
) )
293 ::SendMessage(GetHwnd(), TB_SETSTYLE
, 0, style
| TBSTYLE_FLAT
);
295 #endif // wxUSE_UXTHEME
300 bool wxToolBar::MSWCreateToolbar(const wxPoint
& pos
, const wxSize
& size
)
302 if ( !MSWCreateControl(TOOLBARCLASSNAME
, wxEmptyString
, pos
, size
) )
305 // toolbar-specific post initialisation
306 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
308 #ifdef TB_SETEXTENDEDSTYLE
309 if ( wxApp::GetComCtl32Version() >= 471 )
310 ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_DRAWDDARROWS
);
316 void wxToolBar::Recreate()
318 const HWND hwndOld
= GetHwnd();
321 // we haven't been created yet, no need to recreate
325 // get the position and size before unsubclassing the old toolbar
326 const wxPoint pos
= GetPosition();
327 const wxSize size
= GetSize();
331 if ( !MSWCreateToolbar(pos
, size
) )
334 wxFAIL_MSG( _T("recreating the toolbar failed") );
339 // reparent all our children under the new toolbar
340 for ( wxWindowList::compatibility_iterator node
= m_children
.GetFirst();
342 node
= node
->GetNext() )
344 wxWindow
*win
= node
->GetData();
345 if ( !win
->IsTopLevel() )
346 ::SetParent(GetHwndOf(win
), GetHwnd());
349 // only destroy the old toolbar now --
350 // after all the children had been reparented
351 ::DestroyWindow(hwndOld
);
353 // it is for the old bitmap control and can't be used with the new one
356 ::DeleteObject((HBITMAP
) m_hBitmap
);
360 if ( m_disabledImgList
)
362 delete m_disabledImgList
;
363 m_disabledImgList
= NULL
;
369 wxToolBar::~wxToolBar()
371 // we must refresh the frame size when the toolbar is deleted but the frame
372 // is not - otherwise toolbar leaves a hole in the place it used to occupy
373 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
374 if ( frame
&& !frame
->IsBeingDeleted() )
375 frame
->SendSizeEvent();
378 ::DeleteObject((HBITMAP
) m_hBitmap
);
380 delete m_disabledImgList
;
383 wxSize
wxToolBar::DoGetBestSize() const
388 if ( !::SendMessage(GetHwnd(), TB_GETMAXSIZE
, 0, (LPARAM
)&size
) )
390 // maybe an old (< 0x400) Windows version? try to approximate the
391 // toolbar size ourselves
392 sizeBest
= GetToolSize();
393 sizeBest
.y
+= 2 * ::GetSystemMetrics(SM_CYBORDER
); // Add borders
394 sizeBest
.x
*= GetToolsCount();
396 // reverse horz and vertical components if necessary
400 sizeBest
.x
= sizeBest
.y
;
406 sizeBest
.x
= size
.cx
;
407 sizeBest
.y
= size
.cy
;
412 // Without the extra height, DoGetBestSize can report a size that's
413 // smaller than the actual window, causing windows to overlap slightly
414 // in some circumstances, leading to missing borders (especially noticeable
416 if (!(GetWindowStyle() & wxTB_NODIVIDER
))
421 CacheBestSize(sizeBest
);
426 WXDWORD
wxToolBar::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
428 // toolbars never have border, giving one to them results in broken
430 WXDWORD msStyle
= wxControl::MSWGetStyle
432 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exstyle
435 if ( !(style
& wxTB_NO_TOOLTIPS
) )
436 msStyle
|= TBSTYLE_TOOLTIPS
;
438 if ( style
& (wxTB_FLAT
| wxTB_HORZ_LAYOUT
) )
440 // static as it doesn't change during the program lifetime
441 static const int s_verComCtl
= wxApp::GetComCtl32Version();
443 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
444 // style with 6.00 (part of Windows XP) leads to the toolbar with
445 // incorrect background colour - and not using it still results in the
446 // correct (flat) toolbar, so don't use it there
447 if ( s_verComCtl
> 400 && s_verComCtl
< 600 )
448 msStyle
|= TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
;
450 if ( s_verComCtl
>= 470 && style
& wxTB_HORZ_LAYOUT
)
451 msStyle
|= TBSTYLE_LIST
;
454 if ( style
& wxTB_NODIVIDER
)
455 msStyle
|= CCS_NODIVIDER
;
457 if ( style
& wxTB_NOALIGN
)
458 msStyle
|= CCS_NOPARENTALIGN
;
460 if ( style
& wxTB_VERTICAL
)
463 if( style
& wxTB_BOTTOM
)
464 msStyle
|= CCS_BOTTOM
;
466 if ( style
& wxTB_RIGHT
)
467 msStyle
|= CCS_RIGHT
;
472 // ----------------------------------------------------------------------------
473 // adding/removing tools
474 // ----------------------------------------------------------------------------
476 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*tool
)
478 // nothing special to do here - we really create the toolbar buttons in
480 InvalidateBestSize();
484 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
486 // the main difficulty we have here is with the controls in the toolbars:
487 // as we (sometimes) use several separators to cover up the space used by
488 // them, the indices are not the same for us and the toolbar
490 // first determine the position of the first button to delete: it may be
491 // different from pos if we use several separators to cover the space used
493 wxToolBarToolsList::compatibility_iterator node
;
494 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
496 wxToolBarToolBase
*tool2
= node
->GetData();
499 // let node point to the next node in the list
500 node
= node
->GetNext();
505 if ( tool2
->IsControl() )
506 pos
+= ((wxToolBarTool
*)tool2
)->GetSeparatorsCount() - 1;
509 // now determine the number of buttons to delete and the area taken by them
510 size_t nButtonsToDelete
= 1;
512 // get the size of the button we're going to delete
514 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
516 wxLogLastError(_T("TB_GETITEMRECT"));
519 int width
= r
.right
- r
.left
;
521 if ( tool
->IsControl() )
523 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
524 width
*= nButtonsToDelete
;
527 // do delete all buttons
528 m_nButtons
-= nButtonsToDelete
;
529 while ( nButtonsToDelete
-- > 0 )
531 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
533 wxLogLastError(wxT("TB_DELETEBUTTON"));
539 // and finally reposition all the controls after this button (the toolbar
540 // takes care of all normal items)
541 for ( /* node -> first after deleted */ ; node
; node
= node
->GetNext() )
543 wxToolBarTool
*tool2
= (wxToolBarTool
*)node
->GetData();
544 if ( tool2
->IsControl() )
547 wxControl
*control
= tool2
->GetControl();
548 control
->GetPosition(&x
, NULL
);
549 control
->Move(x
- width
, wxDefaultCoord
);
551 wxStaticText
* staticText
= tool2
->GetStaticText();
552 staticText
->Move(x
- width
, wxDefaultCoord
);
556 InvalidateBestSize();
561 void wxToolBar::CreateDisabledImageList()
563 if (m_disabledImgList
!= NULL
)
565 delete m_disabledImgList
;
566 m_disabledImgList
= NULL
;
569 // as we can't use disabled image list with older versions of comctl32.dll,
570 // don't even bother creating it
571 if ( wxApp::GetComCtl32Version() >= 470 )
573 // search for the first disabled button img in the toolbar, if any
574 for ( wxToolBarToolsList::compatibility_iterator
575 node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
577 wxToolBarToolBase
*tool
= node
->GetData();
578 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
579 if ( bmpDisabled
.Ok() )
581 m_disabledImgList
= new wxImageList
585 bmpDisabled
.GetMask() != NULL
,
592 // we don't have any disabled bitmaps
596 bool wxToolBar::Realize()
598 const size_t nTools
= GetToolsCount();
603 #ifdef wxREMAP_BUTTON_COLOURS
604 // don't change the values of these constants, they can be set from the
605 // user code via wxSystemOptions
614 // the user-specified option overrides anything, but if it wasn't set, only
615 // remap the buttons on 8bpp displays as otherwise the bitmaps usually look
616 // much worse after remapping
617 static const wxChar
*remapOption
= wxT("msw.remap");
618 const int remapValue
= wxSystemOptions::HasOption(remapOption
)
619 ? wxSystemOptions::GetOptionInt(remapOption
)
620 : wxDisplayDepth() <= 8 ? Remap_Buttons
623 #endif // wxREMAP_BUTTON_COLOURS
625 // delete all old buttons, if any
626 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
628 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
630 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
634 // First, add the bitmap: we use one bitmap for all toolbar buttons
635 // ----------------------------------------------------------------
637 wxToolBarToolsList::compatibility_iterator node
;
641 if ( HasFlag(wxTB_NOICONS
) )
643 // no icons, don't leave space for them
647 else // do show icons
649 // if we already have a bitmap, we'll replace the existing one --
650 // otherwise we'll install a new one
651 HBITMAP oldToolBarBitmap
= (HBITMAP
)m_hBitmap
;
653 sizeBmp
.x
= m_defaultWidth
;
654 sizeBmp
.y
= m_defaultHeight
;
656 const wxCoord totalBitmapWidth
= m_defaultWidth
*
657 wx_truncate_cast(wxCoord
, nTools
),
658 totalBitmapHeight
= m_defaultHeight
;
660 // Create a bitmap and copy all the tool bitmaps into it
661 wxMemoryDC dcAllButtons
;
662 wxBitmap
bitmap(totalBitmapWidth
, totalBitmapHeight
);
663 dcAllButtons
.SelectObject(bitmap
);
665 #ifdef wxREMAP_BUTTON_COLOURS
666 if ( remapValue
!= Remap_TransparentBg
)
667 #endif // wxREMAP_BUTTON_COLOURS
669 // VZ: why do we hardcode grey colour for CE?
670 dcAllButtons
.SetBackground(wxBrush(
672 wxColour(0xc0, 0xc0, 0xc0)
673 #else // !__WXWINCE__
674 GetBackgroundColour()
675 #endif // __WXWINCE__/!__WXWINCE__
677 dcAllButtons
.Clear();
680 m_hBitmap
= bitmap
.GetHBITMAP();
681 HBITMAP hBitmap
= (HBITMAP
)m_hBitmap
;
683 #ifdef wxREMAP_BUTTON_COLOURS
684 if ( remapValue
== Remap_Bg
)
686 dcAllButtons
.SelectObject(wxNullBitmap
);
688 // Even if we're not remapping the bitmap
689 // content, we still have to remap the background.
690 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
691 totalBitmapWidth
, totalBitmapHeight
);
693 dcAllButtons
.SelectObject(bitmap
);
695 #endif // wxREMAP_BUTTON_COLOURS
697 // the button position
700 // the number of buttons (not separators)
703 CreateDisabledImageList();
704 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
706 wxToolBarToolBase
*tool
= node
->GetData();
707 if ( tool
->IsButton() )
709 const wxBitmap
& bmp
= tool
->GetNormalBitmap();
711 const int w
= bmp
.GetWidth();
712 const int h
= bmp
.GetHeight();
716 int xOffset
= wxMax(0, (m_defaultWidth
- w
)/2);
717 int yOffset
= wxMax(0, (m_defaultHeight
- h
)/2);
719 // notice the last parameter: do use mask
720 dcAllButtons
.DrawBitmap(bmp
, x
+ xOffset
, yOffset
, true);
724 wxFAIL_MSG( _T("invalid tool button bitmap") );
727 // also deal with disabled bitmap if we want to use them
728 if ( m_disabledImgList
)
730 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
731 #if wxUSE_IMAGE && wxUSE_WXDIB
732 if ( !bmpDisabled
.Ok() )
734 // no disabled bitmap specified but we still need to
735 // fill the space in the image list with something, so
736 // we grey out the normal bitmap
738 imgGreyed
= bmp
.ConvertToImage().ConvertToGreyscale();
740 #ifdef wxREMAP_BUTTON_COLOURS
741 if ( remapValue
== Remap_Buttons
)
743 // we need to have light grey background colour for
744 // MapBitmap() to work correctly
745 for ( int y
= 0; y
< h
; y
++ )
747 for ( int x
= 0; x
< w
; x
++ )
749 if ( imgGreyed
.IsTransparent(x
, y
) )
750 imgGreyed
.SetRGB(x
, y
,
752 wxLIGHT_GREY
->Green(),
753 wxLIGHT_GREY
->Blue());
757 #endif // wxREMAP_BUTTON_COLOURS
759 bmpDisabled
= wxBitmap(imgGreyed
);
761 #endif // wxUSE_IMAGE
763 #ifdef wxREMAP_BUTTON_COLOURS
764 if ( remapValue
== Remap_Buttons
)
765 MapBitmap(bmpDisabled
.GetHBITMAP(), w
, h
);
766 #endif // wxREMAP_BUTTON_COLOURS
768 m_disabledImgList
->Add(bmpDisabled
);
771 // still inc width and number of buttons because otherwise the
772 // subsequent buttons will all be shifted which is rather confusing
773 // (and like this you'd see immediately which bitmap was bad)
779 dcAllButtons
.SelectObject(wxNullBitmap
);
781 // don't delete this HBITMAP!
782 bitmap
.SetHBITMAP(0);
784 #ifdef wxREMAP_BUTTON_COLOURS
785 if ( remapValue
== Remap_Buttons
)
787 // Map to system colours
788 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
789 totalBitmapWidth
, totalBitmapHeight
);
791 #endif // wxREMAP_BUTTON_COLOURS
793 bool addBitmap
= true;
795 if ( oldToolBarBitmap
)
797 #ifdef TB_REPLACEBITMAP
798 if ( wxApp::GetComCtl32Version() >= 400 )
800 TBREPLACEBITMAP replaceBitmap
;
801 replaceBitmap
.hInstOld
= NULL
;
802 replaceBitmap
.hInstNew
= NULL
;
803 replaceBitmap
.nIDOld
= (UINT_PTR
)oldToolBarBitmap
;
804 replaceBitmap
.nIDNew
= (UINT_PTR
)hBitmap
;
805 replaceBitmap
.nButtons
= nButtons
;
806 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP
,
807 0, (LPARAM
) &replaceBitmap
) )
809 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
812 ::DeleteObject(oldToolBarBitmap
);
818 #endif // TB_REPLACEBITMAP
820 // we can't replace the old bitmap, so we will add another one
821 // (awfully inefficient, but what else to do?) and shift the bitmap
822 // indices accordingly
825 bitmapId
= m_nButtons
;
829 if ( addBitmap
) // no old bitmap or we can't replace it
831 TBADDBITMAP addBitmap
;
833 addBitmap
.nID
= (UINT_PTR
)hBitmap
;
834 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP
,
835 (WPARAM
) nButtons
, (LPARAM
)&addBitmap
) == -1 )
837 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
841 // disable image lists are only supported in comctl32.dll 4.70+
842 if ( wxApp::GetComCtl32Version() >= 470 )
844 HIMAGELIST hil
= m_disabledImgList
845 ? GetHimagelistOf(m_disabledImgList
)
848 // notice that we set the image list even if don't have one right
849 // now as we could have it before and need to reset it in this case
850 HIMAGELIST oldImageList
= (HIMAGELIST
)
851 ::SendMessage(GetHwnd(), TB_SETDISABLEDIMAGELIST
, 0, (LPARAM
)hil
);
853 // delete previous image list if any
855 ::DeleteObject(oldImageList
);
859 // don't call SetToolBitmapSize() as we don't want to change the values of
860 // m_defaultWidth/Height
861 if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0,
862 MAKELONG(sizeBmp
.x
, sizeBmp
.y
)) )
864 wxLogLastError(_T("TB_SETBITMAPSIZE"));
867 // Next add the buttons and separators
868 // -----------------------------------
870 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
872 // this array will hold the indices of all controls in the toolbar
873 wxArrayInt controlIds
;
875 bool lastWasRadio
= false;
877 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
879 wxToolBarToolBase
*tool
= node
->GetData();
881 // don't add separators to the vertical toolbar with old comctl32.dll
882 // versions as they didn't handle this properly
883 if ( IsVertical() && tool
->IsSeparator() &&
884 wxApp::GetComCtl32Version() <= 472 )
889 TBBUTTON
& button
= buttons
[i
];
891 wxZeroMemory(button
);
893 bool isRadio
= false;
894 switch ( tool
->GetStyle() )
896 case wxTOOL_STYLE_CONTROL
:
897 button
.idCommand
= tool
->GetId();
898 // fall through: create just a separator too
900 case wxTOOL_STYLE_SEPARATOR
:
901 button
.fsState
= TBSTATE_ENABLED
;
902 button
.fsStyle
= TBSTYLE_SEP
;
905 case wxTOOL_STYLE_BUTTON
:
906 if ( !HasFlag(wxTB_NOICONS
) )
907 button
.iBitmap
= bitmapId
;
909 if ( HasFlag(wxTB_TEXT
) )
911 const wxString
& label
= tool
->GetLabel();
912 if ( !label
.empty() )
913 button
.iString
= (INT_PTR
)label
.wx_str();
916 button
.idCommand
= tool
->GetId();
918 if ( tool
->IsEnabled() )
919 button
.fsState
|= TBSTATE_ENABLED
;
920 if ( tool
->IsToggled() )
921 button
.fsState
|= TBSTATE_CHECKED
;
923 switch ( tool
->GetKind() )
926 button
.fsStyle
= TBSTYLE_CHECKGROUP
;
930 // the first item in the radio group is checked by
931 // default to be consistent with wxGTK and the menu
933 button
.fsState
|= TBSTATE_CHECKED
;
935 if (tool
->Toggle(true))
937 DoToggleTool(tool
, true);
940 else if ( tool
->IsToggled() )
942 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
943 int prevIndex
= i
- 1;
946 TBBUTTON
& prevButton
= buttons
[prevIndex
];
947 wxToolBarToolBase
*tool
= nodePrev
->GetData();
948 if ( !tool
->IsButton() || tool
->GetKind() != wxITEM_RADIO
)
951 if ( tool
->Toggle(false) )
952 DoToggleTool(tool
, false);
954 prevButton
.fsState
&= ~TBSTATE_CHECKED
;
955 nodePrev
= nodePrev
->GetPrevious();
964 button
.fsStyle
= TBSTYLE_CHECK
;
968 button
.fsStyle
= TBSTYLE_BUTTON
;
971 case wxITEM_DROPDOWN
:
972 button
.fsStyle
= TBSTYLE_DROPDOWN
;
976 wxFAIL_MSG( _T("unexpected toolbar button kind") );
977 button
.fsStyle
= TBSTYLE_BUTTON
;
985 lastWasRadio
= isRadio
;
990 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS
, (WPARAM
)i
, (LPARAM
)buttons
) )
992 wxLogLastError(wxT("TB_ADDBUTTONS"));
997 // Deal with the controls finally
998 // ------------------------------
1000 // adjust the controls size to fit nicely in the toolbar
1003 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
1005 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1007 // we calculate the running y coord for vertical toolbars so we need to
1008 // get the items size for all items but for the horizontal ones we
1009 // don't need to deal with the non controls
1010 bool isControl
= tool
->IsControl();
1011 if ( !isControl
&& !IsVertical() )
1014 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
1015 // latter only appeared in v4.70 of comctl32.dll
1017 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1018 index
, (LPARAM
)(LPRECT
)&r
) )
1020 wxLogLastError(wxT("TB_GETITEMRECT"));
1025 // can only be control if isVertical
1026 y
+= r
.bottom
- r
.top
;
1031 wxControl
*control
= tool
->GetControl();
1032 wxStaticText
* const staticText
= tool
->GetStaticText();
1034 wxSize size
= control
->GetSize();
1035 wxSize staticTextSize
;
1038 staticTextSize
= staticText
->GetSize();
1039 staticTextSize
.y
+= 3; // margin between control and its label
1042 // the position of the leftmost controls corner
1043 int left
= wxDefaultCoord
;
1045 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
1046 #ifdef TB_SETBUTTONINFO
1047 // available in headers, now check whether it is available now
1048 // (during run-time)
1049 if ( wxApp::GetComCtl32Version() >= 471 )
1051 // set the (underlying) separators width to be that of the
1054 tbbi
.cbSize
= sizeof(tbbi
);
1055 tbbi
.dwMask
= TBIF_SIZE
;
1056 tbbi
.cx
= (WORD
)size
.x
;
1057 if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
1058 tool
->GetId(), (LPARAM
)&tbbi
) )
1060 // the id is probably invalid?
1061 wxLogLastError(wxT("TB_SETBUTTONINFO"));
1065 #endif // comctl32.dll 4.71
1066 // TB_SETBUTTONINFO unavailable
1068 // try adding several separators to fit the controls width
1069 int widthSep
= r
.right
- r
.left
;
1075 tbb
.fsState
= TBSTATE_ENABLED
;
1076 tbb
.fsStyle
= TBSTYLE_SEP
;
1078 size_t nSeparators
= size
.x
/ widthSep
;
1079 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
1081 if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON
,
1082 index
, (LPARAM
)&tbb
) )
1084 wxLogLastError(wxT("TB_INSERTBUTTON"));
1090 // remember the number of separators we used - we'd have to
1091 // delete all of them later
1092 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
1094 // adjust the controls width to exactly cover the separators
1095 size
.x
= (nSeparators
+ 1)*widthSep
;
1096 control
->SetSize(size
.x
, wxDefaultCoord
);
1099 // position the control itself correctly vertically centering it on the
1100 // icon area of the toolbar
1101 int height
= r
.bottom
- r
.top
- staticTextSize
.y
;
1103 int diff
= height
- size
.y
;
1104 if ( diff
< 0 || !HasFlag(wxTB_TEXT
) )
1106 // not enough room for the static text
1110 // recalculate height & diff without the staticText control
1111 height
= r
.bottom
- r
.top
;
1112 diff
= height
- size
.y
;
1115 // the control is too high, resize to fit
1116 control
->SetSize(wxDefaultCoord
, height
- 2);
1121 else // enough space for both the control and the label
1133 y
+= height
+ 2 * GetMargins().y
;
1135 else // horizontal toolbar
1137 if ( left
== wxDefaultCoord
)
1143 control
->Move(left
, top
+ (diff
+ 1) / 2);
1146 staticText
->Move(left
+ (size
.x
- staticTextSize
.x
)/2,
1147 r
.bottom
- staticTextSize
.y
);
1151 // the max index is the "real" number of buttons - i.e. counting even the
1152 // separators which we added just for aligning the controls
1155 if ( !IsVertical() )
1157 if ( m_maxRows
== 0 )
1158 // if not set yet, only one row
1161 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
1163 // if not set yet, have one column
1165 SetRows(m_nButtons
);
1168 InvalidateBestSize();
1174 // ----------------------------------------------------------------------------
1176 // ----------------------------------------------------------------------------
1178 bool wxToolBar::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD id_
)
1180 // cast to signed is important as we compare this id with (signed) ints in
1181 // FindById() and without the cast we'd get a positive int from a
1182 // "negative" (i.e. > 32767) WORD
1183 const int id
= (signed short)id_
;
1185 wxToolBarToolBase
*tool
= FindById(id
);
1189 bool toggled
= false; // just to suppress warnings
1191 if ( tool
->CanBeToggled() )
1193 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
1194 toggled
= (state
& TBSTATE_CHECKED
) != 0;
1196 // ignore the event when a radio button is released, as this doesn't
1197 // seem to happen at all, and is handled otherwise
1198 if ( tool
->GetKind() == wxITEM_RADIO
&& !toggled
)
1201 tool
->Toggle(toggled
);
1202 UnToggleRadioGroup(tool
);
1205 // OnLeftClick() can veto the button state change - for buttons which
1206 // may be toggled only, of couse
1207 if ( !OnLeftClick(id
, toggled
) && tool
->CanBeToggled() )
1210 tool
->Toggle(!toggled
);
1212 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(!toggled
, 0));
1218 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
1220 WXLPARAM
*WXUNUSED(result
))
1222 LPNMHDR hdr
= (LPNMHDR
)lParam
;
1223 if ( hdr
->code
== TBN_DROPDOWN
)
1225 LPNMTOOLBAR tbhdr
= (LPNMTOOLBAR
)lParam
;
1227 wxCommandEvent
evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, tbhdr
->iItem
);
1228 if ( HandleWindowEvent(evt
) )
1230 // Event got handled, don't display default popup menu
1234 const wxToolBarToolBase
* const tool
= FindById(tbhdr
->iItem
);
1235 wxCHECK_MSG( tool
, false, _T("drop down message for unknown tool") );
1237 wxMenu
* const menu
= tool
->GetDropdownMenu();
1241 // Display popup menu below button
1243 if (::SendMessage(GetHwnd(), TB_GETITEMRECT
, GetToolPos(tbhdr
->iItem
), (LPARAM
)&r
))
1244 PopupMenu(menu
, r
.left
, r
.bottom
);
1250 if( !HasFlag(wxTB_NO_TOOLTIPS
) )
1253 // First check if this applies to us
1255 // the tooltips control created by the toolbar is sometimes Unicode, even
1256 // in an ANSI application - this seems to be a bug in comctl32.dll v5
1257 UINT code
= hdr
->code
;
1258 if ( (code
!= (UINT
) TTN_NEEDTEXTA
) && (code
!= (UINT
) TTN_NEEDTEXTW
) )
1261 HWND toolTipWnd
= (HWND
)::SendMessage(GetHwnd(), TB_GETTOOLTIPS
, 0, 0);
1262 if ( toolTipWnd
!= hdr
->hwndFrom
)
1265 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
1266 int id
= (int)ttText
->hdr
.idFrom
;
1268 wxToolBarToolBase
*tool
= FindById(id
);
1270 return HandleTooltipNotify(code
, lParam
, tool
->GetShortHelp());
1272 wxUnusedVar(lParam
);
1279 // ----------------------------------------------------------------------------
1281 // ----------------------------------------------------------------------------
1283 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1285 wxToolBarBase::SetToolBitmapSize(size
);
1287 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
1290 void wxToolBar::SetRows(int nRows
)
1292 if ( nRows
== m_maxRows
)
1294 // avoid resizing the frame uselessly
1298 // TRUE in wParam means to create at least as many rows, FALSE -
1301 ::SendMessage(GetHwnd(), TB_SETROWS
,
1302 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
1310 // The button size is bigger than the bitmap size
1311 wxSize
wxToolBar::GetToolSize() const
1313 // TB_GETBUTTONSIZE is supported from version 4.70
1314 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
1315 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
1316 && !defined (__DIGITALMARS__)
1317 if ( wxApp::GetComCtl32Version() >= 470 )
1319 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
1321 return wxSize(LOWORD(dw
), HIWORD(dw
));
1324 #endif // comctl32.dll 4.70+
1327 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
1332 wxToolBarToolBase
*GetItemSkippingDummySpacers(const wxToolBarToolsList
& tools
,
1335 wxToolBarToolsList::compatibility_iterator current
= tools
.GetFirst();
1337 for ( ; current
; current
= current
->GetNext() )
1340 return current
->GetData();
1342 wxToolBarTool
*tool
= (wxToolBarTool
*)current
->GetData();
1343 size_t separators
= tool
->GetSeparatorsCount();
1345 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
1346 // otherwise, skip as many items as the separator count, plus the
1348 index
-= separators
? separators
+ 1 : 1;
1354 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1359 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
1361 // MBN: when the point ( x, y ) is close to the toolbar border
1362 // TB_HITTEST returns m_nButtons ( not -1 )
1363 if ( index
< 0 || (size_t)index
>= m_nButtons
)
1364 // it's a separator or there is no tool at all there
1365 return (wxToolBarToolBase
*)NULL
;
1367 // when TB_SETBUTTONINFO is available (both during compile- and run-time),
1368 // we don't use the dummy separators hack
1369 #ifdef TB_SETBUTTONINFO
1370 if ( wxApp::GetComCtl32Version() >= 471 )
1372 return m_tools
.Item((size_t)index
)->GetData();
1375 #endif // TB_SETBUTTONINFO
1377 return GetItemSkippingDummySpacers( m_tools
, (size_t) index
);
1381 void wxToolBar::UpdateSize()
1383 wxPoint pos
= GetPosition();
1384 ::SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
1385 if (pos
!= GetPosition())
1388 // In case Realize is called after the initial display (IOW the programmer
1389 // may have rebuilt the toolbar) give the frame the option of resizing the
1390 // toolbar to full width again, but only if the parent is a frame and the
1391 // toolbar is managed by the frame. Otherwise assume that some other
1392 // layout mechanism is controlling the toolbar size and leave it alone.
1393 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
1394 if ( frame
&& frame
->GetToolBar() == this )
1396 frame
->SendSizeEvent();
1400 // ----------------------------------------------------------------------------
1402 // ---------------------------------------------------------------------------
1404 // get the TBSTYLE of the given toolbar window
1405 long wxToolBar::GetMSWToolbarStyle() const
1407 return ::SendMessage(GetHwnd(), TB_GETSTYLE
, 0, 0L);
1410 void wxToolBar::SetWindowStyleFlag(long style
)
1412 // the style bits whose changes force us to recreate the toolbar
1413 static const long MASK_NEEDS_RECREATE
= wxTB_TEXT
| wxTB_NOICONS
;
1415 const long styleOld
= GetWindowStyle();
1417 wxToolBarBase::SetWindowStyleFlag(style
);
1419 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1420 // also fatal as we'd then try to recreate the toolbar when it's just being
1422 if ( GetToolsCount() &&
1423 (style
& MASK_NEEDS_RECREATE
) != (styleOld
& MASK_NEEDS_RECREATE
) )
1425 // to remove the text labels, simply re-realizing the toolbar is enough
1426 // but I don't know of any way to add the text to an existing toolbar
1427 // other than by recreating it entirely
1432 // ----------------------------------------------------------------------------
1434 // ----------------------------------------------------------------------------
1436 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
1438 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
1439 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
1442 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
1444 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
1445 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
1448 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1450 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1451 // without, so we really need to delete the button and recreate it here
1452 wxFAIL_MSG( _T("not implemented") );
1455 void wxToolBar::SetToolNormalBitmap( 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
->SetNormalBitmap(bitmap
);
1467 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1469 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1472 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1474 tool
->SetDisabledBitmap(bitmap
);
1479 // ----------------------------------------------------------------------------
1481 // ----------------------------------------------------------------------------
1483 // Responds to colour changes, and passes event on to children.
1484 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1486 wxRGBToColour(m_backgroundColour
, ::GetSysColor(COLOR_BTNFACE
));
1488 // Remap the buttons
1491 // Relayout the toolbar
1492 int nrows
= m_maxRows
;
1493 m_maxRows
= 0; // otherwise SetRows() wouldn't do anything
1498 // let the event propagate further
1502 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
1504 if ( event
.Leaving() )
1508 OnMouseEnter(wxID_ANY
);
1516 if ( event
.RightDown() )
1518 // find the tool under the mouse
1519 wxCoord x
= 0, y
= 0;
1520 event
.GetPosition(&x
, &y
);
1522 wxToolBarToolBase
*tool
= FindToolForPosition(x
, y
);
1523 OnRightClick(tool
? tool
->GetId() : -1, x
, y
);
1531 // This handler is required to allow the toolbar to be set to a non-default
1532 // colour: for example, when it must blend in with a notebook page.
1533 void wxToolBar::OnEraseBackground(wxEraseEvent
& event
)
1535 RECT rect
= wxGetClientRect(GetHwnd());
1537 wxDC
*dc
= event
.GetDC();
1539 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
->GetImpl();
1540 HDC hdc
= GetHdcOf(*impl
);
1542 int majorVersion
, minorVersion
;
1543 wxGetOsVersion(& majorVersion
, & minorVersion
);
1546 // we may need to draw themed colour so that we appear correctly on
1547 // e.g. notebook page under XP with themes but only do it if the parent
1548 // draws themed background itself
1549 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1551 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1555 hr
= theme
->DrawThemeParentBackground(GetHwnd(), hdc
, &rect
);
1559 // it can also return S_FALSE which seems to simply say that it
1560 // didn't draw anything but no error really occurred
1562 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1566 // Only draw a rebar theme on Vista, since it doesn't jive so well with XP
1567 if ( !UseBgCol() && majorVersion
>= 6 )
1569 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1572 wxUxThemeHandle
hTheme(this, L
"REBAR");
1575 wxRect rect
= GetClientRect();
1576 wxCopyRectToRECT(rect
, r
);
1578 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, hdc
, 0, 0, & r
, NULL
);
1582 // it can also return S_FALSE which seems to simply say that it
1583 // didn't draw anything but no error really occurred
1585 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1589 #endif // wxUSE_UXTHEME
1591 // we need to always draw our background under XP, as otherwise it doesn't
1592 // appear correctly with some themes (e.g. Zune one)
1593 if ( majorVersion
== 5 ||
1594 UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT
) )
1596 // do draw our background
1598 // notice that this 'dumb' implementation may cause flicker for some of
1599 // the controls in which case they should intercept wxEraseEvent and
1600 // process it themselves somehow
1601 AutoHBRUSH
hBrush(wxColourToRGB(GetBackgroundColour()));
1603 wxCHANGE_HDC_MAP_MODE(hdc
, MM_TEXT
);
1604 ::FillRect(hdc
, &rect
, hBrush
);
1606 else // we have no non default background colour
1608 // let the system do it for us
1613 bool wxToolBar::HandleSize(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1615 // calculate our minor dimension ourselves - we're confusing the standard
1616 // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks
1618 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT
, 0, (LPARAM
)&r
) )
1624 w
= r
.right
- r
.left
;
1627 w
*= (m_nButtons
+ m_maxRows
- 1)/m_maxRows
;
1634 if (HasFlag( wxTB_FLAT
))
1635 h
= r
.bottom
- r
.top
- 3;
1637 h
= r
.bottom
- r
.top
;
1640 // FIXME: hardcoded separator line height...
1641 h
+= HasFlag(wxTB_NODIVIDER
) ? 4 : 6;
1646 if ( MAKELPARAM(w
, h
) != lParam
)
1648 // size really changed
1652 // message processed
1659 bool wxToolBar::HandlePaint(WXWPARAM wParam
, WXLPARAM lParam
)
1661 // erase any dummy separators which were used
1662 // for aligning the controls if any here
1664 // first of all, are there any controls at all?
1665 wxToolBarToolsList::compatibility_iterator node
;
1666 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1668 if ( node
->GetData()->IsControl() )
1673 // no controls, nothing to erase
1676 wxSize clientSize
= GetClientSize();
1677 int majorVersion
, minorVersion
;
1678 wxGetOsVersion(& majorVersion
, & minorVersion
);
1680 // prepare the DC on which we'll be drawing
1681 wxClientDC
dc(this);
1682 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
1683 dc
.SetPen(*wxTRANSPARENT_PEN
);
1686 if ( !::GetUpdateRect(GetHwnd(), &r
, FALSE
) )
1687 // nothing to redraw anyhow
1691 wxCopyRECTToRect(r
, rectUpdate
);
1693 dc
.SetClippingRegion(rectUpdate
);
1695 // draw the toolbar tools, separators &c normally
1696 wxControl::MSWWindowProc(WM_PAINT
, wParam
, lParam
);
1698 // for each control in the toolbar find all the separators intersecting it
1701 // NB: this is really the only way to do it as we don't know if a separator
1702 // corresponds to a control (i.e. is a dummy one) or a real one
1704 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1706 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1707 if ( tool
->IsControl() )
1709 // get the control rect in our client coords
1710 wxControl
*control
= tool
->GetControl();
1711 wxStaticText
*staticText
= tool
->GetStaticText();
1712 wxRect rectCtrl
= control
->GetRect();
1713 wxRect
rectStaticText(0,0,0,0);
1716 rectStaticText
= staticText
->GetRect();
1719 // iterate over all buttons
1721 int count
= ::SendMessage(GetHwnd(), TB_BUTTONCOUNT
, 0, 0);
1722 for ( int n
= 0; n
< count
; n
++ )
1724 // is it a separator?
1725 if ( !::SendMessage(GetHwnd(), TB_GETBUTTON
,
1728 wxLogDebug(_T("TB_GETBUTTON failed?"));
1733 if ( tbb
.fsStyle
!= TBSTYLE_SEP
)
1736 // get the bounding rect of the separator
1738 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1741 wxLogDebug(_T("TB_GETITEMRECT failed?"));
1746 // does it intersect the control?
1748 wxCopyRECTToRect(r
, rectItem
);
1749 if ( rectCtrl
.Intersects(rectItem
) || (staticText
&& rectStaticText
.Intersects(rectItem
)))
1751 // yes, do erase it!
1753 bool haveRefreshed
= false;
1756 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1758 // Don't use DrawThemeBackground
1760 else if ( !UseBgCol() && majorVersion
>= 6 )
1762 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1765 wxUxThemeHandle
hTheme(this, L
"REBAR");
1769 // Draw the whole background since the pattern may be position sensitive;
1770 // but clip it to the area of interest.
1772 r
.right
= clientSize
.x
;
1774 r
.bottom
= clientSize
.y
;
1776 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
1777 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), 0, 0, & r
, & clipRect
);
1779 haveRefreshed
= true;
1785 dc
.DrawRectangle(rectItem
);
1788 if ( rectCtrl
.Intersects(rectItem
) )
1790 // Necessary in case we use a no-paint-on-size
1791 // style in the parent: the controls can disappear
1792 control
->Refresh(false);
1795 if ( staticText
&& rectStaticText
.Intersects(rectItem
) )
1797 // Necessary in case we use a no-paint-on-size
1798 // style in the parent: the controls can disappear
1799 staticText
->Refresh(false);
1808 void wxToolBar::HandleMouseMove(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1810 wxCoord x
= GET_X_LPARAM(lParam
),
1811 y
= GET_Y_LPARAM(lParam
);
1812 wxToolBarToolBase
* tool
= FindToolForPosition( x
, y
);
1814 // has the current tool changed?
1815 if ( tool
!= m_pInTool
)
1818 OnMouseEnter(tool
? tool
->GetId() : wxID_ANY
);
1822 WXLRESULT
wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1827 // we don't handle mouse moves, so always pass the message to
1828 // wxControl::MSWWindowProc (HandleMouseMove just calls OnMouseEnter)
1829 HandleMouseMove(wParam
, lParam
);
1833 if ( HandleSize(wParam
, lParam
) )
1839 if ( HandlePaint(wParam
, lParam
) )
1847 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1850 // ----------------------------------------------------------------------------
1851 // private functions
1852 // ----------------------------------------------------------------------------
1854 #ifdef wxREMAP_BUTTON_COLOURS
1856 WXHBITMAP
wxToolBar::MapBitmap(WXHBITMAP bitmap
, int width
, int height
)
1862 wxLogLastError(_T("CreateCompatibleDC"));
1867 SelectInHDC
bmpInHDC(hdcMem
, (HBITMAP
)bitmap
);
1871 wxLogLastError(_T("SelectObject"));
1876 wxCOLORMAP
*cmap
= wxGetStdColourMap();
1878 for ( int i
= 0; i
< width
; i
++ )
1880 for ( int j
= 0; j
< height
; j
++ )
1882 COLORREF pixel
= ::GetPixel(hdcMem
, i
, j
);
1884 for ( size_t k
= 0; k
< wxSTD_COL_MAX
; k
++ )
1886 COLORREF col
= cmap
[k
].from
;
1887 if ( abs(GetRValue(pixel
) - GetRValue(col
)) < 10 &&
1888 abs(GetGValue(pixel
) - GetGValue(col
)) < 10 &&
1889 abs(GetBValue(pixel
) - GetBValue(col
)) < 10 )
1891 if ( cmap
[k
].to
!= pixel
)
1892 ::SetPixel(hdcMem
, i
, j
, cmap
[k
].to
);
1902 #endif // wxREMAP_BUTTON_COLOURS
1904 #endif // wxUSE_TOOLBAR