Tinypad - support for kernel clipboard

git-svn-id: svn://kolibrios.org@4487 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2014-01-19 19:24:16 +00:00
parent a48c1e2408
commit cfffb7f087
4 changed files with 334 additions and 64 deletions

View File

@ -104,6 +104,7 @@ exit_tab_num dd ?
temp_buf dd ? temp_buf dd ?
copy_buf dd ? copy_buf dd ?
clipboard_buf dd ?
label color_tbl dword label color_tbl dword
.text dd ? .text dd ?

View File

@ -43,7 +43,7 @@ FALSE = 0
;include 'debug.inc' ;include 'debug.inc'
;define __DEBUG__ 1 ;define __DEBUG__ 1
;define __DEBUG_LEVEL__ 1 ;define __DEBUG_LEVEL__ 1
;include 'debug-fdo.inc' ;include '../../../debug-fdo.inc'
; compiled-in options ; compiled-in options
@ -612,6 +612,7 @@ include 'tp-tbox.asm'
include 'tp-tabctl.asm' include 'tp-tabctl.asm'
include 'tp-editor.asm' include 'tp-editor.asm'
include 'tp-recode.asm' include 'tp-recode.asm'
include 'tp-clipboard.asm'
include '../../../dll.inc' include '../../../dll.inc'

View File

@ -0,0 +1,252 @@
;-----------------------------------------------------------------------------
put_to_clipboard:
; we have allocated memory?
mov edi,[clipboard_buf]
test edi,edi
jz .end
; convert from Tinypad format to the kernel clipboard format
add edi,3*4
mov esi,[copy_buf]
mov ecx,[copy_count]
cld
;--------------------------------------
@@:
push ecx
lodsd
mov ecx,eax
lodsw
rep movsb
mov ax,0x0a0d
stosw
; mov ax,0x0d
; stosb
pop ecx
dec ecx
jnz @b
xor eax,eax
stosb
; building the clipboard slot header
mov esi,[clipboard_buf]
sub edi,esi
mov [esi],edi ; clipboard area size
xor eax,eax
mov [esi+4],eax ; ; type 'text'
inc eax
mov [esi+8],eax ; cp866 text encoding
; put slot to the kernel clipboard
mov edx,[clipboard_buf]
mov ecx,[edx]
mcall 54,2
; remove unnecessary memory area
xor eax,eax
stdcall mem.ReAlloc,[clipboard_buf],eax
mov [clipboard_buf],eax
xor eax,eax
mov [copy_size],eax
mov [copy_count],eax
stdcall mem.ReAlloc,[copy_buf],eax
mov [copy_buf],eax
;--------------------------------------
.end:
ret
;-----------------------------------------------------------------------------
get_from_clipboard:
pushad
mcall 54,0
; no slots of clipboard ?
test eax,eax
jz .exit
; main list area not found ?
inc eax
test eax,eax
jz .exit
sub eax,2
mov ecx,eax
mcall 54,1
; main list area not found ?
inc eax
test eax,eax
jz .exit
; error ?
sub eax,2
test eax,eax
jz .exit
inc eax
mov [clipboard_buf],eax
; check contents of container
mov ebx,[eax+4]
; check for text
test ebx,ebx
jnz .no_valid_text
mov ebx,[eax+8]
; check for cp866
cmp bl,1
jz .yes_valid_text
.no_valid_text:
xor eax,eax
mov [copy_size],eax
jmp .remove_area
;--------------------------------------
.yes_valid_text:
call know_number_line_breaks
mov [copy_count],ebx
mov eax,[clipboard_buf]
sub esi,eax
mov [eax],esi
shl ebx,1
lea ebx,[ebx*3]
mov eax,[clipboard_buf]
mov eax,[eax]
sub eax,4*3
add eax,ebx
mov [copy_size],eax
stdcall mem.ReAlloc,[copy_buf],eax
mov [copy_buf],eax
call convert_clipboard_buf_to_copy_buf
; remove unnecessary memory area
.remove_area:
xor eax,eax
stdcall mem.ReAlloc,[clipboard_buf],eax
mov [clipboard_buf],eax
;--------------------------------------
.exit:
popad
ret
;-----------------------------------------------------------------------------
convert_clipboard_buf_to_copy_buf:
mov edi,[copy_buf]
mov ebx,edi
add edi,6
mov eax,[clipboard_buf]
mov esi,eax
add esi,4*3
mov ecx,[eax]
sub ecx,4*3
xor edx,edx
cld
;--------------------------------------
.loop:
lodsb
test al,al
jz .inc_counter ;.end_of_data
cmp al,0x0d
je .check_0x0a
cmp al,0x0a
je .inc_counter
dec ecx
jz .end_of_data
stosb
jmp .loop
;--------------------------------------
.check_0x0a:
dec ecx
jz .end_of_data
cmp [esi],byte 0x0a
jne @f
lodsb
;--------------------------------------
.inc_counter:
dec ecx
jz .end_of_data
;--------------------------------------
@@:
mov eax,edi
sub eax,ebx
sub eax,6
.@@111:
mov [ebx],eax
test edx,edx
jz @f
test eax,eax
jz @f
mov [ebx+4],word EDITOR_LINE_FLAG_MOFIFIED
@@:
mov ebx,edi
add edi,6
inc edx
jmp .loop
;--------------------------------------
.end_of_data:
sub edi,[copy_buf]
sub edi,6
mov [copy_size],edi
ret
;-----------------------------------------------------------------------------
know_number_line_breaks:
; to know the number of line breaks
mov eax,[clipboard_buf]
mov esi,eax
add esi,4*3
mov ecx,[eax]
sub ecx,4*3
xor ebx,ebx
cld
;--------------------------------------
@@:
lodsb
test al,al
jz .end_of_data_1
cmp al,0x0d
je .check_0x0a
cmp al,0x0a
je .inc_counter
dec ecx
jnz @b
jmp .end_of_data
;--------------------------------------
.check_0x0a:
inc ebx
dec ecx
jz .end_of_data
cmp [esi],byte 0x0a
jne @b
lodsb
dec ecx
jnz @b
jmp .end_of_data
;--------------------------------------
.inc_counter:
inc ebx
dec ecx
jnz @b
;--------------------------------------
.end_of_data_1:
cmp [esi-2],byte 0x0d
je .end_of_data
cmp [esi-2],byte 0x0a
je .end_of_data
inc ebx
inc esi
;--------------------------------------
.end_of_data:
ret
;-----------------------------------------------------------------------------

View File

@ -482,72 +482,77 @@ endp
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
proc key.ctrl_c proc key.ctrl_c
mov [copy_size],0 mov [copy_size],0
cmp [sel.selected],0 cmp [sel.selected],0
je .exit je .exit
call get_selection_size call get_selection_size
stdcall mem.ReAlloc,[copy_buf],eax push eax
mov [copy_buf],eax stdcall mem.ReAlloc,[copy_buf],eax
mov [copy_buf],eax
pop eax
stdcall mem.ReAlloc,[clipboard_buf],eax
mov [clipboard_buf],eax
cld cld
mov eax,[sel.begin.y] mov eax,[sel.begin.y]
cmp eax,[sel.end.y] cmp eax,[sel.end.y]
je .single_line je .single_line
mov ecx,[sel.begin.y] mov ecx,[sel.begin.y]
call get_line_offset call get_line_offset
inc ecx inc ecx
push ecx push ecx
mov edi,[copy_buf] mov edi,[copy_buf]
call get_real_length call get_real_length
sub eax,[sel.begin.x] sub eax,[sel.begin.x]
jge @f jge @f
xor eax,eax xor eax,eax
@@: add esi,[sel.begin.x] @@: add esi,[sel.begin.x]
add esi,sizeof.EDITOR_LINE_DATA add esi,sizeof.EDITOR_LINE_DATA
mov [edi+EDITOR_LINE_DATA.Size],eax mov [edi+EDITOR_LINE_DATA.Size],eax
add edi,sizeof.EDITOR_LINE_DATA add edi,sizeof.EDITOR_LINE_DATA
mov ecx,eax mov ecx,eax
jecxz @f jecxz @f
rep movsb rep movsb
@@: mov ecx,[sel.end.y] @@: mov ecx,[sel.end.y]
call get_line_offset call get_line_offset
pop ecx pop ecx
cmp ecx,[sel.end.y] cmp ecx,[sel.end.y]
je @f je @f
mov eax,esi mov eax,esi
call get_line_offset call get_line_offset
sub eax,esi sub eax,esi
mov ecx,eax mov ecx,eax
rep movsb rep movsb
mov ecx,[sel.end.y] mov ecx,[sel.end.y]
@@: call get_line_offset @@: call get_line_offset
mov eax,[esi+EDITOR_LINE_DATA.Size] mov eax,[esi+EDITOR_LINE_DATA.Size]
add esi,sizeof.EDITOR_LINE_DATA add esi,sizeof.EDITOR_LINE_DATA
cmp eax,[sel.end.x] cmp eax,[sel.end.x]
jle @f jle @f
mov eax,[sel.end.x] mov eax,[sel.end.x]
@@: mov ebx,edi @@: mov ebx,edi
mov [edi+EDITOR_LINE_DATA.Size],eax mov [edi+EDITOR_LINE_DATA.Size],eax
add edi,sizeof.EDITOR_LINE_DATA add edi,sizeof.EDITOR_LINE_DATA
mov ecx,eax mov ecx,eax
jecxz @f jecxz @f
rep movsb rep movsb
sub eax,[sel.end.x] sub eax,[sel.end.x]
jz @f jz @f
neg eax neg eax
mov ecx,eax mov ecx,eax
add [ebx],eax add [ebx],eax
mov al,' ' mov al,' '
rep stosb rep stosb
@@: sub edi,[copy_buf] @@: sub edi,[copy_buf]
mov [copy_size],edi mov [copy_size],edi
mov eax,[sel.end.y] mov eax,[sel.end.y]
sub eax,[sel.begin.y] sub eax,[sel.begin.y]
inc eax inc eax
mov [copy_count],eax mov [copy_count],eax
call put_to_clipboard
.exit: .exit:
ret ret
.single_line: .single_line:
mov eax,[sel.end.x] mov eax,[sel.end.x]
@ -579,6 +584,8 @@ endp
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
proc key.ctrl_v proc key.ctrl_v
call get_from_clipboard
cmp [copy_size],0 cmp [copy_size],0
je .exit je .exit
@ -684,6 +691,15 @@ proc key.ctrl_v
mov [cur_editor.Modified],1 mov [cur_editor.Modified],1
.exit: .exit:
cmp [copy_size],0
je .exit_1
; remove unnecessary memory area
xor eax,eax
mov [copy_size],eax
mov [copy_count],eax
stdcall mem.ReAlloc,[copy_buf],eax
mov [copy_buf],eax
.exit_1:
ret ret
.check_columns: .check_columns: