Sat, 11 Nov 2017 08:34:06 +0100
new checkbox and radionbutton features and more refactoring
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 | |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
37 | static void selection_handler( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
38 | GtkTextBuffer *buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
39 | GtkTextIter *location, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
40 | GtkTextMark *mark, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
41 | UiTextArea *textview) |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
42 | { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
43 | 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
|
44 | if(mname) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
45 | GtkTextIter begin; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
46 | GtkTextIter end; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
47 | 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
|
48 | if(sel != textview->last_selection_state) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
49 | if(sel) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
50 | 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
|
51 | } else { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
52 | 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
|
53 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
54 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
55 | textview->last_selection_state = sel; |
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 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
58 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
59 | UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var) { |
5 | 60 | GtkWidget *text_area = gtk_text_view_new(); |
61 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); | |
62 | g_signal_connect( | |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
63 | text_area, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
64 | "realize", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | G_CALLBACK(ui_textarea_realize_event), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
66 | NULL); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
67 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
68 | UiTextArea *uitext = malloc(sizeof(UiTextArea)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
69 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
70 | uitext->var = var; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
71 | uitext->last_selection_state = 0; |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
72 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
73 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
74 | text_area, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
75 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
76 | G_CALLBACK(ui_textarea_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
77 | uitext); |
5 | 78 | |
79 | GtkWidget *scroll_area = gtk_scrolled_window_new (NULL, NULL); | |
80 | gtk_scrolled_window_set_policy( | |
81 | GTK_SCROLLED_WINDOW(scroll_area), | |
82 | GTK_POLICY_AUTOMATIC, | |
83 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS | |
84 | gtk_container_add(GTK_CONTAINER(scroll_area), text_area); | |
85 | ||
86 | // font and padding | |
87 | PangoFontDescription *font; | |
88 | font = pango_font_description_from_string("Monospace"); | |
89 | gtk_widget_modify_font(text_area, font); | |
90 | pango_font_description_free(font); | |
91 | ||
92 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); | |
93 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); | |
94 | ||
95 | // add | |
96 | UiContainer *ct = uic_get_current_container(obj); | |
59
eb6611be50c7
added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
97 | ct->add(ct, scroll_area, TRUE); |
5 | 98 | |
99 | // bind value | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
100 | UiText *value = var->value; |
5 | 101 | if(value) { |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
102 | 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
|
103 | |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
104 | if(value->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
105 | 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
|
106 | 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
|
107 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
108 | |
5 | 109 | value->get = ui_textarea_get; |
110 | value->set = ui_textarea_set; | |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
111 | value->getsubstr = ui_textarea_getsubstr; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
112 | value->insert = ui_textarea_insert; |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
113 | 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
|
114 | 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
|
115 | value->selection = ui_textarea_selection; |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
116 | 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
|
117 | value->remove = ui_textarea_remove; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
118 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
119 | value->value.free = NULL; |
5 | 120 | value->obj = buf; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
121 | if(!value->undomgr) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
122 | value->undomgr = ui_create_undomgr(); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
123 | } |
5 | 124 | |
125 | // register undo manager | |
126 | g_signal_connect( | |
127 | buf, | |
128 | "insert-text", | |
129 | G_CALLBACK(ui_textbuf_insert), | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
130 | var); |
5 | 131 | g_signal_connect( |
132 | buf, | |
133 | "delete-range", | |
134 | G_CALLBACK(ui_textbuf_delete), | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
135 | var); |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
136 | |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
137 | g_signal_connect( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
138 | buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
139 | "mark-set", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
140 | G_CALLBACK(selection_handler), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
141 | uitext); |
5 | 142 | } |
143 | ||
144 | return scroll_area; | |
145 | } | |
146 | ||
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
147 | void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
148 | ui_destroy_boundvar(textarea->ctx, textarea->var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
149 | free(textarea); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
150 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
151 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
152 | UIWIDGET ui_textarea(UiObject *obj, UiText *value) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
153 | UiVar *var = NULL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
154 | if(value) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
155 | var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
156 | var->value = value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
157 | var->type = UI_VAR_SPECIAL; |
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 | return ui_textarea_var(obj, var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
160 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
161 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
162 | UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
163 | 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
|
164 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
165 | 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
|
166 | } else { |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
167 | // TODO: error |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
168 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
169 | return NULL; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
170 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
171 | |
5 | 172 | 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
|
173 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
174 | text->value.free(text->value.ptr); |
5 | 175 | } |
176 | GtkTextBuffer *buf = text->obj; | |
177 | GtkTextIter start; | |
178 | GtkTextIter end; | |
179 | gtk_text_buffer_get_bounds(buf, &start, &end); | |
180 | 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
|
181 | text->value.ptr = g_strdup(str); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
182 | text->value.free = (ui_freefunc)g_free; |
5 | 183 | return str; |
184 | } | |
185 | ||
186 | void ui_textarea_set(UiText *text, char *str) { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
187 | 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
|
188 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
189 | text->value.free(text->value.ptr); |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
190 | } |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
191 | text->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
192 | text->value.free = NULL; |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
193 | } |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
194 | |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
195 | 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
|
196 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
197 | text->value.free(text->value.ptr); |
5 | 198 | } |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
199 | GtkTextBuffer *buf = text->obj; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
200 | GtkTextIter ib; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
201 | GtkTextIter ie; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | text->value.ptr = g_strdup(str); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
206 | text->value.free = (ui_freefunc)g_free; |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
207 | return str; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
208 | } |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
209 | |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
210 | 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
|
211 | GtkTextIter offset; |
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, &offset, pos); |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
213 | 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
|
214 | if(text->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
215 | text->value.free(text->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
216 | } |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
217 | text->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
218 | text->value.free = NULL; |
5 | 219 | } |
220 | ||
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
221 | void ui_textarea_setposition(UiText *text, int pos) { |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
222 | GtkTextIter iter; |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
223 | 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
|
224 | gtk_text_buffer_place_cursor(text->obj, &iter); |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
225 | } |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
226 | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
227 | 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
|
228 | GtkTextIter begin; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
229 | GtkTextIter end; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
230 | 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
|
231 | text->pos = gtk_text_iter_get_offset(&begin); |
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
232 | 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
|
233 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
234 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
235 | 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
|
236 | GtkTextIter b; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
237 | GtkTextIter e; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
238 | 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
|
239 | *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
|
240 | *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
|
241 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
242 | |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
243 | int ui_textarea_length(UiText *text) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
244 | GtkTextBuffer *buf = text->obj; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
245 | GtkTextIter start; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
246 | GtkTextIter end; |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
247 | 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
|
248 | 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
|
249 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
250 | |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
251 | 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
|
252 | GtkTextBuffer *buf = text->obj; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
253 | GtkTextIter ib; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
254 | GtkTextIter ie; |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
255 | 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
|
256 | 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
|
257 | 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
|
258 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
259 | |
5 | 260 | void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
261 | gtk_widget_grab_focus(widget); | |
262 | } | |
263 | ||
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
264 | |
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
265 | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
266 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
267 | // undo manager functions |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
268 | |
5 | 269 | void ui_textbuf_insert( |
270 | GtkTextBuffer *textbuffer, | |
271 | GtkTextIter *location, | |
272 | char *text, | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
273 | int length, |
5 | 274 | void *data) |
275 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
276 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
277 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
278 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
279 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
280 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
281 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
282 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
283 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
284 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
285 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
286 | if(mgr->cur) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
287 | UcxList *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
288 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
289 | mgr->cur->next = NULL; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
290 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
291 | elm->prev = NULL; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
292 | UcxList *next = elm->next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
293 | ui_free_textbuf_op(elm->data); |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
294 | free(elm); |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
295 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
296 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
297 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
298 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
299 | UiTextBufOp *last_op = mgr->cur->data; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
300 | if( |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
301 | last_op->type == UI_TEXTBUF_INSERT && |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
302 | 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
|
303 | { |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
304 | // append text to last op |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
305 | int ln = last_op->len; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
306 | char *newtext = malloc(ln + length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
307 | memcpy(newtext, last_op->text, ln); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
308 | memcpy(newtext+ln, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
309 | newtext[ln+length] = '\0'; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
310 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
311 | last_op->text = newtext; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
312 | last_op->len = ln + length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
313 | last_op->end += length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
314 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
315 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
316 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
317 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
318 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
319 | char *dpstr = malloc(length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
320 | memcpy(dpstr, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
321 | dpstr[length] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
322 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
323 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
324 | op->type = UI_TEXTBUF_INSERT; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
325 | op->start = gtk_text_iter_get_offset(location); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
326 | op->end = op->start+length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
327 | op->len = length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
328 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
329 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
330 | UcxList *elm = ucx_list_append(NULL, op); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
331 | mgr->cur = elm; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
332 | mgr->begin = ucx_list_concat(mgr->begin, elm); |
5 | 333 | } |
334 | ||
335 | void ui_textbuf_delete( | |
336 | GtkTextBuffer *textbuffer, | |
337 | GtkTextIter *start, | |
338 | GtkTextIter *end, | |
339 | void *data) | |
340 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
341 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
342 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
343 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
344 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
345 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
346 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
347 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
348 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
349 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
350 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
351 | if(mgr->cur) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
352 | UcxList *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
353 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
354 | mgr->cur->next = NULL; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
355 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
356 | elm->prev = NULL; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
357 | UcxList *next = elm->next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
358 | ui_free_textbuf_op(elm->data); |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
359 | free(elm); |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
360 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
361 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
362 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
363 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
364 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
365 | 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
|
366 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
367 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
368 | op->type = UI_TEXTBUF_DELETE; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
369 | op->start = gtk_text_iter_get_offset(start); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
370 | op->end = gtk_text_iter_get_offset(end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
371 | op->len = op->end - op->start; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
372 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
373 | char *dpstr = malloc(op->len + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
374 | memcpy(dpstr, text, op->len); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
375 | dpstr[op->len] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
376 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
377 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
378 | UcxList *elm = ucx_list_append(NULL, op); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
379 | mgr->cur = elm; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
380 | mgr->begin = ucx_list_concat(mgr->begin, elm); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
381 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
382 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
383 | UiUndoMgr* ui_create_undomgr() { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
384 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
385 | mgr->begin = NULL; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
386 | mgr->cur = NULL; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
387 | mgr->length = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
388 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
389 | return mgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
390 | } |
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 | void ui_free_textbuf_op(UiTextBufOp *op) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
393 | if(op->text) { |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
394 | free(op->text); |
6
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 | free(op); |
5 | 397 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
398 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
399 | 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
|
400 | // return 1 if oldstr + newstr are one word |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
401 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
402 | int has_space = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
403 | for(int i=0;i<oldlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
404 | if(oldstr[i] < 33) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
405 | has_space = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
406 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
407 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
408 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
409 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
410 | for(int i=0;i<newlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
411 | if(has_space && newstr[i] > 32) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
412 | return 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
413 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
414 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
415 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
416 | return 0; |
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 | void ui_text_undo(UiText *value) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
420 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
421 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
422 | if(mgr->cur) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
423 | UiTextBufOp *op = mgr->cur->data; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
424 | mgr->event = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
425 | switch(op->type) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
426 | case UI_TEXTBUF_INSERT: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
427 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
428 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
429 | 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
|
430 | 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
|
431 | gtk_text_buffer_delete(value->obj, &begin, &end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
432 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
433 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
434 | case UI_TEXTBUF_DELETE: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
435 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
436 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
437 | 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
|
438 | 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
|
439 | 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
|
440 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
441 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
442 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
443 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
444 | mgr->cur = mgr->cur->prev; |
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 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
447 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
448 | void ui_text_redo(UiText *value) { |
8 | 449 | UiUndoMgr *mgr = value->undomgr; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
450 | |
8 | 451 | UcxList *elm = NULL; |
452 | if(mgr->cur) { | |
453 | if(mgr->cur->next) { | |
454 | elm = mgr->cur->next; | |
455 | } | |
456 | } else if(mgr->begin) { | |
457 | elm = mgr->begin; | |
458 | } | |
459 | ||
460 | if(elm) { | |
461 | UiTextBufOp *op = elm->data; | |
462 | mgr->event = 0; | |
463 | switch(op->type) { | |
464 | case UI_TEXTBUF_INSERT: { | |
465 | GtkTextIter begin; | |
466 | GtkTextIter end; | |
467 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
468 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
469 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); | |
470 | break; | |
471 | } | |
472 | case UI_TEXTBUF_DELETE: { | |
473 | GtkTextIter begin; | |
474 | GtkTextIter end; | |
475 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
476 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
477 | gtk_text_buffer_delete(value->obj, &begin, &end); | |
478 | break; | |
479 | } | |
480 | } | |
481 | mgr->event = 1; | |
482 | mgr->cur = elm; | |
483 | } | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
484 | } |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
485 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
486 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
487 | 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
|
488 | GtkWidget *textfield = gtk_entry_new(); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
489 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
490 | UiTextField *uitext = malloc(sizeof(UiTextField)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
491 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
492 | uitext->var = var; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
493 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
494 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
495 | textfield, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
496 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
497 | G_CALLBACK(ui_textfield_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
498 | uitext); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
499 | |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
500 | if(width > 0) { |
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
501 | 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
|
502 | } |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
503 | if(frameless) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
504 | // TODO: gtk2legacy workaroud |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
505 | 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
|
506 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
507 | if(password) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
508 | gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
509 | } |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
510 | |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
511 | 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
|
512 | 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
|
513 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
514 | if(var) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
515 | UiString *value = var->value; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
516 | if(value->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
517 | 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
|
518 | value->value.free(value->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
519 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
520 | 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
|
521 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
522 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
523 | 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
|
524 | value->set = ui_textfield_set; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
525 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
526 | 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
|
527 | value->obj = GTK_ENTRY(textfield); |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
528 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
529 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
530 | return textfield; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
531 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
532 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
533 | 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
|
534 | 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
|
535 | if(var) { |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
536 | 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
|
537 | } else { |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
538 | // TODO: error |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
539 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
540 | return NULL; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
541 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
542 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
543 | 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
|
544 | UiVar *var = NULL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
545 | if(value) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
546 | var = malloc(sizeof(UiVar)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
547 | var->value = value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
548 | var->type = UI_VAR_SPECIAL; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
549 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
550 | return create_textfield_var(obj, width, frameless, password, var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
551 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
552 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
553 | void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
554 | ui_destroy_boundvar(textfield->ctx, textfield->var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
555 | free(textfield); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
556 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
557 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
558 | UIWIDGET ui_textfield(UiObject *obj, UiString *value) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
559 | return create_textfield(obj, 0, FALSE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
560 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
561 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
562 | UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
563 | 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
|
564 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
565 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
566 | 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
|
567 | return create_textfield(obj, width, FALSE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
568 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
569 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
570 | 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
|
571 | 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
|
572 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
573 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
574 | UIWIDGET ui_frameless_textfield(UiObject *obj, UiString *value) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
575 | return create_textfield(obj, 0, TRUE, FALSE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
576 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
577 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
578 | 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
|
579 | 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
|
580 | } |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
581 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
582 | UIWIDGET ui_passwordfield(UiObject *obj, UiString *value) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
583 | return create_textfield(obj, 0, FALSE, TRUE, value); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
584 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
585 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
586 | UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) { |
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
587 | 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
|
588 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
589 | |
122
e82b01d17a78
added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
121
diff
changeset
|
590 | 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
|
591 | 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
|
592 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
593 | |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
594 | 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
|
595 | 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
|
596 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
597 | |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
598 | 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
|
599 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
600 | 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
|
601 | } |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
602 | 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
|
603 | 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
|
604 | 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
|
605 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
606 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
607 | void ui_textfield_set(UiString *str, char *value) { |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
608 | 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
|
609 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
610 | str->value.free(str->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
611 | str->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
612 | 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
|
613 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
614 | } |