]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/toolbar.h
added raw key code and flags support (based on patch from Bryce Denney)
[wxWidgets.git] / include / wx / univ / toolbar.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/toolbar.h
3 // Purpose: wxToolBar declaration
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 10.09.00
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_TOOLBAR_H_
13 #define _WX_UNIV_TOOLBAR_H_
14
15 #ifdef __GNUG__
16 #pragma interface "univtoolbar.h"
17 #endif
18
19 #include "wx/button.h" // for wxStdButtonInputHandler
20
21 class WXDLLEXPORT wxToolBarTool;
22
23 // ----------------------------------------------------------------------------
24 // the actions supported by this control
25 // ----------------------------------------------------------------------------
26
27 #define wxACTION_TOOLBAR_TOGGLE wxACTION_BUTTON_TOGGLE
28 #define wxACTION_TOOLBAR_PRESS wxACTION_BUTTON_PRESS
29 #define wxACTION_TOOLBAR_RELEASE wxACTION_BUTTON_RELEASE
30 #define wxACTION_TOOLBAR_CLICK wxACTION_BUTTON_CLICK
31 #define wxACTION_TOOLBAR_ENTER _T("enter") // highlight the tool
32 #define wxACTION_TOOLBAR_LEAVE _T("leave") // unhighlight the tool
33
34 // ----------------------------------------------------------------------------
35 // wxToolBar
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxToolBar : public wxToolBarBase
39 {
40 public:
41 // construction/destruction
42 wxToolBar() { Init(); }
43 wxToolBar(wxWindow *parent,
44 wxWindowID id,
45 const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize,
47 long style = 0,
48 const wxString& name = wxToolBarNameStr)
49 {
50 Init();
51
52 Create(parent, id, pos, size, style, name);
53 }
54
55 bool Create( wxWindow *parent,
56 wxWindowID id,
57 const wxPoint& pos = wxDefaultPosition,
58 const wxSize& size = wxDefaultSize,
59 long style = 0,
60 const wxString& name = wxToolBarNameStr );
61
62 virtual ~wxToolBar();
63
64 virtual bool Realize();
65
66 virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
67
68 virtual void SetToolShortHelp(int id, const wxString& helpString);
69
70 virtual void SetMargins(int x, int y);
71 void SetMargins(const wxSize& size)
72 { SetMargins((int) size.x, (int) size.y); }
73
74 protected:
75 // common part of all ctors
76 void Init();
77
78 // implement base class pure virtuals
79 virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
80 virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
81
82 virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
83 virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
84 virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
85
86 virtual wxToolBarToolBase *CreateTool(int id,
87 const wxString& label,
88 const wxBitmap& bmpNormal,
89 const wxBitmap& bmpDisabled,
90 wxItemKind kind,
91 wxObject *clientData,
92 const wxString& shortHelp,
93 const wxString& longHelp);
94 virtual wxToolBarToolBase *CreateTool(wxControl *control);
95
96 // implement wxUniversal methods
97 virtual bool PerformAction(const wxControlAction& action,
98 long numArg = -1,
99 const wxString& strArg = wxEmptyString);
100 virtual wxSize DoGetBestClientSize() const;
101 virtual void DoDraw(wxControlRenderer *renderer);
102
103 // get the bounding rect for the given tool
104 wxRect GetToolRect(wxToolBarToolBase *tool) const;
105
106 // redraw the given tool
107 void RefreshTool(wxToolBarToolBase *tool);
108
109 // (re)calculate the tool positions, should only be called if it is
110 // necessary to do it, i.e. m_needsLayout == TRUE
111 void DoLayout();
112
113 // get the rect limits depending on the orientation: top/bottom for a
114 // vertical toolbar, left/right for a horizontal one
115 void GetRectLimits(const wxRect& rect, wxCoord *start, wxCoord *end) const;
116
117 private:
118 // have we calculated the positions of our tools?
119 bool m_needsLayout;
120
121 // the width of a separator
122 wxCoord m_widthSeparator;
123
124 // the total size of all toolbar elements
125 wxCoord m_maxWidth,
126 m_maxHeight;
127
128 private:
129 DECLARE_DYNAMIC_CLASS(wxToolBar)
130 };
131
132 // ----------------------------------------------------------------------------
133 // wxStdToolbarInputHandler: translates SPACE and ENTER keys and the left mouse
134 // click into button press/release actions
135 // ----------------------------------------------------------------------------
136
137 class WXDLLEXPORT wxStdToolbarInputHandler : public wxStdInputHandler
138 {
139 public:
140 wxStdToolbarInputHandler(wxInputHandler *inphand);
141
142 virtual bool HandleKey(wxInputConsumer *consumer,
143 const wxKeyEvent& event,
144 bool pressed);
145 virtual bool HandleMouse(wxInputConsumer *consumer,
146 const wxMouseEvent& event);
147 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
148 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
149 virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
150
151 private:
152 wxWindow *m_winCapture;
153 wxToolBarToolBase *m_toolCapture;
154 wxToolBarToolBase *m_toolLast;
155 };
156
157 #endif // _WX_UNIV_TOOLBAR_H_