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 )
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 {
145 if ( SvtMiscOptions().IsPluginsEnabled() )
146 {
147 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
148 ::rtl::OUString sURL( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
149 // Obtain authorization from the current document, that is: our mxObj'x "client site"
150 uno::Reference< com::sun::star::document::XLinkAuthorizer > xLinkAuthorizer;
151 uno::Reference< com::sun::star::lang::XComponent > xComponent;
152 uno::Reference< com::sun::star::embed::XComponentSupplier > xCompSupplier( mxObj->getClientSite(), uno::UNO_QUERY );
153 if ( xCompSupplier.is() ) {
154 xComponent.set( xCompSupplier->getComponent(), uno::UNO_QUERY );
155 if ( xComponent.is() ) {
156 xLinkAuthorizer.set( xComponent, uno::UNO_QUERY );
157 }
158 }
159 if ( xLinkAuthorizer.is() ) {
160 if ( !xLinkAuthorizer->authorizeLinks( sURL ) )
161 return sal_False;
162 }
163 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
164 IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
165 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
166 pWin->SetBackground();
167 pWin->Show();
168
169 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
170 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
171
172 // we must destroy the IFrame before the parent is destroyed
173 xWindow->addEventListener( this );
174
175 mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ) ),
176 uno::UNO_QUERY );
177 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
178 mxFrame->initialize( xWin );
179 mxFrame->setName( maFrmDescr.GetName() );
180
181 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
182 if ( xFramesSupplier.is() )
183 mxFrame->setCreator( xFramesSupplier );
184
185 uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
186
187 util::URL aTargetURL;
188 aTargetURL.Complete = sURL;
189 uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
190 xTrans->parseStrict( aTargetURL );
191
192 uno::Sequence < beans::PropertyValue > aProps(2);
193 aProps[0].Name = ::rtl::OUString::createFromAscii("PluginMode");
194 aProps[0].Value <<= (sal_Int16) 2;
195 aProps[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
196 aProps[1].Value <<= (sal_Bool) sal_True;
197 uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_self"), 0 );
198 if ( xDisp.is() )
199 xDisp->dispatch( aTargetURL, aProps );
200
201 return sal_True;
202 }
203
204 return sal_False;
205 }
206
cancel()207 void SAL_CALL IFrameObject::cancel()
208 {
209 try
210 {
211 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
212 if ( xClose.is() )
213 xClose->close( sal_True );
214 mxFrame = 0;
215 }
216 catch ( uno::Exception& )
217 {}
218 }
219
close(sal_Bool)220 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ )
221 {
222 }
223
addCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)224 void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& )
225 {
226 }
227
removeCloseListener(const com::sun::star::uno::Reference<com::sun::star::util::XCloseListener> &)228 void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& )
229 {
230 }
231
disposing(const com::sun::star::lang::EventObject &)232 void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& )
233 {
234 cancel();
235 }
236
getPropertySetInfo()237 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo()
238 {
239 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
240 return xInfo;
241 }
242
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aAny)243 void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
244 {
245 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
246 if( !pEntry )
247 throw beans::UnknownPropertyException();
248 switch( pEntry->nWID )
249 {
250 case WID_FRAME_URL:
251 {
252 ::rtl::OUString aURL;
253 aAny >>= aURL;
254 maFrmDescr.SetURL( String(aURL) );
255 }
256 break;
257 case WID_FRAME_NAME:
258 {
259 ::rtl::OUString aName;
260 if ( aAny >>= aName )
261 maFrmDescr.SetName( aName );
262 }
263 break;
264 case WID_FRAME_IS_AUTO_SCROLL:
265 {
266 sal_Bool bIsAutoScroll = sal_Bool();
267 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
268 maFrmDescr.SetScrollingMode( ScrollingAuto );
269 }
270 break;
271 case WID_FRAME_IS_SCROLLING_MODE:
272 {
273 sal_Bool bIsScroll = sal_Bool();
274 if ( aAny >>= bIsScroll )
275 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
276 }
277 break;
278 case WID_FRAME_IS_BORDER:
279 {
280 sal_Bool bIsBorder = sal_Bool();
281 if ( aAny >>= bIsBorder )
282 maFrmDescr.SetFrameBorder( bIsBorder );
283 }
284 break;
285 case WID_FRAME_IS_AUTO_BORDER:
286 {
287 sal_Bool bIsAutoBorder = sal_Bool();
288 if ( (aAny >>= bIsAutoBorder) )
289 {
290 sal_Bool bBorder = maFrmDescr.IsFrameBorderOn();
291 maFrmDescr.ResetBorder();
292 if ( bIsAutoBorder )
293 maFrmDescr.SetFrameBorder( bBorder );
294 }
295 }
296 break;
297 case WID_FRAME_MARGIN_WIDTH:
298 {
299 sal_Int32 nMargin = 0;
300 Size aSize = maFrmDescr.GetMargin();
301 if ( aAny >>= nMargin )
302 {
303 aSize.Width() = nMargin;
304 maFrmDescr.SetMargin( aSize );
305 }
306 }
307 break;
308 case WID_FRAME_MARGIN_HEIGHT:
309 {
310 sal_Int32 nMargin = 0;
311 Size aSize = maFrmDescr.GetMargin();
312 if ( aAny >>= nMargin )
313 {
314 aSize.Height() = nMargin;
315 maFrmDescr.SetMargin( aSize );
316 }
317 }
318 break;
319 default: ;
320 }
321 }
322
getPropertyValue(const::rtl::OUString & aPropertyName)323 uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
324 {
325 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
326 if( !pEntry )
327 throw beans::UnknownPropertyException();
328 uno::Any aAny;
329 switch( pEntry->nWID )
330 {
331 case WID_FRAME_URL:
332 {
333 aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
334 }
335 break;
336 case WID_FRAME_NAME:
337 {
338 aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
339 }
340 break;
341 case WID_FRAME_IS_AUTO_SCROLL:
342 {
343 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
344 aAny <<= bIsAutoScroll;
345 }
346 break;
347 case WID_FRAME_IS_SCROLLING_MODE:
348 {
349 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
350 aAny <<= bIsScroll;
351 }
352 break;
353 case WID_FRAME_IS_BORDER:
354 {
355 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
356 aAny <<= bIsBorder;
357 }
358 break;
359 case WID_FRAME_IS_AUTO_BORDER:
360 {
361 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
362 aAny <<= bIsAutoBorder;
363 }
364 break;
365 case WID_FRAME_MARGIN_WIDTH:
366 {
367 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
368 }
369 break;
370 case WID_FRAME_MARGIN_HEIGHT:
371 {
372 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
373 }
374 default: ;
375 }
376 return aAny;
377 }
378
addPropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)379 void SAL_CALL IFrameObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & )
380 {
381 }
382
removePropertyChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertyChangeListener> &)383 void SAL_CALL IFrameObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & )
384 {
385 }
386
addVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)387 void SAL_CALL IFrameObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & )
388 {
389 }
390
removeVetoableChangeListener(const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::beans::XVetoableChangeListener> &)391 void SAL_CALL IFrameObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & )
392 {
393 }
394
execute()395 ::sal_Int16 SAL_CALL IFrameObject::execute()
396 {
397 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
398 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, rtl::OUString::createFromAscii(".uno:InsertObjectFloatingFrame"), mxObj );
399 if ( pDlg )
400 pDlg->Execute();
401 return 0;
402 }
403
setTitle(const::rtl::OUString &)404 void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& )
405 {
406 }
407
408 }
409