Subversion Repositories Kolibri OS

Rev

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