]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/foldbar/captionbar.h
build fix for latest C++ standard
[wxWidgets.git] / contrib / include / wx / foldbar / captionbar.h
CommitLineData
c2a41978
WS
1/////////////////////////////////////////////////////////////////////////////
2// Name: captionbar.h
3// Purpose: wxFoldPanel
4// Author: Jorgen Bodde
7a8d9418
WS
5// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6// : wxWidgets coding standards
c2a41978
WS
7// Created: 22/06/2004
8// RCS-ID: $Id$
9// Copyright: (c) Jorgen Bodde
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
957f5ab7
VZ
13#ifndef __FOLDPANELBAR_H__
14#define __FOLDPANELBAR_H__
15
6c6a558a
WS
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
22#endif
23
24
957f5ab7
VZ
25#define wxFPB_EXTRA_X 10
26#define wxFPB_EXTRA_Y 4
3103e8a9 27#define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be aligned from the right filled with space
957f5ab7
VZ
28
29enum
30{
7a8d9418 31 /** Specifies the bars as gradient vertical filled caption bars going from top to bottom. The gradient
c2a41978
WS
32 starts with first colour, and ends with second colour */
33 wxCAPTIONBAR_GRADIENT_V = 1,
7a8d9418 34 /** Specifies the gradient going from left to right. The gradient starts with first colour, and
c2a41978
WS
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 */
38 wxCAPTIONBAR_SINGLE,
39 /** Draws a rectangle only using the second colour. The first colour is not used*/
40 wxCAPTIONBAR_RECTANGLE,
7a8d9418 41 /** Fills the captionbar with a single colour (first colour) and draws a rectangle around it
c2a41978
WS
42 using the second colour. */
43 wxCAPTIONBAR_FILLED_RECTANGLE
957f5ab7
VZ
44};
45
46/** \class wxCaptionBarStyle
7a8d9418
WS
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
49 be changed.
50
51 At construction time, all styles are set to their default transparency. This means none of the styles will be
c2a41978 52 applied to the wxCaptionBar in question, meaning it will be created using the default internals. When setting i.e
7a8d9418 53 the color, font or panel style, these styles become active to be used.
957f5ab7 54*/
e9333003 55class WXDLLIMPEXP_FOLDBAR wxCaptionBarStyle
957f5ab7
VZ
56{
57private:
c2a41978 58 // boolean flags for default transparency on styles
7a8d9418
WS
59 bool m_firstColourUsed,
60 m_secondColourUsed,
61 m_textColourUsed,
62 m_captionFontUsed,
63 m_captionStyleUsed;
957f5ab7 64
7a8d9418
WS
65 wxFont m_captionFont;
66 wxColour m_firstColour, m_secondColour, m_textColour;
957f5ab7 67
7a8d9418 68 int m_captionStyle;
957f5ab7
VZ
69
70public:
c2a41978
WS
71 /** Default constructor for this class */
72 wxCaptionBarStyle() {
73 ResetDefaults();
74 };
75
76 ~wxCaptionBarStyle() {
77
78 };
79
80 void ResetDefaults() {
7a8d9418
WS
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;
87 };
88
89 /** Copy operator. Only the styles in use in the source object are being copied to the destination object. All other
c2a41978
WS
90 styles are not copied */
91 void operator=(const wxCaptionBarStyle &s) {
7a8d9418 92 if(s.m_captionStyleUsed)
c2a41978 93 {
7a8d9418
WS
94 m_captionStyleUsed = true;
95 m_captionStyle = s.m_captionStyle;
c2a41978 96 }
7a8d9418 97 if(s.m_captionFontUsed)
c2a41978 98 {
7a8d9418
WS
99 m_captionFontUsed = true;
100 m_captionFont = s.m_captionFont;
c2a41978 101 }
7a8d9418 102 if(s.m_firstColourUsed)
c2a41978 103 {
7a8d9418
WS
104 m_firstColourUsed = true;
105 m_firstColour = s.m_firstColour;
c2a41978 106 }
7a8d9418 107 if(s.m_secondColourUsed)
c2a41978 108 {
7a8d9418
WS
109 m_secondColourUsed = true;
110 m_secondColour = s.m_secondColour;
c2a41978 111 }
7a8d9418 112 if(s.m_textColourUsed)
c2a41978 113 {
7a8d9418
WS
114 m_textColourUsed = true;
115 m_textColour = s.m_textColour;
c2a41978
WS
116 }
117 };
118
119 // ------- CaptionBar Font -------
120
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) {
7a8d9418
WS
124 m_captionFont = font;
125 m_captionFontUsed = true;
c2a41978
WS
126 };
127
128 /** Checks if the caption bar font is set */
129 bool CaptionFontUsed() const {
7a8d9418 130 return m_captionFontUsed;
c2a41978
WS
131 };
132
133 /** Returns the font for the caption bar. Please be warned this will result in an assertion failure when
7a8d9418 134 this property is not previously set
c2a41978
WS
135 \sa SetCaptionFont(), CaptionFontUsed() */
136 wxFont GetCaptionFont() const {
7a8d9418
WS
137 wxASSERT(m_captionFontUsed);
138 return m_captionFont;
c2a41978
WS
139 };
140
141 // ------- FirstColour -------
142
7a8d9418
WS
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
c2a41978
WS
145 style is used */
146 void SetFirstColour(const wxColour &col) {
7a8d9418
WS
147 m_firstColour = col;
148 m_firstColourUsed = true;
c2a41978
WS
149 };
150
151 /** Checks if the first colour of the caption bar is set */
152 bool FirstColourUsed() const {
7a8d9418 153 return m_firstColourUsed;
c2a41978
WS
154 };
155
7a8d9418 156 /** Returns the first colour for the caption bar. Please be warned this will
c2a41978
WS
157 result in an assertion failure when this property is not previously set.
158 \sa SetCaptionFirstColour(), CaptionFirstColourUsed() */
159 wxColour GetFirstColour() const {
7a8d9418
WS
160 wxASSERT(m_firstColourUsed);
161 return m_firstColour;
c2a41978
WS
162 };
163
164 // ------- SecondColour -------
165
7a8d9418 166 /** Set second colour for the caption bar. If this is not set, the colour property is undefined and
c2a41978
WS
167 will not be used. Use SecondColourUsed() to check if this style is used */
168 void SetSecondColour(const wxColour &col) {
7a8d9418
WS
169 m_secondColour = col;
170 m_secondColourUsed = true;
c2a41978
WS
171 };
172
173 /** Checks if the second colour of the caption bar is set */
174 bool SecondColourUsed() const {
7a8d9418 175 return m_secondColourUsed;
c2a41978
WS
176 };
177
7a8d9418 178 /** Returns the second colour for the caption bar. Please be warned this will result in
c2a41978
WS
179 an assertion failure when this property is not previously set.
180 \sa SetSecondColour(), SecondColourUsed() */
181 wxColour GetSecondColour() const {
7a8d9418
WS
182 wxASSERT(m_secondColourUsed);
183 return m_secondColour;
c2a41978
WS
184 };
185
186 // ------- Caption Text Colour -------
187
7a8d9418 188 /** Set caption colour for the caption bar. If this is not set, the colour property is
c2a41978
WS
189 undefined and will not be used. Use CaptionColourUsed() to check if this style is used */
190 void SetCaptionColour(const wxColour &col) {
7a8d9418
WS
191 m_textColour = col;
192 m_textColourUsed = true;
c2a41978
WS
193 };
194
195 /** Checks if the caption colour of the caption bar is set */
196 bool CaptionColourUsed() const {
7a8d9418 197 return m_textColourUsed;
c2a41978
WS
198 };
199
7a8d9418 200 /** Returns the caption colour for the caption bar. Please be warned this will
c2a41978
WS
201 result in an assertion failure when this property is not previously set.
202 \sa SetCaptionColour(), CaptionColourUsed() */
203 wxColour GetCaptionColour() const {
7a8d9418
WS
204 wxASSERT(m_textColourUsed);
205 return m_textColour;
c2a41978
WS
206 };
207
208 // ------- CaptionStyle -------
209
7a8d9418
WS
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.
c2a41978
WS
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
218 */
219 void SetCaptionStyle(int style) {
7a8d9418
WS
220 m_captionStyle = style;
221 m_captionStyleUsed = true;
c2a41978
WS
222 };
223
224 /** Checks if the caption style of the caption bar is set */
225 bool CaptionStyleUsed() const {
7a8d9418 226 return m_captionStyleUsed;
c2a41978
WS
227 };
228
7a8d9418 229 /** Returns the caption style for the caption bar. Please be warned this will
c2a41978
WS
230 result in an assertion failure when this property is not previously set.
231 \sa SetCaptionStyle(), CaptionStyleUsed() */
232 int GetCaptionStyle() const {
7a8d9418
WS
233 wxASSERT(m_captionStyleUsed);
234 return m_captionStyle;
c2a41978 235 };
957f5ab7
VZ
236};
237
238#ifndef _NO_CAPTIONBAR_
239
240/** \class wxCaptionBar
c2a41978 241 This class is a graphical caption component that consists of a caption and a clickable arrow.
7a8d9418 242
c2a41978
WS
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.
957f5ab7
VZ
246*/
247
248#include <wx/imaglist.h>
249
250/** Defines an empty captionbar style */
251#define wxEmptyCaptionBarStyle wxCaptionBarStyle()
252
cc863835 253class WXDLLIMPEXP_FOLDBAR wxCaptionBar: public wxWindow
957f5ab7
VZ
254{
255private:
7a8d9418
WS
256 wxString m_caption;
257 wxImageList *m_foldIcons;
258 wxSize m_oldSize;
259 //wxFont m_captionFont;
260 int m_rightIndent;
261 int m_iconWidth, m_iconHeight;
262 //int m_captionStyle;
957f5ab7 263
7a8d9418 264 //wxColour m_firstColour, m_secondColour, m_textColour;
957f5ab7 265
c2a41978 266 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
7a8d9418 267 bool m_collapsed;
957f5ab7 268
7a8d9418 269 wxCaptionBarStyle m_captionStyle;
957f5ab7 270
c2a41978
WS
271 /** Fills the background of the caption with either a gradient, or a solid color */
272 void FillCaptionBackground(wxPaintDC &dc);
957f5ab7 273
c2a41978
WS
274 /* Draw methods */
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 );
957f5ab7 279
c2a41978 280 void RedrawIconBitmap();
957f5ab7 281
c2a41978 282 void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault);
957f5ab7
VZ
283
284public:
285 /** Constructor of wxCaptionBar. To create a wxCaptionBar with the arrow images, simply pass an image list
7a8d9418 286 which contains at least two bitmaps. The bitmaps contain the expanded and collapsed icons needed to
c2a41978 287 represent it's state. If you don't want images, simply pass a null pointer and the bitmap is disabled. */
7a8d9418 288 wxCaptionBar(wxWindow* parent, const wxString &caption, wxImageList *images,
c2a41978
WS
289 wxWindowID id = wxID_ANY, const wxCaptionBarStyle &cbstyle = wxEmptyCaptionBarStyle,
290 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxNO_BORDER);
291
292 ~wxCaptionBar();
293
7a8d9418 294 /** Set wxCaptionBar styles with wxCapionBarSyle class. All styles that are actually set, are applied. If you
c2a41978
WS
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);
299 Refresh();
300 };
7a8d9418
WS
301
302 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
c2a41978
WS
303 changes. */
304 wxCaptionBarStyle GetCaptionStyle() {
7a8d9418 305 return m_captionStyle;
c2a41978 306 };
957f5ab7 307
7a8d9418
WS
308 bool IsVertical() const;
309
957f5ab7 310#if 0
c2a41978 311 /** Sets a pointer to an image list resource (a non owned pointer) to the collapsed and expand icon bitmap.
7a8d9418 312 The reason why it will be assigned a pointer is that it is very likely that multiple caption bars will
c2a41978
WS
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.
7a8d9418
WS
315
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.
318
319 The image list must contain 2 bitmaps. Index 0 will be the expanded state, and index 1 will be the
c2a41978
WS
320 collapsed state of the bitmap. The size of the bitmap is taken in account when the minimal height and
321 widht is calculated.
322
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 */
326
327 void SetFoldIcons(wxImageList *images) {
7a8d9418
WS
328 m_foldIcons = images;
329 m_iconWidth = m_iconHeight = 0;
330 if(m_foldIcons)
331 m_foldIcons->GetSize(0, m_iconWidth, m_iconHeight);
c2a41978
WS
332
333 Refresh();
334 };
957f5ab7
VZ
335
336#endif
337
c2a41978
WS
338 /** Returns wether the status of the bar is expanded or collapsed */
339 bool IsCollapsed() const {
7a8d9418 340 return m_collapsed;
c2a41978 341 };
957f5ab7 342
7a8d9418
WS
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
c2a41978 345 assigning an image list to prevent a redraw */
957f5ab7 346
c2a41978
WS
347 void SetRightIndent(int pixels) {
348 wxCHECK2(pixels >= 0, return);
7a8d9418 349 m_rightIndent = pixels;
c2a41978 350 // issue a refresh (if we have a bmp)
7a8d9418 351 if(m_foldIcons)
c2a41978
WS
352 Refresh();
353 };
957f5ab7
VZ
354
355
7a8d9418 356 /** Return the best size for this panel, based upon the font assigned to this window, and the
c2a41978
WS
357 caption string */
358 wxSize DoGetBestSize() const;
957f5ab7 359
c2a41978
WS
360 /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent
361 to be sent to the parent */
362 void Collapse() {
7a8d9418 363 m_collapsed = true;
c2a41978
WS
364 RedrawIconBitmap();
365 };
957f5ab7 366
c2a41978
WS
367 /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent
368 to be sent to the parent */
369 void Expand() {
7a8d9418 370 m_collapsed = false;
c2a41978
WS
371 RedrawIconBitmap();
372 };
957f5ab7 373
c2a41978
WS
374 void SetBoldFont() {
375 GetFont().SetWeight(wxBOLD);
376 };
957f5ab7 377
c2a41978
WS
378 void SetNormalFont() {
379 GetFont().SetWeight(wxNORMAL);
380 };
957f5ab7
VZ
381
382
383private:
384 /** The paint event for flat or gradient fill */
c2a41978 385 void OnPaint(wxPaintEvent& event);
7a8d9418 386
957f5ab7
VZ
387 /** For clicking the icon, the mouse event must be intercepted */
388 void OnMouseEvent(wxMouseEvent& event);
7a8d9418 389
957f5ab7
VZ
390 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
391 void OnChar(wxKeyEvent& event);
392
c2a41978 393 void OnSize(wxSizeEvent &event);
957f5ab7
VZ
394
395
396protected:
397 DECLARE_NO_COPY_CLASS(wxCaptionBar)
398 DECLARE_EVENT_TABLE()
399};
400
401/***********************************************************************************************************/
402
403/** \class wxCaptionBarEvent
7a8d9418 404 This event will be sent when a EVT_CAPTIONBAR is mapped in the parent. It is to notify the parent
c2a41978
WS
405 that the bar is now in collapsed or expanded state. The parent should re-arrange the associated
406 windows accordingly */
957f5ab7 407
6c6a558a 408class WXDLLIMPEXP_FOLDBAR wxCaptionBarEvent : public wxCommandEvent
957f5ab7
VZ
409{
410
411private:
7a8d9418
WS
412 bool m_collapsed;
413 wxCaptionBar *m_captionBar;
414 void *m_tag;
957f5ab7
VZ
415
416public:
417 wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
418 : wxCommandEvent(commandType, id)
7a8d9418
WS
419 , m_collapsed(false)
420 , m_captionBar(NULL)
421 , m_tag(0)
c2a41978 422 { }
7a8d9418 423
c2a41978
WS
424 /** Constructor for clone copy */
425 wxCaptionBarEvent(const wxCaptionBarEvent &event);
7a8d9418 426
c2a41978
WS
427 /** Clone function */
428 virtual wxEvent *Clone() const {
429 return new wxCaptionBarEvent(*this);
430 };
431
432 /** Returns wether the bar is expanded or collapsed. True means expanded */
7a8d9418
WS
433 bool GetFoldStatus() const {
434 wxCHECK(m_captionBar, false);
435 return !m_captionBar->IsCollapsed();
c2a41978
WS
436 };
437
438 /** Returns the bar associated with this event */
7a8d9418
WS
439 wxCaptionBar *GetCaptionBar() const {
440 return m_captionBar;
c2a41978
WS
441 };
442
443 void SetTag(void *tag) {
7a8d9418 444 m_tag = tag;
c2a41978
WS
445 };
446
447 void *GetTag() const {
7a8d9418 448 return m_tag;
c2a41978
WS
449 };
450
451 /** Sets the bar associated with this event, should not used
452 by any other then the originator of the event */
7a8d9418
WS
453 void SetCaptionBar(wxCaptionBar *bar) {
454 m_captionBar = bar;
c2a41978
WS
455 };
456
457 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent)
957f5ab7
VZ
458
459};
460
461BEGIN_DECLARE_EVENT_TYPES()
6c6a558a 462 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_FOLDBAR, wxEVT_CAPTIONBAR, 7777)
957f5ab7
VZ
463END_DECLARE_EVENT_TYPES()
464
465typedef void (wxEvtHandler::*wxCaptionBarEventFunction)(wxCaptionBarEvent&);
466
467#define EVT_CAPTIONBAR(id, fn) \
468 DECLARE_EVENT_TABLE_ENTRY( \
c2a41978 469 wxEVT_CAPTIONBAR, id, wxID_ANY, \
6c6a558a 470 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(wxCaptionBarEventFunction, & fn), \
957f5ab7
VZ
471 (wxObject *) NULL \
472 ),
473
474#endif // _NO_CAPTIONBAR_
475
476#endif