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 23 by tony, Fri Mar 13 10:26:52 2015 UTC vs.
Revision 35 by tony, Tue Jan 26 14:38:47 2016 UTC

# Line 97 | Line 97 | type
97      procedure ClearCache;
98      function Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap;
99      function GetRowImage(RecNo, Offset: integer): TBitmap;
100 +    procedure InvalidateRowImage(RecNo: integer);
101      function IsEmpty(RecNo: integer): boolean;
102      procedure MarkAsDeleted(RecNo: integer);
103      property AlternateColor[RecNo: integer]: boolean read GetAlternateColor;
# Line 151 | Line 152 | type
152      FLastMouseButton: TMouseButton;
153      FLastMouseShiftState: TShiftState;
154  
155 +    function ActiveControl: TControl;
156      procedure EmptyGrid;
157      function GetDataSource: TDataSource;
158      function GetRecordCount: Integer;
# Line 158 | Line 160 | type
160      function  GridCanModify: boolean;
161      procedure DoDrawRow(aRow: integer; aRect: TRect; aState: TGridDrawState);
162      procedure DoMoveRecord(Data: PtrInt);
163 +    procedure DoSelectNext(Data: PtrInt);
164      procedure DoScrollDataSet(Data: PtrInt);
165      procedure DoSetupDrawPanel(Data: PtrInt);
166      procedure DoSendMouseClicks(Data: PtrInt);
# Line 235 | Line 238 | type
238      property Color;
239      property Constraints;
240      property DataSource: TDataSource read GetDataSource write SetDataSource;
238    property DefaultRowHeight;
241      property DefaultPositionAtEnd: boolean read  FDefaultPositionAtEnd write FDefaultPositionAtEnd;
242      property DragCursor;
243      property DragMode;
# Line 411 | Line 413 | end;
413   procedure TRowCache.ClearCache;
414   begin
415    FreeImages(true);
416 +  SetLength(FList,0);
417   end;
418  
419   function TRowCache.Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap;
# Line 466 | Line 469 | begin
469    until false;
470   end;
471  
472 + procedure TRowCache.InvalidateRowImage(RecNo: integer);
473 + begin
474 +  Dec(RecNo); {adjust to zero base}
475 +  if (RecNo < 0) or (RecNo >= Length(FList)) then
476 +    Exit;
477 +
478 +  if FList[RecNo].FState = rcPresent then
479 +  begin
480 +    FList[RecNo].FBitmap.Free;
481 +    FList[RecNo].FState := rcEmpty;
482 +  end;
483 + end;
484 +
485   function TRowCache.IsEmpty(RecNo: integer): boolean;
486   begin
487    Dec(RecNo);
# Line 508 | Line 524 | end;
524  
525   { TDBControlGrid }
526  
527 + function TDBControlGrid.ActiveControl: TControl;
528 + var AParent: TWinControl;
529 + begin
530 +  Result := nil;
531 +  AParent := Parent;
532 +  while (AParent <> nil) and  not (AParent is TCustomForm) do
533 +    AParent := AParent.Parent;
534 +  if (AParent <> nil) and (AParent is TCustomForm)then
535 +      Result := TCustomForm(AParent).ActiveControl;
536 + end;
537 +
538   procedure TDBControlGrid.EmptyGrid;
539   var
540    OldFixedRows: Integer;
541   begin
542    OldFixedRows := FixedRows;
543    Clear;
544 +  FRowCache.ClearCache;
545    RowCount := OldFixedRows + 1;
546    if dgpIndicator in FOptions then
547      ColWidths[0]:=12;
# Line 594 | Line 622 | begin
622    aRow := integer(Data);
623    FInCacheRefresh := true;
624    if assigned(FDataLink.DataSet) then
625 <    FDatalink.DataSet.MoveBy(aRow - FDrawRow)
625 >    FDatalink.DataSet.MoveBy(aRow - FDrawRow);
626   end;
627  
628   procedure TDBControlGrid.DoSetupDrawPanel(Data: PtrInt);
# Line 630 | Line 658 | end;
658   procedure TDBControlGrid.KeyDownHandler(Sender: TObject; var Key: Word;
659    Shift: TShiftState);
660   var Done: boolean;
661 +    AControl: TControl;
662   begin
663    if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus then
664    begin
665 +    AControl := ActiveControl;
666 +    if (AControl <> nil) and (AControl is TCustomComboBox)
667 +                         and ((Key in [VK_UP,VK_DOWN]) or
668 +                         (TCustomComboBox(AControl).DroppedDown and (Key = VK_RETURN)) or
669 +                         ((TCustomComboBox(AControl).Text <> '') and (Key =  VK_ESCAPE))) then
670 +      Exit; {ignore these keys if we are in a  combobox}
671 +
672 +    if (AControl <> nil) and (AControl is TCustomMemo)
673 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo}
674 +
675      Done := false;
676      if assigned(FOnKeyDownHander) then
677        OnKeyDownHander(Sender,Key,Shift,Done);
# Line 663 | Line 702 | end;
702  
703   procedure TDBControlGrid.OnDataSetChanged(aDataSet: TDataSet);
704   begin
705 <  if (aDataSet.State = dsBrowse) and (FLastRecordCount >  GetRecordCount) then
705 >  if aDataSet.State = dsBrowse then
706    begin
707 <    {must be delete}
708 <    FRowCache.MarkAsDeleted(FSelectedRecNo);
709 <    Dec(FSelectedRow);
707 >    if GetRecordCount = 0 then
708 >    begin
709 >      {Must be closed/reopened}
710 >      FRowCache.ClearCache;
711 >      FSelectedRow := 0;
712 >    end
713 >    else
714 >    if FLastRecordCount >  GetRecordCount then
715 >    begin
716 >      {must be delete}
717 >      FRowCache.MarkAsDeleted(FSelectedRecNo);
718 >      Dec(FSelectedRow);
719 >    end;
720      LayoutChanged;
721    end;
722    FLastRecordCount := GetRecordCount;
723    if aDataSet.State = dsInsert then
724 +  begin
725      FRequiredRecNo := aDataSet.RecNo + 1;
726 +    Application.QueueAsyncCall(@DoSelectNext,0);
727 +  end;
728    UpdateActive
729   end;
730  
# Line 761 | Line 813 | begin
813       RemoveFreeNotification(FDrawPanel);
814       FDrawPanel.RemoveAllHandlersOfObject(self);
815       theForm := Parent;
816 <     while not (theForm is TCustomForm) and (theForm.Parent <> nil) do
816 >     while not ((theForm is TCustomForm) or (theForm is TCustomFrame))
817 >                           and (theForm.Parent <> nil) do
818         theForm := theForm.Parent;
819       FDrawPanel.Parent := theForm;
820    end;
# Line 778 | Line 831 | begin
831         FDrawPanel.Visible := false;
832        FRowCache.Height := FDrawPanel.Height;
833        FRowCache.Width := FDrawPanel.Width;
834 <      AddHandlerOnResize(@OnDrawPanelResize);
834 >      FDrawPanel.AddHandlerOnResize(@OnDrawPanelResize);
835        FreeNotification(FDrawPanel);
836      end;
837    except
# Line 1066 | Line 1119 | begin
1119    FDataLink.DataSet.MoveBy(integer(Data) - FDataLink.DataSet.RecNo);
1120   end;
1121  
1122 + procedure TDBControlGrid.DoSelectNext(Data: PtrInt);
1123 + begin
1124 +  FDataLink.DataSet.MoveBy(1);
1125 + end;
1126 +
1127   procedure TDBControlGrid.DrawAllRows;
1128   begin
1129    inherited DrawAllRows;
# Line 1116 | Line 1174 | begin
1174    if aCol < FixedCols then
1175       DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false)
1176    else
1177 +  if FDrawPanel = nil then
1178 +    DrawFillRect(Canvas,aRect)    else
1179    if not FDrawingActiveRecord and FDataLink.Active then
1180        DoDrawRow(aRow,aRect,aState);
1181    {if we are drawing the active record then this is rendered by the Draw Panel
# Line 1361 | Line 1421 | begin
1421      FInCacheRefresh := false;
1422      FCacheRefreshQueued := false;
1423      Row := FixedRows;
1424 +    FDrawingActiveRecord := false;
1425 +    FSelectedRecNo := 0;
1426 +    FSelectedRow := 0;
1427 +    FRequiredRecNo := 0;
1428    end;
1429    FRowCache.UseAlternateColors := AlternateColor <> Color;
1430    FRowCache.AltColorStartNormal := AltColorStartNormal;
# Line 1550 | Line 1614 | begin
1614    PrevRow := Row;
1615    Row := FDrawRow;
1616    if not FInCacheRefresh then
1617 +  begin
1618      FSelectedRow := FDrawRow;
1619 +    if FDatalink.DataSet.State <> dsInsert then
1620 +      FRowCache.InvalidateRowImage(FSelectedRecNo);
1621 +  end;
1622    InvalidateRow(PrevRow);
1623    SetupDrawPanel(FDrawRow);
1624   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines