More honesty about bug 144394, it's not quite fixed yet.
[dia.git] / app / scroll_tool.c
blobe9ce9ff63dcfd750ccccb919e639eaec1312f42d
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <config.h>
20 #include "scroll_tool.h"
21 #include "handle_ops.h"
22 #include "object_ops.h"
23 #include "connectionpoint_ops.h"
24 #include "message.h"
25 #include "cursor.h"
27 static void scroll_button_press(ScrollTool *tool, GdkEventButton *event,
28 DDisplay *ddisp);
29 static void scroll_button_release(ScrollTool *tool, GdkEventButton *event,
30 DDisplay *ddisp);
31 static void scroll_motion(ScrollTool *tool, GdkEventMotion *event,
32 DDisplay *ddisp);
33 static void scroll_double_click(ScrollTool *tool, GdkEventButton *event,
34 DDisplay *ddisp);
36 Tool *
37 create_scroll_tool(void)
39 ScrollTool *tool;
41 tool = g_new0(ScrollTool, 1);
42 tool->tool.type = SCROLL_TOOL;
43 tool->tool.button_press_func = (ButtonPressFunc) &scroll_button_press;
44 tool->tool.button_release_func = (ButtonReleaseFunc) &scroll_button_release;
45 tool->tool.motion_func = (MotionFunc) &scroll_motion;
46 tool->tool.double_click_func = (DoubleClickFunc) &scroll_double_click;
48 tool->scrolling = FALSE;
49 tool->use_hand = TRUE;
51 ddisplay_set_all_cursor(get_cursor(CURSOR_GRAB));
53 return (Tool *)tool;
56 void
57 free_scroll_tool(Tool *tool)
59 g_free(tool);
60 ddisplay_set_all_cursor(default_cursor);
64 static void
65 scroll_double_click(ScrollTool *tool, GdkEventButton *event,
66 DDisplay *ddisp)
68 /* Do nothing */
71 static void
72 scroll_button_press(ScrollTool *tool, GdkEventButton *event,
73 DDisplay *ddisp)
75 Point clickedpoint;
77 tool->use_hand = (event->state & GDK_SHIFT_MASK) == 0;
78 if (tool->use_hand)
79 ddisplay_set_all_cursor(get_cursor(CURSOR_GRABBING));
80 else
81 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL));
83 ddisplay_untransform_coords(ddisp,
84 (int)event->x, (int)event->y,
85 &clickedpoint.x, &clickedpoint.y);
87 tool->scrolling = TRUE;
88 tool->last_pos = clickedpoint;
94 static void
95 scroll_motion(ScrollTool *tool, GdkEventMotion *event,
96 DDisplay *ddisp)
98 Point to;
99 Point delta;
101 /* set the cursor appropriately, and change use_hand if needed */
102 if (!tool->scrolling) {
103 /* try to minimise the number of cursor type changes */
104 if ((event->state & GDK_SHIFT_MASK) == 0) {
105 if (!tool->use_hand) {
106 tool->use_hand = TRUE;
107 ddisplay_set_all_cursor(get_cursor(CURSOR_GRAB));
109 } else
110 if (tool->use_hand) {
111 tool->use_hand = FALSE;
112 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL));
114 return;
117 ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y);
119 if (tool->use_hand) {
120 delta = tool->last_pos;
121 point_sub(&delta, &to);
123 tool->last_pos = to;
124 point_add(&tool->last_pos, &delta);
126 /* we use this so you can scroll past the edge of the image */
127 point_add(&delta, &ddisp->origo);
128 ddisplay_set_origo(ddisp, delta.x, delta.y);
129 ddisplay_update_scrollbars(ddisp);
130 ddisplay_add_update_all(ddisp);
131 } else {
132 delta = to;
133 point_sub(&delta, &tool->last_pos);
134 point_scale(&delta, 0.5);
136 ddisplay_scroll(ddisp, &delta);
137 tool->last_pos = to;
139 ddisplay_flush(ddisp);
143 static void
144 scroll_button_release(ScrollTool *tool, GdkEventButton *event,
145 DDisplay *ddisp)
147 tool->use_hand = (event->state & GDK_SHIFT_MASK) == 0;
148 if (tool->use_hand) {
149 ddisplay_set_all_cursor(get_cursor(CURSOR_GRAB));
150 } else
151 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL));
153 tool->scrolling = FALSE;