1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright IBM Corporation 2009. 6 * Copyright 2009 by Sun Microsystems, Inc. 7 * 8 * OpenOffice.org - a multi-platform office productivity suite 9 * 10 * $RCSfile: dpglobal.cxx,v $ 11 * $Revision: 1.0 $ 12 * 13 * This file is part of OpenOffice.org. 14 * 15 * OpenOffice.org is free software: you can redistribute it and/or modify 16 * it under the terms of the GNU Lesser General Public License version 3 17 * only, as published by the Free Software Foundation. 18 * 19 * OpenOffice.org is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU Lesser General Public License version 3 for more details 23 * (a copy is included in the LICENSE file that accompanied this code). 24 * 25 * You should have received a copy of the GNU Lesser General Public License 26 * version 3 along with OpenOffice.org. If not, see 27 * <http://www.openoffice.org/license.html> 28 * for a copy of the LGPLv3 License. 29 * 30 ************************************************************************/ 31 32 // MARKER(update_precomp.py): autogen include statement, do not remove 33 #include "precompiled_sc.hxx" 34 35 #include "dpglobal.hxx" 36 #include "dpobject.hxx" 37 #include "document.hxx" 38 39 #include <stdio.h> 40 41 namespace ScDPGlobal 42 { 43 Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight ) 44 { 45 Rectangle rcResult( rLeft ); 46 rcResult.Bottom() = rcResult.Top() + static_cast<long>( rcResult.GetHeight() * rRight.second ); 47 rcResult.Right() = rcResult.Left() + static_cast<long>( rcResult.GetWidth() * rRight.first); 48 return rcResult; 49 } 50 51 String GetFuncString( const String &rString, const sal_uInt16 nIndex ) 52 { 53 if ( nIndex <= 1 ) return rString; 54 sal_uLong uch = rString.Len() ? rString.GetChar( rString.Len()-1 ) : (L'9'+1); 55 bool bEndWithDigital = ( L'0'<=uch && uch<=L'9'); 56 char szTemp[__MAX_NUM_LEN+1]; 57 int nLen = sprintf( szTemp, bEndWithDigital ? DATA_RENAME_SEPARATOR"%hu" : "%hu", nIndex ); 58 String strRet = rString; 59 strRet.Append( String::CreateFromAscii( szTemp, static_cast<sal_uInt16>(nLen) )); 60 return strRet; 61 } 62 63 bool ChkDPTableOverlap( ScDocument *pDestDoc, std::list<ScDPObject> & rClipboard, SCCOL nClipStartCol, SCROW nClipStartRow, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, sal_uInt16 nEndTab, sal_Bool bExcludeClip /*= sal_False*/ ) 64 { 65 if ( ScDPCollection* pDPCollection = pDestDoc->GetDPCollection() ) 66 { 67 sal_uInt16 nCount = pDPCollection->GetCount(); 68 SCsCOL nOffsetX = nStartCol - nClipStartCol; 69 SCsROW nOffsetY = nStartRow - nClipStartRow; 70 71 for( std::list<ScDPObject>::iterator iter = rClipboard.begin(); iter!=rClipboard.end(); iter++ ) 72 { 73 ScRange aRange = iter->GetOutRange(); 74 75 for( sal_uInt16 nCurrTab = nStartTab; nCurrTab<=nEndTab; nCurrTab++ ) 76 { 77 SCsTAB nOffsetZ = nCurrTab - aRange.aStart.Tab(); 78 aRange.Move( nOffsetX, nOffsetY, nOffsetZ ); 79 80 for ( sal_uInt16 i = 0; i<nCount; i++) 81 { 82 if ( (*pDPCollection)[i] && aRange.Intersects( (*pDPCollection)[i]->GetOutRange())) 83 { 84 if ( bExcludeClip && iter->GetOutRange() == (*pDPCollection)[i]->GetOutRange() ) 85 { 86 continue; 87 } 88 return false; 89 } 90 } 91 } 92 } 93 } 94 return true; 95 } 96 //end 97 98 } 99 // -------------------------------------------------------------------- 100 // ScDPItemDataPool 101 // Construct 102 ScDPItemDataPool::ScDPItemDataPool(void) 103 { 104 } 105 // 106 ScDPItemDataPool::ScDPItemDataPool(const ScDPItemDataPool& r): 107 maItems(r.maItems), 108 maItemIds(r.maItemIds) 109 { 110 } 111 112 ScDPItemDataPool::~ScDPItemDataPool(void) 113 { 114 } 115 116 117 const ScDPItemData* ScDPItemDataPool::getData( sal_Int32 nId ) 118 { 119 if ( nId >= static_cast<sal_Int32>(maItems.size()) ) 120 return NULL; 121 else 122 return &(maItems[nId]); 123 } 124 125 sal_Int32 ScDPItemDataPool::getDataId( const ScDPItemData& aData ) 126 { 127 DataHash::const_iterator itr = maItemIds.find( aData), 128 itrEnd = maItemIds.end(); 129 if ( itr == itrEnd ) 130 // not exist 131 return -1; 132 133 else //exist 134 return itr->second; 135 136 } 137 138 sal_Int32 ScDPItemDataPool::insertData( const ScDPItemData& aData ) 139 { 140 sal_Int32 nResult = getDataId( aData ); 141 142 if( nResult < 0 ) 143 { 144 maItemIds.insert( DataHash::value_type( aData, nResult = maItems.size() ) ); 145 maItems.push_back( aData ); 146 } 147 148 return nResult; 149 } 150 151 152