ui/motif/text.c

Thu, 12 Dec 2024 23:23:09 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Dec 2024 23:23:09 +0100
branch
newapi
changeset 414
ef60d527c066
parent 406
0ebf9d7b23e8
child 415
e35cdf33998c
permissions
-rw-r--r--

add text field widgets (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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
118 typedef void(*updatedir_callback)(void*,char*);
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
133 Widget *pathSegments;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
134 size_t numSegments;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
135 size_t segmentAlloc;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
136
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
137 char *path;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
138 int selection;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
139 Boolean input;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
140
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
141 int focus;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
142
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
143 updatedir_callback updateDir;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
144 void *updateDirData;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
145 } PathBar;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
146
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
147 void PathBarSetPath(PathBar *bar, const char *path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
148
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
149 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
150 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
151 Dimension width, height;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
152 XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
153
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
154 Dimension *segW = (void*)XtCalloc(p->numSegments, sizeof(Dimension));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
155
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
156 Dimension maxHeight = 0;
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 /* get width/height from all widgets */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
159 Dimension pathWidth = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
160 for(int i=0;i<p->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
161 Dimension segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
162 Dimension segHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
163 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
164 segW[i] = segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
165 pathWidth += segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
166 if(segHeight > maxHeight) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
167 maxHeight = segHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
168 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
169 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
170 Dimension tfHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
171 XtVaGetValues(p->textfield, XmNheight, &tfHeight, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
172 if(tfHeight > maxHeight) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
173 maxHeight = tfHeight;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
174 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
175
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
176 Boolean arrows = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
177 if(pathWidth + 10 > width) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
178 arrows = True;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
179 pathWidth += p->lw + p->rw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
180 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
181
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
182 /* calc max visible widgets */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
183 int start = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
184 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
185 Dimension vis = p->lw+p->rw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
186 for(int i=p->numSegments;i>0;i--) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
187 Dimension segWidth = segW[i-1];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
188 if(vis + segWidth + 10 > width) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
189 start = i;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
190 arrows = True;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
191 break;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
192 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
193 vis += segWidth;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
194 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
195 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
196 p->shift = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
197 }
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 int leftShift = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
200 if(p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
201 if(start + p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
202 leftShift = start;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
203 start = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
204 p->shift = -leftShift;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
205 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
206 leftShift = -p->shift; /* negative shift */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
207 start += p->shift;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
208 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
209 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
210
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
211 int x = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
212 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
213 XtManageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
214 XtManageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
215 x = p->lw;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
216 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
217 XtUnmanageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
218 XtUnmanageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
219 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
220
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
221 for(int i=0;i<p->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
222 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
223 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
224 x += segW[i];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
225 XtManageChild(p->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
226 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
227 XtUnmanageChild(p->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
228 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
229 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
230
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
231 if(arrows) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
232 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
233 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
234 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
235
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
236 free(segW);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
237
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
238 Dimension rw, rh;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
239 XtMakeResizeRequest(w, width, maxHeight, &rw, &rh);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
240
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
241 XtVaSetValues(p->textfield, XmNwidth, rw, XmNheight, rh, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
242 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
243
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
244 static void pathbarActivateTF(PathBar *p)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
245 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
246 XtUnmanageChild(p->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
247 XtUnmanageChild(p->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
248 XNETextSetSelection(p->textfield, 0, XNETextGetLastPosition(p->textfield), 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
249 XtManageChild(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
250 p->input = 1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
251
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
252 XmProcessTraversal(p->textfield, XmTRAVERSE_CURRENT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
253
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
254 pathbar_resize(p->widget, p, NULL);
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
257 void PathBarActivateTextfield(PathBar *p)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
258 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
259 p->focus = 1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
260 pathbarActivateTF(p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
261 }
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 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
264 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
265 XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct*)c;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
266 XEvent *xevent = cbs->event;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
267
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
268 if (cbs->reason == XmCR_INPUT) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
269 if (xevent->xany.type == ButtonPress) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
270 p->focus = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
271 pathbarActivateTF(p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
272 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
273 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
274 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
275
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
276 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
277 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
278 if(--p->focus < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
279 p->input = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
280 XtUnmanageChild(p->textfield);
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 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
283
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
284 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
285 if(!path.ptr) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
286 path = CX_STR("");
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
289 int add_separator = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
290 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
291 if(path.ptr[0] == '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
292 base.length--;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
293 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
294 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
295 if(path.length == 0 || path.ptr[0] != '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
296 add_separator = 1;
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 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
299
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
300 cxmutstr url;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
301 if(add_separator) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
302 url = cx_strcat(3, base, CX_STR("/"), path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
303 } else {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
304 url = cx_strcat(2, base, path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
305 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
306
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
307 return url;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
308 }
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 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
311 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
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 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
315 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
316 char *newpath = XNETextGetString(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
317 if(newpath) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
318 if(newpath[0] == '~') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
319 char *p = newpath+1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
320 char *home = getenv("HOME");
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
321 char *cp = ConcatPath(home, p);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
322 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
323 newpath = cp;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
324 } else if(newpath[0] != '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
325 char curdir[2048];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
326 curdir[0] = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
327 getcwd(curdir, 2048);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
328 char *cp = ConcatPath(curdir, newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
329 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
330 newpath = cp;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
331 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
332
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
333 /* update path */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
334 PathBarSetPath(p, newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
335 if(p->updateDir) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
336 p->updateDir(p->updateDirData, newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
337 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
338 XtFree(newpath);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
339
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
340 /* hide textfield and show path as buttons */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
341 XtUnmanageChild(p->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
342 pathbar_resize(p->widget, p, NULL);
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 if(p->focus_widget) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
345 XmProcessTraversal(p->focus_widget, XmTRAVERSE_CURRENT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
346 }
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 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
349
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
350 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
351 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
352 p->shift--;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
353 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
354 }
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 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
357 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
358 if(p->shift < 0) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
359 p->shift++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
360 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
361 pathbar_resize(p->widget, p, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
362 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
363
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
364 static 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
365 PathBar *pb = data;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
366 if(event->type == KeyReleaseMask) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
367 if(event->xkey.keycode == 9) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
368 XtUnmanageChild(pb->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
369 pathbar_resize(pb->widget, pb, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
370 *dispatch = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
371 } else if(event->xkey.keycode == 36) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
372 pathbar_pathinput(pb->textfield, pb, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
373 *dispatch = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
374 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
375 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
376 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
377
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
378 PathBar* CreatePathBar(Widget parent, ArgList args, int n)
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 PathBar *bar = (PathBar*)XtMalloc(sizeof(PathBar));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
381 bar->path = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
382 bar->updateDir = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
383 bar->updateDirData = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
384
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
385 bar->focus_widget = NULL;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
386
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
387 bar->shift = 0;
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 XtSetArg(args[n], XmNmarginWidth, 0); n++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
390 XtSetArg(args[n], XmNmarginHeight, 0); n++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
391 bar->widget = XmCreateDrawingArea(parent, "pathbar", args, n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
392 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
393 bar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
394 XmNresizeCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
395 (XtCallbackProc)pathbar_resize,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
396 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
397 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
398 bar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
399 XmNinputCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
400 (XtCallbackProc)pathbar_input,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
401 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
402
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
403 Arg a[4];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
404 XtSetArg(a[0], XmNshadowThickness, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
405 XtSetArg(a[1], XmNx, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
406 XtSetArg(a[2], XmNy, 0);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
407 bar->textfield = XNECreateText(bar->widget, "pbtext", a, 3);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
408 bar->input = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
409 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
410 bar->textfield,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
411 XmNlosingFocusCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
412 (XtCallbackProc)pathbar_losingfocus,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
413 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
414 XtAddCallback(bar->textfield, XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
415 (XtCallbackProc)pathbar_pathinput, bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
416 XtAddEventHandler(bar->textfield, KeyPressMask | KeyReleaseMask, FALSE, pathTextEH, bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
417
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
418 XtSetArg(a[0], XmNarrowDirection, XmARROW_LEFT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
419 bar->left = XmCreateArrowButton(bar->widget, "pbbutton", a, 1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
420 XtSetArg(a[0], XmNarrowDirection, XmARROW_RIGHT);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
421 bar->right = XmCreateArrowButton(bar->widget, "pbbutton", a, 1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
422 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
423 bar->left,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
424 XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
425 (XtCallbackProc)pathbar_shift_left,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
426 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
427 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
428 bar->right,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
429 XmNactivateCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
430 (XtCallbackProc)pathbar_shift_right,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
431 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
432
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
433 Pixel bg;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
434 XtVaGetValues(bar->textfield, XmNbackground, &bg, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
435 XtVaSetValues(bar->widget, XmNbackground, bg, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
436
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
437 XtManageChild(bar->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
438 XtManageChild(bar->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
439
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
440 XtVaGetValues(bar->left, XmNwidth, &bar->lw, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
441 XtVaGetValues(bar->right, XmNwidth, &bar->rw, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
442
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
443 bar->segmentAlloc = 16;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
444 bar->numSegments = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
445 bar->pathSegments = (Widget*)XtCalloc(16, sizeof(Widget));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
446
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
447 bar->selection = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
448
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
449 return bar;
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
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
452 void PathBarChangeDir(Widget w, PathBar *bar, XtPointer c)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
453 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
454 XmToggleButtonSetState(bar->pathSegments[bar->selection], False, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
455
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
456 for(int i=0;i<bar->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
457 if(bar->pathSegments[i] == w) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
458 bar->selection = i;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
459 XmToggleButtonSetState(w, True, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
460 break;
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 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
463
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
464 int plen = strlen(bar->path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
465 int countSeg = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
466 for(int i=0;i<=plen;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
467 char c = bar->path[i];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
468 if(c == '/' || c == '\0') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
469 if(countSeg == bar->selection) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
470 char *dir = XtMalloc(i+2);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
471 memcpy(dir, bar->path, i+1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
472 dir[i+1] = '\0';
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
473 if(bar->updateDir) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
474 bar->updateDir(bar->updateDirData, dir);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
475 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
476 free(dir);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
477 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
478 countSeg++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
479 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
480 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
481 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
482
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
483 void PathBarSetPath(PathBar *bar, const char *path)
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
484 {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
485 if(bar->path) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
486 free(bar->path);
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 bar->path = strdup(path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
489
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
490 for(int i=0;i<bar->numSegments;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
491 XtDestroyWidget(bar->pathSegments[i]);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
492 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
493 XtUnmanageChild(bar->textfield);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
494 XtManageChild(bar->left);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
495 XtManageChild(bar->right);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
496 bar->input = False;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
497
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
498 Arg args[4];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
499 XmString str;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
500
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
501 bar->numSegments = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
502
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
503 int i=0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
504 if(path[0] == '/') {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
505 str = XmStringCreateLocalized("/");
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
506 XtSetArg(args[0], XmNlabelString, str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
507 XtSetArg(args[1], XmNfillOnSelect, True);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
508 XtSetArg(args[2], XmNindicatorOn, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
509 bar->pathSegments[0] = XmCreateToggleButton(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
510 bar->widget, "pbbutton", args, 3);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
511 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
512 bar->pathSegments[0],
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
513 XmNvalueChangedCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
514 (XtCallbackProc)PathBarChangeDir,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
515 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
516 XmStringFree(str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
517 bar->numSegments++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
518 i++;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
519 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
520
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
521 int len = strlen(path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
522 int begin = i;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
523 for(;i<=len;i++) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
524 char c = path[i];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
525 if((c == '/' || c == '\0') && i > begin) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
526 char *segStr = XtMalloc(i - begin + 1);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
527 memcpy(segStr, path+begin, i-begin);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
528 segStr[i-begin] = '\0';
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
529 begin = i+1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
530
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
531 str = XmStringCreateLocalized(segStr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
532 XtFree(segStr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
533 XtSetArg(args[0], XmNlabelString, str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
534 XtSetArg(args[1], XmNfillOnSelect, True);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
535 XtSetArg(args[2], XmNindicatorOn, False);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
536 Widget button = XmCreateToggleButton(bar->widget, "pbbutton", args, 3);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
537 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
538 button,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
539 XmNvalueChangedCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
540 (XtCallbackProc)PathBarChangeDir,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
541 bar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
542 XmStringFree(str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
543
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
544 if(bar->numSegments >= bar->segmentAlloc) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
545 bar->segmentAlloc += 8;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
546 bar->pathSegments = realloc(bar->pathSegments, bar->segmentAlloc * sizeof(Widget));
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 bar->pathSegments[bar->numSegments++] = button;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
550 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
551 }
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 bar->selection = bar->numSegments-1;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
554 XmToggleButtonSetState(bar->pathSegments[bar->selection], True, False);
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 XNETextSetString(bar->textfield, (char*)path);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
557 XNETextSetInsertionPosition(bar->textfield, XNETextGetLastPosition(bar->textfield));
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
558
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
559 pathbar_resize(bar->widget, bar, NULL);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
560 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
561
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
562 void PathBarDestroy(PathBar *pathbar) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
563 if(pathbar->path) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
564 XtFree(pathbar->path);
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 XtFree((void*)pathbar->pathSegments);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
567 XtFree((void*)pathbar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
568 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
569
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
570
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
571 /* ---------------------------- Path Text Field ---------------------------- */
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
572
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
573 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
574 PathBar *pathbar = (PathBar*)data;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
575 // TODO: check if there is somonething missing
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
576 XtFree((void*)pathbar->pathSegments);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
577 XtFree((void*)pathbar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
578 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
579
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
580 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
581 Arg xargs[16];
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
582 int n = 0;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
583
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
584 UiContainerPrivate *ctn = ui_obj_container(obj);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
585 UI_APPLY_LAYOUT(ctn->layout, args);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
586
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
587 Widget parent = ctn->prepare(ctn, xargs, &n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
588 // TODO: name
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
589
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
590 PathBar *pathbar = CreatePathBar(parent, xargs, n);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
591 XtManageChild(pathbar->widget);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
592 ctn->add(ctn, pathbar->widget);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
593
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
594 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
595 if (var) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
596 UiString* value = (UiString*)var->value;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
597 value->obj = pathbar;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
598 value->get = ui_path_textfield_get;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
599 value->set = ui_path_textfield_set;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
600
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
601 if(value->value.ptr) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
602 char *str = strdup(value->value.ptr);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
603 ui_string_set(value, str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
604 free(str);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
605 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
606 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
607
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
608 XtAddCallback(
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
609 pathbar->widget,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
610 XmNdestroyCallback,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
611 (XtCallbackProc)destroy_pathbar,
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
612 pathbar);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
613
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
614 return pathbar->widget;
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
615 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
616
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
617 char* ui_path_textfield_get(UiString *str) {
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
618
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
619 }
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
620
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
621 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
622 PathBarSetPath(str->obj, value);
ef60d527c066 add text field widgets (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 406
diff changeset
623 }

mercurial