mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 21:39:21 +02:00
LCL, fix valedit display problems, issue #16667
git-svn-id: trunk@32595 -
This commit is contained in:
parent
781ddc516d
commit
f5d82af704
106
lcl/valedit.pas
106
lcl/valedit.pas
@ -55,17 +55,15 @@ type
|
|||||||
procedure AdjustColumnWidths; virtual;
|
procedure AdjustColumnWidths; virtual;
|
||||||
procedure AdjustRowCount; virtual;
|
procedure AdjustRowCount; virtual;
|
||||||
procedure ColWidthsChanged; override;
|
procedure ColWidthsChanged; override;
|
||||||
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
|
|
||||||
AState: TGridDrawState); override;
|
|
||||||
function GetEditText(ACol, ARow: Integer): string; override;
|
function GetEditText(ACol, ARow: Integer): string; override;
|
||||||
function GetCell(ACol, ARow: Integer): string;
|
function GetCells(ACol, ARow: Integer): string; override;
|
||||||
|
procedure SetCells(ACol, ARow: Integer; const AValue: string); override;
|
||||||
procedure SetEditText(ACol, ARow: Integer; const Value: string); override;
|
procedure SetEditText(ACol, ARow: Integer; const Value: string); override;
|
||||||
procedure SetCell(ACol, ARow: Integer; const Value: string);
|
procedure TitlesChanged(Sender: TObject);
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
property Modified;
|
property Modified;
|
||||||
property Cells[ACol, ARow: Integer]: string read GetCell write SetCell;
|
|
||||||
property Keys[Index: Integer]: string read GetKey write SetKey;
|
property Keys[Index: Integer]: string read GetKey write SetKey;
|
||||||
property Values[const Key: string]: string read GetValue write SetValue;
|
property Values[const Key: string]: string read GetValue write SetValue;
|
||||||
published
|
published
|
||||||
@ -201,9 +199,17 @@ constructor TValueListEditor.Create(AOwner: TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FStrings := TStringList.Create; // ToDo: create a specialized type.
|
FStrings := TStringList.Create; // ToDo: create a specialized type.
|
||||||
|
// NOTE: here there should be a handler for Strings.OnChange event
|
||||||
|
// so changing externally any value (or count) would be
|
||||||
|
// reflected in grid
|
||||||
FTitleCaptions := TStringList.Create;
|
FTitleCaptions := TStringList.Create;
|
||||||
Columns.Add;
|
TStringList(FTitleCaptions).OnChange := @TitlesChanged;
|
||||||
Columns.Add;
|
with Columns.Add do
|
||||||
|
Title.Caption := 'Key';
|
||||||
|
with Columns.Add do begin
|
||||||
|
Title.Caption := 'Value';
|
||||||
|
DropDownRows := 8;
|
||||||
|
end;
|
||||||
// or: ColCount:=2;
|
// or: ColCount:=2;
|
||||||
// inherited RowCount := 2;
|
// inherited RowCount := 2;
|
||||||
FixedCols := 0;
|
FixedCols := 0;
|
||||||
@ -214,7 +220,6 @@ begin
|
|||||||
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
|
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
|
||||||
goColSizing, goEditing, goAlwaysShowEditor, goThumbTracking];
|
goColSizing, goEditing, goAlwaysShowEditor, goThumbTracking];
|
||||||
FDisplayOptions := [doColumnTitles, doAutoColResize, doKeyColFixed];
|
FDisplayOptions := [doColumnTitles, doAutoColResize, doKeyColFixed];
|
||||||
ShowColumnTitles;
|
|
||||||
Col := 1;
|
Col := 1;
|
||||||
FDropDownRows := 8;
|
FDropDownRows := 8;
|
||||||
end;
|
end;
|
||||||
@ -303,45 +308,6 @@ end;
|
|||||||
procedure TValueListEditor.SetTitleCaptions(const AValue: TStrings);
|
procedure TValueListEditor.SetTitleCaptions(const AValue: TStrings);
|
||||||
begin
|
begin
|
||||||
FTitleCaptions.Assign(AValue);
|
FTitleCaptions.Assign(AValue);
|
||||||
// Refresh the display.
|
|
||||||
ShowColumnTitles;
|
|
||||||
AdjustRowCount;
|
|
||||||
Invalidate;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TValueListEditor.GetCell(ACol, ARow: Integer): string;
|
|
||||||
var
|
|
||||||
I: Integer;
|
|
||||||
begin
|
|
||||||
Result:='';
|
|
||||||
if ARow=0 then begin
|
|
||||||
if doColumnTitles in DisplayOptions then
|
|
||||||
if ACol<FTitleCaptions.Count then
|
|
||||||
Result:=FTitleCaptions[ACol];
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
I:=ARow-FixedRows;
|
|
||||||
if Strings.Count<=I then exit;
|
|
||||||
if ACol=0 then
|
|
||||||
Result:=Strings.Names[I]
|
|
||||||
else if ACol=1 then
|
|
||||||
Result:=Strings.ValueFromIndex[I];
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TValueListEditor.SetCell(ACol, ARow: Integer; const Value: string);
|
|
||||||
var
|
|
||||||
I: Integer;
|
|
||||||
Line: string;
|
|
||||||
begin
|
|
||||||
I:=ARow-FixedRows;
|
|
||||||
if ACol=0 then
|
|
||||||
Line:=Value+'='+Cells[1,ARow]
|
|
||||||
else
|
|
||||||
Line:=Cells[0,ARow]+'='+Value;
|
|
||||||
if I>=Strings.Count then
|
|
||||||
Strings.Insert(I,Line)
|
|
||||||
else
|
|
||||||
Strings[I]:=Line;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TValueListEditor.GetKey(Index: Integer): string;
|
function TValueListEditor.GetKey(Index: Integer): string;
|
||||||
@ -424,13 +390,41 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TValueListEditor.GetCells(ACol, ARow: Integer): string;
|
||||||
procedure TValueListEditor.DrawCell(ACol, ARow: Integer; ARect: TRect;
|
var
|
||||||
AState: TGridDrawState);
|
I: Integer;
|
||||||
begin
|
begin
|
||||||
// ToDo: Change TextRect based on item properties.
|
Result:='';
|
||||||
inherited DrawCell(ACol, ARow, ARect, AState);
|
if ARow=0 then begin
|
||||||
|
if doColumnTitles in DisplayOptions then
|
||||||
|
if ACol<FTitleCaptions.Count then
|
||||||
|
Result:=FTitleCaptions[ACol];
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
I:=ARow-FixedRows;
|
||||||
|
if Strings.Count<=I then exit;
|
||||||
|
if ACol=0 then
|
||||||
|
Result:=Strings.Names[I]
|
||||||
|
else if ACol=1 then
|
||||||
|
Result:=Strings.ValueFromIndex[I];
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TValueListEditor.SetCells(ACol, ARow: Integer; const AValue: string);
|
||||||
|
var
|
||||||
|
I: Integer;
|
||||||
|
Line: string;
|
||||||
|
begin
|
||||||
|
I:=ARow-FixedRows;
|
||||||
|
if ACol=0 then
|
||||||
|
Line:=AValue+'='+Cells[1,ARow]
|
||||||
|
else
|
||||||
|
Line:=Cells[0,ARow]+'='+AValue;
|
||||||
|
if I>=Strings.Count then
|
||||||
|
Strings.Insert(I,Line)
|
||||||
|
else
|
||||||
|
Strings[I]:=Line;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TValueListEditor.GetEditText(ACol, ARow: Longint): string;
|
function TValueListEditor.GetEditText(ACol, ARow: Longint): string;
|
||||||
begin
|
begin
|
||||||
@ -449,6 +443,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TValueListEditor.TitlesChanged(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// Refresh the display.
|
||||||
|
ShowColumnTitles;
|
||||||
|
AdjustRowCount;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TValueListEditor.WSRegisterClass;
|
class procedure TValueListEditor.WSRegisterClass;
|
||||||
begin
|
begin
|
||||||
// RegisterPropertyToSkip(Self, 'SomeProperty', 'VCL compatibility property', '');
|
// RegisterPropertyToSkip(Self, 'SomeProperty', 'VCL compatibility property', '');
|
||||||
|
Loading…
Reference in New Issue
Block a user