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