界面库

优化代码
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 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 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 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 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"; class Function GdipCreatePath(brushMode:integer;var path:pointer):integer;stdcall;external "gdiplus.dll" name "GdipCreatePath";

View File

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

View File

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

Binary file not shown.