/src/libreoffice/include/svx/sdasitm.hxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_SVX_SDASITM_HXX |
21 | | #define INCLUDED_SVX_SDASITM_HXX |
22 | | |
23 | | #include <svx/svddef.hxx> |
24 | | #include <svx/sdooitm.hxx> |
25 | | #include <com/sun/star/beans/PropertyValue.hpp> |
26 | | #include <com/sun/star/uno/Sequence.hxx> |
27 | | #include <rtl/ustring.hxx> |
28 | | #include <svx/svxdllapi.h> |
29 | | #include <unordered_map> |
30 | | |
31 | | namespace com::sun::star::uno |
32 | | { |
33 | | class Any; |
34 | | } |
35 | | |
36 | | class SVXCORE_DLLPUBLIC SdrCustomShapeGeometryItem final : public SfxPoolItem |
37 | | { |
38 | | public: |
39 | | typedef std::pair<const OUString, const OUString> PropertyPair; |
40 | | |
41 | | private: |
42 | | struct PropertyPairHash |
43 | | { |
44 | | inline size_t operator()(const SdrCustomShapeGeometryItem::PropertyPair&) const; |
45 | | }; |
46 | | typedef std::unordered_map<PropertyPair, sal_Int32, PropertyPairHash> PropertyPairHashMap; |
47 | | typedef std::unordered_map<OUString, sal_Int32> PropertyHashMap; |
48 | | |
49 | | PropertyHashMap m_aPropHashMap; |
50 | | PropertyPairHashMap m_aPropPairHashMap; |
51 | | |
52 | | css::uno::Sequence<css::beans::PropertyValue> m_aPropSeq; |
53 | | |
54 | | // For fast comparisons keep a hash of the content, computed on demand |
55 | | // (unusable state is if anyToHash() returns no hash). |
56 | | enum HashState |
57 | | { |
58 | | Unknown, |
59 | | Valid, |
60 | | Unusable |
61 | | }; |
62 | | mutable HashState m_aHashState = HashState::Unknown; |
63 | | mutable size_t m_aHash = 0xdeadbeef; |
64 | | |
65 | | SAL_DLLPRIVATE void SetPropSeq(const css::uno::Sequence<css::beans::PropertyValue>& rPropSeq); |
66 | | inline void UpdateHash() const; |
67 | | inline void InvalidateHash(); |
68 | | |
69 | | public: |
70 | | SAL_DLLPRIVATE SdrCustomShapeGeometryItem(); |
71 | | DECLARE_ITEM_TYPE_FUNCTION(SdrCustomShapeGeometryItem) |
72 | | SdrCustomShapeGeometryItem(const css::uno::Sequence<css::beans::PropertyValue>&); |
73 | | virtual ~SdrCustomShapeGeometryItem() override; |
74 | | |
75 | 133k | SdrCustomShapeGeometryItem(SdrCustomShapeGeometryItem const&) = default; |
76 | | SdrCustomShapeGeometryItem(SdrCustomShapeGeometryItem&&) = default; |
77 | | SdrCustomShapeGeometryItem& operator=(SdrCustomShapeGeometryItem const&) |
78 | | = delete; // due to SfxPoolItem |
79 | | SdrCustomShapeGeometryItem& operator=(SdrCustomShapeGeometryItem&&) |
80 | | = delete; // due to SfxPoolItem |
81 | | |
82 | | SAL_DLLPRIVATE virtual bool operator==(const SfxPoolItem&) const override; |
83 | | |
84 | | SAL_DLLPRIVATE virtual bool GetPresentation(SfxItemPresentation ePresentation, |
85 | | MapUnit eCoreMetric, MapUnit ePresentationMetric, |
86 | | OUString& rText, const IntlWrapper&) const override; |
87 | | |
88 | | SAL_DLLPRIVATE virtual SdrCustomShapeGeometryItem* Clone(SfxItemPool* pPool |
89 | | = nullptr) const override; |
90 | | |
91 | | SAL_DLLPRIVATE virtual bool QueryValue(css::uno::Any& rVal, |
92 | | sal_uInt8 nMemberId = 0) const override; |
93 | | SAL_DLLPRIVATE virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override; |
94 | | |
95 | | css::uno::Any* GetPropertyValueByName(const OUString& rPropName); |
96 | | const css::uno::Any* GetPropertyValueByName(const OUString& rPropName) const; |
97 | | css::uno::Any* GetPropertyValueByName(const OUString& rPropName, const OUString& rPropName2); |
98 | | const css::uno::Any* GetPropertyValueByName(const OUString& rPropName, |
99 | | const OUString& rPropName2) const; |
100 | | |
101 | | void SetPropertyValue(const css::beans::PropertyValue& rPropVal); |
102 | | void SetPropertyValue(const OUString& rSequenceName, const css::beans::PropertyValue& rPropVal); |
103 | | |
104 | | void ClearPropertyValue(const OUString& rPropertyName); |
105 | | }; |
106 | | |
107 | | inline SdrOnOffItem makeSdrTextWordWrapItem(bool bAuto) |
108 | 325k | { |
109 | 325k | return SdrOnOffItem(SDRATTR_TEXT_WORDWRAP, bAuto); |
110 | 325k | } |
111 | | |
112 | | // some useful inline methods |
113 | | |
114 | | size_t SdrCustomShapeGeometryItem::PropertyPairHash:: |
115 | | operator()(const SdrCustomShapeGeometryItem::PropertyPair& r1) const |
116 | 3.29M | { |
117 | 3.29M | size_t hash = 17; |
118 | 3.29M | hash = hash * 37 + r1.first.hashCode(); |
119 | 3.29M | hash = hash * 37 + r1.second.hashCode(); |
120 | 3.29M | return hash; |
121 | 3.29M | }; |
122 | | |
123 | | #endif |
124 | | |
125 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |