ui/gtk/text.c

Sun, 22 Sep 2024 16:39:10 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 22 Sep 2024 16:39:10 +0200
branch
newapi
changeset 302
b00cbbfeec7a
parent 298
c5e207d01ff2
child 310
4918f9132552
permissions
-rw-r--r--

add libadwaita toolkit option

5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "text.h"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
41 #include "../common/types.h"
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
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
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
65 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var) {
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 GtkWidget *text_area = gtk_text_view_new();
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 g_signal_connect(
22
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
69 text_area,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
70 "realize",
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
71 G_CALLBACK(ui_textarea_realize_event),
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
72 NULL);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
73
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
74 UiTextArea *uitext = malloc(sizeof(UiTextArea));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
75 uitext->ctx = obj->ctx;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
76 uitext->var = var;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
77 uitext->last_selection_state = 0;
22
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
78
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
79 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
80 text_area,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
81 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
82 G_CALLBACK(ui_textarea_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
83 uitext);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
85 GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 gtk_scrolled_window_set_policy(
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 GTK_SCROLLED_WINDOW(scroll_area),
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 GTK_POLICY_AUTOMATIC,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
90 SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 // font and padding
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 PangoFontDescription *font;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 font = pango_font_description_from_string("Monospace");
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
95 //gtk_widget_modify_font(text_area, font); // TODO
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 pango_font_description_free(font);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 // add
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
103 ct->add(ct, scroll_area, TRUE);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 // bind value
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
106 UiText *value = var->value;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 if(value) {
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108 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
109
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
110 if(value->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
111 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
112 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
113 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
114
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 value->get = ui_textarea_get;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 value->set = ui_textarea_set;
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
117 value->getsubstr = ui_textarea_getsubstr;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
118 value->insert = ui_textarea_insert;
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
119 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
120 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
121 value->selection = ui_textarea_selection;
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
122 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
123 value->remove = ui_textarea_remove;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
124 value->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
125 value->value.free = NULL;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 value->obj = buf;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
127 if(!value->undomgr) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
128 value->undomgr = ui_create_undomgr();
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
129 }
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
131 g_signal_connect(
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
132 buf,
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
133 "changed",
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
134 G_CALLBACK(ui_textbuf_changed),
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
135 uitext);
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
136
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 // register undo manager
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 g_signal_connect(
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 buf,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 "insert-text",
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 G_CALLBACK(ui_textbuf_insert),
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
142 var);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 g_signal_connect(
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 buf,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 "delete-range",
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 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
147 var);
22
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
148 g_signal_connect(
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
149 buf,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
150 "mark-set",
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
151 G_CALLBACK(selection_handler),
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
152 uitext);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 return scroll_area;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
158 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
159 ui_destroy_boundvar(textarea->ctx, textarea->var);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
160 free(textarea);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
161 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
162
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
163 UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
163
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
164 UiVar *var = malloc(sizeof(UiVar));
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
165 var->value = value;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
166 var->type = UI_VAR_SPECIAL;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
167 var->from = NULL;
b70e2a77dea0 refactore document system to support document trees
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
168 var->from_ctx = NULL;
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
169 return ui_textarea_var(obj, var);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
170 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
171
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
172 UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
173 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_TEXT);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
174 if(var) {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
175 return ui_textarea_var(obj, var);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
176 } else {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
177 // TODO: error
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
178 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
179 return NULL;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
180 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
181
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
182 UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) {
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
183 return SCROLLEDWINDOW_GET_CHILD(textarea);
168
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
184 }
1b99acacc5bb refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 167
diff changeset
185
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 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
187 if(text->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
188 text->value.free(text->value.ptr);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 GtkTextBuffer *buf = text->obj;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 GtkTextIter start;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 GtkTextIter end;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 gtk_text_buffer_get_bounds(buf, &start, &end);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 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
195 text->value.ptr = g_strdup(str);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
196 text->value.free = (ui_freefunc)g_free;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 return str;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
200 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
201 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
202 if(text->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
203 text->value.free(text->value.ptr);
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
204 }
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
205 text->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
206 text->value.free = NULL;
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
207 }
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 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
210 if(text->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
211 text->value.free(text->value.ptr);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
213 GtkTextBuffer *buf = text->obj;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
214 GtkTextIter ib;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
215 GtkTextIter ie;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
216 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
217 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
218 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
219 text->value.ptr = g_strdup(str);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
220 text->value.free = (ui_freefunc)g_free;
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
221 return str;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
222 }
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
223
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
224 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
225 GtkTextIter offset;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
226 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
227 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
228 if(text->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
229 text->value.free(text->value.ptr);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
230 }
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
231 text->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
232 text->value.free = NULL;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
235 void ui_textarea_setposition(UiText *text, int pos) {
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
236 GtkTextIter iter;
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
237 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
238 gtk_text_buffer_place_cursor(text->obj, &iter);
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
239 }
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
240
27
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
241 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
242 GtkTextIter begin;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
243 GtkTextIter end;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
244 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
245 text->pos = gtk_text_iter_get_offset(&begin);
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
246 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
247 }
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
248
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
249 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
250 GtkTextIter b;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
251 GtkTextIter e;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
252 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
253 *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
254 *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
255 }
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
256
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
257 int ui_textarea_length(UiText *text) {
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
258 GtkTextBuffer *buf = text->obj;
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
259 GtkTextIter start;
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
260 GtkTextIter end;
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
261 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
262 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
263 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
264
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
265 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
266 GtkTextBuffer *buf = text->obj;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
267 GtkTextIter ib;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
268 GtkTextIter ie;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
269 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
270 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
271 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
272 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
273
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 void ui_textarea_realize_event(GtkWidget *widget, gpointer data) {
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 gtk_widget_grab_focus(widget);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
278
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
279
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
280 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
281 UiText *value = textarea->var->value;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
282 if(value->observers) {
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
283 UiEvent e;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
284 e.obj = textarea->ctx->obj;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
285 e.window = e.obj->window;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
286 e.document = textarea->ctx->document;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
287 e.eventdata = value;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
288 e.intval = 0;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
289 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
290 }
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
291 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
292
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
293 // undo manager functions
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
294
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 void ui_textbuf_insert(
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 GtkTextBuffer *textbuffer,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 GtkTextIter *location,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 char *text,
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
299 int length,
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 void *data)
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
302 UiVar *var = data;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
303 UiText *value = var->value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
304 if(!value->undomgr) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
305 value->undomgr = ui_create_undomgr();
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
306 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
307 UiUndoMgr *mgr = value->undomgr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
308 if(!mgr->event) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
309 return;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
310 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
311
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
312 if(mgr->cur) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
313 UiTextBufOp *elm = mgr->cur->next;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
314 if(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
315 mgr->cur->next = NULL;
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
316 mgr->end = mgr->cur;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
317 while(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
318 elm->prev = NULL;
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
319 UiTextBufOp *next = elm->next;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
320 ui_free_textbuf_op(elm);
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
321 elm = next;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
322 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
323 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
324
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
325 UiTextBufOp *last_op = mgr->cur;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
326 if(
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
327 last_op->type == UI_TEXTBUF_INSERT &&
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
328 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
329 {
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
330 // append text to last op
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
331 int ln = last_op->len;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
332 char *newtext = malloc(ln + length + 1);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
333 memcpy(newtext, last_op->text, ln);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
334 memcpy(newtext+ln, text, length);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
335 newtext[ln+length] = '\0';
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
336
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
337 last_op->text = newtext;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
338 last_op->len = ln + length;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
339 last_op->end += length;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
340
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
341 return;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
342 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
343 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
344
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
345 char *dpstr = malloc(length + 1);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
346 memcpy(dpstr, text, length);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
347 dpstr[length] = 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
348
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
349 UiTextBufOp *op = malloc(sizeof(UiTextBufOp));
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
350 op->prev = NULL;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
351 op->next = NULL;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
352 op->type = UI_TEXTBUF_INSERT;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
353 op->start = gtk_text_iter_get_offset(location);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
354 op->end = op->start+length;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
355 op->len = length;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
356 op->text = dpstr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
357
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
358 cx_linked_list_add(
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
359 (void**)&mgr->begin,
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
360 (void**)&mgr->end,
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
361 offsetof(UiTextBufOp, prev),
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
362 offsetof(UiTextBufOp, next),
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
363 op);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
364
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
365 mgr->cur = op;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 void ui_textbuf_delete(
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 GtkTextBuffer *textbuffer,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 GtkTextIter *start,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 GtkTextIter *end,
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 void *data)
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 {
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
374 UiVar *var = data;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
375 UiText *value = var->value;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
376 if(!value->undomgr) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
377 value->undomgr = ui_create_undomgr();
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
378 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
379 UiUndoMgr *mgr = value->undomgr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
380 if(!mgr->event) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
381 return;
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 if(mgr->cur) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
385 UiTextBufOp *elm = mgr->cur->next;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
386 if(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
387 mgr->cur->next = NULL;
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
388 mgr->end = mgr->cur;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
389 while(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
390 elm->prev = NULL;
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
391 UiTextBufOp *next = elm->next;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
392 ui_free_textbuf_op(elm);
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
393 elm = next;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
394 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
395 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
396 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
397
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
398 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
399
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
400 UiTextBufOp *op = malloc(sizeof(UiTextBufOp));
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
401 op->prev = NULL;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
402 op->next = NULL;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
403 op->type = UI_TEXTBUF_DELETE;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
404 op->start = gtk_text_iter_get_offset(start);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
405 op->end = gtk_text_iter_get_offset(end);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
406 op->len = op->end - op->start;
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 char *dpstr = malloc(op->len + 1);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
409 memcpy(dpstr, text, op->len);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
410 dpstr[op->len] = 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
411 op->text = dpstr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
412
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
413 cx_linked_list_add(
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
414 (void**)&mgr->begin,
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
415 (void**)&mgr->end,
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
416 offsetof(UiTextBufOp, prev),
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
417 offsetof(UiTextBufOp, next),
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
418 op);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
419
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
420 mgr->cur = op;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
421 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
422
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
423 UiUndoMgr* ui_create_undomgr() {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
424 UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr));
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
425 mgr->begin = NULL;
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
426 mgr->end = NULL;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
427 mgr->cur = NULL;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
428 mgr->length = 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
429 mgr->event = 1;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
430 return mgr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
431 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
432
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
433 void ui_destroy_undomgr(UiUndoMgr *mgr) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
434 UiTextBufOp *op = mgr->begin;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
435 while(op) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
436 UiTextBufOp *nextOp = op->next;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
437 if(op->text) {
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
438 free(op->text);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
439 }
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
440 free(op);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
441 op = nextOp;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
442 }
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
443 free(mgr);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
444 }
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
445
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
446 void ui_free_textbuf_op(UiTextBufOp *op) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
447 if(op->text) {
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
448 free(op->text);
6
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 free(op);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
452
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
453 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
454 // return 1 if oldstr + newstr are one word
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 int has_space = 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
457 for(int i=0;i<oldlen;i++) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
458 if(oldstr[i] < 33) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
459 has_space = 1;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
460 break;
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 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
463
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
464 for(int i=0;i<newlen;i++) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
465 if(has_space && newstr[i] > 32) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
466 return 1;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
467 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
468 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
469
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
470 return 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
471 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
472
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
473 void ui_text_undo(UiText *value) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
474 UiUndoMgr *mgr = value->undomgr;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
475
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
476 if(mgr->cur) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
477 UiTextBufOp *op = mgr->cur;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
478 mgr->event = 0;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
479 switch(op->type) {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
480 case UI_TEXTBUF_INSERT: {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
481 GtkTextIter begin;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
482 GtkTextIter end;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
483 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
484 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
485 gtk_text_buffer_delete(value->obj, &begin, &end);
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
486 break;
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 case UI_TEXTBUF_DELETE: {
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
489 GtkTextIter begin;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
490 GtkTextIter end;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
491 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
492 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
493 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
494 break;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
495 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
496 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
497 mgr->event = 1;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
498 mgr->cur = mgr->cur->prev;
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
499 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
500 }
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
501
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
502 void ui_text_redo(UiText *value) {
8
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
503 UiUndoMgr *mgr = value->undomgr;
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
504
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
505 UiTextBufOp *elm = NULL;
8
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
506 if(mgr->cur) {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
507 if(mgr->cur->next) {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
508 elm = mgr->cur->next;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
509 }
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
510 } else if(mgr->begin) {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
511 elm = mgr->begin;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
512 }
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
513
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
514 if(elm) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
515 UiTextBufOp *op = elm;
8
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
516 mgr->event = 0;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
517 switch(op->type) {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
518 case UI_TEXTBUF_INSERT: {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
519 GtkTextIter begin;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
520 GtkTextIter end;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
521 gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
522 gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
523 gtk_text_buffer_insert(value->obj, &begin, op->text, op->len);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
524 break;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
525 }
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
526 case UI_TEXTBUF_DELETE: {
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
527 GtkTextIter begin;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
528 GtkTextIter end;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
529 gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
530 gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
531 gtk_text_buffer_delete(value->obj, &begin, &end);
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
532 break;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
533 }
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
534 }
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
535 mgr->event = 1;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
536 mgr->cur = elm;
84a541c6e093 added redo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
537 }
6
05a18c56d9ca added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
538 }
65
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
539
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
540
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
541
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
542
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
543 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
544 GtkWidget *textfield = gtk_entry_new();
140
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 UiObject* current = uic_current_obj(obj);
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
547 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
548
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
549 UiTextField *uitext = malloc(sizeof(UiTextField));
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
550 uitext->ctx = obj->ctx;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
551 uitext->var = var;
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
552
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
553 g_signal_connect(
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
554 textfield,
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
555 "destroy",
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
556 G_CALLBACK(ui_textfield_destroy),
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
557 uitext);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
558
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
559 if(args.width > 0) {
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
560 // TODO: gtk4
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
561 #if GTK_MAJOR_VERSION <= 3
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
562 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
563 #endif
94
d51e334c1439 added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
564 }
121
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
565 if(frameless) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
566 // TODO: gtk2legacy workaroud
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
567 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
568 }
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
569 if(password) {
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
570 gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE);
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
571 }
94
d51e334c1439 added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
572
65
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
573 UiContainer *ct = uic_get_current_container(obj);
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
574 ct->add(ct, textfield, FALSE);
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
575
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
576 if(var) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
577 UiString *value = var->value;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
578 if(value->value.ptr) {
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
579 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
580 value->value.free(value->value.ptr);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
581 value->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
582 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
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 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
586 value->set = ui_textfield_set;
141
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
587 value->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
588 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
589 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
590
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
591 g_signal_connect(
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
592 textfield,
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
593 "changed",
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
594 G_CALLBACK(ui_textfield_changed),
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
595 uitext);
65
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
596 }
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
597
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
598 return textfield;
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
599 }
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
600
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
601 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
602 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
603 }
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
604
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
605 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
606 return create_textfield(obj, TRUE, FALSE, args);
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
607 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
608
267
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
609 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
610 return create_textfield(obj, FALSE, TRUE, args);
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
611 }
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
612
79dd183dd4cb port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 253
diff changeset
613
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
614 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) {
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
615 free(textfield);
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
616 }
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
617
143
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
618 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
619 // 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
620 UiString *value = textfield->var->value;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
621 if(value->observers) {
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
622 UiEvent e;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
623 e.obj = textfield->ctx->obj;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
624 e.window = e.obj->window;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
625 e.document = textfield->ctx->document;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
626 e.eventdata = value;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
627 e.intval = 0;
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
628 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
629 }
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
630 }
d499b29d7cb6 adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
631
121
1cc365c34125 added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 94
diff changeset
632
65
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
633 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
634 if(str->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
635 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
636 }
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
637 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
638 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
639 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
640 }
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
641
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
642 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
643 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
644 if(str->value.ptr) {
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
645 str->value.free(str->value.ptr);
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
646 str->value.ptr = NULL;
cc2170ea05ad improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
647 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
648 }
4697592e24ba added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
649 }
282
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
650
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
651 // ----------------------- path textfield -----------------------
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
652
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
653 // TODO: move to common
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
654 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
655 cxstring *pathelms;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
656 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
657
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
658 if (nelm == 0) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
659 *ret_nelm = 0;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
660 return NULL;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
661 }
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 UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
664 size_t n = nelm;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
665 int j = 0;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
666 for (int i = 0; i < nelm; i++) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
667 cxstring c = pathelms[i];
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
668 if (c.length == 0) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
669 if (i == 0) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
670 c.length = 1;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
671 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
672 else {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
673 n--;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
674 continue;
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 }
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 cxmutstr m = cx_strdup(c);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
679 elms[j].name = m.ptr;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
680 elms[j].name_len = m.length;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
681
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
682 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
683 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
684 elms[j].path = elm_path.ptr;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
685 elms[j].path_len = elm_path.length;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
686
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
687 j++;
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 *ret_nelm = n;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
690
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
691 return elms;
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
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
694
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
695 #if GTK_MAJOR_VERSION >= 4
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
696
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
697 UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) {
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
698 // TODO
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
699 return NULL;
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
700 }
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
701
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
702 #else
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
703
282
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
704 static gboolean path_textfield_btn_pressed(GtkWidget *widget, GdkEventButton *event, UiPathTextField *pathtf) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
705 gtk_box_pack_start(GTK_BOX(pathtf->hbox), pathtf->entry, TRUE, TRUE, 0);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
706 gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox);
289
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
707 pathtf->buttonbox = NULL;
282
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
708
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
709 gtk_widget_show(pathtf->entry);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
710 gtk_widget_grab_focus(pathtf->entry);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
711
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
712 return TRUE;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
713 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
714
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
715 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
716 for(int i=0;i<nelm;i++) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
717 free(elms[i].name);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
718 free(elms[i].path);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
719 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
720 free(elms);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
721 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
722
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
723 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
724 free(pathtf->current_path);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
725 g_object_unref(pathtf->entry);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
726 free(pathtf);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
727 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
728
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
729 static void ui_path_textfield_activate(GtkWidget *entry, UiPathTextField *pathtf) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
730 const gchar *text = gtk_entry_get_text(GTK_ENTRY(pathtf->entry));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
731 if(strlen(text) == 0) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
732 return;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
733 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
734
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
735 UiObject *obj = pathtf->obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
736
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
737 if(ui_pathtextfield_update(pathtf, text)) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
738 return;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
739 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
740
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
741 if(pathtf->onactivate) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
742 UiEvent evt;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
743 evt.obj = obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
744 evt.window = obj->window;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
745 evt.document = obj->ctx->document;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
746 evt.eventdata = (char*)text;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
747 evt.intval = -1;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
748 pathtf->onactivate(&evt, pathtf->onactivatedata);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
749 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
750 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
751
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
752 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
753 if (event->keyval == GDK_KEY_Escape) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
754 // reset GtkEntry value
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
755 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
756 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
757 ui_pathtextfield_update(pathtf, text);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
758 return TRUE;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
759 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
760 return FALSE;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
761 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
762
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
763 static GtkWidget* create_path_button_box() {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
764 GtkWidget *bb = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
765 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
766 gtk_box_set_homogeneous(GTK_BOX(bb), FALSE);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
767 gtk_box_set_spacing(GTK_BOX(bb), 0);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
768 return bb;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
769 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
770
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
771 UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
772 UiObject* current = uic_current_obj(obj);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
773
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
774 UiPathTextField *pathtf = malloc(sizeof(UiPathTextField));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
775 memset(pathtf, 0, sizeof(UiPathTextField));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
776 pathtf->obj = obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
777 pathtf->getpathelm = args.getpathelm;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
778 pathtf->getpathelmdata = args.getpathelmdata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
779 pathtf->onactivate = args.onactivate;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
780 pathtf->onactivatedata = args.onactivatedata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
781 pathtf->ondragcomplete = args.ondragcomplete;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
782 pathtf->ondragcompletedata = args.ondragcompletedata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
783 pathtf->ondragstart = args.ondragstart;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
784 pathtf->ondragstartdata = args.ondragstartdata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
785 pathtf->ondrop = args.ondrop;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
786 pathtf->ondropdata = args.ondropsdata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
787
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
788 if(!pathtf->getpathelm) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
789 pathtf->getpathelm = default_pathelm_func;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
790 pathtf->getpathelmdata = NULL;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
791 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
792
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
793 // 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
794 // 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
795 GtkWidget *eventbox = gtk_event_box_new();
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
796 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
797 eventbox,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
798 "button-press-event",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
799 G_CALLBACK(path_textfield_btn_pressed),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
800 pathtf);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
801 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
802 eventbox,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
803 "destroy",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
804 G_CALLBACK(ui_path_textfield_destroy),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
805 pathtf);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
806
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
807 UI_APPLY_LAYOUT1(current, args);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
808 current->container->add(current->container, eventbox, FALSE);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
809
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
810 // hbox as parent for the GtkEntry and GtkButtonBox
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
811 GtkWidget *hbox = ui_gtk_hbox_new(0);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
812 pathtf->hbox = hbox;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
813 gtk_container_add(GTK_CONTAINER(eventbox), hbox);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
814 gtk_widget_set_name(hbox, "path-textfield-box");
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
815
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
816 // 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
817 pathtf->entry = gtk_entry_new();
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
818 g_object_ref(G_OBJECT(pathtf->entry));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
819 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
820
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
821 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
822 pathtf->entry,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
823 "activate",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
824 G_CALLBACK(ui_path_textfield_activate),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
825 pathtf);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
826 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
827 pathtf->entry,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
828 "key-press-event",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
829 G_CALLBACK(ui_path_textfield_key_press),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
830 pathtf);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
831
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
832 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
833 if (var) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
834 UiString* value = (UiString*)var->value;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
835 value->obj = pathtf;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
836 value->get = ui_path_textfield_get;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
837 value->set = ui_path_textfield_set;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
838
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
839 if(value->value.ptr) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
840 char *str = strdup(value->value.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
841 ui_string_set(value, str);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
842 free(str);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
843 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
844 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
845
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
846 return hbox;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
847 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
848
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
849 void ui_path_button_clicked(GtkWidget *widget, UiEventData *event) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
850 UiPathElm *elm = event->customdata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
851 cxmutstr path = cx_strdup(cx_strn(elm->path, elm->path_len));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
852 UiEvent evt;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
853 evt.obj = event->obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
854 evt.window = evt.obj->window;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
855 evt.document = evt.obj->ctx->document;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
856 evt.eventdata = elm->path;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
857 evt.intval = event->value;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
858 event->callback(&evt, event->userdata);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
859 free(path.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
860 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
861
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
862 int ui_pathtextfield_update(UiPathTextField* pathtf, const char *full_path) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
863 size_t full_path_len = strlen(full_path);
289
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
864 if(full_path_len == 0) {
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
865 return 1;
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
866 }
282
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
867
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
868 size_t nelm = 0;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
869 UiPathElm* path_elm = pathtf->getpathelm(full_path, full_path_len, &nelm, pathtf->getpathelmdata);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
870 if (!path_elm) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
871 return 1;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
872 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
873
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
874 free(pathtf->current_path);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
875 pathtf->current_path = strdup(full_path);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
876
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
877 ui_pathelm_destroy(pathtf->current_pathelms, pathtf->current_nelm);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
878 pathtf->current_pathelms = path_elm;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
879 pathtf->current_nelm = nelm;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
880
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
881 GtkWidget *buttonbox = create_path_button_box();
289
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
882
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
883 // switch from entry to buttonbox or remove current buttonbox
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
884 if(pathtf->buttonbox) {
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
885 gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox);
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
886 } else {
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
887 gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry);
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
888 }
6048b20bd46f fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 282
diff changeset
889 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
890 pathtf->buttonbox = buttonbox;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
891
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
892 for (int i=0;i<nelm;i++) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
893 UiPathElm *elm = &path_elm[i];
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
894
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
895 cxmutstr name = cx_strdup(cx_strn(elm->name, elm->name_len));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
896 GtkWidget *button = gtk_button_new_with_label(name.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
897 free(name.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
898
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
899 if(pathtf->onactivate) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
900 UiEventData *eventdata = malloc(sizeof(UiEventData));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
901 eventdata->callback = pathtf->onactivate;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
902 eventdata->userdata = pathtf->onactivatedata;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
903 eventdata->obj = pathtf->obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
904 eventdata->customdata = elm;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
905 eventdata->value = i;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
906
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
907 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
908 button,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
909 "clicked",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
910 G_CALLBACK(ui_path_button_clicked),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
911 eventdata);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
912
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
913 g_signal_connect(
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
914 button,
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
915 "destroy",
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
916 G_CALLBACK(ui_destroy_userdata),
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
917 eventdata);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
918 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
919
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
920 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
921 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
922
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
923 gtk_widget_show_all(buttonbox);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
924
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
925 return 0;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
926 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
927
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
928 char* ui_path_textfield_get(UiString *str) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
929 if(str->value.ptr) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
930 str->value.free(str->value.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
931 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
932 UiPathTextField *tf = str->obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
933 str->value.ptr = g_strdup(gtk_entry_get_text(GTK_ENTRY(tf->entry)));
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
934 str->value.free = (ui_freefunc)g_free;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
935 return str->value.ptr;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
936 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
937
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
938 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
939 UiPathTextField *tf = str->obj;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
940 gtk_entry_set_text(GTK_ENTRY(tf->entry), value);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
941 ui_pathtextfield_update(tf, value);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
942 if(str->value.ptr) {
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
943 str->value.free(str->value.ptr);
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
944 str->value.ptr = NULL;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
945 str->value.free = NULL;
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
946 }
3a77b9048664 add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 267
diff changeset
947 }
298
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
948
c5e207d01ff2 port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
949 #endif

mercurial