gimp/libgimpwidgets/gimpdialog.c
Michael Natterer ba70ce9a10 changed GimpHelpFunc typedef: - renamed "const gchar *help_data" to "const
2003-08-23  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimpwidgetstypes.h: changed GimpHelpFunc typedef:
	- renamed "const gchar *help_data" to "const gchar *help_id".
	- added "gpointer help_data".

	* libgimpwidgets/gimphelpui.[ch]: added "gpointer help_data" to
	gimp_help_connect(). Removed all fiddling with html links and
	treat all help IDs as opaque identifiers.

	* app/core/gimptoolinfo.[ch]: changed "help_data" member to
	"help_id".

	* app/widgets/gimpitemfactory.[ch]: removed the "help_path"
	parameter from gimp_item_factory_new() since we don't fiddle with
	html file paths any more. Simplifies menu item help a lot.
	Renamed "help_data" member of struct GimpItemFactoryEntry to
	"help_id".

	* app/gui/plug-in-menus.c: changed accordingly. 3rd party
	plug-ins' menu item help IDs are now encoded as
	"help_path:help_id".

	* app/gui/file-open-menu.c
	* app/gui/file-save-menu.c: when constructing the <Load> and
	<Save> menus, take the resp. procedures' locale_domain and
	help_path into account. Fixes translation of 3rd party menu items.
	Also do the right thing for load/save procs which are implemented
	as temporary procedures (they are impossible to implement
	currently but it's nice to do the right thing anyway...).

	* app/widgets/gimphelp-ids.h: added GIMP_HELP_MAIN identifier.

	* libgimpwidgets/gimpdialog.[ch]
	* libgimpwidgets/gimpwidgets.[ch]
	* libgimp/gimpui.c
	* app/display/gimpdisplayshell.c
	* app/gui/gui.c
	* app/gui/about-dialog.c
	* app/gui/color-notebook.c
	* app/gui/dialogs-constructors.c
	* app/gui/file-dialog-utils.[ch]
	* app/gui/gradients-commands.c
	* app/gui/help-commands.c
	* app/gui/image-menu.c
	* app/gui/menus.c
	* app/gui/preferences-dialog.c
	* app/gui/tips-dialog.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimpimagemaptool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimptransformtool.c
	* app/widgets/gimperrorconsole.c
	* app/widgets/gimphelp.[ch]
	* app/widgets/gimpmenufactory.[ch]
	* app/widgets/gimptexteditor.c
	* app/widgets/gimptoolbox.c
	* app/widgets/gimpviewabledialog.[ch]
	* plug-ins/common/CEL.c
	* plug-ins/common/CML_explorer.c
	* plug-ins/common/gee.c
	* plug-ins/common/gee_zoom.c
	* plug-ins/common/gqbist.c
	* plug-ins/common/spheredesigner.c
	* plug-ins/flame/flame.c
	* plug-ins/fp/fp_gtk.c
	* plug-ins/helpbrowser/helpbrowser.c
	* plug-ins/ifscompose/ifscompose.c
	* plug-ins/imagemap/imap_main.c: changed accordingly. Removed
	trailing whitespace all over the place.
2003-08-23 19:35:05 +00:00

371 lines
10 KiB
C

/* LIBGIMP - The GIMP Library
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdialog.c
* Copyright (C) 2000 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h> /* strcmp */
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
#include "gimpdialog.h"
#include "gimphelpui.h"
static void gimp_dialog_class_init (GimpDialogClass *klass);
static void gimp_dialog_init (GimpDialog *dialog);
static gboolean gimp_dialog_delete_event (GtkWidget *widget,
GdkEventAny *event);
static void gimp_dialog_close (GtkDialog *dialog);
static GtkDialogClass *parent_class = NULL;
GType
gimp_dialog_get_type (void)
{
static GType dialog_type = 0;
if (! dialog_type)
{
static const GTypeInfo dialog_info =
{
sizeof (GimpDialogClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_dialog_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpDialog),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_dialog_init,
};
dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
"GimpDialog",
&dialog_info, 0);
}
return dialog_type;
}
static void
gimp_dialog_class_init (GimpDialogClass *klass)
{
GtkWidgetClass *widget_class;
GtkDialogClass *dialog_class;
widget_class = GTK_WIDGET_CLASS (klass);
dialog_class = GTK_DIALOG_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
widget_class->delete_event = gimp_dialog_delete_event;
dialog_class->close = gimp_dialog_close;
}
static void
gimp_dialog_init (GimpDialog *dialog)
{
}
static gboolean
gimp_dialog_delete_event (GtkWidget *widget,
GdkEventAny *event)
{
GtkWidget *cancel_widget;
cancel_widget = (GtkWidget *)
g_object_get_data (G_OBJECT (widget), "gimp-dialog-cancel-button");
if (GTK_IS_WIDGET (cancel_widget))
gtk_widget_activate (cancel_widget);
return TRUE;
}
static void
gimp_dialog_close (GtkDialog *dialog)
{
/* Synthesize delete_event to close dialog. */
GtkWidget *widget = GTK_WIDGET (dialog);
if (widget->window)
{
GdkEvent *event;
event = gdk_event_new (GDK_DELETE);
event->any.window = g_object_ref (widget->window);
event->any.send_event = TRUE;
gtk_main_do_event (event);
gdk_event_free (event);
}
}
/**
* gimp_dialog_new:
* @title: The dialog's title which will be set with
* gtk_window_set_title().
* @wmclass_name: The dialog's @wmclass_name which will be set with
* gtk_window_set_wmclass(). The @wmclass_class will be
* automatically set to "Gimp".
* @help_func: The function which will be called if the user presses "F1".
* @help_id: The help_id which will be passed to @help_func.
* @position: The dialog's initial position which will be set with
* gtk_window_set_position().
* @allow_shrink: The dialog's @allow_shrink flag, ...
* @allow_grow: ... it't @allow_grow flag and ...
* @auto_shrink: ... it's @auto_shrink flag which will all be set with
* gtk_window_set_policy().
* @...: A %NULL-terminated @va_list destribing the
* action_area buttons.
*
* This function simply packs the action_area arguments passed in "..."
* into a @va_list variable and passes everything to gimp_dialog_newv().
*
* For a description of the format of the @va_list describing the
* action_area buttons see gimp_dialog_create_action_areav().
*
* Returns: A #GimpDialog.
**/
GtkWidget *
gimp_dialog_new (const gchar *title,
const gchar *wmclass_name,
GimpHelpFunc help_func,
const gchar *help_id,
GtkWindowPosition position,
gint allow_shrink,
gint allow_grow,
gint auto_shrink,
/* specify action area buttons as va_list:
* const gchar *label,
* GCallback callback,
* gpointer callback_data,
* GObject *slot_object,
* GtkWidget **widget_ptr,
* gboolean default_action,
* gboolean connect_delete,
*/
...)
{
GtkWidget *dialog;
va_list args;
va_start (args, auto_shrink);
dialog = gimp_dialog_newv (title,
wmclass_name,
help_func,
help_id,
position,
allow_shrink,
allow_grow,
auto_shrink,
args);
va_end (args);
return dialog;
}
/**
* gimp_dialog_newv:
* @title: The dialog's title which will be set with
* gtk_window_set_title().
* @wmclass_name: The dialog's @wmclass_name which will be set with
* gtk_window_set_wmclass(). The @wmclass_class will be
* automatically set to "Gimp".
* @help_func: The function which will be called if the user presses "F1".
* @help_id: The help_id which will be passed to @help_func.
* @position: The dialog's initial position which will be set with
* gtk_window_set_position().
* @allow_shrink: The dialog's @allow_shrink flag, ...
* @allow_grow: ... it't @allow_grow flag and ...
* @auto_shrink: ... it's @auto_shrink flag which will all be set with
* gtk_window_set_policy().
* @args: A @va_list as obtained with va_start() describing the
* action_area buttons.
*
* This function performs all neccessary setps to set up a standard GIMP
* dialog.
*
* The @va_list describing the action_area buttons will be passed to
* gimp_dialog_create_action_areav().
*
* Returns: A #GimpDialog.
**/
GtkWidget *
gimp_dialog_newv (const gchar *title,
const gchar *wmclass_name,
GimpHelpFunc help_func,
const gchar *help_id,
GtkWindowPosition position,
gint allow_shrink,
gint allow_grow,
gint auto_shrink,
va_list args)
{
GtkWidget *dialog;
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (wmclass_name != NULL, NULL);
dialog = g_object_new (GIMP_TYPE_DIALOG, NULL);
gtk_window_set_title (GTK_WINDOW (dialog), title);
gtk_window_set_wmclass (GTK_WINDOW (dialog), wmclass_name, "Gimp");
gtk_window_set_position (GTK_WINDOW (dialog), position);
#ifdef __GNUC__
#warning FIXME: need a new API for gimp_dialog_new()
#endif
gtk_window_set_policy (GTK_WINDOW (dialog),
allow_shrink, allow_grow, auto_shrink);
/* prepare the action_area */
gimp_dialog_create_action_areav (GIMP_DIALOG (dialog), args);
/* connect the "F1" help key */
if (help_func)
gimp_help_connect (dialog, help_func, help_id, dialog);
return dialog;
}
/**
* gimp_dialog_create_action_area:
* @dialog: The #GimpDialog you want to create the action_area for.
* @...: A %NULL-terminated @va_list destribing the action_area buttons.
*
* This function simply packs the action_area arguments passed in "..."
* into a @va_list variable and passes everything to
* gimp_dialog_create_action_areav().
**/
void
gimp_dialog_create_action_area (GimpDialog *dialog,
/* specify action area buttons as va_list:
* const gchar *label,
* GCallback callback,
* gpointer callback_data,
* GObject *slot_object,
* GtkWidget **widget_ptr,
* gboolean default_action,
* gboolean connect_delete,
*/
...)
{
va_list args;
va_start (args, dialog);
gimp_dialog_create_action_areav (dialog, args);
va_end (args);
}
/**
* gimp_dialog_create_action_areav:
* @dialog: The #GimpDialog you want to create the action_area for.
* @args: A @va_list as obtained with va_start() describing the action_area
* buttons.
*
* This function creates the action area of a #GimpDialog. You will rarely
* need to call it directly. Instead use gimp_dialog_new() or its variants.
**/
void
gimp_dialog_create_action_areav (GimpDialog *dialog,
va_list args)
{
GtkWidget *button;
/* action area variables */
const gchar *label;
GCallback callback;
gpointer callback_data;
GObject *slot_object;
GtkWidget **widget_ptr;
gboolean default_action;
gboolean connect_delete;
gboolean delete_connected = FALSE;
g_return_if_fail (GIMP_IS_DIALOG (dialog));
/* the action_area buttons */
while ((label = va_arg (args, const gchar *)))
{
callback = va_arg (args, GCallback);
callback_data = va_arg (args, gpointer);
slot_object = va_arg (args, GObject *);
widget_ptr = va_arg (args, GtkWidget **);
default_action = va_arg (args, gboolean);
connect_delete = va_arg (args, gboolean);
if (slot_object == (GObject *) 1)
slot_object = G_OBJECT (dialog);
if (callback_data == NULL)
callback_data = dialog;
button = gtk_dialog_add_button (GTK_DIALOG (dialog), label,
GTK_RESPONSE_NONE);
if (callback)
{
if (slot_object)
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (callback),
slot_object);
else
g_signal_connect (button, "clicked",
G_CALLBACK (callback),
callback_data);
}
if (widget_ptr)
*widget_ptr = button;
if (connect_delete && callback && ! delete_connected)
{
g_object_set_data (G_OBJECT (dialog), "gimp-dialog-cancel-button",
button);
delete_connected = TRUE;
}
if (default_action)
gtk_widget_grab_default (button);
}
}