try to avoid scaling bitmaps twice in Skia when drawing
[LibreOffice.git] / include / unotools / mediadescriptor.hxx
blob1e4b3c064d1c78c5a8f5f43803e35be8d7c374a0
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_UNOTOOLS_MEDIADESCRIPTOR_HXX
21 #define INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX
23 #include <sal/config.h>
25 #include <vector>
27 #include <comphelper/docpasswordrequest.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <rtl/ustring.hxx>
30 #include <unotools/unotoolsdllapi.h>
32 namespace com::sun::star::io {
33 class XInputStream;
35 namespace comphelper { class IDocPasswordVerifier; }
37 namespace utl {
39 /** @short can be used to work with a css::document::MediaDescriptor
40 struct.
42 @descr It wraps an unordered_map around the Sequence< css::beans::PropertyValue >, which
43 represent the MediaDescriptor item.
44 Further this helper defines often used functions (as e.g. open of the required streams,
45 consistent checks etcpp.) and it defines all usable property names.
47 @attention This class isn't threadsafe and must be guarded from outside!
49 class UNOTOOLS_DLLPUBLIC MediaDescriptor : public comphelper::SequenceAsHashMap
51 public:
53 /** @short these methods can be used to get the different property names
54 as static const OUString values.
56 @descr Because definition and declaration of static const class members
57 does not work as expected under windows (under unix it works as well)
58 these way must be used :-(
60 static constexpr OUStringLiteral PROP_ABORTED = u"Aborted";
61 static constexpr OUStringLiteral PROP_ASTEMPLATE = u"AsTemplate";
62 static constexpr OUStringLiteral PROP_COMPONENTDATA = u"ComponentData";
63 static constexpr OUStringLiteral PROP_DOCUMENTSERVICE = u"DocumentService";
64 static constexpr OUStringLiteral PROP_ENCRYPTIONDATA = u"EncryptionData";
65 static constexpr OUStringLiteral PROP_FILENAME = u"FileName";
66 static constexpr OUStringLiteral PROP_FILTERNAME = u"FilterName";
67 static constexpr OUStringLiteral PROP_FILTERPROVIDER = u"FilterProvider";
68 static constexpr OUStringLiteral PROP_FILTEROPTIONS = u"FilterOptions";
69 static constexpr OUStringLiteral PROP_FRAME = u"Frame";
70 static constexpr OUStringLiteral PROP_FRAMENAME = u"FrameName";
71 static constexpr OUStringLiteral PROP_HIDDEN = u"Hidden";
72 static constexpr OUStringLiteral PROP_INPUTSTREAM = u"InputStream";
73 static constexpr OUStringLiteral PROP_INTERACTIONHANDLER = u"InteractionHandler";
74 static constexpr OUStringLiteral PROP_AUTHENTICATIONHANDLER = u"AuthenticationHandler";
75 static constexpr OUStringLiteral PROP_JUMPMARK = u"JumpMark";
76 static constexpr OUStringLiteral PROP_MACROEXECUTIONMODE = u"MacroExecutionMode";
77 static constexpr OUStringLiteral PROP_MEDIATYPE = u"MediaType";
78 static constexpr OUStringLiteral PROP_MINIMIZED = u"Minimized";
79 static constexpr OUStringLiteral PROP_NOAUTOSAVE = u"NoAutoSave";
80 static constexpr OUStringLiteral PROP_OPENNEWVIEW = u"OpenNewView";
81 static constexpr OUStringLiteral PROP_OUTPUTSTREAM = u"OutputStream";
82 static constexpr OUStringLiteral PROP_PASSWORD = u"Password";
83 static constexpr OUStringLiteral PROP_POSTDATA = u"PostData";
84 static constexpr OUStringLiteral PROP_PREVIEW = u"Preview";
85 static constexpr OUStringLiteral PROP_READONLY = u"ReadOnly";
86 static constexpr OUStringLiteral PROP_REFERRER = u"Referer";
87 static constexpr OUStringLiteral PROP_REPLACEABLE = u"Replaceable";
88 static constexpr OUStringLiteral PROP_SALVAGEDFILE = u"SalvagedFile";
89 static constexpr OUStringLiteral PROP_STATUSINDICATOR = u"StatusIndicator";
90 static constexpr OUStringLiteral PROP_STREAM = u"Stream";
91 static constexpr OUStringLiteral PROP_STREAMFOROUTPUT = u"StreamForOutput";
92 static constexpr OUStringLiteral PROP_TEMPLATENAME = u"TemplateName";
93 static constexpr OUStringLiteral PROP_TITLE = u"Title";
94 static constexpr OUStringLiteral PROP_TYPENAME = u"TypeName";
95 static constexpr OUStringLiteral PROP_UCBCONTENT = u"UCBContent";
96 static constexpr OUStringLiteral PROP_UPDATEDOCMODE = u"UpdateDocMode";
97 static constexpr OUStringLiteral PROP_URL = u"URL";
98 static constexpr OUStringLiteral PROP_VERSION = u"Version";
99 static constexpr OUStringLiteral PROP_DOCUMENTTITLE = u"DocumentTitle";
100 static constexpr OUStringLiteral PROP_MODEL = u"Model";
101 static constexpr OUStringLiteral PROP_VIEWONLY = u"ViewOnly";
102 static constexpr OUStringLiteral PROP_DOCUMENTBASEURL = u"DocumentBaseURL";
103 static constexpr OUStringLiteral PROP_SUGGESTEDSAVEASNAME = u"SuggestedSaveAsName";
105 // interface
106 public:
108 /** @short these ctors do nothing - excepting that they forward
109 the given parameters to the base class ctors.
111 @descr The ctors must be overwritten to resolve conflicts with
112 the default ctors of the compiler :-(.
114 MediaDescriptor();
115 MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource);
117 /** @short it checks if the descriptor already has a valid
118 InputStream item and creates a new one, if not.
120 @descr This method uses the current items of this MediaDescriptor,
121 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
122 It creates a seekable stream and put it into the descriptor.
124 A might existing InteractionHandler will be used automatically,
125 to solve problems!
127 In case of local file the system file locking is used.
129 @return TRUE, if the stream was already part of the descriptor or could
130 be created as new item. FALSE otherwise.
132 bool addInputStream();
134 /** @short it checks if the descriptor already has a valid
135 InputStream item and creates a new one, if not.
137 @descr This method uses the current items of this MediaDescriptor,
138 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
139 It creates a seekable stream and put it into the descriptor.
141 A might existing InteractionHandler will be used automatically,
142 to solve problems!
144 In case of local file the system file locking is used based on
145 configuration settings.
147 @return TRUE, if the stream was already part of the descriptor or could
148 be created as new item. FALSE otherwise.
150 bool addInputStreamOwnLock();
152 /** @short it checks if the descriptor describes a readonly stream.
154 @descr The descriptor itself isn't changed doing so.
155 It's only checked if the stream seems to be based
156 of a real readonly file.
158 @Attention
159 We don't check the property "ReadOnly" here. Because
160 this property can be set from outside and overwrites
161 the readonly state of the stream.
162 If e.g. the stream could be opened read/write ...
163 but "ReadOnly" property is set to TRUE, this means:
164 show a readonly UI on top of this read/write stream.
166 @return TRUE, if the stream must be interpreted as readonly ...
167 FALSE otherwise.
169 bool isStreamReadOnly() const;
171 /** Returns a value from the sequence contained in the property
172 'ComponentData' of this media descriptor.
174 @descr The property 'ComponentData' should be empty, or should
175 contain a value of type sequence<com.sun.star.beans.NamedValue>
176 or sequence<com.sun.star.beans.PropertyValue>.
178 @return The value with the specified name, if existing in the
179 sequence of the 'ComponentData' property, otherwise an empty
180 Any.
182 css::uno::Any getComponentDataEntry(
183 const OUString& rName ) const;
185 /** Inserts a value into the sequence contained in the property
186 'ComponentData' of the media descriptor.
188 @descr The property 'ComponentData' should be empty, or should
189 contain a value of type sequence<com.sun.star.beans.NamedValue>
190 or sequence<com.sun.star.beans.PropertyValue>. The passed value
191 will be inserted into the sequence, or, if already existing,
192 will be overwritten.
194 @param rName The name of the value to be inserted into the
195 sequence of the 'ComponentData' property.
197 @param rValue The value to be inserted into the sequence of the
198 'ComponentData' property.
200 void setComponentDataEntry(
201 const OUString& rName,
202 const css::uno::Any& rValue );
204 /** Removes a value from the sequence contained in the property
205 'ComponentData' of the media descriptor.
207 @descr The property 'ComponentData' should be empty, or should
208 contain a value of type sequence<com.sun.star.beans.NamedValue>
209 or sequence<com.sun.star.beans.PropertyValue>. The value with
210 the passed name will be removed from the sequence, if existing.
212 @param rName The name of the value to be removed from the sequence
213 of the 'ComponentData' property.
215 void clearComponentDataEntry(
216 const OUString& rName );
218 /** This helper function tries to find a password for the document
219 described by this media descriptor.
221 First, the list of default passwords will be tried if provided. This
222 is needed by import filters for external file formats that have to
223 check a predefined password in some cases without asking the user
224 for a password. Every password is checked using the passed password
225 verifier.
227 If not successful, this media descriptor is asked for a password,
228 that has been set e.g. by an API call to load a document. If
229 existing, the password is checked using the passed password
230 verifier.
232 If still not successful, the interaction handler contained in this
233 media descriptor is used to request a password from the user. This
234 will be repeated until the passed password verifier validates the
235 entered password, or if the user chooses to cancel password input.
237 If a valid password (that is not contained in the passed list of
238 default passwords) was found, it will be inserted into the
239 "Password" property of this descriptor.
241 @param rVerifier
242 The password verifier used to check every processed password.
244 @param eRequestType
245 The password request type that will be passed to the
246 DocPasswordRequest object created internally. See
247 docpasswordrequest.hxx for more details.
249 @param pDefaultPasswords
250 If not null, contains default passwords that will be tried before a
251 password will be requested from the media descriptor or the user.
253 @return
254 If not empty, contains the password that has been validated by the
255 passed password verifier. If empty, no valid password has been
256 found, or the user has chosen to cancel password input.
258 css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(
259 comphelper::IDocPasswordVerifier& rVerifier,
260 comphelper::DocPasswordRequestType eRequestType,
261 const ::std::vector< OUString >* pDefaultPasswords );
263 // helper
264 private:
266 /** @short tries to open a stream by using the given PostData stream.
268 @descr The stream is used directly ...
270 The MediaDescriptor itself is changed inside this method.
271 Means: the stream is added internal and not returned by a value.
273 @param _rxPostData
274 the PostData stream.
276 @return TRUE if the stream could be added successfully.
277 Note: If FALSE is returned, the error was already handled inside!
279 @throw [css::uno::RuntimeException]
280 if the MediaDescriptor seems to be invalid!
282 @throw [css::lang::IllegalArgumentException]
283 if the given PostData stream is <NULL/>.
285 SAL_DLLPRIVATE bool impl_openStreamWithPostData(
286 const css::uno::Reference< css::io::XInputStream >& _rxPostData
289 /** @short tries to open a stream by using the given URL.
291 @descr First it tries to open the content in r/w mode (if its
292 allowed to do so). Only in case it's not allowed or it failed
293 the stream will be tried to open in readonly mode.
295 The MediaDescriptor itself is changed inside this method.
296 Means: the stream is added internal and not returned by a value.
298 @param sURL
299 the URL for open.
301 @param bLockFile
302 specifies whether the file should be locked
304 @return TRUE if the stream could be added successfully.
305 Note: If FALSE is returned, the error was already handled inside!
307 @throw [css::uno::RuntimeException]
308 if the MediaDescriptor seems to be invalid!
310 SAL_DLLPRIVATE bool impl_openStreamWithURL(
311 const OUString& sURL,
312 bool bLockFile
315 /** @short it checks if the descriptor already has a valid
316 InputStream item and creates a new one, if not.
318 @descr This method uses the current items of this MediaDescriptor,
319 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
320 It creates a seekable stream and put it into the descriptor.
322 A might existing InteractionHandler will be used automatically,
323 to solve problems!
325 @param bLockFile
326 specifies whether the file should be locked
328 @return TRUE, if the stream was already part of the descriptor or could
329 be created as new item. FALSE otherwise.
331 SAL_DLLPRIVATE bool impl_addInputStream( bool bLockFile );
336 #endif
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */