Files
libreoffice/cui/source/dialogs/insdlg.cxx

776 lines
29 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2009-10-31 00:36:06 +01:00
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/embed/XInsertObjectDialog.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
2009-10-31 00:36:06 +01:00
#include "insdlg.hxx"
#include <dialmgr.hxx>
2009-10-31 00:36:06 +01:00
#include <svtools/sores.hxx>
#include <stdio.h>
#include <tools/urlobj.hxx>
#include <tools/debug.hxx>
#include <svl/urihelper.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>
#include <vcl/layout.hxx>
2009-10-31 00:36:06 +01:00
#include <vcl/lstbox.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <sot/clsids.hxx>
#include <sfx2/frmdescr.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/filedlghelper.hxx>
#include <svl/ownlist.hxx>
#include <comphelper/seqstream.hxx>
#include "cuires.hrc"
2009-10-31 00:36:06 +01:00
#include <osl/file.hxx>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::ui::dialogs;
using ::rtl::OUString;
static String impl_getSvtResString( sal_uInt32 nId )
{
String aRet;
com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
ResMgr* pMgr = ResMgr::CreateResMgr( "svt", aLocale );
if( pMgr )
{
aRet = String( ResId( nId, *pMgr ) );
delete pMgr;
}
return aRet;
}
sal_Bool InsertObjectDialog_Impl::IsCreateNew() const
2009-10-31 00:36:06 +01:00
{
return sal_False;
2009-10-31 00:36:06 +01:00
}
uno::Reference< io::XInputStream > InsertObjectDialog_Impl::GetIconIfIconified( ::rtl::OUString* /*pGraphicMediaType*/ )
{
return uno::Reference< io::XInputStream >();
}
InsertObjectDialog_Impl::InsertObjectDialog_Impl(Window * pParent, const OString& rID,
const OUString& rUIXMLDescription,
const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage)
: ModalDialog(pParent, rID, rUIXMLDescription)
, m_xStorage( xStorage )
, aCnt( m_xStorage )
{
}
2009-10-31 00:36:06 +01:00
// -----------------------------------------------------------------------
IMPL_LINK_NOARG_INLINE_START(SvInsertOleDlg, DoubleClickHdl)
2009-10-31 00:36:06 +01:00
{
EndDialog( RET_OK );
return 0;
}
IMPL_LINK_INLINE_END( SvInsertOleDlg, DoubleClickHdl, ListBox *, pListBox )
// -----------------------------------------------------------------------
IMPL_LINK_NOARG(SvInsertOleDlg, BrowseHdl)
2009-10-31 00:36:06 +01:00
{
Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
if( xFactory.is() )
{
Reference< XFilePicker > xFilePicker( xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), UNO_QUERY );
DBG_ASSERT( xFilePicker.is(), "could not get FilePicker service" );
Reference< XInitialization > xInit( xFilePicker, UNO_QUERY );
Reference< XFilterManager > xFilterMgr( xFilePicker, UNO_QUERY );
if( xInit.is() && xFilePicker.is() && xFilterMgr.is() )
{
Sequence< Any > aServiceType( 1 );
aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
xInit->initialize( aServiceType );
// add filter
try
{
xFilterMgr->appendFilter(
OUString(),
OUString( RTL_CONSTASCII_USTRINGPARAM( "*.*" ) )
);
}
catch( IllegalArgumentException& )
{
DBG_ASSERT( 0, "caught IllegalArgumentException when registering filter\n" );
}
if( xFilePicker->execute() == ExecutableDialogResults::OK )
{
Sequence< OUString > aPathSeq( xFilePicker->getFiles() );
INetURLObject aObj( aPathSeq[0] );
m_pEdFilepath->SetText( aObj.PathToFileName() );
2009-10-31 00:36:06 +01:00
}
}
}
return 0;
}
// -----------------------------------------------------------------------
IMPL_LINK_NOARG(SvInsertOleDlg, RadioHdl)
2009-10-31 00:36:06 +01:00
{
if ( m_pRbNewObject->IsChecked() )
2009-10-31 00:36:06 +01:00
{
m_pObjectTypeFrame->Show();
m_pFileFrame->Hide();
2009-10-31 00:36:06 +01:00
}
else
{
m_pFileFrame->Show();
m_pObjectTypeFrame->Hide();
2009-10-31 00:36:06 +01:00
}
return 0;
}
// -----------------------------------------------------------------------
void SvInsertOleDlg::SelectDefault()
{
m_pLbObjecttype->SelectEntryPos(0);
2009-10-31 00:36:06 +01:00
}
// -----------------------------------------------------------------------
SvInsertOleDlg::SvInsertOleDlg
(
Window* pParent,
const Reference < embed::XStorage >& xStorage,
const SvObjectServerList* pServers
)
: InsertObjectDialog_Impl( pParent, "InsertOLEObjectDialog", "cui/ui/insertoleobject.ui", xStorage ),
2009-10-31 00:36:06 +01:00
m_pServers( pServers )
{
get(m_pRbNewObject, "createnew");
get(m_pRbObjectFromfile, "createfromfile");
get(m_pObjectTypeFrame, "objecttypeframe");
get(m_pLbObjecttype, "types");
get(m_pFileFrame, "fileframe");
get(m_pEdFilepath, "urled");
get(m_pBtnFilepath, "urlbtn");
get(m_pCbFilelink, "linktofile");
m_pLbObjecttype->SetDoubleClickHdl( LINK( this, SvInsertOleDlg, DoubleClickHdl ) );
m_pBtnFilepath->SetClickHdl( LINK( this, SvInsertOleDlg, BrowseHdl ) );
2009-10-31 00:36:06 +01:00
Link aLink( LINK( this, SvInsertOleDlg, RadioHdl ) );
m_pRbNewObject->SetClickHdl( aLink );
m_pRbObjectFromfile->SetClickHdl( aLink );
m_pRbNewObject->Check( sal_True );
2009-10-31 00:36:06 +01:00
RadioHdl( NULL );
m_pBtnFilepath->SetAccessibleRelationMemberOf(m_pFileFrame->get_label_widget());
2009-10-31 00:36:06 +01:00
}
short SvInsertOleDlg::Execute()
{
short nRet = RET_OK;
SvObjectServerList aObjS;
if ( !m_pServers )
{
// if no list was provided, take the complete one
aObjS.FillInsertObjects();
m_pServers = &aObjS;
}
// fill listbox and select default
ListBox& rBox = GetObjectTypes();
rBox.SetUpdateMode( sal_False );
for ( sal_uLong i = 0; i < m_pServers->Count(); i++ )
2009-10-31 00:36:06 +01:00
rBox.InsertEntry( (*m_pServers)[i].GetHumanName() );
rBox.SetUpdateMode( sal_True );
2009-10-31 00:36:06 +01:00
SelectDefault();
::rtl::OUString aName;
DBG_ASSERT( m_xStorage.is(), "No storage!");
if ( m_xStorage.is() && ( nRet = Dialog::Execute() ) == RET_OK )
{
String aFileName;
sal_Bool bLink = sal_False;
sal_Bool bCreateNew = IsCreateNew();
2009-10-31 00:36:06 +01:00
if ( bCreateNew )
{
// create and insert new embedded object
String aServerName = rBox.GetSelectEntry();
const SvObjectServer* pS = m_pServers->Get( aServerName );
if ( pS )
{
if( pS->GetClassName() == SvGlobalName( SO3_OUT_CLASSID ) )
{
try
{
uno::Reference < embed::XInsertObjectDialog > xDialogCreator(
::comphelper::getProcessServiceFactory()->createInstance(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
uno::UNO_QUERY );
if ( xDialogCreator.is() )
{
aName = aCnt.CreateUniqueObjectName();
embed::InsertedObjectInfo aNewInf = xDialogCreator->createInstanceByDialog(
m_xStorage,
aName,
uno::Sequence < beans::PropertyValue >() );
OSL_ENSURE( aNewInf.Object.is(), "The object must be created or an exception must be thrown!" );
m_xObj = aNewInf.Object;
for ( sal_Int32 nInd = 0; nInd < aNewInf.Options.getLength(); nInd++ )
2012-04-06 14:09:04 +02:00
if ( aNewInf.Options[nInd].Name == "Icon" )
2009-10-31 00:36:06 +01:00
{
aNewInf.Options[nInd].Value >>= m_aIconMetaFile;
}
2012-04-06 14:09:04 +02:00
else if ( aNewInf.Options[nInd].Name == "IconFormat" )
2009-10-31 00:36:06 +01:00
{
datatransfer::DataFlavor aFlavor;
if ( aNewInf.Options[nInd].Value >>= aFlavor )
m_aIconMediaType = aFlavor.MimeType;
}
}
}
catch( ucb::CommandAbortedException& )
{
// the user has pressed cancel
}
catch( uno::Exception& )
{
// TODO: Error handling
}
}
else
{
// create object with desired ClassId
m_xObj = aCnt.CreateEmbeddedObject( pS->GetClassName().GetByteSequence(), aName );
}
if ( !m_xObj.is() )
{
if( aFileName.Len() ) // from OLE Dialog
{
// object couldn't be created from file
2009-10-31 00:36:06 +01:00
// global Resource from svtools (former so3 resource)
String aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE ) );
aErr.SearchAndReplace( rtl::OUString( '%' ), aFileName );
2009-10-31 00:36:06 +01:00
ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
}
else
{
// object couldn't be created
2009-10-31 00:36:06 +01:00
// global Resource from svtools (former so3 resource)
String aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE ) );
aErr.SearchAndReplace( rtl::OUString( '%' ), aServerName );
2009-10-31 00:36:06 +01:00
ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
}
}
}
}
else
{
aFileName = GetFilePath();
INetURLObject aURL;
aURL.SetSmartProtocol( INET_PROT_FILE );
aURL.SetSmartURL( aFileName );
aFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
bLink = IsLinked();
if ( aFileName.Len() )
{
// create MediaDescriptor for file to create object from
uno::Sequence < beans::PropertyValue > aMedium( 2 );
aMedium[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
aMedium[0].Value <<= ::rtl::OUString( aFileName );
uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
uno::Reference< task::XInteractionHandler2 > xInteraction(
task::InteractionHandler::createWithParent(xContext, 0) );
2009-10-31 00:36:06 +01:00
aMedium[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
aMedium[1].Value <<= xInteraction;
2009-10-31 00:36:06 +01:00
// create object from media descriptor
if ( bLink )
m_xObj = aCnt.InsertEmbeddedLink( aMedium, aName );
else
m_xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
}
if ( !m_xObj.is() )
{
// object couldn't be created from file
2009-10-31 00:36:06 +01:00
// global Resource from svtools (former so3 resource)
String aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_FROM_FILE ) );
aErr.SearchAndReplace( rtl::OUString( '%' ), aFileName );
2009-10-31 00:36:06 +01:00
ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
}
}
}
m_pServers = 0;
return nRet;
}
uno::Reference< io::XInputStream > SvInsertOleDlg::GetIconIfIconified( ::rtl::OUString* pGraphicMediaType )
{
if ( m_aIconMetaFile.getLength() )
{
if ( pGraphicMediaType )
*pGraphicMediaType = m_aIconMediaType;
return uno::Reference< io::XInputStream >( new ::comphelper::SequenceInputStream( m_aIconMetaFile ) );
}
return uno::Reference< io::XInputStream >();
}
IMPL_LINK_NOARG(SvInsertPlugInDialog, BrowseHdl)
2009-10-31 00:36:06 +01:00
{
Sequence< OUString > aFilterNames, aFilterTypes;
void fillNetscapePluginFilters( Sequence< OUString >& rNames, Sequence< OUString >& rTypes );
fillNetscapePluginFilters( aFilterNames, aFilterTypes );
Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
if( xFactory.is() )
{
Reference< XFilePicker > xFilePicker( xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), UNO_QUERY );
DBG_ASSERT( xFilePicker.is(), "could not get FilePicker service" );
Reference< XInitialization > xInit( xFilePicker, UNO_QUERY );
Reference< XFilterManager > xFilterMgr( xFilePicker, UNO_QUERY );
if( xInit.is() && xFilePicker.is() && xFilterMgr.is() )
{
Sequence< Any > aServiceType( 1 );
aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
xInit->initialize( aServiceType );
// add the filters
try
{
const OUString* pNames = aFilterNames.getConstArray();
const OUString* pTypes = aFilterTypes.getConstArray();
for( int i = 0; i < aFilterNames.getLength(); i++ )
xFilterMgr->appendFilter( pNames[i], pTypes[i] );
}
catch( IllegalArgumentException& )
{
DBG_ASSERT( 0, "caught IllegalArgumentException when registering filter\n" );
}
if( xFilePicker->execute() == ExecutableDialogResults::OK )
{
Sequence< OUString > aPathSeq( xFilePicker->getFiles() );
INetURLObject aObj( aPathSeq[0] );
m_pEdFileurl->SetText(aObj.PathToFileName());
2009-10-31 00:36:06 +01:00
}
}
}
return 0;
}
// -----------------------------------------------------------------------
SvInsertPlugInDialog::SvInsertPlugInDialog(Window* pParent,
const uno::Reference < embed::XStorage >& xStorage)
: InsertObjectDialog_Impl(pParent, "InsertPluginDialog", "cui/ui/insertplugin.ui", xStorage)
, m_pURL(0)
2009-10-31 00:36:06 +01:00
{
get(m_pEdFileurl, "urled");
get(m_pBtnFileurl, "urlbtn");
get(m_pEdPluginsOptions, "pluginoptions");
m_pBtnFileurl->SetClickHdl(LINK(this, SvInsertPlugInDialog, BrowseHdl));
2009-10-31 00:36:06 +01:00
}
SvInsertPlugInDialog::~SvInsertPlugInDialog()
{
delete m_pURL;
}
// -----------------------------------------------------------------------
static void Plugin_ImplFillCommandSequence( const String& aCommands, uno::Sequence< beans::PropertyValue >& aCommandSequence )
{
2012-02-03 02:34:17 +09:00
sal_Int32 nEaten;
2009-10-31 00:36:06 +01:00
SvCommandList aLst;
aLst.AppendCommands( aCommands, &nEaten );
const size_t nCount = aLst.size();
2009-10-31 00:36:06 +01:00
aCommandSequence.realloc( nCount );
for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
2009-10-31 00:36:06 +01:00
{
aCommandSequence[nIndex].Name = aLst[ nIndex ].GetCommand();
2009-10-31 00:36:06 +01:00
aCommandSequence[nIndex].Handle = -1;
2012-02-03 02:34:17 +09:00
aCommandSequence[nIndex].Value = makeAny( aLst[ nIndex ].GetArgument() );
2009-10-31 00:36:06 +01:00
aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
}
}
short SvInsertPlugInDialog::Execute()
{
short nRet = RET_OK;
m_aCommands = OUString();
2009-10-31 00:36:06 +01:00
DBG_ASSERT( m_xStorage.is(), "No storage!");
if ( m_xStorage.is() && ( nRet = Dialog::Execute() ) == RET_OK )
{
if ( !m_pURL )
m_pURL = new INetURLObject();
else
*m_pURL = INetURLObject();
m_aCommands = GetPlugInOptions();
String aURL = GetPlugInFile();
// URL can be a valid and absolute URL or a system file name
m_pURL->SetSmartProtocol( INET_PROT_FILE );
if ( !aURL.Len() || m_pURL->SetSmartURL( aURL ) )
{
// create a plugin object
::rtl::OUString aName;
SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
m_xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aName );
}
if ( m_xObj.is() )
{
// set properties from dialog
if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
m_xObj->changeState( embed::EmbedStates::RUNNING );
uno::Reference < beans::XPropertySet > xSet( m_xObj->getComponent(), uno::UNO_QUERY );
if ( xSet.is() )
{
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PluginURL") ),
2009-10-31 00:36:06 +01:00
makeAny( ::rtl::OUString( m_pURL->GetMainURL( INetURLObject::NO_DECODE ) ) ) );
uno::Sequence< beans::PropertyValue > aCommandSequence;
Plugin_ImplFillCommandSequence( m_aCommands, aCommandSequence );
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PluginCommands") ), makeAny( aCommandSequence ) );
2009-10-31 00:36:06 +01:00
}
}
else
{
// PlugIn couldn't be created
2009-10-31 00:36:06 +01:00
// global Resource from svtools (former so3 resource)
String aErr( impl_getSvtResString( STR_ERROR_OBJNOCREATE_PLUGIN ) );
aErr.SearchAndReplace( rtl::OUString('%'), aURL );
2009-10-31 00:36:06 +01:00
ErrorBox( this, WB_3DLOOK | WB_OK, aErr ).Execute();
}
}
return nRet;
}
SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window *pParent,
const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage )
: InsertObjectDialog_Impl( pParent, "InsertFloatingFrameDialog", "cui/ui/insertfloatingframe.ui",
xStorage )
2009-10-31 00:36:06 +01:00
{
Init();
2009-10-31 00:36:06 +01:00
}
SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog( Window *pParent,
const uno::Reference < embed::XEmbeddedObject >& xObj )
: InsertObjectDialog_Impl( pParent, "InsertFloatingFrameDialog", "cui/ui/insertfloatingframe.ui",
uno::Reference < embed::XStorage >() )
2009-10-31 00:36:06 +01:00
{
m_xObj = xObj;
Init();
}
void SfxInsertFloatingFrameDialog::Init()
{
get(m_pEDName, "edname");
get(m_pEDURL, "edurl");
get(m_pBTOpen, "buttonbrowse");
get(m_pRBScrollingOn, "scrollbaron");
get(m_pRBScrollingOff, "scrollbaroff");
get(m_pRBScrollingAuto, "scrollbarauto");
get(m_pRBFrameBorderOn, "borderon");
get(m_pRBFrameBorderOff, "borderoff");
get(m_pFTMarginWidth, "widthlabel");
get(m_pNMMarginWidth, "width");
get(m_pCBMarginWidthDefault, "defaultwidth");
get(m_pFTMarginHeight, "heightlabel");
get(m_pNMMarginHeight, "height");
get(m_pCBMarginHeightDefault, "defaultheight");
2009-10-31 00:36:06 +01:00
Link aLink( STATIC_LINK( this, SfxInsertFloatingFrameDialog, CheckHdl ) );
m_pCBMarginWidthDefault->SetClickHdl( aLink );
m_pCBMarginHeightDefault->SetClickHdl( aLink );
2009-10-31 00:36:06 +01:00
m_pCBMarginWidthDefault->Check();
m_pCBMarginHeightDefault->Check();
m_pRBScrollingAuto->Check();
m_pRBFrameBorderOn->Check();
2009-10-31 00:36:06 +01:00
m_pBTOpen->SetClickHdl( STATIC_LINK( this, SfxInsertFloatingFrameDialog, OpenHdl ) );
2009-10-31 00:36:06 +01:00
}
short SfxInsertFloatingFrameDialog::Execute()
{
short nRet = RET_OK;
sal_Bool bOK = sal_False;
2009-10-31 00:36:06 +01:00
uno::Reference < beans::XPropertySet > xSet;
if ( m_xObj.is() )
{
try
{
if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
m_xObj->changeState( embed::EmbedStates::RUNNING );
xSet = uno::Reference < beans::XPropertySet >( m_xObj->getComponent(), uno::UNO_QUERY );
::rtl::OUString aStr;
uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameURL") ) );
2009-10-31 00:36:06 +01:00
if ( aAny >>= aStr )
m_pEDURL->SetText( aStr );
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameName") ) );
2009-10-31 00:36:06 +01:00
if ( aAny >>= aStr )
m_pEDName->SetText( aStr );
2009-10-31 00:36:06 +01:00
sal_Int32 nSize = SIZE_NOT_SET;
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameMarginWidth") ) );
2009-10-31 00:36:06 +01:00
aAny >>= nSize;
if ( nSize == SIZE_NOT_SET )
{
m_pCBMarginWidthDefault->Check( sal_True );
m_pNMMarginWidth->SetText( String::CreateFromInt32( DEFAULT_MARGIN_WIDTH ) );
m_pFTMarginWidth->Enable( sal_False );
m_pNMMarginWidth->Enable( sal_False );
2009-10-31 00:36:06 +01:00
}
else
m_pNMMarginWidth->SetText( String::CreateFromInt32( nSize ) );
2009-10-31 00:36:06 +01:00
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameMarginHeight") ) );
2009-10-31 00:36:06 +01:00
aAny >>= nSize;
if ( nSize == SIZE_NOT_SET )
{
m_pCBMarginHeightDefault->Check( sal_True );
m_pNMMarginHeight->SetText( String::CreateFromInt32( DEFAULT_MARGIN_HEIGHT ) );
m_pFTMarginHeight->Enable( sal_False );
m_pNMMarginHeight->Enable( sal_False );
2009-10-31 00:36:06 +01:00
}
else
m_pNMMarginHeight->SetText( String::CreateFromInt32( nSize ) );
2009-10-31 00:36:06 +01:00
sal_Bool bScrollOn = sal_False;
sal_Bool bScrollOff = sal_False;
sal_Bool bScrollAuto = sal_False;
2009-10-31 00:36:06 +01:00
sal_Bool bSet = sal_False;
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsAutoScroll") ) );
2009-10-31 00:36:06 +01:00
aAny >>= bSet;
if ( !bSet )
{
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsScrollingMode") ) );
2009-10-31 00:36:06 +01:00
aAny >>= bSet;
bScrollOn = bSet;
bScrollOff = !bSet;
}
else
bScrollAuto = sal_True;
2009-10-31 00:36:06 +01:00
m_pRBScrollingOn->Check( bScrollOn );
m_pRBScrollingOff->Check( bScrollOff );
m_pRBScrollingAuto->Check( bScrollAuto );
2009-10-31 00:36:06 +01:00
bSet = sal_False;
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsAutoBorder") ) );
2009-10-31 00:36:06 +01:00
aAny >>= bSet;
if ( !bSet )
{
aAny = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsBorder") ) );
2009-10-31 00:36:06 +01:00
aAny >>= bSet;
m_pRBFrameBorderOn->Check( bSet );
m_pRBFrameBorderOff->Check( !bSet );
2009-10-31 00:36:06 +01:00
}
SetUpdateMode( sal_True );
bOK = sal_True;
2009-10-31 00:36:06 +01:00
}
catch ( uno::Exception& )
{
2011-03-01 17:55:09 +01:00
OSL_FAIL( "No IFrame!" );
2009-10-31 00:36:06 +01:00
}
}
else
{
DBG_ASSERT( m_xStorage.is(), "No storage!");
bOK = m_xStorage.is();
}
if ( bOK && ( nRet = Dialog::Execute() ) == RET_OK )
{
::rtl::OUString aURL;
if ( m_pEDURL->GetText().Len() )
2009-10-31 00:36:06 +01:00
{
// URL can be a valid and absolute URL or a system file name
INetURLObject aObj;
aObj.SetSmartProtocol( INET_PROT_FILE );
if ( aObj.SetSmartURL( m_pEDURL->GetText() ) )
2009-10-31 00:36:06 +01:00
aURL = aObj.GetMainURL( INetURLObject::NO_DECODE );
}
if ( !m_xObj.is() && !aURL.isEmpty() )
2009-10-31 00:36:06 +01:00
{
// create the object
::rtl::OUString aName;
SvGlobalName aClassId( SO3_IFRAME_CLASSID );
m_xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aName );
if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
m_xObj->changeState( embed::EmbedStates::RUNNING );
xSet = uno::Reference < beans::XPropertySet >( m_xObj->getComponent(), uno::UNO_QUERY );
}
if ( m_xObj.is() )
{
try
{
sal_Bool bIPActive = m_xObj->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE;
2009-10-31 00:36:06 +01:00
if ( bIPActive )
m_xObj->changeState( embed::EmbedStates::RUNNING );
::rtl::OUString aName = m_pEDName->GetText();
2009-10-31 00:36:06 +01:00
ScrollingMode eScroll = ScrollingNo;
if ( m_pRBScrollingOn->IsChecked() )
2009-10-31 00:36:06 +01:00
eScroll = ScrollingYes;
if ( m_pRBScrollingOff->IsChecked() )
2009-10-31 00:36:06 +01:00
eScroll = ScrollingNo;
if ( m_pRBScrollingAuto->IsChecked() )
2009-10-31 00:36:06 +01:00
eScroll = ScrollingAuto;
sal_Bool bHasBorder = m_pRBFrameBorderOn->IsChecked();
2009-10-31 00:36:06 +01:00
long lMarginWidth;
if ( !m_pCBMarginWidthDefault->IsChecked() )
lMarginWidth = (long) m_pNMMarginWidth->GetText().ToInt32();
2009-10-31 00:36:06 +01:00
else
lMarginWidth = SIZE_NOT_SET;
long lMarginHeight;
if ( !m_pCBMarginHeightDefault->IsChecked() )
lMarginHeight = (long) m_pNMMarginHeight->GetText().ToInt32();
2009-10-31 00:36:06 +01:00
else
lMarginHeight = SIZE_NOT_SET;
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameURL") ), makeAny( aURL ) );
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameName") ), makeAny( aName ) );
2009-10-31 00:36:06 +01:00
if ( eScroll == ScrollingAuto )
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsAutoScroll") ),
2009-10-31 00:36:06 +01:00
makeAny( sal_True ) );
else
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsScrollingMode") ),
2009-10-31 00:36:06 +01:00
makeAny( (sal_Bool) ( eScroll == ScrollingYes) ) );
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameIsBorder") ),
2009-10-31 00:36:06 +01:00
makeAny( bHasBorder ) );
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameMarginWidth") ),
2009-10-31 00:36:06 +01:00
makeAny( sal_Int32( lMarginWidth ) ) );
xSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameMarginHeight") ),
2009-10-31 00:36:06 +01:00
makeAny( sal_Int32( lMarginHeight ) ) );
if ( bIPActive )
m_xObj->changeState( embed::EmbedStates::INPLACE_ACTIVE );
}
catch ( uno::Exception& )
{
2011-03-01 17:55:09 +01:00
OSL_FAIL( "No IFrame!" );
2009-10-31 00:36:06 +01:00
}
}
}
return nRet;
}
//------------------------------------------------------------------------------
IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog, CheckHdl, CheckBox*, pCB )
{
if ( pCB == pThis->m_pCBMarginWidthDefault )
2009-10-31 00:36:06 +01:00
{
if ( pCB->IsChecked() )
pThis->m_pNMMarginWidth->SetText( String::CreateFromInt32( DEFAULT_MARGIN_WIDTH ) );
pThis->m_pFTMarginWidth->Enable( !pCB->IsChecked() );
pThis->m_pNMMarginWidth->Enable( !pCB->IsChecked() );
2009-10-31 00:36:06 +01:00
}
if ( pCB == pThis->m_pCBMarginHeightDefault )
2009-10-31 00:36:06 +01:00
{
if ( pCB->IsChecked() )
pThis->m_pNMMarginHeight->SetText( String::CreateFromInt32( DEFAULT_MARGIN_HEIGHT ) );
pThis->m_pFTMarginHeight->Enable( !pCB->IsChecked() );
pThis->m_pNMMarginHeight->Enable( !pCB->IsChecked() );
2009-10-31 00:36:06 +01:00
}
return 0L;
}
//------------------------------------------------------------------------------
IMPL_STATIC_LINK( SfxInsertFloatingFrameDialog, OpenHdl, PushButton*, EMPTYARG )
{
Window* pOldParent = Application::GetDefDialogParent();
Application::SetDefDialogParent( pThis );
// create the file dialog
sfx2::FileDialogHelper aFileDlg(
ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0, String() );
2009-10-31 00:36:06 +01:00
// set the title
aFileDlg.SetTitle(CUI_RESSTR(RID_SVXSTR_SELECT_FILE_IFRAME));
2009-10-31 00:36:06 +01:00
// show the dialog
if ( aFileDlg.Execute() == ERRCODE_NONE )
pThis->m_pEDURL->SetText(
2009-10-31 00:36:06 +01:00
INetURLObject( aFileDlg.GetPath() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
Application::SetDefDialogParent( pOldParent );
return 0L;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */