Subversion Repositories Kolibri OS

Rev

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