Subversion Repositories Kolibri OS

Rev

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