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 #define wxFPB_EXTRA_X 10
16 #define wxFPB_EXTRA_Y 4
17 #define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space
21 /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
22 starts with first colour, and ends with second colour */
23 wxCAPTIONBAR_GRADIENT_V
= 1,
24 /** Specifies the gradient going from left to right. The gradient starts with first colour, and
25 ends with second colour on the right */
26 wxCAPTIONBAR_GRADIENT_H
,
27 /** Fills the captionbar with a single colour. The first colour is used for this fill */
29 /** Draws a rectangle only using the second colour. The first colour is not used*/
30 wxCAPTIONBAR_RECTANGLE
,
31 /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
32 using the second colour. */
33 wxCAPTIONBAR_FILLED_RECTANGLE
36 /** \class wxCaptionBarStyle
37 This class encapsulates the styles you wish to set for the wxCaptionBar (this is the part of the wxFoldPanel
38 where the caption is displayed). It can either be applied at creation time be reapplied when styles need to
41 At construction time, all styles are set to their default transparency. This means none of the styles will be
42 applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
43 the color, font or panel style, these styles become active to be used.
45 class wxCaptionBarStyle
48 // boolean flags for default transparency on styles
49 bool _firstColourUsed
,
56 wxColour _firstColour
, _secondColour
, _textColour
;
61 /** Default constructor for this class */
66 ~wxCaptionBarStyle() {
70 void ResetDefaults() {
71 _firstColourUsed
= false;
72 _secondColourUsed
= false;
73 _textColourUsed
= false;
74 _captionFontUsed
= false;
75 _captionStyleUsed
= false;
76 _captionStyle
= wxCAPTIONBAR_GRADIENT_V
;
79 /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
80 styles are not copied */
81 void operator=(const wxCaptionBarStyle
&s
) {
82 if(s
._captionStyleUsed
)
84 _captionStyleUsed
= true;
85 _captionStyle
= s
._captionStyle
;
87 if(s
._captionFontUsed
)
89 _captionFontUsed
= true;
90 _captionFont
= s
._captionFont
;
92 if(s
._firstColourUsed
)
94 _firstColourUsed
= true;
95 _firstColour
= s
._firstColour
;
97 if(s
._secondColourUsed
)
99 _secondColourUsed
= true;
100 _secondColour
= s
._secondColour
;
102 if(s
._textColourUsed
)
104 _textColourUsed
= true;
105 _textColour
= s
._textColour
;
109 // ------- CaptionBar Font -------
111 /** Set font for the caption bar. If this is not set, the font property is undefined
112 and will not be used. Use CaptionFontUsed() to check if this style is used */
113 void SetCaptionFont(const wxFont
&font
) {
115 _captionFontUsed
= true;
118 /** Checks if the caption bar font is set */
119 bool CaptionFontUsed() const {
120 return _captionFontUsed
;
123 /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
124 this property is not previously set
125 \sa SetCaptionFont(), CaptionFontUsed() */
126 wxFont
GetCaptionFont() const {
127 wxASSERT(_captionFontUsed
);
131 // ------- FirstColour -------
133 /** Set first colour for the caption bar. If this is not set, the colour property is
134 undefined and will not be used. Use FirstColourUsed() to check if this
136 void SetFirstColour(const wxColour
&col
) {
138 _firstColourUsed
= true;
141 /** Checks if the first colour of the caption bar is set */
142 bool FirstColourUsed() const {
143 return _firstColourUsed
;
146 /** Returns the first colour for the caption bar. Please be warned this will
147 result in an assertion failure when this property is not previously set.
148 \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
149 wxColour
GetFirstColour() const {
150 wxASSERT(_firstColourUsed
);
154 // ------- SecondColour -------
156 /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
157 will not be used. Use SecondColourUsed() to check if this style is used */
158 void SetSecondColour(const wxColour
&col
) {
160 _secondColourUsed
= true;
163 /** Checks if the second colour of the caption bar is set */
164 bool SecondColourUsed() const {
165 return _secondColourUsed
;
168 /** Returns the second colour for the caption bar. Please be warned this will result in
169 an assertion failure when this property is not previously set.
170 \sa SetSecondColour(), SecondColourUsed() */
171 wxColour
GetSecondColour() const {
172 wxASSERT(_secondColourUsed
);
173 return _secondColour
;
176 // ------- Caption Text Colour -------
178 /** Set caption colour for the caption bar. If this is not set, the colour property is
179 undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
180 void SetCaptionColour(const wxColour
&col
) {
182 _textColourUsed
= true;
185 /** Checks if the caption colour of the caption bar is set */
186 bool CaptionColourUsed() const {
187 return _textColourUsed
;
190 /** Returns the caption colour for the caption bar. Please be warned this will
191 result in an assertion failure when this property is not previously set.
192 \sa SetCaptionColour(), CaptionColourUsed() */
193 wxColour
GetCaptionColour() const {
194 wxASSERT(_textColourUsed
);
198 // ------- CaptionStyle -------
200 /** Set caption style for the caption bar. If this is not set, the property is
201 undefined and will not be used. Use CaptionStyleUsed() to check if this style is used.
202 The following styles can be applied:
203 - wxCAPTIONBAR_GRADIENT_V: Draws a vertical gradient from top to bottom
204 - wxCAPTIONBAR_GRADIENT_H: Draws a horizontal gradient from left to right
205 - wxCAPTIONBAR_SINGLE: Draws a single filled rectangle to draw the caption
206 - wxCAPTIONBAR_RECTANGLE: Draws a single colour with a rectangle around the caption
207 - wxCAPTIONBAR_FILLED_RECTANGLE: Draws a filled rectangle and a border around it
209 void SetCaptionStyle(int style
) {
210 _captionStyle
= style
;
211 _captionStyleUsed
= true;
214 /** Checks if the caption style of the caption bar is set */
215 bool CaptionStyleUsed() const {
216 return _captionStyleUsed
;
219 /** Returns the caption style for the caption bar. Please be warned this will
220 result in an assertion failure when this property is not previously set.
221 \sa SetCaptionStyle(), CaptionStyleUsed() */
222 int GetCaptionStyle() const {
223 wxASSERT(_captionStyleUsed
);
224 return _captionStyle
;
228 #ifndef _NO_CAPTIONBAR_
230 /** \class wxCaptionBar
231 This class is a graphical caption component that consists of a caption and a clickable arrow.
233 The wxCaptionBar fires an event EVT_CAPTIONBAR which is a wxCaptionBarEvent. This event can be caught
234 and the parent window can act upon the collapsed or expanded state of the bar (which is actually just
235 the icon which changed). The parent panel can reduce size or expand again.
238 #include <wx/imaglist.h>
240 /** Defines an empty captionbar style */
241 #define wxEmptyCaptionBarStyle wxCaptionBarStyle()
243 class wxCaptionBar
: public wxWindow
247 wxImageList
*_foldIcons
;
249 //wxFont _captionFont;
251 int _iconWidth
, _iconHeight
;
254 //wxColour _firstColour, _secondColour, _textColour;
256 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
259 wxCaptionBarStyle _style
;
261 /** Fills the background of the caption with either a gradient, or a solid color */
262 void FillCaptionBackground(wxPaintDC
&dc
);
265 void DrawHorizontalGradient(wxDC
&dc
, const wxRect
&rect
);
266 void DrawVerticalGradient(wxDC
&dc
, const wxRect
&rect
);
267 void DrawSingleColour(wxDC
&dc
, const wxRect
&rect
);
268 void DrawSingleRectangle(wxDC
&dc
, const wxRect
&rect
);
270 void RedrawIconBitmap();
272 void ApplyCaptionStyle(const wxCaptionBarStyle
&cbstyle
, bool applyDefault
);
275 /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
276 which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
277 represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
278 wxCaptionBar(wxWindow
* parent
, const wxString
&caption
, wxImageList
*images
,
279 wxWindowID id
= wxID_ANY
, const wxCaptionBarStyle
&cbstyle
= wxEmptyCaptionBarStyle
,
280 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= wxNO_BORDER
);
284 /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
285 set applyDefault to true, all other (not defined) styles will be set to default. If it is false,
286 the styles which are not set in the wxCaptionBarStyle will be ignored */
287 void SetCaptionStyle(bool applyDefault
, wxCaptionBarStyle style
= wxEmptyCaptionBarStyle
) {
288 ApplyCaptionStyle(style
, applyDefault
);
292 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
294 wxCaptionBarStyle
GetCaptionStyle() {
299 /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
300 The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
301 be used and if they all have their own bitmap resources it will eat up more memory then needed. It will
302 also ease the use of shared icon change, when there is any need to.
304 If no wxImageList is assigned, there will be no fold icons and only the doubleclick on the panel
305 will work to collapse / expand.
307 The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
308 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
311 The bitmaps must be the second thing to be done before using it (SetRightIndent should be the first thing),
312 make sure if the icons are larger than the font, that the parent of this window gets a Fit call to resize
313 all the windows accordingly */
315 void SetFoldIcons(wxImageList
*images
) {
317 _iconWidth
= _iconHeight
= 0;
319 _foldIcons
->GetSize(0, _iconWidth
, _iconHeight
);
326 /** Returns wether the status of the bar is expanded or collapsed */
327 bool IsCollapsed() const {
331 /** Sets the amount of pixels on the right from which the bitmap is trailing. If this is 0, it will be
332 drawn all the way to the right, default is equal to wxFPB_BMP_RIGHTSPACE. Assign this before
333 assigning an image list to prevent a redraw */
335 void SetRightIndent(int pixels
) {
336 wxCHECK2(pixels
>= 0, return);
337 _rightIndent
= pixels
;
338 // issue a refresh (if we have a bmp)
344 /** Return the best size for this panel, based upon the font assigned to this window, and the
346 wxSize
DoGetBestSize() const;
348 /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
349 to be sent to the parent */
355 /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
356 to be sent to the parent */
363 GetFont().SetWeight(wxBOLD
);
366 void SetNormalFont() {
367 GetFont().SetWeight(wxNORMAL
);
372 /** The paint event for flat or gradient fill */
373 void OnPaint(wxPaintEvent
& event
);
375 /** For clicking the icon, the mouse event must be intercepted */
376 void OnMouseEvent(wxMouseEvent
& event
);
378 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
379 void OnChar(wxKeyEvent
& event
);
381 void OnSize(wxSizeEvent
&event
);
385 DECLARE_NO_COPY_CLASS(wxCaptionBar
)
386 DECLARE_EVENT_TABLE()
389 /***********************************************************************************************************/
391 /** \class wxCaptionBarEvent
392 This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
393 that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
394 windows accordingly */
396 class WXDLLEXPORT wxCaptionBarEvent
: public wxCommandEvent
405 wxCaptionBarEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
406 : wxCommandEvent(commandType
, id
)
412 /** Constructor for clone copy */
413 wxCaptionBarEvent(const wxCaptionBarEvent
&event
);
415 /** Clone function */
416 virtual wxEvent
*Clone() const {
417 return new wxCaptionBarEvent(*this);
420 /** Returns wether the bar is expanded or collapsed. True means expanded */
421 bool GetFoldStatus() const {
422 wxCHECK(_bar
, false);
423 return !_bar
->IsCollapsed();
426 /** Returns the bar associated with this event */
427 wxCaptionBar
*GetBar() const {
431 void SetTag(void *tag
) {
435 void *GetTag() const {
439 /** Sets the bar associated with this event, should not used
440 by any other then the originator of the event */
441 void SetBar(wxCaptionBar
*bar
) {
445 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent
)
449 BEGIN_DECLARE_EVENT_TYPES()
450 DECLARE_EVENT_TYPE(wxEVT_CAPTIONBAR
, 7777)
451 END_DECLARE_EVENT_TYPES()
453 typedef void (wxEvtHandler::*wxCaptionBarEventFunction
)(wxCaptionBarEvent
&);
455 #define EVT_CAPTIONBAR(id, fn) \
456 DECLARE_EVENT_TABLE_ENTRY( \
457 wxEVT_CAPTIONBAR, id, wxID_ANY, \
458 (wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \
463 #endif // _NO_CAPTIONBAR_