]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/art_aui.cpp
Add expand/collapse button to wxRibbonBar.
[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_gallery_border_pen = m_tab_border_pen;
248 m_gallery_item_border_pen = m_button_bar_hover_border_pen;
249 m_gallery_hover_background_brush = LikePrimary(1.2);
250 m_gallery_button_background_colour = m_page_hover_background_colour;
251 m_gallery_button_background_gradient_colour = m_page_hover_background_gradient_colour;
252 m_gallery_button_hover_background_brush = m_button_bar_hover_background_brush;
253 m_gallery_button_active_background_brush = m_button_bar_active_background_brush;
254 m_gallery_button_disabled_background_brush = primary_hsl.Desaturated(0.15f).ToRGB();
255 SetColour(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR, LikePrimary(0.1));
256 SetColour(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR, wxColour(128, 128, 128));
257 SetColour(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR, LikeSecondary(0.1));
258 SetColour(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR, LikeSecondary(0.1));
259 m_toolbar_border_pen = m_tab_border_pen;
260 SetColour(wxRIBBON_ART_TOOLBAR_FACE_COLOUR, LikePrimary(0.1));
261 m_tool_background_colour = m_page_hover_background_colour;
262 m_tool_background_gradient_colour = m_page_hover_background_gradient_colour;
263 m_toolbar_hover_borden_pen = m_button_bar_hover_border_pen;
264 m_tool_hover_background_brush = m_button_bar_hover_background_brush;
265 m_tool_active_background_brush = m_button_bar_active_background_brush;
266
267 #undef LikeSecondary
268 #undef LikePrimary
269 }
270
271 void wxRibbonAUIArtProvider::DrawTabCtrlBackground(
272 wxDC& dc,
273 wxWindow* WXUNUSED(wnd),
274 const wxRect& rect)
275 {
276 wxRect gradient_rect(rect);
277 gradient_rect.height--;
278 dc.GradientFillLinear(gradient_rect, m_tab_ctrl_background_colour,
279 m_tab_ctrl_background_gradient_colour, wxSOUTH);
280 dc.SetPen(m_tab_border_pen);
281 dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight()+1, rect.GetBottom());
282 }
283
284 int wxRibbonAUIArtProvider::GetTabCtrlHeight(
285 wxDC& dc,
286 wxWindow* WXUNUSED(wnd),
287 const wxRibbonPageTabInfoArray& pages)
288 {
289 int text_height = 0;
290 int icon_height = 0;
291
292 if(pages.GetCount() <= 1 && (m_flags & wxRIBBON_BAR_ALWAYS_SHOW_TABS) == 0)
293 {
294 // To preserve space, a single tab need not be displayed. We still need
295 // one pixel of border though.
296 return 1;
297 }
298
299 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
300 {
301 dc.SetFont(m_tab_active_label_font);
302 text_height = dc.GetTextExtent(wxT("ABCDEFXj")).GetHeight();
303 }
304 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
305 {
306 size_t numpages = pages.GetCount();
307 for(size_t i = 0; i < numpages; ++i)
308 {
309 const wxRibbonPageTabInfo& info = pages.Item(i);
310 if(info.page->GetIcon().IsOk())
311 {
312 icon_height = wxMax(icon_height, info.page->GetIcon().GetHeight());
313 }
314 }
315 }
316
317 return wxMax(text_height, icon_height) + 10;
318 }
319
320 void wxRibbonAUIArtProvider::DrawTab(wxDC& dc,
321 wxWindow* WXUNUSED(wnd),
322 const wxRibbonPageTabInfo& tab)
323 {
324 if(tab.rect.height <= 1)
325 return;
326
327 dc.SetFont(m_tab_label_font);
328 dc.SetPen(*wxTRANSPARENT_PEN);
329 if(tab.active || tab.hovered)
330 {
331 if(tab.active)
332 {
333 dc.SetFont(m_tab_active_label_font);
334 dc.SetBrush(m_background_brush);
335 dc.DrawRectangle(tab.rect.x, tab.rect.y + tab.rect.height - 1,
336 tab.rect.width - 1, 1);
337 }
338 wxRect grad_rect(tab.rect);
339 grad_rect.height -= 4;
340 grad_rect.width -= 1;
341 grad_rect.height /= 2;
342 grad_rect.y = grad_rect.y + tab.rect.height - grad_rect.height - 1;
343 dc.SetBrush(m_tab_active_top_background_brush);
344 dc.DrawRectangle(tab.rect.x, tab.rect.y + 3, tab.rect.width - 1,
345 grad_rect.y - tab.rect.y - 3);
346 dc.GradientFillLinear(grad_rect, m_tab_active_background_colour,
347 m_tab_active_background_gradient_colour, wxSOUTH);
348 }
349 else
350 {
351 wxRect btm_rect(tab.rect);
352 btm_rect.height -= 4;
353 btm_rect.width -= 1;
354 btm_rect.height /= 2;
355 btm_rect.y = btm_rect.y + tab.rect.height - btm_rect.height - 1;
356 dc.SetBrush(m_tab_hover_background_brush);
357 dc.DrawRectangle(btm_rect.x, btm_rect.y, btm_rect.width,
358 btm_rect.height);
359 wxRect grad_rect(tab.rect);
360 grad_rect.width -= 1;
361 grad_rect.y += 3;
362 grad_rect.height = btm_rect.y - grad_rect.y;
363 dc.GradientFillLinear(grad_rect, m_tab_hover_background_top_colour,
364 m_tab_hover_background_top_gradient_colour, wxSOUTH);
365 }
366
367 wxPoint border_points[5];
368 border_points[0] = wxPoint(0, 3);
369 border_points[1] = wxPoint(1, 2);
370 border_points[2] = wxPoint(tab.rect.width - 3, 2);
371 border_points[3] = wxPoint(tab.rect.width - 1, 4);
372 border_points[4] = wxPoint(tab.rect.width - 1, tab.rect.height - 1);
373
374 dc.SetPen(m_tab_border_pen);
375 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, tab.rect.x, tab.rect.y);
376
377 wxRect old_clip;
378 dc.GetClippingBox(old_clip);
379 bool is_first_tab = false;
380 wxRibbonBar* bar = wxDynamicCast(tab.page->GetParent(), wxRibbonBar);
381 if(bar && bar->GetPage(0) == tab.page)
382 is_first_tab = true;
383
384 wxBitmap icon;
385 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
386 {
387 icon = tab.page->GetIcon();
388 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) == 0)
389 {
390 if(icon.IsOk())
391 {
392 int x = tab.rect.x + (tab.rect.width - icon.GetWidth()) / 2;
393 dc.DrawBitmap(icon, x, tab.rect.y + 1 + (tab.rect.height - 1 -
394 icon.GetHeight()) / 2, true);
395 }
396 }
397 }
398 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
399 {
400 wxString label = tab.page->GetLabel();
401 if(!label.IsEmpty())
402 {
403 dc.SetTextForeground(m_tab_label_colour);
404 dc.SetBackgroundMode(wxTRANSPARENT);
405
406 int offset = 0;
407 if(icon.IsOk())
408 offset += icon.GetWidth() + 2;
409 int text_height;
410 int text_width;
411 dc.GetTextExtent(label, &text_width, &text_height);
412 int x = (tab.rect.width - 2 - text_width - offset) / 2;
413 if(x > 8)
414 x = 8;
415 else if(x < 1)
416 x = 1;
417 int width = tab.rect.width - x - 2;
418 x += tab.rect.x + offset;
419 int y = tab.rect.y + (tab.rect.height - text_height) / 2;
420 if(icon.IsOk())
421 {
422 dc.DrawBitmap(icon, x - offset, tab.rect.y + (tab.rect.height -
423 icon.GetHeight()) / 2, true);
424 }
425 dc.SetClippingRegion(x, tab.rect.y, width, tab.rect.height);
426 dc.DrawText(label, x, y);
427 }
428 }
429
430 // Draw the left hand edge of the tab only for the first tab (subsequent
431 // tabs use the right edge of the prior tab as their left edge). As this is
432 // outside the rectangle for the tab, only draw it if the leftmost part of
433 // the tab is within the clip rectangle (the clip region has to be cleared
434 // to draw outside the tab).
435 if(is_first_tab && old_clip.x <= tab.rect.x
436 && tab.rect.x < old_clip.x + old_clip.width)
437 {
438 dc.DestroyClippingRegion();
439 dc.DrawLine(tab.rect.x - 1, tab.rect.y + 4, tab.rect.x - 1,
440 tab.rect.y + tab.rect.height - 1);
441 }
442 }
443
444 void wxRibbonAUIArtProvider::GetBarTabWidth(
445 wxDC& dc,
446 wxWindow* WXUNUSED(wnd),
447 const wxString& label,
448 const wxBitmap& bitmap,
449 int* ideal,
450 int* small_begin_need_separator,
451 int* small_must_have_separator,
452 int* minimum)
453 {
454 int width = 0;
455 int min = 0;
456 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) && !label.IsEmpty())
457 {
458 dc.SetFont(m_tab_active_label_font);
459 width += dc.GetTextExtent(label).GetWidth();
460 min += wxMin(30, width); // enough for a few chars
461 if(bitmap.IsOk())
462 {
463 // gap between label and bitmap
464 width += 4;
465 min += 2;
466 }
467 }
468 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS) && bitmap.IsOk())
469 {
470 width += bitmap.GetWidth();
471 min += bitmap.GetWidth();
472 }
473
474 if(ideal != NULL)
475 {
476 *ideal = width + 16;
477 }
478 if(small_begin_need_separator != NULL)
479 {
480 *small_begin_need_separator = min;
481 }
482 if(small_must_have_separator != NULL)
483 {
484 *small_must_have_separator = min;
485 }
486 if(minimum != NULL)
487 {
488 *minimum = min;
489 }
490 }
491
492 void wxRibbonAUIArtProvider::DrawTabSeparator(
493 wxDC& WXUNUSED(dc),
494 wxWindow* WXUNUSED(wnd),
495 const wxRect& WXUNUSED(rect),
496 double WXUNUSED(visibility))
497 {
498 // No explicit separators between tabs
499 }
500
501 void wxRibbonAUIArtProvider::DrawPageBackground(
502 wxDC& dc,
503 wxWindow* WXUNUSED(wnd),
504 const wxRect& rect)
505 {
506 dc.SetPen(*wxTRANSPARENT_PEN);
507 dc.SetBrush(m_background_brush);
508 dc.DrawRectangle(rect.x + 1, rect.y, rect.width - 2, rect.height - 1);
509
510 dc.SetPen(m_page_border_pen);
511 dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
512 dc.DrawLine(rect.GetRight(), rect.y, rect.GetRight(), rect.y +rect.height);
513 dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight()+1, rect.GetBottom());
514 }
515
516 wxSize wxRibbonAUIArtProvider::GetScrollButtonMinimumSize(
517 wxDC& WXUNUSED(dc),
518 wxWindow* WXUNUSED(wnd),
519 long WXUNUSED(style))
520 {
521 return wxSize(11, 11);
522 }
523
524 void wxRibbonAUIArtProvider::DrawScrollButton(
525 wxDC& dc,
526 wxWindow* WXUNUSED(wnd),
527 const wxRect& rect,
528 long style)
529 {
530 wxRect true_rect(rect);
531 wxPoint arrow_points[3];
532
533 if((style & wxRIBBON_SCROLL_BTN_FOR_MASK) == wxRIBBON_SCROLL_BTN_FOR_TABS)
534 {
535 true_rect.y += 2;
536 true_rect.height -= 2;
537 dc.SetPen(m_tab_border_pen);
538 }
539 else
540 {
541 dc.SetPen(*wxTRANSPARENT_PEN);
542 dc.SetBrush(m_background_brush);
543 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
544 dc.SetPen(m_page_border_pen);
545 }
546
547 switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK)
548 {
549 case wxRIBBON_SCROLL_BTN_LEFT:
550 dc.DrawLine(true_rect.GetRight(), true_rect.y, true_rect.GetRight(),
551 true_rect.y + true_rect.height);
552 arrow_points[0] = wxPoint(rect.width / 2 - 2, rect.height / 2);
553 arrow_points[1] = arrow_points[0] + wxPoint(5, -5);
554 arrow_points[2] = arrow_points[0] + wxPoint(5, 5);
555 break;
556 case wxRIBBON_SCROLL_BTN_RIGHT:
557 dc.DrawLine(true_rect.x, true_rect.y, true_rect.x,
558 true_rect.y + true_rect.height);
559 arrow_points[0] = wxPoint(rect.width / 2 + 3, rect.height / 2);
560 arrow_points[1] = arrow_points[0] - wxPoint(5, -5);
561 arrow_points[2] = arrow_points[0] - wxPoint(5, 5);
562 break;
563 case wxRIBBON_SCROLL_BTN_DOWN:
564 dc.DrawLine(true_rect.x, true_rect.y, true_rect.x + true_rect.width,
565 true_rect.y);
566 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 + 3);
567 arrow_points[1] = arrow_points[0] - wxPoint( 5, 5);
568 arrow_points[2] = arrow_points[0] - wxPoint(-5, 5);
569 break;
570 case wxRIBBON_SCROLL_BTN_UP:
571 dc.DrawLine(true_rect.x, true_rect.GetBottom(),
572 true_rect.x + true_rect.width, true_rect.GetBottom());
573 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 - 2);
574 arrow_points[1] = arrow_points[0] + wxPoint( 5, 5);
575 arrow_points[2] = arrow_points[0] + wxPoint(-5, 5);
576 break;
577 default:
578 return;
579 }
580
581 int x = rect.x;
582 int y = rect.y;
583 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
584 {
585 ++x;
586 ++y;
587 }
588
589 dc.SetPen(*wxTRANSPARENT_PEN);
590 wxBrush B(m_tab_label_colour);
591 dc.SetBrush(B);
592 dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, x, y);
593 }
594
595 wxSize wxRibbonAUIArtProvider::GetPanelSize(
596 wxDC& dc,
597 const wxRibbonPanel* wnd,
598 wxSize client_size,
599 wxPoint* client_offset)
600 {
601 dc.SetFont(m_panel_label_font);
602 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
603 int label_height = label_size.GetHeight() + 5;
604 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
605 {
606 client_size.IncBy(4, label_height + 6);
607 if(client_offset)
608 *client_offset = wxPoint(2, label_height + 3);
609 }
610 else
611 {
612 client_size.IncBy(6, label_height + 4);
613 if(client_offset)
614 *client_offset = wxPoint(3, label_height + 2);
615 }
616 return client_size;
617 }
618
619 wxSize wxRibbonAUIArtProvider::GetPanelClientSize(
620 wxDC& dc,
621 const wxRibbonPanel* wnd,
622 wxSize size,
623 wxPoint* client_offset)
624 {
625 dc.SetFont(m_panel_label_font);
626 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
627 int label_height = label_size.GetHeight() + 5;
628 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
629 {
630 size.DecBy(4, label_height + 6);
631 if(client_offset)
632 *client_offset = wxPoint(2, label_height + 3);
633 }
634 else
635 {
636 size.DecBy(6, label_height + 4);
637 if(client_offset)
638 *client_offset = wxPoint(3, label_height + 2);
639 }
640 if (size.x < 0) size.x = 0;
641 if (size.y < 0) size.y = 0;
642 return size;
643 }
644
645 wxRect wxRibbonAUIArtProvider::GetPanelExtButtonArea(wxDC& dc,
646 const wxRibbonPanel* wnd,
647 wxRect rect)
648 {
649 wxRect true_rect(rect);
650 RemovePanelPadding(&true_rect);
651
652 true_rect.x++;
653 true_rect.width -= 2;
654 true_rect.y++;
655
656 dc.SetFont(m_panel_label_font);
657 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
658 int label_height = label_size.GetHeight() + 5;
659 wxRect label_rect(true_rect);
660 label_rect.height = label_height - 1;
661
662 rect = wxRect(label_rect.GetRight()-13, label_rect.GetBottom()-13, 13, 13);
663 return rect;
664 }
665
666 void wxRibbonAUIArtProvider::DrawPanelBackground(
667 wxDC& dc,
668 wxRibbonPanel* wnd,
669 const wxRect& rect)
670 {
671 dc.SetPen(*wxTRANSPARENT_PEN);
672 dc.SetBrush(m_background_brush);
673 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
674
675 wxRect true_rect(rect);
676 RemovePanelPadding(&true_rect);
677
678 dc.SetPen(m_panel_border_pen);
679 dc.SetBrush(*wxTRANSPARENT_BRUSH);
680 dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);
681
682 true_rect.x++;
683 true_rect.width -= 2;
684 true_rect.y++;
685
686 dc.SetFont(m_panel_label_font);
687 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
688 int label_height = label_size.GetHeight() + 5;
689 wxRect label_rect(true_rect);
690 label_rect.height = label_height - 1;
691 dc.DrawLine(label_rect.x, label_rect.y + label_rect.height,
692 label_rect.x + label_rect.width, label_rect.y + label_rect.height);
693
694 wxColour label_bg_colour = m_panel_label_background_colour;
695 wxColour label_bg_grad_colour = m_panel_label_background_gradient_colour;
696 if(wnd->IsHovered())
697 {
698 label_bg_colour = m_panel_hover_label_background_colour;
699 label_bg_grad_colour = m_panel_hover_label_background_gradient_colour;
700 dc.SetTextForeground(m_panel_hover_label_colour);
701 }
702 else
703 {
704 dc.SetTextForeground(m_panel_label_colour);
705 }
706 dc.GradientFillLinear(label_rect,
707 #ifdef __WXMAC__
708 label_bg_grad_colour, label_bg_colour, wxSOUTH);
709 #else
710 label_bg_colour, label_bg_grad_colour, wxSOUTH);
711 #endif
712 dc.SetFont(m_panel_label_font);
713 dc.DrawText(wnd->GetLabel(), label_rect.x + 3, label_rect.y + 2);
714
715 if(wnd->IsHovered())
716 {
717 wxRect gradient_rect(true_rect);
718 gradient_rect.y += label_rect.height + 1;
719 gradient_rect.height = true_rect.height - label_rect.height - 3;
720 #ifdef __WXMAC__
721 wxColour colour = m_page_hover_background_gradient_colour;
722 wxColour gradient = m_page_hover_background_colour;
723 #else
724 wxColour colour = m_page_hover_background_colour;
725 wxColour gradient = m_page_hover_background_gradient_colour;
726 #endif
727 dc.GradientFillLinear(gradient_rect, colour, gradient, wxSOUTH);
728 }
729
730 if(wnd->HasExtButton())
731 {
732 if(wnd->IsExtButtonHovered())
733 {
734 dc.SetPen(m_panel_hover_button_border_pen);
735 dc.SetBrush(m_panel_hover_button_background_brush);
736 dc.DrawRoundedRectangle(label_rect.GetRight() - 13, label_rect.GetBottom() - 13, 13, 13, 1.0);
737 dc.DrawBitmap(m_panel_extension_bitmap[1], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
738 }
739 else
740 dc.DrawBitmap(m_panel_extension_bitmap[0], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
741 }
742 }
743
744 void wxRibbonAUIArtProvider::DrawMinimisedPanel(
745 wxDC& dc,
746 wxRibbonPanel* wnd,
747 const wxRect& rect,
748 wxBitmap& bitmap)
749 {
750 dc.SetPen(*wxTRANSPARENT_PEN);
751 dc.SetBrush(m_background_brush);
752 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
753
754 wxRect true_rect(rect);
755 RemovePanelPadding(&true_rect);
756
757 dc.SetPen(m_panel_border_pen);
758 dc.SetBrush(*wxTRANSPARENT_BRUSH);
759 dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);
760 true_rect.Deflate(1);
761
762 if(wnd->IsHovered() || wnd->GetExpandedPanel())
763 {
764 wxColour colour = m_page_hover_background_colour;
765 wxColour gradient = m_page_hover_background_gradient_colour;
766 #ifdef __WXMAC__
767 if(!wnd->GetExpandedPanel())
768 #else
769 if(wnd->GetExpandedPanel())
770 #endif
771 {
772 wxColour temp = colour;
773 colour = gradient;
774 gradient = temp;
775 }
776 dc.GradientFillLinear(true_rect, colour, gradient, wxSOUTH);
777 }
778
779 wxRect preview;
780 DrawMinimisedPanelCommon(dc, wnd, true_rect, &preview);
781
782 dc.SetPen(m_panel_border_pen);
783 dc.SetBrush(*wxTRANSPARENT_BRUSH);
784 dc.DrawRectangle(preview.x, preview.y, preview.width, preview.height);
785 preview.Deflate(1);
786 wxRect preview_caption_rect(preview);
787 preview_caption_rect.height = 7;
788 preview.y += preview_caption_rect.height;
789 preview.height -= preview_caption_rect.height;
790 #ifdef __WXMAC__
791 dc.GradientFillLinear(preview_caption_rect,
792 m_panel_hover_label_background_gradient_colour,
793 m_panel_hover_label_background_colour, wxSOUTH);
794 dc.GradientFillLinear(preview,
795 m_page_hover_background_gradient_colour,
796 m_page_hover_background_colour, wxSOUTH);
797 #else
798 dc.GradientFillLinear(preview_caption_rect,
799 m_panel_hover_label_background_colour,
800 m_panel_hover_label_background_gradient_colour, wxSOUTH);
801 dc.GradientFillLinear(preview,
802 m_page_hover_background_colour,
803 m_page_hover_background_gradient_colour, wxSOUTH);
804 #endif
805
806 if(bitmap.IsOk())
807 {
808 dc.DrawBitmap(bitmap, preview.x + (preview.width - bitmap.GetWidth()) / 2,
809 preview.y + (preview.height - bitmap.GetHeight()) / 2, true);
810 }
811 }
812
813 void wxRibbonAUIArtProvider::DrawPartialPanelBackground(wxDC& dc,
814 wxWindow* wnd, const wxRect& rect)
815 {
816 dc.SetPen(*wxTRANSPARENT_PEN);
817 dc.SetBrush(m_background_brush);
818 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
819
820 wxPoint offset(wnd->GetPosition());
821 wxWindow* parent = wnd->GetParent();
822 wxRibbonPanel* panel = NULL;
823
824 for(; parent; parent = parent->GetParent())
825 {
826 panel = wxDynamicCast(parent, wxRibbonPanel);
827 if(panel != NULL)
828 {
829 if(!panel->IsHovered())
830 return;
831 break;
832 }
833 offset += parent->GetPosition();
834 }
835 if(panel == NULL)
836 return;
837
838 wxRect background(panel->GetSize());
839 RemovePanelPadding(&background);
840 background.x++;
841 background.width -= 2;
842 dc.SetFont(m_panel_label_font);
843 int caption_height = dc.GetTextExtent(panel->GetLabel()).GetHeight() + 7;
844 background.y += caption_height - 1;
845 background.height -= caption_height;
846
847 wxRect paint_rect(rect);
848 paint_rect.x += offset.x;
849 paint_rect.y += offset.y;
850
851 wxColour bg_clr, bg_grad_clr;
852 #ifdef __WXMAC__
853 bg_grad_clr = m_page_hover_background_colour;
854 bg_clr = m_page_hover_background_gradient_colour;
855 #else
856 bg_clr = m_page_hover_background_colour;
857 bg_grad_clr = m_page_hover_background_gradient_colour;
858 #endif
859
860 paint_rect.Intersect(background);
861 if(!paint_rect.IsEmpty())
862 {
863 wxColour starting_colour(wxRibbonInterpolateColour(bg_clr, bg_grad_clr,
864 paint_rect.y, background.y, background.y + background.height));
865 wxColour ending_colour(wxRibbonInterpolateColour(bg_clr, bg_grad_clr,
866 paint_rect.y + paint_rect.height, background.y,
867 background.y + background.height));
868 paint_rect.x -= offset.x;
869 paint_rect.y -= offset.y;
870 dc.GradientFillLinear(paint_rect, starting_colour, ending_colour
871 , wxSOUTH);
872 }
873 }
874
875 void wxRibbonAUIArtProvider::DrawGalleryBackground(
876 wxDC& dc,
877 wxRibbonGallery* wnd,
878 const wxRect& rect)
879 {
880 DrawPartialPanelBackground(dc, wnd, rect);
881
882 if(wnd->IsHovered())
883 {
884 dc.SetPen(*wxTRANSPARENT_PEN);
885 dc.SetBrush(m_gallery_hover_background_brush);
886 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
887 {
888 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 2,
889 rect.height - 16);
890 }
891 else
892 {
893 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 16,
894 rect.height - 2);
895 }
896 }
897
898 dc.SetPen(m_gallery_border_pen);
899 dc.SetBrush(*wxTRANSPARENT_BRUSH);
900 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
901
902 DrawGalleryBackgroundCommon(dc, wnd, rect);
903 }
904
905 void wxRibbonAUIArtProvider::DrawGalleryButton(wxDC& dc, wxRect rect,
906 wxRibbonGalleryButtonState state, wxBitmap* bitmaps)
907 {
908 int extra_height = 0;
909 int extra_width = 0;
910 wxRect reduced_rect(rect);
911 reduced_rect.Deflate(1);
912 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
913 {
914 reduced_rect.width++;
915 extra_width = 1;
916 }
917 else
918 {
919 reduced_rect.height++;
920 extra_height = 1;
921 }
922
923 wxBitmap btn_bitmap;
924 switch(state)
925 {
926 case wxRIBBON_GALLERY_BUTTON_NORMAL:
927 dc.GradientFillLinear(reduced_rect,
928 m_gallery_button_background_colour,
929 m_gallery_button_background_gradient_colour, wxSOUTH);
930 btn_bitmap = bitmaps[0];
931 break;
932 case wxRIBBON_GALLERY_BUTTON_HOVERED:
933 dc.SetPen(m_gallery_item_border_pen);
934 dc.SetBrush(m_gallery_button_hover_background_brush);
935 dc.DrawRectangle(rect.x, rect.y, rect.width + extra_width,
936 rect.height + extra_height);
937 btn_bitmap = bitmaps[1];
938 break;
939 case wxRIBBON_GALLERY_BUTTON_ACTIVE:
940 dc.SetPen(m_gallery_item_border_pen);
941 dc.SetBrush(m_gallery_button_active_background_brush);
942 dc.DrawRectangle(rect.x, rect.y, rect.width + extra_width,
943 rect.height + extra_height);
944 btn_bitmap = bitmaps[2];
945 break;
946 case wxRIBBON_GALLERY_BUTTON_DISABLED:
947 dc.SetPen(*wxTRANSPARENT_PEN);
948 dc.SetBrush(m_gallery_button_disabled_background_brush);
949 dc.DrawRectangle(reduced_rect.x, reduced_rect.y, reduced_rect.width,
950 reduced_rect.height);
951 btn_bitmap = bitmaps[3];
952 break;
953 }
954
955 dc.DrawBitmap(btn_bitmap, reduced_rect.x + reduced_rect.width / 2 - 2,
956 (rect.y + rect.height / 2) - 2, true);
957 }
958
959 void wxRibbonAUIArtProvider::DrawGalleryItemBackground(
960 wxDC& dc,
961 wxRibbonGallery* wnd,
962 const wxRect& rect,
963 wxRibbonGalleryItem* item)
964 {
965 if(wnd->GetHoveredItem() != item && wnd->GetActiveItem() != item &&
966 wnd->GetSelection() != item)
967 return;
968
969 dc.SetPen(m_gallery_item_border_pen);
970 if(wnd->GetActiveItem() == item || wnd->GetSelection() == item)
971 dc.SetBrush(m_gallery_button_active_background_brush);
972 else
973 dc.SetBrush(m_gallery_button_hover_background_brush);
974
975 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
976 }
977
978 void wxRibbonAUIArtProvider::DrawButtonBarBackground(
979 wxDC& dc,
980 wxWindow* wnd,
981 const wxRect& rect)
982 {
983 DrawPartialPanelBackground(dc, wnd, rect);
984 }
985
986 void wxRibbonAUIArtProvider::DrawButtonBarButton(
987 wxDC& dc,
988 wxWindow* WXUNUSED(wnd),
989 const wxRect& rect,
990 wxRibbonButtonKind kind,
991 long state,
992 const wxString& label,
993 const wxBitmap& bitmap_large,
994 const wxBitmap& bitmap_small)
995 {
996 if(kind == wxRIBBON_BUTTON_TOGGLE)
997 {
998 kind = wxRIBBON_BUTTON_NORMAL;
999 if(state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
1000 state ^= wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK;
1001 }
1002
1003 if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
1004 | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
1005 {
1006 dc.SetPen(m_button_bar_hover_border_pen);
1007
1008 wxRect bg_rect(rect);
1009 bg_rect.Deflate(1);
1010
1011 if(kind == wxRIBBON_BUTTON_HYBRID)
1012 {
1013 switch(state & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
1014 {
1015 case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
1016 {
1017 int iYBorder = rect.y + bitmap_large.GetHeight() + 4;
1018 wxRect partial_bg(rect);
1019 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
1020 {
1021 partial_bg.SetBottom(iYBorder - 1);
1022 }
1023 else
1024 {
1025 partial_bg.height -= (iYBorder - partial_bg.y + 1);
1026 partial_bg.y = iYBorder + 1;
1027 }
1028 dc.DrawLine(rect.x, iYBorder, rect.x + rect.width, iYBorder);
1029 bg_rect.Intersect(partial_bg);
1030 }
1031 break;
1032 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
1033 {
1034 int iArrowWidth = 9;
1035 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
1036 {
1037 bg_rect.width -= iArrowWidth;
1038 dc.DrawLine(bg_rect.x + bg_rect.width,
1039 rect.y, bg_rect.x + bg_rect.width,
1040 rect.y + rect.height);
1041 }
1042 else
1043 {
1044 --iArrowWidth;
1045 bg_rect.x += bg_rect.width - iArrowWidth;
1046 bg_rect.width = iArrowWidth;
1047 dc.DrawLine(bg_rect.x - 1, rect.y,
1048 bg_rect.x - 1, rect.y + rect.height);
1049 }
1050 }
1051 break;
1052 case wxRIBBON_BUTTONBAR_BUTTON_SMALL:
1053 break;
1054 }
1055 }
1056
1057 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1058 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
1059
1060 dc.SetPen(*wxTRANSPARENT_PEN);
1061 if(state & wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK)
1062 dc.SetBrush(m_button_bar_active_background_brush);
1063 else
1064 dc.SetBrush(m_button_bar_hover_background_brush);
1065 dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
1066 }
1067
1068 dc.SetFont(m_button_bar_label_font);
1069 dc.SetTextForeground(m_button_bar_label_colour);
1070 DrawButtonBarButtonForeground(dc, rect, kind, state, label, bitmap_large,
1071 bitmap_small);
1072 }
1073
1074 void wxRibbonAUIArtProvider::DrawToolBarBackground(
1075 wxDC& dc,
1076 wxWindow* wnd,
1077 const wxRect& rect)
1078 {
1079 DrawPartialPanelBackground(dc, wnd, rect);
1080 }
1081
1082 void wxRibbonAUIArtProvider::DrawToolGroupBackground(
1083 wxDC& dc,
1084 wxWindow* WXUNUSED(wnd),
1085 const wxRect& rect)
1086 {
1087 dc.SetPen(m_toolbar_border_pen);
1088 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1089 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
1090 wxRect bg_rect(rect);
1091 bg_rect.Deflate(1);
1092 dc.GradientFillLinear(bg_rect, m_tool_background_colour,
1093 m_tool_background_gradient_colour, wxSOUTH);
1094 }
1095
1096 void wxRibbonAUIArtProvider::DrawTool(
1097 wxDC& dc,
1098 wxWindow* WXUNUSED(wnd),
1099 const wxRect& rect,
1100 const wxBitmap& bitmap,
1101 wxRibbonButtonKind kind,
1102 long state)
1103 {
1104 if(kind == wxRIBBON_BUTTON_TOGGLE)
1105 {
1106 if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED)
1107 state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
1108 }
1109
1110 wxRect bg_rect(rect);
1111 bg_rect.Deflate(1);
1112 if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
1113 bg_rect.width++;
1114 bool is_custom_bg = (state & (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK |
1115 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)) != 0;
1116 bool is_split_hybrid = kind == wxRIBBON_BUTTON_HYBRID && is_custom_bg;
1117
1118 // Background
1119 if(is_custom_bg)
1120 {
1121 dc.SetPen(*wxTRANSPARENT_PEN);
1122 dc.SetBrush(m_tool_hover_background_brush);
1123 dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
1124 if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
1125 {
1126 wxRect active_rect(bg_rect);
1127 if(kind == wxRIBBON_BUTTON_HYBRID)
1128 {
1129 active_rect.width -= 8;
1130 if(state & wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE)
1131 {
1132 active_rect.x += active_rect.width;
1133 active_rect.width = 8;
1134 }
1135 }
1136 dc.SetBrush(m_tool_active_background_brush);
1137 dc.DrawRectangle(active_rect.x, active_rect.y, active_rect.width,
1138 active_rect.height);
1139 }
1140 }
1141
1142 // Border
1143 if(is_custom_bg)
1144 dc.SetPen(m_toolbar_hover_borden_pen);
1145 else
1146 dc.SetPen(m_toolbar_border_pen);
1147 if((state & wxRIBBON_TOOLBAR_TOOL_FIRST) == 0)
1148 {
1149 wxColour existing;
1150 if(!dc.GetPixel(rect.x, rect.y + 1, &existing) ||
1151 existing != m_toolbar_hover_borden_pen.GetColour())
1152 {
1153 dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
1154 }
1155 }
1156 if(is_custom_bg)
1157 {
1158 wxRect border_rect(bg_rect);
1159 border_rect.Inflate(1);
1160 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1161 dc.DrawRectangle(border_rect.x, border_rect.y, border_rect.width,
1162 border_rect.height);
1163 }
1164
1165 // Foreground
1166 int avail_width = bg_rect.GetWidth();
1167 if(kind & wxRIBBON_BUTTON_DROPDOWN)
1168 {
1169 avail_width -= 8;
1170 if(is_split_hybrid)
1171 {
1172 dc.DrawLine(rect.x + avail_width + 1, rect.y,
1173 rect.x + avail_width + 1, rect.y + rect.height);
1174 }
1175 dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
1176 bg_rect.y + (bg_rect.height / 2) - 2, true);
1177 }
1178 dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
1179 bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
1180 }
1181
1182 #endif // wxUSE_RIBBON