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