[monet] Add MnWidget



commit 2ee83be884591deb41d40689776d9fe0417b8a47
Author: Thomas Wood <thos gnome org>
Date:   Sat Nov 7 12:18:10 2009 +0000

    Add MnWidget
    
    MnWidget is the base type for all widgets options. The object has the
    properties that are required to draw a very basic widget. Further
    properties can be added by subclassing MnWidget.

 monet/Makefile.am |    2 +
 monet/mn-widget.c |  145 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 monet/mn-widget.h |   54 ++++++++++++++++++++
 3 files changed, 201 insertions(+), 0 deletions(-)
---
diff --git a/monet/Makefile.am b/monet/Makefile.am
index be23e80..de70d3e 100644
--- a/monet/Makefile.am
+++ b/monet/Makefile.am
@@ -16,6 +16,7 @@ source_h = \
 	mn-palette.h \
 	mn-parts.h \
 	mn-types.h \
+	mn-widget.h \
 	monet.h
 
 source_h_priv = mn-private.h
@@ -71,6 +72,7 @@ libmonet_la_SOURCES = \
 	$(source_h_priv) \
 	mn-color.c	 \
 	mn-palette.c	 \
+	mn-widget.c	 \
 	monet.c
 
 libmonet_la_LIBADD = $(MONET_LIBS)
diff --git a/monet/mn-widget.c b/monet/mn-widget.c
new file mode 100644
index 0000000..57b68b5
--- /dev/null
+++ b/monet/mn-widget.c
@@ -0,0 +1,145 @@
+/* mn-widget.c */
+
+#include "mn-widget.h"
+#include "mn-palette.h"
+#include "mn-color.h"
+
+G_DEFINE_TYPE (MnWidget, mn_widget, G_TYPE_OBJECT)
+
+#define WIDGET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), MN_TYPE_WIDGET, MnWidgetPrivate))
+
+struct _MnWidgetPrivate
+{
+  MnRectangle *area;
+  MnPalette   *palette;
+  MnBorder    *border;
+  MnState      state;
+};
+
+enum
+{
+  PROP_AREA,
+  PROP_STATE,
+  PROP_BORDER,
+  PROP_PALETTE
+};
+
+static void
+mn_widget_get_property (GObject    *object,
+                        guint       property_id,
+                        GValue     *value,
+                        GParamSpec *pspec)
+{
+  MnWidgetPrivate *priv = MN_WIDGET (object)->priv;
+
+  switch (property_id)
+    {
+    case PROP_AREA:
+      g_value_set_boxed (value, priv->area);
+      break;
+
+    case PROP_STATE:
+      g_value_set_enum (value, priv->state);
+      break;
+
+    case PROP_BORDER:
+      g_value_set_boxed (value, priv->border);
+      break;
+
+    case PROP_PALETTE:
+      g_value_set_pointer (value, priv->palette);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+mn_widget_set_property (GObject      *object,
+                        guint         property_id,
+                        const GValue *value,
+                        GParamSpec   *pspec)
+{
+  MnWidgetPrivate *priv = MN_WIDGET (object)->priv;
+
+  switch (property_id)
+    {
+    case PROP_AREA:
+      priv->area = g_value_get_boxed (value);
+      break;
+
+    case PROP_STATE:
+      priv->state = g_value_get_enum (value);
+      break;
+
+    case PROP_BORDER:
+      priv->border = g_value_get_boxed (value);
+      break;
+
+    case PROP_PALETTE:
+      priv->palette = g_value_get_boxed (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+mn_widget_dispose (GObject *object)
+{
+  G_OBJECT_CLASS (mn_widget_parent_class)->dispose (object);
+}
+
+static void
+mn_widget_finalize (GObject *object)
+{
+  MnWidgetPrivate *priv = MN_WIDGET (object)->priv;
+
+  if (priv->area)
+    {
+      g_free (priv->area);
+      priv->area = NULL;
+    }
+
+  if (priv->palette)
+    {
+      mn_palette_free (priv->palette);
+      priv->palette = NULL;
+    }
+
+  if (priv->border)
+    {
+      g_free (priv->border);
+      priv->border = NULL;
+    }
+
+  G_OBJECT_CLASS (mn_widget_parent_class)->finalize (object);
+}
+
+static void
+mn_widget_class_init (MnWidgetClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (MnWidgetPrivate));
+
+  object_class->get_property = mn_widget_get_property;
+  object_class->set_property = mn_widget_set_property;
+  object_class->dispose = mn_widget_dispose;
+  object_class->finalize = mn_widget_finalize;
+}
+
+static void
+mn_widget_init (MnWidget *self)
+{
+  self->priv = WIDGET_PRIVATE (self);
+}
+
+MnWidget *
+mn_widget_new (void)
+{
+  return g_object_new (MN_TYPE_WIDGET, NULL);
+}
diff --git a/monet/mn-widget.h b/monet/mn-widget.h
new file mode 100644
index 0000000..9bb27c4
--- /dev/null
+++ b/monet/mn-widget.h
@@ -0,0 +1,54 @@
+/* mn-widget.h */
+
+#ifndef _MN_WIDGET_H
+#define _MN_WIDGET_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MN_TYPE_WIDGET mn_widget_get_type()
+
+#define MN_WIDGET(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+  MN_TYPE_WIDGET, MnWidget))
+
+#define MN_WIDGET_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+  MN_TYPE_WIDGET, MnWidgetClass))
+
+#define MN_IS_WIDGET(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+  MN_TYPE_WIDGET))
+
+#define MN_IS_WIDGET_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+  MN_TYPE_WIDGET))
+
+#define MN_WIDGET_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+  MN_TYPE_WIDGET, MnWidgetClass))
+
+typedef struct _MnWidget MnWidget;
+typedef struct _MnWidgetClass MnWidgetClass;
+typedef struct _MnWidgetPrivate MnWidgetPrivate;
+
+struct _MnWidget
+{
+  GObject parent;
+
+  MnWidgetPrivate *priv;
+};
+
+struct _MnWidgetClass
+{
+  GObjectClass parent_class;
+};
+
+GType mn_widget_get_type (void) G_GNUC_CONST;
+
+MnWidget *mn_widget_new (void);
+
+G_END_DECLS
+
+#endif /* _MN_WIDGET_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]