ui/motif/text.c

Sun, 15 Dec 2024 22:13:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Dec 2024 22:13:05 +0100
branch
newapi
changeset 417
f0fee61a70be
parent 416
89ad8467c39f
permissions
-rw-r--r--

implement menu item callbacks (Motif)

5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
31 #include <unistd.h>
5
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "text.h"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "container.h"
19d37cb9c96c added textarea
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
39
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
40 /* ------------------------------ Text Field ------------------------------ */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
41
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
42 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
43 Arg xargs[16];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
44 int n = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
45
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
46 if(frameless) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
47 XtSetArg(xargs[n], XmNshadowThickness, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
48 n++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
49 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
50 if(password) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
51 // TODO
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
52 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
53
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
54 UiContainerPrivate *ctn = ui_obj_container(obj);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
55 UI_APPLY_LAYOUT(ctn->layout, args);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
56
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
57 Widget parent = ctn->prepare(ctn, xargs, &n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
58 char *name = args.name ? (char*)args.name : "textfield";
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
59 Widget textfield = XmCreateTextField(parent, name, xargs, n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
60 XtManageChild(textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
61
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
62 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
63
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
64 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
65 if(var) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
66 UiString *value = (UiString*)var->value;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
67 value->obj = textfield;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
68 value->get = ui_textfield_get;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
69 value->set = ui_textfield_set;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
70
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
71 if(value->value.ptr) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
72 ui_textfield_set(value, value->value.ptr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
73 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
74 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
75
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
76 return textfield;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
77 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
78
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
79 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
80 return create_textfield(obj, args, FALSE, FALSE);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
81 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
82
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
83 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
84 return create_textfield(obj, args, TRUE, FALSE);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
85 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
86
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
87 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
88 return create_textfield(obj, args, FALSE, FALSE);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
89 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
90
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
91 char* ui_textfield_get(UiString *str) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
92 str->value.free(str->value.ptr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
93 char *value = XmTextFieldGetString(str->obj);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
94 str->value.ptr = value;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
95 str->value.free = (ui_freefunc)XtFree;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
96 return value;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
97 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
98
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
99 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
100 XmTextFieldSetString(str->obj, (void*)value);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
101 str->value.ptr = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
102 str->value.free(str->value.ptr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
103 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
104
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
105
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
106
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
107
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
108
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
109 /* -------------------- path bar -------------------- */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
110
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
111 #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
112 #define XNETextSetString(widget,value) XmTextFieldSetString(widget,value)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
113 #define XNETextGetString(widget) XmTextFieldGetString(widget)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
114 #define XNETextGetLastPosition(widget) XmTextFieldGetLastPosition(widget)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
115 #define XNETextSetInsertionPosition(widget, i) XmTextFieldSetInsertionPosition(widget, i)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
116 #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
117
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
118 typedef void(*updatedir_callback)(void*,char*,int);
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
119
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
120 typedef struct PathBar {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
121 Widget widget;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
122 Widget textfield;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
123
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
124 Widget focus_widget;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
125
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
126 Widget left;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
127 Widget right;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
128 Dimension lw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
129 Dimension rw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
130
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
131 int shift;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
132
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
133 UiPathElm *current_pathelms;
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
134 Widget *pathSegments;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
135 size_t numSegments;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
136 size_t segmentAlloc;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
137
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
138 char *path;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
139 int selection;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
140 Boolean input;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
141
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
142 int focus;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
143
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
144 updatedir_callback updateDir;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
145 void *updateDirData;
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
146
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
147 ui_pathelm_func getpathelm;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
148 void *getpathelmdata;
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
149 } PathBar;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
150
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
151 void PathBarSetPath(PathBar *bar, const char *path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
152
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
153 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
154 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
155 Dimension width, height;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
156 XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
157
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
158 Dimension *segW = (void*)XtCalloc(p->numSegments, sizeof(Dimension));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
159
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
160 Dimension maxHeight = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
161
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
162 /* get width/height from all widgets */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
163 Dimension pathWidth = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
164 for(int i=0;i<p->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
165 Dimension segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
166 Dimension segHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
167 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
168 segW[i] = segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
169 pathWidth += segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
170 if(segHeight > maxHeight) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
171 maxHeight = segHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
172 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
173 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
174 Dimension tfHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
175 XtVaGetValues(p->textfield, XmNheight, &tfHeight, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
176 if(tfHeight > maxHeight) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
177 maxHeight = tfHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
178 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
179
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
180 Boolean arrows = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
181 if(pathWidth + 10 > width) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
182 arrows = True;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
183 pathWidth += p->lw + p->rw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
184 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
185
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
186 /* calc max visible widgets */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
187 int start = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
188 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
189 Dimension vis = p->lw+p->rw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
190 for(int i=p->numSegments;i>0;i--) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
191 Dimension segWidth = segW[i-1];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
192 if(vis + segWidth + 10 > width) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
193 start = i;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
194 arrows = True;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
195 break;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
196 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
197 vis += segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
198 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
199 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
200 p->shift = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
201 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
202
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
203 int leftShift = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
204 if(p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
205 if(start + p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
206 leftShift = start;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
207 start = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
208 p->shift = -leftShift;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
209 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
210 leftShift = -p->shift; /* negative shift */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
211 start += p->shift;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
212 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
213 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
214
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
215 int x = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
216 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
217 XtManageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
218 XtManageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
219 x = p->lw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
220 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
221 XtUnmanageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
222 XtUnmanageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
223 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
224
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
225 for(int i=0;i<p->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
226 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
227 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
228 x += segW[i];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
229 XtManageChild(p->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
230 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
231 XtUnmanageChild(p->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
232 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
233 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
234
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
235 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
236 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
237 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
238 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
239
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
240 free(segW);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
241
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
242 Dimension rw, rh;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
243 XtMakeResizeRequest(w, width, maxHeight, &rw, &rh);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
244
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
245 XtVaSetValues(p->textfield, XmNwidth, rw, XmNheight, rh, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
246 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
247
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
248 static void pathbarActivateTF(PathBar *p)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
249 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
250 XtUnmanageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
251 XtUnmanageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
252 XNETextSetSelection(p->textfield, 0, XNETextGetLastPosition(p->textfield), 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
253 XtManageChild(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
254 p->input = 1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
255
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
256 XmProcessTraversal(p->textfield, XmTRAVERSE_CURRENT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
257
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
258 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
259 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
260
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
261 void PathBarActivateTextfield(PathBar *p)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
262 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
263 p->focus = 1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
264 pathbarActivateTF(p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
265 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
266
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
267 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
268 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
269 XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct*)c;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
270 XEvent *xevent = cbs->event;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
271
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
272 if (cbs->reason == XmCR_INPUT) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
273 if (xevent->xany.type == ButtonPress) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
274 p->focus = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
275 pathbarActivateTF(p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
276 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
277 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
278 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
279
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
280 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
281 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
282 if(--p->focus < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
283 p->input = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
284 XtUnmanageChild(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
285 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
286 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
287
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
288 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
289 if(!path.ptr) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
290 path = CX_STR("");
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
291 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
292
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
293 int add_separator = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
294 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
295 if(path.ptr[0] == '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
296 base.length--;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
297 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
298 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
299 if(path.length == 0 || path.ptr[0] != '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
300 add_separator = 1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
301 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
302 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
303
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
304 cxmutstr url;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
305 if(add_separator) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
306 url = cx_strcat(3, base, CX_STR("/"), path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
307 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
308 url = cx_strcat(2, base, path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
309 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
310
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
311 return url;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
312 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
313
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
314 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
315 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
316 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
317
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
318 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
319 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
320 char *newpath = XNETextGetString(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
321 if(newpath) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
322 if(newpath[0] == '~') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
323 char *p = newpath+1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
324 char *home = getenv("HOME");
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
325 char *cp = ConcatPath(home, p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
326 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
327 newpath = cp;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
328 } else if(newpath[0] != '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
329 char curdir[2048];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
330 curdir[0] = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
331 getcwd(curdir, 2048);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
332 char *cp = ConcatPath(curdir, newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
333 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
334 newpath = cp;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
335 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
336
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
337 /* update path */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
338 PathBarSetPath(p, newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
339 if(p->updateDir) {
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
340 p->updateDir(p->updateDirData, newpath, -1);
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
341 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
342 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
343
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
344 /* hide textfield and show path as buttons */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
345 XtUnmanageChild(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
346 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
347
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
348 if(p->focus_widget) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
349 XmProcessTraversal(p->focus_widget, XmTRAVERSE_CURRENT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
350 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
351 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
352 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
353
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
354 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
355 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
356 p->shift--;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
357 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
358 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
359
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
360 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
361 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
362 if(p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
363 p->shift++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
364 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
365 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
366 }
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 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
369 PathBar *pb = data;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
370 if(event->type == KeyReleaseMask) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
371 if(event->xkey.keycode == 9) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
372 XtUnmanageChild(pb->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
373 pathbar_resize(pb->widget, pb, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
374 *dispatch = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
375 } else if(event->xkey.keycode == 36) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
376 pathbar_pathinput(pb->textfield, pb, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
377 *dispatch = False;
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 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
380 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
381
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
382 PathBar* CreatePathBar(Widget parent, ArgList args, int n)
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 PathBar *bar = (PathBar*)XtMalloc(sizeof(PathBar));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
385 bar->path = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
386 bar->updateDir = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
387 bar->updateDirData = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
388
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
389 bar->focus_widget = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
390
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
391 bar->getpathelm = NULL;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
392 bar->getpathelmdata = NULL;
416
89ad8467c39f implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
393 bar->current_pathelms = NULL;
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
394
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
395 bar->shift = 0;
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 XtSetArg(args[n], XmNmarginWidth, 0); n++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
398 XtSetArg(args[n], XmNmarginHeight, 0); n++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
399 bar->widget = XmCreateDrawingArea(parent, "pathbar", args, n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
400 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
401 bar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
402 XmNresizeCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
403 (XtCallbackProc)pathbar_resize,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
404 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
405 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
406 bar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
407 XmNinputCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
408 (XtCallbackProc)pathbar_input,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
409 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
410
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
411 Arg a[4];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
412 XtSetArg(a[0], XmNshadowThickness, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
413 XtSetArg(a[1], XmNx, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
414 XtSetArg(a[2], XmNy, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
415 bar->textfield = XNECreateText(bar->widget, "pbtext", a, 3);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
416 bar->input = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
417 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
418 bar->textfield,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
419 XmNlosingFocusCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
420 (XtCallbackProc)pathbar_losingfocus,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
421 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
422 XtAddCallback(bar->textfield, XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
423 (XtCallbackProc)pathbar_pathinput, bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
424 XtAddEventHandler(bar->textfield, KeyPressMask | KeyReleaseMask, FALSE, pathTextEH, bar);
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 XtSetArg(a[0], XmNarrowDirection, XmARROW_LEFT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
427 bar->left = XmCreateArrowButton(bar->widget, "pbbutton", a, 1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
428 XtSetArg(a[0], XmNarrowDirection, XmARROW_RIGHT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
429 bar->right = XmCreateArrowButton(bar->widget, "pbbutton", a, 1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
430 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
431 bar->left,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
432 XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
433 (XtCallbackProc)pathbar_shift_left,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
434 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
435 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
436 bar->right,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
437 XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
438 (XtCallbackProc)pathbar_shift_right,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
439 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
440
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
441 Pixel bg;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
442 XtVaGetValues(bar->textfield, XmNbackground, &bg, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
443 XtVaSetValues(bar->widget, XmNbackground, bg, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
444
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
445 XtManageChild(bar->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
446 XtManageChild(bar->right);
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 XtVaGetValues(bar->left, XmNwidth, &bar->lw, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
449 XtVaGetValues(bar->right, XmNwidth, &bar->rw, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
450
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
451 bar->segmentAlloc = 16;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
452 bar->numSegments = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
453 bar->pathSegments = (Widget*)XtCalloc(16, sizeof(Widget));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
454
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
455 bar->selection = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
456
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
457 return bar;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
458 }
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 void PathBarChangeDir(Widget w, PathBar *bar, XtPointer c)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
461 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
462 XmToggleButtonSetState(bar->pathSegments[bar->selection], False, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
463
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
464 int i;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
465 for(i=0;i<bar->numSegments;i++) {
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
466 if(bar->pathSegments[i] == w) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
467 bar->selection = i;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
468 XmToggleButtonSetState(w, True, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
469 break;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
470 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
471 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
472
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
473 UiPathElm elm = bar->current_pathelms[i];
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
474 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
475 if(bar->updateDir) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
476 bar->updateDir(bar->updateDirData, name.ptr, i);
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
477 }
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
478 free(name.ptr);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
479 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
480
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
481 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
482 for(int i=0;i<nelm;i++) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
483 free(elms[i].name);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
484 free(elms[i].path);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
485 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
486 free(elms);
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
487 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
488
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
489 void PathBarSetPath(PathBar *bar, const char *path)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
490 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
491 if(bar->path) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
492 free(bar->path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
493 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
494 bar->path = strdup(path);
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 for(int i=0;i<bar->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
497 XtDestroyWidget(bar->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
498 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
499 XtUnmanageChild(bar->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
500 XtManageChild(bar->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
501 XtManageChild(bar->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
502 bar->input = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
503
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
504 Arg args[4];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
505 XmString str;
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 bar->numSegments = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
508
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
509 ui_pathelm_destroy(bar->current_pathelms, bar->numSegments);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
510 size_t nelm = 0;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
511 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
512 if (!path_elm) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
513 return;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
514 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
515 bar->current_pathelms = path_elm;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
516 bar->numSegments = nelm;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
517 bar->pathSegments = realloc(bar->pathSegments, nelm * sizeof(Widget*));
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
518
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
519 for(int i=0;i<nelm;i++) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
520 UiPathElm elm = path_elm[i];
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
521
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
522 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
523 str = XmStringCreateLocalized(elm.name);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
524 free(name.ptr);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
525
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
526 XtSetArg(args[0], XmNlabelString, str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
527 XtSetArg(args[1], XmNfillOnSelect, True);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
528 XtSetArg(args[2], XmNindicatorOn, False);
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
529 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
530 XtAddCallback(
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
531 button,
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
532 XmNvalueChangedCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
533 (XtCallbackProc)PathBarChangeDir,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
534 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
535 XmStringFree(str);
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
536
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
537 bar->pathSegments[i] = button;
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
538 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
539
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
540 bar->selection = bar->numSegments-1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
541 XmToggleButtonSetState(bar->pathSegments[bar->selection], True, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
542
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
543 XNETextSetString(bar->textfield, (char*)path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
544 XNETextSetInsertionPosition(bar->textfield, XNETextGetLastPosition(bar->textfield));
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 pathbar_resize(bar->widget, bar, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
547 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
548
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
549 void PathBarDestroy(PathBar *pathbar) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
550 if(pathbar->path) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
551 XtFree(pathbar->path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
552 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
553 XtFree((void*)pathbar->pathSegments);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
554 XtFree((void*)pathbar);
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
558 /* ---------------------------- Path Text Field ---------------------------- */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
559
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
560 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
561 PathBar *pathbar = (PathBar*)data;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
562 // TODO: check if there is somonething missing
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
563 XtFree((void*)pathbar->pathSegments);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
564 XtFree((void*)pathbar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
565 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
566
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
567 // TODO: move to common
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
568 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
569 cxstring *pathelms;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
570 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
571
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
572 if (nelm == 0) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
573 *ret_nelm = 0;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
574 return NULL;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
575 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
576
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
577 UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm));
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
578 size_t n = nelm;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
579 int j = 0;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
580 for (int i = 0; i < nelm; i++) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
581 cxstring c = pathelms[i];
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
582 if (c.length == 0) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
583 if (i == 0) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
584 c.length = 1;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
585 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
586 else {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
587 n--;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
588 continue;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
589 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
590 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
591
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
592 cxmutstr m = cx_strdup(c);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
593 elms[j].name = m.ptr;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
594 elms[j].name_len = m.length;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
595
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
596 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
597 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
598 elms[j].path = elm_path.ptr;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
599 elms[j].path_len = elm_path.length;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
600
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
601 j++;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
602 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
603 *ret_nelm = n;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
604
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
605 return elms;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
606 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
607
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
608 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
609 UiEventData *event = data;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
610 UiEvent evt;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
611 evt.obj = event->obj;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
612 evt.window = evt.obj->window;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
613 evt.document = evt.obj->ctx->document;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
614 evt.eventdata = path;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
615 evt.intval = index;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
616 event->callback(&evt, event->userdata);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
617 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
618
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
619 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
620 Arg xargs[16];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
621 int n = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
622
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
623 UiContainerPrivate *ctn = ui_obj_container(obj);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
624 UI_APPLY_LAYOUT(ctn->layout, args);
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 Widget parent = ctn->prepare(ctn, xargs, &n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
627 // TODO: name
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
628
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
629
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
630 PathBar *pathbar = CreatePathBar(parent, xargs, n);
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
631 if(!args.getpathelm) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
632 pathbar->getpathelm= default_pathelm_func;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
633 } else {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
634 pathbar->getpathelm = args.getpathelm;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
635 pathbar->getpathelmdata = args.getpathelmdata;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
636 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
637
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
638
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
639 XtManageChild(pathbar->widget);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
640 ctn->add(ctn, pathbar->widget);
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 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
643 if (var) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
644 UiString* value = (UiString*)var->value;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
645 value->obj = pathbar;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
646 value->get = ui_path_textfield_get;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
647 value->set = ui_path_textfield_set;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
648
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
649 if(value->value.ptr) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
650 char *str = strdup(value->value.ptr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
651 ui_string_set(value, str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
652 free(str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
653 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
654 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
655
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
656 if(args.onactivate) {
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
657 UiEventData *eventdata = malloc(sizeof(UiEventData));
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
658 eventdata->callback = args.onactivate;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
659 eventdata->userdata = args.onactivatedata;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
660 eventdata->obj = obj;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
661 eventdata->value = 0;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
662
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
663 pathbar->updateDir = pathbar_activate;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
664 pathbar->updateDirData = eventdata;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
665
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
666 XtAddCallback(
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
667 pathbar->widget,
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
668 XmNdestroyCallback,
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
669 (XtCallbackProc)ui_destroy_eventdata,
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
670 eventdata);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
671 }
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
672
414
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
673 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
674 pathbar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
675 XmNdestroyCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
676 (XtCallbackProc)destroy_pathbar,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
677 pathbar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
678
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
679 return pathbar->widget;
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 char* ui_path_textfield_get(UiString *str) {
415
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
683 PathBar *pathbar = str->obj;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
684 str->value.free(str->value.ptr);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
685 char *value = XmTextFieldGetString(pathbar->textfield);
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
686 str->value.ptr = value;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
687 str->value.free = (ui_freefunc)XtFree;
e35cdf33998c finish motif path bar implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
688 return value;
414
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
691 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
692 PathBarSetPath(str->obj, value);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
693 }

mercurial