]>
Commit | Line | Data |
---|---|---|
bd9396d5 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: No names yet. | |
3 | // Purpose: Contrib. demo | |
4 | // Author: Aleksandras Gluchovas | |
5 | // Modified by: | |
6 | // Created: ??/10/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Aleksandras Gluchovas | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __DYNTBAR_G__ | |
13 | #define __DYNTBAR_G__ | |
14 | ||
15 | #include "wx/tbarbase.h" | |
16 | #include "wx/dynarray.h" | |
17 | ||
18 | // layout item | |
19 | ||
20 | class wxToolLayoutItem : public wxObject | |
21 | { | |
22 | public: | |
23 | wxRect mRect; | |
24 | bool mIsSeparator; | |
25 | }; | |
26 | ||
27 | class wxDynToolInfo; | |
28 | ||
29 | typedef wxToolLayoutItem* wxToolLayoutItemPtrT; | |
30 | typedef wxDynToolInfo* wxDynToolInfoPtrT; | |
31 | ||
32 | ||
33 | WX_DEFINE_ARRAY( wxToolLayoutItemPtrT, wxLayoutItemArrayT ); | |
34 | WX_DEFINE_ARRAY( wxDynToolInfoPtrT, wxDynToolInfoArrayT ); | |
35 | ||
36 | // base class for layouting algorithm implementations | |
37 | ||
38 | class LayoutManagerBase | |
39 | { | |
40 | public: | |
41 | virtual void Layout( const wxSize& parentDim, | |
42 | wxSize& resultingDim, | |
43 | wxLayoutItemArrayT& items, | |
44 | int horizGap, | |
45 | int vertGap ) = 0; | |
46 | ||
47 | virtual ~LayoutManagerBase() {} | |
48 | }; | |
49 | ||
50 | // layouts items in left-to-right order from | |
51 | // top towards bottom | |
52 | ||
53 | class BagLayout : public LayoutManagerBase | |
54 | { | |
55 | public: | |
56 | virtual void Layout( const wxSize& parentDim, | |
57 | wxSize& resultingDim, | |
58 | wxLayoutItemArrayT& items, | |
59 | int horizGap, | |
60 | int vertGap ); | |
61 | }; | |
62 | ||
63 | class wxDynToolInfo : public wxToolLayoutItem | |
64 | { | |
65 | DECLARE_DYNAMIC_CLASS(wxDynToolInfo) | |
66 | ||
67 | public: | |
68 | wxWindow* mpToolWnd; | |
69 | int mIndex; | |
70 | wxSize mRealSize; | |
71 | }; | |
72 | ||
73 | // layouting orientations for tools | |
74 | ||
75 | #define LO_HORIZONTAL 0 | |
76 | #define LO_VERTICAL 1 | |
77 | #define LO_FIT_TO_WINDOW 2 | |
78 | ||
79 | // class manages containment and layouting of tool-windows | |
80 | ||
81 | class wxDynamicToolBar : public wxToolBarBase | |
82 | { | |
83 | DECLARE_DYNAMIC_CLASS(wxDynamicToolBar) | |
84 | protected: | |
85 | ||
86 | friend class wxDynamicToolBarSerializer; | |
87 | ||
88 | wxDynToolInfoArrayT mTools; | |
89 | LayoutManagerBase* mpLayoutMan; | |
90 | ||
91 | protected: | |
92 | virtual void SizeToolWindows(); | |
93 | ||
94 | public: /* public properties */ | |
95 | ||
96 | int mSepartorSize; // default: 8 | |
97 | int mVertGap; // default: 0 | |
98 | int mHorizGap; // default: 0 | |
99 | ||
100 | public: | |
101 | wxDynamicToolBar(); | |
102 | ||
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); | |
106 | ||
107 | ~wxDynamicToolBar(void); | |
108 | ||
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); | |
111 | ||
112 | // overridables | |
113 | ||
114 | virtual void AddTool( int toolIndex, | |
115 | wxWindow* pToolWindow, | |
116 | const wxSize& size = wxDefaultSize ); | |
117 | ||
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 | ||
124 | // method from wxToolBarBase (for compatibility), only | |
125 | // first two arguments are valid | |
126 | ||
127 | virtual wxToolBarTool *AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap, | |
128 | const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL, | |
129 | const wxString& helpString1 = "", const wxString& helpString2 = ""); | |
130 | ||
131 | virtual void AddSeparator( wxWindow* pSepartorWnd = NULL ); | |
132 | ||
133 | wxDynToolInfo* GetToolInfo( int toolIndex ); | |
134 | ||
135 | void RemveTool( int toolIndex ); | |
136 | ||
137 | // the default implementation draws shaded line | |
138 | virtual void DrawSeparator( wxDynToolInfo& info, wxDC& dc ); | |
139 | ||
140 | // see definitions of orientation types | |
141 | virtual void Layout(); | |
142 | ||
143 | virtual void GetPreferredDim( const wxSize& givenDim, wxSize& prefDim ); | |
144 | ||
145 | virtual LayoutManagerBase* CreateDefaulLayout() { return new BagLayout(); } | |
146 | ||
147 | virtual void SetLayout( LayoutManagerBase* pLayout ); | |
148 | ||
149 | virtual void EnableTool(const int toolIndex, const bool enable = TRUE); | |
150 | ||
151 | // event handlers | |
152 | ||
153 | void OnSize( wxSizeEvent& event ); | |
154 | void OnPaint( wxPaintEvent& event ); | |
155 | void OnEraseBackground( wxEraseEvent& event ); | |
156 | ||
157 | // overriden from wxToolBarBase | |
158 | ||
159 | virtual bool Realize(void); | |
160 | ||
161 | DECLARE_EVENT_TABLE() | |
162 | }; | |
163 | ||
164 | #endif |