]> www.fi.muni.cz Git - evince.git/commitdiff
Add I-Beam support to EvView. Now we can see where we can select! Sweet!
authorJonathan Blandford <jrb@redhat.com>
Fri, 1 Jul 2005 04:11:08 +0000 (04:11 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Fri, 1 Jul 2005 04:11:08 +0000 (04:11 +0000)
Fri Jul  1 00:10:15 2005  Jonathan Blandford  <jrb@redhat.com>

        * backend/ev-selection.c: (ev_selection_get_selection_region),
        (ev_selection_get_selection_map):
        * backend/ev-selection.h:
        * pdf/ev-poppler.cc:
        * shell/ev-jobs.c: (ev_job_render_new), (ev_job_render_run):
        * shell/ev-jobs.h:
        * shell/ev-pixbuf-cache.c: (dispose_cache_job_info),
        (job_finished_cb), (copy_job_to_job_info), (add_job_if_needed),
        (ev_pixbuf_cache_get_text_mapping):
        * shell/ev-pixbuf-cache.h:
        * shell/ev-view.c: (location_in_text),
        (ev_view_motion_notify_event), (ev_view_set_cursor): Add I-Beam
        support to EvView.  Now we can see where we can select!  Sweet!

ChangeLog
backend/ev-selection.c
backend/ev-selection.h
pdf/ev-poppler.cc
shell/ev-jobs.c
shell/ev-jobs.h
shell/ev-pixbuf-cache.c
shell/ev-pixbuf-cache.h
shell/ev-view.c

index a63cb65e2a568c929bef9cbd8d9077fb3dac2d93..09c3de7e8497bc0ce0b3fea2ed65fa3c88105662 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Fri Jul  1 00:10:15 2005  Jonathan Blandford  <jrb@redhat.com>
+
+       * backend/ev-selection.c: (ev_selection_get_selection_region),
+       (ev_selection_get_selection_map):
+       * backend/ev-selection.h:
+       * pdf/ev-poppler.cc:
+       * shell/ev-jobs.c: (ev_job_render_new), (ev_job_render_run):
+       * shell/ev-jobs.h:
+       * shell/ev-pixbuf-cache.c: (dispose_cache_job_info),
+       (job_finished_cb), (copy_job_to_job_info), (add_job_if_needed),
+       (ev_pixbuf_cache_get_text_mapping):
+       * shell/ev-pixbuf-cache.h:
+       * shell/ev-view.c: (location_in_text),
+       (ev_view_motion_notify_event), (ev_view_set_cursor): Add I-Beam
+       support to EvView.  Now we can see where we can select!  Sweet!
+
 2005-06-30  Kristian Høgsberg  <krh@redhat.com>
 
        * shell/ev-view.c (ev_view_button_press_event): Fix
index fc8caa60523382f1751676664a082c09eeb9b091..074bbbcd2ab9620da17c1c60686773e8d0813d91 100644 (file)
@@ -70,11 +70,21 @@ ev_selection_render_selection (EvSelection      *selection,
                                 points, old_points);
 }
 
-GdkRegion *ev_selection_get_selection_region (EvSelection     *selection,
-                                             EvRenderContext *rc,
-                                             EvRectangle     *points)
+GdkRegion *
+ev_selection_get_selection_region (EvSelection     *selection,
+                                  EvRenderContext *rc,
+                                  EvRectangle     *points)
 {
        EvSelectionIface *iface = EV_SELECTION_GET_IFACE (selection);
 
        return iface->get_selection_region (selection, rc, points);
 }
+
+GdkRegion *
+ev_selection_get_selection_map (EvSelection     *selection,
+                               EvRenderContext *rc)
+{
+       EvSelectionIface *iface = EV_SELECTION_GET_IFACE (selection);
+
+       return iface->get_selection_map (selection, rc);
+}
index a07d6393c2377081a82ee87ea35339bad22c6027..8c5e224c5f128b32a8dd8cb1c8f2d84f8f3a6114 100644 (file)
@@ -48,6 +48,8 @@ struct _EvSelectionIface
                                              GdkPixbuf       **pixbuf,
                                              EvRectangle      *points,
                                              EvRectangle      *old_points);
+       GdkRegion * (* get_selection_map)    (EvSelection      *selection,
+                                             EvRenderContext  *rc);
        GdkRegion * (* get_selection_region) (EvSelection      *selection,
                                              EvRenderContext  *rc,
                                              EvRectangle      *points);
@@ -59,6 +61,8 @@ void       ev_selection_render_selection     (EvSelection      *selection,
                                              GdkPixbuf       **pixbuf,
                                              EvRectangle      *points,
                                              EvRectangle      *old_points);
+GdkRegion *ev_selection_get_selection_map    (EvSelection      *selection,
+                                             EvRenderContext  *rc);
 GdkRegion *ev_selection_get_selection_region (EvSelection      *selection,
                                              EvRenderContext  *rc,
                                              EvRectangle      *points);
index aa2ac90807ba7324dc4212c1c941277e44f14705..aa33b7f1ba39726b3522fcbd72da5ccbc8522254 100644 (file)
@@ -823,7 +823,6 @@ make_thumbnail_for_size (PdfDocument *pdf_document,
        PopplerPage *poppler_page;
        GdkPixbuf *pixbuf, *sub_pixbuf;
        int width, height;
-       int x_offset, y_offset;
        double scale;
        gdouble unscaled_width, unscaled_height;
 
@@ -1239,11 +1238,35 @@ pdf_selection_get_selection_region (EvSelection     *selection,
        return retval;
 }
 
+GdkRegion *
+pdf_selection_get_selection_map (EvSelection     *selection,
+                                EvRenderContext *rc)
+{
+       PdfDocument *pdf_document;
+       PopplerPage *poppler_page;
+       PopplerRectangle points;
+       GdkRegion *retval;
+
+       pdf_document = PDF_DOCUMENT (selection);
+       poppler_page = poppler_document_get_page (pdf_document->document,
+                                                 rc->page);
+       set_page_orientation (pdf_document, poppler_page);
+
+       points.x1 = 0.0;
+       points.y1 = 0.0;
+       poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
+       retval = poppler_page_get_selection_region (poppler_page, 1.0, &points);
+       g_object_unref (poppler_page);
+
+       return retval;
+}
+
 static void
 pdf_selection_iface_init (EvSelectionIface *iface)
 {
         iface->render_selection = pdf_selection_render_selection;
         iface->get_selection_region = pdf_selection_get_selection_region;
+        iface->get_selection_map = pdf_selection_get_selection_map;
 }
 
 PdfDocument *
index 3bc2fa883ccd260684a4a8ec201b29a7a81060dd..4cc0c258c017bf3d17a0b13ee261b3b01c233c1a 100644 (file)
@@ -227,6 +227,7 @@ ev_job_render_new (EvDocument      *document,
                   gint             height,
                   EvRectangle     *selection_points,
                   gboolean         include_links,
+                  gboolean         include_text,
                   gboolean         include_selection)
 {
        EvJobRender *job;
@@ -242,6 +243,7 @@ ev_job_render_new (EvDocument      *document,
        job->target_width = width;
        job->target_height = height;
        job->include_links = include_links;
+       job->include_text = include_text;
        job->include_selection = include_selection;
 
        if (include_selection)
@@ -281,6 +283,8 @@ ev_job_render_run (EvJobRender *job)
                job->pixbuf = ev_document_render_pixbuf (EV_JOB (job)->document, job->rc);
                if (job->include_links)
                        job->link_mapping = ev_document_get_links (EV_JOB (job)->document, job->rc->page);
+               if (job->include_text && EV_IS_SELECTION (EV_JOB (job)->document))
+                       job->text_mapping = ev_selection_get_selection_map (EV_SELECTION (EV_JOB (job)->document), job->rc);
                if (job->include_selection && EV_IS_SELECTION (EV_JOB (job)->document))
                        ev_selection_render_selection (EV_SELECTION (EV_JOB (job)->document),
                                                       job->rc,
index 9e4690939349bb4fa84eaec419673eaa8af5c312..263f9a15f4194320f6e175c3f57bc00577d1094f 100644 (file)
@@ -115,11 +115,13 @@ struct _EvJobRender
        GdkPixbuf *pixbuf;
 
        GList *link_mapping;
+       GdkRegion *text_mapping;
 
        GdkPixbuf *selection;
        EvRectangle selection_points;
 
        gint include_links : 1;
+       gint include_text : 1;
        gint include_selection : 1;
 };
 
@@ -182,6 +184,7 @@ EvJob          *ev_job_render_new         (EvDocument      *document,
                                           gint             height,
                                           EvRectangle     *selection_points,
                                           gboolean         include_links,
+                                          gboolean         include_text,
                                           gboolean         include_selection);
 void            ev_job_render_run         (EvJobRender     *thumbnail);
 
index 58ba3bff51be64306214b0576282e115caf3d8b4..a6127c3b6531e89af1f703026dd88a2f21718147 100644 (file)
@@ -9,6 +9,7 @@ typedef struct _CacheJobInfo
        GdkPixbuf *pixbuf;
        EvRenderContext *rc;
        GList *link_mapping;
+       GdkRegion *text_mapping;
 
        /* Selection info.  If the *_points structs are unset, we put -1 in x1.
         * selection_points are the coordinates encapsulated in selection.
@@ -144,6 +145,10 @@ dispose_cache_job_info (CacheJobInfo *job_info,
                ev_link_mapping_free (job_info->link_mapping);
                job_info->link_mapping = NULL;
        }
+       if (job_info->text_mapping) {
+               gdk_region_destroy (job_info->text_mapping);
+               job_info->text_mapping = NULL;
+       }
        if (job_info->selection) {
                g_object_unref (G_OBJECT (job_info->selection));
                job_info->selection = NULL;
@@ -210,6 +215,13 @@ job_finished_cb (EvJob         *job,
                        ev_link_mapping_free (job_info->link_mapping);
                job_info->link_mapping = job_render->link_mapping;
        }
+
+       if (job_render->text_mapping) {
+               if (job_info->text_mapping)
+                       gdk_region_destroy (job_info->text_mapping);
+               job_info->text_mapping = job_render->text_mapping;
+       }
+
        if (job_render->include_selection) {
                if (job_info->selection)
                        g_object_unref (job_info->selection);
@@ -403,6 +415,8 @@ copy_job_to_job_info (EvJobRender   *job_render,
        job_info->pixbuf = pixbuf;
        if (job_render->link_mapping)
                job_info->link_mapping = job_render->link_mapping;
+       if (job_render->text_mapping)
+               job_info->text_mapping = job_render->text_mapping;      
 }
 
 static CacheJobInfo *
@@ -468,6 +482,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
                   EvJobPriority  priority)
 {
        gboolean include_links = FALSE;
+       gboolean include_text = FALSE;
        gboolean include_selection = FALSE;
        int width, height;
 
@@ -495,6 +510,8 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
        /* Figure out what else we need for this job */
        if (job_info->link_mapping == NULL)
                include_links = TRUE;
+       if (job_info->text_mapping == NULL)
+               include_text = TRUE;
        if (new_selection_pixbuf_needed (pixbuf_cache, job_info, page, scale)) {
                include_selection = TRUE;
        }
@@ -504,6 +521,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
                                           width, height,
                                           &(job_info->new_points),
                                           include_links,
+                                          include_text,
                                           include_selection);
        ev_job_queue_add_job (job_info->job, priority);
        g_signal_connect (job_info->job, "finished", G_CALLBACK (job_finished_cb), pixbuf_cache);
@@ -660,11 +678,23 @@ clear_selection_if_needed (EvPixbufCache *pixbuf_cache,
        }
 }
 
-GList *
-ev_pixbuf_cach_get_text_mapping      (EvPixbufCache *pixbuf_cache,
+GdkRegion *
+ev_pixbuf_cache_get_text_mapping      (EvPixbufCache *pixbuf_cache,
                                      gint           page)
 {
-       return NULL;
+       CacheJobInfo *job_info;
+
+       job_info = find_job_cache (pixbuf_cache, page);
+       if (job_info == NULL)
+               return NULL;
+
+       /* We don't need to wait for the idle to handle the callback */
+       if (job_info->job &&
+           EV_JOB (job_info->job)->finished) {
+               copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
+       }
+       
+       return job_info->text_mapping;
 }
 
 GdkPixbuf *
index 19d0311f55bf2c2ede126efe50460891657dc141..3081c3b15de222303fe11bb0b4201d959185592d 100644 (file)
@@ -58,9 +58,9 @@ GdkPixbuf     *ev_pixbuf_cache_get_pixbuf           (EvPixbufCache *pixbuf_cache
                                                     gint           page);
 GList         *ev_pixbuf_cache_get_link_mapping     (EvPixbufCache *pixbuf_cache,
                                                     gint           page);
-/* Selection */
-GList         *ev_pixbuf_cach_get_text_mapping      (EvPixbufCache *pixbuf_cache,
+GdkRegion     *ev_pixbuf_cache_get_text_mapping     (EvPixbufCache *pixbuf_cache,
                                                     gint           page);
+/* Selection */
 GdkPixbuf     *ev_pixbuf_cache_get_selection_pixbuf (EvPixbufCache *pixbuf_cache,
                                                     gint           page,
                                                     gfloat         scale);
index 9164267203113fedf353f8cbea1cec23637dd430..476c791b0a93cde94367c4325a18bed6e5f37ddf 100644 (file)
@@ -78,6 +78,7 @@ static guint signals[N_SIGNALS];
 
 typedef enum {
        EV_VIEW_CURSOR_NORMAL,
+       EV_VIEW_CURSOR_IBEAM,
        EV_VIEW_CURSOR_LINK,
        EV_VIEW_CURSOR_WAIT,
        EV_VIEW_CURSOR_HIDDEN,
@@ -944,6 +945,28 @@ find_page_at_location (EvView  *view,
        *page = -1;
 }
 
+static gboolean
+location_in_text (EvView  *view,
+                 gdouble  x,
+                 gdouble  y)
+{
+       GdkRegion *region;
+       gint page = -1;
+       gint x_offset = 0, y_offset = 0;
+
+       find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+       if (page == -1)
+               return FALSE;
+       
+       region = ev_pixbuf_cache_get_text_mapping (view->pixbuf_cache, page);
+
+       if (region)
+               return gdk_region_point_in (region, x_offset / view->scale, y_offset / view->scale);
+       else
+               return FALSE;
+}
+
 /*** Hyperref ***/
 static EvLink *
 get_link_at_location (EvView  *view,
@@ -1420,11 +1443,13 @@ ev_view_motion_notify_event (GtkWidget      *widget,
                        ev_view_set_status (view, msg);
                        ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
                        g_free (msg);
+               } else if (location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y)) {
+                       ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
                } else {
                        ev_view_set_status (view, NULL);
-                       if (view->cursor == EV_VIEW_CURSOR_LINK) {
+                       if (view->cursor == EV_VIEW_CURSOR_LINK ||
+                           view->cursor == EV_VIEW_CURSOR_IBEAM)
                                ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
-                       }
                }
                return TRUE;
        }
@@ -3036,6 +3061,9 @@ ev_view_set_cursor (EvView *view, EvViewCursor new_cursor)
                case EV_VIEW_CURSOR_NORMAL:
                        gdk_window_set_cursor (widget->window, NULL);
                        break;
+               case EV_VIEW_CURSOR_IBEAM:
+                       cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
+                       break;
                case EV_VIEW_CURSOR_LINK:
                        cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
                        break;