Sun, 20 Oct 2024 21:26:06 +0200
make ui_getappdir() and ui_configfile() public
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 | |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
36 | #include <cx/printf.h> |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
37 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
38 | #include <gdk/gdkkeysyms.h> |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
39 | |
5 | 40 | |
174 | 41 | #include "../common/types.h" |
42 | ||
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
43 | static void selection_handler( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
44 | GtkTextBuffer *buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
45 | GtkTextIter *location, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
46 | GtkTextMark *mark, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
47 | UiTextArea *textview) |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
48 | { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
49 | 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
|
50 | if(mname) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
51 | GtkTextIter begin; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
52 | GtkTextIter end; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
53 | 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
|
54 | if(sel != textview->last_selection_state) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
55 | if(sel) { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
56 | 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
|
57 | } else { |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
58 | 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
|
59 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
60 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
61 | textview->last_selection_state = sel; |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
62 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
63 | } |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
64 | |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
65 | UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
66 | UiObject* current = uic_current_obj(obj); |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
67 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_TEXT); |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
68 | |
5 | 69 | GtkWidget *text_area = gtk_text_view_new(); |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
70 | ui_set_name_and_style(text_area, args.name, args.style_class); |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
71 | |
5 | 72 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); |
73 | g_signal_connect( | |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
74 | text_area, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
75 | "realize", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
76 | G_CALLBACK(ui_textarea_realize_event), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
77 | NULL); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
78 | |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
79 | UiTextArea *uitext = malloc(sizeof(UiTextArea)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
80 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
81 | uitext->var = var; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
82 | uitext->last_selection_state = 0; |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
83 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
84 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
85 | text_area, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
86 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
87 | G_CALLBACK(ui_textarea_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
88 | uitext); |
5 | 89 | |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
90 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
5 | 91 | gtk_scrolled_window_set_policy( |
92 | GTK_SCROLLED_WINDOW(scroll_area), | |
93 | GTK_POLICY_AUTOMATIC, | |
94 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS | |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
95 | SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); |
5 | 96 | |
97 | // font and padding | |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
98 | //PangoFontDescription *font; |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
99 | //font = pango_font_description_from_string("Monospace"); |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
100 | //gtk_widget_modify_font(text_area, font); // TODO |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
101 | //pango_font_description_free(font); |
5 | 102 | |
103 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); | |
104 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); | |
105 | ||
106 | // add | |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
107 | UI_APPLY_LAYOUT1(current, args); |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
108 | current->container->add(current->container, scroll_area, TRUE); |
5 | 109 | |
110 | // bind value | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
111 | UiText *value = var->value; |
5 | 112 | if(value) { |
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
113 | 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
|
114 | |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
115 | if(value->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
116 | 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
|
117 | 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
|
118 | } |
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
119 | |
5 | 120 | value->get = ui_textarea_get; |
121 | value->set = ui_textarea_set; | |
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
122 | value->getsubstr = ui_textarea_getsubstr; |
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
123 | value->insert = ui_textarea_insert; |
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
124 | 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
|
125 | 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
|
126 | value->selection = ui_textarea_selection; |
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
127 | 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
|
128 | value->remove = ui_textarea_remove; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
129 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
130 | value->value.free = NULL; |
5 | 131 | value->obj = buf; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
132 | if(!value->undomgr) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
133 | value->undomgr = ui_create_undomgr(); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
134 | } |
5 | 135 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
136 | g_signal_connect( |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
137 | buf, |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
138 | "changed", |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
139 | G_CALLBACK(ui_textbuf_changed), |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
140 | uitext); |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
141 | |
5 | 142 | // register undo manager |
143 | g_signal_connect( | |
144 | buf, | |
145 | "insert-text", | |
146 | G_CALLBACK(ui_textbuf_insert), | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
147 | var); |
5 | 148 | g_signal_connect( |
149 | buf, | |
150 | "delete-range", | |
151 | 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
|
152 | var); |
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
153 | g_signal_connect( |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
154 | buf, |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
155 | "mark-set", |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
156 | G_CALLBACK(selection_handler), |
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
157 | uitext); |
5 | 158 | } |
159 | ||
160 | return scroll_area; | |
161 | } | |
162 | ||
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
163 | void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
164 | ui_destroy_boundvar(textarea->ctx, textarea->var); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
165 | free(textarea); |
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 | |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
168 | UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
169 | return SCROLLEDWINDOW_GET_CHILD(textarea); |
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
170 | } |
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
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 | ||
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
186 | 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
|
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 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
266 | 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
|
267 | UiText *value = textarea->var->value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
268 | if(value->observers) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
269 | UiEvent e; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
270 | e.obj = textarea->ctx->obj; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
271 | e.window = e.obj->window; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
272 | e.document = textarea->ctx->document; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
273 | e.eventdata = value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
274 | e.intval = 0; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
275 | 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
|
276 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
277 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
278 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
279 | // undo manager functions |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
280 | |
5 | 281 | void ui_textbuf_insert( |
282 | GtkTextBuffer *textbuffer, | |
283 | GtkTextIter *location, | |
284 | char *text, | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
285 | int length, |
5 | 286 | void *data) |
287 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
288 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
289 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
290 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
291 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
292 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
293 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
294 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
295 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
296 | } |
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 | if(mgr->cur) { |
174 | 299 | UiTextBufOp *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
300 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
301 | mgr->cur->next = NULL; |
174 | 302 | mgr->end = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
303 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
304 | elm->prev = NULL; |
174 | 305 | UiTextBufOp *next = elm->next; |
306 | ui_free_textbuf_op(elm); | |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
307 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
308 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
309 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
310 | |
174 | 311 | UiTextBufOp *last_op = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
312 | if( |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
313 | last_op->type == UI_TEXTBUF_INSERT && |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
314 | 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
|
315 | { |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
316 | // append text to last op |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
317 | int ln = last_op->len; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
318 | char *newtext = malloc(ln + length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
319 | memcpy(newtext, last_op->text, ln); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
320 | memcpy(newtext+ln, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
321 | newtext[ln+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 | last_op->text = newtext; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
324 | last_op->len = ln + length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
325 | last_op->end += length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
326 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
327 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
328 | } |
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 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
331 | char *dpstr = malloc(length + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
332 | memcpy(dpstr, text, length); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
333 | dpstr[length] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
334 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
335 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
174 | 336 | op->prev = NULL; |
337 | op->next = NULL; | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
338 | op->type = UI_TEXTBUF_INSERT; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
339 | op->start = gtk_text_iter_get_offset(location); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
340 | op->end = op->start+length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
341 | op->len = length; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
342 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
343 | |
174 | 344 | cx_linked_list_add( |
345 | (void**)&mgr->begin, | |
346 | (void**)&mgr->end, | |
347 | offsetof(UiTextBufOp, prev), | |
348 | offsetof(UiTextBufOp, next), | |
349 | op); | |
350 | ||
351 | mgr->cur = op; | |
5 | 352 | } |
353 | ||
354 | void ui_textbuf_delete( | |
355 | GtkTextBuffer *textbuffer, | |
356 | GtkTextIter *start, | |
357 | GtkTextIter *end, | |
358 | void *data) | |
359 | { | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
360 | UiVar *var = data; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
361 | UiText *value = var->value; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
362 | if(!value->undomgr) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
363 | value->undomgr = ui_create_undomgr(); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
364 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
365 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
366 | if(!mgr->event) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
367 | return; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
368 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
369 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
370 | if(mgr->cur) { |
174 | 371 | UiTextBufOp *elm = mgr->cur->next; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
372 | if(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
373 | mgr->cur->next = NULL; |
174 | 374 | mgr->end = mgr->cur; |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
375 | while(elm) { |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
376 | elm->prev = NULL; |
174 | 377 | UiTextBufOp *next = elm->next; |
378 | ui_free_textbuf_op(elm); | |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
379 | elm = next; |
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
380 | } |
6
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 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
384 | 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
|
385 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
386 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
174 | 387 | op->prev = NULL; |
388 | op->next = NULL; | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
389 | op->type = UI_TEXTBUF_DELETE; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
390 | op->start = gtk_text_iter_get_offset(start); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
391 | op->end = gtk_text_iter_get_offset(end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
392 | op->len = op->end - op->start; |
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 *dpstr = malloc(op->len + 1); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
395 | memcpy(dpstr, text, op->len); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
396 | dpstr[op->len] = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
397 | op->text = dpstr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
398 | |
174 | 399 | cx_linked_list_add( |
400 | (void**)&mgr->begin, | |
401 | (void**)&mgr->end, | |
402 | offsetof(UiTextBufOp, prev), | |
403 | offsetof(UiTextBufOp, next), | |
404 | op); | |
405 | ||
406 | mgr->cur = op; | |
6
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 | UiUndoMgr* ui_create_undomgr() { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
410 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
411 | mgr->begin = NULL; |
174 | 412 | mgr->end = NULL; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
413 | mgr->cur = NULL; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
414 | mgr->length = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
415 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
416 | return mgr; |
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 | |
174 | 419 | void ui_destroy_undomgr(UiUndoMgr *mgr) { |
420 | UiTextBufOp *op = mgr->begin; | |
421 | while(op) { | |
422 | UiTextBufOp *nextOp = op->next; | |
423 | if(op->text) { | |
424 | free(op->text); | |
425 | } | |
426 | free(op); | |
427 | op = nextOp; | |
428 | } | |
429 | free(mgr); | |
430 | } | |
431 | ||
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
432 | void ui_free_textbuf_op(UiTextBufOp *op) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
433 | if(op->text) { |
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
434 | free(op->text); |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
435 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
436 | free(op); |
5 | 437 | } |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
438 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
439 | 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
|
440 | // return 1 if oldstr + newstr are one word |
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 | int has_space = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
443 | for(int i=0;i<oldlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
444 | if(oldstr[i] < 33) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
445 | has_space = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
446 | break; |
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 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
449 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
450 | for(int i=0;i<newlen;i++) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
451 | if(has_space && newstr[i] > 32) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
452 | return 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
453 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
454 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
455 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
456 | return 0; |
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 | void ui_text_undo(UiText *value) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
460 | UiUndoMgr *mgr = value->undomgr; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
461 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
462 | if(mgr->cur) { |
174 | 463 | UiTextBufOp *op = mgr->cur; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
464 | mgr->event = 0; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
465 | switch(op->type) { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
466 | case UI_TEXTBUF_INSERT: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
467 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
468 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
469 | 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
|
470 | 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
|
471 | gtk_text_buffer_delete(value->obj, &begin, &end); |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
472 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
473 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
474 | case UI_TEXTBUF_DELETE: { |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
475 | GtkTextIter begin; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
476 | GtkTextIter end; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
477 | 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
|
478 | 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
|
479 | 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
|
480 | break; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
481 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
482 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
483 | mgr->event = 1; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
484 | mgr->cur = mgr->cur->prev; |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
485 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
486 | } |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
487 | |
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
488 | void ui_text_redo(UiText *value) { |
8 | 489 | UiUndoMgr *mgr = value->undomgr; |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
490 | |
174 | 491 | UiTextBufOp *elm = NULL; |
8 | 492 | if(mgr->cur) { |
493 | if(mgr->cur->next) { | |
494 | elm = mgr->cur->next; | |
495 | } | |
496 | } else if(mgr->begin) { | |
497 | elm = mgr->begin; | |
498 | } | |
499 | ||
500 | if(elm) { | |
174 | 501 | UiTextBufOp *op = elm; |
8 | 502 | mgr->event = 0; |
503 | switch(op->type) { | |
504 | case UI_TEXTBUF_INSERT: { | |
505 | GtkTextIter begin; | |
506 | GtkTextIter end; | |
507 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
508 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
509 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); | |
510 | break; | |
511 | } | |
512 | case UI_TEXTBUF_DELETE: { | |
513 | GtkTextIter begin; | |
514 | GtkTextIter end; | |
515 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
516 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
517 | gtk_text_buffer_delete(value->obj, &begin, &end); | |
518 | break; | |
519 | } | |
520 | } | |
521 | mgr->event = 1; | |
522 | mgr->cur = elm; | |
523 | } | |
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
524 | } |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
525 | |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
526 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
527 | |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
528 | |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
529 | static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs args) { |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
530 | GtkWidget *textfield = gtk_entry_new(); |
313
b679cc6059ab
add option to name widgets and add css classes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
531 | ui_set_name_and_style(textfield, args.name, args.style_class); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
532 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
533 | UiObject* current = uic_current_obj(obj); |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
534 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
535 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
536 | UiTextField *uitext = malloc(sizeof(UiTextField)); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
537 | uitext->ctx = obj->ctx; |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
538 | uitext->var = var; |
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 | g_signal_connect( |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
541 | textfield, |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
542 | "destroy", |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
543 | G_CALLBACK(ui_textfield_destroy), |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
544 | uitext); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
545 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
546 | if(args.width > 0) { |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
547 | // TODO: gtk4 |
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
548 | #if GTK_MAJOR_VERSION <= 3 |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
549 | gtk_entry_set_width_chars(GTK_ENTRY(textfield), args.width); |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
550 | #endif |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
551 | } |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
552 | if(frameless) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
553 | // TODO: gtk2legacy workaroud |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
554 | 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
|
555 | } |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
556 | if(password) { |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
557 | gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
558 | } |
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
559 | |
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
560 | UI_APPLY_LAYOUT1(current, args); |
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
561 | current->container->add(current->container, textfield, FALSE); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
562 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
563 | if(var) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
564 | UiString *value = var->value; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
565 | if(value->value.ptr) { |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
566 | ENTRY_SET_TEXT(textfield, value->value.ptr); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
567 | value->value.free(value->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
568 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
569 | 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
|
570 | } |
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 | 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
|
573 | value->set = ui_textfield_set; |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
574 | value->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
575 | 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
|
576 | 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
|
577 | |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
578 | g_signal_connect( |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
579 | textfield, |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
580 | "changed", |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
581 | G_CALLBACK(ui_textfield_changed), |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
582 | uitext); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
583 | } |
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 | return textfield; |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
586 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
587 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
588 | UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
589 | return create_textfield(obj, FALSE, FALSE, args); |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
590 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
591 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
592 | UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
593 | return create_textfield(obj, TRUE, FALSE, args); |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
594 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
595 | |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
596 | UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
597 | return create_textfield(obj, FALSE, TRUE, args); |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
598 | } |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
599 | |
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
600 | |
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
601 | void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
602 | free(textfield); |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
603 | } |
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
604 | |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
605 | void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { |
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
606 | // changed event is only registered, if the textfield->var != NULL |
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
607 | UiString *value = textfield->var->value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
608 | if(value->observers) { |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
609 | UiEvent e; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
610 | e.obj = textfield->ctx->obj; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
611 | e.window = e.obj->window; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
612 | e.document = textfield->ctx->document; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
613 | e.eventdata = value; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
614 | e.intval = 0; |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
615 | 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
|
616 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
617 | } |
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
618 | |
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
619 | |
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
620 | 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
|
621 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
622 | 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
|
623 | } |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
624 | str->value.ptr = g_strdup(ENTRY_GET_TEXT(str->obj)); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
625 | 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
|
626 | 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
|
627 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
628 | |
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
629 | void ui_textfield_set(UiString *str, const char *value) { |
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
630 | ENTRY_SET_TEXT(str->obj, value); |
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
631 | if(str->value.ptr) { |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
632 | str->value.free(str->value.ptr); |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
633 | str->value.ptr = NULL; |
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
634 | 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
|
635 | } |
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
636 | } |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
637 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
638 | // ----------------------- path textfield ----------------------- |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
639 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
640 | // TODO: move to common |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
641 | static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
642 | cxstring *pathelms; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
643 | size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
644 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
645 | if (nelm == 0) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
646 | *ret_nelm = 0; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
647 | return NULL; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
648 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
649 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
650 | UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
651 | size_t n = nelm; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
652 | int j = 0; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
653 | for (int i = 0; i < nelm; i++) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
654 | cxstring c = pathelms[i]; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
655 | if (c.length == 0) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
656 | if (i == 0) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
657 | c.length = 1; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
658 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
659 | else { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
660 | n--; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
661 | continue; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
662 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
663 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
664 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
665 | cxmutstr m = cx_strdup(c); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
666 | elms[j].name = m.ptr; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
667 | elms[j].name_len = m.length; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
668 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
669 | size_t elm_path_len = c.ptr + c.length - full_path; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
670 | cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
671 | elms[j].path = elm_path.ptr; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
672 | elms[j].path_len = elm_path.length; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
673 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
674 | j++; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
675 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
676 | *ret_nelm = n; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
677 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
678 | return elms; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
679 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
680 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
681 | static void ui_pathelm_destroy(UiPathElm *elms, size_t nelm) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
682 | for(int i=0;i<nelm;i++) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
683 | free(elms[i].name); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
684 | free(elms[i].path); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
685 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
686 | free(elms); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
687 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
688 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
689 | static void ui_path_textfield_destroy(GtkWidget *object, UiPathTextField *pathtf) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
690 | g_object_unref(pathtf->entry); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
691 | free(pathtf); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
692 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
693 | |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
694 | void ui_path_button_clicked(GtkWidget *widget, UiEventDataExt *event) { |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
695 | UiPathTextField *pathtf = event->customdata1; |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
696 | for(int i=0;i<event->value1;i++) { |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
697 | if(i <= event->value0) { |
326 | 698 | WIDGET_REMOVE_CSS_CLASS(pathtf->current_path_buttons[i], "pathbar-button-inactive"); |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
699 | } else { |
326 | 700 | WIDGET_ADD_CSS_CLASS(pathtf->current_path_buttons[i], "pathbar-button-inactive"); |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
701 | } |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
702 | } |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
703 | |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
704 | UiPathElm *elm = event->customdata0; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
705 | cxmutstr path = cx_strdup(cx_strn(elm->path, elm->path_len)); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
706 | UiEvent evt; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
707 | evt.obj = event->obj; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
708 | evt.window = evt.obj->window; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
709 | evt.document = evt.obj->ctx->document; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
710 | evt.eventdata = elm->path; |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
711 | evt.intval = event->value0; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
712 | event->callback(&evt, event->userdata); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
713 | free(path.ptr); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
714 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
715 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
716 | int ui_pathtextfield_update(UiPathTextField* pathtf, const char *full_path) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
717 | size_t full_path_len = strlen(full_path); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
718 | if(full_path_len == 0) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
719 | return 1; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
720 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
721 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
722 | size_t nelm = 0; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
723 | UiPathElm* path_elm = pathtf->getpathelm(full_path, full_path_len, &nelm, pathtf->getpathelmdata); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
724 | if (!path_elm) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
725 | return 1; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
726 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
727 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
728 | free(pathtf->current_path); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
729 | pathtf->current_path = strdup(full_path); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
730 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
731 | ui_pathelm_destroy(pathtf->current_pathelms, pathtf->current_nelm); |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
732 | free(pathtf->current_path_buttons); |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
733 | pathtf->current_path_buttons = calloc(nelm, sizeof(GtkWidget*)); |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
734 | pathtf->current_pathelms = path_elm; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
735 | pathtf->current_nelm = nelm; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
736 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
737 | return ui_pathtextfield_update_widget(pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
738 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
739 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
740 | static GtkWidget* ui_path_elm_button(UiPathTextField *pathtf, UiPathElm *elm, int i) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
741 | cxmutstr name = cx_strdup(cx_strn(elm->name, elm->name_len)); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
742 | GtkWidget *button = gtk_button_new_with_label(name.ptr); |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
743 | pathtf->current_path_buttons[i] = button; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
744 | free(name.ptr); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
745 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
746 | if(pathtf->onactivate) { |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
747 | UiEventDataExt *eventdata = malloc(sizeof(UiEventDataExt)); |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
748 | memset(eventdata, 0, sizeof(UiEventDataExt)); |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
749 | eventdata->callback = pathtf->onactivate; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
750 | eventdata->userdata = pathtf->onactivatedata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
751 | eventdata->obj = pathtf->obj; |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
752 | eventdata->customdata0 = elm; |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
753 | eventdata->customdata1 = pathtf; |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
754 | eventdata->value0 = i; |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
755 | eventdata->value1 = pathtf->current_nelm; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
756 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
757 | g_signal_connect( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
758 | button, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
759 | "clicked", |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
760 | G_CALLBACK(ui_path_button_clicked), |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
761 | eventdata); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
762 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
763 | g_signal_connect( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
764 | button, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
765 | "destroy", |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
766 | G_CALLBACK(ui_destroy_userdata), |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
767 | eventdata); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
768 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
769 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
770 | return button; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
771 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
772 | |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
773 | static void ui_path_textfield_activate(GtkWidget *entry, UiPathTextField *pathtf) { |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
774 | const gchar *text = ENTRY_GET_TEXT(pathtf->entry); |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
775 | if(strlen(text) == 0) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
776 | return; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
777 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
778 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
779 | UiObject *obj = pathtf->obj; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
780 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
781 | if(ui_pathtextfield_update(pathtf, text)) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
782 | return; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
783 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
784 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
785 | if(pathtf->onactivate) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
786 | UiEvent evt; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
787 | evt.obj = obj; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
788 | evt.window = obj->window; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
789 | evt.document = obj->ctx->document; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
790 | evt.eventdata = (char*)text; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
791 | evt.intval = -1; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
792 | pathtf->onactivate(&evt, pathtf->onactivatedata); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
793 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
794 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
795 | |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
796 | #if GTK_MAJOR_VERSION >= 4 |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
797 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
798 | static void pathbar_show_hbox(GtkWidget *widget, UiPathTextField *pathtf) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
799 | if(pathtf->current_path) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
800 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
801 | ENTRY_SET_TEXT(pathtf->entry, pathtf->current_path); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
802 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
803 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
804 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
805 | static gboolean ui_path_textfield_key_controller( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
806 | GtkEventControllerKey* self, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
807 | guint keyval, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
808 | guint keycode, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
809 | GdkModifierType state, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
810 | UiPathTextField *pathtf) |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
811 | { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
812 | if(keyval == GDK_KEY_Escape) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
813 | pathbar_show_hbox(NULL, pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
814 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
815 | return FALSE; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
816 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
817 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
818 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
819 | UiObject* current = uic_current_obj(obj); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
820 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
821 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
822 | memset(pathtf, 0, sizeof(UiPathTextField)); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
823 | pathtf->obj = obj; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
824 | pathtf->getpathelm = args.getpathelm; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
825 | pathtf->getpathelmdata = args.getpathelmdata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
826 | pathtf->onactivate = args.onactivate; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
827 | pathtf->onactivatedata = args.onactivatedata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
828 | pathtf->ondragcomplete = args.ondragcomplete; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
829 | pathtf->ondragcompletedata = args.ondragcompletedata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
830 | pathtf->ondragstart = args.ondragstart; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
831 | pathtf->ondragstartdata = args.ondragstartdata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
832 | pathtf->ondrop = args.ondrop; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
833 | pathtf->ondropdata = args.ondropsdata; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
834 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
835 | if(!pathtf->getpathelm) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
836 | pathtf->getpathelm = default_pathelm_func; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
837 | pathtf->getpathelmdata = NULL; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
838 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
839 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
840 | pathtf->stack = gtk_stack_new(); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
841 | gtk_widget_set_name(pathtf->stack, "path-textfield-box"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
842 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
843 | UI_APPLY_LAYOUT1(current, args); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
844 | current->container->add(current->container, pathtf->stack, FALSE); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
845 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
846 | pathtf->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
847 | pathtf->entry = gtk_entry_new(); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
848 | gtk_box_append(GTK_BOX(pathtf->entry_box), pathtf->entry); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
849 | gtk_widget_set_hexpand(pathtf->entry, TRUE); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
850 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
851 | GtkWidget *cancel_button = gtk_button_new_from_icon_name("window-close-symbolic"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
852 | gtk_widget_add_css_class(cancel_button, "flat"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
853 | gtk_widget_add_css_class(cancel_button, "pathbar-extra-button"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
854 | gtk_box_append(GTK_BOX(pathtf->entry_box), cancel_button); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
855 | g_signal_connect( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
856 | cancel_button, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
857 | "clicked", |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
858 | G_CALLBACK(pathbar_show_hbox), |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
859 | pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
860 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
861 | gtk_stack_add_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
862 | g_object_ref(pathtf->entry); // for compatibility with older pathbar version |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
863 | g_signal_connect( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
864 | pathtf->entry, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
865 | "activate", |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
866 | G_CALLBACK(ui_path_textfield_activate), |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
867 | pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
868 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
869 | GtkEventController *entry_cancel = gtk_event_controller_key_new(); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
870 | gtk_widget_add_controller(pathtf->entry, entry_cancel); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
871 | g_signal_connect(entry_cancel, "key-pressed", G_CALLBACK(ui_path_textfield_key_controller), pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
872 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
873 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
874 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
875 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
876 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
877 | if (var) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
878 | UiString* value = (UiString*)var->value; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
879 | value->obj = pathtf; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
880 | value->get = ui_path_textfield_get; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
881 | value->set = ui_path_textfield_set; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
882 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
883 | if(value->value.ptr) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
884 | char *str = strdup(value->value.ptr); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
885 | ui_string_set(value, str); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
886 | free(str); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
887 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
888 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
889 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
890 | return pathtf->stack; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
891 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
892 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
893 | static void pathbar_pressed( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
894 | GtkGestureClick* self, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
895 | gint n_press, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
896 | gdouble x, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
897 | gdouble y, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
898 | UiPathTextField *pathtf) |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
899 | { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
900 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
901 | gtk_widget_grab_focus(pathtf->entry); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
902 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
903 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
904 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
905 | // recreate button hbox |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
906 | if(pathtf->hbox) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
907 | gtk_stack_remove(GTK_STACK(pathtf->stack), pathtf->hbox); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
908 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
909 | pathtf->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
910 | gtk_box_set_homogeneous(GTK_BOX(pathtf->hbox), FALSE); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
911 | gtk_stack_add_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
912 | gtk_widget_set_name(pathtf->hbox, "pathbar"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
913 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
914 | // add buttons for path elements |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
915 | for (int i=0;i<pathtf->current_nelm;i++) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
916 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
917 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
918 | GtkWidget *button = ui_path_elm_button(pathtf, elm, i); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
919 | gtk_widget_add_css_class(button, "flat"); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
920 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
921 | gtk_box_append(GTK_BOX(pathtf->hbox), button); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
922 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
923 | if(i+1 < pathtf->current_nelm && cx_strcmp(cx_strn(elm->name, elm->name_len), CX_STR("/"))) { |
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
924 | GtkWidget *path_separator = gtk_label_new("/"); |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
925 | gtk_widget_add_css_class(path_separator, "pathbar-button-inactive"); |
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
926 | gtk_box_append(GTK_BOX(pathtf->hbox), path_separator); |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
927 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
928 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
929 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
930 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
931 | // create a widget for receiving button press events |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
932 | GtkWidget *event_area = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
933 | GtkGesture *handler = gtk_gesture_click_new(); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
934 | gtk_widget_add_controller(event_area, GTK_EVENT_CONTROLLER(handler)); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
935 | g_signal_connect( |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
936 | handler, |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
937 | "pressed", |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
938 | G_CALLBACK(pathbar_pressed), |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
939 | pathtf); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
940 | gtk_widget_set_hexpand(event_area, TRUE); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
941 | gtk_widget_set_vexpand(event_area, TRUE); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
942 | gtk_box_append(GTK_BOX(pathtf->hbox), event_area); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
943 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
944 | return 0; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
945 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
946 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
947 | #else |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
948 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
949 | static gboolean path_textfield_btn_pressed(GtkWidget *widget, GdkEventButton *event, UiPathTextField *pathtf) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
950 | gtk_box_pack_start(GTK_BOX(pathtf->hbox), pathtf->entry, TRUE, TRUE, 0); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
951 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
952 | pathtf->buttonbox = NULL; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
953 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
954 | gtk_widget_show(pathtf->entry); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
955 | gtk_widget_grab_focus(pathtf->entry); |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
956 | |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
957 | return TRUE; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
958 | } |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
959 | |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
960 | static gboolean ui_path_textfield_key_press(GtkWidget *self, GdkEventKey *event, UiPathTextField *pathtf) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
961 | if (event->keyval == GDK_KEY_Escape) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
962 | // reset GtkEntry value |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
963 | gtk_entry_set_text(GTK_ENTRY(self), pathtf->current_path); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
964 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(self)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
965 | ui_pathtextfield_update(pathtf, text); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
966 | return TRUE; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
967 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
968 | return FALSE; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
969 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
970 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
971 | static GtkWidget* create_path_button_box() { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
972 | GtkWidget *bb = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
973 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bb), GTK_BUTTONBOX_EXPAND); // linked style |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
974 | gtk_box_set_homogeneous(GTK_BOX(bb), FALSE); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
975 | gtk_box_set_spacing(GTK_BOX(bb), 0); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
976 | return bb; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
977 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
978 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
979 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
980 | UiObject* current = uic_current_obj(obj); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
981 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
982 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
983 | memset(pathtf, 0, sizeof(UiPathTextField)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
984 | pathtf->obj = obj; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
985 | pathtf->getpathelm = args.getpathelm; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
986 | pathtf->getpathelmdata = args.getpathelmdata; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
987 | pathtf->onactivate = args.onactivate; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
988 | pathtf->onactivatedata = args.onactivatedata; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
989 | pathtf->ondragcomplete = args.ondragcomplete; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
990 | pathtf->ondragcompletedata = args.ondragcompletedata; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
991 | pathtf->ondragstart = args.ondragstart; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
992 | pathtf->ondragstartdata = args.ondragstartdata; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
993 | pathtf->ondrop = args.ondrop; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
994 | pathtf->ondropdata = args.ondropsdata; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
995 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
996 | if(!pathtf->getpathelm) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
997 | pathtf->getpathelm = default_pathelm_func; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
998 | pathtf->getpathelmdata = NULL; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
999 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1000 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1001 | // top level container for the path textfield is a GtkEventBox |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1002 | // the event box is needed to handle background button presses |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1003 | GtkWidget *eventbox = gtk_event_box_new(); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1004 | g_signal_connect( |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1005 | eventbox, |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1006 | "button-press-event", |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1007 | G_CALLBACK(path_textfield_btn_pressed), |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1008 | pathtf); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1009 | g_signal_connect( |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1010 | eventbox, |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1011 | "destroy", |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1012 | G_CALLBACK(ui_path_textfield_destroy), |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1013 | pathtf); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1014 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1015 | UI_APPLY_LAYOUT1(current, args); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1016 | current->container->add(current->container, eventbox, FALSE); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1017 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1018 | // hbox as parent for the GtkEntry and GtkButtonBox |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1019 | GtkWidget *hbox = ui_gtk_hbox_new(0); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1020 | pathtf->hbox = hbox; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1021 | gtk_container_add(GTK_CONTAINER(eventbox), hbox); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1022 | gtk_widget_set_name(hbox, "path-textfield-box"); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1023 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1024 | // create GtkEntry, that is also visible by default (with input yet) |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1025 | pathtf->entry = gtk_entry_new(); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1026 | g_object_ref(G_OBJECT(pathtf->entry)); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1027 | gtk_box_pack_start(GTK_BOX(hbox), pathtf->entry, TRUE, TRUE, 0); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1028 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1029 | g_signal_connect( |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1030 | pathtf->entry, |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1031 | "activate", |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1032 | G_CALLBACK(ui_path_textfield_activate), |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1033 | pathtf); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1034 | g_signal_connect( |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1035 | pathtf->entry, |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1036 | "key-press-event", |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1037 | G_CALLBACK(ui_path_textfield_key_press), |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1038 | pathtf); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1039 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1040 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1041 | if (var) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1042 | UiString* value = (UiString*)var->value; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1043 | value->obj = pathtf; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1044 | value->get = ui_path_textfield_get; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1045 | value->set = ui_path_textfield_set; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1046 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1047 | if(value->value.ptr) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1048 | char *str = strdup(value->value.ptr); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1049 | ui_string_set(value, str); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1050 | free(str); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1051 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1052 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1053 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1054 | return hbox; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1055 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1056 | |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1057 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1058 | GtkWidget *buttonbox = create_path_button_box(); |
289
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1059 | |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1060 | // switch from entry to buttonbox or remove current buttonbox |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1061 | if(pathtf->buttonbox) { |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1062 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1063 | } else { |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1064 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry); |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1065 | } |
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1066 | gtk_box_pack_start(GTK_BOX(pathtf->hbox), buttonbox, FALSE, FALSE, 0); |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1067 | pathtf->buttonbox = buttonbox; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1068 | |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1069 | for (int i=0;i<pathtf->current_nelm;i++) { |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1070 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1071 | GtkWidget *button = ui_path_elm_button(pathtf, elm, i); |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1072 | gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 0); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1073 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1074 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1075 | gtk_widget_show_all(buttonbox); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1076 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1077 | return 0; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1078 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1079 | |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1080 | #endif |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1081 | |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1082 | char* ui_path_textfield_get(UiString *str) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1083 | if(str->value.ptr) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1084 | str->value.free(str->value.ptr); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1085 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1086 | UiPathTextField *tf = str->obj; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1087 | str->value.ptr = g_strdup(ENTRY_GET_TEXT(tf->entry)); |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1088 | str->value.free = (ui_freefunc)g_free; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1089 | return str->value.ptr; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1090 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1091 | |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1092 | void ui_path_textfield_set(UiString *str, const char *value) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1093 | UiPathTextField *tf = str->obj; |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1094 | ENTRY_SET_TEXT(tf->entry, value); |
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1095 | ui_pathtextfield_update(tf, value); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1096 | if(str->value.ptr) { |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1097 | str->value.free(str->value.ptr); |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1098 | str->value.ptr = NULL; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1099 | str->value.free = NULL; |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1100 | } |
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1101 | } |