Thu, 15 Feb 2024 21:31:15 +0100
add new label (GTK)
5 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
5 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
31 | #include <string.h> |
5 | 32 | |
33 | #include "text.h" | |
34 | #include "container.h" | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
35 | |
5 | 36 | |
174 | 37 | #include "../common/types.h" |
38 | ||
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
39 | static void selection_handler( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
40 | GtkTextBuffer *buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
41 | GtkTextIter *location, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
42 | GtkTextMark *mark, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
43 | UiTextArea *textview) |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
44 | { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
45 | const char *mname = gtk_text_mark_get_name(mark); |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
46 | if(mname) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
47 | GtkTextIter begin; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
48 | GtkTextIter end; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
49 | int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end); |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
50 | if(sel != textview->last_selection_state) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
51 | if(sel) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
52 | ui_set_group(textview->ctx, UI_GROUP_SELECTION); |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
53 | } else { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
54 | ui_unset_group(textview->ctx, UI_GROUP_SELECTION); |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
55 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
56 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
57 | textview->last_selection_state = sel; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
58 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
59 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
60 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
61 | UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var) { |
5 | 62 | GtkWidget *text_area = gtk_text_view_new(); |
63 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); | |
64 | g_signal_connect( | |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | text_area, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
66 | "realize", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
67 | G_CALLBACK(ui_textarea_realize_event), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
68 | NULL); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
69 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
70 | UiTextArea *uitext = malloc(sizeof(UiTextArea)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
71 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
72 | uitext->var = var; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
73 | uitext->last_selection_state = 0; |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
74 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
75 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
76 | text_area, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
77 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
78 | G_CALLBACK(ui_textarea_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
79 | uitext); |
5 | 80 | |
81 | GtkWidget *scroll_area = gtk_scrolled_window_new (NULL, NULL); | |
82 | gtk_scrolled_window_set_policy( | |
83 | GTK_SCROLLED_WINDOW(scroll_area), | |
84 | GTK_POLICY_AUTOMATIC, | |
85 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS | |
86 | gtk_container_add(GTK_CONTAINER(scroll_area), text_area); | |
87 | ||
88 | // font and padding | |
89 | PangoFontDescription *font; | |
90 | font = pango_font_description_from_string("Monospace"); | |
91 | gtk_widget_modify_font(text_area, font); | |
92 | pango_font_description_free(font); | |
93 | ||
94 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); | |
95 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); | |
96 | ||
97 | // add | |
98 | UiContainer *ct = uic_get_current_container(obj); | |
59
eb6611be50c7
added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
99 | ct->add(ct, scroll_area, TRUE); |
5 | 100 | |
101 | // bind value | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
102 | UiText *value = var->value; |
5 | 103 | if(value) { |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
104 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
105 | |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
106 | if(value->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
107 | gtk_text_buffer_set_text(buf, value->value.ptr, -1); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
108 | value->value.free(value->value.ptr); |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
109 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
110 | |
5 | 111 | value->get = ui_textarea_get; |
112 | value->set = ui_textarea_set; | |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
113 | value->getsubstr = ui_textarea_getsubstr; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
114 | value->insert = ui_textarea_insert; |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
115 | value->setposition = ui_textarea_setposition; |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
116 | value->position = ui_textarea_position; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
117 | value->selection = ui_textarea_selection; |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
118 | value->length = ui_textarea_length; |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
119 | value->remove = ui_textarea_remove; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
120 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
121 | value->value.free = NULL; |
5 | 122 | value->obj = buf; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
123 | if(!value->undomgr) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
124 | value->undomgr = ui_create_undomgr(); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
125 | } |
5 | 126 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
127 | g_signal_connect( |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
128 | buf, |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
129 | "changed", |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
130 | G_CALLBACK(ui_textbuf_changed), |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
131 | uitext); |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
132 | |
5 | 133 | // register undo manager |
134 | g_signal_connect( | |
135 | buf, | |
136 | "insert-text", | |
137 | G_CALLBACK(ui_textbuf_insert), | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
138 | var); |
5 | 139 | g_signal_connect( |
140 | buf, | |
141 | "delete-range", | |
142 | G_CALLBACK(ui_textbuf_delete), | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
143 | var); |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
144 | g_signal_connect( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
145 | buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
146 | "mark-set", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
147 | G_CALLBACK(selection_handler), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
148 | uitext); |
5 | 149 | } |
150 | ||
151 | return scroll_area; | |
152 | } | |
153 | ||
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
154 | void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
155 | ui_destroy_boundvar(textarea->ctx, textarea->var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
156 | free(textarea); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
157 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
158 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
159 | UIWIDGET ui_textarea(UiObject *obj, UiText *value) { |
163
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
160 | UiVar *var = malloc(sizeof(UiVar)); |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
161 | var->value = value; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
162 | var->type = UI_VAR_SPECIAL; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
163 | var->from = NULL; |
b70e2a77dea0
refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
164 | var->from_ctx = NULL; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
165 | return ui_textarea_var(obj, var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
166 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
167 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
168 | UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
169 | UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_TEXT); |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
170 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
171 | return ui_textarea_var(obj, var); |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
172 | } else { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
173 | // TODO: error |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
174 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
175 | return NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
176 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
177 | |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
178 | UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
179 | return gtk_bin_get_child(GTK_BIN(textarea)); |
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
180 | } |
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
181 | |
5 | 182 | char* ui_textarea_get(UiText *text) { |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
183 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
184 | text->value.free(text->value.ptr); |
5 | 185 | } |
186 | GtkTextBuffer *buf = text->obj; | |
187 | GtkTextIter start; | |
188 | GtkTextIter end; | |
189 | gtk_text_buffer_get_bounds(buf, &start, &end); | |
190 | char *str = gtk_text_buffer_get_text(buf, &start, &end, FALSE); | |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
191 | text->value.ptr = g_strdup(str); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
192 | text->value.free = (ui_freefunc)g_free; |
5 | 193 | return str; |
194 | } | |
195 | ||
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
196 | void ui_textarea_set(UiText *text, const char *str) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
197 | gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
198 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
199 | text->value.free(text->value.ptr); |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
200 | } |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
201 | text->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
202 | text->value.free = NULL; |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
203 | } |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
204 | |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
205 | char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
206 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
207 | text->value.free(text->value.ptr); |
5 | 208 | } |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
209 | GtkTextBuffer *buf = text->obj; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
210 | GtkTextIter ib; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
211 | GtkTextIter ie; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
212 | gtk_text_buffer_get_iter_at_offset(text->obj, &ib, begin); |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
213 | gtk_text_buffer_get_iter_at_offset(text->obj, &ie, end); |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
214 | char *str = gtk_text_buffer_get_text(buf, &ib, &ie, FALSE); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
215 | text->value.ptr = g_strdup(str); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
216 | text->value.free = (ui_freefunc)g_free; |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
217 | return str; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
218 | } |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
219 | |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
220 | void ui_textarea_insert(UiText *text, int pos, char *str) { |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
221 | GtkTextIter offset; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
222 | gtk_text_buffer_get_iter_at_offset(text->obj, &offset, pos); |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
223 | gtk_text_buffer_insert(text->obj, &offset, str, -1); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
224 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
225 | text->value.free(text->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
226 | } |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
227 | text->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
228 | text->value.free = NULL; |
5 | 229 | } |
230 | ||
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
231 | void ui_textarea_setposition(UiText *text, int pos) { |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
232 | GtkTextIter iter; |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
233 | gtk_text_buffer_get_iter_at_offset(text->obj, &iter, pos); |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
234 | gtk_text_buffer_place_cursor(text->obj, &iter); |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
235 | } |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
236 | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
237 | int ui_textarea_position(UiText *text) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
238 | GtkTextIter begin; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
239 | GtkTextIter end; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
240 | gtk_text_buffer_get_selection_bounds(text->obj, &begin, &end); |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
241 | text->pos = gtk_text_iter_get_offset(&begin); |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
242 | return text->pos; |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
243 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
244 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
245 | void ui_textarea_selection(UiText *text, int *begin, int *end) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
246 | GtkTextIter b; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
247 | GtkTextIter e; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
248 | gtk_text_buffer_get_selection_bounds(text->obj, &b, &e); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
249 | *begin = gtk_text_iter_get_offset(&b); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
250 | *end = gtk_text_iter_get_offset(&e); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
251 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
252 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
253 | int ui_textarea_length(UiText *text) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
254 | GtkTextBuffer *buf = text->obj; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
255 | GtkTextIter start; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
256 | GtkTextIter end; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
257 | gtk_text_buffer_get_bounds(buf, &start, &end); |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
258 | return gtk_text_iter_get_offset(&end); |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
259 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
260 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
261 | void ui_textarea_remove(UiText *text, int begin, int end) { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
262 | GtkTextBuffer *buf = text->obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
263 | GtkTextIter ib; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
264 | GtkTextIter ie; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
265 | gtk_text_buffer_get_iter_at_offset(buf, &ib, begin); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
266 | gtk_text_buffer_get_iter_at_offset(buf, &ie, end); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
267 | gtk_text_buffer_delete(buf, &ib, &ie); |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
268 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
269 | |
5 | 270 | void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
271 | gtk_widget_grab_focus(widget); | |
272 | } | |
273 | ||
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
274 | |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
275 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
276 | void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
277 | UiText *value = textarea->var->value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
278 | if(value->observers) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
279 | UiEvent e; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
280 | e.obj = textarea->ctx->obj; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
281 | e.window = e.obj->window; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
282 | e.document = textarea->ctx->document; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
283 | e.eventdata = value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
284 | e.intval = 0; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
285 | ui_notify_evt(value->observers, &e); |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
286 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
287 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
288 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
289 | // undo manager functions |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
290 | |
5 | 291 | void ui_textbuf_insert( |
292 | GtkTextBuffer *textbuffer, | |
293 | GtkTextIter *location, | |
294 | char *text, | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
295 | int length, |
5 | 296 | void *data) |
297 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
298 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
299 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
300 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
301 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
302 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
303 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
304 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
305 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
306 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
307 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
308 | if(mgr->cur) { |
174 | 309 | UiTextBufOp *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
310 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
311 | mgr->cur->next = NULL; |
174 | 312 | mgr->end = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
313 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
314 | elm->prev = NULL; |
174 | 315 | UiTextBufOp *next = elm->next; |
316 | ui_free_textbuf_op(elm); | |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
317 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
318 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
319 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
320 | |
174 | 321 | UiTextBufOp *last_op = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
322 | if( |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
323 | last_op->type == UI_TEXTBUF_INSERT && |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
324 | ui_check_insertstr(last_op->text, last_op->len, text, length) == 0) |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
325 | { |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
326 | // append text to last op |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
327 | int ln = last_op->len; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
328 | char *newtext = malloc(ln + length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
329 | memcpy(newtext, last_op->text, ln); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
330 | memcpy(newtext+ln, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
331 | newtext[ln+length] = '\0'; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
332 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
333 | last_op->text = newtext; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
334 | last_op->len = ln + length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
335 | last_op->end += length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
336 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
337 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
338 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
339 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
340 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
341 | char *dpstr = malloc(length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
342 | memcpy(dpstr, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
343 | dpstr[length] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
344 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
345 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
174 | 346 | op->prev = NULL; |
347 | op->next = NULL; | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
348 | op->type = UI_TEXTBUF_INSERT; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
349 | op->start = gtk_text_iter_get_offset(location); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
350 | op->end = op->start+length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
351 | op->len = length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
352 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
353 | |
174 | 354 | cx_linked_list_add( |
355 | (void**)&mgr->begin, | |
356 | (void**)&mgr->end, | |
357 | offsetof(UiTextBufOp, prev), | |
358 | offsetof(UiTextBufOp, next), | |
359 | op); | |
360 | ||
361 | mgr->cur = op; | |
5 | 362 | } |
363 | ||
364 | void ui_textbuf_delete( | |
365 | GtkTextBuffer *textbuffer, | |
366 | GtkTextIter *start, | |
367 | GtkTextIter *end, | |
368 | void *data) | |
369 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
370 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
371 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
372 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
373 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
374 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
375 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
376 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
377 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
378 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
379 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
380 | if(mgr->cur) { |
174 | 381 | UiTextBufOp *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
382 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
383 | mgr->cur->next = NULL; |
174 | 384 | mgr->end = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
385 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
386 | elm->prev = NULL; |
174 | 387 | UiTextBufOp *next = elm->next; |
388 | ui_free_textbuf_op(elm); | |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
389 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
390 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
391 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
392 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
393 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
394 | char *text = gtk_text_buffer_get_text(value->obj, start, end, FALSE); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
395 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
396 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
174 | 397 | op->prev = NULL; |
398 | op->next = NULL; | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
399 | op->type = UI_TEXTBUF_DELETE; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
400 | op->start = gtk_text_iter_get_offset(start); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
401 | op->end = gtk_text_iter_get_offset(end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
402 | op->len = op->end - op->start; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
403 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
404 | char *dpstr = malloc(op->len + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
405 | memcpy(dpstr, text, op->len); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
406 | dpstr[op->len] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
407 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
408 | |
174 | 409 | cx_linked_list_add( |
410 | (void**)&mgr->begin, | |
411 | (void**)&mgr->end, | |
412 | offsetof(UiTextBufOp, prev), | |
413 | offsetof(UiTextBufOp, next), | |
414 | op); | |
415 | ||
416 | mgr->cur = op; | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
417 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
418 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
419 | UiUndoMgr* ui_create_undomgr() { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
420 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
421 | mgr->begin = NULL; |
174 | 422 | mgr->end = NULL; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
423 | mgr->cur = NULL; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
424 | mgr->length = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
425 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
426 | return mgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
427 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
428 | |
174 | 429 | void ui_destroy_undomgr(UiUndoMgr *mgr) { |
430 | UiTextBufOp *op = mgr->begin; | |
431 | while(op) { | |
432 | UiTextBufOp *nextOp = op->next; | |
433 | if(op->text) { | |
434 | free(op->text); | |
435 | } | |
436 | free(op); | |
437 | op = nextOp; | |
438 | } | |
439 | free(mgr); | |
440 | } | |
441 | ||
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
442 | void ui_free_textbuf_op(UiTextBufOp *op) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
443 | if(op->text) { |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
444 | free(op->text); |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
445 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
446 | free(op); |
5 | 447 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
448 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
449 | int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
450 | // return 1 if oldstr + newstr are one word |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
451 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
452 | int has_space = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
453 | for(int i=0;i<oldlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
454 | if(oldstr[i] < 33) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
455 | has_space = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
456 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
457 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
458 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
459 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
460 | for(int i=0;i<newlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
461 | if(has_space && newstr[i] > 32) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
462 | return 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
463 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
464 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
465 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
466 | return 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
467 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
468 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
469 | void ui_text_undo(UiText *value) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
470 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
471 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
472 | if(mgr->cur) { |
174 | 473 | UiTextBufOp *op = mgr->cur; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
474 | mgr->event = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
475 | switch(op->type) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
476 | case UI_TEXTBUF_INSERT: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
477 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
478 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
479 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
480 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
481 | gtk_text_buffer_delete(value->obj, &begin, &end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
482 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
483 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
484 | case UI_TEXTBUF_DELETE: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
485 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
486 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
487 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
488 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
489 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
490 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
491 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
492 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
493 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
494 | mgr->cur = mgr->cur->prev; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
495 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
496 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
497 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
498 | void ui_text_redo(UiText *value) { |
8 | 499 | UiUndoMgr *mgr = value->undomgr; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
500 | |
174 | 501 | UiTextBufOp *elm = NULL; |
8 | 502 | if(mgr->cur) { |
503 | if(mgr->cur->next) { | |
504 | elm = mgr->cur->next; | |
505 | } | |
506 | } else if(mgr->begin) { | |
507 | elm = mgr->begin; | |
508 | } | |
509 | ||
510 | if(elm) { | |
174 | 511 | UiTextBufOp *op = elm; |
8 | 512 | mgr->event = 0; |
513 | switch(op->type) { | |
514 | case UI_TEXTBUF_INSERT: { | |
515 | GtkTextIter begin; | |
516 | GtkTextIter end; | |
517 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
518 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
519 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); | |
520 | break; | |
521 | } | |
522 | case UI_TEXTBUF_DELETE: { | |
523 | GtkTextIter begin; | |
524 | GtkTextIter end; | |
525 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
526 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
527 | gtk_text_buffer_delete(value->obj, &begin, &end); | |
528 | break; | |
529 | } | |
530 | } | |
531 | mgr->event = 1; | |
532 | mgr->cur = elm; | |
533 | } | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
534 | } |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
535 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
536 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
537 | static UIWIDGET create_textfield_var(UiObject *obj, int width, UiBool frameless, UiBool password, UiVar *var) { |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
538 | GtkWidget *textfield = gtk_entry_new(); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
539 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
540 | UiTextField *uitext = malloc(sizeof(UiTextField)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
541 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
542 | uitext->var = var; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
543 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
544 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
545 | textfield, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
546 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
547 | G_CALLBACK(ui_textfield_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
548 | uitext); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
549 | |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
550 | if(width > 0) { |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
551 | gtk_entry_set_width_chars(GTK_ENTRY(textfield), width); |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
552 | } |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
553 | if(frameless) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
554 | // TODO: gtk2legacy workaroud |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
555 | gtk_entry_set_has_frame(GTK_ENTRY(textfield), FALSE); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
556 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
557 | if(password) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
558 | gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
559 | } |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
560 | |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
561 | UiContainer *ct = uic_get_current_container(obj); |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
562 | ct->add(ct, textfield, FALSE); |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
563 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
564 | if(var) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
565 | UiString *value = var->value; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
566 | if(value->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
567 | gtk_entry_set_text(GTK_ENTRY(textfield), value->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
568 | value->value.free(value->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
569 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
570 | value->value.free = NULL; |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
571 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
572 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
573 | value->get = ui_textfield_get; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
574 | value->set = ui_textfield_set; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
575 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
576 | value->value.free = NULL; |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
577 | value->obj = GTK_ENTRY(textfield); |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
578 | |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
579 | g_signal_connect( |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
580 | textfield, |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
581 | "changed", |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
582 | G_CALLBACK(ui_textfield_changed), |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
583 | uitext); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
584 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
585 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
586 | return textfield; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
587 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
588 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
589 | static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
590 | UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_STRING); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
591 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
592 | return create_textfield_var(obj, width, frameless, password, var); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
593 | } else { |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
594 | // TODO: error |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
595 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
596 | return NULL; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
597 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
598 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
599 | static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
600 | UiVar *var = NULL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
601 | if(value) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
602 | var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
603 | var->value = value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
604 | var->type = UI_VAR_SPECIAL; |
167
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
605 | var->from = NULL; |
161511838ea6
add new toolbar toggle button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
163
diff
changeset
|
606 | var->from_ctx = NULL; |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
607 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
608 | return create_textfield_var(obj, width, frameless, password, var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
609 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
610 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
611 | void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
161
b1eac0878ce7
fix crash on window close (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
612 | if(textfield->var) { |
174 | 613 | UiText *text = textfield->var->value; |
614 | if(text->undomgr) { | |
615 | ui_destroy_undomgr(text->undomgr); | |
616 | } | |
161
b1eac0878ce7
fix crash on window close (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
617 | ui_destroy_boundvar(textfield->ctx, textfield->var); |
b1eac0878ce7
fix crash on window close (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
143
diff
changeset
|
618 | } |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
619 | free(textfield); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
620 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
621 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
622 | void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
623 | UiString *value = textfield->var->value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
624 | if(value->observers) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
625 | UiEvent e; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
626 | e.obj = textfield->ctx->obj; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
627 | e.window = e.obj->window; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
628 | e.document = textfield->ctx->document; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
629 | e.eventdata = value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
630 | e.intval = 0; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
631 | ui_notify_evt(value->observers, &e); |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
632 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
633 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
634 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
635 | UIWIDGET ui_textfield_deprecated(UiObject *obj, UiString *value) { |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
636 | return create_textfield(obj, 0, FALSE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
637 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
638 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
639 | UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
640 | return create_textfield_nv(obj, 0, FALSE, FALSE, varname); |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
641 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
642 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
643 | UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
644 | return create_textfield(obj, width, FALSE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
645 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
646 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
647 | UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
648 | return create_textfield_nv(obj, width, FALSE, FALSE, varname); |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
649 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
650 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
651 | UIWIDGET ui_frameless_textfield_deprecated(UiObject *obj, UiString *value) { |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
652 | return create_textfield(obj, 0, TRUE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
653 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
654 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
655 | UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
656 | return create_textfield_nv(obj, 0, TRUE, FALSE, varname); |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
657 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
658 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
659 | UIWIDGET ui_passwordfield_deprecated(UiObject *obj, UiString *value) { |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
660 | return create_textfield(obj, 0, FALSE, TRUE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
661 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
662 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
663 | UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
664 | return create_textfield_nv(obj, 0, FALSE, TRUE, varname); |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
665 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
666 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
667 | UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
668 | return create_textfield(obj, width, FALSE, TRUE, value); |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
669 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
670 | |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
671 | UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
672 | return create_textfield_nv(obj, width, FALSE, TRUE, varname); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
673 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
674 | |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
675 | char* ui_textfield_get(UiString *str) { |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
676 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
677 | str->value.free(str->value.ptr); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
678 | } |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
679 | str->value.ptr = g_strdup(gtk_entry_get_text(str->obj)); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
680 | str->value.free = (ui_freefunc)g_free; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
681 | return str->value.ptr; |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
682 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
683 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
684 | void ui_textfield_set(UiString *str, const char *value) { |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
685 | gtk_entry_set_text(str->obj, value); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
686 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
687 | str->value.free(str->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
688 | str->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
689 | str->value.free = NULL; |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
690 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
691 | } |