Subversion Repositories Kolibri OS

Rev

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