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