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 .
23 #include <o3tl/deleter.hxx>
24 #include <vcl/timer.hxx>
25 #include <svl/lstner.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/module.hxx>
29 #include "shellids.hxx"
30 #include <unotools/options.hxx>
31 #include <com/sun/star/uno/Reference.h>
39 class SfxErrorHandler
;
43 namespace svtools
{ class ColorConfig
; }
44 namespace ooo::vba
{ class XSinkCaller
; }
45 namespace com::sun::star::uno
{ class Any
; }
46 namespace com::sun::star::uno
{ template <typename
> class Sequence
; }
60 class ScDefaultsOptions
;
61 class ScFormulaOptions
;
71 class ScDrawTransferObj
;
72 class ScSelectionTransferObj
;
76 class SfxDialogController
;
78 class SAL_DLLPUBLIC_RTTI ScModule final
: public SfxModule
, public SfxListener
, public utl::ConfigurationListener
81 std::unique_ptr
<ScDragData
> m_pDragData
;
82 ScSelectionTransferObj
* m_pSelTransfer
;
83 rtl::Reference
<ScMessagePool
> m_pMessagePool
;
84 // there is no global InputHandler anymore, each View has its own
85 ScInputHandler
* m_pRefInputHandler
;
86 std::unique_ptr
<ScViewCfg
, o3tl::default_delete
<ScViewCfg
>> m_pViewCfg
;
87 std::unique_ptr
<ScDocCfg
, o3tl::default_delete
<ScDocCfg
>> m_pDocCfg
;
88 std::unique_ptr
<ScAppCfg
, o3tl::default_delete
<ScAppCfg
>> m_pAppCfg
;
89 std::unique_ptr
<ScDefaultsCfg
> m_pDefaultsCfg
;
90 std::unique_ptr
<ScFormulaCfg
> m_pFormulaCfg
;
91 std::unique_ptr
<ScInputCfg
> m_pInputCfg
;
92 std::unique_ptr
<ScPrintCfg
> m_pPrintCfg
;
93 std::unique_ptr
<ScNavipiCfg
> m_pNavipiCfg
;
94 std::unique_ptr
<ScAddInCfg
> m_pAddInCfg
;
95 std::unique_ptr
<svtools::ColorConfig
> m_pColorConfig
;
96 std::unique_ptr
<SvtCTLOptions
> m_pCTLOptions
;
97 std::unique_ptr
<SvtUserOptions
> m_pUserOptions
;
98 std::unique_ptr
<SfxErrorHandler
> m_pErrorHdl
;
99 sal_uInt16 m_nCurRefDlgId
;
100 bool m_bIsWaterCan
:1;
101 bool m_bIsInEditCommand
:1;
102 bool m_bIsInExecuteDrop
:1;
103 bool m_bIsInSharedDocLoading
:1;
104 bool m_bIsInSharedDocSaving
:1;
106 // a way to find existing Dialogs for a given parent Window of the slot type
107 std::map
<sal_uInt16
, std::vector
<std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>>> m_mapRefController
;
109 css::uno::Reference
< ooo::vba::XSinkCaller
> mxAutomationApplicationEventsCaller
;
112 SFX_DECL_INTERFACE(SCID_APP
)
115 /// SfxInterface initializer.
116 static void InitInterface_Impl();
119 ScModule( SfxObjectFactory
* pFact
);
120 virtual ~ScModule() override
;
122 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
123 virtual void ConfigurationChanged( utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
126 // moved by the application
128 DECL_DLLPRIVATE_LINK( IdleHandler
, Timer
*, void ); // Timer instead of idle
129 DECL_DLLPRIVATE_LINK( CalcFieldValueHdl
, EditFieldInfo
*, void );
131 void Execute( SfxRequest
& rReq
);
132 void GetState( SfxItemSet
& rSet
);
133 static void HideDisabledSlots( SfxItemSet
& rSet
);
135 void AnythingChanged();
138 const ScDragData
& GetDragData() const;
139 void SetDragObject( ScTransferObj
* pCellObj
, ScDrawTransferObj
* pDrawObj
);
140 void ResetDragObject();
142 const OUString
& rDoc
, const OUString
& rTab
, const OUString
& rArea
);
144 ScDocument
* pLocalDoc
, const OUString
& rTarget
, const OUString
& rText
);
146 static ScDocument
* GetClipDoc(); // called from document - should be removed later
149 ScSelectionTransferObj
* GetSelectionTransfer() const { return m_pSelTransfer
; }
150 void SetSelectionTransfer( ScSelectionTransferObj
* pNew
);
152 void SetWaterCan( bool bNew
) { m_bIsWaterCan
= bNew
; }
153 bool GetIsWaterCan() const { return m_bIsWaterCan
; }
155 void SetInEditCommand( bool bNew
) { m_bIsInEditCommand
= bNew
; }
157 void SetInExecuteDrop( bool bNew
) { m_bIsInExecuteDrop
= bNew
; }
158 bool IsInExecuteDrop() const { return m_bIsInExecuteDrop
; }
161 const ScViewOptions
& GetViewOptions ();
162 SC_DLLPUBLIC
const ScDocOptions
& GetDocOptions ();
163 SC_DLLPUBLIC
const ScAppOptions
& GetAppOptions ();
164 SC_DLLPUBLIC
const ScDefaultsOptions
& GetDefaultsOptions ();
165 SC_DLLPUBLIC
const ScFormulaOptions
& GetFormulaOptions ();
166 SC_DLLPUBLIC
const ScInputOptions
& GetInputOptions ();
167 SC_DLLPUBLIC
const ScPrintOptions
& GetPrintOptions ();
168 void SetViewOptions ( const ScViewOptions
& rOpt
);
169 SC_DLLPUBLIC
void SetDocOptions ( const ScDocOptions
& rOpt
);
170 SC_DLLPUBLIC
void SetAppOptions ( const ScAppOptions
& rOpt
);
171 SC_DLLPUBLIC
void SetDefaultsOptions ( const ScDefaultsOptions
& rOpt
);
172 SC_DLLPUBLIC
void SetFormulaOptions ( const ScFormulaOptions
& rOpt
);
173 SC_DLLPUBLIC
void SetInputOptions ( const ScInputOptions
& rOpt
);
174 void SetPrintOptions ( const ScPrintOptions
& rOpt
);
175 void InsertEntryToLRUList(sal_uInt16 nFIndex
);
177 static void GetSpellSettings( LanguageType
& rDefLang
, LanguageType
& rCjkLang
, LanguageType
& rCtlLang
);
178 static void SetAutoSpellProperty( bool bSet
);
179 static bool GetAutoSpellProperty();
180 static bool HasThesaurusLanguage( LanguageType nLang
);
182 static LanguageType
GetOptDigitLanguage(); // from CTL options
184 ScNavipiCfg
& GetNavipiCfg();
185 ScAddInCfg
& GetAddInCfg();
186 svtools::ColorConfig
& GetColorConfig();
187 SC_DLLPUBLIC SvtUserOptions
& GetUserOptions();
189 void ModifyOptions( const SfxItemSet
& rOptSet
);
192 bool IsEditMode(); // not for SC_INPUT_TYPE
193 bool IsInputMode(); // also for SC_INPUT_TYPE
194 void SetInputMode( ScInputMode eMode
, const OUString
* pInitText
= nullptr );
195 bool InputKeyEvent( const KeyEvent
& rKEvt
, bool bStartEdit
= false );
196 SC_DLLPUBLIC
void InputEnterHandler( ScEnterMode nBlockMode
= ScEnterMode::NORMAL
, bool bBeforeSavingInLOK
= false );
197 void InputCancelHandler();
198 void InputSelection( const EditView
* pView
);
199 void InputChanged( const EditView
* pView
);
200 ScInputHandler
* GetInputHdl( ScTabViewShell
* pViewSh
= nullptr, bool bUseRef
= true );
201 void SetRefInputHdl( ScInputHandler
* pNew
);
202 ScInputHandler
* GetRefInputHdl() { return m_pRefInputHandler
;}
204 void ViewShellGone(const ScTabViewShell
* pViewSh
);
205 void ViewShellChanged(bool bStopEditing
);
206 // communication with function-autopilot
207 void InputGetSelection( sal_Int32
& rStart
, sal_Int32
& rEnd
);
208 void InputSetSelection( sal_Int32 nStart
, sal_Int32 nEnd
);
209 void InputReplaceSelection( std::u16string_view aStr
);
210 void InputTurnOffWinEngine();
211 void ActivateInputWindow( const OUString
* pStr
= nullptr,
212 bool bMatrix
= false );
214 // input of reference:
215 SC_DLLPUBLIC
void SetRefDialog( sal_uInt16 nId
, bool bVis
, SfxViewFrame
* pViewFrm
= nullptr );
216 bool IsModalMode(SfxObjectShell
* pDocSh
= nullptr);
217 bool IsFormulaMode();
218 bool IsRefDialogOpen();
219 bool IsTableLocked();
220 void SetReference( const ScRange
& rRef
, ScDocument
& rDoc
,
221 const ScMarkData
* pMarkData
= nullptr );
224 sal_uInt16
GetCurRefDlgId() const { return m_nCurRefDlgId
; }
226 // virtual methods for the options dialog
227 virtual std::optional
<SfxItemSet
> CreateItemSet( sal_uInt16 nId
) override
;
228 virtual void ApplyItemSet( sal_uInt16 nId
, const SfxItemSet
& rSet
) override
;
229 virtual std::unique_ptr
<SfxTabPage
> CreateTabPage( sal_uInt16 nId
, weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
) override
;
230 virtual std::optional
<SfxStyleFamilies
> CreateStyleFamilies() override
;
232 void SetInSharedDocLoading( bool bNew
) { m_bIsInSharedDocLoading
= bNew
; }
233 bool IsInSharedDocLoading() const { return m_bIsInSharedDocLoading
; }
234 void SetInSharedDocSaving( bool bNew
) { m_bIsInSharedDocSaving
= bNew
; }
235 bool IsInSharedDocSaving() const { return m_bIsInSharedDocSaving
; }
237 SC_DLLPUBLIC
void RegisterRefController(sal_uInt16 nSlotId
, std::shared_ptr
<SfxDialogController
>& rWnd
, weld::Window
* pWndAncestor
);
238 SC_DLLPUBLIC
void UnregisterRefController(sal_uInt16 nSlotId
, const std::shared_ptr
<SfxDialogController
>& rWnd
);
239 SC_DLLPUBLIC
std::shared_ptr
<SfxDialogController
> Find1RefWindow(sal_uInt16 nSlotId
, const weld::Window
*pWndAncestor
);
241 SC_DLLPUBLIC
void RegisterAutomationApplicationEventsCaller(css::uno::Reference
< ooo::vba::XSinkCaller
> const& xCaller
);
242 SC_DLLPUBLIC
void CallAutomationApplicationEventSinks(const OUString
& Method
, css::uno::Sequence
< css::uno::Any
>& Arguments
);
245 #define SC_MOD() ( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule::Calc)) )
247 void global_InitAppOptions();
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */