-
Notifications
You must be signed in to change notification settings - Fork 6
/
widget.lisp
283 lines (227 loc) · 9.15 KB
/
widget.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
;; -*- mode: Lisp; Syntax: Common-Lisp; Package: qooxlisp; -*-
#|
widget
(See package.lisp for license and copyright notigification)
|#
(in-package :qxl)
(defmd qx-atom (qx-widget)
label)
(defmethod qx-configurations append ((self qx-atom))
(nconc
(b-when x (label self)
(list (cons :label x)))))
(defobserver label ((self qx-atom))
(when old-value
(with-integrity (:client `(:post-make-qx ,self))
(qxfmt "clDict[~a].setLabel('~a');" (oid self) (or new-value "")))))
(defmd qx-list (qooxlisp-control qx-widget qooxlisp-family)
:value (c-in nil)
(qx-class "qx.ui.form.List" :allocation :class :cell nil)
selection-mode ;; single (default), multi, additive, or one
(onchangeselection (lambda (self req)
(print (list :generic-list-changesel-fires (req-val req "value")))
(let* ((nv (req-val req "value"))
(nvs (split-sequence #\! nv)))
(setf (^value) nvs))))
spacing)
(defobserver .kids ((self qx-list))
(with-cc :newlist
(setf (^value) nil)))
(defobserver onchangeselection () ;; unspecialized, hoping all selections are lists
(typecase self
(qx-radio-button-group-ex
(with-integrity (:client `(:post-assembly ,self))
(cond
(new-value (qxfmt "
clDict[~a].grouper.addListener('changeSelection', function(e) {
var items = e.getData();
if (items.length > 0) {
var sel = '';
for (i = 0; i < items.length; ++i) {
if (i > 0) sel = sel + '!';
sel = sel + items[i].oid;
}
var req = new qx.io.remote.Request('/callback','GET', 'text/javascript');
req.setParameter('sessId', sessId);
req.setParameter('oid', ~@*~a);
req.setParameter('opcode', 'onchangeselection');
req.setParameter('value',sel);
req.addListener('timeout',function () {alert('Timeout waiting on server');});
req.send();
}
});" (oid self))))))
(otherwise
(with-integrity (:client `(:post-make-qx ,self))
(cond
(new-value (qxfmt "
clDict[~a].addListener('changeSelection', function(e) {
var items = e.getData();
var sel = '';
for (i = 0; i < items.length; ++i) {
if (i > 0) sel = sel + '!';
sel = sel + items[i].oid;
}
var req = new qx.io.remote.Request('/callback','GET', 'text/javascript');
req.setParameter('sessId', sessId);
req.setParameter('oid', ~@*~a);
req.setParameter('opcode', 'onchangeselection');
req.setParameter('value',sel);
req.send();
});" (oid self))))))))
(defmethod qx-configurations append ((self qx-list))
(nconc
(cfg spacing)
(cfg selection-mode)))
;;; --- qx-combo-box --------------------------------------
(defmd qx-abstract-select-box (qooxlisp-control qx-widget qooxlisp-family))
(defmd qx-combo-box (qx-abstract-select-box)
(qx-class "qx.ui.form.ComboBox" :allocation :class :cell nil)
(onchangevalue (lambda (self req)
(trcx :qx-combo-box-onchangevalue-fires (req-val req "value"))
(let ((nv (req-val req "value")))
(setf (^value) nv))))
:value (c-in nil))
(defobserver onchangevalue ()
(with-integrity (:client `(:post-make-qx ,self))
(cond
(new-value (qxfmt "
clDict[~a].addListener('changeValue', function(e) {
var rq = new qx.io.remote.Request('/callback','GET','text/javascript');
rq.setParameter('sessId', sessId);
rq.setParameter('opcode', 'onchangevalue');
rq.setParameter('oid',~:*~a);
console.log('generic onchgval sees data ', e.getData());
rq.setParameter('value', e.getData());
rq.send();
});" (oid self))))))
(defmd qx-abstract-field (qx-widget)
(qx-class "qx.ui.form.AbstractField" :allocation :class :cell nil)
(onchangevalue (lambda (self req)
(let ((nv (req-val req "value")))
(setf (^value) nv))))
:value (c-in nil))
(defmd qx-text-field (qx-abstract-field)
(qx-class "qx.ui.form.TextField" :allocation :class :cell nil))
(defmd qx-password-field (qx-text-field)
(qx-class "qx.ui.form.PasswordField" :allocation :class :cell nil))
(export! qx-text-field qx-password-field)
(defmd qx-list-item (qx-atom)
(qx-class "qx.ui.form.ListItem" :allocation :class :cell nil)
model) ;; >>> bad idea? Use value? Why is model sent to client? Most Lisp objects won't go there
(defmethod qx-configurations append ((self qx-list-item))
(nconc
(b-when x (model self)
(list (cons :model x)))))
(defmacro listitem (label-form &optional model)
(let ((label (gensym)))
`(let ((,label ,label-form))
(trcx :listitwm-model-label (or ,model ,label) ,label)
(make-kid 'qx-list-item
:label ,label
:model (or ,model ,label)))))
;;; --- button --------------------------------------
(defmd qx-button (qooxlisp-control qx-atom)
(qx-class "qx.ui.form.Button" :allocation :class :cell nil)
:allow-grow-x :js-false :allow-grow-y :js-false)
;;; --- label --------------------------------------
(defmd qx-label (qx-widget)
(qx-class "qx.ui.basic.Label" :allocation :class :cell nil)
text$
rich
:allow-grow-x :js-false
:allow-grow-y :js-false)
(defmethod qx-configurations append ((self qx-label))
(nconc
(cfg rich)
(cfg value text$)))
(defobserver text$ ((self qx-label))
;; I think we need this for when value changes vs. during image creation
;; >>> prolly a good idea to figure this out
(with-integrity (:client `(:post-make-qx ,self))
(qxfmt "clDict[~a].setValue('~a');" (oid self) (or new-value ""))))
(defmd qx-image (qx-widget)
(qx-class "qx.ui.basic.Image" :allocation :class :cell nil)
source
scale)
(defmethod qx-configurations append ((self qx-image))
(nconc
(cfg source)
(cfg scale)))
(defmd qx-toggle-button (qx-atom qooxlisp-control )
(value (c-in nil))
(onchangevalue (lambda (self req)
(trc "qx-toggle-button-onchangevalue-fires"
(req-val req "value")
self req)
(let ((nv (cvtjs (req-val req "value"))))
(setf (^value) nv)
(trcx :toggle-chgval self nv)))))
(defmethod qx-configurations append ((self qx-toggle-button))
(nconc
(b-when x (value self)
(trc "qx-toggle-button config value" x self)
(list (cons :value x)))))
(defmd qx-check-box (qx-toggle-button )
(qx-class "qx.ui.form.CheckBox" :allocation :class :cell nil))
(defmd qx-select-box (qx-abstract-select-box)
(qx-class "qx.ui.form.SelectBox" :allocation :class :cell nil)
(onchangeselection (lambda (self req)
(let ((nv (req-val req "value")))
(trc "qx-select-box onchgsel sees nv, req" nv req)
(setf (^value) nv))))
:value (c-in nil))
(defmd qx-scroll (qx-widget qooxlisp-family)
(qx-class "qx.ui.container.Scroll" :allocation :class :cell nil)
)
(defmd qx-stack (qx-widget qooxlisp-family) ;; oops, too close to qxl-stack, which is really a vbox
;; this is actually an overlay
(qx-class "qx.ui.container.Stack" :allocation :class :cell nil)
selection
)
(defobserver selection ((self qx-stack))
(with-integrity (:client `(:post-make-qx ,self))
(cond
(new-value (trcx qx-stack-sets-sel self new-value)
(qxfmt "clDict[~a].setSelection([clDict[~a]]);" (oid self)(oid new-value)))
(old-value (trcx qx-stack-clears-sel new-value)
(qxfmt "clDict[~a].setSelection(null);" (oid self))))))
(defmd qx-tab-view (qx-widget qooxlisp-family)
(qx-class "qx.ui.tabview.TabView" :allocation :class :cell nil)
bar-position
:value (c?n (car (^kids)))
(onchangeselection (lambda (self req)
(let* ((nv (req-val req "value"))
(nvs (split-sequence #\! nv))
(page-id (parse-integer (car nvs)))
)
(b-when page (oid-to-object page-id)
(when (bookmark? page)
(qxfmt "qx.bom.History.getInstance().addToHistory('~a', '~a');"
(md-name page) (label page)))
(setf (^value) page))))))
(defmethod qx-configurations append ((self qx-tab-view))
(nconc (cfg bar-position)))
(defmd qx-tab-page (qx-composite)
(qx-class "qx.ui.tabview.Page" :allocation :class :cell nil)
label icon
(bookmark? nil :cell nil))
(export! bookmark?)
(defobserver label ((self qx-tab-page))
(when old-value
(with-integrity (:client `(:post-make-qx ,self))
(qxfmt "clDict[~a].setLabel('~a');" (oid self) (or new-value "")))))
(defobserver icon ((self qx-tab-page))
(with-integrity (:client `(:post-make-qx ,self))
(qxfmt "clDict[~a].setIcon('~a');" (oid self) (or new-value ""))))
(defmethod qx-configurations append ((self qx-tab-page))
(nconc (cfg label)(cfg icon)))
;;; --------------- selector ------------------------------------
(export! qxl-selector selection ^selection .selector .selection
selected-key ^selected-key multiple-choice? toggle?)
(defmd qxl-selector ()
selection
selected-key
multiple-choice?
toggle?)
(define-symbol-macro .selector (n^ qxl-selector))
(define-symbol-macro .selection (selection .selector))