~ubuntu-branches/ubuntu/precise/evince/precise-updates

« back to all changes in this revision

Viewing changes to libview/ev-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-06-02 10:30:12 UTC
  • mfrom: (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602103012-liwypsthciko6ae9
Tags: 2.27.1-0ubuntu1
* New upstream version:
  New Features and UI Improvements:
  - Use GtkPrintOperation when printing for the backends that
    support rendering into a cairo context 
  - Recover previous session when running evince after a crash
  - Preliminary annotations support
  - Rename Print Setup menu entry as Page Setup for consistency with
    the GTK+ dialog title 
  - Added F3 as a find-next accelerator key 
  - Support the free Gna! unrar tool in comics backend
  - Add evince-previewer as a separate applicaton that implements
    the printing preview 
  Bug fixes:
  - Fix handling of the tmp folder 
  - Abort dnd operations originated in the same Evince window  
  - Disable bouncing during scrolling 
  - Fix build without gconftool-2 
  - Fix documentation build 
  - Fix error handling of broken documents 
  - Fix several memory leaks in comics backend 
  - Escape URIs for display 
  - Resync with libegg to remove deprecated GTK+ symbols
  - Correct check for exit status of commands in comics backend
  - Add -no-undefined flag for Cygwin build 
  - Use g_file_make_symbolic_link to create symlinks 
  - Delete the temp symlink created when opening a copy
  - Don't redraw again when zoom is set more than once to the same
    scale factor 
  - Fix print preview of empty selection 
  - Don't prevent unmounting in case the initial cwd is on an external device 
  - Create and load the document based on the mime-type provided by
    nautilus instead of using our own documents factory.
  - Fix endianess issues in dvi and tiff backends 
  - Fix memory leak in tiff backend 
  - Fix path where accels file is saved 
  - Fix fading animations 
  - Translate the categories in the nautilus properties tab
* debian/control.in:
  - updated libpoppler and gtk requirements
* debian/patches/01_launchpad.patch:
  - new version update

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "ev-pixbuf-cache.h"
38
38
#include "ev-transition-animation.h"
39
39
#include "ev-view-marshal.h"
 
40
#include "ev-document-annotations.h"
 
41
#include "ev-annotation-window.h"
40
42
#include "ev-view.h"
41
43
#include "ev-view-accessible.h"
42
44
#include "ev-view-private.h"
148
150
                                                               gdouble            x,
149
151
                                                               gdouble            y);
150
152
 
 
153
/*** Annotations ***/
 
154
static EvAnnotation *ev_view_get_annotation_at_location      (EvView             *view,
 
155
                                                              gdouble             x,
 
156
                                                              gdouble             y);
 
157
static void          show_annotation_windows                 (EvView             *view,
 
158
                                                              gint                page);
 
159
static void          hide_annotation_windows                 (EvView             *view,
 
160
                                                              gint                page);
151
161
/*** GtkWidget implementation ***/
152
162
static void       ev_view_size_request_continuous_dual_page  (EvView             *view,
153
163
                                                              GtkRequisition     *requisition);
427
437
{
428
438
        gint current_page;
429
439
        gint best_current_page = -1;
 
440
        gint start = view->start_page;
 
441
        gint end = view->end_page;
430
442
        
431
443
        /* Presentation trumps all other modes */
432
444
        if (view->presentation) {
498
510
                ev_page_cache_set_current_page (view->page_cache, best_current_page);
499
511
        }
500
512
 
 
513
        if (start != view->start_page || end != view->end_page) {
 
514
                gint i;
 
515
 
 
516
                for (i = start; i < view->start_page; i++) {
 
517
                        hide_annotation_windows (view, i);
 
518
                }
 
519
 
 
520
                for (i = end; i > view->end_page; i--) {
 
521
                        hide_annotation_windows (view, i);
 
522
                }
 
523
        }
 
524
 
501
525
        ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
502
526
                                        view->start_page,
503
527
                                        view->end_page,
1487
1511
static void
1488
1512
ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
1489
1513
{
1490
 
        EvLink      *link;
1491
 
        EvFormField *field;
 
1514
        EvLink       *link;
 
1515
        EvFormField  *field;
 
1516
        EvAnnotation *annot = NULL;
1492
1517
 
1493
1518
        if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
1494
1519
                return;
1504
1529
                        ev_view_set_cursor (view, EV_VIEW_CURSOR_AUTOSCROLL);
1505
1530
                return;
1506
1531
        }
1507
 
        
 
1532
 
1508
1533
        link = ev_view_get_link_at_location (view, x, y);
1509
1534
        if (link) {
1510
 
                g_object_set (view, "has-tooltip", TRUE, NULL);
1511
1535
                ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1512
1536
        } else if ((field = ev_view_get_form_field_at_location (view, x, y))) {
1513
1537
                if (field->is_read_only) {
1520
1544
                } else {
1521
1545
                        ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1522
1546
                }
 
1547
        } else if ((annot = ev_view_get_annotation_at_location (view, x, y))) {
 
1548
                ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
1523
1549
        } else if (location_in_text (view, x + view->scroll_x, y + view->scroll_y)) {
1524
1550
                ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
1525
1551
        } else {
1529
1555
                    view->cursor == EV_VIEW_CURSOR_AUTOSCROLL)
1530
1556
                        ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
1531
1557
        }
 
1558
 
 
1559
        if (link || annot)
 
1560
                g_object_set (view, "has-tooltip", TRUE, NULL);
1532
1561
}
1533
1562
 
1534
1563
/*** Images ***/
2057
2086
        gtk_widget_grab_focus (field_widget);
2058
2087
}
2059
2088
 
 
2089
/* Annotations */
 
2090
static EvViewWindowChild *
 
2091
ev_view_get_window_child (EvView    *view,
 
2092
                          GtkWidget *window)
 
2093
{
 
2094
        GList *children = view->window_children;
 
2095
 
 
2096
        while (children) {
 
2097
                EvViewWindowChild *child;
 
2098
 
 
2099
                child = (EvViewWindowChild *)children->data;
 
2100
                children = children->next;
 
2101
 
 
2102
                if (child->window == window)
 
2103
                        return child;
 
2104
        }
 
2105
 
 
2106
        return NULL;
 
2107
}
 
2108
 
 
2109
static void
 
2110
ev_view_window_child_move (EvView            *view,
 
2111
                           EvViewWindowChild *child,
 
2112
                           gint               x,
 
2113
                           gint               y)
 
2114
{
 
2115
        child->x = x;
 
2116
        child->y = y;
 
2117
        gtk_window_move (GTK_WINDOW (child->window),
 
2118
                         MAX (child->parent_x, x),
 
2119
                         MAX (child->parent_y, y));
 
2120
}
 
2121
 
 
2122
static void
 
2123
ev_view_window_child_move_with_parent (EvView    *view,
 
2124
                                       GtkWidget *window)
 
2125
{
 
2126
        EvViewWindowChild *child;
 
2127
        gint               root_x, root_y;
 
2128
 
 
2129
        child = ev_view_get_window_child (view, window);
 
2130
        gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
 
2131
                               &root_x, &root_y);
 
2132
        if (root_x != child->parent_x || root_y != child->parent_y) {
 
2133
                gint dest_x, dest_y;
 
2134
 
 
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);
 
2140
        }
 
2141
 
 
2142
        if (child->visible && !GTK_WIDGET_VISIBLE (window))
 
2143
                gtk_widget_show (window);
 
2144
}
 
2145
 
 
2146
static void
 
2147
ev_view_window_child_put (EvView    *view,
 
2148
                          GtkWidget *window,
 
2149
                          guint      page,
 
2150
                          gint       x,
 
2151
                          gint       y,
 
2152
                          gdouble    orig_x,
 
2153
                          gdouble    orig_y)
 
2154
{
 
2155
        EvViewWindowChild *child;
 
2156
        gint               root_x, root_y;
 
2157
 
 
2158
        gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
 
2159
                               &root_x, &root_y);
 
2160
 
 
2161
        child = g_new0 (EvViewWindowChild, 1);
 
2162
        child->window = window;
 
2163
        child->page = page;
 
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);
 
2170
 
 
2171
        if (child->visible)
 
2172
                gtk_widget_show (window);
 
2173
        else
 
2174
                gtk_widget_hide (window);
 
2175
 
 
2176
        view->window_children = g_list_append (view->window_children, child);
 
2177
}
 
2178
 
 
2179
static EvViewWindowChild *
 
2180
ev_view_find_window_child_for_annot (EvView       *view,
 
2181
                                     guint         page,
 
2182
                                     EvAnnotation *annot)
 
2183
{
 
2184
        GList *children = view->window_children;
 
2185
 
 
2186
        while (children) {
 
2187
                EvViewWindowChild *child;
 
2188
                EvAnnotation      *wannot;
 
2189
 
 
2190
                child = (EvViewWindowChild *)children->data;
 
2191
                children = children->next;
 
2192
 
 
2193
                if (child->page != page)
 
2194
                        continue;
 
2195
 
 
2196
                wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
 
2197
                if (wannot == annot || strcmp (wannot->name, annot->name) == 0)
 
2198
                        return child;
 
2199
        }
 
2200
 
 
2201
        return NULL;
 
2202
}
 
2203
 
 
2204
static void
 
2205
ev_view_window_children_free (EvView *view)
 
2206
{
 
2207
        GList *l;
 
2208
 
 
2209
        if (!view->window_children)
 
2210
                return;
 
2211
 
 
2212
        for (l = view->window_children; l && l->data; l = g_list_next (l)) {
 
2213
                EvViewWindowChild *child;
 
2214
 
 
2215
                child = (EvViewWindowChild *)l->data;
 
2216
                gtk_widget_destroy (GTK_WIDGET (child->window));
 
2217
                g_free (child);
 
2218
        }
 
2219
        g_list_free (view->window_children);
 
2220
        view->window_children = NULL;
 
2221
        view->window_child_focus = NULL;
 
2222
}
 
2223
 
 
2224
static void
 
2225
annotation_window_grab_focus (GtkWidget *widget,
 
2226
                              EvView    *view)
 
2227
{
 
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);
 
2231
}
 
2232
 
 
2233
static void
 
2234
annotation_window_closed (EvAnnotationWindow *window,
 
2235
                          EvView             *view)
 
2236
{
 
2237
        EvViewWindowChild *child;
 
2238
 
 
2239
        child = ev_view_get_window_child (view, GTK_WIDGET (window));
 
2240
        child->visible = FALSE;
 
2241
}
 
2242
 
 
2243
static void
 
2244
annotation_window_moved (EvAnnotationWindow *window,
 
2245
                         gint                x,
 
2246
                         gint                y,
 
2247
                         EvView             *view)
 
2248
{
 
2249
        EvViewWindowChild *child;
 
2250
        GdkRectangle       page_area;
 
2251
        GtkBorder          border;
 
2252
        GdkRectangle       view_rect;
 
2253
        EvRectangle        doc_rect;
 
2254
        gint               width, height;
 
2255
 
 
2256
        child = ev_view_get_window_child (view, GTK_WIDGET (window));
 
2257
        if (child->x == x && child->y == y)
 
2258
                return;
 
2259
 
 
2260
        child->moved = TRUE;
 
2261
        child->x = x;
 
2262
        child->y = y;
 
2263
 
 
2264
        /* Window has been moved by the user,
 
2265
         * we have to set a new origin in doc coords
 
2266
         */
 
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;
 
2272
 
 
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;
 
2277
}
 
2278
 
 
2279
static void
 
2280
ev_view_annotation_save (EvView       *view,
 
2281
                         EvAnnotation *annot)
 
2282
{
 
2283
        if (!view->document)
 
2284
                return;
 
2285
 
 
2286
        if (!annot->changed)
 
2287
                return;
 
2288
 
 
2289
        ev_document_annotations_annotation_set_contents (EV_DOCUMENT_ANNOTATIONS (view->document),
 
2290
                                                         annot, annot->contents);
 
2291
        annot->changed = FALSE;
 
2292
}
 
2293
 
 
2294
static void
 
2295
show_annotation_windows (EvView *view,
 
2296
                         gint    page)
 
2297
{
 
2298
        GList     *annots, *l;
 
2299
        GtkWindow *parent;
 
2300
 
 
2301
        parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
 
2302
 
 
2303
        annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
 
2304
 
 
2305
        for (l = annots; l && l->data; l = g_list_next (l)) {
 
2306
                EvAnnotationMapping *annotation_mapping;
 
2307
                EvAnnotation        *annot;
 
2308
                EvViewWindowChild   *child;
 
2309
                GtkWidget           *window;
 
2310
                EvRectangle         *doc_rect;
 
2311
                GdkRectangle         view_rect;
 
2312
 
 
2313
                annotation_mapping = (EvAnnotationMapping *)l->data;
 
2314
                annot = annotation_mapping->annotation;
 
2315
 
 
2316
                if (!EV_IS_ANNOTATION_MARKUP (annot))
 
2317
                        continue;
 
2318
 
 
2319
                window = g_object_get_data (G_OBJECT (annot), "popup");
 
2320
                if (window) {
 
2321
                        ev_view_window_child_move_with_parent (view, window);
 
2322
                        continue;
 
2323
                }
 
2324
 
 
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;
 
2328
                if (window) {
 
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);
 
2332
                } else {
 
2333
                        window = ev_annotation_window_new (annot, parent);
 
2334
                        g_signal_connect (window, "grab_focus",
 
2335
                                          G_CALLBACK (annotation_window_grab_focus),
 
2336
                                          view);
 
2337
                        g_signal_connect (window, "closed",
 
2338
                                          G_CALLBACK (annotation_window_closed),
 
2339
                                          view);
 
2340
                        g_signal_connect (window, "moved",
 
2341
                                          G_CALLBACK (annotation_window_moved),
 
2342
                                          view);
 
2343
                        g_object_set_data (G_OBJECT (annot), "popup", window);
 
2344
 
 
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;
 
2349
 
 
2350
                        ev_view_window_child_put (view, window, page,
 
2351
                                                  view_rect.x, view_rect.y,
 
2352
                                                  doc_rect->x1, doc_rect->y1);
 
2353
 
 
2354
                        g_object_weak_ref (G_OBJECT (annot),
 
2355
                                           (GWeakNotify)ev_view_annotation_save,
 
2356
                                           view);
 
2357
                }
 
2358
        }
 
2359
}
 
2360
 
 
2361
static void
 
2362
hide_annotation_windows (EvView *view,
 
2363
                         gint    page)
 
2364
{
 
2365
        GList *annots, *l;
 
2366
 
 
2367
        annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
 
2368
 
 
2369
        for (l = annots; l && l->data; l = g_list_next (l)) {
 
2370
                EvAnnotationMapping *annotation_mapping;
 
2371
                EvAnnotation        *annot;
 
2372
                GtkWidget           *window;
 
2373
 
 
2374
                annotation_mapping = (EvAnnotationMapping *)l->data;
 
2375
                annot = annotation_mapping->annotation;
 
2376
 
 
2377
                if (!EV_IS_ANNOTATION_MARKUP (annot))
 
2378
                        continue;
 
2379
 
 
2380
                window = g_object_get_data (G_OBJECT (annot), "popup");
 
2381
                if (window)
 
2382
                        gtk_widget_hide (window);
 
2383
        }
 
2384
}
 
2385
 
 
2386
static EvAnnotation *
 
2387
ev_view_get_annotation_at_location (EvView  *view,
 
2388
                                    gdouble  x,
 
2389
                                    gdouble  y)
 
2390
{
 
2391
        gint page = -1;
 
2392
        gint x_offset = 0, y_offset = 0;
 
2393
        gint x_new = 0, y_new = 0;
 
2394
        GList *annotations_mapping;
 
2395
 
 
2396
        if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
 
2397
                return NULL;
 
2398
 
 
2399
        x += view->scroll_x;
 
2400
        y += view->scroll_y;
 
2401
 
 
2402
        find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
 
2403
 
 
2404
        if (page == -1)
 
2405
                return NULL;
 
2406
 
 
2407
        if (get_doc_point_from_offset (view, page, x_offset,
 
2408
                                       y_offset, &x_new, &y_new) == FALSE)
 
2409
                return NULL;
 
2410
 
 
2411
        annotations_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
 
2412
 
 
2413
        if (annotations_mapping)
 
2414
                return ev_annotation_mapping_find (annotations_mapping, x_new, y_new);
 
2415
        else
 
2416
                return NULL;
 
2417
}
 
2418
 
 
2419
static void
 
2420
ev_view_handle_annotation (EvView       *view,
 
2421
                           EvAnnotation *annot,
 
2422
                           gdouble       x,
 
2423
                           gdouble       y)
 
2424
{
 
2425
        if (EV_IS_ANNOTATION_MARKUP (annot)) {
 
2426
                GtkWidget *window;
 
2427
 
 
2428
                window = g_object_get_data (G_OBJECT (annot), "popup");
 
2429
                if (window) {
 
2430
                        EvViewWindowChild *child;
 
2431
 
 
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);
 
2437
                        }
 
2438
                }
 
2439
        }
 
2440
}
 
2441
 
2060
2442
/*** GtkWidget implementation ***/
2061
2443
 
2062
2444
static void
2213
2595
{
2214
2596
        EvView *view = EV_VIEW (widget);
2215
2597
        GList  *children, *l;
 
2598
        gint    root_x, root_y;
2216
2599
 
2217
2600
        GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
2218
2601
        
2219
2602
        if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
2220
2603
            view->sizing_mode == EV_SIZING_BEST_FIT) {
2221
 
 
2222
2604
                g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0);
2223
 
 
2224
2605
                ev_view_size_request (widget, &widget->requisition);
2225
2606
        }
2226
2607
        
2271
2652
                }
2272
2653
        }
2273
2654
        g_list_free (children);
 
2655
 
 
2656
        if (view->window_children)
 
2657
                gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
 
2658
                                       &root_x, &root_y);
 
2659
 
 
2660
        for (l = view->window_children; l && l->data; l = g_list_next (l)) {
 
2661
                EvViewWindowChild *child;
 
2662
                EvRectangle        doc_rect;
 
2663
                GdkRectangle       view_rect;
 
2664
 
 
2665
                child = (EvViewWindowChild *)l->data;
 
2666
 
 
2667
                doc_rect = *ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window));
 
2668
                if (child->moved) {
 
2669
                        doc_rect.x1 = child->orig_x;
 
2670
                        doc_rect.y1 = child->orig_y;
 
2671
                }
 
2672
                doc_rect_to_view_rect (view, child->page, &doc_rect, &view_rect);
 
2673
                view_rect.x -= view->scroll_x;
 
2674
                view_rect.y -= view->scroll_y;
 
2675
 
 
2676
                if (view_rect.x != child->orig_x || view_rect.y != child->orig_y) {
 
2677
                        child->parent_x = root_x;
 
2678
                        child->parent_y = root_y;
 
2679
                        ev_view_window_child_move (view, child, view_rect.x + root_x, view_rect.y + root_y);
 
2680
                }
 
2681
        }
2274
2682
}
2275
2683
 
2276
2684
static void
2490
2898
 
2491
2899
                if (page_ready && view->find_pages && view->highlight_find_results)
2492
2900
                        highlight_find_results (view, i);
 
2901
                if (page_ready && EV_IS_DOCUMENT_ANNOTATIONS (view->document))
 
2902
                        show_annotation_windows (view, i);
2493
2903
        }
2494
2904
 
2495
2905
        cairo_destroy (cr);
2555
2965
        ev_link_mapping_get_area (link_mapping, link, &ev_rect);
2556
2966
 
2557
2967
        doc_rect_to_view_rect (view, page, &ev_rect, area);
2558
 
        area->y -= view->scroll_y ;
 
2968
        area->y -= view->scroll_y;
 
2969
}
 
2970
 
 
2971
static void
 
2972
get_annot_area (EvView       *view,
 
2973
               gint          x,
 
2974
               gint          y,
 
2975
               EvAnnotation *annot,
 
2976
               GdkRectangle *area)
 
2977
{
 
2978
        EvRectangle  ev_rect;
 
2979
        GList       *annots_mapping;
 
2980
        gint         page;
 
2981
        gint         x_offset = 0, y_offset = 0;
 
2982
 
 
2983
        x += view->scroll_x;
 
2984
        y += view->scroll_y;
 
2985
 
 
2986
        find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
 
2987
 
 
2988
        annots_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
 
2989
        ev_annotation_mapping_get_area (annots_mapping, annot, &ev_rect);
 
2990
 
 
2991
        doc_rect_to_view_rect (view, page, &ev_rect, area);
 
2992
        area->y -= view->scroll_y;
2559
2993
}
2560
2994
 
2561
2995
static gboolean
2562
 
ev_view_query_tooltip (GtkWidget         *widget,
2563
 
                       gint               x,
2564
 
                       gint               y,
2565
 
                       gboolean           keyboard_tip,
2566
 
                       GtkTooltip        *tooltip)
 
2996
ev_view_query_tooltip (GtkWidget  *widget,
 
2997
                       gint        x,
 
2998
                       gint        y,
 
2999
                       gboolean    keyboard_tip,
 
3000
                       GtkTooltip *tooltip)
2567
3001
{
2568
 
        EvView *view = EV_VIEW (widget);
2569
 
        EvLink *link;
2570
 
        gchar  *text;
 
3002
        EvView       *view = EV_VIEW (widget);
 
3003
        EvLink       *link;
 
3004
        EvAnnotation *annot;
 
3005
        gchar        *text;
 
3006
 
 
3007
        annot = ev_view_get_annotation_at_location (view, x, y);
 
3008
        if (annot && annot->contents) {
 
3009
                GdkRectangle annot_area;
 
3010
 
 
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);
 
3014
 
 
3015
                return TRUE;
 
3016
        }
2571
3017
 
2572
3018
        link = ev_view_get_link_at_location (view, x, y);
2573
3019
        if (!link)
2624
3070
        if (!GTK_WIDGET_HAS_FOCUS (widget)) {
2625
3071
                gtk_widget_grab_focus (widget);
2626
3072
        }
 
3073
 
 
3074
        if (view->window_child_focus) {
 
3075
                EvAnnotationWindow *window;
 
3076
                EvAnnotation       *annot;
 
3077
 
 
3078
                window = EV_ANNOTATION_WINDOW (view->window_child_focus->window);
 
3079
                annot = ev_annotation_window_get_annotation (window);
 
3080
                ev_annotation_window_ungrab_focus (window);
 
3081
                ev_view_annotation_save (view, annot);
 
3082
                view->window_child_focus = NULL;
 
3083
        }
2627
3084
        
2628
3085
        view->pressed_button = event->button;
2629
3086
        view->selection_info.in_drag = FALSE;
2634
3091
        switch (event->button) {
2635
3092
                case 1: {
2636
3093
                        EvImage *image;
 
3094
                        EvAnnotation *annot;
2637
3095
                        EvFormField *field;
2638
3096
 
2639
3097
                        if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
2648
3106
                                }
2649
3107
 
2650
3108
                                gtk_widget_queue_draw (widget);
 
3109
                        } else if ((annot = ev_view_get_annotation_at_location (view, event->x, event->y))) {
 
3110
                                ev_view_handle_annotation (view, annot, event->x, event->y);
2651
3111
                        } else if ((field = ev_view_get_form_field_at_location (view, event->x, event->y))) {
2652
3112
                                ev_view_remove_all (view);
2653
3113
                                ev_view_handle_form_field (view, field, event->x, event->y);
2859
3319
        oldhadjustment = gtk_adjustment_get_value (view->hadjustment);
2860
3320
        oldvadjustment = gtk_adjustment_get_value (view->vadjustment);
2861
3321
 
2862
 
        if (((oldhadjustment + dhadj_value) > (view->hadjustment->upper - view->hadjustment->page_size)) ||
 
3322
     /* When we reach the edges, we need either to absorb some momentum and bounce by
 
3323
      * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */   
 
3324
     if (((oldhadjustment + dhadj_value) > (view->hadjustment->upper - view->hadjustment->page_size)) ||
2863
3325
           ((oldhadjustment + dhadj_value) < 0))
2864
 
                view->drag_info.momentum.x *= -0.5; /* 0.5 rather than 1 means the edges absorb some momentum */
 
3326
                view->drag_info.momentum.x = 0;
2865
3327
        if (((oldvadjustment + dvadj_value) > (view->vadjustment->upper - view->vadjustment->page_size)) ||
2866
3328
           ((oldvadjustment + dvadj_value) < 0))
2867
 
                view->drag_info.momentum.y *= -0.5;
 
3329
                view->drag_info.momentum.y = 0;
2868
3330
 
2869
3331
        gtk_adjustment_set_value (view->hadjustment,
2870
3332
                                MIN (oldhadjustment + dhadj_value,
3337
3799
 
3338
3800
        if (!view->document)
3339
3801
                return FALSE;
3340
 
        
 
3802
 
 
3803
        if (!GTK_WIDGET_HAS_FOCUS (widget)) {
 
3804
                /* Forward key events to current focused window child */
 
3805
                if (view->window_child_focus) {
 
3806
                        GdkEventKey *new_event;
 
3807
                        gboolean     handled;
 
3808
 
 
3809
                        new_event = (GdkEventKey *) gdk_event_copy ((GdkEvent *)event);
 
3810
                        g_object_unref (new_event->window);
 
3811
                        new_event->window = g_object_ref (view->window_child_focus->window->window);
 
3812
                        gtk_widget_realize (view->window_child_focus->window);
 
3813
                        handled = gtk_widget_event (view->window_child_focus->window, (GdkEvent *)new_event);
 
3814
                        gdk_event_free ((GdkEvent *)new_event);
 
3815
 
 
3816
                        return handled;
 
3817
                }
 
3818
 
 
3819
                return FALSE;
 
3820
        }
 
3821
 
3341
3822
        if (!view->presentation ||
3342
3823
            view->presentation_state == EV_PRESENTATION_END)
3343
3824
                return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3753
4234
                view->goto_entry = NULL;
3754
4235
        }
3755
4236
 
 
4237
        ev_view_window_children_free (view);
 
4238
 
3756
4239
        if (view->selection_scroll_id) {
3757
4240
            g_source_remove (view->selection_scroll_id);
3758
4241
            view->selection_scroll_id = 0;
4068
4551
{
4069
4552
        GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
4070
4553
 
 
4554
        view->start_page = -1;
 
4555
        view->end_page = -1;
4071
4556
        view->spacing = 5;
4072
4557
        view->scale = 1.0;
4073
4558
        view->current_page = 0;
4246
4731
                gtk_layout_move (GTK_LAYOUT (view), child, child_x + dx, child_y + dy);
4247
4732
        }
4248
4733
        g_list_free (children);
 
4734
 
 
4735
        for (l = view->window_children; l && l->data; l = g_list_next (l)) {
 
4736
                EvViewWindowChild *child;
 
4737
 
 
4738
                child = (EvViewWindowChild *)l->data;
 
4739
 
 
4740
                ev_view_window_child_move (view, child, child->x + dx, child->y + dy);
 
4741
        }
4249
4742
        
4250
4743
        if (view->pending_resize)
4251
4744
                gtk_widget_queue_draw (GTK_WIDGET (view));
4399
4892
                        setup_caches (view);
4400
4893
                }
4401
4894
 
 
4895
                view_update_range_and_current_page (view);
 
4896
 
4402
4897
                gtk_widget_queue_resize (GTK_WIDGET (view));
4403
4898
        }
4404
4899
}
4441
4936
                       view->sizing_mode == EV_SIZING_FREE ? view->min_scale : 0,
4442
4937
                       view->max_scale);
4443
4938
 
 
4939
        if (scale == view->scale)
 
4940
                return;
 
4941
 
4444
4942
        if (ABS (view->scale - scale) < EPSILON)
4445
4943
                return;
4446
4944
 
5834
6332
        }
5835
6333
}
5836
6334
                
5837
 
/*** Enum description for usage in signal ***/
5838
 
 
5839
 
void
5840
 
ev_view_update_view_size (EvView *view, GtkScrolledWindow * scrolled_window)
5841
 
{
5842
 
        int width, height;
5843
 
        GtkRequisition vsb_requisition;
5844
 
        GtkRequisition hsb_requisition;
5845
 
        int scrollbar_spacing;
5846
 
        
5847
 
        /* Calculate the width available for the content */ 
5848
 
        width  = GTK_WIDGET (scrolled_window)->allocation.width;
5849
 
        height = GTK_WIDGET (scrolled_window)->allocation.height;
5850
 
 
5851
 
        if (gtk_scrolled_window_get_shadow_type (scrolled_window) == GTK_SHADOW_IN 
5852
 
            && view) {
5853
 
                width -=  2 * GTK_WIDGET(view)->style->xthickness;
5854
 
                height -= 2 * GTK_WIDGET(view)->style->ythickness;
5855
 
        }
5856
 
 
5857
 
        gtk_widget_size_request (scrolled_window->vscrollbar, &vsb_requisition);
5858
 
        gtk_widget_size_request (scrolled_window->hscrollbar, &hsb_requisition);
5859
 
        gtk_widget_style_get (GTK_WIDGET (scrolled_window), 
5860
 
                              "scrollbar_spacing", 
5861
 
                              &scrollbar_spacing, 
5862
 
                              NULL);
5863
 
        
5864
 
        if (EV_IS_VIEW(view)) {
5865
 
                ev_view_set_zoom_for_size (EV_VIEW (view),
5866
 
                                           MAX (1, width),
5867
 
                                           MAX (1, height),
5868
 
                                           vsb_requisition.width + scrollbar_spacing,
5869
 
                                           hsb_requisition.height + scrollbar_spacing);
5870
 
        }
5871
 
}