[metacity] theme: move meta_frame_style_validate to libmetacity



commit 348379bdb230b61599a6de2ef1eff9e0c55d7737
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jan 31 20:51:11 2016 +0200

    theme: move meta_frame_style_validate to libmetacity

 libmetacity/meta-frame-style.c |  170 ++++++++++++++++++++++++++++++++++++++++
 libmetacity/meta-frame-style.h |    4 +
 src/ui/theme.c                 |  161 +-------------------------------------
 3 files changed, 175 insertions(+), 160 deletions(-)
---
diff --git a/libmetacity/meta-frame-style.c b/libmetacity/meta-frame-style.c
index 2e96dbe..ccbb094 100644
--- a/libmetacity/meta-frame-style.c
+++ b/libmetacity/meta-frame-style.c
@@ -148,6 +148,78 @@ check_state  (MetaFrameStyleSet  *style_set,
   return TRUE;
 }
 
+static const char*
+meta_button_type_to_string (MetaButtonType type)
+{
+  switch (type)
+    {
+      case META_BUTTON_TYPE_CLOSE:
+        return "close";
+      case META_BUTTON_TYPE_MAXIMIZE:
+        return "maximize";
+      case META_BUTTON_TYPE_MINIMIZE:
+        return "minimize";
+      case META_BUTTON_TYPE_SHADE:
+       return "shade";
+      case META_BUTTON_TYPE_ABOVE:
+        return "above";
+      case META_BUTTON_TYPE_STICK:
+        return "stick";
+      case META_BUTTON_TYPE_UNSHADE:
+        return "unshade";
+      case META_BUTTON_TYPE_UNABOVE:
+        return "unabove";
+      case META_BUTTON_TYPE_UNSTICK:
+        return "unstick";
+      case META_BUTTON_TYPE_MENU:
+        return "menu";
+      case META_BUTTON_TYPE_APPMENU:
+        return "appmenu";
+      case META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND:
+        return "left_left_background";
+      case META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND:
+        return "left_middle_background";
+      case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND:
+        return "left_right_background";
+      case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
+        return "left_single_background";
+      case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
+        return "right_left_background";
+      case META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND:
+        return "right_middle_background";
+      case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND:
+        return "right_right_background";
+      case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
+        return "right_single_background";
+      case META_BUTTON_TYPE_LAST:
+        break;
+      default:
+        break;
+    }
+
+  return "<unknown>";
+}
+
+static const char*
+meta_button_state_to_string (MetaButtonState state)
+{
+  switch (state)
+    {
+      case META_BUTTON_STATE_NORMAL:
+        return "normal";
+      case META_BUTTON_STATE_PRESSED:
+        return "pressed";
+      case META_BUTTON_STATE_PRELIGHT:
+        return "prelight";
+      case META_BUTTON_STATE_LAST:
+        break;
+      default:
+        break;
+    }
+
+  return "<unknown>";
+}
+
 /**
  * Constructor for a MetaFrameStyle.
  *
@@ -232,6 +304,104 @@ meta_frame_style_apply_scale (const MetaFrameStyle *style,
   pango_font_description_set_size (font_desc, MAX (size * scale, 1));
 }
 
+gboolean
+meta_frame_style_validate (MetaFrameStyle  *style,
+                           guint            current_theme_version,
+                           GError         **error)
+{
+  int i, j;
+
+  g_return_val_if_fail (style != NULL, FALSE);
+  g_return_val_if_fail (style->layout != NULL, FALSE);
+
+  for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
+    {
+      /* for now the "positional" buttons are optional */
+      if (i >= META_BUTTON_TYPE_CLOSE)
+        {
+          for (j = 0; j < META_BUTTON_STATE_LAST; j++)
+            {
+              guint earliest_version;
+
+              earliest_version = meta_theme_metacity_earliest_version_with_button (i);
+
+              if (meta_frame_style_get_button (style, i, j) == NULL &&
+                  earliest_version <= current_theme_version)
+                {
+                  g_set_error (error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
+                               _("<button function='%s' state='%s' draw_ops='whatever'/> must be specified 
for this frame style"),
+                               meta_button_type_to_string (i),
+                               meta_button_state_to_string (j));
+                  return FALSE;
+                }
+            }
+        }
+    }
+
+  return TRUE;
+}
+
+MetaDrawOpList *
+meta_frame_style_get_button (MetaFrameStyle  *style,
+                             MetaButtonType   type,
+                             MetaButtonState  state)
+{
+  MetaDrawOpList *op_list;
+  MetaFrameStyle *parent;
+
+  parent = style;
+  op_list = NULL;
+
+  while (parent && op_list == NULL)
+    {
+      op_list = parent->buttons[type][state];
+      parent = parent->parent;
+    }
+
+  /* We fall back to the side buttons if we don't have
+   * single button backgrounds, and to middle button
+   * backgrounds if we don't have the ones on the sides
+   */
+
+  if (op_list == NULL && type == META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND)
+    {
+      return meta_frame_style_get_button (style,
+                                          META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND,
+                                          state);
+    }
+
+  if (op_list == NULL && type == META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND)
+    {
+      return meta_frame_style_get_button (style,
+                                          META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND,
+                                          state);
+    }
+
+  if (op_list == NULL &&
+      (type == META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND ||
+       type == META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND))
+    {
+      return meta_frame_style_get_button (style,
+                                          META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND,
+                                          state);
+    }
+
+  if (op_list == NULL &&
+      (type == META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND ||
+       type == META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND))
+    {
+      return meta_frame_style_get_button (style,
+                                          META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND,
+                                          state);
+    }
+
+  /* We fall back to normal if no prelight */
+  if (op_list == NULL && state == META_BUTTON_STATE_PRELIGHT)
+    return meta_frame_style_get_button (style, type, META_BUTTON_STATE_NORMAL);
+
+  return op_list;
+}
+
 MetaFrameStyleSet *
 meta_frame_style_set_new (MetaFrameStyleSet *parent)
 {
diff --git a/libmetacity/meta-frame-style.h b/libmetacity/meta-frame-style.h
index 06f8079..43db415 100644
--- a/libmetacity/meta-frame-style.h
+++ b/libmetacity/meta-frame-style.h
@@ -102,6 +102,10 @@ gboolean           meta_frame_style_validate      (MetaFrameStyle        *style,
                                                    guint                  current_theme_version,
                                                    GError               **error);
 
+MetaDrawOpList    *meta_frame_style_get_button    (MetaFrameStyle        *style,
+                                                   MetaButtonType         type,
+                                                   MetaButtonState        state);
+
 MetaFrameStyleSet *meta_frame_style_set_new       (MetaFrameStyleSet     *parent);
 
 void               meta_frame_style_set_ref       (MetaFrameStyleSet     *style_set);
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 1bbc7e5..39c3025 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -994,165 +994,6 @@ map_button_state (MetaButtonType           button_type,
   return META_BUTTON_STATE_LAST;
 }
 
-static MetaDrawOpList*
-get_button (MetaFrameStyle *style,
-            MetaButtonType  type,
-            MetaButtonState state)
-{
-  MetaDrawOpList *op_list;
-  MetaFrameStyle *parent;
-
-  parent = style;
-  op_list = NULL;
-  while (parent && op_list == NULL)
-    {
-      op_list = parent->buttons[type][state];
-      parent = parent->parent;
-    }
-
-  /* We fall back to the side buttons if we don't have
-   * single button backgrounds, and to middle button
-   * backgrounds if we don't have the ones on the sides
-   */
-
-  if (op_list == NULL &&
-      type == META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND)
-    return get_button (style, META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND, state);
-
-  if (op_list == NULL &&
-      type == META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND)
-    return get_button (style, META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND, state);
-
-  if (op_list == NULL &&
-      (type == META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND ||
-       type == META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND))
-    return get_button (style, META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND,
-                       state);
-
-  if (op_list == NULL &&
-      (type == META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND ||
-       type == META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND))
-    return get_button (style, META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND,
-                       state);
-
-  /* We fall back to normal if no prelight */
-  if (op_list == NULL &&
-      state == META_BUTTON_STATE_PRELIGHT)
-    return get_button (style, type, META_BUTTON_STATE_NORMAL);
-
-  return op_list;
-}
-
-static const char*
-meta_button_type_to_string (MetaButtonType type)
-{
-  switch (type)
-    {
-    case META_BUTTON_TYPE_CLOSE:
-      return "close";
-    case META_BUTTON_TYPE_MAXIMIZE:
-      return "maximize";
-    case META_BUTTON_TYPE_MINIMIZE:
-      return "minimize";
-    case META_BUTTON_TYPE_SHADE:
-     return "shade";
-    case META_BUTTON_TYPE_ABOVE:
-      return "above";
-    case META_BUTTON_TYPE_STICK:
-      return "stick";
-    case META_BUTTON_TYPE_UNSHADE:
-      return "unshade";
-    case META_BUTTON_TYPE_UNABOVE:
-      return "unabove";
-    case META_BUTTON_TYPE_UNSTICK:
-      return "unstick";
-    case META_BUTTON_TYPE_MENU:
-      return "menu";
-    case META_BUTTON_TYPE_APPMENU:
-      return "appmenu";
-    case META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND:
-      return "left_left_background";
-    case META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND:
-      return "left_middle_background";
-    case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND:
-      return "left_right_background";
-    case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
-      return "left_single_background";
-    case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
-      return "right_left_background";
-    case META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND:
-      return "right_middle_background";
-    case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND:
-      return "right_right_background";
-    case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
-      return "right_single_background";
-    case META_BUTTON_TYPE_LAST:
-      break;
-    default:
-      break;
-    }
-
-  return "<unknown>";
-}
-
-static const char*
-meta_button_state_to_string (MetaButtonState state)
-{
-  switch (state)
-    {
-    case META_BUTTON_STATE_NORMAL:
-      return "normal";
-    case META_BUTTON_STATE_PRESSED:
-      return "pressed";
-    case META_BUTTON_STATE_PRELIGHT:
-      return "prelight";
-    case META_BUTTON_STATE_LAST:
-      break;
-    default:
-      break;
-    }
-
-  return "<unknown>";
-}
-
-gboolean
-meta_frame_style_validate (MetaFrameStyle    *style,
-                           guint              current_theme_version,
-                           GError           **error)
-{
-  int i, j;
-
-  g_return_val_if_fail (style != NULL, FALSE);
-  g_return_val_if_fail (style->layout != NULL, FALSE);
-
-  for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
-    {
-      /* for now the "positional" buttons are optional */
-      if (i >= META_BUTTON_TYPE_CLOSE)
-        {
-          for (j = 0; j < META_BUTTON_STATE_LAST; j++)
-            {
-              guint earliest_version;
-
-              earliest_version = meta_theme_metacity_earliest_version_with_button (i);
-
-              if (get_button (style, i, j) == NULL &&
-                  earliest_version <= current_theme_version)
-                {
-                  g_set_error (error, META_THEME_ERROR,
-                               META_THEME_ERROR_FAILED,
-                               _("<button function=\"%s\" state=\"%s\" draw_ops=\"whatever\"/> must be 
specified for this frame style"),
-                               meta_button_type_to_string (i),
-                               meta_button_state_to_string (j));
-                  return FALSE;
-                }
-            }
-        }
-    }
-
-  return TRUE;
-}
-
 static void
 get_button_rect (MetaButtonType           type,
                  const MetaFrameGeometry *fgeom,
@@ -1439,7 +1280,7 @@ meta_frame_style_draw_with_style (MetaFrameStyle          *style,
               get_button_rect (j, fgeom, middle_bg_offset, &rect);
 
               button_state = map_button_state (j, fgeom, middle_bg_offset, button_states);
-              op_list = get_button (style, j, button_state);
+              op_list = meta_frame_style_get_button (style, j, button_state);
 
               if (op_list)
                 {


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