1 |
+ |
|
2 |
|
{ |
3 |
|
/*************************************************************************** |
4 |
|
DBControlGrid.pas |
153 |
|
FLastMouseButton: TMouseButton; |
154 |
|
FLastMouseShiftState: TShiftState; |
155 |
|
|
156 |
+ |
function ActiveControl: TControl; |
157 |
|
procedure EmptyGrid; |
158 |
|
function GetDataSource: TDataSource; |
159 |
|
function GetRecordCount: Integer; |
286 |
|
|
287 |
|
implementation |
288 |
|
|
289 |
< |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue; |
289 |
> |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit; |
290 |
|
|
291 |
|
{ TDBControlGridDataLink } |
292 |
|
|
301 |
|
|
302 |
|
function TRowCache.Render(Control: TWinControl): TBitmap; |
303 |
|
var Container: TBitmap; |
302 |
– |
Msg: TLMPaint; |
304 |
|
begin |
305 |
|
Container := TBitmap.Create; |
306 |
|
try |
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; |
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; |
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; |
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; |
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; |
598 |
|
and ValidDataSet and FDatalink.DataSet.CanModify; |
599 |
|
end; |
600 |
|
|
583 |
– |
|
601 |
|
procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect; |
602 |
|
aState: TGridDrawState); |
603 |
|
var CachedRow: TBitmap; |
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) |
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); |
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); |
703 |
|
and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then |
704 |
|
begin |
705 |
|
RecNo := aDataSet.RecNo; |
671 |
– |
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; |
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 |
1184 |
|
if aCol < FixedCols then |
1185 |
|
DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false) |
1186 |
|
else |
1187 |
< |
if FDrawPanel = nil then |
1188 |
< |
DrawFillRect(Canvas,aRect) 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 |
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; |
1691 |
|
FDataLink.Free; |
1692 |
|
end; |
1693 |
|
if assigned(FRowCache) then FRowCache.Free; |
1694 |
+ |
Application.RemoveAsyncCalls(self); |
1695 |
|
inherited Destroy; |
1696 |
|
end; |
1697 |
|
|
1730 |
|
end; |
1731 |
|
|
1732 |
|
end. |
1733 |
+ |
|