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 <breakhdl.hxx> 31 #include <xmloff/xmltoken.hxx> 32 #include <xmloff/xmluconv.hxx> 33 #include <rtl/ustrbuf.hxx> 34 #include <com/sun/star/style/BreakType.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 SvXMLEnumMapEntry pXML_BreakTypes[] = 44 { 45 { XML_AUTO, 0 }, 46 { XML_COLUMN, 1 }, 47 { XML_PAGE, 2 }, 48 { XML_EVEN_PAGE, 2 }, 49 { XML_ODD_PAGE, 2 }, 50 { XML_TOKEN_INVALID, 0} 51 }; 52 53 /////////////////////////////////////////////////////////////////////////////// 54 // 55 // class XMLFmtBreakBeforePropHdl 56 // 57 58 XMLFmtBreakBeforePropHdl::~XMLFmtBreakBeforePropHdl() 59 { 60 // Nothing to do 61 } 62 63 sal_Bool XMLFmtBreakBeforePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 64 { 65 sal_uInt16 nEnum; 66 sal_Bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes ); 67 if( bRet ) 68 { 69 style::BreakType eBreak; 70 switch ( nEnum ) 71 { 72 case 0: 73 eBreak = style::BreakType_NONE; 74 break; 75 case 1: 76 eBreak = style::BreakType_COLUMN_BEFORE; 77 break; 78 default: 79 eBreak = style::BreakType_PAGE_BEFORE; 80 break; 81 } 82 rValue <<= eBreak; 83 } 84 85 return bRet; 86 } 87 88 sal_Bool XMLFmtBreakBeforePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 89 { 90 style::BreakType eBreak; 91 92 if( !( rValue >>= eBreak ) ) 93 { 94 sal_Int32 nValue = 0; 95 if( !( rValue >>= nValue ) ) 96 return sal_False; 97 98 eBreak = (style::BreakType) nValue; 99 } 100 101 sal_uInt16 nEnum = 0; 102 switch( eBreak ) 103 { 104 case style::BreakType_COLUMN_BEFORE: 105 nEnum = 1; 106 break; 107 case style::BreakType_PAGE_BEFORE: 108 nEnum = 2; 109 break; 110 case style::BreakType_NONE: 111 nEnum = 0; 112 break; 113 default: 114 return sal_False; 115 } 116 117 OUStringBuffer aOut; 118 /* sal_Bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes ); 119 rStrExpValue = aOut.makeStringAndClear(); 120 121 return sal_True; 122 } 123 124 /////////////////////////////////////////////////////////////////////////////// 125 // 126 // class XMLFmtBreakBeforePropHdl 127 // 128 129 XMLFmtBreakAfterPropHdl::~XMLFmtBreakAfterPropHdl() 130 { 131 // Nothing to do 132 } 133 134 sal_Bool XMLFmtBreakAfterPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 135 { 136 sal_uInt16 nEnum; 137 sal_Bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes ); 138 if( bRet ) 139 { 140 style::BreakType eBreak; 141 switch ( nEnum ) 142 { 143 case 0: 144 eBreak = style::BreakType_NONE; 145 break; 146 case 1: 147 eBreak = style::BreakType_COLUMN_AFTER; 148 break; 149 default: 150 eBreak = style::BreakType_PAGE_AFTER; 151 break; 152 } 153 rValue <<= eBreak; 154 } 155 156 return bRet; 157 } 158 159 sal_Bool XMLFmtBreakAfterPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 160 { 161 style::BreakType eBreak; 162 163 if( !( rValue >>= eBreak ) ) 164 { 165 sal_Int32 nValue = 0; 166 if( !( rValue >>= nValue ) ) 167 return sal_False; 168 169 eBreak = (style::BreakType) nValue; 170 } 171 172 sal_uInt16 nEnum = 0; 173 switch( eBreak ) 174 { 175 case style::BreakType_COLUMN_AFTER: 176 nEnum = 1; 177 break; 178 case style::BreakType_PAGE_AFTER: 179 nEnum = 2; 180 break; 181 case style::BreakType_NONE: 182 nEnum = 0; 183 break; 184 default: 185 return sal_False; 186 } 187 188 OUStringBuffer aOut; 189 /* sal_Bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes ); 190 rStrExpValue = aOut.makeStringAndClear(); 191 192 return sal_True; 193 } 194