1 /* -*- Mode: C; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3 -*- */
2
3 /*
4 * GImageView
5 * Copyright (C) 2001-2003 Takuro Ashie
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * $Id: gtk2-compat.c,v 1.4 2003/06/13 10:29:29 makeinu Exp $
22 */
23
24 #include "gtk2-compat.h"
25 #include <gtk/gtk.h>
26
27
28 #ifdef USE_GTK2
29
30 gboolean
gtk2compat_scroll_to_button_cb(GtkWidget * widget,GdkEventScroll * se,gpointer data)31 gtk2compat_scroll_to_button_cb (GtkWidget *widget,
32 GdkEventScroll *se,
33 gpointer data)
34 {
35 GdkEventButton be;
36 gboolean retval;
37
38 g_return_val_if_fail (GTK_IS_WIDGET(widget), FALSE);
39
40 be.type = GDK_BUTTON_PRESS;
41 be.window = se->window;
42 be.send_event = se->send_event;
43 be.time = se->time;
44 be.x = se->x;
45 be.y = se->y;
46 be.axes = NULL;
47 be.state = se->state;
48 be.device = se->device;
49 be.x_root = se->x_root;
50 be.y_root = se->y_root;
51 switch ((se)->direction) {
52 case GDK_SCROLL_UP:
53 be.button = 4;
54 break;
55 case GDK_SCROLL_DOWN:
56 be.button = 5;
57 break;
58 case GDK_SCROLL_LEFT:
59 be.button = 6;
60 break;
61 case GDK_SCROLL_RIGHT:
62 be.button = 7;
63 break;
64 default:
65 g_warning ("invalid scroll direction!");
66 be.button = 0;
67 break;
68 }
69
70 g_signal_emit_by_name (G_OBJECT(widget), "button-press-event",
71 &be, &retval);
72 be.type = GDK_BUTTON_RELEASE;
73 g_signal_emit_by_name (G_OBJECT(widget), "button-release-event",
74 &be, &retval);
75
76 return retval;
77 }
78
79 #else /* USE_GTK2 */
80
81 #include <X11/Xlib.h>
82 #include <gdk/gdkx.h>
83 void
gdk_window_focus(GdkWindow * window,guint32 timestamp)84 gdk_window_focus (GdkWindow *window,
85 guint32 timestamp)
86 {
87 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XWINDOW (window));
88
89 gdk_error_trap_push ();
90 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
91 GDK_WINDOW_XWINDOW (window),
92 RevertToParent,
93 timestamp);
94 XSync (GDK_WINDOW_XDISPLAY (window), False);
95 gdk_error_trap_pop ();
96 }
97
98 #endif /* USE_GTK2 */
99