1 #ifndef __FOLDPANELBAR_H__
2 #define __FOLDPANELBAR_H__
4 #define wxFPB_EXTRA_X 10
5 #define wxFPB_EXTRA_Y 4
6 #define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space
10 /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
11 starts with first colour, and ends with second colour */
12 wxCAPTIONBAR_GRADIENT_V
= 1,
13 /** Specifies the gradient going from left to right. The gradient starts with first colour, and
14 ends with second colour on the right */
15 wxCAPTIONBAR_GRADIENT_H
,
16 /** Fills the captionbar with a single colour. The first colour is used for this fill */
18 /** Draws a rectangle only using the second colour. The first colour is not used*/
19 wxCAPTIONBAR_RECTANGLE
,
20 /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
21 using the second colour. */
22 wxCAPTIONBAR_FILLED_RECTANGLE
25 /** \class wxCaptionBarStyle
26 This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel
27 where the caption is displayed). It can either be applied at creation time be reapplied when styles need to
30 At construction time, all styles are set to their default transparency. This means none of the styles will be
31 applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
32 the color, font or panel style, these styles become active to be used.
34 class wxCaptionBarStyle
37 // boolean flags for default transparency on styles
38 bool _firstColourUsed
,
45 wxColour _firstColour
, _secondColour
, _textColour
;
50 /** Default constructor for this class */
55 ~wxCaptionBarStyle() {
59 void ResetDefaults() {
60 _firstColourUsed
= false;
61 _secondColourUsed
= false;
62 _textColourUsed
= false;
63 _captionFontUsed
= false;
64 _captionStyleUsed
= false;
65 _captionStyle
= wxCAPTIONBAR_GRADIENT_V
;
68 /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
69 styles are not copied */
70 void operator=(const wxCaptionBarStyle
&s
) {
71 if(s
._captionStyleUsed
)
73 _captionStyleUsed
= true;
74 _captionStyle
= s
._captionStyle
;
76 if(s
._captionFontUsed
)
78 _captionFontUsed
= true;
79 _captionFont
= s
._captionFont
;
81 if(s
._firstColourUsed
)
83 _firstColourUsed
= true;
84 _firstColour
= s
._firstColour
;
86 if(s
._secondColourUsed
)
88 _secondColourUsed
= true;
89 _secondColour
= s
._secondColour
;
93 _textColourUsed
= true;
94 _textColour
= s
._textColour
;
98 // ------- CaptionBar Font -------
100 /** Set font for the caption bar. If this is not set, the font property is undefined
101 and will not be used. Use CaptionFontUsed() to check if this style is used */
102 void SetCaptionFont(const wxFont
&font
) {
104 _captionFontUsed
= true;
107 /** Checks if the caption bar font is set */
108 bool CaptionFontUsed() const {
109 return _captionFontUsed
;
112 /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
113 this property is not previously set
114 \sa SetCaptionFont(), CaptionFontUsed() */
115 wxFont
GetCaptionFont() const {
116 wxASSERT(_captionFontUsed
);
120 // ------- FirstColour -------
122 /** Set first colour for the caption bar. If this is not set, the colour property is
123 undefined and will not be used. Use FirstColourUsed() to check if this
125 void SetFirstColour(const wxColour
&col
) {
127 _firstColourUsed
= true;
130 /** Checks if the first colour of the caption bar is set */
131 bool FirstColourUsed() const {
132 return _firstColourUsed
;
135 /** Returns the first colour for the caption bar. Please be warned this will
136 result in an assertion failure when this property is not previously set.
137 \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
138 wxColour
GetFirstColour() const {
139 wxASSERT(_firstColourUsed
);
143 // ------- SecondColour -------
145 /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
146 will not be used. Use SecondColourUsed() to check if this style is used */
147 void SetSecondColour(const wxColour
&col
) {
149 _secondColourUsed
= true;
152 /** Checks if the second colour of the caption bar is set */
153 bool SecondColourUsed() const {
154 return _secondColourUsed
;
157 /** Returns the second colour for the caption bar. Please be warned this will result in
158 an assertion failure when this property is not previously set.
159 \sa SetSecondColour(), SecondColourUsed() */
160 wxColour
GetSecondColour() const {
161 wxASSERT(_secondColourUsed
);
162 return _secondColour
;
165 // ------- Caption Text Colour -------
167 /** Set caption colour for the caption bar. If this is not set, the colour property is
168 undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
169 void SetCaptionColour(const wxColour
&col
) {
171 _textColourUsed
= true;
174 /** Checks if the caption colour of the caption bar is set */
175 bool CaptionColourUsed() const {
176 return _textColourUsed
;
179 /** Returns the caption colour for the caption bar. Please be warned this will
180 result in an assertion failure when this property is not previously set.
181 \sa SetCaptionColour(), CaptionColourUsed() */
182 wxColour
GetCaptionColour() const {
183 wxASSERT(_textColourUsed
);
187 // ------- CaptionStyle -------
189 /** Set caption style for the caption bar. If this is not set, the property is
190 undefined and will not be used. Use CaptionStyleUsed() to check if this style is used.
191 The following styles can be applied:
192 - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
193 - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
194 - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
195 - wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
196 - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it
198 void SetCaptionStyle(int style
) {
199 _captionStyle
= style
;
200 _captionStyleUsed
= true;
203 /** Checks if the caption style of the caption bar is set */
204 bool CaptionStyleUsed() const {
205 return _captionStyleUsed
;
208 /** Returns the caption style for the caption bar. Please be warned this will
209 result in an assertion failure when this property is not previously set.
210 \sa SetCaptionStyle(), CaptionStyleUsed() */
211 int GetCaptionStyle() const {
212 wxASSERT(_captionStyleUsed
);
213 return _captionStyle
;
217 #ifndef _NO_CAPTIONBAR_
219 /** \class wxCaptionBar
220 This class is a graphical caption component that consists of a caption and a clickable arrow.
222 The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught
223 and the parent window can act upon the collapsed or expanded state of the bar (which is actually just
224 the icon which changed). The parent panel can reduce size or expand again.
227 #include <wx/imaglist.h>
229 /** Defines an empty captionbar style */
230 #define wxEmptyCaptionBarStyle wxCaptionBarStyle()
232 class wxCaptionBar
: public wxWindow
236 wxImageList
*_foldIcons
;
238 //wxFont _captionFont;
240 int _iconWidth
, _iconHeight
;
243 //wxColour _firstColour, _secondColour, _textColour;
245 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
248 wxCaptionBarStyle _style
;
250 /** Fills the background of the caption with either a gradient, or a solid color */
251 void FillCaptionBackground(wxPaintDC
&dc
);
254 void DrawHorizontalGradient(wxDC
&dc
, const wxRect
&rect
);
255 void DrawVerticalGradient(wxDC
&dc
, const wxRect
&rect
);
256 void DrawSingleColour(wxDC
&dc
, const wxRect
&rect
);
257 void DrawSingleRectangle(wxDC
&dc
, const wxRect
&rect
);
259 void RedrawIconBitmap();
261 void ApplyCaptionStyle(const wxCaptionBarStyle
&cbstyle
, bool applyDefault
);
264 /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
265 which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
266 represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
267 wxCaptionBar(wxWindow
* parent
, const wxString
&caption
, wxImageList
*images
,
268 wxWindowID id
= -1, const wxCaptionBarStyle
&cbstyle
= wxEmptyCaptionBarStyle
,
269 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= wxNO_BORDER
);
273 /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
274 set applyDefault to true, all other (not defined) styles will be set to default. If it is false,
275 the styles which are not set in the wxCaptionBarStyle will be ignored */
276 void SetCaptionStyle(bool applyDefault
, wxCaptionBarStyle style
= wxEmptyCaptionBarStyle
) {
277 ApplyCaptionStyle(style
, applyDefault
);
281 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
283 wxCaptionBarStyle
GetCaptionStyle() {
288 /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
289 The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
290 be used and if they all have their own bitmap resources it will eat up more memory then needed. It will
291 also ease the use of shared icon change, when there is any need to.
293 If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel
294 will work to collapse / expand.
296 The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
297 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
300 The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing),
301 make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize
302 all the windows accordingly */
304 void SetFoldIcons(wxImageList
*images
) {
306 _iconWidth
= _iconHeight
= 0;
308 _foldIcons
->GetSize(0, _iconWidth
, _iconHeight
);
315 /** Returns wether the status of the bar is expanded or collapsed */
316 bool IsCollapsed() const {
320 /** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be
321 drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before
322 assigning an image list to prevent a redraw */
324 void SetRightIndent(int pixels
) {
325 wxCHECK2(pixels
>= 0, return);
326 _rightIndent
= pixels
;
327 // issue a refresh (if we have a bmp)
333 /** Return the best size for this panel, based upon the font assigned to this window, and the
335 wxSize
DoGetBestSize() const;
337 /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
338 to be sent to the parent */
344 /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
345 to be sent to the parent */
352 GetFont().SetWeight(wxBOLD
);
355 void SetNormalFont() {
356 GetFont().SetWeight(wxNORMAL
);
361 /** The paint event for flat or gradient fill */
362 void OnPaint(wxPaintEvent
& event
);
364 /** For clicking the icon, the mouse event must be intercepted */
365 void OnMouseEvent(wxMouseEvent
& event
);
367 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
368 void OnChar(wxKeyEvent
& event
);
370 void OnSize(wxSizeEvent
&event
);
374 DECLARE_NO_COPY_CLASS(wxCaptionBar
)
375 DECLARE_EVENT_TABLE()
378 /***********************************************************************************************************/
380 /** \class wxCaptionBarEvent
381 This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
382 that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
383 windows accordingly */
385 class WXDLLEXPORT wxCaptionBarEvent
: public wxCommandEvent
394 wxCaptionBarEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
395 : wxCommandEvent(commandType
, id
)
401 /** Constructor for clone copy */
402 wxCaptionBarEvent(const wxCaptionBarEvent
&event
);
404 /** Clone function */
405 virtual wxEvent
*Clone() const {
406 return new wxCaptionBarEvent(*this);
409 /** Returns wether the bar is expanded or collapsed. True means expanded */
410 bool GetFoldStatus() const {
411 wxCHECK(_bar
, false);
412 return !_bar
->IsCollapsed();
415 /** Returns the bar associated with this event */
416 wxCaptionBar
*GetBar() const {
420 void SetTag(void *tag
) {
424 void *GetTag() const {
428 /** Sets the bar associated with this event, should not used
429 by any other then the originator of the event */
430 void SetBar(wxCaptionBar
*bar
) {
434 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent
)
438 BEGIN_DECLARE_EVENT_TYPES()
439 DECLARE_EVENT_TYPE(wxEVT_CAPTIONBAR
, 7777)
440 END_DECLARE_EVENT_TYPES()
442 typedef void (wxEvtHandler::*wxCaptionBarEventFunction
)(wxCaptionBarEvent
&);
444 #define EVT_CAPTIONBAR(id, fn) \
445 DECLARE_EVENT_TABLE_ENTRY( \
446 wxEVT_CAPTIONBAR, id, -1, \
447 (wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \
452 #endif // _NO_CAPTIONBAR_