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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
-
|
|
|
!
-
|
!
-
|
!
-
|
|
|
!
|
#include "user32.as"
#include "kernel32.as"
#include "gdi32.as"
onexit goto *hsp_exit
exist dir_cur + "/hsptmp": if strsize = -1: end
sdim script, strsize + 1
bload dir_cur+"/hsptmp", script, strsize, 0
#define WS_CHILD $40000000
#define WS_VSCROLL $00200000
#define WS_HSCROLL $00100000
#define ES_AUTOVSCROLL $0040
#define ES_AUTOHSCROLL $0080
#define ES_MULTILINE $0004
#define ES_DISABLENOSCROLL $00002000
#define WM_USER $0400
#define WM_HSCROLL $0114
#define WM_VSCROLL $0115
#define WM_NOTIFY $004E
#define WM_COMMAND $0111
#define WM_TIMER $0113
#define EM_SETTABSTOPS $00CB
#define EM_GETRECT $00B2
#define EM_SETRECT $00B3
#define EM_GETFIRSTVISIBLELINE $00CE
#define EM_LINEINDEX $00BB
#define EM_GETLINECOUNT $00BA
#define EM_POSFROMCHAR (WM_USER + 38)
#define EM_SETBKGNDCOLOR (WM_USER + 67)
#define EM_GETCHARFORMAT (WM_USER + 58)
#define EM_SETCHARFORMAT (WM_USER + 68)
#define EM_GETEVENTMASK (WM_USER + 59)
#define EM_SETEVENTMASK (WM_USER + 69)
#define EN_CHANGE $0300
#define EN_HSCROLL $0601
#define EN_VSCROLL $0602
#define EN_MSGFILTER $0700
#define EN_REQUESTRESIZE $0701
#define EN_SELCHANGE $0702
#define ENM_CHANGE $00000001
#define ENM_SCROLL $00000004
#define ENM_SELCHANGE $00080000
#define ENM_SCROLLEVENTS $00000008
#define CFM_SIZE $80000000
#define CFM_COLOR $40000000
#define CFM_FACE $20000000
#define CFM_CHARSET $08000000
#define CFE_AUTOCOLOR $40000000
#define ANSI_CHARSET 0
#define FIXED_PITCH 1
#define SCF_ALL $0004
#define SIF_RANGE $0001
#define SIF_PAGE $0002
#define SIF_POS $0004
#define SIF_DISABLENOSCROLL $0008
#define SIF_TRACKPOS $0010
#define SIF_ALL (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
#define SB_HORZ 0
#define SB_VERT 1
#define SB_THUMBTRACK 5
#define SB_ENDSCROLL 8
#define LOGPIXELSY 90
dim CHARFORMAT, 15
dup cfmt_cbSize, CHARFORMAT.0
dup cfmt_dwMask, CHARFORMAT.1
dup cfmt_dwEffects, CHARFORMAT.2
dup cfmt_yHeight, CHARFORMAT.3
dup cfmt_yOffset, CHARFORMAT.4
dup cfmt_crTextColor, CHARFORMAT.5
dupptr cfmt_bCharSet, varptr( CHARFORMAT.6 )+0, 1
dupptr cfmt_bPitchAndFamily, varptr( CHARFORMAT.6 )+1, 1
dupptr cfmt_szFaceName, varptr( CHARFORMAT.6 )+2, 32, 2
dim TEXTMETRIC, 14
dup tmHeight, TEXTMETRIC.0
dup tmAscent, TEXTMETRIC.1
dup tmDescent, TEXTMETRIC.2
dup tmInternalLeading, TEXTMETRIC.3
dup tmExternalLeading, TEXTMETRIC.4
dup tmAveCharWidth, TEXTMETRIC.5
dup tmMaxCharWidth, TEXTMETRIC.6
dup tmWeight, TEXTMETRIC.7
dup tmOverhang, TEXTMETRIC.8
dup tmDigitizedAspectX, TEXTMETRIC.9
dup tmDigitizedAspectY, TEXTMETRIC.10
dupptr tmFirstChar, varptr( TEXTMETRIC.11 )+0, 1
dupptr tmLastChar, varptr( TEXTMETRIC.11 )+1, 1
dupptr tmDefaultChar, varptr( TEXTMETRIC.11 )+2, 1
dupptr tmBreakChar, varptr( TEXTMETRIC.11 )+3, 1
dupptr tmItalic, varptr( TEXTMETRIC.12 )+0, 1
dupptr tmUnderlined, varptr( TEXTMETRIC.12 )+1, 1
dupptr tmStruckOut, varptr( TEXTMETRIC.12 )+2, 1
dupptr tmPitchAndFamily, varptr( TEXTMETRIC.12 )+3, 1
dupptr tmCharSet, varptr( TEXTMETRIC.13 )+0, 1
dim HORZ_SCROLLINFO, 7
dup hscr_cbSize, HORZ_SCROLLINFO.0
dup hscr_fMask, HORZ_SCROLLINFO.1
dup hscr_nMin, HORZ_SCROLLINFO.2
dup hscr_nMax, HORZ_SCROLLINFO.3
dup hscr_nPage, HORZ_SCROLLINFO.4
dup hscr_nPos, HORZ_SCROLLINFO.5
dup hscr_nTrackPos, HORZ_SCROLLINFO.6
LoadLibrary "riched32.dll": hLib = stat
screen 0, 640, 480, 2
hMain = hwnd
dwStyle = $56000000|ES_MULTILINE|ES_DISABLENOSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|WS_HSCROLL|WS_VSCROLL
winobj "RICHEDIT", "", $0200, dwStyle, ginfo_winx, ginfo_winy, 0, 0
iRich = stat: hRich = objinfo( iRich, 2 )
RichFontHeight = 13
RichFontWidth = RichFontHeight / 2 + RichFontHeight \ 2
syscolor 1
sendmsg hRich, EM_SETBKGNDCOLOR, 0, ginfo_b<<16|ginfo_g<<8|ginfo_r
RichViewHorzOffset = 2
RichViewVertOffset = 2
GetDC hRich: hdcRich = stat
GetDeviceCaps hdcRich, LOGPIXELSY: logpx = stat
GetTextMetrics hdcRich, varptr( TEXTMETRIC )
RichExtLeading = tmExternalLeading
ReleaseDC hRich, hdcRich
RulerHorzHeight = 16
dim rc, 4: GetClientRect hRich, varptr( rc )
bgscr 2, rc.2, RulerHorzHeight, 2, 0, 0
hRulerHorz = hwnd
GetWindowLong hwnd, -16
SetWindowLong hwnd, -16, stat & $7FFFFFFF | WS_CHILD
syscolor 4: boxf
scaleL = 0
scaleM = RulerHorzHeight/2
scaleS = RulerHorzHeight - RulerHorzHeight/4
SetParent hRulerHorz, hRich
RulerVertDigit = 8
RulerVertToSeparatorOffset = 2
RulerVertWidth = RichFontWidth * RulerVertDigit + RulerVertToSeparatorOffset
bgscr 3, RulerVertWidth, rc.3 - RulerHorzHeight, 2, 0, RulerHorzHeight
hRulerVert = hwnd
GetWindowLong hwnd, -16
SetWindowLong hwnd, -16, stat & $7FFFFFFF | WS_CHILD
SetParent hRulerVert, hRich
GetTextMetrics hdc, varptr( TEXTMETRIC )
RulerVertExtLeading = tmExternalLeading
cfmt_cbSize = 4*15
sendmsg hRich, EM_GETCHARFORMAT, 0, varptr( CHARFORMAT )
cfmt_dwMask = CFM_SIZE | CFM_FACE | CFM_CHARSET | CFM_COLOR
cfmt_dwEffects = cfmt_dwEffects & ($FFFFFFFF ^ CFE_AUTOCOLOR )
cfmt_yHeight = RichFontHeight * 1440 / logpx
syscolor 9
cfmt_crTextColor = ginfo_b<<16|ginfo_g<<8|ginfo_r
cfmt_bCharSet = ANSI_CHARSET
cfmt_bPitchAndFamily = FIXED_PITCH
cfmt_szFaceName = "MS ゴシック"
sendmsg hRich, EM_SETCHARFORMAT, SCF_ALL, varptr( CHARFORMAT )
SetWindowText hRich, varptr( script )
RichTabStops = 2 * 4
sendmsg hRich, EM_SETTABSTOPS, 1, varptr( RichTabStops )
sendmsg hRich, EM_GETEVENTMASK, 0, 0
dwMask = stat | ENM_SELCHANGE | ENM_SCROLLEVENTS | ENM_SCROLL | ENM_CHANGE
sendmsg hRich, EM_SETEVENTMASK, 0, dwMask
dim rcRichView, 4
sendmsg hRich, EM_GETRECT, 0, varptr( rcRichView )
rcRichView.0 += RulerVertWidth + RichViewHorzOffset
rcRichView.1 += RulerHorzHeight + RichViewVertOffset
sendmsg hRich, EM_SETRECT, 0, varptr( rcRichView )
sendmsg hRich, EM_POSFROMCHAR, 0, 0
mgnRichToChar = stat & $FFFF
gsel 3, 1
GetDC hRich: hdcRich = stat
GetTextMetrics hdcRich, varptr( TEXTMETRIC )
ReleaseDC hRich, hdcRich
mref bm3, 67
bm3.54 = cfmt_bCharSet<<24
font "MS ゴシック", RichFontHeight
fmtDigit = "%"+RulerVertDigit+"d"
gsel 2, 1
mref bm2, 67
bm2.54 = cfmt_bCharSet<<24
font "MS ゴシック", RulerHorzHeight - RulerHorzHeight/4
gsel 0, 1
objsel iRich
oncmd gosub *On_Notify, WM_NOTIFY
oncmd gosub *On_Command, WM_COMMAND
oncmd gosub *On_Timer, WM_TIMER
gsel 2
hscr_cbSize = 28
hscr_fMask = SIF_ALL|SIF_DISABLENOSCROLL
GetScrollInfo hRich, SB_HORZ, varptr( HORZ_SCROLLINFO )
gosub *drawRuler
hscr_prevPos = hscr_nPos
vRuler_limLine = ( rcRichView.3 - rcRichView.1 )/( RichExtLeading - RulerVertExtLeading + RichFontHeight )
sendmsg hRich, EM_GETLINECOUNT, 0, 0: vRuler_maxLine = stat
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
stop
*On_Timer
switch( wparam )
case 1
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
if( vRuler_prevLine != vRuler_nLine): gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
swbreak
swend
return 0
*On_Command
if( lparam != hRich ): return 0
switch( wparam>>16 & $FFFF )
case EN_HSCROLL
GetScrollInfo hRich, SB_HORZ, varptr( HORZ_SCROLLINFO )
if( hscr_nPos != hscr_prevPos ): gosub *drawRuler
hscr_prevPos = hscr_nPos
swbreak
case EN_VSCROLL
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
swbreak
case EN_CHANGE
sendmsg hRich, EM_GETLINECOUNT, 0, 0: vRuler_maxLine = stat
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
swbreak
swend
return 0
*On_Notify
dupptr NMHDR, lparam, 12
if( NMHDR != hRich ): return 0
switch( NMHDR.2 )
case EN_SELCHANGE
GetScrollInfo hRich, SB_HORZ, varptr( HORZ_SCROLLINFO )
if( hscr_nPos != hscr_prevPos ): gosub *drawRuler
hscr_prevPos = hscr_nPos
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
swbreak
case EN_MSGFILTER
dupptr MSGFILTER, lparam, 24
msg = MSGFILTER.3: wp = MSGFILTER.4: lp = MSGFILTER.5
if( msg == WM_HSCROLL )||( msg == WM_VSCROLL ): gosub *EditNotify_Scroll
swbreak
swend
return 0
*EditNotify_Scroll
switch( msg )
case WM_HSCROLL
if( wp & $FFFF ) != SB_ENDSCROLL{
hscr_nPos = wp>>16 & $FFFF
gosub *drawRuler
hscr_prevPos = hscr_nPos
}
swbreak
case WM_VSCROLL
if( wp & $FFFF ) == SB_THUMBTRACK{
SetTimer hMain, 1, 10, 0
}
if( wp & $FFFF ) == SB_ENDSCROLL{
KillTimer hMain, 1
}
sendmsg hRich, EM_GETFIRSTVISIBLELINE, 0, 0: vRuler_nLine = stat
gosub *drawRulerVertLineNo
vRuler_prevLine = vRuler_nLine
swbreak
swend
return
*drawRuler
wid = ginfo_sel: gsel 2
syscolor 4: boxf 0, 0, ginfo_winx, RulerHorzHeight
CountStartRow = hscr_nPos / RichFontWidth
oxDrawScale = mgnRichToChar - hscr_nPos \ RichFontWidth
syscolor 7
redraw 0
repeat ( ginfo_winx - mgnRichToChar ) / RichFontWidth + 1
if( oxDrawScale+cnt*RichFontWidth < mgnRichToChar ): continue
switch ( CountStartRow + cnt ) \ 10
case 0
pos oxDrawScale+cnt*RichFontWidth+2, 0: mes ""+( CountStartRow + cnt)
line oxDrawScale+cnt*RichFontWidth, scaleL, oxDrawScale+cnt*RichFontWidth, RulerHorzHeight
swbreak
case 5
line oxDrawScale+cnt*RichFontWidth, scaleM, oxDrawScale+cnt*RichFontWidth, RulerHorzHeight
swbreak
default
line oxDrawScale+cnt*RichFontWidth, scaleS, oxDrawScale+cnt*RichFontWidth, RulerHorzHeight
swbreak
swend
loop
redraw 1
gsel wid
return
*drawRulerVertLineNo
wid = ginfo_sel: gsel 3
redraw 0
syscolor 1: boxf
syscolor 4: line RulerVertWidth-1, -1, RulerVertWidth-1, ginfo_winy
syscolor 9
repeat limit(vRuler_maxLine - vRuler_nLine, vRuler_maxLine - vRuler_nLine, vRuler_limLine ), vRuler_nLine
sendmsg hRich, EM_LINEINDEX, cnt, 0
sendmsg hRich, EM_POSFROMCHAR, stat, 0
pt.0 = stat & $FFFF
pt.1 = stat>>16 & $FFFF
pos 0, pt.1 - RulerHorzHeight + tmExternalLeading
mes strf(fmtDigit,cnt+1)
loop
redraw 1
gsel wid
return
*hsp_exit
if( iparam == 0 ){
gsel 0
clrobj iRich
FreeLibrary hLib
}
end
|