ui/motif/tree.c

Mon, 23 Sep 2024 23:22:27 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 23 Sep 2024 23:22:27 +0200
branch
newapi
changeset 309
02c95df91de1
parent 176
bc63cb601f6d
permissions
-rw-r--r--

add headerbar toggle button (GTK)

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

mercurial