Line data Source code
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 <sal/config.h>
21 :
22 : #include <com/sun/star/frame/XDispatch.hpp>
23 : #include <com/sun/star/frame/Frame.hpp>
24 : #include <com/sun/star/frame/XFrame2.hpp>
25 : #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
26 : #include <com/sun/star/util/URLTransformer.hpp>
27 : #include <com/sun/star/util/XURLTransformer.hpp>
28 : #include <com/sun/star/util/XCloseable.hpp>
29 : #include <com/sun/star/lang/XEventListener.hpp>
30 : #include <com/sun/star/lang/XServiceInfo.hpp>
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33 : #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 :
35 : #include <cppuhelper/implbase6.hxx>
36 : #include <cppuhelper/supportsservice.hxx>
37 : #include <rtl/ref.hxx>
38 : #include <svtools/miscopt.hxx>
39 : #include <svl/ownlist.hxx>
40 : #include <svl/itemprop.hxx>
41 : #include <sfx2/frmdescr.hxx>
42 : #include <sfx2/sfxdlg.hxx>
43 : #include <sfx2/sfxsids.hrc>
44 : #include <toolkit/helper/vclunohelper.hxx>
45 : #include <vcl/window.hxx>
46 :
47 : using namespace ::com::sun::star;
48 :
49 : namespace {
50 :
51 : class IFrameObject : public ::cppu::WeakImplHelper6 <
52 : css::util::XCloseable,
53 : css::lang::XEventListener,
54 : css::frame::XSynchronousFrameLoader,
55 : css::ui::dialogs::XExecutableDialog,
56 : css::lang::XServiceInfo,
57 : css::beans::XPropertySet >
58 : {
59 : css::uno::Reference < css::uno::XComponentContext > mxContext;
60 : css::uno::Reference < css::frame::XFrame2 > mxFrame;
61 : css::uno::Reference < css::embed::XEmbeddedObject > mxObj;
62 : SfxItemPropertyMap maPropMap;
63 : SfxFrameDescriptor maFrmDescr;
64 :
65 : public:
66 : IFrameObject(const css::uno::Reference < css::uno::XComponentContext>& rxContext, const css::uno::Sequence< css::uno::Any >& aArguments)
67 : throw (css::uno::Exception, css::uno::RuntimeException);
68 : virtual ~IFrameObject();
69 :
70 0 : virtual OUString SAL_CALL getImplementationName()
71 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
72 : {
73 0 : return OUString("com.sun.star.comp.sfx2.IFrameObject");
74 : }
75 :
76 0 : virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
77 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
78 : {
79 0 : return cppu::supportsService(this, ServiceName);
80 : }
81 :
82 0 : virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
83 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
84 : {
85 0 : css::uno::Sequence< OUString > aSeq(1);
86 0 : aSeq[0] = OUString("com.sun.star.frame.SpecialEmbeddedObject");
87 0 : return aSeq;
88 : }
89 :
90 : virtual sal_Bool SAL_CALL load( const css::uno::Sequence < css::beans::PropertyValue >& lDescriptor,
91 : const css::uno::Reference < css::frame::XFrame >& xFrame ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
92 : virtual void SAL_CALL cancel() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
93 : virtual void SAL_CALL close( sal_Bool bDeliverOwnership ) throw( css::util::CloseVetoException, css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
94 : virtual void SAL_CALL addCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
95 : virtual void SAL_CALL removeCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
96 : virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
97 : virtual void SAL_CALL setTitle( const OUString& aTitle ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 : virtual ::sal_Int16 SAL_CALL execute( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
99 : virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
100 : virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
101 : virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
102 : virtual void SAL_CALL addVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
103 : virtual void SAL_CALL removeVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
104 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 : };
107 :
108 0 : class IFrameWindow_Impl : public vcl::Window
109 : {
110 : uno::Reference < frame::XFrame2 > mxFrame;
111 :
112 : public:
113 : IFrameWindow_Impl( vcl::Window *pParent,
114 : bool bHasBorder,
115 : WinBits nWinBits = 0 );
116 : };
117 :
118 0 : IFrameWindow_Impl::IFrameWindow_Impl( vcl::Window *pParent, bool bHasBorder, WinBits nWinBits )
119 0 : : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
120 : {
121 0 : if ( !bHasBorder )
122 0 : SetBorderStyle( WindowBorderStyle::NOBORDER );
123 : else
124 0 : SetBorderStyle( WindowBorderStyle::NORMAL );
125 0 : }
126 :
127 : #define PROPERTY_UNBOUND 0
128 :
129 : #define WID_FRAME_URL 1
130 : #define WID_FRAME_NAME 2
131 : #define WID_FRAME_IS_AUTO_SCROLL 3
132 : #define WID_FRAME_IS_SCROLLING_MODE 4
133 : #define WID_FRAME_IS_BORDER 5
134 : #define WID_FRAME_IS_AUTO_BORDER 6
135 : #define WID_FRAME_MARGIN_WIDTH 7
136 : #define WID_FRAME_MARGIN_HEIGHT 8
137 :
138 2 : const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
139 : {
140 : static const SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
141 : {
142 2 : { OUString("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, ::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
143 2 : { OUString("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, ::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
144 2 : { OUString("FrameIsBorder"), WID_FRAME_IS_BORDER, ::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
145 2 : { OUString("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE,::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
146 2 : { OUString("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, cppu::UnoType<sal_Int32>::get(), PROPERTY_UNBOUND, 0 },
147 2 : { OUString("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, cppu::UnoType<sal_Int32>::get(), PROPERTY_UNBOUND, 0 },
148 2 : { OUString("FrameName"), WID_FRAME_NAME, cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
149 2 : { OUString("FrameURL"), WID_FRAME_URL, cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
150 : { OUString(), 0, css::uno::Type(), 0, 0 }
151 20 : };
152 2 : return aIFramePropertyMap_Impl;
153 : }
154 :
155 2 : IFrameObject::IFrameObject(const uno::Reference < uno::XComponentContext >& rxContext, const css::uno::Sequence< css::uno::Any >& aArguments)
156 : throw ( uno::Exception, uno::RuntimeException )
157 : : mxContext( rxContext )
158 2 : , maPropMap( lcl_GetIFramePropertyMap_Impl() )
159 : {
160 2 : if ( aArguments.getLength() )
161 2 : aArguments[0] >>= mxObj;
162 2 : }
163 :
164 4 : IFrameObject::~IFrameObject()
165 : {
166 4 : }
167 :
168 0 : sal_Bool SAL_CALL IFrameObject::load(
169 : const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
170 : const uno::Reference < frame::XFrame >& xFrame )
171 : throw( uno::RuntimeException, std::exception )
172 : {
173 0 : if ( SvtMiscOptions().IsPluginsEnabled() )
174 : {
175 : DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
176 0 : vcl::Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
177 0 : IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
178 0 : pWin->SetSizePixel( pParent->GetOutputSizePixel() );
179 0 : pWin->SetBackground();
180 0 : pWin->Show();
181 :
182 0 : uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
183 0 : xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
184 :
185 : // we must destroy the IFrame before the parent is destroyed
186 0 : xWindow->addEventListener( this );
187 :
188 0 : mxFrame = frame::Frame::create( mxContext );
189 0 : uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
190 0 : mxFrame->initialize( xWin );
191 0 : mxFrame->setName( maFrmDescr.GetName() );
192 :
193 0 : uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
194 0 : if ( xFramesSupplier.is() )
195 0 : mxFrame->setCreator( xFramesSupplier );
196 :
197 0 : util::URL aTargetURL;
198 0 : aTargetURL.Complete = OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
199 0 : uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( mxContext ) );
200 0 : xTrans->parseStrict( aTargetURL );
201 :
202 0 : uno::Sequence < beans::PropertyValue > aProps(2);
203 0 : aProps[0].Name = "PluginMode";
204 0 : aProps[0].Value <<= (sal_Int16) 2;
205 0 : aProps[1].Name = "ReadOnly";
206 0 : aProps[1].Value <<= true;
207 0 : uno::Reference < frame::XDispatch > xDisp = mxFrame->queryDispatch( aTargetURL, "_self", 0 );
208 0 : if ( xDisp.is() )
209 0 : xDisp->dispatch( aTargetURL, aProps );
210 :
211 0 : return sal_True;
212 : }
213 :
214 0 : return sal_False;
215 : }
216 :
217 0 : void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException, std::exception )
218 : {
219 : try
220 : {
221 0 : uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
222 0 : if ( xClose.is() )
223 0 : xClose->close( sal_True );
224 0 : mxFrame = 0;
225 : }
226 0 : catch (const uno::Exception&)
227 : {
228 : }
229 0 : }
230 :
231 2 : void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException, std::exception )
232 : {
233 2 : }
234 :
235 2 : void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException, std::exception )
236 : {
237 2 : }
238 :
239 0 : void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException, std::exception )
240 : {
241 0 : }
242 :
243 0 : void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException, std::exception)
244 : {
245 0 : cancel();
246 0 : }
247 :
248 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException, std::exception )
249 : {
250 0 : static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
251 0 : return xInfo;
252 : }
253 :
254 12 : void SAL_CALL IFrameObject::setPropertyValue(const OUString& aPropertyName, const uno::Any& aAny)
255 : throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
256 : {
257 12 : const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
258 12 : if( !pEntry )
259 0 : throw beans::UnknownPropertyException();
260 12 : switch( pEntry->nWID )
261 : {
262 : case WID_FRAME_URL:
263 : {
264 2 : OUString aURL;
265 2 : aAny >>= aURL;
266 2 : maFrmDescr.SetURL( aURL );
267 : }
268 2 : break;
269 : case WID_FRAME_NAME:
270 : {
271 2 : OUString aName;
272 2 : if ( aAny >>= aName )
273 2 : maFrmDescr.SetName( aName );
274 : }
275 2 : break;
276 : case WID_FRAME_IS_AUTO_SCROLL:
277 : {
278 : bool bIsAutoScroll;
279 2 : if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
280 2 : maFrmDescr.SetScrollingMode( ScrollingAuto );
281 : }
282 2 : break;
283 : case WID_FRAME_IS_SCROLLING_MODE:
284 : {
285 : bool bIsScroll;
286 0 : if ( aAny >>= bIsScroll )
287 0 : maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
288 : }
289 0 : break;
290 : case WID_FRAME_IS_BORDER:
291 : {
292 : bool bIsBorder;
293 2 : if ( aAny >>= bIsBorder )
294 2 : maFrmDescr.SetFrameBorder( bIsBorder );
295 : }
296 2 : break;
297 : case WID_FRAME_IS_AUTO_BORDER:
298 : {
299 : bool bIsAutoBorder;
300 0 : if ( (aAny >>= bIsAutoBorder) )
301 : {
302 0 : bool bBorder = maFrmDescr.IsFrameBorderOn();
303 0 : maFrmDescr.ResetBorder();
304 0 : if ( bIsAutoBorder )
305 0 : maFrmDescr.SetFrameBorder( bBorder );
306 : }
307 : }
308 0 : break;
309 : case WID_FRAME_MARGIN_WIDTH:
310 : {
311 2 : sal_Int32 nMargin = 0;
312 2 : Size aSize = maFrmDescr.GetMargin();
313 2 : if ( aAny >>= nMargin )
314 : {
315 2 : aSize.Width() = nMargin;
316 2 : maFrmDescr.SetMargin( aSize );
317 : }
318 : }
319 2 : break;
320 : case WID_FRAME_MARGIN_HEIGHT:
321 : {
322 2 : sal_Int32 nMargin = 0;
323 2 : Size aSize = maFrmDescr.GetMargin();
324 2 : if ( aAny >>= nMargin )
325 : {
326 2 : aSize.Height() = nMargin;
327 2 : maFrmDescr.SetMargin( aSize );
328 : }
329 : }
330 2 : break;
331 : default: ;
332 : }
333 12 : }
334 :
335 0 : uno::Any SAL_CALL IFrameObject::getPropertyValue(const OUString& aPropertyName)
336 : throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
337 : {
338 0 : const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
339 0 : if( !pEntry )
340 0 : throw beans::UnknownPropertyException();
341 0 : uno::Any aAny;
342 0 : switch( pEntry->nWID )
343 : {
344 : case WID_FRAME_URL:
345 : {
346 0 : aAny <<= OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
347 : }
348 0 : break;
349 : case WID_FRAME_NAME:
350 : {
351 0 : aAny <<= OUString( maFrmDescr.GetName() );
352 : }
353 0 : break;
354 : case WID_FRAME_IS_AUTO_SCROLL:
355 : {
356 0 : bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
357 0 : aAny <<= bIsAutoScroll;
358 : }
359 0 : break;
360 : case WID_FRAME_IS_SCROLLING_MODE:
361 : {
362 0 : bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
363 0 : aAny <<= bIsScroll;
364 : }
365 0 : break;
366 : case WID_FRAME_IS_BORDER:
367 : {
368 0 : bool bIsBorder = maFrmDescr.IsFrameBorderOn();
369 0 : aAny <<= bIsBorder;
370 : }
371 0 : break;
372 : case WID_FRAME_IS_AUTO_BORDER:
373 : {
374 0 : bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
375 0 : aAny <<= bIsAutoBorder;
376 : }
377 0 : break;
378 : case WID_FRAME_MARGIN_WIDTH:
379 : {
380 0 : aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
381 : }
382 0 : break;
383 : case WID_FRAME_MARGIN_HEIGHT:
384 : {
385 0 : aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
386 : }
387 : default: ;
388 : }
389 0 : return aAny;
390 : }
391 :
392 0 : void SAL_CALL IFrameObject::addPropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
393 : {
394 0 : }
395 :
396 0 : void SAL_CALL IFrameObject::removePropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
397 : {
398 0 : }
399 :
400 0 : void SAL_CALL IFrameObject::addVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
401 : {
402 0 : }
403 :
404 0 : void SAL_CALL IFrameObject::removeVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
405 : {
406 0 : }
407 :
408 0 : ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException, std::exception)
409 : {
410 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
411 0 : VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, ".uno:InsertObjectFloatingFrame", mxObj );
412 0 : if ( pDlg )
413 0 : pDlg->Execute();
414 0 : return 0;
415 : }
416 :
417 0 : void SAL_CALL IFrameObject::setTitle( const OUString& ) throw (::com::sun::star::uno::RuntimeException, std::exception)
418 : {
419 0 : }
420 :
421 : }
422 :
423 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
424 2 : com_sun_star_comp_sfx2_IFrameObject_get_implementation(
425 : css::uno::XComponentContext *context,
426 : css::uno::Sequence<css::uno::Any> const &arguments)
427 : {
428 2 : return cppu::acquire(new IFrameObject(context, arguments));
429 951 : }
430 :
431 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|