1 /////////////////////////////////////////////////////////////////////////////
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 __FOLDPANELBAR_H__
14 #define __FOLDPANELBAR_H__
16 #ifdef WXMAKINGDLL_FOLDBAR
17 #define WXDLLIMPEXP_FOLDBAR WXEXPORT
18 #elif defined(WXUSINGDLL)
19 #define WXDLLIMPEXP_FOLDBAR WXIMPORT
20 #else // not making nor using DLL
21 #define WXDLLIMPEXP_FOLDBAR
25 #define wxFPB_EXTRA_X 10
26 #define wxFPB_EXTRA_Y 4
27 #define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be aligned from the right filled with space
31 /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
32 starts with first colour, and ends with second colour */
33 wxCAPTIONBAR_GRADIENT_V
= 1,
34 /** Specifies the gradient going from left to right. The gradient starts with first colour, and
35 ends with second colour on the right */
36 wxCAPTIONBAR_GRADIENT_H
,
37 /** Fills the captionbar with a single colour. The first colour is used for this fill */
39 /** Draws a rectangle only using the second colour. The first colour is not used*/
40 wxCAPTIONBAR_RECTANGLE
,
41 /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
42 using the second colour. */
43 wxCAPTIONBAR_FILLED_RECTANGLE
46 /** \class wxCaptionBarStyle
47 This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel
48 where the caption is displayed). It can either be applied at creation time be reapplied when styles need to
51 At construction time, all styles are set to their default transparency. This means none of the styles will be
52 applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
53 the color, font or panel style, these styles become active to be used.
55 class WXDLLIMPEXP_FOLDBAR wxCaptionBarStyle
58 // boolean flags for default transparency on styles
59 bool m_firstColourUsed
,
66 wxColour m_firstColour
, m_secondColour
, m_textColour
;
71 /** Default constructor for this class */
76 ~wxCaptionBarStyle() {
80 void ResetDefaults() {
81 m_firstColourUsed
= false;
82 m_secondColourUsed
= false;
83 m_textColourUsed
= false;
84 m_captionFontUsed
= false;
85 m_captionStyleUsed
= false;
86 m_captionStyle
= wxCAPTIONBAR_GRADIENT_V
;
89 /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
90 styles are not copied */
91 void operator=(const wxCaptionBarStyle
&s
) {
92 if(s
.m_captionStyleUsed
)
94 m_captionStyleUsed
= true;
95 m_captionStyle
= s
.m_captionStyle
;
97 if(s
.m_captionFontUsed
)
99 m_captionFontUsed
= true;
100 m_captionFont
= s
.m_captionFont
;
102 if(s
.m_firstColourUsed
)
104 m_firstColourUsed
= true;
105 m_firstColour
= s
.m_firstColour
;
107 if(s
.m_secondColourUsed
)
109 m_secondColourUsed
= true;
110 m_secondColour
= s
.m_secondColour
;
112 if(s
.m_textColourUsed
)
114 m_textColourUsed
= true;
115 m_textColour
= s
.m_textColour
;
119 // ------- CaptionBar Font -------
121 /** Set font for the caption bar. If this is not set, the font property is undefined
122 and will not be used. Use CaptionFontUsed() to check if this style is used */
123 void SetCaptionFont(const wxFont
&font
) {
124 m_captionFont
= font
;
125 m_captionFontUsed
= true;
128 /** Checks if the caption bar font is set */
129 bool CaptionFontUsed() const {
130 return m_captionFontUsed
;
133 /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
134 this property is not previously set
135 \sa SetCaptionFont(), CaptionFontUsed() */
136 wxFont
GetCaptionFont() const {
137 wxASSERT(m_captionFontUsed
);
138 return m_captionFont
;
141 // ------- FirstColour -------
143 /** Set first colour for the caption bar. If this is not set, the colour property is
144 undefined and will not be used. Use FirstColourUsed() to check if this
146 void SetFirstColour(const wxColour
&col
) {
148 m_firstColourUsed
= true;
151 /** Checks if the first colour of the caption bar is set */
152 bool FirstColourUsed() const {
153 return m_firstColourUsed
;
156 /** Returns the first colour for the caption bar. Please be warned this will
157 result in an assertion failure when this property is not previously set.
158 \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
159 wxColour
GetFirstColour() const {
160 wxASSERT(m_firstColourUsed
);
161 return m_firstColour
;
164 // ------- SecondColour -------
166 /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
167 will not be used. Use SecondColourUsed() to check if this style is used */
168 void SetSecondColour(const wxColour
&col
) {
169 m_secondColour
= col
;
170 m_secondColourUsed
= true;
173 /** Checks if the second colour of the caption bar is set */
174 bool SecondColourUsed() const {
175 return m_secondColourUsed
;
178 /** Returns the second colour for the caption bar. Please be warned this will result in
179 an assertion failure when this property is not previously set.
180 \sa SetSecondColour(), SecondColourUsed() */
181 wxColour
GetSecondColour() const {
182 wxASSERT(m_secondColourUsed
);
183 return m_secondColour
;
186 // ------- Caption Text Colour -------
188 /** Set caption colour for the caption bar. If this is not set, the colour property is
189 undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
190 void SetCaptionColour(const wxColour
&col
) {
192 m_textColourUsed
= true;
195 /** Checks if the caption colour of the caption bar is set */
196 bool CaptionColourUsed() const {
197 return m_textColourUsed
;
200 /** Returns the caption colour for the caption bar. Please be warned this will
201 result in an assertion failure when this property is not previously set.
202 \sa SetCaptionColour(), CaptionColourUsed() */
203 wxColour
GetCaptionColour() const {
204 wxASSERT(m_textColourUsed
);
208 // ------- CaptionStyle -------
210 /** Set caption style for the caption bar. If this is not set, the property is
211 undefined and will not be used. Use CaptionStyleUsed() to check if this style is used.
212 The following styles can be applied:
213 - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
214 - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
215 - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
216 - wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
217 - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it
219 void SetCaptionStyle(int style
) {
220 m_captionStyle
= style
;
221 m_captionStyleUsed
= true;
224 /** Checks if the caption style of the caption bar is set */
225 bool CaptionStyleUsed() const {
226 return m_captionStyleUsed
;
229 /** Returns the caption style for the caption bar. Please be warned this will
230 result in an assertion failure when this property is not previously set.
231 \sa SetCaptionStyle(), CaptionStyleUsed() */
232 int GetCaptionStyle() const {
233 wxASSERT(m_captionStyleUsed
);
234 return m_captionStyle
;
238 #ifndef _NO_CAPTIONBAR_
240 /** \class wxCaptionBar
241 This class is a graphical caption component that consists of a caption and a clickable arrow.
243 The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught
244 and the parent window can act upon the collapsed or expanded state of the bar (which is actually just
245 the icon which changed). The parent panel can reduce size or expand again.
248 #include <wx/imaglist.h>
250 /** Defines an empty captionbar style */
251 #define wxEmptyCaptionBarStyle wxCaptionBarStyle()
253 class WXDLLIMPEXP_FOLDBAR wxCaptionBar
: public wxWindow
257 wxImageList
*m_foldIcons
;
259 //wxFont m_captionFont;
261 int m_iconWidth
, m_iconHeight
;
262 //int m_captionStyle;
264 //wxColour m_firstColour, m_secondColour, m_textColour;
266 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
269 wxCaptionBarStyle m_captionStyle
;
271 /** Fills the background of the caption with either a gradient, or a solid color */
272 void FillCaptionBackground(wxPaintDC
&dc
);
275 void DrawHorizontalGradient(wxDC
&dc
, const wxRect
&rect
);
276 void DrawVerticalGradient(wxDC
&dc
, const wxRect
&rect
);
277 void DrawSingleColour(wxDC
&dc
, const wxRect
&rect
);
278 void DrawSingleRectangle(wxDC
&dc
, const wxRect
&rect
);
280 void RedrawIconBitmap();
282 void ApplyCaptionStyle(const wxCaptionBarStyle
&cbstyle
, bool applyDefault
);
285 /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
286 which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
287 represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
288 wxCaptionBar(wxWindow
* parent
, const wxString
&caption
, wxImageList
*images
,
289 wxWindowID id
= wxID_ANY
, const wxCaptionBarStyle
&cbstyle
= wxEmptyCaptionBarStyle
,
290 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= wxNO_BORDER
);
294 /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
295 set applyDefault to true, all other (not defined) styles will be set to default. If it is false,
296 the styles which are not set in the wxCaptionBarStyle will be ignored */
297 void SetCaptionStyle(bool applyDefault
, wxCaptionBarStyle style
= wxEmptyCaptionBarStyle
) {
298 ApplyCaptionStyle(style
, applyDefault
);
302 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
304 wxCaptionBarStyle
GetCaptionStyle() {
305 return m_captionStyle
;
308 bool IsVertical() const;
311 /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
312 The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
313 be used and if they all have their own bitmap resources it will eat up more memory then needed. It will
314 also ease the use of shared icon change, when there is any need to.
316 If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel
317 will work to collapse / expand.
319 The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
320 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
323 The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing),
324 make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize
325 all the windows accordingly */
327 void SetFoldIcons(wxImageList
*images
) {
328 m_foldIcons
= images
;
329 m_iconWidth
= m_iconHeight
= 0;
331 m_foldIcons
->GetSize(0, m_iconWidth
, m_iconHeight
);
338 /** Returns wether the status of the bar is expanded or collapsed */
339 bool IsCollapsed() const {
343 /** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be
344 drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before
345 assigning an image list to prevent a redraw */
347 void SetRightIndent(int pixels
) {
348 wxCHECK2(pixels
>= 0, return);
349 m_rightIndent
= pixels
;
350 // issue a refresh (if we have a bmp)
356 /** Return the best size for this panel, based upon the font assigned to this window, and the
358 wxSize
DoGetBestSize() const;
360 /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
361 to be sent to the parent */
367 /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
368 to be sent to the parent */
375 GetFont().SetWeight(wxBOLD
);
378 void SetNormalFont() {
379 GetFont().SetWeight(wxNORMAL
);
384 /** The paint event for flat or gradient fill */
385 void OnPaint(wxPaintEvent
& event
);
387 /** For clicking the icon, the mouse event must be intercepted */
388 void OnMouseEvent(wxMouseEvent
& event
);
390 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
391 void OnChar(wxKeyEvent
& event
);
393 void OnSize(wxSizeEvent
&event
);
397 DECLARE_NO_COPY_CLASS(wxCaptionBar
)
398 DECLARE_EVENT_TABLE()
401 /***********************************************************************************************************/
403 /** \class wxCaptionBarEvent
404 This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
405 that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
406 windows accordingly */
408 class WXDLLIMPEXP_FOLDBAR wxCaptionBarEvent
: public wxCommandEvent
413 wxCaptionBar
*m_captionBar
;
417 wxCaptionBarEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
418 : wxCommandEvent(commandType
, id
)
424 /** Constructor for clone copy */
425 wxCaptionBarEvent(const wxCaptionBarEvent
&event
);
427 /** Clone function */
428 virtual wxEvent
*Clone() const {
429 return new wxCaptionBarEvent(*this);
432 /** Returns wether the bar is expanded or collapsed. True means expanded */
433 bool GetFoldStatus() const {
434 wxCHECK(m_captionBar
, false);
435 return !m_captionBar
->IsCollapsed();
438 /** Returns the bar associated with this event */
439 wxCaptionBar
*GetCaptionBar() const {
443 void SetTag(void *tag
) {
447 void *GetTag() const {
451 /** Sets the bar associated with this event, should not used
452 by any other then the originator of the event */
453 void SetCaptionBar(wxCaptionBar
*bar
) {
457 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent
)
461 BEGIN_DECLARE_EVENT_TYPES()
462 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_FOLDBAR
, wxEVT_CAPTIONBAR
, 7777)
463 END_DECLARE_EVENT_TYPES()
465 typedef void (wxEvtHandler::*wxCaptionBarEventFunction
)(wxCaptionBarEvent
&);
467 #define EVT_CAPTIONBAR(id, fn) \
468 DECLARE_EVENT_TABLE_ENTRY( \
469 wxEVT_CAPTIONBAR, id, wxID_ANY, \
470 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(wxCaptionBarEventFunction, & fn), \
474 #endif // _NO_CAPTIONBAR_