mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 19:35:58 +02:00
fixed saving default values for TStringGrid from Jesus
git-svn-id: trunk@7058 -
This commit is contained in:
parent
092848eb6d
commit
a7912f11f2
@ -22,10 +22,10 @@
|
|||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
<TopLine Value="1"/>
|
<TopLine Value="1"/>
|
||||||
<UnitName Value="project1"/>
|
<UnitName Value="project1"/>
|
||||||
<UsageCount Value="28"/>
|
<UsageCount Value="40"/>
|
||||||
</Unit0>
|
</Unit0>
|
||||||
<Unit1>
|
<Unit1>
|
||||||
<CursorPos X="23" Y="168"/>
|
<CursorPos X="26" Y="179"/>
|
||||||
<EditorIndex Value="0"/>
|
<EditorIndex Value="0"/>
|
||||||
<Filename Value="unit1.pas"/>
|
<Filename Value="unit1.pas"/>
|
||||||
<ComponentName Value="Form1"/>
|
<ComponentName Value="Form1"/>
|
||||||
@ -34,7 +34,7 @@
|
|||||||
<ResourceFilename Value="Unit1.lrs"/>
|
<ResourceFilename Value="Unit1.lrs"/>
|
||||||
<TopLine Value="150"/>
|
<TopLine Value="150"/>
|
||||||
<UnitName Value="Unit1"/>
|
<UnitName Value="Unit1"/>
|
||||||
<UsageCount Value="28"/>
|
<UsageCount Value="40"/>
|
||||||
</Unit1>
|
</Unit1>
|
||||||
</Units>
|
</Units>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
|
237
lcl/grids.pas
237
lcl/grids.pas
@ -508,6 +508,7 @@ type
|
|||||||
FStringEditor: TStringCellEditor;
|
FStringEditor: TStringCellEditor;
|
||||||
FExtendedColSizing: boolean;
|
FExtendedColSizing: boolean;
|
||||||
FExtendedRowSizing: boolean;
|
FExtendedRowSizing: boolean;
|
||||||
|
FUpdatingAutoFillCols: boolean;
|
||||||
{.$ifdef UseXOR}
|
{.$ifdef UseXOR}
|
||||||
FPrevLine: boolean;
|
FPrevLine: boolean;
|
||||||
FPrevValue: Integer;
|
FPrevValue: Integer;
|
||||||
@ -732,7 +733,7 @@ type
|
|||||||
property ColCount: Integer read GetColCount write SetColCount;
|
property ColCount: Integer read GetColCount write SetColCount;
|
||||||
property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
|
property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
|
||||||
property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths;
|
property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths;
|
||||||
property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth;
|
property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth default 64;
|
||||||
property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight default 20;
|
property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight default 20;
|
||||||
property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True;
|
property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True;
|
||||||
property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle;
|
property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle;
|
||||||
@ -1394,6 +1395,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomGrid.InternalAutoFillColumns;
|
procedure TCustomGrid.InternalAutoFillColumns;
|
||||||
|
procedure SetColumnWidth(aCol,aWidth: Integer);
|
||||||
|
begin
|
||||||
|
if csLoading in ComponentState then
|
||||||
|
SetRawColWidths(aCol, aWidth)
|
||||||
|
else
|
||||||
|
SetColWidths(aCol, aWidth);
|
||||||
|
end;
|
||||||
var
|
var
|
||||||
I, ForcedIndex: Integer;
|
I, ForcedIndex: Integer;
|
||||||
Count: Integer;
|
Count: Integer;
|
||||||
@ -1405,69 +1413,79 @@ begin
|
|||||||
if not AutoFillColumns then
|
if not AutoFillColumns then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
if FUpdatingAutoFillCols then
|
||||||
// if needed, last size can be obtained from FLastWidth
|
exit;
|
||||||
// when InternalAutoFillColumns is called from DoChangeBounds
|
|
||||||
// for example.
|
|
||||||
|
|
||||||
// Insert the algorithm that modify ColWidths accordingly
|
|
||||||
//
|
|
||||||
// For testing purposes, a simple algortihm is implemented:
|
|
||||||
// if SizePriority=0, column size should be unmodified
|
|
||||||
// if SizePriority<>0 means variable size column, its size
|
|
||||||
// is the average avalilable size.
|
|
||||||
|
|
||||||
Count := 0;
|
|
||||||
FixedSizeWidth := 0;
|
|
||||||
TotalWidth := 0;
|
|
||||||
for i:=0 to ColCount-1 do begin
|
|
||||||
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
|
||||||
AvailableSize := GetColWidths(i);
|
|
||||||
if aPriority>0 then
|
|
||||||
Inc(Count)
|
|
||||||
else
|
|
||||||
Inc(FixedSizeWidth, AvailableSize);
|
|
||||||
Inc(TotalWidth, AvailableSize);
|
|
||||||
end;
|
|
||||||
|
|
||||||
if Count=0 then begin
|
|
||||||
//it's an autofillcolumns grid, so at least one
|
|
||||||
// of the columns must fill completly the grid's
|
|
||||||
// available width, let it be that column the last
|
|
||||||
ForcedIndex := ColCount-1;
|
|
||||||
Count := 1;
|
|
||||||
end else
|
|
||||||
ForcedIndex := -1;
|
|
||||||
|
|
||||||
AvailableSize := ClientWidth - FixedSizeWidth - Integer(BorderStyle);
|
|
||||||
if AvailableSize<0 then begin
|
|
||||||
// There is no space available to fill with
|
|
||||||
// Variable Size Columns, what to do?
|
|
||||||
|
|
||||||
// Simply set all Variable Size Columns
|
FUpdatingAutoFillCols:=True;
|
||||||
// to 0, decreasing the size beyond this
|
try
|
||||||
// shouldn't be allowed.
|
// if needed, last size can be obtained from FLastWidth
|
||||||
|
// when InternalAutoFillColumns is called from DoChangeBounds
|
||||||
|
// for example.
|
||||||
|
|
||||||
|
// Insert the algorithm that modify ColWidths accordingly
|
||||||
|
//
|
||||||
|
// For testing purposes, a simple algortihm is implemented:
|
||||||
|
// if SizePriority=0, column size should be unmodified
|
||||||
|
// if SizePriority<>0 means variable size column, its size
|
||||||
|
// is the average avalilable size.
|
||||||
|
|
||||||
|
Count := 0;
|
||||||
|
FixedSizeWidth := 0;
|
||||||
|
TotalWidth := 0;
|
||||||
for i:=0 to ColCount-1 do begin
|
for i:=0 to ColCount-1 do begin
|
||||||
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
||||||
|
AvailableSize := GetColWidths(i);
|
||||||
if aPriority>0 then
|
if aPriority>0 then
|
||||||
SetColWidths(i,0);
|
Inc(Count)
|
||||||
//SetRawColWidths(i,0);
|
else
|
||||||
|
Inc(FixedSizeWidth, AvailableSize);
|
||||||
|
Inc(TotalWidth, AvailableSize);
|
||||||
end;
|
end;
|
||||||
end else begin
|
|
||||||
// Simpler case: There is actually available space to
|
if Count=0 then begin
|
||||||
// to be shared for variable size columns.
|
//it's an autofillcolumns grid, so at least one
|
||||||
FixedSizeWidth := AvailableSize mod Count; // space left after filling columns
|
// of the columns must fill completly the grid's
|
||||||
AvailableSize := AvailableSize div Count;
|
// available width, let it be that column the last
|
||||||
for i:=0 to ColCount-1 do begin
|
ForcedIndex := ColCount-1;
|
||||||
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
Count := 1;
|
||||||
if (APriority>0) or (i=ForcedIndex) then
|
end else
|
||||||
if i=ColCount-1 then
|
ForcedIndex := -1;
|
||||||
// the last column gets all space left
|
|
||||||
SetColWidths(i, AvailableSize + FixedSizeWidth)
|
AvailableSize := Width {ClientWidth} - FixedSizeWidth - Integer(BorderStyle);
|
||||||
else
|
if AvailableSize<0 then begin
|
||||||
SetColWidths(i, AvailableSize)
|
// There is no space available to fill with
|
||||||
//SetRawColWidths(i, AvailableSize);
|
// Variable Size Columns, what to do?
|
||||||
|
|
||||||
|
// Simply set all Variable Size Columns
|
||||||
|
// to 0, decreasing the size beyond this
|
||||||
|
// shouldn't be allowed.
|
||||||
|
for i:=0 to ColCount-1 do begin
|
||||||
|
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
||||||
|
if aPriority>0 then
|
||||||
|
SetColumnWidth(i, 0);
|
||||||
|
//SetColWidths(i,0);
|
||||||
|
//SetRawColWidths(i,0);
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
// Simpler case: There is actually available space to
|
||||||
|
// to be shared for variable size columns.
|
||||||
|
FixedSizeWidth := AvailableSize mod Count; // space left after filling columns
|
||||||
|
AvailableSize := AvailableSize div Count;
|
||||||
|
for i:=0 to ColCount-1 do begin
|
||||||
|
GetAutoFillColumnInfo(i, aMin, aMax, aPriority);
|
||||||
|
if (APriority>0) or (i=ForcedIndex) then
|
||||||
|
if i=ColCount-1 then
|
||||||
|
// the last column gets all space left
|
||||||
|
//SetColWidths(i, AvailableSize + FixedSizeWidth)
|
||||||
|
SetColumnWidth(i, AvailableSize + FixedSizeWidth)
|
||||||
|
else
|
||||||
|
//SetColWidths(i, AvailableSize)
|
||||||
|
//SetRawColWidths(i, AvailableSize);
|
||||||
|
SetColumnWidth(i, AvailableSize);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
FUpdatingAutoFillCols:=False;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1491,10 +1509,12 @@ begin
|
|||||||
if AValue<0 then Avalue:=-1;
|
if AValue<0 then Avalue:=-1;
|
||||||
if Avalue<>PtrInt(FCols[ACol]) then begin
|
if Avalue<>PtrInt(FCols[ACol]) then begin
|
||||||
SetRawColWidths(ACol, Avalue);
|
SetRawColWidths(ACol, Avalue);
|
||||||
VisualChange;
|
if not (csLoading in ComponentState) then begin
|
||||||
if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then
|
VisualChange;
|
||||||
EditorWidthChanged(aCol, aValue);
|
if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then
|
||||||
ColWidthsChanged;
|
EditorWidthChanged(aCol, aValue);
|
||||||
|
ColWidthsChanged;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1772,10 +1792,14 @@ procedure TCustomGrid.SetDefColWidth(Valor: Integer);
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if Valor=fDefColwidth then Exit;
|
if Valor=fDefColwidth then
|
||||||
|
Exit;
|
||||||
FDefColWidth:=Valor;
|
FDefColWidth:=Valor;
|
||||||
for i:=0 to ColCount-1 do FCols[i] := Pointer(-1);
|
if not AutoFillColumns then begin
|
||||||
VisualChange;
|
for i:=0 to ColCount-1 do
|
||||||
|
FCols[i] := Pointer(-1);
|
||||||
|
VisualChange;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomGrid.SetDefRowHeight(Valor: Integer);
|
procedure TCustomGrid.SetDefRowHeight(Valor: Integer);
|
||||||
@ -1915,9 +1939,6 @@ var
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
// Recalc colwidths if it is necesary
|
|
||||||
InternalAutoFillColumns;
|
|
||||||
|
|
||||||
// Calculate New Cached Values
|
// Calculate New Cached Values
|
||||||
FGCache.GridWidth:=0;
|
FGCache.GridWidth:=0;
|
||||||
FGCache.FixedWidth:=0;
|
FGCache.FixedWidth:=0;
|
||||||
@ -1950,14 +1971,17 @@ var
|
|||||||
FGCache.ClientHeight := Height - Integer(BorderStyle);
|
FGCache.ClientHeight := Height - Integer(BorderStyle);
|
||||||
HsbRange:=Width - Dv;
|
HsbRange:=Width - Dv;
|
||||||
VsbRange:=Height - Dh;
|
VsbRange:=Height - Dh;
|
||||||
|
|
||||||
HsbVisible := (FScrollBars in [ssHorizontal, ssBoth]) or (FGCache.GridWidth > FGCache.ClientWidth);
|
HsbVisible := (FScrollBars in [ssHorizontal, ssBoth]) or (FGCache.GridWidth > FGCache.ClientWidth);
|
||||||
VsbVisible := (FScrollBars in [ssVertical, ssBoth]) or (FGCache.GridHeight > FGCache.ClientHeight);
|
VsbVisible := (FScrollBars in [ssVertical, ssBoth]) or (FGCache.GridHeight > FGCache.ClientHeight);
|
||||||
if ScrollBarAutomatic(ssHorizontal) then
|
if ScrollBarAutomatic(ssHorizontal) then
|
||||||
HsbVisible := HsbVisible or (VsbVisible and (TW>HsbRange));
|
HsbVisible := not AutoFillColumns and (HsbVisible or (VsbVisible and (TW>HsbRange)));
|
||||||
if ScrollBarAutomatic(ssVertical) then
|
if ScrollBarAutomatic(ssVertical) then
|
||||||
VsbVisible := VsbVisible or (HsbVisible and (TH>VsbRange));
|
VsbVisible := VsbVisible or (HsbVisible and (TH>VsbRange));
|
||||||
|
|
||||||
if not HSBVisible then DH:=0;
|
if not HSBVisible then DH:=0;
|
||||||
if not VSbVisible then DV:=0;
|
if not VSbVisible then DV:=0;
|
||||||
|
|
||||||
Dec(FGCache.ClientWidth, DV);
|
Dec(FGCache.ClientWidth, DV);
|
||||||
Dec(FGCache.ClientHeight, DH);
|
Dec(FGCache.ClientHeight, DH);
|
||||||
end;
|
end;
|
||||||
@ -1991,6 +2015,9 @@ var
|
|||||||
begin
|
begin
|
||||||
if FCols=nil then exit; // not yet initialized or already destroyed
|
if FCols=nil then exit; // not yet initialized or already destroyed
|
||||||
|
|
||||||
|
if AutoFillColumns then
|
||||||
|
InternalAutoFillColumns;
|
||||||
|
|
||||||
CalcNewCachedSizes;
|
CalcNewCachedSizes;
|
||||||
|
|
||||||
CalcScrollbarsVisiblity;
|
CalcScrollbarsVisiblity;
|
||||||
@ -2002,7 +2029,6 @@ begin
|
|||||||
FGCache.TLColOff:=0;
|
FGCache.TLColOff:=0;
|
||||||
FGCache.TLRowOff:=0;
|
FGCache.TLRowOff:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$Ifdef DbgVisualChange}
|
{$Ifdef DbgVisualChange}
|
||||||
DbgOut('Width=',IntTostr(Width));
|
DbgOut('Width=',IntTostr(Width));
|
||||||
DbgOut(' Height=',IntToStr(height));
|
DbgOut(' Height=',IntToStr(height));
|
||||||
@ -3880,40 +3906,57 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomGrid.DefineProperties(Filer: TFiler);
|
procedure TCustomGrid.DefineProperties(Filer: TFiler);
|
||||||
function SonIguales(L1,L2: TList): boolean;
|
function SonRowsIguales(aGrid: TCustomGrid): boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=False; // store by default
|
result := aGrid.RowCount = RowCount;
|
||||||
for i:=0 to L1.Count-1 do begin
|
if Result then
|
||||||
Result:=L1[i]=L2[i];
|
for i:=0 to RowCount-1 do
|
||||||
if not Result then break;
|
if aGrid.RowHeights[i]<>RowHeights[i] then begin
|
||||||
end;
|
result := false;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
function SonColsIguales(aGrid: TCustomGrid): boolean;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
result := aGrid.ColCount = ColCount;
|
||||||
|
if Result then
|
||||||
|
for i:=0 to ColCount-1 do
|
||||||
|
if aGrid.ColWidths[i]<>ColWidths[i] then begin
|
||||||
|
result := false;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
function SonDefault(IsColumn: Boolean; L1: TList): boolean;
|
function SonDefault(IsColumn: Boolean; L1: TList): boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
DefValue, Value: Integer;
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if IsColumn then DefValue := DefaultColWidth
|
||||||
|
else DefValue := DefaultRowHeight;
|
||||||
for i:=0 to L1.Count-1 do begin
|
for i:=0 to L1.Count-1 do begin
|
||||||
if IsColumn then
|
Value := PtrInt(L1[i]);
|
||||||
Result := PtrInt(L1[i]) = DefaultColWidth
|
Result := (Value = DefValue) or (Value<0);
|
||||||
else
|
if not Result then
|
||||||
Result := PtrInt(L1[i]) = DefaultRowHeight;
|
break;
|
||||||
if not Result then break;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
function NeedWidths: boolean;
|
function NeedWidths: boolean;
|
||||||
begin
|
begin
|
||||||
if Filer.Ancestor <> nil then
|
if Filer.Ancestor <> nil then
|
||||||
Result := not SonIguales(TCustomGrid(Filer.Ancestor).FCols, FCols)
|
Result := not SonColsIguales(TCustomGrid(Filer.Ancestor))
|
||||||
else
|
else
|
||||||
Result := not SonDefault(True, FCols);
|
Result := not SonDefault(True, FCols);
|
||||||
|
result := Result and not AutoFillColumns;
|
||||||
end;
|
end;
|
||||||
function NeedHeights: boolean;
|
function NeedHeights: boolean;
|
||||||
begin
|
begin
|
||||||
if Filer.Ancestor <> nil then
|
if Filer.Ancestor <> nil then
|
||||||
Result := not SonIguales(TCustomGrid(Filer.Ancestor).FRows, FRows)
|
Result := not SonRowsIguales(TCustomGrid(Filer.Ancestor))
|
||||||
else
|
else
|
||||||
Result := not SonDefault(false, FRows);
|
Result := not SonDefault(false, FRows);
|
||||||
end;
|
end;
|
||||||
@ -6106,18 +6149,24 @@ procedure TCustomStringGrid.DefineProperties(Filer: TFiler);
|
|||||||
i,j: integer;
|
i,j: integer;
|
||||||
AntGrid: TCustomStringGrid;
|
AntGrid: TCustomStringGrid;
|
||||||
begin
|
begin
|
||||||
|
result := false;
|
||||||
AntGrid := TCustomStringGrid(Filer.Ancestor);
|
AntGrid := TCustomStringGrid(Filer.Ancestor);
|
||||||
//DebugLn('TCustomStringGrid.DefineProperties: Ancestor=',Integer(AntGrid));
|
if (AntGrid<>nil) then begin
|
||||||
if AntGrid<>nil then begin
|
result := (AntGrid.ColCount<>ColCount) or (AntGrid.RowCount<>RowCount);
|
||||||
result:=false;
|
if not result then
|
||||||
for i:=0 to AntGrid.ColCount-1 do
|
for i:=0 to AntGrid.ColCount-1 do
|
||||||
for j:=0 to AntGrid.RowCount-1 do
|
for j:=0 to AntGrid.RowCount-1 do
|
||||||
if Cells[i,j]<>AntGrid.Cells[i,j] then begin
|
if Cells[i,j]<>AntGrid.Cells[i,j] then begin
|
||||||
result:=true;
|
result := true;
|
||||||
break;
|
break;
|
||||||
end;
|
end
|
||||||
end else
|
end else
|
||||||
result:=true;
|
for i:=0 to ColCount-1 do
|
||||||
|
for j:=0 to RowCount-1 do
|
||||||
|
if Cells[i,j]<>'' then begin
|
||||||
|
result := true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
begin
|
begin
|
||||||
inherited DefineProperties(Filer);
|
inherited DefineProperties(Filer);
|
||||||
|
Loading…
Reference in New Issue
Block a user