]>
Commit | Line | Data |
---|---|---|
8e08b761 | 1 | ///////////////////////////////////////////////////////////////////////////// |
4cbc57f0 JS |
2 | // Name: dyntbar.h |
3 | // Purpose: wxDynamicToolBar header | |
8e08b761 JS |
4 | // Author: Aleksandras Gluchovas |
5 | // Modified by: | |
6 | // Created: ??/10/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Aleksandras Gluchovas | |
4cbc57f0 | 9 | // Licence: wxWindows licence |
8e08b761 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __DYNTBAR_G__ | |
13 | #define __DYNTBAR_G__ | |
14 | ||
ab7ce33c | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
8e08b761 JS |
16 | #pragma interface "dyntbar.h" |
17 | #endif | |
18 | ||
19 | #include "wx/tbarbase.h" | |
20 | #include "wx/dynarray.h" | |
2b5f62a0 | 21 | #include "wx/fl/fldefs.h" |
8e08b761 | 22 | |
4cbc57f0 JS |
23 | /* |
24 | Tool layout item. | |
25 | */ | |
8e08b761 | 26 | |
510b9edb | 27 | class WXDLLIMPEXP_FL wxToolLayoutItem : public wxObject |
8e08b761 | 28 | { |
b2995a23 GT |
29 | DECLARE_DYNAMIC_CLASS(wxToolLayoutItem) |
30 | ||
8e08b761 | 31 | public: |
4cbc57f0 JS |
32 | wxRect mRect; |
33 | bool mIsSeparator; | |
8e08b761 JS |
34 | }; |
35 | ||
510b9edb | 36 | class WXDLLIMPEXP_FL wxDynToolInfo; |
8e08b761 JS |
37 | |
38 | typedef wxToolLayoutItem* wxToolLayoutItemPtrT; | |
39 | typedef wxDynToolInfo* wxDynToolInfoPtrT; | |
40 | ||
659f8ec3 MB |
41 | WXFL_DEFINE_ARRAY_PTR( wxToolLayoutItemPtrT, wxLayoutItemArrayT ); |
42 | WXFL_DEFINE_ARRAY_PTR( wxDynToolInfoPtrT, wxDynToolInfoArrayT ); | |
8e08b761 | 43 | |
4cbc57f0 JS |
44 | /* |
45 | This is a base class for layout algorithm implementations. | |
46 | */ | |
8e08b761 | 47 | |
510b9edb | 48 | class WXDLLIMPEXP_FL LayoutManagerBase |
8e08b761 JS |
49 | { |
50 | public: | |
4cbc57f0 JS |
51 | // Constructor. |
52 | virtual void Layout( const wxSize& parentDim, | |
53 | wxSize& resultingDim, | |
54 | wxLayoutItemArrayT& items, | |
55 | int horizGap, | |
56 | int vertGap ) = 0; | |
57 | ||
58 | // Destructor. | |
59 | virtual ~LayoutManagerBase() {} | |
8e08b761 JS |
60 | }; |
61 | ||
4cbc57f0 JS |
62 | /* |
63 | BagLayout lays out items in left-to-right order from | |
64 | top to bottom. | |
65 | */ | |
8e08b761 | 66 | |
510b9edb | 67 | class WXDLLIMPEXP_FL BagLayout : public LayoutManagerBase |
8e08b761 JS |
68 | { |
69 | public: | |
4cbc57f0 JS |
70 | // Constructor. |
71 | virtual void Layout( const wxSize& parentDim, | |
72 | wxSize& resultingDim, | |
73 | wxLayoutItemArrayT& items, | |
74 | int horizGap, | |
75 | int vertGap ); | |
8e08b761 JS |
76 | }; |
77 | ||
4cbc57f0 JS |
78 | /* |
79 | This class holds dynamic toolbar item information. | |
80 | */ | |
81 | ||
510b9edb | 82 | class WXDLLIMPEXP_FL wxDynToolInfo : public wxToolLayoutItem |
8e08b761 | 83 | { |
4cbc57f0 | 84 | DECLARE_DYNAMIC_CLASS(wxDynToolInfo) |
8e08b761 JS |
85 | |
86 | public: | |
4cbc57f0 JS |
87 | wxWindow* mpToolWnd; |
88 | int mIndex; | |
89 | wxSize mRealSize; | |
8e08b761 JS |
90 | }; |
91 | ||
4cbc57f0 | 92 | // Layout orientations for tools |
8e08b761 JS |
93 | |
94 | #define LO_HORIZONTAL 0 | |
95 | #define LO_VERTICAL 1 | |
96 | #define LO_FIT_TO_WINDOW 2 | |
97 | ||
4cbc57f0 JS |
98 | /* |
99 | wxDynamicToolBar manages containment and layout of tool windows. | |
100 | */ | |
8e08b761 | 101 | |
510b9edb | 102 | class WXDLLIMPEXP_FL wxDynamicToolBar : public wxToolBarBase |
8e08b761 | 103 | { |
b2995a23 | 104 | protected: |
4cbc57f0 | 105 | friend class wxDynamicToolBarSerializer; |
8e08b761 | 106 | |
4cbc57f0 JS |
107 | wxDynToolInfoArrayT mTools; |
108 | LayoutManagerBase* mpLayoutMan; | |
8e08b761 JS |
109 | |
110 | protected: | |
4cbc57f0 JS |
111 | // Internal function for sizing tool windows. |
112 | virtual void SizeToolWindows(); | |
8e08b761 JS |
113 | |
114 | public: /* public properties */ | |
115 | ||
4cbc57f0 JS |
116 | int mSepartorSize; // default: 8 |
117 | int mVertGap; // default: 0 | |
118 | int mHorizGap; // default: 0 | |
119 | ||
8e08b761 | 120 | public: |
4cbc57f0 JS |
121 | // Default constructor. |
122 | ||
123 | wxDynamicToolBar(); | |
124 | ||
125 | // Constructor: see the documentation for wxToolBar for details. | |
126 | ||
127 | wxDynamicToolBar(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
128 | const long style = wxNO_BORDER, const int orientation = wxVERTICAL, | |
129 | const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr); | |
130 | ||
131 | // Destructor. | |
8e08b761 | 132 | |
4cbc57f0 | 133 | ~wxDynamicToolBar(void); |
8e08b761 | 134 | |
4cbc57f0 | 135 | // Creation function: see the documentation for wxToolBar for details. |
8e08b761 | 136 | |
4cbc57f0 JS |
137 | bool Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
138 | const long style = wxNO_BORDER, const int orientation = wxVERTICAL, const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr); | |
8e08b761 | 139 | |
4cbc57f0 | 140 | // Adds a tool. See the documentation for wxToolBar for details. |
8e08b761 | 141 | |
4cbc57f0 JS |
142 | virtual void AddTool( int toolIndex, |
143 | wxWindow* pToolWindow, | |
8252c9ca GD |
144 | const wxSize& size = wxDefaultSize ); |
145 | ||
4cbc57f0 JS |
146 | // Adds a tool. See the documentation for wxToolBar for details. |
147 | ||
148 | virtual void AddTool( int toolIndex, | |
8252c9ca GD |
149 | const wxString& imageFileName, |
150 | wxBitmapType imageFileType = wxBITMAP_TYPE_BMP, | |
873a543b | 151 | const wxString& labelText = wxT(""), bool alignTextRight = FALSE, |
8252c9ca | 152 | bool isFlat = TRUE ); |
4cbc57f0 JS |
153 | // Adds a tool. See the documentation for wxToolBar for details. |
154 | ||
155 | virtual void AddTool( int toolIndex, wxBitmap labelBmp, | |
873a543b | 156 | const wxString& labelText = wxT(""), bool alignTextRight = FALSE, |
8252c9ca | 157 | bool isFlat = TRUE ); |
8e08b761 | 158 | |
8552e6f0 MB |
159 | // Unhide method from parent. |
160 | ||
161 | virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool) | |
162 | { return wxToolBarBase::AddTool(tool); }; | |
163 | ||
4cbc57f0 JS |
164 | // Method from wxToolBarBase (for compatibility), only |
165 | // the first two arguments are valid. | |
166 | // See the documentation for wxToolBar for details. | |
8e08b761 | 167 | |
4cbc57f0 | 168 | virtual wxToolBarToolBase *AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap, |
8e08b761 | 169 | const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL, |
873a543b | 170 | const wxString& helpString1 = wxT(""), const wxString& helpString2 = wxT("")); |
8e08b761 | 171 | |
4cbc57f0 JS |
172 | // Adds a separator. See the documentation for wxToolBar for details. |
173 | ||
8552e6f0 | 174 | virtual void AddSeparator( wxWindow* pSepartorWnd ); |
4cbb46c9 | 175 | |
8552e6f0 MB |
176 | // Unhide method from parent. |
177 | ||
178 | virtual wxToolBarToolBase *AddSeparator() | |
179 | { return wxToolBarBase::AddSeparator(); }; | |
4cbc57f0 JS |
180 | |
181 | // Returns tool information for the given tool index. | |
182 | ||
183 | wxDynToolInfo* GetToolInfo( int toolIndex ); | |
184 | ||
185 | // Removes the given tool. Misspelt in order not to clash with a similar function | |
186 | // in the base class. | |
187 | ||
188 | void RemveTool( int toolIndex ); | |
189 | ||
190 | // Draws a separator. The default implementation draws a shaded line. | |
8e08b761 | 191 | |
4cbc57f0 | 192 | virtual void DrawSeparator( wxDynToolInfo& info, wxDC& dc ); |
8e08b761 | 193 | |
4cbc57f0 | 194 | // Performs layout. See definitions of orientation types. |
8e08b761 | 195 | |
4cbc57f0 | 196 | virtual bool Layout(); |
8e08b761 | 197 | |
4cbc57f0 | 198 | // Returns the preferred dimension, taking the given dimension and a reference to the result. |
8e08b761 | 199 | |
4cbc57f0 | 200 | virtual void GetPreferredDim( const wxSize& givenDim, wxSize& prefDim ); |
8e08b761 | 201 | |
4cbc57f0 | 202 | // Creates the default layout (BagLayout). |
8e08b761 | 203 | |
4cbc57f0 | 204 | virtual LayoutManagerBase* CreateDefaultLayout() { return new BagLayout(); } |
8e08b761 | 205 | |
4cbc57f0 | 206 | // Sets the layout for this toolbar. |
8e08b761 | 207 | |
4cbc57f0 | 208 | virtual void SetLayout( LayoutManagerBase* pLayout ); |
8e08b761 | 209 | |
4cbc57f0 | 210 | // Enables or disables the given tool. |
8e08b761 | 211 | |
083f7497 | 212 | virtual void EnableTool(int toolIndex, bool enable = TRUE); |
8e08b761 | 213 | |
4cbc57f0 | 214 | // Responds to size events, calling Layout. |
8e08b761 | 215 | |
4cbc57f0 JS |
216 | void OnSize( wxSizeEvent& event ); |
217 | ||
218 | // Responds to paint events, drawing separators. | |
219 | ||
220 | void OnPaint( wxPaintEvent& event ); | |
221 | ||
222 | // Responds to background erase events. Currently does nothing. | |
223 | ||
224 | void OnEraseBackground( wxEraseEvent& event ); | |
225 | ||
226 | // Overriden from wxToolBarBase; does nothing. | |
227 | ||
228 | virtual bool Realize(void); | |
229 | ||
230 | // Finds a tool for the given position. | |
8e08b761 JS |
231 | |
232 | virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, | |
233 | wxCoord y) const; | |
234 | ||
4cbc57f0 | 235 | // Inserts a tool at the given position. |
8e08b761 JS |
236 | |
237 | virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool); | |
238 | ||
4cbc57f0 JS |
239 | // Deletes a tool. The tool is still in m_tools list when this function is called, and it will |
240 | // only be deleted from it if it succeeds. | |
241 | ||
8e08b761 JS |
242 | virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); |
243 | ||
4cbc57f0 JS |
244 | // Called when the tools enabled flag changes. |
245 | ||
8e08b761 JS |
246 | virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable); |
247 | ||
4cbc57f0 JS |
248 | // Called when the tool is toggled. |
249 | ||
8e08b761 JS |
250 | virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle); |
251 | ||
4cbc57f0 JS |
252 | // Called when the tools 'can be toggled' flag changes. |
253 | ||
8e08b761 JS |
254 | virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); |
255 | ||
4cbc57f0 JS |
256 | // Creates a toolbar tool. |
257 | ||
8e08b761 | 258 | virtual wxToolBarToolBase *CreateTool(int id, |
349f1d8e VZ |
259 | const wxString& label, |
260 | const wxBitmap& bmpNormal, | |
261 | const wxBitmap& bmpDisabled, | |
262 | wxItemKind kind, | |
8e08b761 | 263 | wxObject *clientData, |
349f1d8e VZ |
264 | const wxString& shortHelp, |
265 | const wxString& longHelp); | |
8e08b761 | 266 | |
4cbc57f0 JS |
267 | // Creates a toolbar tool. |
268 | ||
269 | virtual wxToolBarToolBase *CreateTool(wxControl *control); | |
8e08b761 | 270 | |
349f1d8e | 271 | private: |
4cbc57f0 | 272 | DECLARE_EVENT_TABLE() |
349f1d8e | 273 | DECLARE_DYNAMIC_CLASS(wxDynamicToolBar) |
8e08b761 JS |
274 | }; |
275 | ||
276 | #endif /* __DYNTBAR_G__ */ | |
277 |