Replace GtkText in testselection with GtkTextView

This commit is contained in:
Christian Dywan
2010-03-31 16:16:26 +02:00
committed by Javier Jardón
parent e0602fd6a8
commit 44af4852ee

View File

@ -273,6 +273,7 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
int i; int i;
SelType seltype; SelType seltype;
char *str; char *str;
GtkTextBuffer *buffer;
if (data->length < 0) if (data->length < 0)
{ {
@ -303,10 +304,8 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
selection_string = g_string_new (NULL); selection_string = g_string_new (NULL);
gtk_text_freeze (GTK_TEXT (selection_text)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (selection_text));
gtk_text_set_point (GTK_TEXT (selection_text), 0); gtk_text_buffer_set_text (buffer, "", -1);
gtk_text_forward_delete (GTK_TEXT (selection_text),
gtk_text_get_length (GTK_TEXT (selection_text)));
position = 0; position = 0;
while (position < data->length) while (position < data->length)
@ -344,16 +343,11 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
continue; continue;
} }
} }
gtk_text_insert (GTK_TEXT (selection_text), NULL, gtk_text_buffer_insert_at_cursor (buffer, str, -1);
&selection_text->style->black, gtk_text_buffer_insert_at_cursor (buffer, "\n", -1);
NULL, str, -1);
gtk_text_insert (GTK_TEXT (selection_text), NULL,
&selection_text->style->black,
NULL, "\n", -1);
g_string_append (selection_string, str); g_string_append (selection_string, str);
g_free (str); g_free (str);
} }
gtk_text_thaw (GTK_TEXT (selection_text));
} }
void void
@ -378,7 +372,7 @@ paste (GtkWidget *widget, GtkWidget *entry)
void void
quit (void) quit (void)
{ {
exit (0); gtk_main_quit ();
} }
int int
@ -389,9 +383,8 @@ main (int argc, char *argv[])
GtkWidget *table; GtkWidget *table;
GtkWidget *label; GtkWidget *label;
GtkWidget *entry; GtkWidget *entry;
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *scrolled;
static GtkTargetEntry targetlist[] = { static GtkTargetEntry targetlist[] = {
{ "STRING", 0, STRING }, { "STRING", 0, STRING },
@ -442,20 +435,12 @@ main (int argc, char *argv[])
g_signal_connect (selection_widget, "selection_get", g_signal_connect (selection_widget, "selection_get",
G_CALLBACK (selection_get), NULL); G_CALLBACK (selection_get), NULL);
selection_text = gtk_text_new (NULL, NULL); selection_text = gtk_text_view_new ();
gtk_table_attach_defaults (GTK_TABLE (table), selection_text, 0, 1, 1, 2); scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolled), selection_text);
gtk_table_attach_defaults (GTK_TABLE (table), scrolled, 0, 1, 1, 2);
gtk_widget_show (selection_text); gtk_widget_show (selection_text);
hscrollbar = gtk_hscrollbar_new (GTK_TEXT (selection_text)->hadj);
gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (hscrollbar);
vscrollbar = gtk_vscrollbar_new (GTK_TEXT (selection_text)->vadj);
gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 1, 2,
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (vscrollbar);
hbox = gtk_hbox_new (FALSE, 2); hbox = gtk_hbox_new (FALSE, 2);
gtk_table_attach (GTK_TABLE (table), hbox, 0, 2, 3, 4, gtk_table_attach (GTK_TABLE (table), hbox, 0, 2, 3, 4,
GTK_EXPAND | GTK_FILL, 0, 0, 0); GTK_EXPAND | GTK_FILL, 0, 0, 0);