1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #ifndef INCLUDED_SFX2_APP_HXX
20 #define INCLUDED_SFX2_APP_HXX
21
22 #include <memory>
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <vcl/errcode.hxx>
27 #include <svl/poolitem.hxx>
28 #include <vcl/bitmapex.hxx>
29 #include <tools/link.hxx>
30
31 #include <sfx2/shell.hxx>
32
33 namespace com::sun::star::script { class XLibraryContainer; }
34
35 namespace weld { class Window; }
36
37 class BasicManager;
38 class DdeService;
39 class SfxAppData_Impl;
40 class SfxChildWinFactArr_Impl;
41 class SfxDispatcher;
42 class SfxEventHint;
43 class SfxItemSet;
44 class SfxObjectShell;
45 class SfxObjectShellArr_Impl;
46 class SfxObjectShellLock;
47 class SfxProgress;
48 class SfxSlotPool;
49 class SfxStbCtrlFactArr_Impl;
50 class SfxTbxCtrlFactArr_Impl;
51 class SfxViewFrame;
52 class SfxViewFrameArr_Impl;
53 class SfxViewShellArr_Impl;
54 class StarBASIC;
55 class SfxWorkWindow;
56 class SfxFilterMatcher;
57 class SfxModule;
58 struct SfxChildWinFactory;
59 struct SfxStbCtrlFactory;
60 struct SfxTbxCtrlFactory;
61 class SbxArray;
62 class SbxValue;
63
64 namespace sfx2
65 {
66 namespace sidebar {
67 class Theme;
68 }
69 }
70
71 enum class SfxToolsModule
72 {
73 Math = 0,
74 Calc = 1,
75 Draw = 2,
76 Writer = 3,
77 Basic = 4,
78 LAST = Basic
79 };
80
81 class SFX2_DLLPUBLIC SfxLinkItem final : public SfxPoolItem
82 {
83 Link<SfxPoolItem const *, void> aLink;
84 public:
SfxLinkItem(sal_uInt16 nWhichId,const Link<SfxPoolItem const *,void> & rValue)85 SfxLinkItem( sal_uInt16 nWhichId, const Link<SfxPoolItem const *, void>& rValue ) : SfxPoolItem( nWhichId )
86 { aLink = rValue; }
87
Clone(SfxItemPool * =nullptr) const88 virtual SfxLinkItem* Clone( SfxItemPool* = nullptr ) const override
89 { return new SfxLinkItem( *this ); }
operator ==(const SfxPoolItem & rL) const90 virtual bool operator==( const SfxPoolItem& rL) const override
91 { return static_cast<const SfxLinkItem&>(rL).aLink == aLink; }
92 const Link<SfxPoolItem const *, void>&
GetValue() const93 GetValue() const { return aLink; }
94 };
95
96 // This is a singleton class. Sad that there apparently is no other
97 // way than a comment like this to indicate that to the code reader.
98 class SFX2_DLLPUBLIC SfxApplication final : public SfxShell
99 {
100 std::unique_ptr<SfxAppData_Impl> pImpl;
101
102 DECL_DLLPRIVATE_STATIC_LINK( SfxApplication, GlobalBasicErrorHdl_Impl, StarBASIC*, bool );
103
104 void Deinitialize();
105
106 public:
107 SFX_DECL_INTERFACE(SFX_INTERFACE_SFXAPP)
108
109 private:
110 /// SfxInterface initializer.
111 static void InitInterface_Impl();
112 SfxApplication();
113
114 public:
115 virtual ~SfxApplication() override;
116 static SfxApplication* GetOrCreate();
117 static SfxApplication* Get();
118
119 // DDE
120 #if defined(_WIN32)
121 static bool DdeExecute( const OUString& rCmd );
122 #endif
123 bool InitializeDde();
124 const DdeService* GetDdeService() const;
125 DdeService* GetDdeService();
126 #if defined(_WIN32)
127 void AddDdeTopic( SfxObjectShell* );
128 #endif
129 void RemoveDdeTopic( SfxObjectShell const * );
130
131 // "static" methods
132 /**
133 * @param pArgs Takes ownership
134 */
135 ErrCode LoadTemplate( SfxObjectShellLock& xDoc, const OUString& rFileName, std::unique_ptr<SfxItemSet> pArgs );
136 weld::Window* GetTopWindow() const;
137
138 // members
139 SfxFilterMatcher& GetFilterMatcher();
140 SfxProgress* GetProgress() const;
141 sal_uInt16 GetFreeIndex();
142 void ReleaseIndex(sal_uInt16 i);
143
144 // Basic/Scripting
145 static bool IsXScriptURL( const OUString& rScriptURL );
146 static OUString ChooseScript(weld::Window *pParent);
147 static void MacroOrganizer(weld::Window* pParent, sal_Int16 nTabId);
148 static ErrCode CallBasic( const OUString&, BasicManager*, SbxArray *pArgs, SbxValue *pRet );
CallAppBasic(const OUString & i_macroName)149 static ErrCode CallAppBasic( const OUString& i_macroName )
150 { return CallBasic( i_macroName, SfxApplication::GetBasicManager(), nullptr, nullptr ); }
151 static BasicManager* GetBasicManager();
152 css::script::XLibraryContainer * GetDialogContainer();
153 css::script::XLibraryContainer * GetBasicContainer();
154 static StarBASIC* GetBasic();
155 void SaveBasicAndDialogContainer() const;
156
157 // misc.
158 void GetOptions(SfxItemSet &);
159 void SetOptions(const SfxItemSet &);
160 virtual void Invalidate(sal_uInt16 nId = 0) override;
161 void NotifyEvent(const SfxEventHint& rEvent, bool bSynchron = true );
162 bool IsDowning() const;
163 void ResetLastDir();
164
165 SAL_DLLPRIVATE SfxDispatcher* GetAppDispatcher_Impl();
166 SAL_DLLPRIVATE SfxDispatcher* GetDispatcher_Impl();
167
168 SAL_DLLPRIVATE void SetOptions_Impl(const SfxItemSet &);
169 SAL_DLLPRIVATE void Initialize_Impl();
170
Get_Impl() const171 SAL_DLLPRIVATE SfxAppData_Impl* Get_Impl() const { return pImpl.get(); }
172
173 // Object-Factories/global arrays
174 SAL_DLLPRIVATE void RegisterChildWindow_Impl(SfxModule*, std::unique_ptr<SfxChildWinFactory>);
175 SAL_DLLPRIVATE void RegisterStatusBarControl_Impl(SfxModule*, const SfxStbCtrlFactory&);
176 SAL_DLLPRIVATE void RegisterToolBoxControl_Impl( SfxModule*, const SfxTbxCtrlFactory&);
177 SAL_DLLPRIVATE SfxTbxCtrlFactArr_Impl& GetTbxCtrlFactories_Impl() const;
178 SAL_DLLPRIVATE SfxStbCtrlFactArr_Impl& GetStbCtrlFactories_Impl() const;
179 SAL_DLLPRIVATE SfxChildWinFactArr_Impl& GetChildWinFactories_Impl() const;
180 SAL_DLLPRIVATE SfxViewFrameArr_Impl& GetViewFrames_Impl() const;
181 SAL_DLLPRIVATE SfxViewShellArr_Impl& GetViewShells_Impl() const;
182 SAL_DLLPRIVATE SfxObjectShellArr_Impl& GetObjectShells_Impl() const;
183 SAL_DLLPRIVATE void SetViewFrame_Impl(SfxViewFrame *pViewFrame);
184
185 // Slot Methods
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 &);
199
200 SAL_DLLPRIVATE void SetProgress_Impl(SfxProgress *);
201 SAL_DLLPRIVATE const OUString& GetLastDir_Impl() const;
202 SAL_DLLPRIVATE void SetLastDir_Impl( const OUString & );
203
204 SAL_DLLPRIVATE static void Registrations_Impl();
205 SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl(const SfxViewFrame *pFrame) const;
206
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();
212
213 static void SetModule(SfxToolsModule nSharedLib, std::unique_ptr<SfxModule> pModule);
214 static SfxModule* GetModule(SfxToolsModule nSharedLib);
215
216 static bool loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth);
217
218 /** loads the application logo as used in the impress slideshow pause screen */
219 static BitmapEx GetApplicationLogo(tools::Long nWidth);
220
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();
224
225 static bool IsTipOfTheDayDue();
226
227 /** this Theme contains Images so must be deleted before DeInitVCL */
228 sfx2::sidebar::Theme & GetSidebarTheme();
229 };
230
SfxGetpApp()231 inline SfxApplication* SfxGetpApp()
232 {
233 return SfxApplication::Get();
234 }
235
236 #endif
237
238
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
240