1*d0626817SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*d0626817SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*d0626817SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*d0626817SAndrew Rist * distributed with this work for additional information
6*d0626817SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*d0626817SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*d0626817SAndrew Rist * "License"); you may not use this file except in compliance
9*d0626817SAndrew Rist * with the License. You may obtain a copy of the License at
10*d0626817SAndrew Rist *
11*d0626817SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*d0626817SAndrew Rist *
13*d0626817SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*d0626817SAndrew Rist * software distributed under the License is distributed on an
15*d0626817SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d0626817SAndrew Rist * KIND, either express or implied. See the License for the
17*d0626817SAndrew Rist * specific language governing permissions and limitations
18*d0626817SAndrew Rist * under the License.
19*d0626817SAndrew Rist *
20*d0626817SAndrew Rist *************************************************************/
21*d0626817SAndrew Rist
22*d0626817SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "dpglobal.hxx"
28cdf0e10cSrcweir #include "dpobject.hxx"
29cdf0e10cSrcweir #include "document.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir namespace ScDPGlobal
34cdf0e10cSrcweir {
operator *(const Rectangle & rLeft,const std::pair<double,double> & rRight)35cdf0e10cSrcweir Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir Rectangle rcResult( rLeft );
38cdf0e10cSrcweir rcResult.Bottom() = rcResult.Top() + static_cast<long>( rcResult.GetHeight() * rRight.second );
39cdf0e10cSrcweir rcResult.Right() = rcResult.Left() + static_cast<long>( rcResult.GetWidth() * rRight.first);
40cdf0e10cSrcweir return rcResult;
41cdf0e10cSrcweir }
42cdf0e10cSrcweir
GetFuncString(const String & rString,const sal_uInt16 nIndex)43cdf0e10cSrcweir String GetFuncString( const String &rString, const sal_uInt16 nIndex )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir if ( nIndex <= 1 ) return rString;
46cdf0e10cSrcweir sal_uLong uch = rString.Len() ? rString.GetChar( rString.Len()-1 ) : (L'9'+1);
47cdf0e10cSrcweir bool bEndWithDigital = ( L'0'<=uch && uch<=L'9');
48cdf0e10cSrcweir char szTemp[__MAX_NUM_LEN+1];
49cdf0e10cSrcweir int nLen = sprintf( szTemp, bEndWithDigital ? DATA_RENAME_SEPARATOR"%hu" : "%hu", nIndex );
50cdf0e10cSrcweir String strRet = rString;
51cdf0e10cSrcweir strRet.Append( String::CreateFromAscii( szTemp, static_cast<sal_uInt16>(nLen) ));
52cdf0e10cSrcweir return strRet;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
ChkDPTableOverlap(ScDocument * pDestDoc,std::list<ScDPObject> & rClipboard,SCCOL nClipStartCol,SCROW nClipStartRow,SCCOL nStartCol,SCROW nStartRow,SCTAB nStartTab,sal_uInt16 nEndTab,sal_Bool bExcludeClip)55cdf0e10cSrcweir 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*/ )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir if ( ScDPCollection* pDPCollection = pDestDoc->GetDPCollection() )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir sal_uInt16 nCount = pDPCollection->GetCount();
60cdf0e10cSrcweir SCsCOL nOffsetX = nStartCol - nClipStartCol;
61cdf0e10cSrcweir SCsROW nOffsetY = nStartRow - nClipStartRow;
62cdf0e10cSrcweir
63cdf0e10cSrcweir for( std::list<ScDPObject>::iterator iter = rClipboard.begin(); iter!=rClipboard.end(); iter++ )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir ScRange aRange = iter->GetOutRange();
66cdf0e10cSrcweir
67cdf0e10cSrcweir for( sal_uInt16 nCurrTab = nStartTab; nCurrTab<=nEndTab; nCurrTab++ )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir SCsTAB nOffsetZ = nCurrTab - aRange.aStart.Tab();
70cdf0e10cSrcweir aRange.Move( nOffsetX, nOffsetY, nOffsetZ );
71cdf0e10cSrcweir
72cdf0e10cSrcweir for ( sal_uInt16 i = 0; i<nCount; i++)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir if ( (*pDPCollection)[i] && aRange.Intersects( (*pDPCollection)[i]->GetOutRange()))
75cdf0e10cSrcweir {
76cdf0e10cSrcweir if ( bExcludeClip && iter->GetOutRange() == (*pDPCollection)[i]->GetOutRange() )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir continue;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir return false;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir }
86cdf0e10cSrcweir return true;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir //end
89cdf0e10cSrcweir
90cdf0e10cSrcweir }
91cdf0e10cSrcweir // --------------------------------------------------------------------
92cdf0e10cSrcweir // ScDPItemDataPool
93cdf0e10cSrcweir // Construct
ScDPItemDataPool(void)94cdf0e10cSrcweir ScDPItemDataPool::ScDPItemDataPool(void)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir }
97cdf0e10cSrcweir //
ScDPItemDataPool(const ScDPItemDataPool & r)98cdf0e10cSrcweir ScDPItemDataPool::ScDPItemDataPool(const ScDPItemDataPool& r):
99cdf0e10cSrcweir maItems(r.maItems),
100cdf0e10cSrcweir maItemIds(r.maItemIds)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
~ScDPItemDataPool(void)104cdf0e10cSrcweir ScDPItemDataPool::~ScDPItemDataPool(void)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir
getData(sal_Int32 nId)109cdf0e10cSrcweir const ScDPItemData* ScDPItemDataPool::getData( sal_Int32 nId )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir if ( nId >= static_cast<sal_Int32>(maItems.size()) )
112cdf0e10cSrcweir return NULL;
113cdf0e10cSrcweir else
114cdf0e10cSrcweir return &(maItems[nId]);
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
getDataId(const ScDPItemData & aData)117cdf0e10cSrcweir sal_Int32 ScDPItemDataPool::getDataId( const ScDPItemData& aData )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir DataHash::const_iterator itr = maItemIds.find( aData),
120cdf0e10cSrcweir itrEnd = maItemIds.end();
121cdf0e10cSrcweir if ( itr == itrEnd )
122cdf0e10cSrcweir // not exist
123cdf0e10cSrcweir return -1;
124cdf0e10cSrcweir
125cdf0e10cSrcweir else //exist
126cdf0e10cSrcweir return itr->second;
127cdf0e10cSrcweir
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
insertData(const ScDPItemData & aData)130cdf0e10cSrcweir sal_Int32 ScDPItemDataPool::insertData( const ScDPItemData& aData )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir sal_Int32 nResult = getDataId( aData );
133cdf0e10cSrcweir
134cdf0e10cSrcweir if( nResult < 0 )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir maItemIds.insert( DataHash::value_type( aData, nResult = maItems.size() ) );
137cdf0e10cSrcweir maItems.push_back( aData );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir return nResult;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir
144