Subversion Repositories Kolibri OS

Rev

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