update credits
[LibreOffice.git] / framework / source / services / backingcomp.cxx
blob88515c03f10f8fd2d2f17a5b3d170f726115a0e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "services/backingcomp.hxx"
22 #include "backingwindow.hxx"
24 #include <threadhelp/readguard.hxx>
25 #include <threadhelp/writeguard.hxx>
26 #include <classes/droptargetlistener.hxx>
27 #include <targets.h>
28 #include <properties.h>
29 #include <services.h>
31 #include <helpid.hrc>
33 #include <com/sun/star/beans/NamedValue.hpp>
34 #include <com/sun/star/util/XURLTransformer.hpp>
35 #include <com/sun/star/frame/XDispatchProvider.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/awt/Toolkit.hpp>
38 #include <com/sun/star/awt/XDataTransferProviderAccess.hpp>
39 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
40 #include <com/sun/star/awt/KeyEvent.hpp>
41 #include <com/sun/star/awt/KeyModifier.hpp>
42 #include <com/sun/star/frame/XLayoutManager.hpp>
43 #include <com/sun/star/util/URLTransformer.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <cppuhelper/typeprovider.hxx>
47 #include <cppuhelper/factory.hxx>
48 #include <toolkit/helper/vclunohelper.hxx>
49 #include <vcl/keycod.hxx>
50 #include <vcl/wrkwin.hxx>
51 #include <vcl/svapp.hxx>
52 #include <rtl/ustrbuf.hxx>
54 #include <svl/solar.hrc>
55 #include <svl/urihelper.hxx>
56 #include <osl/file.hxx>
57 #include <unotools/configmgr.hxx>
59 #include <unotools/bootstrap.hxx>
61 namespace framework
64 //_______________________________________________
66 //_______________________________________________
68 BackingComp::BackingComp( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR )
69 : ThreadHelpBase (&Application::GetSolarMutex() )
70 , m_xSMGR (xSMGR )
74 //_______________________________________________
76 BackingComp::~BackingComp()
80 //_______________________________________________
82 /** return information about supported interfaces.
84 Some interfaces are supported by his class directly, but some other ones are
85 used by aggregation. An instance of this class must provide some window interfaces.
86 But it must represent a VCL window behind such interfaces too! So we use an internal
87 saved window member to ask it for it's interfaces and return it. But we must be aware then,
88 that it can be destroyed from outside too ...
90 @param aType
91 describe the required interface type
93 @return An Any holding the instance, which provides the queried interface.
94 Note: There exist two possible results ... this instance itself and her window member!
97 css::uno::Any SAL_CALL BackingComp::queryInterface( /*IN*/ const css::uno::Type& aType )
98 throw(css::uno::RuntimeException)
100 css::uno::Any aResult;
102 // first look for own supported interfaces
103 aResult = ::cppu::queryInterface(
104 aType,
105 static_cast< css::lang::XTypeProvider* >(this),
106 static_cast< css::lang::XServiceInfo* >(this),
107 static_cast< css::lang::XInitialization* >(this),
108 static_cast< css::frame::XController* >(this),
109 static_cast< css::lang::XComponent* >(this),
110 static_cast< css::lang::XEventListener* >(this),
111 static_cast< css::awt::XKeyListener* >(static_cast< css::lang::XEventListener* >(this)));
113 // then look for supported window interfaces
114 // Note: They exist only, if this instance was initialized
115 // with a valid window reference. It's aggregation on demand ...
116 if (!aResult.hasValue())
118 /* SAFE { */
119 ReadGuard aReadLock(m_aLock);
120 if (m_xWindow.is())
121 aResult = m_xWindow->queryInterface(aType);
122 aReadLock.unlock();
123 /* } SAFE */
126 // look for XWeak and XInterface
127 if (!aResult.hasValue())
128 aResult = OWeakObject::queryInterface(aType);
130 return aResult;
133 //_______________________________________________
135 /** increase ref count of this instance.
138 void SAL_CALL BackingComp::acquire()
139 throw()
141 OWeakObject::acquire();
144 //_______________________________________________
146 /** decrease ref count of this instance.
149 void SAL_CALL BackingComp::release()
150 throw()
152 OWeakObject::release();
155 //_______________________________________________
157 /** return collection about all supported interfaces.
159 Optimize this method !
160 We initialize a static variable only one time.
161 And we don't must use a mutex at every call!
162 For the first call; pTypeCollection is NULL -
163 for the second call pTypeCollection is different from NULL!
165 @return A list of all supported interface types.
168 css::uno::Sequence< css::uno::Type > SAL_CALL BackingComp::getTypes()
169 throw(css::uno::RuntimeException)
171 static ::cppu::OTypeCollection* pTypeCollection = NULL;
172 if (!pTypeCollection)
174 /* GLOBAL SAFE { */
175 ::osl::MutexGuard aGlobalLock(::osl::Mutex::getGlobalMutex());
176 // Control these pointer again ... it can be, that another instance will be faster then this one!
177 if (!pTypeCollection)
179 /* LOCAL SAFE { */
180 ReadGuard aReadLock(m_aLock);
181 css::uno::Reference< css::lang::XTypeProvider > xProvider(m_xWindow, css::uno::UNO_QUERY);
182 aReadLock.unlock();
183 /* } LOCAL SAFE */
185 css::uno::Sequence< css::uno::Type > lWindowTypes;
186 if (xProvider.is())
187 lWindowTypes = xProvider->getTypes();
189 static ::cppu::OTypeCollection aTypeCollection(
190 ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XInitialization >*)NULL ),
191 ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ),
192 ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ),
193 ::getCppuType((const ::com::sun::star::uno::Reference< css::frame::XController >*)NULL ),
194 ::getCppuType((const ::com::sun::star::uno::Reference< css::lang::XComponent >*)NULL ),
195 lWindowTypes);
197 pTypeCollection = &aTypeCollection;
199 /* } GLOBAL SAFE */
201 return pTypeCollection->getTypes();
204 //_______________________________________________
206 /** create one unique Id for all instances of this class.
208 Optimize this method
209 We initialize a static variable only one time. And we don't must use a mutex at every call!
210 For the first call; pID is NULL - for the second call pID is different from NULL!
212 @return A byte array, which represent the unique id.
215 css::uno::Sequence< sal_Int8 > SAL_CALL BackingComp::getImplementationId()
216 throw(css::uno::RuntimeException)
218 static ::cppu::OImplementationId* pID = NULL;
219 if (!pID)
221 /* GLOBAL SAFE { */
222 ::osl::MutexGuard aLock(::osl::Mutex::getGlobalMutex());
223 // Control these pointer again ... it can be, that another instance will be faster then this one!
224 if (!pID)
226 static ::cppu::OImplementationId aID(sal_False);
227 pID = &aID;
229 /* } GLOBAL SAFE */
231 return pID->getImplementationId();
234 //_______________________________________________
236 /** returns a static implementation name for this UNO service.
238 Because this value is needed at different places and our class is used
239 by some generic macros too, we have to use a static impl method for that!
241 @see impl_getStaticImplementationName()
242 @see IMPLEMENTATIONNAME
244 @return The implementation name of this class.
247 OUString SAL_CALL BackingComp::getImplementationName()
248 throw(css::uno::RuntimeException)
250 return impl_getStaticImplementationName();
253 //_______________________________________________
255 /** returns information about supported services.
257 Because this value is needed at different places and our class is used
258 by some generic macros too, we have to use a static impl method for that!
260 @see impl_getStaticSupportedServiceNames()
261 @see SERVICENAME
263 @return <TRUE/> if the queried service is supported;
264 <br><FALSE/> otherwise.
267 sal_Bool SAL_CALL BackingComp::supportsService( /*IN*/ const OUString& sServiceName )
268 throw(css::uno::RuntimeException)
270 return (
271 sServiceName.equals("com.sun.star.frame.StartModule") ||
272 sServiceName.equals(SERVICENAME_FRAMECONTROLLER)
276 //_______________________________________________
278 /** returns collection of supported services.
280 Because this value is needed at different places and our class is used
281 by some generic macros too, we have to use a static impl method for that!
283 @see impl_getStaticSupportedServiceNames()
284 @see SERVICENAME
286 @return A list of all supported uno service names.
289 css::uno::Sequence< OUString > SAL_CALL BackingComp::getSupportedServiceNames()
290 throw(css::uno::RuntimeException)
292 return impl_getStaticSupportedServiceNames();
295 //_______________________________________________
297 /** returns static implementation name.
299 Because this value is needed at different places and our class is used
300 by some generic macros too, we have to use a static impl method for that!
302 @see impl_getStaticSupportedServiceNames()
303 @see SERVICENAME
305 @return The implementation name of this class.
308 OUString BackingComp::impl_getStaticImplementationName()
310 return IMPLEMENTATIONNAME_STARTMODULE;
313 //_______________________________________________
315 /** returns static list of supported service names.
317 Because this value is needed at different places and our class is used
318 by some generic macros too, we have to use a static impl method for that!
320 @see impl_getStaticSupportedServiceNames()
321 @see SERVICENAME
323 @return A list of all supported uno service names.
326 css::uno::Sequence< OUString > BackingComp::impl_getStaticSupportedServiceNames()
328 css::uno::Sequence< OUString > lNames(1);
329 lNames[0] = "com.sun.star.frame.StartModule";
330 return lNames;
333 //_______________________________________________
335 /** returns a new instance of this class.
337 This factory method is registered inside the UNO runtime
338 and will be called for every createInstance() request from outside,
339 which wish to use this service.
341 @param xSMGR
342 reference to the uno service manager, which call us
343 We use it too, to set it at the new created instance.
345 @return A new instance as uno reference.
348 css::uno::Reference< css::uno::XInterface > SAL_CALL BackingComp::impl_createInstance( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
349 throw(css::uno::Exception)
351 BackingComp* pObject = new BackingComp(xSMGR);
352 return css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(pObject), css::uno::UNO_QUERY);
355 //_______________________________________________
357 /** returns a new factory instance for instances of this class.
359 It uses a helper class of the cppuhelper project as factory.
360 It will be initialized with all neccessary information and
361 will be able afterwards to create instance of this class.
362 This factory call us back inside our method impl_createInstance().
363 So we can create and initialize ourself. Only filtering of creation
364 requests will be done by this factory.
366 @param xSMGR
367 reference to the uno service manager, which call us
369 @return A new instance of our factory.
372 css::uno::Reference< css::lang::XSingleServiceFactory > BackingComp::impl_createFactory( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
374 css::uno::Reference< css::lang::XSingleServiceFactory > xReturn(
375 cppu::createSingleFactory(
376 xSMGR,
377 BackingComp::impl_getStaticImplementationName(),
378 BackingComp::impl_createInstance,
379 BackingComp::impl_getStaticSupportedServiceNames()));
380 return xReturn;
383 //_______________________________________________
386 attach this component to a target frame.
388 We has to use the container window of this frame as parent window of our own component window.
389 But it's not allowed to work with it realy. May another component used it too.
390 Currently we need it only to create our child component window and support it's
391 interfaces inside our queryInterface() method. The user of us must have e.g. the
392 XWindow interface of it to be able to call setComponent(xWindow,xController) at the
393 frame!
395 May he will do the following things:
397 <listing>
398 XController xBackingComp = (XController)UnoRuntime.queryInterface(
399 XController.class,
400 xSMGR.createInstance(SERVICENAME_STARTMODULE));
402 // at this time XWindow isn't present at this instance!
403 XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
404 XWindow.class,
405 xBackingComp);
407 // attach controller to the frame
408 // We will use it's container window, to create
409 // the component window. From now we offer the window interfaces!
410 xBackingComp.attachFrame(xFrame);
412 XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
413 XWindow.class,
414 xBackingComp);
416 // Our user can set us at the frame as new component
417 xFrame.setComponent(xBackingWin, xBackingComp);
419 // But that had no effect to our view state.
420 // We must be started to create our UI elements like e.g. menu, title, background ...
421 XInitialization xBackingInit = (XInitialization)UnoRuntime.queryInterface(
422 XInitialization.class,
423 xBackingComp);
425 xBackingInit.initialize(lArgs);
426 </listing>
428 @param xFrame
429 reference to our new target frame
431 @throw com::sun::star::uno::RuntimeException
432 if the given frame reference is wrong or component window couldn't be created
433 successfully.
434 We throw it too, if we already attached to a frame. Because we don't support
435 reparenting of our component window on demand!
438 void SAL_CALL BackingComp::attachFrame( /*IN*/ const css::uno::Reference< css::frame::XFrame >& xFrame )
439 throw (css::uno::RuntimeException)
441 /* SAFE */
442 WriteGuard aWriteLock(m_aLock);
444 // check some required states
445 if (m_xFrame.is())
446 throw css::uno::RuntimeException(
447 OUString("already attached"),
448 static_cast< ::cppu::OWeakObject* >(this));
450 if (!xFrame.is())
451 throw css::uno::RuntimeException(
452 OUString("invalid frame reference"),
453 static_cast< ::cppu::OWeakObject* >(this));
455 if (!m_xWindow.is())
456 return; // disposed
458 // safe the frame reference
459 m_xFrame = xFrame;
461 // establish drag&drop mode
462 ::framework::DropTargetListener* pDropListener = new ::framework::DropTargetListener(m_xSMGR, m_xFrame);
463 m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >(static_cast< ::cppu::OWeakObject* >(pDropListener), css::uno::UNO_QUERY);
465 css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create( comphelper::getComponentContext(m_xSMGR) );
466 css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xToolkit->getDropTarget(m_xWindow);
467 if (xDropTarget.is())
469 xDropTarget->addDropTargetListener(m_xDropTargetListener);
470 xDropTarget->setActive(sal_True);
473 // initialize the component and it's parent window
474 css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow();
475 WorkWindow* pParent = (WorkWindow*)VCLUnoHelper::GetWindow(xParentWindow);
476 Window* pWindow = VCLUnoHelper::GetWindow(m_xWindow);
478 // disable full screen mode of the frame!
479 if (pParent && pParent->IsFullScreenMode())
481 pParent->ShowFullScreenMode(sal_False);
482 pParent->SetMenuBarMode(MENUBAR_MODE_NORMAL);
485 // create the menu bar for the backing component
486 css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY_THROW);
487 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
488 xPropSet->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER) >>= xLayoutManager;
489 if (xLayoutManager.is())
491 xLayoutManager->lock();
492 xLayoutManager->createElement( DECLARE_ASCII( "private:resource/menubar/menubar" ));
493 xLayoutManager->unlock();
496 if (pWindow)
498 // set help ID for our canvas
499 pWindow->SetHelpId(HID_BACKINGWINDOW);
502 // inform BackingWindow about frame
503 BackingWindow* pBack = dynamic_cast<BackingWindow*>(pWindow );
504 if( pBack )
505 pBack->setOwningFrame( m_xFrame );
507 aWriteLock.unlock();
508 /* } SAFE */
511 //_______________________________________________
513 /** not supported.
515 This component does not know any model. It will be represented by a window and
516 it's controller only.
518 return <FALSE/> everytime.
521 sal_Bool SAL_CALL BackingComp::attachModel( /*IN*/ const css::uno::Reference< css::frame::XModel >& )
522 throw (css::uno::RuntimeException)
524 return sal_False;
527 //_______________________________________________
529 /** not supported.
531 This component does not know any model. It will be represented by a window and
532 it's controller only.
534 return An empty reference every time.
537 css::uno::Reference< css::frame::XModel > SAL_CALL BackingComp::getModel()
538 throw (css::uno::RuntimeException)
540 return css::uno::Reference< css::frame::XModel >();
543 //_______________________________________________
545 /** not supported.
547 return An empty value.
550 css::uno::Any SAL_CALL BackingComp::getViewData()
551 throw (css::uno::RuntimeException)
553 return css::uno::Any();
556 //_______________________________________________
558 /** not supported.
560 @param aData
561 not used.
564 void SAL_CALL BackingComp::restoreViewData( /*IN*/ const css::uno::Any& )
565 throw (css::uno::RuntimeException)
569 //_______________________________________________
571 /** returns the attached frame for this component.
573 @see attachFrame()
575 @return The internaly saved frame reference.
576 Can be null, if attachFrame() was not called before.
579 css::uno::Reference< css::frame::XFrame > SAL_CALL BackingComp::getFrame()
580 throw (css::uno::RuntimeException)
582 /* SAFE { */
583 ReadGuard aReadLock(m_aLock);
584 return m_xFrame;
585 /* } SAFE */
588 //_______________________________________________
590 /** ask controller for it's current working state.
592 If somehwere whish to close this component, it must suspend the controller before.
593 That will be a chance for it to disagree with that AND show any UI for a possible
594 UI user.
596 @param bSuspend
597 If its set to sal_True this controller should be suspended.
598 sal_False will resuspend it.
600 @return sal_True if the request could be finished successfully; sal_False otherwise.
603 sal_Bool SAL_CALL BackingComp::suspend( /*IN*/ sal_Bool )
604 throw (css::uno::RuntimeException)
606 /* FIXME ... implemented by using default :-( */
607 return sal_True;
610 //_______________________________________________
612 /** callback from our window member.
614 Our internal saved window wish to die. It will be disposed from outside (may be the frame)
615 and inform us. We must release its reference only here. Of course we check the given reference
616 here and reject callback from unknown sources.
618 Note: deregistration as listener isnt neccessary here. The broadcaster do it automaticly.
620 @param aEvent
621 describe the broadcaster of this callback
623 @throw ::com::sun::star::uno::RuntimeException
624 if the broadcaster doesn't represent the expected window reference.
627 void SAL_CALL BackingComp::disposing( /*IN*/ const css::lang::EventObject& aEvent )
628 throw(css::uno::RuntimeException)
630 // Attention: dont free m_pAccExec here! see comments inside dtor and
631 // keyPressed() for further details.
633 /* SAFE { */
634 WriteGuard aWriteLock(m_aLock);
636 if (!aEvent.Source.is() || aEvent.Source!=m_xWindow || !m_xWindow.is())
637 throw css::uno::RuntimeException(
638 OUString("unexpected source or called twice"),
639 static_cast< ::cppu::OWeakObject* >(this));
641 m_xWindow = css::uno::Reference< css::awt::XWindow >();
643 aWriteLock.unlock();
644 /* } SAFE */
647 //_______________________________________________
649 /** kill this instance.
651 It can be called from our owner frame only. But there is no possibility to check the calli.
652 We have to release all our internal used resources and die. From this point we can throw
653 DisposedExceptions for every further interface request ... but current implementation doesn`t do so ...
657 void SAL_CALL BackingComp::dispose()
658 throw(css::uno::RuntimeException)
660 /* SAFE { */
661 WriteGuard aWriteLock(m_aLock);
663 // kill the menu
664 css::util::URL aURL;
665 aURL.Complete = DECLARE_ASCII(".uno:close");
666 css::uno::Reference< css::util::XURLTransformer > xParser(css::util::URLTransformer::create(::comphelper::getComponentContext(m_xSMGR)));
667 if (xParser.is())
668 xParser->parseStrict(aURL);
670 css::uno::Reference< css::frame::XDispatchProvider > xProvider(m_xFrame, css::uno::UNO_QUERY);
671 if (xProvider.is())
673 css::uno::Reference< css::frame::XDispatch > xDispatch = xProvider->queryDispatch(aURL, SPECIALTARGET_MENUBAR, 0);
674 if (xDispatch.is())
675 xDispatch->dispatch(aURL, css::uno::Sequence< css::beans::PropertyValue>());
678 // deregister drag&drop helper
679 if (m_xDropTargetListener.is())
681 css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create( comphelper::getComponentContext(m_xSMGR) );
682 css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xToolkit->getDropTarget(m_xWindow);
683 if (xDropTarget.is())
685 xDropTarget->removeDropTargetListener(m_xDropTargetListener);
686 xDropTarget->setActive(sal_False);
688 m_xDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >();
691 // stop listening at the window
692 if (m_xWindow.is())
694 css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
695 if (xBroadcaster.is())
697 css::uno::Reference< css::lang::XEventListener > xEventThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
698 xBroadcaster->removeEventListener(xEventThis);
700 css::uno::Reference< css::awt::XKeyListener > xKeyThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
701 m_xWindow->removeKeyListener(xKeyThis);
702 m_xWindow = css::uno::Reference< css::awt::XWindow >();
705 // forget all other used references
706 m_xFrame = css::uno::Reference< css::frame::XFrame >();
707 m_xSMGR = css::uno::Reference< css::lang::XMultiServiceFactory >();
709 aWriteLock.unlock();
710 /* } SAFE */
713 //_______________________________________________
715 /** not supported.
717 @param xListener
718 not used.
720 @throw ::com::sun::star::uno::RuntimeException
721 because the listener expect to be holded alive by this container.
722 We must inform it about this unsupported feature.
725 void SAL_CALL BackingComp::addEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
726 throw(css::uno::RuntimeException)
728 throw css::uno::RuntimeException(
729 OUString("not supported"),
730 static_cast< ::cppu::OWeakObject* >(this));
733 //_______________________________________________
735 /** not supported.
737 Because registration is not supported too, we must do nothing here. Nobody can call this method realy.
739 @param xListener
740 not used.
743 void SAL_CALL BackingComp::removeEventListener( /*IN*/ const css::uno::Reference< css::lang::XEventListener >& )
744 throw(css::uno::RuntimeException)
748 //_______________________________________________
751 force initialiation for this component.
753 Inside attachFrame() we created our component window. But it was not allowed there, to
754 initialitze it. E.g. the menu must be set at the container window of the frame, which
755 is our parent window. But may at that time another component used it.
756 That's why our creator has to inform us, when it's time to initialize us realy.
757 Currently only calling of this method must be done. But further implementatoins
758 can use special in parameter to configure this initialization ...
760 @param lArgs
761 currently not used
763 @throw com::sun::star::uno::RuntimeException
764 if some resources are missing
765 Means if may be attachedFrame() wasn't called before.
768 void SAL_CALL BackingComp::initialize( /*IN*/ const css::uno::Sequence< css::uno::Any >& lArgs )
769 throw(css::uno::Exception, css::uno::RuntimeException)
771 /* SAFE { */
772 WriteGuard aWriteLock(m_aLock);
774 if (m_xWindow.is())
775 throw css::uno::Exception(
776 OUString("already initialized"),
777 static_cast< ::cppu::OWeakObject* >(this));
779 css::uno::Reference< css::awt::XWindow > xParentWindow;
780 if (
781 (lArgs.getLength()!=1 ) ||
782 (!(lArgs[0] >>= xParentWindow)) ||
783 (!xParentWindow.is() )
786 throw css::uno::Exception(
787 OUString("wrong or corrupt argument list"),
788 static_cast< ::cppu::OWeakObject* >(this));
791 // create the component window
792 Window* pParent = VCLUnoHelper::GetWindow(xParentWindow);
793 Window* pWindow = new BackingWindow(pParent);
794 m_xWindow = VCLUnoHelper::GetInterface(pWindow);
796 if (!m_xWindow.is())
797 throw css::uno::RuntimeException(
798 OUString("couldn't create component window"),
799 static_cast< ::cppu::OWeakObject* >(this));
801 // start listening for window disposing
802 // It's set at our owner frame as component window later too. So it will may be disposed there ...
803 css::uno::Reference< css::lang::XComponent > xBroadcaster(m_xWindow, css::uno::UNO_QUERY);
804 if (xBroadcaster.is())
805 xBroadcaster->addEventListener(static_cast< css::lang::XEventListener* >(this));
807 m_xWindow->setVisible(sal_True);
809 aWriteLock.unlock();
810 /* } SAFE */
813 //_______________________________________________
818 void SAL_CALL BackingComp::keyPressed( /*IN*/ const css::awt::KeyEvent& )
819 throw(css::uno::RuntimeException)
823 //_______________________________________________
828 void SAL_CALL BackingComp::keyReleased( /*IN*/ const css::awt::KeyEvent& )
829 throw(css::uno::RuntimeException)
831 /* Attention
832 Please use keyPressed() instead of this method. Otherwhise it would be possible, that
833 - a key input may be first switch to the backing mode
834 - and this component register itself as key listener too
835 - and it's first event will be a keyRealeased() for the already well known event, which switched to the backing mode!
836 So it will be handled twice! document => backing mode => exit app ...
840 } // namespace framework
842 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */