]>
Commit | Line | Data |
---|---|---|
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 licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_UNIV_TOOLBAR_H_ | |
13 | #define _WX_UNIV_TOOLBAR_H_ | |
14 | ||
15 | #include "wx/button.h" // for wxStdButtonInputHandler | |
16 | ||
17 | class WXDLLEXPORT wxToolBarTool; | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // the actions supported by this control | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #define wxACTION_TOOLBAR_TOGGLE wxACTION_BUTTON_TOGGLE | |
24 | #define wxACTION_TOOLBAR_PRESS wxACTION_BUTTON_PRESS | |
25 | #define wxACTION_TOOLBAR_RELEASE wxACTION_BUTTON_RELEASE | |
26 | #define wxACTION_TOOLBAR_CLICK wxACTION_BUTTON_CLICK | |
27 | #define wxACTION_TOOLBAR_ENTER _T("enter") // highlight the tool | |
28 | #define wxACTION_TOOLBAR_LEAVE _T("leave") // unhighlight the tool | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // wxToolBar | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | class WXDLLEXPORT wxToolBar : public wxToolBarBase | |
35 | { | |
36 | public: | |
37 | // construction/destruction | |
38 | wxToolBar() { Init(); } | |
39 | wxToolBar(wxWindow *parent, | |
40 | wxWindowID id, | |
41 | const wxPoint& pos = wxDefaultPosition, | |
42 | const wxSize& size = wxDefaultSize, | |
43 | long style = 0, | |
44 | const wxString& name = wxToolBarNameStr) | |
45 | { | |
46 | Init(); | |
47 | ||
48 | Create(parent, id, pos, size, style, name); | |
49 | } | |
50 | ||
51 | bool Create( wxWindow *parent, | |
52 | wxWindowID id, | |
53 | const wxPoint& pos = wxDefaultPosition, | |
54 | const wxSize& size = wxDefaultSize, | |
55 | long style = 0, | |
56 | const wxString& name = wxToolBarNameStr ); | |
57 | ||
58 | virtual ~wxToolBar(); | |
59 | ||
60 | virtual bool Realize(); | |
61 | ||
62 | virtual void SetWindowStyleFlag( long style ); | |
63 | ||
64 | virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const; | |
65 | ||
66 | virtual void SetToolShortHelp(int id, const wxString& helpString); | |
67 | ||
68 | virtual void SetMargins(int x, int y); | |
69 | void SetMargins(const wxSize& size) | |
70 | { SetMargins((int) size.x, (int) size.y); } | |
71 | ||
72 | virtual bool PerformAction(const wxControlAction& action, | |
73 | long numArg = -1, | |
74 | const wxString& strArg = wxEmptyString); | |
75 | protected: | |
76 | // common part of all ctors | |
77 | void Init(); | |
78 | ||
79 | // implement base class pure virtuals | |
80 | virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool); | |
81 | virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); | |
82 | ||
83 | virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable); | |
84 | virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle); | |
85 | virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); | |
86 | ||
87 | virtual wxToolBarToolBase *CreateTool(int id, | |
88 | const wxString& label, | |
89 | const wxBitmap& bmpNormal, | |
90 | const wxBitmap& bmpDisabled, | |
91 | wxItemKind kind, | |
92 | wxObject *clientData, | |
93 | const wxString& shortHelp, | |
94 | const wxString& longHelp); | |
95 | virtual wxToolBarToolBase *CreateTool(wxControl *control); | |
96 | ||
97 | virtual wxSize DoGetBestClientSize() const; | |
98 | virtual void DoSetSize(int x, int y, | |
99 | int width, int height, | |
100 | int sizeFlags = wxSIZE_AUTO); | |
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_ |