minor tab drawing improvements
[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/mac/private.h"
39 #include "wx/graphics.h"
40 #endif
41
42 #ifdef __WXGTK__
43 #include <gtk/gtk.h>
44 #include "wx/gtk/win_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
58
59 // wxAuiBlendColour is used by wxAuiStepColour
60 double wxAuiBlendColour(double fg, double bg, double alpha)
61 {
62 double result = bg + (alpha * (fg - bg));
63 if (result < 0.0)
64 result = 0.0;
65 if (result > 255)
66 result = 255;
67 return result;
68 }
69
70 // wxAuiStepColour() it a utility function that simply darkens
71 // or lightens a color, based on the specified percentage
72 // ialpha of 0 would be completely black, 100 completely white
73 // an ialpha of 100 returns the same colour
74 wxColor wxAuiStepColour(const wxColor& c, int ialpha)
75 {
76 if (ialpha == 100)
77 return c;
78
79 double r = c.Red(), g = c.Green(), b = c.Blue();
80 double bg;
81
82 // ialpha is 0..200 where 0 is completely black
83 // and 200 is completely white and 100 is the same
84 // convert that to normal alpha 0.0 - 1.0
85 ialpha = wxMin(ialpha, 200);
86 ialpha = wxMax(ialpha, 0);
87 double alpha = ((double)(ialpha - 100.0))/100.0;
88
89 if (ialpha > 100)
90 {
91 // blend with white
92 bg = 255.0;
93 alpha = 1.0 - alpha; // 0 = transparent fg; 1 = opaque fg
94 }
95 else
96 {
97 // blend with black
98 bg = 0.0;
99 alpha = 1.0 + alpha; // 0 = transparent fg; 1 = opaque fg
100 }
101
102 r = wxAuiBlendColour(r, bg, alpha);
103 g = wxAuiBlendColour(g, bg, alpha);
104 b = wxAuiBlendColour(b, bg, alpha);
105
106 return wxColour((int)r, (int)g, (int)b);
107 }
108
109
110 wxColor wxAuiLightContrastColour(const wxColour& c)
111 {
112 int amount = 120;
113
114 // if the color is especially dark, then
115 // make the contrast even lighter
116 if (c.Red() < 128 && c.Green() < 128 && c.Blue() < 128)
117 amount = 160;
118
119 return wxAuiStepColour(c, amount);
120 }
121
122 // wxAuiBitmapFromBits() is a utility function that creates a
123 // masked bitmap from raw bits (XBM format)
124 wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
125 const wxColour& color)
126 {
127 wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
128 img.Replace(0,0,0,123,123,123);
129 img.Replace(255,255,255,color.Red(),color.Green(),color.Blue());
130 img.SetMaskColour(123,123,123);
131 return wxBitmap(img);
132 }
133
134
135 static void DrawGradientRectangle(wxDC& dc,
136 const wxRect& rect,
137 const wxColour& start_color,
138 const wxColour& end_color,
139 int direction)
140 {
141 int rd, gd, bd, high = 0;
142 rd = end_color.Red() - start_color.Red();
143 gd = end_color.Green() - start_color.Green();
144 bd = end_color.Blue() - start_color.Blue();
145
146 if (direction == wxAUI_GRADIENT_VERTICAL)
147 high = rect.GetHeight()-1;
148 else
149 high = rect.GetWidth()-1;
150
151 for (int i = 0; i <= high; ++i)
152 {
153 int r,g,b;
154
155
156 r = start_color.Red() + ((i*rd*100)/high)/100;
157 g = start_color.Green() + ((i*gd*100)/high)/100;
158 b = start_color.Blue() + ((i*bd*100)/high)/100;
159
160 wxPen p(wxColor((unsigned char)r,
161 (unsigned char)g,
162 (unsigned char)b));
163 dc.SetPen(p);
164
165 if (direction == wxAUI_GRADIENT_VERTICAL)
166 dc.DrawLine(rect.x, rect.y+i, rect.x+rect.width, rect.y+i);
167 else
168 dc.DrawLine(rect.x+i, rect.y, rect.x+i, rect.y+rect.height);
169 }
170 }
171
172 wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
173 {
174 wxCoord x,y;
175
176 // first check if the text fits with no problems
177 dc.GetTextExtent(text, &x, &y);
178 if (x <= max_size)
179 return text;
180
181 size_t i, len = text.Length();
182 size_t last_good_length = 0;
183 for (i = 0; i < len; ++i)
184 {
185 wxString s = text.Left(i);
186 s += wxT("...");
187
188 dc.GetTextExtent(s, &x, &y);
189 if (x > max_size)
190 break;
191
192 last_good_length = i;
193 }
194
195 wxString ret = text.Left(last_good_length);
196 ret += wxT("...");
197 return ret;
198 }
199
200 wxAuiDefaultDockArt::wxAuiDefaultDockArt()
201 {
202 #ifdef __WXMAC__
203 wxBrush toolbarbrush;
204 toolbarbrush.MacSetTheme( kThemeBrushToolbarBackground );
205 wxColor base_colour = toolbarbrush.GetColour();
206 #else
207 wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
208 #endif
209
210 m_base_colour = base_colour;
211 wxColor darker1_colour = wxAuiStepColour(base_colour, 85);
212 wxColor darker2_colour = wxAuiStepColour(base_colour, 75);
213 wxColor darker3_colour = wxAuiStepColour(base_colour, 60);
214 wxColor darker4_colour = wxAuiStepColour(base_colour, 50);
215 wxColor darker5_colour = wxAuiStepColour(base_colour, 40);
216
217 m_active_caption_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
218 m_active_caption_gradient_colour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
219 m_active_caption_text_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
220 m_inactive_caption_colour = darker1_colour;
221 m_inactive_caption_gradient_colour = wxAuiStepColour(base_colour, 97);
222 m_inactive_caption_text_colour = *wxBLACK;
223
224 #ifdef __WXMAC__
225 m_sash_brush = toolbarbrush;
226 m_background_brush = toolbarbrush;
227 m_gripper_brush = toolbarbrush;
228 #else
229 m_sash_brush = wxBrush(base_colour);
230 m_background_brush = wxBrush(base_colour);
231 m_gripper_brush = wxBrush(base_colour);
232 #endif
233 m_border_pen = wxPen(darker2_colour);
234 m_gripper_pen1 = wxPen(darker5_colour);
235 m_gripper_pen2 = wxPen(darker3_colour);
236 m_gripper_pen3 = *wxWHITE_PEN;
237
238 #ifdef __WXMAC__
239 m_caption_font = *wxSMALL_FONT;
240 #else
241 m_caption_font = wxFont(8, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE);
242 #endif
243
244 // some built in bitmaps
245 #if defined( __WXMAC__ )
246 static unsigned char close_bits[]={
247 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
248 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
249 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
250 #elif defined( __WXGTK__)
251 static unsigned char close_bits[]={
252 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8,
253 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef,
254 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
255 #else
256 static unsigned char close_bits[]={
257 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9,
258 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3,
259 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
260 #endif
261
262 static unsigned char maximize_bits[] = {
263 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xf7, 0xf7, 0x07, 0xf0,
264 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0x07, 0xf0,
265 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
266
267 static unsigned char restore_bits[]={
268 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf0, 0x1f, 0xf0, 0xdf, 0xf7,
269 0x07, 0xf4, 0x07, 0xf4, 0xf7, 0xf5, 0xf7, 0xf1, 0xf7, 0xfd, 0xf7, 0xfd,
270 0x07, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
271
272 static unsigned char pin_bits[]={
273 0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0xfc,0xdf,0xfc,0xdf,0xfc,
274 0xdf,0xfc,0xdf,0xfc,0xdf,0xfc,0x0f,0xf8,0x7f,0xff,0x7f,0xff,
275 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
276
277 #ifdef __WXMAC__
278 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE);
279 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE );
280 #else
281 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_inactive_caption_text_colour);
282 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_active_caption_text_colour);
283 #endif
284
285 #ifdef __WXMAC__
286 m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE);
287 m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE );
288 #else
289 m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_inactive_caption_text_colour);
290 m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_active_caption_text_colour);
291 #endif
292
293 #ifdef __WXMAC__
294 m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE);
295 m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE );
296 #else
297 m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_inactive_caption_text_colour);
298 m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_active_caption_text_colour);
299 #endif
300
301 m_inactive_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_inactive_caption_text_colour);
302 m_active_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_active_caption_text_colour);
303
304 // default metric values
305 #if defined(__WXMAC__)
306 SInt32 height;
307 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight , &height );
308 m_sash_size = height;
309 #elif defined(__WXGTK__)
310 m_sash_size = wxRendererNative::Get().GetSplitterParams(NULL).widthSash;
311 #else
312 m_sash_size = 4;
313 #endif
314 m_caption_size = 17;
315 m_border_size = 1;
316 m_button_size = 14;
317 m_gripper_size = 9;
318 m_gradient_type = wxAUI_GRADIENT_VERTICAL;
319 }
320
321 int wxAuiDefaultDockArt::GetMetric(int id)
322 {
323 switch (id)
324 {
325 case wxAUI_ART_SASH_SIZE: return m_sash_size;
326 case wxAUI_ART_CAPTION_SIZE: return m_caption_size;
327 case wxAUI_ART_GRIPPER_SIZE: return m_gripper_size;
328 case wxAUI_ART_PANE_BORDER_SIZE: return m_border_size;
329 case wxAUI_ART_PANE_BUTTON_SIZE: return m_button_size;
330 case wxAUI_ART_GRADIENT_TYPE: return m_gradient_type;
331 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
332 }
333
334 return 0;
335 }
336
337 void wxAuiDefaultDockArt::SetMetric(int id, int new_val)
338 {
339 switch (id)
340 {
341 case wxAUI_ART_SASH_SIZE: m_sash_size = new_val; break;
342 case wxAUI_ART_CAPTION_SIZE: m_caption_size = new_val; break;
343 case wxAUI_ART_GRIPPER_SIZE: m_gripper_size = new_val; break;
344 case wxAUI_ART_PANE_BORDER_SIZE: m_border_size = new_val; break;
345 case wxAUI_ART_PANE_BUTTON_SIZE: m_button_size = new_val; break;
346 case wxAUI_ART_GRADIENT_TYPE: m_gradient_type = new_val; break;
347 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
348 }
349 }
350
351 wxColour wxAuiDefaultDockArt::GetColour(int id)
352 {
353 switch (id)
354 {
355 case wxAUI_ART_BACKGROUND_COLOUR: return m_background_brush.GetColour();
356 case wxAUI_ART_SASH_COLOUR: return m_sash_brush.GetColour();
357 case wxAUI_ART_INACTIVE_CAPTION_COLOUR: return m_inactive_caption_colour;
358 case wxAUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR: return m_inactive_caption_gradient_colour;
359 case wxAUI_ART_INACTIVE_CAPTION_TEXT_COLOUR: return m_inactive_caption_text_colour;
360 case wxAUI_ART_ACTIVE_CAPTION_COLOUR: return m_active_caption_colour;
361 case wxAUI_ART_ACTIVE_CAPTION_GRADIENT_COLOUR: return m_active_caption_gradient_colour;
362 case wxAUI_ART_ACTIVE_CAPTION_TEXT_COLOUR: return m_active_caption_text_colour;
363 case wxAUI_ART_BORDER_COLOUR: return m_border_pen.GetColour();
364 case wxAUI_ART_GRIPPER_COLOUR: return m_gripper_brush.GetColour();
365 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
366 }
367
368 return wxColour();
369 }
370
371 void wxAuiDefaultDockArt::SetColour(int id, const wxColor& colour)
372 {
373 switch (id)
374 {
375 case wxAUI_ART_BACKGROUND_COLOUR: m_background_brush.SetColour(colour); break;
376 case wxAUI_ART_SASH_COLOUR: m_sash_brush.SetColour(colour); break;
377 case wxAUI_ART_INACTIVE_CAPTION_COLOUR: m_inactive_caption_colour = colour; break;
378 case wxAUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR: m_inactive_caption_gradient_colour = colour; break;
379 case wxAUI_ART_INACTIVE_CAPTION_TEXT_COLOUR: m_inactive_caption_text_colour = colour; break;
380 case wxAUI_ART_ACTIVE_CAPTION_COLOUR: m_active_caption_colour = colour; break;
381 case wxAUI_ART_ACTIVE_CAPTION_GRADIENT_COLOUR: m_active_caption_gradient_colour = colour; break;
382 case wxAUI_ART_ACTIVE_CAPTION_TEXT_COLOUR: m_active_caption_text_colour = colour; break;
383 case wxAUI_ART_BORDER_COLOUR: m_border_pen.SetColour(colour); break;
384 case wxAUI_ART_GRIPPER_COLOUR:
385 m_gripper_brush.SetColour(colour);
386 m_gripper_pen1.SetColour(wxAuiStepColour(colour, 40));
387 m_gripper_pen2.SetColour(wxAuiStepColour(colour, 60));
388 break;
389 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
390 }
391 }
392
393 void wxAuiDefaultDockArt::SetFont(int id, const wxFont& font)
394 {
395 if (id == wxAUI_ART_CAPTION_FONT)
396 m_caption_font = font;
397 }
398
399 wxFont wxAuiDefaultDockArt::GetFont(int id)
400 {
401 if (id == wxAUI_ART_CAPTION_FONT)
402 return m_caption_font;
403 return wxNullFont;
404 }
405
406 void wxAuiDefaultDockArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect)
407 {
408 #if defined(__WXMAC__)
409 HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height );
410 CGContextRef cgContext ;
411 #if wxMAC_USE_CORE_GRAPHICS
412 cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext() ;
413 #else
414 Rect bounds ;
415 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
416 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
417 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
418 CGContextScaleCTM( cgContext , 1 , -1 ) ;
419 #endif
420
421 HIThemeSplitterDrawInfo drawInfo ;
422 drawInfo.version = 0 ;
423 drawInfo.state = kThemeStateActive ;
424 drawInfo.adornment = kHIThemeSplitterAdornmentNone ;
425 HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;
426
427 #if wxMAC_USE_CORE_GRAPHICS
428 #else
429 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
430 #endif
431
432 #elif defined(__WXGTK__)
433 // clear out the rectangle first
434 dc.SetPen(*wxTRANSPARENT_PEN);
435 dc.SetBrush(m_sash_brush);
436 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
437
438 GdkRectangle gdk_rect;
439 if (orientation == wxVERTICAL )
440 {
441 gdk_rect.x = rect.x;
442 gdk_rect.y = rect.y;
443 gdk_rect.width = m_sash_size;
444 gdk_rect.height = rect.height;
445 }
446 else
447 {
448 gdk_rect.x = rect.x;
449 gdk_rect.y = rect.y;
450 gdk_rect.width = rect.width;
451 gdk_rect.height = m_sash_size;
452 }
453
454 if (!window) return;
455 if (!window->m_wxwindow) return;
456 if (!GTK_PIZZA(window->m_wxwindow)->bin_window) return;
457
458 gtk_paint_handle
459 (
460 window->m_wxwindow->style,
461 GTK_PIZZA(window->m_wxwindow)->bin_window,
462 // flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
463 GTK_STATE_NORMAL,
464 GTK_SHADOW_NONE,
465 NULL /* no clipping */,
466 window->m_wxwindow,
467 "paned",
468 rect.x,
469 rect.y,
470 rect.width,
471 rect.height,
472 (orientation == wxVERTICAL) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL
473 );
474
475 #else
476 wxUnusedVar(window);
477 wxUnusedVar(orientation);
478 dc.SetPen(*wxTRANSPARENT_PEN);
479 dc.SetBrush(m_sash_brush);
480 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
481 #endif
482 }
483
484
485 void wxAuiDefaultDockArt::DrawBackground(wxDC& dc, wxWindow *WXUNUSED(window), int, const wxRect& rect)
486 {
487 dc.SetPen(*wxTRANSPARENT_PEN);
488 #ifdef __WXMAC__
489 // we have to clear first, otherwise we are drawing a light striped pattern
490 // over an already darker striped background
491 dc.SetBrush(*wxWHITE_BRUSH) ;
492 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
493 #endif
494 dc.SetBrush(m_background_brush);
495 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
496 }
497
498 void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow *WXUNUSED(window), const wxRect& _rect,
499 wxAuiPaneInfo& pane)
500 {
501 dc.SetPen(m_border_pen);
502 dc.SetBrush(*wxTRANSPARENT_BRUSH);
503
504 wxRect rect = _rect;
505 int i, border_width = GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
506
507 if (pane.IsToolbar())
508 {
509 for (i = 0; i < border_width; ++i)
510 {
511 dc.SetPen(*wxWHITE_PEN);
512 dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
513 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height);
514 dc.SetPen(m_border_pen);
515 dc.DrawLine(rect.x, rect.y+rect.height-1,
516 rect.x+rect.width, rect.y+rect.height-1);
517 dc.DrawLine(rect.x+rect.width-1, rect.y,
518 rect.x+rect.width-1, rect.y+rect.height);
519 rect.Deflate(1);
520 }
521 }
522 else
523 {
524 for (i = 0; i < border_width; ++i)
525 {
526 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
527 rect.Deflate(1);
528 }
529 }
530 }
531
532
533 void wxAuiDefaultDockArt::DrawCaptionBackground(wxDC& dc, const wxRect& rect, bool active)
534 {
535 if (m_gradient_type == wxAUI_GRADIENT_NONE)
536 {
537 if (active)
538 dc.SetBrush(wxBrush(m_active_caption_colour));
539 else
540 dc.SetBrush(wxBrush(m_inactive_caption_colour));
541
542 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
543 }
544 else
545 {
546 if (active)
547 {
548 // on mac the gradients are expected to become darker from the top
549 #ifdef __WXMAC__
550 DrawGradientRectangle(dc, rect,
551 m_active_caption_colour,
552 m_active_caption_gradient_colour,
553 m_gradient_type);
554 #else
555 // on other platforms, active gradients become lighter at the top
556 DrawGradientRectangle(dc, rect,
557 m_active_caption_gradient_colour,
558 m_active_caption_colour,
559 m_gradient_type);
560 #endif
561 }
562 else
563 {
564 #ifdef __WXMAC__
565 // on mac the gradients are expected to become darker from the top
566 DrawGradientRectangle(dc, rect,
567 m_inactive_caption_gradient_colour,
568 m_inactive_caption_colour,
569 m_gradient_type);
570 #else
571 // on other platforms, inactive gradients become lighter at the bottom
572 DrawGradientRectangle(dc, rect,
573 m_inactive_caption_colour,
574 m_inactive_caption_gradient_colour,
575 m_gradient_type);
576 #endif
577 }
578 }
579 }
580
581
582 void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window),
583 const wxString& text,
584 const wxRect& rect,
585 wxAuiPaneInfo& pane)
586 {
587 dc.SetPen(*wxTRANSPARENT_PEN);
588 dc.SetFont(m_caption_font);
589
590 DrawCaptionBackground(dc, rect,
591 (pane.state & wxAuiPaneInfo::optionActive)?true:false);
592
593 if (pane.state & wxAuiPaneInfo::optionActive)
594 dc.SetTextForeground(m_active_caption_text_colour);
595 else
596 dc.SetTextForeground(m_inactive_caption_text_colour);
597
598
599 wxCoord w,h;
600 dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);
601
602 wxRect clip_rect = rect;
603 clip_rect.width -= 3; // text offset
604 clip_rect.width -= 2; // button padding
605 if (pane.HasCloseButton())
606 clip_rect.width -= m_button_size;
607 if (pane.HasPinButton())
608 clip_rect.width -= m_button_size;
609 if (pane.HasMaximizeButton())
610 clip_rect.width -= m_button_size;
611
612 wxString draw_text = wxAuiChopText(dc, text, clip_rect.width);
613
614 dc.SetClippingRegion(clip_rect);
615 dc.DrawText(draw_text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
616 dc.DestroyClippingRegion();
617 }
618
619 void wxAuiDefaultDockArt::DrawGripper(wxDC& dc, wxWindow *WXUNUSED(window),
620 const wxRect& rect,
621 wxAuiPaneInfo& pane)
622 {
623 dc.SetPen(*wxTRANSPARENT_PEN);
624 dc.SetBrush(m_gripper_brush);
625
626 dc.DrawRectangle(rect.x, rect.y, rect.width,rect.height);
627
628 if (!pane.HasGripperTop())
629 {
630 int y = 5;
631 while (1)
632 {
633 dc.SetPen(m_gripper_pen1);
634 dc.DrawPoint(rect.x+3, rect.y+y);
635 dc.SetPen(m_gripper_pen2);
636 dc.DrawPoint(rect.x+3, rect.y+y+1);
637 dc.DrawPoint(rect.x+4, rect.y+y);
638 dc.SetPen(m_gripper_pen3);
639 dc.DrawPoint(rect.x+5, rect.y+y+1);
640 dc.DrawPoint(rect.x+5, rect.y+y+2);
641 dc.DrawPoint(rect.x+4, rect.y+y+2);
642
643 y += 4;
644 if (y > rect.GetHeight()-5)
645 break;
646 }
647 }
648 else
649 {
650 int x = 5;
651 while (1)
652 {
653 dc.SetPen(m_gripper_pen1);
654 dc.DrawPoint(rect.x+x, rect.y+3);
655 dc.SetPen(m_gripper_pen2);
656 dc.DrawPoint(rect.x+x+1, rect.y+3);
657 dc.DrawPoint(rect.x+x, rect.y+4);
658 dc.SetPen(m_gripper_pen3);
659 dc.DrawPoint(rect.x+x+1, rect.y+5);
660 dc.DrawPoint(rect.x+x+2, rect.y+5);
661 dc.DrawPoint(rect.x+x+2, rect.y+4);
662
663 x += 4;
664 if (x > rect.GetWidth()-5)
665 break;
666 }
667 }
668 }
669
670 void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, wxWindow *WXUNUSED(window),
671 int button,
672 int button_state,
673 const wxRect& _rect,
674 wxAuiPaneInfo& pane)
675 {
676 wxBitmap bmp;
677 switch (button)
678 {
679 default:
680 case wxAUI_BUTTON_CLOSE:
681 if (pane.state & wxAuiPaneInfo::optionActive)
682 bmp = m_active_close_bitmap;
683 else
684 bmp = m_inactive_close_bitmap;
685 break;
686 case wxAUI_BUTTON_PIN:
687 if (pane.state & wxAuiPaneInfo::optionActive)
688 bmp = m_active_pin_bitmap;
689 else
690 bmp = m_inactive_pin_bitmap;
691 break;
692 case wxAUI_BUTTON_MAXIMIZE_RESTORE:
693 if (pane.IsMaximized())
694 {
695 if (pane.state & wxAuiPaneInfo::optionActive)
696 bmp = m_active_restore_bitmap;
697 else
698 bmp = m_inactive_restore_bitmap;
699 }
700 else
701 {
702 if (pane.state & wxAuiPaneInfo::optionActive)
703 bmp = m_active_maximize_bitmap;
704 else
705 bmp = m_inactive_maximize_bitmap;
706 }
707 break;
708 }
709
710
711 wxRect rect = _rect;
712
713 int old_y = rect.y;
714 rect.y = rect.y + (rect.height/2) - (bmp.GetHeight()/2);
715 rect.height = old_y + rect.height - rect.y - 1;
716
717
718 if (button_state == wxAUI_BUTTON_STATE_PRESSED)
719 {
720 rect.x++;
721 rect.y++;
722 }
723
724 if (button_state == wxAUI_BUTTON_STATE_HOVER ||
725 button_state == wxAUI_BUTTON_STATE_PRESSED)
726 {
727 if (pane.state & wxAuiPaneInfo::optionActive)
728 {
729 dc.SetBrush(wxBrush(wxAuiStepColour(m_active_caption_colour, 120)));
730 dc.SetPen(wxPen(wxAuiStepColour(m_active_caption_colour, 70)));
731 }
732 else
733 {
734 dc.SetBrush(wxBrush(wxAuiStepColour(m_inactive_caption_colour, 120)));
735 dc.SetPen(wxPen(wxAuiStepColour(m_inactive_caption_colour, 70)));
736 }
737
738 // draw the background behind the button
739 dc.DrawRectangle(rect.x, rect.y, 15, 15);
740 }
741
742
743 // draw the button itself
744 dc.DrawBitmap(bmp, rect.x, rect.y, true);
745 }
746
747
748 #endif // wxUSE_AUI