]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: captionbar.h | |
3 | // Purpose: wxFoldPanel | |
4 | // Author: Jorgen Bodde | |
5 | // Modified by: | |
6 | // Created: 22/06/2004 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Jorgen Bodde | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __FOLDPANELBAR_H__ | |
13 | #define __FOLDPANELBAR_H__ | |
14 | ||
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 | |
18 | ||
19 | enum | |
20 | { | |
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 */ | |
28 | wxCAPTIONBAR_SINGLE, | |
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 | |
34 | }; | |
35 | ||
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 | |
39 | be changed. | |
40 | ||
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. | |
44 | */ | |
45 | class wxCaptionBarStyle | |
46 | { | |
47 | private: | |
48 | // boolean flags for default transparency on styles | |
49 | bool _firstColourUsed, | |
50 | _secondColourUsed, | |
51 | _textColourUsed, | |
52 | _captionFontUsed, | |
53 | _captionStyleUsed; | |
54 | ||
55 | wxFont _captionFont; | |
56 | wxColour _firstColour, _secondColour, _textColour; | |
57 | ||
58 | int _captionStyle; | |
59 | ||
60 | public: | |
61 | /** Default constructor for this class */ | |
62 | wxCaptionBarStyle() { | |
63 | ResetDefaults(); | |
64 | }; | |
65 | ||
66 | ~wxCaptionBarStyle() { | |
67 | ||
68 | }; | |
69 | ||
70 | void ResetDefaults() { | |
71 | _firstColourUsed = false; | |
72 | _secondColourUsed = false; | |
73 | _textColourUsed = false; | |
74 | _captionFontUsed = false; | |
75 | _captionStyleUsed = false; | |
76 | _captionStyle = wxCAPTIONBAR_GRADIENT_V; | |
77 | }; | |
78 | ||
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) | |
83 | { | |
84 | _captionStyleUsed = true; | |
85 | _captionStyle = s._captionStyle; | |
86 | } | |
87 | if(s._captionFontUsed) | |
88 | { | |
89 | _captionFontUsed = true; | |
90 | _captionFont = s._captionFont; | |
91 | } | |
92 | if(s._firstColourUsed) | |
93 | { | |
94 | _firstColourUsed = true; | |
95 | _firstColour = s._firstColour; | |
96 | } | |
97 | if(s._secondColourUsed) | |
98 | { | |
99 | _secondColourUsed = true; | |
100 | _secondColour = s._secondColour; | |
101 | } | |
102 | if(s._textColourUsed) | |
103 | { | |
104 | _textColourUsed = true; | |
105 | _textColour = s._textColour; | |
106 | } | |
107 | }; | |
108 | ||
109 | // ------- CaptionBar Font ------- | |
110 | ||
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) { | |
114 | _captionFont = font; | |
115 | _captionFontUsed = true; | |
116 | }; | |
117 | ||
118 | /** Checks if the caption bar font is set */ | |
119 | bool CaptionFontUsed() const { | |
120 | return _captionFontUsed; | |
121 | }; | |
122 | ||
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); | |
128 | return _captionFont; | |
129 | }; | |
130 | ||
131 | // ------- FirstColour ------- | |
132 | ||
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 | |
135 | style is used */ | |
136 | void SetFirstColour(const wxColour &col) { | |
137 | _firstColour = col; | |
138 | _firstColourUsed = true; | |
139 | }; | |
140 | ||
141 | /** Checks if the first colour of the caption bar is set */ | |
142 | bool FirstColourUsed() const { | |
143 | return _firstColourUsed; | |
144 | }; | |
145 | ||
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); | |
151 | return _firstColour; | |
152 | }; | |
153 | ||
154 | // ------- SecondColour ------- | |
155 | ||
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) { | |
159 | _secondColour = col; | |
160 | _secondColourUsed = true; | |
161 | }; | |
162 | ||
163 | /** Checks if the second colour of the caption bar is set */ | |
164 | bool SecondColourUsed() const { | |
165 | return _secondColourUsed; | |
166 | }; | |
167 | ||
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; | |
174 | }; | |
175 | ||
176 | // ------- Caption Text Colour ------- | |
177 | ||
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) { | |
181 | _textColour = col; | |
182 | _textColourUsed = true; | |
183 | }; | |
184 | ||
185 | /** Checks if the caption colour of the caption bar is set */ | |
186 | bool CaptionColourUsed() const { | |
187 | return _textColourUsed; | |
188 | }; | |
189 | ||
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); | |
195 | return _textColour; | |
196 | }; | |
197 | ||
198 | // ------- CaptionStyle ------- | |
199 | ||
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 | |
208 | */ | |
209 | void SetCaptionStyle(int style) { | |
210 | _captionStyle = style; | |
211 | _captionStyleUsed = true; | |
212 | }; | |
213 | ||
214 | /** Checks if the caption style of the caption bar is set */ | |
215 | bool CaptionStyleUsed() const { | |
216 | return _captionStyleUsed; | |
217 | }; | |
218 | ||
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; | |
225 | }; | |
226 | }; | |
227 | ||
228 | #ifndef _NO_CAPTIONBAR_ | |
229 | ||
230 | /** \class wxCaptionBar | |
231 | This class is a graphical caption component that consists of a caption and a clickable arrow. | |
232 | ||
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. | |
236 | */ | |
237 | ||
238 | #include <wx/imaglist.h> | |
239 | ||
240 | /** Defines an empty captionbar style */ | |
241 | #define wxEmptyCaptionBarStyle wxCaptionBarStyle() | |
242 | ||
243 | class wxCaptionBar: public wxWindow | |
244 | { | |
245 | private: | |
246 | wxString _caption; | |
247 | wxImageList *_foldIcons; | |
248 | wxSize _oldSize; | |
249 | //wxFont _captionFont; | |
250 | int _rightIndent; | |
251 | int _iconWidth, _iconHeight; | |
252 | //int _captionStyle; | |
253 | ||
254 | //wxColour _firstColour, _secondColour, _textColour; | |
255 | ||
256 | /** True when the caption is in collapsed state (means at the bottom of the wxFoldPanel */ | |
257 | bool _collapsed; | |
258 | ||
259 | wxCaptionBarStyle _style; | |
260 | ||
261 | /** Fills the background of the caption with either a gradient, or a solid color */ | |
262 | void FillCaptionBackground(wxPaintDC &dc); | |
263 | ||
264 | /* Draw methods */ | |
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 ); | |
269 | ||
270 | void RedrawIconBitmap(); | |
271 | ||
272 | void ApplyCaptionStyle(const wxCaptionBarStyle &cbstyle, bool applyDefault); | |
273 | ||
274 | public: | |
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); | |
281 | ||
282 | ~wxCaptionBar(); | |
283 | ||
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); | |
289 | Refresh(); | |
290 | }; | |
291 | ||
292 | /** Returns the current style of the captionbar in a wxCaptionBarStyle class. This can be used to change and set back the | |
293 | changes. */ | |
294 | wxCaptionBarStyle GetCaptionStyle() { | |
295 | return _style; | |
296 | }; | |
297 | ||
298 | #if 0 | |
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. | |
303 | ||
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. | |
306 | ||
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 | |
309 | widht is calculated. | |
310 | ||
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 */ | |
314 | ||
315 | void SetFoldIcons(wxImageList *images) { | |
316 | _foldIcons = images; | |
317 | _iconWidth = _iconHeight = 0; | |
318 | if(_foldIcons) | |
319 | _foldIcons->GetSize(0, _iconWidth, _iconHeight); | |
320 | ||
321 | Refresh(); | |
322 | }; | |
323 | ||
324 | #endif | |
325 | ||
326 | /** Returns wether the status of the bar is expanded or collapsed */ | |
327 | bool IsCollapsed() const { | |
328 | return _collapsed; | |
329 | }; | |
330 | ||
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 */ | |
334 | ||
335 | void SetRightIndent(int pixels) { | |
336 | wxCHECK2(pixels >= 0, return); | |
337 | _rightIndent = pixels; | |
338 | // issue a refresh (if we have a bmp) | |
339 | if(_foldIcons) | |
340 | Refresh(); | |
341 | }; | |
342 | ||
343 | ||
344 | /** Return the best size for this panel, based upon the font assigned to this window, and the | |
345 | caption string */ | |
346 | wxSize DoGetBestSize() const; | |
347 | ||
348 | /** This sets the internal state / representation to collapsed. This does not trigger a wxCaptionBarEvent | |
349 | to be sent to the parent */ | |
350 | void Collapse() { | |
351 | _collapsed = true; | |
352 | RedrawIconBitmap(); | |
353 | }; | |
354 | ||
355 | /** This sets the internal state / representation to expanded. This does not trigger a wxCaptionBarEvent | |
356 | to be sent to the parent */ | |
357 | void Expand() { | |
358 | _collapsed = false; | |
359 | RedrawIconBitmap(); | |
360 | }; | |
361 | ||
362 | void SetBoldFont() { | |
363 | GetFont().SetWeight(wxBOLD); | |
364 | }; | |
365 | ||
366 | void SetNormalFont() { | |
367 | GetFont().SetWeight(wxNORMAL); | |
368 | }; | |
369 | ||
370 | ||
371 | private: | |
372 | /** The paint event for flat or gradient fill */ | |
373 | void OnPaint(wxPaintEvent& event); | |
374 | ||
375 | /** For clicking the icon, the mouse event must be intercepted */ | |
376 | void OnMouseEvent(wxMouseEvent& event); | |
377 | ||
378 | /** Maybe when focus (don't know how yet) a cursor left or backspace will collapse or expand */ | |
379 | void OnChar(wxKeyEvent& event); | |
380 | ||
381 | void OnSize(wxSizeEvent &event); | |
382 | ||
383 | ||
384 | protected: | |
385 | DECLARE_NO_COPY_CLASS(wxCaptionBar) | |
386 | DECLARE_EVENT_TABLE() | |
387 | }; | |
388 | ||
389 | /***********************************************************************************************************/ | |
390 | ||
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 */ | |
395 | ||
396 | class WXDLLEXPORT wxCaptionBarEvent : public wxCommandEvent | |
397 | { | |
398 | ||
399 | private: | |
400 | bool _collapsed; | |
401 | wxCaptionBar *_bar; | |
402 | void *_tag; | |
403 | ||
404 | public: | |
405 | wxCaptionBarEvent(wxEventType commandType = wxEVT_NULL, int id = 0) | |
406 | : wxCommandEvent(commandType, id) | |
407 | , _collapsed(false) | |
408 | , _bar(0) | |
409 | , _tag(0) | |
410 | { } | |
411 | ||
412 | /** Constructor for clone copy */ | |
413 | wxCaptionBarEvent(const wxCaptionBarEvent &event); | |
414 | ||
415 | /** Clone function */ | |
416 | virtual wxEvent *Clone() const { | |
417 | return new wxCaptionBarEvent(*this); | |
418 | }; | |
419 | ||
420 | /** Returns wether the bar is expanded or collapsed. True means expanded */ | |
421 | bool GetFoldStatus() const { | |
422 | wxCHECK(_bar, false); | |
423 | return !_bar->IsCollapsed(); | |
424 | }; | |
425 | ||
426 | /** Returns the bar associated with this event */ | |
427 | wxCaptionBar *GetBar() const { | |
428 | return _bar; | |
429 | }; | |
430 | ||
431 | void SetTag(void *tag) { | |
432 | _tag = tag; | |
433 | }; | |
434 | ||
435 | void *GetTag() const { | |
436 | return _tag; | |
437 | }; | |
438 | ||
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) { | |
442 | _bar = bar; | |
443 | }; | |
444 | ||
445 | DECLARE_DYNAMIC_CLASS(wxCaptionBarEvent) | |
446 | ||
447 | }; | |
448 | ||
449 | BEGIN_DECLARE_EVENT_TYPES() | |
450 | DECLARE_EVENT_TYPE(wxEVT_CAPTIONBAR, 7777) | |
451 | END_DECLARE_EVENT_TYPES() | |
452 | ||
453 | typedef void (wxEvtHandler::*wxCaptionBarEventFunction)(wxCaptionBarEvent&); | |
454 | ||
455 | #define EVT_CAPTIONBAR(id, fn) \ | |
456 | DECLARE_EVENT_TABLE_ENTRY( \ | |
457 | wxEVT_CAPTIONBAR, id, wxID_ANY, \ | |
458 | (wxObjectEventFunction)(wxEventFunction)(wxCaptionBarEventFunction) \ | |
459 | & fn, \ | |
460 | (wxObject *) NULL \ | |
461 | ), | |
462 | ||
463 | #endif // _NO_CAPTIONBAR_ | |
464 | ||
465 | #endif |