tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / text / XMLLineNumberingImportContext.cxx
blob67450c0d5f5c490c7bb6be39e6931719f56c132f
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 #include <XMLLineNumberingImportContext.hxx>
21 #include "XMLLineNumberingSeparatorImportContext.hxx"
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/text/XLineNumberingProperties.hpp>
25 #include <com/sun/star/style/LineNumberPosition.hpp>
26 #include <com/sun/star/style/NumberingType.hpp>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmlement.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::style;
38 using namespace ::xmloff::token;
40 using ::com::sun::star::beans::XPropertySet;
41 using ::com::sun::star::xml::sax::XFastAttributeList;
42 using ::com::sun::star::text::XLineNumberingProperties;
45 constexpr OUStringLiteral gsCharStyleName(u"CharStyleName");
46 constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines");
47 constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames");
48 constexpr OUStringLiteral gsDistance(u"Distance");
49 constexpr OUStringLiteral gsInterval(u"Interval");
50 constexpr OUStringLiteral gsSeparatorText(u"SeparatorText");
51 constexpr OUStringLiteral gsNumberPosition(u"NumberPosition");
52 constexpr OUStringLiteral gsNumberingType(u"NumberingType");
53 constexpr OUStringLiteral gsIsOn(u"IsOn");
54 constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage");
55 constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval");
57 XMLLineNumberingImportContext::XMLLineNumberingImportContext(
58 SvXMLImport& rImport)
59 : SvXMLStyleContext(rImport, XmlStyleFamily::TEXT_LINENUMBERINGCONFIG)
60 , sNumFormat(GetXMLToken(XML_1))
61 , sNumLetterSync(GetXMLToken(XML_FALSE))
62 , nOffset(-1)
63 , nNumberPosition(style::LineNumberPosition::LEFT)
64 , nIncrement(-1)
65 , nSeparatorIncrement(-1)
66 , bNumberLines(true)
67 , bCountEmptyLines(true)
68 , bCountInFloatingFrames(false)
69 , bRestartNumbering(false)
73 XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
77 void XMLLineNumberingImportContext::SetAttribute( sal_Int32 nElement,
78 const OUString& rValue )
80 bool bTmp(false);
81 sal_Int32 nTmp;
83 switch (nElement)
85 case XML_ELEMENT(TEXT, XML_STYLE_NAME):
86 sStyleName = rValue;
87 break;
89 case XML_ELEMENT(TEXT, XML_NUMBER_LINES):
90 if (::sax::Converter::convertBool(bTmp, rValue))
92 bNumberLines = bTmp;
94 break;
96 case XML_ELEMENT(TEXT, XML_COUNT_EMPTY_LINES):
97 if (::sax::Converter::convertBool(bTmp, rValue))
99 bCountEmptyLines = bTmp;
101 break;
103 case XML_ELEMENT(TEXT, XML_COUNT_IN_TEXT_BOXES):
104 if (::sax::Converter::convertBool(bTmp, rValue))
106 bCountInFloatingFrames = bTmp;
108 break;
110 case XML_ELEMENT(TEXT, XML_RESTART_ON_PAGE):
111 if (::sax::Converter::convertBool(bTmp, rValue))
113 bRestartNumbering = bTmp;
115 break;
117 case XML_ELEMENT(TEXT, XML_OFFSET):
118 if (GetImport().GetMM100UnitConverter().
119 convertMeasureToCore(nTmp, rValue))
121 nOffset = nTmp;
123 break;
125 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
126 sNumFormat = rValue;
127 break;
129 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
130 sNumLetterSync = rValue;
131 break;
133 case XML_ELEMENT(TEXT, XML_NUMBER_POSITION):
135 static const SvXMLEnumMapEntry<sal_Int16> aLineNumberPositionMap[] =
137 { XML_LEFT, style::LineNumberPosition::LEFT },
138 { XML_RIGHT, style::LineNumberPosition::RIGHT },
139 { XML_INSIDE, style::LineNumberPosition::INSIDE },
140 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
141 { XML_TOKEN_INVALID, 0 }
144 (void)SvXMLUnitConverter::convertEnum(nNumberPosition, rValue,
145 aLineNumberPositionMap);
146 break;
149 case XML_ELEMENT(TEXT, XML_INCREMENT):
150 if (::sax::Converter::convertNumber(nTmp, rValue, 0))
152 nIncrement = static_cast<sal_Int16>(nTmp);
154 break;
158 void XMLLineNumberingImportContext::CreateAndInsert(bool)
160 // insert and block mode is handled in insertStyleFamily
162 // we'll try to get the LineNumberingProperties
163 Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
164 UNO_QUERY);
165 if (!xSupplier.is())
166 return;
168 Reference<XPropertySet> xLineNumbering =
169 xSupplier->getLineNumberingProperties();
171 if (!xLineNumbering.is())
172 return;
174 Any aAny;
176 // set style name (if it exists)
177 if ( GetImport().GetStyles()->FindStyleChildContext(
178 XmlStyleFamily::TEXT_TEXT, sStyleName ) != nullptr )
180 aAny <<= GetImport().GetStyleDisplayName(
181 XmlStyleFamily::TEXT_TEXT, sStyleName );
182 xLineNumbering->setPropertyValue(gsCharStyleName, aAny);
185 xLineNumbering->setPropertyValue(gsSeparatorText, Any(sSeparator));
186 xLineNumbering->setPropertyValue(gsDistance, Any(nOffset));
187 xLineNumbering->setPropertyValue(gsNumberPosition, Any(nNumberPosition));
189 if (nIncrement >= 0)
191 xLineNumbering->setPropertyValue(gsInterval, Any(nIncrement));
194 if (nSeparatorIncrement >= 0)
196 xLineNumbering->setPropertyValue(gsSeparatorInterval, Any(nSeparatorIncrement));
199 xLineNumbering->setPropertyValue(gsIsOn, Any(bNumberLines));
200 xLineNumbering->setPropertyValue(gsCountEmptyLines, Any(bCountEmptyLines));
201 xLineNumbering->setPropertyValue(gsCountLinesInFrames, Any(bCountInFloatingFrames));
202 xLineNumbering->setPropertyValue(gsRestartAtEachPage, Any(bRestartNumbering));
204 sal_Int16 nNumType = NumberingType::ARABIC;
205 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
206 sNumFormat,
207 sNumLetterSync );
208 xLineNumbering->setPropertyValue(gsNumberingType, Any(nNumType));
211 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLLineNumberingImportContext::createFastChildContext(
212 sal_Int32 nElement,
213 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
215 if ( nElement == XML_ELEMENT(TEXT, XML_LINENUMBERING_SEPARATOR) )
216 return new XMLLineNumberingSeparatorImportContext(GetImport(), *this);
217 return nullptr;
220 void XMLLineNumberingImportContext::SetSeparatorText(
221 const OUString& sText)
223 sSeparator = sText;
226 void XMLLineNumberingImportContext::SetSeparatorIncrement(
227 sal_Int16 nIncr)
229 nSeparatorIncrement = nIncr;
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */