Subversion Repositories Kolibri OS

Rev

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