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 29 by tony, Sat May 9 11:37:49 2015 UTC vs.
Revision 80 by tony, Mon Jan 1 11:31:07 2018 UTC

# Line 152 | 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 284 | Line 285 | end;
285  
286   implementation
287  
288 < uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue;
288 > uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit;
289  
290   { TDBControlGridDataLink }
291  
# Line 299 | Line 300 | end;
300  
301   function TRowCache.Render(Control: TWinControl): TBitmap;
302   var Container: TBitmap;
302     Msg: TLMPaint;
303   begin
304    Container := TBitmap.Create;
305    try
# Line 365 | Line 365 | begin
365      for i := StartIndex to Length(FList) - 1 do
366      begin
367        FList[i].FState := rcEmpty;
368 +      FList[i].FBitmap := nil;
369        FList[i].FAlternateColor := altColor;
370        if UseAlternateColors then
371          altColor := not altColor;
# Line 412 | 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 420 | Line 422 | begin
422    Dec(RecNo); {Adust to zero base}
423    ExtendCache(RecNo + 1);
424    FList[RecNo].FState := rcPresent;
425 +  if FList[RecNo].FBitmap <> nil then
426 +    FList[RecNo].FBitmap.Free;
427    FList[RecNo].FBitmap := Render(Control);
428    Result := FList[RecNo].FBitmap;
429   end;
# Line 476 | Line 480 | begin
480    if FList[RecNo].FState = rcPresent then
481    begin
482      FList[RecNo].FBitmap.Free;
483 +    FList[RecNo].FBitmap := nil;
484      FList[RecNo].FState := rcEmpty;
485    end;
486   end;
# Line 522 | Line 527 | end;
527  
528   { TDBControlGrid }
529  
530 + function TDBControlGrid.ActiveControl: TControl;
531 + var AParent: TWinControl;
532 + begin
533 +  Result := nil;
534 +  AParent := Parent;
535 +  while (AParent <> nil) and  not (AParent is TCustomForm) do
536 +    AParent := AParent.Parent;
537 +  if (AParent <> nil) and (AParent is TCustomForm)then
538 +      Result := TCustomForm(AParent).ActiveControl;
539 + end;
540 +
541   procedure TDBControlGrid.EmptyGrid;
542   var
543    OldFixedRows: Integer;
544   begin
545    OldFixedRows := FixedRows;
546    Clear;
547 +  FRowCache.ClearCache;
548    RowCount := OldFixedRows + 1;
549    if dgpIndicator in FOptions then
550      ColWidths[0]:=12;
# Line 580 | Line 597 | begin
597      and ValidDataSet and FDatalink.DataSet.CanModify;
598   end;
599  
583
600   procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect;
601    aState: TGridDrawState);
602   var CachedRow: TBitmap;
# Line 608 | Line 624 | begin
624    aRow := integer(Data);
625    FInCacheRefresh := true;
626    if assigned(FDataLink.DataSet) then
627 <    FDatalink.DataSet.MoveBy(aRow - FDrawRow)
627 >    FDatalink.DataSet.MoveBy(aRow - FDrawRow);
628   end;
629  
630   procedure TDBControlGrid.DoSetupDrawPanel(Data: PtrInt);
# Line 644 | Line 660 | end;
660   procedure TDBControlGrid.KeyDownHandler(Sender: TObject; var Key: Word;
661    Shift: TShiftState);
662   var Done: boolean;
663 +    AControl: TControl;
664   begin
665    if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus then
666    begin
667 +    AControl := ActiveControl;
668 +    if (AControl <> nil) and (AControl is TCustomComboBox)
669 +                         and ((Key in [VK_UP,VK_DOWN]) or
670 +                         (TCustomComboBox(AControl).DroppedDown and (Key = VK_RETURN)) or
671 +                         ((TCustomComboBox(AControl).Text <> '') and (Key =  VK_ESCAPE))) then
672 +      Exit; {ignore these keys if we are in a  combobox}
673 +
674 +    if (AControl <> nil) and (AControl is TCustomMemo)
675 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo}
676 +
677 +    if (AControl <> nil) and (AControl is TCustomGrid)
678 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo}
679 +
680 +    if (AControl <> nil) and ((AControl is TDateEdit) or (AControl is TCustomMaskedit))
681 +                         and (Key in [VK_RETURN,VK_UP,VK_DOWN,
682 +                               VK_ESCAPE,VK_LEFT,VK_RIGHT]) then Exit; {Ignore Return in a CustomMemo}
683      Done := false;
684      if assigned(FOnKeyDownHander) then
685        OnKeyDownHander(Sender,Key,Shift,Done);
# Line 668 | Line 701 | begin
701        and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then
702    begin
703      RecNo := aDataSet.RecNo;
671    Application.ProcessMessages;  {A couple of trips round the message loop seems to be necessary}
704      Application.ProcessMessages;
705      if RecNo = aDataSet.RecNo then   {Guard against sudden changes}
706 <      FRowCache.Add2Cache(aDataSet.RecNo,FDrawPanel);
706 >      FRowCache.Add2Cache(RecNo,FDrawPanel);
707    end;
708   end;
709  
710   procedure TDBControlGrid.OnDataSetChanged(aDataSet: TDataSet);
711   begin
712 <  if (aDataSet.State = dsBrowse) and (FLastRecordCount >  GetRecordCount) then
712 >  if aDataSet.State = dsBrowse then
713    begin
714 <    {must be delete}
715 <    FRowCache.MarkAsDeleted(FSelectedRecNo);
716 <    Dec(FSelectedRow);
714 >    if GetRecordCount = 0 then
715 >    begin
716 >      {Must be closed/reopened}
717 >      FRowCache.ClearCache;
718 >      FSelectedRow := 0;
719 >    end
720 >    else
721 >    if FLastRecordCount >  GetRecordCount then
722 >    begin
723 >      {must be delete}
724 >      FRowCache.MarkAsDeleted(FSelectedRecNo);
725 >      Dec(FSelectedRow);
726 >    end;
727      LayoutChanged;
728    end;
729    FLastRecordCount := GetRecordCount;
# Line 820 | Line 862 | end;
862  
863   procedure TDBControlGrid.SetupDrawPanel(aRow: integer);
864   begin
865 +  if FDrawPanel = nil then Exit;
866    if ValidDataSet and FRowCache.AlternateColor[FDataLink.DataSet.RecNo] then
867      FDrawPanel.Color := AlternateColor
868    else
# Line 1139 | Line 1182 | begin
1182    if aCol < FixedCols then
1183       DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false)
1184    else
1185 <  if FDrawPanel = nil then
1186 <    DrawFillRect(Canvas,aRect)    else
1185 >  if (FDrawPanel = nil) or not FDataLink.Active then
1186 >    DrawFillRect(Canvas,aRect)
1187 >  else
1188    if not FDrawingActiveRecord and FDataLink.Active then
1189        DoDrawRow(aRow,aRect,aState);
1190    {if we are drawing the active record then this is rendered by the Draw Panel
# Line 1386 | Line 1430 | begin
1430      FInCacheRefresh := false;
1431      FCacheRefreshQueued := false;
1432      Row := FixedRows;
1433 +    FDrawingActiveRecord := false;
1434 +    FSelectedRecNo := 0;
1435 +    FSelectedRow := 0;
1436 +    FRequiredRecNo := 0;
1437    end;
1438    FRowCache.UseAlternateColors := AlternateColor <> Color;
1439    FRowCache.AltColorStartNormal := AltColorStartNormal;
# Line 1641 | Line 1689 | begin
1689      FDataLink.Free;
1690    end;
1691    if assigned(FRowCache) then FRowCache.Free;
1692 +  Application.RemoveAsyncCalls(self);
1693    inherited Destroy;
1694   end;
1695  
# Line 1679 | Line 1728 | begin
1728   end;
1729  
1730   end.
1731 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines