File: | ui/theme-viewer.c |
Warning: | line 903, column 5 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
2 | |
3 | /* Croma theme viewer and test app main() */ |
4 | |
5 | /* |
6 | * Copyright (C) 2002 Havoc Pennington |
7 | * |
8 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License as |
10 | * published by the Free Software Foundation; either version 2 of the |
11 | * License, or (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
21 | * 02110-1301, USA. |
22 | */ |
23 | |
24 | #include <config.h> |
25 | #include "util.h" |
26 | #include "theme.h" |
27 | #include "theme-parser.h" |
28 | #include "preview-widget.h" |
29 | #include <ctk/ctk.h> |
30 | #include <time.h> |
31 | #include <stdlib.h> |
32 | #include <string.h> |
33 | |
34 | #include <libintl.h> |
35 | #define _(x)dgettext ("croma", x) dgettext (GETTEXT_PACKAGE"croma", x) |
36 | #define N_(x)x x |
37 | |
38 | /* We need to compute all different button arrangements |
39 | * in terms of button location. We don't care about |
40 | * different arrangements in terms of button function. |
41 | * |
42 | * So if dups are allowed, from 0-4 buttons on the left, from 0-4 on |
43 | * the right, 5x5=25 combinations. |
44 | * |
45 | * If no dups, 0-4 on left determines the number on the right plus |
46 | * we have a special case for the "no buttons on either side" case. |
47 | */ |
48 | #ifndef ALLOW_DUPLICATE_BUTTONS |
49 | #define BUTTON_LAYOUT_COMBINATIONS(META_BUTTON_FUNCTION_LAST + 1 + 1) (MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST + 1 + 1) |
50 | #else |
51 | #define BUTTON_LAYOUT_COMBINATIONS(META_BUTTON_FUNCTION_LAST + 1 + 1) ((MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST+1)*(MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST+1)) |
52 | #endif |
53 | |
54 | enum |
55 | { |
56 | FONT_SIZE_SMALL, |
57 | FONT_SIZE_NORMAL, |
58 | FONT_SIZE_LARGE, |
59 | FONT_SIZE_LAST |
60 | }; |
61 | |
62 | static MetaTheme *global_theme = NULL((void*)0); |
63 | static CtkWidget *previews[META_FRAME_TYPE_LAST*FONT_SIZE_LAST + BUTTON_LAYOUT_COMBINATIONS(META_BUTTON_FUNCTION_LAST + 1 + 1)] = { NULL((void*)0), }; |
64 | static double milliseconds_to_draw_frame = 0.0; |
65 | |
66 | static void run_theme_benchmark (void); |
67 | |
68 | static const gchar *xml = |
69 | "<interface>" |
70 | "<menu id='menubar'>" |
71 | "<submenu>" |
72 | "<attribute name='label'>Windows</attribute>" |
73 | "<section>" |
74 | "<item>" |
75 | "<attribute name='label'>Dialog</attribute>" |
76 | "<attribute name='action'>theme-viewer.dialog1</attribute>" |
77 | "<attribute name='accel'><control>d</attribute>" |
78 | "</item>" |
79 | "<item>" |
80 | "<attribute name='label'>Modal dialog</attribute>" |
81 | "<attribute name='action'>theme-viewer.dialog2</attribute>" |
82 | "</item>" |
83 | "<item>" |
84 | "<attribute name='label'>Utility</attribute>" |
85 | "<attribute name='action'>theme-viewer.utility</attribute>" |
86 | "<attribute name='accel'><control>u</attribute>" |
87 | "</item>" |
88 | "<item>" |
89 | "<attribute name='label'>Splashscreen</attribute>" |
90 | "<attribute name='action'>theme-viewer.splashscreen</attribute>" |
91 | "<attribute name='accel'><control>s</attribute>" |
92 | "</item>" |
93 | "<item>" |
94 | "<attribute name='label'>Top dock</attribute>" |
95 | "<attribute name='action'>theme-viewer.top-dock</attribute>" |
96 | "</item>" |
97 | "<item>" |
98 | "<attribute name='label'>Bottom dock</attribute>" |
99 | "<attribute name='action'>theme-viewer.bottom-dock</attribute>" |
100 | "</item>" |
101 | "<item>" |
102 | "<attribute name='label'>Left dock</attribute>" |
103 | "<attribute name='action'>theme-viewer.left-dock</attribute>" |
104 | "</item>" |
105 | "<item>" |
106 | "<attribute name='label'>Right dock</attribute>" |
107 | "<attribute name='action'>theme-viewer.right-dock</attribute>" |
108 | "</item>" |
109 | "<item>" |
110 | "<attribute name='label'>All docks</attribute>" |
111 | "<attribute name='action'>theme-viewer.all-docks</attribute>" |
112 | "</item>" |
113 | "<item>" |
114 | "<attribute name='label'>Desktop</attribute>" |
115 | "<attribute name='action'>theme-viewer.desktop</attribute>" |
116 | "</item>" |
117 | "</section>" |
118 | "</submenu>" |
119 | "</menu>" |
120 | "</interface>"; |
121 | |
122 | static GActionEntry theme_viewer_entries[] = |
123 | { |
124 | /* menubar */ |
125 | { "dialog1", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
126 | { "dialog2", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
127 | { "utility", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
128 | { "splashscreen", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
129 | { "top-dock", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
130 | { "bottom-dock", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
131 | { "left-dock", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
132 | { "right-dock", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
133 | { "all-docks", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
134 | { "desktop", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
135 | /* toolbar */ |
136 | { "new", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
137 | { "open", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} }, |
138 | { "quit", NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), {} } |
139 | }; |
140 | |
141 | static CtkWidget * |
142 | create_toolbar (void) |
143 | { |
144 | CtkWidget *toolbar; |
145 | CtkToolItem *item; |
146 | |
147 | toolbar = ctk_toolbar_new (); |
148 | |
149 | item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-new", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL((void*)0)); |
150 | ctk_tool_item_set_tooltip_markup (item, "Open another one of these windows"); |
151 | ctk_actionable_set_action_name (CTK_ACTIONABLE (item)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_actionable_get_type ())))))), "theme-viewer.new"); |
152 | ctk_toolbar_insert (CTK_TOOLBAR (toolbar)((((CtkToolbar*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((toolbar)), ((ctk_toolbar_get_type ())))))), item, -1); |
153 | |
154 | item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-open", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL((void*)0)); |
155 | ctk_tool_item_set_tooltip_markup (item, "This is a demo button with an 'open' icon"); |
156 | ctk_actionable_set_action_name (CTK_ACTIONABLE (item)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_actionable_get_type ())))))), "theme-viewer.open"); |
157 | ctk_toolbar_insert (CTK_TOOLBAR (toolbar)((((CtkToolbar*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((toolbar)), ((ctk_toolbar_get_type ())))))), item, -1); |
158 | |
159 | item = ctk_tool_button_new (ctk_image_new_from_icon_name ("application-exit", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL((void*)0)); |
160 | ctk_tool_item_set_tooltip_markup (item, "This is a demo button with a 'quit' icon"); |
161 | ctk_actionable_set_action_name (CTK_ACTIONABLE (item)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_actionable_get_type ())))))), "theme-viewer.quit"); |
162 | ctk_toolbar_insert (CTK_TOOLBAR (toolbar)((((CtkToolbar*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((toolbar)), ((ctk_toolbar_get_type ())))))), item, -1); |
163 | |
164 | return toolbar; |
165 | } |
166 | |
167 | static CtkWidget * |
168 | normal_contents (void) |
169 | { |
170 | CtkWidget *grid; |
171 | CtkWidget *statusbar; |
172 | CtkWidget *contents; |
173 | CtkWidget *sw; |
174 | CtkBuilder *builder; |
175 | |
176 | grid = ctk_grid_new (); |
177 | builder = ctk_builder_new_from_string (xml, -1); |
178 | |
179 | /* create menu items */ |
180 | GMenuModel *model = G_MENU_MODEL (ctk_builder_get_object (builder, "menubar"))((((GMenuModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (builder, "menubar"))), ((g_menu_model_get_type ())))))); |
181 | CtkWidget *menubar = ctk_menu_bar_new_from_model (model); |
182 | ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), menubar, 0, 0, 1, 1); |
183 | ctk_widget_set_hexpand (menubar, TRUE(!(0))); |
184 | |
185 | /* Create the toolbar */ |
186 | CtkWidget *toolbar = create_toolbar (); |
187 | ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), toolbar, 0, 1, 1, 1); |
188 | ctk_widget_set_hexpand (toolbar, TRUE(!(0))); |
189 | |
190 | /* Create document |
191 | */ |
192 | |
193 | sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
194 | ctk_widget_set_hexpand (sw, TRUE(!(0))); |
195 | ctk_widget_set_vexpand (sw, TRUE(!(0))); |
196 | |
197 | ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
198 | CTK_POLICY_AUTOMATIC, |
199 | CTK_POLICY_AUTOMATIC); |
200 | |
201 | ctk_scrolled_window_set_shadow_type (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
202 | CTK_SHADOW_IN); |
203 | |
204 | ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), |
205 | sw, |
206 | 0, 2, 1, 1); |
207 | |
208 | contents = ctk_text_view_new (); |
209 | ctk_text_view_set_wrap_mode (CTK_TEXT_VIEW (contents)((((CtkTextView*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((contents)), ((ctk_text_view_get_type ())))))), |
210 | PANGO_WRAP_WORD); |
211 | |
212 | ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sw)), ((ctk_container_get_type ())))))), |
213 | contents); |
214 | |
215 | /* Create statusbar */ |
216 | |
217 | statusbar = ctk_statusbar_new (); |
218 | ctk_widget_set_hexpand (statusbar, TRUE(!(0))); |
219 | ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), |
220 | statusbar, |
221 | 0, 3, 1, 1); |
222 | |
223 | ctk_widget_show_all (grid); |
224 | |
225 | g_object_unref (builder); |
226 | |
227 | return grid; |
228 | } |
229 | |
230 | static void |
231 | update_spacings (CtkWidget *vbox, |
232 | CtkWidget *action_area) |
233 | { |
234 | ctk_container_set_border_width (CTK_CONTAINER (vbox)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_container_get_type ())))))), 2); |
235 | ctk_box_set_spacing (CTK_BOX (action_area)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_area)), ((ctk_box_get_type ())))))), 10); |
236 | ctk_container_set_border_width (CTK_CONTAINER (action_area)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_area)), ((ctk_container_get_type ())))))), 5); |
237 | } |
238 | |
239 | static CtkWidget* |
240 | dialog_contents (void) |
241 | { |
242 | CtkWidget *vbox; |
243 | CtkWidget *hbox; |
244 | CtkWidget *action_area; |
245 | CtkWidget *label; |
246 | CtkWidget *image; |
247 | CtkWidget *button; |
248 | |
249 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
250 | |
251 | action_area = ctk_button_box_new (CTK_ORIENTATION_HORIZONTAL); |
252 | |
253 | ctk_button_box_set_layout (CTK_BUTTON_BOX (action_area)((((CtkButtonBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_area)), ((ctk_button_box_get_type ())))))), |
254 | CTK_BUTTONBOX_END); |
255 | |
256 | button = ctk_button_new_with_mnemonic (_("_OK")dgettext ("croma", "_OK")); |
257 | ctk_button_set_image (CTK_BUTTON (button)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((ctk_button_get_type ())))))), ctk_image_new_from_icon_name ("ctk-ok", CTK_ICON_SIZE_BUTTON)); |
258 | |
259 | ctk_box_pack_end (CTK_BOX (action_area)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_area)), ((ctk_box_get_type ())))))), |
260 | button, |
261 | FALSE(0), TRUE(!(0)), 0); |
262 | |
263 | ctk_box_pack_end (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), action_area, |
264 | FALSE(0), TRUE(!(0)), 0); |
265 | |
266 | update_spacings (vbox, action_area); |
267 | |
268 | label = ctk_label_new (_("This is a sample message in a sample dialog")dgettext ("croma", "This is a sample message in a sample dialog" )); |
269 | image = ctk_image_new_from_icon_name ("dialog-information", |
270 | CTK_ICON_SIZE_DIALOG); |
271 | ctk_widget_set_halign (image, CTK_ALIGN_CENTER); |
272 | ctk_widget_set_valign (image, CTK_ALIGN_START); |
273 | |
274 | ctk_label_set_line_wrap (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((ctk_label_get_type ())))))), TRUE(!(0))); |
275 | ctk_label_set_selectable (CTK_LABEL (label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((label)), ((ctk_label_get_type ())))))), TRUE(!(0))); |
276 | |
277 | hbox = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 6); |
278 | |
279 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), image, |
280 | FALSE(0), FALSE(0), 0); |
281 | |
282 | ctk_box_pack_start (CTK_BOX (hbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((hbox)), ((ctk_box_get_type ())))))), label, |
283 | TRUE(!(0)), TRUE(!(0)), 0); |
284 | |
285 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), |
286 | hbox, |
287 | FALSE(0), FALSE(0), 0); |
288 | |
289 | ctk_widget_show_all (vbox); |
290 | |
291 | return vbox; |
292 | } |
293 | |
294 | static CtkWidget* |
295 | utility_contents (void) |
296 | { |
297 | CtkWidget *grid; |
298 | CtkWidget *button; |
299 | int i; |
300 | |
301 | grid = ctk_grid_new (); |
302 | |
303 | i = 0; |
304 | while (i < 3) |
305 | { |
306 | int j; |
307 | |
308 | j = 0; |
309 | while (j < 4) |
310 | { |
311 | char *str; |
312 | |
313 | str = g_strdup_printf ("_%c", (char) ('A' + 4*i + j)); |
314 | |
315 | button = ctk_button_new_with_mnemonic (str); |
316 | |
317 | g_free (str); |
318 | |
319 | ctk_widget_set_hexpand (button, TRUE(!(0))); |
320 | ctk_widget_set_vexpand (button, TRUE(!(0))); |
321 | |
322 | ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((grid)), ((ctk_grid_get_type ())))))), |
323 | button, |
324 | i, j, 1, 1); |
325 | |
326 | ++j; |
327 | } |
328 | |
329 | ++i; |
330 | } |
331 | |
332 | ctk_widget_show_all (grid); |
333 | |
334 | return grid; |
335 | } |
336 | |
337 | static CtkWidget* |
338 | menu_contents (void) |
339 | { |
340 | CtkWidget *vbox; |
341 | int i; |
342 | CtkWidget *frame; |
343 | |
344 | frame = ctk_frame_new (NULL((void*)0)); |
345 | ctk_frame_set_shadow_type (CTK_FRAME (frame)((((CtkFrame*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_frame_get_type ())))))), |
346 | CTK_SHADOW_OUT); |
347 | |
348 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
349 | |
350 | i = 0; |
351 | while (i < 10) |
352 | { |
353 | CtkWidget *mi; |
354 | |
355 | char *str = g_strdup_printf (_("Fake menu item %d\n")dgettext ("croma", "Fake menu item %d\n"), i + 1); |
356 | mi = ctk_label_new (str); |
357 | ctk_widget_set_halign (mi, CTK_ALIGN_START); |
358 | ctk_widget_set_valign (mi, CTK_ALIGN_CENTER); |
359 | g_free (str); |
360 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), mi, FALSE(0), FALSE(0), 0); |
361 | |
362 | ++i; |
363 | } |
364 | |
365 | ctk_container_add (CTK_CONTAINER (frame)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((frame)), ((ctk_container_get_type ())))))), vbox); |
366 | |
367 | ctk_widget_show_all (frame); |
368 | |
369 | return frame; |
370 | } |
371 | |
372 | static void |
373 | override_background_color (CtkWidget *widget, |
374 | CdkRGBA *rgba) |
375 | { |
376 | gchar *css; |
377 | CtkCssProvider *provider; |
378 | |
379 | provider = ctk_css_provider_new (); |
380 | |
381 | css = g_strdup_printf ("* { background-color: %s; }", |
382 | cdk_rgba_to_string (rgba)); |
383 | ctk_css_provider_load_from_data (provider, css, -1, NULL((void*)0)); |
384 | g_free (css); |
385 | |
386 | ctk_style_context_add_provider (ctk_widget_get_style_context (widget), |
387 | CTK_STYLE_PROVIDER (provider)((((CtkStyleProvider*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((provider)), ((ctk_style_provider_get_type ( ))))))), |
388 | CTK_STYLE_PROVIDER_PRIORITY_APPLICATION600); |
389 | g_object_unref (provider); |
390 | } |
391 | |
392 | static CtkWidget* |
393 | border_only_contents (void) |
394 | { |
395 | CtkWidget *event_box; |
396 | CtkWidget *vbox; |
397 | CtkWidget *w; |
398 | CdkRGBA color; |
399 | |
400 | event_box = ctk_event_box_new (); |
401 | |
402 | color.red = 0.6; |
403 | color.green = 0; |
404 | color.blue = 0.6; |
405 | color.alpha = 1.0; |
406 | override_background_color (event_box, &color); |
407 | |
408 | vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
409 | ctk_container_set_border_width (CTK_CONTAINER (vbox)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_container_get_type ())))))), 3); |
410 | |
411 | w = ctk_label_new (_("Border-only window")dgettext ("croma", "Border-only window")); |
412 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), w, FALSE(0), FALSE(0), 0); |
413 | w = ctk_button_new_with_label (_("Bar")dgettext ("croma", "Bar")); |
414 | ctk_box_pack_start (CTK_BOX (vbox)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((vbox)), ((ctk_box_get_type ())))))), w, FALSE(0), FALSE(0), 0); |
415 | |
416 | ctk_container_add (CTK_CONTAINER (event_box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((event_box)), ((ctk_container_get_type ())))))), vbox); |
417 | |
418 | ctk_widget_show_all (event_box); |
419 | |
420 | return event_box; |
421 | } |
422 | |
423 | static CtkWidget* |
424 | get_window_contents (MetaFrameType type, |
425 | const char **title) |
426 | { |
427 | switch (type) |
428 | { |
429 | case META_FRAME_TYPE_NORMAL: |
430 | *title = _("Normal Application Window")dgettext ("croma", "Normal Application Window"); |
431 | return normal_contents (); |
432 | |
433 | case META_FRAME_TYPE_DIALOG: |
434 | *title = _("Dialog Box")dgettext ("croma", "Dialog Box"); |
435 | return dialog_contents (); |
436 | |
437 | case META_FRAME_TYPE_MODAL_DIALOG: |
438 | *title = _("Modal Dialog Box")dgettext ("croma", "Modal Dialog Box"); |
439 | return dialog_contents (); |
440 | |
441 | case META_FRAME_TYPE_UTILITY: |
442 | *title = _("Utility Palette")dgettext ("croma", "Utility Palette"); |
443 | return utility_contents (); |
444 | |
445 | case META_FRAME_TYPE_MENU: |
446 | *title = _("Torn-off Menu")dgettext ("croma", "Torn-off Menu"); |
447 | return menu_contents (); |
448 | |
449 | case META_FRAME_TYPE_BORDER: |
450 | *title = _("Border")dgettext ("croma", "Border"); |
451 | return border_only_contents (); |
452 | |
453 | case META_FRAME_TYPE_ATTACHED: |
454 | *title = _("Attached Modal Dialog")dgettext ("croma", "Attached Modal Dialog"); |
455 | return dialog_contents (); |
456 | |
457 | case META_FRAME_TYPE_LAST: |
458 | g_assert_not_reached ()do { g_assertion_message_expr ("croma", "ui/theme-viewer.c", 458 , ((const char*) (__func__)), ((void*)0)); } while (0); |
459 | break; |
460 | } |
461 | |
462 | return NULL((void*)0); |
463 | } |
464 | |
465 | static MetaFrameFlags |
466 | get_window_flags (MetaFrameType type) |
467 | { |
468 | MetaFrameFlags flags; |
469 | |
470 | flags = META_FRAME_ALLOWS_DELETE | |
471 | META_FRAME_ALLOWS_MENU | |
472 | META_FRAME_ALLOWS_MINIMIZE | |
473 | META_FRAME_ALLOWS_MAXIMIZE | |
474 | META_FRAME_ALLOWS_VERTICAL_RESIZE | |
475 | META_FRAME_ALLOWS_HORIZONTAL_RESIZE | |
476 | META_FRAME_HAS_FOCUS | |
477 | META_FRAME_ALLOWS_SHADE | |
478 | META_FRAME_ALLOWS_MOVE; |
479 | |
480 | switch (type) |
481 | { |
482 | case META_FRAME_TYPE_NORMAL: |
483 | break; |
484 | |
485 | case META_FRAME_TYPE_DIALOG: |
486 | case META_FRAME_TYPE_MODAL_DIALOG: |
487 | flags &= ~(META_FRAME_ALLOWS_MINIMIZE | |
488 | META_FRAME_ALLOWS_MAXIMIZE); |
489 | break; |
490 | |
491 | case META_FRAME_TYPE_UTILITY: |
492 | flags &= ~(META_FRAME_ALLOWS_MINIMIZE | |
493 | META_FRAME_ALLOWS_MAXIMIZE); |
494 | break; |
495 | |
496 | case META_FRAME_TYPE_MENU: |
497 | flags &= ~(META_FRAME_ALLOWS_MINIMIZE | |
498 | META_FRAME_ALLOWS_MAXIMIZE); |
499 | break; |
500 | |
501 | case META_FRAME_TYPE_BORDER: |
502 | break; |
503 | |
504 | case META_FRAME_TYPE_ATTACHED: |
505 | break; |
506 | |
507 | case META_FRAME_TYPE_LAST: |
508 | g_assert_not_reached ()do { g_assertion_message_expr ("croma", "ui/theme-viewer.c", 508 , ((const char*) (__func__)), ((void*)0)); } while (0); |
509 | break; |
510 | } |
511 | |
512 | return flags; |
513 | } |
514 | |
515 | static void |
516 | override_font (CtkWidget *widget, |
517 | const gchar *font) |
518 | { |
519 | gchar *css; |
520 | CtkCssProvider *provider; |
521 | |
522 | provider = ctk_css_provider_new (); |
523 | |
524 | css = g_strdup_printf ("* { font: %s; }", font); |
525 | ctk_css_provider_load_from_data (provider, css, -1, NULL((void*)0)); |
526 | g_free (css); |
527 | |
528 | ctk_style_context_add_provider (ctk_widget_get_style_context (widget), |
529 | CTK_STYLE_PROVIDER (provider)((((CtkStyleProvider*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((provider)), ((ctk_style_provider_get_type ( ))))))), |
530 | CTK_STYLE_PROVIDER_PRIORITY_APPLICATION600); |
531 | g_object_unref (provider); |
532 | } |
533 | |
534 | static CtkWidget* |
535 | preview_collection (int font_size, |
536 | const PangoFontDescription *base_desc) |
537 | { |
538 | CtkWidget *box; |
539 | CtkWidget *sw; |
540 | CdkRGBA desktop_color; |
541 | int i; |
542 | CtkWidget *eventbox; |
543 | |
544 | sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
545 | ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
546 | CTK_POLICY_AUTOMATIC, |
547 | CTK_POLICY_AUTOMATIC); |
548 | |
549 | box = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
550 | ctk_box_set_spacing (CTK_BOX (box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_box_get_type ())))))), 20); |
551 | ctk_container_set_border_width (CTK_CONTAINER (box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_container_get_type ())))))), 20); |
552 | |
553 | eventbox = ctk_event_box_new (); |
554 | ctk_container_add (CTK_CONTAINER (eventbox)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((eventbox)), ((ctk_container_get_type ())))))), box); |
555 | |
556 | ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sw)), ((ctk_container_get_type ())))))), eventbox); |
557 | |
558 | GSimpleActionGroup *action_group = g_simple_action_group_new (); |
559 | g_action_map_add_action_entries (G_ACTION_MAP (action_group)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_group)), ((g_action_map_get_type ())))))), |
560 | theme_viewer_entries, |
561 | G_N_ELEMENTS (theme_viewer_entries)(sizeof (theme_viewer_entries) / sizeof ((theme_viewer_entries )[0])), |
562 | NULL((void*)0)); |
563 | ctk_widget_insert_action_group (sw, "theme-viewer", G_ACTION_GROUP (action_group)((((GActionGroup*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((action_group)), ((g_action_group_get_type ()))))))); |
564 | g_object_unref (action_group); |
565 | |
566 | desktop_color.red = 0.32; |
567 | desktop_color.green = 0.46; |
568 | desktop_color.blue = 0.65; |
569 | desktop_color.alpha = 1.0; |
570 | |
571 | override_background_color (eventbox, &desktop_color); |
572 | |
573 | i = 0; |
574 | while (i < META_FRAME_TYPE_LAST) |
575 | { |
576 | const char *title = NULL((void*)0); |
577 | CtkWidget *contents; |
578 | CtkAlign xalign, yalign; |
579 | CtkWidget *eventbox2; |
580 | CtkWidget *preview; |
581 | double scale; |
582 | |
583 | eventbox2 = ctk_event_box_new (); |
584 | |
585 | preview = meta_preview_new (); |
586 | |
587 | ctk_container_add (CTK_CONTAINER (eventbox2)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((eventbox2)), ((ctk_container_get_type ())))))), preview); |
588 | |
589 | meta_preview_set_frame_type (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), i); |
590 | meta_preview_set_frame_flags (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), |
591 | get_window_flags (i)); |
592 | |
593 | meta_preview_set_theme (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), global_theme); |
594 | |
595 | contents = get_window_contents (i, &title); |
596 | |
597 | meta_preview_set_title (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), title); |
598 | |
599 | ctk_container_add (CTK_CONTAINER (preview)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((ctk_container_get_type ())))))), contents); |
600 | |
601 | if (i == META_FRAME_TYPE_MENU) |
602 | { |
603 | xalign = CTK_ALIGN_START; |
604 | yalign = CTK_ALIGN_START; |
605 | } |
606 | else |
607 | { |
608 | xalign = CTK_ALIGN_FILL; |
609 | yalign = CTK_ALIGN_FILL; |
610 | } |
611 | |
612 | ctk_widget_set_halign (eventbox2, xalign); |
613 | ctk_widget_set_valign (eventbox2, yalign); |
614 | |
615 | ctk_box_pack_start (CTK_BOX (box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_box_get_type ())))))), eventbox2, TRUE(!(0)), TRUE(!(0)), 0); |
616 | |
617 | switch (font_size) |
618 | { |
619 | case FONT_SIZE_SMALL: |
620 | scale = PANGO_SCALE_XX_SMALL((double)0.5787037037037); |
621 | break; |
622 | case FONT_SIZE_LARGE: |
623 | scale = PANGO_SCALE_XX_LARGE((double)1.728); |
624 | break; |
625 | default: |
626 | scale = 1.0; |
627 | break; |
628 | } |
629 | |
630 | if (scale != 1.0) |
631 | { |
632 | PangoFontDescription *font_desc; |
633 | gchar *font_string; |
634 | |
635 | font_desc = pango_font_description_new (); |
636 | |
637 | pango_font_description_set_size (font_desc, |
638 | MAX (pango_font_description_get_size (base_desc) * scale, 1)(((pango_font_description_get_size (base_desc) * scale) > ( 1)) ? (pango_font_description_get_size (base_desc) * scale) : (1))); |
639 | |
640 | font_string = pango_font_description_to_string (font_desc); |
641 | override_font (preview, font_string); |
642 | g_free (font_string); |
643 | |
644 | pango_font_description_free (font_desc); |
645 | } |
646 | |
647 | previews[font_size*META_FRAME_TYPE_LAST + i] = preview; |
648 | |
649 | ++i; |
650 | } |
651 | |
652 | return sw; |
653 | } |
654 | |
655 | static MetaButtonLayout different_layouts[BUTTON_LAYOUT_COMBINATIONS(META_BUTTON_FUNCTION_LAST + 1 + 1)]; |
656 | |
657 | static void |
658 | init_layouts (void) |
659 | { |
660 | int i; |
661 | |
662 | /* Blank out all the layouts */ |
663 | i = 0; |
664 | while (i < (int) G_N_ELEMENTS (different_layouts)(sizeof (different_layouts) / sizeof ((different_layouts)[0]) )) |
665 | { |
666 | int j; |
667 | |
668 | j = 0; |
669 | while (j < MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
670 | { |
671 | different_layouts[i].left_buttons[j] = META_BUTTON_FUNCTION_LAST; |
672 | different_layouts[i].right_buttons[j] = META_BUTTON_FUNCTION_LAST; |
673 | ++j; |
674 | } |
675 | ++i; |
676 | } |
677 | |
678 | #ifndef ALLOW_DUPLICATE_BUTTONS |
679 | i = 0; |
680 | while (i <= MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
681 | { |
682 | int j; |
683 | |
684 | j = 0; |
685 | while (j < i) |
686 | { |
687 | different_layouts[i].right_buttons[j] = (MetaButtonFunction) j; |
688 | ++j; |
689 | } |
690 | while (j < MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
691 | { |
692 | different_layouts[i].left_buttons[j-i] = (MetaButtonFunction) j; |
693 | ++j; |
694 | } |
695 | |
696 | ++i; |
697 | } |
698 | |
699 | /* Special extra case for no buttons on either side */ |
700 | different_layouts[i].left_buttons[0] = META_BUTTON_FUNCTION_LAST; |
701 | different_layouts[i].right_buttons[0] = META_BUTTON_FUNCTION_LAST; |
702 | |
703 | #else |
704 | /* FIXME this code is if we allow duplicate buttons, |
705 | * which we currently do not |
706 | */ |
707 | int left; |
708 | int i; |
709 | |
710 | left = 0; |
711 | i = 0; |
712 | |
713 | while (left < MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
714 | { |
715 | int right; |
716 | |
717 | right = 0; |
718 | |
719 | while (right < MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
720 | { |
721 | int j; |
722 | |
723 | static const MetaButtonFunction left_functions[MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST] = { |
724 | META_BUTTON_FUNCTION_MENU, |
725 | META_BUTTON_FUNCTION_MINIMIZE, |
726 | META_BUTTON_FUNCTION_MAXIMIZE, |
727 | META_BUTTON_FUNCTION_CLOSE |
728 | }; |
729 | static const MetaButtonFunction right_functions[MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST] = { |
730 | META_BUTTON_FUNCTION_MINIMIZE, |
731 | META_BUTTON_FUNCTION_MAXIMIZE, |
732 | META_BUTTON_FUNCTION_CLOSE, |
733 | META_BUTTON_FUNCTION_MENU |
734 | }; |
735 | |
736 | g_assert (i < BUTTON_LAYOUT_COMBINATIONS)do { if (i < (META_BUTTON_FUNCTION_LAST + 1 + 1)) ; else g_assertion_message_expr ("croma", "ui/theme-viewer.c", 736, ((const char*) (__func__ )), "i < BUTTON_LAYOUT_COMBINATIONS"); } while (0); |
737 | |
738 | j = 0; |
739 | while (j <= left) |
740 | { |
741 | different_layouts[i].left_buttons[j] = left_functions[j]; |
742 | ++j; |
743 | } |
744 | |
745 | j = 0; |
746 | while (j <= right) |
747 | { |
748 | different_layouts[i].right_buttons[j] = right_functions[j]; |
749 | ++j; |
750 | } |
751 | |
752 | ++i; |
753 | |
754 | ++right; |
755 | } |
756 | |
757 | ++left; |
758 | } |
759 | #endif |
760 | } |
761 | |
762 | |
763 | static CtkWidget* |
764 | previews_of_button_layouts (void) |
765 | { |
766 | static gboolean initted = FALSE(0); |
767 | CtkWidget *box; |
768 | CtkWidget *sw; |
769 | CdkRGBA desktop_color; |
770 | int i; |
771 | CtkWidget *eventbox; |
772 | |
773 | if (!initted) |
774 | { |
775 | init_layouts (); |
776 | initted = TRUE(!(0)); |
777 | } |
778 | |
779 | sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0)); |
780 | ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (sw)((((CtkScrolledWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((sw)), ((ctk_scrolled_window_get_type ()))) ))), |
781 | CTK_POLICY_AUTOMATIC, |
782 | CTK_POLICY_AUTOMATIC); |
783 | |
784 | box = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0); |
785 | ctk_box_set_spacing (CTK_BOX (box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_box_get_type ())))))), 20); |
786 | ctk_container_set_border_width (CTK_CONTAINER (box)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_container_get_type ())))))), 20); |
787 | |
788 | eventbox = ctk_event_box_new (); |
789 | ctk_container_add (CTK_CONTAINER (eventbox)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((eventbox)), ((ctk_container_get_type ())))))), box); |
790 | |
791 | ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sw)), ((ctk_container_get_type ())))))), eventbox); |
792 | |
793 | desktop_color.red = 0.32; |
794 | desktop_color.green = 0.46; |
795 | desktop_color.blue = 0.65; |
796 | desktop_color.alpha = 1.0; |
797 | |
798 | override_background_color (eventbox, &desktop_color); |
799 | |
800 | i = 0; |
801 | while (i < BUTTON_LAYOUT_COMBINATIONS(META_BUTTON_FUNCTION_LAST + 1 + 1)) |
802 | { |
803 | CtkWidget *eventbox2; |
804 | CtkWidget *preview; |
805 | char *title; |
806 | |
807 | eventbox2 = ctk_event_box_new (); |
808 | |
809 | preview = meta_preview_new (); |
810 | |
811 | ctk_container_add (CTK_CONTAINER (eventbox2)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((eventbox2)), ((ctk_container_get_type ())))))), preview); |
812 | |
813 | meta_preview_set_theme (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), global_theme); |
814 | |
815 | title = g_strdup_printf (_("Button layout test %d")dgettext ("croma", "Button layout test %d"), i+1); |
816 | meta_preview_set_title (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), title); |
817 | g_free (title); |
818 | |
819 | meta_preview_set_button_layout (META_PREVIEW (preview)((((MetaPreview*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((preview)), ((meta_preview_get_type ())))))), |
820 | &different_layouts[i]); |
821 | |
822 | ctk_widget_set_halign (eventbox2, CTK_ALIGN_FILL); |
823 | |
824 | ctk_box_pack_start (CTK_BOX (box)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((box)), ((ctk_box_get_type ())))))), eventbox2, TRUE(!(0)), TRUE(!(0)), 0); |
825 | |
826 | previews[META_FRAME_TYPE_LAST*FONT_SIZE_LAST + i] = preview; |
827 | |
828 | ++i; |
829 | } |
830 | |
831 | return sw; |
832 | } |
833 | |
834 | static CtkWidget* |
835 | benchmark_summary (void) |
836 | { |
837 | char *msg; |
838 | CtkWidget *label; |
839 | |
840 | msg = g_strdup_printf (_("%g milliseconds to draw one window frame")dgettext ("croma", "%g milliseconds to draw one window frame" ), |
841 | milliseconds_to_draw_frame); |
842 | label = ctk_label_new (msg); |
843 | g_free (msg); |
844 | |
845 | return label; |
846 | } |
847 | |
848 | int |
849 | main (int argc, char **argv) |
850 | { |
851 | CtkWidget *window; |
852 | CtkWidget *collection; |
853 | CtkStyleContext *style; |
854 | PangoFontDescription *font_desc; |
855 | GError *err; |
856 | clock_t start, end; |
857 | CtkWidget *notebook; |
858 | int i; |
859 | |
860 | bindtextdomain (GETTEXT_PACKAGE"croma", CROMA_LOCALEDIR"/usr/share/locale"); |
861 | textdomain(GETTEXT_PACKAGE"croma"); |
862 | bind_textdomain_codeset(GETTEXT_PACKAGE"croma", "UTF-8"); |
863 | |
864 | ctk_init (&argc, &argv); |
865 | |
866 | if (g_getenv ("CROMA_DEBUG") != NULL((void*)0)) |
867 | { |
868 | meta_set_debugging (TRUE(!(0))); |
869 | meta_set_verbose (TRUE(!(0))); |
870 | } |
871 | |
872 | start = clock (); |
873 | err = NULL((void*)0); |
874 | if (argc == 1) |
875 | global_theme = meta_theme_load ("ClearlooksRe_ctk", &err); |
876 | else if (argc == 2) |
877 | global_theme = meta_theme_load (argv[1], &err); |
878 | else |
879 | { |
880 | g_printerr (_("Usage: croma-theme-viewer [THEMENAME]\n")dgettext ("croma", "Usage: croma-theme-viewer [THEMENAME]\n")); |
881 | exit (1); |
882 | } |
883 | end = clock (); |
884 | |
885 | if (global_theme == NULL((void*)0)) |
886 | { |
887 | g_printerr (_("Error loading theme: %s\n")dgettext ("croma", "Error loading theme: %s\n"), |
888 | err->message); |
889 | g_error_free (err); |
890 | exit (1); |
891 | } |
892 | |
893 | g_print (_("Loaded theme \"%s\" in %g seconds\n")dgettext ("croma", "Loaded theme \"%s\" in %g seconds\n"), |
894 | global_theme->name, |
895 | (end - start) / (double) CLOCKS_PER_SEC((__clock_t) 1000000)); |
896 | |
897 | run_theme_benchmark (); |
898 | |
899 | window = ctk_window_new (CTK_WINDOW_TOPLEVEL); |
900 | ctk_window_set_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_window_get_type ())))))), 350, 350); |
901 | |
902 | if (strcmp (global_theme->name, global_theme->readable_name)==0) |
903 | ctk_window_set_title (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_window_get_type ())))))), |
This statement is never executed | |
904 | global_theme->readable_name); |
905 | else |
906 | { |
907 | /* The theme directory name is different from the name the theme |
908 | * gives itself within its file. Display both, directory name first. |
909 | */ |
910 | gchar *title = g_strconcat (global_theme->name, " - ", |
911 | global_theme->readable_name, |
912 | NULL((void*)0)); |
913 | |
914 | ctk_window_set_title (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_window_get_type ())))))), |
915 | title); |
916 | |
917 | g_free (title); |
918 | } |
919 | |
920 | g_signal_connect (G_OBJECT (window), "destroy",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), (((GType) ((20) << (2))) )))))), ("destroy"), (((GCallback) (ctk_main_quit))), (((void *)0)), ((void*)0), (GConnectFlags) 0) |
921 | G_CALLBACK (ctk_main_quit), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), (((GType) ((20) << (2))) )))))), ("destroy"), (((GCallback) (ctk_main_quit))), (((void *)0)), ((void*)0), (GConnectFlags) 0); |
922 | |
923 | ctk_widget_realize (window); |
924 | style = ctk_widget_get_style_context (window); |
925 | ctk_style_context_get (style, CTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL((void*)0)); |
926 | |
927 | g_assert (style)do { if (style) ; else g_assertion_message_expr ("croma", "ui/theme-viewer.c" , 927, ((const char*) (__func__)), "style"); } while (0); |
928 | g_assert (font_desc)do { if (font_desc) ; else g_assertion_message_expr ("croma", "ui/theme-viewer.c", 928, ((const char*) (__func__)), "font_desc" ); } while (0); |
929 | |
930 | notebook = ctk_notebook_new (); |
931 | ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), ((ctk_container_get_type ())))))), notebook); |
932 | |
933 | collection = preview_collection (FONT_SIZE_NORMAL, |
934 | font_desc); |
935 | ctk_notebook_append_page (CTK_NOTEBOOK (notebook)((((CtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((notebook)), ((ctk_notebook_get_type ())))))), |
936 | collection, |
937 | ctk_label_new (_("Normal Title Font")dgettext ("croma", "Normal Title Font"))); |
938 | |
939 | collection = preview_collection (FONT_SIZE_SMALL, |
940 | font_desc); |
941 | ctk_notebook_append_page (CTK_NOTEBOOK (notebook)((((CtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((notebook)), ((ctk_notebook_get_type ())))))), |
942 | collection, |
943 | ctk_label_new (_("Small Title Font")dgettext ("croma", "Small Title Font"))); |
944 | |
945 | collection = preview_collection (FONT_SIZE_LARGE, |
946 | font_desc); |
947 | ctk_notebook_append_page (CTK_NOTEBOOK (notebook)((((CtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((notebook)), ((ctk_notebook_get_type ())))))), |
948 | collection, |
949 | ctk_label_new (_("Large Title Font")dgettext ("croma", "Large Title Font"))); |
950 | |
951 | collection = previews_of_button_layouts (); |
952 | ctk_notebook_append_page (CTK_NOTEBOOK (notebook)((((CtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((notebook)), ((ctk_notebook_get_type ())))))), |
953 | collection, |
954 | ctk_label_new (_("Button Layouts")dgettext ("croma", "Button Layouts"))); |
955 | |
956 | collection = benchmark_summary (); |
957 | ctk_notebook_append_page (CTK_NOTEBOOK (notebook)((((CtkNotebook*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((notebook)), ((ctk_notebook_get_type ())))))), |
958 | collection, |
959 | ctk_label_new (_("Benchmark")dgettext ("croma", "Benchmark"))); |
960 | |
961 | pango_font_description_free (font_desc); |
962 | |
963 | i = 0; |
964 | while (i < (int) G_N_ELEMENTS (previews)(sizeof (previews) / sizeof ((previews)[0]))) |
965 | { |
966 | /* preview widget likes to be realized before its size request. |
967 | * it's lame that way. |
968 | */ |
969 | ctk_widget_realize (previews[i]); |
970 | |
971 | ++i; |
972 | } |
973 | |
974 | ctk_widget_show_all (window); |
975 | |
976 | ctk_main (); |
977 | |
978 | return 0; |
979 | } |
980 | |
981 | |
982 | static MetaFrameFlags |
983 | get_flags (CtkWidget *widget) |
984 | { |
985 | return META_FRAME_ALLOWS_DELETE | |
986 | META_FRAME_ALLOWS_MENU | |
987 | META_FRAME_ALLOWS_MINIMIZE | |
988 | META_FRAME_ALLOWS_MAXIMIZE | |
989 | META_FRAME_ALLOWS_VERTICAL_RESIZE | |
990 | META_FRAME_ALLOWS_HORIZONTAL_RESIZE | |
991 | META_FRAME_HAS_FOCUS | |
992 | META_FRAME_ALLOWS_SHADE | |
993 | META_FRAME_ALLOWS_MOVE; |
994 | } |
995 | |
996 | static int |
997 | get_text_height (CtkWidget *widget) |
998 | { |
999 | CtkStyleContext *style; |
1000 | PangoFontDescription *font_desc; |
1001 | int text_height; |
1002 | |
1003 | style = ctk_widget_get_style_context (widget); |
1004 | ctk_style_context_get (style, CTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL((void*)0)); |
1005 | text_height = meta_pango_font_desc_get_text_height (font_desc, ctk_widget_get_pango_context (widget)); |
1006 | pango_font_description_free (font_desc); |
1007 | |
1008 | return text_height; |
1009 | } |
1010 | |
1011 | static PangoLayout* |
1012 | create_title_layout (CtkWidget *widget) |
1013 | { |
1014 | PangoLayout *layout; |
1015 | |
1016 | layout = ctk_widget_create_pango_layout (widget, _("Window Title Goes Here")dgettext ("croma", "Window Title Goes Here")); |
1017 | |
1018 | return layout; |
1019 | } |
1020 | |
1021 | static void |
1022 | run_theme_benchmark (void) |
1023 | { |
1024 | CtkWidget* widget; |
1025 | MetaFrameBorders borders; |
1026 | MetaButtonState button_states[META_BUTTON_TYPE_LAST] = |
1027 | { |
1028 | META_BUTTON_STATE_NORMAL, |
1029 | META_BUTTON_STATE_NORMAL, |
1030 | META_BUTTON_STATE_NORMAL, |
1031 | META_BUTTON_STATE_NORMAL |
1032 | }; |
1033 | PangoLayout *layout; |
1034 | clock_t start; |
1035 | clock_t end; |
1036 | GTimer *timer; |
1037 | int i; |
1038 | MetaButtonLayout button_layout; |
1039 | #define ITERATIONS 100 |
1040 | int client_width; |
1041 | int client_height; |
1042 | int inc; |
1043 | |
1044 | widget = ctk_window_new (CTK_WINDOW_TOPLEVEL); |
1045 | ctk_widget_realize (widget); |
1046 | |
1047 | meta_theme_get_frame_borders (global_theme, |
1048 | META_FRAME_TYPE_NORMAL, |
1049 | get_text_height (widget), |
1050 | get_flags (widget), |
1051 | &borders); |
1052 | |
1053 | layout = create_title_layout (widget); |
1054 | |
1055 | i = 0; |
1056 | while (i < MAX_BUTTONS_PER_CORNERMETA_BUTTON_FUNCTION_LAST) |
1057 | { |
1058 | button_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST; |
1059 | button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST; |
1060 | ++i; |
1061 | } |
1062 | |
1063 | button_layout.left_buttons[0] = META_BUTTON_FUNCTION_MENU; |
1064 | |
1065 | button_layout.right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE; |
1066 | button_layout.right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE; |
1067 | button_layout.right_buttons[2] = META_BUTTON_FUNCTION_CLOSE; |
1068 | |
1069 | timer = g_timer_new (); |
1070 | start = clock (); |
1071 | |
1072 | client_width = 50; |
1073 | client_height = 50; |
1074 | inc = 1000 / ITERATIONS; /* Increment to grow width/height, |
1075 | * eliminates caching effects. |
1076 | */ |
1077 | |
1078 | i = 0; |
1079 | while (i < ITERATIONS) |
1080 | { |
1081 | cairo_surface_t *pixmap; |
1082 | cairo_t *cr; |
1083 | |
1084 | /* Creating the pixmap in the loop is right, since |
1085 | * CDK does the same with its double buffering. |
1086 | */ |
1087 | pixmap = cdk_window_create_similar_surface (ctk_widget_get_window (widget), |
1088 | CAIRO_CONTENT_COLOR, |
1089 | client_width + borders.total.left + borders.total.right, |
1090 | client_height + borders.total.top + borders.total.bottom); |
1091 | cr = cairo_create (pixmap); |
1092 | |
1093 | meta_theme_draw_frame (global_theme, |
1094 | ctk_widget_get_style_context (widget), |
1095 | cr, |
1096 | META_FRAME_TYPE_NORMAL, |
1097 | get_flags (widget), |
1098 | client_width, client_height, |
1099 | layout, |
1100 | get_text_height (widget), |
1101 | &button_layout, |
1102 | button_states, |
1103 | meta_preview_get_mini_icon (), |
1104 | meta_preview_get_icon ()); |
1105 | |
1106 | cairo_destroy (cr); |
1107 | cairo_surface_destroy (pixmap); |
1108 | |
1109 | ++i; |
1110 | client_width += inc; |
1111 | client_height += inc; |
1112 | } |
1113 | |
1114 | end = clock (); |
1115 | g_timer_stop (timer); |
1116 | |
1117 | milliseconds_to_draw_frame = (g_timer_elapsed (timer, NULL((void*)0)) / (double) ITERATIONS) * 1000; |
1118 | |
1119 | g_print (_("Drew %d frames in %g client-side seconds (%g milliseconds per frame) and %g seconds wall clock time including X server resources (%g milliseconds per frame)\n")dgettext ("croma", "Drew %d frames in %g client-side seconds (%g milliseconds per frame) and %g seconds wall clock time including X server resources (%g milliseconds per frame)\n" ), |
1120 | ITERATIONS, |
1121 | ((double)end - (double)start) / CLOCKS_PER_SEC((__clock_t) 1000000), |
1122 | (((double)end - (double)start) / CLOCKS_PER_SEC((__clock_t) 1000000) / (double) ITERATIONS) * 1000, |
1123 | g_timer_elapsed (timer, NULL((void*)0)), |
1124 | milliseconds_to_draw_frame); |
1125 | |
1126 | g_timer_destroy (timer); |
1127 | g_object_unref (G_OBJECT (layout)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((layout)), (((GType) ((20) << (2))))))))); |
1128 | ctk_widget_destroy (widget); |
1129 | |
1130 | #undef ITERATIONS |
1131 | } |
1132 |