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

Separated tool_options creation from tool registration so we don't

2002-06-17  Michael Natterer  <mitch@gimp.org>

	Separated tool_options creation from tool registration so we
	don't implicitly create widgets before gui_init():

	* libgimptool/gimptooltypes.h: removed GimpToolOptionsNewFunc
	typedef here...

	* app/core/core-types.h: ...and added it here.

	* libgimpproxy/gimpproxytypes.h: regenerated.

	* app/core/gimptoolinfo.[ch]: added a GimpToolOptionsNewFunc
	pointer to remember the constructor. Fixed the finalize() method
	(bug was never noticed because we leaked all tool infos)

	* app/tools/tool_manager.[ch]: moved tool_options creation to the
	new function tool_manager_restore(). Unref the tool infos after
	adding them to their container. Added "brush" and "gradient" to
	the context properties which are defined for tool contexts.

	* app/app_procs.c: call tool_manager_restore() after gui_init().

	* app/gui/gui.c: removed the hack introduced recently and call
	render_setup() in gui_init() again, not in gui_themes_init().

	Use the correct contexts now that they are properly initialized
	at the time of tool_options creation:

	* app/tools/gimpblendtool.c: use tool_info->context, not
	gimp_get_user_context() to get/set the tool's gradient.

	* app/paint/gimppaintcore.[ch] (gimp_paint_core_start): added a
	GimpPaintOptions paramater and get the brush to use from
	paint_options->context (instead of gimp_get_current_context()).

	* app/paint/gimppaintcore-stroke.c
	* app/tools/gimppainttool.c: changed accordingly.

	* app/tools/paint_options.c: added a brush preview to the paint
	options.
parent 340b6acb
2002-06-17 Michael Natterer <mitch@gimp.org>
Separated tool_options creation from tool registration so we
don't implicitly create widgets before gui_init():
* libgimptool/gimptooltypes.h: removed GimpToolOptionsNewFunc
typedef here...
* app/core/core-types.h: ...and added it here.
* libgimpproxy/gimpproxytypes.h: regenerated.
* app/core/gimptoolinfo.[ch]: added a GimpToolOptionsNewFunc
pointer to remember the constructor. Fixed the finalize() method
(bug was never noticed because we leaked all tool infos)
* app/tools/tool_manager.[ch]: moved tool_options creation to the
new function tool_manager_restore(). Unref the tool infos after
adding them to their container. Added "brush" and "gradient" to
the context properties which are defined for tool contexts.
* app/app_procs.c: call tool_manager_restore() after gui_init().
* app/gui/gui.c: removed the hack introduced recently and call
render_setup() in gui_init() again, not in gui_themes_init().
Use the correct contexts now that they are properly initialized
at the time of tool_options creation:
* app/tools/gimpblendtool.c: use tool_info->context, not
gimp_get_user_context() to get/set the tool's gradient.
* app/paint/gimppaintcore.[ch] (gimp_paint_core_start): added a
GimpPaintOptions paramater and get the brush to use from
paint_options->context (instead of gimp_get_current_context()).
* app/paint/gimppaintcore-stroke.c
* app/tools/gimppainttool.c: changed accordingly.
* app/tools/paint_options.c: added a brush preview to the paint
options.
2002-06-16 Michael Natterer <mitch@gimp.org>
Fix for #85201:
......
......@@ -157,6 +157,7 @@ app_init (gint gimp_argc,
if (! no_interface)
{
gui_init (the_gimp);
tool_manager_restore (the_gimp);
}
/* Initialize the plug-in structures
......
......@@ -188,6 +188,8 @@ typedef struct _PathList PathList;
typedef struct _GimpToolOptions GimpToolOptions; /*< proxy-include >*/
typedef GimpToolOptions * (* GimpToolOptionsNewFunc) (GimpToolInfo *tool_info); /*< proxy-include >*/
/* functions */
......
......@@ -154,7 +154,7 @@ gimp_tool_info_finalize (GObject *object)
if (tool_info->stock_id)
{
g_object_unref (G_OBJECT (tool_info->stock_id));
g_free (tool_info->stock_id);
tool_info->stock_id = NULL;
}
if (tool_info->stock_pixbuf)
......@@ -273,11 +273,7 @@ gimp_tool_info_new (Gimp *gimp,
tool_info->paint_info = paint_info;
if (tool_context)
{
tool_info->context = gimp_context_new (gimp,
identifier,
context);
}
tool_info->context = gimp_context_new (gimp, identifier, context);
tool_info->gimp = gimp;
tool_info->tool_type = tool_type;
......@@ -308,16 +304,12 @@ gimp_tool_info_set_standard (Gimp *gimp,
g_return_if_fail (! tool_info || GIMP_IS_TOOL_INFO (tool_info));
if (gimp->standard_tool_info)
{
g_object_unref (G_OBJECT (gimp->standard_tool_info));
}
g_object_unref (G_OBJECT (gimp->standard_tool_info));
gimp->standard_tool_info = tool_info;
if (gimp->standard_tool_info)
{
g_object_ref (G_OBJECT (gimp->standard_tool_info));
}
g_object_ref (G_OBJECT (gimp->standard_tool_info));
}
GimpToolInfo *
......
......@@ -52,9 +52,12 @@ struct _GimpToolInfo
gchar *help_domain;
gchar *help_data;
const gchar *stock_id;
gchar *stock_id;
GdkPixbuf *stock_pixbuf;
/* temp_hack, will be a GType once tool_options are GimpContext derived */
GimpToolOptionsNewFunc options_new_func;
GimpContext *context;
GimpToolOptions *tool_options;
GimpPaintInfo *paint_info;
......
......@@ -184,8 +184,6 @@ gui_themes_init (Gimp *gimp)
gdk_rgb_set_install (gimprc.install_cmap);
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
render_setup (gimprc.transparency_type, gimprc.transparency_size);
}
const gchar *
......@@ -230,11 +228,7 @@ gui_init (Gimp *gimp)
color_display_init ();
/* temporatily moved to gui_themes_init() until the previews have their
* own render buffers
*
* render_setup (gimprc.transparency_type, gimprc.transparency_size);
*/
render_setup (gimprc.transparency_type, gimprc.transparency_size);
dialogs_init (gimp);
......
......@@ -44,7 +44,7 @@ gimp_paint_core_stroke (GimpPaintCore *core,
g_return_val_if_fail (strokes != NULL, FALSE);
g_return_val_if_fail (n_strokes > 0, FALSE);
if (gimp_paint_core_start (core, drawable, &strokes[0]))
if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0]))
{
gint i;
......@@ -108,7 +108,7 @@ gimp_paint_core_stroke_vectors (GimpPaintCore *core,
if (! coords)
return FALSE;
if (! gimp_paint_core_start (core, drawable, &coords[0]))
if (! gimp_paint_core_start (core, drawable, paint_options, &coords[0]))
{
g_free (coords);
return FALSE;
......
......@@ -37,8 +37,7 @@
#include "paint-funcs/paint-funcs.h"
#include "core/gimp.h"
#include "core/gimpbrushpipe.h"
#include "core/gimpbrush.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpgradient.h"
......@@ -48,6 +47,7 @@
#include "gimppaintcore.h"
#include "gimppaintcore-kernels.h"
#include "gimppaintoptions.h"
#include "app_procs.h"
#include "gimprc.h"
......@@ -340,23 +340,22 @@ gimp_paint_core_paint (GimpPaintCore *core,
}
gboolean
gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpCoords *coords)
gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
{
GimpContext *context;
GimpImage *gimage;
GimpImage *gimage;
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (paint_options != NULL, FALSE);
g_return_val_if_fail (coords != NULL, FALSE);
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
context = gimp_get_current_context (gimage->gimp);
core->cur_coords = *coords;
/* Each buffer is the same size as
......@@ -364,7 +363,7 @@ gimp_paint_core_start (GimpPaintCore *core,
*/
if (core->grr_brush &&
core->grr_brush != gimp_context_get_brush (context))
core->grr_brush != gimp_context_get_brush (paint_options->context))
{
g_signal_handlers_disconnect_by_func (G_OBJECT (core->grr_brush),
gimp_paint_core_invalidate_cache,
......@@ -372,7 +371,7 @@ gimp_paint_core_start (GimpPaintCore *core,
g_object_unref (G_OBJECT (core->grr_brush));
}
core->grr_brush = gimp_context_get_brush (context);
core->grr_brush = gimp_context_get_brush (paint_options->context);
if (! core->grr_brush)
{
......
......@@ -146,6 +146,7 @@ void gimp_paint_core_paint (GimpPaintCore *core,
gboolean gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
void gimp_paint_core_finish (GimpPaintCore *core,
GimpDrawable *drawable);
......
......@@ -443,13 +443,9 @@ static GimpToolOptions *
blend_options_new (GimpToolInfo *tool_info)
{
BlendOptions *options;
GimpContext *user_context;
GimpGradient *gradient;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *button;
GtkWidget *preview;
/* the new blend tool options structure */
options = g_new0 (BlendOptions, 1);
......@@ -481,7 +477,7 @@ blend_options_new (GimpToolInfo *tool_info)
gimp_dnd_viewable_dest_set (vbox,
GIMP_TYPE_GRADIENT,
blend_options_drop_gradient,
options);
tool_info);
gimp_dnd_viewable_dest_set (vbox,
GIMP_TYPE_TOOL_INFO,
blend_options_drop_tool,
......@@ -506,27 +502,32 @@ blend_options_new (GimpToolInfo *tool_info)
&options->offset);
/* the gradient preview */
user_context = gimp_get_user_context (tool_info->gimp);
gradient = gimp_context_get_gradient (user_context);
button = gtk_button_new ();
preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient),
96, 16, 0,
FALSE, FALSE, TRUE);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Gradient:"), 1.0, 0.5,
button, 2, TRUE);
g_signal_connect_object (G_OBJECT (user_context), "gradient_changed",
G_CALLBACK (gimp_preview_set_viewable),
G_OBJECT (preview),
G_CONNECT_SWAPPED);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (blend_options_gradient_clicked),
NULL);
{
GimpGradient *gradient;
GtkWidget *button;
GtkWidget *preview;
gradient = gimp_context_get_gradient (tool_info->context);
button = gtk_button_new ();
preview = gimp_preview_new_full (GIMP_VIEWABLE (gradient),
96, 16, 0,
FALSE, FALSE, TRUE);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Gradient:"), 1.0, 0.5,
button, 2, TRUE);
g_signal_connect_object (G_OBJECT (tool_info->context), "gradient_changed",
G_CALLBACK (gimp_preview_set_viewable),
G_OBJECT (preview),
G_CONNECT_SWAPPED);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (blend_options_gradient_clicked),
NULL);
}
/* the gradient type menu */
options->gradient_type_w =
......@@ -677,14 +678,11 @@ blend_options_drop_gradient (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
GimpToolOptions *tool_options;
GimpContext *context;
GimpToolInfo *tool_info;
tool_options = (GimpToolOptions *) data;
context = gimp_get_user_context (tool_options->tool_info->gimp);
tool_info = GIMP_TOOL_INFO (data);
gimp_context_set_gradient (context, GIMP_GRADIENT (viewable));
gimp_context_set_gradient (tool_info->context, GIMP_GRADIENT (viewable));
}
static void
......
......@@ -299,7 +299,7 @@ gimp_paint_tool_button_press (GimpTool *tool,
core->use_pressure = TRUE;
}
if (! gimp_paint_core_start (core, drawable, &curr_coords))
if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords))
return;
if ((gdisp != tool->gdisp) || ! (state & GDK_SHIFT_MASK))
......
......@@ -31,7 +31,10 @@
#include "paint/gimppaintoptions.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpenummenu.h"
#include "widgets/gimppreview.h"
#include "widgets/gimpwidgets-constructors.h"
#include "widgets/gtkhwrapbox.h"
......@@ -74,6 +77,8 @@ static void paint_options_paint_mode_update (GtkWidget *widget,
static void paint_options_paint_mode_changed (GimpContext *context,
GimpLayerModeEffects paint_mode,
gpointer data);
static void paint_options_brush_clicked (GtkWidget *widget,
gpointer data);
static void paint_options_gradient_toggle_callback (GtkWidget *widget,
GimpPaintOptions *options);
......@@ -109,7 +114,7 @@ paint_options_init (GimpPaintOptions *options,
vbox = options->tool_options.main_vbox;
/* the main table */
table = gtk_table_new (2, 3, FALSE);
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
......@@ -155,6 +160,37 @@ paint_options_init (GimpPaintOptions *options,
gtk_widget_set_sensitive (mode_label, FALSE);
}
/* the brush preview */
if (tool_info->tool_type != GIMP_TYPE_BUCKET_FILL_TOOL &&
tool_info->tool_type != GIMP_TYPE_BLEND_TOOL &&
tool_info->tool_type != GIMP_TYPE_INK_TOOL)
{
GimpBrush *brush;
GtkWidget *button;
GtkWidget *preview;
brush = gimp_context_get_brush (options->context);
button = gtk_button_new ();
preview = gimp_preview_new_full (GIMP_VIEWABLE (brush),
24, 24, 0,
FALSE, TRUE, TRUE);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Brush:"), 1.0, 0.5,
button, 2, TRUE);
g_signal_connect_object (G_OBJECT (options->context), "brush_changed",
G_CALLBACK (gimp_preview_set_viewable),
G_OBJECT (preview),
G_CONNECT_SWAPPED);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (paint_options_brush_clicked),
NULL);
}
/* a separator after the common paint options */
if (tool_info->tool_type == GIMP_TYPE_BLEND_TOOL)
{
......@@ -647,6 +683,19 @@ paint_options_paint_mode_changed (GimpContext *context,
GINT_TO_POINTER (paint_mode));
}
static void
paint_options_brush_clicked (GtkWidget *widget,
gpointer data)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
if (GIMP_IS_DOCK (toplevel))
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toplevel)->dialog_factory,
"gimp-brush-grid", -1);
}
static void
paint_options_gradient_toggle_callback (GtkWidget *widget,
GimpPaintOptions *options)
......
......@@ -299,7 +299,7 @@ gimp_paint_tool_button_press (GimpTool *tool,
core->use_pressure = TRUE;
}
if (! gimp_paint_core_start (core, drawable, &curr_coords))
if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords))
return;
if ((gdisp != tool->gdisp) || ! (state & GDK_SHIFT_MASK))
......
......@@ -31,7 +31,10 @@
#include "paint/gimppaintoptions.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpenummenu.h"
#include "widgets/gimppreview.h"
#include "widgets/gimpwidgets-constructors.h"
#include "widgets/gtkhwrapbox.h"
......@@ -74,6 +77,8 @@ static void paint_options_paint_mode_update (GtkWidget *widget,
static void paint_options_paint_mode_changed (GimpContext *context,
GimpLayerModeEffects paint_mode,
gpointer data);
static void paint_options_brush_clicked (GtkWidget *widget,
gpointer data);
static void paint_options_gradient_toggle_callback (GtkWidget *widget,
GimpPaintOptions *options);
......@@ -109,7 +114,7 @@ paint_options_init (GimpPaintOptions *options,
vbox = options->tool_options.main_vbox;
/* the main table */
table = gtk_table_new (2, 3, FALSE);
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
......@@ -155,6 +160,37 @@ paint_options_init (GimpPaintOptions *options,
gtk_widget_set_sensitive (mode_label, FALSE);
}
/* the brush preview */
if (tool_info->tool_type != GIMP_TYPE_BUCKET_FILL_TOOL &&
tool_info->tool_type != GIMP_TYPE_BLEND_TOOL &&
tool_info->tool_type != GIMP_TYPE_INK_TOOL)
{
GimpBrush *brush;
GtkWidget *button;
GtkWidget *preview;
brush = gimp_context_get_brush (options->context);
button = gtk_button_new ();
preview = gimp_preview_new_full (GIMP_VIEWABLE (brush),
24, 24, 0,
FALSE, TRUE, TRUE);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Brush:"), 1.0, 0.5,
button, 2, TRUE);
g_signal_connect_object (G_OBJECT (options->context), "brush_changed",
G_CALLBACK (gimp_preview_set_viewable),
G_OBJECT (preview),
G_CONNECT_SWAPPED);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (paint_options_brush_clicked),
NULL);
}
/* a separator after the common paint options */
if (tool_info->tool_type == GIMP_TYPE_BLEND_TOOL)
{
......@@ -647,6 +683,19 @@ paint_options_paint_mode_changed (GimpContext *context,
GINT_TO_POINTER (paint_mode));
}
static void
paint_options_brush_clicked (GtkWidget *widget,
gpointer data)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
if (GIMP_IS_DOCK (toplevel))
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toplevel)->dialog_factory,
"gimp-brush-grid", -1);
}
static void
paint_options_gradient_toggle_callback (GtkWidget *widget,
GimpPaintOptions *options)
......
......@@ -59,8 +59,10 @@
#include "libgimp/gimpintl.h"
#define PAINT_OPTIONS_MASK GIMP_CONTEXT_OPACITY_MASK | \
GIMP_CONTEXT_PAINT_MODE_MASK
#define PAINT_OPTIONS_MASK GIMP_CONTEXT_OPACITY_MASK | \
GIMP_CONTEXT_PAINT_MODE_MASK | \
GIMP_CONTEXT_BRUSH_MASK | \
GIMP_CONTEXT_GRADIENT_MASK
typedef struct _GimpToolManager GimpToolManager;
......@@ -148,6 +150,34 @@ tool_manager_init (Gimp *gimp)
gimp_container_thaw (gimp->tool_info_list);
}
void
tool_manager_restore (Gimp *gimp)
{
GimpToolManager *tool_manager;
GimpToolInfo *tool_info;
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
tool_manager = tool_manager_get (gimp);
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
tool_info = GIMP_TOOL_INFO (list->data);
if (tool_info->options_new_func)
{
tool_info->tool_options = tool_info->options_new_func (tool_info);
}
else
{
tool_info->tool_options = tool_options_new (tool_info);
}
}
}
void
tool_manager_exit (Gimp *gimp)
{
......@@ -542,16 +572,10 @@ tool_manager_register_tool (GType tool_type,
g_object_unref (G_OBJECT (pixbuf));
if (options_new_func)
{
tool_info->tool_options = options_new_func (tool_info);
}
else
{
tool_info->tool_options = tool_options_new (tool_info);
}
tool_info->options_new_func = options_new_func;
gimp_container_add (gimp->tool_info_list, GIMP_OBJECT (tool_info));
g_object_unref (G_OBJECT (tool_info));
}
GimpToolInfo *
......
......@@ -21,6 +21,7 @@
void tool_manager_init (Gimp *gimp);
void tool_manager_restore (Gimp *gimp);
void tool_manager_exit (Gimp *gimp);
GimpTool * tool_manager_get_active (Gimp *gimp);
......
......@@ -68,6 +68,7 @@ typedef struct _GimpImage GimpImage;
typedef struct _GimpCoords GimpCoords; /*< proxy-include >*/
typedef struct _GimpToolOptions GimpToolOptions; /*< proxy-include >*/
typedef GimpToolOptions * (* GimpToolOptionsNewFunc) (GimpToolInfo *tool_info); /*< proxy-include >*/
/* autogenerated from "./../app/widgets/widgets-enums.h" */
/* The GIMP -- an image manipulation program
......
......@@ -39,8 +39,6 @@ typedef struct _GimpTransformTool GimpTransformTool;
/* functions */
typedef GimpToolOptions * (* GimpToolOptionsNewFunc) (GimpToolInfo *tool_info);
typedef void (* GimpToolOptionsResetFunc) (GimpToolOptions *tool_options);
typedef void (* GimpToolRegisterCallback) (GType tool_type,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment