Subversion Repositories Kolibri OS

Rev

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

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