Subversion Repositories Kolibri OS

Rev

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