2008-04-29 00:30:55 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpwindow.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-04-29 00:30:55 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-04-29 00:30:55 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-04-29 00:30:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:28:18 +08:00
|
|
|
#include <gegl.h>
|
2008-04-29 00:30:55 +08:00
|
|
|
#include <gtk/gtk.h>
|
2013-04-09 21:41:20 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2008-04-29 00:30:55 +08:00
|
|
|
|
2011-10-07 06:48:55 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
|
|
|
|
2009-06-24 05:25:09 +08:00
|
|
|
#include "display/display-types.h"
|
|
|
|
#include "display/gimpcanvas.h"
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
#include "gimpwindow.h"
|
|
|
|
|
2010-06-10 00:55:48 +08:00
|
|
|
#include "gimp-log.h"
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MONITOR_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct _GimpWindowPrivate
|
|
|
|
{
|
|
|
|
gint monitor;
|
|
|
|
GtkWidget *primary_focus_widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_window_dispose (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_window_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen);
|
|
|
|
static gboolean gimp_window_configure_event (GtkWidget *widget,
|
|
|
|
GdkEventConfigure *cevent);
|
|
|
|
static gboolean gimp_window_key_press_event (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent);
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpWindow, gimp_window, GTK_TYPE_WINDOW)
|
|
|
|
|
2013-04-09 21:41:20 +08:00
|
|
|
#define parent_class gimp_window_parent_class
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
static guint window_signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_window_class_init (GimpWindowClass *klass)
|
|
|
|
{
|
2013-04-09 21:41:20 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2008-04-29 00:30:55 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
window_signals[MONITOR_CHANGED] =
|
|
|
|
g_signal_new ("monitor-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpWindowClass, monitor_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__OBJECT_INT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
GDK_TYPE_SCREEN,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
2013-04-09 21:41:20 +08:00
|
|
|
object_class->dispose = gimp_window_dispose;
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
widget_class->screen_changed = gimp_window_screen_changed;
|
|
|
|
widget_class->configure_event = gimp_window_configure_event;
|
2008-04-29 00:30:55 +08:00
|
|
|
widget_class->key_press_event = gimp_window_key_press_event;
|
2014-03-14 04:11:07 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpWindowPrivate));
|
2008-04-29 00:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_window_init (GimpWindow *window)
|
|
|
|
{
|
2014-03-14 04:11:07 +08:00
|
|
|
window->private = G_TYPE_INSTANCE_GET_PRIVATE (window,
|
|
|
|
GIMP_TYPE_WINDOW,
|
|
|
|
GimpWindowPrivate);
|
|
|
|
|
|
|
|
window->private->monitor = -1;
|
2008-04-29 00:30:55 +08:00
|
|
|
}
|
|
|
|
|
2013-04-09 21:41:20 +08:00
|
|
|
static void
|
|
|
|
gimp_window_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
gimp_window_set_primary_focus_widget (GIMP_WINDOW (object), NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
static void
|
|
|
|
gimp_window_monitor_changed (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GimpWindow *window = GIMP_WINDOW (widget);
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (widget);
|
|
|
|
GdkWindow *gdk_window = gtk_widget_get_window (widget);
|
|
|
|
|
|
|
|
if (gdk_window)
|
|
|
|
{
|
|
|
|
window->private->monitor = gdk_screen_get_monitor_at_window (screen,
|
|
|
|
gdk_window);
|
|
|
|
|
|
|
|
g_signal_emit (widget, window_signals[MONITOR_CHANGED], 0,
|
|
|
|
screen,
|
|
|
|
window->private->monitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_window_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen)
|
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen);
|
|
|
|
|
|
|
|
gimp_window_monitor_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_window_configure_event (GtkWidget *widget,
|
|
|
|
GdkEventConfigure *cevent)
|
|
|
|
{
|
|
|
|
GimpWindow *window = GIMP_WINDOW (widget);
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (widget);
|
|
|
|
GdkWindow *gdk_window = gtk_widget_get_window (widget);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->configure_event)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->configure_event (widget, cevent);
|
|
|
|
|
|
|
|
if (gdk_window &&
|
|
|
|
window->private->monitor !=
|
|
|
|
gdk_screen_get_monitor_at_window (screen, gdk_window))
|
|
|
|
{
|
|
|
|
gimp_window_monitor_changed (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-06 07:13:48 +08:00
|
|
|
fnord (le);
|
|
|
|
|
2008-04-29 00:30:55 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_window_key_press_event (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
|
|
|
{
|
2013-04-09 21:41:20 +08:00
|
|
|
GimpWindow *gimp_window = GIMP_WINDOW (widget);
|
|
|
|
GtkWindow *window = GTK_WINDOW (widget);
|
|
|
|
GtkWidget *focus = gtk_window_get_focus (window);
|
2011-09-18 05:23:30 +08:00
|
|
|
GdkModifierType accel_mods;
|
|
|
|
gboolean enable_mnemonics;
|
2013-04-09 21:41:20 +08:00
|
|
|
gboolean handled = FALSE;
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
/* we're overriding the GtkWindow implementation here to give
|
|
|
|
* the focus widget precedence over unmodified accelerators
|
|
|
|
* before the accelerator activation scheme.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* text widgets get all key events first */
|
2013-04-26 05:49:29 +08:00
|
|
|
if (focus &&
|
|
|
|
(GTK_IS_EDITABLE (focus) ||
|
|
|
|
GTK_IS_TEXT_VIEW (focus) ||
|
|
|
|
GIMP_IS_CANVAS (focus) ||
|
|
|
|
gtk_widget_get_ancestor (focus, GIMP_TYPE_CANVAS)))
|
2010-06-10 00:55:48 +08:00
|
|
|
{
|
|
|
|
handled = gtk_window_propagate_key_event (window, event);
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
GIMP_LOG (KEY_EVENTS,
|
|
|
|
"handled by gtk_window_propagate_key_event(text_widget)");
|
|
|
|
}
|
2012-05-06 07:13:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
static guint32 val = 0;
|
|
|
|
if ((val = (val << 8) |
|
|
|
|
(((int)event->keyval) & 0xff)) % 141650939 == 62515060)
|
|
|
|
geimnum (eb);
|
|
|
|
}
|
2008-04-29 00:30:55 +08:00
|
|
|
|
2013-04-26 05:49:29 +08:00
|
|
|
if (! handled &&
|
2014-03-14 04:11:07 +08:00
|
|
|
event->keyval == GDK_KEY_Escape &&
|
|
|
|
gimp_window->private->primary_focus_widget)
|
2013-04-09 21:41:20 +08:00
|
|
|
{
|
2014-03-14 04:11:07 +08:00
|
|
|
if (focus != gimp_window->private->primary_focus_widget)
|
|
|
|
gtk_widget_grab_focus (gimp_window->private->primary_focus_widget);
|
2013-04-09 21:41:20 +08:00
|
|
|
else
|
|
|
|
gtk_widget_error_bell (widget);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-10-07 06:48:55 +08:00
|
|
|
accel_mods =
|
|
|
|
gtk_widget_get_modifier_mask (widget,
|
|
|
|
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
|
2011-09-18 05:23:30 +08:00
|
|
|
|
|
|
|
g_object_get (gtk_widget_get_settings (widget),
|
|
|
|
"gtk-enable-mnemonics", &enable_mnemonics,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (enable_mnemonics)
|
|
|
|
accel_mods |= gtk_window_get_mnemonic_modifier (window);
|
|
|
|
|
|
|
|
/* invoke modified accelerators */
|
2012-12-14 16:40:52 +08:00
|
|
|
if (! handled && (event->state & accel_mods))
|
2010-06-10 00:55:48 +08:00
|
|
|
{
|
|
|
|
handled = gtk_window_activate_key (window, event);
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
GIMP_LOG (KEY_EVENTS,
|
|
|
|
"handled by gtk_window_activate_key(modified)");
|
|
|
|
}
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
/* invoke focus widget handlers */
|
|
|
|
if (! handled)
|
2010-06-10 00:55:48 +08:00
|
|
|
{
|
|
|
|
handled = gtk_window_propagate_key_event (window, event);
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
GIMP_LOG (KEY_EVENTS,
|
|
|
|
"handled by gtk_window_propagate_key_event(other_widget)");
|
|
|
|
}
|
2008-04-29 00:30:55 +08:00
|
|
|
|
2011-09-18 05:23:30 +08:00
|
|
|
/* invoke non-modified accelerators */
|
2011-10-07 06:48:55 +08:00
|
|
|
if (! handled && ! (event->state & accel_mods))
|
2010-06-10 00:55:48 +08:00
|
|
|
{
|
|
|
|
handled = gtk_window_activate_key (window, event);
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
GIMP_LOG (KEY_EVENTS,
|
|
|
|
"handled by gtk_window_activate_key(unmodified)");
|
|
|
|
}
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
/* chain up, bypassing gtk_window_key_press(), to invoke binding set */
|
|
|
|
if (! handled)
|
2008-04-29 16:47:52 +08:00
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
widget_class = g_type_class_peek_static (g_type_parent (GTK_TYPE_WINDOW));
|
|
|
|
|
|
|
|
handled = widget_class->key_press_event (widget, event);
|
2010-06-10 00:55:48 +08:00
|
|
|
|
|
|
|
if (handled)
|
|
|
|
GIMP_LOG (KEY_EVENTS,
|
|
|
|
"handled by widget_class->key_press_event()");
|
2008-04-29 16:47:52 +08:00
|
|
|
}
|
2008-04-29 00:30:55 +08:00
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
2013-04-09 21:41:20 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_window_set_primary_focus_widget (GimpWindow *window,
|
|
|
|
GtkWidget *primary_focus)
|
|
|
|
{
|
2014-03-14 04:11:07 +08:00
|
|
|
GimpWindowPrivate *private;
|
|
|
|
|
2013-04-09 21:41:20 +08:00
|
|
|
g_return_if_fail (GIMP_IS_WINDOW (window));
|
2013-04-11 01:28:49 +08:00
|
|
|
g_return_if_fail (primary_focus == NULL || GTK_IS_WIDGET (primary_focus));
|
|
|
|
g_return_if_fail (primary_focus == NULL ||
|
|
|
|
gtk_widget_get_toplevel (primary_focus) ==
|
2013-04-09 21:41:20 +08:00
|
|
|
GTK_WIDGET (window));
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
private = window->private;
|
|
|
|
|
|
|
|
if (private->primary_focus_widget)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (private->primary_focus_widget),
|
|
|
|
(gpointer) &private->primary_focus_widget);
|
2013-04-09 21:41:20 +08:00
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
private->primary_focus_widget = primary_focus;
|
2013-04-09 21:41:20 +08:00
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
if (private->primary_focus_widget)
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (private->primary_focus_widget),
|
|
|
|
(gpointer) &private->primary_focus_widget);
|
2013-04-09 21:41:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_window_get_primary_focus_widget (GimpWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_WINDOW (window), NULL);
|
|
|
|
|
2014-03-14 04:11:07 +08:00
|
|
|
return window->private->primary_focus_widget;
|
2013-04-09 21:41:20 +08:00
|
|
|
}
|