tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / xmltabi.cxx
blobedea09f76c660bed0539c19c6375a4bf1c96a482
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 <com/sun/star/style/TabAlign.hpp>
21 #include <sal/log.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <com/sun/star/style/TabStop.hpp>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmluconv.hxx>
27 #include <xmltabi.hxx>
30 using namespace ::com::sun::star;
31 using namespace ::xmloff::token;
33 class SvxXMLTabStopContext_Impl : public SvXMLImportContext
35 private:
36 style::TabStop aTabStop;
38 public:
40 SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
41 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList );
43 const style::TabStop& getTabStop() const { return aTabStop; }
47 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
48 SvXMLImport& rImport, sal_Int32 /*nElement*/,
49 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
50 : SvXMLImportContext( rImport )
52 aTabStop.Position = 0;
53 aTabStop.Alignment = style::TabAlign_LEFT;
54 aTabStop.DecimalChar = ',';
55 aTabStop.FillChar = ' ';
56 sal_Unicode cTextFillChar = 0;
58 for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
60 sal_Int32 nVal;
61 switch( aIter.getToken() )
63 case XML_ELEMENT(STYLE, XML_POSITION):
64 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
65 nVal, aIter.toView()))
67 aTabStop.Position = nVal;
69 break;
70 case XML_ELEMENT(STYLE, XML_TYPE):
71 if( IsXMLToken( aIter, XML_LEFT ) )
73 aTabStop.Alignment = style::TabAlign_LEFT;
75 else if( IsXMLToken( aIter, XML_RIGHT ) )
77 aTabStop.Alignment = style::TabAlign_RIGHT;
79 else if( IsXMLToken( aIter, XML_CENTER ) )
81 aTabStop.Alignment = style::TabAlign_CENTER;
83 else if( IsXMLToken( aIter, XML_CHAR ) )
85 aTabStop.Alignment = style::TabAlign_DECIMAL;
87 else if( IsXMLToken( aIter, XML_DEFAULT ) )
89 aTabStop.Alignment = style::TabAlign_DEFAULT;
91 break;
92 case XML_ELEMENT(STYLE, XML_CHAR):
93 if( !aIter.isEmpty() )
94 aTabStop.DecimalChar = aIter.toString()[0];
95 break;
96 case XML_ELEMENT(STYLE, XML_LEADER_STYLE):
97 if( IsXMLToken( aIter, XML_NONE ) )
98 aTabStop.FillChar = ' ';
99 else if( IsXMLToken( aIter, XML_DOTTED ) )
100 aTabStop.FillChar = '.';
101 else
102 aTabStop.FillChar = '_';
103 break;
104 case XML_ELEMENT(STYLE, XML_LEADER_TEXT):
105 if( !aIter.isEmpty() )
106 cTextFillChar = aIter.toString()[0];
107 break;
108 default:
109 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
113 if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
114 aTabStop.FillChar = cTextFillChar;
118 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
119 SvXMLImport& rImport, sal_Int32 nElement,
120 const XMLPropertyState& rProp,
121 ::std::vector< XMLPropertyState > &rProps )
122 : XMLElementPropertyContext( rImport, nElement, rProp, rProps )
126 css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLTabStopImportContext::createFastChildContext(
127 sal_Int32 nElement,
128 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
130 if( nElement == XML_ELEMENT(STYLE, XML_TAB_STOP) )
132 // create new tabstop import context
133 const rtl::Reference<SvxXMLTabStopContext_Impl> xTabStopContext{
134 new SvxXMLTabStopContext_Impl( GetImport(), nElement, xAttrList )};
136 // add new tabstop to array of tabstops
137 maTabStops.push_back( xTabStopContext );
139 return xTabStopContext;
141 else
142 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
144 return nullptr;
147 void SvxXMLTabStopImportContext::endFastElement(sal_Int32 nElement)
149 sal_uInt16 nCount = maTabStops.size();
150 uno::Sequence< style::TabStop> aSeq( nCount );
152 if( nCount )
154 sal_uInt16 nNewCount = 0;
156 style::TabStop* pTabStops = aSeq.getArray();
157 for( sal_uInt16 i=0; i < nCount; i++ )
159 SvxXMLTabStopContext_Impl *pTabStopContext = maTabStops[i].get();
160 const style::TabStop& rTabStop = pTabStopContext->getTabStop();
161 bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
162 if( !bDflt || 0==i )
164 *pTabStops++ = pTabStopContext->getTabStop();
165 nNewCount++;
167 if( bDflt && 0==i )
168 break;
171 if( nCount != nNewCount )
172 aSeq.realloc( nNewCount );
174 aProp.maValue <<= aSeq;
176 SetInsert( true );
177 XMLElementPropertyContext::endFastElement(nElement);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */