2022-10-15 15:11:05 -04:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2024-09-29 02:14:30 +02:00
|
|
|
#include "gimpresourceselect-private.h"
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
#include "gimpuitypes.h"
|
2023-08-19 01:22:09 +02:00
|
|
|
#include "gimpresourcechooser.h"
|
2022-10-15 15:11:05 -04:00
|
|
|
#include "gimpuimarshal.h"
|
|
|
|
|
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* SECTION: gimpresourcechooser
|
|
|
|
* @title: GimpResourceChooser
|
2023-05-31 16:12:04 +02:00
|
|
|
* @short_description: Base class for buttons that popup a resource
|
|
|
|
* selection dialog.
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* A button which pops up a resource selection dialog.
|
|
|
|
*
|
|
|
|
* Responsibilities:
|
|
|
|
*
|
|
|
|
* - implementing outer container widget,
|
|
|
|
* - managing clicks and popping up a remote chooser,
|
|
|
|
* - having a resource property,
|
|
|
|
* - signaling when user selects resource
|
|
|
|
* - receiving drag,
|
|
|
|
* - triggering draws of the button interior (by subclass) and draws of remote popup chooser.
|
|
|
|
*
|
|
|
|
* Collaborations:
|
|
|
|
*
|
|
|
|
* - owned by GimpProcedureDialog via GimpPropWidget
|
|
|
|
* - resource property usually bound to a GimpConfig for a GimpPluginProcedure.
|
|
|
|
* - communicates using GimpResourceSelect with remote GimpPDBDialog,
|
|
|
|
* to choose an installed GimpResource owned by core.
|
|
|
|
*
|
|
|
|
* Subclass responsibilities:
|
|
|
|
*
|
|
|
|
* - creating interior widgets
|
|
|
|
* - drawing the interior (a preview of the chosen resource)
|
|
|
|
* - declaring which interior widgets are drag destinations
|
|
|
|
* - declaring which interior widgets are clickable (generate "clicked" signal)
|
|
|
|
* - generate "clicked" (delegating to GtkButton or implementing from mouse events)
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
RESOURCE_SET,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TITLE,
|
2023-08-17 23:02:38 +02:00
|
|
|
PROP_LABEL,
|
2022-10-15 15:11:05 -04:00
|
|
|
PROP_RESOURCE,
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2023-05-31 16:12:04 +02:00
|
|
|
GimpResource *resource;
|
|
|
|
gchar *title;
|
2023-08-17 23:02:38 +02:00
|
|
|
gchar *label;
|
2023-08-16 23:53:33 +02:00
|
|
|
gchar *callback;
|
2023-08-17 23:02:38 +02:00
|
|
|
|
|
|
|
GtkWidget *label_widget;
|
2023-08-19 01:22:09 +02:00
|
|
|
} GimpResourceChooserPrivate;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_chooser_constructed (GObject *object);
|
|
|
|
static void gimp_resource_chooser_dispose (GObject *object);
|
|
|
|
static void gimp_resource_chooser_finalize (GObject *object);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_chooser_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_resource_chooser_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_chooser_clicked (GimpResourceChooser *self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_chooser_callback (GimpResource *resource,
|
|
|
|
gboolean dialog_closing,
|
|
|
|
gpointer user_data);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_select_drag_data_received (GimpResourceChooser *self,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection,
|
|
|
|
guint info,
|
|
|
|
guint time);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
static void gimp_resource_chooser_set_remote_dialog (GimpResourceChooser *self,
|
|
|
|
GimpResource *resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2022-09-05 19:28:35 -04:00
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
static guint resource_button_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
static GParamSpec *resource_button_props[N_PROPS] = { NULL, };
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GimpResourceChooser, gimp_resource_chooser, GTK_TYPE_BOX)
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_class_init (GimpResourceChooserClass *klass)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
object_class->constructed = gimp_resource_chooser_constructed;
|
|
|
|
object_class->dispose = gimp_resource_chooser_dispose;
|
|
|
|
object_class->finalize = gimp_resource_chooser_finalize;
|
|
|
|
object_class->set_property = gimp_resource_chooser_set_property;
|
|
|
|
object_class->get_property = gimp_resource_chooser_get_property;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
klass->resource_set = NULL;
|
Issue #9270: Change GimpBrushSelect to choose only brush.
gimp_brushes_popup() was triggering a popup allowing to change not only
the brush, but also the "paint mode", the opacity and the spacing. As
far as I could see, this was used nowhere for the paint mode and
opacity.
As for the spacing, it looks like gfig was indeed getting this data,
except that the GimpBrushSelect was disabling the effect on this scale
by setting change_brush_spacing to FALSE when calling
gimp_brush_factory_view_new(), and even setting this to TRUE, it was not
working fine anyway. Rather than debugging this, let's simplify the API.
Such settings seems like additional paint settings which don't have to
be in the brush selection. If someone wants people to also select an
opacity, spacing or paint mode, it would be much more efficient to add
separate plug-in arguments for these.
Additionally, I fix GimpBrushFactoryView not to show the spacing scale
when change_brush_spacing was set to FALSE anyway. This is just a bogus
widget then, which can only confuse people.
2024-09-06 18:02:16 +02:00
|
|
|
klass->draw_interior = NULL;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* GimpResourceChooser:title:
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* The title to be used for the resource selection popup dialog.
|
|
|
|
*
|
2023-08-16 23:53:33 +02:00
|
|
|
* Since: 3.0
|
2022-10-15 15:11:05 -04:00
|
|
|
*/
|
2023-05-31 16:12:04 +02:00
|
|
|
resource_button_props[PROP_TITLE] =
|
|
|
|
g_param_spec_string ("title",
|
|
|
|
"Title",
|
|
|
|
"The title to be used for the resource selection popup dialog",
|
|
|
|
"Resource Selection",
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-17 23:02:38 +02:00
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* GimpResourceChooser:label:
|
2023-08-17 23:02:38 +02:00
|
|
|
*
|
|
|
|
* Label text with mnemonic.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
resource_button_props[PROP_LABEL] =
|
|
|
|
g_param_spec_string ("label",
|
|
|
|
"Label",
|
|
|
|
"The label to be used next to the button",
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* GimpResourceChooser:resource:
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* The currently selected resource.
|
|
|
|
*
|
2023-08-16 23:53:33 +02:00
|
|
|
* Since: 3.0
|
2022-10-15 15:11:05 -04:00
|
|
|
*/
|
2023-05-31 16:12:04 +02:00
|
|
|
resource_button_props[PROP_RESOURCE] =
|
|
|
|
gimp_param_spec_resource ("resource",
|
|
|
|
"Resource",
|
|
|
|
"The currently selected resource",
|
app, libgimp*, pdb: new GimpParamSpecObject abstract spec type.
This abstract spec type is basically a GParamSpecObject with a default
value. It will be used by various object spec with default values, such
as GimpParamSpecColor, GimpParamSpecUnit and all GimpParamSpecResource
subtypes. Also it has a duplicate() class method so that every spec type
can implement the proper way to duplicate itself.
This fixes the fact that in gimp_config_param_spec_duplicate(), all
unknown object spec types (because they are implemented in libgimp,
which is invisible to libgimpconfig) are just copied as
GParamSpecObject, hence losing default values and other parameters.
As a second enhancement, it also makes it easier to detect the object
spec types for which we have default value support in
gimp_config_reset_properties().
As a side fix, gimp_param_spec_color() now just always duplicates the
passed default color, making it hence much easier to avoid bugs when
reusing a GeglColor.
2024-09-02 23:38:13 +02:00
|
|
|
GIMP_TYPE_RESOURCE,
|
2023-05-31 16:12:04 +02:00
|
|
|
TRUE, /* none_ok */
|
2024-07-27 08:18:54 -04:00
|
|
|
NULL, /* no default for this property. */
|
2024-09-06 13:38:43 +02:00
|
|
|
FALSE,
|
2023-05-31 16:12:04 +02:00
|
|
|
GIMP_PARAM_READWRITE);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
g_object_class_install_properties (object_class,
|
|
|
|
N_PROPS, resource_button_props);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* GimpResourceChooser::resource-set:
|
2022-10-15 15:11:05 -04:00
|
|
|
* @widget: the object which received the signal.
|
|
|
|
* @resource: the currently selected resource.
|
|
|
|
* @dialog_closing: whether the dialog was closed or not.
|
|
|
|
*
|
|
|
|
* The ::resource-set signal is emitted when the user selects a resource.
|
|
|
|
*
|
2023-08-16 23:53:33 +02:00
|
|
|
* Since: 3.0
|
2022-10-15 15:11:05 -04:00
|
|
|
*/
|
|
|
|
resource_button_signals[RESOURCE_SET] =
|
|
|
|
g_signal_new ("resource-set",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2023-08-19 01:22:09 +02:00
|
|
|
G_STRUCT_OFFSET (GimpResourceChooserClass, resource_set),
|
2022-10-15 15:11:05 -04:00
|
|
|
NULL, NULL,
|
|
|
|
_gimpui_marshal_VOID__POINTER_BOOLEAN,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_OBJECT,
|
|
|
|
G_TYPE_BOOLEAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_init (GimpResourceChooser *self)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (GIMP_RESOURCE_CHOOSER (self));
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2023-05-31 17:01:46 +02:00
|
|
|
gtk_box_set_spacing (GTK_BOX (self), 6);
|
2023-08-17 23:02:38 +02:00
|
|
|
|
|
|
|
priv->label_widget = gtk_label_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (self), priv->label_widget, FALSE, FALSE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_constructed (GObject *object)
|
2023-08-17 23:02:38 +02:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (GIMP_RESOURCE_CHOOSER (object));
|
2024-01-05 11:05:32 -05:00
|
|
|
/* Set text of label widget now since underlying property might have changed.
|
|
|
|
* Not when empty string: set_text throws CRITICAL on empty string!
|
|
|
|
*/
|
|
|
|
if (priv->label != NULL)
|
|
|
|
{
|
|
|
|
gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->label_widget), priv->label);
|
|
|
|
gtk_widget_show (GTK_WIDGET (priv->label_widget));
|
|
|
|
}
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
G_OBJECT_CLASS (gimp_resource_chooser_parent_class)->constructed (object);
|
2023-05-31 16:12:04 +02:00
|
|
|
}
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_dispose (GObject *self)
|
2023-05-31 16:12:04 +02:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
|
|
|
GimpResourceChooserClass *klass;
|
2023-08-16 23:53:33 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (GIMP_RESOURCE_CHOOSER (self));
|
|
|
|
klass = GIMP_RESOURCE_CHOOSER_GET_CLASS (self);
|
2023-08-16 23:53:33 +02:00
|
|
|
|
|
|
|
if (priv->callback)
|
|
|
|
{
|
|
|
|
GType resource_type = klass->resource_type;
|
|
|
|
|
|
|
|
if (resource_type == GIMP_TYPE_FONT)
|
|
|
|
gimp_fonts_close_popup (priv->callback);
|
|
|
|
else if (resource_type == GIMP_TYPE_GRADIENT)
|
|
|
|
gimp_gradients_close_popup (priv->callback);
|
|
|
|
else if (resource_type == GIMP_TYPE_BRUSH)
|
|
|
|
gimp_brushes_close_popup (priv->callback);
|
|
|
|
else if (resource_type == GIMP_TYPE_PALETTE)
|
|
|
|
gimp_palettes_close_popup (priv->callback);
|
|
|
|
else if (resource_type == GIMP_TYPE_PATTERN)
|
|
|
|
gimp_patterns_close_popup (priv->callback);
|
|
|
|
else
|
|
|
|
g_warning ("%s: unhandled resource type", G_STRFUNC);
|
|
|
|
|
|
|
|
gimp_plug_in_remove_temp_procedure (gimp_get_plug_in (), priv->callback);
|
|
|
|
g_clear_pointer (&priv->callback, g_free);
|
|
|
|
}
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
G_OBJECT_CLASS (gimp_resource_chooser_parent_class)->dispose (self);
|
2023-05-31 16:12:04 +02:00
|
|
|
}
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_finalize (GObject *object)
|
2023-05-31 16:12:04 +02:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooser *self = GIMP_RESOURCE_CHOOSER (object);
|
|
|
|
GimpResourceChooserPrivate *priv = gimp_resource_chooser_get_instance_private (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
g_clear_pointer (&priv->title, g_free);
|
2023-08-17 23:02:38 +02:00
|
|
|
g_clear_pointer (&priv->label, g_free);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
G_OBJECT_CLASS (gimp_resource_chooser_parent_class)->finalize (object);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-09-28 22:56:16 +02:00
|
|
|
* _gimp_resource_chooser_set_drag_target:
|
2023-10-02 00:07:46 +02:00
|
|
|
* @chooser: A [class@ResourceChooser]
|
2023-05-31 16:12:04 +02:00
|
|
|
* @drag_region_widget: An interior widget to be a droppable region
|
|
|
|
* and emit "drag-data-received" signal
|
2023-08-16 23:53:33 +02:00
|
|
|
* @drag_target: The drag target to accept
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* Called by a subclass init to specialize the instance.
|
|
|
|
*
|
|
|
|
* Subclass knows its interior widget whose region is a drop zone.
|
|
|
|
* Subclass knows what things can be dropped (target.)
|
|
|
|
* Self (super) handles the drop.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
void
|
2024-09-28 22:56:16 +02:00
|
|
|
_gimp_resource_chooser_set_drag_target (GimpResourceChooser *chooser,
|
|
|
|
GtkWidget *drag_region_widget,
|
|
|
|
const GtkTargetEntry *drag_target)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-10-02 00:07:46 +02:00
|
|
|
g_return_if_fail (GIMP_IS_RESOURCE_CHOOSER (chooser));
|
2022-10-15 15:11:05 -04:00
|
|
|
g_return_if_fail (drag_target != NULL);
|
|
|
|
g_return_if_fail (drag_region_widget != NULL);
|
|
|
|
|
|
|
|
gtk_drag_dest_set (drag_region_widget,
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
drag_target, 1, /* Pass array of size 1 */
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
|
2023-10-02 00:07:46 +02:00
|
|
|
/* connect drag_region_widget's drag_received signal to chooser's callback. */
|
2022-10-15 15:11:05 -04:00
|
|
|
g_signal_connect_swapped (drag_region_widget, "drag-data-received",
|
|
|
|
G_CALLBACK (gimp_resource_select_drag_data_received),
|
2023-10-02 00:07:46 +02:00
|
|
|
chooser);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-09-28 22:56:16 +02:00
|
|
|
* _gimp_resource_chooser_set_clickable:
|
2023-10-02 00:07:46 +02:00
|
|
|
* @chooser: A [class@ResourceChooser]
|
|
|
|
* @widget: An interior widget that emits "clicked" signal
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* Called by a subclass init to specialize the instance.
|
|
|
|
*
|
|
|
|
* Subclass knows its interior widget whose region when clicked
|
|
|
|
* should popup remote chooser.
|
|
|
|
* Self handles the click event.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
void
|
2024-09-28 22:56:16 +02:00
|
|
|
_gimp_resource_chooser_set_clickable (GimpResourceChooser *chooser,
|
|
|
|
GtkWidget *widget)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-10-02 00:07:46 +02:00
|
|
|
g_return_if_fail (GIMP_IS_RESOURCE_CHOOSER (chooser));
|
2022-10-15 15:11:05 -04:00
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
/* Require the widget have a signal "clicked", usually a button. */
|
|
|
|
g_signal_connect_swapped (widget, "clicked",
|
2023-08-19 01:22:09 +02:00
|
|
|
G_CALLBACK (gimp_resource_chooser_clicked),
|
2023-10-02 00:07:46 +02:00
|
|
|
chooser);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* gimp_resource_chooser_get_resource:
|
2023-10-02 00:07:46 +02:00
|
|
|
* @chooser: A #GimpResourceChooser
|
2022-10-15 15:11:05 -04:00
|
|
|
*
|
|
|
|
* Gets the currently selected resource.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): an internal copy of the resource which must not be freed.
|
|
|
|
*
|
2023-08-16 23:53:33 +02:00
|
|
|
* Since: 3.0
|
2022-10-15 15:11:05 -04:00
|
|
|
*/
|
|
|
|
GimpResource *
|
2023-10-02 00:07:46 +02:00
|
|
|
gimp_resource_chooser_get_resource (GimpResourceChooser *chooser)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-10-02 00:07:46 +02:00
|
|
|
g_return_val_if_fail (GIMP_IS_RESOURCE_CHOOSER (chooser), NULL);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-10-02 00:07:46 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (chooser);
|
2023-05-31 16:12:04 +02:00
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
return priv->resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* gimp_resource_chooser_set_resource:
|
2023-10-02 00:07:46 +02:00
|
|
|
* @chooser: A #GimpResourceChooser
|
2022-10-15 15:11:05 -04:00
|
|
|
* @resource: Resource to set.
|
|
|
|
*
|
|
|
|
* Sets the currently selected resource.
|
|
|
|
* This will select the resource in both the button and any chooser popup.
|
|
|
|
*
|
2023-08-16 23:53:33 +02:00
|
|
|
* Since: 3.0
|
2022-10-15 15:11:05 -04:00
|
|
|
*/
|
|
|
|
void
|
2023-10-02 00:07:46 +02:00
|
|
|
gimp_resource_chooser_set_resource (GimpResourceChooser *chooser,
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResource *resource)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-10-02 00:07:46 +02:00
|
|
|
g_return_if_fail (GIMP_IS_RESOURCE_CHOOSER (chooser));
|
2022-10-15 15:11:05 -04:00
|
|
|
g_return_if_fail (resource != NULL);
|
|
|
|
|
2023-10-02 00:07:46 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (chooser);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-16 23:53:33 +02:00
|
|
|
if (priv->callback)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
|
|
|
/* A popup chooser dialog is already shown.
|
|
|
|
* Call its setter to change the selection there
|
|
|
|
* (since all views of the resource must be consistent.)
|
|
|
|
* That will call back, which will change our own view of the resource.
|
|
|
|
*/
|
2023-10-02 00:07:46 +02:00
|
|
|
gimp_resource_chooser_set_remote_dialog (chooser, resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Call our own setter. */
|
2023-10-02 00:07:46 +02:00
|
|
|
gimp_resource_chooser_callback (resource, FALSE, chooser);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 23:02:38 +02:00
|
|
|
/**
|
2023-08-19 01:22:09 +02:00
|
|
|
* gimp_resource_chooser_get_label:
|
|
|
|
* @widget: A [class@ResourceChooser].
|
2023-08-17 23:02:38 +02:00
|
|
|
*
|
|
|
|
* Returns the label widget.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the [class@Gtk.Widget] showing the label text.
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_get_label (GimpResourceChooser *widget)
|
2023-08-17 23:02:38 +02:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
g_return_val_if_fail (GIMP_IS_RESOURCE_CHOOSER (widget), NULL);
|
2023-08-17 23:02:38 +02:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (widget);
|
2023-08-17 23:02:38 +02:00
|
|
|
return priv->label_widget;
|
|
|
|
}
|
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_set_remote_dialog (GimpResourceChooser *self,
|
|
|
|
GimpResource *resource)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv;
|
|
|
|
GimpResourceChooserClass *klass;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
g_return_if_fail (GIMP_IS_RESOURCE_CHOOSER (self));
|
2022-10-15 15:11:05 -04:00
|
|
|
g_return_if_fail (resource != NULL);
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
priv = gimp_resource_chooser_get_instance_private (self);
|
|
|
|
klass = GIMP_RESOURCE_CHOOSER_GET_CLASS (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
g_return_if_fail (klass->resource_type != G_TYPE_INVALID);
|
2023-08-16 23:53:33 +02:00
|
|
|
g_return_if_fail (klass->resource_type == G_TYPE_FROM_INSTANCE (resource));
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2024-09-30 17:08:44 +02:00
|
|
|
gimp_resource_select_set (priv->callback, resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *gvalue,
|
|
|
|
GParamSpec *pspec)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooser *self = GIMP_RESOURCE_CHOOSER (object);
|
|
|
|
GimpResourceChooserPrivate *priv = gimp_resource_chooser_get_instance_private (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TITLE:
|
|
|
|
priv->title = g_value_dup_string (gvalue);
|
|
|
|
break;
|
|
|
|
|
2023-08-17 23:02:38 +02:00
|
|
|
case PROP_LABEL:
|
|
|
|
priv->label = g_value_dup_string (gvalue);
|
|
|
|
break;
|
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
case PROP_RESOURCE:
|
2024-09-03 13:31:58 +02:00
|
|
|
gimp_resource_chooser_set_resource (self, g_value_get_object (gvalue));
|
2022-10-15 15:11:05 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooser *self = GIMP_RESOURCE_CHOOSER (object);
|
|
|
|
GimpResourceChooserPrivate *priv = gimp_resource_chooser_get_instance_private (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TITLE:
|
|
|
|
g_value_set_string (value, priv->title);
|
|
|
|
break;
|
|
|
|
|
2023-08-17 23:02:38 +02:00
|
|
|
case PROP_LABEL:
|
|
|
|
g_value_set_string (value, priv->label);
|
|
|
|
break;
|
|
|
|
|
2022-10-15 15:11:05 -04:00
|
|
|
case PROP_RESOURCE:
|
|
|
|
g_value_set_object (value, priv->resource);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A callback from the remote resource select popup.
|
|
|
|
* When user chooses a resource.
|
|
|
|
* Via a temporary PDB procedure.
|
|
|
|
*
|
|
|
|
* Set self's model (priv->resource)
|
|
|
|
* Notify any parent widget subscribed on the "resource" property
|
|
|
|
* typically a prop widget.
|
|
|
|
* Update the view, since model changed.
|
|
|
|
*/
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_callback (GimpResource *resource,
|
|
|
|
gboolean dialog_closing,
|
|
|
|
gpointer user_data)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooser *self = GIMP_RESOURCE_CHOOSER (user_data);
|
|
|
|
GimpResourceChooserPrivate *priv = gimp_resource_chooser_get_instance_private (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
priv->resource = resource;
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
GIMP_RESOURCE_CHOOSER_GET_CLASS (self)->draw_interior (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
|
|
|
if (dialog_closing)
|
2023-08-16 23:53:33 +02:00
|
|
|
g_clear_pointer (&priv->callback, g_free);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-16 23:53:33 +02:00
|
|
|
g_signal_emit (self, resource_button_signals[RESOURCE_SET], 0, resource, dialog_closing);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), resource_button_props[PROP_RESOURCE]);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_clicked (GimpResourceChooser *self)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserPrivate *priv = gimp_resource_chooser_get_instance_private (self);
|
|
|
|
GimpResourceChooserClass *klass = GIMP_RESOURCE_CHOOSER_GET_CLASS (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-16 23:53:33 +02:00
|
|
|
if (priv->callback)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
|
|
|
/* Popup already created. Calling setter raises the popup. */
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_set_remote_dialog (self, priv->resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
app, libgimp, pdb: add a parent_window parameter to gimp_*_popup() PDB calls.
Brush, font, gradient, palette and pattern choices are currently chosen through
a dialog created by the core, which then returns the user choice to the calling
plug-in. This has the unfortunate consequence of having a pile of likely at
least 3 windows (main GIMP window by core process, plug-in window by plug-in
process, then the choice popup by the core process) shared in 2 processes, which
often end up under each other and that's messy. Even more as the choice popup is
kinda expected to be like a sub-part of the plug-in dialog.
So anyway, now the plug-in can send its window handle to the core so that the
resource choice dialog ends up always above the plug-in dialog.
Of course, it will always work only on platforms where we have working
inter-process transient support.
2023-08-15 00:12:16 +02:00
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
|
|
|
GBytes *handle = NULL;
|
|
|
|
|
|
|
|
if (GIMP_IS_DIALOG (toplevel))
|
|
|
|
handle = gimp_dialog_get_native_handle (GIMP_DIALOG (toplevel));
|
|
|
|
|
2024-09-30 17:08:44 +02:00
|
|
|
priv->callback = g_strdup (gimp_resource_select_new (priv->title,
|
|
|
|
handle,
|
|
|
|
priv->resource,
|
|
|
|
klass->resource_type,
|
|
|
|
gimp_resource_chooser_callback,
|
|
|
|
self,
|
|
|
|
NULL));
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_set_remote_dialog (self, priv->resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Drag methods. */
|
|
|
|
|
|
|
|
static void
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_select_drag_data_received (GimpResourceChooser *self,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection,
|
|
|
|
guint info,
|
|
|
|
guint time)
|
2022-10-15 15:11:05 -04:00
|
|
|
{
|
|
|
|
gint length = gtk_selection_data_get_length (selection);
|
|
|
|
gchar *str;
|
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
GimpResourceChooserClass *klass;
|
2022-10-15 15:11:05 -04:00
|
|
|
|
2023-08-19 01:22:09 +02:00
|
|
|
klass = GIMP_RESOURCE_CHOOSER_GET_CLASS (self);
|
2022-10-15 15:11:05 -04:00
|
|
|
/* Require class resource_type was initialized. */
|
|
|
|
g_assert (klass->resource_type != 0);
|
|
|
|
|
|
|
|
/* Drag data is a string that is the ID of the resource. */
|
|
|
|
|
|
|
|
if (gtk_selection_data_get_format (selection) != 8 || length < 1)
|
|
|
|
{
|
|
|
|
g_warning ("%s: received invalid resource data", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_strndup ((const gchar *) gtk_selection_data_get_data (selection),
|
|
|
|
length);
|
|
|
|
|
|
|
|
if (g_utf8_validate (str, -1, NULL))
|
|
|
|
{
|
|
|
|
gint pid;
|
|
|
|
gpointer unused;
|
|
|
|
gint name_offset = 0;
|
|
|
|
|
|
|
|
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
|
|
|
|
pid == gimp_getpid () && name_offset > 0)
|
|
|
|
{
|
|
|
|
gchar *name = str + name_offset;
|
|
|
|
GimpResource *resource;
|
|
|
|
|
2023-05-31 16:12:04 +02:00
|
|
|
resource = gimp_resource_get_by_name (klass->resource_type, name);
|
2023-08-19 01:22:09 +02:00
|
|
|
gimp_resource_chooser_set_resource (self, resource);
|
2022-10-15 15:11:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|