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: impgrf.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"
33 // include ------------------------------------------------------------------
35 #include <limits.h> // USHRT_MAX
36 #include <tools/urlobj.hxx>
37 #include <tools/bigint.hxx>
38 #include <svtools/eitem.hxx>
39 #include <svtools/stritem.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <vcl/waitobj.hxx>
44 #include <svtools/pathoptions.hxx>
45 #include <svtools/viewoptions.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include <ucbhelper/content.hxx>
48 #include <osl/file.hxx>
49 #include <com/sun/star/ucb/CommandAbortedException.hpp>
51 using namespace ::ucbhelper
;
52 using namespace com::sun::star::uno
;
54 #include <svx/dialogs.hrc>
57 #define _SVX_IMPGRF_CXX
60 #include <svx/dialmgr.hxx>
64 // defines ---------------------------------------------------------------
66 #define IMPGRF_INIKEY_ASLINK "ImportGraphicAsLink"
67 #define IMPGRF_INIKEY_PREVIEW "ImportGraphicPreview"
68 #define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("ImportGraphicDialog"))
70 GraphicFilter
* GetGrfFilter()
72 return GraphicFilter::GetGraphicFilter();
75 // -----------------------------------------------------------------------
77 int LoadGraphic( const String
&rPath
, const String
&rFilterName
,
78 Graphic
& rGraphic
, GraphicFilter
* pFilter
,
79 USHORT
* pDeterminedFormat
)
82 pFilter
= ::GetGrfFilter();
84 const USHORT nFilter
= rFilterName
.Len() && pFilter
->GetImportFormatCount()
85 ? pFilter
->GetImportFormatNumber( rFilterName
)
86 : GRFILTER_FORMAT_DONTKNOW
;
90 // dann teste mal auf File-Protokoll:
91 SvStream
* pStream
= NULL
;
92 INetURLObject
aURL( rPath
);
94 if ( aURL
.HasError() || INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
96 aURL
.SetSmartProtocol( INET_PROT_FILE
);
97 aURL
.SetSmartURL( rPath
);
99 else if ( INET_PROT_FILE
!= aURL
.GetProtocol() )
101 // z.Z. nur auf die aktuelle DocShell
102 pMed
= new SfxMedium( rPath
, STREAM_READ
, TRUE
);
104 pStream
= pMed
->GetInStream();
106 int nRes
= GRFILTER_OK
;
109 nRes
= pFilter
->ImportGraphic( rGraphic
, aURL
, nFilter
, pDeterminedFormat
);
111 nRes
= pFilter
->ImportGraphic( rGraphic
, rPath
, *pStream
,
112 nFilter
, pDeterminedFormat
);
119 DBG_WARNING3( "GrafikFehler [%d] - [%s] URL[%s]",
121 pMed
->GetPhysicalName().GetBuffer(),
126 DBG_WARNING2( "GrafikFehler [%d] - [%s]", nRes
, rPath
.GetBuffer() );