ui/gtk/text.c

changeset 22
bcf880b29bc3
parent 12
fe94e0fb9ef3
child 27
77b09bb52ca0
equal deleted inserted replaced
21:012418e7dc90 22:bcf880b29bc3
31 #include <string.h> 31 #include <string.h>
32 32
33 #include "text.h" 33 #include "text.h"
34 #include "container.h" 34 #include "container.h"
35 35
36 static void selection_handler(
37 GtkTextBuffer *buf,
38 GtkTextIter *location,
39 GtkTextMark *mark,
40 UiTextArea *textview)
41 {
42 const char *mname = gtk_text_mark_get_name(mark);
43 if(mname) {
44 GtkTextIter begin;
45 GtkTextIter end;
46 int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end);
47 if(sel != textview->last_selection_state) {
48 if(sel) {
49 ui_set_group(textview->ctx, UI_GROUP_SELECTION);
50 } else {
51 ui_unset_group(textview->ctx, UI_GROUP_SELECTION);
52 }
53 }
54 textview->last_selection_state = sel;
55 }
56 }
57
36 UIWIDGET ui_textarea(UiObject *obj, UiText *value) { 58 UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
37 GtkWidget *text_area = gtk_text_view_new(); 59 GtkWidget *text_area = gtk_text_view_new();
38 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); 60 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR);
39 g_signal_connect( 61 g_signal_connect(
40 text_area, 62 text_area,
41 "realize", 63 "realize",
42 G_CALLBACK(ui_textarea_realize_event), 64 G_CALLBACK(ui_textarea_realize_event),
43 NULL); 65 NULL);
66 g_signal_connect(
67 text_area,
68 "selection-clear-event",
69 G_CALLBACK(selection_handler),
70 NULL);
71
72 UiTextArea *uitext = ucx_mempool_malloc(
73 obj->ctx->mempool,
74 sizeof(UiTextArea));
75 uitext->ctx = obj->ctx;
76 uitext->last_selection_state = 0;
44 77
45 GtkWidget *scroll_area = gtk_scrolled_window_new (NULL, NULL); 78 GtkWidget *scroll_area = gtk_scrolled_window_new (NULL, NULL);
46 gtk_scrolled_window_set_policy( 79 gtk_scrolled_window_set_policy(
47 GTK_SCROLLED_WINDOW(scroll_area), 80 GTK_SCROLLED_WINDOW(scroll_area),
48 GTK_POLICY_AUTOMATIC, 81 GTK_POLICY_AUTOMATIC,
84 g_signal_connect( 117 g_signal_connect(
85 buf, 118 buf,
86 "delete-range", 119 "delete-range",
87 G_CALLBACK(ui_textbuf_delete), 120 G_CALLBACK(ui_textbuf_delete),
88 value); 121 value);
122
123 g_signal_connect(
124 buf,
125 "mark-set",
126 G_CALLBACK(selection_handler),
127 uitext);
89 } 128 }
90 129
91 return scroll_area; 130 return scroll_area;
92 } 131 }
93 132

mercurial