summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <thb@openoffice.org>2001-06-21 14:47:37 +0000
committerThorsten Behrens <thb@openoffice.org>2001-06-21 14:47:37 +0000
commit76bfd8d2c5bf62b01021d02f9661d9fab307ef39 (patch)
tree3ffe607e6ed9f2c1ded1664c9bb6b79c6b8f8a31
parent663e92ac6029d7cc690ff66fe959d6ff4c902a0d (diff)
#87126# Replacement for SvxImportGraphicsDialog
-rw-r--r--svx/inc/opengrf.hxx97
-rw-r--r--svx/prj/d.lst1
-rw-r--r--svx/source/dialog/makefile.mk9
-rw-r--r--svx/source/dialog/opengrf.cxx348
4 files changed, 452 insertions, 3 deletions
diff --git a/svx/inc/opengrf.hxx b/svx/inc/opengrf.hxx
new file mode 100644
index 000000000000..b64701ad44fc
--- /dev/null
+++ b/svx/inc/opengrf.hxx
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * $RCSfile: opengrf.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: thb $ $Date: 2001-06-21 15:47:36 $
+ *
+ * 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 _SVX_OPENGRF_HXX
+#define _SVX_OPENGRF_HXX
+
+#include <memory> // auto_ptr
+
+#ifndef _FILTER_HXX
+#include <svtools/filter.hxx>
+#endif
+
+
+struct SvxOpenGrf_Impl;
+
+class SvxOpenGraphicDialog
+{
+public:
+ SvxOpenGraphicDialog ( const String& rTitle );
+ ~SvxOpenGraphicDialog ();
+
+ short Execute();
+ void SetPath( const String& rPath );
+
+ sal_Bool IsAsLink() const;
+
+ int GetGraphic(Graphic&) const;
+ String GetPath() const;
+ String GetCurrentFilter() const;
+
+private:
+ // disable copy and assignment
+ SvxOpenGraphicDialog (const SvxOpenGraphicDialog&);
+ SvxOpenGraphicDialog& operator = ( const SvxOpenGraphicDialog & );
+
+ const std::auto_ptr< SvxOpenGrf_Impl > mpImpl;
+};
+
+#endif // _SVX_OPENGRF_HXX
+
diff --git a/svx/prj/d.lst b/svx/prj/d.lst
index 2949c03ff625..607654f386eb 100644
--- a/svx/prj/d.lst
+++ b/svx/prj/d.lst
@@ -142,6 +142,7 @@ hedabu: ..\inc\hyznitem.hxx %_DEST%\inc%_EXT%\svx\hyznitem.hxx
hedabu: ..\inc\ifaceids.hxx %_DEST%\inc%_EXT%\svx\ifaceids.hxx
hedabu: ..\inc\imapdlg.hxx %_DEST%\inc%_EXT%\svx\imapdlg.hxx
hedabu: ..\inc\impgrf.hxx %_DEST%\inc%_EXT%\svx\impgrf.hxx
+hedabu: ..\inc\opengrf.hxx %_DEST%\inc%_EXT%\svx\opengrf.hxx
hedabu: ..\inc\insctrl.hxx %_DEST%\inc%_EXT%\svx\insctrl.hxx
hedabu: ..\inc\itemdata.hxx %_DEST%\inc%_EXT%\svx\itemdata.hxx
hedabu: ..\inc\itemwin.hxx %_DEST%\inc%_EXT%\svx\itemwin.hxx
diff --git a/svx/source/dialog/makefile.mk b/svx/source/dialog/makefile.mk
index fe1638166f2e..3a11bb271bd4 100644
--- a/svx/source/dialog/makefile.mk
+++ b/svx/source/dialog/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.10 $
+# $Revision: 1.11 $
#
-# last change: $Author: dr $ $Date: 2001-06-14 16:14:55 $
+# last change: $Author: thb $ $Date: 2001-06-21 15:47:37 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -146,6 +146,7 @@ CXXFILES = \
imapdlg.cxx \
imapwnd.cxx \
impgrf.cxx \
+ opengrf.cxx \
labdlg.cxx \
langbox.cxx \
langtab.cxx \
@@ -300,6 +301,7 @@ SLOFILES=\
$(SLO)$/hdft.obj \
$(SLO)$/hyphen.obj \
$(SLO)$/impgrf.obj \
+ $(SLO)$/opengrf.obj \
$(SLO)$/labdlg.obj \
$(SLO)$/langtab.obj \
$(SLO)$/langbox.obj \
@@ -354,8 +356,9 @@ EXCEPTIONSFILES=\
$(SLO)$/hltpbase.obj \
$(SLO)$/hldocntp.obj \
$(SLO)$/hlmarkwn.obj \
+ $(SLO)$/opengrf.obj \
$(SLO)$/hyphen.obj \
- $(SLO)$/rubydialog.obj \
+ $(SLO)$/rubydialog.obj \
$(SLO)$/thesdlg.obj \
$(SLO)$/spldlg.obj \
$(SLO)$/numpages.obj \
diff --git a/svx/source/dialog/opengrf.cxx b/svx/source/dialog/opengrf.cxx
new file mode 100644
index 000000000000..708bd5b22a71
--- /dev/null
+++ b/svx/source/dialog/opengrf.cxx
@@ -0,0 +1,348 @@
+/*************************************************************************
+ *
+ * $RCSfile: opengrf.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: thb $ $Date: 2001-06-21 15:47:37 $
+ *
+ * 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <tools/urlobj.hxx>
+
+#ifndef _CPPUHELPER_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
+#include <com/sun/star/uno/Reference.h>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UI_DIALOGS_COMMONFILEPICKERELEMENTIDS_HPP_
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_FILEPREVIEWIMAGEFORMATS_HPP_
+#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_LISTBOXCONTROLACTIONS_HPP_
+#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_TEMPLATEDESCRIPTION_HPP_
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERLISTENER_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERNOTIFIER_HPP_
+#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPREVIEW_HPP_
+#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILTERMANAGER_HPP_
+#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
+#endif
+#ifndef SVTOOLS_URIHELPER_HXX
+#include <svtools/urihelper.hxx>
+#endif
+#ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
+#include <unotools/ucbstreamhelper.hxx>
+#endif
+#ifndef _TRANSFER_HXX //autogen
+#include <svtools/transfer.hxx>
+#endif
+#ifndef _SVDOGRAF_HXX //autogen
+#include <svx/svdograf.hxx>
+#endif
+#ifndef _SVSTOR_HXX //autogen
+#include <so3/svstor.hxx>
+#endif
+#ifndef _SOT_FORMATS_HXX //autogen
+#include <sot/formats.hxx>
+#endif
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#ifndef _FILEDLGHELPER_HXX
+#include <sfx2/filedlghelper.hxx>
+#endif
+#ifndef _SFXDOCFILE_HXX
+#include <sfx2/docfile.hxx>
+#endif
+
+#ifndef _SVX_OPENGRF_HXX
+#include "opengrf.hxx"
+#endif
+
+#include "dialogs.hrc"
+#include "impgrf.hrc"
+
+
+//-----------------------------------------------------------------------------
+
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::uno;
+using namespace ::rtl;
+using namespace ::cppu;
+
+
+//-----------------------------------------------------------------------------
+
+USHORT SvxOpenGrfErr2ResId( short err )
+{
+ switch( err )
+ {
+ case GRFILTER_OPENERROR:
+ return STR_GRFILTER_OPENERROR;
+ case GRFILTER_IOERROR:
+ return STR_GRFILTER_IOERROR;
+ case GRFILTER_VERSIONERROR:
+ return STR_GRFILTER_VERSIONERROR;
+ case GRFILTER_FILTERERROR:
+ return STR_GRFILTER_FILTERERROR;
+ case GRFILTER_FORMATERROR:
+ default:
+ return STR_GRFILTER_FORMATERROR;
+ }
+}
+
+
+struct SvxOpenGrf_Impl
+{
+ SvxOpenGrf_Impl ();
+
+ sfx2::FileDialogHelper aFileDlg;
+ Reference < XFilePickerControlAccess > xCtrlAcc;
+};
+
+
+SvxOpenGrf_Impl::SvxOpenGrf_Impl() :
+ aFileDlg(SFXWB_GRAPHIC)
+{
+ Reference < XFilePicker > xFP = aFileDlg.GetFilePicker();
+ xCtrlAcc = Reference < XFilePickerControlAccess >(xFP, UNO_QUERY);
+}
+
+
+SvxOpenGraphicDialog::SvxOpenGraphicDialog( const String& rTitle ) :
+ mpImpl( new SvxOpenGrf_Impl )
+{
+ mpImpl->aFileDlg.SetTitle(rTitle);
+}
+
+
+SvxOpenGraphicDialog::~SvxOpenGraphicDialog()
+{
+}
+
+
+GraphicFilter* GetGrfFilter();
+
+short SvxOpenGraphicDialog::Execute()
+{
+ USHORT nImpRet;
+ BOOL bQuitLoop=FALSE;
+
+ while( bQuitLoop == FALSE &&
+ mpImpl->aFileDlg.Execute() == ERRCODE_NONE )
+ {
+ if( GetPath().Len() )
+ {
+ GraphicFilter* pFilter = GetGrfFilter();
+ INetURLObject aObj( GetPath() );
+
+ // check whether we can load the graphic
+ String aCurFilter( mpImpl->aFileDlg.GetCurrentFilter() );
+ USHORT nFormatNum = pFilter->GetImportFormatNumber( aCurFilter );
+ USHORT nRetFormat = 0;
+ USHORT nFound = USHRT_MAX;
+
+ if ( INET_PROT_FILE != aObj.GetProtocol() )
+ {
+ SfxMedium aMed( aObj.GetMainURL(), STREAM_READ, TRUE );
+ aMed.SetTransferPriority( SFX_TFPRIO_SYNCHRON );
+ aMed.DownLoad();
+ SvStream* pStream = aMed.GetInStream();
+
+ if( pStream )
+ nImpRet = pFilter->CanImportGraphic( aObj.GetMainURL(), *pStream, nFormatNum, &nRetFormat );
+ else
+ nImpRet = pFilter->CanImportGraphic( aObj, nFormatNum, &nRetFormat );
+
+ if ( GRFILTER_OK != nImpRet )
+ {
+ if ( !pStream )
+ nImpRet = pFilter->CanImportGraphic( aObj, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ else
+ nImpRet = pFilter->CanImportGraphic( aObj.GetMainURL(), *pStream,
+ GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ }
+ }
+ else
+ {
+ if( (nImpRet=pFilter->CanImportGraphic( aObj, nFormatNum, &nRetFormat )) != GRFILTER_OK )
+ nImpRet = pFilter->CanImportGraphic( aObj, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ }
+
+ if ( GRFILTER_OK == nImpRet )
+ nFound = nRetFormat;
+
+ // could not load?
+ if ( nFound == USHRT_MAX )
+ {
+ WarningBox aWarningBox( NULL, WB_3DLOOK | WB_RETRY_CANCEL, String(ResId(SvxOpenGrfErr2ResId(nImpRet))) );
+ bQuitLoop = aWarningBox.Execute()==RET_RETRY ? FALSE : TRUE;
+ }
+ else
+ {
+ // setup appropriate filter (so next time, it will work)
+ if( pFilter->GetImportFormatCount() )
+ {
+ mpImpl->aFileDlg.SetCurrentFilter(pFilter->GetImportFormatName(nFound));
+ }
+ }
+ }
+ }
+
+ return nImpRet;
+}
+
+
+void SvxOpenGraphicDialog::SetPath( const String& rPath )
+{
+ mpImpl->aFileDlg.SetDisplayDirectory(rPath);
+}
+
+
+sal_Bool SvxOpenGraphicDialog::IsAsLink() const
+{
+ Any aVal = mpImpl->xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 );
+ DBG_ASSERT(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found")
+ return aVal.hasValue() ? *(sal_Bool*) aVal.getValue() : sal_True;
+}
+
+
+int SvxOpenGraphicDialog::GetGraphic(Graphic& rGraphic) const
+{
+ GraphicFilter* pFilter = GetGrfFilter();
+ String aPath( GetPath() );
+
+ // select graphic filter from dialog filter selection
+ String aCurFilter( mpImpl->aFileDlg.GetCurrentFilter() );
+
+ const int nFilter = aCurFilter.Len() && pFilter->GetImportFormatCount()
+ ? pFilter->GetImportFormatNumber( aCurFilter )
+ : GRFILTER_FORMAT_DONTKNOW;
+
+ INetURLObject aURL( aPath );
+ int nRes(GRFILTER_OK);
+
+ if ( aURL.HasError() || INET_PROT_NOT_VALID == aURL.GetProtocol() )
+ {
+ aURL.SetSmartProtocol( INET_PROT_FILE );
+ aURL.SetSmartURL( aPath );
+
+ nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter );
+ }
+ else if ( INET_PROT_FILE != aURL.GetProtocol() )
+ {
+ SfxMedium aMed( aPath, STREAM_READ, TRUE );
+ SvStream* pStream = NULL;
+
+ aMed.SetTransferPriority( SFX_TFPRIO_SYNCHRON );
+ aMed.DownLoad();
+
+ if( (pStream = aMed.GetInStream()) )
+ nRes = pFilter->ImportGraphic( rGraphic, aPath, *pStream, nFilter );
+ else
+ nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter );
+ }
+
+ if( nRes )
+ {
+ WarningBox aWarningBox( NULL, WB_3DLOOK | WB_OK, String(ResId(SvxOpenGrfErr2ResId(nRes))) );
+ aWarningBox.Execute();
+ }
+
+ return nRes;
+}
+
+
+String SvxOpenGraphicDialog::GetPath() const
+{
+ return mpImpl->aFileDlg.GetPath();
+}
+
+
+String SvxOpenGraphicDialog::GetCurrentFilter() const
+{
+ return mpImpl->aFileDlg.GetCurrentFilter();
+}