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.
20 #include "scroll_tool.h"
21 #include "handle_ops.h"
22 #include "object_ops.h"
23 #include "connectionpoint_ops.h"
27 static void scroll_button_press(ScrollTool
*tool
, GdkEventButton
*event
,
29 static void scroll_button_release(ScrollTool
*tool
, GdkEventButton
*event
,
31 static void scroll_motion(ScrollTool
*tool
, GdkEventMotion
*event
,
33 static void scroll_double_click(ScrollTool
*tool
, GdkEventButton
*event
,
37 create_scroll_tool(void)
41 tool
= g_new(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
));
58 free_scroll_tool(Tool
*tool
)
61 ddisplay_set_all_cursor(default_cursor
);
66 scroll_double_click(ScrollTool
*tool
, GdkEventButton
*event
,
73 scroll_button_press(ScrollTool
*tool
, GdkEventButton
*event
,
78 tool
->use_hand
= (event
->state
& GDK_SHIFT_MASK
) == 0;
80 ddisplay_set_all_cursor(get_cursor(CURSOR_GRABBING
));
82 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL
));
84 ddisplay_untransform_coords(ddisp
,
85 (int)event
->x
, (int)event
->y
,
86 &clickedpoint
.x
, &clickedpoint
.y
);
88 tool
->scrolling
= TRUE
;
89 tool
->last_pos
= clickedpoint
;
96 scroll_motion(ScrollTool
*tool
, GdkEventMotion
*event
,
102 /* set the cursor appropriately, and change use_hand if needed */
103 if (!tool
->scrolling
) {
104 /* try to minimise the number of cursor type changes */
105 if ((event
->state
& GDK_SHIFT_MASK
) == 0) {
106 if (!tool
->use_hand
) {
107 tool
->use_hand
= TRUE
;
108 ddisplay_set_all_cursor(get_cursor(CURSOR_GRAB
));
111 if (tool
->use_hand
) {
112 tool
->use_hand
= FALSE
;
113 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL
));
118 ddisplay_untransform_coords(ddisp
, event
->x
, event
->y
, &to
.x
, &to
.y
);
120 if (tool
->use_hand
) {
121 delta
= tool
->last_pos
;
122 point_sub(&delta
, &to
);
125 point_add(&tool
->last_pos
, &delta
);
127 /* we use this so you can scroll past the edge of the image */
128 point_add(&delta
, &ddisp
->origo
);
129 ddisplay_set_origo(ddisp
, delta
.x
, delta
.y
);
130 ddisplay_update_scrollbars(ddisp
);
131 ddisplay_add_update_all(ddisp
);
134 point_sub(&delta
, &tool
->last_pos
);
135 point_scale(&delta
, 0.5);
137 ddisplay_scroll(ddisp
, &delta
);
140 ddisplay_flush(ddisp
);
145 scroll_button_release(ScrollTool
*tool
, GdkEventButton
*event
,
148 tool
->use_hand
= (event
->state
& GDK_SHIFT_MASK
) == 0;
149 if (tool
->use_hand
) {
150 ddisplay_set_all_cursor(get_cursor(CURSOR_GRAB
));
152 ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL
));
154 tool
->scrolling
= FALSE
;