Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / sfx2 / source / inc / shutdownicon.hxx
blob1127a9ca352c151cab07da184403bd551b4e6a7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SFX2_SOURCE_APPL_SHUTDOWNICON_HXX
21 #define INCLUDED_SFX2_SOURCE_APPL_SHUTDOWNICON_HXX
23 #include <com/sun/star/frame/XTerminateListener.hpp>
24 #include <com/sun/star/frame/XDesktop2.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/beans/XFastPropertySet.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <rtl/ustring.hxx>
30 #include <rtl/ref.hxx>
31 #include <comphelper/compbase.hxx>
32 #include <tools/link.hxx>
33 #include <memory>
35 #ifdef MACOSX
36 #include <vcl/menu.hxx>
37 #endif
39 extern "C" {
41 void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray();
42 void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray();
46 namespace sfx2
48 class FileDialogHelper;
51 typedef comphelper::WeakComponentImplHelper<
52 css::lang::XInitialization,
53 css::frame::XTerminateListener,
54 css::lang::XServiceInfo,
55 css::beans::XFastPropertySet > ShutdownIconServiceBase;
57 inline constexpr OUString WRITER_URL = u"private:factory/swriter"_ustr;
58 inline constexpr OUString CALC_URL = u"private:factory/scalc"_ustr;
59 inline constexpr OUString IMPRESS_URL = u"private:factory/simpress"_ustr;
60 inline constexpr OUString IMPRESS_WIZARD_URL = u"private:factory/simpress?slot=6686"_ustr;
61 inline constexpr OUString DRAW_URL = u"private:factory/sdraw"_ustr;
62 inline constexpr OUString MATH_URL = u"private:factory/smath"_ustr;
63 inline constexpr OUString BASE_URL = u"private:factory/sdatabase?Interactive"_ustr;
64 inline constexpr OUString STARTMODULE_URL = u".uno:ShowStartModule"_ustr;
66 class ShutdownIcon : public ShutdownIconServiceBase
68 bool m_bVeto;
69 bool m_bListenForTermination;
70 bool m_bSystemDialogs;
71 std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
72 css::uno::Reference< css::uno::XComponentContext > m_xContext;
73 css::uno::Reference< css::frame::XDesktop2 > m_xDesktop;
75 static rtl::Reference<ShutdownIcon> pShutdownIcon; // one instance
77 bool m_bInitialized;
78 void initSystray();
79 void deInitSystray();
81 static void EnterModalMode();
82 static void LeaveModalMode();
83 static OUString getShortcutName();
85 friend class SfxNotificationListener_Impl;
87 public:
88 explicit ShutdownIcon( css::uno::Reference< css::uno::XComponentContext > xContext );
90 virtual ~ShutdownIcon() override;
92 virtual OUString SAL_CALL getImplementationName() override;
94 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
96 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
98 static ShutdownIcon* getInstance();
99 static ShutdownIcon* createInstance();
101 static void terminateDesktop();
102 static void addTerminateListener();
104 static void FileOpen();
105 static void OpenURL( const OUString& aURL, const OUString& rTarget, const css::uno::Sequence< css::beans::PropertyValue >& =
106 css::uno::Sequence< css::beans::PropertyValue >( 0 ) );
107 static void FromTemplate();
108 static void FromCommand( const OUString& rCommand );
110 static void SetAutostart( bool bActivate );
111 static bool GetAutostart();
112 static bool bModalMode;
114 /// @throws css::uno::Exception
115 void init();
117 static OUString GetUrlDescription( std::u16string_view aUrl );
119 void SetVeto( bool bVeto ) { m_bVeto = bVeto;}
121 void StartFileDialog();
122 DECL_LINK(DialogClosedHdl_Impl, sfx2::FileDialogHelper*, void);
124 static bool IsQuickstarterInstalled();
126 // Component Helper - force override
127 virtual void disposing(std::unique_lock<std::mutex>&) override;
129 // XEventListener
130 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
132 // XTerminateListener
133 virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override;
134 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override;
136 // XInitialization
137 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
139 // XFastPropertySet
140 virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle,
141 const css::uno::Any& aValue ) override;
142 virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override;
144 #ifdef _WIN32
145 static void EnableAutostartW32( const OUString &aShortcutName );
146 static OUString GetAutostartFolderNameW32();
147 #elif defined MACOSX
148 static void SetDefaultMenuBar( MenuBar *pMenuBar );
149 #endif
152 extern "C" {
153 # ifdef _WIN32
154 // builtin win32 systray
155 void win32_init_sys_tray();
156 void win32_shutdown_sys_tray();
157 # elif defined MACOSX
158 void aqua_init_systray();
159 void aqua_shutdown_systray();
160 # endif
163 #endif
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */