[gtk+/gtk-2-24] pixbuf-engine: add a GtkRC option for widget direction



commit 85f2a721cfae94ed9497c56a72b3dce0677f4317
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Jul 5 10:08:10 2012 -0400

    pixbuf-engine: add a GtkRC option for widget direction
    
    Add a GtkRC option to select for an LTR/RTL widget direction in the
    pixbuf engine; this will allow the engine to apply different theming
    assets according to the text direction, which is useful when theming
    e.g. a spinbutton or a combobox entry.

 modules/engines/pixbuf/pixbuf-draw.c     |   12 +++++++++-
 modules/engines/pixbuf/pixbuf-rc-style.c |   37 +++++++++++++++++++++++++++++-
 modules/engines/pixbuf/pixbuf.h          |    9 +++++-
 3 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c
index 38f2761..9239bd1 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -72,6 +72,10 @@ match_theme_image (GtkStyle       *style,
 	  match_data->orientation != image->match_data.orientation)
 	continue;
 
+      if ((flags & THEME_MATCH_DIRECTION) &&
+	  match_data->direction != image->match_data.direction)
+	continue;
+
       if ((flags & THEME_MATCH_GAP_SIDE) &&
 	  match_data->gap_side != image->match_data.gap_side)
 	continue;
@@ -126,7 +130,13 @@ draw_simple_image(GtkStyle       *style,
       else
 	match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
     }
-    
+
+  if (!(match_data->flags & THEME_MATCH_DIRECTION))
+    {
+      match_data->flags |= THEME_MATCH_DIRECTION;
+      match_data->direction = gtk_widget_get_direction (widget);
+    }
+
   image = match_theme_image (style, match_data);
   if (image)
     {
diff --git a/modules/engines/pixbuf/pixbuf-rc-style.c b/modules/engines/pixbuf/pixbuf-rc-style.c
index a3367c4..3597087 100644
--- a/modules/engines/pixbuf/pixbuf-rc-style.c
+++ b/modules/engines/pixbuf/pixbuf-rc-style.c
@@ -64,6 +64,7 @@ theme_symbols[] =
   { "overlay_stretch", 	TOKEN_OVERLAY_STRETCH },
   { "arrow_direction", 	TOKEN_ARROW_DIRECTION },
   { "orientation", 	TOKEN_ORIENTATION },
+  { "direction", 	TOKEN_DIRECTION },
   { "expander_style",	TOKEN_EXPANDER_STYLE },
   { "window_edge",	TOKEN_WINDOW_EDGE },
 
@@ -130,7 +131,10 @@ theme_symbols[] =
   { "EAST",		TOKEN_EAST },
   { "SOUTH_WEST",	TOKEN_SOUTH_WEST },
   { "SOUTH",		TOKEN_SOUTH },
-  { "SOUTH_EAST",	TOKEN_SOUTH_EAST }
+  { "SOUTH_EAST",	TOKEN_SOUTH_EAST },
+
+  { "LTR",              TOKEN_LTR },
+  { "RTL",              TOKEN_RTL }
 };
 
 static GtkRcStyleClass *parent_class;
@@ -609,6 +613,34 @@ theme_parse_window_edge(GScanner * scanner,
   return G_TOKEN_NONE;
 }
 
+static guint
+theme_parse_direction(GScanner * scanner,
+                      ThemeImage * data)
+{
+  guint               token;
+
+  token = g_scanner_get_next_token(scanner);
+  if (token != TOKEN_DIRECTION)
+    return TOKEN_DIRECTION;
+
+  token = g_scanner_get_next_token(scanner);
+  if (token != G_TOKEN_EQUAL_SIGN)
+    return G_TOKEN_EQUAL_SIGN;
+
+  token = g_scanner_get_next_token(scanner);
+
+  if (token == TOKEN_LTR)
+    data->match_data.direction = GTK_TEXT_DIR_LTR;
+  else if (token == TOKEN_RTL)
+    data->match_data.direction = GTK_TEXT_DIR_RTL;
+  else
+    return TOKEN_LTR;
+
+  data->match_data.flags |= THEME_MATCH_DIRECTION;
+  
+  return G_TOKEN_NONE;
+}
+
 static void
 theme_image_ref (ThemeImage *data)
 {
@@ -741,6 +773,9 @@ theme_parse_image(GtkSettings  *settings,
 	case TOKEN_WINDOW_EDGE:
 	  token = theme_parse_window_edge(scanner, data);
 	  break;
+        case TOKEN_DIRECTION:
+          token = theme_parse_direction(scanner, data);
+          break;
 	default:
 	  g_scanner_get_next_token(scanner);
 	  token = G_TOKEN_RIGHT_CURLY;
diff --git a/modules/engines/pixbuf/pixbuf.h b/modules/engines/pixbuf/pixbuf.h
index 77e19d4..d0c74e9 100644
--- a/modules/engines/pixbuf/pixbuf.h
+++ b/modules/engines/pixbuf/pixbuf.h
@@ -111,7 +111,10 @@ enum
   TOKEN_EAST,
   TOKEN_SOUTH_WEST,
   TOKEN_SOUTH,
-  TOKEN_SOUTH_EAST
+  TOKEN_SOUTH_EAST,
+  TOKEN_DIRECTION,
+  TOKEN_LTR,
+  TOKEN_RTL
 };
 
 typedef enum
@@ -135,7 +138,8 @@ typedef enum {
   THEME_MATCH_SHADOW          = 1 << 3,
   THEME_MATCH_ARROW_DIRECTION = 1 << 4,
   THEME_MATCH_EXPANDER_STYLE  = 1 << 5,
-  THEME_MATCH_WINDOW_EDGE     = 1 << 6
+  THEME_MATCH_WINDOW_EDGE     = 1 << 6,
+  THEME_MATCH_DIRECTION       = 1 << 7
 } ThemeMatchFlags;
 
 typedef enum {
@@ -170,6 +174,7 @@ struct _ThemeMatchData
   GtkArrowType     arrow_direction;
   GtkExpanderStyle expander_style;
   GdkWindowEdge    window_edge;
+  GtkTextDirection direction;
 };
 
 struct _ThemeImage



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