ui/motif/list.c

Fri, 14 Jun 2024 18:25:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 14 Jun 2024 18:25:43 +0200
branch
newapi
changeset 291
302a150ff5e4
parent 176
bc63cb601f6d
permissions
-rw-r--r--

implement ui_list_getselection (GTK)

34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0ec8a5f17782 added listview and sidebar (Motif)
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
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "container.h"
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "list.h"
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 void* ui_strmodel_getvalue(void *elm, int column) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 return column == 0 ? elm : NULL;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 UIWIDGET ui_listview_str(UiObject *obj, UiList *list, ui_callback f, void *udata) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 return ui_listview(obj, list, ui_strmodel_getvalue, f, udata);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
47 UIWIDGET ui_listview_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
36
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
48 int count;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
49 XmStringTable items = ui_create_stringlist(var->value, getvalue, &count);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 Arg args[8];
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 int n = 0;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 XtSetArg(args[n], XmNitemCount, count);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 n++;
36
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
55 XtSetArg(args[n], XmNitems, count == 0 ? NULL : items);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 n++;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UiContainer *ct = uic_get_current_container(obj);
60
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
59 Widget parent = ct->prepare(ct, args, &n, TRUE);
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
60 Widget widget = XmCreateScrolledList(parent, "listview", args, n);
63
46a42f0c4f93 added textfield and some container fixes (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
61 ct->add(ct, XtParent(widget));
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 XtManageChild(widget);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
64 UiListView *listview = cxMalloc(obj->ctx->allocator, sizeof(UiListView));
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 listview->widget = widget;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
66 listview->list = var;
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 listview->getvalue = getvalue;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 for (int i=0;i<count;i++) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 XmStringFree(items[i]);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 XtFree((char *)items);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(f) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
75 UiListViewEventData *event = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
76 obj->ctx->allocator,
77
bc0ed99e49c7 fixed memory allocation bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
77 sizeof(UiListViewEventData));
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 event->event.obj = obj;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
79 event->event.userdata = udata;
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 event->event.callback = f;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 event->event.value = 0;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
82 event->var = var;
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 XtAddCallback(
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 widget,
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 XmNdefaultActionCallback,
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 (XtCallbackProc)ui_list_selection_callback,
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 event);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 return widget;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
93 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
94 UiVar *var = malloc(sizeof(UiVar));
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
95 var->value = list;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
96 var->type = UI_VAR_SPECIAL;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
97 return ui_listview_var(obj, var, getvalue, f, udata);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
100 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
101 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 if(var) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 UiListVar *value = var->value;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
104 return ui_listview_var(obj, var, getvalue, f, udata);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 } else {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 // TODO: error
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 return NULL;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
112 XmStringTable ui_create_stringlist(UiList *list, ui_getvaluefunc getvalue, int *count) {
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 int num = list->count(list);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 XmStringTable items = (XmStringTable)XtMalloc(num * sizeof(XmString));
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 void *data = list->first(list);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 for(int i=0;i<num;i++) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 items[i] = XmStringCreateLocalized(getvalue(data, 0));
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 data = list->next(list);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 *count = num;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 return items;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 void ui_listview_update(UiEvent *event, UiListView *view) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 int count;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 XmStringTable items = ui_create_stringlist(
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
129 view->list->value,
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 view->getvalue,
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 &count);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
36
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
133 XtVaSetValues(
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
134 view->widget,
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
135 XmNitems, count == 0 ? NULL : items,
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
136 XmNitemCount,
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
137 count,
e4198fc2ead4 fixed list, text and added ui_close (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 34
diff changeset
138 NULL);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 for (int i=0;i<count;i++) {
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 XmStringFree(items[i]);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 XtFree((char *)items);
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 void ui_list_selection_callback (Widget widget, UiListViewEventData *event, XtPointer data) {
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
147 XmListCallbackStruct *cbs = (XmListCallbackStruct *)data;
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 UiEvent e;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 e.obj = event->event.obj;
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 e.window = event->event.obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
152 e.document = event->event.obj->ctx->document;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
153 UiList *list = event->var->value;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
154 e.eventdata = list->get(list, cbs->item_position - 1);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 e.intval = cbs->item_position - 1;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
156 event->event.callback(&e, event->event.userdata);
34
0ec8a5f17782 added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 }
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
158
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
159
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
160 /* --------------------------- ComboBox --------------------------- */
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
161
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
162 UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata) {
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
163 return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
164 }
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
165
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
166 UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
167 UiVar *var = malloc(sizeof(UiVar));
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
168 var->value = list;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
169 var->type = UI_VAR_SPECIAL;
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
170 return ui_combobox_var(obj, var, getvalue, f, udata);
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
171 }
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
172
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
173 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
174 UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_LIST);
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
175 if(var) {
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
176 UiListVar *value = var->value;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
177 return ui_combobox_var(obj, var, getvalue, f, udata);
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
178 } else {
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
179 // TODO: error
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
180 }
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
181 return NULL;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
182 }
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
183
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
184 UIWIDGET ui_combobox_var(UiObject *obj, UiVar *var, ui_getvaluefunc getvalue, ui_callback f, void *udata) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
185 UiListView *listview = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
186 obj->ctx->allocator,
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
187 sizeof(UiListView));
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
188
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
189 UiContainer *ct = uic_get_current_container(obj);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
190 Arg args[16];
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
191 int n = 0;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
192 XtSetArg(args[n], XmNindicatorOn, XmINDICATOR_NONE);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
193 n++;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
194 XtSetArg(args[n], XmNtraversalOn, FALSE);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
195 n++;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
196 XtSetArg(args[n], XmNwidth, 160);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
197 n++;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
198 Widget parent = ct->prepare(ct, args, &n, FALSE);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
199 Widget combobox = XmCreateDropDownList(parent, "combobox", args, n);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
200 XtManageChild(combobox);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
201 listview->widget = combobox;
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 122
diff changeset
202 listview->list = var;
117
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
203 listview->getvalue = getvalue;
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
204
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
205 ui_listview_update(NULL, listview);
38c53b8a6139 added combobox (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
206
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
207 return parent;
122
e82b01d17a78 added some special textfields (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
208 }

mercurial