xref: /trunk/main/xmloff/source/style/XMLBitmapRepeatOffsetPropertyHandler.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <xmloff/xmltoken.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <com/sun/star/uno/Any.hxx>
34 #include "XMLBitmapRepeatOffsetPropertyHandler.hxx"
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 
42 using ::xmloff::token::GetXMLToken;
43 using ::xmloff::token::XML_VERTICAL;
44 using ::xmloff::token::XML_HORIZONTAL;
45 
46 
47 XMLBitmapRepeatOffsetPropertyHandler::XMLBitmapRepeatOffsetPropertyHandler( sal_Bool bX )
48 :   mbX( bX ),
49     msVertical( GetXMLToken(XML_VERTICAL) ),
50     msHorizontal( GetXMLToken(XML_HORIZONTAL) )
51 {
52 }
53 
54 XMLBitmapRepeatOffsetPropertyHandler::~XMLBitmapRepeatOffsetPropertyHandler()
55 {
56 }
57 
58 sal_Bool XMLBitmapRepeatOffsetPropertyHandler::importXML(
59     const OUString& rStrImpValue,
60     Any& rValue,
61     const SvXMLUnitConverter& ) const
62 {
63     SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
64     OUString aToken;
65     if( aTokenEnum.getNextToken( aToken ) )
66     {
67         sal_Int32 nValue;
68         if( SvXMLUnitConverter::convertPercent( nValue, aToken ) )
69         {
70             if( aTokenEnum.getNextToken( aToken ) )
71             {
72                 if( ( mbX && ( aToken == msHorizontal ) ) || ( !mbX && ( aToken == msVertical ) ) )
73                 {
74                     rValue <<= nValue;
75                     return sal_True;
76                 }
77             }
78         }
79     }
80 
81     return sal_False;
82 
83 }
84 
85 sal_Bool XMLBitmapRepeatOffsetPropertyHandler::exportXML(
86     OUString& rStrExpValue,
87     const Any& rValue,
88     const SvXMLUnitConverter& ) const
89 {
90     OUStringBuffer aOut;
91 
92     sal_Int32 nValue = 0;
93     if( rValue >>= nValue )
94     {
95         SvXMLUnitConverter::convertPercent( aOut, nValue );
96         aOut.append( sal_Unicode( ' ' ) );
97         aOut.append( mbX ? msHorizontal : msVertical );
98         rStrExpValue = aOut.makeStringAndClear();
99 
100         return sal_True;
101     }
102 
103     return sal_False;
104 }
105 
106