[metacity] select-image.c: don't use deprecated GtkMisc
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] select-image.c: don't use deprecated GtkMisc
- Date: Sat, 4 Oct 2014 21:16:22 +0000 (UTC)
commit 51b9e57dcab716b874c668bdfa9d457fda15f6eb
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sat Oct 4 01:56:03 2014 +0300
select-image.c: don't use deprecated GtkMisc
src/ui/select-image.c | 153 +++++++++++++++++++++++++++----------------------
src/ui/select-image.h | 24 +++++---
src/ui/tabpopup.c | 45 ++-------------
3 files changed, 106 insertions(+), 116 deletions(-)
---
diff --git a/src/ui/select-image.c b/src/ui/select-image.c
index 22db457..a99f722 100644
--- a/src/ui/select-image.c
+++ b/src/ui/select-image.c
@@ -1,7 +1,5 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* Metacity popup window thing showing windows you can tab to */
-
/*
* Copyright (C) 2001 Havoc Pennington
* Copyright (C) 2002 Red Hat, Inc.
@@ -24,101 +22,120 @@
#include <config.h>
#include "select-image.h"
-#define OUTSIDE_SELECT_RECT 2
-#define INSIDE_SELECT_RECT 2
-
-static void meta_select_image_class_init (MetaSelectImageClass *klass);
-static gboolean meta_select_image_draw (GtkWidget *widget,
- cairo_t *cr);
-
-static GtkImageClass *parent_class;
-
-GType
-meta_select_image_get_type (void)
-{
- static GType image_type = 0;
-
- if (!image_type)
- {
- static const GTypeInfo image_info =
- {
- sizeof (MetaSelectImageClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) meta_select_image_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (MetaSelectImage),
- 16, /* n_preallocs */
- (GInstanceInitFunc) NULL,
- };
-
- image_type = g_type_register_static (GTK_TYPE_IMAGE, "MetaSelectImage", &image_info, 0);
- }
-
- return image_type;
-}
+#define BORDER_WIDTH 2
+#define PADDING 3
-static void
-meta_select_image_class_init (MetaSelectImageClass *klass)
+struct _MetaSelectImagePrivate
{
- GtkWidgetClass *widget_class;
-
- parent_class = g_type_class_peek (gtk_image_get_type ());
+ gboolean selected;
+};
- widget_class = GTK_WIDGET_CLASS (klass);
-
- widget_class->draw= meta_select_image_draw;
-}
+G_DEFINE_TYPE_WITH_PRIVATE (MetaSelectImage, meta_select_image, GTK_TYPE_IMAGE);
static gboolean
meta_select_image_draw (GtkWidget *widget,
cairo_t *cr)
{
- GtkAllocation allocation;
+ MetaSelectImage *image;
- gtk_widget_get_allocation (widget, &allocation);
+ image = META_SELECT_IMAGE (widget);
- if (META_SELECT_IMAGE (widget)->selected)
+ if (image->priv->selected)
{
- GtkMisc *misc;
GtkRequisition requisition;
GtkStyleContext *context;
GdkRGBA color;
int x, y, w, h;
- gint xpad, ypad;
- gfloat xalign, yalign;
- misc = GTK_MISC (widget);
-
gtk_widget_get_preferred_size (widget, &requisition, 0);
- gtk_misc_get_alignment (misc, &xalign, &yalign);
- gtk_misc_get_padding (misc, &xpad, &ypad);
-
- x = (allocation.width - (requisition.width - xpad * 2)) * xalign + 0.5;
- y = (allocation.height - (requisition.height - ypad * 2)) * yalign + 0.5;
- x -= INSIDE_SELECT_RECT + 1;
- y -= INSIDE_SELECT_RECT + 1;
-
- w = requisition.width - OUTSIDE_SELECT_RECT * 2 - 1;
- h = requisition.height - OUTSIDE_SELECT_RECT * 2 - 1;
+ x = BORDER_WIDTH;
+ y = BORDER_WIDTH;
+ w = requisition.width - BORDER_WIDTH * 2;
+ h = requisition.height - BORDER_WIDTH * 2;
context = gtk_widget_get_style_context (widget);
- gtk_style_context_set_state (context,
- gtk_widget_get_state_flags (widget));
-
+ gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
gtk_style_context_lookup_color (context, "color", &color);
cairo_set_line_width (cr, 2.0);
cairo_set_source_rgb (cr, color.red, color.green, color.blue);
- cairo_rectangle (cr, x, y, w + 1, h + 1);
+ cairo_rectangle (cr, x, y, w, h);
cairo_stroke (cr);
cairo_set_line_width (cr, 1.0);
}
- return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
+ return GTK_WIDGET_CLASS (meta_select_image_parent_class)->draw (widget, cr);
+}
+
+static void
+meta_select_image_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ GTK_WIDGET_CLASS (meta_select_image_parent_class)->get_preferred_width (widget,
+ minimum_width,
+ natural_width);
+
+ *minimum_width += (BORDER_WIDTH + PADDING) * 2;
+ *natural_width += (BORDER_WIDTH + PADDING) * 2;
+}
+
+static void
+meta_select_image_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GTK_WIDGET_CLASS (meta_select_image_parent_class)->get_preferred_height (widget,
+ minimum_height,
+ natural_height);
+
+ *minimum_height += (BORDER_WIDTH + PADDING) * 2;
+ *natural_height += (BORDER_WIDTH + PADDING) * 2;
+}
+
+static void
+meta_select_image_init (MetaSelectImage *image)
+{
+ image->priv = meta_select_image_get_instance_private (image);
+}
+
+static void
+meta_select_image_class_init (MetaSelectImageClass *class)
+{
+ GtkWidgetClass *widget_class;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+
+ widget_class->draw = meta_select_image_draw;
+ widget_class->get_preferred_width = meta_select_image_get_preferred_width;
+ widget_class->get_preferred_height = meta_select_image_get_preferred_height;
+}
+
+GtkWidget *
+meta_select_image_new (GdkPixbuf *pixbuf)
+{
+ GtkWidget *widget;
+
+ widget = g_object_new (META_TYPE_SELECT_IMAGE, NULL);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (widget), pixbuf);
+
+ return widget;
+}
+
+void
+meta_select_image_select (MetaSelectImage *image)
+{
+ image->priv->selected = TRUE;
+ gtk_widget_queue_draw (GTK_WIDGET (image));
+}
+
+void
+meta_select_image_unselect (MetaSelectImage *image)
+{
+ image->priv->selected = FALSE;
+ gtk_widget_queue_draw (GTK_WIDGET (image));
}
diff --git a/src/ui/select-image.h b/src/ui/select-image.h
index f42c769..64466a3 100644
--- a/src/ui/select-image.h
+++ b/src/ui/select-image.h
@@ -1,7 +1,5 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* Metacity popup window thing showing windows you can tab to */
-
/*
* Copyright (C) 2001 Havoc Pennington
* Copyright (C) 2002 Red Hat, Inc.
@@ -26,16 +24,21 @@
#include <gtk/gtk.h>
-#define META_TYPE_SELECT_IMAGE (meta_select_image_get_type ())
-#define META_SELECT_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_IMAGE,
MetaSelectImage))
+#define META_TYPE_SELECT_IMAGE (meta_select_image_get_type ())
+#define META_SELECT_IMAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_SELECT_IMAGE,
MetaSelectImage))
+#define META_SELECT_IMAGE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_SELECT_IMAGE,
MetaSelectImageClass))
+#define META_IS_SELECT_IMAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_SELECT_IMAGE))
+#define META_IS_SELECT_IMAGE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_SELECT_IMAGE))
+#define META_SELECT_IMAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), META_TYPE_SELECT_IMAGE,
MetaSelectImageClass))
-typedef struct _MetaSelectImage MetaSelectImage;
-typedef struct _MetaSelectImageClass MetaSelectImageClass;
+typedef struct _MetaSelectImage MetaSelectImage;
+typedef struct _MetaSelectImageClass MetaSelectImageClass;
+typedef struct _MetaSelectImagePrivate MetaSelectImagePrivate;
struct _MetaSelectImage
{
- GtkImage parent_instance;
- guint selected : 1;
+ GtkImage parent;
+ MetaSelectImagePrivate *priv;
};
struct _MetaSelectImageClass
@@ -43,6 +46,9 @@ struct _MetaSelectImageClass
GtkImageClass parent_class;
};
-GType meta_select_image_get_type (void) G_GNUC_CONST;
+GType meta_select_image_get_type (void) G_GNUC_CONST;
+GtkWidget *meta_select_image_new (GdkPixbuf *pixbuf);
+void meta_select_image_select (MetaSelectImage *image);
+void meta_select_image_unselect (MetaSelectImage *image);
#endif
diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c
index 4b88d29..2a72d4c 100644
--- a/src/ui/tabpopup.c
+++ b/src/ui/tabpopup.c
@@ -62,10 +62,6 @@ struct _MetaTabPopup
gboolean outline;
};
-static GtkWidget* selectable_image_new (GdkPixbuf *pixbuf);
-static void select_image (GtkWidget *widget);
-static void unselect_image (GtkWidget *widget);
-
static GtkWidget* selectable_workspace_new (MetaWorkspace *workspace);
static void select_workspace (GtkWidget *widget);
static void unselect_workspace (GtkWidget *widget);
@@ -343,17 +339,15 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
{
if (te->dimmed_icon)
{
- image = selectable_image_new (te->dimmed_icon);
+ image = meta_select_image_new (te->dimmed_icon);
}
else
{
- image = selectable_image_new (te->icon);
+ image = meta_select_image_new (te->icon);
}
- gtk_misc_set_padding (GTK_MISC (image),
- INSIDE_SELECT_RECT + OUTSIDE_SELECT_RECT + 1,
- INSIDE_SELECT_RECT + OUTSIDE_SELECT_RECT + 1);
- gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
+ gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
}
else
{
@@ -458,7 +452,7 @@ display_entry (MetaTabPopup *popup,
if (popup->current_selected_entry)
{
if (popup->outline)
- unselect_image (popup->current_selected_entry->widget);
+ meta_select_image_unselect (META_SELECT_IMAGE (popup->current_selected_entry->widget));
else
unselect_workspace (popup->current_selected_entry->widget);
}
@@ -466,7 +460,7 @@ display_entry (MetaTabPopup *popup,
gtk_label_set_markup (GTK_LABEL (popup->label), te->title);
if (popup->outline)
- select_image (te->widget);
+ meta_select_image_select (META_SELECT_IMAGE (te->widget));
else
select_workspace (te->widget);
@@ -588,33 +582,6 @@ meta_ui_tab_popup_select (MetaTabPopup *popup,
}
}
-
-
-static GtkWidget*
-selectable_image_new (GdkPixbuf *pixbuf)
-{
- GtkWidget *w;
-
- w = g_object_new (meta_select_image_get_type (), NULL);
- gtk_image_set_from_pixbuf (GTK_IMAGE (w), pixbuf);
-
- return w;
-}
-
-static void
-select_image (GtkWidget *widget)
-{
- META_SELECT_IMAGE (widget)->selected = TRUE;
- gtk_widget_queue_draw (widget);
-}
-
-static void
-unselect_image (GtkWidget *widget)
-{
- META_SELECT_IMAGE (widget)->selected = FALSE;
- gtk_widget_queue_draw (widget);
-}
-
#define META_TYPE_SELECT_WORKSPACE (meta_select_workspace_get_type ())
#define META_SELECT_WORKSPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_WORKSPACE,
MetaSelectWorkspace))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]