No changes, just clean up duplicate colour functions in wxAUI.
[wxWidgets.git] / src / aui / dockart.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/dockart.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
5 // Modified by:
6 // Created: 2005-05-17
7 // RCS-ID: $Id$
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_AUI
27
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/settings.h"
33 #include "wx/dcclient.h"
34 #include "wx/image.h"
35 #endif
36
37 #ifdef __WXMAC__
38 #include "wx/osx/private.h"
39 #include "wx/graphics.h"
40 #include "wx/dcgraph.h"
41 #endif
42
43 #ifdef __WXGTK__
44 #include <gtk/gtk.h>
45 #include "wx/renderer.h"
46 #endif
47
48
49 // -- wxAuiDefaultDockArt class implementation --
50
51 // wxAuiDefaultDockArt is an art provider class which does all of the drawing for
52 // wxAuiManager. This allows the library caller to customize the dock art
53 // (probably by deriving from this class), or to completely replace all drawing
54 // with custom dock art (probably by writing a new stand-alone class derived
55 // from the wxAuiDockArt base class). The active dock art class can be set via
56 // wxAuiManager::SetDockArt()
57 wxColor wxAuiLightContrastColour(const wxColour& c)
58 {
59 int amount = 120;
60
61 // if the color is especially dark, then
62 // make the contrast even lighter
63 if (c.Red() < 128 && c.Green() < 128 && c.Blue() < 128)
64 amount = 160;
65
66 return c.ChangeLightness(amount);
67 }
68
69 // wxAuiBitmapFromBits() is a utility function that creates a
70 // masked bitmap from raw bits (XBM format)
71 wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
72 const wxColour& color)
73 {
74 wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
75 img.Replace(0,0,0,123,123,123);
76 img.Replace(255,255,255,color.Red(),color.Green(),color.Blue());
77 img.SetMaskColour(123,123,123);
78 return wxBitmap(img);
79 }
80
81
82 static void DrawGradientRectangle(wxDC& dc,
83 const wxRect& rect,
84 const wxColour& start_color,
85 const wxColour& end_color,
86 int direction)
87 {
88 int rd, gd, bd, high = 0;
89 rd = end_color.Red() - start_color.Red();
90 gd = end_color.Green() - start_color.Green();
91 bd = end_color.Blue() - start_color.Blue();
92
93 if (direction == wxAUI_GRADIENT_VERTICAL)
94 high = rect.GetHeight()-1;
95 else
96 high = rect.GetWidth()-1;
97
98 for (int i = 0; i <= high; ++i)
99 {
100 int r,g,b;
101
102
103 r = start_color.Red() + (high <= 0 ? 0 : (((i*rd*100)/high)/100));
104 g = start_color.Green() + (high <= 0 ? 0 : (((i*gd*100)/high)/100));
105 b = start_color.Blue() + (high <= 0 ? 0 : (((i*bd*100)/high)/100));
106
107 wxPen p(wxColor((unsigned char)r,
108 (unsigned char)g,
109 (unsigned char)b));
110 dc.SetPen(p);
111
112 if (direction == wxAUI_GRADIENT_VERTICAL)
113 dc.DrawLine(rect.x, rect.y+i, rect.x+rect.width, rect.y+i);
114 else
115 dc.DrawLine(rect.x+i, rect.y, rect.x+i, rect.y+rect.height);
116 }
117 }
118
119 wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
120 {
121 wxCoord x,y;
122
123 // first check if the text fits with no problems
124 dc.GetTextExtent(text, &x, &y);
125 if (x <= max_size)
126 return text;
127
128 size_t i, len = text.Length();
129 size_t last_good_length = 0;
130 for (i = 0; i < len; ++i)
131 {
132 wxString s = text.Left(i);
133 s += wxT("...");
134
135 dc.GetTextExtent(s, &x, &y);
136 if (x > max_size)
137 break;
138
139 last_good_length = i;
140 }
141
142 wxString ret = text.Left(last_good_length);
143 ret += wxT("...");
144 return ret;
145 }
146
147 wxAuiDefaultDockArt::wxAuiDefaultDockArt()
148 {
149 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
150 wxColor base_colour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground));
151 #else
152 wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
153 #endif
154
155 // the base_colour is too pale to use as our base colour,
156 // so darken it a bit --
157 if ((255-base_colour.Red()) +
158 (255-base_colour.Green()) +
159 (255-base_colour.Blue()) < 60)
160 {
161 base_colour = base_colour.ChangeLightness(92);
162 }
163
164 m_base_colour = base_colour;
165 wxColor darker1_colour = base_colour.ChangeLightness(85);
166 wxColor darker2_colour = base_colour.ChangeLightness(75);
167 wxColor darker3_colour = base_colour.ChangeLightness(60);
168 //wxColor darker4_colour = base_colour.ChangeLightness(50);
169 wxColor darker5_colour = base_colour.ChangeLightness(40);
170
171 m_active_caption_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
172 m_active_caption_gradient_colour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
173 m_active_caption_text_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
174 m_inactive_caption_colour = darker1_colour;
175 m_inactive_caption_gradient_colour = base_colour.ChangeLightness(97);
176 m_inactive_caption_text_colour = *wxBLACK;
177
178 m_sash_brush = wxBrush(base_colour);
179 m_background_brush = wxBrush(base_colour);
180 m_gripper_brush = wxBrush(base_colour);
181
182 m_border_pen = wxPen(darker2_colour);
183 m_gripper_pen1 = wxPen(darker5_colour);
184 m_gripper_pen2 = wxPen(darker3_colour);
185 m_gripper_pen3 = *wxWHITE_PEN;
186
187 #ifdef __WXMAC__
188 m_caption_font = *wxSMALL_FONT;
189 #else
190 m_caption_font = wxFont(8, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE);
191 #endif
192
193 // some built in bitmaps
194 #if defined( __WXMAC__ )
195 static const unsigned char close_bits[]={
196 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
197 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
198 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
199 #elif defined(__WXGTK__)
200 static const unsigned char close_bits[]={
201 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8,
202 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef,
203 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
204 #else
205 static const unsigned char close_bits[]={
206 // reduced height, symmetric
207 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xf3, 0x9f, 0xf9,
208 0x3f, 0xfc, 0x7f, 0xfe, 0x3f, 0xfc, 0x9f, 0xf9, 0xcf, 0xf3, 0xff, 0xff,
209 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
210 /*
211 // same height as maximize/restore
212 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xe7, 0xcf, 0xf3, 0x9f, 0xf9,
213 0x3f, 0xfc, 0x7f, 0xfe, 0x3f, 0xfc, 0x9f, 0xf9, 0xcf, 0xf3, 0xe7, 0xe7,
214 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
215 */
216 #endif
217
218 static const unsigned char maximize_bits[] = {
219 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xf7, 0xf7, 0x07, 0xf0,
220 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0x07, 0xf0,
221 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
222
223 static const unsigned char restore_bits[]={
224 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf0, 0x1f, 0xf0, 0xdf, 0xf7,
225 0x07, 0xf4, 0x07, 0xf4, 0xf7, 0xf5, 0xf7, 0xf1, 0xf7, 0xfd, 0xf7, 0xfd,
226 0x07, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
227
228 static const unsigned char pin_bits[]={
229 0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0xfc,0xdf,0xfc,0xdf,0xfc,
230 0xdf,0xfc,0xdf,0xfc,0xdf,0xfc,0x0f,0xf8,0x7f,0xff,0x7f,0xff,
231 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
232
233 #ifdef __WXMAC__
234 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE);
235 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE );
236 #else
237 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_inactive_caption_text_colour);
238 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_active_caption_text_colour);
239 #endif
240
241 #ifdef __WXMAC__
242 m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE);
243 m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE );
244 #else
245 m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_inactive_caption_text_colour);
246 m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_active_caption_text_colour);
247 #endif
248
249 #ifdef __WXMAC__
250 m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE);
251 m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE );
252 #else
253 m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_inactive_caption_text_colour);
254 m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_active_caption_text_colour);
255 #endif
256
257 m_inactive_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_inactive_caption_text_colour);
258 m_active_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_active_caption_text_colour);
259
260 // default metric values
261 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
262 SInt32 height;
263 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight , &height );
264 m_sash_size = height;
265 #elif defined(__WXGTK__)
266 m_sash_size = wxRendererNative::Get().GetSplitterParams(NULL).widthSash;
267 #else
268 m_sash_size = 4;
269 #endif
270 m_caption_size = 17;
271 m_border_size = 1;
272 m_button_size = 14;
273 m_gripper_size = 9;
274 m_gradient_type = wxAUI_GRADIENT_VERTICAL;
275 }
276
277 int wxAuiDefaultDockArt::GetMetric(int id)
278 {
279 switch (id)
280 {
281 case wxAUI_DOCKART_SASH_SIZE: return m_sash_size;
282 case wxAUI_DOCKART_CAPTION_SIZE: return m_caption_size;
283 case wxAUI_DOCKART_GRIPPER_SIZE: return m_gripper_size;
284 case wxAUI_DOCKART_PANE_BORDER_SIZE: return m_border_size;
285 case wxAUI_DOCKART_PANE_BUTTON_SIZE: return m_button_size;
286 case wxAUI_DOCKART_GRADIENT_TYPE: return m_gradient_type;
287 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
288 }
289
290 return 0;
291 }
292
293 void wxAuiDefaultDockArt::SetMetric(int id, int new_val)
294 {
295 switch (id)
296 {
297 case wxAUI_DOCKART_SASH_SIZE: m_sash_size = new_val; break;
298 case wxAUI_DOCKART_CAPTION_SIZE: m_caption_size = new_val; break;
299 case wxAUI_DOCKART_GRIPPER_SIZE: m_gripper_size = new_val; break;
300 case wxAUI_DOCKART_PANE_BORDER_SIZE: m_border_size = new_val; break;
301 case wxAUI_DOCKART_PANE_BUTTON_SIZE: m_button_size = new_val; break;
302 case wxAUI_DOCKART_GRADIENT_TYPE: m_gradient_type = new_val; break;
303 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
304 }
305 }
306
307 wxColour wxAuiDefaultDockArt::GetColour(int id)
308 {
309 switch (id)
310 {
311 case wxAUI_DOCKART_BACKGROUND_COLOUR: return m_background_brush.GetColour();
312 case wxAUI_DOCKART_SASH_COLOUR: return m_sash_brush.GetColour();
313 case wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR: return m_inactive_caption_colour;
314 case wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR: return m_inactive_caption_gradient_colour;
315 case wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR: return m_inactive_caption_text_colour;
316 case wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR: return m_active_caption_colour;
317 case wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR: return m_active_caption_gradient_colour;
318 case wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR: return m_active_caption_text_colour;
319 case wxAUI_DOCKART_BORDER_COLOUR: return m_border_pen.GetColour();
320 case wxAUI_DOCKART_GRIPPER_COLOUR: return m_gripper_brush.GetColour();
321 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
322 }
323
324 return wxColour();
325 }
326
327 void wxAuiDefaultDockArt::SetColour(int id, const wxColor& colour)
328 {
329 switch (id)
330 {
331 case wxAUI_DOCKART_BACKGROUND_COLOUR: m_background_brush.SetColour(colour); break;
332 case wxAUI_DOCKART_SASH_COLOUR: m_sash_brush.SetColour(colour); break;
333 case wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR: m_inactive_caption_colour = colour; break;
334 case wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR: m_inactive_caption_gradient_colour = colour; break;
335 case wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR: m_inactive_caption_text_colour = colour; break;
336 case wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR: m_active_caption_colour = colour; break;
337 case wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR: m_active_caption_gradient_colour = colour; break;
338 case wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR: m_active_caption_text_colour = colour; break;
339 case wxAUI_DOCKART_BORDER_COLOUR: m_border_pen.SetColour(colour); break;
340 case wxAUI_DOCKART_GRIPPER_COLOUR:
341 m_gripper_brush.SetColour(colour);
342 m_gripper_pen1.SetColour(colour.ChangeLightness(40));
343 m_gripper_pen2.SetColour(colour.ChangeLightness(60));
344 break;
345 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
346 }
347 }
348
349 void wxAuiDefaultDockArt::SetFont(int id, const wxFont& font)
350 {
351 if (id == wxAUI_DOCKART_CAPTION_FONT)
352 m_caption_font = font;
353 }
354
355 wxFont wxAuiDefaultDockArt::GetFont(int id)
356 {
357 if (id == wxAUI_DOCKART_CAPTION_FONT)
358 return m_caption_font;
359 return wxNullFont;
360 }
361
362 void wxAuiDefaultDockArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect)
363 {
364 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
365 wxUnusedVar(window);
366 wxUnusedVar(orientation);
367
368 HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height );
369 CGContextRef cgContext ;
370 wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
371 cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext() ;
372
373 HIThemeSplitterDrawInfo drawInfo ;
374 drawInfo.version = 0 ;
375 drawInfo.state = kThemeStateActive ;
376 drawInfo.adornment = kHIThemeSplitterAdornmentNone ;
377 HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;
378
379 #elif defined(__WXGTK__)
380 // clear out the rectangle first
381 dc.SetPen(*wxTRANSPARENT_PEN);
382 dc.SetBrush(m_sash_brush);
383 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
384
385 #if 0
386 GdkRectangle gdk_rect;
387 if (orientation == wxVERTICAL )
388 {
389 gdk_rect.x = rect.x;
390 gdk_rect.y = rect.y;
391 gdk_rect.width = m_sash_size;
392 gdk_rect.height = rect.height;
393 }
394 else
395 {
396 gdk_rect.x = rect.x;
397 gdk_rect.y = rect.y;
398 gdk_rect.width = rect.width;
399 gdk_rect.height = m_sash_size;
400 }
401 #endif
402
403 if (!window) return;
404 if (!window->m_wxwindow) return;
405 if (!GTK_WIDGET_DRAWABLE(window->m_wxwindow)) return;
406
407 gtk_paint_handle
408 (
409 window->m_wxwindow->style,
410 window->GTKGetDrawingWindow(),
411 // flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
412 GTK_STATE_NORMAL,
413 GTK_SHADOW_NONE,
414 NULL /* no clipping */,
415 window->m_wxwindow,
416 "paned",
417 rect.x,
418 rect.y,
419 rect.width,
420 rect.height,
421 (orientation == wxVERTICAL) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL
422 );
423
424 #else
425 wxUnusedVar(window);
426 wxUnusedVar(orientation);
427 dc.SetPen(*wxTRANSPARENT_PEN);
428 dc.SetBrush(m_sash_brush);
429 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
430 #endif
431 }
432
433
434 void wxAuiDefaultDockArt::DrawBackground(wxDC& dc, wxWindow *WXUNUSED(window), int, const wxRect& rect)
435 {
436 dc.SetPen(*wxTRANSPARENT_PEN);
437 #ifdef __WXMAC__
438 // we have to clear first, otherwise we are drawing a light striped pattern
439 // over an already darker striped background
440 dc.SetBrush(*wxWHITE_BRUSH) ;
441 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
442 #endif
443 dc.SetBrush(m_background_brush);
444 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
445 }
446
447 void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow *WXUNUSED(window), const wxRect& _rect,
448 wxAuiPaneInfo& pane)
449 {
450 dc.SetPen(m_border_pen);
451 dc.SetBrush(*wxTRANSPARENT_BRUSH);
452
453 wxRect rect = _rect;
454 int i, border_width = GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
455
456 if (pane.IsToolbar())
457 {
458 for (i = 0; i < border_width; ++i)
459 {
460 dc.SetPen(*wxWHITE_PEN);
461 dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
462 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height);
463 dc.SetPen(m_border_pen);
464 dc.DrawLine(rect.x, rect.y+rect.height-1,
465 rect.x+rect.width, rect.y+rect.height-1);
466 dc.DrawLine(rect.x+rect.width-1, rect.y,
467 rect.x+rect.width-1, rect.y+rect.height);
468 rect.Deflate(1);
469 }
470 }
471 else
472 {
473 for (i = 0; i < border_width; ++i)
474 {
475 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
476 rect.Deflate(1);
477 }
478 }
479 }
480
481
482 void wxAuiDefaultDockArt::DrawCaptionBackground(wxDC& dc, const wxRect& rect, bool active)
483 {
484 if (m_gradient_type == wxAUI_GRADIENT_NONE)
485 {
486 if (active)
487 dc.SetBrush(wxBrush(m_active_caption_colour));
488 else
489 dc.SetBrush(wxBrush(m_inactive_caption_colour));
490
491 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
492 }
493 else
494 {
495 if (active)
496 {
497 // on mac the gradients are expected to become darker from the top
498 #ifdef __WXMAC__
499 DrawGradientRectangle(dc, rect,
500 m_active_caption_colour,
501 m_active_caption_gradient_colour,
502 m_gradient_type);
503 #else
504 // on other platforms, active gradients become lighter at the top
505 DrawGradientRectangle(dc, rect,
506 m_active_caption_gradient_colour,
507 m_active_caption_colour,
508 m_gradient_type);
509 #endif
510 }
511 else
512 {
513 #ifdef __WXMAC__
514 // on mac the gradients are expected to become darker from the top
515 DrawGradientRectangle(dc, rect,
516 m_inactive_caption_gradient_colour,
517 m_inactive_caption_colour,
518 m_gradient_type);
519 #else
520 // on other platforms, inactive gradients become lighter at the bottom
521 DrawGradientRectangle(dc, rect,
522 m_inactive_caption_colour,
523 m_inactive_caption_gradient_colour,
524 m_gradient_type);
525 #endif
526 }
527 }
528 }
529
530
531 void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window),
532 const wxString& text,
533 const wxRect& rect,
534 wxAuiPaneInfo& pane)
535 {
536 dc.SetPen(*wxTRANSPARENT_PEN);
537 dc.SetFont(m_caption_font);
538
539 DrawCaptionBackground(dc, rect,
540 (pane.state & wxAuiPaneInfo::optionActive)?true:false);
541
542 if (pane.state & wxAuiPaneInfo::optionActive)
543 dc.SetTextForeground(m_active_caption_text_colour);
544 else
545 dc.SetTextForeground(m_inactive_caption_text_colour);
546
547
548 wxCoord w,h;
549 dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);
550
551 wxRect clip_rect = rect;
552 clip_rect.width -= 3; // text offset
553 clip_rect.width -= 2; // button padding
554 if (pane.HasCloseButton())
555 clip_rect.width -= m_button_size;
556 if (pane.HasPinButton())
557 clip_rect.width -= m_button_size;
558 if (pane.HasMaximizeButton())
559 clip_rect.width -= m_button_size;
560
561 wxString draw_text = wxAuiChopText(dc, text, clip_rect.width);
562
563 dc.SetClippingRegion(clip_rect);
564 dc.DrawText(draw_text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
565 dc.DestroyClippingRegion();
566 }
567
568 void wxAuiDefaultDockArt::DrawGripper(wxDC& dc, wxWindow *WXUNUSED(window),
569 const wxRect& rect,
570 wxAuiPaneInfo& pane)
571 {
572 dc.SetPen(*wxTRANSPARENT_PEN);
573 dc.SetBrush(m_gripper_brush);
574
575 dc.DrawRectangle(rect.x, rect.y, rect.width,rect.height);
576
577 if (!pane.HasGripperTop())
578 {
579 int y = 5;
580 while (1)
581 {
582 dc.SetPen(m_gripper_pen1);
583 dc.DrawPoint(rect.x+3, rect.y+y);
584 dc.SetPen(m_gripper_pen2);
585 dc.DrawPoint(rect.x+3, rect.y+y+1);
586 dc.DrawPoint(rect.x+4, rect.y+y);
587 dc.SetPen(m_gripper_pen3);
588 dc.DrawPoint(rect.x+5, rect.y+y+1);
589 dc.DrawPoint(rect.x+5, rect.y+y+2);
590 dc.DrawPoint(rect.x+4, rect.y+y+2);
591
592 y += 4;
593 if (y > rect.GetHeight()-5)
594 break;
595 }
596 }
597 else
598 {
599 int x = 5;
600 while (1)
601 {
602 dc.SetPen(m_gripper_pen1);
603 dc.DrawPoint(rect.x+x, rect.y+3);
604 dc.SetPen(m_gripper_pen2);
605 dc.DrawPoint(rect.x+x+1, rect.y+3);
606 dc.DrawPoint(rect.x+x, rect.y+4);
607 dc.SetPen(m_gripper_pen3);
608 dc.DrawPoint(rect.x+x+1, rect.y+5);
609 dc.DrawPoint(rect.x+x+2, rect.y+5);
610 dc.DrawPoint(rect.x+x+2, rect.y+4);
611
612 x += 4;
613 if (x > rect.GetWidth()-5)
614 break;
615 }
616 }
617 }
618
619 void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, wxWindow *WXUNUSED(window),
620 int button,
621 int button_state,
622 const wxRect& _rect,
623 wxAuiPaneInfo& pane)
624 {
625 wxBitmap bmp;
626 if (!(&pane))
627 return;
628 switch (button)
629 {
630 default:
631 case wxAUI_BUTTON_CLOSE:
632 if (pane.state & wxAuiPaneInfo::optionActive)
633 bmp = m_active_close_bitmap;
634 else
635 bmp = m_inactive_close_bitmap;
636 break;
637 case wxAUI_BUTTON_PIN:
638 if (pane.state & wxAuiPaneInfo::optionActive)
639 bmp = m_active_pin_bitmap;
640 else
641 bmp = m_inactive_pin_bitmap;
642 break;
643 case wxAUI_BUTTON_MAXIMIZE_RESTORE:
644 if (pane.IsMaximized())
645 {
646 if (pane.state & wxAuiPaneInfo::optionActive)
647 bmp = m_active_restore_bitmap;
648 else
649 bmp = m_inactive_restore_bitmap;
650 }
651 else
652 {
653 if (pane.state & wxAuiPaneInfo::optionActive)
654 bmp = m_active_maximize_bitmap;
655 else
656 bmp = m_inactive_maximize_bitmap;
657 }
658 break;
659 }
660
661
662 wxRect rect = _rect;
663
664 int old_y = rect.y;
665 rect.y = rect.y + (rect.height/2) - (bmp.GetHeight()/2);
666 rect.height = old_y + rect.height - rect.y - 1;
667
668
669 if (button_state == wxAUI_BUTTON_STATE_PRESSED)
670 {
671 rect.x++;
672 rect.y++;
673 }
674
675 if (button_state == wxAUI_BUTTON_STATE_HOVER ||
676 button_state == wxAUI_BUTTON_STATE_PRESSED)
677 {
678 if (pane.state & wxAuiPaneInfo::optionActive)
679 {
680 dc.SetBrush(wxBrush(m_active_caption_colour.ChangeLightness(120)));
681 dc.SetPen(wxPen(m_active_caption_colour.ChangeLightness(70)));
682 }
683 else
684 {
685 dc.SetBrush(wxBrush(m_inactive_caption_colour.ChangeLightness(120)));
686 dc.SetPen(wxPen(m_inactive_caption_colour.ChangeLightness(70)));
687 }
688
689 // draw the background behind the button
690 dc.DrawRectangle(rect.x, rect.y, 15, 15);
691 }
692
693
694 // draw the button itself
695 dc.DrawBitmap(bmp, rect.x, rect.y, true);
696 }
697
698
699 #endif // wxUSE_AUI