ui/motif/tree.c

Sat, 17 May 2014 10:48:59 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 17 May 2014 10:48:59 +0200
changeset 45
cfeb2d5f1332
parent 44
a1571777eff2
child 52
25e5390cce41
permissions
-rw-r--r--

added scrolled window for table widget (Motif)

39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4e66271541e8 added table view (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
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
32 #include <inttypes.h>
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "tree.h"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "container.h"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../common/object.h"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../../ucx/utils.h"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 // TODO: check if modelinfo is complete
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 Arg args[16];
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 int n = 0;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
46 // create scrolled window
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
47 UiContainer *ct = uic_get_current_container(obj);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
48 Widget parent = ct->add(ct, args, &n);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
49
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
50 XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
51 n++;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
52 XtSetArg(args[n], XmNshadowThickness, 0);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
53 n++;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
54 Widget scrollw = XmCreateScrolledWindow(parent, "scroll_win", args, n);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
55 XtManageChild(scrollw);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
56
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 // create table headers
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 XmStringTable header = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 modelinfo->columns * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 header[i] = XmStringCreateLocalized(modelinfo->titles[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
63 n = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 XtSetArg(args[n], XmNdetailColumnHeading, header);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 XtSetArg(args[n], XmNdetailColumnHeadingCount, modelinfo->columns);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 // set res
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 XtSetArg(args[n], XmNlayoutType, XmDETAIL);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 XtSetArg(args[n], XmNentryViewType, XmSMALL_ICON);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 n++;
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
76 XtSetArg(args[n], XmNwidth, 600);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
77 n++;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
80 //UiContainer *ct = uic_get_current_container(obj);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
81 //Widget parent = ct->add(ct, args, &n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
83 Widget container = XmCreateContainer(scrollw, "table", args, n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 XtManageChild(container);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
86 // add callbacks
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
87 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
88 event->obj = obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 event->activate = modelinfo->activate;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 event->selection = modelinfo->selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
91 event->userdata = modelinfo->userdata;
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
92 event->last_selection = NULL;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
93 if(modelinfo->selection) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
94 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
95 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
96 XmNselectionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
97 (XtCallbackProc)ui_table_select_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
98 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
99 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
100 if(modelinfo->activate) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
101 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
102 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
103 XmNdefaultActionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 (XtCallbackProc)ui_table_action_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
105 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
106 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
107
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 // add initial data
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 void *data = model->first(model);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
110 int width = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 while(data) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
112 int w = ui_add_icon_gadget(container, modelinfo, data);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
113 if(w > width) {
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
114 width = w;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
115 }
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 data = model->next(model);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
119 // set new XmContainer width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
120 XtVaSetValues(container, XmNwidth, width, NULL);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
121
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 XmStringFree(header[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 XtFree((char*)header);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
128 return scrollw;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
131 #define UI_COL_CHAR_WIDTH 12
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
132
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
133 int ui_add_icon_gadget(Widget container, UiModelInfo *modelinfo, void *data) {
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
134 int width = 50;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
135
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 if(modelinfo->columns == 0) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
137 return width;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 XmString label = NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 Arg args[8];
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 Boolean f;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 // first column
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 if(modelinfo->types[0] != 12345678) { // TODO: icon/label type
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 modelinfo->types[0],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 modelinfo->getvalue(data, 0),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
149
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
150 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
151 width += strlen(str) * UI_COL_CHAR_WIDTH;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
152
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
153
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 XmString label = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 XtSetArg(args[0], XmNlabelString, label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 free(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 } else {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 // TODO
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 // remaining columns are the icon gadget details
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 XmStringTable details = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 (modelinfo->columns - 1) * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 for(int i=1;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 modelinfo->types[i],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 modelinfo->getvalue(data, i),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
171
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
172 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
173 width += strlen(str) * UI_COL_CHAR_WIDTH;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
174
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 details[i - 1] = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 free(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 XtSetArg(args[1], XmNdetail, details);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 XtSetArg(args[2], XmNdetailCount, modelinfo->columns - 1);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
182 XtSetArg(args[3], XmNshadowThickness, 0);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
184 Widget item = XmCreateIconGadget(container, "table_item", args, 4);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 XtManageChild(item);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 XmStringFree(label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 for(int i=0;i<modelinfo->columns-1;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 XmStringFree(details[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 XtFree((char*)details);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
193
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
194 return width;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 char* ui_type_to_string(UiModelType type, void *data, Boolean *free) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 switch(type) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 case UI_STRING: *free = FALSE; return data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 case UI_INTEGER: {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 *free = TRUE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 int *val = data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 sstr_t str = ucx_asprintf(ucx_default_allocator(), "%d", *val);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 return str.ptr;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 *free = FALSE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 return NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 }
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
210
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
211 void ui_table_action_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
212 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
213 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
214 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
215 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
216 UiListSelection *selection = ui_list_selection(sel);
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
217
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
218 UiEvent e;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
219 e.obj = event->obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
220 e.window = event->obj->window;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
221 e.document = event->obj->document;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
222 e.eventdata = selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
223 e.intval = selection->count > 0 ? selection->rows[0] : -1;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
224 event->activate(&e, event->userdata);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
225
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
226 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
227 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
228 event->last_selection = selection;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
229 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
230
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
231 void ui_table_select_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
232 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
233 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
234 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
235 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
236 UiListSelection *selection = ui_list_selection(sel);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
237 if(!ui_compare_list_selection(selection, event->last_selection)) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
238 UiEvent e;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
239 e.obj = event->obj;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
240 e.window = event->obj->window;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
241 e.document = event->obj->document;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
242 e.eventdata = selection;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
243 e.intval = selection->count > 0 ? selection->rows[0] : -1;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
244 event->selection(&e, event->userdata);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
245 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
246 if(event->last_selection) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
247 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
248 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
249 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
250 event->last_selection = selection;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
251 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
252
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
253 UiListSelection* ui_list_selection(XmContainerSelectCallbackStruct *xs) {
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
254 UiListSelection *selection = malloc(sizeof(UiListSelection));
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
255 selection->count = xs->selected_item_count;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
256 selection->rows = calloc(selection->count, sizeof(int));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
257 for(int i=0;i<selection->count;i++) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
258 int index;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
259 XtVaGetValues(xs->selected_items[i], XmNpositionIndex, &index, NULL);
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
260 selection->rows[i] = index;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
261 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
262 return selection;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
263 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
264
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
265 Boolean ui_compare_list_selection(UiListSelection *s1, UiListSelection *s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
266 if(!s1 || !s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
267 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
268 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
269 if(s1->count != s2->count) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
270 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
271 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
272 for(int i=0;i<s1->count;i++) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
273 if(s1->rows[i] != s2->rows[i]) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
274 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
275 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
276 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
277 return TRUE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
278 }

mercurial