[bijiben/wip/sadiq/modernize] color-button: Port to G_DECLARE_FINAL_TYPE
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben/wip/sadiq/modernize] color-button: Port to G_DECLARE_FINAL_TYPE
- Date: Thu, 2 Nov 2017 06:22:27 +0000 (UTC)
commit edefcc577759ea0d8c234ed5fce8255d0b845bcb
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Thu Nov 2 11:47:23 2017 +0530
color-button: Port to G_DECLARE_FINAL_TYPE
* Use G_DECLARE_FINAL_TYPE to avoid boilerplate code
* Don't use private members.
This class isn't derivable. So there isn't any difference
* Also, to be consistant with gnome coding standards, use
'self' as identifier name when referencing self.
This is a part of effort to clean up codebase and make the code more
maintainable.
https://bugzilla.gnome.org/show_bug.cgi?id=789696
src/bjb-color-button.c | 71 +++++++++++++++---------------------------------
src/bjb-color-button.h | 27 ++----------------
2 files changed, 25 insertions(+), 73 deletions(-)
---
diff --git a/src/bjb-color-button.c b/src/bjb-color-button.c
index 8ae5eff..4185106 100644
--- a/src/bjb-color-button.c
+++ b/src/bjb-color-button.c
@@ -34,26 +34,25 @@ static const gchar *palette_str[BJB_NUM_COLORS] = {
"rgb(235, 239, 244)", //
};
-struct _BjbColorButtonPrivate
+struct _BjbColorButton
{
+ GtkColorButton parent_instance;
+
GdkRGBA palette [BJB_NUM_COLORS];
GtkWidget *dialog;
gchar *title;
GdkRGBA rgba;
};
-#define BJB_COLOR_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_COLOR_BUTTON,
BjbColorButtonPrivate))
-
-
G_DEFINE_TYPE (BjbColorButton, bjb_color_button, GTK_TYPE_COLOR_BUTTON);
static gboolean
dialog_destroy (GtkWidget *widget,
gpointer data)
{
- BjbColorButton *button = BJB_COLOR_BUTTON (data);
+ BjbColorButton *self = BJB_COLOR_BUTTON (data);
- button->priv->dialog = NULL;
+ self->dialog = NULL;
return FALSE;
}
@@ -63,8 +62,7 @@ dialog_response (GtkDialog *dialog,
gint response,
gpointer data)
{
- BjbColorButton *button = BJB_COLOR_BUTTON (data);
- BjbColorButtonPrivate *priv = button->priv;
+ BjbColorButton *self = BJB_COLOR_BUTTON (data);
if (response == GTK_RESPONSE_CANCEL)
gtk_widget_hide (GTK_WIDGET (dialog));
@@ -72,31 +70,30 @@ dialog_response (GtkDialog *dialog,
else if (response == GTK_RESPONSE_OK)
{
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
- &priv->rgba);
+ &self->rgba);
gtk_widget_hide (GTK_WIDGET (dialog));
- gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), &priv->rgba);
- g_signal_emit_by_name (button, "color-set");
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (self), &self->rgba);
+ g_signal_emit_by_name (self, "color-set");
}
}
static void
bjb_color_button_clicked (GtkButton *b)
{
- BjbColorButton *button = BJB_COLOR_BUTTON (b);
- BjbColorButtonPrivate *priv = button->priv;
+ BjbColorButton *self = BJB_COLOR_BUTTON (b);
GtkWidget *dialog;
gint i;
/* if dialog already exists, make sure it's shown and raised */
- if (!button->priv->dialog)
+ if (!self->dialog)
{
/* Create the dialog and connects its buttons */
GtkWidget *parent;
- parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (self));
- button->priv->dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
+ self->dialog = dialog = gtk_color_chooser_dialog_new (self->title, NULL);
if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
{
@@ -112,63 +109,39 @@ bjb_color_button_clicked (GtkButton *b)
GdkRGBA color;
if (gdk_rgba_parse (&color, palette_str[i]))
- priv->palette [i] = color;
+ self->palette [i] = color;
}
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
GTK_ORIENTATION_HORIZONTAL,
BJB_NUM_COLORS,
BJB_NUM_COLORS,
- priv->palette);
-
+ self->palette);
g_signal_connect (dialog, "response",
- G_CALLBACK (dialog_response), button);
+ G_CALLBACK (dialog_response), self);
g_signal_connect (dialog, "destroy",
- G_CALLBACK (dialog_destroy), button);
+ G_CALLBACK (dialog_destroy), self);
}
- gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &priv->rgba);
- gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->priv->dialog),
- &button->priv->rgba);
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (self), &self->rgba);
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (self->dialog),
+ &self->rgba);
- gtk_window_present (GTK_WINDOW (button->priv->dialog));
+ gtk_window_present (GTK_WINDOW (self->dialog));
}
-
-
static void
bjb_color_button_init (BjbColorButton *self)
{
- BjbColorButtonPrivate *priv = BJB_COLOR_BUTTON_GET_PRIVATE(self);
- self->priv = priv;
-
- priv->title = _("Note Color");
-}
-
-static void
-bjb_color_button_constructed (GObject *obj)
-{
- G_OBJECT_CLASS (bjb_color_button_parent_class)->constructed (obj);
-}
-
-static void
-bjb_color_button_finalize (GObject *object)
-{
- G_OBJECT_CLASS (bjb_color_button_parent_class)->finalize (object);
+ self->title = _("Note Color");
}
static void
bjb_color_button_class_init (BjbColorButtonClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
- g_type_class_add_private (klass, sizeof (BjbColorButtonPrivate));
-
- object_class->constructed = bjb_color_button_constructed;
- object_class->finalize = bjb_color_button_finalize;
-
/* Override std::gtk_color_button */
button_class->clicked = bjb_color_button_clicked;
}
diff --git a/src/bjb-color-button.h b/src/bjb-color-button.h
index 1768cd1..4ea86ab 100644
--- a/src/bjb-color-button.h
+++ b/src/bjb-color-button.h
@@ -22,30 +22,9 @@
G_BEGIN_DECLS
-#define BJB_TYPE_COLOR_BUTTON (bjb_color_button_get_type ())
-#define BJB_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_COLOR_BUTTON,
BjbColorButton))
-#define BJB_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_COLOR_BUTTON,
BjbColorButtonClass))
-#define BJB_IS_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_COLOR_BUTTON))
-#define BJB_IS_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_COLOR_BUTTON))
-#define BJB_COLOR_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_COLOR_BUTTON,
BjbColorButtonClass))
-
-typedef struct _BjbColorButtonClass BjbColorButtonClass;
-typedef struct _BjbColorButton BjbColorButton;
-typedef struct _BjbColorButtonPrivate BjbColorButtonPrivate;
-
-
-struct _BjbColorButtonClass
-{
- GtkColorButtonClass parent_class;
-};
-
-struct _BjbColorButton
-{
- GtkColorButton parent_instance;
- BjbColorButtonPrivate *priv;
-};
-
-GType bjb_color_button_get_type (void) G_GNUC_CONST;
+#define BJB_TYPE_COLOR_BUTTON (bjb_color_button_get_type ())
+
+G_DECLARE_FINAL_TYPE (BjbColorButton, bjb_color_button, BJB, COLOR_BUTTON, GtkColorButton)
GtkWidget * bjb_color_button_new (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]