1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDynamicToolBar header
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dyntbar.h"
19 #include "wx/tbarbase.h"
20 #include "wx/dynarray.h"
26 class wxToolLayoutItem
: public wxObject
28 DECLARE_DYNAMIC_CLASS(wxToolLayoutItem
)
37 typedef wxToolLayoutItem
* wxToolLayoutItemPtrT
;
38 typedef wxDynToolInfo
* wxDynToolInfoPtrT
;
40 WX_DEFINE_ARRAY( wxToolLayoutItemPtrT
, wxLayoutItemArrayT
);
41 WX_DEFINE_ARRAY( wxDynToolInfoPtrT
, wxDynToolInfoArrayT
);
44 This is a base class for layout algorithm implementations.
47 class LayoutManagerBase
51 virtual void Layout( const wxSize
& parentDim
,
53 wxLayoutItemArrayT
& items
,
58 virtual ~LayoutManagerBase() {}
62 BagLayout lays out items in left-to-right order from
66 class BagLayout
: public LayoutManagerBase
70 virtual void Layout( const wxSize
& parentDim
,
72 wxLayoutItemArrayT
& items
,
78 This class holds dynamic toolbar item information.
81 class wxDynToolInfo
: public wxToolLayoutItem
83 DECLARE_DYNAMIC_CLASS(wxDynToolInfo
)
91 // Layout orientations for tools
93 #define LO_HORIZONTAL 0
95 #define LO_FIT_TO_WINDOW 2
98 wxDynamicToolBar manages containment and layout of tool windows.
101 class wxDynamicToolBar
: public wxToolBarBase
103 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
106 friend class wxDynamicToolBarSerializer
;
108 wxDynToolInfoArrayT mTools
;
109 LayoutManagerBase
* mpLayoutMan
;
112 // Internal function for sizing tool windows.
113 virtual void SizeToolWindows();
115 public: /* public properties */
117 int mSepartorSize
; // default: 8
118 int mVertGap
; // default: 0
119 int mHorizGap
; // default: 0
122 // Default constructor.
126 // Constructor: see the documentation for wxToolBar for details.
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
);
134 ~wxDynamicToolBar(void);
136 // Creation function: see the documentation for wxToolBar for details.
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
);
141 // Adds a tool. See the documentation for wxToolBar for details.
143 virtual void AddTool( int toolIndex
,
144 wxWindow
* pToolWindow
,
145 const wxSize
& size
= wxDefaultSize
);
147 // Adds a tool. See the documentation for wxToolBar for details.
149 virtual void AddTool( int toolIndex
,
150 const wxString
& imageFileName
,
151 wxBitmapType imageFileType
= wxBITMAP_TYPE_BMP
,
152 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
153 bool isFlat
= TRUE
);
154 // Adds a tool. See the documentation for wxToolBar for details.
156 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
157 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
158 bool isFlat
= TRUE
);
160 // Method from wxToolBarBase (for compatibility), only
161 // the first two arguments are valid.
162 // See the documentation for wxToolBar for details.
164 virtual wxToolBarToolBase
*AddTool(const int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
165 const bool toggle
= FALSE
, const long xPos
= -1, const long yPos
= -1, wxObject
*clientData
= NULL
,
166 const wxString
& helpString1
= "", const wxString
& helpString2
= "");
168 // Adds a separator. See the documentation for wxToolBar for details.
170 virtual void AddSeparator( wxWindow
* pSepartorWnd
= NULL
);
172 // Returns tool information for the given tool index.
174 wxDynToolInfo
* GetToolInfo( int toolIndex
);
176 // Removes the given tool. Misspelt in order not to clash with a similar function
177 // in the base class.
179 void RemveTool( int toolIndex
);
181 // Draws a separator. The default implementation draws a shaded line.
183 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
185 // Performs layout. See definitions of orientation types.
187 virtual bool Layout();
189 // Returns the preferred dimension, taking the given dimension and a reference to the result.
191 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
193 // Creates the default layout (BagLayout).
195 virtual LayoutManagerBase
* CreateDefaultLayout() { return new BagLayout(); }
197 // Sets the layout for this toolbar.
199 virtual void SetLayout( LayoutManagerBase
* pLayout
);
201 // Enables or disables the given tool.
203 virtual void EnableTool(const int toolIndex
, const bool enable
= TRUE
);
205 // Responds to size events, calling Layout.
207 void OnSize( wxSizeEvent
& event
);
209 // Responds to paint events, drawing separators.
211 void OnPaint( wxPaintEvent
& event
);
213 // Responds to background erase events. Currently does nothing.
215 void OnEraseBackground( wxEraseEvent
& event
);
217 // Overriden from wxToolBarBase; does nothing.
219 virtual bool Realize(void);
221 // Finds a tool for the given position.
223 virtual wxToolBarToolBase
*FindToolForPosition(wxCoord x
,
226 // Inserts a tool at the given position.
228 virtual bool DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
);
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.
233 virtual bool DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
);
235 // Called when the tools enabled flag changes.
237 virtual void DoEnableTool(wxToolBarToolBase
*tool
, bool enable
);
239 // Called when the tool is toggled.
241 virtual void DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
);
243 // Called when the tools 'can be toggled' flag changes.
245 virtual void DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
);
247 // Creates a toolbar tool.
249 virtual wxToolBarToolBase
*CreateTool(int id
,
250 const wxBitmap
& bitmap1
,
251 const wxBitmap
& bitmap2
,
253 wxObject
*clientData
,
254 const wxString
& shortHelpString
,
255 const wxString
& longHelpString
);
257 // Creates a toolbar tool.
259 virtual wxToolBarToolBase
*CreateTool(wxControl
*control
);
261 DECLARE_EVENT_TABLE()
264 #endif /* __DYNTBAR_G__ */