merge the formfield patch from ooo-build
[ooovba.git] / framework / source / dispatch / startmoduledispatcher.cxx
blobdef4f785be172753fc22a68686798a8e6dd6fdb8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: closedispatcher.cxx,v $
10 * $Revision: 1.22 $
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 //_______________________________________________
37 // my own includes
39 #include <pattern/frame.hxx>
40 #include <threadhelp/readguard.hxx>
41 #include <threadhelp/writeguard.hxx>
42 #include <classes/framelistanalyzer.hxx>
43 #include <dispatchcommands.h>
44 #include <targets.h>
45 #include <services.h>
46 #include <general.h>
48 //_______________________________________________
49 // interface includes
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 //_______________________________________________
66 // namespace
68 namespace framework{
70 #ifdef fpf
71 #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
72 #endif
73 namespace fpf = ::framework::pattern::frame;
75 //_______________________________________________
76 // declarations
78 DEFINE_XINTERFACE_4(StartModuleDispatcher ,
79 OWeakObject ,
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( )
98 , m_xSMGR (xSMGR )
99 , m_xOwner (xFrame )
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))
170 return sal_False;
172 // SAFE -> ----------------------------------
173 ReadGuard aReadLock(m_aLock);
174 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
175 aReadLock.unlock();
176 // <- SAFE ----------------------------------
178 css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
179 xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY);
181 FrameListAnalyzer aCheck(
182 xDesktop,
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 ();
189 if (
190 ( ! aCheck.m_xBackingComponent.is ()) &&
191 ( nVisibleFrames < 1 )
194 bIsPossible = sal_True;
197 return bIsPossible;
200 //-----------------------------------------------
201 ::sal_Bool StartModuleDispatcher::implts_establishBackingMode()
203 // SAFE -> ----------------------------------
204 ReadGuard aReadLock(m_aLock);
205 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
206 aReadLock.unlock();
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);
225 return sal_True;
228 //-----------------------------------------------
229 void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
230 ::sal_Int16 nState ,
231 const css::uno::Any& aResult )
233 if ( ! xListener.is())
234 return;
236 css::frame::DispatchResultEvent aEvent(
237 css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
238 nState,
239 aResult);
241 xListener->dispatchFinished(aEvent);
244 } // namespace framework