bump product version to 4.2.0.1
[LibreOffice.git] / include / svx / xmlgrhlp.hxx
blob7e399b0f47ef3c877767c817819eb80acdc2712c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_XMLGRHLP_HXX
21 #define INCLUDED_SVX_XMLGRHLP_HXX
23 #include <cppuhelper/compbase2.hxx>
24 #include <osl/mutex.hxx>
25 #include <svtools/grfmgr.hxx>
26 #include <vector>
27 #include <set>
28 #include <utility>
29 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
30 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
31 #include <com/sun/star/embed/XStorage.hpp>
32 #include <svx/svxdllapi.h>
34 // ----------------------
35 // - SvXMLGraphicHelper -
36 // ----------------------
38 enum SvXMLGraphicHelperMode
40 GRAPHICHELPER_MODE_READ = 0,
41 GRAPHICHELPER_MODE_WRITE = 1
44 // ----------------------
45 // - SvXMLGraphicHelper -
46 // ----------------------
47 struct SvxGraphicHelperStream_Impl
49 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > xStorage;
50 ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > xStream;
53 class SVX_DLLPUBLIC SvXMLGraphicHelper : public ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
54 ::com::sun::star::document::XBinaryStreamResolver >
56 private:
58 typedef ::std::pair< OUString, OUString > URLPair;
59 typedef ::std::vector< URLPair > URLPairVector;
60 typedef ::std::vector< GraphicObject > GraphicObjectVector;
61 typedef ::std::set< OUString > URLSet;
62 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > > GraphicOutputStreamVector;
64 ::osl::Mutex maMutex;
65 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > mxRootStorage;
66 OUString maCurStorageName;
67 URLPairVector maGrfURLs;
68 GraphicObjectVector maGrfObjs;
69 GraphicOutputStreamVector maGrfStms;
70 URLSet maURLSet;
71 SvXMLGraphicHelperMode meCreateMode;
72 sal_Bool mbDirect;
74 SVX_DLLPRIVATE sal_Bool ImplGetStreamNames( const OUString& rURLStr,
75 OUString& rPictureStorageName,
76 OUString& rPictureStreamName );
77 SVX_DLLPRIVATE css::uno::Reference < css::embed::XStorage >
78 ImplGetGraphicStorage( const OUString& rPictureStorageName );
79 SVX_DLLPRIVATE SvxGraphicHelperStream_Impl
80 ImplGetGraphicStream( const OUString& rPictureStorageName,
81 const OUString& rPictureStreamName,
82 sal_Bool bTruncate );
83 SVX_DLLPRIVATE OUString ImplGetGraphicMimeType( const OUString& rFileName ) const;
84 SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
85 const OUString& rPictureStreamName );
86 SVX_DLLPRIVATE sal_Bool ImplWriteGraphic( const OUString& rPictureStorageName,
87 const OUString& rPictureStreamName,
88 const OUString& rGraphicId,
89 bool bUseGfxLink );
90 SVX_DLLPRIVATE void ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt32 nInsertPos, OUString& rRequestedFileName );
92 protected:
93 SvXMLGraphicHelper();
94 ~SvXMLGraphicHelper();
95 void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage,
96 SvXMLGraphicHelperMode eCreateMode,
97 sal_Bool bDirect );
99 virtual void SAL_CALL disposing();
101 public:
102 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
104 static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage,
105 SvXMLGraphicHelperMode eCreateMode,
106 sal_Bool bDirect = sal_True );
107 static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode );
109 static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper );
111 public:
113 // XGraphicObjectResolver
114 virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) throw(::com::sun::star::uno::RuntimeException);
116 // XBinaryStreamResolver
117 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) throw (::com::sun::star::uno::RuntimeException);
118 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException);
119 virtual OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException);
123 // for instantiation via service manager
124 namespace svx
126 /** Create this with createInstanceWithArguments. service name
127 "com.sun.star.comp.Svx.GraphicImportHelper", one argument which is the
128 XStorage. Without arguments no helper class is created. With an empty
129 argument the helper class is created and initialized like in the CTOR to
130 SvXMLGraphicHelper that only gets the create mode.
132 You should call dispose after you no longer need this component.
134 uses eCreateMode == GRAPHICHELPER_MODE_READ, bDirect == sal_True in
135 SvXMLGraphicHelper
137 SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicImportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception );
138 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames() throw();
139 SVX_DLLPUBLIC OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName() throw();
141 /** Create this with createInstanceWithArguments. service name
142 "com.sun.star.comp.Svx.GraphicExportHelper", one argument which is the
143 XStorage. Without arguments no helper class is created. With an empty
144 argument the helper class is created and initialized like in the CTOR to
145 SvXMLGraphicHelper that only gets the create mode
147 To write the Pictures stream, you have to call dispose at this component.
148 Make sure you call dipose before you commit the parent storage.
150 uses eCreateMode == GRAPHICHELPER_MODE_WRITE, bDirect == sal_True in
151 SvXMLGraphicHelper
153 SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicExportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception );
154 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames() throw();
155 SVX_DLLPUBLIC OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName() throw();
158 #endif
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */