1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
11 #ifndef INCLUDED_SVX_CLASSIFICATIONFIELD_HXX
12 #define INCLUDED_SVX_CLASSIFICATIONFIELD_HXX
13 
14 #include <sal/config.h>
15 #include <svx/svxdllapi.h>
16 #include <editeng/flditem.hxx>
17 
18 namespace svx {
19 
20 enum class ClassificationType
21 {
22     CATEGORY,
23     MARKING,
24     TEXT,
25     INTELLECTUAL_PROPERTY_PART,
26     PARAGRAPH,
27 };
28 
29 class SVX_DLLPUBLIC ClassificationResult
30 {
31 public:
32     ClassificationType meType;
33     OUString msName;            //< Display text or 'Name' field (from example.xml).
34     OUString msAbbreviatedName; //< Abbreviated name, displayed instead of Name.
35     OUString msIdentifier;      //< The identifier of this entry (from example.xml).
36 
ClassificationResult(ClassificationType eType,const OUString & sName,const OUString & sAbbreviatedName,const OUString & sIdentifier="")37     ClassificationResult(ClassificationType eType, const OUString& sName,
38                          const OUString& sAbbreviatedName, const OUString& sIdentifier = "")
39         : meType(eType)
40         , msName(sName)
41         , msAbbreviatedName(sAbbreviatedName)
42         , msIdentifier(sIdentifier)
43     {
44     }
45 
46     /// Returns the text to display, which is the Abbreviated Name, if provided, otherwise Name.
getDisplayText() const47     OUString const & getDisplayText() const
48     {
49         return !msAbbreviatedName.isEmpty() ? msAbbreviatedName : msName;
50     }
51 
operator ==(const ClassificationResult & rOther) const52     bool operator==(const ClassificationResult& rOther) const
53     {
54         return (meType == rOther.meType &&
55                 msName == rOther.msName &&
56                 msAbbreviatedName == rOther.msAbbreviatedName &&
57                 msIdentifier == rOther.msIdentifier);
58     }
59 };
60 
61 class SVX_DLLPUBLIC ClassificationField final : public SvxFieldData
62 {
63 public:
64     ClassificationType const meType;
65     OUString const msDescription;
66     OUString const msFullClassName;
67     OUString const msIdentifier;
68 
ClassificationField(ClassificationType eType,OUString const & sDescription,OUString const & sFullClassName,OUString const & sIdentifier)69     ClassificationField(ClassificationType eType, OUString const & sDescription, OUString const & sFullClassName, OUString const & sIdentifier)
70         : SvxFieldData()
71         , meType(eType)
72         , msDescription(sDescription)
73         , msFullClassName(sFullClassName)
74         , msIdentifier(sIdentifier)
75     {}
76 
Clone() const77     std::unique_ptr<SvxFieldData> Clone() const override
78     {
79         return std::make_unique<ClassificationField>(meType, msDescription, msFullClassName, msIdentifier);
80     }
81 
operator ==(const SvxFieldData & rOther) const82     bool operator==(const SvxFieldData& rOther) const override
83     {
84         if (typeid(rOther) != typeid(*this))
85             return false;
86 
87         const ClassificationField& rOtherField = static_cast<const ClassificationField&>(rOther);
88         return (meType == rOtherField.meType &&
89                 msDescription == rOtherField.msDescription &&
90                 msFullClassName == rOtherField.msFullClassName &&
91                 msIdentifier == rOtherField.msIdentifier);
92     }
93 };
94 
95 } // end svx namespace
96 
97 #endif // INCLUDED_SVX_CLASSIFICATIONFIELD_HXX
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
100