1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <tools/debug.hxx>
30 #include <backhdl.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <sax/tools/converter.hxx>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <rtl/ustrbuf.hxx>
37 using ::rtl::OUString
;
38 using ::rtl::OUStringBuffer
;
40 using namespace ::com::sun::star
;
41 using namespace ::xmloff::token
;
43 SvXMLEnumMapEntry pXML_BrushHorizontalPos
[] =
45 { XML_LEFT
, style::GraphicLocation_LEFT_MIDDLE
},
46 { XML_RIGHT
, style::GraphicLocation_RIGHT_MIDDLE
},
47 { XML_TOKEN_INVALID
, 0 }
50 SvXMLEnumMapEntry pXML_BrushVerticalPos
[] =
52 { XML_TOP
, style::GraphicLocation_MIDDLE_TOP
},
53 { XML_BOTTOM
, style::GraphicLocation_MIDDLE_BOTTOM
},
54 { XML_TOKEN_INVALID
, 0 }
57 ///////////////////////////////////////////////////////////////////////////////
59 // class XMLBackGraphicPositionPropHdl
62 XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl()
67 sal_Bool
XMLBackGraphicPositionPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
69 sal_Bool bRet
= sal_True
;
70 style::GraphicLocation ePos
= style::GraphicLocation_NONE
, eTmp
;
72 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
74 sal_Bool bHori
= sal_False
, bVert
= sal_False
;
76 while( bRet
&& aTokenEnum
.getNextToken( aToken
) )
82 else if( -1 != aToken
.indexOf( sal_Unicode('%') ) )
85 if (::sax::Converter::convertPercent( nPrc
, aToken
))
89 ePos
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
90 (nPrc
< 75 ? style::GraphicLocation_MIDDLE_MIDDLE
:
91 style::GraphicLocation_RIGHT_BOTTOM
);
96 eTmp
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
97 (nPrc
< 75 ? style::GraphicLocation_LEFT_MIDDLE
:
98 style::GraphicLocation_LEFT_BOTTOM
);
99 MergeXMLVertPos( ePos
, eTmp
);
109 else if( IsXMLToken( aToken
, XML_CENTER
) )
112 MergeXMLVertPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
114 MergeXMLHoriPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
116 ePos
= style::GraphicLocation_MIDDLE_MIDDLE
;
118 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushHorizontalPos
) )
121 MergeXMLHoriPos( ePos
, (style::GraphicLocation
)nTmp
);
123 ePos
= (style::GraphicLocation
)nTmp
;
129 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushVerticalPos
) )
132 MergeXMLVertPos( ePos
, (style::GraphicLocation
)nTmp
);
134 ePos
= (style::GraphicLocation
)nTmp
;
145 bRet
&= style::GraphicLocation_NONE
!= ePos
;
147 rValue
<<= (style::GraphicLocation
)(sal_uInt16
)ePos
;
152 sal_Bool
XMLBackGraphicPositionPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
154 sal_Bool bRet
= sal_True
;
157 style::GraphicLocation eLocation
;
158 if( !( rValue
>>= eLocation
) )
160 sal_Int32 nValue
= 0;
161 if( rValue
>>= nValue
)
162 eLocation
= (style::GraphicLocation
)nValue
;
173 case style::GraphicLocation_LEFT_TOP
:
174 case style::GraphicLocation_MIDDLE_TOP
:
175 case style::GraphicLocation_RIGHT_TOP
:
176 aOut
.append( GetXMLToken(XML_TOP
) );
179 case style::GraphicLocation_LEFT_MIDDLE
:
180 case style::GraphicLocation_MIDDLE_MIDDLE
:
181 case style::GraphicLocation_RIGHT_MIDDLE
:
182 aOut
.append( GetXMLToken(XML_CENTER
) );
185 case style::GraphicLocation_LEFT_BOTTOM
:
186 case style::GraphicLocation_MIDDLE_BOTTOM
:
187 case style::GraphicLocation_RIGHT_BOTTOM
:
188 aOut
.append( GetXMLToken(XML_BOTTOM
) );
197 aOut
.append( sal_Unicode( ' ' ) );
201 case style::GraphicLocation_LEFT_TOP
:
202 case style::GraphicLocation_LEFT_BOTTOM
:
203 case style::GraphicLocation_LEFT_MIDDLE
:
204 aOut
.append( GetXMLToken(XML_LEFT
) );
206 case style::GraphicLocation_MIDDLE_TOP
:
207 case style::GraphicLocation_MIDDLE_MIDDLE
:
208 case style::GraphicLocation_MIDDLE_BOTTOM
:
209 aOut
.append( GetXMLToken(XML_CENTER
) );
211 case style::GraphicLocation_RIGHT_MIDDLE
:
212 case style::GraphicLocation_RIGHT_TOP
:
213 case style::GraphicLocation_RIGHT_BOTTOM
:
214 aOut
.append( GetXMLToken(XML_RIGHT
) );
222 rStrExpValue
= aOut
.makeStringAndClear();
227 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation
& ePos
, style::GraphicLocation eVert
) const
231 case style::GraphicLocation_LEFT_TOP
:
232 case style::GraphicLocation_LEFT_MIDDLE
:
233 case style::GraphicLocation_LEFT_BOTTOM
:
234 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
235 style::GraphicLocation_LEFT_TOP
:
236 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
237 style::GraphicLocation_LEFT_MIDDLE
:
238 style::GraphicLocation_LEFT_BOTTOM
);
242 case style::GraphicLocation_MIDDLE_TOP
:
243 case style::GraphicLocation_MIDDLE_MIDDLE
:
244 case style::GraphicLocation_MIDDLE_BOTTOM
:
248 case style::GraphicLocation_RIGHT_TOP
:
249 case style::GraphicLocation_RIGHT_MIDDLE
:
250 case style::GraphicLocation_RIGHT_BOTTOM
:
251 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
252 style::GraphicLocation_RIGHT_TOP
:
253 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
254 style::GraphicLocation_RIGHT_MIDDLE
:
255 style::GraphicLocation_RIGHT_BOTTOM
);
262 void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation
& ePos
, style::GraphicLocation eHori
) const
264 DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE
==eHori
|| style::GraphicLocation_MIDDLE_MIDDLE
==eHori
|| style::GraphicLocation_RIGHT_MIDDLE
==eHori
,
265 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
269 case style::GraphicLocation_LEFT_TOP
:
270 case style::GraphicLocation_MIDDLE_TOP
:
271 case style::GraphicLocation_RIGHT_TOP
:
272 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
273 style::GraphicLocation_LEFT_TOP
:
274 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
275 style::GraphicLocation_MIDDLE_TOP
:
276 style::GraphicLocation_RIGHT_TOP
);
279 case style::GraphicLocation_LEFT_MIDDLE
:
280 case style::GraphicLocation_MIDDLE_MIDDLE
:
281 case style::GraphicLocation_RIGHT_MIDDLE
:
285 case style::GraphicLocation_LEFT_BOTTOM
:
286 case style::GraphicLocation_MIDDLE_BOTTOM
:
287 case style::GraphicLocation_RIGHT_BOTTOM
:
288 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
289 style::GraphicLocation_LEFT_BOTTOM
:
290 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
291 style::GraphicLocation_MIDDLE_BOTTOM
:
292 style::GraphicLocation_RIGHT_BOTTOM
);
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */