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