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"
47 #include "wx/dcclient.h"
49 #include "wx/msw/private.h"
52 #include "wx/msw/uxtheme.h"
55 // this define controls whether the code for button colours remapping (only
56 // useful for 16 or 256 colour images) is active at all, it's always turned off
57 // for CE where it doesn't compile (and is probably not needed anyhow) and may
58 // also be turned off for other systems if you always use 24bpp images and so
61 #define wxREMAP_BUTTON_COLOURS
62 #endif // !__WXWINCE__
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // these standard constants are not always defined in compilers headers
72 #define TBSTYLE_LIST 0x1000
73 #define TBSTYLE_FLAT 0x0800
76 #ifndef TBSTYLE_TRANSPARENT
77 #define TBSTYLE_TRANSPARENT 0x8000
80 #ifndef TBSTYLE_TOOLTIPS
81 #define TBSTYLE_TOOLTIPS 0x0100
86 #define TB_SETSTYLE (WM_USER + 56)
87 #define TB_GETSTYLE (WM_USER + 57)
91 #define TB_HITTEST (WM_USER + 69)
95 #define TB_GETMAXSIZE (WM_USER + 83)
98 // these values correspond to those used by comctl32.dll
99 #define DEFAULTBITMAPX 16
100 #define DEFAULTBITMAPY 15
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
118 style ( wxNO_BORDER | wxTB_HORIZONTAL)
127 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
128 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
129 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged
)
130 EVT_ERASE_BACKGROUND(wxToolBar::OnEraseBackground
)
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 class wxToolBarTool
: public wxToolBarToolBase
140 wxToolBarTool(wxToolBar
*tbar
,
142 const wxString
& label
,
143 const wxBitmap
& bmpNormal
,
144 const wxBitmap
& bmpDisabled
,
146 wxObject
*clientData
,
147 const wxString
& shortHelp
,
148 const wxString
& longHelp
)
149 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
150 clientData
, shortHelp
, longHelp
)
156 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
, const wxString
& label
)
157 : wxToolBarToolBase(tbar
, control
, label
)
159 if ( IsControl() && !m_label
.empty() )
161 // create a control to render the control's label
162 m_staticText
= new wxStaticText
169 wxALIGN_CENTRE
| wxST_NO_AUTORESIZE
180 virtual ~wxToolBarTool()
185 virtual void SetLabel(const wxString
& label
)
187 if ( label
== m_label
)
190 wxToolBarToolBase::SetLabel(label
);
193 m_staticText
->SetLabel(label
);
195 // we need to update the label shown in the toolbar because it has a
196 // pointer to the internal buffer of the old label
198 // TODO: use TB_SETBUTTONINFO
201 wxStaticText
* GetStaticText()
203 wxASSERT_MSG( IsControl(),
204 _T("only makes sense for embedded control tools") );
209 // set/get the number of separators which we use to cover the space used by
210 // a control in the toolbar
211 void SetSeparatorsCount(size_t count
) { m_nSepCount
= count
; }
212 size_t GetSeparatorsCount() const { return m_nSepCount
; }
216 wxStaticText
*m_staticText
;
218 DECLARE_NO_COPY_CLASS(wxToolBarTool
)
221 // ============================================================================
223 // ============================================================================
225 // ----------------------------------------------------------------------------
227 // ----------------------------------------------------------------------------
229 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
230 const wxString
& label
,
231 const wxBitmap
& bmpNormal
,
232 const wxBitmap
& bmpDisabled
,
234 wxObject
*clientData
,
235 const wxString
& shortHelp
,
236 const wxString
& longHelp
)
238 return new wxToolBarTool(this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
239 clientData
, shortHelp
, longHelp
);
243 wxToolBar::CreateTool(wxControl
*control
, const wxString
& label
)
245 return new wxToolBarTool(this, control
, label
);
248 // ----------------------------------------------------------------------------
249 // wxToolBar construction
250 // ----------------------------------------------------------------------------
252 void wxToolBar::Init()
255 m_disabledImgList
= NULL
;
259 m_defaultWidth
= DEFAULTBITMAPX
;
260 m_defaultHeight
= DEFAULTBITMAPY
;
265 bool wxToolBar::Create(wxWindow
*parent
,
270 const wxString
& name
)
272 // common initialisation
273 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
278 // MSW-specific initialisation
279 if ( !MSWCreateToolbar(pos
, size
) )
282 wxSetCCUnicodeFormat(GetHwnd());
284 // workaround for flat toolbar on Windows XP classic style: we have to set
285 // the style after creating the control; doing it at creation time doesn't work
287 if ( style
& wxTB_FLAT
)
289 LRESULT style
= GetMSWToolbarStyle();
291 if ( !(style
& TBSTYLE_FLAT
) )
292 ::SendMessage(GetHwnd(), TB_SETSTYLE
, 0, style
| TBSTYLE_FLAT
);
294 #endif // wxUSE_UXTHEME
299 bool wxToolBar::MSWCreateToolbar(const wxPoint
& pos
, const wxSize
& size
)
301 if ( !MSWCreateControl(TOOLBARCLASSNAME
, wxEmptyString
, pos
, size
) )
304 // toolbar-specific post initialisation
305 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
307 #ifdef TB_SETEXTENDEDSTYLE
308 if ( wxApp::GetComCtl32Version() >= 471 )
309 ::SendMessage(GetHwnd(), TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_DRAWDDARROWS
);
315 void wxToolBar::Recreate()
317 const HWND hwndOld
= GetHwnd();
320 // we haven't been created yet, no need to recreate
324 // get the position and size before unsubclassing the old toolbar
325 const wxPoint pos
= GetPosition();
326 const wxSize size
= GetSize();
330 if ( !MSWCreateToolbar(pos
, size
) )
333 wxFAIL_MSG( _T("recreating the toolbar failed") );
338 // reparent all our children under the new toolbar
339 for ( wxWindowList::compatibility_iterator node
= m_children
.GetFirst();
341 node
= node
->GetNext() )
343 wxWindow
*win
= node
->GetData();
344 if ( !win
->IsTopLevel() )
345 ::SetParent(GetHwndOf(win
), GetHwnd());
348 // only destroy the old toolbar now --
349 // after all the children had been reparented
350 ::DestroyWindow(hwndOld
);
352 // it is for the old bitmap control and can't be used with the new one
355 ::DeleteObject((HBITMAP
) m_hBitmap
);
359 if ( m_disabledImgList
)
361 delete m_disabledImgList
;
362 m_disabledImgList
= NULL
;
368 wxToolBar::~wxToolBar()
370 // we must refresh the frame size when the toolbar is deleted but the frame
371 // is not - otherwise toolbar leaves a hole in the place it used to occupy
372 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
373 if ( frame
&& !frame
->IsBeingDeleted() )
374 frame
->SendSizeEvent();
377 ::DeleteObject((HBITMAP
) m_hBitmap
);
379 delete m_disabledImgList
;
382 wxSize
wxToolBar::DoGetBestSize() const
387 if ( !::SendMessage(GetHwnd(), TB_GETMAXSIZE
, 0, (LPARAM
)&size
) )
389 // maybe an old (< 0x400) Windows version? try to approximate the
390 // toolbar size ourselves
391 sizeBest
= GetToolSize();
392 sizeBest
.y
+= 2 * ::GetSystemMetrics(SM_CYBORDER
); // Add borders
393 sizeBest
.x
*= GetToolsCount();
395 // reverse horz and vertical components if necessary
399 sizeBest
.x
= sizeBest
.y
;
405 sizeBest
.x
= size
.cx
;
406 sizeBest
.y
= size
.cy
;
411 // Without the extra height, DoGetBestSize can report a size that's
412 // smaller than the actual window, causing windows to overlap slightly
413 // in some circumstances, leading to missing borders (especially noticeable
415 if (!(GetWindowStyle() & wxTB_NODIVIDER
))
420 CacheBestSize(sizeBest
);
425 WXDWORD
wxToolBar::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
427 // toolbars never have border, giving one to them results in broken
429 WXDWORD msStyle
= wxControl::MSWGetStyle
431 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exstyle
434 if ( !(style
& wxTB_NO_TOOLTIPS
) )
435 msStyle
|= TBSTYLE_TOOLTIPS
;
437 if ( style
& (wxTB_FLAT
| wxTB_HORZ_LAYOUT
) )
439 // static as it doesn't change during the program lifetime
440 static const int s_verComCtl
= wxApp::GetComCtl32Version();
442 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
443 // style with 6.00 (part of Windows XP) leads to the toolbar with
444 // incorrect background colour - and not using it still results in the
445 // correct (flat) toolbar, so don't use it there
446 if ( s_verComCtl
> 400 && s_verComCtl
< 600 )
447 msStyle
|= TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
;
449 if ( s_verComCtl
>= 470 && style
& wxTB_HORZ_LAYOUT
)
450 msStyle
|= TBSTYLE_LIST
;
453 if ( style
& wxTB_NODIVIDER
)
454 msStyle
|= CCS_NODIVIDER
;
456 if ( style
& wxTB_NOALIGN
)
457 msStyle
|= CCS_NOPARENTALIGN
;
459 if ( style
& wxTB_VERTICAL
)
462 if( style
& wxTB_BOTTOM
)
463 msStyle
|= CCS_BOTTOM
;
465 if ( style
& wxTB_RIGHT
)
466 msStyle
|= CCS_RIGHT
;
471 // ----------------------------------------------------------------------------
472 // adding/removing tools
473 // ----------------------------------------------------------------------------
475 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*tool
)
477 // nothing special to do here - we really create the toolbar buttons in
481 InvalidateBestSize();
485 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
487 // the main difficulty we have here is with the controls in the toolbars:
488 // as we (sometimes) use several separators to cover up the space used by
489 // them, the indices are not the same for us and the toolbar
491 // first determine the position of the first button to delete: it may be
492 // different from pos if we use several separators to cover the space used
494 wxToolBarToolsList::compatibility_iterator node
;
495 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
497 wxToolBarToolBase
*tool2
= node
->GetData();
500 // let node point to the next node in the list
501 node
= node
->GetNext();
506 if ( tool2
->IsControl() )
507 pos
+= ((wxToolBarTool
*)tool2
)->GetSeparatorsCount() - 1;
510 // now determine the number of buttons to delete and the area taken by them
511 size_t nButtonsToDelete
= 1;
513 // get the size of the button we're going to delete
515 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
517 wxLogLastError(_T("TB_GETITEMRECT"));
520 int width
= r
.right
- r
.left
;
522 if ( tool
->IsControl() )
524 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
525 width
*= nButtonsToDelete
;
526 tool
->GetControl()->Destroy();
529 // do delete all buttons
530 m_nButtons
-= nButtonsToDelete
;
531 while ( nButtonsToDelete
-- > 0 )
533 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
535 wxLogLastError(wxT("TB_DELETEBUTTON"));
543 // and finally reposition all the controls after this button (the toolbar
544 // takes care of all normal items)
545 for ( /* node -> first after deleted */ ; node
; node
= node
->GetNext() )
547 wxToolBarTool
*tool2
= (wxToolBarTool
*)node
->GetData();
548 if ( tool2
->IsControl() )
551 wxControl
*control
= tool2
->GetControl();
552 control
->GetPosition(&x
, NULL
);
553 control
->Move(x
- width
, wxDefaultCoord
);
555 wxStaticText
* staticText
= tool2
->GetStaticText();
556 staticText
->Move(x
- width
, wxDefaultCoord
);
560 InvalidateBestSize();
565 void wxToolBar::CreateDisabledImageList()
567 if (m_disabledImgList
!= NULL
)
569 delete m_disabledImgList
;
570 m_disabledImgList
= NULL
;
573 // as we can't use disabled image list with older versions of comctl32.dll,
574 // don't even bother creating it
575 if ( wxApp::GetComCtl32Version() >= 470 )
577 // search for the first disabled button img in the toolbar, if any
578 for ( wxToolBarToolsList::compatibility_iterator
579 node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
581 wxToolBarToolBase
*tool
= node
->GetData();
582 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
583 if ( bmpDisabled
.Ok() )
585 m_disabledImgList
= new wxImageList
589 bmpDisabled
.GetMask() != NULL
,
596 // we don't have any disabled bitmaps
600 bool wxToolBar::Realize()
602 const size_t nTools
= GetToolsCount();
607 #ifdef wxREMAP_BUTTON_COLOURS
608 // don't change the values of these constants, they can be set from the
609 // user code via wxSystemOptions
618 // the user-specified option overrides anything, but if it wasn't set, only
619 // remap the buttons on 8bpp displays as otherwise the bitmaps usually look
620 // much worse after remapping
621 static const wxChar
*remapOption
= wxT("msw.remap");
622 const int remapValue
= wxSystemOptions::HasOption(remapOption
)
623 ? wxSystemOptions::GetOptionInt(remapOption
)
624 : wxDisplayDepth() <= 8 ? Remap_Buttons
627 #endif // wxREMAP_BUTTON_COLOURS
629 // delete all old buttons, if any
630 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
632 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
634 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
638 // First, add the bitmap: we use one bitmap for all toolbar buttons
639 // ----------------------------------------------------------------
641 wxToolBarToolsList::compatibility_iterator node
;
645 if ( HasFlag(wxTB_NOICONS
) )
647 // no icons, don't leave space for them
651 else // do show icons
653 // if we already have a bitmap, we'll replace the existing one --
654 // otherwise we'll install a new one
655 HBITMAP oldToolBarBitmap
= (HBITMAP
)m_hBitmap
;
657 sizeBmp
.x
= m_defaultWidth
;
658 sizeBmp
.y
= m_defaultHeight
;
660 const wxCoord totalBitmapWidth
= m_defaultWidth
*
661 wx_truncate_cast(wxCoord
, nTools
),
662 totalBitmapHeight
= m_defaultHeight
;
664 // Create a bitmap and copy all the tool bitmaps into it
665 wxMemoryDC dcAllButtons
;
666 wxBitmap
bitmap(totalBitmapWidth
, totalBitmapHeight
);
667 dcAllButtons
.SelectObject(bitmap
);
669 #ifdef wxREMAP_BUTTON_COLOURS
670 if ( remapValue
!= Remap_TransparentBg
)
671 #endif // wxREMAP_BUTTON_COLOURS
673 // VZ: why do we hardcode grey colour for CE?
674 dcAllButtons
.SetBackground(wxBrush(
676 wxColour(0xc0, 0xc0, 0xc0)
677 #else // !__WXWINCE__
678 GetBackgroundColour()
679 #endif // __WXWINCE__/!__WXWINCE__
681 dcAllButtons
.Clear();
684 m_hBitmap
= bitmap
.GetHBITMAP();
685 HBITMAP hBitmap
= (HBITMAP
)m_hBitmap
;
687 #ifdef wxREMAP_BUTTON_COLOURS
688 if ( remapValue
== Remap_Bg
)
690 dcAllButtons
.SelectObject(wxNullBitmap
);
692 // Even if we're not remapping the bitmap
693 // content, we still have to remap the background.
694 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
695 totalBitmapWidth
, totalBitmapHeight
);
697 dcAllButtons
.SelectObject(bitmap
);
699 #endif // wxREMAP_BUTTON_COLOURS
701 // the button position
704 // the number of buttons (not separators)
707 CreateDisabledImageList();
708 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
710 wxToolBarToolBase
*tool
= node
->GetData();
711 if ( tool
->IsButton() )
713 const wxBitmap
& bmp
= tool
->GetNormalBitmap();
715 const int w
= bmp
.GetWidth();
716 const int h
= bmp
.GetHeight();
720 int xOffset
= wxMax(0, (m_defaultWidth
- w
)/2);
721 int yOffset
= wxMax(0, (m_defaultHeight
- h
)/2);
723 // notice the last parameter: do use mask
724 dcAllButtons
.DrawBitmap(bmp
, x
+ xOffset
, yOffset
, true);
728 wxFAIL_MSG( _T("invalid tool button bitmap") );
731 // also deal with disabled bitmap if we want to use them
732 if ( m_disabledImgList
)
734 wxBitmap bmpDisabled
= tool
->GetDisabledBitmap();
735 #if wxUSE_IMAGE && wxUSE_WXDIB
736 if ( !bmpDisabled
.Ok() )
738 // no disabled bitmap specified but we still need to
739 // fill the space in the image list with something, so
740 // we grey out the normal bitmap
742 imgGreyed
= bmp
.ConvertToImage().ConvertToGreyscale();
744 #ifdef wxREMAP_BUTTON_COLOURS
745 if ( remapValue
== Remap_Buttons
)
747 // we need to have light grey background colour for
748 // MapBitmap() to work correctly
749 for ( int y
= 0; y
< h
; y
++ )
751 for ( int x
= 0; x
< w
; x
++ )
753 if ( imgGreyed
.IsTransparent(x
, y
) )
754 imgGreyed
.SetRGB(x
, y
,
756 wxLIGHT_GREY
->Green(),
757 wxLIGHT_GREY
->Blue());
761 #endif // wxREMAP_BUTTON_COLOURS
763 bmpDisabled
= wxBitmap(imgGreyed
);
765 #endif // wxUSE_IMAGE
767 #ifdef wxREMAP_BUTTON_COLOURS
768 if ( remapValue
== Remap_Buttons
)
769 MapBitmap(bmpDisabled
.GetHBITMAP(), w
, h
);
770 #endif // wxREMAP_BUTTON_COLOURS
772 m_disabledImgList
->Add(bmpDisabled
);
775 // still inc width and number of buttons because otherwise the
776 // subsequent buttons will all be shifted which is rather confusing
777 // (and like this you'd see immediately which bitmap was bad)
783 dcAllButtons
.SelectObject(wxNullBitmap
);
785 // don't delete this HBITMAP!
786 bitmap
.SetHBITMAP(0);
788 #ifdef wxREMAP_BUTTON_COLOURS
789 if ( remapValue
== Remap_Buttons
)
791 // Map to system colours
792 hBitmap
= (HBITMAP
)MapBitmap((WXHBITMAP
) hBitmap
,
793 totalBitmapWidth
, totalBitmapHeight
);
795 #endif // wxREMAP_BUTTON_COLOURS
797 bool addBitmap
= true;
799 if ( oldToolBarBitmap
)
801 #ifdef TB_REPLACEBITMAP
802 if ( wxApp::GetComCtl32Version() >= 400 )
804 TBREPLACEBITMAP replaceBitmap
;
805 replaceBitmap
.hInstOld
= NULL
;
806 replaceBitmap
.hInstNew
= NULL
;
807 replaceBitmap
.nIDOld
= (UINT
) oldToolBarBitmap
;
808 replaceBitmap
.nIDNew
= (UINT
) hBitmap
;
809 replaceBitmap
.nButtons
= nButtons
;
810 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP
,
811 0, (LPARAM
) &replaceBitmap
) )
813 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
816 ::DeleteObject(oldToolBarBitmap
);
822 #endif // TB_REPLACEBITMAP
824 // we can't replace the old bitmap, so we will add another one
825 // (awfully inefficient, but what else to do?) and shift the bitmap
826 // indices accordingly
829 bitmapId
= m_nButtons
;
833 if ( addBitmap
) // no old bitmap or we can't replace it
835 TBADDBITMAP addBitmap
;
837 addBitmap
.nID
= (UINT
) hBitmap
;
838 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP
,
839 (WPARAM
) nButtons
, (LPARAM
)&addBitmap
) == -1 )
841 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
845 // disable image lists are only supported in comctl32.dll 4.70+
846 if ( wxApp::GetComCtl32Version() >= 470 )
848 HIMAGELIST hil
= m_disabledImgList
849 ? GetHimagelistOf(m_disabledImgList
)
852 // notice that we set the image list even if don't have one right
853 // now as we could have it before and need to reset it in this case
854 HIMAGELIST oldImageList
= (HIMAGELIST
)
855 ::SendMessage(GetHwnd(), TB_SETDISABLEDIMAGELIST
, 0, (LPARAM
)hil
);
857 // delete previous image list if any
859 ::DeleteObject(oldImageList
);
863 // don't call SetToolBitmapSize() as we don't want to change the values of
864 // m_defaultWidth/Height
865 if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0,
866 MAKELONG(sizeBmp
.x
, sizeBmp
.y
)) )
868 wxLogLastError(_T("TB_SETBITMAPSIZE"));
871 // Next add the buttons and separators
872 // -----------------------------------
874 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
876 // this array will hold the indices of all controls in the toolbar
877 wxArrayInt controlIds
;
879 bool lastWasRadio
= false;
881 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
883 wxToolBarToolBase
*tool
= node
->GetData();
885 // don't add separators to the vertical toolbar with old comctl32.dll
886 // versions as they didn't handle this properly
887 if ( IsVertical() && tool
->IsSeparator() &&
888 wxApp::GetComCtl32Version() <= 472 )
893 TBBUTTON
& button
= buttons
[i
];
895 wxZeroMemory(button
);
897 bool isRadio
= false;
898 switch ( tool
->GetStyle() )
900 case wxTOOL_STYLE_CONTROL
:
901 button
.idCommand
= tool
->GetId();
902 // fall through: create just a separator too
904 case wxTOOL_STYLE_SEPARATOR
:
905 button
.fsState
= TBSTATE_ENABLED
;
906 button
.fsStyle
= TBSTYLE_SEP
;
909 case wxTOOL_STYLE_BUTTON
:
910 if ( !HasFlag(wxTB_NOICONS
) )
911 button
.iBitmap
= bitmapId
;
913 if ( HasFlag(wxTB_TEXT
) )
915 const wxString
& label
= tool
->GetLabel();
916 if ( !label
.empty() )
917 button
.iString
= (int)label
.wx_str();
920 button
.idCommand
= tool
->GetId();
922 if ( tool
->IsEnabled() )
923 button
.fsState
|= TBSTATE_ENABLED
;
924 if ( tool
->IsToggled() )
925 button
.fsState
|= TBSTATE_CHECKED
;
927 switch ( tool
->GetKind() )
930 button
.fsStyle
= TBSTYLE_CHECKGROUP
;
934 // the first item in the radio group is checked by
935 // default to be consistent with wxGTK and the menu
937 button
.fsState
|= TBSTATE_CHECKED
;
939 if (tool
->Toggle(true))
941 DoToggleTool(tool
, true);
944 else if ( tool
->IsToggled() )
946 wxToolBarToolsList::compatibility_iterator nodePrev
= node
->GetPrevious();
947 int prevIndex
= i
- 1;
950 TBBUTTON
& prevButton
= buttons
[prevIndex
];
951 wxToolBarToolBase
*tool
= nodePrev
->GetData();
952 if ( !tool
->IsButton() || tool
->GetKind() != wxITEM_RADIO
)
955 if ( tool
->Toggle(false) )
956 DoToggleTool(tool
, false);
958 prevButton
.fsState
&= ~TBSTATE_CHECKED
;
959 nodePrev
= nodePrev
->GetPrevious();
968 button
.fsStyle
= TBSTYLE_CHECK
;
972 button
.fsStyle
= TBSTYLE_BUTTON
;
975 case wxITEM_DROPDOWN
:
976 button
.fsStyle
= TBSTYLE_DROPDOWN
;
980 wxFAIL_MSG( _T("unexpected toolbar button kind") );
981 button
.fsStyle
= TBSTYLE_BUTTON
;
989 lastWasRadio
= isRadio
;
994 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS
, (WPARAM
)i
, (LPARAM
)buttons
) )
996 wxLogLastError(wxT("TB_ADDBUTTONS"));
1001 // Deal with the controls finally
1002 // ------------------------------
1004 // adjust the controls size to fit nicely in the toolbar
1007 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
1009 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1011 // we calculate the running y coord for vertical toolbars so we need to
1012 // get the items size for all items but for the horizontal ones we
1013 // don't need to deal with the non controls
1014 bool isControl
= tool
->IsControl();
1015 if ( !isControl
&& !IsVertical() )
1018 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
1019 // latter only appeared in v4.70 of comctl32.dll
1021 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1022 index
, (LPARAM
)(LPRECT
)&r
) )
1024 wxLogLastError(wxT("TB_GETITEMRECT"));
1029 // can only be control if isVertical
1030 y
+= r
.bottom
- r
.top
;
1035 wxControl
*control
= tool
->GetControl();
1036 wxStaticText
* const staticText
= tool
->GetStaticText();
1038 wxSize size
= control
->GetSize();
1039 wxSize staticTextSize
;
1042 staticTextSize
= staticText
->GetSize();
1043 staticTextSize
.y
+= 3; // margin between control and its label
1046 // the position of the leftmost controls corner
1047 int left
= wxDefaultCoord
;
1049 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
1050 #ifdef TB_SETBUTTONINFO
1051 // available in headers, now check whether it is available now
1052 // (during run-time)
1053 if ( wxApp::GetComCtl32Version() >= 471 )
1055 // set the (underlying) separators width to be that of the
1058 tbbi
.cbSize
= sizeof(tbbi
);
1059 tbbi
.dwMask
= TBIF_SIZE
;
1060 tbbi
.cx
= (WORD
)size
.x
;
1061 if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
1062 tool
->GetId(), (LPARAM
)&tbbi
) )
1064 // the id is probably invalid?
1065 wxLogLastError(wxT("TB_SETBUTTONINFO"));
1069 #endif // comctl32.dll 4.71
1070 // TB_SETBUTTONINFO unavailable
1072 // try adding several separators to fit the controls width
1073 int widthSep
= r
.right
- r
.left
;
1079 tbb
.fsState
= TBSTATE_ENABLED
;
1080 tbb
.fsStyle
= TBSTYLE_SEP
;
1082 size_t nSeparators
= size
.x
/ widthSep
;
1083 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
1085 if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON
,
1086 index
, (LPARAM
)&tbb
) )
1088 wxLogLastError(wxT("TB_INSERTBUTTON"));
1094 // remember the number of separators we used - we'd have to
1095 // delete all of them later
1096 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
1098 // adjust the controls width to exactly cover the separators
1099 size
.x
= (nSeparators
+ 1)*widthSep
;
1100 control
->SetSize(size
.x
, wxDefaultCoord
);
1103 // position the control itself correctly vertically centering it on the
1104 // icon area of the toolbar
1105 int height
= r
.bottom
- r
.top
- staticTextSize
.y
;
1107 int diff
= height
- size
.y
;
1108 if ( diff
< 0 || !HasFlag(wxTB_TEXT
) )
1110 // not enough room for the static text
1114 // recalculate height & diff without the staticText control
1115 height
= r
.bottom
- r
.top
;
1116 diff
= height
- size
.y
;
1119 // the control is too high, resize to fit
1120 control
->SetSize(wxDefaultCoord
, height
- 2);
1125 else // enough space for both the control and the label
1137 y
+= height
+ 2 * GetMargins().y
;
1139 else // horizontal toolbar
1141 if ( left
== wxDefaultCoord
)
1147 control
->Move(left
, top
+ (diff
+ 1) / 2);
1150 staticText
->Move(left
+ (size
.x
- staticTextSize
.x
)/2,
1151 r
.bottom
- staticTextSize
.y
);
1155 // the max index is the "real" number of buttons - i.e. counting even the
1156 // separators which we added just for aligning the controls
1159 if ( !IsVertical() )
1161 if ( m_maxRows
== 0 )
1162 // if not set yet, only one row
1165 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
1167 // if not set yet, have one column
1169 SetRows(m_nButtons
);
1172 InvalidateBestSize();
1178 // ----------------------------------------------------------------------------
1180 // ----------------------------------------------------------------------------
1182 bool wxToolBar::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD id_
)
1184 // cast to signed is important as we compare this id with (signed) ints in
1185 // FindById() and without the cast we'd get a positive int from a
1186 // "negative" (i.e. > 32767) WORD
1187 const int id
= (signed short)id_
;
1189 wxToolBarToolBase
*tool
= FindById(id
);
1193 bool toggled
= false; // just to suppress warnings
1195 if ( tool
->CanBeToggled() )
1197 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
1198 toggled
= (state
& TBSTATE_CHECKED
) != 0;
1200 // ignore the event when a radio button is released, as this doesn't
1201 // seem to happen at all, and is handled otherwise
1202 if ( tool
->GetKind() == wxITEM_RADIO
&& !toggled
)
1205 tool
->Toggle(toggled
);
1206 UnToggleRadioGroup(tool
);
1209 // OnLeftClick() can veto the button state change - for buttons which
1210 // may be toggled only, of couse
1211 if ( !OnLeftClick(id
, toggled
) && tool
->CanBeToggled() )
1214 tool
->Toggle(!toggled
);
1216 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(!toggled
, 0));
1222 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
1224 WXLPARAM
*WXUNUSED(result
))
1226 LPNMHDR hdr
= (LPNMHDR
)lParam
;
1227 if ( hdr
->code
== TBN_DROPDOWN
)
1229 LPNMTOOLBAR tbhdr
= (LPNMTOOLBAR
)lParam
;
1231 wxCommandEvent
evt(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, tbhdr
->iItem
);
1232 if ( HandleWindowEvent(evt
) )
1234 // Event got handled, don't display default popup menu
1238 const wxToolBarToolBase
* const tool
= FindById(tbhdr
->iItem
);
1239 wxCHECK_MSG( tool
, false, _T("drop down message for unknown tool") );
1241 wxMenu
* const menu
= tool
->GetDropdownMenu();
1245 // Display popup menu below button
1247 if (::SendMessage(GetHwnd(), TB_GETITEMRECT
, GetToolPos(tbhdr
->iItem
), (LPARAM
)&r
))
1248 PopupMenu(menu
, r
.left
, r
.bottom
);
1254 if( !HasFlag(wxTB_NO_TOOLTIPS
) )
1257 // First check if this applies to us
1259 // the tooltips control created by the toolbar is sometimes Unicode, even
1260 // in an ANSI application - this seems to be a bug in comctl32.dll v5
1261 UINT code
= hdr
->code
;
1262 if ( (code
!= (UINT
) TTN_NEEDTEXTA
) && (code
!= (UINT
) TTN_NEEDTEXTW
) )
1265 HWND toolTipWnd
= (HWND
)::SendMessage(GetHwnd(), TB_GETTOOLTIPS
, 0, 0);
1266 if ( toolTipWnd
!= hdr
->hwndFrom
)
1269 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
1270 int id
= (int)ttText
->hdr
.idFrom
;
1272 wxToolBarToolBase
*tool
= FindById(id
);
1274 return HandleTooltipNotify(code
, lParam
, tool
->GetShortHelp());
1276 wxUnusedVar(lParam
);
1283 // ----------------------------------------------------------------------------
1285 // ----------------------------------------------------------------------------
1287 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
1289 wxToolBarBase::SetToolBitmapSize(size
);
1291 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
1294 void wxToolBar::SetRows(int nRows
)
1296 if ( nRows
== m_maxRows
)
1298 // avoid resizing the frame uselessly
1302 // TRUE in wParam means to create at least as many rows, FALSE -
1305 ::SendMessage(GetHwnd(), TB_SETROWS
,
1306 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
1314 // The button size is bigger than the bitmap size
1315 wxSize
wxToolBar::GetToolSize() const
1317 // TB_GETBUTTONSIZE is supported from version 4.70
1318 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
1319 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \
1320 && !defined (__DIGITALMARS__)
1321 if ( wxApp::GetComCtl32Version() >= 470 )
1323 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
1325 return wxSize(LOWORD(dw
), HIWORD(dw
));
1328 #endif // comctl32.dll 4.70+
1331 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
1336 wxToolBarToolBase
*GetItemSkippingDummySpacers(const wxToolBarToolsList
& tools
,
1339 wxToolBarToolsList::compatibility_iterator current
= tools
.GetFirst();
1341 for ( ; current
; current
= current
->GetNext() )
1344 return current
->GetData();
1346 wxToolBarTool
*tool
= (wxToolBarTool
*)current
->GetData();
1347 size_t separators
= tool
->GetSeparatorsCount();
1349 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
1350 // otherwise, skip as many items as the separator count, plus the
1352 index
-= separators
? separators
+ 1 : 1;
1358 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1363 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
1365 // MBN: when the point ( x, y ) is close to the toolbar border
1366 // TB_HITTEST returns m_nButtons ( not -1 )
1367 if ( index
< 0 || (size_t)index
>= m_nButtons
)
1368 // it's a separator or there is no tool at all there
1369 return (wxToolBarToolBase
*)NULL
;
1371 // when TB_SETBUTTONINFO is available (both during compile- and run-time),
1372 // we don't use the dummy separators hack
1373 #ifdef TB_SETBUTTONINFO
1374 if ( wxApp::GetComCtl32Version() >= 471 )
1376 return m_tools
.Item((size_t)index
)->GetData();
1379 #endif // TB_SETBUTTONINFO
1381 return GetItemSkippingDummySpacers( m_tools
, (size_t) index
);
1385 void wxToolBar::UpdateSize()
1387 wxPoint pos
= GetPosition();
1388 ::SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
1389 if (pos
!= GetPosition())
1392 // In case Realize is called after the initial display (IOW the programmer
1393 // may have rebuilt the toolbar) give the frame the option of resizing the
1394 // toolbar to full width again, but only if the parent is a frame and the
1395 // toolbar is managed by the frame. Otherwise assume that some other
1396 // layout mechanism is controlling the toolbar size and leave it alone.
1397 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
1398 if ( frame
&& frame
->GetToolBar() == this )
1400 frame
->SendSizeEvent();
1404 // ----------------------------------------------------------------------------
1406 // ---------------------------------------------------------------------------
1408 // get the TBSTYLE of the given toolbar window
1409 long wxToolBar::GetMSWToolbarStyle() const
1411 return ::SendMessage(GetHwnd(), TB_GETSTYLE
, 0, 0L);
1414 void wxToolBar::SetWindowStyleFlag(long style
)
1416 // the style bits whose changes force us to recreate the toolbar
1417 static const long MASK_NEEDS_RECREATE
= wxTB_TEXT
| wxTB_NOICONS
;
1419 const long styleOld
= GetWindowStyle();
1421 wxToolBarBase::SetWindowStyleFlag(style
);
1423 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1424 // also fatal as we'd then try to recreate the toolbar when it's just being
1426 if ( GetToolsCount() &&
1427 (style
& MASK_NEEDS_RECREATE
) != (styleOld
& MASK_NEEDS_RECREATE
) )
1429 // to remove the text labels, simply re-realizing the toolbar is enough
1430 // but I don't know of any way to add the text to an existing toolbar
1431 // other than by recreating it entirely
1436 // ----------------------------------------------------------------------------
1438 // ----------------------------------------------------------------------------
1440 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
1442 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
1443 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
1446 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
1448 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
1449 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
1452 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1454 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1455 // without, so we really need to delete the button and recreate it here
1456 wxFAIL_MSG( _T("not implemented") );
1459 void wxToolBar::SetToolNormalBitmap( int id
, const wxBitmap
& bitmap
)
1461 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1464 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1466 tool
->SetNormalBitmap(bitmap
);
1471 void wxToolBar::SetToolDisabledBitmap( int id
, const wxBitmap
& bitmap
)
1473 wxToolBarTool
* tool
= wx_static_cast(wxToolBarTool
*, FindById(id
));
1476 wxCHECK_RET( tool
->IsButton(), wxT("Can only set bitmap on button tools."));
1478 tool
->SetDisabledBitmap(bitmap
);
1483 // ----------------------------------------------------------------------------
1485 // ----------------------------------------------------------------------------
1487 // Responds to colour changes, and passes event on to children.
1488 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1490 wxRGBToColour(m_backgroundColour
, ::GetSysColor(COLOR_BTNFACE
));
1492 // Remap the buttons
1495 // Relayout the toolbar
1496 int nrows
= m_maxRows
;
1497 m_maxRows
= 0; // otherwise SetRows() wouldn't do anything
1502 // let the event propagate further
1506 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
1508 if ( event
.Leaving() )
1512 OnMouseEnter(wxID_ANY
);
1520 if ( event
.RightDown() )
1522 // find the tool under the mouse
1523 wxCoord x
= 0, y
= 0;
1524 event
.GetPosition(&x
, &y
);
1526 wxToolBarToolBase
*tool
= FindToolForPosition(x
, y
);
1527 OnRightClick(tool
? tool
->GetId() : -1, x
, y
);
1535 // This handler is required to allow the toolbar to be set to a non-default
1536 // colour: for example, when it must blend in with a notebook page.
1537 void wxToolBar::OnEraseBackground(wxEraseEvent
& event
)
1539 RECT rect
= wxGetClientRect(GetHwnd());
1541 wxDC
*dc
= event
.GetDC();
1543 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
->GetImpl();
1544 HDC hdc
= GetHdcOf(*impl
);
1546 int majorVersion
, minorVersion
;
1547 wxGetOsVersion(& majorVersion
, & minorVersion
);
1550 // we may need to draw themed colour so that we appear correctly on
1551 // e.g. notebook page under XP with themes but only do it if the parent
1552 // draws themed background itself
1553 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1555 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1559 hr
= theme
->DrawThemeParentBackground(GetHwnd(), hdc
, &rect
);
1563 // it can also return S_FALSE which seems to simply say that it
1564 // didn't draw anything but no error really occurred
1566 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1570 // Only draw a rebar theme on Vista, since it doesn't jive so well with XP
1571 if ( !UseBgCol() && majorVersion
>= 6 )
1573 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1576 wxUxThemeHandle
hTheme(this, L
"REBAR");
1579 wxRect rect
= GetClientRect();
1580 wxCopyRectToRECT(rect
, r
);
1582 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, hdc
, 0, 0, & r
, NULL
);
1586 // it can also return S_FALSE which seems to simply say that it
1587 // didn't draw anything but no error really occurred
1589 wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr
);
1593 #endif // wxUSE_UXTHEME
1595 if ( UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT
) )
1597 // do draw our background
1599 // notice that this 'dumb' implementation may cause flicker for some of
1600 // the controls in which case they should intercept wxEraseEvent and
1601 // process it themselves somehow
1602 AutoHBRUSH
hBrush(wxColourToRGB(GetBackgroundColour()));
1604 wxCHANGE_HDC_MAP_MODE(hdc
, MM_TEXT
);
1605 ::FillRect(hdc
, &rect
, hBrush
);
1607 else // we have no non default background colour
1609 // let the system do it for us
1614 bool wxToolBar::HandleSize(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1616 // calculate our minor dimension ourselves - we're confusing the standard
1617 // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks
1619 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT
, 0, (LPARAM
)&r
) )
1625 w
= r
.right
- r
.left
;
1628 w
*= (m_nButtons
+ m_maxRows
- 1)/m_maxRows
;
1635 if (HasFlag( wxTB_FLAT
))
1636 h
= r
.bottom
- r
.top
- 3;
1638 h
= r
.bottom
- r
.top
;
1641 // FIXME: hardcoded separator line height...
1642 h
+= HasFlag(wxTB_NODIVIDER
) ? 4 : 6;
1647 if ( MAKELPARAM(w
, h
) != lParam
)
1649 // size really changed
1653 // message processed
1660 bool wxToolBar::HandlePaint(WXWPARAM wParam
, WXLPARAM lParam
)
1662 // erase any dummy separators which were used
1663 // for aligning the controls if any here
1665 // first of all, are there any controls at all?
1666 wxToolBarToolsList::compatibility_iterator node
;
1667 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1669 if ( node
->GetData()->IsControl() )
1674 // no controls, nothing to erase
1677 wxSize clientSize
= GetClientSize();
1678 int majorVersion
, minorVersion
;
1679 wxGetOsVersion(& majorVersion
, & minorVersion
);
1681 // prepare the DC on which we'll be drawing
1682 wxClientDC
dc(this);
1683 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
1684 dc
.SetPen(*wxTRANSPARENT_PEN
);
1687 if ( !::GetUpdateRect(GetHwnd(), &r
, FALSE
) )
1688 // nothing to redraw anyhow
1692 wxCopyRECTToRect(r
, rectUpdate
);
1694 dc
.SetClippingRegion(rectUpdate
);
1696 // draw the toolbar tools, separators &c normally
1697 wxControl::MSWWindowProc(WM_PAINT
, wParam
, lParam
);
1699 // for each control in the toolbar find all the separators intersecting it
1702 // NB: this is really the only way to do it as we don't know if a separator
1703 // corresponds to a control (i.e. is a dummy one) or a real one
1705 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
1707 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->GetData();
1708 if ( tool
->IsControl() )
1710 // get the control rect in our client coords
1711 wxControl
*control
= tool
->GetControl();
1712 wxStaticText
*staticText
= tool
->GetStaticText();
1713 wxRect rectCtrl
= control
->GetRect();
1714 wxRect
rectStaticText(0,0,0,0);
1717 rectStaticText
= staticText
->GetRect();
1720 // iterate over all buttons
1722 int count
= ::SendMessage(GetHwnd(), TB_BUTTONCOUNT
, 0, 0);
1723 for ( int n
= 0; n
< count
; n
++ )
1725 // is it a separator?
1726 if ( !::SendMessage(GetHwnd(), TB_GETBUTTON
,
1729 wxLogDebug(_T("TB_GETBUTTON failed?"));
1734 if ( tbb
.fsStyle
!= TBSTYLE_SEP
)
1737 // get the bounding rect of the separator
1739 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
,
1742 wxLogDebug(_T("TB_GETITEMRECT failed?"));
1747 // does it intersect the control?
1749 wxCopyRECTToRect(r
, rectItem
);
1750 if ( rectCtrl
.Intersects(rectItem
) || (staticText
&& rectStaticText
.Intersects(rectItem
)))
1752 // yes, do erase it!
1754 bool haveRefreshed
= false;
1757 if ( !UseBgCol() && !GetParent()->UseBgCol() )
1759 // Don't use DrawThemeBackground
1761 else if ( !UseBgCol() && majorVersion
>= 6 )
1763 wxUxThemeEngine
*theme
= wxUxThemeEngine::GetIfActive();
1766 wxUxThemeHandle
hTheme(this, L
"REBAR");
1770 // Draw the whole background since the pattern may be position sensitive;
1771 // but clip it to the area of interest.
1773 r
.right
= clientSize
.x
;
1775 r
.bottom
= clientSize
.y
;
1777 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
1778 HRESULT hr
= theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), 0, 0, & r
, & clipRect
);
1780 haveRefreshed
= true;
1786 dc
.DrawRectangle(rectItem
);
1789 if ( rectCtrl
.Intersects(rectItem
) )
1791 // Necessary in case we use a no-paint-on-size
1792 // style in the parent: the controls can disappear
1793 control
->Refresh(false);
1796 if ( staticText
&& rectStaticText
.Intersects(rectItem
) )
1798 // Necessary in case we use a no-paint-on-size
1799 // style in the parent: the controls can disappear
1800 staticText
->Refresh(false);
1809 void wxToolBar::HandleMouseMove(WXWPARAM
WXUNUSED(wParam
), WXLPARAM lParam
)
1811 wxCoord x
= GET_X_LPARAM(lParam
),
1812 y
= GET_Y_LPARAM(lParam
);
1813 wxToolBarToolBase
* tool
= FindToolForPosition( x
, y
);
1815 // has the current tool changed?
1816 if ( tool
!= m_pInTool
)
1819 OnMouseEnter(tool
? tool
->GetId() : wxID_ANY
);
1823 WXLRESULT
wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1828 // we don't handle mouse moves, so always pass the message to
1829 // wxControl::MSWWindowProc (HandleMouseMove just calls OnMouseEnter)
1830 HandleMouseMove(wParam
, lParam
);
1834 if ( HandleSize(wParam
, lParam
) )
1840 if ( HandlePaint(wParam
, lParam
) )
1848 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1851 // ----------------------------------------------------------------------------
1852 // private functions
1853 // ----------------------------------------------------------------------------
1855 #ifdef wxREMAP_BUTTON_COLOURS
1857 WXHBITMAP
wxToolBar::MapBitmap(WXHBITMAP bitmap
, int width
, int height
)
1863 wxLogLastError(_T("CreateCompatibleDC"));
1868 SelectInHDC
bmpInHDC(hdcMem
, (HBITMAP
)bitmap
);
1872 wxLogLastError(_T("SelectObject"));
1877 wxCOLORMAP
*cmap
= wxGetStdColourMap();
1879 for ( int i
= 0; i
< width
; i
++ )
1881 for ( int j
= 0; j
< height
; j
++ )
1883 COLORREF pixel
= ::GetPixel(hdcMem
, i
, j
);
1885 for ( size_t k
= 0; k
< wxSTD_COL_MAX
; k
++ )
1887 COLORREF col
= cmap
[k
].from
;
1888 if ( abs(GetRValue(pixel
) - GetRValue(col
)) < 10 &&
1889 abs(GetGValue(pixel
) - GetGValue(col
)) < 10 &&
1890 abs(GetBValue(pixel
) - GetBValue(col
)) < 10 )
1892 if ( cmap
[k
].to
!= pixel
)
1893 ::SetPixel(hdcMem
, i
, j
, cmap
[k
].to
);
1903 #endif // wxREMAP_BUTTON_COLOURS
1905 #endif // wxUSE_TOOLBAR