fpspreadsheet: Introduce events to notify visual controls of col width/format and row height/format change. Extend worksheet inspector to display col/row formats and col widths.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5276 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
613396797a
commit
10e082b3c2
@ -59,9 +59,17 @@ type
|
||||
TsNotifyEvent = procedure (Sender: TObject) of object;
|
||||
|
||||
{@@ This event fires whenever a cell value or cell formatting changes. It is
|
||||
handled by TsWorkbookLink to update the listening controls. }
|
||||
handled by TsWorkbookSource to update the listening visual controls. }
|
||||
TsCellEvent = procedure (Sender: TObject; ARow, ACol: Cardinal) of object;
|
||||
|
||||
{@@ This event fires whenever a column width or column format changes. It is
|
||||
handled by TsWorkbookSource to update the listening visual controls. }
|
||||
TsColEvent = procedure (Sender: TObject; ACol: Cardinal) of object;
|
||||
|
||||
{@@ This event fires whenever a row height or row format changes. It is
|
||||
handled by TsWorkbookSource to update the listening visual controls }
|
||||
TsRowEvent = procedure (Sender: TObject; ARow: Cardinal) of object;
|
||||
|
||||
{@@ This event can be used to override the built-in comparing function which
|
||||
is called when cells are sorted. }
|
||||
TsCellCompareEvent = procedure (Sender: TObject; ACell1, ACell2: PCell;
|
||||
@ -105,6 +113,8 @@ type
|
||||
FZoomFactor: Double;
|
||||
FOnChangeCell: TsCellEvent;
|
||||
FOnChangeFont: TsCellEvent;
|
||||
FOnChangeCol: TsColEvent;
|
||||
FOnChangeRow: TsRowEvent;
|
||||
FOnZoom: TsNotifyEvent;
|
||||
FOnCompareCells: TsCellCompareEvent;
|
||||
FOnSelectCell: TsCellEvent;
|
||||
@ -428,6 +438,7 @@ type
|
||||
function GetColFormatIndex(ACol: Cardinal): Integer;
|
||||
function GetColWidth(ACol: Cardinal; AUnits: TsSizeUnits): Single; overload;
|
||||
function GetColWidth(ACol: Cardinal): Single; overload; deprecated 'Use version with parameter AUnits.';
|
||||
function GetColWidthType(ACol: Cardinal): TsColWidthType;
|
||||
function HasColFormats: Boolean;
|
||||
function HasRowFormats: Boolean;
|
||||
function IsEmptyRow(ARow: Cardinal): Boolean;
|
||||
@ -451,8 +462,10 @@ type
|
||||
ARowHeightType: TsRowHeightType = rhtCustom); overload; deprecated 'Use version with parameter AUnits';
|
||||
procedure WriteColInfo(ACol: Cardinal; AData: TCol);
|
||||
procedure WriteColFormatIndex(ACol: Cardinal; AFormatIndex: Integer);
|
||||
procedure WriteColWidth(ACol: Cardinal; AWidth: Single; AUnits: TsSizeUnits); overload;
|
||||
procedure WriteColWidth(ACol: Cardinal; AWidth: Single); overload; deprecated 'Use version with parameter AUnits';
|
||||
procedure WriteColWidth(ACol: Cardinal; AWidth: Single; AUnits: TsSizeUnits;
|
||||
AColWidthType: TsColWidthType = cwtCustom); overload;
|
||||
procedure WriteColWidth(ACol: Cardinal; AWidth: Single;
|
||||
AColWidthType: TsColWidthType = cwtCustom); overload; deprecated 'Use version with parameter AUnits';
|
||||
|
||||
// Sorting
|
||||
procedure Sort(const ASortParams: TsSortParams;
|
||||
@ -521,9 +534,11 @@ type
|
||||
AOffsetX: Double = 0.0; AOffsetY: Double = 0.0; AScaleX: Double = 1.0;
|
||||
AScaleY: Double = 1.0): Integer; overload;
|
||||
|
||||
// Notification of changed cells
|
||||
// Notification of changed cells, rows or columns
|
||||
procedure ChangedCell(ARow, ACol: Cardinal);
|
||||
procedure ChangedCol(ACol: Cardinal);
|
||||
procedure ChangedFont(ARow, ACol: Cardinal);
|
||||
procedure ChangedRow(ARow: Cardinal);
|
||||
|
||||
{ Properties }
|
||||
|
||||
@ -580,8 +595,12 @@ type
|
||||
property ZoomFactor: Double read FZoomFactor write SetZoomFactor;
|
||||
{@@ Event fired when cell contents or formatting changes }
|
||||
property OnChangeCell: TsCellEvent read FOnChangeCell write FOnChangeCell;
|
||||
{@@ Event fired when column height or formatting changes }
|
||||
property OnChangeCol: TsColEvent read FOnChangeCol write FOnChangeCol;
|
||||
{@@ Event fired when the font size in a cell changes }
|
||||
property OnChangeFont: TsCellEvent read FOnChangeFont write FOnChangeFont;
|
||||
{@@ Event fired when a row height or row formatting has changed }
|
||||
property OnChangeRow: TsRowEvent read FOnChangeRow write FOnChangeRow;
|
||||
{@@ Event to override cell comparison for sorting }
|
||||
property OnCompareCells: TsCellCompareEvent read FOnCompareCells write FOnCompareCells;
|
||||
{@@ Event fired when a cell is "selected". }
|
||||
@ -1617,6 +1636,34 @@ begin
|
||||
FOnChangeCell(Self, ARow, ACol);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Is called whenever a column width or column format has changed. Fires an event
|
||||
"OnChangedCol" which is handled by TsWorkbookSource
|
||||
|
||||
@param ACol Index of the column which as changed
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorksheet.ChangedCol(ACol: Cardinal);
|
||||
begin
|
||||
if FWorkbook.FReadWriteFlag = rwfRead then
|
||||
exit;
|
||||
if FWorkbook.NotificationsEnabled and Assigned(FOnChangeCol) then
|
||||
FOnChangeCol(Self, ACol);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Is called whenever a row height or row format has changed. Fires an event
|
||||
"OnChangedRow" which is handled by TsWorkbookSource
|
||||
|
||||
@param ARow Index of the row which as changed
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorksheet.ChangedRow(ARow: Cardinal);
|
||||
begin
|
||||
if FWorkbook.FReadWriteFlag = rwfRead then
|
||||
exit;
|
||||
if FWorkbook.NotificationsEnabled and Assigned(FOnChangeRow) then
|
||||
FOnChangeRow(Self, ARow);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Is called whenever a font height changes. Fires an even "OnChangeFont"
|
||||
which is handled by TsWorksheetGrid to update the row heights.
|
||||
@ -6602,6 +6649,27 @@ begin
|
||||
Result := GetColWidth(ACol, suChars);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Returns the type of column width of a specific column.
|
||||
If there is no column record then cwtDefault is returned.
|
||||
|
||||
@param ACol Index of the column considered
|
||||
@param AUnits Units for the column width.
|
||||
@return Width of the column. This is the "raw" value, without application of
|
||||
the zoom factor.
|
||||
-------------------------------------------------------------------------------}
|
||||
function TsWorksheet.GetColWidthType(ACol: Cardinal): TsColWidthType;
|
||||
var
|
||||
lCol: PCol;
|
||||
begin
|
||||
lCol := FindCol(ACol);
|
||||
if lCol = nil then
|
||||
Result := cwtDefault
|
||||
else
|
||||
Result := lCol^.ColWidthType;
|
||||
end;
|
||||
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Returns the index to the cell format to be used for a given row.
|
||||
If there is no row record then the default format (index 0) is returned.
|
||||
@ -7119,6 +7187,7 @@ begin
|
||||
lRow^.Height := AData.Height;
|
||||
lRow^.RowHeightType := AData.RowHeightType;
|
||||
lRow^.FormatIndex := AData.FormatIndex;
|
||||
ChangedRow(ARow);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7137,6 +7206,7 @@ begin
|
||||
exit;
|
||||
lRow := GetRow(ARow);
|
||||
lRow^.FormatIndex := AFormatIndex;
|
||||
ChangedRow(ARow);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7159,6 +7229,7 @@ begin
|
||||
lRow := GetRow(ARow);
|
||||
lRow^.Height := FWorkbook.ConvertUnits(AHeight, AUnits, FWorkbook.FUnits);
|
||||
lRow^.RowHeightType := ARowHeightType;
|
||||
ChangedRow(ARow);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7192,6 +7263,7 @@ begin
|
||||
lCol^.Width := AData.Width;
|
||||
lCol^.ColWidthType := AData.ColWidthType;
|
||||
lCol^.FormatIndex := AData.FormatIndex;
|
||||
ChangedCol(ACol);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7211,6 +7283,7 @@ begin
|
||||
exit;
|
||||
lCol := GetCol(ACol);
|
||||
lCol^.FormatIndex := AFormatIndex;
|
||||
ChangedCol(ACol);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7219,10 +7292,12 @@ end;
|
||||
|
||||
@param ACol Index of the column to be considered
|
||||
@param AWidth Width to be assigned to the column.
|
||||
@param AColWidthType Type of the column width (default -> AWidth is ignored)
|
||||
or custom)
|
||||
@param AUnits Units used for parameter AWidth.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorksheet.WriteColWidth(ACol: Cardinal; AWidth: Single;
|
||||
AUnits: TsSizeUnits);
|
||||
AUnits: TsSizeUnits; AColWidthType: TsColWidthType = cwtCustom);
|
||||
var
|
||||
lCol: PCol;
|
||||
begin
|
||||
@ -7230,7 +7305,8 @@ begin
|
||||
exit;
|
||||
lCol := GetCol(ACol);
|
||||
lCol^.Width := FWorkbook.ConvertUnits(AWidth, AUnits, FWorkbook.FUnits);
|
||||
lCol^.ColWidthType := cwtCustom;
|
||||
lCol^.ColWidthType := AColWidthType;
|
||||
ChangedCol(ACol);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -7240,9 +7316,10 @@ end;
|
||||
Note that this method is deprecated and will be removed.
|
||||
Use the variant in which the units of the new width can be specified.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorksheet.WriteColWidth(ACol: Cardinal; AWidth: Single);
|
||||
procedure TsWorksheet.WriteColWidth(ACol: Cardinal; AWidth: Single;
|
||||
AColWidthType: TsColWidthType = cwtCustom);
|
||||
begin
|
||||
WriteColWidth(ACol, AWidth, suChars);
|
||||
WriteColWidth(ACol, AWidth, suChars, AColWidthType);
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
|
@ -43,7 +43,7 @@ type
|
||||
TsNotificationItem = (lniWorkbook,
|
||||
lniWorksheet, lniWorksheetAdd, lniWorksheetRemoving, lniWorksheetRemove,
|
||||
lniWorksheetRename, lniWorksheetZoom,
|
||||
lniCell, lniSelection, lniAbortSelection, lniRow); //, lniPalette);
|
||||
lniCell, lniSelection, lniAbortSelection, lniRow, lniCol);
|
||||
{@@ This set accompanies the notification between WorkbookSource and visual
|
||||
controls and describes which items have changed in the spreadsheet. }
|
||||
TsNotificationItems = set of TsNotificationItem;
|
||||
@ -64,7 +64,6 @@ type
|
||||
FUserFileFormatID: TsSpreadFormatID;
|
||||
FPendingSelection: TsCellRangeArray;
|
||||
FPendingOperation: TsCopyOperation;
|
||||
// FControlLockCount: Integer;
|
||||
FOptions: TsWorkbookOptions;
|
||||
FOnError: TsWorkbookSourceErrorEvent;
|
||||
|
||||
@ -79,6 +78,8 @@ type
|
||||
procedure CellChangedHandler(Sender: TObject; ARow, ACol: Cardinal);
|
||||
procedure CellFontChangedHandler(Sender: TObject; ARow, ACol: Cardinal);
|
||||
procedure CellSelectedHandler(Sender: TObject; ARow, ACol: Cardinal);
|
||||
procedure ColChangedHandler(Sender: TObject; ACol: Cardinal);
|
||||
procedure RowChangedHandler(Sender: TObject; ARow: Cardinal);
|
||||
// procedure WorkbookChangedPaletteHandler(Sender: TObject);
|
||||
procedure WorkbookOpenedHandler(Sender: TObject);
|
||||
procedure WorksheetAddedHandler(Sender: TObject; ASheet: TsWorksheet);
|
||||
@ -437,7 +438,8 @@ type
|
||||
|
||||
{@@ Classification of data displayed by the SpreadsheetInspector. Each item
|
||||
can be assigned to a tab of a TabControl. }
|
||||
TsInspectorMode = (imWorkbook, imWorksheet, imCellValue, imCellProperties, imRow);
|
||||
TsInspectorMode = (imWorkbook, imWorksheet, imCellValue, imCellProperties,
|
||||
imRow, imCol);
|
||||
|
||||
{@@ Inspector expanded nodes }
|
||||
TsInspectorExpandedNode = (ienFormatSettings, ienPageLayout, ienFonts, ienFormats,
|
||||
@ -464,6 +466,8 @@ type
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure UpdateCellValue(ACell: PCell; AStrings: TStrings); virtual;
|
||||
procedure UpdateCellProperties(ACell: PCell; AStrings: TStrings); virtual;
|
||||
procedure UpdateCol(ACol: Integer; AStrings: TStrings); virtual;
|
||||
procedure UpdateFormatProperties(AFormatIndex: integer; AStrings: TStrings); virtual;
|
||||
procedure UpdateRow(ARow: Integer; AStrings: TStrings); virtual;
|
||||
procedure UpdateWorkbook(AWorkbook: TsWorkbook; AStrings: TStrings); virtual;
|
||||
procedure UpdateWorksheet(ASheet: TsWorksheet; AStrings: TStrings); virtual;
|
||||
@ -729,6 +733,20 @@ begin
|
||||
NotifyListeners([lniCell], FWorksheet.FindCell(ARow, ACol));
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Event handler for the OnChangeCol event of TsWorksheet which is fired whenver
|
||||
a column width or column format changes.
|
||||
|
||||
@param Sender Pointer to the worksheet
|
||||
@param ACol Index (in sheet notation) of the column changed
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorkbookSource.ColChangedHandler(Sender: TObject;
|
||||
ACol: Cardinal);
|
||||
begin
|
||||
if FWorksheet <> nil then
|
||||
NotifyListeners([lniCol], {%H-}Pointer(PtrInt(ACol)));
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Event handler for the OnChangeFont event of TsWorksheet which is fired
|
||||
whenever a cell font changes. The listener, in particular the worksheetGrid,
|
||||
@ -770,11 +788,28 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Event handler for the OnChangeRow event of TsWorksheet which is fired whenver
|
||||
a row width or row format changes.
|
||||
|
||||
@param Sender Pointer to the worksheet
|
||||
@param ARow Index (in sheet notation) of the row changed
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorkbookSource.RowChangedHandler(Sender: TObject;
|
||||
ARow: Cardinal);
|
||||
begin
|
||||
if FWorksheet <> nil then
|
||||
NotifyListeners([lniRow], {%H-}Pointer(PtrInt(ARow)));
|
||||
end;
|
||||
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Creates a new empty workbook and adds a single worksheet
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsWorkbookSource.CreateNewWorkbook;
|
||||
begin
|
||||
FFileName := '';
|
||||
FFileFormatID := sfidUnknown;
|
||||
InternalCreateNewWorkbook;
|
||||
FWorksheet := FWorkbook.AddWorksheet(Format(rsDefaultSheetName,[1]));
|
||||
SelectWorksheet(FWorksheet);
|
||||
@ -1613,7 +1648,9 @@ begin
|
||||
if FWorksheet <> nil then
|
||||
begin
|
||||
FWorksheet.OnChangeCell := @CellChangedHandler;
|
||||
FWorksheet.OnChangeCol := @ColChangedHandler;
|
||||
FWorksheet.OnChangeFont := @CellFontChangedHandler;
|
||||
FWorksheet.OnChangeRow := @RowChangedHandler;
|
||||
FWorksheet.OnSelectCell := @CellSelectedHandler;
|
||||
FWorksheet.OnZoom := @WorksheetZoomHandler;
|
||||
NotifyListeners([lniWorksheet]);
|
||||
@ -2874,9 +2911,15 @@ begin
|
||||
book := FWorkbookSource.Workbook;
|
||||
sheet := FWorkbookSource.Worksheet;
|
||||
if sheet <> nil then begin
|
||||
FCurrRow := sheet.ActiveCellRow;
|
||||
FCurrCol := sheet.ActiveCellCol;
|
||||
{
|
||||
cell := sheet.FindCell(sheet.ActiveCellRow, sheet.ActiveCellCol);
|
||||
if cell <> nil then
|
||||
if cell <> nil then begin
|
||||
FCurrRow := cell^.Row;
|
||||
FCurrCol := cell^.Col;
|
||||
end;
|
||||
}
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -2888,6 +2931,7 @@ begin
|
||||
imWorksheet : UpdateWorksheet(sheet, list);
|
||||
imWorkbook : UpdateWorkbook(book, list);
|
||||
imRow : UpdateRow(FCurrRow, list);
|
||||
imCol : UpdateCol(FCurrCol, list);
|
||||
end;
|
||||
Strings.Assign(list);
|
||||
finally
|
||||
@ -2943,9 +2987,26 @@ begin
|
||||
if ([lniCell, lniSelection]*AChangedItems <> []) then
|
||||
DoUpdate;
|
||||
imRow:
|
||||
if AData <> nil then begin
|
||||
FCurrRow := PCell(AData)^.Row;
|
||||
if ([lniSelection] * AChangedItems <> []) then DoUpdate;
|
||||
begin
|
||||
if ([lniSelection] * AChangedItems <> []) then begin
|
||||
if AData <> nil then
|
||||
FCurrRow := PCell(AData)^.Row;
|
||||
end else if ([lniRow] * AChangedItems <> []) then
|
||||
FCurrRow := PtrInt(AData)
|
||||
else
|
||||
exit;
|
||||
DoUpdate;
|
||||
end;
|
||||
imCol:
|
||||
begin
|
||||
if ([lniSelection] * AChangedItems <> []) then begin
|
||||
if AData <> nil then
|
||||
FCurrCol := PCell(AData)^.Col;
|
||||
end else if ([lniCol] * AChangedItems <> []) then
|
||||
FCurrCol := PtrInt(AData)
|
||||
else
|
||||
exit;
|
||||
DoUpdate;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -3022,27 +3083,13 @@ procedure TsSpreadsheetInspector.UpdateCellProperties(ACell: PCell;
|
||||
AStrings: TStrings);
|
||||
var
|
||||
s: String;
|
||||
cb: TsCellBorder;
|
||||
r1, r2, c1, c2: Cardinal;
|
||||
fmt: TsCellFormat;
|
||||
numFmt: TsNumFormatParams;
|
||||
rtp: TsRichTextParam;
|
||||
begin
|
||||
if (ACell <> nil) then
|
||||
fmt := Workbook.GetCellFormat(ACell^.FormatIndex)
|
||||
if ACell <> nil then
|
||||
UpdateFormatProperties(ACell^.FormatIndex, AStrings)
|
||||
else
|
||||
InitFormatRecord(fmt);
|
||||
|
||||
if (ACell = nil)
|
||||
then AStrings.Add('FormatIndex=(default)')
|
||||
else AStrings.Add(Format('FormatIndex=%d', [ACell^.FormatIndex]));
|
||||
|
||||
if (ACell = nil) or not (uffFont in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('FontIndex=(default)')
|
||||
else AStrings.Add(Format('FontIndex=%d (%s)', [
|
||||
fmt.FontIndex,
|
||||
Workbook.GetFontAsString(fmt.FontIndex)
|
||||
]));
|
||||
UpdateFormatProperties(-1, AStrings);
|
||||
|
||||
if (ACell <> nil) and (Length(ACell^.RichTextParams) > 0) then
|
||||
begin
|
||||
@ -3055,31 +3102,64 @@ begin
|
||||
end else
|
||||
AStrings.Add('Rich-text parameters=(none)');
|
||||
|
||||
if (ACell=nil) or not (uffTextRotation in fmt.UsedFormattingFields)
|
||||
if (Worksheet = nil) or not Worksheet.IsMerged(ACell) then
|
||||
AStrings.Add('Merged range=(none)')
|
||||
else
|
||||
begin
|
||||
Worksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
AStrings.Add('Merged range=' + GetCellRangeString(r1, c1, r2, c2));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TsSpreadsheetInspector.UpdateFormatProperties(AFormatIndex: integer;
|
||||
AStrings: TStrings);
|
||||
var
|
||||
s: String;
|
||||
cb: TsCellBorder;
|
||||
fmt: TsCellFormat;
|
||||
numFmt: TsNumFormatParams;
|
||||
begin
|
||||
if AFormatIndex > -1 then
|
||||
fmt := Workbook.GetCellFormat(AFormatIndex)
|
||||
else
|
||||
InitFormatRecord(fmt);
|
||||
|
||||
if (AFormatIndex = -1)
|
||||
then AStrings.Add('FormatIndex=(default)')
|
||||
else AStrings.Add(Format('FormatIndex=%d', [AFormatIndex]));
|
||||
|
||||
if (AFormatIndex = -1) or not (uffFont in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('FontIndex=(default)')
|
||||
else AStrings.Add(Format('FontIndex=%d (%s)', [
|
||||
fmt.FontIndex,
|
||||
Workbook.GetFontAsString(fmt.FontIndex)
|
||||
]));
|
||||
|
||||
if (AFormatIndex = -1) or not (uffTextRotation in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('TextRotation=(default)')
|
||||
else AStrings.Add(Format('TextRotation=%s', [
|
||||
GetEnumName(TypeInfo(TsTextRotation), ord(fmt.TextRotation))
|
||||
]));
|
||||
|
||||
if (ACell=nil) or not (uffHorAlign in fmt.UsedFormattingFields)
|
||||
if (AFormatIndex = -1) or not (uffHorAlign in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('HorAlignment=(default)')
|
||||
else AStrings.Add(Format('HorAlignment=%s', [
|
||||
GetEnumName(TypeInfo(TsHorAlignment), ord(fmt.HorAlignment))
|
||||
]));
|
||||
|
||||
if (ACell=nil) or not (uffVertAlign in fmt.UsedFormattingFields)
|
||||
if (AFormatIndex = -1) or not (uffVertAlign in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('VertAlignment=(default)')
|
||||
else AStrings.Add(Format('VertAlignment=%s', [
|
||||
GetEnumName(TypeInfo(TsVertAlignment), ord(fmt.VertAlignment))
|
||||
]));
|
||||
|
||||
if (ACell=nil) or not (uffWordwrap in fmt.UsedFormattingFields)
|
||||
if (AFormatIndex = -1) or not (uffWordwrap in fmt.UsedFormattingFields)
|
||||
then AStrings.Add('Wordwrap=(default)')
|
||||
else AStrings.Add(Format('Wordwrap=%s', [
|
||||
BoolToStr(uffWordwrap in fmt.UsedFormattingFields, true)
|
||||
]));
|
||||
|
||||
if (ACell=nil) or not (uffBorder in fmt.UsedFormattingFields) then
|
||||
if (AFormatIndex = -1) or not (uffBorder in fmt.UsedFormattingFields) then
|
||||
AStrings.Add('Borders=(none)')
|
||||
else
|
||||
begin
|
||||
@ -3092,7 +3172,7 @@ begin
|
||||
end;
|
||||
|
||||
for cb in TsCellBorder do
|
||||
if ACell = nil then
|
||||
if AFormatIndex = -1 then
|
||||
AStrings.Add(Format('BorderStyles[%s]=(default)', [
|
||||
GetEnumName(TypeInfo(TsCellBorder), ord(cb))]))
|
||||
else
|
||||
@ -3101,7 +3181,7 @@ begin
|
||||
GetEnumName(TypeInfo(TsLineStyle), ord(fmt.BorderStyles[cb].LineStyle)),
|
||||
GetColorName(fmt.BorderStyles[cb].Color)]));
|
||||
|
||||
if (ACell = nil) or not (uffBackground in fmt.UsedformattingFields) then
|
||||
if (AFormatIndex = -1) or not (uffBackground in fmt.UsedformattingFields) then
|
||||
begin
|
||||
AStrings.Add('Style=(default)');
|
||||
AStrings.Add('PatternColor=(default)');
|
||||
@ -3116,7 +3196,7 @@ begin
|
||||
fmt.Background.BgColor, GetColorName(fmt.Background.BgColor)]));
|
||||
end;
|
||||
|
||||
if (ACell = nil) or not (uffNumberFormat in fmt.UsedFormattingFields) then
|
||||
if (AFormatIndex = -1) or not (uffNumberFormat in fmt.UsedFormattingFields) then
|
||||
begin
|
||||
AStrings.Add('NumberFormatIndex=-1');
|
||||
AStrings.Add('NumberFormat=(default)');
|
||||
@ -3130,19 +3210,11 @@ begin
|
||||
AStrings.Add('NumberFormatStr=' + numFmt.NumFormatStr);
|
||||
end;
|
||||
|
||||
if (ACell = nil) or not (uffBiDi in fmt.UsedFormattingFields) then
|
||||
if (AFormatIndex = -1) or not (uffBiDi in fmt.UsedFormattingFields) then
|
||||
AStrings.Add('BiDi=(bdDefault)')
|
||||
else
|
||||
AStrings.Add(Format('BiDiMode=%s', [
|
||||
GetEnumName(TypeInfo(TsBiDiMode), ord(fmt.BiDiMode))]));
|
||||
|
||||
if (Worksheet = nil) or not Worksheet.IsMerged(ACell) then
|
||||
AStrings.Add('Merged range=(none)')
|
||||
else
|
||||
begin
|
||||
Worksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
AStrings.Add('Merged range=' + GetCellRangeString(r1, c1, r2, c2));
|
||||
end;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -3220,6 +3292,48 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Creates a string list containing the properties of a column.
|
||||
The string list items are name-value pairs in the format "name=value".
|
||||
The string list is displayed in the inspector's grid.
|
||||
|
||||
@param ACol index of the investigated column
|
||||
@param AStrings Stringlist receiving the name-value pairs.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsSpreadsheetInspector.UpdateCol(ACol: Integer; AStrings: TStrings);
|
||||
var
|
||||
unitStr: String;
|
||||
lCol: PCol;
|
||||
begin
|
||||
if (Workbook = nil) or (Worksheet = nil) then
|
||||
exit;
|
||||
if (ACol < 0) or (ACol <> Worksheet.ActiveCellCol) then
|
||||
exit;
|
||||
|
||||
unitStr := SizeUnitNames[Workbook.Units];
|
||||
lCol := Worksheet.FindCol(ACol);
|
||||
AStrings.Add(Format('Col=%d', [ACol]));
|
||||
if lCol <> nil then
|
||||
begin
|
||||
AStrings.Add(Format('Width=%.1f %s (%.1f pt)', [
|
||||
lCol^.Width, unitstr, Workbook.ConvertUnits(lCol^.Width, Workbook.Units, suPoints)
|
||||
]));
|
||||
AStrings.Add(Format('ColWidthType=%s', [
|
||||
ColWidthTypeNames[lCol^.ColWidthType]
|
||||
]));
|
||||
UpdateFormatProperties(lCol^.FormatIndex, AStrings);
|
||||
end else
|
||||
begin
|
||||
AStrings.Add('No column record=');
|
||||
AStrings.Add(Format('DefaultColWidth=%.1f %s (%.1f pt)', [
|
||||
Worksheet.ReadDefaultColWidth(Workbook.Units), unitStr,
|
||||
Worksheet.ReadDefaultColWidth(suPoints)
|
||||
]));
|
||||
// UpdateFormatProperties(-1, AStrings);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Creates a string list containing the properties of a row.
|
||||
The string list items are name-value pairs in the format "name=value".
|
||||
@ -3233,7 +3347,9 @@ var
|
||||
lRow: PRow;
|
||||
unitStr: String;
|
||||
begin
|
||||
if ARow < 0 then
|
||||
if (Workbook = nil) or (Worksheet = nil) then
|
||||
exit;
|
||||
if (ARow < 0) or (ARow <> Worksheet.ActiveCellRow) then
|
||||
exit;
|
||||
|
||||
unitStr := SizeUnitNames[Workbook.Units];
|
||||
@ -3247,9 +3363,7 @@ begin
|
||||
AStrings.Add(Format('RowHeightType=%s', [
|
||||
RowHeightTypeNames[lRow^.RowHeightType]
|
||||
]));
|
||||
AStrings.Add(Format('FormatIndex=%d', [
|
||||
lRow^.FormatIndex
|
||||
]));
|
||||
UpdateFormatProperties(lRow^.FormatIndex, AStrings);
|
||||
end else
|
||||
begin
|
||||
AStrings.Add('No row record=');
|
||||
@ -3257,6 +3371,7 @@ begin
|
||||
Worksheet.ReadDefaultRowHeight(Workbook.Units), unitStr,
|
||||
Worksheet.ReadDefaultRowHeight(suPoints)
|
||||
]));
|
||||
// UpdateFormatProperties(-1, AStrings);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -246,8 +246,6 @@ type
|
||||
procedure Setup;
|
||||
procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override;
|
||||
function TrimToCell(ACell: PCell): String;
|
||||
procedure UpdateColWidths(AStartIndex: Integer = 0);
|
||||
procedure UpdateRowHeight(ARow: Integer; AEnforceCalcRowHeight: Boolean = false);
|
||||
|
||||
{@@ Automatically recalculate formulas whenever a cell value changes. }
|
||||
property AutoCalc: Boolean read FAutoCalc write SetAutoCalc default false;
|
||||
@ -325,7 +323,10 @@ type
|
||||
const ALeftOuterStyle, ATopOuterStyle, ARightOuterStyle, ABottomOuterStyle,
|
||||
AHorInnerStyle, AVertInnerStyle: TsCellBorderStyle);
|
||||
|
||||
{ Row height calculation }
|
||||
{ Row height / col width calculation }
|
||||
procedure UpdateColWidth(ACol: Integer);
|
||||
procedure UpdateColWidths(AStartIndex: Integer = 0);
|
||||
procedure UpdateRowHeight(ARow: Integer; AEnforceCalcRowHeight: Boolean = false);
|
||||
procedure UpdateRowHeights(AStartRow: Integer = -1; AEnforceCalcRowHeight: Boolean = false);
|
||||
|
||||
{ Utilities related to Workbooks }
|
||||
@ -4066,7 +4067,7 @@ procedure TsCustomWorksheetGrid.ListenerNotification(AChangedItems: TsNotificati
|
||||
AData: Pointer = nil);
|
||||
var
|
||||
grow, gcol: Integer;
|
||||
srow: Cardinal;
|
||||
srow, scol: Cardinal;
|
||||
cell: PCell;
|
||||
lRow: PRow;
|
||||
begin
|
||||
@ -4140,7 +4141,7 @@ begin
|
||||
// HOW TO DO THIS???? SelectActive not working...
|
||||
end;
|
||||
|
||||
// Row height (after font change).
|
||||
// Row height (after font or row record change).
|
||||
if (lniRow in AChangedItems) and (Worksheet <> nil) then
|
||||
begin
|
||||
srow := {%H-}PtrInt(AData); // sheet row
|
||||
@ -4151,6 +4152,15 @@ begin
|
||||
UpdateRowHeight(grow, true);
|
||||
end;
|
||||
|
||||
// Column width
|
||||
if (lniCol in AChangedItems) and (Worksheet <> nil) then
|
||||
begin
|
||||
scol := {%Hä}PtrInt(AData); // sheet column index
|
||||
gcol := GetGridCol(scol);
|
||||
//lCol := Worksheet.FindCol(scol);
|
||||
UpdateColWidth(gcol);
|
||||
end;
|
||||
|
||||
// Worksheet zoom
|
||||
if (lniWorksheetZoom in AChangedItems) and (Worksheet <> nil) then
|
||||
AdaptToZoomFactor; // Reads value directly from Worksheet
|
||||
@ -4799,30 +4809,40 @@ begin
|
||||
);
|
||||
end;
|
||||
|
||||
procedure TsCustomWorksheetGrid.UpdateColWidth(ACol: Integer);
|
||||
var
|
||||
lCol: PCol;
|
||||
w: Integer; // Col width at current zoom level
|
||||
w100: Integer; // Col width at 100% zoom level
|
||||
begin
|
||||
if Worksheet <> nil then
|
||||
begin
|
||||
lCol := Worksheet.FindCol(ACol - FHeaderCount);
|
||||
if (lCol <> nil) and (lCol^.ColWidthType = cwtCustom) then
|
||||
w100 := CalcColWidthFromSheet(lCol^.Width)
|
||||
else
|
||||
w100 := CalcColWidthFromSheet(Worksheet.ReadDefaultColWidth(Workbook.Units));
|
||||
w := round(w100 * ZoomFactor);
|
||||
end else
|
||||
w := DefaultColWidth; // Zoom factor has already been applied by getter
|
||||
ColWidths[ACol] := w;
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
Updates column widths according to the data in the TCol records
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TsCustomWorksheetGrid.UpdateColWidths(AStartIndex: Integer = 0);
|
||||
var
|
||||
i: Integer;
|
||||
lCol: PCol;
|
||||
w: Integer; // Col width at current zoom level
|
||||
w100: Integer; // Col width at 100% zoom level
|
||||
begin
|
||||
if AStartIndex = 0 then
|
||||
AStartIndex := FHeaderCount;
|
||||
for i := AStartIndex to ColCount-1 do begin
|
||||
if Worksheet <> nil then
|
||||
begin
|
||||
lCol := Worksheet.FindCol(i - FHeaderCount);
|
||||
if (lCol <> nil) and (lCol^.ColWidthType = cwtCustom) then
|
||||
w100 := CalcColWidthFromSheet(lCol^.Width)
|
||||
else
|
||||
w100 := CalcColWidthFromSheet(Worksheet.ReadDefaultColWidth(Workbook.Units));
|
||||
w := round(w100 * ZoomFactor);
|
||||
end else
|
||||
w := DefaultColWidth; // Zoom factor is already applied by getter
|
||||
ColWidths[i] := w;
|
||||
BeginUpdate;
|
||||
try
|
||||
for i := AStartIndex to ColCount-1 do
|
||||
UpdateColWidth(i);
|
||||
finally
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -625,7 +625,7 @@ type
|
||||
{@@ Complete set of sorting parameters
|
||||
@param SortByCols If true sorting is top-down, otherwise left-right
|
||||
@param Priority Determines whether numbers are before or after text.
|
||||
@param SortKeys Array of sorting indexes and sorting directions }
|
||||
@param SortKeys Array of sorting col/row indexes and sorting directions }
|
||||
TsSortParams = record
|
||||
SortByCols: Boolean;
|
||||
Priority: TsSortPriority;
|
||||
@ -814,7 +814,7 @@ type
|
||||
|
||||
const
|
||||
RowHeightTypeNames: array[TsRowHeightType] of string = (
|
||||
'Default', 'Auto', 'Custom');
|
||||
'Default', 'Custom', 'Auto');
|
||||
|
||||
ColWidthTypeNames: array[TsColWidthType] of string = (
|
||||
'Default', 'Custom');
|
||||
|
Loading…
Reference in New Issue
Block a user