From 1d410164f6533b5e76741cd4dbb1dd2335787488 Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Fri, 21 Oct 2022 17:30:02 +0800 Subject: [PATCH] Update utslvclgrid.tsf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一滚动条实现 --- funcext/tvclib/utslvclgrid.tsf | 537 +++++++++++---------------------- 1 file changed, 174 insertions(+), 363 deletions(-) diff --git a/funcext/tvclib/utslvclgrid.tsf b/funcext/tvclib/utslvclgrid.tsf index 7c99dc5..985a9ff 100644 --- a/funcext/tvclib/utslvclgrid.tsf +++ b/funcext/tvclib/utslvclgrid.tsf @@ -5,10 +5,101 @@ uses utslvclauxiliary,utslvclmemstruct,utslvclgdi; @explan(˵) ؼ %% @date(20220510) **} -type TcustomGridCtl = class(TCustomControl) //ԻƱ +type TcustomGridCtl = class(tcustomscrollcontrol) //ԻƱ {** @explan(˵) ԻƱؼ %% **} + protected + function GetClientXCapacity();virtual; // + begin + r := integer(ClientRect[2]/GetXScrollDelta()); + return r; + end + function GetClientYCapacity();virtual; //߶ + begin + r := integer(ClientRect[3]/GetYScrollDelta()); + return r; + end + function GetClientXCount();virtual; //ȼ + begin + r := integer(0.99+ allwidth()/FColWidth); + return r; + end + function GetClientYCount();virtual; //߶ + begin + return integer(0.99+allheigth()/FRowHeight); + end + function GetXScrollDelta();override; + begin + return FColWidth; + end + function GetYScrollDelta();override; + begin + return FRowHeight; + end + function PositionChanged();virtual; + begin + InvalidateRect(nil,false); + end + function UpDateScrollBar(); + begin + DoControlAlign(); + end + public + function IncPaintLock(); + begin + BeginUpdate(); + end + function DecPaintLock(); + begin + EndUpdate(); + end + function DoEndUpDate();override; + begin + if not(IsUpDating())then + begin + if FScroolChanged then + begin + FScroolChanged := false; + UpDateScrollBar(); + end + end + inherited; + end + function DoControlAlign();override; + begin + UpDateFixed(); + InitialScroll(); + end + private + function allwidth(); + begin + //return (FxWidth-FXfiexed); + r := 0; + for i:= 0 to FColsWidths.length()-1 do + begin + r+=FColsWidths[i]; + end + return r; + end + function allheigth(); + begin + //return FyHeight-FYfiexed; + if FVariableRows then + begin + r := 0; + for i:= 0 to FRowsHeight.length()-1 do + begin + r+=FRowsHeight[i]; + end + return r; + end else + begin + r := FRowHeight*FItemCount; + return r; + end + end + public function Create(AOwner);override; // begin inherited; @@ -16,12 +107,10 @@ type TcustomGridCtl = class(TCustomControl) // function AfterConstruction();override; begin inherited; - FLocalX := 0; - FLocalY := 0; Width := 300; Height := 260; FMouseSizeColumnWidth := 1; - FAutoScroll := 3; + AutoScroll := 3; FItemCount := 0; FFixedRows := 1; FColumFixed := 0; @@ -38,7 +127,6 @@ type TcustomGridCtl = class(TCustomControl) // FColsWidths := new tnumindexarray(); FRowsHeight := new tnumindexarray(); FVariableRows := false; - FSI := new TScrollinfo(); end function GetItemRect(i);virtual; //кŻ begin @@ -75,9 +163,9 @@ type TcustomGridCtl = class(TCustomControl) // begin yb += FRowsHeight[ii]; end - itv := FRowWidth; + //itv := FRowWidth; end else - yb += i * FRowHeight; + yb += i * FRowHeight; if i= 0 then clsa[length(clsa)]:= v; end FColsWidths.splices(beg>0?beg:0,len >= 0?len:FColsWidths.Length(),clsa); - InitialScroll(nil,nil,0); + DoControlAlign(); end function SetRows(rows,beg,len);virtual; begin @@ -255,7 +343,7 @@ type TcustomGridCtl = class(TCustomControl) // if v>0 then clsa[length(clsa)]:= v; end FRowsHeight.splices(beg>0?beg:0,len >= 0?len:FRowsHeight.Length(),clsa); - InitialScroll(nil,nil,0); + DoControlAlign(); end function GetColumnWidth(i); begin @@ -286,7 +374,10 @@ type TcustomGridCtl = class(TCustomControl) // @param(j)(integer) к %% **} dr := array(rec[0:1],rec[2:3]); - if i= FYfiexed then begin xdx := GetYpos(); - basey := FMarginTop-FRowWidth * xdx; + basey := FMarginTop-FRowHeight * xdx; end end if(FMouseSizeColumnWidth=0)then @@ -557,166 +640,7 @@ type TcustomGridCtl = class(TCustomControl) // end setcursornormal(); return false; - end - //ϵͳ - function DoWMSIZE(o,e);override; //С - begin - InitialScroll(e.lolParam,e.hilparam); - inherited; - end - function DoMouseWheel(o,e);override; - begin - hwnd := self.Handle; - FSI.fMask := SIF_ALL; - _wapi.GetScrollInfo(hwnd,SB_VERT,FSI._getptr_); - // 浱ǰλãЩбȽ - yPos := FSI.nPos; - dd := 0; - if e.delta<0 and FSI.nMax>yPos then - begin - dd++; - end - if e.delta>0 and FSI.nMin yPos)then - begin - //_wapi.ScrollWindow(hwnd, 0, FRowHeight * (yPos - FSI.nPos), nil, ClipScroll()); - ivrect := ClientRect; - ivrect[1]:= FYfiexed; //FMarginTop+FRowHeight*FFixedRows; - InvalidateRect(ivrect,false); - //UpdateWindow(hwnd); - end - return 0; - end - function DoHScroll(o,e);override; - begin - FSI.fMask := SIF_ALL; - _wapi.GetScrollInfo(e.hwnd,SB_HORZ,FSI._getptr_); - // 浱ǰλãЩбȽ - xPos := FSI.nPos; - case e.lowparam of - // ûߵ - SB_LEFT: - begin - FSI.nPos := FSI.nMin; - end - SB_RIGHT: - begin - FSI.nPos := FSI.nMax; - end - SB_LINELEFT: - begin - FSI.nPos -= 1; - end - // ûұߵ - SB_LINERIGHT: - begin - FSI.nPos += 1; - end - // ûߵĹ - SB_PAGELEFT: - begin - FSI.nPos -= FSI.nPage; - end - // ûұߵĹ - SB_PAGERIGHT: - begin - FSI.nPos += FSI.nPage; - end - // û϶ - SB_THUMBTRACK: - begin - FSI.nPos := FSI.nTrackPos; - end - end; - if FSI.nPos=xPos then return; - // ùλ - FSI.fMask := SIF_POS; - _wapi.SetScrollInfo(e.hwnd,SB_HORZ,FSI._getptr_,TRUE); - // ùλãڴڵܲͬһֵ - _wapi.GetScrollInfo(e.hwnd,SB_HORZ,FSI._getptr_); - // ǰıֵбȽϣͬ - FLocalX := FSI.nPos; - if(FSI.nPos <> xPos)then - begin - //_wapi.ScrollWindow(e.hwnd, FColWidth * (xPos - FSI.nPos), 0, NIL,ClipScroll()); - ivrect := ClientRect; - ivrect[0]:= FXfiexed; //FMarginTop+FRowHeight*FFixedRows; - InvalidateRect(ivrect,false); - //UpdateWindow(hwnd); - end - end + end function MergeCells(cells); begin {** @@ -781,10 +705,9 @@ type TcustomGridCtl = class(TCustomControl) // //f := true; FMarginBottom := nb; end - if f then InitialScroll(nil,nil,0); + if f then DoControlAlign(); end //******************* - property AutoScroll read FAutoScroll write setAutoScroll; property ItemCount read GetItemCount write SetItemCount; property ItemHeight read FRowHeight write SetRowHeigt; property MouseSizeCell read FMouseSizeColumnWidth write FMouseSizeColumnWidth; @@ -796,114 +719,14 @@ type TcustomGridCtl = class(TCustomControl) // @param(ItemCount)(integer) %% @param(MouseSizeCell)(bool) ıп %% @param(FixedRows)(integer) ̶Ϊб %% - **} - protected - function ItemUpDated(flag,idx);virtual; - begin - {** - @explan(˵) ״̬ %% - @param(flag)(bool) Ƿǿˢ,ĬϵȲʱˢ %% - @param(idx)(integer) idԺ %% - **} - if HandleAllocated()and not(IsUpDating())then - begin - InitialScroll(nil,nil,idx); - end - end - function InitialScroll(x,y,idx);virtual; - begin - if not HandleAllocated()then return; - UpDateFixed(); - if IsUpDating()then return; - if not(x>0 and y>0)then - begin - rc := ClientRect; - xClient := rc[2]; - yClient := rc[3]; - end else - begin - xClient := x; - yClient := y; - end - xClient -= FXfiexed; - yClient -= FYfiexed; - if xClient sc then - begin - FAutoScroll := sc; - InitialScroll(nil,nil,0); + DoControlAlign(); end end + function GetColumnCount(); begin return FColsWidths.length(); @@ -993,7 +808,7 @@ type TcustomGridCtl = class(TCustomControl) // if FItemCount <> ct and ct >= 0 then begin FItemCount := ct; - if not FVariableRows then InitialScroll(nil,nil,0); + if not FVariableRows then DoControlAlign(); end end function SetRowHeigt(h); @@ -1001,7 +816,7 @@ type TcustomGridCtl = class(TCustomControl) // if FRowHeight <> h and h >= 5 then begin FRowHeight := h; - InitialScroll(nil,nil,0); + DoControlAlign(); end end function SetFixedColumns(rs); @@ -1009,7 +824,7 @@ type TcustomGridCtl = class(TCustomControl) // if rs >= 0 and FColumFixed <> rs then begin FColumFixed := rs; - InitialScroll(nil,nil,0); + DoControlAlign(); end end function SetFixedRows(rs); @@ -1017,7 +832,7 @@ type TcustomGridCtl = class(TCustomControl) // if rs >= 0 and FFixedRows <> rs then begin FFixedRows := rs; - InitialScroll(nil,nil,0); + DoControlAlign(); end end @@ -1027,7 +842,7 @@ type TcustomGridCtl = class(TCustomControl) // begin if FColsWidths[idx]=value then return; FColsWidths[idx]:= value; - InitialScroll(nil,nil,0); + DoControlAlign(); end end function UpDateRowWidth(idx,value); @@ -1036,7 +851,7 @@ type TcustomGridCtl = class(TCustomControl) // begin if FRowsHeight[idx]=value then return; FRowsHeight[idx]:= value; - InitialScroll(nil,nil,0); + DoControlAlign(); end end @@ -1091,69 +906,7 @@ type TcustomGridCtl = class(TCustomControl) // cursor := FC_NORMAL; FC_CURRENT := FC_NORMAL; end - end - function GetHeaderRect(); - begin - end - type TPAINTCOUNT=class - {** - @explan(˵) Ƽ %% - **} - function create(v); - begin - if v is class(TControl)then - begin - FPainter := v; - v.BeginUpDate(); - end - end - function Destroy(); - begin - if FPainter then FPainter.EndUpDate(); - FPainter := nil; - end - FPainter; - end - type TMerger=class - public - FCells; - function Create(); - begin - FCells := array(); // r,c value - end - function isok(); - begin - return length(FCells); - end - function mergeid(i,j); - begin - i := FCells[0]; - j := FCells[1]; - end - function CellInMerge(i,j); - begin - if isok()then - begin - if i >= FCells[0]and i <= FCells[2]and j >= FCells[1]and j <= FCells[3]then return true; - end - return false; - end - function GetRange(); - begin - r := array(); - if isok()then - begin - return FCells; - end - return r; - end - function SetMergeCells(rec); - begin - FCells := array(); - if not ifarray(rec)then return; - if(rec[2]>= rec[0]and rec[3]>rec[1])or(rec[2]>rec[0]and rec[3]>= rec[1])then FCells := rec; - end - end + end FMergers; FAutoScroll; //̶*********** @@ -1183,7 +936,6 @@ type TcustomGridCtl = class(TCustomControl) // //*********************************** FItemCount; //************** - FSI; //п FMouseSizeColumnWidth; FSizeColum; @@ -1192,6 +944,65 @@ type TcustomGridCtl = class(TCustomControl) // FCurrentSizePos; end implementation +type TPAINTCOUNT=class + {** + @explan(˵) Ƽ %% + **} + function create(v); + begin + if v is class(TControl)then + begin + FPainter := v; + v.BeginUpDate(); + end + end + function Destroy(); + begin + if FPainter then FPainter.EndUpDate(); + FPainter := nil; + end + FPainter; +end +type TMerger=class + public + FCells; + function Create(); + begin + FCells := array(); // r,c value + end + function isok(); + begin + return length(FCells); + end + function mergeid(i,j); + begin + i := FCells[0]; + j := FCells[1]; + end + function CellInMerge(i,j); + begin + if isok()then + begin + if i >= FCells[0]and i <= FCells[2]and j >= FCells[1]and j <= FCells[3]then return true; + end + return false; + end + function GetRange(); + begin + r := array(); + if isok()then + begin + return FCells; + end + return r; + end + function SetMergeCells(rec); + begin + FCells := array(); + if not ifarray(rec)then return; + if(rec[2]>= rec[0]and rec[3]>rec[1])or(rec[2]>rec[0]and rec[3]>= rec[1])then FCells := rec; + end +end type TCanvsRgnClipAutoSave=class()//canvas ü {** @expan(˵) ücanvas,ʱԭ %%