Subversion Repositories Kolibri OS

Rev

Rev 2808 | Rev 3903 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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