界面库

优化
This commit is contained in:
JianjunLiu 2022-10-27 14:47:07 +08:00
parent 174e8f077c
commit e9d9e0d2e9
5 changed files with 213 additions and 81 deletions

View File

@ -2483,6 +2483,7 @@ type TComboBox = class(TcustomComboBox)
"visible","anchors","align","enabled","parentcolor","parentfont", "visible","anchors","align","enabled","parentcolor","parentfont",
"height","width","left","top", "height","width","left","top",
"readonly","itemindex", "readonly","itemindex",
"checkbox","multisel",
"items","dropdowncount","oncloseup","ondropdown","onselchanged","oneditchanged"); "items","dropdowncount","oncloseup","ondropdown","onselchanged","oneditchanged");
end end
end end

View File

@ -3257,6 +3257,17 @@ type tcustomsynhighlighter = class(TSynHighLighter)
if n then if n then
begin begin
st := fcbgestate[n]; st := fcbgestate[n];
if fswordpairs[n,2] then
begin
if st.state then
begin
st.GetRight();
end else
begin
st.GetLeft();
end
end else
begin
if fswordpairs[n][1]=lttk then if fswordpairs[n][1]=lttk then
begin begin
st.GetRight(); st.GetRight();
@ -3264,6 +3275,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
st.GetLeft(); st.GetLeft();
end end
end
d.FMATe := st.GetSate(); d.FMATe := st.GetSate();
end end
end end
@ -3446,6 +3458,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
fswordpairs[v1,0]:= v0; fswordpairs[v1,0]:= v0;
fswordpairs[v1,1]:= v1; fswordpairs[v1,1]:= v1;
fswordpairs[v1,2] := (v0=v1);
fswordpairshash[v0]:=v1; fswordpairshash[v0]:=v1;
fswordpairshash[v1]:=v1; fswordpairshash[v1]:=v1;
fswordpairshashdata[i] := v; fswordpairshashdata[i] := v;

View File

@ -1794,6 +1794,7 @@ type tpairstate =class //
begin begin
echo "²ã¼¶:",FCJ," ÐòºÅ:",FIndexs[FIndex],"״̬:", FCstate; echo "²ã¼¶:",FCJ," ÐòºÅ:",FIndexs[FIndex],"״̬:", FCstate;
end end
property state read FState;
function Clone(); function Clone();
begin begin
r := new tpairstate(FType); r := new tpairstate(FType);

View File

@ -654,6 +654,20 @@ type TcustomGridCtl = class(tcustomscrollcontrol) //
**} **}
FMergers := array(); FMergers := array();
end end
//*******************
property ItemCount read GetItemCount write SetItemCount;
property ItemHeight read FRowHeight write SetRowHeigt;
property MouseSizeCell read FMouseSizeColumnWidth write FMouseSizeColumnWidth;
property FixedRows read FFixedRows write SetFixedRows;
property FixedColumns read FColumFixed write SetFixedColumns;
property ColumnCount read GetColumnCount;
property VariableRows read FVariableRows write SetVariableRows;
{**
@param(ItemCount)(integer) 行数 %%
@param(MouseSizeCell)(bool) 鼠标改变列宽 %%
@param(FixedRows)(integer) 固定的行数作为列标 %%
**}
private
function GetGridMargin(); function GetGridMargin();
begin begin
return array(FMarginLeft,FMarginTop,FMarginRight,FMarginBottom); return array(FMarginLeft,FMarginTop,FMarginRight,FMarginBottom);
@ -687,20 +701,6 @@ type TcustomGridCtl = class(tcustomscrollcontrol) //
end end
if f then DoControlAlign(); if f then DoControlAlign();
end end
//*******************
property ItemCount read GetItemCount write SetItemCount;
property ItemHeight read FRowHeight write SetRowHeigt;
property MouseSizeCell read FMouseSizeColumnWidth write FMouseSizeColumnWidth;
property FixedRows read FFixedRows write SetFixedRows;
property FixedColumns read FColumFixed write SetFixedColumns;
property ColumnCount read GetColumnCount;
property VariableRows read FVariableRows write SetVariableRows;
{**
@param(ItemCount)(integer) 行数 %%
@param(MouseSizeCell)(bool) 鼠标改变列宽 %%
@param(FixedRows)(integer) 固定的行数作为列标 %%
**}
private
function allwidth(); function allwidth();
begin begin
return FxWidth; return FxWidth;

View File

@ -1398,8 +1398,21 @@ type teditable=class(TSLUIBASE) //
r[3]-= 1; r[3]-= 1;
return r; return r;
end end
function WMKEYUP(o,e);virtual;
begin
if FOnKeyUp then
begin
CallMessgeFunction(FOnKeyUp,o,e);
if e.skip then return ;
end
end
function WMKEYDOWN(o,e);virtual;//按键 function WMKEYDOWN(o,e);virtual;//按键
begin begin
if FOnKeyDown then
begin
CallMessgeFunction(FOnKeyDown,o,e);
if e.skip then return ;
end
fsft := ssShift in e.shiftstate; fsft := ssShift in e.shiftstate;
fctl := ssCtrl in e.shiftstate; fctl := ssCtrl in e.shiftstate;
case e.CharCode of case e.CharCode of
@ -1463,6 +1476,11 @@ type teditable=class(TSLUIBASE) //
end end
function WMCHAR(o,e);virtual;//字符 function WMCHAR(o,e);virtual;//字符
begin begin
if fOnKeyPress then
begin
CallMessgeFunction(fOnKeyPress,o,e);
if e.skip then return ;
end
if fcanundo then fredolist.clear();//清空 if fcanundo then fredolist.clear();//清空
c := e.CharCode; c := e.CharCode;
case c of case c of
@ -1638,6 +1656,9 @@ type teditable=class(TSLUIBASE) //
FOnMaxText := 0; FOnMaxText := 0;
FOnUpdate := 0; FOnUpdate := 0;
FOnChange := 0; FOnChange := 0;
FOnKeyUp := nil;
FOnKeyDown := nil;
fOnKeyPress := nil;
Fplaceholder := 0; Fplaceholder := 0;
FHost := nil; FHost := nil;
FFont := nil; FFont := nil;
@ -1655,6 +1676,9 @@ type teditable=class(TSLUIBASE) //
property ClientRect read FClientRect write FClientRect; //区域 property ClientRect read FClientRect write FClientRect; //区域
property host read FHost write SetHost; property host read FHost write SetHost;
property HasFocus read FSetFocused; property HasFocus read FSetFocused;
property OnKeyPress read FOnKeyPress write FOnKeyPress;
property OnKeyDown read FOnKeyDown write FOnKeyDown;
property onkeyup read FOnKeyUp write FOnKeyUp;
property Focusedborder read FFocusBorder write FFocusBorder; property Focusedborder read FFocusBorder write FFocusBorder;
private private
fcanundo; fcanundo;
@ -1668,6 +1692,9 @@ type teditable=class(TSLUIBASE) //
FOnMaxText; FOnMaxText;
FOnUpdate; FOnUpdate;
FOnChange; FOnChange;
FOnKeyPress;
FOnKeyDown;
FOnKeyUp;
Fplaceholder; Fplaceholder;
FSetFocused; FSetFocused;
FFocusBorder; FFocusBorder;
@ -2301,7 +2328,6 @@ type tcustomedit=class(TCustomControl)
function Create(AOwner);override; function Create(AOwner);override;
begin begin
inherited; inherited;
end end
function AfterConstruction();override; function AfterConstruction();override;
begin begin
@ -2560,7 +2586,7 @@ type tthreeEntry=class(TCustomControl)
if not ifarray(r)then return array(0,0,0,0); if not ifarray(r)then return array(0,0,0,0);
return r; return r;
end end
function WMCHAR(o,e):WM_CHAR;override; function WMCHAR(o,e);override;
begin begin
case e.char of case e.char of
"0" to "9":return inherited; "0" to "9":return inherited;
@ -2693,7 +2719,7 @@ type tthreeEntry=class(TCustomControl)
begin begin
if v.HasFocus then return v.SetFocus(); if v.HasFocus then return v.SetFocus();
end end
for i,v in FEditable do for i,v in FEntrys do
begin begin
return v.SetFocus(); return v.SetFocus();
end end
@ -3291,24 +3317,39 @@ type TcustomListBox=class(TCustomListBoxbase)
**} **}
if FMultisel=1 then if FMultisel=1 then
begin begin
flg := false;
if isValidIndex(n)then if isValidIndex(n)then
begin begin
if FSelBegin=n then return ;
FSelBegin := FSelEnd := n; FSelBegin := FSelEnd := n;
InvalidateRect(nil,false); flg := true;
end else end else
if ifarray(n) and isValidIndex(n[1])and isValidIndex(n[0])then if ifarray(n) and isValidIndex(n[1])and isValidIndex(n[0])then
begin begin
FSelBegin := MinValue(n); n1 := MinValue(n);
FSelEnd := MaxValue(n); n2 := MaxValue(n);
if n1<>FSelBegin or n2<>FSelEnd then
begin
FSelBegin := n1;
FSelEnd := n2;
flg := true;
end
end
if flg then
begin
InvalidateRect(nil,false);
if FselectionChange then
CallMessgeFunction(FselectionChange,self(true),new tuieventbase(0,0,0,0));
end end
return; return;
end else end else
if FMultisel=2 then if FMultisel=2 then
begin begin
FMultisel3Data := array(); FMultisel3Data2 := array();
if isValidIndex(n)then if isValidIndex(n)then
begin begin
FMultisel3Data[n]:= true; FMultisel3Data2[n]:= true;
end else end else
if ifarray(n)then if ifarray(n)then
begin begin
@ -3316,10 +3357,17 @@ type TcustomListBox=class(TCustomListBoxbase)
begin begin
if isValidIndex(v)then if isValidIndex(v)then
begin begin
FMultisel3Data[v]:= true; FMultisel3Data2[v]:= true;
end end
end end
end end
if FMultisel3Data2<>FMultisel3Data then
begin
FMultisel3Data := FMultisel3Data2;
InvalidateRect(nil,false);
if FselectionChange then
CallMessgeFunction(FselectionChange,self(true),new tuieventbase(0,0,0,0));
end
return; return;
end end
if not(isValidIndex2(n)) or n=FSelBegin then return; if not(isValidIndex2(n)) or n=FSelBegin then return;
@ -3972,9 +4020,12 @@ type TcustomComboBox=class(TCustomComboBoxbase)
function create(AOwner);override; function create(AOwner);override;
begin begin
inherited; inherited;
fmultisel := false;
fcheckbox := false;
FEdit := new TcustomEdit(self); FEdit := new TcustomEdit(self);
FEdit.OnKeyDown := function(o,e) FEdit.OnKeyDown := function(o,e)
begin begin
if FMultisel then return ;
case e.charcode of case e.charcode of
VK_UP: VK_UP:
begin begin
@ -3990,9 +4041,11 @@ type TcustomComboBox=class(TCustomComboBoxbase)
end end
FEdit.onchange := function(o,e); FEdit.onchange := function(o,e);
begin begin
if not o.Readonly then if not(o.Readonly) then
begin begin
feditischanging := true;
CallMessgeFunction(Foneditchanged,o,e); CallMessgeFunction(Foneditchanged,o,e);
if FMultisel then return feditischanging:=false;
t := o.Text; t := o.Text;
if t = getCurrentItemText() then return ; if t = getCurrentItemText() then return ;
for i,v in items do for i,v in items do
@ -4000,15 +4053,17 @@ type TcustomComboBox=class(TCustomComboBoxbase)
if t = v then if t = v then
begin begin
ItemIndex := i; ItemIndex := i;
feditischanging := false;
return ; return ;
end end
end end
ItemIndex := -1; ItemIndex := -1;
feditischanging := false;
end end
end end
FEdit.onupdate := function(o,e); FEdit.onupdate := function(o,e);
begin begin
if not o.Readonly then if not(o.Readonly) then
begin begin
CallMessgeFunction(FoneditUpdate,o,e); CallMessgeFunction(FoneditUpdate,o,e);
end end
@ -4019,13 +4074,11 @@ type TcustomComboBox=class(TCustomComboBoxbase)
FListBox.WsPopUp := true; FListBox.WsPopUp := true;
FListBox.onselectionchange := function(o,e); FListBox.onselectionchange := function(o,e);
begin begin
if feditischanging then return ;
r := getCurrentItemText(); r := getCurrentItemText();
if r then
begin
FEdit.Text := r; FEdit.Text := r;
ShowDropDown(false); ShowDropDown(false);
CallMessgeFunction(OnSelchanged,self,e); CallMessgeFunction(OnSelchanged,self(true),e);
end
end end
FEdit.Readonly := Freadonly; FEdit.Readonly := Freadonly;
FListBox.parent := self; FListBox.parent := self;
@ -4123,9 +4176,22 @@ type TcustomComboBox=class(TCustomComboBoxbase)
@explan(说明)获取选中的子项字符串 %% @explan(说明)获取选中的子项字符串 %%
@return(string) 子项字符串 %% @return(string) 子项字符串 %%
**} **}
return getItemText(FListBox.GetCurrentSelection()); idx := FListBox.GetCurrentSelection();
if FMultisel then
begin
r := "";
for i,v in idx do
begin
r+=getItemText(v)+";";
end
if r then r[length(r):]:="";
return r;
end
return getItemText(idx);
end end
property readonly:bool read Freadonly write setReadOnly; property readonly:bool read Freadonly write setReadOnly;
property Multisel:bool read fmultisel write setMultisel;
property checkbox:bool read fcheckbox write setcheckbox;
property textheight read FTextHeight Write FTextHeight; property textheight read FTextHeight Write FTextHeight;
property itemheight read FItemHeight write FItemHeight; property itemheight read FItemHeight write FItemHeight;
property items:strings read Getitems write setItems; property items:strings read Getitems write setItems;
@ -4137,6 +4203,32 @@ type TcustomComboBox=class(TCustomComboBoxbase)
{** {**
@param(oneditchanged)(function[tcomboBox,tuieventbase])文本被改变回调,文本显示后调用%% @param(oneditchanged)(function[tcomboBox,tuieventbase])文本被改变回调,文本显示后调用%%
**} **}
private
function setMultisel(v);
begin
nv := v?true:false;
if nv<>FMultisel then
begin
FMultisel := nv;
if FMultisel then
begin
FListBox.Multisel := 2;
end else
begin
FListBox.Multisel := 0;
end
end
end
function setcheckbox(v);
begin
nv := v?true:false;
if nv<>fcheckbox then
begin
fcheckbox := nv;
FListBox.checkbox := nv;
end
end
function setReadOnly(v); function setReadOnly(v);
begin begin
nv := v?true:false; nv := v?true:false;
@ -4146,15 +4238,19 @@ type TcustomComboBox=class(TCustomComboBoxbase)
FEdit.Readonly := nv; FEdit.Readonly := nv;
end end
end end
private
function GetItemIndex();override; function GetItemIndex();override;
begin begin
if FMultisel and (csDesigning in ComponentState) then return -1;
return FListBox.GetCurrentSelection(); return FListBox.GetCurrentSelection();
end end
function SetItemIndex(idx);override; function SetItemIndex(idx);override;
begin begin
if FMultisel and (csDesigning in ComponentState) then return -1;
return FListBox.SetCurrentSelection(idx); return FListBox.SetCurrentSelection(idx);
end end
feditischanging;//¸Ä±äÕýÔڻص÷
fmultisel;
fcheckbox;
FTextHeight; FTextHeight;
FItemHeight; FItemHeight;
Freadonly; Freadonly;
@ -5357,19 +5453,6 @@ type TCustomSpinEdit = class(TCustomControl)
end end
end; end;
end end
type TSpinCEdit=class(tcustomedit)
function create(AOwner);override;
begin
inherited;
border := false;
caption := "0";
end
function SetDesigning(f,fc);
begin
if f then Enabled := false;
else Enabled := true;
end
end
FChar; FChar;
protected protected
function UpdateControl();virtual; function UpdateControl();virtual;
@ -5377,8 +5460,6 @@ type TCustomSpinEdit = class(TCustomControl)
FEdit.Text := inttostr(FValue); FEdit.Text := inttostr(FValue);
end end
function GetValue();virtual; function GetValue();virtual;
begin
if FEdit.HandleAllocated()then
begin begin
r := FEdit.text; r := FEdit.text;
r := StrToIntDef(r,FValue); r := StrToIntDef(r,FValue);
@ -5386,7 +5467,7 @@ type TCustomSpinEdit = class(TCustomControl)
begin begin
FValue := r; FValue := r;
end end
end
return FValue; return FValue;
end end
procedure SetValue(const AValue:Double);virtual; procedure SetValue(const AValue:Double);virtual;
@ -5457,6 +5538,14 @@ type TCustomSpinEdit = class(TCustomControl)
end end
end end
public public
function dosetfocus(o,e);override;
begin
FEdit.setFocus();
end
function dokillfocus(o,e);override;
begin
FEdit.killFocus();
end
function editkeypress(o,e);virtual; function editkeypress(o,e);virtual;
begin begin
c := e.wparam; c := e.wparam;
@ -5480,9 +5569,11 @@ type TCustomSpinEdit = class(TCustomControl)
height := 25; height := 25;
Width := 60; Width := 60;
FUDwidth := 20; FUDwidth := 20;
FEdit := new TSpinCEdit(self); FEdit := new teditable(self);
FEdit.Visible := true;
FEdit.border := true;
FEdit.OnKeyPress := thisfunction(editkeypress); FEdit.OnKeyPress := thisfunction(editkeypress);
FEdit.parent := self; FEdit.host := self(true);
FUPrect := array(); FUPrect := array();
FDownrect := array(); FDownrect := array();
CI_UP := 1; CI_UP := 1;
@ -5495,21 +5586,15 @@ type TCustomSpinEdit = class(TCustomControl)
end end
function Recycling();override; function Recycling();override;
begin begin
FEdit.OnKeyPress := nil; FEdit.Recycling();
fedit := nil;
inherited; inherited;
end end
function DoControlAlign(rect);override; function DoControlAlign(rect);override;
begin begin
rect := ClientRect; rect := ClientRect;
{$ifdef linux} FEdit.ClientRect := array(rect[0],rect[1],rect[2]-FUDwidth,rect[3]);
if csDesigning in ComponentState then
begin
rect[0]+=2;
rect[1]+=2;
rect[3]-=2;
end
{$endif}
FEdit.SetBounds(rect[0],rect[1],rect[2]-FUDwidth,rect[3]);
cl := rect; //ClientRect(); cl := rect; //ClientRect();
cl[0]:= cl[2]-FUDwidth; cl[0]:= cl[2]-FUDwidth;
cl2 := cl; cl2 := cl;
@ -5519,21 +5604,51 @@ type TCustomSpinEdit = class(TCustomControl)
FUPrect := cl; FUPrect := cl;
FDownrect := CL2; FDownrect := CL2;
end end
function WMKEYDOWN(o,e);override;
begin
if csDesigning in ComponentState then return ;
fedit.WMKEYDOWN(o,e);
if e.CharCode=VK_UP then
begin
doIncrease(o,e);
end else
if e.CharCode = VK_DOWN then
begin
doDcrease(o,e);
end
end
function WMCHAR(o,e);override;
begin
if csDesigning in ComponentState then return ;
FEdit.WMCHAR(o,e);
end
function MouseDown(o,e);override; function MouseDown(o,e);override;
begin begin
if csDesigning in ComponentState then return ;
p := e.pos;
if pointinrect(p,FEdit.ClientRect)then
begin
return FEdit.MouseDown(o,e);
end
end
function MouseUp(o,e);override;
begin
if csDesigning in ComponentState then return ;
FEdit.MouseUp(o,e);
if FCI=CI_DOWN then if FCI=CI_DOWN then
begin begin
doDcrease(o,e); doDcrease(o,e);
//InValidateRect(nil,false); return ;
end else end else
if FCI=CI_UP then if FCI=CI_UP then
begin begin
doIncrease(o,e); doIncrease(o,e);
//InValidateRect(nil,false); return ;
end end
end end
function MouseMove(o,e);override; function MouseMove(o,e);override;
begin begin
if csDesigning in ComponentState then return ;
p := e.pos; p := e.pos;
if pointinrect(p,FUPrect)then if pointinrect(p,FUPrect)then
begin begin
@ -5545,10 +5660,12 @@ type TCustomSpinEdit = class(TCustomControl)
end else end else
begin begin
FCI := 0; FCI := 0;
FEdit.MouseMove(o,e);
end end
end end
function paint();override; function paint();override;
begin begin
FEdit.paint();
DrawItem(CI_UP,CIS_NONE); DrawItem(CI_UP,CIS_NONE);
DrawItem(CI_DOWN,CIS_NONE); DrawItem(CI_DOWN,CIS_NONE);
end end
@ -5876,7 +5993,7 @@ type tcustomipaddr = class(TCustomControl)
FPrev.ExecuteCommand("ecsel",array(10,1)); FPrev.ExecuteCommand("ecsel",array(10,1));
end end
end end
function WMCHAR(o,e):WM_CHAR;override; function WMCHAR(o,e);override;
begin begin
case e.char of case e.char of
"0" to "9" : "0" to "9" :