1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: insdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
38 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
39 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
40 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <com/sun/star/embed/EmbedStates.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 #include <com/sun/star/embed/XInsertObjectDialog.hpp>
48 #include <com/sun/star/ucb/CommandAbortedException.hpp>
49 #include <com/sun/star/task/XInteractionHandler.hpp>
52 #include <svx/dialmgr.hxx>
53 #include <svtools/sores.hxx>
56 #include <tools/urlobj.hxx>
57 #include <tools/debug.hxx>
58 #include <svtools/urihelper.hxx>
59 #include <svtools/svmedit.hxx>
60 #include <vcl/button.hxx>
61 #include <vcl/fixed.hxx>
62 #include <vcl/group.hxx>
63 #include <vcl/lstbox.hxx>
64 #include <vcl/msgbox.hxx>
65 #include <vcl/svapp.hxx>
66 #include <sot/clsids.hxx>
67 #include <sfx2/frmdescr.hxx>
68 #include <sfx2/viewsh.hxx>
69 #include <sfx2/filedlghelper.hxx>
70 #include <svtools/ownlist.hxx>
71 #include <comphelper/seqstream.hxx>
73 #include "svuidlg.hrc"
76 #include <osl/file.hxx>
78 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
79 #include <com/sun/star/container/XNameAccess.hpp>
80 #include <unotools/processfactory.hxx>
82 using namespace ::com::sun::star
;
83 using namespace ::com::sun::star::lang
;
84 using namespace ::com::sun::star::uno
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::ui::dialogs
;
87 using ::rtl::OUString
;
89 #define _SVSTDARR_STRINGSDTOR
90 #include <svtools/svstdarr.hxx>
93 static String
impl_getSvtResString( sal_uInt32 nId
)
96 com::sun::star::lang::Locale aLocale
= Application::GetSettings().GetUILocale();
97 ResMgr
* pMgr
= ResMgr::CreateResMgr( "svt", aLocale
);
100 aRet
= String( ResId( nId
, *pMgr
) );
106 BOOL
InsertObjectDialog_Impl::IsCreateNew() const
111 uno::Reference
< io::XInputStream
> InsertObjectDialog_Impl::GetIconIfIconified( ::rtl::OUString
* /*pGraphicMediaType*/ )
113 return uno::Reference
< io::XInputStream
>();
116 InsertObjectDialog_Impl::InsertObjectDialog_Impl( Window
* pParent
, const ResId
& rResId
, const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
)
117 : ModalDialog( pParent
, rResId
)
118 , m_xStorage( xStorage
)
123 // -----------------------------------------------------------------------
125 IMPL_LINK_INLINE_START( SvInsertOleDlg
, DoubleClickHdl
, ListBox
*, EMPTYARG
)
130 IMPL_LINK_INLINE_END( SvInsertOleDlg
, DoubleClickHdl
, ListBox
*, pListBox
)
132 // -----------------------------------------------------------------------
134 IMPL_LINK( SvInsertOleDlg
, BrowseHdl
, PushButton
*, EMPTYARG
)
136 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
139 Reference
< XFilePicker
> xFilePicker( xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), UNO_QUERY
);
140 DBG_ASSERT( xFilePicker
.is(), "could not get FilePicker service" );
142 Reference
< XInitialization
> xInit( xFilePicker
, UNO_QUERY
);
143 Reference
< XFilterManager
> xFilterMgr( xFilePicker
, UNO_QUERY
);
144 if( xInit
.is() && xFilePicker
.is() && xFilterMgr
.is() )
146 Sequence
< Any
> aServiceType( 1 );
147 aServiceType
[0] <<= TemplateDescription::FILEOPEN_SIMPLE
;
148 xInit
->initialize( aServiceType
);
153 xFilterMgr
->appendFilter(
155 OUString( RTL_CONSTASCII_USTRINGPARAM( "*.*" ) )
158 catch( IllegalArgumentException
& )
160 DBG_ASSERT( 0, "caught IllegalArgumentException when registering filter\n" );
163 if( xFilePicker
->execute() == ExecutableDialogResults::OK
)
165 Sequence
< OUString
> aPathSeq( xFilePicker
->getFiles() );
166 INetURLObject
aObj( aPathSeq
[0] );
167 aEdFilepath
.SetText( aObj
.PathToFileName() );
175 // -----------------------------------------------------------------------
177 IMPL_LINK( SvInsertOleDlg
, RadioHdl
, RadioButton
*, EMPTYARG
)
179 if ( aRbNewObject
.IsChecked() )
181 aLbObjecttype
.Show();
185 aGbObject
.SetText( _aOldStr
);
190 aLbObjecttype
.Hide();
194 aGbObject
.SetText( aStrFile
);
199 // -----------------------------------------------------------------------
201 void SvInsertOleDlg::SelectDefault()
203 aLbObjecttype
.SelectEntryPos( 0 );
206 void SvInsertOleDlg::FillObjectServerList( SvObjectServerList
* pList
)
208 pList
->FillInsertObjects();
211 // -----------------------------------------------------------------------
212 SvInsertOleDlg::SvInsertOleDlg
215 const Reference
< embed::XStorage
>& xStorage
,
216 const SvObjectServerList
* pServers
218 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OLEOBJECT
), xStorage
),
219 aRbNewObject( this, SVX_RES( RB_NEW_OBJECT
) ),
220 aRbObjectFromfile( this, SVX_RES( RB_OBJECT_FROMFILE
) ),
221 aLbObjecttype( this, SVX_RES( LB_OBJECTTYPE
) ),
222 aEdFilepath( this, SVX_RES( ED_FILEPATH
) ),
223 aBtnFilepath( this, SVX_RES( BTN_FILEPATH
) ),
224 aCbFilelink( this, SVX_RES( CB_FILELINK
) ),
225 aGbObject( this, SVX_RES( GB_OBJECT
) ),
226 aOKButton1( this, SVX_RES( 1 ) ),
227 aCancelButton1( this, SVX_RES( 1 ) ),
228 aHelpButton1( this, SVX_RES( 1 ) ),
229 aStrFile( SVX_RES( STR_FILE
) ),
230 m_pServers( pServers
)
233 _aOldStr
= aGbObject
.GetText();
234 aLbObjecttype
.SetDoubleClickHdl( LINK( this, SvInsertOleDlg
, DoubleClickHdl
) );
235 aBtnFilepath
.SetClickHdl( LINK( this, SvInsertOleDlg
, BrowseHdl
) );
236 Link
aLink( LINK( this, SvInsertOleDlg
, RadioHdl
) );
237 aRbNewObject
.SetClickHdl( aLink
);
238 aRbObjectFromfile
.SetClickHdl( aLink
);
239 aRbNewObject
.Check( TRUE
);
243 short SvInsertOleDlg::Execute()
246 SvObjectServerList aObjS
;
249 // if no list was provided, take the complete one
250 aObjS
.FillInsertObjects();
254 // fill listbox and select default
255 ListBox
& rBox
= GetObjectTypes();
256 rBox
.SetUpdateMode( FALSE
);
257 for ( ULONG i
= 0; i
< m_pServers
->Count(); i
++ )
258 rBox
.InsertEntry( (*m_pServers
)[i
].GetHumanName() );
259 rBox
.SetUpdateMode( TRUE
);
261 ::rtl::OUString aName
;
263 DBG_ASSERT( m_xStorage
.is(), "No storage!");
264 if ( m_xStorage
.is() && ( nRet
= Dialog::Execute() ) == RET_OK
)
268 BOOL bCreateNew
= IsCreateNew();
271 // create and insert new embedded object
272 String aServerName
= rBox
.GetSelectEntry();
273 const SvObjectServer
* pS
= m_pServers
->Get( aServerName
);
276 if( pS
->GetClassName() == SvGlobalName( SO3_OUT_CLASSID
) )
280 uno::Reference
< embed::XInsertObjectDialog
> xDialogCreator(
281 ::comphelper::getProcessServiceFactory()->createInstance(
282 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
285 if ( xDialogCreator
.is() )
287 aName
= aCnt
.CreateUniqueObjectName();
288 embed::InsertedObjectInfo aNewInf
= xDialogCreator
->createInstanceByDialog(
291 uno::Sequence
< beans::PropertyValue
>() );
293 OSL_ENSURE( aNewInf
.Object
.is(), "The object must be created or an exception must be thrown!" );
294 m_xObj
= aNewInf
.Object
;
295 for ( sal_Int32 nInd
= 0; nInd
< aNewInf
.Options
.getLength(); nInd
++ )
296 if ( aNewInf
.Options
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Icon" ) ) ) )
298 aNewInf
.Options
[nInd
].Value
>>= m_aIconMetaFile
;
300 else if ( aNewInf
.Options
[nInd
].Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IconFormat" ) ) ) )
302 datatransfer::DataFlavor aFlavor
;
303 if ( aNewInf
.Options
[nInd
].Value
>>= aFlavor
)
304 m_aIconMediaType
= aFlavor
.MimeType
;
309 catch( ucb::CommandAbortedException
& )
311 // the user has pressed cancel
313 catch( uno::Exception
& )
315 // TODO: Error handling
320 // create object with desired ClassId
321 m_xObj
= aCnt
.CreateEmbeddedObject( pS
->GetClassName().GetByteSequence(), aName
);
326 if( aFileName
.Len() ) // from OLE Dialog
328 // Objekt konnte nicht aus Datei erzeugt werden
329 // global Resource from svtools (former so3 resource)
330 String
aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE
) );
331 aErr
.SearchAndReplace( String( '%' ), aFileName
);
332 ErrorBox( this, WB_3DLOOK
| WB_OK
, aErr
).Execute();
336 // Objekt konnte nicht erzeugt werden
337 // global Resource from svtools (former so3 resource)
338 String
aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE
) );
339 aErr
.SearchAndReplace( String( '%' ), aServerName
);
340 ErrorBox( this, WB_3DLOOK
| WB_OK
, aErr
).Execute();
347 aFileName
= GetFilePath();
349 aURL
.SetSmartProtocol( INET_PROT_FILE
);
350 aURL
.SetSmartURL( aFileName
);
351 aFileName
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
354 if ( aFileName
.Len() )
356 // create MediaDescriptor for file to create object from
357 uno::Sequence
< beans::PropertyValue
> aMedium( 2 );
358 aMedium
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
359 aMedium
[0].Value
<<= ::rtl::OUString( aFileName
);
361 uno::Reference
< task::XInteractionHandler
> xInteraction
;
362 uno::Reference
< lang::XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
364 xInteraction
= uno::Reference
< task::XInteractionHandler
>(
365 xFactory
->createInstance(
366 DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
367 uno::UNO_QUERY_THROW
);
369 if ( xInteraction
.is() )
371 aMedium
[1].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
372 aMedium
[1].Value
<<= xInteraction
;
376 OSL_ASSERT( "Can not get InteractionHandler!\n" );
377 aMedium
.realloc( 1 );
380 // create object from media descriptor
382 m_xObj
= aCnt
.InsertEmbeddedLink( aMedium
, aName
);
384 m_xObj
= aCnt
.InsertEmbeddedObject( aMedium
, aName
);
389 // Objekt konnte nicht aus Datei erzeugt werden
390 // global Resource from svtools (former so3 resource)
391 String
aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE
) );
392 aErr
.SearchAndReplace( String( '%' ), aFileName
);
393 ErrorBox( this, WB_3DLOOK
| WB_OK
, aErr
).Execute();
402 uno::Reference
< io::XInputStream
> SvInsertOleDlg::GetIconIfIconified( ::rtl::OUString
* pGraphicMediaType
)
404 if ( m_aIconMetaFile
.getLength() )
406 if ( pGraphicMediaType
)
407 *pGraphicMediaType
= m_aIconMediaType
;
409 return uno::Reference
< io::XInputStream
>( new ::comphelper::SequenceInputStream( m_aIconMetaFile
) );
412 return uno::Reference
< io::XInputStream
>();
415 IMPL_LINK( SvInsertPlugInDialog
, BrowseHdl
, PushButton
*, EMPTYARG
)
417 Sequence
< OUString
> aFilterNames
, aFilterTypes
;
418 void fillNetscapePluginFilters( Sequence
< OUString
>& rNames
, Sequence
< OUString
>& rTypes
);
419 fillNetscapePluginFilters( aFilterNames
, aFilterTypes
);
421 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
424 Reference
< XFilePicker
> xFilePicker( xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), UNO_QUERY
);
425 DBG_ASSERT( xFilePicker
.is(), "could not get FilePicker service" );
427 Reference
< XInitialization
> xInit( xFilePicker
, UNO_QUERY
);
428 Reference
< XFilterManager
> xFilterMgr( xFilePicker
, UNO_QUERY
);
429 if( xInit
.is() && xFilePicker
.is() && xFilterMgr
.is() )
431 Sequence
< Any
> aServiceType( 1 );
432 aServiceType
[0] <<= TemplateDescription::FILEOPEN_SIMPLE
;
433 xInit
->initialize( aServiceType
);
438 const OUString
* pNames
= aFilterNames
.getConstArray();
439 const OUString
* pTypes
= aFilterTypes
.getConstArray();
440 for( int i
= 0; i
< aFilterNames
.getLength(); i
++ )
441 xFilterMgr
->appendFilter( pNames
[i
], pTypes
[i
] );
443 catch( IllegalArgumentException
& )
445 DBG_ASSERT( 0, "caught IllegalArgumentException when registering filter\n" );
448 if( xFilePicker
->execute() == ExecutableDialogResults::OK
)
450 Sequence
< OUString
> aPathSeq( xFilePicker
->getFiles() );
451 INetURLObject
aObj( aPathSeq
[0] );
452 aEdFileurl
.SetText( aObj
.PathToFileName() );
460 // -----------------------------------------------------------------------
462 SvInsertPlugInDialog::SvInsertPlugInDialog( Window
* pParent
, const uno::Reference
< embed::XStorage
>& xStorage
)
463 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OBJECT_PLUGIN
), xStorage
),
464 aEdFileurl( this, SVX_RES( ED_FILEURL
) ),
465 aBtnFileurl( this, SVX_RES( BTN_FILEURL
) ),
466 aGbFileurl( this, SVX_RES( GB_FILEURL
) ),
467 aEdPluginsOptions( this, SVX_RES( ED_PLUGINS_OPTIONS
) ),
468 aGbPluginsOptions( this, SVX_RES( GB_PLUGINS_OPTIONS
) ),
469 aOKButton1( this, SVX_RES( 1 ) ),
470 aCancelButton1( this, SVX_RES( 1 ) ),
471 aHelpButton1( this, SVX_RES( 1 ) ),
475 aBtnFileurl
.SetClickHdl( LINK( this, SvInsertPlugInDialog
, BrowseHdl
) );
478 SvInsertPlugInDialog::~SvInsertPlugInDialog()
483 // -----------------------------------------------------------------------
485 static void Plugin_ImplFillCommandSequence( const String
& aCommands
, uno::Sequence
< beans::PropertyValue
>& aCommandSequence
)
489 aLst
.AppendCommands( aCommands
, &nEaten
);
491 const sal_Int32 nCount
= aLst
.Count();
492 aCommandSequence
.realloc( nCount
);
493 for( sal_Int32 nIndex
= 0; nIndex
< nCount
; nIndex
++ )
495 const SvCommand
& rCommand
= aLst
[ nIndex
];
497 aCommandSequence
[nIndex
].Name
= rCommand
.GetCommand();
498 aCommandSequence
[nIndex
].Handle
= -1;
499 aCommandSequence
[nIndex
].Value
= makeAny( OUString( rCommand
.GetArgument() ) );
500 aCommandSequence
[nIndex
].State
= beans::PropertyState_DIRECT_VALUE
;
504 short SvInsertPlugInDialog::Execute()
508 DBG_ASSERT( m_xStorage
.is(), "No storage!");
509 if ( m_xStorage
.is() && ( nRet
= Dialog::Execute() ) == RET_OK
)
512 m_pURL
= new INetURLObject();
514 *m_pURL
= INetURLObject();
516 m_aCommands
= GetPlugInOptions();
517 String aURL
= GetPlugInFile();
519 // URL can be a valid and absolute URL or a system file name
520 m_pURL
->SetSmartProtocol( INET_PROT_FILE
);
521 if ( !aURL
.Len() || m_pURL
->SetSmartURL( aURL
) )
523 // create a plugin object
524 ::rtl::OUString aName
;
525 SvGlobalName
aClassId( SO3_PLUGIN_CLASSID
);
526 m_xObj
= aCnt
.CreateEmbeddedObject( aClassId
.GetByteSequence(), aName
);
531 // set properties from dialog
532 if ( m_xObj
->getCurrentState() == embed::EmbedStates::LOADED
)
533 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
535 uno::Reference
< beans::XPropertySet
> xSet( m_xObj
->getComponent(), uno::UNO_QUERY
);
538 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
539 makeAny( ::rtl::OUString( m_pURL
->GetMainURL( INetURLObject::NO_DECODE
) ) ) );
540 uno::Sequence
< beans::PropertyValue
> aCommandSequence
;
541 Plugin_ImplFillCommandSequence( m_aCommands
, aCommandSequence
);
542 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("PluginCommands"), makeAny( aCommandSequence
) );
547 // PlugIn konnte nicht erzeugt werden
548 // global Resource from svtools (former so3 resource)
549 String
aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_PLUGIN
) );
550 aErr
.SearchAndReplace( String( '%' ), aURL
);
551 ErrorBox( this, WB_3DLOOK
| WB_OK
, aErr
).Execute();
558 // class SvInsertAppletDlg -----------------------------------------------
560 IMPL_LINK( SvInsertAppletDialog
, BrowseHdl
, PushButton
*, EMPTYARG
)
562 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
565 Reference
< XFilePicker
> xFilePicker( xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), UNO_QUERY
);
566 DBG_ASSERT( xFilePicker
.is(), "could not get FilePicker service" );
568 Reference
< XInitialization
> xInit( xFilePicker
, UNO_QUERY
);
569 Reference
< XFilterManager
> xFilterMgr( xFilePicker
, UNO_QUERY
);
570 if( xInit
.is() && xFilePicker
.is() && xFilterMgr
.is() )
572 Sequence
< Any
> aServiceType( 1 );
573 aServiceType
[0] <<= TemplateDescription::FILEOPEN_SIMPLE
;
574 xInit
->initialize( aServiceType
);
579 xFilterMgr
->appendFilter(
580 OUString( RTL_CONSTASCII_USTRINGPARAM( "Applet" ) ),
581 OUString( RTL_CONSTASCII_USTRINGPARAM( "*.class" ) )
584 catch( IllegalArgumentException
& )
586 DBG_ASSERT( 0, "caught IllegalArgumentException when registering filter\n" );
589 if( xFilePicker
->execute() == ExecutableDialogResults::OK
)
591 Sequence
< OUString
> aPathSeq( xFilePicker
->getFiles() );
593 INetURLObject
aObj( aPathSeq
[0] );
594 aEdClassfile
.SetText( aObj
.getName() );
595 aObj
.removeSegment();
596 aEdClasslocation
.SetText( aObj
.PathToFileName() );
604 // -----------------------------------------------------------------------
606 SvInsertAppletDialog::SvInsertAppletDialog( Window
* pParent
, const uno::Reference
< embed::XStorage
>& xStorage
)
607 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OBJECT_APPLET
), xStorage
),
608 aFtClassfile( this, SVX_RES( FT_CLASSFILE
) ),
609 aEdClassfile( this, SVX_RES( ED_CLASSFILE
) ),
610 aFtClasslocation( this, SVX_RES( FT_CLASSLOCATION
) ),
611 aEdClasslocation( this, SVX_RES( ED_CLASSLOCATION
) ),
612 aBtnClass( this, SVX_RES( BTN_CLASS
) ),
613 aGbClass( this, SVX_RES( GB_CLASS
) ),
614 aEdAppletOptions( this, SVX_RES( ED_APPLET_OPTIONS
) ),
615 aGbAppletOptions( this, SVX_RES( GB_APPLET_OPTIONS
) ),
616 aOKButton1( this, SVX_RES( 1 ) ),
617 aCancelButton1( this, SVX_RES( 1 ) ),
618 aHelpButton1( this, SVX_RES( 1 ) ),
622 aBtnClass
.SetClickHdl( LINK( this, SvInsertAppletDialog
, BrowseHdl
) );
625 SvInsertAppletDialog::SvInsertAppletDialog( Window
* pParent
, const uno::Reference
< embed::XEmbeddedObject
>& xObj
)
626 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OBJECT_APPLET
), uno::Reference
< embed::XStorage
>() ),
627 aFtClassfile( this, SVX_RES( FT_CLASSFILE
) ),
628 aEdClassfile( this, SVX_RES( ED_CLASSFILE
) ),
629 aFtClasslocation( this, SVX_RES( FT_CLASSLOCATION
) ),
630 aEdClasslocation( this, SVX_RES( ED_CLASSLOCATION
) ),
631 aBtnClass( this, SVX_RES( BTN_CLASS
) ),
632 aGbClass( this, SVX_RES( GB_CLASS
) ),
633 aEdAppletOptions( this, SVX_RES( ED_APPLET_OPTIONS
) ),
634 aGbAppletOptions( this, SVX_RES( GB_APPLET_OPTIONS
) ),
635 aOKButton1( this, SVX_RES( 1 ) ),
636 aCancelButton1( this, SVX_RES( 1 ) ),
637 aHelpButton1( this, SVX_RES( 1 ) ),
642 aBtnClass
.SetClickHdl( LINK( this, SvInsertAppletDialog
, BrowseHdl
) );
646 SvInsertAppletDialog::~SvInsertAppletDialog()
651 short SvInsertAppletDialog::Execute()
658 uno::Reference
< beans::XPropertySet
> xSet
;
663 if ( m_xObj
->getCurrentState() == embed::EmbedStates::LOADED
)
664 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
665 xSet
= uno::Reference
< beans::XPropertySet
>( m_xObj
->getComponent(), uno::UNO_QUERY
);
666 ::rtl::OUString aStr
;
667 uno::Any aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("AppletCode") );
670 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase") );
672 SetClassLocation( aStr
);
673 uno::Sequence
< beans::PropertyValue
> aCommands
;
674 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("AppletCommands") );
675 if ( aAny
>>= aCommands
)
678 aList
.FillFromSequence( aCommands
);
679 SetAppletOptions( aList
.GetCommands() );
682 String
aText( SVX_RES( STR_EDIT_APPLET
) );
686 catch ( uno::Exception
& )
688 DBG_ERROR( "No Applet!" );
693 DBG_ASSERT( m_xStorage
.is(), "No storage!");
694 bOK
= m_xStorage
.is();
697 if ( bOK
&& ( nRet
= Dialog::Execute() ) == RET_OK
)
701 ::rtl::OUString aName
;
702 SvGlobalName
aClassId( SO3_APPLET_CLASSID
);
703 m_xObj
= aCnt
.CreateEmbeddedObject( aClassId
.GetByteSequence(), aName
);
704 if ( m_xObj
->getCurrentState() == embed::EmbedStates::LOADED
)
705 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
706 xSet
= uno::Reference
< beans::XPropertySet
>( m_xObj
->getComponent(), uno::UNO_QUERY
);
713 BOOL bIPActive
= m_xObj
->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
;
715 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
717 String aClassLocation
= GetClassLocation();
719 // Hack, aFileName wird auch fuer Class benutzt
720 m_aClass
= GetClass();
721 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCode"), makeAny( ::rtl::OUString( m_aClass
) ) );
723 ::rtl::OUString tmp
= aClassLocation
;
724 ::osl::File::getFileURLFromSystemPath(tmp
, tmp
);
725 aClassLocation
= tmp
;
726 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), makeAny( tmp
) );
727 m_aCommands
= GetAppletOptions();
729 uno::Sequence
< beans::PropertyValue
> aCommandSequence
;
730 Plugin_ImplFillCommandSequence( m_aCommands
, aCommandSequence
);
731 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCommands"), makeAny( aCommandSequence
) );
734 m_xObj
->changeState( embed::EmbedStates::INPLACE_ACTIVE
);
736 catch ( uno::Exception
& )
738 DBG_ERROR( "No Applet!" );
746 SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window
*pParent
,
747 const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
)
748 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OBJECT_IFRAME
), xStorage
)
749 , aFTName ( this, SVX_RES( FT_FRAMENAME
) )
750 , aEDName ( this, SVX_RES( ED_FRAMENAME
) )
751 , aFTURL ( this, SVX_RES( FT_URL
) )
752 , aEDURL ( this, SVX_RES( ED_URL
) )
753 , aBTOpen ( this, SVX_RES(BT_FILEOPEN
) )
754 , aRBScrollingOn ( this, SVX_RES( RB_SCROLLINGON
) )
755 , aRBScrollingOff ( this, SVX_RES( RB_SCROLLINGOFF
) )
756 , aRBScrollingAuto ( this, SVX_RES( RB_SCROLLINGAUTO
) )
757 , aFLScrolling ( this, SVX_RES( GB_SCROLLING
) )
758 , aFLSepLeft( this, SVX_RES( FL_SEP_LEFT
) )
759 , aRBFrameBorderOn ( this, SVX_RES( RB_FRMBORDER_ON
) )
760 , aRBFrameBorderOff ( this, SVX_RES( RB_FRMBORDER_OFF
) )
761 , aFLFrameBorder( this, SVX_RES( GB_BORDER
) )
762 , aFLSepRight( this, SVX_RES( FL_SEP_RIGHT
) )
763 , aFTMarginWidth ( this, SVX_RES( FT_MARGINWIDTH
) )
764 , aNMMarginWidth ( this, SVX_RES( NM_MARGINWIDTH
) )
765 , aCBMarginWidthDefault( this, SVX_RES( CB_MARGINHEIGHTDEFAULT
) )
766 , aFTMarginHeight ( this, SVX_RES( FT_MARGINHEIGHT
) )
767 , aNMMarginHeight ( this, SVX_RES( NM_MARGINHEIGHT
) )
768 , aCBMarginHeightDefault( this, SVX_RES( CB_MARGINHEIGHTDEFAULT
) )
769 , aFLMargin( this, SVX_RES( GB_MARGIN
) )
770 , aOKButton1( this, SVX_RES( 1 ) )
771 , aCancelButton1( this, SVX_RES( 1 ) )
772 , aHelpButton1( this, SVX_RES( 1 ) )
776 aFLSepLeft
.SetStyle(aFLSepLeft
.GetStyle()|WB_VERT
);
777 aFLSepRight
.SetStyle(aFLSepRight
.GetStyle()|WB_VERT
);
779 Link
aLink( STATIC_LINK( this, SfxInsertFloatingFrameDialog
, CheckHdl
) );
780 aCBMarginWidthDefault
.SetClickHdl( aLink
);
781 aCBMarginHeightDefault
.SetClickHdl( aLink
);
783 aCBMarginWidthDefault
.Check();
784 aCBMarginHeightDefault
.Check();
785 aRBScrollingAuto
.Check();
786 aRBFrameBorderOn
.Check();
788 aBTOpen
.SetClickHdl( STATIC_LINK( this, SfxInsertFloatingFrameDialog
, OpenHdl
) );
791 SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window
*pParent
, const uno::Reference
< embed::XEmbeddedObject
>& xObj
)
792 : InsertObjectDialog_Impl( pParent
, SVX_RES( MD_INSERT_OBJECT_IFRAME
), uno::Reference
< embed::XStorage
>() )
793 , aFTName ( this, SVX_RES( FT_FRAMENAME
) )
794 , aEDName ( this, SVX_RES( ED_FRAMENAME
) )
795 , aFTURL ( this, SVX_RES( FT_URL
) )
796 , aEDURL ( this, SVX_RES( ED_URL
) )
797 , aBTOpen ( this, SVX_RES(BT_FILEOPEN
) )
798 , aRBScrollingOn ( this, SVX_RES( RB_SCROLLINGON
) )
799 , aRBScrollingOff ( this, SVX_RES( RB_SCROLLINGOFF
) )
800 , aRBScrollingAuto ( this, SVX_RES( RB_SCROLLINGAUTO
) )
801 , aFLScrolling ( this, SVX_RES( GB_SCROLLING
) )
802 , aFLSepLeft( this, SVX_RES( FL_SEP_LEFT
) )
803 , aRBFrameBorderOn ( this, SVX_RES( RB_FRMBORDER_ON
) )
804 , aRBFrameBorderOff ( this, SVX_RES( RB_FRMBORDER_OFF
) )
805 , aFLFrameBorder( this, SVX_RES( GB_BORDER
) )
806 , aFLSepRight( this, SVX_RES( FL_SEP_RIGHT
) )
807 , aFTMarginWidth ( this, SVX_RES( FT_MARGINWIDTH
) )
808 , aNMMarginWidth ( this, SVX_RES( NM_MARGINWIDTH
) )
809 , aCBMarginWidthDefault( this, SVX_RES( CB_MARGINHEIGHTDEFAULT
) )
810 , aFTMarginHeight ( this, SVX_RES( FT_MARGINHEIGHT
) )
811 , aNMMarginHeight ( this, SVX_RES( NM_MARGINHEIGHT
) )
812 , aCBMarginHeightDefault( this, SVX_RES( CB_MARGINHEIGHTDEFAULT
) )
813 , aFLMargin( this, SVX_RES( GB_MARGIN
) )
814 , aOKButton1( this, SVX_RES( 1 ) )
815 , aCancelButton1( this, SVX_RES( 1 ) )
816 , aHelpButton1( this, SVX_RES( 1 ) )
822 aFLSepLeft
.SetStyle(aFLSepLeft
.GetStyle()|WB_VERT
);
823 aFLSepRight
.SetStyle(aFLSepRight
.GetStyle()|WB_VERT
);
825 Link
aLink( STATIC_LINK( this, SfxInsertFloatingFrameDialog
, CheckHdl
) );
826 aCBMarginWidthDefault
.SetClickHdl( aLink
);
827 aCBMarginHeightDefault
.SetClickHdl( aLink
);
829 aCBMarginWidthDefault
.Check();
830 aCBMarginHeightDefault
.Check();
831 aRBScrollingAuto
.Check();
832 aRBFrameBorderOn
.Check();
834 aBTOpen
.SetClickHdl( STATIC_LINK( this, SfxInsertFloatingFrameDialog
, OpenHdl
) );
837 short SfxInsertFloatingFrameDialog::Execute()
841 uno::Reference
< beans::XPropertySet
> xSet
;
846 if ( m_xObj
->getCurrentState() == embed::EmbedStates::LOADED
)
847 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
848 xSet
= uno::Reference
< beans::XPropertySet
>( m_xObj
->getComponent(), uno::UNO_QUERY
);
849 ::rtl::OUString aStr
;
850 uno::Any aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameURL") );
852 aEDURL
.SetText( aStr
);
853 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameName") );
855 aEDName
.SetText( aStr
);
857 sal_Int32 nSize
= SIZE_NOT_SET
;
858 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth") );
861 if ( nSize
== SIZE_NOT_SET
)
863 aCBMarginWidthDefault
.Check( TRUE
);
864 aNMMarginWidth
.SetText( String::CreateFromInt32( DEFAULT_MARGIN_WIDTH
) );
865 aFTMarginWidth
.Enable( FALSE
);
866 aNMMarginWidth
.Enable( FALSE
);
869 aNMMarginWidth
.SetText( String::CreateFromInt32( nSize
) );
871 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight") );
874 if ( nSize
== SIZE_NOT_SET
)
876 aCBMarginHeightDefault
.Check( TRUE
);
877 aNMMarginHeight
.SetText( String::CreateFromInt32( DEFAULT_MARGIN_HEIGHT
) );
878 aFTMarginHeight
.Enable( FALSE
);
879 aNMMarginHeight
.Enable( FALSE
);
882 aNMMarginHeight
.SetText( String::CreateFromInt32( nSize
) );
884 BOOL bScrollOn
= FALSE
;
885 BOOL bScrollOff
= FALSE
;
886 BOOL bScrollAuto
= FALSE
;
888 sal_Bool bSet
= sal_False
;
889 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll") );
893 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode") );
901 aRBScrollingOn
.Check( bScrollOn
);
902 aRBScrollingOff
.Check( bScrollOff
);
903 aRBScrollingAuto
.Check( bScrollAuto
);
906 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder") );
910 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder") );
912 aRBFrameBorderOn
.Check( bSet
);
913 aRBFrameBorderOff
.Check( !bSet
);
916 SetUpdateMode( TRUE
);
919 catch ( uno::Exception
& )
921 DBG_ERROR( "No IFrame!" );
926 DBG_ASSERT( m_xStorage
.is(), "No storage!");
927 bOK
= m_xStorage
.is();
930 if ( bOK
&& ( nRet
= Dialog::Execute() ) == RET_OK
)
932 ::rtl::OUString aURL
;
933 if ( aEDURL
.GetText().Len() )
935 // URL can be a valid and absolute URL or a system file name
937 aObj
.SetSmartProtocol( INET_PROT_FILE
);
938 if ( aObj
.SetSmartURL( aEDURL
.GetText() ) )
939 aURL
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
942 if ( !m_xObj
.is() && aURL
.getLength() )
945 ::rtl::OUString aName
;
946 SvGlobalName
aClassId( SO3_IFRAME_CLASSID
);
947 m_xObj
= aCnt
.CreateEmbeddedObject( aClassId
.GetByteSequence(), aName
);
948 if ( m_xObj
->getCurrentState() == embed::EmbedStates::LOADED
)
949 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
950 xSet
= uno::Reference
< beans::XPropertySet
>( m_xObj
->getComponent(), uno::UNO_QUERY
);
957 BOOL bIPActive
= m_xObj
->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
;
959 m_xObj
->changeState( embed::EmbedStates::RUNNING
);
961 ::rtl::OUString aName
= aEDName
.GetText();
962 ScrollingMode eScroll
= ScrollingNo
;
963 if ( aRBScrollingOn
.IsChecked() )
964 eScroll
= ScrollingYes
;
965 if ( aRBScrollingOff
.IsChecked() )
966 eScroll
= ScrollingNo
;
967 if ( aRBScrollingAuto
.IsChecked() )
968 eScroll
= ScrollingAuto
;
970 sal_Bool bHasBorder
= aRBFrameBorderOn
.IsChecked();
973 if ( !aCBMarginWidthDefault
.IsChecked() )
974 lMarginWidth
= (long) aNMMarginWidth
.GetText().ToInt32();
976 lMarginWidth
= SIZE_NOT_SET
;
979 if ( !aCBMarginHeightDefault
.IsChecked() )
980 lMarginHeight
= (long) aNMMarginHeight
.GetText().ToInt32();
982 lMarginHeight
= SIZE_NOT_SET
;
984 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameURL"), makeAny( aURL
) );
985 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameName"), makeAny( aName
) );
987 if ( eScroll
== ScrollingAuto
)
988 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll"),
989 makeAny( sal_True
) );
991 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode"),
992 makeAny( (sal_Bool
) ( eScroll
== ScrollingYes
) ) );
994 //if ( aFrmDescr.IsFrameBorderSet() )
995 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder"),
996 makeAny( bHasBorder
) );
998 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder"),
999 makeAny( sal_True ) );*/
1001 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth"),
1002 makeAny( sal_Int32( lMarginWidth
) ) );
1004 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight"),
1005 makeAny( sal_Int32( lMarginHeight
) ) );
1008 m_xObj
->changeState( embed::EmbedStates::INPLACE_ACTIVE
);
1010 catch ( uno::Exception
& )
1012 DBG_ERROR( "No IFrame!" );
1020 //------------------------------------------------------------------------------
1022 IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog
, CheckHdl
, CheckBox
*, pCB
)
1024 if ( pCB
== &pThis
->aCBMarginWidthDefault
)
1026 if ( pCB
->IsChecked() )
1027 pThis
->aNMMarginWidth
.SetText( String::CreateFromInt32( DEFAULT_MARGIN_WIDTH
) );
1028 pThis
->aFTMarginWidth
.Enable( !pCB
->IsChecked() );
1029 pThis
->aNMMarginWidth
.Enable( !pCB
->IsChecked() );
1032 if ( pCB
== &pThis
->aCBMarginHeightDefault
)
1034 if ( pCB
->IsChecked() )
1035 pThis
->aNMMarginHeight
.SetText( String::CreateFromInt32( DEFAULT_MARGIN_HEIGHT
) );
1036 pThis
->aFTMarginHeight
.Enable( !pCB
->IsChecked() );
1037 pThis
->aNMMarginHeight
.Enable( !pCB
->IsChecked() );
1043 //------------------------------------------------------------------------------
1045 IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog
, OpenHdl
, PushButton
*, EMPTYARG
)
1047 Window
* pOldParent
= Application::GetDefDialogParent();
1048 Application::SetDefDialogParent( pThis
);
1050 // create the file dialog
1051 sfx2::FileDialogHelper
aFileDlg( WB_OPEN
| SFXWB_PASSWORD
, String() );
1054 aFileDlg
.SetTitle( OUString( String( SVX_RES( MD_INSERT_OBJECT_IFRAME
) ) ) );
1057 if ( aFileDlg
.Execute() == ERRCODE_NONE
)
1058 pThis
->aEDURL
.SetText(
1059 INetURLObject( aFileDlg
.GetPath() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET
) );
1061 Application::SetDefDialogParent( pOldParent
);