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