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