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 |
309 |
|
Container.SetSize(Control.Width,Control.Height); |
310 |
+ |
Container.Canvas.Brush.Color := control.Color; |
311 |
|
Control.PaintTo(Container.Canvas,0,0); |
312 |
|
except |
313 |
|
Container.Free; |
369 |
|
for i := StartIndex to Length(FList) - 1 do |
370 |
|
begin |
371 |
|
FList[i].FState := rcEmpty; |
372 |
+ |
FList[i].FBitmap := nil; |
373 |
|
FList[i].FAlternateColor := altColor; |
374 |
|
if UseAlternateColors then |
375 |
|
altColor := not altColor; |
421 |
|
end; |
422 |
|
|
423 |
|
function TRowCache.Add2Cache(RecNo: Longint; Control: TWinControl): TBitmap; |
420 |
– |
var i: integer; |
424 |
|
begin |
425 |
|
Dec(RecNo); {Adust to zero base} |
426 |
|
ExtendCache(RecNo + 1); |
427 |
|
FList[RecNo].FState := rcPresent; |
428 |
+ |
if FList[RecNo].FBitmap <> nil then |
429 |
+ |
FList[RecNo].FBitmap.Free; |
430 |
|
FList[RecNo].FBitmap := Render(Control); |
431 |
|
Result := FList[RecNo].FBitmap; |
432 |
|
end; |
483 |
|
if FList[RecNo].FState = rcPresent then |
484 |
|
begin |
485 |
|
FList[RecNo].FBitmap.Free; |
486 |
+ |
FList[RecNo].FBitmap := nil; |
487 |
|
FList[RecNo].FState := rcEmpty; |
488 |
|
end; |
489 |
|
end; |
600 |
|
and ValidDataSet and FDatalink.DataSet.CanModify; |
601 |
|
end; |
602 |
|
|
597 |
– |
|
603 |
|
procedure TDBControlGrid.DoDrawRow(aRow: integer; aRect: TRect; |
604 |
|
aState: TGridDrawState); |
605 |
|
var CachedRow: TBitmap; |
612 |
|
begin |
613 |
|
FCacheRefreshQueued := true; |
614 |
|
Application.QueueAsyncCall(@DoMoveRecord,PtrInt(aRow)); |
615 |
< |
end |
615 |
> |
end; |
616 |
> |
Canvas.FillRect(aRect); |
617 |
|
end |
618 |
|
else |
619 |
|
Canvas.Draw(aRect.Left,aRect.Top,CachedRow) |
666 |
|
var Done: boolean; |
667 |
|
AControl: TControl; |
668 |
|
begin |
669 |
< |
if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus then |
669 |
> |
if Visible and assigned(FDrawPanel) and FDrawPanel.Visible and FWeHaveFocus |
670 |
> |
and (Self.Owner=Screen.ActiveForm) then |
671 |
|
begin |
672 |
|
AControl := ActiveControl; |
673 |
|
if (AControl <> nil) and (AControl is TCustomComboBox) |
679 |
|
if (AControl <> nil) and (AControl is TCustomMemo) |
680 |
|
and (Key in [VK_RETURN,VK_UP,VK_DOWN]) then Exit; {Ignore Return in a CustomMemo} |
681 |
|
|
682 |
+ |
if (AControl <> nil) and (AControl is TCustomGrid) |
683 |
+ |
and (Key in [VK_RETURN,VK_UP,VK_DOWN,VK_TAB]) then Exit; {Ignore Return in a CustomMemo} |
684 |
+ |
|
685 |
+ |
if (AControl <> nil) and ((AControl is TDateEdit) or (AControl is TCustomMaskedit)) |
686 |
+ |
and (Key in [VK_RETURN,VK_UP,VK_DOWN, |
687 |
+ |
VK_ESCAPE,VK_LEFT,VK_RIGHT]) then Exit; {Ignore Return in a CustomMemo} |
688 |
|
Done := false; |
689 |
|
if assigned(FOnKeyDownHander) then |
690 |
|
OnKeyDownHander(Sender,Key,Shift,Done); |
706 |
|
and (FModified or (FRowCache.IsEmpty(aDataSet.RecNo))) then |
707 |
|
begin |
708 |
|
RecNo := aDataSet.RecNo; |
696 |
– |
Application.ProcessMessages; {A couple of trips round the message loop seems to be necessary} |
709 |
|
Application.ProcessMessages; |
710 |
|
if RecNo = aDataSet.RecNo then {Guard against sudden changes} |
711 |
< |
FRowCache.Add2Cache(aDataSet.RecNo,FDrawPanel); |
711 |
> |
FRowCache.Add2Cache(RecNo,FDrawPanel); |
712 |
|
end; |
713 |
|
end; |
714 |
|
|
867 |
|
|
868 |
|
procedure TDBControlGrid.SetupDrawPanel(aRow: integer); |
869 |
|
begin |
870 |
+ |
if FDrawPanel = nil then Exit; |
871 |
|
if ValidDataSet and FRowCache.AlternateColor[FDataLink.DataSet.RecNo] then |
872 |
|
FDrawPanel.Color := AlternateColor |
873 |
|
else |
1179 |
|
result := dsInactive; |
1180 |
|
end; |
1181 |
|
|
1169 |
– |
var |
1170 |
– |
DataCol: Integer; |
1182 |
|
begin |
1183 |
|
PrepareCanvas(aCol, aRow, aState); |
1184 |
|
|
1185 |
|
if aCol < FixedCols then |
1186 |
|
DrawIndicator(Canvas,aRow, aRect,GetDataSetState,false) |
1187 |
|
else |
1188 |
< |
if FDrawPanel = nil then |
1189 |
< |
DrawFillRect(Canvas,aRect) else |
1188 |
> |
if (FDrawPanel = nil) or not FDataLink.Active then |
1189 |
> |
DrawFillRect(Canvas,aRect) |
1190 |
> |
else |
1191 |
|
if not FDrawingActiveRecord and FDataLink.Active then |
1192 |
|
DoDrawRow(aRow,aRect,aState); |
1193 |
|
{if we are drawing the active record then this is rendered by the Draw Panel |
1289 |
|
procedure TDBControlGrid.KeyDown(var Key: Word; Shift: TShiftState); |
1290 |
|
type |
1291 |
|
TOperation=(opMoveBy,opCancel,opAppend,opInsert,opDelete); |
1280 |
– |
var |
1281 |
– |
DeltaCol,DeltaRow: Integer; |
1292 |
|
|
1293 |
|
procedure DoOnKeyDown; |
1294 |
|
begin |
1690 |
|
FDataLink.Free; |
1691 |
|
end; |
1692 |
|
if assigned(FRowCache) then FRowCache.Free; |
1693 |
+ |
if not (csDesigning in ComponentState) then |
1694 |
+ |
Application.RemoveOnKeyDownBeforeHandler( @KeyDownHandler ); |
1695 |
+ |
Application.RemoveAsyncCalls(self); |
1696 |
|
inherited Destroy; |
1697 |
|
end; |
1698 |
|
|
1731 |
|
end; |
1732 |
|
|
1733 |
|
end. |
1734 |
+ |
|