2005-02-05 04:51:19 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2002-11-21 03:45:03 +08:00
|
|
|
*
|
2002-11-23 05:08:04 +08:00
|
|
|
* gimppropwidgets.c
|
2007-02-12 19:01:08 +08:00
|
|
|
* Copyright (C) 2002-2007 Michael Natterer <mitch@gimp.org>
|
2004-04-18 23:12:42 +08:00
|
|
|
* Sven Neumann <sven@gimp.org>
|
2002-11-23 05:08:04 +08:00
|
|
|
*
|
2005-02-05 04:51:19 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2002-11-21 03:45:03 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-02-05 04:51:19 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2002-11-21 03:45:03 +08:00
|
|
|
*
|
2005-02-05 04:51:19 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2002-11-21 03:45:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-12-01 22:53:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gegl.h>
|
2002-11-21 03:45:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-07-27 03:56:47 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2002-11-21 03:45:03 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-02-05 04:48:02 +08:00
|
|
|
#include "gimpwidgets.h"
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-02-05 04:48:02 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimppropwidgets
|
|
|
|
* @title: GimpPropWidgets
|
|
|
|
* @short_description: Editable views on #GObject properties.
|
|
|
|
*
|
|
|
|
* Editable views on #GObject properties.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
/* utility function prototypes */
|
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
static void set_param_spec (GObject *object,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GParamSpec *param_spec);
|
2004-10-22 10:15:14 +08:00
|
|
|
static void set_radio_spec (GObject *object,
|
|
|
|
GParamSpec *param_spec);
|
2003-10-24 00:58:16 +08:00
|
|
|
static GParamSpec * get_param_spec (GObject *object);
|
|
|
|
|
|
|
|
static GParamSpec * find_param_spec (GObject *object,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *strloc);
|
|
|
|
static GParamSpec * check_param_spec (GObject *object,
|
|
|
|
const gchar *property_name,
|
2007-02-12 19:01:08 +08:00
|
|
|
GType type,
|
|
|
|
const gchar *strloc);
|
|
|
|
static GParamSpec * check_param_spec_w (GObject *object,
|
|
|
|
const gchar *property_name,
|
|
|
|
GType type,
|
2003-10-24 00:58:16 +08:00
|
|
|
const gchar *strloc);
|
|
|
|
|
|
|
|
static gboolean get_numeric_values (GObject *object,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
gdouble *value,
|
|
|
|
gdouble *lower,
|
|
|
|
gdouble *upper,
|
|
|
|
const gchar *strloc);
|
|
|
|
|
|
|
|
static void connect_notify (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GCallback callback,
|
|
|
|
gpointer callback_data);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2020-11-25 09:19:39 +08:00
|
|
|
static gboolean gimp_prop_widget_double_to_factor (GBinding *binding,
|
|
|
|
const GValue *from_value,
|
|
|
|
GValue *to_value,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean gimp_prop_widget_double_from_factor (GBinding *binding,
|
|
|
|
const GValue *from_value,
|
|
|
|
GValue *to_value,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
/******************/
|
|
|
|
/* check button */
|
|
|
|
/******************/
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_check_button_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of boolean property controlled by checkbutton.
|
|
|
|
* @label: Label to give checkbutton (including mnemonic).
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GtkCheckButton that displays and sets the specified
|
2005-07-12 04:26:51 +08:00
|
|
|
* boolean property.
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @label is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned button.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GtkCheckButton widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_check_button_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *label)
|
|
|
|
{
|
2003-01-26 04:29:42 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *button;
|
2020-05-15 22:43:35 +08:00
|
|
|
const gchar *blurb;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! label)
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2006-09-23 02:22:53 +08:00
|
|
|
button = gtk_check_button_new_with_mnemonic (label);
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
blurb = g_param_spec_get_blurb (param_spec);
|
|
|
|
if (blurb)
|
2020-09-16 02:34:42 +08:00
|
|
|
gimp_help_set_help_data (button, blurb, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
g_object_bind_property (config, property_name,
|
|
|
|
button, "active",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
return button;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-25 01:58:28 +08:00
|
|
|
static void gimp_prop_enum_check_button_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_enum_check_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *button);
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_enum_check_button_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by checkbutton.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @label: (nullable): Label to give checkbutton (including mnemonic).
|
2005-07-12 04:26:51 +08:00
|
|
|
* @false_value: Enum value corresponding to unchecked state.
|
2018-04-19 02:57:03 +08:00
|
|
|
* @true_value: Enum value corresponding to checked state.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GtkCheckButton that displays and sets the specified
|
|
|
|
* property of type Enum. Note that this widget only allows two values
|
|
|
|
* for the enum, one corresponding to the "checked" state and the
|
|
|
|
* other to the "unchecked" state.
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @label is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned button.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GtkCheckButton widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-03-25 01:58:28 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_enum_check_button_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *label,
|
|
|
|
gint false_value,
|
|
|
|
gint true_value)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *button;
|
|
|
|
gint value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
2003-03-25 01:58:28 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! label)
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2003-03-25 01:58:28 +08:00
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
button = gtk_check_button_new_with_mnemonic (label);
|
2005-07-12 04:26:51 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
|
|
|
value == true_value);
|
2003-03-25 01:58:28 +08:00
|
|
|
|
|
|
|
if (value != false_value && value != true_value)
|
|
|
|
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
|
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (button), button, param_spec);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (button), "false-value",
|
|
|
|
GINT_TO_POINTER (false_value));
|
|
|
|
g_object_set_data (G_OBJECT (button), "true-value",
|
|
|
|
GINT_TO_POINTER (true_value));
|
|
|
|
|
|
|
|
g_signal_connect (button, "toggled",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_enum_check_button_callback),
|
|
|
|
config);
|
2003-03-25 01:58:28 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_enum_check_button_notify),
|
|
|
|
button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2003-03-25 01:58:28 +08:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_enum_check_button_callback (GtkWidget *widget,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gint false_value;
|
|
|
|
gint true_value;
|
2018-02-05 02:50:10 +08:00
|
|
|
gint value;
|
|
|
|
gint v;
|
2003-03-25 01:58:28 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (widget));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
|
|
|
|
"false-value"));
|
|
|
|
true_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
|
|
|
|
"true-value"));
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
value = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ?
|
|
|
|
true_value : false_value);
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
{
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2003-03-25 01:58:28 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), FALSE);
|
|
|
|
}
|
2003-03-25 01:58:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_enum_check_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *button)
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
gint false_value;
|
|
|
|
gint true_value;
|
|
|
|
gboolean active = FALSE;
|
|
|
|
gboolean inconsistent = FALSE;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
|
|
|
|
"false-value"));
|
|
|
|
true_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
|
|
|
|
"true-value"));
|
|
|
|
|
|
|
|
if (value == true_value)
|
|
|
|
active = TRUE;
|
|
|
|
else if (value != false_value)
|
|
|
|
inconsistent = TRUE;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button),
|
|
|
|
inconsistent);
|
|
|
|
|
2008-06-28 23:09:46 +08:00
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) != active)
|
2003-03-25 01:58:28 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (button,
|
|
|
|
gimp_prop_enum_check_button_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (button,
|
|
|
|
gimp_prop_enum_check_button_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-30 21:20:06 +08:00
|
|
|
/******************/
|
|
|
|
/* switch */
|
|
|
|
/******************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_switch_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of boolean property controlled by checkbutton.
|
|
|
|
* @label: Label to give checkbutton (including mnemonic).
|
|
|
|
* @label_out: (out) (optional) (transfer none): The generated #GtkLabel
|
|
|
|
* @switch_out: (out) (optional) (transfer none): The generated #GtkSwitch
|
|
|
|
*
|
|
|
|
* Creates a #GtkBox with a switch and a label that displays and sets the
|
|
|
|
* specified boolean property.
|
|
|
|
* If @label is %NULL, the @property_name's nick will be used as label.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): The newly created box containing a #GtkSwitch.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_switch_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *label,
|
|
|
|
GtkWidget **label_out,
|
|
|
|
GtkWidget **switch_out)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
const gchar *tooltip;
|
|
|
|
GtkWidget *plabel;
|
|
|
|
GtkWidget *pswitch;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! label)
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
|
|
|
|
tooltip = g_param_spec_get_blurb (param_spec);
|
|
|
|
|
|
|
|
pswitch = gtk_switch_new ();
|
|
|
|
g_object_bind_property (config, property_name, pswitch, "active",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
gimp_help_set_help_data (pswitch, tooltip, NULL);
|
|
|
|
gtk_widget_show (pswitch);
|
|
|
|
|
|
|
|
plabel = gtk_label_new_with_mnemonic (label);
|
2020-11-13 19:36:45 +08:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (plabel), 0.0);
|
2020-05-30 21:20:06 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (plabel), pswitch);
|
|
|
|
gimp_help_set_help_data (plabel, tooltip, NULL);
|
|
|
|
gtk_widget_show (plabel);
|
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), plabel, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), pswitch, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
if (label_out)
|
|
|
|
*label_out = plabel;
|
|
|
|
if (switch_out)
|
|
|
|
*switch_out = pswitch;
|
|
|
|
|
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-08 20:46:21 +08:00
|
|
|
/*************************/
|
|
|
|
/* int/enum combo box */
|
|
|
|
/*************************/
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2016-01-22 04:43:15 +08:00
|
|
|
static void gimp_prop_int_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_int_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_prop_pointer_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_pointer_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo_box);
|
2004-12-08 20:46:21 +08:00
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_int_combo_box_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of int property controlled by combo box.
|
|
|
|
* @store: #GimpIntStore holding list of labels, values, etc.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GimpIntComboBox widget to display and set the specified
|
|
|
|
* property. The contents of the widget are determined by @store,
|
|
|
|
* which should be created using gimp_int_store_new().
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GimpIntComboBox widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2004-12-08 20:46:21 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_int_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GimpIntStore *store)
|
|
|
|
{
|
2020-09-16 02:34:42 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *combo_box;
|
2020-05-15 22:43:35 +08:00
|
|
|
const gchar *blurb;
|
2004-12-08 20:46:21 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_INT, G_STRFUNC);
|
2004-12-08 20:46:21 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
|
|
|
|
"model", store,
|
2020-05-15 22:43:35 +08:00
|
|
|
"visible", TRUE,
|
2004-12-08 20:46:21 +08:00
|
|
|
NULL);
|
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
blurb = g_param_spec_get_blurb (param_spec);
|
|
|
|
if (blurb)
|
2020-09-16 02:34:42 +08:00
|
|
|
gimp_help_set_help_data (combo_box, blurb, NULL);
|
2004-12-08 20:46:21 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
g_object_bind_property (config, property_name,
|
2020-09-18 21:19:24 +08:00
|
|
|
combo_box, "value",
|
2020-05-15 22:43:35 +08:00
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2019-09-26 02:24:06 +08:00
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
return combo_box;
|
2004-12-08 20:46:21 +08:00
|
|
|
}
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2016-01-22 04:43:15 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_pointer_combo_box_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of GType/gpointer property controlled by combo box.
|
|
|
|
* @store: #GimpIntStore holding list of labels, values, etc.
|
|
|
|
*
|
|
|
|
* Creates a #GimpIntComboBox widget to display and set the specified
|
|
|
|
* property. The contents of the widget are determined by @store,
|
|
|
|
* which should be created using gimp_int_store_new().
|
|
|
|
* Values are GType/gpointer data, and therefore must be stored in the
|
|
|
|
* "user-data" column, instead of the usual "value" column.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GimpIntComboBox widget.
|
2016-01-22 04:43:15 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.10
|
2016-01-22 04:43:15 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_pointer_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GimpIntStore *store)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
gpointer property_value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_GTYPE, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
{
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_POINTER, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &property_value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* We use a GimpIntComboBox but we cannot store gpointer in the
|
|
|
|
* "value" column, because gpointer is not a subset of gint. Instead
|
|
|
|
* we store the value in the "user-data" column which is a gpointer.
|
|
|
|
*/
|
|
|
|
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
|
|
|
|
"model", store,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_int_combo_box_set_active_by_user_data (GIMP_INT_COMBO_BOX (combo_box),
|
|
|
|
property_value);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
|
|
|
G_CALLBACK (gimp_prop_pointer_combo_box_callback),
|
|
|
|
config);
|
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (combo_box), combo_box, param_spec);
|
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_pointer_combo_box_notify),
|
|
|
|
combo_box);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (combo_box);
|
|
|
|
|
2016-01-22 04:43:15 +08:00
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_enum_combo_box_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by combo box.
|
|
|
|
* @minimum: Smallest allowed value of enum.
|
|
|
|
* @maximum: Largest allowed value of enum.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GimpIntComboBox widget to display and set the specified
|
2005-07-12 04:26:51 +08:00
|
|
|
* enum property. The @mimimum_value and @maximum_value give the
|
2005-02-04 06:31:55 +08:00
|
|
|
* possibility of restricting the allowed range to a subset of the
|
|
|
|
* enum. If the two values are equal (e.g., 0, 0), then the full
|
|
|
|
* range of the Enum is used.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GimpEnumComboBox widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-23 05:08:04 +08:00
|
|
|
GtkWidget *
|
2004-04-18 23:12:42 +08:00
|
|
|
gimp_prop_enum_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint minimum,
|
|
|
|
gint maximum)
|
2002-11-23 05:08:04 +08:00
|
|
|
{
|
2017-05-10 01:07:39 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkListStore *store = NULL;
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
gint value;
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
2002-11-23 05:08:04 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2004-04-18 23:12:42 +08:00
|
|
|
if (minimum != maximum)
|
|
|
|
{
|
|
|
|
store = gimp_enum_store_new_with_range (param_spec->value_type,
|
|
|
|
minimum, maximum);
|
2017-03-18 05:50:12 +08:00
|
|
|
}
|
|
|
|
else if (param_spec->value_type == GIMP_TYPE_DESATURATE_MODE)
|
|
|
|
{
|
|
|
|
/* this is a bad hack, if we get more of those, we should probably
|
|
|
|
* think of something less ugly
|
|
|
|
*/
|
|
|
|
store = gimp_enum_store_new_with_values (param_spec->value_type,
|
|
|
|
5,
|
|
|
|
GIMP_DESATURATE_LUMINANCE,
|
|
|
|
GIMP_DESATURATE_LUMA,
|
|
|
|
GIMP_DESATURATE_LIGHTNESS,
|
|
|
|
GIMP_DESATURATE_AVERAGE,
|
|
|
|
GIMP_DESATURATE_VALUE);
|
2017-05-10 01:07:39 +08:00
|
|
|
}
|
2017-03-18 05:50:12 +08:00
|
|
|
|
2017-05-10 01:07:39 +08:00
|
|
|
if (store)
|
|
|
|
{
|
2017-03-18 05:50:12 +08:00
|
|
|
combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
|
|
|
|
"model", store,
|
|
|
|
NULL);
|
2004-04-18 23:12:42 +08:00
|
|
|
g_object_unref (store);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combo_box = gimp_enum_combo_box_new (param_spec->value_type);
|
|
|
|
}
|
|
|
|
|
2004-04-21 03:06:37 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value);
|
2004-04-18 23:12:42 +08:00
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
2004-12-08 20:46:21 +08:00
|
|
|
G_CALLBACK (gimp_prop_int_combo_box_callback),
|
2004-04-18 23:12:42 +08:00
|
|
|
config);
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
set_param_spec (G_OBJECT (combo_box), combo_box, param_spec);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
2004-12-08 20:46:21 +08:00
|
|
|
G_CALLBACK (gimp_prop_int_combo_box_notify),
|
2004-04-18 23:12:42 +08:00
|
|
|
combo_box);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (combo_box);
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
return combo_box;
|
2004-04-18 23:12:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-12-08 20:46:21 +08:00
|
|
|
gimp_prop_int_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config)
|
2004-04-18 23:12:42 +08:00
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (widget));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2004-04-21 03:06:37 +08:00
|
|
|
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value))
|
2004-04-18 23:12:42 +08:00
|
|
|
{
|
2018-02-05 02:50:10 +08:00
|
|
|
gint v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2004-04-18 23:12:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-12-08 20:46:21 +08:00
|
|
|
gimp_prop_int_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo_box)
|
2004-04-18 23:12:42 +08:00
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2004-07-08 20:50:15 +08:00
|
|
|
g_signal_handlers_block_by_func (combo_box,
|
2004-12-08 20:46:21 +08:00
|
|
|
gimp_prop_int_combo_box_callback,
|
2004-07-08 20:50:15 +08:00
|
|
|
config);
|
|
|
|
|
2004-07-08 21:17:06 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value);
|
2004-07-08 20:50:15 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (combo_box,
|
2004-12-08 20:46:21 +08:00
|
|
|
gimp_prop_int_combo_box_callback,
|
2004-07-08 20:50:15 +08:00
|
|
|
config);
|
2002-11-23 05:08:04 +08:00
|
|
|
}
|
|
|
|
|
2016-01-22 04:43:15 +08:00
|
|
|
static void
|
|
|
|
gimp_prop_pointer_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (widget));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gimp_int_combo_box_get_active_user_data (GIMP_INT_COMBO_BOX (widget),
|
|
|
|
&value))
|
|
|
|
{
|
2018-02-05 02:50:10 +08:00
|
|
|
gpointer v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2016-01-22 04:43:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_pointer_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo_box)
|
|
|
|
{
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (combo_box,
|
|
|
|
gimp_prop_pointer_combo_box_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_int_combo_box_set_active_by_user_data (GIMP_INT_COMBO_BOX (combo_box),
|
|
|
|
value);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (combo_box,
|
|
|
|
gimp_prop_pointer_combo_box_callback,
|
|
|
|
config);
|
|
|
|
}
|
2004-04-18 23:12:42 +08:00
|
|
|
|
2004-04-19 07:48:30 +08:00
|
|
|
/************************/
|
|
|
|
/* boolean combo box */
|
|
|
|
/************************/
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
static void gimp_prop_boolean_combo_box_callback (GtkWidget *combo,
|
2004-04-19 07:48:30 +08:00
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_boolean_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2017-05-01 06:39:49 +08:00
|
|
|
GtkWidget *combo);
|
2004-04-18 23:12:42 +08:00
|
|
|
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_boolean_combo_box_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of boolean property controlled by combo box.
|
|
|
|
* @true_text: Label used for entry corresponding to %TRUE value.
|
|
|
|
* @false_text: Label used for entry corresponding to %FALSE value.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GtkComboBox widget to display and set the specified
|
2005-07-12 04:26:51 +08:00
|
|
|
* boolean property. The combo box will have two entries, one
|
2005-02-04 06:31:55 +08:00
|
|
|
* displaying the @true_text label, the other displaying the
|
|
|
|
* @false_text label.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GtkComboBox widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *
|
2004-04-19 07:48:30 +08:00
|
|
|
gimp_prop_boolean_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *true_text,
|
|
|
|
const gchar *false_text)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2017-05-01 06:39:49 +08:00
|
|
|
GtkWidget *combo;
|
2004-04-19 07:48:30 +08:00
|
|
|
gboolean value;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
combo = gimp_int_combo_box_new (true_text, TRUE,
|
|
|
|
false_text, FALSE,
|
|
|
|
NULL);
|
2004-04-19 07:48:30 +08:00
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), value);
|
2004-04-19 07:48:30 +08:00
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
g_signal_connect (combo, "changed",
|
2004-04-19 07:48:30 +08:00
|
|
|
G_CALLBACK (gimp_prop_boolean_combo_box_callback),
|
|
|
|
config);
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
set_param_spec (G_OBJECT (combo), combo, param_spec);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, property_name,
|
2004-04-19 07:48:30 +08:00
|
|
|
G_CALLBACK (gimp_prop_boolean_combo_box_notify),
|
2017-05-01 06:39:49 +08:00
|
|
|
combo);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
return combo;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
2004-04-19 07:48:30 +08:00
|
|
|
static void
|
2017-05-01 06:39:49 +08:00
|
|
|
gimp_prop_boolean_combo_box_callback (GtkWidget *combo,
|
2004-04-19 07:48:30 +08:00
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gint value;
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
param_spec = get_param_spec (G_OBJECT (combo));
|
2004-04-19 07:48:30 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo), &value))
|
|
|
|
{
|
2018-02-05 02:50:10 +08:00
|
|
|
gint v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2017-05-01 06:39:49 +08:00
|
|
|
}
|
2004-04-19 07:48:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_boolean_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2017-05-01 06:39:49 +08:00
|
|
|
GtkWidget *combo)
|
2004-04-19 07:48:30 +08:00
|
|
|
{
|
2017-05-01 06:39:49 +08:00
|
|
|
gboolean value;
|
2004-04-19 07:48:30 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
g_signal_handlers_block_by_func (combo,
|
2004-07-08 21:17:06 +08:00
|
|
|
gimp_prop_boolean_combo_box_callback,
|
|
|
|
config);
|
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), value);
|
2004-07-08 21:17:06 +08:00
|
|
|
|
2017-05-01 06:39:49 +08:00
|
|
|
g_signal_handlers_unblock_by_func (combo,
|
2004-07-08 21:17:06 +08:00
|
|
|
gimp_prop_boolean_combo_box_callback,
|
|
|
|
config);
|
2004-04-19 07:48:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
/*****************/
|
|
|
|
/* radio boxes */
|
|
|
|
/*****************/
|
2003-02-05 21:03:44 +08:00
|
|
|
|
|
|
|
static void gimp_prop_radio_button_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_radio_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *button);
|
|
|
|
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_enum_radio_frame_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by the radio buttons.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @title: (nullable): Label for the frame holding the buttons
|
2005-07-12 04:26:51 +08:00
|
|
|
* @minimum: Smallest value of enum to be included.
|
|
|
|
* @maximum: Largest value of enum to be included.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a group of radio buttons which function to set and display
|
2005-07-12 04:26:51 +08:00
|
|
|
* the specified enum property. The @minimum and @maximum arguments
|
2005-02-04 06:31:55 +08:00
|
|
|
* allow only a subset of the enum to be used. If the two arguments
|
|
|
|
* are equal (e.g., 0, 0), then the full range of the enum will be used.
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @title is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned frame.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A #GimpFrame containing the radio buttons.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-02-08 01:12:21 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_enum_radio_frame_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
2005-02-05 19:51:48 +08:00
|
|
|
const gchar *title,
|
2003-02-08 01:12:21 +08:00
|
|
|
gint minimum,
|
|
|
|
gint maximum)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *button;
|
|
|
|
gint value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
2003-02-08 01:12:21 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! title)
|
|
|
|
title = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (minimum != maximum)
|
|
|
|
{
|
|
|
|
frame = gimp_enum_radio_frame_new_with_range (param_spec->value_type,
|
|
|
|
minimum, maximum,
|
2005-02-05 19:51:48 +08:00
|
|
|
gtk_label_new (title),
|
2003-02-08 01:12:21 +08:00
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2003-02-08 01:12:21 +08:00
|
|
|
&button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame = gimp_enum_radio_frame_new (param_spec->value_type,
|
2005-02-05 19:51:48 +08:00
|
|
|
gtk_label_new (title),
|
2003-02-08 01:12:21 +08:00
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2003-02-08 01:12:21 +08:00
|
|
|
&button);
|
|
|
|
}
|
|
|
|
|
2003-11-15 07:17:38 +08:00
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
set_radio_spec (G_OBJECT (button), param_spec);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_notify),
|
|
|
|
button);
|
|
|
|
|
2003-10-19 23:38:10 +08:00
|
|
|
g_object_set_data (G_OBJECT (frame), "radio-button", button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_enum_radio_box_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by the radio buttons.
|
|
|
|
* @minimum: Smallest value of enum to be included.
|
|
|
|
* @maximum: Largest value of enum to be included.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a group of radio buttons which function to set and display
|
2005-07-12 04:26:51 +08:00
|
|
|
* the specified enum property. The @minimum and @maximum arguments
|
2005-02-04 06:31:55 +08:00
|
|
|
* allow only a subset of the enum to be used. If the two arguments
|
|
|
|
* are equal (e.g., 0, 0), then the full range of the enum will be used.
|
|
|
|
* If you want to assign a label to the group of radio buttons, use
|
|
|
|
* gimp_prop_enum_radio_frame_new() instead of this function.
|
|
|
|
*
|
2019-10-03 21:59:09 +08:00
|
|
|
* Returns: (transfer full): A #GtkBox containing the radio buttons.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2004-05-03 23:37:56 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_enum_radio_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint minimum,
|
|
|
|
gint maximum)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
gint value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
2004-05-03 23:37:56 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (minimum != maximum)
|
|
|
|
{
|
|
|
|
vbox = gimp_enum_radio_box_new_with_range (param_spec->value_type,
|
|
|
|
minimum, maximum,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2004-05-03 23:37:56 +08:00
|
|
|
&button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vbox = gimp_enum_radio_box_new (param_spec->value_type,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2004-05-03 23:37:56 +08:00
|
|
|
&button);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
|
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
set_radio_spec (G_OBJECT (button), param_spec);
|
2004-05-03 23:37:56 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_notify),
|
|
|
|
button);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (vbox), "radio-button", button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2004-05-03 23:37:56 +08:00
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
2019-10-03 21:59:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_int_radio_frame_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by the radio buttons.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @title: (nullable): Label for the frame holding the buttons
|
2019-10-03 21:59:09 +08:00
|
|
|
* @store: #GimpIntStore holding list of labels, values, etc.
|
|
|
|
*
|
|
|
|
* Creates a group of radio buttons which function to set and display
|
|
|
|
* the specified int property. If @title is %NULL, the
|
|
|
|
* @property_name's nick will be used as label of the returned frame.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): A #GimpFrame containing the radio buttons.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_int_radio_frame_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *title,
|
|
|
|
GimpIntStore *store)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
|
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_INT, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! title)
|
|
|
|
title = g_param_spec_get_nick (param_spec);
|
|
|
|
|
|
|
|
frame = gimp_frame_new (title);
|
|
|
|
|
|
|
|
box = gimp_prop_int_radio_box_new (config, property_name, store);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), box);
|
|
|
|
gtk_widget_show (box);
|
|
|
|
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_int_radio_box_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by the radio buttons.
|
|
|
|
* @store: #GimpIntStore holding list of labels, values, etc.
|
|
|
|
*
|
|
|
|
* Creates a group of radio buttons which function to set and display
|
|
|
|
* the specified int property. If you want to assign a label to the
|
|
|
|
* group of radio buttons, use gimp_prop_int_radio_frame_new()
|
|
|
|
* instead of this function.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): A #GtkBox containing the radio buttons.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_int_radio_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GimpIntStore *store)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *button = NULL;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean iter_valid;
|
|
|
|
GSList *group = NULL;
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
|
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_INT, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (store);
|
|
|
|
|
|
|
|
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
|
|
|
|
iter_valid;
|
|
|
|
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
|
|
|
{
|
|
|
|
gchar *label;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
GIMP_INT_STORE_LABEL, &label,
|
|
|
|
GIMP_INT_STORE_VALUE, &value,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
button = gtk_radio_button_new_with_mnemonic (group, label);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_free (label);
|
|
|
|
|
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (button), "gimp-item-data",
|
|
|
|
GINT_TO_POINTER (value));
|
|
|
|
|
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
|
|
|
|
|
|
|
|
set_radio_spec (G_OBJECT (button), param_spec);
|
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_notify),
|
|
|
|
button);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (vbox), "radio-button", button);
|
|
|
|
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
/***********/
|
|
|
|
/* label */
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
static void gimp_prop_enum_label_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *label);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_enum_label_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property to be displayed.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GimpEnumLabel widget.
|
2005-06-25 06:46:42 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-06-25 06:46:42 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_enum_label_new (GObject *config,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *label;
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
|
|
|
param_spec = check_param_spec (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
label = gimp_enum_label_new (param_spec->value_type, value);
|
2018-05-17 03:18:34 +08:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2005-06-25 06:46:42 +08:00
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
set_param_spec (G_OBJECT (label), label, param_spec);
|
2005-06-25 06:46:42 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_enum_label_notify),
|
|
|
|
label);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2005-06-25 06:46:42 +08:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_enum_label_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *label)
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_enum_label_set_value (GIMP_ENUM_LABEL (label), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_boolean_radio_frame_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of boolean property controlled by the radio buttons.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @title: (nullable): Label for the frame.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @true_text: Label for the button corresponding to %TRUE.
|
|
|
|
* @false_text: Label for the button corresponding to %FALSE.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a pair of radio buttons which function to set and display
|
2005-07-12 04:26:51 +08:00
|
|
|
* the specified boolean property.
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @title is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned frame.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A #GimpFrame containing the radio buttons.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-02-08 01:12:21 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_boolean_radio_frame_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *title,
|
|
|
|
const gchar *true_text,
|
|
|
|
const gchar *false_text)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *button;
|
|
|
|
gboolean value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
|
2003-02-08 01:12:21 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! title)
|
|
|
|
title = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2003-11-15 02:05:39 +08:00
|
|
|
frame =
|
|
|
|
gimp_int_radio_group_new (TRUE, title,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2020-01-15 20:51:55 +08:00
|
|
|
config, NULL, value,
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2003-11-15 02:05:39 +08:00
|
|
|
false_text, FALSE, &button,
|
|
|
|
true_text, TRUE, NULL,
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2003-11-15 02:05:39 +08:00
|
|
|
NULL);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
set_radio_spec (G_OBJECT (button), param_spec);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_notify),
|
|
|
|
button);
|
|
|
|
|
2003-10-19 23:38:10 +08:00
|
|
|
g_object_set_data (G_OBJECT (frame), "radio-button", button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-05-08 03:27:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_enum_icon_box_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of enum property controlled by the radio buttons.
|
|
|
|
* @icon_prefix: The prefix of the group of icon names to use.
|
|
|
|
* @minimum: Smallest value of enum to be included.
|
|
|
|
* @maximum: Largest value of enum to be included.
|
|
|
|
*
|
|
|
|
* Creates a horizontal box of radio buttons with named icons, which
|
|
|
|
* function to set and display the value of the specified Enum
|
|
|
|
* property. The icon name for each icon is created by appending the
|
|
|
|
* enum_value's nick to the given @icon_prefix. See
|
|
|
|
* gimp_enum_icon_box_new() for more information.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A #libgimpwidgets-gimpenumiconbox containing the radio buttons.
|
2014-05-08 03:27:57 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.10
|
2014-05-08 03:27:57 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_enum_icon_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *icon_prefix,
|
|
|
|
gint minimum,
|
|
|
|
gint maximum)
|
2003-02-05 21:03:44 +08:00
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *button;
|
|
|
|
gint value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_ENUM, G_STRFUNC);
|
2003-02-05 21:03:44 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (minimum != maximum)
|
|
|
|
{
|
2014-05-08 03:27:57 +08:00
|
|
|
box = gimp_enum_icon_box_new_with_range (param_spec->value_type,
|
|
|
|
minimum, maximum,
|
|
|
|
icon_prefix,
|
|
|
|
GTK_ICON_SIZE_MENU,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2014-05-08 03:27:57 +08:00
|
|
|
&button);
|
2003-02-05 21:03:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-08 03:27:57 +08:00
|
|
|
box = gimp_enum_icon_box_new (param_spec->value_type,
|
|
|
|
icon_prefix,
|
|
|
|
GTK_ICON_SIZE_MENU,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_callback),
|
2019-08-08 06:01:10 +08:00
|
|
|
config, NULL,
|
2014-05-08 03:27:57 +08:00
|
|
|
&button);
|
2003-02-05 21:03:44 +08:00
|
|
|
}
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2003-11-15 07:17:38 +08:00
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
|
2003-02-05 21:03:44 +08:00
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
set_radio_spec (G_OBJECT (button), param_spec);
|
2003-02-05 21:03:44 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_radio_button_notify),
|
|
|
|
button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (box);
|
|
|
|
|
2003-02-05 21:03:44 +08:00
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_radio_button_callback (GtkWidget *widget,
|
|
|
|
GObject *config)
|
|
|
|
{
|
2008-06-28 23:09:46 +08:00
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
2003-02-08 01:12:21 +08:00
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gint value;
|
2018-02-05 02:50:10 +08:00
|
|
|
gint v;
|
2003-02-05 21:03:44 +08:00
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
param_spec = get_param_spec (G_OBJECT (widget));
|
2003-02-08 01:12:21 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return;
|
2003-02-05 21:03:44 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
|
|
|
|
"gimp-item-data"));
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2003-02-08 01:12:21 +08:00
|
|
|
}
|
2003-02-05 21:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_radio_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *button)
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2003-11-15 07:17:38 +08:00
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
|
2003-02-05 21:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
/*****************/
|
|
|
|
/* adjustments */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
static void gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_adjustment_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkAdjustment *adjustment);
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_spin_button_new:
|
2005-02-05 04:48:02 +08:00
|
|
|
* @config: Object to which property is attached.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @property_name: Name of double property controlled by the spin button.
|
2005-02-04 06:31:55 +08:00
|
|
|
* @step_increment: Step size.
|
|
|
|
* @page_increment: Page size.
|
|
|
|
* @digits: Number of digits after decimal point to display.
|
|
|
|
*
|
|
|
|
* Creates a spin button to set and display the value of the
|
2005-07-12 04:26:51 +08:00
|
|
|
* specified double property.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #libgimpwidgets-gimpspinbutton.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_spin_button_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gdouble step_increment,
|
|
|
|
gdouble page_increment,
|
|
|
|
gint digits)
|
|
|
|
{
|
2014-06-22 04:35:39 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
gdouble value;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
if (! get_numeric_values (config,
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec, &value, &lower, &upper, G_STRFUNC))
|
2003-10-24 00:58:16 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
if (! G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
digits = 0;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2018-06-25 00:15:16 +08:00
|
|
|
adjustment = gtk_adjustment_new (value, lower, upper,
|
|
|
|
step_increment, page_increment, 0);
|
2014-06-22 04:35:39 +08:00
|
|
|
|
2019-03-09 20:25:19 +08:00
|
|
|
spinbutton = gimp_spin_button_new (adjustment, step_increment, digits);
|
2014-06-22 04:35:39 +08:00
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-01-26 04:29:42 +08:00
|
|
|
set_param_spec (G_OBJECT (adjustment), spinbutton, param_spec);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (adjustment, "value-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_adjustment_callback),
|
|
|
|
config);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_adjustment_notify),
|
|
|
|
adjustment);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
return spinbutton;
|
2005-08-06 21:03:59 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 08:13:49 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_label_spin_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @digits: Number of digits after decimal point to display.
|
|
|
|
*
|
|
|
|
* Creates a #GimpLabelSpin to set and display the value of the
|
|
|
|
* specified double property.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): A new #libgimpwidgets-gimpspinbutton.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_label_spin_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint digits)
|
|
|
|
{
|
|
|
|
const gchar *label;
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *widget;
|
|
|
|
gdouble value;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
|
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! get_numeric_values (config,
|
|
|
|
param_spec, &value, &lower, &upper, G_STRFUNC))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
digits = 0;
|
|
|
|
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
widget = gimp_label_spin_new (label, value, lower, upper, digits);
|
|
|
|
|
|
|
|
g_object_bind_property (config, property_name,
|
|
|
|
widget, "value",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2005-08-06 21:03:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_hscale_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of integer or double property controlled by the scale.
|
|
|
|
* @step_increment: Step size.
|
|
|
|
* @page_increment: Page size.
|
|
|
|
* @digits: Number of digits after decimal point to display.
|
|
|
|
*
|
|
|
|
* Creates a horizontal scale to control the value of the specified
|
|
|
|
* integer or double property.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkScale.
|
2005-08-06 21:03:59 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-08-06 21:03:59 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_hscale_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gdouble step_increment,
|
|
|
|
gdouble page_increment,
|
|
|
|
gint digits)
|
|
|
|
{
|
2017-05-23 04:39:28 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *scale;
|
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
gdouble value;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
2005-08-06 21:03:59 +08:00
|
|
|
|
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! get_numeric_values (config,
|
|
|
|
param_spec, &value, &lower, &upper, G_STRFUNC))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (! G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
digits = 0;
|
|
|
|
|
2018-06-25 00:15:16 +08:00
|
|
|
adjustment = gtk_adjustment_new (value, lower, upper,
|
|
|
|
step_increment, page_increment, 0.0);
|
2005-08-06 21:03:59 +08:00
|
|
|
|
2016-09-10 03:52:09 +08:00
|
|
|
scale = g_object_new (GTK_TYPE_SCALE,
|
|
|
|
"orientation", GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
"adjustment", adjustment,
|
|
|
|
"digits", digits,
|
2005-08-06 21:03:59 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (adjustment), scale, param_spec);
|
|
|
|
|
|
|
|
g_signal_connect (adjustment, "value-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_adjustment_callback),
|
|
|
|
config);
|
2005-08-06 21:03:59 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_adjustment_notify),
|
|
|
|
adjustment);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (scale);
|
|
|
|
|
2005-08-06 21:03:59 +08:00
|
|
|
return scale;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_scale_entry_new:
|
2006-04-22 10:58:02 +08:00
|
|
|
* @config: Object to which property is attached.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @label: (nullable): The text for the #GtkLabel which will appear left of
|
|
|
|
* the #GtkHScale.
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
* @property_name: Name of integer or double property controlled by the scale.
|
2020-11-25 09:19:39 +08:00
|
|
|
* @factor: Optional multiplier to convert @property_name's
|
|
|
|
* range into the #GimpScaleEntry's range. The common
|
|
|
|
* usage is to set 1.0.
|
2020-11-26 07:27:43 +08:00
|
|
|
* For non-double properties, no other values than 1.0
|
|
|
|
* are acceptable.
|
2017-06-04 03:22:12 +08:00
|
|
|
* @limit_scale: %FALSE if the range of possible values of the
|
2013-12-26 20:57:27 +08:00
|
|
|
* GtkHScale should be the same as of the GtkSpinButton.
|
|
|
|
* @lower_limit: The scale's lower boundary if @scale_limits is %TRUE.
|
|
|
|
* @upper_limit: The scale's upper boundary if @scale_limits is %TRUE.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
* Creates a #GimpScaleEntry (slider and spin button) to set and display
|
2020-11-25 09:19:39 +08:00
|
|
|
* the value of a specified int or double property with sensible default
|
|
|
|
* settings depending on the range (decimal places, increments, etc.).
|
|
|
|
* These settings can be overridden by the relevant widget methods.
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
*
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @label is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned object.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2020-11-25 09:19:39 +08:00
|
|
|
* If @factor is not 1.0, the widget's range will be computed based of
|
|
|
|
* @property_name's range multiplied by @factor. A typical usage would
|
|
|
|
* be to display a [0.0, 1.0] range as [0.0, 100.0] by setting 100.0 as
|
|
|
|
* @factor.
|
|
|
|
*
|
|
|
|
* See gimp_scale_entry_set_bounds() for more information on
|
|
|
|
* @limit_scale, @lower_limit and @upper_limit.
|
|
|
|
*
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
* Returns: (transfer full): The newly allocated #GimpScaleEntry.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
GtkWidget *
|
2003-02-08 01:12:21 +08:00
|
|
|
gimp_prop_scale_entry_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *label,
|
2020-11-25 09:19:39 +08:00
|
|
|
gdouble factor,
|
2006-04-22 10:58:02 +08:00
|
|
|
gboolean limit_scale,
|
|
|
|
gdouble lower_limit,
|
|
|
|
gdouble upper_limit)
|
2003-02-08 01:12:21 +08:00
|
|
|
{
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
GtkWidget *widget;
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
const gchar *tooltip;
|
|
|
|
gdouble value;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
2020-11-26 07:27:43 +08:00
|
|
|
gint digits = -1;
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2020-11-25 09:19:39 +08:00
|
|
|
g_return_val_if_fail (factor != 0.0, NULL);
|
|
|
|
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
2003-02-08 01:12:21 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2020-11-26 07:27:43 +08:00
|
|
|
g_return_val_if_fail (G_IS_PARAM_SPEC_DOUBLE (param_spec) || factor == 1.0, NULL);
|
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
if (! get_numeric_values (config,
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec, &value, &lower, &upper, G_STRFUNC))
|
2003-10-24 00:58:16 +08:00
|
|
|
return NULL;
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! label)
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2020-11-26 07:27:43 +08:00
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec) || G_IS_PARAM_SPEC_UINT (param_spec))
|
|
|
|
digits = 0;
|
|
|
|
|
|
|
|
widget = gimp_scale_entry_new (label, value, lower * factor, upper * factor, digits);
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
if (limit_scale)
|
2020-11-25 09:19:39 +08:00
|
|
|
gimp_scale_entry_set_bounds (GIMP_SCALE_ENTRY (widget),
|
|
|
|
lower_limit, upper_limit,
|
|
|
|
FALSE);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
tooltip = g_param_spec_get_blurb (param_spec);
|
|
|
|
gimp_help_set_help_data (widget, tooltip, NULL);
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2020-11-26 07:27:43 +08:00
|
|
|
if (factor != 1.0)
|
|
|
|
{
|
|
|
|
gdouble *user_data;
|
|
|
|
|
|
|
|
user_data = g_new0 (gdouble, 1);
|
|
|
|
*user_data = factor;
|
|
|
|
/* With @factor == 1.0, this is equivalent to a
|
|
|
|
* g_object_bind_property().
|
|
|
|
*/
|
|
|
|
g_object_bind_property_full (config, property_name,
|
|
|
|
widget, "value",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
|
|
|
gimp_prop_widget_double_to_factor,
|
|
|
|
gimp_prop_widget_double_from_factor,
|
|
|
|
user_data, (GDestroyNotify) g_free);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_bind_property (config, property_name,
|
|
|
|
widget, "value",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
}
|
2003-02-20 04:06:38 +08:00
|
|
|
|
libgimpwidgets: make GimpScaleEntry into its own widget.
Instead of the gimp_scale_entry_new() which creates several bound yet
independant widgets, and in the same time pack them into an existing
grid and return a GtkAdjustment (while heavily relying on GObject data
to link widgets), let's have a proper custom widget with its own clean
API.
This also simplifies the gimp_prop_scale_entry_new() property widget
variant.
First advantage is that we don't force the usage of a grid to use this
widget (there are a few pieces of code which create a GtkGrid with only
this inside just to be able to use this feature).
Second thing is that I am creating a much simpler API.
gimp_scale_entry_new() had 17 parameters! How crazy is that? So I
removed all the grid packing related parameters. Also I moved the spin
button/scale unconstraining parameters into their separate function,
because the constrained behavior is the most common use case, so it's
stupid to add 3 permanent dummy parameters for most calls. Instead the
few times where we'll want different ranges for the spin button and the
scale, we'll call the separate API gimp_scale_entry_set_range().
Thirdly the tooltip can be set directly with gimp_help_set_help_data()
since this is now its own widget. No need to have dedicated logics
anymore, better stay generic. Similarly no need of a custom function to
switch sensitivitivy (instead of generic gtk_widget_set_sensitive()).
Fourth thing is that we should not use macros for the public API, but
proper functions, because macros are not properly introspected for
binding.
For future improvements, maybe we could even make this widget implement
GtkOrientable interface, in order to be able to use it vertically.
Note: right now, I created a separate gimp_scale_entry_new2() and only
modified the property widget API to use this new code. Eventually I will
remove fully the old gimp_scale_entry_new() function (and the new code
will replace it).
2020-10-30 07:30:03 +08:00
|
|
|
return widget;
|
2003-02-20 04:06:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
static void
|
|
|
|
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2008-08-29 23:54:10 +08:00
|
|
|
gdouble value;
|
2013-06-17 08:14:17 +08:00
|
|
|
gdouble *factor;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
param_spec = get_param_spec (G_OBJECT (adjustment));
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2008-08-29 23:54:10 +08:00
|
|
|
value = gtk_adjustment_get_value (adjustment);
|
|
|
|
|
2013-06-17 08:14:17 +08:00
|
|
|
factor = g_object_get_data (G_OBJECT (adjustment),
|
|
|
|
"gimp-prop-adjustment-factor");
|
|
|
|
if (factor)
|
|
|
|
value /= *factor;
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
gint v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (gint) value)
|
|
|
|
g_object_set (config, param_spec->name, (gint) value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_UINT (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
guint v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (guint) value)
|
|
|
|
g_object_set (config, param_spec->name, (guint) value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_LONG (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
glong v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (glong) value)
|
|
|
|
g_object_set (config, param_spec->name, (glong) value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
gulong v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (gulong) value)
|
|
|
|
g_object_set (config, param_spec->name, (gulong) value, NULL);
|
2003-11-14 21:41:16 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
gint64 v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (gint64) value)
|
|
|
|
g_object_set (config, param_spec->name, (gint64) value, NULL);
|
2003-11-14 21:41:16 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
guint64 v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != (guint64) value)
|
|
|
|
g_object_set (config, param_spec->name, (guint64) value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
{
|
2014-06-19 08:01:10 +08:00
|
|
|
gdouble v;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_adjustment_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
{
|
2013-06-17 08:14:17 +08:00
|
|
|
gdouble value;
|
|
|
|
gdouble *factor;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
gint int_value;
|
|
|
|
|
2003-02-20 04:06:38 +08:00
|
|
|
g_object_get (config, param_spec->name, &int_value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
value = int_value;
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_UINT (param_spec))
|
|
|
|
{
|
|
|
|
guint uint_value;
|
|
|
|
|
2003-02-20 04:06:38 +08:00
|
|
|
g_object_get (config, param_spec->name, &uint_value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
value = uint_value;
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_LONG (param_spec))
|
|
|
|
{
|
|
|
|
glong long_value;
|
|
|
|
|
2003-02-20 04:06:38 +08:00
|
|
|
g_object_get (config, param_spec->name, &long_value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
value = long_value;
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
|
|
|
|
{
|
|
|
|
gulong ulong_value;
|
|
|
|
|
2003-02-20 04:06:38 +08:00
|
|
|
g_object_get (config, param_spec->name, &ulong_value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
value = ulong_value;
|
|
|
|
}
|
2003-11-14 21:41:16 +08:00
|
|
|
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
|
|
|
|
{
|
|
|
|
gint64 int64_value;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &int64_value, NULL);
|
|
|
|
|
|
|
|
value = int64_value;
|
|
|
|
}
|
2003-11-17 05:57:46 +08:00
|
|
|
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
|
2003-11-14 21:41:16 +08:00
|
|
|
{
|
|
|
|
guint64 uint64_value;
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &uint64_value, NULL);
|
|
|
|
|
2004-11-21 22:22:45 +08:00
|
|
|
#if defined _MSC_VER && (_MSC_VER < 1300)
|
2003-11-17 05:20:14 +08:00
|
|
|
value = (gint64) uint64_value;
|
|
|
|
#else
|
2003-11-14 21:41:16 +08:00
|
|
|
value = uint64_value;
|
2003-11-17 05:20:14 +08:00
|
|
|
#endif
|
2003-11-14 21:41:16 +08:00
|
|
|
}
|
2002-11-21 03:45:03 +08:00
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
{
|
2003-02-20 04:06:38 +08:00
|
|
|
g_object_get (config, param_spec->name, &value, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-17 05:57:46 +08:00
|
|
|
g_warning ("%s: unhandled param spec of type %s",
|
2004-05-12 16:13:33 +08:00
|
|
|
G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (param_spec));
|
2002-11-21 03:45:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-17 08:14:17 +08:00
|
|
|
factor = g_object_get_data (G_OBJECT (adjustment),
|
|
|
|
"gimp-prop-adjustment-factor");
|
|
|
|
if (factor)
|
|
|
|
value *= *factor;
|
|
|
|
|
2008-08-29 23:54:10 +08:00
|
|
|
if (gtk_adjustment_get_value (adjustment) != value)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_block_by_func (adjustment,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_adjustment_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (adjustment, value);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_unblock_by_func (adjustment,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_adjustment_callback,
|
|
|
|
config);
|
2003-01-05 21:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************/
|
|
|
|
/* memsize */
|
|
|
|
/*************/
|
|
|
|
|
|
|
|
static void gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
|
2006-04-12 18:53:28 +08:00
|
|
|
GObject *config);
|
2003-01-05 21:52:14 +08:00
|
|
|
static void gimp_prop_memsize_notify (GObject *config,
|
2006-04-12 18:53:28 +08:00
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpMemsizeEntry *entry);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_memsize_entry_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of memsize property.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GimpMemsizeEntry (spin button and option menu) to set
|
|
|
|
* and display the value of the specified memsize property. See
|
|
|
|
* gimp_memsize_entry_new() for more information.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GimpMemsizeEntry.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-01-05 21:52:14 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_memsize_entry_new (GObject *config,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
2003-11-14 21:41:16 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GParamSpecUInt64 *uint64_spec;
|
|
|
|
GtkWidget *entry;
|
|
|
|
guint64 value;
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
GIMP_TYPE_PARAM_MEMSIZE, G_STRFUNC);
|
2003-01-05 21:52:14 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2003-11-14 21:41:16 +08:00
|
|
|
uint64_spec = G_PARAM_SPEC_UINT64 (param_spec);
|
|
|
|
|
2003-11-26 03:45:01 +08:00
|
|
|
g_return_val_if_fail (uint64_spec->minimum <= GIMP_MAX_MEMSIZE, NULL);
|
|
|
|
g_return_val_if_fail (uint64_spec->maximum <= GIMP_MAX_MEMSIZE, NULL);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
|
|
|
entry = gimp_memsize_entry_new (value,
|
2006-04-12 18:53:28 +08:00
|
|
|
uint64_spec->minimum,
|
|
|
|
uint64_spec->maximum);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2003-01-26 04:29:42 +08:00
|
|
|
set_param_spec (G_OBJECT (entry),
|
2011-01-03 21:03:00 +08:00
|
|
|
gimp_memsize_entry_get_spinbutton (GIMP_MEMSIZE_ENTRY (entry)),
|
2003-01-26 04:29:42 +08:00
|
|
|
param_spec);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (entry, "value-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_memsize_callback),
|
|
|
|
config);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_memsize_notify),
|
|
|
|
entry);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (entry);
|
|
|
|
|
2003-01-05 21:52:14 +08:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
|
2006-04-12 18:53:28 +08:00
|
|
|
GObject *config)
|
2003-01-05 21:52:14 +08:00
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2018-02-05 02:50:10 +08:00
|
|
|
guint64 value;
|
|
|
|
guint64 v;
|
2003-01-05 21:52:14 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (entry));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2003-11-14 21:41:16 +08:00
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC_UINT64 (param_spec));
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
value = gimp_memsize_entry_get_value (entry);
|
|
|
|
|
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (v != value)
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2003-01-05 21:52:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_memsize_notify (GObject *config,
|
2006-04-12 18:53:28 +08:00
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpMemsizeEntry *entry)
|
2003-01-05 21:52:14 +08:00
|
|
|
{
|
2003-11-14 21:41:16 +08:00
|
|
|
guint64 value;
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2003-11-14 21:41:16 +08:00
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC_UINT64 (param_spec));
|
2003-01-05 21:52:14 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
2006-04-12 18:53:28 +08:00
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
2003-01-05 21:52:14 +08:00
|
|
|
|
2011-01-03 21:03:00 +08:00
|
|
|
if (gimp_memsize_entry_get_value (entry) != value)
|
2003-01-05 21:52:14 +08:00
|
|
|
{
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2003-01-05 21:52:14 +08:00
|
|
|
gimp_prop_memsize_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_memsize_entry_set_value (entry, value);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2003-01-05 21:52:14 +08:00
|
|
|
gimp_prop_memsize_callback,
|
|
|
|
config);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-25 06:23:05 +08:00
|
|
|
/***********/
|
|
|
|
/* label */
|
|
|
|
/***********/
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_label_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of string property.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2007-02-12 16:44:25 +08:00
|
|
|
* Creates a #GtkLabel to display the value of the specified property.
|
|
|
|
* The property should be a string property or at least transformable
|
|
|
|
* to a string. If the user should be able to edit the string, use
|
2005-07-12 04:26:51 +08:00
|
|
|
* gimp_prop_entry_new() instead.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkLabel widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2004-06-25 06:23:05 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_label_new (GObject *config,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
2020-09-16 02:34:42 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *label;
|
2020-05-15 22:43:35 +08:00
|
|
|
const gchar *blurb;
|
2004-06-25 06:23:05 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 16:44:25 +08:00
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
2004-06-25 06:23:05 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2007-02-12 16:44:25 +08:00
|
|
|
label = gtk_label_new (NULL);
|
2018-05-04 08:19:39 +08:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
blurb = g_param_spec_get_blurb (param_spec);
|
|
|
|
if (blurb)
|
2020-09-16 02:34:42 +08:00
|
|
|
gimp_help_set_help_data (label, blurb, NULL);
|
2007-02-12 16:44:25 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
g_object_bind_property (config, property_name,
|
|
|
|
label, "label",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2004-06-25 06:23:05 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
return label;
|
2004-06-25 06:23:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
/***********/
|
|
|
|
/* entry */
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
static void gimp_prop_entry_callback (GtkWidget *entry,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_entry_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *entry);
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_entry_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of string property.
|
|
|
|
* @max_len: Maximum allowed length of string.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GtkEntry to set and display the value of the specified
|
|
|
|
* string property.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkEntry widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-23 05:08:04 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_entry_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint max_len)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *entry;
|
|
|
|
gchar *value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
param_spec = check_param_spec (config, property_name,
|
2004-05-12 16:13:33 +08:00
|
|
|
G_TYPE_PARAM_STRING, G_STRFUNC);
|
2002-11-23 05:08:04 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2005-05-08 23:53:21 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), value ? value : "");
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (max_len > 0)
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), max_len);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (entry),
|
|
|
|
param_spec->flags & G_PARAM_WRITABLE);
|
|
|
|
|
2003-01-26 04:29:42 +08:00
|
|
|
set_param_spec (G_OBJECT (entry), entry, param_spec);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_entry_callback),
|
|
|
|
config);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_entry_notify),
|
|
|
|
entry);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (entry);
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_entry_callback (GtkWidget *entry,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2018-02-05 02:50:10 +08:00
|
|
|
const gchar *value;
|
|
|
|
gchar *v;
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (entry));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
value = gtk_entry_get_text (GTK_ENTRY (entry));
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
if (g_strcmp0 (v, value))
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_entry_notify,
|
|
|
|
entry);
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_entry_notify,
|
|
|
|
entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (v);
|
2002-11-23 05:08:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_entry_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *entry)
|
|
|
|
{
|
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2002-11-23 05:08:04 +08:00
|
|
|
gimp_prop_entry_callback,
|
|
|
|
config);
|
|
|
|
|
2005-05-08 23:53:21 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), value ? value : "");
|
2002-11-23 05:08:04 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2002-11-23 05:08:04 +08:00
|
|
|
gimp_prop_entry_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
/*****************/
|
|
|
|
/* text buffer */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
static void gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_text_buffer_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkTextBuffer *text_buffer);
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_text_buffer_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of string property.
|
2005-11-02 23:02:06 +08:00
|
|
|
* @max_len: Maximum allowed length of text (in characters).
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GtkTextBuffer to set and display the value of the
|
|
|
|
* specified string property. Unless the string is expected to
|
|
|
|
* contain multiple lines or a large amount of text, use
|
|
|
|
* gimp_prop_entry_new() instead. See #GtkTextView for information on
|
|
|
|
* how to insert a text buffer into a visible widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2005-11-02 23:02:06 +08:00
|
|
|
* If @max_len is 0 or negative, the text buffer allows an unlimited
|
|
|
|
* number of characters to be entered.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkTextBuffer.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkTextBuffer *
|
|
|
|
gimp_prop_text_buffer_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint max_len)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkTextBuffer *text_buffer;
|
|
|
|
gchar *value;
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_STRING, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
text_buffer = gtk_text_buffer_new (NULL);
|
2003-02-21 00:11:23 +08:00
|
|
|
gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (max_len > 0)
|
|
|
|
g_object_set_data (G_OBJECT (text_buffer), "max-len",
|
|
|
|
GINT_TO_POINTER (max_len));
|
|
|
|
|
2003-01-26 04:29:42 +08:00
|
|
|
set_param_spec (G_OBJECT (text_buffer), NULL, param_spec);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (text_buffer, "changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_text_buffer_callback),
|
|
|
|
config);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_text_buffer_notify),
|
|
|
|
text_buffer);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
return text_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
|
|
|
|
GObject *config)
|
|
|
|
{
|
2002-11-23 05:08:04 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkTextIter start_iter;
|
|
|
|
GtkTextIter end_iter;
|
|
|
|
gchar *text;
|
|
|
|
gint max_len;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
param_spec = get_param_spec (G_OBJECT (text_buffer));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
gtk_text_buffer_get_bounds (text_buffer, &start_iter, &end_iter);
|
|
|
|
text = gtk_text_buffer_get_text (text_buffer, &start_iter, &end_iter, FALSE);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
max_len = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text_buffer),
|
|
|
|
"max-length"));
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-11-02 23:02:06 +08:00
|
|
|
if (max_len > 0 && g_utf8_strlen (text, -1) > max_len)
|
2002-11-23 05:08:04 +08:00
|
|
|
{
|
2005-11-02 22:45:06 +08:00
|
|
|
g_message (dngettext (GETTEXT_PACKAGE "-libgimp",
|
|
|
|
"This text input field is limited to %d character.",
|
|
|
|
"This text input field is limited to %d characters.",
|
|
|
|
max_len), max_len);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-11-02 23:02:06 +08:00
|
|
|
gtk_text_buffer_get_iter_at_offset (text_buffer,
|
|
|
|
&start_iter, max_len - 1);
|
2002-11-23 05:08:04 +08:00
|
|
|
gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-11-02 23:02:06 +08:00
|
|
|
/* this calls us recursively, but in the else branch */
|
2002-11-23 05:08:04 +08:00
|
|
|
gtk_text_buffer_delete (text_buffer, &start_iter, &end_iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-05 02:50:10 +08:00
|
|
|
gchar *v;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
if (g_strcmp0 (v, text))
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_text_buffer_notify,
|
|
|
|
text_buffer);
|
|
|
|
|
|
|
|
g_object_set (config, param_spec->name, text, NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_text_buffer_notify,
|
|
|
|
text_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (v);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
g_free (text);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_text_buffer_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkTextBuffer *text_buffer)
|
|
|
|
{
|
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_block_by_func (text_buffer,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_text_buffer_callback,
|
|
|
|
config);
|
|
|
|
|
2003-02-21 00:11:23 +08:00
|
|
|
gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_unblock_by_func (text_buffer,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_text_buffer_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-12 23:29:45 +08:00
|
|
|
/***********************/
|
|
|
|
/* string combo box */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
static void gimp_prop_string_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_string_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_string_combo_box_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of int property controlled by combo box.
|
2007-03-08 18:06:31 +08:00
|
|
|
* @model: #GtkTreeStore holding list of values
|
2007-02-12 23:29:45 +08:00
|
|
|
* @id_column: column in @store that holds string IDs
|
|
|
|
* @label_column: column in @store that holds labels to use in the combo-box
|
|
|
|
*
|
|
|
|
* Creates a #GimpStringComboBox widget to display and set the
|
|
|
|
* specified property. The contents of the widget are determined by
|
|
|
|
* @store.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): The newly created #GimpStringComboBox widget.
|
2007-02-12 23:29:45 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2007-02-12 23:29:45 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_string_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
2007-03-08 18:06:31 +08:00
|
|
|
GtkTreeModel *model,
|
2007-02-12 23:29:45 +08:00
|
|
|
gint id_column,
|
|
|
|
gint label_column)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
2007-03-08 18:06:31 +08:00
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
|
2007-02-12 23:29:45 +08:00
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_STRING, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2007-03-08 18:06:31 +08:00
|
|
|
combo_box = gimp_string_combo_box_new (model, id_column, label_column);
|
2007-02-12 23:29:45 +08:00
|
|
|
|
|
|
|
gimp_string_combo_box_set_active (GIMP_STRING_COMBO_BOX (combo_box), value);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
|
|
|
G_CALLBACK (gimp_prop_string_combo_box_callback),
|
|
|
|
config);
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
set_param_spec (G_OBJECT (combo_box), combo_box, param_spec);
|
2007-02-12 23:29:45 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_string_combo_box_notify),
|
|
|
|
combo_box);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (combo_box);
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
return combo_box;
|
2007-02-12 23:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_string_combo_box_callback (GtkWidget *widget,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gchar *value;
|
2018-02-05 02:50:10 +08:00
|
|
|
gchar *v;
|
2007-02-12 23:29:45 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (widget));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
value = gimp_string_combo_box_get_active (GIMP_STRING_COMBO_BOX (widget));
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
|
|
|
|
|
|
|
if (g_strcmp0 (v, value))
|
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2007-02-12 23:29:45 +08:00
|
|
|
|
|
|
|
g_free (value);
|
2018-02-05 02:50:10 +08:00
|
|
|
g_free (v);
|
2007-02-12 23:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_string_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo_box)
|
|
|
|
{
|
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (combo_box,
|
|
|
|
gimp_prop_string_combo_box_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_string_combo_box_set_active (GIMP_STRING_COMBO_BOX (combo_box), value);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (combo_box,
|
|
|
|
gimp_prop_string_combo_box_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 15:12:33 +08:00
|
|
|
/*************************/
|
|
|
|
/* file chooser button */
|
|
|
|
/*************************/
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2006-12-18 15:28:41 +08:00
|
|
|
static GtkWidget * gimp_prop_file_chooser_button_setup (GtkWidget *button,
|
|
|
|
GObject *config,
|
|
|
|
GParamSpec *param_spec);
|
|
|
|
static void gimp_prop_file_chooser_button_callback (GtkFileChooser *button,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_file_chooser_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkFileChooser *button);
|
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_file_chooser_button_new:
|
|
|
|
* @config: object to which property is attached.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @property_name: name of path property.
|
2005-03-25 08:37:16 +08:00
|
|
|
* @title: the title of the browse dialog.
|
|
|
|
* @action: the open mode for the widget.
|
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GtkFileChooserButton to edit the specified path property.
|
2005-03-25 08:37:16 +08:00
|
|
|
*
|
2005-03-25 08:45:17 +08:00
|
|
|
* Note that #GtkFileChooserButton implements the #GtkFileChooser
|
|
|
|
* interface; you can use the #GtkFileChooser API with it.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkFileChooserButton.
|
2005-03-25 08:37:16 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-03-25 08:37:16 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_file_chooser_button_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *title,
|
|
|
|
GtkFileChooserAction action)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
GIMP_TYPE_PARAM_CONFIG_PATH, G_STRFUNC);
|
2005-03-25 08:37:16 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2006-12-18 15:28:41 +08:00
|
|
|
button = gtk_file_chooser_button_new (title, action);
|
|
|
|
|
|
|
|
return gimp_prop_file_chooser_button_setup (button, config, param_spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_file_chooser_button_new_with_dialog:
|
|
|
|
* @config: object to which property is attached.
|
|
|
|
* @property_name: name of path property.
|
|
|
|
* @dialog: the #GtkFileChooserDialog widget to use.
|
|
|
|
*
|
|
|
|
* Creates a #GtkFileChooserButton to edit the specified path property.
|
|
|
|
*
|
|
|
|
* The button uses @dialog as it's file-picking window. Note that @dialog
|
|
|
|
* must be a #GtkFileChooserDialog (or subclass) and must not have
|
|
|
|
* %GTK_DIALOG_DESTROY_WITH_PARENT set.
|
|
|
|
*
|
|
|
|
* Note that #GtkFileChooserButton implements the #GtkFileChooser
|
|
|
|
* interface; you can use the #GtkFileChooser API with it.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkFileChooserButton.
|
2006-12-18 15:28:41 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2006-12-18 15:28:41 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_file_chooser_button_new_with_dialog (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GtkWidget *dialog)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GTK_IS_FILE_CHOOSER_DIALOG (dialog), NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
GIMP_TYPE_PARAM_CONFIG_PATH, G_STRFUNC);
|
2006-12-18 15:28:41 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
button = gtk_file_chooser_button_new_with_dialog (dialog);
|
|
|
|
|
|
|
|
return gimp_prop_file_chooser_button_setup (button, config, param_spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
gimp_prop_file_chooser_button_setup (GtkWidget *button,
|
|
|
|
GObject *config,
|
|
|
|
GParamSpec *param_spec)
|
|
|
|
{
|
2007-11-10 22:47:45 +08:00
|
|
|
gchar *value;
|
2016-10-01 04:07:00 +08:00
|
|
|
GFile *file = NULL;
|
2006-12-18 15:28:41 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_object_get (config,
|
2006-12-18 15:28:41 +08:00
|
|
|
param_spec->name, &value,
|
2005-03-25 08:37:16 +08:00
|
|
|
NULL);
|
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
file = gimp_file_new_for_config_path (value, NULL);
|
|
|
|
g_free (value);
|
|
|
|
}
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
if (file)
|
2005-03-25 08:37:16 +08:00
|
|
|
{
|
2016-10-01 04:07:00 +08:00
|
|
|
gchar *basename = g_file_get_basename (file);
|
2007-10-10 04:50:10 +08:00
|
|
|
|
|
|
|
if (basename && basename[0] == '.')
|
|
|
|
gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (button), TRUE);
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (button), file, NULL);
|
|
|
|
g_object_unref (file);
|
2005-03-25 08:37:16 +08:00
|
|
|
}
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
set_param_spec (G_OBJECT (button), button, param_spec);
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2007-11-10 23:00:07 +08:00
|
|
|
g_signal_connect (button, "file-set",
|
|
|
|
G_CALLBACK (gimp_prop_file_chooser_button_callback),
|
|
|
|
config);
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2006-12-18 15:28:41 +08:00
|
|
|
connect_notify (config, param_spec->name,
|
2005-03-25 08:37:16 +08:00
|
|
|
G_CALLBACK (gimp_prop_file_chooser_button_notify),
|
|
|
|
button);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2007-11-10 22:47:45 +08:00
|
|
|
return button;
|
2005-03-25 08:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_file_chooser_button_callback (GtkFileChooser *button,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2016-10-01 04:07:00 +08:00
|
|
|
GFile *file;
|
2018-02-05 02:50:10 +08:00
|
|
|
gchar *value = NULL;
|
|
|
|
gchar *v;
|
2005-03-25 08:37:16 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (button));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
file = gtk_file_chooser_get_file (button);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
2018-02-05 02:50:10 +08:00
|
|
|
value = gimp_file_get_config_path (file, NULL);
|
2016-10-01 04:07:00 +08:00
|
|
|
g_object_unref (file);
|
|
|
|
}
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
if (g_strcmp0 (v, value))
|
2005-06-11 22:29:57 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_file_chooser_button_notify,
|
|
|
|
button);
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
2005-03-25 08:37:16 +08:00
|
|
|
|
2006-06-05 02:05:53 +08:00
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_file_chooser_button_notify,
|
|
|
|
button);
|
2005-06-11 22:29:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (value);
|
2018-02-05 02:50:10 +08:00
|
|
|
g_free (v);
|
2005-03-25 08:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_file_chooser_button_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkFileChooser *button)
|
|
|
|
{
|
|
|
|
gchar *value;
|
2016-10-01 04:07:00 +08:00
|
|
|
GFile *file = NULL;
|
2005-03-25 08:37:16 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
file = gimp_file_new_for_config_path (value, NULL);
|
|
|
|
g_free (value);
|
|
|
|
}
|
2005-03-25 08:37:16 +08:00
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (button,
|
|
|
|
gimp_prop_file_chooser_button_callback,
|
|
|
|
config);
|
|
|
|
|
2016-10-01 04:07:00 +08:00
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
gtk_file_chooser_set_file (button, file, NULL);
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
2006-08-10 21:12:17 +08:00
|
|
|
else
|
2016-10-01 04:07:00 +08:00
|
|
|
{
|
|
|
|
gtk_file_chooser_unselect_all (button);
|
|
|
|
}
|
2005-03-25 08:37:16 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (button,
|
|
|
|
gimp_prop_file_chooser_button_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
/*****************/
|
|
|
|
/* path editor */
|
|
|
|
/*****************/
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
static void gimp_prop_path_editor_path_callback (GimpPathEditor *editor,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_path_editor_writable_callback (GimpPathEditor *editor,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_path_editor_path_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpPathEditor *editor);
|
|
|
|
static void gimp_prop_path_editor_writable_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpPathEditor *editor);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2019-08-09 18:32:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_path_editor_new:
|
|
|
|
* @config: object to which property is attached.
|
|
|
|
* @path_property_name: name of path property.
|
|
|
|
* @writable_property_name: name of writable path property.
|
|
|
|
* @filechooser_title: window title of #GtkFileChooserDialog widget.
|
|
|
|
*
|
|
|
|
* Creates a #GimpPathEditor to edit the specified path and writable
|
|
|
|
* path properties.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): A new #GimpPathEditor.
|
|
|
|
**/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_path_editor_new (GObject *config,
|
2004-01-29 05:53:50 +08:00
|
|
|
const gchar *path_property_name,
|
|
|
|
const gchar *writable_property_name,
|
2019-08-09 18:32:09 +08:00
|
|
|
const gchar *filechooser_title)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GParamSpec *path_param_spec;
|
|
|
|
GParamSpec *writable_param_spec = NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *editor;
|
|
|
|
gchar *value;
|
2002-12-30 03:02:05 +08:00
|
|
|
gchar *filename;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-03-25 08:37:16 +08:00
|
|
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
|
|
|
g_return_val_if_fail (path_property_name != NULL, NULL);
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
path_param_spec = check_param_spec_w (config, path_property_name,
|
|
|
|
GIMP_TYPE_PARAM_CONFIG_PATH, G_STRFUNC);
|
2004-01-29 05:53:50 +08:00
|
|
|
if (! path_param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
return NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (writable_property_name)
|
|
|
|
{
|
2007-02-12 19:01:08 +08:00
|
|
|
writable_param_spec = check_param_spec_w (config, writable_property_name,
|
|
|
|
GIMP_TYPE_PARAM_CONFIG_PATH,
|
|
|
|
G_STRFUNC);
|
2004-01-29 05:53:50 +08:00
|
|
|
if (! writable_param_spec)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
g_object_get (config,
|
2004-01-29 05:53:50 +08:00
|
|
|
path_property_name, &value,
|
2002-11-21 03:45:03 +08:00
|
|
|
NULL);
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
|
|
|
|
g_free (value);
|
2002-12-30 03:02:05 +08:00
|
|
|
|
2019-08-09 18:32:09 +08:00
|
|
|
editor = gimp_path_editor_new (filechooser_title, filename);
|
2002-12-30 03:02:05 +08:00
|
|
|
g_free (filename);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (writable_property_name)
|
|
|
|
{
|
|
|
|
g_object_get (config,
|
|
|
|
writable_property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
gimp_path_editor_set_writable_path (GIMP_PATH_EDITOR (editor), filename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (editor), "gimp-config-param-spec-path",
|
|
|
|
path_param_spec);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (editor, "path-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_path_editor_path_callback),
|
|
|
|
config);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
connect_notify (config, path_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_path_editor_path_notify),
|
2002-11-23 05:08:04 +08:00
|
|
|
editor);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (writable_property_name)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (editor), "gimp-config-param-spec-writable",
|
|
|
|
writable_param_spec);
|
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (editor, "writable-changed",
|
2004-01-29 05:53:50 +08:00
|
|
|
G_CALLBACK (gimp_prop_path_editor_writable_callback),
|
|
|
|
config);
|
|
|
|
|
|
|
|
connect_notify (config, writable_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_path_editor_writable_notify),
|
|
|
|
editor);
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (editor);
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_prop_path_editor_path_callback (GimpPathEditor *editor,
|
|
|
|
GObject *config)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GParamSpec *path_param_spec;
|
|
|
|
GParamSpec *writable_param_spec;
|
2002-11-21 03:45:03 +08:00
|
|
|
gchar *value;
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *utf8;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
path_param_spec = g_object_get_data (G_OBJECT (editor),
|
|
|
|
"gimp-config-param-spec-path");
|
|
|
|
writable_param_spec = g_object_get_data (G_OBJECT (editor),
|
|
|
|
"gimp-config-param-spec-writable");
|
|
|
|
if (! path_param_spec)
|
2002-11-21 03:45:03 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
value = gimp_path_editor_get_path (editor);
|
2016-09-03 02:47:51 +08:00
|
|
|
utf8 = value ? gimp_config_path_unexpand (value, TRUE, NULL) : NULL;
|
2004-01-29 05:53:50 +08:00
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_path_editor_path_notify,
|
|
|
|
editor);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_object_set (config,
|
2004-01-29 05:53:50 +08:00
|
|
|
path_param_spec->name, utf8,
|
2002-11-21 03:45:03 +08:00
|
|
|
NULL);
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_path_editor_path_notify,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_free (utf8);
|
|
|
|
|
|
|
|
if (writable_param_spec)
|
|
|
|
{
|
|
|
|
value = gimp_path_editor_get_writable_path (editor);
|
2016-09-03 02:47:51 +08:00
|
|
|
utf8 = value ? gimp_config_path_unexpand (value, TRUE, NULL) : NULL;
|
2004-01-29 05:53:50 +08:00
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_path_editor_writable_notify,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_object_set (config,
|
|
|
|
writable_param_spec->name, utf8,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_path_editor_writable_notify,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_free (utf8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_path_editor_writable_callback (GimpPathEditor *editor,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
gchar *value;
|
|
|
|
gchar *utf8;
|
|
|
|
|
|
|
|
param_spec = g_object_get_data (G_OBJECT (editor),
|
|
|
|
"gimp-config-param-spec-writable");
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
value = gimp_path_editor_get_writable_path (editor);
|
2016-09-03 02:47:51 +08:00
|
|
|
utf8 = value ? gimp_config_path_unexpand (value, TRUE, NULL) : NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
g_free (value);
|
2004-01-29 05:53:50 +08:00
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_path_editor_writable_notify,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_object_set (config,
|
|
|
|
param_spec->name, utf8,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_path_editor_writable_notify,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_free (utf8);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_prop_path_editor_path_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpPathEditor *editor)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
gchar *value;
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *filename;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
|
|
|
|
g_free (value);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_block_by_func (editor,
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_prop_path_editor_path_callback,
|
2002-11-21 03:45:03 +08:00
|
|
|
config);
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_path_editor_set_path (editor, filename);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_unblock_by_func (editor,
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_prop_path_editor_path_callback,
|
2002-11-21 03:45:03 +08:00
|
|
|
config);
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_path_editor_writable_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GimpPathEditor *editor)
|
|
|
|
{
|
|
|
|
gchar *value;
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
|
2002-11-21 03:45:03 +08:00
|
|
|
g_free (value);
|
2004-01-29 05:53:50 +08:00
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (editor,
|
|
|
|
gimp_prop_path_editor_writable_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_path_editor_set_writable_path (editor, filename);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (editor,
|
|
|
|
gimp_prop_path_editor_writable_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
g_free (filename);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
/***************/
|
|
|
|
/* sizeentry */
|
|
|
|
/***************/
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
static void gimp_prop_size_entry_callback (GimpSizeEntry *entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_size_entry_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry);
|
2003-10-02 03:55:13 +08:00
|
|
|
static void gimp_prop_size_entry_notify_unit (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry);
|
2007-10-18 16:34:24 +08:00
|
|
|
static gint gimp_prop_size_entry_num_chars (gdouble lower,
|
|
|
|
gdouble upper);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_size_entry_new:
|
2005-02-05 04:48:02 +08:00
|
|
|
* @config: Object to which property is attached.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @property_name: Name of int or double property.
|
2007-10-15 02:51:58 +08:00
|
|
|
* @property_is_pixel: When %TRUE, the property value is in pixels,
|
|
|
|
* and in the selected unit otherwise.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @unit_property_name: Name of unit property.
|
|
|
|
* @unit_format: A printf-like unit-format string as is used with
|
|
|
|
* gimp_unit_menu_new().
|
|
|
|
* @update_policy: How the automatic pixel <-> real-world-unit
|
|
|
|
* calculations should be done.
|
2005-02-04 06:31:55 +08:00
|
|
|
* @resolution: The resolution (in dpi) for the field.
|
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GimpSizeEntry to set and display the specified double or
|
|
|
|
* int property, and its associated unit property. Note that this
|
|
|
|
* function is only suitable for creating a size entry holding a
|
|
|
|
* single value. Use gimp_prop_coordinates_new() to create a size
|
|
|
|
* entry holding two values.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GimpSizeEntry widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-10-02 03:55:13 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_size_entry_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
2007-10-15 02:51:58 +08:00
|
|
|
gboolean property_is_pixel,
|
2003-10-02 03:55:13 +08:00
|
|
|
const gchar *unit_property_name,
|
|
|
|
const gchar *unit_format,
|
|
|
|
GimpSizeEntryUpdatePolicy update_policy,
|
|
|
|
gdouble resolution)
|
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
GtkWidget *entry;
|
2003-10-02 03:55:13 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GParamSpec *unit_param_spec;
|
|
|
|
gboolean show_pixels;
|
2007-10-16 23:39:56 +08:00
|
|
|
gboolean show_percent;
|
2003-10-02 03:55:13 +08:00
|
|
|
gdouble value;
|
2003-10-24 00:58:16 +08:00
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
2003-10-02 03:55:13 +08:00
|
|
|
GimpUnit unit_value;
|
|
|
|
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
2003-10-02 03:55:13 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
if (! get_numeric_values (config,
|
2004-05-12 16:13:33 +08:00
|
|
|
param_spec, &value, &lower, &upper, G_STRFUNC))
|
2003-10-24 00:58:16 +08:00
|
|
|
return NULL;
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
if (unit_property_name)
|
|
|
|
{
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
unit_param_spec = check_param_spec_w (config, unit_property_name,
|
|
|
|
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
|
2003-10-02 03:55:13 +08:00
|
|
|
if (! unit_param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_value_init (&value, unit_param_spec->value_type);
|
2007-10-16 23:39:56 +08:00
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
g_value_set_int (&value, GIMP_UNIT_PIXEL);
|
2007-10-17 16:30:03 +08:00
|
|
|
show_pixels = (g_param_value_validate (unit_param_spec,
|
|
|
|
&value) == FALSE);
|
2007-10-16 23:39:56 +08:00
|
|
|
|
|
|
|
g_value_set_int (&value, GIMP_UNIT_PERCENT);
|
2007-10-17 16:30:03 +08:00
|
|
|
show_percent = (g_param_value_validate (unit_param_spec,
|
|
|
|
&value) == FALSE);
|
2007-10-16 23:39:56 +08:00
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
unit_property_name, &unit_value,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit_param_spec = NULL;
|
|
|
|
unit_value = GIMP_UNIT_INCH;
|
|
|
|
show_pixels = FALSE;
|
2007-10-16 23:39:56 +08:00
|
|
|
show_percent = FALSE;
|
2003-10-02 03:55:13 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
entry = gimp_size_entry_new (1, unit_value, unit_format,
|
|
|
|
show_pixels, show_percent, FALSE,
|
2017-03-23 09:36:27 +08:00
|
|
|
gimp_prop_size_entry_num_chars (lower, upper) + 1 +
|
|
|
|
gimp_unit_get_scaled_digits (unit_value, resolution),
|
2007-10-18 16:34:24 +08:00
|
|
|
update_policy);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2003-10-15 19:04:31 +08:00
|
|
|
set_param_spec (NULL,
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (entry), 0),
|
2003-10-15 19:04:31 +08:00
|
|
|
param_spec);
|
|
|
|
|
|
|
|
if (unit_param_spec)
|
2018-05-25 10:08:59 +08:00
|
|
|
set_param_spec (NULL,
|
|
|
|
gimp_size_entry_get_unit_combo (GIMP_SIZE_ENTRY (entry)),
|
|
|
|
unit_param_spec);
|
2003-10-15 19:04:31 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (entry), unit_value);
|
2003-10-24 01:35:18 +08:00
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
if (update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE)
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0,
|
2003-10-24 00:58:16 +08:00
|
|
|
resolution, FALSE);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_value_boundaries (GIMP_SIZE_ENTRY (entry), 0,
|
2003-10-24 00:58:16 +08:00
|
|
|
lower, upper);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "value-is-pixel",
|
2007-10-15 02:51:58 +08:00
|
|
|
GINT_TO_POINTER (property_is_pixel ? TRUE : FALSE));
|
|
|
|
|
|
|
|
if (property_is_pixel)
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 0, value);
|
2007-10-15 02:51:58 +08:00
|
|
|
else
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (entry), 0, value);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec",
|
2003-10-02 03:55:13 +08:00
|
|
|
param_spec);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "refval-changed",
|
2007-10-16 22:22:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_size_entry_callback),
|
|
|
|
config);
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "value-changed",
|
2007-10-16 22:22:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_size_entry_callback),
|
|
|
|
config);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_size_entry_notify),
|
2007-10-17 16:30:03 +08:00
|
|
|
entry);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
|
|
|
if (unit_property_name)
|
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-unit",
|
2004-01-29 05:53:50 +08:00
|
|
|
unit_param_spec);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "unit-changed",
|
2004-01-29 05:53:50 +08:00
|
|
|
G_CALLBACK (gimp_prop_size_entry_callback),
|
|
|
|
config);
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
connect_notify (config, unit_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_size_entry_notify_unit),
|
2007-10-17 16:30:03 +08:00
|
|
|
entry);
|
2003-10-02 03:55:13 +08:00
|
|
|
}
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (entry);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
return entry;
|
2003-10-02 03:55:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_prop_size_entry_callback (GimpSizeEntry *entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GParamSpec *unit_param_spec;
|
|
|
|
gdouble value;
|
2007-10-15 02:51:58 +08:00
|
|
|
gboolean value_is_pixel;
|
2003-10-02 03:55:13 +08:00
|
|
|
GimpUnit unit_value;
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
param_spec = g_object_get_data (G_OBJECT (entry), "gimp-config-param-spec");
|
2003-10-02 03:55:13 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
unit_param_spec = g_object_get_data (G_OBJECT (entry),
|
2003-10-02 03:55:13 +08:00
|
|
|
"gimp-config-param-spec-unit");
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
value_is_pixel = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry),
|
2007-10-15 02:51:58 +08:00
|
|
|
"value-is-pixel"));
|
|
|
|
|
|
|
|
if (value_is_pixel)
|
2007-10-17 16:30:03 +08:00
|
|
|
value = gimp_size_entry_get_refval (entry, 0);
|
2007-10-15 02:51:58 +08:00
|
|
|
else
|
2007-10-17 16:30:03 +08:00
|
|
|
value = gimp_size_entry_get_value (entry, 0);
|
2007-10-15 02:51:58 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
unit_value = gimp_size_entry_get_unit (entry);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2004-03-21 01:21:48 +08:00
|
|
|
if (unit_param_spec)
|
|
|
|
{
|
|
|
|
GimpUnit old_unit;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
unit_param_spec->name, &old_unit,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (unit_value == old_unit)
|
|
|
|
unit_param_spec = NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
g_object_set (config,
|
|
|
|
param_spec->name, ROUND (value),
|
|
|
|
|
|
|
|
unit_param_spec ?
|
|
|
|
unit_param_spec->name : NULL, unit_value,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
{
|
|
|
|
g_object_set (config,
|
|
|
|
param_spec->name, value,
|
|
|
|
|
|
|
|
unit_param_spec ?
|
|
|
|
unit_param_spec->name : NULL, unit_value,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_size_entry_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry)
|
2003-10-02 03:55:13 +08:00
|
|
|
{
|
2007-10-15 02:51:58 +08:00
|
|
|
gdouble value;
|
|
|
|
gdouble entry_value;
|
|
|
|
gboolean value_is_pixel;
|
2003-10-02 03:55:13 +08:00
|
|
|
|
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
gint int_value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &int_value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value = int_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
value_is_pixel = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry),
|
2007-10-15 02:51:58 +08:00
|
|
|
"value-is-pixel"));
|
|
|
|
|
|
|
|
if (value_is_pixel)
|
2007-10-17 16:30:03 +08:00
|
|
|
entry_value = gimp_size_entry_get_refval (entry, 0);
|
2007-10-15 02:51:58 +08:00
|
|
|
else
|
2007-10-17 16:30:03 +08:00
|
|
|
entry_value = gimp_size_entry_get_value (entry, 0);
|
2007-10-15 02:51:58 +08:00
|
|
|
|
|
|
|
if (value != entry_value)
|
2003-10-02 03:55:13 +08:00
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
gimp_prop_size_entry_callback,
|
|
|
|
config);
|
|
|
|
|
2007-10-15 02:51:58 +08:00
|
|
|
if (value_is_pixel)
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval (entry, 0, value);
|
2007-10-15 02:51:58 +08:00
|
|
|
else
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_value (entry, 0, value);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
gimp_prop_size_entry_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_size_entry_notify_unit (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry)
|
2003-10-02 03:55:13 +08:00
|
|
|
{
|
|
|
|
GimpUnit value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
if (value != gimp_size_entry_get_unit (entry))
|
2003-10-02 03:55:13 +08:00
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
gimp_prop_size_entry_callback,
|
|
|
|
config);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_unit (entry, value);
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
gimp_prop_size_entry_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-18 16:34:24 +08:00
|
|
|
static gint
|
|
|
|
gimp_prop_size_entry_num_chars (gdouble lower,
|
|
|
|
gdouble upper)
|
|
|
|
{
|
|
|
|
gint lower_chars = log (fabs (lower)) / log (10);
|
|
|
|
gint upper_chars = log (fabs (upper)) / log (10);
|
|
|
|
|
|
|
|
if (lower < 0.0)
|
|
|
|
lower_chars++;
|
|
|
|
|
|
|
|
if (upper < 0.0)
|
|
|
|
upper_chars++;
|
|
|
|
|
|
|
|
return MAX (lower_chars, upper_chars);
|
|
|
|
}
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
/*****************/
|
|
|
|
/* coordinates */
|
|
|
|
/*****************/
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
static void gimp_prop_coordinates_callback (GimpSizeEntry *entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_coordinates_notify_x (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
static void gimp_prop_coordinates_notify_y (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
static void gimp_prop_coordinates_notify_unit (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_coordinates_new:
|
2005-02-05 04:48:02 +08:00
|
|
|
* @config: Object to which property is attached.
|
2005-07-12 04:26:51 +08:00
|
|
|
* @x_property_name: Name of int or double property for X coordinate.
|
|
|
|
* @y_property_name: Name of int or double property for Y coordinate.
|
|
|
|
* @unit_property_name: Name of unit property.
|
|
|
|
* @unit_format: A printf-like unit-format string as is used with
|
|
|
|
* gimp_unit_menu_new().
|
|
|
|
* @update_policy: How the automatic pixel <-> real-world-unit
|
|
|
|
* calculations should be done.
|
2005-02-04 06:31:55 +08:00
|
|
|
* @xresolution: The resolution (in dpi) for the X coordinate.
|
|
|
|
* @yresolution: The resolution (in dpi) for the Y coordinate.
|
|
|
|
* @has_chainbutton: Whether to add a chainbutton to the size entry.
|
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GimpSizeEntry to set and display two double or int
|
|
|
|
* properties, which will usually represent X and Y coordinates, and
|
|
|
|
* their associated unit property.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GimpSizeEntry widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2002-11-21 03:45:03 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_coordinates_new (GObject *config,
|
|
|
|
const gchar *x_property_name,
|
|
|
|
const gchar *y_property_name,
|
|
|
|
const gchar *unit_property_name,
|
|
|
|
const gchar *unit_format,
|
|
|
|
GimpSizeEntryUpdatePolicy update_policy,
|
|
|
|
gdouble xresolution,
|
|
|
|
gdouble yresolution,
|
|
|
|
gboolean has_chainbutton)
|
2003-04-04 01:50:56 +08:00
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
GtkWidget *entry;
|
2003-04-04 01:50:56 +08:00
|
|
|
GtkWidget *chainbutton = NULL;
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
entry = gimp_size_entry_new (2, GIMP_UNIT_INCH, unit_format,
|
|
|
|
FALSE, FALSE, TRUE, 10,
|
|
|
|
update_policy);
|
2003-04-04 01:50:56 +08:00
|
|
|
|
|
|
|
if (has_chainbutton)
|
|
|
|
{
|
|
|
|
chainbutton = gimp_chain_button_new (GIMP_CHAIN_BOTTOM);
|
2018-05-03 02:23:05 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (entry), chainbutton, 1, 3, 2, 1);
|
2003-04-04 01:50:56 +08:00
|
|
|
gtk_widget_show (chainbutton);
|
|
|
|
}
|
|
|
|
|
2003-10-02 03:55:13 +08:00
|
|
|
if (! gimp_prop_coordinates_connect (config,
|
|
|
|
x_property_name,
|
|
|
|
y_property_name,
|
|
|
|
unit_property_name,
|
2007-10-17 16:30:03 +08:00
|
|
|
entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
chainbutton,
|
|
|
|
xresolution,
|
|
|
|
yresolution))
|
2003-04-04 01:50:56 +08:00
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
gtk_widget_destroy (entry);
|
2003-04-04 01:50:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (entry);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
return entry;
|
2003-04-04 01:50:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2003-10-02 03:55:13 +08:00
|
|
|
gimp_prop_coordinates_connect (GObject *config,
|
|
|
|
const gchar *x_property_name,
|
|
|
|
const gchar *y_property_name,
|
|
|
|
const gchar *unit_property_name,
|
2007-10-17 16:30:03 +08:00
|
|
|
GtkWidget *entry,
|
2003-10-02 03:55:13 +08:00
|
|
|
GtkWidget *chainbutton,
|
|
|
|
gdouble xresolution,
|
|
|
|
gdouble yresolution)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
GParamSpec *x_param_spec;
|
|
|
|
GParamSpec *y_param_spec;
|
|
|
|
GParamSpec *unit_param_spec;
|
2003-11-12 23:15:22 +08:00
|
|
|
gdouble x_value, x_lower, x_upper;
|
|
|
|
gdouble y_value, y_lower, y_upper;
|
2003-04-04 23:11:30 +08:00
|
|
|
GimpUnit unit_value;
|
2003-04-04 01:50:56 +08:00
|
|
|
gdouble *old_x_value;
|
|
|
|
gdouble *old_y_value;
|
2003-04-04 23:11:30 +08:00
|
|
|
GimpUnit *old_unit_value;
|
2003-11-12 23:15:22 +08:00
|
|
|
gboolean chain_checked;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (entry), FALSE);
|
2018-05-25 10:08:59 +08:00
|
|
|
g_return_val_if_fail (gimp_size_entry_get_n_fields (GIMP_SIZE_ENTRY (entry)) == 2,
|
|
|
|
FALSE);
|
2003-04-04 01:50:56 +08:00
|
|
|
g_return_val_if_fail (chainbutton == NULL ||
|
|
|
|
GIMP_IS_CHAIN_BUTTON (chainbutton), FALSE);
|
|
|
|
|
2004-05-12 16:13:33 +08:00
|
|
|
x_param_spec = find_param_spec (config, x_property_name, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! x_param_spec)
|
2003-04-04 01:50:56 +08:00
|
|
|
return FALSE;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-05-12 16:13:33 +08:00
|
|
|
y_param_spec = find_param_spec (config, y_property_name, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! y_param_spec)
|
2003-04-04 01:50:56 +08:00
|
|
|
return FALSE;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-11-12 23:15:22 +08:00
|
|
|
if (! get_numeric_values (config, x_param_spec,
|
2004-05-12 16:13:33 +08:00
|
|
|
&x_value, &x_lower, &x_upper, G_STRFUNC) ||
|
2003-11-12 23:15:22 +08:00
|
|
|
! get_numeric_values (config, y_param_spec,
|
2004-05-12 16:13:33 +08:00
|
|
|
&y_value, &y_lower, &y_upper, G_STRFUNC))
|
2003-11-12 23:15:22 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
if (unit_property_name)
|
|
|
|
{
|
2007-02-12 19:01:08 +08:00
|
|
|
unit_param_spec = check_param_spec_w (config, unit_property_name,
|
|
|
|
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
|
2002-11-21 03:45:03 +08:00
|
|
|
if (! unit_param_spec)
|
2003-04-04 01:50:56 +08:00
|
|
|
return FALSE;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
unit_property_name, &unit_value,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit_param_spec = NULL;
|
2002-11-23 05:08:04 +08:00
|
|
|
unit_value = GIMP_UNIT_INCH;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
2003-10-15 19:04:31 +08:00
|
|
|
set_param_spec (NULL,
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (entry), 0),
|
2003-10-15 19:04:31 +08:00
|
|
|
x_param_spec);
|
|
|
|
set_param_spec (NULL,
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (entry), 1),
|
2003-10-15 19:04:31 +08:00
|
|
|
y_param_spec);
|
|
|
|
|
|
|
|
if (unit_param_spec)
|
|
|
|
set_param_spec (NULL,
|
2018-05-25 10:08:59 +08:00
|
|
|
gimp_size_entry_get_unit_combo (GIMP_SIZE_ENTRY (entry)),
|
|
|
|
unit_param_spec);
|
2003-10-15 19:04:31 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (entry), unit_value);
|
2003-10-24 01:35:18 +08:00
|
|
|
|
2018-05-25 10:08:59 +08:00
|
|
|
switch (gimp_size_entry_get_update_policy (GIMP_SIZE_ENTRY (entry)))
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0,
|
2002-11-21 03:45:03 +08:00
|
|
|
xresolution, FALSE);
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 1,
|
2002-11-21 03:45:03 +08:00
|
|
|
yresolution, FALSE);
|
2003-11-12 23:15:22 +08:00
|
|
|
chain_checked = (ABS (x_value - y_value) < 1);
|
2002-11-21 03:45:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
|
2003-11-12 23:15:22 +08:00
|
|
|
chain_checked = (ABS (x_value - y_value) < GIMP_MIN_RESOLUTION);
|
2002-11-21 03:45:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-12 23:15:22 +08:00
|
|
|
chain_checked = (x_value == y_value);
|
2002-11-21 03:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 0,
|
2003-11-12 23:15:22 +08:00
|
|
|
x_lower, x_upper);
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (entry), 1,
|
2003-11-12 23:15:22 +08:00
|
|
|
y_lower, y_upper);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 0, x_value);
|
|
|
|
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (entry), 1, y_value);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-x",
|
2002-11-21 03:45:03 +08:00
|
|
|
x_param_spec);
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-y",
|
2002-11-21 03:45:03 +08:00
|
|
|
y_param_spec);
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
old_x_value = g_new0 (gdouble, 1);
|
|
|
|
*old_x_value = x_value;
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (entry), "old-x-value",
|
2003-04-04 01:50:56 +08:00
|
|
|
old_x_value,
|
|
|
|
(GDestroyNotify) g_free);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
old_y_value = g_new0 (gdouble, 1);
|
|
|
|
*old_y_value = y_value;
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (entry), "old-y-value",
|
2003-04-04 01:50:56 +08:00
|
|
|
old_y_value,
|
|
|
|
(GDestroyNotify) g_free);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
if (chainbutton)
|
|
|
|
{
|
2002-11-21 03:45:03 +08:00
|
|
|
if (chain_checked)
|
2003-04-04 01:50:56 +08:00
|
|
|
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton), TRUE);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "chainbutton", chainbutton);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "value-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_coordinates_callback),
|
|
|
|
config);
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "refval-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_coordinates_callback),
|
|
|
|
config);
|
2002-11-21 23:46:19 +08:00
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, x_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_coordinates_notify_x),
|
2007-10-17 16:30:03 +08:00
|
|
|
entry);
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, y_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_coordinates_notify_y),
|
2007-10-17 16:30:03 +08:00
|
|
|
entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
|
|
|
if (unit_property_name)
|
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-unit",
|
2004-01-29 05:53:50 +08:00
|
|
|
unit_param_spec);
|
|
|
|
|
|
|
|
old_unit_value = g_new0 (GimpUnit, 1);
|
|
|
|
*old_unit_value = unit_value;
|
2007-10-17 16:30:03 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (entry), "old-unit-value",
|
2004-01-29 05:53:50 +08:00
|
|
|
old_unit_value,
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_connect (entry, "unit-changed",
|
2004-01-29 05:53:50 +08:00
|
|
|
G_CALLBACK (gimp_prop_coordinates_callback),
|
|
|
|
config);
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
connect_notify (config, unit_property_name,
|
|
|
|
G_CALLBACK (gimp_prop_coordinates_notify_unit),
|
2007-10-17 16:30:03 +08:00
|
|
|
entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
return TRUE;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_prop_coordinates_callback (GimpSizeEntry *entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *x_param_spec;
|
|
|
|
GParamSpec *y_param_spec;
|
|
|
|
GParamSpec *unit_param_spec;
|
|
|
|
gdouble x_value;
|
|
|
|
gdouble y_value;
|
|
|
|
GimpUnit unit_value;
|
2002-11-21 23:46:19 +08:00
|
|
|
gdouble *old_x_value;
|
|
|
|
gdouble *old_y_value;
|
2003-04-04 23:11:30 +08:00
|
|
|
GimpUnit *old_unit_value;
|
2004-10-12 22:59:14 +08:00
|
|
|
gboolean backwards;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
x_param_spec = g_object_get_data (G_OBJECT (entry),
|
2002-11-21 03:45:03 +08:00
|
|
|
"gimp-config-param-spec-x");
|
2007-10-17 16:30:03 +08:00
|
|
|
y_param_spec = g_object_get_data (G_OBJECT (entry),
|
2002-11-21 03:45:03 +08:00
|
|
|
"gimp-config-param-spec-y");
|
|
|
|
|
|
|
|
if (! x_param_spec || ! y_param_spec)
|
|
|
|
return;
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
unit_param_spec = g_object_get_data (G_OBJECT (entry),
|
2003-10-02 03:55:13 +08:00
|
|
|
"gimp-config-param-spec-unit");
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
x_value = gimp_size_entry_get_refval (entry, 0);
|
|
|
|
y_value = gimp_size_entry_get_refval (entry, 1);
|
|
|
|
unit_value = gimp_size_entry_get_unit (entry);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
old_x_value = g_object_get_data (G_OBJECT (entry), "old-x-value");
|
|
|
|
old_y_value = g_object_get_data (G_OBJECT (entry), "old-y-value");
|
|
|
|
old_unit_value = g_object_get_data (G_OBJECT (entry), "old-unit-value");
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2003-04-04 23:11:30 +08:00
|
|
|
if (! old_x_value || ! old_y_value || (unit_param_spec && ! old_unit_value))
|
2003-04-04 01:50:56 +08:00
|
|
|
return;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2004-12-24 02:12:23 +08:00
|
|
|
/*
|
|
|
|
* FIXME: if the entry was created using gimp_coordinates_new, then
|
|
|
|
* the chain button is handled automatically and the following block
|
|
|
|
* of code is unnecessary (and, in fact, redundant).
|
|
|
|
*/
|
2002-11-21 23:46:19 +08:00
|
|
|
if (x_value != y_value)
|
|
|
|
{
|
|
|
|
GtkWidget *chainbutton;
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
chainbutton = g_object_get_data (G_OBJECT (entry), "chainbutton");
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2002-11-21 23:46:19 +08:00
|
|
|
if (chainbutton &&
|
2004-12-24 02:12:23 +08:00
|
|
|
gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chainbutton)) &&
|
|
|
|
! g_object_get_data (G_OBJECT (chainbutton), "constrains-ratio"))
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
if (x_value != *old_x_value)
|
2003-04-04 01:50:56 +08:00
|
|
|
y_value = x_value;
|
|
|
|
else if (y_value != *old_y_value)
|
|
|
|
x_value = y_value;
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-12 22:59:14 +08:00
|
|
|
backwards = (*old_x_value == x_value);
|
|
|
|
|
2003-04-04 23:11:30 +08:00
|
|
|
if (*old_x_value == x_value &&
|
|
|
|
*old_y_value == y_value &&
|
|
|
|
(old_unit_value == NULL || *old_unit_value == unit_value))
|
2002-11-21 23:46:19 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
*old_x_value = x_value;
|
|
|
|
*old_y_value = y_value;
|
|
|
|
|
2003-04-04 23:11:30 +08:00
|
|
|
if (old_unit_value)
|
|
|
|
*old_unit_value = unit_value;
|
|
|
|
|
2003-11-12 23:15:22 +08:00
|
|
|
if (unit_param_spec)
|
|
|
|
g_object_set (config,
|
|
|
|
unit_param_spec->name, unit_value,
|
|
|
|
NULL);
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
if (G_IS_PARAM_SPEC_INT (x_param_spec) &&
|
|
|
|
G_IS_PARAM_SPEC_INT (y_param_spec))
|
|
|
|
{
|
2004-10-12 22:59:14 +08:00
|
|
|
if (backwards)
|
|
|
|
g_object_set (config,
|
|
|
|
y_param_spec->name, ROUND (y_value),
|
|
|
|
x_param_spec->name, ROUND (x_value),
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
g_object_set (config,
|
|
|
|
x_param_spec->name, ROUND (x_value),
|
|
|
|
y_param_spec->name, ROUND (y_value),
|
|
|
|
NULL);
|
|
|
|
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (x_param_spec) &&
|
|
|
|
G_IS_PARAM_SPEC_DOUBLE (y_param_spec))
|
|
|
|
{
|
2004-10-12 22:59:14 +08:00
|
|
|
if (backwards)
|
|
|
|
g_object_set (config,
|
|
|
|
y_param_spec->name, y_value,
|
|
|
|
x_param_spec->name, x_value,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
g_object_set (config,
|
|
|
|
x_param_spec->name, x_value,
|
|
|
|
y_param_spec->name, y_value,
|
|
|
|
NULL);
|
2002-11-21 03:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_coordinates_notify_x (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
gint int_value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &int_value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value = int_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
if (value != gimp_size_entry_get_refval (entry, 0))
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2009-08-06 05:40:39 +08:00
|
|
|
gdouble *old_x_value = g_object_get_data (G_OBJECT (entry),
|
|
|
|
"old-x-value");
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval (entry, 0, value);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2009-08-06 05:40:39 +08:00
|
|
|
if (old_x_value)
|
|
|
|
*old_x_value = value;
|
|
|
|
|
|
|
|
g_signal_emit_by_name (entry, "value-changed",
|
|
|
|
gimp_size_entry_get_value (entry, 0));
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_coordinates_notify_y (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
gint int_value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &int_value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
value = int_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
if (value != gimp_size_entry_get_refval (entry, 1))
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2009-08-06 05:40:39 +08:00
|
|
|
gdouble *old_y_value = g_object_get_data (G_OBJECT (entry),
|
|
|
|
"old-y-value");
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_refval (entry, 1, value);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2009-08-06 05:40:39 +08:00
|
|
|
if (old_y_value)
|
|
|
|
*old_y_value = value;
|
|
|
|
|
|
|
|
g_signal_emit_by_name (entry, "value-changed",
|
|
|
|
gimp_size_entry_get_value (entry, 1));
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_coordinates_notify_unit (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
2007-10-17 16:30:03 +08:00
|
|
|
GimpSizeEntry *entry)
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
|
|
|
GimpUnit value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
if (value != gimp_size_entry_get_unit (entry))
|
2002-11-21 03:45:03 +08:00
|
|
|
{
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_block_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
gimp_size_entry_set_unit (entry, value);
|
2002-11-21 03:45:03 +08:00
|
|
|
|
2007-10-17 16:30:03 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry,
|
2002-11-21 03:45:03 +08:00
|
|
|
gimp_prop_coordinates_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
|
2003-07-07 21:37:19 +08:00
|
|
|
/****************/
|
|
|
|
/* color area */
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
static void gimp_prop_color_area_callback (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_color_area_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *area);
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_color_area_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of RGB property.
|
|
|
|
* @width: Width of color area.
|
|
|
|
* @height: Height of color area.
|
|
|
|
* @type: How transparency is represented.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
|
|
|
* Creates a #GimpColorArea to set and display the value of an RGB
|
|
|
|
* property.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GimpColorArea widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2003-07-07 21:37:19 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_color_area_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpColorAreaType type)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *area;
|
|
|
|
GimpRGB *value;
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
GIMP_TYPE_PARAM_RGB, G_STRFUNC);
|
2003-07-07 21:37:19 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
area = gimp_color_area_new (value, type,
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
|
|
|
|
gtk_widget_set_size_request (area, width, height);
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (area), area, param_spec);
|
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (area, "color-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_color_area_callback),
|
|
|
|
config);
|
2003-07-07 21:37:19 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_color_area_notify),
|
|
|
|
area);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (area);
|
|
|
|
|
2003-07-07 21:37:19 +08:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_color_area_callback (GtkWidget *area,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GimpRGB value;
|
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (area));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_color_area_get_color (GIMP_COLOR_AREA (area), &value);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_color_area_notify,
|
|
|
|
area);
|
|
|
|
|
|
|
|
g_object_set (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_color_area_notify,
|
|
|
|
area);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_color_area_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *area)
|
|
|
|
{
|
|
|
|
GimpRGB *value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (area,
|
|
|
|
gimp_prop_color_area_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_color_area_set_color (GIMP_COLOR_AREA (area), value);
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (area,
|
|
|
|
gimp_prop_color_area_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-15 05:03:34 +08:00
|
|
|
/********************/
|
|
|
|
/* unit combo box */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
static void gimp_prop_unit_combo_box_callback (GtkWidget *combo,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_unit_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_prop_unit_combo_box_new:
|
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of Unit property.
|
|
|
|
*
|
|
|
|
* Creates a #GimpUnitComboBox to set and display the value of a Unit
|
|
|
|
* property. See gimp_unit_combo_box_new() for more information.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GimpUnitComboBox widget.
|
2010-10-15 05:03:34 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.8
|
2010-10-15 05:03:34 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_unit_combo_box_new (GObject *config,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
2010-10-31 01:37:46 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GimpUnit unit;
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
2010-10-31 01:37:46 +08:00
|
|
|
gboolean show_pixels;
|
|
|
|
gboolean show_percent;
|
2010-10-15 05:03:34 +08:00
|
|
|
|
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
|
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_value_init (&value, param_spec->value_type);
|
|
|
|
|
|
|
|
g_value_set_int (&value, GIMP_UNIT_PIXEL);
|
|
|
|
show_pixels = (g_param_value_validate (param_spec, &value) == FALSE);
|
|
|
|
|
|
|
|
g_value_set_int (&value, GIMP_UNIT_PERCENT);
|
|
|
|
show_percent = (g_param_value_validate (param_spec, &value) == FALSE);
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
property_name, &unit,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
combo = gimp_unit_combo_box_new ();
|
2010-10-31 01:37:46 +08:00
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
|
|
|
gimp_unit_store_set_has_pixels (GIMP_UNIT_STORE (model), show_pixels);
|
|
|
|
gimp_unit_store_set_has_percent (GIMP_UNIT_STORE (model), show_percent);
|
|
|
|
|
|
|
|
gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (combo), unit);
|
2010-10-15 05:03:34 +08:00
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (combo), combo, param_spec);
|
|
|
|
|
|
|
|
g_signal_connect (combo, "changed",
|
|
|
|
G_CALLBACK (gimp_prop_unit_combo_box_callback),
|
|
|
|
config);
|
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_unit_combo_box_notify),
|
|
|
|
combo);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
2010-10-15 05:03:34 +08:00
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_unit_combo_box_callback (GtkWidget *combo,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
2018-02-05 02:50:10 +08:00
|
|
|
GimpUnit value;
|
|
|
|
GimpUnit v;
|
2010-10-15 05:03:34 +08:00
|
|
|
|
|
|
|
param_spec = get_param_spec (G_OBJECT (combo));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
value = gimp_unit_combo_box_get_active (GIMP_UNIT_COMBO_BOX (combo));
|
2010-10-15 05:03:34 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_get (config, param_spec->name, &v, NULL);
|
2010-10-15 05:03:34 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
if (v != value)
|
|
|
|
{
|
|
|
|
/* FIXME gimp_unit_menu_update (menu, &unit); */
|
2010-10-15 05:03:34 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_signal_handlers_block_by_func (config,
|
|
|
|
gimp_prop_unit_combo_box_notify,
|
|
|
|
combo);
|
2010-10-15 05:03:34 +08:00
|
|
|
|
2018-02-05 02:50:10 +08:00
|
|
|
g_object_set (config, param_spec->name, value, NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (config,
|
|
|
|
gimp_prop_unit_combo_box_notify,
|
|
|
|
combo);
|
|
|
|
}
|
2010-10-15 05:03:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_unit_combo_box_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkWidget *combo)
|
|
|
|
{
|
|
|
|
GimpUnit unit;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &unit,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (combo,
|
|
|
|
gimp_prop_unit_combo_box_callback,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (combo), unit);
|
|
|
|
|
|
|
|
/* FIXME gimp_unit_menu_update (menu, &unit); */
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (combo,
|
|
|
|
gimp_prop_unit_combo_box_callback,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 06:55:02 +08:00
|
|
|
/***************/
|
|
|
|
/* icon name */
|
|
|
|
/***************/
|
2003-07-07 21:37:19 +08:00
|
|
|
|
2014-05-09 06:55:02 +08:00
|
|
|
/**
|
2016-06-26 04:54:10 +08:00
|
|
|
* gimp_prop_icon_image_new:
|
2014-05-09 06:55:02 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of string property.
|
|
|
|
* @icon_size: Size of desired icon image.
|
|
|
|
*
|
|
|
|
* Creates a widget to display a icon image representing the value of the
|
|
|
|
* specified string property, which should encode an icon name.
|
|
|
|
* See gtk_image_new_from_icon_name() for more information.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkImage widget.
|
2014-05-09 06:55:02 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.10
|
2014-05-09 06:55:02 +08:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_icon_image_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GtkIconSize icon_size)
|
2003-07-07 21:37:19 +08:00
|
|
|
{
|
2020-05-15 22:43:35 +08:00
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *image;
|
|
|
|
gchar *icon_name;
|
|
|
|
const gchar *blurb;
|
2003-07-07 21:37:19 +08:00
|
|
|
|
|
|
|
param_spec = check_param_spec (config, property_name,
|
2004-05-12 16:13:33 +08:00
|
|
|
G_TYPE_PARAM_STRING, G_STRFUNC);
|
2003-07-07 21:37:19 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_object_get (config,
|
2014-05-09 06:55:02 +08:00
|
|
|
property_name, &icon_name,
|
2003-07-07 21:37:19 +08:00
|
|
|
NULL);
|
|
|
|
|
2014-05-09 06:55:02 +08:00
|
|
|
image = gtk_image_new_from_icon_name (icon_name, icon_size);
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
blurb = g_param_spec_get_blurb (param_spec);
|
|
|
|
if (blurb)
|
2020-09-16 02:34:42 +08:00
|
|
|
gimp_help_set_help_data (image, blurb, NULL);
|
2003-07-07 21:37:19 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
g_object_bind_property (config, property_name,
|
|
|
|
image, "icon-name",
|
|
|
|
G_BINDING_BIDIRECTIONAL);
|
2003-07-07 21:37:19 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
g_free (icon_name);
|
2003-07-07 21:37:19 +08:00
|
|
|
|
2020-05-15 22:43:35 +08:00
|
|
|
return image;
|
2003-07-07 21:37:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-23 04:32:34 +08:00
|
|
|
/**************/
|
|
|
|
/* expander */
|
|
|
|
/**************/
|
|
|
|
|
|
|
|
static void gimp_prop_expanded_notify (GtkExpander *expander,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GObject *config);
|
|
|
|
static void gimp_prop_expander_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkExpander *expander);
|
|
|
|
|
|
|
|
|
2005-02-04 06:31:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_prop_expander_new:
|
2005-07-12 04:26:51 +08:00
|
|
|
* @config: Object to which property is attached.
|
|
|
|
* @property_name: Name of boolean property.
|
2020-05-08 22:28:02 +08:00
|
|
|
* @label: (nullable): Label for expander.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2005-07-12 04:26:51 +08:00
|
|
|
* Creates a #GtkExpander controlled by the specified boolean property.
|
|
|
|
* A value of %TRUE for the property corresponds to the expanded state
|
2005-02-04 06:31:55 +08:00
|
|
|
* for the widget.
|
2019-08-03 06:04:28 +08:00
|
|
|
* If @label is %NULL, the @property_name's nick will be used as label
|
2016-02-11 23:35:45 +08:00
|
|
|
* of the returned widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): A new #GtkExpander widget.
|
2005-02-04 06:31:55 +08:00
|
|
|
*
|
2018-02-05 02:50:10 +08:00
|
|
|
* Since: 2.4
|
2005-02-04 06:31:55 +08:00
|
|
|
*/
|
2005-01-23 04:32:34 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_prop_expander_new (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *label)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
GtkWidget *expander;
|
|
|
|
gboolean value;
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
param_spec = check_param_spec_w (config, property_name,
|
|
|
|
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
|
2005-01-23 04:32:34 +08:00
|
|
|
if (! param_spec)
|
|
|
|
return NULL;
|
|
|
|
|
2016-02-10 06:35:06 +08:00
|
|
|
if (! label)
|
|
|
|
label = g_param_spec_get_nick (param_spec);
|
|
|
|
|
2005-01-23 04:32:34 +08:00
|
|
|
g_object_get (config,
|
|
|
|
property_name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
expander = g_object_new (GTK_TYPE_EXPANDER,
|
|
|
|
"label", label,
|
|
|
|
"expanded", value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
set_param_spec (G_OBJECT (expander), expander, param_spec);
|
|
|
|
|
|
|
|
g_signal_connect (expander, "notify::expanded",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_CALLBACK (gimp_prop_expanded_notify),
|
|
|
|
config);
|
2005-01-23 04:32:34 +08:00
|
|
|
|
|
|
|
connect_notify (config, property_name,
|
|
|
|
G_CALLBACK (gimp_prop_expander_notify),
|
|
|
|
expander);
|
|
|
|
|
2019-09-26 02:24:06 +08:00
|
|
|
gtk_widget_show (expander);
|
|
|
|
|
2005-01-23 04:32:34 +08:00
|
|
|
return expander;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_expanded_notify (GtkExpander *expander,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GObject *config)
|
|
|
|
{
|
|
|
|
param_spec = get_param_spec (G_OBJECT (expander));
|
|
|
|
if (! param_spec)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_set (config,
|
|
|
|
param_spec->name, gtk_expander_get_expanded (expander),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_prop_expander_notify (GObject *config,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GtkExpander *expander)
|
|
|
|
{
|
|
|
|
gboolean value;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
param_spec->name, &value,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (gtk_expander_get_expanded (expander) != value)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (expander,
|
|
|
|
gimp_prop_expanded_notify,
|
|
|
|
config);
|
|
|
|
|
|
|
|
gtk_expander_set_expanded (expander, value);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (expander,
|
|
|
|
gimp_prop_expanded_notify,
|
|
|
|
config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
/*******************************/
|
|
|
|
/* private utility functions */
|
|
|
|
/*******************************/
|
|
|
|
|
2007-08-08 17:56:51 +08:00
|
|
|
static GQuark gimp_prop_widgets_param_spec_quark (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
#define PARAM_SPEC_QUARK (gimp_prop_widgets_param_spec_quark ())
|
|
|
|
|
|
|
|
static GQuark
|
|
|
|
gimp_prop_widgets_param_spec_quark (void)
|
|
|
|
{
|
|
|
|
static GQuark param_spec_quark = 0;
|
|
|
|
|
|
|
|
if (! param_spec_quark)
|
|
|
|
param_spec_quark = g_quark_from_static_string ("gimp-config-param-spec");
|
|
|
|
|
|
|
|
return param_spec_quark;
|
|
|
|
}
|
2002-11-23 05:08:04 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_param_spec (GObject *object,
|
2003-01-26 04:29:42 +08:00
|
|
|
GtkWidget *widget,
|
|
|
|
GParamSpec *param_spec)
|
2002-11-23 05:08:04 +08:00
|
|
|
{
|
2003-10-15 19:04:31 +08:00
|
|
|
if (object)
|
|
|
|
{
|
2007-08-08 17:56:51 +08:00
|
|
|
g_object_set_qdata (object, PARAM_SPEC_QUARK, param_spec);
|
2003-10-15 19:04:31 +08:00
|
|
|
}
|
2003-01-26 04:29:42 +08:00
|
|
|
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
const gchar *blurb = g_param_spec_get_blurb (param_spec);
|
|
|
|
|
|
|
|
if (blurb)
|
2014-05-15 05:34:01 +08:00
|
|
|
gimp_help_set_help_data (widget, blurb, NULL);
|
2003-01-26 04:29:42 +08:00
|
|
|
}
|
2002-11-23 05:08:04 +08:00
|
|
|
}
|
|
|
|
|
2004-10-22 10:15:14 +08:00
|
|
|
static void
|
|
|
|
set_radio_spec (GObject *object,
|
|
|
|
GParamSpec *param_spec)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
for (list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (object));
|
|
|
|
list;
|
|
|
|
list = g_slist_next (list))
|
|
|
|
{
|
|
|
|
set_param_spec (list->data, NULL, param_spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
static GParamSpec *
|
|
|
|
get_param_spec (GObject *object)
|
|
|
|
{
|
2007-08-08 17:56:51 +08:00
|
|
|
return g_object_get_qdata (object, PARAM_SPEC_QUARK);
|
2002-11-23 05:08:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GParamSpec *
|
|
|
|
find_param_spec (GObject *object,
|
|
|
|
const gchar *property_name,
|
|
|
|
const gchar *strloc)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
|
|
|
|
param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
|
|
|
|
property_name);
|
|
|
|
|
|
|
|
if (! param_spec)
|
|
|
|
g_warning ("%s: %s has no property named '%s'",
|
|
|
|
strloc,
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (object)),
|
|
|
|
property_name);
|
|
|
|
|
|
|
|
return param_spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GParamSpec *
|
|
|
|
check_param_spec (GObject *object,
|
|
|
|
const gchar *property_name,
|
|
|
|
GType type,
|
|
|
|
const gchar *strloc)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
|
|
|
|
param_spec = find_param_spec (object, property_name, strloc);
|
|
|
|
|
|
|
|
if (param_spec && ! g_type_is_a (G_TYPE_FROM_INSTANCE (param_spec), type))
|
|
|
|
{
|
|
|
|
g_warning ("%s: property '%s' of %s is not a %s",
|
|
|
|
strloc,
|
|
|
|
param_spec->name,
|
|
|
|
g_type_name (param_spec->owner_type),
|
|
|
|
g_type_name (type));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return param_spec;
|
|
|
|
}
|
|
|
|
|
2007-02-12 19:01:08 +08:00
|
|
|
static GParamSpec *
|
|
|
|
check_param_spec_w (GObject *object,
|
|
|
|
const gchar *property_name,
|
|
|
|
GType type,
|
|
|
|
const gchar *strloc)
|
|
|
|
{
|
|
|
|
GParamSpec *param_spec;
|
|
|
|
|
|
|
|
param_spec = check_param_spec (object, property_name, type, strloc);
|
|
|
|
|
|
|
|
if (param_spec &&
|
|
|
|
(param_spec->flags & G_PARAM_WRITABLE) == 0)
|
|
|
|
{
|
2013-06-17 08:14:17 +08:00
|
|
|
g_warning ("%s: property '%s' of %s is not writable",
|
2007-02-12 19:01:08 +08:00
|
|
|
strloc,
|
|
|
|
param_spec->name,
|
|
|
|
g_type_name (param_spec->owner_type));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return param_spec;
|
|
|
|
}
|
|
|
|
|
2003-10-24 00:58:16 +08:00
|
|
|
static gboolean
|
|
|
|
get_numeric_values (GObject *object,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
gdouble *value,
|
|
|
|
gdouble *lower,
|
|
|
|
gdouble *upper,
|
|
|
|
const gchar *strloc)
|
|
|
|
{
|
|
|
|
if (G_IS_PARAM_SPEC_INT (param_spec))
|
|
|
|
{
|
|
|
|
GParamSpecInt *int_spec = G_PARAM_SPEC_INT (param_spec);
|
|
|
|
gint int_value;
|
|
|
|
|
|
|
|
g_object_get (object, param_spec->name, &int_value, NULL);
|
|
|
|
|
|
|
|
*value = int_value;
|
|
|
|
*lower = int_spec->minimum;
|
|
|
|
*upper = int_spec->maximum;
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_UINT (param_spec))
|
|
|
|
{
|
|
|
|
GParamSpecUInt *uint_spec = G_PARAM_SPEC_UINT (param_spec);
|
|
|
|
guint uint_value;
|
|
|
|
|
|
|
|
g_object_get (object, param_spec->name, &uint_value, NULL);
|
|
|
|
|
|
|
|
*value = uint_value;
|
|
|
|
*lower = uint_spec->minimum;
|
|
|
|
*upper = uint_spec->maximum;
|
|
|
|
}
|
|
|
|
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
|
|
|
|
{
|
|
|
|
GParamSpecDouble *double_spec = G_PARAM_SPEC_DOUBLE (param_spec);
|
|
|
|
|
|
|
|
g_object_get (object, param_spec->name, value, NULL);
|
|
|
|
|
|
|
|
*lower = double_spec->minimum;
|
|
|
|
*upper = double_spec->maximum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s: property '%s' of %s is not numeric",
|
|
|
|
strloc,
|
|
|
|
param_spec->name,
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (object)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-11-23 05:08:04 +08:00
|
|
|
static void
|
|
|
|
connect_notify (GObject *config,
|
|
|
|
const gchar *property_name,
|
|
|
|
GCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
gchar *notify_name;
|
|
|
|
|
|
|
|
notify_name = g_strconcat ("notify::", property_name, NULL);
|
|
|
|
|
|
|
|
g_signal_connect_object (config, notify_name, callback, callback_data, 0);
|
|
|
|
|
|
|
|
g_free (notify_name);
|
|
|
|
}
|
2020-11-25 09:19:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_prop_widget_double_to_factor (GBinding *binding,
|
|
|
|
const GValue *from_value,
|
|
|
|
GValue *to_value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gdouble *factor = (gdouble*) user_data;
|
|
|
|
gdouble val = g_value_get_double (from_value);
|
|
|
|
|
|
|
|
g_value_set_double (to_value, val * (*factor));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_prop_widget_double_from_factor (GBinding *binding,
|
|
|
|
const GValue *from_value,
|
|
|
|
GValue *to_value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gdouble *factor = (gdouble*) user_data;
|
|
|
|
gdouble val = g_value_get_double (from_value);
|
|
|
|
|
|
|
|
g_value_set_double (to_value, val / (*factor));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|