2003-07-11 12:51:24 +00:00
|
|
|
/* gtkentrycompletion.c
|
|
|
|
* Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
#include <config.h>
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkentrycompletion.h"
|
|
|
|
#include "gtkentryprivate.h"
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
2004-04-12 19:40:22 +00:00
|
|
|
#include "gtkframe.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkvbox.h"
|
|
|
|
#include "gtkwindow.h"
|
|
|
|
#include "gtkentry.h"
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtksignal.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkalias.h"
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
enum
|
|
|
|
{
|
2004-07-19 18:15:48 +00:00
|
|
|
INSERT_PREFIX,
|
2003-07-11 12:51:24 +00:00
|
|
|
MATCH_SELECTED,
|
|
|
|
ACTION_ACTIVATED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_MODEL,
|
2004-05-27 04:46:42 +00:00
|
|
|
PROP_MINIMUM_KEY_LENGTH,
|
2004-07-19 18:15:48 +00:00
|
|
|
PROP_TEXT_COLUMN,
|
|
|
|
PROP_INLINE_COMPLETION,
|
2005-04-04 05:15:32 +00:00
|
|
|
PROP_POPUP_COMPLETION,
|
2005-05-26 20:36:36 +00:00
|
|
|
PROP_POPUP_SET_WIDTH,
|
|
|
|
PROP_POPUP_SINGLE_MATCH
|
2003-07-11 12:51:24 +00:00
|
|
|
};
|
|
|
|
|
2004-01-23 08:38:47 +00:00
|
|
|
#define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
|
|
|
|
static void gtk_entry_completion_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_entry_completion_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_entry_completion_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand);
|
|
|
|
static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand);
|
|
|
|
static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
|
|
|
|
static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
const char *attribute,
|
|
|
|
gint column);
|
|
|
|
static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkCellLayoutDataFunc func,
|
|
|
|
gpointer func_data,
|
|
|
|
GDestroyNotify destroy);
|
|
|
|
static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell);
|
2003-12-19 22:47:20 +00:00
|
|
|
static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gint position);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean gtk_entry_completion_popup_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
2003-10-11 13:32:16 +00:00
|
|
|
static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
|
|
|
|
gpointer data);
|
2004-06-06 03:17:45 +00:00
|
|
|
static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event,
|
|
|
|
gpointer data);
|
2003-07-11 12:51:24 +00:00
|
|
|
static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
|
|
|
|
gint index,
|
2003-10-11 13:49:22 +00:00
|
|
|
const gchar *string,
|
2003-07-11 12:51:24 +00:00
|
|
|
gboolean markup);
|
|
|
|
static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
|
2004-05-10 19:10:27 +00:00
|
|
|
static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter);
|
2004-07-19 18:15:48 +00:00
|
|
|
static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
|
2004-12-16 03:49:22 +00:00
|
|
|
const gchar *prefix);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
|
2006-05-14 04:25:34 +00:00
|
|
|
gtk_entry_completion_cell_layout_init))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *)klass;
|
|
|
|
|
|
|
|
object_class->set_property = gtk_entry_completion_set_property;
|
|
|
|
object_class->get_property = gtk_entry_completion_get_property;
|
|
|
|
object_class->finalize = gtk_entry_completion_finalize;
|
|
|
|
|
2004-05-10 19:10:27 +00:00
|
|
|
klass->match_selected = gtk_entry_completion_match_selected;
|
2004-07-19 18:15:48 +00:00
|
|
|
klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEntryCompletion::insert-prefix:
|
|
|
|
* @widget: the object which received the signal
|
|
|
|
* @prefix: the common prefix of all possible completions
|
|
|
|
*
|
2004-10-31 18:01:07 +00:00
|
|
|
* Gets emitted when the inline autocompletion is triggered.
|
|
|
|
* The default behaviour is to make the entry display the
|
2004-07-19 18:15:48 +00:00
|
|
|
* whole prefix and select the newly inserted part.
|
|
|
|
*
|
|
|
|
* Applications may connect to this signal in order to insert only a
|
|
|
|
* smaller part of the @prefix into the entry - e.g. the entry used in
|
|
|
|
* the #GtkFileChooser inserts only the part of the prefix up to the
|
|
|
|
* next '/'.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the signal has been handled
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
entry_completion_signals[INSERT_PREFIX] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("insert_prefix"),
|
2004-07-19 18:15:48 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
|
|
|
|
_gtk_boolean_handled_accumulator, NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__STRING,
|
|
|
|
G_TYPE_BOOLEAN, 1,
|
|
|
|
G_TYPE_STRING);
|
2004-05-10 19:10:27 +00:00
|
|
|
|
2004-03-15 01:32:20 +00:00
|
|
|
/**
|
|
|
|
* GtkEntryCompletion::match-selected:
|
|
|
|
* @widget: the object which received the signal
|
|
|
|
* @model: the #GtkTreeModel containing the matches
|
|
|
|
* @iter: a #GtkTreeIter positioned at the selected match
|
|
|
|
*
|
2004-10-31 18:01:07 +00:00
|
|
|
* Gets emitted when a match from the list is selected.
|
|
|
|
* The default behaviour is to replace the contents of the
|
|
|
|
* entry with the contents of the text column in the row
|
|
|
|
* pointed to by @iter.
|
2004-03-15 01:32:20 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the signal has been handled
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2004-03-15 01:32:20 +00:00
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
entry_completion_signals[MATCH_SELECTED] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("match_selected"),
|
2003-07-11 12:51:24 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
|
|
|
|
_gtk_boolean_handled_accumulator, NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__OBJECT_BOXED,
|
|
|
|
G_TYPE_BOOLEAN, 2,
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
|
|
|
GTK_TYPE_TREE_ITER);
|
2004-03-15 01:32:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkEntryCompletion::action-activated:
|
|
|
|
* @widget: the object which received the signal
|
|
|
|
* @index: the index of the activated action
|
|
|
|
*
|
2004-10-31 18:01:07 +00:00
|
|
|
* Gets emitted when an action is activated.
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2004-03-15 01:32:20 +00:00
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
entry_completion_signals[ACTION_ACTIVATED] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("action_activated"),
|
2003-07-11 12:51:24 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
|
|
|
|
NULL, NULL,
|
|
|
|
_gtk_marshal_NONE__INT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MODEL,
|
|
|
|
g_param_spec_object ("model",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Completion Model"),
|
|
|
|
P_("The model to find matches in"),
|
2003-07-11 12:51:24 +00:00
|
|
|
GTK_TYPE_TREE_MODEL,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-07-11 12:51:24 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MINIMUM_KEY_LENGTH,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_int ("minimum-key-length",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Minimum Key Length"),
|
|
|
|
P_("Minimum length of the search key in order to look up matches"),
|
2005-01-26 06:46:51 +00:00
|
|
|
0,
|
2003-07-11 12:51:24 +00:00
|
|
|
G_MAXINT,
|
|
|
|
1,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2004-05-27 04:46:42 +00:00
|
|
|
/**
|
2004-07-19 18:15:48 +00:00
|
|
|
* GtkEntryCompletion:text-column:
|
2004-05-27 04:46:42 +00:00
|
|
|
*
|
|
|
|
* The column of the model containing the strings.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_TEXT_COLUMN,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_int ("text-column",
|
2004-05-27 04:46:42 +00:00
|
|
|
P_("Text column"),
|
|
|
|
P_("The column of the model containing the strings."),
|
|
|
|
-1,
|
|
|
|
G_MAXINT,
|
|
|
|
-1,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2004-07-19 18:15:48 +00:00
|
|
|
/**
|
2004-10-31 18:01:07 +00:00
|
|
|
* GtkEntryCompletion:inline-completion:
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
2004-10-31 18:01:07 +00:00
|
|
|
* Determines whether the common prefix of the possible completions
|
2005-03-15 15:00:11 +00:00
|
|
|
* should be inserted automatically in the entry. Note that this
|
|
|
|
* requires text-column to be set, even if you are using a custom
|
|
|
|
* match function.
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_INLINE_COMPLETION,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_boolean ("inline-completion",
|
2004-07-19 18:15:48 +00:00
|
|
|
P_("Inline completion"),
|
|
|
|
P_("Whether the common prefix should be inserted automatically"),
|
|
|
|
FALSE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2004-07-19 18:15:48 +00:00
|
|
|
/**
|
2004-10-31 18:01:07 +00:00
|
|
|
* GtkEntryCompletion:popup-completion:
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
2004-10-31 18:01:07 +00:00
|
|
|
* Determines whether the possible completions should be
|
|
|
|
* shown in a popup window.
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_POPUP_COMPLETION,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_boolean ("popup-completion",
|
2004-07-19 18:15:48 +00:00
|
|
|
P_("Popup completion"),
|
|
|
|
P_("Whether the completions should be shown in a popup window"),
|
|
|
|
TRUE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2004-07-19 18:15:48 +00:00
|
|
|
|
2005-04-04 05:15:32 +00:00
|
|
|
/**
|
|
|
|
* GtkEntryCompletion:popup-set-width:
|
|
|
|
*
|
|
|
|
* Determines whether the completions popup window will be
|
|
|
|
* resized to the width of the entry.
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_POPUP_SET_WIDTH,
|
|
|
|
g_param_spec_boolean ("popup-set-width",
|
|
|
|
P_("Popup set width"),
|
|
|
|
P_("If TRUE, the popup window will have the same size as the entry"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2005-05-26 20:36:36 +00:00
|
|
|
/**
|
|
|
|
* GtkEntryCompletion:popup-single-match:
|
|
|
|
*
|
|
|
|
* Determines whether the completions popup window will shown
|
|
|
|
* for a single possible completion. You probably want to set
|
|
|
|
* this to %FALSE if you are using
|
|
|
|
* <link linkend="GtkEntryCompletion--inline-completion">inline
|
|
|
|
* completion</link>.
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_POPUP_SINGLE_MATCH,
|
|
|
|
g_param_spec_boolean ("popup-single-match",
|
|
|
|
P_("Popup single match"),
|
|
|
|
P_("If TRUE, the popup window will appear for a single match."),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
|
|
|
|
{
|
|
|
|
iface->pack_start = gtk_entry_completion_pack_start;
|
|
|
|
iface->pack_end = gtk_entry_completion_pack_end;
|
|
|
|
iface->clear = gtk_entry_completion_clear;
|
|
|
|
iface->add_attribute = gtk_entry_completion_add_attribute;
|
|
|
|
iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
|
|
|
|
iface->clear_attributes = gtk_entry_completion_clear_attributes;
|
2003-12-19 22:47:20 +00:00
|
|
|
iface->reorder = gtk_entry_completion_reorder;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_init (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkEntryCompletionPrivate *priv;
|
2004-04-12 19:40:22 +00:00
|
|
|
GtkWidget *popup_frame;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
/* yes, also priv, need to keep the code readable */
|
|
|
|
priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
|
|
|
|
|
|
|
|
priv->minimum_key_length = 1;
|
|
|
|
priv->text_column = -1;
|
2004-07-19 18:15:48 +00:00
|
|
|
priv->has_completion = FALSE;
|
|
|
|
priv->inline_completion = FALSE;
|
|
|
|
priv->popup_completion = TRUE;
|
2005-04-04 05:15:32 +00:00
|
|
|
priv->popup_set_width = TRUE;
|
2005-05-26 20:36:36 +00:00
|
|
|
priv->popup_single_match = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
/* completions */
|
|
|
|
priv->filter_model = NULL;
|
|
|
|
|
|
|
|
priv->tree_view = gtk_tree_view_new ();
|
|
|
|
g_signal_connect (priv->tree_view, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_list_button_press),
|
|
|
|
completion);
|
2004-06-06 03:17:45 +00:00
|
|
|
g_signal_connect (priv->tree_view, "enter_notify_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_list_enter_notify),
|
|
|
|
completion);
|
|
|
|
g_signal_connect (priv->tree_view, "motion_notify_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_list_motion_notify),
|
|
|
|
completion);
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
|
2004-05-10 17:15:14 +00:00
|
|
|
gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
|
|
|
|
gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
|
|
|
|
gtk_tree_selection_unselect_all (sel);
|
2003-10-11 13:32:16 +00:00
|
|
|
g_signal_connect (sel, "changed",
|
|
|
|
G_CALLBACK (gtk_entry_completion_selection_changed),
|
|
|
|
completion);
|
|
|
|
priv->first_sel_changed = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
priv->column = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
|
|
|
|
|
|
|
|
priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
2004-04-12 19:40:22 +00:00
|
|
|
GTK_SHADOW_NONE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-19 21:26:27 +00:00
|
|
|
/* a nasty hack to get the completions treeview to size nicely */
|
|
|
|
gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
/* actions */
|
|
|
|
priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
|
|
|
|
|
|
|
|
priv->action_view =
|
|
|
|
gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
|
2006-07-21 05:23:43 +00:00
|
|
|
g_object_ref_sink (priv->action_view);
|
2003-07-11 12:51:24 +00:00
|
|
|
g_signal_connect (priv->action_view, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_action_button_press),
|
|
|
|
completion);
|
2004-06-06 03:17:45 +00:00
|
|
|
g_signal_connect (priv->action_view, "enter_notify_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_list_enter_notify),
|
|
|
|
completion);
|
|
|
|
g_signal_connect (priv->action_view, "motion_notify_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_list_motion_notify),
|
|
|
|
completion);
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
|
2004-05-10 17:15:14 +00:00
|
|
|
gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
|
|
|
|
gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
|
|
|
|
gtk_tree_selection_unselect_all (sel);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
|
|
|
|
0, "",
|
|
|
|
cell,
|
|
|
|
gtk_entry_completion_action_data_func,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* pack it all */
|
|
|
|
priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
|
|
|
|
g_signal_connect (priv->popup_window, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_popup_key_press),
|
|
|
|
completion);
|
|
|
|
g_signal_connect (priv->popup_window, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_entry_completion_popup_button_press),
|
|
|
|
completion);
|
|
|
|
|
2004-04-12 19:40:22 +00:00
|
|
|
popup_frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
|
|
|
|
GTK_SHADOW_ETCHED_IN);
|
|
|
|
gtk_widget_show (popup_frame);
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
priv->vbox = gtk_vbox_new (FALSE, 0);
|
2004-04-12 19:40:22 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
|
|
|
|
gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
/* we don't want to see the action treeview when no actions have
|
|
|
|
* been inserted, so we pack the action treeview after the first
|
|
|
|
* action has been added
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
|
2006-07-21 05:23:43 +00:00
|
|
|
GtkEntryCompletionPrivate *priv = completion->priv;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
|
|
|
gtk_entry_completion_set_model (completion,
|
|
|
|
g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_MINIMUM_KEY_LENGTH:
|
|
|
|
gtk_entry_completion_set_minimum_key_length (completion,
|
|
|
|
g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
2004-05-27 04:46:42 +00:00
|
|
|
case PROP_TEXT_COLUMN:
|
|
|
|
priv->text_column = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
|
2004-07-19 18:15:48 +00:00
|
|
|
case PROP_INLINE_COMPLETION:
|
|
|
|
priv->inline_completion = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_POPUP_COMPLETION:
|
|
|
|
priv->popup_completion = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2005-04-04 05:15:32 +00:00
|
|
|
case PROP_POPUP_SET_WIDTH:
|
|
|
|
priv->popup_set_width = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2005-05-26 20:36:36 +00:00
|
|
|
case PROP_POPUP_SINGLE_MATCH:
|
|
|
|
priv->popup_single_match = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
|
|
|
g_value_set_object (value,
|
|
|
|
gtk_entry_completion_get_model (completion));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_MINIMUM_KEY_LENGTH:
|
|
|
|
g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
|
|
|
|
break;
|
|
|
|
|
2004-05-27 04:46:42 +00:00
|
|
|
case PROP_TEXT_COLUMN:
|
|
|
|
g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
|
|
|
|
break;
|
|
|
|
|
2004-07-19 18:15:48 +00:00
|
|
|
case PROP_INLINE_COMPLETION:
|
|
|
|
g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_POPUP_COMPLETION:
|
|
|
|
g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
|
|
|
|
break;
|
|
|
|
|
2005-04-04 05:15:32 +00:00
|
|
|
case PROP_POPUP_SET_WIDTH:
|
|
|
|
g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
|
|
|
|
break;
|
|
|
|
|
2005-05-26 20:36:36 +00:00
|
|
|
case PROP_POPUP_SINGLE_MATCH:
|
|
|
|
g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
|
|
|
|
break;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
|
2006-07-21 05:23:43 +00:00
|
|
|
GtkEntryCompletionPrivate *priv = completion->priv;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->tree_view)
|
|
|
|
gtk_widget_destroy (priv->tree_view);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->entry)
|
|
|
|
gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->actions)
|
2006-07-21 08:15:53 +00:00
|
|
|
g_object_unref (priv->actions);
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->action_view)
|
|
|
|
g_object_unref (priv->action_view);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->case_normalized_key)
|
|
|
|
g_free (priv->case_normalized_key);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->popup_window)
|
|
|
|
gtk_widget_destroy (priv->popup_window);
|
2004-02-22 02:06:49 +00:00
|
|
|
|
2006-07-21 05:23:43 +00:00
|
|
|
if (priv->match_notify)
|
|
|
|
(* priv->match_notify) (priv->match_data);
|
2006-06-16 17:42:40 +00:00
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* implement cell layout interface */
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean 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_start (priv->column, cell, expand);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
const gchar *attribute,
|
|
|
|
gint 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkCellLayoutDataFunc func,
|
|
|
|
gpointer func_data,
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
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),
|
|
|
|
cell, func, func_data, destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-12-19 22:47:20 +00:00
|
|
|
static void
|
|
|
|
gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gint position)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
/* all those callbacks */
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
|
|
|
|
const gchar *key,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gchar *item = NULL;
|
|
|
|
gchar *normalized_string;
|
|
|
|
gchar *case_normalized_string;
|
|
|
|
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
|
|
|
|
|
2004-08-22 04:11:14 +00:00
|
|
|
g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING,
|
|
|
|
FALSE);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
completion->priv->text_column, &item,
|
|
|
|
-1);
|
|
|
|
|
2004-02-22 01:07:39 +00:00
|
|
|
if (item != NULL)
|
|
|
|
{
|
|
|
|
normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
|
|
|
|
case_normalized_string = g_utf8_casefold (normalized_string, -1);
|
|
|
|
|
|
|
|
if (!strncmp (key, case_normalized_string, strlen (key)))
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
g_free (item);
|
|
|
|
g_free (normalized_string);
|
|
|
|
g_free (case_normalized_string);
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
|
|
|
|
|
|
|
|
if (!completion->priv->case_normalized_key)
|
|
|
|
return ret;
|
|
|
|
|
2004-03-14 20:44:10 +00:00
|
|
|
if (completion->priv->match_func)
|
2003-07-11 12:51:24 +00:00
|
|
|
ret = (* completion->priv->match_func) (completion,
|
|
|
|
completion->priv->case_normalized_key,
|
|
|
|
iter,
|
|
|
|
completion->priv->match_data);
|
2004-03-14 20:44:10 +00:00
|
|
|
else if (completion->priv->text_column >= 0)
|
|
|
|
ret = gtk_entry_completion_default_completion_func (completion,
|
|
|
|
completion->priv->case_normalized_key,
|
|
|
|
iter,
|
|
|
|
NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_popup_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* propagate event to the entry */
|
|
|
|
gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_popup_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* if we come here, it's usually time to popdown */
|
|
|
|
_gtk_entry_completion_popdown (completion);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_list_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
|
|
|
event->x, event->y,
|
|
|
|
&path, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2004-05-10 19:10:27 +00:00
|
|
|
gboolean entry_set;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
|
|
|
|
&iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2004-03-15 23:56:44 +00:00
|
|
|
g_signal_handler_block (completion->priv->entry,
|
|
|
|
completion->priv->changed_id);
|
2003-07-11 12:51:24 +00:00
|
|
|
g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
|
|
|
|
0, GTK_TREE_MODEL (completion->priv->filter_model),
|
|
|
|
&iter, &entry_set);
|
2004-03-15 23:56:44 +00:00
|
|
|
g_signal_handler_unblock (completion->priv->entry,
|
|
|
|
completion->priv->changed_id);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
_gtk_entry_completion_popdown (completion);
|
2004-05-10 19:10:27 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_action_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
|
|
|
event->x, event->y,
|
|
|
|
&path, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
|
|
|
|
0, gtk_tree_path_get_indices (path)[0]);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
_gtk_entry_completion_popdown (completion);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gchar *string = NULL;
|
|
|
|
gboolean markup;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
0, &string,
|
|
|
|
1, &markup,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (markup)
|
2004-11-19 23:18:38 +00:00
|
|
|
g_object_set (cell,
|
2003-07-11 12:51:24 +00:00
|
|
|
"text", NULL,
|
|
|
|
"markup", string,
|
|
|
|
NULL);
|
|
|
|
else
|
2004-11-19 23:18:38 +00:00
|
|
|
g_object_set (cell,
|
2003-07-11 12:51:24 +00:00
|
|
|
"markup", NULL,
|
|
|
|
"text", string,
|
|
|
|
NULL);
|
2004-01-28 20:39:46 +00:00
|
|
|
|
|
|
|
g_free (string);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 13:32:16 +00:00
|
|
|
static void
|
|
|
|
gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
|
|
|
|
|
|
|
|
if (completion->priv->first_sel_changed)
|
|
|
|
{
|
|
|
|
completion->priv->first_sel_changed = FALSE;
|
2003-11-18 23:12:10 +00:00
|
|
|
if (gtk_widget_is_focus (completion->priv->tree_view))
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
2003-10-11 13:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
/* public API */
|
2003-09-30 21:44:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkEntryCompletion object.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #GtkEntryCompletion object.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
GtkEntryCompletion *
|
|
|
|
gtk_entry_completion_new (void)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion;
|
|
|
|
|
|
|
|
completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
|
|
|
|
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_entry:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
*
|
|
|
|
* Gets the entry @completion has been attached to.
|
|
|
|
*
|
|
|
|
* Return value: The entry @completion has been attached to.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
|
|
|
|
|
|
|
|
return completion->priv->entry;
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_model:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
* @model: The #GtkTreeModel.
|
|
|
|
*
|
|
|
|
* Sets the model for a #GtkEntryCompletion. If @completion already has
|
|
|
|
* a model set, it will remove it before setting the new model.
|
2004-06-26 04:05:25 +00:00
|
|
|
* If model is %NULL, then it will unset the model.
|
2003-09-30 21:44:39 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_set_model (GtkEntryCompletion *completion,
|
|
|
|
GtkTreeModel *model)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
2004-06-26 03:39:35 +00:00
|
|
|
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2004-10-26 15:53:32 +00:00
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
|
|
|
|
NULL);
|
|
|
|
_gtk_entry_completion_popdown (completion);
|
|
|
|
completion->priv->filter_model = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
/* code will unref the old filter model (if any) */
|
|
|
|
completion->priv->filter_model =
|
|
|
|
GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
|
|
|
|
gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
|
|
|
|
gtk_entry_completion_visible_func,
|
|
|
|
completion,
|
|
|
|
NULL);
|
2004-09-13 17:34:54 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
|
|
|
|
GTK_TREE_MODEL (completion->priv->filter_model));
|
2004-11-19 23:18:38 +00:00
|
|
|
g_object_unref (completion->priv->filter_model);
|
2004-09-13 17:34:54 +00:00
|
|
|
|
2005-01-26 06:46:51 +00:00
|
|
|
g_object_notify (G_OBJECT (completion), "model");
|
|
|
|
|
2004-09-13 17:34:54 +00:00
|
|
|
if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
|
|
|
|
_gtk_entry_completion_resize_popup (completion);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_model:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
*
|
|
|
|
* Returns the model the #GtkEntryCompletion is using as data source.
|
|
|
|
* Returns %NULL if the model is unset.
|
|
|
|
*
|
|
|
|
* Return value: A #GtkTreeModel, or %NULL if none is currently being used.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
GtkTreeModel *
|
|
|
|
gtk_entry_completion_get_model (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
|
|
|
|
|
2004-10-26 15:53:32 +00:00
|
|
|
if (!completion->priv->filter_model)
|
|
|
|
return NULL;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
return gtk_tree_model_filter_get_model (completion->priv->filter_model);
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_match_func:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
* @func: The #GtkEntryCompletionMatchFunc to use.
|
|
|
|
* @func_data: The user data for @func.
|
|
|
|
* @func_notify: Destroy notifier for @func_data.
|
|
|
|
*
|
|
|
|
* Sets the match function for @completion to be @func. The match function
|
|
|
|
* is used to determine if a row should or should not be in the completion
|
|
|
|
* list.
|
|
|
|
*
|
2006-07-17 03:59:17 +00:00
|
|
|
* Since: 2.4
|
2003-09-30 21:44:39 +00:00
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
|
|
|
|
GtkEntryCompletionMatchFunc func,
|
|
|
|
gpointer func_data,
|
|
|
|
GDestroyNotify func_notify)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
|
|
|
if (completion->priv->match_notify)
|
|
|
|
(* completion->priv->match_notify) (completion->priv->match_data);
|
|
|
|
|
|
|
|
completion->priv->match_func = func;
|
|
|
|
completion->priv->match_data = func_data;
|
|
|
|
completion->priv->match_notify = func_notify;
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_minimum_key_length:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
* @length: The minimum length of the key in order to start completing.
|
|
|
|
*
|
|
|
|
* Requires the length of the search key for @completion to be at least
|
|
|
|
* @length. This is useful for long lists, where completing using a small
|
|
|
|
* key takes a lot of time and will come up with meaningless results anyway
|
|
|
|
* (ie, a too large dataset).
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
|
|
|
|
gint length)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
2005-01-26 06:46:51 +00:00
|
|
|
g_return_if_fail (length >= 0);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-01-26 06:46:51 +00:00
|
|
|
if (completion->priv->minimum_key_length != length)
|
|
|
|
{
|
|
|
|
completion->priv->minimum_key_length = length;
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (completion), "minimum-key-length");
|
2005-01-26 06:46:51 +00:00
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_minimum_key_length:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
*
|
|
|
|
* Returns the minimum key length as set for @completion.
|
|
|
|
*
|
|
|
|
* Return value: The currently used minimum key length.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
gint
|
|
|
|
gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
|
|
|
|
|
|
|
|
return completion->priv->minimum_key_length;
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_complete:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
*
|
|
|
|
* Requests a completion operation, or in other words a refiltering of the
|
|
|
|
* current list with completions, using the current key. The completion list
|
|
|
|
* view will be updated accordingly.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_complete (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
2004-10-26 15:53:32 +00:00
|
|
|
if (!completion->priv->filter_model)
|
|
|
|
return;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (completion->priv->case_normalized_key)
|
|
|
|
g_free (completion->priv->case_normalized_key);
|
|
|
|
|
|
|
|
tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
|
|
|
|
-1, G_NORMALIZE_ALL);
|
|
|
|
completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
gtk_tree_model_filter_refilter (completion->priv->filter_model);
|
2005-06-17 18:26:25 +00:00
|
|
|
|
|
|
|
if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
|
|
|
|
_gtk_entry_completion_resize_popup (completion);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
|
|
|
|
gint index,
|
2003-10-11 13:49:22 +00:00
|
|
|
const gchar *string,
|
2003-07-11 12:51:24 +00:00
|
|
|
gboolean markup)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
gtk_list_store_insert (completion->priv->actions, &iter, index);
|
|
|
|
gtk_list_store_set (completion->priv->actions, &iter,
|
|
|
|
0, string,
|
|
|
|
1, markup,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (!completion->priv->action_view->parent)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
|
|
|
|
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
|
|
|
|
path, NULL, FALSE);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
|
|
|
|
completion->priv->action_view, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (completion->priv->action_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_insert_action_text:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
2004-06-02 03:16:03 +00:00
|
|
|
* @index_: The index of the item to insert.
|
2003-09-30 21:44:39 +00:00
|
|
|
* @text: Text of the item to insert.
|
|
|
|
*
|
2004-06-02 03:16:03 +00:00
|
|
|
* Inserts an action in @completion's action item list at position @index_
|
2003-09-30 21:44:39 +00:00
|
|
|
* with text @text. If you want the action item to have markup, use
|
|
|
|
* gtk_entry_completion_insert_action_markup().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
|
2004-06-02 03:16:03 +00:00
|
|
|
gint index_,
|
2003-10-11 13:49:22 +00:00
|
|
|
const gchar *text)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
2004-06-02 03:16:03 +00:00
|
|
|
gtk_entry_completion_insert_action (completion, index_, text, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_insert_action_markup:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
2004-06-02 03:16:03 +00:00
|
|
|
* @index_: The index of the item to insert.
|
2003-09-30 21:44:39 +00:00
|
|
|
* @markup: Markup of the item to insert.
|
|
|
|
*
|
2004-06-02 03:16:03 +00:00
|
|
|
* Inserts an action in @completion's action item list at position @index_
|
2003-09-30 21:44:39 +00:00
|
|
|
* with markup @markup.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
|
2004-06-02 03:16:03 +00:00
|
|
|
gint index_,
|
2003-10-11 13:49:22 +00:00
|
|
|
const gchar *markup)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
g_return_if_fail (markup != NULL);
|
|
|
|
|
2004-06-02 03:16:03 +00:00
|
|
|
gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_delete_action:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
2004-06-02 03:16:03 +00:00
|
|
|
* @index_: The index of the item to Delete.
|
2003-09-30 21:44:39 +00:00
|
|
|
*
|
2004-06-02 03:16:03 +00:00
|
|
|
* Deletes the action at @index_ from @completion's action list.
|
2003-09-30 21:44:39 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
|
2004-06-02 03:16:03 +00:00
|
|
|
gint index_)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
2004-06-02 03:16:03 +00:00
|
|
|
g_return_if_fail (index_ >= 0);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
|
2004-06-02 03:16:03 +00:00
|
|
|
&iter, NULL, index_);
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_list_store_remove (completion->priv->actions, &iter);
|
|
|
|
}
|
|
|
|
|
2003-09-30 21:44:39 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_text_column:
|
|
|
|
* @completion: A #GtkEntryCompletion.
|
|
|
|
* @column: The column in the model of @completion to get strings from.
|
|
|
|
*
|
2004-03-03 22:55:46 +00:00
|
|
|
* Convenience function for setting up the most used case of this code: a
|
2003-09-30 21:44:39 +00:00
|
|
|
* completion list with just strings. This function will set up @completion
|
|
|
|
* to have a list displaying all (and just) strings in the completion list,
|
|
|
|
* and to get those strings from @column in the model of @completion.
|
|
|
|
*
|
2004-05-27 04:46:42 +00:00
|
|
|
* This functions creates and adds a #GtkCellRendererText for the selected
|
2004-05-27 04:48:41 +00:00
|
|
|
* column. If you need to set the text column, but don't want the cell
|
|
|
|
* renderer, use g_object_set() to set the ::text_column property directly.
|
2004-05-27 04:46:42 +00:00
|
|
|
*
|
2003-09-30 21:44:39 +00:00
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
void
|
|
|
|
gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
|
|
|
|
gint column)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
g_return_if_fail (column >= 0);
|
|
|
|
|
|
|
|
completion->priv->text_column = column;
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
|
|
|
|
cell, TRUE);
|
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
|
|
|
|
cell,
|
|
|
|
"text", column);
|
2004-05-27 04:46:42 +00:00
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (completion), "text-column");
|
2004-05-27 04:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_text_column:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Returns the column in the model of @completion to get strings from.
|
|
|
|
*
|
|
|
|
* Return value: the column containing the strings
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
|
|
|
|
{
|
2004-07-12 14:38:10 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
|
2004-05-27 04:46:42 +00:00
|
|
|
|
|
|
|
return completion->priv->text_column;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* private */
|
|
|
|
|
2004-06-06 03:17:45 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_list_enter_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
|
|
|
|
|
|
|
|
return completion->priv->ignore_enter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_list_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
|
|
|
|
|
|
|
|
completion->priv->ignore_enter = FALSE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-17 22:02:21 +00:00
|
|
|
/* some nasty size requisition */
|
2004-04-12 19:40:22 +00:00
|
|
|
gboolean
|
2003-11-17 22:02:21 +00:00
|
|
|
_gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
2004-03-17 00:17:07 +00:00
|
|
|
gint x, y;
|
2004-04-21 21:47:53 +00:00
|
|
|
gint matches, items, height, x_border, y_border;
|
2004-03-17 00:17:07 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
gint monitor_num;
|
2005-07-13 11:57:10 +00:00
|
|
|
gint vertical_separator;
|
2004-03-17 00:17:07 +00:00
|
|
|
GdkRectangle monitor;
|
|
|
|
GtkRequisition popup_req;
|
2004-07-30 06:22:26 +00:00
|
|
|
GtkRequisition entry_req;
|
2004-04-12 19:40:22 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean above;
|
2004-05-18 18:31:54 +00:00
|
|
|
gint width;
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
|
|
|
|
if (!completion->priv->entry->window)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-17 00:17:07 +00:00
|
|
|
gdk_window_get_origin (completion->priv->entry->window, &x, &y);
|
2004-10-08 04:24:45 +00:00
|
|
|
_gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2004-04-21 21:47:53 +00:00
|
|
|
matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2004-04-21 21:47:53 +00:00
|
|
|
items = MIN (matches, 15);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
|
|
|
|
NULL, NULL, NULL, &height);
|
|
|
|
|
2005-07-13 11:57:10 +00:00
|
|
|
gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
|
|
|
|
"vertical-separator", &vertical_separator,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
height += vertical_separator;
|
2006-01-30 18:24:26 +00:00
|
|
|
|
|
|
|
gtk_widget_realize (completion->priv->tree_view);
|
2005-07-13 11:57:10 +00:00
|
|
|
|
2003-11-17 22:02:21 +00:00
|
|
|
if (items <= 0)
|
|
|
|
gtk_widget_hide (completion->priv->scrolled_window);
|
|
|
|
else
|
|
|
|
gtk_widget_show (completion->priv->scrolled_window);
|
|
|
|
|
2004-05-18 18:31:54 +00:00
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
|
|
|
|
monitor_num = gdk_screen_get_monitor_at_window (screen,
|
|
|
|
GTK_WIDGET (completion->priv->entry)->window);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
|
|
|
2005-04-04 05:15:32 +00:00
|
|
|
if (completion->priv->popup_set_width)
|
|
|
|
width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
|
|
|
|
else
|
|
|
|
width = -1;
|
|
|
|
|
2005-04-04 21:35:46 +00:00
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
|
2004-10-31 19:10:29 +00:00
|
|
|
gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-10-11 13:32:16 +00:00
|
|
|
/* default on no match */
|
|
|
|
completion->priv->current_selected = -1;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
|
|
|
|
|
|
|
|
if (items)
|
|
|
|
{
|
2003-11-19 21:26:27 +00:00
|
|
|
gtk_widget_show (completion->priv->action_view);
|
2004-10-31 19:10:29 +00:00
|
|
|
gtk_widget_set_size_request (completion->priv->action_view, width, -1);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
2003-11-19 21:26:27 +00:00
|
|
|
else
|
|
|
|
gtk_widget_hide (completion->priv->action_view);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2004-03-17 00:17:07 +00:00
|
|
|
gtk_widget_size_request (completion->priv->popup_window, &popup_req);
|
2004-07-30 06:22:26 +00:00
|
|
|
gtk_widget_size_request (completion->priv->entry, &entry_req);
|
2004-03-17 00:17:07 +00:00
|
|
|
|
|
|
|
if (x < monitor.x)
|
|
|
|
x = monitor.x;
|
|
|
|
else if (x + popup_req.width > monitor.x + monitor.width)
|
|
|
|
x = monitor.x + monitor.width - popup_req.width;
|
|
|
|
|
2005-09-27 04:48:53 +00:00
|
|
|
if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
|
|
|
|
y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
|
2004-04-12 19:40:22 +00:00
|
|
|
{
|
2004-07-30 06:22:26 +00:00
|
|
|
y += entry_req.height;
|
2004-04-12 19:40:22 +00:00
|
|
|
above = FALSE;
|
|
|
|
}
|
2004-03-17 00:17:07 +00:00
|
|
|
else
|
2004-04-12 19:40:22 +00:00
|
|
|
{
|
|
|
|
y -= popup_req.height;
|
|
|
|
above = TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-21 21:47:53 +00:00
|
|
|
if (matches > 0)
|
|
|
|
{
|
|
|
|
path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
|
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
|
|
|
|
NULL, FALSE, 0.0, 0.0);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2004-03-17 00:17:07 +00:00
|
|
|
|
|
|
|
gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
|
|
|
|
|
2004-04-12 19:40:22 +00:00
|
|
|
return above;
|
2003-11-17 22:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_entry_completion_popup (GtkEntryCompletion *completion)
|
|
|
|
{
|
2004-03-10 22:42:48 +00:00
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GList *renderers;
|
2005-10-28 20:35:11 +00:00
|
|
|
GtkWidget *toplevel;
|
2003-11-17 22:02:21 +00:00
|
|
|
|
|
|
|
if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return;
|
|
|
|
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->entry))
|
|
|
|
return;
|
|
|
|
|
2005-11-07 17:28:37 +00:00
|
|
|
if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
|
|
|
|
return;
|
|
|
|
|
2004-06-06 03:17:45 +00:00
|
|
|
completion->priv->ignore_enter = TRUE;
|
|
|
|
|
2004-03-10 22:42:48 +00:00
|
|
|
column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
|
|
|
|
renderers = gtk_tree_view_column_get_cell_renderers (column);
|
|
|
|
gtk_widget_ensure_style (completion->priv->tree_view);
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
|
2004-03-10 22:42:48 +00:00
|
|
|
&completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
|
|
|
|
NULL);
|
|
|
|
g_list_free (renderers);
|
|
|
|
|
2003-11-17 22:02:21 +00:00
|
|
|
gtk_widget_show_all (completion->priv->vbox);
|
|
|
|
|
2004-03-17 00:17:07 +00:00
|
|
|
_gtk_entry_completion_resize_popup (completion);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-28 20:35:11 +00:00
|
|
|
toplevel = gtk_widget_get_toplevel (completion->priv->entry);
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
2006-01-10 04:33:30 +00:00
|
|
|
gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
|
2005-10-28 20:35:11 +00:00
|
|
|
GTK_WINDOW (completion->priv->popup_window));
|
2006-01-09 19:22:33 +00:00
|
|
|
|
|
|
|
/* prevent the first row being focused */
|
|
|
|
gtk_widget_grab_focus (completion->priv->tree_view);
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
|
|
|
|
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
|
2005-10-28 20:35:11 +00:00
|
|
|
|
2006-01-09 19:22:33 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_widget_show (completion->priv->popup_window);
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_grab_add (completion->priv->popup_window);
|
|
|
|
gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK,
|
|
|
|
NULL, NULL, GDK_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_entry_completion_popdown (GtkEntryCompletion *completion)
|
|
|
|
{
|
2004-08-02 06:09:24 +00:00
|
|
|
if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
|
|
|
|
return;
|
|
|
|
|
2004-06-06 03:17:45 +00:00
|
|
|
completion->priv->ignore_enter = FALSE;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
gtk_grab_remove (completion->priv->popup_window);
|
|
|
|
|
|
|
|
gtk_widget_hide (completion->priv->popup_window);
|
|
|
|
}
|
2004-05-10 19:10:27 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
gchar *str = NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
|
2006-02-10 19:19:54 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
|
2004-05-10 19:10:27 +00:00
|
|
|
|
|
|
|
/* move cursor to the end */
|
|
|
|
gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-07-19 18:15:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *prefix = NULL;
|
|
|
|
gboolean valid;
|
2005-03-15 15:00:11 +00:00
|
|
|
const gchar *key;
|
2004-07-19 18:15:48 +00:00
|
|
|
|
2005-03-15 15:00:11 +00:00
|
|
|
if (completion->priv->text_column < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
|
2004-07-19 18:15:48 +00:00
|
|
|
|
|
|
|
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
|
|
|
|
&iter, completion->priv->text_column, &text,
|
|
|
|
-1);
|
|
|
|
|
2006-06-19 21:20:56 +00:00
|
|
|
if (text && g_str_has_prefix (text, key))
|
2004-07-19 18:15:48 +00:00
|
|
|
{
|
|
|
|
if (!prefix)
|
|
|
|
prefix = g_strdup (text);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *p = prefix;
|
|
|
|
const gchar *q = text;
|
|
|
|
|
|
|
|
while (*p && *p == *q)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
|
|
|
|
&iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
|
2004-12-16 03:49:22 +00:00
|
|
|
const gchar *prefix)
|
2004-07-19 18:15:48 +00:00
|
|
|
{
|
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
gint key_len;
|
|
|
|
gint prefix_len;
|
|
|
|
const gchar *key;
|
|
|
|
|
|
|
|
prefix_len = g_utf8_strlen (prefix, -1);
|
|
|
|
|
|
|
|
key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
|
|
|
|
key_len = g_utf8_strlen (key, -1);
|
|
|
|
|
|
|
|
if (prefix_len > key_len)
|
|
|
|
{
|
2005-03-17 18:09:24 +00:00
|
|
|
gint pos = prefix_len;
|
|
|
|
|
2004-07-19 18:15:48 +00:00
|
|
|
gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
|
2005-09-13 15:08:43 +00:00
|
|
|
prefix + strlen (key), -1, &pos);
|
2004-07-19 18:15:48 +00:00
|
|
|
gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
|
|
|
|
key_len, prefix_len);
|
|
|
|
|
|
|
|
completion->priv->has_completion = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_insert_prefix:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Requests a prefix insertion.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
gboolean done;
|
|
|
|
gchar *prefix;
|
|
|
|
|
|
|
|
g_signal_handler_block (completion->priv->entry,
|
|
|
|
completion->priv->insert_text_id);
|
|
|
|
prefix = gtk_entry_completion_compute_prefix (completion);
|
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
|
|
|
|
0, prefix, &done);
|
|
|
|
g_free (prefix);
|
|
|
|
}
|
|
|
|
g_signal_handler_unblock (completion->priv->entry,
|
|
|
|
completion->priv->insert_text_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_inline_completion:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
* @inline_completion: %TRUE to do inline completion
|
|
|
|
*
|
|
|
|
* Sets whether the common prefix of the possible completions should
|
|
|
|
* be automatically inserted in the entry.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
|
|
|
|
gboolean inline_completion)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
|
|
|
inline_completion = inline_completion != FALSE;
|
|
|
|
|
|
|
|
if (completion->priv->inline_completion != inline_completion)
|
|
|
|
{
|
|
|
|
completion->priv->inline_completion = inline_completion;
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (completion), "inline-completion");
|
2004-07-19 18:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_inline_completion:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Returns whether the common prefix of the possible completions should
|
|
|
|
* be automatically inserted in the entry.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if inline completion is turned on
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
|
|
|
|
|
|
|
|
return completion->priv->inline_completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_popup_completion:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
2004-07-19 19:33:05 +00:00
|
|
|
* @popup_completion: %TRUE to do popup completion
|
2004-07-19 18:15:48 +00:00
|
|
|
*
|
|
|
|
* Sets whether the completions should be presented in a popup window.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
|
|
|
|
gboolean popup_completion)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
|
|
|
popup_completion = popup_completion != FALSE;
|
|
|
|
|
|
|
|
if (completion->priv->popup_completion != popup_completion)
|
|
|
|
{
|
|
|
|
completion->priv->popup_completion = popup_completion;
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (completion), "popup-completion");
|
2004-07-19 18:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_popup_completion:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Returns whether the completions should be presented in a popup window.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if popup completion is turned on
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
|
|
|
|
|
|
|
|
return completion->priv->popup_completion;
|
|
|
|
}
|
2005-03-20 07:01:23 +00:00
|
|
|
|
2005-04-04 05:15:32 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_popup_set_width:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
* @popup_set_width: %TRUE to make the width of the popup the same as the entry
|
|
|
|
*
|
|
|
|
* Sets whether the completion popup window will be resized to be the same
|
|
|
|
* width as the entry.
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
|
|
|
|
gboolean popup_set_width)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
|
|
|
popup_set_width = popup_set_width != FALSE;
|
|
|
|
|
|
|
|
if (completion->priv->popup_set_width != popup_set_width)
|
|
|
|
{
|
|
|
|
completion->priv->popup_set_width = popup_set_width;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (completion), "popup-set-width");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_popup_set_width:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Returns whether the completion popup window will be resized to the
|
|
|
|
* width of the entry.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the popup window will be resized to the width of
|
|
|
|
* the entry
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
|
|
|
|
|
|
|
|
return completion->priv->popup_set_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-26 20:36:36 +00:00
|
|
|
/**
|
|
|
|
* gtk_entry_completion_set_popup_single_match:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
* @popup_single_match: %TRUE if the popup should appear even for a single
|
|
|
|
* match
|
|
|
|
*
|
|
|
|
* Sets whether the completion popup window will appear even if there is
|
|
|
|
* only a single match. You may want to set this to %FALSE if you
|
|
|
|
* are using <link linkend="GtkEntryCompletion--inline-completion">inline
|
|
|
|
* completion</link>.
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
|
|
|
|
gboolean popup_single_match)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
|
|
|
|
|
|
|
|
popup_single_match = popup_single_match != FALSE;
|
|
|
|
|
|
|
|
if (completion->priv->popup_single_match != popup_single_match)
|
|
|
|
{
|
|
|
|
completion->priv->popup_single_match = popup_single_match;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (completion), "popup-single-match");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_entry_completion_get_popup_single_match:
|
|
|
|
* @completion: a #GtkEntryCompletion
|
|
|
|
*
|
|
|
|
* Returns whether the completion popup window will appear even if there is
|
|
|
|
* only a single match.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the popup window will appear regardless of the
|
|
|
|
* number of matches.
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
|
|
|
|
|
|
|
|
return completion->priv->popup_single_match;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-20 07:01:23 +00:00
|
|
|
#define __GTK_ENTRY_COMPLETION_C__
|
|
|
|
#include "gtkaliasdef.c"
|