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
)
77 // Don't use mutex or guard in this method!!! Is a method of XInterface.
79 Reference
< XInterface
> xDel
= BaseControl::impl_getDelegator();
82 // If a delegator exists, forward question to its queryInterface.
83 // Delegator will ask its own queryAggregation!
84 aReturn
= xDel
->queryInterface( rType
);
88 // If a delegator is unknown, forward question to own queryAggregation.
89 aReturn
= queryAggregation( rType
);
97 void SAL_CALL
FrameControl::acquire() throw()
100 // Don't use mutex or guard in this method!!! Is a method of XInterface.
102 // Forward to baseclass
103 BaseControl::acquire();
108 void SAL_CALL
FrameControl::release() throw()
111 // Don't use mutex or guard in this method!!! Is a method of XInterface.
113 // Forward to baseclass
114 BaseControl::release();
119 Sequence
< Type
> SAL_CALL
FrameControl::getTypes()
121 static OTypeCollection
ourTypeCollection(
122 cppu::UnoType
<XControlModel
>::get(),
123 cppu::UnoType
<XControlContainer
>::get(),
124 cppu::UnoType
<XConnectionPointContainer
>::get(),
125 BaseControl::getTypes() );
127 return ourTypeCollection
.getTypes();
132 Any SAL_CALL
FrameControl::queryAggregation( const Type
& aType
)
134 // Ask for my own supported interfaces ...
135 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
136 Any
aReturn ( ::cppu::queryInterface( aType
,
137 static_cast< XControlModel
* > ( this ) ,
138 static_cast< XConnectionPointContainer
* > ( this )
142 // If searched interface not supported by this class ...
143 if ( !aReturn
.hasValue() )
145 // ... ask baseclasses.
146 aReturn
= OPropertySetHelper::queryInterface( aType
);
147 if ( !aReturn
.hasValue() )
149 aReturn
= BaseControl::queryAggregation( aType
);
156 OUString
FrameControl::getImplementationName()
158 return "stardiv.UnoControls.FrameControl";
161 css::uno::Sequence
<OUString
> FrameControl::getSupportedServiceNames()
163 return { "com.sun.star.frame.FrameControl" };
168 void SAL_CALL
FrameControl::createPeer( const Reference
< XToolkit
>& xToolkit
,
169 const Reference
< XWindowPeer
>& xParentPeer
)
171 BaseControl::createPeer( xToolkit
, xParentPeer
);
172 if ( impl_getPeerWindow().is() )
174 if( !m_sComponentURL
.isEmpty() )
176 impl_createFrame( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
183 sal_Bool SAL_CALL
FrameControl::setModel( const Reference
< XControlModel
>& /*xModel*/ )
191 Reference
< XControlModel
> SAL_CALL
FrameControl::getModel()
194 return Reference
< XControlModel
>();
199 void SAL_CALL
FrameControl::dispose()
202 BaseControl::dispose();
207 sal_Bool SAL_CALL
FrameControl::setGraphics( const Reference
< XGraphics
>& /*xDevice*/ )
209 // it is not possible to print this control
215 Reference
< XGraphics
> SAL_CALL
FrameControl::getGraphics()
217 // when it's not possible to set graphics ! then it's possible to return null
218 return Reference
< XGraphics
>();
221 // XConnectionPointContainer
223 Sequence
< Type
> SAL_CALL
FrameControl::getConnectionPointTypes()
225 // Forwarded to helper class
226 return m_aConnectionPointContainer
->getConnectionPointTypes();
229 // XConnectionPointContainer
231 Reference
< XConnectionPoint
> SAL_CALL
FrameControl::queryConnectionPoint( const Type
& aType
)
233 // Forwarded to helper class
234 return m_aConnectionPointContainer
->queryConnectionPoint( aType
);
237 // XConnectionPointContainer
239 void SAL_CALL
FrameControl::advise( const Type
& aType
,
240 const Reference
< XInterface
>& xListener
)
242 // Forwarded to helper class
243 m_aConnectionPointContainer
->advise( aType
, xListener
);
246 // XConnectionPointContainer
248 void SAL_CALL
FrameControl::unadvise( const Type
& aType
,
249 const Reference
< XInterface
>& xListener
)
251 // Forwarded to helper class
252 m_aConnectionPointContainer
->unadvise( aType
, xListener
);
255 // OPropertySetHelper
257 sal_Bool
FrameControl::convertFastPropertyValue( Any
& rConvertedValue
,
262 bool bReturn
= false;
265 case PropertyHandle::Componenturl
: rConvertedValue
= rValue
;
266 rOldValue
<<= m_sComponentURL
;
270 case PropertyHandle::Loaderarguments
: rConvertedValue
= rValue
;
271 rOldValue
<<= m_seqLoaderArguments
;
278 throw IllegalArgumentException();
284 // OPropertySetHelper
286 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
289 // this method only set the value
290 MutexGuard
aGuard (m_aMutex
);
293 case PropertyHandle::Componenturl
: rValue
>>= m_sComponentURL
;
296 impl_createFrame ( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
300 case PropertyHandle::Loaderarguments
: rValue
>>= m_seqLoaderArguments
;
303 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
307 // OPropertySetHelper
309 void FrameControl::getFastPropertyValue( Any
& rRet
,
310 sal_Int32 nHandle
) const
312 MutexGuard
aGuard ( Mutex::getGlobalMutex() );
316 case PropertyHandle::Componenturl
: rRet
<<= m_sComponentURL
;
319 case PropertyHandle::Loaderarguments
: rRet
<<= m_seqLoaderArguments
;
322 case PropertyHandle::Frame
: rRet
<<= m_xFrame
;
325 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
329 // OPropertySetHelper
331 IPropertyArrayHelper
& FrameControl::getInfoHelper()
333 // Create a table that map names to index values.
334 // attention: properties need to be sorted by name!
335 static OPropertyArrayHelper
ourPropertyInfo(
337 Property( "ComponentUrl", PropertyHandle::Componenturl
, cppu::UnoType
<OUString
>::get(),
338 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
),
339 Property( "Frame", PropertyHandle::Frame
, cppu::UnoType
<XFrame
>::get(),
340 PropertyAttribute::BOUND
| PropertyAttribute::TRANSIENT
),
341 Property( "LoaderArguments", PropertyHandle::Loaderarguments
, cppu::UnoType
<Sequence
<PropertyValue
>>::get(),
342 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
)
346 return ourPropertyInfo
;
349 // OPropertySetHelper
351 Reference
< XPropertySetInfo
> SAL_CALL
FrameControl::getPropertySetInfo()
353 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
354 // (Use method "getInfoHelper()".)
355 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
362 WindowDescriptor
FrameControl::impl_getWindowDescriptor( const Reference
< XWindowPeer
>& xParentPeer
)
364 WindowDescriptor aDescriptor
;
366 aDescriptor
.Type
= WindowClass_CONTAINER
;
367 aDescriptor
.ParentIndex
= -1;
368 aDescriptor
.Parent
= xParentPeer
;
369 aDescriptor
.Bounds
= getPosSize ();
370 aDescriptor
.WindowAttributes
= 0;
377 void FrameControl::impl_createFrame( const Reference
< XWindowPeer
>& xPeer
,
378 const OUString
& rURL
,
379 const Sequence
< PropertyValue
>& rArguments
)
381 Reference
< XFrame2
> xOldFrame
;
382 Reference
< XFrame2
> xNewFrame
;
385 MutexGuard
aGuard ( m_aMutex
);
386 xOldFrame
= m_xFrame
;
389 xNewFrame
= Frame::create( impl_getComponentContext() );
391 Reference
< XWindow
> xWP ( xPeer
, UNO_QUERY
);
392 xNewFrame
->initialize ( xWP
);
395 //xFrame->setName( "WhatYouWant" );
397 Reference
< XURLTransformer
> xTrans
= URLTransformer::create( impl_getComponentContext() );
400 aURL
.Complete
= rURL
;
401 xTrans
->parseStrict( aURL
);
403 Reference
< XDispatch
> xDisp
= xNewFrame
->queryDispatch ( aURL
, OUString (), FrameSearchFlag::SELF
);
406 xDisp
->dispatch ( aURL
, rArguments
);
411 MutexGuard
aGuard ( m_aMutex
);
412 m_xFrame
= xNewFrame
;
415 // notify the listeners
416 sal_Int32 nFrameId
= PropertyHandle::Frame
;
417 Any
aNewFrame ( &xNewFrame
, cppu::UnoType
<XFrame
>::get());
418 Any
aOldFrame ( &xOldFrame
, cppu::UnoType
<XFrame
>::get());
420 fire ( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
424 xOldFrame
->dispose ();
430 void FrameControl::impl_deleteFrame()
432 Reference
< XFrame2
> xOldFrame
;
433 Reference
< XFrame2
> xNullFrame
;
436 // do not dispose the frame in this guarded section (deadlock?)
437 MutexGuard
aGuard( m_aMutex
);
438 xOldFrame
= m_xFrame
;
442 // notify the listeners
443 sal_Int32 nFrameId
= PropertyHandle::Frame
;
444 Any
aNewFrame( &xNullFrame
, cppu::UnoType
<XFrame2
>::get());
445 Any
aOldFrame( &xOldFrame
, cppu::UnoType
<XFrame2
>::get());
446 fire( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
450 xOldFrame
->dispose();
454 } // namespace unocontrols
456 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
457 stardiv_UnoControls_FrameControl_get_implementation(
458 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
460 return cppu::acquire(new unocontrols::FrameControl(context
));
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */