forked from jslarve/ColorTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSSelectSpinnerClass.clw
More file actions
449 lines (410 loc) · 12 KB
/
Copy pathJSSelectSpinnerClass.clw
File metadata and controls
449 lines (410 loc) · 12 KB
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
MEMBER
!MIT License
!
!Copyright (c) 2021 Jeff Slarve
!
!Permission is hereby granted, free of charge, to any person obtaining a copy
!of this software and associated documentation files (the "Software"), to deal
!in the Software without restriction, including without limitation the rights
!to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
!copies of the Software, and to permit persons to whom the Software is
!furnished to do so, subject to the following conditions:
!
!The above copyright notice and this permission notice shall be included in all
!copies or substantial portions of the Software.
!
!THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
!IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
!FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
!AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
!LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
!OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
!SOFTWARE.
!
Include('JSSelectSpinnerClass.inc'),ONCE
Include('KeyCodes.clw'),ONCE
OMIT('***')
* Created with Clarion 10.0
* User: jslarve
* Date: 9/8/2018
* Time: 8:19 AM
***
MAP
Module('')
ULtoA(ULONG,*CSTRING,SIGNED),ULONG,RAW,NAME('_ultoa'),PROC
end
ToHEX(Long pLong,Long pLen=6),STRING
IsSpecialHexCharacter(String pS),LONG
LeftRotate(SIGNED pN,UNSIGNED pD,SIGNED pBits=32),SIGNED
RightRotate(SIGNED pN,UNSIGNED pD,SIGNED pBits=32),SIGNED
END
JSSelectSpinnerClass.Construct PROCEDURE
CODE
SELF.FEQ = 0
SELF.MinRange = 33
SELF.MaxRange = 126
SELF.BitQty = 24
JSSelectSpinnerClass.IncrementBuffer PROCEDURE(*STRING pS,LONG pDirection)
S &String
MinRange LONG
MaxRange LONG
HexString String('0123456789ABCDEF')
DecVal SHORT
CODE
S &= pS[1]
Case SELF.Mode
of JSSpinMode:Alpha OROF JSSpinMode:ASCII OROF JSSpinMode:Custom
Case SELF.Mode
of JSSpinMode:Alpha
Case Val(S)
of 33 to 126
Case Val(S)
of 65 to 90
MinRange = 65
MaxRange = 90
of 97 to 122
MinRange = 97
MaxRange = 122
else
MinRange = Val(S)
MaxRange = MinRange
end
ELSE
RETURN
end
of JSSpinMode:ASCII
MinRange = 33
MaxRange = 126
of JSSpinMode:Custom
MinRange = SELF.MinRange
MaxRange = SELF.MaxRange
END
Case pDirection
of 1
S = CHR(VAL(S)+1)
If VAL(S) > MaxRange
S = CHR(MinRange)
end
of -1
S = CHR(VAL(S)-1)
If VAL(S) < MinRange
S = CHR(MaxRange)
end
end
of JSSpinMode:Binary
S = Choose(S=1,0,1)
of JSSpinMode:Decimal
Case pDirection
of 1
If S = 9
S = 0
else
S += 1
end
of -1
If S = 0
S = 9
ELSE
S -= 1
END
end
of JSSpinMode:Hexadecimal
DecVal = Evaluate('0' & S & 'h')
Case pDirection
of 1
If DecVal >= 15
DecVal = 0
ELSE
DecVal += 1
END
of -1
If DecVal <= 0
DecVal = 15
ELSE
DecVal -= 1
END
END
S = HexString[DecVal+1]
of JSSpinMode:Octal
Case pDirection
of 1
If S = 7
S = 0
ELSE
S += 1
END
of -1
If S = 0
S = 7
ELSE
S -= 1
END
end
end
JSSelectSpinnerClass.Init PROCEDURE(LONG pFEQ,LONG pMODE)
CODE
CASE pFEQ{PROP:Type}
OF CREATE:entry orof CREATE:text
SELF.FEQ = pFEQ
ELSE
Message('JSSelectSpinnerClass: You can only pass an ENTRY or TEXT control to the Init method')
RETURN
END
CASE pMode
OF JSSpinMode:Alpha
OROF JSSpinMode:Binary
OROF JSSpinMode:Decimal
OROF JSSpinMode:Hexadecimal
OROF JSSpinMode:Octal
SELF.Mode = pMode
ELSE
SELF.Mode = JSSpinMode:Alpha
END
SELF.FEQ{PROP:Alrt,255} = PgUpKey
SELF.FEQ{PROP:Alrt,255} = PgDnKey
SELF.FEQ{PROP:Alrt,255} = CtrlPgDn
SELF.FEQ{PROP:Alrt,255} = CtrlPgUp
SELF.FEQ{PROP:Alrt,255} = CtrlMouseLeft2
SELF.FEQ{PROP:Alrt,255} = ShiftPgDn
SELF.FEQ{PROP:Alrt,255} = ShiftPgUp
JSSelectSpinnerClass.TakeEvent PROCEDURE
Looped BYTE
Buffer &String
Ndx LONG
OrigSelStart LONG
OrigSelEnd LONG
SelStart LONG
SelEnd LONG
EvalLong LONG
CODE
If Field() <> SELF.FEQ
Return 0
end
Case Event()
of Event:AlertKey orof EVENT:PreAlertKey
ELSE
Return 0
end
! ST.Trace('Class event: ' & Event() & ' Field=' & Field())
LOOP ! This method receive all EVENT:Accepted's
IF Looped
RETURN 0
ELSE
Looped = 1
END
Case Event()
of EVENT:PreAlertKey
Case KeyCode()
of CtrlMouseLeft2
Cycle
end
of EVENT:AlertKey
Case KeyCode()
of CtrlMouseLeft2
Execute Popup('Alpha Mode|Binary Mode|Octal Mode|Decimal Mode|Hexadecimal Mode|ASCII Mode|Custom Mode')
SELF.Mode = JSSpinMode:Alpha
SELF.Mode = JSSpinMode:Binary
SELF.Mode = JSSpinMode:Octal
SELF.Mode = JSSpinMode:Decimal
SELF.Mode = JSSpinMode:HexaDecimal
SELF.Mode = JSSpinMode:ASCII
SELF.Mode = JSSpinMode:Custom
end
SELF.FEQ{PROP:SelStart} = 0
SELF.FEQ{PROP:SelEnd} = Len(Clip(Contents(SELF.FEQ)))
SelEnd = 0
SelStart = 0
OrigSelEnd = 0
OrigSelStart = 0
SELECT(SELF.FEQ)
of PgUpKey orof CtrlPgUp
Do GetContents
Do GetSelection
! ST.Trace('PgUpKey SelStart=' & SelStart & ' Selend=' & SelEnd)
If SelStart = SelEnd
Ndx = SelStart
If Ndx <> 0
SELF.IncrementBuffer(Buffer[Ndx],1)
end
else
Case KeyCode()
of PgUpKey
Loop Ndx = SelStart to SelEnd
If SELF.Mode = JSSpinMode:Hexadecimal AND IsSpecialHexCharacter(Buffer[Ndx])
Cycle
end
SELF.IncrementBuffer(Buffer[ndx],1)
end
of CtrlPgUp
Case SELF.Mode
of JSSpinMode:Decimal orof JSSpinMode:Hexadecimal orof JSSpinMode:Octal
Loop Ndx = SelEnd to SelStart BY -1
If SELF.Mode = JSSpinMode:Hexadecimal AND IsSpecialHexCharacter(Buffer[Ndx])
Cycle
end
SELF.IncrementBuffer(Buffer[ndx],1)
If Buffer[Ndx] <> '0'
Break
end
end
else
Loop Ndx = SelStart to SelEnd
SELF.IncrementBuffer(Buffer[ndx],1)
end
end
end
end
Do PutContents
of ShiftPgUp
Case SELF.Mode
of JSSpinMode:HexaDecimal
Do GetContents
EvalLong = Evaluate('0' & Buffer & 'h')
EvalLong = LeftRotate(EvalLong,1,SELF.BitQty)
Buffer = ToHEX(EvalLong,Len(Clip(Buffer)))
Do PutContents
end
of ShiftPgDn
Case SELF.Mode
of JSSpinMode:HexaDecimal
Do GetContents
EvalLong = Evaluate('0' & Buffer & 'h')
EvalLong = RightRotate(EvalLong,1,SELF.BitQty)
Buffer = ToHEX(EvalLong,Len(Clip(Buffer)))
Do PutContents
end
of PgDnKey orof CtrlPgDn
Do GetContents
Do GetSelection
! ST.Trace('PgDnKey SelStart=' & SelStart & ' Selend=' & SelEnd)
If SelStart = SelEnd
Ndx = SelStart
If Ndx <> 0
SELF.IncrementBuffer(Buffer[Ndx],-1)
end
else
Case KeyCode()
of PgDnKey
Loop Ndx = SelStart to SelEnd
If SELF.Mode = JSSpinMode:Hexadecimal AND IsSpecialHexCharacter(Buffer[Ndx])
Cycle
end
SELF.IncrementBuffer(Buffer[ndx],-1)
end
of CtrlPgDn
Case SELF.Mode
of JSSpinMode:Decimal orof JSSpinMode:Hexadecimal orof JSSpinMode:Octal
Loop Ndx = SelEnd to SelStart BY -1
If SELF.Mode = JSSpinMode:Hexadecimal AND IsSpecialHexCharacter(Buffer[Ndx])
Cycle
end
SELF.IncrementBuffer(Buffer[ndx],-1)
Case SELF.Mode
of JSSpinMode:Decimal
If Buffer[Ndx] <> '9'
Break
end
of JSSpinMode:Hexadecimal
If Buffer[Ndx] <> 'F'
Break
end
of JSSpinMode:Octal
If Buffer[Ndx] <> '7'
Break
end
end
end
else
Loop Ndx = SelStart to SelEnd
SELF.IncrementBuffer(Buffer[ndx],-1)
end
end
end
end
Do PutContents
end
end
END
Return 0
GetContents ROUTINE
If CONTENTS(SELF.FEQ)
Update(SELF.FEQ)
Buffer &= NEW String(len(Contents(SELF.FEQ)))
Buffer = CONTENTS(SELF.FEQ)
! ST.Trace('GetContents Buffer="' & Buffer & '"')
end
PutContents ROUTINE
If NOT Buffer &= NULL
Change(SELF.FEQ,Clip(Buffer))
Display(SELF.FEQ)
Dispose(Buffer)
SELF.FEQ{PROP:SelStart} = SelStart
SELF.FEQ{PROP:SelEnd} = SelEnd
! ST.Trace('PutContents SelStart=' & SELF.FEQ{PROP:SelStart} & ' SelEnd=' & SELF.FEQ{PROP:SelEnd})
SELF.FEQ{PROP:Touched} = TRUE
Post(Event:Accepted,SELF.FEQ)
end
GetSelection ROUTINE
OrigSelStart = SELF.FEQ{PROP:SelStart}
OrigSelEnd = SELF.FEQ{PROP:SelEnd}
If OrigSelEnd < OrigSelStart
SelStart = OrigSelEnd + 1
SelEnd = OrigSelStart - 1
ELSE
SelStart = OrigSelStart
SelEnd = OrigSelEnd
end
! ST.Trace('GetSelection 1: SelStart=' & SelStart & ' SelEnd=' & SElEnd)
If NOT SelStart
SelStart = 1
end
If SelStart > SelEnd
!SelStart = SelEnd
SelEnd = SelStart
end
If SelEnd > Len(Clip(Contents(SELF.FEQ)))
SelEnd = Len(Clip(Contents(SELF.FEQ)))
end
If SelStart > Len(Clip(Contents(SELF.FEQ)))
SelStart = Len(Clip(Contents(SELF.FEQ)))
end
If NOT SelEnd
SelEnd = SelStart
end
! ST.Trace('GetSelection 2: SelStart=' & SelStart & ' SelEnd=' & SElEnd)
IsSpecialHexCharacter PROCEDURE(String pS)
CODE
Case pS
of '#' orof 'x' orof 'h' orof 'H'
RETURN TRUE
END
RETURN FALSE
ToHEX PROCEDURE(Long pLong,Long pLen=6)!,STRING
lHexCS CSTRING(20)
CODE
ULtoA(pLong,lHexCS,16)
RETURN UPPER(ALL('0',pLen - LEN(lHexCS)) & lHexCS)
LeftRotate PROCEDURE(SIGNED pN,UNSIGNED pD,SIGNED pBits=32)!,SIGNED
TruncMask LONG
BitNdx LONG
CODE
TruncMask = (2 ^ pBits) - 1
RETURN BAND( |
BOR( |
BSHIFT(pN,ABS(pD)), |
BSHIFT(pN,-(pBits-ABS(pD)))|
), |
TruncMask |
)
RightRotate PROCEDURE(SIGNED pN,UNSIGNED pD,SIGNED pBits=32)!,SIGNED
TruncMask LONG
BitNdx LONG
CODE
TruncMask = (2 ^ pBits) - 1
RETURN BAND( |
BOR( |
BSHIFT(pN,-ABS(pD)), |
BSHIFT(pN,(pBits-ABS(pD)))|
), |
TruncMask |
)