Gimp/app/gui/gui.c
Sven Neumann 073e533a8a Finally landed the new GimpConfig based gimprc parser. It's not finished
2002-11-18  Sven Neumann  <sven@gimp.org>

	Finally landed the new GimpConfig based gimprc parser. It's not
	finished yet but we need to start somewhere. This release removes
	the old gimprc.[ch] files. The gimprc format changes slightly, but
	the changes are minimal. The Preferences dialog is temporarily
	disabled since it still needs to be ported. If you are are afraid,
	stay away from CVS for a few days ;-)

	* app/Makefile.am
	* app/gimprc.[ch]: removed the old gimprc system.

	* app/base/Makefile.am
	* app/base/base-config.[ch]: removed these files in favor of
	config/gimpbaseconfig.[ch].

	* app/core/Makefile.am
	* app/core/gimpcoreconfig.[ch]: removed these files in favor of
	config/gimpcoreconfig.[ch].

	* app/config/Makefile.am
	* app/config/config-types.h: moved typedefs into this new file.

	* app/config/gimpbaseconfig.[ch]
	* app/config/gimpcoreconfig.[ch]
	* app/config/gimpdisplayconfig.[ch]
	* app/config/gimpguiconfig.[ch]
	* app/config/gimprc.[ch]
	* app/config/test-config.c: brought into shape for real use.

	* app/base/base-types.h: include config/config-types.h here. Added
	a global GimpBaseConfig *base_config variable to ease migration.

	* app/gui/Makefile.am: temporarily disabled the preferences dialog.

	* app/app_procs.c
	* app/undo.c
	* app/undo_history.c
	* app/base/base.[ch]
	* app/base/gimphistogram.c
	* app/base/pixel-processor.c
	* app/base/temp-buf.c
	* app/base/tile-cache.c
	* app/core/core-types.h
	* app/core/gimp-documents.c
	* app/core/gimp.c
	* app/core/gimpbrush.c
	* app/core/gimpbrushgenerated.c
	* app/core/gimpcontext.c
	* app/core/gimpdrawable-transform.c
	* app/core/gimpimage-new.c
	* app/core/gimpimage.c
	* app/core/gimpimagefile.c
	* app/core/gimpmodules.c
	* app/core/gimppattern.c
	* app/display/Makefile.am
	* app/display/gimpdisplay-handlers.c
	* app/display/gimpdisplay.[ch]
	* app/display/gimpdisplayshell-callbacks.c
	* app/display/gimpdisplayshell-handlers.c
	* app/display/gimpdisplayshell-layer-select.c
	* app/display/gimpdisplayshell-render.c
	* app/display/gimpdisplayshell-scale.c
	* app/display/gimpdisplayshell-scroll.c
	* app/display/gimpdisplayshell-selection.c
	* app/display/gimpdisplayshell.[ch]
	* app/display/gimpnavigationview.c
	* app/file/file-save.c
	* app/gui/device-status-dialog.c
	* app/gui/dialogs-constructors.c
	* app/gui/file-commands.c
	* app/gui/file-new-dialog.c
	* app/gui/file-open-dialog.c
	* app/gui/file-save-dialog.c
	* app/gui/gui.c
	* app/gui/menus.c
	* app/gui/paths-dialog.c
	* app/gui/resize-dialog.c
	* app/gui/session.c
	* app/gui/test-commands.c
	* app/gui/tips-dialog.c
	* app/gui/tips-dialog.h
	* app/gui/user-install-dialog.c
	* app/gui/view-commands.c
	* app/paint/gimppaintcore.c
	* app/plug-in/plug-in.c
	* app/plug-in/plug-ins.c
	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.c
	* app/tools/gimptexttool.[ch]
	* app/tools/selection_options.c
	* app/tools/tools.c
	* app/tools/transform_options.c
	* app/widgets/gimphelp.c
	* app/widgets/gimpitemfactory.c
	* app/widgets/gimpselectioneditor.c
	* app/xcf/xcf-load.c
	* tools/pdbgen/pdb/fileops.pdb
	* tools/pdbgen/pdb/gimprc.pdb
	* tools/pdbgen/pdb/image.pdb
	* tools/pdbgen/pdb/layer.pdb
	* tools/pdbgen/pdb/transform_tools.pdb: use the new config system
	instead of the old gimprc stuff.

	* etc/gimprc.in
	* etc/gimprc_user.in: adapted to the new gimprc format. Will update
	the man-page later...

	* app/pdb/fileops_cmds.c
	* app/pdb/gimprc_cmds.c
	* app/pdb/image_cmds.c
	* app/pdb/layer_cmds.c
	* app/pdb/transform_tools_cmds.c
	* libgimp/gimpgimprc_pdb.c: regenerated.
2002-11-18 20:50:31 +00:00

600 lines
14 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 <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-render.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "device-status-dialog.h"
#include "dialogs.h"
#include "dialogs-commands.h"
#include "error-console-dialog.h"
#include "file-open-dialog.h"
#include "file-save-dialog.h"
#include "gui.h"
#include "menus.h"
#include "session.h"
#include "libgimp/gimpintl.h"
#include "pixmaps/wilber2.xpm"
/* local function prototypes */
static void gui_main (Gimp *gimp);
static void gui_main_quit (Gimp *gimp);
static void gui_set_busy (Gimp *gimp);
static void gui_unset_busy (Gimp *gimp);
static void gui_message (Gimp *gimp,
const gchar *message);
static GimpObject * gui_display_new (GimpImage *gimage,
guint scale);
static void gui_themes_dir_foreach_func (GimpDatafileData *file_data);
static gint gui_rotate_the_shield_harmonics (GtkWidget *widget,
GdkEvent *eevent,
gpointer data);
static void gui_really_quit_callback (GtkWidget *button,
gboolean quit,
gpointer data);
static void gui_display_changed (GimpContext *context,
GimpDisplay *display,
Gimp *gimp);
static void gui_image_disconnect (GimpImage *gimage,
gpointer data);
/* private variables */
static GQuark image_disconnect_handler_id = 0;
static GHashTable *themes_hash = NULL;
/* public functions */
void
gui_libs_init (gint *argc,
gchar ***argv)
{
#ifdef HAVE_PUTENV
gchar *display_env;
#endif
g_return_if_fail (argc != NULL);
g_return_if_fail (argv != NULL);
gtk_init (argc, argv);
#ifdef HAVE_PUTENV
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
putenv (display_env);
#endif
gimp_widgets_init ();
g_type_class_ref (GIMP_TYPE_COLOR_SELECT);
}
void
gui_themes_init (Gimp *gimp)
{
GimpGuiConfig *config;
const gchar *theme_dir;
gchar *gtkrc;
g_return_if_fail (GIMP_IS_GIMP (gimp));
config = GIMP_GUI_CONFIG (gimp->config);
themes_hash = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_free);
if (config->theme_path)
{
gimp_datafiles_read_directories (config->theme_path,
G_FILE_TEST_IS_DIR,
gui_themes_dir_foreach_func,
gimp);
}
theme_dir = gui_themes_get_theme_dir (gimp);
if (theme_dir)
{
gtkrc = g_build_filename (theme_dir, "gtkrc", NULL);
}
else
{
/* get the hardcoded default theme gtkrc */
gtkrc = g_strdup (gimp_gtkrc ());
}
if (gimp->be_verbose)
g_print (_("Parsing '%s'\n"), gtkrc);
gtk_rc_parse (gtkrc);
g_free (gtkrc);
/* parse the user gtkrc */
gtkrc = gimp_personal_rc_file ("gtkrc");
if (gimp->be_verbose)
g_print (_("Parsing '%s'\n"), gtkrc);
gtk_rc_parse (gtkrc);
g_free (gtkrc);
/* tooltips */
gimp_help_init ();
if (! config->show_tool_tips)
gimp_help_disable_tooltips ();
gdk_rgb_set_min_colors (CLAMP (gimp->config->min_colors, 27, 256));
gdk_rgb_set_install (gimp->config->install_cmap);
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
}
const gchar *
gui_themes_get_theme_dir (Gimp *gimp)
{
GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);
if (config->theme)
return g_hash_table_lookup (themes_hash, config->theme);
return g_hash_table_lookup (themes_hash, "Default");
}
void
gui_init (Gimp *gimp)
{
GimpDisplayConfig *display_config;
GimpGuiConfig *gui_config;
g_return_if_fail (GIMP_IS_GIMP (gimp));
display_config = GIMP_DISPLAY_CONFIG (gimp->config);
gui_config = GIMP_GUI_CONFIG (gimp->config);
gimp->gui_main_loop_func = gui_main;
gimp->gui_main_loop_quit_func = gui_main_quit;
gimp->gui_set_busy_func = gui_set_busy;
gimp->gui_unset_busy_func = gui_unset_busy;
gimp->gui_message_func = gui_message;
gimp->gui_create_display_func = gui_display_new;
image_disconnect_handler_id =
gimp_container_add_handler (gimp->images, "disconnect",
G_CALLBACK (gui_image_disconnect),
gimp);
g_signal_connect (G_OBJECT (gimp_get_user_context (gimp)), "display_changed",
G_CALLBACK (gui_display_changed),
gimp);
/* make sure the monitor resolution is valid */
if (display_config->monitor_res_from_gdk ||
display_config->monitor_xres < GIMP_MIN_RESOLUTION ||
display_config->monitor_yres < GIMP_MIN_RESOLUTION)
{
gdouble xres, yres;
gui_get_screen_resolution (&xres, &yres);
g_object_set (G_OBJECT (gimp->config),
"monitor-xresolution", xres,
"monitor-yresolution", yres,
"monitor-resolution-from-windowing-system", TRUE,
NULL);
}
menus_init (gimp);
render_setup (gui_config->transparency_type, gui_config->transparency_size);
dialogs_init (gimp);
gimp_devices_init (gimp, device_status_dialog_update_current);
session_init (gimp);
}
void
gui_restore (Gimp *gimp,
gboolean restore_session)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->message_handler = GIMP_MESSAGE_BOX;
file_open_dialog_menu_init (gimp, gimp_item_factory_from_path ("<Load>"));
file_save_dialog_menu_init (gimp, gimp_item_factory_from_path ("<Save>"));
menus_restore (gimp);
gimp_devices_restore (gimp);
if (GIMP_GUI_CONFIG (gimp->config)->restore_session || restore_session)
session_restore (gimp);
dialogs_show_toolbox ();
}
void
gui_post_init (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (GIMP_GUI_CONFIG (gimp->config)->show_tips)
{
gimp_dialog_factory_dialog_new (global_dialog_factory,
"gimp-tips-dialog", -1);
}
}
void
gui_shutdown (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->message_handler = GIMP_CONSOLE;
session_save (gimp);
if (GIMP_GUI_CONFIG (gimp->config)->save_device_status)
gimp_devices_save (gimp);
gimp_displays_delete (gimp);
}
void
gui_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
menus_exit (gimp);
render_free ();
dialogs_exit (gimp);
gimp_devices_exit (gimp);
gimp_help_free ();
gimp_container_remove_handler (gimp->images, image_disconnect_handler_id);
image_disconnect_handler_id = 0;
if (themes_hash)
{
g_hash_table_destroy (themes_hash);
themes_hash = NULL;
}
g_type_class_unref (g_type_class_peek (GIMP_TYPE_COLOR_SELECT));
}
void
gui_get_screen_resolution (gdouble *xres,
gdouble *yres)
{
gint width, height;
gint width_mm, height_mm;
gdouble x = 0.0;
gdouble y = 0.0;
g_return_if_fail (xres != NULL);
g_return_if_fail (yres != NULL);
width = gdk_screen_width ();
height = gdk_screen_height ();
width_mm = gdk_screen_width_mm ();
height_mm = gdk_screen_height_mm ();
/*
* From xdpyinfo.c:
*
* there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
*
* dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
* = N pixels / (M inch / 25.4)
* = N * 25.4 pixels / M inch
*/
if (width_mm > 0 && height_mm > 0)
{
x = (width * 25.4) / (gdouble) width_mm;
y = (height * 25.4) / (gdouble) height_mm;
}
if (x < GIMP_MIN_RESOLUTION || x > GIMP_MAX_RESOLUTION ||
y < GIMP_MIN_RESOLUTION || y > GIMP_MAX_RESOLUTION)
{
g_warning ("GDK returned bogus values for the screen resolution, "
"using 75 dpi instead.");
x = 75.0;
y = 75.0;
}
*xres = x;
*yres = y;
}
void
gui_really_quit_dialog (GCallback quit_func)
{
GtkItemFactory *item_factory;
GtkWidget *dialog;
item_factory = GTK_ITEM_FACTORY (gimp_item_factory_from_path ("<Toolbox>"));
gimp_item_factory_set_sensitive (item_factory, "/File/Quit", FALSE);
item_factory = GTK_ITEM_FACTORY (gimp_item_factory_from_path ("<Image>"));
gimp_item_factory_set_sensitive (item_factory, "/File/Quit", FALSE);
dialog = gimp_query_boolean_box (_("Quit The GIMP?"),
gimp_standard_help_func,
"dialogs/really_quit.html",
GIMP_STOCK_WILBER_EEK,
_("Some files are unsaved.\n"
"\nReally quit The GIMP?"),
GTK_STOCK_QUIT, GTK_STOCK_CANCEL,
NULL, NULL,
gui_really_quit_callback,
quit_func);
gtk_widget_show (dialog);
}
/* private functions */
static void
gui_main (Gimp *gimp)
{
gtk_main ();
}
static void
gui_main_quit (Gimp *gimp)
{
gtk_main_quit ();
}
static void
gui_set_busy (Gimp *gimp)
{
gimp_displays_set_busy (gimp);
gimp_dialog_factories_idle ();
gdk_flush ();
}
static void
gui_unset_busy (Gimp *gimp)
{
gimp_displays_unset_busy (gimp);
gimp_dialog_factories_unidle ();
gdk_flush ();
}
static void
gui_message (Gimp *gimp,
const gchar *message)
{
switch (gimp->message_handler)
{
case GIMP_MESSAGE_BOX:
gimp_message_box (message, NULL, NULL);
break;
case GIMP_ERROR_CONSOLE:
gimp_dialog_factory_dialog_raise (global_dock_factory,
"gimp-error-console", -1);
error_console_add (gimp, message);
break;
default:
break;
}
}
gboolean double_speed = FALSE;
static GimpObject *
gui_display_new (GimpImage *gimage,
guint scale)
{
GimpDisplay *gdisp;
gdisp = gimp_display_new (gimage, scale);
gimp_context_set_display (gimp_get_user_context (gimage->gimp), gdisp);
if (double_speed)
{
GimpDisplayShell *shell;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
g_signal_connect_after (G_OBJECT (shell->canvas), "expose_event",
G_CALLBACK (gui_rotate_the_shield_harmonics),
NULL);
}
return GIMP_OBJECT (gdisp);
}
static void
gui_themes_dir_foreach_func (GimpDatafileData *file_data)
{
Gimp *gimp;
gchar *basename;
gimp = (Gimp *) file_data->user_data;
basename = g_path_get_basename (file_data->filename);
if (gimp->be_verbose)
g_print (_("Adding theme '%s' (%s)\n"), basename, file_data->filename);
g_hash_table_insert (themes_hash,
basename,
g_strdup (file_data->filename));
}
static gint
gui_rotate_the_shield_harmonics (GtkWidget *widget,
GdkEvent *eevent,
gpointer data)
{
GdkPixmap *pixmap = NULL;
GdkBitmap *mask = NULL;
gint width = 0;
gint height = 0;
g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
gui_rotate_the_shield_harmonics,
data);
pixmap = gdk_pixmap_create_from_xpm_d (widget->window,
&mask,
NULL,
wilber2_xpm);
gdk_drawable_get_size (pixmap, &width, &height);
if (widget->allocation.width >= width &&
widget->allocation.height >= height)
{
gint x, y;
x = (widget->allocation.width - width) / 2;
y = (widget->allocation.height - height) / 2;
gdk_gc_set_clip_mask (widget->style->black_gc, mask);
gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
gdk_draw_drawable (widget->window,
widget->style->black_gc,
pixmap, 0, 0,
x, y,
width, height);
gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
}
g_object_unref (pixmap);
g_object_unref (mask);
return FALSE;
}
static void
gui_really_quit_callback (GtkWidget *button,
gboolean quit,
gpointer data)
{
GCallback quit_func;
quit_func = G_CALLBACK (data);
if (quit)
{
(* quit_func) ();
}
else
{
GtkItemFactory *item_factory;
item_factory = GTK_ITEM_FACTORY (gimp_item_factory_from_path ("<Toolbox>"));
gimp_item_factory_set_sensitive (item_factory, "/File/Quit", TRUE);
item_factory = GTK_ITEM_FACTORY (gimp_item_factory_from_path ("<Image>"));
gimp_item_factory_set_sensitive (item_factory, "/File/Quit", TRUE);
}
}
/* FIXME: this junk should mostly go to the display subsystem */
static void
gui_display_changed (GimpContext *context,
GimpDisplay *display,
Gimp *gimp)
{
GimpDisplayShell *shell = NULL;
if (display)
shell = GIMP_DISPLAY_SHELL (display->shell);
gimp_display_shell_set_menu_sensitivity (shell, gimp);
}
static void
gui_image_disconnect (GimpImage *gimage,
gpointer data)
{
Gimp *gimp;
gimp = (Gimp *) data;
/* check if this is the last image */
if (gimp_container_num_children (gimp->images) == 1)
{
dialogs_show_toolbox ();
}
}