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"
18 #include "wx/ribbon/art.h"
22 #include "wx/ribbon/art_internal.h"
23 #include "wx/ribbon/bar.h"
24 #include "wx/ribbon/buttonbar.h"
25 #include "wx/ribbon/gallery.h"
26 #include "wx/ribbon/toolbar.h"
32 #include "wx/msw/private.h"
33 #elif defined(__WXMAC__)
34 #include "wx/osx/private.h"
37 wxRibbonAUIArtProvider::wxRibbonAUIArtProvider()
38 : wxRibbonMSWArtProvider(false)
40 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
41 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
43 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
46 SetColourScheme(base_colour
,
47 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
48 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
50 m_tab_active_label_font
= m_tab_label_font
;
51 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
53 m_page_border_left
= 1;
54 m_page_border_right
= 1;
55 m_page_border_top
= 1;
56 m_page_border_bottom
= 2;
57 m_tab_separation_size
= 0;
59 m_gallery_bitmap_padding_left_size
= 3;
60 m_gallery_bitmap_padding_right_size
= 3;
61 m_gallery_bitmap_padding_top_size
= 3;
62 m_gallery_bitmap_padding_bottom_size
= 3;
65 wxRibbonAUIArtProvider::~wxRibbonAUIArtProvider()
69 wxRibbonArtProvider
* wxRibbonAUIArtProvider::Clone() const
71 wxRibbonAUIArtProvider
*copy
= new wxRibbonAUIArtProvider();
74 copy
->m_tab_ctrl_background_colour
= m_tab_ctrl_background_colour
;
75 copy
->m_tab_ctrl_background_gradient_colour
= m_tab_ctrl_background_gradient_colour
;
76 copy
->m_panel_label_background_colour
= m_panel_label_background_colour
;
77 copy
->m_panel_label_background_gradient_colour
= m_panel_label_background_gradient_colour
;
78 copy
->m_panel_hover_label_background_colour
= m_panel_hover_label_background_colour
;
79 copy
->m_panel_hover_label_background_gradient_colour
= m_panel_hover_label_background_gradient_colour
;
81 copy
->m_background_brush
= m_background_brush
;
82 copy
->m_tab_active_top_background_brush
= m_tab_active_top_background_brush
;
83 copy
->m_tab_hover_background_brush
= m_tab_hover_background_brush
;
84 copy
->m_button_bar_hover_background_brush
= m_button_bar_hover_background_brush
;
85 copy
->m_button_bar_active_background_brush
= m_button_bar_active_background_brush
;
86 copy
->m_gallery_button_active_background_brush
= m_gallery_button_active_background_brush
;
87 copy
->m_gallery_button_hover_background_brush
= m_gallery_button_hover_background_brush
;
88 copy
->m_gallery_button_disabled_background_brush
= m_gallery_button_disabled_background_brush
;
90 copy
->m_toolbar_hover_borden_pen
= m_toolbar_hover_borden_pen
;
91 copy
->m_tool_hover_background_brush
= m_tool_hover_background_brush
;
92 copy
->m_tool_active_background_brush
= m_tool_active_background_brush
;
97 void wxRibbonAUIArtProvider::SetFont(int id
, const wxFont
& font
)
99 wxRibbonMSWArtProvider::SetFont(id
, font
);
100 if(id
== wxRIBBON_ART_TAB_LABEL_FONT
)
102 m_tab_active_label_font
= m_tab_label_font
;
103 m_tab_active_label_font
.SetWeight(wxFONTWEIGHT_BOLD
);
107 wxColour
wxRibbonAUIArtProvider::GetColour(int id
) const
111 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
112 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
113 return m_background_brush
.GetColour();
114 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
115 return m_tab_ctrl_background_colour
;
116 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
117 return m_tab_ctrl_background_gradient_colour
;
118 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
119 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
120 return m_tab_active_top_background_brush
.GetColour();
121 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
122 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
123 return m_tab_hover_background_brush
.GetColour();
124 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
125 return m_panel_label_background_colour
;
126 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
127 return m_panel_label_background_gradient_colour
;
128 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR
:
129 return m_panel_hover_label_background_colour
;
130 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR
:
131 return m_panel_hover_label_background_gradient_colour
;
132 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
133 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
134 return m_button_bar_hover_background_brush
.GetColour();
135 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
136 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
137 return m_gallery_button_hover_background_brush
.GetColour();
138 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
139 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
140 return m_gallery_button_active_background_brush
.GetColour();
141 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
142 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
143 return m_gallery_button_disabled_background_brush
.GetColour();
145 return wxRibbonMSWArtProvider::GetColour(id
);
149 void wxRibbonAUIArtProvider::SetColour(int id
, const wxColor
& colour
)
153 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR
:
154 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR
:
155 m_background_brush
.SetColour(colour
);
157 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR
:
158 m_tab_ctrl_background_colour
= colour
;
160 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR
:
161 m_tab_ctrl_background_gradient_colour
= colour
;
163 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR
:
164 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR
:
165 m_tab_active_top_background_brush
.SetColour(colour
);
167 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR
:
168 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR
:
169 m_tab_hover_background_brush
.SetColour(colour
);
171 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR
:
172 m_panel_label_background_colour
= colour
;
174 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR
:
175 m_panel_label_background_gradient_colour
= colour
;
177 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR
:
178 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR
:
179 m_button_bar_hover_background_brush
.SetColour(colour
);
181 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR
:
182 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR
:
183 m_gallery_button_hover_background_brush
.SetColour(colour
);
185 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR
:
186 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR
:
187 m_gallery_button_active_background_brush
.SetColour(colour
);
189 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR
:
190 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR
:
191 m_gallery_button_disabled_background_brush
.SetColour(colour
);
194 wxRibbonMSWArtProvider::SetColour(id
, colour
);
199 void wxRibbonAUIArtProvider::SetColourScheme(
200 const wxColour
& primary
,
201 const wxColour
& secondary
,
202 const wxColour
& tertiary
)
204 wxRibbonHSLColour
primary_hsl(primary
);
205 wxRibbonHSLColour
secondary_hsl(secondary
);
206 wxRibbonHSLColour
tertiary_hsl(tertiary
);
208 // Map primary & secondary luminance from [0, 1] to [0.15, 0.85]
209 primary_hsl
.luminance
= cos(primary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
210 secondary_hsl
.luminance
= cos(secondary_hsl
.luminance
* M_PI
) * -0.35 + 0.5;
212 // TODO: Remove next line once this provider stops piggybacking MSW
213 wxRibbonMSWArtProvider::SetColourScheme(primary
, secondary
, tertiary
);
215 #define LikePrimary(luminance) \
216 wxRibbonShiftLuminance(primary_hsl, luminance ## f).ToRGB()
217 #define LikeSecondary(luminance) \
218 wxRibbonShiftLuminance(secondary_hsl, luminance ## f).ToRGB()
220 m_tab_ctrl_background_colour
= LikePrimary(0.9);
221 m_tab_ctrl_background_gradient_colour
= LikePrimary(1.7);
222 m_tab_border_pen
= LikePrimary(0.75);
223 m_tab_label_colour
= LikePrimary(0.1);
224 m_tab_hover_background_top_colour
= primary_hsl
.ToRGB();
225 m_tab_hover_background_top_gradient_colour
= LikePrimary(1.6);
226 m_tab_hover_background_brush
= m_tab_hover_background_top_colour
;
227 m_tab_active_background_colour
= m_tab_ctrl_background_gradient_colour
;
228 m_tab_active_background_gradient_colour
= primary_hsl
.ToRGB();
229 m_tab_active_top_background_brush
= m_tab_active_background_colour
;
230 m_panel_label_colour
= m_tab_label_colour
;
231 m_panel_minimised_label_colour
= m_panel_label_colour
;
232 m_panel_hover_label_colour
= tertiary_hsl
.ToRGB();
233 m_page_border_pen
= m_tab_border_pen
;
234 m_panel_border_pen
= m_tab_border_pen
;
235 m_background_brush
= primary_hsl
.ToRGB();
236 m_page_hover_background_colour
= LikePrimary(1.5);
237 m_page_hover_background_gradient_colour
= LikePrimary(0.9);
238 m_panel_label_background_colour
= LikePrimary(0.85);
239 m_panel_label_background_gradient_colour
= LikePrimary(0.97);
240 m_panel_hover_label_background_gradient_colour
= secondary_hsl
.ToRGB();
241 m_panel_hover_label_background_colour
= secondary_hsl
.Lighter(0.2f
).ToRGB();
242 m_button_bar_hover_border_pen
= secondary_hsl
.ToRGB();
243 m_button_bar_hover_background_brush
= LikeSecondary(1.7);
244 m_button_bar_active_background_brush
= LikeSecondary(1.4);
245 m_button_bar_label_colour
= m_tab_label_colour
;
246 m_gallery_border_pen
= m_tab_border_pen
;
247 m_gallery_item_border_pen
= m_button_bar_hover_border_pen
;
248 m_gallery_hover_background_brush
= LikePrimary(1.2);
249 m_gallery_button_background_colour
= m_page_hover_background_colour
;
250 m_gallery_button_background_gradient_colour
= m_page_hover_background_gradient_colour
;
251 m_gallery_button_hover_background_brush
= m_button_bar_hover_background_brush
;
252 m_gallery_button_active_background_brush
= m_button_bar_active_background_brush
;
253 m_gallery_button_disabled_background_brush
= primary_hsl
.Desaturated(0.15f
).ToRGB();
254 SetColour(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR
, LikePrimary(0.1));
255 SetColour(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR
, wxColour(128, 128, 128));
256 SetColour(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR
, LikeSecondary(0.1));
257 SetColour(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR
, LikeSecondary(0.1));
258 m_toolbar_border_pen
= m_tab_border_pen
;
259 SetColour(wxRIBBON_ART_TOOLBAR_FACE_COLOUR
, LikePrimary(0.1));
260 m_tool_background_colour
= m_page_hover_background_colour
;
261 m_tool_background_gradient_colour
= m_page_hover_background_gradient_colour
;
262 m_toolbar_hover_borden_pen
= m_button_bar_hover_border_pen
;
263 m_tool_hover_background_brush
= m_button_bar_hover_background_brush
;
264 m_tool_active_background_brush
= m_button_bar_active_background_brush
;
270 void wxRibbonAUIArtProvider::DrawTabCtrlBackground(
272 wxWindow
* WXUNUSED(wnd
),
275 wxRect
gradient_rect(rect
);
276 gradient_rect
.height
--;
277 dc
.GradientFillLinear(gradient_rect
, m_tab_ctrl_background_colour
,
278 m_tab_ctrl_background_gradient_colour
, wxSOUTH
);
279 dc
.SetPen(m_tab_border_pen
);
280 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight()+1, rect
.GetBottom());
283 int wxRibbonAUIArtProvider::GetTabCtrlHeight(
285 wxWindow
* WXUNUSED(wnd
),
286 const wxRibbonPageTabInfoArray
& pages
)
291 if(pages
.GetCount() <= 1 && (m_flags
& wxRIBBON_BAR_ALWAYS_SHOW_TABS
) == 0)
293 // To preserve space, a single tab need not be displayed. We still need
294 // one pixel of border though.
298 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
300 dc
.SetFont(m_tab_active_label_font
);
301 text_height
= dc
.GetTextExtent(wxT("ABCDEFXj")).GetHeight();
303 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
305 size_t numpages
= pages
.GetCount();
306 for(size_t i
= 0; i
< numpages
; ++i
)
308 const wxRibbonPageTabInfo
& info
= pages
.Item(i
);
309 if(info
.page
->GetIcon().IsOk())
311 icon_height
= wxMax(icon_height
, info
.page
->GetIcon().GetHeight());
316 return wxMax(text_height
, icon_height
) + 10;
319 void wxRibbonAUIArtProvider::DrawTab(wxDC
& dc
,
320 wxWindow
* WXUNUSED(wnd
),
321 const wxRibbonPageTabInfo
& tab
)
323 if(tab
.rect
.height
<= 1)
326 dc
.SetFont(m_tab_label_font
);
327 dc
.SetPen(*wxTRANSPARENT_PEN
);
328 if(tab
.active
|| tab
.hovered
)
332 dc
.SetFont(m_tab_active_label_font
);
333 dc
.SetBrush(m_background_brush
);
334 dc
.DrawRectangle(tab
.rect
.x
, tab
.rect
.y
+ tab
.rect
.height
- 1,
335 tab
.rect
.width
- 1, 1);
337 wxRect
grad_rect(tab
.rect
);
338 grad_rect
.height
-= 4;
339 grad_rect
.width
-= 1;
340 grad_rect
.height
/= 2;
341 grad_rect
.y
= grad_rect
.y
+ tab
.rect
.height
- grad_rect
.height
- 1;
342 dc
.SetBrush(m_tab_active_top_background_brush
);
343 dc
.DrawRectangle(tab
.rect
.x
, tab
.rect
.y
+ 3, tab
.rect
.width
- 1,
344 grad_rect
.y
- tab
.rect
.y
- 3);
345 dc
.GradientFillLinear(grad_rect
, m_tab_active_background_colour
,
346 m_tab_active_background_gradient_colour
, wxSOUTH
);
350 wxRect
btm_rect(tab
.rect
);
351 btm_rect
.height
-= 4;
353 btm_rect
.height
/= 2;
354 btm_rect
.y
= btm_rect
.y
+ tab
.rect
.height
- btm_rect
.height
- 1;
355 dc
.SetBrush(m_tab_hover_background_brush
);
356 dc
.DrawRectangle(btm_rect
.x
, btm_rect
.y
, btm_rect
.width
,
358 wxRect
grad_rect(tab
.rect
);
359 grad_rect
.width
-= 1;
361 grad_rect
.height
= btm_rect
.y
- grad_rect
.y
;
362 dc
.GradientFillLinear(grad_rect
, m_tab_hover_background_top_colour
,
363 m_tab_hover_background_top_gradient_colour
, wxSOUTH
);
366 wxPoint border_points
[5];
367 border_points
[0] = wxPoint(0, 3);
368 border_points
[1] = wxPoint(1, 2);
369 border_points
[2] = wxPoint(tab
.rect
.width
- 3, 2);
370 border_points
[3] = wxPoint(tab
.rect
.width
- 1, 4);
371 border_points
[4] = wxPoint(tab
.rect
.width
- 1, tab
.rect
.height
- 1);
373 dc
.SetPen(m_tab_border_pen
);
374 dc
.DrawLines(sizeof(border_points
)/sizeof(wxPoint
), border_points
, tab
.rect
.x
, tab
.rect
.y
);
377 dc
.GetClippingBox(old_clip
);
378 bool is_first_tab
= false;
379 wxRibbonBar
* bar
= wxDynamicCast(tab
.page
->GetParent(), wxRibbonBar
);
380 if(bar
&& bar
->GetPage(0) == tab
.page
)
384 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
)
386 icon
= tab
.page
->GetIcon();
387 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) == 0)
389 int x
= tab
.rect
.x
+ (tab
.rect
.width
- icon
.GetWidth()) / 2;
390 dc
.DrawBitmap(icon
, x
, tab
.rect
.y
+ 1 + (tab
.rect
.height
- 1 -
391 icon
.GetHeight()) / 2, true);
394 if(m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
)
396 wxString label
= tab
.page
->GetLabel();
399 dc
.SetTextForeground(m_tab_label_colour
);
400 dc
.SetBackgroundMode(wxTRANSPARENT
);
404 offset
+= icon
.GetWidth() + 2;
407 dc
.GetTextExtent(label
, &text_width
, &text_height
);
408 int x
= (tab
.rect
.width
- 2 - text_width
- offset
) / 2;
413 int width
= tab
.rect
.width
- x
- 2;
414 x
+= tab
.rect
.x
+ offset
;
415 int y
= tab
.rect
.y
+ (tab
.rect
.height
- text_height
) / 2;
418 dc
.DrawBitmap(icon
, x
- offset
, tab
.rect
.y
+ (tab
.rect
.height
-
419 icon
.GetHeight()) / 2, true);
421 dc
.SetClippingRegion(x
, tab
.rect
.y
, width
, tab
.rect
.height
);
422 dc
.DrawText(label
, x
, y
);
426 // Draw the left hand edge of the tab only for the first tab (subsequent
427 // tabs use the right edge of the prior tab as their left edge). As this is
428 // outside the rectangle for the tab, only draw it if the leftmost part of
429 // the tab is within the clip rectangle (the clip region has to be cleared
430 // to draw outside the tab).
431 if(is_first_tab
&& old_clip
.x
<= tab
.rect
.x
432 && tab
.rect
.x
< old_clip
.x
+ old_clip
.width
)
434 dc
.DestroyClippingRegion();
435 dc
.DrawLine(tab
.rect
.x
- 1, tab
.rect
.y
+ 4, tab
.rect
.x
- 1,
436 tab
.rect
.y
+ tab
.rect
.height
- 1);
440 void wxRibbonAUIArtProvider::GetBarTabWidth(
442 wxWindow
* WXUNUSED(wnd
),
443 const wxString
& label
,
444 const wxBitmap
& bitmap
,
446 int* small_begin_need_separator
,
447 int* small_must_have_separator
,
452 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_LABELS
) && !label
.IsEmpty())
454 dc
.SetFont(m_tab_active_label_font
);
455 width
+= dc
.GetTextExtent(label
).GetWidth();
456 min
+= wxMin(30, width
); // enough for a few chars
459 // gap between label and bitmap
464 if((m_flags
& wxRIBBON_BAR_SHOW_PAGE_ICONS
) && bitmap
.IsOk())
466 width
+= bitmap
.GetWidth();
467 min
+= bitmap
.GetWidth();
474 if(small_begin_need_separator
!= NULL
)
476 *small_begin_need_separator
= min
;
478 if(small_must_have_separator
!= NULL
)
480 *small_must_have_separator
= min
;
488 void wxRibbonAUIArtProvider::DrawTabSeparator(
490 wxWindow
* WXUNUSED(wnd
),
491 const wxRect
& WXUNUSED(rect
),
492 double WXUNUSED(visibility
))
494 // No explicit separators between tabs
497 void wxRibbonAUIArtProvider::DrawPageBackground(
499 wxWindow
* WXUNUSED(wnd
),
502 dc
.SetPen(*wxTRANSPARENT_PEN
);
503 dc
.SetBrush(m_background_brush
);
504 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
, rect
.width
- 2, rect
.height
- 1);
506 dc
.SetPen(m_page_border_pen
);
507 dc
.DrawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
508 dc
.DrawLine(rect
.GetRight(), rect
.y
, rect
.GetRight(), rect
.y
+rect
.height
);
509 dc
.DrawLine(rect
.x
, rect
.GetBottom(), rect
.GetRight()+1, rect
.GetBottom());
512 wxSize
wxRibbonAUIArtProvider::GetScrollButtonMinimumSize(
514 wxWindow
* WXUNUSED(wnd
),
515 long WXUNUSED(style
))
517 return wxSize(11, 11);
520 void wxRibbonAUIArtProvider::DrawScrollButton(
522 wxWindow
* WXUNUSED(wnd
),
526 wxRect
true_rect(rect
);
527 wxPoint arrow_points
[3];
529 if((style
& wxRIBBON_SCROLL_BTN_FOR_MASK
) == wxRIBBON_SCROLL_BTN_FOR_TABS
)
532 true_rect
.height
-= 2;
533 dc
.SetPen(m_tab_border_pen
);
537 dc
.SetPen(*wxTRANSPARENT_PEN
);
538 dc
.SetBrush(m_background_brush
);
539 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
540 dc
.SetPen(m_page_border_pen
);
543 switch(style
& wxRIBBON_SCROLL_BTN_DIRECTION_MASK
)
545 case wxRIBBON_SCROLL_BTN_LEFT
:
546 dc
.DrawLine(true_rect
.GetRight(), true_rect
.y
, true_rect
.GetRight(),
547 true_rect
.y
+ true_rect
.height
);
548 arrow_points
[0] = wxPoint(rect
.width
/ 2 - 2, rect
.height
/ 2);
549 arrow_points
[1] = arrow_points
[0] + wxPoint(5, -5);
550 arrow_points
[2] = arrow_points
[0] + wxPoint(5, 5);
552 case wxRIBBON_SCROLL_BTN_RIGHT
:
553 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
,
554 true_rect
.y
+ true_rect
.height
);
555 arrow_points
[0] = wxPoint(rect
.width
/ 2 + 3, rect
.height
/ 2);
556 arrow_points
[1] = arrow_points
[0] - wxPoint(5, -5);
557 arrow_points
[2] = arrow_points
[0] - wxPoint(5, 5);
559 case wxRIBBON_SCROLL_BTN_DOWN
:
560 dc
.DrawLine(true_rect
.x
, true_rect
.y
, true_rect
.x
+ true_rect
.width
,
562 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 + 3);
563 arrow_points
[1] = arrow_points
[0] - wxPoint( 5, 5);
564 arrow_points
[2] = arrow_points
[0] - wxPoint(-5, 5);
566 case wxRIBBON_SCROLL_BTN_UP
:
567 dc
.DrawLine(true_rect
.x
, true_rect
.GetBottom(),
568 true_rect
.x
+ true_rect
.width
, true_rect
.GetBottom());
569 arrow_points
[0] = wxPoint(rect
.width
/ 2, rect
.height
/ 2 - 2);
570 arrow_points
[1] = arrow_points
[0] + wxPoint( 5, 5);
571 arrow_points
[2] = arrow_points
[0] + wxPoint(-5, 5);
579 if(style
& wxRIBBON_SCROLL_BTN_ACTIVE
)
585 dc
.SetPen(*wxTRANSPARENT_PEN
);
586 wxBrush
B(m_tab_label_colour
);
588 dc
.DrawPolygon(sizeof(arrow_points
)/sizeof(wxPoint
), arrow_points
, x
, y
);
591 wxSize
wxRibbonAUIArtProvider::GetPanelSize(
593 const wxRibbonPanel
* wnd
,
595 wxPoint
* client_offset
)
597 dc
.SetFont(m_panel_label_font
);
598 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
599 int label_height
= label_size
.GetHeight() + 5;
600 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
602 client_size
.IncBy(4, label_height
+ 6);
604 *client_offset
= wxPoint(2, label_height
+ 3);
608 client_size
.IncBy(6, label_height
+ 4);
610 *client_offset
= wxPoint(3, label_height
+ 2);
615 wxSize
wxRibbonAUIArtProvider::GetPanelClientSize(
617 const wxRibbonPanel
* wnd
,
619 wxPoint
* client_offset
)
621 dc
.SetFont(m_panel_label_font
);
622 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
623 int label_height
= label_size
.GetHeight() + 5;
624 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
626 size
.DecBy(4, label_height
+ 6);
628 *client_offset
= wxPoint(2, label_height
+ 3);
632 size
.DecBy(6, label_height
+ 4);
634 *client_offset
= wxPoint(3, label_height
+ 2);
639 void wxRibbonAUIArtProvider::DrawPanelBackground(
644 dc
.SetPen(*wxTRANSPARENT_PEN
);
645 dc
.SetBrush(m_background_brush
);
646 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
648 wxRect
true_rect(rect
);
649 RemovePanelPadding(&true_rect
);
651 dc
.SetPen(m_panel_border_pen
);
652 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
653 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
656 true_rect
.width
-= 2;
659 dc
.SetFont(m_panel_label_font
);
660 wxSize label_size
= dc
.GetTextExtent(wnd
->GetLabel());
661 int label_height
= label_size
.GetHeight() + 5;
662 wxRect
label_rect(true_rect
);
663 label_rect
.height
= label_height
- 1;
664 dc
.DrawLine(label_rect
.x
, label_rect
.y
+ label_rect
.height
,
665 label_rect
.x
+ label_rect
.width
, label_rect
.y
+ label_rect
.height
);
667 wxColour label_bg_colour
= m_panel_label_background_colour
;
668 wxColour label_bg_grad_colour
= m_panel_label_background_gradient_colour
;
671 label_bg_colour
= m_panel_hover_label_background_colour
;
672 label_bg_grad_colour
= m_panel_hover_label_background_gradient_colour
;
673 dc
.SetTextForeground(m_panel_hover_label_colour
);
677 dc
.SetTextForeground(m_panel_label_colour
);
679 dc
.GradientFillLinear(label_rect
,
681 label_bg_grad_colour
, label_bg_colour
, wxSOUTH
);
683 label_bg_colour
, label_bg_grad_colour
, wxSOUTH
);
685 dc
.SetFont(m_panel_label_font
);
686 dc
.DrawText(wnd
->GetLabel(), label_rect
.x
+ 3, label_rect
.y
+ 2);
690 wxRect
gradient_rect(true_rect
);
691 gradient_rect
.y
+= label_rect
.height
+ 1;
692 gradient_rect
.height
= true_rect
.height
- label_rect
.height
- 3;
694 wxColour colour
= m_page_hover_background_gradient_colour
;
695 wxColour gradient
= m_page_hover_background_colour
;
697 wxColour colour
= m_page_hover_background_colour
;
698 wxColour gradient
= m_page_hover_background_gradient_colour
;
700 dc
.GradientFillLinear(gradient_rect
, colour
, gradient
, wxSOUTH
);
704 void wxRibbonAUIArtProvider::DrawMinimisedPanel(
710 dc
.SetPen(*wxTRANSPARENT_PEN
);
711 dc
.SetBrush(m_background_brush
);
712 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
714 wxRect
true_rect(rect
);
715 RemovePanelPadding(&true_rect
);
717 dc
.SetPen(m_panel_border_pen
);
718 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
719 dc
.DrawRectangle(true_rect
.x
, true_rect
.y
, true_rect
.width
, true_rect
.height
);
720 true_rect
.Deflate(1);
722 if(wnd
->IsHovered() || wnd
->GetExpandedPanel())
724 wxColour colour
= m_page_hover_background_colour
;
725 wxColour gradient
= m_page_hover_background_gradient_colour
;
727 if(!wnd
->GetExpandedPanel())
729 if(wnd
->GetExpandedPanel())
732 wxColour temp
= colour
;
736 dc
.GradientFillLinear(true_rect
, colour
, gradient
, wxSOUTH
);
740 DrawMinimisedPanelCommon(dc
, wnd
, true_rect
, &preview
);
742 dc
.SetPen(m_panel_border_pen
);
743 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
744 dc
.DrawRectangle(preview
.x
, preview
.y
, preview
.width
, preview
.height
);
746 wxRect
preview_caption_rect(preview
);
747 preview_caption_rect
.height
= 7;
748 preview
.y
+= preview_caption_rect
.height
;
749 preview
.height
-= preview_caption_rect
.height
;
751 dc
.GradientFillLinear(preview_caption_rect
,
752 m_panel_hover_label_background_gradient_colour
,
753 m_panel_hover_label_background_colour
, wxSOUTH
);
754 dc
.GradientFillLinear(preview
,
755 m_page_hover_background_gradient_colour
,
756 m_page_hover_background_colour
, wxSOUTH
);
758 dc
.GradientFillLinear(preview_caption_rect
,
759 m_panel_hover_label_background_colour
,
760 m_panel_hover_label_background_gradient_colour
, wxSOUTH
);
761 dc
.GradientFillLinear(preview
,
762 m_page_hover_background_colour
,
763 m_page_hover_background_gradient_colour
, wxSOUTH
);
768 dc
.DrawBitmap(bitmap
, preview
.x
+ (preview
.width
- bitmap
.GetWidth()) / 2,
769 preview
.y
+ (preview
.height
- bitmap
.GetHeight()) / 2, true);
773 void wxRibbonAUIArtProvider::DrawPartialPanelBackground(wxDC
& dc
,
774 wxWindow
* wnd
, const wxRect
& rect
)
776 dc
.SetPen(*wxTRANSPARENT_PEN
);
777 dc
.SetBrush(m_background_brush
);
778 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
780 wxPoint
offset(wnd
->GetPosition());
781 wxWindow
* parent
= wnd
->GetParent();
782 wxRibbonPanel
* panel
= NULL
;
784 for(; parent
; parent
= parent
->GetParent())
786 panel
= wxDynamicCast(parent
, wxRibbonPanel
);
789 if(!panel
->IsHovered())
793 offset
+= parent
->GetPosition();
798 wxRect
background(panel
->GetSize());
799 RemovePanelPadding(&background
);
801 background
.width
-= 2;
802 dc
.SetFont(m_panel_label_font
);
803 int caption_height
= dc
.GetTextExtent(panel
->GetLabel()).GetHeight() + 7;
804 background
.y
+= caption_height
- 1;
805 background
.height
-= caption_height
;
807 wxRect
paint_rect(rect
);
808 paint_rect
.x
+= offset
.x
;
809 paint_rect
.y
+= offset
.y
;
811 wxColour bg_clr
, bg_grad_clr
;
813 bg_grad_clr
= m_page_hover_background_colour
;
814 bg_clr
= m_page_hover_background_gradient_colour
;
816 bg_clr
= m_page_hover_background_colour
;
817 bg_grad_clr
= m_page_hover_background_gradient_colour
;
820 paint_rect
.Intersect(background
);
821 if(!paint_rect
.IsEmpty())
823 wxColour
starting_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
824 paint_rect
.y
, background
.y
, background
.y
+ background
.height
));
825 wxColour
ending_colour(wxRibbonInterpolateColour(bg_clr
, bg_grad_clr
,
826 paint_rect
.y
+ paint_rect
.height
, background
.y
,
827 background
.y
+ background
.height
));
828 paint_rect
.x
-= offset
.x
;
829 paint_rect
.y
-= offset
.y
;
830 dc
.GradientFillLinear(paint_rect
, starting_colour
, ending_colour
835 void wxRibbonAUIArtProvider::DrawGalleryBackground(
837 wxRibbonGallery
* wnd
,
840 DrawPartialPanelBackground(dc
, wnd
, rect
);
844 dc
.SetPen(*wxTRANSPARENT_PEN
);
845 dc
.SetBrush(m_gallery_hover_background_brush
);
846 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
848 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2,
853 dc
.DrawRectangle(rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 16,
858 dc
.SetPen(m_gallery_border_pen
);
859 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
860 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
862 DrawGalleryBackgroundCommon(dc
, wnd
, rect
);
865 void wxRibbonAUIArtProvider::DrawGalleryButton(wxDC
& dc
, wxRect rect
,
866 wxRibbonGalleryButtonState state
, wxBitmap
* bitmaps
)
868 int extra_height
= 0;
870 wxRect
reduced_rect(rect
);
871 reduced_rect
.Deflate(1);
872 if(m_flags
& wxRIBBON_BAR_FLOW_VERTICAL
)
874 reduced_rect
.width
++;
879 reduced_rect
.height
++;
886 case wxRIBBON_GALLERY_BUTTON_NORMAL
:
887 dc
.GradientFillLinear(reduced_rect
,
888 m_gallery_button_background_colour
,
889 m_gallery_button_background_gradient_colour
, wxSOUTH
);
890 btn_bitmap
= bitmaps
[0];
892 case wxRIBBON_GALLERY_BUTTON_HOVERED
:
893 dc
.SetPen(m_gallery_item_border_pen
);
894 dc
.SetBrush(m_gallery_button_hover_background_brush
);
895 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
896 rect
.height
+ extra_height
);
897 btn_bitmap
= bitmaps
[1];
899 case wxRIBBON_GALLERY_BUTTON_ACTIVE
:
900 dc
.SetPen(m_gallery_item_border_pen
);
901 dc
.SetBrush(m_gallery_button_active_background_brush
);
902 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+ extra_width
,
903 rect
.height
+ extra_height
);
904 btn_bitmap
= bitmaps
[2];
906 case wxRIBBON_GALLERY_BUTTON_DISABLED
:
907 dc
.SetPen(*wxTRANSPARENT_PEN
);
908 dc
.SetBrush(m_gallery_button_disabled_background_brush
);
909 dc
.DrawRectangle(reduced_rect
.x
, reduced_rect
.y
, reduced_rect
.width
,
910 reduced_rect
.height
);
911 btn_bitmap
= bitmaps
[3];
915 dc
.DrawBitmap(btn_bitmap
, reduced_rect
.x
+ reduced_rect
.width
/ 2 - 2,
916 (rect
.y
+ rect
.height
/ 2) - 2, true);
919 void wxRibbonAUIArtProvider::DrawGalleryItemBackground(
921 wxRibbonGallery
* wnd
,
923 wxRibbonGalleryItem
* item
)
925 if(wnd
->GetHoveredItem() != item
&& wnd
->GetActiveItem() != item
&&
926 wnd
->GetSelection() != item
)
929 dc
.SetPen(m_gallery_item_border_pen
);
930 if(wnd
->GetActiveItem() == item
|| wnd
->GetSelection() == item
)
931 dc
.SetBrush(m_gallery_button_active_background_brush
);
933 dc
.SetBrush(m_gallery_button_hover_background_brush
);
935 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
938 void wxRibbonAUIArtProvider::DrawButtonBarBackground(
943 DrawPartialPanelBackground(dc
, wnd
, rect
);
946 void wxRibbonAUIArtProvider::DrawButtonBarButton(
948 wxWindow
* WXUNUSED(wnd
),
950 wxRibbonButtonKind kind
,
952 const wxString
& label
,
953 const wxBitmap
& bitmap_large
,
954 const wxBitmap
& bitmap_small
)
956 if(state
& (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
957 | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
))
959 dc
.SetPen(m_button_bar_hover_border_pen
);
961 wxRect
bg_rect(rect
);
964 if(kind
== wxRIBBON_BUTTON_HYBRID
)
966 switch(state
& wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK
)
968 case wxRIBBON_BUTTONBAR_BUTTON_LARGE
:
970 int iYBorder
= rect
.y
+ bitmap_large
.GetHeight() + 4;
971 wxRect
partial_bg(rect
);
972 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
974 partial_bg
.SetBottom(iYBorder
- 1);
978 partial_bg
.height
-= (iYBorder
- partial_bg
.y
+ 1);
979 partial_bg
.y
= iYBorder
+ 1;
981 dc
.DrawLine(rect
.x
, iYBorder
, rect
.x
+ rect
.width
, iYBorder
);
982 bg_rect
.Intersect(partial_bg
);
985 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM
:
988 if(state
& wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED
)
990 bg_rect
.width
-= iArrowWidth
;
991 dc
.DrawLine(bg_rect
.x
+ bg_rect
.width
,
992 rect
.y
, bg_rect
.x
+ bg_rect
.width
,
993 rect
.y
+ rect
.height
);
998 bg_rect
.x
+= bg_rect
.width
- iArrowWidth
;
999 bg_rect
.width
= iArrowWidth
;
1000 dc
.DrawLine(bg_rect
.x
- 1, rect
.y
,
1001 bg_rect
.x
- 1, rect
.y
+ rect
.height
);
1005 case wxRIBBON_BUTTONBAR_BUTTON_SMALL
:
1010 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1011 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1013 dc
.SetPen(*wxTRANSPARENT_PEN
);
1014 if(state
& wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK
)
1015 dc
.SetBrush(m_button_bar_active_background_brush
);
1017 dc
.SetBrush(m_button_bar_hover_background_brush
);
1018 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1021 dc
.SetFont(m_button_bar_label_font
);
1022 dc
.SetTextForeground(m_button_bar_label_colour
);
1023 DrawButtonBarButtonForeground(dc
, rect
, kind
, state
, label
, bitmap_large
,
1027 void wxRibbonAUIArtProvider::DrawToolBarBackground(
1032 DrawPartialPanelBackground(dc
, wnd
, rect
);
1035 void wxRibbonAUIArtProvider::DrawToolGroupBackground(
1037 wxWindow
* WXUNUSED(wnd
),
1040 dc
.SetPen(m_toolbar_border_pen
);
1041 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1042 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
1043 wxRect
bg_rect(rect
);
1045 dc
.GradientFillLinear(bg_rect
, m_tool_background_colour
,
1046 m_tool_background_gradient_colour
, wxSOUTH
);
1049 void wxRibbonAUIArtProvider::DrawTool(
1051 wxWindow
* WXUNUSED(wnd
),
1053 const wxBitmap
& bitmap
,
1054 wxRibbonButtonKind kind
,
1057 wxRect
bg_rect(rect
);
1059 if((state
& wxRIBBON_TOOLBAR_TOOL_LAST
) == 0)
1061 bool is_custom_bg
= (state
& (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK
|
1062 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)) != 0;
1063 bool is_split_hybrid
= kind
== wxRIBBON_BUTTON_HYBRID
&& is_custom_bg
;
1068 dc
.SetPen(*wxTRANSPARENT_PEN
);
1069 dc
.SetBrush(m_tool_hover_background_brush
);
1070 dc
.DrawRectangle(bg_rect
.x
, bg_rect
.y
, bg_rect
.width
, bg_rect
.height
);
1071 if(state
& wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK
)
1073 wxRect
active_rect(bg_rect
);
1074 if(kind
== wxRIBBON_BUTTON_HYBRID
)
1076 active_rect
.width
-= 8;
1077 if(state
& wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE
)
1079 active_rect
.x
+= active_rect
.width
;
1080 active_rect
.width
= 8;
1083 dc
.SetBrush(m_tool_active_background_brush
);
1084 dc
.DrawRectangle(active_rect
.x
, active_rect
.y
, active_rect
.width
,
1085 active_rect
.height
);
1091 dc
.SetPen(m_toolbar_hover_borden_pen
);
1093 dc
.SetPen(m_toolbar_border_pen
);
1094 if((state
& wxRIBBON_TOOLBAR_TOOL_FIRST
) == 0)
1097 if(!dc
.GetPixel(rect
.x
, rect
.y
+ 1, &existing
) ||
1098 existing
!= m_toolbar_hover_borden_pen
.GetColour())
1100 dc
.DrawLine(rect
.x
, rect
.y
+ 1, rect
.x
, rect
.y
+ rect
.height
- 1);
1105 wxRect
border_rect(bg_rect
);
1106 border_rect
.Inflate(1);
1107 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1108 dc
.DrawRectangle(border_rect
.x
, border_rect
.y
, border_rect
.width
,
1109 border_rect
.height
);
1113 int avail_width
= bg_rect
.GetWidth();
1114 if(kind
!= wxRIBBON_BUTTON_NORMAL
)
1119 dc
.DrawLine(rect
.x
+ avail_width
+ 1, rect
.y
,
1120 rect
.x
+ avail_width
+ 1, rect
.y
+ rect
.height
);
1122 dc
.DrawBitmap(m_toolbar_drop_bitmap
, bg_rect
.x
+ avail_width
+ 2,
1123 bg_rect
.y
+ (bg_rect
.height
/ 2) - 2, true);
1125 dc
.DrawBitmap(bitmap
, bg_rect
.x
+ (avail_width
- bitmap
.GetWidth()) / 2,
1126 bg_rect
.y
+ (bg_rect
.height
- bitmap
.GetHeight()) / 2, true);
1129 #endif // wxUSE_RIBBON