gimp/app/widgets/gimptooloptionseditor.c
Michael Natterer eb6e907b36 simplified everything a lot by merging the public GimpContextPropType enum
2003-02-09  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpcontext.[ch]: simplified everything a lot by
	merging the public GimpContextPropType enum with the internal
	anonymous object property id enum. Removed the internal copy_prop
	functions and handle property copying in a big switch() in
	gimp_context_copy_property(). Removed the separate signal
	connections for each property of the parent context and do the
	same using a single "notify" handler. Emit "notify" signals all
	over the place.  Removed internal arrays which are no longer
	needed due to enum merge and copy_property simplification.
	Removed the array of signal names and use g_signal_name().
	Removed gimp_context_unset_parent() and allow "parent" being NULL
	in gimp_context_set_parent().

	* app/tools/tool_manager.c
	* app/widgets/gimpdevices.c: changed accordingly.

	* libgimptool/gimptooltypes.h: changed GimpToolOptionsGUIFunc to
	return a GtkWidget (the created tool options widget).

	* libgimptool/gimptoolmodule.c: #include <gtk/gtk.h>

	* app/tools/tool_options.[ch]: removed the "main_vbox" from the
	GimpToolOptions struct. Changed gimp_tool_options_gui() to create
	and return the main_vbox.

	* app/tools/tool_manager.c: create the "This Tool has no Options"
	label here if NULL was passed as "options_gui_func". Attach the
	options widget to the tool_options object using
	g_object_set_data().

	* app/gui/tool-options-dialog.c: changed accordingly.

	* app/tools/gimpairbrushtool.c
	* app/tools/gimpblendoptions.[ch]
	* app/tools/gimpbucketfilloptions.[ch]
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorpickeroptions.[ch]
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcropoptions.[ch]
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimperasertool.c
	* app/tools/gimpflipoptions.[ch]
	* app/tools/gimpinkoptions.[ch]
	* app/tools/gimpmagnifyoptions.[ch]
	* app/tools/gimpmeasureoptions.[ch]
	* app/tools/gimpmoveoptions.[ch]
	* app/tools/gimpselectionoptions.[ch]
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptextoptions.[ch]
	* app/tools/gimptransformoptions.[ch]
	* app/tools/gimpvectoroptions.[ch]
	* app/tools/paint_options.[ch]: return the options vbox from
	all tool_options_gui functions.
2003-02-09 17:32:52 +00:00

291 lines
8.7 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpdnd.h"
#include "widgets/gimpeditor.h"
#include "tools/tool_options.h"
#include "tool-options-dialog.h"
#include "libgimp/gimpintl.h"
/* local function prototypes */
static void tool_options_dialog_destroy (GtkWidget *widget,
gpointer data);
static void tool_options_dialog_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
gpointer data);
static void tool_options_dialog_drop_tool (GtkWidget *widget,
GimpViewable *viewable,
gpointer data);
static void tool_options_dialog_save_callback (GtkWidget *widget,
GimpContext *context);
static void tool_options_dialog_restore_callback (GtkWidget *widget,
GimpContext *context);
static void tool_options_dialog_reset_callback (GtkWidget *widget,
GimpContext *context);
/* private variables */
static GtkWidget *options_shell = NULL;
static GtkWidget *options_vbox = NULL;
static GtkWidget *options_save_button = NULL;
static GtkWidget *options_revert_button = NULL;
static GtkWidget *options_reset_button = NULL;
static GimpToolOptions *visible_tool_options = NULL;
/* public functions */
GtkWidget *
tool_options_dialog_create (Gimp *gimp)
{
GimpContext *user_context;
GtkWidget *editor;
GtkWidget *scrolled_win;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (options_shell)
return options_shell;
user_context = gimp_get_user_context (gimp);
editor = g_object_new (GIMP_TYPE_EDITOR, NULL);
gtk_widget_set_size_request (editor, -1, 200);
options_shell = editor;
g_signal_connect (options_shell, "destroy",
G_CALLBACK (tool_options_dialog_destroy),
NULL);
options_save_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_SAVE,
_("Save current settings to disk"),
NULL,
G_CALLBACK (tool_options_dialog_save_callback),
NULL,
user_context);
options_revert_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_REVERT_TO_SAVED,
_("Restore saved settings"),
NULL,
G_CALLBACK (tool_options_dialog_restore_callback),
NULL,
user_context);
options_reset_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_STOCK_RESET,
_("Reset"),
NULL,
G_CALLBACK (tool_options_dialog_reset_callback),
NULL,
user_context);
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (editor), scrolled_win);
gtk_widget_show (scrolled_win);
/* The vbox containing the tool options */
options_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (options_vbox), 2);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
options_vbox);
gtk_widget_show (options_vbox);
/* dnd stuff */
gtk_drag_dest_set (options_shell,
GTK_DEST_DEFAULT_ALL,
NULL, 0,
GDK_ACTION_COPY);
gimp_dnd_viewable_dest_add (options_shell,
GIMP_TYPE_TOOL_INFO,
tool_options_dialog_drop_tool,
user_context);
g_signal_connect_object (user_context, "tool_changed",
G_CALLBACK (tool_options_dialog_tool_changed),
options_shell,
0);
tool_options_dialog_tool_changed (user_context,
gimp_context_get_tool (user_context),
options_shell);
return editor;
}
/* private functions */
static void
tool_options_dialog_destroy (GtkWidget *widget,
gpointer data)
{
GList *options;
GList *list;
options = gtk_container_get_children (GTK_CONTAINER (options_vbox));
for (list = options; list; list = g_list_next (list))
{
g_object_ref (list->data);
gtk_container_remove (GTK_CONTAINER (options_vbox),
GTK_WIDGET (list->data));
}
g_list_free (options);
options_shell = NULL;
}
static void
tool_options_dialog_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
gpointer data)
{
GtkWidget *options_gui;
if (visible_tool_options &&
(! tool_info || tool_info->tool_options != visible_tool_options))
{
options_gui = g_object_get_data (G_OBJECT (visible_tool_options),
"gimp-tool-options-gui");
if (options_gui)
gtk_widget_hide (options_gui);
visible_tool_options = NULL;
}
if (tool_info && tool_info->tool_options)
{
options_gui = g_object_get_data (G_OBJECT (tool_info->tool_options),
"gimp-tool-options-gui");
if (! options_gui->parent)
gtk_box_pack_start (GTK_BOX (options_vbox), options_gui,
FALSE, FALSE, 0);
gtk_widget_show (options_gui);
visible_tool_options = tool_info->tool_options;
gtk_widget_set_sensitive (options_save_button, TRUE);
gtk_widget_set_sensitive (options_revert_button, TRUE);
gtk_widget_set_sensitive (options_reset_button, TRUE);
}
else
{
gtk_widget_set_sensitive (options_save_button, FALSE);
gtk_widget_set_sensitive (options_revert_button, FALSE);
gtk_widget_set_sensitive (options_reset_button, FALSE);
}
}
static void
tool_options_dialog_drop_tool (GtkWidget *widget,
GimpViewable *viewable,
gpointer data)
{
GimpContext *context;
context = GIMP_CONTEXT (data);
gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable));
}
static void
tool_options_dialog_save_callback (GtkWidget *widget,
GimpContext *context)
{
GimpToolInfo *tool_info;
GError *error = NULL;
tool_info = gimp_context_get_tool (context);
if (! tool_info)
return;
if (! gimp_tool_options_serialize (tool_info->tool_options, &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
}
}
static void
tool_options_dialog_restore_callback (GtkWidget *widget,
GimpContext *context)
{
GimpToolInfo *tool_info;
GError *error = NULL;
tool_info = gimp_context_get_tool (context);
if (! tool_info)
return;
if (! gimp_tool_options_deserialize (tool_info->tool_options, &error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
}
}
static void
tool_options_dialog_reset_callback (GtkWidget *widget,
GimpContext *context)
{
GimpToolInfo *tool_info;
tool_info = gimp_context_get_tool (context);
if (! tool_info)
return;
gimp_tool_options_reset (tool_info->tool_options);
}