[monet/monet-xml] Use a single entry point for simple widgets



commit 880d61403c66bcbe234fa991c8acbc5e4ab402e4
Author: Thomas Wood <thos gnome org>
Date:   Sun Jul 25 17:07:49 2010 +0100

    Use a single entry point for simple widgets

 monet-gtk/style.c |   36 ++++++-----
 monet/mn-config.h |   10 +++-
 monet/mn-style.c  |  132 +----------------------------------------
 monet/mn-style.h  |  168 ++++-------------------------------------------------
 4 files changed, 42 insertions(+), 304 deletions(-)
---
diff --git a/monet-gtk/style.c b/monet-gtk/style.c
index bd70983..0921c6e 100644
--- a/monet-gtk/style.c
+++ b/monet-gtk/style.c
@@ -224,8 +224,8 @@ monet_gtk_draw_shadow (GtkStyle      *style,
 
   if (DETAIL ("entry"))
     {
-      mn_style_paint_entry (mn_style, cr, x, y, width, height, mn_palette,
-                            mn_state, mn_flags);
+      mn_style_paint_widget (mn_style, MN_ENTRY, cr, x, y, width, height,
+                             mn_palette, mn_state, mn_flags);
     }
   else
     monet_gtk_style_parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
@@ -273,6 +273,7 @@ monet_gtk_draw_box (GtkStyle      *style,
   MnFlags mn_flags;
   MnStyle *mn_style;
   gint int_w, int_h;
+  MnWidget mn_widget;
 
   monet_params_init (style, window, state_type, widget,
                      &mn_style, &cr, &mn_state, &mn_flags, &mn_palette);
@@ -284,30 +285,33 @@ monet_gtk_draw_box (GtkStyle      *style,
       height = int_h;
     }
 
+  mn_widget = MN_WIDGET_INVALID;
+
   if (DETAIL ("button"))
     {
-      mn_style_paint_button (mn_style, cr, x, y, width, height, mn_palette,
-                             mn_state, mn_flags);
+      mn_widget = MN_BUTTON;
     }
   else if (DETAIL ("menu"))
     {
-      mn_style_paint_menu (mn_style, cr, x, y, width, height, mn_palette,
-                           mn_state, mn_flags);
+      mn_widget = MN_MENU;
     }
   else if (DETAIL ("menuitem"))
     {
-      mn_style_paint_menu_item (mn_style, cr, x, y, width, height, mn_palette,
-                                mn_state, mn_flags);
+      mn_widget = MN_MENU_ITEM;
     }
   else if (DETAIL ("menubar"))
     {
-      mn_style_paint_menu_bar (mn_style, cr, x, y, width, height, mn_palette,
-                               mn_state, mn_flags);
+      mn_widget = MN_MENU_BAR;
     }
   else if (DETAIL ("toolbar"))
     {
-      mn_style_paint_tool_bar (mn_style, cr, x, y, width, height, mn_palette,
-                               mn_state, mn_flags);
+      mn_widget = MN_TOOL_BAR;
+    }
+
+  if (mn_widget != MN_WIDGET_INVALID)
+    {
+      mn_style_paint_widget (mn_style, mn_widget, cr, x, y, width, height,
+                             mn_palette, mn_state, mn_flags);
     }
   else
     {
@@ -365,8 +369,8 @@ monet_gtk_draw_check (GtkStyle      *style,
   if (shadow_type == GTK_SHADOW_IN)
     mn_flags |= MN_FLAGS_CHECKED;
 
-  mn_style_paint_check_box (mn_style, cr, x, y, width, height, mn_palette,
-                            mn_state, mn_flags);
+  mn_style_paint_widget (mn_style, MN_CHECK, cr, x, y, width, height,
+                         mn_palette, mn_state, mn_flags);
 
   cairo_destroy (cr);
 }
@@ -397,8 +401,8 @@ monet_gtk_draw_option (GtkStyle      *style,
   if (shadow_type == GTK_SHADOW_IN)
     mn_flags |= MN_FLAGS_CHECKED;
 
-  mn_style_paint_radio_button (mn_style, cr, x, y, width, height, mn_palette,
-                               mn_state, mn_flags);
+  mn_style_paint_widget (mn_style, MN_RADIO, cr, x, y, width, height,
+                         mn_palette, mn_state, mn_flags);
 
   cairo_destroy (cr);
 }
diff --git a/monet/mn-config.h b/monet/mn-config.h
index 69f4e8f..27a8ce5 100644
--- a/monet/mn-config.h
+++ b/monet/mn-config.h
@@ -19,6 +19,9 @@
  * Author: Thomas Wood <thos gnome org>
  */
 
+#ifndef MN_CONFIG_H
+#define MN_CONFIG_H
+
 #include <glib.h>
 #include <glib-object.h>
 #include <cairo/cairo.h>
@@ -53,8 +56,9 @@ typedef struct _MnConfigPrivate MnConfigPrivate;
 
 typedef GSList *MnDrawingOps[4];
 
-enum
+typedef enum
 {
+  MN_WIDGET_INVALID = -1,
   MN_BUTTON,
   MN_ENTRY,
   MN_CHECK,
@@ -65,7 +69,7 @@ enum
   MN_TOOL_BAR,
 
   MN_WIDGET_LAST
-};
+} MnWidget;
 
 struct _MnConfig
 {
@@ -147,3 +151,5 @@ gboolean mn_config_load_from_file (MnConfig     *config,
                                    GError      **err);
 
 G_END_DECLS
+
+#endif /* MN_CONFIG_H */
diff --git a/monet/mn-style.c b/monet/mn-style.c
index ee4b954..e48589e 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -323,25 +323,8 @@ mn_style_draw_ops (MnStyle   *style,
 }
 
 void
-mn_style_paint_entry (MnStyle   *style,
-                      cairo_t   *cr,
-                      gdouble    x,
-                      gdouble    y,
-                      gdouble    width,
-                      gdouble    height,
-                      MnPalette *colors,
-                      MnState    state,
-                      MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_ENTRY];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_button (MnStyle   *style,
+mn_style_paint_widget (MnStyle   *style,
+                       MnWidget   widget,
                        cairo_t   *cr,
                        gdouble    x,
                        gdouble    y,
@@ -353,116 +336,7 @@ mn_style_paint_button (MnStyle   *style,
 {
   GSList **ops;
 
-  ops = style->priv->config->widget_ops[MN_BUTTON];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_check_box (MnStyle   *style,
-                          cairo_t   *cr,
-                          gdouble    x,
-                          gdouble    y,
-                          gdouble    width,
-                          gdouble    height,
-                          MnPalette *colors,
-                          MnState    state,
-                          MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_CHECK];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_radio_button (MnStyle   *style,
-                             cairo_t   *cr,
-                             gdouble    x,
-                             gdouble    y,
-                             gdouble    width,
-                             gdouble    height,
-                             MnPalette *colors,
-                             MnState    state,
-                             MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_MENU];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-
-void
-mn_style_paint_menu (MnStyle   *style,
-                     cairo_t   *cr,
-                     gdouble    x,
-                     gdouble    y,
-                     gdouble    width,
-                     gdouble    height,
-                     MnPalette *colors,
-                     MnState    state,
-                     MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_MENU];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_menu_item (MnStyle   *style,
-                          cairo_t   *cr,
-                          gdouble    x,
-                          gdouble    y,
-                          gdouble    width,
-                          gdouble    height,
-                          MnPalette *colors,
-                          MnState    state,
-                          MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_MENU_ITEM];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_menu_bar (MnStyle   *style,
-                         cairo_t   *cr,
-                         gdouble    x,
-                         gdouble    y,
-                         gdouble    width,
-                         gdouble    height,
-                         MnPalette *colors,
-                         MnState    state,
-                         MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_MENU_BAR];
-
-  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
-}
-
-void
-mn_style_paint_tool_bar (MnStyle   *style,
-                         cairo_t   *cr,
-                         gdouble    x,
-                         gdouble    y,
-                         gdouble    width,
-                         gdouble    height,
-                         MnPalette *colors,
-                         MnState    state,
-                         MnFlags    flags)
-{
-  GSList **ops;
-
-  ops = style->priv->config->widget_ops[MN_TOOL_BAR];
+  ops = style->priv->config->widget_ops[widget];
 
   mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
diff --git a/monet/mn-style.h b/monet/mn-style.h
index c748289..fa82832 100644
--- a/monet/mn-style.h
+++ b/monet/mn-style.h
@@ -25,6 +25,7 @@
 #define _MN_STYLE_H
 
 #include "mn-palette.h"
+#include "mn-config.h"
 #include <glib-object.h>
 
 G_BEGIN_DECLS
@@ -65,81 +66,6 @@ struct _MnStyle
 struct _MnStyleClass
 {
   GObjectClass parent_class;
-
-  void (*mn_style_paint_entry)        (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_button)       (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_menu)         (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_menu_bar)     (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_menu_item)    (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_radio_button) (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_check_box)    (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-  void (*mn_style_paint_scroll_bar)   (MnStyle *style,
-                                       cairo_t   *cr,
-                                       gdouble    x,
-                                       gdouble    y,
-                                       gdouble    width,
-                                       gdouble    height,
-                                       MnPalette *colors,
-                                       MnState    state,
-                                       MnFlags    flags);
-
-
 };
 
 GType mn_style_get_type (void) G_GNUC_CONST;
@@ -151,88 +77,16 @@ gboolean mn_style_load_config    (MnStyle      *style,
                                   GError      **error);
 
 
-void mn_style_paint_entry        (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_button       (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_menu         (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_menu_bar     (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_menu_item    (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_radio_button (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_check_box    (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-void mn_style_paint_scroll_bar   (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
-
-void mn_style_paint_tool_bar     (MnStyle *style,
-                                  cairo_t   *cr,
-                                  gdouble    x,
-                                  gdouble    y,
-                                  gdouble    width,
-                                  gdouble    height,
-                                  MnPalette *colors,
-                                  MnState    state,
-                                  MnFlags    flags);
+void mn_style_paint_widget (MnStyle   *style,
+                            MnWidget   widget,
+                            cairo_t   *cr,
+                            gdouble    x,
+                            gdouble    y,
+                            gdouble    width,
+                            gdouble    height,
+                            MnPalette *colors,
+                            MnState    state,
+                            MnFlags    flags);
 
 
 G_END_DECLS



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