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 "adjushdl.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/ParagraphAdjust.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27
28 using namespace ::com::sun::star;
29
30 using namespace ::xmloff::token;
31
32 SvXMLEnumMapEntry<style::ParagraphAdjust> const pXML_Para_Adjust_Enum[] =
33 {
34 { XML_START, style::ParagraphAdjust_LEFT },
35 { XML_END, style::ParagraphAdjust_RIGHT },
36 { XML_CENTER, style::ParagraphAdjust_CENTER },
37 { XML_JUSTIFY, style::ParagraphAdjust_BLOCK },
38 { XML_JUSTIFIED, style::ParagraphAdjust_BLOCK }, // obsolete
39 { XML_LEFT, style::ParagraphAdjust_LEFT },
40 { XML_RIGHT, style::ParagraphAdjust_RIGHT },
41 { XML_TOKEN_INVALID, style::ParagraphAdjust(0) }
42 };
43
44 SvXMLEnumMapEntry<style::ParagraphAdjust> const pXML_Para_Align_Last_Enum[] =
45 {
46 { XML_START, style::ParagraphAdjust_LEFT },
47 { XML_CENTER, style::ParagraphAdjust_CENTER },
48 { XML_JUSTIFY, style::ParagraphAdjust_BLOCK },
49 { XML_JUSTIFIED, style::ParagraphAdjust_BLOCK }, // obsolete
50 { XML_TOKEN_INVALID, style::ParagraphAdjust(0) }
51 };
52
53
54
55
~XMLParaAdjustPropHdl()56 XMLParaAdjustPropHdl::~XMLParaAdjustPropHdl()
57 {
58 // nothing to do
59 }
60
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const61 bool XMLParaAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
62 {
63 style::ParagraphAdjust eAdjust;
64 bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Adjust_Enum );
65 if( bRet )
66 rValue <<= static_cast<sal_Int16>(eAdjust);
67
68 return bRet;
69 }
70
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const71 bool XMLParaAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
72 {
73 if(!rValue.hasValue())
74 return false;
75 OUStringBuffer aOut;
76 sal_Int16 nVal = 0;
77
78 rValue >>= nVal;
79
80 bool bRet = SvXMLUnitConverter::convertEnum( aOut, static_cast<style::ParagraphAdjust>(nVal), pXML_Para_Adjust_Enum, XML_START );
81
82 rStrExpValue = aOut.makeStringAndClear();
83
84 return bRet;
85 }
86
87
88
89
~XMLLastLineAdjustPropHdl()90 XMLLastLineAdjustPropHdl::~XMLLastLineAdjustPropHdl()
91 {
92 // nothing to do
93 }
94
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const95 bool XMLLastLineAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
96 {
97 style::ParagraphAdjust eAdjust;
98 bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Align_Last_Enum );
99 if( bRet )
100 rValue <<= static_cast<sal_Int16>(eAdjust);
101
102 return bRet;
103 }
104
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const105 bool XMLLastLineAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
106 {
107 OUStringBuffer aOut;
108 sal_Int16 nVal = 0;
109 bool bRet = false;
110
111 rValue >>= nVal;
112
113 if( static_cast<style::ParagraphAdjust>(nVal) != style::ParagraphAdjust_LEFT )
114 bRet = SvXMLUnitConverter::convertEnum( aOut, static_cast<style::ParagraphAdjust>(nVal), pXML_Para_Align_Last_Enum, XML_START );
115
116 rStrExpValue = aOut.makeStringAndClear();
117
118 return bRet;
119 }
120
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
122