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