1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: closedispatcher.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include <dispatch/startmoduledispatcher.hxx>
36 //_______________________________________________
39 #include <pattern/frame.hxx>
40 #include <threadhelp/readguard.hxx>
41 #include <threadhelp/writeguard.hxx>
42 #include <classes/framelistanalyzer.hxx>
43 #include <dispatchcommands.h>
48 //_______________________________________________
50 #include <com/sun/star/frame/XDesktop.hpp>
51 #include <com/sun/star/frame/XController.hpp>
52 #include <com/sun/star/frame/CommandGroup.hpp>
53 #include <com/sun/star/awt/XTopWindow.hpp>
54 #include "com/sun/star/beans/XFastPropertySet.hpp"
55 #include <com/sun/star/frame/XModuleManager.hpp>
57 //_______________________________________________
58 // includes of other projects
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <vcl/window.hxx>
61 #include <vcl/svapp.hxx>
62 #include <vos/mutex.hxx>
63 #include <svtools/moduleoptions.hxx>
65 //_______________________________________________
71 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
73 namespace fpf
= ::framework::pattern::frame
;
75 //_______________________________________________
78 DEFINE_XINTERFACE_4(StartModuleDispatcher
,
80 DIRECT_INTERFACE(css::lang::XTypeProvider
),
81 DIRECT_INTERFACE(css::frame::XNotifyingDispatch
),
82 DIRECT_INTERFACE(css::frame::XDispatch
),
83 DIRECT_INTERFACE(css::frame::XDispatchInformationProvider
))
85 // Note: XStatusListener is an implementation detail. Hide it for scripting!
86 DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher
,
87 css::lang::XTypeProvider
,
88 css::frame::XDispatchInformationProvider
,
89 css::frame::XNotifyingDispatch
,
90 css::frame::XDispatch
)
92 //-----------------------------------------------
93 StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
94 const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
95 const ::rtl::OUString
& sTarget
)
96 : ThreadHelpBase (&Application::GetSolarMutex() )
97 , ::cppu::OWeakObject( )
100 , m_sDispatchTarget (sTarget
)
101 , m_lStatusListener (m_aLock
.getShareableOslMutex())
105 //-----------------------------------------------
106 StartModuleDispatcher::~StartModuleDispatcher()
110 //-----------------------------------------------
111 void SAL_CALL
StartModuleDispatcher::dispatch(const css::util::URL
& aURL
,
112 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
)
113 throw(css::uno::RuntimeException
)
115 dispatchWithNotification(aURL
, lArguments
, css::uno::Reference
< css::frame::XDispatchResultListener
>());
118 //-----------------------------------------------
119 void SAL_CALL
StartModuleDispatcher::dispatchWithNotification(const css::util::URL
& aURL
,
120 const css::uno::Sequence
< css::beans::PropertyValue
>& /*lArguments*/,
121 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
)
122 throw(css::uno::RuntimeException
)
124 ::sal_Int16 nResult
= css::frame::DispatchResultState::DONTKNOW
;
125 if (aURL
.Complete
.equals (CMD_UNO_SHOWSTARTMODULE
))
127 nResult
= css::frame::DispatchResultState::FAILURE
;
128 if (implts_isBackingModePossible ())
130 if (implts_establishBackingMode ())
131 nResult
= css::frame::DispatchResultState::SUCCESS
;
135 implts_notifyResultListener(xListener
, nResult
, css::uno::Any());
138 //-----------------------------------------------
139 css::uno::Sequence
< ::sal_Int16
> SAL_CALL
StartModuleDispatcher::getSupportedCommandGroups()
140 throw(css::uno::RuntimeException
)
142 return css::uno::Sequence
< ::sal_Int16
>();
145 //-----------------------------------------------
146 css::uno::Sequence
< css::frame::DispatchInformation
> SAL_CALL
StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16
/*nCommandGroup*/)
147 throw(css::uno::RuntimeException
)
149 return css::uno::Sequence
< css::frame::DispatchInformation
>();
152 //-----------------------------------------------
153 void SAL_CALL
StartModuleDispatcher::addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
154 const css::util::URL
& /*aURL*/ )
155 throw(css::uno::RuntimeException
)
159 //-----------------------------------------------
160 void SAL_CALL
StartModuleDispatcher::removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
161 const css::util::URL
& /*aURL*/ )
162 throw(css::uno::RuntimeException
)
166 //-----------------------------------------------
167 ::sal_Bool
StartModuleDispatcher::implts_isBackingModePossible ()
169 if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE
))
172 // SAFE -> ----------------------------------
173 ReadGuard
aReadLock(m_aLock
);
174 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
176 // <- SAFE ----------------------------------
178 css::uno::Reference
< css::frame::XFramesSupplier
> xDesktop(
179 xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY
);
181 FrameListAnalyzer
aCheck(
183 css::uno::Reference
< css::frame::XFrame
>(),
184 FrameListAnalyzer::E_HELP
| FrameListAnalyzer::E_BACKINGCOMPONENT
);
186 ::sal_Bool bIsPossible
= sal_False
;
187 ::sal_Int32 nVisibleFrames
= aCheck
.m_lOtherVisibleFrames
.getLength ();
190 ( ! aCheck
.m_xBackingComponent
.is ()) &&
191 ( nVisibleFrames
< 1 )
194 bIsPossible
= sal_True
;
200 //-----------------------------------------------
201 ::sal_Bool
StartModuleDispatcher::implts_establishBackingMode()
203 // SAFE -> ----------------------------------
204 ReadGuard
aReadLock(m_aLock
);
205 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
207 // <- SAFE ----------------------------------
209 css::uno::Reference
< css::frame::XFrame
> xDesktop (xSMGR
->createInstance(SERVICENAME_DESKTOP
), css::uno::UNO_QUERY
);
210 css::uno::Reference
< css::frame::XFrame
> xFrame
= xDesktop
->findFrame (SPECIALTARGET_BLANK
, 0);
211 css::uno::Reference
< css::awt::XWindow
> xContainerWindow
= xFrame
->getContainerWindow ();
213 css::uno::Sequence
< css::uno::Any
> lArgs(1);
214 lArgs
[0] <<= xContainerWindow
;
216 css::uno::Reference
< css::frame::XController
> xStartModule(
217 xSMGR
->createInstanceWithArguments(SERVICENAME_STARTMODULE
, lArgs
),
218 css::uno::UNO_QUERY_THROW
);
220 css::uno::Reference
< css::awt::XWindow
> xComponentWindow(xStartModule
, css::uno::UNO_QUERY
);
221 xFrame
->setComponent(xComponentWindow
, xStartModule
);
222 xStartModule
->attachFrame(xFrame
);
223 xContainerWindow
->setVisible(sal_True
);
228 //-----------------------------------------------
229 void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
,
231 const css::uno::Any
& aResult
)
233 if ( ! xListener
.is())
236 css::frame::DispatchResultEvent
aEvent(
237 css::uno::Reference
< css::uno::XInterface
>(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
),
241 xListener
->dispatchFinished(aEvent
);
244 } // namespace framework