bump product version to 5.0.4.1
[LibreOffice.git] / include / sfx2 / Metadatable.hxx
blob0cd51ecf163d49e431141039bfd4d3e6d2d06242
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 .
19 #ifndef INCLUDED_SFX2_METADATABLE_HXX
20 #define INCLUDED_SFX2_METADATABLE_HXX
22 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
26 #include <cppuhelper/implbase1.hxx>
27 #include <com/sun/star/rdf/XMetadatable.hpp>
29 #include <memory>
32 namespace com { namespace sun { namespace star {
33 namespace frame { class XModel; }
34 } } }
36 namespace sfx2 {
37 class IXmlIdRegistry;
40 namespace sfx2 {
42 class XmlIdRegistry;
43 class MetadatableUndo;
46 // XML ID handling ---------------------------------------------------
49 /// create a sfx2::XmlIdRegistryDocument or a sfx2::XmlIdRegistryClipboard
50 SFX2_DLLPUBLIC ::sfx2::IXmlIdRegistry *
51 createXmlIdRegistry(const bool i_DocIsClipboard);
54 /** base class for core objects that may have xml:id.
56 <p>The interface of this class consists of 3 parts:
57 <ul><li>implementations that are used by the MetadatableMixin
58 below</li>
59 <li>hooks to be called by the sw core whenever actions that are
60 relevant to the uniqueness of xml:ids are taken (copying,
61 splitting, merging, deletion, undo, etc.)</li>
62 <li>abstract methods that are called by the implementation of the
63 previous hooks</li></ul>
64 </p>
66 class SFX2_DLLPUBLIC Metadatable
68 public:
69 Metadatable() : m_pReg(0) {}
71 // destructor calls RemoveMetadataReference
72 virtual ~Metadatable();
74 // for MetadatableMixin ----------------------------------------------
76 ::com::sun::star::beans::StringPair GetMetadataReference() const;
77 void SetMetadataReference(
78 const ::com::sun::star::beans::StringPair & i_rReference);
79 void EnsureMetadataReference();
81 // hooks -------------------------------------------------------------
83 // called from dtor!
84 void RemoveMetadataReference();
86 /** register this as a copy of i_rSource */
87 void RegisterAsCopyOf(Metadatable const & i_rSource,
88 const bool i_bCopyPrecedesSource = false);
90 /** create an Undo Metadatable, which remembers this' reference */
91 std::shared_ptr<MetadatableUndo> CreateUndo() const;
92 std::shared_ptr<MetadatableUndo> CreateUndoForDelete();
94 /** restore this from Undo Metadatable */
95 void RestoreMetadata(std::shared_ptr<MetadatableUndo> const& i_pUndo);
97 /** merge this and i_rOther into this */
98 void JoinMetadatable(Metadatable const & i_rOther,
99 const bool i_isMergedEmpty, const bool i_isOtherEmpty);
101 // abstract methods --------------------------------------------------
103 /** get the registry from the SwDoc */
104 virtual ::sfx2::IXmlIdRegistry& GetRegistry() = 0;
106 /** is this in a clipboard document? */
107 virtual bool IsInClipboard() const = 0;
109 /** is this in undo array? */
110 virtual bool IsInUndo() const = 0;
112 /** which stream is this in? true: content.xml; false: styles.xml */
113 virtual bool IsInContent() const = 0;
115 /** create XMetadatable from this.
116 note: if IsInUndo or IsInClipboard return true,
117 MakeUnoObject <em>must not</em> be called!
119 virtual ::com::sun::star::uno::Reference<
120 ::com::sun::star::rdf::XMetadatable > MakeUnoObject() = 0;
122 private:
123 Metadatable(const Metadatable&) SAL_DELETED_FUNCTION;
124 Metadatable& operator=(const Metadatable&) SAL_DELETED_FUNCTION;
126 friend class MetadatableClipboard;
127 friend class MetadatableUndo;
129 // note that Reg may be a XmlIdRegistryDocument or a XmlIdRegistryClipboard
130 XmlIdRegistry* m_pReg; // null => no XmlId
134 /** base class for UNO objects that implement XMetadatable.
136 <p>An instance of this base class is associated with an instance of
137 Metadatable.</p>
139 class SFX2_DLLPUBLIC MetadatableMixin :
140 public ::cppu::WeakImplHelper1<
141 ::com::sun::star::rdf::XMetadatable>
144 public:
145 MetadatableMixin() {};
147 virtual ~MetadatableMixin() {}
149 // ::com::sun::star::rdf::XNode:
150 virtual OUString SAL_CALL getStringValue()
151 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 // ::com::sun::star::rdf::XURI:
154 virtual OUString SAL_CALL getLocalName()
155 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 virtual OUString SAL_CALL getNamespace()
157 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 // ::com::sun::star::rdf::XMetadatable:
160 virtual ::com::sun::star::beans::StringPair SAL_CALL getMetadataReference()
161 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
162 virtual void SAL_CALL setMetadataReference(
163 const ::com::sun::star::beans::StringPair & i_rReference)
164 throw (::com::sun::star::uno::RuntimeException,
165 ::com::sun::star::lang::IllegalArgumentException, std::exception) SAL_OVERRIDE;
166 virtual void SAL_CALL ensureMetadataReference()
167 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 protected:
170 /// get the core object corresponding to this UNO object.
171 virtual Metadatable * GetCoreObject() = 0;
172 /// get the XModel for the document
173 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
174 GetModel() = 0;
178 } // namespace sfx2
180 #endif // INCLUDED_SFX2_METADATABLE_HXX
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */