ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/ibcontrols/DBControlGrid.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/DBControlGrid.pas (file contents):
Revision 35 by tony, Tue Jan 26 14:38:47 2016 UTC vs.
Revision 317 by tony, Thu Feb 25 12:01:13 2021 UTC

# Line 1 | Line 1
1 +  
2   {
3   /***************************************************************************
4                                 DBControlGrid.pas
# Line 67 | Line 68 | uses
68   }
69  
70   type
70  TRowCacheState = (rcEmpty,rcPresent,rcDeleted);
71  TRowDetails = record
72    FState: TRowCacheState;
73    FAlternateColor: boolean;
74    FBitmap: TBitmap;
75  end;
76
71    { TRowCache }
72  
73    TRowCache = class
74    private
75 +    type
76 +      TRowCacheState = (rcEmpty,rcPresent,rcDeleted);
77 +      TRowDetails = record
78 +        FState: TRowCacheState;
79 +        FAlternateColor: boolean;
80 +        FBitmap: TBitmap;
81 +  end;
82 +
83 +  private
84      FAltColorStartNormal: boolean;
85      FHeight: integer;
86      FList: array of TRowDetails;
# Line 285 | Line 288 | end;
288  
289   implementation
290  
291 < uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue;
291 > uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit;
292  
293   { TDBControlGridDataLink }
294  
# Line 300 | Line 303 | end;
303  
304   function TRowCache.Render(Control: TWinControl): TBitmap;
305   var Container: TBitmap;
303     Msg: TLMPaint;
306   begin
307    Container := TBitmap.Create;
308    try
309      Container.SetSize(Control.Width,Control.Height);
310 +    Container.Canvas.Brush.Color := control.Color;
311 +    Container.Canvas.FillRect(0,0,Control.Width,Control.Height);
312      Control.PaintTo(Container.Canvas,0,0);
313    except
314      Container.Free;
# Line 366 | Line 370 | begin
370      for i := StartIndex to Length(FList) - 1 do
371      begin
372        FList[i].FState := rcEmpty;
373 +      FList[i].FBitmap := nil;
374        FList[i].FAlternateColor := altColor;
375        if UseAlternateColors then
376          altColor := not altColor;
# Line 417 | Line 422 | begin
422   end;
423  
424   function TRowCache.Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap;
420 var i: integer;
425   begin
426    Dec(RecNo); {Adust to zero base}
427    ExtendCache(RecNo + 1);
428    FList[RecNo].FState := rcPresent;
429 +  if FList[RecNo].FBitmap <> nil then
430 +    FList[RecNo].FBitmap.Free;
431    FList[RecNo].FBitmap := Render(Control);
432    Result := FList[RecNo].FBitmap;
433   end;
# Line 478 | Line 484 | begin
484    if FList[RecNo].FState = rcPresent then
485    begin
486      FList[RecNo].FBitmap.Free;
487 +    FList[RecNo].FBitmap := nil;
488      FList[RecNo].FState := rcEmpty;
489    end;
490   end;
# Line 594 | Line 601 | begin
601      and ValidDataSet and FDatalink.DataSet.CanModify;
602   end;
603  
597
604   procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect;
605    aState: TGridDrawState);
606   var CachedRow: TBitmap;
# Line 607 | Line 613 | begin
613      begin
614        FCacheRefreshQueued := true;
615        Application.QueueAsyncCall(@DoMoveRecord,PtrInt(aRow));
616 <    end
616 >    end;
617 >    Canvas.FillRect(aRect);
618    end
619    else
620       Canvas.Draw(aRect.Left,aRect.Top,CachedRow)
# Line 660 | Line 667 | procedure TDBControlGrid.KeyDownHandler(
667   var Done: boolean;
668      AControl: TControl;
669   begin
670 <  if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus then
670 >  if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus
671 >    and (Self.Owner=Screen.ActiveForm) then
672    begin
673      AControl := ActiveControl;
674      if (AControl <> nil) and (AControl is TCustomComboBox)
# Line 672 | Line 680 | begin
680      if (AControl <> nil) and (AControl is TCustomMemo)
681                           and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo}
682  
683 +    if (AControl <> nil) and (AControl is TCustomGrid)
684 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo}
685 +
686 +    if (AControl <> nil) and ((AControl is TDateEdit) or (AControl is TCustomMaskedit))
687 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,
688 +                               VK_ESCAPE,VK_LEFT,VK_RIGHT]) then Exit; {Ignore Return in a CustomMemo}
689      Done := false;
690      if assigned(FOnKeyDownHander) then
691        OnKeyDownHander(Sender,Key,Shift,Done);
# Line 693 | Line 707 | begin
707        and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then
708    begin
709      RecNo := aDataSet.RecNo;
696    Application.ProcessMessages;  {A couple of trips round the message loop seems to be necessary}
710      Application.ProcessMessages;
711      if RecNo = aDataSet.RecNo then   {Guard against sudden changes}
712 <      FRowCache.Add2Cache(aDataSet.RecNo,FDrawPanel);
712 >      FRowCache.Add2Cache(RecNo,FDrawPanel);
713    end;
714   end;
715  
# Line 855 | Line 868 | end;
868  
869   procedure TDBControlGrid.SetupDrawPanel(aRow: integer);
870   begin
871 +  if FDrawPanel = nil then Exit;
872    if ValidDataSet and FRowCache.AlternateColor[FDataLink.DataSet.RecNo] then
873      FDrawPanel.Color := AlternateColor
874    else
# Line 1166 | Line 1180 | begin
1180      result := dsInactive;
1181   end;
1182  
1169 var
1170  DataCol: Integer;
1183   begin
1184    PrepareCanvas(aCol, aRow, aState);
1185  
1186    if aCol < FixedCols then
1187       DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false)
1188    else
1189 <  if FDrawPanel = nil then
1190 <    DrawFillRect(Canvas,aRect)    else
1189 >  if (FDrawPanel = nil) or not FDataLink.Active then
1190 >    DrawFillRect(Canvas,aRect)
1191 >  else
1192    if not FDrawingActiveRecord and FDataLink.Active then
1193        DoDrawRow(aRow,aRect,aState);
1194    {if we are drawing the active record then this is rendered by the Draw Panel
# Line 1277 | Line 1290 | end;
1290   procedure TDBControlGrid.KeyDown(var Key: Word; Shift: TShiftState);
1291   type
1292    TOperation=(opMoveBy,opCancel,opAppend,opInsert,opDelete);
1280 var
1281  DeltaCol,DeltaRow: Integer;
1293  
1294    procedure DoOnKeyDown;
1295    begin
# Line 1680 | Line 1691 | begin
1691      FDataLink.Free;
1692    end;
1693    if assigned(FRowCache) then FRowCache.Free;
1694 +  if not (csDesigning in ComponentState) then
1695 +    Application.RemoveOnKeyDownBeforeHandler( @KeyDownHandler );
1696 +  Application.RemoveAsyncCalls(self);
1697    inherited Destroy;
1698   end;
1699  
# Line 1718 | Line 1732 | begin
1732   end;
1733  
1734   end.
1735 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines