mirror of https://github.com/GNOME/gimp.git
libgimp: port gimp*select.[ch] to the new plug-in API
Use the new implementation only if a GimpPlugIn exists, use the old code otherwise. Add a GDestroyNotify for the callabck's user_data.
This commit is contained in:
parent
224af7e42f
commit
6e80a2324f
|
@ -37,19 +37,24 @@ typedef struct
|
|||
GimpRunBrushCallback callback;
|
||||
gboolean closing;
|
||||
gpointer data;
|
||||
GDestroyNotify data_destroy;
|
||||
} GimpBrushData;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_brush_data_free (GimpBrushData *data);
|
||||
static void gimp_brush_data_free (GimpBrushData *data);
|
||||
|
||||
static void gimp_temp_brush_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gboolean gimp_temp_brush_run_idle (GimpBrushData *brush_data);
|
||||
static void gimp_temp_brush_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static GimpValueArray *
|
||||
gimp_temp_brush_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static gboolean gimp_temp_brush_run_idle (GimpBrushData *brush_data);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -66,66 +71,158 @@ gimp_brush_select_new (const gchar *title,
|
|||
gint spacing,
|
||||
GimpLayerMode paint_mode,
|
||||
GimpRunBrushCallback callback,
|
||||
gpointer data)
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_FLOAT, "opacity", "Opacity" },
|
||||
{ GIMP_PDB_INT32, "spacing", "Spacing" },
|
||||
{ GIMP_PDB_INT32, "paint mode", "Paint mode" },
|
||||
{ GIMP_PDB_INT32, "mask width", "Brush width" },
|
||||
{ GIMP_PDB_INT32, "mask height" "Brush height" },
|
||||
{ GIMP_PDB_INT32, "mask len", "Length of brush mask data" },
|
||||
{ GIMP_PDB_INT8ARRAY, "mask data", "The brush mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
gchar *brush_callback = gimp_procedural_db_temp_name ();
|
||||
GimpBrushData *brush_data;
|
||||
|
||||
gchar *brush_callback = gimp_procedural_db_temp_name ();
|
||||
brush_data = g_slice_new0 (GimpBrushData);
|
||||
|
||||
gimp_install_temp_proc (brush_callback,
|
||||
"Temporary brush popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_brush_run);
|
||||
brush_data->brush_callback = brush_callback;
|
||||
brush_data->callback = callback;
|
||||
brush_data->data = data;
|
||||
brush_data->data_destroy = data_destroy;
|
||||
|
||||
if (plug_in)
|
||||
{
|
||||
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||
brush_callback,
|
||||
GIMP_TEMPORARY,
|
||||
gimp_temp_brush_run_func,
|
||||
brush_data,
|
||||
(GDestroyNotify)
|
||||
gimp_brush_data_free);
|
||||
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_string ("brush-name",
|
||||
"Brush name",
|
||||
"The brush name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_double ("opacity",
|
||||
"Opacity",
|
||||
NULL,
|
||||
0.0, 1.0, 1.0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("spacing",
|
||||
"Spacing",
|
||||
NULL,
|
||||
-1, 1000, 20,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_enum ("paint-mode",
|
||||
"Paint mode",
|
||||
NULL,
|
||||
GIMP_TYPE_LAYER_MODE,
|
||||
GIMP_LAYER_MODE_NORMAL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("mask-width",
|
||||
"Brush width",
|
||||
NULL,
|
||||
0, 10000, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("mask-height",
|
||||
"Brush height",
|
||||
NULL,
|
||||
0, 10000, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int32 ("mask-len",
|
||||
"Mask length",
|
||||
"Length of brush "
|
||||
"mask data",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int8_array ("mask-data",
|
||||
"Mask data",
|
||||
"The brush mask "
|
||||
"data",
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("closing",
|
||||
"Closing",
|
||||
"If the dialog was "
|
||||
"cloaing",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_FLOAT, "opacity", "Opacity" },
|
||||
{ GIMP_PDB_INT32, "spacing", "Spacing" },
|
||||
{ GIMP_PDB_INT32, "paint mode", "Paint mode" },
|
||||
{ GIMP_PDB_INT32, "mask width", "Brush width" },
|
||||
{ GIMP_PDB_INT32, "mask height" "Brush height" },
|
||||
{ GIMP_PDB_INT32, "mask len", "Length of brush mask data" },
|
||||
{ GIMP_PDB_INT8ARRAY, "mask data", "The brush mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
|
||||
gimp_install_temp_proc (brush_callback,
|
||||
"Temporary brush popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_brush_run);
|
||||
}
|
||||
|
||||
if (gimp_brushes_popup (brush_callback, title, brush_name,
|
||||
opacity, spacing, paint_mode))
|
||||
{
|
||||
GimpBrushData *brush_data;
|
||||
|
||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
||||
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_brush_select_ht)
|
||||
/* Allow callbacks to be watched */
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_brush_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_brush_data_free);
|
||||
gimp_plug_in_extension_enable (plug_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_extension_enable ();
|
||||
|
||||
brush_data = g_slice_new0 (GimpBrushData);
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_brush_select_ht)
|
||||
{
|
||||
gimp_brush_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_brush_data_free);
|
||||
}
|
||||
|
||||
brush_data->brush_callback = brush_callback;
|
||||
brush_data->callback = callback;
|
||||
brush_data->data = data;
|
||||
|
||||
g_hash_table_insert (gimp_brush_select_ht, brush_callback, brush_data);
|
||||
g_hash_table_insert (gimp_brush_select_ht, brush_callback,
|
||||
brush_data);
|
||||
}
|
||||
|
||||
return brush_callback;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (brush_callback);
|
||||
g_free (brush_callback);
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, brush_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_uninstall_temp_proc (brush_callback);
|
||||
gimp_brush_data_free (brush_data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -133,31 +230,32 @@ gimp_brush_select_new (const gchar *title,
|
|||
void
|
||||
gimp_brush_select_destroy (const gchar *brush_callback)
|
||||
{
|
||||
GimpBrushData *brush_data;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
|
||||
g_return_if_fail (brush_callback != NULL);
|
||||
g_return_if_fail (gimp_brush_select_ht != NULL);
|
||||
|
||||
brush_data = g_hash_table_lookup (gimp_brush_select_ht, brush_callback);
|
||||
|
||||
if (! brush_data)
|
||||
if (plug_in)
|
||||
{
|
||||
g_warning ("Can't find internal brush data");
|
||||
return;
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, brush_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpBrushData *brush_data;
|
||||
|
||||
if (brush_data->idle_id)
|
||||
g_source_remove (brush_data->idle_id);
|
||||
g_return_if_fail (gimp_brush_select_ht != NULL);
|
||||
|
||||
g_free (brush_data->brush_name);
|
||||
g_free (brush_data->brush_mask_data);
|
||||
brush_data = g_hash_table_lookup (gimp_brush_select_ht, brush_callback);
|
||||
|
||||
if (brush_data->brush_callback)
|
||||
gimp_brushes_close_popup (brush_data->brush_callback);
|
||||
if (! brush_data)
|
||||
{
|
||||
g_warning ("Can't find internal brush data");
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (brush_callback);
|
||||
g_hash_table_remove (gimp_brush_select_ht, brush_callback);
|
||||
|
||||
g_hash_table_remove (gimp_brush_select_ht, brush_callback);
|
||||
gimp_uninstall_temp_proc (brush_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,6 +264,18 @@ gimp_brush_select_destroy (const gchar *brush_callback)
|
|||
static void
|
||||
gimp_brush_data_free (GimpBrushData *data)
|
||||
{
|
||||
if (data->idle_id)
|
||||
g_source_remove (data->idle_id);
|
||||
|
||||
if (data->brush_callback)
|
||||
gimp_brushes_close_popup (data->brush_callback);
|
||||
|
||||
g_free (data->brush_name);
|
||||
g_free (data->brush_mask_data);
|
||||
|
||||
if (data->data_destroy)
|
||||
data->data_destroy (data->data);
|
||||
|
||||
g_slice_free (GimpBrushData, data);
|
||||
}
|
||||
|
||||
|
@ -212,6 +322,32 @@ gimp_temp_brush_run (const gchar *name,
|
|||
values[0].data.d_status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
gimp_temp_brush_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpBrushData *data = run_data;
|
||||
|
||||
g_free (data->brush_name);
|
||||
g_free (data->brush_mask_data);
|
||||
|
||||
data->brush_name = g_value_dup_string (gimp_value_array_index (args, 0));
|
||||
data->opacity = g_value_get_double (gimp_value_array_index (args, 1));
|
||||
data->spacing = g_value_get_int (gimp_value_array_index (args, 2));
|
||||
data->paint_mode = g_value_get_enum (gimp_value_array_index (args, 3));
|
||||
data->width = g_value_get_int (gimp_value_array_index (args, 4));
|
||||
data->height = g_value_get_int (gimp_value_array_index (args, 5));
|
||||
data->brush_mask_data = gimp_value_dup_int8_array (gimp_value_array_index (args, 7));
|
||||
data->closing = g_value_get_boolean (gimp_value_array_index (args, 8));
|
||||
|
||||
if (! data->idle_id)
|
||||
data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_brush_run_idle,
|
||||
data);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_temp_brush_run_idle (GimpBrushData *brush_data)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,8 @@ const gchar * gimp_brush_select_new (const gchar *title,
|
|||
gint spacing,
|
||||
GimpLayerMode paint_mode,
|
||||
GimpRunBrushCallback callback,
|
||||
gpointer data);
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy);
|
||||
void gimp_brush_select_destroy (const gchar *brush_callback);
|
||||
|
||||
|
||||
|
|
|
@ -618,7 +618,7 @@ gimp_brush_select_button_clicked (GimpBrushSelectButton *button)
|
|||
gimp_brush_select_new (priv->title, priv->brush_name,
|
||||
priv->opacity, priv->spacing, priv->paint_mode,
|
||||
gimp_brush_select_button_callback,
|
||||
button);
|
||||
button, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,19 +31,24 @@ typedef struct
|
|||
GimpRunFontCallback callback;
|
||||
gboolean closing;
|
||||
gpointer data;
|
||||
GDestroyNotify data_destroy;
|
||||
} GimpFontData;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_font_data_free (GimpFontData *data);
|
||||
static void gimp_font_data_free (GimpFontData *data);
|
||||
|
||||
static void gimp_temp_font_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gboolean gimp_temp_font_run_idle (GimpFontData *font_data);
|
||||
static void gimp_temp_font_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static GimpValueArray *
|
||||
gimp_temp_font_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static gboolean gimp_temp_font_run_idle (GimpFontData *font_data);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -57,58 +62,105 @@ const gchar *
|
|||
gimp_font_select_new (const gchar *title,
|
||||
const gchar *font_name,
|
||||
GimpRunFontCallback callback,
|
||||
gpointer data)
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
gchar *font_callback = gimp_procedural_db_temp_name ();
|
||||
GimpFontData *font_data;
|
||||
|
||||
gchar *font_callback = gimp_procedural_db_temp_name ();
|
||||
font_data = g_slice_new0 (GimpFontData);
|
||||
|
||||
gimp_install_temp_proc (font_callback,
|
||||
"Temporary font popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_font_run);
|
||||
font_data->font_callback = font_callback;
|
||||
font_data->callback = callback;
|
||||
font_data->data = data;
|
||||
font_data->data_destroy = data_destroy;
|
||||
|
||||
if (plug_in)
|
||||
{
|
||||
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||
font_callback,
|
||||
GIMP_TEMPORARY,
|
||||
gimp_temp_font_run_func,
|
||||
font_data,
|
||||
(GDestroyNotify)
|
||||
gimp_font_data_free);
|
||||
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_string ("font-name",
|
||||
"Font name",
|
||||
"The font name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("closing",
|
||||
"Closing",
|
||||
"If the dialog was "
|
||||
"closing",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
|
||||
gimp_install_temp_proc (font_callback,
|
||||
"Temporary font popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_font_run);
|
||||
}
|
||||
|
||||
if (gimp_fonts_popup (font_callback, title, font_name))
|
||||
{
|
||||
GimpFontData *font_data;
|
||||
|
||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
||||
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_font_select_ht)
|
||||
/* Allow callbacks to be watched */
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_font_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_font_data_free);
|
||||
gimp_plug_in_extension_enable (plug_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_extension_enable ();
|
||||
|
||||
font_data = g_slice_new0 (GimpFontData);
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_font_select_ht)
|
||||
{
|
||||
gimp_font_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_font_data_free);
|
||||
}
|
||||
|
||||
font_data->font_callback = font_callback;
|
||||
font_data->callback = callback;
|
||||
font_data->data = data;
|
||||
|
||||
g_hash_table_insert (gimp_font_select_ht, font_callback, font_data);
|
||||
g_hash_table_insert (gimp_font_select_ht, font_callback, font_data);
|
||||
}
|
||||
|
||||
return font_callback;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (font_callback);
|
||||
g_free (font_callback);
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, font_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_uninstall_temp_proc (font_callback);
|
||||
gimp_font_data_free (font_data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -116,30 +168,32 @@ gimp_font_select_new (const gchar *title,
|
|||
void
|
||||
gimp_font_select_destroy (const gchar *font_callback)
|
||||
{
|
||||
GimpFontData *font_data;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
|
||||
g_return_if_fail (font_callback != NULL);
|
||||
g_return_if_fail (gimp_font_select_ht != NULL);
|
||||
|
||||
font_data = g_hash_table_lookup (gimp_font_select_ht, font_callback);
|
||||
|
||||
if (! font_data)
|
||||
if (plug_in)
|
||||
{
|
||||
g_warning ("Can't find internal font data");
|
||||
return;
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, font_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpFontData *font_data;
|
||||
|
||||
if (font_data->idle_id)
|
||||
g_source_remove (font_data->idle_id);
|
||||
g_return_if_fail (gimp_font_select_ht != NULL);
|
||||
|
||||
g_free (font_data->font_name);
|
||||
font_data = g_hash_table_lookup (gimp_font_select_ht, font_callback);
|
||||
|
||||
if (font_data->font_callback)
|
||||
gimp_fonts_close_popup (font_data->font_callback);
|
||||
if (! font_data)
|
||||
{
|
||||
g_warning ("Can't find internal font data");
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (font_callback);
|
||||
gimp_uninstall_temp_proc (font_callback);
|
||||
|
||||
g_hash_table_remove (gimp_font_select_ht, font_callback);
|
||||
g_hash_table_remove (gimp_font_select_ht, font_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,6 +202,17 @@ gimp_font_select_destroy (const gchar *font_callback)
|
|||
static void
|
||||
gimp_font_data_free (GimpFontData *data)
|
||||
{
|
||||
if (data->idle_id)
|
||||
g_source_remove (data->idle_id);
|
||||
|
||||
g_free (data->font_name);
|
||||
|
||||
if (data->font_callback)
|
||||
gimp_fonts_close_popup (data->font_callback);
|
||||
|
||||
if (data->data_destroy)
|
||||
data->data_destroy (data->data);
|
||||
|
||||
g_slice_free (GimpFontData, data);
|
||||
}
|
||||
|
||||
|
@ -186,6 +251,25 @@ gimp_temp_font_run (const gchar *name,
|
|||
values[0].data.d_status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
gimp_temp_font_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpFontData *data = run_data;
|
||||
|
||||
g_free (data->font_name);
|
||||
|
||||
data->font_name = g_value_dup_string (gimp_value_array_index (args, 0));
|
||||
data->closing = g_value_get_boolean (gimp_value_array_index (args, 1));
|
||||
|
||||
if (! data->idle_id)
|
||||
data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_font_run_idle,
|
||||
data);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_temp_font_run_idle (GimpFontData *font_data)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,8 @@ typedef void (* GimpRunFontCallback) (const gchar *font_name,
|
|||
const gchar * gimp_font_select_new (const gchar *title,
|
||||
const gchar *font_name,
|
||||
GimpRunFontCallback callback,
|
||||
gpointer data);
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy);
|
||||
void gimp_font_select_destroy (const gchar *font_callback);
|
||||
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ gimp_font_select_button_clicked (GimpFontSelectButton *button)
|
|||
select_button->temp_callback =
|
||||
gimp_font_select_new (priv->title, priv->font_name,
|
||||
gimp_font_select_button_callback,
|
||||
button);
|
||||
button, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,19 +33,24 @@ typedef struct
|
|||
GimpRunGradientCallback callback;
|
||||
gboolean closing;
|
||||
gpointer data;
|
||||
GDestroyNotify data_destroy;
|
||||
} GimpGradientData;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_gradient_data_free (GimpGradientData *data);
|
||||
static void gimp_gradient_data_free (GimpGradientData *data);
|
||||
|
||||
static void gimp_temp_gradient_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gboolean gimp_temp_gradient_run_idle (GimpGradientData *gradient_data);
|
||||
static void gimp_temp_gradient_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static GimpValueArray *
|
||||
gimp_temp_gradient_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static gboolean gimp_temp_gradient_run_idle (GimpGradientData *gradient_data);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -60,62 +65,122 @@ gimp_gradient_select_new (const gchar *title,
|
|||
const gchar *gradient_name,
|
||||
gint sample_size,
|
||||
GimpRunGradientCallback callback,
|
||||
gpointer data)
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "gradient width", "Gradient width" },
|
||||
{ GIMP_PDB_FLOATARRAY,"gradient data", "The gradient mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
gchar *gradient_callback = gimp_procedural_db_temp_name ();
|
||||
GimpGradientData *gradient_data;
|
||||
|
||||
gchar *gradient_callback = gimp_procedural_db_temp_name ();
|
||||
gradient_data = g_slice_new0 (GimpGradientData);
|
||||
|
||||
gimp_install_temp_proc (gradient_callback,
|
||||
"Temporary gradient popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_gradient_run);
|
||||
gradient_data->gradient_callback = gradient_callback;
|
||||
gradient_data->callback = callback;
|
||||
gradient_data->data = data;
|
||||
gradient_data->data_destroy = data_destroy;
|
||||
|
||||
if (plug_in)
|
||||
{
|
||||
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||
gradient_callback,
|
||||
GIMP_TEMPORARY,
|
||||
gimp_temp_gradient_run_func,
|
||||
gradient_data,
|
||||
(GDestroyNotify)
|
||||
gimp_gradient_data_free);
|
||||
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_string ("gradient-name",
|
||||
"Gradient name",
|
||||
"The gradient name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int32 ("gradient-width",
|
||||
"Gradient width",
|
||||
"The gradient width",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_float_array ("gradient-data",
|
||||
"Gradient data",
|
||||
"The gradient "
|
||||
"data",
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("closing",
|
||||
"Closing",
|
||||
"If the dialog was "
|
||||
"closing",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "gradient width", "Gradient width" },
|
||||
{ GIMP_PDB_FLOATARRAY,"gradient data", "The gradient mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
|
||||
gimp_install_temp_proc (gradient_callback,
|
||||
"Temporary gradient popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_gradient_run);
|
||||
}
|
||||
|
||||
if (gimp_gradients_popup (gradient_callback, title, gradient_name,
|
||||
sample_size))
|
||||
{
|
||||
GimpGradientData *gradient_data;
|
||||
|
||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
||||
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_gradient_select_ht)
|
||||
/* Allow callbacks to be watched */
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_gradient_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_gradient_data_free);
|
||||
gimp_plug_in_extension_enable (plug_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_extension_enable ();
|
||||
|
||||
gradient_data = g_slice_new0 (GimpGradientData);
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_gradient_select_ht)
|
||||
{
|
||||
gimp_gradient_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_gradient_data_free);
|
||||
}
|
||||
|
||||
gradient_data->gradient_callback = gradient_callback;
|
||||
gradient_data->callback = callback;
|
||||
gradient_data->data = data;
|
||||
|
||||
g_hash_table_insert (gimp_gradient_select_ht,
|
||||
gradient_callback, gradient_data);
|
||||
g_hash_table_insert (gimp_gradient_select_ht,
|
||||
gradient_callback, gradient_data);
|
||||
}
|
||||
|
||||
return gradient_callback;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (gradient_callback);
|
||||
g_free (gradient_callback);
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, gradient_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_uninstall_temp_proc (gradient_callback);
|
||||
gimp_gradient_data_free (gradient_data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -123,32 +188,33 @@ gimp_gradient_select_new (const gchar *title,
|
|||
void
|
||||
gimp_gradient_select_destroy (const gchar *gradient_callback)
|
||||
{
|
||||
GimpGradientData *gradient_data;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
|
||||
g_return_if_fail (gradient_callback != NULL);
|
||||
g_return_if_fail (gimp_gradient_select_ht != NULL);
|
||||
|
||||
gradient_data = g_hash_table_lookup (gimp_gradient_select_ht,
|
||||
gradient_callback);
|
||||
|
||||
if (! gradient_data)
|
||||
if (plug_in)
|
||||
{
|
||||
g_warning ("Can't find internal gradient data");
|
||||
return;
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, gradient_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpGradientData *gradient_data;
|
||||
|
||||
if (gradient_data->idle_id)
|
||||
g_source_remove (gradient_data->idle_id);
|
||||
g_return_if_fail (gimp_gradient_select_ht != NULL);
|
||||
|
||||
g_free (gradient_data->gradient_name);
|
||||
g_free (gradient_data->gradient_data);
|
||||
gradient_data = g_hash_table_lookup (gimp_gradient_select_ht,
|
||||
gradient_callback);
|
||||
|
||||
if (gradient_data->gradient_callback)
|
||||
gimp_gradients_close_popup (gradient_data->gradient_callback);
|
||||
if (! gradient_data)
|
||||
{
|
||||
g_warning ("Can't find internal gradient data");
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (gradient_callback);
|
||||
g_hash_table_remove (gimp_gradient_select_ht, gradient_callback);
|
||||
|
||||
g_hash_table_remove (gimp_gradient_select_ht, gradient_callback);
|
||||
gimp_uninstall_temp_proc (gradient_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,6 +223,18 @@ gimp_gradient_select_destroy (const gchar *gradient_callback)
|
|||
static void
|
||||
gimp_gradient_data_free (GimpGradientData *data)
|
||||
{
|
||||
if (data->idle_id)
|
||||
g_source_remove (data->idle_id);
|
||||
|
||||
if (data->gradient_callback)
|
||||
gimp_gradients_close_popup (data->gradient_callback);
|
||||
|
||||
g_free (data->gradient_name);
|
||||
g_free (data->gradient_data);
|
||||
|
||||
if (data->data_destroy)
|
||||
data->data_destroy (data->data);
|
||||
|
||||
g_slice_free (GimpGradientData, data);
|
||||
}
|
||||
|
||||
|
@ -201,6 +279,28 @@ gimp_temp_gradient_run (const gchar *name,
|
|||
values[0].data.d_status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
gimp_temp_gradient_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpGradientData *data = run_data;
|
||||
|
||||
g_free (data->gradient_name);
|
||||
g_free (data->gradient_data);
|
||||
|
||||
data->gradient_name = g_value_dup_string (gimp_value_array_index (args, 0));
|
||||
data->width = g_value_get_int (gimp_value_array_index (args, 1));
|
||||
data->gradient_data = gimp_value_dup_float_array (gimp_value_array_index (args, 2));
|
||||
data->closing = g_value_get_boolean (gimp_value_array_index (args, 3));
|
||||
|
||||
if (! data->idle_id)
|
||||
data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_gradient_run_idle,
|
||||
data);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_temp_gradient_run_idle (GimpGradientData *gradient_data)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,8 @@ const gchar * gimp_gradient_select_new (const gchar *title,
|
|||
const gchar *gradient_name,
|
||||
gint sample_size,
|
||||
GimpRunGradientCallback callback,
|
||||
gpointer data);
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy);
|
||||
void gimp_gradient_select_destroy (const gchar *gradient_callback);
|
||||
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ gimp_gradient_select_button_clicked (GimpGradientSelectButton *button)
|
|||
gimp_gradient_select_new (priv->title, priv->gradient_name,
|
||||
priv->sample_size,
|
||||
gimp_gradient_select_button_callback,
|
||||
button);
|
||||
button, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,19 +32,24 @@ typedef struct
|
|||
GimpRunPaletteCallback callback;
|
||||
gboolean closing;
|
||||
gpointer data;
|
||||
GDestroyNotify data_destroy;
|
||||
} GimpPaletteData;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_palette_data_free (GimpPaletteData *data);
|
||||
static void gimp_palette_data_free (GimpPaletteData *data);
|
||||
|
||||
static void gimp_temp_palette_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gboolean gimp_temp_palette_run_idle (GimpPaletteData *palette_data);
|
||||
static void gimp_temp_palette_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static GimpValueArray *
|
||||
gimp_temp_palette_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static gboolean gimp_temp_palette_run_idle (GimpPaletteData *palette_data);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -58,60 +63,113 @@ const gchar *
|
|||
gimp_palette_select_new (const gchar *title,
|
||||
const gchar *palette_name,
|
||||
GimpRunPaletteCallback callback,
|
||||
gpointer data)
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "num colors", "Number of colors" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
gchar *palette_callback = gimp_procedural_db_temp_name ();
|
||||
GimpPaletteData *palette_data;
|
||||
|
||||
gchar *palette_callback = gimp_procedural_db_temp_name ();
|
||||
palette_data = g_slice_new0 (GimpPaletteData);
|
||||
|
||||
gimp_install_temp_proc (palette_callback,
|
||||
"Temporary palette popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_palette_run);
|
||||
palette_data->palette_callback = palette_callback;
|
||||
palette_data->callback = callback;
|
||||
palette_data->data = data;
|
||||
palette_data->data_destroy = data_destroy;
|
||||
|
||||
if (plug_in)
|
||||
{
|
||||
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||
palette_callback,
|
||||
GIMP_TEMPORARY,
|
||||
gimp_temp_palette_run_func,
|
||||
palette_data,
|
||||
(GDestroyNotify)
|
||||
gimp_palette_data_free);
|
||||
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_string ("palette-name",
|
||||
"Palette name",
|
||||
"The palette name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("num-colors",
|
||||
"Num colors",
|
||||
"Number of colors",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("closing",
|
||||
"Closing",
|
||||
"If the dialog was "
|
||||
"closing",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "num colors", "Number of colors" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
|
||||
gimp_install_temp_proc (palette_callback,
|
||||
"Temporary palette popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_palette_run);
|
||||
}
|
||||
|
||||
if (gimp_palettes_popup (palette_callback, title, palette_name))
|
||||
{
|
||||
GimpPaletteData *palette_data;
|
||||
|
||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
||||
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_palette_select_ht)
|
||||
/* Allow callbacks to be watched */
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_palette_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_palette_data_free);
|
||||
gimp_plug_in_extension_enable (plug_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_extension_enable ();
|
||||
|
||||
palette_data = g_slice_new0 (GimpPaletteData);
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_palette_select_ht)
|
||||
{
|
||||
gimp_palette_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_palette_data_free);
|
||||
}
|
||||
|
||||
palette_data->palette_callback = palette_callback;
|
||||
palette_data->callback = callback;
|
||||
palette_data->data = data;
|
||||
|
||||
g_hash_table_insert (gimp_palette_select_ht,
|
||||
palette_callback, palette_data);
|
||||
g_hash_table_insert (gimp_palette_select_ht,
|
||||
palette_callback, palette_data);
|
||||
}
|
||||
|
||||
return palette_callback;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (palette_callback);
|
||||
g_free (palette_callback);
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, palette_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_uninstall_temp_proc (palette_callback);
|
||||
gimp_palette_data_free (palette_data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -119,30 +177,33 @@ gimp_palette_select_new (const gchar *title,
|
|||
void
|
||||
gimp_palette_select_destroy (const gchar *palette_callback)
|
||||
{
|
||||
GimpPaletteData *palette_data;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
|
||||
g_return_if_fail (palette_callback != NULL);
|
||||
g_return_if_fail (gimp_palette_select_ht != NULL);
|
||||
|
||||
palette_data = g_hash_table_lookup (gimp_palette_select_ht, palette_callback);
|
||||
|
||||
if (! palette_data)
|
||||
if (plug_in)
|
||||
{
|
||||
g_warning ("Can't find internal palette data");
|
||||
return;
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, palette_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpPaletteData *palette_data;
|
||||
|
||||
if (palette_data->idle_id)
|
||||
g_source_remove (palette_data->idle_id);
|
||||
g_return_if_fail (gimp_palette_select_ht != NULL);
|
||||
|
||||
g_free (palette_data->palette_name);
|
||||
palette_data = g_hash_table_lookup (gimp_palette_select_ht,
|
||||
palette_callback);
|
||||
|
||||
if (palette_data->palette_callback)
|
||||
gimp_palettes_close_popup (palette_data->palette_callback);
|
||||
if (! palette_data)
|
||||
{
|
||||
g_warning ("Can't find internal palette data");
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (palette_callback);
|
||||
gimp_uninstall_temp_proc (palette_callback);
|
||||
|
||||
g_hash_table_remove (gimp_palette_select_ht, palette_callback);
|
||||
g_hash_table_remove (gimp_palette_select_ht, palette_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,6 +212,17 @@ gimp_palette_select_destroy (const gchar *palette_callback)
|
|||
static void
|
||||
gimp_palette_data_free (GimpPaletteData *data)
|
||||
{
|
||||
if (data->idle_id)
|
||||
g_source_remove (data->idle_id);
|
||||
|
||||
if (data->palette_callback)
|
||||
gimp_palettes_close_popup (data->palette_callback);
|
||||
|
||||
g_free (data->palette_name);
|
||||
|
||||
if (data->data_destroy)
|
||||
data->data_destroy (data->data);
|
||||
|
||||
g_slice_free (GimpPaletteData, data);
|
||||
}
|
||||
|
||||
|
@ -190,6 +262,26 @@ gimp_temp_palette_run (const gchar *name,
|
|||
values[0].data.d_status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
gimp_temp_palette_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpPaletteData *data = run_data;
|
||||
|
||||
g_free (data->palette_name);
|
||||
|
||||
data->palette_name = g_value_dup_string (gimp_value_array_index (args, 0));
|
||||
data->num_colors = g_value_get_int (gimp_value_array_index (args, 1));
|
||||
data->closing = g_value_get_boolean (gimp_value_array_index (args, 2));
|
||||
|
||||
if (! data->idle_id)
|
||||
data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_palette_run_idle,
|
||||
data);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_temp_palette_run_idle (GimpPaletteData *palette_data)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,8 @@ typedef void (* GimpRunPaletteCallback) (const gchar *palette_name,
|
|||
const gchar * gimp_palette_select_new (const gchar *title,
|
||||
const gchar *palette_name,
|
||||
GimpRunPaletteCallback callback,
|
||||
gpointer data);
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy);
|
||||
void gimp_palette_select_destroy (const gchar *palette_callback);
|
||||
|
||||
|
||||
|
|
|
@ -398,7 +398,7 @@ gimp_palette_select_button_clicked (GimpPaletteSelectButton *button)
|
|||
select_button->temp_callback =
|
||||
gimp_palette_select_new (priv->title, priv->palette_name,
|
||||
gimp_palette_select_button_callback,
|
||||
button);
|
||||
button, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,19 +35,24 @@ typedef struct
|
|||
GimpRunPatternCallback callback;
|
||||
gboolean closing;
|
||||
gpointer data;
|
||||
GDestroyNotify data_destroy;
|
||||
} GimpPatternData;
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_pattern_data_free (GimpPatternData *data);
|
||||
static void gimp_pattern_data_free (GimpPatternData *data);
|
||||
|
||||
static void gimp_temp_pattern_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gboolean gimp_temp_pattern_run_idle (GimpPatternData *pattern_data);
|
||||
static void gimp_temp_pattern_run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static GimpValueArray *
|
||||
gimp_temp_pattern_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static gboolean gimp_temp_pattern_run_idle (GimpPatternData *pattern_data);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -61,64 +66,143 @@ const gchar *
|
|||
gimp_pattern_select_new (const gchar *title,
|
||||
const gchar *pattern_name,
|
||||
GimpRunPatternCallback callback,
|
||||
gpointer data)
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "mask width", "Pattern width" },
|
||||
{ GIMP_PDB_INT32, "mask height", "Pattern height" },
|
||||
{ GIMP_PDB_INT32, "mask bpp", "Pattern bytes per pixel" },
|
||||
{ GIMP_PDB_INT32, "mask len", "Length of pattern mask data" },
|
||||
{ GIMP_PDB_INT8ARRAY,"mask data", "The pattern mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
gchar *pattern_callback = gimp_procedural_db_temp_name ();
|
||||
GimpPatternData *pattern_data;
|
||||
|
||||
gchar *pattern_callback = gimp_procedural_db_temp_name ();
|
||||
pattern_data = g_slice_new0 (GimpPatternData);
|
||||
|
||||
gimp_install_temp_proc (pattern_callback,
|
||||
"Temporary pattern popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_pattern_run);
|
||||
pattern_data->pattern_callback = pattern_callback;
|
||||
pattern_data->callback = callback;
|
||||
pattern_data->data = data;
|
||||
pattern_data->data_destroy = data_destroy;
|
||||
|
||||
|
||||
if (plug_in)
|
||||
{
|
||||
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||
pattern_callback,
|
||||
GIMP_TEMPORARY,
|
||||
gimp_temp_pattern_run_func,
|
||||
pattern_data,
|
||||
(GDestroyNotify)
|
||||
gimp_pattern_data_free);
|
||||
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_string ("pattern-name",
|
||||
"Pattern name",
|
||||
"The pattern name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("mask-width",
|
||||
"Mask width",
|
||||
"Pattern width",
|
||||
0, 10000, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("mask-height",
|
||||
"Mask height",
|
||||
"Pattern height",
|
||||
0, 10000, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_int ("mask-bpp",
|
||||
"Mask bpp",
|
||||
"Pattern bytes per pixel",
|
||||
0, 10000, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int32 ("mask-len",
|
||||
"Mask length",
|
||||
"Length of pattern "
|
||||
"mask data",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int8_array ("mask-data",
|
||||
"Mask data",
|
||||
"The pattern mask "
|
||||
"data",
|
||||
G_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("closing",
|
||||
"Closing",
|
||||
"If the dialog was "
|
||||
"cloaing",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||
g_object_unref (procedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "str", "String" },
|
||||
{ GIMP_PDB_INT32, "mask width", "Pattern width" },
|
||||
{ GIMP_PDB_INT32, "mask height", "Pattern height" },
|
||||
{ GIMP_PDB_INT32, "mask bpp", "Pattern bytes per pixel" },
|
||||
{ GIMP_PDB_INT32, "mask len", "Length of pattern mask data" },
|
||||
{ GIMP_PDB_INT8ARRAY,"mask data", "The pattern mask data" },
|
||||
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
|
||||
"[0 = No, 1 = Yes]" }
|
||||
};
|
||||
|
||||
gimp_install_temp_proc (pattern_callback,
|
||||
"Temporary pattern popup callback procedure",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
"",
|
||||
GIMP_TEMPORARY,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL,
|
||||
gimp_temp_pattern_run);
|
||||
}
|
||||
|
||||
if (gimp_patterns_popup (pattern_callback, title, pattern_name))
|
||||
{
|
||||
GimpPatternData *pattern_data;
|
||||
|
||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
||||
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_pattern_select_ht)
|
||||
/* Allow callbacks to be watched */
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_pattern_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_pattern_data_free);
|
||||
gimp_plug_in_extension_enable (plug_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_extension_enable ();
|
||||
|
||||
pattern_data = g_slice_new0 (GimpPatternData);
|
||||
/* Now add to hash table so we can find it again */
|
||||
if (! gimp_pattern_select_ht)
|
||||
{
|
||||
gimp_pattern_select_ht =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) gimp_pattern_data_free);
|
||||
}
|
||||
|
||||
pattern_data->pattern_callback = pattern_callback;
|
||||
pattern_data->callback = callback;
|
||||
pattern_data->data = data;
|
||||
|
||||
g_hash_table_insert (gimp_pattern_select_ht,
|
||||
pattern_callback, pattern_data);
|
||||
g_hash_table_insert (gimp_pattern_select_ht,
|
||||
pattern_callback, pattern_data);
|
||||
}
|
||||
|
||||
return pattern_callback;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (pattern_callback);
|
||||
g_free (pattern_callback);
|
||||
if (plug_in)
|
||||
{
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, pattern_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_uninstall_temp_proc (pattern_callback);
|
||||
gimp_pattern_data_free (pattern_data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -126,32 +210,33 @@ gimp_pattern_select_new (const gchar *title,
|
|||
void
|
||||
gimp_pattern_select_destroy (const gchar *pattern_callback)
|
||||
{
|
||||
GimpPatternData *pattern_data;
|
||||
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||
|
||||
g_return_if_fail (pattern_callback != NULL);
|
||||
g_return_if_fail (gimp_pattern_select_ht != NULL);
|
||||
|
||||
pattern_data = g_hash_table_lookup (gimp_pattern_select_ht,
|
||||
pattern_callback);
|
||||
|
||||
if (! pattern_data)
|
||||
if (plug_in)
|
||||
{
|
||||
g_warning ("Can't find internal pattern data");
|
||||
return;
|
||||
gimp_plug_in_remove_temp_procedure (plug_in, pattern_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpPatternData *pattern_data;
|
||||
|
||||
if (pattern_data->idle_id)
|
||||
g_source_remove (pattern_data->idle_id);
|
||||
g_return_if_fail (gimp_pattern_select_ht != NULL);
|
||||
|
||||
g_free (pattern_data->pattern_name);
|
||||
g_free (pattern_data->pattern_mask_data);
|
||||
pattern_data = g_hash_table_lookup (gimp_pattern_select_ht,
|
||||
pattern_callback);
|
||||
|
||||
if (pattern_data->pattern_callback)
|
||||
gimp_patterns_close_popup (pattern_data->pattern_callback);
|
||||
if (! pattern_data)
|
||||
{
|
||||
g_warning ("Can't find internal pattern data");
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_uninstall_temp_proc (pattern_callback);
|
||||
g_hash_table_remove (gimp_pattern_select_ht, pattern_callback);
|
||||
|
||||
g_hash_table_remove (gimp_pattern_select_ht, pattern_callback);
|
||||
gimp_uninstall_temp_proc (pattern_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,6 +245,18 @@ gimp_pattern_select_destroy (const gchar *pattern_callback)
|
|||
static void
|
||||
gimp_pattern_data_free (GimpPatternData *data)
|
||||
{
|
||||
if (data->idle_id)
|
||||
g_source_remove (data->idle_id);
|
||||
|
||||
if (data->pattern_callback)
|
||||
gimp_patterns_close_popup (data->pattern_callback);
|
||||
|
||||
g_free (data->pattern_name);
|
||||
g_free (data->pattern_mask_data);
|
||||
|
||||
if (data->data_destroy)
|
||||
data->data_destroy (data->data);
|
||||
|
||||
g_slice_free (GimpPatternData, data);
|
||||
}
|
||||
|
||||
|
@ -204,6 +301,30 @@ gimp_temp_pattern_run (const gchar *name,
|
|||
values[0].data.d_status = GIMP_PDB_SUCCESS;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
gimp_temp_pattern_run_func (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpPatternData *data = run_data;
|
||||
|
||||
g_free (data->pattern_name);
|
||||
g_free (data->pattern_mask_data);
|
||||
|
||||
data->pattern_name = g_value_dup_string (gimp_value_array_index (args, 0));
|
||||
data->width = g_value_get_int (gimp_value_array_index (args, 1));
|
||||
data->height = g_value_get_int (gimp_value_array_index (args, 2));
|
||||
data->bytes = g_value_get_int (gimp_value_array_index (args, 3));
|
||||
data->pattern_mask_data = gimp_value_dup_int8_array (gimp_value_array_index (args, 5));
|
||||
data->closing = g_value_get_boolean (gimp_value_array_index (args, 6));
|
||||
|
||||
if (! data->idle_id)
|
||||
data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_pattern_run_idle,
|
||||
data);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_temp_pattern_run_idle (GimpPatternData *pattern_data)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,8 @@ typedef void (* GimpRunPatternCallback) (const gchar *pattern_name,
|
|||
const gchar * gimp_pattern_select_new (const gchar *title,
|
||||
const gchar *pattern_name,
|
||||
GimpRunPatternCallback callback,
|
||||
gpointer data);
|
||||
gpointer data,
|
||||
GDestroyNotify data_destroy);
|
||||
void gimp_pattern_select_destroy (const gchar *pattern_callback);
|
||||
|
||||
|
||||
|
|
|
@ -468,7 +468,7 @@ gimp_pattern_select_button_clicked (GimpPatternSelectButton *button)
|
|||
select_button->temp_callback =
|
||||
gimp_pattern_select_new (priv->title, priv->pattern_name,
|
||||
gimp_pattern_select_button_callback,
|
||||
button);
|
||||
button, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue