tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_content.hxx
bloba292877f2e2ef25ad9d7b60b0585060d1129e908
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 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
26 #include <ucbhelper/contenthelper.hxx>
27 #include <com/sun/star/ucb/XContentCreator.hpp>
28 #include <utility>
29 #include "tdoc_provider.hxx"
31 namespace com::sun::star {
32 namespace sdbc { class XRow; }
33 namespace io { class XInputStream; class XOutputStream; }
34 namespace beans { struct PropertyValue; }
35 namespace ucb { struct OpenCommandArgument2; struct TransferInfo;
36 struct ContentInfo; }
39 namespace tdoc_ucp
43 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
45 class ContentProperties
47 public:
48 ContentProperties()
49 : m_eType( STREAM )
52 ContentProperties( const ContentType & rType, OUString aTitle )
53 : m_eType( rType ),
54 m_aContentType( rType == STREAM
55 ? TDOC_STREAM_CONTENT_TYPE
56 : rType == FOLDER
57 ? TDOC_FOLDER_CONTENT_TYPE
58 : rType == DOCUMENT
59 ? TDOC_DOCUMENT_CONTENT_TYPE
60 : TDOC_ROOT_CONTENT_TYPE ),
61 m_aTitle(std::move( aTitle ))
64 ContentType getType() const { return m_eType; }
66 // Properties
68 const OUString & getContentType() const { return m_aContentType; }
70 bool getIsFolder() const { return m_eType > STREAM; }
71 bool getIsDocument() const { return !getIsFolder(); }
73 const OUString & getTitle() const { return m_aTitle; }
74 void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; }
76 css::uno::Sequence< css::ucb::ContentInfo >
77 getCreatableContentsInfo() const;
79 bool isContentCreator() const;
81 private:
82 ContentType m_eType;
83 OUString m_aContentType;
84 OUString m_aTitle;
88 class Content : public ::ucbhelper::ContentImplHelper,
89 public css::ucb::XContentCreator
91 enum ContentState { TRANSIENT, // created via createNewContent,
92 // but did not process "insert" yet
93 PERSISTENT, // processed "insert"
94 DEAD // processed "delete" / document was closed
97 ContentProperties m_aProps;
98 ContentState m_eState;
99 ContentProvider* m_pProvider;
101 private:
102 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
103 ContentProvider* pProvider,
104 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
105 ContentProperties aProps );
106 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
107 ContentProvider* pProvider,
108 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
109 const css::ucb::ContentInfo& Info );
111 virtual css::uno::Sequence< css::beans::Property >
112 getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
113 virtual css::uno::Sequence< css::ucb::CommandInfo >
114 getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
115 virtual OUString getParentURL() override;
117 static bool hasData( ContentProvider const * pProvider, const Uri & rUri );
118 bool hasData( const Uri & rUri ) const { return hasData( m_pProvider, rUri ); }
120 static bool loadData( ContentProvider const * pProvider,
121 const Uri & rUri,
122 ContentProperties& rProps );
123 /// @throws css::ucb::CommandFailedException
124 /// @throws css::task::DocumentPasswordRequest
125 /// @throws css::uno::RuntimeException
126 bool storeData( const css::uno::Reference< css::io::XInputStream >& xData,
127 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
128 void renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId,
129 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
130 bool removeData();
132 bool copyData( const Uri & rSourceUri, const OUString & rNewName );
134 css::uno::Reference< css::ucb::XContentIdentifier >
135 makeNewIdentifier( const OUString& rTitle );
137 typedef rtl::Reference< Content > ContentRef;
138 typedef std::vector< ContentRef > ContentRefList;
139 void queryChildren( ContentRefList& rChildren );
141 bool exchangeIdentity(
142 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
144 css::uno::Reference< css::sdbc::XRow >
145 getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
146 css::uno::Sequence< css::uno::Any >
147 /// @throws css::uno::Exception
148 setPropertyValues(
149 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
150 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
152 /// @throws css::uno::Exception
153 css::uno::Any
154 open( const css::ucb::OpenCommandArgument2& rArg,
155 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
157 /// @throws css::uno::Exception
158 void insert( const css::uno::Reference< css::io::XInputStream >& xData,
159 sal_Int32 nNameClashResolve,
160 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
162 /// @throws css::uno::Exception
163 void destroy( bool bDeletePhysical,
164 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
166 /// @throws css::uno::Exception
167 void transfer( const css::ucb::TransferInfo& rInfo,
168 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
170 static css::uno::Reference< css::sdbc::XRow >
171 getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
172 const css::uno::Sequence< css::beans::Property >& rProperties,
173 const ContentProperties& rData,
174 ContentProvider* pProvider,
175 const OUString& rContentId );
178 static bool commitStorage(
179 const css::uno::Reference< css::embed::XStorage > & xStorage );
181 static bool closeOutputStream(
182 const css::uno::Reference< css::io::XOutputStream > & xOut );
184 /// @throws css::ucb::CommandFailedException
185 /// @throws css::task::DocumentPasswordRequest
186 /// @throws css::uno::RuntimeException
187 css::uno::Reference< css::io::XInputStream >
188 getInputStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
190 /// @throws css::ucb::CommandFailedException
191 /// @throws css::task::DocumentPasswordRequest
192 /// @throws css::uno::RuntimeException
193 css::uno::Reference< css::io::XOutputStream >
194 getTruncatedOutputStream(
195 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
197 css::uno::Reference< css::ucb::XContent >
198 queryChildContent( std::u16string_view rRelativeChildUri );
200 /// @throws css::ucb::CommandFailedException
201 /// @throws css::task::DocumentPasswordRequest
202 /// @throws css::uno::RuntimeException
203 css::uno::Reference< css::io::XStream >
204 getStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
206 public:
207 // Create existing content. Fail, if not already exists.
208 static rtl::Reference<Content> create(
209 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
210 ContentProvider* pProvider,
211 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier );
213 // Create new content. Fail, if already exists.
214 static rtl::Reference<Content> create(
215 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
216 ContentProvider* pProvider,
217 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
218 const css::ucb::ContentInfo& Info );
220 virtual ~Content() override;
222 // XInterface
223 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
224 virtual void SAL_CALL acquire()
225 noexcept override;
226 virtual void SAL_CALL release()
227 noexcept override;
229 // XTypeProvider
230 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
231 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
233 // XServiceInfo
234 virtual OUString SAL_CALL
235 getImplementationName() override;
236 virtual css::uno::Sequence< OUString > SAL_CALL
237 getSupportedServiceNames() override;
239 // XContent
240 virtual OUString SAL_CALL
241 getContentType() override;
242 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
243 getIdentifier() override;
245 // XCommandProcessor
246 virtual css::uno::Any SAL_CALL
247 execute( const css::ucb::Command& aCommand,
248 sal_Int32 CommandId,
249 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
250 virtual void SAL_CALL
251 abort( sal_Int32 CommandId ) override;
254 // Additional interfaces
257 // XContentCreator
258 virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
259 queryCreatableContentsInfo() override;
260 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
261 createNewContent( const css::ucb::ContentInfo& Info ) override;
264 // Non-interface methods.
267 static css::uno::Reference< css::sdbc::XRow >
268 getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
269 const css::uno::Sequence< css::beans::Property >& rProperties,
270 ContentProvider* pProvider,
271 const OUString& rContentId );
273 void notifyDocumentClosed();
274 void notifyChildRemoved( std::u16string_view rRelativeChildUri );
275 void notifyChildInserted( std::u16string_view rRelativeChildUri );
277 rtl::Reference< ContentProvider > getContentProvider() const
278 { return rtl::Reference< ContentProvider >( m_pProvider ); }
281 } // namespace tdoc_ucp
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */