1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/tbarbase.h"
16 #include "wx/dynarray.h"
20 class wxToolLayoutItem
: public wxObject
29 typedef wxToolLayoutItem
* wxToolLayoutItemPtrT
;
30 typedef wxDynToolInfo
* wxDynToolInfoPtrT
;
33 WX_DEFINE_ARRAY( wxToolLayoutItemPtrT
, wxLayoutItemArrayT
);
34 WX_DEFINE_ARRAY( wxDynToolInfoPtrT
, wxDynToolInfoArrayT
);
36 // base class for layouting algorithm implementations
38 class LayoutManagerBase
41 virtual void Layout( const wxSize
& parentDim
,
43 wxLayoutItemArrayT
& items
,
47 virtual ~LayoutManagerBase() {}
50 // layouts items in left-to-right order from
53 class BagLayout
: public LayoutManagerBase
56 virtual void Layout( const wxSize
& parentDim
,
58 wxLayoutItemArrayT
& items
,
63 class wxDynToolInfo
: public wxToolLayoutItem
65 DECLARE_DYNAMIC_CLASS(wxDynToolInfo
)
73 // layouting orientations for tools
75 #define LO_HORIZONTAL 0
77 #define LO_FIT_TO_WINDOW 2
79 // class manages containment and layouting of tool-windows
81 class wxDynamicToolBar
: public wxToolBarBase
83 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar
)
86 friend class wxDynamicToolBarSerializer
;
88 wxDynToolInfoArrayT mTools
;
89 LayoutManagerBase
* mpLayoutMan
;
92 virtual void SizeToolWindows();
94 public: /* public properties */
96 int mSepartorSize
; // default: 8
97 int mVertGap
; // default: 0
98 int mHorizGap
; // default: 0
103 wxDynamicToolBar(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
104 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
,
105 const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
107 ~wxDynamicToolBar(void);
109 bool Create(wxWindow
*parent
, const wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
110 const long style
= wxNO_BORDER
, const int orientation
= wxVERTICAL
, const int RowsOrColumns
= 1, const wxString
& name
= wxToolBarNameStr
);
114 virtual void AddTool( int toolIndex
,
115 wxWindow
* pToolWindow
,
116 const wxSize
& size
= wxDefaultSize
);
118 virtual void AddTool( int toolIndex
,
119 const wxString
& imageFileName
,
120 int imageFileType
= wxBITMAP_TYPE_BMP
,
121 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
122 bool isFlat
= TRUE
);
123 virtual void AddTool( int toolIndex
, wxBitmap labelBmp
,
124 const wxString
& labelText
= "", bool alignTextRight
= FALSE
,
125 bool isFlat
= TRUE
);
127 // method from wxToolBarBase (for compatibility), only
128 // first two arguments are valid
130 virtual wxToolBarTool
*AddTool(const int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
131 const bool toggle
= FALSE
, const long xPos
= -1, const long yPos
= -1, wxObject
*clientData
= NULL
,
132 const wxString
& helpString1
= "", const wxString
& helpString2
= "");
134 virtual void AddSeparator( wxWindow
* pSepartorWnd
= NULL
);
136 wxDynToolInfo
* GetToolInfo( int toolIndex
);
138 void RemveTool( int toolIndex
);
140 // the default implementation draws shaded line
141 virtual void DrawSeparator( wxDynToolInfo
& info
, wxDC
& dc
);
143 // see definitions of orientation types
144 virtual bool Layout();
146 virtual void GetPreferredDim( const wxSize
& givenDim
, wxSize
& prefDim
);
148 virtual LayoutManagerBase
* CreateDefaulLayout() { return new BagLayout(); }
150 virtual void SetLayout( LayoutManagerBase
* pLayout
);
152 virtual void EnableTool(const int toolIndex
, const bool enable
= TRUE
);
156 void OnSize( wxSizeEvent
& event
);
157 void OnPaint( wxPaintEvent
& event
);
158 void OnEraseBackground( wxEraseEvent
& event
);
160 // overriden from wxToolBarBase
162 virtual bool Realize(void);
164 DECLARE_EVENT_TABLE()