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, |