1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <formula/errorcodes.hxx>
23 #include <formula/opcode.hxx>
24 #include <svx/fmshell.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <editeng/svxenum.hxx>
27 #include <o3tl/deleter.hxx>
31 #include <shellids.hxx>
32 #include <tabprotection.hxx>
33 #include <com/sun/star/ui/dialogs/DialogClosedEvent.hpp>
34 #include <com/sun/star/sheet/XSpreadsheet.hpp>
35 #include <dragdata.hxx>
41 class SfxAbstractTabDialog
;
44 class SvxNumberInfoItem
;
45 struct SfxChildWinInfo
;
46 class AbstractScInsertTableDlg
;
47 class AbstractScMoveTableDlg
;
48 class AbstractScTabBgColorDlg
;
49 class AbstractScStringInputDlg
;
50 class ScStyleSaveData
;
52 class ScAuditingShell
;
54 class ScDrawTextObjectBar
;
58 class ScDrawFormShell
;
60 class ScOleObjectShell
;
64 class ScPageBreakShell
;
66 class ScNavigatorSettings
;
68 class ScDrawTransferObj
;
69 class ScCondFormatDlgData
;
70 class ScDispatchProviderInterceptor
;
72 namespace sc
{ class SparklineShell
; }
74 struct ScHeaderFieldData
;
76 namespace editeng
{ class SvxBorderLine
; }
78 namespace com::sun::star::frame
{ class XDispatchProviderInterceptor
; }
85 enum ObjectSelectionType
102 class ScFormEditData
;
103 class ScViewOptiChangesListener
;
104 class SAL_DLLPUBLIC_RTTI ScTabViewShell
: public SfxViewShell
, public ScDBFunc
107 rtl::Reference
<ScViewOptiChangesListener
> mChangesListener
;
108 struct SendFormulabarUpdate
111 OUString m_aSelection
;
112 sal_uInt64 m_nShellId
;
113 std::chrono::steady_clock::time_point m_nTimeStamp
;
115 SendFormulabarUpdate()
123 SendFormulabarUpdate maSendFormulabarUpdate
;
125 ObjectSelectionType eCurOST
;
126 sal_uInt16 nDrawSfxId
;
127 SdrObjKind eFormObjKind
;
128 OUString sDrawCustom
; // current custom shape type
129 std::unique_ptr
<ScDrawShell
> pDrawShell
;
130 std::unique_ptr
<ScDrawTextObjectBar
> pDrawTextShell
;
131 std::unique_ptr
<ScEditShell
> pEditShell
;
132 std::unique_ptr
<ScPivotShell
> pPivotShell
;
133 std::unique_ptr
<sc::SparklineShell
> m_pSparklineShell
;
134 std::unique_ptr
<ScAuditingShell
> pAuditingShell
;
135 std::unique_ptr
<ScDrawFormShell
> pDrawFormShell
;
136 std::unique_ptr
<ScCellShell
> pCellShell
;
137 std::unique_ptr
<ScOleObjectShell
> pOleObjectShell
;
138 std::unique_ptr
<ScChartShell
> pChartShell
;
139 std::unique_ptr
<ScGraphicShell
> pGraphicShell
;
140 std::unique_ptr
<ScMediaShell
> pMediaShell
;
141 std::unique_ptr
<ScPageBreakShell
> pPageBreakShell
;
142 std::unique_ptr
<svx::ExtrusionBar
> pExtrusionBarShell
;
143 std::unique_ptr
<svx::FontworkBar
> pFontworkBarShell
;
145 std::unique_ptr
<FmFormShell
> pFormShell
;
147 std::unique_ptr
<ScFormEditData
> mpFormEditData
;
148 std::unique_ptr
<ScInputHandler
, o3tl::default_delete
<ScInputHandler
>> mpInputHandler
; // for OLE input cell
150 std::unique_ptr
<::editeng::SvxBorderLine
> pCurFrameLine
;
152 rtl::Reference
<ScDispatchProviderInterceptor
> xDisProvInterceptor
;
156 ScTabViewTarget aTarget
;
157 std::unique_ptr
<ScDPObject
> pDialogDPObject
;
159 std::unique_ptr
<ScNavigatorSettings
> pNavSettings
;
161 // used in first Activate
165 bool bActiveDrawTextSh
;
166 bool bActiveDrawFormSh
;
167 bool bActiveOleObjectSh
;
169 bool bActiveGraphicSh
;
173 bool bFormShellAtTop
; // does the FormShell need to be on top?
175 bool bDontSwitch
; // Don't turn off EditShell
176 bool bInFormatDialog
; // for GetSelectionText
178 bool bReadOnly
; // to detect status changes
182 bool bForceFocusOnCurCell
; // #i123629#
184 bool bInPrepareClose
;
189 sal_uInt16 nCurRefDlgId
;
191 std::unique_ptr
<SfxBroadcaster
> pAccessibilityBroadcaster
;
193 // ugly hack for Add button in ScNameDlg
194 std::map
<OUString
, ScRangeName
> m_RangeMap
;
199 std::unique_ptr
<ScDragData
> m_pDragData
;
200 std::shared_ptr
<ScCondFormatDlgData
> m_pScCondFormatDlgItem
;
202 // Chart insert wizard's mark to make sure it undoes the correct thing in LOK case
203 UndoStackMark m_InsertWizardUndoMark
= MARK_INVALID
;
206 void Construct( TriState nForceDesignMode
);
208 SfxShell
* GetMySubShell() const;
210 void DoReadUserData( std::u16string_view rData
);
211 void DoReadUserDataSequence( const css::uno::Sequence
< css::beans::PropertyValue
>& rSettings
);
212 bool IsSignatureLineSelected();
213 bool IsSignatureLineSigned();
214 bool IsQRCodeSelected();
216 DECL_LINK( SimpleRefClose
, const OUString
*, void );
217 DECL_LINK( SimpleRefDone
, const OUString
&, void );
218 DECL_LINK( SimpleRefAborted
, const OUString
&, void );
219 DECL_LINK( SimpleRefChange
, const OUString
&, void );
220 DECL_LINK( FormControlActivated
, LinkParamNone
*, void );
221 DECL_LINK( DialogClosedHdl
, css::ui::dialogs::DialogClosedEvent
*, void );
224 virtual void Activate(bool bMDI
) override
;
225 virtual void Deactivate(bool bMDI
) override
;
226 virtual bool PrepareClose( bool bUI
= true ) override
;
228 virtual void ShowCursor(bool bOn
) override
;
230 virtual void Move() override
; // notification
232 virtual void InnerResizePixel( const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
) override
; // new
233 virtual void OuterResizePixel( const Point
&rOfs
, const Size
&rSize
) override
;
234 virtual void SetZoomFactor( const Fraction
&rZoomX
, const Fraction
&rZoomY
) override
;
236 virtual void QueryObjAreaPixel( tools::Rectangle
& rRect
) const override
;
238 virtual OUString
GetSelectionText( bool bWholeWord
= false, bool bOnlyASample
= false ) override
;
239 virtual bool HasSelection( bool bText
= true ) const override
;
241 virtual void WriteUserData(OUString
&, bool bBrowse
= false) override
;
242 virtual void ReadUserData(const OUString
&, bool bBrowse
= false) override
;
243 virtual void WriteUserDataSequence (css::uno::Sequence
< css::beans::PropertyValue
>& ) override
;
244 virtual void ReadUserDataSequence (const css::uno::Sequence
< css::beans::PropertyValue
>& ) override
;
246 virtual void UIDeactivated( SfxInPlaceClient
* pClient
) override
;
248 virtual bool KeyInput( const KeyEvent
&rKeyEvent
) override
;
249 virtual SdrView
* GetDrawView() const override
;
252 SFX_DECL_INTERFACE(SCID_TABVIEW_SHELL
)
253 SFX_DECL_VIEWFACTORY(ScTabViewShell
);
256 /// SfxInterface initializer.
257 static void InitInterface_Impl();
260 /** -> Clone Method for Factory
261 Created from a general shell and inherit as much as possible */
262 ScTabViewShell(SfxViewFrame
& rViewFrame
, SfxViewShell
* pOldSh
);
264 virtual ~ScTabViewShell() override
;
266 weld::Window
* GetDialogParent();
268 SC_DLLPUBLIC
bool IsRefInputMode() const;
269 void ExecuteInputDirect();
271 void HandleDuplicateRecords(css::uno::Reference
<css::sheet::XSpreadsheet
> ActiveSheet
,
272 const css::table::CellRangeAddress
& aRange
, bool bRemove
,
273 bool bIncludesHeaders
, bool bDuplicateRows
,
274 const std::vector
<int>& rSelectedEntries
);
275 css::uno::Reference
<css::sheet::XSpreadsheet
> GetRangeWithSheet(css::table::CellRangeAddress
& rRangeData
, bool& bHasData
, bool bHasUnoArguments
);
276 void ExtendSingleSelection(css::table::CellRangeAddress
& rRangeData
);
278 const ScInputHandler
* GetInputHandler() const { return mpInputHandler
.get(); }
279 ScInputHandler
* GetInputHandler() { return mpInputHandler
.get(); }
280 SC_DLLPUBLIC
const OUString
* GetEditString() const;
281 void UpdateInputHandler( bool bForce
= false, bool bStopEditing
= true );
282 void UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust
);
283 bool TabKeyInput(const KeyEvent
& rKEvt
);
284 bool SfxKeyInput(const KeyEvent
& rKEvt
);
288 ::editeng::SvxBorderLine
* GetDefaultFrameLine() const { return pCurFrameLine
.get(); }
289 void SetDefaultFrameLine(const ::editeng::SvxBorderLine
* pLine
);
291 SC_DLLPUBLIC
void Execute( SfxRequest
& rReq
);
292 SC_DLLPUBLIC
void GetState( SfxItemSet
& rSet
);
294 void ExecuteTable( SfxRequest
& rReq
);
295 void GetStateTable( SfxItemSet
& rSet
);
297 void WindowChanged();
298 SC_DLLPUBLIC
void ExecDraw(SfxRequest
&);
299 void ExecDrawIns(SfxRequest
& rReq
);
300 void GetDrawState(SfxItemSet
&rSet
);
301 void GetDrawInsState(SfxItemSet
&rSet
);
302 void ExecGallery(const SfxRequest
& rReq
);
304 void ExecChildWin(const SfxRequest
& rReq
);
306 void ExecImageMap( SfxRequest
& rReq
);
307 void GetImageMapState( SfxItemSet
& rSet
);
309 void ExecuteSave( SfxRequest
& rReq
);
310 void GetSaveState( SfxItemSet
& rSet
);
311 void ExecSearch( SfxRequest
& rReq
);
313 void ExecuteUndo(SfxRequest
& rReq
);
314 void GetUndoState(SfxItemSet
&rSet
);
316 void ExecuteObject(const SfxRequest
& rReq
);
317 void GetObjectState(SfxItemSet
&rSet
);
319 void ExecDrawOpt(const SfxRequest
& rReq
);
320 void GetDrawOptState(SfxItemSet
&rSet
);
322 void ExecStyle(SfxRequest
& rReq
);
323 void GetStyleState(SfxItemSet
&rSet
);
325 void UpdateDrawShell();
326 SC_DLLPUBLIC
void SetDrawShell( bool bActive
);
327 void SetDrawTextShell( bool bActive
);
329 void SetPivotShell( bool bActive
);
330 void SetSparklineShell(bool bActive
);
331 void SetDialogDPObject( std::unique_ptr
<ScDPObject
> pObj
);
332 const ScDPObject
* GetDialogDPObject() const { return pDialogDPObject
.get(); }
334 void SetDontSwitch(bool bFlag
){bDontSwitch
=bFlag
;}
336 void SetAuditShell( bool bActive
);
337 void SetDrawFormShell( bool bActive
);
338 void SetEditShell(EditView
* pView
, bool bActive
);
339 void SetOleObjectShell( bool bActive
);
340 void SetChartShell( bool bActive
);
341 void SetGraphicShell( bool bActive
);
342 void SetMediaShell( bool bActive
);
344 void SetDrawShellOrSub();
345 void SetCurSubShell( ObjectSelectionType eOST
, bool bForce
= false );
347 void SetFormShellAtTop( bool bSet
);
349 ObjectSelectionType
GetCurObjectSelectionType() const { return eCurOST
; }
351 virtual ErrCode
DoVerb(sal_Int32 nVerb
) override
;
353 void StopEditShell();
354 bool IsDrawTextShell() const;
355 bool IsAuditShell() const;
357 void SetDrawTextUndo( SfxUndoManager
* pUndoMgr
);
359 void FillFieldData( ScHeaderFieldData
& rData
);
361 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
363 ScNavigatorSettings
* GetNavigatorSettings();
366 virtual SfxPrinter
* GetPrinter( bool bCreate
= false ) override
;
367 virtual sal_uInt16
SetPrinter( SfxPrinter
* pNewPrinter
,
368 SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
) override
;
370 virtual bool HasPrintOptionsPage() const override
;
371 virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rOptions
) override
;
373 void ConnectObject( const SdrOle2Obj
* pObj
);
374 void ActivateObject(SdrOle2Obj
* pObj
, sal_Int32 nVerb
);
376 void DeactivateOle();
378 SAL_RET_MAYBENULL SC_DLLPUBLIC
static ScTabViewShell
* GetActiveViewShell();
380 std::shared_ptr
<SfxModelessDialogController
> CreateRefDialogController(SfxBindings
* pB
, SfxChildWindow
* pCW
,
381 SfxChildWinInfo
* pInfo
,
382 weld::Window
* pParent
, sal_uInt16 nSlotId
);
384 void UpdateOleZoom();
386 virtual const FmFormShell
* GetFormShell() const override
{ return pFormShell
.get(); }
387 virtual FmFormShell
* GetFormShell() override
{ return pFormShell
.get(); }
389 void InsertURL( const OUString
& rName
, const OUString
& rURL
, const OUString
& rTarget
,
391 void InsertURLButton( const OUString
& rName
, const OUString
& rURL
, const OUString
& rTarget
,
392 const Point
* pInsPos
);
393 void InsertURLField( const OUString
& rName
, const OUString
& rURL
, const OUString
& rTarget
);
395 SC_DLLPUBLIC
bool SelectObject( std::u16string_view rName
);
397 void SetInFormatDialog(bool bFlag
) {bInFormatDialog
=bFlag
;}
399 void ForceMove() { Move(); }
401 SC_DLLPUBLIC
static std::unique_ptr
<SvxNumberInfoItem
> MakeNumberInfoItem( ScDocument
& rDoc
, const ScViewData
& rViewData
);
403 static void UpdateNumberFormatter( const SvxNumberInfoItem
& rInfoItem
);
405 void ExecuteCellFormatDlg( SfxRequest
& rReq
, const OUString
&rTabPage
);
407 bool GetFunction( OUString
& rFuncStr
, FormulaError nErrCode
);
409 void StartSimpleRefDialog( const OUString
& rTitle
, const OUString
& rInitVal
,
410 bool bCloseOnButtonUp
, bool bSingleCell
, bool bMultiSelection
);
411 void StopSimpleRefDialog();
413 void SetCurRefDlgId( sal_uInt16 nNew
);
415 void AddAccessibilityObject( SfxListener
& rObject
);
416 void RemoveAccessibilityObject( SfxListener
& rObject
);
417 void BroadcastAccessibility( const SfxHint
&rHint
);
418 bool HasAccessibilityObjects() const;
420 bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash
);
421 void ExecuteOnlyActiveSheetSavedDlg();
423 void FinishProtectTable();
424 void ExecProtectTable( SfxRequest
& rReq
);
426 using ScTabView::ShowCursor
;
428 bool IsActive() const { return bIsActive
; }
429 OUString
GetFormula(const ScAddress
& rAddress
);
430 bool UseSubTotal(ScRangeList
* pRangeList
);
431 OUString
DoAutoSum(bool& rRangeFinder
, bool& rSubTotal
, const OpCode eCode
);
433 // ugly hack to call Define Names from Manage Names
434 void SwitchBetweenRefDialogs(SfxModelessDialogController
* pDialog
);
436 bool GetForceFocusOnCurCell() const { return bForceFocusOnCurCell
; }
437 void SetForceFocusOnCurCell(bool bFlag
) { bForceFocusOnCurCell
=bFlag
; }
438 /// See SfxViewShell::getPart().
439 int getPart() const override
;
440 /// See SfxViewShell::afterCallbackRegistered().
441 void afterCallbackRegistered() override
;
442 /// See SfxViewShell::NotifyCursor().
443 void NotifyCursor(SfxViewShell
* pViewShell
) const override
;
444 /// See SfxViewShell::GetColorConfigColor().
445 ::Color
GetColorConfigColor(svtools::ColorConfigEntry nColorType
) const override
;
446 /// Emits a LOK_CALLBACK_INVALIDATE_HEADER for all views whose current tab is equal to nCurrentTabIndex
447 static void notifyAllViewsHeaderInvalidation(const SfxViewShell
* pForViewShell
, HeaderType eHeaderType
, SCTAB nCurrentTabIndex
);
448 static bool isAnyEditViewInRange(const SfxViewShell
* pForViewShell
, bool bColumns
, SCCOLROW nStart
, SCCOLROW nEnd
);
449 /// Emits a LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY for all views whose current tab
450 /// is equal to nCurrentTabIndex
451 static void notifyAllViewsSheetGeomInvalidation(const SfxViewShell
* pForViewShell
, bool bColumns
, bool bRows
, bool bSizes
,
452 bool bHidden
, bool bFiltered
, bool bGroups
, SCTAB nCurrentTabIndex
);
453 void LOKSendFormulabarUpdate(EditView
* pEditView
, const OUString
& rText
, const ESelection
& rSelection
);
454 css::uno::Reference
<css::drawing::XShapes
> getSelectedXShapes();
455 SC_DLLPUBLIC
static css::uno::Reference
<css::datatransfer::XTransferable2
> GetClipData(vcl::Window
* pWin
);
457 void InitFormEditData();
458 void ClearFormEditData();
459 ScFormEditData
* GetFormEditData() { return mpFormEditData
.get(); }
461 virtual tools::Rectangle
getLOKVisibleArea() const override
;
463 const ScDragData
& GetDragData() const { return *m_pDragData
; }
464 void SetDragObject(ScTransferObj
* pCellObj
, ScDrawTransferObj
* pDrawObj
);
465 void ResetDragObject();
466 void SetDragLink(const OUString
& rDoc
, const OUString
& rTab
, const OUString
& rArea
);
467 void SetDragJump(ScDocument
* pLocalDoc
, const OUString
& rTarget
, const OUString
& rText
);
469 void SetMoveKeepEdit(bool value
) { bMoveKeepEdit
= value
; };
470 bool GetMoveKeepEdit() { return bMoveKeepEdit
; };
472 void setScCondFormatDlgItem(const std::shared_ptr
<ScCondFormatDlgData
>& rItem
) { m_pScCondFormatDlgItem
= rItem
; }
473 const std::shared_ptr
<ScCondFormatDlgData
>& getScCondFormatDlgItem() const { return m_pScCondFormatDlgItem
; }
475 void SetInsertWizardUndoMark();
478 void ExecuteMoveTable( SfxRequest
& rReq
);
479 void DoMoveTableFromDialog( SfxRequest
& rReq
, const VclPtr
<AbstractScMoveTableDlg
>& pDlg
);
480 void ExecuteInsertTable( SfxRequest
& rReq
);
481 void DoInsertTableFromDialog( SfxRequest
& rReq
, const VclPtr
<AbstractScInsertTableDlg
>& pDlg
);
482 void ExecuteAppendOrRenameTable( SfxRequest
& rReq
);
483 void ExecuteAppendOrRenameTableDialog( const VclPtr
<AbstractScStringInputDlg
>& pDlg
, const std::shared_ptr
<SfxRequest
>& xReq
, sal_uInt16 nSlot
);
484 bool DoAppendOrRenameTableDialog( sal_Int32 nResult
, const VclPtr
<AbstractScStringInputDlg
>& pDlg
, const std::shared_ptr
<SfxRequest
>& xReq
, sal_uInt16 nSlot
);
485 void ExecuteSetTableBackgroundCol( SfxRequest
& rReq
);
486 void ExecuteTableBackgroundDialog( const VclPtr
<AbstractScTabBgColorDlg
>& pDlg
, const std::shared_ptr
<SfxRequest
>& xReq
, Color aOldTabBgColor
, sal_uInt16 nSlot
);
487 bool DoTableBackgroundDialog( sal_Int32 nResult
, const VclPtr
<AbstractScTabBgColorDlg
>& pDlg
, const std::shared_ptr
<SfxRequest
>& xReq
, Color aOldTabBgColor
, sal_uInt16 nSlot
);
488 void ExecuteStyleEdit(SfxRequest
& rReq
, SfxStyleSheetBase
* pStyleSheet
, sal_uInt16 nRetMask
, sal_uInt16 nSlotId
,
489 bool bAddUndo
, bool bUndo
,
490 const std::shared_ptr
<ScStyleSaveData
>& rOldData
,
491 const std::shared_ptr
<ScStyleSaveData
>& rNewData
,
492 SfxStyleFamily eFamily
, bool bStyleToMarked
, bool bListAction
,
493 SdrObject
* pEditObject
, ESelection aSelection
);
494 void ExecuteStyleEditDialog(VclPtr
<SfxAbstractTabDialog
> pDlg
,
495 SfxStyleSheetBase
* pStyleSheet
, sal_uInt16 nResult
, sal_uInt16
& rnRetMask
,
496 std::shared_ptr
<SfxItemSet
> xOldSet
, sal_uInt16 nSlotId
,
498 ScStyleSaveData
& rNewData
, std::u16string_view aOldName
);
499 void ExecuteStyleEditPost(SfxRequest
& rReq
, SfxStyleSheetBase
* pStyleSheet
, sal_uInt16 nSlotId
,
500 sal_uInt16 nRetMask
, bool bAddUndo
, bool bUndo
, SfxStyleFamily eFamily
,
501 ScStyleSaveData
& rOldData
, ScStyleSaveData
& rNewData
,
502 bool bStyleToMarked
, bool bListAction
,
503 SdrObject
* pEditObject
, ESelection aSelection
);
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */