gimp/app/display/gimpdisplayshell-handlers.c

288 lines
11 KiB
C
Raw Normal View History

/* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "core/gimpimage.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
app/core/Makefile.am new files: the QMask stuff stripped from GUI code. 2001-11-30 Michael Natterer <mitch@gimp.org> * app/core/Makefile.am * app/core/gimpimage-qmask.[ch]: new files: the QMask stuff stripped from GUI code. Added gimp_image_qmask_invert(). * app/core/gimpimage.[ch]: removed the QMask functions. * app/display/Makefile.am * app/display/gimpdisplayshell-qmask.[ch]: removed. * app/gui/Makefile.am * app/gui/qmask-commands.[ch]: new files for the new QMask item factory callbacks and the qmask query dialog. * app/gui/menus.c: added a context menu for the QMask button. * app/display/gimpdisplayshell.c * app/display/gimpdisplayshell-handlers.c: don't include the qmask stuff. * app/display/gimpdisplayshell-callbacks.[ch]: Moved the 2 qmask callbacks here. Don't popup the dialog on double_click. Show the contect menu on right-click. * app/display/gimpdisplayshell-callbacks.[ch]: gimp_display_shell_canvas_events(): removed the hack of conntecting "key_press_event" to gtk_true() while a tool is active. Instead, check for (event & GDK_BUTTON1_MASK) in the key_press and key_release handlers and stop signal emission. Save the modifier state on "button_press" and restore it after "button_release". Changed the way context menus are updated/shown: - removed GimpContainerContextFunc. - pass around item factory identifiers (e.g. "<Brushes>") - added voodoo to update the menus before showing them. * app/widgets/gimpitemfactory.[ch]: gimp_item_factory_new(): take a GimpItemFactoryUpdateFunc parameter, attach it as data to the factory and use it to update the menu in gimp_item_factory_popup_with_date(). * app/widgets/gimpwidgets-utils.[ch]: removed gimp_item_factory_popup_with_data() here. * app/widgets/gimpbrushfactoryview.[ch] * app/widgets/gimpbufferview.[ch] * app/widgets/gimpcontainereditor.[ch] * app/widgets/gimpdatafactoryview.[ch] * app/widgets/gimpdocumentview.[ch] * app/widgets/gimpdrawablelistview.[ch]: use item_factory identifier strings all over the place. * app/widgets/gimpdockbook.c: removed the menu update code, it's now in gui/dialogs-commands.c. * app/gui/brushes-commands.[ch] * app/gui/buffers-commands.[c] * app/gui/channels-commands.[ch] * app/gui/dialogs-commands.[ch] * app/gui/documents-commands.[ch] * app/gui/gradient-editor-commands.[ch] * app/gui/gradients-commands.[ch] * app/gui/layers-commands.[ch] * app/gui/palettes-commands.[ch] * app/gui/patterns-commands.[ch]: removed all show_context_menu() functions and made the update functions public. Changed all update functions to use the gimp_item_factory_set_foo() methods instead of gimp_menu_item_set_foo(). * app/gui/menus.c: pass the update functions to the gimp_item_factory_new(). * app/gui/dialogs-constructors.c: pass item factory identifiers to all view constructors. * app/gui/gradient-editor.c: show the context menu using the new method. * app/gui/toolbox.c: no need to include "dialogs-commands.h".
2001-11-30 22:41:56 +08:00
#include "gimpdisplayshell-callbacks.h"
#include "gimpdisplayshell-handlers.h"
#include "gimpdisplayshell-scale.h"
app/display/Makefile.am app/display/display-types.h new widget derived 2002-02-03 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/display-types.h * app/display/gimpstatusbar.[ch]: new widget derived from GtkStatusbar. Contains the coordinates display, a progress bar which is also used for status message display and a cancel button. Added a simplified API for pushing/popping messages which takes a string as context_id and does the conversion to guint internally on each call. * app/display/gimpdisplayshell.[ch]: removed the status bar code. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/gui/view-commands.c * app/gimpprogress.c: changed accordingly. Removed knowledge about GimpDisplayShell from tools: * app/tools/gimptool.[ch]: added gimp_tool_push_status() and gimp_tool_pop_status() so tools don't need to fiddle with display details. * app/tools/gimpdrawtool.[ch]: pass a GimpDisplay instead of a GdkWindow to gimp_draw_tool_start() (the window passed was always gdisp->shell->canvas->window). * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.[ch] * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.[ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.[ch] * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimprectselecttool.[ch] * app/tools/gimptransformtool.c: changed accordingly: - pass GimpDisplay to gimp_draw_tool_start(). - use GimpTool's new status push/pop functions. - removed the statusbar context_id from all tool structs. * app/gui/dialogs-constructors.[ch]: a bit cleanup in preparation of dockable editor dialogs.
2002-02-03 20:10:23 +08:00
#include "gimpstatusbar.h"
#include "gimprc.h"
/* local function prototypes */
static void gimp_display_shell_clean_dirty_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_undo_event_handler (GimpImage *gimage,
gint event,
GimpDisplayShell *shell);
static void gimp_display_shell_name_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_selection_control_handler (GimpImage *gimage,
GimpSelectionControl control,
GimpDisplayShell *shell);
static void gimp_display_shell_size_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_resolution_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_unit_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_qmask_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static void gimp_display_shell_update_guide_handler (GimpImage *gimage,
GimpGuide *guide,
GimpDisplayShell *shell);
static void gimp_display_shell_invalidate_preview_handler (GimpImage *gimage,
GimpDisplayShell *shell);
static gboolean gimp_display_shell_idle_update_icon (gpointer data);
/* public functions */
void
gimp_display_shell_connect (GimpDisplayShell *shell)
{
GimpImage *gimage;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (GIMP_IS_DISPLAY (shell->gdisp));
g_return_if_fail (GIMP_IS_IMAGE (shell->gdisp->gimage));
gimage = shell->gdisp->gimage;
g_signal_connect (G_OBJECT (gimage), "clean",
G_CALLBACK (gimp_display_shell_clean_dirty_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "dirty",
G_CALLBACK (gimp_display_shell_clean_dirty_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "undo_event",
G_CALLBACK (gimp_display_shell_undo_event_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "name_changed",
G_CALLBACK (gimp_display_shell_name_changed_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "selection_control",
G_CALLBACK (gimp_display_shell_selection_control_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "size_changed",
G_CALLBACK (gimp_display_shell_size_changed_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "resolution_changed",
G_CALLBACK (gimp_display_shell_resolution_changed_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "unit_changed",
G_CALLBACK (gimp_display_shell_unit_changed_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "qmask_changed",
G_CALLBACK (gimp_display_shell_qmask_changed_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "update_guide",
G_CALLBACK (gimp_display_shell_update_guide_handler),
shell);
g_signal_connect (G_OBJECT (gimage), "invalidate_preview",
G_CALLBACK (gimp_display_shell_invalidate_preview_handler),
shell);
gimp_display_shell_invalidate_preview_handler (gimage, shell);
}
void
gimp_display_shell_disconnect (GimpDisplayShell *shell)
{
GimpImage *gimage;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (GIMP_IS_DISPLAY (shell->gdisp));
g_return_if_fail (GIMP_IS_IMAGE (shell->gdisp->gimage));
gimage = shell->gdisp->gimage;
if (shell->icon_idle_id)
{
g_source_remove (shell->icon_idle_id);
shell->icon_idle_id = 0;
}
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_invalidate_preview_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_update_guide_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_qmask_changed_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_unit_changed_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_resolution_changed_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_size_changed_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_selection_control_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_name_changed_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_undo_event_handler,
shell);
g_signal_handlers_disconnect_by_func (G_OBJECT (gimage),
gimp_display_shell_clean_dirty_handler,
shell);
}
/* private functions */
static void
gimp_display_shell_clean_dirty_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
shell->title_dirty = TRUE;
}
static void
gimp_display_shell_undo_event_handler (GimpImage *gimage,
gint event,
GimpDisplayShell *shell)
{
shell->title_dirty = TRUE;
}
static void
gimp_display_shell_name_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
made the gimp_object_get_memsize() debugging output configurable by a 2002-02-06 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.c: made the gimp_object_get_memsize() debugging output configurable by a global "gimp_debug_memsize" boolean. * app/display/gimpdisplay.c: removed duplicated prototype. * app/display/gimpdisplayshell.[ch]: renamed the various cursor functions to be more consistent and shorter. Compress window title updates by adding a "gboolean title_dirty" and updating the title in gimp_display_shell_flush(). Added "%m" (memory size) to the possible title string substitutions. * app/display/gimpdisplay-foreach.c * app/display/gimpdisplayshell-handlers.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimptool.c: changed accordingly. * app/display/gimpdisplayshell-callbacks.c: forgot to grab the pointer when dragging guides from the rulers. Coincidentially, this also fixes the buggy offset between guide and mouse pointer... Cleaned up the main tool event callback a but more. * app/widgets/gimppreview.c * app/gui/commands.c: set the new global "gimp_debug_memsize" toggle to TRUE while calling gimp_object_get_memsize(). * app/gui/preferences-dialog.c: added a image title example containing the new "%m" feature. * docs/gimprc-1.3.5.in: document "%m" in the manpage. * app/tools/gimpbezierselecttool.c: reordered some statements. * app/tools/gimpdrawtool.[ch]: store the GimpDisplay passed to gimp_draw_tool_start() in draw_tool->gdisp and use it for coordinate transfomration. This way we can paint on a display which is not tool->gdisp. * app/tools/gimppainttool.c: changed the gimp_draw_tool_foo() calls needed to make the straight_line preview work in a way that does not interfere with paint_tool subclasses which want to do their own drawing (like the clone tool). Also changed the paint_tools PRETRACE_PAINT and POSTTRACE_PAINT flags usage in a way that subclasses can use them without major hackery: don't simply wrap gimp_display_flush_now() with PRETRACE/POSTTRACE calls, but wrap the actual painting calls, so subclasses are able to do useful things with paint_tool->*_coords. * app/tools/gimpclonetool.c: removed poking around in draw_tool internals and simply suspend()/resume() it in PRETRACE_PAINT/POSTTRACE_PAINT to get the clone_src indicator drawn correctly.
2002-02-07 19:33:01 +08:00
shell->title_dirty = TRUE;
}
static void
gimp_display_shell_selection_control_handler (GimpImage *gimage,
GimpSelectionControl control,
GimpDisplayShell *shell)
{
gimp_display_shell_selection_visibility (shell, control);
}
static void
gimp_display_shell_size_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
app/display/Makefile.am app/display/display-types.h new widget derived 2002-02-03 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/display-types.h * app/display/gimpstatusbar.[ch]: new widget derived from GtkStatusbar. Contains the coordinates display, a progress bar which is also used for status message display and a cancel button. Added a simplified API for pushing/popping messages which takes a string as context_id and does the conversion to guint internally on each call. * app/display/gimpdisplayshell.[ch]: removed the status bar code. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/gui/view-commands.c * app/gimpprogress.c: changed accordingly. Removed knowledge about GimpDisplayShell from tools: * app/tools/gimptool.[ch]: added gimp_tool_push_status() and gimp_tool_pop_status() so tools don't need to fiddle with display details. * app/tools/gimpdrawtool.[ch]: pass a GimpDisplay instead of a GdkWindow to gimp_draw_tool_start() (the window passed was always gdisp->shell->canvas->window). * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.[ch] * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.[ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.[ch] * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimprectselecttool.[ch] * app/tools/gimptransformtool.c: changed accordingly: - pass GimpDisplay to gimp_draw_tool_start(). - use GimpTool's new status push/pop functions. - removed the statusbar context_id from all tool structs. * app/gui/dialogs-constructors.[ch]: a bit cleanup in preparation of dockable editor dialogs.
2002-02-03 20:10:23 +08:00
gimp_statusbar_resize_cursor (GIMP_STATUSBAR (shell->statusbar));
gimp_display_shell_scale_resize (shell, gimprc.resize_windows_on_resize, TRUE);
}
static void
gimp_display_shell_resolution_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
gimp_display_shell_scale_setup (shell);
app/display/Makefile.am app/display/display-types.h new widget derived 2002-02-03 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/display-types.h * app/display/gimpstatusbar.[ch]: new widget derived from GtkStatusbar. Contains the coordinates display, a progress bar which is also used for status message display and a cancel button. Added a simplified API for pushing/popping messages which takes a string as context_id and does the conversion to guint internally on each call. * app/display/gimpdisplayshell.[ch]: removed the status bar code. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/gui/view-commands.c * app/gimpprogress.c: changed accordingly. Removed knowledge about GimpDisplayShell from tools: * app/tools/gimptool.[ch]: added gimp_tool_push_status() and gimp_tool_pop_status() so tools don't need to fiddle with display details. * app/tools/gimpdrawtool.[ch]: pass a GimpDisplay instead of a GdkWindow to gimp_draw_tool_start() (the window passed was always gdisp->shell->canvas->window). * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.[ch] * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.[ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.[ch] * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimprectselecttool.[ch] * app/tools/gimptransformtool.c: changed accordingly: - pass GimpDisplay to gimp_draw_tool_start(). - use GimpTool's new status push/pop functions. - removed the statusbar context_id from all tool structs. * app/gui/dialogs-constructors.[ch]: a bit cleanup in preparation of dockable editor dialogs.
2002-02-03 20:10:23 +08:00
gimp_statusbar_resize_cursor (GIMP_STATUSBAR (shell->statusbar));
}
static void
gimp_display_shell_unit_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
gimp_display_shell_scale_setup (shell);
app/display/Makefile.am app/display/display-types.h new widget derived 2002-02-03 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/display-types.h * app/display/gimpstatusbar.[ch]: new widget derived from GtkStatusbar. Contains the coordinates display, a progress bar which is also used for status message display and a cancel button. Added a simplified API for pushing/popping messages which takes a string as context_id and does the conversion to guint internally on each call. * app/display/gimpdisplayshell.[ch]: removed the status bar code. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/gui/view-commands.c * app/gimpprogress.c: changed accordingly. Removed knowledge about GimpDisplayShell from tools: * app/tools/gimptool.[ch]: added gimp_tool_push_status() and gimp_tool_pop_status() so tools don't need to fiddle with display details. * app/tools/gimpdrawtool.[ch]: pass a GimpDisplay instead of a GdkWindow to gimp_draw_tool_start() (the window passed was always gdisp->shell->canvas->window). * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.[ch] * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.[ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.[ch] * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimprectselecttool.[ch] * app/tools/gimptransformtool.c: changed accordingly: - pass GimpDisplay to gimp_draw_tool_start(). - use GimpTool's new status push/pop functions. - removed the statusbar context_id from all tool structs. * app/gui/dialogs-constructors.[ch]: a bit cleanup in preparation of dockable editor dialogs.
2002-02-03 20:10:23 +08:00
gimp_statusbar_resize_cursor (GIMP_STATUSBAR (shell->statusbar));
}
static void
gimp_display_shell_qmask_changed_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
GtkImage *image;
image = GTK_IMAGE (GTK_BIN (shell->qmask)->child);
g_signal_handlers_block_by_func (G_OBJECT (shell->qmask),
gimp_display_shell_qmask_toggled,
shell);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shell->qmask),
shell->gdisp->gimage->qmask_state);
if (shell->gdisp->gimage->qmask_state)
gtk_image_set_from_stock (image, GIMP_STOCK_QMASK_ON, GTK_ICON_SIZE_MENU);
else
gtk_image_set_from_stock (image, GIMP_STOCK_QMASK_OFF, GTK_ICON_SIZE_MENU);
g_signal_handlers_unblock_by_func (G_OBJECT (shell->qmask),
gimp_display_shell_qmask_toggled,
shell);
}
static void
gimp_display_shell_update_guide_handler (GimpImage *gimage,
GimpGuide *guide,
GimpDisplayShell *shell)
{
gimp_display_shell_expose_guide (shell, guide);
}
static void
gimp_display_shell_invalidate_preview_handler (GimpImage *gimage,
GimpDisplayShell *shell)
{
if (shell->icon_idle_id)
{
g_source_remove (shell->icon_idle_id);
}
shell->icon_idle_id = g_idle_add_full (G_PRIORITY_LOW,
gimp_display_shell_idle_update_icon,
shell,
NULL);
}
static gboolean
gimp_display_shell_idle_update_icon (gpointer data)
{
GimpDisplayShell *shell;
shell = GIMP_DISPLAY_SHELL (data);
shell->icon_idle_id = 0;
gimp_display_shell_update_icon (shell);
return FALSE;
}