]>
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 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "dyntbar.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/tbarbase.h" | |
20 | #include "wx/dynarray.h" | |
21 | ||
4cbc57f0 JS |
22 | /* |
23 | Tool layout item. | |
24 | */ | |
8e08b761 JS |
25 | |
26 | class wxToolLayoutItem : public wxObject | |
27 | { | |
28 | public: | |
4cbc57f0 JS |
29 | wxRect mRect; |
30 | bool mIsSeparator; | |
8e08b761 JS |
31 | }; |
32 | ||
33 | class wxDynToolInfo; | |
34 | ||
35 | typedef wxToolLayoutItem* wxToolLayoutItemPtrT; | |
36 | typedef wxDynToolInfo* wxDynToolInfoPtrT; | |
37 | ||
8e08b761 JS |
38 | WX_DEFINE_ARRAY( wxToolLayoutItemPtrT, wxLayoutItemArrayT ); |
39 | WX_DEFINE_ARRAY( wxDynToolInfoPtrT, wxDynToolInfoArrayT ); | |
40 | ||
4cbc57f0 JS |
41 | /* |
42 | This is a base class for layout algorithm implementations. | |
43 | */ | |
8e08b761 JS |
44 | |
45 | class LayoutManagerBase | |
46 | { | |
47 | public: | |
4cbc57f0 JS |
48 | // Constructor. |
49 | virtual void Layout( const wxSize& parentDim, | |
50 | wxSize& resultingDim, | |
51 | wxLayoutItemArrayT& items, | |
52 | int horizGap, | |
53 | int vertGap ) = 0; | |
54 | ||
55 | // Destructor. | |
56 | virtual ~LayoutManagerBase() {} | |
8e08b761 JS |
57 | }; |
58 | ||
4cbc57f0 JS |
59 | /* |
60 | BagLayout lays out items in left-to-right order from | |
61 | top to bottom. | |
62 | */ | |
8e08b761 JS |
63 | |
64 | class BagLayout : public LayoutManagerBase | |
65 | { | |
66 | public: | |
4cbc57f0 JS |
67 | // Constructor. |
68 | virtual void Layout( const wxSize& parentDim, | |
69 | wxSize& resultingDim, | |
70 | wxLayoutItemArrayT& items, | |
71 | int horizGap, | |
72 | int vertGap ); | |
8e08b761 JS |
73 | }; |
74 | ||
4cbc57f0 JS |
75 | /* |
76 | This class holds dynamic toolbar item information. | |
77 | */ | |
78 | ||
8e08b761 JS |
79 | class wxDynToolInfo : public wxToolLayoutItem |
80 | { | |
4cbc57f0 | 81 | DECLARE_DYNAMIC_CLASS(wxDynToolInfo) |
8e08b761 JS |
82 | |
83 | public: | |
4cbc57f0 JS |
84 | wxWindow* mpToolWnd; |
85 | int mIndex; | |
86 | wxSize mRealSize; | |
8e08b761 JS |
87 | }; |
88 | ||
4cbc57f0 | 89 | // Layout orientations for tools |
8e08b761 JS |
90 | |
91 | #define LO_HORIZONTAL 0 | |
92 | #define LO_VERTICAL 1 | |
93 | #define LO_FIT_TO_WINDOW 2 | |
94 | ||
4cbc57f0 JS |
95 | /* |
96 | wxDynamicToolBar manages containment and layout of tool windows. | |
97 | */ | |
8e08b761 JS |
98 | |
99 | class wxDynamicToolBar : public wxToolBarBase | |
100 | { | |
4cbc57f0 | 101 | DECLARE_DYNAMIC_CLASS(wxDynamicToolBar) |
8e08b761 JS |
102 | protected: |
103 | ||
4cbc57f0 | 104 | friend class wxDynamicToolBarSerializer; |
8e08b761 | 105 | |
4cbc57f0 JS |
106 | wxDynToolInfoArrayT mTools; |
107 | LayoutManagerBase* mpLayoutMan; | |
8e08b761 JS |
108 | |
109 | protected: | |
4cbc57f0 JS |
110 | // Internal function for sizing tool windows. |
111 | virtual void SizeToolWindows(); | |
8e08b761 JS |
112 | |
113 | public: /* public properties */ | |
114 | ||
4cbc57f0 JS |
115 | int mSepartorSize; // default: 8 |
116 | int mVertGap; // default: 0 | |
117 | int mHorizGap; // default: 0 | |
118 | ||
8e08b761 | 119 | public: |
4cbc57f0 JS |
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. | |
8e08b761 | 131 | |
4cbc57f0 | 132 | ~wxDynamicToolBar(void); |
8e08b761 | 133 | |
4cbc57f0 | 134 | // Creation function: see the documentation for wxToolBar for details. |
8e08b761 | 135 | |
4cbc57f0 JS |
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); | |
8e08b761 | 138 | |
4cbc57f0 | 139 | // Adds a tool. See the documentation for wxToolBar for details. |
8e08b761 | 140 | |
4cbc57f0 JS |
141 | virtual void AddTool( int toolIndex, |
142 | wxWindow* pToolWindow, | |
8252c9ca GD |
143 | const wxSize& size = wxDefaultSize ); |
144 | ||
4cbc57f0 JS |
145 | // Adds a tool. See the documentation for wxToolBar for details. |
146 | ||
147 | virtual void AddTool( int toolIndex, | |
8252c9ca GD |
148 | const wxString& imageFileName, |
149 | wxBitmapType imageFileType = wxBITMAP_TYPE_BMP, | |
150 | const wxString& labelText = "", bool alignTextRight = FALSE, | |
151 | bool isFlat = TRUE ); | |
4cbc57f0 JS |
152 | // Adds a tool. See the documentation for wxToolBar for details. |
153 | ||
154 | virtual void AddTool( int toolIndex, wxBitmap labelBmp, | |
8252c9ca GD |
155 | const wxString& labelText = "", bool alignTextRight = FALSE, |
156 | bool isFlat = TRUE ); | |
8e08b761 | 157 | |
4cbc57f0 JS |
158 | // Method from wxToolBarBase (for compatibility), only |
159 | // the first two arguments are valid. | |
160 | // See the documentation for wxToolBar for details. | |
8e08b761 | 161 | |
4cbc57f0 | 162 | virtual wxToolBarToolBase *AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap, |
8e08b761 JS |
163 | const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL, |
164 | const wxString& helpString1 = "", const wxString& helpString2 = ""); | |
165 | ||
4cbc57f0 JS |
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. | |
8e08b761 | 180 | |
4cbc57f0 | 181 | virtual void DrawSeparator( wxDynToolInfo& info, wxDC& dc ); |
8e08b761 | 182 | |
4cbc57f0 | 183 | // Performs layout. See definitions of orientation types. |
8e08b761 | 184 | |
4cbc57f0 | 185 | virtual bool Layout(); |
8e08b761 | 186 | |
4cbc57f0 | 187 | // Returns the preferred dimension, taking the given dimension and a reference to the result. |
8e08b761 | 188 | |
4cbc57f0 | 189 | virtual void GetPreferredDim( const wxSize& givenDim, wxSize& prefDim ); |
8e08b761 | 190 | |
4cbc57f0 | 191 | // Creates the default layout (BagLayout). |
8e08b761 | 192 | |
4cbc57f0 | 193 | virtual LayoutManagerBase* CreateDefaultLayout() { return new BagLayout(); } |
8e08b761 | 194 | |
4cbc57f0 | 195 | // Sets the layout for this toolbar. |
8e08b761 | 196 | |
4cbc57f0 | 197 | virtual void SetLayout( LayoutManagerBase* pLayout ); |
8e08b761 | 198 | |
4cbc57f0 | 199 | // Enables or disables the given tool. |
8e08b761 | 200 | |
4cbc57f0 | 201 | virtual void EnableTool(const int toolIndex, const bool enable = TRUE); |
8e08b761 | 202 | |
4cbc57f0 | 203 | // Responds to size events, calling Layout. |
8e08b761 | 204 | |
4cbc57f0 JS |
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. | |
8e08b761 JS |
220 | |
221 | virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, | |
222 | wxCoord y) const; | |
223 | ||
4cbc57f0 | 224 | // Inserts a tool at the given position. |
8e08b761 JS |
225 | |
226 | virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool); | |
227 | ||
4cbc57f0 JS |
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 | ||
8e08b761 JS |
231 | virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); |
232 | ||
4cbc57f0 JS |
233 | // Called when the tools enabled flag changes. |
234 | ||
8e08b761 JS |
235 | virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable); |
236 | ||
4cbc57f0 JS |
237 | // Called when the tool is toggled. |
238 | ||
8e08b761 JS |
239 | virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle); |
240 | ||
4cbc57f0 JS |
241 | // Called when the tools 'can be toggled' flag changes. |
242 | ||
8e08b761 JS |
243 | virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); |
244 | ||
4cbc57f0 JS |
245 | // Creates a toolbar tool. |
246 | ||
8e08b761 JS |
247 | virtual wxToolBarToolBase *CreateTool(int id, |
248 | const wxBitmap& bitmap1, | |
249 | const wxBitmap& bitmap2, | |
250 | bool toggle, | |
251 | wxObject *clientData, | |
252 | const wxString& shortHelpString, | |
253 | const wxString& longHelpString); | |
8e08b761 | 254 | |
4cbc57f0 JS |
255 | // Creates a toolbar tool. |
256 | ||
257 | virtual wxToolBarToolBase *CreateTool(wxControl *control); | |
8e08b761 | 258 | |
4cbc57f0 | 259 | DECLARE_EVENT_TABLE() |
8e08b761 JS |
260 | }; |
261 | ||
262 | #endif /* __DYNTBAR_G__ */ | |
263 |