diff options
Diffstat (limited to 'libstorycode/gtk')
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.c | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index b26c86b..df71f1e 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -409,15 +409,33 @@ void sc_editor_paste(GtkNarrativeView *e) static void clipboard_get(GtkClipboard *cb, GtkSelectionData *seldata, guint info, gpointer data) { - char *t = data; + GtkNarrativeView *e = data; printf("clipboard get\n"); if ( info == 0 ) { - printf("sending SC frame\n"); + char *t; + size_t start_offs, end_offs; + start_offs = narrative_pos_trail_to_offset(e->n, e->sel_start.para, + e->sel_start.pos, e->sel_start.trail); + end_offs = narrative_pos_trail_to_offset(e->n, e->sel_end.para, + e->sel_end.pos, e->sel_end.trail); + t = narrative_range_as_text(e->n, e->sel_start.para, start_offs, + e->sel_end.para, end_offs); + if ( t != NULL ) { + printf("got text '%s'\n", t); + gtk_selection_data_set_text(seldata, t, -1); + } else { + fprintf(stderr, "Couldn't format Storycode as text\n"); + } + + } else if ( info == 1 ) { + char *t = strdup(": Text"); + printf("sending SC\n"); gtk_selection_data_set(seldata, gtk_selection_data_get_target(seldata), 8, (const guchar *)t, strlen(t)+1); + } else { GdkAtom target; gchar *name; @@ -431,35 +449,26 @@ static void clipboard_get(GtkClipboard *cb, GtkSelectionData *seldata, static void clipboard_clear(GtkClipboard *cb, gpointer data) { - free(data); + /* Do absolutely nothing */ } static void copy_selection(GtkNarrativeView *e) { -// char *t; -// GtkClipboard *cb; -// GdkAtom atom; -// GtkTargetEntry targets[1]; -// -// atom = gdk_atom_intern("CLIPBOARD", FALSE); -// if ( atom == GDK_NONE ) return; -// -// cb = gtk_clipboard_get(atom); -// -// targets[0].target = "text/x-storycode"; -// targets[0].flags = 0; -// targets[0].info = 0; -// -// printf("copying selection\n"); -// -// bl = block_at_cursor(e->cursor_frame, e->cpos.para, 0); -// if ( bl == NULL ) return; -// -// t = serialise_sc_block(bl); -// -// gtk_clipboard_set_with_data(cb, targets, 1, -// clipboard_get, clipboard_clear, t); + GtkClipboard *cb; + GtkTargetEntry targets[2]; + + cb = gtk_clipboard_get_default(gtk_widget_get_display(GTK_WIDGET(e))); + + targets[0].target = "text/plain"; + targets[0].flags = 0; + targets[0].info = 0; + + targets[1].target = "text/x-storycode"; + targets[1].flags = 0; + targets[1].info = 1; + + gtk_clipboard_set_with_owner(cb, targets, 2, clipboard_get, clipboard_clear, G_OBJECT(e)); } |