]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: foldpanelitem.h | |
3 | // Purpose: wxFoldPanel | |
4 | // Author: Jorgen Bodde | |
5 | // Modified by: | |
6 | // Created: 22/06/2004 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Jorgen Bodde | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __WXFOLDPANELITEM_H__ | |
13 | #define __WXFOLDPANELITEM_H__ | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/wx.h" | |
17 | #endif | |
18 | ||
19 | #include "captionbar.h" | |
20 | ||
21 | #define wxFPB_ALIGN_LEFT 0 | |
22 | #define wxFPB_ALIGN_WIDTH 1 | |
23 | ||
24 | #define wxFPB_DEFAULT_LEFTSPACING 5 | |
25 | #define wxFPB_DEFAULT_RIGHTSPACING 10 | |
26 | #define wxFPB_DEFAULT_YSPACING 8 | |
27 | ||
28 | #define wxFPB_DEFAULT_LEFTLINESPACING 2 | |
29 | #define wxFPB_DEFAULT_RIGHTLINESPACING 2 | |
30 | ||
31 | class wxFoldWindowItem | |
32 | { | |
33 | private: | |
34 | wxWindow *_wnd; | |
35 | int _type, _flags; | |
36 | int _leftSpacing, | |
37 | _rightSpacing, | |
38 | _ySpacing; | |
39 | int _lineWidth, _lineY; | |
40 | wxColour _sepLineColour; | |
41 | ||
42 | public: | |
43 | enum | |
44 | { | |
45 | WINDOW = 0, | |
46 | SEPARATOR | |
47 | }; | |
48 | ||
49 | // wxWindow constructor. This initialises the class as a wxWindow type | |
50 | wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing = wxFPB_DEFAULT_YSPACING, | |
51 | int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing = wxFPB_DEFAULT_RIGHTSPACING) | |
52 | : _wnd(wnd) | |
53 | , _type(WINDOW) | |
54 | , _flags(flags) | |
55 | , _leftSpacing(leftSpacing) | |
56 | , _rightSpacing(rightSpacing) | |
57 | , _ySpacing(ySpacing) | |
58 | , _lineWidth(0) | |
59 | , _lineY(0) | |
60 | { | |
61 | }; | |
62 | ||
63 | // separator constructor. This initialises the class as a separator type | |
64 | wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int ySpacing = wxFPB_DEFAULT_YSPACING, | |
65 | int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING, | |
66 | int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING) | |
67 | : _wnd(0) | |
68 | , _type(SEPARATOR) | |
69 | , _flags(wxFPB_ALIGN_WIDTH) | |
70 | , _leftSpacing(leftSpacing) | |
71 | , _rightSpacing(rightSpacing) | |
72 | , _ySpacing(ySpacing) | |
73 | , _lineWidth(0) | |
74 | , _lineY(y) | |
75 | , _sepLineColour(lineColor) | |
76 | { | |
77 | }; | |
78 | ||
79 | // TODO: Make a c'tor for a captioned splitter | |
80 | ||
81 | int GetType() const { | |
82 | return _type; | |
83 | }; | |
84 | ||
85 | int GetLineY() const { | |
86 | return _lineY; | |
87 | }; | |
88 | ||
89 | int GetLineWidth() const { | |
90 | return _lineWidth; | |
91 | }; | |
92 | ||
93 | const wxColour &GetLineColour() const { | |
94 | return _sepLineColour; | |
95 | }; | |
96 | ||
97 | int GetLeftSpacing() const { | |
98 | return _leftSpacing; | |
99 | }; | |
100 | ||
101 | int GetRightSpacing() const { | |
102 | return _rightSpacing; | |
103 | }; | |
104 | ||
105 | int GetYSpacing() const { | |
106 | return _ySpacing; | |
107 | }; | |
108 | ||
109 | // returns the window height if type is wxFoldWindowItem::WINDOW | |
110 | // and returns the total size plus the extra spacing | |
111 | ||
112 | int GetWindowHeight() const { | |
113 | int value = 0; | |
114 | if(_type == WINDOW) | |
115 | { | |
116 | wxCHECK(_wnd, 0); | |
117 | wxSize size = _wnd->GetSize(); | |
118 | value = size.GetHeight() + _ySpacing; | |
119 | } | |
120 | else if(_type == SEPARATOR) | |
121 | value = 1 + _ySpacing; | |
122 | ||
123 | return value; | |
124 | }; | |
125 | ||
126 | // resize the element, whatever it is. A separator or | |
127 | // line will be always alligned by width | |
128 | ||
129 | void ResizeItem(int width) { | |
130 | if((_flags & wxFPB_ALIGN_WIDTH)) | |
131 | { | |
132 | // allign by taking full width | |
133 | int myWidth = width - _leftSpacing - _rightSpacing; | |
134 | ||
135 | if(myWidth < 0) | |
136 | myWidth = 10; // can't have negative width | |
137 | ||
138 | if(_type == SEPARATOR) | |
139 | _lineWidth = myWidth; | |
140 | else | |
141 | { | |
142 | wxCHECK2(_wnd, return); | |
143 | _wnd->SetSize(wxSize(myWidth, wxDefaultCoord)); | |
144 | } | |
145 | } | |
146 | }; | |
147 | ||
148 | }; | |
149 | ||
150 | #include <wx/dynarray.h> | |
151 | WX_DECLARE_OBJARRAY(wxFoldWindowItem, wxFoldWindowItemArray); | |
152 | ||
153 | #ifndef _NO_DOXYGEN_ | |
154 | ||
155 | /** \wxFoldPanelItem | |
156 | This class is a child sibling of the wxFoldPanelBar class. It will be containing a wxCaptionBar class | |
157 | for receiving of events, and a the rest of the area can be populated by a wxPanel derived class. | |
158 | */ | |
159 | ||
160 | class WXDLLIMPEXP_FOLDBAR wxFoldPanelItem: public wxPanel | |
161 | { | |
162 | private: | |
163 | wxCaptionBar *_captionBar; | |
164 | ||
165 | bool _controlCreated; | |
166 | int _yUserSize, | |
167 | _yPanelSize, | |
168 | _yLastInsertPos; | |
169 | int _yPos; | |
170 | bool _userSized; | |
171 | ||
172 | private: | |
173 | DECLARE_CLASS( wxFoldPanelItem ) | |
174 | DECLARE_EVENT_TABLE() | |
175 | ||
176 | private: | |
177 | wxFoldWindowItemArray _items; | |
178 | ||
179 | void OnSize(wxSizeEvent &event); | |
180 | void OnPressCaption(wxCaptionBarEvent &event); | |
181 | void OnPaint(wxPaintEvent &event); | |
182 | ||
183 | public: | |
184 | // constructors and destructors | |
185 | wxFoldPanelItem( wxWindow *parent, const wxString &caption, wxImageList *icons = 0, bool collapsedInitially = false, | |
186 | const wxCaptionBarStyle &style = wxEmptyCaptionBarStyle); | |
187 | virtual ~wxFoldPanelItem(); | |
188 | ||
189 | /** Add a window item to the list of items on this panel. The flags are wxFPB_ALIGN_LEFT for a non sizing | |
190 | window element, and wxFPB_ALIGN_WIDTH for a width alligned item. The ySpacing parameter reserves a number | |
191 | of pixels before the window element, and leftSpacing is an indent. rightSpacing is only relevant when the | |
192 | style wxFPB_ALIGN_WIDTH is chosen. */ | |
193 | void AddWindow(wxWindow *window, int flags, int ySpacing, int leftSpacing, int rightSpacing); | |
194 | ||
195 | void AddSeparator(const wxColour &color, int ySpacing, int leftSpacing, int rightSpacing); | |
196 | ||
197 | /** Repositions this wxFoldPanelBar and reports the height occupied for the next wxFoldPanelBar in the | |
198 | list */ | |
199 | int Reposition(int y); | |
200 | ||
201 | void ResizePanel(); | |
202 | ||
203 | /** Return expanded or collapsed status. If the panel is expanded, true is returned */ | |
204 | bool IsExpanded() const { | |
205 | return !_captionBar->IsCollapsed(); | |
206 | }; | |
207 | ||
208 | /** Return Y pos */ | |
209 | ||
210 | int GetY() const { | |
211 | return _yPos; | |
212 | }; | |
213 | ||
214 | // this should not be called by the user, because it doesn't trigger the parent | |
215 | // to tell it that we are collapsed or expanded, it only changes visual state | |
216 | void Collapse() { | |
217 | _captionBar->Collapse(); | |
218 | ResizePanel(); | |
219 | }; | |
220 | ||
221 | // this should not be called by the user, because it doesn't trigger the parent | |
222 | // to tell it that we are collapsed or expanded, it only changes visual state | |
223 | void Expand() { | |
224 | _captionBar->Expand(); | |
225 | ResizePanel(); | |
226 | }; | |
227 | ||
228 | /* Return size of panel */ | |
229 | ||
230 | int GetPanelHeight() const { | |
231 | if(_captionBar->IsCollapsed()) | |
232 | return GetCaptionHeight(); | |
233 | else if(_userSized) | |
234 | return _yUserSize; | |
235 | return _yPanelSize; | |
236 | }; | |
237 | ||
238 | // returns height of caption only. This is for folding calulation | |
239 | // purposes | |
240 | ||
241 | int GetCaptionHeight() const { | |
242 | wxSize size = _captionBar->GetSize(); | |
243 | return size.GetHeight(); | |
244 | }; | |
245 | ||
246 | void ApplyCaptionStyle(const wxCaptionBarStyle &style) { | |
247 | wxCHECK2(_captionBar, return); | |
248 | _captionBar->SetCaptionStyle(false, style); | |
249 | }; | |
250 | ||
251 | wxCaptionBarStyle GetCaptionStyle() { | |
252 | wxCHECK(_captionBar, wxEmptyCaptionBarStyle); | |
253 | return _captionBar->GetCaptionStyle(); | |
254 | }; | |
255 | }; | |
256 | ||
257 | ||
258 | #endif // _NO_DOXYGEN_ | |
259 | ||
260 | #endif // __WXFOLDPANELITEM_H__ |