📄 wwdbgrid.pas
字号:
end;
procedure TwwDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var value: string;
OldActive: integer;
EditableCell: Boolean;
lookupControl: TWinControl;
tempFld: TField;
tempRect,OrigRect: TRect;
procedure GetAbsolutePos(var ALeft, ATop: integer);
var curObject: TWinControl;
lastObject: TWinControl;
begin
curObject:= self;
lastObject:= self;
ALeft:= curObject.left;
ATop:= curObject.top;
while (curObject<>Nil) do begin
curObject:= curObject.parent;
if curObject is TCustomform then break;
if curObject.containsControl(lastObject) then begin
ALeft:= ALeft + curObject.left;
ATop:= ATop + curObject.top;
end;
end;
end;
function IsEditableCell(DataCol, DataRow: Integer;
const Value: string; AState: TGridDrawState): Boolean;
begin
Result := (gdSelected in AState) or
// ((DataRow=dbRow(Row)) and (dgRowSelectEditable in Options));
((DataRow=dbRow(Row)) and (PaintOptions.ActiveRecordColor<>clNone));
if Result then
begin
if not ((dgAlwaysShowSelection in Options) or
(FFocused and not IsDropDownGridFocused)) then Result:= False;
end;
end;
begin
if drawingCell then exit; { Avoid recursion }
drawingCell:= True;
if (row=ARow) and (col=ACol) and
// ShouldShowCustomControls and
isCustomEditCell(ACol, ARow, lookupControl) and
(ShouldShowCustomControls or (lookupControl is TwwExpandButton)) then
begin
currentCustomEdit:= lookupControl;
MakeCustomControlVisible:=True;
with Canvas do begin
EditableCell := IsEditableCell(ACol, dbRow(ARow), Value, AState);
if (gdSelected in AState) and (not (csDesigning in ComponentState)) then
begin
if (currentCustomEdit<>Nil) and (currentCustomEdit.parent=self) and
(ValidParentForm(Self).ActiveControl = currentCustomEdit) then
begin
{7/19/97 - Avoid flicker, previously checked BoundsRect}
TempRect:= ARect;
if AdjustBoundsRect(CurrentCustomEdit) then
InflateRect(TempRect, -1, -1);
if (currentCustomEdit.BoundsRect.left<>TempRect.Left) or
(currentCustomEdit.BoundsRect.right<>TempRect.right) then
begin
if Columns[dbCol(ACol)].DisableSizing then
begin
if TempRect.Right-TempRect.Left<currentCustomEdit.Width then
TempRect.Right:= TempRect.Left + currentCustomEdit.Width;
if TempRect.Bottom-TempRect.Top<currentCustomEdit.Height then
TempRect.Bottom:= TempRect.Top + currentCustomEdit.Height;
if tempRect.Top+ currentcustomEdit.height>Parent.ClientHeight then
begin
tempRect.Top:= ARect.Bottom-currentCustomedit.Height;
tempRect.Bottom:= ARect.Bottom;
end;
end;
{$ifdef wwDelphi4Up}
if (Canvas.CanvasOrientation = coRightToLeft) then { 9/25/98 - Support bidi mode }
begin
TempRect.Right := ClientWidth - ARect.Left;
TempRect.Left := tempRect.Right - (ARect.Right-ARect.Left) + 1;
end;
{$endif}
currentCustomEdit.BoundsRect:= TempRect;
end
end
else if EditableCell and (ValidParentForm(Self).ActiveControl = Self) then
begin
{ Clear buffer if changing rows so old value isn't drawn at all}
OldActive:= DataLink.ActiveRecord;
Value:= '';
try
DataLink.ActiveRecord:= dbRow(ARow)+RowOffset;
if wwIsClass(currentCustomEdit.classType, 'TwwDBCustomLookupCombo') then
begin
tempFld:= GetColField(dbCol(ACol));
if tempFld<>Nil then
value:= tempFld.asString
end
else value:= WideGetFieldValue(dbCol(ACol));
finally
DataLink.ActiveRecord:= OldActive;
end;
{ This is here for screen repainting reasons, otherwise screen is painted wrong then right. }
if not (currentcustomedit is TCustomRichEdit) and
not wwIsClass(currentCustomEdit.classType, 'TfcTreeCombo') and // 10/28/01 - Otherwise mapped values not respected
(currentCustomEdit is TCustomEdit) then // 1/29/01
TEdit(currentCustomEdit).Text:= Value;
if (currentCustomEdit.parent <> Self) then
begin
currentCustomEdit.parent:= Self;
wwSetBoolean(currentCustomEdit, 'ctl3D', False);
// TEdit(currentCustomEdit).ctl3d:= False;
if not wwIsClass(currentCustomEdit.classType, 'TwwDataInspector') then
// TEdit(currentCustomEdit).BorderStyle:= bsNone;
wwSetBorder(currentCustomEdit, False);
end;
{ 1/25/98 - Moved to after setting ctl3d and borderstyle }
TempRect:= ARect;
TempRect:= CellRect(Col, Row);
OrigRect:= TempRect;
if AdjustBoundsRect(CurrentCustomEdit) then
InflateRect(TempRect, -1, -1);
if not sameRect(currentCustomEdit.BoundsRect, TempRect) then begin
if Columns[dbCol(Col)].DisableSizing then
begin
if TempRect.Right-TempRect.Left<currentCustomEdit.Width then
TempRect.Right:= TempRect.Left + currentCustomEdit.Width;
if TempRect.Bottom-TempRect.Top<currentCustomEdit.Height then
TempRect.Bottom:= TempRect.Top + currentCustomEdit.Height;
if tempRect.Top+ currentcustomEdit.height>Parent.ClientHeight then
begin
tempRect.Top:= OrigRect.Bottom-currentCustomedit.Height;
tempRect.Bottom:=OrigRect.Bottom;
end;
end;
{$ifdef wwDelphi4Up}
if (Canvas.CanvasOrientation = coRightToLeft) then { 9/25/98 - Support bidi mode }
begin
TempRect.Right := ClientWidth - ARect.Left;
TempRect.Left := tempRect.Right - (ARect.Right-ARect.Left) +1;
end;
{$endif}
currentCustomEdit.BoundsRect := TempRect;
end;
drawingCell:= False;
exit;
end
end;
end;
end;
inherited DrawCell(ACol, ARow, ARect, AState);
{ Make cells 3D style }
// if DrawCellInfo.DefaultDrawHorzLines then
{ if DefaultDrawing then }Draw3DLines(ARect, ACol, ARow, AState);
drawingCell:= False;
end;
{ Override so checkboxes in grid don't show underlying text }
function TwwDBGrid.IsWWControl(ACol, ARow: integer): boolean;
var fldName: string;
ControlType, Parameters, tempName: string;
Apos: integer;
IsCustomControl: boolean;
IsDateTime: boolean;
begin
result:= False;
if not isValidCell(ACol, ARow) then exit;
fldName:= DataLink.fields[dbCol(ACol)].fieldName;
GetControlInfo(FldName, ControlType, Parameters);
IsCustomControl:= IsWWEditControl(ControlType);
//
// 3/18/06 - Support TimeStamp type for Auto - DateTimePicker
IsDateTime:=
(DataLink.Fields[dbCol(ACol)] is TDateTimeField) or
((DataLink.Fields[dbCol(ACol)]<>nil) and
(DataLink.Fields[dbCol(ACol)].DataType in [ftDate, ftDateTime, ftTimeStamp, ftTime]) );
result:= (ControlType='Bitmap') or (ControlType='ImageIndex') or
(ControlType='CheckBox') or IsCustomControl or
(not (ecoDisableDateTimePicker in EditControlOptions) and { Fix - 8/13/98 }
IsDateTime);
// (DataLink.fields[dbCol(ACol)] is TDateTimeField));
if isCustomControl then
begin
APos:= 1;
tempName:= strGetToken(Parameters, ';', APos);
if GetComponent(tempName)=nil then result:= false;
end;
end;
function TwwDBGrid.CanEditShow: Boolean;
begin
Result:= inherited CanEditShow;
if Result then
begin
if (dgAlwaysShowEditor in Options) and not Focused and
(inplaceEditor<>Nil) and not inplaceEditor.visible then
Result:= False {(ValidParentForm(Self).ActiveControl = Self)}
else if isWWControl(col, row) then result:= False
else if isMemoField(col, row) then result:= False;
end
end;
{ Update checkbox }
procedure TwwDBGrid.SetFieldValue(ACol: Integer; val: string);
begin
if (ACol >= 0) and Datalink.Active and (ACol < DataLink.FieldCount) then
Datalink.Fields[ACol].Text:= Val;
end;
function TwwDBGrid.IsRichEditCell(
col, row: integer;
var customEdit: TWinControl) : boolean;
var fldName: string;
i: integer;
controlType: TStrings;
APos: integer;
begin
result:= False;
if not isValidCell(col, row) then exit;
fldName:= DataLink.fields[dbCol(col)].fieldName;
{ 8/14/97 - Optimized logic to speed painting of grid }
controlType:= GetControlType;
for i:= 0 to ControlType.count-1 do begin
APos:= 1;
if strGetToken(controlType[i], ';', APos)<>fldName then continue;
if strGetToken(controlType[i], ';', APos)='RichEdit' then
begin
customEdit:= GetComponent(strGetToken(controlType[i], ';', APos));
result:= True;
break;
end
end
end;
//procedure TwwDBGrid.SetControlType(AFieldName: string; AComponentType: TwwFieldControlType;
// AParameters: string; AAlwaysPaints: boolean = False);
procedure TwwDBGrid.SetControlType(AFieldName: string; AComponentType: TwwFieldControlType;
AParameters: string);
var componentTypeStr: string;
customEdit: TWinControl;
TempComponent: TComponent;
begin
case AComponentType of
fctNone, fctField: componentTypeStr:= '';
fctURLLink: componentTypeStr:= 'URL-Link';
fctCustom, fctComboBox, fctLookupCombo, fctRichEdit: begin
{ 9/4/97 - fctRichEdit same path as customEdit}
componentTypeStr:=WW_DB_EDIT;
if AComponentType=fctRichEdit then componentTypeStr:= 'RichEdit';
customEdit:= GetComponent(AParameters); { 1/22/97 - Change customEdit properties immediately }
if (customEdit<>Nil) and
(ShouldShowCustomControls or (customEdit is TwwExpandButton)) then
// (not (ecoDisableCustomControls in EditControlOptions)) then
begin
customEdit.visible:= False;
// if (customEdit is TwwExpandButton) and
// (TwwExpandButton(customEdit).grid<>nil) then
// TwwExpandButton(customEdit).grid.visible:= false;
customEdit.parent:= self;
wwSetControlDataSource(customEdit, dataSource);
wwSetControlDataField(customEdit, AFieldName);
{ !!!!! Cheating casts to make protected properties public}
wwSetBoolean(customEdit, 'ctl3D', False);
// TwwDBEdit(customEdit).ctl3d:= False;
if AComponentType <> fctRichEdit then { 9/18/99 - Don't set font if richedit }
TwwDBEdit(customEdit).font:= self.font;
if not wwIsClass(CustomEdit.classType, 'TwwDataInspector') then
wwSetBorder(CustomEdit, False);
//TwwDBEdit(customEdit).BorderStyle:= bsNone;
// Don't support scrollbars for inspector as then text gets cutoff in csPaintCopyState
// If find way to support csPaintCopy, then we can remove this restriction
if wwIsClass(CustomEdit.classtype, 'TwwDataInspector') then
TDrawGrid(customedit).ScrollBars:= ssNone;
end
end;
fctCheckbox: componentTypeStr:= 'CheckBox';
fctBitmap: componentTypeStr:= 'Bitmap';
fctImageIndex: componentTypeStr:= 'ImageIndex';
else componentTypeStr:= '';
end;
if ControlInfoInDataSet then
begin
TempComponent:= Datasource.dataset;
if (DataSource.DataSet=nil) or (wwGetControlType(Datasource.dataset)=nil) then TempComponent:= self;
end
else TempComponent:= self;
// if AAlwaysPaints then AParameters:= AParameters+';T'
// else AParameters:= AParameters + ';F';
wwDataSet_SetControl(TempComponent,
AFieldName, componentTypeStr, AParameters);
end;
procedure TwwDBGrid.RefreshDisplay;
var CustomEdit: TWinControl;
begin
doneInitControls:= False;
InitControls;
LayoutChanged;
// 8/13/02 - Clear CurrentCustomEdit (this code deemed necessary if user
// changes control information when changing records).
// Otherwise if active column is being changed, the inplaceeditor
// can get disabled
if not
(isCustomEditCell(Col, Row, customEdit) and
(ShouldShowCustomControls or (customEdit is TwwExpandButton))) then
CurrentCustomEdit:=nil;
end;
{ Initialize controls to have the following attributes }
{ 1. This grid as parent
{ 2. Visible is False
{ 3. DataSource is this grid's datasource
{ 4. Set field later at time it is shown
}
{4/28/97 - Allow the same control to be attached more than once }
procedure TwwDBGrid.InitControls;
var
i: integer;
parts : TStrings;
dbLookupComboBox: TWinControl;
controlType: TStrings;
begin
if (doneInitcontrols) and not (csDesigning in ComponentState) then exit;
if (dataSource=Nil) then exit;
if (dataSource.dataSet=Nil) then exit;
if (csLoading in ComponentState) then exit;
if not GridIsLoaded then exit;
if (ecoDisableCustomControls in EditControlOptions) then exit;
parts:= TStringList.create;
with dataSource do begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -