tdf#124953: Use rangelist's combined range top-left address...
[LibreOffice.git] / include / svx / xmlgrhlp.hxx
blobf04c33e136bd032a1ea0cafcad68d1577c9e2ee5
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/compbase.hxx>
24 #include <osl/mutex.hxx>
25 #include <vcl/GraphicObject.hxx>
26 #include <rtl/ref.hxx>
27 #include <vector>
28 #include <set>
29 #include <unordered_map>
30 #include <utility>
31 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
32 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
33 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
34 #include <com/sun/star/embed/XStorage.hpp>
35 #include <svx/svxdllapi.h>
37 enum class SvXMLGraphicHelperMode
39 Read, Write
42 struct SvxGraphicHelperStream_Impl
44 css::uno::Reference < css::embed::XStorage > xStorage;
45 css::uno::Reference < css::io::XStream > xStream;
48 class SVX_DLLPUBLIC SvXMLGraphicHelper final : public cppu::WeakComponentImplHelper<css::document::XGraphicObjectResolver,
49 css::document::XGraphicStorageHandler,
50 css::document::XBinaryStreamResolver>
52 private:
53 typedef ::std::vector< css::uno::Reference< css::io::XOutputStream > > GraphicOutputStreamVector;
55 ::osl::Mutex maMutex;
56 css::uno::Reference < css::embed::XStorage > mxRootStorage;
57 OUString maCurStorageName;
58 GraphicOutputStreamVector maGrfStms;
60 std::unordered_map<OUString, css::uno::Reference<css::graphic::XGraphic>> maGraphicObjects;
61 std::unordered_map<Graphic, std::pair<OUString, OUString>> maExportGraphics;
62 std::unordered_map<void*, std::pair<OUString, OUString>> maExportPdf;
64 SvXMLGraphicHelperMode meCreateMode;
65 OUString maOutputMimeType;
67 SVX_DLLPRIVATE static bool ImplGetStreamNames( const OUString& rURLStr,
68 OUString& rPictureStorageName,
69 OUString& rPictureStreamName );
70 SVX_DLLPRIVATE css::uno::Reference < css::embed::XStorage >
71 ImplGetGraphicStorage( const OUString& rPictureStorageName );
72 SVX_DLLPRIVATE SvxGraphicHelperStream_Impl
73 ImplGetGraphicStream( const OUString& rPictureStorageName,
74 const OUString& rPictureStreamName );
75 SVX_DLLPRIVATE static OUString ImplGetGraphicMimeType( const OUString& rFileName );
76 SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
77 const OUString& rPictureStreamName );
79 SvXMLGraphicHelper();
80 virtual ~SvXMLGraphicHelper() override;
81 void Init( const css::uno::Reference < css::embed::XStorage >& xXMLStorage,
82 SvXMLGraphicHelperMode eCreateMode,
83 const OUString& rGraphicMimeType = OUString() );
85 virtual void SAL_CALL disposing() override;
87 SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
88 OUString & rOutMimeType, OUString const & rRequestName);
90 public:
91 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
93 static rtl::Reference<SvXMLGraphicHelper> Create( const css::uno::Reference < css::embed::XStorage >& rXMLStorage,
94 SvXMLGraphicHelperMode eCreateMode );
95 static rtl::Reference<SvXMLGraphicHelper> Create( SvXMLGraphicHelperMode eCreateMode,
96 const OUString& rMimeType = OUString() );
98 public:
100 // XGraphicObjectResolver
101 virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) override;
103 // XGraphicStorageHandler
104 virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
105 loadGraphic(OUString const & aURL) override;
107 virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
108 loadGraphicFromOutputStream(css::uno::Reference<css::io::XOutputStream> const & rxOutputStream) override;
110 virtual OUString SAL_CALL
111 saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
113 virtual OUString SAL_CALL
114 saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override;
116 virtual css::uno::Reference<css::io::XInputStream> SAL_CALL
117 createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override;
119 // XBinaryStreamResolver
120 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) override;
121 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL createOutputStream( ) override;
122 virtual OUString SAL_CALL resolveOutputStream( const css::uno::Reference< css::io::XOutputStream >& rxBinaryStream ) override;
125 #endif
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */