1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDynamicToolBar header
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/tbarbase.h"
16 #include "wx/dynarray.h"
17 #include "wx/fl/fldefs.h"
23 class WXDLLIMPEXP_FL wxToolLayoutItem
: public wxObject
25 DECLARE_DYNAMIC_CLASS(wxToolLayoutItem
)
32 class WXDLLIMPEXP_FL wxDynToolInfo
;
34 typedef wxToolLayoutItem
* wxToolLayoutItemPtrT
;
35 typedef wxDynToolInfo
* wxDynToolInfoPtrT
;
37 WXFL_DEFINE_ARRAY_PTR( wxToolLayoutItemPtrT
, wxLayoutItemArrayT
);
38 WXFL_DEFINE_ARRAY_PTR( wxDynToolInfoPtrT
, wxDynToolInfoArrayT
);
41 This is a base class for layout algorithm implementations.
44 class WXDLLIMPEXP_FL LayoutManagerBase
48 virtual void Layout( const wxSize
& parentDim
,
50 wxLayoutItemArrayT
& items
,
55 virtual ~LayoutManagerBase() {}
59 BagLayout lays out items in left-to-right order from
63 class WXDLLIMPEXP_FL BagLayout
: public LayoutManagerBase
67 virtual void Layout( const wxSize
& parentDim
,
69 wxLayoutItemArrayT
& items
,
75 This class holds dynamic toolbar item information.
78 class WXDLLIMPEXP_FL wxDynToolInfo
: public wxToolLayoutItem
80 DECLARE_DYNAMIC_CLASS(wxDynToolInfo
)
88 // Layout orientations for tools
90 #define LO_HORIZONTAL 0
92 #define LO_FIT_TO_WINDOW 2
95 wxDynamicToolBar manages containment and layout of tool windows.
98 class WXDLLIMPEXP_FL wxDynamicToolBar
: public wxToolBarBase
101 friend class wxDynamicToolBarSerializer
;
103 wxDynToolInfoArrayT mTools
;
104 LayoutManagerBase
* mpLayoutMan
;
107 // Internal function for sizing tool windows.
108 virtual void SizeToolWindows();
110 public: /* public properties */
112 int mSepartorSize
; // default: 8
113 int mVertGap
; // default: 0
114 int mHorizGap
; // default: 0
117 // Default constructor.
121 // Constructor: see the documentation for wxToolBar for details.
123 wxDynamicToolBar(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
124 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
,
125 const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
129 ~wxDynamicToolBar(void);
131 // Creation function: see the documentation for wxToolBar for details.
133 bool Create(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
134 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
, const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
136 // Adds a tool. See the documentation for wxToolBar for details.
138 virtual void AddTool( int toolIndex
,
139 wxWindow
* pToolWindow
,
140 const wxSize
& size
= wxDefaultSize
);
142 // Adds a tool. See the documentation for wxToolBar for details.
144 virtual void AddTool( int toolIndex
,
145 const wxString
& imageFileName
,
146 wxBitmapType imageFileType
= wxBITMAP_TYPE_BMP
,
147 const wxString
& labelText
= wxT(""), bool alignTextRight
= false,
148 bool isFlat
= true );
149 // Adds a tool. See the documentation for wxToolBar for details.
151 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
152 const wxString
& labelText
= wxT(""), bool alignTextRight
= false,
153 bool isFlat
= true );
155 // Unhide method from parent.
157 virtual wxToolBarToolBase
*AddTool (wxToolBarToolBase
*tool
)
158 { return wxToolBarBase::AddTool(tool
); };
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
= wxDefaultCoord
, const long yPos
= wxDefaultCoord
, wxObject
*clientData
= NULL
,
166 const wxString
& helpString1
= wxT(""), const wxString
& helpString2
= wxT(""));
168 // Adds a separator. See the documentation for wxToolBar for details.
170 virtual void AddSeparator( wxWindow
* pSepartorWnd
);
172 // Unhide method from parent.
174 virtual wxToolBarToolBase
*AddSeparator()
175 { return wxToolBarBase::AddSeparator(); };
177 // Returns tool information for the given tool index.
179 wxDynToolInfo
* GetToolInfo( int toolIndex
);
181 // Removes the given tool. Misspelt in order not to clash with a similar function
182 // in the base class.
184 void RemveTool( int toolIndex
);
186 // Draws a separator. The default implementation draws a shaded line.
188 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
190 // Performs layout. See definitions of orientation types.
192 virtual bool Layout();
194 // Returns the preferred dimension, taking the given dimension and a reference to the result.
196 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
198 // Creates the default layout (BagLayout).
200 virtual LayoutManagerBase
* CreateDefaultLayout() { return new BagLayout(); }
202 // Sets the layout for this toolbar.
204 virtual void SetLayout( LayoutManagerBase
* pLayout
);
206 // Enables or disables the given tool.
208 virtual void EnableTool(int toolIndex
, bool enable
= true);
210 // Responds to size events, calling Layout.
212 void OnSize( wxSizeEvent
& event
);
214 // Responds to paint events, drawing separators.
216 void OnPaint( wxPaintEvent
& event
);
218 // Responds to background erase events. Currently does nothing.
220 void OnEraseBackground( wxEraseEvent
& event
);
222 // Overriden from wxToolBarBase; does nothing.
224 virtual bool Realize(void);
226 // Finds a tool for the given position.
228 virtual wxToolBarToolBase
*FindToolForPosition(wxCoord x
,
231 // Inserts a tool at the given position.
233 virtual bool DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
);
235 // Deletes a tool. The tool is still in m_tools list when this function is called, and it will
236 // only be deleted from it if it succeeds.
238 virtual bool DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
);
240 // Called when the tools enabled flag changes.
242 virtual void DoEnableTool(wxToolBarToolBase
*tool
, bool enable
);
244 // Called when the tool is toggled.
246 virtual void DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
);
248 // Called when the tools 'can be toggled' flag changes.
250 virtual void DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
);
252 // Creates a toolbar tool.
254 virtual wxToolBarToolBase
*CreateTool(int id
,
255 const wxString
& label
,
256 const wxBitmap
& bmpNormal
,
257 const wxBitmap
& bmpDisabled
,
259 wxObject
*clientData
,
260 const wxString
& shortHelp
,
261 const wxString
& longHelp
);
263 // Creates a toolbar tool.
265 virtual wxToolBarToolBase
*CreateTool(wxControl
*control
);
268 DECLARE_EVENT_TABLE()
269 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
272 #endif /* __DYNTBAR_G__ */