Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <dispatch/startmoduledispatcher.hxx>
31 : :
32 : : #include <pattern/frame.hxx>
33 : : #include <threadhelp/readguard.hxx>
34 : : #include <threadhelp/writeguard.hxx>
35 : : #include <framework/framelistanalyzer.hxx>
36 : : #include <dispatchcommands.h>
37 : : #include <targets.h>
38 : : #include <services.h>
39 : : #include <general.h>
40 : :
41 : : #include <com/sun/star/frame/XDesktop.hpp>
42 : : #include <com/sun/star/frame/XController.hpp>
43 : : #include <com/sun/star/frame/CommandGroup.hpp>
44 : : #include <com/sun/star/awt/XTopWindow.hpp>
45 : : #include "com/sun/star/beans/XFastPropertySet.hpp"
46 : : #include <com/sun/star/frame/XModuleManager.hpp>
47 : :
48 : : #include <toolkit/helper/vclunohelper.hxx>
49 : : #include <vcl/window.hxx>
50 : : #include <vcl/svapp.hxx>
51 : : #include <osl/mutex.hxx>
52 : : #include <unotools/moduleoptions.hxx>
53 : :
54 : :
55 : : namespace framework{
56 : :
57 : : #ifdef fpf
58 : : #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
59 : : #endif
60 : : namespace fpf = ::framework::pattern::frame;
61 : :
62 : :
63 [ # # ][ # # ]: 0 : DEFINE_XINTERFACE_4(StartModuleDispatcher ,
64 : : OWeakObject ,
65 : : DIRECT_INTERFACE(css::lang::XTypeProvider ),
66 : : DIRECT_INTERFACE(css::frame::XNotifyingDispatch ),
67 : : DIRECT_INTERFACE(css::frame::XDispatch ),
68 : : DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
69 : :
70 : : // Note: XStatusListener is an implementation detail. Hide it for scripting!
71 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
72 : : css::lang::XTypeProvider ,
73 : : css::frame::XDispatchInformationProvider,
74 : : css::frame::XNotifyingDispatch ,
75 : : css::frame::XDispatch )
76 : :
77 : : //-----------------------------------------------
78 : 0 : StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
79 : : const css::uno::Reference< css::frame::XFrame >& xFrame ,
80 : : const ::rtl::OUString& sTarget)
81 [ # # ]: 0 : : ThreadHelpBase (&Application::GetSolarMutex() )
82 : : , ::cppu::OWeakObject( )
83 : : , m_xSMGR (xSMGR )
84 : : , m_xOwner (xFrame )
85 : : , m_sDispatchTarget (sTarget )
86 [ # # ][ # # ]: 0 : , m_lStatusListener (m_aLock.getShareableOslMutex())
[ # # ][ # # ]
87 : : {
88 : 0 : }
89 : :
90 : : //-----------------------------------------------
91 [ # # ][ # # ]: 0 : StartModuleDispatcher::~StartModuleDispatcher()
[ # # ][ # # ]
92 : : {
93 [ # # ]: 0 : }
94 : :
95 : : //-----------------------------------------------
96 : 0 : void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL& aURL ,
97 : : const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
98 : : throw(css::uno::RuntimeException)
99 : : {
100 [ # # ]: 0 : dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
101 : 0 : }
102 : :
103 : : //-----------------------------------------------
104 : 0 : void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
105 : : const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
106 : : const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
107 : : throw(css::uno::RuntimeException)
108 : : {
109 : 0 : ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
110 [ # # ]: 0 : if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
111 : : {
112 : 0 : nResult = css::frame::DispatchResultState::FAILURE;
113 [ # # ]: 0 : if (implts_isBackingModePossible ())
114 : : {
115 [ # # ]: 0 : if (implts_establishBackingMode ())
116 : 0 : nResult = css::frame::DispatchResultState::SUCCESS;
117 : : }
118 : : }
119 : :
120 [ # # ]: 0 : implts_notifyResultListener(xListener, nResult, css::uno::Any());
121 : 0 : }
122 : :
123 : : //-----------------------------------------------
124 : 0 : css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
125 : : throw(css::uno::RuntimeException)
126 : : {
127 : 0 : return css::uno::Sequence< ::sal_Int16 >();
128 : : }
129 : :
130 : : //-----------------------------------------------
131 : 0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
132 : : throw(css::uno::RuntimeException)
133 : : {
134 : 0 : return css::uno::Sequence< css::frame::DispatchInformation >();
135 : : }
136 : :
137 : : //-----------------------------------------------
138 : 0 : void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
139 : : const css::util::URL& /*aURL*/ )
140 : : throw(css::uno::RuntimeException)
141 : : {
142 : 0 : }
143 : :
144 : : //-----------------------------------------------
145 : 0 : void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
146 : : const css::util::URL& /*aURL*/ )
147 : : throw(css::uno::RuntimeException)
148 : : {
149 : 0 : }
150 : :
151 : : //-----------------------------------------------
152 : 0 : ::sal_Bool StartModuleDispatcher::implts_isBackingModePossible ()
153 : : {
154 [ # # ][ # # ]: 0 : if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE))
[ # # ][ # # ]
155 : 0 : return sal_False;
156 : :
157 : : // SAFE -> ----------------------------------
158 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
159 : 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
160 [ # # ]: 0 : aReadLock.unlock();
161 : : // <- SAFE ----------------------------------
162 : :
163 : : css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
164 [ # # ][ # # ]: 0 : xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
[ # # ][ # # ]
165 : :
166 : : FrameListAnalyzer aCheck(
167 : : xDesktop,
168 : : css::uno::Reference< css::frame::XFrame >(),
169 [ # # ]: 0 : FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
170 : :
171 : 0 : ::sal_Bool bIsPossible = sal_False;
172 : 0 : ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
173 : :
174 [ # # ][ # # ]: 0 : if (
[ # # ]
175 : 0 : ( ! aCheck.m_xBackingComponent.is ()) &&
176 : : ( nVisibleFrames < 1 )
177 : : )
178 : : {
179 : 0 : bIsPossible = sal_True;
180 : : }
181 : :
182 [ # # ][ # # ]: 0 : return bIsPossible;
183 : : }
184 : :
185 : : //-----------------------------------------------
186 : 0 : ::sal_Bool StartModuleDispatcher::implts_establishBackingMode()
187 : : {
188 : : // SAFE -> ----------------------------------
189 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
190 : 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
191 [ # # ]: 0 : aReadLock.unlock();
192 : : // <- SAFE ----------------------------------
193 : :
194 [ # # ][ # # ]: 0 : css::uno::Reference< css::frame::XFrame > xDesktop (xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
[ # # ][ # # ]
195 [ # # ][ # # ]: 0 : css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->findFrame (SPECIALTARGET_BLANK, 0);
[ # # ]
196 [ # # ][ # # ]: 0 : css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow ();
197 : :
198 [ # # ]: 0 : css::uno::Sequence< css::uno::Any > lArgs(1);
199 [ # # ][ # # ]: 0 : lArgs[0] <<= xContainerWindow;
200 : :
201 : : css::uno::Reference< css::frame::XController > xStartModule(
202 [ # # ]: 0 : xSMGR->createInstanceWithArguments(SERVICENAME_STARTMODULE, lArgs),
203 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY_THROW);
[ # # ]
204 : :
205 [ # # ]: 0 : css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
206 [ # # ][ # # ]: 0 : xFrame->setComponent(xComponentWindow, xStartModule);
207 [ # # ][ # # ]: 0 : xStartModule->attachFrame(xFrame);
208 [ # # ][ # # ]: 0 : xContainerWindow->setVisible(sal_True);
209 : :
210 [ # # ][ # # ]: 0 : return sal_True;
211 : : }
212 : :
213 : : //-----------------------------------------------
214 : 0 : void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
215 : : ::sal_Int16 nState ,
216 : : const css::uno::Any& aResult )
217 : : {
218 [ # # ]: 0 : if ( ! xListener.is())
219 : 0 : return;
220 : :
221 : : css::frame::DispatchResultEvent aEvent(
222 : : css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
223 : : nState,
224 [ # # ][ # # ]: 0 : aResult);
225 : :
226 [ # # ][ # # ]: 0 : xListener->dispatchFinished(aEvent);
[ # # ]
227 : : }
228 : :
229 : : } // namespace framework
230 : :
231 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|