1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/art_aui.cpp
3 // Purpose: AUI style art provider for ribbon interface
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
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"
29 #include "wx/settings.h"
33 #include "wx/msw/private.h"
34 #elif defined(__WXMAC__)
35 #include "wx/osx/private.h"
36 // only for kThemeBrushToolbarBackground
37 #include <Carbon/Carbon.h>
40 wxRibbonAUIArtProvider::wxRibbonAUIArtProvider()
41 : wxRibbonMSWArtProvider(false)
43 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
44 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
46 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
49 SetColourScheme(base_colour
,
50 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
51 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
53 m_tab_active_label_font
= m_tab_label_font
;
54 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
56 m_page_border_left
= 1;
57 m_page_border_right
= 1;
58 m_page_border_top
= 1;
59 m_page_border_bottom
= 2;
60 m_tab_separation_size
= 0;
62 m_gallery_bitmap_padding_left_size
= 3;
63 m_gallery_bitmap_padding_right_size
= 3;
64 m_gallery_bitmap_padding_top_size
= 3;
65 m_gallery_bitmap_padding_bottom_size
= 3;
68 wxRibbonAUIArtProvider::~wxRibbonAUIArtProvider()
72 wxRibbonArtProvider
* wxRibbonAUIArtProvider::Clone() const
74 wxRibbonAUIArtProvider
*copy
= new wxRibbonAUIArtProvider();
77 copy
->m_tab_ctrl_background_colour
= m_tab_ctrl_background_colour
;
78 copy
->m_tab_ctrl_background_gradient_colour
= m_tab_ctrl_background_gradient_colour
;
79 copy
->m_panel_label_background_colour
= m_panel_label_background_colour
;
80 copy
->m_panel_label_background_gradient_colour
= m_panel_label_background_gradient_colour
;
81 copy
->m_panel_hover_label_background_colour
= m_panel_hover_label_background_colour
;
82 copy
->m_panel_hover_label_background_gradient_colour
= m_panel_hover_label_background_gradient_colour
;
84 copy
->m_background_brush
= m_background_brush
;
85 copy
->m_tab_active_top_background_brush
= m_tab_active_top_background_brush
;
86 copy
->m_tab_hover_background_brush
= m_tab_hover_background_brush
;
87 copy
->m_button_bar_hover_background_brush
= m_button_bar_hover_background_brush
;
88 copy
->m_button_bar_active_background_brush
= m_button_bar_active_background_brush
;
89 copy
->m_gallery_button_active_background_brush
= m_gallery_button_active_background_brush
;
90 copy
->m_gallery_button_hover_background_brush
= m_gallery_button_hover_background_brush
;
91 copy
->m_gallery_button_disabled_background_brush
= m_gallery_button_disabled_background_brush
;
93 copy
->m_toolbar_hover_borden_pen
= m_toolbar_hover_borden_pen
;
94 copy
->m_tool_hover_background_brush
= m_tool_hover_background_brush
;
95 copy
->m_tool_active_background_brush
= m_tool_active_background_brush
;
100 void wxRibbonAUIArtProvider::SetFont(int id
, const wxFont
& font
)
102 wxRibbonMSWArtProvider::SetFont(id
, font
);
103 if(id
== wxRIBBON_ART_TAB_LABEL_FONT
)
105 m_tab_active_label_font
= m_tab_label_font
;
106 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
110 wxColour
wxRibbonAUIArtProvider::GetColour(int id
) const
114 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
115 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
116 return m_background_brush
.GetColour();
117 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
118 return m_tab_ctrl_background_colour
;
119 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
120 return m_tab_ctrl_background_gradient_colour
;
121 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
122 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
123 return m_tab_active_top_background_brush
.GetColour();
124 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
125 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
126 return m_tab_hover_background_brush
.GetColour();
127 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
128 return m_panel_label_background_colour
;
129 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
130 return m_panel_label_background_gradient_colour
;
131 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR
:
132 return m_panel_hover_label_background_colour
;
133 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR
:
134 return m_panel_hover_label_background_gradient_colour
;
135 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
136 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
137 return m_button_bar_hover_background_brush
.GetColour();
138 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
139 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
140 return m_gallery_button_hover_background_brush
.GetColour();
141 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
142 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
143 return m_gallery_button_active_background_brush
.GetColour();
144 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
145 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
146 return m_gallery_button_disabled_background_brush
.GetColour();
148 return wxRibbonMSWArtProvider::GetColour(id
);
152 void wxRibbonAUIArtProvider::SetColour(int id
, const wxColor
& colour
)
156 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
157 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
158 m_background_brush
.SetColour(colour
);
160 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
161 m_tab_ctrl_background_colour
= colour
;
163 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
164 m_tab_ctrl_background_gradient_colour
= colour
;
166 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
167 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
168 m_tab_active_top_background_brush
.SetColour(colour
);
170 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
171 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
172 m_tab_hover_background_brush
.SetColour(colour
);
174 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
175 m_panel_label_background_colour
= colour
;
177 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
178 m_panel_label_background_gradient_colour
= colour
;
180 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
181 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
182 m_button_bar_hover_background_brush
.SetColour(colour
);
184 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
185 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
186 m_gallery_button_hover_background_brush
.SetColour(colour
);
188 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
189 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
190 m_gallery_button_active_background_brush
.SetColour(colour
);
192 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
193 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
194 m_gallery_button_disabled_background_brush
.SetColour(colour
);
197 wxRibbonMSWArtProvider::SetColour(id
, colour
);
202 void wxRibbonAUIArtProvider::SetColourScheme(
203 const wxColour
& primary
,
204 const wxColour
& secondary
,
205 const wxColour
& tertiary
)
207 wxRibbonHSLColour
primary_hsl(primary
);
208 wxRibbonHSLColour
secondary_hsl(secondary
);
209 wxRibbonHSLColour
tertiary_hsl(tertiary
);
211 // Map primary & secondary luminance from [0, 1] to [0.15, 0.85]
212 primary_hsl
.luminance
= cos(primary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
213 secondary_hsl
.luminance
= cos(secondary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
215 // TODO: Remove next line once this provider stops piggybacking MSW
216 wxRibbonMSWArtProvider::SetColourScheme(primary
, secondary
, tertiary
);
218 #define LikePrimary(luminance) \
219 wxRibbonShiftLuminance(primary_hsl, luminance ## f).ToRGB()
220 #define LikeSecondary(luminance) \
221 wxRibbonShiftLuminance(secondary_hsl, luminance ## f).ToRGB()
223 m_tab_ctrl_background_colour
= LikePrimary(0.9);
224 m_tab_ctrl_background_gradient_colour
= LikePrimary(1.7);
225 m_tab_border_pen
= LikePrimary(0.75);
226 m_tab_label_colour
= LikePrimary(0.1);
227 m_tab_hover_background_top_colour
= primary_hsl
.ToRGB();
228 m_tab_hover_background_top_gradient_colour
= LikePrimary(1.6);
229 m_tab_hover_background_brush
= m_tab_hover_background_top_colour
;
230 m_tab_active_background_colour
= m_tab_ctrl_background_gradient_colour
;
231 m_tab_active_background_gradient_colour
= primary_hsl
.ToRGB();
232 m_tab_active_top_background_brush
= m_tab_active_background_colour
;
233 m_panel_label_colour
= m_tab_label_colour
;
234 m_panel_minimised_label_colour
= m_panel_label_colour
;
235 m_panel_hover_label_colour
= tertiary_hsl
.ToRGB();
236 m_page_border_pen
= m_tab_border_pen
;
237 m_panel_border_pen
= m_tab_border_pen
;
238 m_background_brush
= primary_hsl
.ToRGB();
239 m_page_hover_background_colour
= LikePrimary(1.5);
240 m_page_hover_background_gradient_colour
= LikePrimary(0.9);
241 m_panel_label_background_colour
= LikePrimary(0.85);
242 m_panel_label_background_gradient_colour
= LikePrimary(0.97);
243 m_panel_hover_label_background_gradient_colour
= secondary_hsl
.ToRGB();
244 m_panel_hover_label_background_colour
= secondary_hsl
.Lighter(0.2f
).ToRGB();
245 m_button_bar_hover_border_pen
= secondary_hsl
.ToRGB();
246 m_button_bar_hover_background_brush
= LikeSecondary(1.7);
247 m_button_bar_active_background_brush
= LikeSecondary(1.4);
248 m_button_bar_label_colour
= m_tab_label_colour
;
249 m_gallery_border_pen
= m_tab_border_pen
;
250 m_gallery_item_border_pen
= m_button_bar_hover_border_pen
;
251 m_gallery_hover_background_brush
= LikePrimary(1.2);
252 m_gallery_button_background_colour
= m_page_hover_background_colour
;
253 m_gallery_button_background_gradient_colour
= m_page_hover_background_gradient_colour
;
254 m_gallery_button_hover_background_brush
= m_button_bar_hover_background_brush
;
255 m_gallery_button_active_background_brush
= m_button_bar_active_background_brush
;
256 m_gallery_button_disabled_background_brush
= primary_hsl
.Desaturated(0.15f
).ToRGB();
257 SetColour(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR
, LikePrimary(0.1));
258 SetColour(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR
, wxColour(128, 128, 128));
259 SetColour(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR
, LikeSecondary(0.1));
260 SetColour(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR
, LikeSecondary(0.1));
261 m_toolbar_border_pen
= m_tab_border_pen
;
262 SetColour(wxRIBBON_ART_TOOLBAR_FACE_COLOUR
, LikePrimary(0.1));
263 m_tool_background_colour
= m_page_hover_background_colour
;
264 m_tool_background_gradient_colour
= m_page_hover_background_gradient_colour
;
265 m_toolbar_hover_borden_pen
= m_button_bar_hover_border_pen
;
266 m_tool_hover_background_brush
= m_button_bar_hover_background_brush
;
267 m_tool_active_background_brush
= m_button_bar_active_background_brush
;
273 void wxRibbonAUIArtProvider::DrawTabCtrlBackground(
275 wxWindow
* WXUNUSED(wnd
),
278 wxRect
gradient_rect(rect
);
279 gradient_rect
.height
--;
280 dc
.GradientFillLinear(gradient_rect
, m_tab_ctrl_background_colour
,
281 m_tab_ctrl_background_gradient_colour
, wxSOUTH
);
282 dc
.SetPen(m_tab_border_pen
);
283 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight()+1, rect
.GetBottom());
286 int wxRibbonAUIArtProvider::GetTabCtrlHeight(
288 wxWindow
* WXUNUSED(wnd
),
289 const wxRibbonPageTabInfoArray
& pages
)
294 if(pages
.GetCount() <= 1 && (m_flags
& wxRIBBON_BAR_ALWAYS_SHOW_TABS
) == 0)
296 // To preserve space, a single tab need not be displayed. We still need
297 // one pixel of border though.
301 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
303 dc
.SetFont(m_tab_active_label_font
);
304 text_height
= dc
.GetTextExtent(wxT("ABCDEFXj")).GetHeight();
306 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
308 size_t numpages
= pages
.GetCount();
309 for(size_t i
= 0; i
< numpages
; ++i
)
311 const wxRibbonPageTabInfo
& info
= pages
.Item(i
);
312 if(info
.page
->GetIcon().IsOk())
314 icon_height
= wxMax(icon_height
, info
.page
->GetIcon().GetHeight());
319 return wxMax(text_height
, icon_height
) + 10;
322 void wxRibbonAUIArtProvider::DrawTab(wxDC
& dc
,
323 wxWindow
* WXUNUSED(wnd
),
324 const wxRibbonPageTabInfo
& tab
)
326 if(tab
.rect
.height
<= 1)
329 dc
.SetFont(m_tab_label_font
);
330 dc
.SetPen(*wxTRANSPARENT_PEN
);
331 if(tab
.active
|| tab
.hovered
)
335 dc
.SetFont(m_tab_active_label_font
);
336 dc
.SetBrush(m_background_brush
);
337 dc
.DrawRectangle(tab
.rect
.x
, tab
.rect
.y
+ tab
.rect
.height
- 1,
338 tab
.rect
.width
- 1, 1);
340 wxRect
grad_rect(tab
.rect
);
341 grad_rect
.height
-= 4;
342 grad_rect
.width
-= 1;
343 grad_rect
.height
/= 2;
344 grad_rect
.y
= grad_rect
.y
+ tab
.rect
.height
- grad_rect
.height
- 1;
345 dc
.SetBrush(m_tab_active_top_background_brush
);
346 dc
.DrawRectangle(tab
.rect
.x
, tab
.rect
.y
+ 3, tab
.rect
.width
- 1,
347 grad_rect
.y
- tab
.rect
.y
- 3);
348 dc
.GradientFillLinear(grad_rect
, m_tab_active_background_colour
,
349 m_tab_active_background_gradient_colour
, wxSOUTH
);
353 wxRect
btm_rect(tab
.rect
);
354 btm_rect
.height
-= 4;
356 btm_rect
.height
/= 2;
357 btm_rect
.y
= btm_rect
.y
+ tab
.rect
.height
- btm_rect
.height
- 1;
358 dc
.SetBrush(m_tab_hover_background_brush
);
359 dc
.DrawRectangle(btm_rect
.x
, btm_rect
.y
, btm_rect
.width
,
361 wxRect
grad_rect(tab
.rect
);
362 grad_rect
.width
-= 1;
364 grad_rect
.height
= btm_rect
.y
- grad_rect
.y
;
365 dc
.GradientFillLinear(grad_rect
, m_tab_hover_background_top_colour
,
366 m_tab_hover_background_top_gradient_colour
, wxSOUTH
);
369 wxPoint border_points
[5];
370 border_points
[0] = wxPoint(0, 3);
371 border_points
[1] = wxPoint(1, 2);
372 border_points
[2] = wxPoint(tab
.rect
.width
- 3, 2);
373 border_points
[3] = wxPoint(tab
.rect
.width
- 1, 4);
374 border_points
[4] = wxPoint(tab
.rect
.width
- 1, tab
.rect
.height
- 1);
376 dc
.SetPen(m_tab_border_pen
);
377 dc
.DrawLines(sizeof(border_points
)/sizeof(wxPoint
), border_points
, tab
.rect
.x
, tab
.rect
.y
);
380 dc
.GetClippingBox(old_clip
);
381 bool is_first_tab
= false;
382 wxRibbonBar
* bar
= wxDynamicCast(tab
.page
->GetParent(), wxRibbonBar
);
383 if(bar
&& bar
->GetPage(0) == tab
.page
)
387 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
389 icon
= tab
.page
->GetIcon();
390 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) == 0)
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);
397 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
399 wxString label
= tab
.page
->GetLabel();
402 dc
.SetTextForeground(m_tab_label_colour
);
403 dc
.SetBackgroundMode(wxTRANSPARENT
);
407 offset
+= icon
.GetWidth() + 2;
410 dc
.GetTextExtent(label
, &text_width
, &text_height
);
411 int x
= (tab
.rect
.width
- 2 - text_width
- offset
) / 2;
416 int width
= tab
.rect
.width
- x
- 2;
417 x
+= tab
.rect
.x
+ offset
;
418 int y
= tab
.rect
.y
+ (tab
.rect
.height
- text_height
) / 2;
421 dc
.DrawBitmap(icon
, x
- offset
, tab
.rect
.y
+ (tab
.rect
.height
-
422 icon
.GetHeight()) / 2, true);
424 dc
.SetClippingRegion(x
, tab
.rect
.y
, width
, tab
.rect
.height
);
425 dc
.DrawText(label
, x
, y
);
429 // Draw the left hand edge of the tab only for the first tab (subsequent
430 // tabs use the right edge of the prior tab as their left edge). As this is
431 // outside the rectangle for the tab, only draw it if the leftmost part of
432 // the tab is within the clip rectangle (the clip region has to be cleared
433 // to draw outside the tab).
434 if(is_first_tab
&& old_clip
.x
<= tab
.rect
.x
435 && tab
.rect
.x
< old_clip
.x
+ old_clip
.width
)
437 dc
.DestroyClippingRegion();
438 dc
.DrawLine(tab
.rect
.x
- 1, tab
.rect
.y
+ 4, tab
.rect
.x
- 1,
439 tab
.rect
.y
+ tab
.rect
.height
- 1);
443 void wxRibbonAUIArtProvider::GetBarTabWidth(
445 wxWindow
* WXUNUSED(wnd
),
446 const wxString
& label
,
447 const wxBitmap
& bitmap
,
449 int* small_begin_need_separator
,
450 int* small_must_have_separator
,
455 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) && !label
.IsEmpty())
457 dc
.SetFont(m_tab_active_label_font
);
458 width
+= dc
.GetTextExtent(label
).GetWidth();
459 min
+= wxMin(30, width
); // enough for a few chars
462 // gap between label and bitmap
467 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
) && bitmap
.IsOk())
469 width
+= bitmap
.GetWidth();
470 min
+= bitmap
.GetWidth();
477 if(small_begin_need_separator
!= NULL
)
479 *small_begin_need_separator
= min
;
481 if(small_must_have_separator
!= NULL
)
483 *small_must_have_separator
= min
;
491 void wxRibbonAUIArtProvider::DrawTabSeparator(
493 wxWindow
* WXUNUSED(wnd
),
494 const wxRect
& WXUNUSED(rect
),
495 double WXUNUSED(visibility
))
497 // No explicit separators between tabs
500 void wxRibbonAUIArtProvider::DrawPageBackground(
502 wxWindow
* WXUNUSED(wnd
),
505 dc
.SetPen(*wxTRANSPARENT_PEN
);
506 dc
.SetBrush(m_background_brush
);
507 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
, rect
.width
- 2, rect
.height
- 1);
509 dc
.SetPen(m_page_border_pen
);
510 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
511 dc
.DrawLine(rect
.GetRight(), rect
.y
, rect
.GetRight(), rect
.y
+rect
.height
);
512 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight()+1, rect
.GetBottom());
515 wxSize
wxRibbonAUIArtProvider::GetScrollButtonMinimumSize(
517 wxWindow
* WXUNUSED(wnd
),
518 long WXUNUSED(style
))
520 return wxSize(11, 11);
523 void wxRibbonAUIArtProvider::DrawScrollButton(
525 wxWindow
* WXUNUSED(wnd
),
529 wxRect
true_rect(rect
);
530 wxPoint arrow_points
[3];
532 if((style
& wxRIBBON_SCROLL_BTN_FOR_MASK
) == wxRIBBON_SCROLL_BTN_FOR_TABS
)
535 true_rect
.height
-= 2;
536 dc
.SetPen(m_tab_border_pen
);
540 dc
.SetPen(*wxTRANSPARENT_PEN
);
541 dc
.SetBrush(m_background_brush
);
542 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
543 dc
.SetPen(m_page_border_pen
);
546 switch(style
& wxRIBBON_SCROLL_BTN_DIRECTION_MASK
)
548 case wxRIBBON_SCROLL_BTN_LEFT
:
549 dc
.DrawLine(true_rect
.GetRight(), true_rect
.y
, true_rect
.GetRight(),
550 true_rect
.y
+ true_rect
.height
);
551 arrow_points
[0] = wxPoint(rect
.width
/ 2 - 2, rect
.height
/ 2);
552 arrow_points
[1] = arrow_points
[0] + wxPoint(5, -5);
553 arrow_points
[2] = arrow_points
[0] + wxPoint(5, 5);
555 case wxRIBBON_SCROLL_BTN_RIGHT
:
556 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
,
557 true_rect
.y
+ true_rect
.height
);
558 arrow_points
[0] = wxPoint(rect
.width
/ 2 + 3, rect
.height
/ 2);
559 arrow_points
[1] = arrow_points
[0] - wxPoint(5, -5);
560 arrow_points
[2] = arrow_points
[0] - wxPoint(5, 5);
562 case wxRIBBON_SCROLL_BTN_DOWN
:
563 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
+ true_rect
.width
,
565 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 + 3);
566 arrow_points
[1] = arrow_points
[0] - wxPoint( 5, 5);
567 arrow_points
[2] = arrow_points
[0] - wxPoint(-5, 5);
569 case wxRIBBON_SCROLL_BTN_UP
:
570 dc
.DrawLine(true_rect
.x
, true_rect
.GetBottom(),
571 true_rect
.x
+ true_rect
.width
, true_rect
.GetBottom());
572 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 - 2);
573 arrow_points
[1] = arrow_points
[0] + wxPoint( 5, 5);
574 arrow_points
[2] = arrow_points
[0] + wxPoint(-5, 5);
582 if(style
& wxRIBBON_SCROLL_BTN_ACTIVE
)
588 dc
.SetPen(*wxTRANSPARENT_PEN
);
589 wxBrush
B(m_tab_label_colour
);
591 dc
.DrawPolygon(sizeof(arrow_points
)/sizeof(wxPoint
), arrow_points
, x
, y
);
594 wxSize
wxRibbonAUIArtProvider::GetPanelSize(
596 const wxRibbonPanel
* wnd
,
598 wxPoint
* client_offset
)
600 dc
.SetFont(m_panel_label_font
);
601 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
602 int label_height
= label_size
.GetHeight() + 5;
603 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
605 client_size
.IncBy(4, label_height
+ 6);
607 *client_offset
= wxPoint(2, label_height
+ 3);
611 client_size
.IncBy(6, label_height
+ 4);
613 *client_offset
= wxPoint(3, label_height
+ 2);
618 wxSize
wxRibbonAUIArtProvider::GetPanelClientSize(
620 const wxRibbonPanel
* wnd
,
622 wxPoint
* client_offset
)
624 dc
.SetFont(m_panel_label_font
);
625 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
626 int label_height
= label_size
.GetHeight() + 5;
627 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
629 size
.DecBy(4, label_height
+ 6);
631 *client_offset
= wxPoint(2, label_height
+ 3);
635 size
.DecBy(6, label_height
+ 4);
637 *client_offset
= wxPoint(3, label_height
+ 2);
639 if (size
.x
< 0) size
.x
= 0;
640 if (size
.y
< 0) size
.y
= 0;
644 void wxRibbonAUIArtProvider::DrawPanelBackground(
649 dc
.SetPen(*wxTRANSPARENT_PEN
);
650 dc
.SetBrush(m_background_brush
);
651 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
653 wxRect
true_rect(rect
);
654 RemovePanelPadding(&true_rect
);
656 dc
.SetPen(m_panel_border_pen
);
657 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
658 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
661 true_rect
.width
-= 2;
664 dc
.SetFont(m_panel_label_font
);
665 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
666 int label_height
= label_size
.GetHeight() + 5;
667 wxRect
label_rect(true_rect
);
668 label_rect
.height
= label_height
- 1;
669 dc
.DrawLine(label_rect
.x
, label_rect
.y
+ label_rect
.height
,
670 label_rect
.x
+ label_rect
.width
, label_rect
.y
+ label_rect
.height
);
672 wxColour label_bg_colour
= m_panel_label_background_colour
;
673 wxColour label_bg_grad_colour
= m_panel_label_background_gradient_colour
;
676 label_bg_colour
= m_panel_hover_label_background_colour
;
677 label_bg_grad_colour
= m_panel_hover_label_background_gradient_colour
;
678 dc
.SetTextForeground(m_panel_hover_label_colour
);
682 dc
.SetTextForeground(m_panel_label_colour
);
684 dc
.GradientFillLinear(label_rect
,
686 label_bg_grad_colour
, label_bg_colour
, wxSOUTH
);
688 label_bg_colour
, label_bg_grad_colour
, wxSOUTH
);
690 dc
.SetFont(m_panel_label_font
);
691 dc
.DrawText(wnd
->GetLabel(), label_rect
.x
+ 3, label_rect
.y
+ 2);
695 wxRect
gradient_rect(true_rect
);
696 gradient_rect
.y
+= label_rect
.height
+ 1;
697 gradient_rect
.height
= true_rect
.height
- label_rect
.height
- 3;
699 wxColour colour
= m_page_hover_background_gradient_colour
;
700 wxColour gradient
= m_page_hover_background_colour
;
702 wxColour colour
= m_page_hover_background_colour
;
703 wxColour gradient
= m_page_hover_background_gradient_colour
;
705 dc
.GradientFillLinear(gradient_rect
, colour
, gradient
, wxSOUTH
);
709 void wxRibbonAUIArtProvider::DrawMinimisedPanel(
715 dc
.SetPen(*wxTRANSPARENT_PEN
);
716 dc
.SetBrush(m_background_brush
);
717 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
719 wxRect
true_rect(rect
);
720 RemovePanelPadding(&true_rect
);
722 dc
.SetPen(m_panel_border_pen
);
723 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
724 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
725 true_rect
.Deflate(1);
727 if(wnd
->IsHovered() || wnd
->GetExpandedPanel())
729 wxColour colour
= m_page_hover_background_colour
;
730 wxColour gradient
= m_page_hover_background_gradient_colour
;
732 if(!wnd
->GetExpandedPanel())
734 if(wnd
->GetExpandedPanel())
737 wxColour temp
= colour
;
741 dc
.GradientFillLinear(true_rect
, colour
, gradient
, wxSOUTH
);
745 DrawMinimisedPanelCommon(dc
, wnd
, true_rect
, &preview
);
747 dc
.SetPen(m_panel_border_pen
);
748 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
749 dc
.DrawRectangle(preview
.x
, preview
.y
, preview
.width
, preview
.height
);
751 wxRect
preview_caption_rect(preview
);
752 preview_caption_rect
.height
= 7;
753 preview
.y
+= preview_caption_rect
.height
;
754 preview
.height
-= preview_caption_rect
.height
;
756 dc
.GradientFillLinear(preview_caption_rect
,
757 m_panel_hover_label_background_gradient_colour
,
758 m_panel_hover_label_background_colour
, wxSOUTH
);
759 dc
.GradientFillLinear(preview
,
760 m_page_hover_background_gradient_colour
,
761 m_page_hover_background_colour
, wxSOUTH
);
763 dc
.GradientFillLinear(preview_caption_rect
,
764 m_panel_hover_label_background_colour
,
765 m_panel_hover_label_background_gradient_colour
, wxSOUTH
);
766 dc
.GradientFillLinear(preview
,
767 m_page_hover_background_colour
,
768 m_page_hover_background_gradient_colour
, wxSOUTH
);
773 dc
.DrawBitmap(bitmap
, preview
.x
+ (preview
.width
- bitmap
.GetWidth()) / 2,
774 preview
.y
+ (preview
.height
- bitmap
.GetHeight()) / 2, true);
778 void wxRibbonAUIArtProvider::DrawPartialPanelBackground(wxDC
& dc
,
779 wxWindow
* wnd
, const wxRect
& rect
)
781 dc
.SetPen(*wxTRANSPARENT_PEN
);
782 dc
.SetBrush(m_background_brush
);
783 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
785 wxPoint
offset(wnd
->GetPosition());
786 wxWindow
* parent
= wnd
->GetParent();
787 wxRibbonPanel
* panel
= NULL
;
789 for(; parent
; parent
= parent
->GetParent())
791 panel
= wxDynamicCast(parent
, wxRibbonPanel
);
794 if(!panel
->IsHovered())
798 offset
+= parent
->GetPosition();
803 wxRect
background(panel
->GetSize());
804 RemovePanelPadding(&background
);
806 background
.width
-= 2;
807 dc
.SetFont(m_panel_label_font
);
808 int caption_height
= dc
.GetTextExtent(panel
->GetLabel()).GetHeight() + 7;
809 background
.y
+= caption_height
- 1;
810 background
.height
-= caption_height
;
812 wxRect
paint_rect(rect
);
813 paint_rect
.x
+= offset
.x
;
814 paint_rect
.y
+= offset
.y
;
816 wxColour bg_clr
, bg_grad_clr
;
818 bg_grad_clr
= m_page_hover_background_colour
;
819 bg_clr
= m_page_hover_background_gradient_colour
;
821 bg_clr
= m_page_hover_background_colour
;
822 bg_grad_clr
= m_page_hover_background_gradient_colour
;
825 paint_rect
.Intersect(background
);
826 if(!paint_rect
.IsEmpty())
828 wxColour
starting_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
829 paint_rect
.y
, background
.y
, background
.y
+ background
.height
));
830 wxColour
ending_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
831 paint_rect
.y
+ paint_rect
.height
, background
.y
,
832 background
.y
+ background
.height
));
833 paint_rect
.x
-= offset
.x
;
834 paint_rect
.y
-= offset
.y
;
835 dc
.GradientFillLinear(paint_rect
, starting_colour
, ending_colour
840 void wxRibbonAUIArtProvider::DrawGalleryBackground(
842 wxRibbonGallery
* wnd
,
845 DrawPartialPanelBackground(dc
, wnd
, rect
);
849 dc
.SetPen(*wxTRANSPARENT_PEN
);
850 dc
.SetBrush(m_gallery_hover_background_brush
);
851 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
853 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2,
858 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 16,
863 dc
.SetPen(m_gallery_border_pen
);
864 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
865 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
867 DrawGalleryBackgroundCommon(dc
, wnd
, rect
);
870 void wxRibbonAUIArtProvider::DrawGalleryButton(wxDC
& dc
, wxRect rect
,
871 wxRibbonGalleryButtonState state
, wxBitmap
* bitmaps
)
873 int extra_height
= 0;
875 wxRect
reduced_rect(rect
);
876 reduced_rect
.Deflate(1);
877 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
879 reduced_rect
.width
++;
884 reduced_rect
.height
++;
891 case wxRIBBON_GALLERY_BUTTON_NORMAL
:
892 dc
.GradientFillLinear(reduced_rect
,
893 m_gallery_button_background_colour
,
894 m_gallery_button_background_gradient_colour
, wxSOUTH
);
895 btn_bitmap
= bitmaps
[0];
897 case wxRIBBON_GALLERY_BUTTON_HOVERED
:
898 dc
.SetPen(m_gallery_item_border_pen
);
899 dc
.SetBrush(m_gallery_button_hover_background_brush
);
900 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
901 rect
.height
+ extra_height
);
902 btn_bitmap
= bitmaps
[1];
904 case wxRIBBON_GALLERY_BUTTON_ACTIVE
:
905 dc
.SetPen(m_gallery_item_border_pen
);
906 dc
.SetBrush(m_gallery_button_active_background_brush
);
907 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
908 rect
.height
+ extra_height
);
909 btn_bitmap
= bitmaps
[2];
911 case wxRIBBON_GALLERY_BUTTON_DISABLED
:
912 dc
.SetPen(*wxTRANSPARENT_PEN
);
913 dc
.SetBrush(m_gallery_button_disabled_background_brush
);
914 dc
.DrawRectangle(reduced_rect
.x
, reduced_rect
.y
, reduced_rect
.width
,
915 reduced_rect
.height
);
916 btn_bitmap
= bitmaps
[3];
920 dc
.DrawBitmap(btn_bitmap
, reduced_rect
.x
+ reduced_rect
.width
/ 2 - 2,
921 (rect
.y
+ rect
.height
/ 2) - 2, true);
924 void wxRibbonAUIArtProvider::DrawGalleryItemBackground(
926 wxRibbonGallery
* wnd
,
928 wxRibbonGalleryItem
* item
)
930 if(wnd
->GetHoveredItem() != item
&& wnd
->GetActiveItem() != item
&&
931 wnd
->GetSelection() != item
)
934 dc
.SetPen(m_gallery_item_border_pen
);
935 if(wnd
->GetActiveItem() == item
|| wnd
->GetSelection() == item
)
936 dc
.SetBrush(m_gallery_button_active_background_brush
);
938 dc
.SetBrush(m_gallery_button_hover_background_brush
);
940 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
943 void wxRibbonAUIArtProvider::DrawButtonBarBackground(
948 DrawPartialPanelBackground(dc
, wnd
, rect
);
951 void wxRibbonAUIArtProvider::DrawButtonBarButton(
953 wxWindow
* WXUNUSED(wnd
),
955 wxRibbonButtonKind kind
,
957 const wxString
& label
,
958 const wxBitmap
& bitmap_large
,
959 const wxBitmap
& bitmap_small
)
961 if(state
& (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
962 | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
))
964 dc
.SetPen(m_button_bar_hover_border_pen
);
966 wxRect
bg_rect(rect
);
969 if(kind
== wxRIBBON_BUTTON_HYBRID
)
971 switch(state
& wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK
)
973 case wxRIBBON_BUTTONBAR_BUTTON_LARGE
:
975 int iYBorder
= rect
.y
+ bitmap_large
.GetHeight() + 4;
976 wxRect
partial_bg(rect
);
977 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
979 partial_bg
.SetBottom(iYBorder
- 1);
983 partial_bg
.height
-= (iYBorder
- partial_bg
.y
+ 1);
984 partial_bg
.y
= iYBorder
+ 1;
986 dc
.DrawLine(rect
.x
, iYBorder
, rect
.x
+ rect
.width
, iYBorder
);
987 bg_rect
.Intersect(partial_bg
);
990 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM
:
993 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
995 bg_rect
.width
-= iArrowWidth
;
996 dc
.DrawLine(bg_rect
.x
+ bg_rect
.width
,
997 rect
.y
, bg_rect
.x
+ bg_rect
.width
,
998 rect
.y
+ rect
.height
);
1003 bg_rect
.x
+= bg_rect
.width
- iArrowWidth
;
1004 bg_rect
.width
= iArrowWidth
;
1005 dc
.DrawLine(bg_rect
.x
- 1, rect
.y
,
1006 bg_rect
.x
- 1, rect
.y
+ rect
.height
);
1010 case wxRIBBON_BUTTONBAR_BUTTON_SMALL
:
1015 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1016 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1018 dc
.SetPen(*wxTRANSPARENT_PEN
);
1019 if(state
& wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
)
1020 dc
.SetBrush(m_button_bar_active_background_brush
);
1022 dc
.SetBrush(m_button_bar_hover_background_brush
);
1023 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1026 dc
.SetFont(m_button_bar_label_font
);
1027 dc
.SetTextForeground(m_button_bar_label_colour
);
1028 DrawButtonBarButtonForeground(dc
, rect
, kind
, state
, label
, bitmap_large
,
1032 void wxRibbonAUIArtProvider::DrawToolBarBackground(
1037 DrawPartialPanelBackground(dc
, wnd
, rect
);
1040 void wxRibbonAUIArtProvider::DrawToolGroupBackground(
1042 wxWindow
* WXUNUSED(wnd
),
1045 dc
.SetPen(m_toolbar_border_pen
);
1046 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1047 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1048 wxRect
bg_rect(rect
);
1050 dc
.GradientFillLinear(bg_rect
, m_tool_background_colour
,
1051 m_tool_background_gradient_colour
, wxSOUTH
);
1054 void wxRibbonAUIArtProvider::DrawTool(
1056 wxWindow
* WXUNUSED(wnd
),
1058 const wxBitmap
& bitmap
,
1059 wxRibbonButtonKind kind
,
1062 wxRect
bg_rect(rect
);
1064 if((state
& wxRIBBON_TOOLBAR_TOOL_LAST
) == 0)
1066 bool is_custom_bg
= (state
& (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK
|
1067 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)) != 0;
1068 bool is_split_hybrid
= kind
== wxRIBBON_BUTTON_HYBRID
&& is_custom_bg
;
1073 dc
.SetPen(*wxTRANSPARENT_PEN
);
1074 dc
.SetBrush(m_tool_hover_background_brush
);
1075 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1076 if(state
& wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)
1078 wxRect
active_rect(bg_rect
);
1079 if(kind
== wxRIBBON_BUTTON_HYBRID
)
1081 active_rect
.width
-= 8;
1082 if(state
& wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
)
1084 active_rect
.x
+= active_rect
.width
;
1085 active_rect
.width
= 8;
1088 dc
.SetBrush(m_tool_active_background_brush
);
1089 dc
.DrawRectangle(active_rect
.x
, active_rect
.y
, active_rect
.width
,
1090 active_rect
.height
);
1096 dc
.SetPen(m_toolbar_hover_borden_pen
);
1098 dc
.SetPen(m_toolbar_border_pen
);
1099 if((state
& wxRIBBON_TOOLBAR_TOOL_FIRST
) == 0)
1102 if(!dc
.GetPixel(rect
.x
, rect
.y
+ 1, &existing
) ||
1103 existing
!= m_toolbar_hover_borden_pen
.GetColour())
1105 dc
.DrawLine(rect
.x
, rect
.y
+ 1, rect
.x
, rect
.y
+ rect
.height
- 1);
1110 wxRect
border_rect(bg_rect
);
1111 border_rect
.Inflate(1);
1112 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1113 dc
.DrawRectangle(border_rect
.x
, border_rect
.y
, border_rect
.width
,
1114 border_rect
.height
);
1118 int avail_width
= bg_rect
.GetWidth();
1119 if(kind
!= wxRIBBON_BUTTON_NORMAL
)
1124 dc
.DrawLine(rect
.x
+ avail_width
+ 1, rect
.y
,
1125 rect
.x
+ avail_width
+ 1, rect
.y
+ rect
.height
);
1127 dc
.DrawBitmap(m_toolbar_drop_bitmap
, bg_rect
.x
+ avail_width
+ 2,
1128 bg_rect
.y
+ (bg_rect
.height
/ 2) - 2, true);
1130 dc
.DrawBitmap(bitmap
, bg_rect
.x
+ (avail_width
- bitmap
.GetWidth()) / 2,
1131 bg_rect
.y
+ (bg_rect
.height
- bitmap
.GetHeight()) / 2, true);
1134 #endif // wxUSE_RIBBON