]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/art_msw.cpp
32d0e2acdb050cf13dd4004b00a42c69810036ca
[wxWidgets.git] / src / ribbon / art_msw.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/art_msw.cpp
3 // Purpose: MSW style art provider for ribbon interface
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-05-25
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 #include "wx/dcmemory.h"
19 #include "wx/ribbon/art.h"
20
21 #if wxUSE_RIBBON
22
23 #include "wx/ribbon/art_internal.h"
24 #include "wx/ribbon/bar.h"
25 #include "wx/ribbon/buttonbar.h"
26 #include "wx/ribbon/gallery.h"
27 #include "wx/ribbon/toolbar.h"
28
29 #ifndef WX_PRECOMP
30 #endif
31
32 #ifdef __WXMSW__
33 #include "wx/msw/private.h"
34 #endif
35
36 static const char* const gallery_up_xpm[] = {
37 "5 5 2 1",
38 " c None",
39 "x c #FF00FF",
40 " ",
41 " x ",
42 " xxx ",
43 "xxxxx",
44 " "};
45
46 static const char* const gallery_down_xpm[] = {
47 "5 5 2 1",
48 " c None",
49 "x c #FF00FF",
50 " ",
51 "xxxxx",
52 " xxx ",
53 " x ",
54 " "};
55
56 static const char* const gallery_left_xpm[] = {
57 "5 5 2 1",
58 " c None",
59 "x c #FF00FF",
60 " x ",
61 " xx ",
62 " xxx ",
63 " xx ",
64 " x "};
65
66 static const char* const gallery_right_xpm[] = {
67 "5 5 2 1",
68 " c None",
69 "x c #FF00FF",
70 " x ",
71 " xx ",
72 " xxx ",
73 " xx ",
74 " x "};
75
76 static const char* const gallery_extension_xpm[] = {
77 "5 5 2 1",
78 " c None",
79 "x c #FF00FF",
80 "xxxxx",
81 " ",
82 "xxxxx",
83 " xxx ",
84 " x "};
85
86 wxRibbonMSWArtProvider::wxRibbonMSWArtProvider(bool set_colour_scheme)
87 {
88 m_flags = 0;
89 m_tab_label_font = *wxNORMAL_FONT;
90 m_button_bar_label_font = m_tab_label_font;
91 m_panel_label_font = m_tab_label_font;
92
93 if(set_colour_scheme)
94 {
95 SetColourScheme(
96 wxColour(194, 216, 241),
97 wxColour(255, 223, 114),
98 wxColour( 0, 0, 0));
99 }
100
101 m_cached_tab_separator_visibility = -10.0; // valid visibilities are in range [0, 1]
102 m_tab_separation_size = 3;
103 m_page_border_left = 2;
104 m_page_border_top = 1;
105 m_page_border_right = 2;
106 m_page_border_bottom = 3;
107 m_panel_x_separation_size = 1;
108 m_panel_y_separation_size = 1;
109 m_tool_group_separation_size = 3;
110 m_gallery_bitmap_padding_left_size = 4;
111 m_gallery_bitmap_padding_right_size = 4;
112 m_gallery_bitmap_padding_top_size = 4;
113 m_gallery_bitmap_padding_bottom_size = 4;
114 }
115
116 wxRibbonMSWArtProvider::~wxRibbonMSWArtProvider()
117 {
118 }
119
120 void wxRibbonMSWArtProvider::GetColourScheme(
121 wxColour* primary,
122 wxColour* secondary,
123 wxColour* tertiary) const
124 {
125 if(primary != NULL)
126 *primary = m_primary_scheme_colour;
127 if(secondary != NULL)
128 *secondary = m_secondary_scheme_colour;
129 if(tertiary != NULL)
130 *tertiary = m_tertiary_scheme_colour;
131 }
132
133 void wxRibbonMSWArtProvider::SetColourScheme(
134 const wxColour& primary,
135 const wxColour& secondary,
136 const wxColour& tertiary)
137 {
138 m_primary_scheme_colour = primary;
139 m_secondary_scheme_colour = secondary;
140 m_tertiary_scheme_colour = tertiary;
141
142 wxRibbonHSLColour primary_hsl(primary);
143 wxRibbonHSLColour secondary_hsl(secondary);
144 // tertiary not used for anything
145
146 // Map primary saturation from [0, 1] to [.25, .75]
147 primary_hsl.saturation = cos(primary_hsl.saturation * M_PI) * -0.25 + 0.5;
148
149 // Map primary luminance from [0, 1] to [.23, .83]
150 primary_hsl.luminance = cos(primary_hsl.luminance * M_PI) * -0.3 + 0.53;
151
152 // Map secondary saturation from [0, 1] to [0.16, 0.84]
153 secondary_hsl.saturation = cos(secondary_hsl.saturation * M_PI) * -0.34 + 0.5;
154
155 // Map secondary luminance from [0, 1] to [0.1, 0.9]
156 secondary_hsl.luminance = cos(secondary_hsl.luminance * M_PI) * -0.4 + 0.5;
157
158 #define LikePrimary(h, s, l) \
159 primary_hsl.ShiftHue(h ## f).Saturated(s ## f).Lighter(l ## f).ToRGB()
160 #define LikeSecondary(h, s, l) \
161 secondary_hsl.ShiftHue(h ## f).Saturated(s ## f).Lighter(l ## f).ToRGB()
162
163 m_page_border_pen = LikePrimary(1.4, 0.00, -0.08);
164
165 m_page_background_top_colour = LikePrimary(-0.1, -0.03, 0.12);
166 m_page_hover_background_top_colour = LikePrimary(-2.8, 0.27, 0.17);
167 m_page_background_top_gradient_colour = LikePrimary(0.1, -0.10, 0.08);
168 m_page_hover_background_top_gradient_colour = LikePrimary(3.2, 0.16, 0.13);
169 m_page_background_colour = LikePrimary(0.4, -0.09, 0.05);
170 m_page_hover_background_colour = LikePrimary(0.1, 0.19, 0.10);
171 m_page_background_gradient_colour = LikePrimary(-3.2, 0.27, 0.10);
172 m_page_hover_background_gradient_colour = LikePrimary(1.8, 0.01, 0.15);
173
174 m_tab_active_background_colour = LikePrimary(-0.1, -0.31, 0.16);
175 m_tab_active_background_gradient_colour = LikePrimary(-0.1, -0.03, 0.12);
176 m_tab_separator_colour = LikePrimary(0.9, 0.24, 0.05);
177 m_tab_ctrl_background_brush = LikePrimary(1.0, 0.39, 0.07);
178 m_tab_hover_background_colour = LikePrimary(1.3, 0.15, 0.10);
179 m_tab_hover_background_top_colour = LikePrimary(1.4, 0.36, 0.08);
180 m_tab_border_pen = LikePrimary(1.4, 0.03, -0.05);
181 m_tab_separator_gradient_colour = LikePrimary(1.7, -0.15, -0.18);
182 m_tab_hover_background_top_gradient_colour = LikePrimary(1.8, 0.34, 0.13);
183 m_tab_label_colour = LikePrimary(4.3, 0.13, -0.49);
184 m_tab_hover_background_gradient_colour = LikeSecondary(-1.5, -0.34, 0.01);
185
186 m_panel_minimised_border_gradient_pen = LikePrimary(-6.9, -0.17, -0.09);
187 m_panel_minimised_border_pen = LikePrimary(-5.3, -0.24, -0.06);
188 m_panel_border_gradient_pen = LikePrimary(-5.2, -0.15, -0.06);
189 m_panel_border_pen = LikePrimary(-2.8, -0.32, 0.02);
190 m_panel_label_background_brush = LikePrimary(-1.5, 0.03, 0.05);
191 m_panel_active_background_gradient_colour = LikePrimary(0.5, 0.34, 0.05);
192 m_panel_hover_label_background_brush = LikePrimary(1.0, 0.30, 0.09);
193 m_panel_active_background_top_gradient_colour = LikePrimary(1.4, -0.17, -0.13);
194 m_panel_active_background_colour = LikePrimary(1.6, -0.18, -0.18);
195 m_panel_active_background_top_colour = LikePrimary(1.7, -0.20, -0.03);
196 m_panel_label_colour = LikePrimary(2.8, -0.14, -0.35);
197 m_panel_hover_label_colour = m_panel_label_colour;
198 m_panel_minimised_label_colour = m_tab_label_colour;
199
200 m_gallery_button_disabled_background_colour = LikePrimary(-2.8, -0.46, 0.09);
201 m_gallery_button_disabled_background_top_brush = LikePrimary(-2.8, -0.36, 0.15);
202 m_gallery_hover_background_brush = LikePrimary(-0.8, 0.05, 0.15);
203 m_gallery_border_pen = LikePrimary(0.7, -0.02, 0.03);
204 m_gallery_button_background_top_brush = LikePrimary(0.8, 0.34, 0.13);
205 m_gallery_button_background_colour = LikePrimary(1.3, 0.10, 0.08);
206 // SetColour used so that the relevant bitmaps are generated
207 SetColour(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR, LikePrimary(1.4, -0.21, -0.23));
208 SetColour(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR, LikePrimary(1.5, -0.24, -0.29));
209 SetColour(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR, LikePrimary(1.5, -0.24, -0.29));
210 SetColour(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR, LikePrimary(0.0, -1.0, 0.0));
211 m_gallery_button_disabled_background_gradient_colour = LikePrimary(1.5, -0.43, 0.12);
212 m_gallery_button_background_gradient_colour = LikePrimary(1.7, 0.11, 0.09);
213 m_gallery_item_border_pen = LikeSecondary(-3.9, -0.16, -0.14);
214 m_gallery_button_hover_background_colour = LikeSecondary(-0.9, 0.16, -0.07);
215 m_gallery_button_hover_background_gradient_colour = LikeSecondary(0.1, 0.12, 0.03);
216 m_gallery_button_hover_background_top_brush = LikeSecondary(4.3, 0.16, 0.17);
217
218 m_gallery_button_active_background_colour = LikeSecondary(-9.9, 0.03, -0.22);
219 m_gallery_button_active_background_gradient_colour = LikeSecondary(-9.5, 0.14, -0.11);
220 m_gallery_button_active_background_top_brush = LikeSecondary(-9.0, 0.15, -0.08);
221
222 m_button_bar_label_colour = m_tab_label_colour;
223 m_button_bar_hover_border_pen = LikeSecondary(-6.2, -0.47, -0.14);
224 m_button_bar_hover_background_gradient_colour = LikeSecondary(-0.6, 0.16, 0.04);
225 m_button_bar_hover_background_colour = LikeSecondary(-0.2, 0.16, -0.10);
226 m_button_bar_hover_background_top_gradient_colour = LikeSecondary(0.2, 0.16, 0.03);
227 m_button_bar_hover_background_top_colour = LikeSecondary(8.8, 0.16, 0.17);
228 m_button_bar_active_border_pen = LikeSecondary(-6.2, -0.47, -0.25);
229 m_button_bar_active_background_top_colour = LikeSecondary(-8.4, 0.08, 0.06);
230 m_button_bar_active_background_top_gradient_colour = LikeSecondary(-9.7, 0.13, -0.07);
231 m_button_bar_active_background_colour = LikeSecondary(-9.9, 0.14, -0.14);
232 m_button_bar_active_background_gradient_colour = LikeSecondary(-8.7, 0.17, -0.03);
233
234 m_toolbar_border_pen = LikePrimary(1.4, -0.21, -0.16);
235 SetColour(wxRIBBON_ART_TOOLBAR_FACE_COLOUR, LikePrimary(1.4, -0.17, -0.22));
236 m_tool_background_top_colour = LikePrimary(-1.9, -0.07, 0.06);
237 m_tool_background_top_gradient_colour = LikePrimary(1.4, 0.12, 0.08);
238 m_tool_background_colour = LikePrimary(1.4, -0.09, 0.03);
239 m_tool_background_gradient_colour = LikePrimary(1.9, 0.11, 0.09);
240 m_tool_hover_background_top_colour = LikeSecondary(3.4, 0.11, 0.16);
241 m_tool_hover_background_top_gradient_colour = LikeSecondary(-1.4, 0.04, 0.08);
242 m_tool_hover_background_colour = LikeSecondary(-1.8, 0.16, -0.12);
243 m_tool_hover_background_gradient_colour = LikeSecondary(-2.6, 0.16, 0.05);
244 m_tool_active_background_top_colour = LikeSecondary(-9.9, -0.12, -0.09);
245 m_tool_active_background_top_gradient_colour = LikeSecondary(-8.5, 0.16, -0.12);
246 m_tool_active_background_colour = LikeSecondary(-7.9, 0.16, -0.20);
247 m_tool_active_background_gradient_colour = LikeSecondary(-6.6, 0.16, -0.10);
248
249 #undef LikePrimary
250 #undef LikeSecondary
251
252 // Invalidate cached tab separator
253 m_cached_tab_separator_visibility = -1.0;
254 }
255
256 wxRibbonArtProvider* wxRibbonMSWArtProvider::Clone() const
257 {
258 wxRibbonMSWArtProvider *copy = new wxRibbonMSWArtProvider;
259 CloneTo(copy);
260 return copy;
261 }
262
263 void wxRibbonMSWArtProvider::CloneTo(wxRibbonMSWArtProvider* copy) const
264 {
265 for(int i = 0; i < 4; ++i)
266 {
267 copy->m_gallery_up_bitmap[i] = m_gallery_up_bitmap[i];
268 copy->m_gallery_down_bitmap[i] = m_gallery_down_bitmap[i];
269 copy->m_gallery_extension_bitmap[i] = m_gallery_extension_bitmap[i];
270 }
271 copy->m_toolbar_drop_bitmap = m_toolbar_drop_bitmap;
272
273 copy->m_primary_scheme_colour = m_primary_scheme_colour;
274 copy->m_secondary_scheme_colour = m_secondary_scheme_colour;
275 copy->m_tertiary_scheme_colour = m_tertiary_scheme_colour;
276
277 copy->m_button_bar_label_colour = m_button_bar_label_colour;
278 copy->m_tab_label_colour = m_tab_label_colour;
279 copy->m_tab_separator_colour = m_tab_separator_colour;
280 copy->m_tab_separator_gradient_colour = m_tab_separator_gradient_colour;
281 copy->m_tab_active_background_colour = m_tab_hover_background_colour;
282 copy->m_tab_active_background_gradient_colour = m_tab_hover_background_gradient_colour;
283 copy->m_tab_hover_background_colour = m_tab_hover_background_colour;
284 copy->m_tab_hover_background_gradient_colour = m_tab_hover_background_gradient_colour;
285 copy->m_tab_hover_background_top_colour = m_tab_hover_background_top_colour;
286 copy->m_tab_hover_background_top_gradient_colour = m_tab_hover_background_top_gradient_colour;
287 copy->m_panel_label_colour = m_panel_label_colour;
288 copy->m_panel_hover_label_colour = m_panel_hover_label_colour;
289 copy->m_panel_minimised_label_colour = m_panel_minimised_label_colour;
290 copy->m_panel_active_background_colour = m_panel_active_background_colour;
291 copy->m_panel_active_background_gradient_colour = m_panel_active_background_gradient_colour;
292 copy->m_panel_active_background_top_colour = m_panel_active_background_top_colour;
293 copy->m_panel_active_background_top_gradient_colour = m_panel_active_background_top_gradient_colour;
294 copy->m_page_background_colour = m_page_background_colour;
295 copy->m_page_background_gradient_colour = m_page_background_gradient_colour;
296 copy->m_page_background_top_colour = m_page_background_top_colour;
297 copy->m_page_background_top_gradient_colour = m_page_background_top_gradient_colour;
298 copy->m_page_hover_background_colour = m_page_hover_background_colour;
299 copy->m_page_hover_background_gradient_colour = m_page_hover_background_gradient_colour;
300 copy->m_page_hover_background_top_colour = m_page_hover_background_top_colour;
301 copy->m_page_hover_background_top_gradient_colour = m_page_hover_background_top_gradient_colour;
302 copy->m_button_bar_hover_background_colour = m_button_bar_hover_background_colour;
303 copy->m_button_bar_hover_background_gradient_colour = m_button_bar_hover_background_gradient_colour;
304 copy->m_button_bar_hover_background_top_colour = m_button_bar_hover_background_top_colour;
305 copy->m_button_bar_hover_background_top_gradient_colour = m_button_bar_hover_background_top_gradient_colour;
306 copy->m_button_bar_active_background_colour = m_button_bar_active_background_colour;
307 copy->m_button_bar_active_background_gradient_colour = m_button_bar_active_background_gradient_colour;
308 copy->m_button_bar_active_background_top_colour = m_button_bar_active_background_top_colour;
309 copy->m_button_bar_active_background_top_gradient_colour = m_button_bar_active_background_top_gradient_colour;
310 copy->m_gallery_button_background_colour = m_gallery_button_background_colour;
311 copy->m_gallery_button_background_gradient_colour = m_gallery_button_background_gradient_colour;
312 copy->m_gallery_button_hover_background_colour = m_gallery_button_hover_background_colour;
313 copy->m_gallery_button_hover_background_gradient_colour = m_gallery_button_hover_background_gradient_colour;
314 copy->m_gallery_button_active_background_colour = m_gallery_button_active_background_colour;
315 copy->m_gallery_button_active_background_gradient_colour = m_gallery_button_active_background_gradient_colour;
316 copy->m_gallery_button_disabled_background_colour = m_gallery_button_disabled_background_colour;
317 copy->m_gallery_button_disabled_background_gradient_colour = m_gallery_button_disabled_background_gradient_colour;
318 copy->m_gallery_button_face_colour = m_gallery_button_face_colour;
319 copy->m_gallery_button_hover_face_colour = m_gallery_button_hover_face_colour;
320 copy->m_gallery_button_active_face_colour = m_gallery_button_active_face_colour;
321 copy->m_gallery_button_disabled_face_colour = m_gallery_button_disabled_face_colour;
322
323 copy->m_tab_ctrl_background_brush = m_tab_ctrl_background_brush;
324 copy->m_panel_label_background_brush = m_panel_label_background_brush;
325 copy->m_panel_hover_label_background_brush = m_panel_hover_label_background_brush;
326 copy->m_gallery_hover_background_brush = m_gallery_hover_background_brush;
327 copy->m_gallery_button_background_top_brush = m_gallery_button_background_top_brush;
328 copy->m_gallery_button_hover_background_top_brush = m_gallery_button_hover_background_top_brush;
329 copy->m_gallery_button_active_background_top_brush = m_gallery_button_active_background_top_brush;
330 copy->m_gallery_button_disabled_background_top_brush = m_gallery_button_disabled_background_top_brush;
331
332 copy->m_tab_label_font = m_tab_label_font;
333 copy->m_button_bar_label_font = m_button_bar_label_font;
334 copy->m_panel_label_font = m_panel_label_font;
335
336 copy->m_page_border_pen = m_page_border_pen;
337 copy->m_panel_border_pen = m_panel_border_pen;
338 copy->m_panel_border_gradient_pen = m_panel_border_gradient_pen;
339 copy->m_panel_minimised_border_pen = m_panel_minimised_border_pen;
340 copy->m_panel_minimised_border_gradient_pen = m_panel_minimised_border_gradient_pen;
341 copy->m_tab_border_pen = m_tab_border_pen;
342 copy->m_gallery_border_pen = m_gallery_border_pen;
343 copy->m_button_bar_hover_border_pen = m_button_bar_hover_border_pen;
344 copy->m_button_bar_active_border_pen = m_button_bar_active_border_pen;
345 copy->m_gallery_item_border_pen = m_gallery_item_border_pen;
346 copy->m_toolbar_border_pen = m_toolbar_border_pen;
347
348 copy->m_flags = m_flags;
349 copy->m_tab_separation_size = m_tab_separation_size;
350 copy->m_page_border_left = m_page_border_left;
351 copy->m_page_border_top = m_page_border_top;
352 copy->m_page_border_right = m_page_border_right;
353 copy->m_page_border_bottom = m_page_border_bottom;
354 copy->m_panel_x_separation_size = m_panel_x_separation_size;
355 copy->m_panel_y_separation_size = m_panel_y_separation_size;
356 copy->m_gallery_bitmap_padding_left_size = m_gallery_bitmap_padding_left_size;
357 copy->m_gallery_bitmap_padding_right_size = m_gallery_bitmap_padding_right_size;
358 copy->m_gallery_bitmap_padding_top_size = m_gallery_bitmap_padding_top_size;
359 copy->m_gallery_bitmap_padding_bottom_size = m_gallery_bitmap_padding_bottom_size;
360 }
361
362 long wxRibbonMSWArtProvider::GetFlags() const
363 {
364 return m_flags;
365 }
366
367 void wxRibbonMSWArtProvider::SetFlags(long flags)
368 {
369 if((flags ^ m_flags) & wxRIBBON_BAR_FLOW_VERTICAL)
370 {
371 if(flags & wxRIBBON_BAR_FLOW_VERTICAL)
372 {
373 m_page_border_left++;
374 m_page_border_right++;
375 m_page_border_top--;
376 m_page_border_bottom--;
377 }
378 else
379 {
380 m_page_border_left--;
381 m_page_border_right--;
382 m_page_border_top++;
383 m_page_border_bottom++;
384 }
385 }
386 m_flags = flags;
387
388 // Need to reload some bitmaps when flags change
389 #define Reload(setting) SetColour(setting, GetColour(setting))
390 Reload(wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR);
391 Reload(wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR);
392 Reload(wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR);
393 Reload(wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR);
394 #undef Reload
395 }
396
397 int wxRibbonMSWArtProvider::GetMetric(int id) const
398 {
399 switch(id)
400 {
401 case wxRIBBON_ART_TAB_SEPARATION_SIZE:
402 return m_tab_separation_size;
403 case wxRIBBON_ART_PAGE_BORDER_LEFT_SIZE:
404 return m_page_border_left;
405 case wxRIBBON_ART_PAGE_BORDER_TOP_SIZE:
406 return m_page_border_top;
407 case wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE:
408 return m_page_border_right;
409 case wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE:
410 return m_page_border_bottom;
411 case wxRIBBON_ART_PANEL_X_SEPARATION_SIZE:
412 return m_panel_x_separation_size;
413 case wxRIBBON_ART_PANEL_Y_SEPARATION_SIZE:
414 return m_panel_y_separation_size;
415 case wxRIBBON_ART_TOOL_GROUP_SEPARATION_SIZE:
416 return m_tool_group_separation_size;
417 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE:
418 return m_gallery_bitmap_padding_left_size;
419 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE:
420 return m_gallery_bitmap_padding_right_size;
421 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE:
422 return m_gallery_bitmap_padding_top_size;
423 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE:
424 return m_gallery_bitmap_padding_bottom_size;
425 default:
426 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
427 break;
428 }
429
430 return 0;
431 }
432
433 void wxRibbonMSWArtProvider::SetMetric(int id, int new_val)
434 {
435 switch(id)
436 {
437 case wxRIBBON_ART_TAB_SEPARATION_SIZE:
438 m_tab_separation_size = new_val;
439 break;
440 case wxRIBBON_ART_PAGE_BORDER_LEFT_SIZE:
441 m_page_border_left = new_val;
442 break;
443 case wxRIBBON_ART_PAGE_BORDER_TOP_SIZE:
444 m_page_border_top = new_val;
445 break;
446 case wxRIBBON_ART_PAGE_BORDER_RIGHT_SIZE:
447 m_page_border_right = new_val;
448 break;
449 case wxRIBBON_ART_PAGE_BORDER_BOTTOM_SIZE:
450 m_page_border_bottom = new_val;
451 break;
452 case wxRIBBON_ART_PANEL_X_SEPARATION_SIZE:
453 m_panel_x_separation_size = new_val;
454 break;
455 case wxRIBBON_ART_PANEL_Y_SEPARATION_SIZE:
456 m_panel_y_separation_size = new_val;
457 break;
458 case wxRIBBON_ART_TOOL_GROUP_SEPARATION_SIZE:
459 m_tool_group_separation_size = new_val;
460 break;
461 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE:
462 m_gallery_bitmap_padding_left_size = new_val;
463 break;
464 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE:
465 m_gallery_bitmap_padding_right_size = new_val;
466 break;
467 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE:
468 m_gallery_bitmap_padding_top_size = new_val;
469 break;
470 case wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE:
471 m_gallery_bitmap_padding_bottom_size = new_val;
472 break;
473 default:
474 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
475 break;
476 }
477 }
478
479 void wxRibbonMSWArtProvider::SetFont(int id, const wxFont& font)
480 {
481 switch(id)
482 {
483 case wxRIBBON_ART_TAB_LABEL_FONT:
484 m_tab_label_font = font;
485 break;
486 case wxRIBBON_ART_BUTTON_BAR_LABEL_FONT:
487 m_button_bar_label_font = font;
488 break;
489 case wxRIBBON_ART_PANEL_LABEL_FONT:
490 m_panel_label_font = font;
491 break;
492 default:
493 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
494 break;
495 }
496 }
497
498 wxFont wxRibbonMSWArtProvider::GetFont(int id) const
499 {
500 switch(id)
501 {
502 case wxRIBBON_ART_TAB_LABEL_FONT:
503 return m_tab_label_font;
504 case wxRIBBON_ART_BUTTON_BAR_LABEL_FONT:
505 return m_button_bar_label_font;
506 case wxRIBBON_ART_PANEL_LABEL_FONT:
507 return m_panel_label_font;
508 default:
509 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
510 break;
511 }
512
513 return wxNullFont;
514 }
515
516 wxColour wxRibbonMSWArtProvider::GetColour(int id) const
517 {
518 switch(id)
519 {
520 case wxRIBBON_ART_BUTTON_BAR_LABEL_COLOUR:
521 return m_button_bar_label_colour;
522 case wxRIBBON_ART_BUTTON_BAR_HOVER_BORDER_COLOUR:
523 return m_button_bar_hover_border_pen.GetColour();
524 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_COLOUR:
525 return m_button_bar_hover_background_top_colour;
526 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
527 return m_button_bar_hover_background_top_gradient_colour;
528 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR:
529 return m_button_bar_hover_background_colour;
530 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR:
531 return m_button_bar_hover_background_gradient_colour;
532 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BORDER_COLOUR:
533 return m_button_bar_active_border_pen.GetColour();
534 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_COLOUR:
535 return m_button_bar_active_background_top_colour;
536 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
537 return m_button_bar_active_background_top_gradient_colour;
538 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_COLOUR:
539 return m_button_bar_active_background_colour;
540 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
541 return m_button_bar_active_background_gradient_colour;
542 case wxRIBBON_ART_GALLERY_BORDER_COLOUR:
543 return m_gallery_border_pen.GetColour();
544 case wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR:
545 return m_gallery_hover_background_brush.GetColour();
546 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_COLOUR:
547 return m_gallery_button_background_colour;
548 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_GRADIENT_COLOUR:
549 return m_gallery_button_background_gradient_colour;
550 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_TOP_COLOUR:
551 return m_gallery_button_background_top_brush.GetColour();
552 case wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR:
553 return m_gallery_button_face_colour;
554 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR:
555 return m_gallery_button_hover_background_colour;
556 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR:
557 return m_gallery_button_hover_background_gradient_colour;
558 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_TOP_COLOUR:
559 return m_gallery_button_hover_background_top_brush.GetColour();
560 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR:
561 return m_gallery_button_face_colour;
562 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR:
563 return m_gallery_button_active_background_colour;
564 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
565 return m_gallery_button_active_background_gradient_colour;
566 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_TOP_COLOUR:
567 return m_gallery_button_background_top_brush.GetColour();
568 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR:
569 return m_gallery_button_active_face_colour;
570 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR:
571 return m_gallery_button_disabled_background_colour;
572 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR:
573 return m_gallery_button_disabled_background_gradient_colour;
574 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_TOP_COLOUR:
575 return m_gallery_button_disabled_background_top_brush.GetColour();
576 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR:
577 return m_gallery_button_disabled_face_colour;
578 case wxRIBBON_ART_GALLERY_ITEM_BORDER_COLOUR:
579 return m_gallery_item_border_pen.GetColour();
580 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR:
581 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR:
582 return m_tab_ctrl_background_brush.GetColour();
583 case wxRIBBON_ART_TAB_LABEL_COLOUR:
584 return m_tab_label_colour;
585 case wxRIBBON_ART_TAB_SEPARATOR_COLOUR:
586 return m_tab_separator_colour;
587 case wxRIBBON_ART_TAB_SEPARATOR_GRADIENT_COLOUR:
588 return m_tab_separator_gradient_colour;
589 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR:
590 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
591 return wxColour(0, 0, 0);
592 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_COLOUR:
593 return m_tab_active_background_colour;
594 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
595 return m_tab_active_background_gradient_colour;
596 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_COLOUR:
597 return m_tab_hover_background_top_colour;
598 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
599 return m_tab_hover_background_top_gradient_colour;
600 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR:
601 return m_tab_hover_background_colour;
602 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR:
603 return m_tab_hover_background_gradient_colour;
604 case wxRIBBON_ART_TAB_BORDER_COLOUR:
605 return m_tab_border_pen.GetColour();
606 case wxRIBBON_ART_PANEL_BORDER_COLOUR:
607 return m_panel_border_pen.GetColour();
608 case wxRIBBON_ART_PANEL_BORDER_GRADIENT_COLOUR:
609 return m_panel_border_gradient_pen.GetColour();
610 case wxRIBBON_ART_PANEL_MINIMISED_BORDER_COLOUR:
611 return m_panel_minimised_border_pen.GetColour();
612 case wxRIBBON_ART_PANEL_MINIMISED_BORDER_GRADIENT_COLOUR:
613 return m_panel_minimised_border_gradient_pen.GetColour();
614 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR:
615 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR:
616 return m_panel_label_background_brush.GetColour();
617 case wxRIBBON_ART_PANEL_LABEL_COLOUR:
618 return m_panel_label_colour;
619 case wxRIBBON_ART_PANEL_MINIMISED_LABEL_COLOUR:
620 return m_panel_minimised_label_colour;
621 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR:
622 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR:
623 return m_panel_hover_label_background_brush.GetColour();
624 case wxRIBBON_ART_PANEL_HOVER_LABEL_COLOUR:
625 return m_panel_hover_label_colour;
626 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_TOP_COLOUR:
627 return m_panel_active_background_top_colour;
628 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
629 return m_panel_active_background_top_gradient_colour;
630 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_COLOUR:
631 return m_panel_active_background_colour;
632 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
633 return m_panel_active_background_gradient_colour;
634 case wxRIBBON_ART_PAGE_BORDER_COLOUR:
635 return m_page_border_pen.GetColour();
636 case wxRIBBON_ART_PAGE_BACKGROUND_TOP_COLOUR:
637 return m_page_background_top_colour;
638 case wxRIBBON_ART_PAGE_BACKGROUND_TOP_GRADIENT_COLOUR:
639 return m_page_background_top_gradient_colour;
640 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR:
641 return m_page_background_colour;
642 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR:
643 return m_page_background_gradient_colour;
644 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_COLOUR:
645 return m_page_hover_background_top_colour;
646 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
647 return m_page_hover_background_top_gradient_colour;
648 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_COLOUR:
649 return m_page_hover_background_colour;
650 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_GRADIENT_COLOUR:
651 return m_page_hover_background_gradient_colour;
652 case wxRIBBON_ART_TOOLBAR_BORDER_COLOUR:
653 case wxRIBBON_ART_TOOLBAR_HOVER_BORDER_COLOUR:
654 return m_toolbar_border_pen.GetColour();
655 case wxRIBBON_ART_TOOLBAR_FACE_COLOUR:
656 return m_tool_face_colour;
657 default:
658 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
659 break;
660 }
661
662 return wxColour();
663 }
664
665 void wxRibbonMSWArtProvider::SetColour(int id, const wxColor& colour)
666 {
667 switch(id)
668 {
669 case wxRIBBON_ART_BUTTON_BAR_LABEL_COLOUR:
670 m_button_bar_label_colour = colour;
671 break;
672 case wxRIBBON_ART_BUTTON_BAR_HOVER_BORDER_COLOUR:
673 m_button_bar_hover_border_pen.SetColour(colour);
674 break;
675 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_COLOUR:
676 m_button_bar_hover_background_top_colour = colour;
677 break;
678 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
679 m_button_bar_hover_background_top_gradient_colour = colour;
680 break;
681 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR:
682 m_button_bar_hover_background_colour = colour;
683 break;
684 case wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR:
685 m_button_bar_hover_background_gradient_colour = colour;
686 break;
687 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BORDER_COLOUR:
688 m_button_bar_active_border_pen.SetColour(colour);
689 break;
690 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_COLOUR:
691 m_button_bar_active_background_top_colour = colour;
692 break;
693 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
694 m_button_bar_active_background_top_gradient_colour = colour;
695 break;
696 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_COLOUR:
697 m_button_bar_active_background_colour = colour;
698 break;
699 case wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
700 m_button_bar_active_background_gradient_colour = colour;
701 break;
702 case wxRIBBON_ART_GALLERY_BORDER_COLOUR:
703 m_gallery_border_pen.SetColour(colour);
704 break;
705 case wxRIBBON_ART_GALLERY_HOVER_BACKGROUND_COLOUR:
706 m_gallery_hover_background_brush.SetColour(colour);
707 break;
708 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_COLOUR:
709 m_gallery_button_background_colour = colour;
710 break;
711 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_GRADIENT_COLOUR:
712 m_gallery_button_background_gradient_colour = colour;
713 break;
714 case wxRIBBON_ART_GALLERY_BUTTON_BACKGROUND_TOP_COLOUR:
715 m_gallery_button_background_top_brush.SetColour(colour);
716 break;
717 case wxRIBBON_ART_GALLERY_BUTTON_FACE_COLOUR:
718 m_gallery_button_face_colour = colour;
719 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
720 {
721 m_gallery_up_bitmap[0] = wxRibbonLoadPixmap(gallery_left_xpm, colour);
722 m_gallery_down_bitmap[0] = wxRibbonLoadPixmap(gallery_right_xpm, colour);
723 }
724 else
725 {
726 m_gallery_up_bitmap[0] = wxRibbonLoadPixmap(gallery_up_xpm, colour);
727 m_gallery_down_bitmap[0] = wxRibbonLoadPixmap(gallery_down_xpm, colour);
728 }
729 m_gallery_extension_bitmap[0] = wxRibbonLoadPixmap(gallery_extension_xpm, colour);
730 break;
731 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_COLOUR:
732 m_gallery_button_hover_background_colour = colour;
733 break;
734 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_GRADIENT_COLOUR:
735 m_gallery_button_hover_background_gradient_colour = colour;
736 break;
737 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_BACKGROUND_TOP_COLOUR:
738 m_gallery_button_hover_background_top_brush.SetColour(colour);
739 break;
740 case wxRIBBON_ART_GALLERY_BUTTON_HOVER_FACE_COLOUR:
741 m_gallery_button_hover_face_colour = colour;
742 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
743 {
744 m_gallery_up_bitmap[1] = wxRibbonLoadPixmap(gallery_left_xpm, colour);
745 m_gallery_down_bitmap[1] = wxRibbonLoadPixmap(gallery_right_xpm, colour);
746 }
747 else
748 {
749 m_gallery_up_bitmap[1] = wxRibbonLoadPixmap(gallery_up_xpm, colour);
750 m_gallery_down_bitmap[1] = wxRibbonLoadPixmap(gallery_down_xpm, colour);
751 }
752 m_gallery_extension_bitmap[1] = wxRibbonLoadPixmap(gallery_extension_xpm, colour);
753 break;
754 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_COLOUR:
755 m_gallery_button_active_background_colour = colour;
756 break;
757 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
758 m_gallery_button_active_background_gradient_colour = colour;
759 break;
760 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_BACKGROUND_TOP_COLOUR:
761 m_gallery_button_background_top_brush.SetColour(colour);
762 break;
763 case wxRIBBON_ART_GALLERY_BUTTON_ACTIVE_FACE_COLOUR:
764 m_gallery_button_active_face_colour = colour;
765 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
766 {
767 m_gallery_up_bitmap[2] = wxRibbonLoadPixmap(gallery_left_xpm, colour);
768 m_gallery_down_bitmap[2] = wxRibbonLoadPixmap(gallery_right_xpm, colour);
769 }
770 else
771 {
772 m_gallery_up_bitmap[2] = wxRibbonLoadPixmap(gallery_up_xpm, colour);
773 m_gallery_down_bitmap[2] = wxRibbonLoadPixmap(gallery_down_xpm, colour);
774 }
775 m_gallery_extension_bitmap[2] = wxRibbonLoadPixmap(gallery_extension_xpm, colour);
776 break;
777 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_COLOUR:
778 m_gallery_button_disabled_background_colour = colour;
779 break;
780 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_GRADIENT_COLOUR:
781 m_gallery_button_disabled_background_gradient_colour = colour;
782 break;
783 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_BACKGROUND_TOP_COLOUR:
784 m_gallery_button_disabled_background_top_brush.SetColour(colour);
785 break;
786 case wxRIBBON_ART_GALLERY_BUTTON_DISABLED_FACE_COLOUR:
787 m_gallery_button_disabled_face_colour = colour;
788 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
789 {
790 m_gallery_up_bitmap[3] = wxRibbonLoadPixmap(gallery_left_xpm, colour);
791 m_gallery_down_bitmap[3] = wxRibbonLoadPixmap(gallery_right_xpm, colour);
792 }
793 else
794 {
795 m_gallery_up_bitmap[3] = wxRibbonLoadPixmap(gallery_up_xpm, colour);
796 m_gallery_down_bitmap[3] = wxRibbonLoadPixmap(gallery_down_xpm, colour);
797 }
798 m_gallery_extension_bitmap[3] = wxRibbonLoadPixmap(gallery_extension_xpm, colour);
799 break;
800 case wxRIBBON_ART_GALLERY_ITEM_BORDER_COLOUR:
801 m_gallery_item_border_pen.SetColour(colour);
802 break;
803 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_COLOUR:
804 case wxRIBBON_ART_TAB_CTRL_BACKGROUND_GRADIENT_COLOUR:
805 m_tab_ctrl_background_brush.SetColour(colour);
806 m_cached_tab_separator_visibility = -1.0;
807 break;
808 case wxRIBBON_ART_TAB_LABEL_COLOUR:
809 m_tab_label_colour = colour;
810 break;
811 case wxRIBBON_ART_TAB_SEPARATOR_COLOUR:
812 m_tab_separator_colour = colour;
813 m_cached_tab_separator_visibility = -1.0;
814 break;
815 case wxRIBBON_ART_TAB_SEPARATOR_GRADIENT_COLOUR:
816 m_tab_separator_gradient_colour = colour;
817 m_cached_tab_separator_visibility = -1.0;
818 break;
819 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_COLOUR:
820 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
821 break;
822 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_COLOUR:
823 m_tab_active_background_colour = colour;
824 break;
825 case wxRIBBON_ART_TAB_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
826 m_tab_active_background_gradient_colour = colour;
827 break;
828 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_COLOUR:
829 m_tab_hover_background_top_colour = colour;
830 break;
831 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
832 m_tab_hover_background_top_gradient_colour = colour;
833 break;
834 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR:
835 m_tab_hover_background_colour = colour;
836 break;
837 case wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR:
838 m_tab_hover_background_gradient_colour = colour;
839 break;
840 case wxRIBBON_ART_TAB_BORDER_COLOUR:
841 m_tab_border_pen.SetColour(colour);
842 break;
843 case wxRIBBON_ART_PANEL_BORDER_COLOUR:
844 m_panel_border_pen.SetColour(colour);
845 break;
846 case wxRIBBON_ART_PANEL_BORDER_GRADIENT_COLOUR:
847 m_panel_border_gradient_pen.SetColour(colour);
848 break;
849 case wxRIBBON_ART_PANEL_MINIMISED_BORDER_COLOUR:
850 m_panel_minimised_border_pen.SetColour(colour);
851 break;
852 case wxRIBBON_ART_PANEL_MINIMISED_BORDER_GRADIENT_COLOUR:
853 m_panel_minimised_border_gradient_pen.SetColour(colour);
854 break;
855 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_COLOUR:
856 case wxRIBBON_ART_PANEL_LABEL_BACKGROUND_GRADIENT_COLOUR:
857 m_panel_label_background_brush.SetColour(colour);
858 break;
859 case wxRIBBON_ART_PANEL_LABEL_COLOUR:
860 m_panel_label_colour = colour;
861 break;
862 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_COLOUR:
863 case wxRIBBON_ART_PANEL_HOVER_LABEL_BACKGROUND_GRADIENT_COLOUR:
864 m_panel_hover_label_background_brush.SetColour(colour);
865 break;
866 case wxRIBBON_ART_PANEL_HOVER_LABEL_COLOUR:
867 m_panel_hover_label_colour = colour;
868 break;
869 case wxRIBBON_ART_PANEL_MINIMISED_LABEL_COLOUR:
870 m_panel_minimised_label_colour = colour;
871 break;
872 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_TOP_COLOUR:
873 m_panel_active_background_top_colour = colour;
874 break;
875 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR:
876 m_panel_active_background_top_gradient_colour = colour;
877 break;
878 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_COLOUR:
879 m_panel_active_background_colour = colour;
880 break;
881 case wxRIBBON_ART_PANEL_ACTIVE_BACKGROUND_GRADIENT_COLOUR:
882 m_panel_active_background_gradient_colour = colour;
883 break;
884 case wxRIBBON_ART_PAGE_BORDER_COLOUR:
885 m_page_border_pen.SetColour(colour);
886 break;
887 case wxRIBBON_ART_PAGE_BACKGROUND_TOP_COLOUR:
888 m_page_background_top_colour = colour;
889 break;
890 case wxRIBBON_ART_PAGE_BACKGROUND_TOP_GRADIENT_COLOUR:
891 m_page_background_top_gradient_colour = colour;
892 break;
893 case wxRIBBON_ART_PAGE_BACKGROUND_COLOUR:
894 m_page_background_colour = colour;
895 break;
896 case wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR:
897 m_page_background_gradient_colour = colour;
898 break;
899 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_COLOUR:
900 m_page_hover_background_top_colour = colour;
901 break;
902 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR:
903 m_page_hover_background_top_gradient_colour = colour;
904 break;
905 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_COLOUR:
906 m_page_hover_background_colour = colour;
907 break;
908 case wxRIBBON_ART_PAGE_HOVER_BACKGROUND_GRADIENT_COLOUR:
909 m_page_hover_background_gradient_colour = colour;
910 break;
911 case wxRIBBON_ART_TOOLBAR_BORDER_COLOUR:
912 case wxRIBBON_ART_TOOLBAR_HOVER_BORDER_COLOUR:
913 m_toolbar_border_pen.SetColour(colour);
914 break;
915 case wxRIBBON_ART_TOOLBAR_FACE_COLOUR:
916 m_tool_face_colour = colour;
917 m_toolbar_drop_bitmap = wxRibbonLoadPixmap(gallery_down_xpm, colour);
918 break;
919 default:
920 wxFAIL_MSG(wxT("Invalid Metric Ordinal"));
921 break;
922 }
923 }
924
925 void wxRibbonMSWArtProvider::DrawTabCtrlBackground(
926 wxDC& dc,
927 wxWindow* WXUNUSED(wnd),
928 const wxRect& rect)
929 {
930 dc.SetPen(*wxTRANSPARENT_PEN);
931 dc.SetBrush(m_tab_ctrl_background_brush);
932 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
933
934 dc.SetPen(m_page_border_pen);
935 if(rect.width > 6)
936 {
937 dc.DrawLine(rect.x + 3, rect.y + rect.height - 1, rect.x + rect.width - 3, rect.y + rect.height - 1);
938 }
939 else
940 {
941 dc.DrawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1);
942 }
943 }
944
945 void wxRibbonMSWArtProvider::DrawTab(
946 wxDC& dc,
947 wxWindow* WXUNUSED(wnd),
948 const wxRibbonPageTabInfo& tab)
949 {
950 if(tab.rect.height <= 2)
951 return;
952
953 if(tab.active || tab.hovered)
954 {
955 if(tab.active)
956 {
957 wxRect background(tab.rect);
958
959 background.x += 2;
960 background.y += 2;
961 background.width -= 4;
962 background.height -= 2;
963
964 dc.GradientFillLinear(background, m_tab_active_background_colour,
965 m_tab_active_background_gradient_colour, wxSOUTH);
966
967 // TODO: active and hovered
968 }
969 else if(tab.hovered)
970 {
971 wxRect background(tab.rect);
972
973 background.x += 2;
974 background.y += 2;
975 background.width -= 4;
976 background.height -= 3;
977 int h = background.height;
978 background.height /= 2;
979 dc.GradientFillLinear(background,
980 m_tab_hover_background_top_colour,
981 m_tab_hover_background_top_gradient_colour, wxSOUTH);
982
983 background.y += background.height;
984 background.height = h - background.height;
985 dc.GradientFillLinear(background, m_tab_hover_background_colour,
986 m_tab_hover_background_gradient_colour, wxSOUTH);
987 }
988
989 wxPoint border_points[6];
990 border_points[0] = wxPoint(1, tab.rect.height - 2);
991 border_points[1] = wxPoint(1, 3);
992 border_points[2] = wxPoint(3, 1);
993 border_points[3] = wxPoint(tab.rect.width - 4, 1);
994 border_points[4] = wxPoint(tab.rect.width - 2, 3);
995 border_points[5] = wxPoint(tab.rect.width - 2, tab.rect.height - 1);
996
997 dc.SetPen(m_tab_border_pen);
998 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, tab.rect.x, tab.rect.y);
999
1000 if(tab.active)
1001 {
1002 // Give the tab a curved outward border at the bottom
1003 dc.DrawPoint(tab.rect.x, tab.rect.y + tab.rect.height - 2);
1004 dc.DrawPoint(tab.rect.x + tab.rect.width - 1, tab.rect.y + tab.rect.height - 2);
1005
1006 wxPen p(m_tab_active_background_gradient_colour);
1007 dc.SetPen(p);
1008
1009 // Technically the first two points are the wrong colour, but they're near enough
1010 dc.DrawPoint(tab.rect.x + 1, tab.rect.y + tab.rect.height - 2);
1011 dc.DrawPoint(tab.rect.x + tab.rect.width - 2, tab.rect.y + tab.rect.height - 2);
1012 dc.DrawPoint(tab.rect.x + 1, tab.rect.y + tab.rect.height - 1);
1013 dc.DrawPoint(tab.rect.x, tab.rect.y + tab.rect.height - 1);
1014 dc.DrawPoint(tab.rect.x + tab.rect.width - 2, tab.rect.y + tab.rect.height - 1);
1015 dc.DrawPoint(tab.rect.x + tab.rect.width - 1, tab.rect.y + tab.rect.height - 1);
1016 }
1017 }
1018
1019 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
1020 {
1021 wxBitmap icon = tab.page->GetIcon();
1022 int x = tab.rect.x + 4;
1023 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) == 0)
1024 x = tab.rect.x + (tab.rect.width - icon.GetWidth()) / 2;
1025 dc.DrawBitmap(icon, x, tab.rect.y + 1 + (tab.rect.height - 1 -
1026 icon.GetHeight()) / 2, true);
1027 }
1028 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
1029 {
1030 wxString label = tab.page->GetLabel();
1031 if(!label.IsEmpty())
1032 {
1033 dc.SetFont(m_tab_label_font);
1034 dc.SetTextForeground(m_tab_label_colour);
1035 dc.SetBackgroundMode(wxTRANSPARENT);
1036
1037 int text_height;
1038 int text_width;
1039 dc.GetTextExtent(label, &text_width, &text_height);
1040 int width = tab.rect.width - 5;
1041 int x = tab.rect.x + 3;
1042 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
1043 {
1044 x += 3 + tab.page->GetIcon().GetWidth();
1045 width -= 3 + tab.page->GetIcon().GetWidth();
1046 }
1047 int y = tab.rect.y + (tab.rect.height - text_height) / 2;
1048
1049 if(width <= text_width)
1050 {
1051 dc.SetClippingRegion(x, tab.rect.y, width, tab.rect.height);
1052 dc.DrawText(label, x, y);
1053 }
1054 else
1055 {
1056 dc.DrawText(label, x + (width - text_width) / 2 + 1, y);
1057 }
1058 }
1059 }
1060 }
1061
1062 void wxRibbonMSWArtProvider::DrawTabSeparator(
1063 wxDC& dc,
1064 wxWindow* wnd,
1065 const wxRect& rect,
1066 double visibility)
1067 {
1068 if(visibility <= 0.0)
1069 {
1070 return;
1071 }
1072 if(visibility > 1.0)
1073 {
1074 visibility = 1.0;
1075 }
1076
1077 // The tab separator is relatively expensive to draw (for its size), and is
1078 // usually drawn multiple times sequentially (in different positions), so it
1079 // makes sense to draw it once and cache it.
1080 if(!m_cached_tab_separator.IsOk() || m_cached_tab_separator.GetSize() != rect.GetSize() || visibility != m_cached_tab_separator_visibility)
1081 {
1082 wxRect size(rect.GetSize());
1083 ReallyDrawTabSeparator(wnd, size, visibility);
1084 }
1085 dc.DrawBitmap(m_cached_tab_separator, rect.x, rect.y, false);
1086 }
1087
1088 void wxRibbonMSWArtProvider::ReallyDrawTabSeparator(wxWindow* wnd, const wxRect& rect, double visibility)
1089 {
1090 if(!m_cached_tab_separator.IsOk() || m_cached_tab_separator.GetSize() != rect.GetSize())
1091 {
1092 m_cached_tab_separator = wxBitmap(rect.GetSize());
1093 }
1094
1095 wxMemoryDC dc(m_cached_tab_separator);
1096 DrawTabCtrlBackground(dc, wnd, rect);
1097
1098 wxCoord x = rect.x + rect.width / 2;
1099 double h = (double)(rect.height - 1);
1100
1101 double r1 = m_tab_ctrl_background_brush.GetColour().Red() * (1.0 - visibility) + 0.5;
1102 double g1 = m_tab_ctrl_background_brush.GetColour().Green() * (1.0 - visibility) + 0.5;
1103 double b1 = m_tab_ctrl_background_brush.GetColour().Blue() * (1.0 - visibility) + 0.5;
1104 double r2 = m_tab_separator_colour.Red();
1105 double g2 = m_tab_separator_colour.Green();
1106 double b2 = m_tab_separator_colour.Blue();
1107 double r3 = m_tab_separator_gradient_colour.Red();
1108 double g3 = m_tab_separator_gradient_colour.Green();
1109 double b3 = m_tab_separator_gradient_colour.Blue();
1110
1111 for(int i = 0; i < rect.height - 1; ++i)
1112 {
1113 double p = ((double)i)/h;
1114
1115 double r = (p * r3 + (1.0 - p) * r2) * visibility + r1;
1116 double g = (p * g3 + (1.0 - p) * g2) * visibility + g1;
1117 double b = (p * b3 + (1.0 - p) * b2) * visibility + b1;
1118
1119 wxPen P(wxColour((unsigned char)r, (unsigned char)g, (unsigned char)b));
1120 dc.SetPen(P);
1121 dc.DrawPoint(x, rect.y + i);
1122 }
1123
1124 m_cached_tab_separator_visibility = visibility;
1125 }
1126
1127 void wxRibbonMSWArtProvider::DrawPartialPageBackground(wxDC& dc,
1128 wxWindow* WXUNUSED(wnd), const wxRect& rect, wxRibbonPage* page,
1129 wxPoint offset, bool hovered)
1130 {
1131 wxRect background(page->GetSize());
1132 page->AdjustRectToIncludeScrollButtons(&background);
1133 background.height -= 2;
1134 // Page background isn't dependant upon the width of the page
1135 // (at least not the part of it intended to be painted by this
1136 // function). Set to wider than the page itself for when externally
1137 // expanded panels need a background - the expanded panel can be wider
1138 // than the bar.
1139 background.x = 0;
1140 background.width = INT_MAX;
1141
1142 // upper_rect, lower_rect, paint_rect are all in page co-ordinates
1143 wxRect upper_rect(background);
1144 upper_rect.height /= 5;
1145
1146 wxRect lower_rect(background);
1147 lower_rect.y += upper_rect.height;
1148 lower_rect.height -= upper_rect.height;
1149
1150 wxRect paint_rect(rect);
1151 paint_rect.x += offset.x;
1152 paint_rect.y += offset.y;
1153
1154 wxColour bg_top, bg_top_grad, bg_btm, bg_btm_grad;
1155 if(hovered)
1156 {
1157 bg_top = m_page_hover_background_top_colour;
1158 bg_top_grad = m_page_hover_background_top_gradient_colour;
1159 bg_btm = m_page_hover_background_colour;
1160 bg_btm_grad = m_page_hover_background_gradient_colour;
1161 }
1162 else
1163 {
1164 bg_top = m_page_background_top_colour;
1165 bg_top_grad = m_page_background_top_gradient_colour;
1166 bg_btm = m_page_background_colour;
1167 bg_btm_grad = m_page_background_gradient_colour;
1168 }
1169
1170 if(paint_rect.Intersects(upper_rect))
1171 {
1172 wxRect rect(upper_rect);
1173 rect.Intersect(paint_rect);
1174 rect.x -= offset.x;
1175 rect.y -= offset.y;
1176 wxColour starting_colour(wxRibbonInterpolateColour(bg_top, bg_top_grad,
1177 paint_rect.y, upper_rect.y, upper_rect.y + upper_rect.height));
1178 wxColour ending_colour(wxRibbonInterpolateColour(bg_top, bg_top_grad,
1179 paint_rect.y + paint_rect.height, upper_rect.y,
1180 upper_rect.y + upper_rect.height));
1181 dc.GradientFillLinear(rect, starting_colour, ending_colour, wxSOUTH);
1182 }
1183
1184 if(paint_rect.Intersects(lower_rect))
1185 {
1186 wxRect rect(lower_rect);
1187 rect.Intersect(paint_rect);
1188 rect.x -= offset.x;
1189 rect.y -= offset.y;
1190 wxColour starting_colour(wxRibbonInterpolateColour(bg_btm, bg_btm_grad,
1191 paint_rect.y, lower_rect.y, lower_rect.y + lower_rect.height));
1192 wxColour ending_colour(wxRibbonInterpolateColour(bg_btm, bg_btm_grad,
1193 paint_rect.y + paint_rect.height,
1194 lower_rect.y, lower_rect.y + lower_rect.height));
1195 dc.GradientFillLinear(rect, starting_colour, ending_colour, wxSOUTH);
1196 }
1197 }
1198
1199 void wxRibbonMSWArtProvider::DrawPageBackground(
1200 wxDC& dc,
1201 wxWindow* WXUNUSED(wnd),
1202 const wxRect& rect)
1203 {
1204 dc.SetPen(*wxTRANSPARENT_PEN);
1205 dc.SetBrush(m_tab_ctrl_background_brush);
1206
1207 {
1208 wxRect edge(rect);
1209
1210 edge.width = 2;
1211 dc.DrawRectangle(edge.x, edge.y, edge.width, edge.height);
1212
1213 edge.x += rect.width - 2;
1214 dc.DrawRectangle(edge.x, edge.y, edge.width, edge.height);
1215
1216 edge = rect;
1217 edge.height = 2;
1218 edge.y += (rect.height - edge.height);
1219 dc.DrawRectangle(edge.x, edge.y, edge.width, edge.height);
1220 }
1221
1222 {
1223 wxRect background(rect);
1224 background.x += 2;
1225 background.width -= 4;
1226 background.height -= 2;
1227
1228 background.height /= 5;
1229 dc.GradientFillLinear(background, m_page_background_top_colour,
1230 m_page_background_top_gradient_colour, wxSOUTH);
1231
1232 background.y += background.height;
1233 background.height = rect.height - 2 - background.height;
1234 dc.GradientFillLinear(background, m_page_background_colour,
1235 m_page_background_gradient_colour, wxSOUTH);
1236 }
1237
1238 {
1239 wxPoint border_points[8];
1240 border_points[0] = wxPoint(2, 0);
1241 border_points[1] = wxPoint(1, 1);
1242 border_points[2] = wxPoint(1, rect.height - 4);
1243 border_points[3] = wxPoint(3, rect.height - 2);
1244 border_points[4] = wxPoint(rect.width - 4, rect.height - 2);
1245 border_points[5] = wxPoint(rect.width - 2, rect.height - 4);
1246 border_points[6] = wxPoint(rect.width - 2, 1);
1247 border_points[7] = wxPoint(rect.width - 4, -1);
1248
1249 dc.SetPen(m_page_border_pen);
1250 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, rect.x, rect.y);
1251 }
1252 }
1253
1254 void wxRibbonMSWArtProvider::DrawScrollButton(
1255 wxDC& dc,
1256 wxWindow* WXUNUSED(wnd),
1257 const wxRect& rect_,
1258 long style)
1259 {
1260 wxRect rect(rect_);
1261
1262 if((style & wxRIBBON_SCROLL_BTN_FOR_MASK) == wxRIBBON_SCROLL_BTN_FOR_PAGE)
1263 {
1264 // Page scroll buttons do not have the luxury of rendering on top of anything
1265 // else, and their size includes some padding, hence the background painting
1266 // and size adjustment.
1267 dc.SetPen(*wxTRANSPARENT_PEN);
1268 dc.SetBrush(m_tab_ctrl_background_brush);
1269 dc.DrawRectangle(rect);
1270 dc.SetClippingRegion(rect);
1271 switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK)
1272 {
1273 case wxRIBBON_SCROLL_BTN_LEFT:
1274 rect.x++;
1275 case wxRIBBON_SCROLL_BTN_RIGHT:
1276 rect.y--;
1277 rect.width--;
1278 break;
1279 case wxRIBBON_SCROLL_BTN_UP:
1280 rect.x++;
1281 rect.y--;
1282 rect.width -= 2;
1283 rect.height++;
1284 break;
1285 case wxRIBBON_SCROLL_BTN_DOWN:
1286 rect.x++;
1287 rect.width -= 2;
1288 rect.height--;
1289 break;
1290 }
1291 }
1292
1293 {
1294 wxRect background(rect);
1295 background.x++;
1296 background.y++;
1297 background.width -= 2;
1298 background.height -= 2;
1299
1300 if(style & wxRIBBON_SCROLL_BTN_UP)
1301 background.height /= 2;
1302 else
1303 background.height /= 5;
1304 dc.GradientFillLinear(background, m_page_background_top_colour,
1305 m_page_background_top_gradient_colour, wxSOUTH);
1306
1307 background.y += background.height;
1308 background.height = rect.height - 2 - background.height;
1309 dc.GradientFillLinear(background, m_page_background_colour,
1310 m_page_background_gradient_colour, wxSOUTH);
1311 }
1312
1313 {
1314 wxPoint border_points[7];
1315 switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK)
1316 {
1317 case wxRIBBON_SCROLL_BTN_LEFT:
1318 border_points[0] = wxPoint(2, 0);
1319 border_points[1] = wxPoint(rect.width - 1, 0);
1320 border_points[2] = wxPoint(rect.width - 1, rect.height - 1);
1321 border_points[3] = wxPoint(2, rect.height - 1);
1322 border_points[4] = wxPoint(0, rect.height - 3);
1323 border_points[5] = wxPoint(0, 2);
1324 break;
1325 case wxRIBBON_SCROLL_BTN_RIGHT:
1326 border_points[0] = wxPoint(0, 0);
1327 border_points[1] = wxPoint(rect.width - 3, 0);
1328 border_points[2] = wxPoint(rect.width - 1, 2);
1329 border_points[3] = wxPoint(rect.width - 1, rect.height - 3);
1330 border_points[4] = wxPoint(rect.width - 3, rect.height - 1);
1331 border_points[5] = wxPoint(0, rect.height - 1);
1332 break;
1333 case wxRIBBON_SCROLL_BTN_UP:
1334 border_points[0] = wxPoint(2, 0);
1335 border_points[1] = wxPoint(rect.width - 3, 0);
1336 border_points[2] = wxPoint(rect.width - 1, 2);
1337 border_points[3] = wxPoint(rect.width - 1, rect.height - 1);
1338 border_points[4] = wxPoint(0, rect.height - 1);
1339 border_points[5] = wxPoint(0, 2);
1340 break;
1341 case wxRIBBON_SCROLL_BTN_DOWN:
1342 border_points[0] = wxPoint(0, 0);
1343 border_points[1] = wxPoint(rect.width - 1, 0);
1344 border_points[2] = wxPoint(rect.width - 1, rect.height - 3);
1345 border_points[3] = wxPoint(rect.width - 3, rect.height - 1);
1346 border_points[4] = wxPoint(2, rect.height - 1);
1347 border_points[5] = wxPoint(0, rect.height - 3);
1348 break;
1349 }
1350 border_points[6] = border_points[0];
1351
1352 dc.SetPen(m_page_border_pen);
1353 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, rect.x, rect.y);
1354 }
1355
1356 {
1357 // NB: Code for handling hovered/active state is temporary
1358 wxPoint arrow_points[3];
1359 switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK)
1360 {
1361 case wxRIBBON_SCROLL_BTN_LEFT:
1362 arrow_points[0] = wxPoint(rect.width / 2 - 2, rect.height / 2);
1363 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
1364 arrow_points[0].y += 1;
1365 arrow_points[1] = arrow_points[0] + wxPoint(3, -3);
1366 arrow_points[2] = arrow_points[0] + wxPoint(3, 3);
1367 break;
1368 case wxRIBBON_SCROLL_BTN_RIGHT:
1369 arrow_points[0] = wxPoint(rect.width / 2 + 2, rect.height / 2);
1370 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
1371 arrow_points[0].y += 1;
1372 arrow_points[1] = arrow_points[0] - wxPoint(3, 3);
1373 arrow_points[2] = arrow_points[0] - wxPoint(3, -3);
1374 break;
1375 case wxRIBBON_SCROLL_BTN_UP:
1376 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 - 2);
1377 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
1378 arrow_points[0].y += 1;
1379 arrow_points[1] = arrow_points[0] + wxPoint( 3, 3);
1380 arrow_points[2] = arrow_points[0] + wxPoint(-3, 3);
1381 break;
1382 case wxRIBBON_SCROLL_BTN_DOWN:
1383 arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 + 2);
1384 if(style & wxRIBBON_SCROLL_BTN_ACTIVE)
1385 arrow_points[0].y += 1;
1386 arrow_points[1] = arrow_points[0] - wxPoint( 3, 3);
1387 arrow_points[2] = arrow_points[0] - wxPoint(-3, 3);
1388 break;
1389 }
1390
1391 dc.SetPen(*wxTRANSPARENT_PEN);
1392 wxBrush B(style & wxRIBBON_SCROLL_BTN_HOVERED ? m_tab_active_background_colour : m_tab_label_colour);
1393 dc.SetBrush(B);
1394 dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, rect.x, rect.y);
1395 }
1396 }
1397
1398 void wxRibbonMSWArtProvider::DrawDropdownArrow(wxDC& dc, int x, int y, const wxColour& colour)
1399 {
1400 wxPoint arrow_points[3];
1401 wxBrush brush(colour);
1402 arrow_points[0] = wxPoint(1, 2);
1403 arrow_points[1] = arrow_points[0] + wxPoint(-3, -3);
1404 arrow_points[2] = arrow_points[0] + wxPoint( 3, -3);
1405 dc.SetPen(*wxTRANSPARENT_PEN);
1406 dc.SetBrush(brush);
1407 dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, x, y);
1408 }
1409
1410 void wxRibbonMSWArtProvider::RemovePanelPadding(wxRect* rect)
1411 {
1412 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1413 {
1414 rect->y += 1;
1415 rect->height -= 2;
1416 }
1417 else
1418 {
1419 rect->x += 1;
1420 rect->width -= 2;
1421 }
1422 }
1423
1424 void wxRibbonMSWArtProvider::DrawPanelBackground(
1425 wxDC& dc,
1426 wxRibbonPanel* wnd,
1427 const wxRect& rect)
1428 {
1429 DrawPartialPageBackground(dc, wnd, rect, false);
1430
1431 wxRect true_rect(rect);
1432 RemovePanelPadding(&true_rect);
1433
1434 int label_height;
1435 {
1436 dc.SetFont(m_panel_label_font);
1437 dc.SetPen(*wxTRANSPARENT_PEN);
1438 if(wnd->IsHovered())
1439 {
1440 dc.SetBrush(m_panel_hover_label_background_brush);
1441 dc.SetTextForeground(m_panel_hover_label_colour);
1442 }
1443 else
1444 {
1445 dc.SetBrush(m_panel_label_background_brush);
1446 dc.SetTextForeground(m_panel_label_colour);
1447 }
1448
1449 wxRect label_rect(true_rect);
1450 wxString label = wnd->GetLabel();
1451 bool clip_label = false;
1452 wxSize label_size(dc.GetTextExtent(label));
1453
1454 label_rect.SetX(label_rect.GetX() + 1);
1455 label_rect.SetWidth(label_rect.GetWidth() - 2);
1456 label_rect.SetHeight(label_size.GetHeight() + 2);
1457 label_rect.SetY(true_rect.GetBottom() - label_rect.GetHeight());
1458 label_height = label_rect.GetHeight();
1459
1460 if(label_size.GetWidth() > label_rect.GetWidth())
1461 {
1462 // Test if there is enough length for 3 letters and ...
1463 wxString new_label = label.Mid(0, 3) + wxT("...");
1464 label_size = dc.GetTextExtent(new_label);
1465 if(label_size.GetWidth() > label_rect.GetWidth())
1466 {
1467 // Not enough room for three characters and ...
1468 // Display the entire label and just crop it
1469 clip_label = true;
1470 }
1471 else
1472 {
1473 // Room for some characters and ...
1474 // Display as many characters as possible and append ...
1475 for(size_t len = label.Len() - 1; len >= 3; --len)
1476 {
1477 new_label = label.Mid(0, len) + wxT("...");
1478 label_size = dc.GetTextExtent(new_label);
1479 if(label_size.GetWidth() <= label_rect.GetWidth())
1480 {
1481 label = new_label;
1482 break;
1483 }
1484 }
1485 }
1486 }
1487
1488 dc.DrawRectangle(label_rect.GetX(), label_rect.GetY(), label_rect.GetWidth(), label_rect.GetHeight());
1489 if(clip_label)
1490 {
1491 wxDCClipper clip(dc, label_rect);
1492 dc.DrawText(label, label_rect.x, label_rect.y +
1493 (label_rect.GetHeight() - label_size.GetHeight()) / 2);
1494 }
1495 else
1496 {
1497 dc.DrawText(label, label_rect.x +
1498 (label_rect.GetWidth() - label_size.GetWidth()) / 2,
1499 label_rect.y +
1500 (label_rect.GetHeight() - label_size.GetHeight()) / 2);
1501 }
1502 }
1503
1504 if(wnd->IsHovered())
1505 {
1506 wxRect client_rect(true_rect);
1507 client_rect.x++;
1508 client_rect.width -= 2;
1509 client_rect.y++;
1510 client_rect.height -= 2 + label_height;
1511 DrawPartialPageBackground(dc, wnd, client_rect, true);
1512 }
1513
1514 DrawPanelBorder(dc, true_rect, m_panel_border_pen, m_panel_border_gradient_pen);
1515 }
1516
1517 void wxRibbonMSWArtProvider::DrawGalleryBackground(
1518 wxDC& dc,
1519 wxRibbonGallery* wnd,
1520 const wxRect& rect)
1521 {
1522 DrawPartialPageBackground(dc, wnd, rect);
1523
1524 if(wnd->IsHovered())
1525 {
1526 dc.SetPen(*wxTRANSPARENT_PEN);
1527 dc.SetBrush(m_gallery_hover_background_brush);
1528 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1529 {
1530 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 2,
1531 rect.height - 16);
1532 }
1533 else
1534 {
1535 dc.DrawRectangle(rect.x + 1, rect.y + 1, rect.width - 16,
1536 rect.height - 2);
1537 }
1538 }
1539
1540 dc.SetPen(m_gallery_border_pen);
1541 // Outline
1542 dc.DrawLine(rect.x + 1, rect.y, rect.x + rect.width - 1, rect.y);
1543 dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
1544 dc.DrawLine(rect.x + 1, rect.y + rect.height - 1, rect.x + rect.width - 1,
1545 rect.y + rect.height - 1);
1546 dc.DrawLine(rect.x + rect.width - 1, rect.y + 1, rect.x + rect.width - 1,
1547 rect.y + rect.height - 1);
1548
1549 DrawGalleryBackgroundCommon(dc, wnd, rect);
1550 }
1551
1552 void wxRibbonMSWArtProvider::DrawGalleryBackgroundCommon(wxDC& dc,
1553 wxRibbonGallery* wnd,
1554 const wxRect& rect)
1555 {
1556 wxRect up_btn, down_btn, ext_btn;
1557
1558 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1559 {
1560 // Divider between items and buttons
1561 dc.DrawLine(rect.x, rect.y + rect.height - 15, rect.x + rect.width,
1562 rect.y + rect.height - 15);
1563
1564 up_btn = wxRect(rect.x, rect.y + rect.height - 15, rect.width / 3, 15);
1565
1566 down_btn = wxRect(up_btn.GetRight() + 1, up_btn.GetTop(),
1567 up_btn.GetWidth(), up_btn.GetHeight());
1568 dc.DrawLine(down_btn.GetLeft(), down_btn.GetTop(), down_btn.GetLeft(),
1569 down_btn.GetBottom());
1570
1571 ext_btn = wxRect(down_btn.GetRight() + 1, up_btn.GetTop(), rect.width -
1572 up_btn.GetWidth() - down_btn.GetWidth() - 1, up_btn.GetHeight());
1573 dc.DrawLine(ext_btn.GetLeft(), ext_btn.GetTop(), ext_btn.GetLeft(),
1574 ext_btn.GetBottom());
1575 }
1576 else
1577 {
1578 // Divider between items and buttons
1579 dc.DrawLine(rect.x + rect.width - 15, rect.y, rect.x + rect.width - 15,
1580 rect.y + rect.height);
1581
1582 up_btn = wxRect(rect.x + rect.width - 15, rect.y, 15, rect.height / 3);
1583
1584 down_btn = wxRect(up_btn.GetLeft(), up_btn.GetBottom() + 1,
1585 up_btn.GetWidth(), up_btn.GetHeight());
1586 dc.DrawLine(down_btn.GetLeft(), down_btn.GetTop(), down_btn.GetRight(),
1587 down_btn.GetTop());
1588
1589 ext_btn = wxRect(up_btn.GetLeft(), down_btn.GetBottom() + 1, up_btn.GetWidth(),
1590 rect.height - up_btn.GetHeight() - down_btn.GetHeight() - 1);
1591 dc.DrawLine(ext_btn.GetLeft(), ext_btn.GetTop(), ext_btn.GetRight(),
1592 ext_btn.GetTop());
1593 }
1594
1595 DrawGalleryButton(dc, up_btn, wnd->GetUpButtonState(),
1596 m_gallery_up_bitmap);
1597 DrawGalleryButton(dc, down_btn, wnd->GetDownButtonState(),
1598 m_gallery_down_bitmap);
1599 DrawGalleryButton(dc, ext_btn, wnd->GetExtensionButtonState(),
1600 m_gallery_extension_bitmap);
1601 }
1602
1603 void wxRibbonMSWArtProvider::DrawGalleryButton(wxDC& dc,
1604 wxRect rect,
1605 wxRibbonGalleryButtonState state,
1606 wxBitmap* bitmaps)
1607 {
1608 wxBitmap btn_bitmap;
1609 wxBrush btn_top_brush;
1610 wxColour btn_colour;
1611 wxColour btn_grad_colour;
1612 switch(state)
1613 {
1614 case wxRIBBON_GALLERY_BUTTON_NORMAL:
1615 btn_top_brush = m_gallery_button_background_top_brush;
1616 btn_colour = m_gallery_button_background_colour;
1617 btn_grad_colour = m_gallery_button_background_gradient_colour;
1618 btn_bitmap = bitmaps[0];
1619 break;
1620 case wxRIBBON_GALLERY_BUTTON_HOVERED:
1621 btn_top_brush = m_gallery_button_hover_background_top_brush;
1622 btn_colour = m_gallery_button_hover_background_colour;
1623 btn_grad_colour = m_gallery_button_hover_background_gradient_colour;
1624 btn_bitmap = bitmaps[1];
1625 break;
1626 case wxRIBBON_GALLERY_BUTTON_ACTIVE:
1627 btn_top_brush = m_gallery_button_active_background_top_brush;
1628 btn_colour = m_gallery_button_active_background_colour;
1629 btn_grad_colour = m_gallery_button_active_background_gradient_colour;
1630 btn_bitmap = bitmaps[2];
1631 break;
1632 case wxRIBBON_GALLERY_BUTTON_DISABLED:
1633 btn_top_brush = m_gallery_button_disabled_background_top_brush;
1634 btn_colour = m_gallery_button_disabled_background_colour;
1635 btn_grad_colour = m_gallery_button_disabled_background_gradient_colour;
1636 btn_bitmap = bitmaps[3];
1637 break;
1638 }
1639
1640 rect.x++;
1641 rect.y++;
1642 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1643 {
1644 rect.width--;;
1645 rect.height -= 2;
1646 }
1647 else
1648 {
1649 rect.width -= 2;
1650 rect.height--;
1651 }
1652
1653 dc.SetPen(*wxTRANSPARENT_PEN);
1654 dc.SetBrush(btn_top_brush);
1655 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height / 2);
1656
1657 wxRect lower(rect);
1658 lower.height = (lower.height + 1) / 2;
1659 lower.y += rect.height - lower.height;
1660 dc.GradientFillLinear(lower, btn_colour, btn_grad_colour, wxSOUTH);
1661
1662 dc.DrawBitmap(btn_bitmap, rect.x + rect.width / 2 - 2, lower.y - 2, true);
1663 }
1664
1665 void wxRibbonMSWArtProvider::DrawGalleryItemBackground(
1666 wxDC& dc,
1667 wxRibbonGallery* wnd,
1668 const wxRect& rect,
1669 wxRibbonGalleryItem* item)
1670 {
1671 if(wnd->GetHoveredItem() != item && wnd->GetActiveItem() != item &&
1672 wnd->GetSelection() != item)
1673 return;
1674
1675 dc.SetPen(m_gallery_item_border_pen);
1676 dc.DrawLine(rect.x + 1, rect.y, rect.x + rect.width - 1, rect.y);
1677 dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
1678 dc.DrawLine(rect.x + 1, rect.y + rect.height - 1, rect.x + rect.width - 1,
1679 rect.y + rect.height - 1);
1680 dc.DrawLine(rect.x + rect.width - 1, rect.y + 1, rect.x + rect.width - 1,
1681 rect.y + rect.height - 1);
1682
1683 wxBrush top_brush;
1684 wxColour bg_colour;
1685 wxColour bg_gradient_colour;
1686
1687 if(wnd->GetActiveItem() == item || wnd->GetSelection() == item)
1688 {
1689 top_brush = m_gallery_button_active_background_top_brush;
1690 bg_colour = m_gallery_button_active_background_colour;
1691 bg_gradient_colour = m_gallery_button_active_background_gradient_colour;
1692 }
1693 else
1694 {
1695 top_brush = m_gallery_button_hover_background_top_brush;
1696 bg_colour = m_gallery_button_hover_background_colour;
1697 bg_gradient_colour = m_gallery_button_hover_background_gradient_colour;
1698 }
1699
1700 wxRect upper(rect);
1701 upper.x += 1;
1702 upper.width -= 2;
1703 upper.y += 1;
1704 upper.height /= 3;
1705 dc.SetPen(*wxTRANSPARENT_PEN);
1706 dc.SetBrush(top_brush);
1707 dc.DrawRectangle(upper.x, upper.y, upper.width, upper.height);
1708
1709 wxRect lower(upper);
1710 lower.y += lower.height;
1711 lower.height = rect.height - 2 - lower.height;
1712 dc.GradientFillLinear(lower, bg_colour, bg_gradient_colour, wxSOUTH);
1713 }
1714
1715 void wxRibbonMSWArtProvider::DrawPanelBorder(wxDC& dc, const wxRect& rect,
1716 wxPen& primary_colour,
1717 wxPen& secondary_colour)
1718 {
1719 wxPoint border_points[9];
1720 border_points[0] = wxPoint(2, 0);
1721 border_points[1] = wxPoint(rect.width - 3, 0);
1722 border_points[2] = wxPoint(rect.width - 1, 2);
1723 border_points[3] = wxPoint(rect.width - 1, rect.height - 3);
1724 border_points[4] = wxPoint(rect.width - 3, rect.height - 1);
1725 border_points[5] = wxPoint(2, rect.height - 1);
1726 border_points[6] = wxPoint(0, rect.height - 3);
1727 border_points[7] = wxPoint(0, 2);
1728
1729 if(primary_colour.GetColour() == secondary_colour.GetColour())
1730 {
1731 border_points[8] = border_points[0];
1732 dc.SetPen(primary_colour);
1733 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, rect.x, rect.y);
1734 }
1735 else
1736 {
1737 dc.SetPen(primary_colour);
1738 dc.DrawLines(3, border_points, rect.x, rect.y);
1739
1740 #define SingleLine(start, finish) \
1741 dc.DrawLine(start.x + rect.x, start.y + rect.y, finish.x + rect.x, finish.y + rect.y)
1742
1743 SingleLine(border_points[0], border_points[7]);
1744 dc.SetPen(secondary_colour);
1745 dc.DrawLines(3, border_points + 4, rect.x, rect.y);
1746 SingleLine(border_points[4], border_points[3]);
1747
1748 #undef SingleLine
1749
1750 border_points[6] = border_points[2];
1751 wxRibbonDrawParallelGradientLines(dc, 2, border_points + 6, 0, 1,
1752 border_points[3].y - border_points[2].y + 1, rect.x, rect.y,
1753 primary_colour.GetColour(), secondary_colour.GetColour());
1754 }
1755 }
1756
1757 void wxRibbonMSWArtProvider::DrawMinimisedPanel(
1758 wxDC& dc,
1759 wxRibbonPanel* wnd,
1760 const wxRect& rect,
1761 wxBitmap& bitmap)
1762 {
1763 DrawPartialPageBackground(dc, wnd, rect, false);
1764
1765 wxRect true_rect(rect);
1766 RemovePanelPadding(&true_rect);
1767
1768 if(wnd->GetExpandedPanel() != NULL)
1769 {
1770 wxRect client_rect(true_rect);
1771 client_rect.x++;
1772 client_rect.width -= 2;
1773 client_rect.y++;
1774 client_rect.height = (rect.y + rect.height / 5) - client_rect.x;
1775 dc.GradientFillLinear(client_rect,
1776 m_panel_active_background_top_colour,
1777 m_panel_active_background_top_gradient_colour, wxSOUTH);
1778
1779 client_rect.y += client_rect.height;
1780 client_rect.height = (true_rect.y + true_rect.height) - client_rect.y;
1781 dc.GradientFillLinear(client_rect,
1782 m_panel_active_background_colour,
1783 m_panel_active_background_gradient_colour, wxSOUTH);
1784 }
1785 else if(wnd->IsHovered())
1786 {
1787 wxRect client_rect(true_rect);
1788 client_rect.x++;
1789 client_rect.width -= 2;
1790 client_rect.y++;
1791 client_rect.height -= 2;
1792 DrawPartialPageBackground(dc, wnd, client_rect, true);
1793 }
1794
1795 wxRect preview;
1796 DrawMinimisedPanelCommon(dc, wnd, true_rect, &preview);
1797
1798 dc.SetBrush(m_panel_hover_label_background_brush);
1799 dc.SetPen(*wxTRANSPARENT_PEN);
1800 dc.DrawRectangle(preview.x + 1, preview.y + preview.height - 8,
1801 preview.width - 2, 7);
1802
1803 int mid_pos = rect.y + rect.height / 5 - preview.y;
1804 if(mid_pos < 0 || mid_pos >= preview.height)
1805 {
1806 wxRect full_rect(preview);
1807 full_rect.x += 1;
1808 full_rect.y += 1;
1809 full_rect.width -= 2;
1810 full_rect.height -= 9;
1811 if(mid_pos < 0)
1812 {
1813 dc.GradientFillLinear(full_rect,
1814 m_page_hover_background_colour,
1815 m_page_hover_background_gradient_colour, wxSOUTH);
1816 }
1817 else
1818 {
1819 dc.GradientFillLinear(full_rect,
1820 m_page_hover_background_top_colour,
1821 m_page_hover_background_top_gradient_colour, wxSOUTH);
1822 }
1823 }
1824 else
1825 {
1826 wxRect top_rect(preview);
1827 top_rect.x += 1;
1828 top_rect.y += 1;
1829 top_rect.width -= 2;
1830 top_rect.height = mid_pos;
1831 dc.GradientFillLinear(top_rect,
1832 m_page_hover_background_top_colour,
1833 m_page_hover_background_top_gradient_colour, wxSOUTH);
1834
1835 wxRect btm_rect(top_rect);
1836 btm_rect.y = preview.y + mid_pos;
1837 btm_rect.height = preview.y + preview.height - 7 - btm_rect.y;
1838 dc.GradientFillLinear(btm_rect,
1839 m_page_hover_background_colour,
1840 m_page_hover_background_gradient_colour, wxSOUTH);
1841 }
1842
1843 if(bitmap.IsOk())
1844 {
1845 dc.DrawBitmap(bitmap, preview.x + (preview.width - bitmap.GetWidth()) / 2,
1846 preview.y + (preview.height - 7 - bitmap.GetHeight()) / 2, true);
1847 }
1848
1849 DrawPanelBorder(dc, preview, m_panel_border_pen, m_panel_border_gradient_pen);
1850
1851 DrawPanelBorder(dc, true_rect, m_panel_minimised_border_pen,
1852 m_panel_minimised_border_gradient_pen);
1853 }
1854
1855 void wxRibbonMSWArtProvider::DrawMinimisedPanelCommon(
1856 wxDC& dc,
1857 wxRibbonPanel* wnd,
1858 const wxRect& true_rect,
1859 wxRect* preview_rect)
1860 {
1861 wxRect preview(0, 0, 32, 32);
1862 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1863 {
1864 preview.x = true_rect.x + 4;
1865 preview.y = true_rect.y + (true_rect.height - preview.height) / 2;
1866 }
1867 else
1868 {
1869 preview.x = true_rect.x + (true_rect.width - preview.width) / 2;
1870 preview.y = true_rect.y + 4;
1871 }
1872 if(preview_rect)
1873 *preview_rect = preview;
1874
1875 wxCoord label_width, label_height;
1876 dc.SetFont(m_panel_label_font);
1877 dc.GetTextExtent(wnd->GetLabel(), &label_width, &label_height);
1878
1879 int xpos = true_rect.x + (true_rect.width - label_width + 1) / 2;
1880 int ypos = preview.y + preview.height + 5;
1881
1882 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1883 {
1884 xpos = preview.x + preview.width + 5;
1885 ypos = true_rect.y + (true_rect.height - label_height) / 2;
1886 }
1887
1888 dc.SetTextForeground(m_panel_minimised_label_colour);
1889 dc.DrawText(wnd->GetLabel(), xpos, ypos);
1890
1891
1892 wxPoint arrow_points[3];
1893 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
1894 {
1895 xpos += label_width;
1896 arrow_points[0] = wxPoint(xpos + 5, ypos + label_height / 2);
1897 arrow_points[1] = arrow_points[0] + wxPoint(-3, 3);
1898 arrow_points[2] = arrow_points[0] + wxPoint(-3, -3);
1899 }
1900 else
1901 {
1902 ypos += label_height;
1903 arrow_points[0] = wxPoint(true_rect.width / 2, ypos + 5);
1904 arrow_points[1] = arrow_points[0] + wxPoint(-3, -3);
1905 arrow_points[2] = arrow_points[0] + wxPoint( 3, -3);
1906 }
1907
1908 dc.SetPen(*wxTRANSPARENT_PEN);
1909 wxBrush B(m_panel_minimised_label_colour);
1910 dc.SetBrush(B);
1911 dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points,
1912 true_rect.x, true_rect.y);
1913 }
1914
1915 void wxRibbonMSWArtProvider::DrawButtonBarBackground(
1916 wxDC& dc,
1917 wxWindow* wnd,
1918 const wxRect& rect)
1919 {
1920 DrawPartialPageBackground(dc, wnd, rect, true);
1921 }
1922
1923 void wxRibbonMSWArtProvider::DrawPartialPageBackground(
1924 wxDC& dc,
1925 wxWindow* wnd,
1926 const wxRect& rect,
1927 bool allow_hovered)
1928 {
1929 // Assume the window is a child of a ribbon page, and also check for a
1930 // hovered panel somewhere between the window and the page, as it causes
1931 // the background to change.
1932 wxPoint offset(wnd->GetPosition());
1933 wxRibbonPage* page = NULL;
1934 wxWindow* parent = wnd->GetParent();
1935 wxRibbonPanel* panel = wxDynamicCast(wnd, wxRibbonPanel);
1936 bool hovered = false;
1937
1938 if(panel != NULL)
1939 {
1940 hovered = allow_hovered && panel->IsHovered();
1941 if(panel->GetExpandedDummy() != NULL)
1942 {
1943 offset = panel->GetExpandedDummy()->GetPosition();
1944 parent = panel->GetExpandedDummy()->GetParent();
1945 }
1946 }
1947 for(; parent; parent = parent->GetParent())
1948 {
1949 if(panel == NULL)
1950 {
1951 panel = wxDynamicCast(parent, wxRibbonPanel);
1952 if(panel != NULL)
1953 {
1954 hovered = allow_hovered && panel->IsHovered();
1955 if(panel->GetExpandedDummy() != NULL)
1956 {
1957 parent = panel->GetExpandedDummy();
1958 }
1959 }
1960 }
1961 page = wxDynamicCast(parent, wxRibbonPage);
1962 if(page != NULL)
1963 {
1964 break;
1965 }
1966 offset += parent->GetPosition();
1967 }
1968 if(page != NULL)
1969 {
1970 DrawPartialPageBackground(dc, wnd, rect, page, offset, hovered);
1971 return;
1972 }
1973
1974 // No page found - fallback to painting with a stock brush
1975 dc.SetBrush(*wxWHITE_BRUSH);
1976 dc.SetPen(*wxTRANSPARENT_PEN);
1977 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
1978 }
1979
1980 void wxRibbonMSWArtProvider::DrawButtonBarButton(
1981 wxDC& dc,
1982 wxWindow* WXUNUSED(wnd),
1983 const wxRect& rect,
1984 wxRibbonButtonKind kind,
1985 long state,
1986 const wxString& label,
1987 const wxBitmap& bitmap_large,
1988 const wxBitmap& bitmap_small)
1989 {
1990 if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK |
1991 wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
1992 {
1993 if(state & wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK)
1994 dc.SetPen(m_button_bar_active_border_pen);
1995 else
1996 dc.SetPen(m_button_bar_hover_border_pen);
1997
1998 wxRect bg_rect(rect);
1999 bg_rect.x++;
2000 bg_rect.y++;
2001 bg_rect.width -= 2;
2002 bg_rect.height -= 2;
2003
2004 wxRect bg_rect_top(bg_rect);
2005 bg_rect_top.height /= 3;
2006 bg_rect.y += bg_rect_top.height;
2007 bg_rect.height -= bg_rect_top.height;
2008
2009 if(kind == wxRIBBON_BUTTON_HYBRID)
2010 {
2011 switch(state & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
2012 {
2013 case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
2014 {
2015 int iYBorder = rect.y + bitmap_large.GetHeight() + 4;
2016 wxRect partial_bg(rect);
2017 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
2018 {
2019 partial_bg.SetBottom(iYBorder - 1);
2020 }
2021 else
2022 {
2023 partial_bg.height -= (iYBorder - partial_bg.y + 1);
2024 partial_bg.y = iYBorder + 1;
2025 }
2026 dc.DrawLine(rect.x, iYBorder, rect.x + rect.width, iYBorder);
2027 bg_rect.Intersect(partial_bg);
2028 bg_rect_top.Intersect(partial_bg);
2029 }
2030 break;
2031 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
2032 {
2033 int iArrowWidth = 9;
2034 if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
2035 {
2036 bg_rect.width -= iArrowWidth;
2037 bg_rect_top.width -= iArrowWidth;
2038 dc.DrawLine(bg_rect_top.x + bg_rect_top.width,
2039 rect.y, bg_rect_top.x + bg_rect_top.width,
2040 rect.y + rect.height);
2041 }
2042 else
2043 {
2044 --iArrowWidth;
2045 bg_rect.x += bg_rect.width - iArrowWidth;
2046 bg_rect_top.x += bg_rect_top.width - iArrowWidth;
2047 bg_rect.width = iArrowWidth;
2048 bg_rect_top.width = iArrowWidth;
2049 dc.DrawLine(bg_rect_top.x - 1, rect.y,
2050 bg_rect_top.x - 1, rect.y + rect.height);
2051 }
2052 }
2053 break;
2054 case wxRIBBON_BUTTONBAR_BUTTON_SMALL:
2055 break;
2056 }
2057 }
2058
2059 if(state & wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK)
2060 {
2061 dc.GradientFillLinear(bg_rect_top,
2062 m_button_bar_active_background_top_colour,
2063 m_button_bar_active_background_top_gradient_colour, wxSOUTH);
2064 dc.GradientFillLinear(bg_rect,
2065 m_button_bar_active_background_colour,
2066 m_button_bar_active_background_gradient_colour, wxSOUTH);
2067 }
2068 else
2069 {
2070 dc.GradientFillLinear(bg_rect_top,
2071 m_button_bar_hover_background_top_colour,
2072 m_button_bar_hover_background_top_gradient_colour, wxSOUTH);
2073 dc.GradientFillLinear(bg_rect,
2074 m_button_bar_hover_background_colour,
2075 m_button_bar_hover_background_gradient_colour, wxSOUTH);
2076 }
2077
2078 wxPoint border_points[9];
2079 border_points[0] = wxPoint(2, 0);
2080 border_points[1] = wxPoint(rect.width - 3, 0);
2081 border_points[2] = wxPoint(rect.width - 1, 2);
2082 border_points[3] = wxPoint(rect.width - 1, rect.height - 3);
2083 border_points[4] = wxPoint(rect.width - 3, rect.height - 1);
2084 border_points[5] = wxPoint(2, rect.height - 1);
2085 border_points[6] = wxPoint(0, rect.height - 3);
2086 border_points[7] = wxPoint(0, 2);
2087 border_points[8] = border_points[0];
2088
2089 dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points,
2090 rect.x, rect.y);
2091 }
2092
2093 dc.SetFont(m_button_bar_label_font);
2094 dc.SetTextForeground(m_button_bar_label_colour);
2095 DrawButtonBarButtonForeground(dc, rect, kind, state, label, bitmap_large,
2096 bitmap_small);
2097 }
2098
2099 void wxRibbonMSWArtProvider::DrawButtonBarButtonForeground(
2100 wxDC& dc,
2101 const wxRect& rect,
2102 wxRibbonButtonKind kind,
2103 long state,
2104 const wxString& label,
2105 const wxBitmap& bitmap_large,
2106 const wxBitmap& bitmap_small)
2107 {
2108 switch(state & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
2109 {
2110 case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
2111 {
2112 const int padding = 2;
2113 dc.DrawBitmap(bitmap_large,
2114 rect.x + (rect.width - bitmap_large.GetWidth()) / 2,
2115 rect.y + padding, true);
2116 int ypos = rect.y + padding + bitmap_large.GetHeight() + padding;
2117 int arrow_width = kind == wxRIBBON_BUTTON_NORMAL ? 0 : 8;
2118 wxCoord label_w, label_h;
2119 dc.GetTextExtent(label, &label_w, &label_h);
2120 if(label_w + 2 * padding <= rect.width)
2121 {
2122 dc.DrawText(label, rect.x + (rect.width - label_w) / 2, ypos);
2123 if(arrow_width != 0)
2124 {
2125 DrawDropdownArrow(dc, rect.x + rect.width / 2,
2126 ypos + (label_h * 3) / 2,
2127 m_button_bar_label_colour);
2128 }
2129 }
2130 else
2131 {
2132 size_t breaki = label.Len();
2133 do
2134 {
2135 --breaki;
2136 if(wxRibbonCanLabelBreakAtPosition(label, breaki))
2137 {
2138 wxString label_top = label.Mid(0, breaki);
2139 dc.GetTextExtent(label_top, &label_w, &label_h);
2140 if(label_w + 2 * padding <= rect.width)
2141 {
2142 dc.DrawText(label_top,
2143 rect.x + (rect.width - label_w) / 2, ypos);
2144 ypos += label_h;
2145 wxString label_bottom = label.Mid(breaki + 1);
2146 dc.GetTextExtent(label_bottom, &label_w, &label_h);
2147 label_w += arrow_width;
2148 int iX = rect.x + (rect.width - label_w) / 2;
2149 dc.DrawText(label_bottom, iX, ypos);
2150 if(arrow_width != 0)
2151 {
2152 DrawDropdownArrow(dc,
2153 iX + 2 +label_w - arrow_width,
2154 ypos + label_h / 2 + 1,
2155 m_button_bar_label_colour);
2156 }
2157 break;
2158 }
2159 }
2160 } while(breaki > 0);
2161 }
2162 }
2163 break;
2164 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
2165 {
2166 int x_cursor = rect.x + 2;
2167 dc.DrawBitmap(bitmap_small, x_cursor,
2168 rect.y + (rect.height - bitmap_small.GetHeight())/2, true);
2169 x_cursor += bitmap_small.GetWidth() + 2;
2170 wxCoord label_w, label_h;
2171 dc.GetTextExtent(label, &label_w, &label_h);
2172 dc.DrawText(label, x_cursor,
2173 rect.y + (rect.height - label_h) / 2);
2174 x_cursor += label_w + 3;
2175 if(kind != wxRIBBON_BUTTON_NORMAL)
2176 {
2177 DrawDropdownArrow(dc, x_cursor, rect.y + rect.height / 2,
2178 m_button_bar_label_colour);
2179 }
2180 break;
2181 }
2182 default:
2183 // TODO
2184 break;
2185 }
2186 }
2187
2188 void wxRibbonMSWArtProvider::DrawToolBarBackground(
2189 wxDC& dc,
2190 wxWindow* wnd,
2191 const wxRect& rect)
2192 {
2193 DrawPartialPageBackground(dc, wnd, rect);
2194 }
2195
2196 void wxRibbonMSWArtProvider::DrawToolGroupBackground(
2197 wxDC& dc,
2198 wxWindow* WXUNUSED(wnd),
2199 const wxRect& rect)
2200 {
2201 dc.SetPen(m_toolbar_border_pen);
2202 wxPoint outline[9];
2203 outline[0] = wxPoint(2, 0);
2204 outline[1] = wxPoint(rect.width - 3, 0);
2205 outline[2] = wxPoint(rect.width - 1, 2);
2206 outline[3] = wxPoint(rect.width - 1, rect.height - 3);
2207 outline[4] = wxPoint(rect.width - 3, rect.height - 1);
2208 outline[5] = wxPoint(2, rect.height - 1);
2209 outline[6] = wxPoint(0, rect.height - 3);
2210 outline[7] = wxPoint(0, 2);
2211 outline[8] = outline[0];
2212
2213 dc.DrawLines(sizeof(outline)/sizeof(wxPoint), outline, rect.x, rect.y);
2214 }
2215
2216 void wxRibbonMSWArtProvider::DrawTool(
2217 wxDC& dc,
2218 wxWindow* WXUNUSED(wnd),
2219 const wxRect& rect,
2220 const wxBitmap& bitmap,
2221 wxRibbonButtonKind kind,
2222 long state)
2223 {
2224 wxRect bg_rect(rect);
2225 bg_rect.Deflate(1);
2226 if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
2227 bg_rect.width++;
2228 bool is_split_hybrid = (kind == wxRIBBON_BUTTON_HYBRID && (state &
2229 (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK | wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)));
2230
2231 // Background
2232 wxRect bg_rect_top(bg_rect);
2233 bg_rect_top.height = (bg_rect_top.height * 2) / 5;
2234 wxRect bg_rect_btm(bg_rect);
2235 bg_rect_btm.y += bg_rect_top.height;
2236 bg_rect_btm.height -= bg_rect_top.height;
2237 wxColour bg_top_colour = m_tool_background_top_colour;
2238 wxColour bg_top_grad_colour = m_tool_background_top_gradient_colour;
2239 wxColour bg_colour = m_tool_background_colour;
2240 wxColour bg_grad_colour = m_tool_background_gradient_colour;
2241 if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
2242 {
2243 bg_top_colour = m_tool_active_background_top_colour;
2244 bg_top_grad_colour = m_tool_active_background_top_gradient_colour;
2245 bg_colour = m_tool_active_background_colour;
2246 bg_grad_colour = m_tool_active_background_gradient_colour;
2247 }
2248 else if(state & wxRIBBON_TOOLBAR_TOOL_HOVER_MASK)
2249 {
2250 bg_top_colour = m_tool_hover_background_top_colour;
2251 bg_top_grad_colour = m_tool_hover_background_top_gradient_colour;
2252 bg_colour = m_tool_hover_background_colour;
2253 bg_grad_colour = m_tool_hover_background_gradient_colour;
2254 }
2255 dc.GradientFillLinear(bg_rect_top, bg_top_colour, bg_top_grad_colour, wxSOUTH);
2256 dc.GradientFillLinear(bg_rect_btm, bg_colour, bg_grad_colour, wxSOUTH);
2257 if(is_split_hybrid)
2258 {
2259 wxRect nonrect(bg_rect);
2260 if(state & (wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED |
2261 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE))
2262 {
2263 nonrect.width -= 8;
2264 }
2265 else
2266 {
2267 nonrect.x += nonrect.width - 8;
2268 nonrect.width = 8;
2269 }
2270 wxBrush B(m_tool_hover_background_top_colour);
2271 dc.SetPen(*wxTRANSPARENT_PEN);
2272 dc.SetBrush(B);
2273 dc.DrawRectangle(nonrect.x, nonrect.y, nonrect.width, nonrect.height);
2274 }
2275
2276 // Border
2277 dc.SetPen(m_toolbar_border_pen);
2278 if(state & wxRIBBON_TOOLBAR_TOOL_FIRST)
2279 {
2280 dc.DrawPoint(rect.x + 1, rect.y + 1);
2281 dc.DrawPoint(rect.x + 1, rect.y + rect.height - 2);
2282 }
2283 else
2284 dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
2285
2286 if(state & wxRIBBON_TOOLBAR_TOOL_LAST)
2287 {
2288 dc.DrawPoint(rect.x + rect.width - 2, rect.y + 1);
2289 dc.DrawPoint(rect.x + rect.width - 2, rect.y + rect.height - 2);
2290 }
2291
2292 // Foreground
2293 int avail_width = bg_rect.GetWidth();
2294 if(kind != wxRIBBON_BUTTON_NORMAL)
2295 {
2296 avail_width -= 8;
2297 if(is_split_hybrid)
2298 {
2299 dc.DrawLine(rect.x + avail_width + 1, rect.y,
2300 rect.x + avail_width + 1, rect.y + rect.height);
2301 }
2302 dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
2303 bg_rect.y + (bg_rect.height / 2) - 2, true);
2304 }
2305 dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
2306 bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
2307 }
2308
2309 void wxRibbonMSWArtProvider::GetBarTabWidth(
2310 wxDC& dc,
2311 wxWindow* WXUNUSED(wnd),
2312 const wxString& label,
2313 const wxBitmap& bitmap,
2314 int* ideal,
2315 int* small_begin_need_separator,
2316 int* small_must_have_separator,
2317 int* minimum)
2318 {
2319 int width = 0;
2320 int min = 0;
2321 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) && !label.IsEmpty())
2322 {
2323 dc.SetFont(m_tab_label_font);
2324 width += dc.GetTextExtent(label).GetWidth();
2325 min += wxMin(25, width); // enough for a few chars
2326 if(bitmap.IsOk())
2327 {
2328 // gap between label and bitmap
2329 width += 4;
2330 min += 2;
2331 }
2332 }
2333 if((m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS) && bitmap.IsOk())
2334 {
2335 width += bitmap.GetWidth();
2336 min += bitmap.GetWidth();
2337 }
2338
2339 if(ideal != NULL)
2340 {
2341 *ideal = width + 30;
2342 }
2343 if(small_begin_need_separator != NULL)
2344 {
2345 *small_begin_need_separator = width + 20;
2346 }
2347 if(small_must_have_separator != NULL)
2348 {
2349 *small_must_have_separator = width + 10;
2350 }
2351 if(minimum != NULL)
2352 {
2353 *minimum = min;
2354 }
2355 }
2356
2357 int wxRibbonMSWArtProvider::GetTabCtrlHeight(
2358 wxDC& dc,
2359 wxWindow* WXUNUSED(wnd),
2360 const wxRibbonPageTabInfoArray& pages)
2361 {
2362 int text_height = 0;
2363 int icon_height = 0;
2364
2365 if(pages.GetCount() <= 1 && (m_flags & wxRIBBON_BAR_ALWAYS_SHOW_TABS) == 0)
2366 {
2367 // To preserve space, a single tab need not be displayed. We still need
2368 // two pixels of border / padding though.
2369 return 2;
2370 }
2371
2372 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
2373 {
2374 dc.SetFont(m_tab_label_font);
2375 text_height = dc.GetTextExtent(wxT("ABCDEFXj")).GetHeight() + 10;
2376 }
2377 if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
2378 {
2379 size_t numpages = pages.GetCount();
2380 for(size_t i = 0; i < numpages; ++i)
2381 {
2382 const wxRibbonPageTabInfo& info = pages.Item(i);
2383 if(info.page->GetIcon().IsOk())
2384 {
2385 icon_height = wxMax(icon_height, info.page->GetIcon().GetHeight() + 4);
2386 }
2387 }
2388 }
2389
2390 return wxMax(text_height, icon_height);
2391 }
2392
2393 wxSize wxRibbonMSWArtProvider::GetScrollButtonMinimumSize(
2394 wxDC& WXUNUSED(dc),
2395 wxWindow* WXUNUSED(wnd),
2396 long WXUNUSED(style))
2397 {
2398 return wxSize(12, 12);
2399 }
2400
2401 wxSize wxRibbonMSWArtProvider::GetPanelSize(
2402 wxDC& dc,
2403 const wxRibbonPanel* wnd,
2404 wxSize client_size,
2405 wxPoint* client_offset)
2406 {
2407 dc.SetFont(m_panel_label_font);
2408 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
2409
2410 client_size.IncBy(0, label_size.GetHeight());
2411 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2412 client_size.IncBy(4, 8);
2413 else
2414 client_size.IncBy(6, 6);
2415
2416 if(client_offset != NULL)
2417 {
2418 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2419 *client_offset = wxPoint(2, 3);
2420 else
2421 *client_offset = wxPoint(3, 2);
2422 }
2423
2424 return client_size;
2425 }
2426
2427 wxSize wxRibbonMSWArtProvider::GetPanelClientSize(
2428 wxDC& dc,
2429 const wxRibbonPanel* wnd,
2430 wxSize size,
2431 wxPoint* client_offset)
2432 {
2433 dc.SetFont(m_panel_label_font);
2434 wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
2435
2436 size.DecBy(0, label_size.GetHeight());
2437 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2438 size.DecBy(4, 8);
2439 else
2440 size.DecBy(6, 6);
2441
2442 if(client_offset != NULL)
2443 {
2444 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2445 *client_offset = wxPoint(2, 3);
2446 else
2447 *client_offset = wxPoint(3, 2);
2448 }
2449
2450 return size;
2451 }
2452
2453 wxSize wxRibbonMSWArtProvider::GetGallerySize(
2454 wxDC& WXUNUSED(dc),
2455 const wxRibbonGallery* WXUNUSED(wnd),
2456 wxSize client_size)
2457 {
2458 client_size.IncBy( 2, 1); // Left / top padding
2459 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2460 client_size.IncBy(1, 16); // Right / bottom padding
2461 else
2462 client_size.IncBy(16, 1); // Right / bottom padding
2463 return client_size;
2464 }
2465
2466 wxSize wxRibbonMSWArtProvider::GetGalleryClientSize(
2467 wxDC& WXUNUSED(dc),
2468 const wxRibbonGallery* WXUNUSED(wnd),
2469 wxSize size,
2470 wxPoint* client_offset,
2471 wxRect* scroll_up_button,
2472 wxRect* scroll_down_button,
2473 wxRect* extension_button)
2474 {
2475 wxRect scroll_up;
2476 wxRect scroll_down;
2477 wxRect extension;
2478 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2479 {
2480 // Flow is vertical - put buttons on bottom
2481 scroll_up.y = size.GetHeight() - 15;
2482 scroll_up.height = 15;
2483 scroll_up.x = 0;
2484 scroll_up.width = (size.GetWidth() + 2) / 3;
2485 scroll_down.y = scroll_up.y;
2486 scroll_down.height = scroll_up.height;
2487 scroll_down.x = scroll_up.x + scroll_up.width;
2488 scroll_down.width = scroll_up.width;
2489 extension.y = scroll_down.y;
2490 extension.height = scroll_down.height;
2491 extension.x = scroll_down.x + scroll_down.width;
2492 extension.width = size.GetWidth() - scroll_up.width - scroll_down.width;
2493 size.DecBy(1, 16);
2494 size.DecBy( 2, 1);
2495 }
2496 else
2497 {
2498 // Flow is horizontal - put buttons on right
2499 scroll_up.x = size.GetWidth() - 15;
2500 scroll_up.width = 15;
2501 scroll_up.y = 0;
2502 scroll_up.height = (size.GetHeight() + 2) / 3;
2503 scroll_down.x = scroll_up.x;
2504 scroll_down.width = scroll_up.width;
2505 scroll_down.y = scroll_up.y + scroll_up.height;
2506 scroll_down.height = scroll_up.height;
2507 extension.x = scroll_down.x;
2508 extension.width = scroll_down.width;
2509 extension.y = scroll_down.y + scroll_down.height;
2510 extension.height = size.GetHeight() - scroll_up.height - scroll_down.height;
2511 size.DecBy(16, 1);
2512 size.DecBy( 2, 1);
2513 }
2514
2515 if(client_offset != NULL)
2516 *client_offset = wxPoint(2, 1);
2517 if(scroll_up_button != NULL)
2518 *scroll_up_button = scroll_up;
2519 if(scroll_down_button != NULL)
2520 *scroll_down_button = scroll_down;
2521 if(extension_button != NULL)
2522 *extension_button = extension;
2523
2524 return size;
2525 }
2526
2527 wxRect wxRibbonMSWArtProvider::GetPageBackgroundRedrawArea(
2528 wxDC& WXUNUSED(dc),
2529 const wxRibbonPage* WXUNUSED(wnd),
2530 wxSize page_old_size,
2531 wxSize page_new_size)
2532 {
2533 wxRect new_rect, old_rect;
2534
2535 if(page_new_size.GetWidth() != page_old_size.GetWidth())
2536 {
2537 if(page_new_size.GetHeight() != page_old_size.GetHeight())
2538 {
2539 // Width and height both changed - redraw everything
2540 return wxRect(page_new_size);
2541 }
2542 else
2543 {
2544 // Only width changed - redraw right hand side
2545 const int right_edge_width = 4;
2546
2547 new_rect = wxRect(page_new_size.GetWidth() - right_edge_width, 0, right_edge_width, page_new_size.GetHeight());
2548 old_rect = wxRect(page_old_size.GetWidth() - right_edge_width, 0, right_edge_width, page_old_size.GetHeight());
2549 }
2550 }
2551 else
2552 {
2553 if(page_new_size.GetHeight() == page_old_size.GetHeight())
2554 {
2555 // Nothing changed (should never happen) - redraw nothing
2556 return wxRect(0, 0, 0, 0);
2557 }
2558 else
2559 {
2560 // Height changed - need to redraw everything (as the background
2561 // gradient is done vertically).
2562 return page_new_size;
2563 }
2564 }
2565
2566 new_rect.Union(old_rect);
2567 new_rect.Intersect(wxRect(page_new_size));
2568 return new_rect;
2569 }
2570
2571 bool wxRibbonMSWArtProvider::GetButtonBarButtonSize(
2572 wxDC& dc,
2573 wxWindow* wnd,
2574 wxRibbonButtonKind kind,
2575 wxRibbonButtonBarButtonState size,
2576 const wxString& label,
2577 wxSize bitmap_size_large,
2578 wxSize bitmap_size_small,
2579 wxSize* button_size,
2580 wxRect* normal_region,
2581 wxRect* dropdown_region)
2582 {
2583 const int drop_button_width = 8;
2584
2585 dc.SetFont(m_button_bar_label_font);
2586 switch(size & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
2587 {
2588 case wxRIBBON_BUTTONBAR_BUTTON_SMALL:
2589 // Small bitmap, no label
2590 *button_size = bitmap_size_small + wxSize(6, 4);
2591 switch(kind)
2592 {
2593 case wxRIBBON_BUTTON_NORMAL:
2594 *normal_region = wxRect(*button_size);
2595 *dropdown_region = wxRect(0, 0, 0, 0);
2596 break;
2597 case wxRIBBON_BUTTON_DROPDOWN:
2598 *button_size += wxSize(drop_button_width, 0);
2599 *dropdown_region = wxRect(*button_size);
2600 *normal_region = wxRect(0, 0, 0, 0);
2601 break;
2602 case wxRIBBON_BUTTON_HYBRID:
2603 *normal_region = wxRect(*button_size);
2604 *dropdown_region = wxRect(button_size->GetWidth(), 0,
2605 drop_button_width, button_size->GetHeight());
2606 *button_size += wxSize(drop_button_width, 0);
2607 break;
2608 }
2609 break;
2610 case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
2611 // Small bitmap, with label to the right
2612 {
2613 GetButtonBarButtonSize(dc, wnd, kind, wxRIBBON_BUTTONBAR_BUTTON_SMALL,
2614 label, bitmap_size_large, bitmap_size_small, button_size,
2615 normal_region, dropdown_region);
2616 int text_size = dc.GetTextExtent(label).GetWidth();
2617 button_size->SetWidth(button_size->GetWidth() + text_size);
2618 switch(kind)
2619 {
2620 case wxRIBBON_BUTTON_DROPDOWN:
2621 dropdown_region->SetWidth(dropdown_region->GetWidth() + text_size);
2622 break;
2623 case wxRIBBON_BUTTON_HYBRID:
2624 dropdown_region->SetX(dropdown_region->GetX() + text_size);
2625 // no break
2626 case wxRIBBON_BUTTON_NORMAL:
2627 normal_region->SetWidth(normal_region->GetWidth() + text_size);
2628 break;
2629 }
2630 break;
2631 }
2632 case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
2633 // Large bitmap, with label below (possibly split over 2 lines)
2634 {
2635 wxSize icon_size(bitmap_size_large);
2636 icon_size += wxSize(4, 4);
2637 wxCoord label_height;
2638 wxCoord best_width;
2639 dc.GetTextExtent(label, &best_width, &label_height);
2640 int last_line_extra_width = 0;
2641 if(kind != wxRIBBON_BUTTON_NORMAL)
2642 {
2643 last_line_extra_width += 8;
2644 }
2645 size_t i;
2646 for(i = 0; i < label.Len(); ++i)
2647 {
2648 if(wxRibbonCanLabelBreakAtPosition(label, i))
2649 {
2650 int width = wxMax(
2651 dc.GetTextExtent(label.Mid(0, i - 1)).GetWidth(),
2652 dc.GetTextExtent(label.Mid(i + 1)).GetWidth() + last_line_extra_width);
2653 if(width < best_width)
2654 {
2655 best_width = width;
2656 }
2657 }
2658 }
2659 label_height *= 2; // Assume two lines even when only one is used
2660 // (to give all buttons a consistent height)
2661 icon_size.SetWidth(wxMax(icon_size.GetWidth(), best_width) + 6);
2662 icon_size.SetHeight(icon_size.GetHeight() + label_height);
2663 *button_size = icon_size;
2664 switch(kind)
2665 {
2666 case wxRIBBON_BUTTON_DROPDOWN:
2667 *dropdown_region = wxRect(icon_size);
2668 break;
2669 case wxRIBBON_BUTTON_HYBRID:
2670 *normal_region = wxRect(icon_size);
2671 normal_region->height -= 2 + label_height;
2672 dropdown_region->x = 0;
2673 dropdown_region->y = normal_region->height;
2674 dropdown_region->width = icon_size.GetWidth();
2675 dropdown_region->height = icon_size.GetHeight() - normal_region->height;
2676 break;
2677 case wxRIBBON_BUTTON_NORMAL:
2678 *normal_region = wxRect(icon_size);
2679 break;
2680 }
2681 break;
2682 }
2683 };
2684 return true;
2685 }
2686
2687 wxSize wxRibbonMSWArtProvider::GetMinimisedPanelMinimumSize(
2688 wxDC& dc,
2689 const wxRibbonPanel* wnd,
2690 wxSize* desired_bitmap_size,
2691 wxDirection* expanded_panel_direction)
2692 {
2693 if(desired_bitmap_size != NULL)
2694 {
2695 *desired_bitmap_size = wxSize(16, 16);
2696 }
2697 if(expanded_panel_direction != NULL)
2698 {
2699 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2700 *expanded_panel_direction = wxEAST;
2701 else
2702 *expanded_panel_direction = wxSOUTH;
2703 }
2704 wxSize base_size(42, 42);
2705
2706 dc.SetFont(m_panel_label_font);
2707 wxSize label_size(dc.GetTextExtent(wnd->GetLabel()));
2708 label_size.IncBy(2, 2); // Allow for differences between this DC and a paint DC
2709 label_size.IncBy(6, 0); // Padding
2710 label_size.y *= 2; // Second line for dropdown button
2711
2712 if(m_flags & wxRIBBON_BAR_FLOW_VERTICAL)
2713 {
2714 // Label alongside icon
2715 return wxSize(base_size.x + label_size.x,
2716 wxMax(base_size.y, label_size.y));
2717 }
2718 else
2719 {
2720 // Label beneath icon
2721 return wxSize(wxMax(base_size.x, label_size.x),
2722 base_size.y + label_size.y);
2723 }
2724 }
2725
2726 wxSize wxRibbonMSWArtProvider::GetToolSize(
2727 wxDC& WXUNUSED(dc),
2728 wxWindow* WXUNUSED(wnd),
2729 wxSize bitmap_size,
2730 wxRibbonButtonKind kind,
2731 bool WXUNUSED(is_first),
2732 bool is_last,
2733 wxRect* dropdown_region)
2734 {
2735 wxSize size(bitmap_size);
2736 size.IncBy(7, 6);
2737 if(is_last)
2738 size.IncBy(1, 0);
2739 if(kind != wxRIBBON_BUTTON_NORMAL)
2740 {
2741 size.IncBy(8, 0);
2742 if(dropdown_region)
2743 {
2744 if(kind == wxRIBBON_BUTTON_DROPDOWN)
2745 *dropdown_region = size;
2746 else
2747 *dropdown_region = wxRect(size.GetWidth() - 8, 0, 8, size.GetHeight());
2748 }
2749 }
2750 else
2751 {
2752 if(dropdown_region)
2753 *dropdown_region = wxRect(0, 0, 0, 0);
2754 }
2755 return size;
2756 }
2757
2758 #endif // wxUSE_RIBBON