2007-06-01 Neil J. Patel <njp@o-hand.com>
authorNeil J. Patel <njp@openedhand.com>
Fri, 1 Jun 2007 17:18:21 +0000 (17:18 +0000)
committerNeil J. Patel <njp@openedhand.com>
Fri, 1 Jun 2007 17:18:21 +0000 (17:18 +0000)
        * clutter/clutter-entry.c: (clutter_entry_set_property),
        (clutter_entry_get_property), (clutter_entry_class_init),
        (clutter_entry_init), (clutter_entry_set_text),
        (clutter_entry_set_max_length):
        * clutter/clutter-entry.h:
        * examples/test-entry.c: (main):
        Added a max-length property whihc limits the length of the text in the
        entry.

ChangeLog
clutter/clutter-entry.c
clutter/clutter-entry.h
doc/reference/ChangeLog
doc/reference/clutter-sections.txt
doc/reference/tmpl/clutter-entry.sgml
examples/test-entry.c

index 361d568..84da1bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2007-06-01  Neil J. Patel  <njp@o-hand.com>
 
+       * clutter/clutter-entry.c: (clutter_entry_set_property),
+       (clutter_entry_get_property), (clutter_entry_class_init),
+       (clutter_entry_init), (clutter_entry_set_text),
+       (clutter_entry_set_max_length):
+       * clutter/clutter-entry.h:
+       * examples/test-entry.c: (main):
+       Added a max-length property whihc limits the length of the text in the
+       entry.
+
+2007-06-01  Neil J. Patel  <njp@o-hand.com>
+
        * clutter/clutter-entry.c: (clutter_entry_ensure_cursor_position),
        (clutter_entry_paint), (clutter_entry_init),
        (clutter_entry_handle_key_event):
index 4aa36fd..5a5bd0c 100644 (file)
@@ -64,7 +64,8 @@ enum
   PROP_ALIGNMENT,              /* FIXME */
   PROP_POSITION,
   PROP_CURSOR,
-  PROP_TEXT_VISIBLE
+  PROP_TEXT_VISIBLE,
+  PROP_MAX_LENGTH
 };
 
 enum
@@ -104,6 +105,7 @@ struct _ClutterEntryPrivate
   guint                 wrap_mode        : 3;
   gint                  position;
   gint                  text_x;
+  gint                  max_length;
 
   PangoAttrList        *attrs;
   PangoAttrList        *effective_attrs;
@@ -151,6 +153,9 @@ clutter_entry_set_property (GObject      *object,
     case PROP_TEXT_VISIBLE:
       clutter_entry_set_visibility (entry, g_value_get_boolean (value));
       break;
+    case PROP_MAX_LENGTH:
+      clutter_entry_set_max_length (entry, g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -194,6 +199,9 @@ clutter_entry_get_property (GObject    *object,
     case PROP_TEXT_VISIBLE:
       g_value_set_boolean (value, priv->text_visible);
       break;
+    case PROP_MAX_LENGTH:
+      g_value_set_int (value, priv->max_length);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -522,6 +530,20 @@ clutter_entry_class_init (ClutterEntryClass *klass)
                           "Whether the text is visible in plain text",
                           TRUE,
                           CLUTTER_PARAM_READWRITE));
+
+  /**
+   * ClutterEntry:max-length
+   *
+   * The maximum length of the entry text
+   */                  
+  g_object_class_install_property 
+    (gobject_class, PROP_MAX_LENGTH,
+     g_param_spec_int ("max-length",
+                      "Max Length",
+                      "The maximum length of the entry text",
+                      0, G_MAXINT,
+                      0,
+                      CLUTTER_PARAM_READWRITE));
                        
 
   /**
@@ -589,6 +611,7 @@ clutter_entry_init (ClutterEntry *self)
   priv->priv_char     = '*';
   priv->text_visible  = TRUE;
   priv->text_x        = 0;
+  priv->max_length    = 0;
 
   priv->fgcol.red     = 0;
   priv->fgcol.green   = 0;
@@ -696,16 +719,35 @@ void
 clutter_entry_set_text (ClutterEntry *entry,
                        const gchar  *text)
 {
-  ClutterEntryPrivate  *priv;  
+  ClutterEntryPrivate  *priv;
 
   g_return_if_fail (CLUTTER_IS_ENTRY (entry));
 
   priv = entry->priv;
 
   g_object_ref (entry);
-
-  g_free (priv->text);
-  priv->text = g_strdup (text);
+  
+  if (priv->max_length)
+    {
+      gint len = g_utf8_strlen (text, -1);
+      if (len < priv->max_length)
+        {  
+           g_free (priv->text);
+           priv->text = g_strdup (text);
+        }
+      else
+        {
+          gchar new[priv->max_length+1];
+          g_utf8_strncpy (new, text, priv->max_length);
+           g_free (priv->text);
+           priv->text = g_strdup (new);
+        }
+    }
+  else
+    {
+      g_free (priv->text);
+      priv->text = g_strdup (text);
+    }
 
   clutter_entry_clear_layout (entry);  
   clutter_entry_clear_cursor_position (entry); 
@@ -1382,3 +1424,35 @@ clutter_entry_get_invisible_char (ClutterEntry *entry)
   return priv->priv_char;
 }
 
+/**
+ * clutter_entry_set_max_length
+ * @entry: a #ClutterEntry
+ * @max: the maximum number of characters allowed in the entry
+ *
+ * Sets the maximum allowed length of the contents of the actor. If the current
+ * contents are longer than the given length, then they will be truncated to 
+ * fit. 
+ * 
+ **/
+void
+clutter_entry_set_max_length (ClutterEntry *entry, gint max)
+{
+  ClutterEntryPrivate *priv;
+  gchar *new = NULL;
+    
+  g_return_if_fail (CLUTTER_IS_ENTRY (entry));
+  
+  priv = entry->priv;
+  
+  if (max < 0)
+    max = 0;
+  
+  priv->max_length = max;
+  new = g_strdup (priv->text);
+  
+  clutter_entry_set_text (entry, new);
+  
+  g_free (new);
+}
+
+
index 8fb5d41..b3870c2 100644 (file)
@@ -138,7 +138,8 @@ gboolean              clutter_entry_get_visibility     (ClutterEntry       *entr
 void                  clutter_entry_set_invisible_char (ClutterEntry       *entry,
                                                         gunichar            wc);
 gunichar              clutter_entry_get_invisible_char (ClutterEntry       *entry);
-
+void                  clutter_entry_set_max_length     (ClutterEntry       *entry,
+                                                        gint                max);
 
 
 G_END_DECLS
index e7d6a2a..2c09579 100644 (file)
@@ -1,4 +1,9 @@
 2007-06-01  Neil J. Patel  <njp@o-hand.com>
+       * clutter-sections.txt:
+       * tmpl/clutter-entry.sgml:
+       updated for new functions.
+
+2007-06-01  Neil J. Patel  <njp@o-hand.com>
 
        * clutter-sections.txt:
        * tmpl/clutter-entry.sgml:
index a7af787..db388c1 100644 (file)
@@ -787,6 +787,7 @@ clutter_entry_set_visibility
 clutter_entry_get_visibility
 clutter_entry_set_invisible_char
 clutter_entry_get_invisible_char
+clutter_entry_set_max_length
 <SUBSECTION Standard>
 CLUTTER_ENTRY
 CLUTTER_IS_ENTRY
index f8fa08f..110cdc6 100644 (file)
@@ -58,6 +58,11 @@ ClutterEntry
 
 </para>
 
+<!-- ##### ARG ClutterEntry:max-length ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG ClutterEntry:position ##### -->
 <para>
 
@@ -308,3 +313,12 @@ ClutterEntry
 @Returns: 
 
 
+<!-- ##### FUNCTION clutter_entry_set_max_length ##### -->
+<para>
+
+</para>
+
+@entry: 
+@max: 
+
+
index e00bc7e..6e52a5f 100644 (file)
@@ -43,6 +43,7 @@ main (int argc, char *argv[])
   clutter_actor_set_size (entry, 600, 50);
   clutter_actor_set_position (entry, 100, 100);
   /*clutter_entry_set_visibility (CLUTTER_ENTRY (entry), FALSE);*/
+  /*clutter_entry_set_max_length (CLUTTER_ENTRY (entry), 50);*/
   
   clutter_group_add (CLUTTER_GROUP (stage), entry);
   clutter_group_show_all (CLUTTER_GROUP (stage));