Subversion Repositories Kolibri OS

Rev

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