1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of xreader, a generic document viewer
3  *
4  *  Copyright (C) 2004 Red Hat, Inc
5  *
6  * Xreader 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  * Xreader 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 (XREADER_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 	gboolean in_selection;
65 	GList *selections;
66 	EvSelectionStyle style;
67 } SelectionInfo;
68 
69 /* Information for handling images DND */
70 typedef struct {
71 	gboolean in_drag;
72 	GdkPoint start;
73 	EvImage *image;
74 } ImageDNDInfo;
75 
76 typedef enum {
77 	EV_PAN_ACTION_NONE,
78 	EV_PAN_ACTION_NEXT,
79 	EV_PAN_ACTION_PREV
80 } EvPanAction;
81 
82 /* Annotation popup windows */
83 typedef struct {
84 	GtkWidget *window;
85 	guint      page;
86 
87 	/* Current position */
88 	gint       x;
89 	gint       y;
90 
91 	/* EvView root position */
92 	gint       parent_x;
93 	gint       parent_y;
94 
95 	/* Document coords */
96 	gdouble    orig_x;
97 	gdouble    orig_y;
98 
99 	gboolean   visible;
100 	gboolean   moved;
101 } EvViewWindowChild;
102 
103 typedef enum {
104 	SCROLL_TO_KEEP_POSITION,
105 	SCROLL_TO_PAGE_POSITION,
106 	SCROLL_TO_CENTER,
107 	SCROLL_TO_FIND_LOCATION,
108 } PendingScroll;
109 
110 typedef struct _EvHeightToPageCache {
111 	gint rotation;
112 	gboolean dual_even_left;
113 	gdouble *height_to_page;
114 	gdouble *dual_height_to_page;
115 } EvHeightToPageCache;
116 
117 /* Information for handling annotations */
118 typedef struct {
119 	GdkPoint         start;
120 	GdkPoint         stop;
121 	gboolean         adding_annot;
122 	EvAnnotationType type;
123 	EvAnnotation    *annot;
124 } AddingAnnotInfo;
125 
126 struct _EvView {
127 	GtkLayout layout;
128 
129 	/* Container */
130 	GList *children;
131 
132 	EvDocument *document;
133 
134 	/* Find */
135 	GList **find_pages;
136 	gint find_result;
137 	gboolean jump_to_find_result;
138 	gboolean highlight_find_results;
139 
140 	EvDocumentModel *model;
141 	EvPixbufCache *pixbuf_cache;
142 	gsize pixbuf_cache_size;
143 	EvPageCache *page_cache;
144 	EvHeightToPageCache *height_to_page_cache;
145 	EvViewCursor cursor;
146 	EvJobRender *current_job;
147 
148 	GtkRequisition requisition;
149 	gboolean       internal_size_request;
150 
151 	/* Scrolling */
152 	GtkAdjustment *hadjustment;
153 	GtkAdjustment *vadjustment;
154 
155 	/* GtkScrollablePolicy needs to be checked when
156 	* driving the scrollable adjustment values */
157 	guint hscroll_policy : 1;
158 	guint vscroll_policy : 1;
159 
160 	gint scroll_x;
161 	gint scroll_y;
162 
163 	/* Delta sum for emulating normal scrolling */
164 	gdouble       total_delta;
165 	PendingScroll pending_scroll;
166 	gboolean      pending_resize;
167 	EvPoint       pending_point;
168 
169 	/* Current geometry */
170 
171 	gint start_page;
172 	gint end_page;
173 	gint current_page;
174 
175 	gint rotation;
176 	gdouble scale;
177 	gint spacing;
178 
179 	gboolean loading;
180 	gboolean continuous;
181 	gboolean dual_page;
182 	gboolean dual_even_left;
183 	gboolean fullscreen;
184 	EvSizingMode sizing_mode;
185 	GtkWidget *loading_window;
186 	guint loading_timeout;
187 
188 	/* Common for button press handling */
189 	int pressed_button;
190 
191     /* Key bindings propagation */
192     gboolean key_binding_handled;
193 
194 	/* Information for middle clicking and dragging around. */
195 	DragInfo drag_info;
196 
197 	/* Autoscrolling */
198 	AutoScrollInfo scroll_info;
199 
200 	/* Selection */
201 	GdkPoint motion;
202 	guint selection_update_id;
203 	guint selection_scroll_id;
204 
205 	EvViewSelectionMode selection_mode;
206 	SelectionInfo selection_info;
207 
208 	/* Copy link address selection */
209 	EvLinkAction *link_selected;
210 
211 	/* Image DND */
212 	ImageDNDInfo image_dnd_info;
213 
214 	/* Annotations */
215 	GList             *window_children;
216 	EvViewWindowChild *window_child_focus;
217 	EvMapping         *focus_annotation;
218 	AddingAnnotInfo    adding_annot_info;
219 	GHashTable        *annot_window_map;
220 
221 	/* Focus */
222 	EvMapping *focused_element;
223 	guint focused_element_page;
224 	guint child_focus_idle_id;
225 
226 	/* Synctex */
227 	EvMapping *synctex_result;
228 
229 	/* Accessibility */
230 	AtkObject *accessible;
231 
232 	/* Gestures */
233 	GtkGesture *pan_gesture;
234 	GtkGesture *zoom_gesture;
235 	gdouble prev_zoom_gesture_scale;
236 	EvPanAction pan_action;
237 
238 	/* Current zoom center */
239 	gdouble zoom_center_x;
240 	gdouble zoom_center_y;
241 };
242 
243 struct _EvViewClass {
244 	GtkLayoutClass parent_class;
245 
246 	void    (*binding_activated)	  (EvView         *view,
247 					   GtkScrollType   scroll,
248 					   gboolean        horizontal);
249 	void    (*handle_link)		  (EvView         *view,
250 					   EvLink         *link);
251 	void    (*external_link)	  (EvView         *view,
252 					   EvLinkAction   *action);
253 	void    (*popup_menu)		  (EvView         *view,
254 					   GList          *items);
255 	void    (*selection_changed)      (EvView         *view);
256 	void    (*sync_source)            (EvView         *view,
257 					   EvSourceLink   *link);
258 	void    (*annot_added)            (EvView         *view,
259 					   EvAnnotation   *annot);
260 	void    (*layers_changed)         (EvView         *view);
261 	void    (*activate)         (EvView         *view);
262 };
263 
264 void _get_page_size_for_scale_and_rotation (EvDocument *document,
265 					    gint        page,
266 					    gdouble     scale,
267 					    gint        rotation,
268 					    gint       *page_width,
269 					    gint       *page_height);
270 void _ev_view_transform_view_point_to_doc_point (EvView       *view,
271 						 GdkPoint     *view_point,
272 						 GdkRectangle *page_area,
273 						 GtkBorder    *border,
274 						 double       *doc_point_x,
275 						 double       *doc_point_y);
276 void _ev_view_transform_view_rect_to_doc_rect (EvView       *view,
277 					       GdkRectangle *view_rect,
278 					       GdkRectangle *page_area,
279 					       GtkBorder    *border,
280 					       EvRectangle  *doc_rect);
281 void _ev_view_transform_doc_point_to_view_point (EvView   *view,
282 						 int       page,
283 						 EvPoint  *doc_point,
284 						 GdkPoint *view_point);
285 void _ev_view_transform_doc_rect_to_view_rect (EvView       *view,
286 					       int           page,
287 					       EvRectangle  *doc_rect,
288 					       GdkRectangle *view_rect);
289 void _ev_view_get_selection_colors (EvView  *view,
290 				    GdkRGBA *bg_color,
291 				    GdkRGBA *fg_color);
292 
293 #endif  /* __EV_VIEW_PRIVATE_H__ */
294 
295