Subversion Repositories Kolibri OS

Rev

Rev 4308 | 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
4542 IgorA 3
; файл последний раз изменялся 28.01.2014 IgorA
1457 IgorA 4
; на код применена GPL2 лицензия
5
 
6
;input:
7
; edi = pointer to tedit struct
8
; reg = index
9
;output:
10
; reg = pointer to 'tex' struct
11
macro ConvertIndexToPointer reg {
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
	mov byte[ebx],0
2590
 
4542 IgorA 2591
	cmp ecx,12
1457 IgorA 2592
	je .end_f
4542 IgorA 2593
		inc ecx ;размер данных в буфере + символ завершения строки
4228 IgorA 2594
		mov ebx,ted_buffer
4542 IgorA 2595
		mov dword[ebx],ecx
2596
		mcall 54,2,ecx,ted_buffer
1457 IgorA 2597
		call ted_draw_buffer
2598
		cmp ted_fun_draw_panel_buttons,0
2599
		je .end_f
2600
			call ted_fun_draw_panel_buttons
2601
	.end_f:
2602
	popad
2603
	ret
2604
endp
2605
 
2606
 
2607
align 4
2608
proc ted_but_paste, edit:dword
4228 IgorA 2609
	pushad
1457 IgorA 2610
	mov edi,dword[edit]
2611
 
4228 IgorA 2612
	mcall 54,0
2613
	cmp eax,1
2614
	jl .no_buf_r
2615
 
2616
	mov esi,eax
2617
	.cycle: ;обратный цикл по слотам
2618
	dec esi ;номер текущего, проверяемого слота
2619
	mcall 54,1,esi ;read system buffer
2620
	cmp eax,1
2621
	je .no_buf_r
2622
	cmp eax,-1
2623
	je .no_buf_r
2624
		mov ecx,dword[eax]
2625
		cmp ecx,1 ;size
2626
		jl .no_buf_r
2627
		cmp dword[eax+4],0 ;text
2628
		je @f
2629
			cmp esi,1
2630
			jge .cycle ;если в буфере не текст, а слотов в буфере несколько, пробуем перейти к верхнему слоту
2631
			jmp .no_buf_r
2632
		@@:
2633
		cmp dword[eax+8],1 ;866
2634
		je @f
2635
			cmp esi,1
2636
			jge .cycle ;если в буфере текст не в кодировке 866 ... пробуем перейти к верхнему слоту
2637
			jmp .no_buf_r
2638
		@@:
2639
		;копирование текста из системного буфера во внутренний
2640
		cmp ecx,ted_buffer_size
2641
		jle @f
2642
			mov ecx,ted_buffer_size
2643
		@@:
2644
		mov edi,ted_buffer
2645
		mov esi,eax
2646
		add	esi,4 ;12
2647
		mov dword[edi],ecx
2648
		add edi,4 ;12
2649
		sub ecx,4 ;12
2650
		rep movsb
2651
		mov edi,dword[edit]
2652
 
2653
		mov esi,eax
2654
		add	esi,12
2655
		jmp .buf_r
2656
	.no_buf_r:
2657
 
2658
	;если не удалось прочитать данные из системного буфера, попадаем сюда
1457 IgorA 2659
	mov esi,ted_buffer
4228 IgorA 2660
	cmp dword[esi],1 ;проверяем есть ли данные во внутреннем буфере
2661
	jl .no_paste ;если вообще ничего не удалось прочитать идем на выход
2662
	add esi,12 ;system buffer header size
2663
	.buf_r:
2664
 
2665
	mov edx,esi
1457 IgorA 2666
	call tl_strlen
2667
	cmp eax,1
4228 IgorA 2668
	jl .no_paste
1457 IgorA 2669
		mov esi,eax
2670
		call ted_set_undo
2671
		mov ebx,ted_opt_ed_change_time+ted_opt_ed_move_cursor
2672
		stdcall ted_sel_text_del,ebx
2673
		cmp al,1
2674
		jne .del
2675
			mov ebx,ted_opt_ed_move_cursor
2676
		.del:
4228 IgorA 2677
		stdcall ted_text_add,edi,edx,esi,ebx
1457 IgorA 2678
		stdcall ted_draw,edi
2679
		cmp ted_fun_draw_panel_buttons,0
4228 IgorA 2680
		je .no_paste
1457 IgorA 2681
			call ted_fun_draw_panel_buttons
4228 IgorA 2682
	.no_paste:
2683
	popad
1457 IgorA 2684
	ret
2685
endp
2686
 
2687
align 4
2324 IgorA 2688
proc ted_but_sumb_upper uses edi esi, edit:dword
2689
	mov edi,dword[edit]
1457 IgorA 2690
 
2324 IgorA 2691
	stdcall ted_convert_sel_text,fb_char_toupper
2692
	cmp esi,0
2693
	je @f
2694
		stdcall ted_draw,edi
2695
	@@:
2696
	ret
1457 IgorA 2697
endp
2698
 
2699
align 4
2324 IgorA 2700
proc ted_but_sumb_lover uses edi esi, edit:dword
2701
	mov edi,dword[edit]
1457 IgorA 2702
 
2324 IgorA 2703
	stdcall ted_convert_sel_text,fb_char_todown
2704
	cmp esi,0
2705
	je @f
2706
		stdcall ted_draw,edi
2707
	@@:
2708
	ret
1457 IgorA 2709
endp
2710
 
2711
align 4
2712
proc ted_but_reverse, edit:dword
2713
  push eax ebx edi
2714
  mov edi,dword[edit]
2715
 
2716
  call ted_is_select
2717
  cmp al,0
2718
  je @f
2719
    call ted_sel_normalize
2720
    push esi ecx edx
2721
      mov esi,ted_seln_x0
2722
      mov ecx,ted_seln_y0
2723
      call ted_get_pos_by_coords
2724
      mov eax,edx
2725
      mov esi,ted_seln_x1
2726
      cmp esi,0
2727
      je .beg_str
2728
	dec esi
2729
      .beg_str:
2730
      mov ecx,ted_seln_y1
2731
      call ted_get_pos_by_coords
2732
      ;call ted_get_text_perv_pos
2733
      mov ebx,edx
2734
    pop edx ecx esi
2735
    ;cmp eax,...
2736
    ;je @f
2737
    call ted_revers
2738
  @@:
2739
  stdcall ted_draw,edi
2740
  pop edi ebx eax
2741
  ret
2742
endp
2743
 
2744
align 4
2745
proc ted_but_undo, edit:dword
2746
	push eax edi
2747
	mov edi,dword[edit]
2748
 
2749
	mov eax,ted_tim_undo
2750
	cmp ted_tim_ch,eax
2751
	jbe @f
2752
		inc ted_tim_undo
2753
		;call ted_text_colored
2754
		stdcall ted_draw,edi
2755
		cmp ted_fun_draw_panel_buttons,0
2756
		je @f
2757
			call ted_fun_draw_panel_buttons
2758
	@@:
2759
	pop edi eax
2760
	ret
2761
endp
2762
 
2763
align 4
2764
proc ted_but_redo, edit:dword
2765
	push edi
2766
	mov edi,dword[edit]
2767
 
2768
	cmp ted_tim_undo,1
2769
	jb @f
2770
		dec ted_tim_undo
2771
		;call ted_text_colored
2772
		stdcall ted_draw,edi
2773
		cmp ted_fun_draw_panel_buttons,0
2774
		je @f
2775
			call ted_fun_draw_panel_buttons
2776
	@@:
2777
	pop edi
2778
	ret
2779
endp
2780
 
2781
align 4
2782
proc ted_but_find_next, edit:dword
2783
	pushad
2784
	mov edi,dword[edit]
2785
 
2786
	call ted_get_pos_by_cursor
2787
	mov eax,ted_buffer_find
2788
	mov bl,byte[eax]
2789
	@@:
2790
		call ted_get_find_rezult
2791
		cmp bh,1
2792
		je @f ; find
2793
			call ted_iterat_next
2794
			cmp edx,ted_tex_1
2795
			jle @f
2796
			jmp @b
2797
	@@:
2798
	cmp bh,0
2799
	je @f
2800
		call ted_get_text_coords
2801
		inc ebx ;move cursor right
2802
		mov ted_sel_x1,ebx
2803
		mov ted_sel_y1,eax
2804
		mov edx,eax
2805
		mov ecx,ebx
2806
		call ted_go_to_pos
2807
		mov edx,esi ;esi было установлео в ted_get_find_rezult
2808
		call ted_get_text_coords
2809
		mov ted_sel_x0,ebx
2810
		mov ted_sel_y0,eax
2811
		stdcall ted_draw,edi
2812
		jmp .end_find
2813
	@@:
2814
		;попадаем сюда если текст не найден
2815
		cmp ted_fun_find_err,0
2816
		je .end_find
2817
			call ted_fun_find_err ;пользовательская функция
2818
	.end_find:
2819
	popad
2820
	ret
2821
endp
2822
 
2823
;input:
2824
; edi = pointer to tedit struct
2825
align 4
2826
ted_key_ctrl_home:
2827
	mov ted_cur_x,0
2828
	mov ted_cur_y,0
2829
	push eax
2830
		mov eax,ted_scr_w
2831
		mov dword[eax+sb_offs_position],0
2832
		mov eax,ted_scr_h
2833
		mov dword[eax+sb_offs_position],0
2834
	pop eax
2835
	stdcall ted_draw,edi
2836
	cmp ted_fun_draw_panel_buttons,0
2837
	je @f
2838
		call ted_fun_draw_panel_buttons
2839
	@@:
2840
	ret
2841
 
2842
;input:
2843
; edi = pointer to tedit struct
2844
align 4
2845
proc ted_sel_key_up
2846
  cmp ted_drag_k,1
2847
  je @f
2848
    call ted_sel_start
2849
    mov ted_drag_k,1
2850
  @@:
2851
  push dx
2852
    call ted_cur_move_up
2853
    cmp dl,8
2854
    jne @f
2855
      call ted_scroll_set_redraw
2856
    @@:
2857
  pop dx
2858
  call ted_sel_move
2859
  stdcall ted_draw,edi
2860
  ret
2861
endp
2862
 
2863
;input:
2864
; edi = pointer to tedit struct
2865
align 4
2866
proc ted_sel_key_down
2867
  cmp ted_drag_k,1
2868
  je @f
2869
    call ted_sel_start
2870
    mov ted_drag_k,1
2871
  @@:
2872
  push dx
2873
    call ted_cur_move_down
2874
    cmp dl,8
2875
    jne @f
2876
      call ted_scroll_set_redraw
2877
    @@:
2878
  pop dx
2879
  call ted_sel_move
2880
  stdcall ted_draw,edi
2881
  ret
2882
endp
2883
 
2884
;input:
2885
; edi = pointer to tedit struct
2886
align 4
2887
proc ted_sel_key_left
2888
  cmp ted_drag_k,1
2889
  je @f
2890
    call ted_sel_start
2891
  @@:
2892
  push dx
2893
    call ted_cur_move_left
2894
    call ted_sel_move
2895
    cmp ted_drag_k,1
2896
    je @f
2897
      mov ted_drag_k,1
2898
      mov dl,8
2899
    @@:
2900
    cmp dl,8
2901
    jne @f
2902
      call ted_scroll_set_redraw
2903
      stdcall ted_draw,edi
2904
      jmp .end_f
2905
    @@:
2906
      stdcall ted_draw_cur_line,edi
2907
    .end_f:
2908
  pop dx
2909
  ret
2910
endp
2911
 
2912
;input:
2913
; edi = pointer to tedit struct
2914
align 4
2915
proc ted_sel_key_right
2916
  cmp ted_drag_k,1
2917
  je @f
2918
    call ted_sel_start
2919
  @@:
2920
  push dx
2921
    call ted_cur_move_right
2922
    call ted_sel_move
2923
    cmp ted_drag_k,1
2924
    je @f
2925
      mov ted_drag_k,1
2926
      mov dl,8
2927
    @@:
2928
    cmp dl,8
2929
    jne @f
2930
      call ted_scroll_set_redraw
2931
      stdcall ted_draw,edi
2932
      jmp .end_f
2933
    @@:
2934
      stdcall ted_draw_cur_line,edi
2935
    .end_f:
2936
  pop dx
2937
  ret
2938
endp
2939
 
2940
;input:
2941
; edi = pointer to tedit struct
2942
;description:
2943
; this function need to optimize output
2944
align 4
2945
proc ted_draw_cursor_sumb
2946
  pushad
2947
 
2948
  mov eax,13 ;rect
2949
  mov ebx,ted_wnd_l
2950
  add ebx,ted_rec_l
2951
  mov edx,ted_cur_x
2952
  imul edx,ted_rec_w
2953
  add ebx,edx
2954
  shl ebx,16
2955
  add ebx,ted_rec_w
2956
 
2957
  mov ecx,ted_wnd_t ;calc rect -> y0,y1
2958
  add ecx,ted_rec_t
2959
  mov edx,ted_cur_y
2960
  imul edx,ted_rec_h
2961
  add ecx,edx
2962
  shl ecx,16
2963
  add ecx,ted_rec_h
2964
 
2965
  mov edx,ted_color_wnd_work
2966
  push ecx
2967
    call ted_sel_normalize
2968
 
2969
    mov esi,ted_scr_w
2970
	mov ecx,dword[esi+sb_offs_position]
2971
    sub ted_seln_y0,ecx
2972
    sub ted_seln_y1,ecx
2973
 
2974
    mov ecx,ted_cur_y
2975
    cmp ecx,ted_seln_y0
2976
    jl .no_cur_sel
2977
    cmp ecx,ted_seln_y1
2978
    jg .no_cur_sel
2979
    mov edx,ted_color_select ;меняем цвет фона на цвет выделения
2980
 
2981
    mov esi,ted_scr_h
2982
	cmp ecx,ted_seln_y0
2983
    jne @f
2984
      mov ecx,ted_cur_x
2985
      add ecx,dword[esi+sb_offs_position]
2986
      cmp ecx,ted_seln_x0
2987
      jge @f
2988
      mov edx,ted_color_wnd_work
2989
    @@:
2990
 
2991
    mov ecx,ted_cur_y
2992
    cmp ecx,ted_seln_y1
2993
    jne .no_cur_sel
2994
      mov ecx,ted_cur_x
2995
      add ecx,dword[esi+sb_offs_position]
2996
      cmp ecx,ted_seln_x1
2997
      jl .no_cur_sel
2998
      mov edx,ted_color_wnd_work
2999
 
3000
    .no_cur_sel:
3001
  pop ecx
3002
  int 0x40 ;рисование прямоугольника
3003
 
3004
  call ted_get_pos_by_cursor ;берем позицию символа
3005
  cmp ted_gp_opt,2
3006
  jne @f
3007
    mov eax,4
3008
    mov esi,1
3009
    ror ecx,16
3010
    mov bx,cx
3011
    add ebx,0x10001
3012
    call ted_get_symb_color
3013
    call ted_convert_invis_symb
3014
    int 0x40 ;рисование символа
3015
  @@:
3016
 
3017
  popad
3018
  ret
3019
endp
3020
 
3021
;input:
3022
; edx -> pointer to text
3023
; edi -> указатель на структуру tedit
3024
;output:
3025
; ecx = color
3026
; if ted_mode_color=0 then ecx=ted_color_wnd_text
3027
align 4
3028
ted_get_symb_color:
3029
  mov ecx,ted_color_wnd_text ;задаем цвет текста по умолчанию
3030
 
3031
  push eax edx
3032
  cmp ted_mode_color,0
3033
  je .exit
3034
    jmp .on_first
3035
    @@:
3036
      call ted_iterat_perv
3037
      cmp edx,ted_tex_1
3038
      jle .exit
3039
    .on_first:
3040
      xor eax,eax
3041
      mov al,byte[edx+1]
3042
      cmp al,0 ;если al=0 то цвет не меняется
3043
    je @b
3044
 
3045
    cmp eax,ted_colors_text_count
3046
    jge .exit
3047
 
3048
    shl ax,2 ;умножаем индекс цвета на 4 байта
3049
    mov ecx,ted_text_colors ;прибавляем смещение 1-го цвета
3050
    add ecx,eax
3051
    mov ecx,dword[ecx] ;устанавливаем текущий цвет текста по смещению
3052
  .exit:
3053
  pop edx eax
3054
  ret
3055
 
3056
;input:
3057
; edx = pointer to text
3058
; edi = pointer to tedit struct
3059
;description:
3060
; Функция преобразует невидимые символы в печатаемые на экране
3061
align 4
3062
ted_convert_invis_symb:
1458 IgorA 3063
	cmp ted_mode_invis,1
3064
	jne .end_f
3065
		cmp byte[edx],9
3066
		jne @f
3067
			lea edx,[ted_symbol_tab]
3068
		@@:
3069
		cmp byte[edx],13
3070
		jne @f
3071
			mov edx,edi
3072
			add edx,ted_offs_symbol_new_line
3073
		@@:
3074
	.end_f:
3075
	ret
1457 IgorA 3076
 
3077
;input:
3078
; edi = pointer to tedit struct
3079
align 4
3080
ted_scroll_set_redraw:
3081
	push eax
3082
	mov eax,ted_scr_w
3083
	mov dword[eax+sb_offs_redraw],1
3084
	mov eax,ted_scr_h
3085
	mov dword[eax+sb_offs_redraw],1
3086
	pop eax
3087
	ret
3088
 
3089
align 4
3090
proc ted_draw, edit:dword
1458 IgorA 3091
	locals
3092
		line_num dd ?
3093
	endl
3094
	pushad
3095
	mov edi,dword[edit]
1457 IgorA 3096
 
1458 IgorA 3097
	mov eax,4 ;draw text
3098
	mov ecx,ted_text_colors
3099
	mov ecx,dword[ecx]
1457 IgorA 3100
 
1458 IgorA 3101
	mov ebx,ted_wnd_l
3102
	add ebx,ted_rec_l
3103
	shl ebx,16
3104
	add ebx,ted_wnd_t
3105
	add ebx,ted_rec_t
3106
	add ebx,0x10001 ;добавляем отступы для выравнивания буквы по центру
1457 IgorA 3107
 
1458 IgorA 3108
	call ted_sel_normalize ;need before draw select
3109
	mov esi,ted_scr_w
3110
	mov esi,dword[esi+sb_offs_position]
3111
	mov dword[line_num],esi
1457 IgorA 3112
 
1458 IgorA 3113
	stdcall ted_clear_line_before_draw, edi,ebx,1,esi
3114
	call ted_get_first_visible_pos
3115
	cmp edx,0
3116
	je .no_draw_text
3117
	mov esi,1 ;длинна выводимого текста по 1-му символу
3118
	@@:
3119
		call ted_iterat_next
3120
		cmp edx,ted_tex_1
3121
		jle .no_draw_text
1457 IgorA 3122
 
1458 IgorA 3123
		; *** цветовая разметка
3124
		cmp ted_mode_color,0
3125
		je .no_col_change
3126
		cmp byte[edx+1],0
3127
		je .no_col_change
3128
			call ted_get_symb_color
3129
		.no_col_change:
1457 IgorA 3130
 
1458 IgorA 3131
		cmp byte [edx],13
3132
		jne .no_13
3133
			cmp ted_mode_invis,1
3134
			jne .no_invis
3135
				push edx
3136
				mov edx,edi
3137
				add edx,ted_offs_symbol_new_line
3138
				int 0x40
3139
				pop edx
3140
			.no_invis:
3141
			add ebx,ted_rec_h
3142
			;optimized output \/
3143
			mov eax,ted_wnd_h
3144
			add eax,ted_wnd_t
3145
			cmp bx,ax
3146
			jg .no_draw_text
3147
			mov eax,4
3148
			;optimized output /\
3149
			and ebx,0xffff
3150
			ror ebx,16
3151
			add ebx,ted_wnd_l
3152
			add ebx,ted_rec_l
3153
			inc ebx
3154
			ror ebx,16
3155
			inc dword[line_num] ;increment line number
3156
			stdcall ted_clear_line_before_draw,edi,ebx,1,dword[line_num]
3157
			call ted_opt_draw_line_left
3158
			jmp @b
3159
		.no_13:
1457 IgorA 3160
 
1458 IgorA 3161
		int 0x40
3162
		ror ebx,16
3163
		add ebx,ted_rec_w
3164
		mov esi,ted_wnd_l
3165
		add esi,ted_wnd_w
3166
		cmp bx,si
3167
		jl .no_opt
3168
			call ted_opt_draw_line_right
3169
		.no_opt:
3170
		mov si,1
3171
		ror ebx,16
3172
		jmp @b
3173
	.no_draw_text:
1457 IgorA 3174
 
1458 IgorA 3175
	stdcall ted_clear_line_before_draw,edi,ebx,0,dword[line_num]
3176
	call ted_draw_line_numbers
3177
	call ted_draw_main_cursor
1457 IgorA 3178
 
3179
;---------------------------------------------
3180
; set all_redraw flag for draw all ScrollBar
3181
; In some cases it is necessity to draw only the area
3182
; of moving of a "runner", for acceleration of output -
3183
; in this case the flag needs to be reset to 0 (zero).
3184
	mov eax,ted_scr_h
3185
	mov esi,ted_scr_w
3186
	mov dword[eax+sb_offs_all_redraw],1
3187
	mov dword[esi+sb_offs_all_redraw],1
3188
 
3189
; рисование полос прокрутки
3190
	stdcall scroll_bar_horizontal.draw,eax ;[scrollbar_hor_draw]
3191
	stdcall scroll_bar_vertical.draw,esi ;[scrollbar_ver_draw]
3192
; reset all_redraw flag
3193
	mov dword[eax+sb_offs_all_redraw],0
3194
	mov dword[esi+sb_offs_all_redraw],0
3195
;---------------------------------------------
3196
 
3197
  ;left-bottom square
3198
  mov ebx,ted_wnd_l
3199
  shl ebx,16
3200
  add ebx,ted_rec_l
3201
  mov ecx,ted_wnd_t
3202
  add ecx,ted_wnd_h
3203
  shl ecx,16
3204
  mov cx,word[eax+sb_offs_size_y]
3205
  inc cx
3206
  mov edx,ted_color_wnd_capt ;[sc.work]
3207
  mov eax,13
3208
  int 0x40
3209
 
3210
	;right-bottom square
3211
	mov ebx,ted_wnd_l
3212
	add ebx,ted_wnd_w
3213
	shl ebx,16
3214
	mov bx,word[esi+sb_offs_size_x]
3215
	inc bx
3216
	int 0x40
3217
 
3218
	cmp ted_fun_draw_panel_find,0
3219
	je @f
3220
		call ted_fun_draw_panel_find
3221
	@@:
3222
	cmp ted_fun_draw_panel_syntax,0
3223
	je @f
3224
		call ted_fun_draw_panel_syntax
3225
	@@:
3226
	popad
3227
	ret
3228
endp
3229
 
3230
;input:
3231
; edi = pointer to tedit struct
3232
align 4
3233
proc ted_draw_main_cursor
3234
  pushad
3235
 
3236
  mov eax,13 ;draw cursor
3237
  mov ecx,ted_wnd_t ;calc rect -> y0,y1
3238
  add ecx,ted_rec_t
3239
  mov edx,ted_cur_y
3240
  imul edx,ted_rec_h
3241
  add ecx,edx
3242
 
3243
  cmp ted_cur_ins,1 ;проверка режима работы курсора (обычный или вставка)
3244
  jne @f
3245
    mov edx,ted_rec_h
3246
    inc edx   ;1->1, 3->2, 5->3, ...
3247
    shr edx,1 ;edx = высота строки деленная на 2 (когда курсор не полный)
3248
    add ecx,edx
3249
  @@:
3250
  shl ecx,16
3251
  add ecx,ted_rec_h
3252
  cmp ted_cur_ins,1
3253
  jne @f
3254
    shr cx,1 ;делим высоту курсора на 2
3255
  @@:
3256
 
3257
  mov ebx,ted_wnd_l ;calc rect -> x0,x1
3258
  add ebx,ted_rec_l
3259
  mov edx,ted_cur_x
3260
  imul edx,ted_rec_w
3261
  add ebx,edx
3262
  shl ebx,16
3263
  add ebx,ted_rec_w
3264
 
3265
  mov edx,ted_color_cursor
3266
  int 0x40 ;вывод курсора
3267
 
3268
  call ted_get_pos_by_cursor
3269
  cmp ted_gp_opt,2
3270
  jne @f
3271
    mov eax,4 ;draw text
3272
    mov esi,1
3273
    ror ecx,16
3274
    mov bx,cx
3275
    add ebx,0x10001
3276
    cmp ted_cur_ins,1
3277
    jne .no_up_tetx
3278
      mov ecx,ted_rec_h
3279
      inc cx ; 1->1, 3->2, 5->3, ...
3280
      shr cx,1
3281
      sub bx,cx
3282
    .no_up_tetx:
3283
    mov ecx,ted_color_cur_text
3284
    call ted_convert_invis_symb
3285
    int 0x40
3286
  @@:
3287
 
3288
  mov eax,4
3289
  mov ebx,ted_wnd_l
3290
  add ebx,ted_rec_l
3291
  shl ebx,16
3292
  add ebx,ted_wnd_t
3293
  add ebx,3
3294
  mov ecx,ted_color_wnd_bord
3295
  or  ecx,0x80000000
3296
  lea edx,[txtRow]
3297
  int 0x40 ;вывод подписи 'Строка'
3298
 
3299
  add ebx,0x500000
3300
  lea edx,[txtCol]
3301
  int 0x40 ;вывод подписи 'Знак'
3302
 
3303
  cmp ted_tim_undo,0
3304
  je @f
3305
    add ebx,0x500000
3306
    lea edx,[txtOtm]
3307
    int 0x40
3308
    sub ebx,0x500000
3309
  @@:
3310
 
3311
  call ted_draw_buffer
3312
  call ted_draw_help_f1
3313
 
3314
  mov eax,47 ;draw cursor coords
3315
  mov esi,ted_color_wnd_bord
3316
  or  esi,0x40000000
3317
 
3318
  mov edx,ebx
3319
  ror edx,16
3320
  sub edx,35
3321
  ror edx,16
3322
  ;add edx,3
3323
  mov ebx,0x40000 ;Row=...
3324
  mov ecx,ted_scr_w
3325
  mov ecx,dword[ecx+sb_offs_position]
3326
  add ecx,ted_cur_y
3327
  inc ecx
3328
 
3329
push edi
3330
  mov edi,ted_color_wnd_work
3331
  int 0x40 ;вывод числа текущей строки
3332
pop edi
3333
 
3334
  ;mov ebx,0x40000 ;Col=...
3335
  mov ecx,ted_scr_h
3336
  mov ecx,dword[ecx+sb_offs_position]
3337
  add ecx,ted_cur_x
3338
  inc ecx
3339
  add edx,0x500000
3340
push edi
3341
  mov edi,ted_color_wnd_work
3342
  int 0x40 ;вывод числа знаков
3343
pop edi
3344
 
3345
  cmp ted_tim_undo,0
3346
  je @f
3347
    mov ecx,ted_tim_undo
3348
    add edx,0x500000
1458 IgorA 3349
	mov edi,ted_color_wnd_work ;портим регистр edi, но в конце функции это уже не важно
3350
    int 0x40 ;вывод числа отмененных действий
1457 IgorA 3351
  @@:
3352
 
3353
  popad
3354
  ret
3355
endp
3356
 
3357
;input:
3358
; edi = pointer to tedit struct
3359
proc ted_draw_buffer
3360
	pushad
3361
 
3362
	mov eax,ted_buffer
4228 IgorA 3363
	cmp dword[eax],1 ;смотрим размер буфера
3364
	jl @f
1458 IgorA 3365
		mov ebx,ted_rec_l
1457 IgorA 3366
		add bx,300
1458 IgorA 3367
		cmp ebx,ted_wnd_w ;сравниваем координату для вывод текста
3368
		jge @f ;подпись не влазит в окно
3369
 
3370
		add ebx,ted_wnd_l
1457 IgorA 3371
		shl ebx,16
3372
		add ebx,ted_wnd_t
3373
		add ebx,3
3374
		mov ecx,ted_color_wnd_bord
3375
		or ecx,0x40000000
3376
 
3377
		mov edx,ted_buffer
4228 IgorA 3378
		add edx,12
1457 IgorA 3379
		mov esi,edx
3380
		mov edi,ted_color_wnd_work ;edi - destroy not pointer to tedit
3381
		call tl_strlen
3382
		;cmp eax,0 ;буфер пуст
3383
		;je @f
3384
		cmp eax,20
3385
		jle .crop_buf
3386
			mov eax,20 ;обрезка подписи до 20 символов
3387
		.crop_buf:
3388
		mov esi,eax
3389
		mov eax,4
3390
		int 0x40 ;вывод содержимого буфера
3391
 
3392
		sub ebx,50 shl 16
3393
		lea edx,[txtBuf]
3394
		mov esi,edx
3395
		call tl_strlen
3396
		mov esi,eax
3397
		mov eax,4
3398
		xor ecx,0x40000000 ;убираем цвет фона
3399
		int 0x40 ;вывод подписи для буфера
3400
	@@:
3401
	popad
3402
	ret
3403
endp
3404
 
3405
;input:
3406
; edi = pointer to tedit struct
3407
align 4
3408
proc ted_draw_help_f1
1458 IgorA 3409
	pushad
3410
	cmp ted_rec_t,13 ;минимальная высота для рисования справки
3411
	jle @f
3412
		mov eax,13 ;clear place before draw help
3413
		mov ebx,ted_wnd_l
3414
		add ebx,ted_rec_l
3415
		shl ebx,16
3416
		add ebx,ted_wnd_w
3417
		sub ebx,ted_rec_l
3418
		mov ecx,ted_wnd_t
3419
		add ecx,13
3420
		shl ecx,16
3421
		add ecx,ted_rec_h
3422
		mov edx,ted_color_wnd_capt
3423
		int 0x40
1457 IgorA 3424
 
1458 IgorA 3425
	cmp ted_help_id,-1
3426
	je @f
3427
		mov eax,ted_help_id
3428
		ColToIndexOffset eax,edx
1457 IgorA 3429
 
1458 IgorA 3430
		;SetCoordinates
3431
		mov ebx,ted_wnd_l
3432
		add ebx,ted_rec_l
3433
		shl ebx,16
3434
		add ebx,ted_wnd_t
3435
		add ebx,13 ;=3+10
1457 IgorA 3436
 
1458 IgorA 3437
		;SetTextColor
3438
		xor eax,eax
2102 IgorA 3439
		mov al,byte[edx+MAX_COLOR_WORD_LEN+7]
1458 IgorA 3440
		shl ax,2
3441
		mov ecx,ted_text_colors
3442
		add ecx,eax
3443
		mov ecx,dword[ecx]
3444
		or	ecx,0xc0000000 ;SetTextStyles
3445
		mov esi,edi
3446
			mov edi,ted_color_wnd_work
3447
			mov eax,4
3448
			int 0x40
3449
		mov edi,esi
1457 IgorA 3450
 
1458 IgorA 3451
		;*** draw help string ***
3452
		mov ecx,ted_color_wnd_bord
3453
		or ecx,0x80000000
3454
		mov edx,dword[edx+MAX_COLOR_WORD_LEN]
3455
		cmp edx,0
3456
		je @f
3457
			add edx,ted_help_text_f1
3458
			add ebx,0x500000
3459
			int 0x40
3460
	@@:
3461
	popad
3462
	ret
1457 IgorA 3463
endp
3464
 
3465
;input:
3466
; edi = pointer to tedit struct
3467
align 4
3468
proc ted_draw_line_numbers
3469
  pushad
3470
 
3471
  ;top panel with caption
3472
  mov ebx,ted_wnd_l
3473
;  add ebx,ted_rec_l
3474
  shl ebx,16
3475
  add ebx,ted_wnd_w
3476
;  sub ebx,ted_rec_l
3477
  mov edx,ted_color_wnd_work
3478
  mov ecx,ted_wnd_t
3479
  shl ecx,16
3480
  add ecx,ted_rec_t
3481
  mov eax,13
3482
  mov edx,ted_color_wnd_capt
3483
  int 0x40
3484
 
3485
  ;line numbers
3486
  mov ebx,0x40000 ;format
3487
  mov ecx,ted_scr_w
3488
  mov ecx,dword[ecx+sb_offs_position]
3489
  inc ecx
3490
  mov edx,3
3491
  add edx,ted_wnd_l
3492
  rol edx,16
3493
  add edx,ted_wnd_t
3494
  add edx,ted_rec_t
3495
  @@:
3496
 
3497
push ebx ecx edx
3498
  ;left panel with numbers
3499
  mov ebx,ted_wnd_l
3500
  shl ebx,16
3501
  add ebx,ted_rec_l
3502
  mov ecx,ted_rec_h
3503
  rol ecx,16
3504
  mov cx,dx
3505
  rol ecx,16
3506
  mov eax,13
3507
  mov edx,ted_color_wnd_capt
3508
  int 0x40 ;рисуем прямоугольник под номером строки
3509
pop edx ecx ebx
3510
 
3511
    mov eax,47
3512
    mov esi,ted_color_wnd_bord
3513
    int 0x40 ;рисуем номер строки
3514
    inc ecx
3515
    add edx,ted_rec_h
3516
    sub edx,ted_wnd_t
3517
	mov esi,edx
3518
	and esi,0xffff
3519
    cmp esi,ted_wnd_h
3520
    jge @f
3521
    add edx,ted_wnd_t
3522
    jmp @b
3523
  @@:
3524
 
3525
  popad
3526
  ret
3527
endp
3528
 
3529
;output:
3530
; ah = symbol
3531
align 4
3532
proc KeyConvertToASCII, table:dword
1464 IgorA 3533
	push ebx
3534
	mov ebx,dword[table] ;convert scan to ascii
3535
	ror ax,8
3536
	xor ah,ah
3537
	add bx,ax ;? ebx,eax
3538
	mov ah,byte[ebx]
3539
	pop ebx
3540
	ret
1457 IgorA 3541
endp
3542
 
3543
align 4
3544
proc ted_draw_cur_line, edit:dword
3545
  pushad
3546
    mov edi,dword[edit]
3547
 
3548
    mov ebx,ted_wnd_l
3549
    add ebx,ted_rec_l
3550
    shl ebx,16
3551
    mov eax,ted_cur_y
3552
    imul eax,ted_rec_h
3553
	mov bx,ax
3554
    add ebx,ted_wnd_t
3555
    add ebx,ted_rec_t ;ebx - координаты для прямоугольника очистки линии
3556
	add ebx,0x10001   ;добавляем отступы для выравнивания буквы по центру
3557
 
3558
    call ted_sel_normalize ;need before draw select
3559
	mov ecx,ted_cur_y
3560
	mov eax,ted_scr_w
3561
    add ecx,dword[eax+sb_offs_position]
3562
    stdcall ted_clear_line_before_draw,edi,ebx,1,ecx
3563
 
3564
    mov eax,ted_scr_h
3565
	mov esi,dword[eax+sb_offs_position]
3566
    call ted_get_pos_by_coords
3567
 
3568
  cmp ted_gp_opt,2
3569
  jne .no_draw_text
3570
;  mov eax,4 ;draw text
3571
  call ted_get_symb_color
3572
  mov esi,1 ;draw 1 symbol
3573
  @@:
3574
    ;call ted_iterat_next
3575
    cmp edx,ted_tex_1
3576
    jle .no_draw_text
3577
 
3578
    ; *** цветовая разметка
3579
    cmp ted_mode_color,0
3580
    je .no_col_change
3581
    cmp byte[edx+1],0
3582
    je .no_col_change
3583
      call ted_get_symb_color
3584
    .no_col_change:
3585
 
3586
    mov eax,4 ;draw text
3587
    cmp byte [edx],13
3588
    jne .no_13
3589
      cmp ted_mode_invis,1
3590
      jne .no_draw_text
3591
 push edx
3592
 mov edx,edi
3593
 add edx,ted_offs_symbol_new_line
3594
 int 0x40
3595
 pop edx
3596
      jmp .no_draw_text
3597
    .no_13:
3598
 
3599
    int 0x40
3600
    ror ebx,16
3601
    add ebx,ted_rec_w
3602
    mov eax,ted_wnd_w
3603
    add eax,ted_wnd_l ;ax = отступ по оси x
3604
    cmp bx,ax
3605
    jge .no_draw_text ;Opt
3606
    ror ebx,16
3607
    call ted_iterat_next
3608
    jmp @b
3609
  .no_draw_text:
3610
 
3611
  call ted_draw_main_cursor
3612
  popad
3613
  ret
3614
endp
3615
 
3616
;input:
3617
; eax - text need find
3618
; bl - first symbol to find
3619
; edx - first symbol pointer
3620
; edi - pointer to tedit struct
3621
;output:
3622
; bh - rezult
3623
; edx - last text position (if find sucess)
3624
; esi - first symbol pointer
3625
;description:
3626
; Функция проверяет совпадает ли текст в буфере eax
3627
; с текстом редактора по указателю edx.
3628
; Стандартные функции (напр. strcmp) тут не подойдут, потому что
3629
; в памяти редактора текст содержится не в виде ascii строк.
3630
align 4
3631
ted_get_find_rezult:
3632
  push eax
3633
    mov bh,1
3634
    mov esi,edx ;copy edx
3635
    @@:
3636
      cmp byte[edx],bl
3637
      jne .no_text
3638
 
3639
      inc eax ;*** get next symbol (in find text) ***
3640
      mov bl,byte[eax]
3641
      cmp bl,0
3642
      je @f ;end of find text
3643
 
3644
      call ted_iterat_next ;*** get next symbol (in editor text) ***
3645
      cmp edx,ted_tex_1
3646
      jle @f ;end of editor text
3647
 
3648
      jmp @b
3649
      .no_text:
3650
	xor bh,bh
3651
	mov edx,esi ;restore edx
3652
    @@:
3653
  pop eax
3654
  mov bl,byte[eax] ;restore bl
3655
  ret
3656
 
3657
;input:
3658
;  clear_o - если =1 очистить одну строку, =0 очистить все строки окна до низу
3659
align 4
3660
proc ted_clear_line_before_draw, edit:dword, coords:dword, clear_o:dword, numb_lin:dword
3661
	pushad
3662
	mov edi,dword[edit]
3663
	mov ebx,dword[coords]	;ebx = x*2^16+y coords to left up point clear line
3664
	mov esi,dword[numb_lin] ;esi - number text line
3665
 
3666
	sub ebx,0x10001 ;отнимаем отступы для выравнивания буквы по центру
3667
	cmp dword[clear_o],0
3668
	jne @f
3669
		add ebx,ted_rec_h
3670
		inc esi
3671
		ror ebx,16
3672
		xor bx,bx
3673
		add ebx,ted_wnd_l
3674
		add ebx,ted_rec_l ;bx = ted_wnd_l+ted_rec_l
3675
		ror ebx,16
3676
	@@:
3677
 
3678
	mov eax,ted_wnd_h
3679
	add eax,ted_wnd_t
3680
	cmp ax,bx
3681
	jl .no_clear
3682
	sub ax,bx
3683
 
3684
	mov cx,bx
3685
	shl ecx,16
3686
 
3687
	xor bx,bx
3688
	add ebx,ted_wnd_w
3689
	sub ebx,ted_rec_l
3690
	xor cx,cx
3691
	add ecx,ted_rec_h
3692
	mov edx,ted_color_wnd_work
3693
 
3694
	cmp dword[clear_o],0
3695
	je .pusto
3696
	cmp ax,cx
3697
	jge @f
3698
	.pusto:
3699
		mov cx,ax
3700
	@@:
3701
 
3702
	call ted_is_select
3703
	cmp al,0
3704
	je @f
3705
	cmp ted_seln_y0,esi
3706
	jg @f
3707
	cmp ted_seln_y1,esi
3708
	jl @f
3709
		mov edx,ted_color_select ;draw selected line
3710
	@@:
3711
 
3712
	mov eax,13 ;rect
3713
	int 0x40
3714
 
3715
	call ted_is_select
3716
	cmp al,0
3717
	je .no_clear
3718
 
3719
	mov al,13 ;rect
3720
	xor cx,cx
3721
	add ecx,ted_rec_h
3722
	cmp ted_seln_y0,esi
3723
	jne @f
3724
		push bx esi
3725
		mov edx,ted_seln_x0 ; верхняя полоса (затирает слева)
3726
		mov esi,ted_scr_h
3727
		cmp edx,dword[esi+sb_offs_position]
3728
		jle .in_wnd
3729
			sub edx,dword[esi+sb_offs_position]
3730
			imul edx,ted_rec_w
3731
			mov bx,dx
3732
			jmp .no_wnd
3733
		.in_wnd:
3734
		mov bx,0
3735
		.no_wnd:
3736
		mov edx,ted_color_wnd_work
3737
		int 0x40
3738
		pop esi bx
3739
	@@:
3740
	cmp ted_seln_y1,esi
3741
	jne @f
3742
		push esi
3743
		mov edx,ted_seln_x1 ; нижняя полоса (затирает справа)
3744
		mov esi,ted_scr_h
3745
		cmp edx,dword[esi+sb_offs_position]
3746
		jle .in_wnd2
3747
			sub edx,dword[esi+sb_offs_position]
3748
			imul edx,ted_rec_w
3749
			sub bx,dx
3750
			shl edx,16
3751
			add ebx,edx
3752
		.in_wnd2:
3753
 
3754
		mov edx,ted_color_wnd_work
3755
		int 0x40
3756
		pop esi
3757
	@@:
3758
 
3759
	.no_clear:
3760
	popad
3761
	ret
3762
endp
3763
 
3764
;input:
3765
; edi = pointer to tedit struct
3766
;output:
3767
; ecx = новый цвет символа
3768
; edx = pointer to symbol
3769
; edx = 0 if text not in screen
3770
align 4
3771
ted_get_first_visible_pos:
3772
	push eax ecx
3773
	mov eax,ted_scr_w
3774
	mov edx,ted_tex
3775
	xor ecx,ecx
3776
	@@:
3777
		cmp ecx,dword[eax+sb_offs_position]
3778
		je @f
3779
		call ted_iterat_next
3780
		cmp edx,ted_tex_1
3781
		jle @f
3782
		cmp byte [edx],13
3783
		jne @b
3784
		inc ecx
3785
		jmp @b
3786
	@@:
3787
 
3788
	cmp ecx,dword[eax+sb_offs_position]
3789
	je @f
3790
		xor edx,edx
3791
	@@:
3792
	cmp ecx,dword[eax+sb_offs_max_area]
3793
	jle @f
3794
		mov dword[eax+sb_offs_max_area],ecx
3795
	@@:
3796
	pop ecx eax
3797
	call ted_opt_draw_line_left
3798
	ret
3799
 
3800
;input:
3801
; edx = pointer to symbol
3802
; edi = pointer to tedit struct
3803
;output:
3804
; ecx = цвет символа
3805
; edx = указатель на первый левый символ
3806
;description:
3807
; функция нужна для оптимизации вывода текста
3808
align 4
3809
proc ted_opt_draw_line_left
3810
  push ebx
3811
 
3812
  mov ebx,ted_scr_h
3813
  mov ebx,dword[ebx+sb_offs_position]
3814
  cmp ebx,0
3815
  je .ret_f
3816
  push eax
3817
  mov eax,edx
3818
 
3819
  cmp edx,ted_tex
3820
  jne @f
3821
    call ted_iterat_next
3822
    jmp .beg_cycle
3823
  @@:
3824
 
3825
  cmp ebx,0
3826
  je @f
3827
 
3828
  cmp byte[edx],13
3829
  jne @f
3830
    call ted_iterat_next
3831
    .beg_cycle:
3832
  @@:
3833
    cmp edx,ted_tex_1
3834
    jle @f
3835
    cmp byte[edx],13
3836
    je @f
3837
    cmp ebx,0
3838
    je @f
3839
;--------------------------------------
3840
xor eax,eax ;eax будет меняться
3841
mov al,byte[edx+1]
3842
cmp al,0
3843
je .no_color
3844
cmp eax,ted_colors_text_count
3845
jge .no_color
3846
  xor ecx,ecx
3847
  mov cl,byte[edx+1]
3848
  shl cx,2
3849
  add ecx,ted_text_colors
3850
  mov ecx,dword[ecx]
3851
.no_color:
3852
;--------------------------------------
3853
    mov eax,edx
3854
    call ted_iterat_next
3855
    dec ebx
3856
    jmp @b
3857
  @@:
3858
    mov edx,eax
3859
  pop eax
3860
  .ret_f:
3861
  call ted_get_symb_color
3862
  pop ebx
3863
  ret
3864
endp
3865
 
3866
;input:
3867
; edx = pointer to symbol
3868
; edi = pointer to tedit struct
3869
;output:
3870
; ecx = symbol color
3871
; edx = pointer to 13 symbol
3872
;description:
3873
; функция нужна для оптимизации вывода текста
3874
align 4
3875
proc ted_opt_draw_line_right
3876
	push eax
3877
	mov eax,edx
3878
	@@:
3879
		cmp edx,ted_tex_1
3880
		jle @f
3881
		cmp byte[edx],13
3882
		je @f
3883
		mov eax,edx
3884
		call ted_iterat_next
3885
		jmp @b
3886
	@@:
3887
	mov edx,eax ;perv sumbol
3888
	call ted_get_symb_color
3889
 
3890
	pop eax
3891
	ret
3892
endp
3893
 
3894
align 4
3895
proc ted_mouse, edit:dword
3896
	pushad
3897
	mov edi,dword[edit]
3898
 
3899
	;обрабатываем скроллинги
3900
	mov edx,ted_scr_h
3901
	mov ecx,ted_scr_w
3902
 
3903
	cmp word[edx+sb_offs_delta2],0
3904
	jne .horizontal
3905
 
3906
	mov eax,dword[ecx+sb_offs_max_area]
3907
	cmp eax,dword[ecx+sb_offs_cur_area]
3908
	jbe .horizontal
3909
	; mouse event for Vertical ScrollBar
3910
	stdcall scroll_bar_vertical.mouse,ecx ;[scrollbar_ver_mouse]
3911
	cmp dword[ecx+sb_offs_redraw],0
3912
	je @f
3913
		mov dword[ecx+sb_offs_redraw],0
3914
		stdcall ted_draw,edi
3915
		jmp .no_in_wnd
3916
	@@:
3917
	cmp word[ecx+sb_offs_delta2],0
3918
	jne .no_in_wnd
3919
	.horizontal:
3920
	mov eax,dword[edx+sb_offs_max_area]
3921
	cmp eax,dword[edx+sb_offs_cur_area]
3922
	jbe .other
3923
	; mouse event for Horizontal ScrollBar
3924
	stdcall scroll_bar_horizontal.mouse,edx ;[scrollbar_hor_mouse]
3925
	cmp dword[edx+sb_offs_redraw],0
3926
	je .other
3927
		mov dword[edx+sb_offs_redraw],0
3928
		stdcall ted_draw,edi
3929
		jmp .no_in_wnd
3930
	.other:
3931
	cmp word[ecx+sb_offs_delta2],0
3932
	jne .no_in_wnd
3933
	cmp word[edx+sb_offs_delta2],0
3934
	jne .no_in_wnd
3935
 
3936
	;обрабатываем окно редактора
3937
	mcall 37,2 ;get mouse buttons
3938
	cmp al,1
3939
	jne @f
3940
		mcall 37,1 ;get mouse coords
3941
		mov ebx,ted_wnd_t
3942
		add ebx,ted_rec_t
3943
		cmp ax,bx
3944
		jl @f ;y_mouse
3945
 
3946
		sub ebx,ted_rec_t
3947
		add ebx,ted_wnd_h
3948
		cmp bx,ax
3949
		jl @f ;y_mouse>y_wnd
3950
 
3951
		mov ebx,ted_wnd_l
3952
		add ebx,ted_rec_l
3953
		mov ecx,eax
3954
		shr ecx,16
3955
		cmp cx,bx
3956
		jl @f ;x_mouse
3957
 
3958
		sub ebx,ted_rec_l
3959
		add ebx,ted_wnd_w
3960
		cmp bx,cx
3961
		jl @f ;x_mouse>x_wnd
3962
 
3963
		call ted_draw_cursor_sumb
3964
		call ted_wnd_main_click
3965
		jmp .no_in_wnd
3966
	@@:
1458 IgorA 3967
	mov edx,ted_el_focus
3968
	cmp dword[edx],edi
3969
	jne @f
3970
		call ted_wnd_main_mouse_scroll ;смотрим на прокрутку колеса мыши
3971
	@@:
1457 IgorA 3972
	cmp ted_drag_m,0
3973
	je .no_in_wnd
3974
		mov ted_drag_m,0
3975
		stdcall ted_draw,edi
3976
		cmp ted_fun_draw_panel_buttons,0
3977
		je .no_in_wnd
3978
			call ted_fun_draw_panel_buttons
3979
	.no_in_wnd:
3980
	popad
3981
	ret
3982
endp
3983
 
3984
;input:
3985
; eax -> (x,y)
3986
; edi -> указатель на структуру tedit
3987
;description:
3988
; функция вызывется при нажатии кнопкой мыши и попадении курсором в окно редактора
3989
align 4
3990
ted_wnd_main_click:
1458 IgorA 3991
	push ebx ecx edx
3992
	mov ebx,ted_el_focus
3993
	mov dword[ebx],edi ;ставим фокус
1457 IgorA 3994
 
3995
  push eax
3996
    shr eax,16
3997
    and eax,0xffff
3998
    sub eax,ted_wnd_l
3999
    sub eax,ted_rec_l
4000
 
4001
    xor edx,edx
4002
    mov ecx,ted_rec_w
4003
    div cx
4004
    ;inc eax
4005
	mov ebx,ted_scr_h
4006
    cmp eax,dword[ebx+sb_offs_cur_area]
4007
    jle @f
4008
      mov eax,dword[ebx+sb_offs_cur_area]
4009
    @@:
4010
    ;dec eax
4011
    mov ted_cur_x,eax
4012
  pop eax
4013
 
4014
  push eax
4015
    and eax,0xffff
4016
    sub eax,ted_wnd_t
4017
    sub eax,ted_rec_t
4018
 
4019
    xor edx,edx
4020
    mov ecx,ted_rec_h
4021
    div cx
4022
    inc eax
4023
	mov ebx,ted_scr_w
4024
    cmp eax,dword[ebx+sb_offs_cur_area]
4025
    jle @f
4026
      mov eax,dword[ebx+sb_offs_cur_area]
4027
    @@:
4028
    dec eax
4029
    mov ted_cur_y,eax
4030
  pop eax
4031
 
1458 IgorA 4032
	cmp ted_drag_m,0
4033
	je @f
4034
		call ted_sel_move
4035
		jmp .sel_move
4036
	@@:
4037
		mov ted_drag_m,1
4038
		call ted_sel_start
4039
	.sel_move:
4040
	pop edx ecx ebx
4041
	ret
1457 IgorA 4042
 
4043
;input:
4044
; edi = pointer to tedit struct
4045
align 4
4046
ted_wnd_main_mouse_scroll:
4047
	push eax ebx ecx
1458 IgorA 4048
	mcall 37,7 ;прокрутка колеса мыши
1457 IgorA 4049
	cmp ax,0
4050
	je .no_scroll
4051
		mov ecx,ted_scr_w
4052
		mov ebx,dword[ecx+sb_offs_position] ;copy old scroll position
4053
		and eax,0xffff
4054
		btr ax,15
4055
		jae @f
4056
			or eax,0xffff8000
1458 IgorA 4057
		@@:
4058
		add dword[ecx+sb_offs_position],eax
1457 IgorA 4059
 
1458 IgorA 4060
		mov eax,[ecx+sb_offs_position]
4061
		cmp eax,[ecx+sb_offs_max_area]
4062
		jb @f
4063
			mov dword[ecx+sb_offs_position],ebx ;if scroll position out of range
4064
			jmp .no_scroll
4065
		@@:
4066
		stdcall ted_draw,edi
1457 IgorA 4067
	.no_scroll:
4068
	pop ecx ebx eax
4069
	ret
4070
 
4071
align 4
4308 IgorA 4072
proc ted_save_file, edit:dword, file:dword, f_name:dword
1457 IgorA 4073
  pushad
4074
  mov edi,dword[edit]
4075
 
4076
  stdcall ted_can_save,edi
4077
  cmp al,0
2102 IgorA 4078
;  je .no_save
1457 IgorA 4079
 
4080
  mov ecx,ted_max_chars
1489 IgorA 4081
  invoke mem.alloc,ecx
1457 IgorA 4082
  push eax ;запоминаем указатель на выделенную память
4083
 
4084
  mov edx,ted_tex
4085
  xor ecx,ecx
4086
  @@:
4087
    call ted_iterat_next
4088
    cmp edx,ted_tex_1
4089
    jle @f ;edx = ted_tex or edx = ted_tex+sizeof.symbol
4090
    mov bl,[edx]
4091
    mov byte[eax],bl
4092
    inc eax
4093
    inc ecx
4094
    jmp @b
4095
  @@:
4096
 
4097
  cmp ecx,0
4098
  je @f
4099
    mov ebx,dword[file]
4100
    pop eax ;записываем указатель на выделенную память
4101
    mov dword[ebx+16],eax
4102
    push eax ;обратно запоминаем указатель на выделенную память
4103
    mov eax,70
4104
    mov dword[ebx], 2
4105
    mov dword[ebx+4], 0
4106
    mov dword[ebx+8], 0
4107
    mov dword[ebx+12], ecx
4108
    mov  byte[ebx+20], 0
4109
    push dword[f_name]
4110
    pop dword[ebx+21]
4111
    int 0x40
4112
 
4113
    mov ted_err_save,al
4114
 
4115
    cmp eax,0
4116
    je .no_msg
4117
;    cmp eax,6
4118
;    je @f
4119
      cmp ax,10
4120
      jl .zifra_0_9
4121
	mov al,'?'
4122
	sub ax,48
4123
      .zifra_0_9:
4124
      add ax,48
4125
cmp ted_fun_save_err,0
4126
je @f
4127
call ted_fun_save_err
4128
      jmp @f
4129
    .no_msg:
4130
    m2m ted_tim_ls,ted_tim_ch
4131
  @@:
4132
 
4133
  pop ecx ;записываем указатель на выделенную память
1489 IgorA 4134
  invoke mem.free,ecx
1457 IgorA 4135
  .no_save:
4136
  popad
4137
  ret
4138
endp
4139
}