2057
2086
gtk_widget_grab_focus (field_widget);
2090
static EvViewWindowChild *
2091
ev_view_get_window_child (EvView *view,
2094
GList *children = view->window_children;
2097
EvViewWindowChild *child;
2099
child = (EvViewWindowChild *)children->data;
2100
children = children->next;
2102
if (child->window == window)
2110
ev_view_window_child_move (EvView *view,
2111
EvViewWindowChild *child,
2117
gtk_window_move (GTK_WINDOW (child->window),
2118
MAX (child->parent_x, x),
2119
MAX (child->parent_y, y));
2123
ev_view_window_child_move_with_parent (EvView *view,
2126
EvViewWindowChild *child;
2127
gint root_x, root_y;
2129
child = ev_view_get_window_child (view, window);
2130
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2132
if (root_x != child->parent_x || root_y != child->parent_y) {
2133
gint dest_x, dest_y;
2135
dest_x = child->x + (root_x - child->parent_x);
2136
dest_y = child->y + (root_y - child->parent_y);
2137
child->parent_x = root_x;
2138
child->parent_y = root_y;
2139
ev_view_window_child_move (view, child, dest_x, dest_y);
2142
if (child->visible && !GTK_WIDGET_VISIBLE (window))
2143
gtk_widget_show (window);
2147
ev_view_window_child_put (EvView *view,
2155
EvViewWindowChild *child;
2156
gint root_x, root_y;
2158
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
2161
child = g_new0 (EvViewWindowChild, 1);
2162
child->window = window;
2164
child->orig_x = orig_x;
2165
child->orig_y = orig_y;
2166
child->parent_x = root_x;
2167
child->parent_y = root_y;
2168
child->visible = ev_annotation_window_is_open (EV_ANNOTATION_WINDOW (window));
2169
ev_view_window_child_move (view, child, x + root_x, y + root_y);
2172
gtk_widget_show (window);
2174
gtk_widget_hide (window);
2176
view->window_children = g_list_append (view->window_children, child);
2179
static EvViewWindowChild *
2180
ev_view_find_window_child_for_annot (EvView *view,
2182
EvAnnotation *annot)
2184
GList *children = view->window_children;
2187
EvViewWindowChild *child;
2188
EvAnnotation *wannot;
2190
child = (EvViewWindowChild *)children->data;
2191
children = children->next;
2193
if (child->page != page)
2196
wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
2197
if (wannot == annot || strcmp (wannot->name, annot->name) == 0)
2205
ev_view_window_children_free (EvView *view)
2209
if (!view->window_children)
2212
for (l = view->window_children; l && l->data; l = g_list_next (l)) {
2213
EvViewWindowChild *child;
2215
child = (EvViewWindowChild *)l->data;
2216
gtk_widget_destroy (GTK_WIDGET (child->window));
2219
g_list_free (view->window_children);
2220
view->window_children = NULL;
2221
view->window_child_focus = NULL;
2225
annotation_window_grab_focus (GtkWidget *widget,
2228
if (view->window_child_focus)
2229
ev_annotation_window_ungrab_focus (EV_ANNOTATION_WINDOW (view->window_child_focus->window));
2230
view->window_child_focus = ev_view_get_window_child (view, widget);
2234
annotation_window_closed (EvAnnotationWindow *window,
2237
EvViewWindowChild *child;
2239
child = ev_view_get_window_child (view, GTK_WIDGET (window));
2240
child->visible = FALSE;
2244
annotation_window_moved (EvAnnotationWindow *window,
2249
EvViewWindowChild *child;
2250
GdkRectangle page_area;
2252
GdkRectangle view_rect;
2253
EvRectangle doc_rect;
2256
child = ev_view_get_window_child (view, GTK_WIDGET (window));
2257
if (child->x == x && child->y == y)
2260
child->moved = TRUE;
2264
/* Window has been moved by the user,
2265
* we have to set a new origin in doc coords
2267
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
2268
view_rect.x = (x - child->parent_x) + view->scroll_x;
2269
view_rect.y = (y - child->parent_y) + view->scroll_y;
2270
view_rect.width = width;
2271
view_rect.height = height;
2273
get_page_extents (view, child->page, &page_area, &border);
2274
view_rect_to_doc_rect (view, &view_rect, &page_area, &doc_rect);
2275
child->orig_x = doc_rect.x1;
2276
child->orig_y = doc_rect.y1;
2280
ev_view_annotation_save (EvView *view,
2281
EvAnnotation *annot)
2283
if (!view->document)
2286
if (!annot->changed)
2289
ev_document_annotations_annotation_set_contents (EV_DOCUMENT_ANNOTATIONS (view->document),
2290
annot, annot->contents);
2291
annot->changed = FALSE;
2295
show_annotation_windows (EvView *view,
2301
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
2303
annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
2305
for (l = annots; l && l->data; l = g_list_next (l)) {
2306
EvAnnotationMapping *annotation_mapping;
2307
EvAnnotation *annot;
2308
EvViewWindowChild *child;
2310
EvRectangle *doc_rect;
2311
GdkRectangle view_rect;
2313
annotation_mapping = (EvAnnotationMapping *)l->data;
2314
annot = annotation_mapping->annotation;
2316
if (!EV_IS_ANNOTATION_MARKUP (annot))
2319
window = g_object_get_data (G_OBJECT (annot), "popup");
2321
ev_view_window_child_move_with_parent (view, window);
2325
/* Look if we already have a popup for this annot */
2326
child = ev_view_find_window_child_for_annot (view, page, annot);
2327
window = child ? child->window : NULL;
2329
ev_annotation_window_set_annotation (EV_ANNOTATION_WINDOW (window), annot);
2330
g_object_set_data (G_OBJECT (annot), "popup", window);
2331
ev_view_window_child_move_with_parent (view, window);
2333
window = ev_annotation_window_new (annot, parent);
2334
g_signal_connect (window, "grab_focus",
2335
G_CALLBACK (annotation_window_grab_focus),
2337
g_signal_connect (window, "closed",
2338
G_CALLBACK (annotation_window_closed),
2340
g_signal_connect (window, "moved",
2341
G_CALLBACK (annotation_window_moved),
2343
g_object_set_data (G_OBJECT (annot), "popup", window);
2345
doc_rect = (EvRectangle *)ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window));
2346
doc_rect_to_view_rect (view, page, doc_rect, &view_rect);
2347
view_rect.x -= view->scroll_x;
2348
view_rect.y -= view->scroll_y;
2350
ev_view_window_child_put (view, window, page,
2351
view_rect.x, view_rect.y,
2352
doc_rect->x1, doc_rect->y1);
2354
g_object_weak_ref (G_OBJECT (annot),
2355
(GWeakNotify)ev_view_annotation_save,
2362
hide_annotation_windows (EvView *view,
2367
annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
2369
for (l = annots; l && l->data; l = g_list_next (l)) {
2370
EvAnnotationMapping *annotation_mapping;
2371
EvAnnotation *annot;
2374
annotation_mapping = (EvAnnotationMapping *)l->data;
2375
annot = annotation_mapping->annotation;
2377
if (!EV_IS_ANNOTATION_MARKUP (annot))
2380
window = g_object_get_data (G_OBJECT (annot), "popup");
2382
gtk_widget_hide (window);
2386
static EvAnnotation *
2387
ev_view_get_annotation_at_location (EvView *view,
2392
gint x_offset = 0, y_offset = 0;
2393
gint x_new = 0, y_new = 0;
2394
GList *annotations_mapping;
2396
if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
2399
x += view->scroll_x;
2400
y += view->scroll_y;
2402
find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
2407
if (get_doc_point_from_offset (view, page, x_offset,
2408
y_offset, &x_new, &y_new) == FALSE)
2411
annotations_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
2413
if (annotations_mapping)
2414
return ev_annotation_mapping_find (annotations_mapping, x_new, y_new);
2420
ev_view_handle_annotation (EvView *view,
2421
EvAnnotation *annot,
2425
if (EV_IS_ANNOTATION_MARKUP (annot)) {
2428
window = g_object_get_data (G_OBJECT (annot), "popup");
2430
EvViewWindowChild *child;
2432
child = ev_view_get_window_child (view, window);
2433
if (!child->visible) {
2434
child->visible = TRUE;
2435
ev_view_window_child_move (view, child, child->x, child->y);
2436
gtk_widget_show (window);
2060
2442
/*** GtkWidget implementation ***/
2555
2965
ev_link_mapping_get_area (link_mapping, link, &ev_rect);
2557
2967
doc_rect_to_view_rect (view, page, &ev_rect, area);
2558
area->y -= view->scroll_y ;
2968
area->y -= view->scroll_y;
2972
get_annot_area (EvView *view,
2975
EvAnnotation *annot,
2978
EvRectangle ev_rect;
2979
GList *annots_mapping;
2981
gint x_offset = 0, y_offset = 0;
2983
x += view->scroll_x;
2984
y += view->scroll_y;
2986
find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
2988
annots_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
2989
ev_annotation_mapping_get_area (annots_mapping, annot, &ev_rect);
2991
doc_rect_to_view_rect (view, page, &ev_rect, area);
2992
area->y -= view->scroll_y;
2561
2995
static gboolean
2562
ev_view_query_tooltip (GtkWidget *widget,
2565
gboolean keyboard_tip,
2566
GtkTooltip *tooltip)
2996
ev_view_query_tooltip (GtkWidget *widget,
2999
gboolean keyboard_tip,
3000
GtkTooltip *tooltip)
2568
EvView *view = EV_VIEW (widget);
3002
EvView *view = EV_VIEW (widget);
3004
EvAnnotation *annot;
3007
annot = ev_view_get_annotation_at_location (view, x, y);
3008
if (annot && annot->contents) {
3009
GdkRectangle annot_area;
3011
get_annot_area (view, x, y, annot, &annot_area);
3012
gtk_tooltip_set_text (tooltip, annot->contents);
3013
gtk_tooltip_set_tip_area (tooltip, &annot_area);
2572
3018
link = ev_view_get_link_at_location (view, x, y);