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 <framecontrol.hxx>
21 #include <OConnectionPointContainerHelper.hxx>
23 #include <com/sun/star/awt/XControlContainer.hpp>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/frame/Frame.hpp>
26 #include <com/sun/star/frame/FrameSearchFlag.hpp>
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/util/URLTransformer.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <cppuhelper/queryinterface.hxx>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <osl/diagnose.h>
36 using namespace ::osl
;
37 using namespace ::cppu
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::awt
;
42 using namespace ::com::sun::star::frame
;
43 using namespace ::com::sun::star::util
;
45 namespace unocontrols
{
49 enum PropertyHandle
// values represent index in PropertyArray
60 FrameControl::FrameControl( const Reference
< XComponentContext
>& rxContext
)
61 : BaseControl ( rxContext
)
62 , OBroadcastHelper ( m_aMutex
)
63 , OPropertySetHelper ( *static_cast< OBroadcastHelper
* >(this) )
64 , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex
) )
68 FrameControl::~FrameControl()
74 Any SAL_CALL
FrameControl::queryInterface( const Type
& rType
)
76 // Ask for my own supported interfaces ...
77 // Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
78 Any
aReturn ( ::cppu::queryInterface( rType
,
79 static_cast< XControlModel
* > ( this ) ,
80 static_cast< XConnectionPointContainer
* > ( this )
84 // If searched interface not supported by this class ...
85 if ( !aReturn
.hasValue() )
87 // ... ask baseclasses.
88 aReturn
= OPropertySetHelper::queryInterface( rType
);
89 if ( !aReturn
.hasValue() )
91 aReturn
= BaseControl::queryInterface( rType
);
100 void SAL_CALL
FrameControl::acquire() noexcept
103 // Don't use mutex or guard in this method!!! Is a method of XInterface.
105 // Forward to baseclass
106 BaseControl::acquire();
111 void SAL_CALL
FrameControl::release() noexcept
114 // Don't use mutex or guard in this method!!! Is a method of XInterface.
116 // Forward to baseclass
117 BaseControl::release();
122 Sequence
< Type
> SAL_CALL
FrameControl::getTypes()
124 static OTypeCollection
ourTypeCollection(
125 cppu::UnoType
<XControlModel
>::get(),
126 cppu::UnoType
<XControlContainer
>::get(),
127 cppu::UnoType
<XConnectionPointContainer
>::get(),
128 BaseControl::getTypes() );
130 return ourTypeCollection
.getTypes();
133 OUString
FrameControl::getImplementationName()
135 return "stardiv.UnoControls.FrameControl";
138 css::uno::Sequence
<OUString
> FrameControl::getSupportedServiceNames()
140 return { "com.sun.star.frame.FrameControl" };
145 void SAL_CALL
FrameControl::createPeer( const Reference
< XToolkit
>& xToolkit
,
146 const Reference
< XWindowPeer
>& xParentPeer
)
148 BaseControl::createPeer( xToolkit
, xParentPeer
);
149 if ( impl_getPeerWindow().is() )
151 if( !m_sComponentURL
.isEmpty() )
153 impl_createFrame( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
160 sal_Bool SAL_CALL
FrameControl::setModel( const Reference
< XControlModel
>& /*xModel*/ )
168 Reference
< XControlModel
> SAL_CALL
FrameControl::getModel()
171 return Reference
< XControlModel
>();
176 void SAL_CALL
FrameControl::dispose()
179 BaseControl::dispose();
184 sal_Bool SAL_CALL
FrameControl::setGraphics( const Reference
< XGraphics
>& /*xDevice*/ )
186 // it is not possible to print this control
192 Reference
< XGraphics
> SAL_CALL
FrameControl::getGraphics()
194 // when it's not possible to set graphics ! then it's possible to return null
195 return Reference
< XGraphics
>();
198 // XConnectionPointContainer
200 Sequence
< Type
> SAL_CALL
FrameControl::getConnectionPointTypes()
202 // Forwarded to helper class
203 return m_aConnectionPointContainer
->getConnectionPointTypes();
206 // XConnectionPointContainer
208 Reference
< XConnectionPoint
> SAL_CALL
FrameControl::queryConnectionPoint( const Type
& aType
)
210 // Forwarded to helper class
211 return m_aConnectionPointContainer
->queryConnectionPoint( aType
);
214 // XConnectionPointContainer
216 void SAL_CALL
FrameControl::advise( const Type
& aType
,
217 const Reference
< XInterface
>& xListener
)
219 // Forwarded to helper class
220 m_aConnectionPointContainer
->advise( aType
, xListener
);
223 // XConnectionPointContainer
225 void SAL_CALL
FrameControl::unadvise( const Type
& aType
,
226 const Reference
< XInterface
>& xListener
)
228 // Forwarded to helper class
229 m_aConnectionPointContainer
->unadvise( aType
, xListener
);
232 // OPropertySetHelper
234 sal_Bool
FrameControl::convertFastPropertyValue( Any
& rConvertedValue
,
239 bool bReturn
= false;
242 case PropertyHandle::Componenturl
: rConvertedValue
= rValue
;
243 rOldValue
<<= m_sComponentURL
;
247 case PropertyHandle::Loaderarguments
: rConvertedValue
= rValue
;
248 rOldValue
<<= m_seqLoaderArguments
;
255 throw IllegalArgumentException("unknown handle " + OUString::number(nHandle
), getXWeak(), 1);
261 // OPropertySetHelper
263 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
266 // this method only set the value
267 MutexGuard
aGuard (m_aMutex
);
270 case PropertyHandle::Componenturl
: rValue
>>= m_sComponentURL
;
273 impl_createFrame ( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
277 case PropertyHandle::Loaderarguments
: rValue
>>= m_seqLoaderArguments
;
280 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
284 // OPropertySetHelper
286 void FrameControl::getFastPropertyValue( Any
& rRet
,
287 sal_Int32 nHandle
) const
289 MutexGuard
aGuard ( Mutex::getGlobalMutex() );
293 case PropertyHandle::Componenturl
: rRet
<<= m_sComponentURL
;
296 case PropertyHandle::Loaderarguments
: rRet
<<= m_seqLoaderArguments
;
299 case PropertyHandle::Frame
: rRet
<<= m_xFrame
;
302 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
306 // OPropertySetHelper
308 IPropertyArrayHelper
& FrameControl::getInfoHelper()
310 // Create a table that map names to index values.
311 // attention: properties need to be sorted by name!
312 static OPropertyArrayHelper
ourPropertyInfo(
314 Property( "ComponentUrl", PropertyHandle::Componenturl
, cppu::UnoType
<OUString
>::get(),
315 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
),
316 Property( "Frame", PropertyHandle::Frame
, cppu::UnoType
<XFrame
>::get(),
317 PropertyAttribute::BOUND
| PropertyAttribute::TRANSIENT
),
318 Property( "LoaderArguments", PropertyHandle::Loaderarguments
, cppu::UnoType
<Sequence
<PropertyValue
>>::get(),
319 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
)
323 return ourPropertyInfo
;
326 // OPropertySetHelper
328 Reference
< XPropertySetInfo
> SAL_CALL
FrameControl::getPropertySetInfo()
330 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
331 // (Use method "getInfoHelper()".)
332 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
339 WindowDescriptor
FrameControl::impl_getWindowDescriptor( const Reference
< XWindowPeer
>& xParentPeer
)
341 WindowDescriptor aDescriptor
;
343 aDescriptor
.Type
= WindowClass_CONTAINER
;
344 aDescriptor
.ParentIndex
= -1;
345 aDescriptor
.Parent
= xParentPeer
;
346 aDescriptor
.Bounds
= getPosSize ();
347 aDescriptor
.WindowAttributes
= 0;
354 void FrameControl::impl_createFrame( const Reference
< XWindowPeer
>& xPeer
,
355 const OUString
& rURL
,
356 const Sequence
< PropertyValue
>& rArguments
)
358 Reference
< XFrame2
> xOldFrame
;
359 Reference
< XFrame2
> xNewFrame
;
362 MutexGuard
aGuard ( m_aMutex
);
363 xOldFrame
= m_xFrame
;
366 xNewFrame
= Frame::create( impl_getComponentContext() );
368 Reference
< XWindow
> xWP ( xPeer
, UNO_QUERY
);
369 xNewFrame
->initialize ( xWP
);
372 //xFrame->setName( "WhatYouWant" );
374 Reference
< XURLTransformer
> xTrans
= URLTransformer::create( impl_getComponentContext() );
377 aURL
.Complete
= rURL
;
378 xTrans
->parseStrict( aURL
);
380 Reference
< XDispatch
> xDisp
= xNewFrame
->queryDispatch ( aURL
, OUString (), FrameSearchFlag::SELF
);
383 xDisp
->dispatch ( aURL
, rArguments
);
388 MutexGuard
aGuard ( m_aMutex
);
389 m_xFrame
= xNewFrame
;
392 // notify the listeners
393 sal_Int32 nFrameId
= PropertyHandle::Frame
;
394 Any
aNewFrame ( &xNewFrame
, cppu::UnoType
<XFrame
>::get());
395 Any
aOldFrame ( &xOldFrame
, cppu::UnoType
<XFrame
>::get());
397 fire ( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
401 xOldFrame
->dispose ();
407 void FrameControl::impl_deleteFrame()
409 Reference
< XFrame2
> xOldFrame
;
410 Reference
< XFrame2
> xNullFrame
;
413 // do not dispose the frame in this guarded section (deadlock?)
414 MutexGuard
aGuard( m_aMutex
);
415 xOldFrame
= m_xFrame
;
419 // notify the listeners
420 sal_Int32 nFrameId
= PropertyHandle::Frame
;
421 Any
aNewFrame( &xNullFrame
, cppu::UnoType
<XFrame2
>::get());
422 Any
aOldFrame( &xOldFrame
, cppu::UnoType
<XFrame2
>::get());
423 fire( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
427 xOldFrame
->dispose();
431 } // namespace unocontrols
433 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
434 stardiv_UnoControls_FrameControl_get_implementation(
435 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
437 return cppu::acquire(new unocontrols::FrameControl(context
));
439 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */