-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrebgui-view-patch.r
305 lines (276 loc) · 6.99 KB
/
rebgui-view-patch.r
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
REBOL [
Title: "RebGUI View Patches"
Owner: "Ashley G. Trüter"
Version: 0.4.1
Date: 26-Mar-2006
Purpose: "Patches to View functions to cooperate better with RebGUI."
History: {
0.1.0 Initial patch on INFORM and VIEW
}
]
view: func [
"Displays a window face."
view-face [object!]
/new "Creates a new window and returns immediately"
/offset xy [pair!] "Offset of window on screen"
/options opts [block! word!] "Window options [no-title no-border resize]"
/title text [string!] "Window bar title"
/local scr-face
] bind [
enable-show/force ; the window face must be displayed
scr-face: system/view/screen-face ; reduces path overhead
if find scr-face/pane view-face [return view-face] ; should bring to top !!!
either any [new empty? scr-face/pane][
view-face/text: any [
view-face/text
all [system/script/header system/script/title]
copy ""
]
new: all [not new empty? scr-face/pane]
append scr-face/pane view-face
][change scr-face/pane view-face]
; Use window-feel, not default feel, unless the user
; has set their own feel (keep user's feel)
if all [
system/view/vid
view-face/feel = system/view/vid/vid-face/feel
][
view-face/feel: window-feel
]
if offset [view-face/offset: xy]
if options [view-face/options: opts]
if title [view-face/text: text]
show scr-face
; show view-face
if new [do-events]
view-face
] system/view
show-popup: func [face [object!] /window window-face [object!] /away /local no-btn feelname] bind [
enable-show/force none ; the popup must be displayed
if find pop-list face [exit]
window: either window [feelname: copy "popface-feel-win" window-face][
feelname: copy "popface-feel"
if none? face/options [face/options: copy []]
if not find face/options 'parent [
repend face/options ['parent none]
]
system/view/screen-face
]
; do not overwrite if user has provided custom feel
if any [face/feel = system/words/face/feel face/feel = window-feel] [
no-btn: false
if block? get in face 'pane [
no-btn: foreach item face/pane [if get in item 'action [break/return false] true]
]
if away [append feelname "-away"]
if no-btn [append feelname "-nobtn"]
face/feel: get bind to word! feelname 'popface-feel
]
insert tail pop-list pop-face: face
append window/pane face
show window
] system/view
hide-popup: func [/timeout /only pop-face [object!] /local win-face blocks? f] bind [
pop-face: any [pop-face system/view/pop-face]
enable-show/force none
if not f: find pop-list pop-face [exit]
win-face: any [pop-face/parent-face system/view/screen-face]
remove find win-face/pane pop-face
remove f pop-face
blocks?: either in pop-face 'blocking? [
pop-face/blocking?
][
true
]
if timeout [pop-face: pick pop-list length? pop-list]
show win-face
unless blocks? [do-events]
] system/view
unview: func [
"Closes window views, except main view."
/all "Close all views, including main view"
/only face [object!] "Close a single view"
/local pane
] bind [
enable-show/force none ; the window view must be closed
pane: head system/view/screen-face/pane
either only [remove find pane face][
either all [clear pane][remove back tail pane]
]
show system/view/screen-face
] system/view
if system/version/4 = 3 [ ;Windows only
context [
user32-dll: load/library %user32.dll
GCLP_HCURSOR: -12
class-cursor: none
result: none
system-cursors: context [
app-start: 32650
hand: 32649
help: 32651
hourglass: 32650
arrow: 32512
cross: 32515
i-shape: 32513
no: 32648
size-all: 32646
size-nesw: 32643
size-ns: 32645
size-nwse: 32642
size-we: 32644
up-arrow: 32516
wait: 32514
]
monitor-info: make struct! [
cbSize [int]
left [long]
top [long]
right [long]
bottom [long]
wleft [long]
wtop [long]
wright [long]
wbottom [long]
dwFlags [int]
] none
monitor-info/cbSize: length? third monitor-info
pmonitor-info: to-integer reverse third make struct! [pmi [binary!]] reduce [third monitor-info]
get-system-metrics: make routine! [
nIndex [int]
return: [integer!]
] user32-dll "GetSystemMetrics"
load-cursor: make routine! [
hInstance [int]
lpCursorName [int]
return: [integer!]
] user32-dll "LoadCursorA"
set-cursor: make routine! [
hCursor [int]
return: [integer!]
] user32-dll "SetCursor"
set-class-long: make routine! [
hWnd [int]
nIndex [int]
dwNewLong [int]
return: [integer!]
] user32-dll "SetClassLongA"
find-window-class: make routine! [
class [string!]
name [int]
return: [int]
] user32-dll "FindWindowA"
find-window-name: make routine! [
class [int]
name [string!]
return: [int]
] user32-dll "FindWindowA"
get-monitor-info: make routine! [
hMonitor [int]
lpmi [int]
] user32-dll "GetMonitorInfoA"
enum-display-monitors: make routine! [
hdc [int]
lprcClip [int]
lpfnEnum [callback [int int int int return: [int]]]
enumData [int]
return: [integer!]
] user32-dll "EnumDisplayMonitors"
monitor-enum-proc: func [
hMonitor [integer!]
hdcMonitor [integer!]
lprcMonitor [integer!]
dwData [integer!]
/local oft siz woft wsiz
][
get-monitor-info hMonitor pmonitor-info
append result switch dwData [
1 [ ;screen-origin
as-pair monitor-info/left monitor-info/top
]
2 [ ;screen-size
as-pair monitor-info/right - monitor-info/left monitor-info/bottom - monitor-info/top
]
3 [ ;work-origin
as-pair monitor-info/wleft monitor-info/wtop
]
4 [ ;work-size
as-pair monitor-info/wright - monitor-info/wleft monitor-info/wbottom - monitor-info/wtop
]
]
return 1
]
get-result: func [
id [integer!]
][
result: copy []
enum-display-monitors 0 0 :monitor-enum-proc id
;to be sure we are not async!
while [empty? result][wait .01]
result
]
set 'gui-metric func [
"Returns specific gui related metric setting."
keyword [word!] "Available keywords: MONITORS, VSCREEN-ORIGIN, VSCREEN-SIZE, SCREEN-ORIGIN, SCREEN-SIZE, WORK-ORIGIN, WORK-SIZE, BORDER-FIXED, BORDER-SIZE, TITLE-SIZE and WINDOW-MIN-SIZE."
/local x y vals
][
switch keyword [
monitors [
return get-system-metrics 80
]
screen-origin [
return get-result 1
]
screen-size [
return get-result 2
]
work-origin [
return get-result 3
]
work-size [
return get-result 4
]
]
unless vals: select [
border-fixed [7 8]
border-size [32 33]
vscreen-size [78 79]
vscreen-origin [76 77]
title-size [none 4]
window-min-size [28 29]
] keyword [
return none
]
set [x y] reduce vals
set [x y] reduce [
any [all [x get-system-metrics x] 0]
any [all [y get-system-metrics y] 0]
]
as-pair x y
]
set 'cursor func [
"Sets system mouse pointer shape."
shape [word! none!]
/local
cursor
][
;print [now/time/precise "cursor:" shape]
unless class-cursor [class-cursor: set-class-long find-window-class "REBOLWind" 0 GCLP_HCURSOR 0]
cursor: 0
switch type?/word shape [
word! [
cursor: load-cursor 0 any [
all [
in system-cursors shape
system-cursors/:shape
]
system-cursors/arrow
]
]
; image! []
]
set-cursor cursor
true
]
]
]