]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/art_aui.cpp
Fix bug in Unix wxFileSystemWatcher implementation when watch is deleted.
[wxWidgets.git] / src / ribbon / art_aui.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/art_aui.cpp
3 // Purpose: AUI style art provider for ribbon interface
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-08-04
7 // RCS-ID: $Id$
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_RIBBON
19
20 #include "wx/ribbon/art.h"
21 #include "wx/ribbon/art_internal.h"
22 #include "wx/ribbon/bar.h"
23 #include "wx/ribbon/buttonbar.h"
24 #include "wx/ribbon/gallery.h"
25 #include "wx/ribbon/toolbar.h"
26
27 #ifndef WX_PRECOMP
28 #include "wx/dc.h"
29 #include "wx/settings.h"
30 #endif
31
32 #ifdef __WXMSW__
33 #include "wx/msw/private.h"
34 #elif defined(__WXMAC__)
35 #include "wx/osx/private.h"
36 #endif
37
38 wxRibbonAUIArtProvider::wxRibbonAUIArtProvider()
39 : wxRibbonMSWArtProvider(false)
40 {
41 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
42 wxColor base_colour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground));
43 #else
44 wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
45 #endif
46
47 SetColourScheme(base_colour,
48 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT),
49 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
50
51 m_tab_active_label_font = m_tab_label_font;
52 m_tab_active_label_font.SetWeight(wxFONTWEIGHT_BOLD);
53
54 m_page_border_left = 1;
55 m_page_border_right = 1;
56 m_page_border_top = 1;
57 m_page_border_bottom = 2;
58 m_tab_separation_size = 0;
59
60 m_gallery_bitmap_padding_left_size = 3;
61 m_gallery_bitmap_padding_right_size = 3;
62 m_gallery_bitmap_padding_top_size = 3;
63 m_gallery_bitmap_padding_bottom_size = 3;
64 }
65
66 wxRibbonAUIArtProvider::~wxRibbonAUIArtProvider()
67 {
68 }
69
70 wxRibbonArtProvider* wxRibbonAUIArtProvider::Clone() const
71 {
72 wxRibbonAUIArtProvider *copy = new wxRibbonAUIArtProvider();
73 CloneTo(copy);
74
75 copy->m_tab_ctrl_background_colour = m_tab_ctrl_background_colour;
76 copy->m_tab_ctrl_background_gradient_colour = m_tab_ctrl_background_gradient_colour;
77 copy->m_panel_label_background_colour = m_panel_label_background_colour;
78 copy->m_panel_label_background_gradient_colour = m_panel_label_background_gradient_colour;
79 copy->m_panel_hover_label_background_colour = m_panel_hover_label_background_colour;
80 copy->m_panel_hover_label_background_gradient_colour = m_panel_hover_label_background_gradient_colour;
81
82 copy->m_background_brush = m_background_brush;
83 copy->m_tab_active_top_background_brush = m_tab_active_top_background_brush;
84 copy->m_tab_hover_background_brush = m_tab_hover_background_brush;
85 copy->m_button_bar_hover_background_brush = m_button_bar_hover_background_brush;
86 copy->m_button_bar_active_background_brush = m_button_bar_active_background_brush;
87 copy->m_gallery_button_active_background_brush = m_gallery_button_active_background_brush;
88 copy->m_gallery_button_hover_background_brush = m_gallery_button_hover_background_brush;
89 copy->m_gallery_button_disabled_background_brush = m_gallery_button_disabled_background_brush;
90
91 copy->m_toolbar_hover_borden_pen = m_toolbar_hover_borden_pen;
92 copy->m_tool_hover_background_brush = m_tool_hover_background_brush;
93 copy->m_tool_active_background_brush = m_tool_active_background_brush;
94
95 return copy;
96 }
97
98 void wxRibbonAUIArtProvider::SetFont(int id, const wxFont& font)
99 {
100 wxRibbonMSWArtProvider::SetFont(id, font);
101 if(id == wxRIBBON_ART_TAB_LABEL_FONT)
102 {
103 m_tab_active_label_font = m_tab_label_font;
104 m_tab_active_label_font.SetWeight(wxFONTWEIGHT_BOLD);
105 }
106 }
107
108 wxColour wxRibbonAUIArtProvider::GetColour(int id) const
109 {
110 switch(id)
111 {
112 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR:
113 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR:
114 return m_background_brush.GetColour();
115 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR:
116 return m_tab_ctrl_background_colour;
117 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR:
118 return m_tab_ctrl_background_gradient_colour;
119 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR:
120 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
121 return m_tab_active_top_background_brush.GetColour();
122 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR:
123 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR:
124 return m_tab_hover_background_brush.GetColour();
125 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR:
126 return m_panel_label_background_colour;
127 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR:
128 return m_panel_label_background_gradient_colour;
129 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR:
130 return m_panel_hover_label_background_colour;
131 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR:
132 return m_panel_hover_label_background_gradient_colour;
133 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR:
134 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR:
135 return m_button_bar_hover_background_brush.GetColour();
136 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR:
137 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR:
138 return m_gallery_button_hover_background_brush.GetColour();
139 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR:
140 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
141 return m_gallery_button_active_background_brush.GetColour();
142 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR:
143 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR:
144 return m_gallery_button_disabled_background_brush.GetColour();
145 default:
146 return wxRibbonMSWArtProvider::GetColour(id);
147 }
148 }
149
150 void wxRibbonAUIArtProvider::SetColour(int id, const wxColor& colour)
151 {
152 switch(id)
153 {
154 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR:
155 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR:
156 m_background_brush.SetColour(colour);
157 break;
158 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR:
159 m_tab_ctrl_background_colour = colour;
160 break;
161 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR:
162 m_tab_ctrl_background_gradient_colour = colour;
163 break;
164 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR:
165 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
166 m_tab_active_top_background_brush.SetColour(colour);
167 break;
168 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR:
169 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR:
170 m_tab_hover_background_brush.SetColour(colour);
171 break;
172 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR:
173 m_panel_label_background_colour = colour;
174 break;
175 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR:
176 m_panel_label_background_gradient_colour = colour;
177 break;
178 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR:
179 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR:
180 m_button_bar_hover_background_brush.SetColour(colour);
181 break;
182 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR:
183 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR:
184 m_gallery_button_hover_background_brush.SetColour(colour);
185 break;
186 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR:
187 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
188 m_gallery_button_active_background_brush.SetColour(colour);
189 break;
190 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR:
191 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR:
192 m_gallery_button_disabled_background_brush.SetColour(colour);
193 break;
194 default:
195 wxRibbonMSWArtProvider::SetColour(id, colour);
196 break;
197 }
198 }
199
200 void wxRibbonAUIArtProvider::SetColourScheme(
201 const wxColour& primary,
202 const wxColour& secondary,
203 const wxColour& tertiary)
204 {
205 wxRibbonHSLColour primary_hsl(primary);
206 wxRibbonHSLColour secondary_hsl(secondary);
207 wxRibbonHSLColour tertiary_hsl(tertiary);
208
209 // Map primary & secondary luminance from [0, 1] to [0.15, 0.85]
210 primary_hsl.luminance = cos(primary_hsl.luminance * M_PI) * -0.35 + 0.5;
211 secondary_hsl.luminance = cos(secondary_hsl.luminance * M_PI) * -0.35 + 0.5;
212
213 // TODO: Remove next line once this provider stops piggybacking MSW
214 wxRibbonMSWArtProvider::SetColourScheme(primary, secondary, tertiary);
215
216 #define LikePrimary(luminance) \
217 wxRibbonShiftLuminance(primary_hsl, luminance ## f).ToRGB()
218 #define LikeSecondary(luminance) \
219 wxRibbonShiftLuminance(secondary_hsl, luminance ## f).ToRGB()
220
221 m_tab_ctrl_background_colour = LikePrimary(0.9);
222 m_tab_ctrl_background_gradient_colour = LikePrimary(1.7);
223 m_tab_border_pen = LikePrimary(0.75);
224 m_tab_label_colour = LikePrimary(0.1);
225 m_tab_hover_background_top_colour = primary_hsl.ToRGB();
226 m_tab_hover_background_top_gradient_colour = LikePrimary(1.6);
227 m_tab_hover_background_brush = m_tab_hover_background_top_colour;
228 m_tab_active_background_colour = m_tab_ctrl_background_gradient_colour;
229 m_tab_active_background_gradient_colour = primary_hsl.ToRGB();
230 m_tab_active_top_background_brush = m_tab_active_background_colour;
231 m_panel_label_colour = m_tab_label_colour;
232 m_panel_minimised_label_colour = m_panel_label_colour;
233 m_panel_hover_label_colour = tertiary_hsl.ToRGB();
234 m_page_border_pen = m_tab_border_pen;
235 m_panel_border_pen = m_tab_border_pen;
236 m_background_brush = primary_hsl.ToRGB();
237 m_page_hover_background_colour = LikePrimary(1.5);
238 m_page_hover_background_gradient_colour = LikePrimary(0.9);
239 m_panel_label_background_colour = LikePrimary(0.85);
240 m_panel_label_background_gradient_colour = LikePrimary(0.97);
241 m_panel_hover_label_background_gradient_colour = secondary_hsl.ToRGB();
242 m_panel_hover_label_background_colour = secondary_hsl.Lighter(0.2f).ToRGB();
243 m_button_bar_hover_border_pen = secondary_hsl.ToRGB();
244 m_button_bar_hover_background_brush = LikeSecondary(1.7);
245 m_button_bar_active_background_brush = LikeSecondary(1.4);
246 m_button_bar_label_colour = m_tab_label_colour;
247 m_button_bar_label_disabled_colour = m_tab_label_colour;
248 m_gallery_border_pen = m_tab_border_pen;
249 m_gallery_item_border_pen = m_button_bar_hover_border_pen;
250 m_gallery_hover_background_brush = LikePrimary(1.2);
251 m_gallery_button_background_colour = m_page_hover_background_colour;
252 m_gallery_button_background_gradient_colour = m_page_hover_background_gradient_colour;
253 m_gallery_button_hover_background_brush = m_button_bar_hover_background_brush;
254 m_gallery_button_active_background_brush = m_button_bar_active_background_brush;
255 m_gallery_button_disabled_background_brush = primary_hsl.Desaturated(0.15f).ToRGB();
256 SetColour(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR, LikePrimary(0.1));
257 SetColour(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR, wxColour(128, 128, 128));
258 SetColour(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR, LikeSecondary(0.1));
259 SetColour(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR, LikeSecondary(0.1));
260 m_toolbar_border_pen = m_tab_border_pen;
261 SetColour(wxRIBBON_ART_TOOLBAR_FACE_COLOUR, LikePrimary(0.1));
262 m_tool_background_colour = m_page_hover_background_colour;
263 m_tool_background_gradient_colour = m_page_hover_background_gradient_colour;
264 m_toolbar_hover_borden_pen = m_button_bar_hover_border_pen;
265 m_tool_hover_background_brush = m_button_bar_hover_background_brush;
266 m_tool_active_background_brush = m_button_bar_active_background_brush;
267
268 #undef LikeSecondary
269 #undef LikePrimary
270 }
271
272 void wxRibbonAUIArtProvider::DrawTabCtrlBackground(
273 wxDC& dc,
274 wxWindow* WXUNUSED(wnd),
275 const wxRect& rect)
276 {
277 wxRect gradient_rect(rect);
278 gradient_rect.height--;
279 dc.GradientFillLinear(gradient_rect, m_tab_ctrl_background_colour,
280 m_tab_ctrl_background_gradient_colour, wxSOUTH);
281 dc.SetPen(m_tab_border_pen);
282 dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight()+1, rect.GetBottom());
283 }
284
285 int wxRibbonAUIArtProvider::GetTabCtrlHeight(
286 wxDC& dc,
287 wxWindow* WXUNUSED(wnd),
288 const wxRibbonPageTabInfoArray& pages)
289 {
290 int text_height = 0;
291 int icon_height = 0;
292
293 if(pages.GetCount() <= 1 && (m_flags & wxRIBBON_BAR_ALWAYS_SHOW_TABS) == 0)
294 {
295 // To preserve space, a single tab need not be displayed. We still need
296 // one pixel of border though.
297 return 1;
298 }
299
300 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
301 {
302 dc.SetFont(m_tab_active_label_font);
303 text_height = dc.GetTextExtent(wxT("ABCDEFXj")).GetHeight();
304 }
305 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
306 {
307 size_t numpages = pages.GetCount();
308 for(size_t i = 0; i < numpages; ++i)
309 {
310 const wxRibbonPageTabInfo& info = pages.Item(i);
311 if(info.page->GetIcon().IsOk())
312 {
313 icon_height = wxMax(icon_height, info.page->GetIcon().GetHeight());
314 }
315 }
316 }
317
318 return wxMax(text_height, icon_height) + 10;
319 }
320
321 void wxRibbonAUIArtProvider::DrawTab(wxDC& dc,
322 wxWindow* WXUNUSED(wnd),
323 const wxRibbonPageTabInfo& tab)
324 {
325 if(tab.rect.height <= 1)
326 return;
327
328 dc.SetFont(m_tab_label_font);
329 dc.SetPen(*wxTRANSPARENT_PEN);
330 if(tab.active || tab.hovered || tab.highlight)
331 {
332 if(tab.active)
333 {
334 dc.SetFont(m_tab_active_label_font);
335 dc.SetBrush(m_background_brush);
336 dc.DrawRectangle(tab.rect.x, tab.rect.y + tab.rect.height - 1,
337 tab.rect.width - 1, 1);
338 }
339 wxRect grad_rect(tab.rect);
340 grad_rect.height -= 4;
341 grad_rect.width -= 1;
342 grad_rect.height /= 2;
343 grad_rect.y = grad_rect.y + tab.rect.height - grad_rect.height - 1;
344 dc.SetBrush(m_tab_active_top_background_brush);
345 dc.DrawRectangle(tab.rect.x, tab.rect.y + 3, tab.rect.width - 1,
346 grad_rect.y - tab.rect.y - 3);
347 if(tab.highlight)
348 {
349 wxColour top_colour((m_tab_active_background_colour.Red() + m_tab_hover_background_top_colour.Red())/2,
350 (m_tab_active_background_colour.Green() + m_tab_hover_background_top_colour.Green())/2,
351 (m_tab_active_background_colour.Blue() + m_tab_hover_background_top_colour.Blue())/2);
352
353 wxColour bottom_colour((m_tab_active_background_gradient_colour.Red() + m_tab_hover_background_top_gradient_colour.Red())/2,
354 (m_tab_active_background_gradient_colour.Green() + m_tab_hover_background_top_gradient_colour.Green())/2,
355 (m_tab_active_background_gradient_colour.Blue() + m_tab_hover_background_top_gradient_colour.Blue())/2);
356
357 dc.GradientFillLinear(grad_rect, top_colour,
358 bottom_colour, wxSOUTH);
359 }
360 else
361 {
362 dc.GradientFillLinear(grad_rect, m_tab_active_background_colour,
363 m_tab_active_background_gradient_colour, wxSOUTH);
364 }
365 }
366 else
367 {
368 wxRect btm_rect(tab.rect);
369 btm_rect.height -= 4;
370 btm_rect.width -= 1;
371 btm_rect.height /= 2;
372 btm_rect.y = btm_rect.y + tab.rect.height - btm_rect.height - 1;
373 dc.SetBrush(m_tab_hover_background_brush);
374 dc.DrawRectangle(btm_rect.x, btm_rect.y, btm_rect.width,
375 btm_rect.height);
376 wxRect grad_rect(tab.rect);
377 grad_rect.width -= 1;
378 grad_rect.y += 3;
379 grad_rect.height = btm_rect.y - grad_rect.y;
380 dc.GradientFillLinear(grad_rect, m_tab_hover_background_top_colour,
381 m_tab_hover_background_top_gradient_colour, wxSOUTH);
382 }
383
384 wxPoint border_points[5];
385 border_points[0] = wxPoint(0, 3);
386 border_points[1] = wxPoint(1, 2);
387 border_points[2] = wxPoint(tab.rect.width - 3, 2);
388 border_points[3] = wxPoint(tab.rect.width - 1, 4);
389 border_points[4] = wxPoint(tab.rect.width - 1, tab.rect.height - 1);
390
391 dc.SetPen(m_tab_border_pen);
392 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, tab.rect.x, tab.rect.y);
393
394 wxRect old_clip;
395 dc.GetClippingBox(old_clip);
396 bool is_first_tab = false;
397 wxRibbonBar* bar = wxDynamicCast(tab.page->GetParent(), wxRibbonBar);
398 if(bar && bar->GetPage(0) == tab.page)
399 is_first_tab = true;
400
401 wxBitmap icon;
402 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
403 {
404 icon = tab.page->GetIcon();
405 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) == 0)
406 {
407 if(icon.IsOk())
408 {
409 int x = tab.rect.x + (tab.rect.width - icon.GetWidth()) / 2;
410 dc.DrawBitmap(icon, x, tab.rect.y + 1 + (tab.rect.height - 1 -
411 icon.GetHeight()) / 2, true);
412 }
413 }
414 }
415 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
416 {
417 wxString label = tab.page->GetLabel();
418 if(!label.IsEmpty())
419 {
420 dc.SetTextForeground(m_tab_label_colour);
421 dc.SetBackgroundMode(wxTRANSPARENT);
422
423 int offset = 0;
424 if(icon.IsOk())
425 offset += icon.GetWidth() + 2;
426 int text_height;
427 int text_width;
428 dc.GetTextExtent(label, &text_width, &text_height);
429 int x = (tab.rect.width - 2 - text_width - offset) / 2;
430 if(x > 8)
431 x = 8;
432 else if(x < 1)
433 x = 1;
434 int width = tab.rect.width - x - 2;
435 x += tab.rect.x + offset;
436 int y = tab.rect.y + (tab.rect.height - text_height) / 2;
437 if(icon.IsOk())
438 {
439 dc.DrawBitmap(icon, x - offset, tab.rect.y + (tab.rect.height -
440 icon.GetHeight()) / 2, true);
441 }
442 dc.SetClippingRegion(x, tab.rect.y, width, tab.rect.height);
443 dc.DrawText(label, x, y);
444 }
445 }
446
447 // Draw the left hand edge of the tab only for the first tab (subsequent
448 // tabs use the right edge of the prior tab as their left edge). As this is
449 // outside the rectangle for the tab, only draw it if the leftmost part of
450 // the tab is within the clip rectangle (the clip region has to be cleared
451 // to draw outside the tab).
452 if(is_first_tab && old_clip.x <= tab.rect.x
453 && tab.rect.x < old_clip.x + old_clip.width)
454 {
455 dc.DestroyClippingRegion();
456 dc.DrawLine(tab.rect.x - 1, tab.rect.y + 4, tab.rect.x - 1,
457 tab.rect.y + tab.rect.height - 1);
458 }
459 }
460
461 void wxRibbonAUIArtProvider::GetBarTabWidth(
462 wxDC& dc,
463 wxWindow* WXUNUSED(wnd),
464 const wxString& label,
465 const wxBitmap& bitmap,
466 int* ideal,
467 int* small_begin_need_separator,
468 int* small_must_have_separator,
469 int* minimum)
470 {
471 int width = 0;
472 int min = 0;
473 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) && !label.IsEmpty())
474 {
475 dc.SetFont(m_tab_active_label_font);
476 width += dc.GetTextExtent(label).GetWidth();
477 min += wxMin(30, width); // enough for a few chars
478 if(bitmap.IsOk())
479 {
480 // gap between label and bitmap
481 width += 4;
482 min += 2;
483 }
484 }
485 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS) && bitmap.IsOk())
486 {
487 width += bitmap.GetWidth();
488 min += bitmap.GetWidth();
489 }
490
491 if(ideal != NULL)
492 {
493 *ideal = width + 16;
494 }
495 if(small_begin_need_separator != NULL)
496 {
497 *small_begin_need_separator = min;
498 }
499 if(small_must_have_separator != NULL)
500 {
501 *small_must_have_separator = min;
502 }
503 if(minimum != NULL)
504 {
505 *minimum = min;
506 }
507 }
508
509 void wxRibbonAUIArtProvider::DrawTabSeparator(
510 wxDC& WXUNUSED(dc),
511 wxWindow* WXUNUSED(wnd),
512 const wxRect& WXUNUSED(rect),
513 double WXUNUSED(visibility))
514 {
515 // No explicit separators between tabs
516 }
517
518 void wxRibbonAUIArtProvider::DrawPageBackground(
519 wxDC& dc,
520 wxWindow* WXUNUSED(wnd),
521 const wxRect& rect)
522 {
523 dc.SetPen(*wxTRANSPARENT_PEN);
524 dc.SetBrush(m_background_brush);
525 dc.DrawRectangle(rect.x + 1, rect.y, rect.width - 2, rect.height - 1);
526
527 dc.SetPen(m_page_border_pen);
528 dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
529 dc.DrawLine(rect.GetRight(), rect.y, rect.GetRight(), rect.y +rect.height);
530 dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight()+1, rect.GetBottom());
531 }
532
533 wxSize wxRibbonAUIArtProvider::GetScrollButtonMinimumSize(
534 wxDC& WXUNUSED(dc),
535 wxWindow* WXUNUSED(wnd),
536 long WXUNUSED(style))
537 {
538 return wxSize(11, 11);
539 }
540
541 void wxRibbonAUIArtProvider::DrawScrollButton(
542 wxDC& dc,
543 wxWindow* WXUNUSED(wnd),
544 const wxRect& rect,
545 long style)
546 {
547 wxRect true_rect(rect);
548 wxPoint arrow_points[3];
549
550 if((style & wxRIBBON_SCROLL_BTN_FOR_MASK) == wxRIBBON_SCROLL_BTN_FOR_TABS)
551 {
552 true_rect.y += 2;
553 true_rect.height -= 2;
554 dc.SetPen(m_tab_border_pen);
555 }
556 else
557 {
558 dc.SetPen(*wxTRANSPARENT_PEN);
559 dc.SetBrush(m_background_brush);
560 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
561 dc.SetPen(m_page_border_pen);
562 }
563
564 switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK)
565 {
566 case wxRIBBON_SCROLL_BTN_LEFT:
567 dc.DrawLine(true_rect.GetRight(), true_rect.y, true_rect.GetRight(),
568 true_rect.y + true_rect.height);
569 arrow_points[0] = wxPoint(rect.width / 2 - 2, rect.height / 2);
570 arrow_points[1] = arrow_points[0] + wxPoint(5, -5);
571 arrow_points[2] = arrow_points[0] + wxPoint(5, 5);
572 break;
573 case wxRIBBON_SCROLL_BTN_RIGHT:
574 dc.DrawLine(true_rect.x, true_rect.y, true_rect.x,
575 true_rect.y + true_rect.height);
576 arrow_points[0] = wxPoint(rect.width / 2 + 3, rect.height / 2);
577 arrow_points[1] = arrow_points[0] - wxPoint(5, -5);
578 arrow_points[2] = arrow_points[0] - wxPoint(5, 5);
579 break;
580 case wxRIBBON_SCROLL_BTN_DOWN:
581 dc.DrawLine(true_rect.x, true_rect.y, true_rect.x + true_rect.width,
582 true_rect.y);
583 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 + 3);
584 arrow_points[1] = arrow_points[0] - wxPoint( 5, 5);
585 arrow_points[2] = arrow_points[0] - wxPoint(-5, 5);
586 break;
587 case wxRIBBON_SCROLL_BTN_UP:
588 dc.DrawLine(true_rect.x, true_rect.GetBottom(),
589 true_rect.x + true_rect.width, true_rect.GetBottom());
590 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 - 2);
591 arrow_points[1] = arrow_points[0] + wxPoint( 5, 5);
592 arrow_points[2] = arrow_points[0] + wxPoint(-5, 5);
593 break;
594 default:
595 return;
596 }
597
598 int x = rect.x;
599 int y = rect.y;
600 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
601 {
602 ++x;
603 ++y;
604 }
605
606 dc.SetPen(*wxTRANSPARENT_PEN);
607 wxBrush B(m_tab_label_colour);
608 dc.SetBrush(B);
609 dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, x, y);
610 }
611
612 wxSize wxRibbonAUIArtProvider::GetPanelSize(
613 wxDC& dc,
614 const wxRibbonPanel* wnd,
615 wxSize client_size,
616 wxPoint* client_offset)
617 {
618 dc.SetFont(m_panel_label_font);
619 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
620 int label_height = label_size.GetHeight() + 5;
621 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
622 {
623 client_size.IncBy(4, label_height + 6);
624 if(client_offset)
625 *client_offset = wxPoint(2, label_height + 3);
626 }
627 else
628 {
629 client_size.IncBy(6, label_height + 4);
630 if(client_offset)
631 *client_offset = wxPoint(3, label_height + 2);
632 }
633 return client_size;
634 }
635
636 wxSize wxRibbonAUIArtProvider::GetPanelClientSize(
637 wxDC& dc,
638 const wxRibbonPanel* wnd,
639 wxSize size,
640 wxPoint* client_offset)
641 {
642 dc.SetFont(m_panel_label_font);
643 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
644 int label_height = label_size.GetHeight() + 5;
645 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
646 {
647 size.DecBy(4, label_height + 6);
648 if(client_offset)
649 *client_offset = wxPoint(2, label_height + 3);
650 }
651 else
652 {
653 size.DecBy(6, label_height + 4);
654 if(client_offset)
655 *client_offset = wxPoint(3, label_height + 2);
656 }
657 if (size.x < 0) size.x = 0;
658 if (size.y < 0) size.y = 0;
659 return size;
660 }
661
662 wxRect wxRibbonAUIArtProvider::GetPanelExtButtonArea(wxDC& dc,
663 const wxRibbonPanel* wnd,
664 wxRect rect)
665 {
666 wxRect true_rect(rect);
667 RemovePanelPadding(&true_rect);
668
669 true_rect.x++;
670 true_rect.width -= 2;
671 true_rect.y++;
672
673 dc.SetFont(m_panel_label_font);
674 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
675 int label_height = label_size.GetHeight() + 5;
676 wxRect label_rect(true_rect);
677 label_rect.height = label_height - 1;
678
679 rect = wxRect(label_rect.GetRight()-13, label_rect.GetBottom()-13, 13, 13);
680 return rect;
681 }
682
683 void wxRibbonAUIArtProvider::DrawPanelBackground(
684 wxDC& dc,
685 wxRibbonPanel* wnd,
686 const wxRect& rect)
687 {
688 dc.SetPen(*wxTRANSPARENT_PEN);
689 dc.SetBrush(m_background_brush);
690 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
691
692 wxRect true_rect(rect);
693 RemovePanelPadding(&true_rect);
694
695 dc.SetPen(m_panel_border_pen);
696 dc.SetBrush(*wxTRANSPARENT_BRUSH);
697 dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);
698
699 true_rect.x++;
700 true_rect.width -= 2;
701 true_rect.y++;
702
703 dc.SetFont(m_panel_label_font);
704 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
705 int label_height = label_size.GetHeight() + 5;
706 wxRect label_rect(true_rect);
707 label_rect.height = label_height - 1;
708 dc.DrawLine(label_rect.x, label_rect.y + label_rect.height,
709 label_rect.x + label_rect.width, label_rect.y + label_rect.height);
710
711 wxColour label_bg_colour = m_panel_label_background_colour;
712 wxColour label_bg_grad_colour = m_panel_label_background_gradient_colour;
713 if(wnd->IsHovered())
714 {
715 label_bg_colour = m_panel_hover_label_background_colour;
716 label_bg_grad_colour = m_panel_hover_label_background_gradient_colour;
717 dc.SetTextForeground(m_panel_hover_label_colour);
718 }
719 else
720 {
721 dc.SetTextForeground(m_panel_label_colour);
722 }
723 dc.GradientFillLinear(label_rect,
724 #ifdef __WXMAC__
725 label_bg_grad_colour, label_bg_colour, wxSOUTH);
726 #else
727 label_bg_colour, label_bg_grad_colour, wxSOUTH);
728 #endif
729 dc.SetFont(m_panel_label_font);
730 dc.DrawText(wnd->GetLabel(), label_rect.x + 3, label_rect.y + 2);
731
732 if(wnd->IsHovered())
733 {
734 wxRect gradient_rect(true_rect);
735 gradient_rect.y += label_rect.height + 1;
736 gradient_rect.height = true_rect.height - label_rect.height - 3;
737 #ifdef __WXMAC__
738 wxColour colour = m_page_hover_background_gradient_colour;
739 wxColour gradient = m_page_hover_background_colour;
740 #else
741 wxColour colour = m_page_hover_background_colour;
742 wxColour gradient = m_page_hover_background_gradient_colour;
743 #endif
744 dc.GradientFillLinear(gradient_rect, colour, gradient, wxSOUTH);
745 }
746
747 if(wnd->HasExtButton())
748 {
749 if(wnd->IsExtButtonHovered())
750 {
751 dc.SetPen(m_panel_hover_button_border_pen);
752 dc.SetBrush(m_panel_hover_button_background_brush);
753 dc.DrawRoundedRectangle(label_rect.GetRight() - 13, label_rect.GetBottom() - 13, 13, 13, 1.0);
754 dc.DrawBitmap(m_panel_extension_bitmap[1], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
755 }
756 else
757 dc.DrawBitmap(m_panel_extension_bitmap[0], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
758 }
759 }
760
761 void wxRibbonAUIArtProvider::DrawMinimisedPanel(
762 wxDC& dc,
763 wxRibbonPanel* wnd,
764 const wxRect& rect,
765 wxBitmap& bitmap)
766 {
767 dc.SetPen(*wxTRANSPARENT_PEN);
768 dc.SetBrush(m_background_brush);
769 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
770
771 wxRect true_rect(rect);
772 RemovePanelPadding(&true_rect);
773
774 dc.SetPen(m_panel_border_pen);
775 dc.SetBrush(*wxTRANSPARENT_BRUSH);
776 dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);
777 true_rect.Deflate(1);
778
779 if(wnd->IsHovered() || wnd->GetExpandedPanel())
780 {
781 wxColour colour = m_page_hover_background_colour;
782 wxColour gradient = m_page_hover_background_gradient_colour;
783 #ifdef __WXMAC__
784 if(!wnd->GetExpandedPanel())
785 #else
786 if(wnd->GetExpandedPanel())
787 #endif
788 {
789 wxColour temp = colour;
790 colour = gradient;
791 gradient = temp;
792 }
793 dc.GradientFillLinear(true_rect, colour, gradient, wxSOUTH);
794 }
795
796 wxRect preview;
797 DrawMinimisedPanelCommon(dc, wnd, true_rect, &preview);
798
799 dc.SetPen(m_panel_border_pen);
800 dc.SetBrush(*wxTRANSPARENT_BRUSH);
801 dc.DrawRectangle(preview.x, preview.y, preview.width, preview.height);
802 preview.Deflate(1);
803 wxRect preview_caption_rect(preview);
804 preview_caption_rect.height = 7;
805 preview.y += preview_caption_rect.height;
806 preview.height -= preview_caption_rect.height;
807 #ifdef __WXMAC__
808 dc.GradientFillLinear(preview_caption_rect,
809 m_panel_hover_label_background_gradient_colour,
810 m_panel_hover_label_background_colour, wxSOUTH);
811 dc.GradientFillLinear(preview,
812 m_page_hover_background_gradient_colour,
813 m_page_hover_background_colour, wxSOUTH);
814 #else
815 dc.GradientFillLinear(preview_caption_rect,
816 m_panel_hover_label_background_colour,
817 m_panel_hover_label_background_gradient_colour, wxSOUTH);
818 dc.GradientFillLinear(preview,
819 m_page_hover_background_colour,
820 m_page_hover_background_gradient_colour, wxSOUTH);
821 #endif
822
823 if(bitmap.IsOk())
824 {
825 dc.DrawBitmap(bitmap, preview.x + (preview.width - bitmap.GetWidth()) / 2,
826 preview.y + (preview.height - bitmap.GetHeight()) / 2, true);
827 }
828 }
829
830 void wxRibbonAUIArtProvider::DrawPartialPanelBackground(wxDC& dc,
831 wxWindow* wnd, const wxRect& rect)
832 {
833 dc.SetPen(*wxTRANSPARENT_PEN);
834 dc.SetBrush(m_background_brush);
835 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
836
837 wxPoint offset(wnd->GetPosition());
838 wxWindow* parent = wnd->GetParent();
839 wxRibbonPanel* panel = NULL;
840
841 for(; parent; parent = parent->GetParent())
842 {
843 panel = wxDynamicCast(parent, wxRibbonPanel);
844 if(panel != NULL)
845 {
846 if(!panel->IsHovered())
847 return;
848 break;
849 }
850 offset += parent->GetPosition();
851 }
852 if(panel == NULL)
853 return;
854
855 wxRect background(panel->GetSize());
856 RemovePanelPadding(&background);
857 background.x++;
858 background.width -= 2;
859 dc.SetFont(m_panel_label_font);
860 int caption_height = dc.GetTextExtent(panel->GetLabel()).GetHeight() + 7;
861 background.y += caption_height - 1;
862 background.height -= caption_height;
863
864 wxRect paint_rect(rect);
865 paint_rect.x += offset.x;
866 paint_rect.y += offset.y;
867
868 wxColour bg_clr, bg_grad_clr;
869 #ifdef __WXMAC__
870 bg_grad_clr = m_page_hover_background_colour;
871 bg_clr = m_page_hover_background_gradient_colour;
872 #else
873 bg_clr = m_page_hover_background_colour;
874 bg_grad_clr = m_page_hover_background_gradient_colour;
875 #endif
876
877 paint_rect.Intersect(background);
878 if(!paint_rect.IsEmpty())
879 {
880 wxColour starting_colour(wxRibbonInterpolateColour(bg_clr, bg_grad_clr,
881 paint_rect.y, background.y, background.y + background.height));
882 wxColour ending_colour(wxRibbonInterpolateColour(bg_clr, bg_grad_clr,
883 paint_rect.y + paint_rect.height, background.y,
884 background.y + background.height));
885 paint_rect.x -= offset.x;
886 paint_rect.y -= offset.y;
887 dc.GradientFillLinear(paint_rect, starting_colour, ending_colour
888 , wxSOUTH);
889 }
890 }
891
892 void wxRibbonAUIArtProvider::DrawGalleryBackground(
893 wxDC& dc,
894 wxRibbonGallery* wnd,
895 const wxRect& rect)
896 {
897 DrawPartialPanelBackground(dc, wnd, rect);
898
899 if(wnd->IsHovered())
900 {
901 dc.SetPen(*wxTRANSPARENT_PEN);
902 dc.SetBrush(m_gallery_hover_background_brush);
903 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
904 {
905 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 2,
906 rect.height - 16);
907 }
908 else
909 {
910 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 16,
911 rect.height - 2);
912 }
913 }
914
915 dc.SetPen(m_gallery_border_pen);
916 dc.SetBrush(*wxTRANSPARENT_BRUSH);
917 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
918
919 DrawGalleryBackgroundCommon(dc, wnd, rect);
920 }
921
922 void wxRibbonAUIArtProvider::DrawGalleryButton(wxDC& dc, wxRect rect,
923 wxRibbonGalleryButtonState state, wxBitmap* bitmaps)
924 {
925 int extra_height = 0;
926 int extra_width = 0;
927 wxRect reduced_rect(rect);
928 reduced_rect.Deflate(1);
929 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
930 {
931 reduced_rect.width++;
932 extra_width = 1;
933 }
934 else
935 {
936 reduced_rect.height++;
937 extra_height = 1;
938 }
939
940 wxBitmap btn_bitmap;
941 switch(state)
942 {
943 case wxRIBBON_GALLERY_BUTTON_NORMAL:
944 dc.GradientFillLinear(reduced_rect,
945 m_gallery_button_background_colour,
946 m_gallery_button_background_gradient_colour, wxSOUTH);
947 btn_bitmap = bitmaps[0];
948 break;
949 case wxRIBBON_GALLERY_BUTTON_HOVERED:
950 dc.SetPen(m_gallery_item_border_pen);
951 dc.SetBrush(m_gallery_button_hover_background_brush);
952 dc.DrawRectangle(rect.x, rect.y, rect.width + extra_width,
953 rect.height + extra_height);
954 btn_bitmap = bitmaps[1];
955 break;
956 case wxRIBBON_GALLERY_BUTTON_ACTIVE:
957 dc.SetPen(m_gallery_item_border_pen);
958 dc.SetBrush(m_gallery_button_active_background_brush);
959 dc.DrawRectangle(rect.x, rect.y, rect.width + extra_width,
960 rect.height + extra_height);
961 btn_bitmap = bitmaps[2];
962 break;
963 case wxRIBBON_GALLERY_BUTTON_DISABLED:
964 dc.SetPen(*wxTRANSPARENT_PEN);
965 dc.SetBrush(m_gallery_button_disabled_background_brush);
966 dc.DrawRectangle(reduced_rect.x, reduced_rect.y, reduced_rect.width,
967 reduced_rect.height);
968 btn_bitmap = bitmaps[3];
969 break;
970 }
971
972 dc.DrawBitmap(btn_bitmap, reduced_rect.x + reduced_rect.width / 2 - 2,
973 (rect.y + rect.height / 2) - 2, true);
974 }
975
976 void wxRibbonAUIArtProvider::DrawGalleryItemBackground(
977 wxDC& dc,
978 wxRibbonGallery* wnd,
979 const wxRect& rect,
980 wxRibbonGalleryItem* item)
981 {
982 if(wnd->GetHoveredItem() != item && wnd->GetActiveItem() != item &&
983 wnd->GetSelection() != item)
984 return;
985
986 dc.SetPen(m_gallery_item_border_pen);
987 if(wnd->GetActiveItem() == item || wnd->GetSelection() == item)
988 dc.SetBrush(m_gallery_button_active_background_brush);
989 else
990 dc.SetBrush(m_gallery_button_hover_background_brush);
991
992 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
993 }
994
995 void wxRibbonAUIArtProvider::DrawButtonBarBackground(
996 wxDC& dc,
997 wxWindow* wnd,
998 const wxRect& rect)
999 {
1000 DrawPartialPanelBackground(dc, wnd, rect);
1001 }
1002
1003 void wxRibbonAUIArtProvider::DrawButtonBarButton(
1004 wxDC& dc,
1005 wxWindow* WXUNUSED(wnd),
1006 const wxRect& rect,
1007 wxRibbonButtonKind kind,
1008 long state,
1009 const wxString& label,
1010 const wxBitmap& bitmap_large,
1011 const wxBitmap& bitmap_small)
1012 {
1013 if(kind == wxRIBBON_BUTTON_TOGGLE)
1014 {
1015 kind = wxRIBBON_BUTTON_NORMAL;
1016 if(state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
1017 state ^= wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK;
1018 }
1019
1020 if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
1021 | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
1022 {
1023 dc.SetPen(m_button_bar_hover_border_pen);
1024
1025 wxRect bg_rect(rect);
1026 bg_rect.Deflate(1);
1027
1028 if(kind == wxRIBBON_BUTTON_HYBRID)
1029 {
1030 switch(state & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
1031 {
1032 case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
1033 {
1034 int iYBorder = rect.y + bitmap_large.GetHeight() + 4;
1035 wxRect partial_bg(rect);
1036 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
1037 {
1038 partial_bg.SetBottom(iYBorder - 1);
1039 }
1040 else
1041 {
1042 partial_bg.height -= (iYBorder - partial_bg.y + 1);
1043 partial_bg.y = iYBorder + 1;
1044 }
1045 dc.DrawLine(rect.x, iYBorder, rect.x + rect.width, iYBorder);
1046 bg_rect.Intersect(partial_bg);
1047 }
1048 break;
1049 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
1050 {
1051 int iArrowWidth = 9;
1052 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
1053 {
1054 bg_rect.width -= iArrowWidth;
1055 dc.DrawLine(bg_rect.x + bg_rect.width,
1056 rect.y, bg_rect.x + bg_rect.width,
1057 rect.y + rect.height);
1058 }
1059 else
1060 {
1061 --iArrowWidth;
1062 bg_rect.x += bg_rect.width - iArrowWidth;
1063 bg_rect.width = iArrowWidth;
1064 dc.DrawLine(bg_rect.x - 1, rect.y,
1065 bg_rect.x - 1, rect.y + rect.height);
1066 }
1067 }
1068 break;
1069 case wxRIBBON_BUTTONBAR_BUTTON_SMALL:
1070 break;
1071 }
1072 }
1073
1074 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1075 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
1076
1077 dc.SetPen(*wxTRANSPARENT_PEN);
1078 if(state & wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK)
1079 dc.SetBrush(m_button_bar_active_background_brush);
1080 else
1081 dc.SetBrush(m_button_bar_hover_background_brush);
1082 dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
1083 }
1084
1085 dc.SetFont(m_button_bar_label_font);
1086 dc.SetTextForeground(state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED
1087 ? m_button_bar_label_disabled_colour
1088 : m_button_bar_label_colour);
1089 DrawButtonBarButtonForeground(dc, rect, kind, state, label, bitmap_large,
1090 bitmap_small);
1091 }
1092
1093 void wxRibbonAUIArtProvider::DrawToolBarBackground(
1094 wxDC& dc,
1095 wxWindow* wnd,
1096 const wxRect& rect)
1097 {
1098 DrawPartialPanelBackground(dc, wnd, rect);
1099 }
1100
1101 void wxRibbonAUIArtProvider::DrawToolGroupBackground(
1102 wxDC& dc,
1103 wxWindow* WXUNUSED(wnd),
1104 const wxRect& rect)
1105 {
1106 dc.SetPen(m_toolbar_border_pen);
1107 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1108 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
1109 wxRect bg_rect(rect);
1110 bg_rect.Deflate(1);
1111 dc.GradientFillLinear(bg_rect, m_tool_background_colour,
1112 m_tool_background_gradient_colour, wxSOUTH);
1113 }
1114
1115 void wxRibbonAUIArtProvider::DrawTool(
1116 wxDC& dc,
1117 wxWindow* WXUNUSED(wnd),
1118 const wxRect& rect,
1119 const wxBitmap& bitmap,
1120 wxRibbonButtonKind kind,
1121 long state)
1122 {
1123 if(kind == wxRIBBON_BUTTON_TOGGLE)
1124 {
1125 if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED)
1126 state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
1127 }
1128
1129 wxRect bg_rect(rect);
1130 bg_rect.Deflate(1);
1131 if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
1132 bg_rect.width++;
1133 bool is_custom_bg = (state & (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK |
1134 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)) != 0;
1135 bool is_split_hybrid = kind == wxRIBBON_BUTTON_HYBRID && is_custom_bg;
1136
1137 // Background
1138 if(is_custom_bg)
1139 {
1140 dc.SetPen(*wxTRANSPARENT_PEN);
1141 dc.SetBrush(m_tool_hover_background_brush);
1142 dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
1143 if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
1144 {
1145 wxRect active_rect(bg_rect);
1146 if(kind == wxRIBBON_BUTTON_HYBRID)
1147 {
1148 active_rect.width -= 8;
1149 if(state & wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE)
1150 {
1151 active_rect.x += active_rect.width;
1152 active_rect.width = 8;
1153 }
1154 }
1155 dc.SetBrush(m_tool_active_background_brush);
1156 dc.DrawRectangle(active_rect.x, active_rect.y, active_rect.width,
1157 active_rect.height);
1158 }
1159 }
1160
1161 // Border
1162 if(is_custom_bg)
1163 dc.SetPen(m_toolbar_hover_borden_pen);
1164 else
1165 dc.SetPen(m_toolbar_border_pen);
1166 if((state & wxRIBBON_TOOLBAR_TOOL_FIRST) == 0)
1167 {
1168 wxColour existing;
1169 if(!dc.GetPixel(rect.x, rect.y + 1, &existing) ||
1170 existing != m_toolbar_hover_borden_pen.GetColour())
1171 {
1172 dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
1173 }
1174 }
1175 if(is_custom_bg)
1176 {
1177 wxRect border_rect(bg_rect);
1178 border_rect.Inflate(1);
1179 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1180 dc.DrawRectangle(border_rect.x, border_rect.y, border_rect.width,
1181 border_rect.height);
1182 }
1183
1184 // Foreground
1185 int avail_width = bg_rect.GetWidth();
1186 if(kind & wxRIBBON_BUTTON_DROPDOWN)
1187 {
1188 avail_width -= 8;
1189 if(is_split_hybrid)
1190 {
1191 dc.DrawLine(rect.x + avail_width + 1, rect.y,
1192 rect.x + avail_width + 1, rect.y + rect.height);
1193 }
1194 dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
1195 bg_rect.y + (bg_rect.height / 2) - 2, true);
1196 }
1197 dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
1198 bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
1199 }
1200
1201 #endif // wxUSE_RIBBON