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