界面库

优化visibe的消息处理
This commit is contained in:
tslediter 2024-01-11 10:44:25 +08:00
parent e6dd894873
commit 7146bd0fe6
2 changed files with 105 additions and 33 deletions

View File

@ -926,6 +926,10 @@ type TWinControl = class(tcontrol)
__wexstyle := co.dwexstyle;
end
end
function WMSHOWWINDOW(o,e):WM_SHOWWINDOW;virtual;
begin
FVisible := e.wparam?true:false;
end
function WMSETCURSOR(o,e):WM_SETCURSOR;virtual;
begin
if e.lolparam=HTCLIENT then

View File

@ -390,7 +390,7 @@ type tsgtkapi = class(tgtkapis)
//pt := GetParent(dialog);
gtk_window_set_transient_for( GTK_WINDOW(dialog),0);
//gtk_window_set_modal(GTK_WINDOW( dialog),false); //屏蔽掉showmodal
w.Visible := false;
//w.Visible := false;
gtk_widget_hide(dialog);
pts := g_object_get_data(dialog,"modaling_top_parent");
if (pts) then
@ -466,9 +466,9 @@ type tsgtkapi = class(tgtkapis)
function GetTopWidgetList(h,x,y,r);
begin
wd := class(tUIglobalData).uigetdata("TGlobalComponentcache").getwndbyhwnd(h);
if wd and wd.Visible and wd.Enabled then
if wd and wd.Visible and wd.Enabled then //¿É¼ûÒÆÈë×Ó´°¿ÚÅжÏ
begin
xy := wd.ScreenToClient(x,y);
xy :=array(x,y) ;//wd.ScreenToClient(x,y);
if xy[0]>0 and xy[1]>0 and wd.width>xy[0] and wd.height>xy[1] then
begin
r[length(r)] := array(h,xy);
@ -478,7 +478,7 @@ type tsgtkapi = class(tgtkapis)
ci := ctls[i];
if (ci is class(TWinControl)) and ci.HandleAllocated() and (not ci.WsPopUp) then
begin
GetTopWidgetList(ci.Handle,x,y,r);
GetTopWidgetList(ci.Handle,x-ci.left,y-ci.top,r);
end
end
end
@ -780,13 +780,14 @@ type tsgtkapi = class(tgtkapis)
end ;
return r;
end
Function TextOutA(hdc :pointer;X:integer;y:integer;txt:string;len:integer):integer;
function textoutexa(hdc :pointer;X:integer;y:integer;txt:string;len:integer):integer;
begin
cl := gtk_object_get_data(hdc,"text.color");
// gtk_rgb_color_rgb(cl,r,g,b);
// cairo_set_source_rgb(hdc, r, g, b);
xb := gtk_object_get_data(hdc,"viewport.x");
yb := gtk_object_get_data(hdc,"viewport.y");
make_sure_rgn(hdc,xb,yb);
ft := gtk_object_get_data(hdc,"font");
global gtk_gdi_object_globals;
if ft and ifarray(gtk_gdi_object_globals) then
@ -945,6 +946,18 @@ type tsgtkapi = class(tgtkapis)
end
return 1;
end
Function TextOutA(hdc :pointer;X:integer;y:integer;txt:string;len:integer):integer;
begin
s := txt;
for i,v in array("\r","\n") do
begin
if pos(v,s) then
begin
s := replacetext(s,v,"");
end
end
return textoutexa(hdc,x,y,s,min(len,length(s)));
end
Function DrawTextA(hdc :pointer;txt:string;len:integer;rec:array of integer;fmt:integer):integer;
begin
//输出字符数
@ -964,6 +977,24 @@ type tsgtkapi = class(tgtkapis)
wd := fto._getvalue_("width");
ht := fto._getvalue_("height");
end
rl:=0;
mxl := 0;
rs := 1;
for i := 1 to length(txt) do
begin
vi:=txt[i];
if vi="\r" then continue;
if vi="\n" then
begin
rs++;
mxl := max(mxl,rl);
rl := 0;
continue;
end
rl++;
end
ht := ht*rs;
mxl := max(mxl,rl);
//DT_LEFT := 0;
DT_RIGHT := 0x2;
//DT_TOP := 0;
@ -973,7 +1004,7 @@ type tsgtkapi = class(tgtkapis)
//DT_SINGLELINE:= 0x20;
//DT_TABSTOP:= 0x80;
rw := rec[2]-rec[0];
nlen := min(len, min(integer(rw/wd),slen));
nlen := min(len, min(integer(rw/wd),mxl));
sx := rec[0];
rh := rec[3]-rec[1];
sy := rec[1];
@ -983,7 +1014,7 @@ type tsgtkapi = class(tgtkapis)
end
if (fmt .& DT_CENTER)=DT_CENTER then //处理
begin
if nlen = slen then
if nlen = mxl then
begin
sx +=(rw-(nlen*wd))/2;
end
@ -1007,20 +1038,17 @@ type tsgtkapi = class(tgtkapis)
begin
sy := rec[3]-3-ht;
end
r := TextOutA(hdc,sx,sy,txt,nlen);
return r;
rr := gtk_object_get_data(hdc,"rgn");
if rr then
bk := gtk_object_get_data(hdc,"rgn-rec");
gtk_object_set_data(hdc,"rgn-rec",rec);
r := TextOutexA(hdc,sx,sy,txt,slen);
if ifarray(bk) then
begin
p := new TCRect(rr);
rc := p._getdata_();
cairo_reset_clip(hdc);
cairo_rectangle(hdc,rc[0],rc[1],rc[2]-rc[0],rc[3]-rc[1]);
cairo_clip(hdc);
end else
begin
cairo_reset_clip(hdc);
end
gtk_object_set_data(hdc,"rgn-rec",bk);
return r;
end
Function SetTextColor(hdc :pointer;col:integer):integer;
@ -1058,6 +1086,7 @@ type tsgtkapi = class(tgtkapis)
cl := brs[0].Color;
x := gtk_object_get_data(dc,"viewport.x");
y := gtk_object_get_data(dc,"viewport.y");
make_sure_rgn(hdc,x,y);
cairo_rectangle(dc, x+rec[0], y+rec[1], rec[2]-rec[0], rec[3]-rec[1]);
gtk_rgb_color_rgb(cl,r,g,b);
cairo_set_source_rgb(dc,r,g,b);
@ -1076,12 +1105,22 @@ type tsgtkapi = class(tgtkapis)
cl := brs[0].Color;
x := gtk_object_get_data(dc,"viewport.x");
y := gtk_object_get_data(dc,"viewport.y");
make_sure_rgn(hdc,x,y);
cairo_rectangle(dc, x+rec[0], y+rec[1], rec[2]-rec[0], rec[3]-rec[1]);
gtk_rgb_color_rgb(cl,r,g,b);
cairo_set_source_rgb(dc,1-r,1-g,1-b);
cairo_fill(dc);
end
end
function make_sure_rgn(hdc,x,y);
begin
rc := gtk_object_get_data(hdc,"rgn-rec");
if rc then
begin
cairo_rectangle(hdc,rc[0]+x,rc[1]+y,rc[2]-rc[0],rc[3]-rc[1]);
cairo_clip(hdc);
end
end
function ReleaseDC(hwd :pointer;hdc:pointer):integer;
begin
DeleteDC(hdc);
@ -1092,12 +1131,30 @@ type tsgtkapi = class(tgtkapis)
if not(gdiobj) then
begin
gtk_object_set_data(hdc,"rgn",nil);
gtk_object_set_data(hdc,"rgn-rec",nil);
cairo_reset_clip(hdc);
end
else
begin
rr := gtk_object_get_data(hdc,"rgn");
if rr <> gdiobj then return ;
if rr = gdiobj then return ;
p := new TCRect(gdiobj);
rc := p._getdata_();
gtk_object_set_data(hdc,"rgn-rec",rc);
end
return r;
return r;
r := SelectObject(hdc,gdiobj);
if not(gdiobj) then
begin
gtk_object_set_data(hdc,"rgn",nil);
cairo_reset_clip(hdc);
end
else
begin
rr := gtk_object_get_data(hdc,"rgn");
if rr = gdiobj then return ;
p := new TCRect(gdiobj);
rc := p._getdata_();
cairo_reset_clip(hdc);
@ -1252,6 +1309,7 @@ type tsgtkapi = class(tgtkapis)
cairo_set_source_rgb(dc,rc,gc,bc);
end
cairo_applay_pen_style(dc);
make_sure_rgn(hdc,xb,yb);
xy := gtk_object_get_data(dc,"movepointto");
if xy then
begin
@ -8433,14 +8491,14 @@ type tgtk_ctl_scroll_window = class(tgtk_ctl_object)
function GtkEventDispatch(a,mn,c,d);override;
begin
//消息分发
if mn="scroll-event" then
if mn=GS_SCROLL_EVENT then
begin
h := a.handle;
ed := new _GdkEventScroll(c);
dr := ed.direction;
if dr<>0 and dr<>1 then return ;
x := ed.x_root;
y := ed.y_root;
x := ed.x;//ed.x_root;
y := ed.y;//ed.y_root;
r := array();
_wapi.GetTopWidgetList(h,x,y,r);
lenr := length(r)-1;
@ -8588,8 +8646,13 @@ type tgtk_ctl_window_PoPup = class(tgtk_ctl_scroll_window)
//echo "eventtype:",_wapi.gdk_event_get_event_type(c),"\r\n";
global g_gtk_shadow_size_nset,g_gtk_shadow_width,g_gtk_shadow_heigt;
case mn of
GS_HIDE:
begin
AddMessageToGtkMessageQueue(a.handle,_const.WM_SHOWWINDOW,0,0,nil);
end
GS_SHOW:
begin
AddMessageToGtkMessageQueue(a.handle,_const.WM_SHOWWINDOW,1,0,nil);
if _wapi.g_object_get_data(a.handle,"size_last_set") then //延时处理
begin
_wapi.g_timeout_add(20,makeinstance(thisfunction(later_set_size)),a.handle);
@ -8657,7 +8720,7 @@ type tgtk_ctl_window_PoPup = class(tgtk_ctl_scroll_window)
function GtkBaseEventName();override;
begin
//return inherited union2 array("configure-event","delete-event","scroll-event","activate-default");
return inherited union2 array(GS_CONFIGURE_EVENT,GS_DELETE_EVENT,GS_SCROLL_EVENT,GS_SHOW);
return inherited union2 array(GS_CONFIGURE_EVENT,GS_DELETE_EVENT,GS_SCROLL_EVENT,GS_SHOW,GS_HIDE);
end
function CreateWnd(dwExStyle,lpClassName,lpWindowName,dwStyle,x,y,nwidth,nheight,hwndparent,hmenu,hinstance,lpParam);override;
begin
@ -9655,6 +9718,11 @@ begin
return _gtkeventcall_(w,u_d,dt);
//return do_two_param_event(a, "value-changed");
end
function c_g_e_hide(w:pointer;u_d:pointer):integer; //
begin
return do_two_param_event(w, GetGtkEventNameOrId(u_d));
//return do_two_param_event(a, "value-changed");
end
function c_g_e_show(w:pointer;u_d:pointer):integer; //
begin
return do_two_param_event(w, GetGtkEventNameOrId(u_d));