mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 17:56:16 +02:00
LCL: Cancel edit in grids and validate entry for TDrawGrid. Issue #27328, patch from Michl.
git-svn-id: trunk@55901 -
This commit is contained in:
parent
da96cd01b1
commit
ec6a7b1e82
@ -1011,6 +1011,7 @@ type
|
|||||||
procedure DrawRow(aRow: Integer); virtual;
|
procedure DrawRow(aRow: Integer); virtual;
|
||||||
procedure EditButtonClicked(Sender: TObject);
|
procedure EditButtonClicked(Sender: TObject);
|
||||||
procedure EditordoGetValue; virtual;
|
procedure EditordoGetValue; virtual;
|
||||||
|
procedure EditordoResetValue; virtual;
|
||||||
procedure EditordoSetValue; virtual;
|
procedure EditordoSetValue; virtual;
|
||||||
function EditorCanAcceptKey(const ch: TUTF8Char): boolean; virtual;
|
function EditorCanAcceptKey(const ch: TUTF8Char): boolean; virtual;
|
||||||
function EditorIsReadOnly: boolean; virtual;
|
function EditorIsReadOnly: boolean; virtual;
|
||||||
@ -1312,6 +1313,7 @@ type
|
|||||||
|
|
||||||
TCustomDrawGrid=class(TCustomGrid)
|
TCustomDrawGrid=class(TCustomGrid)
|
||||||
private
|
private
|
||||||
|
FEditorRow, FEditorCol: Integer;
|
||||||
FOnColRowDeleted: TgridOperationEvent;
|
FOnColRowDeleted: TgridOperationEvent;
|
||||||
FOnColRowExchanged: TgridOperationEvent;
|
FOnColRowExchanged: TgridOperationEvent;
|
||||||
FOnColRowInserted: TGridOperationEvent;
|
FOnColRowInserted: TGridOperationEvent;
|
||||||
@ -1326,6 +1328,7 @@ type
|
|||||||
FOnSetEditText: TSetEditEvent;
|
FOnSetEditText: TSetEditEvent;
|
||||||
function CellNeedsCheckboxBitmaps(const aCol,aRow: Integer): boolean;
|
function CellNeedsCheckboxBitmaps(const aCol,aRow: Integer): boolean;
|
||||||
procedure DrawCellCheckboxBitmaps(const aCol,aRow: Integer; const aRect: TRect);
|
procedure DrawCellCheckboxBitmaps(const aCol,aRow: Integer; const aRect: TRect);
|
||||||
|
function GetEditorValue(ACol, ARow: Integer): String;
|
||||||
protected
|
protected
|
||||||
FGrid: TVirtualGrid;
|
FGrid: TVirtualGrid;
|
||||||
procedure CalcCellExtent(acol, aRow: Integer; var aRect: TRect); virtual;
|
procedure CalcCellExtent(acol, aRow: Integer; var aRect: TRect); virtual;
|
||||||
@ -1338,6 +1341,7 @@ type
|
|||||||
procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override;
|
procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override;
|
||||||
procedure DrawCellAutonumbering(aCol,aRow: Integer; aRect: TRect; const aValue: string); virtual;
|
procedure DrawCellAutonumbering(aCol,aRow: Integer; aRect: TRect; const aValue: string); virtual;
|
||||||
procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect); override;
|
procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect); override;
|
||||||
|
function GetCells(ACol, ARow: Integer): string; override;
|
||||||
procedure GetCheckBoxState(const aCol, aRow:Integer; var aState:TCheckboxState); virtual;
|
procedure GetCheckBoxState(const aCol, aRow:Integer; var aState:TCheckboxState); virtual;
|
||||||
function GetEditMask(aCol, aRow: Longint): string; override;
|
function GetEditMask(aCol, aRow: Longint): string; override;
|
||||||
function GetEditText(aCol, aRow: Longint): string; override;
|
function GetEditText(aCol, aRow: Longint): string; override;
|
||||||
@ -1494,6 +1498,7 @@ type
|
|||||||
property OnStartDrag;
|
property OnStartDrag;
|
||||||
property OnTopleftChanged;
|
property OnTopleftChanged;
|
||||||
property OnUTF8KeyPress;
|
property OnUTF8KeyPress;
|
||||||
|
property OnValidateEntry;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1611,6 +1616,7 @@ type
|
|||||||
property OnTopleftChanged;
|
property OnTopleftChanged;
|
||||||
property OnUserCheckboxBitmap;
|
property OnUserCheckboxBitmap;
|
||||||
property OnUTF8KeyPress;
|
property OnUTF8KeyPress;
|
||||||
|
property OnValidateEntry;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCustomStringGrid = class;
|
TCustomStringGrid = class;
|
||||||
@ -7319,6 +7325,12 @@ begin
|
|||||||
Key := 0;
|
Key := 0;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
VK_ESCAPE:
|
||||||
|
begin
|
||||||
|
EditordoResetValue;
|
||||||
|
EditorHide;
|
||||||
|
Key := 0;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
if FEditorKey and (not PreserveRowAutoInserted) then
|
if FEditorKey and (not PreserveRowAutoInserted) then
|
||||||
FRowAutoInserted:=False;
|
FRowAutoInserted:=False;
|
||||||
@ -8265,6 +8277,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomGrid.EditordoResetValue;
|
||||||
|
var
|
||||||
|
msg: TGridMessage;
|
||||||
|
begin
|
||||||
|
if (FEditor<>nil) and FEditor.Visible then begin
|
||||||
|
Msg.LclMsg.msg:=GM_SETVALUE;
|
||||||
|
Msg.grid:=Self;
|
||||||
|
Msg.Col:=FCol;
|
||||||
|
Msg.Row:=FRow;
|
||||||
|
Msg.Value:=FEditorOldValue;
|
||||||
|
FEditor.Dispatch(Msg);
|
||||||
|
SetEditText(Msg.Col, Msg.Row, Msg.Value);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomGrid.EditordoSetValue;
|
procedure TCustomGrid.EditordoSetValue;
|
||||||
var
|
var
|
||||||
msg: TGridMessage;
|
msg: TGridMessage;
|
||||||
@ -10277,6 +10304,21 @@ begin
|
|||||||
DrawGridCheckboxBitmaps(aCol, aRow, aRect, aState);
|
DrawGridCheckboxBitmaps(aCol, aRow, aRect, aState);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomDrawGrid.GetEditorValue(ACol, ARow: Integer): String;
|
||||||
|
var
|
||||||
|
msg: TGridMessage;
|
||||||
|
begin
|
||||||
|
if Assigned(Editor) and Editor.Visible then begin
|
||||||
|
Msg.LclMsg.msg:=GM_GETVALUE;
|
||||||
|
Msg.grid:=Self;
|
||||||
|
Msg.Col:=ACol;
|
||||||
|
Msg.Row:=ARow;
|
||||||
|
Msg.Value:='';
|
||||||
|
Editor.Dispatch(Msg);
|
||||||
|
Result:=Msg.Value;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomDrawGrid.CalcCellExtent(acol, aRow: Integer; var aRect: TRect);
|
procedure TCustomDrawGrid.CalcCellExtent(acol, aRow: Integer; var aRect: TRect);
|
||||||
begin
|
begin
|
||||||
//
|
//
|
||||||
@ -10341,6 +10383,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomDrawGrid.GetCells(ACol, ARow: Integer): string;
|
||||||
|
begin
|
||||||
|
Result:=inherited GetCells(ACol, ARow);
|
||||||
|
if (ACol = FEditorCol) and (ARow = FEditorRow) then
|
||||||
|
Result:=GetEditorValue(ACol, ARow);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomDrawGrid.GetCheckBoxState(const aCol, aRow: Integer;
|
procedure TCustomDrawGrid.GetCheckBoxState(const aCol, aRow: Integer;
|
||||||
var aState: TCheckboxState);
|
var aState: TCheckboxState);
|
||||||
begin
|
begin
|
||||||
@ -10423,6 +10472,9 @@ function TCustomDrawGrid.GetEditText(aCol, aRow: Longint): string;
|
|||||||
begin
|
begin
|
||||||
result:='';
|
result:='';
|
||||||
if assigned(OnGetEditText) then OnGetEditText(self, aCol, aRow, Result);
|
if assigned(OnGetEditText) then OnGetEditText(self, aCol, aRow, Result);
|
||||||
|
FEditorOldValue:=Result;
|
||||||
|
FEditorCol:=aCol;
|
||||||
|
FEditorRow:=aRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomDrawGrid.GridMouseWheel(shift: TShiftState; Delta: Integer);
|
procedure TCustomDrawGrid.GridMouseWheel(shift: TShiftState; Delta: Integer);
|
||||||
|
Loading…
Reference in New Issue
Block a user