1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/wince/tbarwce.cpp
3 // Purpose: wxToolBar for Windows CE
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "tbarwce.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/dynarray.h"
36 #include "wx/settings.h"
37 #include "wx/bitmap.h"
38 #include "wx/dcmemory.h"
39 #include "wx/control.h"
42 // Use the WinCE-specific toolbar only if we're either compiling
43 // with a WinCE earlier than 4, or we wish to emulate a PocketPC-style UI
44 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
46 #include "wx/toolbar.h"
48 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
52 #include "wx/msw/private.h"
62 #include "wx/msw/wince/missing.h"
64 #include "wx/msw/winundef.h"
66 #if defined(__MWERKS__) && defined(__WXMSW__)
67 // including <windef.h> for max definition doesn't seem
68 // to work using CodeWarrior 6 Windows. So we define it
69 // here. (Otherwise we get a undefined identifier 'max'
70 // later on in this file.) (Added by dimitri@shortcut.nl)
72 # define max(a,b) (((a) > (b)) ? (a) : (b))
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // these standard constants are not always defined in compilers headers
85 #define TBSTYLE_LIST 0x1000
86 #define TBSTYLE_FLAT 0x0800
89 #ifndef TBSTYLE_TRANSPARENT
90 #define TBSTYLE_TRANSPARENT 0x8000
93 #ifndef TBSTYLE_TOOLTIPS
94 #define TBSTYLE_TOOLTIPS 0x0100
99 #define TB_SETSTYLE (WM_USER + 56)
100 #define TB_GETSTYLE (WM_USER + 57)
104 #define TB_HITTEST (WM_USER + 69)
107 // these values correspond to those used by comctl32.dll
108 #define DEFAULTBITMAPX 16
109 #define DEFAULTBITMAPY 15
110 #define DEFAULTBUTTONX 24
111 #define DEFAULTBUTTONY 24
112 #define DEFAULTBARHEIGHT 27
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
120 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
121 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
122 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged
)
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 class wxToolBarTool
: public wxToolBarToolBase
132 wxToolBarTool(wxToolBar
*tbar
,
134 const wxString
& label
,
135 const wxBitmap
& bmpNormal
,
136 const wxBitmap
& bmpDisabled
,
138 wxObject
*clientData
,
139 const wxString
& shortHelp
,
140 const wxString
& longHelp
)
141 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
142 clientData
, shortHelp
, longHelp
)
147 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
)
148 : wxToolBarToolBase(tbar
, control
)
153 virtual void SetLabel(const wxString
& label
)
155 if ( label
== m_label
)
158 wxToolBarToolBase::SetLabel(label
);
160 // we need to update the label shown in the toolbar because it has a
161 // pointer to the internal buffer of the old label
163 // TODO: use TB_SETBUTTONINFO
166 // set/get the number of separators which we use to cover the space used by
167 // a control in the toolbar
168 void SetSeparatorsCount(size_t count
) { m_nSepCount
= count
; }
169 size_t GetSeparatorsCount() const { return m_nSepCount
; }
176 // ============================================================================
178 // ============================================================================
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
185 const wxString
& label
,
186 const wxBitmap
& bmpNormal
,
187 const wxBitmap
& bmpDisabled
,
189 wxObject
*clientData
,
190 const wxString
& shortHelp
,
191 const wxString
& longHelp
)
193 return new wxToolBarTool(this, id
, label
, bmpNormal
, bmpDisabled
, kind
,
194 clientData
, shortHelp
, longHelp
);
197 wxToolBarToolBase
*wxToolBar::CreateTool(wxControl
*control
)
199 return new wxToolBarTool(this, control
);
202 // ----------------------------------------------------------------------------
203 // wxToolBar construction
204 // ----------------------------------------------------------------------------
206 void wxToolBar::Init()
212 m_defaultWidth
= DEFAULTBITMAPX
;
213 m_defaultHeight
= DEFAULTBITMAPY
;
219 bool wxToolBar::Create(wxWindow
*parent
,
224 const wxString
& name
,
227 // common initialisation
228 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
231 // MSW-specific initialisation
232 if ( !MSWCreateToolbar(pos
, size
, menuBar
) )
235 // set up the colors and fonts
236 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
237 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
242 #ifndef TBSTYLE_NO_DROPDOWN_ARROW
243 #define TBSTYLE_NO_DROPDOWN_ARROW 0x0080
246 bool wxToolBar::MSWCreateToolbar(const wxPoint
& pos
, const wxSize
& size
, wxMenuBar
* menuBar
)
250 m_menuBar
->SetToolBar(this);
252 #if _WIN32_WCE >= 400
253 HWND hWnd
= CommandBar_Create(wxGetInstance(), (HWND
) GetParent()->GetHWND(), GetId());
254 SetHWND((WXHWND
) hWnd
);
256 // Create the menubar.
259 memset (&mbi
, 0, sizeof (SHMENUBARINFO
));
260 mbi
.cbSize
= sizeof (SHMENUBARINFO
);
261 mbi
.hwndParent
= (HWND
) GetParent()->GetHWND();
263 mbi
.nToolBarId
= 5002;
265 mbi
.nToolBarId
= 5000;
269 mbi
.dwFlags
= 0 ; // SHCMBF_EMPTYBAR;
270 mbi
.hInstRes
= wxGetInstance();
272 if (!SHCreateMenuBar(&mbi
))
274 wxFAIL_MSG( _T("SHCreateMenuBar failed") );
278 SetHWND((WXHWND
) mbi
.hwndMB
);
281 // install wxWindows window proc for this window
290 void wxToolBar::Recreate()
293 const HWND hwndOld
= GetHwnd();
296 // we haven't been created yet, no need to recreate
300 // get the position and size before unsubclassing the old toolbar
301 const wxPoint pos
= GetPosition();
302 const wxSize size
= GetSize();
306 if ( !MSWCreateToolbar(pos
, size
) )
309 wxFAIL_MSG( _T("recreating the toolbar failed") );
314 // reparent all our children under the new toolbar
315 for ( wxWindowList::compatibility_iterator node
= m_children
.GetFirst();
317 node
= node
->GetNext() )
319 wxWindow
*win
= node
->GetData();
320 if ( !win
->IsTopLevel() )
321 ::SetParent(GetHwndOf(win
), GetHwnd());
324 // only destroy the old toolbar now -- after all the children had been
326 ::DestroyWindow(hwndOld
);
328 // it is for the old bitmap control and can't be used with the new one
331 ::DeleteObject((HBITMAP
) m_hBitmap
);
340 wxToolBar::~wxToolBar()
343 GetMenuBar()->SetToolBar(NULL
);
345 // we must refresh the frame size when the toolbar is deleted but the frame
346 // is not - otherwise toolbar leaves a hole in the place it used to occupy
347 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
348 if ( frame
&& !frame
->IsBeingDeleted() )
350 frame
->SendSizeEvent();
355 ::DeleteObject((HBITMAP
) m_hBitmap
);
359 wxSize
wxToolBar::DoGetBestSize() const
361 wxSize sizeBest
= GetToolSize();
362 sizeBest
.x
*= GetToolsCount();
364 // reverse horz and vertical components if necessary
365 return HasFlag(wxTB_VERTICAL
) ? wxSize(sizeBest
.y
, sizeBest
.x
) : sizeBest
;
368 // Return HMENU for the menu associated with the commandbar
369 WXHMENU
wxToolBar::GetHMenu()
373 return (WXHMENU
) (HMENU
)::SendMessage((HWND
) GetHWND(), SHCMBM_GETMENU
, (WPARAM
)0, (LPARAM
)0);
380 WXDWORD
wxToolBar::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
382 // toolbars never have border, giving one to them results in broken
384 WXDWORD msStyle
= wxControl::MSWGetStyle
386 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exstyle
389 // always include this one, it never hurts and setting it later only if we
390 // do have tooltips wouldn't work
391 msStyle
|= TBSTYLE_TOOLTIPS
;
393 if ( style
& (wxTB_FLAT
| wxTB_HORZ_LAYOUT
) )
395 // static as it doesn't change during the program lifetime
396 static int s_verComCtl
= wxTheApp
->GetComCtl32Version();
398 // comctl32.dll 4.00 doesn't support the flat toolbars and using this
399 // style with 6.00 (part of Windows XP) leads to the toolbar with
400 // incorrect background colour - and not using it still results in the
401 // correct (flat) toolbar, so don't use it there
402 if ( s_verComCtl
> 400 && s_verComCtl
< 600 )
404 msStyle
|= TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
;
407 if ( s_verComCtl
>= 470 && style
& wxTB_HORZ_LAYOUT
)
409 msStyle
|= TBSTYLE_LIST
;
413 if ( style
& wxTB_NODIVIDER
)
414 msStyle
|= CCS_NODIVIDER
;
416 if ( style
& wxTB_NOALIGN
)
417 msStyle
|= CCS_NOPARENTALIGN
;
419 if ( style
& wxTB_VERTICAL
)
425 // ----------------------------------------------------------------------------
426 // adding/removing tools
427 // ----------------------------------------------------------------------------
429 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
), wxToolBarToolBase
*tool
)
431 // nothing special to do here - we really create the toolbar buttons in
438 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
440 // the main difficulty we have here is with the controls in the toolbars:
441 // as we (sometimes) use several separators to cover up the space used by
442 // them, the indices are not the same for us and the toolbar
444 // first determine the position of the first button to delete: it may be
445 // different from pos if we use several separators to cover the space used
447 wxToolBarToolsList::compatibility_iterator node
;
448 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
450 wxToolBarToolBase
*tool2
= node
->GetData();
453 // let node point to the next node in the list
454 node
= node
->GetNext();
459 if ( tool2
->IsControl() )
461 pos
+= ((wxToolBarTool
*)tool2
)->GetSeparatorsCount() - 1;
465 // now determine the number of buttons to delete and the area taken by them
466 size_t nButtonsToDelete
= 1;
468 // get the size of the button we're going to delete
470 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
472 wxLogLastError(_T("TB_GETITEMRECT"));
475 int width
= r
.right
- r
.left
;
477 if ( tool
->IsControl() )
479 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
481 width
*= nButtonsToDelete
;
484 // do delete all buttons
485 m_nButtons
-= nButtonsToDelete
;
486 while ( nButtonsToDelete
-- > 0 )
488 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
490 wxLogLastError(wxT("TB_DELETEBUTTON"));
498 // and finally reposition all the controls after this button (the toolbar
499 // takes care of all normal items)
500 for ( /* node -> first after deleted */ ; node
; node
= node
->GetNext() )
502 wxToolBarToolBase
*tool2
= node
->GetData();
503 if ( tool2
->IsControl() )
506 wxControl
*control
= tool2
->GetControl();
507 control
->GetPosition(&x
, NULL
);
508 control
->Move(x
- width
, -1);
515 struct wxToolBarIdMapping
521 static wxToolBarIdMapping sm_ToolBarIdMappingArray
[] =
523 { wxID_COPY
, STD_COPY
},
524 { wxID_CUT
, STD_CUT
},
525 { wxID_FIND
, STD_FIND
},
526 { wxID_PASTE
, STD_PASTE
},
527 { wxID_NEW
, STD_FILENEW
},
528 { wxID_OPEN
, STD_FILEOPEN
},
529 { wxID_SAVE
, STD_FILESAVE
},
530 { wxID_PRINT
, STD_PRINT
},
531 { wxID_PREVIEW
, STD_PRINTPRE
},
532 { wxID_UNDO
, STD_UNDO
},
533 { wxID_REDO
, STD_REDOW
},
534 { wxID_HELP
, STD_HELP
},
535 { wxID_DELETE
, STD_DELETE
},
536 { wxID_REPLACE
, STD_REPLACE
},
537 { wxID_PROPERTIES
, STD_PROPERTIES
},
538 { wxID_VIEW_DETAILS
, VIEW_DETAILS
},
539 { wxID_VIEW_SORTDATE
, VIEW_SORTDATE
},
540 { wxID_VIEW_LARGEICONS
, VIEW_LARGEICONS
},
541 { wxID_VIEW_SORTNAME
, VIEW_SORTNAME
},
542 { wxID_VIEW_LIST
, VIEW_LIST
},
543 { wxID_VIEW_SORTSIZE
, VIEW_SORTSIZE
},
544 { wxID_VIEW_SMALLICONS
, VIEW_SMALLICONS
},
545 { wxID_VIEW_SORTTYPE
, VIEW_SORTTYPE
},
549 static int wxFindIdForwxWinId(int id
)
554 if (sm_ToolBarIdMappingArray
[i
].m_wxwinId
== 0)
556 else if (sm_ToolBarIdMappingArray
[i
].m_wxwinId
== id
)
557 return sm_ToolBarIdMappingArray
[i
].m_winceId
;
564 bool wxToolBar::Realize()
566 const size_t nTools
= GetToolsCount();
573 const bool isVertical
= HasFlag(wxTB_VERTICAL
);
576 // delete all old buttons, if any
577 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
579 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
581 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
586 // add the buttons and separators
587 // ------------------------------
589 // Use standard buttons
590 CommandBar_AddBitmap((HWND
) GetHWND(), HINST_COMMCTRL
,
591 IDB_STD_SMALL_COLOR
, 0, 16, 16);
593 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
595 // this array will hold the indices of all controls in the toolbar
596 wxArrayInt controlIds
;
598 bool lastWasRadio
= FALSE
;
600 wxToolBarToolsList::Node
* node
;
601 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
603 wxToolBarToolBase
*tool
= node
->GetData();
605 bool processedThis
= TRUE
;
607 TBBUTTON
& button
= buttons
[i
];
609 wxZeroMemory(button
);
611 bool isRadio
= FALSE
;
612 switch ( tool
->GetStyle() )
614 case wxTOOL_STYLE_CONTROL
:
615 button
.idCommand
= tool
->GetId();
616 // fall through: create just a separator too
618 case wxTOOL_STYLE_SEPARATOR
:
619 button
.fsState
= TBSTATE_ENABLED
;
620 button
.fsStyle
= TBSTYLE_SEP
;
623 case wxTOOL_STYLE_BUTTON
:
624 // if ( !HasFlag(wxTB_NOICONS) )
625 // button.iBitmap = bitmapId;
627 if ( HasFlag(wxTB_TEXT
) )
629 const wxString
& label
= tool
->GetLabel();
630 if ( !label
.empty() )
632 button
.iString
= (int)label
.c_str();
636 int winceId
= wxFindIdForwxWinId(tool
->GetId());
639 button
.idCommand
= tool
->GetId();
640 // if ( !HasFlag(wxTB_NOICONS) )
641 button
.iBitmap
= winceId
;
644 processedThis
= FALSE
;
646 if ( tool
->IsEnabled() )
647 button
.fsState
|= TBSTATE_ENABLED
;
648 if ( tool
->IsToggled() )
649 button
.fsState
|= TBSTATE_CHECKED
;
651 switch ( tool
->GetKind() )
654 button
.fsStyle
= TBSTYLE_CHECKGROUP
;
658 // the first item in the radio group is checked by
659 // default to be consistent with wxGTK and the menu
661 button
.fsState
|= TBSTATE_CHECKED
;
670 button
.fsStyle
= TBSTYLE_CHECK
;
674 wxFAIL_MSG( _T("unexpected toolbar button kind") );
678 button
.fsStyle
= TBSTYLE_BUTTON
;
685 lastWasRadio
= isRadio
;
691 // Add buttons to Commandbar
692 if (!CommandBar_AddButtons(GetHwnd(), i
, buttons
))
694 wxLogLastError(wxT("CommandBar_AddButtons"));
700 // Deal with the controls finally
701 // ------------------------------
703 // adjust the controls size to fit nicely in the toolbar
706 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
708 wxToolBarToolBase
*tool
= node
->GetData();
710 // we calculate the running y coord for vertical toolbars so we need to
711 // get the items size for all items but for the horizontal ones we
712 // don't need to deal with the non controls
713 bool isControl
= tool
->IsControl();
714 if ( !isControl
&& !isVertical
)
717 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
718 // latter only appeared in v4.70 of comctl32.dll
720 if ( !SendMessage(GetHwnd(), TB_GETITEMRECT
,
721 index
, (LPARAM
)(LPRECT
)&r
) )
723 wxLogLastError(wxT("TB_GETITEMRECT"));
728 // can only be control if isVertical
729 y
+= r
.bottom
- r
.top
;
734 wxControl
*control
= tool
->GetControl();
736 wxSize size
= control
->GetSize();
738 // the position of the leftmost controls corner
741 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
742 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
743 // available in headers, now check whether it is available now
745 if ( wxTheApp
->GetComCtl32Version() >= 471 )
747 // set the (underlying) separators width to be that of the
750 tbbi
.cbSize
= sizeof(tbbi
);
751 tbbi
.dwMask
= TBIF_SIZE
;
753 if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
754 tool
->GetId(), (LPARAM
)&tbbi
) )
756 // the id is probably invalid?
757 wxLogLastError(wxT("TB_SETBUTTONINFO"));
761 #endif // comctl32.dll 4.71
762 // TB_SETBUTTONINFO unavailable
764 // try adding several separators to fit the controls width
765 int widthSep
= r
.right
- r
.left
;
771 tbb
.fsState
= TBSTATE_ENABLED
;
772 tbb
.fsStyle
= TBSTYLE_SEP
;
774 size_t nSeparators
= size
.x
/ widthSep
;
775 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
777 if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON
,
778 index
, (LPARAM
)&tbb
) )
780 wxLogLastError(wxT("TB_INSERTBUTTON"));
786 // remember the number of separators we used - we'd have to
787 // delete all of them later
788 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
790 // adjust the controls width to exactly cover the separators
791 control
->SetSize((nSeparators
+ 1)*widthSep
, -1);
794 // position the control itself correctly vertically
795 int height
= r
.bottom
- r
.top
;
796 int diff
= height
- size
.y
;
799 // the control is too high, resize to fit
800 control
->SetSize(-1, height
- 2);
811 y
+= height
+ 2*GetMargins().y
;
813 else // horizontal toolbar
821 control
->Move(left
, top
+ (diff
+ 1) / 2);
824 // the max index is the "real" number of buttons - i.e. counting even the
825 // separators which we added just for aligning the controls
830 if ( m_maxRows
== 0 )
832 // if not set yet, only one row
836 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
838 if ( m_maxRows
== 0 )
840 // if not set yet, have one column
849 // ----------------------------------------------------------------------------
851 // ----------------------------------------------------------------------------
853 bool wxToolBar::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD id
)
855 wxToolBarToolBase
*tool
= FindById((int)id
);
858 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
859 event
.SetEventObject(this);
863 return GetEventHandler()->ProcessEvent(event
);
866 if ( tool
->CanBeToggled() )
868 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
869 tool
->Toggle((state
& TBSTATE_CHECKED
) != 0);
872 bool toggled
= tool
->IsToggled();
874 // avoid sending the event when a radio button is released, this is not
876 if ( !tool
->CanBeToggled() || tool
->GetKind() != wxITEM_RADIO
|| toggled
)
878 // OnLeftClick() can veto the button state change - for buttons which
879 // may be toggled only, of couse
880 if ( !OnLeftClick((int)id
, toggled
) && tool
->CanBeToggled() )
884 tool
->SetToggle(toggled
);
886 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(toggled
, 0));
893 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
895 WXLPARAM
*WXUNUSED(result
))
898 // First check if this applies to us
899 NMHDR
*hdr
= (NMHDR
*)lParam
;
901 // the tooltips control created by the toolbar is sometimes Unicode, even
902 // in an ANSI application - this seems to be a bug in comctl32.dll v5
903 UINT code
= hdr
->code
;
904 if ( (code
!= (UINT
) TTN_NEEDTEXTA
) && (code
!= (UINT
) TTN_NEEDTEXTW
) )
907 HWND toolTipWnd
= (HWND
)::SendMessage((HWND
)GetHWND(), TB_GETTOOLTIPS
, 0, 0);
908 if ( toolTipWnd
!= hdr
->hwndFrom
)
911 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
912 int id
= (int)ttText
->hdr
.idFrom
;
914 wxToolBarToolBase
*tool
= FindById(id
);
918 return HandleTooltipNotify(code
, lParam
, tool
->GetShortHelp());
924 // ----------------------------------------------------------------------------
926 // ----------------------------------------------------------------------------
928 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
930 wxToolBarBase::SetToolBitmapSize(size
);
932 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
935 void wxToolBar::SetRows(int nRows
)
937 if ( nRows
== m_maxRows
)
939 // avoid resizing the frame uselessly
943 // TRUE in wParam means to create at least as many rows, FALSE -
946 ::SendMessage(GetHwnd(), TB_SETROWS
,
947 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
955 // The button size is bigger than the bitmap size
956 wxSize
wxToolBar::GetToolSize() const
958 // TB_GETBUTTONSIZE is supported from version 4.70
959 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
960 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
961 if ( wxTheApp
->GetComCtl32Version() >= 470 )
963 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
965 return wxSize(LOWORD(dw
), HIWORD(dw
));
968 #endif // comctl32.dll 4.70+
971 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
976 wxToolBarToolBase
*GetItemSkippingDummySpacers(const wxToolBarToolsList
& tools
,
979 wxToolBarToolsList::compatibility_iterator current
= tools
.GetFirst();
981 for ( ; current
!= 0; current
= current
->GetNext() )
984 return current
->GetData();
986 wxToolBarTool
*tool
= (wxToolBarTool
*)current
->GetData();
987 size_t separators
= tool
->GetSeparatorsCount();
989 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
990 // otherwise, skip as many items as the separator count, plus the
992 index
-= separators
? separators
+ 1 : 1;
998 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
1003 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
1004 // MBN: when the point ( x, y ) is close to the toolbar border
1005 // TB_HITTEST returns m_nButtons ( not -1 )
1006 if ( index
< 0 || (size_t)index
>= m_nButtons
)
1008 // it's a separator or there is no tool at all there
1009 return (wxToolBarToolBase
*)NULL
;
1012 // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
1013 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
1014 if ( wxTheApp
->GetComCtl32Version() >= 471 )
1016 return m_tools
.Item((size_t)index
)->GetData();
1021 return GetItemSkippingDummySpacers( m_tools
, (size_t) index
);
1025 void wxToolBar::UpdateSize()
1027 // the toolbar size changed
1028 SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
1030 // we must also refresh the frame after the toolbar size (possibly) changed
1031 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
1034 frame
->SendSizeEvent();
1038 // ----------------------------------------------------------------------------
1040 // ---------------------------------------------------------------------------
1042 void wxToolBar::SetWindowStyleFlag(long style
)
1044 // the style bits whose changes force us to recreate the toolbar
1045 static const long MASK_NEEDS_RECREATE
= wxTB_TEXT
| wxTB_NOICONS
;
1047 const long styleOld
= GetWindowStyle();
1049 wxToolBarBase::SetWindowStyleFlag(style
);
1051 // don't recreate an empty toolbar: not only this is unnecessary, but it is
1052 // also fatal as we'd then try to recreate the toolbar when it's just being
1054 if ( GetToolsCount() &&
1055 (style
& MASK_NEEDS_RECREATE
) != (styleOld
& MASK_NEEDS_RECREATE
) )
1057 // to remove the text labels, simply re-realizing the toolbar is enough
1058 // but I don't know of any way to add the text to an existing toolbar
1059 // other than by recreating it entirely
1064 // ----------------------------------------------------------------------------
1066 // ----------------------------------------------------------------------------
1068 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
1070 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
1071 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
1074 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
1076 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
1077 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
1080 void wxToolBar::DoSetToggle(wxToolBarToolBase
*WXUNUSED(tool
), bool WXUNUSED(toggle
))
1082 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
1083 // without, so we really need to delete the button and recreate it here
1084 wxFAIL_MSG( _T("not implemented") );
1087 // ----------------------------------------------------------------------------
1089 // ----------------------------------------------------------------------------
1091 // Responds to colour changes, and passes event on to children.
1092 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1094 wxRGBToColour(m_backgroundColour
, ::GetSysColor(COLOR_BTNFACE
));
1096 // Remap the buttons
1099 // Relayout the toolbar
1100 int nrows
= m_maxRows
;
1101 m_maxRows
= 0; // otherwise SetRows() wouldn't do anything
1106 // let the event propagate further
1110 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
1112 if (event
.Leaving() && m_pInTool
)
1119 if (event
.RightDown())
1121 // For now, we don't have an id. Later we could
1122 // try finding the tool.
1123 OnRightClick((int)-1, event
.GetX(), event
.GetY());
1131 void wxToolBar::HandleMouseMove(WXWPARAM wParam
, WXLPARAM lParam
)
1133 wxCoord x
= GET_X_LPARAM(lParam
),
1134 y
= GET_Y_LPARAM(lParam
);
1135 wxToolBarToolBase
* tool
= FindToolForPosition( x
, y
);
1137 // cursor left current tool
1138 if( tool
!= m_pInTool
&& !tool
)
1144 // cursor entered a tool
1145 if( tool
!= m_pInTool
&& tool
)
1148 OnMouseEnter( tool
->GetId() );
1152 WXLRESULT
wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1158 if ( HandleSize(wParam
, lParam
) )
1163 // we don't handle mouse moves, so always pass the message to
1164 // wxControl::MSWWindowProc
1165 HandleMouseMove(wParam
, lParam
);
1169 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1172 #endif // wxUSE_TOOLBAR && Win95