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

Comparing ibx/trunk/ibcontrols/DBControlGrid.pas (file contents):
Revision 27 by tony, Tue Apr 14 13:10:23 2015 UTC vs.
Revision 143 by tony, Fri Feb 23 12:11:21 2018 UTC

# Line 1 | Line 1
1 +  
2   {
3   /***************************************************************************
4                                 DBControlGrid.pas
# Line 97 | Line 98 | type
98      procedure ClearCache;
99      function Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap;
100      function GetRowImage(RecNo, Offset: integer): TBitmap;
101 +    procedure InvalidateRowImage(RecNo: integer);
102      function IsEmpty(RecNo: integer): boolean;
103      procedure MarkAsDeleted(RecNo: integer);
104      property AlternateColor[RecNo: integer]: boolean read GetAlternateColor;
# Line 151 | Line 153 | type
153      FLastMouseButton: TMouseButton;
154      FLastMouseShiftState: TShiftState;
155  
156 +    function ActiveControl: TControl;
157      procedure EmptyGrid;
158      function GetDataSource: TDataSource;
159      function GetRecordCount: Integer;
# Line 236 | Line 239 | type
239      property Color;
240      property Constraints;
241      property DataSource: TDataSource read GetDataSource write SetDataSource;
239    property DefaultRowHeight;
242      property DefaultPositionAtEnd: boolean read  FDefaultPositionAtEnd write FDefaultPositionAtEnd;
243      property DragCursor;
244      property DragMode;
# Line 284 | Line 286 | end;
286  
287   implementation
288  
289 < uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue;
289 > uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit;
290  
291   { TDBControlGridDataLink }
292  
# Line 299 | Line 301 | end;
301  
302   function TRowCache.Render(Control: TWinControl): TBitmap;
303   var Container: TBitmap;
302     Msg: TLMPaint;
304   begin
305    Container := TBitmap.Create;
306    try
# Line 365 | Line 366 | begin
366      for i := StartIndex to Length(FList) - 1 do
367      begin
368        FList[i].FState := rcEmpty;
369 +      FList[i].FBitmap := nil;
370        FList[i].FAlternateColor := altColor;
371        if UseAlternateColors then
372          altColor := not altColor;
# Line 412 | Line 414 | end;
414   procedure TRowCache.ClearCache;
415   begin
416    FreeImages(true);
417 +  SetLength(FList,0);
418   end;
419  
420   function TRowCache.Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap;
# Line 420 | Line 423 | begin
423    Dec(RecNo); {Adust to zero base}
424    ExtendCache(RecNo + 1);
425    FList[RecNo].FState := rcPresent;
426 +  if FList[RecNo].FBitmap <> nil then
427 +    FList[RecNo].FBitmap.Free;
428    FList[RecNo].FBitmap := Render(Control);
429    Result := FList[RecNo].FBitmap;
430   end;
# Line 467 | Line 472 | begin
472    until false;
473   end;
474  
475 + procedure TRowCache.InvalidateRowImage(RecNo: integer);
476 + begin
477 +  Dec(RecNo); {adjust to zero base}
478 +  if (RecNo < 0) or (RecNo >= Length(FList)) then
479 +    Exit;
480 +
481 +  if FList[RecNo].FState = rcPresent then
482 +  begin
483 +    FList[RecNo].FBitmap.Free;
484 +    FList[RecNo].FBitmap := nil;
485 +    FList[RecNo].FState := rcEmpty;
486 +  end;
487 + end;
488 +
489   function TRowCache.IsEmpty(RecNo: integer): boolean;
490   begin
491    Dec(RecNo);
# Line 509 | Line 528 | end;
528  
529   { TDBControlGrid }
530  
531 + function TDBControlGrid.ActiveControl: TControl;
532 + var AParent: TWinControl;
533 + begin
534 +  Result := nil;
535 +  AParent := Parent;
536 +  while (AParent <> nil) and  not (AParent is TCustomForm) do
537 +    AParent := AParent.Parent;
538 +  if (AParent <> nil) and (AParent is TCustomForm)then
539 +      Result := TCustomForm(AParent).ActiveControl;
540 + end;
541 +
542   procedure TDBControlGrid.EmptyGrid;
543   var
544    OldFixedRows: Integer;
545   begin
546    OldFixedRows := FixedRows;
547    Clear;
548 +  FRowCache.ClearCache;
549    RowCount := OldFixedRows + 1;
550    if dgpIndicator in FOptions then
551      ColWidths[0]:=12;
# Line 567 | Line 598 | begin
598      and ValidDataSet and FDatalink.DataSet.CanModify;
599   end;
600  
570
601   procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect;
602    aState: TGridDrawState);
603   var CachedRow: TBitmap;
# Line 580 | Line 610 | begin
610      begin
611        FCacheRefreshQueued := true;
612        Application.QueueAsyncCall(@DoMoveRecord,PtrInt(aRow));
613 <    end
613 >    end;
614 >    Canvas.FillRect(aRect);
615    end
616    else
617       Canvas.Draw(aRect.Left,aRect.Top,CachedRow)
# Line 595 | Line 626 | begin
626    aRow := integer(Data);
627    FInCacheRefresh := true;
628    if assigned(FDataLink.DataSet) then
629 <    FDatalink.DataSet.MoveBy(aRow - FDrawRow)
629 >    FDatalink.DataSet.MoveBy(aRow - FDrawRow);
630   end;
631  
632   procedure TDBControlGrid.DoSetupDrawPanel(Data: PtrInt);
# Line 631 | Line 662 | end;
662   procedure TDBControlGrid.KeyDownHandler(Sender: TObject; var Key: Word;
663    Shift: TShiftState);
664   var Done: boolean;
665 +    AControl: TControl;
666   begin
667    if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus then
668    begin
669 +    AControl := ActiveControl;
670 +    if (AControl <> nil) and (AControl is TCustomComboBox)
671 +                         and ((Key in [VK_UP,VK_DOWN]) or
672 +                         (TCustomComboBox(AControl).DroppedDown and (Key = VK_RETURN)) or
673 +                         ((TCustomComboBox(AControl).Text <> '') and (Key =  VK_ESCAPE))) then
674 +      Exit; {ignore these keys if we are in a  combobox}
675 +
676 +    if (AControl <> nil) and (AControl is TCustomMemo)
677 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo}
678 +
679 +    if (AControl <> nil) and (AControl is TCustomGrid)
680 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo}
681 +
682 +    if (AControl <> nil) and ((AControl is TDateEdit) or (AControl is TCustomMaskedit))
683 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,
684 +                               VK_ESCAPE,VK_LEFT,VK_RIGHT]) then Exit; {Ignore Return in a CustomMemo}
685      Done := false;
686      if assigned(FOnKeyDownHander) then
687        OnKeyDownHander(Sender,Key,Shift,Done);
# Line 655 | Line 703 | begin
703        and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then
704    begin
705      RecNo := aDataSet.RecNo;
658    Application.ProcessMessages;  {A couple of trips round the message loop seems to be necessary}
706      Application.ProcessMessages;
707      if RecNo = aDataSet.RecNo then   {Guard against sudden changes}
708 <      FRowCache.Add2Cache(aDataSet.RecNo,FDrawPanel);
708 >      FRowCache.Add2Cache(RecNo,FDrawPanel);
709    end;
710   end;
711  
712   procedure TDBControlGrid.OnDataSetChanged(aDataSet: TDataSet);
713   begin
714 <  if (aDataSet.State = dsBrowse) and (FLastRecordCount >  GetRecordCount) then
714 >  if aDataSet.State = dsBrowse then
715    begin
716 <    {must be delete}
717 <    FRowCache.MarkAsDeleted(FSelectedRecNo);
718 <    Dec(FSelectedRow);
716 >    if GetRecordCount = 0 then
717 >    begin
718 >      {Must be closed/reopened}
719 >      FRowCache.ClearCache;
720 >      FSelectedRow := 0;
721 >    end
722 >    else
723 >    if FLastRecordCount >  GetRecordCount then
724 >    begin
725 >      {must be delete}
726 >      FRowCache.MarkAsDeleted(FSelectedRecNo);
727 >      Dec(FSelectedRow);
728 >    end;
729      LayoutChanged;
730    end;
731    FLastRecordCount := GetRecordCount;
# Line 765 | Line 822 | begin
822       RemoveFreeNotification(FDrawPanel);
823       FDrawPanel.RemoveAllHandlersOfObject(self);
824       theForm := Parent;
825 <     while not (theForm is TCustomForm) and (theForm.Parent <> nil) do
825 >     while not ((theForm is TCustomForm) or (theForm is TCustomFrame))
826 >                           and (theForm.Parent <> nil) do
827         theForm := theForm.Parent;
828       FDrawPanel.Parent := theForm;
829    end;
# Line 782 | Line 840 | begin
840         FDrawPanel.Visible := false;
841        FRowCache.Height := FDrawPanel.Height;
842        FRowCache.Width := FDrawPanel.Width;
843 <      AddHandlerOnResize(@OnDrawPanelResize);
843 >      FDrawPanel.AddHandlerOnResize(@OnDrawPanelResize);
844        FreeNotification(FDrawPanel);
845      end;
846    except
# Line 806 | Line 864 | end;
864  
865   procedure TDBControlGrid.SetupDrawPanel(aRow: integer);
866   begin
867 +  if FDrawPanel = nil then Exit;
868    if ValidDataSet and FRowCache.AlternateColor[FDataLink.DataSet.RecNo] then
869      FDrawPanel.Color := AlternateColor
870    else
# Line 1125 | Line 1184 | begin
1184    if aCol < FixedCols then
1185       DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false)
1186    else
1187 +  if (FDrawPanel = nil) or not FDataLink.Active then
1188 +    DrawFillRect(Canvas,aRect)
1189 +  else
1190    if not FDrawingActiveRecord and FDataLink.Active then
1191        DoDrawRow(aRow,aRect,aState);
1192    {if we are drawing the active record then this is rendered by the Draw Panel
# Line 1370 | Line 1432 | begin
1432      FInCacheRefresh := false;
1433      FCacheRefreshQueued := false;
1434      Row := FixedRows;
1435 +    FDrawingActiveRecord := false;
1436 +    FSelectedRecNo := 0;
1437 +    FSelectedRow := 0;
1438 +    FRequiredRecNo := 0;
1439    end;
1440    FRowCache.UseAlternateColors := AlternateColor <> Color;
1441    FRowCache.AltColorStartNormal := AltColorStartNormal;
# Line 1559 | Line 1625 | begin
1625    PrevRow := Row;
1626    Row := FDrawRow;
1627    if not FInCacheRefresh then
1628 +  begin
1629      FSelectedRow := FDrawRow;
1630 +    if FDatalink.DataSet.State <> dsInsert then
1631 +      FRowCache.InvalidateRowImage(FSelectedRecNo);
1632 +  end;
1633    InvalidateRow(PrevRow);
1634    SetupDrawPanel(FDrawRow);
1635   end;
# Line 1621 | Line 1691 | begin
1691      FDataLink.Free;
1692    end;
1693    if assigned(FRowCache) then FRowCache.Free;
1694 +  Application.RemoveAsyncCalls(self);
1695    inherited Destroy;
1696   end;
1697  
# Line 1659 | Line 1730 | begin
1730   end;
1731  
1732   end.
1733 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines