界面库

优化代码
This commit is contained in:
JianjunLiu 2022-04-22 15:27:57 +08:00
parent f6c6342cef
commit 517a052205
4 changed files with 387 additions and 418 deletions

View File

@ -314,7 +314,11 @@ type TGdiplusflat=class
class function GlobalSize(menm:pointer):integer;stdcall;external "Kernel32.dll" name "GlobalSize";
class function memcpy(dst:pointer;src:string;size_t:integer):pointer;cdecl;external "msvcrt.dll" name "memcpy";
class function memcpy2(var dst:string;src:pointer;size_t:integer):pointer;cdecl;external "msvcrt.dll" name "memcpy";
class function tuicloseistream(sm:pointer):integer;cdecl;external "TSLUIL.dll" name "tuicloseistream";
class function tuicloseistream(sm:pointer);
begin
r := tslvclcloseistream(sm);
return r;
end
class function GlobalAlloc(uFlags :integer;dwBytes:integer):pointer;stdcall;external "Kernel32.dll" name "GlobalAlloc";
class Function GdipCreatePath(brushMode:integer;var path:pointer):integer;stdcall;external "gdiplus.dll" name "GdipCreatePath";

View File

@ -954,7 +954,6 @@ end
end
end
class function MultiByteToWideChar_a(CodePage:integer;dwFlags:integer;lpMultiByteStr:string;cbMultiByte:integer;var lpWideCharStr:string;cchWideChar:integer):integer;
class function tuicloseistream(sm:pointer):integer;
class function GetEncoderClsid(n:String;ed:pointer):integer;
begin
WriteStringToPtr(ed,n); //保存
@ -2770,7 +2769,7 @@ end
gtk_widget_destroy(cdlg);
return r=-5;
end
function tsl_gtk_color_selection_property(w:pointer):pointer;cdecl;external "./plugin/libTSLUIL.so";
type TBrowseinfoA_ = class(tslcstructureobj)
{**
@explan(说明)文件夹选择结构 %%
@ -3066,8 +3065,11 @@ end
MultiByteToWideChar_a(0, 0, c , -1, pwszUnicode , iSize-1);
return pwszUnicode;
end
class function GetEncoderClsid(n:String;ed:pointer):integer;cdecl;external "TSLUIL.dll" name "GetEncoderClsid";
class function tuicloseistream(sm:pointer):integer;cdecl;external "TSLUIL.dll" name "tuicloseistream";
class function GetEncoderClsid(n:String;ed:pointer);
begin
r := tslvclgetencoderclsid(n,ed);
return r;
end;
//***********
function GetDpiForMonitor(hmonitor:pointer; dpiType:integer;var dpiX:integer;var dpiY:integer):pointer;stdcall;external "Shcore.dll" name "GetDpiForMonitor";
//Kernel32.dll
@ -25745,16 +25747,6 @@ type TImage=class(TSLUIBASE)
vp := GetFileType(t);
s := gdi.imagetostring(FHandle,vp);
return s;
/////////////////
st := ImageToStream(t);
_wapi.GetHGlobalFromStream(st,memo);
len := _wapi.GlobalSize(memo);
s := "";
lm := _wapi.GlobalLock(memo);
setlength(s,len);
_wapi.memcpy2(s,lm,len);
_wapi.tuicloseistream(st);
return s;
end
function StringToImage(b);
begin
@ -25771,24 +25763,6 @@ type TImage=class(TSLUIBASE)
FHandle := hd;
end
return r;
////////////////////////////////////
len := length(b);
hm := _wapi.GlobalAlloc(2,len+1); //分配内容
lm := _wapi.GlobalLock(hm); //枷锁
if lm <> 0 then
begin
_wapi.memcpy(lm,b,len); //内存拷贝
_wapi.GlobalUnlock(hm); //解锁
end
_wapi.CreateStreamOnHGlobal(hm,true,st);
r := gdi.GdipLoadImageFromStream(st,hd);
if hd then
begin
DestroyHandle();
FHandle := hd;
end
_wapi.tuicloseistream(st);
return r;
end
function ToHbitmap();
begin
@ -28221,7 +28195,8 @@ type TBasicAction=class(TComponent)
begin
if FOnExecute then
begin
calldatafunction(FOnExecute,self);
e := new tuieventbase(0,0,0,0);
calldatafunction(FOnExecute,self(true),e);
return true;
end
return false;
@ -31809,7 +31784,6 @@ type TArrayTreeClass = class
FSubName := sub;
end
end
function create(v);
begin
{**
@ -31825,15 +31799,15 @@ type TArrayTreeClass = class
@explan(说明) 添加节点 %%
**}
len := length(FComponents);
for i:= 0 to len-1 do if o= FComponents[i] then exit;
FComponents[len] := o;
for i := 0 to len-1 do if o=FComponents[i]then exit;
FComponents[len]:= o;
end
function Recycle();
begin
{**
@explan(说明) 出现死循环的时候的处理 %%
**}
if FRecyce then return ;
if FRecyce then return;
FRecyce := true;
for i,v in FComponents do
begin
@ -31854,24 +31828,23 @@ type TArrayTreeClass = class
FInToArray := FSInToArray;
ret := array();
sub := array();
for i := 0 to length( FComponents)-1 do
for i := 0 to length(FComponents)-1 do
begin
ret[FSubName,i] := FComponents[i].toarray();
ret[FSubName,i]:= FComponents[i].toarray();
end
for i,v in FValue do
begin
if i =FSubName then continue;
ret[i] := v;
if i=FSubName then continue;
ret[i]:= v;
end
return ret;
end
class function SetColumnName(info);
begin
if not ifarray(info) then info := array("id":"id","pid":"pid","sub":"sub");
if not ClumnNameOk(info["id"]) then info["id"] := "id";
if not ClumnNameOk(info["pid"]) then info["pid"] := "pid";
if not ClumnNameOk(info["sub"]) then info["sub"] := "sub";
if not ifarray(info)then info := array("id":"id","pid":"pid","sub":"sub");
if not ClumnNameOk(info["id"])then info["id"]:= "id";
if not ClumnNameOk(info["pid"])then info["pid"]:= "pid";
if not ClumnNameOk(info["sub"])then info["sub"]:= "sub";
SetIdName(info["id"],info["pid"],info["sub"]);
end
class function ToTree(d,info);
@ -31886,15 +31859,15 @@ type TArrayTreeClass = class
SetColumnName(info);
root := new TArrayTreeClass(array(FIdName:nil,FPIdName:nil));
oarray := array();
oarray[-inf] := root;
oarray[-inf]:= root;
for i,v in d do //构建id
begin
id := v[FIdName];
ido := oarray[id];
if ifnil(ido) then
if ifnil(ido)then
begin
ido := new TArrayTreeClass(v);
oarray[id] := ido;
oarray[id]:= ido;
end
end
ifcycle := true;
@ -31909,7 +31882,6 @@ type TArrayTreeClass = class
pdo := oarray[-inf];
ifcycle := false;
end
pdo.addcomponent(ido);
end
if ifcycle and oarray then
@ -31929,25 +31901,25 @@ type TArrayTreeClass = class
begin
ri := array();
if not v then continue;
ri[FIdName] := GetCounter();
ri[FPIdName] := id;
ri[FIdName]:= GetCounter();
ri[FPIdName]:= id;
for j,vi in v do
begin
if j = FSubName then
if j=FSubName then
begin
call(thisfunction,vi,ri[FIdName],r);
end
{else if j=FIdName or j = FPIdName then
begin
end} else
end}else
begin
ri[j] := vi;
ri[j]:= vi;
end
end
if ri then
begin
r[length(r)] := ri;
r[length(r)]:= ri;
end
end
end
@ -31960,7 +31932,7 @@ type TArrayTreeClass = class
默认值 array("id":"id","pid":"pid","sub":"sub"); %%
@return(array)
**}
if not ifarray(d) then exit;
if not ifarray(d)then exit;
SetColumnName(info);
r := array();
initconter();
@ -31977,13 +31949,13 @@ type TArrayTreeClass = class
@return(array) 树形结构的array
**}
root := ToTree(d,info);
if not root then return ;
if not root then return;
FSInToArray := tostn(now());
r := (root.toarray());
r :=(root.toarray());
return r;
end
end
type TIniFileExta = class()
end
type TIniFileExta=class()
{**
@explan(说明) ini文件读写封装 %%
**}
@ -32016,20 +31988,19 @@ type TArrayTreeClass = class
@explan(说明) 转换为name,value 列的二维数组 %%
**}
r := array();
for i:=0 to FTStringa.Count-1 do
for i := 0 to FTStringa.Count-1 do
begin
n := FTStringa.Names(i);
if n then
begin
if FLowerKey then n := lowercase(n);
vv := FTStringa.Values(n);
r[length(r)] := array("name":n,"value":ChangeV(vv));
r[length(r)]:= array("name":n,"value":ChangeV(vv));
end
end
FTStringa.Clear();
return r;
end
function STNV();
begin
{**
@ -32039,7 +32010,7 @@ type TArrayTreeClass = class
r := array();
for i,v in nr do
begin
r[v["name"]] := v["value"];
r[v["name"]]:= v["value"];
end
return r;
end
@ -32049,10 +32020,10 @@ type TArrayTreeClass = class
@explan(说明) 转换为一维数组 %%
**}
r := array();
for i:=0 to FTStringa.Count-1 do
for i := 0 to FTStringa.Count-1 do
begin
vi := FTStringa.Strings(i);
r[i] := FLowerKey?lowercase(vi):vi ;
r[i]:= FLowerKey?lowercase(vi):vi;
end
FTStringa.Clear();
return r;
@ -32065,7 +32036,7 @@ type TArrayTreeClass = class
@param(al)(string) 别名 %%
@param(name)(string) 文件名 %%
**}
if ifstring(al) and ifstring(Fname) then
if ifstring(al)and ifstring(Fname)then
begin
FIni := new TIniFile(al,Fname);
FTStringa := new TStringlist();
@ -32077,8 +32048,7 @@ type TArrayTreeClass = class
{**
@explan(说明) 读取section 下面key %%
**}
if ifstring(sn) and sn then
Fini.readSection(sn,FTStringa);
if ifstring(sn)and sn then Fini.readSection(sn,FTStringa);
return STA();
end
function ReadSections();virtual;
@ -32094,8 +32064,7 @@ type TArrayTreeClass = class
{**
@explan(说明) 读取section下面的所有key:value %%
**}
if ifstring(sn) and sn then
FIni.ReadSectionValues(sn,FTStringa);
if ifstring(sn)and sn then FIni.ReadSectionValues(sn,FTStringa);
return STNV();
end
function RenameSection(sn1,sn2);virtual;
@ -32105,7 +32074,7 @@ type TArrayTreeClass = class
@param(sn1)(string) 旧名字 %%
@param(sn2)(string) 新名字 %%
**}
if not(sn1 and sn2 and ifstring(sn1)) and ifstring(sn2) then exit;
if not(sn1 and sn2 and ifstring(sn1))and ifstring(sn2)then exit;
vs1 := ReadSectionValues(sn1);
EraseSection(sn1);
for i,v in vs1 do
@ -32121,7 +32090,7 @@ type TArrayTreeClass = class
@param(k1)(string) 旧名字 %%
@param(k2)(string) 新名字 %%
**}
if (sec and k2 and k1 and ifstring(sec) and ifstring(k1) and ifstring(k2)) then exit;
if(sec and k2 and k1 and ifstring(sec)and ifstring(k1)and ifstring(k2))then exit;
v := ReadKey(sec,k1);
DeleteKey(sec,k1);
WriteKey(sec,k2,v);
@ -32131,8 +32100,7 @@ type TArrayTreeClass = class
{**
@explan(说明) 获得section 数据,二维表,name,value 列
**}
if ifstring(sn) and sn then
FIni.ReadSectionValues(sn,FTStringa);
if ifstring(sn)and sn then FIni.ReadSectionValues(sn,FTStringa);
return STNVA();
end
function ReadSectionValues3(sn);
@ -32144,7 +32112,7 @@ type TArrayTreeClass = class
r := array();
for i,v in d do
begin
r[length(r)] := array(v["name"],v["value"]);
r[length(r)]:= array(v["name"],v["value"]);
end
return r;
end
@ -32153,8 +32121,7 @@ type TArrayTreeClass = class
{**
@explan(说明) 读取key %%
**}
if CheckSK(sn,key) then
return FIni.ReadString(sn,key,ifstring(def)?def:"");
if CheckSK(sn,key)then return FIni.ReadString(sn,key,ifstring(def)?def:"");
return nil;
end
function WriteKey(sn,key,v);virtual;
@ -32162,24 +32129,20 @@ type TArrayTreeClass = class
{**
@explan(说明) 写入key %%
**}
if ifnil(v) then v := "";
if CheckSK(sn,key) then
return FIni.WriteString(sn,key,ifstring(v)?v:tostn(v));
if ifnil(v)then v := "";
if CheckSK(sn,key)then return FIni.WriteString(sn,key,ifstring(v)?v:tostn(v));
return 0;
end
function DeleteKey(sn,key);virtual;
begin
if CheckSK(sn,key) then
return FIni.DeleteKey(sn,key);
if CheckSK(sn,key)then return FIni.DeleteKey(sn,key);
end
function EraseSection(sn);virtual;
begin
{**
@explan(说明)删除section %%
**}
if ifstring(sn) and sn then
return FIni.EraseSection(sn);
if ifstring(sn)and sn then return FIni.EraseSection(sn);
end
function Destroy();virtual;
begin
@ -32190,7 +32153,8 @@ type TArrayTreeClass = class
property LowerKey read FLowerKey write FLowerKey;
property LowerValue read FLowerValue write FLowerValue;
_tag;
end
end
type TCreateProcessA = class()
{**
@explan(说明) 进程构造对象 %%

View File

@ -453,6 +453,7 @@ type tgtkapis = class() //gtk
function gtk_main_iteration():integer ;cdecl;external 'libgtk-3.so';
///////////////////////////////////////////////////////
function tsl_gtk_idle_interface(p:pointer):integer;cdecl;external "./plugin/libTSLUIL.so";
function tsl_gtk_color_selection_property(w:pointer):pointer;cdecl;external "./plugin/libTSLUIL.so";
function g_idle_remove_by_data(p:pointer):integer;cdecl;external 'libgtk-3.so';
////////////////
@ -2867,7 +2868,7 @@ type tgtk_ctl_object = class(_gtkeventtype)
FConnectNameIds := array();
FConnectHandlers := array();
end
function getsingalmap();virtual;
function getsignalmap();virtual;
begin
return array(
"wm-user":'tsl_gtk_wmuser_event', //Óû§
@ -2898,7 +2899,7 @@ type tgtk_ctl_object = class(_gtkeventtype)
end
//echo "\r\nconnect ===========================",FHandle,"=====",n;
eid := GetGtkEventNameOrId(ln);
fn := (getsingalmap())[ln];
fn := (getsignalmap())[ln];
if not(fn and ifstring(fn)) then fn := "tsl_gtk_normal_event_cb";
lnid := g_signal_connect_data(FHandle, ln, gettslvcleventhandler(fn), eid,nil,0);
FConnectNameIds[ln] := lnid;
@ -3143,7 +3144,7 @@ type tgtk_im_object = class(tgtk_ctl_object)
Connect(v,f);
end
end
function getsingalmap();override;
function getsignalmap();override;
begin
return array(
"preedit-start":"dodeleteevents" ,

Binary file not shown.