added button for dialog items in TTIGrid

git-svn-id: trunk@6579 -
This commit is contained in:
mattias 2005-01-13 23:02:30 +00:00
parent b37ea578b9
commit 952977c295
6 changed files with 265 additions and 108 deletions

View File

@ -4,7 +4,8 @@ object Form1: TForm1
ClientWidth = 400
OnCreate = Form1Create
OnDestroy = Form1Destroy
PixelsPerInch = 90
OnMouseDown = Form1MouseDown
PixelsPerInch = 75
HorzScrollBar.Page = 401
VertScrollBar.Page = 301
Left = 290
@ -15,11 +16,12 @@ object Form1: TForm1
BorderStyle = bsSingle
Color = clWhite
DefaultRowHeight = 24
Filter = [tkInteger, tkChar, tkEnumeration, tkFloat, tkSString, tkLString, tkAString, tkWString, tkVariant, tkWChar, tkBool, tkInt64, tkQWord]
FixedColor = clBtnFace
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goSmoothScroll]
Left = 40
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]
Left = 32
Height = 166
Top = 64
Top = 16
Width = 316
ColWidths = (
64
@ -36,4 +38,16 @@ object Form1: TForm1
24
)
end
object TICheckBox1: TTICheckBox
AutoSize = True
Caption = 'goColSizing'
Link.TIObject = TIGrid1
Link.TIPropertyName = 'Options'
Link.TIElementName = 'goColSizing'
TabStop = True
Left = 34
Height = 23
Top = 216
Width = 90
end
end

View File

@ -3,12 +3,19 @@
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'Cl'
+'ientWidth'#3#144#1#8'OnCreate'#7#11'Form1Create'#9'OnDestroy'#7#12'Form1Des'
+'troy'#13'PixelsPerInch'#2'Z'#18'HorzScrollBar.Page'#3#145#1#18'VertScrollBa'
+'r.Page'#3'-'#1#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3#163#0#5'Width'#3#144
+#1#0#7'TTIGrid'#7'TIGrid1'#11'BorderStyle'#7#8'bsSingle'#5'Color'#7#7'clWhit'
+'e'#16'DefaultRowHeight'#2#24#10'FixedColor'#7#9'clBtnFace'#7'Options'#11#15
+'goFixedVertLine'#15'goFixedHorzLine'#10'goVertLine'#10'goHorzLine'#13'goRan'
+'geSelect'#14'goSmoothScroll'#0#4'Left'#2'('#6'Height'#3#166#0#3'Top'#2'@'#5
+'Width'#3'<'#1#9'ColWidths'#1#2'@'#2'@'#2'@'#2'@'#2'@'#0#10'RowHeights'#1#2
+#24#2#24#2#24#2#24#2#24#0#0#0#0
+'troy'#11'OnMouseDown'#7#14'Form1MouseDown'#13'PixelsPerInch'#2'K'#18'HorzSc'
+'rollBar.Page'#3#145#1#18'VertScrollBar.Page'#3'-'#1#4'Left'#3'"'#1#6'Height'
+#3','#1#3'Top'#3#163#0#5'Width'#3#144#1#0#7'TTIGrid'#7'TIGrid1'#11'BorderSty'
+'le'#7#8'bsSingle'#5'Color'#7#7'clWhite'#16'DefaultRowHeight'#2#24#6'Filter'
+#11#9'tkInteger'#6'tkChar'#13'tkEnumeration'#7'tkFloat'#9'tkSString'#9'tkLSt'
+'ring'#9'tkAString'#9'tkWString'#9'tkVariant'#7'tkWChar'#6'tkBool'#7'tkInt64'
+#7'tkQWord'#0#10'FixedColor'#7#9'clBtnFace'#7'Options'#11#15'goFixedVertLine'
+#15'goFixedHorzLine'#10'goVertLine'#10'goHorzLine'#13'goRangeSelect'#9'goEdi'
+'ting'#18'goAlwaysShowEditor'#14'goSmoothScroll'#0#4'Left'#2' '#6'Height'#3
+#166#0#3'Top'#2#16#5'Width'#3'<'#1#9'ColWidths'#1#2'@'#2'@'#2'@'#2'@'#2'@'#0
+#10'RowHeights'#1#2#24#2#24#2#24#2#24#2#24#0#0#0#11'TTICheckBox'#11'TICheckB'
+'ox1'#8'AutoSize'#9#7'Caption'#6#11'goColSizing'#13'Link.TIObject'#7#7'TIGri'
+'d1'#19'Link.TIPropertyName'#6#7'Options'#18'Link.TIElementName'#6#11'goColS'
+'izing'#7'TabStop'#9#4'Left'#2'"'#6'Height'#2#23#3'Top'#3#216#0#5'Width'#2'Z'
+#0#0#0
]);

View File

@ -5,7 +5,8 @@ unit ExampleGrid1;
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, RTTIGrids;
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, RTTIGrids,
RTTICtrls;
type
@ -25,9 +26,12 @@ type
{ TForm1 }
TForm1 = class(TForm)
TICheckBox1: TTICheckBox;
TIGrid1: TTIGrid;
procedure Form1Create(Sender: TObject);
procedure Form1Destroy(Sender: TObject);
procedure Form1MouseDown(Sender: TOBject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
@ -71,6 +75,12 @@ begin
MyCollection.Free;
end;
procedure TForm1.Form1MouseDown(Sender: TOBject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
WriteLn('------------------------------');
end;
initialization
{$I examplegrid1.lrs}

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="5"/>
<General>
<Flags>
@ -8,7 +9,7 @@
<SaveOnlyProjectUnits Value="True"/>
</Flags>
<MainUnit Value="0"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="1"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
<Title Value="exampleprojectgrid1"/>
@ -18,19 +19,19 @@
<Filename Value="exampleprojectgrid1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ExampleProjectGrid1"/>
<UsageCount Value="20"/>
<UsageCount Value="22"/>
</Unit0>
<Unit1>
<CursorPos X="15" Y="48"/>
<CursorPos X="18" Y="59"/>
<EditorIndex Value="0"/>
<Filename Value="examplegrid1.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<Loaded Value="True"/>
<ResourceFilename Value="examplegrid1.lrs"/>
<TopLine Value="29"/>
<TopLine Value="39"/>
<UnitName Value="ExampleGrid1"/>
<UsageCount Value="20"/>
<UsageCount Value="22"/>
</Unit1>
</Units>
<PublishOptions>
@ -56,7 +57,7 @@
</RequiredPackages>
</ProjectOptions>
<CompilerOptions>
<Version Value="3"/>
<Version Value="4"/>
<SearchPaths>
<SrcPath Value="$(LazarusDir)/lcl/;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)/"/>
</SearchPaths>

View File

@ -79,15 +79,16 @@ type
property Visible;
end;
TTICustomGrid = class;
{ TTIGridProperty }
TTIGridProperty = class
private
FEditor: TPropertyEditor;
FEditorControl: TWinControl;
FButtonEditorControl: TWinControl;
FGrid: TTICustomGrid;
FIndex: integer;
FTitle: string;
@ -100,6 +101,7 @@ type
destructor Destroy; override;
function PropInfo: PPropInfo;
function GetEditorControl: TWinControl;
function GetButtonEditorControl: TWinControl;
function PropName: string;
public
property Editor: TPropertyEditor read FEditor;
@ -170,6 +172,7 @@ type
FTIStates: TTIGridStates;
FTIObjectCount: integer;
FProperties: TList;
FExtraBtnEditor: TWinControl;
function GetProperties(Index: integer): TTIGridProperty;
function GetPropertyCount: integer;
procedure SetAliasPropertyNames(const AValue: TAliasStrings);
@ -180,12 +183,20 @@ type
procedure SetPropertyOrder(const AValue: TStrings);
procedure SetShowOnlyProperties(const AValue: TStrings);
procedure SetTIOptions(const NewOptions: TTIGridOptions);
{$IFDEF DebugEditor}
procedure DebugEditor(msg: String; aEditor: TWinControl);
{$ENDIF}
protected
procedure RebuildGridLayout; virtual;
procedure AddHeaderPropertyEditor(Prop: TPropertyEditor);
procedure BeforeMoveSelection(const DCol,DRow: Integer); override;
procedure CalcCellExtent(aCol, aRow: Integer; var aRect: TRect); virtual;
procedure DoEditorHide; override;
procedure DoEditorShow; override;
procedure DrawCell(aCol, aRow: Integer; aRect: TRect;
aState: TGridDrawState); override;
procedure CalcCellExtent(aCol, aRow: Integer; var aRect: TRect); virtual;
procedure EditorPosChanged(aEditor: TWinControl);
procedure EditorWidthChanged(aCol, aWidth: Integer); override;
procedure HeaderClick(IsColumn: Boolean; index: Integer); override;
procedure HeaderSized(IsColumn: Boolean; index: Integer); override;
procedure GetAutoFillColumnInfo(const Index: Integer;
@ -193,8 +204,8 @@ type
procedure SelectEditor; override;
procedure DoEditorControlKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState); virtual;
procedure EditorHide; override;
procedure WriteCellText(aRect: TRect; const aText: string);
procedure UnlinkPropertyEditor(aEditor: TWinControl);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -471,6 +482,16 @@ begin
if tgoShowOnlyProperties in ChangedOptions then ReloadTIList;
end;
{$IFDEF DebugEditor}
procedure TTICustomGrid.DebugEditor(msg: String; aEditor: TWinControl);
begin
Write(Msg,': Editor=');
if aEditor=nil then Write('nil')
else Write(AEditor.className);
WriteLn;
end;
{$ENDIF}
procedure TTICustomGrid.ReloadTIList;
begin
if tgsRebuildingTIList in FTIStates then exit;
@ -565,6 +586,21 @@ begin
FProperties.Add(NewProperty);
end;
procedure TTICustomGrid.BeforeMoveSelection(const DCol, DRow: Integer);
begin
inherited BeforeMoveSelection(DCol, DRow);
if (FExtraBtnEditor<>nil)and(FExtraBtnEditor.Visible) then begin
{$IFDEF DebugEditor}
DebugEditor('BeforeMoveSelection: ', FExtraBtnEditor);
{$ENDIF}
EditorHiding := True;
UnlinkPropertyEditor(FExtraBtnEditor);
FExtraBtnEditor.Visible := false;
FExtraBtnEditor.Parent := nil;
EditorHiding := false;
end;
end;
procedure TTICustomGrid.DrawCell(aCol, aRow: Integer; aRect: TRect;
aState: TGridDrawState);
begin
@ -578,6 +614,27 @@ begin
DrawCellGrid(aCol,aRow,aRect,aState);
end;
procedure TTICustomGrid.EditorPosChanged(aEditor: TWinControl);
var
NewRect, ARect: TRect;
begin
// position
NewRect:=CellRect(Col,Row);
if FExtraBtnEditor<>nil then begin
ARect := NewRect;
ARect.Left := ARect.Right-20;
Dec(NewRect.Right,20);
FExtraBtnEditor.BoundsRect := ARect;
end;
aEditor.BoundsRect:=NewRect;
end;
procedure TTICustomGrid.EditorWidthChanged(aCol, aWidth: Integer);
begin
if (aCol=0) and (aWidth=0) then ;
EditorPosChanged(Editor);
end;
procedure TTICustomGrid.CalcCellExtent(aCol, aRow: Integer; var aRect: TRect);
begin
if (aCol=0) and (aRow=0) and (ARect.Left=0) then ;
@ -612,7 +669,6 @@ var
ObjectIndex: integer;
PropertyIndex: integer;
CellType: TTIGridCellType;
NewRect: TRect;
PropLink: TCustomPropertyLink;
CurObject: TPersistent;
CurProp: TTIGridProperty;
@ -623,9 +679,13 @@ begin
if CellType=tgctValue then begin
CurProp:=Properties[PropertyIndex];
NewEditor:=CurProp.GetEditorControl;
// position
NewRect:=CellRect(Col,Row);
NewEditor.BoundsRect:=NewRect;
FExtraBtnEditor := CurProp.GetButtonEditorControl;
{$IFDEF DebugEditor}
DebugEditor('SelectEditor', NewEditor);
DebugEditor('SelectEditor extra', FExtraBtnEditor);
{$ENDIF}
EditorPosChanged(NewEditor);
// connect to cell property
PropLink:=GetPropertyLinkOfComponent(NewEditor);
if PropLink<>nil then begin
@ -633,10 +693,24 @@ begin
PropName:=CurProp.PropName;
PropLink.SetObjectAndProperty(CurObject,PropName);
end;
if FExtraBtnEditor<>nil then begin
PropLink:=GetPropertyLinkOfComponent(FExtraBtnEditor);
if PropLink<>nil then begin
CurObject:=GetTIObject(ObjectIndex);
PropName:=CurProp.PropName;
PropLink.SetObjectAndProperty(CurObject,PropName);
end;
if FExtraBtnEditor.Parent = nil then
FExtraBtnEditor.Visible := False;
FExtraBtnEditor.Parent := Self;
end;
if Assigned(OnSelectEditor) then
OnSelectEditor(Self,Col,Row,NewEditor);
end;
end else
FExtraBtnEditor := nil;
Editor:=NewEditor;
// options
//EditorOptions := EO_HOOKKEYPRESS or EO_HOOKKEYDOWN or EO_HOOKKEYDOWN;
end;
procedure TTICustomGrid.DoEditorControlKeyUp(Sender: TObject; var Key: Word;
@ -695,16 +769,28 @@ begin
end;
end;
procedure TTICustomGrid.EditorHide;
var
PropLink: TCustomPropertyLink;
procedure TTICustomGrid.DoEditorHide;
begin
if Editor<>nil then begin
PropLink:=GetPropertyLinkOfComponent(Editor);
if PropLink<>nil then
PropLink.SetObjectAndProperty(nil,'');
{$IFDEF DebugEditor}
DebugEditor('doEditorHide', Editor);
{$ENDIF}
UnlinkPropertyEditor(Editor);
inherited DoEditorHide;
end;
procedure TTICustomGrid.DoEditorShow;
begin
{$IFDEF DebugEditor}
DebugEditor('doEditorShow', Editor);
{$ENDIF}
inherited DoEditorShow;
if FExtraBtnEditor<>nil then begin
{$IFDEF DebugEditor}
DebugEditor('doEditorShow Extra', FExtraBtnEditor);
{$ENDIF}
FExtraBtnEditor.Parent := Self;
FExtraBtnEditor.Visible := True;
end;
inherited EditorHide;
end;
procedure TTICustomGrid.WriteCellText(aRect: TRect; const aText: string);
@ -718,6 +804,17 @@ begin
Canvas.TextRect(aRect,ARect.Left,ARect.Top,aText);
end;
procedure TTICustomGrid.UnlinkPropertyEditor(aEditor: TWinControl);
var
PropLink: TCustomPropertyLink;
begin
if not (csDestroying in componentState) then begin
PropLink:=GetPropertyLinkOfComponent(aEditor);
if PropLink<>nil then
PropLink.SetObjectAndProperty(nil,'');
end;
end;
constructor TTICustomGrid.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
@ -1096,6 +1193,7 @@ end;
destructor TTIGridProperty.Destroy;
begin
FreeThenNil(FButtonEditorControl);
FreeThenNil(FEditorControl);
FreeThenNil(FEditor);
inherited Destroy;
@ -1112,6 +1210,7 @@ var
Attr: TPropertyAttributes;
begin
if FEditorControl=nil then begin
FButtonEditorControl := nil;
if Assigned(Grid.OnCreateCellEditor) then
Grid.OnCreateCellEditor(Self,FEditorControl);
if FEditorControl=nil then begin
@ -1120,9 +1219,11 @@ begin
Attr:=Editor.GetAttributes;
if (paDialog in Attr) and (paReadOnly in Attr) then
EditorClass:=TTIButton
else if (paValueList in Attr) then
EditorClass:=TTIComboBox
else
else if (paValueList in Attr) then begin
EditorClass:=TTIComboBox;
if (paDialog in Attr) then
FButtonEditorControl := TTIButton.Create(FGrid);
end else
EditorClass:=TTIEdit;
end;
FEditorControl:=EditorClass.Create(FGrid);
@ -1131,10 +1232,17 @@ begin
FEditorControl.AutoSize:=false;
if Assigned(Grid.OnInitCellEditor) then
Grid.OnInitCellEditor(Self,FEditorControl);
if Assigned(Grid.OnInitCellEditor) and (FButtonEditorControl<>nil) then
Grid.OnInitCellEditor(Self,FButtonEditorControl);
end;
Result:=FEditorControl;
end;
function TTIGridProperty.GetButtonEditorControl: TWinControl;
begin
result := FButtonEditorControl;
end;
function TTIGridProperty.PropName: string;
begin
Result:=PropInfo^.Name;

View File

@ -441,6 +441,9 @@ type
end;
type
{ TCustomGrid }
TCustomGrid=class(TCustomControl)
private
FAutoAdvance: TAutoAdvance;
@ -499,6 +502,7 @@ type
function CheckTopLeft(aCol,aRow: Integer; CheckCols,CheckRows: boolean): boolean;
procedure SetAutoFillColumns(const AValue: boolean);
procedure SetColumns(const AValue: TGridColumns);
procedure SetEditorOptions(const AValue: Integer);
procedure SetFlat(const AValue: Boolean);
procedure SetFocusRectVisible(const AValue: Boolean);
procedure SetTitleFont(const AValue: TFont);
@ -595,6 +599,8 @@ type
procedure DblClick; override;
procedure DefineProperties(Filer: TFiler); override;
procedure DestroyHandle; override;
procedure DoEditorHide; virtual;
procedure DoEditorShow; virtual;
procedure DoExit; override;
procedure DoEnter; override;
procedure DoOnChangeBounds; override;
@ -618,6 +624,7 @@ type
function EditorIsReadOnly: boolean; virtual;
procedure EditorHide; virtual;
procedure EditorShow(const SelAll: boolean); virtual;
procedure EditorWidthChanged(aCol,aWidth: Integer); virtual;
procedure GetAutoFillColumnInfo(const Index: Integer; var aMin,aMax,aPriority: Integer); dynamic;
function GetFixedcolor: TColor; virtual;
function GetSelectedColor: TColor; virtual;
@ -701,7 +708,9 @@ type
property Editor: TWinControl read FEditor write SetEditor;
property EditorMode: Boolean read FEditorMode write EditorSetMode;
property EditorKey: boolean read FEditorKey write FEditorKey;
property EditorShowing: boolean read FEditorShowing;
property EditorHiding: boolean read FEditorHiding write FEditorHiding;
property EditorOptions: Integer read FEditorOptions write SetEditorOptions;
property EditorShowing: boolean read FEditorShowing write FEditorShowing;
property ExtendedColSizing: boolean read FExtendedColSizing write FExtendedColSizing;
property ExtendedRowSizing: boolean read FExtendedRowSizing write FExtendedRowSizing;
property FixedCols: Integer read FFixedCols write SetFixedCols default 1;
@ -1209,8 +1218,9 @@ begin
case Msg of
CM_BASE..CM_MOUSEWHEEL:
case Msg of
CM_MOUSEENTER: DebugLn(hex, 'CM_MOUSEENTER');
CM_MOUSELEAVE: DebugLn(hex, 'CM_MOUSELEAVE');
CM_MOUSEENTER,CM_MOUSELEAVE:;
//CM_MOUSEENTER: DebugLn(hex, 'CM_MOUSEENTER');
//CM_MOUSELEAVE: DebugLn(hex, 'CM_MOUSELEAVE');
CM_TEXTCHANGED: DebugLn(hex, 'CM_TEXTCHANGED');
CM_PARENTCTL3DCHANGED: DebugLn(hex, 'CM_PARENTCTL3DCHANGED');
CM_UIACTIVATE: DebugLn(hex, 'CM_UIACTIVATE');
@ -1425,7 +1435,8 @@ begin
if Avalue<>Integer(FCols[ACol]) then begin
SetRawColWidths(ACol, Avalue);
VisualChange;
if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then EditorPos;
if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then
EditorWidthChanged(aCol, aValue);
ColWidthsChanged;
end;
end;
@ -1503,33 +1514,8 @@ begin
Msg.Grid:=Self;
Msg.Options:=0;
FEditor.Dispatch(Msg);
FEditorOptions:=Msg.Options;
if Msg.Options and EO_HOOKKEYDOWN = EO_HOOKKEYDOWN then begin
FEditor.OnKeyDown:=@EditorKeyDown;
end;
if Msg.Options and EO_HOOKKEYPRESS = EO_HOOKKEYPRESS then begin
FEditor.OnKeyPress := @EditorKeyPress;
end;
if Msg.Options and EO_HOOKKEYUP = EO_HOOKKEYUP then begin
FEditor.OnKeyUp := @EditorKeyUp;
end;
if Msg.Options and EO_HOOKEXIT = EO_HOOKEXIT then begin
FEditor.OnExit:=@EditorExit;
end;
{$IfDef EditorDbg}
DBGOut('SetEditor-> Editor=',FEditor.Name,' ');
if FEditorOptions and EO_AUTOSIZE = EO_AUTOSIZE then DBGOut('EO_AUTOSIZE ');
if FEditorOptions and EO_HOOKKEYDOWN = EO_HOOKKEYDOWN then DBGOut('EO_HOOKKEYDOWN ');
if FEditorOptions and EO_HOOKKEYPRESS = EO_HOOKKEYPRESS then DBGOut('EO_HOOKKEYPRESS ');
if FEditorOptions and EO_HOOKKEYUP = EO_HOOKKEYUP then DBGOut('EO_HOOKKEYUP ');
if FEditorOptions and EO_HOOKEXIT = EO_HOOKEXIT then DBGOut('EO_HOOKEXIT ');
if FEditorOptions and EO_SELECTALL= EO_SELECTALL then DBGOut('EO_SELECTALL ');
if FEditorOptions and EO_WANTCHAR = EO_WANTCHAR then DBGOut('EO_WANTCHAR ');
DebugLn;
{$Endif}
SetEditorOptions(Msg.Options);
end;
end;
@ -3023,6 +3009,39 @@ begin
FColumns.Assign(Avalue);
end;
procedure TCustomGrid.SetEditorOptions(const AValue: Integer);
begin
if FEditorOptions<>AValue then begin
if FEditor=nil then exit;
FEditorOptions:=AValue;
if FEditorOptions and EO_HOOKKEYDOWN = EO_HOOKKEYDOWN then begin
FEditor.OnKeyDown:=@EditorKeyDown;
end;
if FEditorOptions and EO_HOOKKEYPRESS = EO_HOOKKEYPRESS then begin
FEditor.OnKeyPress := @EditorKeyPress;
end;
if FEditorOptions and EO_HOOKKEYUP = EO_HOOKKEYUP then begin
FEditor.OnKeyUp := @EditorKeyUp;
end;
if FEditorOptions and EO_HOOKEXIT = EO_HOOKEXIT then begin
FEditor.OnExit:=@EditorExit;
end;
{$IfDef EditorDbg}
DBGOut('SetEditor-> Editor=',FEditor.Name,' ');
if FEditorOptions and EO_AUTOSIZE = EO_AUTOSIZE then DBGOut('EO_AUTOSIZE ');
if FEditorOptions and EO_HOOKKEYDOWN = EO_HOOKKEYDOWN then DBGOut('EO_HOOKKEYDOWN ');
if FEditorOptions and EO_HOOKKEYPRESS = EO_HOOKKEYPRESS then DBGOut('EO_HOOKKEYPRESS ');
if FEditorOptions and EO_HOOKKEYUP = EO_HOOKKEYUP then DBGOut('EO_HOOKKEYUP ');
if FEditorOptions and EO_HOOKEXIT = EO_HOOKEXIT then DBGOut('EO_HOOKEXIT ');
if FEditorOptions and EO_SELECTALL= EO_SELECTALL then DBGOut('EO_SELECTALL ');
if FEditorOptions and EO_WANTCHAR = EO_WANTCHAR then DBGOut('EO_WANTCHAR ');
DebugLn;
{$Endif}
end;
end;
procedure TCustomGrid.SetFlat(const AValue: Boolean);
begin
if FFlat=AValue then exit;
@ -3586,7 +3605,7 @@ begin
end;
end;
fGridState:=gsNormal;
{$IfDef dbgFocus}DebugLn('MouseUP END RND=',Random);{$Endif}
{$IfDef dbgFocus}DebugLn('MouseUP END RND=', FloatToStr(Random));{$Endif}
end;
procedure TCustomGrid.DblClick;
@ -3674,6 +3693,23 @@ begin
inherited DestroyHandle;
end;
procedure TCustomGrid.DoEditorHide;
begin
Editor.Visible:=False;
Editor.Parent:=nil;
LCLIntf.SetFocus(Self.Handle);
end;
procedure TCustomGrid.DoEditorShow;
begin
ScrollToCell(FCol,FRow);
EditorSetValue;
Editor.Parent:=Self;
Editor.Visible:=True;
LCLIntf.SetFocus(Editor.Handle);
InvalidateCell(FCol,FRow,True);
end;
procedure TCustomGrid.DoOnChangeBounds;
begin
inherited DoOnChangeBounds;
@ -3704,6 +3740,7 @@ begin
{$IfDef dbgFocus}DebugLn('DoEnter - EditorHiding');{$Endif}
end else begin
{$IfDef dbgFocus}DebugLn('DoEnter - Ext');{$Endif}
exit;
if EditorAlwaysShown then begin
SelectEditor;
if Feditor=nil then Invalidate
@ -3916,7 +3953,7 @@ begin
if (not Result) then Exit;
BeforeMoveSelection(DCol,DRow);
{$IfDef dbgFocus}DebugLn(' MoveExtend INIT FCol= ',FCol, ' FRow= ',FRow);{$Endif}
{$IfDef dbgFocus}DebugLn(' MoveExtend INIT FCol= ',IntToStr(FCol), ' FRow= ',IntToStr(FRow));{$Endif}
LastEditor:=Editor;
WasVis:=(LastEditor<>nil)and(LastEditor.Visible);
@ -3965,8 +4002,8 @@ begin
SelectEditor;
ProcessEditor(LastEditor,DCol,DRow,WasVis);
{$IfDef dbgFocus}DebugLn(' MoveExtend FIN FCol= ',FCol, ' FRow= ',FRow);{$Endif}
{$IfDef dbgFocus}DebugLn(' MoveExtend FIN FCol= ',IntToStr(FCol), ' FRow= ',IntToStr(FRow));{$Endif}
end;
function TCustomGrid.MoveNextAuto: boolean;
@ -4080,38 +4117,20 @@ var
WillVis: Boolean;
begin
WillVis:=(FEditor<>nil)and EditorAlwaysShown;
{$ifdef DbgFocus}
DebugLn(' ProcessEditor INIT WasVis=', BoolToStr(WasVis),' WillVis=', BoolToStr(WillVis));
{$endif}
if WillVis or WasVis then begin
if not WillVis then HideLastEditor else
if not WasVis then EditorShow(EditorAlwaysShown)
else begin
{
LastEditor.Visible:=False;
lastEditor.Parent:=nil;
FEditorMode:=False;
EditorShow;
}
HideLastEditor;
EditorShow(EditorAlwaysShown);
{
if LastEditor=FEditor then begin
// only to swap DCol<->FCol and DRow<->FRow
// Hide editor in old position
RestoreEditor;
EditordoGetValue;
RestoreEditor;
// Move Editor to new position and set its value
EditorPos;
EditordoSetValue;
end else begin
// Hide old editor type a
LastEditor.Visible:=False;
lastEditor.Parent:=nil;
// Show new editor type b
EditorShow;
end;
}
end;
end;
{$ifdef DbgFocus}
DebugLn(' ProcessEditor FIN');
{$endif}
end;
procedure TCustomGrid.BeforeMoveSelection(const DCol,DRow: Integer);
@ -4246,11 +4265,9 @@ begin
and Editor.Visible then
begin
FEditorMode:=False;
{$IfDef dbgFocus} DebugLn('EditorHide INIT FCol=',FCol,' FRow=',FRow);{$Endif}
{$IfDef dbgFocus} DebugLn('EditorHide [',Editor.ClassName,'] INIT FCol=',IntToStr(FCol),' FRow=',IntToStr(FRow));{$Endif}
FEditorHiding:=True;
Editor.Visible:=False;
Editor.Parent:=nil;
LCLIntf.SetFocus(Self.Handle);
DoEditorHide;
FEditorHiding:=False;
{$IfDef dbgFocus} DebugLn('EditorHide FIN'); {$Endif}
end;
@ -4265,15 +4282,10 @@ begin
if (goEditing in Options) and
not FEditorShowing and (Editor<>nil) and not Editor.Visible then
begin
{$IfDef dbgFocus} DebugLn('EditorShow INIT FCol=',FCol,' FRow=',FRow);{$Endif}
{$IfDef dbgFocus} DebugLn('EditorShow [',Editor.ClassName,']INIT FCol=',IntToStr(FCol),' FRow=',IntToStr(FRow));{$Endif}
FEditorMode:=True;
FEditorShowing:=True;
ScrollToCell(FCol,FRow);
EditorSetValue;
Editor.Parent:=Self;
Editor.Visible:=True;
LCLIntf.SetFocus(Editor.Handle);
InvalidateCell(FCol,FRow,True);
doEditorShow;
FEditorShowing:=False;
{$IfDef dbgFocus} DebugLn('EditorShow FIN');{$Endif}
if SelAll then
@ -4281,6 +4293,11 @@ begin
end;
end;
procedure TCustomGrid.EditorWidthChanged(aCol, aWidth: Integer);
begin
EditorPos;
end;
procedure TCustomGrid.EditorPos;
var
msg: TGridMessage;