2006-12-09 21:33:38 +00:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-10-12 14:59:14 +00:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
|
|
|
|
* gimpsizebox.c
|
|
|
|
|
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
|
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-10-12 14:59:14 +00:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-10-12 14:59:14 +00:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-10-12 14:59:14 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-09 13:00:01 +00:00
|
|
|
|
|
2004-12-23 18:12:23 +00:00
|
|
|
|
#include <stdio.h>
|
2007-03-09 13:00:01 +00:00
|
|
|
|
|
2013-11-01 22:28:18 +01:00
|
|
|
|
#include <gegl.h>
|
2004-10-12 14:59:14 +00:00
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 13:00:01 +00:00
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
2005-01-25 19:11:26 +00:00
|
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2004-10-12 14:59:14 +00:00
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
|
|
#include "gimpsizebox.h"
|
|
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SB_WIDTH 8
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_WIDTH,
|
|
|
|
|
PROP_HEIGHT,
|
|
|
|
|
PROP_UNIT,
|
|
|
|
|
PROP_XRESOLUTION,
|
|
|
|
|
PROP_YRESOLUTION,
|
2004-10-26 23:31:34 +00:00
|
|
|
|
PROP_RESOLUTION_UNIT,
|
|
|
|
|
PROP_KEEP_ASPECT,
|
|
|
|
|
PROP_EDIT_RESOLUTION
|
2004-10-12 14:59:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
|
#define GIMP_SIZE_BOX_GET_PRIVATE(obj) ((GimpSizeBoxPrivate *) gimp_size_box_get_instance_private ((GimpSizeBox *) (obj)))
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
|
|
|
|
typedef struct _GimpSizeBoxPrivate GimpSizeBoxPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GimpSizeBoxPrivate
|
|
|
|
|
{
|
2004-10-30 23:55:34 +00:00
|
|
|
|
GimpSizeEntry *size_entry;
|
|
|
|
|
GimpChainButton *size_chain;
|
2004-10-26 23:31:34 +00:00
|
|
|
|
GtkWidget *pixel_label;
|
|
|
|
|
GtkWidget *res_label;
|
2004-10-12 14:59:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
|
static void gimp_size_box_constructed (GObject *object);
|
|
|
|
|
static void gimp_size_box_dispose (GObject *object);
|
|
|
|
|
static void gimp_size_box_set_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gimp_size_box_get_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
static void gimp_size_box_update_size (GimpSizeBox *box);
|
|
|
|
|
static void gimp_size_box_update_resolution (GimpSizeBox *box);
|
|
|
|
|
static void gimp_size_box_chain_toggled (GimpChainButton *button,
|
|
|
|
|
GimpSizeBox *box);
|
2004-10-26 21:18:20 +00:00
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpSizeBox, gimp_size_box, GTK_TYPE_BOX)
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
|
#define parent_class gimp_size_box_parent_class
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_class_init (GimpSizeBoxClass *klass)
|
|
|
|
|
{
|
2010-09-26 22:38:01 +02:00
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
|
object_class->constructed = gimp_size_box_constructed;
|
2010-09-26 22:38:01 +02:00
|
|
|
|
object_class->dispose = gimp_size_box_dispose;
|
2004-10-12 14:59:14 +00:00
|
|
|
|
object_class->set_property = gimp_size_box_set_property;
|
|
|
|
|
object_class->get_property = gimp_size_box_get_property;
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_WIDTH,
|
|
|
|
|
g_param_spec_int ("width", NULL, NULL,
|
|
|
|
|
GIMP_MIN_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
256,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-12 14:59:14 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
g_object_class_install_property (object_class, PROP_HEIGHT,
|
|
|
|
|
g_param_spec_int ("height", NULL, NULL,
|
|
|
|
|
GIMP_MIN_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
256,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-12 14:59:14 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
g_object_class_install_property (object_class, PROP_UNIT,
|
|
|
|
|
gimp_param_spec_unit ("unit", NULL, NULL,
|
|
|
|
|
TRUE, TRUE,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
gimp_unit_pixel (),
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-12 14:59:14 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
g_object_class_install_property (object_class, PROP_XRESOLUTION,
|
|
|
|
|
g_param_spec_double ("xresolution",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GIMP_MIN_RESOLUTION,
|
|
|
|
|
GIMP_MAX_RESOLUTION,
|
|
|
|
|
72.0,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-12 14:59:14 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
g_object_class_install_property (object_class, PROP_YRESOLUTION,
|
|
|
|
|
g_param_spec_double ("yresolution",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GIMP_MIN_RESOLUTION,
|
|
|
|
|
GIMP_MAX_RESOLUTION,
|
|
|
|
|
72.0,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-12 14:59:14 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
2004-10-26 23:31:34 +00:00
|
|
|
|
g_object_class_install_property (object_class, PROP_RESOLUTION_UNIT,
|
|
|
|
|
gimp_param_spec_unit ("resolution-unit",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
FALSE, FALSE,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
gimp_unit_inch (),
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-26 23:31:34 +00:00
|
|
|
|
G_PARAM_CONSTRUCT));
|
2004-10-12 14:59:14 +00:00
|
|
|
|
g_object_class_install_property (object_class, PROP_KEEP_ASPECT,
|
|
|
|
|
g_param_spec_boolean ("keep-aspect",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
TRUE,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE));
|
2004-10-26 23:31:34 +00:00
|
|
|
|
g_object_class_install_property (object_class, PROP_EDIT_RESOLUTION,
|
|
|
|
|
g_param_spec_boolean ("edit-resolution",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
FALSE,
|
2006-01-18 20:29:40 +00:00
|
|
|
|
GIMP_PARAM_READWRITE |
|
2004-10-26 23:31:34 +00:00
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2004-10-12 14:59:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_init (GimpSizeBox *box)
|
|
|
|
|
{
|
2010-10-30 15:44:46 +02:00
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
|
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
gtk_box_set_spacing (GTK_BOX (box), 6);
|
2005-11-02 09:27:15 +00:00
|
|
|
|
|
|
|
|
|
box->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_constructed (GObject *object)
|
2004-10-12 14:59:14 +00:00
|
|
|
|
{
|
2011-01-14 09:38:11 +01:00
|
|
|
|
GimpSizeBox *box = GIMP_SIZE_BOX (object);
|
|
|
|
|
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
|
2005-01-02 02:07:46 +00:00
|
|
|
|
GtkWidget *vbox;
|
2004-10-12 14:59:14 +00:00
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
GtkWidget *hbox;
|
2004-10-26 21:18:20 +00:00
|
|
|
|
GtkWidget *label;
|
2005-11-02 09:27:15 +00:00
|
|
|
|
GList *children;
|
|
|
|
|
GList *list;
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2012-11-12 21:51:22 +01:00
|
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-12-23 18:12:23 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
Issue #434: remove broken plural support for GimpUnit.
Rather than trying to implement full i18n plural support, we just remove
this failed attempt from the past. The fact is that to get proper
support, we'd basically need to reimplement a Gettext-like plural
definition syntax within our API, then ask people to write down this
plural definition for their language, then to write every plural form…
all this for custom units which only them will ever see!
Moreover code investigation shows that the singular form was simply
never used, and the plural form was always used (whatever the actual
unit value displayed).
As for the "identifier", this was a text which was never shown anywhere
(except in the unit editor) and for all built-in units, as well as
default unitrc units, it was equivalent to the English plural value.
So we now just have a unique name which is the "long label" to be used
everywhere in the GUI, and abbreviation will be basically the "short
label". That's it. No useless (or worse, not actually usable because it
was not generic internationalization) values anymore!
2024-08-05 16:02:47 +02:00
|
|
|
|
entry = gimp_coordinates_new (box->unit, "%n",
|
2004-12-23 18:12:23 +00:00
|
|
|
|
TRUE, TRUE, SB_WIDTH,
|
|
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
|
|
|
|
TRUE, TRUE,
|
|
|
|
|
_("_Width:"),
|
|
|
|
|
box->width, box->xresolution,
|
2005-01-02 16:55:50 +00:00
|
|
|
|
GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0, box->width,
|
2004-12-23 18:12:23 +00:00
|
|
|
|
_("H_eight:"),
|
|
|
|
|
box->height, box->yresolution,
|
2005-01-02 16:55:50 +00:00
|
|
|
|
GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0, box->height);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2005-01-02 16:55:50 +00:00
|
|
|
|
priv->size_entry = GIMP_SIZE_ENTRY (entry);
|
|
|
|
|
priv->size_chain = GIMP_COORDINATES_CHAINBUTTON (GIMP_SIZE_ENTRY (entry));
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2004-12-23 18:12:23 +00:00
|
|
|
|
/*
|
2005-01-02 16:55:50 +00:00
|
|
|
|
* let gimp_prop_coordinates_callback know how to interpret the chainbutton
|
2004-12-23 18:12:23 +00:00
|
|
|
|
*/
|
|
|
|
|
g_object_set_data (G_OBJECT (priv->size_chain),
|
2005-01-02 16:55:50 +00:00
|
|
|
|
"constrains-ratio", GINT_TO_POINTER (TRUE));
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
|
|
|
|
gimp_prop_coordinates_connect (G_OBJECT (box),
|
2004-12-23 18:12:23 +00:00
|
|
|
|
"width", "height",
|
|
|
|
|
"unit",
|
2004-10-12 14:59:14 +00:00
|
|
|
|
entry, NULL,
|
2004-12-23 18:12:23 +00:00
|
|
|
|
box->xresolution,
|
|
|
|
|
box->yresolution);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
|
2006-05-19 10:45:25 +00:00
|
|
|
|
g_signal_connect (priv->size_chain, "toggled",
|
|
|
|
|
G_CALLBACK (gimp_size_box_chain_toggled),
|
|
|
|
|
box);
|
|
|
|
|
|
2004-12-23 18:12:23 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
|
|
|
|
gtk_widget_show (entry);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
|
2005-11-02 09:27:15 +00:00
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (entry));
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
|
|
|
|
if (GTK_IS_LABEL (list->data))
|
|
|
|
|
gtk_size_group_add_widget (box->size_group, list->data);
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2018-05-02 20:23:05 +02:00
|
|
|
|
gtk_grid_attach (GTK_GRID (entry), vbox, 1, 2, 2, 1);
|
2005-01-02 02:07:46 +00:00
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
2004-10-26 21:18:20 +00:00
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
|
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
|
|
|
|
|
-1);
|
2016-09-08 19:11:20 +02:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2005-01-02 02:07:46 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
2004-10-26 21:18:20 +00:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
priv->pixel_label = label;
|
2004-12-23 18:12:23 +00:00
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
if (box->edit_resolution)
|
|
|
|
|
{
|
2014-04-18 19:17:56 +02:00
|
|
|
|
gboolean chain_active;
|
|
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-12-23 18:12:23 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
|
2004-10-30 23:55:34 +00:00
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
2014-04-18 19:17:56 +02:00
|
|
|
|
chain_active = ABS (box->xresolution -
|
|
|
|
|
box->yresolution) < GIMP_MIN_RESOLUTION;
|
|
|
|
|
|
2004-12-23 18:12:23 +00:00
|
|
|
|
entry = gimp_coordinates_new (box->resolution_unit, _("pixels/%a"),
|
|
|
|
|
FALSE, FALSE, SB_WIDTH,
|
2004-12-24 00:19:41 +00:00
|
|
|
|
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION,
|
2014-04-18 19:17:56 +02:00
|
|
|
|
chain_active, FALSE,
|
2004-12-23 18:12:23 +00:00
|
|
|
|
_("_X resolution:"),
|
|
|
|
|
box->xresolution, 1.0,
|
|
|
|
|
1, 1, 1, 10,
|
|
|
|
|
_("_Y resolution:"),
|
|
|
|
|
box->yresolution, 1.0,
|
|
|
|
|
1, 1, 1, 10);
|
2004-10-30 23:55:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
|
|
|
|
|
gtk_widget_show (entry);
|
|
|
|
|
|
2005-11-02 09:27:15 +00:00
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (entry));
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
|
|
|
|
if (GTK_IS_LABEL (list->data))
|
|
|
|
|
gtk_size_group_add_widget (box->size_group, list->data);
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
2004-10-30 23:55:34 +00:00
|
|
|
|
gimp_prop_coordinates_connect (G_OBJECT (box),
|
|
|
|
|
"xresolution", "yresolution",
|
|
|
|
|
"resolution-unit",
|
2004-12-23 18:12:23 +00:00
|
|
|
|
entry, NULL,
|
2004-10-30 23:55:34 +00:00
|
|
|
|
1.0, 1.0);
|
2005-12-19 22:37:49 +00:00
|
|
|
|
}
|
2004-10-26 23:31:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
|
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
|
|
|
|
|
-1);
|
2016-09-08 19:11:20 +02:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2005-01-02 02:07:46 +00:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
priv->res_label = label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_size_box_update_size (box);
|
|
|
|
|
gimp_size_box_update_resolution (box);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-26 22:38:01 +02:00
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GimpSizeBox *box = GIMP_SIZE_BOX (object);
|
|
|
|
|
|
|
|
|
|
if (box->size_group)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (box->size_group);
|
|
|
|
|
box->size_group = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_set_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GimpSizeBox *box = GIMP_SIZE_BOX (object);
|
|
|
|
|
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_WIDTH:
|
|
|
|
|
box->width = g_value_get_int (value);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gimp_size_box_update_size (box);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
|
box->height = g_value_get_int (value);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gimp_size_box_update_size (box);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
box->unit = g_value_get_object (value);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_XRESOLUTION:
|
|
|
|
|
box->xresolution = g_value_get_double (value);
|
2004-10-30 23:55:34 +00:00
|
|
|
|
if (priv->size_entry)
|
|
|
|
|
gimp_size_entry_set_resolution (priv->size_entry, 0,
|
|
|
|
|
box->xresolution, TRUE);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gimp_size_box_update_resolution (box);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_YRESOLUTION:
|
|
|
|
|
box->yresolution = g_value_get_double (value);
|
2004-10-30 23:55:34 +00:00
|
|
|
|
if (priv->size_entry)
|
|
|
|
|
gimp_size_entry_set_resolution (priv->size_entry, 1,
|
|
|
|
|
box->yresolution, TRUE);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gimp_size_box_update_resolution (box);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_RESOLUTION_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
box->resolution_unit = g_value_get_object (value);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_KEEP_ASPECT:
|
2004-10-30 23:55:34 +00:00
|
|
|
|
if (priv->size_chain)
|
|
|
|
|
gimp_chain_button_set_active (priv->size_chain,
|
2004-10-12 14:59:14 +00:00
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
case PROP_EDIT_RESOLUTION:
|
|
|
|
|
box->edit_resolution = g_value_get_boolean (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_get_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GimpSizeBox *box = GIMP_SIZE_BOX (object);
|
|
|
|
|
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_WIDTH:
|
|
|
|
|
g_value_set_int (value, box->width);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
|
g_value_set_int (value, box->height);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
g_value_set_object (value, box->unit);
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_XRESOLUTION:
|
|
|
|
|
g_value_set_double (value, box->xresolution);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_YRESOLUTION:
|
|
|
|
|
g_value_set_double (value, box->yresolution);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
case PROP_RESOLUTION_UNIT:
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
|
g_value_set_object (value, box->resolution_unit);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
case PROP_KEEP_ASPECT:
|
|
|
|
|
g_value_set_boolean (value,
|
2004-10-30 23:55:34 +00:00
|
|
|
|
gimp_chain_button_get_active (priv->size_chain));
|
2004-10-12 14:59:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
case PROP_EDIT_RESOLUTION:
|
|
|
|
|
g_value_set_boolean (value, box->edit_resolution);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-10-12 14:59:14 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-26 21:18:20 +00:00
|
|
|
|
|
2005-11-02 09:27:15 +00:00
|
|
|
|
static void
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gimp_size_box_update_size (GimpSizeBox *box)
|
2004-10-26 21:18:20 +00:00
|
|
|
|
{
|
2004-10-26 23:31:34 +00:00
|
|
|
|
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
|
|
|
|
|
|
|
|
|
|
if (priv->pixel_label)
|
2004-10-26 21:18:20 +00:00
|
|
|
|
{
|
2006-02-28 12:15:51 +00:00
|
|
|
|
gchar *text = g_strdup_printf (ngettext ("%d × %d pixel",
|
|
|
|
|
"%d × %d pixels", box->height),
|
2005-11-02 16:07:07 +00:00
|
|
|
|
box->width, box->height);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->pixel_label), text);
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_update_resolution (GimpSizeBox *box)
|
|
|
|
|
{
|
|
|
|
|
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
|
|
|
|
|
|
2004-11-06 12:30:38 +00:00
|
|
|
|
if (priv->size_entry)
|
|
|
|
|
{
|
|
|
|
|
gimp_size_entry_set_refval (priv->size_entry, 0, box->width);
|
|
|
|
|
gimp_size_entry_set_refval (priv->size_entry, 1, box->height);
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-26 23:31:34 +00:00
|
|
|
|
if (priv->res_label)
|
|
|
|
|
{
|
|
|
|
|
gchar *text;
|
2005-01-02 16:55:50 +00:00
|
|
|
|
gint xres = ROUND (box->xresolution);
|
|
|
|
|
gint yres = ROUND (box->yresolution);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
|
2005-01-02 16:55:50 +00:00
|
|
|
|
if (xres != yres)
|
2006-04-05 16:45:27 +00:00
|
|
|
|
text = g_strdup_printf (_("%d × %d ppi"), xres, yres);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
else
|
2006-04-05 16:45:27 +00:00
|
|
|
|
text = g_strdup_printf (_("%d ppi"), yres);
|
2004-10-26 23:31:34 +00:00
|
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->res_label), text);
|
2004-10-26 21:18:20 +00:00
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-05-19 10:45:25 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_size_box_chain_toggled (GimpChainButton *button,
|
|
|
|
|
GimpSizeBox *box)
|
|
|
|
|
{
|
|
|
|
|
g_object_set (box,
|
|
|
|
|
"keep-aspect", gimp_chain_button_get_active (button),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|