lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svl / source / items / poolitem.cxx
blob6be08d5220aac9d8ace343db6b00d63405bcdf1a
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 .
21 #include <svl/poolitem.hxx>
22 #include <tools/stream.hxx>
23 #include <unotools/intlwrapper.hxx>
24 #include <unotools/syslocale.hxx>
25 #include <osl/diagnose.h>
26 #include <libxml/xmlwriter.h>
27 #include <typeinfo>
29 SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich)
30 : m_nRefCount(0)
31 , m_nWhich(nWhich)
32 , m_nKind(SfxItemKind::NONE)
34 assert(nWhich <= SHRT_MAX);
38 SfxPoolItem::~SfxPoolItem()
40 assert((m_nRefCount == 0 || m_nRefCount > SFX_ITEMS_MAXREF)
41 && "destroying item in use");
45 bool SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
47 return typeid(rCmp) == typeid(*this);
51 SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
53 assert(!"this item is not serialisable");
54 return Clone();
58 sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
60 return 0;
64 SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
66 assert(!"this item is not serialisable");
67 return rStream;
70 /**
71 * This virtual method allows to get a textual representation of the value
72 * for the SfxPoolItem subclasses. It should be overridden by all UI-relevant
73 * SfxPoolItem subclasses.
75 * Because the unit of measure of the value in the SfxItemPool is only
76 * queryable via @see SfxItemPool::GetMetric(sal_uInt16) const (and not
77 * via the SfxPoolItem instance or subclass, the own unit of measure is
78 * passed to 'eCoreMetric'.
80 * The corresponding unit of measure is passed as 'ePresentationMetric'.
83 * @return SfxItemPresentation SfxItemPresentation::Nameless
84 * A textual representation (if applicable
85 * with a unit of measure) could be created,
86 * but it doesn't contain any semantic meaning
88 * SfxItemPresentation::Complete
89 * A complete textual representation could be
90 * created with semantic meaning (if applicable
91 * with unit of measure)
93 * Example:
95 * pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
96 * "12pt" with return SfxItemPresentation::Nameless
98 * pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
99 * "red" with return SfxItemPresentation::Nameless
100 * Because the SvxColorItem does not know which color it represents
101 * it cannot provide a name, which is communicated by the return value
103 * pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
104 * "1cm top border, 2cm left border, 0.2cm bottom border, ..."
106 bool SfxPoolItem::GetPresentation
108 SfxItemPresentation /*ePresentation*/, // IN: how we should format
109 MapUnit /*eCoreMetric*/, // IN: current metric of the SfxPoolItems
110 MapUnit /*ePresentationMetric*/, // IN: target metric of the presentation
111 OUString& /*rText*/, // OUT: textual representation
112 const IntlWrapper&
113 ) const
115 return false;
118 void SfxPoolItem::dumpAsXml(xmlTextWriterPtr pWriter) const
120 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxPoolItem"));
121 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
122 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("typeName"), BAD_CAST(typeid(*this).name()));
123 OUString rText;
124 IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
125 if (GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, rText, aIntlWrapper))
126 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(rText.getStr()));
127 xmlTextWriterEndElement(pWriter);
130 boost::property_tree::ptree SfxPoolItem::dumpAsJSON() const
132 boost::property_tree::ptree aTree;
133 return aTree;
136 std::unique_ptr<SfxPoolItem> SfxPoolItem::CloneSetWhich( sal_uInt16 nNewWhich ) const
138 std::unique_ptr<SfxPoolItem> pItem(Clone());
139 pItem->SetWhich(nNewWhich);
140 return pItem;
143 bool SfxPoolItem::IsVoidItem() const
145 return false;
148 SfxPoolItem* SfxVoidItem::CreateDefault()
150 return new SfxVoidItem(0);
153 SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
154 SfxPoolItem(which)
158 bool SfxVoidItem::operator==( const SfxPoolItem& rCmp ) const
160 assert(SfxPoolItem::operator==(rCmp));
161 (void) rCmp;
162 return true;
166 bool SfxVoidItem::GetPresentation
168 SfxItemPresentation /*ePresentation*/,
169 MapUnit /*eCoreMetric*/,
170 MapUnit /*ePresentationMetric*/,
171 OUString& rText,
172 const IntlWrapper&
173 ) const
175 rText = "Void";
176 return true;
179 void SfxVoidItem::dumpAsXml(xmlTextWriterPtr pWriter) const
181 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxVoidItem"));
182 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
183 xmlTextWriterEndElement(pWriter);
186 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
188 return new SfxVoidItem(*this);
191 bool SfxVoidItem::IsVoidItem() const
193 return true;
196 void SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
201 bool SfxPoolItem::HasMetrics() const
203 return false;
207 bool SfxPoolItem::QueryValue( css::uno::Any&, sal_uInt8 ) const
209 OSL_FAIL("There is no implementation for QueryValue for this item!");
210 return false;
214 bool SfxPoolItem::PutValue( const css::uno::Any&, sal_uInt8 )
216 OSL_FAIL("There is no implementation for PutValue for this item!");
217 return false;
220 SfxVoidItem::~SfxVoidItem()
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */