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