Subversion Repositories Kolibri OS

Rev

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

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