ui/motif/tree.c

Tue, 22 Jul 2014 19:15:44 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 22 Jul 2014 19:15:44 +0200
changeset 53
62205699cd0e
parent 52
25e5390cce41
child 60
7cd1b8890302
permissions
-rw-r--r--

improved motif tabs

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
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 Arg args[16];
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);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
49 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
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);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
56 XtManageChild(scrollw);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
57
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 // create table headers
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 XmStringTable header = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 modelinfo->columns * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 header[i] = XmStringCreateLocalized(modelinfo->titles[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
64 n = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 XtSetArg(args[n], XmNdetailColumnHeading, header);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 XtSetArg(args[n], XmNdetailColumnHeadingCount, modelinfo->columns);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 // set res
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 XtSetArg(args[n], XmNlayoutType, XmDETAIL);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 XtSetArg(args[n], XmNentryViewType, XmSMALL_ICON);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 n++;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 n++;
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
77 XtSetArg(args[n], XmNwidth, 600);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
78 n++;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
81 //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
82 //Widget parent = ct->add(ct, args, &n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
84 Widget container = XmCreateContainer(scrollw, "table", args, n);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 XtManageChild(container);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
87 // add callbacks
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
88 UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
89 event->obj = obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
90 event->activate = modelinfo->activate;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
91 event->selection = modelinfo->selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
92 event->userdata = modelinfo->userdata;
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
93 event->last_selection = NULL;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
94 if(modelinfo->selection) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
95 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
96 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
97 XmNselectionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
98 (XtCallbackProc)ui_table_select_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
99 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
100 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
101 if(modelinfo->activate) {
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
102 XtAddCallback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
103 container,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
104 XmNdefaultActionCallback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
105 (XtCallbackProc)ui_table_action_callback,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
106 event);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
107 }
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
108
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 // add initial data
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 void *data = model->first(model);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
111 int width = 0;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 while(data) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
113 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
114 if(w > width) {
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
115 width = w;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
116 }
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 data = model->next(model);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
120 // set new XmContainer width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
121 XtVaSetValues(container, XmNwidth, width, NULL);
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
122
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 for(int i=0;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 XmStringFree(header[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 XtFree((char*)header);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
129 return scrollw;
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
132 #define UI_COL_CHAR_WIDTH 12
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
133
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
134 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
135 int width = 50;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
136
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 if(modelinfo->columns == 0) {
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
138 return width;
39
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
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 XmString label = NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 Arg args[8];
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 Boolean f;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 // first column
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 if(modelinfo->types[0] != 12345678) { // TODO: icon/label type
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 modelinfo->types[0],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 modelinfo->getvalue(data, 0),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
150
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
151 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
152 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
153
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
154
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 XmString label = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 XtSetArg(args[0], XmNlabelString, label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 free(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 } else {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 // TODO
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
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 // remaining columns are the icon gadget details
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 XmStringTable details = (XmStringTable)XtMalloc(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 (modelinfo->columns - 1) * sizeof(XmString));
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 for(int i=1;i<modelinfo->columns;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 char *str = ui_type_to_string(
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 modelinfo->types[i],
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 modelinfo->getvalue(data, i),
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 &f);
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
172
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
173 // column width
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
174 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
175
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 details[i - 1] = XmStringCreateLocalized(str);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 if(f) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 free(str);
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 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 XtSetArg(args[1], XmNdetail, details);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 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
183 XtSetArg(args[3], XmNshadowThickness, 0);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 // create widget
45
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
185 Widget item = XmCreateIconGadget(container, "table_item", args, 4);
39
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 XtManageChild(item);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 // cleanup
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 XmStringFree(label);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 for(int i=0;i<modelinfo->columns-1;i++) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 XmStringFree(details[i]);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 XtFree((char*)details);
45
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 return width;
39
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
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 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
199 switch(type) {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 case UI_STRING: *free = FALSE; return data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 case UI_INTEGER: {
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 *free = TRUE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 int *val = data;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 sstr_t str = ucx_asprintf(ucx_default_allocator(), "%d", *val);
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 return str.ptr;
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 }
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 *free = FALSE;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 return NULL;
4e66271541e8 added table view (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 }
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
211
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
212 void ui_table_action_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
213 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
214 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
215 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
216 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
217 UiListSelection *selection = ui_list_selection(sel);
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
218
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
219 UiEvent e;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
220 e.obj = event->obj;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
221 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
222 e.document = event->obj->ctx->document;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
223 e.eventdata = selection;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
224 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
225 event->activate(&e, event->userdata);
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
226
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
227 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
228 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
229 event->last_selection = selection;
43
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
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
232 void ui_table_select_callback(
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
233 Widget widget,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
234 UiTreeEventData *event,
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
235 XmContainerSelectCallbackStruct *sel)
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
236 {
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
237 UiListSelection *selection = ui_list_selection(sel);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
238 if(!ui_compare_list_selection(selection, event->last_selection)) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
239 UiEvent e;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
240 e.obj = event->obj;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
241 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
242 e.document = event->obj->ctx->document;
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
243 e.eventdata = selection;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
244 e.intval = selection->count > 0 ? selection->rows[0] : -1;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
245 event->selection(&e, event->userdata);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
246 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
247 if(event->last_selection) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
248 free(event->last_selection->rows);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
249 free(event->last_selection);
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
250 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
251 event->last_selection = selection;
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
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
254 UiListSelection* ui_list_selection(XmContainerSelectCallbackStruct *xs) {
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
255 UiListSelection *selection = malloc(sizeof(UiListSelection));
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
256 selection->count = xs->selected_item_count;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
257 selection->rows = calloc(selection->count, sizeof(int));
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
258 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
259 int index;
cfeb2d5f1332 added scrolled window for table widget (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
260 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
261 selection->rows[i] = index;
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
262 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
263 return selection;
43
157a21a914ac added table view events (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
264 }
44
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
265
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
266 Boolean ui_compare_list_selection(UiListSelection *s1, UiListSelection *s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
267 if(!s1 || !s2) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
268 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
269 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
270 if(s1->count != s2->count) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
271 return FALSE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
272 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
273 for(int i=0;i<s1->count;i++) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
274 if(s1->rows[i] != s2->rows[i]) {
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
275 return FALSE;
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 }
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
278 return TRUE;
a1571777eff2 optimized selection callback (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
279 }

mercurial