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 <com/sun/star/beans/XPropertySet.hpp>
21 : #include <com/sun/star/beans/PropertyValue.hpp>
22 : #include <com/sun/star/embed/EmbedStates.hpp>
23 : #include <com/sun/star/embed/XInsertObjectDialog.hpp>
24 : #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
25 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 : #include <com/sun/star/lang/XInitialization.hpp>
27 : #include <com/sun/star/task/InteractionHandler.hpp>
28 : #include <com/sun/star/ucb/CommandAbortedException.hpp>
29 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31 : #include <com/sun/star/ui/dialogs/FilePicker.hpp>
32 : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
33 : #include <comphelper/processfactory.hxx>
34 :
35 : #include "insdlg.hxx"
36 : #include <dialmgr.hxx>
37 : #include <svtools/sores.hxx>
38 :
39 : #include <stdio.h>
40 : #include <tools/urlobj.hxx>
41 : #include <tools/debug.hxx>
42 : #include <svl/urihelper.hxx>
43 : #include <vcl/button.hxx>
44 : #include <vcl/fixed.hxx>
45 : #include <vcl/group.hxx>
46 : #include <vcl/layout.hxx>
47 : #include <vcl/lstbox.hxx>
48 : #include <vcl/msgbox.hxx>
49 : #include <vcl/svapp.hxx>
50 : #include <comphelper/classids.hxx>
51 : #include <sfx2/frmdescr.hxx>
52 : #include <sfx2/viewsh.hxx>
53 : #include <sfx2/filedlghelper.hxx>
54 : #include <svl/ownlist.hxx>
55 : #include <comphelper/seqstream.hxx>
56 :
57 : #include "cuires.hrc"
58 :
59 : #include <osl/file.hxx>
60 :
61 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
62 : #include <com/sun/star/container/XNameAccess.hpp>
63 : #include <vcl/settings.hxx>
64 :
65 : using namespace ::com::sun::star;
66 : using namespace ::com::sun::star::lang;
67 : using namespace ::com::sun::star::uno;
68 : using namespace ::com::sun::star::container;
69 : using namespace ::com::sun::star::ui::dialogs;
70 :
71 :
72 0 : static OUString impl_getSvtResString( sal_uInt32 nId )
73 : {
74 0 : OUString aRet;
75 0 : ResMgr* pMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
76 0 : if( pMgr )
77 : {
78 0 : aRet = ResId( nId, *pMgr );
79 0 : delete pMgr;
80 : }
81 0 : return aRet;
82 : }
83 :
84 0 : sal_Bool InsertObjectDialog_Impl::IsCreateNew() const
85 : {
86 0 : return sal_False;
87 : }
88 :
89 0 : uno::Reference< io::XInputStream > InsertObjectDialog_Impl::GetIconIfIconified( OUString* /*pGraphicMediaType*/ )
90 : {
91 0 : return uno::Reference< io::XInputStream >();
92 : }
93 :
94 0 : InsertObjectDialog_Impl::InsertObjectDialog_Impl(Window * pParent, const OString& rID,
95 : const OUString& rUIXMLDescription,
96 : const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage)
97 : : ModalDialog(pParent, rID, rUIXMLDescription)
98 : , m_xStorage( xStorage )
99 0 : , aCnt( m_xStorage )
100 : {
101 0 : }
102 :
103 :
104 :
105 0 : IMPL_LINK_NOARG_INLINE_START(SvInsertOleDlg, DoubleClickHdl)
106 : {
107 0 : EndDialog( RET_OK );
108 0 : return 0;
109 : }
110 0 : IMPL_LINK_INLINE_END( SvInsertOleDlg, DoubleClickHdl, ListBox *, pListBox )
111 :
112 :
113 :
114 0 : IMPL_LINK_NOARG(SvInsertOleDlg, BrowseHdl)
115 : {
116 0 : Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
117 :
118 0 : Reference< XFilePicker3 > xFilePicker = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
119 :
120 : // add filter
121 : try
122 : {
123 0 : xFilePicker->appendFilter(
124 : OUString(),
125 : OUString( "*.*" )
126 0 : );
127 : }
128 0 : catch( const IllegalArgumentException& )
129 : {
130 : DBG_ASSERT( false, "caught IllegalArgumentException when registering filter\n" );
131 : }
132 :
133 0 : if( xFilePicker->execute() == ExecutableDialogResults::OK )
134 : {
135 0 : Sequence< OUString > aPathSeq( xFilePicker->getFiles() );
136 0 : INetURLObject aObj( aPathSeq[0] );
137 0 : m_pEdFilepath->SetText( aObj.PathToFileName() );
138 : }
139 :
140 0 : return 0;
141 : }
142 :
143 :
144 :
145 0 : IMPL_LINK_NOARG(SvInsertOleDlg, RadioHdl)
146 : {
147 0 : if ( m_pRbNewObject->IsChecked() )
148 : {
149 0 : m_pObjectTypeFrame->Show();
150 0 : m_pFileFrame->Hide();
151 : }
152 : else
153 : {
154 0 : m_pFileFrame->Show();
155 0 : m_pObjectTypeFrame->Hide();
156 : }
157 0 : return 0;
158 : }
159 :
160 :
161 :
162 0 : void SvInsertOleDlg::SelectDefault()
163 : {
164 0 : m_pLbObjecttype->SelectEntryPos(0);
165 0 : }
166 :
167 :
168 0 : SvInsertOleDlg::SvInsertOleDlg
169 : (
170 : Window* pParent,
171 : const Reference < embed::XStorage >& xStorage,
172 : const SvObjectServerList* pServers
173 : )
174 : : InsertObjectDialog_Impl( pParent, "InsertOLEObjectDialog", "cui/ui/insertoleobject.ui", xStorage ),
175 0 : m_pServers( pServers )
176 : {
177 0 : get(m_pRbNewObject, "createnew");
178 0 : get(m_pRbObjectFromfile, "createfromfile");
179 0 : get(m_pObjectTypeFrame, "objecttypeframe");
180 0 : get(m_pLbObjecttype, "types");
181 0 : get(m_pFileFrame, "fileframe");
182 0 : get(m_pEdFilepath, "urled");
183 0 : get(m_pBtnFilepath, "urlbtn");
184 0 : get(m_pCbFilelink, "linktofile");
185 0 : m_pLbObjecttype->SetDoubleClickHdl( LINK( this, SvInsertOleDlg, DoubleClickHdl ) );
186 0 : m_pBtnFilepath->SetClickHdl( LINK( this, SvInsertOleDlg, BrowseHdl ) );
187 0 : Link aLink( LINK( this, SvInsertOleDlg, RadioHdl ) );
188 0 : m_pRbNewObject->SetClickHdl( aLink );
189 0 : m_pRbObjectFromfile->SetClickHdl( aLink );
190 0 : m_pRbNewObject->Check( true );
191 0 : RadioHdl( NULL );
192 0 : }
193 :
194 0 : short SvInsertOleDlg::Execute()
195 : {
196 0 : short nRet = RET_OK;
197 0 : SvObjectServerList aObjS;
198 0 : if ( !m_pServers )
199 : {
200 : // if no list was provided, take the complete one
201 0 : aObjS.FillInsertObjects();
202 0 : m_pServers = &aObjS;
203 : }
204 :
205 : // fill listbox and select default
206 0 : ListBox& rBox = GetObjectTypes();
207 0 : rBox.SetUpdateMode( false );
208 0 : for ( sal_uLong i = 0; i < m_pServers->Count(); i++ )
209 0 : rBox.InsertEntry( (*m_pServers)[i].GetHumanName() );
210 0 : rBox.SetUpdateMode( true );
211 0 : SelectDefault();
212 0 : OUString aName;
213 :
214 : DBG_ASSERT( m_xStorage.is(), "No storage!");
215 0 : if ( m_xStorage.is() && ( nRet = Dialog::Execute() ) == RET_OK )
216 : {
217 0 : OUString aFileName;
218 0 : sal_Bool bLink = sal_False;
219 0 : sal_Bool bCreateNew = IsCreateNew();
220 0 : if ( bCreateNew )
221 : {
222 : // create and insert new embedded object
223 0 : OUString aServerName = rBox.GetSelectEntry();
224 0 : const SvObjectServer* pS = m_pServers->Get( aServerName );
225 0 : if ( pS )
226 : {
227 0 : if( pS->GetClassName() == SvGlobalName( SO3_OUT_CLASSID ) )
228 : {
229 : try
230 : {
231 : uno::Reference < embed::XInsertObjectDialog > xDialogCreator(
232 : embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() ),
233 0 : uno::UNO_QUERY );
234 :
235 0 : if ( xDialogCreator.is() )
236 : {
237 0 : aName = aCnt.CreateUniqueObjectName();
238 0 : embed::InsertedObjectInfo aNewInf = xDialogCreator->createInstanceByDialog(
239 : m_xStorage,
240 : aName,
241 0 : uno::Sequence < beans::PropertyValue >() );
242 :
243 : OSL_ENSURE( aNewInf.Object.is(), "The object must be created or an exception must be thrown!" );
244 0 : m_xObj = aNewInf.Object;
245 0 : for ( sal_Int32 nInd = 0; nInd < aNewInf.Options.getLength(); nInd++ )
246 0 : if ( aNewInf.Options[nInd].Name == "Icon" )
247 : {
248 0 : aNewInf.Options[nInd].Value >>= m_aIconMetaFile;
249 : }
250 0 : else if ( aNewInf.Options[nInd].Name == "IconFormat" )
251 : {
252 0 : datatransfer::DataFlavor aFlavor;
253 0 : if ( aNewInf.Options[nInd].Value >>= aFlavor )
254 0 : m_aIconMediaType = aFlavor.MimeType;
255 0 : }
256 :
257 0 : }
258 : }
259 0 : catch( ucb::CommandAbortedException& )
260 : {
261 : // the user has pressed cancel
262 : }
263 0 : catch( uno::Exception& )
264 : {
265 : // TODO: Error handling
266 : }
267 : }
268 : else
269 : {
270 : // create object with desired ClassId
271 0 : m_xObj = aCnt.CreateEmbeddedObject( pS->GetClassName().GetByteSequence(), aName );
272 : }
273 :
274 0 : if ( !m_xObj.is() )
275 : {
276 0 : if( !aFileName.isEmpty() ) // from OLE Dialog
277 : {
278 : // object couldn't be created from file
279 : // global Resource from svtools (former so3 resource)
280 0 : OUString aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE ) );
281 0 : aErr = aErr.replaceFirst( "%", aFileName );
282 0 : ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
283 : }
284 : else
285 : {
286 : // object couldn't be created
287 : // global Resource from svtools (former so3 resource)
288 0 : OUString aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE ) );
289 0 : aErr = aErr.replaceFirst( "%", aServerName );
290 0 : ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
291 : }
292 : }
293 0 : }
294 : }
295 : else
296 : {
297 0 : aFileName = GetFilePath();
298 0 : INetURLObject aURL;
299 0 : aURL.SetSmartProtocol( INET_PROT_FILE );
300 0 : aURL.SetSmartURL( aFileName );
301 0 : aFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
302 0 : bLink = IsLinked();
303 :
304 0 : if ( !aFileName.isEmpty() )
305 : {
306 : // create MediaDescriptor for file to create object from
307 0 : uno::Sequence < beans::PropertyValue > aMedium( 2 );
308 0 : aMedium[0].Name = "URL";
309 0 : aMedium[0].Value <<= OUString( aFileName );
310 :
311 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
312 : uno::Reference< task::XInteractionHandler2 > xInteraction(
313 0 : task::InteractionHandler::createWithParent(xContext, 0) );
314 :
315 0 : aMedium[1].Name = "InteractionHandler";
316 0 : aMedium[1].Value <<= xInteraction;
317 :
318 : // create object from media descriptor
319 0 : if ( bLink )
320 0 : m_xObj = aCnt.InsertEmbeddedLink( aMedium, aName );
321 : else
322 0 : m_xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
323 : }
324 :
325 0 : if ( !m_xObj.is() )
326 : {
327 : // object couldn't be created from file
328 : // global Resource from svtools (former so3 resource)
329 0 : OUString aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE ) );
330 0 : aErr = aErr.replaceFirst( "%", aFileName );
331 0 : ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
332 0 : }
333 0 : }
334 : }
335 :
336 0 : m_pServers = 0;
337 0 : return nRet;
338 : }
339 :
340 0 : uno::Reference< io::XInputStream > SvInsertOleDlg::GetIconIfIconified( OUString* pGraphicMediaType )
341 : {
342 0 : if ( m_aIconMetaFile.getLength() )
343 : {
344 0 : if ( pGraphicMediaType )
345 0 : *pGraphicMediaType = m_aIconMediaType;
346 :
347 0 : return uno::Reference< io::XInputStream >( new ::comphelper::SequenceInputStream( m_aIconMetaFile ) );
348 : }
349 :
350 0 : return uno::Reference< io::XInputStream >();
351 : }
352 :
353 0 : IMPL_LINK_NOARG(SvInsertPlugInDialog, BrowseHdl)
354 : {
355 0 : Sequence< OUString > aFilterNames, aFilterTypes;
356 : void fillNetscapePluginFilters( Sequence< OUString >& rNames, Sequence< OUString >& rTypes );
357 0 : fillNetscapePluginFilters( aFilterNames, aFilterTypes );
358 :
359 0 : Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
360 0 : Reference< XFilePicker3 > xFilePicker = ui::dialogs::FilePicker::createWithMode( xContext, ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE );
361 :
362 : // add the filters
363 : try
364 : {
365 0 : const OUString* pNames = aFilterNames.getConstArray();
366 0 : const OUString* pTypes = aFilterTypes.getConstArray();
367 0 : for( int i = 0; i < aFilterNames.getLength(); i++ )
368 0 : xFilePicker->appendFilter( pNames[i], pTypes[i] );
369 : }
370 0 : catch( IllegalArgumentException& )
371 : {
372 : DBG_ASSERT( false, "caught IllegalArgumentException when registering filter\n" );
373 : }
374 :
375 0 : if( xFilePicker->execute() == ExecutableDialogResults::OK )
376 : {
377 0 : Sequence< OUString > aPathSeq( xFilePicker->getFiles() );
378 0 : INetURLObject aObj( aPathSeq[0] );
379 0 : m_pEdFileurl->SetText(aObj.PathToFileName());
380 : }
381 :
382 0 : return 0;
383 : }
384 :
385 :
386 :
387 0 : SvInsertPlugInDialog::SvInsertPlugInDialog(Window* pParent,
388 : const uno::Reference < embed::XStorage >& xStorage)
389 : : InsertObjectDialog_Impl(pParent, "InsertPluginDialog", "cui/ui/insertplugin.ui", xStorage)
390 0 : , m_pURL(0)
391 : {
392 0 : get(m_pEdFileurl, "urled");
393 0 : get(m_pBtnFileurl, "urlbtn");
394 0 : get(m_pEdPluginsOptions, "pluginoptions");
395 0 : m_pBtnFileurl->SetClickHdl(LINK(this, SvInsertPlugInDialog, BrowseHdl));
396 0 : }
397 :
398 0 : SvInsertPlugInDialog::~SvInsertPlugInDialog()
399 : {
400 0 : delete m_pURL;
401 0 : }
402 :
403 :
404 :
405 0 : static void Plugin_ImplFillCommandSequence( const OUString& aCommands, uno::Sequence< beans::PropertyValue >& aCommandSequence )
406 : {
407 : sal_Int32 nEaten;
408 0 : SvCommandList aLst;
409 0 : aLst.AppendCommands( aCommands, &nEaten );
410 :
411 0 : const size_t nCount = aLst.size();
412 0 : aCommandSequence.realloc( nCount );
413 0 : for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
414 : {
415 0 : aCommandSequence[nIndex].Name = aLst[ nIndex ].GetCommand();
416 0 : aCommandSequence[nIndex].Handle = -1;
417 0 : aCommandSequence[nIndex].Value = makeAny( aLst[ nIndex ].GetArgument() );
418 0 : aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
419 0 : }
420 0 : }
421 :
422 0 : short SvInsertPlugInDialog::Execute()
423 : {
424 0 : short nRet = RET_OK;
425 0 : m_aCommands = OUString();
426 : DBG_ASSERT( m_xStorage.is(), "No storage!");
427 0 : if ( m_xStorage.is() && ( nRet = Dialog::Execute() ) == RET_OK )
428 : {
429 0 : if ( !m_pURL )
430 0 : m_pURL = new INetURLObject();
431 : else
432 0 : *m_pURL = INetURLObject();
433 :
434 0 : m_aCommands = GetPlugInOptions();
435 0 : OUString aURL = GetPlugInFile();
436 :
437 : // URL can be a valid and absolute URL or a system file name
438 0 : m_pURL->SetSmartProtocol( INET_PROT_FILE );
439 0 : if ( aURL.isEmpty() || m_pURL->SetSmartURL( aURL ) )
440 : {
441 : // create a plugin object
442 0 : OUString aName;
443 0 : SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
444 0 : m_xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aName );
445 : }
446 :
447 0 : if ( m_xObj.is() )
448 : {
449 : // set properties from dialog
450 0 : if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
451 0 : m_xObj->changeState( embed::EmbedStates::RUNNING );
452 :
453 0 : uno::Reference < beans::XPropertySet > xSet( m_xObj->getComponent(), uno::UNO_QUERY );
454 0 : if ( xSet.is() )
455 : {
456 0 : xSet->setPropertyValue( "PluginURL",
457 0 : makeAny( OUString( m_pURL->GetMainURL( INetURLObject::NO_DECODE ) ) ) );
458 0 : uno::Sequence< beans::PropertyValue > aCommandSequence;
459 0 : Plugin_ImplFillCommandSequence( m_aCommands, aCommandSequence );
460 0 : xSet->setPropertyValue( "PluginCommands", makeAny( aCommandSequence ) );
461 0 : }
462 : }
463 : else
464 : {
465 : // PlugIn couldn't be created
466 : // global Resource from svtools (former so3 resource)
467 0 : OUString aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_PLUGIN ) );
468 0 : aErr = aErr.replaceFirst( "%", aURL );
469 0 : ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
470 0 : }
471 : }
472 :
473 0 : return nRet;
474 : }
475 :
476 0 : SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window *pParent,
477 : const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage )
478 : : InsertObjectDialog_Impl( pParent, "InsertFloatingFrameDialog", "cui/ui/insertfloatingframe.ui",
479 0 : xStorage )
480 : {
481 0 : Init();
482 0 : }
483 :
484 0 : SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window *pParent,
485 : const uno::Reference < embed::XEmbeddedObject >& xObj )
486 : : InsertObjectDialog_Impl( pParent, "InsertFloatingFrameDialog", "cui/ui/insertfloatingframe.ui",
487 0 : uno::Reference < embed::XStorage >() )
488 : {
489 0 : m_xObj = xObj;
490 :
491 0 : Init();
492 0 : }
493 :
494 0 : void SfxInsertFloatingFrameDialog::Init()
495 : {
496 0 : get(m_pEDName, "edname");
497 0 : get(m_pEDURL, "edurl");
498 0 : get(m_pBTOpen, "buttonbrowse");
499 0 : get(m_pRBScrollingOn, "scrollbaron");
500 0 : get(m_pRBScrollingOff, "scrollbaroff");
501 0 : get(m_pRBScrollingAuto, "scrollbarauto");
502 0 : get(m_pRBFrameBorderOn, "borderon");
503 0 : get(m_pRBFrameBorderOff, "borderoff");
504 0 : get(m_pFTMarginWidth, "widthlabel");
505 0 : get(m_pNMMarginWidth, "width");
506 0 : get(m_pCBMarginWidthDefault, "defaultwidth");
507 0 : get(m_pFTMarginHeight, "heightlabel");
508 0 : get(m_pNMMarginHeight, "height");
509 0 : get(m_pCBMarginHeightDefault, "defaultheight");
510 :
511 0 : Link aLink( STATIC_LINK( this, SfxInsertFloatingFrameDialog, CheckHdl ) );
512 0 : m_pCBMarginWidthDefault->SetClickHdl( aLink );
513 0 : m_pCBMarginHeightDefault->SetClickHdl( aLink );
514 :
515 0 : m_pCBMarginWidthDefault->Check();
516 0 : m_pCBMarginHeightDefault->Check();
517 0 : m_pRBScrollingAuto->Check();
518 0 : m_pRBFrameBorderOn->Check();
519 :
520 0 : m_pBTOpen->SetClickHdl( STATIC_LINK( this, SfxInsertFloatingFrameDialog, OpenHdl ) );
521 0 : }
522 :
523 0 : short SfxInsertFloatingFrameDialog::Execute()
524 : {
525 0 : short nRet = RET_OK;
526 0 : sal_Bool bOK = sal_False;
527 0 : uno::Reference < beans::XPropertySet > xSet;
528 0 : if ( m_xObj.is() )
529 : {
530 : try
531 : {
532 0 : if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
533 0 : m_xObj->changeState( embed::EmbedStates::RUNNING );
534 0 : xSet = uno::Reference < beans::XPropertySet >( m_xObj->getComponent(), uno::UNO_QUERY );
535 0 : OUString aStr;
536 0 : uno::Any aAny = xSet->getPropertyValue( "FrameURL" );
537 0 : if ( aAny >>= aStr )
538 0 : m_pEDURL->SetText( aStr );
539 0 : aAny = xSet->getPropertyValue( "FrameName" );
540 0 : if ( aAny >>= aStr )
541 0 : m_pEDName->SetText( aStr );
542 :
543 0 : sal_Int32 nSize = SIZE_NOT_SET;
544 0 : aAny = xSet->getPropertyValue( "FrameMarginWidth" );
545 0 : aAny >>= nSize;
546 :
547 0 : if ( nSize == SIZE_NOT_SET )
548 : {
549 0 : m_pCBMarginWidthDefault->Check( true );
550 0 : m_pNMMarginWidth->SetText( OUString::number(DEFAULT_MARGIN_WIDTH) );
551 0 : m_pFTMarginWidth->Enable( false );
552 0 : m_pNMMarginWidth->Enable( false );
553 : }
554 : else
555 0 : m_pNMMarginWidth->SetText( OUString::number( nSize ) );
556 :
557 0 : aAny = xSet->getPropertyValue( "FrameMarginHeight" );
558 0 : aAny >>= nSize;
559 :
560 0 : if ( nSize == SIZE_NOT_SET )
561 : {
562 0 : m_pCBMarginHeightDefault->Check( true );
563 0 : m_pNMMarginHeight->SetText( OUString::number(DEFAULT_MARGIN_HEIGHT) );
564 0 : m_pFTMarginHeight->Enable( false );
565 0 : m_pNMMarginHeight->Enable( false );
566 : }
567 : else
568 0 : m_pNMMarginHeight->SetText( OUString::number( nSize ) );
569 :
570 0 : sal_Bool bScrollOn = sal_False;
571 0 : sal_Bool bScrollOff = sal_False;
572 0 : sal_Bool bScrollAuto = sal_False;
573 :
574 0 : sal_Bool bSet = sal_False;
575 0 : aAny = xSet->getPropertyValue( "FrameIsAutoScroll" );
576 0 : aAny >>= bSet;
577 0 : if ( !bSet )
578 : {
579 0 : aAny = xSet->getPropertyValue( "FrameIsScrollingMode" );
580 0 : aAny >>= bSet;
581 0 : bScrollOn = bSet;
582 0 : bScrollOff = !bSet;
583 : }
584 : else
585 0 : bScrollAuto = sal_True;
586 :
587 0 : m_pRBScrollingOn->Check( bScrollOn );
588 0 : m_pRBScrollingOff->Check( bScrollOff );
589 0 : m_pRBScrollingAuto->Check( bScrollAuto );
590 :
591 0 : bSet = sal_False;
592 0 : aAny = xSet->getPropertyValue( "FrameIsAutoBorder" );
593 0 : aAny >>= bSet;
594 0 : if ( !bSet )
595 : {
596 0 : aAny = xSet->getPropertyValue( "FrameIsBorder" );
597 0 : aAny >>= bSet;
598 0 : m_pRBFrameBorderOn->Check( bSet );
599 0 : m_pRBFrameBorderOff->Check( !bSet );
600 : }
601 :
602 0 : SetUpdateMode( true );
603 0 : bOK = sal_True;
604 : }
605 0 : catch ( uno::Exception& )
606 : {
607 : OSL_FAIL( "No IFrame!" );
608 : }
609 : }
610 : else
611 : {
612 : DBG_ASSERT( m_xStorage.is(), "No storage!");
613 0 : bOK = m_xStorage.is();
614 : }
615 :
616 0 : if ( bOK && ( nRet = Dialog::Execute() ) == RET_OK )
617 : {
618 0 : OUString aURL;
619 0 : if ( !m_pEDURL->GetText().isEmpty() )
620 : {
621 : // URL can be a valid and absolute URL or a system file name
622 0 : INetURLObject aObj;
623 0 : aObj.SetSmartProtocol( INET_PROT_FILE );
624 0 : if ( aObj.SetSmartURL( m_pEDURL->GetText() ) )
625 0 : aURL = aObj.GetMainURL( INetURLObject::NO_DECODE );
626 : }
627 :
628 0 : if ( !m_xObj.is() && !aURL.isEmpty() )
629 : {
630 : // create the object
631 0 : OUString aName;
632 0 : SvGlobalName aClassId( SO3_IFRAME_CLASSID );
633 0 : m_xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aName );
634 0 : if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
635 0 : m_xObj->changeState( embed::EmbedStates::RUNNING );
636 0 : xSet = uno::Reference < beans::XPropertySet >( m_xObj->getComponent(), uno::UNO_QUERY );
637 : }
638 :
639 0 : if ( m_xObj.is() )
640 : {
641 : try
642 : {
643 0 : sal_Bool bIPActive = m_xObj->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE;
644 0 : if ( bIPActive )
645 0 : m_xObj->changeState( embed::EmbedStates::RUNNING );
646 :
647 0 : OUString aName = m_pEDName->GetText();
648 0 : ScrollingMode eScroll = ScrollingNo;
649 0 : if ( m_pRBScrollingOn->IsChecked() )
650 0 : eScroll = ScrollingYes;
651 0 : if ( m_pRBScrollingOff->IsChecked() )
652 0 : eScroll = ScrollingNo;
653 0 : if ( m_pRBScrollingAuto->IsChecked() )
654 0 : eScroll = ScrollingAuto;
655 :
656 0 : sal_Bool bHasBorder = m_pRBFrameBorderOn->IsChecked();
657 :
658 : long lMarginWidth;
659 0 : if ( !m_pCBMarginWidthDefault->IsChecked() )
660 0 : lMarginWidth = (long) m_pNMMarginWidth->GetText().toInt32();
661 : else
662 0 : lMarginWidth = SIZE_NOT_SET;
663 :
664 : long lMarginHeight;
665 0 : if ( !m_pCBMarginHeightDefault->IsChecked() )
666 0 : lMarginHeight = (long) m_pNMMarginHeight->GetText().toInt32();
667 : else
668 0 : lMarginHeight = SIZE_NOT_SET;
669 :
670 0 : xSet->setPropertyValue( "FrameURL", makeAny( aURL ) );
671 0 : xSet->setPropertyValue( "FrameName", makeAny( aName ) );
672 :
673 0 : if ( eScroll == ScrollingAuto )
674 0 : xSet->setPropertyValue( "FrameIsAutoScroll", makeAny( sal_True ) );
675 : else
676 0 : xSet->setPropertyValue( "FrameIsScrollingMode", makeAny( (sal_Bool) ( eScroll == ScrollingYes) ) );
677 :
678 0 : xSet->setPropertyValue( "FrameIsBorder", makeAny( bHasBorder ) );
679 0 : xSet->setPropertyValue( "FrameMarginWidth", makeAny( sal_Int32( lMarginWidth ) ) );
680 0 : xSet->setPropertyValue( "FrameMarginHeight", makeAny( sal_Int32( lMarginHeight ) ) );
681 :
682 0 : if ( bIPActive )
683 0 : m_xObj->changeState( embed::EmbedStates::INPLACE_ACTIVE );
684 : }
685 0 : catch ( uno::Exception& )
686 : {
687 : OSL_FAIL( "No IFrame!" );
688 : }
689 0 : }
690 : }
691 :
692 0 : return nRet;
693 : }
694 :
695 :
696 :
697 0 : IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog, CheckHdl, CheckBox*, pCB )
698 : {
699 0 : if ( pCB == pThis->m_pCBMarginWidthDefault )
700 : {
701 0 : if ( pCB->IsChecked() )
702 0 : pThis->m_pNMMarginWidth->SetText( OUString::number(DEFAULT_MARGIN_WIDTH) );
703 0 : pThis->m_pFTMarginWidth->Enable( !pCB->IsChecked() );
704 0 : pThis->m_pNMMarginWidth->Enable( !pCB->IsChecked() );
705 : }
706 :
707 0 : if ( pCB == pThis->m_pCBMarginHeightDefault )
708 : {
709 0 : if ( pCB->IsChecked() )
710 0 : pThis->m_pNMMarginHeight->SetText( OUString::number(DEFAULT_MARGIN_HEIGHT) );
711 0 : pThis->m_pFTMarginHeight->Enable( !pCB->IsChecked() );
712 0 : pThis->m_pNMMarginHeight->Enable( !pCB->IsChecked() );
713 : }
714 :
715 0 : return 0L;
716 : }
717 :
718 :
719 :
720 0 : IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog, OpenHdl, PushButton*, EMPTYARG )
721 : {
722 0 : Window* pOldParent = Application::GetDefDialogParent();
723 0 : Application::SetDefDialogParent( pThis );
724 :
725 : // create the file dialog
726 : sfx2::FileDialogHelper aFileDlg(
727 0 : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0, OUString() );
728 :
729 : // set the title
730 0 : aFileDlg.SetTitle(CUI_RESSTR(RID_SVXSTR_SELECT_FILE_IFRAME));
731 :
732 : // show the dialog
733 0 : if ( aFileDlg.Execute() == ERRCODE_NONE )
734 : pThis->m_pEDURL->SetText(
735 0 : INetURLObject( aFileDlg.GetPath() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
736 :
737 0 : Application::SetDefDialogParent( pOldParent );
738 0 : return 0L;
739 0 : }
740 :
741 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|