5 draw_cb_checks (GtkWidget *widget, cairo_t *cr)
7 GtkStyleContext *context;
9 context = gtk_widget_get_style_context (widget);
11 gtk_style_context_save (context);
13 gtk_style_context_add_class (context, "check");
14 gtk_style_context_set_state (context, 0);
15 gtk_render_check (context, cr, 12, 12, 12, 12);
16 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
17 gtk_render_check (context, cr, 36, 12, 12, 12);
18 gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
19 gtk_render_check (context, cr, 60, 12, 12, 12);
20 gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
21 gtk_render_check (context, cr, 84, 12, 12, 12);
23 gtk_style_context_restore (context);
30 draw_cb_options (GtkWidget *widget, cairo_t *cr)
32 GtkStyleContext *context;
34 context = gtk_widget_get_style_context (widget);
36 gtk_style_context_save (context);
38 gtk_style_context_add_class (context, "radio");
39 gtk_style_context_set_state (context, 0);
40 gtk_render_option (context, cr, 12, 12, 12, 12);
41 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
42 gtk_render_option (context, cr, 36, 12, 12, 12);
43 gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
44 gtk_render_option (context, cr, 60, 12, 12, 12);
45 gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
46 gtk_render_option (context, cr, 84, 12, 12, 12);
48 gtk_style_context_restore (context);
54 draw_cb_arrows (GtkWidget *widget, cairo_t *cr)
56 GtkStyleContext *context;
58 context = gtk_widget_get_style_context (widget);
60 gtk_style_context_save (context);
62 gtk_style_context_set_state (context, 0);
63 gtk_render_arrow (context, cr, 0, 12, 12, 12);
64 gtk_render_arrow (context, cr, G_PI/2, 36, 12, 12);
65 gtk_render_arrow (context, cr, G_PI, 60, 12, 12);
66 gtk_render_arrow (context, cr, G_PI*3/2, 84, 12, 12);
68 gtk_style_context_restore (context);
74 draw_cb_expanders (GtkWidget *widget, cairo_t *cr)
76 GtkStyleContext *context;
78 context = gtk_widget_get_style_context (widget);
80 gtk_style_context_save (context);
82 gtk_style_context_add_class (context, "expander");
83 gtk_style_context_set_state (context, 0);
84 gtk_render_expander (context, cr, 12, 12, 12, 12);
85 gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT);
86 gtk_render_expander (context, cr, 36, 12, 12, 12);
87 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
88 gtk_render_expander (context, cr, 60, 12, 12, 12);
89 gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
90 gtk_render_expander (context, cr, 84, 12, 12, 12);
92 gtk_style_context_restore (context);
98 draw_cb_background (GtkWidget *widget, cairo_t *cr)
100 GtkStyleContext *context;
102 context = gtk_widget_get_style_context (widget);
104 gtk_style_context_save (context);
106 gtk_style_context_add_class (context, "background");
107 gtk_style_context_set_junction_sides (context, 0);
108 gtk_render_background (context, cr, 12, 12, 100, 100);
109 gtk_style_context_remove_class (context, "background");
111 gtk_style_context_restore (context);
117 draw_cb_frame (GtkWidget *widget, cairo_t *cr)
119 GtkStyleContext *context;
121 context = gtk_widget_get_style_context (widget);
123 gtk_style_context_save (context);
125 gtk_style_context_add_class (context, "frame1");
126 gtk_style_context_set_junction_sides (context, 0);
127 gtk_render_frame (context, cr, 12, 12, 50, 50);
128 gtk_style_context_remove_class (context, "frame1");
130 gtk_style_context_add_class (context, "frame2");
131 gtk_render_frame (context, cr, 74, 12, 50, 50);
132 gtk_style_context_remove_class (context, "frame2");
134 gtk_style_context_add_class (context, "frame3");
135 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_RIGHT);
136 gtk_render_frame (context, cr, 12, 74, 56, 50);
137 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_LEFT);
138 gtk_render_frame (context, cr, 68, 74, 56, 50);
139 gtk_style_context_remove_class (context, "frame3");
141 gtk_style_context_restore (context);
146 /* FIXME: this doesn't work */
148 draw_cb_activity (GtkWidget *widget, cairo_t *cr)
150 GtkStyleContext *context;
153 context = gtk_widget_get_style_context (widget);
154 gtk_style_context_notify_state_change (context,
155 gtk_widget_get_window (widget),
157 GTK_STATE_FLAG_ACTIVE,
160 gtk_style_context_save (context);
162 path = gtk_widget_path_new ();
163 gtk_widget_path_append_type (path, GTK_TYPE_SPINNER);
164 gtk_widget_path_iter_add_class (path, 0, "spinner");
165 gtk_style_context_set_path (context, path);
166 gtk_widget_path_free (path);
168 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
169 gtk_render_activity (context, cr, 12, 12, 12, 12);
171 gtk_style_context_restore (context);
177 draw_cb_slider (GtkWidget *widget, cairo_t *cr)
179 GtkStyleContext *context;
182 context = gtk_widget_get_style_context (widget);
183 gtk_style_context_save (context);
185 path = gtk_widget_path_new ();
186 gtk_widget_path_append_type (path, GTK_TYPE_SCALE);
187 gtk_widget_path_iter_add_class (path, 0, "slider");
188 gtk_widget_path_iter_add_class (path, 0, "scale");
189 gtk_style_context_set_path (context, path);
190 gtk_widget_path_free (path);
192 gtk_render_slider (context, cr, 12, 22, 30, 10, GTK_ORIENTATION_HORIZONTAL);
193 gtk_render_slider (context, cr, 54, 12, 10, 30, GTK_ORIENTATION_VERTICAL);
195 gtk_style_context_restore (context);
201 draw_cb_focus (GtkWidget *widget, cairo_t *cr)
203 GtkStyleContext *context;
205 context = gtk_widget_get_style_context (widget);
207 gtk_style_context_save (context);
209 gtk_render_focus (context, cr, 12, 12, 50, 50);
211 gtk_style_context_restore (context);
217 draw_cb_extension (GtkWidget *widget, cairo_t *cr)
219 GtkStyleContext *context;
221 context = gtk_widget_get_style_context (widget);
223 gtk_style_context_save (context);
225 gtk_style_context_add_class (context, "notebook");
226 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
228 gtk_style_context_set_state (context, 0);
229 gtk_render_extension (context, cr, 26, 12, 24, 12, GTK_POS_BOTTOM);
230 gtk_render_extension (context, cr, 12, 26, 12, 24, GTK_POS_RIGHT);
231 gtk_render_extension (context, cr, 26, 52, 24, 12, GTK_POS_TOP);
232 gtk_render_extension (context, cr, 52, 26, 12, 24, GTK_POS_LEFT);
234 gtk_style_context_restore (context);
240 draw_cb_frame_gap (GtkWidget *widget, cairo_t *cr)
242 GtkStyleContext *context;
244 context = gtk_widget_get_style_context (widget);
246 gtk_style_context_save (context);
248 gtk_style_context_add_class (context, "frame");
249 gtk_style_context_set_junction_sides (context, 0);
250 gtk_render_frame_gap (context, cr, 12, 12, 50, 50, GTK_POS_TOP, 15, 35);
251 gtk_style_context_remove_class (context, "frame");
253 gtk_style_context_restore (context);
259 draw_cb_handles (GtkWidget *widget, cairo_t *cr)
261 GtkStyleContext *context;
263 context = gtk_widget_get_style_context (widget);
264 gtk_style_context_save (context);
266 gtk_style_context_add_class (context, "paned");
267 gtk_render_handle (context, cr, 12, 22, 20, 10);
268 gtk_render_handle (context, cr, 44, 12, 10, 20);
269 gtk_style_context_remove_class (context, "paned");
271 gtk_style_context_add_class (context, "grip");
272 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_CORNER_BOTTOMLEFT);
273 gtk_render_handle (context, cr, 12, 48, 12, 12);
275 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_CORNER_BOTTOMRIGHT);
276 gtk_render_handle (context, cr, 40, 48, 12, 12);
278 gtk_style_context_restore (context);
286 draw_cb (GtkWidget *widget, cairo_t *cr)
288 if (strcmp (what, "check") == 0)
289 return draw_cb_checks (widget, cr);
290 else if (strcmp (what, "option") == 0)
291 return draw_cb_options (widget, cr);
292 else if (strcmp (what, "arrow") == 0)
293 return draw_cb_arrows (widget, cr);
294 else if (strcmp (what, "expander") == 0)
295 return draw_cb_expanders (widget, cr);
296 else if (strcmp (what, "background") == 0)
297 return draw_cb_background (widget, cr);
298 else if (strcmp (what, "frame") == 0)
299 return draw_cb_frame (widget, cr);
300 else if (strcmp (what, "activity") == 0)
301 return draw_cb_activity (widget, cr);
302 else if (strcmp (what, "slider") == 0)
303 return draw_cb_slider (widget, cr);
304 else if (strcmp (what, "focus") == 0)
305 return draw_cb_focus (widget, cr);
306 else if (strcmp (what, "extension") == 0)
307 return draw_cb_extension (widget, cr);
308 else if (strcmp (what, "frame-gap") == 0)
309 return draw_cb_frame_gap (widget, cr);
310 else if (strcmp (what, "handle") == 0)
311 return draw_cb_handles (widget, cr);
316 int main (int argc, char *argv[])
320 GtkStyleContext *context;
321 GtkStyleProvider *provider;
323 gtk_init (&argc, &argv);
330 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
331 gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
332 ebox = gtk_event_box_new ();
333 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), TRUE);
334 gtk_container_add (GTK_CONTAINER (window), ebox);
335 gtk_widget_set_name (ebox, "ebox");
337 context = gtk_widget_get_style_context (ebox);
338 provider = (GtkStyleProvider *)gtk_css_provider_new ();
339 gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
341 " border-image: url('gradient1.png') 10 10 10 10 stretch;\n"
344 " border-style: solid;\n"
345 " border-color: rgb(255,0,0);\n"
346 " border-width: 10;\n"
347 " border-radius: 10;\n"
350 " border-style: solid;\n"
351 " border-color: rgb(0,0,0);\n"
352 " border-width: 2;\n"
353 " border-radius: 10;\n"
356 " border-radius: 10;\n"
357 " border-width: 0;\n"
358 " background-image: -gtk-gradient (linear, left top, right bottom, from(#ff00ff), to(#aabbcc));\n"
361 " border-style: solid;\n"
362 " border-width: 1;\n"
363 " border-radius: 0;\n"
365 gtk_style_context_add_provider (context, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
367 g_signal_connect_after (ebox, "draw", G_CALLBACK (draw_cb), NULL);
369 gtk_widget_show_all (window);
373 gtk_style_context_remove_provider (context, provider);