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
104 friend class wxDynamicToolBarSerializer
;
106 wxDynToolInfoArrayT mTools
;
107 LayoutManagerBase
* mpLayoutMan
;
110 // Internal function for sizing tool windows.
111 virtual void SizeToolWindows();
113 public: /* public properties */
115 int mSepartorSize
; // default: 8
116 int mVertGap
; // default: 0
117 int mHorizGap
; // default: 0
120 // Default constructor.
124 // Constructor: see the documentation for wxToolBar for details.
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
);
132 ~wxDynamicToolBar(void);
134 // Creation function: see the documentation for wxToolBar for details.
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
);
139 // Adds a tool. See the documentation for wxToolBar for details.
141 virtual void AddTool( int toolIndex
,
142 wxWindow
* pToolWindow
,
143 const wxSize
& size
= wxDefaultSize
);
145 // Adds a tool. See the documentation for wxToolBar for details.
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.
154 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
155 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
156 bool isFlat
= TRUE
);
158 // Method from wxToolBarBase (for compatibility), only
159 // the first two arguments are valid.
160 // See the documentation for wxToolBar for details.
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
= "");
166 // Adds a separator. See the documentation for wxToolBar for details.
168 virtual void AddSeparator( wxWindow
* pSepartorWnd
= NULL
);
170 // Returns tool information for the given tool index.
172 wxDynToolInfo
* GetToolInfo( int toolIndex
);
174 // Removes the given tool. Misspelt in order not to clash with a similar function
175 // in the base class.
177 void RemveTool( int toolIndex
);
179 // Draws a separator. The default implementation draws a shaded line.
181 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
183 // Performs layout. See definitions of orientation types.
185 virtual bool Layout();
187 // Returns the preferred dimension, taking the given dimension and a reference to the result.
189 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
191 // Creates the default layout (BagLayout).
193 virtual LayoutManagerBase
* CreateDefaultLayout() { return new BagLayout(); }
195 // Sets the layout for this toolbar.
197 virtual void SetLayout( LayoutManagerBase
* pLayout
);
199 // Enables or disables the given tool.
201 virtual void EnableTool(const int toolIndex
, const bool enable
= TRUE
);
203 // Responds to size events, calling Layout.
205 void OnSize( wxSizeEvent
& event
);
207 // Responds to paint events, drawing separators.
209 void OnPaint( wxPaintEvent
& event
);
211 // Responds to background erase events. Currently does nothing.
213 void OnEraseBackground( wxEraseEvent
& event
);
215 // Overriden from wxToolBarBase; does nothing.
217 virtual bool Realize(void);
219 // Finds a tool for the given position.
221 virtual wxToolBarToolBase
*FindToolForPosition(wxCoord x
,
224 // Inserts a tool at the given position.
226 virtual bool DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
);
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.
231 virtual bool DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
);
233 // Called when the tools enabled flag changes.
235 virtual void DoEnableTool(wxToolBarToolBase
*tool
, bool enable
);
237 // Called when the tool is toggled.
239 virtual void DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
);
241 // Called when the tools 'can be toggled' flag changes.
243 virtual void DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
);
245 // Creates a toolbar tool.
247 virtual wxToolBarToolBase
*CreateTool(int id
,
248 const wxString
& label
,
249 const wxBitmap
& bmpNormal
,
250 const wxBitmap
& bmpDisabled
,
252 wxObject
*clientData
,
253 const wxString
& shortHelp
,
254 const wxString
& longHelp
);
256 // Creates a toolbar tool.
258 virtual wxToolBarToolBase
*CreateTool(wxControl
*control
);
261 DECLARE_EVENT_TABLE()
262 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
265 #endif /* __DYNTBAR_G__ */