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 <comphelper/sequence.hxx>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <osl/diagnose.h>
37 using namespace ::osl
;
38 using namespace ::cppu
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::com::sun::star::awt
;
43 using namespace ::com::sun::star::frame
;
44 using namespace ::com::sun::star::util
;
46 namespace unocontrols
{
50 enum PropertyHandle
// values represent index in PropertyArray
61 FrameControl::FrameControl( const Reference
< XComponentContext
>& rxContext
)
62 : FrameControl_BASE ( rxContext
)
63 , OBroadcastHelper ( m_aMutex
)
64 , OPropertySetHelper ( *static_cast< OBroadcastHelper
* >(this) )
65 , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex
) )
69 FrameControl::~FrameControl()
74 Any SAL_CALL
FrameControl::queryInterface( const Type
& rType
)
76 Any aReturn
= OPropertySetHelper::queryInterface(rType
);
77 if (aReturn
.hasValue())
79 return FrameControl_BASE::queryInterface(rType
);
83 void SAL_CALL
FrameControl::acquire() noexcept
86 // Don't use mutex or guard in this method!!! Is a method of XInterface.
88 // Forward to baseclass
89 FrameControl_BASE::acquire();
93 void SAL_CALL
FrameControl::release() noexcept
96 // Don't use mutex or guard in this method!!! Is a method of XInterface.
98 // Forward to baseclass
99 FrameControl_BASE::release();
104 Sequence
< Type
> SAL_CALL
FrameControl::getTypes()
106 static Sequence myTypes
= comphelper::concatSequences(FrameControl_BASE::getTypes(),
107 OPropertySetHelper::getTypes());
111 OUString
FrameControl::getImplementationName()
113 return u
"stardiv.UnoControls.FrameControl"_ustr
;
116 css::uno::Sequence
<OUString
> FrameControl::getSupportedServiceNames()
118 return { u
"com.sun.star.frame.FrameControl"_ustr
};
123 void SAL_CALL
FrameControl::createPeer( const Reference
< XToolkit
>& xToolkit
,
124 const Reference
< XWindowPeer
>& xParentPeer
)
126 BaseControl::createPeer( xToolkit
, xParentPeer
);
127 if ( impl_getPeerWindow().is() )
129 if( !m_sComponentURL
.isEmpty() )
131 impl_createFrame( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
138 sal_Bool SAL_CALL
FrameControl::setModel( const Reference
< XControlModel
>& /*xModel*/ )
146 Reference
< XControlModel
> SAL_CALL
FrameControl::getModel()
149 return Reference
< XControlModel
>();
154 void SAL_CALL
FrameControl::dispose()
156 Reference
< XFrame2
> xOldFrame
;
158 // do not dispose the frame in this guarded section (deadlock?)
159 MutexGuard
aGuard( m_aMutex
);
160 xOldFrame
= std::move(m_xFrame
);
163 // notify the listeners
164 sal_Int32 nFrameId
= PropertyHandle::Frame
;
165 Reference
< XFrame2
> xNullFrame
;
166 Any
aNewFrame( &xNullFrame
, cppu::UnoType
<XFrame2
>::get());
167 Any
aOldFrame( &xOldFrame
, cppu::UnoType
<XFrame2
>::get());
168 fire( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
172 xOldFrame
->dispose();
174 m_aConnectionPointContainer
.clear();
175 BaseControl::dispose();
180 sal_Bool SAL_CALL
FrameControl::setGraphics( const Reference
< XGraphics
>& /*xDevice*/ )
182 // it is not possible to print this control
188 Reference
< XGraphics
> SAL_CALL
FrameControl::getGraphics()
190 // when it's not possible to set graphics ! then it's possible to return null
191 return Reference
< XGraphics
>();
194 // XConnectionPointContainer
196 Sequence
< Type
> SAL_CALL
FrameControl::getConnectionPointTypes()
198 // Forwarded to helper class
199 return m_aConnectionPointContainer
->getConnectionPointTypes();
202 // XConnectionPointContainer
204 Reference
< XConnectionPoint
> SAL_CALL
FrameControl::queryConnectionPoint( const Type
& aType
)
206 // Forwarded to helper class
207 return m_aConnectionPointContainer
->queryConnectionPoint( aType
);
210 // XConnectionPointContainer
212 void SAL_CALL
FrameControl::advise( const Type
& aType
,
213 const Reference
< XInterface
>& xListener
)
215 // Forwarded to helper class
216 m_aConnectionPointContainer
->advise( aType
, xListener
);
219 // XConnectionPointContainer
221 void SAL_CALL
FrameControl::unadvise( const Type
& aType
,
222 const Reference
< XInterface
>& xListener
)
224 // Forwarded to helper class
225 m_aConnectionPointContainer
->unadvise( aType
, xListener
);
228 // OPropertySetHelper
230 sal_Bool
FrameControl::convertFastPropertyValue( Any
& rConvertedValue
,
235 bool bReturn
= false;
238 case PropertyHandle::Componenturl
: rConvertedValue
= rValue
;
239 rOldValue
<<= m_sComponentURL
;
243 case PropertyHandle::Loaderarguments
: rConvertedValue
= rValue
;
244 rOldValue
<<= m_seqLoaderArguments
;
251 throw IllegalArgumentException("unknown handle " + OUString::number(nHandle
), getXWeak(), 1);
257 // OPropertySetHelper
259 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
262 // this method only set the value
263 MutexGuard
aGuard (m_aMutex
);
266 case PropertyHandle::Componenturl
: rValue
>>= m_sComponentURL
;
269 impl_createFrame ( getPeer(), m_sComponentURL
, m_seqLoaderArguments
);
273 case PropertyHandle::Loaderarguments
: rValue
>>= m_seqLoaderArguments
;
276 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
280 // OPropertySetHelper
282 void FrameControl::getFastPropertyValue( Any
& rRet
,
283 sal_Int32 nHandle
) const
285 MutexGuard
aGuard ( Mutex::getGlobalMutex() );
289 case PropertyHandle::Componenturl
: rRet
<<= m_sComponentURL
;
292 case PropertyHandle::Loaderarguments
: rRet
<<= m_seqLoaderArguments
;
295 case PropertyHandle::Frame
: rRet
<<= m_xFrame
;
298 default : OSL_ENSURE ( nHandle
== -1, "This is an invalid property handle." );
302 // OPropertySetHelper
304 IPropertyArrayHelper
& FrameControl::getInfoHelper()
306 // Create a table that map names to index values.
307 // attention: properties need to be sorted by name!
308 static OPropertyArrayHelper
ourPropertyInfo(
310 Property( u
"ComponentUrl"_ustr
, PropertyHandle::Componenturl
, cppu::UnoType
<OUString
>::get(),
311 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
),
312 Property( u
"Frame"_ustr
, PropertyHandle::Frame
, cppu::UnoType
<XFrame
>::get(),
313 PropertyAttribute::BOUND
| PropertyAttribute::TRANSIENT
),
314 Property( u
"LoaderArguments"_ustr
, PropertyHandle::Loaderarguments
, cppu::UnoType
<Sequence
<PropertyValue
>>::get(),
315 PropertyAttribute::BOUND
| PropertyAttribute::CONSTRAINED
)
319 return ourPropertyInfo
;
322 // OPropertySetHelper
324 Reference
< XPropertySetInfo
> SAL_CALL
FrameControl::getPropertySetInfo()
326 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
327 // (Use method "getInfoHelper()".)
328 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
335 WindowDescriptor
FrameControl::impl_getWindowDescriptor( const Reference
< XWindowPeer
>& xParentPeer
)
337 WindowDescriptor aDescriptor
;
339 aDescriptor
.Type
= WindowClass_CONTAINER
;
340 aDescriptor
.ParentIndex
= -1;
341 aDescriptor
.Parent
= xParentPeer
;
342 aDescriptor
.Bounds
= getPosSize ();
343 aDescriptor
.WindowAttributes
= 0;
350 void FrameControl::impl_createFrame( const Reference
< XWindowPeer
>& xPeer
,
351 const OUString
& rURL
,
352 const Sequence
< PropertyValue
>& rArguments
)
354 Reference
< XFrame2
> xOldFrame
;
355 Reference
< XFrame2
> xNewFrame
;
358 MutexGuard
aGuard ( m_aMutex
);
359 xOldFrame
= m_xFrame
;
362 xNewFrame
= Frame::create( impl_getComponentContext() );
364 Reference
< XWindow
> xWP ( xPeer
, UNO_QUERY
);
365 xNewFrame
->initialize ( xWP
);
368 //xFrame->setName( "WhatYouWant" );
370 Reference
< XURLTransformer
> xTrans
= URLTransformer::create( impl_getComponentContext() );
373 aURL
.Complete
= rURL
;
374 xTrans
->parseStrict( aURL
);
376 Reference
< XDispatch
> xDisp
= xNewFrame
->queryDispatch ( aURL
, OUString (), FrameSearchFlag::SELF
);
379 xDisp
->dispatch ( aURL
, rArguments
);
384 MutexGuard
aGuard ( m_aMutex
);
385 m_xFrame
= xNewFrame
;
388 // notify the listeners
389 sal_Int32 nFrameId
= PropertyHandle::Frame
;
390 Any
aNewFrame ( &xNewFrame
, cppu::UnoType
<XFrame
>::get());
391 Any
aOldFrame ( &xOldFrame
, cppu::UnoType
<XFrame
>::get());
393 fire ( &nFrameId
, &aNewFrame
, &aOldFrame
, 1, false );
397 xOldFrame
->dispose ();
401 } // namespace unocontrols
403 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
404 stardiv_UnoControls_FrameControl_get_implementation(
405 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
407 return cppu::acquire(new unocontrols::FrameControl(context
));
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */