[gtk+] Fix GtkEntry drawing to provide visual feedback when editable=FALSE.



commit a864f9d052aa66430b5db572b9bb740b5beeb9a8
Author: David Trowbridge <trowbrds gmail com>
Date:   Mon Aug 19 13:41:39 2013 -0400

    Fix GtkEntry drawing to provide visual feedback when editable=FALSE.
    
    GtkEntry currently draws exactly the same no matter what the state of the
    'editable' property. This is pretty confusing for users because there's
    no visual feedback at all, it just seems like their keyboard is broken.
    
    This change adds a "read-only" class to the StyleContext, which will
    continue to allow the user to select/copy the text, but will draw the
    entry as if it were insensitive, providing some indication that the
    contents can't be changed.
    
    Signed-off-by: David Trowbridge <trowbrds gmail com>
    
    http://bugzilla.gnome.org/show_bug.cgi?id=694831

 gtk/gtk-default.css   |    5 +++++
 gtk/gtkentry.c        |    9 ++++++++-
 gtk/gtkstylecontext.h |    6 ++++++
 3 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtk-default.css b/gtk/gtk-default.css
index b125cf6..5f5f651 100644
--- a/gtk/gtk-default.css
+++ b/gtk/gtk-default.css
@@ -54,6 +54,11 @@ GtkTreeView.dnd {
   color: shade (@bg_color, 0.7);
 }
 
+.entry.read-only {
+  border-color: shade (@bg_color, 0.7);
+  background-color: shade (@bg_color, 0.9);
+}
+
 .entry:selected {
   background-color: shade (@bg_color, 0.9);
   color: @fg_color;
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 76bb874..8c32bd0 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -2054,6 +2054,7 @@ gtk_entry_set_property (GObject         *object,
     case PROP_EDITABLE:
       {
         gboolean new_value = g_value_get_boolean (value);
+        GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (entry));
 
         if (new_value != priv->editable)
          {
@@ -2067,7 +2068,13 @@ gtk_entry_set_property (GObject         *object,
 
                priv->preedit_length = 0;
                priv->preedit_cursor = 0;
+
+                gtk_style_context_remove_class (context, GTK_STYLE_CLASS_READ_ONLY);
              }
+            else
+              {
+                gtk_style_context_add_class (context, GTK_STYLE_CLASS_READ_ONLY);
+              }
 
            priv->editable = new_value;
 
@@ -3705,7 +3712,7 @@ gtk_entry_draw_frame (GtkWidget       *widget,
 
   if (priv->has_frame)
     gtk_render_frame (context, cr,
-                      x, y, width, height);
+                     x, y, width, height);
 
   gtk_entry_draw_progress (widget, context, cr);
 
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 729613c..29f3ebf 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -923,6 +923,12 @@ void           gtk_style_context_set_frame_clock (GtkStyleContext *context,
 GDK_AVAILABLE_IN_3_8
 GdkFrameClock *gtk_style_context_get_frame_clock (GtkStyleContext *context);
 
+/**
+ * GTK_STYLE_CLASS_READ_ONLY:
+ *
+ * A CSS class used to indicate a read-only state.
+ */
+#define GTK_STYLE_CLASS_READ_ONLY "read-only"
 
 GDK_DEPRECATED_IN_3_8_FOR(gtk_style_context_set_state)
 void             gtk_style_context_set_direction (GtkStyleContext  *context,


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