xref: /AOO41X/main/xmloff/source/style/adjushdl.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <adjushdl.hxx>
27 #include <tools/solar.h>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <com/sun/star/style/ParagraphAdjust.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 
34 using namespace ::com::sun::star;
35 using ::rtl::OUString;
36 using ::rtl::OUStringBuffer;
37 
38 using namespace ::xmloff::token;
39 
40 SvXMLEnumMapEntry __READONLY_DATA pXML_Para_Adjust_Enum[] =
41 {
42     { XML_START,        style::ParagraphAdjust_LEFT },
43     { XML_END,          style::ParagraphAdjust_RIGHT },
44     { XML_CENTER,       style::ParagraphAdjust_CENTER },
45     { XML_JUSTIFY,      style::ParagraphAdjust_BLOCK },
46     { XML_JUSTIFIED,    style::ParagraphAdjust_BLOCK }, // obsolete
47     { XML_LEFT,         style::ParagraphAdjust_LEFT },
48     { XML_RIGHT,        style::ParagraphAdjust_RIGHT },
49     { XML_TOKEN_INVALID, 0 }
50 };
51 
52 SvXMLEnumMapEntry __READONLY_DATA pXML_Para_Align_Last_Enum[] =
53 {
54     { XML_START,        style::ParagraphAdjust_LEFT },
55     { XML_CENTER,       style::ParagraphAdjust_CENTER },
56     { XML_JUSTIFY,      style::ParagraphAdjust_BLOCK },
57     { XML_JUSTIFIED,    style::ParagraphAdjust_BLOCK }, // obsolete
58     { XML_TOKEN_INVALID, 0 }
59 };
60 
61 ///////////////////////////////////////////////////////////////////////////////
62 //
63 // class XMLParaAdjustPropHdl
64 //
65 
~XMLParaAdjustPropHdl()66 XMLParaAdjustPropHdl::~XMLParaAdjustPropHdl()
67 {
68     // nothing to do
69 }
70 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const71 sal_Bool XMLParaAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
72 {
73     sal_uInt16 eAdjust;
74     sal_Bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Adjust_Enum );
75     if( bRet )
76         rValue <<= (sal_Int16)eAdjust;
77 
78     return bRet;
79 }
80 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const81 sal_Bool XMLParaAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
82 {
83     if(!rValue.hasValue())
84         return sal_False;     //added by BerryJia for fixing Bug102407 2002-11-5
85     OUStringBuffer aOut;
86     sal_Int16 nVal = 0;
87 
88     rValue >>= nVal;
89 
90     sal_Bool bRet = SvXMLUnitConverter::convertEnum( aOut, nVal, pXML_Para_Adjust_Enum, XML_START );
91 
92     rStrExpValue = aOut.makeStringAndClear();
93 
94     return bRet;
95 }
96 
97 ///////////////////////////////////////////////////////////////////////////////
98 //
99 // class XMLLastLineAdjustPropHdl
100 //
101 
~XMLLastLineAdjustPropHdl()102 XMLLastLineAdjustPropHdl::~XMLLastLineAdjustPropHdl()
103 {
104     // nothing to do
105 }
106 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const107 sal_Bool XMLLastLineAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
108 {
109     sal_uInt16 eAdjust;
110     sal_Bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Align_Last_Enum );
111     if( bRet )
112         rValue <<= (sal_Int16)eAdjust;
113 
114     return bRet;
115 }
116 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const117 sal_Bool XMLLastLineAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
118 {
119     OUStringBuffer aOut;
120     sal_Int16 nVal = 0;
121     sal_Bool bRet = sal_False;
122 
123     rValue >>= nVal;
124 
125     if( nVal != style::ParagraphAdjust_LEFT )
126         bRet = SvXMLUnitConverter::convertEnum( aOut, nVal, pXML_Para_Align_Last_Enum, XML_START );
127 
128     rStrExpValue = aOut.makeStringAndClear();
129 
130     return bRet;
131 }
132 
133