1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFoldPanel
4 // Author: Jorgen Bodde
8 // Copyright: (c) Jorgen Bodde
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __FOLDPANELBAR_H__
13 #define __FOLDPANELBAR_H__
15 #ifdef WXMAKINGDLL_FOLDBAR
16 #define WXDLLIMPEXP_FOLDBAR WXEXPORT
17 #elif defined(WXUSINGDLL)
18 #define WXDLLIMPEXP_FOLDBAR WXIMPORT
19 #else // not making nor using DLL
20 #define WXDLLIMPEXP_FOLDBAR
24 #define wxFPB_EXTRA_X 10
25 #define wxFPB_EXTRA_Y 4
26 #define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space
30 /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
31 starts with first colour, and ends with second colour */
32 wxCAPTIONBAR_GRADIENT_V
= 1,
33 /** Specifies the gradient going from left to right. The gradient starts with first colour, and
34 ends with second colour on the right */
35 wxCAPTIONBAR_GRADIENT_H
,
36 /** Fills the captionbar with a single colour. The first colour is used for this fill */
38 /** Draws a rectangle only using the second colour. The first colour is not used*/
39 wxCAPTIONBAR_RECTANGLE
,
40 /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
41 using the second colour. */
42 wxCAPTIONBAR_FILLED_RECTANGLE
45 /** \class wxCaptionBarStyle
46 This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel
47 where the caption is displayed). It can either be applied at creation time be reapplied when styles need to
50 At construction time, all styles are set to their default transparency. This means none of the styles will be
51 applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
52 the color, font or panel style, these styles become active to be used.
54 class wxCaptionBarStyle
57 // boolean flags for default transparency on styles
58 bool _firstColourUsed
,
65 wxColour _firstColour
, _secondColour
, _textColour
;
70 /** Default constructor for this class */
75 ~wxCaptionBarStyle() {
79 void ResetDefaults() {
80 _firstColourUsed
= false;
81 _secondColourUsed
= false;
82 _textColourUsed
= false;
83 _captionFontUsed
= false;
84 _captionStyleUsed
= false;
85 _captionStyle
= wxCAPTIONBAR_GRADIENT_V
;
88 /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
89 styles are not copied */
90 void operator=(const wxCaptionBarStyle
&s
) {
91 if(s
._captionStyleUsed
)
93 _captionStyleUsed
= true;
94 _captionStyle
= s
._captionStyle
;
96 if(s
._captionFontUsed
)
98 _captionFontUsed
= true;
99 _captionFont
= s
._captionFont
;
101 if(s
._firstColourUsed
)
103 _firstColourUsed
= true;
104 _firstColour
= s
._firstColour
;
106 if(s
._secondColourUsed
)
108 _secondColourUsed
= true;
109 _secondColour
= s
._secondColour
;
111 if(s
._textColourUsed
)
113 _textColourUsed
= true;
114 _textColour
= s
._textColour
;
118 // ------- CaptionBar Font -------
120 /** Set font for the caption bar. If this is not set, the font property is undefined
121 and will not be used. Use CaptionFontUsed() to check if this style is used */
122 void SetCaptionFont(const wxFont
&font
) {
124 _captionFontUsed
= true;
127 /** Checks if the caption bar font is set */
128 bool CaptionFontUsed() const {
129 return _captionFontUsed
;
132 /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
133 this property is not previously set
134 \sa SetCaptionFont(), CaptionFontUsed() */
135 wxFont
GetCaptionFont() const {
136 wxASSERT(_captionFontUsed
);
140 // ------- FirstColour -------
142 /** Set first colour for the caption bar. If this is not set, the colour property is
143 undefined and will not be used. Use FirstColourUsed() to check if this
145 void SetFirstColour(const wxColour
&col
) {
147 _firstColourUsed
= true;
150 /** Checks if the first colour of the caption bar is set */
151 bool FirstColourUsed() const {
152 return _firstColourUsed
;
155 /** Returns the first colour for the caption bar. Please be warned this will
156 result in an assertion failure when this property is not previously set.
157 \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
158 wxColour
GetFirstColour() const {
159 wxASSERT(_firstColourUsed
);
163 // ------- SecondColour -------
165 /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
166 will not be used. Use SecondColourUsed() to check if this style is used */
167 void SetSecondColour(const wxColour
&col
) {
169 _secondColourUsed
= true;
172 /** Checks if the second colour of the caption bar is set */
173 bool SecondColourUsed() const {
174 return _secondColourUsed
;
177 /** Returns the second colour for the caption bar. Please be warned this will result in
178 an assertion failure when this property is not previously set.
179 \sa SetSecondColour(), SecondColourUsed() */
180 wxColour
GetSecondColour() const {
181 wxASSERT(_secondColourUsed
);
182 return _secondColour
;
185 // ------- Caption Text Colour -------
187 /** Set caption colour for the caption bar. If this is not set, the colour property is
188 undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
189 void SetCaptionColour(const wxColour
&col
) {
191 _textColourUsed
= true;
194 /** Checks if the caption colour of the caption bar is set */
195 bool CaptionColourUsed() const {
196 return _textColourUsed
;
199 /** Returns the caption colour for the caption bar. Please be warned this will
200 result in an assertion failure when this property is not previously set.
201 \sa SetCaptionColour(), CaptionColourUsed() */
202 wxColour
GetCaptionColour() const {
203 wxASSERT(_textColourUsed
);
207 // ------- CaptionStyle -------
209 /** Set caption style for the caption bar. If this is not set, the property is
210 undefined and will not be used. Use CaptionStyleUsed() to check if this style is used.
211 The following styles can be applied:
212 - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
213 - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
214 - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
215 - wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
216 - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it
218 void SetCaptionStyle(int style
) {
219 _captionStyle
= style
;
220 _captionStyleUsed
= true;
223 /** Checks if the caption style of the caption bar is set */
224 bool CaptionStyleUsed() const {
225 return _captionStyleUsed
;
228 /** Returns the caption style for the caption bar. Please be warned this will
229 result in an assertion failure when this property is not previously set.
230 \sa SetCaptionStyle(), CaptionStyleUsed() */
231 int GetCaptionStyle() const {
232 wxASSERT(_captionStyleUsed
);
233 return _captionStyle
;
237 #ifndef _NO_CAPTIONBAR_
239 /** \class wxCaptionBar
240 This class is a graphical caption component that consists of a caption and a clickable arrow.
242 The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught
243 and the parent window can act upon the collapsed or expanded state of the bar (which is actually just
244 the icon which changed). The parent panel can reduce size or expand again.
247 #include <wx/imaglist.h>
249 /** Defines an empty captionbar style */
250 #define wxEmptyCaptionBarStyle wxCaptionBarStyle()
252 class WXDLLIMPEXP_FOLDBAR wxCaptionBar
: public wxWindow
256 wxImageList
*_foldIcons
;
258 //wxFont _captionFont;
260 int _iconWidth
, _iconHeight
;
263 //wxColour _firstColour, _secondColour, _textColour;
265 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
268 wxCaptionBarStyle _style
;
270 /** Fills the background of the caption with either a gradient, or a solid color */
271 void FillCaptionBackground(wxPaintDC
&dc
);
274 void DrawHorizontalGradient(wxDC
&dc
, const wxRect
&rect
);
275 void DrawVerticalGradient(wxDC
&dc
, const wxRect
&rect
);
276 void DrawSingleColour(wxDC
&dc
, const wxRect
&rect
);
277 void DrawSingleRectangle(wxDC
&dc
, const wxRect
&rect
);
279 void RedrawIconBitmap();
281 void ApplyCaptionStyle(const wxCaptionBarStyle
&cbstyle
, bool applyDefault
);
284 /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
285 which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
286 represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
287 wxCaptionBar(wxWindow
* parent
, const wxString
&caption
, wxImageList
*images
,
288 wxWindowID id
= wxID_ANY
, const wxCaptionBarStyle
&cbstyle
= wxEmptyCaptionBarStyle
,
289 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= wxNO_BORDER
);
293 /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
294 set applyDefault to true, all other (not defined) styles will be set to default. If it is false,
295 the styles which are not set in the wxCaptionBarStyle will be ignored */
296 void SetCaptionStyle(bool applyDefault
, wxCaptionBarStyle style
= wxEmptyCaptionBarStyle
) {
297 ApplyCaptionStyle(style
, applyDefault
);
301 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
303 wxCaptionBarStyle
GetCaptionStyle() {
308 /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
309 The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
310 be used and if they all have their own bitmap resources it will eat up more memory then needed. It will
311 also ease the use of shared icon change, when there is any need to.
313 If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel
314 will work to collapse / expand.
316 The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
317 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
320 The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing),
321 make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize
322 all the windows accordingly */
324 void SetFoldIcons(wxImageList
*images
) {
326 _iconWidth
= _iconHeight
= 0;
328 _foldIcons
->GetSize(0, _iconWidth
, _iconHeight
);
335 /** Returns wether the status of the bar is expanded or collapsed */
336 bool IsCollapsed() const {
340 /** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be
341 drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before
342 assigning an image list to prevent a redraw */
344 void SetRightIndent(int pixels
) {
345 wxCHECK2(pixels
>= 0, return);
346 _rightIndent
= pixels
;
347 // issue a refresh (if we have a bmp)
353 /** Return the best size for this panel, based upon the font assigned to this window, and the
355 wxSize
DoGetBestSize() const;
357 /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
358 to be sent to the parent */
364 /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
365 to be sent to the parent */
372 GetFont().SetWeight(wxBOLD
);
375 void SetNormalFont() {
376 GetFont().SetWeight(wxNORMAL
);
381 /** The paint event for flat or gradient fill */
382 void OnPaint(wxPaintEvent
& event
);
384 /** For clicking the icon, the mouse event must be intercepted */
385 void OnMouseEvent(wxMouseEvent
& event
);
387 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
388 void OnChar(wxKeyEvent
& event
);
390 void OnSize(wxSizeEvent
&event
);
394 DECLARE_NO_COPY_CLASS(wxCaptionBar
)
395 DECLARE_EVENT_TABLE()
398 /***********************************************************************************************************/
400 /** \class wxCaptionBarEvent
401 This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
402 that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
403 windows accordingly */
405 class WXDLLIMPEXP_FOLDBAR wxCaptionBarEvent
: public wxCommandEvent
414 wxCaptionBarEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
415 : wxCommandEvent(commandType
, id
)
421 /** Constructor for clone copy */
422 wxCaptionBarEvent(const wxCaptionBarEvent
&event
);
424 /** Clone function */
425 virtual wxEvent
*Clone() const {
426 return new wxCaptionBarEvent(*this);
429 /** Returns wether the bar is expanded or collapsed. True means expanded */
430 bool GetFoldStatus() const {
431 wxCHECK(_bar
, false);
432 return !_bar
->IsCollapsed();
435 /** Returns the bar associated with this event */
436 wxCaptionBar
*GetBar() const {
440 void SetTag(void *tag
) {
444 void *GetTag() const {
448 /** Sets the bar associated with this event, should not used
449 by any other then the originator of the event */
450 void SetBar(wxCaptionBar
*bar
) {
454 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent
)
458 BEGIN_DECLARE_EVENT_TYPES()
459 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_FOLDBAR
, wxEVT_CAPTIONBAR
, 7777)
460 END_DECLARE_EVENT_TYPES()
462 typedef void (wxEvtHandler::*wxCaptionBarEventFunction
)(wxCaptionBarEvent
&);
464 #define EVT_CAPTIONBAR(id, fn) \
465 DECLARE_EVENT_TABLE_ENTRY( \
466 wxEVT_CAPTIONBAR, id, wxID_ANY, \
467 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(wxCaptionBarEventFunction, & fn), \
471 #endif // _NO_CAPTIONBAR_