1 |
+ |
|
2 |
|
{ |
3 |
|
/*************************************************************************** |
4 |
|
DBControlGrid.pas |
68 |
|
} |
69 |
|
|
70 |
|
type |
70 |
– |
TRowCacheState = (rcEmpty,rcPresent,rcDeleted); |
71 |
– |
TRowDetails = record |
72 |
– |
FState: TRowCacheState; |
73 |
– |
FAlternateColor: boolean; |
74 |
– |
FBitmap: TBitmap; |
75 |
– |
end; |
76 |
– |
|
71 |
|
{ TRowCache } |
72 |
|
|
73 |
|
TRowCache = class |
74 |
|
private |
75 |
+ |
type |
76 |
+ |
TRowCacheState = (rcEmpty,rcPresent,rcDeleted); |
77 |
+ |
TRowDetails = record |
78 |
+ |
FState: TRowCacheState; |
79 |
+ |
FAlternateColor: boolean; |
80 |
+ |
FBitmap: TBitmap; |
81 |
+ |
end; |
82 |
+ |
|
83 |
+ |
private |
84 |
|
FAltColorStartNormal: boolean; |
85 |
|
FHeight: integer; |
86 |
|
FList: array of TRowDetails; |
288 |
|
|
289 |
|
implementation |
290 |
|
|
291 |
< |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue; |
291 |
> |
uses LCLType, Math, LCLIntf, Forms, LCLMessageGlue, EditBtn, MaskEdit; |
292 |
|
|
293 |
|
{ TDBControlGridDataLink } |
294 |
|
|
303 |
|
|
304 |
|
function TRowCache.Render(Control: TWinControl): TBitmap; |
305 |
|
var Container: TBitmap; |
303 |
– |
Msg: TLMPaint; |
306 |
|
begin |
307 |
|
Container := TBitmap.Create; |
308 |
|
try |
368 |
|
for i := StartIndex to Length(FList) - 1 do |
369 |
|
begin |
370 |
|
FList[i].FState := rcEmpty; |
371 |
+ |
FList[i].FBitmap := nil; |
372 |
|
FList[i].FAlternateColor := altColor; |
373 |
|
if UseAlternateColors then |
374 |
|
altColor := not altColor; |
420 |
|
end; |
421 |
|
|
422 |
|
function TRowCache.Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap; |
420 |
– |
var i: integer; |
423 |
|
begin |
424 |
|
Dec(RecNo); {Adust to zero base} |
425 |
|
ExtendCache(RecNo + 1); |
426 |
|
FList[RecNo].FState := rcPresent; |
427 |
+ |
if FList[RecNo].FBitmap <> nil then |
428 |
+ |
FList[RecNo].FBitmap.Free; |
429 |
|
FList[RecNo].FBitmap := Render(Control); |
430 |
|
Result := FList[RecNo].FBitmap; |
431 |
|
end; |
482 |
|
if FList[RecNo].FState = rcPresent then |
483 |
|
begin |
484 |
|
FList[RecNo].FBitmap.Free; |
485 |
+ |
FList[RecNo].FBitmap := nil; |
486 |
|
FList[RecNo].FState := rcEmpty; |
487 |
|
end; |
488 |
|
end; |
599 |
|
and ValidDataSet and FDatalink.DataSet.CanModify; |
600 |
|
end; |
601 |
|
|
597 |
– |
|
602 |
|
procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect; |
603 |
|
aState: TGridDrawState); |
604 |
|
var CachedRow: TBitmap; |
611 |
|
begin |
612 |
|
FCacheRefreshQueued := true; |
613 |
|
Application.QueueAsyncCall(@DoMoveRecord,PtrInt(aRow)); |
614 |
< |
end |
614 |
> |
end; |
615 |
> |
Canvas.FillRect(aRect); |
616 |
|
end |
617 |
|
else |
618 |
|
Canvas.Draw(aRect.Left,aRect.Top,CachedRow) |
677 |
|
if (AControl <> nil) and (AControl is TCustomMemo) |
678 |
|
and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo} |
679 |
|
|
680 |
+ |
if (AControl <> nil) and (AControl is TCustomGrid) |
681 |
+ |
and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo} |
682 |
+ |
|
683 |
+ |
if (AControl <> nil) and ((AControl is TDateEdit) or (AControl is TCustomMaskedit)) |
684 |
+ |
and (Key in [VK_RETURN,VK_UP,VK_DOWN, |
685 |
+ |
VK_ESCAPE,VK_LEFT,VK_RIGHT]) then Exit; {Ignore Return in a CustomMemo} |
686 |
|
Done := false; |
687 |
|
if assigned(FOnKeyDownHander) then |
688 |
|
OnKeyDownHander(Sender,Key,Shift,Done); |
704 |
|
and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then |
705 |
|
begin |
706 |
|
RecNo := aDataSet.RecNo; |
696 |
– |
Application.ProcessMessages; {A couple of trips round the message loop seems to be necessary} |
707 |
|
Application.ProcessMessages; |
708 |
|
if RecNo = aDataSet.RecNo then {Guard against sudden changes} |
709 |
< |
FRowCache.Add2Cache(aDataSet.RecNo,FDrawPanel); |
709 |
> |
FRowCache.Add2Cache(RecNo,FDrawPanel); |
710 |
|
end; |
711 |
|
end; |
712 |
|
|
865 |
|
|
866 |
|
procedure TDBControlGrid.SetupDrawPanel(aRow: integer); |
867 |
|
begin |
868 |
+ |
if FDrawPanel = nil then Exit; |
869 |
|
if ValidDataSet and FRowCache.AlternateColor[FDataLink.DataSet.RecNo] then |
870 |
|
FDrawPanel.Color := AlternateColor |
871 |
|
else |
1177 |
|
result := dsInactive; |
1178 |
|
end; |
1179 |
|
|
1169 |
– |
var |
1170 |
– |
DataCol: Integer; |
1180 |
|
begin |
1181 |
|
PrepareCanvas(aCol, aRow, aState); |
1182 |
|
|
1183 |
|
if aCol < FixedCols then |
1184 |
|
DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false) |
1185 |
|
else |
1186 |
< |
if FDrawPanel = nil then |
1187 |
< |
DrawFillRect(Canvas,aRect) else |
1186 |
> |
if (FDrawPanel = nil) or not FDataLink.Active then |
1187 |
> |
DrawFillRect(Canvas,aRect) |
1188 |
> |
else |
1189 |
|
if not FDrawingActiveRecord and FDataLink.Active then |
1190 |
|
DoDrawRow(aRow,aRect,aState); |
1191 |
|
{if we are drawing the active record then this is rendered by the Draw Panel |
1287 |
|
procedure TDBControlGrid.KeyDown(var Key: Word; Shift: TShiftState); |
1288 |
|
type |
1289 |
|
TOperation=(opMoveBy,opCancel,opAppend,opInsert,opDelete); |
1280 |
– |
var |
1281 |
– |
DeltaCol,DeltaRow: Integer; |
1290 |
|
|
1291 |
|
procedure DoOnKeyDown; |
1292 |
|
begin |
1688 |
|
FDataLink.Free; |
1689 |
|
end; |
1690 |
|
if assigned(FRowCache) then FRowCache.Free; |
1691 |
+ |
Application.RemoveAsyncCalls(self); |
1692 |
|
inherited Destroy; |
1693 |
|
end; |
1694 |
|
|
1727 |
|
end; |
1728 |
|
|
1729 |
|
end. |
1730 |
+ |
|