Subversion Repositories Kolibri OS

Rev

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