1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "backingwindow.hxx"
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/util/XURLTransformer.hpp>
26 #include <com/sun/star/frame/XDispatchProvider.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/awt/Toolkit.hpp>
29 #include <com/sun/star/awt/XDataTransferProviderAccess.hpp>
30 #include <com/sun/star/awt/KeyEvent.hpp>
31 #include <com/sun/star/awt/KeyModifier.hpp>
32 #include <com/sun/star/frame/XLayoutManager.hpp>
33 #include <com/sun/star/util/URLTransformer.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/awt/XWindow.hpp>
37 #include <com/sun/star/awt/XKeyListener.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/frame/XFrame.hpp>
40 #include <com/sun/star/frame/XDispatch.hpp>
41 #include <com/sun/star/lang/XEventListener.hpp>
42 #include <com/sun/star/lang/XComponent.hpp>
44 #include <cppuhelper/supportsservice.hxx>
45 #include <cppuhelper/queryinterface.hxx>
46 #include <cppuhelper/typeprovider.hxx>
47 #include <toolkit/helper/vclunohelper.hxx>
48 #include <vcl/keycod.hxx>
49 #include <vcl/wrkwin.hxx>
50 #include <vcl/svapp.hxx>
51 #include <rtl/ref.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>
64 const char FRAME_PROPNAME_LAYOUTMANAGER
[] = "LayoutManager";
65 const char HID_BACKINGWINDOW
[] = "FWK_HID_BACKINGWINDOW";
66 const char SPECIALTARGET_MENUBAR
[] = "_menubar";
69 implements the backing component.
71 This component is a special one, which doesn't provide a controller
72 nor a model. It supports the following features:
79 class BackingComp
: public css::lang::XTypeProvider
80 , public css::lang::XServiceInfo
81 , public css::lang::XInitialization
82 , public css::frame::XController
// => XComponent
83 , public css::awt::XKeyListener
// => XEventListener
84 , public css::frame::XDispatchProvider
85 , public css::frame::XDispatch
86 , public ::cppu::OWeakObject
89 /** the global uno service manager.
90 Must be used to create own needed services. */
91 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
93 /** reference to the component window. */
94 css::uno::Reference
< css::awt::XWindow
> m_xWindow
;
96 /** the owner frame of this component. */
97 css::uno::Reference
< css::frame::XFrame
> m_xFrame
;
101 BackingComp( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
102 virtual ~BackingComp( );
105 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
106 virtual void SAL_CALL
acquire ( ) throw( ) SAL_OVERRIDE
;
107 virtual void SAL_CALL
release ( ) throw( ) SAL_OVERRIDE
;
110 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes () throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual OUString SAL_CALL
getImplementationName ( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 virtual sal_Bool SAL_CALL
supportsService ( const OUString
& sServiceName
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& lArgs
) throw(css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 virtual void SAL_CALL
attachFrame( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual sal_Bool SAL_CALL
attachModel( const css::uno::Reference
< css::frame::XModel
>& xModel
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 virtual sal_Bool SAL_CALL
suspend( sal_Bool bSuspend
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual css::uno::Any SAL_CALL
getViewData() throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
126 virtual void SAL_CALL
restoreViewData( const css::uno::Any
& aData
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
127 virtual css::uno::Reference
< css::frame::XModel
> SAL_CALL
getModel() throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
128 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getFrame() throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
131 virtual void SAL_CALL
keyPressed ( const css::awt::KeyEvent
& aEvent
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
132 virtual void SAL_CALL
keyReleased( const css::awt::KeyEvent
& aEvent
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
135 virtual void SAL_CALL
disposing( const css::lang::EventObject
& aEvent
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 virtual void SAL_CALL
dispose ( ) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
139 virtual void SAL_CALL
addEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
140 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch( const css::util::URL
& aURL
, const OUString
& sTargetFrameName
, sal_Int32 nSearchFlags
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
144 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& lDescriptions
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
147 virtual void SAL_CALL
dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
148 virtual void SAL_CALL
addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
149 virtual void SAL_CALL
removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
152 BackingComp::BackingComp( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
)
153 : m_xContext(xContext
)
159 BackingComp::~BackingComp()
165 /** return information about supported interfaces.
167 Some interfaces are supported by his class directly, but some other ones are
168 used by aggregation. An instance of this class must provide some window interfaces.
169 But it must represent a VCL window behind such interfaces too! So we use an internal
170 saved window member to ask it for it's interfaces and return it. But we must be aware then,
171 that it can be destroyed from outside too ...
174 describe the required interface type
176 @return An Any holding the instance, which provides the queried interface.
177 Note: There exist two possible results ... this instance itself and her window member!
180 css::uno::Any SAL_CALL
BackingComp::queryInterface( /*IN*/ const css::uno::Type
& aType
)
181 throw(css::uno::RuntimeException
, std::exception
)
183 css::uno::Any aResult
;
185 // first look for own supported interfaces
186 aResult
= ::cppu::queryInterface(
188 static_cast< css::lang::XTypeProvider
* >(this),
189 static_cast< css::lang::XServiceInfo
* >(this),
190 static_cast< css::lang::XInitialization
* >(this),
191 static_cast< css::frame::XController
* >(this),
192 static_cast< css::lang::XComponent
* >(this),
193 static_cast< css::lang::XEventListener
* >(this),
194 static_cast< css::awt::XKeyListener
* >(static_cast< css::lang::XEventListener
* >(this)),
195 static_cast< css::frame::XDispatchProvider
* >(this),
196 static_cast< css::frame::XDispatch
* >(this) );
198 // then look for supported window interfaces
199 // Note: They exist only, if this instance was initialized
200 // with a valid window reference. It's aggregation on demand ...
201 if (!aResult
.hasValue())
204 SolarMutexGuard aGuard
;
206 aResult
= m_xWindow
->queryInterface(aType
);
210 // look for XWeak and XInterface
211 if (!aResult
.hasValue())
212 aResult
= OWeakObject::queryInterface(aType
);
219 /** increase ref count of this instance.
222 void SAL_CALL
BackingComp::acquire()
225 OWeakObject::acquire();
230 /** decrease ref count of this instance.
233 void SAL_CALL
BackingComp::release()
236 OWeakObject::release();
241 /** return collection about all supported interfaces.
243 Optimize this method !
244 We initialize a static variable only one time.
245 And we don't must use a mutex at every call!
246 For the first call; pTypeCollection is NULL -
247 for the second call pTypeCollection is different from NULL!
249 @return A list of all supported interface types.
252 css::uno::Sequence
< css::uno::Type
> SAL_CALL
BackingComp::getTypes()
253 throw(css::uno::RuntimeException
, std::exception
)
255 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
256 if (!pTypeCollection
)
259 ::osl::MutexGuard
aGlobalLock(::osl::Mutex::getGlobalMutex());
260 // Control these pointer again ... it can be, that another instance will be faster then this one!
261 if (!pTypeCollection
)
264 SolarMutexGuard aGuard
;
265 css::uno::Reference
< css::lang::XTypeProvider
> xProvider(m_xWindow
, css::uno::UNO_QUERY
);
267 css::uno::Sequence
< css::uno::Type
> lWindowTypes
;
269 lWindowTypes
= xProvider
->getTypes();
271 static ::cppu::OTypeCollection
aTypeCollection(
272 cppu::UnoType
<css::lang::XInitialization
>::get(),
273 cppu::UnoType
<css::lang::XTypeProvider
>::get(),
274 cppu::UnoType
<css::lang::XServiceInfo
>::get(),
275 cppu::UnoType
<css::frame::XController
>::get(),
276 cppu::UnoType
<css::lang::XComponent
>::get(),
277 cppu::UnoType
<css::frame::XDispatchProvider
>::get(),
278 cppu::UnoType
<css::frame::XDispatch
>::get(),
281 pTypeCollection
= &aTypeCollection
;
286 return pTypeCollection
->getTypes();
291 /** create one unique Id for all instances of this class.
294 We initialize a static variable only one time. And we don't must use a mutex at every call!
295 For the first call; pID is NULL - for the second call pID is different from NULL!
297 @return A byte array, which represent the unique id.
300 css::uno::Sequence
< sal_Int8
> SAL_CALL
BackingComp::getImplementationId()
301 throw(css::uno::RuntimeException
, std::exception
)
303 return css::uno::Sequence
<sal_Int8
>();
306 OUString SAL_CALL
BackingComp::getImplementationName()
307 throw(css::uno::RuntimeException
, std::exception
)
309 return OUString("com.sun.star.comp.sfx2.BackingComp");
312 sal_Bool SAL_CALL
BackingComp::supportsService( /*IN*/ const OUString
& sServiceName
)
313 throw(css::uno::RuntimeException
, std::exception
)
315 return cppu::supportsService(this, sServiceName
);
318 css::uno::Sequence
< OUString
> SAL_CALL
BackingComp::getSupportedServiceNames()
319 throw(css::uno::RuntimeException
, std::exception
)
321 css::uno::Sequence
< OUString
> lNames(2);
322 lNames
[0] = "com.sun.star.frame.StartModule";
323 lNames
[1] = "com.sun.star.frame.ProtocolHandler";
329 attach this component to a target frame.
331 We have to use the container window of this frame as parent window of our own component window.
332 But it's not allowed to work with it really. May another component used it too.
333 Currently we need it only to create our child component window and support it's
334 interfaces inside our queryInterface() method. The user of us must have e.g. the
335 XWindow interface of it to be able to call setComponent(xWindow,xController) at the
338 May he will do the following things:
341 XController xBackingComp = (XController)UnoRuntime.queryInterface(
343 xSMGR.createInstance(SERVICENAME_STARTMODULE));
345 // at this time XWindow isn't present at this instance!
346 XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
350 // attach controller to the frame
351 // We will use it's container window, to create
352 // the component window. From now we offer the window interfaces!
353 xBackingComp.attachFrame(xFrame);
355 XWindow xBackingComp = (XWindow)UnoRuntime.queryInterface(
359 // Our user can set us at the frame as new component
360 xFrame.setComponent(xBackingWin, xBackingComp);
362 // But that had no effect to our view state.
363 // We must be started to create our UI elements like e.g. menu, title, background ...
364 XInitialization xBackingInit = (XInitialization)UnoRuntime.queryInterface(
365 XInitialization.class,
368 xBackingInit.initialize(lArgs);
372 reference to our new target frame
374 @throw com::sun::star::uno::RuntimeException
375 if the given frame reference is wrong or component window couldn't be created
377 We throw it too, if we already attached to a frame. Because we don't support
378 reparenting of our component window on demand!
381 void SAL_CALL
BackingComp::attachFrame( /*IN*/ const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
382 throw (css::uno::RuntimeException
, std::exception
)
385 SolarMutexGuard aGuard
;
387 // check some required states
389 throw css::uno::RuntimeException(
390 OUString("already attached"),
391 static_cast< ::cppu::OWeakObject
* >(this));
394 throw css::uno::RuntimeException(
395 OUString("invalid frame reference"),
396 static_cast< ::cppu::OWeakObject
* >(this));
401 // safe the frame reference
404 // initialize the component and its parent window
405 css::uno::Reference
< css::awt::XWindow
> xParentWindow
= xFrame
->getContainerWindow();
406 VclPtr
< WorkWindow
> pParent
= static_cast<WorkWindow
*>(VCLUnoHelper::GetWindow(xParentWindow
).get());
407 VclPtr
< vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(m_xWindow
);
409 // disable full screen mode of the frame!
410 if (pParent
&& pParent
->IsFullScreenMode())
412 pParent
->ShowFullScreenMode(false);
413 pParent
->SetMenuBarMode(MENUBAR_MODE_NORMAL
);
416 // create the menu bar for the backing component
417 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY_THROW
);
418 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
419 xPropSet
->getPropertyValue(FRAME_PROPNAME_LAYOUTMANAGER
) >>= xLayoutManager
;
420 if (xLayoutManager
.is())
422 xLayoutManager
->lock();
423 xLayoutManager
->createElement("private:resource/menubar/menubar");
424 xLayoutManager
->unlock();
429 // set help ID for our canvas
430 pWindow
->SetHelpId(HID_BACKINGWINDOW
);
433 // inform BackingWindow about frame
434 BackingWindow
* pBack
= dynamic_cast<BackingWindow
*>(pWindow
.get());
436 pBack
->setOwningFrame( m_xFrame
);
438 // Set a minimum size for Start Center
439 if( pParent
&& pBack
)
441 long nMenuHeight
= 0;
442 vcl::Window
* pMenu
= pParent
->GetWindow(GetWindowType::Next
);
444 nMenuHeight
= pMenu
->GetSizePixel().Height();
446 pParent
->SetMinOutputSizePixel(
448 pBack
->get_width_request(),
449 pBack
->get_height_request() + nMenuHeight
));
459 This component does not know any model. It will be represented by a window and
462 return <FALSE/> every time.
465 sal_Bool SAL_CALL
BackingComp::attachModel( /*IN*/ const css::uno::Reference
< css::frame::XModel
>& )
466 throw (css::uno::RuntimeException
, std::exception
)
475 This component does not know any model. It will be represented by a window and
478 return An empty reference every time.
481 css::uno::Reference
< css::frame::XModel
> SAL_CALL
BackingComp::getModel()
482 throw (css::uno::RuntimeException
, std::exception
)
484 return css::uno::Reference
< css::frame::XModel
>();
491 return An empty value.
494 css::uno::Any SAL_CALL
BackingComp::getViewData()
495 throw (css::uno::RuntimeException
, std::exception
)
497 return css::uno::Any();
508 void SAL_CALL
BackingComp::restoreViewData( /*IN*/ const css::uno::Any
& )
509 throw (css::uno::RuntimeException
, std::exception
)
515 /** returns the attached frame for this component.
519 @return The internally saved frame reference.
520 Can be null, if attachFrame() was not called before.
523 css::uno::Reference
< css::frame::XFrame
> SAL_CALL
BackingComp::getFrame()
524 throw (css::uno::RuntimeException
, std::exception
)
527 SolarMutexGuard aGuard
;
534 /** ask controller for its current working state.
536 If someone wishes to close this component, it must suspend the controller before.
537 That will be a chance for it to disagree with that AND show any UI for a possible
541 If it's set to sal_True this controller should be suspended.
542 sal_False will resuspend it.
544 @return sal_True if the request could be finished successfully; sal_False otherwise.
547 sal_Bool SAL_CALL
BackingComp::suspend( /*IN*/ sal_Bool
)
548 throw (css::uno::RuntimeException
, std::exception
)
550 /* FIXME ... implemented by using default :-( */
556 /** callback from our window member.
558 Our internal saved window wish to die. It will be disposed from outside (may be the frame)
559 and inform us. We must release its reference only here. Of course we check the given reference
560 here and reject callback from unknown sources.
562 Note: deregistration as listener isn't necessary here. The broadcaster do it automatically.
565 describe the broadcaster of this callback
567 @throw ::com::sun::star::uno::RuntimeException
568 if the broadcaster doesn't represent the expected window reference.
571 void SAL_CALL
BackingComp::disposing( /*IN*/ const css::lang::EventObject
& aEvent
)
572 throw(css::uno::RuntimeException
, std::exception
)
574 // Attention: dont free m_pAccExec here! see comments inside dtor and
575 // keyPressed() for further details.
578 SolarMutexGuard aGuard
;
580 if (!aEvent
.Source
.is() || aEvent
.Source
!=m_xWindow
|| !m_xWindow
.is())
581 throw css::uno::RuntimeException(
582 OUString("unexpected source or called twice"),
583 static_cast< ::cppu::OWeakObject
* >(this));
585 m_xWindow
= css::uno::Reference
< css::awt::XWindow
>();
592 /** kill this instance.
594 It can be called from our owner frame only. But there is no possibility to check the calli.
595 We have to release all our internal used resources and die. From this point we can throw
596 DisposedExceptions for every further interface request ... but current implementation doesn`t do so ...
600 void SAL_CALL
BackingComp::dispose()
601 throw(css::uno::RuntimeException
, std::exception
)
604 SolarMutexGuard aGuard
;
608 aURL
.Complete
= ".uno:close";
609 css::uno::Reference
< css::util::XURLTransformer
> xParser
= css::util::URLTransformer::create(m_xContext
);
611 xParser
->parseStrict(aURL
);
613 css::uno::Reference
< css::frame::XDispatchProvider
> xProvider(m_xFrame
, css::uno::UNO_QUERY
);
616 css::uno::Reference
< css::frame::XDispatch
> xDispatch
= xProvider
->queryDispatch(aURL
, SPECIALTARGET_MENUBAR
, 0);
618 xDispatch
->dispatch(aURL
, css::uno::Sequence
< css::beans::PropertyValue
>());
621 // stop listening at the window
624 css::uno::Reference
< css::lang::XComponent
> xBroadcaster(m_xWindow
, css::uno::UNO_QUERY
);
625 if (xBroadcaster
.is())
627 css::uno::Reference
< css::lang::XEventListener
> xEventThis(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
628 xBroadcaster
->removeEventListener(xEventThis
);
630 css::uno::Reference
< css::awt::XKeyListener
> xKeyThis(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
631 m_xWindow
->removeKeyListener(xKeyThis
);
632 m_xWindow
= css::uno::Reference
< css::awt::XWindow
>();
635 // forget all other used references
649 @throw ::com::sun::star::uno::RuntimeException
650 because the listener expect to be holded alive by this container.
651 We must inform it about this unsupported feature.
654 void SAL_CALL
BackingComp::addEventListener( /*IN*/ const css::uno::Reference
< css::lang::XEventListener
>& )
655 throw(css::uno::RuntimeException
, std::exception
)
657 throw css::uno::RuntimeException(
658 OUString("not supported"),
659 static_cast< ::cppu::OWeakObject
* >(this));
666 Because registration is not supported too, we must do nothing here. Nobody can call this method really.
672 void SAL_CALL
BackingComp::removeEventListener( /*IN*/ const css::uno::Reference
< css::lang::XEventListener
>& )
673 throw(css::uno::RuntimeException
, std::exception
)
680 force initialiation for this component.
682 Inside attachFrame() we created our component window. But it was not allowed there, to
683 initialitze it. E.g. the menu must be set at the container window of the frame, which
684 is our parent window. But may at that time another component used it.
685 That's why our creator has to inform us, when it's time to initialize us really.
686 Currently only calling of this method must be done. But further implementatoins
687 can use special in parameter to configure this initialization ...
692 @throw com::sun::star::uno::RuntimeException
693 if some resources are missing
694 Means if may be attachedFrame() wasn't called before.
697 void SAL_CALL
BackingComp::initialize( /*IN*/ const css::uno::Sequence
< css::uno::Any
>& lArgs
)
698 throw(css::uno::Exception
, css::uno::RuntimeException
, std::exception
)
701 SolarMutexGuard aGuard
;
704 throw css::uno::Exception(
705 OUString("already initialized"),
706 static_cast< ::cppu::OWeakObject
* >(this));
708 css::uno::Reference
< css::awt::XWindow
> xParentWindow
;
710 (lArgs
.getLength()!=1 ) ||
711 (!(lArgs
[0] >>= xParentWindow
)) ||
712 (!xParentWindow
.is() )
715 throw css::uno::Exception(
716 OUString("wrong or corrupt argument list"),
717 static_cast< ::cppu::OWeakObject
* >(this));
720 // create the component window
721 vcl::Window
* pParent
= VCLUnoHelper::GetWindow(xParentWindow
);
722 VclPtr
<vcl::Window
> pWindow
= VclPtr
<BackingWindow
>::Create(pParent
);
723 m_xWindow
= VCLUnoHelper::GetInterface(pWindow
);
726 throw css::uno::RuntimeException(
727 OUString("couldn't create component window"),
728 static_cast< ::cppu::OWeakObject
* >(this));
730 // start listening for window disposing
731 // It's set at our owner frame as component window later too. So it will may be disposed there ...
732 css::uno::Reference
< css::lang::XComponent
> xBroadcaster(m_xWindow
, css::uno::UNO_QUERY
);
733 if (xBroadcaster
.is())
734 xBroadcaster
->addEventListener(static_cast< css::lang::XEventListener
* >(this));
736 m_xWindow
->setVisible(sal_True
);
746 void SAL_CALL
BackingComp::keyPressed( /*IN*/ const css::awt::KeyEvent
& )
747 throw(css::uno::RuntimeException
, std::exception
)
756 void SAL_CALL
BackingComp::keyReleased( /*IN*/ const css::awt::KeyEvent
& )
757 throw(css::uno::RuntimeException
, std::exception
)
760 Please use keyPressed() instead of this method. Otherwhise it would be possible, that
761 - a key input may be first switch to the backing mode
762 - and this component register itself as key listener too
763 - and it's first event will be a keyRealeased() for the already well known event, which switched to the backing mode!
764 So it will be handled twice! document => backing mode => exit app ...
769 css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
BackingComp::queryDispatch( const css::util::URL
& aURL
, const OUString
& /*sTargetFrameName*/, sal_Int32
/*nSearchFlags*/ ) throw( css::uno::RuntimeException
, std::exception
)
771 css::uno::Reference
< css::frame::XDispatch
> xDispatch
;
772 if ( aURL
.Protocol
== "vnd.org.libreoffice.recentdocs:" )
778 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
BackingComp::queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& seqDescripts
) throw( css::uno::RuntimeException
, std::exception
)
780 sal_Int32 nCount
= seqDescripts
.getLength();
781 css::uno::Sequence
< css::uno::Reference
< XDispatch
> > lDispatcher( nCount
);
783 for( sal_Int32 i
=0; i
<nCount
; ++i
)
784 lDispatcher
[i
] = queryDispatch( seqDescripts
[i
].FeatureURL
, seqDescripts
[i
].FrameName
, seqDescripts
[i
].SearchFlags
);
790 void SAL_CALL
BackingComp::dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& /*lArgs*/ ) throw( css::uno::RuntimeException
, std::exception
)
792 // vnd.org.libreoffice.recentdocs:ClearRecentFileList - clear recent files
793 if ( aURL
.Path
== "ClearRecentFileList" )
795 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow(m_xWindow
);
796 BackingWindow
* pBack
= dynamic_cast<BackingWindow
*>(pWindow
);
799 pBack
->clearRecentFileList();
801 // Recalculate minimum width
802 css::uno::Reference
< css::awt::XWindow
> xParentWindow
= m_xFrame
->getContainerWindow();
803 VclPtr
< WorkWindow
> pParent
= static_cast<WorkWindow
*>(VCLUnoHelper::GetWindow(xParentWindow
).get());
806 pParent
->SetMinOutputSizePixel( Size(
807 pBack
->get_width_request(),
808 pParent
->GetMinOutputSizePixel().Height()) );
814 void SAL_CALL
BackingComp::addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ ) throw ( css::uno::RuntimeException
, std::exception
)
818 void SAL_CALL
BackingComp::removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ ) throw ( css::uno::RuntimeException
, std::exception
)
824 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
825 com_sun_star_comp_sfx2_BackingComp_get_implementation(
826 css::uno::XComponentContext
*context
,
827 css::uno::Sequence
<css::uno::Any
> const &)
829 return cppu::acquire(new BackingComp(context
));
832 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */