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; |
152 |
|
FLastMouseButton: TMouseButton; |
153 |
|
FLastMouseShiftState: TShiftState; |
154 |
|
|
155 |
+ |
function ActiveControl: TControl; |
156 |
|
procedure EmptyGrid; |
157 |
|
function GetDataSource: TDataSource; |
158 |
|
function GetRecordCount: Integer; |
238 |
|
property Color; |
239 |
|
property Constraints; |
240 |
|
property DataSource: TDataSource read GetDataSource write SetDataSource; |
239 |
– |
property DefaultRowHeight; |
241 |
|
property DefaultPositionAtEnd: boolean read FDefaultPositionAtEnd write FDefaultPositionAtEnd; |
242 |
|
property DragCursor; |
243 |
|
property DragMode; |
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; |
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); |
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; |
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); |
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); |
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; |
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; |
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 |
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 |
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; |
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; |