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_sc.hxx"
26
27 #include "dpglobal.hxx"
28 #include "dpobject.hxx"
29 #include "document.hxx"
30
31 #include <stdio.h>
32
33 namespace ScDPGlobal
34 {
operator *(const Rectangle & rLeft,const std::pair<double,double> & rRight)35 Rectangle operator *( const Rectangle &rLeft, const std::pair<double,double> & rRight )
36 {
37 Rectangle rcResult( rLeft );
38 rcResult.Bottom() = rcResult.Top() + static_cast<long>( rcResult.GetHeight() * rRight.second );
39 rcResult.Right() = rcResult.Left() + static_cast<long>( rcResult.GetWidth() * rRight.first);
40 return rcResult;
41 }
42
GetFuncString(const String & rString,const sal_uInt16 nIndex)43 String GetFuncString( const String &rString, const sal_uInt16 nIndex )
44 {
45 if ( nIndex <= 1 ) return rString;
46 sal_uLong uch = rString.Len() ? rString.GetChar( rString.Len()-1 ) : (L'9'+1);
47 bool bEndWithDigital = ( L'0'<=uch && uch<=L'9');
48 char szTemp[__MAX_NUM_LEN+1];
49 int nLen = sprintf( szTemp, bEndWithDigital ? DATA_RENAME_SEPARATOR"%hu" : "%hu", nIndex );
50 String strRet = rString;
51 strRet.Append( String::CreateFromAscii( szTemp, static_cast<sal_uInt16>(nLen) ));
52 return strRet;
53 }
54
ChkDPTableOverlap(ScDocument * pDestDoc,std::list<ScDPObject> & rClipboard,SCCOL nClipStartCol,SCROW nClipStartRow,SCCOL nStartCol,SCROW nStartRow,SCTAB nStartTab,sal_uInt16 nEndTab,sal_Bool bExcludeClip)55 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*/ )
56 {
57 if ( ScDPCollection* pDPCollection = pDestDoc->GetDPCollection() )
58 {
59 sal_uInt16 nCount = pDPCollection->GetCount();
60 SCsCOL nOffsetX = nStartCol - nClipStartCol;
61 SCsROW nOffsetY = nStartRow - nClipStartRow;
62
63 for( std::list<ScDPObject>::iterator iter = rClipboard.begin(); iter!=rClipboard.end(); iter++ )
64 {
65 ScRange aRange = iter->GetOutRange();
66
67 for( sal_uInt16 nCurrTab = nStartTab; nCurrTab<=nEndTab; nCurrTab++ )
68 {
69 SCsTAB nOffsetZ = nCurrTab - aRange.aStart.Tab();
70 aRange.Move( nOffsetX, nOffsetY, nOffsetZ );
71
72 for ( sal_uInt16 i = 0; i<nCount; i++)
73 {
74 if ( (*pDPCollection)[i] && aRange.Intersects( (*pDPCollection)[i]->GetOutRange()))
75 {
76 if ( bExcludeClip && iter->GetOutRange() == (*pDPCollection)[i]->GetOutRange() )
77 {
78 continue;
79 }
80 return false;
81 }
82 }
83 }
84 }
85 }
86 return true;
87 }
88 //end
89
90 }
91 // --------------------------------------------------------------------
92 // ScDPItemDataPool
93 // Construct
ScDPItemDataPool(void)94 ScDPItemDataPool::ScDPItemDataPool(void)
95 {
96 }
97 //
ScDPItemDataPool(const ScDPItemDataPool & r)98 ScDPItemDataPool::ScDPItemDataPool(const ScDPItemDataPool& r):
99 maItems(r.maItems),
100 maItemIds(r.maItemIds)
101 {
102 }
103
~ScDPItemDataPool(void)104 ScDPItemDataPool::~ScDPItemDataPool(void)
105 {
106 }
107
108
getData(sal_Int32 nId)109 const ScDPItemData* ScDPItemDataPool::getData( sal_Int32 nId )
110 {
111 if ( nId >= static_cast<sal_Int32>(maItems.size()) )
112 return NULL;
113 else
114 return &(maItems[nId]);
115 }
116
getDataId(const ScDPItemData & aData)117 sal_Int32 ScDPItemDataPool::getDataId( const ScDPItemData& aData )
118 {
119 DataHash::const_iterator itr = maItemIds.find( aData),
120 itrEnd = maItemIds.end();
121 if ( itr == itrEnd )
122 // not exist
123 return -1;
124
125 else //exist
126 return itr->second;
127
128 }
129
insertData(const ScDPItemData & aData)130 sal_Int32 ScDPItemDataPool::insertData( const ScDPItemData& aData )
131 {
132 sal_Int32 nResult = getDataId( aData );
133
134 if( nResult < 0 )
135 {
136 maItemIds.insert( DataHash::value_type( aData, nResult = maItems.size() ) );
137 maItems.push_back( aData );
138 }
139
140 return nResult;
141 }
142
143
144