Subversion Repositories Kolibri OS

Rev

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