nss: upgrade to release 3.73
[LibreOffice.git] / UnoControls / source / controls / framecontrol.cxx
blob8ecc73cf2d1a959f893d11fbd07d08fda559b7d1
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 <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>
34 // namespaces
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 {
47 namespace {
49 enum PropertyHandle // values represent index in PropertyArray
50 { // for FrameControl
51 Componenturl = 0,
52 Frame = 1,
53 Loaderarguments = 2
58 // construct/destruct
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()
72 // XInterface
74 Any SAL_CALL FrameControl::queryInterface( const Type& rType )
76 // Attention:
77 // Don't use mutex or guard in this method!!! Is a method of XInterface.
78 Any aReturn;
79 Reference< XInterface > xDel = BaseControl::impl_getDelegator();
80 if ( xDel.is() )
82 // If a delegator exists, forward question to its queryInterface.
83 // Delegator will ask its own queryAggregation!
84 aReturn = xDel->queryInterface( rType );
86 else
88 // If a delegator is unknown, forward question to own queryAggregation.
89 aReturn = queryAggregation( rType );
92 return aReturn;
95 // XInterface
97 void SAL_CALL FrameControl::acquire() throw()
99 // Attention:
100 // Don't use mutex or guard in this method!!! Is a method of XInterface.
102 // Forward to baseclass
103 BaseControl::acquire();
106 // XInterface
108 void SAL_CALL FrameControl::release() throw()
110 // Attention:
111 // Don't use mutex or guard in this method!!! Is a method of XInterface.
113 // Forward to baseclass
114 BaseControl::release();
117 // XTypeProvider
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();
130 // XAggregation
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 );
153 return aReturn;
156 OUString FrameControl::getImplementationName()
158 return "stardiv.UnoControls.FrameControl";
161 css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames()
163 return { "com.sun.star.frame.FrameControl" };
166 // XControl
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 );
181 // XControl
183 sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ )
185 // We have no model.
186 return false;
189 // XControl
191 Reference< XControlModel > SAL_CALL FrameControl::getModel()
193 // We have no model.
194 return Reference< XControlModel >();
197 // XControl
199 void SAL_CALL FrameControl::dispose()
201 impl_deleteFrame();
202 BaseControl::dispose();
205 // XView
207 sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ )
209 // it is not possible to print this control
210 return false;
213 // XView
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 ,
258 Any& rOldValue ,
259 sal_Int32 nHandle ,
260 const Any& rValue )
262 bool bReturn = false;
263 switch (nHandle)
265 case PropertyHandle::Componenturl : rConvertedValue = rValue;
266 rOldValue <<= m_sComponentURL;
267 bReturn = true;
268 break;
270 case PropertyHandle::Loaderarguments : rConvertedValue = rValue;
271 rOldValue <<= m_seqLoaderArguments;
272 bReturn = true;
273 break;
276 if ( !bReturn )
278 throw IllegalArgumentException();
281 return bReturn;
284 // OPropertySetHelper
286 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
287 const Any& rValue )
289 // this method only set the value
290 MutexGuard aGuard (m_aMutex);
291 switch (nHandle)
293 case PropertyHandle::Componenturl : rValue >>= m_sComponentURL;
294 if (getPeer().is())
296 impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments );
298 break;
300 case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments;
301 break;
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() );
314 switch (nHandle)
316 case PropertyHandle::Componenturl : rRet <<= m_sComponentURL;
317 break;
319 case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments;
320 break;
322 case PropertyHandle::Frame : rRet <<= m_xFrame;
323 break;
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 )
344 true );
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() ) );
357 return xInfo;
360 // BaseControl
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;
372 return aDescriptor;
375 // private method
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 );
394 // option
395 //xFrame->setName( "WhatYouWant" );
397 Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
398 // load file
399 URL aURL;
400 aURL.Complete = rURL;
401 xTrans->parseStrict( aURL );
403 Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
404 if (xDisp.is())
406 xDisp->dispatch ( aURL, rArguments );
409 // set the frame
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 );
422 if (xOldFrame.is())
424 xOldFrame->dispose ();
428 // private method
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;
439 m_xFrame.clear();
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 );
448 // dispose the frame
449 if( xOldFrame.is() )
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: */