Subversion Repositories Kolibri OS

Rev

Rev 8589 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
824 mikedld 1
diff16 'tp-common.asm',0,$
8590 rgimad 2
 
258 mikedld 3
;-----------------------------------------------------------------------------
617 mikedld 4
proc clear_selection ;////////////////////////////////////////////////////////
258 mikedld 5
;-----------------------------------------------------------------------------
6
	push	eax ebx
297 mikedld 7
	mov	eax,[cur_editor.SelStart.Y]
8
	mov	ebx,[cur_editor.Caret.Y]
258 mikedld 9
	cmp	eax,ebx
10
	jle	@f
11
	xchg	eax,ebx
297 mikedld 12
    @@: push	[cur_editor.Caret.X] [cur_editor.Caret.Y]
13
	pop	[cur_editor.SelStart.Y] [cur_editor.SelStart.X]
258 mikedld 14
	pop	ebx eax
15
	ret
617 mikedld 16
endp
258 mikedld 17
 
18
;-----------------------------------------------------------------------------
617 mikedld 19
proc pt_in_rect ;/////////////////////////////////////////////////////////////
258 mikedld 20
;-----------------------------------------------------------------------------
21
	cmp	eax,[ecx+0x0]
22
	jl	@f
23
	cmp	ebx,[ecx+0x4]
24
	jl	@f
25
	cmp	eax,[ecx+0x8]
26
	jg	@f
27
	cmp	ebx,[ecx+0xC]
28
	jg	@f
29
	stc
30
	ret
31
    @@: clc
32
	ret
617 mikedld 33
endp
258 mikedld 34
 
35
;-----------------------------------------------------------------------------
617 mikedld 36
proc check_bottom_right ;/////////////////////////////////////////////////////
258 mikedld 37
;-----------------------------------------------------------------------------
38
	push	eax
297 mikedld 39
	mov	eax,[cur_editor.TopLeft.Y]
617 mikedld 40
	or	eax,eax
41
	jns	@f
42
	xor	eax,eax
43
	mov	[cur_editor.TopLeft.Y],eax
44
    @@: add	eax,[lines.scr]
297 mikedld 45
	cmp	eax,[cur_editor.Lines.Count]
258 mikedld 46
	jbe	.lp1
297 mikedld 47
	mov	eax,[cur_editor.Lines.Count]
258 mikedld 48
	sub	eax,[lines.scr]
49
	jns	@f
50
	xor	eax,eax
297 mikedld 51
    @@: mov	[cur_editor.TopLeft.Y],eax
52
  .lp1: mov	eax,[cur_editor.TopLeft.X]
617 mikedld 53
	or	eax,eax
54
	jns	@f
55
	xor	eax,eax
56
	mov	[cur_editor.TopLeft.X],eax
57
    @@: add	eax,[columns.scr]
297 mikedld 58
	cmp	eax,[cur_editor.Columns.Count]
258 mikedld 59
	jbe	.exit
297 mikedld 60
	mov	eax,[cur_editor.Columns.Count]
258 mikedld 61
	sub	eax,[columns.scr]
62
	jns	@f
63
	xor	eax,eax
297 mikedld 64
    @@: mov	[cur_editor.TopLeft.X],eax
258 mikedld 65
  .exit:
66
	pop	eax
67
	ret
617 mikedld 68
endp
258 mikedld 69
 
70
;-----------------------------------------------------------------------------
617 mikedld 71
proc get_real_length ;////////////////////////////////////////////////////////
258 mikedld 72
;-----------------------------------------------------------------------------
987 mikedld 73
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
8590 rgimad 74
 
987 mikedld 75
    @@: cmp	byte[esi+eax+sizeof.EDITOR_LINE_DATA-1],' '
258 mikedld 76
	jne	@f
77
	dec	eax
78
	jnz	@b
79
    @@: ret
617 mikedld 80
endp
258 mikedld 81
 
82
;-----------------------------------------------------------------------------
617 mikedld 83
proc get_line_offset ;////////////////////////////////////////////////////////
258 mikedld 84
;-----------------------------------------------------------------------------
85
; Input:
86
;  ECX = line number
87
; Output:
88
;  ESI = line data offset
89
;-----------------------------------------------------------------------------
90
	push	eax ecx
297 mikedld 91
	mov	esi,[cur_editor.Lines]
259 mikedld 92
    @@: dec	ecx
93
	js	.exit
987 mikedld 94
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
95
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
259 mikedld 96
	jmp	@b
258 mikedld 97
  .exit:
98
	pop	ecx eax
99
	ret
617 mikedld 100
endp
258 mikedld 101
 
102
;-----------------------------------------------------------------------------
617 mikedld 103
proc init_sel_vars ;//////////////////////////////////////////////////////////
258 mikedld 104
;-----------------------------------------------------------------------------
105
	pushad
106
	mov	[sel.selected],1
297 mikedld 107
	mov	eax,[ebp+EDITOR.SelStart.X]
108
	mov	ebx,[ebp+EDITOR.SelStart.Y]
109
	mov	ecx,[ebp+EDITOR.Caret.X]
110
	mov	edx,[ebp+EDITOR.Caret.Y]
258 mikedld 111
	cmp	ebx,edx
112
	jl	.lp2
113
	jne	@f
114
	cmp	eax,ecx
115
	jl	.lp2
116
	jne	.lp1
117
	dec	[sel.selected]
118
	jmp	.lp2
119
    @@: xchg	ebx,edx
120
  .lp1: xchg	eax,ecx
121
  .lp2: mov	[sel.begin.x],eax
122
	mov	[sel.begin.y],ebx
123
	mov	[sel.end.x],ecx
124
	mov	[sel.end.y],edx
125
	popad
126
	ret
617 mikedld 127
endp
258 mikedld 128
 
129
;-----------------------------------------------------------------------------
617 mikedld 130
proc get_scroll_vars ;////////////////////////////////////////////////////////
258 mikedld 131
;-----------------------------------------------------------------------------
132
; Input:
133
;  EAX = maximum data size      (units)
134
;  EBX = visible data size      (units)
135
;  ECX = current data position  (units)
136
;  EDX = scrolling area size    (pixels)
137
; Output:
138
;  EAX = srcoller offset        (pixels)
139
;  EBX = scroller size          (pixels)
140
;-----------------------------------------------------------------------------
141
	push	eax ebx edx
142
;       sub     eax,ebx
143
	mov	esi,eax
144
	mov	eax,edx
145
	imul	ebx
146
	idiv	esi
147
	cmp	eax,[esp]
148
	jge	.null
149
	cmp	eax,AMINS
150
	jge	@f
151
	neg	eax
152
	add	eax,AMINS
153
	sub	[esp],eax
154
	mov	eax,AMINS
155
    @@: mov	[esp+4],eax	; scroller size
156
	mov	eax,[esp]
157
	imul	ecx
158
	idiv	esi
159
	or	eax,eax
160
	jns	@f
161
	xor	eax,eax
297 mikedld 162
   @@:	mov	[esp+8],eax	; scroller offset
258 mikedld 163
	add	eax,[esp+4]
164
	cmp	eax,[esp]
165
	jle	@f
166
    @@:
167
	pop	edx ebx eax
168
	ret
169
  .null:
170
	mov	dword[esp+4],0
171
	mov	dword[esp+8],0
172
	jmp	@b
617 mikedld 173
endp
258 mikedld 174
 
175
;-----------------------------------------------------------------------------
617 mikedld 176
proc uint2strz ;//////////////////////////////////////////////////////////////
258 mikedld 177
;-----------------------------------------------------------------------------
178
	dec	ebx
179
	jz	@f
180
	xor	edx,edx
181
	div	ecx
182
	push	edx
183
	call	uint2strz
184
	pop	eax
185
    @@: cmp	al,10
186
	sbb	al,$69
187
	das
188
	stosb
189
	ret
617 mikedld 190
endp
258 mikedld 191
 
192
;-----------------------------------------------------------------------------
617 mikedld 193
proc uint2str ;///////////////////////////////////////////////////////////////
258 mikedld 194
;-----------------------------------------------------------------------------
195
	cmp	eax,ecx
196
	jb	@f
197
	xor	edx,edx
198
	div	ecx
199
	push	edx
200
	call	uint2str
201
	pop	eax
202
    @@: cmp	al,10
203
	sbb	al,$69
204
	das
205
	stosb
206
	ret
617 mikedld 207
endp
258 mikedld 208
 
209
;-----------------------------------------------------------------------------
617 mikedld 210
proc strlen ;/////////////////////////////////////////////////////////////////
259 mikedld 211
;-----------------------------------------------------------------------------
212
	push	ebx
213
	mov	ebx,eax
214
	xor	eax,eax
215
    @@: cmp	byte[ebx+eax],0
216
	je	@f
217
	inc	eax
218
	jmp	@b
219
    @@: pop	ebx
220
	ret
617 mikedld 221
endp
259 mikedld 222
 
223
;-----------------------------------------------------------------------------
617 mikedld 224
proc rgb_to_gray ;////////////////////////////////////////////////////////////
258 mikedld 225
;-----------------------------------------------------------------------------
226
	push	0 eax
227
	and	dword[esp],0x000000FF
228
	fild	dword[esp]
229
	fmul	[float_gray_b]
230
	shr	eax,8
231
	mov	[esp],eax
232
	and	dword[esp],0x000000FF
233
	fild	dword[esp]
234
	fmul	[float_gray_g]
235
	faddp
236
	shr	eax,8
237
	and	eax,0x000000FF
238
	mov	[esp],eax
239
	fild	dword[esp]
240
	fmul	[float_gray_r]
241
	faddp
242
	frndint
243
	fist	dword[esp]
244
	fist	dword[esp+1]
245
	fistp	dword[esp+2]
246
	pop	eax
247
	add	esp,4
248
	ret
617 mikedld 249
endp
258 mikedld 250
 
251
;float_gray_r dd 0.30f
252
;float_gray_g dd 0.59f
253
;float_gray_b dd 0.11f
254
 
255
;-----------------------------------------------------------------------------
617 mikedld 256
proc get_active_menu_item ;///////////////////////////////////////////////////
258 mikedld 257
;-----------------------------------------------------------------------------
258
	pushad
259
	mov	[mi_cur],0
260
	mcall	37,1
261
	movsx	ebx,ax
262
	sar	eax,16
263
	mov	ecx,__rc
264
	pushd	2 0 (main_menu.width+7) (ATOPH-2)
265
	popd	[__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
266
;       add     [__rc+0xC],ATOPH-2
267
	call	pt_in_rect
268
	jnc	.outside_menu
269
	m2m	dword[ecx+0x8],dword[ecx+0x0]
270
	mov	edx,main_menu
271
    @@: inc	[mi_cur]
272
	movzx	esi,word[edx+0]
273
	add	[ecx+0x8],esi
274
	call	pt_in_rect
275
	jc	.exit
276
	m2m	dword[ecx+0x0],dword[ecx+0x8]
277
	add	edx,8+1
278
	movzx	esi,byte[edx-1]
279
	add	edx,esi
280
	cmp	byte[edx+8],0
281
	jne	@b
282
	mov	[mi_cur],0
283
  .exit:
284
	popad
285
	ret
286
  .outside_menu:
287
	or	[mi_cur],-1
288
    @@: popad
289
	ret
617 mikedld 290
endp
258 mikedld 291
 
292
;-----------------------------------------------------------------------------
617 mikedld 293
proc get_active_popup_item ;//////////////////////////////////////////////////
258 mikedld 294
;-----------------------------------------------------------------------------
295
	pushad
296
	mov	[pi_cur],0
297
	mcall	37,1
298
	movsx	ebx,ax
299
	sar	eax,16
300
	mov	ecx,__rc
301
	mov	dword[ecx+0x0],0
302
	mov	dword[ecx+0x4],0
303
	movzx	edx,[ebp+POPUP.width]
297 mikedld 304
	mov	dword[ecx+0x8],edx
258 mikedld 305
	movzx	edx,[ebp+POPUP.height]
297 mikedld 306
	mov	dword[ecx+0xC],edx
258 mikedld 307
	call	pt_in_rect
308
	jnc	.outside_window
309
	inc	dword[ecx+0x0]
617 mikedld 310
	mov	dword[ecx+0x4],2
258 mikedld 311
	dec	dword[ecx+0x8]
617 mikedld 312
	mov	dword[ecx+0xC],2+POP_IHEIGHT-1
297 mikedld 313
	mov	edx,[ebp+POPUP.data]
258 mikedld 314
    @@: inc	[pi_cur]
315
	inc	edx
316
	movzx	esi,byte[edx-1]
317
	cmp	byte[edx],'-'
318
	jne	.lp1
319
	pushd	[ecx+0xC]
617 mikedld 320
	sub	dword[ecx+0xC],POP_IHEIGHT-POP_SHEIGHT
258 mikedld 321
	call	pt_in_rect
322
	popd	[ecx+0xC]
323
	jc	.separator
617 mikedld 324
	add	dword[ecx+0x4],POP_SHEIGHT
325
	add	dword[ecx+0xC],POP_SHEIGHT
258 mikedld 326
	jmp	.lp3
327
  .lp1: call	pt_in_rect
328
	jnc	.lp2
329
	mov	eax,[pi_cur]
297 mikedld 330
	test	byte[ebp+eax-1],1
258 mikedld 331
	jnz	.exit
332
	jmp	.separator
333
  .lp2: add	dword[ecx+0x4],POP_IHEIGHT
334
	add	dword[ecx+0xC],POP_IHEIGHT
335
	add	edx,esi
336
	inc	edx
337
	movzx	esi,byte[edx-1]
338
  .lp3: add	edx,esi
339
	cmp	byte[edx],0
340
	jne	@b
341
  .separator:
342
	mov	[pi_cur],0
343
  .exit:
344
	popad
345
	ret
346
  .outside_window:
347
	or	[pi_cur],-1
348
	jmp	.exit
617 mikedld 349
endp
258 mikedld 350
 
351
;-----------------------------------------------------------------------------
617 mikedld 352
proc line_add_spaces ;////////////////////////////////////////////////////////
258 mikedld 353
;-----------------------------------------------------------------------------
280 mikedld 354
; Input:
355
;  ESI = line offset
356
;  ECX = needed line length
357
; Output:
358
;  EAX = delta
258 mikedld 359
;-----------------------------------------------------------------------------
280 mikedld 360
	xor	eax,eax
258 mikedld 361
	pushad
987 mikedld 362
	mov	edx,[esi+EDITOR_LINE_DATA.Size]
258 mikedld 363
	cmp	ecx,edx
364
	jbe	.exit
365
	sub	ecx,edx
987 mikedld 366
	lea	eax,[ecx+sizeof.EDITOR_LINE_DATA]
280 mikedld 367
	call	editor_realloc_lines
368
	mov	[esp+4*7],eax
369
	add	esi,eax
258 mikedld 370
	push	ecx
297 mikedld 371
	mov	edi,[cur_editor.Lines]
987 mikedld 372
	add	edi,[cur_editor.Lines.Size] ; !!! CHECK THIS!!! add edi,[edi-4]
259 mikedld 373
	dec	edi
258 mikedld 374
	mov	eax,esi
375
	mov	esi,edi
376
	sub	esi,ecx
987 mikedld 377
	lea	ecx,[eax+sizeof.EDITOR_LINE_DATA]
297 mikedld 378
	add	ecx,edx
258 mikedld 379
	push	ecx
380
	neg	ecx
381
	lea	ecx,[esi+ecx+1]
382
	std
383
	rep	movsb
384
	pop	edi ecx
987 mikedld 385
	add	[eax+EDITOR_LINE_DATA.Size],ecx
258 mikedld 386
	mov	al,' '
387
	cld
388
	rep	stosb
389
  .exit:
390
	popad
391
	ret
617 mikedld 392
endp
258 mikedld 393
 
394
;-----------------------------------------------------------------------------
617 mikedld 395
proc delete_selection ;///////////////////////////////////////////////////////
258 mikedld 396
;-----------------------------------------------------------------------------
259 mikedld 397
;       call    init_sel_vars
398
 
258 mikedld 399
	cmp	[sel.selected],0
400
	je	.exit.2
401
 
402
	pushad
403
	mov	ecx,[sel.begin.y]
404
	cmp	ecx,[sel.end.y]
405
	je	.single_line
406
	call	get_line_offset
987 mikedld 407
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
408
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
258 mikedld 409
	mov	ecx,[sel.begin.x]
410
	call	line_add_spaces
280 mikedld 411
	add	esi,eax
987 mikedld 412
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
258 mikedld 413
	mov	ecx,[sel.end.y]
414
	call	get_line_offset
415
	call	get_real_length
416
	cmp	eax,[sel.end.x]
417
	jbe	@f
418
	mov	eax,[sel.end.x]
987 mikedld 419
    @@: mov	ecx,[esi+EDITOR_LINE_DATA.Size]
258 mikedld 420
	sub	ecx,eax
421
	mov	ebx,[sel.begin.x]
422
	add	ebx,ecx
987 mikedld 423
	mov	[edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ebx
258 mikedld 424
	add	edi,[sel.begin.x]
987 mikedld 425
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
297 mikedld 426
	mov	ecx,[cur_editor.Lines]
824 mikedld 427
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
258 mikedld 428
	sub	ecx,esi
429
	cld
430
	rep	movsb
431
	mov	eax,[sel.end.y]
432
	sub	eax,[sel.begin.y]
297 mikedld 433
	sub	[cur_editor.Lines.Count],eax
258 mikedld 434
	jmp	.exit
435
 
436
  .single_line:
437
	call	get_line_offset
987 mikedld 438
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
439
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
258 mikedld 440
	call	get_real_length
441
	cmp	eax,[sel.begin.x]
442
	jbe	.exit
443
	mov	ecx,[sel.end.x]
444
	cmp	ecx,eax
445
	jbe	@f
446
	mov	ecx,eax
447
    @@: sub	ecx,[sel.begin.x]
987 mikedld 448
	sub	[esi+EDITOR_LINE_DATA.Size],ecx
449
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
258 mikedld 450
	add	edi,[sel.begin.x]
451
	lea	esi,[edi+ecx]
297 mikedld 452
	mov	ecx,[cur_editor.Lines]
824 mikedld 453
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
258 mikedld 454
	sub	ecx,esi
455
	cld
456
	rep	movsb
457
 
458
  .exit:
459
	mov	eax,[sel.begin.x]
297 mikedld 460
	mov	[cur_editor.Caret.X],eax
461
	mov	[cur_editor.SelStart.X],eax
258 mikedld 462
	mov	eax,[sel.begin.y]
297 mikedld 463
	mov	[cur_editor.Caret.Y],eax
464
	mov	[cur_editor.SelStart.Y],eax
280 mikedld 465
 
466
	mov	ecx,[cur_editor.Lines.Count]
467
	call	get_line_offset
987 mikedld 468
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
469
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
280 mikedld 470
	mov	eax,[cur_editor.Lines]
824 mikedld 471
	add	eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
280 mikedld 472
	sub	esi,eax
473
	lea	eax,[esi+4096]
474
	call	editor_realloc_lines
475
 
258 mikedld 476
	popad
297 mikedld 477
	mov	[cur_editor.Modified],1
258 mikedld 478
	clc
479
	ret
480
 
481
  .exit.2:
482
	stc
483
	ret
617 mikedld 484
endp
259 mikedld 485
 
486
;-----------------------------------------------------------------------------
617 mikedld 487
proc get_selection_size ;/////////////////////////////////////////////////////
259 mikedld 488
;-----------------------------------------------------------------------------
489
	push	ecx esi
490
	mov	ecx,[sel.end.y]
491
	inc	ecx
492
	call	get_line_offset
493
	mov	eax,esi
494
	mov	ecx,[sel.begin.y]
495
	call	get_line_offset
496
	sub	eax,esi
497
	pop	esi ecx
498
	ret
617 mikedld 499
endp
259 mikedld 500
 
501
;-----------------------------------------------------------------------------
617 mikedld 502
proc get_lines_in_file ;//////////////////////////////////////////////////////
259 mikedld 503
;-----------------------------------------------------------------------------
280 mikedld 504
; Input:
505
;  ESI = data pointer
506
;  ECX = data length
507
; Output:
508
;  EAX = lines number
509
;  EBX = extra length after tabs expansion
259 mikedld 510
;-----------------------------------------------------------------------------
280 mikedld 511
	push	ecx edx esi 0
259 mikedld 512
	or	ebx,-1
280 mikedld 513
	xor	edx,edx
259 mikedld 514
  .lp0: inc	ebx
515
  .lp1: dec	ecx
516
	jle	.lp2
517
	lodsb
280 mikedld 518
	cmp	al,0
519
	je	.lp2
520
	cmp	al,9
521
	je	.TB
259 mikedld 522
	cmp	al,10
523
	je	.LF
524
	cmp	al,13
525
	je	.CR
280 mikedld 526
	inc	edx
259 mikedld 527
	jmp	.lp1
280 mikedld 528
  .lp2: lea	eax,[ebx+1]
529
	pop	ebx esi edx ecx
259 mikedld 530
	ret
531
 
532
   .CR: cmp	byte[esi],10
280 mikedld 533
	jne	.LF
259 mikedld 534
	lodsb
280 mikedld 535
   .LF: xor	edx,edx
536
	jmp	.lp0
537
   .TB: and	edx,00000111b
538
	add	dword[esp],ATABW
539
	sub	[esp],edx
540
	xor	edx,edx
541
	jmp	.lp1
617 mikedld 542
endp
259 mikedld 543
 
544
;-----------------------------------------------------------------------------
617 mikedld 545
proc update_caption ;/////////////////////////////////////////////////////////
297 mikedld 546
;-----------------------------------------------------------------------------
547
	lea	esi,[cur_editor.FilePath]
548
	mov	edi,s_title
549
 
327 mikedld 550
	xor	ecx,ecx
297 mikedld 551
    @@: lodsb
552
	cmp	al,0
553
	je	@f
554
	stosb
327 mikedld 555
	inc	ecx
297 mikedld 556
	jmp	@b
557
    @@:
327 mikedld 558
	push	ecx
297 mikedld 559
	mov	dword[edi],' - '
560
	add	edi,3
327 mikedld 561
	mov	esi,htext
297 mikedld 562
	mov	ecx,htext.size
563
	cld
564
	rep	movsb
565
 
566
	mov	al,0
567
	stosb
568
 
569
	mcall	71,1,s_title
570
 
327 mikedld 571
	cmp	[do_not_draw],0
572
	jne	@f
573
	lea	esi,[cur_editor.FilePath]
574
	mov	edi,tb_opensave.text
575
	mov	ecx,[esp]
576
	cld
577
	rep	movsb
578
	pop	ecx
579
	mov	[tb_opensave.length],cl
297 mikedld 580
	clc
581
	ret
327 mikedld 582
    @@:
583
	add	esp,4
584
	clc
585
	ret
617 mikedld 586
endp
297 mikedld 587