From bcb38e3d0280ffb81b6e739c7a3b50bebc860521 Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Tue, 28 Mar 2023 12:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 整理编辑控件代码 --- funcext/tvclib/utslmemo.tsf | 293 +++++++++++++++++++++++++----------- 1 file changed, 201 insertions(+), 92 deletions(-) diff --git a/funcext/tvclib/utslmemo.tsf b/funcext/tvclib/utslmemo.tsf index dec09f4..5751369 100644 --- a/funcext/tvclib/utslmemo.tsf +++ b/funcext/tvclib/utslmemo.tsf @@ -70,7 +70,6 @@ TYPE TMemoLineList=class(tnumindexarray) // begin if(Flock)then begin - //echo "+++\r\n"; FEdit.UpDateScroll(); end end @@ -651,7 +650,8 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // FSetPostioned; //λøı FIsCaretShow; //ɼ fcaretcreated; //Ѿɹ - fForceCaret; + fForceCaret; + fcaretcout; //ѡʱcaret count FCharsInWindow; // fTextHeight; //и fLinesInWindow; //ʾ @@ -839,7 +839,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // r[1]:= RC[1]+fTextHeight * iy; iy++; r[3]:= r[1]+fTextHeight; - if i+1=fCaretY then + if i+1=fCaretY then //ǰ begin if Color<>fcurrentLineColor then begin @@ -856,6 +856,19 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // if FSelectionMode=smLine then begin end else + if FSelectionMode=smColumn then + begin + a1 := min(bb[1],ee[1]); + a2 := max(bb[1],ee[1]); + if a1=e2 then + begin + src := array(0,0,0,0); + end else + begin + src[0]+= fCharWidth *(a1-1); + src[2]:= src[0]+fCharWidth *(a2-a1); + end + end else begin if bb[0]=ee[0]then //ͬһ begin @@ -1242,8 +1255,8 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // end if not s then return; bb := array(fCaretY,fCaretX); - r := buffer_InsertChars(bb,s); - fUndoList.AddChange(crInsert,bb,r,s,0); + r := buffer_InsertChars(bb,ee,s,FSelectionMode); + fUndoList.AddChange(crInsert,bb,r,s,FSelectionMode); SetCaretXY(r); UpdateCaret(); memtextchanged(bb); @@ -1581,8 +1594,9 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // end function MoveCaretAndSelection(p1,p2,sel);//ƶѡ begin - if not(ifarray(p2)and ifarray(p1)and p2[0]>= 1 and p2[1]>= 1)then return; + if not(ifarray(p2)and ifarray(p1)and p2[0]>= 1 and p2[1]>= 1)then return; SetCaretXY(p2); + IncPaintLock(); if Sel then begin @@ -1601,10 +1615,21 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // ed := GetBlockEnd()[0]; InvalidateLines(bg,ed); end - fBlockBegin := CaretXY; - fBlockEnd := CaretXY; + if FSelectionMode=smColumn then + begin + if fBlockBegin then fBlockBegin[1] := caretxy[1]; + fBlockEnd := CaretXY; + end else + begin + fBlockBegin := CaretXY; + fBlockEnd := CaretXY; + end end - UpDateCaret(); + if FSelectionMode=smColumn and P2[0]<>P1[0] then + begin + ReCreateCaret(); + end else + UpDateCaret(); DecPaintLock(); end published @@ -1652,7 +1677,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // begin if fCaretX >= fLeftChar and(fCaretX FSelectionMode)and(v in array(smNormal,smLine))then FSelectionMode := v; + if(v <> FSelectionMode)and(v in array(smNormal,smLine,smColumn))then FSelectionMode := v; end function MoveCaretHorz(stp,sel); begin @@ -1997,9 +2022,15 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // crDelete: begin // - SetCaretXY(item.FStartPos); - InsertChars(item.FStr); - //echo tostn(item); + if item.FSelMode = smColumn then + begin + + end + else + begin + SetCaretXY(item.FStartPos); + InsertChars(item.FStr); + end end end end @@ -2219,42 +2250,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // if not GetSelAvail()then return r; bb := GetBlockBegin(); ee := GetBlockEnd(); - if FSelectionMode=smLine then - begin - len := ee[0]; - for i := bb[0]to ee[0] do - begin - r += fLines[i-1].FStr; - if ibb[1]and ee[1]>1 then - try - r := s[bb[1]:ee[1]-1]; //ܳ,try - except - r := ""; - end; - end else - begin - //һ - s := fLines[bb[0]-1].FStr; - if bb[1]<= length(s)then r += s[bb[1]:]; - r += "\r\n"; - //м - for i := bb[0]to ee[0]-2 do - begin - r += fLines[i].FStr; - r += "\r\n"; - end - //һ - s := fLines[ee[0]-1].FStr; - if s and ee[1]>1 then r += s[1:ee[1]-1]; - end - end + r := buffer_getchars(bb,ee,FSelectionMode); return r; end function SetCaretX(cx); @@ -2289,7 +2285,9 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // end function GetSelAvail(); begin - return fBlockBegin <> fBlockEnd and fBlockBegin and fBlockEnd; + r := fBlockBegin <> fBlockEnd and fBlockBegin and fBlockEnd; + if FSelectionMode=smColumn then return fBlockBegin[1]<>fBlockEnd[1]; + return r; end function SelectNextChar(); //ѡȡһַ begin @@ -2327,6 +2325,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // end else if fCaretY>1 then begin + //if FSelectionMode=smColumn then return ; s := fLines.GetStringByIndex(fCaretY-2); fBlockEnd := array(CaretY-1,length(s)+1); end @@ -2339,27 +2338,15 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // IncPaintLock(); ee := GetBlockEnd(); bb := DeleteSel(); - up := false; - if bb[0]=ee[0]then - begin - //InvalidateLines(bb[0],bb[0]); - end else - begin - up := true; - end if v then begin - bb2 := buffer_InsertChars(bb,v); - fUndoList.AddChange(crInsert,bb,bb2,v,0); + bb2 := buffer_InsertChars(bb,ee,v,FSelectionMode); + fUndoList.AddChange(crInsert,bb,bb2,v,FSelectionMode); fUndoList.MergeReplaceItem(); fBlockEnd := bb2; - if bb2[0]<> bb[0]then up := true; end else - bb2 := bb; + bb2 := bb; ExecuteCommand(ecGotoXY,bb2); - //SetCaretXY(bb2); - //if up then UpDateScroll(); - //UpDateCaret(); DecPaintLock(); memtextchanged(bb); end @@ -2370,13 +2357,13 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // if not GetSelAvail()then return 0; bb := GetBlockBegin(); ee := GetBlockEnd(); - if FSelectionMode=smLine then + if FSelectionMode= smLine then begin bb[1]:= 1; ee[1]:= fLines[ee[0]-1].StrLength()+1; - end - fUndoList.AddChange(crDelete,bb,ee,GetSelText(),0); - buffer_DeleteChars(bb,ee); + end + fUndoList.AddChange(crDelete,bb,ee,GetSelText(),FSelectionMode); + buffer_DeleteChars(bb,ee,FSelectionMode); fBlockBegin := fBlockEnd := bb; return bb; end @@ -2420,8 +2407,16 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // function CreateCaret(); // begin if FReadOnly then return; - if fcaretcreated then return; + if fcaretcreated then return; h := Font.Height; + if FSelectionMode=smColumn then + begin + if fBlockBegin and fBlockEnd then + begin + fcaretcout := max(abs(fBlockBegin[0]-fBlockEnd[0])+1,1); + if fcaretcout>1 then h := fTextHeight*fcaretcout; + end + end hd := Handle; _wapi.CreateCaret(hd,nil,1,h); _wapi.ShowCaret(hd); @@ -2437,30 +2432,144 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) // fcaretcreated := false; FIsCaretShow := false; end - FHasFocus; + FHasFocus; //buffer - function buffer_DeleteChars(bb,ee); //ɾѡ + function buffer_getchars(bb,ee,sm);// + begin + r := ""; + case FSelectionMode of + smLine: + begin + for i := bb[0] to ee[0] do + begin + r += fLines[i-1].FStr; + r += "\r\n"; + end + end + smColumn: + begin + len := ee[0]; + a1 := min(bb[1],ee[1]); + a2 := max(bb[1],ee[1]); + if a1=a2 then return r; + for i := bb[0] to ee[0] do + begin + ri := fLines[i-1].FStr; + lri := length(ri); + a22 := min(a2-1,lri); + if lri then + begin + if bytetype(ri,a1)=2 then + begin + a11 := a1+1; + end else + begin + a11 := a1; + end + if bytetype(ri,a22)=1 then + begin + a22-=1; + end + if a11<=a22 then r+=ri[a11:a22]; + end + if ibb[1]and ee[1]>1 then + try + r := s[bb[1]:ee[1]-1]; //ܳ,try + except + r := ""; + end; + end else + begin + //һ + s := fLines[bb[0]-1].FStr; + if bb[1]<= length(s)then r += s[bb[1]:]; + r += "\r\n"; + //м + for i := bb[0]to ee[0]-2 do + begin + r += fLines[i].FStr; + r += "\r\n"; + end + //һ + s := fLines[ee[0]-1].FStr; + if s and ee[1]>1 then r += s[1:ee[1]-1]; + end + end + + end + return r; + end + function buffer_DeleteChars(bb,ee,sm); //ɾѡ begin if bb=ee then return; - if bb[0]=ee[0]then //ɾһе - begin - str := fLines.GetStringByIndex(bb[0]-1); - str[bb[1]:ee[1]-1]:= ""; - fLines.SetValueByIndex(bb[0]-1,str); - end else // - begin - //ɾ - str := fLines.GetStringByIndex(bb[0]-1); - if str and length(str)>= bb[1]then str[bb[1]:]:= ""; - //ɾǰ - str2 := fLines.GetStringByIndex(ee[0]-1); - if ee[1]>1 and str2 then str2[1:ee[1]-1]:= ""; - fLines.SetValueByIndex(bb[0]-1,str+str2); - //ɾм - fLines.splices(bb[0],ee[0]-bb[0],array()); - end + case sm of + smLine: + begin + fLines.splices(bb[0]-1,max(1,ee[0]-bb[0]+1),array()); + end + smColumn: + begin + a1 := min(bb[1],ee[1]); + a2 := max(bb[1],ee[1]); + if a1=a2 then return r; + for i := bb[0] to ee[0] do + begin + ri := fLines.GetStringByIndex(i-1); + lri := length(ri); + a22 := min(a2-1,lri); + if lri then + begin + if bytetype(ri,a1)=2 then + begin + a11 := a1+1; + end else + begin + a11 := a1; + end + if bytetype(ri,a22)=1 then + begin + a22-=1; + end + if a11<=a22 then + begin + ri[a11:a22]:=""; + fLines.SetValueByIndex(i-1,ri); + end + end + end + + end + smNormal: + begin + if bb[0]=ee[0]then //ɾһе + begin + str := fLines.GetStringByIndex(bb[0]-1); + str[bb[1]:ee[1]-1]:= ""; + fLines.SetValueByIndex(bb[0]-1,str); + end else // + begin + //ɾ + str := fLines.GetStringByIndex(bb[0]-1); + if str and length(str)>= bb[1]then str[bb[1]:]:= ""; + //ɾǰ + str2 := fLines.GetStringByIndex(ee[0]-1); + if ee[1]>1 and str2 then str2[1:ee[1]-1]:= ""; + fLines.SetValueByIndex(bb[0]-1,str+str2); + //ɾм + fLines.splices(bb[0],ee[0]-bb[0],array()); + end + end + end end - function buffer_InsertChars(cxy,str); // + function buffer_InsertChars(cxy,ee,str,sm); // begin if not(ifstring(str)and str)then return; ss := str2array(str,"\n");