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 
20 #ifndef INCLUDED_SFX2_SOURCE_APPL_SHUTDOWNICON_HXX
21 #define INCLUDED_SFX2_SOURCE_APPL_SHUTDOWNICON_HXX
22 
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 <osl/mutex.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <tools/link.hxx>
34 #include <memory>
35 
36 extern "C" {
37 
38 void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray();
39 void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray();
40 
41 }
42 
43 namespace sfx2
44 {
45     class FileDialogHelper;
46 }
47 
48 typedef ::cppu::WeakComponentImplHelper<
49     css::lang::XInitialization,
50     css::frame::XTerminateListener,
51     css::lang::XServiceInfo,
52     css::beans::XFastPropertySet > ShutdownIconServiceBase;
53 
54 #define WRITER_URL          "private:factory/swriter"
55 #define CALC_URL            "private:factory/scalc"
56 #define IMPRESS_URL         "private:factory/simpress"
57 #define IMPRESS_WIZARD_URL  "private:factory/simpress?slot=6686"
58 #define DRAW_URL            "private:factory/sdraw"
59 #define MATH_URL            "private:factory/smath"
60 #define BASE_URL            "private:factory/sdatabase?Interactive"
61 #define STARTMODULE_URL     ".uno:ShowStartModule"
62 
63 class ShutdownIcon : public ShutdownIconServiceBase
64 {
65         ::osl::Mutex            m_aMutex;
66         bool                    m_bVeto;
67         bool                    m_bListenForTermination;
68         bool                    m_bSystemDialogs;
69         std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
70         css::uno::Reference< css::uno::XComponentContext > m_xContext;
71 
72         static rtl::Reference<ShutdownIcon> pShutdownIcon; // one instance
73 
74         bool m_bInitialized;
75         void initSystray();
76         void deInitSystray();
77 
78         static void EnterModalMode();
79         static void LeaveModalMode();
80         static OUString getShortcutName();
81 
82         friend class SfxNotificationListener_Impl;
83 
84     public:
85         explicit ShutdownIcon( const css::uno::Reference< css::uno::XComponentContext > & rxContext );
86 
87         virtual ~ShutdownIcon() override;
88 
89         virtual OUString SAL_CALL getImplementationName() override;
90 
91         virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
92 
93         virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
94 
95         static ShutdownIcon* getInstance();
96         static ShutdownIcon* createInstance();
97 
98         static void terminateDesktop();
99         static void addTerminateListener();
100 
101         static void FileOpen();
102         static void OpenURL( const OUString& aURL, const OUString& rTarget, const css::uno::Sequence< css::beans::PropertyValue >& =
103             css::uno::Sequence< css::beans::PropertyValue >( 0 ) );
104         static void FromTemplate();
105 
106         static void SetAutostart( bool bActivate );
107         static bool GetAutostart();
108         static bool bModalMode;
109 
110         /// @throws css::uno::Exception
111         void init();
112 
113         static OUString GetUrlDescription( const OUString& aUrl );
114 
SetVeto(bool bVeto)115         void SetVeto( bool bVeto )  { m_bVeto = bVeto;}
116 
117         void                    StartFileDialog();
118         DECL_LINK(DialogClosedHdl_Impl, sfx2::FileDialogHelper*, void);
119 
120         static bool IsQuickstarterInstalled();
121 
122         // Component Helper - force override
123         virtual void SAL_CALL disposing() override;
124 
125         // XEventListener
126         virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
127 
128         // XTerminateListener
129         virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override;
130         virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override;
131 
132         // XInitialization
133         virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
134 
135         // XFastPropertySet
136         virtual void SAL_CALL setFastPropertyValue(       ::sal_Int32                  nHandle,
137                                                     const css::uno::Any& aValue ) override;
138         virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) override;
139 
140         css::uno::Reference< css::frame::XDesktop2 > m_xDesktop;
141 
142 #ifdef _WIN32
143         static void EnableAutostartW32( const OUString &aShortcutName );
144         static OUString GetAutostartFolderNameW32();
145 #endif
146 };
147 
148 extern "C" {
149 #  ifdef _WIN32
150     // builtin win32 systray
151     void win32_init_sys_tray();
152     void win32_shutdown_sys_tray();
153 #  elif defined MACOSX
154     void aqua_init_systray();
155     void aqua_shutdown_systray();
156 #  endif
157 }
158 
159 #endif
160 
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
162