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

app/main.c moved "message_handler" from here...

2001-12-01  Michael Natterer  <mitch@gimp.org>

	* app/main.c
	* app/appenv.h: moved "message_handler" from here...

	* app/core/gimp.[ch]: ...to here. Added gimp_message() and a
	"gui_message_func" pointer...

	* app/gui/gui.c: ...which gets set here to gui_message().

	* app/errors.c: don't include any gui stuff but simply call
	gimp_message().

	* app/app_procs.c: don't set "message_handler" here, it's done in
	gui.c now.

	* app/gui/error-console-dialog.[ch]: use gimp->message_handler.

	* app/gui/dialogs-constructors.c: pass a Gimp pointer to
	error_console_create().

	* app/widgets/gimpwidgets-utils.[ch]: made the "message" parameter
	of gimp_message_box() a const gchar*, not just gchar*.

	* tools/pdbgen/pdb/message.pdb: use gimp->message_handler, don't
	include "appenv.h".

	* app/pdb/message_cmds.c: regenerated.

	* app/devices.[ch]: cleanup before chopping: removed global
	variable "current_device", added devices_get_current(), pass lots
	of Gimp pointers around.

	* app/gimprc.c: pass a Gimp pointer to devices_rc_update().

	* app/display/gimpdisplayshell-callbacks.c
	* app/gui/toolbox.c
	* app/tools/gimppainttool.c: use devices_get_current(), pass Gimp
	pointers to all devices_foo() functions.

	* app/core/gimpimage-mask.c: no need to include "pdb/pdb-types.h".
parent d214dbdb
2001-12-01 Michael Natterer <mitch@gimp.org>
* app/main.c
* app/appenv.h: moved "message_handler" from here...
* app/core/gimp.[ch]: ...to here. Added gimp_message() and a
"gui_message_func" pointer...
* app/gui/gui.c: ...which gets set here to gui_message().
* app/errors.c: don't include any gui stuff but simply call
gimp_message().
* app/app_procs.c: don't set "message_handler" here, it's done in
gui.c now.
* app/gui/error-console-dialog.[ch]: use gimp->message_handler.
* app/gui/dialogs-constructors.c: pass a Gimp pointer to
error_console_create().
* app/widgets/gimpwidgets-utils.[ch]: made the "message" parameter
of gimp_message_box() a const gchar*, not just gchar*.
* tools/pdbgen/pdb/message.pdb: use gimp->message_handler, don't
include "appenv.h".
* app/pdb/message_cmds.c: regenerated.
* app/devices.[ch]: cleanup before chopping: removed global
variable "current_device", added devices_get_current(), pass lots
of Gimp pointers around.
* app/gimprc.c: pass a Gimp pointer to devices_rc_update().
* app/display/gimpdisplayshell-callbacks.c
* app/gui/toolbox.c
* app/tools/gimppainttool.c: use devices_get_current(), pass Gimp
pointers to all devices_foo() functions.
* app/core/gimpimage-mask.c: no need to include "pdb/pdb-types.h".
2001-12-01 Daniel Egger <degger@fhm.edu>
* app/core/Makefile.am
......@@ -36,7 +78,7 @@
* tools/pdbgen/enumcode.pl: added a general check to prevent
enums which are defined in libgimp* from being written to
"libgimp/gimpenums.c".
"libgimp/gimpenums.h".
* libgimp/gimpenums.h
* plug-ins/script-fu/script-fu-constants.c
......
......@@ -19,17 +19,13 @@ scriptdata =
bin_PROGRAMS = gimp-1.3
##
## gui stuff that needs to go to libgimp/, gui/ or /dev/null
## gui stuff for gui/, display/ or widgets/
##
gui_sources = \
devices.c \
devices.h \
gimpprogress.c \
gimpprogress.h \
nav_window.c \
nav_window.h \
ops_buttons.c \
ops_buttons.h \
undo_history.c \
undo_history.h
......@@ -37,6 +33,8 @@ gui_sources = \
## stuff that needs to be split up in core / ui files
##
core_ui_sources = \
gimpprogress.c \
gimpprogress.h \
image_map.c \
image_map.h
......@@ -51,7 +49,6 @@ core_sources = \
## config stuff
##
config_sources = \
appenv.h \
general.c \
general.h \
gimprc.c \
......@@ -61,6 +58,8 @@ config_sources = \
## stuff which is about to be replaced by new subsystems
##
bye_sources = \
ops_buttons.c \
ops_buttons.h \
path.c \
path.h \
pathP.h \
......@@ -77,6 +76,7 @@ bye_sources = \
## stuff
##
stuff_sources = \
appenv.h \
app_procs.c \
app_procs.h \
main.c \
......
......@@ -92,6 +92,8 @@ app_init (gint gimp_argc,
no_interface,
stack_trace_mode);
gimp_object_set_name (GIMP_OBJECT (the_gimp), prog_name);
/* Check if the user's gimp_directory exists
*/
gimp_dir = gimp_directory ();
......@@ -165,9 +167,6 @@ app_init (gint gimp_argc,
if (! no_splash)
splash_destroy ();
/* FIXME: This needs to go in preferences */
message_handler = GIMP_MESSAGE_BOX;
gui_restore (the_gimp, restore_session);
}
......@@ -223,8 +222,6 @@ app_init_update_status (const gchar *text1,
static void
app_exit_finish (void)
{
message_handler = GIMP_CONSOLE;
if (! no_interface)
{
gui_shutdown (the_gimp);
......
......@@ -36,7 +36,6 @@ extern gchar **batch_cmds;
/* other global variables */
extern gchar *prog_name;
extern GimpMessageHandlerType message_handler;
#endif /* __APPENV_H__ */
......@@ -120,6 +120,7 @@ gimp_init (Gimp *gimp)
gimp->be_verbose = FALSE;
gimp->no_data = FALSE;
gimp->no_interface = FALSE;
gimp->message_handler = GIMP_CONSOLE;
gimp->stack_trace_mode = GIMP_STACK_TRACE_NEVER;
gimp->main_loops = NULL;
......@@ -129,6 +130,7 @@ gimp_init (Gimp *gimp)
gimp->gui_create_display_func = NULL;
gimp->gui_set_busy_func = NULL;
gimp->gui_unset_busy_func = NULL;
gimp->gui_message_func = NULL;
gimp->busy = 0;
gimp->busy_idle_id = 0;
......@@ -585,6 +587,30 @@ gimp_unset_busy (Gimp *gimp)
}
}
void
gimp_message (Gimp *gimp,
const gchar *message)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
switch (gimp->message_handler)
{
case GIMP_MESSAGE_BOX:
case GIMP_ERROR_CONSOLE:
if (gimp->gui_message_func)
{
gimp->gui_message_func (gimp, message);
return;
}
break;
default:
break;
}
g_printerr ("%s: %s\n", GIMP_OBJECT (gimp)->name, message);
}
GimpImage *
gimp_create_image (Gimp *gimp,
gint width,
......
......@@ -29,6 +29,8 @@ typedef GimpObject * (* GimpCreateDisplayFunc) (GimpImage *gimage,
guint scale);
typedef void (* GimpSetBusyFunc) (Gimp *gimp);
typedef void (* GimpUnsetBusyFunc) (Gimp *gimp);
typedef void (* GimpMessageFunc) (Gimp *gimp,
const gchar *message);
#define GIMP_TYPE_GIMP (gimp_get_type ())
......@@ -49,6 +51,7 @@ struct _Gimp
gboolean be_verbose;
gboolean no_data;
gboolean no_interface;
GimpMessageHandlerType message_handler;
GimpStackTraceMode stack_trace_mode;
GList *main_loops;
......@@ -58,6 +61,7 @@ struct _Gimp
GimpCreateDisplayFunc gui_create_display_func;
GimpSetBusyFunc gui_set_busy_func;
GimpUnsetBusyFunc gui_unset_busy_func;
GimpMessageFunc gui_message_func;
gint busy;
guint busy_idle_id;
......@@ -147,6 +151,9 @@ void gimp_set_busy (Gimp *gimp);
void gimp_set_busy_until_idle (Gimp *gimp);
void gimp_unset_busy (Gimp *gimp);
void gimp_message (Gimp *gimp,
const gchar *message);
GimpImage * gimp_create_image (Gimp *gimp,
gint width,
gint height,
......
......@@ -21,7 +21,6 @@
#include <glib-object.h>
#include "core-types.h"
#include "pdb/pdb-types.h"
#include "base/boundary.h"
#include "base/pixel-region.h"
......
......@@ -141,10 +141,9 @@ static void device_status_context_connect (GimpContext *context,
GdkDevice *device);
/* global data */
GdkDevice *current_device = NULL;
/* local data */
static GdkDevice *current_device = NULL;
static GList *device_info_list = NULL;
static DeviceInfoDialog *deviceD = NULL;
......@@ -191,10 +190,12 @@ device_info_get_by_name (gchar *name)
/* the gtk input dialog */
GtkWidget *
input_dialog_create (void)
input_dialog_create (Gimp *gimp)
{
static GtkWidget *inputd = NULL;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (inputd)
return inputd;
......@@ -309,8 +310,17 @@ devices_restore (Gimp *gimp)
suppress_update = FALSE;
}
GdkDevice *
devices_get_current (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return current_device;
}
void
devices_rc_update (gchar *name,
devices_rc_update (Gimp *gimp,
gchar *name,
DeviceValues values,
GdkInputMode mode,
gint num_axes,
......@@ -510,11 +520,15 @@ devices_rc_update (gchar *name,
}
void
select_device (GdkDevice *new_device)
select_device (Gimp *gimp,
GdkDevice *new_device)
{
DeviceInfo *device_info;
GimpContext *context;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GDK_IS_DEVICE (new_device));
device_info = device_info_get_by_device (current_device);
gimp_context_unset_parent (device_info->context);
......@@ -537,10 +551,14 @@ select_device (GdkDevice *new_device)
}
gboolean
devices_check_change (GdkEvent *event)
devices_check_change (Gimp *gimp,
GdkEvent *event)
{
GdkDevice *device;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
switch (event->type)
{
case GDK_MOTION_NOTIFY:
......@@ -570,7 +588,7 @@ devices_check_change (GdkEvent *event)
if (device != current_device)
{
select_device (device);
select_device (gimp, device);
return TRUE;
}
......@@ -743,7 +761,7 @@ devices_write_rc (void)
}
GtkWidget *
device_status_create (void)
device_status_create (Gimp *gimp)
{
DeviceInfo *device_info;
GtkWidget *label;
......@@ -751,6 +769,8 @@ device_status_create (void)
GList *list;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (deviceD)
return deviceD->shell;
......@@ -977,8 +997,10 @@ devices_close_callback (GtkWidget *widget,
}
void
device_status_free (void)
device_status_free (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* Save device status on exit */
if (gimprc.save_device_status)
devices_write_rc ();
......
......@@ -33,28 +33,36 @@ typedef enum
DEVICE_GRADIENT = 1 << 8
} DeviceValues;
/* Initialize the input devices */
void devices_init (Gimp *gimp);
/* Restores device settings from rc file */
void devices_restore (Gimp *gimp);
/* Create device info dialog */
GtkWidget * input_dialog_create (void);
/* Create the device status dialog */
GtkWidget * device_status_create (void);
GdkDevice * devices_get_current (Gimp *gimp);
/* Returns TRUE, and makes necessary global changes
* if event is not for current_device
*/
gboolean devices_check_change (GdkEvent *event);
gboolean devices_check_change (Gimp *gimp,
GdkEvent *event);
/* Loads stored device settings (tool, cursor, ...) */
void select_device (GdkDevice *device);
void devices_select_device (Gimp *gimp,
GdkDevice *device);
/* The device info dialog */
GtkWidget * input_dialog_create (Gimp *gimp);
void input_dialog_free (Gimp *gimp);
/* The device status dialog */
GtkWidget * device_status_create (Gimp *gimp);
void device_status_free (Gimp *gimp);
/* Add information about one tool from rc file */
void devices_rc_update (gchar *name,
void devices_rc_update (Gimp *gimp,
gchar *name,
DeviceValues values,
GdkInputMode mode,
gint num_axes,
......@@ -68,12 +76,5 @@ void devices_rc_update (gchar *name,
const gchar *pattern_name,
const gchar *gradient_name);
/* Free device status (only for session-managment) */
void device_status_free (void);
/* Current device */
extern GdkDevice *current_device;
#endif /* __DEVICES_H__ */
......@@ -177,7 +177,7 @@ dialogs_device_status_get (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
return device_status_create ();
return device_status_create (context->gimp);
}
GtkWidget *
......@@ -225,7 +225,7 @@ dialogs_input_devices_get (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
return input_dialog_create ();
return input_dialog_create (context->gimp);
}
GtkWidget *
......@@ -806,7 +806,7 @@ dialogs_error_console_get (GimpDialogFactory *factory,
if (view)
return NULL;
view = error_console_create ();
view = error_console_create (context->gimp);
g_object_add_weak_pointer (G_OBJECT (view), (gpointer *) &view);
......
......@@ -278,7 +278,7 @@ gimp_display_shell_check_device_cursor (GimpDisplayShell *shell)
{
GdkDevice *device = (GdkDevice *) list->data;
if (device == current_device)
if (device == devices_get_current (shell->gdisp->gimage->gimp))
{
shell->draw_cursor = ! device->has_cursor;
break;
......@@ -317,11 +317,17 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
gimage = gdisp->gimage;
/* Find out what device the event occurred upon */
if (! gimage->gimp->busy && devices_check_change (event))
if (! gimage->gimp->busy && devices_check_change (gimage->gimp, event))
{
gimp_display_shell_check_device_cursor (shell);
}
gimp_display_shell_get_coords (shell, event, current_device, &display_coords);
gimp_display_shell_get_state (shell, event, current_device, &state);
gimp_display_shell_get_coords (shell, event,
devices_get_current (gimage->gimp),
&display_coords);
gimp_display_shell_get_state (shell, event,
devices_get_current (gimage->gimp),
&state);
time = gdk_event_get_time (event);
image_coords = display_coords;
......
......@@ -26,16 +26,13 @@
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include <glib-object.h>
#include "widgets/widgets-types.h"
#include "core/core-types.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "gui/dialogs.h"
#include "gui/error-console-dialog.h"
#include "core/gimp.h"
#include "app_procs.h"
#include "appenv.h"
#include "errors.h"
......@@ -44,35 +41,28 @@
#endif
/* local function prototypes */
static void gimp_eek (const gchar *reason,
const gchar *message,
gboolean use_handler);
/* public functions */
void
gimp_message_log_func (const gchar *log_domain,
GLogLevelFlags flags,
const gchar *message,
gpointer data)
{
if (console_messages == FALSE)
{
switch (message_handler)
{
case GIMP_MESSAGE_BOX:
gimp_message_box ((gchar *) message, NULL, NULL);
break;
case GIMP_ERROR_CONSOLE:
gimp_dialog_factory_dialog_raise (global_dock_factory,
"gimp:error-console", -1);
error_console_add ((gchar *) message);
break;
default:
g_printerr ("%s: %s\n", prog_name, (gchar *) message);
break;
}
}
else
if (! console_messages && GIMP_IS_GIMP (the_gimp))
{
g_printerr ("%s: %s\n", prog_name, (gchar *) message);
gimp_message (the_gimp, message);
}
g_printerr ("%s: %s\n", prog_name, message);
}
void
......@@ -81,7 +71,7 @@ gimp_error_log_func (const gchar *domain,
const gchar *message,
gpointer data)
{
gimp_fatal_error ("%s", message);
gimp_fatal_error (message);
}
void
......@@ -94,48 +84,7 @@ gimp_fatal_error (const gchar *fmt, ...)
message = g_strdup_vprintf (fmt, args);
va_end (args);
#ifndef G_OS_WIN32
g_printerr ("%s: fatal error: %s\n", prog_name, message);
switch (stack_trace_mode)
{
case GIMP_STACK_TRACE_NEVER:
break;
case GIMP_STACK_TRACE_QUERY:
{
sigset_t sigset;
sigemptyset (&sigset);
sigprocmask (SIG_SETMASK, &sigset, NULL);
g_on_error_query (prog_name);
}
break;
case GIMP_STACK_TRACE_ALWAYS:
{
sigset_t sigset;
sigemptyset (&sigset);
sigprocmask (SIG_SETMASK, &sigset, NULL);
g_on_error_stack_trace (prog_name);
}
break;
default:
break;
}
#else
/* g_on_error_* don't do anything reasonable on Win32. */
MessageBox (NULL, message, prog_name, MB_OK|MB_ICONERROR);
#endif /* ! G_OS_WIN32 */
gtk_exit (1);
gimp_eek ("fatal error", message, TRUE);
}
void
......@@ -148,11 +97,22 @@ gimp_terminate (const gchar *fmt, ...)
message = g_strdup_vprintf (fmt, args);
va_end (args);
gimp_eek ("terminated", message, use_debug_handler);
}
/* private functions */
static void
gimp_eek (const gchar *reason,
const gchar *message,
gboolean use_handler)
{
#ifndef G_OS_WIN32
g_printerr ("%s terminated: %s\n", prog_name, message);
g_printerr ("%s: %s: %s\n", prog_name, reason, message);
if (use_debug_handler)
if (use_handler)
{
switch (stack_trace_mode)
{
......@@ -192,5 +152,5 @@ gimp_terminate (const gchar *fmt, ...)
#endif /* ! G_OS_WIN32 */
gtk_exit (1);
exit (1);
}
......@@ -2313,7 +2313,8 @@ parse_device (gpointer val1p,
goto error;
token = get_next_token ();
devices_rc_update (name, values, mode, num_axes, axes, num_keys, keys,
devices_rc_update (the_gimp,
name, values, mode, num_axes, axes, num_keys, keys,
tool_name,
&foreground,
&background,
......
......@@ -141,10 +141,9 @@ static void device_status_context_connect (GimpContext *context,
GdkDevice *device);
/* global data */
GdkDevice *current_device = NULL;
/* local data */
static GdkDevice *current_device = NULL;
static GList *device_info_list = NULL;
static DeviceInfoDialog *deviceD = NULL;
......@@ -191,10 +190,12 @@ device_info_get_by_name (gchar *name)
/* the gtk input dialog */
GtkWidget *
input_dialog_create (void)
input_dialog_create (Gimp *gimp)
{
static GtkWidget *inputd = NULL;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (inputd)
return inputd;
......@@ -309,8 +310,17 @@ devices_restore (Gimp *gimp)
suppress_update = FALSE;
}
GdkDevice *
devices_get_current (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return current_device;
}
void
devices_rc_update (gchar *name,
devices_rc_update (Gimp *gimp,
gchar *name,
DeviceValues values,
GdkInputMode mode,
gint num_axes,
......@@ -510,11 +520,15 @@ devices_rc_update (gchar *name,
}
void
select_device (GdkDevice *new_device)
select_device (Gimp *gimp,
GdkDevice *new_device)
{
DeviceInfo *device_info;
GimpContext *context;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GDK_IS_DEVICE (new_device));
device_info = device_info_get_by_device (current_device);
gimp_context_unset_parent (device_info->context);
......@@ -537,10 +551,14 @@ select_device (GdkDevice *new_device)
}
gboolean
devices_check_change (GdkEvent *event)
devices_check_change (Gimp *gimp,
GdkEvent *event)
{
GdkDevice *device;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
switch (event->type)
{
case GDK_MOTION_NOTIFY:
......@@ -570,7 +588,7 @@ devices_check_change (GdkEvent *event)
if (device != current_device)
{
select_device (device);
select_device (gimp, device);
return TRUE;
}
......@@ -743,7 +761,7 @@ devices_write_rc (void)
}
GtkWidget *
device_status_create (void)
device_status_create (Gimp *gimp)
{
DeviceInfo *device_info;
GtkWidget *label;
......@@ -751,6 +769,8 @@ device_status_create (void)
GList *list;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (deviceD)
return deviceD->shell;
......@@ -977,8 +997,10 @@ devices_close_callback (GtkWidget *widget,
}
void
device_status_free (void)
device_status_free (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
/* Save device status on exit */
if (gimprc.save_device_status)
devices_write_rc ();
......
......@@ -177,7 +177,7 @@ dialogs_device_status_get (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
return device_status_create ();
return device_status_create (context->gimp);
}
GtkWidget *
......@@ -225,7 +225,7 @@ dialogs_input_devices_get (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
return input_dialog_create ();
return input_dialog_create (context->gimp);
}
GtkWidget *
......@@ -806,7 +806,7 @@ dialogs_error_console_get (GimpDialogFactory *factory,
if (view)