]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentrycompletion.c
move a few '{' to their own lines so all enums here have the same style.
[~andy/gtk] / gtk / gtkentrycompletion.c
index 4b0da9769a6bb9a70dc3cfce866827ada2aaa86c..ed1d3c1fe374f79505c14b717b7ef2374f958302 100644 (file)
@@ -32,7 +32,6 @@
 #include "gtkwindow.h"
 #include "gtkentry.h"
 #include "gtkmain.h"
-#include "gtksignal.h"
 #include "gtkmarshalers.h"
 
 #include "gtkprivate.h"
@@ -99,6 +98,7 @@ static void     gtk_entry_completion_clear_attributes    (GtkCellLayout
 static void     gtk_entry_completion_reorder             (GtkCellLayout         *cell_layout,
                                                           GtkCellRenderer       *cell,
                                                           gint                   position);
+static GList *  gtk_entry_completion_get_cells           (GtkCellLayout         *cell_layout);
 
 static gboolean gtk_entry_completion_visible_func        (GtkTreeModel       *model,
                                                           GtkTreeIter        *iter,
@@ -149,9 +149,15 @@ static void     gtk_entry_completion_insert_completion_text (GtkEntryCompletion
 
 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
 
+/* GtkBuildable */
+static void     gtk_entry_completion_buildable_init      (GtkBuildableIface  *iface);
+
 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
-                                               gtk_entry_completion_cell_layout_init))
+                                               gtk_entry_completion_cell_layout_init)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_entry_completion_buildable_init))
+
 
 static void
 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
@@ -287,6 +293,7 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
    * GtkEntryCompletion:text-column:
    *
    * The column of the model containing the strings.
+   * Note that the strings must be UTF-8.
    *
    * Since: 2.6
    */
@@ -386,6 +393,14 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
   g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
 }
 
+static void
+gtk_entry_completion_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = _gtk_cell_layout_buildable_add_child;
+  iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
+  iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
+}
+
 static void
 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
 {
@@ -396,6 +411,7 @@ gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
   iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
   iface->clear_attributes = gtk_entry_completion_clear_attributes;
   iface->reorder = gtk_entry_completion_reorder;
+  iface->get_cells = gtk_entry_completion_get_cells;
 }
 
 static void
@@ -636,6 +652,7 @@ gtk_entry_completion_finalize (GObject *object)
     g_object_unref (priv->action_view);
 
   g_free (priv->case_normalized_key);
+  g_free (priv->completion_prefix);
 
   if (priv->popup_window)
     gtk_widget_destroy (priv->popup_window);
@@ -654,8 +671,6 @@ gtk_entry_completion_pack_start (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_tree_view_column_pack_start (priv->column, cell, expand);
@@ -668,8 +683,6 @@ gtk_entry_completion_pack_end (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_tree_view_column_pack_end (priv->column, cell, expand);
@@ -680,8 +693,6 @@ gtk_entry_completion_clear (GtkCellLayout *cell_layout)
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_tree_view_column_clear (priv->column);
@@ -695,8 +706,6 @@ gtk_entry_completion_add_attribute (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
@@ -711,8 +720,6 @@ gtk_entry_completion_set_cell_data_func (GtkCellLayout          *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
@@ -725,8 +732,6 @@ gtk_entry_completion_clear_attributes (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_tree_view_column_clear_attributes (priv->column, cell);
@@ -739,13 +744,21 @@ gtk_entry_completion_reorder (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
   priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
 
   gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
 }
 
+static GList *
+gtk_entry_completion_get_cells (GtkCellLayout *cell_layout)
+{
+  GtkEntryCompletionPrivate *priv;
+
+  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+
+  return gtk_tree_view_column_get_cell_renderers (priv->column);
+}
+
 /* all those callbacks */
 static gboolean
 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
@@ -1641,11 +1654,12 @@ gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
  * @completion: a #GtkEntryCompletion
  * 
  * Get the original text entered by the user that triggered
- * the completion or NULL if there's no completion ongoing.
+ * the completion or %NULL if there's no completion ongoing.
+ * 
+ * Returns: the prefix for the current completion
  * 
  * Since: 2.12
  **/
-
 const gchar*
 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
 {
@@ -1659,44 +1673,26 @@ gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
                                             const gchar *text)
 {
   GtkEntryCompletionPrivate *priv = completion->priv;
-  gchar *needle;
   gint len;
 
   priv = completion->priv;
 
   if (priv->changed_id > 0)
-    {
-      g_signal_handler_block (priv->entry,
-                             priv->changed_id);
-    }
+    g_signal_handler_block (priv->entry, priv->changed_id);
 
   if (priv->insert_text_id > 0)
-    {
-      g_signal_handler_block (completion->priv->entry,
-                             completion->priv->insert_text_id);
-    }
+    g_signal_handler_block (priv->entry, priv->insert_text_id);
 
   gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
-  needle = strstr (text, completion->priv->completion_prefix);
-  if (needle)
-    {
-      len = g_utf8_strlen (text, -1) - g_utf8_strlen (needle, -1)
-        + g_utf8_strlen (priv->completion_prefix, -1);
-      gtk_editable_select_region (GTK_EDITABLE (priv->entry),
-                                  len, -1);
-    }
+
+  len = strlen (priv->completion_prefix);
+  gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
 
   if (priv->changed_id > 0)
-    {
-      g_signal_handler_unblock (priv->entry,
-                               priv->changed_id);
-    }
+    g_signal_handler_unblock (priv->entry, priv->changed_id);
 
   if (priv->insert_text_id > 0)
-    {
-      g_signal_handler_unblock (priv->entry,
-                               priv->insert_text_id);
-    }
+    g_signal_handler_unblock (priv->entry, priv->insert_text_id);
 }
 
 static gboolean
@@ -1937,6 +1933,16 @@ gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
   return completion->priv->popup_single_match;
 }
 
+/**
+ * gtk_entry_completion_set_inline_selection:
+ * @completion: a #GtkEntryCompletion
+ * @inline_selection: %TRUE to do inline selection
+ * 
+ * Sets whether it is possible to cycle through the possible completions
+ * inside the entry.
+ * 
+ * Since: 2.12
+ **/
 void
 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
                                           gboolean inline_selection)
@@ -1953,6 +1959,16 @@ gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
     }
 }
 
+/**
+ * gtk_entry_completion_get_inline_selection:
+ * @completion: a #GtkEntryCompletion
+ *
+ * Returns %TRUE if inline-selection mode is turned on.
+ *
+ * Returns: %TRUE if inline-selection mode is on
+ *
+ * Since: 2.12
+ **/
 gboolean
 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
 {