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; |
285 |
|
|
286 |
|
implementation |
287 |
|
|
288 |
< |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue; |
288 |
> |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit; |
289 |
|
|
290 |
|
{ TDBControlGridDataLink } |
291 |
|
|
300 |
|
|
301 |
|
function TRowCache.Render(Control: TWinControl): TBitmap; |
302 |
|
var Container: TBitmap; |
302 |
– |
Msg: TLMPaint; |
303 |
|
begin |
304 |
|
Container := TBitmap.Create; |
305 |
|
try |
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; |
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; |
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; |
471 |
|
until false; |
472 |
|
end; |
473 |
|
|
474 |
+ |
procedure TRowCache.InvalidateRowImage(RecNo: integer); |
475 |
+ |
begin |
476 |
+ |
Dec(RecNo); {adjust to zero base} |
477 |
+ |
if (RecNo < 0) or (RecNo >= Length(FList)) then |
478 |
+ |
Exit; |
479 |
+ |
|
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; |
487 |
+ |
|
488 |
|
function TRowCache.IsEmpty(RecNo: integer): boolean; |
489 |
|
begin |
490 |
|
Dec(RecNo); |
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; |
597 |
|
and ValidDataSet and FDatalink.DataSet.CanModify; |
598 |
|
end; |
599 |
|
|
570 |
– |
|
600 |
|
procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect; |
601 |
|
aState: TGridDrawState); |
602 |
|
var CachedRow: TBitmap; |
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); |
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); |
701 |
|
and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then |
702 |
|
begin |
703 |
|
RecNo := aDataSet.RecNo; |
658 |
– |
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; |
820 |
|
RemoveFreeNotification(FDrawPanel); |
821 |
|
FDrawPanel.RemoveAllHandlersOfObject(self); |
822 |
|
theForm := Parent; |
823 |
< |
while not (theForm is TCustomForm) and (theForm.Parent <> nil) do |
823 |
> |
while not ((theForm is TCustomForm) or (theForm is TCustomFrame)) |
824 |
> |
and (theForm.Parent <> nil) do |
825 |
|
theForm := theForm.Parent; |
826 |
|
FDrawPanel.Parent := theForm; |
827 |
|
end; |
838 |
|
FDrawPanel.Visible := false; |
839 |
|
FRowCache.Height := FDrawPanel.Height; |
840 |
|
FRowCache.Width := FDrawPanel.Width; |
841 |
< |
AddHandlerOnResize(@OnDrawPanelResize); |
841 |
> |
FDrawPanel.AddHandlerOnResize(@OnDrawPanelResize); |
842 |
|
FreeNotification(FDrawPanel); |
843 |
|
end; |
844 |
|
except |
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 |
1182 |
|
if aCol < FixedCols then |
1183 |
|
DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false) |
1184 |
|
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 |
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; |
1623 |
|
PrevRow := Row; |
1624 |
|
Row := FDrawRow; |
1625 |
|
if not FInCacheRefresh then |
1626 |
+ |
begin |
1627 |
|
FSelectedRow := FDrawRow; |
1628 |
+ |
if FDatalink.DataSet.State <> dsInsert then |
1629 |
+ |
FRowCache.InvalidateRowImage(FSelectedRecNo); |
1630 |
+ |
end; |
1631 |
|
InvalidateRow(PrevRow); |
1632 |
|
SetupDrawPanel(FDrawRow); |
1633 |
|
end; |
1689 |
|
FDataLink.Free; |
1690 |
|
end; |
1691 |
|
if assigned(FRowCache) then FRowCache.Free; |
1692 |
+ |
Application.RemoveAsyncCalls(self); |
1693 |
|
inherited Destroy; |
1694 |
|
end; |
1695 |
|
|
1728 |
|
end; |
1729 |
|
|
1730 |
|
end. |
1731 |
+ |
|