summaryrefslogtreecommitdiff
path: root/src/theme-parser.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2002-06-04 02:13:00 +0000
committerHavoc Pennington <hp@src.gnome.org>2002-06-04 02:13:00 +0000
commit85815f8188ef0dacf3779b2b6c89e42ba484047f (patch)
tree4552ad9eb8c426b299fa2817e8914faf1f7b24ed /src/theme-parser.c
parent22bbeb0ae08318780ece7744addfcc8e22ddf223 (diff)
downloadmetacity-85815f8188ef0dacf3779b2b6c89e42ba484047f.tar.gz
metacity-85815f8188ef0dacf3779b2b6c89e42ba484047f.tar.bz2
test button aspect ratio instead of hardcoded button size, James feel free
2002-06-03 Havoc Pennington <hp@pobox.com> * src/themes/Esco/metacity-theme-1.xml: test button aspect ratio instead of hardcoded button size, James feel free to revert if you don't like it this way. * src/theme-parser.c: parse the aspect_ratio element for button aspect ratios. * src/theme.h (struct _MetaFrameLayout): allow button sizes to be given as an aspect ratio derived from the titlebar height, instead of as a fixed size. * src/theme.c (meta_frame_layout_validate): validate new button sizing parameters * src/theme.c (meta_frame_layout_calc_geometry): use new button layout params
Diffstat (limited to 'src/theme-parser.c')
-rw-r--r--src/theme-parser.c106
1 files changed, 103 insertions, 3 deletions
diff --git a/src/theme-parser.c b/src/theme-parser.c
index ba686f9..5eafc74 100644
--- a/src/theme-parser.c
+++ b/src/theme-parser.c
@@ -42,6 +42,7 @@ typedef enum
STATE_FRAME_GEOMETRY,
STATE_DISTANCE,
STATE_BORDER,
+ STATE_ASPECT_RATIO,
/* draw ops */
STATE_DRAW_OPS,
STATE_LINE,
@@ -1309,9 +1310,92 @@ parse_distance (GMarkupParseContext *context,
else if (strcmp (name, "left_titlebar_edge") == 0)
info->layout->left_titlebar_edge = val;
else if (strcmp (name, "button_width") == 0)
- info->layout->button_width = val;
+ {
+ info->layout->button_width = val;
+
+ if (!(info->layout->button_sizing == META_BUTTON_SIZING_LAST ||
+ info->layout->button_sizing == META_BUTTON_SIZING_FIXED))
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("Cannot specify both button_width/button_height and aspect ratio for buttons"));
+ return;
+ }
+
+ info->layout->button_sizing = META_BUTTON_SIZING_FIXED;
+ }
else if (strcmp (name, "button_height") == 0)
- info->layout->button_height = val;
+ {
+ info->layout->button_height = val;
+
+ if (!(info->layout->button_sizing == META_BUTTON_SIZING_LAST ||
+ info->layout->button_sizing == META_BUTTON_SIZING_FIXED))
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("Cannot specify both button_width/button_height and aspect ratio for buttons"));
+ return;
+ }
+
+ info->layout->button_sizing = META_BUTTON_SIZING_FIXED;
+ }
+ else
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("Distance \"%s\" is unknown"), name);
+ return;
+ }
+}
+
+static void
+parse_aspect_ratio (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ ParseInfo *info,
+ GError **error)
+{
+ const char *name;
+ const char *value;
+ double val;
+
+ if (!locate_attributes (context, element_name, attribute_names, attribute_values,
+ error,
+ "name", &name, "value", &value,
+ NULL))
+ return;
+
+ if (name == NULL)
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("No \"name\" attribute on element <%s>"), element_name);
+ return;
+ }
+
+ if (value == NULL)
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("No \"value\" attribute on element <%s>"), element_name);
+ return;
+ }
+
+ val = 0;
+ if (!parse_double (value, &val, context, error))
+ return;
+
+ g_assert (info->layout);
+
+ if (strcmp (name, "button") == 0)
+ {
+ info->layout->button_aspect = val;
+
+ if (info->layout->button_sizing != META_BUTTON_SIZING_LAST)
+ {
+ set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ _("Cannot specify both button_width/button_height and aspect ratio for buttons"));
+ return;
+ }
+
+ info->layout->button_sizing = META_BUTTON_SIZING_ASPECT;
+ }
else
{
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
@@ -1446,6 +1530,14 @@ parse_geometry_element (GMarkupParseContext *context,
info, error);
push_state (info, STATE_BORDER);
}
+ else if (ELEMENT_IS ("aspect_ratio"))
+ {
+ parse_aspect_ratio (context, element_name,
+ attribute_names, attribute_values,
+ info, error);
+
+ push_state (info, STATE_ASPECT_RATIO);
+ }
else
{
set_error (error, context,
@@ -3535,8 +3627,9 @@ start_element_handler (GMarkupParseContext *context,
break;
case STATE_DISTANCE:
case STATE_BORDER:
+ case STATE_ASPECT_RATIO:
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
- _("Element <%s> is not allowed inside a distance/border element"),
+ _("Element <%s> is not allowed inside a distance/border/aspect_ratio element"),
element_name);
break;
case STATE_DRAW_OPS:
@@ -3687,6 +3780,10 @@ end_element_handler (GMarkupParseContext *context,
pop_state (info);
g_assert (peek_state (info) == STATE_FRAME_GEOMETRY);
break;
+ case STATE_ASPECT_RATIO:
+ pop_state (info);
+ g_assert (peek_state (info) == STATE_FRAME_GEOMETRY);
+ break;
case STATE_DRAW_OPS:
{
g_assert (info->op_list);
@@ -4007,6 +4104,9 @@ text_handler (GMarkupParseContext *context,
case STATE_BORDER:
NO_TEXT ("border");
break;
+ case STATE_ASPECT_RATIO:
+ NO_TEXT ("aspect_ratio");
+ break;
case STATE_DRAW_OPS:
NO_TEXT ("draw_ops");
break;