60 } |
60 } |
61 textview->last_selection_state = sel; |
61 textview->last_selection_state = sel; |
62 } |
62 } |
63 } |
63 } |
64 |
64 |
65 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var) { |
65 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { |
|
66 UiObject* current = uic_current_obj(obj); |
|
67 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_TEXT); |
|
68 |
66 GtkWidget *text_area = gtk_text_view_new(); |
69 GtkWidget *text_area = gtk_text_view_new(); |
|
70 ui_set_name_and_style(text_area, args.name, args.style_class); |
|
71 |
67 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); |
72 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); |
68 g_signal_connect( |
73 g_signal_connect( |
69 text_area, |
74 text_area, |
70 "realize", |
75 "realize", |
71 G_CALLBACK(ui_textarea_realize_event), |
76 G_CALLBACK(ui_textarea_realize_event), |
88 GTK_POLICY_AUTOMATIC, |
93 GTK_POLICY_AUTOMATIC, |
89 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
94 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
90 SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); |
95 SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); |
91 |
96 |
92 // font and padding |
97 // font and padding |
93 PangoFontDescription *font; |
98 //PangoFontDescription *font; |
94 font = pango_font_description_from_string("Monospace"); |
99 //font = pango_font_description_from_string("Monospace"); |
95 //gtk_widget_modify_font(text_area, font); // TODO |
100 //gtk_widget_modify_font(text_area, font); // TODO |
96 pango_font_description_free(font); |
101 //pango_font_description_free(font); |
97 |
102 |
98 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); |
103 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); |
99 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); |
104 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); |
100 |
105 |
101 // add |
106 // add |
102 UiContainer *ct = uic_get_current_container(obj); |
107 UI_APPLY_LAYOUT1(current, args); |
103 ct->add(ct, scroll_area, TRUE); |
108 current->container->add(current->container, scroll_area, TRUE); |
104 |
109 |
105 // bind value |
110 // bind value |
106 UiText *value = var->value; |
111 UiText *value = var->value; |
107 if(value) { |
112 if(value) { |
108 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
113 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
156 } |
161 } |
157 |
162 |
158 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
163 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
159 ui_destroy_boundvar(textarea->ctx, textarea->var); |
164 ui_destroy_boundvar(textarea->ctx, textarea->var); |
160 free(textarea); |
165 free(textarea); |
161 } |
|
162 |
|
163 UIWIDGET ui_textarea(UiObject *obj, UiText *value) { |
|
164 UiVar *var = malloc(sizeof(UiVar)); |
|
165 var->value = value; |
|
166 var->type = UI_VAR_SPECIAL; |
|
167 var->from = NULL; |
|
168 var->from_ctx = NULL; |
|
169 return ui_textarea_var(obj, var); |
|
170 } |
|
171 |
|
172 UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) { |
|
173 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_TEXT); |
|
174 if(var) { |
|
175 return ui_textarea_var(obj, var); |
|
176 } else { |
|
177 // TODO: error |
|
178 } |
|
179 return NULL; |
|
180 } |
166 } |
181 |
167 |
182 UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
168 UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
183 return SCROLLEDWINDOW_GET_CHILD(textarea); |
169 return SCROLLEDWINDOW_GET_CHILD(textarea); |
184 } |
170 } |
569 } |
555 } |
570 if(password) { |
556 if(password) { |
571 gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
557 gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
572 } |
558 } |
573 |
559 |
574 UiContainer *ct = uic_get_current_container(obj); |
560 UI_APPLY_LAYOUT1(current, args); |
575 ct->add(ct, textfield, FALSE); |
561 current->container->add(current->container, textfield, FALSE); |
576 |
562 |
577 if(var) { |
563 if(var) { |
578 UiString *value = var->value; |
564 UiString *value = var->value; |
579 if(value->value.ptr) { |
565 if(value->value.ptr) { |
580 ENTRY_SET_TEXT(textfield, value->value.ptr); |
566 ENTRY_SET_TEXT(textfield, value->value.ptr); |