ui/motif/text.c

Sun, 29 Sep 2024 19:01:47 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Sep 2024 19:01:47 +0200
branch
newapi
changeset 317
b30415965ec3
parent 253
087cc9216f28
permissions
-rw-r--r--

implement ui_savefiledialog name parameter (GTK)

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 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
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>
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "text.h"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "container.h"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
35
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
36 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var) {
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 UiContainer *ct = uic_get_current_container(obj);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 int n = 0;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 Arg args[16];
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 //XtSetArg(args[n], XmNeditable, TRUE);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 //n++;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 n++;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
60
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
46 Widget parent = ct->prepare(ct, args, &n, TRUE);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 Widget text_area = XmCreateScrolledText(parent, "text_area", args, n);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
48 ct->add(ct, XtParent(text_area));
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 XtManageChild(text_area);
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
51 UiTextArea *uitext = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
52 obj->ctx->allocator,
22
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
53 sizeof(UiTextArea));
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
54 uitext->ctx = obj->ctx;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
55 uitext->last_selection_state = 0;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
56 XtAddCallback(
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
57 text_area,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
58 XmNmotionVerifyCallback,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
59 (XtCallbackProc)ui_text_selection_callback,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
60 uitext);
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
61
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 // bind value
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
63 if(var->value) {
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
64 UiText *value = var->value;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
65 if(value->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
66 XmTextSetString(text_area, value->value.ptr);
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
67 value->value.free(value->value.ptr);
36
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
68 }
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
69
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
70 value->set = ui_textarea_set;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 value->get = ui_textarea_get;
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
72 value->getsubstr = ui_textarea_getsubstr;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
73 value->insert = ui_textarea_insert;
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
74 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
75 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
76 value->selection = ui_textarea_selection;
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
77 value->length = ui_textarea_length;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
78 value->value.ptr = NULL;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 value->obj = text_area;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
80
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
81 if(!value->undomgr) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
82 value->undomgr = ui_create_undomgr();
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
83 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
84
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
85 XtAddCallback(
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
86 text_area,
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
87 XmNmodifyVerifyCallback,
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
88 (XtCallbackProc)ui_text_modify_callback,
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
89 var);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
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 return text_area;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
95 UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
96 UiVar *var = malloc(sizeof(UiVar));
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
97 var->value = value;
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
98 var->type = UI_VAR_SPECIAL;
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
99 return ui_textarea_var(obj, var);
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
100 }
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
101
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
102 UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
103 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_TEXT);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
104 if(var) {
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
105 return ui_textarea_var(obj, var);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
106 } else {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
107 // TODO: error
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
108 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
109 return NULL;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
110 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
111
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 char* ui_textarea_get(UiText *text) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
113 if(text->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
114 text->value.free(text->value.ptr);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 char *str = XmTextGetString(text->obj);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
117 text->value.ptr = str;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
118 text->value.free = (ui_freefunc)XtFree;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return str;
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
253
087cc9216f28 initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 176
diff changeset
122 void ui_textarea_set(UiText *text, const char *str) {
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
123 XmTextSetString(text->obj, str);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
124 if(text->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
125 text->value.free(text->value.ptr);
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
127 text->value.ptr = NULL;
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
129
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
130 char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
131 if(text->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
132 text->value.free(text->value.ptr);
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
133 }
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
134 int length = end - begin;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
135 char *str = XtMalloc(length + 1);
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
136 XmTextGetSubstring(text->obj, begin, length, length + 1, str);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
137 text->value.ptr = str;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
138 text->value.free = (ui_freefunc)XtFree;
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
139 return str;
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
140 }
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
141
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
142 void ui_textarea_insert(UiText *text, int pos, char *str) {
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
143 text->value.ptr = NULL;
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
144 XmTextInsert(text->obj, pos, str);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
145 if(text->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
146 text->value.free(text->value.ptr);
12
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
147 }
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
148 }
fe94e0fb9ef3 added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
149
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
150 void ui_textarea_setposition(UiText *text, int pos) {
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
151 XmTextSetInsertionPosition(text->obj, pos);
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
152 }
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
153
27
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
154 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
155 long begin;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
156 long end;
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
157 XmTextGetSelectionPosition(text->obj, &begin, &end);
90
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
158 text->pos = begin;
2019fdbaadfd persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
159 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
160 }
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
161
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
162 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
163 XmTextGetSelectionPosition(text->obj, (long*)begin, (long*)end);
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
164 }
77b09bb52ca0 added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
165
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
166 int ui_textarea_length(UiText *text) {
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
167 return (int)XmTextGetLastPosition(text->obj);
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
168 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
169
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
170
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
171 void ui_text_set(UiText *text, char *str) {
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
172 if(text->set) {
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
173 text->set(text, str);
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
174 } else {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
175 if(text->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
176 text->value.free(text->value.ptr);
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
177 }
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
178 text->value.ptr = XtNewString(str);
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
179 text->value.free = (ui_freefunc)XtFree;
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
180 }
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
181 }
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
182
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
183 char* ui_text_get(UiText *text) {
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
184 if(text->get) {
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
185 return text->get(text);
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
186 } else {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
187 return text->value.ptr;
131
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
188 }
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
189 }
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
190
774b741984a2 detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
191
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
192 UiUndoMgr* ui_create_undomgr() {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
193 UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr));
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
194 mgr->begin = NULL;
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
195 mgr->end = NULL;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
196 mgr->cur = NULL;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
197 mgr->length = 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
198 mgr->event = 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
199 return mgr;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
200 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
201
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
202 void ui_destroy_undomgr(UiUndoMgr *mgr) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
203 UiTextBufOp *op = mgr->begin;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
204 while(op) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
205 UiTextBufOp *nextOp = op->next;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
206 if(op->text) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
207 free(op->text);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
208 }
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
209 free(op);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
210 op = nextOp;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
211 }
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
212 free(mgr);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
213 }
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
214
22
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
215 void ui_text_selection_callback(
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
216 Widget widget,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
217 UiTextArea *textarea,
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
218 XtPointer data)
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
219 {
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
220 long left = 0;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
221 long right = 0;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
222 XmTextGetSelectionPosition(widget, &left, &right);
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
223 int sel = left < right ? 1 : 0;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
224 if(sel != textarea->last_selection_state) {
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
225 if(sel) {
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
226 ui_set_group(textarea->ctx, UI_GROUP_SELECTION);
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
227 } else {
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
228 ui_unset_group(textarea->ctx, UI_GROUP_SELECTION);
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
229 }
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
230 }
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
231 textarea->last_selection_state = sel;
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
232 }
bcf880b29bc3 textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
233
155
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
234 void ui_text_modify_callback(Widget widget, UiVar *var, XtPointer data) {
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
235 UiText *value = var->value;
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
236 if(!value->obj) {
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
237 // TODO: bug, fix
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
238 return;
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
239 }
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
240 if(!value->undomgr) {
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
241 value->undomgr = ui_create_undomgr();
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
242 }
b907d8059290 fixes document switching with textareas (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
243
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
244 XmTextVerifyCallbackStruct *txv = (XmTextVerifyCallbackStruct*)data;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
245 int type = txv->text->length > 0 ? UI_TEXTBUF_INSERT : UI_TEXTBUF_DELETE;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
246 UiUndoMgr *mgr = value->undomgr;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
247 if(!mgr->event) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
248 return;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
249 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
250
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
251 char *text = txv->text->ptr;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
252 int length = txv->text->length;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
253
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
254 if(mgr->cur) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
255 UiTextBufOp *elm = mgr->cur->next;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
256 if(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
257 mgr->cur->next = NULL;
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
258 mgr->end = mgr->cur;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
259 while(elm) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
260 elm->prev = NULL;
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
261 UiTextBufOp *next = elm->next;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
262 ui_free_textbuf_op(elm);
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
263 elm = next;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
264 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
265 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
266
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
267 UiTextBufOp *last_op = mgr->cur;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
268 if(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
269 last_op->type == UI_TEXTBUF_INSERT &&
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
270 ui_check_insertstr(last_op->text, last_op->len, text, length) == 0)
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
271 {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
272 // append text to last op
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
273 int ln = last_op->len;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
274 char *newtext = malloc(ln + length + 1);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
275 memcpy(newtext, last_op->text, ln);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
276 memcpy(newtext+ln, text, length);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
277 newtext[ln+length] = '\0';
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
278
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
279 last_op->text = newtext;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
280 last_op->len = ln + length;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
281 last_op->end += length;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
282
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
283 return;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
284 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
285 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
286
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
287 char *str;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
288 if(type == UI_TEXTBUF_INSERT) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
289 str = malloc(length + 1);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
290 memcpy(str, text, length);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
291 str[length] = 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
292 } else {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
293 length = txv->endPos - txv->startPos;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
294 str = malloc(length + 1);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
295 XmTextGetSubstring(value->obj, txv->startPos, length, length+1, str);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
296 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
297
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
298 UiTextBufOp *op = malloc(sizeof(UiTextBufOp));
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
299 op->prev = NULL;
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
300 op->next = NULL;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
301 op->type = type;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
302 op->start = txv->startPos;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
303 op->end = txv->endPos + 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
304 op->len = length;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
305 op->text = str;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
306
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
307 cx_linked_list_add(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
308 (void**)&mgr->begin,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
309 (void**)&mgr->end,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
310 offsetof(UiTextBufOp, prev),
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
311 offsetof(UiTextBufOp, next),
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
312 op);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
313
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
314 mgr->cur = op;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
315 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
316
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
317 int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
318 // return 1 if oldstr + newstr are one word
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
319
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
320 int has_space = 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
321 for(int i=0;i<oldlen;i++) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
322 if(oldstr[i] < 33) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
323 has_space = 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
324 break;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
325 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
326 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
327
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
328 for(int i=0;i<newlen;i++) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
329 if(has_space && newstr[i] > 32) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
330 return 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
331 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
332 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
333
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
334 return 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
335 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
336
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
337 void ui_free_textbuf_op(UiTextBufOp *op) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
338 if(op->text) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
339 free(op->text);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
340 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
341 free(op);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
342 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
343
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
344
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
345 void ui_text_undo(UiText *value) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
346 UiUndoMgr *mgr = value->undomgr;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
347
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
348 if(mgr->cur) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
349 UiTextBufOp *op = mgr->cur;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
350 mgr->event = 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
351 switch(op->type) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
352 case UI_TEXTBUF_INSERT: {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
353 XmTextReplace(value->obj, op->start, op->end, "");
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
354 break;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
355 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
356 case UI_TEXTBUF_DELETE: {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
357 XmTextInsert(value->obj, op->start, op->text);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
358 break;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
359 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
360 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
361 mgr->event = 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
362 mgr->cur = mgr->cur->prev;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
363 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
364 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
365
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
366 void ui_text_redo(UiText *value) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
367 UiUndoMgr *mgr = value->undomgr;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
368
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
369 UiTextBufOp *elm = NULL;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
370 if(mgr->cur) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
371 if(mgr->cur->next) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
372 elm = mgr->cur->next;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
373 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
374 } else if(mgr->begin) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
375 elm = mgr->begin;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
376 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
377
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
378 if(elm) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 155
diff changeset
379 UiTextBufOp *op = elm;
9
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
380 mgr->event = 0;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
381 switch(op->type) {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
382 case UI_TEXTBUF_INSERT: {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
383 XmTextInsert(value->obj, op->start, op->text);
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
384 break;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
385 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
386 case UI_TEXTBUF_DELETE: {
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
387 XmTextReplace(value->obj, op->start, op->end, "");
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
388 break;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
389 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
390 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
391 mgr->event = 1;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
392 mgr->cur = elm;
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
393 }
e70e855cea89 added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
394 }
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
395
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
396
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
397 /* ------------------------- textfield ------------------------- */
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
398
122
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
399 static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) {
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
400 UiContainer *ct = uic_get_current_container(obj);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
401 int n = 0;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
402 Arg args[16];
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
403 XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
404 n++;
122
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
405 if(width > 0) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
406 XtSetArg(args[n], XmNcolumns, width / 2 + 1);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
407 n++;
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
408 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
409 if(frameless) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
410 XtSetArg(args[n], XmNshadowThickness, 0);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
411 n++;
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
412 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
413 if(password) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
414 // TODO
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
415 }
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
416
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
417 Widget parent = ct->prepare(ct, args, &n, FALSE);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
418 Widget textfield = XmCreateText(parent, "text_field", args, n);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
419 ct->add(ct, textfield);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
420 XtManageChild(textfield);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
421
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
422 // bind value
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
423 if(value) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
424 if(value->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
425 XmTextSetString(textfield, value->value.ptr);
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
426 value->value.free(value->value.ptr);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
427 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
428
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
429 value->set = ui_textfield_set;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
430 value->get = ui_textfield_get;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
431 value->value.ptr = NULL;
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
432 value->obj = textfield;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
433 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
434
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
435 return textfield;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
436 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
437
122
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
438 static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
439 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_STRING);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
440 if(var) {
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
441 UiString *value = var->value;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
442 return ui_textfield(obj, value);
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
443 } else {
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
444 // TODO: error
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
445 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
446 return NULL;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
447 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
448
122
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
449 UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
450 return create_textfield(obj, 0, FALSE, FALSE, value);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
451 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
452
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
453 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
454 return create_textfield_nv(obj, 0, FALSE, FALSE, varname);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
455 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
456
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
457 UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
458 return create_textfield(obj, width, FALSE, FALSE, value);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
459 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
460
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
461 UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
462 return create_textfield_nv(obj, width, FALSE, FALSE, varname);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
463 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
464
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
465 UIWIDGET ui_frameless_textfield(UiObject *obj, UiString *value) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
466 return create_textfield(obj, 0, TRUE, FALSE, value);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
467 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
468
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
469 UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
470 return create_textfield_nv(obj, 0, TRUE, FALSE, varname);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
471 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
472
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
473 UIWIDGET ui_passwordfield(UiObject *obj, UiString *value) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
474 return create_textfield(obj, 0, FALSE, TRUE, value);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
475 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
476
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
477 UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
478 return create_textfield_nv(obj, 0, FALSE, TRUE, varname);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
479 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
480
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
481 UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
482 return create_textfield(obj, width, FALSE, TRUE, value);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
483 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
484
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
485 UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) {
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
486 return create_textfield_nv(obj, width, FALSE, TRUE, varname);
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
487 }
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
488
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 90
diff changeset
489
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
490 char* ui_textfield_get(UiString *str) {
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
491 if(str->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
492 str->value.free(str->value.ptr);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
493 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
494 char *value = XmTextGetString(str->obj);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
495 str->value.ptr = value;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
496 str->value.free = (ui_freefunc)XtFree;
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
497 return value;
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
498 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
499
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
500 void ui_textfield_set(UiString *str, char *value) {
154
8a4451fcb736 fixes ui_textfield_set (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
501 XmTextSetString(str->obj, value);
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
502 if(str->value.ptr) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
503 str->value.free(str->value.ptr);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
504 }
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 131
diff changeset
505 str->value.ptr = NULL;
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
506 }
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
507

mercurial