diff --git a/app/pdb/palette-select-cmds.c b/app/pdb/palette-select-cmds.c index 2b8b095abe..6e4b68a2f4 100644 --- a/app/pdb/palette-select-cmds.c +++ b/app/pdb/palette-select-cmds.c @@ -161,7 +161,7 @@ register_palette_select_procs (GimpPDB *pdb) gimp_procedure_add_argument (procedure, gimp_param_spec_string ("initial-palette-name", "initial palette name", - "The palette to set as the initial choice.", + "The name of the palette to set as the initial choice.", FALSE, TRUE, FALSE, NULL, GIMP_PARAM_READWRITE)); diff --git a/devel-docs/GIMP3-plug-in-porting-guide/API-for-resources.md b/devel-docs/GIMP3-plug-in-porting-guide/API-for-resources.md index e380c6a275..78b589fc87 100644 --- a/devel-docs/GIMP3-plug-in-porting-guide/API-for-resources.md +++ b/devel-docs/GIMP3-plug-in-porting-guide/API-for-resources.md @@ -28,8 +28,8 @@ Now, there are methods on resource objects. Methods take an instance of the object as the first argument, often called "self." -This means that whenever you used a string name to refer to a resource object, -you usually should pass an instance of an object. +This means that where you formerly used a string name to refer to a resource object, +now you usually should pass an instance of an object. ### Changes to reference documents @@ -38,8 +38,23 @@ you usually should pass an instance of an object. Shows classes Brush, Font, and so forth. The classes have instance methods taking the instance as the first argument. +Example: + +``` +gboolean gboolean gimp_brush_delete(gcharray) => gboolean gimp_brush_delete ( GimpBrush*) +``` + The classes may also have class methods still taking string names. +Example: + +``` +gboolean gimp_brush_id_is_valid (const gchar* id) +``` + +Is a class method (in the "Functions" section of the class) taking the ID +(same as the name) to test whether such a brush is installed in Gimp core. + #### PDB Browser Remember the PDB Browser shows the C API. You must mentally convert @@ -51,6 +66,28 @@ where formerly they took type gcharray i.e. strings. Shows some procedures that take a string name of a brush. These are usually class methods. +#### Other changes to the API + +Many of the Gimp functions dealing with the context +now take or return an instance of a resource. + +Example: + +``` +gcharray* gimp_context_get_brush (void) => GimpBrush* gimp_context_get_brush (void) +``` + +A few functions have even more changed signature: + +``` +gint gimp_palette_get_info (gcharray) => +gint gimp_palette_get_color_count (GimpPalette*) +``` + +The name and description of this function are changed +to accurately describe that the function only returns an integer +(formerly, the description said it also returned the name of the palette.) + ### New resource objects FUTURE diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am index 6ba3f15f24..170532f306 100644 --- a/libgimp/Makefile.am +++ b/libgimp/Makefile.am @@ -146,7 +146,9 @@ libgimpui_sources = \ libgimpui_built_sources = \ gimpuimarshal.c \ - gimpuimarshal.h + gimpuimarshal.h \ + gimppropchooser.c \ + gimppropchooser.h libgimpui_extra_sources = gimpuimarshal.list diff --git a/libgimp/Makefile.gi b/libgimp/Makefile.gi index 61f85a8b71..8df1359532 100644 --- a/libgimp/Makefile.gi +++ b/libgimp/Makefile.gi @@ -193,7 +193,6 @@ libgimpui_introspectable_headers = \ ../libgimp/gimpproceduredialog.h \ ../libgimp/gimpprocview.h \ ../libgimp/gimpprogressbar.h \ - ../libgimp/gimppropchooser.h \ ../libgimp/gimppropchooserfactory.h \ ../libgimp/gimpresourceselectbutton.h \ ../libgimp/gimpsaveproceduredialog.h \ @@ -215,7 +214,6 @@ libgimpui_introspectable = \ ../libgimp/gimpprocbrowserdialog.c \ ../libgimp/gimpproceduredialog.c \ ../libgimp/gimpprocview.c \ - ../libgimp/gimppropchooser.c \ ../libgimp/gimppropchooserfactory.c \ ../libgimp/gimpsaveproceduredialog.c \ ../libgimp/gimpprogressbar.c \ diff --git a/libgimp/gimp.c b/libgimp/gimp.c index b9a2819506..63f9c3cd8b 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -451,7 +451,13 @@ gimp_main (GType plug_in_type, GIMP_TYPE_CHANNEL, GIMP_TYPE_PARAM_CHANNEL, GIMP_TYPE_LAYER_MASK, GIMP_TYPE_PARAM_LAYER_MASK, GIMP_TYPE_SELECTION, GIMP_TYPE_PARAM_SELECTION, - GIMP_TYPE_VECTORS, GIMP_TYPE_PARAM_VECTORS + GIMP_TYPE_VECTORS, GIMP_TYPE_PARAM_VECTORS, + + GIMP_TYPE_BRUSH, GIMP_TYPE_PARAM_BRUSH, + GIMP_TYPE_FONT, GIMP_TYPE_PARAM_FONT, + GIMP_TYPE_GRADIENT, GIMP_TYPE_PARAM_GRADIENT, + GIMP_TYPE_PALETTE, GIMP_TYPE_PARAM_PALETTE, + GIMP_TYPE_PATTERN, GIMP_TYPE_PARAM_PATTERN }; gint i; diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 197954e3bb..b911d2826d 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -56,8 +56,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c index 42410cf63f..b0a1ec229f 100644 --- a/libgimp/gimpgpparams-body.c +++ b/libgimp/gimpgpparams-body.c @@ -604,8 +604,13 @@ gimp_gp_param_to_value (gpointer gimp, g_return_if_fail (param != NULL); g_return_if_fail (value != NULL); - if (type == G_TYPE_NONE) - type = g_type_from_name (param->type_name); + if (type == G_TYPE_NONE || type == G_TYPE_INVALID) + { + type = g_type_from_name (param->type_name); + if (type == 0) + g_critical ("%s: type name %s is not registered", G_STRFUNC, param->type_name); + } + /* assert type is not G_TYPE_NONE and type is not G_TYPE_INVALID. */ g_value_init (value, type); @@ -730,7 +735,9 @@ gimp_gp_param_to_value (gpointer gimp, } else if (GIMP_VALUE_HOLDS_RESOURCE (value)) { - g_value_set_object (value, get_resource_by_id (gimp, G_VALUE_TYPE (value), param->data.d_string)); + gpointer resource; /* when compiled in app, use generic pointer. */ + resource = get_resource_by_id (gimp, G_VALUE_TYPE (value), param->data.d_string); + g_value_set_object (value, resource); } else if (G_VALUE_HOLDS_PARAM (value)) { @@ -1054,9 +1061,27 @@ gimp_value_to_gp_param (const GValue *value, { GObject *resource = g_value_get_object (value); + /* Represent by a char*, which must be NULL when resource is NULL. + * resource may be NULL e.g. for return value of a canceled dialog. + */ param->param_type = GP_PARAM_TYPE_STRING; - param->data.d_string = resource ? get_resource_id (resource) : ""; + if (resource != NULL) + { + gchar * resource_id = get_resource_id (resource); + /* resource_id can be NULL if resource is invalid. */ + if (full_copy) + param->data.d_string = g_strdup (resource_id); + else + param->data.d_string = resource_id; + } + else + { + param->data.d_string = NULL; + } + /* Ensure ( full_copy AND ( d_string==NULL OR points to new allocation )) + * OR ( not full copy AND ( d_string==NULL OR points to resource's ID char* ) + */ } else if (G_VALUE_HOLDS_PARAM (value)) { diff --git a/libgimp/gimppaletteselect_pdb.c b/libgimp/gimppaletteselect_pdb.c index 72c9cd0730..39cb534f16 100644 --- a/libgimp/gimppaletteselect_pdb.c +++ b/libgimp/gimppaletteselect_pdb.c @@ -41,7 +41,7 @@ * gimp_palettes_popup: * @palette_callback: The callback PDB proc to call when user chooses a palette. * @popup_title: Title of the palette selection dialog. - * @initial_palette_name: The palette to set as the initial choice. + * @initial_palette_name: The name of the palette to set as the initial choice. * * Invokes the Gimp palette selection dialog. * diff --git a/libgimp/gimppropchooser.c b/libgimp/gimppropchooser.c index b9dd888116..d6511440e6 100644 --- a/libgimp/gimppropchooser.c +++ b/libgimp/gimppropchooser.c @@ -24,7 +24,6 @@ #include "gimpui.h" - /* PropChooser * A GtkWidget, more specifically a GtkButtonWidget. * Pops up a chooser widget. @@ -34,28 +33,19 @@ * For now, only for Resource choosers, * which are named GimpResourceSelectButton ("select" means "choose") * - * Call a factory to create PropWidgets, passing a creator function of - * a kind of wrapped widget. + * A factory creates the widgets. + */ + +/* Not public i.e. not annotated. * - * Stack of objects: - * PropWidget (this file) - * SelectButton button pops up a - * Select dialog lets user choose - * libgimp wire protocol to core - * PDBDialog (app/widgets/gimppdbdialog.c) - */ + * Used only by GimpProcedureDialog. + * These could be in the public API, + * if we want plugins to create their own widget that updates the plugin's own property. + * + * The following is in the style of GObject annotations, but is not public. -/* Only brush is annotated. - * Usually these are created by GimpProcedureDialog. - * FIXME: It is not clear that these need to be public API, - * unless a plugin creates its own dialog. - */ - -/** - * gimp_prop_chooser_brush_new: * @config: Object to which property is attached. * @property_name: Name of property controlled by button. - * @chooser_title: Title for the popup chooser dialog. * * Creates a #GimpBrushSelectButton that displays and sets the property. * @@ -67,13 +57,9 @@ * * The button is labeled with the @property_name's nick. * - * When pushed, the button pops up a dialog that lets the user choose a brush. - * The dialog will have the given title. - * - * Returns: (transfer full): The newly created #GimpBrushSelectButton widget. - * - * Since: 3.0 + * When pushed, the button shows a dialog that lets the user choose a brush. */ + GtkWidget * gimp_prop_chooser_brush_new (GObject *config, const gchar *property_name, const gchar *title) { diff --git a/libgimp/gimppropchooserfactory.c b/libgimp/gimppropchooserfactory.c index a61979f05e..545528b930 100644 --- a/libgimp/gimppropchooserfactory.c +++ b/libgimp/gimppropchooserfactory.c @@ -24,8 +24,8 @@ #include "libgimp/gimp.h" #include "libgimp/gimpui.h" - static GimpResource * get_initial_resource_from_config (GObject *config, - const gchar *property_name); +static GimpResource * get_initial_resource_from_config (GObject *config, + const gchar *property_name); /** * gimp_prop_chooser_factory: diff --git a/libgimp/gimpresourceselect.c b/libgimp/gimpresourceselect.c index 071255c8ca..87b4115ab9 100644 --- a/libgimp/gimpresourceselect.c +++ b/libgimp/gimpresourceselect.c @@ -129,9 +129,8 @@ static gboolean gimp_temp_resource_idle (GimpResourceAdaption *adaption) * libgimp simply ignores the extra args (adapts the signature.) */ static void -create_callback_PDB_procedure_params ( - GimpProcedure *procedure, - GType resource_type) +create_callback_PDB_procedure_params (GimpProcedure *procedure, + GType resource_type) { /* Order of args is important. */ @@ -263,11 +262,10 @@ create_callback_PDB_procedure_params ( * Call a PDB procedure that communicates with core to create remote dialog. */ static gboolean -popup_remote_chooser ( - const gchar *title, - GimpResource *resource, - gchar *temp_PDB_callback_name, - GType resource_type) +popup_remote_chooser (const gchar *title, + GimpResource *resource, + gchar *temp_PDB_callback_name, + GType resource_type) { gboolean result = FALSE; gchar *resource_name; @@ -306,9 +304,8 @@ popup_remote_chooser ( /*Does nothing, quietly, when the remote dialog is not open. */ static void -close_remote_chooser ( - gchar *temp_PDB_callback_name, - GType resource_type) +close_remote_chooser (gchar *temp_PDB_callback_name, + GType resource_type) { if (g_type_is_a (resource_type, GIMP_TYPE_FONT)) { @@ -393,13 +390,12 @@ index_of_is_closing_arg (GType resource_type) const gchar * -gimp_resource_select_new ( - const gchar *title, - GimpResource *resource, - GType resource_type, - GimpResourceChoosedCallback callback, - gpointer owner_data, - GDestroyNotify data_destroy) + gimp_resource_select_new (const gchar *title, + GimpResource *resource, + GType resource_type, + GimpResourceChoosedCallback callback, + gpointer owner_data, + GDestroyNotify data_destroy) { GimpPlugIn *plug_in = gimp_get_plug_in (); GimpProcedure *procedure; @@ -478,10 +474,9 @@ gimp_resource_select_destroy (const gchar *temp_PDB_callback_name) * so pdb/groups/_select.pdb, _set_popup must have type string. */ void -gimp_resource_select_set ( - const gchar *temp_pdb_callback, - GimpResource *resource, - GType resource_type) +gimp_resource_select_set (const gchar *temp_pdb_callback, + GimpResource *resource, + GType resource_type) { gchar * resource_name; @@ -556,10 +551,9 @@ gimp_resource_data_free (GimpResourceAdaption *adaption) * Called when user chooses a resource in remote dialog. */ static GimpValueArray * -gimp_temp_resource_run ( - GimpProcedure *procedure, - const GimpValueArray *args, - gpointer run_data) /* is-a adaption */ +gimp_temp_resource_run (GimpProcedure *procedure, + const GimpValueArray *args, + gpointer run_data) /* is-a adaption */ { GimpResourceAdaption *adaption = run_data; const gchar *resource_name; @@ -585,8 +579,7 @@ gimp_temp_resource_run ( * but idle_id is not used by the idle func. */ if (! adaption->idle_id) - adaption->idle_id = g_idle_add ((GSourceFunc) gimp_temp_resource_idle, - adaption); + adaption->idle_id = g_idle_add ((GSourceFunc) gimp_temp_resource_idle, adaption); return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL); } diff --git a/libgimp/gimpresourceselectbutton.c b/libgimp/gimpresourceselectbutton.c index ccd17862ab..63d1783e31 100644 --- a/libgimp/gimpresourceselectbutton.c +++ b/libgimp/gimpresourceselectbutton.c @@ -156,6 +156,9 @@ static void gimp_resource_select_drag_data_received (GimpResourceSelectButton static void gimp_resource_select_button_set_remote_dialog (GimpResourceSelectButton *self, GimpResource *resource); +static void gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self, + GimpResource *resource); + static guint resource_button_signals[LAST_SIGNAL] = { 0 }; static GParamSpec *resource_button_props[N_PROPS] = { NULL, }; @@ -409,20 +412,15 @@ gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, GtkW /* We can't draw the interior until self property "resource" is set. */ } -/** - * gimp_resource_select_button_draw_interior: - * @self: A #GimpResourceSelectButton - * @resource: A resource instance whose attributes should be drawn. +/* Calls the virtual method of a similar name, which subclasses must override. * - * Calls the virtual method of a similar name, which subclasses must override. + * resource: The instance to be drawn. * * A subclass knows how to draw its interior. * Called by super when the view is invalidated (needs to be redrawn.) - * Public, but subclasses do not ordinarily call this function. - * - * Since: 3.0 - **/ -void + * Not public. + */ +static void gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self, GimpResource *resource) { GimpResourceSelectButtonClass *klass; @@ -489,7 +487,7 @@ gimp_resource_select_button_set_property (GObject *object, const GValue *gvalue, GParamSpec *pspec) { - GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object); + GimpResourceSelectButton *self = GIMP_RESOURCE_SELECT_BUTTON (object); GimpResourceSelectButtonPrivate *priv = gimp_resource_select_button_get_instance_private (self); g_debug ("%s, id: %i", G_STRFUNC, property_id); @@ -725,7 +723,7 @@ gimp_resource_select_button_finalize (GObject *object) g_debug ("%s", G_STRFUNC); - g_clear_pointer (&priv->resource, g_free); + g_clear_pointer (&priv->resource, g_object_unref); g_free ((gpointer) priv->title); /* Chain up. */ diff --git a/libgimp/gimpresourceselectbutton.h b/libgimp/gimpresourceselectbutton.h index 2e73e30d1a..1cc7b61733 100644 --- a/libgimp/gimpresourceselectbutton.h +++ b/libgimp/gimpresourceselectbutton.h @@ -65,10 +65,6 @@ GimpResource *gimp_resource_select_button_get_resource (GimpResourceSelectButton void gimp_resource_select_button_set_resource (GimpResourceSelectButton *self, GimpResource *resource); -/* Public, but called by super. */ -void gimp_resource_select_button_draw_interior (GimpResourceSelectButton *self, - GimpResource *resource); - /* API from below, used by subclasses e.g. GimpBrushSelectButton */ void gimp_resource_select_button_embed_interior (GimpResourceSelectButton *self, diff --git a/libgimp/gimpui.def b/libgimp/gimpui.def index ce71f3002a..6a9eac4812 100644 --- a/libgimp/gimpui.def +++ b/libgimp/gimpui.def @@ -68,7 +68,6 @@ EXPORTS gimp_prop_chooser_palette_new gimp_prop_chooser_pattern_new gimp_resource_select_button_close_popup - gimp_resource_select_button_draw_interior gimp_resource_select_button_embed_interior gimp_resource_select_button_get_resource gimp_resource_select_button_get_type diff --git a/libgimp/meson.build b/libgimp/meson.build index c296a291ea..e2e98e9661 100644 --- a/libgimp/meson.build +++ b/libgimp/meson.build @@ -272,7 +272,6 @@ libgimpui_sources_introspectable = [ 'gimpproceduredialog.c', 'gimpprocview.c', 'gimpprogressbar.c', - 'gimppropchooser.c', 'gimppropchooserfactory.c', 'gimpresourceselectbutton.c', 'gimpsaveproceduredialog.c', @@ -283,6 +282,7 @@ libgimpui_sources_introspectable = [ libgimpui_sources = [ libgimpui_sources_introspectable, gimpuimarshal, + 'gimppropchooser.c', ] libgimpui_headers_introspectable = [ @@ -305,7 +305,6 @@ libgimpui_headers_introspectable = [ 'gimpproceduredialog.h', 'gimpprocview.h', 'gimpprogressbar.h', - 'gimppropchooser.h', 'gimppropchooserfactory.h', 'gimpresourceselectbutton.h', 'gimpsaveproceduredialog.h', diff --git a/pdb/groups/palette_select.pdb b/pdb/groups/palette_select.pdb index 5394df853b..84d0832bae 100644 --- a/pdb/groups/palette_select.pdb +++ b/pdb/groups/palette_select.pdb @@ -28,7 +28,7 @@ sub palettes_popup { { name => 'popup_title', type => 'string', desc => 'Title of the palette selection dialog' }, { name => 'initial_palette_name', type => 'string', null_ok => 1, - desc => 'The palette to set as the initial choice.' } + desc => 'The name of the palette to set as the initial choice.' } ); %invoke = ( diff --git a/plug-ins/Makefile.am b/plug-ins/Makefile.am index a8c4869c27..06d5cabfeb 100644 --- a/plug-ins/Makefile.am +++ b/plug-ins/Makefile.am @@ -24,10 +24,6 @@ if HAVE_WEBP file_webp = file-webp endif -# lkk temporarily not making these plugins until next commit fixes them for Resource -# gfig -# pagecurl - SUBDIRS = \ script-fu \ file-bmp \ @@ -47,6 +43,7 @@ SUBDIRS = \ $(file_webp) \ flame \ fractal-explorer \ + gfig \ gimpressionist \ gradient-flare \ help \ @@ -56,6 +53,7 @@ SUBDIRS = \ lighting \ map-object \ metadata \ + pagecurl \ $(print) \ $(python) \ screenshot \ diff --git a/plug-ins/common/film.c b/plug-ins/common/film.c index 1f081e29f7..72fdf64aa4 100644 --- a/plug-ins/common/film.c +++ b/plug-ins/common/film.c @@ -44,6 +44,7 @@ /* Define how the plug-in works. Values marked (r) are with regard */ /* to film_height (i.e. it should be a value from 0.0 to 1.0) */ +/* Saved as settings. Must be trivially serializable; no pointers. */ typedef struct { gint film_height; /* height of the film */ @@ -57,7 +58,8 @@ typedef struct gdouble number_height; /* height of picture numbering (r) */ gint number_start; /* number for first picture */ GimpRGB number_color; /* color of number */ - gchar number_font[FONT_LEN]; /* font family to use for numbering */ + GimpFont *number_font; /* font family for numbering */ + gchar font_name[FONT_LEN]; /* serializable name of font for numbering */ gint number_pos[2]; /* flags where to draw numbers (top/bottom) */ gint keep_height; /* flag if to keep max. image height */ gint num_images; /* number of images */ @@ -142,13 +144,16 @@ static gboolean film_dialog (GimpImage *image); static void film_reset_callback (GtkWidget *widget, gpointer data); static void film_font_select_callback (GimpFontSelectButton *button, - const gchar *name, + GimpResource *font, gboolean closing, gpointer data); static void film_scale_entry_update_double (GimpLabelSpin *entry, gdouble *value); +static void film_load_settings (void); +static void film_save_settings (void); + G_DEFINE_TYPE (Film, film, GIMP_TYPE_PLUG_IN) GIMP_MAIN (FILM_TYPE) @@ -179,7 +184,8 @@ static FilmVals filmvals = 0.052, /* Image number height */ 1, /* Start index of numbering */ { 0.93, 0.61, 0.0, 1.0 }, /* Color of number */ - "Monospace", /* Font family for numbering */ + NULL, /* !!! No default, must be set later. */ + "Monospace", /* Case sensitive, must be name of an installed font. */ { TRUE, TRUE }, /* Numbering on top and bottom */ 0, /* Don't keep max. image height */ 0, /* Number of images */ @@ -263,11 +269,10 @@ film_create_procedure (GimpPlugIn *plug_in, G_MININT, G_MAXINT, 1, G_PARAM_READWRITE); - GIMP_PROC_ARG_STRING (procedure, "number-font", - "Number font", - "Font for drawing numbers", - NULL, - G_PARAM_READWRITE); + GIMP_PROC_ARG_FONT (procedure, "number-font", + "Number font", + "Font for drawing numbers", + G_PARAM_READWRITE); GIMP_PROC_ARG_RGB (procedure, "number-color", "Number color", @@ -328,7 +333,7 @@ film_run (GimpProcedure *procedure, switch (run_mode) { case GIMP_RUN_INTERACTIVE: - gimp_get_data (PLUG_IN_PROC, &filmvals); + film_load_settings(); if (! film_dialog (image)) { @@ -350,9 +355,7 @@ film_run (GimpProcedure *procedure, } GIMP_VALUES_GET_RGB (args, 1, &filmvals.film_color); filmvals.number_start = GIMP_VALUES_GET_INT (args, 2); - g_strlcpy (filmvals.number_font, - GIMP_VALUES_GET_STRING (args, 3), - FONT_LEN); + filmvals.number_font = GIMP_VALUES_GET_FONT (args, 3); GIMP_VALUES_GET_RGB (args, 4, &filmvals.number_color); filmvals.number_pos[0] = GIMP_VALUES_GET_INT (args, 5); filmvals.number_pos[1] = GIMP_VALUES_GET_INT (args, 6); @@ -364,7 +367,7 @@ film_run (GimpProcedure *procedure, break; case GIMP_RUN_WITH_LAST_VALS: - gimp_get_data (PLUG_IN_PROC, &filmvals); + film_load_settings(); break; default: @@ -400,9 +403,8 @@ film_run (GimpProcedure *procedure, gimp_display_new (image); } - /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) - gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals)); + film_save_settings(); } if (! return_vals) @@ -646,8 +648,9 @@ check_filmvals (void) if (filmvals.number_start < 0) filmvals.number_start = 0; - if (filmvals.number_font[0] == '\0') - strcpy (filmvals.number_font, "Monospace"); + if (filmvals.number_font == NULL) + filmvals.number_font = gimp_context_get_font (); + g_assert (GIMP_IS_FONT (filmvals.number_font)); for (i = 0, j = 0; i < filmvals.num_images; i++) { @@ -737,7 +740,12 @@ draw_number (GimpLayer *layer, GimpImage *image; GimpLayer *text_layer; gint text_width, text_height, text_ascent, descent; - gchar *fontname = filmvals.number_font; + + GimpFont *font = filmvals.number_font; + gchar *fontname; + + /* FIXME: gimp_text methods should take GimpFont font instead of font_name */ + g_object_get (font, "id", &fontname, NULL); g_snprintf (buf, sizeof (buf), "%d", num); @@ -1124,8 +1132,9 @@ create_selection_tab (GtkWidget *notebook, &filmvals.number_start); /* Fontfamily for numbering */ - font_button = gimp_font_select_button_new (NULL, filmvals.number_font); - g_signal_connect (font_button, "font-set", + /* Require filmvals.number_font is NULL or a valid GimpFont. */ + font_button = gimp_font_select_button_new (NULL, GIMP_RESOURCE (filmvals.number_font)); + g_signal_connect (font_button, "resource-set", G_CALLBACK (film_font_select_callback), &filmvals); label = gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1, _("_Font:"), 0.0, 0.5, @@ -1388,13 +1397,13 @@ film_reset_callback (GtkWidget *widget, static void film_font_select_callback (GimpFontSelectButton *button, - const gchar *name, + GimpResource *resource, gboolean closing, gpointer data) { FilmVals *vals = (FilmVals *) data; - g_strlcpy (vals->number_font, name, FONT_LEN); + vals->number_font = GIMP_FONT (resource); } static void @@ -1403,3 +1412,32 @@ film_scale_entry_update_double (GimpLabelSpin *entry, { *value = gimp_label_spin_get_value (entry); } + +/* FIXME: use GimpProcedureConfig + * + * Now using the old method: get_data. + * And chunking the settings into global struct filmvals instead of properties. + */ +static void +film_load_settings (void) +{ + (void) gimp_get_data (PLUG_IN_PROC, &filmvals); + /* When no data, returns false and filmvals is as statically initialized. */ + + /* The GimpFont pointer was unserialized but garbage. + * Restore pointer from the name which was also serialized. + * A hack that goes away when GimpProcedureConfig is used. + */ + filmvals.number_font = g_object_new (GIMP_TYPE_FONT, "id", filmvals.font_name, NULL); +} + +static void +film_save_settings (void) +{ + /* Copy font name from font, i.e. serialize string not pointer. */ + g_strlcpy (filmvals.font_name, + gimp_resource_get_id (GIMP_RESOURCE (filmvals.number_font)), + FONT_LEN); + + gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals)); +} diff --git a/plug-ins/common/gradient-map.c b/plug-ins/common/gradient-map.c index d26a784184..a2cd0ea6e3 100644 --- a/plug-ins/common/gradient-map.c +++ b/plug-ins/common/gradient-map.c @@ -416,16 +416,16 @@ map (GeglBuffer *buffer, static gdouble * get_samples_gradient (GimpDrawable *drawable) { - gchar *gradient_name; + GimpGradient *gradient; + gint n_d_samples; gdouble *d_samples = NULL; - gradient_name = gimp_context_get_gradient (); + gradient = gimp_context_get_gradient (); /* FIXME: "reverse" hardcoded to FALSE. */ - gimp_gradient_get_uniform_samples (gradient_name, NSAMPLES, FALSE, + gimp_gradient_get_uniform_samples (gradient, NSAMPLES, FALSE, &n_d_samples, &d_samples); - g_free (gradient_name); if (! gimp_drawable_is_rgb (drawable)) { diff --git a/plug-ins/common/sample-colorize.c b/plug-ins/common/sample-colorize.c index e51569377a..40ea8b1a3a 100644 --- a/plug-ins/common/sample-colorize.c +++ b/plug-ins/common/sample-colorize.c @@ -2478,7 +2478,8 @@ fill_missing_colors (void) static void get_gradient (gint mode) { - gchar *name; + GimpGradient *gradient; + gint n_f_samples; gdouble *f_samples; gdouble *f_samp; /* float samples */ @@ -2486,14 +2487,12 @@ get_gradient (gint mode) free_colors (); - name = gimp_context_get_gradient (); + gradient = gimp_context_get_gradient (); - gimp_gradient_get_uniform_samples (name, 256 /* n_samples */, + gimp_gradient_get_uniform_samples (gradient, 256 /* n_samples */, mode == SMP_INV_GRADIENT, &n_f_samples, &f_samples); - g_free (name); - for (lum = 0; lum < 256; lum++) { f_samp = &f_samples[lum * 4]; diff --git a/plug-ins/flame/flame.c b/plug-ins/flame/flame.c index fbd2e2024f..3d186bce60 100644 --- a/plug-ins/flame/flame.c +++ b/plug-ins/flame/flame.c @@ -318,15 +318,15 @@ drawable_to_cmap (control_point *cp) } else if (GRADIENT_DRAWABLE == config.cmap_drawable_id) { - gchar *name = gimp_context_get_gradient (); + GimpGradient *gradient = gimp_context_get_gradient (); + gint num; gdouble *g; /* FIXME: "reverse" hardcoded to FALSE. */ - gimp_gradient_get_uniform_samples (name, 256, FALSE, + gimp_gradient_get_uniform_samples (gradient, 256, FALSE, &num, &g); - g_free (name); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) diff --git a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c index b3c93f5e37..7828803d9d 100644 --- a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c +++ b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c @@ -38,7 +38,7 @@ static gint n_gradient_samples = 0; static gdouble *gradient_samples = NULL; -static gchar *gradient_name = NULL; +static GimpGradient *gradient = NULL; static gboolean ready_now = FALSE; static gchar *tpath = NULL; static DialogElements *elements = NULL; @@ -286,10 +286,10 @@ explorer_number_of_colors_callback (GtkAdjustment *adjustment, g_free (gradient_samples); - if (! gradient_name) - gradient_name = gimp_context_get_gradient (); + if (! gradient) + gradient = gimp_context_get_gradient (); - gimp_gradient_get_uniform_samples (gradient_name, + gimp_gradient_get_uniform_samples (gradient, wvals.ncolors, wvals.gradinvert, &n_gradient_samples, @@ -299,20 +299,15 @@ explorer_number_of_colors_callback (GtkAdjustment *adjustment, dialog_update_preview (); } +/* Same signature as all GimpResourceSelectButton */ static void -explorer_gradient_select_callback (GimpGradientSelectButton *gradient_button, - const gchar *name, - gint width, - const gdouble *gradient_data, - gboolean dialog_closing, - gpointer data) +explorer_gradient_select_callback (gpointer data, /* widget */ + GimpGradient *gradient, + gboolean dialog_closing) { - g_free (gradient_name); g_free (gradient_samples); - gradient_name = g_strdup (name); - - gimp_gradient_get_uniform_samples (gradient_name, + gimp_gradient_get_uniform_samples (gradient, wvals.ncolors, wvals.gradinvert, &n_gradient_samples, @@ -521,9 +516,9 @@ explorer_dialog (void) GtkWidget *hbox; GtkWidget *grid; GtkWidget *button; - GtkWidget *gradient; + GtkWidget *gradient_button; gchar *path; - gchar *gradient_name; + GimpGradient *gradient; GSList *group = NULL; gint i; @@ -1156,21 +1151,21 @@ explorer_dialog (void) _("Create a color-map using a gradient from " "the gradient editor"), NULL); - gradient_name = gimp_context_get_gradient (); + gradient = gimp_context_get_gradient (); - gimp_gradient_get_uniform_samples (gradient_name, + gimp_gradient_get_uniform_samples (gradient, wvals.ncolors, wvals.gradinvert, &n_gradient_samples, &gradient_samples); - gradient = gimp_gradient_select_button_new (_("FractalExplorer Gradient"), - gradient_name); - g_signal_connect (gradient, "gradient-set", + gradient_button = gimp_gradient_select_button_new (_("FractalExplorer Gradient"), + GIMP_RESOURCE (gradient)); + g_signal_connect (gradient_button, "resource-set", G_CALLBACK (explorer_gradient_select_callback), NULL); - g_free (gradient_name); - gtk_box_pack_start (GTK_BOX (hbox), gradient, FALSE, FALSE, 0); - gtk_widget_show (gradient); + + gtk_box_pack_start (GTK_BOX (hbox), gradient_button, FALSE, FALSE, 0); + gtk_widget_show (gradient_button); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); { @@ -1341,15 +1336,13 @@ make_color_map (void) */ if (gradient_samples == NULL) { - gchar *gradient_name = gimp_context_get_gradient (); + GimpGradient *gradient = gimp_context_get_gradient (); - gimp_gradient_get_uniform_samples (gradient_name, + gimp_gradient_get_uniform_samples (gradient, wvals.ncolors, wvals.gradinvert, &n_gradient_samples, &gradient_samples); - - g_free (gradient_name); } redstretch = wvals.redstretch * 127.5; diff --git a/plug-ins/gfig/gfig-dialog.c b/plug-ins/gfig/gfig-dialog.c index a856b13a7f..7beb78ee6b 100644 --- a/plug-ins/gfig/gfig-dialog.c +++ b/plug-ins/gfig/gfig-dialog.c @@ -298,6 +298,8 @@ gfig_dialog (void) NULL); + gimp_window_set_transient (GTK_WINDOW (top_level_dlg)); + gimp_dialog_set_alternative_button_order (GTK_DIALOG (top_level_dlg), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, @@ -394,8 +396,8 @@ gfig_dialog (void) /* brush selector in Stroke frame */ gfig_context->brush_select = gimp_brush_select_button_new ("Brush", - gfig_context->default_style.brush); - g_signal_connect (gfig_context->brush_select, "brush-set", + GIMP_RESOURCE (gfig_context->default_style.brush)); + g_signal_connect (gfig_context->brush_select, "resource-set", G_CALLBACK (gfig_brush_changed_callback), NULL); gtk_box_pack_start (GTK_BOX (vbox), gfig_context->brush_select, FALSE, FALSE, 0); @@ -459,8 +461,9 @@ gfig_dialog (void) /* A page for the pattern selector */ gfig_context->pattern_select - = gimp_pattern_select_button_new ("Pattern", gfig_context->default_style.pattern); - g_signal_connect (gfig_context->pattern_select, "pattern-set", + = gimp_pattern_select_button_new ("Pattern", + GIMP_RESOURCE (gfig_context->default_style.pattern)); + g_signal_connect (gfig_context->pattern_select, "resource-set", G_CALLBACK (gfig_pattern_changed_callback), NULL); gtk_widget_show (gfig_context->pattern_select); gtk_notebook_append_page (GTK_NOTEBOOK (fill_type_notebook), @@ -468,8 +471,9 @@ gfig_dialog (void) /* A page for the gradient selector */ gfig_context->gradient_select - = gimp_gradient_select_button_new ("Gradient", gfig_context->default_style.gradient); - g_signal_connect (gfig_context->gradient_select, "gradient-set", + = gimp_gradient_select_button_new ("Gradient", + GIMP_RESOURCE (gfig_context->default_style.gradient)); + g_signal_connect (gfig_context->gradient_select, "resource-set", G_CALLBACK (gfig_gradient_changed_callback), NULL); gtk_widget_show (gfig_context->gradient_select); gtk_notebook_append_page (GTK_NOTEBOOK (fill_type_notebook), @@ -518,8 +522,7 @@ gfig_dialog (void) gfig_list_load_all (gfig_path); /* Setup initial brush settings */ - gfig_context->bdesc.name = gimp_context_get_brush (); - mygimp_brush_info (&gfig_context->bdesc.width, &gfig_context->bdesc.height); + set_context_bdesc (gimp_context_get_brush ()); gtk_widget_show (main_hbox); @@ -2031,7 +2034,13 @@ toggle_obj_type (GtkRadioAction *action, GtkRadioAction *current, gpointer data) { - static GdkCursor *p_cursors[DEL_OBJ + 1]; + /* cache of cursors. + * Must be larger than action values, i.e. NULL_OPER. + * Test by clicking the "select object" icon. + * C ensures is initialized to NULL. + */ + static GdkCursor *p_cursors[NULL_OPER]; + GdkCursorType ctype = GDK_LAST_CURSOR; DobjType new_type; @@ -2045,13 +2054,17 @@ toggle_obj_type (GtkRadioAction *action, if (new_type < MOVE_OBJ) /* Eeeeek */ { + g_debug ("%s new_type < MOVE_OBJ", G_STRFUNC); obj_show_single = -1; /* Cancel select preview */ } /* Update draw areas */ gtk_widget_queue_draw (gfig_context->preview); } + g_debug ("%s: old and new obj type %d %d", G_STRFUNC, selvals.otype, new_type); + selvals.otype = new_type; + gtk_notebook_set_current_page (GTK_NOTEBOOK (tool_options_notebook), new_type - 1); @@ -2066,7 +2079,6 @@ toggle_obj_type (GtkRadioAction *action, case STAR: case SPIRAL: case BEZIER: - default: ctype = GDK_CROSSHAIR; break; case MOVE_OBJ: @@ -2078,14 +2090,26 @@ toggle_obj_type (GtkRadioAction *action, case DEL_OBJ: ctype = GDK_PIRATE; break; + case OBJ_TYPE_NONE: + ctype = GDK_CROSSHAIR; + break; + default: + g_debug ("%s: default cursor for object type %d.", G_STRFUNC, selvals.otype); + ctype = GDK_CROSSHAIR; + break; } + /* Get cached cursor. */ if (!p_cursors[selvals.otype]) { - GdkDisplay *display = gtk_widget_get_display (gfig_context->preview); + GdkCursor *cursor; - p_cursors[selvals.otype] = gdk_cursor_new_for_display (display, ctype); + GdkDisplay *display = gtk_widget_get_display (gfig_context->preview); + cursor = gdk_cursor_new_for_display (display, ctype); + p_cursors[selvals.otype] = cursor; } + /* Require cursor (possibly from cache) is-a cursor. */ + g_assert (GDK_IS_CURSOR (p_cursors[selvals.otype])); gdk_window_set_cursor (gtk_widget_get_window (gfig_context->preview), p_cursors[selvals.otype]); diff --git a/plug-ins/gfig/gfig-style.c b/plug-ins/gfig/gfig-style.c index fc018b2a03..f3f3c3bb14 100644 --- a/plug-ins/gfig/gfig-style.c +++ b/plug-ins/gfig/gfig-style.c @@ -37,10 +37,11 @@ #include "gfig-style.h" -static void gfig_read_parameter_string (gchar **text, +static void gfig_read_resource (gchar **text, gint nitems, - const gchar *name, - gchar **style_entry); + const gchar *tag, + GimpResource **style_entry, + GType resource_type); static void gfig_read_parameter_int (gchar **text, gint nitems, @@ -57,18 +58,21 @@ static void gfig_read_parameter_gimp_rgb (gchar **text, const gchar *name, GimpRGB *style_entry); +/* From a style string, read a resource name, + * create a resource object, and put it in + * given entry of a style. + */ static void -gfig_read_parameter_string (gchar **text, - gint nitems, - const gchar *name, - gchar **style_entry) +gfig_read_resource (gchar **text, + gint nitems, + const gchar *tag, + GimpResource **style_entry, + GType resource_type) { gint n = 0; gchar *ptr; gchar *tmpstr; - *style_entry = NULL; - while (n < nitems) { ptr = strchr (text[n], ':'); @@ -76,9 +80,21 @@ gfig_read_parameter_string (gchar **text, { tmpstr = g_strndup (text[n], ptr - text[n]); ptr++; - if (!strcmp (tmpstr, name)) + if (!strcmp (tmpstr, tag)) { - *style_entry = g_strdup (g_strchug (ptr)); + /* Create a resource object, just a proxy for the thing in core. */ + GimpResource *resource; + gchar *resource_id = g_strdup (g_strchug (ptr)); + + resource = g_object_new (resource_type, "id", resource_id, NULL); + /* We own the resource object, its refcount is one. + * The resource object owns its string ID. + */ + *style_entry = resource; + /* We are not checking the ID is valid. + * The user might have uninstalled the resource. + */ + g_free (tmpstr); return; } @@ -87,7 +103,9 @@ gfig_read_parameter_string (gchar **text, ++n; } - g_message ("Parameter '%s' not found", name); + /* Fail */ + *style_entry = NULL; + g_message ("Parameter '%s' not found", tag); } @@ -254,14 +272,16 @@ gfig_load_style (Style *style, return TRUE; } - gfig_read_parameter_string (style_text, nitems, "BrushName", - &style->brush); + gfig_read_resource (style_text, nitems, "BrushName", + (GimpResource**) &style->brush, GIMP_TYPE_BRUSH); if (style->brush == NULL) - g_message ("Error loading style: got NULL for brush name."); + g_message ("Error loading style: missing brush."); - gfig_read_parameter_string (style_text, nitems, "Pattern", &style->pattern); - gfig_read_parameter_string (style_text, nitems, "Gradient", &style->gradient); + gfig_read_resource (style_text, nitems, "Pattern", + (GimpResource**) &style->pattern, GIMP_TYPE_PATTERN); + gfig_read_resource (style_text, nitems, "Gradient", + (GimpResource**) &style->gradient, GIMP_TYPE_GRADIENT); gfig_read_parameter_gimp_rgb (style_text, nitems, "Foreground", &style->foreground); @@ -353,10 +373,12 @@ gfig_save_style (Style *style, gint blen = G_ASCII_DTOSTR_BUF_SIZE; if (gfig_context->debug_styles) - g_printerr ("Saving style %s, brush name '%s'\n", style->name, style->brush); + g_printerr ("Saving style %s, brush name '%s'\n", style->name, + gimp_resource_get_id (GIMP_RESOURCE (style->brush))); g_string_append_printf (string, "