summaryrefslogtreecommitdiff
path: root/demos/gtk-demo
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2010-11-24 22:40:19 -0500
committerCarlos Garnacho <carlosg@gnome.org>2010-12-04 15:39:46 +0100
commit9b1118a35db12cafa0f9587f8748eac232a624e0 (patch)
tree5292798b119824e59a2d95c972a378422c610e2d /demos/gtk-demo
parentbbca96044e931638acc75b954b30482cc2571703 (diff)
downloadgtk+-9b1118a35db12cafa0f9587f8748eac232a624e0.tar.gz
Port gtk3-demo to GtkStyleContext
Diffstat (limited to 'demos/gtk-demo')
-rw-r--r--demos/gtk-demo/colorsel.c65
-rw-r--r--demos/gtk-demo/combobox.c6
-rw-r--r--demos/gtk-demo/main.c2
-rw-r--r--demos/gtk-demo/offscreen_window.c25
-rw-r--r--demos/gtk-demo/offscreen_window2.c19
-rw-r--r--demos/gtk-demo/rotated_text.c50
-rw-r--r--demos/gtk-demo/textview.c6
7 files changed, 86 insertions, 87 deletions
diff --git a/demos/gtk-demo/colorsel.c b/demos/gtk-demo/colorsel.c
index eacfa17d38..14ea9107c4 100644
--- a/demos/gtk-demo/colorsel.c
+++ b/demos/gtk-demo/colorsel.c
@@ -9,35 +9,37 @@
static GtkWidget *window = NULL;
static GtkWidget *da;
-static GdkColor color;
+static GdkRGBA color;
static GtkWidget *frame;
-/* Expose callback for the drawing area
+/* draw callback for the drawing area
*/
static gboolean
-draw_callback (GtkWidget *widget,
+draw_callback (GtkWidget *widget,
cairo_t *cr,
gpointer data)
{
- GtkStyle *style;
+ GtkStyleContext *context;
+ GdkRGBA *bg;
- style = gtk_widget_get_style (widget);
-
- gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get (context, 0, "background-color", &bg, NULL);
+ gdk_cairo_set_source_rgba (cr, bg);
cairo_paint (cr);
+ gdk_rgba_free (bg);
return TRUE;
}
static void
change_color_callback (GtkWidget *button,
- gpointer data)
+ gpointer data)
{
GtkWidget *dialog;
GtkColorSelection *colorsel;
GtkColorSelectionDialog *selection_dialog;
gint response;
-
+
dialog = gtk_color_selection_dialog_new ("Changing color");
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
@@ -45,20 +47,19 @@ change_color_callback (GtkWidget *button,
selection_dialog = GTK_COLOR_SELECTION_DIALOG (dialog);
colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog));
- gtk_color_selection_set_previous_color (colorsel, &color);
- gtk_color_selection_set_current_color (colorsel, &color);
+ gtk_color_selection_set_previous_rgba (colorsel, &color);
+ gtk_color_selection_set_current_rgba (colorsel, &color);
gtk_color_selection_set_has_palette (colorsel, TRUE);
-
+
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response == GTK_RESPONSE_OK)
{
- gtk_color_selection_get_current_color (colorsel,
- &color);
-
- gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
+ gtk_color_selection_get_current_rgba (colorsel, &color);
+
+ gtk_widget_override_background_color (da, 0, &color);
}
-
+
gtk_widget_destroy (dialog);
}
@@ -68,20 +69,21 @@ do_colorsel (GtkWidget *do_widget)
GtkWidget *vbox;
GtkWidget *button;
GtkWidget *alignment;
-
+
if (!window)
{
color.red = 0;
- color.blue = 65535;
+ color.blue = 1;
color.green = 0;
-
+ color.alpha = 1;
+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (do_widget));
+ gtk_widget_get_screen (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Color Selection");
g_signal_connect (window, "destroy",
- G_CALLBACK (gtk_widget_destroyed), &window);
+ G_CALLBACK (gtk_widget_destroyed), &window);
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
@@ -92,33 +94,32 @@ do_colorsel (GtkWidget *do_widget)
/*
* Create the color swatch area
*/
-
-
+
+
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
da = gtk_drawing_area_new ();
- g_signal_connect (da, "draw",
- G_CALLBACK (draw_callback), NULL);
+ g_signal_connect (da, "draw", G_CALLBACK (draw_callback), NULL);
/* set a minimum size */
gtk_widget_set_size_request (da, 200, 200);
/* set the color */
- gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
-
+ gtk_widget_override_background_color (da, 0, &color);
+
gtk_container_add (GTK_CONTAINER (frame), da);
alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
-
+
button = gtk_button_new_with_mnemonic ("_Change the above color");
gtk_container_add (GTK_CONTAINER (alignment), button);
-
+
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
-
+
g_signal_connect (button, "clicked",
- G_CALLBACK (change_color_callback), NULL);
+ G_CALLBACK (change_color_callback), NULL);
}
if (!gtk_widget_get_visible (window))
diff --git a/demos/gtk-demo/combobox.c b/demos/gtk-demo/combobox.c
index 308242b109..fbe6c12eeb 100644
--- a/demos/gtk-demo/combobox.c
+++ b/demos/gtk-demo/combobox.c
@@ -281,18 +281,18 @@ G_DEFINE_TYPE_WITH_CODE (MaskEntry, mask_entry, GTK_TYPE_ENTRY,
static void
mask_entry_set_background (MaskEntry *entry)
{
- static const GdkColor error_color = { 0, 65535, 60000, 60000 };
+ static const GdkRGBA error_color = { 1.0, 0.9, 0.9, 1.0 };
if (entry->mask)
{
if (!g_regex_match_simple (entry->mask, gtk_entry_get_text (GTK_ENTRY (entry)), 0, 0))
{
- gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &error_color);
+ gtk_widget_override_color (GTK_WIDGET (entry), 0, &error_color);
return;
}
}
- gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
+ gtk_widget_override_color (GTK_WIDGET (entry), 0, NULL);
}
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index e0c9fb896a..81bd5b6e4e 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -751,7 +751,7 @@ create_text (GtkTextBuffer **buffer,
if (is_source)
{
font_desc = pango_font_description_from_string ("monospace");
- gtk_widget_modify_font (text_view, font_desc);
+ gtk_widget_override_font (text_view, font_desc);
pango_font_description_free (font_desc);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view),
diff --git a/demos/gtk-demo/offscreen_window.c b/demos/gtk-demo/offscreen_window.c
index cb014bc2ac..27ff99ef8d 100644
--- a/demos/gtk-demo/offscreen_window.c
+++ b/demos/gtk-demo/offscreen_window.c
@@ -230,7 +230,7 @@ gtk_rotated_bin_realize (GtkWidget *widget)
{
GtkRotatedBin *bin = GTK_ROTATED_BIN (widget);
GtkAllocation allocation;
- GtkStyle *style;
+ GtkStyleContext *context;
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
@@ -291,9 +291,9 @@ gtk_rotated_bin_realize (GtkWidget *widget)
G_CALLBACK (offscreen_window_from_parent), bin);
gtk_widget_style_attach (widget);
- style = gtk_widget_get_style (widget);
- gtk_style_set_background (style, window, GTK_STATE_NORMAL);
- gtk_style_set_background (style, bin->offscreen_window, GTK_STATE_NORMAL);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_background (context, window);
+ gtk_style_context_set_background (context, bin->offscreen_window);
gdk_window_show (bin->offscreen_window);
}
@@ -542,12 +542,11 @@ gtk_rotated_bin_draw (GtkWidget *widget,
}
if (gtk_cairo_should_draw_window (cr, bin->offscreen_window))
{
- gtk_paint_flat_box (gtk_widget_get_style (widget), cr,
- GTK_STATE_NORMAL, GTK_SHADOW_NONE,
- widget, "blah",
- 0, 0,
- gdk_window_get_width (bin->offscreen_window),
- gdk_window_get_height (bin->offscreen_window));
+ gtk_render_background (gtk_widget_get_style_context (widget),
+ cr,
+ 0, 0,
+ gdk_window_get_width (bin->offscreen_window),
+ gdk_window_get_height (bin->offscreen_window));
if (bin->child)
gtk_container_propagate_draw (GTK_CONTAINER (widget),
@@ -575,7 +574,7 @@ do_offscreen_window (GtkWidget *do_widget)
if (!window)
{
GtkWidget *bin, *vbox, *scale, *button;
- GdkColor black;
+ GdkRGBA black;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
@@ -585,8 +584,8 @@ do_offscreen_window (GtkWidget *do_widget)
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
- gdk_color_parse ("black", &black);
- gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &black);
+ gdk_rgba_parse (&black, "black");
+ gtk_widget_override_background_color (window, 0, &black);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
diff --git a/demos/gtk-demo/offscreen_window2.c b/demos/gtk-demo/offscreen_window2.c
index 7fd2940f3a..96d953dbbe 100644
--- a/demos/gtk-demo/offscreen_window2.c
+++ b/demos/gtk-demo/offscreen_window2.c
@@ -168,7 +168,7 @@ gtk_mirror_bin_realize (GtkWidget *widget)
{
GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
GtkAllocation allocation;
- GtkStyle *style;
+ GtkStyleContext *context;
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
@@ -229,9 +229,9 @@ gtk_mirror_bin_realize (GtkWidget *widget)
G_CALLBACK (offscreen_window_from_parent), bin);
gtk_widget_style_attach (widget);
- style = gtk_widget_get_style (widget);
- gtk_style_set_background (style, window, GTK_STATE_NORMAL);
- gtk_style_set_background (style, bin->offscreen_window, GTK_STATE_NORMAL);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_background (context, window);
+ gtk_style_context_set_background (context, bin->offscreen_window);
gdk_window_show (bin->offscreen_window);
}
@@ -451,12 +451,11 @@ gtk_mirror_bin_draw (GtkWidget *widget,
}
else if (gtk_cairo_should_draw_window (cr, bin->offscreen_window))
{
- gtk_paint_flat_box (gtk_widget_get_style (widget), cr,
- GTK_STATE_NORMAL, GTK_SHADOW_NONE,
- widget, "blah",
- 0, 0,
- gdk_window_get_width (bin->offscreen_window),
- gdk_window_get_height (bin->offscreen_window));
+ gtk_render_background (gtk_widget_get_style_context (widget),
+ cr,
+ 0, 0,
+ gdk_window_get_width (bin->offscreen_window),
+ gdk_window_get_height (bin->offscreen_window));
if (bin->child)
gtk_container_propagate_draw (GTK_CONTAINER (widget),
diff --git a/demos/gtk-demo/rotated_text.c b/demos/gtk-demo/rotated_text.c
index ab6ac71a7f..3d1df15cb8 100644
--- a/demos/gtk-demo/rotated_text.c
+++ b/demos/gtk-demo/rotated_text.c
@@ -18,17 +18,17 @@ const char text[] = "I ♥ GTK+";
static void
fancy_shape_renderer (cairo_t *cr,
- PangoAttrShape *attr,
- gboolean do_path,
- gpointer data)
+ PangoAttrShape *attr,
+ gboolean do_path,
+ gpointer data)
{
double x, y;
cairo_get_current_point (cr, &x, &y);
cairo_translate (cr, x, y);
cairo_scale (cr,
- (double) attr->ink_rect.width / PANGO_SCALE,
- (double) attr->ink_rect.height / PANGO_SCALE);
+ (double) attr->ink_rect.width / PANGO_SCALE,
+ (double) attr->ink_rect.height / PANGO_SCALE);
switch (GPOINTER_TO_UINT (attr->data))
{
@@ -36,9 +36,9 @@ fancy_shape_renderer (cairo_t *cr,
{
cairo_move_to (cr, .5, .0);
cairo_line_to (cr, .9, -.4);
- cairo_curve_to (cr, 1.1, -.8, .5, -.9, .5, -.5);
- cairo_curve_to (cr, .5, -.9, -.1, -.8, .1, -.4);
- cairo_close_path (cr);
+ cairo_curve_to (cr, 1.1, -.8, .5, -.9, .5, -.5);
+ cairo_curve_to (cr, .5, -.9, -.1, -.8, .1, -.4);
+ cairo_close_path (cr);
}
break;
}
@@ -60,8 +60,8 @@ create_fancy_attr_list_for_layout (PangoLayout *layout)
/* Get font metrics and prepare fancy shape size */
metrics = pango_context_get_metrics (pango_layout_get_context (layout),
- pango_layout_get_font_description (layout),
- NULL);
+ pango_layout_get_font_description (layout),
+ NULL);
ascent = pango_font_metrics_get_ascent (metrics);
logical_rect.x = 0;
logical_rect.width = ascent;
@@ -77,9 +77,9 @@ create_fancy_attr_list_for_layout (PangoLayout *layout)
PangoAttribute *attr;
attr = pango_attr_shape_new_with_data (&ink_rect,
- &logical_rect,
- GUINT_TO_POINTER (g_utf8_get_char (p)),
- NULL, NULL);
+ &logical_rect,
+ GUINT_TO_POINTER (g_utf8_get_char (p)),
+ NULL, NULL);
attr->start_index = p - text;
attr->end_index = attr->start_index + strlen (HEART);
@@ -93,7 +93,7 @@ create_fancy_attr_list_for_layout (PangoLayout *layout)
static gboolean
rotated_text_draw (GtkWidget *widget,
cairo_t *cr,
- gpointer data)
+ gpointer data)
{
#define RADIUS 150
#define N_WORDS 5
@@ -119,8 +119,8 @@ rotated_text_draw (GtkWidget *widget,
height = gtk_widget_get_allocated_height (widget);
device_radius = MIN (width, height) / 2.;
cairo_translate (cr,
- device_radius + (width - 2 * device_radius) / 2,
- device_radius + (height - 2 * device_radius) / 2);
+ device_radius + (width - 2 * device_radius) / 2,
+ device_radius + (height - 2 * device_radius) / 2);
cairo_scale (cr, device_radius / RADIUS, device_radius / RADIUS);
/* Create and a subtle gradient source and use it. */
@@ -132,8 +132,8 @@ rotated_text_draw (GtkWidget *widget,
/* Create a PangoContext and set up our shape renderer */
context = gtk_widget_create_pango_context (widget);
pango_cairo_context_set_shape_renderer (context,
- fancy_shape_renderer,
- NULL, NULL);
+ fancy_shape_renderer,
+ NULL, NULL);
/* Create a PangoLayout, set the text, font, and attributes */
layout = pango_layout_new (context);
@@ -181,11 +181,11 @@ do_rotated_text (GtkWidget *do_widget)
PangoLayout *layout;
PangoAttrList *attrs;
- const GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
-
+ const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (do_widget));
+ gtk_widget_get_screen (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Rotated Text");
gtk_window_set_default_size (GTK_WINDOW (window), 4 * RADIUS, 2 * RADIUS);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
@@ -200,10 +200,10 @@ do_rotated_text (GtkWidget *do_widget)
gtk_container_add (GTK_CONTAINER (box), drawing_area);
/* This overrides the background color from the theme */
- gtk_widget_modify_bg (drawing_area, GTK_STATE_NORMAL, &white);
+ gtk_widget_override_background_color (drawing_area, 0, &white);
g_signal_connect (drawing_area, "draw",
- G_CALLBACK (rotated_text_draw), NULL);
+ G_CALLBACK (rotated_text_draw), NULL);
/* And a label */
@@ -215,8 +215,8 @@ do_rotated_text (GtkWidget *do_widget)
/* Set up fancy stuff on the label */
layout = gtk_label_get_layout (GTK_LABEL (label));
pango_cairo_context_set_shape_renderer (pango_layout_get_context (layout),
- fancy_shape_renderer,
- NULL, NULL);
+ fancy_shape_renderer,
+ NULL, NULL);
attrs = create_fancy_attr_list_for_layout (layout);
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index 469bb87b88..acc677ca7f 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -561,7 +561,7 @@ recursive_attach_view (int depth,
{
GtkWidget *child_view;
GtkWidget *event_box;
- GdkColor color;
+ GdkRGBA color;
GtkWidget *align;
if (depth > 4)
@@ -571,8 +571,8 @@ recursive_attach_view (int depth,
/* Event box is to add a black border around each child view */
event_box = gtk_event_box_new ();
- gdk_color_parse ("black", &color);
- gtk_widget_modify_bg (event_box, GTK_STATE_NORMAL, &color);
+ gdk_rgba_parse (&color, "black");
+ gtk_widget_override_background_color (event_box, 0, &color);
align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
gtk_container_set_border_width (GTK_CONTAINER (align), 1);