Subversion Repositories Kolibri OS

Rev

Rev 1459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1457 IgorA 1
; макрос для системной библиотеки box_lib.obj
2
; элемент TextEditor для Kolibri OS
1464 IgorA 3
; файл последний раз изменялся 17.05.2010 IgorA
1457 IgorA 4
; на код применена GPL2 лицензия
5
 
6
;input:
7
; edi = pointer to tedit struct
8
; reg = index
9
;output:
10
; reg = pointer to 'tex' struct
11
macro ConvertIndexToPointer reg {
12
  imul reg,sizeof.symbol
13
  add reg,ted_tex
14
}
15
 
16
;--- out_reg = ted_key_words_data[ind_reg].Text[0] ---
17
macro ColToIndexOffset ind_reg,out_reg {
18
	mov out_reg,ind_reg
19
	imul out_reg,sizeof.TexColViv
20
	add out_reg,ted_key_words_data
21
}
22
 
23
macro use_text_edit
24
{
25
TED_PANEL_NULL	 equ 0 ;нет открытой панели
26
TED_PANEL_FIND	 equ 1 ;панель поиска
27
TED_PANEL_SYNTAX equ 2 ;панель выбора файлов подсветки
28
TED_PANEL_WIDTH  equ 150 ;ширина панели
29
 
30
MAX_COLOR_WORD_LEN equ 40
31
;------------------------------------------------------------------------------
32
struct TexSelect
33
  x0 dd ?
34
  y0 dd ?
35
  x1 dd ?
36
  y1 dd ?
37
ends
38
 
39
struct TexColViv
40
  Text rb MAX_COLOR_WORD_LEN ; слово для подсветки
41
  f1 dd 0 ; справка по слову
42
  wwo db ? ; whole words only
43
  endc db ? ; символ конца выделения (wwo&4)
44
  color db ? ; номер цвета
45
ends
46
 
47
struct symbol
48
  c db ?    ;  +0 символ
49
  col db ?  ;  +1 цвет
50
  perv dd ? ;  +2
51
  next dd ? ;  +6 указатели
52
  tc dd ?   ; +10 врем. создания
53
  td dd ?   ; +14 врем. удаления
54
ends
55
;------------------------------------------------------------------------------
56
 
1464 IgorA 57
ted_symbol_tab db 26 ;ascii код стрелки вправо, используется для рисования табуляции в режиме показа невидимых символов
1458 IgorA 58
 
1457 IgorA 59
if lang eq ru
60
 
61
txtFindCapt db 'Поиск',0
62
txtFindNext db 'Найти далее',0
63
txtFormatCapt db 'Формат',0
64
txtFormatApply db 'Применить',0
65
txtRow db 'Строка',0
66
txtCol db 'Знак',0
67
txtOtm db 'Отмены',0
68
txtBuf db 'Буфер:',0
69
 
70
else
71
 
72
txtFindCapt db 'Search',0
73
txtFindNext db 'Find next',0
74
txtFormatCapt db 'Format',0
75
txtFormatApply db 'Apply',0
76
txtRow db 'Rows',0
77
txtCol db 'Cols',0
78
txtOtm db 'Undo',0
79
txtBuf db 'Buffer:',0
80
 
81
end if
82
 
1464 IgorA 83
;EvChar - таблица для фильтрования добавляемых символов, что-бы не попали лишние знаки
1457 IgorA 84
align 4
1458 IgorA 85
EvChar db 0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0
1457 IgorA 86
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
87
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
88
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
89
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
90
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
91
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
92
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
93
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
94
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
95
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
96
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
97
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
98
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
99
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
100
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1464 IgorA 101
;EvUpper - таблица для преобразования символов к верхнему регистру
1457 IgorA 102
EvUpper db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
103
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
104
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
105
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
106
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
107
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
108
    db 0,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79
109
    db 80,81,82,83,84,85,86,87,88,89,90,0,0,0,0,0
110
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
111
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
112
    db 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143
113
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
114
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
115
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1464 IgorA 116
    db 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159
117
    db 0,240,0,242,0,244,0,246,0,0,0,0,0,0,0,0
118
;EvLover - таблица для преобразования символов к нижнему регистру
1457 IgorA 119
EvLover db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
120
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
121
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
122
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
123
    db 0,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
124
    db 112,113,114,115,116,117,118,119,120,121,122,0,0,0,0,0
125
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
126
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
127
    db 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175
1464 IgorA 128
    db 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239
1457 IgorA 129
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
130
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
131
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
132
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
133
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1464 IgorA 134
    db 241,0,243,0,245,0,247,0,0,0,0,0,0,0,0,0
1457 IgorA 135
conv_table dd 0
136
 
137
 
138
KM_SHIFT equ 0x00010000
139
KM_CTRL equ 0x00020000
140
KM_ALT equ 0x00040000
141
KM_NUMLOCK equ 0x00080000
142
 
143
; KEY CODES
144
KEY_F1 equ 0x0000003B
145
KEY_F2 equ 0x0000003C
146
KEY_F3 equ 0x0000003D
147
 
148
 
149
 
150
align 4
151
proc ted_init, edit:dword
1458 IgorA 152
	push eax ecx edi
153
	mov edi,dword[edit]
1457 IgorA 154
 
1458 IgorA 155
	mov ecx,sizeof.symbol
156
	imul ecx,ted_max_chars
157
	call mem_Alloc ;выделяем память
158
	mov ted_tex,eax
159
	mov ted_tex_1,eax
160
	add ted_tex_1,sizeof.symbol
161
	add eax,ecx
162
	mov ted_tex_end,eax
1457 IgorA 163
 
1458 IgorA 164
	stdcall ted_clear, edi,1
1457 IgorA 165
 
166
;-------------------------------------------------
1458 IgorA 167
	mov ecx,1024 ;1024 - для массива ted_arr_key_pos
168
	add ecx,ted_syntax_file_size
169
	call mem_Alloc
170
	mov ted_arr_key_pos,eax
171
	add eax,1024
172
	mov ted_syntax_file,eax
1457 IgorA 173
 
1458 IgorA 174
	stdcall ted_init_scroll_bars,edi,3
175
	pop edi ecx eax
176
	ret
1457 IgorA 177
endp
178
 
1458 IgorA 179
MIN_W_SCRL_ARE equ 3 ;минимальная отображаемая область для верт. скроллинга
180
MIN_H_SCRL_ARE equ 3 ;минимальная отображаемая область для гориз. скроллинга
181
;input:
1459 IgorA 182
; opt = 1 - менять цвет скроллингов, 2 - изменились размеры окна,
183
;  4 - изменились размеры документа
1457 IgorA 184
align 4
1458 IgorA 185
proc ted_init_scroll_bars, edit:dword, opt:dword
186
	pushad
1459 IgorA 187
	mov edi,dword[edit]
1458 IgorA 188
	mov esi,ted_scr_w
189
	mov ebx,ted_scr_h
190
	bt dword[opt],0
191
	jae @f
192
		mov ecx,ted_color_wnd_work
193
		mov dword[esi+sb_offs_bckg_col],ecx
194
		mov dword[ebx+sb_offs_bckg_col],ecx
195
		mov ecx,ted_color_wnd_capt
196
		mov dword[esi+sb_offs_frnt_col],ecx
197
		mov dword[ebx+sb_offs_frnt_col],ecx
198
		mov ecx,ted_color_wnd_bord
199
		mov dword[esi+sb_offs_line_col],ecx
200
		mov dword[ebx+sb_offs_line_col],ecx
201
	@@:
1459 IgorA 202
	bt dword[opt],2 ; изменились размеры документа ?
203
	jae .doc_resize
204
		call ted_get_num_lines
205
		cmp eax,100
206
		jge @f
207
			mov eax,100
208
		@@:
209
		mov dword[esi+sb_offs_max_area],eax
210
	.doc_resize:
211
	bt dword[opt],1 ; изменились размеры окна ?
1458 IgorA 212
	jae .no_size
213
			mov edx,ted_wnd_l
214
			add edx,ted_rec_l
215
			mov word[ebx+sb_offs_start_x],dx ;выставляем левый отступ гориз. скроллинга
216
		mov eax,ted_wnd_h ;calculate lines in page
217
			mov edx,ted_wnd_t
218
			add edx,eax
219
			mov word[ebx+sb_offs_start_y],dx ;выставляем верхний отступ гориз. скроллинга
220
		sub eax,ted_rec_t
221
		xor edx,edx
222
		mov ecx,ted_rec_h
223
		div ecx
224
		cmp eax,MIN_W_SCRL_ARE
225
		jg @f
226
			mov eax,MIN_W_SCRL_ARE
227
		@@:
228
		mov dword[esi+sb_offs_cur_area],eax
229
 
230
		mov eax,ted_wnd_w ;calculate cols in page
231
			mov edx,ted_wnd_l ;левый отступ окна
232
			add edx,eax ;добавляем ширину окна
233
			mov word[esi+sb_offs_start_x],dx ;выставляем левый отступ верт. скроллинга
234
			mov edx,ted_wnd_t
235
			mov word[esi+sb_offs_start_y],dx ;выставляем верхний отступ верт. скроллинга
236
			mov edx,ted_wnd_h
237
			mov word[esi+sb_offs_size_y],dx ;выставляем высоту верт. скроллинга
238
		sub eax,ted_rec_l
239
			mov word[ebx+sb_offs_size_x],ax ;выставляем ширину гориз. скроллинга
240
		xor edx,edx
241
		mov ecx,ted_rec_w
242
		div ecx
243
		cmp eax,MIN_H_SCRL_ARE
244
		jg @f
245
			mov eax,MIN_H_SCRL_ARE
246
		@@:
247
		dec eax
248
		mov dword[ebx+sb_offs_cur_area],eax ;устанавливаем число символов, которые влазят в экран для гориз. скроллинга
249
	.no_size:
250
	popad
251
	ret
252
endp
253
 
254
align 4
1457 IgorA 255
proc ted_delete, edit:dword
1464 IgorA 256
	push edi
257
	mov edi,dword[edit]
258
	stdcall mem_Free,ted_tex
259
	stdcall mem_Free,ted_arr_key_pos ;ted_syntax_file
260
	pop edi
261
	ret
1457 IgorA 262
endp
263
 
264
 
265
;input:
266
; eax = key kodes
267
align 4
268
proc ted_key, edit:dword, table:dword, control:dword
269
	pushad
270
	mov edi,dword[edit]
1458 IgorA 271
	mov esi,ted_el_focus
272
	cmp dword[esi],edi
273
	jne .end_key_fun ;элемент не в фокусе выходим из функции
1457 IgorA 274
	mov esi,dword[control]
275
 
276
	cmp ah,KEY_F1 ;[F1]
277
	jne @f
278
		stdcall ted_show_help_f1,edi
279
		jmp .end_key_fun
280
	@@:
281
	cmp ah,KEY_F3 ;[F3]
282
	jne @f
283
		stdcall ted_but_find_next,edi
284
		jmp .end_key_fun
285
	@@:
286
 
287
	test esi,KM_CTRL ;Ctrl+...
288
	jz .key_Ctrl
289
		cmp ah,24 ;Ctrl+O
290
		jne @f
291
			cmp ted_fun_on_key_ctrl_o,0
292
			je @f
293
				call ted_fun_on_key_ctrl_o
294
		@@:
1458 IgorA 295
		cmp ah,31 ;Ctrl+S
296
		jne @f
297
			cmp ted_fun_on_key_ctrl_s,0
298
			je @f
299
				call ted_fun_on_key_ctrl_s
300
		@@:
1457 IgorA 301
		cmp ah,33 ;Ctrl+F
302
		jne @f
303
		cmp ted_panel_id,TED_PANEL_FIND
304
		je @f
305
			cmp ted_fun_on_key_ctrl_f,0
306
			je @f
307
				call ted_fun_on_key_ctrl_f
308
		@@:
309
		cmp ah,44 ;Ctrl+Z
310
		jne @f
311
			stdcall ted_but_undo,edi
312
		@@:
313
		cmp ah,46 ;Ctrl+C
314
		jne @f
315
			stdcall ted_but_copy,edi
316
		@@:
317
		cmp ah,47 ;Ctrl+V
318
		jne @f
319
			stdcall ted_but_paste,edi
320
		@@:
321
		cmp ah,49 ;Ctrl+N
322
		jne @f
323
			cmp ted_fun_on_key_ctrl_n,0
324
			je @f
325
				call ted_fun_on_key_ctrl_n
326
		@@:
327
		cmp ah,199 ;Ctrl+Home
328
		jne @f
329
			call ted_key_ctrl_home
330
		@@:
331
		jmp .end_key_fun
332
	.key_Ctrl:
333
 
1458 IgorA 334
	test esi,KM_SHIFT ;Shift+...
335
	jz .key_Shift
336
		cmp ah,72 ;Shift+Up
337
		jne @f
338
			call ted_sel_key_up
339
		@@:
340
		cmp ah,75 ;Shift+Left
341
		jne @f
342
			call ted_sel_key_left
343
		@@:
344
		cmp ah,77 ;Shift+Right
345
		jne @f
346
			call ted_sel_key_right
347
		@@:
348
		cmp ah,80 ;Shift+Down
349
		jne @f
350
			call ted_sel_key_down
351
		@@:
352
		;mov ted_drag_k,1 ;начинаем выделение от клавиатуры
353
		jmp .key_MoveCur
354
	.key_Shift:
1457 IgorA 355
;-------------------------------------------------
1458 IgorA 356
	cmp ah,72 ;178 ;Up
357
	jne @f
358
		call ted_draw_cursor_sumb
359
		call ted_cur_move_up
360
		cmp dl,8
361
		jne .no_red_0
362
			call ted_scroll_set_redraw
363
			stdcall ted_draw,edi
364
			jmp @f
365
		.no_red_0:
366
		call ted_draw_main_cursor
367
		mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
368
	@@:
1464 IgorA 369
	cmp ah,80 ;177 ;Down
370
	jne @f
371
		call ted_draw_cursor_sumb
372
		call ted_cur_move_down
373
		cmp dl,8
374
		jne .no_red_1
375
			call ted_scroll_set_redraw
376
			stdcall ted_draw,edi
377
			jmp @f
378
		.no_red_1:
379
		call ted_draw_main_cursor
380
		mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
381
	@@:
1457 IgorA 382
  cmp ah,75 ;176 ;Left
383
  jne @f
384
    call ted_draw_cursor_sumb
385
    call ted_cur_move_left
386
    cmp dl,8
387
    jne .no_red_2
388
      call ted_scroll_set_redraw
389
      stdcall ted_draw,edi
390
      jmp @f
391
    .no_red_2:
392
    call ted_draw_main_cursor
393
    mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
394
  @@:
395
  cmp ah,77 ;179 ;Right
396
  jne @f
397
    call ted_draw_cursor_sumb
398
    call ted_cur_move_right
399
    cmp dl,8
400
    jne .no_red_3
401
      call ted_scroll_set_redraw
402
      stdcall ted_draw,edi
403
      jmp @f
404
    .no_red_3:
405
    call ted_draw_main_cursor
406
    mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
407
  @@:
408
  cmp ah,71 ;180 ;Home
409
  jne @f
410
    call ted_draw_cursor_sumb
411
    call ted_cur_move_x_first_char
412
    cmp dl,8
413
    jne .no_red_4
414
      call ted_scroll_set_redraw
415
      stdcall ted_draw,edi
416
      jmp @f
417
    .no_red_4:
418
    call ted_draw_main_cursor
419
    mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
420
  @@:
421
  cmp ah,79 ;181 ;End
422
  jne @f
423
    call ted_draw_cursor_sumb
424
    call ted_cur_move_x_last_char
425
    cmp dl,8
426
    jne .no_red_5
427
      call ted_scroll_set_redraw
428
      stdcall ted_draw,edi
429
      jmp @f
430
    .no_red_5:
431
    call ted_draw_main_cursor
432
    mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
433
  @@:
434
  cmp ah,73 ;184 ;PageUp
435
  jne @f
436
    call ted_cur_move_page_up
437
    cmp dl,0
438
    je @f
439
    call ted_scroll_set_redraw
440
    stdcall ted_draw,edi
441
  @@:
442
  cmp ah,81 ;183 ;PageDown
443
  jne @f
444
    call ted_cur_move_page_down
445
    cmp dl,0
446
    je @f
447
    call ted_scroll_set_redraw
448
    stdcall ted_draw,edi
449
    mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
450
  @@:
451
;-------------------------------------------------
1458 IgorA 452
;       cmp esi,0
453
;       jne .end_key_fun
1457 IgorA 454
	.key_MoveCur:
455
 
456
	cmp ah,69 ;[Pause Break]
457
	je .end_key_fun
458
	cmp ah,120 ;[Fn]
459
	je .end_key_fun
460
	cmp ah,0x80 ;if key up
461
	ja .end_key_fun
462
 
463
	cmp dword[table],0
464
	je @f
465
		stdcall KeyConvertToASCII, dword[table]
466
	@@:
467
 
468
	;mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
469
 
470
	lea edx,[EvChar] ;берем адрес таблицы с допустимыми символами
471
	add dl,ah
472
	jae @f
473
		add edx,0x100 ;если было переполнение при добавлении кода символа
474
	@@:
475
	cmp byte [edx],1
476
	jne @f
477
		mov ted_key_new,ah
478
		call ted_set_undo
479
		mov edx,ted_opt_ed_change_time+ted_opt_ed_move_cursor
480
		stdcall ted_sel_text_del,edx
481
		cmp al,1
482
		jne .del
483
			mov edx,ted_opt_ed_move_cursor
484
		.del:
485
		cmp ted_cur_ins,1
486
		je .no_ins_mod
487
			stdcall ted_text_del,edi,ted_opt_ed_change_time
488
			mov edx,ted_opt_ed_move_cursor
489
		.no_ins_mod:
490
		mov ecx,edi
491
		add ecx,ted_offs_key_new
492
		stdcall ted_text_add,edi,ecx,1,edx ;добавляем символ введенный с клавиатуры
493
		cmp ted_key_new,13
494
		jne .dr_m_win
495
			stdcall ted_draw,edi
496
			jmp .dr_cur_l
497
		.dr_m_win:
498
			stdcall ted_draw_cur_line,edi
499
		.dr_cur_l:
500
		cmp ted_fun_draw_panel_buttons,0
501
		je @f
502
			call ted_fun_draw_panel_buttons
503
	@@:
504
 
505
	cmp ah,8 ;[<-]
506
	jne @f
507
		call ted_set_undo
508
		stdcall ted_sel_text_del,ted_opt_ed_change_time
509
		cmp al,1
510
		je .del_one_b
511
			stdcall ted_text_del,edi,ted_opt_ed_change_time+ted_opt_ed_move_cursor
512
		.del_one_b:
513
		stdcall ted_draw,edi
514
		cmp ted_fun_draw_panel_buttons,0
515
		je .end_key_fun
516
			call ted_fun_draw_panel_buttons
517
		jmp .end_key_fun
518
	@@:
519
 
520
	cmp ah,182 ;Delete
521
	jne @f
522
		call ted_set_undo
523
		stdcall ted_sel_text_del,ted_opt_ed_change_time
524
		cmp al,1
525
		je .del_one_d
526
			stdcall ted_text_del,edi,ted_opt_ed_change_time
527
		.del_one_d:
528
		stdcall ted_draw,edi
529
		cmp ted_fun_draw_panel_buttons,0
530
		je .end_key_fun
531
			call ted_fun_draw_panel_buttons
532
		jmp .end_key_fun
533
	@@:
534
 
535
	cmp ah,185 ;Ins
536
	jne @f
537
		call ted_draw_cursor_sumb
538
		xor ted_cur_ins,1
539
		call ted_draw_main_cursor
540
	@@:
541
 
542
	.end_key_fun:
543
	popad
544
	ret
545
endp
546
 
547
;output:
548
; al = 1 - can save
549
align 4
550
proc ted_can_save, edit:dword
551
	push ecx edi
552
	mov edi,dword[edit]
553
 
554
	mov ecx,ted_tim_ch
555
	sub ecx,ted_tim_undo
556
	mov al,1
557
	cmp ted_tim_ls,ecx
558
	jne @f
559
		dec al
560
	@@:
561
	pop edi ecx
562
	ret
563
endp
564
 
565
;input:
566
; edi = pointer to tedit struct
567
;output:
568
; al = 1 - selected
569
align 4
570
proc ted_is_select
571
  push ebx
572
  xor al,al
573
  cmp ted_drag_m,1
574
  je @f
575
    mov al,1
576
    mov ebx,ted_sel_x0
577
    cmp ebx,ted_sel_x1
578
    jne @f
579
    mov ebx,ted_sel_y0
580
    cmp ebx,ted_sel_y1
581
    jne @f
582
    xor al,al
583
  @@:
584
  pop ebx
585
  ret
586
endp
587
 
588
;input:
589
; edi = pointer to tedit struct
590
align 4
591
proc ted_sel_normalize
592
	push ecx esi
593
	push edi
594
		mov esi,edi
595
		add esi,ted_offs_sel
596
		add edi,ted_offs_seln
597
		mov ecx,sizeof.TexSelect
598
		rep movsb
599
	pop edi
600
 
601
	jmp @f
602
		.swp_f:
603
		mov ecx,ted_seln_x0
604
		m2m ted_seln_x0,ted_seln_x1
605
		mov ted_seln_x1,ecx
606
 
607
		mov ecx,ted_seln_y0
608
		cmp ecx,ted_seln_y1 ;(sel_y0>sel_y1)
609
		jle .end_f
610
		m2m ted_seln_y0,ted_seln_y1
611
		mov ted_seln_y1,ecx
612
 
613
		jmp .end_f
614
	@@:
615
 
616
	mov ecx,ted_seln_y0
617
	cmp ecx,ted_seln_y1 ;(sel_y0>sel_y1)
618
	jg .swp_f
619
 
620
	cmp ecx,ted_seln_y1 ;(sel_y0==sel_y1)
621
	jne .end_f
622
		mov ecx,ted_seln_x0
623
		cmp ecx,ted_seln_x1 ;(sel_x0>sel_x1)
624
		jg .swp_f
625
 
626
	.end_f:
627
	pop esi ecx
628
	ret
629
endp
630
 
631
;input:
632
; edi = pointer to tedit struct
633
;description:
634
; Функция вызываемая при начале выделения
635
align 4
636
proc ted_sel_start
637
	push eax ecx
638
		mov eax,ted_scr_h
639
		mov ecx,ted_cur_x
640
		add ecx,dword[eax+sb_offs_position]
641
		mov ted_sel_x0,ecx
642
		mov ted_sel_x1,ecx
643
 
644
		mov eax,ted_scr_w
645
		mov ecx,ted_cur_y
646
		add ecx,dword[eax+sb_offs_position]
647
		mov ted_sel_y0,ecx
648
		mov ted_sel_y1,ecx
649
	pop ecx eax
650
	ret
651
endp
652
 
653
;input:
654
; edi = pointer to tedit struct
655
;description:
656
; Функция вызываемая при перемещении выделения
657
align 4
658
proc ted_sel_move
659
	push eax ecx
660
		mov ecx,ted_cur_x
661
		mov eax,ted_scr_h
662
		add ecx,dword[eax+sb_offs_position]
663
		mov ted_sel_x1,ecx
664
 
665
		mov eax,ted_scr_w
666
		mov ecx,ted_cur_y
667
		add ecx,dword[eax+sb_offs_position]
668
		mov ted_sel_y1,ecx
669
	pop ecx eax
670
	cmp ted_fun_draw_panel_buttons,0 ;redraw toolbar (need to button Copy)
671
	je @f
672
		call ted_fun_draw_panel_buttons
673
	@@:
674
	ret
675
endp
676
 
677
;input:
678
; cl_al_mem = 1 - clear all memory
679
align 4
680
proc ted_clear, edit:dword, cl_al_mem:dword
1464 IgorA 681
	push ecx edi
682
	mov edi,dword[edit]
1457 IgorA 683
 
1464 IgorA 684
	mov ted_cur_x,0
685
	mov ted_cur_y,0
686
	mov ted_tim_ch,0
687
	mov ted_tim_ls,0
688
	mov ted_tim_co,0
689
	mov ted_tim_undo,0
690
	mov ted_help_id,-1
691
	mov ecx,sizeof.symbol
692
	shl ecx,1
693
	add ecx,ted_tex
694
	mov ted_ptr_free_symb,ecx
1457 IgorA 695
 
1464 IgorA 696
	mov ecx,ted_scr_w
697
	mov dword[ecx+sb_offs_position],0
698
	mov dword[ecx+sb_offs_max_area],100 ;число строк видимых в новом документе
699
	mov dword[ecx+sb_offs_redraw],1
700
	mov ecx,ted_scr_h
701
	mov dword[ecx+sb_offs_position],0
702
	mov dword[ecx+sb_offs_max_area],100 ;число символов видимых в новом документе
1457 IgorA 703
 
1464 IgorA 704
	mov ted_sel_x0,0
705
	mov ted_sel_y0,0
706
	mov ted_sel_x1,0
707
	mov ted_sel_y1,0
1457 IgorA 708
 
1464 IgorA 709
	cmp dword[cl_al_mem],0
710
	je .exit
1457 IgorA 711
 
1464 IgorA 712
	push edx
713
	mov ecx,sizeof.symbol
714
	imul ecx,ted_max_chars
715
	mov edx,ted_tex
716
	@@:
717
		mov byte [edx],0
718
		inc edx
719
	loop @b
720
	mov edx,ted_tex
721
	mov dword [edx+6],1
722
	pop edx
1457 IgorA 723
 
1464 IgorA 724
	.exit:
725
	pop edi ecx
726
	ret
1457 IgorA 727
endp
728
 
729
 
730
align 4
731
proc ted_init_syntax_file, edit:dword, file:dword, f_name:dword
732
	pushad
733
	mov edi,dword[edit]
734
 
735
	mov eax,70
736
	mov ebx,dword[file]
737
	mov dword[ebx], 0
738
	mov dword[ebx+4], 0
739
	mov dword[ebx+8], 0
740
	mov ecx,ted_syntax_file_size
741
	mov dword[ebx+12], ecx
742
	m2m dword[ebx+16], ted_syntax_file
743
	mov  byte[ebx+20], 0
744
	m2m dword[ebx+21], dword[f_name]
745
	int 0x40
746
 
747
	mov ecx,0x100
748
	mov edx,ted_arr_key_pos
749
	@@:
750
		mov dword[edx],-1
751
		add edx,4
752
	loop @b
753
 
754
	;init: ted_colors_text_count, ted_key_words_count, ...
755
	mov ted_colors_text_count,1
756
	mov ted_key_words_count,0
757
	mov ted_help_text_f1,0
758
	mov ted_help_id,-1 ;идентификатор слова для справки
759
 
760
	cmp eax,6
761
	je @f
762
	cmp eax,0
763
	je @f
764
		cmp ax,10
765
		jl .zifra_0_9
766
			mov al,'?'
767
			sub ax,48
768
		.zifra_0_9:
769
		add ax,48
770
		cmp ted_fun_init_synt_err,0
771
		je .no_colors
772
			call ted_fun_init_synt_err
773
			jmp .no_colors
774
	@@:
775
 
776
	mov eax,edi ;сохраняем значение edi
777
	mov esi,ted_syntax_file
778
	add edi,ted_offs_count_colors
779
	mov ecx,9*4
780
	rep movsb
781
	mov edi,eax ;востанавливаем значение edi
782
 
783
	mov eax,ted_syntax_file
784
	add eax,32
785
	mov ted_text_colors,eax
786
 
787
	mov eax,ted_colors_text_count ;init: count_colors_text (offset to key words)
788
	add eax,8
789
	shl eax,2
790
	add eax,ted_syntax_file
791
	mov ted_key_words_data,eax
792
 
793
	mov ecx,ted_key_words_count ;init: ted_arr_key_pos (first key positions)
794
	xor eax,eax
795
	@@:
796
		ColToIndexOffset eax,edx
797
		xor ebx,ebx
798
		mov bl,byte[edx]
799
		shl bx,2
800
		mov esi,ted_arr_key_pos
801
		add esi,ebx
802
		cmp dword[esi],-1
803
		jne .no_ch_key
804
			mov dword[esi],eax
805
		.no_ch_key:
806
		inc eax
807
	loop @b
808
 
809
	;init: ted_help_text_f1
810
	mov ecx,ted_key_words_count
811
	imul ecx,sizeof.TexColViv
812
	add ecx,ted_key_words_data
813
	mov ted_help_text_f1,ecx
814
 
1458 IgorA 815
	stdcall ted_init_scroll_bars,edi,1 ;меняем цвета скроллингов
1457 IgorA 816
	.no_colors:
817
	popad
818
	ret
819
endp
820
 
821
;input:
822
; ebx = file size
823
; edi = pointer to tedit struct
824
;description:
825
; Функция вызывается при открытии файла
826
align 4
827
proc ted_on_open_file
828
	push eax ;destination
829
	push ecx ;for cycle
830
	push edx ;source
831
	push esi
832
 
833
	stdcall ted_clear,edi,0 ;чистим не всю память, потому что ниже будем ее заполнять новыми даными
834
	mov eax,ebx
835
	mov ecx,ebx
836
	add eax,2
837
	ConvertIndexToPointer eax
838
	mov edx,ted_tex
839
	add edx,ebx
840
	push ebx
841
	@@:
842
		mov ebx,[edx]
843
		mov byte [eax],bl
844
		mov dword [eax+2],ecx
845
		inc dword [eax+2]
846
		mov dword [eax+6],ecx
847
		add dword [eax+6],3
848
		;mov byte[eax+1],0 ;col=0
849
		mov dword [eax+10],-1 ;tc=-1
850
		mov dword [eax+14],0 ;td=0
851
 
852
		cmp ecx,0
853
		je @f
854
		dec ecx
855
		dec edx
856
		sub eax,sizeof.symbol
857
		jmp @b
858
	@@:
859
	pop ebx
860
	add eax,2
861
	mov dword [eax],0 ; first sumbol 'perv=0'
862
 
863
	mov edx,ted_tex
864
	; begining sumbol 'perv=0' 'next=2'
865
	mov dword [edx+2],0
866
	mov dword [edx+6],2
867
 
868
	add edx,sizeof.symbol
869
	mov dword [edx+6],0 ; last sumbol 'next=0'
870
	mov dword [edx+2],ebx ; last sumbol 'perv=last'
871
	inc dword [edx+2]
872
 
873
	mov edx,ebx
874
	inc edx ;2 = rezerv sumbols
875
	imul edx,sizeof.symbol
876
	add edx,ted_tex
877
	mov dword [edx+6],1 ; last sumbol 'next=1'
878
 
879
	@@: ;clear memory, need if before was open big file
880
		add edx,sizeof.symbol
881
		cmp edx,ted_tex_end
882
		jge @f
883
			mov dword[edx+10],0
884
			mov dword[edx+14],0
885
		jmp @b
886
	@@:
887
 
888
	call ted_get_num_lines
889
	cmp eax,100
890
	jge @f
891
		mov eax,100
892
	@@:
893
	mov esi,ted_scr_w
894
	mov dword[esi+sb_offs_max_area],eax
895
	pop esi edx ecx eax
896
 
897
	call ted_text_colored
898
	stdcall ted_draw,edi
899
	cmp ted_fun_draw_panel_buttons,0
900
	je @f
901
		call ted_fun_draw_panel_buttons
902
	@@:
903
	ret
904
endp
905
 
906
;input:
907
; edx = pointer to symbol struct
908
; edi = pointer to tedit struct
909
;output:
910
; edx = pointer to 'perv' visible symbol struct
911
align 4
912
ted_iterat_perv:
913
  cmp ted_tim_undo,0
914
  je .else
915
  push ebx
916
  @@:
917
    call ted_get_text_perv_pos
918
    cmp edx,ted_tex
919
    je @f
920
    call ted_symbol_not_vis
921
    cmp bl,1
922
    je @b
923
    cmp byte[edx],10 ;пропуск символа с кодом 10
924
    je @b
925
  @@:
926
  pop ebx
927
  ret
928
  .else:
929
    call ted_get_text_perv_pos
930
    cmp edx,ted_tex
931
    je .endif
932
    cmp dword [edx+14],0
933
    jne .else
934
    cmp byte[edx],10 ;пропуск символа с кодом 10
935
    je .else
936
  .endif:
937
  ret
938
 
939
 
940
;input:
941
; edx = pointer to symbol struct
942
; edi = pointer to tedit struct
943
;output:
944
; edx = pointer to 'next' visible symbol struct
945
align 4
946
ted_iterat_next:
947
  cmp ted_tim_undo,0
948
  je .else
949
  push ebx
950
  @@:
951
    call ted_get_text_next_pos
952
    cmp edx,ted_tex_1
953
    jle @f
954
    call ted_symbol_not_vis
955
    cmp bl,1
956
    je @b
957
    cmp byte[edx],10 ;пропуск символа с кодом 10
958
    je @b
959
  @@:
960
  pop ebx
961
  ret
962
  .else:
963
    call ted_get_text_next_pos
964
    cmp edx,ted_tex_1
965
    jle .endif
966
    cmp dword [edx+14],0
967
    jne .else
968
    cmp byte[edx],10 ;пропуск символа с кодом 10
969
    je .else
970
  .endif:
971
  ret
972
 
973
;input:
974
; bl = symbol end of select
975
; edx = pointer to symbol struct
976
; edi = pointer to tedit struct
977
;description:
978
; найти следующую позицию указанного символа
979
align 4
980
ted_iterat_next_pos_char:
981
	@@:
982
		cmp bl,byte[edx]
983
		je @f
984
		cmp edx,ted_tex_1
985
		jle @f
986
			call ted_iterat_next
987
			jmp @b
988
	@@:
989
	call ted_iterat_next
990
	ret
991
 
992
;input:
993
; edx = pointer to symbol struct
994
; edi = pointer to tedit struct
995
align 4
996
ted_iterat_perv_color_tag:
997
  @@:
998
    cmp byte[edx+1],0
999
    jne @f
1000
    call ted_iterat_perv
1001
    cmp edx,ted_tex_1
1002
    jle @f
1003
    jmp @b
1004
  @@:
1005
  ret
1006
 
1007
;input:
1008
; edx = pointer to symbol struct
1009
; edi = pointer to tedit struct
1010
align 4
1011
ted_iterat_next_color_tag:
1012
  @@:
1013
    call ted_iterat_next
1014
    cmp byte[edx+1],0
1015
    jne @f
1016
    cmp edx,ted_tex_1
1017
    jle @f
1018
    jmp @b
1019
  @@:
1020
  ;call ted_iterat_next
1021
  ret
1022
 
1023
;input:
1024
; edx = pointer to symbol struct
1025
; edi = pointer to tedit struct
1026
;output:
1027
; bl = 1 if sumbol not visible
1028
; (tex[i].td+ted_tim_undo<=ted_tim_ch && tex[i].td) || (tex[i].tc>ted_tim_ch-ted_tim_undo)
1029
align 4
1030
ted_symbol_not_vis:
1031
  push eax
1032
 
1033
  xor bl,bl
1034
 
1035
  cmp dword [edx+14],0
1036
  je @f
1037
  mov eax,[edx+14] ;eax=tex[i].td
1038
  add eax,ted_tim_undo
1039
  cmp eax,ted_tim_ch
1040
  jg @f
1041
    mov bl,1
1042
    pop eax
1043
    ret
1044
  @@:
1045
 
1046
  mov eax,ted_tim_ch
1047
  sub eax,ted_tim_undo
1048
  cmp [edx+10],eax
1049
  jle @f
1050
    or bl,1
1051
  @@:
1052
 
1053
  pop eax
1054
  ret
1055
 
1056
;input:
1057
; text:dword - pointer to text string
1058
; add_opt:dword - options
1059
align 4
1060
proc ted_text_add, edit:dword, text:dword, t_len:dword, add_opt:dword
1061
	locals
1062
		new_spc dd ? ;count new spaces
1063
		new_lin dd ? ;count new lines
1064
	endl
1065
;использование регистров внутри функции:
1066
;eax - позиция для вставки текста
1067
;ebx - для временных нужд, длинна вставляемого текста
1068
;ecx - для временных нужд
1069
;edx - указатель на структуру символа
1070
	pushad
1071
	mov edi,dword[edit]
1072
	mov esi,dword[text]
1073
 
1074
	call ted_get_pos_by_cursor
1075
	call ted_get_text_perv_pos
1076
	call ted_get_text_arr_index ;eax=po_t
1077
 
1078
	mov dword[new_spc],0
1079
	cmp ted_gp_opt,2
1080
	je @f
1081
		push eax ;c_sp=cur[cn].x+Scroller->XPos-StrLen(cur[cn].y+Scroller->YPos);
1082
			mov eax,ted_scr_h
1083
			mov eax,dword[eax+sb_offs_position]
1084
			add eax,ted_cur_x ;eax - номер символа
1085
			mov dword[new_spc],eax
1086
 
1087
			mov eax,ted_scr_w
1088
			mov eax,dword[eax+sb_offs_position]
1089
			add eax,ted_cur_y ;eax - номер строки
1090
			call ted_strlen ;ebx = line len
1091
			sub dword[new_spc],ebx ;от позиции курсора отнимаем длинну строки, узнаем колличество добавляемых пробелов
1092
		pop eax
1093
	@@:
1094
 
1095
	mov ebx,dword[t_len]
1096
 
1097
	mov dword[new_lin],0
1098
	cmp ted_gp_opt,0
1099
	jne @f
1100
		push eax
1101
			mov eax,ted_scr_w
1102
			mov eax,dword[eax+sb_offs_position]
1103
			add eax,ted_cur_y
1104
			inc eax
1105
			mov dword[new_lin],eax
1106
 
1107
			call ted_get_num_lines
1108
			sub dword[new_lin],eax
1109
		pop eax
1110
	@@:
1111
 
1464 IgorA 1112
	mov edx,ted_ptr_free_symb
1113
	.beg_cycle: ;for(i=...;i
1114
		cmp dword [edx+10],0 ;if(!tex[i].tc && !tex[i].td)
1115
		jne .u1f
1116
		cmp dword [edx+14],0
1117
		jne .u1f
1118
			test dword[add_opt],ted_opt_ed_change_time ;if(n_tim) ted_tim_ch++;
1119
			jz .no_tim
1120
				inc ted_tim_ch
1121
			.no_tim:
1122
			test dword[add_opt],ted_opt_ed_move_cursor
1123
			jz .no_cur_mov
1124
			cmp dword[new_lin],0 ;если есть добавочные строки, то курсор еще не двигаем
1125
			jg .no_cur_mov
1126
			cmp dword[new_spc],0 ;если нет добавочных пробелов, то курсор тоже не двигаем
1127
			jg .no_cur_mov
1128
				inc ted_cur_x ;move cursor
1129
				;call ted_go_to_pos
1130
				cmp byte [esi],13
1131
				jne .no_cur_mov
1132
					mov ted_cur_x,0
1133
					inc ted_cur_y
1134
			.no_cur_mov:
1457 IgorA 1135
 
1464 IgorA 1136
			mov ecx,ted_opt_ed_change_time
1137
			not ecx
1138
			and dword[add_opt],ecx ;n_tim=false;
1457 IgorA 1139
 
1464 IgorA 1140
			mov cl,byte [esi] ;tex[i].c=ta[ns];
1141
			mov byte [edx],cl
1142
			m2m dword [edx+10],ted_tim_ch ;tex[i].tc=ted_tim_ch;
1143
			mov [edx+2],eax ;tex[i].perv=po_t;
1457 IgorA 1144
 
1464 IgorA 1145
			mov ecx,eax
1146
			imul ecx,sizeof.symbol
1147
			add ecx,ted_tex ; *** ecx = tex[po_t] ***
1148
			add ecx,6   ; *** ecx = tex[po_t].next ***
1149
			m2m dword [edx+6],dword [ecx] ;tex[i].next=tex[po_t].next;
1457 IgorA 1150
 
1464 IgorA 1151
			call ted_get_text_arr_index ;*** eax = i ***
1152
			mov [ecx],eax ;tex[po_t].next=i; // ссылки перенаправляем
1153
			mov ecx,[edx+6] ; *** ecx = tex[i].next ***
1154
			imul ecx,sizeof.symbol
1155
			add ecx,ted_tex ; *** ecx = tex[tex[i].next] ***
1156
			mov [ecx+2],eax ;tex[tex[i].next].perv=i;
1457 IgorA 1157
 
1464 IgorA 1158
			cmp dword[new_lin],0 ;add lines or text
1159
			jle .spc_add
1160
				dec dword[new_lin]
1161
				mov byte [edx],13
1162
				jmp .u1f
1163
			.spc_add:
1164
			cmp dword[new_spc],0 ;add spaces or text
1165
			jle .tex_add
1166
				dec dword[new_spc]
1167
				mov byte [edx],' '
1168
				jmp .u1f
1169
			.tex_add:
1170
			inc esi
1171
			dec ebx
1172
		.u1f:
1173
		add edx,sizeof.symbol
1174
		cmp edx,ted_tex_end
1175
		jge @f ;out of memory
1176
		cmp ebx,0
1177
		jne .beg_cycle
1178
		mov ted_ptr_free_symb,edx ;меняем указатель на свободный символ, для более быстрого поиска памяти
1179
		jmp .add_all
1180
	@@:
1181
	cmp ted_increase_size,0
1182
	je .add_all
1183
		call ted_memory_increase
1184
		cmp ebx,0
1185
		jne .beg_cycle
1186
	.add_all: ;все символы добавлены
1457 IgorA 1187
 
1464 IgorA 1188
	call ted_text_colored
1189
	popad
1190
	ret
1457 IgorA 1191
endp
1192
 
1193
;input:
1464 IgorA 1194
;  edx = pointer to sumbol, when insert
1195
;  edi = pointer to tedit struct
1196
;output:
1197
;  edx = new pointer to sumbol, when insert
1198
align 4
1199
proc ted_memory_increase
1200
	cmp ted_increase_size,0
1201
	je @f
1202
		push eax ebx ecx
1203
		mov ecx,ted_increase_size
1204
		add ecx,ted_max_chars
1205
		mov ted_max_chars,ecx
1206
		imul ecx,sizeof.symbol
1207
		stdcall mem_ReAlloc, ted_tex,ecx
1208
		mov ebx,ted_tex
1209
		mov ted_tex,eax
1210
		mov ted_tex_1,eax
1211
		add ted_tex_1,sizeof.symbol
1212
			sub edx,ebx
1213
			add edx,eax
1214
			mov ted_ptr_free_symb,edx
1215
		add eax,ecx
1216
		mov ted_tex_end,eax
1217
		pop ecx ebx eax
1218
	@@:
1219
	ret
1220
endp
1221
 
1222
;input:
1457 IgorA 1223
;  ecx = position to free insert cell
1224
;  edx = pointer to sumbol, when insert
1225
;  esi = pointer to added symbol
1226
;  edi = pointer to tedit struct
1227
;output:
1228
;  ecx = position to inserted cell
1229
align 4
1230
ted_char_add:
1231
 
1232
  .loop_b:
1233
    cmp ecx,ted_tex_end
1234
    jge .end_f
1235
    cmp dword[ecx+10],0
1236
    jne @f
1237
      cmp dword[ecx+14],0
1238
      je .loop_e
1239
    @@:
1240
    add ecx,sizeof.symbol
1241
    jmp .loop_b
1242
  .loop_e:
1243
 
1244
  push eax ebx
1245
  mov eax,ted_tim_ch
1246
  mov dword[ecx+10],eax
1247
  mov al,byte[esi]
1248
  mov byte[ecx],al
1249
 
1250
  call ted_get_text_arr_index ; *** eax=pos ***
1251
  mov [ecx+2],eax ;tex[i].perv=pos;
1252
  m2m dword[ecx+6],dword[edx+6] ;tex[i].next=tex[pos].next;
1253
 
1254
  push edx
1255
    mov edx,ecx
1256
    call ted_get_text_arr_index ; *** eax=i ***
1257
  pop edx
1258
 
1259
  mov [edx+6],eax ;tex[pos].next=i; // ссылки перенаправляем
1260
  mov ebx,[ecx+6]
1261
  ConvertIndexToPointer ebx
1262
  mov [ebx+2],eax ;tex[tex[i].next].perv=i; // ...
1263
  pop ebx eax
1264
 
1265
  .end_f:
1266
  call ted_text_colored
1267
  ret
1268
 
1269
 
1270
;input:
1271
; conv_table = pointert to convert table
1272
; edi = pointer to tedit struct
1273
;output:
1274
; esi = count converted symbols
1275
;description:
1276
; Функция используется для смены регистра выбранных символов
1277
align 4
1278
proc ted_convert_sel_text
1279
  locals
1280
    conv_cou dd ?
1281
  endl
1282
  mov dword[conv_cou],0
1283
  pushad
1284
 
1285
  call ted_is_select
1286
  cmp al,0
1287
  je .end_f
1288
    call ted_set_undo
1289
    call ted_sel_normalize
1290
 
1291
    mov esi,ted_seln_x0
1292
    mov ecx,ted_seln_y0
1293
    call ted_get_pos_by_coords
1294
    mov eax,edx
1295
    mov esi,ted_seln_x1
1296
    mov ecx,ted_seln_y1
1297
    call ted_get_pos_by_coords
1298
    ;call ted_get_text_perv_pos
1299
    mov ebx,edx
1300
 
1301
    cmp eax,ebx
1302
    je .end_f
1303
 
1304
    inc ted_tim_ch
1305
    mov edx,eax ;i=p0;
1464 IgorA 1306
    mov ecx,ted_ptr_free_symb
1457 IgorA 1307
    @@:
1308
      mov esi,[edx]
1309
      and esi,0xff
1310
      add esi,[conv_table] ;EvUpper
1311
      cmp byte [esi],0
1312
      je .no_change
1313
	m2m dword [edx+14],ted_tim_ch
1314
	call ted_char_add ;b_pos=ted_char_add(tex[i].c^32,i,false,b_pos);
1315
	call ted_get_text_next_pos ;go to added symbol
1316
	inc dword[conv_cou]
1317
      .no_change:
1318
 
1319
      call ted_iterat_next
1320
      cmp edx,ted_tex
1321
      je @f
1322
      cmp edx,ebx
1323
      je @f
1324
 
1325
      jmp @b
1326
    @@:
1327
    cmp dword[conv_cou],0
1328
    jne @f
1329
      dec ted_tim_ch
1330
    @@:
1331
  .end_f:
1332
  popad
1333
  mov esi,dword[conv_cou]
1334
  ret
1335
endp
1336
 
1337
;output:
1338
; bl = 0 - no delete
1339
; bl = 1 - delete
1340
align 4
1341
proc ted_text_del, edit:dword, del_opt:dword
1342
  push cx edx edi
1343
  mov edi,dword[edit]
1344
  mov ebx,dword[del_opt]
1345
 
1346
  xor cl,cl
1347
  test ebx,ted_opt_ed_move_cursor
1348
  jz @f
1349
    call ted_cur_move_left
1350
    cmp dl,0
1351
    je .no_del
1352
  @@:
1353
  call ted_get_pos_by_cursor
1354
  cmp ted_gp_opt,1
1355
  je .no_del
1356
    test ebx,ted_opt_ed_change_time
1357
    jz @f
1358
      inc ted_tim_ch
1359
    @@:
1360
    m2m dword [edx+14], ted_tim_ch
1361
    mov cl,1
1362
  .no_del:
1363
  mov bl,cl
1364
  pop edi edx cx
1365
  ret
1366
endp
1367
 
1368
;input:
1369
; edi = pointer to tedit struct
1370
;output:
1371
; al = 1 if delete
1372
;description:
1373
; Функция удаляет выделенный текст
1374
align 4
1375
proc ted_sel_text_del, del_opt:dword
1376
	push ebx ecx edx esi
1377
 
1378
	call ted_is_select
1379
	cmp al,0
1380
	je .end_f
1381
 
1382
		call ted_sel_normalize
1383
 
1384
		mov esi,ted_seln_x1
1385
		mov ecx,ted_seln_y1
1386
		call ted_get_pos_by_coords
1387
		mov ebx,edx
1388
 
1389
		mov esi,ted_seln_x0
1390
		mov ecx,ted_seln_y0
1391
		call ted_get_pos_by_coords
1392
 
1393
		test dword[del_opt],ted_opt_ed_change_time
1394
		jz @f
1395
			inc ted_tim_ch
1396
		@@:
1397
		cmp edx,ted_tex
1398
		je @f
1399
		cmp edx,ebx ;if(i==te)break;
1400
		je @f
1401
			m2m dword[edx+14],ted_tim_ch
1402
			mov esi,ted_opt_ed_change_time
1403
			not esi
1404
			and dword[del_opt],esi ;n_tim=false;
1405
			call ted_iterat_next
1406
			jmp @b
1407
		@@:
1408
		test dword[del_opt],ted_opt_ed_change_time
1409
		jz @f
1410
			dec ted_tim_ch
1411
			xor al,al
1412
		@@:
1413
		test dword[del_opt],ted_opt_ed_change_time
1414
		jnz @f
1415
			mov ecx,ted_seln_x0
1416
			mov edx,ted_seln_y0
1417
			call ted_go_to_pos
1418
			mov ted_sel_x0,0
1419
			mov ted_sel_y0,0
1420
			mov ted_sel_x1,0
1421
			mov ted_sel_y1,0
1422
		@@:
1423
	.end_f:
1424
	pop esi edx ecx ebx
1425
	ret
1426
endp
1427
 
1428
 
1429
;input:
1430
; eax = pointer to begin select
1431
; ebx = pointer to end select
1432
; edi = pointer to tedit struct
1433
align 4
1434
ted_revers:
1435
  cmp eax,ebx
1436
  jne @f
1437
    ret
1438
  @@:
1439
 
1440
  push ecx edx
1441
 
1442
  mov edx,ted_tex_1
1443
  cmp edx,ebx ;if(p1==1)p1=tex[1].perv;
1444
  jne @f
1445
    call ted_get_text_perv_pos
1446
    mov ebx,edx
1447
  @@:
1448
 
1449
  push esi
1450
    mov edx,[eax+2] ; *** edx = tex[p0].perv ***
1451
    ConvertIndexToPointer edx
1452
    add edx,6
1453
    mov ecx,[edx] ;tmp = tex[tex[p0].perv].next;
1454
 
1455
    mov esi,[ebx+6] ; *** esi = tex[p1].next ***
1456
    ConvertIndexToPointer esi
1457
    add esi,2
1458
    m2m dword[edx],dword[esi] ;tex[tex[p0].perv].next = tex[tex[p1].next].perv;
1459
 
1460
    mov [esi],ecx ;tex[tex[p1].next].perv = tmp;
1461
  pop esi
1462
 
1463
  mov ecx,[eax+2] ;tmp = tex[p0].perv;
1464
  m2m dword[eax+2],dword[ebx+6] ;tex[p0].perv = tex[p1].next;
1465
  mov [ebx+6],ecx ;tex[p1].next = tmp;
1466
 
1467
  mov edx,eax ;i=p0;
1468
  @@:
1469
    mov ecx,[edx+6] ;tmp = tex[i].next;
1470
    m2m dword[edx+6],dword[edx+2] ;tex[i].next = tex[i].perv;
1471
    mov [edx+2],ecx ;tex[i].perv = tmp;
1472
    cmp edx,ebx ;if(i==p1)break;
1473
    je @f
1474
; ---
1475
;cmp edx,ted_tex
1476
;je @f
1477
; ---
1478
    mov edx,ecx ;i = tmp;
1479
    ConvertIndexToPointer edx
1480
    jmp @b
1481
  @@:
1482
  pop edx ecx
1483
  call ted_text_colored
1484
  ret
1485
 
1486
 
1487
;input:
1488
; edi = pointer to tedit struct
1489
;output:
1490
; dl = 0 not move
1491
; dl = 2 if move up
1492
; dl = 8 if scroll move up
1493
align 4
1494
ted_cur_move_up:
1495
  cmp ted_cur_y,0
1496
  je @f
1497
    dec ted_cur_y
1498
    mov dl,2
1499
    ret
1500
  @@:
1501
  push eax
1502
  mov eax,ted_scr_w
1503
  cmp dword[eax+sb_offs_position],0
1504
  je @f
1505
    dec dword[eax+sb_offs_position]
1506
    mov dl,8
1507
    jmp .ret_f
1508
  @@:
1509
  mov dl,0
1510
  .ret_f:
1511
  pop eax
1512
  ret
1513
 
1514
;input:
1515
; edi = pointer to tedit struct
1516
;output:
1517
; dl = 0 not move
1518
; dl = 2 if move down
1519
; dl = 8 if scroll move down
1520
align 4
1521
ted_cur_move_down:
1522
  push eax ebx
1523
  mov ebx,ted_scr_w
1524
  mov dl,0
1525
  mov eax,dword[ebx+sb_offs_cur_area]
1526
  dec eax
1527
  cmp ted_cur_y,eax
1528
  jge @f
1529
    inc ted_cur_y
1530
    mov dl,2
1531
    jmp .ret_f
1532
  @@:
1533
  mov eax,ted_cur_y
1534
  add eax,dword[ebx+sb_offs_position]
1535
  inc eax
1536
  cmp dword[ebx+sb_offs_max_area],eax
1537
  jle @f
1538
    inc dword[ebx+sb_offs_position]
1539
    mov dl,8
1540
  @@:
1541
  .ret_f:
1542
  pop ebx eax
1543
  ret
1544
 
1545
 
1546
;input:
1547
; edi = pointer to tedit struct
1548
;output:
1549
; dl = 0 not move
1550
; dl = 1 if move up
1551
align 4
1552
ted_cur_move_page_up:
1553
  push eax ebx
1554
  mov ebx,ted_scr_w
1555
  mov eax,dword[ebx+sb_offs_cur_area]
1556
  xor dl,dl
1557
  cmp eax,dword[ebx+sb_offs_position]
1558
  jg @f
1559
    sub dword[ebx+sb_offs_position],eax
1560
    mov dl,1
1561
  @@:
1562
  cmp dword[ebx+sb_offs_position],0
1563
  je @f
1564
  cmp dl,1
1565
  je @f
1566
    mov dword[ebx+sb_offs_position],0
1567
    mov dl,1
1568
  @@:
1569
  pop ebx eax
1570
  ret
1571
 
1572
;input:
1573
; edi = pointer to tedit struct
1574
align 4
1575
ted_cur_move_page_down:
1576
	push eax ebx ecx
1577
	mov ecx,ted_scr_w
1578
 
1579
	xor dl,dl
1580
	mov eax,dword[ecx+sb_offs_max_area]
1581
	sub eax,dword[ecx+sb_offs_cur_area]
1582
	cmp dword[ecx+sb_offs_position],eax
1583
	jge @f
1584
		mov ebx,dword[ecx+sb_offs_cur_area]
1585
		add dword[ecx+sb_offs_position],ebx
1586
		mov dl,1
1587
		mov dword[ecx+sb_offs_redraw],1
1588
		cmp dword[ecx+sb_offs_position],eax
1589
		jle @f
1590
			mov dword[ecx+sb_offs_position],eax
1591
	@@:
1592
	pop ecx ebx eax
1593
	ret
1594
 
1595
;input:
1596
; edi = pointer to tedit struct
1597
;output:
1598
; dl = 0 not move
1599
; dl = 1 if move left
1600
; dl = 3 if move left and up
1601
; dl = 8 if scroll move up
1602
align 4
1603
ted_cur_move_left:
1604
	cmp ted_cur_x,0
1605
	je @f
1606
		dec ted_cur_x
1607
		mov dl,1
1608
		ret
1609
	@@:
1610
	push eax
1611
	mov eax,ted_scr_h
1612
	cmp dword[eax+sb_offs_position],0
1613
	je @f
1614
		dec dword[eax+sb_offs_position]
1615
		mov dl,8
1616
		jmp .ret_f
1617
	@@:
1618
	cmp ted_cur_y,0
1619
	jne @f
1620
		mov eax,ted_scr_w
1621
		mov dl,0
1622
		cmp dword[eax+sb_offs_position],0
1623
		je .ret_f
1624
			dec dword[eax+sb_offs_position]
1625
			call ted_scroll_set_redraw
1626
			call ted_cur_move_x_last_char
1627
			mov dl,8
1628
			jmp .ret_f
1629
	@@:
1630
	cmp ted_cur_y,0
1631
	je @f
1632
		dec ted_cur_y
1633
		call ted_cur_move_x_last_char
1634
		cmp dl,8
1635
		je .ret_f
1636
		mov dl,3
1637
		jmp .ret_f
1638
	@@:
1639
	mov dl,0
1640
	.ret_f:
1641
	pop eax
1642
	ret
1643
 
1644
;input:
1645
; edi = pointer to tedit struct
1646
align 4
1647
ted_cur_move_right:
1648
	push eax ebx
1649
	mov eax,ted_scr_h
1650
	xor dl,dl
1651
	mov ebx,dword[eax+sb_offs_cur_area]
1652
	cmp ted_cur_x,ebx
1653
	jge @f
1654
		inc ted_cur_x
1655
		mov dl,1
1656
		jmp .ret_f
1657
	@@:
1658
		inc dword[eax+sb_offs_position]
1659
		mov dl,8
1660
	.ret_f:
1661
	pop ebx eax
1662
	ret
1663
 
1664
;input:
1665
; edi = pointer to tedit struct
1666
align 4
1667
ted_cur_move_x_last_char:
1668
;[hScr.position]
1669
;[hScr.cur_area]
1670
;dl-???
1671
  push eax ebx ecx
1672
  mov eax,ted_cur_y
1673
  mov ecx,ted_scr_w
1674
  add eax,dword[ecx+sb_offs_position]
1675
  call ted_strlen
1676
  xor dl,dl
1677
 
1678
  mov ecx,ted_scr_h
1679
  cmp ebx,dword[ecx+sb_offs_position]
1680
  jge @f
1681
    mov dl,8
1682
    mov dword[ecx+sb_offs_position],ebx
1683
  @@:
1684
  sub ebx,dword[ecx+sb_offs_position]
1685
 
1686
  cmp ebx,dword[ecx+sb_offs_cur_area]
1687
  jle @f ; b---[---]---e
1688
    add dword[ecx+sb_offs_position],ebx
1689
    mov ebx,dword[ecx+sb_offs_cur_area]
1690
    sub dword[ecx+sb_offs_position],ebx
1691
    mov dl,8
1692
  @@:
1693
  mov ted_cur_x,ebx
1694
  pop ecx ebx eax
1695
  ret
1696
 
1697
;input:
1698
; edi = pointer to tedit struct
1699
;output:
1700
; dl = 0 not move
1701
; dl = 1 move cursor
1702
; dl = 8 move cursor and scroll
1703
align 4
1704
ted_cur_move_x_first_char:
1705
	xor dl,dl
1706
	cmp ted_cur_x,0
1707
	je @f
1708
		mov ted_cur_x,0
1709
		mov dl,1
1710
	@@:
1711
	push eax
1712
	mov eax,ted_scr_h
1713
	cmp dword[eax+sb_offs_position],0
1714
	je @f
1715
		mov dword[eax+sb_offs_position],0
1716
		mov dl,8
1717
	@@:
1718
	pop eax
1719
	ret
1720
 
1721
;input:
1722
; edx = pointer to symbol struct
1723
; edi = pointer to tedit struct
1724
;output:
1725
; eax = array index
1726
align 4
1727
ted_get_text_arr_index:
1728
	push ecx edx
1729
		mov eax,edx
1730
		sub eax,ted_tex
1731
		xor edx,edx
1732
		mov ecx,sizeof.symbol
1733
		div ecx
1734
	pop edx ecx
1735
	ret
1736
 
1737
;input:
1738
; edx = pointer to symbol struct
1739
; edi = pointer to tedit struct
1740
;output:
1741
; edx = pointer to 'perv' struct
1742
align 4
1743
ted_get_text_perv_pos:
1744
	mov edx,dword[edx+2]
1745
	imul edx,sizeof.symbol
1746
	add edx,ted_tex
1747
	ret
1748
 
1749
;input:
1750
; edx = pointer to symbol struct
1751
;output:
1752
; edx = pointer to 'next' symbol struct
1753
align 4
1754
ted_get_text_next_pos:
1755
	mov edx,dword[edx+6]
1756
	imul edx,sizeof.symbol
1757
	add edx,ted_tex
1758
	ret
1759
 
1760
;input:
1761
; edi = pointer to tedit struct
1762
;output:
1763
; edx = symbol under cursor
1764
; ted_gp_opt = 1,2
1765
; edx = tex[1].perv if error
1766
; ted_gp_opt = 0
1767
align 4
1768
ted_get_pos_by_cursor:
1769
	push eax ecx esi
1770
		mov esi,ted_cur_x
1771
		mov eax,ted_scr_h
1772
		add esi,dword[eax+sb_offs_position]
1773
		mov ecx,ted_cur_y
1774
		mov eax,ted_scr_w
1775
		add ecx,dword[eax+sb_offs_position]
1776
		call ted_get_pos_by_coords
1777
	pop esi ecx eax
1778
	ret
1779
 
1780
;input:
1781
; esi = XPos
1782
; ecx = YPos
1783
; edi = pointer to tedit struct
1784
;output:
1785
; edx = symbol under cursor
1786
; ted_gp_opt = 1 if found text line
1787
; ted_gp_opt = 2 if found text line and column
1788
; edx = tex[1] if error
1789
; ted_gp_opt = 0 if text no found
1790
align 4
1791
ted_get_pos_by_coords:
1792
  push eax ;Row
1793
  push ebx ;Col
1794
 
1795
  xor eax,eax
1796
  xor ebx,ebx
1797
  mov ted_gp_opt,0
1798
  mov edx,ted_tex
1799
  @@:
1800
    call ted_iterat_next
1801
    cmp edx,ted_tex_1
1802
    jle @f
1803
    cmp ebx,esi
1804
    jne .u1_0 ;Col <> ted_cur_x
1805
      mov ted_gp_opt,1
1806
      cmp eax,ecx
1807
      jge @f ; Row >= ted_cur_y
1808
    .u1_0:
1809
    mov ted_gp_opt,0
1810
    inc ebx
1811
    cmp byte [edx],13
1812
    jne @b
1813
    cmp eax,ecx
1814
    jge @f ; Row >= ted_cur_y
1815
    inc eax
1816
    xor ebx,ebx
1817
    jmp @b
1818
  @@:
1819
  cmp eax,ecx
1820
  jne @f ; Row = ted_cur_y
1821
    inc ted_gp_opt
1822
  @@:
1823
  cmp ted_gp_opt,0
1824
  jne @f
1825
    mov edx,ted_tex_1
1826
    ;call ted_get_text_perv_pos
1827
  @@:
1828
  pop ebx eax
1829
  ret
1830
 
1831
 
1832
;input:
1833
; eax = Row
1834
; edi = pointer to tedit struct
1835
;output:
1836
; ebx = str len
1837
align 4
1838
ted_strlen:
1839
  push edx ecx
1840
  ;ecx = Row, from cycle
1841
 
1842
  xor ebx,ebx
1843
  xor ecx,ecx
1844
  mov edx,ted_tex
1845
  @@:
1846
    call ted_iterat_next
1847
    cmp edx,ted_tex_1
1848
    jle @f
1849
    inc ebx
1850
    cmp byte [edx],13
1851
    jne @b
1852
    dec ebx ;lenght minus 1 sumbol to paragraph
1853
    cmp eax,ecx
1854
    je @f
1855
    xor ebx,ebx
1856
    inc ecx
1857
    jmp @b
1858
  @@:
1859
 
1860
  cmp eax,ecx
1861
  je @f
1862
    xor ebx,ebx
1863
  @@:
1864
 
1865
  pop ecx edx
1866
  ret
1867
 
1868
 
1869
;input:
1870
; edx = symbol position
1871
; edi = pointer to tedit struct
1872
;output:
1873
; eax = number of line
1874
; ebx = symbol position in line
1875
align 4
1876
ted_get_text_coords:
1877
  push edx
1878
  xor eax,eax
1879
  xor ebx,ebx
1880
  @@:
1881
    call ted_iterat_perv
1882
 
1883
    cmp eax,0
1884
    jne .no_col_mov
1885
    inc ebx
1886
    .no_col_mov:
1887
 
1888
    cmp edx,ted_tex_1
1889
    jle @f
1890
    cmp byte [edx],13
1891
    jne @b
1892
    inc eax
1893
    jmp @b
1894
  @@:
1895
  dec ebx
1896
  pop edx
1897
  ret
1898
 
1899
;input:
1900
; edi = pointer to tedit struct
1901
;output:
1902
; eax = num lines
1903
align 4
1904
ted_get_num_lines:
1905
  push edx
1906
  mov eax,1
1907
  mov edx,ted_tex
1908
  @@:
1909
    call ted_iterat_next
1910
    cmp edx,ted_tex_1
1911
    jle @f
1912
    cmp byte [edx],13
1913
    jne @b
1914
    inc eax
1915
    jmp @b
1916
  @@:
1917
;...
1918
;dec eax
1919
  pop edx
1920
  ret
1921
 
1922
 
1923
;input:
1924
; edi = pointer to tedit struct
1925
;description:
1926
; отменяет отмененные действия, перед изменением документа
1927
align 4
1928
proc ted_set_undo
1929
  mov ted_drag_k,0 ;заканчиваем выделение от клавиатуры
1930
  cmp ted_tim_undo,1
1931
  jl .no_work
1932
 
1933
  push eax ebx edx
1934
  mov edx,ted_tex
1935
  call ted_get_text_next_pos ;long i=tex[0].next;
1936
  mov eax,ted_tim_undo
1937
  sub ted_tim_ch,eax ;ted_tim_ch-=ted_tim_undo;
1938
  mov eax,ted_tim_ch
1939
  cmp ted_tim_ls,eax ;if(ted_tim_ls>ted_tim_ch)
1940
  jle @f
1941
    mov ted_tim_ls,0
1942
  @@:
1943
    cmp edx,ted_tex
1944
    je @f
1945
 
1946
    ;if(tex[i].tc>ted_tim_ch){ // если создание символа было отменено
1947
    cmp [edx+10],eax
1948
    jle .no_u1
1949
      mov dword [edx+10],0
1950
      mov dword [edx+14],0
1951
 
1952
      mov ebx,[edx+2]
1953
      imul ebx,sizeof.symbol
1954
      add ebx,ted_tex;.next
1955
      m2m dword [ebx+6],dword [edx+6] ;tex[tex[i].perv].next=tex[i].next;
1956
 
1957
      mov ebx,[edx+6]
1958
      imul ebx,sizeof.symbol
1959
      add ebx,ted_tex;.perv
1960
      m2m dword [ebx+2],dword [edx+2] ;tex[tex[i].next].perv=tex[i].perv;
1961
 
1464 IgorA 1962
cmp ted_ptr_free_symb,edx
1963
jle .no_u1
1964
  mov ted_ptr_free_symb,edx ;меняем указатель на свободный символ, для более быстрого поиска памяти
1457 IgorA 1965
    .no_u1:
1966
 
1967
    ;else if(tex[i].td>ted_tim_ch) tex[i].td=0; // если удаление символа было отменено
1968
    cmp [edx+14],eax
1969
    jle .no_u2
1970
      mov dword [edx+14],0
1971
    .no_u2:
1972
 
1973
    call ted_get_text_next_pos
1974
    jmp @b
1975
  @@:
1976
  mov ted_tim_undo,0
1977
  mov eax,ted_tim_co
1978
  cmp ted_tim_ch,eax
1979
  jge @f
1980
    mov ted_tim_co,0
1981
  @@:
1982
  pop edx ebx eax
1983
  .no_work:
1984
  ret
1985
endp
1986
 
1987
;input:
1988
; ecx = Col
1989
; edx = Row
1990
; edi = pointer to tedit struct
1991
align 4
1992
ted_go_to_pos:
1993
	push eax
1994
	mov eax,ted_scr_w
1995
	mov ted_cur_x,ecx
1996
	sub edx,dword[eax+sb_offs_position]
1997
 
1998
	cmp edx,dword[eax+sb_offs_cur_area] ;ted_cur_y > [.cur_area]
1999
	jl @f
2000
		push ebx
2001
		mov ebx,edx
2002
		sub ebx,dword[eax+sb_offs_cur_area]
2003
		inc ebx
2004
		add dword[eax+sb_offs_position],ebx
2005
		sub edx,ebx
2006
		pop ebx
2007
		; ??? redrav
2008
	@@:
2009
	mov ted_cur_y,edx
2010
	pop eax
2011
	ret
2012
 
2013
;input:
2014
; edi = pointer to tedit struct
2015
align 4
2016
ted_text_colored:
2017
  push eax edx
2018
  mov eax,ted_tim_ch
2019
  sub eax,ted_tim_undo
2020
  mov ted_tim_co,eax
2021
  mov edx,ted_tex
2022
  @@:
2023
    call ted_iterat_next
2024
    cmp edx,ted_tex_1
2025
    jle @f
2026
    mov byte[edx+1],0
2027
    jmp @b
2028
  @@:
2029
 
2030
  cmp ted_key_words_count,1
2031
  jl .no_colors
2032
  mov edx,ted_tex
2033
  @@:
2034
    call ted_text_find_sel_color
2035
    cmp edx,ted_tex_1
2036
    jle .no_colors
2037
    jmp @b
2038
  .no_colors:
2039
  pop edx eax
2040
  ret
2041
 
2042
 
2043
;input:
2044
; edx = pointer to start symbol
2045
; edi = pointer to tedit struct
2046
;output:
2047
; edx = pointer to next symbol
2048
;description:
2049
; Функция для поиска и выделения подсвеченых слов
2050
align 4
2051
proc ted_text_find_sel_color
2052
locals
2053
  begPos dd ? ;начальная позиция
2054
  endPos dd ? ;конечная позиция
2055
  find db ? ;найдено / не найдено
2056
  f_color db ? ;индекс цвета найденого слова
2057
endl
2058
  push eax ebx ecx esi
2059
;eax = word_n текущий номер (позиция) проверяемого слова в списке
2060
;ebx = для разных целей
2061
;ecx = l_pos последний номер (позиция) подходящего слова в списке
2062
;esi = для разных целей, номер проверяемого символа в слове
2063
  mov dword[begPos],1
2064
  mov dword[endPos],1
2065
  mov byte[find],0
2066
  mov byte[f_color],1
2067
  @@:
2068
    call ted_iterat_next
2069
    cmp edx,ted_tex_1
2070
    jle @f
2071
 
2072
    xor eax,eax
2073
    mov al,byte[edx]
2074
    shl ax,2 ;eax*=4
2075
    add eax,ted_arr_key_pos
2076
    mov eax,dword[eax]
2077
    cmp eax,0
2078
    jl @b ;if( (word_n=ted_arr_key_pos[(unsigned char)tex[i].c])>-1 ){
2079
 
2080
    mov ecx,eax
2081
    ;while(l_pos
2082
    .wh_1b:
2083
      cmp ecx,ted_key_words_count
2084
      jge .wh_1e
2085
      ColToIndexOffset ecx,esi
2086
      mov bl,byte[esi]
2087
      ColToIndexOffset eax,esi
2088
      cmp bl,byte[esi]
2089
      jne .wh_1e
2090
	inc ecx
2091
      jmp .wh_1b
2092
    .wh_1e:
2093
 
2094
    mov dword[begPos],edx ;bP=i;
2095
    mov esi,1
2096
 
2097
    .wh_2b: ;while(1){
2098
      call ted_iterat_next
2099
 
2100
      ;while(l_pos>word_n && Col[l_pos-1].Text[pos]!=tex[i].c)
2101
      .wh_3b:
2102
	cmp ecx,eax
2103
	jle .wh_3e
2104
	dec ecx
2105
	ColToIndexOffset ecx,ebx
2106
	inc ecx
2107
	;cmp byte[ebx+esi],byte[edx]
2108
	mov bl,byte[ebx+esi]
2109
	cmp bl,byte[edx]
2110
	je .wh_3e
2111
	  dec ecx
2112
	jmp .wh_3b
2113
      .wh_3e:
2114
 
2115
      ColToIndexOffset eax,ebx
2116
      cmp byte[ebx+esi],0
2117
      jne .if_0 ;if(Col[word_n].Text[pos]==0){
2118
	mov dword[endPos],edx ;eP=i;
2119
	ColToIndexOffset eax,ebx
2120
	mov bl,byte[ebx+MAX_COLOR_WORD_LEN+6]
2121
	mov byte[f_color],bl ;f_color=Col[word_n].color;
2122
 
2123
mov byte[find],1
2124
	  ColToIndexOffset eax,ebx ;... ebx = Col[word_n]
2125
	  mov bl,byte[ebx+MAX_COLOR_WORD_LEN+4]
2126
	  cmp bl,0 ;if(Col[word_n].wwo)
2127
	  je .if_2n
2128
	    push edx
2129
	    mov edx,dword[begPos]
2130
     call ted_iterat_perv
2131
 
2132
	    btr bx,0 ;1-1
2133
	    jae .if_3e ;if(Col[word_n].wwo&1)
2134
	      ;u1= !(isalnum(cont_s)||cont_s=='_')
2135
	      call isalnum
2136
	      jae .if_3e
2137
		mov byte[find],0
2138
	    .if_3e:
2139
 
2140
	    btr bx,3 ;4-1
2141
	    jae .if_4e ;if(Col[word_n].wwo&8)
2142
	      ;u1= !isalpha(cont_s);
2143
	      call isalpha
2144
	      jae .if_4e
2145
		mov byte[find],0
2146
	    .if_4e:
2147
 
2148
	    mov edx,dword[endPos]
2149
;     call ted_iterat_next
2150
 
2151
	    btr bx,1 ;2-1
2152
	    jae .if_5e ;if(Col[word_n].wwo&2)
2153
	      ;u1= !(isalnum(cont_s)||cont_s=='_')
2154
	      call isalnum
2155
	      jae .if_5e
2156
		mov byte[find],0
2157
	    .if_5e:
2158
 
2159
	    btr bx,4 ;5-1
2160
	    jae .if_6e ;if(Col[word_n].wwo&16)
2161
	      ;u1= !isalpha(cont_s);
2162
	      call isalpha
2163
	      jae .if_6e
2164
		mov byte[find],0
2165
	    .if_6e:
2166
 
2167
	    btr bx,2 ;3-1
2168
	    jae .if_7e ;if(Col[word_n].wwo&4)
2169
	    ColToIndexOffset eax,ebx
2170
	    mov bl,byte[ebx+MAX_COLOR_WORD_LEN+5]
2171
	    call ted_iterat_next_pos_char
2172
       cmp edx,ted_tex_1
2173
       jle .if_7e
2174
       mov dword[endPos],edx
2175
	    .if_7e:
2176
 
2177
	    pop edx
2178
	  .if_2n:
2179
;                 if(i!=1){ // не конец документа
2180
;                   cont_s=tex[eP].c;
2181
;                   if(Col[word_n].wwo&2) u2= !(isalnum(cont_s)||cont_s=='_');  // не букв.-числ. символ
2182
;                   if(u2 && Col[word_n].wwo&16) u2= !isalpha(cont_s); // не числ. символ
2183
;                   if(Col[word_n].wwo&4) eP=ted_iterat_next_pos_char(eP,Col[word_n].endc);
2184
 
2185
	cmp eax,ecx
2186
	je .wh_2e ;if(word_n==l_pos) break; // do double - если слово точно последнее
2187
      .if_0:
2188
 
2189
      cmp edx,ted_tex_1
2190
      jle .wh_2e ;if(i==1) break;
2191
 
2192
      ;while(l_pos>word_n && Col[word_n].Text[pos]!=tex[i].c)
2193
      .wh_4b:
2194
	cmp ecx,eax
2195
	jle .wh_4e
2196
	ColToIndexOffset eax,ebx
2197
	;cmp byte[ebx+esi],byte[edx]
2198
	mov bl,byte[ebx+esi]
2199
	cmp bl,byte[edx]
2200
	je .wh_4e
2201
	  inc eax
2202
	jmp .wh_4b
2203
      .wh_4e:
2204
 
2205
      cmp eax,ecx
2206
      je .wh_2e;if(word_n==l_pos) break;
2207
      inc esi ;pos++;
2208
      jmp .wh_2b
2209
    .wh_2e:
2210
 
2211
    cmp byte[find],1 ;if(fnd)break;
2212
    je @f
2213
    mov edx,dword[begPos];i=bP;
2214
    jmp @b
2215
  @@:
2216
 
2217
  cmp byte[find],1
2218
  jne .if_1e ;if(fnd){ // выделение найденого текста
2219
;    if(!mode_sf1 || (mode_sf1 && strlen(Col[word_n].f1->c_str())>0)){
2220
    mov eax,dword[begPos]
2221
    mov bl,byte[f_color]
2222
    mov byte[eax+1],bl ;tex[bP].col=f_color;
2223
    mov eax,dword[endPos]
2224
    mov byte[eax+1],0xff ;tex[eP].col=255;
2225
;    return ItPoPerv(eP); // возвращаем позицию конца вхождения
2226
    mov edx,dword[endPos]
2227
    call ted_get_text_perv_pos
2228
    jmp @f
2229
  .if_1e:
2230
    mov edx,ted_tex
2231
  @@:
2232
 
2233
  pop esi ecx ebx eax
2234
  ret
2235
endp
2236
 
2237
;input:
2238
; edx = pointer to char (byte)
2239
;output:
2240
; cf=1 if symbol is...
2241
align 4
2242
tab_all_num db 0,0,0,0,0,0,11111111b,11b,11111110b,0xff,0xff,111b,11111110b,0xff,0xff,111b,0,0,0,0,0,0,0,0;,0,0,0,0,0,0,0,0 - tab_alpha_0,0,0,0,0,0,0,0
2243
tab_alpha db 0,0,0,0,0,0,0,0,11111110b,0xff,0xff,111b,11111110b,0xff,0xff,111b,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2244
 
2245
align 4
2246
isalnum:
2247
  push eax ebx
2248
  mov al,byte[edx] ;al=offset
2249
  shr al,3
2250
  and eax,11111b
2251
  lea ebx,[tab_all_num]
2252
  add ebx,eax
2253
  mov ah,byte[ebx]
2254
  mov al,byte[edx] ;al=bit
2255
  and ax,111b
2256
  mov bx,word[ebx]
2257
  btr bx,ax
2258
  pop ebx eax
2259
  ret
2260
align 4
2261
isalpha:
2262
  push eax ebx
2263
  mov al,byte[edx] ;al=offset
2264
  shr al,3
2265
  and eax,11111b
2266
  lea ebx,[tab_alpha]
2267
  add ebx,eax
2268
  mov ah,byte[ebx]
2269
  mov al,byte[edx] ;al=bit
2270
  and ax,111b
2271
  mov bx,word[ebx]
2272
  btr bx,ax
2273
  pop ebx eax
2274
  ret
2275
 
2276
align 4
2277
proc ted_show_help_f1, edit:dword
2278
  push eax edx edi
2279
  mov edi,dword[edit]
2280
 
2281
  call ted_get_pos_by_cursor
2282
  push edx
2283
    call ted_iterat_next_color_tag
2284
    mov eax,edx
2285
  pop edx
2286
  call ted_iterat_perv_color_tag
2287
 
2288
  cmp eax,ted_tex
2289
  jle @f
2290
  cmp edx,ted_tex_1
2291
  jle @f
2292
    stdcall ted_find_help_id,eax
2293
  @@:
2294
  ;call ted_draw_main_cursor
2295
  call ted_draw_help_f1
2296
  pop edi edx eax
2297
  ret
2298
endp
2299
 
2300
;input:
2301
; edx = position begin 'symbol' struct
2302
; edi = pointer to tedit struct
2303
; end_pos = position end 'symbol' struct
2304
align 4
2305
proc ted_find_help_id, end_pos:dword
2306
; ecx = word_n
2307
; ebx = l_pos
2308
  mov ted_help_id,-1
2309
 
2310
  push ebx ecx
2311
    xor ebx,ebx
2312
    mov bl,byte[edx]
2313
    shl bx,2 ;ebx*=4
2314
    add ebx,ted_arr_key_pos
2315
    mov ecx,dword[ebx]
2316
    cmp ecx,0
2317
    jl .if_0e ;if( (word_n=ted_arr_key_pos[(unsigned char)tf[0]])>-1 ){
2318
      push esi eax
2319
      mov ebx,ecx ;l_pos=word_n;
2320
      ColToIndexOffset ecx,esi
2321
      push cx
2322
      mov cl,byte[esi]
2323
      @@:
2324
	cmp ebx,ted_key_words_count ;while(l_pos
2325
	jge @f
2326
	;ColToIndexOffset ecx,esi
2327
	ColToIndexOffset ebx,eax
2328
	cmp cl,byte[eax] ;&& Col[l_pos].Text[0]==Col[word_n].Text[0])
2329
	jne @f
2330
	  inc ebx ;l_pos++;
2331
	  jmp @b
2332
      @@:
2333
      pop cx
2334
      call ted_iterat_next ;pos=1;
2335
      mov esi,1
2336
      @@:
2337
	push dx
2338
	push word[edx]
2339
	pop dx
2340
	  .wh_0b:
2341
	    cmp ebx,ecx ;while(l_pos>word_n
2342
	    jle .wh_0e
2343
	    dec ebx
2344
	    ColToIndexOffset ebx,eax
2345
	    inc ebx
2346
	    cmp byte[eax+esi],dl ;&& Col[l_pos-1].Text[pos]!=tf[i])
2347
	    je .wh_0e
2348
	      dec ebx ;l_pos--;
2349
	    jmp .wh_0b
2350
	  .wh_0e:
2351
 
2352
	  .wh_1b:
2353
	    cmp ebx,ecx ;while(l_pos>word_n
2354
	    jle .wh_1e
2355
	    ColToIndexOffset ecx,eax
2356
	    cmp byte[eax+esi],dl
2357
	    je .wh_1e
2358
	      inc ecx ;word_n++;
2359
	    jmp .wh_1b
2360
	  .wh_1e:
2361
	pop dx
2362
 
2363
	cmp ecx,ebx ;if(word_n==l_pos) break;
2364
	je @f
2365
	call ted_iterat_next ;pos++;
2366
	cmp edx,dword[end_pos] ;for(...;i
2367
	je @f ;jge
2368
	inc esi
2369
	jmp @b
2370
      @@:
2371
      pop eax esi
2372
 
2373
      mov ted_help_id,ecx
2374
      ;return word_n;
2375
 
2376
    .if_0e:
2377
  pop ecx ebx
2378
  ret
2379
endp
2380
 
2381
;output:
2382
; eax = код ошибки
2383
; ebx = колличество прочитанных байт
2384
align 4
2385
proc ted_open_file, edit:dword, file:dword, f_name:dword ;функция открытия файла
2386
	push edi
2387
	mov edi,dword[edit]
2388
 
2389
	mov eax,70
2390
	mov ebx,dword[file]
2391
	mov dword[ebx], 0
2392
	mov dword[ebx+4], 0
2393
	mov dword[ebx+8], 0
2394
	m2m dword[ebx+12], ted_max_chars ;число байт, которые могут быть считаны с файла
2395
	m2m dword[ebx+16], ted_tex
2396
	mov  byte[ebx+20], 0
2397
	push dword[f_name]
2398
	pop dword[ebx+21]
2399
	int 0x40
2400
 
2401
	cmp eax,0
2402
	je @f
2403
	cmp eax,6
2404
	je @f
2405
		jmp .ret_f
2406
	@@:
2407
	cmp ebx,-1
2408
	je .ret_f
2409
		;if open file
2410
		call ted_on_open_file
2411
	.ret_f:
2412
	pop edi
2413
	ret
2414
endp
2415
 
2416
align 4
2417
proc ted_but_select_word, edit:dword
2418
	pushad
2419
	mov edi,dword[edit]
2420
 
2421
	call ted_get_pos_by_cursor
2422
	push edx
2423
		call ted_iterat_perv_color_tag
2424
		cmp edx,ted_tex_1
2425
		jle @f
2426
			call ted_get_text_coords
2427
			mov ted_sel_x0,ebx
2428
			mov ted_sel_y0,eax
2429
		@@:
2430
	pop edx
2431
	call ted_iterat_next_color_tag
2432
	cmp edx,ted_tex_1
2433
	jle @f
2434
		call ted_get_text_coords
2435
		mov ted_sel_x1,ebx
2436
		mov ted_sel_y1,eax
2437
	@@:
2438
 
2439
	cmp ted_fun_draw_panel_buttons,0
2440
	je @f
2441
		call ted_fun_draw_panel_buttons
2442
	@@:
2443
	stdcall ted_draw,edi
2444
	popad
2445
	ret
2446
endp
2447
 
2448
align 4
2449
proc ted_but_cut, edit:dword
2450
	push edi
2451
	mov edi,dword[edit]
2452
 
2453
	stdcall ted_but_copy,edi
2454
	call ted_set_undo
2455
	stdcall ted_sel_text_del,ted_opt_ed_change_time
2456
 
2457
	cmp al,1
2458
	jne @f
2459
		stdcall ted_draw,edi
2460
		cmp ted_fun_draw_panel_buttons,0
2461
		je @f
2462
			call ted_fun_draw_panel_buttons
2463
	@@:
2464
	pop edi
2465
	ret
2466
endp
2467
 
2468
;output:
2469
; al = 1 if copy text
2470
align 4
2471
proc ted_but_copy, edit:dword
2472
	pushad
2473
	mov edi,dword[edit]
2474
 
2475
	call ted_is_select
2476
	cmp al,0
2477
	je .end_f ;if not selected text
2478
	call ted_sel_normalize
2479
 
2480
	mov esi,ted_seln_x1
2481
	mov ecx,ted_seln_y1
2482
	call ted_get_pos_by_coords
2483
	mov ebx,edx
2484
	mov esi,ted_seln_x0
2485
	mov ecx,ted_seln_y0
2486
	call ted_get_pos_by_coords
2487
	mov esi,ebx
2488
 
2489
	xor ecx,ecx
2490
	mov ebx,ted_buffer
2491
	;mov edx,ted_tex
2492
	@@:
2493
		cmp edx,ted_tex_1 ;end of file
2494
		jle @f
2495
		cmp edx,esi ;end of select
2496
		je @f
2497
		inc ecx
2498
		cmp ecx,ted_buffer_size ;owerflow bufer
2499
		je @f
2500
 
2501
		mov al,byte[edx]
2502
		mov byte[ebx],al
2503
		inc ebx
2504
 
2505
		call ted_iterat_next
2506
		jmp @b
2507
	@@:
2508
	add ecx,ted_buffer
2509
	mov byte[ebx],0
2510
 
2511
	cmp ecx,0
2512
	je .end_f
2513
		call ted_draw_buffer
2514
		cmp ted_fun_draw_panel_buttons,0
2515
		je .end_f
2516
			call ted_fun_draw_panel_buttons
2517
	.end_f:
2518
	popad
2519
	ret
2520
endp
2521
 
2522
 
2523
align 4
2524
proc ted_but_paste, edit:dword
2525
	push eax ebx esi edi
2526
	mov edi,dword[edit]
2527
 
2528
	mov esi,ted_buffer
2529
	call tl_strlen
2530
	cmp eax,1
2531
	jl @f
2532
		mov esi,eax
2533
		call ted_set_undo
2534
		mov ebx,ted_opt_ed_change_time+ted_opt_ed_move_cursor
2535
		stdcall ted_sel_text_del,ebx
2536
		cmp al,1
2537
		jne .del
2538
			mov ebx,ted_opt_ed_move_cursor
2539
		.del:
2540
		stdcall ted_text_add,edi,ted_buffer,esi,ebx
2541
		stdcall ted_draw,edi
2542
		cmp ted_fun_draw_panel_buttons,0
2543
		je @f
2544
			call ted_fun_draw_panel_buttons
2545
	@@:
2546
	pop edi esi ebx eax
2547
	ret
2548
endp
2549
 
2550
align 4
2551
proc ted_but_sumb_upper, edit:dword
2552
  push edi esi
2553
  mov edi,dword[edit]
2554
 
2555
  mov [conv_table],EvUpper
2556
  call ted_convert_sel_text
2557
  cmp esi,0
2558
  je @f
2559
    stdcall ted_draw,edi
2560
  @@:
2561
  pop esi edi
2562
  ret
2563
endp
2564
 
2565
align 4
2566
proc ted_but_sumb_lover, edit:dword
2567
  push edi esi
2568
  mov edi,dword[edit]
2569
 
2570
  mov [conv_table],EvLover
2571
  call ted_convert_sel_text
2572
  cmp esi,0
2573
  je @f
2574
    stdcall ted_draw,edi
2575
  @@:
2576
  pop esi edi
2577
  ret
2578
endp
2579
 
2580
align 4
2581
proc ted_but_reverse, edit:dword
2582
  push eax ebx edi
2583
  mov edi,dword[edit]
2584
 
2585
  call ted_is_select
2586
  cmp al,0
2587
  je @f
2588
    call ted_sel_normalize
2589
    push esi ecx edx
2590
      mov esi,ted_seln_x0
2591
      mov ecx,ted_seln_y0
2592
      call ted_get_pos_by_coords
2593
      mov eax,edx
2594
      mov esi,ted_seln_x1
2595
      cmp esi,0
2596
      je .beg_str
2597
	dec esi
2598
      .beg_str:
2599
      mov ecx,ted_seln_y1
2600
      call ted_get_pos_by_coords
2601
      ;call ted_get_text_perv_pos
2602
      mov ebx,edx
2603
    pop edx ecx esi
2604
    ;cmp eax,...
2605
    ;je @f
2606
    call ted_revers
2607
  @@:
2608
  stdcall ted_draw,edi
2609
  pop edi ebx eax
2610
  ret
2611
endp
2612
 
2613
align 4
2614
proc ted_but_undo, edit:dword
2615
	push eax edi
2616
	mov edi,dword[edit]
2617
 
2618
	mov eax,ted_tim_undo
2619
	cmp ted_tim_ch,eax
2620
	jbe @f
2621
		inc ted_tim_undo
2622
		;call ted_text_colored
2623
		stdcall ted_draw,edi
2624
		cmp ted_fun_draw_panel_buttons,0
2625
		je @f
2626
			call ted_fun_draw_panel_buttons
2627
	@@:
2628
	pop edi eax
2629
	ret
2630
endp
2631
 
2632
align 4
2633
proc ted_but_redo, edit:dword
2634
	push edi
2635
	mov edi,dword[edit]
2636
 
2637
	cmp ted_tim_undo,1
2638
	jb @f
2639
		dec ted_tim_undo
2640
		;call ted_text_colored
2641
		stdcall ted_draw,edi
2642
		cmp ted_fun_draw_panel_buttons,0
2643
		je @f
2644
			call ted_fun_draw_panel_buttons
2645
	@@:
2646
	pop edi
2647
	ret
2648
endp
2649
 
2650
align 4
2651
proc ted_but_find_next, edit:dword
2652
	pushad
2653
	mov edi,dword[edit]
2654
 
2655
	call ted_get_pos_by_cursor
2656
	mov eax,ted_buffer_find
2657
	mov bl,byte[eax]
2658
	@@:
2659
		call ted_get_find_rezult
2660
		cmp bh,1
2661
		je @f ; find
2662
			call ted_iterat_next
2663
			cmp edx,ted_tex_1
2664
			jle @f
2665
			jmp @b
2666
	@@:
2667
	cmp bh,0
2668
	je @f
2669
		call ted_get_text_coords
2670
		inc ebx ;move cursor right
2671
		mov ted_sel_x1,ebx
2672
		mov ted_sel_y1,eax
2673
		mov edx,eax
2674
		mov ecx,ebx
2675
		call ted_go_to_pos
2676
		mov edx,esi ;esi было установлео в ted_get_find_rezult
2677
		call ted_get_text_coords
2678
		mov ted_sel_x0,ebx
2679
		mov ted_sel_y0,eax
2680
		stdcall ted_draw,edi
2681
		jmp .end_find
2682
	@@:
2683
		;попадаем сюда если текст не найден
2684
		cmp ted_fun_find_err,0
2685
		je .end_find
2686
			call ted_fun_find_err ;пользовательская функция
2687
	.end_find:
2688
	popad
2689
	ret
2690
endp
2691
 
2692
;input:
2693
; edi = pointer to tedit struct
2694
align 4
2695
ted_key_ctrl_home:
2696
	mov ted_cur_x,0
2697
	mov ted_cur_y,0
2698
	push eax
2699
		mov eax,ted_scr_w
2700
		mov dword[eax+sb_offs_position],0
2701
		mov eax,ted_scr_h
2702
		mov dword[eax+sb_offs_position],0
2703
	pop eax
2704
	stdcall ted_draw,edi
2705
	cmp ted_fun_draw_panel_buttons,0
2706
	je @f
2707
		call ted_fun_draw_panel_buttons
2708
	@@:
2709
	ret
2710
 
2711
;input:
2712
; edi = pointer to tedit struct
2713
align 4
2714
proc ted_sel_key_up
2715
  cmp ted_drag_k,1
2716
  je @f
2717
    call ted_sel_start
2718
    mov ted_drag_k,1
2719
  @@:
2720
  push dx
2721
    call ted_cur_move_up
2722
    cmp dl,8
2723
    jne @f
2724
      call ted_scroll_set_redraw
2725
    @@:
2726
  pop dx
2727
  call ted_sel_move
2728
  stdcall ted_draw,edi
2729
  ret
2730
endp
2731
 
2732
;input:
2733
; edi = pointer to tedit struct
2734
align 4
2735
proc ted_sel_key_down
2736
  cmp ted_drag_k,1
2737
  je @f
2738
    call ted_sel_start
2739
    mov ted_drag_k,1
2740
  @@:
2741
  push dx
2742
    call ted_cur_move_down
2743
    cmp dl,8
2744
    jne @f
2745
      call ted_scroll_set_redraw
2746
    @@:
2747
  pop dx
2748
  call ted_sel_move
2749
  stdcall ted_draw,edi
2750
  ret
2751
endp
2752
 
2753
;input:
2754
; edi = pointer to tedit struct
2755
align 4
2756
proc ted_sel_key_left
2757
  cmp ted_drag_k,1
2758
  je @f
2759
    call ted_sel_start
2760
  @@:
2761
  push dx
2762
    call ted_cur_move_left
2763
    call ted_sel_move
2764
    cmp ted_drag_k,1
2765
    je @f
2766
      mov ted_drag_k,1
2767
      mov dl,8
2768
    @@:
2769
    cmp dl,8
2770
    jne @f
2771
      call ted_scroll_set_redraw
2772
      stdcall ted_draw,edi
2773
      jmp .end_f
2774
    @@:
2775
      stdcall ted_draw_cur_line,edi
2776
    .end_f:
2777
  pop dx
2778
  ret
2779
endp
2780
 
2781
;input:
2782
; edi = pointer to tedit struct
2783
align 4
2784
proc ted_sel_key_right
2785
  cmp ted_drag_k,1
2786
  je @f
2787
    call ted_sel_start
2788
  @@:
2789
  push dx
2790
    call ted_cur_move_right
2791
    call ted_sel_move
2792
    cmp ted_drag_k,1
2793
    je @f
2794
      mov ted_drag_k,1
2795
      mov dl,8
2796
    @@:
2797
    cmp dl,8
2798
    jne @f
2799
      call ted_scroll_set_redraw
2800
      stdcall ted_draw,edi
2801
      jmp .end_f
2802
    @@:
2803
      stdcall ted_draw_cur_line,edi
2804
    .end_f:
2805
  pop dx
2806
  ret
2807
endp
2808
 
2809
;input:
2810
; edi = pointer to tedit struct
2811
;description:
2812
; this function need to optimize output
2813
align 4
2814
proc ted_draw_cursor_sumb
2815
  pushad
2816
 
2817
  mov eax,13 ;rect
2818
  mov ebx,ted_wnd_l
2819
  add ebx,ted_rec_l
2820
  mov edx,ted_cur_x
2821
  imul edx,ted_rec_w
2822
  add ebx,edx
2823
  shl ebx,16
2824
  add ebx,ted_rec_w
2825
 
2826
  mov ecx,ted_wnd_t ;calc rect -> y0,y1
2827
  add ecx,ted_rec_t
2828
  mov edx,ted_cur_y
2829
  imul edx,ted_rec_h
2830
  add ecx,edx
2831
  shl ecx,16
2832
  add ecx,ted_rec_h
2833
 
2834
  mov edx,ted_color_wnd_work
2835
  push ecx
2836
    call ted_sel_normalize
2837
 
2838
    mov esi,ted_scr_w
2839
	mov ecx,dword[esi+sb_offs_position]
2840
    sub ted_seln_y0,ecx
2841
    sub ted_seln_y1,ecx
2842
 
2843
    mov ecx,ted_cur_y
2844
    cmp ecx,ted_seln_y0
2845
    jl .no_cur_sel
2846
    cmp ecx,ted_seln_y1
2847
    jg .no_cur_sel
2848
    mov edx,ted_color_select ;меняем цвет фона на цвет выделения
2849
 
2850
    mov esi,ted_scr_h
2851
	cmp ecx,ted_seln_y0
2852
    jne @f
2853
      mov ecx,ted_cur_x
2854
      add ecx,dword[esi+sb_offs_position]
2855
      cmp ecx,ted_seln_x0
2856
      jge @f
2857
      mov edx,ted_color_wnd_work
2858
    @@:
2859
 
2860
    mov ecx,ted_cur_y
2861
    cmp ecx,ted_seln_y1
2862
    jne .no_cur_sel
2863
      mov ecx,ted_cur_x
2864
      add ecx,dword[esi+sb_offs_position]
2865
      cmp ecx,ted_seln_x1
2866
      jl .no_cur_sel
2867
      mov edx,ted_color_wnd_work
2868
 
2869
    .no_cur_sel:
2870
  pop ecx
2871
  int 0x40 ;рисование прямоугольника
2872
 
2873
  call ted_get_pos_by_cursor ;берем позицию символа
2874
  cmp ted_gp_opt,2
2875
  jne @f
2876
    mov eax,4
2877
    mov esi,1
2878
    ror ecx,16
2879
    mov bx,cx
2880
    add ebx,0x10001
2881
    call ted_get_symb_color
2882
    call ted_convert_invis_symb
2883
    int 0x40 ;рисование символа
2884
  @@:
2885
 
2886
  popad
2887
  ret
2888
endp
2889
 
2890
;input:
2891
; edx -> pointer to text
2892
; edi -> указатель на структуру tedit
2893
;output:
2894
; ecx = color
2895
; if ted_mode_color=0 then ecx=ted_color_wnd_text
2896
align 4
2897
ted_get_symb_color:
2898
  mov ecx,ted_color_wnd_text ;задаем цвет текста по умолчанию
2899
 
2900
  push eax edx
2901
  cmp ted_mode_color,0
2902
  je .exit
2903
    jmp .on_first
2904
    @@:
2905
      call ted_iterat_perv
2906
      cmp edx,ted_tex_1
2907
      jle .exit
2908
    .on_first:
2909
      xor eax,eax
2910
      mov al,byte[edx+1]
2911
      cmp al,0 ;если al=0 то цвет не меняется
2912
    je @b
2913
 
2914
    cmp eax,ted_colors_text_count
2915
    jge .exit
2916
 
2917
    shl ax,2 ;умножаем индекс цвета на 4 байта
2918
    mov ecx,ted_text_colors ;прибавляем смещение 1-го цвета
2919
    add ecx,eax
2920
    mov ecx,dword[ecx] ;устанавливаем текущий цвет текста по смещению
2921
  .exit:
2922
  pop edx eax
2923
  ret
2924
 
2925
;input:
2926
; edx = pointer to text
2927
; edi = pointer to tedit struct
2928
;description:
2929
; Функция преобразует невидимые символы в печатаемые на экране
2930
align 4
2931
ted_convert_invis_symb:
1458 IgorA 2932
	cmp ted_mode_invis,1
2933
	jne .end_f
2934
		cmp byte[edx],9
2935
		jne @f
2936
			lea edx,[ted_symbol_tab]
2937
		@@:
2938
		cmp byte[edx],13
2939
		jne @f
2940
			mov edx,edi
2941
			add edx,ted_offs_symbol_new_line
2942
		@@:
2943
	.end_f:
2944
	ret
1457 IgorA 2945
 
2946
;input:
2947
; edi = pointer to tedit struct
2948
align 4
2949
ted_scroll_set_redraw:
2950
	push eax
2951
	mov eax,ted_scr_w
2952
	mov dword[eax+sb_offs_redraw],1
2953
	mov eax,ted_scr_h
2954
	mov dword[eax+sb_offs_redraw],1
2955
	pop eax
2956
	ret
2957
 
2958
align 4
2959
proc ted_draw, edit:dword
1458 IgorA 2960
	locals
2961
		line_num dd ?
2962
	endl
2963
	pushad
2964
	mov edi,dword[edit]
1457 IgorA 2965
 
1458 IgorA 2966
	mov eax,4 ;draw text
2967
	mov ecx,ted_text_colors
2968
	mov ecx,dword[ecx]
1457 IgorA 2969
 
1458 IgorA 2970
	mov ebx,ted_wnd_l
2971
	add ebx,ted_rec_l
2972
	shl ebx,16
2973
	add ebx,ted_wnd_t
2974
	add ebx,ted_rec_t
2975
	add ebx,0x10001 ;добавляем отступы для выравнивания буквы по центру
1457 IgorA 2976
 
1458 IgorA 2977
	call ted_sel_normalize ;need before draw select
2978
	mov esi,ted_scr_w
2979
	mov esi,dword[esi+sb_offs_position]
2980
	mov dword[line_num],esi
1457 IgorA 2981
 
1458 IgorA 2982
	stdcall ted_clear_line_before_draw, edi,ebx,1,esi
2983
	call ted_get_first_visible_pos
2984
	cmp edx,0
2985
	je .no_draw_text
2986
	mov esi,1 ;длинна выводимого текста по 1-му символу
2987
	@@:
2988
		call ted_iterat_next
2989
		cmp edx,ted_tex_1
2990
		jle .no_draw_text
1457 IgorA 2991
 
1458 IgorA 2992
		; *** цветовая разметка
2993
		cmp ted_mode_color,0
2994
		je .no_col_change
2995
		cmp byte[edx+1],0
2996
		je .no_col_change
2997
			call ted_get_symb_color
2998
		.no_col_change:
1457 IgorA 2999
 
1458 IgorA 3000
		cmp byte [edx],13
3001
		jne .no_13
3002
			cmp ted_mode_invis,1
3003
			jne .no_invis
3004
				push edx
3005
				mov edx,edi
3006
				add edx,ted_offs_symbol_new_line
3007
				int 0x40
3008
				pop edx
3009
			.no_invis:
3010
			add ebx,ted_rec_h
3011
			;optimized output \/
3012
			mov eax,ted_wnd_h
3013
			add eax,ted_wnd_t
3014
			cmp bx,ax
3015
			jg .no_draw_text
3016
			mov eax,4
3017
			;optimized output /\
3018
			and ebx,0xffff
3019
			ror ebx,16
3020
			add ebx,ted_wnd_l
3021
			add ebx,ted_rec_l
3022
			inc ebx
3023
			ror ebx,16
3024
			inc dword[line_num] ;increment line number
3025
			stdcall ted_clear_line_before_draw,edi,ebx,1,dword[line_num]
3026
			call ted_opt_draw_line_left
3027
			jmp @b
3028
		.no_13:
1457 IgorA 3029
 
1458 IgorA 3030
		int 0x40
3031
		ror ebx,16
3032
		add ebx,ted_rec_w
3033
		mov esi,ted_wnd_l
3034
		add esi,ted_wnd_w
3035
		cmp bx,si
3036
		jl .no_opt
3037
			call ted_opt_draw_line_right
3038
		.no_opt:
3039
		mov si,1
3040
		ror ebx,16
3041
		jmp @b
3042
	.no_draw_text:
1457 IgorA 3043
 
1458 IgorA 3044
	stdcall ted_clear_line_before_draw,edi,ebx,0,dword[line_num]
3045
	call ted_draw_line_numbers
3046
	call ted_draw_main_cursor
1457 IgorA 3047
 
3048
;---------------------------------------------
3049
; set all_redraw flag for draw all ScrollBar
3050
; In some cases it is necessity to draw only the area
3051
; of moving of a "runner", for acceleration of output -
3052
; in this case the flag needs to be reset to 0 (zero).
3053
	mov eax,ted_scr_h
3054
	mov esi,ted_scr_w
3055
	mov dword[eax+sb_offs_all_redraw],1
3056
	mov dword[esi+sb_offs_all_redraw],1
3057
 
3058
; рисование полос прокрутки
3059
	stdcall scroll_bar_horizontal.draw,eax ;[scrollbar_hor_draw]
3060
	stdcall scroll_bar_vertical.draw,esi ;[scrollbar_ver_draw]
3061
; reset all_redraw flag
3062
	mov dword[eax+sb_offs_all_redraw],0
3063
	mov dword[esi+sb_offs_all_redraw],0
3064
;---------------------------------------------
3065
 
3066
  ;left-bottom square
3067
  mov ebx,ted_wnd_l
3068
  shl ebx,16
3069
  add ebx,ted_rec_l
3070
  mov ecx,ted_wnd_t
3071
  add ecx,ted_wnd_h
3072
  shl ecx,16
3073
  mov cx,word[eax+sb_offs_size_y]
3074
  inc cx
3075
  mov edx,ted_color_wnd_capt ;[sc.work]
3076
  mov eax,13
3077
  int 0x40
3078
 
3079
	;right-bottom square
3080
	mov ebx,ted_wnd_l
3081
	add ebx,ted_wnd_w
3082
	shl ebx,16
3083
	mov bx,word[esi+sb_offs_size_x]
3084
	inc bx
3085
	int 0x40
3086
 
3087
	cmp ted_fun_draw_panel_find,0
3088
	je @f
3089
		call ted_fun_draw_panel_find
3090
	@@:
3091
	cmp ted_fun_draw_panel_syntax,0
3092
	je @f
3093
		call ted_fun_draw_panel_syntax
3094
	@@:
3095
	popad
3096
	ret
3097
endp
3098
 
3099
;input:
3100
; edi = pointer to tedit struct
3101
align 4
3102
proc ted_draw_main_cursor
3103
  pushad
3104
 
3105
  mov eax,13 ;draw cursor
3106
  mov ecx,ted_wnd_t ;calc rect -> y0,y1
3107
  add ecx,ted_rec_t
3108
  mov edx,ted_cur_y
3109
  imul edx,ted_rec_h
3110
  add ecx,edx
3111
 
3112
  cmp ted_cur_ins,1 ;проверка режима работы курсора (обычный или вставка)
3113
  jne @f
3114
    mov edx,ted_rec_h
3115
    inc edx   ;1->1, 3->2, 5->3, ...
3116
    shr edx,1 ;edx = высота строки деленная на 2 (когда курсор не полный)
3117
    add ecx,edx
3118
  @@:
3119
  shl ecx,16
3120
  add ecx,ted_rec_h
3121
  cmp ted_cur_ins,1
3122
  jne @f
3123
    shr cx,1 ;делим высоту курсора на 2
3124
  @@:
3125
 
3126
  mov ebx,ted_wnd_l ;calc rect -> x0,x1
3127
  add ebx,ted_rec_l
3128
  mov edx,ted_cur_x
3129
  imul edx,ted_rec_w
3130
  add ebx,edx
3131
  shl ebx,16
3132
  add ebx,ted_rec_w
3133
 
3134
  mov edx,ted_color_cursor
3135
  int 0x40 ;вывод курсора
3136
 
3137
  call ted_get_pos_by_cursor
3138
  cmp ted_gp_opt,2
3139
  jne @f
3140
    mov eax,4 ;draw text
3141
    mov esi,1
3142
    ror ecx,16
3143
    mov bx,cx
3144
    add ebx,0x10001
3145
    cmp ted_cur_ins,1
3146
    jne .no_up_tetx
3147
      mov ecx,ted_rec_h
3148
      inc cx ; 1->1, 3->2, 5->3, ...
3149
      shr cx,1
3150
      sub bx,cx
3151
    .no_up_tetx:
3152
    mov ecx,ted_color_cur_text
3153
    call ted_convert_invis_symb
3154
    int 0x40
3155
  @@:
3156
 
3157
  mov eax,4
3158
  mov ebx,ted_wnd_l
3159
  add ebx,ted_rec_l
3160
  shl ebx,16
3161
  add ebx,ted_wnd_t
3162
  add ebx,3
3163
  mov ecx,ted_color_wnd_bord
3164
  or  ecx,0x80000000
3165
  lea edx,[txtRow]
3166
  int 0x40 ;вывод подписи 'Строка'
3167
 
3168
  add ebx,0x500000
3169
  lea edx,[txtCol]
3170
  int 0x40 ;вывод подписи 'Знак'
3171
 
3172
  cmp ted_tim_undo,0
3173
  je @f
3174
    add ebx,0x500000
3175
    lea edx,[txtOtm]
3176
    int 0x40
3177
    sub ebx,0x500000
3178
  @@:
3179
 
3180
  call ted_draw_buffer
3181
  call ted_draw_help_f1
3182
 
3183
  mov eax,47 ;draw cursor coords
3184
  mov esi,ted_color_wnd_bord
3185
  or  esi,0x40000000
3186
 
3187
  mov edx,ebx
3188
  ror edx,16
3189
  sub edx,35
3190
  ror edx,16
3191
  ;add edx,3
3192
  mov ebx,0x40000 ;Row=...
3193
  mov ecx,ted_scr_w
3194
  mov ecx,dword[ecx+sb_offs_position]
3195
  add ecx,ted_cur_y
3196
  inc ecx
3197
 
3198
push edi
3199
  mov edi,ted_color_wnd_work
3200
  int 0x40 ;вывод числа текущей строки
3201
pop edi
3202
 
3203
  ;mov ebx,0x40000 ;Col=...
3204
  mov ecx,ted_scr_h
3205
  mov ecx,dword[ecx+sb_offs_position]
3206
  add ecx,ted_cur_x
3207
  inc ecx
3208
  add edx,0x500000
3209
push edi
3210
  mov edi,ted_color_wnd_work
3211
  int 0x40 ;вывод числа знаков
3212
pop edi
3213
 
3214
  cmp ted_tim_undo,0
3215
  je @f
3216
    mov ecx,ted_tim_undo
3217
    add edx,0x500000
1458 IgorA 3218
	mov edi,ted_color_wnd_work ;портим регистр edi, но в конце функции это уже не важно
3219
    int 0x40 ;вывод числа отмененных действий
1457 IgorA 3220
  @@:
3221
 
3222
  popad
3223
  ret
3224
endp
3225
 
3226
;input:
3227
; edi = pointer to tedit struct
3228
proc ted_draw_buffer
3229
	pushad
3230
 
3231
	mov eax,ted_buffer
3232
	cmp byte[eax],0 ;смотрим 1-й символ из буфера
3233
	je @f
1458 IgorA 3234
		mov ebx,ted_rec_l
1457 IgorA 3235
		add bx,300
1458 IgorA 3236
		cmp ebx,ted_wnd_w ;сравниваем координату для вывод текста
3237
		jge @f ;подпись не влазит в окно
3238
 
3239
		add ebx,ted_wnd_l
1457 IgorA 3240
		shl ebx,16
3241
		add ebx,ted_wnd_t
3242
		add ebx,3
3243
		mov ecx,ted_color_wnd_bord
3244
		or ecx,0x40000000
3245
 
3246
		mov edx,ted_buffer
3247
		mov esi,edx
3248
		mov edi,ted_color_wnd_work ;edi - destroy not pointer to tedit
3249
		call tl_strlen
3250
		;cmp eax,0 ;буфер пуст
3251
		;je @f
3252
		cmp eax,20
3253
		jle .crop_buf
3254
			mov eax,20 ;обрезка подписи до 20 символов
3255
		.crop_buf:
3256
		mov esi,eax
3257
		mov eax,4
3258
		int 0x40 ;вывод содержимого буфера
3259
 
3260
		sub ebx,50 shl 16
3261
		lea edx,[txtBuf]
3262
		mov esi,edx
3263
		call tl_strlen
3264
		mov esi,eax
3265
		mov eax,4
3266
		xor ecx,0x40000000 ;убираем цвет фона
3267
		int 0x40 ;вывод подписи для буфера
3268
	@@:
3269
	popad
3270
	ret
3271
endp
3272
 
3273
;input:
3274
; edi = pointer to tedit struct
3275
align 4
3276
proc ted_draw_help_f1
1458 IgorA 3277
	pushad
3278
	cmp ted_rec_t,13 ;минимальная высота для рисования справки
3279
	jle @f
3280
		mov eax,13 ;clear place before draw help
3281
		mov ebx,ted_wnd_l
3282
		add ebx,ted_rec_l
3283
		shl ebx,16
3284
		add ebx,ted_wnd_w
3285
		sub ebx,ted_rec_l
3286
		mov ecx,ted_wnd_t
3287
		add ecx,13
3288
		shl ecx,16
3289
		add ecx,ted_rec_h
3290
		mov edx,ted_color_wnd_capt
3291
		int 0x40
1457 IgorA 3292
 
1458 IgorA 3293
	cmp ted_help_id,-1
3294
	je @f
3295
		mov eax,ted_help_id
3296
		ColToIndexOffset eax,edx
1457 IgorA 3297
 
1458 IgorA 3298
		;SetCoordinates
3299
		mov ebx,ted_wnd_l
3300
		add ebx,ted_rec_l
3301
		shl ebx,16
3302
		add ebx,ted_wnd_t
3303
		add ebx,13 ;=3+10
1457 IgorA 3304
 
1458 IgorA 3305
		;SetTextColor
3306
		xor eax,eax
3307
		mov al,byte[edx+MAX_COLOR_WORD_LEN+6]
3308
		shl ax,2
3309
		mov ecx,ted_text_colors
3310
		add ecx,eax
3311
		mov ecx,dword[ecx]
3312
		or	ecx,0xc0000000 ;SetTextStyles
3313
		mov esi,edi
3314
			mov edi,ted_color_wnd_work
3315
			mov eax,4
3316
			int 0x40
3317
		mov edi,esi
1457 IgorA 3318
 
1458 IgorA 3319
		;*** draw help string ***
3320
		mov ecx,ted_color_wnd_bord
3321
		or ecx,0x80000000
3322
		mov edx,dword[edx+MAX_COLOR_WORD_LEN]
3323
		cmp edx,0
3324
		je @f
3325
			add edx,ted_help_text_f1
3326
			add ebx,0x500000
3327
			int 0x40
3328
	@@:
3329
	popad
3330
	ret
1457 IgorA 3331
endp
3332
 
3333
;input:
3334
; edi = pointer to tedit struct
3335
align 4
3336
proc ted_draw_line_numbers
3337
  pushad
3338
 
3339
  ;top panel with caption
3340
  mov ebx,ted_wnd_l
3341
;  add ebx,ted_rec_l
3342
  shl ebx,16
3343
  add ebx,ted_wnd_w
3344
;  sub ebx,ted_rec_l
3345
  mov edx,ted_color_wnd_work
3346
  mov ecx,ted_wnd_t
3347
  shl ecx,16
3348
  add ecx,ted_rec_t
3349
  mov eax,13
3350
  mov edx,ted_color_wnd_capt
3351
  int 0x40
3352
 
3353
  ;line numbers
3354
  mov ebx,0x40000 ;format
3355
  mov ecx,ted_scr_w
3356
  mov ecx,dword[ecx+sb_offs_position]
3357
  inc ecx
3358
  mov edx,3
3359
  add edx,ted_wnd_l
3360
  rol edx,16
3361
  add edx,ted_wnd_t
3362
  add edx,ted_rec_t
3363
  @@:
3364
 
3365
push ebx ecx edx
3366
  ;left panel with numbers
3367
  mov ebx,ted_wnd_l
3368
  shl ebx,16
3369
  add ebx,ted_rec_l
3370
  mov ecx,ted_rec_h
3371
  rol ecx,16
3372
  mov cx,dx
3373
  rol ecx,16
3374
  mov eax,13
3375
  mov edx,ted_color_wnd_capt
3376
  int 0x40 ;рисуем прямоугольник под номером строки
3377
pop edx ecx ebx
3378
 
3379
    mov eax,47
3380
    mov esi,ted_color_wnd_bord
3381
    int 0x40 ;рисуем номер строки
3382
    inc ecx
3383
    add edx,ted_rec_h
3384
    sub edx,ted_wnd_t
3385
	mov esi,edx
3386
	and esi,0xffff
3387
    cmp esi,ted_wnd_h
3388
    jge @f
3389
    add edx,ted_wnd_t
3390
    jmp @b
3391
  @@:
3392
 
3393
  popad
3394
  ret
3395
endp
3396
 
3397
;output:
3398
; ah = symbol
3399
align 4
3400
proc KeyConvertToASCII, table:dword
1464 IgorA 3401
	push ebx
3402
	mov ebx,dword[table] ;convert scan to ascii
3403
	ror ax,8
3404
	xor ah,ah
3405
	add bx,ax ;? ebx,eax
3406
	mov ah,byte[ebx]
3407
	pop ebx
3408
	ret
1457 IgorA 3409
endp
3410
 
3411
align 4
3412
proc ted_draw_cur_line, edit:dword
3413
  pushad
3414
    mov edi,dword[edit]
3415
 
3416
    mov ebx,ted_wnd_l
3417
    add ebx,ted_rec_l
3418
    shl ebx,16
3419
    mov eax,ted_cur_y
3420
    imul eax,ted_rec_h
3421
	mov bx,ax
3422
    add ebx,ted_wnd_t
3423
    add ebx,ted_rec_t ;ebx - координаты для прямоугольника очистки линии
3424
	add ebx,0x10001   ;добавляем отступы для выравнивания буквы по центру
3425
 
3426
    call ted_sel_normalize ;need before draw select
3427
	mov ecx,ted_cur_y
3428
	mov eax,ted_scr_w
3429
    add ecx,dword[eax+sb_offs_position]
3430
    stdcall ted_clear_line_before_draw,edi,ebx,1,ecx
3431
 
3432
    mov eax,ted_scr_h
3433
	mov esi,dword[eax+sb_offs_position]
3434
    call ted_get_pos_by_coords
3435
 
3436
  cmp ted_gp_opt,2
3437
  jne .no_draw_text
3438
;  mov eax,4 ;draw text
3439
  call ted_get_symb_color
3440
  mov esi,1 ;draw 1 symbol
3441
  @@:
3442
    ;call ted_iterat_next
3443
    cmp edx,ted_tex_1
3444
    jle .no_draw_text
3445
 
3446
    ; *** цветовая разметка
3447
    cmp ted_mode_color,0
3448
    je .no_col_change
3449
    cmp byte[edx+1],0
3450
    je .no_col_change
3451
      call ted_get_symb_color
3452
    .no_col_change:
3453
 
3454
    mov eax,4 ;draw text
3455
    cmp byte [edx],13
3456
    jne .no_13
3457
      cmp ted_mode_invis,1
3458
      jne .no_draw_text
3459
 push edx
3460
 mov edx,edi
3461
 add edx,ted_offs_symbol_new_line
3462
 int 0x40
3463
 pop edx
3464
      jmp .no_draw_text
3465
    .no_13:
3466
 
3467
    int 0x40
3468
    ror ebx,16
3469
    add ebx,ted_rec_w
3470
    mov eax,ted_wnd_w
3471
    add eax,ted_wnd_l ;ax = отступ по оси x
3472
    cmp bx,ax
3473
    jge .no_draw_text ;Opt
3474
    ror ebx,16
3475
    call ted_iterat_next
3476
    jmp @b
3477
  .no_draw_text:
3478
 
3479
  call ted_draw_main_cursor
3480
  popad
3481
  ret
3482
endp
3483
 
3484
;input:
3485
; eax - text need find
3486
; bl - first symbol to find
3487
; edx - first symbol pointer
3488
; edi - pointer to tedit struct
3489
;output:
3490
; bh - rezult
3491
; edx - last text position (if find sucess)
3492
; esi - first symbol pointer
3493
;description:
3494
; Функция проверяет совпадает ли текст в буфере eax
3495
; с текстом редактора по указателю edx.
3496
; Стандартные функции (напр. strcmp) тут не подойдут, потому что
3497
; в памяти редактора текст содержится не в виде ascii строк.
3498
align 4
3499
ted_get_find_rezult:
3500
  push eax
3501
    mov bh,1
3502
    mov esi,edx ;copy edx
3503
    @@:
3504
      cmp byte[edx],bl
3505
      jne .no_text
3506
 
3507
      inc eax ;*** get next symbol (in find text) ***
3508
      mov bl,byte[eax]
3509
      cmp bl,0
3510
      je @f ;end of find text
3511
 
3512
      call ted_iterat_next ;*** get next symbol (in editor text) ***
3513
      cmp edx,ted_tex_1
3514
      jle @f ;end of editor text
3515
 
3516
      jmp @b
3517
      .no_text:
3518
	xor bh,bh
3519
	mov edx,esi ;restore edx
3520
    @@:
3521
  pop eax
3522
  mov bl,byte[eax] ;restore bl
3523
  ret
3524
 
3525
;input:
3526
;  clear_o - если =1 очистить одну строку, =0 очистить все строки окна до низу
3527
align 4
3528
proc ted_clear_line_before_draw, edit:dword, coords:dword, clear_o:dword, numb_lin:dword
3529
	pushad
3530
	mov edi,dword[edit]
3531
	mov ebx,dword[coords]	;ebx = x*2^16+y coords to left up point clear line
3532
	mov esi,dword[numb_lin] ;esi - number text line
3533
 
3534
	sub ebx,0x10001 ;отнимаем отступы для выравнивания буквы по центру
3535
	cmp dword[clear_o],0
3536
	jne @f
3537
		add ebx,ted_rec_h
3538
		inc esi
3539
		ror ebx,16
3540
		xor bx,bx
3541
		add ebx,ted_wnd_l
3542
		add ebx,ted_rec_l ;bx = ted_wnd_l+ted_rec_l
3543
		ror ebx,16
3544
	@@:
3545
 
3546
	mov eax,ted_wnd_h
3547
	add eax,ted_wnd_t
3548
	cmp ax,bx
3549
	jl .no_clear
3550
	sub ax,bx
3551
 
3552
	mov cx,bx
3553
	shl ecx,16
3554
 
3555
	xor bx,bx
3556
	add ebx,ted_wnd_w
3557
	sub ebx,ted_rec_l
3558
	xor cx,cx
3559
	add ecx,ted_rec_h
3560
	mov edx,ted_color_wnd_work
3561
 
3562
	cmp dword[clear_o],0
3563
	je .pusto
3564
	cmp ax,cx
3565
	jge @f
3566
	.pusto:
3567
		mov cx,ax
3568
	@@:
3569
 
3570
	call ted_is_select
3571
	cmp al,0
3572
	je @f
3573
	cmp ted_seln_y0,esi
3574
	jg @f
3575
	cmp ted_seln_y1,esi
3576
	jl @f
3577
		mov edx,ted_color_select ;draw selected line
3578
	@@:
3579
 
3580
	mov eax,13 ;rect
3581
	int 0x40
3582
 
3583
	call ted_is_select
3584
	cmp al,0
3585
	je .no_clear
3586
 
3587
	mov al,13 ;rect
3588
	xor cx,cx
3589
	add ecx,ted_rec_h
3590
	cmp ted_seln_y0,esi
3591
	jne @f
3592
		push bx esi
3593
		mov edx,ted_seln_x0 ; верхняя полоса (затирает слева)
3594
		mov esi,ted_scr_h
3595
		cmp edx,dword[esi+sb_offs_position]
3596
		jle .in_wnd
3597
			sub edx,dword[esi+sb_offs_position]
3598
			imul edx,ted_rec_w
3599
			mov bx,dx
3600
			jmp .no_wnd
3601
		.in_wnd:
3602
		mov bx,0
3603
		.no_wnd:
3604
		mov edx,ted_color_wnd_work
3605
		int 0x40
3606
		pop esi bx
3607
	@@:
3608
	cmp ted_seln_y1,esi
3609
	jne @f
3610
		push esi
3611
		mov edx,ted_seln_x1 ; нижняя полоса (затирает справа)
3612
		mov esi,ted_scr_h
3613
		cmp edx,dword[esi+sb_offs_position]
3614
		jle .in_wnd2
3615
			sub edx,dword[esi+sb_offs_position]
3616
			imul edx,ted_rec_w
3617
			sub bx,dx
3618
			shl edx,16
3619
			add ebx,edx
3620
		.in_wnd2:
3621
 
3622
		mov edx,ted_color_wnd_work
3623
		int 0x40
3624
		pop esi
3625
	@@:
3626
 
3627
	.no_clear:
3628
	popad
3629
	ret
3630
endp
3631
 
3632
;input:
3633
; edi = pointer to tedit struct
3634
;output:
3635
; ecx = новый цвет символа
3636
; edx = pointer to symbol
3637
; edx = 0 if text not in screen
3638
align 4
3639
ted_get_first_visible_pos:
3640
	push eax ecx
3641
	mov eax,ted_scr_w
3642
	mov edx,ted_tex
3643
	xor ecx,ecx
3644
	@@:
3645
		cmp ecx,dword[eax+sb_offs_position]
3646
		je @f
3647
		call ted_iterat_next
3648
		cmp edx,ted_tex_1
3649
		jle @f
3650
		cmp byte [edx],13
3651
		jne @b
3652
		inc ecx
3653
		jmp @b
3654
	@@:
3655
 
3656
	cmp ecx,dword[eax+sb_offs_position]
3657
	je @f
3658
		xor edx,edx
3659
	@@:
3660
	cmp ecx,dword[eax+sb_offs_max_area]
3661
	jle @f
3662
		mov dword[eax+sb_offs_max_area],ecx
3663
	@@:
3664
	pop ecx eax
3665
	call ted_opt_draw_line_left
3666
	ret
3667
 
3668
;input:
3669
; edx = pointer to symbol
3670
; edi = pointer to tedit struct
3671
;output:
3672
; ecx = цвет символа
3673
; edx = указатель на первый левый символ
3674
;description:
3675
; функция нужна для оптимизации вывода текста
3676
align 4
3677
proc ted_opt_draw_line_left
3678
  push ebx
3679
 
3680
  mov ebx,ted_scr_h
3681
  mov ebx,dword[ebx+sb_offs_position]
3682
  cmp ebx,0
3683
  je .ret_f
3684
  push eax
3685
  mov eax,edx
3686
 
3687
  cmp edx,ted_tex
3688
  jne @f
3689
    call ted_iterat_next
3690
    jmp .beg_cycle
3691
  @@:
3692
 
3693
  cmp ebx,0
3694
  je @f
3695
 
3696
  cmp byte[edx],13
3697
  jne @f
3698
    call ted_iterat_next
3699
    .beg_cycle:
3700
  @@:
3701
    cmp edx,ted_tex_1
3702
    jle @f
3703
    cmp byte[edx],13
3704
    je @f
3705
    cmp ebx,0
3706
    je @f
3707
;--------------------------------------
3708
xor eax,eax ;eax будет меняться
3709
mov al,byte[edx+1]
3710
cmp al,0
3711
je .no_color
3712
cmp eax,ted_colors_text_count
3713
jge .no_color
3714
  xor ecx,ecx
3715
  mov cl,byte[edx+1]
3716
  shl cx,2
3717
  add ecx,ted_text_colors
3718
  mov ecx,dword[ecx]
3719
.no_color:
3720
;--------------------------------------
3721
    mov eax,edx
3722
    call ted_iterat_next
3723
    dec ebx
3724
    jmp @b
3725
  @@:
3726
    mov edx,eax
3727
  pop eax
3728
  .ret_f:
3729
  call ted_get_symb_color
3730
  pop ebx
3731
  ret
3732
endp
3733
 
3734
;input:
3735
; edx = pointer to symbol
3736
; edi = pointer to tedit struct
3737
;output:
3738
; ecx = symbol color
3739
; edx = pointer to 13 symbol
3740
;description:
3741
; функция нужна для оптимизации вывода текста
3742
align 4
3743
proc ted_opt_draw_line_right
3744
	push eax
3745
	mov eax,edx
3746
	@@:
3747
		cmp edx,ted_tex_1
3748
		jle @f
3749
		cmp byte[edx],13
3750
		je @f
3751
		mov eax,edx
3752
		call ted_iterat_next
3753
		jmp @b
3754
	@@:
3755
	mov edx,eax ;perv sumbol
3756
	call ted_get_symb_color
3757
 
3758
	pop eax
3759
	ret
3760
endp
3761
 
3762
align 4
3763
proc ted_mouse, edit:dword
3764
	pushad
3765
	mov edi,dword[edit]
3766
 
3767
	;обрабатываем скроллинги
3768
	mov edx,ted_scr_h
3769
	mov ecx,ted_scr_w
3770
 
3771
	cmp word[edx+sb_offs_delta2],0
3772
	jne .horizontal
3773
 
3774
	mov eax,dword[ecx+sb_offs_max_area]
3775
	cmp eax,dword[ecx+sb_offs_cur_area]
3776
	jbe .horizontal
3777
	; mouse event for Vertical ScrollBar
3778
	stdcall scroll_bar_vertical.mouse,ecx ;[scrollbar_ver_mouse]
3779
	cmp dword[ecx+sb_offs_redraw],0
3780
	je @f
3781
		mov dword[ecx+sb_offs_redraw],0
3782
		stdcall ted_draw,edi
3783
		jmp .no_in_wnd
3784
	@@:
3785
	cmp word[ecx+sb_offs_delta2],0
3786
	jne .no_in_wnd
3787
	.horizontal:
3788
	mov eax,dword[edx+sb_offs_max_area]
3789
	cmp eax,dword[edx+sb_offs_cur_area]
3790
	jbe .other
3791
	; mouse event for Horizontal ScrollBar
3792
	stdcall scroll_bar_horizontal.mouse,edx ;[scrollbar_hor_mouse]
3793
	cmp dword[edx+sb_offs_redraw],0
3794
	je .other
3795
		mov dword[edx+sb_offs_redraw],0
3796
		stdcall ted_draw,edi
3797
		jmp .no_in_wnd
3798
	.other:
3799
	cmp word[ecx+sb_offs_delta2],0
3800
	jne .no_in_wnd
3801
	cmp word[edx+sb_offs_delta2],0
3802
	jne .no_in_wnd
3803
 
3804
	;обрабатываем окно редактора
3805
	mcall 37,2 ;get mouse buttons
3806
	cmp al,1
3807
	jne @f
3808
		mcall 37,1 ;get mouse coords
3809
		mov ebx,ted_wnd_t
3810
		add ebx,ted_rec_t
3811
		cmp ax,bx
3812
		jl @f ;y_mouse
3813
 
3814
		sub ebx,ted_rec_t
3815
		add ebx,ted_wnd_h
3816
		cmp bx,ax
3817
		jl @f ;y_mouse>y_wnd
3818
 
3819
		mov ebx,ted_wnd_l
3820
		add ebx,ted_rec_l
3821
		mov ecx,eax
3822
		shr ecx,16
3823
		cmp cx,bx
3824
		jl @f ;x_mouse
3825
 
3826
		sub ebx,ted_rec_l
3827
		add ebx,ted_wnd_w
3828
		cmp bx,cx
3829
		jl @f ;x_mouse>x_wnd
3830
 
3831
		call ted_draw_cursor_sumb
3832
		call ted_wnd_main_click
3833
		jmp .no_in_wnd
3834
	@@:
1458 IgorA 3835
	mov edx,ted_el_focus
3836
	cmp dword[edx],edi
3837
	jne @f
3838
		call ted_wnd_main_mouse_scroll ;смотрим на прокрутку колеса мыши
3839
	@@:
1457 IgorA 3840
	cmp ted_drag_m,0
3841
	je .no_in_wnd
3842
		mov ted_drag_m,0
3843
		stdcall ted_draw,edi
3844
		cmp ted_fun_draw_panel_buttons,0
3845
		je .no_in_wnd
3846
			call ted_fun_draw_panel_buttons
3847
	.no_in_wnd:
3848
	popad
3849
	ret
3850
endp
3851
 
3852
;input:
3853
; eax -> (x,y)
3854
; edi -> указатель на структуру tedit
3855
;description:
3856
; функция вызывется при нажатии кнопкой мыши и попадении курсором в окно редактора
3857
align 4
3858
ted_wnd_main_click:
1458 IgorA 3859
	push ebx ecx edx
3860
	mov ebx,ted_el_focus
3861
	mov dword[ebx],edi ;ставим фокус
1457 IgorA 3862
 
3863
  push eax
3864
    shr eax,16
3865
    and eax,0xffff
3866
    sub eax,ted_wnd_l
3867
    sub eax,ted_rec_l
3868
 
3869
    xor edx,edx
3870
    mov ecx,ted_rec_w
3871
    div cx
3872
    ;inc eax
3873
	mov ebx,ted_scr_h
3874
    cmp eax,dword[ebx+sb_offs_cur_area]
3875
    jle @f
3876
      mov eax,dword[ebx+sb_offs_cur_area]
3877
    @@:
3878
    ;dec eax
3879
    mov ted_cur_x,eax
3880
  pop eax
3881
 
3882
  push eax
3883
    and eax,0xffff
3884
    sub eax,ted_wnd_t
3885
    sub eax,ted_rec_t
3886
 
3887
    xor edx,edx
3888
    mov ecx,ted_rec_h
3889
    div cx
3890
    inc eax
3891
	mov ebx,ted_scr_w
3892
    cmp eax,dword[ebx+sb_offs_cur_area]
3893
    jle @f
3894
      mov eax,dword[ebx+sb_offs_cur_area]
3895
    @@:
3896
    dec eax
3897
    mov ted_cur_y,eax
3898
  pop eax
3899
 
1458 IgorA 3900
	cmp ted_drag_m,0
3901
	je @f
3902
		call ted_sel_move
3903
		jmp .sel_move
3904
	@@:
3905
		mov ted_drag_m,1
3906
		call ted_sel_start
3907
	.sel_move:
3908
	pop edx ecx ebx
3909
	ret
1457 IgorA 3910
 
3911
;input:
3912
; edi = pointer to tedit struct
3913
align 4
3914
ted_wnd_main_mouse_scroll:
3915
	push eax ebx ecx
1458 IgorA 3916
	mcall 37,7 ;прокрутка колеса мыши
1457 IgorA 3917
	cmp ax,0
3918
	je .no_scroll
3919
		mov ecx,ted_scr_w
3920
		mov ebx,dword[ecx+sb_offs_position] ;copy old scroll position
3921
		and eax,0xffff
3922
		btr ax,15
3923
		jae @f
3924
			or eax,0xffff8000
1458 IgorA 3925
		@@:
3926
		add dword[ecx+sb_offs_position],eax
1457 IgorA 3927
 
1458 IgorA 3928
		mov eax,[ecx+sb_offs_position]
3929
		cmp eax,[ecx+sb_offs_max_area]
3930
		jb @f
3931
			mov dword[ecx+sb_offs_position],ebx ;if scroll position out of range
3932
			jmp .no_scroll
3933
		@@:
3934
		stdcall ted_draw,edi
1457 IgorA 3935
	.no_scroll:
3936
	pop ecx ebx eax
3937
	ret
3938
 
3939
align 4
3940
proc ted_but_save_file, edit:dword, file:dword, f_name:dword
3941
  pushad
3942
  mov edi,dword[edit]
3943
 
3944
  stdcall ted_can_save,edi
3945
  cmp al,0
3946
  je .no_save
3947
 
3948
  mov ecx,ted_max_chars
3949
  call mem_Alloc
3950
  push eax ;запоминаем указатель на выделенную память
3951
 
3952
  mov edx,ted_tex
3953
  xor ecx,ecx
3954
  @@:
3955
    call ted_iterat_next
3956
    cmp edx,ted_tex_1
3957
    jle @f ;edx = ted_tex or edx = ted_tex+sizeof.symbol
3958
    mov bl,[edx]
3959
    mov byte[eax],bl
3960
    inc eax
3961
    inc ecx
3962
    jmp @b
3963
  @@:
3964
 
3965
  cmp ecx,0
3966
  je @f
3967
    mov ebx,dword[file]
3968
    pop eax ;записываем указатель на выделенную память
3969
    mov dword[ebx+16],eax
3970
    push eax ;обратно запоминаем указатель на выделенную память
3971
    mov eax,70
3972
    mov dword[ebx], 2
3973
    mov dword[ebx+4], 0
3974
    mov dword[ebx+8], 0
3975
    mov dword[ebx+12], ecx
3976
    mov  byte[ebx+20], 0
3977
    push dword[f_name]
3978
    pop dword[ebx+21]
3979
    int 0x40
3980
 
3981
    mov ted_err_save,al
3982
 
3983
    cmp eax,0
3984
    je .no_msg
3985
;    cmp eax,6
3986
;    je @f
3987
      cmp ax,10
3988
      jl .zifra_0_9
3989
	mov al,'?'
3990
	sub ax,48
3991
      .zifra_0_9:
3992
      add ax,48
3993
cmp ted_fun_save_err,0
3994
je @f
3995
call ted_fun_save_err
3996
      jmp @f
3997
    .no_msg:
3998
    m2m ted_tim_ls,ted_tim_ch
3999
  @@:
4000
 
4001
  pop ecx ;записываем указатель на выделенную память
1464 IgorA 4002
  stdcall mem_Free,ecx
1457 IgorA 4003
  .no_save:
4004
  popad
4005
  ret
4006
endp
4007
}