xref: /trunk/main/xmloff/source/style/csmaphdl.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <csmaphdl.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <com/sun/star/style/CaseMap.hpp>
35 #include <com/sun/star/uno/Any.hxx>
36 
37 using ::rtl::OUString;
38 using ::rtl::OUStringBuffer;
39 
40 using namespace ::com::sun::star;
41 using namespace ::xmloff::token;
42 
43 static SvXMLEnumMapEntry pXML_Casemap_Enum[] =
44 {
45     { XML_NONE,                 style::CaseMap::NONE },
46     { XML_CASEMAP_LOWERCASE,    style::CaseMap::LOWERCASE },
47     { XML_CASEMAP_UPPERCASE,    style::CaseMap::UPPERCASE },
48     { XML_CASEMAP_CAPITALIZE,   style::CaseMap::TITLE },
49     { XML_TOKEN_INVALID,        0 }
50 };
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 //
54 // class XMLPosturePropHdl
55 //
56 
57 XMLCaseMapPropHdl::~XMLCaseMapPropHdl()
58 {
59     // nothing to do
60 }
61 
62 sal_Bool XMLCaseMapPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
63 {
64     sal_uInt16 nVal;
65     sal_Bool bRet = SvXMLUnitConverter::convertEnum(
66         nVal, rStrImpValue, pXML_Casemap_Enum );
67     if( ( bRet ) )
68         rValue <<= nVal;
69 
70     return bRet;
71 }
72 
73 sal_Bool XMLCaseMapPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
74 {
75     sal_Bool bRet = sal_False;
76     sal_uInt16 nValue = sal_uInt16();
77     OUStringBuffer aOut;
78 
79     if( rValue >>= nValue )
80     {
81         bRet = SvXMLUnitConverter::convertEnum(
82             aOut, nValue, pXML_Casemap_Enum );
83         if( bRet )
84             rStrExpValue = aOut.makeStringAndClear();
85     }
86 
87     return bRet;
88 }
89 
90 ///////////////////////////////////////////////////////////////////////////////
91 //
92 // class XMLCaseMapVariantHdl
93 //
94 
95 XMLCaseMapVariantHdl::~XMLCaseMapVariantHdl()
96 {
97     // nothing to do
98 }
99 
100 sal_Bool XMLCaseMapVariantHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
101 {
102     sal_Bool bRet = sal_False;
103 
104     if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
105     {
106         rValue <<= (sal_Int16)style::CaseMap::SMALLCAPS;
107         bRet = sal_True;
108     }
109     else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL ) )
110     {
111         rValue <<= (sal_Int16)style::CaseMap::NONE;
112         bRet = sal_True;
113     }
114 
115     return bRet;
116 }
117 
118 sal_Bool XMLCaseMapVariantHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
119 {
120     sal_uInt16 nValue = sal_uInt16();
121     OUStringBuffer aOut;
122 
123     if( rValue >>= nValue )
124     {
125         switch( nValue )
126         {
127         case style::CaseMap::NONE:
128             aOut.append( GetXMLToken(XML_CASEMAP_NORMAL) );
129             break;
130         case style::CaseMap::SMALLCAPS:
131             aOut.append( GetXMLToken(XML_CASEMAP_SMALL_CAPS) );
132             break;
133         }
134     }
135 
136     rStrExpValue = aOut.makeStringAndClear();
137     return rStrExpValue.getLength() != 0;
138 }
139