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 .
19 #ifndef INCLUDED_SFX2_APP_HXX
20 #define INCLUDED_SFX2_APP_HXX
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <comphelper/errcode.hxx>
27 #include <svl/poolitem.hxx>
28 #include <vcl/bitmapex.hxx>
29 #include <tools/link.hxx>
30 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
31 #include <unordered_map>
33 #include <sfx2/shell.hxx>
35 namespace com::sun::star::frame
{ class XFrame
; }
36 namespace com::sun::star::script
{ class XLibraryContainer
; }
38 namespace weld
{ class Window
; }
42 class SfxAppData_Impl
;
47 class SfxObjectShellLock
;
53 class SfxFilterMatcher
;
55 struct SfxChildWinFactory
;
56 struct SfxStbCtrlFactory
;
57 struct SfxTbxCtrlFactory
;
68 enum class SfxToolsModule
78 class SFX2_DLLPUBLIC SfxLinkItem final
: public SfxPoolItem
80 Link
<SfxPoolItem
const *, void> aLink
;
82 SfxLinkItem( sal_uInt16 nWhichId
, const Link
<SfxPoolItem
const *, void>& rValue
) : SfxPoolItem( nWhichId
)
85 virtual SfxLinkItem
* Clone( SfxItemPool
* = nullptr ) const override
86 { return new SfxLinkItem( *this ); }
87 virtual bool operator==( const SfxPoolItem
& rL
) const override
88 { return static_cast<const SfxLinkItem
&>(rL
).aLink
== aLink
; }
89 const Link
<SfxPoolItem
const *, void>&
90 GetValue() const { return aLink
; }
93 // This is a singleton class. Sad that there apparently is no other
94 // way than a comment like this to indicate that to the code reader.
95 class SFX2_DLLPUBLIC SfxApplication final
: public SfxShell
97 std::unique_ptr
<SfxAppData_Impl
> pImpl
;
99 DECL_DLLPRIVATE_STATIC_LINK( SfxApplication
, GlobalBasicErrorHdl_Impl
, StarBASIC
*, bool );
104 SFX_DECL_INTERFACE(SFX_INTERFACE_SFXAPP
)
107 /// SfxInterface initializer.
108 static void InitInterface_Impl();
112 virtual ~SfxApplication() override
;
113 static SfxApplication
* GetOrCreate();
114 static SfxApplication
* Get();
118 static bool DdeExecute( const OUString
& rCmd
);
120 bool InitializeDde();
121 const DdeService
* GetDdeService() const;
122 DdeService
* GetDdeService();
124 void AddDdeTopic( SfxObjectShell
* );
126 void RemoveDdeTopic( SfxObjectShell
const * );
130 * @param pArgs Takes ownership
132 ErrCodeMsg
LoadTemplate( SfxObjectShellLock
& xDoc
, const OUString
& rFileName
, std::unique_ptr
<SfxItemSet
> pArgs
);
133 weld::Window
* GetTopWindow() const;
136 SfxFilterMatcher
& GetFilterMatcher();
137 SfxProgress
* GetProgress() const;
138 sal_uInt16
GetFreeIndex();
139 void ReleaseIndex(sal_uInt16 i
);
142 static bool IsXScriptURL( const OUString
& rScriptURL
);
143 static OUString
ChooseScript(weld::Window
*pParent
);
144 // if xDocFrame is present, then select that document in the macro organizer by default, otherwise it is typically "Application Macros"
145 // that is preselected
146 static void MacroOrganizer(weld::Window
* pParent
, const css::uno::Reference
<css::frame::XFrame
>& xDocFrame
, sal_Int16 nTabId
);
147 static ErrCode
CallBasic( const OUString
&, BasicManager
*, SbxArray
*pArgs
, SbxValue
*pRet
);
148 static ErrCode
CallAppBasic( const OUString
& i_macroName
)
149 { return CallBasic( i_macroName
, SfxApplication::GetBasicManager(), nullptr, nullptr ); }
150 static BasicManager
* GetBasicManager();
151 css::script::XLibraryContainer
* GetDialogContainer();
152 css::script::XLibraryContainer
* GetBasicContainer();
153 static StarBASIC
* GetBasic();
154 void SaveBasicAndDialogContainer() const;
157 static void GetOptions(SfxItemSet
&);
158 static void SetOptions(const SfxItemSet
&);
159 virtual void Invalidate(sal_uInt16 nId
= 0) override
;
160 void NotifyEvent(const SfxEventHint
& rEvent
, bool bSynchron
= true );
161 bool IsDowning() const;
164 SAL_DLLPRIVATE SfxDispatcher
* GetAppDispatcher_Impl();
165 SAL_DLLPRIVATE SfxDispatcher
* GetDispatcher_Impl();
167 SAL_DLLPRIVATE
void Initialize_Impl();
169 SAL_DLLPRIVATE SfxAppData_Impl
* Get_Impl() const { return pImpl
.get(); }
171 // Object-Factories/global arrays
172 SAL_DLLPRIVATE
void RegisterChildWindow_Impl(SfxModule
*, const SfxChildWinFactory
&);
173 SAL_DLLPRIVATE
void RegisterStatusBarControl_Impl(SfxModule
*, const SfxStbCtrlFactory
&);
174 SAL_DLLPRIVATE
void RegisterToolBoxControl_Impl( SfxModule
*, const SfxTbxCtrlFactory
&);
175 SAL_DLLPRIVATE SfxTbxCtrlFactory
* GetTbxCtrlFactory(const std::type_info
& rSlotType
, sal_uInt16 nSlotID
) const;
176 SAL_DLLPRIVATE SfxStbCtrlFactory
* GetStbCtrlFactory(const std::type_info
& rSlotType
, sal_uInt16 nSlotID
) const;
177 SAL_DLLPRIVATE SfxChildWinFactory
* GetChildWinFactoryById(sal_uInt16 nId
) const;
178 SAL_DLLPRIVATE
std::vector
<SfxViewFrame
*>& GetViewFrames_Impl() const;
179 SAL_DLLPRIVATE
std::vector
<SfxViewShell
*>& GetViewShells_Impl() const;
180 /* unordered_map<ModuleName+Language, acceleratorConfigurationClassInstance> */
181 SAL_DLLPRIVATE
std::unordered_map
<OUString
, css::uno::Reference
<css::ui::XAcceleratorConfiguration
>>& GetAcceleratorConfs_Impl() const;
182 SAL_DLLPRIVATE
std::vector
<SfxObjectShell
*>& GetObjectShells_Impl() const;
183 SAL_DLLPRIVATE
void SetViewFrame_Impl(SfxViewFrame
*pViewFrame
);
186 // TODO/CLEANUP: still needed?
187 SAL_DLLPRIVATE
void NewDocDirectExec_Impl(SfxRequest
&);
188 SAL_DLLPRIVATE
static void NewDocDirectState_Impl(SfxItemSet
&);
189 SAL_DLLPRIVATE
void NewDocExec_Impl(SfxRequest
&);
190 SAL_DLLPRIVATE
void OpenDocExec_Impl(SfxRequest
&);
191 SAL_DLLPRIVATE
void OpenRemoteExec_Impl(SfxRequest
&);
192 SAL_DLLPRIVATE
void SignPDFExec_Impl(SfxRequest
&);
193 SAL_DLLPRIVATE
void MiscExec_Impl(SfxRequest
&);
194 SAL_DLLPRIVATE
void MiscState_Impl(SfxItemSet
&);
195 SAL_DLLPRIVATE
static void PropExec_Impl(SfxRequest
const &);
196 SAL_DLLPRIVATE
static void PropState_Impl(SfxItemSet
&);
197 SAL_DLLPRIVATE
void OfaExec_Impl(SfxRequest
&);
198 SAL_DLLPRIVATE
static void OfaState_Impl(SfxItemSet
&);
200 SAL_DLLPRIVATE
void SetProgress_Impl(SfxProgress
*);
201 SAL_DLLPRIVATE
const OUString
& GetLastDir_Impl() const;
202 SAL_DLLPRIVATE
void SetLastDir_Impl( const OUString
& );
204 SAL_DLLPRIVATE
static void Registrations_Impl();
205 SAL_DLLPRIVATE SfxWorkWindow
* GetWorkWindow_Impl(const SfxViewFrame
*pFrame
) const;
207 // TODO/CLEANUP: still needed? -- unclear whether this comment
208 // refers to the GetDisabledSlotList_Impl() method which was
209 // already removed, or the below methods?
210 SAL_DLLPRIVATE SfxSlotPool
& GetAppSlotPool_Impl() const;
211 SAL_DLLPRIVATE
static SfxModule
* GetModule_Impl();
213 static void SetModule(SfxToolsModule nSharedLib
, std::unique_ptr
<SfxModule
> pModule
);
214 static SfxModule
* GetModule(SfxToolsModule nSharedLib
);
216 static bool loadBrandSvg(const char *pName
, BitmapEx
&rBitmap
, int nWidth
);
218 /** loads the application logo as used in the impress slideshow pause screen */
219 static BitmapEx
GetApplicationLogo(tools::Long nWidth
);
221 /** if true then dialog/infobar notifications like the tip of the day or
222 version change infobar should be suppressed */
223 static bool IsHeadlessOrUITest();
225 static bool IsTipOfTheDayDue();
227 /** this Theme contains Images so must be deleted before DeInitVCL */
228 sfx2::sidebar::Theme
& GetSidebarTheme();
231 inline SfxApplication
* SfxGetpApp()
233 return SfxApplication::Get();
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */