OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/libgtkui/native_theme_gtk2.h" | |
6 | |
7 #include <gtk/gtk.h> | |
8 | |
9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h" | |
10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h" | |
11 #include "chrome/browser/ui/libgtkui/gtk2_ui.h" | |
12 #include "chrome/browser/ui/libgtkui/gtk2_util.h" | |
13 #include "chrome/browser/ui/libgtkui/skia_utils_gtk2.h" | |
14 #include "third_party/skia/include/core/SkColor.h" | |
15 #include "ui/gfx/color_palette.h" | |
16 #include "ui/gfx/color_utils.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 #include "ui/gfx/geometry/size.h" | |
19 #include "ui/gfx/path.h" | |
20 #include "ui/gfx/skia_util.h" | |
21 #include "ui/native_theme/common_theme.h" | |
22 #include "ui/native_theme/native_theme_aura.h" | |
23 #include "ui/native_theme/native_theme_dark_aura.h" | |
24 | |
25 namespace libgtkui { | |
26 | |
27 namespace { | |
28 | |
29 // Theme colors returned by GetSystemColor(). | |
30 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | |
31 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | |
32 | |
33 // Generates the normal URL color, a green color used in unhighlighted URL | |
34 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the | |
35 // selected text color, it is more important to match the qualities of the | |
36 // foreground typeface color instead of taking the background into account. | |
37 SkColor NormalURLColor(SkColor foreground) { | |
38 color_utils::HSL fg_hsl, hue_hsl; | |
39 color_utils::SkColorToHSL(foreground, &fg_hsl); | |
40 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); | |
41 | |
42 // Only allow colors that have a fair amount of saturation in them (color vs | |
43 // white). This means that our output color will always be fairly green. | |
44 double s = std::max(0.5, fg_hsl.s); | |
45 | |
46 // Make sure the luminance is at least as bright as the |kURLTextColor| green | |
47 // would be if we were to use that. | |
48 double l; | |
49 if (fg_hsl.l < hue_hsl.l) | |
50 l = hue_hsl.l; | |
51 else | |
52 l = (fg_hsl.l + hue_hsl.l) / 2; | |
53 | |
54 color_utils::HSL output = { hue_hsl.h, s, l }; | |
55 return color_utils::HSLToSkColor(output, 255); | |
56 } | |
57 | |
58 // Generates the selected URL color, a green color used on URL text in the | |
59 // currently highlighted entry in the autocomplete popup. It's a mix of | |
60 // |kURLTextColor|, the current text color, and the background color (the | |
61 // select highlight). It is more important to contrast with the background | |
62 // saturation than to look exactly like the foreground color. | |
63 SkColor SelectedURLColor(SkColor foreground, SkColor background) { | |
64 color_utils::HSL fg_hsl, bg_hsl, hue_hsl; | |
65 color_utils::SkColorToHSL(foreground, &fg_hsl); | |
66 color_utils::SkColorToHSL(background, &bg_hsl); | |
67 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); | |
68 | |
69 // The saturation of the text should be opposite of the background, clamped | |
70 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but | |
71 // less than 0.8 so it's not the oversaturated neon-color. | |
72 double opposite_s = 1 - bg_hsl.s; | |
73 double s = std::max(0.2, std::min(0.8, opposite_s)); | |
74 | |
75 // The luminance should match the luminance of the foreground text. Again, | |
76 // we clamp so as to have at some amount of color (green) in the text. | |
77 double opposite_l = fg_hsl.l; | |
78 double l = std::max(0.1, std::min(0.9, opposite_l)); | |
79 | |
80 color_utils::HSL output = { hue_hsl.h, s, l }; | |
81 return color_utils::HSLToSkColor(output, 255); | |
82 } | |
83 | |
84 enum WidgetState { | |
85 NORMAL = 0, | |
86 ACTIVE = 1, | |
87 PRELIGHT = 2, | |
88 SELECTED = 3, | |
89 INSENSITIVE = 4, | |
90 }; | |
91 | |
92 #if GTK_MAJOR_VERSION == 2 | |
93 // Same order as enum WidgetState above | |
94 const GtkStateType stateMap[] = { | |
95 GTK_STATE_NORMAL, | |
96 GTK_STATE_ACTIVE, | |
97 GTK_STATE_PRELIGHT, | |
98 GTK_STATE_SELECTED, | |
99 GTK_STATE_INSENSITIVE, | |
100 }; | |
101 | |
102 SkColor GetFGColor(GtkWidget* widget, WidgetState state) { | |
103 return GdkColorToSkColor(gtk_rc_get_style(widget)->fg[stateMap[state]]); | |
104 } | |
105 SkColor GetBGColor(GtkWidget* widget, WidgetState state) { | |
106 return GdkColorToSkColor(gtk_rc_get_style(widget)->bg[stateMap[state]]); | |
107 } | |
108 | |
109 SkColor GetTextColor(GtkWidget* widget, WidgetState state) { | |
110 return GdkColorToSkColor(gtk_rc_get_style(widget)->text[stateMap[state]]); | |
111 } | |
112 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { | |
113 return GdkColorToSkColor(gtk_rc_get_style(widget)->text_aa[stateMap[state]]); | |
114 } | |
115 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { | |
116 return GdkColorToSkColor(gtk_rc_get_style(widget)->base[stateMap[state]]); | |
117 } | |
118 | |
119 #else | |
120 // Same order as enum WidgetState above | |
121 const GtkStateFlags stateMap[] = { | |
122 GTK_STATE_FLAG_NORMAL, | |
123 GTK_STATE_FLAG_ACTIVE, | |
124 GTK_STATE_FLAG_PRELIGHT, | |
125 GTK_STATE_FLAG_SELECTED, | |
126 GTK_STATE_FLAG_INSENSITIVE, | |
127 }; | |
128 | |
129 SkColor GetFGColor(GtkWidget* widget, WidgetState state) { | |
130 GdkRGBA color; | |
131 gtk_style_context_get_color( | |
132 gtk_widget_get_style_context(widget), stateMap[state], &color); | |
133 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
134 } | |
135 SkColor GetBGColor(GtkWidget* widget, WidgetState state) { | |
136 GdkRGBA color; | |
137 | |
138 G_GNUC_BEGIN_IGNORE_DEPRECATIONS | |
139 gtk_style_context_get_background_color( | |
140 gtk_widget_get_style_context(widget), stateMap[state], &color); | |
141 G_GNUC_END_IGNORE_DEPRECATIONS | |
142 | |
143 // Hack for default color | |
144 if (color.alpha == 0.0) | |
145 color = {1, 1, 1, 1}; | |
146 | |
147 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
148 } | |
149 | |
150 SkColor GetTextColor(GtkWidget* widget, WidgetState state) { | |
151 return GetFGColor(widget, state); | |
152 } | |
153 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { | |
154 return GetFGColor(widget, state); | |
155 } | |
156 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { | |
157 return GetBGColor(widget, state); | |
158 } | |
159 | |
160 #endif | |
161 | |
162 } // namespace | |
163 | |
164 // static | |
165 NativeThemeGtk2* NativeThemeGtk2::instance() { | |
166 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); | |
167 return &s_native_theme; | |
168 } | |
169 | |
170 // Constructors automatically called | |
171 NativeThemeGtk2::NativeThemeGtk2() {} | |
172 // This doesn't actually get called | |
173 NativeThemeGtk2::~NativeThemeGtk2() {} | |
174 | |
175 void NativeThemeGtk2::PaintMenuPopupBackground( | |
176 SkCanvas* canvas, | |
177 const gfx::Size& size, | |
178 const MenuBackgroundExtraParams& menu_background) const { | |
179 if (menu_background.corner_radius > 0) { | |
180 SkPaint paint; | |
181 paint.setStyle(SkPaint::kFill_Style); | |
182 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
183 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); | |
184 | |
185 gfx::Path path; | |
186 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), | |
187 SkIntToScalar(size.height())); | |
188 SkScalar radius = SkIntToScalar(menu_background.corner_radius); | |
189 SkScalar radii[8] = {radius, radius, radius, radius, | |
190 radius, radius, radius, radius}; | |
191 path.addRoundRect(rect, radii); | |
192 | |
193 canvas->drawPath(path, paint); | |
194 } else { | |
195 canvas->drawColor(GetSystemColor(kColorId_MenuBackgroundColor), | |
196 SkBlendMode::kSrc); | |
197 } | |
198 } | |
199 | |
200 void NativeThemeGtk2::PaintMenuItemBackground( | |
201 SkCanvas* canvas, | |
202 State state, | |
203 const gfx::Rect& rect, | |
204 const MenuItemExtraParams& menu_item) const { | |
205 SkColor color; | |
206 SkPaint paint; | |
207 switch (state) { | |
208 case NativeTheme::kNormal: | |
209 case NativeTheme::kDisabled: | |
210 color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); | |
211 paint.setColor(color); | |
212 break; | |
213 case NativeTheme::kHovered: | |
214 color = GetSystemColor( | |
215 NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | |
216 paint.setColor(color); | |
217 break; | |
218 default: | |
219 NOTREACHED() << "Invalid state " << state; | |
220 break; | |
221 } | |
222 if (menu_item.corner_radius > 0) { | |
223 const SkScalar radius = SkIntToScalar(menu_item.corner_radius); | |
224 canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint); | |
225 return; | |
226 } | |
227 canvas->drawRect(gfx::RectToSkRect(rect), paint); | |
228 } | |
229 | |
230 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { | |
231 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | |
232 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); | |
233 | |
234 switch (color_id) { | |
235 // Windows | |
236 case kColorId_WindowBackground: | |
237 return GetBGColor(GetWindow(), SELECTED); | |
238 | |
239 // Dialogs | |
240 case kColorId_DialogBackground: | |
241 case kColorId_BubbleBackground: | |
242 return GetBGColor(GetWindow(), NORMAL); | |
243 | |
244 // FocusableBorder | |
245 case kColorId_FocusedBorderColor: | |
246 return GetBGColor(GetEntry(), SELECTED); | |
247 case kColorId_UnfocusedBorderColor: | |
248 return GetTextAAColor(GetEntry(), NORMAL); | |
249 | |
250 // MenuItem | |
251 case kColorId_SelectedMenuItemForegroundColor: | |
252 return GetTextColor(GetMenuItem(), SELECTED); | |
253 case kColorId_FocusedMenuItemBackgroundColor: | |
254 return GetBGColor(GetMenuItem(), SELECTED); | |
255 | |
256 case kColorId_EnabledMenuItemForegroundColor: | |
257 return GetTextColor(GetMenuItem(), NORMAL); | |
258 case kColorId_DisabledMenuItemForegroundColor: | |
259 return GetTextColor(GetMenuItem(), INSENSITIVE); | |
260 case kColorId_FocusedMenuButtonBorderColor: | |
261 return GetBGColor(GetEntry(), NORMAL); | |
262 case kColorId_HoverMenuButtonBorderColor: | |
263 return GetTextAAColor(GetEntry(), PRELIGHT); | |
264 case kColorId_MenuBorderColor: | |
265 case kColorId_EnabledMenuButtonBorderColor: | |
266 case kColorId_MenuSeparatorColor: { | |
267 return GetTextColor(GetMenuItem(), INSENSITIVE); | |
268 } | |
269 case kColorId_MenuBackgroundColor: | |
270 return GetBGColor(GetMenu(), NORMAL); | |
271 | |
272 // Label | |
273 case kColorId_LabelEnabledColor: | |
274 return GetTextColor(GetEntry(), NORMAL); | |
275 case kColorId_LabelDisabledColor: | |
276 return GetTextColor(GetLabel(), INSENSITIVE); | |
277 | |
278 // Link | |
279 case kColorId_LinkDisabled: | |
280 return SkColorSetA(GetSystemColor(kColorId_LinkEnabled), 0xBB); | |
281 case kColorId_LinkEnabled: { | |
282 SkColor link_color = SK_ColorTRANSPARENT; | |
283 GetChromeStyleColor("link-color", &link_color); | |
284 if (link_color != SK_ColorTRANSPARENT) | |
285 return link_color; | |
286 // Default color comes from gtklinkbutton.c. | |
287 return SkColorSetRGB(0x00, 0x00, 0xEE); | |
288 } | |
289 case kColorId_LinkPressed: | |
290 return SK_ColorRED; | |
291 | |
292 // Button | |
293 case kColorId_ButtonEnabledColor: | |
294 return GetTextColor(GetButton(), NORMAL); | |
295 case kColorId_BlueButtonEnabledColor: | |
296 return GetTextColor(GetBlueButton(), NORMAL); | |
297 case kColorId_ButtonDisabledColor: | |
298 return GetTextColor(GetButton(), INSENSITIVE); | |
299 case kColorId_BlueButtonDisabledColor: | |
300 return GetTextColor(GetBlueButton(), INSENSITIVE); | |
301 case kColorId_ButtonHoverColor: | |
302 return GetTextColor(GetButton(), PRELIGHT); | |
303 case kColorId_BlueButtonHoverColor: | |
304 return GetTextColor(GetBlueButton(), PRELIGHT); | |
305 case kColorId_BlueButtonPressedColor: | |
306 return GetTextColor(GetBlueButton(), ACTIVE); | |
307 case kColorId_BlueButtonShadowColor: | |
308 return SK_ColorTRANSPARENT; | |
309 case kColorId_ProminentButtonColor: | |
310 return GetSystemColor(kColorId_LinkEnabled); | |
311 case kColorId_TextOnProminentButtonColor: | |
312 return GetTextColor(GetLabel(), SELECTED); | |
313 case kColorId_ButtonPressedShade: | |
314 return SK_ColorTRANSPARENT; | |
315 | |
316 // Textfield | |
317 case kColorId_TextfieldDefaultColor: | |
318 return GetTextColor(GetEntry(), NORMAL); | |
319 case kColorId_TextfieldDefaultBackground: | |
320 return GetBaseColor(GetEntry(), NORMAL); | |
321 | |
322 #if GTK_MAJOR_VERSION == 2 | |
323 case kColorId_TextfieldReadOnlyColor: | |
324 return GetTextColor(GetEntry(), ACTIVE); | |
325 case kColorId_TextfieldReadOnlyBackground: | |
326 return GetBaseColor(GetEntry(), ACTIVE); | |
327 case kColorId_TextfieldSelectionColor: | |
328 return GetTextColor(GetEntry(), SELECTED); | |
329 case kColorId_TextfieldSelectionBackgroundFocused: | |
330 return GetBaseColor(GetEntry(), SELECTED); | |
331 #else | |
332 case kColorId_TextfieldReadOnlyColor: | |
333 return GetTextColor(GetEntry(), SELECTED); | |
334 case kColorId_TextfieldReadOnlyBackground: | |
335 return GetBaseColor(GetEntry(), SELECTED); | |
336 case kColorId_TextfieldSelectionColor: | |
337 return GetTextColor(GetLabel(), SELECTED); | |
338 case kColorId_TextfieldSelectionBackgroundFocused: | |
339 return GetBaseColor(GetLabel(), SELECTED); | |
340 #endif | |
341 | |
342 | |
343 // Tooltips | |
344 case kColorId_TooltipBackground: | |
345 return GetBGColor(GetTooltip(), NORMAL); | |
346 case kColorId_TooltipText: | |
347 return GetFGColor(GetTooltip(), NORMAL); | |
348 | |
349 // Trees and Tables (implemented on GTK using the same class) | |
350 case kColorId_TableBackground: | |
351 case kColorId_TreeBackground: | |
352 return GetBGColor(GetTree(), NORMAL); | |
353 case kColorId_TableText: | |
354 case kColorId_TreeText: | |
355 return GetTextColor(GetTree(), NORMAL); | |
356 case kColorId_TableSelectedText: | |
357 case kColorId_TableSelectedTextUnfocused: | |
358 case kColorId_TreeSelectedText: | |
359 case kColorId_TreeSelectedTextUnfocused: | |
360 return GetTextColor(GetTree(), SELECTED); | |
361 case kColorId_TableSelectionBackgroundFocused: | |
362 case kColorId_TableSelectionBackgroundUnfocused: | |
363 case kColorId_TreeSelectionBackgroundFocused: | |
364 case kColorId_TreeSelectionBackgroundUnfocused: | |
365 return GetBGColor(GetTree(), SELECTED); | |
366 case kColorId_TreeArrow: | |
367 return GetFGColor(GetTree(), NORMAL); | |
368 case kColorId_TableGroupingIndicatorColor: | |
369 return GetTextAAColor(GetTree(), NORMAL); | |
370 | |
371 // Results Table | |
372 case kColorId_ResultsTableNormalBackground: | |
373 return GetSystemColor(kColorId_TextfieldDefaultBackground); | |
374 case kColorId_ResultsTableHoveredBackground: | |
375 return color_utils::AlphaBlend( | |
376 GetSystemColor(kColorId_TextfieldDefaultBackground), | |
377 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), | |
378 0x80); | |
379 case kColorId_ResultsTableSelectedBackground: | |
380 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); | |
381 case kColorId_ResultsTableNormalText: | |
382 case kColorId_ResultsTableHoveredText: | |
383 return GetSystemColor(kColorId_TextfieldDefaultColor); | |
384 case kColorId_ResultsTableSelectedText: | |
385 return GetSystemColor(kColorId_TextfieldSelectionColor); | |
386 case kColorId_ResultsTableNormalDimmedText: | |
387 case kColorId_ResultsTableHoveredDimmedText: | |
388 return color_utils::AlphaBlend( | |
389 GetSystemColor(kColorId_TextfieldDefaultColor), | |
390 GetSystemColor(kColorId_TextfieldDefaultBackground), | |
391 0x80); | |
392 case kColorId_ResultsTableSelectedDimmedText: | |
393 return color_utils::AlphaBlend( | |
394 GetSystemColor(kColorId_TextfieldSelectionColor), | |
395 GetSystemColor(kColorId_TextfieldDefaultBackground), | |
396 0x80); | |
397 case kColorId_ResultsTableNormalUrl: | |
398 case kColorId_ResultsTableHoveredUrl: | |
399 return NormalURLColor(GetSystemColor(kColorId_TextfieldDefaultColor)); | |
400 | |
401 case kColorId_ResultsTableSelectedUrl: | |
402 return SelectedURLColor( | |
403 GetSystemColor(kColorId_TextfieldSelectionColor), | |
404 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused)); | |
405 | |
406 case kColorId_ResultsTablePositiveText: { | |
407 return color_utils::GetReadableColor(kPositiveTextColor, | |
408 GetBaseColor(GetEntry(), NORMAL)); | |
409 } | |
410 case kColorId_ResultsTablePositiveHoveredText: { | |
411 return color_utils::GetReadableColor(kPositiveTextColor, | |
412 GetBaseColor(GetEntry(), PRELIGHT)); | |
413 } | |
414 case kColorId_ResultsTablePositiveSelectedText: { | |
415 return color_utils::GetReadableColor(kPositiveTextColor, | |
416 GetBaseColor(GetEntry(), SELECTED)); | |
417 } | |
418 case kColorId_ResultsTableNegativeText: { | |
419 return color_utils::GetReadableColor(kNegativeTextColor, | |
420 GetBaseColor(GetEntry(), NORMAL)); | |
421 } | |
422 case kColorId_ResultsTableNegativeHoveredText: { | |
423 return color_utils::GetReadableColor(kNegativeTextColor, | |
424 GetBaseColor(GetEntry(), PRELIGHT)); | |
425 } | |
426 case kColorId_ResultsTableNegativeSelectedText: { | |
427 return color_utils::GetReadableColor(kNegativeTextColor, | |
428 GetBaseColor(GetEntry(), SELECTED)); | |
429 } | |
430 | |
431 // Throbber | |
432 case kColorId_ThrobberSpinningColor: | |
433 case kColorId_ThrobberLightColor: | |
434 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); | |
435 | |
436 case kColorId_ThrobberWaitingColor: | |
437 return color_utils::AlphaBlend( | |
438 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), | |
439 GetBGColor(GetWindow(), NORMAL), | |
440 0x80); | |
441 | |
442 // Alert icons | |
443 // Just fall back to the same colors as Aura. | |
444 case kColorId_AlertSeverityLow: | |
445 case kColorId_AlertSeverityMedium: | |
446 case kColorId_AlertSeverityHigh: { | |
447 ui::NativeTheme* fallback_theme = | |
448 color_utils::IsDark(GetTextColor(GetEntry(), NORMAL)) | |
449 ? ui::NativeThemeAura::instance() | |
450 : ui::NativeThemeDarkAura::instance(); | |
451 return fallback_theme->GetSystemColor(color_id); | |
452 } | |
453 | |
454 case kColorId_NumColors: | |
455 NOTREACHED(); | |
456 break; | |
457 } | |
458 | |
459 return kInvalidColorIdColor; | |
460 } | |
461 | |
462 // Get ChromeGtkFrame theme colors. No-op in GTK3. | |
463 bool NativeThemeGtk2::GetChromeStyleColor(const char* style_property, | |
464 SkColor* ret_color) const { | |
465 #if GTK_MAJOR_VERSION == 2 | |
466 GdkColor* style_color = nullptr; | |
467 gtk_widget_style_get(GetWindow(), style_property, &style_color, nullptr); | |
468 if (style_color) { | |
469 *ret_color = GdkColorToSkColor(*style_color); | |
470 gdk_color_free(style_color); | |
471 return true; | |
472 } | |
473 #endif | |
474 | |
475 return false; | |
476 } | |
477 | |
478 GtkWidget* NativeThemeGtk2::GetWindow() const { | |
479 static GtkWidget* fake_window = NULL; | |
480 | |
481 if (!fake_window) { | |
482 fake_window = chrome_gtk_frame_new(); | |
483 gtk_widget_realize(fake_window); | |
484 } | |
485 | |
486 return fake_window; | |
487 } | |
488 | |
489 GtkWidget* NativeThemeGtk2::GetEntry() const { | |
490 static GtkWidget* fake_entry = NULL; | |
491 | |
492 if (!fake_entry) { | |
493 fake_entry = gtk_entry_new(); | |
494 | |
495 // The fake entry needs to be in the window so it can be realized so we can | |
496 // use the computed parts of the style. | |
497 gtk_container_add(GTK_CONTAINER(GetWindow()), fake_entry); | |
498 gtk_widget_realize(fake_entry); | |
499 } | |
500 | |
501 return fake_entry; | |
502 } | |
503 | |
504 GtkWidget* NativeThemeGtk2::GetLabel() const { | |
505 static GtkWidget* fake_label = NULL; | |
506 | |
507 if (!fake_label) | |
508 fake_label = gtk_label_new(""); | |
509 | |
510 return fake_label; | |
511 } | |
512 | |
513 GtkWidget* NativeThemeGtk2::GetButton() const { | |
514 static GtkWidget* fake_button = NULL; | |
515 | |
516 if (!fake_button) | |
517 fake_button = gtk_button_new(); | |
518 | |
519 return fake_button; | |
520 } | |
521 | |
522 GtkWidget* NativeThemeGtk2::GetBlueButton() const { | |
523 static GtkWidget* fake_bluebutton = NULL; | |
524 | |
525 if (!fake_bluebutton) { | |
526 fake_bluebutton = gtk_button_new(); | |
527 TurnButtonBlue(fake_bluebutton); | |
528 } | |
529 | |
530 return fake_bluebutton; | |
531 } | |
532 | |
533 GtkWidget* NativeThemeGtk2::GetTree() const { | |
534 static GtkWidget* fake_tree = NULL; | |
535 | |
536 if (!fake_tree) | |
537 fake_tree = gtk_tree_view_new(); | |
538 | |
539 return fake_tree; | |
540 } | |
541 | |
542 GtkWidget* NativeThemeGtk2::GetTooltip() const { | |
543 static GtkWidget* fake_tooltip = NULL; | |
544 | |
545 if (!fake_tooltip) { | |
546 fake_tooltip = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
547 gtk_widget_set_name(fake_tooltip, "gtk-tooltip"); | |
548 gtk_widget_realize(fake_tooltip); | |
549 } | |
550 | |
551 return fake_tooltip; | |
552 } | |
553 | |
554 GtkWidget* NativeThemeGtk2::GetMenu() const { | |
555 static GtkWidget* fake_menu = NULL; | |
556 | |
557 if (!fake_menu) | |
558 fake_menu = gtk_custom_menu_new(); | |
559 | |
560 return fake_menu; | |
561 } | |
562 | |
563 GtkWidget* NativeThemeGtk2::GetMenuItem() const { | |
564 static GtkWidget* fake_menu_item = NULL; | |
565 | |
566 if (!fake_menu_item) { | |
567 fake_menu_item = gtk_custom_menu_item_new(); | |
568 gtk_menu_shell_append(GTK_MENU_SHELL(GetMenu()), fake_menu_item); | |
569 } | |
570 | |
571 return fake_menu_item; | |
572 } | |
573 | |
574 } // namespace libgtkui | |
OLD | NEW |