+void
+ev_view_select_all (EvView *ev_view)
+{
+ GtkWidget *widget = GTK_WIDGET (ev_view);
+ GdkRectangle selection;
+ int width, height;
+ int x_offset, y_offset;
+ GtkBorder border;
+
+ g_return_if_fail (EV_IS_VIEW (ev_view));
+
+ ev_view_get_offsets (ev_view, &x_offset, &y_offset);
+ ev_document_get_page_size (ev_view->document, -1, &width, &height);
+ ev_document_misc_get_page_border_size (width, height, &border);
+
+ ev_view->has_selection = TRUE;
+ selection.x = x_offset + border.left;
+ selection.y = y_offset + border.top;
+ selection.width = width;
+ selection.height = height;
+ view_rect_to_doc_rect (ev_view, &selection, &ev_view->selection);
+
+ gtk_widget_queue_draw (widget);
+}
+
+void
+ev_view_copy (EvView *ev_view)
+{
+ GtkClipboard *clipboard;
+ GdkRectangle selection;
+ char *text;
+
+ doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
+ text = ev_document_get_text (ev_view->document, &selection);
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
+ GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_text (clipboard, text, -1);
+ g_free (text);
+}
+
+static void
+ev_view_primary_get_cb (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ guint info,
+ gpointer data)
+{
+ EvView *ev_view = EV_VIEW (data);
+ GdkRectangle selection;
+ char *text;
+
+ doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
+ text = ev_document_get_text (ev_view->document, &selection);
+ gtk_selection_data_set_text (selection_data, text, -1);
+}
+
+static void
+ev_view_primary_clear_cb (GtkClipboard *clipboard,
+ gpointer data)
+{
+ EvView *ev_view = EV_VIEW (data);
+
+ ev_view->has_selection = FALSE;
+}
+
+static void
+ev_view_update_primary_selection (EvView *ev_view)
+{
+ GtkClipboard *clipboard;
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
+ GDK_SELECTION_PRIMARY);
+
+ if (ev_view->has_selection) {
+ if (!gtk_clipboard_set_with_owner (clipboard,
+ targets,
+ G_N_ELEMENTS (targets),
+ ev_view_primary_get_cb,
+ ev_view_primary_clear_cb,
+ G_OBJECT (ev_view)))
+ ev_view_primary_clear_cb (clipboard, ev_view);
+ } else {
+ if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (ev_view))
+ gtk_clipboard_clear (clipboard);
+ }
+}
+