]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/include/wx/foldbar/captionbar.h
mark slider as being transparent, otherwise it has ugly solid grey background when...
[wxWidgets.git] / contrib / include / wx / foldbar / captionbar.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: captionbar.h
3// Purpose: wxFoldPanel
4// Author: Jorgen Bodde
5// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6// : wxWidgets coding standards
7// Created: 22/06/2004
8// RCS-ID: $Id$
9// Copyright: (c) Jorgen Bodde
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef __FOLDPANELBAR_H__
14#define __FOLDPANELBAR_H__
15
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
25#define wxFPB_EXTRA_X 10
26#define wxFPB_EXTRA_Y 4
27#define wxFPB_BMP_RIGHTSPACE 2 // pixels of the bmp to be alligned from the right filled with space
28
29enum
30{
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 */
38 wxCAPTIONBAR_SINGLE,
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
44};
45
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
49 be changed.
50
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.
54*/
55class wxCaptionBarStyle
56{
57private:
58 // boolean flags for default transparency on styles
59 bool m_firstColourUsed,
60 m_secondColourUsed,
61 m_textColourUsed,
62 m_captionFontUsed,
63 m_captionStyleUsed;
64
65 wxFont m_captionFont;
66 wxColour m_firstColour, m_secondColour, m_textColour;
67
68 int m_captionStyle;
69
70public:
71 /** Default constructor for this class */
72 wxCaptionBarStyle() {
73 ResetDefaults();
74 };
75
76 ~wxCaptionBarStyle() {
77
78 };
79
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;
87 };
88
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)
93 {
94 m_captionStyleUsed = true;
95 m_captionStyle = s.m_captionStyle;
96 }
97 if(s.m_captionFontUsed)
98 {
99 m_captionFontUsed = true;
100 m_captionFont = s.m_captionFont;
101 }
102 if(s.m_firstColourUsed)
103 {
104 m_firstColourUsed = true;
105 m_firstColour = s.m_firstColour;
106 }
107 if(s.m_secondColourUsed)
108 {
109 m_secondColourUsed = true;
110 m_secondColour = s.m_secondColour;
111 }
112 if(s.m_textColourUsed)
113 {
114 m_textColourUsed = true;
115 m_textColour = s.m_textColour;
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) {
124 m_captionFont = font;
125 m_captionFontUsed = true;
126 };
127
128 /** Checks if the caption bar font is set */
129 bool CaptionFontUsed() const {
130 return m_captionFontUsed;
131 };
132
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;
139 };
140
141 // ------- FirstColour -------
142
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
145 style is used */
146 void SetFirstColour(const wxColour &col) {
147 m_firstColour = col;
148 m_firstColourUsed = true;
149 };
150
151 /** Checks if the first colour of the caption bar is set */
152 bool FirstColourUsed() const {
153 return m_firstColourUsed;
154 };
155
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;
162 };
163
164 // ------- SecondColour -------
165
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;
171 };
172
173 /** Checks if the second colour of the caption bar is set */
174 bool SecondColourUsed() const {
175 return m_secondColourUsed;
176 };
177
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;
184 };
185
186 // ------- Caption Text Colour -------
187
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) {
191 m_textColour = col;
192 m_textColourUsed = true;
193 };
194
195 /** Checks if the caption colour of the caption bar is set */
196 bool CaptionColourUsed() const {
197 return m_textColourUsed;
198 };
199
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);
205 return m_textColour;
206 };
207
208 // ------- CaptionStyle -------
209
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
218 */
219 void SetCaptionStyle(int style) {
220 m_captionStyle = style;
221 m_captionStyleUsed = true;
222 };
223
224 /** Checks if the caption style of the caption bar is set */
225 bool CaptionStyleUsed() const {
226 return m_captionStyleUsed;
227 };
228
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;
235 };
236};
237
238#ifndef _NO_CAPTIONBAR_
239
240/** \class wxCaptionBar
241 This class is a graphical caption component that consists of a caption and a clickable arrow.
242
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.
246*/
247
248#include <wx/imaglist.h>
249
250/** Defines an empty captionbar style */
251#define wxEmptyCaptionBarStyle wxCaptionBarStyle()
252
253class WXDLLIMPEXP_FOLDBAR wxCaptionBar: public wxWindow
254{
255private:
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;
263
264 //wxColour m_firstColour, m_secondColour, m_textColour;
265
266 /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */
267 bool m_collapsed;
268
269 wxCaptionBarStyle m_captionStyle;
270
271 /** Fills the background of the caption with either a gradient, or a solid color */
272 void FillCaptionBackground(wxPaintDC &dc);
273
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 );
279
280 void RedrawIconBitmap();
281
282 void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault);
283
284public:
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);
291
292 ~wxCaptionBar();
293
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);
299 Refresh();
300 };
301
302 /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the
303 changes. */
304 wxCaptionBarStyle GetCaptionStyle() {
305 return m_captionStyle;
306 };
307
308 bool IsVertical() const;
309
310#if 0
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.
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
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) {
328 m_foldIcons = images;
329 m_iconWidth = m_iconHeight = 0;
330 if(m_foldIcons)
331 m_foldIcons->GetSize(0, m_iconWidth, m_iconHeight);
332
333 Refresh();
334 };
335
336#endif
337
338 /** Returns wether the status of the bar is expanded or collapsed */
339 bool IsCollapsed() const {
340 return m_collapsed;
341 };
342
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 */
346
347 void SetRightIndent(int pixels) {
348 wxCHECK2(pixels >= 0, return);
349 m_rightIndent = pixels;
350 // issue a refresh (if we have a bmp)
351 if(m_foldIcons)
352 Refresh();
353 };
354
355
356 /** Return the best size for this panel, based upon the font assigned to this window, and the
357 caption string */
358 wxSize DoGetBestSize() const;
359
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() {
363 m_collapsed = true;
364 RedrawIconBitmap();
365 };
366
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() {
370 m_collapsed = false;
371 RedrawIconBitmap();
372 };
373
374 void SetBoldFont() {
375 GetFont().SetWeight(wxBOLD);
376 };
377
378 void SetNormalFont() {
379 GetFont().SetWeight(wxNORMAL);
380 };
381
382
383private:
384 /** The paint event for flat or gradient fill */
385 void OnPaint(wxPaintEvent& event);
386
387 /** For clicking the icon, the mouse event must be intercepted */
388 void OnMouseEvent(wxMouseEvent& event);
389
390 /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */
391 void OnChar(wxKeyEvent& event);
392
393 void OnSize(wxSizeEvent &event);
394
395
396protected:
397 DECLARE_NO_COPY_CLASS(wxCaptionBar)
398 DECLARE_EVENT_TABLE()
399};
400
401/***********************************************************************************************************/
402
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 */
407
408class WXDLLIMPEXP_FOLDBAR wxCaptionBarEvent : public wxCommandEvent
409{
410
411private:
412 bool m_collapsed;
413 wxCaptionBar *m_captionBar;
414 void *m_tag;
415
416public:
417 wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
418 : wxCommandEvent(commandType, id)
419 , m_collapsed(false)
420 , m_captionBar(NULL)
421 , m_tag(0)
422 { }
423
424 /** Constructor for clone copy */
425 wxCaptionBarEvent(const wxCaptionBarEvent &event);
426
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 */
433 bool GetFoldStatus() const {
434 wxCHECK(m_captionBar, false);
435 return !m_captionBar->IsCollapsed();
436 };
437
438 /** Returns the bar associated with this event */
439 wxCaptionBar *GetCaptionBar() const {
440 return m_captionBar;
441 };
442
443 void SetTag(void *tag) {
444 m_tag = tag;
445 };
446
447 void *GetTag() const {
448 return m_tag;
449 };
450
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) {
454 m_captionBar = bar;
455 };
456
457 DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent)
458
459};
460
461BEGIN_DECLARE_EVENT_TYPES()
462 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_FOLDBAR, wxEVT_CAPTIONBAR, 7777)
463END_DECLARE_EVENT_TYPES()
464
465typedef void (wxEvtHandler::*wxCaptionBarEventFunction)(wxCaptionBarEvent&);
466
467#define EVT_CAPTIONBAR(id, fn) \
468 DECLARE_EVENT_TABLE_ENTRY( \
469 wxEVT_CAPTIONBAR, id, wxID_ANY, \
470 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(wxCaptionBarEventFunction, & fn), \
471 (wxObject *) NULL \
472 ),
473
474#endif // _NO_CAPTIONBAR_
475
476#endif