fpspreadsheet: Add change palette notification to visual control system.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3804 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-11-28 10:41:54 +00:00
parent 3ba964d1e6
commit 2df085549c
2 changed files with 28 additions and 6 deletions

View File

@ -951,6 +951,7 @@ type
FOnAddWorksheet: TsWorksheetEvent; FOnAddWorksheet: TsWorksheetEvent;
FOnRemoveWorksheet: TsRemoveWorksheetEvent; FOnRemoveWorksheet: TsRemoveWorksheetEvent;
FOnSelectWorksheet: TsWorksheetEvent; FOnSelectWorksheet: TsWorksheetEvent;
FOnChangePalette: TNotifyEvent;
FFileName: String; FFileName: String;
FLockCount: Integer; FLockCount: Integer;
FLog: TStringList; FLog: TStringList;
@ -1065,6 +1066,8 @@ type
property Options: TsWorkbookOptions read FOptions write FOptions; property Options: TsWorkbookOptions read FOptions write FOptions;
{@@ This event fires whenever a new worksheet is added } {@@ This event fires whenever a new worksheet is added }
property OnAddWorksheet: TsWorksheetEvent read FOnAddWorksheet write FOnAddWorksheet; property OnAddWorksheet: TsWorksheetEvent read FOnAddWorksheet write FOnAddWorksheet;
{@@ This event fires whenever the workbook palette changes. }
property OnChangePalette: TNotifyEvent read FOnChangePalette write FOnChangePalette;
{@@ This event fires whenever a worksheet is changed } {@@ This event fires whenever a worksheet is changed }
property OnChangeWorksheet: TsWorksheetEvent read FOnChangeWorksheet write FOnChangeWorksheet; property OnChangeWorksheet: TsWorksheetEvent read FOnChangeWorksheet write FOnChangeWorksheet;
{@@ This event fires whenever a workbook is loaded } {@@ This event fires whenever a workbook is loaded }
@ -7323,6 +7326,8 @@ begin
end; end;
end; end;
Result := Length(FPalette) - 1; Result := Length(FPalette) - 1;
if Assigned(FOnChangePalette) then FOnChangePalette(self);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -7589,6 +7594,8 @@ begin
{$IFDEF RNGCHECK} {$IFDEF RNGCHECK}
{$R+} {$R+}
{$ENDIF} {$ENDIF}
if Assigned(FOnChangePalette) then FOnChangePalette(self);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@ -40,7 +40,7 @@ type
which kind of item has changed: the workbook, the worksheet, a cell value, which kind of item has changed: the workbook, the worksheet, a cell value,
or a cell formatting, etc. } or a cell formatting, etc. }
TsNotificationItem = (lniWorkbook, lniWorksheet, lniCell, lniSelection, TsNotificationItem = (lniWorkbook, lniWorksheet, lniCell, lniSelection,
lniAbortSelection, lniRow); lniAbortSelection, lniRow, lniPalette);
{@@ This set accompanies the notification between WorkbookSource and visual {@@ This set accompanies the notification between WorkbookSource and visual
controls and describes which items have changed in the spreadsheet. } controls and describes which items have changed in the spreadsheet. }
TsNotificationItems = set of TsNotificationItem; TsNotificationItems = set of TsNotificationItem;
@ -75,6 +75,7 @@ type
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0); AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0);
procedure SetFileName(const AFileName: TFileName); procedure SetFileName(const AFileName: TFileName);
procedure SetOptions(AValue: TsWorkbookOptions); procedure SetOptions(AValue: TsWorkbookOptions);
procedure WorkbookChangedPaletteHandler(Sender: TObject);
procedure WorkbookOpenedHandler(Sender: TObject); procedure WorkbookOpenedHandler(Sender: TObject);
procedure WorksheetAddedHandler(Sender: TObject; ASheet: TsWorksheet); procedure WorksheetAddedHandler(Sender: TObject; ASheet: TsWorksheet);
procedure WorksheetChangedHandler(Sender: TObject; ASheet: TsWorksheet); procedure WorksheetChangedHandler(Sender: TObject; ASheet: TsWorksheet);
@ -761,6 +762,7 @@ begin
FWorkbook.OnChangeWorksheet := @WorksheetChangedHandler; FWorkbook.OnChangeWorksheet := @WorksheetChangedHandler;
FWorkbook.OnRemoveWorksheet := @WorksheetRemovedHandler; FWorkbook.OnRemoveWorksheet := @WorksheetRemovedHandler;
FWorkbook.OnSelectWorksheet := @WorksheetSelectedHandler; FWorkbook.OnSelectWorksheet := @WorksheetSelectedHandler;
FWorkbook.OnChangePalette := @WorkbookChangedPaletteHandler;
// Pass options to workbook // Pass options to workbook
SetOptions(FOptions); SetOptions(FOptions);
end; end;
@ -867,9 +869,6 @@ procedure TsWorkbookSource.NotifyListeners(AChangedItems: TsNotificationItems;
var var
i: Integer; i: Integer;
begin begin
//if FControlLockCount > 0 then
// exit;
for i:=0 to FListeners.Count-1 do for i:=0 to FListeners.Count-1 do
if TObject(FListeners[i]) is TsCellCombobox then if TObject(FListeners[i]) is TsCellCombobox then
TsCellCombobox(FListeners[i]).ListenerNotification(AChangedItems, AData) TsCellCombobox(FListeners[i]).ListenerNotification(AChangedItems, AData)
@ -1069,6 +1068,15 @@ begin
FPendingOperation := AOperation; FPendingOperation := AOperation;
end; end;
{@@ ----------------------------------------------------------------------------
Event handler called whenever the palette of the workbook is changed.
-------------------------------------------------------------------------------}
procedure TsWorkbookSource.WorkbookChangedPaletteHandler(Sender: TObject);
begin
Unused(Sender);
NotifyListeners([lniPalette]);
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Event handler called whenever a new workbook is opened. Event handler called whenever a new workbook is opened.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
@ -1825,14 +1833,21 @@ var
activeCell: PCell; activeCell: PCell;
begin begin
Unused(AData); Unused(AData);
if (Worksheet = nil) or ([lniCell, lniSelection]*AChangedItems = []) then if (Worksheet = nil) or
([lniCell, lniSelection, lniPalette]*AChangedItems = [])
then
exit; exit;
activeCell := GetActiveCell; activeCell := GetActiveCell;
if (([lniCell]*AChangedItems <>[]) and (PCell(AData) = activeCell)) or if (([lniCell]*AChangedItems <> []) and (PCell(AData) = activeCell)) or
(lniSelection in AChangedItems) (lniSelection in AChangedItems)
then then
ExtractFromCell(activeCell); ExtractFromCell(activeCell);
if (FFormatItem in [cfiFontColor, cfiBorderColor, cfiBackgroundColor]) and
(lniPalette in AChangedItems)
then
Populate;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------