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 #ifndef SC_CONVUNO_HXX 29 #define SC_CONVUNO_HXX 30 31 #include <algorithm> 32 #include <i18npool/lang.h> 33 #include <com/sun/star/table/CellAddress.hpp> 34 #include <com/sun/star/table/CellRangeAddress.hpp> 35 #include <com/sun/star/lang/Locale.hpp> 36 #include "global.hxx" 37 #include "address.hxx" 38 39 40 class ScUnoConversion 41 { 42 public: 43 static LanguageType GetLanguage( const com::sun::star::lang::Locale& rLocale ); 44 static void FillLocale( com::sun::star::lang::Locale& rLocale, LanguageType eLang ); 45 46 // CellAddress -> ScAddress 47 static inline void FillScAddress( 48 ScAddress& rScAddress, 49 const ::com::sun::star::table::CellAddress& rApiAddress ); 50 // ScAddress -> CellAddress 51 static inline void FillApiAddress( 52 ::com::sun::star::table::CellAddress& rApiAddress, 53 const ScAddress& rScAddress ); 54 // CellRangeAddress -> ScRange 55 static inline void FillScRange( 56 ScRange& rScRange, 57 const ::com::sun::star::table::CellRangeAddress& rApiRange ); 58 // ScRange -> CellRangeAddress 59 static inline void FillApiRange( 60 ::com::sun::star::table::CellRangeAddress& rApiRange, 61 const ScRange& rScRange ); 62 // CellAddress -> CellRangeAddress 63 static inline void FillApiRange( 64 ::com::sun::star::table::CellRangeAddress& rApiRange, 65 const ::com::sun::star::table::CellAddress& rApiAddress ); 66 // CellRangeAddress-Start -> CellAddress 67 static inline void FillApiStartAddress( 68 ::com::sun::star::table::CellAddress& rApiAddress, 69 const ::com::sun::star::table::CellRangeAddress& rApiRange ); 70 // CellRangeAddress-End -> CellAddress 71 static inline void FillApiEndAddress( 72 ::com::sun::star::table::CellAddress& rApiAddress, 73 const ::com::sun::star::table::CellRangeAddress& rApiRange ); 74 75 /** Returns true, if the passed ranges have at least one common cell. */ 76 static inline bool Intersects( 77 const ::com::sun::star::table::CellRangeAddress& rApiARange1, 78 const ::com::sun::star::table::CellRangeAddress& rApiARange2 ); 79 /** Returns true, if the passed address rApiInner is inside the passed range rApiOuter. */ 80 static inline bool Contains( 81 const ::com::sun::star::table::CellRangeAddress& rApiOuter, 82 const ::com::sun::star::table::CellAddress& rApiInner ); 83 /** Returns true, if the passed range rApiInner is completely inside the passed range rApiOuter. */ 84 static inline bool Contains( 85 const ::com::sun::star::table::CellRangeAddress& rApiOuter, 86 const ::com::sun::star::table::CellRangeAddress& rApiInner ); 87 }; 88 89 90 inline void ScUnoConversion::FillScAddress( 91 ScAddress& rScAddress, 92 const ::com::sun::star::table::CellAddress& rApiAddress ) 93 { 94 rScAddress.Set( (SCCOL)rApiAddress.Column, (SCROW)rApiAddress.Row, (SCTAB)rApiAddress.Sheet ); 95 } 96 97 inline void ScUnoConversion::FillApiAddress( 98 ::com::sun::star::table::CellAddress& rApiAddress, 99 const ScAddress& rScAddress ) 100 { 101 rApiAddress.Column = rScAddress.Col(); 102 rApiAddress.Row = rScAddress.Row(); 103 rApiAddress.Sheet = rScAddress.Tab(); 104 } 105 106 inline void ScUnoConversion::FillScRange( 107 ScRange& rScRange, 108 const ::com::sun::star::table::CellRangeAddress& rApiRange ) 109 { 110 rScRange.aStart.Set( (SCCOL)rApiRange.StartColumn, (SCROW)rApiRange.StartRow, (SCTAB)rApiRange.Sheet ); 111 rScRange.aEnd.Set( (SCCOL)rApiRange.EndColumn, (SCROW)rApiRange.EndRow, (SCTAB)rApiRange.Sheet ); 112 } 113 114 inline void ScUnoConversion::FillApiRange( 115 ::com::sun::star::table::CellRangeAddress& rApiRange, 116 const ScRange& rScRange ) 117 { 118 rApiRange.StartColumn = rScRange.aStart.Col(); 119 rApiRange.StartRow = rScRange.aStart.Row(); 120 rApiRange.Sheet = rScRange.aStart.Tab(); 121 rApiRange.EndColumn = rScRange.aEnd.Col(); 122 rApiRange.EndRow = rScRange.aEnd.Row(); 123 } 124 125 inline void ScUnoConversion::FillApiRange( 126 ::com::sun::star::table::CellRangeAddress& rApiRange, 127 const ::com::sun::star::table::CellAddress& rApiAddress ) 128 { 129 rApiRange.StartColumn = rApiRange.EndColumn = rApiAddress.Column; 130 rApiRange.StartRow = rApiRange.EndRow = rApiAddress.Row; 131 rApiRange.Sheet = rApiAddress.Sheet; 132 } 133 134 inline void ScUnoConversion::FillApiStartAddress( 135 ::com::sun::star::table::CellAddress& rApiAddress, 136 const ::com::sun::star::table::CellRangeAddress& rApiRange ) 137 { 138 rApiAddress.Column = rApiRange.StartColumn; 139 rApiAddress.Row = rApiRange.StartRow; 140 rApiAddress.Sheet = rApiRange.Sheet; 141 } 142 143 inline void ScUnoConversion::FillApiEndAddress( 144 ::com::sun::star::table::CellAddress& rApiAddress, 145 const ::com::sun::star::table::CellRangeAddress& rApiRange ) 146 { 147 rApiAddress.Column = rApiRange.EndColumn; 148 rApiAddress.Row = rApiRange.EndRow; 149 rApiAddress.Sheet = rApiRange.Sheet; 150 } 151 152 inline bool ScUnoConversion::Intersects( 153 const ::com::sun::star::table::CellRangeAddress& rApiRange1, 154 const ::com::sun::star::table::CellRangeAddress& rApiRange2 ) 155 { 156 return (rApiRange1.Sheet == rApiRange2.Sheet) && 157 (::std::max( rApiRange1.StartColumn, rApiRange2.StartColumn ) <= ::std::min( rApiRange1.EndColumn, rApiRange2.EndColumn )) && 158 (::std::max( rApiRange1.StartRow, rApiRange2.StartRow ) <= ::std::min( rApiRange1.EndRow, rApiRange2.EndRow )); 159 } 160 161 inline bool ScUnoConversion::Contains( 162 const ::com::sun::star::table::CellRangeAddress& rApiOuter, 163 const ::com::sun::star::table::CellAddress& rApiInner ) 164 { 165 return (rApiOuter.Sheet == rApiInner.Sheet) && 166 (rApiOuter.StartColumn <= rApiInner.Column) && (rApiInner.Column <= rApiOuter.EndColumn) && 167 (rApiOuter.StartRow <= rApiInner.Row) && (rApiInner.Row <= rApiOuter.EndRow); 168 } 169 170 inline bool ScUnoConversion::Contains( 171 const ::com::sun::star::table::CellRangeAddress& rApiOuter, 172 const ::com::sun::star::table::CellRangeAddress& rApiInner ) 173 { 174 return (rApiOuter.Sheet == rApiInner.Sheet) && 175 (rApiOuter.StartColumn <= rApiInner.StartColumn) && (rApiInner.EndColumn <= rApiOuter.EndColumn) && 176 (rApiOuter.StartRow <= rApiInner.StartRow) && (rApiInner.EndRow <= rApiOuter.EndRow); 177 } 178 179 //___________________________________________________________________ 180 181 inline sal_Bool operator==( 182 const ::com::sun::star::table::CellAddress& rApiAddress1, 183 const ::com::sun::star::table::CellAddress& rApiAddress2 ) 184 { 185 return 186 (rApiAddress1.Column == rApiAddress2.Column) && 187 (rApiAddress1.Row == rApiAddress2.Row) && 188 (rApiAddress1.Sheet == rApiAddress2.Sheet); 189 } 190 191 inline sal_Bool operator!=( 192 const ::com::sun::star::table::CellAddress& rApiAddress1, 193 const ::com::sun::star::table::CellAddress& rApiAddress2 ) 194 { 195 return !(rApiAddress1 == rApiAddress2); 196 } 197 198 inline sal_Bool operator==( 199 const ::com::sun::star::table::CellRangeAddress& rApiRange1, 200 const ::com::sun::star::table::CellRangeAddress& rApiRange2 ) 201 { 202 return 203 (rApiRange1.StartColumn == rApiRange2.StartColumn) && 204 (rApiRange1.StartRow == rApiRange2.StartRow) && 205 (rApiRange1.EndColumn == rApiRange2.EndColumn) && 206 (rApiRange1.EndRow == rApiRange2.EndRow) && 207 (rApiRange1.Sheet == rApiRange2.Sheet); 208 } 209 210 inline sal_Bool operator!=( 211 const ::com::sun::star::table::CellRangeAddress& rApiRange1, 212 const ::com::sun::star::table::CellRangeAddress& rApiRange2 ) 213 { 214 return !(rApiRange1 == rApiRange2); 215 } 216 217 #endif 218 219