Subversion Repositories Kolibri OS

Rev

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