1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelitem.h
3 // Purpose: wxFoldPanel
4 // Author: Jorgen Bodde
5 // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6 // : wxWidgets coding standards
9 // Copyright: (c) Jorgen Bodde
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef __WXFOLDPANELITEM_H__
14 #define __WXFOLDPANELITEM_H__
16 #include "wx/foldbar/captionbar.h"
18 #define wxFPB_ALIGN_LEFT 0
19 #define wxFPB_ALIGN_WIDTH 1
21 #define wxFPB_DEFAULT_LEFTSPACING 5
22 #define wxFPB_DEFAULT_RIGHTSPACING 10
23 #define wxFPB_DEFAULT_SPACING 8
25 #define wxFPB_DEFAULT_LEFTLINESPACING 2
26 #define wxFPB_DEFAULT_RIGHTLINESPACING 2
28 class wxFoldWindowItem
36 int m_lineLength
, m_lineY
;
37 wxColour m_sepLineColour
;
46 // wxWindow constructor. This initialises the class as a wxWindow type
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
)
52 , m_leftSpacing(leftSpacing
)
53 , m_rightSpacing(rightSpacing
)
60 // separator constructor. This initialises the class as a separator type
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
)
66 , m_flags(wxFPB_ALIGN_WIDTH
)
67 , m_leftSpacing(leftSpacing
)
68 , m_rightSpacing(rightSpacing
)
72 , m_sepLineColour(lineColor
)
76 // TODO: Make a c'tor for a captioned splitter
82 int GetLineY() const {
86 int GetLineLength() const {
90 const wxColour
&GetLineColour() const {
91 return m_sepLineColour
;
94 int GetLeftSpacing() const {
98 int GetRightSpacing() const {
99 return m_rightSpacing
;
102 int GetSpacing() const {
106 // returns space needed by the window if type is wxFoldWindowItem::WINDOW
107 // and returns the total size plus the extra spacing
109 int GetWindowLength(bool vertical
) const {
113 wxCHECK(m_wndItem
, 0);
114 wxSize size
= m_wndItem
->GetSize();
115 value
= ( vertical
? size
.GetHeight() : size
.GetWidth() ) + m_Spacing
;
117 else if(m_type
== SEPARATOR
)
118 value
= 1 + m_Spacing
;
123 // resize the element, whatever it is. A separator or
124 // line will be always aligned by width or height
125 // depending on orientation of the whole panel
127 void ResizeItem(int size
, bool vertical
) {
128 if(m_flags
& wxFPB_ALIGN_WIDTH
)
130 // align by taking full width
131 int mySize
= size
- m_leftSpacing
- m_rightSpacing
;
134 mySize
= 10; // can't have negative width
136 if(m_type
== SEPARATOR
)
137 m_lineLength
= mySize
;
140 wxCHECK2(m_wndItem
, return);
141 m_wndItem
->SetSize(vertical
?mySize
:wxDefaultCoord
, vertical
?wxDefaultCoord
:mySize
);
148 #include <wx/dynarray.h>
149 WX_DECLARE_OBJARRAY(wxFoldWindowItem
, wxFoldWindowItemArray
);
154 This class is a child sibling of the wxFoldPanelBar class. It will be containing a wxCaptionBar class
155 for receiving of events, and a the rest of the area can be populated by a wxPanel derived class.
158 class WXDLLIMPEXP_FOLDBAR wxFoldPanelItem
: public wxPanel
161 wxCaptionBar
*m_captionBar
;
163 bool m_controlCreated
;
171 DECLARE_CLASS( wxFoldPanelItem
)
172 DECLARE_EVENT_TABLE()
175 wxFoldWindowItemArray m_items
;
177 void OnSize(wxSizeEvent
&event
);
178 void OnPressCaption(wxCaptionBarEvent
&event
);
179 void OnPaint(wxPaintEvent
&event
);
182 // constructors and destructors
183 wxFoldPanelItem( wxWindow
*parent
, const wxString
&caption
, wxImageList
*icons
= 0, bool collapsedInitially
= false,
184 const wxCaptionBarStyle
&style
= wxEmptyCaptionBarStyle
);
185 virtual ~wxFoldPanelItem();
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 aligned 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
);
193 void AddSeparator(const wxColour
&color
, int ySpacing
, int leftSpacing
, int rightSpacing
);
195 /** Repositions this wxFoldPanelBar and reports the length occupied for the next wxFoldPanelBar in the
197 int Reposition(int pos
);
201 /** Return expanded or collapsed status. If the panel is expanded, true is returned */
202 bool IsExpanded() const {
203 return !m_captionBar
->IsCollapsed();
208 int GetItemPos() const {
212 // this should not be called by the user, because it doesn't trigger the parent
213 // to tell it that we are collapsed or expanded, it only changes visual state
215 m_captionBar
->Collapse();
219 // this should not be called by the user, because it doesn't trigger the parent
220 // to tell it that we are collapsed or expanded, it only changes visual state
222 m_captionBar
->Expand();
226 /* Return size of panel */
228 int GetPanelLength() const {
229 if(m_captionBar
->IsCollapsed())
230 return GetCaptionLength();
236 bool IsVertical() const;
238 // returns space of caption only. This is for folding calulation
241 int GetCaptionLength() const {
242 wxSize size
= m_captionBar
->GetSize();
243 return IsVertical() ? size
.GetHeight() : size
.GetWidth();
246 void ApplyCaptionStyle(const wxCaptionBarStyle
&style
) {
247 wxCHECK2(m_captionBar
, return);
248 m_captionBar
->SetCaptionStyle(false, style
);
251 wxCaptionBarStyle
GetCaptionStyle() {
252 wxCHECK(m_captionBar
, wxEmptyCaptionBarStyle
);
253 return m_captionBar
->GetCaptionStyle();
258 #endif // _NO_DOXYGEN_
260 #endif // __WXFOLDPANELITEM_H__