gimp/app/gdisplay_ops.c

316 lines
7.9 KiB
C
Raw Normal View History

1997-11-25 06:05:25 +08:00
/* 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.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
#include <gtk/gtk.h>
Makefile.am configure.in added the new library below. 2001-01-24 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added the new library below. * libgimpwidgets/Makefile.am * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.[ch] * libgimpwidgets/gimpcolorbutton.[ch] * libgimpwidgets/gimpdialog.[ch] * libgimpwidgets/gimpfileselection.[ch] * libgimpwidgets/gimphelpui.[ch] * libgimpwidgets/gimppatheditor.[ch] * libgimpwidgets/gimppixmap.[ch] * libgimpwidgets/gimpquerybox.[ch] * libgimpwidgets/gimpsizeentry.[ch] * libgimpwidgets/gimpunitmenu.[ch] * libgimpwidgets/gimpwidgets.[ch] * libgimpwidgets/gimpwidgets.def * libgimpwidgets/gimpwidgetstypes.h: new shared library. Currently there are some ugly dependencies into libgimp. These will be removed and go to a "libgimpglue" library which will be a library for functions which share a common interface between plug-ins and the app but have different implementations. Include "libgimp/gimpunit.h" from "libgimpwidgets/gimpwidgetstypes.h" to simulate this upcoming separation. * libgimp/Makefile.am * libgimp/gimpchainbutton.[ch] * libgimp/gimpcolorarea.[ch] * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimpfileselection.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimppixmap.[ch] * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: removed from here. * libgimp/gimpui.h * libgimp/gimpuitypes.h * libgimp/makefile.mingw.in * libgimp/makefile.msc: changed accordingly. * app/[all ui files] * app/pdb/palette_cmds.c * app/pdb/tools_cmds.c * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/tools.pdb: #include "libgimpwidgets/gimpwidgets.h" and removed useless includes. * app/apptypes.h: #include "libgimpwidgets/gimpwidgetstypes.h" * app/Makefile.am * plug-ins/[all makefiles which link against libgimpui]: link against libgimpwidgets.la * po-libgimp/POTFILES.in: changed file locations.
2001-01-25 06:36:18 +08:00
#include "libgimpwidgets/gimpwidgets.h"
#include "apptypes.h"
1997-11-25 06:05:25 +08:00
#include "colormaps.h"
#include "cursorutil.h"
#include "gdisplay_ops.h"
#include "gimpimage.h"
1997-11-25 06:05:25 +08:00
#include "gimprc.h"
#include "libgimp/gimpintl.h"
1997-11-25 06:05:25 +08:00
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
static void gdisplay_close_warning_callback (GtkWidget *widget,
gboolean close,
gpointer data);
static void gdisplay_close_warning_dialog (gchar *image_name,
GDisplay *gdisp);
1997-11-25 06:05:25 +08:00
/*
* This file is for operations on the gdisplay object
*/
gulong
gdisplay_white_pixel (GDisplay *gdisp)
{
return g_white_pixel;
}
gulong
gdisplay_gray_pixel (GDisplay *gdisp)
{
return g_gray_pixel;
}
gulong
gdisplay_black_pixel (GDisplay *gdisp)
{
return g_black_pixel;
}
gulong
gdisplay_color_pixel (GDisplay *gdisp)
{
return g_color_pixel;
}
void
new ui for the "Layer Offset" dialog. 1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de> * app/channel_ops.[ch]: new ui for the "Layer Offset" dialog. * app/channels_dialog.c * app/layers_dialog.c: major code cleanup: Folded some callbacks into common ones, "widget" instead of "w", indentation, ... * app/commands.c * app/interface.[ch] * app/global_edit.c: the query boxes must be shown by the caller now. There's no need to split up the string for the message box manually as the Gtk 1.2 label widget handles newlines corectly. Added the "edge_lock" toggle to the "Shrink Selection" dialog. Nicer spacings for the query and message boxes. * app/ink.c: tried to grab the pointer in the blob preview but failed. Left the code there as a reminder (commented out). * app/menus.c: reordered <Image>/Select. I was bored and grep-ed the sources for ancient or deprecated stuff: * app/about_dialog.[ch] * app/actionarea.[ch] * app/app_procs.c * app/brush_edit.c * app/brush_select.c * app/color_select.c * app/convert.c * app/devices.c * app/gdisplay.c * app/gdisplay_ops.c * app/histogram_tool.[ch] * app/info_window.c * app/install.c * app/ops_buttons.c * app/palette.c * app/palette_select.c * app/paths_dialog.c * app/pattern_select.c * app/resize.c * app/scale_toolc.c * app/text_tool.c: s/container_border_width/container_set_border_width/g, s/sprintf/g_snprintf/g, replaced some constant string lengths with strlen(x). * app/bezier_select.c * app/blend.c * app/boundary.c * app/errors.[ch] * app/free_select.c * app/gimpbrushlist.c * app/gimprc.c * app/iscissors.c * app/main.c * app/patterns.[ch] * app/text_tool.c: namespace fanaticism: prefixed all gimp error functions with "gimp_" and formated the messages more uniformly. * app/gradient.c * app/gradient_select.c: same stuff as above for the ui code. There are still some sub-dialogs which need cleanup. Did some cleanup in most of these files: prototypes, removed tons of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
gdisplay_xserver_resolution (gdouble *xres,
gdouble *yres)
{
gint width, height;
gint widthMM, heightMM;
width = gdk_screen_width ();
height = gdk_screen_height ();
widthMM = gdk_screen_width_mm ();
heightMM = 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
*/
*xres = (width * 25.4) / ((gdouble) widthMM);
*yres = (height * 25.4) / ((gdouble) heightMM);
}
1997-11-25 06:05:25 +08:00
void
gdisplay_new_view (GDisplay *gdisp)
{
GDisplay *new_gdisp;
/* make sure the image has been fully loaded... */
if (gdisp->gimage)
{
new_gdisp = gdisplay_new (gdisp->gimage, gdisp->scale);
}
}
void
gdisplay_close_window (GDisplay *gdisp,
gboolean kill_it)
1997-11-25 06:05:25 +08:00
{
/* FIXME: gimp_busy HACK not really appropriate here because we only
* want to prevent the busy image and display to be closed. --Mitch
*/
if (gimp_busy)
return;
1997-11-25 06:05:25 +08:00
/* If the image has been modified, give the user a chance to save
* it before nuking it--this only applies if its the last view
* to an image canvas. (a gimage with disp_count = 1)
1997-11-25 06:05:25 +08:00
*/
if (! kill_it &&
(gdisp->gimage->disp_count == 1) &&
gdisp->gimage->dirty &&
confirm_on_close)
{
gdisplay_close_warning_dialog
(g_basename (gimp_image_filename (gdisp->gimage)), gdisp);
}
1997-11-25 06:05:25 +08:00
else
{
gtk_widget_destroy (gdisp->shell);
}
}
void
gdisplay_shrink_wrap (GDisplay *gdisp)
{
/*
* I'm pretty sure this assumes that the current size is < display size
* Is this a valid assumption?
*/
GtkAllocation allocation;
1997-11-25 06:05:25 +08:00
gint disp_width, disp_height;
gint width, height;
gint shell_x, shell_y;
1997-11-25 06:05:25 +08:00
gint shell_width, shell_height;
gint max_auto_width, max_auto_height;
gint border_x, border_y;
gint s_width, s_height;
1997-11-25 06:05:25 +08:00
gboolean resize = FALSE;
s_width = gdk_screen_width ();
1997-11-25 06:05:25 +08:00
s_height = gdk_screen_height ();
width = SCALEX (gdisp, gdisp->gimage->width);
height = SCALEY (gdisp, gdisp->gimage->height);
1997-11-25 06:05:25 +08:00
disp_width = gdisp->disp_width;
1997-11-25 06:05:25 +08:00
disp_height = gdisp->disp_height;
shell_width = gdisp->shell->allocation.width;
1997-11-25 06:05:25 +08:00
shell_height = gdisp->shell->allocation.height;
border_x = shell_width - disp_width;
1997-11-25 06:05:25 +08:00
border_y = shell_height - disp_height;
max_auto_width = (s_width - border_x) * 0.75;
1997-11-25 06:05:25 +08:00
max_auto_height = (s_height - border_y) * 0.75;
allocation.x = 0;
allocation.y = 0;
/* If one of the display dimensions has changed and one of the
* dimensions fits inside the screen
1997-11-25 06:05:25 +08:00
*/
if (((width + border_x) < s_width || (height + border_y) < s_height) &&
(width != disp_width || height != disp_height))
{
width = ((width + border_x) < s_width) ? width : max_auto_width;
1997-11-25 06:05:25 +08:00
height = ((height + border_y) < s_height) ? height : max_auto_height;
resize = TRUE;
}
/* If the projected dimension is greater than current, but less than
* 3/4 of the screen size, expand automagically
*/
else if ((width > disp_width || height > disp_height) &&
(disp_width < max_auto_width || disp_height < max_auto_height))
{
width = MIN (max_auto_width, width);
height = MIN (max_auto_height, height);
resize = TRUE;
}
if (resize)
{
if (width < gdisp->statusarea->requisition.width)
{
width = gdisp->statusarea->requisition.width;
}
#undef RESIZE_DEBUG
#ifdef RESIZE_DEBUG
g_print ("1w:%d/%d d:%d/%d s:%d/%d b:%d/%d\n",
width, height,
disp_width, disp_height,
shell_width, shell_height,
border_x, border_y);
#endif /* RESIZE_DEBUG */
1997-11-25 06:05:25 +08:00
gdisp->disp_width = width;
1997-11-25 06:05:25 +08:00
gdisp->disp_height = height;
allocation.width = width + border_x;
allocation.height = height + border_y;
/* don't call gdisplay_canvas_events() on any of the following
* changes because our caller has to do a full display update anyway
*/
gtk_signal_handler_block_by_data (GTK_OBJECT (gdisp->canvas), gdisp);
gtk_widget_size_allocate (gdisp->shell, &allocation);
gdk_window_resize (gdisp->shell->window,
allocation.width,
allocation.height);
/* let Gtk/X/WM position the window */
while (gtk_events_pending ())
gtk_main_iteration ();
1997-11-25 06:05:25 +08:00
gdk_window_get_origin (gdisp->shell->window, &shell_x, &shell_y);
/* if the window is offscreen, center it... */
if (shell_x > s_width || shell_y > s_height ||
(shell_x + width + border_x) < 0 || (shell_y + height + border_y) < 0)
{
shell_x = (s_width - width - border_x) >> 1;
shell_y = (s_height - height - border_y) >> 1;
gdk_window_move (gdisp->shell->window, shell_x, shell_y);
}
gtk_signal_handler_unblock_by_data (GTK_OBJECT (gdisp->canvas), gdisp);
}
1997-11-25 06:05:25 +08:00
/* If the width or height of the display has changed, recalculate
* the display offsets...
*/
if (disp_width != gdisp->disp_width ||
1997-11-25 06:05:25 +08:00
disp_height != gdisp->disp_height)
{
gdisp->offset_x += (disp_width - gdisp->disp_width) / 2;
1997-11-25 06:05:25 +08:00
gdisp->offset_y += (disp_height - gdisp->disp_height) / 2;
}
}
/********************************************************
* Routines to query before closing a dirty image *
********************************************************/
static void
new ui for the "Layer Offset" dialog. 1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de> * app/channel_ops.[ch]: new ui for the "Layer Offset" dialog. * app/channels_dialog.c * app/layers_dialog.c: major code cleanup: Folded some callbacks into common ones, "widget" instead of "w", indentation, ... * app/commands.c * app/interface.[ch] * app/global_edit.c: the query boxes must be shown by the caller now. There's no need to split up the string for the message box manually as the Gtk 1.2 label widget handles newlines corectly. Added the "edge_lock" toggle to the "Shrink Selection" dialog. Nicer spacings for the query and message boxes. * app/ink.c: tried to grab the pointer in the blob preview but failed. Left the code there as a reminder (commented out). * app/menus.c: reordered <Image>/Select. I was bored and grep-ed the sources for ancient or deprecated stuff: * app/about_dialog.[ch] * app/actionarea.[ch] * app/app_procs.c * app/brush_edit.c * app/brush_select.c * app/color_select.c * app/convert.c * app/devices.c * app/gdisplay.c * app/gdisplay_ops.c * app/histogram_tool.[ch] * app/info_window.c * app/install.c * app/ops_buttons.c * app/palette.c * app/palette_select.c * app/paths_dialog.c * app/pattern_select.c * app/resize.c * app/scale_toolc.c * app/text_tool.c: s/container_border_width/container_set_border_width/g, s/sprintf/g_snprintf/g, replaced some constant string lengths with strlen(x). * app/bezier_select.c * app/blend.c * app/boundary.c * app/errors.[ch] * app/free_select.c * app/gimpbrushlist.c * app/gimprc.c * app/iscissors.c * app/main.c * app/patterns.[ch] * app/text_tool.c: namespace fanaticism: prefixed all gimp error functions with "gimp_" and formated the messages more uniformly. * app/gradient.c * app/gradient_select.c: same stuff as above for the ui code. There are still some sub-dialogs which need cleanup. Did some cleanup in most of these files: prototypes, removed tons of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
gdisplay_close_warning_callback (GtkWidget *widget,
gboolean close,
gpointer data)
1997-11-25 06:05:25 +08:00
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
1997-11-25 06:05:25 +08:00
gdisp->warning_dialog = NULL;
1997-11-25 06:05:25 +08:00
if (close)
gtk_widget_destroy (gdisp->shell);
1997-11-25 06:05:25 +08:00
}
static void
gdisplay_close_warning_dialog (gchar *image_name,
1997-11-25 06:05:25 +08:00
GDisplay *gdisp)
{
GtkWidget *mbox;
gchar *warning_buf;
if (gdisp->warning_dialog != NULL)
1997-11-25 06:05:25 +08:00
{
gdk_window_raise (gdisp->warning_dialog->window);
1997-11-25 06:05:25 +08:00
return;
}
warning_buf =
g_strdup_printf (_("Changes were made to %s.\nClose anyway?"), image_name);
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
gdisp->warning_dialog = mbox =
gimp_query_boolean_box (image_name,
gimp_standard_help_func,
"dialogs/really_close.html",
FALSE,
warning_buf,
_("Close"), _("Cancel"),
NULL, NULL,
gdisplay_close_warning_callback,
gdisp);
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
g_free (warning_buf);
1997-11-25 06:05:25 +08:00
gtk_widget_show (mbox);
}