Subversion Repositories Kolibri OS

Rev

Rev 7576 | Rev 7579 | 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
7497 IgorA 3
; файл последний раз изменялся 21.10.2018 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
 
23
TED_PANEL_NULL	 equ 0 ;нет открытой панели
24
TED_PANEL_FIND	 equ 1 ;панель поиска
25
TED_PANEL_SYNTAX equ 2 ;панель выбора файлов подсветки
7576 IgorA 26
TED_PANEL_REPLACE equ 3 ;панель замены
1457 IgorA 27
TED_PANEL_WIDTH  equ 150 ;ширина панели
28
 
4988 IgorA 29
TED_LINES_IN_NEW_FILE equ 30 ;число строк в новом файле
1457 IgorA 30
MAX_COLOR_WORD_LEN equ 40
31
;------------------------------------------------------------------------------
32
struct TexSelect
4988 IgorA 33
	x0 dd ?
34
	y0 dd ?
35
	x1 dd ?
36
	y1 dd ?
1457 IgorA 37
ends
38
 
39
struct TexColViv
2102 IgorA 40
	Text  rb MAX_COLOR_WORD_LEN ; слово для подсветки
41
	f1    dd 0 ; справка по слову
42
	flags db ? ; f1+4 флаги используемые при выделении
43
	endc  db ? ; f1+5 символ конца выделения (используется при flags&4)
44
	escc  db ? ; f1+6 экранирующий символ (используется при flags&4)
45
	color db ? ; f1+7 номер цвета
1457 IgorA 46
ends
47
 
48
struct symbol
4988 IgorA 49
	c db ?    ;  +0 символ
50
	col db ?  ;  +1 цвет
51
	perv dd ? ;  +2
52
	next dd ? ;  +6 указатели
53
	tc dd ?   ; +10 врем. создания
54
	td dd ?   ; +14 врем. удаления
1457 IgorA 55
ends
56
;------------------------------------------------------------------------------
57
 
6274 IgorA 58
ted_symbol_space db 32 ;ascii код пробела, иногда бывает нужен в коде
1464 IgorA 59
ted_symbol_tab db 26 ;ascii код стрелки вправо, используется для рисования табуляции в режиме показа невидимых символов
1458 IgorA 60
 
1457 IgorA 61
if lang eq ru
62
 
63
txtRow db 'Строка',0
64
txtCol db 'Знак',0
65
txtOtm db 'Отмены',0
66
txtBuf db 'Буфер:',0
67
 
68
else
69
 
70
txtRow db 'Rows',0
71
txtCol db 'Cols',0
72
txtOtm db 'Undo',0
73
txtBuf db 'Buffer:',0
74
 
75
end if
76
 
1464 IgorA 77
;EvChar - таблица для фильтрования добавляемых символов, что-бы не попали лишние знаки
7036 IgorA 78
align 16
1458 IgorA 79
EvChar db 0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0
1457 IgorA 80
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
85
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
86
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
87
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
88
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
89
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
90
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
91
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
92
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
93
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
94
    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
95
 
96
KM_SHIFT equ 0x00010000
97
KM_CTRL equ 0x00020000
98
KM_ALT equ 0x00040000
99
KM_NUMLOCK equ 0x00080000
100
 
101
; KEY CODES
102
KEY_F1 equ 0x0000003B
103
KEY_F2 equ 0x0000003C
104
KEY_F3 equ 0x0000003D
105
 
106
 
107
 
6274 IgorA 108
align 16
6087 IgorA 109
proc ted_init uses eax ecx edi, edit:dword
6274 IgorA 110
	mov edi,[edit]
1457 IgorA 111
 
1458 IgorA 112
	mov ecx,sizeof.symbol
113
	imul ecx,ted_max_chars
1489 IgorA 114
	invoke mem.alloc,ecx ;выделяем память
1458 IgorA 115
	mov ted_tex,eax
116
	mov ted_tex_1,eax
117
	add ted_tex_1,sizeof.symbol
118
	add eax,ecx
119
	mov ted_tex_end,eax
1457 IgorA 120
 
1458 IgorA 121
	stdcall ted_clear, edi,1
1457 IgorA 122
 
123
;-------------------------------------------------
1458 IgorA 124
	mov ecx,1024 ;1024 - для массива ted_arr_key_pos
125
	add ecx,ted_syntax_file_size
1489 IgorA 126
	invoke mem.alloc,ecx
1458 IgorA 127
	mov ted_arr_key_pos,eax
128
	add eax,1024
129
	mov ted_syntax_file,eax
1457 IgorA 130
 
1458 IgorA 131
	stdcall ted_init_scroll_bars,edi,3
132
	ret
1457 IgorA 133
endp
134
 
1458 IgorA 135
MIN_W_SCRL_ARE equ 3 ;минимальная отображаемая область для верт. скроллинга
136
MIN_H_SCRL_ARE equ 3 ;минимальная отображаемая область для гориз. скроллинга
137
;input:
1459 IgorA 138
; opt = 1 - менять цвет скроллингов, 2 - изменились размеры окна,
139
;  4 - изменились размеры документа
6274 IgorA 140
align 16
1458 IgorA 141
proc ted_init_scroll_bars, edit:dword, opt:dword
142
	pushad
6274 IgorA 143
	mov edi,[edit]
1458 IgorA 144
	mov esi,ted_scr_w
145
	mov ebx,ted_scr_h
146
	bt dword[opt],0
147
	jae @f
148
		mov ecx,ted_color_wnd_work
149
		mov dword[esi+sb_offs_bckg_col],ecx
150
		mov dword[ebx+sb_offs_bckg_col],ecx
151
		mov ecx,ted_color_wnd_capt
152
		mov dword[esi+sb_offs_frnt_col],ecx
153
		mov dword[ebx+sb_offs_frnt_col],ecx
154
		mov ecx,ted_color_wnd_bord
155
		mov dword[esi+sb_offs_line_col],ecx
156
		mov dword[ebx+sb_offs_line_col],ecx
157
	@@:
1459 IgorA 158
	bt dword[opt],2 ; изменились размеры документа ?
159
	jae .doc_resize
160
		call ted_get_num_lines
4988 IgorA 161
		cmp eax,TED_LINES_IN_NEW_FILE
1459 IgorA 162
		jge @f
4988 IgorA 163
			mov eax,TED_LINES_IN_NEW_FILE
1459 IgorA 164
		@@:
165
		mov dword[esi+sb_offs_max_area],eax
166
	.doc_resize:
167
	bt dword[opt],1 ; изменились размеры окна ?
1458 IgorA 168
	jae .no_size
169
			mov edx,ted_wnd_l
170
			add edx,ted_rec_l
171
			mov word[ebx+sb_offs_start_x],dx ;выставляем левый отступ гориз. скроллинга
6256 IgorA 172
			mov eax,ted_wnd_h ;calculate lines in page
1458 IgorA 173
			mov edx,ted_wnd_t
174
			add edx,eax
175
			mov word[ebx+sb_offs_start_y],dx ;выставляем верхний отступ гориз. скроллинга
176
		sub eax,ted_rec_t
177
		xor edx,edx
178
		mov ecx,ted_rec_h
179
		div ecx
180
		cmp eax,MIN_W_SCRL_ARE
181
		jg @f
182
			mov eax,MIN_W_SCRL_ARE
183
		@@:
184
		mov dword[esi+sb_offs_cur_area],eax
185
 
186
		mov eax,ted_wnd_w ;calculate cols in page
187
			mov edx,ted_wnd_l ;левый отступ окна
188
			add edx,eax ;добавляем ширину окна
189
			mov word[esi+sb_offs_start_x],dx ;выставляем левый отступ верт. скроллинга
190
			mov edx,ted_wnd_t
191
			mov word[esi+sb_offs_start_y],dx ;выставляем верхний отступ верт. скроллинга
192
			mov edx,ted_wnd_h
193
			mov word[esi+sb_offs_size_y],dx ;выставляем высоту верт. скроллинга
194
		sub eax,ted_rec_l
195
			mov word[ebx+sb_offs_size_x],ax ;выставляем ширину гориз. скроллинга
196
		xor edx,edx
197
		mov ecx,ted_rec_w
198
		div ecx
199
		cmp eax,MIN_H_SCRL_ARE
200
		jg @f
201
			mov eax,MIN_H_SCRL_ARE
202
		@@:
203
		dec eax
204
		mov dword[ebx+sb_offs_cur_area],eax ;устанавливаем число символов, которые влазят в экран для гориз. скроллинга
205
	.no_size:
206
	popad
207
	ret
208
endp
209
 
6274 IgorA 210
align 16
6087 IgorA 211
proc ted_delete uses edi, edit:dword
6274 IgorA 212
	mov edi,[edit]
1489 IgorA 213
	invoke mem.free,ted_tex
214
	invoke mem.free,ted_arr_key_pos ;ted_syntax_file
1464 IgorA 215
	ret
1457 IgorA 216
endp
217
 
218
 
219
;input:
220
; eax = key kodes
6274 IgorA 221
align 16
1457 IgorA 222
proc ted_key, edit:dword, table:dword, control:dword
223
	pushad
6274 IgorA 224
	mov edi,[edit]
1458 IgorA 225
	mov esi,ted_el_focus
226
	cmp dword[esi],edi
227
	jne .end_key_fun ;элемент не в фокусе выходим из функции
1457 IgorA 228
	mov esi,dword[control]
229
 
230
	cmp ah,KEY_F1 ;[F1]
231
	jne @f
232
		stdcall ted_show_help_f1,edi
233
		jmp .end_key_fun
234
	@@:
235
	cmp ah,KEY_F3 ;[F3]
236
	jne @f
7577 IgorA 237
		stdcall ted_but_find,edi,0
1457 IgorA 238
		jmp .end_key_fun
239
	@@:
240
 
241
	test esi,KM_CTRL ;Ctrl+...
242
	jz .key_Ctrl
4988 IgorA 243
		; *** вызов внешних функций которые требуют окна открытия/сохранения/поиска/...
1457 IgorA 244
		cmp ah,24 ;Ctrl+O
245
		jne @f
246
			cmp ted_fun_on_key_ctrl_o,0
7571 IgorA 247
			je .end_key_fun
1457 IgorA 248
				call ted_fun_on_key_ctrl_o
249
		@@:
1458 IgorA 250
		cmp ah,31 ;Ctrl+S
7571 IgorA 251
		jne .end_ctrl_s
1458 IgorA 252
			cmp ted_fun_on_key_ctrl_s,0
7571 IgorA 253
			je .end_key_fun
254
				xor eax,eax
255
				test esi,KM_SHIFT
256
				jz @f
257
					inc eax
258
				@@:
1458 IgorA 259
				call ted_fun_on_key_ctrl_s
7571 IgorA 260
				jmp .end_key_fun
261
		.end_ctrl_s:
1457 IgorA 262
		cmp ah,33 ;Ctrl+F
263
		jne @f
264
		cmp ted_panel_id,TED_PANEL_FIND
265
		je @f
266
			cmp ted_fun_on_key_ctrl_f,0
7571 IgorA 267
			je .end_key_fun
1457 IgorA 268
				call ted_fun_on_key_ctrl_f
269
		@@:
4988 IgorA 270
		cmp ah,49 ;Ctrl+N
271
		jne @f
272
			cmp ted_fun_on_key_ctrl_n,0
7571 IgorA 273
			je .end_key_fun
4988 IgorA 274
				call ted_fun_on_key_ctrl_n
275
		@@:
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
444
		stdcall KeyConvertToASCII, dword[table]
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
1160
				cmp byte [esi],13
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
1172
			and dword[add_opt],ecx ;n_tim=false;
1457 IgorA 1173
 
1464 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;
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 ***
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
1971
		cmp byte [edx],13
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
 
2049
;input:
2050
; ecx = Col
2051
; edx = Row
2052
; edi = pointer to tedit struct
7576 IgorA 2053
;output:
2054
; ecx = cursor x
2055
; edx = cursor y
6274 IgorA 2056
align 16
1457 IgorA 2057
ted_go_to_pos:
7576 IgorA 2058
	push eax ebx
2059
	mov eax,ted_scr_h
2060
	sub ecx,[eax+sb_offs_position]
7577 IgorA 2061
	cmp ecx,0 ;ted_cur_x < 0
7576 IgorA 2062
	jge @f
2063
		add [eax+sb_offs_position],ecx ;прокрутка скроллинга влево
2064
		xor ecx,ecx
2065
	@@:
2066
	mov ebx,5 ;5 - желаемый отступ слева
2067
	cmp ecx,ebx
2068
	jge .end0
2069
		sub ebx,ecx ;ebx - на сколько символов нужно сдвинуть курсор
2070
		cmp [eax+sb_offs_position],ebx
2071
		jge @f
2072
			add ecx,[eax+sb_offs_position]
2073
			mov dword[eax+sb_offs_position],0
2074
			jmp .end0
2075
		@@:
2076
			sub [eax+sb_offs_position],ebx
2077
			add ecx,ebx
2078
	.end0:
2079
	cmp ecx,[eax+sb_offs_cur_area] ;ted_cur_x > [.cur_area]
2080
	jl .end1
2081
		mov ebx,ecx
2082
		sub ebx,[eax+sb_offs_cur_area]
2083
		inc ebx
2084
		add [eax+sb_offs_position],ebx ;прокрутка скроллинга вправо
2085
		sub ecx,ebx
2086
	.end1:
2087
	mov ted_cur_x,ecx
2088
 
1457 IgorA 2089
	mov eax,ted_scr_w
7497 IgorA 2090
	sub edx,[eax+sb_offs_position]
7576 IgorA 2091
	cmp edx,0 ;ted_cur_y < 0
2092
	jge @f
2093
		add [eax+sb_offs_position],edx ;прокрутка скроллинга вверх
2094
		xor edx,edx
2095
		jmp .end2
2096
	@@:
7497 IgorA 2097
	cmp edx,[eax+sb_offs_cur_area] ;ted_cur_y > [.cur_area]
7576 IgorA 2098
	jl .end2
1457 IgorA 2099
		mov ebx,edx
7497 IgorA 2100
		sub ebx,[eax+sb_offs_cur_area]
1457 IgorA 2101
		inc ebx
7576 IgorA 2102
		add [eax+sb_offs_position],ebx ;прокрутка скроллинга вниз
1457 IgorA 2103
		sub edx,ebx
7576 IgorA 2104
	.end2:
1457 IgorA 2105
	mov ted_cur_y,edx
7576 IgorA 2106
	pop ebx eax
1457 IgorA 2107
	ret
2108
 
2109
;input:
2110
; edi = pointer to tedit struct
6274 IgorA 2111
align 16
1457 IgorA 2112
ted_text_colored:
2113
  push eax edx
2114
  mov eax,ted_tim_ch
2115
  sub eax,ted_tim_undo
2116
  mov ted_tim_co,eax
2117
  mov edx,ted_tex
2118
  @@:
2119
    call ted_iterat_next
2120
    cmp edx,ted_tex_1
2121
    jle @f
2122
    mov byte[edx+1],0
2123
    jmp @b
2124
  @@:
2125
 
2126
  cmp ted_key_words_count,1
2127
  jl .no_colors
2128
  mov edx,ted_tex
2129
  @@:
2130
    call ted_text_find_sel_color
2131
    cmp edx,ted_tex_1
2132
    jle .no_colors
2133
    jmp @b
2134
  .no_colors:
2135
  pop edx eax
2136
  ret
2137
 
2138
 
2139
;input:
2140
; edx = pointer to start symbol
2141
; edi = pointer to tedit struct
2142
;output:
2143
; edx = pointer to next symbol
2144
;description:
2145
; Функция для поиска и выделения подсвеченых слов
6274 IgorA 2146
align 16
6086 IgorA 2147
proc ted_text_find_sel_color uses eax ebx ecx esi
1457 IgorA 2148
locals
6086 IgorA 2149
	begPos dd ? ;начальная позиция
2150
	endPos dd ? ;конечная позиция
2151
	find db ? ;найдено / не найдено
2152
	f_color db ? ;индекс цвета найденого слова
1457 IgorA 2153
endl
2154
;eax = word_n текущий номер (позиция) проверяемого слова в списке
2155
;ebx = для разных целей
2156
;ecx = l_pos последний номер (позиция) подходящего слова в списке
2157
;esi = для разных целей, номер проверяемого символа в слове
6086 IgorA 2158
	mov dword[begPos],1
2159
	mov dword[endPos],1
2160
	mov byte[find],0
2161
	mov byte[f_color],1
2162
	@@:
2163
		call ted_iterat_next
2164
		cmp edx,ted_tex_1
2165
		jle @f
1457 IgorA 2166
 
6086 IgorA 2167
		xor eax,eax
2168
		mov al,byte[edx]
2169
		shl ax,2 ;eax*=4
2170
		add eax,ted_arr_key_pos
7497 IgorA 2171
		mov eax,[eax]
6086 IgorA 2172
		cmp eax,0
2173
		jl @b ;if( (word_n=ted_arr_key_pos[(unsigned char)tex[i].c])>-1 ){
1457 IgorA 2174
 
6086 IgorA 2175
		mov ecx,eax
2176
		;while(l_pos
2177
		.wh_1b:
2178
			cmp ecx,ted_key_words_count
2179
			jge .wh_1e
2180
			ColToIndexOffset ecx,esi
2181
			mov bl,byte[esi]
2182
			ColToIndexOffset eax,esi
2183
			cmp bl,byte[esi]
2184
			jne .wh_1e
2185
				inc ecx
2186
			jmp .wh_1b
2187
		.wh_1e:
1457 IgorA 2188
 
7497 IgorA 2189
		mov [begPos],edx ;bP=i;
6086 IgorA 2190
		mov esi,1
2191
align 4
2192
		.wh_2b: ;while(1){
2193
		call ted_iterat_next
1457 IgorA 2194
 
6086 IgorA 2195
		;while(l_pos>word_n && Col[l_pos-1].Text[pos]!=tex[i].c)
2196
		.wh_3b:
2197
			cmp ecx,eax
2198
			jle .wh_3e
2199
			dec ecx
2200
			ColToIndexOffset ecx,ebx
2201
			inc ecx
2202
			;cmp byte[ebx+esi],byte[edx]
2203
			mov bl,byte[ebx+esi]
2204
			cmp bl,byte[edx]
2205
			je .wh_3e
2206
				dec ecx
2207
			jmp .wh_3b
2208
		.wh_3e:
1457 IgorA 2209
 
6086 IgorA 2210
		ColToIndexOffset eax,ebx
2211
		cmp byte[ebx+esi],0
2212
		jne .if_0 ;if(Col[word_n].Text[pos]==0){
7497 IgorA 2213
		mov [endPos],edx ;eP=i;
6086 IgorA 2214
		ColToIndexOffset eax,ebx
7497 IgorA 2215
		mov bl,[ebx+MAX_COLOR_WORD_LEN+7]
2216
		mov [f_color],bl ;f_color=Col[word_n].color;
1457 IgorA 2217
 
6086 IgorA 2218
		mov byte[find],1
2219
		ColToIndexOffset eax,ebx ;... ebx = Col[word_n]
7497 IgorA 2220
		mov bl,[ebx+MAX_COLOR_WORD_LEN+4]
6086 IgorA 2221
		cmp bl,0 ;if(Col[word_n].wwo)
2222
		je .if_2n
2223
			push edx
7497 IgorA 2224
			mov edx,[begPos]
6086 IgorA 2225
			call ted_iterat_perv
1457 IgorA 2226
 
6086 IgorA 2227
			btr bx,0 ;1-1
2228
			jae .if_3e ;if(Col[word_n].wwo&1)
2229
				;u1= !(isalnum(cont_s)||cont_s=='_')
2230
				call isalnum
2231
				jae .if_3e
2232
					mov byte[find],0
2233
					jmp .if_4e
2234
			.if_3e:
1457 IgorA 2235
 
6086 IgorA 2236
			btr bx,3 ;4-1
2237
			jae .if_4e ;if(Col[word_n].wwo&8)
2238
				;u1= !isalpha(cont_s);
2239
				call isalpha
2240
				jae .if_4e
2241
					mov byte[find],0
2242
			.if_4e:
1457 IgorA 2243
 
7497 IgorA 2244
			mov edx,[endPos]
6086 IgorA 2245
			;call ted_iterat_next
1457 IgorA 2246
 
6086 IgorA 2247
			btr bx,1 ;2-1
2248
			jae .if_5e ;if(Col[word_n].wwo&2)
2249
				;u1= !(isalnum(cont_s)||cont_s=='_')
2250
				call isalnum
2251
				jae .if_5e
2252
					mov byte[find],0
2253
					jmp .if_6e
2254
			.if_5e:
1457 IgorA 2255
 
6086 IgorA 2256
			btr bx,4 ;5-1
2257
			jae .if_6e ;if(Col[word_n].wwo&16)
2258
				;u1= !isalpha(cont_s);
2259
				call isalpha
2260
				jae .if_6e
2261
					mov byte[find],0
2262
			.if_6e:
1457 IgorA 2263
 
6086 IgorA 2264
			btr bx,2 ;3-1
2265
			jae .if_7e ;if(Col[word_n].wwo&4)
2266
				ColToIndexOffset eax,ebx
2267
				mov bx,word[ebx+MAX_COLOR_WORD_LEN+5]
2268
				call ted_iterat_next_pos_char
2269
				cmp edx,ted_tex_1
2270
				jle .if_7e
2271
					mov dword[endPos],edx
2272
			.if_7e:
1457 IgorA 2273
 
6086 IgorA 2274
			pop edx
2275
		.if_2n:
2276
;if(i!=1){ // не конец документа
2277
;  cont_s=tex[eP].c;
2278
;  if(Col[word_n].wwo&2) u2= !(isalnum(cont_s)||cont_s=='_');  // не букв.-числ. символ
2279
;  if(u2 && Col[word_n].wwo&16) u2= !isalpha(cont_s); // не числ. символ
2280
;  if(Col[word_n].wwo&4) eP=ted_iterat_next_pos_char(eP,Col[word_n].endc);
1457 IgorA 2281
 
6086 IgorA 2282
			cmp eax,ecx
2283
			je .wh_2e ;if(word_n==l_pos) break; // do double - если слово точно последнее
2284
		.if_0:
1457 IgorA 2285
 
6086 IgorA 2286
		cmp edx,ted_tex_1
2287
		jle .wh_2e ;if(i==1) break;
1457 IgorA 2288
 
6086 IgorA 2289
		;while(l_pos>word_n && Col[word_n].Text[pos]!=tex[i].c)
2290
		.wh_4b:
2291
		cmp ecx,eax
2292
		jle .wh_4e
2293
			ColToIndexOffset eax,ebx
2294
			;cmp byte[ebx+esi],byte[edx]
2295
			mov bl,byte[ebx+esi]
2296
			cmp bl,byte[edx]
2297
			je .wh_4e
2298
				inc eax
2299
			jmp .wh_4b
2300
		.wh_4e:
1457 IgorA 2301
 
6086 IgorA 2302
		cmp eax,ecx
2303
		je .wh_2e;if(word_n==l_pos) break;
2304
			inc esi ;pos++;
2305
			jmp .wh_2b
2306
		.wh_2e:
1457 IgorA 2307
 
6086 IgorA 2308
		cmp byte[find],1 ;if(fnd)break;
2309
		je @f
7497 IgorA 2310
			mov edx,[begPos];i=bP;
6086 IgorA 2311
		jmp @b
2312
	@@:
1457 IgorA 2313
 
6086 IgorA 2314
	cmp byte[find],1
2315
	jne .if_1e ;if(fnd){ // выделение найденого текста
2316
		;if(!mode_sf1 || (mode_sf1 && strlen(Col[word_n].f1->c_str())>0)){
7497 IgorA 2317
		mov eax,[begPos]
2318
		mov bl,[f_color]
2319
		mov [eax+1],bl ;tex[bP].col=f_color;
2320
		mov eax,[endPos]
6086 IgorA 2321
		mov byte[eax+1],0xff ;tex[eP].col=255;
2322
		;return ItPoPerv(eP); // возвращаем позицию конца вхождения
7497 IgorA 2323
		mov edx,[endPos]
6086 IgorA 2324
		call ted_get_text_perv_pos
2325
		jmp @f
2326
	.if_1e:
2327
		mov edx,ted_tex
2328
	@@:
1457 IgorA 2329
 
6086 IgorA 2330
	ret
1457 IgorA 2331
endp
2332
 
2333
;input:
2334
; edx = pointer to char (byte)
2335
;output:
2336
; cf=1 if symbol is...
6274 IgorA 2337
align 16
6086 IgorA 2338
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
2339
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 2340
 
6086 IgorA 2341
;output:
2342
; cf=1 если в [edx] буква, цифра или '_'
6274 IgorA 2343
align 16
1457 IgorA 2344
isalnum:
6086 IgorA 2345
	push eax ebx
2346
	movzx eax,byte[edx] ;al=offset
2347
	shr eax,3
2348
	lea ebx,[tab_all_num]
2349
	add ebx,eax
2350
	movzx ax,byte[edx] ;al=bit
2351
	and ax,111b
2352
	bt word[ebx],ax
2353
	pop ebx eax
2354
	ret
2355
 
2356
;output:
2357
; cf=1 если в [edx] буква или '_'
6274 IgorA 2358
align 16
1457 IgorA 2359
isalpha:
6086 IgorA 2360
	push eax ebx
2361
	movzx eax,byte[edx] ;al=offset
2362
	shr eax,3
2363
	lea ebx,[tab_alpha]
2364
	add ebx,eax
2365
	movzx ax,byte[edx] ;al=bit
2366
	and ax,111b
2367
	bt word[ebx],ax
2368
	pop ebx eax
2369
	ret
1457 IgorA 2370
 
6274 IgorA 2371
align 16
6086 IgorA 2372
proc ted_show_help_f1 uses eax edx edi, edit:dword
6274 IgorA 2373
	mov edi,[edit]
1457 IgorA 2374
 
6086 IgorA 2375
	call ted_get_pos_by_cursor
2376
	push edx
2377
		call ted_iterat_next_color_tag
2378
		mov eax,edx
2379
	pop edx
2380
	call ted_iterat_perv_color_tag
1457 IgorA 2381
 
6086 IgorA 2382
	cmp eax,ted_tex
2383
	jle @f
2384
	cmp edx,ted_tex_1
2385
	jle @f
2386
		stdcall ted_find_help_id,eax
2387
	@@:
2388
	;call ted_draw_main_cursor
2389
	call ted_draw_help_f1
2390
	ret
1457 IgorA 2391
endp
2392
 
2393
;input:
2394
; edx = position begin 'symbol' struct
2395
; edi = pointer to tedit struct
2396
; end_pos = position end 'symbol' struct
6274 IgorA 2397
align 16
1457 IgorA 2398
proc ted_find_help_id, end_pos:dword
2399
; ecx = word_n
2400
; ebx = l_pos
2401
  mov ted_help_id,-1
2402
 
2403
  push ebx ecx
2404
    xor ebx,ebx
7497 IgorA 2405
    mov bl,[edx]
1457 IgorA 2406
    shl bx,2 ;ebx*=4
2407
    add ebx,ted_arr_key_pos
7497 IgorA 2408
    mov ecx,[ebx]
1457 IgorA 2409
    cmp ecx,0
2410
    jl .if_0e ;if( (word_n=ted_arr_key_pos[(unsigned char)tf[0]])>-1 ){
2411
      push esi eax
2412
      mov ebx,ecx ;l_pos=word_n;
2413
      ColToIndexOffset ecx,esi
2414
      push cx
7497 IgorA 2415
      mov cl,[esi]
1457 IgorA 2416
      @@:
2417
	cmp ebx,ted_key_words_count ;while(l_pos
2418
	jge @f
2419
	;ColToIndexOffset ecx,esi
2420
	ColToIndexOffset ebx,eax
7497 IgorA 2421
	cmp cl,[eax] ;&& Col[l_pos].Text[0]==Col[word_n].Text[0])
1457 IgorA 2422
	jne @f
2423
	  inc ebx ;l_pos++;
2424
	  jmp @b
2425
      @@:
2426
      pop cx
2427
      call ted_iterat_next ;pos=1;
2428
      mov esi,1
2429
      @@:
2430
	push dx
2431
	push word[edx]
2432
	pop dx
2433
	  .wh_0b:
2434
	    cmp ebx,ecx ;while(l_pos>word_n
2435
	    jle .wh_0e
2436
	    dec ebx
2437
	    ColToIndexOffset ebx,eax
2438
	    inc ebx
2439
	    cmp byte[eax+esi],dl ;&& Col[l_pos-1].Text[pos]!=tf[i])
2440
	    je .wh_0e
2441
	      dec ebx ;l_pos--;
2442
	    jmp .wh_0b
2443
	  .wh_0e:
2444
 
2445
	  .wh_1b:
2446
	    cmp ebx,ecx ;while(l_pos>word_n
2447
	    jle .wh_1e
2448
	    ColToIndexOffset ecx,eax
2449
	    cmp byte[eax+esi],dl
2450
	    je .wh_1e
2451
	      inc ecx ;word_n++;
2452
	    jmp .wh_1b
2453
	  .wh_1e:
2454
	pop dx
2455
 
2456
	cmp ecx,ebx ;if(word_n==l_pos) break;
2457
	je @f
2458
	call ted_iterat_next ;pos++;
7497 IgorA 2459
	cmp edx,[end_pos] ;for(...;i
1457 IgorA 2460
	je @f ;jge
2461
	inc esi
2462
	jmp @b
2463
      @@:
2464
      pop eax esi
2465
 
2466
      mov ted_help_id,ecx
2467
      ;return word_n;
2468
 
2469
    .if_0e:
2470
  pop ecx ebx
2471
  ret
2472
endp
2473
 
2474
;output:
2475
; eax = код ошибки
2476
; ebx = колличество прочитанных байт
6274 IgorA 2477
align 16
6087 IgorA 2478
proc ted_open_file uses ecx edx edi, edit:dword, file:dword, f_name:dword ;функция открытия файла
6274 IgorA 2479
	mov edi,[edit]
1457 IgorA 2480
 
2808 IgorA 2481
	; *** проверяем размер памяти и если не хватает то увеличиваем ***
2482
	;пробуем получить информацию о файле
6274 IgorA 2483
	mov ebx,[file]
2484
	mov dword[ebx], SSF_GET_INFO
2808 IgorA 2485
	mov dword[ebx+4], 0
2486
	mov dword[ebx+8], 0
2487
	mov dword[ebx+12], 0
2488
	m2m dword[ebx+16], ted_tex
2489
	mov  byte[ebx+20], 0
2490
	push dword[f_name]
2491
	pop dword[ebx+21]
6274 IgorA 2492
	mcall SF_FILE
2493
	or eax,eax
2494
	jz .end_0
2808 IgorA 2495
		mov edx,ted_max_chars
2496
		cmp eax,2 ;функция не поддерживается для данной файловой системы
2497
		je @f
2498
		jmp .ret_f
6274 IgorA 2499
align 4
2808 IgorA 2500
	.end_0:
2501
	;проверяем хватит ли памяти для загрузки файла
2502
	mov ecx,ted_max_chars
2503
	sub ecx,2 ;ecx = максимальное число байт, для которых была выделена память
2504
	mov edx,ted_tex
6274 IgorA 2505
	mov edx,[edx+32] ;+32 = +0x20: qword: размер файла в байтах
2808 IgorA 2506
	cmp edx,ecx
2507
	jl @f
2508
		;увеличиваем память если не хватило
2509
		mov ecx,edx ;память необходимая для открытия файла
2510
		add ecx,2  ;память для служебных начального и конечного символов
2511
		add ecx,ted_increase_size ;память для редактирования файла
2512
		mov ted_max_chars,ecx
2513
		imul ecx,sizeof.symbol
2514
		invoke mem.realloc, ted_tex,ecx
2515
		mov ted_tex,eax
2516
		mov ted_tex_1,eax
2517
		add ted_tex_1,sizeof.symbol
2518
		add eax,ecx
2519
		mov ted_tex_end,eax
2520
		mov ecx,ted_tex_1
2521
		add ecx,sizeof.symbol
2522
		mov ted_ptr_free_symb,ecx
2523
	@@:
2524
 
2525
	; *** пробуем открыть файл ***
6274 IgorA 2526
	mov ebx,[file]
2527
	mov dword[ebx], SSF_READ_FILE
1457 IgorA 2528
	mov dword[ebx+4], 0
2529
	mov dword[ebx+8], 0
2808 IgorA 2530
	m2m dword[ebx+12], edx ;число байт, которые могут быть считаны с файла (не больше чем ted_max_chars)
1457 IgorA 2531
	m2m dword[ebx+16], ted_tex
2532
	mov  byte[ebx+20], 0
2533
	push dword[f_name]
2534
	pop dword[ebx+21]
6274 IgorA 2535
	mcall SF_FILE
1457 IgorA 2536
 
6274 IgorA 2537
	or eax,eax
2538
	jz @f
1457 IgorA 2539
	cmp eax,6
2540
	je @f
2541
		jmp .ret_f
2542
	@@:
2543
	cmp ebx,-1
2544
	je .ret_f
2545
		;if open file
2546
		call ted_on_open_file
2547
	.ret_f:
2548
	ret
2549
endp
2550
 
6274 IgorA 2551
align 16
1457 IgorA 2552
proc ted_but_select_word, edit:dword
2553
	pushad
6274 IgorA 2554
	mov edi,[edit]
1457 IgorA 2555
 
2556
	call ted_get_pos_by_cursor
2557
	push edx
2558
		call ted_iterat_perv_color_tag
2559
		cmp edx,ted_tex_1
2560
		jle @f
2561
			call ted_get_text_coords
2562
			mov ted_sel_x0,ebx
2563
			mov ted_sel_y0,eax
2564
		@@:
2565
	pop edx
2566
	call ted_iterat_next_color_tag
2567
	cmp edx,ted_tex_1
2568
	jle @f
2569
		call ted_get_text_coords
2570
		mov ted_sel_x1,ebx
2571
		mov ted_sel_y1,eax
2572
	@@:
2573
 
2574
	cmp ted_fun_draw_panel_buttons,0
2575
	je @f
2576
		call ted_fun_draw_panel_buttons
2577
	@@:
2578
	stdcall ted_draw,edi
2579
	popad
2580
	ret
2581
endp
2582
 
7497 IgorA 2583
;output:
2584
; al = 1 if delete
6274 IgorA 2585
align 16
6087 IgorA 2586
proc ted_but_cut uses edi, edit:dword
6274 IgorA 2587
	mov edi,[edit]
1457 IgorA 2588
 
2589
	stdcall ted_but_copy,edi
2590
	call ted_set_undo
2591
	stdcall ted_sel_text_del,ted_opt_ed_change_time
2592
 
2593
	cmp al,1
2594
	jne @f
2595
		stdcall ted_draw,edi
2596
		cmp ted_fun_draw_panel_buttons,0
2597
		je @f
2598
			call ted_fun_draw_panel_buttons
2599
	@@:
2600
	ret
2601
endp
2602
 
6274 IgorA 2603
align 16
1457 IgorA 2604
proc ted_but_copy, edit:dword
2605
	pushad
6274 IgorA 2606
	mov edi,[edit]
1457 IgorA 2607
 
2608
	call ted_is_select
6274 IgorA 2609
	or al,al
2610
	jz .end_f ;if not selected text
1457 IgorA 2611
	call ted_sel_normalize
2612
 
2613
	mov esi,ted_seln_x1
2614
	mov ecx,ted_seln_y1
2615
	call ted_get_pos_by_coords
2616
	mov ebx,edx
2617
	mov esi,ted_seln_x0
2618
	mov ecx,ted_seln_y0
2619
	call ted_get_pos_by_coords
2620
	mov esi,ebx
2621
 
4228 IgorA 2622
	mov ecx,12 ;system buffer header size
1457 IgorA 2623
	mov ebx,ted_buffer
4228 IgorA 2624
	mov dword[ebx+4],0 ;text data
2625
	mov dword[ebx+8],1 ;code 866
2626
	add ebx,ecx
1457 IgorA 2627
	@@:
2628
		cmp edx,ted_tex_1 ;end of file
2629
		jle @f
2630
		cmp edx,esi ;end of select
2631
		je @f
2632
		inc ecx
2633
		cmp ecx,ted_buffer_size ;owerflow bufer
2634
		je @f
2635
 
2636
		mov al,byte[edx]
2637
		mov byte[ebx],al
2638
		inc ebx
5832 IgorA 2639
		cmp al,13
2640
		jne .no_13
2641
			mov byte[ebx],10 ;делаем конец строки в буфере 13,10 для совместимости с другими программами
2642
			inc ebx
2643
			inc ecx
2644
		.no_13:
2645
 
1457 IgorA 2646
		call ted_iterat_next
2647
		jmp @b
2648
	@@:
2649
	mov byte[ebx],0
2650
 
4542 IgorA 2651
	cmp ecx,12
1457 IgorA 2652
	je .end_f
4228 IgorA 2653
		mov ebx,ted_buffer
6274 IgorA 2654
		mov [ebx],ecx
2655
		mcall SF_CLIPBOARD,SSF_WRITE_CB,ecx,ted_buffer
1457 IgorA 2656
		call ted_draw_buffer
2657
		cmp ted_fun_draw_panel_buttons,0
2658
		je .end_f
2659
			call ted_fun_draw_panel_buttons
2660
	.end_f:
2661
	popad
2662
	ret
2663
endp
2664
 
2665
 
6274 IgorA 2666
align 16
1457 IgorA 2667
proc ted_but_paste, edit:dword
4228 IgorA 2668
	pushad
6274 IgorA 2669
	mov edi,[edit]
1457 IgorA 2670
 
6274 IgorA 2671
	mcall SF_CLIPBOARD,SSF_GET_SLOT_COUNT
4228 IgorA 2672
	cmp eax,1
2673
	jl .no_buf_r
2674
 
2675
	mov esi,eax
2676
	.cycle: ;обратный цикл по слотам
2677
	dec esi ;номер текущего, проверяемого слота
6274 IgorA 2678
	mcall SF_CLIPBOARD,SSF_READ_CB,esi
4228 IgorA 2679
	cmp eax,1
2680
	je .no_buf_r
2681
	cmp eax,-1
2682
	je .no_buf_r
7497 IgorA 2683
		mov ecx,[eax]
4228 IgorA 2684
		cmp ecx,1 ;size
2685
		jl .no_buf_r
2686
		cmp dword[eax+4],0 ;text
2687
		je @f
2688
			cmp esi,1
2689
			jge .cycle ;если в буфере не текст, а слотов в буфере несколько, пробуем перейти к верхнему слоту
2690
			jmp .no_buf_r
2691
		@@:
2692
		cmp dword[eax+8],1 ;866
2693
		je @f
2694
			cmp esi,1
2695
			jge .cycle ;если в буфере текст не в кодировке 866 ... пробуем перейти к верхнему слоту
2696
			jmp .no_buf_r
2697
		@@:
2698
		;копирование текста из системного буфера во внутренний
2699
		cmp ecx,ted_buffer_size
2700
		jle @f
2701
			mov ecx,ted_buffer_size
2702
		@@:
2703
		mov edi,ted_buffer
2704
		mov esi,eax
2705
		add	esi,4 ;12
2706
		mov dword[edi],ecx
2707
		add edi,4 ;12
2708
		sub ecx,4 ;12
2709
		rep movsb
6274 IgorA 2710
		mov edi,[edit]
4228 IgorA 2711
 
2712
		mov esi,eax
2713
		add	esi,12
2714
		jmp .buf_r
2715
	.no_buf_r:
2716
 
2717
	;если не удалось прочитать данные из системного буфера, попадаем сюда
1457 IgorA 2718
	mov esi,ted_buffer
4228 IgorA 2719
	cmp dword[esi],1 ;проверяем есть ли данные во внутреннем буфере
2720
	jl .no_paste ;если вообще ничего не удалось прочитать идем на выход
2721
	add esi,12 ;system buffer header size
2722
	.buf_r:
2723
 
2724
	mov edx,esi
1457 IgorA 2725
	call tl_strlen
2726
	cmp eax,1
4228 IgorA 2727
	jl .no_paste
1457 IgorA 2728
		mov esi,eax
2729
		call ted_set_undo
2730
		mov ebx,ted_opt_ed_change_time+ted_opt_ed_move_cursor
2731
		stdcall ted_sel_text_del,ebx
2732
		cmp al,1
2733
		jne .del
2734
			mov ebx,ted_opt_ed_move_cursor
2735
		.del:
4228 IgorA 2736
		stdcall ted_text_add,edi,edx,esi,ebx
1457 IgorA 2737
		stdcall ted_draw,edi
2738
		cmp ted_fun_draw_panel_buttons,0
4228 IgorA 2739
		je .no_paste
1457 IgorA 2740
			call ted_fun_draw_panel_buttons
4228 IgorA 2741
	.no_paste:
2742
	popad
1457 IgorA 2743
	ret
2744
endp
2745
 
6274 IgorA 2746
align 16
2324 IgorA 2747
proc ted_but_sumb_upper uses edi esi, edit:dword
6274 IgorA 2748
	mov edi,[edit]
1457 IgorA 2749
 
2324 IgorA 2750
	stdcall ted_convert_sel_text,fb_char_toupper
6274 IgorA 2751
	or esi,esi
2752
	jz @f
2324 IgorA 2753
		stdcall ted_draw,edi
2754
	@@:
2755
	ret
1457 IgorA 2756
endp
2757
 
6274 IgorA 2758
align 16
2324 IgorA 2759
proc ted_but_sumb_lover uses edi esi, edit:dword
6274 IgorA 2760
	mov edi,[edit]
1457 IgorA 2761
 
2324 IgorA 2762
	stdcall ted_convert_sel_text,fb_char_todown
6274 IgorA 2763
	or esi,esi
2764
	jz @f
2324 IgorA 2765
		stdcall ted_draw,edi
2766
	@@:
2767
	ret
1457 IgorA 2768
endp
2769
 
6274 IgorA 2770
align 16
6087 IgorA 2771
proc ted_but_reverse uses eax ebx edi, edit:dword
6274 IgorA 2772
	mov edi,[edit]
1457 IgorA 2773
 
6087 IgorA 2774
	call ted_is_select
6274 IgorA 2775
	or al,al
2776
	jz @f
6087 IgorA 2777
		call ted_sel_normalize
2778
		push esi ecx edx
2779
			mov esi,ted_seln_x0
2780
			mov ecx,ted_seln_y0
2781
			call ted_get_pos_by_coords
2782
			mov eax,edx
2783
			mov esi,ted_seln_x1
2784
			cmp esi,0
2785
			je .beg_str
2786
				dec esi
2787
			.beg_str:
2788
			mov ecx,ted_seln_y1
2789
			call ted_get_pos_by_coords
2790
			;call ted_get_text_perv_pos
2791
			mov ebx,edx
2792
		pop edx ecx esi
2793
		;cmp eax,...
2794
		;je @f
2795
		call ted_revers
2796
	@@:
2797
	stdcall ted_draw,edi
2798
	ret
1457 IgorA 2799
endp
2800
 
6274 IgorA 2801
align 16
6087 IgorA 2802
proc ted_but_undo uses eax edi, edit:dword
6274 IgorA 2803
	mov edi,[edit]
1457 IgorA 2804
 
2805
	mov eax,ted_tim_undo
2806
	cmp ted_tim_ch,eax
2807
	jbe @f
2808
		inc ted_tim_undo
2809
		;call ted_text_colored
2810
		stdcall ted_draw,edi
2811
		cmp ted_fun_draw_panel_buttons,0
2812
		je @f
2813
			call ted_fun_draw_panel_buttons
2814
	@@:
2815
	ret
2816
endp
2817
 
6274 IgorA 2818
align 16
6087 IgorA 2819
proc ted_but_redo uses edi, edit:dword
6274 IgorA 2820
	mov edi,[edit]
1457 IgorA 2821
 
2822
	cmp ted_tim_undo,1
2823
	jb @f
2824
		dec ted_tim_undo
2825
		;call ted_text_colored
2826
		stdcall ted_draw,edi
2827
		cmp ted_fun_draw_panel_buttons,0
2828
		je @f
2829
			call ted_fun_draw_panel_buttons
2830
	@@:
2831
	ret
2832
endp
2833
 
7576 IgorA 2834
;description:
2835
; функция находит текст на который указывает ted_buffer_find
2836
;input:
2837
; f_opt = параметры поиска:
7577 IgorA 2838
;   (0 - искать ниже курсора, 1 - искать выше курсора, 2 - искать от начала файла)
2839
;   если установлен 31-й бит, то не обновляется окно
2840
;output:
2841
; eax = был ли найден искомый текст (0 - нет, 1 - да)
6274 IgorA 2842
align 16
7577 IgorA 2843
proc ted_but_find uses ebx ecx edx edi esi, edit:dword, f_opt:dword
7576 IgorA 2844
	push [edit]
7577 IgorA 2845
	cmp word[f_opt],2
7576 IgorA 2846
	jne @f
7577 IgorA 2847
		call _but_find_first
2848
		jmp .end0
7576 IgorA 2849
	@@:
7577 IgorA 2850
	cmp word[f_opt],0
7576 IgorA 2851
	jne @f
7577 IgorA 2852
		call _but_find_next
2853
		jmp .end0
7576 IgorA 2854
	@@:
7577 IgorA 2855
	cmp word[f_opt],1
2856
	jne .end0
2857
		call _but_find_perv
2858
	.end0:
2859
 
2860
	bt dword[f_opt],31
2861
	jc .end1
2862
	or eax,eax
2863
	jz @f
2864
		;текст найден, обновляем окно
2865
		stdcall ted_draw,edi
2866
		jmp .end1
2867
	@@:
2868
		;текст не найден, пробуем вызвать сообщение
2869
		cmp ted_fun_find_err,0
2870
		je .end1
2871
			call ted_fun_find_err ;пользовательская функция
2872
	.end1:
7576 IgorA 2873
	ret
2874
endp
2875
 
2876
;description:
7577 IgorA 2877
; функция находит текст от начала файла, или от конца текущего выделения
2878
;output:
2879
; eax = был ли найден искомый текст (0 - нет, 1 - да)
2880
; ebx, ecx, edx, edi, edi - портятся
7576 IgorA 2881
align 16
7577 IgorA 2882
proc _but_find_first, edit:dword
7576 IgorA 2883
	mov edi,[edit]
2884
 
2885
	call ted_is_select
2886
	or al,al
2887
	jz @f
2888
		call ted_sel_normalize
2889
		mov edx,ted_sel_y1
2890
		mov ecx,ted_sel_x1
2891
		call ted_go_to_pos ;переход на конец выделения
2892
		call ted_get_pos_by_cursor
2893
		jmp .end0
2894
	@@:
2895
		mov edx,ted_tex
2896
		call ted_iterat_next
2897
	.end0:
2898
	mov eax,ted_buffer_find
2899
	mov bl,byte[eax]
2900
	@@:
2901
		call ted_get_find_rezult
2902
		cmp bh,1
2903
		je @f ; find
2904
			call ted_iterat_next
2905
			cmp edx,ted_tex_1
2906
			jle @f
2907
			jmp @b
2908
	@@:
7577 IgorA 2909
	call _but_find_select
7576 IgorA 2910
	ret
2911
endp
2912
 
2913
;description:
7577 IgorA 2914
; функция находит текст выше курсора
2915
;output:
2916
; eax = был ли найден искомый текст (0 - нет, 1 - да)
2917
; ebx, ecx, edx, edi, edi - портятся
7576 IgorA 2918
align 16
7577 IgorA 2919
proc _but_find_perv, edit:dword
7576 IgorA 2920
	mov edi,[edit]
2921
	call ted_is_select
2922
	or al,al
2923
	jz @f
2924
		call ted_sel_normalize
2925
		mov edx,ted_sel_y0
2926
		mov ecx,ted_sel_x0
2927
		call ted_go_to_pos ;переход на начало выделения
2928
		call ted_get_pos_by_cursor
2929
		call ted_iterat_perv ;переход на 1-й символ перед выделением
2930
		jmp .end0
2931
	@@:
2932
	call ted_get_pos_by_cursor
2933
	.end0:
2934
	mov eax,ted_buffer_find
2935
	mov bl,byte[eax]
2936
	@@:
2937
		call ted_get_find_rezult
2938
		cmp bh,1
2939
		je @f ; find
2940
			call ted_iterat_perv
2941
			cmp edx,ted_tex_1
2942
			jle @f
2943
			jmp @b
2944
	@@:
7577 IgorA 2945
	call _but_find_select
7576 IgorA 2946
	ret
2947
endp
2948
 
2949
;description:
7577 IgorA 2950
; функция находит текст ниже курсора
2951
;output:
2952
; eax = был ли найден искомый текст (0 - нет, 1 - да)
2953
; ebx, edx, edi, esi - портятся
7576 IgorA 2954
align 16
7577 IgorA 2955
proc _but_find_next, edit:dword
6274 IgorA 2956
	mov edi,[edit]
1457 IgorA 2957
 
2958
	call ted_get_pos_by_cursor
2959
	mov eax,ted_buffer_find
2960
	mov bl,byte[eax]
2961
	@@:
2962
		call ted_get_find_rezult
2963
		cmp bh,1
2964
		je @f ; find
2965
			call ted_iterat_next
2966
			cmp edx,ted_tex_1
2967
			jle @f
2968
			jmp @b
2969
	@@:
7577 IgorA 2970
	call _but_find_select
7576 IgorA 2971
	ret
2972
endp
2973
 
7577 IgorA 2974
;description:
2975
; вспомогательная функция, выделяет найденный текст
7576 IgorA 2976
;input:
2977
; bh = был ли найден искомый текст (0 - нет, 1 - да)
2978
; esi = first symbol pointer
2979
align 16
7577 IgorA 2980
_but_find_select:
7576 IgorA 2981
	or bh,bh
2982
	jz @f
1457 IgorA 2983
		call ted_get_text_coords
2984
		inc ebx ;move cursor right
2985
		mov ted_sel_x1,ebx
2986
		mov ted_sel_y1,eax
2987
		mov edx,eax
2988
		mov ecx,ebx
2989
		call ted_go_to_pos
7576 IgorA 2990
		mov edx,esi
1457 IgorA 2991
		call ted_get_text_coords
2992
		mov ted_sel_x0,ebx
2993
		mov ted_sel_y0,eax
7577 IgorA 2994
		xor eax,eax
2995
		inc eax
2996
		jmp .end0
1457 IgorA 2997
	@@:
7577 IgorA 2998
		xor eax,eax ;текст не найден
2999
	.end0:
1457 IgorA 3000
	ret
7576 IgorA 3001
 
3002
;input:
3003
; rpl_text = текст для замены
3004
; r_opt = параметры поиска:
7577 IgorA 3005
;   (0 - искать ниже курсора, 1 - искать выше курсора, 2 - искать от начала файла)
7576 IgorA 3006
; n_tim = фиксировать замену в изменениях (0 - нет, 1 - да)
3007
;output:
3008
; eax = 0 - не удачно, 1 - удачно
3009
align 16
3010
proc ted_but_replace uses edx edi esi, edit:dword, rpl_text:dword, r_opt:dword, n_tim:dword
3011
	mov edi,[edit]
7577 IgorA 3012
	mov eax,[r_opt]
3013
	bts eax,31
3014
	stdcall ted_but_find, edi,eax
3015
	or eax,eax
3016
	jz .end0
7576 IgorA 3017
 
3018
	xor edx,edx
3019
	cmp dword[n_tim],0
3020
	je @f
7577 IgorA 3021
		call ted_set_undo
7576 IgorA 3022
		mov edx,ted_opt_ed_change_time
3023
	@@:
3024
	stdcall ted_sel_text_del, edx
3025
	or eax,0xff
7577 IgorA 3026
	jz .end0
7576 IgorA 3027
		mov esi,[rpl_text]
3028
		stdcall tl_strlen
3029
		or eax,eax
7577 IgorA 3030
		jz .end0
7576 IgorA 3031
		stdcall ted_text_add, edi,esi,eax,ted_opt_ed_move_cursor
3032
		xor eax,eax
3033
		inc eax
7577 IgorA 3034
	.end0:
7576 IgorA 3035
	ret
1457 IgorA 3036
endp
3037
 
3038
;input:
7577 IgorA 3039
; eax - text need find
3040
; bl - first symbol to find
3041
; edx - first symbol pointer
3042
; edi - pointer to tedit struct
3043
;output:
3044
; bh - rezult
3045
; edx - last text position (if find sucess)
3046
; esi - first symbol pointer
3047
;description:
3048
; Функция проверяет совпадает ли текст в буфере eax
3049
; с текстом редактора по указателю edx.
3050
; Стандартные функции (напр. strcmp) тут не подойдут, потому что
3051
; в памяти редактора текст содержится не в виде ascii строк.
3052
align 16
3053
ted_get_find_rezult:
3054
push eax
3055
	mov bh,1
3056
	mov esi,edx ;copy edx
3057
	@@:
3058
		cmp byte[edx],bl
3059
		jne .no_text
3060
 
3061
		inc eax ;*** get next symbol (in find text) ***
3062
		mov bl,byte[eax]
3063
		or bl,bl
3064
		jz @f ;end of find text
3065
 
3066
		call ted_iterat_next ;*** get next symbol (in editor text) ***
3067
		cmp edx,ted_tex_1
3068
		jg @b
3069
align 4
3070
		.no_text:
3071
	xor bh,bh
3072
	mov edx,esi ;restore edx
3073
	@@:
3074
pop eax
3075
	mov bl,byte[eax] ;restore bl
3076
	ret
3077
 
3078
;input:
1457 IgorA 3079
; edi = pointer to tedit struct
6274 IgorA 3080
align 16
1457 IgorA 3081
ted_key_ctrl_home:
3082
	mov ted_cur_x,0
3083
	mov ted_cur_y,0
3084
	push eax
3085
		mov eax,ted_scr_w
3086
		mov dword[eax+sb_offs_position],0
3087
		mov eax,ted_scr_h
3088
		mov dword[eax+sb_offs_position],0
3089
	pop eax
3090
	stdcall ted_draw,edi
3091
	cmp ted_fun_draw_panel_buttons,0
3092
	je @f
3093
		call ted_fun_draw_panel_buttons
3094
	@@:
3095
	ret
3096
 
3097
;input:
3098
; edi = pointer to tedit struct
6274 IgorA 3099
align 16
4988 IgorA 3100
ted_key_ctrl_end:
3101
	push eax ebx
3102
		call ted_get_num_lines
3103
		mov ebx,ted_scr_w
7497 IgorA 3104
		mov [ebx+sb_offs_position],eax ;ставим ползунок на последнюю строку документа
3105
		cmp eax,[ebx+sb_offs_cur_area]
4988 IgorA 3106
		jle @f
7497 IgorA 3107
			mov eax,[ebx+sb_offs_cur_area] ;получаем число строк влазящих в окно
4988 IgorA 3108
		@@:
7497 IgorA 3109
		sub [ebx+sb_offs_position],eax ;отнимаем от ползунка число строк влазящих в окно (но не больше тех, что есть в документе)
4988 IgorA 3110
		dec eax
3111
		mov ted_cur_y,eax ;ставим курсор на последнюю строку документа
3112
	pop ebx eax
3113
	call ted_cur_move_x_last_char
3114
	stdcall ted_draw,edi
3115
	cmp ted_fun_draw_panel_buttons,0
3116
	je @f
3117
		call ted_fun_draw_panel_buttons
3118
	@@:
3119
	ret
3120
 
3121
;input:
3122
; edi = pointer to tedit struct
6274 IgorA 3123
align 16
1457 IgorA 3124
proc ted_sel_key_up
3125
  cmp ted_drag_k,1
3126
  je @f
3127
    call ted_sel_start
3128
    mov ted_drag_k,1
3129
  @@:
3130
  push dx
3131
    call ted_cur_move_up
3132
    cmp dl,8
3133
    jne @f
3134
      call ted_scroll_set_redraw
3135
    @@:
3136
  pop dx
3137
  call ted_sel_move
3138
  stdcall ted_draw,edi
3139
  ret
3140
endp
3141
 
3142
;input:
3143
; edi = pointer to tedit struct
6274 IgorA 3144
align 16
1457 IgorA 3145
proc ted_sel_key_down
3146
  cmp ted_drag_k,1
3147
  je @f
3148
    call ted_sel_start
3149
    mov ted_drag_k,1
3150
  @@:
3151
  push dx
3152
    call ted_cur_move_down
3153
    cmp dl,8
3154
    jne @f
3155
      call ted_scroll_set_redraw
3156
    @@:
3157
  pop dx
3158
  call ted_sel_move
3159
  stdcall ted_draw,edi
3160
  ret
3161
endp
3162
 
3163
;input:
3164
; edi = pointer to tedit struct
6274 IgorA 3165
align 16
1457 IgorA 3166
proc ted_sel_key_left
3167
  cmp ted_drag_k,1
3168
  je @f
3169
    call ted_sel_start
3170
  @@:
3171
  push dx
3172
    call ted_cur_move_left
3173
    call ted_sel_move
3174
    cmp ted_drag_k,1
3175
    je @f
3176
      mov ted_drag_k,1
3177
      mov dl,8
3178
    @@:
3179
    cmp dl,8
3180
    jne @f
3181
      call ted_scroll_set_redraw
3182
      stdcall ted_draw,edi
3183
      jmp .end_f
3184
    @@:
3185
      stdcall ted_draw_cur_line,edi
3186
    .end_f:
3187
  pop dx
3188
  ret
3189
endp
3190
 
3191
;input:
3192
; edi = pointer to tedit struct
6274 IgorA 3193
align 16
1457 IgorA 3194
proc ted_sel_key_right
3195
  cmp ted_drag_k,1
3196
  je @f
3197
    call ted_sel_start
3198
  @@:
3199
  push dx
3200
    call ted_cur_move_right
3201
    call ted_sel_move
3202
    cmp ted_drag_k,1
3203
    je @f
3204
      mov ted_drag_k,1
3205
      mov dl,8
3206
    @@:
3207
    cmp dl,8
3208
    jne @f
3209
      call ted_scroll_set_redraw
3210
      stdcall ted_draw,edi
3211
      jmp .end_f
3212
    @@:
3213
      stdcall ted_draw_cur_line,edi
3214
    .end_f:
3215
  pop dx
3216
  ret
3217
endp
3218
 
3219
;input:
3220
; edi = pointer to tedit struct
3221
;description:
3222
; this function need to optimize output
6274 IgorA 3223
align 16
1457 IgorA 3224
proc ted_draw_cursor_sumb
6256 IgorA 3225
pushad
3226
	mov ebx,ted_wnd_l
3227
	add ebx,ted_rec_l
3228
	mov edx,ted_cur_x
3229
	imul edx,ted_rec_w
3230
	add ebx,edx
3231
	shl ebx,16
3232
	add ebx,ted_rec_w
1457 IgorA 3233
 
6256 IgorA 3234
	mov ecx,ted_wnd_t ;calc rect -> y0,y1
3235
	add ecx,ted_rec_t
3236
	mov edx,ted_cur_y
3237
	imul edx,ted_rec_h
3238
	add ecx,edx
3239
	shl ecx,16
3240
	add ecx,ted_rec_h
1457 IgorA 3241
 
6256 IgorA 3242
	mov edx,ted_color_wnd_work
6274 IgorA 3243
	call ted_sel_normalize
1457 IgorA 3244
 
6274 IgorA 3245
	mov esi,ted_scr_w
3246
	mov eax,[esi+sb_offs_position]
3247
	sub ted_seln_y0,eax
3248
	sub ted_seln_y1,eax
1457 IgorA 3249
 
6274 IgorA 3250
	mov eax,ted_cur_y
3251
	cmp eax,ted_seln_y0
3252
	jl .no_cur_sel
3253
	cmp eax,ted_seln_y1
3254
	jg .no_cur_sel
6256 IgorA 3255
		mov edx,ted_color_select ;меняем цвет фона на цвет выделения
3256
		mov esi,ted_scr_h
6274 IgorA 3257
		cmp eax,ted_seln_y0
6256 IgorA 3258
		jne @f
6274 IgorA 3259
			mov eax,ted_cur_x
3260
			add eax,[esi+sb_offs_position]
3261
			cmp eax,ted_seln_x0
6256 IgorA 3262
			jge @f
3263
			mov edx,ted_color_wnd_work
3264
		@@:
6274 IgorA 3265
		mov eax,ted_cur_y
3266
		cmp eax,ted_seln_y1
6256 IgorA 3267
		jne .no_cur_sel
6274 IgorA 3268
			mov eax,ted_cur_x
3269
			add eax,[esi+sb_offs_position]
3270
			cmp eax,ted_seln_x1
6256 IgorA 3271
			jl .no_cur_sel
3272
			mov edx,ted_color_wnd_work
6274 IgorA 3273
	.no_cur_sel:
3274
	mcall SF_DRAW_RECT
1457 IgorA 3275
 
6256 IgorA 3276
	call ted_get_pos_by_cursor ;берем позицию символа
3277
	cmp ted_gp_opt,2
3278
	jne @f
3279
		mov esi,1
3280
		ror ecx,16
3281
		mov bx,cx
3282
		add ebx,0x10001
3283
		call ted_get_symb_color
3284
		call ted_convert_invis_symb
3285
		mcall SF_DRAW_TEXT ;рисование символа
3286
	@@:
3287
popad
3288
	ret
1457 IgorA 3289
endp
3290
 
3291
;input:
3292
; edx -> pointer to text
3293
; edi -> указатель на структуру tedit
3294
;output:
3295
; ecx = color
3296
; if ted_mode_color=0 then ecx=ted_color_wnd_text
6274 IgorA 3297
align 16
1457 IgorA 3298
ted_get_symb_color:
6256 IgorA 3299
	mov ecx,ted_color_wnd_text ;задаем цвет текста по умолчанию
1457 IgorA 3300
 
6256 IgorA 3301
	push eax edx
3302
	cmp ted_mode_color,0
3303
	je .exit
3304
		jmp .on_first
3305
		@@:
3306
			call ted_iterat_perv
3307
			cmp edx,ted_tex_1
3308
			jle .exit
3309
		.on_first:
3310
			xor eax,eax
3311
			mov al,byte[edx+1]
3312
			or al,al ;если al=0 то цвет не меняется
3313
			jz @b
1457 IgorA 3314
 
6256 IgorA 3315
		cmp eax,ted_colors_text_count
3316
		jge .exit
1457 IgorA 3317
 
6256 IgorA 3318
		shl ax,2 ;умножаем индекс цвета на 4 байта
3319
		mov ecx,ted_text_colors ;прибавляем смещение 1-го цвета
3320
		add ecx,eax
7497 IgorA 3321
		mov ecx,[ecx] ;устанавливаем текущий цвет текста по смещению
6256 IgorA 3322
	.exit:
3323
	or ecx,ted_font_size
3324
	pop edx eax
3325
	ret
1457 IgorA 3326
 
3327
;input:
3328
; edx = pointer to text
3329
; edi = pointer to tedit struct
3330
;description:
3331
; Функция преобразует невидимые символы в печатаемые на экране
6274 IgorA 3332
align 16
1457 IgorA 3333
ted_convert_invis_symb:
1458 IgorA 3334
	cmp ted_mode_invis,1
6274 IgorA 3335
	jne .else
1458 IgorA 3336
		cmp byte[edx],9
3337
		jne @f
3338
			lea edx,[ted_symbol_tab]
6274 IgorA 3339
			jmp .end_f
3340
align 4
1458 IgorA 3341
		@@:
3342
		cmp byte[edx],13
3343
		jne @f
3344
			mov edx,edi
3345
			add edx,ted_offs_symbol_new_line
3346
		@@:
6274 IgorA 3347
		jmp .end_f
3348
align 4
3349
	.else:
3350
		cmp byte[edx],9
3351
		je @f
3352
		cmp byte[edx],13
3353
		je @f
3354
			jmp .end_f
3355
		@@:
3356
			lea edx,[ted_symbol_space]
1458 IgorA 3357
	.end_f:
3358
	ret
1457 IgorA 3359
 
3360
;input:
3361
; edi = pointer to tedit struct
6274 IgorA 3362
align 16
1457 IgorA 3363
ted_scroll_set_redraw:
3364
	push eax
3365
	mov eax,ted_scr_w
3366
	mov dword[eax+sb_offs_redraw],1
3367
	mov eax,ted_scr_h
3368
	mov dword[eax+sb_offs_redraw],1
3369
	pop eax
3370
	ret
3371
 
6274 IgorA 3372
align 16
1457 IgorA 3373
proc ted_draw, edit:dword
1458 IgorA 3374
	locals
3375
		line_num dd ?
3376
	endl
3377
	pushad
6274 IgorA 3378
	mov edi,[edit]
1457 IgorA 3379
 
6256 IgorA 3380
	mov eax,SF_DRAW_TEXT
1458 IgorA 3381
	mov ecx,ted_text_colors
7497 IgorA 3382
	mov ecx,[ecx]
1457 IgorA 3383
 
1458 IgorA 3384
	mov ebx,ted_wnd_l
3385
	add ebx,ted_rec_l
3386
	shl ebx,16
3387
	add ebx,ted_wnd_t
3388
	add ebx,ted_rec_t
3389
	add ebx,0x10001 ;добавляем отступы для выравнивания буквы по центру
1457 IgorA 3390
 
1458 IgorA 3391
	call ted_sel_normalize ;need before draw select
3392
	mov esi,ted_scr_w
6274 IgorA 3393
	mov esi,[esi+sb_offs_position]
3394
	mov [line_num],esi
1457 IgorA 3395
 
1458 IgorA 3396
	stdcall ted_clear_line_before_draw, edi,ebx,1,esi
3397
	call ted_get_first_visible_pos
3398
	cmp edx,0
3399
	je .no_draw_text
3400
	mov esi,1 ;длинна выводимого текста по 1-му символу
3401
	@@:
3402
		call ted_iterat_next
3403
		cmp edx,ted_tex_1
3404
		jle .no_draw_text
1457 IgorA 3405
 
1458 IgorA 3406
		; *** цветовая разметка
3407
		cmp ted_mode_color,0
3408
		je .no_col_change
3409
		cmp byte[edx+1],0
3410
		je .no_col_change
3411
			call ted_get_symb_color
3412
		.no_col_change:
1457 IgorA 3413
 
6274 IgorA 3414
		cmp byte[edx],13
1458 IgorA 3415
		jne .no_13
3416
			cmp ted_mode_invis,1
3417
			jne .no_invis
3418
				push edx
3419
				mov edx,edi
3420
				add edx,ted_offs_symbol_new_line
3421
				int 0x40
3422
				pop edx
3423
			.no_invis:
3424
			add ebx,ted_rec_h
3425
			;optimized output \/
3426
			mov eax,ted_wnd_h
3427
			add eax,ted_wnd_t
3428
			cmp bx,ax
3429
			jg .no_draw_text
6256 IgorA 3430
			mov eax,SF_DRAW_TEXT
1458 IgorA 3431
			;optimized output /\
3432
			and ebx,0xffff
3433
			ror ebx,16
3434
			add ebx,ted_wnd_l
3435
			add ebx,ted_rec_l
3436
			inc ebx
3437
			ror ebx,16
3438
			inc dword[line_num] ;increment line number
3439
			stdcall ted_clear_line_before_draw,edi,ebx,1,dword[line_num]
3440
			call ted_opt_draw_line_left
3441
			jmp @b
6256 IgorA 3442
align 4
1458 IgorA 3443
		.no_13:
1457 IgorA 3444
 
1458 IgorA 3445
		int 0x40
3446
		ror ebx,16
3447
		add ebx,ted_rec_w
3448
		mov esi,ted_wnd_l
3449
		add esi,ted_wnd_w
3450
		cmp bx,si
3451
		jl .no_opt
3452
			call ted_opt_draw_line_right
3453
		.no_opt:
3454
		mov si,1
3455
		ror ebx,16
3456
		jmp @b
3457
	.no_draw_text:
1457 IgorA 3458
 
4988 IgorA 3459
	inc dword[line_num]
1458 IgorA 3460
	stdcall ted_clear_line_before_draw,edi,ebx,0,dword[line_num]
3461
	call ted_draw_line_numbers
3462
	call ted_draw_main_cursor
1457 IgorA 3463
 
3464
;---------------------------------------------
3465
; set all_redraw flag for draw all ScrollBar
3466
; In some cases it is necessity to draw only the area
3467
; of moving of a "runner", for acceleration of output -
3468
; in this case the flag needs to be reset to 0 (zero).
3469
	mov eax,ted_scr_h
3470
	mov esi,ted_scr_w
3471
	mov dword[eax+sb_offs_all_redraw],1
3472
	mov dword[esi+sb_offs_all_redraw],1
3473
 
3474
; рисование полос прокрутки
3475
	stdcall scroll_bar_horizontal.draw,eax ;[scrollbar_hor_draw]
3476
	stdcall scroll_bar_vertical.draw,esi ;[scrollbar_ver_draw]
3477
; reset all_redraw flag
3478
	mov dword[eax+sb_offs_all_redraw],0
3479
	mov dword[esi+sb_offs_all_redraw],0
3480
;---------------------------------------------
3481
 
6087 IgorA 3482
	;left-bottom square
3483
	mov ebx,ted_wnd_l
3484
	shl ebx,16
3485
	add ebx,ted_rec_l
3486
	mov ecx,ted_wnd_t
3487
	add ecx,ted_wnd_h
3488
	shl ecx,16
3489
	mov cx,word[eax+sb_offs_size_y]
3490
	inc cx
6256 IgorA 3491
	mcall SF_DRAW_RECT,,,ted_color_wnd_capt ;[sc.work]
1457 IgorA 3492
 
3493
	;right-bottom square
3494
	mov ebx,ted_wnd_l
3495
	add ebx,ted_wnd_w
3496
	shl ebx,16
3497
	mov bx,word[esi+sb_offs_size_x]
3498
	inc bx
3499
	int 0x40
3500
 
3501
	cmp ted_fun_draw_panel_find,0
3502
	je @f
3503
		call ted_fun_draw_panel_find
3504
	@@:
3505
	cmp ted_fun_draw_panel_syntax,0
3506
	je @f
3507
		call ted_fun_draw_panel_syntax
3508
	@@:
3509
	popad
3510
	ret
3511
endp
3512
 
3513
;input:
3514
; edi = pointer to tedit struct
6274 IgorA 3515
align 16
1457 IgorA 3516
proc ted_draw_main_cursor
6274 IgorA 3517
pushad
1457 IgorA 3518
 
6274 IgorA 3519
	mov eax,SF_DRAW_RECT ;draw cursor
3520
	mov ecx,ted_wnd_t ;calc rect -> y0,y1
3521
	add ecx,ted_rec_t
3522
	mov edx,ted_cur_y
3523
	imul edx,ted_rec_h
3524
	add ecx,edx
1457 IgorA 3525
 
6274 IgorA 3526
	cmp ted_cur_ins,1 ;проверка режима работы курсора (обычный или вставка)
3527
	jne @f
3528
		mov edx,ted_rec_h
3529
		inc edx   ;1->1, 3->2, 5->3, ...
3530
		shr edx,1 ;edx = высота строки деленная на 2 (когда курсор не полный)
3531
		add ecx,edx
3532
	@@:
3533
	shl ecx,16
3534
	add ecx,ted_rec_h
3535
	cmp ted_cur_ins,1
3536
	jne @f
3537
		shr cx,1 ;делим высоту курсора на 2
3538
	@@:
1457 IgorA 3539
 
6274 IgorA 3540
	mov ebx,ted_wnd_l ;calc rect -> x0,x1
3541
	add ebx,ted_rec_l
3542
	mov edx,ted_cur_x
3543
	imul edx,ted_rec_w
3544
	add ebx,edx
3545
	shl ebx,16
3546
	add ebx,ted_rec_w
1457 IgorA 3547
 
6274 IgorA 3548
	mov edx,ted_color_cursor
3549
	int 0x40 ;вывод курсора
1457 IgorA 3550
 
6274 IgorA 3551
	call ted_get_pos_by_cursor
3552
	cmp ted_gp_opt,2
3553
	jne @f
3554
		mov esi,1
3555
		ror ecx,16
3556
		mov bx,cx
3557
		add ebx,0x10001
3558
		cmp ted_cur_ins,1
3559
		jne .no_up_tetx
3560
			mov ecx,ted_rec_h
3561
			inc cx ; 1->1, 3->2, 5->3, ...
3562
			shr cx,1
3563
			sub bx,cx
3564
		.no_up_tetx:
3565
		mov ecx,ted_color_cur_text
3566
		or ecx,ted_font_size
3567
		call ted_convert_invis_symb
3568
		mcall SF_DRAW_TEXT
3569
	@@:
1457 IgorA 3570
 
6274 IgorA 3571
	mov ebx,ted_wnd_l
3572
	add ebx,ted_rec_l
3573
	shl ebx,16
3574
	add ebx,ted_wnd_t
3575
	add ebx,3
3576
	mov ecx,ted_color_wnd_bord
3577
	or  ecx,0x80000000
3578
	lea edx,[txtRow]
3579
	mcall SF_DRAW_TEXT ;вывод подписи 'Строка'
1457 IgorA 3580
 
6274 IgorA 3581
	add ebx,0x500000
3582
	lea edx,[txtCol]
3583
	int 0x40 ;вывод подписи 'Знак'
1457 IgorA 3584
 
6274 IgorA 3585
	cmp ted_tim_undo,0
3586
	je @f
3587
		add ebx,0x500000
3588
		lea edx,[txtOtm]
3589
		int 0x40
3590
		sub ebx,0x500000
3591
	@@:
1457 IgorA 3592
 
6274 IgorA 3593
	call ted_draw_buffer
3594
	call ted_draw_help_f1
1457 IgorA 3595
 
6274 IgorA 3596
	mov eax,47 ;draw cursor coords
3597
	mov esi,ted_color_wnd_bord
3598
	or  esi,0x40000000
1457 IgorA 3599
 
6274 IgorA 3600
	mov edx,ebx
3601
	ror edx,16
3602
	sub edx,35
3603
	ror edx,16
3604
	;add edx,3
3605
	mov ebx,0x40000 ;Row=...
3606
	mov ecx,ted_scr_w
3607
	mov ecx,[ecx+sb_offs_position]
3608
	add ecx,ted_cur_y
3609
	inc ecx
1457 IgorA 3610
 
3611
push edi
6274 IgorA 3612
	mov edi,ted_color_wnd_work
3613
	int 0x40 ;вывод числа текущей строки
1457 IgorA 3614
pop edi
3615
 
6274 IgorA 3616
	;mov ebx,0x40000 ;Col=...
3617
	mov ecx,ted_scr_h
3618
	mov ecx,[ecx+sb_offs_position]
3619
	add ecx,ted_cur_x
3620
	inc ecx
3621
	add edx,0x500000
1457 IgorA 3622
push edi
6274 IgorA 3623
	mov edi,ted_color_wnd_work
3624
	int 0x40 ;вывод числа знаков
1457 IgorA 3625
pop edi
3626
 
6274 IgorA 3627
	cmp ted_tim_undo,0
3628
	je @f
3629
		mov ecx,ted_tim_undo
3630
		add edx,0x500000
3631
		mov edi,ted_color_wnd_work ;портим регистр edi, но в конце функции это уже не важно
3632
		int 0x40 ;вывод числа отмененных действий
3633
	@@:
1457 IgorA 3634
 
6274 IgorA 3635
popad
3636
	ret
1457 IgorA 3637
endp
3638
 
3639
;input:
3640
; edi = pointer to tedit struct
6274 IgorA 3641
align 16
1457 IgorA 3642
proc ted_draw_buffer
3643
	pushad
3644
 
3645
	mov eax,ted_buffer
4228 IgorA 3646
	cmp dword[eax],1 ;смотрим размер буфера
3647
	jl @f
1458 IgorA 3648
		mov ebx,ted_rec_l
1457 IgorA 3649
		add bx,300
1458 IgorA 3650
		cmp ebx,ted_wnd_w ;сравниваем координату для вывод текста
3651
		jge @f ;подпись не влазит в окно
3652
 
3653
		add ebx,ted_wnd_l
1457 IgorA 3654
		shl ebx,16
3655
		add ebx,ted_wnd_t
3656
		add ebx,3
3657
		mov ecx,ted_color_wnd_bord
3658
		or ecx,0x40000000
3659
 
3660
		mov edx,ted_buffer
4228 IgorA 3661
		add edx,12
1457 IgorA 3662
		mov esi,edx
3663
		mov edi,ted_color_wnd_work ;edi - destroy not pointer to tedit
3664
		call tl_strlen
3665
		;cmp eax,0 ;буфер пуст
3666
		;je @f
3667
		cmp eax,20
3668
		jle .crop_buf
3669
			mov eax,20 ;обрезка подписи до 20 символов
3670
		.crop_buf:
3671
		mov esi,eax
6256 IgorA 3672
		mcall SF_DRAW_TEXT ;вывод содержимого буфера
1457 IgorA 3673
 
3674
		sub ebx,50 shl 16
3675
		lea edx,[txtBuf]
3676
		mov esi,edx
3677
		call tl_strlen
3678
		mov esi,eax
3679
		xor ecx,0x40000000 ;убираем цвет фона
6256 IgorA 3680
		mcall SF_DRAW_TEXT ;вывод подписи для буфера
1457 IgorA 3681
	@@:
3682
	popad
3683
	ret
3684
endp
3685
 
3686
;input:
3687
; edi = pointer to tedit struct
6274 IgorA 3688
align 16
1457 IgorA 3689
proc ted_draw_help_f1
1458 IgorA 3690
	pushad
3691
	cmp ted_rec_t,13 ;минимальная высота для рисования справки
3692
	jle @f
6087 IgorA 3693
		;clear place before draw help
1458 IgorA 3694
		mov ebx,ted_wnd_l
3695
		add ebx,ted_rec_l
3696
		shl ebx,16
3697
		add ebx,ted_wnd_w
3698
		sub ebx,ted_rec_l
3699
		mov ecx,ted_wnd_t
3700
		add ecx,13
3701
		shl ecx,16
6256 IgorA 3702
		add ecx,9 ;9 - высота 0-го шрифта, ставить ted_rec_h пока еще рано
3703
		mcall SF_DRAW_RECT,,,ted_color_wnd_capt
1457 IgorA 3704
 
1458 IgorA 3705
	cmp ted_help_id,-1
3706
	je @f
3707
		mov eax,ted_help_id
3708
		ColToIndexOffset eax,edx
1457 IgorA 3709
 
1458 IgorA 3710
		;SetCoordinates
3711
		mov ebx,ted_wnd_l
3712
		add ebx,ted_rec_l
3713
		shl ebx,16
3714
		add ebx,ted_wnd_t
3715
		add ebx,13 ;=3+10
1457 IgorA 3716
 
1458 IgorA 3717
		;SetTextColor
3718
		xor eax,eax
2102 IgorA 3719
		mov al,byte[edx+MAX_COLOR_WORD_LEN+7]
1458 IgorA 3720
		shl ax,2
3721
		mov ecx,ted_text_colors
3722
		add ecx,eax
6274 IgorA 3723
		mov ecx,[ecx]
1458 IgorA 3724
		or	ecx,0xc0000000 ;SetTextStyles
3725
		mov esi,edi
6256 IgorA 3726
		mcall SF_DRAW_TEXT,,,,,ted_color_wnd_work
1458 IgorA 3727
		mov edi,esi
1457 IgorA 3728
 
6087 IgorA 3729
		mov esi,edx
3730
		call tl_strlen
3731
 
1458 IgorA 3732
		;*** draw help string ***
3733
		mov ecx,ted_color_wnd_bord
3734
		or ecx,0x80000000
6274 IgorA 3735
		mov edx,[edx+MAX_COLOR_WORD_LEN]
3736
		or edx,edx
3737
		jz @f
1458 IgorA 3738
			add edx,ted_help_text_f1
6087 IgorA 3739
			inc eax
3740
			imul eax,6 ;ширина символа в сист. шрифте
3741
			shl eax,16
3742
			add ebx,eax
6256 IgorA 3743
			mcall SF_DRAW_TEXT
1458 IgorA 3744
	@@:
3745
	popad
3746
	ret
1457 IgorA 3747
endp
3748
 
3749
;input:
3750
; edi = pointer to tedit struct
6274 IgorA 3751
align 16
1457 IgorA 3752
proc ted_draw_line_numbers
6256 IgorA 3753
pushad
3754
	;top panel with caption
3755
	mov ebx,ted_wnd_l
6274 IgorA 3756
	;add ebx,ted_rec_l
6256 IgorA 3757
	shl ebx,16
3758
	add ebx,ted_wnd_w
6274 IgorA 3759
	;sub ebx,ted_rec_l
6256 IgorA 3760
	mov edx,ted_color_wnd_work
3761
	mov ecx,ted_wnd_t
3762
	shl ecx,16
3763
	add ecx,ted_rec_t
3764
	mov edx,ted_color_wnd_capt
3765
	mcall SF_DRAW_RECT
1457 IgorA 3766
 
6256 IgorA 3767
	;line numbers
3768
	mov ebx,0x40000 ;format
3769
	mov ecx,ted_scr_w
6274 IgorA 3770
	mov ecx,[ecx+sb_offs_position]
6256 IgorA 3771
	inc ecx
3772
	mov edx,3
3773
	add edx,ted_wnd_l
3774
	rol edx,16
3775
	add edx,ted_wnd_t
3776
	add edx,ted_rec_t
3777
	@@:
1457 IgorA 3778
 
3779
push ebx ecx edx
6256 IgorA 3780
	;left panel with numbers
3781
	mov ebx,ted_wnd_l
3782
	shl ebx,16
3783
	add ebx,ted_rec_l
3784
	mov ecx,ted_rec_h
3785
	rol ecx,16
3786
	mov cx,dx
3787
	rol ecx,16
3788
	mov edx,ted_color_wnd_capt
3789
	mcall SF_DRAW_RECT ;рисуем прямоугольник под номером строки
1457 IgorA 3790
pop edx ecx ebx
3791
 
6256 IgorA 3792
		mov esi,ted_color_wnd_bord
6274 IgorA 3793
		mcall SF_DRAW_NUMBER ;рисуем номер строки
6256 IgorA 3794
		inc ecx
3795
		add edx,ted_rec_h
3796
		sub edx,ted_wnd_t
3797
		mov esi,edx
3798
		and esi,0xffff
3799
		cmp esi,ted_wnd_h
3800
		jge @f
3801
		add edx,ted_wnd_t
3802
		jmp @b
3803
align 4
3804
	@@:
3805
popad
3806
	ret
1457 IgorA 3807
endp
3808
 
3809
;output:
3810
; ah = symbol
6274 IgorA 3811
align 16
3812
proc KeyConvertToASCII uses ebx, table:dword
3813
	mov ebx,[table] ;convert scan to ascii
1464 IgorA 3814
	ror ax,8
3815
	xor ah,ah
3816
	add bx,ax ;? ebx,eax
3817
	mov ah,byte[ebx]
3818
	ret
1457 IgorA 3819
endp
3820
 
6274 IgorA 3821
align 16
1457 IgorA 3822
proc ted_draw_cur_line, edit:dword
6274 IgorA 3823
pushad
3824
	mov edi,[edit]
1457 IgorA 3825
 
6274 IgorA 3826
	mov ebx,ted_wnd_l
3827
	add ebx,ted_rec_l
3828
	shl ebx,16
3829
	mov eax,ted_cur_y
3830
	imul eax,ted_rec_h
1457 IgorA 3831
	mov bx,ax
6274 IgorA 3832
	add ebx,ted_wnd_t
3833
	add ebx,ted_rec_t ;ebx - координаты для прямоугольника очистки линии
1457 IgorA 3834
	add ebx,0x10001   ;добавляем отступы для выравнивания буквы по центру
3835
 
6274 IgorA 3836
	call ted_sel_normalize ;need before draw select
1457 IgorA 3837
	mov ecx,ted_cur_y
3838
	mov eax,ted_scr_w
6274 IgorA 3839
	add ecx,[eax+sb_offs_position]
3840
	stdcall ted_clear_line_before_draw,edi,ebx,1,ecx
1457 IgorA 3841
 
6274 IgorA 3842
	mov eax,ted_scr_h
3843
	mov esi,[eax+sb_offs_position]
3844
	call ted_get_pos_by_coords
1457 IgorA 3845
 
6274 IgorA 3846
	cmp ted_gp_opt,2
3847
	jne .no_draw_text
3848
	call ted_get_symb_color
3849
	mov esi,1 ;draw 1 symbol
3850
	@@:
3851
		;call ted_iterat_next
3852
		cmp edx,ted_tex_1
3853
		jle .no_draw_text
1457 IgorA 3854
 
6274 IgorA 3855
		; *** цветовая разметка
3856
		cmp ted_mode_color,0
3857
		je .no_col_change
3858
		cmp byte[edx+1],0
3859
		je .no_col_change
3860
			call ted_get_symb_color
3861
		.no_col_change:
1457 IgorA 3862
 
6274 IgorA 3863
		mov eax,SF_DRAW_TEXT
3864
		cmp byte [edx],13
3865
		jne .no_13
3866
			cmp ted_mode_invis,1
3867
			jne .no_draw_text
3868
			push edx
3869
			mov edx,edi
3870
			add edx,ted_offs_symbol_new_line
3871
			int 0x40
3872
			pop edx
3873
			jmp .no_draw_text
3874
align 4
3875
		.no_13:
1457 IgorA 3876
 
6274 IgorA 3877
		int 0x40
3878
		ror ebx,16
3879
		add ebx,ted_rec_w
3880
		mov eax,ted_wnd_w
3881
		add eax,ted_wnd_l ;ax = отступ по оси x
3882
		cmp bx,ax
3883
		jge .no_draw_text ;Opt
3884
		ror ebx,16
3885
		call ted_iterat_next
3886
		jmp @b
3887
align 4
3888
	.no_draw_text:
1457 IgorA 3889
 
6274 IgorA 3890
	call ted_draw_main_cursor
3891
popad
3892
	ret
1457 IgorA 3893
endp
3894
 
3895
;input:
3896
;  clear_o - если =1 очистить одну строку, =0 очистить все строки окна до низу
6274 IgorA 3897
align 16
1457 IgorA 3898
proc ted_clear_line_before_draw, edit:dword, coords:dword, clear_o:dword, numb_lin:dword
3899
	pushad
6274 IgorA 3900
	mov edi,[edit]
3901
	mov ebx,[coords] ;ebx = x*2^16+y coords to left up point clear line
3902
	mov esi,[numb_lin] ;esi - number text line
1457 IgorA 3903
 
3904
	sub ebx,0x10001 ;отнимаем отступы для выравнивания буквы по центру
3905
	cmp dword[clear_o],0
3906
	jne @f
3907
		add ebx,ted_rec_h
3908
		ror ebx,16
3909
		xor bx,bx
3910
		add ebx,ted_wnd_l
3911
		add ebx,ted_rec_l ;bx = ted_wnd_l+ted_rec_l
3912
		ror ebx,16
3913
	@@:
3914
 
3915
	mov eax,ted_wnd_h
3916
	add eax,ted_wnd_t
3917
	cmp ax,bx
3918
	jl .no_clear
3919
	sub ax,bx
3920
 
3921
	mov cx,bx
3922
	shl ecx,16
3923
 
3924
	xor bx,bx
3925
	add ebx,ted_wnd_w
3926
	sub ebx,ted_rec_l
3927
	xor cx,cx
3928
	add ecx,ted_rec_h
3929
	mov edx,ted_color_wnd_work
3930
 
3931
	cmp dword[clear_o],0
3932
	je .pusto
3933
	cmp ax,cx
3934
	jge @f
3935
	.pusto:
3936
		mov cx,ax
4988 IgorA 3937
		jmp .no_select ;если очистка окна до низу, то всегда фоновым цветом
1457 IgorA 3938
	@@:
3939
 
3940
	call ted_is_select
7576 IgorA 3941
	or al,al
3942
	jz .no_select
1457 IgorA 3943
	cmp ted_seln_y0,esi
4988 IgorA 3944
	jg .no_select
1457 IgorA 3945
	cmp ted_seln_y1,esi
4988 IgorA 3946
	jl .no_select
1457 IgorA 3947
		mov edx,ted_color_select ;draw selected line
4988 IgorA 3948
	.no_select:
1457 IgorA 3949
 
6256 IgorA 3950
	mcall SF_DRAW_RECT ;закраска полной строки цветом фона или цветом выделения
1457 IgorA 3951
 
3952
	call ted_is_select
6256 IgorA 3953
	or al,al
3954
	jz .no_clear
1457 IgorA 3955
 
6256 IgorA 3956
	mov al,SF_DRAW_RECT
1457 IgorA 3957
	xor cx,cx
3958
	add ecx,ted_rec_h
3959
	cmp ted_seln_y0,esi
3960
	jne @f
3961
		push bx esi
3962
		mov edx,ted_seln_x0 ; верхняя полоса (затирает слева)
3963
		mov esi,ted_scr_h
6274 IgorA 3964
		cmp edx,[esi+sb_offs_position]
1457 IgorA 3965
		jle .in_wnd
6274 IgorA 3966
			sub edx,[esi+sb_offs_position]
1457 IgorA 3967
			imul edx,ted_rec_w
3968
			mov bx,dx
3969
			jmp .no_wnd
3970
		.in_wnd:
7497 IgorA 3971
		xor bx,bx
1457 IgorA 3972
		.no_wnd:
3973
		mov edx,ted_color_wnd_work
3974
		int 0x40
3975
		pop esi bx
3976
	@@:
3977
	cmp ted_seln_y1,esi
3978
	jne @f
4988 IgorA 3979
		;push esi
3980
		;если выделен весь файл тут можно сделать выход, но тогда нужно выше убрать jmp .no_select
1457 IgorA 3981
		mov edx,ted_seln_x1 ; нижняя полоса (затирает справа)
3982
		mov esi,ted_scr_h
6274 IgorA 3983
		cmp edx,[esi+sb_offs_position]
1457 IgorA 3984
		jle .in_wnd2
6274 IgorA 3985
			sub edx,[esi+sb_offs_position]
1457 IgorA 3986
			imul edx,ted_rec_w
3987
			sub bx,dx
3988
			shl edx,16
3989
			add ebx,edx
3990
		.in_wnd2:
3991
		mov edx,ted_color_wnd_work
3992
		int 0x40
4988 IgorA 3993
		;pop esi
1457 IgorA 3994
	@@:
3995
 
3996
	.no_clear:
3997
	popad
3998
	ret
3999
endp
4000
 
4001
;input:
4002
; edi = pointer to tedit struct
4003
;output:
4004
; ecx = новый цвет символа
4005
; edx = pointer to symbol
4006
; edx = 0 if text not in screen
6274 IgorA 4007
align 16
1457 IgorA 4008
ted_get_first_visible_pos:
4009
	push eax ecx
4010
	mov eax,ted_scr_w
4011
	mov edx,ted_tex
4012
	xor ecx,ecx
4013
	@@:
6274 IgorA 4014
		cmp ecx,[eax+sb_offs_position]
1457 IgorA 4015
		je @f
4016
		call ted_iterat_next
4017
		cmp edx,ted_tex_1
4018
		jle @f
6256 IgorA 4019
		cmp byte[edx],13
1457 IgorA 4020
		jne @b
4021
		inc ecx
4022
		jmp @b
6256 IgorA 4023
align 4
1457 IgorA 4024
	@@:
4025
 
6274 IgorA 4026
	cmp ecx,[eax+sb_offs_position]
1457 IgorA 4027
	je @f
4028
		xor edx,edx
4029
	@@:
6274 IgorA 4030
	cmp ecx,[eax+sb_offs_max_area]
1457 IgorA 4031
	jle @f
6274 IgorA 4032
		mov [eax+sb_offs_max_area],ecx
1457 IgorA 4033
	@@:
4034
	pop ecx eax
4035
	call ted_opt_draw_line_left
4036
	ret
4037
 
4038
;input:
4039
; edx = pointer to symbol
4040
; edi = pointer to tedit struct
4041
;output:
4042
; ecx = цвет символа
4043
; edx = указатель на первый левый символ
4044
;description:
4045
; функция нужна для оптимизации вывода текста
6274 IgorA 4046
align 16
6256 IgorA 4047
proc ted_opt_draw_line_left uses ebx
4048
	mov ebx,ted_scr_h
6274 IgorA 4049
	mov ebx,[ebx+sb_offs_position]
6256 IgorA 4050
	or ebx,ebx
4051
	jz .ret_f
4052
	push eax
4053
	mov eax,edx
1457 IgorA 4054
 
6256 IgorA 4055
	cmp edx,ted_tex
4056
	jne @f
4057
		call ted_iterat_next
4058
		jmp .beg_cycle
4059
	@@:
1457 IgorA 4060
 
6256 IgorA 4061
	or ebx,ebx
4062
	jz @f
1457 IgorA 4063
 
6256 IgorA 4064
	cmp byte[edx],13
4065
	jne @f
4066
		call ted_iterat_next
4067
		.beg_cycle:
4068
	@@:
4069
		cmp edx,ted_tex_1
4070
		jle @f
4071
		cmp byte[edx],13
4072
		je @f
4073
		or ebx,ebx
4074
		jz @f
1457 IgorA 4075
;--------------------------------------
4076
xor eax,eax ;eax будет меняться
4077
mov al,byte[edx+1]
6256 IgorA 4078
or al,al
4079
jz .no_color
1457 IgorA 4080
cmp eax,ted_colors_text_count
4081
jge .no_color
6256 IgorA 4082
	xor ecx,ecx
4083
	mov cl,byte[edx+1]
4084
	shl cx,2
4085
	add ecx,ted_text_colors
6274 IgorA 4086
	mov ecx,[ecx]
1457 IgorA 4087
.no_color:
4088
;--------------------------------------
6256 IgorA 4089
		mov eax,edx
4090
		call ted_iterat_next
4091
		dec ebx
4092
		jmp @b
4093
align 4
4094
	@@:
4095
		mov edx,eax
4096
	pop eax
4097
	.ret_f:
4098
	call ted_get_symb_color
4099
	ret
1457 IgorA 4100
endp
4101
 
4102
;input:
4103
; edx = pointer to symbol
4104
; edi = pointer to tedit struct
4105
;output:
4106
; ecx = symbol color
4107
; edx = pointer to 13 symbol
4108
;description:
4109
; функция нужна для оптимизации вывода текста
6274 IgorA 4110
align 16
1457 IgorA 4111
proc ted_opt_draw_line_right
4112
	push eax
4113
	mov eax,edx
4114
	@@:
4115
		cmp edx,ted_tex_1
4116
		jle @f
4117
		cmp byte[edx],13
4118
		je @f
4119
		mov eax,edx
4120
		call ted_iterat_next
4121
		jmp @b
4122
	@@:
4123
	mov edx,eax ;perv sumbol
4124
	call ted_get_symb_color
4125
 
4126
	pop eax
4127
	ret
4128
endp
4129
 
6274 IgorA 4130
align 16
1457 IgorA 4131
proc ted_mouse, edit:dword
4132
	pushad
6274 IgorA 4133
	mov edi,[edit]
1457 IgorA 4134
 
4135
	;обрабатываем скроллинги
4136
	mov edx,ted_scr_h
4137
	mov ecx,ted_scr_w
4138
 
4139
	cmp word[edx+sb_offs_delta2],0
4140
	jne .horizontal
4141
 
6274 IgorA 4142
	mov eax,[ecx+sb_offs_max_area]
4143
	cmp eax,[ecx+sb_offs_cur_area]
1457 IgorA 4144
	jbe .horizontal
4145
	; mouse event for Vertical ScrollBar
4146
	stdcall scroll_bar_vertical.mouse,ecx ;[scrollbar_ver_mouse]
4147
	cmp dword[ecx+sb_offs_redraw],0
4148
	je @f
4149
		mov dword[ecx+sb_offs_redraw],0
4150
		stdcall ted_draw,edi
4151
		jmp .no_in_wnd
4152
	@@:
4153
	cmp word[ecx+sb_offs_delta2],0
4154
	jne .no_in_wnd
4155
	.horizontal:
6274 IgorA 4156
	mov eax,[edx+sb_offs_max_area]
4157
	cmp eax,[edx+sb_offs_cur_area]
1457 IgorA 4158
	jbe .other
4159
	; mouse event for Horizontal ScrollBar
4160
	stdcall scroll_bar_horizontal.mouse,edx ;[scrollbar_hor_mouse]
4161
	cmp dword[edx+sb_offs_redraw],0
4162
	je .other
4163
		mov dword[edx+sb_offs_redraw],0
4164
		stdcall ted_draw,edi
4165
		jmp .no_in_wnd
4166
	.other:
4167
	cmp word[ecx+sb_offs_delta2],0
4168
	jne .no_in_wnd
4169
	cmp word[edx+sb_offs_delta2],0
4170
	jne .no_in_wnd
4171
 
4172
	;обрабатываем окно редактора
6274 IgorA 4173
	mcall SF_MOUSE_GET,SSF_BUTTON
1457 IgorA 4174
	cmp al,1
4175
	jne @f
6274 IgorA 4176
		mcall SF_MOUSE_GET,SSF_WINDOW_POSITION
1457 IgorA 4177
		mov ebx,ted_wnd_t
4178
		add ebx,ted_rec_t
4179
		cmp ax,bx
4180
		jl @f ;y_mouse
4181
 
4182
		sub ebx,ted_rec_t
4183
		add ebx,ted_wnd_h
4184
		cmp bx,ax
4185
		jl @f ;y_mouse>y_wnd
4186
 
4187
		mov ebx,ted_wnd_l
4188
		add ebx,ted_rec_l
4189
		mov ecx,eax
4190
		shr ecx,16
4191
		cmp cx,bx
4192
		jl @f ;x_mouse
4193
 
4194
		sub ebx,ted_rec_l
4195
		add ebx,ted_wnd_w
4196
		cmp bx,cx
4197
		jl @f ;x_mouse>x_wnd
4198
 
4199
		call ted_draw_cursor_sumb
4200
		call ted_wnd_main_click
4201
		jmp .no_in_wnd
4202
	@@:
1458 IgorA 4203
	mov edx,ted_el_focus
6274 IgorA 4204
	cmp [edx],edi
1458 IgorA 4205
	jne @f
4206
		call ted_wnd_main_mouse_scroll ;смотрим на прокрутку колеса мыши
4207
	@@:
1457 IgorA 4208
	cmp ted_drag_m,0
4209
	je .no_in_wnd
4210
		mov ted_drag_m,0
4211
		stdcall ted_draw,edi
4212
		cmp ted_fun_draw_panel_buttons,0
4213
		je .no_in_wnd
4214
			call ted_fun_draw_panel_buttons
4215
	.no_in_wnd:
4216
	popad
4217
	ret
4218
endp
4219
 
4220
;input:
4221
; eax -> (x,y)
4222
; edi -> указатель на структуру tedit
4223
;description:
4224
; функция вызывется при нажатии кнопкой мыши и попадении курсором в окно редактора
6274 IgorA 4225
align 16
1457 IgorA 4226
ted_wnd_main_click:
1458 IgorA 4227
	push ebx ecx edx
4228
	mov ebx,ted_el_focus
6274 IgorA 4229
	mov [ebx],edi ;ставим фокус
1457 IgorA 4230
 
6087 IgorA 4231
	push eax
4232
		shr eax,16
4233
		sub eax,ted_wnd_l
4234
		sub eax,ted_rec_l
1457 IgorA 4235
 
6087 IgorA 4236
		xor edx,edx
4237
		mov ecx,ted_rec_w
4238
		div cx
4239
		;inc eax
4240
		mov ebx,ted_scr_h
6274 IgorA 4241
		cmp eax,[ebx+sb_offs_cur_area]
6087 IgorA 4242
		jle @f
6274 IgorA 4243
			mov eax,[ebx+sb_offs_cur_area]
6087 IgorA 4244
		@@:
4245
		;dec eax
4246
		mov ted_cur_x,eax
4247
	pop eax
1457 IgorA 4248
 
6087 IgorA 4249
	push eax
4250
		and eax,0xffff
4251
		sub eax,ted_wnd_t
4252
		sub eax,ted_rec_t
1457 IgorA 4253
 
6087 IgorA 4254
		xor edx,edx
4255
		mov ecx,ted_rec_h
4256
		div cx
4257
		inc eax
4258
		mov ebx,ted_scr_w
6274 IgorA 4259
		cmp eax,[ebx+sb_offs_cur_area]
6087 IgorA 4260
		jle @f
6274 IgorA 4261
			mov eax,[ebx+sb_offs_cur_area]
6087 IgorA 4262
		@@:
4263
		dec eax
4264
		mov ted_cur_y,eax
4265
	pop eax
1457 IgorA 4266
 
1458 IgorA 4267
	cmp ted_drag_m,0
4268
	je @f
4269
		call ted_sel_move
4270
		jmp .sel_move
4271
	@@:
4272
		mov ted_drag_m,1
4273
		call ted_sel_start
4274
	.sel_move:
4275
	pop edx ecx ebx
4276
	ret
1457 IgorA 4277
 
4278
;input:
4279
; edi = pointer to tedit struct
6274 IgorA 4280
align 16
1457 IgorA 4281
ted_wnd_main_mouse_scroll:
4282
	push eax ebx ecx
6274 IgorA 4283
	mcall SF_MOUSE_GET,SSF_SCROLL_DATA
4284
	or ax,ax
4285
	jz .no_scroll
1457 IgorA 4286
		mov ecx,ted_scr_w
6274 IgorA 4287
		mov ebx,[ecx+sb_offs_position] ;copy old scroll position
1457 IgorA 4288
		and eax,0xffff
4289
		btr ax,15
4290
		jae @f
4291
			or eax,0xffff8000
1458 IgorA 4292
		@@:
6274 IgorA 4293
		add [ecx+sb_offs_position],eax
1457 IgorA 4294
 
1458 IgorA 4295
		mov eax,[ecx+sb_offs_position]
4296
		cmp eax,[ecx+sb_offs_max_area]
4297
		jb @f
6274 IgorA 4298
			mov [ecx+sb_offs_position],ebx ;if scroll position out of range
1458 IgorA 4299
			jmp .no_scroll
4300
		@@:
4301
		stdcall ted_draw,edi
1457 IgorA 4302
	.no_scroll:
4303
	pop ecx ebx eax
4304
	ret
4305
 
6274 IgorA 4306
align 16
4308 IgorA 4307
proc ted_save_file, edit:dword, file:dword, f_name:dword
6274 IgorA 4308
pushad
4309
	mov edi,[edit]
1457 IgorA 4310
 
6274 IgorA 4311
	stdcall ted_can_save,edi
4312
	;or al,al
4313
	;jz .no_save
1457 IgorA 4314
 
6274 IgorA 4315
	mov ecx,ted_max_chars
4316
	invoke mem.alloc,ecx
4317
	push eax ;запоминаем указатель на выделенную память
1457 IgorA 4318
 
6274 IgorA 4319
	mov edx,ted_tex
4320
	xor ecx,ecx
4321
	@@:
4322
		call ted_iterat_next
4323
		cmp edx,ted_tex_1
4324
		jle @f ;edx = ted_tex or edx = ted_tex+sizeof.symbol
4325
		mov bl,[edx]
4326
		mov byte[eax],bl
4327
		inc eax
4328
		inc ecx
4329
		jmp @b
4330
align 4
4331
	@@:
1457 IgorA 4332
 
6274 IgorA 4333
	or ecx,ecx
4334
	jz @f
4335
		mov ebx,[file]
4336
		pop eax ;записываем указатель на выделенную память
4337
		mov [ebx+16],eax
4338
		push eax ;обратно запоминаем указатель на выделенную память
4339
		mov dword[ebx], SSF_CREATE_FILE
4340
		mov dword[ebx+4], 0
4341
		mov dword[ebx+8], 0
4342
		mov [ebx+12], ecx
4343
		mov  byte[ebx+20], 0
4344
		push dword[f_name]
4345
		pop dword[ebx+21]
4346
		mcall SF_FILE
1457 IgorA 4347
 
6274 IgorA 4348
		mov ted_err_save,al
1457 IgorA 4349
 
6274 IgorA 4350
		or eax,eax
4351
		jz .no_msg
4352
		;cmp eax,6
4353
		;je @f
4354
		cmp ax,10
4355
		jl .zifra_0_9
4356
			mov al,'?'
4357
			sub ax,48
4358
		.zifra_0_9:
4359
		add ax,48
4360
		cmp ted_fun_save_err,0
4361
		je @f
4362
		call ted_fun_save_err
4363
		jmp @f
4364
		.no_msg:
4365
		m2m ted_tim_ls,ted_tim_ch
4366
	@@:
1457 IgorA 4367
 
6274 IgorA 4368
	pop ecx ;записываем указатель на выделенную память
4369
	invoke mem.free,ecx
4370
	.no_save:
4371
popad
4372
	ret
1457 IgorA 4373
endp