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"
19 #include "wx/settings.h"
20 #include "wx/ribbon/art.h"
24 #include "wx/ribbon/art_internal.h"
25 #include "wx/ribbon/bar.h"
26 #include "wx/ribbon/buttonbar.h"
27 #include "wx/ribbon/gallery.h"
28 #include "wx/ribbon/toolbar.h"
34 #include "wx/msw/private.h"
35 #elif defined(__WXMAC__)
36 #include "wx/osx/private.h"
39 wxRibbonAUIArtProvider::wxRibbonAUIArtProvider()
40 : wxRibbonMSWArtProvider(false)
42 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
43 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
45 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
48 SetColourScheme(base_colour
,
49 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
50 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
52 m_tab_active_label_font
= m_tab_label_font
;
53 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
55 m_page_border_left
= 1;
56 m_page_border_right
= 1;
57 m_page_border_top
= 1;
58 m_page_border_bottom
= 2;
59 m_tab_separation_size
= 0;
61 m_gallery_bitmap_padding_left_size
= 3;
62 m_gallery_bitmap_padding_right_size
= 3;
63 m_gallery_bitmap_padding_top_size
= 3;
64 m_gallery_bitmap_padding_bottom_size
= 3;
67 wxRibbonAUIArtProvider::~wxRibbonAUIArtProvider()
71 wxRibbonArtProvider
* wxRibbonAUIArtProvider::Clone() const
73 wxRibbonAUIArtProvider
*copy
= new wxRibbonAUIArtProvider();
76 copy
->m_tab_ctrl_background_colour
= m_tab_ctrl_background_colour
;
77 copy
->m_tab_ctrl_background_gradient_colour
= m_tab_ctrl_background_gradient_colour
;
78 copy
->m_panel_label_background_colour
= m_panel_label_background_colour
;
79 copy
->m_panel_label_background_gradient_colour
= m_panel_label_background_gradient_colour
;
80 copy
->m_panel_hover_label_background_colour
= m_panel_hover_label_background_colour
;
81 copy
->m_panel_hover_label_background_gradient_colour
= m_panel_hover_label_background_gradient_colour
;
83 copy
->m_background_brush
= m_background_brush
;
84 copy
->m_tab_active_top_background_brush
= m_tab_active_top_background_brush
;
85 copy
->m_tab_hover_background_brush
= m_tab_hover_background_brush
;
86 copy
->m_button_bar_hover_background_brush
= m_button_bar_hover_background_brush
;
87 copy
->m_button_bar_active_background_brush
= m_button_bar_active_background_brush
;
88 copy
->m_gallery_button_active_background_brush
= m_gallery_button_active_background_brush
;
89 copy
->m_gallery_button_hover_background_brush
= m_gallery_button_hover_background_brush
;
90 copy
->m_gallery_button_disabled_background_brush
= m_gallery_button_disabled_background_brush
;
92 copy
->m_toolbar_hover_borden_pen
= m_toolbar_hover_borden_pen
;
93 copy
->m_tool_hover_background_brush
= m_tool_hover_background_brush
;
94 copy
->m_tool_active_background_brush
= m_tool_active_background_brush
;
99 void wxRibbonAUIArtProvider::SetFont(int id
, const wxFont
& font
)
101 wxRibbonMSWArtProvider::SetFont(id
, font
);
102 if(id
== wxRIBBON_ART_TAB_LABEL_FONT
)
104 m_tab_active_label_font
= m_tab_label_font
;
105 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
109 wxColour
wxRibbonAUIArtProvider::GetColour(int id
) const
113 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
114 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
115 return m_background_brush
.GetColour();
116 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
117 return m_tab_ctrl_background_colour
;
118 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
119 return m_tab_ctrl_background_gradient_colour
;
120 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
121 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
122 return m_tab_active_top_background_brush
.GetColour();
123 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
124 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
125 return m_tab_hover_background_brush
.GetColour();
126 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
127 return m_panel_label_background_colour
;
128 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
129 return m_panel_label_background_gradient_colour
;
130 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR
:
131 return m_panel_hover_label_background_colour
;
132 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR
:
133 return m_panel_hover_label_background_gradient_colour
;
134 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
135 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
136 return m_button_bar_hover_background_brush
.GetColour();
137 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
138 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
139 return m_gallery_button_hover_background_brush
.GetColour();
140 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
141 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
142 return m_gallery_button_active_background_brush
.GetColour();
143 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
144 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
145 return m_gallery_button_disabled_background_brush
.GetColour();
147 return wxRibbonMSWArtProvider::GetColour(id
);
151 void wxRibbonAUIArtProvider::SetColour(int id
, const wxColor
& colour
)
155 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
156 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
157 m_background_brush
.SetColour(colour
);
159 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
160 m_tab_ctrl_background_colour
= colour
;
162 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
163 m_tab_ctrl_background_gradient_colour
= colour
;
165 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
166 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
167 m_tab_active_top_background_brush
.SetColour(colour
);
169 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
170 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
171 m_tab_hover_background_brush
.SetColour(colour
);
173 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
174 m_panel_label_background_colour
= colour
;
176 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
177 m_panel_label_background_gradient_colour
= colour
;
179 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
180 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
181 m_button_bar_hover_background_brush
.SetColour(colour
);
183 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
184 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
185 m_gallery_button_hover_background_brush
.SetColour(colour
);
187 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
188 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
189 m_gallery_button_active_background_brush
.SetColour(colour
);
191 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
192 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
193 m_gallery_button_disabled_background_brush
.SetColour(colour
);
196 wxRibbonMSWArtProvider::SetColour(id
, colour
);
201 void wxRibbonAUIArtProvider::SetColourScheme(
202 const wxColour
& primary
,
203 const wxColour
& secondary
,
204 const wxColour
& tertiary
)
206 wxRibbonHSLColour
primary_hsl(primary
);
207 wxRibbonHSLColour
secondary_hsl(secondary
);
208 wxRibbonHSLColour
tertiary_hsl(tertiary
);
210 // Map primary & secondary luminance from [0, 1] to [0.15, 0.85]
211 primary_hsl
.luminance
= cos(primary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
212 secondary_hsl
.luminance
= cos(secondary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
214 // TODO: Remove next line once this provider stops piggybacking MSW
215 wxRibbonMSWArtProvider::SetColourScheme(primary
, secondary
, tertiary
);
217 #define LikePrimary(luminance) \
218 wxRibbonShiftLuminance(primary_hsl, luminance ## f).ToRGB()
219 #define LikeSecondary(luminance) \
220 wxRibbonShiftLuminance(secondary_hsl, luminance ## f).ToRGB()
222 m_tab_ctrl_background_colour
= LikePrimary(0.9);
223 m_tab_ctrl_background_gradient_colour
= LikePrimary(1.7);
224 m_tab_border_pen
= LikePrimary(0.75);
225 m_tab_label_colour
= LikePrimary(0.1);
226 m_tab_hover_background_top_colour
= primary_hsl
.ToRGB();
227 m_tab_hover_background_top_gradient_colour
= LikePrimary(1.6);
228 m_tab_hover_background_brush
= m_tab_hover_background_top_colour
;
229 m_tab_active_background_colour
= m_tab_ctrl_background_gradient_colour
;
230 m_tab_active_background_gradient_colour
= primary_hsl
.ToRGB();
231 m_tab_active_top_background_brush
= m_tab_active_background_colour
;
232 m_panel_label_colour
= m_tab_label_colour
;
233 m_panel_minimised_label_colour
= m_panel_label_colour
;
234 m_panel_hover_label_colour
= tertiary_hsl
.ToRGB();
235 m_page_border_pen
= m_tab_border_pen
;
236 m_panel_border_pen
= m_tab_border_pen
;
237 m_background_brush
= primary_hsl
.ToRGB();
238 m_page_hover_background_colour
= LikePrimary(1.5);
239 m_page_hover_background_gradient_colour
= LikePrimary(0.9);
240 m_panel_label_background_colour
= LikePrimary(0.85);
241 m_panel_label_background_gradient_colour
= LikePrimary(0.97);
242 m_panel_hover_label_background_gradient_colour
= secondary_hsl
.ToRGB();
243 m_panel_hover_label_background_colour
= secondary_hsl
.Lighter(0.2f
).ToRGB();
244 m_button_bar_hover_border_pen
= secondary_hsl
.ToRGB();
245 m_button_bar_hover_background_brush
= LikeSecondary(1.7);
246 m_button_bar_active_background_brush
= LikeSecondary(1.4);
247 m_button_bar_label_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
;
272 void wxRibbonAUIArtProvider::DrawTabCtrlBackground(
274 wxWindow
* WXUNUSED(wnd
),
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());
285 int wxRibbonAUIArtProvider::GetTabCtrlHeight(
287 wxWindow
* WXUNUSED(wnd
),
288 const wxRibbonPageTabInfoArray
& pages
)
293 if(pages
.GetCount() <= 1 && (m_flags
& wxRIBBON_BAR_ALWAYS_SHOW_TABS
) == 0)
295 // To preserve space, a single tab need not be displayed. We still need
296 // one pixel of border though.
300 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
302 dc
.SetFont(m_tab_active_label_font
);
303 text_height
= dc
.GetTextExtent(wxT("ABCDEFXj")).GetHeight();
305 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
307 size_t numpages
= pages
.GetCount();
308 for(size_t i
= 0; i
< numpages
; ++i
)
310 const wxRibbonPageTabInfo
& info
= pages
.Item(i
);
311 if(info
.page
->GetIcon().IsOk())
313 icon_height
= wxMax(icon_height
, info
.page
->GetIcon().GetHeight());
318 return wxMax(text_height
, icon_height
) + 10;
321 void wxRibbonAUIArtProvider::DrawTab(wxDC
& dc
,
322 wxWindow
* WXUNUSED(wnd
),
323 const wxRibbonPageTabInfo
& tab
)
325 if(tab
.rect
.height
<= 1)
328 dc
.SetFont(m_tab_label_font
);
329 dc
.SetPen(*wxTRANSPARENT_PEN
);
330 if(tab
.active
|| tab
.hovered
)
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);
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 dc
.GradientFillLinear(grad_rect
, m_tab_active_background_colour
,
348 m_tab_active_background_gradient_colour
, wxSOUTH
);
352 wxRect
btm_rect(tab
.rect
);
353 btm_rect
.height
-= 4;
355 btm_rect
.height
/= 2;
356 btm_rect
.y
= btm_rect
.y
+ tab
.rect
.height
- btm_rect
.height
- 1;
357 dc
.SetBrush(m_tab_hover_background_brush
);
358 dc
.DrawRectangle(btm_rect
.x
, btm_rect
.y
, btm_rect
.width
,
360 wxRect
grad_rect(tab
.rect
);
361 grad_rect
.width
-= 1;
363 grad_rect
.height
= btm_rect
.y
- grad_rect
.y
;
364 dc
.GradientFillLinear(grad_rect
, m_tab_hover_background_top_colour
,
365 m_tab_hover_background_top_gradient_colour
, wxSOUTH
);
368 wxPoint border_points
[5];
369 border_points
[0] = wxPoint(0, 3);
370 border_points
[1] = wxPoint(1, 2);
371 border_points
[2] = wxPoint(tab
.rect
.width
- 3, 2);
372 border_points
[3] = wxPoint(tab
.rect
.width
- 1, 4);
373 border_points
[4] = wxPoint(tab
.rect
.width
- 1, tab
.rect
.height
- 1);
375 dc
.SetPen(m_tab_border_pen
);
376 dc
.DrawLines(sizeof(border_points
)/sizeof(wxPoint
), border_points
, tab
.rect
.x
, tab
.rect
.y
);
379 dc
.GetClippingBox(old_clip
);
380 bool is_first_tab
= false;
381 wxRibbonBar
* bar
= wxDynamicCast(tab
.page
->GetParent(), wxRibbonBar
);
382 if(bar
&& bar
->GetPage(0) == tab
.page
)
386 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
388 icon
= tab
.page
->GetIcon();
389 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) == 0)
391 int x
= tab
.rect
.x
+ (tab
.rect
.width
- icon
.GetWidth()) / 2;
392 dc
.DrawBitmap(icon
, x
, tab
.rect
.y
+ 1 + (tab
.rect
.height
- 1 -
393 icon
.GetHeight()) / 2, true);
396 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
398 wxString label
= tab
.page
->GetLabel();
401 dc
.SetTextForeground(m_tab_label_colour
);
402 dc
.SetBackgroundMode(wxTRANSPARENT
);
406 offset
+= icon
.GetWidth() + 2;
409 dc
.GetTextExtent(label
, &text_width
, &text_height
);
410 int x
= (tab
.rect
.width
- 2 - text_width
- offset
) / 2;
415 int width
= tab
.rect
.width
- x
- 2;
416 x
+= tab
.rect
.x
+ offset
;
417 int y
= tab
.rect
.y
+ (tab
.rect
.height
- text_height
) / 2;
420 dc
.DrawBitmap(icon
, x
- offset
, tab
.rect
.y
+ (tab
.rect
.height
-
421 icon
.GetHeight()) / 2, true);
423 dc
.SetClippingRegion(x
, tab
.rect
.y
, width
, tab
.rect
.height
);
424 dc
.DrawText(label
, x
, y
);
428 // Draw the left hand edge of the tab only for the first tab (subsequent
429 // tabs use the right edge of the prior tab as their left edge). As this is
430 // outside the rectangle for the tab, only draw it if the leftmost part of
431 // the tab is within the clip rectangle (the clip region has to be cleared
432 // to draw outside the tab).
433 if(is_first_tab
&& old_clip
.x
<= tab
.rect
.x
434 && tab
.rect
.x
< old_clip
.x
+ old_clip
.width
)
436 dc
.DestroyClippingRegion();
437 dc
.DrawLine(tab
.rect
.x
- 1, tab
.rect
.y
+ 4, tab
.rect
.x
- 1,
438 tab
.rect
.y
+ tab
.rect
.height
- 1);
442 void wxRibbonAUIArtProvider::GetBarTabWidth(
444 wxWindow
* WXUNUSED(wnd
),
445 const wxString
& label
,
446 const wxBitmap
& bitmap
,
448 int* small_begin_need_separator
,
449 int* small_must_have_separator
,
454 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) && !label
.IsEmpty())
456 dc
.SetFont(m_tab_active_label_font
);
457 width
+= dc
.GetTextExtent(label
).GetWidth();
458 min
+= wxMin(30, width
); // enough for a few chars
461 // gap between label and bitmap
466 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
) && bitmap
.IsOk())
468 width
+= bitmap
.GetWidth();
469 min
+= bitmap
.GetWidth();
476 if(small_begin_need_separator
!= NULL
)
478 *small_begin_need_separator
= min
;
480 if(small_must_have_separator
!= NULL
)
482 *small_must_have_separator
= min
;
490 void wxRibbonAUIArtProvider::DrawTabSeparator(
492 wxWindow
* WXUNUSED(wnd
),
493 const wxRect
& WXUNUSED(rect
),
494 double WXUNUSED(visibility
))
496 // No explicit separators between tabs
499 void wxRibbonAUIArtProvider::DrawPageBackground(
501 wxWindow
* WXUNUSED(wnd
),
504 dc
.SetPen(*wxTRANSPARENT_PEN
);
505 dc
.SetBrush(m_background_brush
);
506 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
, rect
.width
- 2, rect
.height
- 1);
508 dc
.SetPen(m_page_border_pen
);
509 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
510 dc
.DrawLine(rect
.GetRight(), rect
.y
, rect
.GetRight(), rect
.y
+rect
.height
);
511 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight()+1, rect
.GetBottom());
514 wxSize
wxRibbonAUIArtProvider::GetScrollButtonMinimumSize(
516 wxWindow
* WXUNUSED(wnd
),
517 long WXUNUSED(style
))
519 return wxSize(11, 11);
522 void wxRibbonAUIArtProvider::DrawScrollButton(
524 wxWindow
* WXUNUSED(wnd
),
528 wxRect
true_rect(rect
);
529 wxPoint arrow_points
[3];
531 if((style
& wxRIBBON_SCROLL_BTN_FOR_MASK
) == wxRIBBON_SCROLL_BTN_FOR_TABS
)
534 true_rect
.height
-= 2;
535 dc
.SetPen(m_tab_border_pen
);
539 dc
.SetPen(*wxTRANSPARENT_PEN
);
540 dc
.SetBrush(m_background_brush
);
541 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
542 dc
.SetPen(m_page_border_pen
);
545 switch(style
& wxRIBBON_SCROLL_BTN_DIRECTION_MASK
)
547 case wxRIBBON_SCROLL_BTN_LEFT
:
548 dc
.DrawLine(true_rect
.GetRight(), true_rect
.y
, true_rect
.GetRight(),
549 true_rect
.y
+ true_rect
.height
);
550 arrow_points
[0] = wxPoint(rect
.width
/ 2 - 2, rect
.height
/ 2);
551 arrow_points
[1] = arrow_points
[0] + wxPoint(5, -5);
552 arrow_points
[2] = arrow_points
[0] + wxPoint(5, 5);
554 case wxRIBBON_SCROLL_BTN_RIGHT
:
555 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
,
556 true_rect
.y
+ true_rect
.height
);
557 arrow_points
[0] = wxPoint(rect
.width
/ 2 + 3, rect
.height
/ 2);
558 arrow_points
[1] = arrow_points
[0] - wxPoint(5, -5);
559 arrow_points
[2] = arrow_points
[0] - wxPoint(5, 5);
561 case wxRIBBON_SCROLL_BTN_DOWN
:
562 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
+ true_rect
.width
,
564 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 + 3);
565 arrow_points
[1] = arrow_points
[0] - wxPoint( 5, 5);
566 arrow_points
[2] = arrow_points
[0] - wxPoint(-5, 5);
568 case wxRIBBON_SCROLL_BTN_UP
:
569 dc
.DrawLine(true_rect
.x
, true_rect
.GetBottom(),
570 true_rect
.x
+ true_rect
.width
, true_rect
.GetBottom());
571 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 - 2);
572 arrow_points
[1] = arrow_points
[0] + wxPoint( 5, 5);
573 arrow_points
[2] = arrow_points
[0] + wxPoint(-5, 5);
581 if(style
& wxRIBBON_SCROLL_BTN_ACTIVE
)
587 dc
.SetPen(*wxTRANSPARENT_PEN
);
588 wxBrush
B(m_tab_label_colour
);
590 dc
.DrawPolygon(sizeof(arrow_points
)/sizeof(wxPoint
), arrow_points
, x
, y
);
593 wxSize
wxRibbonAUIArtProvider::GetPanelSize(
595 const wxRibbonPanel
* wnd
,
597 wxPoint
* client_offset
)
599 dc
.SetFont(m_panel_label_font
);
600 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
601 int label_height
= label_size
.GetHeight() + 5;
602 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
604 client_size
.IncBy(4, label_height
+ 6);
606 *client_offset
= wxPoint(2, label_height
+ 3);
610 client_size
.IncBy(6, label_height
+ 4);
612 *client_offset
= wxPoint(3, label_height
+ 2);
617 wxSize
wxRibbonAUIArtProvider::GetPanelClientSize(
619 const wxRibbonPanel
* wnd
,
621 wxPoint
* client_offset
)
623 dc
.SetFont(m_panel_label_font
);
624 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
625 int label_height
= label_size
.GetHeight() + 5;
626 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
628 size
.DecBy(4, label_height
+ 6);
630 *client_offset
= wxPoint(2, label_height
+ 3);
634 size
.DecBy(6, label_height
+ 4);
636 *client_offset
= wxPoint(3, label_height
+ 2);
641 void wxRibbonAUIArtProvider::DrawPanelBackground(
646 dc
.SetPen(*wxTRANSPARENT_PEN
);
647 dc
.SetBrush(m_background_brush
);
648 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
650 wxRect
true_rect(rect
);
651 RemovePanelPadding(&true_rect
);
653 dc
.SetPen(m_panel_border_pen
);
654 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
655 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
658 true_rect
.width
-= 2;
661 dc
.SetFont(m_panel_label_font
);
662 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
663 int label_height
= label_size
.GetHeight() + 5;
664 wxRect
label_rect(true_rect
);
665 label_rect
.height
= label_height
- 1;
666 dc
.DrawLine(label_rect
.x
, label_rect
.y
+ label_rect
.height
,
667 label_rect
.x
+ label_rect
.width
, label_rect
.y
+ label_rect
.height
);
669 wxColour label_bg_colour
= m_panel_label_background_colour
;
670 wxColour label_bg_grad_colour
= m_panel_label_background_gradient_colour
;
673 label_bg_colour
= m_panel_hover_label_background_colour
;
674 label_bg_grad_colour
= m_panel_hover_label_background_gradient_colour
;
675 dc
.SetTextForeground(m_panel_hover_label_colour
);
679 dc
.SetTextForeground(m_panel_label_colour
);
681 dc
.GradientFillLinear(label_rect
,
683 label_bg_grad_colour
, label_bg_colour
, wxSOUTH
);
685 label_bg_colour
, label_bg_grad_colour
, wxSOUTH
);
687 dc
.SetFont(m_panel_label_font
);
688 dc
.DrawText(wnd
->GetLabel(), label_rect
.x
+ 3, label_rect
.y
+ 2);
692 wxRect
gradient_rect(true_rect
);
693 gradient_rect
.y
+= label_rect
.height
+ 1;
694 gradient_rect
.height
= true_rect
.height
- label_rect
.height
- 3;
696 wxColour colour
= m_page_hover_background_gradient_colour
;
697 wxColour gradient
= m_page_hover_background_colour
;
699 wxColour colour
= m_page_hover_background_colour
;
700 wxColour gradient
= m_page_hover_background_gradient_colour
;
702 dc
.GradientFillLinear(gradient_rect
, colour
, gradient
, wxSOUTH
);
706 void wxRibbonAUIArtProvider::DrawMinimisedPanel(
712 dc
.SetPen(*wxTRANSPARENT_PEN
);
713 dc
.SetBrush(m_background_brush
);
714 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
716 wxRect
true_rect(rect
);
717 RemovePanelPadding(&true_rect
);
719 dc
.SetPen(m_panel_border_pen
);
720 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
721 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
722 true_rect
.Deflate(1);
724 if(wnd
->IsHovered() || wnd
->GetExpandedPanel())
726 wxColour colour
= m_page_hover_background_colour
;
727 wxColour gradient
= m_page_hover_background_gradient_colour
;
729 if(!wnd
->GetExpandedPanel())
731 if(wnd
->GetExpandedPanel())
734 wxColour temp
= colour
;
738 dc
.GradientFillLinear(true_rect
, colour
, gradient
, wxSOUTH
);
742 DrawMinimisedPanelCommon(dc
, wnd
, true_rect
, &preview
);
744 dc
.SetPen(m_panel_border_pen
);
745 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
746 dc
.DrawRectangle(preview
.x
, preview
.y
, preview
.width
, preview
.height
);
748 wxRect
preview_caption_rect(preview
);
749 preview_caption_rect
.height
= 7;
750 preview
.y
+= preview_caption_rect
.height
;
751 preview
.height
-= preview_caption_rect
.height
;
753 dc
.GradientFillLinear(preview_caption_rect
,
754 m_panel_hover_label_background_gradient_colour
,
755 m_panel_hover_label_background_colour
, wxSOUTH
);
756 dc
.GradientFillLinear(preview
,
757 m_page_hover_background_gradient_colour
,
758 m_page_hover_background_colour
, wxSOUTH
);
760 dc
.GradientFillLinear(preview_caption_rect
,
761 m_panel_hover_label_background_colour
,
762 m_panel_hover_label_background_gradient_colour
, wxSOUTH
);
763 dc
.GradientFillLinear(preview
,
764 m_page_hover_background_colour
,
765 m_page_hover_background_gradient_colour
, wxSOUTH
);
770 dc
.DrawBitmap(bitmap
, preview
.x
+ (preview
.width
- bitmap
.GetWidth()) / 2,
771 preview
.y
+ (preview
.height
- bitmap
.GetHeight()) / 2, true);
775 void wxRibbonAUIArtProvider::DrawPartialPanelBackground(wxDC
& dc
,
776 wxWindow
* wnd
, const wxRect
& rect
)
778 dc
.SetPen(*wxTRANSPARENT_PEN
);
779 dc
.SetBrush(m_background_brush
);
780 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
782 wxPoint
offset(wnd
->GetPosition());
783 wxWindow
* parent
= wnd
->GetParent();
784 wxRibbonPanel
* panel
= NULL
;
786 for(; parent
; parent
= parent
->GetParent())
788 panel
= wxDynamicCast(parent
, wxRibbonPanel
);
791 if(!panel
->IsHovered())
795 offset
+= parent
->GetPosition();
800 wxRect
background(panel
->GetSize());
801 RemovePanelPadding(&background
);
803 background
.width
-= 2;
804 dc
.SetFont(m_panel_label_font
);
805 int caption_height
= dc
.GetTextExtent(panel
->GetLabel()).GetHeight() + 7;
806 background
.y
+= caption_height
- 1;
807 background
.height
-= caption_height
;
809 wxRect
paint_rect(rect
);
810 paint_rect
.x
+= offset
.x
;
811 paint_rect
.y
+= offset
.y
;
813 wxColour bg_clr
, bg_grad_clr
;
815 bg_grad_clr
= m_page_hover_background_colour
;
816 bg_clr
= m_page_hover_background_gradient_colour
;
818 bg_clr
= m_page_hover_background_colour
;
819 bg_grad_clr
= m_page_hover_background_gradient_colour
;
822 paint_rect
.Intersect(background
);
823 if(!paint_rect
.IsEmpty())
825 wxColour
starting_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
826 paint_rect
.y
, background
.y
, background
.y
+ background
.height
));
827 wxColour
ending_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
828 paint_rect
.y
+ paint_rect
.height
, background
.y
,
829 background
.y
+ background
.height
));
830 paint_rect
.x
-= offset
.x
;
831 paint_rect
.y
-= offset
.y
;
832 dc
.GradientFillLinear(paint_rect
, starting_colour
, ending_colour
837 void wxRibbonAUIArtProvider::DrawGalleryBackground(
839 wxRibbonGallery
* wnd
,
842 DrawPartialPanelBackground(dc
, wnd
, rect
);
846 dc
.SetPen(*wxTRANSPARENT_PEN
);
847 dc
.SetBrush(m_gallery_hover_background_brush
);
848 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
850 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2,
855 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 16,
860 dc
.SetPen(m_gallery_border_pen
);
861 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
862 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
864 DrawGalleryBackgroundCommon(dc
, wnd
, rect
);
867 void wxRibbonAUIArtProvider::DrawGalleryButton(wxDC
& dc
, wxRect rect
,
868 wxRibbonGalleryButtonState state
, wxBitmap
* bitmaps
)
870 int extra_height
= 0;
872 wxRect
reduced_rect(rect
);
873 reduced_rect
.Deflate(1);
874 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
876 reduced_rect
.width
++;
881 reduced_rect
.height
++;
888 case wxRIBBON_GALLERY_BUTTON_NORMAL
:
889 dc
.GradientFillLinear(reduced_rect
,
890 m_gallery_button_background_colour
,
891 m_gallery_button_background_gradient_colour
, wxSOUTH
);
892 btn_bitmap
= bitmaps
[0];
894 case wxRIBBON_GALLERY_BUTTON_HOVERED
:
895 dc
.SetPen(m_gallery_item_border_pen
);
896 dc
.SetBrush(m_gallery_button_hover_background_brush
);
897 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
898 rect
.height
+ extra_height
);
899 btn_bitmap
= bitmaps
[1];
901 case wxRIBBON_GALLERY_BUTTON_ACTIVE
:
902 dc
.SetPen(m_gallery_item_border_pen
);
903 dc
.SetBrush(m_gallery_button_active_background_brush
);
904 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
905 rect
.height
+ extra_height
);
906 btn_bitmap
= bitmaps
[2];
908 case wxRIBBON_GALLERY_BUTTON_DISABLED
:
909 dc
.SetPen(*wxTRANSPARENT_PEN
);
910 dc
.SetBrush(m_gallery_button_disabled_background_brush
);
911 dc
.DrawRectangle(reduced_rect
.x
, reduced_rect
.y
, reduced_rect
.width
,
912 reduced_rect
.height
);
913 btn_bitmap
= bitmaps
[3];
917 dc
.DrawBitmap(btn_bitmap
, reduced_rect
.x
+ reduced_rect
.width
/ 2 - 2,
918 (rect
.y
+ rect
.height
/ 2) - 2, true);
921 void wxRibbonAUIArtProvider::DrawGalleryItemBackground(
923 wxRibbonGallery
* wnd
,
925 wxRibbonGalleryItem
* item
)
927 if(wnd
->GetHoveredItem() != item
&& wnd
->GetActiveItem() != item
&&
928 wnd
->GetSelection() != item
)
931 dc
.SetPen(m_gallery_item_border_pen
);
932 if(wnd
->GetActiveItem() == item
|| wnd
->GetSelection() == item
)
933 dc
.SetBrush(m_gallery_button_active_background_brush
);
935 dc
.SetBrush(m_gallery_button_hover_background_brush
);
937 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
940 void wxRibbonAUIArtProvider::DrawButtonBarBackground(
945 DrawPartialPanelBackground(dc
, wnd
, rect
);
948 void wxRibbonAUIArtProvider::DrawButtonBarButton(
950 wxWindow
* WXUNUSED(wnd
),
952 wxRibbonButtonKind kind
,
954 const wxString
& label
,
955 const wxBitmap
& bitmap_large
,
956 const wxBitmap
& bitmap_small
)
958 if(state
& (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
959 | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
))
961 dc
.SetPen(m_button_bar_hover_border_pen
);
963 wxRect
bg_rect(rect
);
966 if(kind
== wxRIBBON_BUTTON_HYBRID
)
968 switch(state
& wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK
)
970 case wxRIBBON_BUTTONBAR_BUTTON_LARGE
:
972 int iYBorder
= rect
.y
+ bitmap_large
.GetHeight() + 4;
973 wxRect
partial_bg(rect
);
974 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
976 partial_bg
.SetBottom(iYBorder
- 1);
980 partial_bg
.height
-= (iYBorder
- partial_bg
.y
+ 1);
981 partial_bg
.y
= iYBorder
+ 1;
983 dc
.DrawLine(rect
.x
, iYBorder
, rect
.x
+ rect
.width
, iYBorder
);
984 bg_rect
.Intersect(partial_bg
);
987 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM
:
990 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
992 bg_rect
.width
-= iArrowWidth
;
993 dc
.DrawLine(bg_rect
.x
+ bg_rect
.width
,
994 rect
.y
, bg_rect
.x
+ bg_rect
.width
,
995 rect
.y
+ rect
.height
);
1000 bg_rect
.x
+= bg_rect
.width
- iArrowWidth
;
1001 bg_rect
.width
= iArrowWidth
;
1002 dc
.DrawLine(bg_rect
.x
- 1, rect
.y
,
1003 bg_rect
.x
- 1, rect
.y
+ rect
.height
);
1007 case wxRIBBON_BUTTONBAR_BUTTON_SMALL
:
1012 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1013 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1015 dc
.SetPen(*wxTRANSPARENT_PEN
);
1016 if(state
& wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
)
1017 dc
.SetBrush(m_button_bar_active_background_brush
);
1019 dc
.SetBrush(m_button_bar_hover_background_brush
);
1020 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1023 dc
.SetFont(m_button_bar_label_font
);
1024 dc
.SetTextForeground(m_button_bar_label_colour
);
1025 DrawButtonBarButtonForeground(dc
, rect
, kind
, state
, label
, bitmap_large
,
1029 void wxRibbonAUIArtProvider::DrawToolBarBackground(
1034 DrawPartialPanelBackground(dc
, wnd
, rect
);
1037 void wxRibbonAUIArtProvider::DrawToolGroupBackground(
1039 wxWindow
* WXUNUSED(wnd
),
1042 dc
.SetPen(m_toolbar_border_pen
);
1043 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1044 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1045 wxRect
bg_rect(rect
);
1047 dc
.GradientFillLinear(bg_rect
, m_tool_background_colour
,
1048 m_tool_background_gradient_colour
, wxSOUTH
);
1051 void wxRibbonAUIArtProvider::DrawTool(
1053 wxWindow
* WXUNUSED(wnd
),
1055 const wxBitmap
& bitmap
,
1056 wxRibbonButtonKind kind
,
1059 wxRect
bg_rect(rect
);
1061 if((state
& wxRIBBON_TOOLBAR_TOOL_LAST
) == 0)
1063 bool is_custom_bg
= (state
& (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK
|
1064 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)) != 0;
1065 bool is_split_hybrid
= kind
== wxRIBBON_BUTTON_HYBRID
&& is_custom_bg
;
1070 dc
.SetPen(*wxTRANSPARENT_PEN
);
1071 dc
.SetBrush(m_tool_hover_background_brush
);
1072 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1073 if(state
& wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)
1075 wxRect
active_rect(bg_rect
);
1076 if(kind
== wxRIBBON_BUTTON_HYBRID
)
1078 active_rect
.width
-= 8;
1079 if(state
& wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
)
1081 active_rect
.x
+= active_rect
.width
;
1082 active_rect
.width
= 8;
1085 dc
.SetBrush(m_tool_active_background_brush
);
1086 dc
.DrawRectangle(active_rect
.x
, active_rect
.y
, active_rect
.width
,
1087 active_rect
.height
);
1093 dc
.SetPen(m_toolbar_hover_borden_pen
);
1095 dc
.SetPen(m_toolbar_border_pen
);
1096 if((state
& wxRIBBON_TOOLBAR_TOOL_FIRST
) == 0)
1099 if(!dc
.GetPixel(rect
.x
, rect
.y
+ 1, &existing
) ||
1100 existing
!= m_toolbar_hover_borden_pen
.GetColour())
1102 dc
.DrawLine(rect
.x
, rect
.y
+ 1, rect
.x
, rect
.y
+ rect
.height
- 1);
1107 wxRect
border_rect(bg_rect
);
1108 border_rect
.Inflate(1);
1109 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1110 dc
.DrawRectangle(border_rect
.x
, border_rect
.y
, border_rect
.width
,
1111 border_rect
.height
);
1115 int avail_width
= bg_rect
.GetWidth();
1116 if(kind
!= wxRIBBON_BUTTON_NORMAL
)
1121 dc
.DrawLine(rect
.x
+ avail_width
+ 1, rect
.y
,
1122 rect
.x
+ avail_width
+ 1, rect
.y
+ rect
.height
);
1124 dc
.DrawBitmap(m_toolbar_drop_bitmap
, bg_rect
.x
+ avail_width
+ 2,
1125 bg_rect
.y
+ (bg_rect
.height
/ 2) - 2, true);
1127 dc
.DrawBitmap(bitmap
, bg_rect
.x
+ (avail_width
- bitmap
.GetWidth()) / 2,
1128 bg_rect
.y
+ (bg_rect
.height
- bitmap
.GetHeight()) / 2, true);
1131 #endif // wxUSE_RIBBON