xref: /trunk/main/sc/source/ui/view/viewfun2.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "scitems.hxx"
34*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sfx2/app.hxx>
37*cdf0e10cSrcweir #define _SVSTDARR_STRINGS
38*cdf0e10cSrcweir #include <editeng/boxitem.hxx>
39*cdf0e10cSrcweir #include <editeng/fontitem.hxx>
40*cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
41*cdf0e10cSrcweir #include <svl/srchitem.hxx>
42*cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
43*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
44*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
45*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
46*cdf0e10cSrcweir #include <sfx2/objitem.hxx>
47*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
48*cdf0e10cSrcweir #include <svl/stritem.hxx>
49*cdf0e10cSrcweir #include <svl/zforlist.hxx>
50*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
51*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
52*cdf0e10cSrcweir #include <vcl/sound.hxx>
53*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include "viewfunc.hxx"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include "sc.hrc"
58*cdf0e10cSrcweir #include "globstr.hrc"
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #include "attrib.hxx"
61*cdf0e10cSrcweir #include "autoform.hxx"
62*cdf0e10cSrcweir #include "cell.hxx"					// EnterAutoSum
63*cdf0e10cSrcweir #include "compiler.hxx"
64*cdf0e10cSrcweir #include "docfunc.hxx"
65*cdf0e10cSrcweir #include "docpool.hxx"
66*cdf0e10cSrcweir #include "docsh.hxx"
67*cdf0e10cSrcweir #include "global.hxx"
68*cdf0e10cSrcweir #include "patattr.hxx"
69*cdf0e10cSrcweir #include "printfun.hxx"
70*cdf0e10cSrcweir #include "rangenam.hxx"
71*cdf0e10cSrcweir #include "rangeutl.hxx"
72*cdf0e10cSrcweir #include "refundo.hxx"
73*cdf0e10cSrcweir #include "tablink.hxx"
74*cdf0e10cSrcweir #include "tabvwsh.hxx"
75*cdf0e10cSrcweir #include "uiitems.hxx"
76*cdf0e10cSrcweir #include "undoblk.hxx"
77*cdf0e10cSrcweir #include "undocell.hxx"
78*cdf0e10cSrcweir #include "undotab.hxx"
79*cdf0e10cSrcweir #include "sizedev.hxx"
80*cdf0e10cSrcweir #include "editable.hxx"
81*cdf0e10cSrcweir #include "scmod.hxx"
82*cdf0e10cSrcweir #include "inputhdl.hxx"
83*cdf0e10cSrcweir #include "inputwin.hxx"
84*cdf0e10cSrcweir #include "funcdesc.hxx"
85*cdf0e10cSrcweir #include "docuno.hxx"
86*cdf0e10cSrcweir #include "charthelper.hxx"
87*cdf0e10cSrcweir #include "tabbgcolor.hxx"
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir #include <basic/sbstar.hxx>
90*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
91*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer.hpp>
92*cdf0e10cSrcweir using namespace com::sun::star;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir // helper func defined in docfunc.cxx
95*cdf0e10cSrcweir void VBA_DeleteModule( ScDocShell& rDocSh, String& sModuleName );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir // STATIC DATA ---------------------------------------------------------------
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir //----------------------------------------------------------------------------
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir sal_Bool ScViewFunc::AdjustBlockHeight( sal_Bool bPaint, ScMarkData* pMarkData )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
105*cdf0e10cSrcweir 	if (!pMarkData)
106*cdf0e10cSrcweir 		pMarkData = &GetViewData()->GetMarkData();
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
109*cdf0e10cSrcweir 	SCCOLROW* pRanges = new SCCOLROW[MAXCOLROWCOUNT];
110*cdf0e10cSrcweir 	SCCOLROW nRangeCnt = pMarkData->GetMarkRowRanges( pRanges );
111*cdf0e10cSrcweir 	if (nRangeCnt == 0)
112*cdf0e10cSrcweir 	{
113*cdf0e10cSrcweir 		pRanges[0] = pRanges[1] = GetViewData()->GetCurY();
114*cdf0e10cSrcweir 		nRangeCnt = 1;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	double nPPTX = GetViewData()->GetPPTX();
118*cdf0e10cSrcweir 	double nPPTY = GetViewData()->GetPPTY();
119*cdf0e10cSrcweir 	Fraction aZoomX = GetViewData()->GetZoomX();
120*cdf0e10cSrcweir 	Fraction aZoomY = GetViewData()->GetZoomY();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	ScSizeDeviceProvider aProv(pDocSh);
123*cdf0e10cSrcweir 	if (aProv.IsPrinter())
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		nPPTX = aProv.GetPPTX();
126*cdf0e10cSrcweir 		nPPTY = aProv.GetPPTY();
127*cdf0e10cSrcweir 		aZoomX = aZoomY = Fraction( 1, 1 );
128*cdf0e10cSrcweir 	}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	sal_Bool bAnyChanged = sal_False;
131*cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
132*cdf0e10cSrcweir 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
133*cdf0e10cSrcweir 	{
134*cdf0e10cSrcweir 		if (pMarkData->GetTableSelect(nTab))
135*cdf0e10cSrcweir 		{
136*cdf0e10cSrcweir 			SCCOLROW* pOneRange = pRanges;
137*cdf0e10cSrcweir 			sal_Bool bChanged = sal_False;
138*cdf0e10cSrcweir             SCROW nPaintY = 0;
139*cdf0e10cSrcweir 			for (SCROW nRangeNo=0; nRangeNo<nRangeCnt; nRangeNo++)
140*cdf0e10cSrcweir 			{
141*cdf0e10cSrcweir 				SCROW nStartNo = *(pOneRange++);
142*cdf0e10cSrcweir 				SCROW nEndNo = *(pOneRange++);
143*cdf0e10cSrcweir 				if (pDoc->SetOptimalHeight( nStartNo, nEndNo, nTab, 0, aProv.GetDevice(),
144*cdf0e10cSrcweir 											nPPTX, nPPTY, aZoomX, aZoomY, sal_False ))
145*cdf0e10cSrcweir 				{
146*cdf0e10cSrcweir 					if (!bChanged)
147*cdf0e10cSrcweir 						nPaintY = nStartNo;
148*cdf0e10cSrcweir 					bAnyChanged = bChanged = sal_True;
149*cdf0e10cSrcweir 				}
150*cdf0e10cSrcweir 			}
151*cdf0e10cSrcweir 			if ( bPaint && bChanged )
152*cdf0e10cSrcweir 				pDocSh->PostPaint( 0, nPaintY, nTab, MAXCOL, MAXROW, nTab,
153*cdf0e10cSrcweir 													PAINT_GRID | PAINT_LEFT );
154*cdf0e10cSrcweir 		}
155*cdf0e10cSrcweir 	}
156*cdf0e10cSrcweir 	delete[] pRanges;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	if ( bPaint && bAnyChanged )
159*cdf0e10cSrcweir 		pDocSh->UpdateOle(GetViewData());
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	return bAnyChanged;
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //----------------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir sal_Bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, sal_Bool bPaint )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
170*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
171*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
172*cdf0e10cSrcweir 	double nPPTX = GetViewData()->GetPPTX();
173*cdf0e10cSrcweir 	double nPPTY = GetViewData()->GetPPTY();
174*cdf0e10cSrcweir 	Fraction aZoomX = GetViewData()->GetZoomX();
175*cdf0e10cSrcweir 	Fraction aZoomY = GetViewData()->GetZoomY();
176*cdf0e10cSrcweir     sal_uInt16 nOldPixel = 0;
177*cdf0e10cSrcweir 	if (nStartRow == nEndRow)
178*cdf0e10cSrcweir 		nOldPixel = (sal_uInt16) (pDoc->GetRowHeight(nStartRow,nTab) * nPPTY);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	ScSizeDeviceProvider aProv(pDocSh);
181*cdf0e10cSrcweir 	if (aProv.IsPrinter())
182*cdf0e10cSrcweir 	{
183*cdf0e10cSrcweir 		nPPTX = aProv.GetPPTX();
184*cdf0e10cSrcweir 		nPPTY = aProv.GetPPTY();
185*cdf0e10cSrcweir 		aZoomX = aZoomY = Fraction( 1, 1 );
186*cdf0e10cSrcweir 	}
187*cdf0e10cSrcweir 	sal_Bool bChanged = pDoc->SetOptimalHeight( nStartRow, nEndRow, nTab, 0, aProv.GetDevice(),
188*cdf0e10cSrcweir 											nPPTX, nPPTY, aZoomX, aZoomY, sal_False );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	if (bChanged && ( nStartRow == nEndRow ))
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 		sal_uInt16 nNewPixel = (sal_uInt16) (pDoc->GetRowHeight(nStartRow,nTab) * nPPTY);
193*cdf0e10cSrcweir 		if ( nNewPixel == nOldPixel )
194*cdf0e10cSrcweir 			bChanged = sal_False;
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	if ( bPaint && bChanged )
198*cdf0e10cSrcweir 		pDocSh->PostPaint( 0, nStartRow, nTab, MAXCOL, MAXROW, nTab,
199*cdf0e10cSrcweir 											PAINT_GRID | PAINT_LEFT );
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	return bChanged;
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //----------------------------------------------------------------------------
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir enum ScAutoSum
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	ScAutoSumNone = 0,
210*cdf0e10cSrcweir 	ScAutoSumData,
211*cdf0e10cSrcweir 	ScAutoSumSum
212*cdf0e10cSrcweir };
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir ScAutoSum lcl_IsAutoSumData( ScDocument* pDoc, SCCOL nCol, SCROW nRow,
216*cdf0e10cSrcweir 		SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	ScBaseCell* pCell;
219*cdf0e10cSrcweir 	pDoc->GetCell( nCol, nRow, nTab, pCell );
220*cdf0e10cSrcweir 	if ( pCell && pCell->HasValueData() )
221*cdf0e10cSrcweir 	{
222*cdf0e10cSrcweir 		if ( pCell->GetCellType() == CELLTYPE_FORMULA )
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			ScTokenArray* pCode = ((ScFormulaCell*)pCell)->GetCode();
225*cdf0e10cSrcweir 			if ( pCode && pCode->GetOuterFuncOpCode() == ocSum )
226*cdf0e10cSrcweir 			{
227*cdf0e10cSrcweir 				if ( pCode->GetAdjacentExtendOfOuterFuncRefs( nExtend,
228*cdf0e10cSrcweir 						ScAddress( nCol, nRow, nTab ), eDir ) )
229*cdf0e10cSrcweir 					return ScAutoSumSum;
230*cdf0e10cSrcweir 			}
231*cdf0e10cSrcweir 		}
232*cdf0e10cSrcweir 		return ScAutoSumData;
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 	return ScAutoSumNone;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir //----------------------------------------------------------------------------
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir #define SC_AUTOSUM_MAXCOUNT		20
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir ScAutoSum lcl_SeekAutoSumData( ScDocument* pDoc, SCCOL& nCol, SCROW& nRow,
243*cdf0e10cSrcweir 		SCTAB nTab, ScDirection eDir, SCCOLROW& nExtend )
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir 	sal_uInt16 nCount = 0;
246*cdf0e10cSrcweir 	while (nCount < SC_AUTOSUM_MAXCOUNT)
247*cdf0e10cSrcweir 	{
248*cdf0e10cSrcweir 		if ( eDir == DIR_TOP )
249*cdf0e10cSrcweir 		{
250*cdf0e10cSrcweir 			if (nRow > 0)
251*cdf0e10cSrcweir 				--nRow;
252*cdf0e10cSrcweir 			else
253*cdf0e10cSrcweir 				return ScAutoSumNone;
254*cdf0e10cSrcweir 		}
255*cdf0e10cSrcweir 		else
256*cdf0e10cSrcweir 		{
257*cdf0e10cSrcweir 			if (nCol > 0)
258*cdf0e10cSrcweir 				--nCol;
259*cdf0e10cSrcweir 			else
260*cdf0e10cSrcweir 				return ScAutoSumNone;
261*cdf0e10cSrcweir 		}
262*cdf0e10cSrcweir 		ScAutoSum eSum;
263*cdf0e10cSrcweir 		if ( (eSum = lcl_IsAutoSumData(
264*cdf0e10cSrcweir 				pDoc, nCol, nRow, nTab, eDir, nExtend )) != ScAutoSumNone )
265*cdf0e10cSrcweir 			return eSum;
266*cdf0e10cSrcweir 		++nCount;
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir 	return ScAutoSumNone;
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir #undef SC_AUTOSUM_MAXCOUNT
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir //----------------------------------------------------------------------------
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir bool lcl_FindNextSumEntryInColumn( ScDocument* pDoc, SCCOL nCol, SCROW& nRow,
276*cdf0e10cSrcweir                                    SCTAB nTab, SCCOLROW& nExtend, SCROW nMinRow )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     const SCROW nTmp = nRow;
279*cdf0e10cSrcweir     ScAutoSum eSkip = ScAutoSumNone;
280*cdf0e10cSrcweir     while ( ( eSkip = lcl_IsAutoSumData( pDoc, nCol, nRow, nTab, DIR_TOP, nExtend ) ) == ScAutoSumData &&
281*cdf0e10cSrcweir             nRow > nMinRow )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         --nRow;
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir     if ( eSkip == ScAutoSumSum && nRow < nTmp )
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         return true;
288*cdf0e10cSrcweir     }
289*cdf0e10cSrcweir     return false;
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir //----------------------------------------------------------------------------
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir bool lcl_FindNextSumEntryInRow( ScDocument* pDoc, SCCOL& nCol, SCROW nRow,
295*cdf0e10cSrcweir                                 SCTAB nTab, SCCOLROW& nExtend, SCROW nMinCol )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     const SCCOL nTmp = nCol;
298*cdf0e10cSrcweir     ScAutoSum eSkip = ScAutoSumNone;
299*cdf0e10cSrcweir     while ( ( eSkip = lcl_IsAutoSumData( pDoc, nCol, nRow, nTab, DIR_LEFT, nExtend ) ) == ScAutoSumData &&
300*cdf0e10cSrcweir             nCol > nMinCol )
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         --nCol;
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir     if ( eSkip == ScAutoSumSum && nCol < nTmp )
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         return true;
307*cdf0e10cSrcweir     }
308*cdf0e10cSrcweir     return false;
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir //----------------------------------------------------------------------------
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir bool lcl_GetAutoSumForColumnRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     const ScAddress aStart = rRange.aStart;
316*cdf0e10cSrcweir     const ScAddress aEnd = rRange.aEnd;
317*cdf0e10cSrcweir     if ( aStart.Col() != aEnd.Col() )
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir         return false;
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     const SCTAB nTab = aEnd.Tab();
323*cdf0e10cSrcweir     const SCCOL nCol = aEnd.Col();
324*cdf0e10cSrcweir     SCROW nEndRow = aEnd.Row();
325*cdf0e10cSrcweir     SCROW nStartRow = nEndRow;
326*cdf0e10cSrcweir     SCCOLROW nExtend = 0;
327*cdf0e10cSrcweir     const ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nCol, nEndRow, nTab, DIR_TOP, nExtend /*out*/ );
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     if ( eSum == ScAutoSumSum )
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         bool bContinue = false;
332*cdf0e10cSrcweir         do
333*cdf0e10cSrcweir         {
334*cdf0e10cSrcweir             rRangeList.Append( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
335*cdf0e10cSrcweir             nEndRow = static_cast< SCROW >( nExtend );
336*cdf0e10cSrcweir             if ( ( bContinue = lcl_FindNextSumEntryInColumn( pDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, aStart.Row() ) ) == true )
337*cdf0e10cSrcweir             {
338*cdf0e10cSrcweir                 nStartRow = nEndRow;
339*cdf0e10cSrcweir             }
340*cdf0e10cSrcweir         } while ( bContinue );
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir     else
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         while ( nStartRow > aStart.Row() &&
345*cdf0e10cSrcweir                 lcl_IsAutoSumData( pDoc, nCol, nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ ) != ScAutoSumSum )
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             --nStartRow;
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir         rRangeList.Append( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     return true;
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir //----------------------------------------------------------------------------
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir bool lcl_GetAutoSumForRowRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     const ScAddress aStart = rRange.aStart;
360*cdf0e10cSrcweir     const ScAddress aEnd = rRange.aEnd;
361*cdf0e10cSrcweir     if ( aStart.Row() != aEnd.Row() )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         return false;
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir     const SCTAB nTab = aEnd.Tab();
367*cdf0e10cSrcweir     const SCROW nRow = aEnd.Row();
368*cdf0e10cSrcweir     SCCOL nEndCol = aEnd.Col();
369*cdf0e10cSrcweir     SCCOL nStartCol = nEndCol;
370*cdf0e10cSrcweir     SCCOLROW nExtend = 0;
371*cdf0e10cSrcweir     const ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nEndCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     if ( eSum == ScAutoSumSum )
374*cdf0e10cSrcweir     {
375*cdf0e10cSrcweir         bool bContinue = false;
376*cdf0e10cSrcweir         do
377*cdf0e10cSrcweir         {
378*cdf0e10cSrcweir             rRangeList.Append( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
379*cdf0e10cSrcweir             nEndCol = static_cast< SCCOL >( nExtend );
380*cdf0e10cSrcweir             if ( ( bContinue = lcl_FindNextSumEntryInRow( pDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, aStart.Col() ) ) == true )
381*cdf0e10cSrcweir             {
382*cdf0e10cSrcweir                 nStartCol = nEndCol;
383*cdf0e10cSrcweir             }
384*cdf0e10cSrcweir         } while ( bContinue );
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir     else
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         while ( nStartCol > aStart.Col() &&
389*cdf0e10cSrcweir                 lcl_IsAutoSumData( pDoc, nStartCol-1, nRow, nTab, DIR_LEFT, nExtend /*out*/ ) != ScAutoSumSum )
390*cdf0e10cSrcweir         {
391*cdf0e10cSrcweir             --nStartCol;
392*cdf0e10cSrcweir         }
393*cdf0e10cSrcweir         rRangeList.Append( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     return true;
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir //----------------------------------------------------------------------------
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir sal_Bool ScViewFunc::GetAutoSumArea( ScRangeList& rRangeList )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
404*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 	SCCOL nCol = GetViewData()->GetCurX();
407*cdf0e10cSrcweir 	SCROW nRow = GetViewData()->GetCurY();
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	SCCOL nStartCol = nCol;
410*cdf0e10cSrcweir 	SCROW nStartRow = nRow;
411*cdf0e10cSrcweir 	SCCOL nEndCol	 = nCol;
412*cdf0e10cSrcweir 	SCROW nEndRow	 = nRow;
413*cdf0e10cSrcweir 	SCCOL nSeekCol	 = nCol;
414*cdf0e10cSrcweir 	SCROW nSeekRow	 = nRow;
415*cdf0e10cSrcweir 	SCCOLROW nExtend;		// wird per Reference gueltig bei ScAutoSumSum
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	sal_Bool bCol = sal_False;
418*cdf0e10cSrcweir 	sal_Bool bRow = sal_False;
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	ScAutoSum eSum;
421*cdf0e10cSrcweir 	if ( nRow != 0
422*cdf0e10cSrcweir 			&& ((eSum = lcl_IsAutoSumData( pDoc, nCol, nRow-1, nTab,
423*cdf0e10cSrcweir 				DIR_TOP, nExtend /*out*/ )) == ScAutoSumData )
424*cdf0e10cSrcweir 			&& ((eSum = lcl_IsAutoSumData( pDoc, nCol, nRow-1, nTab,
425*cdf0e10cSrcweir 				DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
426*cdf0e10cSrcweir 		)
427*cdf0e10cSrcweir 	{
428*cdf0e10cSrcweir 		bRow = sal_True;
429*cdf0e10cSrcweir 		nSeekRow = nRow - 1;
430*cdf0e10cSrcweir 	}
431*cdf0e10cSrcweir 	else if ( nCol != 0 && (eSum = lcl_IsAutoSumData( pDoc, nCol-1, nRow, nTab,
432*cdf0e10cSrcweir 			DIR_LEFT, nExtend /*out*/ )) == ScAutoSumData )
433*cdf0e10cSrcweir 	{
434*cdf0e10cSrcweir 		bCol = sal_True;
435*cdf0e10cSrcweir 		nSeekCol = nCol - 1;
436*cdf0e10cSrcweir 	}
437*cdf0e10cSrcweir     else if ( (eSum = lcl_SeekAutoSumData( pDoc, nCol, nSeekRow, nTab, DIR_TOP, nExtend /*out*/ )) != ScAutoSumNone )
438*cdf0e10cSrcweir 		bRow = sal_True;
439*cdf0e10cSrcweir     else if (( eSum = lcl_SeekAutoSumData( pDoc, nSeekCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ )) != ScAutoSumNone )
440*cdf0e10cSrcweir 		bCol = sal_True;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	if ( bCol || bRow )
443*cdf0e10cSrcweir 	{
444*cdf0e10cSrcweir 		if ( bRow )
445*cdf0e10cSrcweir 		{
446*cdf0e10cSrcweir 			nStartRow = nSeekRow;		// nSeekRow evtl. per Reference angepasst
447*cdf0e10cSrcweir 			if ( eSum == ScAutoSumSum )
448*cdf0e10cSrcweir 				nEndRow = nStartRow;		// nur Summen summieren
449*cdf0e10cSrcweir 			else
450*cdf0e10cSrcweir 				nEndRow = nRow - 1;		// Datenbereich evtl. nach unten erweitern
451*cdf0e10cSrcweir 		}
452*cdf0e10cSrcweir 		else
453*cdf0e10cSrcweir 		{
454*cdf0e10cSrcweir 			nStartCol = nSeekCol;		// nSeekCol evtl. per Reference angepasst
455*cdf0e10cSrcweir 			if ( eSum == ScAutoSumSum )
456*cdf0e10cSrcweir 				nEndCol = nStartCol;		// nur Summen summieren
457*cdf0e10cSrcweir 			else
458*cdf0e10cSrcweir 				nEndCol = nCol - 1;		// Datenbereich evtl. nach rechts erweitern
459*cdf0e10cSrcweir 		}
460*cdf0e10cSrcweir 		sal_Bool bContinue = sal_False;
461*cdf0e10cSrcweir 		do
462*cdf0e10cSrcweir 		{
463*cdf0e10cSrcweir 			if ( eSum == ScAutoSumData )
464*cdf0e10cSrcweir 			{
465*cdf0e10cSrcweir 				if ( bRow )
466*cdf0e10cSrcweir 				{
467*cdf0e10cSrcweir 					while ( nStartRow != 0 && lcl_IsAutoSumData(	pDoc, nCol,
468*cdf0e10cSrcweir 							nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ ) == eSum )
469*cdf0e10cSrcweir 						--nStartRow;
470*cdf0e10cSrcweir 				}
471*cdf0e10cSrcweir 				else
472*cdf0e10cSrcweir 				{
473*cdf0e10cSrcweir 					while ( nStartCol != 0 && lcl_IsAutoSumData( pDoc, nStartCol-1,
474*cdf0e10cSrcweir 							nRow, nTab, DIR_LEFT, nExtend /*out*/ ) == eSum )
475*cdf0e10cSrcweir 						--nStartCol;
476*cdf0e10cSrcweir 				}
477*cdf0e10cSrcweir 			}
478*cdf0e10cSrcweir 			rRangeList.Append(
479*cdf0e10cSrcweir 				ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ) );
480*cdf0e10cSrcweir 			if ( eSum == ScAutoSumSum )
481*cdf0e10cSrcweir 			{
482*cdf0e10cSrcweir 				if ( bRow )
483*cdf0e10cSrcweir 				{
484*cdf0e10cSrcweir                     nEndRow = static_cast< SCROW >( nExtend );
485*cdf0e10cSrcweir                     if ( ( bContinue = lcl_FindNextSumEntryInColumn( pDoc, nCol, nEndRow /*inout*/, nTab, nExtend /*out*/, 0 ) ) == true )
486*cdf0e10cSrcweir                     {
487*cdf0e10cSrcweir                         nStartRow = nEndRow;
488*cdf0e10cSrcweir                     }
489*cdf0e10cSrcweir 				}
490*cdf0e10cSrcweir 				else
491*cdf0e10cSrcweir 				{
492*cdf0e10cSrcweir                     nEndCol = static_cast< SCCOL >( nExtend );
493*cdf0e10cSrcweir                     if ( ( bContinue = lcl_FindNextSumEntryInRow( pDoc, nEndCol /*inout*/, nRow, nTab, nExtend /*out*/, 0 ) ) == true )
494*cdf0e10cSrcweir                     {
495*cdf0e10cSrcweir                         nStartCol = nEndCol;
496*cdf0e10cSrcweir                     }
497*cdf0e10cSrcweir 				}
498*cdf0e10cSrcweir 			}
499*cdf0e10cSrcweir 		} while ( bContinue );
500*cdf0e10cSrcweir 		return sal_True;
501*cdf0e10cSrcweir 	}
502*cdf0e10cSrcweir 	return sal_False;
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir //----------------------------------------------------------------------------
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, sal_Bool bSubTotal)		// Block mit Summen fuellen
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir     String aFormula = GetAutoSumFormula( rRangeList, bSubTotal );
510*cdf0e10cSrcweir 	EnterBlock( aFormula, NULL );
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir //----------------------------------------------------------------------------
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor, bool bContinue )
516*cdf0e10cSrcweir {
517*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
518*cdf0e10cSrcweir     const SCTAB nTab = rRange.aStart.Tab();
519*cdf0e10cSrcweir     SCCOL nStartCol = rRange.aStart.Col();
520*cdf0e10cSrcweir     SCROW nStartRow = rRange.aStart.Row();
521*cdf0e10cSrcweir     const SCCOL nEndCol = rRange.aEnd.Col();
522*cdf0e10cSrcweir     const SCROW nEndRow = rRange.aEnd.Row();
523*cdf0e10cSrcweir     SCCOLROW nExtend = 0; // out parameter for lcl_IsAutoSumData
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir     // ignore rows at the top of the given range which don't contain autosum data
526*cdf0e10cSrcweir     bool bRowData = false;
527*cdf0e10cSrcweir     for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
528*cdf0e10cSrcweir     {
529*cdf0e10cSrcweir         for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
530*cdf0e10cSrcweir         {
531*cdf0e10cSrcweir             if ( lcl_IsAutoSumData( pDoc, nCol, nRow, nTab, DIR_TOP, nExtend ) != ScAutoSumNone )
532*cdf0e10cSrcweir             {
533*cdf0e10cSrcweir                 bRowData = true;
534*cdf0e10cSrcweir                 break;
535*cdf0e10cSrcweir             }
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir         if ( bRowData )
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             nStartRow = nRow;
540*cdf0e10cSrcweir             break;
541*cdf0e10cSrcweir         }
542*cdf0e10cSrcweir     }
543*cdf0e10cSrcweir     if ( !bRowData )
544*cdf0e10cSrcweir     {
545*cdf0e10cSrcweir         return false;
546*cdf0e10cSrcweir     }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     // ignore columns at the left of the given range which don't contain autosum data
549*cdf0e10cSrcweir     bool bColData = false;
550*cdf0e10cSrcweir     for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
551*cdf0e10cSrcweir     {
552*cdf0e10cSrcweir         for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
553*cdf0e10cSrcweir         {
554*cdf0e10cSrcweir             if ( lcl_IsAutoSumData( pDoc, nCol, nRow, nTab, DIR_LEFT, nExtend ) != ScAutoSumNone )
555*cdf0e10cSrcweir             {
556*cdf0e10cSrcweir                 bColData = true;
557*cdf0e10cSrcweir                 break;
558*cdf0e10cSrcweir             }
559*cdf0e10cSrcweir         }
560*cdf0e10cSrcweir         if ( bColData )
561*cdf0e10cSrcweir         {
562*cdf0e10cSrcweir             nStartCol = nCol;
563*cdf0e10cSrcweir             break;
564*cdf0e10cSrcweir         }
565*cdf0e10cSrcweir     }
566*cdf0e10cSrcweir     if ( !bColData )
567*cdf0e10cSrcweir     {
568*cdf0e10cSrcweir         return false;
569*cdf0e10cSrcweir     }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     const bool bEndRowEmpty = pDoc->IsBlockEmpty( nTab, nStartCol, nEndRow, nEndCol, nEndRow );
572*cdf0e10cSrcweir     const bool bEndColEmpty = pDoc->IsBlockEmpty( nTab, nEndCol, nStartRow, nEndCol, nEndRow );
573*cdf0e10cSrcweir     bool bRow = ( ( nStartRow != nEndRow ) && ( bEndRowEmpty || ( !bEndRowEmpty && !bEndColEmpty ) ) );
574*cdf0e10cSrcweir     bool bCol = ( ( nStartCol != nEndCol ) && ( bEndColEmpty || nStartRow == nEndRow ) );
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir     // find an empty row for entering the result
577*cdf0e10cSrcweir     SCROW nInsRow = nEndRow;
578*cdf0e10cSrcweir     if ( bRow && !bEndRowEmpty )
579*cdf0e10cSrcweir     {
580*cdf0e10cSrcweir         if ( nInsRow < MAXROW )
581*cdf0e10cSrcweir         {
582*cdf0e10cSrcweir             ++nInsRow;
583*cdf0e10cSrcweir             while ( !pDoc->IsBlockEmpty( nTab, nStartCol, nInsRow, nEndCol, nInsRow ) )
584*cdf0e10cSrcweir             {
585*cdf0e10cSrcweir                 if ( nInsRow < MAXROW )
586*cdf0e10cSrcweir                 {
587*cdf0e10cSrcweir                     ++nInsRow;
588*cdf0e10cSrcweir                 }
589*cdf0e10cSrcweir                 else
590*cdf0e10cSrcweir                 {
591*cdf0e10cSrcweir                     bRow = false;
592*cdf0e10cSrcweir                     break;
593*cdf0e10cSrcweir                 }
594*cdf0e10cSrcweir             }
595*cdf0e10cSrcweir         }
596*cdf0e10cSrcweir         else
597*cdf0e10cSrcweir         {
598*cdf0e10cSrcweir             bRow = false;
599*cdf0e10cSrcweir         }
600*cdf0e10cSrcweir     }
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir     // find an empty column for entering the result
603*cdf0e10cSrcweir     SCCOL nInsCol = nEndCol;
604*cdf0e10cSrcweir     if ( bCol && !bEndColEmpty )
605*cdf0e10cSrcweir     {
606*cdf0e10cSrcweir         if ( nInsCol < MAXCOL )
607*cdf0e10cSrcweir         {
608*cdf0e10cSrcweir             ++nInsCol;
609*cdf0e10cSrcweir             while ( !pDoc->IsBlockEmpty( nTab, nInsCol, nStartRow, nInsCol, nEndRow ) )
610*cdf0e10cSrcweir             {
611*cdf0e10cSrcweir                 if ( nInsCol < MAXCOL )
612*cdf0e10cSrcweir                 {
613*cdf0e10cSrcweir                     ++nInsCol;
614*cdf0e10cSrcweir                 }
615*cdf0e10cSrcweir                 else
616*cdf0e10cSrcweir                 {
617*cdf0e10cSrcweir                     bCol = false;
618*cdf0e10cSrcweir                     break;
619*cdf0e10cSrcweir                 }
620*cdf0e10cSrcweir             }
621*cdf0e10cSrcweir         }
622*cdf0e10cSrcweir         else
623*cdf0e10cSrcweir         {
624*cdf0e10cSrcweir             bCol = false;
625*cdf0e10cSrcweir         }
626*cdf0e10cSrcweir     }
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir     if ( !bRow && !bCol )
629*cdf0e10cSrcweir     {
630*cdf0e10cSrcweir         return false;
631*cdf0e10cSrcweir     }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir     SCCOL nMarkEndCol = nEndCol;
634*cdf0e10cSrcweir     SCROW nMarkEndRow = nEndRow;
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir     if ( bRow )
637*cdf0e10cSrcweir     {
638*cdf0e10cSrcweir         // calculate the row sums for all columns of the given range
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir         SCROW nSumEndRow = nEndRow;
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir         if ( bEndRowEmpty )
643*cdf0e10cSrcweir         {
644*cdf0e10cSrcweir             // the last row of the given range is empty;
645*cdf0e10cSrcweir             // don't take into account for calculating the autosum
646*cdf0e10cSrcweir             --nSumEndRow;
647*cdf0e10cSrcweir         }
648*cdf0e10cSrcweir         else
649*cdf0e10cSrcweir         {
650*cdf0e10cSrcweir             // increase mark range
651*cdf0e10cSrcweir             ++nMarkEndRow;
652*cdf0e10cSrcweir         }
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir         for ( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
655*cdf0e10cSrcweir         {
656*cdf0e10cSrcweir             if ( !pDoc->IsBlockEmpty( nTab, nCol, nStartRow, nCol, nSumEndRow ) )
657*cdf0e10cSrcweir             {
658*cdf0e10cSrcweir                 ScRangeList aRangeList;
659*cdf0e10cSrcweir                 const ScRange aRange( nCol, nStartRow, nTab, nCol, nSumEndRow, nTab );
660*cdf0e10cSrcweir                 if ( lcl_GetAutoSumForColumnRange( pDoc, aRangeList, aRange ) )
661*cdf0e10cSrcweir                 {
662*cdf0e10cSrcweir                     const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal );
663*cdf0e10cSrcweir                     EnterData( nCol, nInsRow, nTab, aFormula );
664*cdf0e10cSrcweir                 }
665*cdf0e10cSrcweir             }
666*cdf0e10cSrcweir         }
667*cdf0e10cSrcweir     }
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     if ( bCol )
670*cdf0e10cSrcweir     {
671*cdf0e10cSrcweir         // calculate the column sums for all rows of the given range
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir         SCCOL nSumEndCol = nEndCol;
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir         if ( bEndColEmpty )
676*cdf0e10cSrcweir         {
677*cdf0e10cSrcweir             // the last column of the given range is empty;
678*cdf0e10cSrcweir             // don't take into account for calculating the autosum
679*cdf0e10cSrcweir             --nSumEndCol;
680*cdf0e10cSrcweir         }
681*cdf0e10cSrcweir         else
682*cdf0e10cSrcweir         {
683*cdf0e10cSrcweir             // increase mark range
684*cdf0e10cSrcweir             ++nMarkEndCol;
685*cdf0e10cSrcweir         }
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir         for ( SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow )
688*cdf0e10cSrcweir         {
689*cdf0e10cSrcweir             if ( !pDoc->IsBlockEmpty( nTab, nStartCol, nRow, nSumEndCol, nRow ) )
690*cdf0e10cSrcweir             {
691*cdf0e10cSrcweir                 ScRangeList aRangeList;
692*cdf0e10cSrcweir                 const ScRange aRange( nStartCol, nRow, nTab, nSumEndCol, nRow, nTab );
693*cdf0e10cSrcweir                 if ( lcl_GetAutoSumForRowRange( pDoc, aRangeList, aRange ) )
694*cdf0e10cSrcweir                 {
695*cdf0e10cSrcweir                     const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal );
696*cdf0e10cSrcweir                     EnterData( nInsCol, nRow, nTab, aFormula );
697*cdf0e10cSrcweir                 }
698*cdf0e10cSrcweir             }
699*cdf0e10cSrcweir         }
700*cdf0e10cSrcweir     }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     // set new mark range and cursor position
703*cdf0e10cSrcweir     const ScRange aMarkRange( nStartCol, nStartRow, nTab, nMarkEndCol, nMarkEndRow, nTab );
704*cdf0e10cSrcweir     MarkRange( aMarkRange, sal_False, bContinue );
705*cdf0e10cSrcweir     if ( bSetCursor )
706*cdf0e10cSrcweir     {
707*cdf0e10cSrcweir         SetCursor( nMarkEndCol, nMarkEndRow );
708*cdf0e10cSrcweir     }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir     return true;
711*cdf0e10cSrcweir }
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir //----------------------------------------------------------------------------
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir String ScViewFunc::GetAutoSumFormula( const ScRangeList& rRangeList, bool bSubTotal )
716*cdf0e10cSrcweir {
717*cdf0e10cSrcweir     String aFormula = '=';
718*cdf0e10cSrcweir     ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
719*cdf0e10cSrcweir     const ScFuncDesc* pDesc = NULL;
720*cdf0e10cSrcweir     if ( bSubTotal )
721*cdf0e10cSrcweir     {
722*cdf0e10cSrcweir         pDesc = pFuncMgr->Get( SC_OPCODE_SUB_TOTAL );
723*cdf0e10cSrcweir     }
724*cdf0e10cSrcweir     else
725*cdf0e10cSrcweir     {
726*cdf0e10cSrcweir         pDesc = pFuncMgr->Get( SC_OPCODE_SUM );
727*cdf0e10cSrcweir     }
728*cdf0e10cSrcweir     if ( pDesc && pDesc->pFuncName )
729*cdf0e10cSrcweir     {
730*cdf0e10cSrcweir         aFormula += *pDesc->pFuncName;
731*cdf0e10cSrcweir         if ( bSubTotal )
732*cdf0e10cSrcweir         {
733*cdf0e10cSrcweir             aFormula.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "(9;" ) );
734*cdf0e10cSrcweir         }
735*cdf0e10cSrcweir         else
736*cdf0e10cSrcweir         {
737*cdf0e10cSrcweir             aFormula += '(';
738*cdf0e10cSrcweir         }
739*cdf0e10cSrcweir         ScDocument* pDoc = GetViewData()->GetDocument();
740*cdf0e10cSrcweir         String aRef;
741*cdf0e10cSrcweir         rRangeList.Format( aRef, SCA_VALID, pDoc );
742*cdf0e10cSrcweir         aFormula += aRef;
743*cdf0e10cSrcweir         aFormula += ')';
744*cdf0e10cSrcweir     }
745*cdf0e10cSrcweir     return aFormula;
746*cdf0e10cSrcweir }
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir //----------------------------------------------------------------------------
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir void ScViewFunc::EnterBlock( const String& rString, const EditTextObject* pData )
751*cdf0e10cSrcweir {
752*cdf0e10cSrcweir 	//	Mehrfachselektion vorher abfragen...
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir 	SCCOL nCol = GetViewData()->GetCurX();
755*cdf0e10cSrcweir 	SCROW nRow = GetViewData()->GetCurY();
756*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
757*cdf0e10cSrcweir 	ScMarkData& rMark = GetViewData()->GetMarkData();
758*cdf0e10cSrcweir 	if ( rMark.IsMultiMarked() )
759*cdf0e10cSrcweir 	{
760*cdf0e10cSrcweir 		rMark.MarkToSimple();
761*cdf0e10cSrcweir 		if ( rMark.IsMultiMarked() )
762*cdf0e10cSrcweir 		{		// "Einfuegen auf Mehrfachselektion nicht moeglich"
763*cdf0e10cSrcweir 			ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir 			//	insert into single cell
766*cdf0e10cSrcweir 			if ( pData )
767*cdf0e10cSrcweir 				EnterData( nCol, nRow, nTab, pData );
768*cdf0e10cSrcweir 			else
769*cdf0e10cSrcweir 				EnterData( nCol, nRow, nTab, rString );
770*cdf0e10cSrcweir 			return;
771*cdf0e10cSrcweir 		}
772*cdf0e10cSrcweir 	}
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
775*cdf0e10cSrcweir 	String aNewStr = rString;
776*cdf0e10cSrcweir 	if ( pData )
777*cdf0e10cSrcweir 	{
778*cdf0e10cSrcweir 		const ScPatternAttr* pOldPattern = pDoc->GetPattern( nCol, nRow, nTab );
779*cdf0e10cSrcweir 		ScTabEditEngine aEngine( *pOldPattern, pDoc->GetEnginePool() );
780*cdf0e10cSrcweir 		aEngine.SetText(*pData);
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 		ScEditAttrTester aTester( &aEngine );
783*cdf0e10cSrcweir 		if (!aTester.NeedsObject())
784*cdf0e10cSrcweir 		{
785*cdf0e10cSrcweir 			aNewStr = aEngine.GetText();
786*cdf0e10cSrcweir 			pData = NULL;
787*cdf0e10cSrcweir 		}
788*cdf0e10cSrcweir 	}
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir 	//	Einfuegen per PasteFromClip
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir 	WaitObject aWait( GetFrameWin() );
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 	ScAddress aPos( nCol, nRow, nTab );
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 	ScDocument* pInsDoc = new ScDocument( SCDOCMODE_CLIP );
797*cdf0e10cSrcweir 	pInsDoc->ResetClip( pDoc, nTab );
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 	if (aNewStr.GetChar(0) == '=')						// Formel ?
800*cdf0e10cSrcweir 	{
801*cdf0e10cSrcweir 		//	SetString geht nicht, weil in Clipboard-Dokumenten nicht kompiliert wird!
802*cdf0e10cSrcweir 		ScFormulaCell* pFCell = new ScFormulaCell( pDoc, aPos, aNewStr );
803*cdf0e10cSrcweir 		pInsDoc->PutCell( nCol, nRow, nTab, pFCell );
804*cdf0e10cSrcweir 	}
805*cdf0e10cSrcweir 	else if ( pData )
806*cdf0e10cSrcweir 		pInsDoc->PutCell( nCol, nRow, nTab, new ScEditCell( pData, pDoc, NULL ) );
807*cdf0e10cSrcweir 	else
808*cdf0e10cSrcweir 		pInsDoc->SetString( nCol, nRow, nTab, aNewStr );
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir 	pInsDoc->SetClipArea( ScRange(aPos) );
811*cdf0e10cSrcweir 	// auf Block einfuegen, mit Undo etc.
812*cdf0e10cSrcweir 	if ( PasteFromClip( IDF_CONTENTS, pInsDoc, PASTE_NOFUNC, sal_False, sal_False,
813*cdf0e10cSrcweir 			sal_False, INS_NONE, IDF_ATTRIB ) )
814*cdf0e10cSrcweir 	{
815*cdf0e10cSrcweir 		const SfxUInt32Item* pItem = (SfxUInt32Item*) pInsDoc->GetAttr(
816*cdf0e10cSrcweir 			nCol, nRow, nTab, ATTR_VALUE_FORMAT );
817*cdf0e10cSrcweir 		if ( pItem )
818*cdf0e10cSrcweir 		{	// Numberformat setzen wenn inkompatibel
819*cdf0e10cSrcweir 			// MarkData wurde bereits in PasteFromClip MarkToSimple'ed
820*cdf0e10cSrcweir 			ScRange aRange;
821*cdf0e10cSrcweir 			rMark.GetMarkArea( aRange );
822*cdf0e10cSrcweir 			ScPatternAttr* pPattern = new ScPatternAttr( pDoc->GetPool() );
823*cdf0e10cSrcweir 			pPattern->GetItemSet().Put( *pItem );
824*cdf0e10cSrcweir 			short nNewType = pDoc->GetFormatTable()->GetType( pItem->GetValue() );
825*cdf0e10cSrcweir 			pDoc->ApplyPatternIfNumberformatIncompatible( aRange, rMark,
826*cdf0e10cSrcweir 				*pPattern, nNewType );
827*cdf0e10cSrcweir 			delete pPattern;
828*cdf0e10cSrcweir 		}
829*cdf0e10cSrcweir 	}
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir 	delete pInsDoc;
832*cdf0e10cSrcweir }
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir //----------------------------------------------------------------------------
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir //UNUSED2008-05  void ScViewFunc::PaintWidthHeight( sal_Bool bColumns, SCCOLROW nStart, SCCOLROW nEnd )
838*cdf0e10cSrcweir //UNUSED2008-05  {
839*cdf0e10cSrcweir //UNUSED2008-05      SCTAB nTab = GetViewData()->GetTabNo();
840*cdf0e10cSrcweir //UNUSED2008-05      ScDocument* pDoc = GetViewData()->GetDocument();
841*cdf0e10cSrcweir //UNUSED2008-05
842*cdf0e10cSrcweir //UNUSED2008-05      sal_uInt16 nParts = PAINT_GRID;
843*cdf0e10cSrcweir //UNUSED2008-05      SCCOL nStartCol = 0;
844*cdf0e10cSrcweir //UNUSED2008-05      SCROW nStartRow = 0;
845*cdf0e10cSrcweir //UNUSED2008-05      SCCOL nEndCol = MAXCOL;         // fuer Test auf Merge
846*cdf0e10cSrcweir //UNUSED2008-05      SCROW nEndRow = MAXROW;
847*cdf0e10cSrcweir //UNUSED2008-05      if ( bColumns )
848*cdf0e10cSrcweir //UNUSED2008-05      {
849*cdf0e10cSrcweir //UNUSED2008-05          nParts |= PAINT_TOP;
850*cdf0e10cSrcweir //UNUSED2008-05          nStartCol = static_cast<SCCOL>(nStart);
851*cdf0e10cSrcweir //UNUSED2008-05          nEndCol = static_cast<SCCOL>(nEnd);
852*cdf0e10cSrcweir //UNUSED2008-05      }
853*cdf0e10cSrcweir //UNUSED2008-05      else
854*cdf0e10cSrcweir //UNUSED2008-05      {
855*cdf0e10cSrcweir //UNUSED2008-05          nParts |= PAINT_LEFT;
856*cdf0e10cSrcweir //UNUSED2008-05          nStartRow = nStart;
857*cdf0e10cSrcweir //UNUSED2008-05          nEndRow = nEnd;
858*cdf0e10cSrcweir //UNUSED2008-05      }
859*cdf0e10cSrcweir //UNUSED2008-05      if (pDoc->HasAttrib( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab,
860*cdf0e10cSrcweir //UNUSED2008-05                           HASATTR_MERGED | HASATTR_OVERLAPPED ))
861*cdf0e10cSrcweir //UNUSED2008-05      {
862*cdf0e10cSrcweir //UNUSED2008-05          nStartCol = 0;
863*cdf0e10cSrcweir //UNUSED2008-05          nStartRow = 0;
864*cdf0e10cSrcweir //UNUSED2008-05      }
865*cdf0e10cSrcweir //UNUSED2008-05      GetViewData()->GetDocShell()->PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts );
866*cdf0e10cSrcweir //UNUSED2008-05  }
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir //----------------------------------------------------------------------------
870*cdf0e10cSrcweir //	manueller Seitenumbruch
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir void ScViewFunc::InsertPageBreak( sal_Bool bColumn, sal_Bool bRecord, const ScAddress* pPos,
873*cdf0e10cSrcweir 									sal_Bool bSetModified )
874*cdf0e10cSrcweir {
875*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
876*cdf0e10cSrcweir 	ScAddress aCursor;
877*cdf0e10cSrcweir 	if (pPos)
878*cdf0e10cSrcweir 		aCursor = *pPos;
879*cdf0e10cSrcweir 	else
880*cdf0e10cSrcweir 		aCursor = ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), nTab );
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 	sal_Bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().
883*cdf0e10cSrcweir 						InsertPageBreak( bColumn, aCursor, bRecord, bSetModified, sal_False );
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 	if ( bSuccess && bSetModified )
886*cdf0e10cSrcweir 		UpdatePageBreakData( sal_True );	// fuer PageBreak-Modus
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir //----------------------------------------------------------------------------
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir void ScViewFunc::DeletePageBreak( sal_Bool bColumn, sal_Bool bRecord, const ScAddress* pPos,
893*cdf0e10cSrcweir 									sal_Bool bSetModified )
894*cdf0e10cSrcweir {
895*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
896*cdf0e10cSrcweir 	ScAddress aCursor;
897*cdf0e10cSrcweir 	if (pPos)
898*cdf0e10cSrcweir 		aCursor = *pPos;
899*cdf0e10cSrcweir 	else
900*cdf0e10cSrcweir 		aCursor = ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), nTab );
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 	sal_Bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().
903*cdf0e10cSrcweir 						RemovePageBreak( bColumn, aCursor, bRecord, bSetModified, sal_False );
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir 	if ( bSuccess && bSetModified )
906*cdf0e10cSrcweir 		UpdatePageBreakData( sal_True );	// fuer PageBreak-Modus
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir //----------------------------------------------------------------------------
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir void ScViewFunc::RemoveManualBreaks()
912*cdf0e10cSrcweir {
913*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
914*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
915*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
916*cdf0e10cSrcweir 	sal_Bool bUndo(pDoc->IsUndoEnabled());
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir 	if (bUndo)
919*cdf0e10cSrcweir 	{
920*cdf0e10cSrcweir 		ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
921*cdf0e10cSrcweir 		pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
922*cdf0e10cSrcweir 		pDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, sal_False, pUndoDoc );
923*cdf0e10cSrcweir 		pDocSh->GetUndoManager()->AddUndoAction(
924*cdf0e10cSrcweir 								new ScUndoRemoveBreaks( pDocSh, nTab, pUndoDoc ) );
925*cdf0e10cSrcweir 	}
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 	pDoc->RemoveManualBreaks(nTab);
928*cdf0e10cSrcweir 	pDoc->UpdatePageBreaks(nTab);
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir 	UpdatePageBreakData( sal_True );
931*cdf0e10cSrcweir 	pDocSh->SetDocumentModified();
932*cdf0e10cSrcweir 	pDocSh->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
933*cdf0e10cSrcweir }
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir //----------------------------------------------------------------------------
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir void ScViewFunc::SetPrintZoom(sal_uInt16 nScale, sal_uInt16 nPages)
938*cdf0e10cSrcweir {
939*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
940*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
941*cdf0e10cSrcweir 	pDocSh->SetPrintZoom( nTab, nScale, nPages );
942*cdf0e10cSrcweir }
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir void ScViewFunc::AdjustPrintZoom()
945*cdf0e10cSrcweir {
946*cdf0e10cSrcweir 	ScRange aRange;
947*cdf0e10cSrcweir 	if ( GetViewData()->GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
948*cdf0e10cSrcweir 		GetViewData()->GetMarkData().GetMultiMarkArea( aRange );
949*cdf0e10cSrcweir 	GetViewData()->GetDocShell()->AdjustPrintZoom( aRange );
950*cdf0e10cSrcweir }
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir //----------------------------------------------------------------------------
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir void ScViewFunc::SetPrintRanges( sal_Bool bEntireSheet, const String* pPrint,
955*cdf0e10cSrcweir 								const String* pRepCol, const String* pRepRow,
956*cdf0e10cSrcweir 								sal_Bool bAddPrint )
957*cdf0e10cSrcweir {
958*cdf0e10cSrcweir 	//	on all selected tables
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
961*cdf0e10cSrcweir 	ScDocument* pDoc	= pDocSh->GetDocument();
962*cdf0e10cSrcweir 	SCTAB nTabCount	= pDoc->GetTableCount();
963*cdf0e10cSrcweir 	ScMarkData& rMark	= GetViewData()->GetMarkData();
964*cdf0e10cSrcweir 	SCTAB nTab;
965*cdf0e10cSrcweir 	sal_Bool bUndo (pDoc->IsUndoEnabled());
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir 	ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir     ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir 	for (nTab=0; nTab<nTabCount; nTab++)
972*cdf0e10cSrcweir 		if (rMark.GetTableSelect(nTab))
973*cdf0e10cSrcweir 		{
974*cdf0e10cSrcweir 			ScRange aRange( 0,0,nTab );
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir 			//	print ranges
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir             if( !bAddPrint )
979*cdf0e10cSrcweir                 pDoc->ClearPrintRanges( nTab );
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir             if( bEntireSheet )
982*cdf0e10cSrcweir             {
983*cdf0e10cSrcweir                 pDoc->SetPrintEntireSheet( nTab );
984*cdf0e10cSrcweir             }
985*cdf0e10cSrcweir             else if ( pPrint )
986*cdf0e10cSrcweir 			{
987*cdf0e10cSrcweir                 if ( pPrint->Len() )
988*cdf0e10cSrcweir 				{
989*cdf0e10cSrcweir                     const sal_Unicode sep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
990*cdf0e10cSrcweir                     sal_uInt16 nTCount = pPrint->GetTokenCount(sep);
991*cdf0e10cSrcweir 					for (sal_uInt16 i=0; i<nTCount; i++)
992*cdf0e10cSrcweir 					{
993*cdf0e10cSrcweir 						String aToken = pPrint->GetToken(i, sep);
994*cdf0e10cSrcweir 						if ( aRange.ParseAny( aToken, pDoc, aDetails ) & SCA_VALID )
995*cdf0e10cSrcweir                             pDoc->AddPrintRange( nTab, aRange );
996*cdf0e10cSrcweir 					}
997*cdf0e10cSrcweir 				}
998*cdf0e10cSrcweir 			}
999*cdf0e10cSrcweir             else    // NULL = use selection (print range is always set), use empty string to delete all ranges
1000*cdf0e10cSrcweir 			{
1001*cdf0e10cSrcweir 				if ( GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
1002*cdf0e10cSrcweir 				{
1003*cdf0e10cSrcweir                     pDoc->AddPrintRange( nTab, aRange );
1004*cdf0e10cSrcweir 				}
1005*cdf0e10cSrcweir 				else if ( rMark.IsMultiMarked() )
1006*cdf0e10cSrcweir 				{
1007*cdf0e10cSrcweir 					rMark.MarkToMulti();
1008*cdf0e10cSrcweir 					ScRangeListRef aList( new ScRangeList );
1009*cdf0e10cSrcweir 					rMark.FillRangeListWithMarks( aList, sal_False );
1010*cdf0e10cSrcweir 					sal_uInt16 nCnt = (sal_uInt16) aList->Count();
1011*cdf0e10cSrcweir 					if ( nCnt )
1012*cdf0e10cSrcweir 					{
1013*cdf0e10cSrcweir 						ScRangePtr pR;
1014*cdf0e10cSrcweir 						sal_uInt16 i;
1015*cdf0e10cSrcweir 						for ( pR = aList->First(), i=0; i < nCnt;
1016*cdf0e10cSrcweir 							  pR = aList->Next(), i++ )
1017*cdf0e10cSrcweir 						{
1018*cdf0e10cSrcweir                             pDoc->AddPrintRange( nTab, *pR );
1019*cdf0e10cSrcweir 						}
1020*cdf0e10cSrcweir 					}
1021*cdf0e10cSrcweir 				}
1022*cdf0e10cSrcweir 			}
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir 			//	repeat columns
1025*cdf0e10cSrcweir 
1026*cdf0e10cSrcweir 			if ( pRepCol )
1027*cdf0e10cSrcweir 			{
1028*cdf0e10cSrcweir 				if ( !pRepCol->Len() )
1029*cdf0e10cSrcweir 					pDoc->SetRepeatColRange( nTab, NULL );
1030*cdf0e10cSrcweir 				else
1031*cdf0e10cSrcweir 					if ( aRange.ParseAny( *pRepCol, pDoc, aDetails ) & SCA_VALID )
1032*cdf0e10cSrcweir 						pDoc->SetRepeatColRange( nTab, &aRange );
1033*cdf0e10cSrcweir 			}
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir 			//	repeat rows
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir 			if ( pRepRow )
1038*cdf0e10cSrcweir 			{
1039*cdf0e10cSrcweir 				if ( !pRepRow->Len() )
1040*cdf0e10cSrcweir 					pDoc->SetRepeatRowRange( nTab, NULL );
1041*cdf0e10cSrcweir 				else
1042*cdf0e10cSrcweir 					if ( aRange.ParseAny( *pRepRow, pDoc, aDetails ) & SCA_VALID )
1043*cdf0e10cSrcweir 						pDoc->SetRepeatRowRange( nTab, &aRange );
1044*cdf0e10cSrcweir 			}
1045*cdf0e10cSrcweir 		}
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir 	//	undo (for all tables)
1048*cdf0e10cSrcweir 	if (bUndo)
1049*cdf0e10cSrcweir 	{
1050*cdf0e10cSrcweir 		SCTAB nCurTab = GetViewData()->GetTabNo();
1051*cdf0e10cSrcweir 		ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
1052*cdf0e10cSrcweir 		pDocSh->GetUndoManager()->AddUndoAction(
1053*cdf0e10cSrcweir 					new ScUndoPrintRange( pDocSh, nCurTab, pOldRanges, pNewRanges ) );
1054*cdf0e10cSrcweir 	}
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir 	//	update page breaks
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir 	for (nTab=0; nTab<nTabCount; nTab++)
1059*cdf0e10cSrcweir 		if (rMark.GetTableSelect(nTab))
1060*cdf0e10cSrcweir 			ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages();
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir 	SfxBindings& rBindings = GetViewData()->GetBindings();
1063*cdf0e10cSrcweir 	rBindings.Invalidate( SID_DELETE_PRINTAREA );
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir 	pDocSh->SetDocumentModified();
1066*cdf0e10cSrcweir }
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir //----------------------------------------------------------------------------
1069*cdf0e10cSrcweir //	Zellen zusammenfassen
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir sal_Bool ScViewFunc::TestMergeCells()			// Vorab-Test (fuer Menue)
1072*cdf0e10cSrcweir {
1073*cdf0e10cSrcweir 	//	simple test: sal_True if there's a selection but no multi selection and not filtered
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir 	const ScMarkData& rMark = GetViewData()->GetMarkData();
1076*cdf0e10cSrcweir 	if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1077*cdf0e10cSrcweir 	{
1078*cdf0e10cSrcweir         ScRange aDummy;
1079*cdf0e10cSrcweir         return GetViewData()->GetSimpleArea( aDummy) == SC_MARK_SIMPLE;
1080*cdf0e10cSrcweir 	}
1081*cdf0e10cSrcweir 	else
1082*cdf0e10cSrcweir 		return sal_False;
1083*cdf0e10cSrcweir }
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir //----------------------------------------------------------------------------
1087*cdf0e10cSrcweir 
1088*cdf0e10cSrcweir sal_Bool ScViewFunc::MergeCells( sal_Bool bApi, sal_Bool& rDoContents, sal_Bool bRecord )
1089*cdf0e10cSrcweir {
1090*cdf0e10cSrcweir 	//	Editable- und Verschachtelungs-Abfrage muss vorneweg sein (auch in DocFunc),
1091*cdf0e10cSrcweir 	//	damit dann nicht die Inhalte-QueryBox kommt
1092*cdf0e10cSrcweir 	ScEditableTester aTester( this );
1093*cdf0e10cSrcweir 	if (!aTester.IsEditable())
1094*cdf0e10cSrcweir 	{
1095*cdf0e10cSrcweir 		ErrorMessage(aTester.GetMessageId());
1096*cdf0e10cSrcweir 		return sal_False;
1097*cdf0e10cSrcweir 	}
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir 	ScMarkData& rMark = GetViewData()->GetMarkData();
1100*cdf0e10cSrcweir 	rMark.MarkToSimple();
1101*cdf0e10cSrcweir 	if (!rMark.IsMarked())
1102*cdf0e10cSrcweir 	{
1103*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1104*cdf0e10cSrcweir 		return sal_False;
1105*cdf0e10cSrcweir 	}
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1108*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
1109*cdf0e10cSrcweir 
1110*cdf0e10cSrcweir 	ScRange aMarkRange;
1111*cdf0e10cSrcweir 	rMark.GetMarkArea( aMarkRange );
1112*cdf0e10cSrcweir 	SCCOL nStartCol = aMarkRange.aStart.Col();
1113*cdf0e10cSrcweir 	SCROW nStartRow = aMarkRange.aStart.Row();
1114*cdf0e10cSrcweir 	SCTAB nStartTab = aMarkRange.aStart.Tab();
1115*cdf0e10cSrcweir 	SCCOL nEndCol = aMarkRange.aEnd.Col();
1116*cdf0e10cSrcweir 	SCROW nEndRow = aMarkRange.aEnd.Row();
1117*cdf0e10cSrcweir 	SCTAB nEndTab = aMarkRange.aEnd.Tab();
1118*cdf0e10cSrcweir 	if ( nStartCol == nEndCol && nStartRow == nEndRow )
1119*cdf0e10cSrcweir 	{
1120*cdf0e10cSrcweir 		// nichts zu tun
1121*cdf0e10cSrcweir 		return sal_True;
1122*cdf0e10cSrcweir 	}
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir 	if ( pDoc->HasAttrib( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1125*cdf0e10cSrcweir 							HASATTR_MERGED | HASATTR_OVERLAPPED ) )
1126*cdf0e10cSrcweir 	{		// "Zusammenfassen nicht verschachteln !"
1127*cdf0e10cSrcweir 		ErrorMessage(STR_MSSG_MERGECELLS_0);
1128*cdf0e10cSrcweir 		return sal_False;
1129*cdf0e10cSrcweir 	}
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir 	sal_Bool bOk = sal_True;
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir 	if ( !pDoc->IsBlockEmpty( nStartTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) ||
1134*cdf0e10cSrcweir 		 !pDoc->IsBlockEmpty( nStartTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) )
1135*cdf0e10cSrcweir 	{
1136*cdf0e10cSrcweir 		if (!bApi)
1137*cdf0e10cSrcweir 		{
1138*cdf0e10cSrcweir 			MessBox aBox( GetViewData()->GetDialogParent(),
1139*cdf0e10cSrcweir 							WinBits(WB_YES_NO_CANCEL | WB_DEF_NO),
1140*cdf0e10cSrcweir 							ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ),
1141*cdf0e10cSrcweir 							ScGlobal::GetRscString( STR_MERGE_NOTEMPTY ) );
1142*cdf0e10cSrcweir 			sal_uInt16 nRetVal = aBox.Execute();
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir 			if ( nRetVal == RET_YES )
1145*cdf0e10cSrcweir 				rDoContents = sal_True;
1146*cdf0e10cSrcweir 			else if ( nRetVal == RET_CANCEL )
1147*cdf0e10cSrcweir 				bOk = sal_False;
1148*cdf0e10cSrcweir 		}
1149*cdf0e10cSrcweir 	}
1150*cdf0e10cSrcweir 
1151*cdf0e10cSrcweir 	if (bOk)
1152*cdf0e10cSrcweir 	{
1153*cdf0e10cSrcweir 		HideCursor();
1154*cdf0e10cSrcweir 		bOk = pDocSh->GetDocFunc().MergeCells( aMarkRange, rDoContents, bRecord, bApi );
1155*cdf0e10cSrcweir 		ShowCursor();
1156*cdf0e10cSrcweir 
1157*cdf0e10cSrcweir 		if (bOk)
1158*cdf0e10cSrcweir 		{
1159*cdf0e10cSrcweir 			SetCursor( nStartCol, nStartRow );
1160*cdf0e10cSrcweir 			//DoneBlockMode( sal_False);
1161*cdf0e10cSrcweir 			Unmark();
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir 			pDocSh->UpdateOle(GetViewData());
1164*cdf0e10cSrcweir 			UpdateInputLine();
1165*cdf0e10cSrcweir 		}
1166*cdf0e10cSrcweir 	}
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir 	return bOk;
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir 
1172*cdf0e10cSrcweir //----------------------------------------------------------------------------
1173*cdf0e10cSrcweir 
1174*cdf0e10cSrcweir sal_Bool ScViewFunc::TestRemoveMerge()
1175*cdf0e10cSrcweir {
1176*cdf0e10cSrcweir 	sal_Bool bMerged = sal_False;
1177*cdf0e10cSrcweir 	ScRange aRange;
1178*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1179*cdf0e10cSrcweir 	{
1180*cdf0e10cSrcweir 		ScDocument* pDoc = GetViewData()->GetDocument();
1181*cdf0e10cSrcweir 		if ( pDoc->HasAttrib( aRange, HASATTR_MERGED ) )
1182*cdf0e10cSrcweir 			bMerged = sal_True;
1183*cdf0e10cSrcweir 	}
1184*cdf0e10cSrcweir 	return bMerged;
1185*cdf0e10cSrcweir }
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir //----------------------------------------------------------------------------
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir sal_Bool ScViewFunc::RemoveMerge( sal_Bool bRecord )
1191*cdf0e10cSrcweir {
1192*cdf0e10cSrcweir 	ScRange aRange;
1193*cdf0e10cSrcweir     ScEditableTester aTester( this );
1194*cdf0e10cSrcweir     if (!aTester.IsEditable())
1195*cdf0e10cSrcweir     {
1196*cdf0e10cSrcweir         ErrorMessage(aTester.GetMessageId());
1197*cdf0e10cSrcweir         return sal_False;
1198*cdf0e10cSrcweir     }
1199*cdf0e10cSrcweir 	else if (GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1200*cdf0e10cSrcweir 	{
1201*cdf0e10cSrcweir         ScRange aExtended( aRange );
1202*cdf0e10cSrcweir         GetViewData()->GetDocument()->ExtendMerge( aExtended );
1203*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir 		HideCursor();
1206*cdf0e10cSrcweir 		sal_Bool bOk = pDocSh->GetDocFunc().UnmergeCells( aRange, bRecord, sal_False );
1207*cdf0e10cSrcweir         MarkRange( aExtended );
1208*cdf0e10cSrcweir 		ShowCursor();
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir 		if (bOk)
1211*cdf0e10cSrcweir 			pDocSh->UpdateOle(GetViewData());
1212*cdf0e10cSrcweir 	}
1213*cdf0e10cSrcweir 	return sal_True;		//! bOk ??
1214*cdf0e10cSrcweir }
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir //----------------------------------------------------------------------------
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir void ScViewFunc::FillSimple( FillDir eDir, sal_Bool bRecord )
1219*cdf0e10cSrcweir {
1220*cdf0e10cSrcweir 	ScRange aRange;
1221*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1222*cdf0e10cSrcweir 	{
1223*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1224*cdf0e10cSrcweir 		const ScMarkData& rMark = GetViewData()->GetMarkData();
1225*cdf0e10cSrcweir 		sal_Bool bSuccess = pDocSh->GetDocFunc().FillSimple( aRange, &rMark, eDir, bRecord, sal_False );
1226*cdf0e10cSrcweir 		if (bSuccess)
1227*cdf0e10cSrcweir 		{
1228*cdf0e10cSrcweir 			pDocSh->UpdateOle(GetViewData());
1229*cdf0e10cSrcweir 			UpdateScrollBars();
1230*cdf0e10cSrcweir 		}
1231*cdf0e10cSrcweir 	}
1232*cdf0e10cSrcweir 	else
1233*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1234*cdf0e10cSrcweir }
1235*cdf0e10cSrcweir 
1236*cdf0e10cSrcweir //----------------------------------------------------------------------------
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir void ScViewFunc::FillSeries( FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd,
1239*cdf0e10cSrcweir 							 double fStart, double fStep, double fMax, sal_Bool bRecord )
1240*cdf0e10cSrcweir {
1241*cdf0e10cSrcweir 	ScRange aRange;
1242*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1243*cdf0e10cSrcweir 	{
1244*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1245*cdf0e10cSrcweir 		const ScMarkData& rMark = GetViewData()->GetMarkData();
1246*cdf0e10cSrcweir 		sal_Bool bSuccess = pDocSh->GetDocFunc().
1247*cdf0e10cSrcweir 						FillSeries( aRange, &rMark, eDir, eCmd, eDateCmd,
1248*cdf0e10cSrcweir 									fStart, fStep, fMax, bRecord, sal_False );
1249*cdf0e10cSrcweir 		if (bSuccess)
1250*cdf0e10cSrcweir 		{
1251*cdf0e10cSrcweir 			pDocSh->UpdateOle(GetViewData());
1252*cdf0e10cSrcweir 			UpdateScrollBars();
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir             // #i97876# Spreadsheet data changes are not notified
1255*cdf0e10cSrcweir             ScModelObj* pModelObj = ScModelObj::getImplementation( pDocSh->GetModel() );
1256*cdf0e10cSrcweir             if ( pModelObj && pModelObj->HasChangesListeners() )
1257*cdf0e10cSrcweir             {
1258*cdf0e10cSrcweir                 ScRangeList aChangeRanges;
1259*cdf0e10cSrcweir                 aChangeRanges.Append( aRange );
1260*cdf0e10cSrcweir                 pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges );
1261*cdf0e10cSrcweir             }
1262*cdf0e10cSrcweir 		}
1263*cdf0e10cSrcweir 	}
1264*cdf0e10cSrcweir 	else
1265*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1266*cdf0e10cSrcweir }
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir //----------------------------------------------------------------------------
1269*cdf0e10cSrcweir 
1270*cdf0e10cSrcweir void ScViewFunc::FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
1271*cdf0e10cSrcweir 							SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount, sal_Bool bRecord )
1272*cdf0e10cSrcweir {
1273*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
1274*cdf0e10cSrcweir 	ScRange aRange( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab );
1275*cdf0e10cSrcweir     ScRange aSourceRange( aRange );
1276*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1277*cdf0e10cSrcweir 	const ScMarkData& rMark = GetViewData()->GetMarkData();
1278*cdf0e10cSrcweir 	sal_Bool bSuccess = pDocSh->GetDocFunc().
1279*cdf0e10cSrcweir 					FillAuto( aRange, &rMark, eDir, nCount, bRecord, sal_False );
1280*cdf0e10cSrcweir 	if (bSuccess)
1281*cdf0e10cSrcweir 	{
1282*cdf0e10cSrcweir 		MarkRange( aRange, sal_False );			// aRange ist in FillAuto veraendert worden
1283*cdf0e10cSrcweir 		pDocSh->UpdateOle(GetViewData());
1284*cdf0e10cSrcweir 		UpdateScrollBars();
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir         // #i97876# Spreadsheet data changes are not notified
1287*cdf0e10cSrcweir         ScModelObj* pModelObj = ScModelObj::getImplementation( pDocSh->GetModel() );
1288*cdf0e10cSrcweir         if ( pModelObj && pModelObj->HasChangesListeners() )
1289*cdf0e10cSrcweir         {
1290*cdf0e10cSrcweir             ScRangeList aChangeRanges;
1291*cdf0e10cSrcweir             ScRange aChangeRange( aRange );
1292*cdf0e10cSrcweir             switch ( eDir )
1293*cdf0e10cSrcweir             {
1294*cdf0e10cSrcweir                 case FILL_TO_BOTTOM:
1295*cdf0e10cSrcweir                     {
1296*cdf0e10cSrcweir                         aChangeRange.aStart.SetRow( aSourceRange.aEnd.Row() + 1 );
1297*cdf0e10cSrcweir                     }
1298*cdf0e10cSrcweir                     break;
1299*cdf0e10cSrcweir                 case FILL_TO_TOP:
1300*cdf0e10cSrcweir                     {
1301*cdf0e10cSrcweir                         aChangeRange.aEnd.SetRow( aSourceRange.aStart.Row() - 1 );
1302*cdf0e10cSrcweir                     }
1303*cdf0e10cSrcweir                     break;
1304*cdf0e10cSrcweir                 case FILL_TO_RIGHT:
1305*cdf0e10cSrcweir                     {
1306*cdf0e10cSrcweir                         aChangeRange.aStart.SetCol( aSourceRange.aEnd.Col() + 1 );
1307*cdf0e10cSrcweir                     }
1308*cdf0e10cSrcweir                     break;
1309*cdf0e10cSrcweir                 case FILL_TO_LEFT:
1310*cdf0e10cSrcweir                     {
1311*cdf0e10cSrcweir                         aChangeRange.aEnd.SetCol( aSourceRange.aStart.Col() - 1 );
1312*cdf0e10cSrcweir                     }
1313*cdf0e10cSrcweir                     break;
1314*cdf0e10cSrcweir                 default:
1315*cdf0e10cSrcweir                     {
1316*cdf0e10cSrcweir 
1317*cdf0e10cSrcweir                     }
1318*cdf0e10cSrcweir                     break;
1319*cdf0e10cSrcweir             }
1320*cdf0e10cSrcweir             aChangeRanges.Append( aChangeRange );
1321*cdf0e10cSrcweir             pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges );
1322*cdf0e10cSrcweir         }
1323*cdf0e10cSrcweir 	}
1324*cdf0e10cSrcweir }
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir //----------------------------------------------------------------------------
1327*cdf0e10cSrcweir 
1328*cdf0e10cSrcweir void ScViewFunc::FillTab( sal_uInt16 nFlags, sal_uInt16 nFunction, sal_Bool bSkipEmpty, sal_Bool bAsLink )
1329*cdf0e10cSrcweir {
1330*cdf0e10cSrcweir 	//! allow source sheet to be protected
1331*cdf0e10cSrcweir 	ScEditableTester aTester( this );
1332*cdf0e10cSrcweir 	if (!aTester.IsEditable())
1333*cdf0e10cSrcweir 	{
1334*cdf0e10cSrcweir 		ErrorMessage(aTester.GetMessageId());
1335*cdf0e10cSrcweir 		return;
1336*cdf0e10cSrcweir 	}
1337*cdf0e10cSrcweir 
1338*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1339*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
1340*cdf0e10cSrcweir 	ScMarkData& rMark = GetViewData()->GetMarkData();
1341*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
1342*cdf0e10cSrcweir 	sal_Bool bUndo(pDoc->IsUndoEnabled());
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir 	ScRange aMarkRange;
1345*cdf0e10cSrcweir 	rMark.MarkToSimple();
1346*cdf0e10cSrcweir 	sal_Bool bMulti = rMark.IsMultiMarked();
1347*cdf0e10cSrcweir 	if (bMulti)
1348*cdf0e10cSrcweir 		rMark.GetMultiMarkArea( aMarkRange );
1349*cdf0e10cSrcweir 	else if (rMark.IsMarked())
1350*cdf0e10cSrcweir 		rMark.GetMarkArea( aMarkRange );
1351*cdf0e10cSrcweir 	else
1352*cdf0e10cSrcweir 		aMarkRange = ScRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(), nTab );
1353*cdf0e10cSrcweir 
1354*cdf0e10cSrcweir 	ScDocument* pUndoDoc = NULL;
1355*cdf0e10cSrcweir //	if ( bRecord )
1356*cdf0e10cSrcweir 	if (bUndo)
1357*cdf0e10cSrcweir 	{
1358*cdf0e10cSrcweir 		pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1359*cdf0e10cSrcweir 		pUndoDoc->InitUndo( pDoc, nTab, nTab );
1360*cdf0e10cSrcweir //		pUndoDoc->SelectTable( nTab, sal_True );		// nur fuer Markierung
1361*cdf0e10cSrcweir 
1362*cdf0e10cSrcweir 		SCTAB nTabCount = pDoc->GetTableCount();
1363*cdf0e10cSrcweir 		for (SCTAB i=0; i<nTabCount; i++)
1364*cdf0e10cSrcweir 			if (i != nTab && rMark.GetTableSelect(i))
1365*cdf0e10cSrcweir 			{
1366*cdf0e10cSrcweir 				pUndoDoc->AddUndoTab( i, i );
1367*cdf0e10cSrcweir 				aMarkRange.aStart.SetTab( i );
1368*cdf0e10cSrcweir 				aMarkRange.aEnd.SetTab( i );
1369*cdf0e10cSrcweir 				pDoc->CopyToDocument( aMarkRange, IDF_ALL, bMulti, pUndoDoc );
1370*cdf0e10cSrcweir //				pUndoDoc->SelectTable( i, sal_True );
1371*cdf0e10cSrcweir 			}
1372*cdf0e10cSrcweir 	}
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir 	if (bMulti)
1375*cdf0e10cSrcweir 		pDoc->FillTabMarked( nTab, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1376*cdf0e10cSrcweir 	else
1377*cdf0e10cSrcweir 	{
1378*cdf0e10cSrcweir 		aMarkRange.aStart.SetTab( nTab );
1379*cdf0e10cSrcweir 		aMarkRange.aEnd.SetTab( nTab );
1380*cdf0e10cSrcweir 		pDoc->FillTab( aMarkRange, rMark, nFlags, nFunction, bSkipEmpty, bAsLink );
1381*cdf0e10cSrcweir 	}
1382*cdf0e10cSrcweir 
1383*cdf0e10cSrcweir //	if ( bRecord )
1384*cdf0e10cSrcweir 	if (bUndo)
1385*cdf0e10cSrcweir 	{	//! fuer ChangeTrack erst zum Schluss
1386*cdf0e10cSrcweir 		pDocSh->GetUndoManager()->AddUndoAction(
1387*cdf0e10cSrcweir 			new ScUndoFillTable( pDocSh, rMark,
1388*cdf0e10cSrcweir 								aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nTab,
1389*cdf0e10cSrcweir 								aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab,
1390*cdf0e10cSrcweir 								pUndoDoc, bMulti, nTab, nFlags, nFunction, bSkipEmpty, bAsLink ) );
1391*cdf0e10cSrcweir 	}
1392*cdf0e10cSrcweir 
1393*cdf0e10cSrcweir 	pDocSh->PostPaintGridAll();
1394*cdf0e10cSrcweir 	pDocSh->PostDataChanged();
1395*cdf0e10cSrcweir }
1396*cdf0e10cSrcweir 
1397*cdf0e10cSrcweir //----------------------------------------------------------------------------
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir /** Downward fill of selected cell(s) by double-clicking cross-hair cursor
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir 	Extends a current selection down to the last non-empty cell of an adjacent
1402*cdf0e10cSrcweir 	column when the lower-right corner of the selection is double-clicked.  It
1403*cdf0e10cSrcweir 	uses a left-adjoining non-empty column as a guide if such is available,
1404*cdf0e10cSrcweir 	otherwise a right-adjoining non-empty column is used.
1405*cdf0e10cSrcweir 
1406*cdf0e10cSrcweir 	@author Kohei Yoshida (kohei@openoffice.org)
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir 	@return No return value
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir 	@see #i12313#
1411*cdf0e10cSrcweir */
1412*cdf0e10cSrcweir void ScViewFunc::FillCrossDblClick()
1413*cdf0e10cSrcweir {
1414*cdf0e10cSrcweir 	ScRange aRange;
1415*cdf0e10cSrcweir 	GetViewData()->GetSimpleArea( aRange );
1416*cdf0e10cSrcweir 	aRange.Justify();
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetCurPos().Tab();
1419*cdf0e10cSrcweir 	SCCOL nStartX = aRange.aStart.Col();
1420*cdf0e10cSrcweir 	SCROW nStartY = aRange.aStart.Row();
1421*cdf0e10cSrcweir 	SCCOL nEndX   = aRange.aEnd.Col();
1422*cdf0e10cSrcweir 	SCROW nEndY   = aRange.aEnd.Row();
1423*cdf0e10cSrcweir 
1424*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir 	// Make sure the selection is not empty
1427*cdf0e10cSrcweir 	if ( pDoc->IsBlockEmpty( nTab, nStartX, nStartY, nEndX, nEndY ) )
1428*cdf0e10cSrcweir 		return;
1429*cdf0e10cSrcweir 
1430*cdf0e10cSrcweir 	if ( nEndY < MAXROW )
1431*cdf0e10cSrcweir 	{
1432*cdf0e10cSrcweir 		if ( nStartX > 0 )
1433*cdf0e10cSrcweir 		{
1434*cdf0e10cSrcweir 			SCCOL nMovX = nStartX - 1;
1435*cdf0e10cSrcweir 			SCROW nMovY = nStartY;
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir 			if ( pDoc->HasData( nMovX, nStartY, nTab ) &&
1438*cdf0e10cSrcweir 				 pDoc->HasData( nMovX, nStartY + 1, nTab ) )
1439*cdf0e10cSrcweir 			{
1440*cdf0e10cSrcweir 				pDoc->FindAreaPos( nMovX, nMovY, nTab, 0, 1 );
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir 				if ( nMovY > nEndY )
1443*cdf0e10cSrcweir 				{
1444*cdf0e10cSrcweir 					FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY,
1445*cdf0e10cSrcweir 							  nMovY - nEndY );
1446*cdf0e10cSrcweir 					return;
1447*cdf0e10cSrcweir 				}
1448*cdf0e10cSrcweir 			}
1449*cdf0e10cSrcweir 		}
1450*cdf0e10cSrcweir 
1451*cdf0e10cSrcweir 		if ( nEndX < MAXCOL )
1452*cdf0e10cSrcweir 		{
1453*cdf0e10cSrcweir 			SCCOL nMovX = nEndX + 1;
1454*cdf0e10cSrcweir 			SCROW nMovY = nStartY;
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir 			if ( pDoc->HasData( nMovX, nStartY, nTab ) &&
1457*cdf0e10cSrcweir 				 pDoc->HasData( nMovX, nStartY + 1, nTab ) )
1458*cdf0e10cSrcweir 			{
1459*cdf0e10cSrcweir 				pDoc->FindAreaPos( nMovX, nMovY, nTab, 0, 1 );
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir 				if ( nMovY > nEndY )
1462*cdf0e10cSrcweir 				{
1463*cdf0e10cSrcweir 					FillAuto( FILL_TO_BOTTOM, nStartX, nStartY, nEndX, nEndY,
1464*cdf0e10cSrcweir 							  nMovY - nEndY );
1465*cdf0e10cSrcweir 					return;
1466*cdf0e10cSrcweir 				}
1467*cdf0e10cSrcweir 			}
1468*cdf0e10cSrcweir 		}
1469*cdf0e10cSrcweir 	}
1470*cdf0e10cSrcweir }
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir //----------------------------------------------------------------------------
1473*cdf0e10cSrcweir 
1474*cdf0e10cSrcweir void ScViewFunc::TransliterateText( sal_Int32 nType )
1475*cdf0e10cSrcweir {
1476*cdf0e10cSrcweir 	ScMarkData aFuncMark = GetViewData()->GetMarkData();
1477*cdf0e10cSrcweir 	if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )
1478*cdf0e10cSrcweir 	{
1479*cdf0e10cSrcweir 		//	no selection -> use cursor position
1480*cdf0e10cSrcweir 
1481*cdf0e10cSrcweir 		ScAddress aCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
1482*cdf0e10cSrcweir 		aFuncMark.SetMarkArea( ScRange( aCursor ) );
1483*cdf0e10cSrcweir 	}
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir 	sal_Bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().
1486*cdf0e10cSrcweir 						TransliterateText( aFuncMark, nType, sal_True, sal_False );
1487*cdf0e10cSrcweir 	if (bSuccess)
1488*cdf0e10cSrcweir 	{
1489*cdf0e10cSrcweir 		GetViewData()->GetViewShell()->UpdateInputHandler();
1490*cdf0e10cSrcweir 	}
1491*cdf0e10cSrcweir }
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir //----------------------------------------------------------------------------
1494*cdf0e10cSrcweir //	AutoFormat
1495*cdf0e10cSrcweir 
1496*cdf0e10cSrcweir ScAutoFormatData* ScViewFunc::CreateAutoFormatData()
1497*cdf0e10cSrcweir {
1498*cdf0e10cSrcweir 	ScAutoFormatData* pData = NULL;
1499*cdf0e10cSrcweir 	SCCOL nStartCol;
1500*cdf0e10cSrcweir 	SCROW nStartRow;
1501*cdf0e10cSrcweir 	SCTAB nStartTab;
1502*cdf0e10cSrcweir 	SCCOL nEndCol;
1503*cdf0e10cSrcweir 	SCROW nEndRow;
1504*cdf0e10cSrcweir 	SCTAB nEndTab;
1505*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
1506*cdf0e10cSrcweir 	{
1507*cdf0e10cSrcweir 		if ( nEndCol-nStartCol >= 3 && nEndRow-nStartRow >= 3 )
1508*cdf0e10cSrcweir 		{
1509*cdf0e10cSrcweir 			ScDocument* pDoc = GetViewData()->GetDocument();
1510*cdf0e10cSrcweir 			pData = new ScAutoFormatData;
1511*cdf0e10cSrcweir 			pDoc->GetAutoFormatData( nStartTab, nStartCol,nStartRow,nEndCol,nEndRow, *pData );
1512*cdf0e10cSrcweir 		}
1513*cdf0e10cSrcweir 	}
1514*cdf0e10cSrcweir 	return pData;
1515*cdf0e10cSrcweir }
1516*cdf0e10cSrcweir 
1517*cdf0e10cSrcweir 
1518*cdf0e10cSrcweir //----------------------------------------------------------------------------
1519*cdf0e10cSrcweir 
1520*cdf0e10cSrcweir void ScViewFunc::AutoFormat( sal_uInt16 nFormatNo, sal_Bool bRecord )
1521*cdf0e10cSrcweir {
1522*cdf0e10cSrcweir #if 1
1523*cdf0e10cSrcweir 
1524*cdf0e10cSrcweir 	ScRange aRange;
1525*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1526*cdf0e10cSrcweir 	{
1527*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1528*cdf0e10cSrcweir 		ScMarkData& rMark = GetViewData()->GetMarkData();
1529*cdf0e10cSrcweir 
1530*cdf0e10cSrcweir 		sal_Bool bSuccess = pDocSh->GetDocFunc().AutoFormat( aRange, &rMark, nFormatNo, bRecord, sal_False );
1531*cdf0e10cSrcweir 		if (bSuccess)
1532*cdf0e10cSrcweir 			pDocSh->UpdateOle(GetViewData());
1533*cdf0e10cSrcweir 	}
1534*cdf0e10cSrcweir 	else
1535*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1536*cdf0e10cSrcweir 
1537*cdf0e10cSrcweir #else
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir 	// nur wegen Matrix nicht editierbar? Attribute trotzdem ok
1540*cdf0e10cSrcweir 	sal_Bool bOnlyNotBecauseOfMatrix;
1541*cdf0e10cSrcweir 	if ( !SelectionEditable( &bOnlyNotBecauseOfMatrix ) && !bOnlyNotBecauseOfMatrix )
1542*cdf0e10cSrcweir 	{
1543*cdf0e10cSrcweir 		ErrorMessage(STR_PROTECTIONERR);
1544*cdf0e10cSrcweir 		return;
1545*cdf0e10cSrcweir 	}
1546*cdf0e10cSrcweir 
1547*cdf0e10cSrcweir 	SCCOL nStartCol;
1548*cdf0e10cSrcweir 	SCROW nStartRow;
1549*cdf0e10cSrcweir 	SCTAB nStartTab;
1550*cdf0e10cSrcweir 	SCCOL nEndCol;
1551*cdf0e10cSrcweir 	SCROW nEndRow;
1552*cdf0e10cSrcweir 	SCTAB nEndTab;
1553*cdf0e10cSrcweir 
1554*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
1555*cdf0e10cSrcweir 	{
1556*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1557*cdf0e10cSrcweir 		ScDocument* pDoc = pDocSh->GetDocument();
1558*cdf0e10cSrcweir 		ScMarkData& rMark = GetViewData()->GetMarkData();
1559*cdf0e10cSrcweir 		sal_Bool bSize = (*ScGlobal::GetAutoFormat())[nFormatNo]->GetIncludeWidthHeight();
1560*cdf0e10cSrcweir 		if (bRecord && !pDoc->IsUndoEnabled())
1561*cdf0e10cSrcweir 			bRecord = sal_False;
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 		ScDocument* pUndoDoc = NULL;
1564*cdf0e10cSrcweir 		if ( bRecord )
1565*cdf0e10cSrcweir 		{
1566*cdf0e10cSrcweir 			pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1567*cdf0e10cSrcweir 			pUndoDoc->InitUndo( pDoc, nStartTab, nEndTab, bSize, bSize );
1568*cdf0e10cSrcweir 			pDoc->CopyToDocument( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1569*cdf0e10cSrcweir 									IDF_ATTRIB, sal_False, pUndoDoc );
1570*cdf0e10cSrcweir 			if (bSize)
1571*cdf0e10cSrcweir 			{
1572*cdf0e10cSrcweir 				pDoc->CopyToDocument( nStartCol,0,nStartTab, nEndCol,MAXROW,nEndTab,
1573*cdf0e10cSrcweir 															IDF_NONE, sal_False, pUndoDoc );
1574*cdf0e10cSrcweir 				pDoc->CopyToDocument( 0,nStartRow,nStartTab, MAXCOL,nEndRow,nEndTab,
1575*cdf0e10cSrcweir 															IDF_NONE, sal_False, pUndoDoc );
1576*cdf0e10cSrcweir 			}
1577*cdf0e10cSrcweir 			pDoc->BeginDrawUndo();
1578*cdf0e10cSrcweir 		}
1579*cdf0e10cSrcweir 
1580*cdf0e10cSrcweir 		GetFrameWin()->EnterWait();
1581*cdf0e10cSrcweir 		pDoc->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, nFormatNo, rMark );
1582*cdf0e10cSrcweir 		GetFrameWin()->LeaveWait();
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir 		if (bSize)
1585*cdf0e10cSrcweir 		{
1586*cdf0e10cSrcweir 			SetMarkedWidthOrHeight( sal_True, SC_SIZE_VISOPT, STD_EXTRA_WIDTH, sal_False, sal_False );
1587*cdf0e10cSrcweir 			SetMarkedWidthOrHeight( sal_False, SC_SIZE_VISOPT, 0, sal_False, sal_False );
1588*cdf0e10cSrcweir 			pDocSh->PostPaint( 0,0,nStartTab, MAXCOL,MAXROW,nStartTab,
1589*cdf0e10cSrcweir 									PAINT_GRID | PAINT_LEFT | PAINT_TOP );
1590*cdf0e10cSrcweir 		}
1591*cdf0e10cSrcweir 		else
1592*cdf0e10cSrcweir 		{
1593*cdf0e10cSrcweir 			sal_Bool bAdj = AdjustBlockHeight( sal_False );
1594*cdf0e10cSrcweir 			if (bAdj)
1595*cdf0e10cSrcweir 				pDocSh->PostPaint( 0,nStartRow,nStartTab, MAXCOL,MAXROW,nStartTab,
1596*cdf0e10cSrcweir 									PAINT_GRID | PAINT_LEFT );
1597*cdf0e10cSrcweir 			else
1598*cdf0e10cSrcweir 				pDocSh->PostPaint( nStartCol, nStartRow, nStartTab,
1599*cdf0e10cSrcweir 									nEndCol, nEndRow, nEndTab, PAINT_GRID );
1600*cdf0e10cSrcweir 		}
1601*cdf0e10cSrcweir 
1602*cdf0e10cSrcweir 		if ( bRecord )		// Draw-Undo erst jetzt verfuegbar
1603*cdf0e10cSrcweir 		{
1604*cdf0e10cSrcweir 			pDocSh->GetUndoManager()->AddUndoAction(
1605*cdf0e10cSrcweir 				new ScUndoAutoFormat( pDocSh,
1606*cdf0e10cSrcweir 						ScRange(nStartCol,nStartRow,nStartTab, nEndCol,nEndRow,nEndTab),
1607*cdf0e10cSrcweir 						pUndoDoc, rMark, bSize, nFormatNo ) );
1608*cdf0e10cSrcweir 		}
1609*cdf0e10cSrcweir 
1610*cdf0e10cSrcweir 		pDocSh->UpdateOle(GetViewData());
1611*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
1612*cdf0e10cSrcweir 	}
1613*cdf0e10cSrcweir 	else
1614*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir #endif
1617*cdf0e10cSrcweir }
1618*cdf0e10cSrcweir 
1619*cdf0e10cSrcweir 
1620*cdf0e10cSrcweir //----------------------------------------------------------------------------
1621*cdf0e10cSrcweir //	Suchen & Ersetzen
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir void ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
1624*cdf0e10cSrcweir 										sal_Bool bAddUndo, sal_Bool bIsApi )
1625*cdf0e10cSrcweir {
1626*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1627*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
1628*cdf0e10cSrcweir 	ScMarkData& rMark = GetViewData()->GetMarkData();
1629*cdf0e10cSrcweir 	if (bAddUndo && !pDoc->IsUndoEnabled())
1630*cdf0e10cSrcweir 		bAddUndo = sal_False;
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir 	SCCOL nCol = GetViewData()->GetCurX();
1633*cdf0e10cSrcweir 	SCROW nRow = GetViewData()->GetCurY();
1634*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
1635*cdf0e10cSrcweir //    sal_Bool bAttrib = pSearchItem->GetPattern();
1636*cdf0e10cSrcweir 	sal_uInt16 nCommand = pSearchItem->GetCommand();
1637*cdf0e10cSrcweir 	sal_Bool bAllTables = pSearchItem->IsAllTables();
1638*cdf0e10cSrcweir 	sal_Bool* pOldSelectedTables = NULL;
1639*cdf0e10cSrcweir 	sal_uInt16 nOldSelectedCount = 0;
1640*cdf0e10cSrcweir 	SCTAB nOldTab = nTab;
1641*cdf0e10cSrcweir 	SCTAB nLastTab = pDoc->GetTableCount() - 1;
1642*cdf0e10cSrcweir 	SCTAB nStartTab, nEndTab;
1643*cdf0e10cSrcweir 	if ( bAllTables )
1644*cdf0e10cSrcweir 	{
1645*cdf0e10cSrcweir 		nStartTab = 0;
1646*cdf0e10cSrcweir 		nEndTab = nLastTab;
1647*cdf0e10cSrcweir 		pOldSelectedTables = new sal_Bool [ nEndTab + 1 ];
1648*cdf0e10cSrcweir 		for ( SCTAB j = 0; j <= nEndTab; j++ )
1649*cdf0e10cSrcweir 		{
1650*cdf0e10cSrcweir 			pOldSelectedTables[j] = rMark.GetTableSelect( j );
1651*cdf0e10cSrcweir 			if ( pOldSelectedTables[j] )
1652*cdf0e10cSrcweir 				++nOldSelectedCount;
1653*cdf0e10cSrcweir 		}
1654*cdf0e10cSrcweir 	}
1655*cdf0e10cSrcweir 	else
1656*cdf0e10cSrcweir 	{	//! mindestens eine ist immer selektiert
1657*cdf0e10cSrcweir 		nStartTab = nEndTab = rMark.GetFirstSelected();
1658*cdf0e10cSrcweir 		for ( SCTAB j = nStartTab + 1; j <= nLastTab; j++ )
1659*cdf0e10cSrcweir 		{
1660*cdf0e10cSrcweir 			if ( rMark.GetTableSelect( j ) )
1661*cdf0e10cSrcweir 				nEndTab = j;
1662*cdf0e10cSrcweir 		}
1663*cdf0e10cSrcweir 	}
1664*cdf0e10cSrcweir 
1665*cdf0e10cSrcweir 	if (   nCommand == SVX_SEARCHCMD_REPLACE
1666*cdf0e10cSrcweir 		|| nCommand == SVX_SEARCHCMD_REPLACE_ALL )
1667*cdf0e10cSrcweir 	{
1668*cdf0e10cSrcweir 		for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
1669*cdf0e10cSrcweir 		{
1670*cdf0e10cSrcweir 			if ( (bAllTables || rMark.GetTableSelect( j )) &&
1671*cdf0e10cSrcweir 					pDoc->IsTabProtected( j ) )
1672*cdf0e10cSrcweir 			{
1673*cdf0e10cSrcweir 				if ( pOldSelectedTables )
1674*cdf0e10cSrcweir 					delete [] pOldSelectedTables;
1675*cdf0e10cSrcweir 				ErrorMessage(STR_PROTECTIONERR);
1676*cdf0e10cSrcweir 				return;
1677*cdf0e10cSrcweir 			}
1678*cdf0e10cSrcweir 		}
1679*cdf0e10cSrcweir 	}
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir 	if (   nCommand == SVX_SEARCHCMD_FIND
1682*cdf0e10cSrcweir 		|| nCommand == SVX_SEARCHCMD_FIND_ALL)
1683*cdf0e10cSrcweir 		bAddUndo = sal_False;
1684*cdf0e10cSrcweir 
1685*cdf0e10cSrcweir 	//!		bAttrib bei Undo beruecksichtigen !!!
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir 	ScDocument* pUndoDoc = NULL;
1688*cdf0e10cSrcweir 	ScMarkData* pUndoMark = NULL;
1689*cdf0e10cSrcweir 	String aUndoStr;
1690*cdf0e10cSrcweir 	if (bAddUndo)
1691*cdf0e10cSrcweir 	{
1692*cdf0e10cSrcweir 		pUndoMark = new ScMarkData( rMark );				// Markierung wird veraendert
1693*cdf0e10cSrcweir 		if ( nCommand == SVX_SEARCHCMD_REPLACE_ALL )
1694*cdf0e10cSrcweir 		{
1695*cdf0e10cSrcweir 			pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1696*cdf0e10cSrcweir 			pUndoDoc->InitUndo( pDoc, nStartTab, nEndTab );
1697*cdf0e10cSrcweir 		}
1698*cdf0e10cSrcweir 	}
1699*cdf0e10cSrcweir 
1700*cdf0e10cSrcweir 	if ( bAllTables )
1701*cdf0e10cSrcweir 	{	//! alles selektieren, erst nachdem pUndoMark erzeugt wurde
1702*cdf0e10cSrcweir 		for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
1703*cdf0e10cSrcweir 		{
1704*cdf0e10cSrcweir 			rMark.SelectTable( j, sal_True );
1705*cdf0e10cSrcweir 		}
1706*cdf0e10cSrcweir 	}
1707*cdf0e10cSrcweir 
1708*cdf0e10cSrcweir 	DoneBlockMode(sal_True);				// Markierung nicht loeschen!
1709*cdf0e10cSrcweir 	InitOwnBlockMode();
1710*cdf0e10cSrcweir 
1711*cdf0e10cSrcweir 	//	wenn vom Anfang an gesucht wird, nicht nochmal fragen ob vom Anfang gesucht werden soll
1712*cdf0e10cSrcweir 	sal_Bool bFirst = sal_True;
1713*cdf0e10cSrcweir 	if ( nCol == 0 && nRow == 0 && nTab == nStartTab && !pSearchItem->GetBackward()  )
1714*cdf0e10cSrcweir 		bFirst = sal_False;
1715*cdf0e10cSrcweir 
1716*cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
1717*cdf0e10cSrcweir 	while (sal_True)
1718*cdf0e10cSrcweir 	{
1719*cdf0e10cSrcweir 		GetFrameWin()->EnterWait();
1720*cdf0e10cSrcweir 		if (pDoc->SearchAndReplace( *pSearchItem, nCol, nRow, nTab, rMark, aUndoStr, pUndoDoc ) )
1721*cdf0e10cSrcweir 		{
1722*cdf0e10cSrcweir 			bFound = sal_True;
1723*cdf0e10cSrcweir 			bFirst = sal_True;
1724*cdf0e10cSrcweir 			if (bAddUndo)
1725*cdf0e10cSrcweir 			{
1726*cdf0e10cSrcweir 				GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
1727*cdf0e10cSrcweir 					new ScUndoReplace( GetViewData()->GetDocShell(), *pUndoMark,
1728*cdf0e10cSrcweir 										nCol, nRow, nTab,
1729*cdf0e10cSrcweir 										aUndoStr, pUndoDoc, pSearchItem ) );
1730*cdf0e10cSrcweir 				pUndoDoc = NULL;
1731*cdf0e10cSrcweir 			}
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir 			break;					// Abbruch while True
1734*cdf0e10cSrcweir 		}
1735*cdf0e10cSrcweir 		else if ( bFirst && (nCommand == SVX_SEARCHCMD_FIND ||
1736*cdf0e10cSrcweir 				nCommand == SVX_SEARCHCMD_REPLACE) )
1737*cdf0e10cSrcweir 		{
1738*cdf0e10cSrcweir 			bFirst = sal_False;
1739*cdf0e10cSrcweir 			sal_uInt16 nRetVal;
1740*cdf0e10cSrcweir 			GetFrameWin()->LeaveWait();
1741*cdf0e10cSrcweir 			if ( bIsApi )
1742*cdf0e10cSrcweir 				nRetVal = RET_NO;
1743*cdf0e10cSrcweir 			else
1744*cdf0e10cSrcweir 			{
1745*cdf0e10cSrcweir 				//	Suchen-Dialog als Parent, wenn vorhanden
1746*cdf0e10cSrcweir 				Window* pParent = GetParentOrChild(SID_SEARCH_DLG);
1747*cdf0e10cSrcweir 				sal_uInt16 nStrId;
1748*cdf0e10cSrcweir 				if ( pSearchItem->GetBackward() )
1749*cdf0e10cSrcweir 				{
1750*cdf0e10cSrcweir 					if ( nStartTab == nEndTab )
1751*cdf0e10cSrcweir 						nStrId = STR_MSSG_SEARCHANDREPLACE_1;
1752*cdf0e10cSrcweir 					else
1753*cdf0e10cSrcweir 						nStrId = STR_MSSG_SEARCHANDREPLACE_4;
1754*cdf0e10cSrcweir 				}
1755*cdf0e10cSrcweir 				else
1756*cdf0e10cSrcweir 				{
1757*cdf0e10cSrcweir 					if ( nStartTab == nEndTab )
1758*cdf0e10cSrcweir 						nStrId = STR_MSSG_SEARCHANDREPLACE_2;
1759*cdf0e10cSrcweir 					else
1760*cdf0e10cSrcweir 						nStrId = STR_MSSG_SEARCHANDREPLACE_5;
1761*cdf0e10cSrcweir 				}
1762*cdf0e10cSrcweir 				MessBox aBox( pParent, WinBits(WB_YES_NO | WB_DEF_YES),
1763*cdf0e10cSrcweir 								ScGlobal::GetRscString( STR_MSSG_SEARCHANDREPLACE_3 ),
1764*cdf0e10cSrcweir 								ScGlobal::GetRscString( nStrId ) );
1765*cdf0e10cSrcweir 				nRetVal = aBox.Execute();
1766*cdf0e10cSrcweir 			}
1767*cdf0e10cSrcweir 
1768*cdf0e10cSrcweir 			if ( nRetVal == RET_YES )
1769*cdf0e10cSrcweir 			{
1770*cdf0e10cSrcweir 				ScDocument::GetSearchAndReplaceStart( *pSearchItem, nCol, nRow );
1771*cdf0e10cSrcweir 				if (pSearchItem->GetBackward())
1772*cdf0e10cSrcweir 					nTab = nEndTab;
1773*cdf0e10cSrcweir 				else
1774*cdf0e10cSrcweir 					nTab = nStartTab;
1775*cdf0e10cSrcweir 			}
1776*cdf0e10cSrcweir 			else
1777*cdf0e10cSrcweir 			{
1778*cdf0e10cSrcweir 				break;					// Abbruch while True
1779*cdf0e10cSrcweir 			}
1780*cdf0e10cSrcweir 		}
1781*cdf0e10cSrcweir 		else							// nichts gefunden
1782*cdf0e10cSrcweir 		{
1783*cdf0e10cSrcweir 			if ( nCommand == SVX_SEARCHCMD_FIND_ALL || nCommand == SVX_SEARCHCMD_REPLACE_ALL )
1784*cdf0e10cSrcweir 			{
1785*cdf0e10cSrcweir 				pDocSh->PostPaintGridAll();								// Markierung
1786*cdf0e10cSrcweir 			}
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir 			GetFrameWin()->LeaveWait();
1789*cdf0e10cSrcweir 			if (!bIsApi)
1790*cdf0e10cSrcweir 			{
1791*cdf0e10cSrcweir 				//	Suchen-Dialog als Parent, wenn vorhanden
1792*cdf0e10cSrcweir 				Window* pParent = GetParentOrChild(SID_SEARCH_DLG);
1793*cdf0e10cSrcweir 				// "nichts gefunden"
1794*cdf0e10cSrcweir 				InfoBox aBox( pParent, ScGlobal::GetRscString( STR_MSSG_SEARCHANDREPLACE_0 ) );
1795*cdf0e10cSrcweir 				aBox.Execute();
1796*cdf0e10cSrcweir 			}
1797*cdf0e10cSrcweir 
1798*cdf0e10cSrcweir 			break;						// Abbruch while True
1799*cdf0e10cSrcweir 		}
1800*cdf0e10cSrcweir 	}								// of while sal_True
1801*cdf0e10cSrcweir 
1802*cdf0e10cSrcweir 	if ( pOldSelectedTables )
1803*cdf0e10cSrcweir 	{	// urspruenglich selektierte Tabellen wiederherstellen
1804*cdf0e10cSrcweir 		for ( SCTAB j = nStartTab; j <= nEndTab; j++ )
1805*cdf0e10cSrcweir 		{
1806*cdf0e10cSrcweir 			rMark.SelectTable( j, pOldSelectedTables[j] );
1807*cdf0e10cSrcweir 		}
1808*cdf0e10cSrcweir 		if ( bFound )
1809*cdf0e10cSrcweir 		{	// durch Fundstelle neu selektierte Tabelle bleibt
1810*cdf0e10cSrcweir 			rMark.SelectTable( nTab, sal_True );
1811*cdf0e10cSrcweir 			// wenn vorher nur eine selektiert war, ist es ein Tausch
1812*cdf0e10cSrcweir 			//! wenn nicht, ist jetzt evtl. eine mehr selektiert
1813*cdf0e10cSrcweir 			if ( nOldSelectedCount == 1 && nTab != nOldTab )
1814*cdf0e10cSrcweir 				rMark.SelectTable( nOldTab, sal_False );
1815*cdf0e10cSrcweir 		}
1816*cdf0e10cSrcweir 		delete [] pOldSelectedTables;
1817*cdf0e10cSrcweir 	}
1818*cdf0e10cSrcweir 
1819*cdf0e10cSrcweir     MarkDataChanged();
1820*cdf0e10cSrcweir 
1821*cdf0e10cSrcweir 	if ( bFound )
1822*cdf0e10cSrcweir 	{
1823*cdf0e10cSrcweir 		if ( nTab != GetViewData()->GetTabNo() )
1824*cdf0e10cSrcweir 			SetTabNo( nTab );
1825*cdf0e10cSrcweir 
1826*cdf0e10cSrcweir 		//	wenn nichts markiert ist, DoneBlockMode, damit von hier aus
1827*cdf0e10cSrcweir 		//	direkt per Shift-Cursor markiert werden kann:
1828*cdf0e10cSrcweir 		if (!rMark.IsMarked() && !rMark.IsMultiMarked())
1829*cdf0e10cSrcweir 			DoneBlockMode(sal_True);
1830*cdf0e10cSrcweir 
1831*cdf0e10cSrcweir 		AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
1832*cdf0e10cSrcweir 		SetCursor( nCol, nRow, sal_True );
1833*cdf0e10cSrcweir 
1834*cdf0e10cSrcweir 		if (   nCommand == SVX_SEARCHCMD_REPLACE
1835*cdf0e10cSrcweir 			|| nCommand == SVX_SEARCHCMD_REPLACE_ALL )
1836*cdf0e10cSrcweir 		{
1837*cdf0e10cSrcweir 			if ( nCommand == SVX_SEARCHCMD_REPLACE )
1838*cdf0e10cSrcweir 				pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID );
1839*cdf0e10cSrcweir 			else
1840*cdf0e10cSrcweir 				pDocSh->PostPaintGridAll();
1841*cdf0e10cSrcweir 			pDocSh->SetDocumentModified();
1842*cdf0e10cSrcweir 		}
1843*cdf0e10cSrcweir 		else if ( nCommand == SVX_SEARCHCMD_FIND_ALL )
1844*cdf0e10cSrcweir 			pDocSh->PostPaintGridAll();								// Markierung
1845*cdf0e10cSrcweir 		GetFrameWin()->LeaveWait();
1846*cdf0e10cSrcweir 	}
1847*cdf0e10cSrcweir 
1848*cdf0e10cSrcweir 	delete pUndoDoc;			// loeschen wenn nicht benutzt
1849*cdf0e10cSrcweir 	delete pUndoMark;			// kann immer geloescht werden
1850*cdf0e10cSrcweir }
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir 
1853*cdf0e10cSrcweir //----------------------------------------------------------------------------
1854*cdf0e10cSrcweir //	Zielwertsuche
1855*cdf0e10cSrcweir 
1856*cdf0e10cSrcweir void ScViewFunc::Solve( const ScSolveParam& rParam )
1857*cdf0e10cSrcweir {
1858*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
1859*cdf0e10cSrcweir 
1860*cdf0e10cSrcweir 	SCCOL nDestCol = rParam.aRefVariableCell.Col();
1861*cdf0e10cSrcweir 	SCROW nDestRow = rParam.aRefVariableCell.Row();
1862*cdf0e10cSrcweir 	SCTAB nDestTab = rParam.aRefVariableCell.Tab();
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir 	ScEditableTester aTester( pDoc, nDestTab, nDestCol,nDestRow, nDestCol,nDestRow );
1865*cdf0e10cSrcweir 	if (!aTester.IsEditable())
1866*cdf0e10cSrcweir 	{
1867*cdf0e10cSrcweir 		ErrorMessage(aTester.GetMessageId());
1868*cdf0e10cSrcweir 		return;
1869*cdf0e10cSrcweir 	}
1870*cdf0e10cSrcweir 
1871*cdf0e10cSrcweir 	if ( pDoc )
1872*cdf0e10cSrcweir 	{
1873*cdf0e10cSrcweir 		String  aTargetValStr;
1874*cdf0e10cSrcweir 		if ( rParam.pStrTargetVal != NULL )
1875*cdf0e10cSrcweir 			aTargetValStr = *(rParam.pStrTargetVal);
1876*cdf0e10cSrcweir 
1877*cdf0e10cSrcweir 		String  aMsgStr;
1878*cdf0e10cSrcweir 		String	aResStr;
1879*cdf0e10cSrcweir 		double	nSolveResult;
1880*cdf0e10cSrcweir 
1881*cdf0e10cSrcweir 		GetFrameWin()->EnterWait();
1882*cdf0e10cSrcweir 
1883*cdf0e10cSrcweir 		sal_Bool  	bExact =
1884*cdf0e10cSrcweir 					pDoc->Solver(
1885*cdf0e10cSrcweir 						rParam.aRefFormulaCell.Col(),
1886*cdf0e10cSrcweir 						rParam.aRefFormulaCell.Row(),
1887*cdf0e10cSrcweir 						rParam.aRefFormulaCell.Tab(),
1888*cdf0e10cSrcweir 						nDestCol, nDestRow, nDestTab,
1889*cdf0e10cSrcweir 						aTargetValStr,
1890*cdf0e10cSrcweir 						nSolveResult );
1891*cdf0e10cSrcweir 
1892*cdf0e10cSrcweir 		GetFrameWin()->LeaveWait();
1893*cdf0e10cSrcweir 
1894*cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
1895*cdf0e10cSrcweir 		sal_uLong nFormat = 0;
1896*cdf0e10cSrcweir 		const ScPatternAttr* pPattern = pDoc->GetPattern( nDestCol, nDestRow, nDestTab );
1897*cdf0e10cSrcweir 		if ( pPattern )
1898*cdf0e10cSrcweir 			nFormat = pPattern->GetNumberFormat( pFormatter );
1899*cdf0e10cSrcweir 		Color* p;
1900*cdf0e10cSrcweir 		pFormatter->GetOutputString( nSolveResult, nFormat, aResStr, &p );
1901*cdf0e10cSrcweir 
1902*cdf0e10cSrcweir 		if ( bExact )
1903*cdf0e10cSrcweir 		{
1904*cdf0e10cSrcweir 			aMsgStr  = ScGlobal::GetRscString( STR_MSSG_SOLVE_0 );
1905*cdf0e10cSrcweir 			aMsgStr += ScGlobal::GetRscString( STR_MSSG_SOLVE_1 );
1906*cdf0e10cSrcweir 			aMsgStr += String( aResStr );
1907*cdf0e10cSrcweir 			aMsgStr += ScGlobal::GetRscString( STR_MSSG_SOLVE_2 );
1908*cdf0e10cSrcweir 		}
1909*cdf0e10cSrcweir 		else
1910*cdf0e10cSrcweir 		{
1911*cdf0e10cSrcweir 			aMsgStr  = ScGlobal::GetRscString( STR_MSSG_SOLVE_3 );
1912*cdf0e10cSrcweir 			aMsgStr += ScGlobal::GetRscString( STR_MSSG_SOLVE_4 );
1913*cdf0e10cSrcweir 			aMsgStr += ScGlobal::GetRscString( STR_MSSG_SOLVE_5 );
1914*cdf0e10cSrcweir 			aMsgStr += String( aResStr );
1915*cdf0e10cSrcweir 			aMsgStr += ScGlobal::GetRscString( STR_MSSG_SOLVE_6 );
1916*cdf0e10cSrcweir 		}
1917*cdf0e10cSrcweir 
1918*cdf0e10cSrcweir 		MessBox aBox( GetViewData()->GetDialogParent(),
1919*cdf0e10cSrcweir 						WinBits(WB_YES_NO | WB_DEF_NO),
1920*cdf0e10cSrcweir 						ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ), aMsgStr );
1921*cdf0e10cSrcweir 		sal_uInt16 nRetVal = aBox.Execute();
1922*cdf0e10cSrcweir 
1923*cdf0e10cSrcweir 		if ( RET_YES == nRetVal )
1924*cdf0e10cSrcweir 			EnterValue( nDestCol, nDestRow, nDestTab, nSolveResult );
1925*cdf0e10cSrcweir 
1926*cdf0e10cSrcweir 		GetViewData()->GetViewShell()->UpdateInputHandler( sal_True );
1927*cdf0e10cSrcweir 	}
1928*cdf0e10cSrcweir }
1929*cdf0e10cSrcweir 
1930*cdf0e10cSrcweir 
1931*cdf0e10cSrcweir //----------------------------------------------------------------------------
1932*cdf0e10cSrcweir //	Mehrfachoperation
1933*cdf0e10cSrcweir 
1934*cdf0e10cSrcweir void ScViewFunc::TabOp( const ScTabOpParam& rParam, sal_Bool bRecord )
1935*cdf0e10cSrcweir {
1936*cdf0e10cSrcweir 	ScRange aRange;
1937*cdf0e10cSrcweir 	if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
1938*cdf0e10cSrcweir 	{
1939*cdf0e10cSrcweir 		ScDocShell* pDocSh = GetViewData()->GetDocShell();
1940*cdf0e10cSrcweir 		ScMarkData& rMark = GetViewData()->GetMarkData();
1941*cdf0e10cSrcweir 		pDocSh->GetDocFunc().TabOp( aRange, &rMark, rParam, bRecord, sal_False );
1942*cdf0e10cSrcweir 	}
1943*cdf0e10cSrcweir 	else
1944*cdf0e10cSrcweir 		ErrorMessage(STR_NOMULTISELECT);
1945*cdf0e10cSrcweir }
1946*cdf0e10cSrcweir 
1947*cdf0e10cSrcweir 
1948*cdf0e10cSrcweir //----------------------------------------------------------------------------
1949*cdf0e10cSrcweir 
1950*cdf0e10cSrcweir void ScViewFunc::MakeScenario( const String& rName, const String& rComment,
1951*cdf0e10cSrcweir 									const Color& rColor, sal_uInt16 nFlags )
1952*cdf0e10cSrcweir {
1953*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
1954*cdf0e10cSrcweir 	ScMarkData&	rMark	= GetViewData()->GetMarkData();
1955*cdf0e10cSrcweir 	SCTAB		nTab	= GetViewData()->GetTabNo();
1956*cdf0e10cSrcweir 
1957*cdf0e10cSrcweir 	SCTAB nNewTab = pDocSh->MakeScenario( nTab, rName, rComment, rColor, nFlags, rMark );
1958*cdf0e10cSrcweir 	if (nFlags & SC_SCENARIO_COPYALL)
1959*cdf0e10cSrcweir 		SetTabNo( nNewTab, sal_True );			// SC_SCENARIO_COPYALL -> sichtbar
1960*cdf0e10cSrcweir 	else
1961*cdf0e10cSrcweir 	{
1962*cdf0e10cSrcweir 		SfxBindings& rBindings = GetViewData()->GetBindings();
1963*cdf0e10cSrcweir 		rBindings.Invalidate( SID_STATUS_DOCPOS );		// Statusbar
1964*cdf0e10cSrcweir 		rBindings.Invalidate( SID_TABLES_COUNT );
1965*cdf0e10cSrcweir 		rBindings.Invalidate( SID_SELECT_SCENARIO );
1966*cdf0e10cSrcweir 		rBindings.Invalidate( FID_TABLE_SHOW );
1967*cdf0e10cSrcweir 	}
1968*cdf0e10cSrcweir }
1969*cdf0e10cSrcweir 
1970*cdf0e10cSrcweir 
1971*cdf0e10cSrcweir //----------------------------------------------------------------------------
1972*cdf0e10cSrcweir 
1973*cdf0e10cSrcweir void ScViewFunc::ExtendScenario()
1974*cdf0e10cSrcweir {
1975*cdf0e10cSrcweir 	ScEditableTester aTester( this );
1976*cdf0e10cSrcweir 	if (!aTester.IsEditable())
1977*cdf0e10cSrcweir 	{
1978*cdf0e10cSrcweir 		ErrorMessage(aTester.GetMessageId());
1979*cdf0e10cSrcweir 		return;
1980*cdf0e10cSrcweir 	}
1981*cdf0e10cSrcweir 
1982*cdf0e10cSrcweir 		//	Undo: Attribute anwenden
1983*cdf0e10cSrcweir 
1984*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
1985*cdf0e10cSrcweir 	ScPatternAttr aPattern( pDoc->GetPool() );
1986*cdf0e10cSrcweir 	aPattern.GetItemSet().Put( ScMergeFlagAttr( SC_MF_SCENARIO ) );
1987*cdf0e10cSrcweir 	aPattern.GetItemSet().Put( ScProtectionAttr( sal_True ) );
1988*cdf0e10cSrcweir 	ApplySelectionPattern(aPattern);
1989*cdf0e10cSrcweir }
1990*cdf0e10cSrcweir 
1991*cdf0e10cSrcweir 
1992*cdf0e10cSrcweir //----------------------------------------------------------------------------
1993*cdf0e10cSrcweir 
1994*cdf0e10cSrcweir void ScViewFunc::UseScenario( const String& rName )
1995*cdf0e10cSrcweir {
1996*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
1997*cdf0e10cSrcweir 	SCTAB		nTab	= GetViewData()->GetTabNo();
1998*cdf0e10cSrcweir 
1999*cdf0e10cSrcweir 	DoneBlockMode();
2000*cdf0e10cSrcweir 	InitOwnBlockMode();
2001*cdf0e10cSrcweir 	pDocSh->UseScenario( nTab, rName );
2002*cdf0e10cSrcweir }
2003*cdf0e10cSrcweir 
2004*cdf0e10cSrcweir 
2005*cdf0e10cSrcweir //----------------------------------------------------------------------------
2006*cdf0e10cSrcweir //	Tabelle einfuegen
2007*cdf0e10cSrcweir 
2008*cdf0e10cSrcweir sal_Bool ScViewFunc::InsertTable( const String& rName, SCTAB nTab, sal_Bool bRecord )
2009*cdf0e10cSrcweir {
2010*cdf0e10cSrcweir 	//	Reihenfolge Tabelle/Name ist bei DocFunc umgekehrt
2011*cdf0e10cSrcweir 	sal_Bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().
2012*cdf0e10cSrcweir 						InsertTable( nTab, rName, bRecord, sal_False );
2013*cdf0e10cSrcweir 	if (bSuccess)
2014*cdf0e10cSrcweir 		SetTabNo( nTab, sal_True );
2015*cdf0e10cSrcweir 
2016*cdf0e10cSrcweir 	return bSuccess;
2017*cdf0e10cSrcweir }
2018*cdf0e10cSrcweir 
2019*cdf0e10cSrcweir //----------------------------------------------------------------------------
2020*cdf0e10cSrcweir //	Tabellen einfuegen
2021*cdf0e10cSrcweir 
2022*cdf0e10cSrcweir sal_Bool ScViewFunc::InsertTables(SvStrings *pNames, SCTAB nTab,
2023*cdf0e10cSrcweir 											SCTAB nCount, sal_Bool bRecord )
2024*cdf0e10cSrcweir {
2025*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
2026*cdf0e10cSrcweir 	ScDocument* pDoc 	= pDocSh->GetDocument();
2027*cdf0e10cSrcweir 	if (bRecord && !pDoc->IsUndoEnabled())
2028*cdf0e10cSrcweir 		bRecord = sal_False;
2029*cdf0e10cSrcweir 
2030*cdf0e10cSrcweir 	SvStrings *pNameList= NULL;
2031*cdf0e10cSrcweir 
2032*cdf0e10cSrcweir 	WaitObject aWait( GetFrameWin() );
2033*cdf0e10cSrcweir 
2034*cdf0e10cSrcweir 	if (bRecord)
2035*cdf0e10cSrcweir 	{
2036*cdf0e10cSrcweir 		pNameList= new SvStrings;
2037*cdf0e10cSrcweir 		pDoc->BeginDrawUndo();							//	InsertTab erzeugt ein SdrUndoNewPage
2038*cdf0e10cSrcweir 	}
2039*cdf0e10cSrcweir 
2040*cdf0e10cSrcweir 	sal_Bool bFlag=sal_False;
2041*cdf0e10cSrcweir 
2042*cdf0e10cSrcweir 	String aValTabName;
2043*cdf0e10cSrcweir 	String *pStr;
2044*cdf0e10cSrcweir 
2045*cdf0e10cSrcweir 	for(SCTAB i=0;i<nCount;i++)
2046*cdf0e10cSrcweir 	{
2047*cdf0e10cSrcweir 		if(pNames!=NULL)
2048*cdf0e10cSrcweir 		{
2049*cdf0e10cSrcweir 			pStr=pNames->GetObject(static_cast<sal_uInt16>(i));
2050*cdf0e10cSrcweir 		}
2051*cdf0e10cSrcweir 		else
2052*cdf0e10cSrcweir 		{
2053*cdf0e10cSrcweir 			aValTabName.Erase();
2054*cdf0e10cSrcweir 			pDoc->CreateValidTabName( aValTabName);
2055*cdf0e10cSrcweir 			pStr=&aValTabName;
2056*cdf0e10cSrcweir 		}
2057*cdf0e10cSrcweir 
2058*cdf0e10cSrcweir 		if(pDoc->InsertTab( nTab+i,*pStr))
2059*cdf0e10cSrcweir 		{
2060*cdf0e10cSrcweir 			bFlag=sal_True;
2061*cdf0e10cSrcweir 			pDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab+i ) );
2062*cdf0e10cSrcweir 		}
2063*cdf0e10cSrcweir 		else
2064*cdf0e10cSrcweir 		{
2065*cdf0e10cSrcweir 			break;
2066*cdf0e10cSrcweir 		}
2067*cdf0e10cSrcweir 
2068*cdf0e10cSrcweir 		if(pNameList!=NULL)
2069*cdf0e10cSrcweir 			pNameList->Insert(new String(*pStr),pNameList->Count());
2070*cdf0e10cSrcweir 
2071*cdf0e10cSrcweir 	}
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir 	if (bFlag)
2074*cdf0e10cSrcweir 	{
2075*cdf0e10cSrcweir 		if (bRecord)
2076*cdf0e10cSrcweir 			pDocSh->GetUndoManager()->AddUndoAction(
2077*cdf0e10cSrcweir 						new ScUndoInsertTables( pDocSh, nTab, sal_False, pNameList));
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir 		//	Views updaten:
2080*cdf0e10cSrcweir 
2081*cdf0e10cSrcweir 		SetTabNo( nTab, sal_True );
2082*cdf0e10cSrcweir 		pDocSh->PostPaintExtras();
2083*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
2084*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2085*cdf0e10cSrcweir 		return sal_True;
2086*cdf0e10cSrcweir 	}
2087*cdf0e10cSrcweir 	else
2088*cdf0e10cSrcweir 	{
2089*cdf0e10cSrcweir 		return sal_False;
2090*cdf0e10cSrcweir 	}
2091*cdf0e10cSrcweir }
2092*cdf0e10cSrcweir 
2093*cdf0e10cSrcweir 
2094*cdf0e10cSrcweir //----------------------------------------------------------------------------
2095*cdf0e10cSrcweir 
2096*cdf0e10cSrcweir sal_Bool ScViewFunc::AppendTable( const String& rName, sal_Bool bRecord )
2097*cdf0e10cSrcweir {
2098*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
2099*cdf0e10cSrcweir 	ScDocument* pDoc   = pDocSh->GetDocument();
2100*cdf0e10cSrcweir 	if (bRecord && !pDoc->IsUndoEnabled())
2101*cdf0e10cSrcweir 		bRecord = sal_False;
2102*cdf0e10cSrcweir 
2103*cdf0e10cSrcweir 	WaitObject aWait( GetFrameWin() );
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir 	if (bRecord)
2106*cdf0e10cSrcweir 		pDoc->BeginDrawUndo();							//	InsertTab erzeugt ein SdrUndoNewPage
2107*cdf0e10cSrcweir 
2108*cdf0e10cSrcweir 	if (pDoc->InsertTab( SC_TAB_APPEND, rName ))
2109*cdf0e10cSrcweir 	{
2110*cdf0e10cSrcweir 		SCTAB nTab = pDoc->GetTableCount()-1;
2111*cdf0e10cSrcweir 		if (bRecord)
2112*cdf0e10cSrcweir 			pDocSh->GetUndoManager()->AddUndoAction(
2113*cdf0e10cSrcweir 						new ScUndoInsertTab( pDocSh, nTab, sal_True, rName));
2114*cdf0e10cSrcweir 		GetViewData()->InsertTab( nTab );
2115*cdf0e10cSrcweir 		SetTabNo( nTab, sal_True );
2116*cdf0e10cSrcweir 		pDocSh->PostPaintExtras();
2117*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
2118*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2119*cdf0e10cSrcweir 		return sal_True;
2120*cdf0e10cSrcweir 	}
2121*cdf0e10cSrcweir 	else
2122*cdf0e10cSrcweir 	{
2123*cdf0e10cSrcweir 		return sal_False;
2124*cdf0e10cSrcweir 	}
2125*cdf0e10cSrcweir }
2126*cdf0e10cSrcweir 
2127*cdf0e10cSrcweir 
2128*cdf0e10cSrcweir //----------------------------------------------------------------------------
2129*cdf0e10cSrcweir 
2130*cdf0e10cSrcweir sal_Bool ScViewFunc::DeleteTable( SCTAB nTab, sal_Bool bRecord )
2131*cdf0e10cSrcweir {
2132*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
2133*cdf0e10cSrcweir 	ScDocument* pDoc 	= pDocSh->GetDocument();
2134*cdf0e10cSrcweir 
2135*cdf0e10cSrcweir 	sal_Bool bSuccess = pDocSh->GetDocFunc().DeleteTable( nTab, bRecord, sal_False );
2136*cdf0e10cSrcweir 	if (bSuccess)
2137*cdf0e10cSrcweir 	{
2138*cdf0e10cSrcweir 		SCTAB nNewTab = nTab;
2139*cdf0e10cSrcweir 		if ( nNewTab >= pDoc->GetTableCount() )
2140*cdf0e10cSrcweir 			--nNewTab;
2141*cdf0e10cSrcweir 		SetTabNo( nNewTab, sal_True );
2142*cdf0e10cSrcweir 	}
2143*cdf0e10cSrcweir 	return bSuccess;
2144*cdf0e10cSrcweir }
2145*cdf0e10cSrcweir 
2146*cdf0e10cSrcweir sal_Bool ScViewFunc::DeleteTables(const SvShorts &TheTabs, sal_Bool bRecord )
2147*cdf0e10cSrcweir {
2148*cdf0e10cSrcweir 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
2149*cdf0e10cSrcweir 	ScDocument* pDoc 	= pDocSh->GetDocument();
2150*cdf0e10cSrcweir     sal_Bool bVbaEnabled = pDoc ? pDoc->IsInVBAMode() : sal_False;
2151*cdf0e10cSrcweir 	SCTAB		nNewTab = TheTabs.front();
2152*cdf0e10cSrcweir 	WaitObject aWait( GetFrameWin() );
2153*cdf0e10cSrcweir 	if (bRecord && !pDoc->IsUndoEnabled())
2154*cdf0e10cSrcweir 		bRecord = sal_False;
2155*cdf0e10cSrcweir 
2156*cdf0e10cSrcweir 	while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
2157*cdf0e10cSrcweir 		--nNewTab;
2158*cdf0e10cSrcweir 
2159*cdf0e10cSrcweir 	sal_Bool bWasLinked = sal_False;
2160*cdf0e10cSrcweir 	ScDocument* pUndoDoc = NULL;
2161*cdf0e10cSrcweir 	ScRefUndoData* pUndoData = NULL;
2162*cdf0e10cSrcweir 	if (bRecord)
2163*cdf0e10cSrcweir 	{
2164*cdf0e10cSrcweir 		pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
2165*cdf0e10cSrcweir //		pUndoDoc->InitDrawLayer( pDocSh );
2166*cdf0e10cSrcweir 		SCTAB nCount = pDoc->GetTableCount();
2167*cdf0e10cSrcweir 
2168*cdf0e10cSrcweir //		pUndoDoc->InitUndo( pDoc, 0, nCount-1 );		// incl. Ref.
2169*cdf0e10cSrcweir 
2170*cdf0e10cSrcweir 		String aOldName;
2171*cdf0e10cSrcweir         for (size_t i = 0; i < TheTabs.size(); i++)
2172*cdf0e10cSrcweir         {
2173*cdf0e10cSrcweir             SCTAB nTab = TheTabs[i];
2174*cdf0e10cSrcweir 			if (i==0)
2175*cdf0e10cSrcweir 				pUndoDoc->InitUndo( pDoc, nTab,nTab, sal_True,sal_True );	// incl. Spalten/Zeilenflags
2176*cdf0e10cSrcweir 			else
2177*cdf0e10cSrcweir 				pUndoDoc->AddUndoTab( nTab,nTab, sal_True,sal_True );		// incl. Spalten/Zeilenflags
2178*cdf0e10cSrcweir 
2179*cdf0e10cSrcweir 			pDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,sal_False, pUndoDoc );
2180*cdf0e10cSrcweir 			pDoc->GetName( nTab, aOldName );
2181*cdf0e10cSrcweir 			pUndoDoc->RenameTab( nTab, aOldName, sal_False );
2182*cdf0e10cSrcweir 			if (pDoc->IsLinked(nTab))
2183*cdf0e10cSrcweir 			{
2184*cdf0e10cSrcweir 				bWasLinked = sal_True;
2185*cdf0e10cSrcweir 				pUndoDoc->SetLink( nTab, pDoc->GetLinkMode(nTab), pDoc->GetLinkDoc(nTab),
2186*cdf0e10cSrcweir 									pDoc->GetLinkFlt(nTab), pDoc->GetLinkOpt(nTab),
2187*cdf0e10cSrcweir 									pDoc->GetLinkTab(nTab),
2188*cdf0e10cSrcweir 									pDoc->GetLinkRefreshDelay(nTab) );
2189*cdf0e10cSrcweir 			}
2190*cdf0e10cSrcweir 			if ( pDoc->IsScenario(nTab) )
2191*cdf0e10cSrcweir 			{
2192*cdf0e10cSrcweir 				pUndoDoc->SetScenario( nTab, sal_True );
2193*cdf0e10cSrcweir 				String aComment;
2194*cdf0e10cSrcweir 				Color  aColor;
2195*cdf0e10cSrcweir 				sal_uInt16 nScenFlags;
2196*cdf0e10cSrcweir 				pDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
2197*cdf0e10cSrcweir 				pUndoDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
2198*cdf0e10cSrcweir 				sal_Bool bActive = pDoc->IsActiveScenario( nTab );
2199*cdf0e10cSrcweir 				pUndoDoc->SetActiveScenario( nTab, bActive );
2200*cdf0e10cSrcweir 			}
2201*cdf0e10cSrcweir 			pUndoDoc->SetVisible( nTab, pDoc->IsVisible( nTab ) );
2202*cdf0e10cSrcweir             pUndoDoc->SetTabBgColor( nTab, pDoc->GetTabBgColor(nTab) );
2203*cdf0e10cSrcweir             pUndoDoc->SetSheetEvents( nTab, pDoc->GetSheetEvents( nTab ) );
2204*cdf0e10cSrcweir 
2205*cdf0e10cSrcweir 			if ( pDoc->IsTabProtected( nTab ) )
2206*cdf0e10cSrcweir                 pUndoDoc->SetTabProtection(nTab, pDoc->GetTabProtection(nTab));
2207*cdf0e10cSrcweir 
2208*cdf0e10cSrcweir 			//	Drawing-Layer muss sein Undo selbst in der Hand behalten !!!
2209*cdf0e10cSrcweir 			//		pUndoDoc->TransferDrawPage(pDoc, nTab,nTab);
2210*cdf0e10cSrcweir 		}
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir 		pUndoDoc->AddUndoTab( 0, nCount-1 );			//	alle Tabs fuer Referenzen
2213*cdf0e10cSrcweir 
2214*cdf0e10cSrcweir 		pDoc->BeginDrawUndo();							//	DeleteTab erzeugt ein SdrUndoDelPage
2215*cdf0e10cSrcweir 
2216*cdf0e10cSrcweir 		pUndoData = new ScRefUndoData( pDoc );
2217*cdf0e10cSrcweir 	}
2218*cdf0e10cSrcweir 
2219*cdf0e10cSrcweir 	sal_Bool bDelDone = sal_False;
2220*cdf0e10cSrcweir 
2221*cdf0e10cSrcweir     for (size_t i = TheTabs.size(); i > 0; i--)
2222*cdf0e10cSrcweir     {
2223*cdf0e10cSrcweir         String sCodeName;
2224*cdf0e10cSrcweir         sal_Bool bHasCodeName = pDoc->GetCodeName( TheTabs[i-1], sCodeName );
2225*cdf0e10cSrcweir         if (pDoc->DeleteTab( TheTabs[i-1], pUndoDoc ))
2226*cdf0e10cSrcweir 		{
2227*cdf0e10cSrcweir 			bDelDone = sal_True;
2228*cdf0e10cSrcweir             if( bVbaEnabled )
2229*cdf0e10cSrcweir             {
2230*cdf0e10cSrcweir                 if( bHasCodeName )
2231*cdf0e10cSrcweir                 {
2232*cdf0e10cSrcweir                     VBA_DeleteModule( *pDocSh, sCodeName );
2233*cdf0e10cSrcweir                 }
2234*cdf0e10cSrcweir             }
2235*cdf0e10cSrcweir             pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[i-1] ) );
2236*cdf0e10cSrcweir 		}
2237*cdf0e10cSrcweir 	}
2238*cdf0e10cSrcweir 	if (bRecord)
2239*cdf0e10cSrcweir 	{
2240*cdf0e10cSrcweir 		pDocSh->GetUndoManager()->AddUndoAction(
2241*cdf0e10cSrcweir 					new ScUndoDeleteTab( GetViewData()->GetDocShell(), TheTabs,
2242*cdf0e10cSrcweir 											pUndoDoc, pUndoData ));
2243*cdf0e10cSrcweir 	}
2244*cdf0e10cSrcweir 
2245*cdf0e10cSrcweir 
2246*cdf0e10cSrcweir 	if (bDelDone)
2247*cdf0e10cSrcweir 	{
2248*cdf0e10cSrcweir 		if ( nNewTab >= pDoc->GetTableCount() )
2249*cdf0e10cSrcweir 			nNewTab = pDoc->GetTableCount() - 1;
2250*cdf0e10cSrcweir 
2251*cdf0e10cSrcweir 		SetTabNo( nNewTab, sal_True );
2252*cdf0e10cSrcweir 
2253*cdf0e10cSrcweir 		if (bWasLinked)
2254*cdf0e10cSrcweir 		{
2255*cdf0e10cSrcweir 			pDocSh->UpdateLinks();				// Link-Manager updaten
2256*cdf0e10cSrcweir 			GetViewData()->GetBindings().Invalidate(SID_LINKS);
2257*cdf0e10cSrcweir 		}
2258*cdf0e10cSrcweir 
2259*cdf0e10cSrcweir 		pDocSh->PostPaintExtras();
2260*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
2261*cdf0e10cSrcweir 
2262*cdf0e10cSrcweir         SfxApplication* pSfxApp = SFX_APP();                                // Navigator
2263*cdf0e10cSrcweir         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2264*cdf0e10cSrcweir         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
2265*cdf0e10cSrcweir         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
2266*cdf0e10cSrcweir 	}
2267*cdf0e10cSrcweir 	else
2268*cdf0e10cSrcweir 	{
2269*cdf0e10cSrcweir 		delete pUndoDoc;
2270*cdf0e10cSrcweir 		delete pUndoData;
2271*cdf0e10cSrcweir 	}
2272*cdf0e10cSrcweir 	return bDelDone;
2273*cdf0e10cSrcweir }
2274*cdf0e10cSrcweir 
2275*cdf0e10cSrcweir 
2276*cdf0e10cSrcweir //----------------------------------------------------------------------------
2277*cdf0e10cSrcweir 
2278*cdf0e10cSrcweir sal_Bool ScViewFunc::RenameTable( const String& rName, SCTAB nTab )
2279*cdf0e10cSrcweir {
2280*cdf0e10cSrcweir 	//	Reihenfolge Tabelle/Name ist bei DocFunc umgekehrt
2281*cdf0e10cSrcweir 	sal_Bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().
2282*cdf0e10cSrcweir 						RenameTable( nTab, rName, sal_True, sal_False );
2283*cdf0e10cSrcweir 	if (bSuccess)
2284*cdf0e10cSrcweir 	{
2285*cdf0e10cSrcweir 		//	Der Tabellenname koennte in einer Formel vorkommen...
2286*cdf0e10cSrcweir 		GetViewData()->GetViewShell()->UpdateInputHandler();
2287*cdf0e10cSrcweir 	}
2288*cdf0e10cSrcweir 	return bSuccess;
2289*cdf0e10cSrcweir }
2290*cdf0e10cSrcweir 
2291*cdf0e10cSrcweir 
2292*cdf0e10cSrcweir //----------------------------------------------------------------------------
2293*cdf0e10cSrcweir 
2294*cdf0e10cSrcweir bool ScViewFunc::SetTabBgColor( const Color& rColor, SCTAB nTab )
2295*cdf0e10cSrcweir {
2296*cdf0e10cSrcweir     bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( nTab, rColor, sal_True, sal_False );
2297*cdf0e10cSrcweir     if (bSuccess)
2298*cdf0e10cSrcweir     {
2299*cdf0e10cSrcweir         GetViewData()->GetViewShell()->UpdateInputHandler();
2300*cdf0e10cSrcweir     }
2301*cdf0e10cSrcweir     return bSuccess;
2302*cdf0e10cSrcweir }
2303*cdf0e10cSrcweir 
2304*cdf0e10cSrcweir bool ScViewFunc::SetTabBgColor( ScUndoTabColorInfo::List& rUndoSetTabBgColorInfoList )
2305*cdf0e10cSrcweir {
2306*cdf0e10cSrcweir     bool bSuccess = GetViewData()->GetDocShell()->GetDocFunc().SetTabBgColor( rUndoSetTabBgColorInfoList, sal_True, sal_False );
2307*cdf0e10cSrcweir     if (bSuccess)
2308*cdf0e10cSrcweir     {
2309*cdf0e10cSrcweir         GetViewData()->GetViewShell()->UpdateInputHandler();
2310*cdf0e10cSrcweir     }
2311*cdf0e10cSrcweir     return bSuccess;
2312*cdf0e10cSrcweir }
2313*cdf0e10cSrcweir 
2314*cdf0e10cSrcweir //----------------------------------------------------------------------------
2315*cdf0e10cSrcweir 
2316*cdf0e10cSrcweir void ScViewFunc::InsertAreaLink( const String& rFile,
2317*cdf0e10cSrcweir 									const String& rFilter, const String& rOptions,
2318*cdf0e10cSrcweir 									const String& rSource, sal_uLong nRefresh )
2319*cdf0e10cSrcweir {
2320*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
2321*cdf0e10cSrcweir 	SCCOL nPosX = GetViewData()->GetCurX();
2322*cdf0e10cSrcweir 	SCROW nPosY = GetViewData()->GetCurY();
2323*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
2324*cdf0e10cSrcweir 	ScAddress aPos( nPosX, nPosY, nTab );
2325*cdf0e10cSrcweir 
2326*cdf0e10cSrcweir     pDocSh->GetDocFunc().InsertAreaLink( rFile, rFilter, rOptions, rSource, aPos, nRefresh, sal_False, sal_False );
2327*cdf0e10cSrcweir }
2328*cdf0e10cSrcweir 
2329*cdf0e10cSrcweir 
2330*cdf0e10cSrcweir //----------------------------------------------------------------------------
2331*cdf0e10cSrcweir 
2332*cdf0e10cSrcweir void ScViewFunc::InsertTableLink( const String& rFile,
2333*cdf0e10cSrcweir 									const String& rFilter, const String& rOptions,
2334*cdf0e10cSrcweir 									const String& rTabName )
2335*cdf0e10cSrcweir {
2336*cdf0e10cSrcweir 	String aFilterName = rFilter;
2337*cdf0e10cSrcweir 	String aOpt = rOptions;
2338*cdf0e10cSrcweir 	ScDocumentLoader aLoader( rFile, aFilterName, aOpt );
2339*cdf0e10cSrcweir 	if (!aLoader.IsError())
2340*cdf0e10cSrcweir 	{
2341*cdf0e10cSrcweir 		ScDocShell* pSrcSh = aLoader.GetDocShell();
2342*cdf0e10cSrcweir 		ScDocument* pSrcDoc = pSrcSh->GetDocument();
2343*cdf0e10cSrcweir 		SCTAB nTab = MAXTAB+1;
2344*cdf0e10cSrcweir 		if (!rTabName.Len())				// kein Name angegeben -> erste Tabelle
2345*cdf0e10cSrcweir 			nTab = 0;
2346*cdf0e10cSrcweir 		else
2347*cdf0e10cSrcweir 		{
2348*cdf0e10cSrcweir 			String aTemp;
2349*cdf0e10cSrcweir 			SCTAB nCount = pSrcDoc->GetTableCount();
2350*cdf0e10cSrcweir 			for (SCTAB i=0; i<nCount; i++)
2351*cdf0e10cSrcweir 			{
2352*cdf0e10cSrcweir 				pSrcDoc->GetName( i, aTemp );
2353*cdf0e10cSrcweir 				if ( aTemp == rTabName )
2354*cdf0e10cSrcweir 					nTab = i;
2355*cdf0e10cSrcweir 			}
2356*cdf0e10cSrcweir 		}
2357*cdf0e10cSrcweir 
2358*cdf0e10cSrcweir 		if ( nTab <= MAXTAB )
2359*cdf0e10cSrcweir 			ImportTables( pSrcSh, 1, &nTab, sal_True,
2360*cdf0e10cSrcweir 						GetViewData()->GetTabNo() );
2361*cdf0e10cSrcweir 	}
2362*cdf0e10cSrcweir }
2363*cdf0e10cSrcweir 
2364*cdf0e10cSrcweir 
2365*cdf0e10cSrcweir //----------------------------------------------------------------------------
2366*cdf0e10cSrcweir //	Tabellen aus anderem Dokument kopieren / linken
2367*cdf0e10cSrcweir 
2368*cdf0e10cSrcweir void ScViewFunc::ImportTables( ScDocShell* pSrcShell,
2369*cdf0e10cSrcweir 								SCTAB nCount, const SCTAB* pSrcTabs, sal_Bool bLink,SCTAB nTab )
2370*cdf0e10cSrcweir {
2371*cdf0e10cSrcweir 	ScDocument* pSrcDoc = pSrcShell->GetDocument();
2372*cdf0e10cSrcweir 
2373*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
2374*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
2375*cdf0e10cSrcweir 	sal_Bool bUndo(pDoc->IsUndoEnabled());
2376*cdf0e10cSrcweir 	//SCTAB nTab = GetViewData()->GetTabNo();
2377*cdf0e10cSrcweir 
2378*cdf0e10cSrcweir 	sal_Bool bError = sal_False;
2379*cdf0e10cSrcweir 	sal_Bool bRefs = sal_False;
2380*cdf0e10cSrcweir 	sal_Bool bName = sal_False;
2381*cdf0e10cSrcweir 
2382*cdf0e10cSrcweir 	if (pSrcDoc->GetDrawLayer())
2383*cdf0e10cSrcweir 		pDocSh->MakeDrawLayer();
2384*cdf0e10cSrcweir 
2385*cdf0e10cSrcweir 	if (bUndo)
2386*cdf0e10cSrcweir 		pDoc->BeginDrawUndo();			// drawing layer must do its own undo actions
2387*cdf0e10cSrcweir 
2388*cdf0e10cSrcweir 	SCTAB nInsCount = 0;
2389*cdf0e10cSrcweir 	SCTAB i;
2390*cdf0e10cSrcweir 	for( i=0; i<nCount; i++ )
2391*cdf0e10cSrcweir 	{	// #63304# insert sheets first and update all references
2392*cdf0e10cSrcweir 		String aName;
2393*cdf0e10cSrcweir 		pSrcDoc->GetName( pSrcTabs[i], aName );
2394*cdf0e10cSrcweir 		pDoc->CreateValidTabName( aName );
2395*cdf0e10cSrcweir 		if ( !pDoc->InsertTab( nTab+i, aName ) )
2396*cdf0e10cSrcweir 		{
2397*cdf0e10cSrcweir 			bError = sal_True;		// total error
2398*cdf0e10cSrcweir 			break;	// for
2399*cdf0e10cSrcweir 		}
2400*cdf0e10cSrcweir 		++nInsCount;
2401*cdf0e10cSrcweir 	}
2402*cdf0e10cSrcweir 	for (i=0; i<nCount && !bError; i++)
2403*cdf0e10cSrcweir 	{
2404*cdf0e10cSrcweir 		SCTAB nSrcTab = pSrcTabs[i];
2405*cdf0e10cSrcweir 		SCTAB nDestTab1=nTab+i;
2406*cdf0e10cSrcweir 		sal_uLong nErrVal = pDoc->TransferTab( pSrcDoc, nSrcTab, nDestTab1,
2407*cdf0e10cSrcweir 			sal_False );		// no insert
2408*cdf0e10cSrcweir 
2409*cdf0e10cSrcweir 		switch (nErrVal)
2410*cdf0e10cSrcweir 		{
2411*cdf0e10cSrcweir 			case 0:						// interner Fehler oder voll Fehler
2412*cdf0e10cSrcweir 				bError = sal_True;
2413*cdf0e10cSrcweir 				break;
2414*cdf0e10cSrcweir 			case 2:
2415*cdf0e10cSrcweir 				bRefs = sal_True;
2416*cdf0e10cSrcweir 				break;
2417*cdf0e10cSrcweir 			case 3:
2418*cdf0e10cSrcweir 				bName = sal_True;
2419*cdf0e10cSrcweir 				break;
2420*cdf0e10cSrcweir 			case 4:
2421*cdf0e10cSrcweir 				bRefs = bName = sal_True;
2422*cdf0e10cSrcweir 				break;
2423*cdf0e10cSrcweir 		}
2424*cdf0e10cSrcweir 
2425*cdf0e10cSrcweir 		// TransferTab doesn't copy drawing objects with bInsertNew=FALSE
2426*cdf0e10cSrcweir 		if ( !bError )
2427*cdf0e10cSrcweir 			pDoc->TransferDrawPage( pSrcDoc, nSrcTab, nDestTab1 );
2428*cdf0e10cSrcweir 
2429*cdf0e10cSrcweir 		if(!bError &&pSrcDoc->IsScenario(nSrcTab))
2430*cdf0e10cSrcweir 		{
2431*cdf0e10cSrcweir 			String aComment;
2432*cdf0e10cSrcweir 			Color  aColor;
2433*cdf0e10cSrcweir 			sal_uInt16 nFlags;
2434*cdf0e10cSrcweir 
2435*cdf0e10cSrcweir 			pSrcDoc->GetScenarioData(nSrcTab, aComment,aColor, nFlags);
2436*cdf0e10cSrcweir 			pDoc->SetScenario( nDestTab1,sal_True);
2437*cdf0e10cSrcweir 			pDoc->SetScenarioData( nTab+i,aComment,aColor,nFlags);
2438*cdf0e10cSrcweir 			sal_Bool bActive = pSrcDoc->IsActiveScenario(nSrcTab );
2439*cdf0e10cSrcweir 			pDoc->SetActiveScenario( nDestTab1, bActive );
2440*cdf0e10cSrcweir 			sal_Bool bVisible=pSrcDoc->IsVisible(nSrcTab);
2441*cdf0e10cSrcweir 			pDoc->SetVisible(nDestTab1,bVisible );
2442*cdf0e10cSrcweir 
2443*cdf0e10cSrcweir 		}
2444*cdf0e10cSrcweir 	}
2445*cdf0e10cSrcweir 
2446*cdf0e10cSrcweir 	if (bLink)
2447*cdf0e10cSrcweir 	{
2448*cdf0e10cSrcweir 		sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
2449*cdf0e10cSrcweir 
2450*cdf0e10cSrcweir 		SfxMedium* pMed = pSrcShell->GetMedium();
2451*cdf0e10cSrcweir 		String aFileName = pMed->GetName();
2452*cdf0e10cSrcweir 		String aFilterName;
2453*cdf0e10cSrcweir 		if (pMed->GetFilter())
2454*cdf0e10cSrcweir 			aFilterName = pMed->GetFilter()->GetFilterName();
2455*cdf0e10cSrcweir 		String aOptions = ScDocumentLoader::GetOptions(*pMed);
2456*cdf0e10cSrcweir 
2457*cdf0e10cSrcweir 		sal_Bool bWasThere = pDoc->HasLink( aFileName, aFilterName, aOptions );
2458*cdf0e10cSrcweir 
2459*cdf0e10cSrcweir 		sal_uLong nRefresh = 0;
2460*cdf0e10cSrcweir 		String aTabStr;
2461*cdf0e10cSrcweir 		for (i=0; i<nInsCount; i++)
2462*cdf0e10cSrcweir 		{
2463*cdf0e10cSrcweir 			pSrcDoc->GetName( pSrcTabs[i], aTabStr );
2464*cdf0e10cSrcweir 			pDoc->SetLink( nTab+i, SC_LINK_NORMAL,
2465*cdf0e10cSrcweir 						aFileName, aFilterName, aOptions, aTabStr, nRefresh );
2466*cdf0e10cSrcweir 		}
2467*cdf0e10cSrcweir 
2468*cdf0e10cSrcweir 		if (!bWasThere)			// Link pro Quelldokument nur einmal eintragen
2469*cdf0e10cSrcweir 		{
2470*cdf0e10cSrcweir 			ScTableLink* pLink = new ScTableLink( pDocSh, aFileName, aFilterName, aOptions, nRefresh );
2471*cdf0e10cSrcweir 			pLink->SetInCreate( sal_True );
2472*cdf0e10cSrcweir 			pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aFileName, &aFilterName );
2473*cdf0e10cSrcweir 			pLink->Update();
2474*cdf0e10cSrcweir 			pLink->SetInCreate( sal_False );
2475*cdf0e10cSrcweir 
2476*cdf0e10cSrcweir 			SfxBindings& rBindings = GetViewData()->GetBindings();
2477*cdf0e10cSrcweir 			rBindings.Invalidate( SID_LINKS );
2478*cdf0e10cSrcweir 		}
2479*cdf0e10cSrcweir 	}
2480*cdf0e10cSrcweir 
2481*cdf0e10cSrcweir 
2482*cdf0e10cSrcweir 	if (bUndo)
2483*cdf0e10cSrcweir 	{
2484*cdf0e10cSrcweir 		pDocSh->GetUndoManager()->AddUndoAction(
2485*cdf0e10cSrcweir 				new ScUndoImportTab( pDocSh, nTab, nCount, bLink ) );
2486*cdf0e10cSrcweir 	}
2487*cdf0e10cSrcweir 
2488*cdf0e10cSrcweir 	for (i=0; i<nInsCount; i++)
2489*cdf0e10cSrcweir 		GetViewData()->InsertTab(nTab);
2490*cdf0e10cSrcweir 	SetTabNo(nTab,sal_True);
2491*cdf0e10cSrcweir 	pDocSh->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
2492*cdf0e10cSrcweir 								PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
2493*cdf0e10cSrcweir 
2494*cdf0e10cSrcweir 	SfxApplication* pSfxApp = SFX_APP();
2495*cdf0e10cSrcweir 	pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2496*cdf0e10cSrcweir 	pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
2497*cdf0e10cSrcweir 
2498*cdf0e10cSrcweir 	pDocSh->PostPaintExtras();
2499*cdf0e10cSrcweir 	pDocSh->PostPaintGridAll();
2500*cdf0e10cSrcweir 	pDocSh->SetDocumentModified();
2501*cdf0e10cSrcweir 
2502*cdf0e10cSrcweir 	if (bRefs)
2503*cdf0e10cSrcweir 		ErrorMessage(STR_ABSREFLOST);
2504*cdf0e10cSrcweir 	if (bName)
2505*cdf0e10cSrcweir 		ErrorMessage(STR_NAMECONFLICT);
2506*cdf0e10cSrcweir }
2507*cdf0e10cSrcweir 
2508*cdf0e10cSrcweir 
2509*cdf0e10cSrcweir //----------------------------------------------------------------------------
2510*cdf0e10cSrcweir //	Tabelle in anderes Dokument verschieben / kopieren
2511*cdf0e10cSrcweir 
2512*cdf0e10cSrcweir void ScViewFunc::MoveTable( sal_uInt16 nDestDocNo, SCTAB nDestTab, sal_Bool bCopy )
2513*cdf0e10cSrcweir {
2514*cdf0e10cSrcweir 	ScDocument* pDoc	   = GetViewData()->GetDocument();
2515*cdf0e10cSrcweir 	ScDocShell* pDocShell  = GetViewData()->GetDocShell();
2516*cdf0e10cSrcweir 	ScDocument*	pDestDoc   = NULL;
2517*cdf0e10cSrcweir 	ScDocShell* pDestShell = NULL;
2518*cdf0e10cSrcweir 	ScTabViewShell* pDestViewSh = NULL;
2519*cdf0e10cSrcweir 	sal_Bool bUndo (pDoc->IsUndoEnabled());
2520*cdf0e10cSrcweir 
2521*cdf0e10cSrcweir 	sal_Bool bNewDoc = ( nDestDocNo == SC_DOC_NEW );
2522*cdf0e10cSrcweir 	if ( bNewDoc )
2523*cdf0e10cSrcweir 	{
2524*cdf0e10cSrcweir         nDestTab = 0;           // als erstes einfuegen
2525*cdf0e10cSrcweir 
2526*cdf0e10cSrcweir 		//	ohne SFX_CALLMODE_RECORD ausfuehren, weil schon im Move-Befehl enthalten:
2527*cdf0e10cSrcweir 
2528*cdf0e10cSrcweir 		String aUrl = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("private:factory/"));
2529*cdf0e10cSrcweir 		aUrl.AppendAscii(RTL_CONSTASCII_STRINGPARAM( STRING_SCAPP ));				// "scalc"
2530*cdf0e10cSrcweir 		SfxStringItem aItem( SID_FILE_NAME, aUrl );
2531*cdf0e10cSrcweir 		SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") );
2532*cdf0e10cSrcweir 
2533*cdf0e10cSrcweir 		const SfxPoolItem* pRetItem = GetViewData()->GetDispatcher().Execute(
2534*cdf0e10cSrcweir 					SID_OPENDOC, SFX_CALLMODE_API|SFX_CALLMODE_SYNCHRON, &aItem, &aTarget, 0L );
2535*cdf0e10cSrcweir 		if ( pRetItem )
2536*cdf0e10cSrcweir 		{
2537*cdf0e10cSrcweir 			if ( pRetItem->ISA( SfxObjectItem ) )
2538*cdf0e10cSrcweir 				pDestShell = PTR_CAST( ScDocShell, ((const SfxObjectItem*)pRetItem)->GetShell() );
2539*cdf0e10cSrcweir 			else if ( pRetItem->ISA( SfxViewFrameItem ) )
2540*cdf0e10cSrcweir 			{
2541*cdf0e10cSrcweir 				SfxViewFrame* pFrm = ((const SfxViewFrameItem*)pRetItem)->GetFrame();
2542*cdf0e10cSrcweir 				if (pFrm)
2543*cdf0e10cSrcweir 					pDestShell = PTR_CAST( ScDocShell, pFrm->GetObjectShell() );
2544*cdf0e10cSrcweir 			}
2545*cdf0e10cSrcweir 			if (pDestShell)
2546*cdf0e10cSrcweir 				pDestViewSh = pDestShell->GetBestViewShell();
2547*cdf0e10cSrcweir 		}
2548*cdf0e10cSrcweir 	}
2549*cdf0e10cSrcweir 	else
2550*cdf0e10cSrcweir 		pDestShell = ScDocShell::GetShellByNum( nDestDocNo );
2551*cdf0e10cSrcweir 
2552*cdf0e10cSrcweir 	if (!pDestShell)
2553*cdf0e10cSrcweir 	{
2554*cdf0e10cSrcweir 		DBG_ERROR("Dest-Doc nicht gefunden !!!");
2555*cdf0e10cSrcweir 		return;
2556*cdf0e10cSrcweir 	}
2557*cdf0e10cSrcweir 
2558*cdf0e10cSrcweir 	pDestDoc = pDestShell->GetDocument();
2559*cdf0e10cSrcweir 
2560*cdf0e10cSrcweir 	SCTAB nTab = GetViewData()->GetTabNo();
2561*cdf0e10cSrcweir 
2562*cdf0e10cSrcweir 	if (pDestDoc != pDoc)
2563*cdf0e10cSrcweir 	{
2564*cdf0e10cSrcweir 		if (bNewDoc)
2565*cdf0e10cSrcweir 		{
2566*cdf0e10cSrcweir 			while (pDestDoc->GetTableCount() > 1)
2567*cdf0e10cSrcweir 				pDestDoc->DeleteTab(0);
2568*cdf0e10cSrcweir 			pDestDoc->RenameTab( 0,
2569*cdf0e10cSrcweir 						String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("______42_____")),
2570*cdf0e10cSrcweir 						sal_False );
2571*cdf0e10cSrcweir 		}
2572*cdf0e10cSrcweir 
2573*cdf0e10cSrcweir 		ScMarkData& rMark		= GetViewData()->GetMarkData();
2574*cdf0e10cSrcweir 		SCTAB		nTabCount	= pDoc->GetTableCount();
2575*cdf0e10cSrcweir 		SCTAB		nTabSelCount = rMark.GetSelectCount();
2576*cdf0e10cSrcweir 
2577*cdf0e10cSrcweir 		SvShorts	TheTabs;
2578*cdf0e10cSrcweir 
2579*cdf0e10cSrcweir 		for(SCTAB i=0;i<nTabCount;i++)
2580*cdf0e10cSrcweir 		{
2581*cdf0e10cSrcweir 			if(rMark.GetTableSelect(i))
2582*cdf0e10cSrcweir 			{
2583*cdf0e10cSrcweir 				String aTabName;
2584*cdf0e10cSrcweir 				pDoc->GetName( i, aTabName);
2585*cdf0e10cSrcweir 				TheTabs.push_back(i);
2586*cdf0e10cSrcweir 				for(SCTAB j=i+1;j<nTabCount;j++)
2587*cdf0e10cSrcweir 				{
2588*cdf0e10cSrcweir 					if((!pDoc->IsVisible(j))&&(pDoc->IsScenario(j)))
2589*cdf0e10cSrcweir 					{
2590*cdf0e10cSrcweir 						pDoc->GetName( j, aTabName);
2591*cdf0e10cSrcweir 						TheTabs.push_back(j);
2592*cdf0e10cSrcweir 						i=j;
2593*cdf0e10cSrcweir 					}
2594*cdf0e10cSrcweir 					else break;
2595*cdf0e10cSrcweir 				}
2596*cdf0e10cSrcweir 			}
2597*cdf0e10cSrcweir 		}
2598*cdf0e10cSrcweir 
2599*cdf0e10cSrcweir 		GetFrameWin()->EnterWait();
2600*cdf0e10cSrcweir 
2601*cdf0e10cSrcweir 		if (pDoc->GetDrawLayer())
2602*cdf0e10cSrcweir 			pDestShell->MakeDrawLayer();
2603*cdf0e10cSrcweir 
2604*cdf0e10cSrcweir 		if (!bNewDoc && bUndo)
2605*cdf0e10cSrcweir 			pDestDoc->BeginDrawUndo();		// drawing layer must do its own undo actions
2606*cdf0e10cSrcweir 
2607*cdf0e10cSrcweir 		sal_uLong nErrVal =1;
2608*cdf0e10cSrcweir 		if(nDestTab==SC_TAB_APPEND)
2609*cdf0e10cSrcweir             nDestTab=pDestDoc->GetTableCount();
2610*cdf0e10cSrcweir 		SCTAB nDestTab1=nDestTab;
2611*cdf0e10cSrcweir 		for( size_t j=0; j<TheTabs.size(); j++, nDestTab1++ )
2612*cdf0e10cSrcweir 		{	// #63304# insert sheets first and update all references
2613*cdf0e10cSrcweir 			String aName;
2614*cdf0e10cSrcweir 			pDoc->GetName( TheTabs[j], aName );
2615*cdf0e10cSrcweir 			pDestDoc->CreateValidTabName( aName );
2616*cdf0e10cSrcweir 			if ( !pDestDoc->InsertTab( nDestTab1, aName ) )
2617*cdf0e10cSrcweir 			{
2618*cdf0e10cSrcweir 				nErrVal = 0;		// total error
2619*cdf0e10cSrcweir 				break;	// for
2620*cdf0e10cSrcweir 			}
2621*cdf0e10cSrcweir 		}
2622*cdf0e10cSrcweir 		if ( nErrVal > 0 )
2623*cdf0e10cSrcweir 		{
2624*cdf0e10cSrcweir 			nDestTab1 = nDestTab;
2625*cdf0e10cSrcweir 			for(size_t i=0;i<TheTabs.size();i++)
2626*cdf0e10cSrcweir 			{
2627*cdf0e10cSrcweir 				nErrVal = pDestDoc->TransferTab( pDoc, TheTabs[i], nDestTab1,
2628*cdf0e10cSrcweir 					sal_False );		// no insert
2629*cdf0e10cSrcweir 
2630*cdf0e10cSrcweir 				// TransferTab doesn't copy drawing objects with bInsertNew=FALSE
2631*cdf0e10cSrcweir 				if ( nErrVal > 0 )
2632*cdf0e10cSrcweir 					pDestDoc->TransferDrawPage( pDoc, TheTabs[i], nDestTab1 );
2633*cdf0e10cSrcweir 
2634*cdf0e10cSrcweir 				if(nErrVal>0 && pDoc->IsScenario(TheTabs[i]))
2635*cdf0e10cSrcweir 				{
2636*cdf0e10cSrcweir 					String aComment;
2637*cdf0e10cSrcweir 					Color  aColor;
2638*cdf0e10cSrcweir 					sal_uInt16 nFlags;
2639*cdf0e10cSrcweir 
2640*cdf0e10cSrcweir 					pDoc->GetScenarioData(TheTabs[i], aComment,aColor, nFlags);
2641*cdf0e10cSrcweir 					pDestDoc->SetScenario(nDestTab1,sal_True);
2642*cdf0e10cSrcweir 					pDestDoc->SetScenarioData(nDestTab1,aComment,aColor,nFlags);
2643*cdf0e10cSrcweir 					sal_Bool bActive = pDoc->IsActiveScenario(TheTabs[i]);
2644*cdf0e10cSrcweir 					pDestDoc->SetActiveScenario(nDestTab1, bActive );
2645*cdf0e10cSrcweir 
2646*cdf0e10cSrcweir 					sal_Bool bVisible=pDoc->IsVisible(TheTabs[i]);
2647*cdf0e10cSrcweir 					pDestDoc->SetVisible(nDestTab1,bVisible );
2648*cdf0e10cSrcweir 
2649*cdf0e10cSrcweir 				}
2650*cdf0e10cSrcweir 
2651*cdf0e10cSrcweir 				if ( nErrVal > 0 && pDoc->IsTabProtected( TheTabs[i] ) )
2652*cdf0e10cSrcweir                     pDestDoc->SetTabProtection(nDestTab1, pDoc->GetTabProtection(TheTabs[i]));
2653*cdf0e10cSrcweir 
2654*cdf0e10cSrcweir 				nDestTab1++;
2655*cdf0e10cSrcweir 			}
2656*cdf0e10cSrcweir 		}
2657*cdf0e10cSrcweir 		String sName;
2658*cdf0e10cSrcweir 		if (!bNewDoc && bUndo)
2659*cdf0e10cSrcweir 		{
2660*cdf0e10cSrcweir 			pDestDoc->GetName(nDestTab, sName);
2661*cdf0e10cSrcweir 			pDestShell->GetUndoManager()->AddUndoAction(
2662*cdf0e10cSrcweir                             new ScUndoImportTab( pDestShell, nDestTab,
2663*cdf0e10cSrcweir                                 static_cast<SCTAB>(TheTabs.size()), sal_False));
2664*cdf0e10cSrcweir 
2665*cdf0e10cSrcweir 		}
2666*cdf0e10cSrcweir 		else
2667*cdf0e10cSrcweir 		{
2668*cdf0e10cSrcweir 			pDestShell->GetUndoManager()->Clear();
2669*cdf0e10cSrcweir 		}
2670*cdf0e10cSrcweir 
2671*cdf0e10cSrcweir 		GetFrameWin()->LeaveWait();
2672*cdf0e10cSrcweir 		switch (nErrVal)
2673*cdf0e10cSrcweir 		{
2674*cdf0e10cSrcweir 			case 0:						// interner Fehler oder voll Fehler
2675*cdf0e10cSrcweir 			{
2676*cdf0e10cSrcweir 				ErrorMessage(STR_TABINSERT_ERROR);
2677*cdf0e10cSrcweir 				return;
2678*cdf0e10cSrcweir 			}
2679*cdf0e10cSrcweir             //break;
2680*cdf0e10cSrcweir 			case 2:
2681*cdf0e10cSrcweir 				ErrorMessage(STR_ABSREFLOST);
2682*cdf0e10cSrcweir 			break;
2683*cdf0e10cSrcweir 			case 3:
2684*cdf0e10cSrcweir 				ErrorMessage(STR_NAMECONFLICT);
2685*cdf0e10cSrcweir 			break;
2686*cdf0e10cSrcweir 			case 4:
2687*cdf0e10cSrcweir 			{
2688*cdf0e10cSrcweir 				ErrorMessage(STR_ABSREFLOST);
2689*cdf0e10cSrcweir 				ErrorMessage(STR_NAMECONFLICT);
2690*cdf0e10cSrcweir 			}
2691*cdf0e10cSrcweir 			break;
2692*cdf0e10cSrcweir 			default:
2693*cdf0e10cSrcweir 			break;
2694*cdf0e10cSrcweir 		}
2695*cdf0e10cSrcweir 		//pDestShell->GetUndoManager()->Clear();		//! Undo implementieren !!!
2696*cdf0e10cSrcweir /*
2697*cdf0e10cSrcweir 		String sName;
2698*cdf0e10cSrcweir 		pDestDoc->GetName(nDestTab, sName);
2699*cdf0e10cSrcweir 		pDestShell->GetUndoManager()->AddUndoAction(
2700*cdf0e10cSrcweir 						new ScUndoInsertTab( pDestShell, nDestTab, sal_True, sName ) );
2701*cdf0e10cSrcweir */
2702*cdf0e10cSrcweir 		if (!bCopy)
2703*cdf0e10cSrcweir 		{
2704*cdf0e10cSrcweir 			if(nTabCount!=nTabSelCount)
2705*cdf0e10cSrcweir 				DeleteTables(TheTabs);// incl. Paint & Undo
2706*cdf0e10cSrcweir 			else
2707*cdf0e10cSrcweir 				ErrorMessage(STR_TABREMOVE_ERROR);
2708*cdf0e10cSrcweir 		}
2709*cdf0e10cSrcweir 
2710*cdf0e10cSrcweir 		if (bNewDoc)
2711*cdf0e10cSrcweir 		{
2712*cdf0e10cSrcweir 			//	ChartListenerCollection must be updated before DeleteTab
2713*cdf0e10cSrcweir 			if ( pDestDoc->IsChartListenerCollectionNeedsUpdate() )
2714*cdf0e10cSrcweir 				pDestDoc->UpdateChartListenerCollection();
2715*cdf0e10cSrcweir 
2716*cdf0e10cSrcweir 			pDestDoc->DeleteTab(static_cast<SCTAB>(TheTabs.size()));   // first old table
2717*cdf0e10cSrcweir //?			pDestDoc->SelectTable(0, sal_True);		// neue erste Tabelle selektieren
2718*cdf0e10cSrcweir 			if (pDestViewSh)
2719*cdf0e10cSrcweir 				pDestViewSh->TabChanged();		// Pages auf dem Drawing-Layer
2720*cdf0e10cSrcweir 			pDestShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
2721*cdf0e10cSrcweir 									PAINT_GRID | PAINT_TOP | PAINT_LEFT |
2722*cdf0e10cSrcweir 									PAINT_EXTRAS | PAINT_SIZE );
2723*cdf0e10cSrcweir 			//	PAINT_SIZE fuer Gliederung
2724*cdf0e10cSrcweir 		}
2725*cdf0e10cSrcweir 		else
2726*cdf0e10cSrcweir 		{
2727*cdf0e10cSrcweir 			pDestShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, nDestTab ) );
2728*cdf0e10cSrcweir 			pDestShell->PostPaintExtras();
2729*cdf0e10cSrcweir 			pDestShell->PostPaintGridAll();
2730*cdf0e10cSrcweir 		}
2731*cdf0e10cSrcweir 
2732*cdf0e10cSrcweir 		TheTabs.clear();
2733*cdf0e10cSrcweir 
2734*cdf0e10cSrcweir 		pDestShell->SetDocumentModified();
2735*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2736*cdf0e10cSrcweir 	}
2737*cdf0e10cSrcweir 	else					// within the documents
2738*cdf0e10cSrcweir 	{
2739*cdf0e10cSrcweir 
2740*cdf0e10cSrcweir 		ScMarkData& rMark		= GetViewData()->GetMarkData();
2741*cdf0e10cSrcweir 		SCTAB		nTabCount	= pDoc->GetTableCount();
2742*cdf0e10cSrcweir 
2743*cdf0e10cSrcweir 		SvShorts	TheTabs;
2744*cdf0e10cSrcweir 		SvShorts	TheDestTabs;
2745*cdf0e10cSrcweir 		SvStrings	TheTabNames;
2746*cdf0e10cSrcweir 		String		aDestName;
2747*cdf0e10cSrcweir 		String		*pString;
2748*cdf0e10cSrcweir 
2749*cdf0e10cSrcweir 		for(SCTAB i=0;i<nTabCount;i++)
2750*cdf0e10cSrcweir 		{
2751*cdf0e10cSrcweir 			if(rMark.GetTableSelect(i))
2752*cdf0e10cSrcweir 			{
2753*cdf0e10cSrcweir 				String aTabName;
2754*cdf0e10cSrcweir 				pDoc->GetName( i, aTabName);
2755*cdf0e10cSrcweir 				TheTabNames.Insert(new String(aTabName),TheTabNames.Count());
2756*cdf0e10cSrcweir 
2757*cdf0e10cSrcweir 				for(SCTAB j=i+1;j<nTabCount;j++)
2758*cdf0e10cSrcweir 				{
2759*cdf0e10cSrcweir 					if((!pDoc->IsVisible(j))&&(pDoc->IsScenario(j)))
2760*cdf0e10cSrcweir 					{
2761*cdf0e10cSrcweir 						pDoc->GetName( j, aTabName);
2762*cdf0e10cSrcweir 						TheTabNames.Insert(new String(aTabName),TheTabNames.Count());
2763*cdf0e10cSrcweir 						i=j;
2764*cdf0e10cSrcweir 					}
2765*cdf0e10cSrcweir 					else break;
2766*cdf0e10cSrcweir 				}
2767*cdf0e10cSrcweir 
2768*cdf0e10cSrcweir 			}
2769*cdf0e10cSrcweir 		}
2770*cdf0e10cSrcweir 
2771*cdf0e10cSrcweir 		if (bCopy && bUndo)
2772*cdf0e10cSrcweir 			pDoc->BeginDrawUndo();			// drawing layer must do its own undo actions
2773*cdf0e10cSrcweir 
2774*cdf0e10cSrcweir 		pDoc->GetName( nDestTab, aDestName);
2775*cdf0e10cSrcweir 		SCTAB nDestTab1=nDestTab;
2776*cdf0e10cSrcweir 		SCTAB nMovTab=0;
2777*cdf0e10cSrcweir 		for(int j=0;j<TheTabNames.Count();j++)
2778*cdf0e10cSrcweir 		{
2779*cdf0e10cSrcweir 			nTabCount	= pDoc->GetTableCount();
2780*cdf0e10cSrcweir             pString=TheTabNames[sal::static_int_cast<sal_uInt16>(j)];
2781*cdf0e10cSrcweir 			if(!pDoc->GetTable(*pString,nMovTab))
2782*cdf0e10cSrcweir 			{
2783*cdf0e10cSrcweir 				nMovTab=nTabCount;
2784*cdf0e10cSrcweir 			}
2785*cdf0e10cSrcweir 			if(!pDoc->GetTable(aDestName,nDestTab1))
2786*cdf0e10cSrcweir 			{
2787*cdf0e10cSrcweir 				nDestTab1=nTabCount;
2788*cdf0e10cSrcweir 			}
2789*cdf0e10cSrcweir 			pDocShell->MoveTable( nMovTab, nDestTab1, bCopy, sal_False );	// Undo ist hier
2790*cdf0e10cSrcweir 
2791*cdf0e10cSrcweir 			if(bCopy && pDoc->IsScenario(nMovTab))
2792*cdf0e10cSrcweir 			{
2793*cdf0e10cSrcweir 				String aComment;
2794*cdf0e10cSrcweir 				Color  aColor;
2795*cdf0e10cSrcweir 				sal_uInt16 nFlags;
2796*cdf0e10cSrcweir 
2797*cdf0e10cSrcweir 				pDoc->GetScenarioData(nMovTab, aComment,aColor, nFlags);
2798*cdf0e10cSrcweir 				pDoc->SetScenario(nDestTab1,sal_True);
2799*cdf0e10cSrcweir 				pDoc->SetScenarioData(nDestTab1,aComment,aColor,nFlags);
2800*cdf0e10cSrcweir 				sal_Bool bActive = pDoc->IsActiveScenario(nMovTab );
2801*cdf0e10cSrcweir 				pDoc->SetActiveScenario( nDestTab1, bActive );
2802*cdf0e10cSrcweir 				sal_Bool bVisible=pDoc->IsVisible(nMovTab);
2803*cdf0e10cSrcweir 				pDoc->SetVisible(nDestTab1,bVisible );
2804*cdf0e10cSrcweir 			}
2805*cdf0e10cSrcweir 
2806*cdf0e10cSrcweir 			TheTabs.push_back(nMovTab);
2807*cdf0e10cSrcweir 
2808*cdf0e10cSrcweir 			if(!bCopy)
2809*cdf0e10cSrcweir 			{
2810*cdf0e10cSrcweir 				if(!pDoc->GetTable(*pString,nDestTab1))
2811*cdf0e10cSrcweir 				{
2812*cdf0e10cSrcweir 					nDestTab1=nTabCount;
2813*cdf0e10cSrcweir 				}
2814*cdf0e10cSrcweir 			}
2815*cdf0e10cSrcweir 
2816*cdf0e10cSrcweir 			TheDestTabs.push_back(nDestTab1);
2817*cdf0e10cSrcweir 			delete pString;
2818*cdf0e10cSrcweir 		}
2819*cdf0e10cSrcweir 
2820*cdf0e10cSrcweir 		nTab = GetViewData()->GetTabNo();
2821*cdf0e10cSrcweir 
2822*cdf0e10cSrcweir 		if (bUndo)
2823*cdf0e10cSrcweir 		{
2824*cdf0e10cSrcweir 			if (bCopy)
2825*cdf0e10cSrcweir 			{
2826*cdf0e10cSrcweir 				pDocShell->GetUndoManager()->AddUndoAction(
2827*cdf0e10cSrcweir 						new ScUndoCopyTab( pDocShell, TheTabs, TheDestTabs));
2828*cdf0e10cSrcweir 			}
2829*cdf0e10cSrcweir 			else
2830*cdf0e10cSrcweir 			{
2831*cdf0e10cSrcweir 				pDocShell->GetUndoManager()->AddUndoAction(
2832*cdf0e10cSrcweir 						new ScUndoMoveTab( pDocShell, TheTabs, TheDestTabs));
2833*cdf0e10cSrcweir 			}
2834*cdf0e10cSrcweir 		}
2835*cdf0e10cSrcweir 
2836*cdf0e10cSrcweir 		SCTAB nNewTab = nDestTab;
2837*cdf0e10cSrcweir 		if (nNewTab == SC_TAB_APPEND)
2838*cdf0e10cSrcweir 			nNewTab = pDoc->GetTableCount()-1;
2839*cdf0e10cSrcweir 		else if (!bCopy && nTab<nDestTab)
2840*cdf0e10cSrcweir 			nNewTab--;
2841*cdf0e10cSrcweir 
2842*cdf0e10cSrcweir 		SetTabNo( nNewTab, sal_True );
2843*cdf0e10cSrcweir 
2844*cdf0e10cSrcweir         //#i29848# adjust references to data on the copied sheet
2845*cdf0e10cSrcweir         if( bCopy )
2846*cdf0e10cSrcweir             ScChartHelper::AdjustRangesOfChartsOnDestinationPage( pDoc, pDestDoc, nTab, nNewTab );
2847*cdf0e10cSrcweir 	}
2848*cdf0e10cSrcweir }
2849*cdf0e10cSrcweir 
2850*cdf0e10cSrcweir 
2851*cdf0e10cSrcweir //----------------------------------------------------------------------------
2852*cdf0e10cSrcweir 
2853*cdf0e10cSrcweir void ScViewFunc::ShowTable( const String& rName )
2854*cdf0e10cSrcweir {
2855*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
2856*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
2857*cdf0e10cSrcweir 	sal_Bool bUndo(pDoc->IsUndoEnabled());
2858*cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
2859*cdf0e10cSrcweir 	SCTAB nPos = 0;
2860*cdf0e10cSrcweir 	String aTabName;
2861*cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
2862*cdf0e10cSrcweir 	for (SCTAB i=0; i<nCount; i++)
2863*cdf0e10cSrcweir 	{
2864*cdf0e10cSrcweir 		pDoc->GetName( i, aTabName );
2865*cdf0e10cSrcweir 		if ( aTabName == rName )
2866*cdf0e10cSrcweir 		{
2867*cdf0e10cSrcweir 			nPos = i;
2868*cdf0e10cSrcweir 			bFound = sal_True;
2869*cdf0e10cSrcweir 		}
2870*cdf0e10cSrcweir 	}
2871*cdf0e10cSrcweir 
2872*cdf0e10cSrcweir 	if (bFound)
2873*cdf0e10cSrcweir 	{
2874*cdf0e10cSrcweir 		pDoc->SetVisible( nPos, sal_True );
2875*cdf0e10cSrcweir 		if (bUndo)
2876*cdf0e10cSrcweir 		{
2877*cdf0e10cSrcweir 			pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, nPos, sal_True ) );
2878*cdf0e10cSrcweir 		}
2879*cdf0e10cSrcweir 		SetTabNo( nPos, sal_True );
2880*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2881*cdf0e10cSrcweir 		pDocSh->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_EXTRAS);
2882*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
2883*cdf0e10cSrcweir 	}
2884*cdf0e10cSrcweir 	else
2885*cdf0e10cSrcweir 		Sound::Beep();
2886*cdf0e10cSrcweir }
2887*cdf0e10cSrcweir 
2888*cdf0e10cSrcweir 
2889*cdf0e10cSrcweir //----------------------------------------------------------------------------
2890*cdf0e10cSrcweir 
2891*cdf0e10cSrcweir void ScViewFunc::HideTable( SCTAB nTab )
2892*cdf0e10cSrcweir {
2893*cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
2894*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
2895*cdf0e10cSrcweir 	sal_Bool bUndo(pDoc->IsUndoEnabled());
2896*cdf0e10cSrcweir 	SCTAB nVisible = 0;
2897*cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
2898*cdf0e10cSrcweir 	for (SCTAB i=0; i<nCount; i++)
2899*cdf0e10cSrcweir 	{
2900*cdf0e10cSrcweir 		if (pDoc->IsVisible(i))
2901*cdf0e10cSrcweir 			++nVisible;
2902*cdf0e10cSrcweir 	}
2903*cdf0e10cSrcweir 
2904*cdf0e10cSrcweir 	if (nVisible > 1)
2905*cdf0e10cSrcweir 	{
2906*cdf0e10cSrcweir 		pDoc->SetVisible( nTab, sal_False );
2907*cdf0e10cSrcweir 		if (bUndo)
2908*cdf0e10cSrcweir 		{
2909*cdf0e10cSrcweir 			pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, nTab, sal_False ) );
2910*cdf0e10cSrcweir 		}
2911*cdf0e10cSrcweir 
2912*cdf0e10cSrcweir 		//	Views updaten:
2913*cdf0e10cSrcweir 		pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
2914*cdf0e10cSrcweir 
2915*cdf0e10cSrcweir 		SetTabNo( nTab, sal_True );
2916*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
2917*cdf0e10cSrcweir 		pDocSh->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_EXTRAS);
2918*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
2919*cdf0e10cSrcweir 	}
2920*cdf0e10cSrcweir 	else
2921*cdf0e10cSrcweir 		Sound::Beep();
2922*cdf0e10cSrcweir }
2923*cdf0e10cSrcweir 
2924*cdf0e10cSrcweir 
2925*cdf0e10cSrcweir //----------------------------------------------------------------------------
2926*cdf0e10cSrcweir 
2927*cdf0e10cSrcweir void ScViewFunc::InsertSpecialChar( const String& rStr, const Font& rFont )
2928*cdf0e10cSrcweir {
2929*cdf0e10cSrcweir 	ScEditableTester aTester( this );
2930*cdf0e10cSrcweir 	if (!aTester.IsEditable())
2931*cdf0e10cSrcweir 	{
2932*cdf0e10cSrcweir 		ErrorMessage(aTester.GetMessageId());
2933*cdf0e10cSrcweir 		return;
2934*cdf0e10cSrcweir 	}
2935*cdf0e10cSrcweir 
2936*cdf0e10cSrcweir 	const sal_Unicode* pChar	= rStr.GetBuffer();
2937*cdf0e10cSrcweir 	ScTabViewShell* pViewShell	= GetViewData()->GetViewShell();
2938*cdf0e10cSrcweir 	SvxFontItem		aFontItem( rFont.GetFamily(),
2939*cdf0e10cSrcweir 							   rFont.GetName(),
2940*cdf0e10cSrcweir 							   rFont.GetStyleName(),
2941*cdf0e10cSrcweir 							   rFont.GetPitch(),
2942*cdf0e10cSrcweir 							   rFont.GetCharSet(),
2943*cdf0e10cSrcweir 							   ATTR_FONT );
2944*cdf0e10cSrcweir 
2945*cdf0e10cSrcweir 	//	if string contains WEAK characters, set all fonts
2946*cdf0e10cSrcweir 	sal_uInt8 nScript;
2947*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
2948*cdf0e10cSrcweir 	if ( pDoc->HasStringWeakCharacters( rStr ) )
2949*cdf0e10cSrcweir 		nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
2950*cdf0e10cSrcweir 	else
2951*cdf0e10cSrcweir 		nScript = pDoc->GetStringScriptType( rStr );
2952*cdf0e10cSrcweir 
2953*cdf0e10cSrcweir 	SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, pViewShell->GetPool() );
2954*cdf0e10cSrcweir 	aSetItem.PutItemForScriptType( nScript, aFontItem );
2955*cdf0e10cSrcweir 	ApplyUserItemSet( aSetItem.GetItemSet() );
2956*cdf0e10cSrcweir 
2957*cdf0e10cSrcweir 	while ( *pChar )
2958*cdf0e10cSrcweir 		pViewShell->TabKeyInput( KeyEvent( *(pChar++), KeyCode() ) );
2959*cdf0e10cSrcweir }
2960*cdf0e10cSrcweir 
2961*cdf0e10cSrcweir 
2962*cdf0e10cSrcweir //----------------------------------------------------------------------------
2963*cdf0e10cSrcweir 
2964*cdf0e10cSrcweir void ScViewFunc::UpdateLineAttrs( SvxBorderLine&	   rLine,
2965*cdf0e10cSrcweir 								  const SvxBorderLine* pDestLine,
2966*cdf0e10cSrcweir 								  const SvxBorderLine* pSrcLine,
2967*cdf0e10cSrcweir 								  sal_Bool 				   bColor )
2968*cdf0e10cSrcweir {
2969*cdf0e10cSrcweir 	if ( pSrcLine && pDestLine )
2970*cdf0e10cSrcweir 	{
2971*cdf0e10cSrcweir 		if ( bColor )
2972*cdf0e10cSrcweir 		{
2973*cdf0e10cSrcweir 			rLine.SetColor		( pSrcLine->GetColor() );
2974*cdf0e10cSrcweir 			rLine.SetOutWidth	( pDestLine->GetOutWidth() );
2975*cdf0e10cSrcweir 			rLine.SetInWidth	( pDestLine->GetInWidth() );
2976*cdf0e10cSrcweir 			rLine.SetDistance	( pDestLine->GetDistance() );
2977*cdf0e10cSrcweir 		}
2978*cdf0e10cSrcweir 		else
2979*cdf0e10cSrcweir 		{
2980*cdf0e10cSrcweir 			rLine.SetColor		( pDestLine->GetColor() );
2981*cdf0e10cSrcweir 			rLine.SetOutWidth	( pSrcLine->GetOutWidth() );
2982*cdf0e10cSrcweir 			rLine.SetInWidth	( pSrcLine->GetInWidth() );
2983*cdf0e10cSrcweir 			rLine.SetDistance	( pSrcLine->GetDistance() );
2984*cdf0e10cSrcweir 		}
2985*cdf0e10cSrcweir 	}
2986*cdf0e10cSrcweir }
2987*cdf0e10cSrcweir 
2988*cdf0e10cSrcweir 
2989*cdf0e10cSrcweir #define SET_LINE_ATTRIBUTES(LINE,BOXLINE) \
2990*cdf0e10cSrcweir 	pBoxLine = aBoxItem.Get##LINE();								\
2991*cdf0e10cSrcweir 	if ( pBoxLine )													\
2992*cdf0e10cSrcweir 	{																\
2993*cdf0e10cSrcweir 		if ( pLine )												\
2994*cdf0e10cSrcweir 		{															\
2995*cdf0e10cSrcweir 			UpdateLineAttrs( aLine, pBoxLine, pLine, bColorOnly );	\
2996*cdf0e10cSrcweir 			aBoxItem.SetLine( &aLine, BOXLINE );					\
2997*cdf0e10cSrcweir 		}															\
2998*cdf0e10cSrcweir 		else														\
2999*cdf0e10cSrcweir 			aBoxItem.SetLine( NULL, BOXLINE );						\
3000*cdf0e10cSrcweir 	}
3001*cdf0e10cSrcweir 
3002*cdf0e10cSrcweir 
3003*cdf0e10cSrcweir //----------------------------------------------------------------------------
3004*cdf0e10cSrcweir 
3005*cdf0e10cSrcweir void ScViewFunc::SetSelectionFrameLines( const SvxBorderLine* pLine,
3006*cdf0e10cSrcweir 										 sal_Bool bColorOnly )
3007*cdf0e10cSrcweir {
3008*cdf0e10cSrcweir 	// nur wegen Matrix nicht editierbar? Attribute trotzdem ok
3009*cdf0e10cSrcweir 	sal_Bool bOnlyNotBecauseOfMatrix;
3010*cdf0e10cSrcweir 	if ( !SelectionEditable( &bOnlyNotBecauseOfMatrix ) && !bOnlyNotBecauseOfMatrix )
3011*cdf0e10cSrcweir 	{
3012*cdf0e10cSrcweir 		ErrorMessage(STR_PROTECTIONERR);
3013*cdf0e10cSrcweir 		return;
3014*cdf0e10cSrcweir 	}
3015*cdf0e10cSrcweir 
3016*cdf0e10cSrcweir 	ScDocument*				pDoc = GetViewData()->GetDocument();
3017*cdf0e10cSrcweir     ScMarkData aFuncMark( GetViewData()->GetMarkData() );       // local copy for UnmarkFiltered
3018*cdf0e10cSrcweir     ScViewUtil::UnmarkFiltered( aFuncMark, pDoc );
3019*cdf0e10cSrcweir 	ScDocShell*				pDocSh = GetViewData()->GetDocShell();
3020*cdf0e10cSrcweir 	const ScPatternAttr*	pSelAttrs = GetSelectionPattern();
3021*cdf0e10cSrcweir     const SfxItemSet&       rSelItemSet = pSelAttrs->GetItemSet();
3022*cdf0e10cSrcweir 
3023*cdf0e10cSrcweir 	const SfxPoolItem*		pBorderAttr	= NULL;
3024*cdf0e10cSrcweir     SfxItemState            eItemState = rSelItemSet.GetItemState( ATTR_BORDER, sal_True, &pBorderAttr );
3025*cdf0e10cSrcweir 
3026*cdf0e10cSrcweir     const SfxPoolItem*      pTLBRItem = 0;
3027*cdf0e10cSrcweir     SfxItemState            eTLBRState = rSelItemSet.GetItemState( ATTR_BORDER_TLBR, sal_True, &pTLBRItem );
3028*cdf0e10cSrcweir 
3029*cdf0e10cSrcweir     const SfxPoolItem*      pBLTRItem = 0;
3030*cdf0e10cSrcweir     SfxItemState            eBLTRState = rSelItemSet.GetItemState( ATTR_BORDER_BLTR, sal_True, &pBLTRItem );
3031*cdf0e10cSrcweir 
3032*cdf0e10cSrcweir     // any of the lines visible?
3033*cdf0e10cSrcweir     if( (eItemState != SFX_ITEM_DEFAULT) || (eTLBRState != SFX_ITEM_DEFAULT) || (eBLTRState != SFX_ITEM_DEFAULT) )
3034*cdf0e10cSrcweir 	{
3035*cdf0e10cSrcweir         // none of the lines don't care?
3036*cdf0e10cSrcweir         if( (eItemState != SFX_ITEM_DONTCARE) && (eTLBRState != SFX_ITEM_DONTCARE) && (eBLTRState != SFX_ITEM_DONTCARE) )
3037*cdf0e10cSrcweir 		{
3038*cdf0e10cSrcweir 			SfxItemSet*		pOldSet	= new SfxItemSet(
3039*cdf0e10cSrcweir 											*(pDoc->GetPool()),
3040*cdf0e10cSrcweir 											ATTR_PATTERN_START,
3041*cdf0e10cSrcweir 											ATTR_PATTERN_END );
3042*cdf0e10cSrcweir 			SfxItemSet*		pNewSet	= new SfxItemSet(
3043*cdf0e10cSrcweir 											*(pDoc->GetPool()),
3044*cdf0e10cSrcweir 											ATTR_PATTERN_START,
3045*cdf0e10cSrcweir 											ATTR_PATTERN_END );
3046*cdf0e10cSrcweir 
3047*cdf0e10cSrcweir 			//------------------------------------------------------------
3048*cdf0e10cSrcweir 			const SvxBorderLine*	pBoxLine = NULL;
3049*cdf0e10cSrcweir 			SvxBorderLine			aLine;
3050*cdf0e10cSrcweir 
3051*cdf0e10cSrcweir 			// hier wird die pBoxLine benutzt:
3052*cdf0e10cSrcweir 
3053*cdf0e10cSrcweir             if( pBorderAttr )
3054*cdf0e10cSrcweir             {
3055*cdf0e10cSrcweir                 SvxBoxItem      aBoxItem( *(const SvxBoxItem*)pBorderAttr );
3056*cdf0e10cSrcweir                 SvxBoxInfoItem  aBoxInfoItem( ATTR_BORDER_INNER );
3057*cdf0e10cSrcweir 
3058*cdf0e10cSrcweir                 SET_LINE_ATTRIBUTES(Top,BOX_LINE_TOP)
3059*cdf0e10cSrcweir                 SET_LINE_ATTRIBUTES(Bottom,BOX_LINE_BOTTOM)
3060*cdf0e10cSrcweir                 SET_LINE_ATTRIBUTES(Left,BOX_LINE_LEFT)
3061*cdf0e10cSrcweir                 SET_LINE_ATTRIBUTES(Right,BOX_LINE_RIGHT)
3062*cdf0e10cSrcweir 
3063*cdf0e10cSrcweir                 aBoxInfoItem.SetLine( aBoxItem.GetTop(), BOXINFO_LINE_HORI );
3064*cdf0e10cSrcweir                 aBoxInfoItem.SetLine( aBoxItem.GetLeft(), BOXINFO_LINE_VERT );
3065*cdf0e10cSrcweir                 aBoxInfoItem.ResetFlags(); // Lines auf Valid setzen
3066*cdf0e10cSrcweir 
3067*cdf0e10cSrcweir                 pOldSet->Put( *pBorderAttr );
3068*cdf0e10cSrcweir                 pNewSet->Put( aBoxItem );
3069*cdf0e10cSrcweir                 pNewSet->Put( aBoxInfoItem );
3070*cdf0e10cSrcweir             }
3071*cdf0e10cSrcweir 
3072*cdf0e10cSrcweir             if( pTLBRItem && ((const SvxLineItem*)pTLBRItem)->GetLine() )
3073*cdf0e10cSrcweir             {
3074*cdf0e10cSrcweir                 SvxLineItem aTLBRItem( *(const SvxLineItem*)pTLBRItem );
3075*cdf0e10cSrcweir                 UpdateLineAttrs( aLine, aTLBRItem.GetLine(), pLine, bColorOnly );
3076*cdf0e10cSrcweir                 aTLBRItem.SetLine( &aLine );
3077*cdf0e10cSrcweir                 pOldSet->Put( *pTLBRItem );
3078*cdf0e10cSrcweir                 pNewSet->Put( aTLBRItem );
3079*cdf0e10cSrcweir             }
3080*cdf0e10cSrcweir 
3081*cdf0e10cSrcweir             if( pBLTRItem && ((const SvxLineItem*)pBLTRItem)->GetLine() )
3082*cdf0e10cSrcweir             {
3083*cdf0e10cSrcweir                 SvxLineItem aBLTRItem( *(const SvxLineItem*)pBLTRItem );
3084*cdf0e10cSrcweir                 UpdateLineAttrs( aLine, aBLTRItem.GetLine(), pLine, bColorOnly );
3085*cdf0e10cSrcweir                 aBLTRItem.SetLine( &aLine );
3086*cdf0e10cSrcweir                 pOldSet->Put( *pBLTRItem );
3087*cdf0e10cSrcweir                 pNewSet->Put( aBLTRItem );
3088*cdf0e10cSrcweir             }
3089*cdf0e10cSrcweir 
3090*cdf0e10cSrcweir 			ApplyAttributes( pNewSet, pOldSet );
3091*cdf0e10cSrcweir 
3092*cdf0e10cSrcweir 			delete pOldSet;
3093*cdf0e10cSrcweir 			delete pNewSet;
3094*cdf0e10cSrcweir 		}
3095*cdf0e10cSrcweir 		else // if ( eItemState == SFX_ITEM_DONTCARE )
3096*cdf0e10cSrcweir 		{
3097*cdf0e10cSrcweir 			aFuncMark.MarkToMulti();
3098*cdf0e10cSrcweir 			pDoc->ApplySelectionLineStyle( aFuncMark, pLine, bColorOnly );
3099*cdf0e10cSrcweir 		}
3100*cdf0e10cSrcweir 
3101*cdf0e10cSrcweir 		ScRange aMarkRange;
3102*cdf0e10cSrcweir 		aFuncMark.GetMultiMarkArea( aMarkRange );
3103*cdf0e10cSrcweir 		SCCOL nStartCol = aMarkRange.aStart.Col();
3104*cdf0e10cSrcweir 		SCROW nStartRow = aMarkRange.aStart.Row();
3105*cdf0e10cSrcweir 		SCTAB nStartTab = aMarkRange.aStart.Tab();
3106*cdf0e10cSrcweir 		SCCOL nEndCol = aMarkRange.aEnd.Col();
3107*cdf0e10cSrcweir 		SCROW nEndRow = aMarkRange.aEnd.Row();
3108*cdf0e10cSrcweir 		SCTAB nEndTab = aMarkRange.aEnd.Tab();
3109*cdf0e10cSrcweir 		pDocSh->PostPaint( nStartCol, nStartRow, nStartTab,
3110*cdf0e10cSrcweir 						   nEndCol, nEndRow, nEndTab,
3111*cdf0e10cSrcweir 						   PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
3112*cdf0e10cSrcweir 
3113*cdf0e10cSrcweir 		pDocSh->UpdateOle( GetViewData() );
3114*cdf0e10cSrcweir 		pDocSh->SetDocumentModified();
3115*cdf0e10cSrcweir 	}
3116*cdf0e10cSrcweir }
3117*cdf0e10cSrcweir 
3118*cdf0e10cSrcweir #undef SET_LINE_ATTRIBUTES
3119*cdf0e10cSrcweir 
3120*cdf0e10cSrcweir 
3121*cdf0e10cSrcweir //----------------------------------------------------------------------------
3122*cdf0e10cSrcweir 
3123*cdf0e10cSrcweir void ScViewFunc::SetConditionalFormat( const ScConditionalFormat& rNew )
3124*cdf0e10cSrcweir {
3125*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
3126*cdf0e10cSrcweir 	sal_uLong nIndex = pDoc->AddCondFormat(rNew);			// dafuer gibt's kein Undo
3127*cdf0e10cSrcweir 	SfxUInt32Item aItem( ATTR_CONDITIONAL, nIndex );
3128*cdf0e10cSrcweir 
3129*cdf0e10cSrcweir 	ApplyAttr( aItem );			// mit Paint und Undo...
3130*cdf0e10cSrcweir }
3131*cdf0e10cSrcweir 
3132*cdf0e10cSrcweir 
3133*cdf0e10cSrcweir //----------------------------------------------------------------------------
3134*cdf0e10cSrcweir 
3135*cdf0e10cSrcweir void ScViewFunc::SetValidation( const ScValidationData& rNew )
3136*cdf0e10cSrcweir {
3137*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
3138*cdf0e10cSrcweir 	sal_uLong nIndex = pDoc->AddValidationEntry(rNew);		// dafuer gibt's kein Undo
3139*cdf0e10cSrcweir 	SfxUInt32Item aItem( ATTR_VALIDDATA, nIndex );
3140*cdf0e10cSrcweir 
3141*cdf0e10cSrcweir 	ApplyAttr( aItem );			// mit Paint und Undo...
3142*cdf0e10cSrcweir }
3143*cdf0e10cSrcweir 
3144*cdf0e10cSrcweir 
3145