Bump version to 6.0-36
[LibreOffice.git] / UnoControls / source / controls / framecontrol.cxx
blob6f36178259788c135f5aa58113ad540c1fdbaf96
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/XDispatch.hpp>
26 #include <com/sun/star/util/URLTransformer.hpp>
27 #include <com/sun/star/util/XURLTransformer.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <osl/diagnose.h>
33 // namespaces
35 using namespace ::osl;
36 using namespace ::cppu;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::awt;
41 using namespace ::com::sun::star::frame;
42 using namespace ::com::sun::star::util;
44 namespace unocontrols{
46 enum PropertyHandle // values represent index in PropertyArray
47 { // for FrameControl
48 Componenturl = 0,
49 Frame = 1,
50 Loaderarguments = 2
53 // construct/destruct
55 FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
56 : BaseControl ( rxContext )
57 , OBroadcastHelper ( m_aMutex )
58 , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
59 , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) )
63 FrameControl::~FrameControl()
67 // XInterface
69 Any SAL_CALL FrameControl::queryInterface( const Type& rType )
71 // Attention:
72 // Don't use mutex or guard in this method!!! Is a method of XInterface.
73 Any aReturn;
74 Reference< XInterface > xDel = BaseControl::impl_getDelegator();
75 if ( xDel.is() )
77 // If an delegator exist, forward question to his queryInterface.
78 // Delegator will ask his own queryAggregation!
79 aReturn = xDel->queryInterface( rType );
81 else
83 // If an delegator unknown, forward question to own queryAggregation.
84 aReturn = queryAggregation( rType );
87 return aReturn;
90 // XInterface
92 void SAL_CALL FrameControl::acquire() throw()
94 // Attention:
95 // Don't use mutex or guard in this method!!! Is a method of XInterface.
97 // Forward to baseclass
98 BaseControl::acquire();
101 // XInterface
103 void SAL_CALL FrameControl::release() throw()
105 // Attention:
106 // Don't use mutex or guard in this method!!! Is a method of XInterface.
108 // Forward to baseclass
109 BaseControl::release();
112 // XTypeProvider
114 Sequence< Type > SAL_CALL FrameControl::getTypes()
116 static OTypeCollection ourTypeCollection(
117 cppu::UnoType<XControlModel>::get(),
118 cppu::UnoType<XControlContainer>::get(),
119 cppu::UnoType<XConnectionPointContainer>::get(),
120 BaseControl::getTypes() );
122 return ourTypeCollection.getTypes();
125 // XAggregation
127 Any SAL_CALL FrameControl::queryAggregation( const Type& aType )
129 // Ask for my own supported interfaces ...
130 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
131 Any aReturn ( ::cppu::queryInterface( aType ,
132 static_cast< XControlModel* > ( this ) ,
133 static_cast< XConnectionPointContainer* > ( this )
137 // If searched interface not supported by this class ...
138 if ( !aReturn.hasValue() )
140 // ... ask baseclasses.
141 aReturn = OPropertySetHelper::queryInterface( aType );
142 if ( !aReturn.hasValue() )
144 aReturn = BaseControl::queryAggregation( aType );
148 return aReturn;
151 OUString FrameControl::getImplementationName()
153 return impl_getStaticImplementationName();
156 css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames()
158 return impl_getStaticSupportedServiceNames();
161 // XControl
163 void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit ,
164 const Reference< XWindowPeer >& xParentPeer )
166 BaseControl::createPeer( xToolkit, xParentPeer );
167 if ( impl_getPeerWindow().is() )
169 if( !m_sComponentURL.isEmpty() )
171 impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments );
176 // XControl
178 sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ )
180 // We have no model.
181 return false;
184 // XControl
186 Reference< XControlModel > SAL_CALL FrameControl::getModel()
188 // We have no model.
189 return Reference< XControlModel >();
192 // XControl
194 void SAL_CALL FrameControl::dispose()
196 impl_deleteFrame();
197 BaseControl::dispose();
200 // XView
202 sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ )
204 // it is not possible to print this control
205 return false;
208 // XView
210 Reference< XGraphics > SAL_CALL FrameControl::getGraphics()
212 // when it's not possible to set graphics ! then it's possible to return null
213 return Reference< XGraphics >();
216 // XConnectionPointContainer
218 Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes()
220 // Forwarded to helper class
221 return m_aConnectionPointContainer->getConnectionPointTypes();
224 // XConnectionPointContainer
226 Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType )
228 // Forwarded to helper class
229 return m_aConnectionPointContainer->queryConnectionPoint( aType );
232 // XConnectionPointContainer
234 void SAL_CALL FrameControl::advise( const Type& aType ,
235 const Reference< XInterface >& xListener )
237 // Forwarded to helper class
238 m_aConnectionPointContainer->advise( aType, xListener );
241 // XConnectionPointContainer
243 void SAL_CALL FrameControl::unadvise( const Type& aType ,
244 const Reference< XInterface >& xListener )
246 // Forwarded to helper class
247 m_aConnectionPointContainer->unadvise( aType, xListener );
250 // impl but public method to register service
252 const Sequence< OUString > FrameControl::impl_getStaticSupportedServiceNames()
254 Sequence<OUString> seqServiceNames { "com.sun.star.frame.FrameControl" };
255 return seqServiceNames;
258 // impl but public method to register service
260 const OUString FrameControl::impl_getStaticImplementationName()
262 return OUString("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* pDescriptor = new WindowDescriptor;
376 pDescriptor->Type = WindowClass_CONTAINER;
377 pDescriptor->ParentIndex = -1;
378 pDescriptor->Parent = xParentPeer;
379 pDescriptor->Bounds = getPosSize ();
380 pDescriptor->WindowAttributes = 0;
382 return pDescriptor;
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: */