1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dyntbar.h"
19 #include "wx/tbarbase.h"
20 #include "wx/dynarray.h"
24 class wxToolLayoutItem
: public wxObject
33 typedef wxToolLayoutItem
* wxToolLayoutItemPtrT
;
34 typedef wxDynToolInfo
* wxDynToolInfoPtrT
;
37 WX_DEFINE_ARRAY( wxToolLayoutItemPtrT
, wxLayoutItemArrayT
);
38 WX_DEFINE_ARRAY( wxDynToolInfoPtrT
, wxDynToolInfoArrayT
);
40 // base class for layouting algorithm implementations
42 class LayoutManagerBase
45 virtual void Layout( const wxSize
& parentDim
,
47 wxLayoutItemArrayT
& items
,
51 virtual ~LayoutManagerBase() {}
54 // layouts items in left-to-right order from
57 class BagLayout
: public LayoutManagerBase
60 virtual void Layout( const wxSize
& parentDim
,
62 wxLayoutItemArrayT
& items
,
67 class wxDynToolInfo
: public wxToolLayoutItem
69 DECLARE_DYNAMIC_CLASS(wxDynToolInfo
)
77 // layouting orientations for tools
79 #define LO_HORIZONTAL 0
81 #define LO_FIT_TO_WINDOW 2
83 // class manages containment and layouting of tool-windows
85 class wxDynamicToolBar
: public wxToolBarBase
87 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
90 friend class wxDynamicToolBarSerializer
;
92 wxDynToolInfoArrayT mTools
;
93 LayoutManagerBase
* mpLayoutMan
;
96 virtual void SizeToolWindows();
98 public: /* public properties */
100 int mSepartorSize
; // default: 8
101 int mVertGap
; // default: 0
102 int mHorizGap
; // default: 0
107 wxDynamicToolBar(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
108 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
,
109 const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
111 ~wxDynamicToolBar(void);
113 bool Create(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
114 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
, const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
118 virtual void AddTool( int toolIndex
,
119 wxWindow
* pToolWindow
,
120 const wxSize
& size
= wxDefaultSize
);
122 virtual void AddTool( int toolIndex
,
123 const wxString
& imageFileName
,
124 int imageFileType
= wxBITMAP_TYPE_BMP
,
125 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
126 bool isFlat
= TRUE
);
127 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
128 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
129 bool isFlat
= TRUE
);
131 // method from wxToolBarBase (for compatibility), only
132 // first two arguments are valid
134 virtual wxToolBarToolBase
*AddTool(const int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
135 const bool toggle
= FALSE
, const long xPos
= -1, const long yPos
= -1, wxObject
*clientData
= NULL
,
136 const wxString
& helpString1
= "", const wxString
& helpString2
= "");
138 virtual void AddSeparator( wxWindow
* pSepartorWnd
= NULL
);
140 wxDynToolInfo
* GetToolInfo( int toolIndex
);
142 void RemveTool( int toolIndex
);
144 // the default implementation draws shaded line
145 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
147 // see definitions of orientation types
148 virtual bool Layout();
150 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
152 virtual LayoutManagerBase
* CreateDefaulLayout() { return new BagLayout(); }
154 virtual void SetLayout( LayoutManagerBase
* pLayout
);
156 virtual void EnableTool(const int toolIndex
, const bool enable
= TRUE
);
160 void OnSize( wxSizeEvent
& event
);
161 void OnPaint( wxPaintEvent
& event
);
162 void OnEraseBackground( wxEraseEvent
& event
);
164 // overriden from wxToolBarBase
166 virtual bool Realize(void);
168 // stuff from the 2.1.15
170 virtual wxToolBarToolBase
*FindToolForPosition(wxCoord x
,
174 virtual bool DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
);
176 // the tool is still in m_tools list when this function is called, it will
177 // only be deleted from it if it succeeds
178 virtual bool DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
);
180 // called when the tools enabled flag changes
181 virtual void DoEnableTool(wxToolBarToolBase
*tool
, bool enable
);
183 // called when the tool is toggled
184 virtual void DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
);
186 // called when the tools "can be toggled" flag changes
187 virtual void DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
);
189 // the functions to create toolbar tools
190 virtual wxToolBarToolBase
*CreateTool(int id
,
191 const wxBitmap
& bitmap1
,
192 const wxBitmap
& bitmap2
,
194 wxObject
*clientData
,
195 const wxString
& shortHelpString
,
196 const wxString
& longHelpString
);
197 virtual wxToolBarToolBase
*CreateTool(wxControl
*control
);
200 DECLARE_EVENT_TABLE()
203 #endif /* __DYNTBAR_G__ */