1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "services/backingcomp.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "backingwindow.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //_______________________________________________
36*cdf0e10cSrcweir // own includes
37*cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
38*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
39*cdf0e10cSrcweir #include <classes/droptargetlistener.hxx>
40*cdf0e10cSrcweir #include <framework/acceleratorinfo.hxx>
41*cdf0e10cSrcweir #include <targets.h>
42*cdf0e10cSrcweir #include <properties.h>
43*cdf0e10cSrcweir #include <services.h>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #ifndef _FRAMEWORK_HELPID_HRC
46*cdf0e10cSrcweir #include <helpid.hrc>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir //_______________________________________________
50*cdf0e10cSrcweir // interface includes
51*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/awt/XDataTransferProviderAccess.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/awt/KeyEvent.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //_______________________________________________
62*cdf0e10cSrcweir // other includes
63*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
64*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
65*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
66*cdf0e10cSrcweir #include <vcl/keycod.hxx>
67*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
68*cdf0e10cSrcweir #include <vcl/svapp.hxx>
69*cdf0e10cSrcweir #include <tools/resmgr.hxx>
70*cdf0e10cSrcweir #include <tools/urlobj.hxx>
71*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #ifndef _SOLAR_HRC
74*cdf0e10cSrcweir #include <svl/solar.hrc>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #include <svl/urihelper.hxx>
77*cdf0e10cSrcweir #include <osl/file.hxx>
78*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir #ifndef _UTL_BOOTSTRAP_HXX_
81*cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
82*cdf0e10cSrcweir #endif
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir namespace framework
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir //_______________________________________________
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir //_______________________________________________
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir BackingComp::BackingComp( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR )
92*cdf0e10cSrcweir     : ThreadHelpBase    (&Application::GetSolarMutex()                  )
93*cdf0e10cSrcweir     , m_xSMGR           (xSMGR                                          )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir //_______________________________________________
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir BackingComp::~BackingComp()
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir //_______________________________________________
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir /** return information about supported interfaces.
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     Some interfaces are supported by his class directly, but some other ones are
108*cdf0e10cSrcweir     used by aggregation. An instance of this class must provide some window interfaces.
109*cdf0e10cSrcweir     But it must represent a VCL window behind such interfaces too! So we use an internal
110*cdf0e10cSrcweir     saved window member to ask it for it's interfaces and return it. But we must be aware then,
111*cdf0e10cSrcweir     that it can be destroyed from outside too ...
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     @param  aType
114*cdf0e10cSrcweir                 describe the required interface type
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     @return An Any holding the instance, which provides the queried interface.
117*cdf0e10cSrcweir             Note: There exist two possible results ... this instance itself and her window member!
118*cdf0e10cSrcweir  */
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir css::uno::Any SAL_CALL BackingComp::queryInterface( /*IN*/ const css::uno::Type& aType )
121*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     css::uno::Any aResult;
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     // first look for own supported interfaces
126*cdf0e10cSrcweir     aResult = ::cppu::queryInterface(
127*cdf0e10cSrcweir                 aType,
128*cdf0e10cSrcweir                 static_cast< css::lang::XTypeProvider* >(this),
129*cdf0e10cSrcweir                 static_cast< css::lang::XServiceInfo* >(this),
130*cdf0e10cSrcweir                 static_cast< css::lang::XInitialization* >(this),
131*cdf0e10cSrcweir                 static_cast< css::frame::XController* >(this),
132*cdf0e10cSrcweir                 static_cast< css::lang::XComponent* >(this),
133*cdf0e10cSrcweir                 static_cast< css::lang::XEventListener* >(this),
134*cdf0e10cSrcweir                 static_cast< css::awt::XKeyListener* >(static_cast< css::lang::XEventListener* >(this)));
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     // then look for supported window interfaces
137*cdf0e10cSrcweir     // Note: They exist only, if this instance was initialized
138*cdf0e10cSrcweir     // with a valid window reference. It's aggregation on demand ...
139*cdf0e10cSrcweir     if (!aResult.hasValue())
140*cdf0e10cSrcweir     {
141*cdf0e10cSrcweir         /* SAFE { */
142*cdf0e10cSrcweir         ReadGuard aReadLock(m_aLock);
143*cdf0e10cSrcweir         if (m_xWindow.is())
144*cdf0e10cSrcweir             aResult = m_xWindow->queryInterface(aType);
145*cdf0e10cSrcweir         aReadLock.unlock();
146*cdf0e10cSrcweir         /* } SAFE */
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     // look for XWeak and XInterface
150*cdf0e10cSrcweir     if (!aResult.hasValue())
151*cdf0e10cSrcweir         aResult = OWeakObject::queryInterface(aType);
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     return aResult;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir //_______________________________________________
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir /** increase ref count of this instance.
159*cdf0e10cSrcweir  */
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void SAL_CALL BackingComp::acquire()
162*cdf0e10cSrcweir     throw()
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir     OWeakObject::acquire();
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir //_______________________________________________
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir /** decrease ref count of this instance.
170*cdf0e10cSrcweir  */
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void SAL_CALL BackingComp::release()
173*cdf0e10cSrcweir     throw()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     OWeakObject::release();
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //_______________________________________________
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir /** return collection about all supported interfaces.
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     Optimize this method !
183*cdf0e10cSrcweir     We initialize a static variable only one time.
184*cdf0e10cSrcweir     And we don't must use a mutex at every call!
185*cdf0e10cSrcweir     For the first call; pTypeCollection is NULL -
186*cdf0e10cSrcweir     for the second call pTypeCollection is different from NULL!
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     @return A list of all supported interface types.
189*cdf0e10cSrcweir */
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir css::uno::Sequence< css::uno::Type > SAL_CALL BackingComp::getTypes()
192*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     static ::cppu::OTypeCollection* pTypeCollection = NULL;
195*cdf0e10cSrcweir     if (!pTypeCollection)
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         /* GLOBAL SAFE { */
198*cdf0e10cSrcweir         ::osl::MutexGuard aGlobalLock(::osl::Mutex::getGlobalMutex());
199*cdf0e10cSrcweir         // Control these pointer again ... it can be, that another instance will be faster then this one!
200*cdf0e10cSrcweir         if (!pTypeCollection)
201*cdf0e10cSrcweir         {
202*cdf0e10cSrcweir             /* LOCAL SAFE { */
203*cdf0e10cSrcweir             ReadGuard aReadLock(m_aLock);
204*cdf0e10cSrcweir             css::uno::Reference< css::lang::XTypeProvider > xProvider(m_xWindow, css::uno::UNO_QUERY);
205*cdf0e10cSrcweir             aReadLock.unlock();
206*cdf0e10cSrcweir             /* } LOCAL SAFE */
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir             css::uno::Sequence< css::uno::Type > lWindowTypes;
209*cdf0e10cSrcweir             if (xProvider.is())
210*cdf0e10cSrcweir                 lWindowTypes = xProvider->getTypes();
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir             static ::cppu::OTypeCollection aTypeCollection(
213*cdf0e10cSrcweir                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XInitialization >*)NULL ),
214*cdf0e10cSrcweir                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ),
215*cdf0e10cSrcweir                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ),
216*cdf0e10cSrcweir                     ::getCppuType((const ::com::sun::star::uno::Reference< css::frame::XController >*)NULL ),
217*cdf0e10cSrcweir                     ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XComponent >*)NULL ),
218*cdf0e10cSrcweir                     lWindowTypes);
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir             pTypeCollection = &aTypeCollection;
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir         /* } GLOBAL SAFE */
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir     return pTypeCollection->getTypes();
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir //_______________________________________________
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir /** create one unique Id for all instances of this class.
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     Optimize this method
232*cdf0e10cSrcweir     We initialize a static variable only one time. And we don't must use a mutex at every call!
233*cdf0e10cSrcweir     For the first call; pID is NULL - for the second call pID is different from NULL!
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     @return A byte array, which represent the unique id.
236*cdf0e10cSrcweir */
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir css::uno::Sequence< sal_Int8 > SAL_CALL BackingComp::getImplementationId()
239*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     static ::cppu::OImplementationId* pID = NULL;
242*cdf0e10cSrcweir     if (!pID)
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         /* GLOBAL SAFE { */
245*cdf0e10cSrcweir         ::osl::MutexGuard aLock(::osl::Mutex::getGlobalMutex());
246*cdf0e10cSrcweir         // Control these pointer again ... it can be, that another instance will be faster then this one!
247*cdf0e10cSrcweir         if (!pID)
248*cdf0e10cSrcweir         {
249*cdf0e10cSrcweir             static ::cppu::OImplementationId aID(sal_False);
250*cdf0e10cSrcweir             pID = &aID;
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir         /* } GLOBAL SAFE */
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir     return pID->getImplementationId();
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir //_______________________________________________
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir /** returns a static implementation name for this UNO service.
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     Because this value is needed at different places and our class is used
262*cdf0e10cSrcweir     by some generic macros too, we have to use a static impl method for that!
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     @see impl_getStaticImplementationName()
265*cdf0e10cSrcweir     @see IMPLEMENTATIONNAME
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     @return The implementation name of this class.
268*cdf0e10cSrcweir */
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir ::rtl::OUString SAL_CALL BackingComp::getImplementationName()
271*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     return impl_getStaticImplementationName();
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir //_______________________________________________
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir /** returns information about supported services.
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     Because this value is needed at different places and our class is used
281*cdf0e10cSrcweir     by some generic macros too, we have to use a static impl method for that!
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     @see impl_getStaticSupportedServiceNames()
284*cdf0e10cSrcweir     @see SERVICENAME
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     @return <TRUE/> if the queried service is supported;
287*cdf0e10cSrcweir             <br><FALSE/> otherwise.
288*cdf0e10cSrcweir */
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir sal_Bool SAL_CALL BackingComp::supportsService( /*IN*/ const ::rtl::OUString& sServiceName )
291*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     return (
294*cdf0e10cSrcweir             sServiceName.equals(SERVICENAME_STARTMODULE    ) ||
295*cdf0e10cSrcweir             sServiceName.equals(SERVICENAME_FRAMECONTROLLER)
296*cdf0e10cSrcweir            );
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir //_______________________________________________
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir /** returns collection of supported services.
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     Because this value is needed at different places and our class is used
304*cdf0e10cSrcweir     by some generic macros too, we have to use a static impl method for that!
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     @see impl_getStaticSupportedServiceNames()
307*cdf0e10cSrcweir     @see SERVICENAME
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     @return A list of all supported uno service names.
310*cdf0e10cSrcweir */
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL BackingComp::getSupportedServiceNames()
313*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     return impl_getStaticSupportedServiceNames();
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir //_______________________________________________
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir /** returns static implementation name.
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     Because this value is needed at different places and our class is used
323*cdf0e10cSrcweir     by some generic macros too, we have to use a static impl method for that!
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     @see impl_getStaticSupportedServiceNames()
326*cdf0e10cSrcweir     @see SERVICENAME
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     @return The implementation name of this class.
329*cdf0e10cSrcweir */
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir ::rtl::OUString BackingComp::impl_getStaticImplementationName()
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir     return IMPLEMENTATIONNAME_STARTMODULE;
334*cdf0e10cSrcweir }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir //_______________________________________________
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir /** returns static list of supported service names.
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     Because this value is needed at different places and our class is used
341*cdf0e10cSrcweir     by some generic macros too, we have to use a static impl method for that!
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     @see impl_getStaticSupportedServiceNames()
344*cdf0e10cSrcweir     @see SERVICENAME
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     @return A list of all supported uno service names.
347*cdf0e10cSrcweir */
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > BackingComp::impl_getStaticSupportedServiceNames()
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > lNames(1);
352*cdf0e10cSrcweir     lNames[0] = SERVICENAME_STARTMODULE;
353*cdf0e10cSrcweir     return lNames;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir //_______________________________________________
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir /** returns a new instance of this class.
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir     This factory method is registered inside the UNO runtime
361*cdf0e10cSrcweir     and will be called for every createInstance() request from outside,
362*cdf0e10cSrcweir     which wish to use this service.
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     @param  xSMGR
365*cdf0e10cSrcweir                 reference to the uno service manager, which call us
366*cdf0e10cSrcweir                 We use it too, to set it at the new created instance.
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     @return A new instance as uno reference.
369*cdf0e10cSrcweir */
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL BackingComp::impl_createInstance( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
372*cdf0e10cSrcweir     throw(css::uno::Exception)
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir     BackingComp* pObject = new BackingComp(xSMGR);
375*cdf0e10cSrcweir     return css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(pObject), css::uno::UNO_QUERY);
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //_______________________________________________
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir /** returns a new factory instance for instances of this class.
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     It uses a helper class of the cppuhelper project as factory.
383*cdf0e10cSrcweir     It will be initialized with all neccessary informations and
384*cdf0e10cSrcweir     will be able afterwards to create instance of this class.
385*cdf0e10cSrcweir     This factory call us back inside our method impl_createInstance().
386*cdf0e10cSrcweir     So we can create and initialize ourself. Only filtering of creation
387*cdf0e10cSrcweir     requests will be done by this factory.
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir     @param  xSMGR
390*cdf0e10cSrcweir                 reference to the uno service manager, which call us
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     @return A new instance of our factory.
393*cdf0e10cSrcweir */
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > BackingComp::impl_createFactory( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir     css::uno::Reference< css::lang::XSingleServiceFactory > xReturn(
398*cdf0e10cSrcweir         cppu::createSingleFactory(
399*cdf0e10cSrcweir             xSMGR,
400*cdf0e10cSrcweir             BackingComp::impl_getStaticImplementationName(),
401*cdf0e10cSrcweir             BackingComp::impl_createInstance,
402*cdf0e10cSrcweir             BackingComp::impl_getStaticSupportedServiceNames()));
403*cdf0e10cSrcweir     return xReturn;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir //_______________________________________________
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir /**
409*cdf0e10cSrcweir     attach this component to a target frame.
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     We has to use the container window of this frame as parent window of our own component window.
412*cdf0e10cSrcweir     But it's not allowed to work with it realy. May another component used it too.
413*cdf0e10cSrcweir     Currently we need it only to create our child component window and support it's
414*cdf0e10cSrcweir     interfaces inside our queryInterface() method. The user of us must have e.g. the
415*cdf0e10cSrcweir     XWindow interface of it to be able to call setComponent(xWindow,xController) at the
416*cdf0e10cSrcweir     frame!
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     May he will do the following things:
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     <listing>
421*cdf0e10cSrcweir         XController xBackingComp = (XController)UnoRuntime.queryInterface(
422*cdf0e10cSrcweir             XController.class,
423*cdf0e10cSrcweir             xSMGR.createInstance(SERVICENAME_STARTMODULE));
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         // at this time XWindow isn't present at this instance!
426*cdf0e10cSrcweir         XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
427*cdf0e10cSrcweir             XWindow.class,
428*cdf0e10cSrcweir             xBackingComp);
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir         // attach controller to the frame
431*cdf0e10cSrcweir         // We will use it's container window, to create
432*cdf0e10cSrcweir         // the component window. From now we offer the window interfaces!
433*cdf0e10cSrcweir         xBackingComp.attachFrame(xFrame);
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir         XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
436*cdf0e10cSrcweir             XWindow.class,
437*cdf0e10cSrcweir             xBackingComp);
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir         // Our user can set us at the frame as new component
440*cdf0e10cSrcweir         xFrame.setComponent(xBackingWin, xBackingComp);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         // But that had no effect to our view state.
443*cdf0e10cSrcweir         // We must be started to create our UI elements like e.g. menu, title, background ...
444*cdf0e10cSrcweir         XInitialization xBackingInit = (XInitialization)UnoRuntime.queryInterface(
445*cdf0e10cSrcweir             XInitialization.class,
446*cdf0e10cSrcweir             xBackingComp);
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         xBackingInit.initialize(lArgs);
449*cdf0e10cSrcweir     </listing>
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     @param  xFrame
452*cdf0e10cSrcweir                 reference to our new target frame
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir     @throw  com::sun::star::uno::RuntimeException
455*cdf0e10cSrcweir                 if the given frame reference is wrong or component window couldn't be created
456*cdf0e10cSrcweir                 successfully.
457*cdf0e10cSrcweir                 We throw it too, if we already attached to a frame. Because we don't support
458*cdf0e10cSrcweir                 reparenting of our component window on demand!
459*cdf0e10cSrcweir */
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir void SAL_CALL BackingComp::attachFrame( /*IN*/ const css::uno::Reference< css::frame::XFrame >& xFrame )
462*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir     /* SAFE */
465*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir     // check some required states
468*cdf0e10cSrcweir     if (m_xFrame.is())
469*cdf0e10cSrcweir         throw css::uno::RuntimeException(
470*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("already attached"),
471*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir     if (!xFrame.is())
474*cdf0e10cSrcweir         throw css::uno::RuntimeException(
475*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("invalid frame reference"),
476*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir     if (!m_xWindow.is())
479*cdf0e10cSrcweir         throw css::uno::RuntimeException(
480*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("instance seams to be not or wrong initialized"),
481*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     // safe the frame reference
484*cdf0e10cSrcweir     m_xFrame = xFrame;
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir     // establish drag&drop mode
487*cdf0e10cSrcweir     ::framework::DropTargetListener* pDropListener = new ::framework::DropTargetListener(m_xSMGR, m_xFrame);
488*cdf0e10cSrcweir     m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >(static_cast< ::cppu::OWeakObject* >(pDropListener), css::uno::UNO_QUERY);
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     css::uno::Reference< css::awt::XDataTransferProviderAccess > xTransfer(m_xSMGR->createInstance(SERVICENAME_VCLTOOLKIT), css::uno::UNO_QUERY);
491*cdf0e10cSrcweir     if (xTransfer.is())
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir         css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xTransfer->getDropTarget(m_xWindow);
494*cdf0e10cSrcweir         if (xDropTarget.is())
495*cdf0e10cSrcweir         {
496*cdf0e10cSrcweir             xDropTarget->addDropTargetListener(m_xDropTargetListener);
497*cdf0e10cSrcweir             xDropTarget->setActive(sal_True);
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir     }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     // initialize the component and it's parent window
502*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow();
503*cdf0e10cSrcweir     WorkWindow* pParent = (WorkWindow*)VCLUnoHelper::GetWindow(xParentWindow);
504*cdf0e10cSrcweir     Window*     pWindow = VCLUnoHelper::GetWindow(m_xWindow);
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     // disable full screen mode of the frame!
507*cdf0e10cSrcweir     if (pParent->IsFullScreenMode())
508*cdf0e10cSrcweir     {
509*cdf0e10cSrcweir         pParent->ShowFullScreenMode(sal_False);
510*cdf0e10cSrcweir         pParent->SetMenuBarMode(MENUBAR_MODE_NORMAL);
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     // create the menu bar for the backing component
514*cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY_THROW);
515*cdf0e10cSrcweir     css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
516*cdf0e10cSrcweir     xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
517*cdf0e10cSrcweir     if (xLayoutManager.is())
518*cdf0e10cSrcweir     {
519*cdf0e10cSrcweir         xLayoutManager->lock();
520*cdf0e10cSrcweir         xLayoutManager->createElement( DECLARE_ASCII( "private:resource/menubar/menubar"     ));
521*cdf0e10cSrcweir         /* #i85963# new backing window comes withoud standard bar and statusbar
522*cdf0e10cSrcweir         xLayoutManager->createElement( DECLARE_ASCII( "private:resource/toolbar/standardbar" ));
523*cdf0e10cSrcweir         xLayoutManager->createElement( DECLARE_ASCII( "private:resource/statusbar/statusbar" ));
524*cdf0e10cSrcweir         xLayoutManager->showElement  ( DECLARE_ASCII( "private:resource/toolbar/standardbar" ));
525*cdf0e10cSrcweir         xLayoutManager->showElement  ( DECLARE_ASCII( "private:resource/statusbar/statusbar" ));
526*cdf0e10cSrcweir         */
527*cdf0e10cSrcweir         xLayoutManager->unlock();
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     // set help ID for our canvas
531*cdf0e10cSrcweir     pWindow->SetHelpId(HID_BACKINGWINDOW);
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     // inform BackingWindow about frame
534*cdf0e10cSrcweir     BackingWindow* pBack = dynamic_cast<BackingWindow*>(pWindow );
535*cdf0e10cSrcweir     if( pBack )
536*cdf0e10cSrcweir         pBack->setOwningFrame( m_xFrame );
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     aWriteLock.unlock();
539*cdf0e10cSrcweir     /* } SAFE */
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir //_______________________________________________
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir /** not supported.
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     This component does not know any model. It will be represented by a window and
547*cdf0e10cSrcweir     it's controller only.
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir     return  <FALSE/> everytime.
550*cdf0e10cSrcweir  */
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir sal_Bool SAL_CALL BackingComp::attachModel( /*IN*/ const css::uno::Reference< css::frame::XModel >& )
553*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir     return sal_False;
556*cdf0e10cSrcweir }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir //_______________________________________________
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir /** not supported.
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     This component does not know any model. It will be represented by a window and
563*cdf0e10cSrcweir     it's controller only.
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir     return  An empty reference every time.
566*cdf0e10cSrcweir  */
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > SAL_CALL BackingComp::getModel()
569*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     return css::uno::Reference< css::frame::XModel >();
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir //_______________________________________________
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir /** not supported.
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir     return  An empty value.
579*cdf0e10cSrcweir  */
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir css::uno::Any SAL_CALL BackingComp::getViewData()
582*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir     return css::uno::Any();
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir //_______________________________________________
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir /** not supported.
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     @param  aData
592*cdf0e10cSrcweir                 not used.
593*cdf0e10cSrcweir  */
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir void SAL_CALL BackingComp::restoreViewData( /*IN*/ const css::uno::Any& )
596*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
597*cdf0e10cSrcweir {
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir //_______________________________________________
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir /** returns the attached frame for this component.
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir     @see    attachFrame()
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir     @return The internaly saved frame reference.
607*cdf0e10cSrcweir             Can be null, if attachFrame() was not called before.
608*cdf0e10cSrcweir  */
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > SAL_CALL BackingComp::getFrame()
611*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     /* SAFE { */
614*cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
615*cdf0e10cSrcweir     return m_xFrame;
616*cdf0e10cSrcweir     /* } SAFE */
617*cdf0e10cSrcweir }
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir //_______________________________________________
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir /** ask controller for it's current working state.
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     If somehwere whish to close this component, it must suspend the controller before.
624*cdf0e10cSrcweir     That will be a chance for it to disagree with that AND show any UI for a possible
625*cdf0e10cSrcweir     UI user.
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir     @param  bSuspend
628*cdf0e10cSrcweir                 If its set to sal_True this controller should be suspended.
629*cdf0e10cSrcweir                 sal_False will resuspend it.
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir     @return sal_True if the request could be finished successfully; sal_False otherwise.
632*cdf0e10cSrcweir  */
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir sal_Bool SAL_CALL BackingComp::suspend( /*IN*/ sal_Bool )
635*cdf0e10cSrcweir     throw (css::uno::RuntimeException)
636*cdf0e10cSrcweir {
637*cdf0e10cSrcweir     /* FIXME ... implemented by using default :-( */
638*cdf0e10cSrcweir     return sal_True;
639*cdf0e10cSrcweir }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir //_______________________________________________
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir /** callback from our window member.
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     Our internal saved window wish to die. It will be disposed from outside (may be the frame)
646*cdf0e10cSrcweir     and inform us. We must release its reference only here. Of course we check the given reference
647*cdf0e10cSrcweir     here and reject callback from unknown sources.
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir     Note: deregistration as listener isnt neccessary here. The broadcaster do it automaticly.
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir     @param  aEvent
652*cdf0e10cSrcweir                 describe the broadcaster of this callback
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir     @throw ::com::sun::star::uno::RuntimeException
655*cdf0e10cSrcweir                 if the broadcaster doesn't represent the expected window reference.
656*cdf0e10cSrcweir */
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir void SAL_CALL BackingComp::disposing( /*IN*/ const css::lang::EventObject& aEvent )
659*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
660*cdf0e10cSrcweir {
661*cdf0e10cSrcweir     // Attention: dont free m_pAccExec here! see comments inside dtor and
662*cdf0e10cSrcweir     // keyPressed() for further details.
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     /* SAFE { */
665*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     if (!aEvent.Source.is() || aEvent.Source!=m_xWindow || !m_xWindow.is())
668*cdf0e10cSrcweir         throw css::uno::RuntimeException(
669*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("unexpected source or called twice"),
670*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir     m_xWindow = css::uno::Reference< css::awt::XWindow >();
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     aWriteLock.unlock();
675*cdf0e10cSrcweir     /* } SAFE */
676*cdf0e10cSrcweir }
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir //_______________________________________________
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir /** kill this instance.
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir     It can be called from our owner frame only. But there is no possibility to check the calli.
683*cdf0e10cSrcweir     We have to release all our internal used ressources and die. From this point we can throw
684*cdf0e10cSrcweir     DisposedExceptions for every further interface request ... but current implementation doesn`t do so ...
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir */
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir void SAL_CALL BackingComp::dispose()
689*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
690*cdf0e10cSrcweir {
691*cdf0e10cSrcweir     /* SAFE { */
692*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir     // kill the menu
695*cdf0e10cSrcweir     css::util::URL aURL;
696*cdf0e10cSrcweir     aURL.Complete = DECLARE_ASCII(".uno:close");
697*cdf0e10cSrcweir     css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY);
698*cdf0e10cSrcweir     if (xParser.is())
699*cdf0e10cSrcweir         xParser->parseStrict(aURL);
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchProvider > xProvider(m_xFrame, css::uno::UNO_QUERY);
702*cdf0e10cSrcweir     if (xProvider.is())
703*cdf0e10cSrcweir     {
704*cdf0e10cSrcweir         css::uno::Reference< css::frame::XDispatch > xDispatch = xProvider->queryDispatch(aURL, SPECIALTARGET_MENUBAR, 0);
705*cdf0e10cSrcweir         if (xDispatch.is())
706*cdf0e10cSrcweir             xDispatch->dispatch(aURL, css::uno::Sequence< css::beans::PropertyValue>());
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     // deregister drag&drop helper
710*cdf0e10cSrcweir     if (m_xDropTargetListener.is())
711*cdf0e10cSrcweir     {
712*cdf0e10cSrcweir         css::uno::Reference< css::awt::XDataTransferProviderAccess > xTransfer(m_xSMGR->createInstance(SERVICENAME_VCLTOOLKIT), css::uno::UNO_QUERY);
713*cdf0e10cSrcweir         if (xTransfer.is())
714*cdf0e10cSrcweir         {
715*cdf0e10cSrcweir             css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xTransfer->getDropTarget(m_xWindow);
716*cdf0e10cSrcweir             if (xDropTarget.is())
717*cdf0e10cSrcweir             {
718*cdf0e10cSrcweir                 xDropTarget->removeDropTargetListener(m_xDropTargetListener);
719*cdf0e10cSrcweir                 xDropTarget->setActive(sal_False);
720*cdf0e10cSrcweir             }
721*cdf0e10cSrcweir         }
722*cdf0e10cSrcweir         m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >();
723*cdf0e10cSrcweir     }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir     // stop listening at the window
726*cdf0e10cSrcweir     if (m_xWindow.is())
727*cdf0e10cSrcweir     {
728*cdf0e10cSrcweir         css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
729*cdf0e10cSrcweir         if (xBroadcaster.is())
730*cdf0e10cSrcweir         {
731*cdf0e10cSrcweir             css::uno::Reference< css::lang::XEventListener > xEventThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
732*cdf0e10cSrcweir             xBroadcaster->removeEventListener(xEventThis);
733*cdf0e10cSrcweir         }
734*cdf0e10cSrcweir         css::uno::Reference< css::awt::XKeyListener > xKeyThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
735*cdf0e10cSrcweir         m_xWindow->removeKeyListener(xKeyThis);
736*cdf0e10cSrcweir         m_xWindow = css::uno::Reference< css::awt::XWindow >();
737*cdf0e10cSrcweir     }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir     // forget all other used references
740*cdf0e10cSrcweir     m_xFrame  = css::uno::Reference< css::frame::XFrame >();
741*cdf0e10cSrcweir     m_xSMGR   = css::uno::Reference< css::lang::XMultiServiceFactory >();
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     aWriteLock.unlock();
744*cdf0e10cSrcweir     /* } SAFE */
745*cdf0e10cSrcweir }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir //_______________________________________________
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir /** not supported.
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     @param  xListener
752*cdf0e10cSrcweir                 not used.
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir     @throw  ::com::sun::star::uno::RuntimeException
755*cdf0e10cSrcweir                 because the listener expect to be holded alive by this container.
756*cdf0e10cSrcweir                 We must inform it about this unsupported feature.
757*cdf0e10cSrcweir  */
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir void SAL_CALL BackingComp::addEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
760*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir     throw css::uno::RuntimeException(
763*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("not supported"),
764*cdf0e10cSrcweir             static_cast< ::cppu::OWeakObject* >(this));
765*cdf0e10cSrcweir }
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir //_______________________________________________
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir /** not supported.
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir     Because registration is not supported too, we must do nothing here. Nobody can call this method realy.
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir     @param  xListener
774*cdf0e10cSrcweir                 not used.
775*cdf0e10cSrcweir  */
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir void SAL_CALL BackingComp::removeEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
778*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
779*cdf0e10cSrcweir {
780*cdf0e10cSrcweir }
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir //_______________________________________________
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir /**
785*cdf0e10cSrcweir     force initialiation for this component.
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir     Inside attachFrame() we created our component window. But it was not allowed there, to
788*cdf0e10cSrcweir     initialitze it. E.g. the menu must be set at the container window of the frame, which
789*cdf0e10cSrcweir     is our parent window. But may at that time another component used it.
790*cdf0e10cSrcweir     That's why our creator has to inform us, when it's time to initialize us realy.
791*cdf0e10cSrcweir     Currently only calling of this method must be done. But further implementatoins
792*cdf0e10cSrcweir     can use special in parameter to configure this initialization ...
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir     @param  lArgs
795*cdf0e10cSrcweir                 currently not used
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir     @throw  com::sun::star::uno::RuntimeException
798*cdf0e10cSrcweir                 if some ressources are missing
799*cdf0e10cSrcweir                 Means if may be attachedFrame() wasn't called before.
800*cdf0e10cSrcweir  */
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir void SAL_CALL BackingComp::initialize( /*IN*/ const css::uno::Sequence< css::uno::Any >& lArgs )
803*cdf0e10cSrcweir     throw(css::uno::Exception, css::uno::RuntimeException)
804*cdf0e10cSrcweir {
805*cdf0e10cSrcweir     /* SAFE { */
806*cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir     if (m_xWindow.is())
809*cdf0e10cSrcweir         throw css::uno::Exception(
810*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("already initialized"),
811*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow > xParentWindow;
814*cdf0e10cSrcweir     if (
815*cdf0e10cSrcweir         (lArgs.getLength()!=1         ) ||
816*cdf0e10cSrcweir         (!(lArgs[0] >>= xParentWindow)) ||
817*cdf0e10cSrcweir         (!xParentWindow.is()          )
818*cdf0e10cSrcweir        )
819*cdf0e10cSrcweir     {
820*cdf0e10cSrcweir         throw css::uno::Exception(
821*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("wrong or corrupt argument list"),
822*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
823*cdf0e10cSrcweir     }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir     // create the component window
826*cdf0e10cSrcweir     Window* pParent   = VCLUnoHelper::GetWindow(xParentWindow);
827*cdf0e10cSrcweir     Window* pWindow   = new BackingWindow(pParent);
828*cdf0e10cSrcweir             m_xWindow = VCLUnoHelper::GetInterface(pWindow);
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     if (!m_xWindow.is())
831*cdf0e10cSrcweir         throw css::uno::RuntimeException(
832*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("couldn't create component window"),
833*cdf0e10cSrcweir                 static_cast< ::cppu::OWeakObject* >(this));
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir     // start listening for window disposing
836*cdf0e10cSrcweir     // It's set at our owner frame as component window later too. So it will may be disposed there ...
837*cdf0e10cSrcweir     css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
838*cdf0e10cSrcweir     if (xBroadcaster.is())
839*cdf0e10cSrcweir         xBroadcaster->addEventListener(static_cast< css::lang::XEventListener* >(this));
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir     m_xWindow->setVisible(sal_True);
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     aWriteLock.unlock();
844*cdf0e10cSrcweir     /* } SAFE */
845*cdf0e10cSrcweir }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir //_______________________________________________
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir /**
850*cdf0e10cSrcweir  */
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir void SAL_CALL BackingComp::keyPressed( /*IN*/ const css::awt::KeyEvent&  )
853*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
854*cdf0e10cSrcweir {
855*cdf0e10cSrcweir }
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir //_______________________________________________
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir /**
860*cdf0e10cSrcweir  */
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir void SAL_CALL BackingComp::keyReleased( /*IN*/ const css::awt::KeyEvent& )
863*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
864*cdf0e10cSrcweir {
865*cdf0e10cSrcweir     /* Attention
866*cdf0e10cSrcweir         Please use keyPressed() instead of this method. Otherwhise it would be possible, that
867*cdf0e10cSrcweir         - a key input may be first switch to the backing mode
868*cdf0e10cSrcweir         - and this component register itself as key listener too
869*cdf0e10cSrcweir         - and it's first event will be a keyRealeased() for the already well known event, which switched to the backing mode!
870*cdf0e10cSrcweir         So it will be handled twice! document => backing mode => exit app ...
871*cdf0e10cSrcweir      */
872*cdf0e10cSrcweir }
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir } // namespace framework
875