LibreOffice Module UnoControls (master) 1
framecontrol.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <framecontrol.hxx>
22
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>
32#include <osl/diagnose.h>
33
34// namespaces
35
36using namespace ::osl;
37using namespace ::cppu;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::awt;
42using namespace ::com::sun::star::frame;
43using namespace ::com::sun::star::util;
44
45namespace unocontrols {
46
47namespace {
48
49enum PropertyHandle // values represent index in PropertyArray
50{ // for FrameControl
51 Componenturl = 0,
52 Frame = 1,
53 Loaderarguments = 2
54};
55
56}
57
58// construct/destruct
59
60FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
61 : BaseControl ( rxContext )
63 , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
64 , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) )
65{
66}
67
69{
70}
71
72// XInterface
73
74Any SAL_CALL FrameControl::queryInterface( const Type& rType )
75{
76 // Ask for my own supported interfaces ...
77 // Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
78 Any aReturn ( ::cppu::queryInterface( rType ,
79 static_cast< XControlModel* > ( this ) ,
80 static_cast< XConnectionPointContainer* > ( this )
81 )
82 );
83
84 // If searched interface not supported by this class ...
85 if ( !aReturn.hasValue() )
86 {
87 // ... ask baseclasses.
88 aReturn = OPropertySetHelper::queryInterface( rType );
89 if ( !aReturn.hasValue() )
90 {
91 aReturn = BaseControl::queryInterface( rType );
92 }
93 }
94
95 return aReturn;
96}
97
98// XInterface
99
100void SAL_CALL FrameControl::acquire() noexcept
101{
102 // Attention:
103 // Don't use mutex or guard in this method!!! Is a method of XInterface.
104
105 // Forward to baseclass
107}
108
109// XInterface
110
111void SAL_CALL FrameControl::release() noexcept
112{
113 // Attention:
114 // Don't use mutex or guard in this method!!! Is a method of XInterface.
115
116 // Forward to baseclass
118}
119
120// XTypeProvider
121
122Sequence< Type > SAL_CALL FrameControl::getTypes()
123{
124 static OTypeCollection ourTypeCollection(
129
130 return ourTypeCollection.getTypes();
131}
132
134{
135 return "stardiv.UnoControls.FrameControl";
136}
137
138css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames()
139{
140 return { "com.sun.star.frame.FrameControl" };
141}
142
143// XControl
144
145void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit ,
146 const Reference< XWindowPeer >& xParentPeer )
147{
148 BaseControl::createPeer( xToolkit, xParentPeer );
149 if ( impl_getPeerWindow().is() )
150 {
151 if( !m_sComponentURL.isEmpty() )
152 {
154 }
155 }
156}
157
158// XControl
159
160sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ )
161{
162 // We have no model.
163 return false;
164}
165
166// XControl
167
168Reference< XControlModel > SAL_CALL FrameControl::getModel()
169{
170 // We have no model.
171 return Reference< XControlModel >();
172}
173
174// XControl
175
177{
180}
181
182// XView
183
184sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ )
185{
186 // it is not possible to print this control
187 return false;
188}
189
190// XView
191
192Reference< XGraphics > SAL_CALL FrameControl::getGraphics()
193{
194 // when it's not possible to set graphics ! then it's possible to return null
195 return Reference< XGraphics >();
196}
197
198// XConnectionPointContainer
199
200Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes()
201{
202 // Forwarded to helper class
203 return m_aConnectionPointContainer->getConnectionPointTypes();
204}
205
206// XConnectionPointContainer
207
208Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType )
209{
210 // Forwarded to helper class
211 return m_aConnectionPointContainer->queryConnectionPoint( aType );
212}
213
214// XConnectionPointContainer
215
216void SAL_CALL FrameControl::advise( const Type& aType ,
217 const Reference< XInterface >& xListener )
218{
219 // Forwarded to helper class
220 m_aConnectionPointContainer->advise( aType, xListener );
221}
222
223// XConnectionPointContainer
224
225void SAL_CALL FrameControl::unadvise( const Type& aType ,
226 const Reference< XInterface >& xListener )
227{
228 // Forwarded to helper class
229 m_aConnectionPointContainer->unadvise( aType, xListener );
230}
231
232// OPropertySetHelper
233
235 Any& rOldValue ,
236 sal_Int32 nHandle ,
237 const Any& rValue )
238{
239 bool bReturn = false;
240 switch (nHandle)
241 {
242 case PropertyHandle::Componenturl : rConvertedValue = rValue;
243 rOldValue <<= m_sComponentURL;
244 bReturn = true;
245 break;
246
247 case PropertyHandle::Loaderarguments : rConvertedValue = rValue;
248 rOldValue <<= m_seqLoaderArguments;
249 bReturn = true;
250 break;
251 }
252
253 if ( !bReturn )
254 {
255 throw IllegalArgumentException("unknown handle " + OUString::number(nHandle), getXWeak(), 1);
256 }
257
258 return bReturn;
259}
260
261// OPropertySetHelper
262
264 const Any& rValue )
265{
266 // this method only set the value
267 MutexGuard aGuard (m_aMutex);
268 switch (nHandle)
269 {
270 case PropertyHandle::Componenturl : rValue >>= m_sComponentURL;
271 if (getPeer().is())
272 {
274 }
275 break;
276
277 case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments;
278 break;
279
280 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
281 }
282}
283
284// OPropertySetHelper
285
287 sal_Int32 nHandle ) const
288{
289 MutexGuard aGuard ( Mutex::getGlobalMutex() );
290
291 switch (nHandle)
292 {
293 case PropertyHandle::Componenturl : rRet <<= m_sComponentURL;
294 break;
295
296 case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments;
297 break;
298
299 case PropertyHandle::Frame : rRet <<= m_xFrame;
300 break;
301
302 default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
303 }
304}
305
306// OPropertySetHelper
307
308IPropertyArrayHelper& FrameControl::getInfoHelper()
309{
310 // Create a table that map names to index values.
311 // attention: properties need to be sorted by name!
312 static OPropertyArrayHelper ourPropertyInfo(
313 {
314 Property( "ComponentUrl", PropertyHandle::Componenturl, cppu::UnoType<OUString>::get(),
315 PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ),
316 Property( "Frame", PropertyHandle::Frame, cppu::UnoType<XFrame>::get(),
317 PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT ),
318 Property( "LoaderArguments", PropertyHandle::Loaderarguments, cppu::UnoType<Sequence<PropertyValue>>::get(),
319 PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED )
320 },
321 true );
322
323 return ourPropertyInfo;
324}
325
326// OPropertySetHelper
327
328Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo()
329{
330 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
331 // (Use method "getInfoHelper()".)
332 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
333
334 return xInfo;
335}
336
337// BaseControl
338
339WindowDescriptor FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
340{
341 WindowDescriptor aDescriptor;
342
343 aDescriptor.Type = WindowClass_CONTAINER;
344 aDescriptor.ParentIndex = -1;
345 aDescriptor.Parent = xParentPeer;
346 aDescriptor.Bounds = getPosSize ();
347 aDescriptor.WindowAttributes = 0;
348
349 return aDescriptor;
350}
351
352// private method
353
354void FrameControl::impl_createFrame( const Reference< XWindowPeer >& xPeer ,
355 const OUString& rURL ,
356 const Sequence< PropertyValue >& rArguments )
357{
358 Reference< XFrame2 > xOldFrame;
359 Reference< XFrame2 > xNewFrame;
360
361 {
362 MutexGuard aGuard ( m_aMutex );
363 xOldFrame = m_xFrame;
364 }
365
366 xNewFrame = Frame::create( impl_getComponentContext() );
367
368 Reference< XWindow > xWP ( xPeer, UNO_QUERY );
369 xNewFrame->initialize ( xWP );
370
371 // option
372 //xFrame->setName( "WhatYouWant" );
373
374 Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
375 // load file
376 URL aURL;
377 aURL.Complete = rURL;
378 xTrans->parseStrict( aURL );
379
380 Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
381 if (xDisp.is())
382 {
383 xDisp->dispatch ( aURL, rArguments );
384 }
385
386 // set the frame
387 {
388 MutexGuard aGuard ( m_aMutex );
389 m_xFrame = xNewFrame;
390 }
391
392 // notify the listeners
393 sal_Int32 nFrameId = PropertyHandle::Frame;
394 Any aNewFrame ( &xNewFrame, cppu::UnoType<XFrame>::get());
395 Any aOldFrame ( &xOldFrame, cppu::UnoType<XFrame>::get());
396
397 fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
398
399 if (xOldFrame.is())
400 {
401 xOldFrame->dispose ();
402 }
403}
404
405// private method
406
408{
409 Reference< XFrame2 > xOldFrame;
410 Reference< XFrame2 > xNullFrame;
411
412 {
413 // do not dispose the frame in this guarded section (deadlock?)
414 MutexGuard aGuard( m_aMutex );
415 xOldFrame = m_xFrame;
416 m_xFrame.clear();
417 }
418
419 // notify the listeners
420 sal_Int32 nFrameId = PropertyHandle::Frame;
421 Any aNewFrame( &xNullFrame, cppu::UnoType<XFrame2>::get());
422 Any aOldFrame( &xOldFrame, cppu::UnoType<XFrame2>::get());
423 fire( &nFrameId, &aNewFrame, &aOldFrame, 1, false );
424
425 // dispose the frame
426 if( xOldFrame.is() )
427 xOldFrame->dispose();
428}
429
430
431} // namespace unocontrols
432
433extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
435 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
436{
437 return cppu::acquire(new unocontrols::FrameControl(context));
438}
439/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mutable::osl::Mutex m_aMutex
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL fire(sal_Int32 *pnHandles, const css::uno::Any *pNewValues, const css::uno::Any *pOldValues, sal_Int32 nCount, sal_Bool bVetoable)
const css::uno::Reference< css::awt::XWindow > & impl_getPeerWindow() const
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &xToolkit, const css::uno::Reference< css::awt::XWindowPeer > &xParent) override
virtual void SAL_CALL release() noexcept override
decrement refcount @seealso XInterface @seealso acquire() @onerror A RuntimeException is thrown.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
get information about supported interfaces @seealso XTypeProvider
virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
const css::uno::Reference< css::uno::XComponentContext > & impl_getComponentContext() const
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
give answer, if interface is supported @descr The interfaces are searched by type.
Definition: basecontrol.cxx:70
virtual void SAL_CALL dispose() override
virtual css::awt::Rectangle SAL_CALL getPosSize() override
virtual void SAL_CALL acquire() noexcept override
increment refcount @seealso XInterface @seealso release() @onerror A RuntimeException is thrown.
Definition: basecontrol.cxx:99
rtl::Reference< OConnectionPointContainerHelper > m_aConnectionPointContainer
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &xToolkit, const css::uno::Reference< css::awt::XWindowPeer > &xParent) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
get information about supported interfaces @seealso XTypeProvider
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL unadvise(const css::uno::Type &aType, const css::uno::Reference< css::uno::XInterface > &xListener) override
virtual void SAL_CALL acquire() noexcept override
increment refcount @seealso XInterface @seealso release() @onerror A RuntimeException is thrown.
OUString SAL_CALL getImplementationName() override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
FrameControl(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual sal_Bool SAL_CALL setGraphics(const css::uno::Reference< css::awt::XGraphics > &xDevice) override
virtual ~FrameControl() override
virtual css::uno::Reference< css::lang::XConnectionPoint > SAL_CALL queryConnectionPoint(const css::uno::Type &aType) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getConnectionPointTypes() override
virtual css::awt::WindowDescriptor impl_getWindowDescriptor(const css::uno::Reference< css::awt::XWindowPeer > &xParentPeer) override
virtual void SAL_CALL advise(const css::uno::Type &aType, const css::uno::Reference< css::uno::XInterface > &xListener) override
virtual css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics() override
virtual void SAL_CALL release() noexcept override
decrement refcount @seealso XInterface @seealso acquire() @onerror A RuntimeException is thrown.
void impl_createFrame(const css::uno::Reference< css::awt::XWindowPeer > &xPeer, const OUString &sURL, const css::uno::Sequence< css::beans::PropertyValue > &seqArguments)
css::uno::Reference< css::frame::XFrame2 > m_xFrame
css::uno::Sequence< css::beans::PropertyValue > m_seqLoaderArguments
virtual sal_Bool SAL_CALL setModel(const css::uno::Reference< css::awt::XControlModel > &xModel) override
virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override
URL aURL
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_UnoControls_FrameControl_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::mutex m_aMutex
Type
OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper
sal_Int32 nHandle
unsigned char sal_Bool