1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDynamicToolBar header
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "dyntbar.h"
19 #include "wx/tbarbase.h"
20 #include "wx/dynarray.h"
21 #include "wx/fl/fldefs.h"
27 class WXDLLIMPEXP_FL wxToolLayoutItem
: public wxObject
29 DECLARE_DYNAMIC_CLASS(wxToolLayoutItem
)
36 class WXDLLIMPEXP_FL wxDynToolInfo
;
38 typedef wxToolLayoutItem
* wxToolLayoutItemPtrT
;
39 typedef wxDynToolInfo
* wxDynToolInfoPtrT
;
41 WXFL_DEFINE_ARRAY_PTR( wxToolLayoutItemPtrT
, wxLayoutItemArrayT
);
42 WXFL_DEFINE_ARRAY_PTR( wxDynToolInfoPtrT
, wxDynToolInfoArrayT
);
45 This is a base class for layout algorithm implementations.
48 class WXDLLIMPEXP_FL LayoutManagerBase
52 virtual void Layout( const wxSize
& parentDim
,
54 wxLayoutItemArrayT
& items
,
59 virtual ~LayoutManagerBase() {}
63 BagLayout lays out items in left-to-right order from
67 class WXDLLIMPEXP_FL BagLayout
: public LayoutManagerBase
71 virtual void Layout( const wxSize
& parentDim
,
73 wxLayoutItemArrayT
& items
,
79 This class holds dynamic toolbar item information.
82 class WXDLLIMPEXP_FL wxDynToolInfo
: public wxToolLayoutItem
84 DECLARE_DYNAMIC_CLASS(wxDynToolInfo
)
92 // Layout orientations for tools
94 #define LO_HORIZONTAL 0
96 #define LO_FIT_TO_WINDOW 2
99 wxDynamicToolBar manages containment and layout of tool windows.
102 class WXDLLIMPEXP_FL wxDynamicToolBar
: public wxToolBarBase
105 friend class wxDynamicToolBarSerializer
;
107 wxDynToolInfoArrayT mTools
;
108 LayoutManagerBase
* mpLayoutMan
;
111 // Internal function for sizing tool windows.
112 virtual void SizeToolWindows();
114 public: /* public properties */
116 int mSepartorSize
; // default: 8
117 int mVertGap
; // default: 0
118 int mHorizGap
; // default: 0
121 // Default constructor.
125 // Constructor: see the documentation for wxToolBar for details.
127 wxDynamicToolBar(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
128 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
,
129 const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
133 ~wxDynamicToolBar(void);
135 // Creation function: see the documentation for wxToolBar for details.
137 bool Create(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
138 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
, const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
140 // Adds a tool. See the documentation for wxToolBar for details.
142 virtual void AddTool( int toolIndex
,
143 wxWindow
* pToolWindow
,
144 const wxSize
& size
= wxDefaultSize
);
146 // Adds a tool. See the documentation for wxToolBar for details.
148 virtual void AddTool( int toolIndex
,
149 const wxString
& imageFileName
,
150 wxBitmapType imageFileType
= wxBITMAP_TYPE_BMP
,
151 const wxString
& labelText
= wxT(""), bool alignTextRight
= FALSE
,
152 bool isFlat
= TRUE
);
153 // Adds a tool. See the documentation for wxToolBar for details.
155 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
156 const wxString
& labelText
= wxT(""), bool alignTextRight
= FALSE
,
157 bool isFlat
= TRUE
);
159 // Method from wxToolBarBase (for compatibility), only
160 // the first two arguments are valid.
161 // See the documentation for wxToolBar for details.
163 virtual wxToolBarToolBase
*AddTool(const int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
164 const bool toggle
= FALSE
, const long xPos
= -1, const long yPos
= -1, wxObject
*clientData
= NULL
,
165 const wxString
& helpString1
= wxT(""), const wxString
& helpString2
= wxT(""));
167 // Adds a separator. See the documentation for wxToolBar for details.
169 virtual void AddSeparator( wxWindow
* pSepartorWnd
= NULL
);
171 // Returns tool information for the given tool index.
173 wxDynToolInfo
* GetToolInfo( int toolIndex
);
175 // Removes the given tool. Misspelt in order not to clash with a similar function
176 // in the base class.
178 void RemveTool( int toolIndex
);
180 // Draws a separator. The default implementation draws a shaded line.
182 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
184 // Performs layout. See definitions of orientation types.
186 virtual bool Layout();
188 // Returns the preferred dimension, taking the given dimension and a reference to the result.
190 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
192 // Creates the default layout (BagLayout).
194 virtual LayoutManagerBase
* CreateDefaultLayout() { return new BagLayout(); }
196 // Sets the layout for this toolbar.
198 virtual void SetLayout( LayoutManagerBase
* pLayout
);
200 // Enables or disables the given tool.
202 virtual void EnableTool(int toolIndex
, bool enable
= TRUE
);
204 // Responds to size events, calling Layout.
206 void OnSize( wxSizeEvent
& event
);
208 // Responds to paint events, drawing separators.
210 void OnPaint( wxPaintEvent
& event
);
212 // Responds to background erase events. Currently does nothing.
214 void OnEraseBackground( wxEraseEvent
& event
);
216 // Overriden from wxToolBarBase; does nothing.
218 virtual bool Realize(void);
220 // Finds a tool for the given position.
222 virtual wxToolBarToolBase
*FindToolForPosition(wxCoord x
,
225 // Inserts a tool at the given position.
227 virtual bool DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
);
229 // Deletes a tool. The tool is still in m_tools list when this function is called, and it will
230 // only be deleted from it if it succeeds.
232 virtual bool DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
);
234 // Called when the tools enabled flag changes.
236 virtual void DoEnableTool(wxToolBarToolBase
*tool
, bool enable
);
238 // Called when the tool is toggled.
240 virtual void DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
);
242 // Called when the tools 'can be toggled' flag changes.
244 virtual void DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
);
246 // Creates a toolbar tool.
248 virtual wxToolBarToolBase
*CreateTool(int id
,
249 const wxString
& label
,
250 const wxBitmap
& bmpNormal
,
251 const wxBitmap
& bmpDisabled
,
253 wxObject
*clientData
,
254 const wxString
& shortHelp
,
255 const wxString
& longHelp
);
257 // Creates a toolbar tool.
259 virtual wxToolBarToolBase
*CreateTool(wxControl
*control
);
262 DECLARE_EVENT_TABLE()
263 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
266 #endif /* __DYNTBAR_G__ */