LibreOffice Module xmloff (master) 1
breakhdl.cxx
Go to the documentation of this file.
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#include "breakhdl.hxx"
21#include <xmloff/xmltoken.hxx>
22#include <xmloff/xmluconv.hxx>
23#include <xmloff/xmlement.hxx>
24#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/style/BreakType.hpp>
26#include <com/sun/star/uno/Any.hxx>
27
28using namespace ::com::sun::star;
29using namespace ::xmloff::token;
30
32{
33 { XML_AUTO, 0 },
34 { XML_COLUMN, 1 },
35 { XML_PAGE, 2 },
36 { XML_EVEN_PAGE, 2 },
37 { XML_ODD_PAGE, 2 },
39};
40
41
42
43
45{
46 // Nothing to do
47}
48
49bool XMLFmtBreakBeforePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
50{
51 sal_uInt16 nEnum;
52 bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes );
53 if( bRet )
54 {
55 style::BreakType eBreak;
56 switch ( nEnum )
57 {
58 case 0:
59 eBreak = style::BreakType_NONE;
60 break;
61 case 1:
62 eBreak = style::BreakType_COLUMN_BEFORE;
63 break;
64 default:
65 eBreak = style::BreakType_PAGE_BEFORE;
66 break;
67 }
68 rValue <<= eBreak;
69 }
70
71 return bRet;
72}
73
74bool XMLFmtBreakBeforePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
75{
76 style::BreakType eBreak;
77
78 if( !( rValue >>= eBreak ) )
79 {
80 sal_Int32 nValue = 0;
81 if( !( rValue >>= nValue ) )
82 return false;
83
84 eBreak = static_cast<style::BreakType>(nValue);
85 }
86
87 sal_uInt16 nEnum = 0;
88 switch( eBreak )
89 {
90 case style::BreakType_COLUMN_BEFORE:
91 nEnum = 1;
92 break;
93 case style::BreakType_PAGE_BEFORE:
94 nEnum = 2;
95 break;
96 case style::BreakType_NONE:
97 nEnum = 0;
98 break;
99 default:
100 return false;
101 }
102
103 OUStringBuffer aOut;
104 /* bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes );
105 rStrExpValue = aOut.makeStringAndClear();
106
107 return true;
108}
109
110
111
112
114{
115 // Nothing to do
116}
117
118bool XMLFmtBreakAfterPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
119{
120 sal_uInt16 nEnum;
121 bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes );
122 if( bRet )
123 {
124 style::BreakType eBreak;
125 switch ( nEnum )
126 {
127 case 0:
128 eBreak = style::BreakType_NONE;
129 break;
130 case 1:
131 eBreak = style::BreakType_COLUMN_AFTER;
132 break;
133 default:
134 eBreak = style::BreakType_PAGE_AFTER;
135 break;
136 }
137 rValue <<= eBreak;
138 }
139
140 return bRet;
141}
142
143bool XMLFmtBreakAfterPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
144{
145 style::BreakType eBreak;
146
147 if( !( rValue >>= eBreak ) )
148 {
149 sal_Int32 nValue = 0;
150 if( !( rValue >>= nValue ) )
151 return false;
152
153 eBreak = static_cast<style::BreakType>(nValue);
154 }
155
156 sal_uInt16 nEnum = 0;
157 switch( eBreak )
158 {
159 case style::BreakType_COLUMN_AFTER:
160 nEnum = 1;
161 break;
162 case style::BreakType_PAGE_AFTER:
163 nEnum = 2;
164 break;
165 case style::BreakType_NONE:
166 nEnum = 0;
167 break;
168 default:
169 return false;
170 }
171
172 OUStringBuffer aOut;
173 /* bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes );
174 rStrExpValue = aOut.makeStringAndClear();
175
176 return true;
177}
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLEnumMapEntry< sal_uInt16 > const pXML_BreakTypes[]
Definition: breakhdl.cxx:31
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
virtual ~XMLFmtBreakAfterPropHdl() override
Definition: breakhdl.cxx:113
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: breakhdl.cxx:118
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: breakhdl.cxx:143
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: breakhdl.cxx:74
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: breakhdl.cxx:49
virtual ~XMLFmtBreakBeforePropHdl() override
Definition: breakhdl.cxx:44
sal_Int16 nValue
Handling of tokens in XML: