]>
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 | { | |
b2995a23 | 103 | protected: |
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 | 247 | virtual wxToolBarToolBase *CreateTool(int id, |
349f1d8e VZ |
248 | const wxString& label, |
249 | const wxBitmap& bmpNormal, | |
250 | const wxBitmap& bmpDisabled, | |
251 | wxItemKind kind, | |
8e08b761 | 252 | wxObject *clientData, |
349f1d8e VZ |
253 | const wxString& shortHelp, |
254 | const wxString& longHelp); | |
8e08b761 | 255 | |
4cbc57f0 JS |
256 | // Creates a toolbar tool. |
257 | ||
258 | virtual wxToolBarToolBase *CreateTool(wxControl *control); | |
8e08b761 | 259 | |
349f1d8e | 260 | private: |
4cbc57f0 | 261 | DECLARE_EVENT_TABLE() |
349f1d8e | 262 | DECLARE_DYNAMIC_CLASS(wxDynamicToolBar) |
8e08b761 JS |
263 | }; |
264 | ||
265 | #endif /* __DYNTBAR_G__ */ | |
266 |