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 #ifdef TB_SETEXTENDEDSTYLE
307 if ( wxApp::GetComCtl32Version() >= 471 )
308 ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_DRAWDDARROWS
);
311 // The toolbar background for some colour schemes cannot be determined
312 // (for example Silver). So set an explicit background colour to avoid parts of
313 // the background being painted wrongly.
315 int majorVersion
, minorVersion
;
316 wxGetOsVersion(& majorVersion
, & minorVersion
);
317 if (majorVersion
< 6)
318 SetBackgroundColour(GetBackgroundColour());
323 void wxToolBar::Recreate()
325 const HWND hwndOld
= GetHwnd();
328 // we haven't been created yet, no need to recreate
332 // get the position and size before unsubclassing the old toolbar
333 const wxPoint pos
= GetPosition();
334 const wxSize size
= GetSize();
338 if ( !MSWCreateToolbar(pos
, size
) )
341 wxFAIL_MSG( _T("recreating the toolbar failed") );
346 // reparent all our children under the new toolbar
347 for ( wxWindowList::compatibility_iterator node
= m_children
.GetFirst();
349 node
= node
->GetNext() )
351 wxWindow
*win
= node
->GetData();
352 if ( !win
->IsTopLevel() )
353 ::SetParent(GetHwndOf(win
), GetHwnd());
356 // only destroy the old toolbar now --
357 // after all the children had been reparented
358 ::DestroyWindow(hwndOld
);
360 // it is for the old bitmap control and can't be used with the new one
363 ::DeleteObject((HBITMAP
) m_hBitmap
);
367 if ( m_disabledImgList
)
369 delete m_disabledImgList
;
370 m_disabledImgList
= NULL
;
376 wxToolBar::~wxToolBar()
378 // we must refresh the frame size when the toolbar is deleted but the frame
379 // is not - otherwise toolbar leaves a hole in the place it used to occupy
380 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
381 if ( frame
&& !frame
->IsBeingDeleted() )
382 frame
->SendSizeEvent();
385 ::DeleteObject((HBITMAP
) m_hBitmap
);
387 delete m_disabledImgList
;
390 wxSize
wxToolBar::DoGetBestSize() const
395 if ( !::SendMessage(GetHwnd(), TB_GETMAXSIZE
, 0, (LPARAM
)&size
) )
397 // maybe an old (< 0x400) Windows version? try to approximate the
398 // toolbar size ourselves
399 sizeBest
= GetToolSize();
400 sizeBest
.y
+= 2 * ::GetSystemMetrics(SM_CYBORDER
); // Add borders
401 sizeBest
.x
*= GetToolsCount();
403 // reverse horz and vertical components if necessary
407 sizeBest
.x
= sizeBest
.y
;
413 sizeBest
.x
= size
.cx
;
414 sizeBest
.y
= size
.cy
;
419 // Without the extra height, DoGetBestSize can report a size that's
420 // smaller than the actual window, causing windows to overlap slightly
421 // in some circumstances, leading to missing borders (especially noticeable
423 if (!(GetWindowStyle() & wxTB_NODIVIDER
))
428 CacheBestSize(sizeBest
);
433 WXDWORD
wxToolBar::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
435 // toolbars never have border, giving one to them results in broken
437 WXDWORD msStyle
= wxControl::MSWGetStyle
439 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exstyle
442 if ( !(style
& wxTB_NO_TOOLTIPS
) )
443 msStyle
|= TBSTYLE_TOOLTIPS
;
445 if ( style
& (wxTB_FLAT
| wxTB_HORZ_LAYOUT
) )
447 // static as it doesn't change during the program lifetime
448 static const int s_verComCtl
= wxApp::GetComCtl32Version();
450 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
451 // style with 6.00 (part of Windows XP) leads to the toolbar with
452 // incorrect background colour - and not using it still results in the
453 // correct (flat) toolbar, so don't use it there
454 if ( s_verComCtl
> 400 && s_verComCtl
< 600 )
455 msStyle
|= TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
;
457 if ( s_verComCtl
>= 470 && style
& wxTB_HORZ_LAYOUT
)
458 msStyle
|= TBSTYLE_LIST
;
461 if ( style
& wxTB_NODIVIDER
)
462 msStyle
|= CCS_NODIVIDER
;
464 if ( style
& wxTB_NOALIGN
)
465 msStyle
|= CCS_NOPARENTALIGN
;
467 if ( style
& wxTB_VERTICAL
)
470 if( style
& wxTB_BOTTOM
)
471 msStyle
|= CCS_BOTTOM
;
473 if ( style
& wxTB_RIGHT
)
474 msStyle
|= CCS_RIGHT
;
479 // ----------------------------------------------------------------------------
480 // adding/removing tools
481 // ----------------------------------------------------------------------------
483 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*tool
)
485 // nothing special to do here - we really create the toolbar buttons in
489 InvalidateBestSize();
493 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
495 // the main difficulty we have here is with the controls in the toolbars:
496 // as we (sometimes) use several separators to cover up the space used by
497 // them, the indices are not the same for us and the toolbar
499 // first determine the position of the first button to delete: it may be
500 // different from pos if we use several separators to cover the space used
502 wxToolBarToolsList::compatibility_iterator node
;
503 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
505 wxToolBarToolBase
*tool2
= node
->GetData();
508 // let node point to the next node in the list
509 node
= node
->GetNext();
514 if ( tool2
->IsControl() )
515 pos
+= ((wxToolBarTool
*)tool2
)->GetSeparatorsCount() - 1;
518 // now determine the number of buttons to delete and the area taken by them
519 size_t nButtonsToDelete
= 1;
521 // get the size of the button we're going to delete
523 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
525 wxLogLastError(_T("TB_GETITEMRECT"));
528 int width
= r
.right
- r
.left
;
530 if ( tool
->IsControl() )
532 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
533 width
*= nButtonsToDelete
;
534 tool
->GetControl()->Destroy();
537 // do delete all buttons
538 m_nButtons
-= nButtonsToDelete
;
539 while ( nButtonsToDelete
-- > 0 )
541 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
543 wxLogLastError(wxT("TB_DELETEBUTTON"));
551 // and finally reposition all the controls after this button (the toolbar
552 // takes care of all normal items)
553 for ( /* node -> first after deleted */ ; node
; node
= node
->GetNext() )
555 wxToolBarTool
*tool2
= (wxToolBarTool
*)node
->GetData();
556 if ( tool2
->IsControl() )
559 wxControl
*control
= tool2
->GetControl();
560 control
->GetPosition(&x
, NULL
);
561 control
->Move(x
- width
, wxDefaultCoord
);
563 wxStaticText
* staticText
= tool2
->GetStaticText();
564 staticText
->Move(x
- width
, wxDefaultCoord
);
568 InvalidateBestSize();
573 void wxToolBar::CreateDisabledImageList()
575 if (m_disabledImgList
!= NULL
)
577 delete m_disabledImgList
;
578 m_disabledImgList
= NULL
;
581 // as we can't use disabled image list with older versions of comctl32.dll,
582 // don't even bother creating it
583 if ( wxApp::GetComCtl32Version() >= 470 )
585 // search for the first disabled button img in the toolbar, if any
586 for ( wxToolBarToolsList::compatibility_iterator
587 node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
589 wxToolBarToolBase
*tool
= node
->GetData();
590 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
591 if ( bmpDisabled
.Ok() )
593 m_disabledImgList
= new wxImageList
597 bmpDisabled
.GetMask() != NULL
,
604 // we don't have any disabled bitmaps
608 bool wxToolBar::Realize()
610 const size_t nTools
= GetToolsCount();
615 #ifdef wxREMAP_BUTTON_COLOURS
616 // don't change the values of these constants, they can be set from the
617 // user code via wxSystemOptions
626 // the user-specified option overrides anything, but if it wasn't set, only
627 // remap the buttons on 8bpp displays as otherwise the bitmaps usually look
628 // much worse after remapping
629 static const wxChar
*remapOption
= wxT("msw.remap");
630 const int remapValue
= wxSystemOptions::HasOption(remapOption
)
631 ? wxSystemOptions::GetOptionInt(remapOption
)
632 : wxDisplayDepth() <= 8 ? Remap_Buttons
635 #endif // wxREMAP_BUTTON_COLOURS
637 // delete all old buttons, if any
638 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
640 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
642 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
646 // First, add the bitmap: we use one bitmap for all toolbar buttons
647 // ----------------------------------------------------------------
649 wxToolBarToolsList::compatibility_iterator node
;
653 if ( HasFlag(wxTB_NOICONS
) )
655 // no icons, don't leave space for them
659 else // do show icons
661 // if we already have a bitmap, we'll replace the existing one --
662 // otherwise we'll install a new one
663 HBITMAP oldToolBarBitmap
= (HBITMAP
)m_hBitmap
;
665 sizeBmp
.x
= m_defaultWidth
;
666 sizeBmp
.y
= m_defaultHeight
;
668 const wxCoord totalBitmapWidth
= m_defaultWidth
*
669 wx_truncate_cast(wxCoord
, nTools
),
670 totalBitmapHeight
= m_defaultHeight
;
672 // Create a bitmap and copy all the tool bitmaps into it
673 wxMemoryDC dcAllButtons
;
674 wxBitmap
bitmap(totalBitmapWidth
, totalBitmapHeight
);
675 dcAllButtons
.SelectObject(bitmap
);
677 #ifdef wxREMAP_BUTTON_COLOURS
678 if ( remapValue
!= Remap_TransparentBg
)
679 #endif // wxREMAP_BUTTON_COLOURS
681 // VZ: why do we hardcode grey colour for CE?
682 dcAllButtons
.SetBackground(wxBrush(
684 wxColour(0xc0, 0xc0, 0xc0)
685 #else // !__WXWINCE__
686 GetBackgroundColour()
687 #endif // __WXWINCE__/!__WXWINCE__
689 dcAllButtons
.Clear();
692 m_hBitmap
= bitmap
.GetHBITMAP();
693 HBITMAP hBitmap
= (HBITMAP
)m_hBitmap
;
695 #ifdef wxREMAP_BUTTON_COLOURS
696 if ( remapValue
== Remap_Bg
)
698 dcAllButtons
.SelectObject(wxNullBitmap
);
700 // Even if we're not remapping the bitmap
701 // content, we still have to remap the background.
702 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
703 totalBitmapWidth
, totalBitmapHeight
);
705 dcAllButtons
.SelectObject(bitmap
);
707 #endif // wxREMAP_BUTTON_COLOURS
709 // the button position
712 // the number of buttons (not separators)
715 CreateDisabledImageList();
716 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
718 wxToolBarToolBase
*tool
= node
->GetData();
719 if ( tool
->IsButton() )
721 const wxBitmap
& bmp
= tool
->GetNormalBitmap();
723 const int w
= bmp
.GetWidth();
724 const int h
= bmp
.GetHeight();
728 int xOffset
= wxMax(0, (m_defaultWidth
- w
)/2);
729 int yOffset
= wxMax(0, (m_defaultHeight
- h
)/2);
731 // notice the last parameter: do use mask
732 dcAllButtons
.DrawBitmap(bmp
, x
+ xOffset
, yOffset
, true);
736 wxFAIL_MSG( _T("invalid tool button bitmap") );
739 // also deal with disabled bitmap if we want to use them
740 if ( m_disabledImgList
)
742 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
743 #if wxUSE_IMAGE && wxUSE_WXDIB
744 if ( !bmpDisabled
.Ok() )
746 // no disabled bitmap specified but we still need to
747 // fill the space in the image list with something, so
748 // we grey out the normal bitmap
750 imgGreyed
= bmp
.ConvertToImage().ConvertToGreyscale();
752 #ifdef wxREMAP_BUTTON_COLOURS
753 if ( remapValue
== Remap_Buttons
)
755 // we need to have light grey background colour for
756 // MapBitmap() to work correctly
757 for ( int y
= 0; y
< h
; y
++ )
759 for ( int x
= 0; x
< w
; x
++ )
761 if ( imgGreyed
.IsTransparent(x
, y
) )
762 imgGreyed
.SetRGB(x
, y
,
764 wxLIGHT_GREY
->Green(),
765 wxLIGHT_GREY
->Blue());
769 #endif // wxREMAP_BUTTON_COLOURS
771 bmpDisabled
= wxBitmap(imgGreyed
);
773 #endif // wxUSE_IMAGE
775 #ifdef wxREMAP_BUTTON_COLOURS
776 if ( remapValue
== Remap_Buttons
)
777 MapBitmap(bmpDisabled
.GetHBITMAP(), w
, h
);
778 #endif // wxREMAP_BUTTON_COLOURS
780 m_disabledImgList
->Add(bmpDisabled
);
783 // still inc width and number of buttons because otherwise the
784 // subsequent buttons will all be shifted which is rather confusing
785 // (and like this you'd see immediately which bitmap was bad)
791 dcAllButtons
.SelectObject(wxNullBitmap
);
793 // don't delete this HBITMAP!
794 bitmap
.SetHBITMAP(0);
796 #ifdef wxREMAP_BUTTON_COLOURS
797 if ( remapValue
== Remap_Buttons
)
799 // Map to system colours
800 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
801 totalBitmapWidth
, totalBitmapHeight
);
803 #endif // wxREMAP_BUTTON_COLOURS
805 bool addBitmap
= true;
807 if ( oldToolBarBitmap
)
809 #ifdef TB_REPLACEBITMAP
810 if ( wxApp::GetComCtl32Version() >= 400 )
812 TBREPLACEBITMAP replaceBitmap
;
813 replaceBitmap
.hInstOld
= NULL
;
814 replaceBitmap
.hInstNew
= NULL
;
815 replaceBitmap
.nIDOld
= (UINT
) oldToolBarBitmap
;
816 replaceBitmap
.nIDNew
= (UINT
) hBitmap
;
817 replaceBitmap
.nButtons
= nButtons
;
818 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP
,
819 0, (LPARAM
) &replaceBitmap
) )
821 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
824 ::DeleteObject(oldToolBarBitmap
);
830 #endif // TB_REPLACEBITMAP
832 // we can't replace the old bitmap, so we will add another one
833 // (awfully inefficient, but what else to do?) and shift the bitmap
834 // indices accordingly
837 bitmapId
= m_nButtons
;
841 if ( addBitmap
) // no old bitmap or we can't replace it
843 TBADDBITMAP addBitmap
;
845 addBitmap
.nID
= (UINT
) hBitmap
;
846 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP
,
847 (WPARAM
) nButtons
, (LPARAM
)&addBitmap
) == -1 )
849 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
853 // disable image lists are only supported in comctl32.dll 4.70+
854 if ( wxApp::GetComCtl32Version() >= 470 )
856 HIMAGELIST hil
= m_disabledImgList
857 ? GetHimagelistOf(m_disabledImgList
)
860 // notice that we set the image list even if don't have one right
861 // now as we could have it before and need to reset it in this case
862 HIMAGELIST oldImageList
= (HIMAGELIST
)
863 ::SendMessage(GetHwnd(), TB_SETDISABLEDIMAGELIST
, 0, (LPARAM
)hil
);
865 // delete previous image list if any
867 ::DeleteObject(oldImageList
);
871 // don't call SetToolBitmapSize() as we don't want to change the values of
872 // m_defaultWidth/Height
873 if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0,
874 MAKELONG(sizeBmp
.x
, sizeBmp
.y
)) )
876 wxLogLastError(_T("TB_SETBITMAPSIZE"));
879 // Next add the buttons and separators
880 // -----------------------------------
882 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
884 // this array will hold the indices of all controls in the toolbar
885 wxArrayInt controlIds
;
887 bool lastWasRadio
= false;
889 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
891 wxToolBarToolBase
*tool
= node
->GetData();
893 // don't add separators to the vertical toolbar with old comctl32.dll
894 // versions as they didn't handle this properly
895 if ( IsVertical() && tool
->IsSeparator() &&
896 wxApp::GetComCtl32Version() <= 472 )
901 TBBUTTON
& button
= buttons
[i
];
903 wxZeroMemory(button
);
905 bool isRadio
= false;
906 switch ( tool
->GetStyle() )
908 case wxTOOL_STYLE_CONTROL
:
909 button
.idCommand
= tool
->GetId();
910 // fall through: create just a separator too
912 case wxTOOL_STYLE_SEPARATOR
:
913 button
.fsState
= TBSTATE_ENABLED
;
914 button
.fsStyle
= TBSTYLE_SEP
;
917 case wxTOOL_STYLE_BUTTON
:
918 if ( !HasFlag(wxTB_NOICONS
) )
919 button
.iBitmap
= bitmapId
;
921 if ( HasFlag(wxTB_TEXT
) )
923 const wxString
& label
= tool
->GetLabel();
924 if ( !label
.empty() )
925 button
.iString
= (int)label
.wx_str();
928 button
.idCommand
= tool
->GetId();
930 if ( tool
->IsEnabled() )
931 button
.fsState
|= TBSTATE_ENABLED
;
932 if ( tool
->IsToggled() )
933 button
.fsState
|= TBSTATE_CHECKED
;
935 switch ( tool
->GetKind() )
938 button
.fsStyle
= TBSTYLE_CHECKGROUP
;
942 // the first item in the radio group is checked by
943 // default to be consistent with wxGTK and the menu
945 button
.fsState
|= TBSTATE_CHECKED
;
947 if (tool
->Toggle(true))
949 DoToggleTool(tool
, true);
952 else if ( tool
->IsToggled() )
954 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
955 int prevIndex
= i
- 1;
958 TBBUTTON
& prevButton
= buttons
[prevIndex
];
959 wxToolBarToolBase
*tool
= nodePrev
->GetData();
960 if ( !tool
->IsButton() || tool
->GetKind() != wxITEM_RADIO
)
963 if ( tool
->Toggle(false) )
964 DoToggleTool(tool
, false);
966 prevButton
.fsState
&= TBSTATE_CHECKED
;
967 nodePrev
= nodePrev
->GetPrevious();
976 button
.fsStyle
= TBSTYLE_CHECK
;
980 button
.fsStyle
= TBSTYLE_BUTTON
;
983 case wxITEM_DROPDOWN
:
984 button
.fsStyle
= TBSTYLE_DROPDOWN
;
988 wxFAIL_MSG( _T("unexpected toolbar button kind") );
989 button
.fsStyle
= TBSTYLE_BUTTON
;
997 lastWasRadio
= isRadio
;
1002 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS
, (WPARAM
)i
, (LPARAM
)buttons
) )
1004 wxLogLastError(wxT("TB_ADDBUTTONS"));
1009 // Deal with the controls finally
1010 // ------------------------------
1012 // adjust the controls size to fit nicely in the toolbar
1015 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
1017 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1019 // we calculate the running y coord for vertical toolbars so we need to
1020 // get the items size for all items but for the horizontal ones we
1021 // don't need to deal with the non controls
1022 bool isControl
= tool
->IsControl();
1023 if ( !isControl
&& !IsVertical() )
1026 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
1027 // latter only appeared in v4.70 of comctl32.dll
1029 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1030 index
, (LPARAM
)(LPRECT
)&r
) )
1032 wxLogLastError(wxT("TB_GETITEMRECT"));
1037 // can only be control if isVertical
1038 y
+= r
.bottom
- r
.top
;
1043 wxControl
*control
= tool
->GetControl();
1044 wxStaticText
* const staticText
= tool
->GetStaticText();
1046 wxSize size
= control
->GetSize();
1047 wxSize staticTextSize
;
1050 staticTextSize
= staticText
->GetSize();
1051 staticTextSize
.y
+= 3; // margin between control and its label
1054 // the position of the leftmost controls corner
1055 int left
= wxDefaultCoord
;
1057 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
1058 #ifdef TB_SETBUTTONINFO
1059 // available in headers, now check whether it is available now
1060 // (during run-time)
1061 if ( wxApp::GetComCtl32Version() >= 471 )
1063 // set the (underlying) separators width to be that of the
1066 tbbi
.cbSize
= sizeof(tbbi
);
1067 tbbi
.dwMask
= TBIF_SIZE
;
1068 tbbi
.cx
= (WORD
)size
.x
;
1069 if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
1070 tool
->GetId(), (LPARAM
)&tbbi
) )
1072 // the id is probably invalid?
1073 wxLogLastError(wxT("TB_SETBUTTONINFO"));
1077 #endif // comctl32.dll 4.71
1078 // TB_SETBUTTONINFO unavailable
1080 // try adding several separators to fit the controls width
1081 int widthSep
= r
.right
- r
.left
;
1087 tbb
.fsState
= TBSTATE_ENABLED
;
1088 tbb
.fsStyle
= TBSTYLE_SEP
;
1090 size_t nSeparators
= size
.x
/ widthSep
;
1091 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
1093 if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON
,
1094 index
, (LPARAM
)&tbb
) )
1096 wxLogLastError(wxT("TB_INSERTBUTTON"));
1102 // remember the number of separators we used - we'd have to
1103 // delete all of them later
1104 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
1106 // adjust the controls width to exactly cover the separators
1107 size
.x
= (nSeparators
+ 1)*widthSep
;
1108 control
->SetSize(size
.x
, wxDefaultCoord
);
1111 // position the control itself correctly vertically centering it on the
1112 // icon area of the toolbar
1113 int height
= r
.bottom
- r
.top
- staticTextSize
.y
;
1115 int diff
= height
- size
.y
;
1116 if ( diff
< 0 || !HasFlag(wxTB_TEXT
) )
1118 // not enough room for the static text
1122 // recalculate height & diff without the staticText control
1123 height
= r
.bottom
- r
.top
;
1124 diff
= height
- size
.y
;
1127 // the control is too high, resize to fit
1128 control
->SetSize(wxDefaultCoord
, height
- 2);
1133 else // enough space for both the control and the label
1145 y
+= height
+ 2 * GetMargins().y
;
1147 else // horizontal toolbar
1149 if ( left
== wxDefaultCoord
)
1155 control
->Move(left
, top
+ (diff
+ 1) / 2);
1158 staticText
->Move(left
+ (size
.x
- staticTextSize
.x
)/2,
1159 r
.bottom
- staticTextSize
.y
);
1163 // the max index is the "real" number of buttons - i.e. counting even the
1164 // separators which we added just for aligning the controls
1167 if ( !IsVertical() )
1169 if ( m_maxRows
== 0 )
1170 // if not set yet, only one row
1173 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
1175 // if not set yet, have one column
1177 SetRows(m_nButtons
);
1180 InvalidateBestSize();
1186 // ----------------------------------------------------------------------------
1188 // ----------------------------------------------------------------------------
1190 bool wxToolBar::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD id
)
1192 wxToolBarToolBase
*tool
= FindById((int)id
);
1196 bool toggled
= false; // just to suppress warnings
1198 if ( tool
->CanBeToggled() )
1200 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
1201 toggled
= (state
& TBSTATE_CHECKED
) != 0;
1203 // ignore the event when a radio button is released, as this doesn't
1204 // seem to happen at all, and is handled otherwise
1205 if ( tool
->GetKind() == wxITEM_RADIO
&& !toggled
)
1208 tool
->Toggle(toggled
);
1209 UnToggleRadioGroup(tool
);
1212 // OnLeftClick() can veto the button state change - for buttons which
1213 // may be toggled only, of couse
1214 if ( !OnLeftClick((int)id
, toggled
) && tool
->CanBeToggled() )
1217 tool
->Toggle(!toggled
);
1219 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(!toggled
, 0));
1225 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
1227 WXLPARAM
*WXUNUSED(result
))
1229 LPNMHDR hdr
= (LPNMHDR
)lParam
;
1230 if ( hdr
->code
== TBN_DROPDOWN
)
1232 LPNMTOOLBAR tbhdr
= (LPNMTOOLBAR
)lParam
;
1234 wxCommandEvent
evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, tbhdr
->iItem
);
1235 if ( GetEventHandler()->ProcessEvent(evt
) )
1237 // Event got handled, don't display default popup menu
1241 const wxToolBarToolBase
* const tool
= FindById(tbhdr
->iItem
);
1242 wxCHECK_MSG( tool
, false, _T("drop down message for unknown tool") );
1244 wxMenu
* const menu
= tool
->GetDropdownMenu();
1248 // Display popup menu below button
1250 if (::SendMessage(GetHwnd(), TB_GETITEMRECT
, GetToolPos(tbhdr
->iItem
), (LPARAM
)&r
))
1251 PopupMenu(menu
, r
.left
, r
.bottom
);
1257 if( !HasFlag(wxTB_NO_TOOLTIPS
) )
1260 // First check if this applies to us
1262 // the tooltips control created by the toolbar is sometimes Unicode, even
1263 // in an ANSI application - this seems to be a bug in comctl32.dll v5
1264 UINT code
= hdr
->code
;
1265 if ( (code
!= (UINT
) TTN_NEEDTEXTA
) && (code
!= (UINT
) TTN_NEEDTEXTW
) )
1268 HWND toolTipWnd
= (HWND
)::SendMessage(GetHwnd(), TB_GETTOOLTIPS
, 0, 0);
1269 if ( toolTipWnd
!= hdr
->hwndFrom
)
1272 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
1273 int id
= (int)ttText
->hdr
.idFrom
;
1275 wxToolBarToolBase
*tool
= FindById(id
);
1277 return HandleTooltipNotify(code
, lParam
, tool
->GetShortHelp());
1279 wxUnusedVar(lParam
);
1286 // ----------------------------------------------------------------------------
1288 // ----------------------------------------------------------------------------
1290 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1292 wxToolBarBase::SetToolBitmapSize(size
);
1294 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
1297 void wxToolBar::SetRows(int nRows
)
1299 if ( nRows
== m_maxRows
)
1301 // avoid resizing the frame uselessly
1305 // TRUE in wParam means to create at least as many rows, FALSE -
1308 ::SendMessage(GetHwnd(), TB_SETROWS
,
1309 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
1317 // The button size is bigger than the bitmap size
1318 wxSize
wxToolBar::GetToolSize() const
1320 // TB_GETBUTTONSIZE is supported from version 4.70
1321 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
1322 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
1323 && !defined (__DIGITALMARS__)
1324 if ( wxApp::GetComCtl32Version() >= 470 )
1326 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
1328 return wxSize(LOWORD(dw
), HIWORD(dw
));
1331 #endif // comctl32.dll 4.70+
1334 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
1339 wxToolBarToolBase
*GetItemSkippingDummySpacers(const wxToolBarToolsList
& tools
,
1342 wxToolBarToolsList::compatibility_iterator current
= tools
.GetFirst();
1344 for ( ; current
; current
= current
->GetNext() )
1347 return current
->GetData();
1349 wxToolBarTool
*tool
= (wxToolBarTool
*)current
->GetData();
1350 size_t separators
= tool
->GetSeparatorsCount();
1352 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
1353 // otherwise, skip as many items as the separator count, plus the
1355 index
-= separators
? separators
+ 1 : 1;
1361 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1366 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
1368 // MBN: when the point ( x, y ) is close to the toolbar border
1369 // TB_HITTEST returns m_nButtons ( not -1 )
1370 if ( index
< 0 || (size_t)index
>= m_nButtons
)
1371 // it's a separator or there is no tool at all there
1372 return (wxToolBarToolBase
*)NULL
;
1374 // when TB_SETBUTTONINFO is available (both during compile- and run-time),
1375 // we don't use the dummy separators hack
1376 #ifdef TB_SETBUTTONINFO
1377 if ( wxApp::GetComCtl32Version() >= 471 )
1379 return m_tools
.Item((size_t)index
)->GetData();
1382 #endif // TB_SETBUTTONINFO
1384 return GetItemSkippingDummySpacers( m_tools
, (size_t) index
);
1388 void wxToolBar::UpdateSize()
1390 wxPoint pos
= GetPosition();
1391 ::SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
1392 if (pos
!= GetPosition())
1395 // In case Realize is called after the initial display (IOW the programmer
1396 // may have rebuilt the toolbar) give the frame the option of resizing the
1397 // toolbar to full width again, but only if the parent is a frame and the
1398 // toolbar is managed by the frame. Otherwise assume that some other
1399 // layout mechanism is controlling the toolbar size and leave it alone.
1400 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
1401 if ( frame
&& frame
->GetToolBar() == this )
1403 frame
->SendSizeEvent();
1407 // ----------------------------------------------------------------------------
1409 // ---------------------------------------------------------------------------
1411 // get the TBSTYLE of the given toolbar window
1412 long wxToolBar::GetMSWToolbarStyle() const
1414 return ::SendMessage(GetHwnd(), TB_GETSTYLE
, 0, 0L);
1417 void wxToolBar::SetWindowStyleFlag(long style
)
1419 // the style bits whose changes force us to recreate the toolbar
1420 static const long MASK_NEEDS_RECREATE
= wxTB_TEXT
| wxTB_NOICONS
;
1422 const long styleOld
= GetWindowStyle();
1424 wxToolBarBase::SetWindowStyleFlag(style
);
1426 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1427 // also fatal as we'd then try to recreate the toolbar when it's just being
1429 if ( GetToolsCount() &&
1430 (style
& MASK_NEEDS_RECREATE
) != (styleOld
& MASK_NEEDS_RECREATE
) )
1432 // to remove the text labels, simply re-realizing the toolbar is enough
1433 // but I don't know of any way to add the text to an existing toolbar
1434 // other than by recreating it entirely
1439 // ----------------------------------------------------------------------------
1441 // ----------------------------------------------------------------------------
1443 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
1445 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
1446 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
1449 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
1451 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
1452 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
1455 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1457 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1458 // without, so we really need to delete the button and recreate it here
1459 wxFAIL_MSG( _T("not implemented") );
1462 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1464 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1467 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1469 tool
->SetNormalBitmap(bitmap
);
1474 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1476 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1479 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1481 tool
->SetDisabledBitmap(bitmap
);
1486 // ----------------------------------------------------------------------------
1488 // ----------------------------------------------------------------------------
1490 // Responds to colour changes, and passes event on to children.
1491 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1493 wxRGBToColour(m_backgroundColour
, ::GetSysColor(COLOR_BTNFACE
));
1495 // Remap the buttons
1498 // Relayout the toolbar
1499 int nrows
= m_maxRows
;
1500 m_maxRows
= 0; // otherwise SetRows() wouldn't do anything
1505 // let the event propagate further
1509 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
1511 if ( event
.Leaving() )
1515 OnMouseEnter(wxID_ANY
);
1523 if ( event
.RightDown() )
1525 // find the tool under the mouse
1526 wxCoord x
= 0, y
= 0;
1527 event
.GetPosition(&x
, &y
);
1529 wxToolBarToolBase
*tool
= FindToolForPosition(x
, y
);
1530 OnRightClick(tool
? tool
->GetId() : -1, x
, y
);
1538 // This handler is required to allow the toolbar to be set to a non-default
1539 // colour: for example, when it must blend in with a notebook page.
1540 void wxToolBar::OnEraseBackground(wxEraseEvent
& event
)
1542 RECT rect
= wxGetClientRect(GetHwnd());
1543 HDC hdc
= GetHdcOf((*event
.GetDC()));
1545 int majorVersion
, minorVersion
;
1546 wxGetOsVersion(& majorVersion
, & minorVersion
);
1549 // we may need to draw themed colour so that we appear correctly on
1550 // e.g. notebook page under XP with themes but only do it if the parent
1551 // draws themed background itself
1552 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1554 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1558 hr
= theme
->DrawThemeParentBackground(GetHwnd(), hdc
, &rect
);
1562 // it can also return S_FALSE which seems to simply say that it
1563 // didn't draw anything but no error really occurred
1565 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1569 // Only draw a rebar theme on Vista, since it doesn't jive so well with XP
1570 if ( !UseBgCol() && majorVersion
>= 6 )
1572 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1575 wxUxThemeHandle
hTheme(this, L
"REBAR");
1578 wxRect rect
= GetClientRect();
1579 wxCopyRectToRECT(rect
, r
);
1581 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, hdc
, 0, 0, & r
, NULL
);
1585 // it can also return S_FALSE which seems to simply say that it
1586 // didn't draw anything but no error really occurred
1588 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1592 #endif // wxUSE_UXTHEME
1594 if ( 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 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, (HDC
) dc
.GetHDC(), 0, 0, & r
, & clipRect
);
1778 haveRefreshed
= true;
1784 dc
.DrawRectangle(rectItem
);
1787 if ( rectCtrl
.Intersects(rectItem
) )
1789 // Necessary in case we use a no-paint-on-size
1790 // style in the parent: the controls can disappear
1791 control
->Refresh(false);
1794 if ( staticText
&& rectStaticText
.Intersects(rectItem
) )
1796 // Necessary in case we use a no-paint-on-size
1797 // style in the parent: the controls can disappear
1798 staticText
->Refresh(false);
1807 void wxToolBar::HandleMouseMove(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1809 wxCoord x
= GET_X_LPARAM(lParam
),
1810 y
= GET_Y_LPARAM(lParam
);
1811 wxToolBarToolBase
* tool
= FindToolForPosition( x
, y
);
1813 // has the current tool changed?
1814 if ( tool
!= m_pInTool
)
1817 OnMouseEnter(tool
? tool
->GetId() : wxID_ANY
);
1821 WXLRESULT
wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1826 // we don't handle mouse moves, so always pass the message to
1827 // wxControl::MSWWindowProc (HandleMouseMove just calls OnMouseEnter)
1828 HandleMouseMove(wParam
, lParam
);
1832 if ( HandleSize(wParam
, lParam
) )
1838 if ( HandlePaint(wParam
, lParam
) )
1846 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1849 // ----------------------------------------------------------------------------
1850 // private functions
1851 // ----------------------------------------------------------------------------
1853 #ifdef wxREMAP_BUTTON_COLOURS
1855 WXHBITMAP
wxToolBar::MapBitmap(WXHBITMAP bitmap
, int width
, int height
)
1861 wxLogLastError(_T("CreateCompatibleDC"));
1866 SelectInHDC
bmpInHDC(hdcMem
, (HBITMAP
)bitmap
);
1870 wxLogLastError(_T("SelectObject"));
1875 wxCOLORMAP
*cmap
= wxGetStdColourMap();
1877 for ( int i
= 0; i
< width
; i
++ )
1879 for ( int j
= 0; j
< height
; j
++ )
1881 COLORREF pixel
= ::GetPixel(hdcMem
, i
, j
);
1883 for ( size_t k
= 0; k
< wxSTD_COL_MAX
; k
++ )
1885 COLORREF col
= cmap
[k
].from
;
1886 if ( abs(GetRValue(pixel
) - GetRValue(col
)) < 10 &&
1887 abs(GetGValue(pixel
) - GetGValue(col
)) < 10 &&
1888 abs(GetBValue(pixel
) - GetBValue(col
)) < 10 )
1890 if ( cmap
[k
].to
!= pixel
)
1891 ::SetPixel(hdcMem
, i
, j
, cmap
[k
].to
);
1901 #endif // wxREMAP_BUTTON_COLOURS
1903 #endif // wxUSE_TOOLBAR