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