tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / UnoControls / source / controls / framecontrol.cxx
blobe6eefda2124cfa23cf8974a81ac43260a7ae1c53
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 <comphelper/sequence.hxx>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <osl/diagnose.h>
35 // namespaces
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 {
48 namespace {
50 enum PropertyHandle // values represent index in PropertyArray
51 { // for FrameControl
52 Componenturl = 0,
53 Frame = 1,
54 Loaderarguments = 2
59 // construct/destruct
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()
73 // XInterface
74 Any SAL_CALL FrameControl::queryInterface( const Type& rType )
76 Any aReturn = OPropertySetHelper::queryInterface(rType);
77 if (aReturn.hasValue())
78 return aReturn;
79 return FrameControl_BASE::queryInterface(rType);
82 // XInterface
83 void SAL_CALL FrameControl::acquire() noexcept
85 // Attention:
86 // Don't use mutex or guard in this method!!! Is a method of XInterface.
88 // Forward to baseclass
89 FrameControl_BASE::acquire();
92 // XInterface
93 void SAL_CALL FrameControl::release() noexcept
95 // Attention:
96 // Don't use mutex or guard in this method!!! Is a method of XInterface.
98 // Forward to baseclass
99 FrameControl_BASE::release();
102 // XTypeProvider
104 Sequence< Type > SAL_CALL FrameControl::getTypes()
106 static Sequence myTypes = comphelper::concatSequences(FrameControl_BASE::getTypes(),
107 OPropertySetHelper::getTypes());
108 return myTypes;
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 };
121 // XControl
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 );
136 // XControl
138 sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ )
140 // We have no model.
141 return false;
144 // XControl
146 Reference< XControlModel > SAL_CALL FrameControl::getModel()
148 // We have no model.
149 return Reference< XControlModel >();
152 // XControl
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 );
170 // dispose the frame
171 if( xOldFrame.is() )
172 xOldFrame->dispose();
174 m_aConnectionPointContainer.clear();
175 BaseControl::dispose();
178 // XView
180 sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ )
182 // it is not possible to print this control
183 return false;
186 // XView
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 ,
231 Any& rOldValue ,
232 sal_Int32 nHandle ,
233 const Any& rValue )
235 bool bReturn = false;
236 switch (nHandle)
238 case PropertyHandle::Componenturl : rConvertedValue = rValue;
239 rOldValue <<= m_sComponentURL;
240 bReturn = true;
241 break;
243 case PropertyHandle::Loaderarguments : rConvertedValue = rValue;
244 rOldValue <<= m_seqLoaderArguments;
245 bReturn = true;
246 break;
249 if ( !bReturn )
251 throw IllegalArgumentException("unknown handle " + OUString::number(nHandle), getXWeak(), 1);
254 return bReturn;
257 // OPropertySetHelper
259 void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
260 const Any& rValue )
262 // this method only set the value
263 MutexGuard aGuard (m_aMutex);
264 switch (nHandle)
266 case PropertyHandle::Componenturl : rValue >>= m_sComponentURL;
267 if (getPeer().is())
269 impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments );
271 break;
273 case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments;
274 break;
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() );
287 switch (nHandle)
289 case PropertyHandle::Componenturl : rRet <<= m_sComponentURL;
290 break;
292 case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments;
293 break;
295 case PropertyHandle::Frame : rRet <<= m_xFrame;
296 break;
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 )
317 true );
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() ) );
330 return xInfo;
333 // BaseControl
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;
345 return aDescriptor;
348 // private method
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 );
367 // option
368 //xFrame->setName( "WhatYouWant" );
370 Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
371 // load file
372 URL aURL;
373 aURL.Complete = rURL;
374 xTrans->parseStrict( aURL );
376 Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
377 if (xDisp.is())
379 xDisp->dispatch ( aURL, rArguments );
382 // set the frame
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 );
395 if (xOldFrame.is())
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: */