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