Fresh IDE . Check-in [2ce9ccfb8f]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added TCaret.visible field for hiding the caret without detaching.

More simple and flexible code for scrolling and rendering in TAsmEdit; Proper processing of the external scroll events.

Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:2ce9ccfb8fd5388e2d10a03b8bbb331dc3ad28a4
User & Date: johnfound 2017-12-05 09:56:13
Context
2017-12-05
11:29
Implemented inverting text caret (instead of semitransparent) because it looks better. Implemented vertical caret support in TAsmEdit. check-in: 13078aacb8 user: johnfound tags: NoCanvasGUI
09:56
Added TCaret.visible field for hiding the caret without detaching.

More simple and flexible code for scrolling and rendering in TAsmEdit; Proper processing of the external scroll events. check-in: 2ce9ccfb8f user: johnfound tags: NoCanvasGUI

2017-12-04
15:34
Semi-transparent caret. Implemented changing insert-mode and the selection type from the keyboard (Insert and Ctrl+Alt+Insert keys.) UpdateCaretPos now updates the caret size as well. Also, vertical caret should be implemented there. check-in: 5b08d05798 user: johnfound tags: NoCanvasGUI
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/gui/TAsmEdit.asm.

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
151
152
153
154
155
156
157



158
159
160
161
162
163
164
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
...
221
222
223
224
225
226
227




228




















229


230




























































231
232
233
234
235
236
237
...
457
458
459
460
461
462
463

















































































































464
465
466
467
468
469
470
...
695
696
697
698
699
700
701



702
703
704
705
706
707
708
709
710
711



712
713
714
715
716
717
718
719
720
721
722
723
724




725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740
....
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
....
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
....
2221
2222
2223
2224
2225
2226
2227



2228













































2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248


2249


2250
2251

2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
....
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492

2493
2494
2495
2496
2497
2498

2499
2500
2501
2502
2503
2504
2505
  param .Text,      .GetText,      .SetText

  param .CaretX,    ._caret_x, NONE
  param .CaretY,    ._caret_y, NONE
  param .SelectionX, ._selection_x, NONE
  param .SelectionY, ._selection_y, NONE

  param .PosX,      ._scrollx.pos, ._scrollx.pos
  param .PosY,      ._scrolly.pos, ._scrolly.pos



; param methods

  method  .SetOptions, .value

  method  .GetSelection
................................................................................
  method  .GetText
  method  .SetText, .value

  method  .ComputeLeftMarginWidth
  method  .ComputeScreenInChars

  method  .SetCaretXY, .value, .axis, .fSelect




  method  ._AddSelRectangles, .pRectList


; common methods

  method .Create, .parent
................................................................................

  method .SelfPaint, .pDstImage, .xDst, .yDst, .xSrc, .ySrc, .width, .height    ; Paints itself on the caller provided TImage.

; Text navigarion methods

  method .TextLine, .y

  method .ScrollToCaretY
  method .ScrollToCaretX

  method .CaretLeftRight, .count, .select
  method .CaretUpDown, .count, .scroll, .select

  method .CaretHome, .select
  method .CaretEnd, .select
  method .CaretScrHome, .select
................................................................................
endobj




method TAsmEdit.EventScroll
begin




        inherited [.direction], [.command], [.value]




















        exec      [.self], TAsmEdit:RectChanged2, 0


        return




























































endp


; returns in EDX the rectangle list.

method TAsmEdit._AddSelRectangles       ;, .pRectList
.rect1 RECT
................................................................................

.finish:
        popad
        return
endp





















































































































method TAsmEdit.EventKeyPress
begin
        pushad

        mov     esi, [.self]
................................................................................


method TAsmEdit.UpdateCaretPos
begin
        pushad

        mov     esi, [.self]




        mov     eax, [esi+TAsmEdit._caret_x]
        mov     ecx, [esi+TAsmEdit._caret_y]

        get     edx, esi, TAsmEdit:PosX
        sub     eax, edx
        js      .hide_caret

        imul    eax, [esi+TAsmEdit._font_width]
        add     eax, [esi+TAsmEdit._left_margin]




        get     edx, esi, TAsmEdit:PosY
        sub     ecx, edx
        js      .hide_caret

        mov     edx, 2
        test    [esi+TAsmEdit._options], aeoOverwriteMode
        jz      @f
        mov     edx, [esi+TAsmEdit._font_height]
@@:

        imul    ecx, [esi+TAsmEdit._font_height]
        add     ecx, [esi+TAsmEdit._font_height]




        sub     ecx, edx

        stdcall CaretChange, eax, ecx, [esi+TAsmEdit._font_width], edx

.finish:
        popad
        return

.hide_caret:

        jmp     .finish
endp





................................................................................
        pushad

        mov     edi, [.self]

        mov     [edi+TAsmEdit._cursor], mcText
        mov     [edi+TAsmEdit.__want_focus], TRUE

        mov     [edi+TAsmEdit._options], aeoLeftMargin or aeoLineNumbers or aeoBlockSelection; or aeoStripedBackground or aeoScrollYMore or aeoScrollXMore

        stdcall GetFontMetrics, [ASM.Font]

        mov     [edi+TAsmEdit._font_height], eax
        mov     [edi+TAsmEdit._font_asc], ebx
        mov     [edi+TAsmEdit._font_desc], edx

................................................................................





; Navigation manipulation methods.



method TAsmEdit.ScrollToCaretX
.max_col   dd ? ; the maximal column NOT including partial columns.
.quarter_x dd ?
.rect      RECT
begin
        pushad

        mov     esi, [.self]

        mov     eax, [esi+TAsmEdit._width]
        sub     eax, [esi+TAsmEdit._left_margin]
        sub     eax, [GUI.scrollWidth]
        xor     edx, edx
        div     [esi+TAsmEdit._font_width]

        dec     eax
        mov     [.max_col], eax

        shr     eax, 2
        mov     [.quarter_x], eax

        mov     eax, [esi+TAsmEdit._caret_x]
        sub     eax, [esi+TAsmEdit._scrollx.pos]    ; offset from the screen home.
        js      .scroll_right

; scroll left

        sub     eax, [.max_col]
        jbe     .finish         ; no need to scroll.

;        OutputValue "Scroll distance: ", eax, 10, -1

        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok

        add     eax, [.quarter_x]

.morex_ok:

        get     edx, esi, TAsmEdit:PosX
        add     edx, eax
        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [esi+TAsmEdit._width_ch]
        cmova   eax, [esi+TAsmEdit._width_ch]
        jae     .scroll_left_ok

; now scroll the screen left

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx

.scroll_left_ok:
        mov     edx, [esi+TAsmEdit._width_ch]
        dec     edx

        sub     eax, edx
        neg     eax

;        OutputValue "Scroll left from: ", eax, 10, -1
;        OutputValue "Scroll left to:   ", edx, 10, -1

        inc     edx
        mov     [.rect.left], eax
        mov     [.rect.right], edx

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], eax
        mov     [.rect.bottom], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

.changed:
        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return


.scroll_right:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollXMore
        jz      .morex_ok2

        add     eax, [.quarter_x]

.morex_ok2:

        xor     ecx, ecx
        mov     edx, [esi+TAsmEdit._scrollx.pos]
        sub     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosX, edx

        cmp     eax, [esi+TAsmEdit._width_ch]
        cmova   eax, [esi+TAsmEdit._width_ch]
        jae     .scroll_right_ok

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_width]

        mov     ecx, [esi+TAsmEdit._width_ch]
        imul    ecx, [esi+TAsmEdit._font_width]

        neg     edx
        stdcall ScrollImageH, [esi+TAsmEdit._imgText], edx

.scroll_right_ok:
        xor     ecx, ecx
        inc     eax

        mov     [.rect.left], ecx
        mov     [.rect.right], eax

        mov     eax, [esi+TAsmEdit._height_ch]

        mov     [.rect.top], ecx
        mov     [.rect.bottom], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

        jmp     .changed

endp



method TAsmEdit.TextLine  ; .y
begin
        push    esi

        mov     eax, [.self]
        mov     esi, [eax+TAsmEdit._lines]

................................................................................
        stc
        pop     esi
        return
endp




















































method TAsmEdit.ScrollToCaretY
.max_line  dd ? ; the maximal line NOT including partial rows.
.half_y    dd ?
.quarter_y dd ?
.rect      RECT
begin
        pushad

        mov     esi, [.self]
        mov     edi, [esi+TAsmEdit._lines]

        mov     eax, [esi+TAsmEdit._height]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]

        dec     eax
        mov     [.max_line], eax

        shr     eax, 2
        mov     [.quarter_y], eax





        mov     eax, [esi+TAsmEdit._caret_y]
        sub     eax, [esi+TAsmEdit._scrolly.pos]    ; offset from the screen home.

        js      .scroll_down

; scroll up

        sub     eax, [.max_line]
        jbe     .finish

        test    [esi+TAsmEdit._options], aeoScrollYMore
        jz      .morey_ok

        add     eax, [.quarter_y]

.morey_ok:
        xor     ecx, ecx

        test    [esi+TAsmEdit._options], aeoStripedBackground
        jz      .even_scroll_up_ok

; scroll always even count lines in Zebra mode.
        bt      eax, ecx
        adc     eax, ecx

.even_scroll_up_ok:

        get     edx, esi, TAsmEdit:PosY
        add     edx, eax

        set     esi, TAsmEdit:PosY, edx

; now scroll the screen up

        cmp     eax, [esi+TAsmEdit._height_ch]
        cmova   eax, [esi+TAsmEdit._height_ch]
        jae     .scroll_up_ok

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_height]

        OutputValue "Scroll images up/down: ", edx, 10, -1

        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx

.scroll_up_ok:
        mov     edx, [esi+TAsmEdit._height_ch]
        sub     eax, edx
        neg     eax

        dec     eax

        mov     [.rect.top], eax
        mov     [.rect.bottom], edx
        mov     [.rect.left], 0
        mov     eax, [esi+TAsmEdit._width_ch]
        mov     [.rect.right], eax

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]

.changed:

; In the best case, only the changed part of the window should be refreshed. Especially on the
; relatively narrow assembly source text, the proper updated rectangle can increase the performance
; on big resolutions.
        exec    esi, TAsmEdit:RectChanged2, 0

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return


.scroll_down:

        neg     eax

        test    [esi+TAsmEdit._options], aeoScrollYMore
        jz      .morey_ok2

        add     eax, [.quarter_y]

.morey_ok2:
        xor     ecx, ecx

        test    [esi+TAsmEdit._options], aeoStripedBackground
        jz      .even_scroll_dn_ok

; scroll always even count lines in Zebra mode.
        bt      eax, ecx
        adc     eax, ecx

.even_scroll_dn_ok:

        get     edx, esi, TAsmEdit:PosY
        sub     edx, eax
        cmovs   edx, ecx
        set     esi, TAsmEdit:PosY, edx

        cmp     eax, [esi+TAsmEdit._height_ch]
        cmova   eax, [esi+TAsmEdit._height_ch]
        jae     .scroll_down_ok

        mov     edx, eax
        imul    edx, [esi+TAsmEdit._font_height]

        mov     ecx, [esi+TAsmEdit._height_ch]
        imul    ecx, [esi+TAsmEdit._font_height]

        neg     edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgText], edx
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], edx

.scroll_down_ok:
        mov     [.rect.bottom], eax
        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     [.rect.top], eax
        mov     [.rect.left], eax
        mov     [.rect.right], ecx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.rect.top], [.rect.bottom]

        jmp     .changed

endp






................................................................................
        cmova   ecx, eax

        exec    esi, TAsmEdit:SetCaretXY, ebx, caretAxisY, [.select]

        cmp     [.scroll], edx
        je      .scroll_ok

        mov     [esi+TAsmEdit._scrolly.pos], ecx

        xor     eax, eax
        mov     ecx, [esi+TAsmEdit._width_ch]
        mov     ebx, [esi+TAsmEdit._height_ch]
        mov     [.rect.left], eax
        mov     [.rect.top], eax
        mov     [.rect.right], ecx
        mov     [.rect.bottom], ebx

        lea     eax, [.rect]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], 0, [esi+TAsmEdit._height_ch]

        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos
        jmp     .finish

.scroll_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

.finish:
        popad
        return
endp




method TAsmEdit.CaretHome
begin
        exec    [.self], TAsmEdit:SetCaretXY, 0, caretAxisX, [.select]
        exec    [.self], TAsmEdit:ScrollToCaretX







|
|
<







 







>
>
>







 







|
|







 







>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>






|



>
>
>



|









>
>
>
>


|






>







 







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<
<
<
<




|






|


|
>
>

>
>

|
>
|

<
<
|
|

<
<
<
<
<
<
|

<
|
<
<
|
<
<
<
<
|
|


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|



<


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
|
<
<


<


>






>







132
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
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
...
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
...
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
....
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
....
2260
2261
2262
2263
2264
2265
2266
















































































































































2267
2268
2269
2270
2271
2272
2273
....
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345




2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370


2371
2372
2373






2374
2375

2376


2377




2378
2379
2380
2381





































2382
2383
2384
2385

2386
2387
























































2388
2389
2390
2391
2392
2393
2394
....
2475
2476
2477
2478
2479
2480
2481











2482


2483
2484

2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
  param .Text,      .GetText,      .SetText

  param .CaretX,    ._caret_x, NONE
  param .CaretY,    ._caret_y, NONE
  param .SelectionX, ._selection_x, NONE
  param .SelectionY, ._selection_y, NONE

  param .PosX,      ._scrollx.pos, .SetPosX
  param .PosY,      ._scrolly.pos, .SetPosY



; param methods

  method  .SetOptions, .value

  method  .GetSelection
................................................................................
  method  .GetText
  method  .SetText, .value

  method  .ComputeLeftMarginWidth
  method  .ComputeScreenInChars

  method  .SetCaretXY, .value, .axis, .fSelect

  method  .SetPosX, .value
  method  .SetPosY, .value

  method  ._AddSelRectangles, .pRectList


; common methods

  method .Create, .parent
................................................................................

  method .SelfPaint, .pDstImage, .xDst, .yDst, .xSrc, .ySrc, .width, .height    ; Paints itself on the caller provided TImage.

; Text navigarion methods

  method .TextLine, .y

  method .ScrollToCaretX
  method .ScrollToCaretY

  method .CaretLeftRight, .count, .select
  method .CaretUpDown, .count, .scroll, .select

  method .CaretHome, .select
  method .CaretEnd, .select
  method .CaretScrHome, .select
................................................................................
endobj




method TAsmEdit.EventScroll
begin
        pushad

        mov     esi, [.self]

        cmp     [.direction], scrollX
        je      .horiz_scroll

        cmp     [.command], scWheelUp
        je      .scrollupy

        cmp     [.command], scWheelDn
        je      .scrolldny

        cmp     [.command], scTrack
        jne     .finish

        set     esi, TAsmEdit:PosY, [.value]

.finish:
;        stdcall ProcessSystemEvents
;
        xor     edx, edx
;        mov     [esi+TAsmEdit._img_txt_valid], edx
;        mov     [esi+TAsmEdit._img_margin_valid], edx

        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos
        popad
        return

.scrollupy:
        xor     edx, edx
        get     eax, esi, TAsmEdit:PosY
        sub     eax, [ASM.MouseWheel]
        cmovs   eax, edx
        set     esi, TAsmEdit:PosY, eax
        jmp     .finish


.scrolldny:
        mov     edx, [esi+TAsmEdit._lines]
        mov     edx, [edx+TText.TextLen]
        shr     edx, 2

        get     eax, esi, TAsmEdit:PosY

        add     eax, [ASM.MouseWheel]
        cmp     eax, edx
        cmova   eax, edx

        set     [.self], TAsmEdit:PosY, eax
        jmp     .finish


.horiz_scroll:
        cmp     [.command], scWheelUp
        je      .scrollupx

        cmp     [.command], scWheelDn
        je      .scrolldnx

        cmp     [.command], scTrack
        jne     .finish

        set     esi, TScrollWindow:StartX, [.value]
        jmp     .finish


.scrollupx:
        get     eax, esi, TAsmEdit:PosX
        xor     edx, edx
        sub     eax, [ASM.MouseWheel]
        cmovs   eax, edx

        set     esi, TAsmEdit:PosX, eax
        jmp     .finish


.scrolldnx:
        or      edx, -1
        shr     edx, 1

        get     ecx, [esi+TScrollWindow.XScroller], TScrollbar:Max;
        get     eax, esi, TAsmEdit:PosX
        add     eax, [ASM.MouseWheel]
        cmovs   eax, edx
        set     esi, TAsmEdit:PosX, eax
        jmp     .finish

endp


; returns in EDX the rectangle list.

method TAsmEdit._AddSelRectangles       ;, .pRectList
.rect1 RECT
................................................................................

.finish:
        popad
        return
endp



method TAsmEdit.SetPosX
.render RECT
begin
        pushad
        mov     esi, [.self]

        xor     ecx, ecx
        mov     ebx, [esi+TAsmEdit._width_ch]
        mov     eax, [esi+TAsmEdit._height_ch]
        mov     [.render.left], ecx
        mov     [.render.top], ecx
        mov     [.render.right], ebx
        mov     [.render.bottom], eax

        mov     eax, [.value]
        xchg    eax, [esi+TAsmEdit._scrollx.pos]
        sub     eax, [esi+TAsmEdit._scrollx.pos]        ; eax < 0 = scroll left; eax > 0 = scroll right
        jz      .finish

        mov     edx, eax
        jns     @f
        neg     edx
@@:
        cmp     edx, [esi+TAsmEdit._width_ch]
        jge     .do_render

        test    eax, eax
        js      .scroll_left

        cmp     eax, [esi+TAsmEdit._width_ch]
        jae     .do_render

        mov     [.render.right], eax
        jmp     .scrollit

.scroll_left:
        add     ebx, eax
        dec     ebx
        mov     [.render.left], ebx

.scrollit:
        neg     eax
        imul    eax, [esi+TAsmEdit._font_width]
        stdcall ScrollImageH, [esi+TAsmEdit._imgText], eax

.do_render:
        lea     eax, [.render]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax

.finish:
        popad
        return
endp



method TAsmEdit.SetPosY
.render RECT
begin
        pushad
        mov     esi, [.self]

        xor     ecx, ecx
        mov     eax, [esi+TAsmEdit._width_ch]
        mov     ebx, [esi+TAsmEdit._height_ch]
        mov     [.render.left], ecx
        mov     [.render.top], ecx
        mov     [.render.right], eax
        mov     [.render.bottom], ebx

        mov     eax, [.value]
        xchg    eax, [esi+TAsmEdit._scrolly.pos]
        sub     eax, [esi+TAsmEdit._scrolly.pos]        ; eax < 0 = scroll up; eax > 0 = scroll down
        jz      .finish

        mov     edx, eax
        jns     @f
        neg     edx
@@:
        cmp     edx, [esi+TAsmEdit._height_ch]
        jge     .do_render

        test    eax, eax
        js      .scroll_up

        cmp     eax, [esi+TAsmEdit._height_ch]
        jae     .do_render

        mov     [.render.bottom], eax
        jmp     .scrollit

.scroll_up:
        add     ebx, eax
        dec     ebx
        mov     [.render.top], ebx

.scrollit:
        neg     eax
        imul    eax, [esi+TAsmEdit._font_height]
        stdcall ScrollImageV, [esi+TAsmEdit._imgText], eax
        stdcall ScrollImageV, [esi+TAsmEdit._imgMargin], eax

.do_render:
        lea     eax, [.render]
        exec    esi, TAsmEdit:_RenderTxt, [esi+TAsmEdit._imgText], eax
        exec    esi, TAsmEdit:_RenderLM, [esi+TAsmEdit._imgMargin], [.render.top], [.render.bottom]

.finish:
        popad
        return
endp



method TAsmEdit.EventKeyPress
begin
        pushad

        mov     esi, [.self]
................................................................................


method TAsmEdit.UpdateCaretPos
begin
        pushad

        mov     esi, [.self]
        xor     edi, edi
        xor     ebx, ebx
        inc     ebx

        mov     eax, [esi+TAsmEdit._caret_x]
        mov     ecx, [esi+TAsmEdit._caret_y]

        get     edx, esi, TAsmEdit:PosX
        sub     eax, edx
        cmovs   ebx, edi

        imul    eax, [esi+TAsmEdit._font_width]
        add     eax, [esi+TAsmEdit._left_margin]

        cmp     eax, [esi+TAsmEdit._width]
        cmovae  ebx, edi

        get     edx, esi, TAsmEdit:PosY
        sub     ecx, edx
        cmovs   ebx, edi

        mov     edx, 2
        test    [esi+TAsmEdit._options], aeoOverwriteMode
        jz      @f
        mov     edx, [esi+TAsmEdit._font_height]
@@:

        imul    ecx, [esi+TAsmEdit._font_height]
        add     ecx, [esi+TAsmEdit._font_height]

        cmp     ecx, [esi+TAsmEdit._height]
        cmovae  ebx, edi

        sub     ecx, edx

        stdcall CaretChange, eax, ecx, [esi+TAsmEdit._font_width], edx, ebx

.finish:
        popad
        return

.hide_caret:
        mov     [Caret.visible], 0
        jmp     .finish
endp





................................................................................
        pushad

        mov     edi, [.self]

        mov     [edi+TAsmEdit._cursor], mcText
        mov     [edi+TAsmEdit.__want_focus], TRUE

        mov     [edi+TAsmEdit._options], aeoLeftMargin or aeoLineNumbers ; or aeoStripedBackground or aeoScrollYMore or aeoScrollXMore

        stdcall GetFontMetrics, [ASM.Font]

        mov     [edi+TAsmEdit._font_height], eax
        mov     [edi+TAsmEdit._font_asc], ebx
        mov     [edi+TAsmEdit._font_desc], edx

................................................................................





; Navigation manipulation methods.

















































































































































method TAsmEdit.TextLine  ; .y
begin
        push    esi

        mov     eax, [.self]
        mov     esi, [eax+TAsmEdit._lines]

................................................................................
        stc
        pop     esi
        return
endp



method TAsmEdit.ScrollToCaretX
begin
        pushad

        mov     esi, [.self]
        xor     ecx, ecx

        mov     eax, [esi+TAsmEdit._width]
        sub     eax, [esi+TAsmEdit._left_margin]
        xor     edx, edx
        div     [esi+TAsmEdit._font_width]

        dec     eax
        mov     ebx, eax    ; max column

        shr     eax, 2
        test    [esi+TAsmEdit._options], aeoScrollXMore
        cmovz   edi, ecx
        cmovnz  edi, eax        ; scroll more than needed.

        get     edx, esi, TAsmEdit:PosX

        mov     eax, [esi+TAsmEdit._caret_x]
        sub     eax, edx                       ; offset from the screen home.
        jz      .finish                        ; no need to scroll
        js      .do_scroll

        sub     eax, ebx
        jle     .finish

        neg     edi

.do_scroll:
        sub     eax, edi
        add     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosX, edx
        exec    esi, TAsmEdit:RectChanged2, ecx

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos
        popad
        return
endp




method TAsmEdit.ScrollToCaretY




begin
        pushad

        mov     esi, [.self]
        xor     ecx, ecx

        mov     eax, [esi+TAsmEdit._height]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]

        dec     eax
        mov     ebx, eax  ; max line

        shr     eax, 2
        test    [esi+TAsmEdit._options], aeoScrollYMore
        cmovz   edi, ecx
        cmovnz  edi, eax        ; scroll more than needed.

        get     edx, esi, TAsmEdit:PosY

        mov     eax, [esi+TAsmEdit._caret_y]
        sub     eax, edx                       ; offset from the screen home.
        jz      .finish                        ; no need to scroll
        js      .do_scroll



        sub     eax, ebx
        jle     .finish







        neg     edi


.do_scroll:


        sub     eax, edi




        add     edx, eax
        cmovs   edx, ecx

        set     esi, TAsmEdit:PosY, edx





































        exec    esi, TAsmEdit:RectChanged2, ecx

.finish:
        exec    esi, TAsmEdit:UpdateCaretPos

        popad
        return
























































endp






................................................................................
        cmova   ecx, eax

        exec    esi, TAsmEdit:SetCaretXY, ebx, caretAxisY, [.select]

        cmp     [.scroll], edx
        je      .scroll_ok












        set     esi, TAsmEdit:PosY, ecx


        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos


.scroll_ok:

        exec    esi, TAsmEdit:ScrollToCaretY

.finish:
        popad
        return
endp




method TAsmEdit.CaretHome
begin
        exec    [.self], TAsmEdit:SetCaretXY, 0, caretAxisX, [.select]
        exec    [.self], TAsmEdit:ScrollToCaretX

Changes to freshlib/gui/TEdit.asm.

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
        and     [esi+TCanvasWindow._canvas_valid], 0

.canvas_ok:
        mov     edx, [esi+TEdit._height]
        sub     edx, 6

;        add     ecx, [GUI.boxBorderWidth]
        stdcall CaretChange, ecx, 3, 2, edx

.finish:
        popad
        return
endp









|







642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
        and     [esi+TCanvasWindow._canvas_valid], 0

.canvas_ok:
        mov     edx, [esi+TEdit._height]
        sub     edx, 6

;        add     ecx, [GUI.boxBorderWidth]
        stdcall CaretChange, ecx, 3, 2, edx, TRUE

.finish:
        popad
        return
endp


Changes to freshlib/gui/textcaret.asm.

20
21
22
23
24
25
26

27
28
29
30
31
32
33
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
167
168
169
170
171
172
173



174
175
176
177
178
179
180
...
252
253
254
255
256
257
258



259
260
261
262
263
264
265
  .pWindow    dd ?

  .pTopWindow dd ?
  .xOffs      dd ?      ; the offset between the caret owner window and its top level parent window
  .yOffs      dd ?      ;

  .state      dd ?       ; 1 if the caret is displayed 0 if not.

  .next_time  dd ?

  .Pos       TBounds
  .mxLock    TMutex
ends


................................................................................
        pop     ecx
        return
endp




proc CaretChange, .x, .y, .width, .height
begin
        pushad

        stdcall WaitForMutex, Caret.mxLock, CARET_MUTEX_WAIT
        jc      .exit

        stdcall __ClearCaret
................................................................................

        test    edx, edx
        cmovz   edx, eax

        mov     [Caret.Pos.width], ecx
        mov     [Caret.Pos.height], edx




; restart the visible state from the beginning in order to make the moved
; caret move visible.

        mov     [Caret.state], 1
        stdcall GetTimestamp
        add     eax, [GUI.caretTimes+4]
        mov     [Caret.next_time], eax
................................................................................

        mov     ebx, [.topWindow]
        cmp     ebx, [Caret.pTopWindow]
        jne     .release

        cmp     [Caret.state], 0
        je      .release




        get     ebx, ebx, TWindow:Screen
        test    ebx, ebx
        jz      .release

        push    ecx edx
        mov     ecx, [Caret.Pos.x]







>







 







|







 







>
>
>







 







>
>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
  .pWindow    dd ?

  .pTopWindow dd ?
  .xOffs      dd ?      ; the offset between the caret owner window and its top level parent window
  .yOffs      dd ?      ;

  .state      dd ?       ; 1 if the caret is displayed 0 if not.
  .visible    dd ?
  .next_time  dd ?

  .Pos       TBounds
  .mxLock    TMutex
ends


................................................................................
        pop     ecx
        return
endp




proc CaretChange, .x, .y, .width, .height, .visible
begin
        pushad

        stdcall WaitForMutex, Caret.mxLock, CARET_MUTEX_WAIT
        jc      .exit

        stdcall __ClearCaret
................................................................................

        test    edx, edx
        cmovz   edx, eax

        mov     [Caret.Pos.width], ecx
        mov     [Caret.Pos.height], edx

        mov     eax, [.visible]
        mov     [Caret.visible], eax

; restart the visible state from the beginning in order to make the moved
; caret move visible.

        mov     [Caret.state], 1
        stdcall GetTimestamp
        add     eax, [GUI.caretTimes+4]
        mov     [Caret.next_time], eax
................................................................................

        mov     ebx, [.topWindow]
        cmp     ebx, [Caret.pTopWindow]
        jne     .release

        cmp     [Caret.state], 0
        je      .release

        cmp     [Caret.visible], 0
        je      .release

        get     ebx, ebx, TWindow:Screen
        test    ebx, ebx
        jz      .release

        push    ecx edx
        mov     ecx, [Caret.Pos.x]