2004-07-16 20:27:40 +00:00
|
|
|
/* GtkCellRendererCombo
|
|
|
|
* Copyright (C) 2004 Lorenzo Gil Sanchez
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-16 20:27:40 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2004-07-16 20:27:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkentry.h"
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
#include "gtkcellrenderercombo.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
#include "gtkcombobox.h"
|
2008-05-28 11:49:20 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2008-06-08 22:25:57 +00:00
|
|
|
|
2011-04-11 21:39:48 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-02 03:37:23 +00:00
|
|
|
* GtkCellRendererCombo:
|
|
|
|
*
|
|
|
|
* Renders a combobox in a cell
|
2011-04-11 21:39:48 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* `GtkCellRendererCombo` renders text in a cell like `GtkCellRendererText` from
|
|
|
|
* which it is derived. But while `GtkCellRendererText` offers a simple entry to
|
|
|
|
* edit the text, `GtkCellRendererCombo` offers a `GtkComboBox`
|
2011-04-11 21:39:48 +00:00
|
|
|
* widget to edit the text. The values to display in the combo box are taken from
|
2021-05-20 13:17:04 +00:00
|
|
|
* the tree model specified in the `GtkCellRendererCombo`:model property.
|
2011-04-11 21:39:48 +00:00
|
|
|
*
|
|
|
|
* The combo cell renderer takes care of adding a text cell renderer to the combo
|
|
|
|
* box and sets it to display the column specified by its
|
2021-05-20 13:17:04 +00:00
|
|
|
* `GtkCellRendererCombo`:text-column property. Further properties of the combo box
|
|
|
|
* can be set in a handler for the `GtkCellRenderer::editing-started` signal.
|
2011-04-11 21:39:48 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-27 00:07:53 +00:00
|
|
|
typedef struct _GtkCellRendererComboPrivate GtkCellRendererComboPrivate;
|
|
|
|
typedef struct _GtkCellRendererComboClass GtkCellRendererComboClass;
|
|
|
|
|
|
|
|
struct _GtkCellRendererCombo
|
|
|
|
{
|
|
|
|
GtkCellRendererText parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkCellRendererComboClass
|
|
|
|
{
|
|
|
|
GtkCellRendererTextClass parent;
|
|
|
|
};
|
|
|
|
|
2011-04-11 21:39:48 +00:00
|
|
|
|
2010-08-26 17:15:37 +00:00
|
|
|
struct _GtkCellRendererComboPrivate
|
2008-06-08 22:25:57 +00:00
|
|
|
{
|
2010-06-01 12:40:52 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
|
2008-06-08 22:25:57 +00:00
|
|
|
GtkWidget *combo;
|
2010-06-01 12:40:52 +00:00
|
|
|
|
|
|
|
gboolean has_entry;
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
int text_column;
|
2010-06-01 12:40:52 +00:00
|
|
|
|
2010-10-08 00:37:23 +00:00
|
|
|
gulong focus_out_id;
|
2008-06-08 22:25:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-25 03:57:25 +00:00
|
|
|
static void gtk_cell_renderer_combo_finalize (GObject *object);
|
2004-07-16 20:27:40 +00:00
|
|
|
static void gtk_cell_renderer_combo_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gtk_cell_renderer_combo_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static GtkCellEditable *gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
|
2010-10-04 14:22:09 +00:00
|
|
|
GdkEvent *event,
|
|
|
|
GtkWidget *widget,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *path,
|
2010-10-04 14:22:09 +00:00
|
|
|
const GdkRectangle *background_area,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_MODEL,
|
|
|
|
PROP_TEXT_COLUMN,
|
|
|
|
PROP_HAS_ENTRY
|
|
|
|
};
|
|
|
|
|
2008-05-28 11:49:20 +00:00
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint cell_renderer_combo_signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
#define GTK_CELL_RENDERER_COMBO_PATH "gtk-cell-renderer-combo-path"
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererCombo, gtk_cell_renderer_combo, GTK_TYPE_CELL_RENDERER_TEXT)
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_class_init (GtkCellRendererComboClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
|
|
|
|
|
2004-10-25 03:57:25 +00:00
|
|
|
object_class->finalize = gtk_cell_renderer_combo_finalize;
|
2004-07-16 20:27:40 +00:00
|
|
|
object_class->get_property = gtk_cell_renderer_combo_get_property;
|
|
|
|
object_class->set_property = gtk_cell_renderer_combo_set_property;
|
|
|
|
|
|
|
|
cell_class->start_editing = gtk_cell_renderer_combo_start_editing;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkCellRendererCombo:model:
|
|
|
|
*
|
2004-10-31 17:56:51 +00:00
|
|
|
* Holds a tree model containing the possible values for the combo box.
|
|
|
|
* Use the text_column property to specify the column holding the values.
|
2004-07-16 20:27:40 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MODEL,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("model", NULL, NULL,
|
2004-07-16 20:27:40 +00:00
|
|
|
GTK_TYPE_TREE_MODEL,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
/**
|
2004-10-31 17:56:51 +00:00
|
|
|
* GtkCellRendererCombo:text-column:
|
2004-07-16 20:27:40 +00:00
|
|
|
*
|
2007-07-12 01:55:15 +00:00
|
|
|
* Specifies the model column which holds the possible values for the
|
|
|
|
* combo box.
|
|
|
|
*
|
2004-10-31 17:56:51 +00:00
|
|
|
* Note that this refers to the model specified in the model property,
|
2014-01-28 06:54:48 +00:00
|
|
|
* not the model backing the tree view to which
|
2007-07-12 01:55:15 +00:00
|
|
|
* this cell renderer is attached.
|
2004-07-16 20:27:40 +00:00
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* `GtkCellRendererCombo` automatically adds a text cell renderer for
|
2007-07-12 01:55:15 +00:00
|
|
|
* this column to its combo box.
|
2004-07-16 20:27:40 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_TEXT_COLUMN,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_int ("text-column", NULL, NULL,
|
2004-07-16 20:27:40 +00:00
|
|
|
-1,
|
|
|
|
G_MAXINT,
|
|
|
|
-1,
|
2014-06-08 15:26:04 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
/**
|
2004-10-31 17:56:51 +00:00
|
|
|
* GtkCellRendererCombo:has-entry:
|
2004-07-16 20:27:40 +00:00
|
|
|
*
|
2007-07-12 01:55:15 +00:00
|
|
|
* If %TRUE, the cell renderer will include an entry and allow to enter
|
|
|
|
* values other than the ones in the popup list.
|
2004-07-16 20:27:40 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_HAS_ENTRY,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("has-entry", NULL, NULL,
|
2004-07-16 20:27:40 +00:00
|
|
|
TRUE,
|
2014-06-08 15:26:04 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2008-05-28 11:49:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkCellRendererCombo::changed:
|
|
|
|
* @combo: the object on which the signal is emitted
|
|
|
|
* @path_string: a string of the path identifying the edited cell
|
|
|
|
* (relative to the tree view model)
|
|
|
|
* @new_iter: the new iter selected in the combo box
|
|
|
|
* (relative to the combo box model)
|
|
|
|
*
|
|
|
|
* This signal is emitted each time after the user selected an item in
|
|
|
|
* the combo box, either by using the mouse or the arrow keys. Contrary
|
|
|
|
* to GtkComboBox, GtkCellRendererCombo::changed is not emitted for
|
|
|
|
* changes made to a selected item in the entry. The argument @new_iter
|
|
|
|
* corresponds to the newly selected item in the combo box and it is relative
|
|
|
|
* to the GtkTreeModel set via the model property on GtkCellRendererCombo.
|
|
|
|
*
|
|
|
|
* Note that as soon as you change the model displayed in the tree view,
|
|
|
|
* the tree view will immediately cease the editing operating. This
|
|
|
|
* means that you most probably want to refrain from changing the model
|
|
|
|
* until the combo cell renderer emits the edited or editing_canceled signal.
|
|
|
|
*/
|
|
|
|
cell_renderer_combo_signals[CHANGED] =
|
|
|
|
g_signal_new (I_("changed"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL,
|
|
|
|
_gtk_marshal_VOID__STRING_BOXED,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
GTK_TYPE_TREE_ITER);
|
2019-06-06 22:27:54 +00:00
|
|
|
g_signal_set_va_marshaller (cell_renderer_combo_signals[CHANGED],
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
_gtk_marshal_VOID__STRING_BOXEDv);
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_init (GtkCellRendererCombo *self)
|
|
|
|
{
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (self);
|
2010-06-01 12:40:52 +00:00
|
|
|
|
|
|
|
priv->model = NULL;
|
|
|
|
priv->text_column = -1;
|
|
|
|
priv->has_entry = TRUE;
|
|
|
|
priv->focus_out_id = 0;
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-20 13:17:04 +00:00
|
|
|
* gtk_cell_renderer_combo_new:
|
|
|
|
*
|
|
|
|
* Creates a new `GtkCellRendererCombo`.
|
|
|
|
* Adjust how text is drawn using object properties.
|
|
|
|
* Object properties can be set globally (with g_object_set()).
|
|
|
|
* Also, with `GtkTreeViewColumn`, you can bind a property to a value
|
|
|
|
* in a `GtkTreeModel`. For example, you can bind the “text” property
|
|
|
|
* on the cell renderer to a string value in the model, thus rendering
|
|
|
|
* a different string in each row of the `GtkTreeView`.
|
|
|
|
*
|
2004-07-16 20:27:40 +00:00
|
|
|
* Returns: the new cell renderer
|
|
|
|
*/
|
|
|
|
GtkCellRenderer *
|
|
|
|
gtk_cell_renderer_combo_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_CELL_RENDERER_COMBO, NULL);
|
|
|
|
}
|
|
|
|
|
2004-10-25 03:57:25 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCellRendererCombo *cell = GTK_CELL_RENDERER_COMBO (object);
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (cell);
|
2004-10-25 03:57:25 +00:00
|
|
|
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->model)
|
2004-10-25 03:57:25 +00:00
|
|
|
{
|
2010-06-01 12:40:52 +00:00
|
|
|
g_object_unref (priv->model);
|
|
|
|
priv->model = NULL;
|
2004-10-25 03:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_cell_renderer_combo_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2008-02-07 15:50:39 +00:00
|
|
|
GtkCellRendererCombo *cell = GTK_CELL_RENDERER_COMBO (object);
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (cell);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
2010-06-01 12:40:52 +00:00
|
|
|
g_value_set_object (value, priv->model);
|
2004-07-16 20:27:40 +00:00
|
|
|
break;
|
|
|
|
case PROP_TEXT_COLUMN:
|
2010-06-01 12:40:52 +00:00
|
|
|
g_value_set_int (value, priv->text_column);
|
2004-07-16 20:27:40 +00:00
|
|
|
break;
|
|
|
|
case PROP_HAS_ENTRY:
|
2010-06-01 12:40:52 +00:00
|
|
|
g_value_set_boolean (value, priv->has_entry);
|
2004-07-16 20:27:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2008-01-06 03:28:40 +00:00
|
|
|
break;
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2008-02-07 15:50:39 +00:00
|
|
|
GtkCellRendererCombo *cell = GTK_CELL_RENDERER_COMBO (object);
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (cell);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
2004-10-25 03:57:25 +00:00
|
|
|
{
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->model)
|
|
|
|
g_object_unref (priv->model);
|
|
|
|
priv->model = GTK_TREE_MODEL (g_value_get_object (value));
|
|
|
|
if (priv->model)
|
|
|
|
g_object_ref (priv->model);
|
2008-10-31 18:20:07 +00:00
|
|
|
break;
|
2004-10-25 03:57:25 +00:00
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
case PROP_TEXT_COLUMN:
|
2014-06-08 15:26:04 +00:00
|
|
|
if (priv->text_column != g_value_get_int (value))
|
|
|
|
{
|
|
|
|
priv->text_column = g_value_get_int (value);
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
break;
|
|
|
|
case PROP_HAS_ENTRY:
|
2014-06-08 15:26:04 +00:00
|
|
|
if (priv->has_entry != g_value_get_boolean (value))
|
|
|
|
{
|
|
|
|
priv->has_entry = g_value_get_boolean (value);
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2008-01-06 03:28:40 +00:00
|
|
|
break;
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 11:49:20 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_changed (GtkComboBox *combo,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkCellRendererCombo *cell;
|
|
|
|
|
|
|
|
cell = GTK_CELL_RENDERER_COMBO (data);
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (combo, &iter))
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
path = g_object_get_data (G_OBJECT (combo), GTK_CELL_RENDERER_COMBO_PATH);
|
|
|
|
g_signal_emit (cell, cell_renderer_combo_signals[CHANGED], 0,
|
|
|
|
path, &iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_editing_done (GtkCellEditable *combo,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererCombo *cell = GTK_CELL_RENDERER_COMBO (data);
|
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (cell);
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *path;
|
|
|
|
char *new_text = NULL;
|
2004-07-16 20:27:40 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkEntry *entry;
|
2004-12-09 17:55:58 +00:00
|
|
|
gboolean canceled;
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->focus_out_id > 0)
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
2010-06-01 12:40:52 +00:00
|
|
|
g_signal_handler_disconnect (combo, priv->focus_out_id);
|
|
|
|
priv->focus_out_id = 0;
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
2009-12-04 01:15:00 +00:00
|
|
|
|
|
|
|
g_object_get (combo,
|
|
|
|
"editing-canceled", &canceled,
|
|
|
|
NULL);
|
2004-12-09 17:55:58 +00:00
|
|
|
gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
|
|
|
|
if (canceled)
|
2008-06-08 22:25:57 +00:00
|
|
|
{
|
|
|
|
priv->combo = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2010-10-14 01:52:27 +00:00
|
|
|
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
2020-05-03 16:19:17 +00:00
|
|
|
entry = GTK_ENTRY (gtk_combo_box_get_child (GTK_COMBO_BOX (combo)));
|
2019-02-28 19:31:36 +00:00
|
|
|
new_text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (entry)));
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
2008-06-08 22:25:57 +00:00
|
|
|
|
|
|
|
if (model
|
|
|
|
&& gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
|
2010-06-01 12:40:52 +00:00
|
|
|
gtk_tree_model_get (model, &iter, priv->text_column, &new_text, -1);
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
path = g_object_get_data (G_OBJECT (combo), GTK_CELL_RENDERER_COMBO_PATH);
|
|
|
|
g_signal_emit_by_name (cell, "edited", path, new_text);
|
|
|
|
|
2008-06-08 22:25:57 +00:00
|
|
|
priv->combo = NULL;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
g_free (new_text);
|
|
|
|
}
|
|
|
|
|
2018-01-06 20:06:12 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_renderer_combo_focus_change (GtkWidget *widget,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
2018-01-06 20:06:12 +00:00
|
|
|
if (!gtk_widget_has_focus (widget))
|
|
|
|
gtk_cell_renderer_combo_editing_done (GTK_CELL_EDITABLE (widget), data);
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkCellRendererCombo *cell;
|
|
|
|
gboolean found;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
} SearchData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_text (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
SearchData *search_data = (SearchData *)data;
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (search_data->cell);
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text, *cell_text;
|
2010-06-01 12:40:52 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, priv->text_column, &text, -1);
|
2010-06-01 19:01:33 +00:00
|
|
|
g_object_get (GTK_CELL_RENDERER_TEXT (search_data->cell),
|
|
|
|
"text", &cell_text,
|
|
|
|
NULL);
|
|
|
|
if (text && cell_text && g_strcmp0 (text, cell_text) == 0)
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
|
|
|
search_data->iter = *iter;
|
|
|
|
search_data->found = TRUE;
|
|
|
|
}
|
2004-10-25 19:21:26 +00:00
|
|
|
|
2010-06-01 19:01:33 +00:00
|
|
|
g_free (cell_text);
|
2004-10-25 19:21:26 +00:00
|
|
|
g_free (text);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
return search_data->found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCellEditable *
|
|
|
|
gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
|
2010-10-04 14:22:09 +00:00
|
|
|
GdkEvent *event,
|
|
|
|
GtkWidget *widget,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *path,
|
2010-10-04 14:22:09 +00:00
|
|
|
const GdkRectangle *background_area,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags)
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
2019-05-27 00:12:40 +00:00
|
|
|
GtkCellRendererCombo *cell_combo = GTK_CELL_RENDERER_COMBO (cell);
|
|
|
|
GtkCellRendererComboPrivate *priv = gtk_cell_renderer_combo_get_instance_private (cell_combo);
|
2004-07-16 20:27:40 +00:00
|
|
|
GtkWidget *combo;
|
|
|
|
SearchData search_data;
|
2010-06-01 19:01:33 +00:00
|
|
|
gboolean editable;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2019-05-27 00:12:40 +00:00
|
|
|
g_object_get (cell, "editable", &editable, NULL);
|
2010-06-01 19:01:33 +00:00
|
|
|
if (editable == FALSE)
|
2004-07-16 20:27:40 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->text_column < 0)
|
|
|
|
return NULL;
|
2008-06-08 22:25:57 +00:00
|
|
|
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->has_entry)
|
2004-07-16 20:27:40 +00:00
|
|
|
{
|
2010-10-14 01:52:27 +00:00
|
|
|
combo = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
|
2008-06-08 22:25:57 +00:00
|
|
|
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->model)
|
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), priv->model);
|
2010-10-14 01:52:27 +00:00
|
|
|
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo),
|
2010-06-01 12:40:52 +00:00
|
|
|
priv->text_column);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2019-05-27 00:12:40 +00:00
|
|
|
g_object_get (cell, "text", &text, NULL);
|
2010-06-01 19:01:33 +00:00
|
|
|
if (text)
|
2020-05-03 16:19:17 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (gtk_combo_box_get_child (GTK_COMBO_BOX (combo))), text);
|
2010-06-01 19:01:33 +00:00
|
|
|
g_free (text);
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
2008-06-08 22:25:57 +00:00
|
|
|
|
|
|
|
combo = gtk_combo_box_new ();
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->model)
|
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), priv->model);
|
2008-06-08 22:25:57 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo),
|
2010-06-01 12:40:52 +00:00
|
|
|
cell, "text", priv->text_column,
|
2004-07-16 20:27:40 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* determine the current value */
|
2010-06-01 12:40:52 +00:00
|
|
|
if (priv->model)
|
2008-06-08 22:25:57 +00:00
|
|
|
{
|
|
|
|
search_data.cell = cell_combo;
|
|
|
|
search_data.found = FALSE;
|
2010-06-01 12:40:52 +00:00
|
|
|
gtk_tree_model_foreach (priv->model, find_text, &search_data);
|
2008-06-08 22:25:57 +00:00
|
|
|
if (search_data.found)
|
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo),
|
|
|
|
&(search_data.iter));
|
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_set (combo, "has-frame", FALSE, NULL);
|
2004-07-16 20:27:40 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (combo),
|
2005-09-01 05:11:46 +00:00
|
|
|
I_(GTK_CELL_RENDERER_COMBO_PATH),
|
2004-07-16 20:27:40 +00:00
|
|
|
g_strdup (path), g_free);
|
|
|
|
|
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
2008-08-11 09:17:49 +00:00
|
|
|
g_signal_connect (GTK_CELL_EDITABLE (combo), "editing-done",
|
2004-07-16 20:27:40 +00:00
|
|
|
G_CALLBACK (gtk_cell_renderer_combo_editing_done),
|
|
|
|
cell_combo);
|
2008-05-28 11:49:20 +00:00
|
|
|
g_signal_connect (GTK_CELL_EDITABLE (combo), "changed",
|
|
|
|
G_CALLBACK (gtk_cell_renderer_combo_changed),
|
|
|
|
cell_combo);
|
2018-01-06 20:06:12 +00:00
|
|
|
priv->focus_out_id = g_signal_connect (combo, "notify::has-focus",
|
|
|
|
G_CALLBACK (gtk_cell_renderer_combo_focus_change),
|
2010-06-01 12:40:52 +00:00
|
|
|
cell_combo);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2008-06-08 22:25:57 +00:00
|
|
|
priv->combo = combo;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
return GTK_CELL_EDITABLE (combo);
|
|
|
|
}
|