Fresh IDE . Check-in [67022b13a9]
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:More simple API for the TAsmEdit carete and selections coordinates.
Timelines: family | ancestors | descendants | both | NoCanvasGUI
Files: files | file ages | folders
SHA1:67022b13a93222bb82631b6faa9149bb7da0e5ce
User & Date: johnfound 2018-07-03 12:06:09
Context
2018-07-24
07:42
Work on TAsmEdit. Simple syntax highlighter working now. The colors are derived from the Tomorrow there. Leaf check-in: fbc1786a73 user: johnfound tags: NoCanvasGUI
2018-07-03
12:06
More simple API for the TAsmEdit carete and selections coordinates. check-in: 67022b13a9 user: johnfound tags: NoCanvasGUI
2018-07-01
10:29
Some work on the TAsmEdit selections. Not working though. check-in: 95492a43df user: johnfound tags: NoCanvasGUI
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/gui/TAsmEdit.asm.

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
126
127
128
129
130
131
132

133
134

135
136
137
138
139
140
141
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223









224
225
226
227
228
229
230
...
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
...
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
...
462
463
464
465
466
467
468






469
470
471
472
473
474
475
...
563
564
565
566
567
568
569






570
571
572
573
574
575
576
...
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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
...
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
953
954
955
956



957
958
959
960
961
962
963
....
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
....
1188
1189
1190
1191
1192
1193
1194

1195


1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
....
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
....
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
....
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829

2830
2831
2832
2833
2834
2835
2836
2837
2838
....
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
....
2890
2891
2892
2893
2894
2895
2896
2897


2898

2899
2900
2901
2902
2903
2904
2905
....
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
....
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
....
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964


2965

2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985




























































































2986
2987
2988
2989
2990
2991
2992
....
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221

3222
3223
3224
3225
3226
3227
3228
....
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
aeoAutoBrackets        = $080000
aeoSmartTabs           = $100000
aeoPersistentSelection = $200000

aeoDefault = aeoLeftMargin or aeoLineNumbers or aeoConsoleCaret or aeoAutoIndents or aeoSmartTabs


; constants for SetCaretXY
caretAxisX = 0
caretAxisY = 1

; select commands

selCmdNone  = 0
selCmdStart = 1
selCmdEnd   = 2

; Operations for undo/redo:

chopInserted = 0
chopDeleted  = 1
chopChanged  = 2

struct TUndoInfo
................................................................................

  ._wrap_width    dd    ?       ; the word wrap width for the word wrapped lines.

  ._caretPos      POINT

  ._selStart      POINT         ; The selection start point
  ._selEnd        POINT         ;


  ._selCmd        dd    ?


  ._drag_button   dd    ?

  ._scrollx       TScroller
  ._scrolly       TScroller

  ._width_ch      dd    ?       ; width and
................................................................................

  method  .GetText
  method  .SetText, .value

  method  .ComputeLeftMarginWidth
  method  .ComputeScreenInChars

  method  .SetCaretXY, .value, .axis, .cmdSelect

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

  method  ._AddSelRectangles, .pRectList
  method  ._AddSelRectanglesAbs, .pRectList


................................................................................
; Text navigarion methods

  method .TextLine, .y

  method .ScrollToCaretX
  method .ScrollToCaretY

  method .CaretLeftRight, .count, .cmdSelect
  method .CaretUpDown, .count, .scroll, .cmdSelect

  method .CaretHome, .cmdSelect
  method .CaretEnd, .cmdSelect
  method .CaretScrHome, .cmdSelect
  method .CaretScrEnd, .cmdSelect
  method .CaretTxtHome, .cmdSelect
  method .CaretTxtEnd, .cmdSelect










; undo/redo

  method .SaveForUndo, .LineNum, .operation
  method .Undo
  method .Redo

................................................................................
        pushad
        mov     esi, [.self]
        cmp     [esi+TAsmEdit._drag_button], mbLeft
        jne     .finish

        xor     ecx, ecx



        mov     eax, [.x]
        sub     eax, [esi+TAsmEdit._left_margin]
        cdq
        idiv    [esi+TAsmEdit._font_width]

        get     ebx, esi, TAsmEdit:PosX
        add     eax, ebx
        cmovs   eax, ecx

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisX, selCmdEnd
        exec    esi, TAsmEdit:ScrollToCaretX

        mov     eax, [.y]
        cdq
        idiv    [esi+TAsmEdit._font_height]
        get     ebx, esi, TAsmEdit:PosY
        add     eax, ebx
        cmovs   eax, ecx



        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisY, selCmdEnd
        exec    esi, TAsmEdit:ScrollToCaretY

        exec    esi, TAsmEdit:UpdateCaretPos


.finish:
        popad
        return
endp


................................................................................
        mov     [esi+TAsmEdit._drag_button], eax

        stdcall SetMouseCapture, esi

        cmp     eax, mbLeft
        jne     .finish



        xor     ecx, ecx

        mov     eax, [.x]
        sub     eax, [esi+TAsmEdit._left_margin]
        cdq
        idiv    [esi+TAsmEdit._font_width]

        get     ebx, esi, TAsmEdit:PosX
        add     eax, ebx
        cmovs   eax, ecx

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisX, selCmdStart


        mov     eax, [.y]
        cdq
        idiv    [esi+TAsmEdit._font_height]
        get     ebx, esi, TAsmEdit:PosY
        add     eax, ebx
        cmovs   eax, ecx




        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisY, selCmdStart
        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        popad
        return
endp


................................................................................
        lea     edi, [.rect1]
        mov     ecx, sizeof.RECT * 3 / 4

        rep stosd

        mov     esi, [.self]
        mov     edx, [.pRectList]







        mov     eax, [esi+TAsmEdit._selStart.x]
        mov     ecx, [esi+TAsmEdit._selStart.y]
        mov     ebx, [esi+TAsmEdit._selEnd.x]
        mov     edi, [esi+TAsmEdit._selEnd.y]

        test    [esi+TAsmEdit._options], aeoBlockSelection
................................................................................
        lea     edi, [.rect1]
        mov     ecx, sizeof.RECT * 4 / 4

        rep stosd

        mov     esi, [.self]
        mov     edx, [.pRectList]







        mov     eax, [esi+TAsmEdit._width_ch]
        mov     ecx, [esi+TAsmEdit._height_ch]
        mov     [.client.right], eax
        mov     [.client.bottom], ecx

        mov     eax, [esi+TAsmEdit._selStart.x]
................................................................................

.finish:
        mov     [esp+4*regEDX], edx
        popad
        return
endp


method TAsmEdit.SetCaretXY       ; .value, .axis, .cmdSelect
begin
        pushad
        mov     esi, [.self]
        mov     ecx, [.axis]
        and     ecx, 1

        mov     ebx, [.value]
        cmp     ebx, [esi+TAsmEdit._caretPos + 4*ecx]
        jne     .change_it

        cmp     [.cmdSelect], selCmdNone
        jne     .finish

;        cmp     ebx, [esi+TAsmEdit._selection_x+4*ecx]
;        je      .finish

.change_it:
        stdcall CreateArray, sizeof.RECT
        mov     edx, eax

        exec    esi, TAsmEdit:_AddSelRectangles, edx

        cmp     [.cmdSelect], selCmdStart
        jne     .sel_start_ok

        mov     eax, [esi+TAsmEdit._caretPos + 4*ecx]
        mov     [esi+TAsmEdit._selStart + 4*ecx], eax
        mov     [esi+TAsmEdit._selEnd + 4*ecx], ebx

        OutputValue "Selection start:", eax, 10, -1
        OutputValue "Selection end:", ebx, 10, -1

        xor     ecx, 1
        mov     eax, [esi+TAsmEdit._caretPos + 4*ecx]
        mov     [esi+TAsmEdit._selStart + 4*ecx], eax
        mov     [esi+TAsmEdit._selEnd + 4*ecx], eax

        xor     ecx, 1

.sel_start_ok:

        mov     [esi+TAsmEdit._caretPos + 4*ecx], ebx

        cmp     [.cmdSelect], selCmdEnd
        jne     .selection_ok

        mov     [esi+TAsmEdit._selEnd + 4*ecx], ebx

        xor     ecx, 1
        mov     ebx, [esi+TAsmEdit._caretPos + 4*ecx]
        mov     [esi+TAsmEdit._selEnd + 4*ecx], ebx

.selection_ok:

        exec    esi, TAsmEdit:_AddSelRectangles, edx
        mov     ecx, [edx+TArray.count]
        lea     edi, [edx+TArray.array]

.loop:
        dec     ecx
        js      .freelist

        mov     eax, [edi+RECT.left]
        mov     ebx, [edi+RECT.top]

        imul    eax, [esi+TAsmEdit._font_width]
        imul    ebx, [esi+TAsmEdit._font_height]

        add     eax, [esi+TAsmEdit._left_margin]

        mov     [edi+RECT.left], eax
        mov     [edi+RECT.top], ebx

        mov     eax, [edi+RECT.right]
        mov     ebx, [edi+RECT.bottom]

        imul    eax, [esi+TAsmEdit._font_width]
        imul    ebx, [esi+TAsmEdit._font_height]

        add     eax, [esi+TAsmEdit._left_margin]

        mov     [edi+RECT.right], eax
        mov     [edi+RECT.bottom], ebx

        exec    esi, TAsmEdit:RectChanged2, edi

        add     edi, sizeof.RECT
        jmp     .loop

.freelist:
        stdcall FreeMem, edx

.finish:
        popad
        return
endp




method TAsmEdit.SetPosX
.render RECT
begin
        pushad
................................................................................
        popad
        return
endp



method TAsmEdit.EventKeyPress

begin
        pushad

        mov     esi, [.self]

        mov     ecx, [esi+TAsmEdit._selCmd]
        xor     ebx, ebx
        xor     edx, edx
        dec     ebx
        inc     edx
        inc     edx             ; ebx = -1 edx = 2

        mov     eax, [.kbdState]
        test    eax, maskShift
        cmovz   ecx, ebx                ; ecx = selCmdNone = -1 if the shift key is not pressed.


; continue the selection, if Ctrl key is pressed.
        and     eax, maskCtrl or maskShift
        cmp     eax, maskCtrl or maskShift
        cmove   ecx, edx

        inc     ecx

        cmp     ecx, edx
        cmova   ecx, edx                ; ecx = selCmdEnd if > selCmdEnd

        OutputValue "Selection command: ", ecx, 10, -1


        mov     eax, [.utf8]

        test    eax, eax
        jz      .no_char

        cmp     eax, $20
        jb      .ctrl_char

        cmp     eax, $7f
        je      .no_char




        jmp     .finish


.ctrl_char:

        cmp     eax, 26         ; Ctrl+Z
................................................................................
        mov     [esi+TAsmEdit._img_txt_valid], eax
        mov     [esi+TAsmEdit._img_margin_valid], eax
        exec    esi, TAsmEdit:RectChanged2, eax
        jmp     .finish


.left:
        exec    esi, TAsmEdit:CaretLeftRight, -1, ecx
        jmp     .endselect


.right:
        exec    esi, TAsmEdit:CaretLeftRight, 1, ecx
        jmp     .endselect

.up:
        exec    esi, TAsmEdit:CaretUpDown, -1, FALSE, ecx
        jmp     .endselect


.down:
        exec    esi, TAsmEdit:CaretUpDown, 1, FALSE, ecx
        jmp     .endselect

.homekey:
        test    [.kbdState], maskCtrl
        jnz     .start_of_scr

        exec    esi, TAsmEdit:CaretHome, ecx
        jmp     .endselect

.start_of_scr:
        exec    esi, TAsmEdit:CaretScrHome, ecx
        jmp     .endselect


.endkey:
        test    [.kbdState], maskCtrl
        jnz     .end_of_scr

        exec    esi, TAsmEdit:CaretEnd, ecx
        jmp     .endselect

.end_of_scr:
        exec    esi, TAsmEdit:CaretScrEnd, ecx
        jmp     .endselect



.pgupkey:
        test    [.kbdState], maskCtrl
        jnz     .start_of_text

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

        exec    esi, TAsmEdit:CaretUpDown, eax, TRUE, ecx
        jmp     .endselect

.start_of_text:
        exec    esi, TAsmEdit:CaretTxtHome, ecx
        jmp     .endselect


.pgdnkey:
        test    [.kbdState], maskCtrl
        jnz     .end_of_text

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

        exec    esi, TAsmEdit:CaretUpDown, eax, TRUE, ecx
        jmp     .endselect

.end_of_text:
        exec    esi, TAsmEdit:CaretTxtEnd, ecx
        jmp     .endselect


.insertkey:
        get     eax, esi, TAsmEdit:Options

        mov     edx, aeoOverwriteMode
................................................................................
        jmp     .endmove

.delkey:
        exec    esi, TAsmEdit:DeleteSelection
        jmp     .endmove

.endselect:




        mov     [esi+TAsmEdit._selCmd], ecx

.endmove:

.finish:
        popad
        return
endp



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

        stdcall BlendImage, [.pDstImage], ecx, edx, [esi+TAsmEdit._imgText], eax, [.rect_txt.top], ebx, edi

.text_ok:

; Here, draw the selection if any.

        stdcall CreateArray, sizeof.RECT
        push    eax

        exec    esi, TAsmEdit:_AddSelRectangles, eax
        mov     ecx, [edx+TArray.count]
        test    ecx, ecx
        jz      .selection_ok

        mov     eax, [.xSrc]
        mov     ebx, [.ySrc]
        mov     [.rect_dst.left], eax
................................................................................


method TAsmEdit.GetSelection
.lines dd ?
begin
        pushad

        stdcall CreateArray, sizeof.RECT
        exec    [.self], TAsmEdit:_AddSelRectanglesAbs, eax
        mov     [.lines], edx

        lea     edi, [edx+TArray.array]
        mov     ecx, [edx+TArray.count]

        stdcall StrNew
        mov     edx, eax
................................................................................
        xor     ebx, ebx
        test    [esi+TAsmEdit._options], aeoNavXCaretWrap
        jz      .set_pos

        cmp     [esi+TAsmEdit._caretPos.y], ebx
        je      .finish

        exec    esi, TAsmEdit:CaretUpDown, -1, FALSE, [.cmdSelect]
        exec    esi, TAsmEdit:CaretEnd, [.cmdSelect]
        jmp     .finish

.leftok:
        test    [esi+TAsmEdit._options], aeoNavXCaretWrap
        jz      .set_pos

        exec    esi, TAsmEdit:TextLine, [esi+TAsmEdit._caretPos.y]
        cmovc   ebx, edx
        jc      .set_pos

        cmp     ebx, [eax+TTextLine.length]
        jbe     .set_pos

        exec    esi, TAsmEdit:CaretUpDown, 1, FALSE, [.cmdSelect]
        exec    esi, TAsmEdit:CaretHome, [.cmdSelect]
        jmp     .finish

.set_pos:


        exec    esi, TAsmEdit:SetCaretXY, ebx, caretAxisX, [.cmdSelect]
        exec    esi, TAsmEdit:ScrollToCaretX

.finish:
        popad
        return
endp

................................................................................
        add     eax, 2
        sub     eax, [esi+TAsmEdit._height_ch]
        cmovs   eax, edx

        cmp     ecx, eax
        cmova   ecx, eax

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

        cmp     [.scroll], edx
        je      .scroll_ok

        set     esi, TAsmEdit:PosY, ecx
        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos
................................................................................
endp




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


        exec    [.self], TAsmEdit:ScrollToCaretX

        return
endp


method TAsmEdit.CaretEnd
begin
        push    esi
................................................................................

        exec    esi, TAsmEdit:TextLine, [esi+TAsmEdit._caretPos.y]      ; returns CF=1 and eax=0 on error.
        jc      .set_pos

        mov     eax, [eax+TTextLine.length]

.set_pos:
        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisX, [.cmdSelect]
        exec    esi, TAsmEdit:ScrollToCaretX

.finish:
        pop     esi
        return
endp

................................................................................
begin
        push    esi

        mov     esi, [.self]

        get     eax, esi, TAsmEdit:PosY

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisY, [.cmdSelect]
        exec    esi, TAsmEdit:UpdateCaretPos

        pop     esi
        return
endp


................................................................................
        mov     eax, [esi+TAsmEdit._height]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]
        add     eax, [esi+TAsmEdit._scrolly.pos]
        dec     eax
        js      .finish

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisY, [.cmdSelect]
        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        pop     edx esi
        return
endp



method TAsmEdit.CaretTxtHome
begin
        exec    [.self], TAsmEdit:SetCaretXY, 0, caretAxisY, [.cmdSelect]


        exec    [.self], TAsmEdit:ScrollToCaretY

        return
endp


method TAsmEdit.CaretTxtEnd
begin
        push    esi

        mov     esi, [.self]
        mov     eax, [esi+TAsmEdit._lines]
        mov     eax, [eax+TText.TextLen]
        shr     eax, 2

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisY, [.cmdSelect]
        exec    esi, TAsmEdit:ScrollToCaretY

        pop     esi
        return
endp






























































































; Line handling and formatting methods.



; Undo/Redo methods

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

method TAsmEdit.DeleteSelection
.rect RECT
.list dd ?
begin
        pushad

        stdcall CreateArray, sizeof.RECT
        exec    [.self], TAsmEdit:_AddSelRectanglesAbs, eax

        mov     [.list], edx

        lea     edi, [edx+TArray.array]
        mov     ecx, [edx+TArray.count]

        mov     edx, [.self]
        mov     edx, [edx+TAsmEdit._line_widths]

.rect_loop:
................................................................................
        cmovg   eax, ecx

        get     edx, esi, TAsmEdit:SelStartY
        get     ecx, esi, TAsmEdit:SelEndY
        cmp     edx, ecx
        cmovg   edx, ecx

        exec    esi, TAsmEdit:SetCaretXY, eax, caretAxisX, FALSE
        exec    esi, TAsmEdit:SetCaretXY, edx, caretAxisY, FALSE

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

        mov     [.rect.left], eax
        mov     [.rect.top], eax







<
<
<
<
<
<
<
<
<
<







 







>

|
>







 







<
<







 







|
|

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







 







>
>








|
|
<







>
>

|



>







 







>
>










|
|
>







>
>
>

|
|







 







>
>
>
>
>
>







 







>
>
>
>
>
>







 







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







 







>





|
<
<
<
<
<

|
|
<
>

<
<
<
<
<
<
<
<
<
<
<
>











>
>
>







 







|




|



|




|






|



|







|



|













|



|











|



|







 







>

>
>
|

<
<







 







|
|

<







 







<
|







 







|
|













|
|



>

<







 







|







 







|
>
>
|
>







 







|







 







|







 







|











|
>
>
|
>













|






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







 







<
|
<

>







 







|
|







33
34
35
36
37
38
39










40
41
42
43
44
45
46
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
162
163
164
165
166
167
168


169
170
171
172
173
174
175
...
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
...
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
...
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
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
...
716
717
718
719
720
721
722



































































































723
724
725
726
727
728
729
...
834
835
836
837
838
839
840
841
842
843
844
845
846
847





848
849
850

851
852











853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
....
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
....
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111


1112
1113
1114
1115
1116
1117
1118
....
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820

1821
1822
1823
1824
1825
1826
1827
....
2224
2225
2226
2227
2228
2229
2230

2231
2232
2233
2234
2235
2236
2237
2238
....
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741

2742
2743
2744
2745
2746
2747
2748
....
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
....
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
....
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
....
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
....
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
....
3219
3220
3221
3222
3223
3224
3225

3226

3227
3228
3229
3230
3231
3232
3233
3234
3235
....
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
aeoAutoBrackets        = $080000
aeoSmartTabs           = $100000
aeoPersistentSelection = $200000

aeoDefault = aeoLeftMargin or aeoLineNumbers or aeoConsoleCaret or aeoAutoIndents or aeoSmartTabs












; Operations for undo/redo:

chopInserted = 0
chopDeleted  = 1
chopChanged  = 2

struct TUndoInfo
................................................................................

  ._wrap_width    dd    ?       ; the word wrap width for the word wrapped lines.

  ._caretPos      POINT

  ._selStart      POINT         ; The selection start point
  ._selEnd        POINT         ;
  ._selAreaUpdate dd ?

  ._selCmd        dd    ?       ; ==0 if the shift key wasn't pressed on the last keyboard interaction.
  ._selCmdPrev    dd    ?       ; the previous value of the _selCmd field.

  ._drag_button   dd    ?

  ._scrollx       TScroller
  ._scrolly       TScroller

  ._width_ch      dd    ?       ; width and
................................................................................

  method  .GetText
  method  .SetText, .value

  method  .ComputeLeftMarginWidth
  method  .ComputeScreenInChars



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

  method  ._AddSelRectangles, .pRectList
  method  ._AddSelRectanglesAbs, .pRectList


................................................................................
; Text navigarion methods

  method .TextLine, .y

  method .ScrollToCaretX
  method .ScrollToCaretY

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

  method .CaretHome
  method .CaretEnd
  method .CaretScrHome
  method .CaretScrEnd
  method .CaretTxtHome
  method .CaretTxtEnd

; Selection control methods.

  method .SelStartHere
  method .SelEndHere

  method .SelChangeBegin
  method .SelChangeEnd


; undo/redo

  method .SaveForUndo, .LineNum, .operation
  method .Undo
  method .Redo

................................................................................
        pushad
        mov     esi, [.self]
        cmp     [esi+TAsmEdit._drag_button], mbLeft
        jne     .finish

        xor     ecx, ecx

        exec    esi, TAsmEdit:SelChangeBegin

        mov     eax, [.x]
        sub     eax, [esi+TAsmEdit._left_margin]
        cdq
        idiv    [esi+TAsmEdit._font_width]

        get     ebx, esi, TAsmEdit:PosX
        add     eax, ebx
        cmovs   eax, ecx
        mov     [esi+TAsmEdit._caretPos.x], eax
        mov     [esi+TAsmEdit._selEnd.x], eax


        mov     eax, [.y]
        cdq
        idiv    [esi+TAsmEdit._font_height]
        get     ebx, esi, TAsmEdit:PosY
        add     eax, ebx
        cmovs   eax, ecx
        mov     [esi+TAsmEdit._caretPos.y], eax
        mov     [esi+TAsmEdit._selEnd.y], eax

        exec    esi, TAsmEdit:ScrollToCaretX
        exec    esi, TAsmEdit:ScrollToCaretY

        exec    esi, TAsmEdit:UpdateCaretPos
        exec    esi, TAsmEdit:SelChangeEnd

.finish:
        popad
        return
endp


................................................................................
        mov     [esi+TAsmEdit._drag_button], eax

        stdcall SetMouseCapture, esi

        cmp     eax, mbLeft
        jne     .finish

        exec    esi, TAsmEdit:SelChangeBegin

        xor     ecx, ecx

        mov     eax, [.x]
        sub     eax, [esi+TAsmEdit._left_margin]
        cdq
        idiv    [esi+TAsmEdit._font_width]

        get     ebx, esi, TAsmEdit:PosX
        add     eax, ebx
        cmovs   eax, ecx
        mov     [esi+TAsmEdit._caretPos.x], eax
        mov     [esi+TAsmEdit._selStart.x], eax
        mov     [esi+TAsmEdit._selEnd.x], eax

        mov     eax, [.y]
        cdq
        idiv    [esi+TAsmEdit._font_height]
        get     ebx, esi, TAsmEdit:PosY
        add     eax, ebx
        cmovs   eax, ecx
        mov     [esi+TAsmEdit._caretPos.y], eax
        mov     [esi+TAsmEdit._selStart.y], eax
        mov     [esi+TAsmEdit._selEnd.y], eax

        exec    esi, TAsmEdit:UpdateCaretPos
        exec    esi, TAsmEdit:SelChangeEnd

.finish:
        popad
        return
endp


................................................................................
        lea     edi, [.rect1]
        mov     ecx, sizeof.RECT * 3 / 4

        rep stosd

        mov     esi, [.self]
        mov     edx, [.pRectList]

        test    edx, edx
        jnz     .array_ok
        stdcall CreateArray, sizeof.RECT
        mov     edx, eax
.array_ok:

        mov     eax, [esi+TAsmEdit._selStart.x]
        mov     ecx, [esi+TAsmEdit._selStart.y]
        mov     ebx, [esi+TAsmEdit._selEnd.x]
        mov     edi, [esi+TAsmEdit._selEnd.y]

        test    [esi+TAsmEdit._options], aeoBlockSelection
................................................................................
        lea     edi, [.rect1]
        mov     ecx, sizeof.RECT * 4 / 4

        rep stosd

        mov     esi, [.self]
        mov     edx, [.pRectList]

        test    edx, edx
        jnz     .array_ok
        stdcall CreateArray, sizeof.RECT
        mov     edx, eax
.array_ok:

        mov     eax, [esi+TAsmEdit._width_ch]
        mov     ecx, [esi+TAsmEdit._height_ch]
        mov     [.client.right], eax
        mov     [.client.bottom], ecx

        mov     eax, [esi+TAsmEdit._selStart.x]
................................................................................

.finish:
        mov     [esp+4*regEDX], edx
        popad
        return
endp







































































































method TAsmEdit.SetPosX
.render RECT
begin
        pushad
................................................................................
        popad
        return
endp



method TAsmEdit.EventKeyPress
.selCmd dd ?
begin
        pushad

        mov     esi, [.self]

; Remember the selection command






        mov     ecx, [.kbdState]
        and     ecx, maskShift

        mov     [.selCmd], ecx












; check the keys

        mov     eax, [.utf8]

        test    eax, eax
        jz      .no_char

        cmp     eax, $20
        jb      .ctrl_char

        cmp     eax, $7f
        je      .no_char

; here handle usual typing!


        jmp     .finish


.ctrl_char:

        cmp     eax, 26         ; Ctrl+Z
................................................................................
        mov     [esi+TAsmEdit._img_txt_valid], eax
        mov     [esi+TAsmEdit._img_margin_valid], eax
        exec    esi, TAsmEdit:RectChanged2, eax
        jmp     .finish


.left:
        exec    esi, TAsmEdit:CaretLeftRight, -1
        jmp     .endselect


.right:
        exec    esi, TAsmEdit:CaretLeftRight, 1
        jmp     .endselect

.up:
        exec    esi, TAsmEdit:CaretUpDown, -1, FALSE
        jmp     .endselect


.down:
        exec    esi, TAsmEdit:CaretUpDown, 1, FALSE
        jmp     .endselect

.homekey:
        test    [.kbdState], maskCtrl
        jnz     .start_of_scr

        exec    esi, TAsmEdit:CaretHome
        jmp     .endselect

.start_of_scr:
        exec    esi, TAsmEdit:CaretScrHome
        jmp     .endselect


.endkey:
        test    [.kbdState], maskCtrl
        jnz     .end_of_scr

        exec    esi, TAsmEdit:CaretEnd
        jmp     .endselect

.end_of_scr:
        exec    esi, TAsmEdit:CaretScrEnd
        jmp     .endselect



.pgupkey:
        test    [.kbdState], maskCtrl
        jnz     .start_of_text

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

        exec    esi, TAsmEdit:CaretUpDown, eax, TRUE
        jmp     .endselect

.start_of_text:
        exec    esi, TAsmEdit:CaretTxtHome
        jmp     .endselect


.pgdnkey:
        test    [.kbdState], maskCtrl
        jnz     .end_of_text

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

        exec    esi, TAsmEdit:CaretUpDown, eax, TRUE
        jmp     .endselect

.end_of_text:
        exec    esi, TAsmEdit:CaretTxtEnd
        jmp     .endselect


.insertkey:
        get     eax, esi, TAsmEdit:Options

        mov     edx, aeoOverwriteMode
................................................................................
        jmp     .endmove

.delkey:
        exec    esi, TAsmEdit:DeleteSelection
        jmp     .endmove

.endselect:
.endmove:

        mov     ecx, [.selCmd]
        xchg    ecx, [esi+TAsmEdit._selCmd]
        mov     [esi+TAsmEdit._selCmdPrev], ecx



.finish:
        popad
        return
endp



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

        stdcall BlendImage, [.pDstImage], ecx, edx, [esi+TAsmEdit._imgText], eax, [.rect_txt.top], ebx, edi

.text_ok:

; Here, draw the selection if any.

        exec    esi, TAsmEdit:_AddSelRectangles, 0
        push    edx


        mov     ecx, [edx+TArray.count]
        test    ecx, ecx
        jz      .selection_ok

        mov     eax, [.xSrc]
        mov     ebx, [.ySrc]
        mov     [.rect_dst.left], eax
................................................................................


method TAsmEdit.GetSelection
.lines dd ?
begin
        pushad


        exec    [.self], TAsmEdit:_AddSelRectanglesAbs, 0
        mov     [.lines], edx

        lea     edi, [edx+TArray.array]
        mov     ecx, [edx+TArray.count]

        stdcall StrNew
        mov     edx, eax
................................................................................
        xor     ebx, ebx
        test    [esi+TAsmEdit._options], aeoNavXCaretWrap
        jz      .set_pos

        cmp     [esi+TAsmEdit._caretPos.y], ebx
        je      .finish

        exec    esi, TAsmEdit:CaretUpDown, -1, FALSE
        exec    esi, TAsmEdit:CaretEnd
        jmp     .finish

.leftok:
        test    [esi+TAsmEdit._options], aeoNavXCaretWrap
        jz      .set_pos

        exec    esi, TAsmEdit:TextLine, [esi+TAsmEdit._caretPos.y]
        cmovc   ebx, edx
        jc      .set_pos

        cmp     ebx, [eax+TTextLine.length]
        jbe     .set_pos

        exec    esi, TAsmEdit:CaretUpDown, 1, FALSE
        exec    esi, TAsmEdit:CaretHome
        jmp     .finish

.set_pos:
        mov     [esi+TAsmEdit._caretPos.x], ebx


        exec    esi, TAsmEdit:ScrollToCaretX

.finish:
        popad
        return
endp

................................................................................
        add     eax, 2
        sub     eax, [esi+TAsmEdit._height_ch]
        cmovs   eax, edx

        cmp     ecx, eax
        cmova   ecx, eax

        mov     [esi+TAsmEdit._caretPos.y], ebx

        cmp     [.scroll], edx
        je      .scroll_ok

        set     esi, TAsmEdit:PosY, ecx
        exec    esi, TAsmEdit:RectChanged2, edx
        exec    esi, TAsmEdit:UpdateCaretPos
................................................................................
endp




method TAsmEdit.CaretHome
begin
        push    eax
        mov     eax, [.self]
        and     [eax+TAsmEdit._caretPos.x], 0
        exec    eax, TAsmEdit:ScrollToCaretX
        pop     eax
        return
endp


method TAsmEdit.CaretEnd
begin
        push    esi
................................................................................

        exec    esi, TAsmEdit:TextLine, [esi+TAsmEdit._caretPos.y]      ; returns CF=1 and eax=0 on error.
        jc      .set_pos

        mov     eax, [eax+TTextLine.length]

.set_pos:
        mov     [esi+TAsmEdit._caretPos.x], eax
        exec    esi, TAsmEdit:ScrollToCaretX

.finish:
        pop     esi
        return
endp

................................................................................
begin
        push    esi

        mov     esi, [.self]

        get     eax, esi, TAsmEdit:PosY

        mov     [esi+TAsmEdit._caretPos.y], eax
        exec    esi, TAsmEdit:UpdateCaretPos

        pop     esi
        return
endp


................................................................................
        mov     eax, [esi+TAsmEdit._height]
        xor     edx, edx
        div     [esi+TAsmEdit._font_height]
        add     eax, [esi+TAsmEdit._scrolly.pos]
        dec     eax
        js      .finish

        mov     [esi+TAsmEdit._caretPos.y], eax
        exec    esi, TAsmEdit:UpdateCaretPos

.finish:
        pop     edx esi
        return
endp



method TAsmEdit.CaretTxtHome
begin
        push    eax
        mov     eax, [.self]
        and     [eax+TAsmEdit._caretPos.y], 0
        exec    eax, TAsmEdit:ScrollToCaretY
        pop     eax
        return
endp


method TAsmEdit.CaretTxtEnd
begin
        push    esi

        mov     esi, [.self]
        mov     eax, [esi+TAsmEdit._lines]
        mov     eax, [eax+TText.TextLen]
        shr     eax, 2

        mov     [esi+TAsmEdit._caretPos.y], eax
        exec    esi, TAsmEdit:ScrollToCaretY

        pop     esi
        return
endp


; Selection control methods


method TAsmEdit.SelStartHere
begin


        return
endp



method TAsmEdit.SelEndHere
begin


        return
endp


method TAsmEdit.SelChangeBegin
begin
        pushad
        mov     esi, [.self]
        xor     edx, edx
        xchg    edx, [esi+TAsmEdit._selAreaUpdate]
        test    edx, edx
        jz      .old_ok

        stdcall FreeMem, edx
        xor     edx, edx

.old_ok:
        exec    esi, TAsmEdit:_AddSelRectangles, edx
        mov     [esi+TAsmEdit._selAreaUpdate], edx

        popad
        return
endp


method TAsmEdit.SelChangeEnd
begin
        pushad
        mov     esi, [.self]
        mov     edx, [esi+TAsmEdit._selAreaUpdate]

        exec    esi, TAsmEdit:_AddSelRectangles, edx
        mov     ecx, [edx+TArray.count]
        lea     edi, [edx+TArray.array]

.loop:
        dec     ecx
        js      .freelist

        mov     eax, [edi+RECT.left]
        mov     ebx, [edi+RECT.top]

        imul    eax, [esi+TAsmEdit._font_width]
        imul    ebx, [esi+TAsmEdit._font_height]

        add     eax, [esi+TAsmEdit._left_margin]

        mov     [edi+RECT.left], eax
        mov     [edi+RECT.top], ebx

        mov     eax, [edi+RECT.right]
        mov     ebx, [edi+RECT.bottom]

        imul    eax, [esi+TAsmEdit._font_width]
        imul    ebx, [esi+TAsmEdit._font_height]

        add     eax, [esi+TAsmEdit._left_margin]

        mov     [edi+RECT.right], eax
        mov     [edi+RECT.bottom], ebx

        exec    esi, TAsmEdit:RectChanged2, edi

        add     edi, sizeof.RECT
        jmp     .loop

.freelist:
        stdcall FreeMem, edx
        xor     edx, edx
        mov     [esi+TAsmEdit._selAreaUpdate], edx

        popad
        return
endp


; Line handling and formatting methods.



; Undo/Redo methods

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

method TAsmEdit.DeleteSelection
.rect RECT
.list dd ?
begin
        pushad


        exec    [.self], TAsmEdit:_AddSelRectanglesAbs, 0

        mov     [.list], edx

        lea     edi, [edx+TArray.array]
        mov     ecx, [edx+TArray.count]

        mov     edx, [.self]
        mov     edx, [edx+TAsmEdit._line_widths]

.rect_loop:
................................................................................
        cmovg   eax, ecx

        get     edx, esi, TAsmEdit:SelStartY
        get     ecx, esi, TAsmEdit:SelEndY
        cmp     edx, ecx
        cmovg   edx, ecx

        mov     [esi+TAsmEdit._caretPos.x], eax
        mov     [esi+TAsmEdit._caretPos.y], edx

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

        mov     [.rect.left], eax
        mov     [.rect.top], eax