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

added some utility functions to get a Gimp, GimpImage, GimpDisplay and

2004-05-03  Michael Natterer  <mitch@gimp.org>

	* app/actions/actions.[ch]: added some utility functions to get a
	Gimp, GimpImage, GimpDisplay and GtkWidget from the "data" pointer
	passed to action callbacks.

	* app/actions/channels-actions.c
	* app/actions/channels-commands.c
	* app/actions/drawable-actions.c
	* app/actions/drawable-commands.c
	* app/actions/edit-actions.c
	* app/actions/edit-commands.c
	* app/actions/file-actions.c
	* app/actions/file-commands.c
	* app/actions/help-commands.c
	* app/actions/image-actions.c
	* app/actions/image-commands.c
	* app/actions/layers-actions.c
	* app/actions/layers-commands.c
	* app/actions/plug-in-actions.c
	* app/actions/plug-in-commands.c
	* app/actions/qmask-actions.c
	* app/actions/qmask-commands.c
	* app/actions/select-actions.c
	* app/actions/select-commands.c
	* app/actions/tools-commands.c
	* app/actions/vectors-actions.c
	* app/actions/vectors-commands.c
	* app/actions/view-commands.c: use the new functions instead of
	duplicating insane macros and if() constructs over and over again.
parent 3c38214c
2004-05-03 Michael Natterer <mitch@gimp.org>
* app/actions/actions.[ch]: added some utility functions to get a
Gimp, GimpImage, GimpDisplay and GtkWidget from the "data" pointer
passed to action callbacks.
* app/actions/channels-actions.c
* app/actions/channels-commands.c
* app/actions/drawable-actions.c
* app/actions/drawable-commands.c
* app/actions/edit-actions.c
* app/actions/edit-commands.c
* app/actions/file-actions.c
* app/actions/file-commands.c
* app/actions/help-commands.c
* app/actions/image-actions.c
* app/actions/image-commands.c
* app/actions/layers-actions.c
* app/actions/layers-commands.c
* app/actions/plug-in-actions.c
* app/actions/plug-in-commands.c
* app/actions/qmask-actions.c
* app/actions/qmask-commands.c
* app/actions/select-actions.c
* app/actions/select-commands.c
* app/actions/tools-commands.c
* app/actions/vectors-actions.c
* app/actions/vectors-commands.c
* app/actions/view-commands.c: use the new functions instead of
duplicating insane macros and if() constructs over and over again.
2004-05-03 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpwidgets.c: use a GimpFrame for
......
......@@ -25,8 +25,18 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "widgets/gimpactionfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpimageeditor.h"
#include "widgets/gimpitemtreeview.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "gui/dialogs.h"
#include "brushes-actions.h"
#include "buffers-actions.h"
......@@ -201,3 +211,82 @@ actions_exit (Gimp *gimp)
g_object_unref (global_action_factory);
global_action_factory = NULL;
}
Gimp *
action_data_get_gimp (gpointer data)
{
if (! data)
return NULL;
if (GIMP_IS_DISPLAY (data))
return ((GimpDisplay *) data)->gimage->gimp;
else if (GIMP_IS_DISPLAY_SHELL (data))
return ((GimpDisplayShell *) data)->gdisp->gimage->gimp;
else if (GIMP_IS_ITEM_TREE_VIEW (data))
return ((GimpItemTreeView *) data)->gimage->gimp;
else if (GIMP_IS_IMAGE_EDITOR (data))
return ((GimpImageEditor *) data)->gimage->gimp;
else if (GIMP_IS_GIMP (data))
return data;
else if (GIMP_IS_DOCK (data))
return ((GimpDock *) data)->context->gimp;
return NULL;
}
GimpImage *
action_data_get_image (gpointer data)
{
if (! data)
return NULL;
if (GIMP_IS_DISPLAY (data))
return ((GimpDisplay *) data)->gimage;
else if (GIMP_IS_DISPLAY_SHELL (data))
return ((GimpDisplayShell *) data)->gdisp->gimage;
else if (GIMP_IS_ITEM_TREE_VIEW (data))
return ((GimpItemTreeView *) data)->gimage;
else if (GIMP_IS_IMAGE_EDITOR (data))
return ((GimpImageEditor *) data)->gimage;
else if (GIMP_IS_GIMP (data))
return gimp_context_get_image (gimp_get_user_context (data));
else if (GIMP_IS_DOCK (data))
return gimp_context_get_image (((GimpDock *) data)->context);
return NULL;
}
GimpDisplay *
action_data_get_display (gpointer data)
{
if (! data)
return NULL;
if (GIMP_IS_DISPLAY (data))
return data;
else if (GIMP_IS_DISPLAY_SHELL (data))
return ((GimpDisplayShell *) data)->gdisp;
else if (GIMP_IS_GIMP (data))
return gimp_context_get_display (gimp_get_user_context (data));
else if (GIMP_IS_DOCK (data))
return gimp_context_get_display (((GimpDock *) data)->context);
return NULL;
}
GtkWidget *
action_data_get_widget (gpointer data)
{
if (! data)
return NULL;
if (GIMP_IS_DISPLAY (data))
return ((GimpDisplay *) data)->shell;
else if (GIMP_IS_GIMP (data))
return dialogs_get_toolbox ();
else if (GTK_IS_WIDGET (data))
return data;
return NULL;
}
......@@ -23,8 +23,13 @@
extern GimpActionFactory *global_action_factory;
void actions_init (Gimp *gimp);
void actions_exit (Gimp *gimp);
void actions_init (Gimp *gimp);
void actions_exit (Gimp *gimp);
Gimp * action_data_get_gimp (gpointer data);
GimpImage * action_data_get_image (gpointer data);
GimpDisplay * action_data_get_display (gpointer data);
GtkWidget * action_data_get_widget (gpointer data);
#endif /* __ACTIONS_H__ */
......@@ -30,11 +30,8 @@
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcomponenteditor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemtreeview.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "actions.h"
#include "channels-actions.h"
#include "channels-commands.h"
......@@ -128,7 +125,7 @@ void
channels_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *gimage = NULL;
GimpImage *gimage;
GimpChannel *channel = NULL;
gboolean fs = FALSE;
gboolean component = FALSE;
......@@ -147,12 +144,7 @@ channels_actions_update (GimpActionGroup *group,
}
else
{
if (GIMP_IS_ITEM_TREE_VIEW (data))
gimage = GIMP_ITEM_TREE_VIEW (data)->gimage;
else if (GIMP_IS_DISPLAY_SHELL (data))
gimage = GIMP_DISPLAY_SHELL (data)->gdisp->gimage;
else if (GIMP_IS_DISPLAY (data))
gimage = GIMP_DISPLAY (data)->gimage;
gimage = action_data_get_image (data);
if (gimage)
{
......
......@@ -30,7 +30,6 @@
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpchannel-select.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
......@@ -38,13 +37,9 @@
#include "widgets/gimpcomponenteditor.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemtreeview.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
#include "gui/dialogs.h"
#include "actions.h"
#include "channels-commands.h"
#include "gimp-intl.h"
......@@ -59,19 +54,7 @@ static void channels_color_changed (GimpColorButton *button,
#define return_if_no_image(gimage,data) \
if (GIMP_IS_DISPLAY (data)) \
gimage = ((GimpDisplay *) data)->gimage; \
else if (GIMP_IS_GIMP (data)) \
gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
else if (GIMP_IS_DOCK (data)) \
gimage = gimp_context_get_image (((GimpDock *) data)->context); \
else if (GIMP_IS_COMPONENT_EDITOR (data)) \
gimage = ((GimpImageEditor *) data)->gimage; \
else if (GIMP_IS_ITEM_TREE_VIEW (data)) \
gimage = ((GimpItemTreeView *) data)->gimage; \
else \
gimage = NULL; \
\
gimage = action_data_get_image (data); \
if (! gimage) \
return
......@@ -82,19 +65,7 @@ static void channels_color_changed (GimpColorButton *button,
return
#define return_if_no_widget(widget,data) \
if (GIMP_IS_DISPLAY (data)) \
widget = ((GimpDisplay *) data)->shell; \
else if (GIMP_IS_GIMP (data)) \
widget = dialogs_get_toolbox (); \
else if (GIMP_IS_DOCK (data)) \
widget = data; \
else if (GIMP_IS_COMPONENT_EDITOR (data)) \
widget = data; \
else if (GIMP_IS_ITEM_TREE_VIEW (data)) \
widget = data; \
else \
widget = NULL; \
\
widget = action_data_get_widget (data); \
if (! widget) \
return
......
......@@ -33,9 +33,7 @@
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "actions.h"
#include "drawable-actions.h"
#include "drawable-commands.h"
......@@ -119,29 +117,16 @@ void
drawable_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpDisplay *gdisp = NULL;
GimpDisplayShell *shell = NULL;
GimpImage *gimage = NULL;
GimpDrawable *drawable = NULL;
gboolean is_rgb = FALSE;
gboolean is_gray = FALSE;
gboolean is_indexed = FALSE;
if (GIMP_IS_DISPLAY_SHELL (data))
{
shell = GIMP_DISPLAY_SHELL (data);
gdisp = shell->gdisp;
}
else if (GIMP_IS_DISPLAY (data))
{
gdisp = GIMP_DISPLAY (data);
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
}
GimpImage *gimage;
GimpDrawable *drawable = NULL;
gboolean is_rgb = FALSE;
gboolean is_gray = FALSE;
gboolean is_indexed = FALSE;
if (gdisp)
{
gimage = gdisp->gimage;
gimage = action_data_get_image (data);
if (gimage)
{
drawable = gimp_image_active_drawable (gimage);
if (drawable)
......
......@@ -18,8 +18,6 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......@@ -27,7 +25,6 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-desaturate.h"
#include "core/gimpdrawable-equalize.h"
......@@ -36,31 +33,16 @@
#include "core/gimpimage-undo.h"
#include "core/gimpitem-linked.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpitemtreeview.h"
#include "display/gimpdisplay.h"
#include "gui/dialogs.h"
#include "gui/offset-dialog.h"
#include "actions.h"
#include "drawable-commands.h"
#include "gimp-intl.h"
#define return_if_no_image(gimage,data) \
if (GIMP_IS_DISPLAY (data)) \
gimage = ((GimpDisplay *) data)->gimage; \
else if (GIMP_IS_GIMP (data)) \
gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
else if (GIMP_IS_DOCK (data)) \
gimage = gimp_context_get_image (((GimpDock *) data)->context); \
else if (GIMP_IS_ITEM_TREE_VIEW (data)) \
gimage = ((GimpItemTreeView *) data)->gimage; \
else \
gimage = NULL; \
\
gimage = action_data_get_image (data); \
if (! gimage) \
return
......@@ -71,17 +53,7 @@
return
#define return_if_no_widget(widget,data) \
if (GIMP_IS_DISPLAY (data)) \
widget = ((GimpDisplay *) data)->shell; \
else if (GIMP_IS_GIMP (data)) \
widget = dialogs_get_toolbox (); \
else if (GIMP_IS_DOCK (data)) \
widget = data; \
else if (GIMP_IS_ITEM_TREE_VIEW (data)) \
widget = data; \
else \
widget = NULL; \
\
widget = action_data_get_widget (data); \
if (! widget) \
return
......
......@@ -36,11 +36,7 @@
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h"
#include "display/gimpdisplayshell-selection.h"
#include "actions.h"
#include "edit-actions.h"
#include "edit-commands.h"
......@@ -190,27 +186,14 @@ void
edit_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpDisplay *gdisp = NULL;
GimpDisplayShell *shell = NULL;
GimpImage *gimage = NULL;
GimpDrawable *drawable = NULL;
gboolean sel = FALSE;
GimpImage *gimage;
GimpDrawable *drawable = NULL;
gboolean sel = FALSE;
if (GIMP_IS_DISPLAY_SHELL (data))
{
shell = GIMP_DISPLAY_SHELL (data);
gdisp = shell->gdisp;
}
else if (GIMP_IS_DISPLAY (data))
{
gdisp = GIMP_DISPLAY (data);
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
}
gimage = action_data_get_image (data);
if (gdisp)
if (gimage)
{
gimage = gdisp->gimage;
sel = ! gimp_channel_is_empty (gimp_image_get_mask (gimage));
drawable = gimp_image_active_drawable (gimage);
......@@ -225,7 +208,7 @@ edit_actions_update (GimpActionGroup *group,
gchar *undo_name = NULL;
gchar *redo_name = NULL;
if (gdisp && gimp_image_undo_is_enabled (gimage))
if (gimage && gimp_image_undo_is_enabled (gimage))
{
GimpUndo *undo;
GimpUndo *redo;
......@@ -256,10 +239,10 @@ edit_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("edit-cut", drawable);
SET_SENSITIVE ("edit-copy", drawable);
SET_SENSITIVE ("edit-paste", gdisp && group->gimp->global_buffer);
SET_SENSITIVE ("edit-paste-into", gdisp && group->gimp->global_buffer);
SET_SENSITIVE ("edit-paste", gimage && group->gimp->global_buffer);
SET_SENSITIVE ("edit-paste-into", gimage && group->gimp->global_buffer);
SET_SENSITIVE ("edit-named-cut", drawable);
SET_SENSITIVE ("edit-named-cut", drawable);
SET_SENSITIVE ("edit-named-paste", drawable);
SET_SENSITIVE ("edit-clear", drawable);
......
......@@ -30,7 +30,6 @@
#include "core/gimp-edit.h"
#include "core/gimpbuffer.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
......@@ -40,39 +39,25 @@
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-transform.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
#include "gui/dialogs.h"
#include "gui/stroke-dialog.h"
#include "actions.h"
#include "edit-commands.h"
#include "gimp-intl.h"
#define return_if_no_display(gdisp,data) \
if (GIMP_IS_DISPLAY (data)) \
gdisp = data; \
else if (GIMP_IS_GIMP (data)) \
gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
else if (GIMP_IS_DOCK (data)) \
gdisp = gimp_context_get_display (((GimpDock *) data)->context); \
else \
gdisp = NULL; \
gdisp = action_data_get_display (data); \
if (! gdisp) \
return
#define return_if_no_image(gimage,data) \
if (GIMP_IS_DISPLAY (data)) \
gimage = ((GimpDisplay *) data)->gimage; \
else if (GIMP_IS_GIMP (data)) \
gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
else if (GIMP_IS_DOCK (data)) \
gimage = gimp_context_get_image (((GimpDock *) data)->context); \
else \
gimage = NULL; \
gimage = action_data_get_image (data); \
if (! gimage) \
return
......
......@@ -36,9 +36,7 @@
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "actions.h"
#include "file-actions.h"
#include "file-commands.h"
......@@ -173,38 +171,23 @@ void
file_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpDisplay *gdisp = NULL;
GimpDisplayShell *shell = NULL;
GimpImage *gimage = NULL;
GimpDrawable *drawable = NULL;
if (GIMP_IS_DISPLAY_SHELL (data))
{
shell = GIMP_DISPLAY_SHELL (data);
gdisp = shell->gdisp;
}
else if (GIMP_IS_DISPLAY (data))
{
gdisp = GIMP_DISPLAY (data);
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
}
GimpImage *gimage = NULL;
GimpDrawable *drawable = NULL;
if (gdisp)
{
gimage = gdisp->gimage;
gimage = action_data_get_image (data);
drawable = gimp_image_active_drawable (gimage);
}
if (gimage)
drawable = gimp_image_active_drawable (gimage);
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
SET_SENSITIVE ("file-save", gdisp && drawable);
SET_SENSITIVE ("file-save-as", gdisp && drawable);
SET_SENSITIVE ("file-save-a-copy", gdisp && drawable);
SET_SENSITIVE ("file-save-as-template", gdisp);
SET_SENSITIVE ("file-revert", gdisp && GIMP_OBJECT (gimage)->name);
SET_SENSITIVE ("file-close", gdisp);
SET_SENSITIVE ("file-save", gimage && drawable);
SET_SENSITIVE ("file-save-as", gimage && drawable);
SET_SENSITIVE ("file-save-a-copy", gimage && drawable);
SET_SENSITIVE ("file-save-as-template", gimage);
SET_SENSITIVE ("file-revert", gimage && GIMP_OBJECT (gimage)->name);
SET_SENSITIVE ("file-close", gimage);
#undef SET_SENSITIVE
}
......
......@@ -39,7 +39,6 @@
#include "file/file-save.h"
#include "file/file-utils.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
......@@ -53,6 +52,7 @@
#include "gui/file-save-dialog.h"
#include "gui/menus.h"
#include "actions.h"
#include "file-commands.h"
#include "gimp-intl.h"
......@@ -62,38 +62,17 @@
#define return_if_no_gimp(gimp,data) \
if (GIMP_IS_DISPLAY (data)) \
gimp = ((GimpDisplay *) data)->gimage->gimp; \
else if (GIMP_IS_GIMP (data)) \
gimp = data; \
else if (GIMP_IS_DOCK (data)) \
gimp = ((GimpDock *) data)->context->gimp; \
else \
gimp = NULL; \
gimp = action_data_get_gimp (data); \
if (! gimp) \
return
#define return_if_no_display(gdisp,data) \
if (GIMP_IS_DISPLAY (data)) \
gdisp = data; \
else if (GIMP_IS_GIMP (data)) \
gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
else if (GIMP_IS_DOCK (data)) \
gdisp = gimp_context_get_display (((GimpDock *) data)->context); \
else \
gdisp = NULL; \
gdisp = action_data_get_display (data); \
if (! gdisp) \
return
#define return_if_no_widget(widget,data) \
if (GIMP_IS_DISPLAY (data)) \
widget = ((GimpDisplay *) data)->shell; \
else if (GIMP_IS_GIMP (data)) \
widget = dialogs_get_toolbox (); \
else if (GIMP_IS_DOCK (data)) \
widget = data; \
else \
widget = NULL; \
widget = action_data_get_widget (data); \
if (! widget) \
return
......
......@@ -24,14 +24,7 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "widgets/gimpdock.h"
#include "display/gimpdisplay.h"
#include "gui/dialogs.h"
#include "actions.h"
#include "help-commands.h"
......@@ -46,14 +39,7 @@ void
help_context_help_cmd_callback (GtkAction *action,
gpointer data)
{
GtkWidget *widget = NULL;