ui/motif/tree.c

Tue, 24 Jan 2017 18:46:47 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 24 Jan 2017 18:46:47 +0100
changeset 139
dbde25a5bc53
parent 128
c284c15509a8
child 153
ee49d1852a5f
permissions
-rw-r--r--

fixes a ucx include

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"
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
38 #include "../common/context.h"
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "../../ucx/utils.h"
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 // TODO: check if modelinfo is complete
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
60
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
44 Arg args[32];
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 int n = 0;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
47 // create scrolled window
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
48 UiContainer *ct = uic_get_current_container(obj);
60
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
49 Widget parent = ct->prepare(ct, args, &n, TRUE);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
50
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
51 XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
52 n++;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
53 XtSetArg(args[n], XmNshadowThickness, 0);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
54 n++;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
55 Widget scrollw = XmCreateScrolledWindow(parent, "scroll_win", args, n);
60
7cd1b8890302 added vbox container (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
56 ct->add(ct, scrollw);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
57 XtManageChild(scrollw);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
58
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 // create table headers
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 XmStringTable header = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 modelinfo->columns * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 header[i] = XmStringCreateLocalized(modelinfo->titles[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
65 n = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 XtSetArg(args[n], XmNdetailColumnHeading, header);
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 XtSetArg(args[n], XmNdetailColumnHeadingCount, modelinfo->columns);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 // set res
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 XtSetArg(args[n], XmNlayoutType, XmDETAIL);
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], XmNentryViewType, XmSMALL_ICON);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 n++;
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
78 XtSetArg(args[n], XmNwidth, 600);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
79 n++;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
82 //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
83 //Widget parent = ct->add(ct, args, &n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
85 Widget container = XmCreateContainer(scrollw, "table", args, n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 XtManageChild(container);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
88 // add callbacks
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 event->obj = obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
91 event->activate = modelinfo->activate;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
92 event->selection = modelinfo->selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
93 event->userdata = modelinfo->userdata;
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
94 event->last_selection = NULL;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
95 if(modelinfo->selection) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
96 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
97 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
98 XmNselectionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
99 (XtCallbackProc)ui_table_select_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
100 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
101 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
102 if(modelinfo->activate) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
103 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
105 XmNdefaultActionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
106 (XtCallbackProc)ui_table_action_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
107 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
108 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
109
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 // add initial data
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 void *data = model->first(model);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
112 int width = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 while(data) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
114 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
115 if(w > width) {
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
116 width = w;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
117 }
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 data = model->next(model);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
121 UiTableView *tableview = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiTableView));
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
122 tableview->widget = container;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
123 tableview->list = model;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
124 tableview->modelinfo = modelinfo;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
125 model->observers = ui_add_observer(
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
126 model->observers,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
127 (ui_callback)ui_table_update,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
128 tableview);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
129
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
130 // set new XmContainer width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
131 XtVaSetValues(container, XmNwidth, width, NULL);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
132
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 XmStringFree(header[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 XtFree((char*)header);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
139 return scrollw;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
128
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
142 void ui_table_update(UiEvent *event, UiTableView *view) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
143 // clear container
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
144 Widget *children;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
145 int nc;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
146
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
147 XtVaGetValues(
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
148 view->widget,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
149 XmNchildren,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
150 &children,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
151 XmNnumChildren,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
152 &nc,
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
153 NULL);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
154
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
155 for(int i=0;i<nc;i++) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
156 XtDestroyWidget(children[i]);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
157 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
158
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
159 UiList *model = view->list;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
160
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
161 void *data = model->first(model);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
162 int width = 0;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
163 while(data) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
164 int w = ui_add_icon_gadget(view->widget, view->modelinfo, data);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
165 if(w > width) {
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
166 width = w;
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
167 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
168 data = model->next(model);
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
169 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
170
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
171 }
c284c15509a8 fixes var binding and motif tableview
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
172
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
173 #define UI_COL_CHAR_WIDTH 12
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
174
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
175 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
176 int width = 50;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
177
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 if(modelinfo->columns == 0) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
179 return width;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 XmString label = NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 Arg args[8];
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 Boolean f;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 // first column
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 if(modelinfo->types[0] != 12345678) { // TODO: icon/label type
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 modelinfo->types[0],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 modelinfo->getvalue(data, 0),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
191
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
192 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
193 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
194
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
195
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 XmString label = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 XtSetArg(args[0], XmNlabelString, label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 free(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 } else {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 // TODO
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 // remaining columns are the icon gadget details
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 XmStringTable details = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 (modelinfo->columns - 1) * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 for(int i=1;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 modelinfo->types[i],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 modelinfo->getvalue(data, i),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
213
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
214 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
215 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
216
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 details[i - 1] = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 free(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 XtSetArg(args[1], XmNdetail, details);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 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
224 XtSetArg(args[3], XmNshadowThickness, 0);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
226 Widget item = XmCreateIconGadget(container, "table_item", args, 4);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 XtManageChild(item);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 XmStringFree(label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 for(int i=0;i<modelinfo->columns-1;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 XmStringFree(details[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 XtFree((char*)details);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
235
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
236 return width;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 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
240 switch(type) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 case UI_STRING: *free = FALSE; return data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 case UI_INTEGER: {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 *free = TRUE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 int *val = data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 sstr_t str = ucx_asprintf(ucx_default_allocator(), "%d", *val);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 return str.ptr;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 *free = FALSE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 return NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
252
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
253 void ui_table_action_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
254 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
255 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
256 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
257 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
258 UiListSelection *selection = ui_list_selection(sel);
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
259
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
260 UiEvent e;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
261 e.obj = event->obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
262 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
263 e.document = event->obj->ctx->document;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
264 e.eventdata = selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
265 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
266 event->activate(&e, event->userdata);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
267
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
268 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
269 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
270 event->last_selection = selection;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
271 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
272
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
273 void ui_table_select_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
274 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
275 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
276 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
277 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
278 UiListSelection *selection = ui_list_selection(sel);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
279 if(!ui_compare_list_selection(selection, event->last_selection)) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
280 UiEvent e;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
281 e.obj = event->obj;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
282 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
283 e.document = event->obj->ctx->document;
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
284 e.eventdata = selection;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
285 e.intval = selection->count > 0 ? selection->rows[0] : -1;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
286 event->selection(&e, event->userdata);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
287 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
288 if(event->last_selection) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
289 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
290 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
291 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
292 event->last_selection = selection;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
293 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
294
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
295 UiListSelection* ui_list_selection(XmContainerSelectCallbackStruct *xs) {
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
296 UiListSelection *selection = malloc(sizeof(UiListSelection));
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
297 selection->count = xs->selected_item_count;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
298 selection->rows = calloc(selection->count, sizeof(int));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
299 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
300 int index;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
301 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
302 selection->rows[i] = index;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
303 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
304 return selection;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
305 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
306
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
307 Boolean ui_compare_list_selection(UiListSelection *s1, UiListSelection *s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
308 if(!s1 || !s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
309 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
310 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
311 if(s1->count != s2->count) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
312 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
313 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
314 for(int i=0;i<s1->count;i++) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
315 if(s1->rows[i] != s2->rows[i]) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
316 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
317 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
318 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
319 return TRUE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
320 }

mercurial