diff options
author | Niklas Nebel <nn@openoffice.org> | 2002-05-29 12:36:53 +0000 |
---|---|---|
committer | Niklas Nebel <nn@openoffice.org> | 2002-05-29 12:36:53 +0000 |
commit | 03a8a759055fb8ef24967578408d8c3193f3c209 (patch) | |
tree | 5b241de4fd236268466d06d15bc4f04e47f84424 | |
parent | cb025885ca24e8b24b0d1725f7ece62a4afa3849 (diff) |
#99038# call filter options dialogs from FilterOptionsDialog service instead of ConvertFrom/To
-rw-r--r-- | sc/inc/filtuno.hxx | 158 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 542 | ||||
-rw-r--r-- | sc/source/ui/inc/docsh.hxx | 8 | ||||
-rw-r--r-- | sc/source/ui/unoobj/appluno.cxx | 16 | ||||
-rw-r--r-- | sc/source/ui/unoobj/filtuno.cxx | 309 | ||||
-rw-r--r-- | sc/source/ui/unoobj/makefile.mk | 10 |
6 files changed, 663 insertions, 380 deletions
diff --git a/sc/inc/filtuno.hxx b/sc/inc/filtuno.hxx new file mode 100644 index 000000000000..e5f9606a0f6d --- /dev/null +++ b/sc/inc/filtuno.hxx @@ -0,0 +1,158 @@ +/************************************************************************* + * + * $RCSfile: filtuno.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2002-05-29 13:32:33 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef SC_FILTUNO_HXX +#define SC_FILTUNO_HXX + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_ +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#endif +#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_ +#include <com/sun/star/document/XImporter.hpp> +#endif +#ifndef _COM_SUN_STAR_DOCUMENT_XEXPORTER_HPP_ +#include <com/sun/star/document/XExporter.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE5_HXX_ +#include <cppuhelper/implbase5.hxx> +#endif + + +namespace com { namespace sun { namespace star { namespace io { + class XInputStream; +} } } } + + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + ScFilterOptionsObj_CreateInstance( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& ); + + +class ScFilterOptionsObj : public ::cppu::WeakImplHelper5< + ::com::sun::star::beans::XPropertyAccess, + ::com::sun::star::ui::dialogs::XExecutableDialog, + ::com::sun::star::document::XImporter, + ::com::sun::star::document::XExporter, + ::com::sun::star::lang::XServiceInfo > +{ +private: + ::rtl::OUString aFileName; + ::rtl::OUString aFilterName; + ::rtl::OUString aFilterOptions; + ::com::sun::star::uno::Reference< + ::com::sun::star::io::XInputStream > xInputStream; + sal_Bool bExport; + +public: + ScFilterOptionsObj(); + virtual ~ScFilterOptionsObj(); + + static ::rtl::OUString getImplementationName_Static(); + static ::com::sun::star::uno::Sequence< ::rtl::OUString> getSupportedServiceNames_Static(); + + // XPropertyAccess + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& aProps ) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + // XExecutableDialog + virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL execute() throw (::com::sun::star::uno::RuntimeException); + + // XImporter + virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& xDoc ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // XExporter + virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& xDoc ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException); +}; + + +#endif + diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 313e2b3534f6..89a5ee9eec48 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -2,9 +2,9 @@ * * $RCSfile: docsh.cxx,v $ * - * $Revision: 1.51 $ + * $Revision: 1.52 $ * - * last change: $Author: nn $ $Date: 2002-03-04 19:37:54 $ + * last change: $Author: nn $ $Date: 2002-05-29 13:36:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -842,7 +842,6 @@ BOOL __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium ) // SvStream* pStream = rMedium.GetInStream(); // if (pStream) { - FltError eError; String sItStr; SfxItemSet* pSet = rMedium.GetItemSet(); const SfxPoolItem* pItem; @@ -854,63 +853,27 @@ BOOL __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium ) if (sItStr.Len() == 0) { - String aTitle = ScGlobal::GetRscString( STR_IMPORT_LOTUS ); - ScImportOptions aOptions(59, 34, RTL_TEXTENCODING_IBM_437); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - FALSE, &aOptions, &aTitle, TRUE, FALSE ); - int nDlgRet; - { // WarteCursor aus und wieder einschalten - ScWaitCursorOff aWait( GetDialogParent() ); - nDlgRet = pDlg->Execute(); - } - if ( RET_OK == nDlgRet ) - { - pDlg->GetImportOptions( aOptions ); - SfxItemSet* pItemSet = rMedium.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, - aOptions.aStrFont)); - ScColumn::bDoubleAlloc = TRUE; - eError = ScImportLotus123( rMedium, &aDocument, - aOptions.eCharSet ); - ScColumn::bDoubleAlloc = FALSE; - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); + // default for lotus import (from API without options): + // IBM_437 encoding - if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) - bRet = TRUE; - } - else - bRet = TRUE; - } - else - { - // ConvertFrom lautlos abbrechen - SetError( ERRCODE_IO_ABORT ); - bRet = FALSE; - } - - delete pDlg; + sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_437 ); } - else + + ScColumn::bDoubleAlloc = TRUE; + FltError eError = ScImportLotus123( rMedium, &aDocument, + ScGlobal::GetCharsetValue(sItStr)); + ScColumn::bDoubleAlloc = FALSE; + if (eError != eERR_OK) { - ScColumn::bDoubleAlloc = TRUE; - eError = ScImportLotus123( rMedium, &aDocument, - ScGlobal::GetCharsetValue(sItStr)); - ScColumn::bDoubleAlloc = FALSE; - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); + if (!GetError()) + SetError(eError); - if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) - bRet = TRUE; - } - else + if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) bRet = TRUE; } + else + bRet = TRUE; + // rMedium.CloseInStream(); } } @@ -973,86 +936,49 @@ BOOL __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium ) if ( !bOptInit ) { - String aExt = rMedium.GetURLObject().getExtension(); - String aPrivDatName = rMedium.GetURLObject().getName(); - sal_Unicode cAsciiDel; - if (aExt.EqualsIgnoreCaseAscii("CSV")) - cAsciiDel = ','; - else - cAsciiDel = '\t'; + // default for ascii import (from API without options): + // ISO8859-1/MS_1252 encoding, comma, double quotes - SvStream* pInStream = rMedium.GetInStream(); - if (pInStream) - { - ScImportAsciiDlg* pDlg = new ScImportAsciiDlg( - NULL,aPrivDatName, - pInStream, cAsciiDel ); - int nDlgRet; - { // WarteCursor aus und wieder einschalten - ScWaitCursorOff aWait( GetDialogParent() ); - nDlgRet = pDlg->Execute(); - } - if ( nDlgRet == RET_OK ) - { - pDlg->GetOptions( aOptions ); + aOptions.SetCharSet( RTL_TEXTENCODING_MS_1252 ); + aOptions.SetFieldSeps( (sal_Unicode) ',' ); + aOptions.SetTextSep( (sal_Unicode) '"' ); + } - SfxItemSet* pItemSet = rMedium.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, aOptions.WriteToString() )); + FltError eError = eERR_OK; + BOOL bOverflow = FALSE; - bOptInit = TRUE; - } - else - { - // ConvertFrom lautlos abbrechen - SetError( ERRCODE_IO_ABORT ); - bRet = FALSE; - } + if( ! rMedium.IsStorage() ) + { + ScImportExport aImpEx( &aDocument ); + aImpEx.SetExtOptions( aOptions ); - delete pDlg; + SvStream* pInStream = rMedium.GetInStream(); + if (pInStream) + { + pInStream->SetStreamCharSet( aOptions.GetCharSet() ); + pInStream->Seek( 0 ); + bRet = aImpEx.ImportStream( *pInStream ); + eError = bRet ? eERR_OK : SCERR_IMPORT_CONNECT; + aDocument.StartAllListeners(); + aDocument.SetDirty(); + bOverflow = aImpEx.IsOverflow(); } else DBG_ERROR( "No Stream" ); } - if( bOptInit ) // Jetzt gesetzt ? + if (eError != eERR_OK) { - FltError eError = eERR_OK; - BOOL bOverflow = FALSE; - - if( ! rMedium.IsStorage() ) - { - ScImportExport aImpEx( &aDocument ); - aImpEx.SetExtOptions( aOptions ); - - SvStream* pInStream = rMedium.GetInStream(); - if (pInStream) - { - pInStream->SetStreamCharSet( aOptions.GetCharSet() ); - pInStream->Seek( 0 ); - bRet = aImpEx.ImportStream( *pInStream ); - eError = bRet ? eERR_OK : SCERR_IMPORT_CONNECT; - aDocument.StartAllListeners(); - aDocument.SetDirty(); - bOverflow = aImpEx.IsOverflow(); - } - else - DBG_ERROR( "No Stream" ); - } - - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); - } - else if ( bOverflow ) - { - if (!GetError()) - SetError(SCWARN_IMPORT_RANGE_OVERFLOW); - } - bSetColWidths = TRUE; - bSetSimpleTextColWidths = TRUE; + if (!GetError()) + SetError(eError); + } + else if ( bOverflow ) + { + if (!GetError()) + SetError(SCWARN_IMPORT_RANGE_OVERFLOW); } + bSetColWidths = TRUE; + bSetSimpleTextColWidths = TRUE; } else if (aFltName.EqualsAscii(pFilterDBase)) { @@ -1064,61 +990,27 @@ BOOL __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium ) { sItStr = ((const SfxStringItem*)pItem)->GetValue(); } + if (sItStr.Len() == 0) { - String aTitle = ScGlobal::GetRscString(STR_IMPORT_DBF); - ScImportOptions aOptions; - aOptions.SetTextEncoding( RTL_TEXTENCODING_IBM_850 ); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - FALSE, &aOptions, &aTitle, FALSE, TRUE ); - int nDlgRet; - { // WarteCursor aus und wieder einschalten - ScWaitCursorOff aWait( GetDialogParent() ); - nDlgRet = pDlg->Execute(); - } - if ( nDlgRet == RET_OK ) - { - pDlg->GetImportOptions( aOptions ); - SfxItemSet* pItemSet = rMedium.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, - aOptions.aStrFont)); + // default for dBase import (from API without options): + // IBM_850 encoding - ULONG eError = DBaseImport( rMedium.GetPhysicalName(), - aOptions.eCharSet, bSimpleColWidth ); + sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 ); + } - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); - bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW ); - } - else - bRet = TRUE; - } - else - { - // ConvertFrom lautlos abbrechen - SetError( ERRCODE_IO_ABORT ); - bRet = FALSE; - } + ULONG eError = DBaseImport( rMedium.GetPhysicalName(), + ScGlobal::GetCharsetValue(sItStr), bSimpleColWidth ); - delete pDlg; + if (eError != eERR_OK) + { + if (!GetError()) + SetError(eError); + bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW ); } else - { - ULONG eError = DBaseImport( rMedium.GetPhysicalName(), - ScGlobal::GetCharsetValue(sItStr), bSimpleColWidth ); + bRet = TRUE; - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); - bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW ); - } - else - bRet = TRUE; - } aColWidthRange.aStart.SetRow( 1 ); // Spaltenheader nicht bSetColWidths = TRUE; bSetSimpleTextColWidths = TRUE; @@ -1146,59 +1038,25 @@ BOOL __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium ) if (sItStr.Len() == 0) { - String aTitle = ScGlobal::GetRscString( STR_IMPORT_DIF ); - ScImportOptions aOptions(59, 34, RTL_TEXTENCODING_MS_1252); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - FALSE, &aOptions, &aTitle, TRUE, FALSE ); - int nDlgRet; - { // WarteCursor aus und wieder einschalten - ScWaitCursorOff aWait( GetDialogParent() ); - nDlgRet = pDlg->Execute(); - } - if ( RET_OK == nDlgRet ) - { - pDlg->GetImportOptions( aOptions ); - SfxItemSet* pItemSet = rMedium.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, - aOptions.aStrFont)); - eError = ScImportDif( *pStream, &aDocument, ScAddress(0,0,0), - aOptions.eCharSet); - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); - - if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) - bRet = TRUE; - } - else - bRet = TRUE; - } - else - { - // ConvertFrom lautlos abbrechen - SetError( ERRCODE_IO_ABORT ); - bRet = FALSE; - } + // default for DIF import (from API without options): + // ISO8859-1/MS_1252 encoding - delete pDlg; + sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 ); } - else + + eError = ScImportDif( *pStream, &aDocument, ScAddress(0,0,0), + ScGlobal::GetCharsetValue(sItStr)); + if (eError != eERR_OK) { - eError = ScImportDif( *pStream, &aDocument, ScAddress(0,0,0), - ScGlobal::GetCharsetValue(sItStr)); - if (eError != eERR_OK) - { - if (!GetError()) - SetError(eError); + if (!GetError()) + SetError(eError); - if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) - bRet = TRUE; - } - else + if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK ) bRet = TRUE; } + else + bRet = TRUE; + rMedium.CloseInStream(); } bSetColWidths = TRUE; @@ -1768,75 +1626,38 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) SvStream* pStream = rMed.GetOutStream(); if (pStream) { - sal_Unicode cAsciiDel; - sal_Unicode cStrDel; String sItStr; SfxItemSet* pSet = rMed.GetItemSet(); - - BOOL bShowDlg=FALSE; - BOOL bCancel=FALSE; - - const SfxPoolItem* pDlgItem; - if (pSet&& SFX_ITEM_SET == - pSet->GetItemState( SID_USE_FILTEROPTIONS, TRUE, &pDlgItem ) ) - { - bShowDlg=((const SfxBoolItem*)pDlgItem)->GetValue(); - } - const SfxPoolItem* pItem; if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS, TRUE, &pItem ) ) { sItStr = ((const SfxStringItem*)pItem)->GetValue(); } - if (sItStr.Len() == 0 || bShowDlg) - { - if (aDocument.GetTableCount() > 1) - if (!rMed.GetError()) - rMed.SetError(SCWARN_EXPORT_ASCII); - cStrDel = '"'; - String aExt = rMed.GetName().Copy(rMed.GetName().Len()-3, 3); - if (aExt.EqualsIgnoreCaseAscii("CSV")) - cAsciiDel = ','; - else - cAsciiDel = '\t'; - ScImportOptions aOptions((USHORT)cAsciiDel, (USHORT)cStrDel, RTL_TEXTENCODING_DONTKNOW); - String aTitle = ScGlobal::GetRscString( STR_EXPORT_ASCII ); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - TRUE, &aOptions, &aTitle, TRUE, FALSE ); - if ( pDlg->Execute() == RET_OK ) - { - WaitObject aWait( GetDialogParent() ); - pDlg->GetImportOptions( aOptions ); - cAsciiDel = (sal_Unicode) aOptions.nFieldSepCode; - cStrDel = (sal_Unicode) aOptions.nTextSepCode; - sItStr = aOptions.BuildString(); - SfxItemSet* pItemSet = rMed.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, sItStr)); - AsciiSave( *pStream, cAsciiDel, cStrDel, aOptions.eCharSet ); - } - else - { - bCancel = TRUE; - SetError( ERRCODE_IO_ABORT ); - } - delete pDlg; - } - else + + if ( sItStr.Len() == 0 ) { - WaitObject aWait( GetDialogParent() ); - ScImportOptions aOptions( sItStr ); - cAsciiDel = (sal_Unicode)aOptions.nFieldSepCode; - cStrDel = (sal_Unicode)aOptions.nTextSepCode; - AsciiSave( *pStream, cAsciiDel, cStrDel, aOptions.eCharSet ); + // default for ascii export (from API without options): + // ISO8859-1/MS_1252 encoding, comma, double quotes + + ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 ); + sItStr = aDefOptions.BuildString(); } - bRet = !bCancel; + + WaitObject aWait( GetDialogParent() ); + ScImportOptions aOptions( sItStr ); + sal_Unicode cAsciiDel = (sal_Unicode)aOptions.nFieldSepCode; + sal_Unicode cStrDel = (sal_Unicode)aOptions.nTextSepCode; + AsciiSave( *pStream, cAsciiDel, cStrDel, aOptions.eCharSet ); + bRet = TRUE; + + if (aDocument.GetTableCount() > 1) + if (!rMed.GetError()) + rMed.SetError(SCWARN_EXPORT_ASCII); } } else if (aFltName.EqualsAscii(pFilterDBase)) { - BOOL bCancel = FALSE; String sCharSet; SfxItemSet* pSet = rMed.GetItemSet(); const SfxPoolItem* pItem; @@ -1844,84 +1665,61 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) pSet->GetItemState( SID_FILE_FILTEROPTIONS, TRUE, &pItem ) ) { sCharSet = ((const SfxStringItem*)pItem)->GetValue(); - - if ( pSet->GetItemState( SID_USE_FILTEROPTIONS, TRUE, &pItem ) == SFX_ITEM_SET && - ((const SfxBoolItem*)pItem)->GetValue() ) - { - sCharSet.Erase(); // "edit options" - forget old - } } + if (sCharSet.Len() == 0) { - ScImportOptions aOptions(59, 34, RTL_TEXTENCODING_IBM_850); - String aTitle = ScGlobal::GetRscString( STR_EXPORT_DBF ); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - FALSE, &aOptions, &aTitle, FALSE, TRUE ); - if ( pDlg->Execute() == RET_OK ) - { - pDlg->GetImportOptions( aOptions ); - sCharSet = aOptions.aStrFont; - SfxItemSet* pItemSet = rMed.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, sCharSet)); - } - else - bCancel = TRUE; - delete pDlg; - } + // default for dBase export (from API without options): + // IBM_850 encoding - if ( bCancel ) - { - SetError( ERRCODE_IO_ABORT ); + sCharSet = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 ); } - else - { - WaitObject aWait( GetDialogParent() ); + + WaitObject aWait( GetDialogParent() ); // HACK damit Sba geoffnetes TempFile ueberschreiben kann - rMed.CloseOutStream(); - BOOL bHasMemo = FALSE; + rMed.CloseOutStream(); + BOOL bHasMemo = FALSE; - ULONG eError = DBaseExport( rMed.GetPhysicalName(), - ScGlobal::GetCharsetValue(sCharSet), bHasMemo ); + ULONG eError = DBaseExport( rMed.GetPhysicalName(), + ScGlobal::GetCharsetValue(sCharSet), bHasMemo ); - if ( eError != eERR_OK && (eError & ERRCODE_WARNING_MASK) ) - { -//! if ( !rMed.GetError() ) -//! rMed.SetError( eError ); - eError = eERR_OK; - } -//! else if ( aDocument.GetTableCount() > 1 && !rMed.GetError() ) -//! rMed.SetError( SCWARN_EXPORT_ASCII ); + if ( eError != eERR_OK && (eError & ERRCODE_WARNING_MASK) ) + { +//! if ( !rMed.GetError() ) +//! rMed.SetError( eError ); + eError = eERR_OK; + } +//! else if ( aDocument.GetTableCount() > 1 && !rMed.GetError() ) +//! rMed.SetError( SCWARN_EXPORT_ASCII ); - INetURLObject aTmpFile( rMed.GetPhysicalName(), INET_PROT_FILE ); + INetURLObject aTmpFile( rMed.GetPhysicalName(), INET_PROT_FILE ); + if ( bHasMemo ) + aTmpFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) ); + if ( eError != eERR_OK ) + { + if (!GetError()) + SetError(eError); + if ( bHasMemo && IsDocument( aTmpFile ) ) + KillFile( aTmpFile ); + } + else + { + bRet = TRUE; if ( bHasMemo ) - aTmpFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) ); - if ( eError != eERR_OK ) { - if (!GetError()) - SetError(eError); - if ( bHasMemo && IsDocument( aTmpFile ) ) - KillFile( aTmpFile ); - } - else - { - bRet = TRUE; - if ( bHasMemo ) + SfxStringItem* pNameItem = + (SfxStringItem*) rMed.GetItemSet()->GetItem( SID_FILE_NAME ); + INetURLObject aDbtFile( pNameItem->GetValue(), INET_PROT_FILE ); + aDbtFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) ); + if ( IsDocument( aDbtFile ) && !KillFile( aDbtFile ) ) + bRet = FALSE; + if ( bRet && !MoveFile( aTmpFile, aDbtFile ) ) + bRet = FALSE; + if ( !bRet ) { - SfxStringItem* pNameItem = - (SfxStringItem*) rMed.GetItemSet()->GetItem( SID_FILE_NAME ); - INetURLObject aDbtFile( pNameItem->GetValue(), INET_PROT_FILE ); - aDbtFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) ); - if ( IsDocument( aDbtFile ) && !KillFile( aDbtFile ) ) - bRet = FALSE; - if ( bRet && !MoveFile( aTmpFile, aDbtFile ) ) - bRet = FALSE; - if ( !bRet ) - { - KillFile( aTmpFile ); - if ( !GetError() ) - SetError( SCERR_EXPORT_DATA ); - } + KillFile( aTmpFile ); + if ( !GetError() ) + SetError( SCERR_EXPORT_DATA ); } } } @@ -1931,7 +1729,6 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) SvStream* pStream = rMed.GetOutStream(); if (pStream) { - BOOL bCancel = FALSE; String sItStr; SfxItemSet* pSet = rMed.GetItemSet(); const SfxPoolItem* pItem; @@ -1940,42 +1737,23 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) { sItStr = ((const SfxStringItem*)pItem)->GetValue(); } + if (sItStr.Len() == 0) { - if (aDocument.GetTableCount() > 1) - if (!rMed.GetError()) - rMed.SetError(SCWARN_EXPORT_ASCII); - - ScImportOptions aOptions(59, 34, RTL_TEXTENCODING_MS_1252); - String aTitle = ScGlobal::GetRscString( STR_EXPORT_DIF ); - ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, - FALSE, &aOptions, &aTitle, TRUE, FALSE ); - if ( pDlg->Execute() == RET_OK ) - { - WaitObject aWait( GetDialogParent() ); - pDlg->GetImportOptions( aOptions ); - SfxItemSet* pItemSet = rMed.GetItemSet(); - if (pItemSet) - pItemSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, - aOptions.aStrFont)); - USHORT nTab = GetSaveTab(); - ScExportDif( *pStream, &aDocument, ScAddress(0,0,nTab), - aOptions.eCharSet ); - } - else - { - bCancel = TRUE; - SetError( ERRCODE_IO_ABORT ); - } - delete pDlg; - } - else - { - WaitObject aWait( GetDialogParent() ); - ScExportDif( *pStream, &aDocument, ScAddress(0,0,0), - ScGlobal::GetCharsetValue(sItStr) ); + // default for DIF export (from API without options): + // ISO8859-1/MS_1252 encoding + + sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 ); } - bRet = !bCancel; + + WaitObject aWait( GetDialogParent() ); + ScExportDif( *pStream, &aDocument, ScAddress(0,0,0), + ScGlobal::GetCharsetValue(sItStr) ); + bRet = TRUE; + + if (aDocument.GetTableCount() > 1) + if (!rMed.GetError()) + rMed.SetError(SCWARN_EXPORT_ASCII); } } else if (aFltName.EqualsAscii(pFilterSylk)) @@ -2092,6 +1870,26 @@ String ScDocShell::GetWebQueryFilterName() // static return String::CreateFromAscii(pFilterHtmlWebQ); } +String ScDocShell::GetAsciiFilterName() // static +{ + return String::CreateFromAscii(pFilterAscii); +} + +String ScDocShell::GetLotusFilterName() // static +{ + return String::CreateFromAscii(pFilterLotus); +} + +String ScDocShell::GetDBaseFilterName() // static +{ + return String::CreateFromAscii(pFilterDBase); +} + +String ScDocShell::GetDifFilterName() // static +{ + return String::CreateFromAscii(pFilterDif); +} + BOOL ScDocShell::HasAutomaticTableName( const String& rFilter ) // static { // TRUE for those filters that keep the default table name diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index 9effce9b147b..35ae2622d5f4 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -2,9 +2,9 @@ * * $RCSfile: docsh.hxx,v $ * - * $Revision: 1.18 $ + * $Revision: 1.19 $ * - * last change: $Author: sab $ $Date: 2001-10-15 11:29:21 $ + * last change: $Author: nn $ $Date: 2002-05-29 13:35:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -394,6 +394,10 @@ public: static ScDocShell* GetShellByNum( USHORT nDocNo ); static String GetOwnFilterName(); static String GetWebQueryFilterName(); + static String GetAsciiFilterName(); + static String GetLotusFilterName(); + static String GetDBaseFilterName(); + static String GetDifFilterName(); static BOOL HasAutomaticTableName( const String& rFilter ); DECL_LINK( RefreshDBDataHdl, ScDBData* ); diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index 10e2b2478839..51cc623e30db 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: appluno.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: nn $ $Date: 2001-05-30 10:11:00 $ + * last change: $Author: nn $ $Date: 2002-05-29 13:34:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,6 +73,7 @@ #include "appluno.hxx" #include "afmtuno.hxx" #include "funcuno.hxx" +#include "filtuno.hxx" #include "miscuno.hxx" #include "scmod.hxx" #include "appoptio.hxx" @@ -241,6 +242,10 @@ sal_Bool SAL_CALL component_writeInfo( ScFunctionAccess::getSupportedServiceNames_Static() ); lcl_WriteInfo( pRegistryKey, + ScFilterOptionsObj::getImplementationName_Static(), + ScFilterOptionsObj::getSupportedServiceNames_Static() ); + + lcl_WriteInfo( pRegistryKey, ScXMLImport_getImplementationName(), ScXMLImport_getSupportedServiceNames() ); @@ -334,6 +339,13 @@ void * SAL_CALL component_getFactory( ScFunctionAccess_CreateInstance, ScFunctionAccess::getSupportedServiceNames_Static() ); + if ( aImpl == ScFilterOptionsObj::getImplementationName_Static() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScFilterOptionsObj::getImplementationName_Static(), + ScFilterOptionsObj_CreateInstance, + ScFilterOptionsObj::getSupportedServiceNames_Static() ); + if ( aImpl == ScXMLImport_getImplementationName() ) xFactory = cppu::createSingleFactory( reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx new file mode 100644 index 000000000000..7f2b74850f59 --- /dev/null +++ b/sc/source/ui/unoobj/filtuno.cxx @@ -0,0 +1,309 @@ +/************************************************************************* + * + * $RCSfile: filtuno.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2002-05-29 13:34:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifdef PCH +#include "ui_pch.hxx" +#endif + +#pragma hdrstop + +#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> +#include <tools/urlobj.hxx> +#include <vcl/msgbox.hxx> +#include <unotools/ucbstreamhelper.hxx> + +#include "filtuno.hxx" +#include "miscuno.hxx" +#include "unoguard.hxx" +#include "scdll.hxx" +#include "imoptdlg.hxx" +#include "asciiopt.hxx" +#include "docsh.hxx" +#include "globstr.hrc" + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +#define SCFILTEROPTIONSOBJ_SERVICE "com.sun.star.ui.dialogs.FilterOptionsDialog" +#define SCFILTEROPTIONSOBJ_IMPLNAME "com.sun.star.comp.Calc.FilterOptionsDialog" + +SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj, SCFILTEROPTIONSOBJ_IMPLNAME, SCFILTEROPTIONSOBJ_SERVICE ) + +#define SC_UNONAME_FILENAME "FileName" +#define SC_UNONAME_FILTERNAME "FilterName" +#define SC_UNONAME_FILTEROPTIONS "FilterOptions" +#define SC_UNONAME_INPUTSTREAM "InputStream" + +//------------------------------------------------------------------------ + +ScFilterOptionsObj::ScFilterOptionsObj() : + bExport( sal_False ) +{ +} + +ScFilterOptionsObj::~ScFilterOptionsObj() +{ +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScFilterOptionsObj_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& ) +{ + ScUnoGuard aGuard; + SC_DLL()->Load(); // load module + + return (::cppu::OWeakObject*) new ScFilterOptionsObj; +} + +rtl::OUString ScFilterOptionsObj::getImplementationName_Static() +{ + return rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_IMPLNAME ); +} + +uno::Sequence<rtl::OUString> ScFilterOptionsObj::getSupportedServiceNames_Static() +{ + uno::Sequence<rtl::OUString> aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_SERVICE ); + return aRet; +} + +// XPropertyAccess + +uno::Sequence<beans::PropertyValue> SAL_CALL ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException) +{ + uno::Sequence<beans::PropertyValue> aRet(1); + beans::PropertyValue* pArray = aRet.getArray(); + + pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_FILTEROPTIONS ); + pArray[0].Value <<= aFilterOptions; + + return aRet; +} + +void SAL_CALL ScFilterOptionsObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& aProps ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + const beans::PropertyValue* pPropArray = aProps.getConstArray(); + long nPropCount = aProps.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if ( aPropName.EqualsAscii( SC_UNONAME_FILENAME ) ) + rProp.Value >>= aFileName; + else if ( aPropName.EqualsAscii( SC_UNONAME_FILTERNAME ) ) + rProp.Value >>= aFilterName; + else if ( aPropName.EqualsAscii( SC_UNONAME_FILTEROPTIONS ) ) + rProp.Value >>= aFilterOptions; + else if ( aPropName.EqualsAscii( SC_UNONAME_INPUTSTREAM ) ) + rProp.Value >>= xInputStream; + } +} + +// XExecutableDialog + +void SAL_CALL ScFilterOptionsObj::setTitle( const ::rtl::OUString& aTitle ) throw(uno::RuntimeException) +{ + // not used +} + +sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException) +{ + sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL; + + String aFilterString( aFilterName ); + if ( !bExport && aFilterString == ScDocShell::GetAsciiFilterName() ) + { + // ascii import is special... + + INetURLObject aURL( aFileName ); + String aExt = aURL.getExtension(); + String aPrivDatName = aURL.getName(); + sal_Unicode cAsciiDel; + if (aExt.EqualsIgnoreCaseAscii("CSV")) + cAsciiDel = ','; + else + cAsciiDel = '\t'; + + SvStream* pInStream = NULL; + if ( xInputStream.is() ) + pInStream = utl::UcbStreamHelper::CreateStream( xInputStream ); + + ScImportAsciiDlg* pDlg = new ScImportAsciiDlg( NULL, aPrivDatName, pInStream, cAsciiDel ); + if ( pDlg->Execute() == RET_OK ) + { + ScAsciiOptions aOptions; + pDlg->GetOptions( aOptions ); + aFilterOptions = aOptions.WriteToString(); + nRet = ui::dialogs::ExecutableDialogResults::OK; + } + delete pDlg; + delete pInStream; + } + else + { + sal_Bool bMultiByte = sal_True; + sal_Bool bDBEnc = sal_False; + sal_Bool bAscii = sal_False; + + sal_Unicode cStrDel = '"'; + sal_Unicode cAsciiDel = ';'; + rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW; + + String aTitle; + + if ( aFilterString == ScDocShell::GetAsciiFilterName() ) + { + // ascii export (import is handled above) + + INetURLObject aURL( aFileName ); + String aExt = aURL.getExtension(); + if (aExt.EqualsIgnoreCaseAscii("CSV")) + cAsciiDel = ','; + else + cAsciiDel = '\t'; + + aTitle = ScGlobal::GetRscString( STR_EXPORT_ASCII ); + bAscii = sal_True; + } + else if ( aFilterString == ScDocShell::GetLotusFilterName() ) + { + // lotus is only imported + DBG_ASSERT( !bExport, "Filter Options for Lotus Export is not implemented" ); + + aTitle = ScGlobal::GetRscString( STR_IMPORT_LOTUS ); + eEncoding = RTL_TEXTENCODING_IBM_437; + } + else if ( aFilterString == ScDocShell::GetDBaseFilterName() ) + { + if ( bExport ) + { + // dBase export + aTitle = ScGlobal::GetRscString( STR_EXPORT_DBF ); + } + else + { + // dBase import + aTitle = ScGlobal::GetRscString( STR_IMPORT_DBF ); + } + // common for dBase import/export + eEncoding = RTL_TEXTENCODING_IBM_850; + bMultiByte = sal_False; + bDBEnc = sal_True; + } + else if ( aFilterString == ScDocShell::GetDifFilterName() ) + { + if ( bExport ) + { + // DIF export + aTitle = ScGlobal::GetRscString( STR_EXPORT_DIF ); + } + else + { + // DIF import + aTitle = ScGlobal::GetRscString( STR_IMPORT_DIF ); + } + // common for DIF import/export + eEncoding = RTL_TEXTENCODING_MS_1252; + } + + ScImportOptions aOptions((USHORT)cAsciiDel, (USHORT)cStrDel, eEncoding); + ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, bAscii, + &aOptions, &aTitle, bMultiByte, bDBEnc ); + + if ( pDlg->Execute() == RET_OK ) + { + pDlg->GetImportOptions( aOptions ); + if ( bAscii ) + aFilterOptions = aOptions.BuildString(); + else + aFilterOptions = aOptions.aStrFont; + nRet = ui::dialogs::ExecutableDialogResults::OK; + } + delete pDlg; + } + + xInputStream.clear(); // don't hold the stream longer than necessary + + return nRet; +} + +// XImporter + +void SAL_CALL ScFilterOptionsObj::setTargetDocument( const uno::Reference<lang::XComponent>& xDoc ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + bExport = sal_False; +} + +// XExporter + +void SAL_CALL ScFilterOptionsObj::setSourceDocument( const uno::Reference<lang::XComponent>& xDoc ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + bExport = sal_True; +} + diff --git a/sc/source/ui/unoobj/makefile.mk b/sc/source/ui/unoobj/makefile.mk index 44b5ae944d4f..ec612b8db9d9 100644 --- a/sc/source/ui/unoobj/makefile.mk +++ b/sc/source/ui/unoobj/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.9 $ +# $Revision: 1.10 $ # -# last change: $Author: nn $ $Date: 2001-04-06 14:36:18 $ +# last change: $Author: nn $ $Date: 2002-05-29 13:34:44 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -114,7 +114,8 @@ CXXFILES = \ convuno.cxx \ editsrc.cxx \ unoguard.cxx \ - confuno.cxx + confuno.cxx \ + filtuno.cxx SLOFILES = \ $(SLO)$/docuno.obj \ @@ -148,7 +149,8 @@ SLOFILES = \ $(SLO)$/convuno.obj \ $(SLO)$/editsrc.obj \ $(SLO)$/unoguard.obj \ - $(SLO)$/confuno.obj + $(SLO)$/confuno.obj \ + $(SLO)$/filtuno.obj # --- Tagets ------------------------------------------------------- |