Commit a75c675d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added GimpToolRegisterFunc, GimpToolRegisterCallback and

2001-11-20  Michael Natterer  <mitch@gimp.org>

	* app/tools/tools-types.h: added GimpToolRegisterFunc,
	GimpToolRegisterCallback and GimpToolOptionsNewFunc typedefs
	which are used to register tools.

	* app/tools/tools.c: put the register funcs in an array of
	GimpToolRegisterFuncs. Pass a Gimp pointer *plus* a
	GimpToolRegisterCallback (which is tool_manager_register_tool())
	to the tools' register functions.

	* app/tools/tool_manager.[ch]: added a GimpToolOptionsNewFunc to
	the parameters of tool_manager_register_tool(). Create the tool
	options here, not in each tool.

	* app/tools/paint_options.[ch]
	* app/tools/selection_options.[ch]
	* app/tools/tool_options.[ch]
	* app/tools/transform_options.[ch]: all _init() and _new()
	functions take a GimpToolInfo pointer now. The _reset() func needs
	to be set manually now.

	* app/tools/[all_tools].[ch]: changed accordingly:

	- pass GimpToolOptionsNewFuncs to the register callback.
	- don't create the tool options in the tools' _init() function.
	- removed all static tool options variables.
	- get the options from the tool system in the cases i missed
	  in my last commit.
	- added minor hacks to get rid of the static options pointer
	  in some pathological cases :) (i.e. the ink tool).
parent 82f6bb6b
2001-11-20 Michael Natterer <mitch@gimp.org>
* app/tools/tools-types.h: added GimpToolRegisterFunc,
GimpToolRegisterCallback and GimpToolOptionsNewFunc typedefs
which are used to register tools.
* app/tools/tools.c: put the register funcs in an array of
GimpToolRegisterFuncs. Pass a Gimp pointer *plus* a
GimpToolRegisterCallback (which is tool_manager_register_tool())
to the tools' register functions.
* app/tools/tool_manager.[ch]: added a GimpToolOptionsNewFunc to
the parameters of tool_manager_register_tool(). Create the tool
options here, not in each tool.
* app/tools/paint_options.[ch]
* app/tools/selection_options.[ch]
* app/tools/tool_options.[ch]
* app/tools/transform_options.[ch]: all _init() and _new()
functions take a GimpToolInfo pointer now. The _reset() func needs
to be set manually now.
* app/tools/[all_tools].[ch]: changed accordingly:
- pass GimpToolOptionsNewFuncs to the register callback.
- don't create the tool options in the tools' _init() function.
- removed all static tool options variables.
- get the options from the tool system in the cases i missed
in my last commit.
- added minor hacks to get rid of the static options pointer
in some pathological cases :) (i.e. the ink tool).
2001-11-20 David Neary <dneary@eircom.net>
* app/core/gimppalette.c: Included errno,h
......@@ -11,8 +43,6 @@
* app/core/gimppalette.c
* app/core/gimppattern.c: More of the extensive proofing. Fun fun fun!
2001-11-20 Sven Neumann <sven@gimp.org>
* app/gui/preferences-dialog.c
......
......@@ -37,7 +37,6 @@
#include "gimpcolorbalancetool.h"
#include "gimpcolorbalancetool-transfer.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "image_map.h"
......@@ -88,10 +87,6 @@ static void color_balance_yb_adjustment_update (GtkAdjustment *adj,
gpointer data);
/* the color balance tool options */
static GimpToolOptions *color_balance_options = NULL;
/* the color balance dialog */
static ColorBalanceDialog *color_balance_dialog = NULL;
static GimpImageMapToolClass *parent_class = NULL;
......@@ -100,17 +95,19 @@ static GimpImageMapToolClass *parent_class = NULL;
/* functions */
void
gimp_color_balance_tool_register (Gimp *gimp)
gimp_color_balance_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_COLOR_BALANCE_TOOL,
FALSE,
"gimp:color_balance_tool",
_("Color Balance"),
_("Adjust color balance"),
N_("/Image/Colors/Color Balance..."), NULL,
NULL, "tools/color_balance.html",
GIMP_STOCK_TOOL_COLOR_BALANCE);
(* callback) (gimp,
GIMP_TYPE_COLOR_BALANCE_TOOL,
NULL,
FALSE,
"gimp:color_balance_tool",
_("Color Balance"),
_("Adjust color balance"),
N_("/Image/Colors/Color Balance..."), NULL,
NULL, "tools/color_balance.html",
GIMP_STOCK_TOOL_COLOR_BALANCE);
}
GType
......@@ -159,17 +156,6 @@ gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
static void
gimp_color_balance_tool_init (GimpColorBalanceTool *bc_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (bc_tool);
if (! color_balance_options)
{
color_balance_options = tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_COLOR_BALANCE_TOOL,
(GimpToolOptions *) color_balance_options);
}
}
static void
......
......@@ -73,9 +73,10 @@ struct _ColorBalanceDialog
};
void gimp_color_balance_tool_register (Gimp *gimp);
void gimp_color_balance_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback);
GType gimp_color_balance_tool_get_type (void);
GType gimp_color_balance_tool_get_type (void);
void color_balance (PixelRegion *srcPR,
......
......@@ -43,7 +43,6 @@
#include "gimpcurvestool.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "image_map.h"
......@@ -177,14 +176,8 @@ static gboolean curves_read_from_file (FILE *f);
static void curves_write_to_file (FILE *f);
/* the curves tool options */
static GimpToolOptions * curves_options = NULL;
/* the curves dialog */
static CurvesDialog * curves_dialog = NULL;
static GimpImageMapToolClass *parent_class = NULL;
/* the curves file dialog */
static GtkWidget *file_dlg = NULL;
static gboolean load_save;
......@@ -199,21 +192,25 @@ static CRMatrix CR_basis =
{ 0.0, 1.0, 0.0, 0.0 },
};
static GimpImageMapToolClass *parent_class = NULL;
/* functions */
/* public functions */
void
gimp_curves_tool_register (Gimp *gimp)
gimp_curves_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_CURVES_TOOL,
FALSE,
"gimp:curves_tool",
_("Curves"),
_("Adjust color curves"),
N_("/Image/Colors/Curves..."), NULL,
NULL, "tools/curves.html",
GIMP_STOCK_TOOL_CURVES);
(* callback) (gimp,
GIMP_TYPE_CURVES_TOOL,
NULL,
FALSE,
"gimp:curves_tool",
_("Curves"),
_("Adjust color curves"),
N_("/Image/Colors/Curves..."), NULL,
NULL, "tools/curves.html",
GIMP_STOCK_TOOL_CURVES);
}
GType
......@@ -263,17 +260,6 @@ gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
static void
gimp_curves_tool_init (GimpCurvesTool *bc_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (bc_tool);
if (! curves_options)
{
curves_options = tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_CURVES_TOOL,
(GimpToolOptions *) curves_options);
}
}
static void
......
......@@ -85,7 +85,8 @@ struct _CurvesDialog
};
void gimp_curves_tool_register (Gimp *gimp);
void gimp_curves_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback);
GType gimp_curves_tool_get_type (void);
......
......@@ -37,7 +37,6 @@
#include "gimphuesaturationtool.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "image_map.h"
......@@ -97,15 +96,6 @@ static gint hue_saturation_hue_partition_events (GtkWidget *,
HueSaturationDialog *hsd);
/* the hue-saturation tool options */
static GimpToolOptions *hue_saturation_options = NULL;
/* the hue-saturation tool dialog */
static HueSaturationDialog *hue_saturation_dialog = NULL;
static GimpImageMapToolClass *parent_class = NULL;
/* Local variables */
static gint hue_transfer[6][256];
static gint lightness_transfer[6][256];
......@@ -120,21 +110,27 @@ static gint default_colors[6][3] =
{ 255, 0, 255 }
};
static HueSaturationDialog *hue_saturation_dialog = NULL;
/* functions */
static GimpImageMapToolClass *parent_class = NULL;
/* public functions */
void
gimp_hue_saturation_tool_register (Gimp *gimp)
gimp_hue_saturation_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_HUE_SATURATION_TOOL,
FALSE,
"gimp:hue_saturation_tool",
_("Hue-Saturation"),
_("Adjust hue and saturation"),
N_("/Image/Colors/Hue-Saturation..."), NULL,
NULL, "tools/hue_saturation.html",
GIMP_STOCK_TOOL_HUE_SATURATION);
(* callback) (gimp,
GIMP_TYPE_HUE_SATURATION_TOOL,
NULL,
FALSE,
"gimp:hue_saturation_tool",
_("Hue-Saturation"),
_("Adjust hue and saturation"),
N_("/Image/Colors/Hue-Saturation..."), NULL,
NULL, "tools/hue_saturation.html",
GIMP_STOCK_TOOL_HUE_SATURATION);
}
GType
......@@ -181,17 +177,6 @@ gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *klass)
static void
gimp_hue_saturation_tool_init (GimpHueSaturationTool *bc_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (bc_tool);
if (! hue_saturation_options)
{
hue_saturation_options = tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_HUE_SATURATION_TOOL,
(GimpToolOptions *) hue_saturation_options);
}
}
static void
......
......@@ -81,7 +81,8 @@ struct _HueSaturationDialog
};
void gimp_hue_saturation_tool_register (Gimp *gimp);
void gimp_hue_saturation_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback);
GType gimp_hue_saturation_tool_get_type (void);
......
......@@ -40,7 +40,6 @@
#include "gimpthresholdtool.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "image_map.h"
......@@ -96,10 +95,6 @@ static void threshold_histogram_range (GimpHistogramView *,
gpointer );
/* the threshold tool options */
static GimpToolOptions *threshold_options = NULL;
/* the threshold tool dialog */
static ThresholdDialog *threshold_dialog = NULL;
static GimpImageMapToolClass *parent_class = NULL;
......@@ -108,17 +103,19 @@ static GimpImageMapToolClass *parent_class = NULL;
/* functions */
void
gimp_threshold_tool_register (Gimp *gimp)
gimp_threshold_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_THRESHOLD_TOOL,
FALSE,
"gimp:threshold_tool",
_("Threshold"),
_("Reduce image to two colors using a threshold"),
N_("/Image/Colors/Threshold..."), NULL,
NULL, "tools/threshold.html",
GIMP_STOCK_TOOL_THRESHOLD);
(* callback) (gimp,
GIMP_TYPE_THRESHOLD_TOOL,
NULL,
FALSE,
"gimp:threshold_tool",
_("Threshold"),
_("Reduce image to two colors using a threshold"),
N_("/Image/Colors/Threshold..."), NULL,
NULL, "tools/threshold.html",
GIMP_STOCK_TOOL_THRESHOLD);
}
GType
......@@ -165,17 +162,6 @@ gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
static void
gimp_threshold_tool_init (GimpThresholdTool *bc_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (bc_tool);
if (! threshold_options)
{
threshold_options = tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_THRESHOLD_TOOL,
(GimpToolOptions *) threshold_options);
}
}
static void
......
......@@ -68,7 +68,8 @@ struct _ThresholdDialog
};
void gimp_threshold_tool_register (Gimp *gimp);
void gimp_threshold_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback);
GType gimp_threshold_tool_get_type (void);
......
......@@ -108,11 +108,9 @@ static void gimp_color_picker_tool_cursor_update (GimpTool *tool,
static void gimp_color_picker_tool_draw (GimpDrawTool *draw_tool);
static GimpToolOptions * gimp_color_picker_tool_options_new (GimpToolInfo *tool_info);
static void gimp_color_picker_tool_options_reset (GimpToolOptions *tool_options);
static GimpColorPickerToolOptions * gimp_color_picker_tool_options_new (void);
static void gimp_color_picker_tool_options_reset (GimpToolOptions *tool_options);
static void gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
gpointer data);
static void gimp_color_picker_tool_info_update (GimpTool *tool,
......@@ -131,9 +129,6 @@ static gboolean pick_color_do (GimpImage *gimage,
gint final);
/* the color picker tool options */
static GimpColorPickerToolOptions * gimp_color_picker_tool_options = NULL;
/* the color value */
gint col_value[5] = { 0, 0, 0, 0, 0 };
......@@ -154,17 +149,19 @@ static GimpDrawToolClass *parent_class = NULL;
void
gimp_color_picker_tool_register (Gimp *gimp)
gimp_color_picker_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_COLOR_PICKER_TOOL,
FALSE,
"gimp:color_picker_tool",
_("Color Picker"),
_("Pick colors from the image"),
N_("/Tools/Color Picker"), "<shift>O",
NULL, "tools/color_picker.html",
GIMP_STOCK_TOOL_COLOR_PICKER);
(* callback) (gimp,
GIMP_TYPE_COLOR_PICKER_TOOL,
gimp_color_picker_tool_options_new,
FALSE,
"gimp:color_picker_tool",
_("Color Picker"),
_("Pick colors from the image"),
N_("/Tools/Color Picker"), "<shift>O",
NULL, "tools/color_picker.html",
GIMP_STOCK_TOOL_COLOR_PICKER);
}
GtkType
......@@ -226,14 +223,6 @@ gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool)
tool = GIMP_TOOL (color_picker_tool);
if (! gimp_color_picker_tool_options)
{
gimp_color_picker_tool_options = gimp_color_picker_tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_COLOR_PICKER_TOOL,
(GimpToolOptions *) gimp_color_picker_tool_options);
}
tool->tool_cursor = GIMP_COLOR_PICKER_TOOL_CURSOR;
tool->preserve = FALSE; /* Don't preserve on drawable change */
......@@ -788,8 +777,8 @@ gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
/* tool options stuff */
static GimpColorPickerToolOptions *
gimp_color_picker_tool_options_new (void)
static GimpToolOptions *
gimp_color_picker_tool_options_new (GimpToolInfo *tool_info)
{
GimpColorPickerToolOptions *options;
......@@ -800,8 +789,10 @@ gimp_color_picker_tool_options_new (void)
GtkWidget *scale;
options = g_new0 (GimpColorPickerToolOptions, 1);
tool_options_init ((GimpToolOptions *) options,
gimp_color_picker_tool_options_reset);
tool_options_init ((GimpToolOptions *) options, tool_info);
((GimpToolOptions *) options)->reset_func = gimp_color_picker_tool_options_reset;
options->sample_merged = options->sample_merged_d = FALSE;
options->sample_average = options->sample_average_d = FALSE;
......@@ -880,7 +871,7 @@ gimp_color_picker_tool_options_new (void)
&options->update_active);
gtk_widget_show (options->update_active_w);
return options;
return (GimpToolOptions *) options;
}
static void
......
......@@ -28,21 +28,21 @@
void
tool_options_init (GimpToolOptions *options,
ToolOptionsResetFunc reset_func)
tool_options_init (GimpToolOptions *options,
GimpToolInfo *tool_info)
{
options->main_vbox = gtk_vbox_new (FALSE, 2);
options->reset_func = reset_func;
options->main_vbox = gtk_vbox_new (FALSE, 2);
options->tool_info = tool_info;
}
GimpToolOptions *
tool_options_new (void)
tool_options_new (GimpToolInfo *tool_info)
{
GimpToolOptions *options;
GtkWidget *label;
options = g_new0 (GimpToolOptions, 1);
tool_options_init (options, NULL);
tool_options_init (options, tool_info);
label = gtk_label_new (_("This tool has no options."));
gtk_box_pack_start (GTK_BOX (options->main_vbox), label, FALSE, FALSE, 6);
......
......@@ -24,21 +24,22 @@
struct _GimpToolOptions
{
GtkWidget *main_vbox;
GtkWidget *main_vbox;
ToolOptionsResetFunc reset_func;
GimpToolInfo *tool_info;
GimpToolOptionsResetFunc reset_func;
};
/* create a dummy tool options structure
* (to be used by tools without options)
*/
GimpToolOptions * tool_options_new (void);
GimpToolOptions * tool_options_new (GimpToolInfo *tool_info);
/* initialize an already allocated ToolOptions structure
* (to be used by derived tool options only)
*/
void tool_options_init (GimpToolOptions *options,
ToolOptionsResetFunc reset_func);
void tool_options_init (GimpToolOptions *options,
GimpToolInfo *tool_info);
#endif /* __TOOL_OPTIONS_H__ */
......@@ -35,6 +35,7 @@
#include "core/gimpdrawable.h"
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
#include "core/gimptoolinfo.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
......@@ -101,7 +102,7 @@ static void gimp_airbrush_tool_motion (GimpPaintTool *paint_tool,
gboolean incremental);
static gint airbrush_time_out (gpointer data);
static AirbrushOptions * airbrush_options_new (void);
static GimpToolOptions * airbrush_options_new (GimpToolInfo *tool_info);
static void airbrush_options_reset (GimpToolOptions *tool_options);
......@@ -114,25 +115,25 @@ static gdouble non_gui_rate;
static gdouble non_gui_pressure;
static gboolean non_gui_incremental;
static AirbrushOptions *airbrush_options = NULL;
static GimpPaintToolClass *parent_class = NULL;
/* functions */
void
gimp_airbrush_tool_register (Gimp *gimp)
gimp_airbrush_tool_register (Gimp *gimp,
GimpToolRegisterCallback callback)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_AIRBRUSH_TOOL,
TRUE,
"gimp:airbrush_tool",
_("Airbrush"),
_("Airbrush with variable pressure"),
N_("/Tools/Paint Tools/Airbrush"), "A",
NULL, "tools/airbrush.html",
GIMP_STOCK_TOOL_AIRBRUSH);
(* callback) (gimp,
GIMP_TYPE_AIRBRUSH_TOOL,
airbrush_options_new,
TRUE,
"gimp:airbrush_tool",
_("Airbrush"),
_("Airbrush with variable pressure"),
N_("/Tools/Paint Tools/Airbrush"), "A",
NULL, "tools/airbrush.html",
GIMP_STOCK_TOOL_AIRBRUSH);
}
GType
......@@ -188,18 +189,10 @@ gimp_airbrush_tool_init (GimpAirbrushTool *airbrush)
tool = GIMP_TOOL (airbrush);
paint_tool = GIMP_PAINT_TOOL (airbrush);
if (! airbrush_options)
{
airbrush_options = airbrush_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_AIRBRUSH_TOOL,
(GimpToolOptions *) airbrush_options);
}
tool->tool_cursor = GIMP_AIRBRUSH_TOOL_CURSOR;
tool->tool_cursor = GIMP_AIRBRUSH_TOOL_CURSOR;
paint_tool->pick_colors = TRUE;
paint_tool->flags |= TOOL_CAN_HANDLE_CHANGING_BRUSH;
paint_tool->pick_colors = TRUE;
paint_tool->flags |= TOOL_CAN_HANDLE_CHANGING_BRUSH;
}
static void
......@@ -219,21 +212,24 @@ gimp_airbrush_tool_paint (GimpPaintTool *paint_tool,
GimpDrawable *drawable,