#include "gtkwindow.h"
#include "gtkentry.h"
#include "gtkmain.h"
-#include "gtksignal.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
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,
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)
* GtkEntryCompletion:text-column:
*
* The column of the model containing the strings.
+ * Note that the strings must be UTF-8.
*
* Since: 2.6
*/
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)
{
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
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);
{
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);
{
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);
{
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);
{
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);
{
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),
{
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);
{
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,
* @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)
{
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
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)
}
}
+/**
+ * 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)
{