6886
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
6561
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2014 by Claus Gittinger
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libview' }"
|
|
15 |
|
6886
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
6561
|
18 |
DeviceWorkstation subclass:#GuiServerWorkstation
|
|
19 |
instanceVariableNames:'guiServerPid out in connectionTimeout
|
|
20 |
connectionTimeoutForWindowCreation hasConnectionBroken
|
|
21 |
dispatchingExpose buttonsPressed displayName listOfFonts fontMap
|
|
22 |
viewMap nextId useExtraCanvas answerSemaphore accessLock
|
|
23 |
useNativeWidgets'
|
|
24 |
classVariableNames:'DefaultConnectionTimeout
|
|
25 |
DefaultConnectionTimeoutForWindowCreation KeyPressMask
|
|
26 |
KeyReleaseMask ButtonPressMask ButtonReleaseMask ButtonMotionMask
|
|
27 |
PointerMotionMask ExposureMask FocusChangeMask EnterWindowMask
|
|
28 |
LeaveWindowMask KeymapStateMask VisibilityChangeMask
|
|
29 |
StructureNotifyMask ResizeRedirectMask PropertyChangeMask
|
|
30 |
ColormapChangeMask SubstructureNotifyMask
|
|
31 |
SubstructureRedirectMask'
|
|
32 |
poolDictionaries:''
|
|
33 |
category:'Interface-Graphics'
|
|
34 |
!
|
|
35 |
|
|
36 |
!GuiServerWorkstation class methodsFor:'documentation'!
|
|
37 |
|
|
38 |
copyright
|
|
39 |
"
|
|
40 |
COPYRIGHT (c) 2014 by Claus Gittinger
|
|
41 |
All Rights Reserved
|
|
42 |
|
|
43 |
This software is furnished under a license and may be used
|
|
44 |
only in accordance with the terms of that license and with the
|
|
45 |
inclusion of the above copyright notice. This software may not
|
|
46 |
be provided or otherwise made available to, or used by, any
|
|
47 |
other person. No title to or ownership of the software is
|
|
48 |
hereby transferred.
|
|
49 |
"
|
|
50 |
!
|
|
51 |
|
|
52 |
documentation
|
|
53 |
"
|
|
54 |
This is an experimental UI interface, not yet ready for general use.
|
|
55 |
|
|
56 |
This class provides the interface to the GUIServer.
|
|
57 |
It redefines all required methods from DeviceWorkstation.
|
|
58 |
|
|
59 |
The GUIServer is a little Java program, which provides a socket interface,
|
|
60 |
allowing for GUI operations to be sent and events to be received.
|
|
61 |
Thus providing a platform independent, portable and nice looking GUI interface alternative.
|
|
62 |
|
|
63 |
[author:]
|
|
64 |
Claus Gittinger
|
|
65 |
"
|
|
66 |
!
|
|
67 |
|
|
68 |
example
|
|
69 |
"
|
|
70 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
6886
|
71 |
Smalltalk at:#D2 put:(self new initializeFor:'localhost:64001')
|
6561
|
72 |
|
|
73 |
D2 startDispatch.
|
|
74 |
|
|
75 |
(View onDevice:D2) open.
|
|
76 |
(Button onDevice:D2) label:'Hello'; open.
|
|
77 |
|
|
78 |
|v b1 b2|
|
|
79 |
v := View onDevice:D2.
|
|
80 |
v extent:200@200.
|
|
81 |
b1 := Button label:'Press Me' in:v. b1 extent:100@50.
|
|
82 |
b2 := Button label:'Me Too' in:v. b2 extent:100@50.
|
|
83 |
b2 top:60.
|
|
84 |
b1 action:[ Transcript showCR:'b1 pressed'. b1 extent:150@40].
|
|
85 |
b2 action:[ Transcript showCR:'b2 pressed'].
|
|
86 |
v open.
|
|
87 |
v inspect.
|
|
88 |
|
|
89 |
(SystemBrowser onDevice:D2) open
|
|
90 |
"
|
|
91 |
!
|
|
92 |
|
|
93 |
example1
|
|
94 |
"
|
|
95 |
|v b1 b2|
|
|
96 |
|
6886
|
97 |
'Smalltalk at:#D2 put:(self new initializeFor:nil)'.
|
|
98 |
Smalltalk at:#D2 put:(self new initializeFor:'localhost:64001').
|
6561
|
99 |
|
|
100 |
D2 startDispatch.
|
|
101 |
|
|
102 |
v := View onDevice:D2.
|
|
103 |
v extent:200@200.
|
|
104 |
b1 := Button label:'Press Me' in:v. b1 extent:100@50.
|
|
105 |
b2 := Button label:'Me Too' in:v. b2 extent:100@50.
|
|
106 |
b2 top:60.
|
6886
|
107 |
b1 action:[ Transcript showCR:'b1 pressed'. self halt. b1 extent:150@40].
|
6561
|
108 |
b2 action:[ Transcript showCR:'b2 pressed'].
|
|
109 |
v open.
|
|
110 |
"
|
|
111 |
!
|
|
112 |
|
|
113 |
example1b
|
|
114 |
"
|
|
115 |
|v b1 b2|
|
|
116 |
|
|
117 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
6886
|
118 |
Smalltalk at:#D2 put:(self new initializeFor:'localhost:64001').
|
6561
|
119 |
|
|
120 |
D2 startDispatch.
|
|
121 |
|
|
122 |
v := View onDevice:D2.
|
|
123 |
v extent:200@200.
|
|
124 |
|
|
125 |
v open.
|
|
126 |
Delay waitForSeconds:2.
|
|
127 |
v displayString:'hello' x:10 y:20.
|
|
128 |
"
|
|
129 |
!
|
|
130 |
|
|
131 |
example2
|
|
132 |
"
|
|
133 |
|v v1 v2 v3|
|
|
134 |
|
|
135 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
136 |
|
|
137 |
D2 startDispatch.
|
|
138 |
|
|
139 |
v := View onDevice:D2.
|
|
140 |
v extent:200@220.
|
|
141 |
v1 := View in:v.
|
|
142 |
v1 origin:5@5 corner:95@95.
|
|
143 |
v1 viewBackground:Color red.
|
|
144 |
|
|
145 |
v2 := View in:v.
|
|
146 |
v2 origin:100@5 corner:195@95.
|
|
147 |
v2 viewBackground:Color green.
|
|
148 |
|
|
149 |
v3 := View in:v.
|
|
150 |
v3 origin:5@100 corner:95@195.
|
|
151 |
v3 viewBackground:Color blue.
|
|
152 |
v open
|
|
153 |
"
|
|
154 |
!
|
|
155 |
|
|
156 |
example3
|
|
157 |
"
|
|
158 |
|v v1 |
|
|
159 |
|
|
160 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
161 |
|
|
162 |
D2 startDispatch.
|
|
163 |
|
|
164 |
v := View onDevice:D2.
|
|
165 |
v extent:200@220.
|
|
166 |
|
|
167 |
v1 := ScrollBar in:v.
|
|
168 |
v1 origin:5@5 corner:25@1.0.
|
|
169 |
v1 viewBackground:Color red.
|
|
170 |
|
|
171 |
v open
|
|
172 |
"
|
|
173 |
!
|
|
174 |
|
|
175 |
example3b
|
|
176 |
"
|
|
177 |
|v v1 v2|
|
|
178 |
|
|
179 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
180 |
|
|
181 |
D2 startDispatch.
|
|
182 |
|
|
183 |
v := View onDevice:D2.
|
|
184 |
v extent:200@220.
|
|
185 |
|
|
186 |
v1 := ScrollBar in:v.
|
|
187 |
v1 origin:5@5 corner:25@1.0.
|
|
188 |
|
|
189 |
v2 := HorizontalScrollBar in:v.
|
|
190 |
v2 origin:25@5 corner:1.0@25.
|
|
191 |
|
|
192 |
v open
|
|
193 |
"
|
|
194 |
!
|
|
195 |
|
|
196 |
example4
|
|
197 |
"
|
|
198 |
|v v1 r1 r2 if c1 grp chk tm|
|
|
199 |
|
|
200 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
201 |
|
|
202 |
D2 startDispatch.
|
|
203 |
|
|
204 |
v := View onDevice:D2.
|
|
205 |
v extent:200@220.
|
|
206 |
|
|
207 |
v1 := Label label:'label' in:v.
|
|
208 |
v1 origin:5@5 corner:125@25.
|
|
209 |
|
|
210 |
grp := RadioButtonGroup new.
|
|
211 |
r1 := RadioButton label:'radio 1' in:v.
|
|
212 |
r1 origin:5@25 corner:1.0@50.
|
|
213 |
grp add:r1 value:1.
|
|
214 |
|
|
215 |
r2 := RadioButton label:'radio 2' in:v.
|
|
216 |
r2 origin:5@50 corner:1.0@75.
|
|
217 |
grp add:r2 value:2.
|
|
218 |
grp onChangeEvaluate:[ Transcript showCR:'changed'].
|
|
219 |
|
|
220 |
r2 := RadioButton label:'radio 2' in:v.
|
|
221 |
r2 origin:5@50 corner:1.0@75.
|
|
222 |
grp add:r2 value:2.
|
|
223 |
grp onChangeEvaluate:[ Transcript showCR:'changed'].
|
|
224 |
|
|
225 |
chk := false asValue.
|
|
226 |
c1 := CheckBox label:'check' in:v.
|
|
227 |
c1 origin:5@75 corner:1.0@100.
|
|
228 |
c1 model:chk.
|
|
229 |
chk onChangeEvaluate:[ Transcript showCR:'changed'].
|
|
230 |
|
|
231 |
tm := 'hello' asValue.
|
|
232 |
if := EditField in:v.
|
|
233 |
if viewBackground:(Color yellow lightened).
|
|
234 |
if origin:5@100 corner:1.0@125.
|
|
235 |
if model:tm.
|
|
236 |
' if passwordCharacter:$* '.
|
|
237 |
tm onChangeEvaluate:[ Transcript showCR:'changed'].
|
|
238 |
|
|
239 |
v open
|
|
240 |
"
|
|
241 |
!
|
|
242 |
|
|
243 |
example5
|
|
244 |
"
|
|
245 |
|v v1 r1 r2 v3 c1 grp chk|
|
|
246 |
|
|
247 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
248 |
|
|
249 |
D2 startDispatch.
|
|
250 |
|
|
251 |
v := View onDevice:D2.
|
|
252 |
v extent:200@220.
|
|
253 |
|
|
254 |
v1 := TextView in:v.
|
|
255 |
v1 viewBackground:Color red.
|
|
256 |
v1 origin:5@5 corner:1.0@1.0.
|
|
257 |
v1 contents:'line1
|
|
258 |
line2
|
|
259 |
line3'.
|
|
260 |
v1 textChanged.
|
|
261 |
v open
|
|
262 |
"
|
|
263 |
!
|
|
264 |
|
|
265 |
example5b
|
|
266 |
"
|
|
267 |
|v v1 v2 v3|
|
|
268 |
|
|
269 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
270 |
|
|
271 |
D2 startDispatch.
|
|
272 |
|
|
273 |
v := View onDevice:D2.
|
|
274 |
v extent:200@220.
|
|
275 |
v viewBackground:Color yellow.
|
|
276 |
|
|
277 |
v1 := View in:v.
|
|
278 |
v1 extent:180@180.
|
|
279 |
v1 viewBackground:Color green.
|
|
280 |
|
|
281 |
v2 := SelectionInListView in:v1.
|
|
282 |
v2 viewBackground:Color red.
|
|
283 |
v2 origin:5@5 corner:100@100.
|
|
284 |
v2 list:#('line1' 'line2' 'line3').
|
|
285 |
v open.
|
|
286 |
|
|
287 |
Delay waitForSeconds:2.
|
|
288 |
D2 send:'set-visible ',v2 id,' true'.
|
|
289 |
D2 send:'set-bounds ',v2 id,' 10 10 50 50'.
|
|
290 |
"
|
|
291 |
! !
|
|
292 |
|
|
293 |
!GuiServerWorkstation class methodsFor:'class initialization'!
|
|
294 |
|
|
295 |
initialize
|
|
296 |
KeyPressMask := 16r01.
|
|
297 |
KeyReleaseMask := 16r02.
|
|
298 |
ButtonPressMask := 16r04.
|
|
299 |
ButtonReleaseMask := 16r08.
|
|
300 |
ButtonMotionMask := 16r10.
|
|
301 |
PointerMotionMask := 16r20.
|
|
302 |
ExposureMask := 16r40.
|
|
303 |
FocusChangeMask := 16r80.
|
|
304 |
EnterWindowMask := 16r100.
|
|
305 |
LeaveWindowMask := 16r200.
|
|
306 |
KeymapStateMask := 16r400.
|
|
307 |
VisibilityChangeMask := 16r800.
|
|
308 |
StructureNotifyMask := 16r1000.
|
|
309 |
ResizeRedirectMask := 16r2000.
|
|
310 |
PropertyChangeMask := 16r4000.
|
|
311 |
ColormapChangeMask := 16r8000.
|
|
312 |
SubstructureNotifyMask := 16r10000.
|
|
313 |
SubstructureRedirectMask := 16r20000.
|
|
314 |
! !
|
|
315 |
|
|
316 |
!GuiServerWorkstation class methodsFor:'defaults'!
|
|
317 |
|
|
318 |
defaultGUIServerPath
|
6886
|
319 |
^ nil.
|
6561
|
320 |
^ Smalltalk projectDirectory constructString:'../support/guiServer/guiserver.jar'
|
|
321 |
"/ ^ '/Users/cg/Downloads/languages/lisp/newLisp/newlisp-10.6.0/guiserver/guiserver.jar'.
|
|
322 |
"/ ^ self projectDirectory constructString:'guiserver.jar'
|
|
323 |
!
|
|
324 |
|
|
325 |
defaultGUIServerPort
|
6886
|
326 |
^ 64001
|
|
327 |
"/ ^ 47011
|
6561
|
328 |
! !
|
|
329 |
|
|
330 |
!GuiServerWorkstation methodsFor:'bitmap/window creation'!
|
|
331 |
|
|
332 |
createBitmapFromArray:data width:w height:h
|
|
333 |
"create a monochrome, depth1 bitmap from a given (byte-)array.
|
|
334 |
The rows are aligned to a multiple of 8"
|
|
335 |
|
|
336 |
"/ for now, just return a dummy id...
|
|
337 |
^ 4711
|
|
338 |
|
|
339 |
"/ todo: save as png and use that path in the future...
|
|
340 |
"/ self halt.
|
|
341 |
!
|
|
342 |
|
|
343 |
createWindowFor:aView type:typeSymbol origin:org extent:ext
|
|
344 |
minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv
|
|
345 |
style:styleSymbol inputOnly:inp
|
|
346 |
label:label owner:owner
|
|
347 |
icon:icn iconMask:icnM iconView:icnV
|
|
348 |
|
|
349 |
|nr id nativeWindowType x y w h containerId|
|
|
350 |
|
|
351 |
nr := nextId.
|
|
352 |
nextId := nextId + 1.
|
|
353 |
|
|
354 |
useNativeWidgets ifTrue:[
|
|
355 |
nativeWindowType := aView nativeWindowType.
|
|
356 |
].
|
|
357 |
|
|
358 |
x := org x.
|
|
359 |
y := org y.
|
|
360 |
w := ext x.
|
|
361 |
h := ext y.
|
|
362 |
|
|
363 |
id := '%1_%2' bindWith:aView class nameWithoutPrefix with:nr.
|
|
364 |
|
|
365 |
sv isNil ifTrue:[
|
|
366 |
self gs_frame:id x:org x y:org y width:w height:h label:'x' visible:false.
|
|
367 |
"/ self send:('canvas ','canvas_',id).
|
|
368 |
useExtraCanvas ifTrue:[
|
|
369 |
self send:('canvas ','canvas_',id).
|
|
370 |
self send:('add-to ',id,' canvas_',id).
|
|
371 |
self send:('set-visible ','canvas_',id,' true').
|
|
372 |
self send:('set-null-layout ','canvas_',id).
|
|
373 |
] ifFalse:[
|
|
374 |
self send:('set-null-layout ',id).
|
|
375 |
].
|
|
376 |
] ifFalse:[
|
|
377 |
containerId := sv id.
|
|
378 |
useExtraCanvas ifTrue:[
|
|
379 |
sv superView isNil ifTrue:[
|
|
380 |
containerId := 'canvas_',containerId
|
|
381 |
].
|
|
382 |
].
|
|
383 |
nativeWindowType notNil ifTrue:[
|
|
384 |
nativeWindowType == #Button ifTrue:[
|
|
385 |
self send:('button ',id,' button-action ',(Base64Coder encode:aView label),' ',x printString,' ',y printString)
|
|
386 |
"/ (gs:set-flow-layout 'ButtonDemo "center" 2 15)
|
|
387 |
"/ (gs:add-to 'ButtonDemo 'ColorPanel 'aButton)
|
|
388 |
] ifFalse:[ nativeWindowType == #VerticalScrollBar ifTrue:[
|
|
389 |
"/ action orientation minPos maxPos pos pageIncrement
|
|
390 |
self send:('scrollbar ',id,' scrollbar-action vertical 0 100 0 10')
|
|
391 |
] ifFalse:[ nativeWindowType == #HorizontalScrollBar ifTrue:[
|
|
392 |
"/ action orientation minPos maxPos pos pageIncrement
|
|
393 |
self send:('scrollbar ',id,' scrollbar-action horizontal 0 100 0 10')
|
|
394 |
] ifFalse:[ nativeWindowType == #Label ifTrue:[
|
|
395 |
"/ "left", "center", "right", "leading", "trailing", "bottom" and "top"
|
|
396 |
self send:('label ',id,' ',(Base64Coder encode:aView label),' center ',w printString,' ',h printString).
|
|
397 |
] ifFalse:[ nativeWindowType == #RadioButton ifTrue:[
|
|
398 |
self send:('radio-button ',id,' radio-button-action ',(Base64Coder encode:aView label),' ',(aView isOn printString)).
|
|
399 |
] ifFalse:[ nativeWindowType == #CheckBox ifTrue:[
|
|
400 |
self send:('check-box ',id,' check-box-action ',(Base64Coder encode:aView label),' ',(aView isOn printString)).
|
|
401 |
] ifFalse:[ nativeWindowType == #EditField ifTrue:[
|
|
402 |
aView passwordCharacter notNil ifTrue:[
|
|
403 |
self send:('text-field ',id,' text-field-action ',(aView maxChars ? 9999) printString,' ',(Base64Coder encode:aView passwordCharacter asString)).
|
|
404 |
] ifFalse:[
|
|
405 |
self send:('text-field ',id,' text-field-action ',(aView maxChars ? 9999) printString).
|
|
406 |
].
|
|
407 |
self changeText:(aView contents asString) in:id.
|
|
408 |
] ifFalse:[ nativeWindowType == #TextView ifTrue:[
|
|
409 |
self send:('text-area ',id,' text-area-action ',w printString,' ',h printString).
|
|
410 |
self changeText:(aView contents) in:id.
|
|
411 |
] ifFalse:[ nativeWindowType == #SelectionInListView ifTrue:[
|
|
412 |
self send:('list-box ',id,' list-box-action ',((aView list collect:[:l | (Base64Coder encode:l?'')]) asStringCollection asStringWith:' ')).
|
|
413 |
"/ self changeList:aView list in:id.
|
|
414 |
] ifFalse:[
|
|
415 |
self halt.
|
|
416 |
self send:('canvas ',id)
|
|
417 |
]]]]]]]]].
|
|
418 |
] ifFalse:[
|
|
419 |
self send:('canvas ',id)
|
|
420 |
].
|
|
421 |
self send:('add-to ',containerId,' ',id).
|
|
422 |
self send:('set-visible ',id,' true').
|
|
423 |
self send:('set-null-layout ',id).
|
|
424 |
self send:('set-bounds ',id,' %1 %2 %3 %4' bindWith:x with:y with:w with:h).
|
|
425 |
].
|
|
426 |
viewMap at:id put:aView.
|
|
427 |
^ id
|
|
428 |
!
|
|
429 |
|
|
430 |
destroyGC:gcId
|
|
431 |
!
|
|
432 |
|
|
433 |
destroyPixmap:pixmapId
|
|
434 |
!
|
|
435 |
|
|
436 |
destroyView:aView withId:id
|
|
437 |
|container|
|
|
438 |
|
|
439 |
container := aView superView.
|
|
440 |
|
|
441 |
viewMap removeKey:id ifAbsent:[].
|
|
442 |
container isNil ifTrue:[
|
|
443 |
self send:('dispose ',id)
|
|
444 |
] ifFalse:[
|
|
445 |
(useExtraCanvas and:[container superView isNil]) ifTrue:[
|
|
446 |
self send:('remove-from canvas_',container id,' ',id)
|
|
447 |
] ifFalse:[
|
|
448 |
self send:('remove-from ',container id,' ',id)
|
|
449 |
].
|
|
450 |
].
|
|
451 |
!
|
|
452 |
|
6886
|
453 |
gcFor:aDrawableId
|
|
454 |
"create a GC for drawing into aDrawable"
|
|
455 |
|
|
456 |
^ aDrawableId
|
|
457 |
!
|
|
458 |
|
6561
|
459 |
supportsNativeWidgetType:aWidgetTypeSymbol
|
|
460 |
useNativeWidgets ifFalse:[^ false].
|
|
461 |
|
|
462 |
aWidgetTypeSymbol == #Button ifTrue:[^ true].
|
|
463 |
aWidgetTypeSymbol == #Scrollbar ifTrue:[^ true].
|
|
464 |
aWidgetTypeSymbol == #Label ifTrue:[^ true].
|
|
465 |
aWidgetTypeSymbol == #Toggle ifTrue:[^ true].
|
|
466 |
aWidgetTypeSymbol == #ScrolledView ifTrue:[^ true].
|
|
467 |
aWidgetTypeSymbol == #CheckBox ifTrue:[^ true].
|
|
468 |
aWidgetTypeSymbol == #RadioButton ifTrue:[^ true].
|
|
469 |
aWidgetTypeSymbol == #ComboBox ifTrue:[^ true].
|
|
470 |
aWidgetTypeSymbol == #Slider ifTrue:[^ true].
|
|
471 |
aWidgetTypeSymbol == #ProgressBar ifTrue:[^ true].
|
|
472 |
aWidgetTypeSymbol == #ListBox ifTrue:[^ true].
|
|
473 |
aWidgetTypeSymbol == #EditField ifTrue:[^ true].
|
|
474 |
aWidgetTypeSymbol == #TextView ifTrue:[^ true].
|
|
475 |
aWidgetTypeSymbol == #Menu ifTrue:[^ true].
|
|
476 |
aWidgetTypeSymbol == #MenuBar ifTrue:[^ true].
|
|
477 |
aWidgetTypeSymbol == #Table ifTrue:[^ true].
|
|
478 |
|
|
479 |
^ false
|
|
480 |
! !
|
|
481 |
|
|
482 |
!GuiServerWorkstation methodsFor:'cursor stuff'!
|
|
483 |
|
|
484 |
builtInCursorShapes
|
|
485 |
"return a collection of standard cursor names.
|
|
486 |
Those are built into the XServer and need not be created as
|
|
487 |
user cursors.
|
|
488 |
(actually, there are more than those below ...)"
|
|
489 |
|
|
490 |
"/ if you add something here, also add to #shapeNumberFromCursor ...
|
|
491 |
|
|
492 |
^ #(
|
|
493 |
#upLeftArrow "/ default
|
|
494 |
#upRightHand "/ hand
|
|
495 |
#text "/ text
|
|
496 |
#wait "/ wait
|
|
497 |
#crossHair "/ crosshair
|
|
498 |
#origin "/ nw-resize
|
|
499 |
#topLeft "/ nw-resize
|
|
500 |
#corner "/ se-resize
|
|
501 |
#bottomRight "/ se-resize
|
|
502 |
#topRight "/ ne-resize
|
|
503 |
#bottomLeft "/ sw-resize
|
|
504 |
)
|
|
505 |
!
|
|
506 |
|
|
507 |
createCursorShape:aShapeSymbol
|
|
508 |
|cursors i|
|
|
509 |
|
|
510 |
cursors := #(
|
|
511 |
(#upLeftArrow #default )
|
|
512 |
(#upRightHand #hand )
|
|
513 |
(#text #text )
|
|
514 |
(#wait #wait )
|
|
515 |
(#crossHair #crosshair )
|
|
516 |
(#origin #nw-resize )
|
|
517 |
(#topLeft #nw-resize )
|
|
518 |
(#corner #se-resize )
|
|
519 |
(#bottomRight #se-resize )
|
|
520 |
(#topRight #ne-resize )
|
|
521 |
(#bottomLeft #sw-resize )
|
|
522 |
).
|
|
523 |
i := cursors findFirst:[:entry | entry first == aShapeSymbol].
|
|
524 |
i == 0 ifTrue:[^ nil].
|
|
525 |
^ (cursors at:i) second
|
|
526 |
!
|
|
527 |
|
|
528 |
destroyCursor:aCursorId
|
|
529 |
!
|
|
530 |
|
|
531 |
setCursor:aCursorId in:aWindowId
|
|
532 |
"/ ;; @syntax (gs:set-cursor <sym-id> <str-shape>)
|
|
533 |
"/ ;; @param <sym-id> The name of the frame, dialog or window.
|
|
534 |
"/ ;; @param <str-shape> The string describing the cursor shape.
|
|
535 |
"/ ;;
|
|
536 |
"/ ;; The cursor shape can be one of the following:
|
|
537 |
"/ ;; <pre>
|
|
538 |
"/ ;; "default"
|
|
539 |
"/ ;; "crosshair"
|
|
540 |
"/ ;; "text"
|
|
541 |
"/ ;; "wait"
|
|
542 |
"/ ;; "sw-resize"
|
|
543 |
"/ ;; "se-resize"
|
|
544 |
"/ ;; "nw-resize"
|
|
545 |
"/ ;; "ne-resize"
|
|
546 |
"/ ;; "n-resize"
|
|
547 |
"/ ;; "s-resize"
|
|
548 |
"/ ;; "w-resize"
|
|
549 |
"/ ;; "e-resize"
|
|
550 |
"/ ;; "hand"
|
|
551 |
"/ ;; "move"
|
|
552 |
|
|
553 |
self gs_set_cursor:aWindowId cursor:aCursorId
|
|
554 |
! !
|
|
555 |
|
|
556 |
!GuiServerWorkstation methodsFor:'event handling'!
|
|
557 |
|
|
558 |
addToKnownScreens
|
|
559 |
!
|
|
560 |
|
|
561 |
base64StringFromLineStream:s
|
|
562 |
|str|
|
|
563 |
|
|
564 |
str := s upToAny:')( '.
|
|
565 |
(str first = $") ifTrue:[
|
|
566 |
str := str withoutQuotes.
|
|
567 |
].
|
|
568 |
^ (Base64Coder decodeAsString:str)
|
|
569 |
!
|
|
570 |
|
|
571 |
defaultEventMask
|
|
572 |
^ ExposureMask | StructureNotifyMask |
|
|
573 |
KeyPressMask | KeyReleaseMask |
|
|
574 |
PointerMotionMask |
|
|
575 |
EnterWindowMask | LeaveWindowMask |
|
|
576 |
ButtonPressMask | ButtonMotionMask | ButtonReleaseMask |
|
|
577 |
PropertyChangeMask
|
|
578 |
!
|
|
579 |
|
|
580 |
dispatchEventFor:aViewIdOrNil withMask:eventMask
|
|
581 |
"central event handling method:
|
|
582 |
get next event and send appropriate message to the sensor or view.
|
|
583 |
If the argument aViewIdOrNil is nil, events for any view are processed,
|
|
584 |
otherwise only events for the view with given id are processed.
|
|
585 |
If the argument aMask is nonNil, only events for this eventMask are
|
|
586 |
handled.
|
|
587 |
WARNING: this may block to wait for an event - you better check for a
|
|
588 |
pending event before calling this."
|
|
589 |
|
|
590 |
|line|
|
|
591 |
|
|
592 |
EndOfStreamNotification handle:[:ex |
|
|
593 |
] do:[
|
|
594 |
line := in nextLine.
|
|
595 |
].
|
|
596 |
line isNil ifTrue:[
|
|
597 |
hasConnectionBroken := true.
|
|
598 |
self brokenConnection.
|
|
599 |
^ self.
|
|
600 |
].
|
|
601 |
self handleInput:line.
|
|
602 |
!
|
|
603 |
|
|
604 |
eventMaskFor:anEventSymbol
|
|
605 |
"return the eventMask bit-constant corresponding to an event symbol"
|
|
606 |
|
|
607 |
anEventSymbol == #keyPress ifTrue:[^ KeyPressMask].
|
|
608 |
anEventSymbol == #keyRelease ifTrue:[^ KeyReleaseMask].
|
|
609 |
anEventSymbol == #buttonPress ifTrue:[^ ButtonPressMask].
|
|
610 |
anEventSymbol == #buttonRelease ifTrue:[^ ButtonReleaseMask].
|
|
611 |
anEventSymbol == #buttonMotion ifTrue:[^ ButtonMotionMask].
|
|
612 |
anEventSymbol == #pointerMotion ifTrue:[^ PointerMotionMask].
|
|
613 |
anEventSymbol == #expose ifTrue:[^ ExposureMask].
|
|
614 |
anEventSymbol == #focusChange ifTrue:[^ FocusChangeMask].
|
|
615 |
anEventSymbol == #enter ifTrue:[^ EnterWindowMask].
|
|
616 |
anEventSymbol == #leave ifTrue:[^ LeaveWindowMask].
|
|
617 |
anEventSymbol == #keymapState ifTrue:[^ KeymapStateMask].
|
|
618 |
anEventSymbol == #visibilityChange ifTrue:[^ VisibilityChangeMask].
|
|
619 |
anEventSymbol == #structureNotify ifTrue:[^ StructureNotifyMask].
|
|
620 |
anEventSymbol == #resizeRedirect ifTrue:[^ ResizeRedirectMask].
|
|
621 |
anEventSymbol == #propertyChange ifTrue:[^ PropertyChangeMask].
|
|
622 |
anEventSymbol == #colormapChange ifTrue:[^ ColormapChangeMask].
|
|
623 |
anEventSymbol == #substructureNotify ifTrue:[^ SubstructureNotifyMask].
|
|
624 |
anEventSymbol == #substructureRedirect ifTrue:[^ SubstructureRedirectMask].
|
|
625 |
^ 0
|
|
626 |
!
|
|
627 |
|
|
628 |
eventPending
|
|
629 |
^ in notNil
|
|
630 |
and:[ in isOpen
|
|
631 |
and:[ in canReadWithoutBlocking ]]
|
|
632 |
|
|
633 |
"
|
|
634 |
self new initializeFor:nil
|
|
635 |
"
|
|
636 |
!
|
|
637 |
|
|
638 |
handleInput:line
|
|
639 |
"handle an incoming event from the guiServer"
|
|
640 |
|
|
641 |
|s cmd var view text|
|
|
642 |
|
|
643 |
"/ gui server sends lisp-like lines:
|
|
644 |
"/ (action id)
|
|
645 |
"/ ...
|
|
646 |
Transcript showCR:'<< ',line.
|
|
647 |
|
|
648 |
s := line readStream.
|
|
649 |
s next == $( ifFalse:[^ false ].
|
|
650 |
|
|
651 |
s skipSeparators.
|
|
652 |
cmd := s upToAny:'")( '.
|
|
653 |
s skipSeparators.
|
|
654 |
|
|
655 |
cmd = 'button-action' ifTrue:[
|
|
656 |
view := self viewFromLineStream:s.
|
|
657 |
Transcript showCR:view.
|
|
658 |
Transcript showCR:view isNativeWidget.
|
|
659 |
self buttonPress:1 x:1 y:1 view:view.
|
|
660 |
self buttonRelease:1 x:1 y:1 view:view.
|
|
661 |
^ true.
|
|
662 |
].
|
|
663 |
cmd = 'radio-button-action' ifTrue:[
|
|
664 |
view := self viewFromLineStream:s.
|
|
665 |
Transcript showCR:view.
|
|
666 |
Transcript showCR:view isNativeWidget.
|
|
667 |
self buttonPress:1 x:1 y:1 view:view.
|
|
668 |
self buttonRelease:1 x:1 y:1 view:view.
|
|
669 |
^ true.
|
|
670 |
].
|
|
671 |
cmd = 'check-box-action' ifTrue:[
|
|
672 |
view := self viewFromLineStream:s.
|
|
673 |
Transcript showCR:view.
|
|
674 |
Transcript showCR:view isNativeWidget.
|
|
675 |
self buttonPress:1 x:1 y:1 view:view.
|
|
676 |
self buttonRelease:1 x:1 y:1 view:view.
|
|
677 |
^ true.
|
|
678 |
].
|
|
679 |
cmd = 'scrollbar-action' ifTrue:[
|
|
680 |
view := self viewFromLineStream:s.
|
|
681 |
Transcript showCR:view.
|
|
682 |
Transcript showCR:view isNativeWidget.
|
|
683 |
^ true.
|
|
684 |
].
|
|
685 |
cmd = 'text-field-action' ifTrue:[
|
|
686 |
view := self viewFromLineStream:s.
|
|
687 |
text := self base64StringFromLineStream:s.
|
|
688 |
Transcript showCR:view.
|
|
689 |
Transcript showCR:view isNativeWidget.
|
|
690 |
Transcript showCR:text.
|
|
691 |
^ true.
|
|
692 |
].
|
|
693 |
|
|
694 |
cmd = 'set' ifTrue:[
|
|
695 |
var := s upToAny:')( '.
|
|
696 |
s skipSeparators.
|
|
697 |
var first == $' ifTrue:[ var := var copyFrom:2 ].
|
|
698 |
|
|
699 |
var = 'gs:screen' ifTrue:[
|
|
700 |
s peek == $' ifTrue:[ s next ].
|
|
701 |
s peek ~~ $( ifTrue:[ self halt].
|
|
702 |
s next.
|
|
703 |
width := (Number readFrom:s) asInteger.
|
|
704 |
s skipSeparators.
|
|
705 |
height := (Number readFrom:s) asInteger.
|
|
706 |
s skipSeparators.
|
|
707 |
resolutionHor := resolutionVer := (Number readFrom:s) asInteger "is dpi" / 25.4.
|
|
708 |
widthMM := width / resolutionHor.
|
|
709 |
heightMM := height / resolutionVer.
|
|
710 |
"/ self halt.
|
|
711 |
^ true.
|
|
712 |
].
|
|
713 |
].
|
|
714 |
|
|
715 |
self halt.
|
|
716 |
^ false.
|
|
717 |
|
|
718 |
"
|
|
719 |
self new initializeFor:nil
|
|
720 |
"
|
|
721 |
!
|
|
722 |
|
|
723 |
setEventMask:mask in:viewID
|
|
724 |
!
|
|
725 |
|
|
726 |
viewFromLineStream:s
|
|
727 |
|id|
|
|
728 |
|
|
729 |
id := s upToAny:')( '.
|
|
730 |
(id first = $") ifTrue:[
|
|
731 |
id := id withoutQuotes.
|
|
732 |
].
|
|
733 |
^ viewMap at:id ifAbsent:nil.
|
|
734 |
! !
|
|
735 |
|
|
736 |
!GuiServerWorkstation methodsFor:'font stuff'!
|
|
737 |
|
|
738 |
ascentOf:id
|
|
739 |
^ 16
|
|
740 |
!
|
|
741 |
|
|
742 |
descentOf:id
|
|
743 |
^ 8
|
|
744 |
!
|
|
745 |
|
|
746 |
getFontWithFamily:familyString face:faceString style:styleString size:sizeArg sizeUnit:sizeUnit encoding:encodingSym
|
6886
|
747 |
|spec id|
|
6561
|
748 |
|
6886
|
749 |
spec := { familyString . faceString . styleString . sizeArg }.
|
|
750 |
id := fontMap at:spec ifAbsent:nil.
|
|
751 |
id isNil ifTrue:[
|
|
752 |
id := (fontMap size // 2) + 1.
|
|
753 |
fontMap at:spec put:id.
|
|
754 |
fontMap at:id put:spec.
|
|
755 |
].
|
6561
|
756 |
^ id
|
|
757 |
!
|
|
758 |
|
|
759 |
maxAscentOf:id
|
|
760 |
^ 16
|
|
761 |
!
|
|
762 |
|
|
763 |
maxDescentOf:id
|
|
764 |
^ 8
|
|
765 |
!
|
|
766 |
|
|
767 |
maxWidthOfFont:id
|
|
768 |
^ 10
|
|
769 |
!
|
|
770 |
|
|
771 |
minWidthOfFont:id
|
|
772 |
^ 10
|
|
773 |
!
|
|
774 |
|
|
775 |
subclassResponsibility
|
|
776 |
MiniDebugger enter.
|
|
777 |
AbortSignal raise
|
|
778 |
!
|
|
779 |
|
|
780 |
widthOf:aString from:index1 to:index2 inFont:aFontId
|
|
781 |
^ (index2-index1+1) * 10
|
|
782 |
! !
|
|
783 |
|
6886
|
784 |
!GuiServerWorkstation methodsFor:'gc stuff'!
|
|
785 |
|
|
786 |
displayString:aString from:start to:stop x:x y:y in:aDrawable with:aGCId opaque:opaque
|
|
787 |
|cmd|
|
|
788 |
|
|
789 |
cmd := 'draw-text ',aGCId,' ',(Base64Coder encode:aString utf8Encoded).
|
|
790 |
self send:cmd.
|
|
791 |
!
|
|
792 |
|
|
793 |
setBackground:fg in:aGC
|
|
794 |
"nothing done - color sent with each draw request"
|
|
795 |
!
|
|
796 |
|
|
797 |
setBackgroundColor:clr in:aGC
|
|
798 |
"nothing done - color sent with each draw request"
|
|
799 |
!
|
|
800 |
|
|
801 |
setFont:aFontId in:aGCId
|
|
802 |
|cmd spec familyString faceString styleString size|
|
|
803 |
|
|
804 |
spec := fontMap at:aFontId ifAbsent:nil.
|
|
805 |
spec isNil ifTrue:[
|
|
806 |
self halt:'no such font'.
|
|
807 |
^ self.
|
|
808 |
].
|
|
809 |
familyString := spec first.
|
|
810 |
faceString := spec second.
|
|
811 |
styleString := spec third.
|
|
812 |
size := spec fourth.
|
|
813 |
|
|
814 |
cmd := 'set-font ',aGCId,' ',(Base64Coder encode:familyString utf8Encoded), ' ',size printString.
|
|
815 |
|
|
816 |
self send:cmd.
|
|
817 |
!
|
|
818 |
|
|
819 |
setForeground:fg background:bg in:aGC
|
|
820 |
"nothing done - color sent with each draw request"
|
|
821 |
!
|
|
822 |
|
|
823 |
setForeground:fg in:aGC
|
|
824 |
"nothing done - color sent with each draw request"
|
|
825 |
!
|
|
826 |
|
|
827 |
setForegroundColor:clr in:aGC
|
|
828 |
"nothing done - color sent with each draw request"
|
|
829 |
!
|
|
830 |
|
|
831 |
setFunction:aFunctionSymbol in:aGCId
|
|
832 |
|cmd|
|
|
833 |
|
|
834 |
cmd := 'set-function ',aGCId,' ',aFunctionSymbol printString.
|
|
835 |
self send:cmd.
|
|
836 |
!
|
|
837 |
|
|
838 |
setLineWidth:lw style:s cap:c join:j in:aGC
|
|
839 |
! !
|
|
840 |
|
6561
|
841 |
!GuiServerWorkstation methodsFor:'gs interaction'!
|
|
842 |
|
|
843 |
gs_frame:id x:x y:y width:w height:h label:label visible:visible
|
|
844 |
label isNil ifTrue:[
|
|
845 |
self send:('frame %1 %2 %3 %4'
|
|
846 |
bindWith:id with:x with:y with:w with:h)
|
|
847 |
] ifFalse:[
|
|
848 |
self send:('frame %1 %2 %3 %4 %5 %6'
|
|
849 |
bindWith:id with:x with:y with:w with:h
|
|
850 |
with:(Base64Coder encode:label) with:visible)
|
|
851 |
]
|
|
852 |
!
|
|
853 |
|
|
854 |
gs_set_background:id color:colorId
|
|
855 |
self gs_set_color:id color:colorId
|
|
856 |
!
|
|
857 |
|
|
858 |
gs_set_background:id r:redFraction g:greenFraction b:blueFraction alpha:alphaFraction
|
|
859 |
self gs_set_color:id r:redFraction g:greenFraction b:blueFraction alpha:alphaFraction
|
|
860 |
!
|
|
861 |
|
|
862 |
gs_set_color:id color:colorId
|
|
863 |
self gs_set_color:id
|
|
864 |
r:(((colorId rightShift:16) bitAnd:16rFF) / 255.0)
|
|
865 |
g:(((colorId rightShift:8) bitAnd:16rFF) / 255.0)
|
|
866 |
b:((colorId bitAnd:16rFF) / 255.0)
|
|
867 |
alpha:1
|
|
868 |
!
|
|
869 |
|
|
870 |
gs_set_color:id r:redFraction g:greenFraction b:blueFraction alpha:alphaFraction
|
|
871 |
self send:('set-color %1 %2 %3 %4 %5'
|
|
872 |
bindWith:id
|
|
873 |
with:redFraction
|
|
874 |
with:greenFraction
|
|
875 |
with:blueFraction
|
|
876 |
with:alphaFraction)
|
|
877 |
!
|
|
878 |
|
|
879 |
gs_set_cursor:id cursor:cursorId
|
|
880 |
self send:('set-cursor ',id,' ',cursorId)
|
|
881 |
!
|
|
882 |
|
|
883 |
gs_set_foreground:id r:redFraction g:greenFraction b:blueFraction alpha:alphaFraction
|
|
884 |
self send:('set-foreground %1 %2 %3 %4 %5'
|
|
885 |
bindWith:id
|
|
886 |
with:redFraction
|
|
887 |
with:greenFraction
|
|
888 |
with:blueFraction
|
|
889 |
with:alphaFraction)
|
|
890 |
!
|
|
891 |
|
|
892 |
gs_set_resizable:id resizable:aBoolean
|
|
893 |
self send:'set-resizable %1 %2' with:id with:aBoolean
|
|
894 |
!
|
|
895 |
|
|
896 |
gs_set_trace:aBoolean
|
|
897 |
self send:'set-trace System %1' with:aBoolean
|
|
898 |
!
|
|
899 |
|
|
900 |
gs_set_utf8:aBoolean
|
|
901 |
self send:'set-utf8 System %1' with:aBoolean
|
|
902 |
!
|
|
903 |
|
|
904 |
gs_set_visible:id visible:visible
|
|
905 |
self send:('set-visible ',id,' ',visible printString)
|
|
906 |
!
|
|
907 |
|
|
908 |
send:cmdString
|
|
909 |
out isNil ifTrue:[^ self].
|
|
910 |
out nextPutLine:cmdString
|
|
911 |
!
|
|
912 |
|
|
913 |
send:cmd with:arg
|
|
914 |
self send:(cmd bindWith:arg)
|
|
915 |
!
|
|
916 |
|
|
917 |
send:cmd with:arg1 with:arg2
|
|
918 |
self send:(cmd bindWith:arg1 with:arg2)
|
|
919 |
! !
|
|
920 |
|
|
921 |
!GuiServerWorkstation methodsFor:'initialization & release'!
|
|
922 |
|
|
923 |
closeConnection
|
|
924 |
|c p|
|
|
925 |
|
|
926 |
(c := in) notNil ifTrue:[
|
|
927 |
in := nil.
|
|
928 |
c close.
|
|
929 |
].
|
|
930 |
(c := out) notNil ifTrue:[
|
|
931 |
out := nil.
|
|
932 |
c close.
|
|
933 |
].
|
6886
|
934 |
((p := guiServerPid) notNil and:[p ~~ #alreadyRunning]) ifTrue:[
|
6561
|
935 |
guiServerPid := nil.
|
|
936 |
OperatingSystem terminateProcess:p
|
|
937 |
].
|
|
938 |
!
|
|
939 |
|
|
940 |
guiServerTerminated
|
|
941 |
"connection to GUIServer broken"
|
|
942 |
|
|
943 |
|c|
|
|
944 |
|
|
945 |
Transcript showCR:'guiServer terminated'.
|
|
946 |
|
|
947 |
(c := in) notNil ifTrue:[
|
|
948 |
in := nil.
|
|
949 |
c close.
|
|
950 |
].
|
|
951 |
(c := out) notNil ifTrue:[
|
|
952 |
out := nil.
|
|
953 |
c close.
|
|
954 |
].
|
|
955 |
self brokenConnection
|
|
956 |
!
|
|
957 |
|
|
958 |
initializeFor:aHostName
|
|
959 |
"initialize the receiver for a connection to a GUIServer;
|
|
960 |
the argument, aHostName may be nil (for a new server on the local machine)
|
|
961 |
or the name:port of an already running server"
|
|
962 |
|
|
963 |
in notNil ifTrue:[
|
|
964 |
"/ already connected - you bad guy try to trick me manually ?
|
|
965 |
^ self
|
|
966 |
].
|
|
967 |
|
|
968 |
self openConnectionTo:aHostName.
|
|
969 |
|
|
970 |
"/ useNativeWidgets := false.
|
|
971 |
useNativeWidgets := true.
|
|
972 |
useExtraCanvas := false.
|
|
973 |
"/ useExtraCanvas := true.
|
|
974 |
|
|
975 |
connectionTimeout := connectionTimeout ? DefaultConnectionTimeout.
|
|
976 |
connectionTimeoutForWindowCreation := connectionTimeoutForWindowCreation ? DefaultConnectionTimeoutForWindowCreation.
|
|
977 |
hasConnectionBroken := false.
|
|
978 |
|
|
979 |
dispatching := false.
|
|
980 |
dispatchingExpose := false.
|
|
981 |
isSlow := false.
|
|
982 |
shiftDown := false.
|
|
983 |
ctrlDown := false.
|
|
984 |
metaDown := false.
|
|
985 |
altDown := false.
|
|
986 |
motionEventCompression := true.
|
|
987 |
buttonsPressed := 0.
|
|
988 |
|
|
989 |
visualType := #TrueColor.
|
|
990 |
depth := 24.
|
|
991 |
redShift := 16. greenShift := 8. blueShift := 0.
|
|
992 |
listOfFonts := nil.
|
|
993 |
nextId := 1.
|
|
994 |
|
|
995 |
fontMap := Dictionary new.
|
|
996 |
viewMap := Dictionary new.
|
|
997 |
|
|
998 |
self initializeDeviceResourceTables.
|
|
999 |
self initializeScreenProperties.
|
|
1000 |
|
|
1001 |
self initializeDefaultValues.
|
|
1002 |
self initializeSpecialFlags.
|
|
1003 |
self initializeKeyboardMap.
|
|
1004 |
self initializeDeviceSignals.
|
|
1005 |
|
|
1006 |
self initializeViewStyle.
|
|
1007 |
!
|
|
1008 |
|
|
1009 |
initializeScreenProperties
|
|
1010 |
"setup screen specific properties."
|
|
1011 |
|
|
1012 |
super initializeScreenProperties.
|
|
1013 |
|
|
1014 |
out nextPutLine:'get-screen System'.
|
|
1015 |
self handleInput:(in nextLine).
|
|
1016 |
|
|
1017 |
width := 1280.
|
|
1018 |
height := 1024.
|
|
1019 |
!
|
|
1020 |
|
|
1021 |
initializeSpecialFlags
|
|
1022 |
^ self
|
|
1023 |
!
|
|
1024 |
|
|
1025 |
nativeWidgets:aBoolean
|
|
1026 |
"enable/disable native widgets on a display"
|
|
1027 |
|
|
1028 |
useNativeWidgets := aBoolean
|
|
1029 |
!
|
|
1030 |
|
|
1031 |
openConnectionTo:aHostNameOrNil
|
|
1032 |
"open a connection to aHostNameOrNil;
|
|
1033 |
if nil, a new GUIServer is started; otherwise, try to connect to that host."
|
|
1034 |
|
|
1035 |
|host port hostAndPort startGUIServer acceptSocket connectionFromGS connectionToGS|
|
|
1036 |
|
|
1037 |
startGUIServer := false.
|
|
1038 |
|
|
1039 |
aHostNameOrNil isNil ifTrue:[
|
|
1040 |
host := 'localhost'.
|
|
1041 |
port := self guiServerPort.
|
|
1042 |
startGUIServer := true.
|
|
1043 |
] ifFalse:[
|
|
1044 |
hostAndPort := aHostNameOrNil splitBy:$:.
|
|
1045 |
host := hostAndPort first.
|
|
1046 |
port := (hostAndPort at:2 ifAbsent:[self guiServerPort]) asNumber.
|
6886
|
1047 |
guiServerPid := #alreadyRunning.
|
6561
|
1048 |
].
|
|
1049 |
|
|
1050 |
displayName := (host , ':' , port printString).
|
|
1051 |
|
|
1052 |
startGUIServer ifTrue:[
|
|
1053 |
self startGUIServerWithPort:port
|
|
1054 |
].
|
|
1055 |
|
|
1056 |
acceptSocket := Socket newTCPserverAtPort:(port+1).
|
|
1057 |
acceptSocket listenFor:1.
|
|
1058 |
|
|
1059 |
"/ give GUI server a chance to come up
|
|
1060 |
[connectionFromGS isNil] whileTrue:[
|
|
1061 |
connectionFromGS := Socket newTCPclientToHost:host port:port.
|
|
1062 |
connectionFromGS isNil ifTrue:[
|
|
1063 |
Delay waitForSeconds:0.1
|
|
1064 |
].
|
|
1065 |
].
|
|
1066 |
|
|
1067 |
acceptSocket readWaitWithTimeoutMs:500.
|
|
1068 |
connectionToGS := acceptSocket accept.
|
|
1069 |
acceptSocket close.
|
|
1070 |
|
|
1071 |
out := connectionFromGS.
|
|
1072 |
in := connectionToGS.
|
|
1073 |
|
|
1074 |
"/ self startReaderProcess.
|
|
1075 |
|
|
1076 |
self gs_set_trace:true.
|
|
1077 |
self gs_set_utf8:true.
|
|
1078 |
|
|
1079 |
"
|
|
1080 |
Smalltalk at:#D2 put:(self new initializeFor:nil).
|
|
1081 |
Smalltalk at:#D2 put:(self new initializeFor:'localhost:47020')
|
|
1082 |
|
|
1083 |
WorkspaceApplication openOnDevice:D2
|
|
1084 |
|
|
1085 |
D2 startDispatch.
|
|
1086 |
SystemBrowser openOnDevice:d
|
|
1087 |
"
|
|
1088 |
!
|
|
1089 |
|
|
1090 |
startGUIServerWithPort:portNr
|
|
1091 |
"start the java GUIServer"
|
|
1092 |
|
|
1093 |
|cmd args javaHome guiServerPath|
|
|
1094 |
|
|
1095 |
guiServerPath := self guiServerPath.
|
6886
|
1096 |
guiServerPath isNil ifTrue:[
|
|
1097 |
"/ assume already runnning
|
|
1098 |
guiServerPid := #alreadyRunning.
|
|
1099 |
^ self.
|
|
1100 |
].
|
6561
|
1101 |
|
|
1102 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
1103 |
cmd := 'cmd/c'
|
|
1104 |
] ifFalse:[
|
|
1105 |
javaHome := OperatingSystem getEnvironment:'JAVA_HOME'.
|
|
1106 |
cmd := javaHome isNil
|
|
1107 |
ifTrue:'/usr/bin/java'
|
|
1108 |
ifFalse:[ javaHome asFilename constructString:'bin/java' ].
|
|
1109 |
].
|
|
1110 |
args := { 'java' . '-jar' . guiServerPath . portNr asString }.
|
|
1111 |
|
|
1112 |
Processor
|
|
1113 |
monitor:[
|
|
1114 |
guiServerPid := OperatingSystem
|
|
1115 |
exec:cmd
|
|
1116 |
withArguments:args
|
|
1117 |
fork:true
|
|
1118 |
]
|
|
1119 |
action:[:status |
|
|
1120 |
status stillAlive ifFalse:[
|
|
1121 |
OperatingSystem closePid:guiServerPid.
|
|
1122 |
guiServerPid := nil.
|
|
1123 |
self guiServerTerminated.
|
|
1124 |
].
|
|
1125 |
].
|
|
1126 |
|
|
1127 |
guiServerPid isNil ifTrue:[
|
|
1128 |
self error:'failed to launch guiserver.jar'
|
|
1129 |
].
|
|
1130 |
|
|
1131 |
"
|
|
1132 |
self new initializeFor:nil
|
|
1133 |
"
|
|
1134 |
! !
|
|
1135 |
|
|
1136 |
!GuiServerWorkstation methodsFor:'misc'!
|
|
1137 |
|
|
1138 |
halt
|
|
1139 |
Screen currentScreenQuerySignal answer:Display do:[
|
|
1140 |
super halt.
|
|
1141 |
].
|
|
1142 |
!
|
|
1143 |
|
|
1144 |
mapWindow:viewId
|
|
1145 |
self gs_set_visible:viewId visible:true
|
|
1146 |
!
|
|
1147 |
|
|
1148 |
setWindowBackground:colorId in:viewId
|
|
1149 |
self gs_set_background:viewId color:colorId.
|
|
1150 |
!
|
|
1151 |
|
|
1152 |
setWindowName:label in:viewId
|
|
1153 |
!
|
|
1154 |
|
|
1155 |
unmapWindow:viewId
|
|
1156 |
self gs_set_visible:viewId visible:false
|
|
1157 |
! !
|
|
1158 |
|
|
1159 |
!GuiServerWorkstation methodsFor:'native window stuff'!
|
|
1160 |
|
|
1161 |
changeButtonState:stateBoolean in:id
|
|
1162 |
out nextPutLine:('set-selected ',id,' ',stateBoolean printString).
|
|
1163 |
!
|
|
1164 |
|
|
1165 |
changeLabel:label in:id
|
|
1166 |
out nextPutLine:('set-text ',id,' ',(Base64Coder encode:label)).
|
|
1167 |
!
|
|
1168 |
|
|
1169 |
changeList:list in:id
|
|
1170 |
out nextPutLine:('clear-list ',id).
|
|
1171 |
list do:[:each |
|
|
1172 |
out nextPutLine:('add-list-item ',id,' ',(Base64Coder encode:each asString)).
|
|
1173 |
].
|
|
1174 |
!
|
|
1175 |
|
|
1176 |
changeText:text in:id
|
|
1177 |
out nextPutLine:('set-text ',id,' ',(Base64Coder encode:text asString)).
|
|
1178 |
! !
|
|
1179 |
|
|
1180 |
!GuiServerWorkstation methodsFor:'queries'!
|
|
1181 |
|
|
1182 |
displayFileDescriptor
|
|
1183 |
"return the file descriptor associated with the display
|
|
1184 |
if any. If there is no underlying filedescriptor, return nil.
|
|
1185 |
(used for event select/polling)"
|
|
1186 |
|
6886
|
1187 |
in isNil ifTrue:[^ nil].
|
6561
|
1188 |
^ in fileDescriptor
|
|
1189 |
!
|
|
1190 |
|
|
1191 |
displayName
|
|
1192 |
^ displayName
|
|
1193 |
!
|
|
1194 |
|
|
1195 |
guiServerPath
|
|
1196 |
^ self class defaultGUIServerPath
|
|
1197 |
!
|
|
1198 |
|
|
1199 |
guiServerPort
|
|
1200 |
^ self class defaultGUIServerPort
|
|
1201 |
!
|
|
1202 |
|
|
1203 |
isOpen
|
|
1204 |
"answer true, if device can be used"
|
|
1205 |
|
|
1206 |
^ hasConnectionBroken not
|
|
1207 |
and:[guiServerPid notNil
|
|
1208 |
and:[in notNil
|
|
1209 |
and:[out notNil
|
|
1210 |
and:[in isOpen
|
|
1211 |
and:[out isOpen]]]]].
|
|
1212 |
!
|
|
1213 |
|
|
1214 |
mayOpenDebugger
|
|
1215 |
^ false
|
|
1216 |
!
|
|
1217 |
|
|
1218 |
supportsNativeWidgets
|
|
1219 |
^ useNativeWidgets
|
|
1220 |
! !
|
|
1221 |
|
|
1222 |
!GuiServerWorkstation methodsFor:'window stuff'!
|
|
1223 |
|
|
1224 |
moveResizeWindow:aWindowId x:x y:y width:w height:h
|
|
1225 |
self send:('set-bounds %1 %2 %3 %4 %5' bindWith:aWindowId with:x with:y with:w with:h)
|
|
1226 |
!
|
|
1227 |
|
|
1228 |
moveWindow:aWindowId x:x y:y
|
|
1229 |
self send:('set-location %1 %2 %3 %4 %5' bindWith:aWindowId with:x with:y)
|
|
1230 |
!
|
|
1231 |
|
|
1232 |
resizeWindow:aWindowId width:w height:h
|
|
1233 |
self send:('set-current-size %1 %2 %3' bindWith:aWindowId with:w with:h)
|
|
1234 |
! !
|
|
1235 |
|
|
1236 |
!GuiServerWorkstation class methodsFor:'documentation'!
|
|
1237 |
|
|
1238 |
version
|
6886
|
1239 |
^ '$Header$'
|
6561
|
1240 |
!
|
|
1241 |
|
|
1242 |
version_CVS
|
6886
|
1243 |
^ '$Header$'
|
6561
|
1244 |
! !
|
|
1245 |
|
|
1246 |
|
|
1247 |
GuiServerWorkstation initialize!
|