ui/gtk/text.c

changeset 115
e57ca2747782
parent 112
c3f2f16fa4b8
equal deleted inserted replaced
114:3da24640513a 115:e57ca2747782
30 #include <stdlib.h> 30 #include <stdlib.h>
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 #include "widget.h"
35 36
36 #include <cx/printf.h> 37 #include <cx/printf.h>
37 38
38 #include <gdk/gdkkeysyms.h> 39 #include <gdk/gdkkeysyms.h>
39 40
51 GtkTextIter begin; 52 GtkTextIter begin;
52 GtkTextIter end; 53 GtkTextIter end;
53 int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end); 54 int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end);
54 if(sel != textview->last_selection_state) { 55 if(sel != textview->last_selection_state) {
55 if(sel) { 56 if(sel) {
56 ui_set_group(textview->ctx, UI_GROUP_SELECTION); 57 ui_set_state(textview->ctx, UI_GROUP_SELECTION);
57 } else { 58 } else {
58 ui_unset_group(textview->ctx, UI_GROUP_SELECTION); 59 ui_unset_state(textview->ctx, UI_GROUP_SELECTION);
59 } 60 }
60 } 61 }
61 textview->last_selection_state = sel; 62 textview->last_selection_state = sel;
62 } 63 }
63 } 64 }
110 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) { 111 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) {
111 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT); 112 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT);
112 113
113 GtkWidget *text_area = gtk_text_view_new(); 114 GtkWidget *text_area = gtk_text_view_new();
114 ui_set_name_and_style(text_area, args->name, args->style_class); 115 ui_set_name_and_style(text_area, args->name, args->style_class);
115 ui_set_widget_groups(obj->ctx, text_area, args->groups); 116 ui_set_widget_states(obj->ctx, text_area, args->states);
116 117
117 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); 118 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR);
118 g_signal_connect( 119 g_signal_connect(
119 text_area, 120 text_area,
120 "realize", 121 "realize",
142 GTK_SCROLLED_WINDOW(scroll_area), 143 GTK_SCROLLED_WINDOW(scroll_area),
143 GTK_POLICY_AUTOMATIC, 144 GTK_POLICY_AUTOMATIC,
144 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS 145 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
145 SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); 146 SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area);
146 147
147 if(args->width > 0 || args->height > 0) { 148 ui_widget_size_request(scroll_area, args->width, args->height);
148 int width = args->width;
149 int height = args->height;
150 if(width == 0) {
151 width = -1;
152 }
153 if(height == 0) {
154 height = -1;
155 }
156 gtk_widget_set_size_request(scroll_area, width, height);
157 }
158 149
159 // font and padding 150 // font and padding
160 //PangoFontDescription *font; 151 //PangoFontDescription *font;
161 //font = pango_font_description_from_string("Monospace"); 152 //font = pango_font_description_from_string("Monospace");
162 //gtk_widget_modify_font(text_area, font); // TODO 153 //gtk_widget_modify_font(text_area, font); // TODO
333 } 324 }
334 325
335 326
336 327
337 void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { 328 void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) {
329 if(!ui_onchange_events_is_enabled()) {
330 return;
331 }
332
338 UiText *value = textarea->var->value; 333 UiText *value = textarea->var->value;
339 334
340 UiEvent e; 335 UiEvent e;
341 e.obj = textarea->obj; 336 e.obj = textarea->obj;
342 e.window = e.obj->window; 337 e.window = e.obj->window;
606 601
607 602
608 static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs *args) { 603 static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs *args) {
609 GtkWidget *textfield = gtk_entry_new(); 604 GtkWidget *textfield = gtk_entry_new();
610 ui_set_name_and_style(textfield, args->name, args->style_class); 605 ui_set_name_and_style(textfield, args->name, args->style_class);
611 ui_set_widget_groups(obj->ctx, textfield, args->groups); 606 ui_set_widget_states(obj->ctx, textfield, args->states);
612 607
613 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); 608 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING);
614 609
615 UiTextField *uitext = malloc(sizeof(UiTextField)); 610 UiTextField *uitext = malloc(sizeof(UiTextField));
616 uitext->obj = obj; 611 uitext->obj = obj;
696 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { 691 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) {
697 free(textfield); 692 free(textfield);
698 } 693 }
699 694
700 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { 695 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) {
701 UiString *value = textfield->var->value; 696 if(!ui_onchange_events_is_enabled()) {
697 return;
698 }
699
700 UiString *value = textfield->var ? textfield->var->value : NULL;
702 701
703 UiEvent e; 702 UiEvent e;
704 e.obj = textfield->obj; 703 e.obj = textfield->obj;
705 e.window = e.obj->window; 704 e.window = e.obj->window;
706 e.document = textfield->obj->ctx->document; 705 e.document = textfield->obj->ctx->document;
707 e.eventdata = value; 706 e.eventdata = value;
708 e.eventdatatype = UI_EVENT_DATA_TEXT_VALUE; 707 e.eventdatatype = value ? UI_EVENT_DATA_TEXT_VALUE : 0;
709 e.intval = 0; 708 e.intval = 0;
710 e.set = ui_get_setop(); 709 e.set = ui_get_setop();
711 710
712 if(textfield->onchange) { 711 if(textfield->onchange) {
713 textfield->onchange(&e, textfield->onchangedata); 712 textfield->onchange(&e, textfield->onchangedata);
718 } 717 }
719 } 718 }
720 719
721 void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) { 720 void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) {
722 if(textfield->onactivate) { 721 if(textfield->onactivate) {
722 UiString *value = textfield->var ? textfield->var->value : NULL;
723
723 UiEvent e; 724 UiEvent e;
724 e.obj = textfield->obj; 725 e.obj = textfield->obj;
725 e.window = e.obj->window; 726 e.window = e.obj->window;
726 e.document = textfield->obj->ctx->document; 727 e.document = textfield->obj->ctx->document;
727 e.eventdata = NULL; 728 e.eventdata = value;
728 e.eventdatatype = 0; 729 e.eventdatatype = value ? UI_EVENT_DATA_TEXT_VALUE : 0;
729 e.intval = 0; 730 e.intval = 0;
730 e.set = ui_get_setop(); 731 e.set = ui_get_setop();
731 textfield->onactivate(&e, textfield->onactivatedata); 732 textfield->onactivate(&e, textfield->onactivatedata);
732 } 733 }
733 } 734 }
954 } 955 }
955 956
956 pathtf->stack = gtk_stack_new(); 957 pathtf->stack = gtk_stack_new();
957 gtk_widget_set_name(pathtf->stack, "path-textfield-box"); 958 gtk_widget_set_name(pathtf->stack, "path-textfield-box");
958 959
960 if(args->width > 0) {
961 gtk_widget_set_size_request(pathtf->stack, args->width, -1);
962 }
963
959 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; 964 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end;
960 UiLayout layout = UI_ARGS2LAYOUT(args); 965 UiLayout layout = UI_ARGS2LAYOUT(args);
961 ct->add(ct, pathtf->stack, &layout); 966 ct->add(ct, pathtf->stack, &layout);
962 967
963 pathtf->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); 968 pathtf->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1125 eventbox, 1130 eventbox,
1126 "destroy", 1131 "destroy",
1127 G_CALLBACK(ui_path_textfield_destroy), 1132 G_CALLBACK(ui_path_textfield_destroy),
1128 pathtf); 1133 pathtf);
1129 1134
1135 if(args->width > 0) {
1136 gtk_widget_set_size_request(eventbox, args->width, -1);
1137 }
1138
1130 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; 1139 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end;
1131 UiLayout layout = UI_ARGS2LAYOUT(args); 1140 UiLayout layout = UI_ARGS2LAYOUT(args);
1132 ct->add(ct, eventbox, &layout); 1141 ct->add(ct, eventbox, &layout);
1133 1142
1134 // hbox as parent for the GtkEntry and GtkButtonBox 1143 // hbox as parent for the GtkEntry and GtkButtonBox

mercurial