fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / UnoControls / source / controls / framecontrol.cxx
blobda8fd36e274fd332aa40ce0d78f345e5e736675d
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"
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/frame/Frame.hpp>
24 #include <com/sun/star/frame/FrameSearchFlag.hpp>
25 #include <com/sun/star/frame/XDispatchProvider.hpp>
26 #include <com/sun/star/frame/XDispatch.hpp>
27 #include <com/sun/star/util/URLTransformer.hpp>
28 #include <com/sun/star/util/XURLTransformer.hpp>
29 #include <comphelper/processfactory.hxx>
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 // construct/destruct
49 FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
50 : BaseControl ( rxContext )
51 , OBroadcastHelper ( m_aMutex )
52 , OPropertySetHelper ( *(static_cast< OBroadcastHelper * >(this)) )
53 , m_aInterfaceContainer ( m_aMutex )
54 , m_aConnectionPointContainer ( m_aMutex )
58 FrameControl::~FrameControl()
62 // XInterface
64 Any SAL_CALL FrameControl::queryInterface( const Type& rType ) throw( RuntimeException, std::exception )
66 // Attention:
67 // Don't use mutex or guard in this method!!! Is a method of XInterface.
68 Any aReturn;
69 Reference< XInterface > xDel = BaseControl::impl_getDelegator();
70 if ( xDel.is() )
72 // If an delegator exist, forward question to his queryInterface.
73 // Delegator will ask his own queryAggregation!
74 aReturn = xDel->queryInterface( rType );
76 else
78 // If an delegator unknown, forward question to own queryAggregation.
79 aReturn = queryAggregation( rType );
82 return aReturn;
85 // XInterface
87 void SAL_CALL FrameControl::acquire() throw()
89 // Attention:
90 // Don't use mutex or guard in this method!!! Is a method of XInterface.
92 // Forward to baseclass
93 BaseControl::acquire();
96 // XInterface
98 void SAL_CALL FrameControl::release() throw()
100 // Attention:
101 // Don't use mutex or guard in this method!!! Is a method of XInterface.
103 // Forward to baseclass
104 BaseControl::release();
107 // XTypeProvider
109 Sequence< Type > SAL_CALL FrameControl::getTypes() throw( RuntimeException, std::exception )
111 // Optimize this method !
112 // We initialize a static variable only one time. And we don't must use a mutex at every call!
113 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
114 static OTypeCollection* pTypeCollection = NULL;
116 if ( pTypeCollection == NULL )
118 // Ready for multithreading; get global mutex for first call of this method only! see before
119 MutexGuard aGuard( Mutex::getGlobalMutex() );
121 // Control these pointer again ... it can be, that another instance will be faster then these!
122 if ( pTypeCollection == NULL )
124 // Create a static typecollection ...
125 static OTypeCollection aTypeCollection ( cppu::UnoType<XControlModel>::get(),
126 cppu::UnoType<XControlContainer>::get(),
127 cppu::UnoType<XConnectionPointContainer>::get(),
128 BaseControl::getTypes()
130 // ... and set his address to static pointer!
131 pTypeCollection = &aTypeCollection;
135 return pTypeCollection->getTypes();
138 // XAggregation
140 Any SAL_CALL FrameControl::queryAggregation( const Type& aType ) throw( RuntimeException, std::exception )
142 // Ask for my own supported interfaces ...
143 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
144 Any aReturn ( ::cppu::queryInterface( aType ,
145 static_cast< XControlModel* > ( this ) ,
146 static_cast< XConnectionPointContainer* > ( this )
150 // If searched interface not supported by this class ...
151 if ( !aReturn.hasValue() )
153 // ... ask baseclasses.
154 aReturn = OPropertySetHelper::queryInterface( aType );
155 if ( !aReturn.hasValue() )
157 aReturn = BaseControl::queryAggregation( aType );
161 return aReturn;
164 OUString FrameControl::getImplementationName()
165 throw (css::uno::RuntimeException, std::exception)
167 return impl_getStaticImplementationName();
170 css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames()
171 throw (css::uno::RuntimeException, std::exception)
173 return impl_getStaticSupportedServiceNames();
176 // XControl
178 void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit ,
179 const Reference< XWindowPeer >& xParentPeer ) throw( RuntimeException, std::exception )
181 BaseControl::createPeer( xToolkit, xParentPeer );
182 if ( impl_getPeerWindow().is() )
184 if( !m_sComponentURL.isEmpty() )
186 impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments );
191 // XControl
193 sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ ) throw( RuntimeException, std::exception )
195 // We have no model.
196 return false;
199 // XControl
201 Reference< XControlModel > SAL_CALL FrameControl::getModel() throw( RuntimeException, std::exception )
203 // We have no model.
204 return Reference< XControlModel >();
207 // XControl
209 void SAL_CALL FrameControl::dispose() throw( RuntimeException, std::exception )
211 impl_deleteFrame();
212 BaseControl::dispose();
215 // XView
217 sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ ) throw( RuntimeException, std::exception )
219 // it is not possible to print this control
220 return false;
223 // XView
225 Reference< XGraphics > SAL_CALL FrameControl::getGraphics() throw( RuntimeException, std::exception )
227 // when it's not possible to set graphics ! then it's possible to return null
228 return Reference< XGraphics >();
231 // XConnectionPointContainer
233 Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes() throw( RuntimeException, std::exception )
235 // Forwarded to helper class
236 return m_aConnectionPointContainer.getConnectionPointTypes();
239 // XConnectionPointContainer
241 Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType ) throw( RuntimeException, std::exception )
243 // Forwarded to helper class
244 return m_aConnectionPointContainer.queryConnectionPoint( aType );
247 // XConnectionPointContainer
249 void SAL_CALL FrameControl::advise( const Type& aType ,
250 const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
252 // Forwarded to helper class
253 m_aConnectionPointContainer.advise( aType, xListener );
256 // XConnectionPointContainer
258 void SAL_CALL FrameControl::unadvise( const Type& aType ,
259 const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
261 // Forwarded to helper class
262 m_aConnectionPointContainer.unadvise( aType, xListener );
265 // impl but public method to register service
267 const Sequence< OUString > FrameControl::impl_getStaticSupportedServiceNames()
269 MutexGuard aGuard( Mutex::getGlobalMutex() );
270 Sequence< OUString > seqServiceNames( 1 );
271 seqServiceNames.getArray() [0] = SERVICENAME_FRAMECONTROL;
272 return seqServiceNames;
275 // impl but public method to register service
277 const OUString FrameControl::impl_getStaticImplementationName()
279 return OUString(IMPLEMENTATIONNAME_FRAMECONTROL);
282 // OPropertySetHelper
284 sal_Bool FrameControl::convertFastPropertyValue( Any& rConvertedValue ,
285 Any& rOldValue ,
286 sal_Int32 nHandle ,
287 const Any& rValue ) throw( IllegalArgumentException )
289 bool bReturn = false;
290 switch (nHandle)
292 case PROPERTYHANDLE_COMPONENTURL : rConvertedValue = rValue;
293 rOldValue <<= m_sComponentURL;
294 bReturn = true;
295 break;
297 case PROPERTYHANDLE_LOADERARGUMENTS : rConvertedValue = rValue;
298 rOldValue <<= m_seqLoaderArguments;
299 bReturn = true;
300 break;
303 if ( !bReturn )
305 throw IllegalArgumentException();
308 return bReturn;
311 // OPropertySetHelper
313 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
314 const Any& rValue )
315 throw ( ::com::sun::star::uno::Exception, std::exception )
317 // this method only set the value
318 MutexGuard aGuard (m_aMutex);
319 switch (nHandle)
321 case PROPERTYHANDLE_COMPONENTURL : rValue >>= m_sComponentURL;
322 if (getPeer().is())
324 impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments );
326 break;
328 case PROPERTYHANDLE_LOADERARGUMENTS : rValue >>= m_seqLoaderArguments;
329 break;
331 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
335 // OPropertySetHelper
337 void FrameControl::getFastPropertyValue( Any& rRet ,
338 sal_Int32 nHandle ) const
340 MutexGuard aGuard ( Mutex::getGlobalMutex() );
342 switch (nHandle)
344 case PROPERTYHANDLE_COMPONENTURL : rRet <<= m_sComponentURL;
345 break;
347 case PROPERTYHANDLE_LOADERARGUMENTS : rRet <<= m_seqLoaderArguments;
348 break;
350 case PROPERTYHANDLE_FRAME : rRet <<= m_xFrame;
351 break;
353 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
357 // OPropertySetHelper
359 IPropertyArrayHelper& FrameControl::getInfoHelper()
361 // Create a table that map names to index values.
362 static OPropertyArrayHelper* pInfo;
364 if (!pInfo)
366 // global method must be guarded
367 MutexGuard aGuard ( Mutex::getGlobalMutex() );
369 if (!pInfo)
371 pInfo = new OPropertyArrayHelper( impl_getStaticPropertyDescriptor(), true );
375 return *pInfo;
378 // OPropertySetHelper
380 Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo() throw( RuntimeException, std::exception )
382 // Optimize this method !
383 // We initialize a static variable only one time. And we don't must use a mutex at every call!
384 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
385 static Reference< XPropertySetInfo >* pInfo = (Reference< XPropertySetInfo >*)0;
386 if ( pInfo == (Reference< XPropertySetInfo >*)0 )
388 // Ready for multithreading
389 MutexGuard aGuard ( Mutex::getGlobalMutex () );
390 // Control this pointer again, another instance can be faster then these!
391 if ( pInfo == (Reference< XPropertySetInfo >*)0 )
393 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
394 // (Use method "getInfoHelper()".)
395 static Reference< XPropertySetInfo > xInfo ( createPropertySetInfo ( getInfoHelper () ) );
396 pInfo = &xInfo;
399 return ( *pInfo );
402 // BaseControl
404 WindowDescriptor* FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
406 WindowDescriptor* pDescriptor = new WindowDescriptor;
408 pDescriptor->Type = WindowClass_CONTAINER;
409 pDescriptor->ParentIndex = -1;
410 pDescriptor->Parent = xParentPeer;
411 pDescriptor->Bounds = getPosSize ();
412 pDescriptor->WindowAttributes = 0;
414 return pDescriptor;
417 // private method
419 void FrameControl::impl_createFrame( const Reference< XWindowPeer >& xPeer ,
420 const OUString& rURL ,
421 const Sequence< PropertyValue >& rArguments )
423 Reference< XFrame2 > xOldFrame;
424 Reference< XFrame2 > xNewFrame;
427 MutexGuard aGuard ( m_aMutex );
428 xOldFrame = m_xFrame;
431 xNewFrame = Frame::create( impl_getComponentContext() );
433 Reference< XWindow > xWP ( xPeer, UNO_QUERY );
434 xNewFrame->initialize ( xWP );
436 // option
437 //xFrame->setName( "WhatYouWant" );
439 Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
440 // load file
441 URL aURL;
442 aURL.Complete = rURL;
443 xTrans->parseStrict( aURL );
445 Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
446 if (xDisp.is())
448 xDisp->dispatch ( aURL, rArguments );
451 // set the frame
453 MutexGuard aGuard ( m_aMutex );
454 m_xFrame = xNewFrame;
457 // notify the listeners
458 sal_Int32 nFrameId = PROPERTYHANDLE_FRAME;
459 Any aNewFrame ( &xNewFrame, cppu::UnoType<XFrame>::get());
460 Any aOldFrame ( &xOldFrame, cppu::UnoType<XFrame>::get());
462 fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
464 if (xOldFrame.is())
466 xOldFrame->dispose ();
470 // private method
472 void FrameControl::impl_deleteFrame()
474 Reference< XFrame2 > xOldFrame;
475 Reference< XFrame2 > xNullFrame;
478 // do not dispose the frame in this guarded section (deadlock?)
479 MutexGuard aGuard( m_aMutex );
480 xOldFrame = m_xFrame;
481 m_xFrame = Reference< XFrame2 > ();
484 // notify the listeners
485 sal_Int32 nFrameId = PROPERTYHANDLE_FRAME;
486 Any aNewFrame( &xNullFrame, cppu::UnoType<XFrame2>::get());
487 Any aOldFrame( &xOldFrame, cppu::UnoType<XFrame2>::get());
488 fire( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
490 // dispose the frame
491 if( xOldFrame.is() )
492 xOldFrame->dispose();
495 // private method
497 const Sequence< Property > FrameControl::impl_getStaticPropertyDescriptor()
499 // All Properties of this implementation. The array must be sorted!
500 static const Property pPropertys[PROPERTY_COUNT] =
502 Property( PROPERTYNAME_COMPONENTURL, PROPERTYHANDLE_COMPONENTURL, cppu::UnoType<OUString>::get(), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ),
503 Property( PROPERTYNAME_FRAME, PROPERTYHANDLE_FRAME, cppu::UnoType<XFrame>::get(), PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT ),
504 Property( PROPERTYNAME_LOADERARGUMENTS, PROPERTYHANDLE_LOADERARGUMENTS, cppu::UnoType<Sequence<PropertyValue>>::get(), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED )
507 static const Sequence< Property > seqPropertys( pPropertys, PROPERTY_COUNT );
509 return seqPropertys;
512 } // namespace unocontrols
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */