2 weeks ago
move ui_customwidget to separate file
5 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
450
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
4 | * Copyright 2025 Olaf Wintermann. All rights reserved. |
5 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
31 | #include <unistd.h> |
5 | 32 | |
33 | #include "text.h" | |
34 | #include "container.h" | |
35 | ||
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
36 | #include <cx/string.h> |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
37 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
38 | |
450
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
39 | /* ------------------------------ Text Area ------------------------------ */ |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
40 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
41 | UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
42 | Arg xargs[16]; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
43 | int n = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
44 | |
452
a0620cf552a6
add first code for motif tabview (incomplete)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
450
diff
changeset
|
45 | XtSetArg(xargs[n], XmNeditMode, XmMULTI_LINE_EDIT); n++; |
a0620cf552a6
add first code for motif tabview (incomplete)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
450
diff
changeset
|
46 | |
450
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
47 | UiContainerPrivate *ctn = ui_obj_container(obj); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
48 | UI_APPLY_LAYOUT(ctn->layout, args); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
49 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
50 | Widget parent = ctn->prepare(ctn, xargs, &n); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
51 | char *name = args.name ? (char*)args.name : "textarea"; |
459
4ea4bb379273
limit textarea width (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
452
diff
changeset
|
52 | XtSetArg(xargs[n], XmNwidth, 100); n++; |
450
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
53 | Widget widget = XmCreateScrolledText(parent, name, xargs, n); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
54 | XtManageChild(widget); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
55 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
56 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_TEXT); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
57 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
58 | UiTextArea *textarea = malloc(sizeof(UiTextArea)); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
59 | memset(textarea, 0, sizeof(UiTextArea)); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
60 | textarea->obj = obj; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
61 | textarea->var = var; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
62 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
63 | if(var) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
64 | UiText *value = var->value; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
65 | if(value->value.ptr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
66 | XmTextSetString(widget, value->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
67 | value->value.free(value->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
68 | value->value.ptr = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
69 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
70 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
71 | value->set = ui_textarea_set; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
72 | value->get = ui_textarea_get; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
73 | value->getsubstr = ui_textarea_getsubstr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
74 | value->insert = ui_textarea_insert; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
75 | value->setposition = ui_textarea_setposition; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
76 | value->position = ui_textarea_position; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
77 | value->selection = ui_textarea_selection; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
78 | value->length = ui_textarea_length; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
79 | value->value.ptr = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
80 | value->obj = widget; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
81 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
82 | if(!value->undomgr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
83 | value->undomgr = ui_create_undomgr(); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
84 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
85 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
86 | XtAddCallback( |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
87 | widget, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
88 | XmNmodifyVerifyCallback, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
89 | (XtCallbackProc)ui_text_modify_callback, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
90 | var); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
91 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
92 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
93 | return widget; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
94 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
95 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
96 | char* ui_textarea_get(UiText *text) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
97 | if(text->value.ptr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
98 | text->value.free(text->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
99 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
100 | char *str = XmTextGetString(text->obj); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
101 | text->value.ptr = str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
102 | text->value.free = (ui_freefunc)XtFree; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
103 | return str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
104 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
105 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
106 | void ui_textarea_set(UiText *text, const char *str) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
107 | XmTextSetString(text->obj, (char*)str); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
108 | if(text->value.ptr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
109 | text->value.free(text->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
110 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
111 | text->value.ptr = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
112 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
113 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
114 | char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
115 | if(text->value.ptr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
116 | text->value.free(text->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
117 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
118 | int length = end - begin; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
119 | char *str = XtMalloc(length + 1); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
120 | XmTextGetSubstring(text->obj, begin, length, length + 1, str); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
121 | text->value.ptr = str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
122 | text->value.free = (ui_freefunc)XtFree; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
123 | return str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
124 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
125 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
126 | void ui_textarea_insert(UiText *text, int pos, char *str) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
127 | text->value.ptr = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
128 | XmTextInsert(text->obj, pos, str); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
129 | if(text->value.ptr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
130 | text->value.free(text->value.ptr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
131 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
132 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
133 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
134 | void ui_textarea_setposition(UiText *text, int pos) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
135 | XmTextSetInsertionPosition(text->obj, pos); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
136 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
137 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
138 | int ui_textarea_position(UiText *text) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
139 | long begin; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
140 | long end; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
141 | XmTextGetSelectionPosition(text->obj, &begin, &end); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
142 | text->pos = begin; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
143 | return text->pos; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
144 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
145 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
146 | void ui_textarea_selection(UiText *text, int *begin, int *end) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
147 | XmTextGetSelectionPosition(text->obj, (long*)begin, (long*)end); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
148 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
149 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
150 | int ui_textarea_length(UiText *text) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
151 | return (int)XmTextGetLastPosition(text->obj); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
152 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
153 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
154 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
155 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
156 | UiUndoMgr* ui_create_undomgr() { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
157 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
158 | mgr->begin = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
159 | mgr->end = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
160 | mgr->cur = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
161 | mgr->length = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
162 | mgr->event = 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
163 | return mgr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
164 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
165 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
166 | void ui_destroy_undomgr(UiUndoMgr *mgr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
167 | UiTextBufOp *op = mgr->begin; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
168 | while(op) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
169 | UiTextBufOp *nextOp = op->next; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
170 | if(op->text) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
171 | free(op->text); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
172 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
173 | free(op); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
174 | op = nextOp; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
175 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
176 | free(mgr); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
177 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
178 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
179 | void ui_text_selection_callback( |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
180 | Widget widget, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
181 | UiTextArea *textarea, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
182 | XtPointer data) |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
183 | { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
184 | long left = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
185 | long right = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
186 | XmTextGetSelectionPosition(widget, &left, &right); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
187 | int sel = left < right ? 1 : 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
188 | if(sel != textarea->last_selection_state) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
189 | if(sel) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
190 | ui_set_group(textarea->obj->ctx, UI_GROUP_SELECTION); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
191 | } else { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
192 | ui_unset_group(textarea->obj->ctx, UI_GROUP_SELECTION); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
193 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
194 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
195 | textarea->last_selection_state = sel; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
196 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
197 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
198 | void ui_text_modify_callback(Widget widget, UiVar *var, XtPointer data) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
199 | UiText *value = var->value; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
200 | if(!value->obj) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
201 | // TODO: bug, fix |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
202 | return; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
203 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
204 | if(!value->undomgr) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
205 | value->undomgr = ui_create_undomgr(); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
206 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
207 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
208 | XmTextVerifyCallbackStruct *txv = (XmTextVerifyCallbackStruct*)data; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
209 | int type = txv->text->length > 0 ? UI_TEXTBUF_INSERT : UI_TEXTBUF_DELETE; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
210 | UiUndoMgr *mgr = value->undomgr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
211 | if(!mgr->event) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
212 | return; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
213 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
214 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
215 | char *text = txv->text->ptr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
216 | int length = txv->text->length; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
217 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
218 | if(mgr->cur) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
219 | UiTextBufOp *elm = mgr->cur->next; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
220 | if(elm) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
221 | mgr->cur->next = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
222 | mgr->end = mgr->cur; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
223 | while(elm) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
224 | elm->prev = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
225 | UiTextBufOp *next = elm->next; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
226 | ui_free_textbuf_op(elm); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
227 | elm = next; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
228 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
229 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
230 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
231 | UiTextBufOp *last_op = mgr->cur; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
232 | if( |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
233 | last_op->type == UI_TEXTBUF_INSERT && |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
234 | ui_check_insertstr(last_op->text, last_op->len, text, length) == 0) |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
235 | { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
236 | // append text to last op |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
237 | int ln = last_op->len; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
238 | char *newtext = malloc(ln + length + 1); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
239 | memcpy(newtext, last_op->text, ln); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
240 | memcpy(newtext+ln, text, length); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
241 | newtext[ln+length] = '\0'; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
242 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
243 | last_op->text = newtext; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
244 | last_op->len = ln + length; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
245 | last_op->end += length; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
246 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
247 | return; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
248 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
249 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
250 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
251 | char *str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
252 | if(type == UI_TEXTBUF_INSERT) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
253 | str = malloc(length + 1); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
254 | memcpy(str, text, length); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
255 | str[length] = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
256 | } else { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
257 | length = txv->endPos - txv->startPos; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
258 | str = malloc(length + 1); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
259 | XmTextGetSubstring(value->obj, txv->startPos, length, length+1, str); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
260 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
261 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
262 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
263 | op->prev = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
264 | op->next = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
265 | op->type = type; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
266 | op->start = txv->startPos; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
267 | op->end = txv->endPos + 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
268 | op->len = length; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
269 | op->text = str; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
270 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
271 | cx_linked_list_add( |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
272 | (void**)&mgr->begin, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
273 | (void**)&mgr->end, |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
274 | offsetof(UiTextBufOp, prev), |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
275 | offsetof(UiTextBufOp, next), |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
276 | op); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
277 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
278 | mgr->cur = op; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
279 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
280 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
281 | int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
282 | // return 1 if oldstr + newstr are one word |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
283 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
284 | int has_space = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
285 | for(int i=0;i<oldlen;i++) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
286 | if(oldstr[i] < 33) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
287 | has_space = 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
288 | break; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
289 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
290 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
291 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
292 | for(int i=0;i<newlen;i++) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
293 | if(has_space && newstr[i] > 32) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
294 | return 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
295 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
296 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
297 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
298 | return 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
299 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
300 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
301 | void ui_free_textbuf_op(UiTextBufOp *op) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
302 | if(op->text) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
303 | free(op->text); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
304 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
305 | free(op); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
306 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
307 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
308 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
309 | void ui_text_undo(UiText *value) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
310 | UiUndoMgr *mgr = value->undomgr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
311 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
312 | if(mgr->cur) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
313 | UiTextBufOp *op = mgr->cur; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
314 | mgr->event = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
315 | switch(op->type) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
316 | case UI_TEXTBUF_INSERT: { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
317 | XmTextReplace(value->obj, op->start, op->end, ""); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
318 | break; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
319 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
320 | case UI_TEXTBUF_DELETE: { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
321 | XmTextInsert(value->obj, op->start, op->text); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
322 | break; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
323 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
324 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
325 | mgr->event = 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
326 | mgr->cur = mgr->cur->prev; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
327 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
328 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
329 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
330 | void ui_text_redo(UiText *value) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
331 | UiUndoMgr *mgr = value->undomgr; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
332 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
333 | UiTextBufOp *elm = NULL; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
334 | if(mgr->cur) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
335 | if(mgr->cur->next) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
336 | elm = mgr->cur->next; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
337 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
338 | } else if(mgr->begin) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
339 | elm = mgr->begin; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
340 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
341 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
342 | if(elm) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
343 | UiTextBufOp *op = elm; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
344 | mgr->event = 0; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
345 | switch(op->type) { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
346 | case UI_TEXTBUF_INSERT: { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
347 | XmTextInsert(value->obj, op->start, op->text); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
348 | break; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
349 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
350 | case UI_TEXTBUF_DELETE: { |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
351 | XmTextReplace(value->obj, op->start, op->end, ""); |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
352 | break; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
353 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
354 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
355 | mgr->event = 1; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
356 | mgr->cur = elm; |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
357 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
358 | } |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
359 | |
99b5d52096b5
add textarea (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
416
diff
changeset
|
360 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
361 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
362 | /* ------------------------------ Text Field ------------------------------ */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
363 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
364 | static UIWIDGET create_textfield(UiObject *obj, UiTextFieldArgs args, int frameless, int password) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
365 | Arg xargs[16]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
366 | int n = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
367 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
368 | if(frameless) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
369 | XtSetArg(xargs[n], XmNshadowThickness, 0); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
370 | n++; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
371 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
372 | if(password) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
373 | // TODO |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
374 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
375 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
376 | UiContainerPrivate *ctn = ui_obj_container(obj); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
377 | UI_APPLY_LAYOUT(ctn->layout, args); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
378 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
379 | Widget parent = ctn->prepare(ctn, xargs, &n); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
380 | char *name = args.name ? (char*)args.name : "textfield"; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
381 | Widget textfield = XmCreateTextField(parent, name, xargs, n); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
382 | XtManageChild(textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
383 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
384 | ui_set_widget_groups(obj->ctx, textfield, args.groups); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
385 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
386 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_STRING); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
387 | if(var) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
388 | UiString *value = (UiString*)var->value; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
389 | value->obj = textfield; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
390 | value->get = ui_textfield_get; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
391 | value->set = ui_textfield_set; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
392 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
393 | if(value->value.ptr) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
394 | ui_textfield_set(value, value->value.ptr); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
395 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
396 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
397 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
398 | return textfield; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
399 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
400 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
401 | UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
402 | return create_textfield(obj, args, FALSE, FALSE); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
403 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
404 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
405 | UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
406 | return create_textfield(obj, args, TRUE, FALSE); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
407 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
408 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
409 | UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
410 | return create_textfield(obj, args, FALSE, FALSE); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
411 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
412 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
413 | char* ui_textfield_get(UiString *str) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
414 | str->value.free(str->value.ptr); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
415 | char *value = XmTextFieldGetString(str->obj); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
416 | str->value.ptr = value; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
417 | str->value.free = (ui_freefunc)XtFree; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
418 | return value; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
419 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
420 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
421 | void ui_textfield_set(UiString *str, const char *value) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
422 | XmTextFieldSetString(str->obj, (void*)value); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
423 | str->value.ptr = NULL; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
424 | str->value.free(str->value.ptr); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
425 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
426 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
427 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
428 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
429 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
430 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
431 | /* -------------------- path bar -------------------- */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
432 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
433 | #define XNECreateText(parent,name,args,count) XmCreateTextField(parent,name,args,count) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
434 | #define XNETextSetString(widget,value) XmTextFieldSetString(widget,value) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
435 | #define XNETextGetString(widget) XmTextFieldGetString(widget) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
436 | #define XNETextGetLastPosition(widget) XmTextFieldGetLastPosition(widget) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
437 | #define XNETextSetInsertionPosition(widget, i) XmTextFieldSetInsertionPosition(widget, i) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
438 | #define XNETextSetSelection(w, f, l, t) XmTextFieldSetSelection(w, f, l, t) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
439 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
440 | typedef void(*updatedir_callback)(void*,char*,int); |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
441 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
442 | typedef struct PathBar { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
443 | Widget widget; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
444 | Widget textfield; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
445 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
446 | Widget focus_widget; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
447 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
448 | Widget left; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
449 | Widget right; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
450 | Dimension lw; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
451 | Dimension rw; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
452 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
453 | int shift; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
454 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
455 | UiPathElm *current_pathelms; |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
456 | Widget *pathSegments; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
457 | size_t numSegments; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
458 | size_t segmentAlloc; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
459 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
460 | char *path; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
461 | int selection; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
462 | Boolean input; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
463 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
464 | int focus; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
465 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
466 | updatedir_callback updateDir; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
467 | void *updateDirData; |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
468 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
469 | ui_pathelm_func getpathelm; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
470 | void *getpathelmdata; |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
471 | } PathBar; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
472 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
473 | void PathBarSetPath(PathBar *bar, const char *path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
474 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
475 | void pathbar_resize(Widget w, PathBar *p, XtPointer d) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
476 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
477 | Dimension width, height; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
478 | XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
479 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
480 | Dimension *segW = (void*)XtCalloc(p->numSegments, sizeof(Dimension)); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
481 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
482 | Dimension maxHeight = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
483 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
484 | /* get width/height from all widgets */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
485 | Dimension pathWidth = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
486 | for(int i=0;i<p->numSegments;i++) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
487 | Dimension segWidth; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
488 | Dimension segHeight; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
489 | XtVaGetValues(p->pathSegments[i], XmNwidth, &segWidth, XmNheight, &segHeight, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
490 | segW[i] = segWidth; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
491 | pathWidth += segWidth; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
492 | if(segHeight > maxHeight) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
493 | maxHeight = segHeight; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
494 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
495 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
496 | Dimension tfHeight; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
497 | XtVaGetValues(p->textfield, XmNheight, &tfHeight, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
498 | if(tfHeight > maxHeight) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
499 | maxHeight = tfHeight; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
500 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
501 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
502 | Boolean arrows = False; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
503 | if(pathWidth + 10 > width) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
504 | arrows = True; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
505 | pathWidth += p->lw + p->rw; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
506 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
507 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
508 | /* calc max visible widgets */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
509 | int start = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
510 | if(arrows) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
511 | Dimension vis = p->lw+p->rw; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
512 | for(int i=p->numSegments;i>0;i--) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
513 | Dimension segWidth = segW[i-1]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
514 | if(vis + segWidth + 10 > width) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
515 | start = i; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
516 | arrows = True; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
517 | break; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
518 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
519 | vis += segWidth; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
520 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
521 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
522 | p->shift = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
523 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
524 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
525 | int leftShift = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
526 | if(p->shift < 0) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
527 | if(start + p->shift < 0) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
528 | leftShift = start; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
529 | start = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
530 | p->shift = -leftShift; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
531 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
532 | leftShift = -p->shift; /* negative shift */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
533 | start += p->shift; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
534 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
535 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
536 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
537 | int x = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
538 | if(arrows) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
539 | XtManageChild(p->left); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
540 | XtManageChild(p->right); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
541 | x = p->lw; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
542 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
543 | XtUnmanageChild(p->left); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
544 | XtUnmanageChild(p->right); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
545 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
546 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
547 | for(int i=0;i<p->numSegments;i++) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
548 | if(i >= start && i < p->numSegments - leftShift && !p->input) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
549 | XtVaSetValues(p->pathSegments[i], XmNx, x, XmNy, 0, XmNheight, maxHeight, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
550 | x += segW[i]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
551 | XtManageChild(p->pathSegments[i]); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
552 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
553 | XtUnmanageChild(p->pathSegments[i]); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
554 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
555 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
556 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
557 | if(arrows) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
558 | XtVaSetValues(p->left, XmNx, 0, XmNy, 0, XmNheight, maxHeight, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
559 | XtVaSetValues(p->right, XmNx, x, XmNy, 0, XmNheight, maxHeight, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
560 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
561 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
562 | free(segW); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
563 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
564 | Dimension rw, rh; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
565 | XtMakeResizeRequest(w, width, maxHeight, &rw, &rh); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
566 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
567 | XtVaSetValues(p->textfield, XmNwidth, rw, XmNheight, rh, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
568 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
569 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
570 | static void pathbarActivateTF(PathBar *p) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
571 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
572 | XtUnmanageChild(p->left); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
573 | XtUnmanageChild(p->right); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
574 | XNETextSetSelection(p->textfield, 0, XNETextGetLastPosition(p->textfield), 0); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
575 | XtManageChild(p->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
576 | p->input = 1; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
577 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
578 | XmProcessTraversal(p->textfield, XmTRAVERSE_CURRENT); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
579 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
580 | pathbar_resize(p->widget, p, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
581 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
582 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
583 | void PathBarActivateTextfield(PathBar *p) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
584 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
585 | p->focus = 1; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
586 | pathbarActivateTF(p); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
587 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
588 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
589 | void pathbar_input(Widget w, PathBar *p, XtPointer c) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
590 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
591 | XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct*)c; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
592 | XEvent *xevent = cbs->event; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
593 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
594 | if (cbs->reason == XmCR_INPUT) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
595 | if (xevent->xany.type == ButtonPress) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
596 | p->focus = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
597 | pathbarActivateTF(p); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
598 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
599 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
600 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
601 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
602 | void pathbar_losingfocus(Widget w, PathBar *p, XtPointer c) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
603 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
604 | if(--p->focus < 0) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
605 | p->input = False; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
606 | XtUnmanageChild(p->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
607 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
608 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
609 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
610 | static cxmutstr concat_path_s(cxstring base, cxstring path) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
611 | if(!path.ptr) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
612 | path = CX_STR(""); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
613 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
614 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
615 | int add_separator = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
616 | if(base.length != 0 && base.ptr[base.length-1] == '/') { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
617 | if(path.ptr[0] == '/') { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
618 | base.length--; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
619 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
620 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
621 | if(path.length == 0 || path.ptr[0] != '/') { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
622 | add_separator = 1; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
623 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
624 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
625 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
626 | cxmutstr url; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
627 | if(add_separator) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
628 | url = cx_strcat(3, base, CX_STR("/"), path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
629 | } else { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
630 | url = cx_strcat(2, base, path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
631 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
632 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
633 | return url; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
634 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
635 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
636 | static char* ConcatPath(const char *path1, const char *path2) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
637 | return concat_path_s(cx_str(path1), cx_str(path2)).ptr; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
638 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
639 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
640 | void pathbar_pathinput(Widget w, PathBar *p, XtPointer d) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
641 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
642 | char *newpath = XNETextGetString(p->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
643 | if(newpath) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
644 | if(newpath[0] == '~') { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
645 | char *p = newpath+1; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
646 | char *home = getenv("HOME"); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
647 | char *cp = ConcatPath(home, p); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
648 | XtFree(newpath); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
649 | newpath = cp; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
650 | } else if(newpath[0] != '/') { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
651 | char curdir[2048]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
652 | curdir[0] = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
653 | getcwd(curdir, 2048); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
654 | char *cp = ConcatPath(curdir, newpath); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
655 | XtFree(newpath); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
656 | newpath = cp; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
657 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
658 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
659 | /* update path */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
660 | PathBarSetPath(p, newpath); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
661 | if(p->updateDir) { |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
662 | p->updateDir(p->updateDirData, newpath, -1); |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
663 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
664 | XtFree(newpath); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
665 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
666 | /* hide textfield and show path as buttons */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
667 | XtUnmanageChild(p->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
668 | pathbar_resize(p->widget, p, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
669 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
670 | if(p->focus_widget) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
671 | XmProcessTraversal(p->focus_widget, XmTRAVERSE_CURRENT); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
672 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
673 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
674 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
675 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
676 | void pathbar_shift_left(Widget w, PathBar *p, XtPointer d) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
677 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
678 | p->shift--; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
679 | pathbar_resize(p->widget, p, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
680 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
681 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
682 | void pathbar_shift_right(Widget w, PathBar *p, XtPointer d) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
683 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
684 | if(p->shift < 0) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
685 | p->shift++; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
686 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
687 | pathbar_resize(p->widget, p, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
688 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
689 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
690 | static void pathTextEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
691 | PathBar *pb = data; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
692 | if(event->type == KeyReleaseMask) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
693 | if(event->xkey.keycode == 9) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
694 | XtUnmanageChild(pb->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
695 | pathbar_resize(pb->widget, pb, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
696 | *dispatch = False; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
697 | } else if(event->xkey.keycode == 36) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
698 | pathbar_pathinput(pb->textfield, pb, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
699 | *dispatch = False; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
700 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
701 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
702 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
703 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
704 | PathBar* CreatePathBar(Widget parent, ArgList args, int n) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
705 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
706 | PathBar *bar = (PathBar*)XtMalloc(sizeof(PathBar)); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
707 | bar->path = NULL; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
708 | bar->updateDir = NULL; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
709 | bar->updateDirData = NULL; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
710 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
711 | bar->focus_widget = NULL; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
712 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
713 | bar->getpathelm = NULL; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
714 | bar->getpathelmdata = NULL; |
416
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
715 | bar->current_pathelms = NULL; |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
716 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
717 | bar->shift = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
718 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
719 | XtSetArg(args[n], XmNmarginWidth, 0); n++; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
720 | XtSetArg(args[n], XmNmarginHeight, 0); n++; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
721 | bar->widget = XmCreateDrawingArea(parent, "pathbar", args, n); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
722 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
723 | bar->widget, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
724 | XmNresizeCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
725 | (XtCallbackProc)pathbar_resize, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
726 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
727 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
728 | bar->widget, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
729 | XmNinputCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
730 | (XtCallbackProc)pathbar_input, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
731 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
732 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
733 | Arg a[4]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
734 | XtSetArg(a[0], XmNshadowThickness, 0); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
735 | XtSetArg(a[1], XmNx, 0); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
736 | XtSetArg(a[2], XmNy, 0); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
737 | bar->textfield = XNECreateText(bar->widget, "pbtext", a, 3); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
738 | bar->input = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
739 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
740 | bar->textfield, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
741 | XmNlosingFocusCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
742 | (XtCallbackProc)pathbar_losingfocus, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
743 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
744 | XtAddCallback(bar->textfield, XmNactivateCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
745 | (XtCallbackProc)pathbar_pathinput, bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
746 | XtAddEventHandler(bar->textfield, KeyPressMask | KeyReleaseMask, FALSE, pathTextEH, bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
747 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
748 | XtSetArg(a[0], XmNarrowDirection, XmARROW_LEFT); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
749 | bar->left = XmCreateArrowButton(bar->widget, "pbbutton", a, 1); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
750 | XtSetArg(a[0], XmNarrowDirection, XmARROW_RIGHT); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
751 | bar->right = XmCreateArrowButton(bar->widget, "pbbutton", a, 1); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
752 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
753 | bar->left, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
754 | XmNactivateCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
755 | (XtCallbackProc)pathbar_shift_left, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
756 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
757 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
758 | bar->right, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
759 | XmNactivateCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
760 | (XtCallbackProc)pathbar_shift_right, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
761 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
762 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
763 | Pixel bg; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
764 | XtVaGetValues(bar->textfield, XmNbackground, &bg, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
765 | XtVaSetValues(bar->widget, XmNbackground, bg, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
766 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
767 | XtManageChild(bar->left); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
768 | XtManageChild(bar->right); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
769 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
770 | XtVaGetValues(bar->left, XmNwidth, &bar->lw, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
771 | XtVaGetValues(bar->right, XmNwidth, &bar->rw, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
772 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
773 | bar->segmentAlloc = 16; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
774 | bar->numSegments = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
775 | bar->pathSegments = (Widget*)XtCalloc(16, sizeof(Widget)); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
776 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
777 | bar->selection = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
778 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
779 | return bar; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
780 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
781 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
782 | void PathBarChangeDir(Widget w, PathBar *bar, XtPointer c) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
783 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
784 | XmToggleButtonSetState(bar->pathSegments[bar->selection], False, False); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
785 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
786 | int i; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
787 | for(i=0;i<bar->numSegments;i++) { |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
788 | if(bar->pathSegments[i] == w) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
789 | bar->selection = i; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
790 | XmToggleButtonSetState(w, True, False); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
791 | break; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
792 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
793 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
794 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
795 | UiPathElm elm = bar->current_pathelms[i]; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
796 | cxmutstr name = cx_strdup(cx_strn(elm.name, elm.name_len)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
797 | if(bar->updateDir) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
798 | bar->updateDir(bar->updateDirData, name.ptr, i); |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
799 | } |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
800 | free(name.ptr); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
801 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
802 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
803 | static void ui_pathelm_destroy(UiPathElm *elms, size_t nelm) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
804 | for(int i=0;i<nelm;i++) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
805 | free(elms[i].name); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
806 | free(elms[i].path); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
807 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
808 | free(elms); |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
809 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
810 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
811 | void PathBarSetPath(PathBar *bar, const char *path) |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
812 | { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
813 | if(bar->path) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
814 | free(bar->path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
815 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
816 | bar->path = strdup(path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
817 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
818 | for(int i=0;i<bar->numSegments;i++) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
819 | XtDestroyWidget(bar->pathSegments[i]); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
820 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
821 | XtUnmanageChild(bar->textfield); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
822 | XtManageChild(bar->left); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
823 | XtManageChild(bar->right); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
824 | bar->input = False; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
825 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
826 | Arg args[4]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
827 | XmString str; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
828 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
829 | bar->numSegments = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
830 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
831 | ui_pathelm_destroy(bar->current_pathelms, bar->numSegments); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
832 | size_t nelm = 0; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
833 | UiPathElm* path_elm = bar->getpathelm(bar->path, strlen(bar->path), &nelm, bar->getpathelmdata); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
834 | if (!path_elm) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
835 | return; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
836 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
837 | bar->current_pathelms = path_elm; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
838 | bar->numSegments = nelm; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
839 | bar->pathSegments = realloc(bar->pathSegments, nelm * sizeof(Widget*)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
840 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
841 | for(int i=0;i<nelm;i++) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
842 | UiPathElm elm = path_elm[i]; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
843 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
844 | cxmutstr name = cx_strdup(cx_strn(elm.name, elm.name_len)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
845 | str = XmStringCreateLocalized(elm.name); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
846 | free(name.ptr); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
847 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
848 | XtSetArg(args[0], XmNlabelString, str); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
849 | XtSetArg(args[1], XmNfillOnSelect, True); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
850 | XtSetArg(args[2], XmNindicatorOn, False); |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
851 | Widget button = XmCreateToggleButton(bar->widget, "pbbutton", args, 3); |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
852 | XtAddCallback( |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
853 | button, |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
854 | XmNvalueChangedCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
855 | (XtCallbackProc)PathBarChangeDir, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
856 | bar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
857 | XmStringFree(str); |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
858 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
859 | bar->pathSegments[i] = button; |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
860 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
861 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
862 | bar->selection = bar->numSegments-1; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
863 | XmToggleButtonSetState(bar->pathSegments[bar->selection], True, False); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
864 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
865 | XNETextSetString(bar->textfield, (char*)path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
866 | XNETextSetInsertionPosition(bar->textfield, XNETextGetLastPosition(bar->textfield)); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
867 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
868 | pathbar_resize(bar->widget, bar, NULL); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
869 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
870 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
871 | void PathBarDestroy(PathBar *pathbar) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
872 | if(pathbar->path) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
873 | XtFree(pathbar->path); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
874 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
875 | XtFree((void*)pathbar->pathSegments); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
876 | XtFree((void*)pathbar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
877 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
878 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
879 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
880 | /* ---------------------------- Path Text Field ---------------------------- */ |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
881 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
882 | static void destroy_pathbar(Widget w, XtPointer *data, XtPointer d) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
883 | PathBar *pathbar = (PathBar*)data; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
884 | // TODO: check if there is somonething missing |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
885 | XtFree((void*)pathbar->pathSegments); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
886 | XtFree((void*)pathbar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
887 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
888 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
889 | // TODO: move to common |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
890 | static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
891 | cxstring *pathelms; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
892 | size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
893 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
894 | if (nelm == 0) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
895 | *ret_nelm = 0; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
896 | return NULL; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
897 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
898 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
899 | UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
900 | size_t n = nelm; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
901 | int j = 0; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
902 | for (int i = 0; i < nelm; i++) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
903 | cxstring c = pathelms[i]; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
904 | if (c.length == 0) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
905 | if (i == 0) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
906 | c.length = 1; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
907 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
908 | else { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
909 | n--; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
910 | continue; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
911 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
912 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
913 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
914 | cxmutstr m = cx_strdup(c); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
915 | elms[j].name = m.ptr; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
916 | elms[j].name_len = m.length; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
917 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
918 | size_t elm_path_len = c.ptr + c.length - full_path; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
919 | cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
920 | elms[j].path = elm_path.ptr; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
921 | elms[j].path_len = elm_path.length; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
922 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
923 | j++; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
924 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
925 | *ret_nelm = n; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
926 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
927 | return elms; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
928 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
929 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
930 | static void pathbar_activate(void *data, char *path, int index) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
931 | UiEventData *event = data; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
932 | UiEvent evt; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
933 | evt.obj = event->obj; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
934 | evt.window = evt.obj->window; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
935 | evt.document = evt.obj->ctx->document; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
936 | evt.eventdata = path; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
937 | evt.intval = index; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
938 | event->callback(&evt, event->userdata); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
939 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
940 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
941 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
942 | Arg xargs[16]; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
943 | int n = 0; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
944 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
945 | UiContainerPrivate *ctn = ui_obj_container(obj); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
946 | UI_APPLY_LAYOUT(ctn->layout, args); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
947 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
948 | Widget parent = ctn->prepare(ctn, xargs, &n); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
949 | // TODO: name |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
950 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
951 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
952 | PathBar *pathbar = CreatePathBar(parent, xargs, n); |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
953 | if(!args.getpathelm) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
954 | pathbar->getpathelm= default_pathelm_func; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
955 | } else { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
956 | pathbar->getpathelm = args.getpathelm; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
957 | pathbar->getpathelmdata = args.getpathelmdata; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
958 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
959 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
960 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
961 | XtManageChild(pathbar->widget); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
962 | ctn->add(ctn, pathbar->widget); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
963 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
964 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_STRING); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
965 | if (var) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
966 | UiString* value = (UiString*)var->value; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
967 | value->obj = pathbar; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
968 | value->get = ui_path_textfield_get; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
969 | value->set = ui_path_textfield_set; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
970 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
971 | if(value->value.ptr) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
972 | char *str = strdup(value->value.ptr); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
973 | ui_string_set(value, str); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
974 | free(str); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
975 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
976 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
977 | |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
978 | if(args.onactivate) { |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
979 | UiEventData *eventdata = malloc(sizeof(UiEventData)); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
980 | eventdata->callback = args.onactivate; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
981 | eventdata->userdata = args.onactivatedata; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
982 | eventdata->obj = obj; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
983 | eventdata->value = 0; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
984 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
985 | pathbar->updateDir = pathbar_activate; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
986 | pathbar->updateDirData = eventdata; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
987 | |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
988 | XtAddCallback( |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
989 | pathbar->widget, |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
990 | XmNdestroyCallback, |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
991 | (XtCallbackProc)ui_destroy_eventdata, |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
992 | eventdata); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
993 | } |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
994 | |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
995 | XtAddCallback( |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
996 | pathbar->widget, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
997 | XmNdestroyCallback, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
998 | (XtCallbackProc)destroy_pathbar, |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
999 | pathbar); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1000 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1001 | return pathbar->widget; |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1002 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1003 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1004 | char* ui_path_textfield_get(UiString *str) { |
415
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1005 | PathBar *pathbar = str->obj; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1006 | str->value.free(str->value.ptr); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1007 | char *value = XmTextFieldGetString(pathbar->textfield); |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1008 | str->value.ptr = value; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1009 | str->value.free = (ui_freefunc)XtFree; |
e35cdf33998c
finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
1010 | return value; |
414
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1011 | } |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1012 | |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1013 | void ui_path_textfield_set(UiString *str, const char *value) { |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1014 | PathBarSetPath(str->obj, value); |
ef60d527c066
add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
1015 | } |