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