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