Commit b70ee4b7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

put all tool_manager variables into a struct which is attached to a

2001-07-07  Michael Natterer  <mitch@gimp.org>

	* app/tools/tool_manager.[ch]: put all tool_manager variables into
	a struct which is attached to a "Gimp". Pass a Gimp* to all
	tool_manager functions.

	* app/disp_callbacks.c
	* app/gdisplay.c
	* app/gimage.c
	* app/scale.c
	* app/scroll.c
	* app/undo.c
	* app/gui/convert-dialog.c
	* app/gui/edit-commands.c
	* app/gui/tool-options-dialog.c
	* app/gui/tools-commands.c: changed accordingly.

	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimptexttool.c
	* app/tools/gimpthresholdtool.c
	* app/tools/gimptool.c
	* app/tools/gimptransformtool.c: mostly bad hacks for tool dialogs
	which exist without a real context. Needs some more review.
parent 56939566
2001-07-07 Michael Natterer <mitch@gimp.org>
* app/tools/tool_manager.[ch]: put all tool_manager variables into
a struct which is attached to a "Gimp". Pass a Gimp* to all
tool_manager functions.
* app/disp_callbacks.c
* app/gdisplay.c
* app/gimage.c
* app/scale.c
* app/scroll.c
* app/undo.c
* app/gui/convert-dialog.c
* app/gui/edit-commands.c
* app/gui/tool-options-dialog.c
* app/gui/tools-commands.c: changed accordingly.
* app/tools/gimpbezierselecttool.c
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpclonetool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcroptool.c
* app/tools/gimpcurvestool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimphistogramtool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimptexttool.c
* app/tools/gimpthresholdtool.c
* app/tools/gimptool.c
* app/tools/gimptransformtool.c: mostly bad hacks for tool dialogs
which exist without a real context. Needs some more review.
2001-07-07 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
......
......@@ -92,7 +92,7 @@ edit_cut_cmd_callback (GtkWidget *widget,
return_if_no_display (gdisp);
/* stop any active tool */
tool_manager_control_active (HALT, gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
if (gimp_edit_cut (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage)))
......@@ -122,7 +122,7 @@ edit_paste_cmd_callback (GtkWidget *widget,
if (gdisp->gimage->gimp->global_buffer)
{
/* stop any active tool */
tool_manager_control_active (HALT, gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
if (gimp_edit_paste (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage),
......@@ -145,7 +145,7 @@ edit_paste_into_cmd_callback (GtkWidget *widget,
if (gdisp->gimage->gimp->global_buffer)
{
/* stop any active tool */
tool_manager_control_active (HALT, gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
if (gimp_edit_paste (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage),
......@@ -168,7 +168,7 @@ edit_paste_as_new_cmd_callback (GtkWidget *widget,
if (gdisp->gimage->gimp->global_buffer)
{
/* stop any active tool */
tool_manager_control_active (HALT, gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
gimp_edit_paste_as_new (gdisp->gimage->gimp,
gdisp->gimage,
......@@ -186,7 +186,7 @@ edit_named_cut_cmd_callback (GtkWidget *widget,
return_if_no_display (gdisp);
/* stop any active tool */
tool_manager_control_active (HALT, gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
qbox = gimp_query_string_box (_("Cut Named"),
gimp_standard_help_func,
......
......@@ -87,6 +87,7 @@ tools_select_cmd_callback (GtkWidget *widget,
{
GtkType tool_type;
GimpToolInfo *tool_info;
GimpTool *active_tool;
GDisplay *gdisp;
tool_type = (GtkType) action;
......@@ -100,6 +101,8 @@ tools_select_cmd_callback (GtkWidget *widget,
#warning FIXME (let the tool manager to this stuff)
#endif
active_tool = tool_manager_get_active (the_gimp);
/* Paranoia */
active_tool->drawable = NULL;
......
......@@ -38,6 +38,7 @@
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "drawable.h"
#include "gdisplay.h"
#include "image_map.h"
......@@ -621,6 +622,10 @@ color_balance_create_lookup_tables (ColorBalanceDialog *cbd)
static void
color_balance_preview (ColorBalanceDialog *cbd)
{
GimpTool *active_tool;
active_tool = tool_manager_get_active (the_gimp);
if (!cbd->image_map)
{
g_message ("color_balance_preview(): No image map");
......@@ -656,11 +661,14 @@ color_balance_ok_callback (GtkWidget *widget,
gpointer data)
{
ColorBalanceDialog *cbd;
GimpTool *active_tool;
cbd = (ColorBalanceDialog *) data;
gimp_dialog_hide (cbd->shell);
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
if (!cbd->preview)
......@@ -682,11 +690,14 @@ color_balance_cancel_callback (GtkWidget *widget,
gpointer data)
{
ColorBalanceDialog *cbd;
GimpTool *active_tool;
cbd = (ColorBalanceDialog *) data;
gimp_dialog_hide (cbd->shell);
active_tool = tool_manager_get_active (the_gimp);
if (cbd->image_map)
{
active_tool->preserve = TRUE;
......@@ -738,6 +749,7 @@ color_balance_preview_update (GtkWidget *widget,
gpointer data)
{
ColorBalanceDialog *cbd;
GimpTool *active_tool;
cbd = (ColorBalanceDialog *) data;
......@@ -751,6 +763,8 @@ color_balance_preview_update (GtkWidget *widget,
cbd->preview = FALSE;
if (cbd->image_map)
{
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_clear (cbd->image_map);
active_tool->preserve = FALSE;
......
......@@ -43,6 +43,7 @@
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "drawable.h"
#include "gdisplay.h"
#include "image_map.h"
......@@ -390,9 +391,9 @@ gimp_curves_tool_button_press (GimpTool *tool,
if (drawable != tool->drawable)
{
active_tool->preserve = TRUE;
tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
tool->preserve = FALSE;
tool->drawable = drawable;
......@@ -608,10 +609,14 @@ curves_dialog_hide (void)
void
curves_free (void)
{
GimpTool *active_tool;
if (curves_dialog)
{
if (curves_dialog->image_map)
{
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
......@@ -1227,12 +1232,16 @@ curves_calculate_curve (CurvesDialog *cd)
static void
curves_preview (CurvesDialog *cd)
{
GimpTool *active_tool;
if (!cd->image_map)
{
g_message ("curves_preview(): No image map");
return;
}
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_apply (cd->image_map, (ImageMapApplyFunc)gimp_lut_process_2,
(void *) cd->lut);
......@@ -1361,11 +1370,14 @@ curves_ok_callback (GtkWidget *widget,
gpointer data)
{
CurvesDialog *cd;
GimpTool *active_tool;
cd = (CurvesDialog *) data;
gimp_dialog_hide (cd->shell);
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE; /* We're about to dirty... */
if (!cd->preview)
......@@ -1388,11 +1400,14 @@ curves_cancel_callback (GtkWidget *widget,
gpointer data)
{
CurvesDialog *cd;
GimpTool *active_tool;
cd = (CurvesDialog *) data;
gimp_dialog_hide (cd->shell);
active_tool = tool_manager_get_active (the_gimp);
if (cd->image_map)
{
active_tool->preserve = TRUE;
......@@ -1442,6 +1457,7 @@ curves_preview_update (GtkWidget *widget,
gpointer data)
{
CurvesDialog *cd;
GimpTool *active_tool;
cd = (CurvesDialog *) data;
......@@ -1455,6 +1471,8 @@ curves_preview_update (GtkWidget *widget,
cd->preview = FALSE;
if (cd->image_map)
{
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_clear (cd->image_map);
active_tool->preserve = FALSE;
......
......@@ -38,6 +38,7 @@
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "drawable.h"
#include "gdisplay.h"
#include "image_map.h"
......@@ -399,6 +400,10 @@ hue_saturation_dialog_hide (void)
void
hue_saturation_free (void)
{
GimpTool *active_tool;
active_tool = tool_manager_get_active (the_gimp);
if (hue_saturation_dialog)
{
if (hue_saturation_dialog->image_map)
......@@ -725,6 +730,10 @@ hue_saturation_update (HueSaturationDialog *hsd,
static void
hue_saturation_preview (HueSaturationDialog *hsd)
{
GimpTool *active_tool;
active_tool = tool_manager_get_active (the_gimp);
if (!hsd->image_map)
{
g_warning ("hue_saturation_preview(): No image map");
......@@ -759,11 +768,14 @@ hue_saturation_ok_callback (GtkWidget *widget,
gpointer data)
{
HueSaturationDialog *hsd;
GimpTool *active_tool;
hsd = (HueSaturationDialog *) data;
gimp_dialog_hide (hsd->shell);
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
if (!hsd->preview)
......@@ -785,11 +797,14 @@ hue_saturation_cancel_callback (GtkWidget *widget,
gpointer data)
{
HueSaturationDialog *hsd;
GimpTool *active_tool;
hsd = (HueSaturationDialog *) data;
gimp_dialog_hide (hsd->shell);
active_tool = tool_manager_get_active (the_gimp);
if (hsd->image_map)
{
active_tool->preserve = TRUE;
......@@ -825,6 +840,7 @@ hue_saturation_preview_update (GtkWidget *widget,
gpointer data)
{
HueSaturationDialog *hsd;
GimpTool *active_tool;
hsd = (HueSaturationDialog *) data;
......@@ -838,6 +854,8 @@ hue_saturation_preview_update (GtkWidget *widget,
hsd->preview = FALSE;
if (hsd->image_map)
{
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_clear (hsd->image_map);
active_tool->preserve = FALSE;
......
......@@ -40,6 +40,7 @@
#include "tool_manager.h"
#include "tool_options.h"
#include "app_procs.h"
#include "drawable.h"
#include "gdisplay.h"
#include "image_map.h"
......@@ -482,12 +483,16 @@ threshold_update (ThresholdDialog *td,
static void
threshold_preview (ThresholdDialog *td)
{
GimpTool *active_tool;
if (!td->image_map)
{
g_warning ("threshold_preview(): No image map");
return;
}
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_apply (td->image_map, threshold, td);
active_tool->preserve = FALSE;
......@@ -515,11 +520,14 @@ threshold_ok_callback (GtkWidget *widget,
gpointer data)
{
ThresholdDialog *td;
GimpTool *active_tool;
td = (ThresholdDialog *) data;
gimp_dialog_hide (td->shell);
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
if (!td->preview)
......@@ -541,11 +549,14 @@ threshold_cancel_callback (GtkWidget *widget,
gpointer data)
{
ThresholdDialog *td;
GimpTool *active_tool;
td = (ThresholdDialog *) data;
gimp_dialog_hide (td->shell);
active_tool = tool_manager_get_active (the_gimp);
if (td->image_map)
{
active_tool->preserve = TRUE;
......@@ -565,6 +576,7 @@ threshold_preview_update (GtkWidget *widget,
gpointer data)
{
ThresholdDialog *td;
GimpTool *active_tool;
td = (ThresholdDialog *) data;
......@@ -578,6 +590,8 @@ threshold_preview_update (GtkWidget *widget,
td->preview = FALSE;
if (td->image_map)
{
active_tool = tool_manager_get_active (the_gimp);
active_tool->preserve = TRUE;
image_map_clear (td->image_map);
active_tool->preserve = FALSE;
......
......@@ -999,7 +999,9 @@ gimp_transform_tool_grid_density_changed (void)
GimpTransformTool *tr_tool;
GimpDrawTool *dr_tool;
tr_tool = GIMP_TRANSFORM_TOOL ( /* EEEEEEEK!!! */ active_tool);
/* EEEK!!! */
tr_tool = GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp));
dr_tool = GIMP_DRAW_TOOL (tr_tool);
if (tr_tool->function == TRANSFORM_CREATING)
......@@ -1018,7 +1020,8 @@ gimp_transform_tool_showpath_changed (gint type /* a truly undescriptive name */
{
GimpTransformTool *tr_tool;
tr_tool = GIMP_TRANSFORM_TOOL ( /* EEEEEEEK!!! */ active_tool);
/* EEEEEEEK!!! */
tr_tool = GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp));
if (tr_tool->function == TRANSFORM_CREATING)
return;
......@@ -1045,7 +1048,10 @@ gimp_transform_tool_grid_recalc (GimpTransformTool *tr_tool)
}
if (gimp_transform_tool_show_grid ())
gimp_transform_tool_setup_grid (GIMP_TRANSFORM_TOOL ( /* EEEEEEK!!! */ active_tool));
{
/* EEEEEEK!!! */
gimp_transform_tool_setup_grid (GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp)));
}
}
static void
......@@ -1208,7 +1214,8 @@ gimp_transform_tool_do (GimpImage *gimage,
y2 = y1 + tile_manager_height (float_tiles);
/* Find the bounding coordinates */
if (alpha == 0 || (active_tool && gimp_transform_tool_clip ()))
if (alpha == 0 || (tool_manager_get_active (gimage->gimp) &&
gimp_transform_tool_clip ()))
{
tx1 = x1;
ty1 = y1;
......@@ -1217,7 +1224,10 @@ gimp_transform_tool_do (GimpImage *gimage,
}
else
{
gdouble dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4;
gdouble dx1, dy1;
gdouble dx2, dy2;
gdouble dx3, dy3;
gdouble dx4, dy4;
gimp_matrix3_transform_point (matrix, x1, y1, &dx1, &dy1);
gimp_matrix3_transform_point (matrix, x2, y1, &dx2, &dy2);
......@@ -1230,6 +1240,7 @@ gimp_transform_tool_do (GimpImage *gimage,
ty1 = MIN (dy1, dy2);
ty1 = MIN (ty1, dy3);
ty1 = MIN (ty1, dy4);
tx2 = MAX (dx1, dx2);
tx2 = MAX (tx2, dx3);
tx2 = MAX (tx2, dx4);
......
......@@ -999,7 +999,9 @@ gimp_transform_tool_grid_density_changed (void)
GimpTransformTool *tr_tool;
GimpDrawTool *dr_tool;
tr_tool = GIMP_TRANSFORM_TOOL ( /* EEEEEEEK!!! */ active_tool);
/* EEEK!!! */
tr_tool = GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp));
dr_tool = GIMP_DRAW_TOOL (tr_tool);
if (tr_tool->function == TRANSFORM_CREATING)
......@@ -1018,7 +1020,8 @@ gimp_transform_tool_showpath_changed (gint type /* a truly undescriptive name */
{
GimpTransformTool *tr_tool;
tr_tool = GIMP_TRANSFORM_TOOL ( /* EEEEEEEK!!! */ active_tool);
/* EEEEEEEK!!! */
tr_tool = GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp));
if (tr_tool->function == TRANSFORM_CREATING)
return;
......@@ -1045,7 +1048,10 @@ gimp_transform_tool_grid_recalc (GimpTransformTool *tr_tool)
}
if (gimp_transform_tool_show_grid ())
gimp_transform_tool_setup_grid (GIMP_TRANSFORM_TOOL ( /* EEEEEEK!!! */ active_tool));
{
/* EEEEEEK!!! */
gimp_transform_tool_setup_grid (GIMP_TRANSFORM_TOOL (tool_manager_get_active (the_gimp)));
}
}
static void
......@@ -1208,7 +1214,8 @@ gimp_transform_tool_do (GimpImage *gimage,
y2 = y1 + tile_manager_height (float_tiles);
/* Find the bounding coordinates */
if (alpha == 0 || (active_tool && gimp_transform_tool_clip ()))
if (alpha == 0 || (tool_manager_get_active (gimage->gimp) &&
gimp_transform_tool_clip ()))
{
tx1 = x1;
ty1 = y1;
......@@ -1217,7 +1224,10 @@ gimp_transform_tool_do (GimpImage *gimage,
}
else
{
gdouble dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4;
gdouble dx1, dy1;
gdouble dx2, dy2;
gdouble dx3, dy3;
gdouble dx4, dy4;
gimp_matrix3_transform_point (matrix, x1, y1, &dx1, &dy1);
gimp_matrix3_transform_point (matrix, x2, y1, &dx2, &dy2);
......@@ -1230,6 +1240,7 @@ gimp_transform_tool_do (GimpImage *gimage,
ty1 = MIN (dy1, dy2);
ty1 = MIN (ty1, dy3);
ty1 = MIN (ty1, dy4);
tx2 = MAX (dx1, dx2);
tx2 = MAX (tx2, dx3);
tx2 = MAX (tx2, dx4);
......
......@@ -1272,12 +1272,15 @@ undo_pop_transform (GimpImage *gimage,
UndoType type,
gpointer tu_ptr)
{
GimpTool *active_tool;
GimpTransformTool *tt;
TransformUndo *tu;
TileManager *temp;
gdouble d;
gint i;
active_tool = tool_manager_get_active (gimage->gimp);
/* Can't have ANY tool selected - maybe a plugin running */
if (active_tool == NULL)
return TRUE;
......@@ -1363,10 +1366,13 @@ undo_pop_paint (GimpImage *gimage,
UndoType type,
gpointer pu_ptr)
{
GimpTool *active_tool;
GimpPaintTool *pt;
PaintUndo *pu;
gdouble tmp;
active_tool = tool_manager_get_active (gimage->gimp);
/* Can't have ANY tool selected - maybe a plugin running */
if (active_tool == NULL)
return TRUE;
......
......@@ -411,15 +411,18 @@ gdisplay_format_title (GDisplay *gdisp,
static void
gdisplay_delete (GDisplay *gdisp)
{
GimpTool *active_tool;
g_hash_table_remove (display_ht, gdisp->shell);
g_hash_table_remove (display_ht, gdisp->canvas);
/* stop any active tool */
tool_manager_control_active (HALT, (void *) gdisp);
tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
active_tool = tool_manager_get_active (gdisp->gimage->gimp);
/* clear out the pointer to this gdisp from the active tool */
if (active_tool &&
active_tool->gdisp == gdisp)
if (active_tool && active_tool->gdisp == gdisp)
{
active_tool->drawable = NULL;
active_tool->gdisp = NULL;
......@@ -708,7 +711,7 @@ gdisplay_flush_displays_only (GDisplay *gdisp)
if (list)
{
/* stop the currently active tool */
tool_manager_control_active (PAUSE, (void *) gdisp);
tool_manager_control_active (gdisp->gimage->gimp, PAUSE, gdisp);
while (list)
{
......@@ -733,7 +736,7 @@ gdisplay_flush_displays_only (GDisplay *gdisp)
selection_start (gdisp->select, TRUE);
/* start the currently active tool */
tool_manager_control_active (RESUME, (void *) gdisp);
tool_manager_control_active (gdisp->gimage->gimp, RESUME, gdisp);
}
}
......
......@@ -502,6 +502,7 @@ indexed_ok_callback (GtkWidget *widget,
IndexedDialog *dialog;
ConvertPaletteType palette_type;
ConvertDitherType dither_type;
GimpTool *active_tool;
dialog = (IndexedDialog *) data;
......@@ -528,8 +529,10 @@ indexed_ok_callback (GtkWidget *widget,
/* Close the dialogs when open because they're useless for indexed
* images and could crash the GIMP when used nevertheless
*/
active_tool = tool_manager_get_active (dialog->gimage->gimp);
if (active_tool)
tool_manager_control_active (HALT, active_tool->gdisp);
tool_manager_control_active (dialog->gimage->gimp, HALT, active_tool->gdisp);
/* Convert the image to indexed color */
gimp_image_convert (dialog->gimage, INDEXED, dialog->num_cols,
......
......@@ -176,6 +176,7 @@ gdisplay_canvas_events (GtkWidget *canvas,
GdkEvent *event)
{
GDisplay *gdisp;
GimpTool *active_tool;
GdkEventExpose *eevent;
GdkEventMotion *mevent;
GdkEventButton *bevent;
......@@ -193,6 +194,8 @@ gdisplay_canvas_events (GtkWidget *canvas,
if (!canvas->window)
return FALSE;