1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of atril, a mate document viewer
3  *
4  *  Copyright (C) 2004 Red Hat, Inc
5  *
6  * Atril is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Atril is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #if !defined (ATRIL_COMPILATION)
22 #error "This is a private header."
23 #endif
24 
25 #ifndef __EV_VIEW_PRIVATE_H__
26 #define __EV_VIEW_PRIVATE_H__
27 
28 #include "ev-view.h"
29 #include "ev-document-model.h"
30 #include "ev-pixbuf-cache.h"
31 #include "ev-page-cache.h"
32 #include "ev-jobs.h"
33 #include "ev-image.h"
34 #include "ev-form-field.h"
35 #include "ev-selection.h"
36 #include "ev-view-cursor.h"
37 
38 #define DRAG_HISTORY 10
39 
40 /* Information for middle clicking and moving around the doc */
41 typedef struct {
42         gboolean in_drag;
43 	GdkPoint start;
44 	gdouble hadj;
45 	gdouble vadj;
46 	guint drag_timeout_id;
47 	guint release_timeout_id;
48 	GdkPoint buffer[DRAG_HISTORY];
49 	GdkPoint momentum;
50 } DragInfo;
51 
52 /* Autoscrolling */
53 typedef struct {
54 	gboolean autoscrolling;
55 	guint last_y;
56 	guint start_y;
57 	guint timeout_id;
58 } AutoScrollInfo;
59 
60 /* Information for handling selection */
61 typedef struct {
62 	gboolean in_drag;
63 	GdkPoint start;
64 	GList *selections;
65 	EvSelectionStyle style;
66 } SelectionInfo;
67 
68 /* Information for handling images DND */
69 typedef struct {
70 	gboolean in_drag;
71 	GdkPoint start;
72 	EvImage *image;
73 } ImageDNDInfo;
74 
75 typedef enum {
76 	EV_PAN_ACTION_NONE,
77 	EV_PAN_ACTION_NEXT,
78 	EV_PAN_ACTION_PREV
79 } EvPanAction;
80 
81 /* Annotation popup windows */
82 typedef struct {
83 	GtkWidget *window;
84 	guint      page;
85 
86 	/* Current position */
87 	gint       x;
88 	gint       y;
89 
90 	/* EvView root position */
91 	gint       parent_x;
92 	gint       parent_y;
93 
94 	/* Document coords */
95 	gdouble    orig_x;
96 	gdouble    orig_y;
97 
98 	gboolean   visible;
99 	gboolean   moved;
100 } EvViewWindowChild;
101 
102 typedef enum {
103 	SCROLL_TO_KEEP_POSITION,
104 	SCROLL_TO_PAGE_POSITION,
105 	SCROLL_TO_CENTER,
106 	SCROLL_TO_FIND_LOCATION,
107 } PendingScroll;
108 
109 typedef struct _EvHeightToPageCache {
110 	gint rotation;
111 	gboolean dual_even_left;
112 	gdouble *height_to_page;
113 	gdouble *dual_height_to_page;
114 } EvHeightToPageCache;
115 
116 struct _EvView {
117 	GtkContainer layout;
118 
119 	/* Container */
120 	GList *children;
121 
122 	EvDocument *document;
123 
124 	/* Find */
125 	GList **find_pages;
126 	gint find_result;
127 	gboolean jump_to_find_result;
128 	gboolean highlight_find_results;
129 	EvDocumentModel *model;
130 	EvPixbufCache *pixbuf_cache;
131 	gsize pixbuf_cache_size;
132 	EvPageCache *page_cache;
133 	EvHeightToPageCache *height_to_page_cache;
134 	EvViewCursor cursor;
135 	EvJobRender *current_job;
136 
137 	GtkRequisition requisition;
138 	gboolean       internal_size_request;
139 
140 	/* Scrolling */
141 	GtkAdjustment *hadjustment;
142 	GtkAdjustment *vadjustment;
143 	/* GtkScrollablePolicy needs to be checked when
144 	* driving the scrollable adjustment values */
145 	guint hscroll_policy : 1;
146 	guint vscroll_policy : 1;
147 
148 	gint scroll_x;
149 	gint scroll_y;
150 
151 	/* Delta sum for emulating normal scrolling */
152 	gdouble       total_delta;
153 	PendingScroll pending_scroll;
154 	gboolean      pending_resize;
155 	EvPoint       pending_point;
156 
157 	/* Current geometry */
158 
159 	gint start_page;
160 	gint end_page;
161 	gint current_page;
162 
163 	gint rotation;
164 	gdouble scale;
165 	gint spacing;
166 
167 	gboolean loading;
168 	gboolean continuous;
169 	gboolean dual_even_left;
170 	gboolean fullscreen;
171 	EvSizingMode sizing_mode;
172 	EvPageLayout page_layout;
173 	GtkWidget *loading_window;
174 	guint loading_timeout;
175 
176 	/* Common for button press handling */
177 	int pressed_button;
178 
179 	/* Key bindings propagation */
180 	gboolean key_binding_handled;
181 
182 	/* Information for middle clicking and dragging around. */
183 	DragInfo drag_info;
184 
185 	/* Autoscrolling */
186 	AutoScrollInfo scroll_info;
187 
188 	/* Selection */
189 	GdkPoint motion;
190 	guint selection_update_id;
191 	guint selection_scroll_id;
192 
193 	SelectionInfo selection_info;
194 
195 	/* Copy link address selection */
196 	EvLinkAction *link_selected;
197 
198 	/* Image DND */
199 	ImageDNDInfo image_dnd_info;
200 
201 	/* Annotations */
202 	GList             *window_children;
203 	EvViewWindowChild *window_child_focus;
204 	gboolean           adding_annot;
205 	EvAnnotationType   adding_annot_type;
206 
207 	/* Focus */
208 	EvMapping *focused_element;
209 	guint focused_element_page;
210 
211 	/* Synctex */
212 	EvMapping *synctex_result;
213 
214 	/* Accessibility */
215 	AtkObject *accessible;
216 
217 	/* Caret navigation */
218 	gboolean caret_enabled;
219 	gint     cursor_offset;
220 	gint     cursor_page;
221 	gdouble  cursor_line_offset;
222 	gboolean cursor_visible;
223 	guint    cursor_blink_timeout_id;
224 	guint    cursor_blink_time;
225 
226 	/* Gestures */
227 	GtkGesture *pan_gesture;
228 	GtkGesture *zoom_gesture;
229 	gdouble prev_zoom_gesture_scale;
230 	EvPanAction pan_action;
231 
232 	/* Current zoom center */
233 	gdouble zoom_center_x;
234 	gdouble zoom_center_y;
235 };
236 
237 struct _EvViewClass {
238 	GtkContainerClass parent_class;
239 
240 	void     (*scroll)            (EvView         *view,
241 	                               GtkScrollType   scroll,
242 	                               GtkOrientation  orientation);
243 	void     (*handle_link)       (EvView         *view,
244 	                               EvLink         *link);
245 	void     (*external_link)     (EvView         *view,
246 	                               EvLinkAction   *action);
247 	void     (*popup_menu)        (EvView         *view,
248 	                               GList          *items);
249 	void     (*selection_changed) (EvView         *view);
250 	void     (*sync_source)       (EvView         *view,
251 	                               EvSourceLink   *link);
252 	void     (*annot_added)       (EvView         *view,
253 	                               EvAnnotation   *annot);
254 	void     (*annot_removed)     (EvView         *view,
255 	                               EvAnnotation   *annot);
256 	void     (*layers_changed)    (EvView         *view);
257 	gboolean (*move_cursor)       (EvView         *view,
258 	                               GtkMovementStep step,
259 	                               gint            count,
260 	                               gboolean        extend_selection);
261 };
262 
263 void _get_page_size_for_scale_and_rotation (EvDocument *document,
264 					    gint        page,
265 					    gdouble     scale,
266 					    gint        rotation,
267 					    gint       *page_width,
268 					    gint       *page_height);
269 void _ev_view_transform_view_point_to_doc_point (EvView       *view,
270 						 GdkPoint     *view_point,
271 						 GdkRectangle *page_area,
272 						 double       *doc_point_x,
273 						 double       *doc_point_y);
274 void _ev_view_transform_view_rect_to_doc_rect (EvView       *view,
275 					       GdkRectangle *view_rect,
276 					       GdkRectangle *page_area,
277 					       EvRectangle  *doc_rect);
278 void _ev_view_transform_doc_point_to_view_point (EvView   *view,
279 						 int       page,
280 						 EvPoint  *doc_point,
281 						 GdkPoint *view_point);
282 void _ev_view_transform_doc_rect_to_view_rect (EvView       *view,
283 					       int           page,
284 					       EvRectangle  *doc_rect,
285 					       GdkRectangle *view_rect);
286 void _ev_view_get_selection_colors (EvView  *view,
287                                     GdkRGBA *bg_color,
288                                     GdkRGBA *fg_color);
289 gint _ev_view_get_caret_cursor_offset_at_doc_point (EvView *view,
290                                                     gint    page,
291                                                     gdouble doc_x,
292                                                     gdouble doc_y);
293 void _ev_view_clear_selection (EvView   *view);
294 void _ev_view_set_selection   (EvView   *view,
295                                GdkPoint *start_point,
296                                GdkPoint *end_point);
297 void _ev_view_set_focused_element (EvView *view,
298                                    EvMapping *element_mapping,
299                                    gint page);
300 void _ev_view_focus_form_field    (EvView      *view,
301 				   EvFormField *field);
302 
303 #endif  /* __EV_VIEW_PRIVATE_H__ */
304 
305