界面库
加入自动换行文本
This commit is contained in:
@@ -1345,6 +1345,166 @@ type tmemo = class(TSynMemoNorm) //
|
||||
FonSetFocus;
|
||||
fonKillFocus;
|
||||
end
|
||||
type twrapmemo = class(TScrollingWinControl)
|
||||
public
|
||||
function create(aowner);
|
||||
begin
|
||||
ftexts := array();
|
||||
fcharcount := 10;
|
||||
ftext := "";
|
||||
inherited;
|
||||
AutoScroll := 1;
|
||||
end
|
||||
function doControlALign();override;
|
||||
begin
|
||||
formattexts();
|
||||
inherited;
|
||||
end
|
||||
function MouseDown(o,e);override;
|
||||
begin
|
||||
SetFocus();
|
||||
end
|
||||
function KeyDown(o,e);override; //按键处理
|
||||
begin
|
||||
if ssCtrl in e.shiftstate then
|
||||
begin
|
||||
case e.charcode of
|
||||
ord("C"):
|
||||
begin
|
||||
getclipboard().text := ftext;
|
||||
end
|
||||
end ;
|
||||
end
|
||||
end
|
||||
function paint();override;
|
||||
begin
|
||||
ypos := GetYPos();
|
||||
// 计算需要重绘的区域
|
||||
ps := PAINTSTRUCT().rcPaint;
|
||||
tp := ps[1];
|
||||
bo := ps[3];
|
||||
FirstLine := integer(max(0,yPos+(tp)/GetYScrollDelta()));
|
||||
LastLine := integer(min(length(ftexts)-1,yPos+(bo)/GetYScrollDelta()));
|
||||
rc := ps;
|
||||
cvs := Canvas;
|
||||
cvs.Font := font;
|
||||
for i:= FirstLine to LastLine do
|
||||
begin
|
||||
s := ftexts[i];
|
||||
r := RC;
|
||||
r[1]:= RC[1]+FCharHeight * (i-ypos);
|
||||
r[3]:= r[1]+FCharHeight;
|
||||
if ifstring(s) then
|
||||
begin
|
||||
cvs.drawtext(s,r);
|
||||
end
|
||||
end
|
||||
end
|
||||
function FontChanged(o);override;
|
||||
begin
|
||||
if HandleAllocated() then doControlALign();
|
||||
end
|
||||
protected
|
||||
function GetXScrollDelta();override; //x间隔
|
||||
begin
|
||||
return FCharwidth;
|
||||
end
|
||||
function GetYScrollDelta();override; //y 间隔
|
||||
begin
|
||||
return FCharHeight;
|
||||
end
|
||||
function GetClientXCapacity();override; //宽度容量
|
||||
begin
|
||||
return fcharcount+1;
|
||||
end
|
||||
function GetClientYCapacity();override; //高度容量
|
||||
begin
|
||||
r := ClientRect;
|
||||
return ceil((r[3]-r[1])/GetYScrollDelta());
|
||||
end
|
||||
function GetClientXCount();override; //宽度间隔
|
||||
begin
|
||||
return fcharcount;
|
||||
end
|
||||
function GetClientYCount();override; //高度项
|
||||
begin
|
||||
h := FCharHeight * length(ftexts);
|
||||
return integer(h/GetYScrollDelta());
|
||||
end
|
||||
function PositionChanged();override; //基准点改变
|
||||
begin
|
||||
InvalidateRect(nil,false);
|
||||
end
|
||||
published
|
||||
property text:text read ftext write settext;
|
||||
private
|
||||
function formattexts();
|
||||
begin
|
||||
FCharwidth := font.Width;
|
||||
FCharHeight := font.Height+4;
|
||||
ss := str2array(ftext,"\n");
|
||||
rec := ClientRect;
|
||||
fcharcount := integer((rec[2]-rec[0])/FCharwidth);
|
||||
ftexts := array();
|
||||
if fcharcount>0 then
|
||||
begin
|
||||
for i,v in ss do
|
||||
begin
|
||||
cutstr(v,fcharcount,ftexts);
|
||||
end
|
||||
end
|
||||
end
|
||||
function settext(s);
|
||||
begin
|
||||
if ifstring(s) and s<>ftext then
|
||||
begin
|
||||
ftext := s;
|
||||
if HandleAllocated() then
|
||||
begin
|
||||
doControlALign();
|
||||
InvalidateRect(nil,false);
|
||||
end
|
||||
end
|
||||
end
|
||||
function getclipboard();//获得clipbord
|
||||
begin
|
||||
if not FCopyer then
|
||||
begin
|
||||
FCopyer := new TcustomClipBoard(self);
|
||||
end
|
||||
return FCopyer;
|
||||
end
|
||||
function cutstr(s,w,r);
|
||||
begin
|
||||
idx := length(r);
|
||||
len := length(s);
|
||||
i := 0;
|
||||
while i<len do
|
||||
begin
|
||||
if i=len then break;
|
||||
et := min(i+w,len);
|
||||
if bytetype(s,et)=1 then
|
||||
begin
|
||||
et-=1;
|
||||
end
|
||||
r[idx++] := s[i+1:et];
|
||||
i := et;
|
||||
end
|
||||
return ;
|
||||
for i := 0 to len step w do
|
||||
begin
|
||||
if i=len then continue;
|
||||
r[idx++] := s[i+1:min(i+w,len)];
|
||||
end
|
||||
end
|
||||
private
|
||||
FCharwidth;
|
||||
fcharcount;
|
||||
FCharHeight;
|
||||
ftexts;
|
||||
ftext;
|
||||
[weakref] FCopyer;
|
||||
end
|
||||
type thighlighter= class(tcustomsynhighlighter) //语法高亮
|
||||
uses UTslMemo;
|
||||
function create(AOwner);
|
||||
|
||||
@@ -504,7 +504,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
||||
FMouseIsDown;
|
||||
FInPutCache; //汉字输入缓存
|
||||
FSelectionMode; //选中模式
|
||||
FCopyer; //剪切板
|
||||
[weakref]FCopyer; //剪切板
|
||||
FReadOnly; //只读
|
||||
fUndoList; //撤销
|
||||
fRedoList; //反撤销
|
||||
@@ -2340,9 +2340,10 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
||||
end
|
||||
function GetMaxCharsInRow();
|
||||
begin
|
||||
if fMaxCharsInRow>10 then n := fMaxCharsInRow;
|
||||
else n := 10;
|
||||
return((FLines.RowMaxLength/n)+0.5)* n;
|
||||
if fMaxCharsInRow>5 then n := fMaxCharsInRow;
|
||||
else n := 5;
|
||||
//return((FLines.RowMaxLength/n)+0.5)* n;
|
||||
return(ceil((FLines.RowMaxLength+1)/n))* n;
|
||||
end
|
||||
function CreateCaret(); //构造光标
|
||||
begin
|
||||
|
||||
@@ -10,7 +10,6 @@ type TcustomClipBoard=class(tcomponent) //
|
||||
@explan(说明) 剪切板类 %%
|
||||
**}
|
||||
private
|
||||
private
|
||||
FIsopen;
|
||||
function CloseClipboard(); //关闭
|
||||
begin
|
||||
|
||||
Reference in New Issue
Block a user