update credits
[LibreOffice.git] / include / svx / xmlgrhlp.hxx
blobd14c9dc5cd232688cdf49f7c2ec241047ea33707
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 _XMLGRHLP_HXX
21 #define _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 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > ImplGetGraphicStorage( const OUString& rPictureStorageName );
78 SVX_DLLPRIVATE SvxGraphicHelperStream_Impl ImplGetGraphicStream( const OUString& rPictureStorageName,
79 const OUString& rPictureStreamName,
80 sal_Bool bTruncate );
81 SVX_DLLPRIVATE String ImplGetGraphicMimeType( const String& rFileName ) const;
82 SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
83 const OUString& rPictureStreamName );
84 SVX_DLLPRIVATE sal_Bool ImplWriteGraphic( const OUString& rPictureStorageName,
85 const OUString& rPictureStreamName,
86 const OUString& rGraphicId,
87 bool bUseGfxLink );
88 SVX_DLLPRIVATE void ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt32 nInsertPos, OUString& rRequestedFileName );
90 protected:
91 SvXMLGraphicHelper();
92 ~SvXMLGraphicHelper();
93 void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage,
94 SvXMLGraphicHelperMode eCreateMode,
95 sal_Bool bDirect );
97 virtual void SAL_CALL disposing();
99 public:
100 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
102 static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage,
103 SvXMLGraphicHelperMode eCreateMode,
104 sal_Bool bDirect = sal_True );
105 static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode );
107 static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper );
109 public:
111 // XGraphicObjectResolver
112 virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) throw(::com::sun::star::uno::RuntimeException);
114 // XBinaryStreamResolver
115 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) throw (::com::sun::star::uno::RuntimeException);
116 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException);
117 virtual OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException);
121 // for instantiation via service manager
122 namespace svx
124 /** Create this with createInstanceWithArguments. service name
125 "com.sun.star.comp.Svx.GraphicImportHelper", one argument which is the
126 XStorage. Without arguments no helper class is created. With an empty
127 argument the helper class is created and initialized like in the CTOR to
128 SvXMLGraphicHelper that only gets the create mode.
130 You should call dispose after you no longer need this component.
132 uses eCreateMode == GRAPHICHELPER_MODE_READ, bDirect == sal_True in
133 SvXMLGraphicHelper
135 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 );
136 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames() throw();
137 SVX_DLLPUBLIC OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName() throw();
139 /** Create this with createInstanceWithArguments. service name
140 "com.sun.star.comp.Svx.GraphicExportHelper", one argument which is the
141 XStorage. Without arguments no helper class is created. With an empty
142 argument the helper class is created and initialized like in the CTOR to
143 SvXMLGraphicHelper that only gets the create mode
145 To write the Pictures stream, you have to call dispose at this component.
146 Make sure you call dipose before you commit the parent storage.
148 uses eCreateMode == GRAPHICHELPER_MODE_WRITE, bDirect == sal_True in
149 SvXMLGraphicHelper
151 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 );
152 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames() throw();
153 SVX_DLLPUBLIC OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName() throw();
156 #endif
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */