fixed saving default values for TStringGrid from Jesus

git-svn-id: trunk@7058 -
This commit is contained in:
mattias 2005-04-04 18:14:20 +00:00
parent 092848eb6d
commit a7912f11f2
2 changed files with 146 additions and 97 deletions

View File

@ -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>

View File

@ -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,7 +1413,11 @@ begin
if not AutoFillColumns then if not AutoFillColumns then
exit; exit;
if FUpdatingAutoFillCols then
exit;
FUpdatingAutoFillCols:=True;
try
// if needed, last size can be obtained from FLastWidth // if needed, last size can be obtained from FLastWidth
// when InternalAutoFillColumns is called from DoChangeBounds // when InternalAutoFillColumns is called from DoChangeBounds
// for example. // for example.
@ -1439,7 +1451,7 @@ begin
end else end else
ForcedIndex := -1; ForcedIndex := -1;
AvailableSize := ClientWidth - FixedSizeWidth - Integer(BorderStyle); AvailableSize := Width {ClientWidth} - FixedSizeWidth - Integer(BorderStyle);
if AvailableSize<0 then begin if AvailableSize<0 then begin
// There is no space available to fill with // There is no space available to fill with
// Variable Size Columns, what to do? // Variable Size Columns, what to do?
@ -1450,7 +1462,8 @@ begin
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);
if aPriority>0 then if aPriority>0 then
SetColWidths(i,0); SetColumnWidth(i, 0);
//SetColWidths(i,0);
//SetRawColWidths(i,0); //SetRawColWidths(i,0);
end; end;
end else begin end else begin
@ -1463,12 +1476,17 @@ begin
if (APriority>0) or (i=ForcedIndex) then if (APriority>0) or (i=ForcedIndex) then
if i=ColCount-1 then if i=ColCount-1 then
// the last column gets all space left // the last column gets all space left
SetColWidths(i, AvailableSize + FixedSizeWidth) //SetColWidths(i, AvailableSize + FixedSizeWidth)
SetColumnWidth(i, AvailableSize + FixedSizeWidth)
else else
SetColWidths(i, AvailableSize) //SetColWidths(i, AvailableSize)
//SetRawColWidths(i, AvailableSize); //SetRawColWidths(i, AvailableSize);
SetColumnWidth(i, AvailableSize);
end; end;
end; end;
finally
FUpdatingAutoFillCols:=False;
end;
end; end;
procedure TCustomGrid.InternalSetColCount(ACount: Integer); procedure TCustomGrid.InternalSetColCount(ACount: Integer);
@ -1491,12 +1509,14 @@ 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);
if not (csLoading in ComponentState) then begin
VisualChange; VisualChange;
if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then if (FEditor<>nil)and(Feditor.Visible)and(ACol<=FCol) then
EditorWidthChanged(aCol, aValue); EditorWidthChanged(aCol, aValue);
ColWidthsChanged; ColWidthsChanged;
end; end;
end; end;
end;
procedure TCustomGrid.InternalSetFixedCols(const AValue: Integer); procedure TCustomGrid.InternalSetFixedCols(const AValue: Integer);
begin begin
@ -1772,11 +1792,15 @@ 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
for i:=0 to ColCount-1 do
FCols[i] := Pointer(-1);
VisualChange; VisualChange;
end; end;
end;
procedure TCustomGrid.SetDefRowHeight(Valor: Integer); procedure TCustomGrid.SetDefRowHeight(Valor: Integer);
var var
@ -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
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; 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
AntGrid := TCustomStringGrid(Filer.Ancestor);
//DebugLn('TCustomStringGrid.DefineProperties: Ancestor=',Integer(AntGrid));
if AntGrid<>nil then begin
result := false; result := false;
AntGrid := TCustomStringGrid(Filer.Ancestor);
if (AntGrid<>nil) then begin
result := (AntGrid.ColCount<>ColCount) or (AntGrid.RowCount<>RowCount);
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
for i:=0 to ColCount-1 do
for j:=0 to RowCount-1 do
if Cells[i,j]<>'' then begin
result := true; result := true;
break;
end;
end; end;
begin begin
inherited DefineProperties(Filer); inherited DefineProperties(Filer);