1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26
27 #include "iframe.hxx"
28 #include <sfx2/sfxdlg.hxx>
29 #include <sfx2/sfxsids.hrc>
30 #include <com/sun/star/document/XLinkAuthorizer.hpp>
31 #include <com/sun/star/frame/XDesktop.hpp>
32 #include <com/sun/star/frame/XDispatchProvider.hpp>
33 #include <com/sun/star/frame/XDispatch.hpp>
34 #include <com/sun/star/frame/XFramesSupplier.hpp>
35 #include <com/sun/star/util/XURLTransformer.hpp>
36
37 #include <tools/urlobj.hxx>
38 #include <tools/debug.hxx>
39 #include <rtl/ustring.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <ucbhelper/simpleinteractionrequest.hxx>
42 #include <svtools/miscopt.hxx>
43 #include <vcl/window.hxx>
44
45 using namespace ::com::sun::star;
46
47 namespace sfx2
48 {
49
50 class IFrameWindow_Impl : public Window
51 {
52 uno::Reference < frame::XFrame > mxFrame;
53 sal_Bool bActive;
54 sal_Bool bBorder;
55
56 public:
57 IFrameWindow_Impl( Window *pParent,
58 sal_Bool bHasBorder,
59 WinBits nWinBits = 0 );
60
61 public:
62 void SetBorder( sal_Bool bNewBorder = sal_True );
HasBorder() const63 sal_Bool HasBorder() const { return bBorder; }
64 };
65
IFrameWindow_Impl(Window * pParent,sal_Bool bHasBorder,WinBits nWinBits)66 IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits )
67 : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
68 , bActive(sal_False)
69 , bBorder(bHasBorder)
70 {
71 if ( !bHasBorder )
72 SetBorderStyle( WINDOW_BORDER_NOBORDER );
73 else
74 SetBorderStyle( WINDOW_BORDER_NORMAL );
75 //SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
76 }
77
SetBorder(sal_Bool bNewBorder)78 void IFrameWindow_Impl::SetBorder( sal_Bool bNewBorder )
79 {
80 if ( bBorder != bNewBorder )
81 {
82 Size aSize = GetSizePixel();
83 bBorder = bNewBorder;
84 if ( bBorder )
85 SetBorderStyle( WINDOW_BORDER_NORMAL );
86 else
87 SetBorderStyle( WINDOW_BORDER_NOBORDER );
88 if ( GetSizePixel() != aSize )
89 SetSizePixel( aSize );
90 }
91 }
92
93 #define PROPERTY_UNBOUND 0
94
95 #define WID_FRAME_URL 1
96 #define WID_FRAME_NAME 2
97 #define WID_FRAME_IS_AUTO_SCROLL 3
98 #define WID_FRAME_IS_SCROLLING_MODE 4
99 #define WID_FRAME_IS_BORDER 5
100 #define WID_FRAME_IS_AUTO_BORDER 6
101 #define WID_FRAME_MARGIN_WIDTH 7
102 #define WID_FRAME_MARGIN_HEIGHT 8
103
lcl_GetIFramePropertyMap_Impl()104 const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
105 {
106 static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
107 {
108 { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
109 { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
110 { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
111 { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
112 { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
113 { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
114 { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
115 { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
116 {0,0,0,0,0,0}
117 };
118 return aIFramePropertyMap_Impl;
119 }
120
121 SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
122 SFX_IMPL_SINGLEFACTORY( IFrameObject );
123
IFrameObject(const uno::Reference<lang::XMultiServiceFactory> & rFact)124 IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
125 : mxFact( rFact )
126 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
127 {
128 }
129
~IFrameObject()130 IFrameObject::~IFrameObject()
131 {
132 }
133
134
initialize(const uno::Sequence<uno::Any> & aArguments)135 void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
136 {
137 if ( aArguments.getLength() )
138 aArguments[0] >>= mxObj;
139 }
140
load(const uno::Sequence<com::sun::star::beans::PropertyValue> &,const uno::Reference<frame::XFrame> & xFrame)141 sal_Bool SAL_CALL IFrameObject::load(
142 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
143 const uno::Reference < frame::XFrame >& xFrame )
144 throw( uno::RuntimeException )
145 {
146 if ( SvtMiscOptions().IsPluginsEnabled() )
147 {
148 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
149 ::rtl::OUString sURL( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
150 // Obtain authorization from the current document, that is: our mxObj'x "client site"
151 uno::Reference< com::sun::star::document::XLinkAuthorizer > xLinkAuthorizer;
152 uno::Reference< com::sun::star::lang::XComponent > xComponent;
153 uno::Reference< com::sun::star::embed::XComponentSupplier > xCompSupplier( mxObj->getClientSite(), uno::UNO_QUERY );
154 if ( xCompSupplier.is() ) {
155 xComponent.set( xCompSupplier->getComponent(), uno::UNO_QUERY );
156 if ( xComponent.is() ) {
157 xLinkAuthorizer.set( xComponent, uno::UNO_QUERY );
158 }
159 }
160 if ( xLinkAuthorizer.is() ) {
161 if ( !xLinkAuthorizer->authorizeLinks( sURL ) )
162 return sal_False;
163 }
164 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
165 IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
166 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
167 pWin->SetBackground();
168 pWin->Show();
169
170 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
171 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
172
173 // we must destroy the IFrame before the parent is destroyed
174 xWindow->addEventListener( this );
175
176 mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ) ),
177 uno::UNO_QUERY );
178 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
179 mxFrame->initialize( xWin );
180 mxFrame->setName( maFrmDescr.GetName() );
181
182 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
183 if ( xFramesSupplier.is() )
184 mxFrame->setCreator( xFramesSupplier );
185
186 uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
187
188 util::URL aTargetURL;
189 aTargetURL.Complete = sURL;
190 uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
191 xTrans->parseStrict( aTargetURL );
192
193 uno::Sequence < beans::PropertyValue > aProps(2);
194 aProps[0].Name = ::rtl::OUString::createFromAscii("PluginMode");
195 aProps[0].Value <<= (sal_Int16) 2;
196 aProps[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
197 aProps[1].Value <<= (sal_Bool) sal_True;
198 uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_self"), 0 );
199 if ( xDisp.is() )
200 xDisp->dispatch( aTargetURL, aProps );
201
202 return sal_True;
203 }
204
205 return sal_False;
206 }
207
cancel()208 void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
209 {
210 try
211 {
212 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
213 if ( xClose.is() )
214 xClose->close( sal_True );
215 mxFrame = 0;
216 }
217 catch ( uno::Exception& )
218 {}
219 }
220
close(sal_Bool)221 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
222 {
223 }
224
addCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)225 void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
226 {
227 }
228
removeCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)229 void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
230 {
231 }
232
disposing(const com::sun::star::lang::EventObject &)233 void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
234 {
235 cancel();
236 }
237
getPropertySetInfo()238 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
239 {
240 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
241 return xInfo;
242 }
243
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aAny)244 void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
245 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
246 {
247 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
248 if( !pEntry )
249 throw beans::UnknownPropertyException();
250 switch( pEntry->nWID )
251 {
252 case WID_FRAME_URL:
253 {
254 ::rtl::OUString aURL;
255 aAny >>= aURL;
256 maFrmDescr.SetURL( String(aURL) );
257 }
258 break;
259 case WID_FRAME_NAME:
260 {
261 ::rtl::OUString aName;
262 if ( aAny >>= aName )
263 maFrmDescr.SetName( aName );
264 }
265 break;
266 case WID_FRAME_IS_AUTO_SCROLL:
267 {
268 sal_Bool bIsAutoScroll = sal_Bool();
269 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
270 maFrmDescr.SetScrollingMode( ScrollingAuto );
271 }
272 break;
273 case WID_FRAME_IS_SCROLLING_MODE:
274 {
275 sal_Bool bIsScroll = sal_Bool();
276 if ( aAny >>= bIsScroll )
277 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
278 }
279 break;
280 case WID_FRAME_IS_BORDER:
281 {
282 sal_Bool bIsBorder = sal_Bool();
283 if ( aAny >>= bIsBorder )
284 maFrmDescr.SetFrameBorder( bIsBorder );
285 }
286 break;
287 case WID_FRAME_IS_AUTO_BORDER:
288 {
289 sal_Bool bIsAutoBorder = sal_Bool();
290 if ( (aAny >>= bIsAutoBorder) )
291 {
292 sal_Bool bBorder = maFrmDescr.IsFrameBorderOn();
293 maFrmDescr.ResetBorder();
294 if ( bIsAutoBorder )
295 maFrmDescr.SetFrameBorder( bBorder );
296 }
297 }
298 break;
299 case WID_FRAME_MARGIN_WIDTH:
300 {
301 sal_Int32 nMargin = 0;
302 Size aSize = maFrmDescr.GetMargin();
303 if ( aAny >>= nMargin )
304 {
305 aSize.Width() = nMargin;
306 maFrmDescr.SetMargin( aSize );
307 }
308 }
309 break;
310 case WID_FRAME_MARGIN_HEIGHT:
311 {
312 sal_Int32 nMargin = 0;
313 Size aSize = maFrmDescr.GetMargin();
314 if ( aAny >>= nMargin )
315 {
316 aSize.Height() = nMargin;
317 maFrmDescr.SetMargin( aSize );
318 }
319 }
320 break;
321 default: ;
322 }
323 }
324
getPropertyValue(const::rtl::OUString & aPropertyName)325 uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
326 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
327 {
328 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
329 if( !pEntry )
330 throw beans::UnknownPropertyException();
331 uno::Any aAny;
332 switch( pEntry->nWID )
333 {
334 case WID_FRAME_URL:
335 {
336 aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
337 }
338 break;
339 case WID_FRAME_NAME:
340 {
341 aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
342 }
343 break;
344 case WID_FRAME_IS_AUTO_SCROLL:
345 {
346 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
347 aAny <<= bIsAutoScroll;
348 }
349 break;
350 case WID_FRAME_IS_SCROLLING_MODE:
351 {
352 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
353 aAny <<= bIsScroll;
354 }
355 break;
356 case WID_FRAME_IS_BORDER:
357 {
358 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
359 aAny <<= bIsBorder;
360 }
361 break;
362 case WID_FRAME_IS_AUTO_BORDER:
363 {
364 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
365 aAny <<= bIsAutoBorder;
366 }
367 break;
368 case WID_FRAME_MARGIN_WIDTH:
369 {
370 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
371 }
372 break;
373 case WID_FRAME_MARGIN_HEIGHT:
374 {
375 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
376 }
377 default: ;
378 }
379 return aAny;
380 }
381
addPropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)382 void SAL_CALL IFrameObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
383 {
384 }
385
removePropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)386 void SAL_CALL IFrameObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
387 {
388 }
389
addVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)390 void SAL_CALL IFrameObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
391 {
392 }
393
removeVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)394 void SAL_CALL IFrameObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
395 {
396 }
397
execute()398 ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException)
399 {
400 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
401 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, rtl::OUString::createFromAscii(".uno:InsertObjectFloatingFrame"), mxObj );
402 if ( pDlg )
403 pDlg->Execute();
404 return 0;
405 }
406
setTitle(const::rtl::OUString &)407 void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)
408 {
409 }
410
411 }
412