Bump version to 6.4-15
[LibreOffice.git] / UnoControls / source / controls / framecontrol.cxx
bloba954c112d6f1f89462d587f2b2c8ac5284fbd530
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 enum PropertyHandle // values represent index in PropertyArray
48 { // for FrameControl
49 Componenturl = 0,
50 Frame = 1,
51 Loaderarguments = 2
54 // construct/destruct
56 FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
57 : BaseControl ( rxContext )
58 , OBroadcastHelper ( m_aMutex )
59 , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
60 , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) )
64 FrameControl::~FrameControl()
68 // XInterface
70 Any SAL_CALL FrameControl::queryInterface( const Type& rType )
72 // Attention:
73 // Don't use mutex or guard in this method!!! Is a method of XInterface.
74 Any aReturn;
75 Reference< XInterface > xDel = BaseControl::impl_getDelegator();
76 if ( xDel.is() )
78 // If a delegator exists, forward question to its queryInterface.
79 // Delegator will ask its own queryAggregation!
80 aReturn = xDel->queryInterface( rType );
82 else
84 // If a delegator is unknown, forward question to own queryAggregation.
85 aReturn = queryAggregation( rType );
88 return aReturn;
91 // XInterface
93 void SAL_CALL FrameControl::acquire() throw()
95 // Attention:
96 // Don't use mutex or guard in this method!!! Is a method of XInterface.
98 // Forward to baseclass
99 BaseControl::acquire();
102 // XInterface
104 void SAL_CALL FrameControl::release() throw()
106 // Attention:
107 // Don't use mutex or guard in this method!!! Is a method of XInterface.
109 // Forward to baseclass
110 BaseControl::release();
113 // XTypeProvider
115 Sequence< Type > SAL_CALL FrameControl::getTypes()
117 static OTypeCollection ourTypeCollection(
118 cppu::UnoType<XControlModel>::get(),
119 cppu::UnoType<XControlContainer>::get(),
120 cppu::UnoType<XConnectionPointContainer>::get(),
121 BaseControl::getTypes() );
123 return ourTypeCollection.getTypes();
126 // XAggregation
128 Any SAL_CALL FrameControl::queryAggregation( const Type& aType )
130 // Ask for my own supported interfaces ...
131 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
132 Any aReturn ( ::cppu::queryInterface( aType ,
133 static_cast< XControlModel* > ( this ) ,
134 static_cast< XConnectionPointContainer* > ( this )
138 // If searched interface not supported by this class ...
139 if ( !aReturn.hasValue() )
141 // ... ask baseclasses.
142 aReturn = OPropertySetHelper::queryInterface( aType );
143 if ( !aReturn.hasValue() )
145 aReturn = BaseControl::queryAggregation( aType );
149 return aReturn;
152 OUString FrameControl::getImplementationName()
154 return impl_getStaticImplementationName();
157 css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames()
159 return impl_getStaticSupportedServiceNames();
162 // XControl
164 void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit ,
165 const Reference< XWindowPeer >& xParentPeer )
167 BaseControl::createPeer( xToolkit, xParentPeer );
168 if ( impl_getPeerWindow().is() )
170 if( !m_sComponentURL.isEmpty() )
172 impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments );
177 // XControl
179 sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ )
181 // We have no model.
182 return false;
185 // XControl
187 Reference< XControlModel > SAL_CALL FrameControl::getModel()
189 // We have no model.
190 return Reference< XControlModel >();
193 // XControl
195 void SAL_CALL FrameControl::dispose()
197 impl_deleteFrame();
198 BaseControl::dispose();
201 // XView
203 sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ )
205 // it is not possible to print this control
206 return false;
209 // XView
211 Reference< XGraphics > SAL_CALL FrameControl::getGraphics()
213 // when it's not possible to set graphics ! then it's possible to return null
214 return Reference< XGraphics >();
217 // XConnectionPointContainer
219 Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes()
221 // Forwarded to helper class
222 return m_aConnectionPointContainer->getConnectionPointTypes();
225 // XConnectionPointContainer
227 Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType )
229 // Forwarded to helper class
230 return m_aConnectionPointContainer->queryConnectionPoint( aType );
233 // XConnectionPointContainer
235 void SAL_CALL FrameControl::advise( const Type& aType ,
236 const Reference< XInterface >& xListener )
238 // Forwarded to helper class
239 m_aConnectionPointContainer->advise( aType, xListener );
242 // XConnectionPointContainer
244 void SAL_CALL FrameControl::unadvise( const Type& aType ,
245 const Reference< XInterface >& xListener )
247 // Forwarded to helper class
248 m_aConnectionPointContainer->unadvise( aType, xListener );
251 // impl but public method to register service
253 Sequence< OUString > FrameControl::impl_getStaticSupportedServiceNames()
255 return { "com.sun.star.frame.FrameControl" };
258 // impl but public method to register service
260 OUString FrameControl::impl_getStaticImplementationName()
262 return "stardiv.UnoControls.FrameControl";
265 // OPropertySetHelper
267 sal_Bool FrameControl::convertFastPropertyValue( Any& rConvertedValue ,
268 Any& rOldValue ,
269 sal_Int32 nHandle ,
270 const Any& rValue )
272 bool bReturn = false;
273 switch (nHandle)
275 case PropertyHandle::Componenturl : rConvertedValue = rValue;
276 rOldValue <<= m_sComponentURL;
277 bReturn = true;
278 break;
280 case PropertyHandle::Loaderarguments : rConvertedValue = rValue;
281 rOldValue <<= m_seqLoaderArguments;
282 bReturn = true;
283 break;
286 if ( !bReturn )
288 throw IllegalArgumentException();
291 return bReturn;
294 // OPropertySetHelper
296 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
297 const Any& rValue )
299 // this method only set the value
300 MutexGuard aGuard (m_aMutex);
301 switch (nHandle)
303 case PropertyHandle::Componenturl : rValue >>= m_sComponentURL;
304 if (getPeer().is())
306 impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments );
308 break;
310 case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments;
311 break;
313 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
317 // OPropertySetHelper
319 void FrameControl::getFastPropertyValue( Any& rRet ,
320 sal_Int32 nHandle ) const
322 MutexGuard aGuard ( Mutex::getGlobalMutex() );
324 switch (nHandle)
326 case PropertyHandle::Componenturl : rRet <<= m_sComponentURL;
327 break;
329 case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments;
330 break;
332 case PropertyHandle::Frame : rRet <<= m_xFrame;
333 break;
335 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
339 // OPropertySetHelper
341 IPropertyArrayHelper& FrameControl::getInfoHelper()
343 // Create a table that map names to index values.
344 // attention: properties need to be sorted by name!
345 static OPropertyArrayHelper ourPropertyInfo(
347 Property( "ComponentUrl", PropertyHandle::Componenturl, cppu::UnoType<OUString>::get(),
348 PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ),
349 Property( "Frame", PropertyHandle::Frame, cppu::UnoType<XFrame>::get(),
350 PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT ),
351 Property( "LoaderArguments", PropertyHandle::Loaderarguments, cppu::UnoType<Sequence<PropertyValue>>::get(),
352 PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED )
354 true );
356 return ourPropertyInfo;
359 // OPropertySetHelper
361 Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo()
363 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
364 // (Use method "getInfoHelper()".)
365 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
367 return xInfo;
370 // BaseControl
372 WindowDescriptor FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
374 WindowDescriptor aDescriptor;
376 aDescriptor.Type = WindowClass_CONTAINER;
377 aDescriptor.ParentIndex = -1;
378 aDescriptor.Parent = xParentPeer;
379 aDescriptor.Bounds = getPosSize ();
380 aDescriptor.WindowAttributes = 0;
382 return aDescriptor;
385 // private method
387 void FrameControl::impl_createFrame( const Reference< XWindowPeer >& xPeer ,
388 const OUString& rURL ,
389 const Sequence< PropertyValue >& rArguments )
391 Reference< XFrame2 > xOldFrame;
392 Reference< XFrame2 > xNewFrame;
395 MutexGuard aGuard ( m_aMutex );
396 xOldFrame = m_xFrame;
399 xNewFrame = Frame::create( impl_getComponentContext() );
401 Reference< XWindow > xWP ( xPeer, UNO_QUERY );
402 xNewFrame->initialize ( xWP );
404 // option
405 //xFrame->setName( "WhatYouWant" );
407 Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
408 // load file
409 URL aURL;
410 aURL.Complete = rURL;
411 xTrans->parseStrict( aURL );
413 Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
414 if (xDisp.is())
416 xDisp->dispatch ( aURL, rArguments );
419 // set the frame
421 MutexGuard aGuard ( m_aMutex );
422 m_xFrame = xNewFrame;
425 // notify the listeners
426 sal_Int32 nFrameId = PropertyHandle::Frame;
427 Any aNewFrame ( &xNewFrame, cppu::UnoType<XFrame>::get());
428 Any aOldFrame ( &xOldFrame, cppu::UnoType<XFrame>::get());
430 fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
432 if (xOldFrame.is())
434 xOldFrame->dispose ();
438 // private method
440 void FrameControl::impl_deleteFrame()
442 Reference< XFrame2 > xOldFrame;
443 Reference< XFrame2 > xNullFrame;
446 // do not dispose the frame in this guarded section (deadlock?)
447 MutexGuard aGuard( m_aMutex );
448 xOldFrame = m_xFrame;
449 m_xFrame.clear();
452 // notify the listeners
453 sal_Int32 nFrameId = PropertyHandle::Frame;
454 Any aNewFrame( &xNullFrame, cppu::UnoType<XFrame2>::get());
455 Any aOldFrame( &xOldFrame, cppu::UnoType<XFrame2>::get());
456 fire( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
458 // dispose the frame
459 if( xOldFrame.is() )
460 xOldFrame->dispose();
464 } // namespace unocontrols
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */