Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2007-08-31 20:37:24 (GMT)
committer Carlos Garcia Campos <carlosgc@src.gnome.org>2007-08-31 20:37:24 (GMT)
commit982600bbceb76a22d5c7b3e0cbe6e20421105ad6 (patch)
tree1d233d670a447357a7d41044660881e4475f2658 /shell
parentf76fa765536d1f5875699606d0a78c6f132fce1e (diff)
Add support for double and triple click selections.
2007-08-31 Carlos Garcia Campos <carlosgc@gnome.org> * backend/dvi/dvi-document.c: (dvi_document_document_iface_init): * backend/impress/impress-document.c: (impress_document_document_iface_init): * backend/ps/ps-document.c: (ps_document_document_iface_init): * backend/djvu/djvu-document.c: (djvu_document_document_iface_init), (djvu_selection_get_selected_text), (djvu_selection_iface_init): * backend/tiff/tiff-document.c: (tiff_document_document_iface_init): * backend/pixbuf/pixbuf-document.c: (pixbuf_document_document_iface_init): * backend/comics/comics-document.c: (comics_document_document_iface_init): * backend/pdf/ev-poppler.cc: (pdf_document_document_iface_init), (pdf_selection_render_selection), (pdf_selection_get_selected_text), (pdf_selection_get_selection_region), (pdf_selection_get_selection_map), (pdf_selection_iface_init): * libdocument/ev-selection.[ch]: (ev_selection_get_selected_text), (ev_selection_get_selection_region), (ev_selection_get_selection_map): * libdocument/ev-document.[ch]: * shell/ev-pixbuf-cache.[ch]: (add_job), (ev_pixbuf_cache_get_selection_surface), (update_job_selection): * shell/ev-view-private.h: * shell/ev-jobs.[ch]: (ev_job_render_new), (ev_job_render_new), (ev_job_render_run): * shell/ev-window.c: (ev_window_setup_action_sensitivity): * shell/ev-view.c: (start_selection_for_event), (ev_view_button_press_event), (ev_view_drag_data_get), (ev_view_drag_data_received), (ev_view_button_release_event), (compute_new_selection_text), (compute_selections), (ev_view_select_all), (get_selected_text), (ev_view_copy), (ev_view_primary_get_cb): Add support for double and triple click selections. svn path=/trunk/; revision=2648
Diffstat (limited to 'shell')
-rw-r--r--shell/ev-jobs.c5
-rw-r--r--shell/ev-jobs.h3
-rw-r--r--shell/ev-pixbuf-cache.c12
-rw-r--r--shell/ev-pixbuf-cache.h2
-rw-r--r--shell/ev-view-private.h2
-rw-r--r--shell/ev-view.c116
-rw-r--r--shell/ev-window.c2
7 files changed, 99 insertions, 43 deletions
diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c
index 6934f60..99bfc87 100644
--- a/shell/ev-jobs.c
+++ b/shell/ev-jobs.c
@@ -8,7 +8,6 @@
#include "ev-document-misc.h"
#include "ev-file-helpers.h"
#include "ev-document-fonts.h"
-#include "ev-selection.h"
#include "ev-async-renderer.h"
#include <glib/gstdio.h>
@@ -276,6 +275,7 @@ ev_job_render_new (EvDocument *document,
gint width,
gint height,
EvRectangle *selection_points,
+ EvSelectionStyle selection_style,
GdkColor *text,
GdkColor *base,
gboolean include_forms,
@@ -296,6 +296,7 @@ ev_job_render_new (EvDocument *document,
job->rc = g_object_ref (rc);
job->target_width = width;
job->target_height = height;
+ job->selection_style = selection_style;
job->text = *text;
job->base = *base;
job->include_forms = include_forms;
@@ -371,10 +372,12 @@ ev_job_render_run (EvJobRender *job)
&(job->selection),
&(job->selection_points),
NULL,
+ job->selection_style,
&(job->text), &(job->base));
job->selection_region =
ev_selection_get_selection_region (EV_SELECTION (EV_JOB (job)->document),
job->rc,
+ job->selection_style,
&(job->selection_points));
}
diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h
index b15f260..6d7e95b 100644
--- a/shell/ev-jobs.h
+++ b/shell/ev-jobs.h
@@ -24,6 +24,7 @@
#include "ev-document.h"
#include "ev-window.h"
#include "ev-file-exporter.h"
+#include "ev-selection.h"
G_BEGIN_DECLS
@@ -133,6 +134,7 @@ struct _EvJobRender
cairo_surface_t *selection;
GdkRegion *selection_region;
EvRectangle selection_points;
+ EvSelectionStyle selection_style;
GdkColor base;
GdkColor text;
@@ -229,6 +231,7 @@ EvJob *ev_job_render_new (EvDocument *document,
gint width,
gint height,
EvRectangle *selection_points,
+ EvSelectionStyle selection_style,
GdkColor *text,
GdkColor *base,
gboolean include_forms,
diff --git a/shell/ev-pixbuf-cache.c b/shell/ev-pixbuf-cache.c
index 951decb..4605491 100644
--- a/shell/ev-pixbuf-cache.c
+++ b/shell/ev-pixbuf-cache.c
@@ -1,7 +1,6 @@
#include "ev-pixbuf-cache.h"
#include "ev-job-queue.h"
#include "ev-page-cache.h"
-#include "ev-selection.h"
#include "ev-document-images.h"
#include "ev-document-forms.h"
#include "ev-image.h"
@@ -26,9 +25,10 @@ typedef struct _CacheJobInfo
/* Selection data.
* Selection_points are the coordinates encapsulated in selection.
* target_points is the target selection size. */
- EvRectangle selection_points;
- EvRectangle target_points;
- gboolean points_set;
+ EvRectangle selection_points;
+ EvRectangle target_points;
+ EvSelectionStyle selection_style;
+ gboolean points_set;
cairo_surface_t *selection;
GdkRegion *selection_region;
@@ -646,6 +646,7 @@ add_job (EvPixbufCache *pixbuf_cache,
job_info->rc,
width, height,
&(job_info->target_points),
+ job_info->selection_style,
text, base,
include_forms,
include_links,
@@ -1021,6 +1022,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
job_info->selection_region =
ev_selection_get_selection_region (EV_SELECTION (pixbuf_cache->document),
job_info->rc,
+ job_info->selection_style,
&(job_info->target_points));
gtk_widget_ensure_style (pixbuf_cache->view);
@@ -1031,6 +1033,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
job_info->rc, &(job_info->selection),
&(job_info->target_points),
old_points,
+ job_info->selection_style,
text, base);
job_info->selection_points = job_info->target_points;
ev_document_doc_mutex_unlock ();
@@ -1046,6 +1049,7 @@ update_job_selection (CacheJobInfo *job_info,
{
job_info->points_set = TRUE;
job_info->target_points = selection->rect;
+ job_info->selection_style = selection->style;
}
static void
diff --git a/shell/ev-pixbuf-cache.h b/shell/ev-pixbuf-cache.h
index d2116cd..ed1c1ec 100644
--- a/shell/ev-pixbuf-cache.h
+++ b/shell/ev-pixbuf-cache.h
@@ -26,6 +26,7 @@
#include <gtk/gtkwidget.h>
#include "ev-document.h"
+#include "ev-selection.h"
#include "ev-job-queue.h"
G_BEGIN_DECLS
@@ -43,6 +44,7 @@ typedef struct {
int page;
EvRectangle rect;
GdkRegion *covered_region;
+ EvSelectionStyle style;
} EvViewSelection;
typedef struct _EvPixbufCache EvPixbufCache;
diff --git a/shell/ev-view-private.h b/shell/ev-view-private.h
index d1edfa6..e839a31 100644
--- a/shell/ev-view-private.h
+++ b/shell/ev-view-private.h
@@ -26,6 +26,7 @@
#include "ev-page-cache.h"
#include "ev-image.h"
#include "ev-form-field.h"
+#include "ev-selection.h"
/* Information for middle clicking and moving around the doc */
typedef struct {
@@ -41,6 +42,7 @@ typedef struct {
GdkPoint start;
gboolean in_selection;
GList *selections;
+ EvSelectionStyle style;
} SelectionInfo;
/* Information for handling images DND */
diff --git a/shell/ev-view.c b/shell/ev-view.c
index b3bd531..cbdffd8 100644
--- a/shell/ev-view.c
+++ b/shell/ev-view.c
@@ -32,7 +32,6 @@
#include "ev-view.h"
#include "ev-view-private.h"
#include "ev-utils.h"
-#include "ev-selection.h"
#include "ev-document-links.h"
#include "ev-document-images.h"
#include "ev-document-find.h"
@@ -315,6 +314,7 @@ static void jump_to_find_page (EvView
/*** Selection ***/
static void compute_selections (EvView *view,
+ EvSelectionStyle style,
GdkPoint *start,
GdkPoint *stop);
static void clear_selection (EvView *view);
@@ -2594,6 +2594,32 @@ ev_view_query_tooltip (GtkWidget *widget,
}
#endif /* GTK_CHECK_VERSION (2, 11, 7) */
+static void
+start_selection_for_event (EvView *view,
+ GdkEventButton *event)
+{
+ EvSelectionStyle style;
+
+ clear_selection (view);
+
+ view->selection_info.start.x = event->x + view->scroll_x;
+ view->selection_info.start.y = event->y + view->scroll_y;
+
+ switch (event->type) {
+ case GDK_2BUTTON_PRESS:
+ style = EV_SELECTION_STYLE_WORD;
+ break;
+ case GDK_3BUTTON_PRESS:
+ style = EV_SELECTION_STYLE_LINE;
+ break;
+ default:
+ style = EV_SELECTION_STYLE_GLYPH;
+ break;
+ }
+
+ view->selection_info.style = style;
+}
+
static gboolean
ev_view_button_press_event (GtkWidget *widget,
GdkEventButton *event)
@@ -2615,18 +2641,17 @@ ev_view_button_press_event (GtkWidget *widget,
EvImage *image;
EvFormField *field;
- if (view->selection_info.selections) {
- if (location_in_selected_text (view,
+ if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
+ if (event->type == GDK_3BUTTON_PRESS) {
+ start_selection_for_event (view, event);
+ } else if (location_in_selected_text (view,
event->x + view->scroll_x,
event->y + view->scroll_y)) {
view->selection_info.in_drag = TRUE;
} else {
- clear_selection (view);
-
- view->selection_info.start.x = event->x + view->scroll_x;
- view->selection_info.start.y = event->y + view->scroll_y;
+ start_selection_for_event (view, event);
}
-
+
gtk_widget_queue_draw (widget);
} else if (!location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y) &&
(image = ev_view_get_image_at_location (view, event->x, event->y))) {
@@ -2642,8 +2667,9 @@ ev_view_button_press_event (GtkWidget *widget,
ev_view_handle_form_field (view, field, event->x, event->y);
} else {
ev_view_remove_all (view);
- view->selection_info.start.x = event->x + view->scroll_x;
- view->selection_info.start.y = event->y + view->scroll_y;
+
+ if (EV_IS_SELECTION (view->document))
+ start_selection_for_event (view, event);
}
}
return TRUE;
@@ -2690,16 +2716,14 @@ ev_view_drag_data_get (GtkWidget *widget,
switch (info) {
case TARGET_DND_TEXT:
- if (view->selection_info.selections &&
- ev_document_can_get_text (view->document)) {
+ if (EV_IS_SELECTION (view->document) &&
+ view->selection_info.selections) {
gchar *text;
text = get_selected_text (view);
-
gtk_selection_data_set_text (selection_data,
text,
strlen (text));
-
g_free (text);
}
break;
@@ -2780,7 +2804,10 @@ ev_view_drag_data_received (GtkWidget *widget,
static gboolean
selection_update_idle_cb (EvView *view)
{
- compute_selections (view, &view->selection_info.start, &view->motion);
+ compute_selections (view,
+ view->selection_info.style,
+ &view->selection_info.start,
+ &view->motion);
view->selection_update_id = 0;
return FALSE;
}
@@ -2979,6 +3006,14 @@ ev_view_button_release_event (GtkWidget *widget,
view->selection_update_id = 0;
}
+ if (!view->selection_info.in_selection &&
+ view->selection_info.style != EV_SELECTION_STYLE_GLYPH) {
+ compute_selections (view,
+ view->selection_info.style,
+ &(view->selection_info.start),
+ &(view->selection_info.start));
+ }
+
if (view->selection_info.selections) {
ev_view_update_primary_selection (view);
@@ -5061,9 +5096,10 @@ gdk_rectangle_point_in (GdkRectangle *rectangle,
}
static GList *
-compute_new_selection_text (EvView *view,
- GdkPoint *start,
- GdkPoint *stop)
+compute_new_selection_text (EvView *view,
+ EvSelectionStyle style,
+ GdkPoint *start,
+ GdkPoint *stop)
{
int n_pages, i, first, last;
GList *list = NULL;
@@ -5118,6 +5154,7 @@ compute_new_selection_text (EvView *view,
selection = g_new0 (EvViewSelection, 1);
selection->page = i;
+ selection->style = style;
selection->rect.x1 = selection->rect.y1 = 0;
selection->rect.x2 = width;
selection->rect.y2 = height;
@@ -5275,16 +5312,17 @@ merge_selection_region (EvView *view,
}
static void
-compute_selections (EvView *view,
- GdkPoint *start,
- GdkPoint *stop)
+compute_selections (EvView *view,
+ EvSelectionStyle style,
+ GdkPoint *start,
+ GdkPoint *stop)
{
GList *list;
if (view->selection_mode == EV_VIEW_SELECTION_RECTANGLE)
list = compute_new_selection_rect (view, start, stop);
else
- list = compute_new_selection_text (view, start, stop);
+ list = compute_new_selection_text (view, style, start, stop);
merge_selection_region (view, list);
}
@@ -5309,10 +5347,10 @@ clear_selection (EvView *view)
g_object_notify (G_OBJECT (view), "has-selection");
}
-
void
ev_view_select_all (EvView *view)
{
+ GList *selections = NULL;
int n_pages, i;
/* Disable selection on rotated pages for the 0.4.0 series */
@@ -5320,7 +5358,7 @@ ev_view_select_all (EvView *view)
return;
clear_selection (view);
-
+
n_pages = ev_page_cache_get_n_pages (view->page_cache);
for (i = 0; i < n_pages; i++) {
int width, height;
@@ -5333,15 +5371,15 @@ ev_view_select_all (EvView *view)
selection = g_new0 (EvViewSelection, 1);
selection->page = i;
+ selection->style = EV_SELECTION_STYLE_GLYPH;
selection->rect.x1 = selection->rect.y1 = 0;
selection->rect.x2 = width;
selection->rect.y2 = height;
- view->selection_info.selections = g_list_append (view->selection_info.selections, selection);
+ selections = g_list_append (selections, selection);
}
- ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections);
- g_object_notify (G_OBJECT (view), "has-selection");
+ merge_selection_region (view, selections);
gtk_widget_queue_draw (GTK_WIDGET (view));
}
@@ -5352,29 +5390,35 @@ ev_view_get_has_selection (EvView *view)
}
static char *
-get_selected_text (EvView *ev_view)
+get_selected_text (EvView *view)
{
GString *text;
GList *l;
gchar *normalized_text;
+ EvRenderContext *rc;
text = g_string_new (NULL);
+ rc = ev_render_context_new (view->rotation, 1, view->scale);
ev_document_doc_mutex_lock ();
- for (l = ev_view->selection_info.selections; l != NULL; l = l->next) {
+ for (l = view->selection_info.selections; l != NULL; l = l->next) {
EvViewSelection *selection = (EvViewSelection *)l->data;
- char *tmp;
+ gchar *tmp;
+
+ ev_render_context_set_page (rc, selection->page);
+ tmp = ev_selection_get_selected_text (EV_SELECTION (view->document),
+ rc, selection->style,
+ &(selection->rect));
- tmp = ev_document_get_text (ev_view->document,
- selection->page,
- &selection->rect);
g_string_append (text, tmp);
g_free (tmp);
}
ev_document_doc_mutex_unlock ();
+ g_object_unref (rc);
+
normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
g_string_free (text, TRUE);
return normalized_text;
@@ -5386,9 +5430,8 @@ ev_view_copy (EvView *ev_view)
GtkClipboard *clipboard;
char *text;
- if (!ev_document_can_get_text (ev_view->document)) {
+ if (!EV_IS_SELECTION (ev_view->document))
return;
- }
text = get_selected_text (ev_view);
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
@@ -5406,9 +5449,8 @@ ev_view_primary_get_cb (GtkClipboard *clipboard,
EvView *ev_view = EV_VIEW (data);
char *text;
- if (!ev_document_can_get_text (ev_view->document)) {
+ if (!EV_IS_SELECTION (ev_view->document))
return;
- }
text = get_selected_text (ev_view);
if (text) {
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 9081b85..81b303f 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -316,7 +316,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
has_properties = FALSE;
}
- if (has_document && ev_document_can_get_text (document)) {
+ if (has_document && EV_IS_SELECTION (document)) {
can_get_text = TRUE;
}