xref: /aoo41x/main/sc/source/ui/docshell/docsh.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 // System - Includes -----------------------------------------------------
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "scitems.hxx"
33*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
34*cdf0e10cSrcweir #include <editeng/svxenum.hxx>
35*cdf0e10cSrcweir #include <svx/algitem.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <sot/clsids.hxx>
38*cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
39*cdf0e10cSrcweir #include <tools/stream.hxx>
40*cdf0e10cSrcweir #include <tools/string.hxx>
41*cdf0e10cSrcweir #include <tools/urlobj.hxx>
42*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
43*cdf0e10cSrcweir #include <vcl/virdev.hxx>
44*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
45*cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
46*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
47*cdf0e10cSrcweir #include <svl/zforlist.hxx>
48*cdf0e10cSrcweir #include <svl/PasswordHelper.hxx>
49*cdf0e10cSrcweir #include <sfx2/app.hxx>
50*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
51*cdf0e10cSrcweir #include <sfx2/dinfdlg.hxx>
52*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
53*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
54*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
55*cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
56*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
57*cdf0e10cSrcweir #include <sfx2/objface.hxx>
58*cdf0e10cSrcweir #include <svl/srchitem.hxx>
59*cdf0e10cSrcweir #include <unotools/fltrcfg.hxx>
60*cdf0e10cSrcweir #include <svl/documentlockfile.hxx>
61*cdf0e10cSrcweir #include <svl/sharecontrolfile.hxx>
62*cdf0e10cSrcweir #include <unotools/charclass.hxx>
63*cdf0e10cSrcweir #include <vcl/virdev.hxx>
64*cdf0e10cSrcweir #include "chgtrack.hxx"
65*cdf0e10cSrcweir #include "chgviset.hxx"
66*cdf0e10cSrcweir #include <sfx2/request.hxx>
67*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/script/vba/VBAEventId.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetView.hpp>
72*cdf0e10cSrcweir #include <com/sun/star/task/XJob.hpp>
73*cdf0e10cSrcweir #include <basic/sbstar.hxx>
74*cdf0e10cSrcweir #include <basic/basmgr.hxx>
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir #include "scabstdlg.hxx" //CHINA001
77*cdf0e10cSrcweir #include <sot/formats.hxx>
78*cdf0e10cSrcweir #define SOT_FORMATSTR_ID_STARCALC_30 SOT_FORMATSTR_ID_STARCALC
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir #include "cell.hxx"
83*cdf0e10cSrcweir #include "global.hxx"
84*cdf0e10cSrcweir #include "filter.hxx"
85*cdf0e10cSrcweir #include "scmod.hxx"
86*cdf0e10cSrcweir #include "tabvwsh.hxx"
87*cdf0e10cSrcweir #include "docfunc.hxx"
88*cdf0e10cSrcweir #include "imoptdlg.hxx"
89*cdf0e10cSrcweir #include "impex.hxx"
90*cdf0e10cSrcweir #include "scresid.hxx"
91*cdf0e10cSrcweir #include "sc.hrc"
92*cdf0e10cSrcweir #include "globstr.hrc"
93*cdf0e10cSrcweir #include "scerrors.hxx"
94*cdf0e10cSrcweir #include "brdcst.hxx"
95*cdf0e10cSrcweir #include "stlpool.hxx"
96*cdf0e10cSrcweir #include "autostyl.hxx"
97*cdf0e10cSrcweir #include "attrib.hxx"
98*cdf0e10cSrcweir #include "asciiopt.hxx"
99*cdf0e10cSrcweir #include "waitoff.hxx"
100*cdf0e10cSrcweir #include "docpool.hxx"		// LoadCompleted
101*cdf0e10cSrcweir #include "progress.hxx"
102*cdf0e10cSrcweir #include "pntlock.hxx"
103*cdf0e10cSrcweir #include "collect.hxx"
104*cdf0e10cSrcweir #include "docuno.hxx"
105*cdf0e10cSrcweir #include "appoptio.hxx"
106*cdf0e10cSrcweir #include "detdata.hxx"
107*cdf0e10cSrcweir #include "printfun.hxx"
108*cdf0e10cSrcweir #include "dociter.hxx"
109*cdf0e10cSrcweir #include "cellform.hxx"
110*cdf0e10cSrcweir #include "chartlis.hxx"
111*cdf0e10cSrcweir #include "hints.hxx"
112*cdf0e10cSrcweir #include "xmlwrap.hxx"
113*cdf0e10cSrcweir #include "drwlayer.hxx"
114*cdf0e10cSrcweir #include "refreshtimer.hxx"
115*cdf0e10cSrcweir #include "dbcolect.hxx"
116*cdf0e10cSrcweir #include "scextopt.hxx"
117*cdf0e10cSrcweir #include "compiler.hxx"
118*cdf0e10cSrcweir #include "cfgids.hxx"
119*cdf0e10cSrcweir #include "warnpassword.hxx"
120*cdf0e10cSrcweir #include "optsolver.hxx"
121*cdf0e10cSrcweir #include "sheetdata.hxx"
122*cdf0e10cSrcweir #include "tabprotection.hxx"
123*cdf0e10cSrcweir #include "dpobject.hxx"
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir #include "docsh.hxx"
126*cdf0e10cSrcweir #include "docshimp.hxx"
127*cdf0e10cSrcweir #include <rtl/logfile.hxx>
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
130*cdf0e10cSrcweir #include "uiitems.hxx"
131*cdf0e10cSrcweir #include "cellsuno.hxx"
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir using namespace com::sun::star;
134*cdf0e10cSrcweir using ::rtl::OUString;
135*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir //	Stream-Namen im Storage
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir const sal_Char __FAR_DATA ScDocShell::pStarCalcDoc[] = STRING_SCSTREAM;		// "StarCalcDocument"
142*cdf0e10cSrcweir const sal_Char __FAR_DATA ScDocShell::pStyleName[] = "SfxStyleSheets";
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //	Filter-Namen (wie in sclib.cxx)
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterSc50[]		= "StarCalc 5.0";
147*cdf0e10cSrcweir //static const sal_Char __FAR_DATA pFilterSc50Temp[]	= "StarCalc 5.0 Vorlage/Template";
148*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterSc40[]		= "StarCalc 4.0";
149*cdf0e10cSrcweir //static const sal_Char __FAR_DATA pFilterSc40Temp[]	= "StarCalc 4.0 Vorlage/Template";
150*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterSc30[]		= "StarCalc 3.0";
151*cdf0e10cSrcweir //static const sal_Char __FAR_DATA pFilterSc30Temp[]	= "StarCalc 3.0 Vorlage/Template";
152*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterSc10[]		= "StarCalc 1.0";
153*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterXML[]		= "StarOffice XML (Calc)";
154*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterAscii[]		= "Text - txt - csv (StarCalc)";
155*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterLotus[]		= "Lotus";
156*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterQPro6[]		= "Quattro Pro 6.0";
157*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterExcel4[]	= "MS Excel 4.0";
158*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterEx4Temp[]	= "MS Excel 4.0 Vorlage/Template";
159*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterExcel5[]	= "MS Excel 5.0/95";
160*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterEx5Temp[]	= "MS Excel 5.0/95 Vorlage/Template";
161*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterExcel95[]	= "MS Excel 95";
162*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterEx95Temp[]	= "MS Excel 95 Vorlage/Template";
163*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterExcel97[]	= "MS Excel 97";
164*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterEx97Temp[]	= "MS Excel 97 Vorlage/Template";
165*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterEx07Xml[]   = "MS Excel 2007 XML";
166*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterDBase[]		= "dBase";
167*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterDif[]		= "DIF";
168*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterSylk[]		= "SYLK";
169*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterHtml[]		= "HTML (StarCalc)";
170*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterHtmlWebQ[]	= "calc_HTML_WebQuery";
171*cdf0e10cSrcweir static const sal_Char __FAR_DATA pFilterRtf[]		= "Rich Text Format (StarCalc)";
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir //----------------------------------------------------------------------
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir #define ScDocShell
176*cdf0e10cSrcweir #include "scslots.hxx"
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir SFX_IMPL_INTERFACE(ScDocShell,SfxObjectShell, ScResId(SCSTR_DOCSHELL))
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	SFX_CHILDWINDOW_REGISTRATION( SID_HYPERLINK_INSERT );
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //	GlobalName der aktuellen Version:
185*cdf0e10cSrcweir SFX_IMPL_OBJECTFACTORY( ScDocShell, SvGlobalName(SO3_SC_CLASSID), SFXOBJECTSHELL_STD_NORMAL, "scalc" )
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir TYPEINIT1( ScDocShell, SfxObjectShell );		// SfxInPlaceObject: kein Type-Info ?
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir //------------------------------------------------------------------
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void __EXPORT ScDocShell::FillClass( SvGlobalName* pClassName,
192*cdf0e10cSrcweir 										sal_uInt32* pFormat,
193*cdf0e10cSrcweir                                         String* /* pAppName */,
194*cdf0e10cSrcweir 										String* pFullTypeName,
195*cdf0e10cSrcweir 										String* pShortTypeName,
196*cdf0e10cSrcweir                                         sal_Int32 nFileFormat,
197*cdf0e10cSrcweir                                         sal_Bool bTemplate /* = sal_False */) const
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	if ( nFileFormat == SOFFICE_FILEFORMAT_60 )
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		*pClassName		= SvGlobalName( SO3_SC_CLASSID_60 );
202*cdf0e10cSrcweir 		*pFormat		= SOT_FORMATSTR_ID_STARCALC_60;
203*cdf0e10cSrcweir 		*pFullTypeName	= String( ScResId( SCSTR_LONG_SCDOC_NAME ) );
204*cdf0e10cSrcweir 		*pShortTypeName	= String( ScResId( SCSTR_SHORT_SCDOC_NAME ) );
205*cdf0e10cSrcweir 	}
206*cdf0e10cSrcweir 	else if ( nFileFormat == SOFFICE_FILEFORMAT_8 )
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		*pClassName		= SvGlobalName( SO3_SC_CLASSID_60 );
209*cdf0e10cSrcweir         *pFormat		= bTemplate ? SOT_FORMATSTR_ID_STARCALC_8_TEMPLATE : SOT_FORMATSTR_ID_STARCALC_8;
210*cdf0e10cSrcweir 		*pFullTypeName	= String( RTL_CONSTASCII_USTRINGPARAM("calc8") );
211*cdf0e10cSrcweir 		*pShortTypeName	= String( ScResId( SCSTR_SHORT_SCDOC_NAME ) );
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 	else
214*cdf0e10cSrcweir 	{
215*cdf0e10cSrcweir 		DBG_ERROR("wat fuer ne Version?");
216*cdf0e10cSrcweir 	}
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir //------------------------------------------------------------------
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir void ScDocShell::DoEnterHandler()
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
224*cdf0e10cSrcweir 	if (pViewSh)
225*cdf0e10cSrcweir 		if (pViewSh->GetViewData()->GetDocShell() == this)
226*cdf0e10cSrcweir 			SC_MOD()->InputEnterHandler();
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir //------------------------------------------------------------------
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir SCTAB ScDocShell::GetSaveTab()
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	SCTAB nTab = 0;
234*cdf0e10cSrcweir 	ScTabViewShell* pSh = GetBestViewShell();
235*cdf0e10cSrcweir 	if (pSh)
236*cdf0e10cSrcweir 	{
237*cdf0e10cSrcweir 		const ScMarkData& rMark = pSh->GetViewData()->GetMarkData();
238*cdf0e10cSrcweir 		for ( nTab = 0; nTab <= MAXTAB; nTab++ )	// erste markierte Tabelle
239*cdf0e10cSrcweir 			if ( rMark.GetTableSelect( nTab ) )
240*cdf0e10cSrcweir 				break;
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir 	return nTab;
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir sal_uInt16 ScDocShell::GetHiddenInformationState( sal_uInt16 nStates )
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	// get global state like HIDDENINFORMATION_DOCUMENTVERSIONS
248*cdf0e10cSrcweir     sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES )
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         if ( aDocument.GetChangeTrack() && aDocument.GetChangeTrack()->GetFirst() )
253*cdf0e10cSrcweir           nState |= HIDDENINFORMATION_RECORDEDCHANGES;
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir     if ( nStates & HIDDENINFORMATION_NOTES )
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         SCTAB nTableCount = aDocument.GetTableCount();
258*cdf0e10cSrcweir         SCTAB nTable = 0;
259*cdf0e10cSrcweir         sal_Bool bFound(sal_False);
260*cdf0e10cSrcweir 	    while ( nTable < nTableCount && !bFound )
261*cdf0e10cSrcweir 	    {
262*cdf0e10cSrcweir             ScCellIterator aCellIter( &aDocument, 0,0, nTable, MAXCOL,MAXROW, nTable );
263*cdf0e10cSrcweir             for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell && !bFound; pCell = aCellIter.GetNext() )
264*cdf0e10cSrcweir                 if (pCell->HasNote())
265*cdf0e10cSrcweir                     bFound = sal_True;
266*cdf0e10cSrcweir             nTable++;
267*cdf0e10cSrcweir         }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir         if (bFound)
270*cdf0e10cSrcweir             nState |= HIDDENINFORMATION_NOTES;
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	return nState;
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir void ScDocShell::BeforeXMLLoading()
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     aDocument.DisableIdle( sal_True );
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     // prevent unnecessary broadcasts and updates
281*cdf0e10cSrcweir     DBG_ASSERT(pModificator == NULL, "The Modificator should not exist");
282*cdf0e10cSrcweir 	pModificator = new ScDocShellModificator( *this );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     aDocument.SetImportingXML( sal_True );
285*cdf0e10cSrcweir     aDocument.EnableExecuteLink( false );   // #i101304# to be safe, prevent nested loading from external references
286*cdf0e10cSrcweir     aDocument.EnableUndo( sal_False );
287*cdf0e10cSrcweir 	// prevent unnecessary broadcasts and "half way listeners"
288*cdf0e10cSrcweir 	aDocument.SetInsertingFromOtherDoc( sal_True );
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
291*cdf0e10cSrcweir 		ScColumn::bDoubleAlloc = sal_True;
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir void ScDocShell::AfterXMLLoading(sal_Bool bRet)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
297*cdf0e10cSrcweir 	{
298*cdf0e10cSrcweir 		UpdateLinks();
299*cdf0e10cSrcweir 		// don't prevent establishing of listeners anymore
300*cdf0e10cSrcweir 		aDocument.SetInsertingFromOtherDoc( sal_False );
301*cdf0e10cSrcweir 		if ( bRet )
302*cdf0e10cSrcweir 		{
303*cdf0e10cSrcweir 			ScChartListenerCollection* pChartListener = aDocument.GetChartListenerCollection();
304*cdf0e10cSrcweir 			if (pChartListener)
305*cdf0e10cSrcweir 				pChartListener->UpdateDirtyCharts();
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 			// #95582#; set the table names of linked tables to the new path
308*cdf0e10cSrcweir 			SCTAB nTabCount = aDocument.GetTableCount();
309*cdf0e10cSrcweir 			for (SCTAB i = 0; i < nTabCount; ++i)
310*cdf0e10cSrcweir 			{
311*cdf0e10cSrcweir 				if (aDocument.IsLinked( i ))
312*cdf0e10cSrcweir 				{
313*cdf0e10cSrcweir 					String aName;
314*cdf0e10cSrcweir 					aDocument.GetName(i, aName);
315*cdf0e10cSrcweir 					String aLinkTabName = aDocument.GetLinkTab(i);
316*cdf0e10cSrcweir 					xub_StrLen nLinkTabNameLength = aLinkTabName.Len();
317*cdf0e10cSrcweir 					xub_StrLen nNameLength = aName.Len();
318*cdf0e10cSrcweir 					if (nLinkTabNameLength < nNameLength)
319*cdf0e10cSrcweir 					{
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 						// remove the quottes on begin and end of the docname and restore the escaped quotes
322*cdf0e10cSrcweir 						const sal_Unicode* pNameBuffer = aName.GetBuffer();
323*cdf0e10cSrcweir 						if ( *pNameBuffer == '\'' && // all docnames have to have a ' character on the first pos
324*cdf0e10cSrcweir 							ScGlobal::UnicodeStrChr( pNameBuffer, SC_COMPILER_FILE_TAB_SEP ) )
325*cdf0e10cSrcweir 						{
326*cdf0e10cSrcweir 							rtl::OUStringBuffer aDocURLBuffer;
327*cdf0e10cSrcweir 							sal_Bool bQuote = sal_True;			// Dokumentenname ist immer quoted
328*cdf0e10cSrcweir 							++pNameBuffer;
329*cdf0e10cSrcweir 							while ( bQuote && *pNameBuffer )
330*cdf0e10cSrcweir 							{
331*cdf0e10cSrcweir 								if ( *pNameBuffer == '\'' && *(pNameBuffer-1) != '\\' )
332*cdf0e10cSrcweir 									bQuote = sal_False;
333*cdf0e10cSrcweir 								else if( !(*pNameBuffer == '\\' && *(pNameBuffer+1) == '\'') )
334*cdf0e10cSrcweir 									aDocURLBuffer.append(*pNameBuffer);		// falls escaped Quote: nur Quote in den Namen
335*cdf0e10cSrcweir 								++pNameBuffer;
336*cdf0e10cSrcweir 							}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 							if( *pNameBuffer == SC_COMPILER_FILE_TAB_SEP )  // after the last quote of the docname should be the # char
340*cdf0e10cSrcweir 							{
341*cdf0e10cSrcweir 								xub_StrLen nIndex = nNameLength - nLinkTabNameLength;
342*cdf0e10cSrcweir 								INetURLObject aINetURLObject(aDocURLBuffer.makeStringAndClear());
343*cdf0e10cSrcweir 								if(	aName.Equals(aLinkTabName, nIndex, nLinkTabNameLength) &&
344*cdf0e10cSrcweir 									(aName.GetChar(nIndex - 1) == '#') && // before the table name should be the # char
345*cdf0e10cSrcweir 									!aINetURLObject.HasError()) // the docname should be a valid URL
346*cdf0e10cSrcweir 								{
347*cdf0e10cSrcweir                         	    	aName = ScGlobal::GetDocTabName( aDocument.GetLinkDoc( i ), aDocument.GetLinkTab( i ) );
348*cdf0e10cSrcweir 	                            	aDocument.RenameTab(i, aName, sal_True, sal_True);
349*cdf0e10cSrcweir 								}
350*cdf0e10cSrcweir 								// else;  nothing has to happen, because it is a user given name
351*cdf0e10cSrcweir 							}
352*cdf0e10cSrcweir 							// else;  nothing has to happen, because it is a user given name
353*cdf0e10cSrcweir 						}
354*cdf0e10cSrcweir 						// else;  nothing has to happen, because it is a user given name
355*cdf0e10cSrcweir 					}
356*cdf0e10cSrcweir 					// else;  nothing has to happen, because it is a user given name
357*cdf0e10cSrcweir 				}
358*cdf0e10cSrcweir 			}
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir             // #i94570# DataPilot table names have to be unique, or the tables can't be accessed by API.
361*cdf0e10cSrcweir             // If no name (or an invalid name, skipped in ScXMLDataPilotTableContext::EndElement) was set, create a new name.
362*cdf0e10cSrcweir             ScDPCollection* pDPCollection = aDocument.GetDPCollection();
363*cdf0e10cSrcweir             if ( pDPCollection )
364*cdf0e10cSrcweir             {
365*cdf0e10cSrcweir                 sal_uInt16 nDPCount = pDPCollection->GetCount();
366*cdf0e10cSrcweir                 for (sal_uInt16 nDP=0; nDP<nDPCount; nDP++)
367*cdf0e10cSrcweir                 {
368*cdf0e10cSrcweir                     ScDPObject* pDPObj = (*pDPCollection)[nDP];
369*cdf0e10cSrcweir                     if ( !pDPObj->GetName().Len() )
370*cdf0e10cSrcweir                         pDPObj->SetName( pDPCollection->CreateNewName() );
371*cdf0e10cSrcweir                 }
372*cdf0e10cSrcweir             }
373*cdf0e10cSrcweir 		}
374*cdf0e10cSrcweir 		ScColumn::bDoubleAlloc = sal_False;
375*cdf0e10cSrcweir     }
376*cdf0e10cSrcweir     else
377*cdf0e10cSrcweir 		aDocument.SetInsertingFromOtherDoc( sal_False );
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	aDocument.SetImportingXML( sal_False );
380*cdf0e10cSrcweir     aDocument.EnableExecuteLink( true );
381*cdf0e10cSrcweir     aDocument.EnableUndo( sal_True );
382*cdf0e10cSrcweir     bIsEmpty = sal_False;
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     if (pModificator)
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir         delete pModificator;
387*cdf0e10cSrcweir         pModificator = NULL;
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir     else
390*cdf0e10cSrcweir     {
391*cdf0e10cSrcweir         DBG_ERROR("The Modificator should exist");
392*cdf0e10cSrcweir     }
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir     aDocument.DisableIdle( sal_False );
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor )
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScDocShell::LoadXML" );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	//	MacroCallMode is no longer needed, state is kept in SfxObjectShell now
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	// no Seek(0) here - always loading from storage, GetInStream must not be called
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     BeforeXMLLoading();
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     // #i62677# BeforeXMLLoading is also called from ScXMLImport::startDocument when invoked
408*cdf0e10cSrcweir     // from an external component. The XMLFromWrapper flag is only set here, when called
409*cdf0e10cSrcweir     // through ScDocShell.
410*cdf0e10cSrcweir     aDocument.SetXMLFromWrapper( sal_True );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     ScXMLImportWrapper aImport( aDocument, pLoadMedium, xStor );
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     sal_Bool bRet(sal_False);
415*cdf0e10cSrcweir     ErrCode nError = ERRCODE_NONE;
416*cdf0e10cSrcweir 	if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
417*cdf0e10cSrcweir         bRet = aImport.Import(sal_False, nError);
418*cdf0e10cSrcweir 	else
419*cdf0e10cSrcweir         bRet = aImport.Import(sal_True, nError);
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir     if ( nError )
422*cdf0e10cSrcweir         pLoadMedium->SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir     aDocument.SetXMLFromWrapper( sal_False );
425*cdf0e10cSrcweir     AfterXMLLoading(bRet);
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 	//!	row heights...
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 	return bRet;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir sal_Bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScDocShell::SaveXML" );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     aDocument.DisableIdle( sal_True );
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     ScXMLImportWrapper aImport( aDocument, pSaveMedium, xStor );
439*cdf0e10cSrcweir 	sal_Bool bRet(sal_False);
440*cdf0e10cSrcweir 	if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
441*cdf0e10cSrcweir 		bRet = aImport.Export(sal_False);
442*cdf0e10cSrcweir 	else
443*cdf0e10cSrcweir 		bRet = aImport.Export(sal_True);
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     aDocument.DisableIdle( sal_False );
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir     return bRet;
448*cdf0e10cSrcweir }
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::Load( SfxMedium& rMedium )
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::Load" );
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 	//	only the latin script language is loaded
457*cdf0e10cSrcweir 	//	-> initialize the others from options (before loading)
458*cdf0e10cSrcweir     InitOptions(true);
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 	GetUndoManager()->Clear();
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     sal_Bool bRet = SfxObjectShell::Load( rMedium );
463*cdf0e10cSrcweir 	if( bRet )
464*cdf0e10cSrcweir 	{
465*cdf0e10cSrcweir         if (GetMedium())
466*cdf0e10cSrcweir         {
467*cdf0e10cSrcweir             SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
468*cdf0e10cSrcweir             nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
469*cdf0e10cSrcweir         }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 		{
472*cdf0e10cSrcweir 			//	prepare a valid document for XML filter
473*cdf0e10cSrcweir 			//	(for ConvertFrom, InitNew is called before)
474*cdf0e10cSrcweir 			aDocument.MakeTable(0);
475*cdf0e10cSrcweir 			aDocument.GetStyleSheetPool()->CreateStandardStyles();
476*cdf0e10cSrcweir 			aDocument.UpdStlShtPtrsFrmNms();
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir             bRet = LoadXML( &rMedium, NULL );
479*cdf0e10cSrcweir 		}
480*cdf0e10cSrcweir 	}
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir     if (!bRet && !rMedium.GetError())
483*cdf0e10cSrcweir         rMedium.SetError( SVSTREAM_FILEFORMAT_ERROR, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     if (rMedium.GetError())
486*cdf0e10cSrcweir         SetError( rMedium.GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 	InitItems();
489*cdf0e10cSrcweir 	CalcOutputFactor();
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 	// #73762# invalidate eventually temporary table areas
492*cdf0e10cSrcweir 	if ( bRet )
493*cdf0e10cSrcweir 		aDocument.InvalidateTableArea();
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	bIsEmpty = sal_False;
496*cdf0e10cSrcweir 	FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
497*cdf0e10cSrcweir 	return bRet;
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir     if (rHint.ISA(ScTablesHint) )
503*cdf0e10cSrcweir     {
504*cdf0e10cSrcweir         const ScTablesHint& rScHint = static_cast< const ScTablesHint& >( rHint );
505*cdf0e10cSrcweir         if (rScHint.GetId() == SC_TAB_INSERTED)
506*cdf0e10cSrcweir         {
507*cdf0e10cSrcweir             uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = aDocument.GetVbaEventProcessor();
508*cdf0e10cSrcweir             if ( xVbaEvents.is() ) try
509*cdf0e10cSrcweir             {
510*cdf0e10cSrcweir                 uno::Sequence< uno::Any > aArgs( 1 );
511*cdf0e10cSrcweir                 aArgs[0] <<= rScHint.GetTab1();
512*cdf0e10cSrcweir                 xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_NEWSHEET, aArgs );
513*cdf0e10cSrcweir             }
514*cdf0e10cSrcweir             catch( uno::Exception& )
515*cdf0e10cSrcweir             {
516*cdf0e10cSrcweir             }
517*cdf0e10cSrcweir         }
518*cdf0e10cSrcweir     }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 	if (rHint.ISA(SfxSimpleHint))								// ohne Parameter
521*cdf0e10cSrcweir 	{
522*cdf0e10cSrcweir 		sal_uLong nSlot = ((const SfxSimpleHint&)rHint).GetId();
523*cdf0e10cSrcweir 		switch ( nSlot )
524*cdf0e10cSrcweir 		{
525*cdf0e10cSrcweir 			case SFX_HINT_TITLECHANGED:
526*cdf0e10cSrcweir 				aDocument.SetName( SfxShell::GetName() );
527*cdf0e10cSrcweir 				//	RegisterNewTargetNames gibts nicht mehr
528*cdf0e10cSrcweir 				SFX_APP()->Broadcast(SfxSimpleHint( SC_HINT_DOCNAME_CHANGED ));	// Navigator
529*cdf0e10cSrcweir 				break;
530*cdf0e10cSrcweir 		}
531*cdf0e10cSrcweir 	}
532*cdf0e10cSrcweir 	else if (rHint.ISA(SfxStyleSheetHint))						// Vorlagen geaendert
533*cdf0e10cSrcweir 		NotifyStyle((const SfxStyleSheetHint&) rHint);
534*cdf0e10cSrcweir 	else if (rHint.ISA(ScAutoStyleHint))
535*cdf0e10cSrcweir 	{
536*cdf0e10cSrcweir 		//!	direct call for AutoStyles
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 		//	this is called synchronously from ScInterpreter::ScStyle,
539*cdf0e10cSrcweir 		//	modifying the document must be asynchronous
540*cdf0e10cSrcweir 		//	(handled by AddInitial)
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 		ScAutoStyleHint& rStlHint = (ScAutoStyleHint&)rHint;
543*cdf0e10cSrcweir 		ScRange aRange = rStlHint.GetRange();
544*cdf0e10cSrcweir 		String aName1 = rStlHint.GetStyle1();
545*cdf0e10cSrcweir 		String aName2 = rStlHint.GetStyle2();
546*cdf0e10cSrcweir 		sal_uInt32 nTimeout = rStlHint.GetTimeout();
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 		if (!pAutoStyleList)
549*cdf0e10cSrcweir 			pAutoStyleList = new ScAutoStyleList(this);
550*cdf0e10cSrcweir 		pAutoStyleList->AddInitial( aRange, aName1, nTimeout, aName2 );
551*cdf0e10cSrcweir 	}
552*cdf0e10cSrcweir     else if ( rHint.ISA( SfxEventHint ) )
553*cdf0e10cSrcweir     {
554*cdf0e10cSrcweir         sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
555*cdf0e10cSrcweir         switch ( nEventId )
556*cdf0e10cSrcweir         {
557*cdf0e10cSrcweir             case SFX_EVENT_LOADFINISHED:
558*cdf0e10cSrcweir                 {
559*cdf0e10cSrcweir                     // the readonly documents should not be opened in shared mode
560*cdf0e10cSrcweir                     if ( HasSharedXMLFlagSet() && !SC_MOD()->IsInSharedDocLoading() && !IsReadOnly() )
561*cdf0e10cSrcweir                     {
562*cdf0e10cSrcweir                         if ( SwitchToShared( sal_True, sal_False ) )
563*cdf0e10cSrcweir                         {
564*cdf0e10cSrcweir                             ScViewData* pViewData = GetViewData();
565*cdf0e10cSrcweir                             ScTabView* pTabView = ( pViewData ? dynamic_cast< ScTabView* >( pViewData->GetView() ) : NULL );
566*cdf0e10cSrcweir                             if ( pTabView )
567*cdf0e10cSrcweir                             {
568*cdf0e10cSrcweir                                 pTabView->UpdateLayerLocks();
569*cdf0e10cSrcweir                             }
570*cdf0e10cSrcweir                         }
571*cdf0e10cSrcweir                         else
572*cdf0e10cSrcweir                         {
573*cdf0e10cSrcweir                             // switching to shared mode has failed, the document should be opened readonly
574*cdf0e10cSrcweir                             // TODO/LATER: And error message should be shown here probably
575*cdf0e10cSrcweir                             SetReadOnlyUI( sal_True );
576*cdf0e10cSrcweir                         }
577*cdf0e10cSrcweir                     }
578*cdf0e10cSrcweir                 }
579*cdf0e10cSrcweir                 break;
580*cdf0e10cSrcweir             case SFX_EVENT_VIEWCREATED:
581*cdf0e10cSrcweir                 {
582*cdf0e10cSrcweir                     if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading() )
583*cdf0e10cSrcweir                     {
584*cdf0e10cSrcweir                         ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
585*cdf0e10cSrcweir                         if ( aAppOptions.GetShowSharedDocumentWarning() )
586*cdf0e10cSrcweir                         {
587*cdf0e10cSrcweir                             WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
588*cdf0e10cSrcweir                                 ScGlobal::GetRscString( STR_SHARED_DOC_WARNING ) );
589*cdf0e10cSrcweir                             aBox.SetDefaultCheckBoxText();
590*cdf0e10cSrcweir                             aBox.Execute();
591*cdf0e10cSrcweir                             sal_Bool bChecked = aBox.GetCheckBoxState();
592*cdf0e10cSrcweir                             if ( bChecked )
593*cdf0e10cSrcweir                             {
594*cdf0e10cSrcweir                                 aAppOptions.SetShowSharedDocumentWarning( !bChecked );
595*cdf0e10cSrcweir                                 SC_MOD()->SetAppOptions( aAppOptions );
596*cdf0e10cSrcweir                             }
597*cdf0e10cSrcweir                         }
598*cdf0e10cSrcweir                     }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir                     try
601*cdf0e10cSrcweir                     {
602*cdf0e10cSrcweir                         uno::Reference< uno::XComponentContext > xContext;
603*cdf0e10cSrcweir                         uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
604*cdf0e10cSrcweir                         uno::Reference< beans::XPropertySet > xProp( xServiceManager, uno::UNO_QUERY_THROW );
605*cdf0e10cSrcweir                         xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) >>= xContext;
606*cdf0e10cSrcweir                         if ( xContext.is() )
607*cdf0e10cSrcweir                         {
608*cdf0e10cSrcweir                             uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW );
609*cdf0e10cSrcweir                             uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration(
610*cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocumentJob" ) ) );
611*cdf0e10cSrcweir                             if ( xEnum.is() )
612*cdf0e10cSrcweir                             {
613*cdf0e10cSrcweir                                 while ( xEnum->hasMoreElements() )
614*cdf0e10cSrcweir                                 {
615*cdf0e10cSrcweir                                     uno::Any aAny = xEnum->nextElement();
616*cdf0e10cSrcweir                                     uno::Reference< lang::XSingleComponentFactory > xFactory;
617*cdf0e10cSrcweir                                     aAny >>= xFactory;
618*cdf0e10cSrcweir                                     if ( xFactory.is() )
619*cdf0e10cSrcweir                                     {
620*cdf0e10cSrcweir                                         uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
621*cdf0e10cSrcweir                                         uno::Sequence< beans::NamedValue > aArgsForJob(1);
622*cdf0e10cSrcweir                                         ScViewData* pViewData = GetViewData();
623*cdf0e10cSrcweir                                         SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : NULL );
624*cdf0e10cSrcweir                                         SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : NULL );
625*cdf0e10cSrcweir                                         SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : NULL );
626*cdf0e10cSrcweir                                         uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : 0 );
627*cdf0e10cSrcweir                                         uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
628*cdf0e10cSrcweir                                         aArgsForJob[0] = beans::NamedValue( ::rtl::OUString::createFromAscii( "SpreadsheetView" ),
629*cdf0e10cSrcweir                                             uno::makeAny( xSpreadsheetView ) );
630*cdf0e10cSrcweir                                         xJob->execute( aArgsForJob );
631*cdf0e10cSrcweir                                     }
632*cdf0e10cSrcweir                                 }
633*cdf0e10cSrcweir                             }
634*cdf0e10cSrcweir                         }
635*cdf0e10cSrcweir                     }
636*cdf0e10cSrcweir                     catch ( uno::Exception & )
637*cdf0e10cSrcweir                     {
638*cdf0e10cSrcweir                     }
639*cdf0e10cSrcweir                 }
640*cdf0e10cSrcweir                 break;
641*cdf0e10cSrcweir             case SFX_EVENT_SAVEDOC:
642*cdf0e10cSrcweir                 {
643*cdf0e10cSrcweir                     if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() )
644*cdf0e10cSrcweir                     {
645*cdf0e10cSrcweir                         bool bSuccess = false;
646*cdf0e10cSrcweir                         bool bRetry = true;
647*cdf0e10cSrcweir                         while ( bRetry )
648*cdf0e10cSrcweir                         {
649*cdf0e10cSrcweir                             bRetry = false;
650*cdf0e10cSrcweir                             uno::Reference< frame::XModel > xModel;
651*cdf0e10cSrcweir                             try
652*cdf0e10cSrcweir                             {
653*cdf0e10cSrcweir                                 // load shared file
654*cdf0e10cSrcweir                                 xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW );
655*cdf0e10cSrcweir                                 uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir                                 // check if shared flag is set in shared file
658*cdf0e10cSrcweir                                 bool bShared = false;
659*cdf0e10cSrcweir                                 ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
660*cdf0e10cSrcweir                                 ScDocShell* pSharedDocShell = ( pDocObj ? dynamic_cast< ScDocShell* >( pDocObj->GetObjectShell() ) : NULL );
661*cdf0e10cSrcweir                                 if ( pSharedDocShell )
662*cdf0e10cSrcweir                                 {
663*cdf0e10cSrcweir                                     bShared = pSharedDocShell->HasSharedXMLFlagSet();
664*cdf0e10cSrcweir                                 }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir                                 // #i87870# check if shared status was disabled and enabled again
667*cdf0e10cSrcweir                                 bool bOwnEntry = false;
668*cdf0e10cSrcweir                                 bool bEntriesNotAccessible = false;
669*cdf0e10cSrcweir                                 try
670*cdf0e10cSrcweir                                 {
671*cdf0e10cSrcweir                                     ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
672*cdf0e10cSrcweir                                     bOwnEntry = aControlFile.HasOwnEntry();
673*cdf0e10cSrcweir                                 }
674*cdf0e10cSrcweir                                 catch ( uno::Exception& )
675*cdf0e10cSrcweir                                 {
676*cdf0e10cSrcweir                                     bEntriesNotAccessible = true;
677*cdf0e10cSrcweir                                 }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir                                 if ( bShared && bOwnEntry )
680*cdf0e10cSrcweir                                 {
681*cdf0e10cSrcweir                                     uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir                                     if ( xStorable->isReadonly() )
684*cdf0e10cSrcweir                                     {
685*cdf0e10cSrcweir                                         xCloseable->close( sal_True );
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir                                         String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) );
688*cdf0e10cSrcweir                                         bool bNoLockAccess = false;
689*cdf0e10cSrcweir                                         try
690*cdf0e10cSrcweir                                         {
691*cdf0e10cSrcweir                                             ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
692*cdf0e10cSrcweir                                             uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData();
693*cdf0e10cSrcweir                                             if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
694*cdf0e10cSrcweir                                             {
695*cdf0e10cSrcweir                                                 if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() > 0 )
696*cdf0e10cSrcweir                                                 {
697*cdf0e10cSrcweir                                                     aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
698*cdf0e10cSrcweir                                                 }
699*cdf0e10cSrcweir                                                 else if ( aData[LOCKFILE_SYSUSERNAME_ID].getLength() > 0 )
700*cdf0e10cSrcweir                                                 {
701*cdf0e10cSrcweir                                                     aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
702*cdf0e10cSrcweir                                                 }
703*cdf0e10cSrcweir                                             }
704*cdf0e10cSrcweir                                         }
705*cdf0e10cSrcweir                                         catch ( uno::Exception& )
706*cdf0e10cSrcweir                                         {
707*cdf0e10cSrcweir                                             bNoLockAccess = true;
708*cdf0e10cSrcweir                                         }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir                                         if ( bNoLockAccess )
711*cdf0e10cSrcweir                                         {
712*cdf0e10cSrcweir                                             // TODO/LATER: in future an error regarding impossibility to open file for writing could be shown
713*cdf0e10cSrcweir                                             ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
714*cdf0e10cSrcweir                                         }
715*cdf0e10cSrcweir                                         else
716*cdf0e10cSrcweir                                         {
717*cdf0e10cSrcweir                                             String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_SAVE_LATER ) );
718*cdf0e10cSrcweir                                             aMessage.SearchAndReplaceAscii( "%1", aUserName );
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir                                             WarningBox aBox( GetActiveDialogParent(), WinBits( WB_RETRY_CANCEL | WB_DEF_RETRY ), aMessage );
721*cdf0e10cSrcweir                                             if ( aBox.Execute() == RET_RETRY )
722*cdf0e10cSrcweir                                             {
723*cdf0e10cSrcweir                                                 bRetry = true;
724*cdf0e10cSrcweir                                             }
725*cdf0e10cSrcweir                                         }
726*cdf0e10cSrcweir                                     }
727*cdf0e10cSrcweir                                     else
728*cdf0e10cSrcweir                                     {
729*cdf0e10cSrcweir                                         // merge changes from shared file into temp file
730*cdf0e10cSrcweir                                         bool bSaveToShared = false;
731*cdf0e10cSrcweir                                         if ( pSharedDocShell )
732*cdf0e10cSrcweir                                         {
733*cdf0e10cSrcweir                                             bSaveToShared = MergeSharedDocument( pSharedDocShell );
734*cdf0e10cSrcweir                                         }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir                                         // close shared file
737*cdf0e10cSrcweir                                         xCloseable->close( sal_True );
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir                                         // TODO: keep file lock on shared file
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir                                         // store to shared file
742*cdf0e10cSrcweir                                         if ( bSaveToShared )
743*cdf0e10cSrcweir                                         {
744*cdf0e10cSrcweir                                             bool bChangedViewSettings = false;
745*cdf0e10cSrcweir                                             ScChangeViewSettings* pChangeViewSet = aDocument.GetChangeViewSettings();
746*cdf0e10cSrcweir                                             if ( pChangeViewSet && pChangeViewSet->ShowChanges() )
747*cdf0e10cSrcweir                                             {
748*cdf0e10cSrcweir                                                 pChangeViewSet->SetShowChanges( sal_False );
749*cdf0e10cSrcweir                                                 pChangeViewSet->SetShowAccepted( sal_False );
750*cdf0e10cSrcweir                                                 aDocument.SetChangeViewSettings( *pChangeViewSet );
751*cdf0e10cSrcweir                                                 bChangedViewSettings = true;
752*cdf0e10cSrcweir                                             }
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir                                             uno::Reference< frame::XStorable > xStor( GetModel(), uno::UNO_QUERY_THROW );
755*cdf0e10cSrcweir                                             // TODO/LATER: More entries from the MediaDescriptor might be interesting for the merge
756*cdf0e10cSrcweir                                             uno::Sequence< beans::PropertyValue > aValues(1);
757*cdf0e10cSrcweir                                             aValues[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
758*cdf0e10cSrcweir                                             aValues[0].Value <<= ::rtl::OUString( GetMedium()->GetFilter()->GetFilterName() );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir                                             SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
761*cdf0e10cSrcweir                                             if ( pPasswordItem && pPasswordItem->GetValue().Len() )
762*cdf0e10cSrcweir                                             {
763*cdf0e10cSrcweir                                                 aValues.realloc( 2 );
764*cdf0e10cSrcweir                                                 aValues[1].Name = ::rtl::OUString::createFromAscii( "Password" );
765*cdf0e10cSrcweir                                                 aValues[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
766*cdf0e10cSrcweir                                             }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir                                             SC_MOD()->SetInSharedDocSaving( true );
769*cdf0e10cSrcweir                                             xStor->storeToURL( GetSharedFileURL(), aValues );
770*cdf0e10cSrcweir                                             SC_MOD()->SetInSharedDocSaving( false );
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir                                             if ( bChangedViewSettings )
773*cdf0e10cSrcweir                                             {
774*cdf0e10cSrcweir                                                 pChangeViewSet->SetShowChanges( sal_True );
775*cdf0e10cSrcweir                                                 pChangeViewSet->SetShowAccepted( sal_True );
776*cdf0e10cSrcweir                                                 aDocument.SetChangeViewSettings( *pChangeViewSet );
777*cdf0e10cSrcweir                                             }
778*cdf0e10cSrcweir                                         }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir                                         bSuccess = true;
781*cdf0e10cSrcweir                                         GetUndoManager()->Clear();
782*cdf0e10cSrcweir                                     }
783*cdf0e10cSrcweir                                 }
784*cdf0e10cSrcweir                                 else
785*cdf0e10cSrcweir                                 {
786*cdf0e10cSrcweir                                     xCloseable->close( sal_True );
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir                                     if ( bEntriesNotAccessible )
789*cdf0e10cSrcweir                                     {
790*cdf0e10cSrcweir                                         // TODO/LATER: in future an error regarding impossibility to write to share control file could be shown
791*cdf0e10cSrcweir                                         ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
792*cdf0e10cSrcweir                                     }
793*cdf0e10cSrcweir                                     else
794*cdf0e10cSrcweir                                     {
795*cdf0e10cSrcweir                                         WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
796*cdf0e10cSrcweir                                             ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) );
797*cdf0e10cSrcweir                                         aBox.Execute();
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir                                         SfxBindings* pBindings = GetViewBindings();
800*cdf0e10cSrcweir                                         if ( pBindings )
801*cdf0e10cSrcweir                                         {
802*cdf0e10cSrcweir                                             pBindings->ExecuteSynchron( SID_SAVEASDOC );
803*cdf0e10cSrcweir                                         }
804*cdf0e10cSrcweir                                     }
805*cdf0e10cSrcweir                                 }
806*cdf0e10cSrcweir                             }
807*cdf0e10cSrcweir                             catch ( uno::Exception& )
808*cdf0e10cSrcweir                             {
809*cdf0e10cSrcweir                                 DBG_ERROR( "SFX_EVENT_SAVEDOC: caught exception\n" );
810*cdf0e10cSrcweir                                 SC_MOD()->SetInSharedDocSaving( false );
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir                                 try
813*cdf0e10cSrcweir                                 {
814*cdf0e10cSrcweir                                     uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
815*cdf0e10cSrcweir                                     xClose->close( sal_True );
816*cdf0e10cSrcweir                                 }
817*cdf0e10cSrcweir                                 catch ( uno::Exception& )
818*cdf0e10cSrcweir                                 {
819*cdf0e10cSrcweir                                 }
820*cdf0e10cSrcweir                             }
821*cdf0e10cSrcweir                         }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir                         if ( !bSuccess )
824*cdf0e10cSrcweir                             SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // this error code will produce no error message, but will break the further saving process
825*cdf0e10cSrcweir                     }
826*cdf0e10cSrcweir                     if (pSheetSaveData)
827*cdf0e10cSrcweir                         pSheetSaveData->SetInSupportedSave(true);
828*cdf0e10cSrcweir                 }
829*cdf0e10cSrcweir                 break;
830*cdf0e10cSrcweir             case SFX_EVENT_SAVEASDOC:
831*cdf0e10cSrcweir             case SFX_EVENT_SAVETODOC:
832*cdf0e10cSrcweir                 // #i108978# If no event is sent before saving, there will also be no "...DONE" event,
833*cdf0e10cSrcweir                 // and SAVE/SAVEAS can't be distinguished from SAVETO. So stream copying is only enabled
834*cdf0e10cSrcweir                 // if there is a SAVE/SAVEAS/SAVETO event first.
835*cdf0e10cSrcweir                 if (pSheetSaveData)
836*cdf0e10cSrcweir                     pSheetSaveData->SetInSupportedSave(true);
837*cdf0e10cSrcweir                 break;
838*cdf0e10cSrcweir             case SFX_EVENT_SAVEDOCDONE:
839*cdf0e10cSrcweir                 {
840*cdf0e10cSrcweir                     if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() )
841*cdf0e10cSrcweir                     {
842*cdf0e10cSrcweir                     }
843*cdf0e10cSrcweir                     UseSheetSaveEntries();      // use positions from saved file for next saving
844*cdf0e10cSrcweir                     if (pSheetSaveData)
845*cdf0e10cSrcweir                         pSheetSaveData->SetInSupportedSave(false);
846*cdf0e10cSrcweir                 }
847*cdf0e10cSrcweir                 break;
848*cdf0e10cSrcweir             case SFX_EVENT_SAVEASDOCDONE:
849*cdf0e10cSrcweir                 // new positions are used after "save" and "save as", but not "save to"
850*cdf0e10cSrcweir                 UseSheetSaveEntries();      // use positions from saved file for next saving
851*cdf0e10cSrcweir                 if (pSheetSaveData)
852*cdf0e10cSrcweir                     pSheetSaveData->SetInSupportedSave(false);
853*cdf0e10cSrcweir                 break;
854*cdf0e10cSrcweir             case SFX_EVENT_SAVETODOCDONE:
855*cdf0e10cSrcweir                 // only reset the flag, don't use the new positions
856*cdf0e10cSrcweir                 if (pSheetSaveData)
857*cdf0e10cSrcweir                     pSheetSaveData->SetInSupportedSave(false);
858*cdf0e10cSrcweir                 break;
859*cdf0e10cSrcweir             default:
860*cdf0e10cSrcweir                 {
861*cdf0e10cSrcweir                 }
862*cdf0e10cSrcweir                 break;
863*cdf0e10cSrcweir         }
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir 	// Inhalte fuer Organizer laden
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::LoadFrom( SfxMedium& rMedium )
871*cdf0e10cSrcweir {
872*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::LoadFrom" );
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 	WaitObject aWait( GetActiveDialogParent() );
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir     if (GetMedium())
881*cdf0e10cSrcweir     {
882*cdf0e10cSrcweir         SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
883*cdf0e10cSrcweir         nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
884*cdf0e10cSrcweir     }
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir     //  until loading/saving only the styles in XML is implemented,
887*cdf0e10cSrcweir     //  load the whole file
888*cdf0e10cSrcweir     bRet = LoadXML( &rMedium, NULL );
889*cdf0e10cSrcweir     InitItems();
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     SfxObjectShell::LoadFrom( rMedium );
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir 	return bRet;
894*cdf0e10cSrcweir }
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir static void lcl_parseHtmlFilterOption(const OUString& rOption, LanguageType& rLang, bool& rDateConvert)
897*cdf0e10cSrcweir {
898*cdf0e10cSrcweir     OUStringBuffer aBuf;
899*cdf0e10cSrcweir     OUString aTokens[2];
900*cdf0e10cSrcweir     sal_Int32 n = rOption.getLength();
901*cdf0e10cSrcweir     const sal_Unicode* p = rOption.getStr();
902*cdf0e10cSrcweir     sal_Int32 nTokenId = 0;
903*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < n; ++i)
904*cdf0e10cSrcweir     {
905*cdf0e10cSrcweir         const sal_Unicode c = p[i];
906*cdf0e10cSrcweir         if (c == sal_Unicode(' '))
907*cdf0e10cSrcweir         {
908*cdf0e10cSrcweir             if (aBuf.getLength())
909*cdf0e10cSrcweir                 aTokens[nTokenId++] = aBuf.makeStringAndClear();
910*cdf0e10cSrcweir         }
911*cdf0e10cSrcweir         else
912*cdf0e10cSrcweir             aBuf.append(c);
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir         if (nTokenId >= 2)
915*cdf0e10cSrcweir             break;
916*cdf0e10cSrcweir     }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir     if (aBuf.getLength())
919*cdf0e10cSrcweir         aTokens[nTokenId] = aBuf.makeStringAndClear();
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir     rLang = static_cast<LanguageType>(aTokens[0].toInt32());
922*cdf0e10cSrcweir     rDateConvert = static_cast<bool>(aTokens[1].toInt32());
923*cdf0e10cSrcweir }
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir namespace {
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir class LoadMediumGuard
928*cdf0e10cSrcweir {
929*cdf0e10cSrcweir public:
930*cdf0e10cSrcweir     explicit LoadMediumGuard(ScDocument* pDoc) :
931*cdf0e10cSrcweir         mpDoc(pDoc)
932*cdf0e10cSrcweir     {
933*cdf0e10cSrcweir         mpDoc->SetLoadingMedium(true);
934*cdf0e10cSrcweir     }
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir     ~LoadMediumGuard()
937*cdf0e10cSrcweir     {
938*cdf0e10cSrcweir         mpDoc->SetLoadingMedium(false);
939*cdf0e10cSrcweir     }
940*cdf0e10cSrcweir private:
941*cdf0e10cSrcweir     ScDocument* mpDoc;
942*cdf0e10cSrcweir };
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::ConvertFrom( SfxMedium& rMedium )
947*cdf0e10cSrcweir {
948*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertFrom" );
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir     LoadMediumGuard aLoadGuard(&aDocument);
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;				// sal_False heisst Benutzerabbruch !!
953*cdf0e10cSrcweir 									// bei Fehler: Fehler am Stream setzen!!
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir 	GetUndoManager()->Clear();
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir 	// ob nach dem Import optimale Spaltenbreiten gesetzt werden sollen
960*cdf0e10cSrcweir 	sal_Bool bSetColWidths = sal_False;
961*cdf0e10cSrcweir 	sal_Bool bSetSimpleTextColWidths = sal_False;
962*cdf0e10cSrcweir 	sal_Bool bSimpleColWidth[MAXCOLCOUNT];
963*cdf0e10cSrcweir 	memset( bSimpleColWidth, 1, (MAXCOLCOUNT) * sizeof(sal_Bool) );
964*cdf0e10cSrcweir 	ScRange aColWidthRange;
965*cdf0e10cSrcweir 	// ob nach dem Import optimale Zeilenhoehen gesetzt werden sollen
966*cdf0e10cSrcweir 	sal_Bool bSetRowHeights = sal_False;
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir 	aConvFilterName.Erase(); //@ #BugId 54198
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir 	//	Alle Filter brauchen die komplette Datei am Stueck (nicht asynchron),
971*cdf0e10cSrcweir 	//	darum vorher per CreateFileStream dafuer sorgen, dass die komplette
972*cdf0e10cSrcweir 	//	Datei uebertragen wird.
973*cdf0e10cSrcweir 	rMedium.GetPhysicalName();	//! CreateFileStream direkt rufen, wenn verfuegbar
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir     SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
976*cdf0e10cSrcweir     nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : com::sun::star::document::UpdateDocMode::NO_UPDATE;
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     const SfxFilter* pFilter = rMedium.GetFilter();
979*cdf0e10cSrcweir 	if (pFilter)
980*cdf0e10cSrcweir 	{
981*cdf0e10cSrcweir 		String aFltName = pFilter->GetFilterName();
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 		aConvFilterName=aFltName; //@ #BugId 54198
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir 		sal_Bool bCalc3 = ( aFltName.EqualsAscii(pFilterSc30) );
986*cdf0e10cSrcweir 		sal_Bool bCalc4 = ( aFltName.EqualsAscii(pFilterSc40) );
987*cdf0e10cSrcweir 		if (!bCalc3 && !bCalc4)
988*cdf0e10cSrcweir 			aDocument.SetInsertingFromOtherDoc( sal_True );
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir         if (aFltName.EqualsAscii(pFilterXML))
991*cdf0e10cSrcweir 			bRet = LoadXML( &rMedium, NULL );
992*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterSc10))
993*cdf0e10cSrcweir 		{
994*cdf0e10cSrcweir 			SvStream* pStream = rMedium.GetInStream();
995*cdf0e10cSrcweir 			if (pStream)
996*cdf0e10cSrcweir 			{
997*cdf0e10cSrcweir 				FltError eError = ScFormatFilter::Get().ScImportStarCalc10( *pStream, &aDocument );
998*cdf0e10cSrcweir 				if (eError != eERR_OK)
999*cdf0e10cSrcweir 				{
1000*cdf0e10cSrcweir 					if (!GetError())
1001*cdf0e10cSrcweir 						SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1002*cdf0e10cSrcweir 				}
1003*cdf0e10cSrcweir 				else
1004*cdf0e10cSrcweir 					bRet = sal_True;
1005*cdf0e10cSrcweir 			}
1006*cdf0e10cSrcweir 		}
1007*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterLotus))
1008*cdf0e10cSrcweir 		{
1009*cdf0e10cSrcweir 			String sItStr;
1010*cdf0e10cSrcweir 			SfxItemSet*	 pSet = rMedium.GetItemSet();
1011*cdf0e10cSrcweir 			const SfxPoolItem* pItem;
1012*cdf0e10cSrcweir 			if ( pSet && SFX_ITEM_SET ==
1013*cdf0e10cSrcweir 				 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1014*cdf0e10cSrcweir 			{
1015*cdf0e10cSrcweir 				sItStr = ((const SfxStringItem*)pItem)->GetValue();
1016*cdf0e10cSrcweir 			}
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir 			if (sItStr.Len() == 0)
1019*cdf0e10cSrcweir 			{
1020*cdf0e10cSrcweir 				//	default for lotus import (from API without options):
1021*cdf0e10cSrcweir 				//	IBM_437 encoding
1022*cdf0e10cSrcweir 				sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_437 );
1023*cdf0e10cSrcweir 			}
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir 			ScColumn::bDoubleAlloc = sal_True;
1026*cdf0e10cSrcweir 			FltError eError = ScFormatFilter::Get().ScImportLotus123( rMedium, &aDocument,
1027*cdf0e10cSrcweir 												ScGlobal::GetCharsetValue(sItStr));
1028*cdf0e10cSrcweir 			ScColumn::bDoubleAlloc = sal_False;
1029*cdf0e10cSrcweir 			if (eError != eERR_OK)
1030*cdf0e10cSrcweir 			{
1031*cdf0e10cSrcweir 				if (!GetError())
1032*cdf0e10cSrcweir 					SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir 				if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1035*cdf0e10cSrcweir 					bRet = sal_True;
1036*cdf0e10cSrcweir 			}
1037*cdf0e10cSrcweir 			else
1038*cdf0e10cSrcweir 				bRet = sal_True;
1039*cdf0e10cSrcweir 			bSetColWidths = sal_True;
1040*cdf0e10cSrcweir 			bSetRowHeights = sal_True;
1041*cdf0e10cSrcweir 		}
1042*cdf0e10cSrcweir 		else if ( aFltName.EqualsAscii(pFilterExcel4) || aFltName.EqualsAscii(pFilterExcel5) ||
1043*cdf0e10cSrcweir 				   aFltName.EqualsAscii(pFilterExcel95) || aFltName.EqualsAscii(pFilterExcel97) ||
1044*cdf0e10cSrcweir 				   aFltName.EqualsAscii(pFilterEx4Temp) || aFltName.EqualsAscii(pFilterEx5Temp) ||
1045*cdf0e10cSrcweir 				   aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp) )
1046*cdf0e10cSrcweir 		{
1047*cdf0e10cSrcweir 			EXCIMPFORMAT eFormat = EIF_AUTO;
1048*cdf0e10cSrcweir 			if ( aFltName.EqualsAscii(pFilterExcel4) || aFltName.EqualsAscii(pFilterEx4Temp) )
1049*cdf0e10cSrcweir 				eFormat = EIF_BIFF_LE4;
1050*cdf0e10cSrcweir 			else if ( aFltName.EqualsAscii(pFilterExcel5) || aFltName.EqualsAscii(pFilterExcel95) ||
1051*cdf0e10cSrcweir 					  aFltName.EqualsAscii(pFilterEx5Temp) || aFltName.EqualsAscii(pFilterEx95Temp) )
1052*cdf0e10cSrcweir 				eFormat = EIF_BIFF5;
1053*cdf0e10cSrcweir 			else if ( aFltName.EqualsAscii(pFilterExcel97) || aFltName.EqualsAscii(pFilterEx97Temp) )
1054*cdf0e10cSrcweir 				eFormat = EIF_BIFF8;
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir 			MakeDrawLayer();				//! im Filter
1057*cdf0e10cSrcweir             CalcOutputFactor();             // #93255# prepare update of row height
1058*cdf0e10cSrcweir 			ScColumn::bDoubleAlloc = sal_True;
1059*cdf0e10cSrcweir 			FltError eError = ScFormatFilter::Get().ScImportExcel( rMedium, &aDocument, eFormat );
1060*cdf0e10cSrcweir 			ScColumn::bDoubleAlloc = sal_False;
1061*cdf0e10cSrcweir 			aDocument.UpdateFontCharSet();
1062*cdf0e10cSrcweir 			if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
1063*cdf0e10cSrcweir 				aDocument.UpdateChartListenerCollection();				//! fuer alle Importe?
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir 			// #75299# all graphics objects must have names
1066*cdf0e10cSrcweir 			aDocument.EnsureGraphicNames();
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir 			if (eError == SCWARN_IMPORT_RANGE_OVERFLOW)
1069*cdf0e10cSrcweir 			{
1070*cdf0e10cSrcweir 				if (!GetError())
1071*cdf0e10cSrcweir 					SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1072*cdf0e10cSrcweir 				bRet = sal_True;
1073*cdf0e10cSrcweir 			}
1074*cdf0e10cSrcweir 			else if (eError != eERR_OK)
1075*cdf0e10cSrcweir 			{
1076*cdf0e10cSrcweir 				if (!GetError())
1077*cdf0e10cSrcweir 					SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1078*cdf0e10cSrcweir 			}
1079*cdf0e10cSrcweir 			else
1080*cdf0e10cSrcweir 				bRet = sal_True;
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir             // #93255# update of row height done inside of Excel filter to speed up chart import
1083*cdf0e10cSrcweir //            bSetRowHeights = sal_True;      //  #75357# optimal row heights must be updated
1084*cdf0e10cSrcweir 		}
1085*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterAscii))
1086*cdf0e10cSrcweir 		{
1087*cdf0e10cSrcweir 			SfxItemSet*	 pSet = rMedium.GetItemSet();
1088*cdf0e10cSrcweir 			const SfxPoolItem* pItem;
1089*cdf0e10cSrcweir 			ScAsciiOptions aOptions;
1090*cdf0e10cSrcweir 			sal_Bool bOptInit = sal_False;
1091*cdf0e10cSrcweir 
1092*cdf0e10cSrcweir 			if ( pSet && SFX_ITEM_SET ==
1093*cdf0e10cSrcweir 				 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1094*cdf0e10cSrcweir 			{
1095*cdf0e10cSrcweir 				aOptions.ReadFromString( ((const SfxStringItem*)pItem)->GetValue() );
1096*cdf0e10cSrcweir 				bOptInit = sal_True;
1097*cdf0e10cSrcweir 			}
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir 			if ( !bOptInit )
1100*cdf0e10cSrcweir 			{
1101*cdf0e10cSrcweir 				//	default for ascii import (from API without options):
1102*cdf0e10cSrcweir 				//	ISO8859-1/MS_1252 encoding, comma, double quotes
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir 				aOptions.SetCharSet( RTL_TEXTENCODING_MS_1252 );
1105*cdf0e10cSrcweir 				aOptions.SetFieldSeps( (sal_Unicode) ',' );
1106*cdf0e10cSrcweir 				aOptions.SetTextSep( (sal_Unicode) '"' );
1107*cdf0e10cSrcweir 			}
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir 			FltError eError = eERR_OK;
1110*cdf0e10cSrcweir 			sal_Bool bOverflow = sal_False;
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir 			if( ! rMedium.IsStorage() )
1113*cdf0e10cSrcweir 			{
1114*cdf0e10cSrcweir 				ScImportExport	aImpEx( &aDocument );
1115*cdf0e10cSrcweir 				aImpEx.SetExtOptions( aOptions );
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir 				SvStream* pInStream = rMedium.GetInStream();
1118*cdf0e10cSrcweir 				if (pInStream)
1119*cdf0e10cSrcweir 				{
1120*cdf0e10cSrcweir 					pInStream->SetStreamCharSet( aOptions.GetCharSet() );
1121*cdf0e10cSrcweir 					pInStream->Seek( 0 );
1122*cdf0e10cSrcweir                     bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL() );
1123*cdf0e10cSrcweir 					eError = bRet ? eERR_OK : SCERR_IMPORT_CONNECT;
1124*cdf0e10cSrcweir 					aDocument.StartAllListeners();
1125*cdf0e10cSrcweir 					aDocument.SetDirty();
1126*cdf0e10cSrcweir 					bOverflow = aImpEx.IsOverflow();
1127*cdf0e10cSrcweir 				}
1128*cdf0e10cSrcweir 				else
1129*cdf0e10cSrcweir 				{
1130*cdf0e10cSrcweir 					DBG_ERROR( "No Stream" );
1131*cdf0e10cSrcweir 				}
1132*cdf0e10cSrcweir 			}
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir 			if (eError != eERR_OK)
1135*cdf0e10cSrcweir 			{
1136*cdf0e10cSrcweir 				if (!GetError())
1137*cdf0e10cSrcweir 					SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1138*cdf0e10cSrcweir 			}
1139*cdf0e10cSrcweir 			else if ( bOverflow )
1140*cdf0e10cSrcweir 			{
1141*cdf0e10cSrcweir 				if (!GetError())
1142*cdf0e10cSrcweir 					SetError(SCWARN_IMPORT_RANGE_OVERFLOW, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1143*cdf0e10cSrcweir 			}
1144*cdf0e10cSrcweir 			bSetColWidths = sal_True;
1145*cdf0e10cSrcweir 			bSetSimpleTextColWidths = sal_True;
1146*cdf0e10cSrcweir 		}
1147*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterDBase))
1148*cdf0e10cSrcweir 		{
1149*cdf0e10cSrcweir 			String sItStr;
1150*cdf0e10cSrcweir 			SfxItemSet*	 pSet = rMedium.GetItemSet();
1151*cdf0e10cSrcweir 			const SfxPoolItem* pItem;
1152*cdf0e10cSrcweir 			if ( pSet && SFX_ITEM_SET ==
1153*cdf0e10cSrcweir 				 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1154*cdf0e10cSrcweir 			{
1155*cdf0e10cSrcweir 				sItStr = ((const SfxStringItem*)pItem)->GetValue();
1156*cdf0e10cSrcweir 			}
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir 			if (sItStr.Len() == 0)
1159*cdf0e10cSrcweir 			{
1160*cdf0e10cSrcweir 				//	default for dBase import (from API without options):
1161*cdf0e10cSrcweir 				//	IBM_850 encoding
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir 				sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
1164*cdf0e10cSrcweir 			}
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 			sal_uLong eError = DBaseImport( rMedium.GetPhysicalName(),
1167*cdf0e10cSrcweir 					ScGlobal::GetCharsetValue(sItStr), bSimpleColWidth );
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir 			if (eError != eERR_OK)
1170*cdf0e10cSrcweir 			{
1171*cdf0e10cSrcweir 				if (!GetError())
1172*cdf0e10cSrcweir 					SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1173*cdf0e10cSrcweir 				bRet = ( eError == SCWARN_IMPORT_RANGE_OVERFLOW );
1174*cdf0e10cSrcweir 			}
1175*cdf0e10cSrcweir 			else
1176*cdf0e10cSrcweir 				bRet = sal_True;
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir 			aColWidthRange.aStart.SetRow( 1 );	// Spaltenheader nicht
1179*cdf0e10cSrcweir 			bSetColWidths = sal_True;
1180*cdf0e10cSrcweir 			bSetSimpleTextColWidths = sal_True;
1181*cdf0e10cSrcweir 			// Memo-Felder fuehren zu einem bSimpleColWidth[nCol]==FALSE
1182*cdf0e10cSrcweir 			for ( SCCOL nCol=0; nCol <= MAXCOL && !bSetRowHeights; nCol++ )
1183*cdf0e10cSrcweir 			{
1184*cdf0e10cSrcweir 				if ( !bSimpleColWidth[nCol] )
1185*cdf0e10cSrcweir 					bSetRowHeights = sal_True;
1186*cdf0e10cSrcweir 			}
1187*cdf0e10cSrcweir 		}
1188*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterDif))
1189*cdf0e10cSrcweir 		{
1190*cdf0e10cSrcweir 			SvStream* pStream = rMedium.GetInStream();
1191*cdf0e10cSrcweir 			if (pStream)
1192*cdf0e10cSrcweir 			{
1193*cdf0e10cSrcweir 				FltError eError;
1194*cdf0e10cSrcweir 				String sItStr;
1195*cdf0e10cSrcweir 				SfxItemSet*	 pSet = rMedium.GetItemSet();
1196*cdf0e10cSrcweir 				const SfxPoolItem* pItem;
1197*cdf0e10cSrcweir 				if ( pSet && SFX_ITEM_SET ==
1198*cdf0e10cSrcweir 					 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1199*cdf0e10cSrcweir 				{
1200*cdf0e10cSrcweir 					sItStr = ((const SfxStringItem*)pItem)->GetValue();
1201*cdf0e10cSrcweir 				}
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir 				if (sItStr.Len() == 0)
1204*cdf0e10cSrcweir 				{
1205*cdf0e10cSrcweir 					//	default for DIF import (from API without options):
1206*cdf0e10cSrcweir 					//	ISO8859-1/MS_1252 encoding
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir 					sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
1209*cdf0e10cSrcweir 				}
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir 				eError = ScFormatFilter::Get().ScImportDif( *pStream, &aDocument, ScAddress(0,0,0),
1212*cdf0e10cSrcweir 									ScGlobal::GetCharsetValue(sItStr));
1213*cdf0e10cSrcweir 				if (eError != eERR_OK)
1214*cdf0e10cSrcweir 				{
1215*cdf0e10cSrcweir 					if (!GetError())
1216*cdf0e10cSrcweir 						SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir 					if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1219*cdf0e10cSrcweir 						bRet = sal_True;
1220*cdf0e10cSrcweir 				}
1221*cdf0e10cSrcweir 				else
1222*cdf0e10cSrcweir 					bRet = sal_True;
1223*cdf0e10cSrcweir 			}
1224*cdf0e10cSrcweir 			bSetColWidths = sal_True;
1225*cdf0e10cSrcweir 			bSetSimpleTextColWidths = sal_True;
1226*cdf0e10cSrcweir 			bSetRowHeights = sal_True;
1227*cdf0e10cSrcweir 		}
1228*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterSylk))
1229*cdf0e10cSrcweir 		{
1230*cdf0e10cSrcweir 			FltError eError = SCERR_IMPORT_UNKNOWN;
1231*cdf0e10cSrcweir 			if( !rMedium.IsStorage() )
1232*cdf0e10cSrcweir 			{
1233*cdf0e10cSrcweir 				ScImportExport aImpEx( &aDocument );
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir 				SvStream* pInStream = rMedium.GetInStream();
1236*cdf0e10cSrcweir 				if (pInStream)
1237*cdf0e10cSrcweir 				{
1238*cdf0e10cSrcweir 					pInStream->Seek( 0 );
1239*cdf0e10cSrcweir                     bRet = aImpEx.ImportStream( *pInStream, rMedium.GetBaseURL(), SOT_FORMATSTR_ID_SYLK );
1240*cdf0e10cSrcweir 					eError = bRet ? eERR_OK : SCERR_IMPORT_UNKNOWN;
1241*cdf0e10cSrcweir 					aDocument.StartAllListeners();
1242*cdf0e10cSrcweir 					aDocument.SetDirty();
1243*cdf0e10cSrcweir 				}
1244*cdf0e10cSrcweir 				else
1245*cdf0e10cSrcweir 				{
1246*cdf0e10cSrcweir 					DBG_ERROR( "No Stream" );
1247*cdf0e10cSrcweir 				}
1248*cdf0e10cSrcweir 			}
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir 			if ( eError != eERR_OK && !GetError() )
1251*cdf0e10cSrcweir 				SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1252*cdf0e10cSrcweir 			bSetColWidths = sal_True;
1253*cdf0e10cSrcweir 			bSetSimpleTextColWidths = sal_True;
1254*cdf0e10cSrcweir 			bSetRowHeights = sal_True;
1255*cdf0e10cSrcweir 		}
1256*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterQPro6))
1257*cdf0e10cSrcweir         {
1258*cdf0e10cSrcweir             ScColumn::bDoubleAlloc = sal_True;
1259*cdf0e10cSrcweir             FltError eError = ScFormatFilter::Get().ScImportQuattroPro( rMedium, &aDocument);
1260*cdf0e10cSrcweir             ScColumn::bDoubleAlloc = sal_False;
1261*cdf0e10cSrcweir             if (eError != eERR_OK)
1262*cdf0e10cSrcweir             {
1263*cdf0e10cSrcweir                 if (!GetError())
1264*cdf0e10cSrcweir                     SetError( eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
1265*cdf0e10cSrcweir                 if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1266*cdf0e10cSrcweir                     bRet = sal_True;
1267*cdf0e10cSrcweir             }
1268*cdf0e10cSrcweir             else
1269*cdf0e10cSrcweir                 bRet = sal_True;
1270*cdf0e10cSrcweir             // TODO: Filter should set column widths. Not doing it here, it may
1271*cdf0e10cSrcweir             // result in very narrow or wide columns, depending on content.
1272*cdf0e10cSrcweir             // Setting row heights makes cells with font size attribution or
1273*cdf0e10cSrcweir             // wrapping enabled look nicer..
1274*cdf0e10cSrcweir             bSetRowHeights = sal_True;
1275*cdf0e10cSrcweir         }
1276*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterRtf))
1277*cdf0e10cSrcweir 		{
1278*cdf0e10cSrcweir 			FltError eError = SCERR_IMPORT_UNKNOWN;
1279*cdf0e10cSrcweir 			if( !rMedium.IsStorage() )
1280*cdf0e10cSrcweir 			{
1281*cdf0e10cSrcweir 				SvStream* pInStream = rMedium.GetInStream();
1282*cdf0e10cSrcweir 				if (pInStream)
1283*cdf0e10cSrcweir 				{
1284*cdf0e10cSrcweir 					pInStream->Seek( 0 );
1285*cdf0e10cSrcweir 					ScRange aRange;
1286*cdf0e10cSrcweir                     eError = ScFormatFilter::Get().ScImportRTF( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange );
1287*cdf0e10cSrcweir 					if (eError != eERR_OK)
1288*cdf0e10cSrcweir 					{
1289*cdf0e10cSrcweir 						if (!GetError())
1290*cdf0e10cSrcweir 							SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir 						if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1293*cdf0e10cSrcweir 							bRet = sal_True;
1294*cdf0e10cSrcweir 					}
1295*cdf0e10cSrcweir 					else
1296*cdf0e10cSrcweir 						bRet = sal_True;
1297*cdf0e10cSrcweir 					aDocument.StartAllListeners();
1298*cdf0e10cSrcweir 					aDocument.SetDirty();
1299*cdf0e10cSrcweir 					bSetColWidths = sal_True;
1300*cdf0e10cSrcweir 					bSetRowHeights = sal_True;
1301*cdf0e10cSrcweir 				}
1302*cdf0e10cSrcweir 				else
1303*cdf0e10cSrcweir 				{
1304*cdf0e10cSrcweir 					DBG_ERROR( "No Stream" );
1305*cdf0e10cSrcweir 				}
1306*cdf0e10cSrcweir 			}
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir 			if ( eError != eERR_OK && !GetError() )
1309*cdf0e10cSrcweir 				SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1310*cdf0e10cSrcweir 		}
1311*cdf0e10cSrcweir 		else if (aFltName.EqualsAscii(pFilterHtml) || aFltName.EqualsAscii(pFilterHtmlWebQ))
1312*cdf0e10cSrcweir 		{
1313*cdf0e10cSrcweir 			FltError eError = SCERR_IMPORT_UNKNOWN;
1314*cdf0e10cSrcweir 			sal_Bool bWebQuery = aFltName.EqualsAscii(pFilterHtmlWebQ);
1315*cdf0e10cSrcweir 			if( !rMedium.IsStorage() )
1316*cdf0e10cSrcweir 			{
1317*cdf0e10cSrcweir 				SvStream* pInStream = rMedium.GetInStream();
1318*cdf0e10cSrcweir 				if (pInStream)
1319*cdf0e10cSrcweir 				{
1320*cdf0e10cSrcweir                     LanguageType eLang = LANGUAGE_SYSTEM;
1321*cdf0e10cSrcweir                     bool bDateConvert = false;
1322*cdf0e10cSrcweir                     SfxItemSet*	 pSet = rMedium.GetItemSet();
1323*cdf0e10cSrcweir                     const SfxPoolItem* pItem;
1324*cdf0e10cSrcweir                     if ( pSet && SFX_ITEM_SET ==
1325*cdf0e10cSrcweir                          pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
1326*cdf0e10cSrcweir                     {
1327*cdf0e10cSrcweir                         String aFilterOption = (static_cast<const SfxStringItem*>(pItem))->GetValue();
1328*cdf0e10cSrcweir                         lcl_parseHtmlFilterOption(aFilterOption, eLang, bDateConvert);
1329*cdf0e10cSrcweir                     }
1330*cdf0e10cSrcweir 
1331*cdf0e10cSrcweir 					pInStream->Seek( 0 );
1332*cdf0e10cSrcweir 					ScRange aRange;
1333*cdf0e10cSrcweir 					// HTML macht eigenes ColWidth/RowHeight
1334*cdf0e10cSrcweir 					CalcOutputFactor();
1335*cdf0e10cSrcweir                     SvNumberFormatter aNumFormatter(aDocument.GetServiceManager(), eLang);
1336*cdf0e10cSrcweir                     eError = ScFormatFilter::Get().ScImportHTML( *pInStream, rMedium.GetBaseURL(), &aDocument, aRange,
1337*cdf0e10cSrcweir 											GetOutputFactor(), !bWebQuery, &aNumFormatter, bDateConvert );
1338*cdf0e10cSrcweir 					if (eError != eERR_OK)
1339*cdf0e10cSrcweir 					{
1340*cdf0e10cSrcweir 						if (!GetError())
1341*cdf0e10cSrcweir 							SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1342*cdf0e10cSrcweir 
1343*cdf0e10cSrcweir 						if( ( eError & ERRCODE_WARNING_MASK ) == ERRCODE_WARNING_MASK )
1344*cdf0e10cSrcweir 							bRet = sal_True;
1345*cdf0e10cSrcweir 					}
1346*cdf0e10cSrcweir 					else
1347*cdf0e10cSrcweir 						bRet = sal_True;
1348*cdf0e10cSrcweir 					aDocument.StartAllListeners();
1349*cdf0e10cSrcweir 					aDocument.SetDirty();
1350*cdf0e10cSrcweir 				}
1351*cdf0e10cSrcweir 				else
1352*cdf0e10cSrcweir 				{
1353*cdf0e10cSrcweir 					DBG_ERROR( "No Stream" );
1354*cdf0e10cSrcweir 				}
1355*cdf0e10cSrcweir 			}
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir 			if ( eError != eERR_OK && !GetError() )
1358*cdf0e10cSrcweir 				SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1359*cdf0e10cSrcweir 		}
1360*cdf0e10cSrcweir 		else
1361*cdf0e10cSrcweir 		{
1362*cdf0e10cSrcweir 			if (!GetError())
1363*cdf0e10cSrcweir 				SetError(SCERR_IMPORT_NI, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
1364*cdf0e10cSrcweir 		}
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir 		if (!bCalc3)
1367*cdf0e10cSrcweir 			aDocument.SetInsertingFromOtherDoc( sal_False );
1368*cdf0e10cSrcweir 	}
1369*cdf0e10cSrcweir 	else
1370*cdf0e10cSrcweir 	{
1371*cdf0e10cSrcweir 		DBG_ERROR("Kein Filter bei ConvertFrom");
1372*cdf0e10cSrcweir 	}
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir 	InitItems();
1375*cdf0e10cSrcweir 	CalcOutputFactor();
1376*cdf0e10cSrcweir 	if ( bRet && (bSetColWidths || bSetRowHeights) )
1377*cdf0e10cSrcweir 	{	// Spaltenbreiten/Zeilenhoehen anpassen, Basis 100% Zoom
1378*cdf0e10cSrcweir 		Fraction aZoom( 1, 1 );
1379*cdf0e10cSrcweir 		double nPPTX = ScGlobal::nScreenPPTX * (double) aZoom
1380*cdf0e10cSrcweir 			/ GetOutputFactor();	// Faktor ist Drucker zu Bildschirm
1381*cdf0e10cSrcweir 		double nPPTY = ScGlobal::nScreenPPTY * (double) aZoom;
1382*cdf0e10cSrcweir 		VirtualDevice aVirtDev;
1383*cdf0e10cSrcweir 		//	all sheets (for Excel import)
1384*cdf0e10cSrcweir 		SCTAB nTabCount = aDocument.GetTableCount();
1385*cdf0e10cSrcweir 		for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1386*cdf0e10cSrcweir 		{
1387*cdf0e10cSrcweir             SCCOL nEndCol;
1388*cdf0e10cSrcweir             SCROW nEndRow;
1389*cdf0e10cSrcweir             aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1390*cdf0e10cSrcweir 			aColWidthRange.aEnd.SetCol( nEndCol );
1391*cdf0e10cSrcweir 			aColWidthRange.aEnd.SetRow( nEndRow );
1392*cdf0e10cSrcweir 			ScMarkData aMark;
1393*cdf0e10cSrcweir 			aMark.SetMarkArea( aColWidthRange );
1394*cdf0e10cSrcweir 			aMark.MarkToMulti();
1395*cdf0e10cSrcweir 			// Reihenfolge erst Breite dann Hoehe ist wichtig (vergl. hund.rtf)
1396*cdf0e10cSrcweir 			if ( bSetColWidths )
1397*cdf0e10cSrcweir 			{
1398*cdf0e10cSrcweir 				for ( SCCOL nCol=0; nCol <= nEndCol; nCol++ )
1399*cdf0e10cSrcweir 				{
1400*cdf0e10cSrcweir 					sal_uInt16 nWidth = aDocument.GetOptimalColWidth(
1401*cdf0e10cSrcweir 						nCol, nTab, &aVirtDev, nPPTX, nPPTY, aZoom, aZoom, sal_False, &aMark,
1402*cdf0e10cSrcweir 						(bSetSimpleTextColWidths && bSimpleColWidth[nCol]) );
1403*cdf0e10cSrcweir 					aDocument.SetColWidth( nCol, nTab,
1404*cdf0e10cSrcweir 						nWidth + (sal_uInt16)ScGlobal::nLastColWidthExtra );
1405*cdf0e10cSrcweir 				}
1406*cdf0e10cSrcweir 			}
1407*cdf0e10cSrcweir //			if ( bSetRowHeights )
1408*cdf0e10cSrcweir //			{
1409*cdf0e10cSrcweir //				//	nExtra must be 0
1410*cdf0e10cSrcweir //				aDocument.SetOptimalHeight(	0, nEndRow, nTab, 0, &aVirtDev,
1411*cdf0e10cSrcweir //					nPPTX, nPPTY, aZoom, aZoom, sal_False );
1412*cdf0e10cSrcweir //			}
1413*cdf0e10cSrcweir 		}
1414*cdf0e10cSrcweir 		if ( bSetRowHeights )
1415*cdf0e10cSrcweir 			UpdateAllRowHeights();		// with vdev or printer, depending on configuration
1416*cdf0e10cSrcweir 	}
1417*cdf0e10cSrcweir 	FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir 	// #73762# invalidate eventually temporary table areas
1420*cdf0e10cSrcweir 	if ( bRet )
1421*cdf0e10cSrcweir 		aDocument.InvalidateTableArea();
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir 	bIsEmpty = sal_False;
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir 	return bRet;
1426*cdf0e10cSrcweir }
1427*cdf0e10cSrcweir 
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir ScDocShell::PrepareSaveGuard::PrepareSaveGuard( ScDocShell& rDocShell )
1430*cdf0e10cSrcweir     : mrDocShell( rDocShell)
1431*cdf0e10cSrcweir {
1432*cdf0e10cSrcweir     // DoEnterHandler not here (because of AutoSave), is in ExecuteSave.
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir     ScChartListenerCollection* pCharts = mrDocShell.aDocument.GetChartListenerCollection();
1435*cdf0e10cSrcweir     if (pCharts)
1436*cdf0e10cSrcweir         pCharts->UpdateDirtyCharts();                           // Charts to be updated.
1437*cdf0e10cSrcweir     mrDocShell.aDocument.StopTemporaryChartLock();
1438*cdf0e10cSrcweir     if (mrDocShell.pAutoStyleList)
1439*cdf0e10cSrcweir         mrDocShell.pAutoStyleList->ExecuteAllNow();             // Execute template timeouts now.
1440*cdf0e10cSrcweir     if (mrDocShell.aDocument.HasExternalRefManager())
1441*cdf0e10cSrcweir     {
1442*cdf0e10cSrcweir         ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
1443*cdf0e10cSrcweir         if (pRefMgr && pRefMgr->hasExternalData())
1444*cdf0e10cSrcweir         {
1445*cdf0e10cSrcweir             pRefMgr->setAllCacheTableReferencedStati( false);
1446*cdf0e10cSrcweir             mrDocShell.aDocument.MarkUsedExternalReferences();  // Mark tables of external references to be written.
1447*cdf0e10cSrcweir         }
1448*cdf0e10cSrcweir     }
1449*cdf0e10cSrcweir     if (mrDocShell.GetCreateMode()== SFX_CREATE_MODE_STANDARD)
1450*cdf0e10cSrcweir         mrDocShell.SfxObjectShell::SetVisArea( Rectangle() );   // "Normally" worked on => no VisArea.
1451*cdf0e10cSrcweir }
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir ScDocShell::PrepareSaveGuard::~PrepareSaveGuard()
1454*cdf0e10cSrcweir {
1455*cdf0e10cSrcweir     if (mrDocShell.aDocument.HasExternalRefManager())
1456*cdf0e10cSrcweir     {
1457*cdf0e10cSrcweir         ScExternalRefManager* pRefMgr = mrDocShell.aDocument.GetExternalRefManager();
1458*cdf0e10cSrcweir         if (pRefMgr && pRefMgr->hasExternalData())
1459*cdf0e10cSrcweir         {
1460*cdf0e10cSrcweir             // Prevent accidental data loss due to lack of knowledge.
1461*cdf0e10cSrcweir             pRefMgr->setAllCacheTableReferencedStati( true);
1462*cdf0e10cSrcweir         }
1463*cdf0e10cSrcweir     }
1464*cdf0e10cSrcweir }
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir 
1467*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::Save()
1468*cdf0e10cSrcweir {
1469*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::Save" );
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir     PrepareSaveGuard aPrepareGuard( *this);
1474*cdf0e10cSrcweir 
1475*cdf0e10cSrcweir 	//	wait cursor is handled with progress bar
1476*cdf0e10cSrcweir     sal_Bool bRet = SfxObjectShell::Save();
1477*cdf0e10cSrcweir 	if( bRet )
1478*cdf0e10cSrcweir         bRet = SaveXML( GetMedium(), NULL );
1479*cdf0e10cSrcweir 	return bRet;
1480*cdf0e10cSrcweir }
1481*cdf0e10cSrcweir 
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::SaveAs( SfxMedium& rMedium )
1484*cdf0e10cSrcweir {
1485*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::SaveAs" );
1486*cdf0e10cSrcweir 
1487*cdf0e10cSrcweir #if ENABLE_SHEET_PROTECTION
1488*cdf0e10cSrcweir     ScTabViewShell* pViewShell = GetBestViewShell();
1489*cdf0e10cSrcweir     if (pViewShell && ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_OOO))
1490*cdf0e10cSrcweir     {
1491*cdf0e10cSrcweir         if (!pViewShell->ExecuteRetypePassDlg(PASSHASH_OOO))
1492*cdf0e10cSrcweir             // password re-type cancelled.  Don't save the document.
1493*cdf0e10cSrcweir             return false;
1494*cdf0e10cSrcweir     }
1495*cdf0e10cSrcweir #endif
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1498*cdf0e10cSrcweir 
1499*cdf0e10cSrcweir     PrepareSaveGuard aPrepareGuard( *this);
1500*cdf0e10cSrcweir 
1501*cdf0e10cSrcweir 	//	wait cursor is handled with progress bar
1502*cdf0e10cSrcweir     sal_Bool bRet = SfxObjectShell::SaveAs( rMedium );
1503*cdf0e10cSrcweir 	if( bRet )
1504*cdf0e10cSrcweir         bRet = SaveXML( &rMedium, NULL );
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir 	return bRet;
1507*cdf0e10cSrcweir }
1508*cdf0e10cSrcweir 
1509*cdf0e10cSrcweir 
1510*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::IsInformationLost()
1511*cdf0e10cSrcweir {
1512*cdf0e10cSrcweir /*
1513*cdf0e10cSrcweir 	const SfxFilter *pFilt = GetMedium()->GetFilter();
1514*cdf0e10cSrcweir 	sal_Bool bRet = pFilt && pFilt->IsAlienFormat() && bNoInformLost;
1515*cdf0e10cSrcweir 	if (bNoInformLost)					// nur einmal!!
1516*cdf0e10cSrcweir 		bNoInformLost = sal_False;
1517*cdf0e10cSrcweir 	return bRet;
1518*cdf0e10cSrcweir */
1519*cdf0e10cSrcweir 	//!!! bei Gelegenheit ein korrekte eigene Behandlung einbauen
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir 	return SfxObjectShell::IsInformationLost();
1522*cdf0e10cSrcweir }
1523*cdf0e10cSrcweir 
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir // Xcl-like column width measured in characters of standard font.
1526*cdf0e10cSrcweir xub_StrLen lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
1527*cdf0e10cSrcweir {
1528*cdf0e10cSrcweir     // double fColScale = 1.0;
1529*cdf0e10cSrcweir 	double	f = nWidth;
1530*cdf0e10cSrcweir 	f *= 1328.0 / 25.0;
1531*cdf0e10cSrcweir 	f += 90.0;
1532*cdf0e10cSrcweir 	f *= 1.0 / 23.0;
1533*cdf0e10cSrcweir 	// f /= fColScale * 256.0;
1534*cdf0e10cSrcweir 	f /= 256.0;
1535*cdf0e10cSrcweir 
1536*cdf0e10cSrcweir 	return xub_StrLen( f );
1537*cdf0e10cSrcweir }
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir void lcl_ScDocShell_GetFixedWidthString( String& rStr, const ScDocument& rDoc,
1541*cdf0e10cSrcweir         SCTAB nTab, SCCOL nCol, sal_Bool bValue, SvxCellHorJustify eHorJust )
1542*cdf0e10cSrcweir {
1543*cdf0e10cSrcweir     xub_StrLen nLen = lcl_ScDocShell_GetColWidthInChars(
1544*cdf0e10cSrcweir             rDoc.GetColWidth( nCol, nTab ) );
1545*cdf0e10cSrcweir     if ( nLen < rStr.Len() )
1546*cdf0e10cSrcweir     {
1547*cdf0e10cSrcweir         if ( bValue )
1548*cdf0e10cSrcweir             rStr.AssignAscii( "###" );
1549*cdf0e10cSrcweir         rStr.Erase( nLen );
1550*cdf0e10cSrcweir     }
1551*cdf0e10cSrcweir     if ( nLen > rStr.Len() )
1552*cdf0e10cSrcweir     {
1553*cdf0e10cSrcweir         if ( bValue && eHorJust == SVX_HOR_JUSTIFY_STANDARD )
1554*cdf0e10cSrcweir             eHorJust = SVX_HOR_JUSTIFY_RIGHT;
1555*cdf0e10cSrcweir         switch ( eHorJust )
1556*cdf0e10cSrcweir         {
1557*cdf0e10cSrcweir             case SVX_HOR_JUSTIFY_RIGHT:
1558*cdf0e10cSrcweir             {
1559*cdf0e10cSrcweir                 String aTmp;
1560*cdf0e10cSrcweir                 aTmp.Fill( nLen - rStr.Len() );
1561*cdf0e10cSrcweir                 rStr.Insert( aTmp, 0 );
1562*cdf0e10cSrcweir             }
1563*cdf0e10cSrcweir             break;
1564*cdf0e10cSrcweir             case SVX_HOR_JUSTIFY_CENTER:
1565*cdf0e10cSrcweir             {
1566*cdf0e10cSrcweir                 xub_StrLen nLen2 = (nLen - rStr.Len()) / 2;
1567*cdf0e10cSrcweir                 String aTmp;
1568*cdf0e10cSrcweir                 aTmp.Fill( nLen2 );
1569*cdf0e10cSrcweir                 rStr.Insert( aTmp, 0 );
1570*cdf0e10cSrcweir                 rStr.Expand( nLen );
1571*cdf0e10cSrcweir             }
1572*cdf0e10cSrcweir             break;
1573*cdf0e10cSrcweir             default:
1574*cdf0e10cSrcweir                 rStr.Expand( nLen );
1575*cdf0e10cSrcweir         }
1576*cdf0e10cSrcweir     }
1577*cdf0e10cSrcweir }
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir 
1580*cdf0e10cSrcweir void lcl_ScDocShell_WriteEmptyFixedWidthString( SvStream& rStream,
1581*cdf0e10cSrcweir         const ScDocument& rDoc, SCTAB nTab, SCCOL nCol )
1582*cdf0e10cSrcweir {
1583*cdf0e10cSrcweir     String aString;
1584*cdf0e10cSrcweir     lcl_ScDocShell_GetFixedWidthString( aString, rDoc, nTab, nCol, sal_False,
1585*cdf0e10cSrcweir             SVX_HOR_JUSTIFY_STANDARD );
1586*cdf0e10cSrcweir     rStream.WriteUnicodeOrByteText( aString );
1587*cdf0e10cSrcweir }
1588*cdf0e10cSrcweir 
1589*cdf0e10cSrcweir 
1590*cdf0e10cSrcweir void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt )
1591*cdf0e10cSrcweir {
1592*cdf0e10cSrcweir     sal_Unicode cDelim    = rAsciiOpt.nFieldSepCode;
1593*cdf0e10cSrcweir     sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
1594*cdf0e10cSrcweir     CharSet eCharSet      = rAsciiOpt.eCharSet;
1595*cdf0e10cSrcweir     sal_Bool bFixedWidth      = rAsciiOpt.bFixedWidth;
1596*cdf0e10cSrcweir     sal_Bool bSaveAsShown     = rAsciiOpt.bSaveAsShown;
1597*cdf0e10cSrcweir 
1598*cdf0e10cSrcweir 	CharSet eOldCharSet = rStream.GetStreamCharSet();
1599*cdf0e10cSrcweir 	rStream.SetStreamCharSet( eCharSet );
1600*cdf0e10cSrcweir 	sal_uInt16 nOldNumberFormatInt = rStream.GetNumberFormatInt();
1601*cdf0e10cSrcweir     ByteString aStrDelimEncoded;    // only used if not Unicode
1602*cdf0e10cSrcweir     UniString aStrDelimDecoded;     // only used if context encoding
1603*cdf0e10cSrcweir     ByteString aDelimEncoded;
1604*cdf0e10cSrcweir     UniString aDelimDecoded;
1605*cdf0e10cSrcweir     sal_Bool bContextOrNotAsciiEncoding;
1606*cdf0e10cSrcweir 	if ( eCharSet == RTL_TEXTENCODING_UNICODE )
1607*cdf0e10cSrcweir     {
1608*cdf0e10cSrcweir 		rStream.StartWritingUnicodeText();
1609*cdf0e10cSrcweir         bContextOrNotAsciiEncoding = sal_False;
1610*cdf0e10cSrcweir     }
1611*cdf0e10cSrcweir     else
1612*cdf0e10cSrcweir     {
1613*cdf0e10cSrcweir         aStrDelimEncoded = ByteString( cStrDelim, eCharSet );
1614*cdf0e10cSrcweir         aDelimEncoded = ByteString( cDelim, eCharSet );
1615*cdf0e10cSrcweir         rtl_TextEncodingInfo aInfo;
1616*cdf0e10cSrcweir         aInfo.StructSize = sizeof(aInfo);
1617*cdf0e10cSrcweir         if ( rtl_getTextEncodingInfo( eCharSet, &aInfo ) )
1618*cdf0e10cSrcweir         {
1619*cdf0e10cSrcweir             bContextOrNotAsciiEncoding =
1620*cdf0e10cSrcweir                 (((aInfo.Flags & RTL_TEXTENCODING_INFO_CONTEXT) != 0) ||
1621*cdf0e10cSrcweir                  ((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
1622*cdf0e10cSrcweir             if ( bContextOrNotAsciiEncoding )
1623*cdf0e10cSrcweir             {
1624*cdf0e10cSrcweir                 aStrDelimDecoded = String( aStrDelimEncoded, eCharSet );
1625*cdf0e10cSrcweir                 aDelimDecoded = String( aDelimEncoded, eCharSet );
1626*cdf0e10cSrcweir             }
1627*cdf0e10cSrcweir         }
1628*cdf0e10cSrcweir         else
1629*cdf0e10cSrcweir             bContextOrNotAsciiEncoding = sal_False;
1630*cdf0e10cSrcweir     }
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir 	SCCOL nStartCol = 0;
1633*cdf0e10cSrcweir 	SCROW nStartRow = 0;
1634*cdf0e10cSrcweir 	SCTAB nTab = GetSaveTab();
1635*cdf0e10cSrcweir 	SCCOL nEndCol;
1636*cdf0e10cSrcweir 	SCROW nEndRow;
1637*cdf0e10cSrcweir 	aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir 	ScProgress aProgress( this, ScGlobal::GetRscString( STR_SAVE_DOC ), nEndRow );
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir 	String aString;
1642*cdf0e10cSrcweir 
1643*cdf0e10cSrcweir 	ScTabViewShell*	pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
1644*cdf0e10cSrcweir 	const ScViewOptions& rOpt = (pViewSh)
1645*cdf0e10cSrcweir 								? pViewSh->GetViewData()->GetOptions()
1646*cdf0e10cSrcweir 								: aDocument.GetViewOptions();
1647*cdf0e10cSrcweir 	sal_Bool bShowFormulas = rOpt.GetOption( VOPT_FORMULAS );
1648*cdf0e10cSrcweir 	sal_Bool bTabProtect = aDocument.IsTabProtected( nTab );
1649*cdf0e10cSrcweir 
1650*cdf0e10cSrcweir 	SCCOL nCol;
1651*cdf0e10cSrcweir 	SCROW nRow;
1652*cdf0e10cSrcweir 	SCCOL nNextCol = nStartCol;
1653*cdf0e10cSrcweir 	SCROW nNextRow = nStartRow;
1654*cdf0e10cSrcweir 	SCCOL nEmptyCol;
1655*cdf0e10cSrcweir 	SCROW nEmptyRow;
1656*cdf0e10cSrcweir 	SvNumberFormatter& rFormatter = *aDocument.GetFormatTable();
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir 	ScHorizontalCellIterator aIter( &aDocument, nTab, nStartCol, nStartRow,
1659*cdf0e10cSrcweir 		nEndCol, nEndRow );
1660*cdf0e10cSrcweir 	ScBaseCell* pCell;
1661*cdf0e10cSrcweir     while ( ( pCell = aIter.GetNext( nCol, nRow ) ) != NULL )
1662*cdf0e10cSrcweir     {
1663*cdf0e10cSrcweir         sal_Bool bProgress = sal_False;		// only upon line change
1664*cdf0e10cSrcweir         if ( nNextRow < nRow )
1665*cdf0e10cSrcweir         {   // empty rows or/and empty columns up to end of row
1666*cdf0e10cSrcweir             bProgress = sal_True;
1667*cdf0e10cSrcweir             for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
1668*cdf0e10cSrcweir             {   // remaining columns of last row
1669*cdf0e10cSrcweir                 if ( bFixedWidth )
1670*cdf0e10cSrcweir                     lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1671*cdf0e10cSrcweir                             aDocument, nTab, nEmptyCol );
1672*cdf0e10cSrcweir                 else if ( cDelim != 0 )
1673*cdf0e10cSrcweir                     rStream.WriteUniOrByteChar( cDelim );
1674*cdf0e10cSrcweir             }
1675*cdf0e10cSrcweir             endlub( rStream );
1676*cdf0e10cSrcweir             nNextRow++;
1677*cdf0e10cSrcweir             for ( nEmptyRow = nNextRow; nEmptyRow < nRow; nEmptyRow++ )
1678*cdf0e10cSrcweir             {   // completely empty rows
1679*cdf0e10cSrcweir                 for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
1680*cdf0e10cSrcweir                 {
1681*cdf0e10cSrcweir                     if ( bFixedWidth )
1682*cdf0e10cSrcweir                         lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1683*cdf0e10cSrcweir                                 aDocument, nTab, nEmptyCol );
1684*cdf0e10cSrcweir                     else if ( cDelim != 0 )
1685*cdf0e10cSrcweir                         rStream.WriteUniOrByteChar( cDelim );
1686*cdf0e10cSrcweir                 }
1687*cdf0e10cSrcweir                 endlub( rStream );
1688*cdf0e10cSrcweir             }
1689*cdf0e10cSrcweir             for ( nEmptyCol = nStartCol; nEmptyCol < nCol; nEmptyCol++ )
1690*cdf0e10cSrcweir             {   // empty columns at beginning of row
1691*cdf0e10cSrcweir                 if ( bFixedWidth )
1692*cdf0e10cSrcweir                     lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1693*cdf0e10cSrcweir                             aDocument, nTab, nEmptyCol );
1694*cdf0e10cSrcweir                 else if ( cDelim != 0 )
1695*cdf0e10cSrcweir                     rStream.WriteUniOrByteChar( cDelim );
1696*cdf0e10cSrcweir             }
1697*cdf0e10cSrcweir             nNextRow = nRow;
1698*cdf0e10cSrcweir         }
1699*cdf0e10cSrcweir         else if ( nNextCol < nCol )
1700*cdf0e10cSrcweir         {   // empty columns in same row
1701*cdf0e10cSrcweir             for ( nEmptyCol = nNextCol; nEmptyCol < nCol; nEmptyCol++ )
1702*cdf0e10cSrcweir             {   // columns in between
1703*cdf0e10cSrcweir                 if ( bFixedWidth )
1704*cdf0e10cSrcweir                     lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1705*cdf0e10cSrcweir                             aDocument, nTab, nEmptyCol );
1706*cdf0e10cSrcweir                 else if ( cDelim != 0 )
1707*cdf0e10cSrcweir                     rStream.WriteUniOrByteChar( cDelim );
1708*cdf0e10cSrcweir             }
1709*cdf0e10cSrcweir         }
1710*cdf0e10cSrcweir         if ( nCol == nEndCol )
1711*cdf0e10cSrcweir         {
1712*cdf0e10cSrcweir             bProgress = sal_True;
1713*cdf0e10cSrcweir             nNextCol = nStartCol;
1714*cdf0e10cSrcweir             nNextRow = nRow + 1;
1715*cdf0e10cSrcweir         }
1716*cdf0e10cSrcweir         else
1717*cdf0e10cSrcweir             nNextCol = nCol + 1;
1718*cdf0e10cSrcweir 
1719*cdf0e10cSrcweir         CellType eType = pCell->GetCellType();
1720*cdf0e10cSrcweir         if ( bTabProtect )
1721*cdf0e10cSrcweir         {
1722*cdf0e10cSrcweir             const ScProtectionAttr* pProtAttr =
1723*cdf0e10cSrcweir                 (const ScProtectionAttr*) aDocument.GetAttr(
1724*cdf0e10cSrcweir                                                             nCol, nRow, nTab, ATTR_PROTECTION );
1725*cdf0e10cSrcweir             if ( pProtAttr->GetHideCell() ||
1726*cdf0e10cSrcweir                     ( eType == CELLTYPE_FORMULA && bShowFormulas &&
1727*cdf0e10cSrcweir                       pProtAttr->GetHideFormula() ) )
1728*cdf0e10cSrcweir                 eType = CELLTYPE_NONE;	// hide
1729*cdf0e10cSrcweir         }
1730*cdf0e10cSrcweir         sal_Bool bString;
1731*cdf0e10cSrcweir         switch ( eType )
1732*cdf0e10cSrcweir         {
1733*cdf0e10cSrcweir             case CELLTYPE_NOTE:
1734*cdf0e10cSrcweir             case CELLTYPE_NONE:
1735*cdf0e10cSrcweir                 aString.Erase();
1736*cdf0e10cSrcweir                 bString = sal_False;
1737*cdf0e10cSrcweir                 break;
1738*cdf0e10cSrcweir             case CELLTYPE_FORMULA :
1739*cdf0e10cSrcweir                 {
1740*cdf0e10cSrcweir                     sal_uInt16 nErrCode;
1741*cdf0e10cSrcweir                     if ( bShowFormulas )
1742*cdf0e10cSrcweir                     {
1743*cdf0e10cSrcweir                         ((ScFormulaCell*)pCell)->GetFormula( aString );
1744*cdf0e10cSrcweir                         bString = sal_True;
1745*cdf0e10cSrcweir                     }
1746*cdf0e10cSrcweir                     else if ( ( nErrCode = ((ScFormulaCell*)pCell)->GetErrCode() ) != 0 )
1747*cdf0e10cSrcweir                     {
1748*cdf0e10cSrcweir                         aString = ScGlobal::GetErrorString( nErrCode );
1749*cdf0e10cSrcweir                         bString = sal_True;
1750*cdf0e10cSrcweir                     }
1751*cdf0e10cSrcweir                     else if ( ((ScFormulaCell*)pCell)->IsValue() )
1752*cdf0e10cSrcweir                     {
1753*cdf0e10cSrcweir                         sal_uInt32 nFormat;
1754*cdf0e10cSrcweir                         aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1755*cdf0e10cSrcweir                         if ( bFixedWidth || bSaveAsShown )
1756*cdf0e10cSrcweir                         {
1757*cdf0e10cSrcweir                             Color* pDummy;
1758*cdf0e10cSrcweir                             ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1759*cdf0e10cSrcweir                             bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
1760*cdf0e10cSrcweir                         }
1761*cdf0e10cSrcweir                         else
1762*cdf0e10cSrcweir                         {
1763*cdf0e10cSrcweir                             ScCellFormat::GetInputString( pCell, nFormat, aString, rFormatter );
1764*cdf0e10cSrcweir                             bString = sal_False;
1765*cdf0e10cSrcweir                         }
1766*cdf0e10cSrcweir                     }
1767*cdf0e10cSrcweir                     else
1768*cdf0e10cSrcweir                     {
1769*cdf0e10cSrcweir                         if ( bSaveAsShown )
1770*cdf0e10cSrcweir                         {
1771*cdf0e10cSrcweir                             sal_uInt32 nFormat;
1772*cdf0e10cSrcweir                             aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1773*cdf0e10cSrcweir                             Color* pDummy;
1774*cdf0e10cSrcweir                             ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1775*cdf0e10cSrcweir                         }
1776*cdf0e10cSrcweir                         else
1777*cdf0e10cSrcweir                             ((ScFormulaCell*)pCell)->GetString( aString );
1778*cdf0e10cSrcweir                         bString = sal_True;
1779*cdf0e10cSrcweir                     }
1780*cdf0e10cSrcweir                 }
1781*cdf0e10cSrcweir                 break;
1782*cdf0e10cSrcweir             case CELLTYPE_STRING :
1783*cdf0e10cSrcweir                 if ( bSaveAsShown )
1784*cdf0e10cSrcweir                 {
1785*cdf0e10cSrcweir                     sal_uInt32 nFormat;
1786*cdf0e10cSrcweir                     aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1787*cdf0e10cSrcweir                     Color* pDummy;
1788*cdf0e10cSrcweir                     ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1789*cdf0e10cSrcweir                 }
1790*cdf0e10cSrcweir                 else
1791*cdf0e10cSrcweir                     ((ScStringCell*)pCell)->GetString( aString );
1792*cdf0e10cSrcweir                 bString = sal_True;
1793*cdf0e10cSrcweir                 break;
1794*cdf0e10cSrcweir             case CELLTYPE_EDIT :
1795*cdf0e10cSrcweir                 {
1796*cdf0e10cSrcweir                     const EditTextObject* pObj;
1797*cdf0e10cSrcweir                     static_cast<const ScEditCell*>(pCell)->GetData( pObj);
1798*cdf0e10cSrcweir                     EditEngine& rEngine = aDocument.GetEditEngine();
1799*cdf0e10cSrcweir                     rEngine.SetText( *pObj);
1800*cdf0e10cSrcweir                     aString = rEngine.GetText();  // including LF
1801*cdf0e10cSrcweir                     bString = sal_True;
1802*cdf0e10cSrcweir                 }
1803*cdf0e10cSrcweir                 break;
1804*cdf0e10cSrcweir             case CELLTYPE_VALUE :
1805*cdf0e10cSrcweir                 {
1806*cdf0e10cSrcweir                     sal_uInt32 nFormat;
1807*cdf0e10cSrcweir                     aDocument.GetNumberFormat( nCol, nRow, nTab, nFormat );
1808*cdf0e10cSrcweir                     if ( bFixedWidth || bSaveAsShown )
1809*cdf0e10cSrcweir                     {
1810*cdf0e10cSrcweir                         Color* pDummy;
1811*cdf0e10cSrcweir                         ScCellFormat::GetString( pCell, nFormat, aString, &pDummy, rFormatter );
1812*cdf0e10cSrcweir                         bString = bSaveAsShown && rFormatter.IsTextFormat( nFormat);
1813*cdf0e10cSrcweir                     }
1814*cdf0e10cSrcweir                     else
1815*cdf0e10cSrcweir                     {
1816*cdf0e10cSrcweir                         ScCellFormat::GetInputString( pCell, nFormat, aString, rFormatter );
1817*cdf0e10cSrcweir                         bString = sal_False;
1818*cdf0e10cSrcweir                     }
1819*cdf0e10cSrcweir                 }
1820*cdf0e10cSrcweir                 break;
1821*cdf0e10cSrcweir             default:
1822*cdf0e10cSrcweir                 DBG_ERROR( "ScDocShell::AsciiSave: unknown CellType" );
1823*cdf0e10cSrcweir                 aString.Erase();
1824*cdf0e10cSrcweir                 bString = sal_False;
1825*cdf0e10cSrcweir         }
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir         if ( bFixedWidth )
1828*cdf0e10cSrcweir         {
1829*cdf0e10cSrcweir             SvxCellHorJustify eHorJust = (SvxCellHorJustify)
1830*cdf0e10cSrcweir                 ((const SvxHorJustifyItem*) aDocument.GetAttr( nCol, nRow,
1831*cdf0e10cSrcweir                 nTab, ATTR_HOR_JUSTIFY ))->GetValue();
1832*cdf0e10cSrcweir             lcl_ScDocShell_GetFixedWidthString( aString, aDocument, nTab, nCol,
1833*cdf0e10cSrcweir                     !bString, eHorJust );
1834*cdf0e10cSrcweir             rStream.WriteUnicodeOrByteText( aString );
1835*cdf0e10cSrcweir         }
1836*cdf0e10cSrcweir         else
1837*cdf0e10cSrcweir         {
1838*cdf0e10cSrcweir             if (!bString && cStrDelim != 0 && aString.Len() > 0)
1839*cdf0e10cSrcweir             {
1840*cdf0e10cSrcweir                 sal_Unicode c = aString.GetChar(0);
1841*cdf0e10cSrcweir                 bString = (c == cStrDelim || c == ' ' ||
1842*cdf0e10cSrcweir                         aString.GetChar( aString.Len()-1) == ' ' ||
1843*cdf0e10cSrcweir                         aString.Search( cStrDelim) != STRING_NOTFOUND);
1844*cdf0e10cSrcweir                 if (!bString && cDelim != 0)
1845*cdf0e10cSrcweir                     bString = (aString.Search( cDelim) != STRING_NOTFOUND);
1846*cdf0e10cSrcweir             }
1847*cdf0e10cSrcweir             if ( bString )
1848*cdf0e10cSrcweir             {
1849*cdf0e10cSrcweir                 if ( cStrDelim != 0 ) //@ BugId 55355
1850*cdf0e10cSrcweir                 {
1851*cdf0e10cSrcweir                     if ( eCharSet == RTL_TEXTENCODING_UNICODE )
1852*cdf0e10cSrcweir                     {
1853*cdf0e10cSrcweir                         xub_StrLen nPos = aString.Search( cStrDelim );
1854*cdf0e10cSrcweir                         // #i116636# quotes are needed if text delimiter (quote), field delimiter, or LF is in the cell text
1855*cdf0e10cSrcweir                         bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
1856*cdf0e10cSrcweir                                             ( nPos != STRING_NOTFOUND ) ||
1857*cdf0e10cSrcweir                                             ( aString.Search( cDelim ) != STRING_NOTFOUND ) ||
1858*cdf0e10cSrcweir                                             ( aString.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
1859*cdf0e10cSrcweir                         while ( nPos != STRING_NOTFOUND )
1860*cdf0e10cSrcweir                         {
1861*cdf0e10cSrcweir                             aString.Insert( cStrDelim, nPos );
1862*cdf0e10cSrcweir                             nPos = aString.Search( cStrDelim, nPos+2 );
1863*cdf0e10cSrcweir                         }
1864*cdf0e10cSrcweir                         if ( bNeedQuotes )
1865*cdf0e10cSrcweir                             rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1866*cdf0e10cSrcweir                         rStream.WriteUnicodeText( aString );
1867*cdf0e10cSrcweir                         if ( bNeedQuotes )
1868*cdf0e10cSrcweir                             rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1869*cdf0e10cSrcweir                     }
1870*cdf0e10cSrcweir                     else
1871*cdf0e10cSrcweir                     {
1872*cdf0e10cSrcweir                         // #105549# This is nasty. The Unicode to byte encoding
1873*cdf0e10cSrcweir                         // may convert typographical quotation marks to ASCII
1874*cdf0e10cSrcweir                         // quotation marks, which may interfer with the delimiter,
1875*cdf0e10cSrcweir                         // so we have to escape delimiters after the string has
1876*cdf0e10cSrcweir                         // been encoded. Since this may happen also with UTF-8
1877*cdf0e10cSrcweir                         // encoded typographical quotation marks if such was
1878*cdf0e10cSrcweir                         // specified as a delimiter we have to check for the full
1879*cdf0e10cSrcweir                         // encoded delimiter string, not just one character.
1880*cdf0e10cSrcweir                         // Now for RTL_TEXTENCODING_ISO_2022_... and similar brain
1881*cdf0e10cSrcweir                         // dead encodings where one code point (and especially a
1882*cdf0e10cSrcweir                         // low ASCII value) may represent different characters, we
1883*cdf0e10cSrcweir                         // have to convert forth and back and forth again. Same for
1884*cdf0e10cSrcweir                         // UTF-7 since it is a context sensitive encoding too.
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir                         if ( bContextOrNotAsciiEncoding )
1887*cdf0e10cSrcweir                         {
1888*cdf0e10cSrcweir                             // to byte encoding
1889*cdf0e10cSrcweir                             ByteString aStrEnc( aString, eCharSet );
1890*cdf0e10cSrcweir                             // back to Unicode
1891*cdf0e10cSrcweir                             UniString aStrDec( aStrEnc, eCharSet );
1892*cdf0e10cSrcweir                             // search on re-decoded string
1893*cdf0e10cSrcweir                             xub_StrLen nPos = aStrDec.Search( aStrDelimDecoded );
1894*cdf0e10cSrcweir                             bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
1895*cdf0e10cSrcweir                                                 ( nPos != STRING_NOTFOUND ) ||
1896*cdf0e10cSrcweir                                                 ( aStrDec.Search( aDelimDecoded ) != STRING_NOTFOUND ) ||
1897*cdf0e10cSrcweir                                                 ( aStrDec.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
1898*cdf0e10cSrcweir                             while ( nPos != STRING_NOTFOUND )
1899*cdf0e10cSrcweir                             {
1900*cdf0e10cSrcweir                                 aStrDec.Insert( aStrDelimDecoded, nPos );
1901*cdf0e10cSrcweir                                 nPos = aStrDec.Search( aStrDelimDecoded,
1902*cdf0e10cSrcweir                                         nPos+1+aStrDelimDecoded.Len() );
1903*cdf0e10cSrcweir                             }
1904*cdf0e10cSrcweir                             // write byte re-encoded
1905*cdf0e10cSrcweir                             if ( bNeedQuotes )
1906*cdf0e10cSrcweir                                 rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1907*cdf0e10cSrcweir                             rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
1908*cdf0e10cSrcweir                             if ( bNeedQuotes )
1909*cdf0e10cSrcweir                                 rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
1910*cdf0e10cSrcweir                         }
1911*cdf0e10cSrcweir                         else
1912*cdf0e10cSrcweir                         {
1913*cdf0e10cSrcweir                             ByteString aStrEnc( aString, eCharSet );
1914*cdf0e10cSrcweir                             // search on encoded string
1915*cdf0e10cSrcweir                             xub_StrLen nPos = aStrEnc.Search( aStrDelimEncoded );
1916*cdf0e10cSrcweir                             bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
1917*cdf0e10cSrcweir                                                 ( nPos != STRING_NOTFOUND ) ||
1918*cdf0e10cSrcweir                                                 ( aStrEnc.Search( aDelimEncoded ) != STRING_NOTFOUND ) ||
1919*cdf0e10cSrcweir                                                 ( aStrEnc.Search( sal_Char(_LF) ) != STRING_NOTFOUND );
1920*cdf0e10cSrcweir                             while ( nPos != STRING_NOTFOUND )
1921*cdf0e10cSrcweir                             {
1922*cdf0e10cSrcweir                                 aStrEnc.Insert( aStrDelimEncoded, nPos );
1923*cdf0e10cSrcweir                                 nPos = aStrEnc.Search( aStrDelimEncoded,
1924*cdf0e10cSrcweir                                         nPos+1+aStrDelimEncoded.Len() );
1925*cdf0e10cSrcweir                             }
1926*cdf0e10cSrcweir                             // write byte encoded
1927*cdf0e10cSrcweir                             if ( bNeedQuotes )
1928*cdf0e10cSrcweir                                 rStream.Write( aStrDelimEncoded.GetBuffer(),
1929*cdf0e10cSrcweir                                         aStrDelimEncoded.Len() );
1930*cdf0e10cSrcweir                             rStream.Write( aStrEnc.GetBuffer(), aStrEnc.Len() );
1931*cdf0e10cSrcweir                             if ( bNeedQuotes )
1932*cdf0e10cSrcweir                                 rStream.Write( aStrDelimEncoded.GetBuffer(),
1933*cdf0e10cSrcweir                                         aStrDelimEncoded.Len() );
1934*cdf0e10cSrcweir                         }
1935*cdf0e10cSrcweir                     }
1936*cdf0e10cSrcweir                 }
1937*cdf0e10cSrcweir                 else
1938*cdf0e10cSrcweir                     rStream.WriteUnicodeOrByteText( aString );
1939*cdf0e10cSrcweir             }
1940*cdf0e10cSrcweir             else
1941*cdf0e10cSrcweir                 rStream.WriteUnicodeOrByteText( aString );
1942*cdf0e10cSrcweir         }
1943*cdf0e10cSrcweir 
1944*cdf0e10cSrcweir         if( nCol < nEndCol )
1945*cdf0e10cSrcweir         {
1946*cdf0e10cSrcweir             if(cDelim!=0) //@ BugId 55355
1947*cdf0e10cSrcweir                 rStream.WriteUniOrByteChar( cDelim );
1948*cdf0e10cSrcweir         }
1949*cdf0e10cSrcweir         else
1950*cdf0e10cSrcweir             endlub( rStream );
1951*cdf0e10cSrcweir 
1952*cdf0e10cSrcweir         if ( bProgress )
1953*cdf0e10cSrcweir             aProgress.SetStateOnPercent( nRow );
1954*cdf0e10cSrcweir     }
1955*cdf0e10cSrcweir 
1956*cdf0e10cSrcweir 	// write out empty if requested
1957*cdf0e10cSrcweir 	if ( nNextRow <= nEndRow )
1958*cdf0e10cSrcweir 	{
1959*cdf0e10cSrcweir         for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
1960*cdf0e10cSrcweir         {	// remaining empty columns of last row
1961*cdf0e10cSrcweir             if ( bFixedWidth )
1962*cdf0e10cSrcweir                 lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1963*cdf0e10cSrcweir                         aDocument, nTab, nEmptyCol );
1964*cdf0e10cSrcweir             else if ( cDelim != 0 )
1965*cdf0e10cSrcweir                 rStream.WriteUniOrByteChar( cDelim );
1966*cdf0e10cSrcweir         }
1967*cdf0e10cSrcweir 		endlub( rStream );
1968*cdf0e10cSrcweir 		nNextRow++;
1969*cdf0e10cSrcweir 	}
1970*cdf0e10cSrcweir 	for ( nEmptyRow = nNextRow; nEmptyRow <= nEndRow; nEmptyRow++ )
1971*cdf0e10cSrcweir 	{	// entire empty rows
1972*cdf0e10cSrcweir         for ( nEmptyCol = nStartCol; nEmptyCol < nEndCol; nEmptyCol++ )
1973*cdf0e10cSrcweir         {
1974*cdf0e10cSrcweir             if ( bFixedWidth )
1975*cdf0e10cSrcweir                 lcl_ScDocShell_WriteEmptyFixedWidthString( rStream,
1976*cdf0e10cSrcweir                         aDocument, nTab, nEmptyCol );
1977*cdf0e10cSrcweir             else if ( cDelim != 0 )
1978*cdf0e10cSrcweir                 rStream.WriteUniOrByteChar( cDelim );
1979*cdf0e10cSrcweir         }
1980*cdf0e10cSrcweir 		endlub( rStream );
1981*cdf0e10cSrcweir 	}
1982*cdf0e10cSrcweir 
1983*cdf0e10cSrcweir 	rStream.SetStreamCharSet( eOldCharSet );
1984*cdf0e10cSrcweir 	rStream.SetNumberFormatInt( nOldNumberFormatInt );
1985*cdf0e10cSrcweir }
1986*cdf0e10cSrcweir 
1987*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed )
1988*cdf0e10cSrcweir {
1989*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertTo" );
1990*cdf0e10cSrcweir 
1991*cdf0e10cSrcweir 	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
1992*cdf0e10cSrcweir 
1993*cdf0e10cSrcweir     //  #i6500# don't call DoEnterHandler here (doesn't work with AutoSave),
1994*cdf0e10cSrcweir     //  it's already in ExecuteSave (as for Save and SaveAs)
1995*cdf0e10cSrcweir 
1996*cdf0e10cSrcweir 	if (pAutoStyleList)
1997*cdf0e10cSrcweir 		pAutoStyleList->ExecuteAllNow();				// Vorlagen-Timeouts jetzt ausfuehren
1998*cdf0e10cSrcweir 	if (GetCreateMode()== SFX_CREATE_MODE_STANDARD)
1999*cdf0e10cSrcweir         SfxObjectShell::SetVisArea( Rectangle() );     // normal bearbeitet -> keine VisArea
2000*cdf0e10cSrcweir 
2001*cdf0e10cSrcweir 	DBG_ASSERT( rMed.GetFilter(), "Filter == 0" );
2002*cdf0e10cSrcweir 
2003*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2004*cdf0e10cSrcweir 	String aFltName = rMed.GetFilter()->GetFilterName();
2005*cdf0e10cSrcweir 
2006*cdf0e10cSrcweir /*
2007*cdf0e10cSrcweir 	if (aFltName.EqualsAscii(pFilterLotus))
2008*cdf0e10cSrcweir 	{
2009*cdf0e10cSrcweir 		SvStream* pStream = rMed.GetOutStream();
2010*cdf0e10cSrcweir 		if (pStream)
2011*cdf0e10cSrcweir 		{
2012*cdf0e10cSrcweir 			FltError eError = ScFormatFilter::Get().ScExportLotus123( *pStream, &aDocument, ExpWK1,
2013*cdf0e10cSrcweir 												CHARSET_IBMPC_437 );
2014*cdf0e10cSrcweir 			bRet = eError == eERR_OK;
2015*cdf0e10cSrcweir 		}
2016*cdf0e10cSrcweir 	}
2017*cdf0e10cSrcweir 	else
2018*cdf0e10cSrcweir */
2019*cdf0e10cSrcweir     if (aFltName.EqualsAscii(pFilterXML))
2020*cdf0e10cSrcweir 	{
2021*cdf0e10cSrcweir         //TODO/LATER: this shouldn't happen!
2022*cdf0e10cSrcweir         DBG_ERROR("XML filter in ConvertFrom?!");
2023*cdf0e10cSrcweir 		bRet = SaveXML( &rMed, NULL );
2024*cdf0e10cSrcweir 	}
2025*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterExcel5) || aFltName.EqualsAscii(pFilterExcel95) ||
2026*cdf0e10cSrcweir 			 aFltName.EqualsAscii(pFilterExcel97) || aFltName.EqualsAscii(pFilterEx5Temp) ||
2027*cdf0e10cSrcweir 			 aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp) ||
2028*cdf0e10cSrcweir 			 aFltName.EqualsAscii(pFilterEx07Xml))
2029*cdf0e10cSrcweir 	{
2030*cdf0e10cSrcweir 		WaitObject aWait( GetActiveDialogParent() );
2031*cdf0e10cSrcweir 
2032*cdf0e10cSrcweir         bool bDoSave = true;
2033*cdf0e10cSrcweir         if( ScTabViewShell* pViewShell = GetBestViewShell() )
2034*cdf0e10cSrcweir         {
2035*cdf0e10cSrcweir             ScExtDocOptions* pExtDocOpt = aDocument.GetExtDocOptions();
2036*cdf0e10cSrcweir             if( !pExtDocOpt )
2037*cdf0e10cSrcweir                 aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
2038*cdf0e10cSrcweir             pViewShell->GetViewData()->WriteExtOptions( *pExtDocOpt );
2039*cdf0e10cSrcweir 
2040*cdf0e10cSrcweir             /*  #115980# #i104990# If the imported document contains a medium
2041*cdf0e10cSrcweir                 password, determine if we can save it, otherwise ask the users
2042*cdf0e10cSrcweir                 whether they want to save without it. */
2043*cdf0e10cSrcweir             if( (rMed.GetFilter()->GetFilterFlags() & SFX_FILTER_ENCRYPTION) == 0 )
2044*cdf0e10cSrcweir             {
2045*cdf0e10cSrcweir                 SfxItemSet* pItemSet = rMed.GetItemSet();
2046*cdf0e10cSrcweir                 const SfxPoolItem* pItem = 0;
2047*cdf0e10cSrcweir                 if( pItemSet && pItemSet->GetItemState( SID_PASSWORD, sal_True, &pItem ) == SFX_ITEM_SET )
2048*cdf0e10cSrcweir                 {
2049*cdf0e10cSrcweir                     bDoSave = ScWarnPassword::WarningOnPassword( rMed );
2050*cdf0e10cSrcweir                     // #i42858# remove password from medium (warn only one time)
2051*cdf0e10cSrcweir                     if( bDoSave )
2052*cdf0e10cSrcweir                         pItemSet->ClearItem( SID_PASSWORD );
2053*cdf0e10cSrcweir                 }
2054*cdf0e10cSrcweir             }
2055*cdf0e10cSrcweir 
2056*cdf0e10cSrcweir #if ENABLE_SHEET_PROTECTION
2057*cdf0e10cSrcweir             if( bDoSave )
2058*cdf0e10cSrcweir             {
2059*cdf0e10cSrcweir                 bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen( aDocument, PASSHASH_XL );
2060*cdf0e10cSrcweir                 bDoSave = !bNeedRetypePassDlg || pViewShell->ExecuteRetypePassDlg( PASSHASH_XL );
2061*cdf0e10cSrcweir             }
2062*cdf0e10cSrcweir #endif
2063*cdf0e10cSrcweir         }
2064*cdf0e10cSrcweir 
2065*cdf0e10cSrcweir         if( bDoSave )
2066*cdf0e10cSrcweir         {
2067*cdf0e10cSrcweir             ExportFormatExcel eFormat = ExpBiff5;
2068*cdf0e10cSrcweir             if( aFltName.EqualsAscii( pFilterExcel97 ) || aFltName.EqualsAscii( pFilterEx97Temp ) )
2069*cdf0e10cSrcweir                 eFormat = ExpBiff8;
2070*cdf0e10cSrcweir             if( aFltName.EqualsAscii( pFilterEx07Xml ) )
2071*cdf0e10cSrcweir                 eFormat = Exp2007Xml;
2072*cdf0e10cSrcweir             FltError eError = ScFormatFilter::Get().ScExportExcel5( rMed, &aDocument, eFormat, RTL_TEXTENCODING_MS_1252 );
2073*cdf0e10cSrcweir 
2074*cdf0e10cSrcweir             if( eError && !GetError() )
2075*cdf0e10cSrcweir                 SetError( eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2076*cdf0e10cSrcweir 
2077*cdf0e10cSrcweir             // don't return false for warnings
2078*cdf0e10cSrcweir             bRet = ((eError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK) || (eError == eERR_OK);
2079*cdf0e10cSrcweir         }
2080*cdf0e10cSrcweir         else
2081*cdf0e10cSrcweir         {
2082*cdf0e10cSrcweir             // export aborted, i.e. "Save without password" warning
2083*cdf0e10cSrcweir             SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2084*cdf0e10cSrcweir         }
2085*cdf0e10cSrcweir     }
2086*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterAscii))
2087*cdf0e10cSrcweir 	{
2088*cdf0e10cSrcweir 		SvStream* pStream = rMed.GetOutStream();
2089*cdf0e10cSrcweir 		if (pStream)
2090*cdf0e10cSrcweir 		{
2091*cdf0e10cSrcweir 			String sItStr;
2092*cdf0e10cSrcweir 			SfxItemSet*	 pSet = rMed.GetItemSet();
2093*cdf0e10cSrcweir 			const SfxPoolItem* pItem;
2094*cdf0e10cSrcweir 			if ( pSet && SFX_ITEM_SET ==
2095*cdf0e10cSrcweir 				 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2096*cdf0e10cSrcweir 			{
2097*cdf0e10cSrcweir 				sItStr = ((const SfxStringItem*)pItem)->GetValue();
2098*cdf0e10cSrcweir 			}
2099*cdf0e10cSrcweir 
2100*cdf0e10cSrcweir 			if ( sItStr.Len() == 0 )
2101*cdf0e10cSrcweir 			{
2102*cdf0e10cSrcweir 				//	default for ascii export (from API without options):
2103*cdf0e10cSrcweir 				//	ISO8859-1/MS_1252 encoding, comma, double quotes
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir 				ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 );
2106*cdf0e10cSrcweir 				sItStr = aDefOptions.BuildString();
2107*cdf0e10cSrcweir 			}
2108*cdf0e10cSrcweir 
2109*cdf0e10cSrcweir 			WaitObject aWait( GetActiveDialogParent() );
2110*cdf0e10cSrcweir 			ScImportOptions aOptions( sItStr );
2111*cdf0e10cSrcweir 			AsciiSave( *pStream, aOptions );
2112*cdf0e10cSrcweir 			bRet = sal_True;
2113*cdf0e10cSrcweir 
2114*cdf0e10cSrcweir 			if (aDocument.GetTableCount() > 1)
2115*cdf0e10cSrcweir 				if (!rMed.GetError())
2116*cdf0e10cSrcweir 					rMed.SetError(SCWARN_EXPORT_ASCII, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2117*cdf0e10cSrcweir 		}
2118*cdf0e10cSrcweir 	}
2119*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterDBase))
2120*cdf0e10cSrcweir 	{
2121*cdf0e10cSrcweir 		String sCharSet;
2122*cdf0e10cSrcweir 		SfxItemSet*	pSet = rMed.GetItemSet();
2123*cdf0e10cSrcweir 		const SfxPoolItem* pItem;
2124*cdf0e10cSrcweir 		if ( pSet && SFX_ITEM_SET ==
2125*cdf0e10cSrcweir 			 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2126*cdf0e10cSrcweir 		{
2127*cdf0e10cSrcweir 			sCharSet = ((const SfxStringItem*)pItem)->GetValue();
2128*cdf0e10cSrcweir 		}
2129*cdf0e10cSrcweir 
2130*cdf0e10cSrcweir 		if (sCharSet.Len() == 0)
2131*cdf0e10cSrcweir 		{
2132*cdf0e10cSrcweir 			//	default for dBase export (from API without options):
2133*cdf0e10cSrcweir 			//	IBM_850 encoding
2134*cdf0e10cSrcweir 
2135*cdf0e10cSrcweir 			sCharSet = ScGlobal::GetCharsetString( RTL_TEXTENCODING_IBM_850 );
2136*cdf0e10cSrcweir 		}
2137*cdf0e10cSrcweir 
2138*cdf0e10cSrcweir 		WaitObject aWait( GetActiveDialogParent() );
2139*cdf0e10cSrcweir // HACK damit Sba geoffnetes TempFile ueberschreiben kann
2140*cdf0e10cSrcweir 		rMed.CloseOutStream();
2141*cdf0e10cSrcweir 		sal_Bool bHasMemo = sal_False;
2142*cdf0e10cSrcweir 
2143*cdf0e10cSrcweir 		sal_uLong eError = DBaseExport( rMed.GetPhysicalName(),
2144*cdf0e10cSrcweir 						ScGlobal::GetCharsetValue(sCharSet), bHasMemo );
2145*cdf0e10cSrcweir 
2146*cdf0e10cSrcweir 		if ( eError != eERR_OK && (eError & ERRCODE_WARNING_MASK) )
2147*cdf0e10cSrcweir 		{
2148*cdf0e10cSrcweir //!			if ( !rMed.GetError() )
2149*cdf0e10cSrcweir //!				rMed.SetError( eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2150*cdf0e10cSrcweir 			eError = eERR_OK;
2151*cdf0e10cSrcweir 		}
2152*cdf0e10cSrcweir //!		else if ( aDocument.GetTableCount() > 1 && !rMed.GetError() )
2153*cdf0e10cSrcweir //!			rMed.SetError( SCWARN_EXPORT_ASCII, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2154*cdf0e10cSrcweir 
2155*cdf0e10cSrcweir 		INetURLObject aTmpFile( rMed.GetPhysicalName(), INET_PROT_FILE );
2156*cdf0e10cSrcweir 		if ( bHasMemo )
2157*cdf0e10cSrcweir 			aTmpFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) );
2158*cdf0e10cSrcweir 		if ( eError != eERR_OK )
2159*cdf0e10cSrcweir 		{
2160*cdf0e10cSrcweir 			if (!GetError())
2161*cdf0e10cSrcweir 				SetError(eError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2162*cdf0e10cSrcweir 			if ( bHasMemo && IsDocument( aTmpFile ) )
2163*cdf0e10cSrcweir 				KillFile( aTmpFile );
2164*cdf0e10cSrcweir 		}
2165*cdf0e10cSrcweir 		else
2166*cdf0e10cSrcweir 		{
2167*cdf0e10cSrcweir 			bRet = sal_True;
2168*cdf0e10cSrcweir 			if ( bHasMemo )
2169*cdf0e10cSrcweir 			{
2170*cdf0e10cSrcweir 				SfxStringItem* pNameItem =
2171*cdf0e10cSrcweir 					(SfxStringItem*) rMed.GetItemSet()->GetItem( SID_FILE_NAME );
2172*cdf0e10cSrcweir 				INetURLObject aDbtFile( pNameItem->GetValue(), INET_PROT_FILE );
2173*cdf0e10cSrcweir 				aDbtFile.setExtension( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("dbt")) );
2174*cdf0e10cSrcweir 				if ( IsDocument( aDbtFile ) && !KillFile( aDbtFile ) )
2175*cdf0e10cSrcweir 					bRet = sal_False;
2176*cdf0e10cSrcweir 				if ( bRet && !MoveFile( aTmpFile, aDbtFile ) )
2177*cdf0e10cSrcweir 					bRet = sal_False;
2178*cdf0e10cSrcweir 				if ( !bRet )
2179*cdf0e10cSrcweir 				{
2180*cdf0e10cSrcweir 					KillFile( aTmpFile );
2181*cdf0e10cSrcweir 					if ( !GetError() )
2182*cdf0e10cSrcweir 						SetError( SCERR_EXPORT_DATA, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2183*cdf0e10cSrcweir 				}
2184*cdf0e10cSrcweir 			}
2185*cdf0e10cSrcweir 		}
2186*cdf0e10cSrcweir 	}
2187*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterDif))
2188*cdf0e10cSrcweir 	{
2189*cdf0e10cSrcweir 		SvStream* pStream = rMed.GetOutStream();
2190*cdf0e10cSrcweir 		if (pStream)
2191*cdf0e10cSrcweir 		{
2192*cdf0e10cSrcweir 			String sItStr;
2193*cdf0e10cSrcweir 			SfxItemSet*	 pSet = rMed.GetItemSet();
2194*cdf0e10cSrcweir 			const SfxPoolItem* pItem;
2195*cdf0e10cSrcweir 			if ( pSet && SFX_ITEM_SET ==
2196*cdf0e10cSrcweir 				 pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
2197*cdf0e10cSrcweir 			{
2198*cdf0e10cSrcweir 				sItStr = ((const SfxStringItem*)pItem)->GetValue();
2199*cdf0e10cSrcweir 			}
2200*cdf0e10cSrcweir 
2201*cdf0e10cSrcweir 			if (sItStr.Len() == 0)
2202*cdf0e10cSrcweir 			{
2203*cdf0e10cSrcweir 				//	default for DIF export (from API without options):
2204*cdf0e10cSrcweir 				//	ISO8859-1/MS_1252 encoding
2205*cdf0e10cSrcweir 
2206*cdf0e10cSrcweir 				sItStr = ScGlobal::GetCharsetString( RTL_TEXTENCODING_MS_1252 );
2207*cdf0e10cSrcweir 			}
2208*cdf0e10cSrcweir 
2209*cdf0e10cSrcweir 			WaitObject aWait( GetActiveDialogParent() );
2210*cdf0e10cSrcweir 			ScFormatFilter::Get().ScExportDif( *pStream, &aDocument, ScAddress(0,0,0),
2211*cdf0e10cSrcweir 				ScGlobal::GetCharsetValue(sItStr) );
2212*cdf0e10cSrcweir 			bRet = sal_True;
2213*cdf0e10cSrcweir 
2214*cdf0e10cSrcweir 			if (aDocument.GetTableCount() > 1)
2215*cdf0e10cSrcweir 				if (!rMed.GetError())
2216*cdf0e10cSrcweir 					rMed.SetError(SCWARN_EXPORT_ASCII, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
2217*cdf0e10cSrcweir 		}
2218*cdf0e10cSrcweir 	}
2219*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterSylk))
2220*cdf0e10cSrcweir 	{
2221*cdf0e10cSrcweir 		SvStream* pStream = rMed.GetOutStream();
2222*cdf0e10cSrcweir 		if ( pStream )
2223*cdf0e10cSrcweir 		{
2224*cdf0e10cSrcweir 			WaitObject aWait( GetActiveDialogParent() );
2225*cdf0e10cSrcweir 
2226*cdf0e10cSrcweir             SCCOL nEndCol;
2227*cdf0e10cSrcweir             SCROW nEndRow;
2228*cdf0e10cSrcweir             aDocument.GetCellArea( 0, nEndCol, nEndRow );
2229*cdf0e10cSrcweir 			ScRange aRange( 0,0,0, nEndCol,nEndRow,0 );
2230*cdf0e10cSrcweir 
2231*cdf0e10cSrcweir 			ScImportExport aImExport( &aDocument, aRange );
2232*cdf0e10cSrcweir             aImExport.SetFormulas( sal_True );
2233*cdf0e10cSrcweir             bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SOT_FORMATSTR_ID_SYLK );
2234*cdf0e10cSrcweir 		}
2235*cdf0e10cSrcweir 	}
2236*cdf0e10cSrcweir 	else if (aFltName.EqualsAscii(pFilterHtml))
2237*cdf0e10cSrcweir 	{
2238*cdf0e10cSrcweir 		SvStream* pStream = rMed.GetOutStream();
2239*cdf0e10cSrcweir 		if ( pStream )
2240*cdf0e10cSrcweir 		{
2241*cdf0e10cSrcweir             WaitObject aWait( GetActiveDialogParent() );
2242*cdf0e10cSrcweir 			ScImportExport aImExport( &aDocument );
2243*cdf0e10cSrcweir 			aImExport.SetStreamPath( rMed.GetName() );
2244*cdf0e10cSrcweir             bRet = aImExport.ExportStream( *pStream, rMed.GetBaseURL( true ), SOT_FORMATSTR_ID_HTML );
2245*cdf0e10cSrcweir             if ( bRet && aImExport.GetNonConvertibleChars().Len() )
2246*cdf0e10cSrcweir                 SetError( *new StringErrorInfo(
2247*cdf0e10cSrcweir                     SCWARN_EXPORT_NONCONVERTIBLE_CHARS,
2248*cdf0e10cSrcweir                     aImExport.GetNonConvertibleChars(),
2249*cdf0e10cSrcweir                     ERRCODE_BUTTON_OK | ERRCODE_MSG_INFO ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2250*cdf0e10cSrcweir 		}
2251*cdf0e10cSrcweir 	}
2252*cdf0e10cSrcweir 	else
2253*cdf0e10cSrcweir 	{
2254*cdf0e10cSrcweir 		if (GetError())
2255*cdf0e10cSrcweir 			SetError(SCERR_IMPORT_NI, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
2256*cdf0e10cSrcweir 	}
2257*cdf0e10cSrcweir 	return bRet;
2258*cdf0e10cSrcweir }
2259*cdf0e10cSrcweir 
2260*cdf0e10cSrcweir 
2261*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor )
2262*cdf0e10cSrcweir {
2263*cdf0e10cSrcweir     return SfxObjectShell::SaveCompleted( xStor );
2264*cdf0e10cSrcweir }
2265*cdf0e10cSrcweir 
2266*cdf0e10cSrcweir 
2267*cdf0e10cSrcweir sal_Bool __EXPORT ScDocShell::DoSaveCompleted( SfxMedium * pNewStor )
2268*cdf0e10cSrcweir {
2269*cdf0e10cSrcweir 	sal_Bool bRet = SfxObjectShell::DoSaveCompleted( pNewStor );
2270*cdf0e10cSrcweir 
2271*cdf0e10cSrcweir 	//	SC_HINT_DOC_SAVED fuer Wechsel ReadOnly -> Read/Write
2272*cdf0e10cSrcweir 	Broadcast( SfxSimpleHint( SC_HINT_DOC_SAVED ) );
2273*cdf0e10cSrcweir 	return bRet;
2274*cdf0e10cSrcweir }
2275*cdf0e10cSrcweir 
2276*cdf0e10cSrcweir 
2277*cdf0e10cSrcweir sal_Bool ScDocShell::QuerySlotExecutable( sal_uInt16 nSlotId )
2278*cdf0e10cSrcweir {
2279*cdf0e10cSrcweir     // #i112634# ask VBA event handlers whether to save or print the document
2280*cdf0e10cSrcweir 
2281*cdf0e10cSrcweir     using namespace ::com::sun::star::script::vba;
2282*cdf0e10cSrcweir 
2283*cdf0e10cSrcweir     sal_Int32 nVbaEventId = VBAEventId::NO_EVENT;
2284*cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgs;
2285*cdf0e10cSrcweir     switch( nSlotId )
2286*cdf0e10cSrcweir     {
2287*cdf0e10cSrcweir         case SID_SAVEDOC:
2288*cdf0e10cSrcweir         case SID_SAVEASDOC:
2289*cdf0e10cSrcweir             nVbaEventId = VBAEventId::WORKBOOK_BEFORESAVE;
2290*cdf0e10cSrcweir             aArgs.realloc( 1 );
2291*cdf0e10cSrcweir             aArgs[ 0 ] <<= (nSlotId == SID_SAVEASDOC);
2292*cdf0e10cSrcweir         break;
2293*cdf0e10cSrcweir         case SID_PRINTDOC:
2294*cdf0e10cSrcweir         case SID_PRINTDOCDIRECT:
2295*cdf0e10cSrcweir             nVbaEventId = VBAEventId::WORKBOOK_BEFOREPRINT;
2296*cdf0e10cSrcweir         break;
2297*cdf0e10cSrcweir     }
2298*cdf0e10cSrcweir 
2299*cdf0e10cSrcweir     sal_Bool bSlotExecutable = sal_True;
2300*cdf0e10cSrcweir     if( nVbaEventId != VBAEventId::NO_EVENT ) try
2301*cdf0e10cSrcweir     {
2302*cdf0e10cSrcweir         uno::Reference< XVBAEventProcessor > xEventProcessor( aDocument.GetVbaEventProcessor(), uno::UNO_QUERY_THROW );
2303*cdf0e10cSrcweir         xEventProcessor->processVbaEvent( nVbaEventId, aArgs );
2304*cdf0e10cSrcweir     }
2305*cdf0e10cSrcweir     catch( util::VetoException& )
2306*cdf0e10cSrcweir     {
2307*cdf0e10cSrcweir         bSlotExecutable = sal_False;
2308*cdf0e10cSrcweir     }
2309*cdf0e10cSrcweir     catch( uno::Exception& )
2310*cdf0e10cSrcweir     {
2311*cdf0e10cSrcweir     }
2312*cdf0e10cSrcweir     return bSlotExecutable;
2313*cdf0e10cSrcweir }
2314*cdf0e10cSrcweir 
2315*cdf0e10cSrcweir 
2316*cdf0e10cSrcweir sal_uInt16 __EXPORT ScDocShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
2317*cdf0e10cSrcweir {
2318*cdf0e10cSrcweir 	if(SC_MOD()->GetCurRefDlgId()>0)
2319*cdf0e10cSrcweir 	{
2320*cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
2321*cdf0e10cSrcweir 		if( pFrame )
2322*cdf0e10cSrcweir 		{
2323*cdf0e10cSrcweir 			SfxViewShell* p = pFrame->GetViewShell();
2324*cdf0e10cSrcweir 			ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
2325*cdf0e10cSrcweir 			if(pViewSh!=NULL)
2326*cdf0e10cSrcweir 			{
2327*cdf0e10cSrcweir 				Window *pWin=pViewSh->GetWindow();
2328*cdf0e10cSrcweir 				if(pWin!=NULL) pWin->GrabFocus();
2329*cdf0e10cSrcweir 			}
2330*cdf0e10cSrcweir 		}
2331*cdf0e10cSrcweir 
2332*cdf0e10cSrcweir 		return sal_False;
2333*cdf0e10cSrcweir 	}
2334*cdf0e10cSrcweir 	if ( aDocument.IsInLinkUpdate() || aDocument.IsInInterpreter() )
2335*cdf0e10cSrcweir 	{
2336*cdf0e10cSrcweir 		ErrorMessage(STR_CLOSE_ERROR_LINK);
2337*cdf0e10cSrcweir 		return sal_False;
2338*cdf0e10cSrcweir 	}
2339*cdf0e10cSrcweir 
2340*cdf0e10cSrcweir 	DoEnterHandler();
2341*cdf0e10cSrcweir 
2342*cdf0e10cSrcweir 	// start 'Workbook_BeforeClose' VBA event handler for possible veto
2343*cdf0e10cSrcweir     if( !IsInPrepareClose() )
2344*cdf0e10cSrcweir     {
2345*cdf0e10cSrcweir         try
2346*cdf0e10cSrcweir         {
2347*cdf0e10cSrcweir             uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( aDocument.GetVbaEventProcessor(), uno::UNO_SET_THROW );
2348*cdf0e10cSrcweir             uno::Sequence< uno::Any > aArgs;
2349*cdf0e10cSrcweir             xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_BEFORECLOSE, aArgs );
2350*cdf0e10cSrcweir         }
2351*cdf0e10cSrcweir         catch( util::VetoException& )
2352*cdf0e10cSrcweir         {
2353*cdf0e10cSrcweir             // if event processor throws VetoException, macro has vetoed close
2354*cdf0e10cSrcweir 		    return sal_False;
2355*cdf0e10cSrcweir 		}
2356*cdf0e10cSrcweir         catch( uno::Exception& )
2357*cdf0e10cSrcweir         {
2358*cdf0e10cSrcweir         }
2359*cdf0e10cSrcweir     }
2360*cdf0e10cSrcweir 	// end handler code
2361*cdf0e10cSrcweir 
2362*cdf0e10cSrcweir 	sal_uInt16 nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing );
2363*cdf0e10cSrcweir 	if (nRet == sal_True)						// sal_True = schliessen
2364*cdf0e10cSrcweir 		aDocument.DisableIdle(sal_True);		// nicht mehr drin rumpfuschen !!!
2365*cdf0e10cSrcweir 
2366*cdf0e10cSrcweir 	return nRet;
2367*cdf0e10cSrcweir }
2368*cdf0e10cSrcweir 
2369*cdf0e10cSrcweir void ScDocShell::PrepareReload()
2370*cdf0e10cSrcweir {
2371*cdf0e10cSrcweir 	SfxObjectShell::PrepareReload();	// tut nichts?
2372*cdf0e10cSrcweir 
2373*cdf0e10cSrcweir 	//	Das Disconnect von DDE-Links kann Reschedule ausloesen.
2374*cdf0e10cSrcweir 	//	Wenn die DDE-Links erst im Dokument-dtor geloescht werden, kann beim Reload
2375*cdf0e10cSrcweir 	//	aus diesem Reschedule das DDE-Link-Update fuer das neue Dokument ausgeloest
2376*cdf0e10cSrcweir 	//	werden. Dabei verklemmt sicht dann irgendwas.
2377*cdf0e10cSrcweir 	//	-> Beim Reload die DDE-Links des alten Dokuments vorher disconnecten
2378*cdf0e10cSrcweir 
2379*cdf0e10cSrcweir 	aDocument.DisconnectDdeLinks();
2380*cdf0e10cSrcweir }
2381*cdf0e10cSrcweir 
2382*cdf0e10cSrcweir 
2383*cdf0e10cSrcweir String ScDocShell::GetOwnFilterName()			// static
2384*cdf0e10cSrcweir {
2385*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterSc50);
2386*cdf0e10cSrcweir }
2387*cdf0e10cSrcweir 
2388*cdf0e10cSrcweir String ScDocShell::GetHtmlFilterName()
2389*cdf0e10cSrcweir {
2390*cdf0e10cSrcweir     return String::CreateFromAscii(pFilterHtml);
2391*cdf0e10cSrcweir }
2392*cdf0e10cSrcweir 
2393*cdf0e10cSrcweir String ScDocShell::GetWebQueryFilterName()		// static
2394*cdf0e10cSrcweir {
2395*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterHtmlWebQ);
2396*cdf0e10cSrcweir }
2397*cdf0e10cSrcweir 
2398*cdf0e10cSrcweir String ScDocShell::GetAsciiFilterName()			// static
2399*cdf0e10cSrcweir {
2400*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterAscii);
2401*cdf0e10cSrcweir }
2402*cdf0e10cSrcweir 
2403*cdf0e10cSrcweir String ScDocShell::GetLotusFilterName()			// static
2404*cdf0e10cSrcweir {
2405*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterLotus);
2406*cdf0e10cSrcweir }
2407*cdf0e10cSrcweir 
2408*cdf0e10cSrcweir String ScDocShell::GetDBaseFilterName()			// static
2409*cdf0e10cSrcweir {
2410*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterDBase);
2411*cdf0e10cSrcweir }
2412*cdf0e10cSrcweir 
2413*cdf0e10cSrcweir String ScDocShell::GetDifFilterName()			// static
2414*cdf0e10cSrcweir {
2415*cdf0e10cSrcweir 	return String::CreateFromAscii(pFilterDif);
2416*cdf0e10cSrcweir }
2417*cdf0e10cSrcweir 
2418*cdf0e10cSrcweir sal_Bool ScDocShell::HasAutomaticTableName( const String& rFilter )		// static
2419*cdf0e10cSrcweir {
2420*cdf0e10cSrcweir 	//	sal_True for those filters that keep the default table name
2421*cdf0e10cSrcweir 	//	(which is language specific)
2422*cdf0e10cSrcweir 
2423*cdf0e10cSrcweir 	return rFilter.EqualsAscii( pFilterAscii )
2424*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterLotus )
2425*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterExcel4 )
2426*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterEx4Temp )
2427*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterDBase )
2428*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterDif )
2429*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterSylk )
2430*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterHtml )
2431*cdf0e10cSrcweir 		|| rFilter.EqualsAscii( pFilterRtf );
2432*cdf0e10cSrcweir }
2433*cdf0e10cSrcweir 
2434*cdf0e10cSrcweir //==================================================================
2435*cdf0e10cSrcweir 
2436*cdf0e10cSrcweir #define __SCDOCSHELL_INIT \
2437*cdf0e10cSrcweir 		aDocument		( SCDOCMODE_DOCUMENT, this ), \
2438*cdf0e10cSrcweir         aDdeTextFmt(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TEXT"))), \
2439*cdf0e10cSrcweir 		nPrtToScreenFactor( 1.0 ), \
2440*cdf0e10cSrcweir         pImpl           ( new DocShell_Impl ), \
2441*cdf0e10cSrcweir 		bHeaderOn		( sal_True ), \
2442*cdf0e10cSrcweir 		bFooterOn		( sal_True ), \
2443*cdf0e10cSrcweir         bNoInformLost   ( sal_True ), \
2444*cdf0e10cSrcweir 		bIsEmpty		( sal_True ), \
2445*cdf0e10cSrcweir 		bIsInUndo		( sal_False ), \
2446*cdf0e10cSrcweir 		bDocumentModifiedPending( sal_False ), \
2447*cdf0e10cSrcweir 		nDocumentLock	( 0 ), \
2448*cdf0e10cSrcweir         nCanUpdate (com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG), \
2449*cdf0e10cSrcweir         bUpdateEnabled  ( sal_True ), \
2450*cdf0e10cSrcweir         pOldAutoDBRange ( NULL ), \
2451*cdf0e10cSrcweir 		pDocHelper 		( NULL ), \
2452*cdf0e10cSrcweir 		pAutoStyleList	( NULL ), \
2453*cdf0e10cSrcweir 		pPaintLockData	( NULL ), \
2454*cdf0e10cSrcweir 		pOldJobSetup	( NULL ), \
2455*cdf0e10cSrcweir         pSolverSaveData ( NULL ), \
2456*cdf0e10cSrcweir         pSheetSaveData  ( NULL ), \
2457*cdf0e10cSrcweir         pModificator    ( NULL )
2458*cdf0e10cSrcweir 
2459*cdf0e10cSrcweir //------------------------------------------------------------------
2460*cdf0e10cSrcweir 
2461*cdf0e10cSrcweir ScDocShell::ScDocShell( const ScDocShell& rShell )
2462*cdf0e10cSrcweir     :   SvRefBase(),
2463*cdf0e10cSrcweir         SotObject(),
2464*cdf0e10cSrcweir 	    SfxObjectShell( rShell.GetCreateMode() ),
2465*cdf0e10cSrcweir         SfxListener(),
2466*cdf0e10cSrcweir 		__SCDOCSHELL_INIT
2467*cdf0e10cSrcweir {
2468*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ScDocShell" );
2469*cdf0e10cSrcweir 
2470*cdf0e10cSrcweir 	SetPool( &SC_MOD()->GetPool() );
2471*cdf0e10cSrcweir 
2472*cdf0e10cSrcweir 	bIsInplace = rShell.bIsInplace;
2473*cdf0e10cSrcweir 
2474*cdf0e10cSrcweir 	pDocFunc = new ScDocFunc(*this);
2475*cdf0e10cSrcweir 
2476*cdf0e10cSrcweir 	//	SetBaseModel needs exception handling
2477*cdf0e10cSrcweir 	ScModelObj::CreateAndSet( this );
2478*cdf0e10cSrcweir 
2479*cdf0e10cSrcweir 	StartListening(*this);
2480*cdf0e10cSrcweir 	SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2481*cdf0e10cSrcweir 	if (pStlPool)
2482*cdf0e10cSrcweir 		StartListening(*pStlPool);
2483*cdf0e10cSrcweir 
2484*cdf0e10cSrcweir 	GetPageOnFromPageStyleSet( NULL, 0, bHeaderOn, bFooterOn );
2485*cdf0e10cSrcweir 	SetHelpId( HID_SCSHELL_DOCSH );
2486*cdf0e10cSrcweir 
2487*cdf0e10cSrcweir 	//	InitItems und CalcOutputFactor werden jetzt nach bei Load/ConvertFrom/InitNew gerufen
2488*cdf0e10cSrcweir }
2489*cdf0e10cSrcweir 
2490*cdf0e10cSrcweir //------------------------------------------------------------------
2491*cdf0e10cSrcweir 
2492*cdf0e10cSrcweir ScDocShell::ScDocShell( const sal_uInt64 i_nSfxCreationFlags )
2493*cdf0e10cSrcweir 	:	SfxObjectShell( i_nSfxCreationFlags )
2494*cdf0e10cSrcweir     ,   __SCDOCSHELL_INIT
2495*cdf0e10cSrcweir {
2496*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ScDocShell" );
2497*cdf0e10cSrcweir 
2498*cdf0e10cSrcweir 	SetPool( &SC_MOD()->GetPool() );
2499*cdf0e10cSrcweir 
2500*cdf0e10cSrcweir 	bIsInplace = (GetCreateMode() == SFX_CREATE_MODE_EMBEDDED);
2501*cdf0e10cSrcweir 	//	wird zurueckgesetzt, wenn nicht inplace
2502*cdf0e10cSrcweir 
2503*cdf0e10cSrcweir 	pDocFunc = new ScDocFunc(*this);
2504*cdf0e10cSrcweir 
2505*cdf0e10cSrcweir 	//	SetBaseModel needs exception handling
2506*cdf0e10cSrcweir 	ScModelObj::CreateAndSet( this );
2507*cdf0e10cSrcweir 
2508*cdf0e10cSrcweir 	StartListening(*this);
2509*cdf0e10cSrcweir 	SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2510*cdf0e10cSrcweir 	if (pStlPool)
2511*cdf0e10cSrcweir 		StartListening(*pStlPool);
2512*cdf0e10cSrcweir 	SetHelpId( HID_SCSHELL_DOCSH );
2513*cdf0e10cSrcweir 
2514*cdf0e10cSrcweir 	aDocument.GetDBCollection()->SetRefreshHandler(
2515*cdf0e10cSrcweir 		LINK( this, ScDocShell, RefreshDBDataHdl ) );
2516*cdf0e10cSrcweir 
2517*cdf0e10cSrcweir 	//	InitItems und CalcOutputFactor werden jetzt nach bei Load/ConvertFrom/InitNew gerufen
2518*cdf0e10cSrcweir }
2519*cdf0e10cSrcweir 
2520*cdf0e10cSrcweir //------------------------------------------------------------------
2521*cdf0e10cSrcweir 
2522*cdf0e10cSrcweir __EXPORT ScDocShell::~ScDocShell()
2523*cdf0e10cSrcweir {
2524*cdf0e10cSrcweir 	ResetDrawObjectShell();	// #55570# falls der Drawing-Layer noch versucht, darauf zuzugreifen
2525*cdf0e10cSrcweir 
2526*cdf0e10cSrcweir 	SfxStyleSheetPool* pStlPool = aDocument.GetStyleSheetPool();
2527*cdf0e10cSrcweir 	if (pStlPool)
2528*cdf0e10cSrcweir 		EndListening(*pStlPool);
2529*cdf0e10cSrcweir 	EndListening(*this);
2530*cdf0e10cSrcweir 
2531*cdf0e10cSrcweir 	delete pAutoStyleList;
2532*cdf0e10cSrcweir 
2533*cdf0e10cSrcweir 	SfxApplication *pSfxApp = SFX_APP();
2534*cdf0e10cSrcweir 	if ( pSfxApp->GetDdeService() )				// DDE vor Dokument loeschen
2535*cdf0e10cSrcweir 		pSfxApp->RemoveDdeTopic( this );
2536*cdf0e10cSrcweir 
2537*cdf0e10cSrcweir 	delete pDocFunc;
2538*cdf0e10cSrcweir 	delete aDocument.mpUndoManager;
2539*cdf0e10cSrcweir 	aDocument.mpUndoManager = 0;
2540*cdf0e10cSrcweir     delete pImpl;
2541*cdf0e10cSrcweir 
2542*cdf0e10cSrcweir 	delete pPaintLockData;
2543*cdf0e10cSrcweir 
2544*cdf0e10cSrcweir 	delete pOldJobSetup;		// gesetzt nur bei Fehler in StartJob()
2545*cdf0e10cSrcweir 
2546*cdf0e10cSrcweir     delete pSolverSaveData;
2547*cdf0e10cSrcweir     delete pSheetSaveData;
2548*cdf0e10cSrcweir     delete pOldAutoDBRange;
2549*cdf0e10cSrcweir 
2550*cdf0e10cSrcweir     if (pModificator)
2551*cdf0e10cSrcweir     {
2552*cdf0e10cSrcweir         DBG_ERROR("The Modificator should not exist");
2553*cdf0e10cSrcweir         delete pModificator;
2554*cdf0e10cSrcweir     }
2555*cdf0e10cSrcweir }
2556*cdf0e10cSrcweir 
2557*cdf0e10cSrcweir //------------------------------------------------------------------
2558*cdf0e10cSrcweir 
2559*cdf0e10cSrcweir ::svl::IUndoManager* __EXPORT ScDocShell::GetUndoManager()
2560*cdf0e10cSrcweir {
2561*cdf0e10cSrcweir 	return aDocument.GetUndoManager();
2562*cdf0e10cSrcweir }
2563*cdf0e10cSrcweir 
2564*cdf0e10cSrcweir void ScDocShell::SetModified( sal_Bool bModified )
2565*cdf0e10cSrcweir {
2566*cdf0e10cSrcweir     if ( SfxObjectShell::IsEnableSetModified() )
2567*cdf0e10cSrcweir 	{
2568*cdf0e10cSrcweir     	SfxObjectShell::SetModified( bModified );
2569*cdf0e10cSrcweir 		Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
2570*cdf0e10cSrcweir 	}
2571*cdf0e10cSrcweir }
2572*cdf0e10cSrcweir 
2573*cdf0e10cSrcweir 
2574*cdf0e10cSrcweir void ScDocShell::SetDocumentModified( sal_Bool bIsModified /* = sal_True */ )
2575*cdf0e10cSrcweir {
2576*cdf0e10cSrcweir 	//	BroadcastUno muss auch mit pPaintLockData sofort passieren
2577*cdf0e10cSrcweir 	//!	auch bei SetDrawModified, wenn Drawing angebunden ist
2578*cdf0e10cSrcweir 	//!	dann eigener Hint???
2579*cdf0e10cSrcweir 
2580*cdf0e10cSrcweir 	if ( pPaintLockData && bIsModified )
2581*cdf0e10cSrcweir 	{
2582*cdf0e10cSrcweir         // #i115009# broadcast BCA_BRDCST_ALWAYS, so a component can read recalculated results
2583*cdf0e10cSrcweir         // of RecalcModeAlways formulas (like OFFSET) after modifying cells
2584*cdf0e10cSrcweir         aDocument.Broadcast( SC_HINT_DATACHANGED, BCA_BRDCST_ALWAYS, NULL );
2585*cdf0e10cSrcweir         aDocument.InvalidateTableArea();    // #i105279# needed here
2586*cdf0e10cSrcweir         aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
2587*cdf0e10cSrcweir 
2588*cdf0e10cSrcweir 		pPaintLockData->SetModified();			// spaeter...
2589*cdf0e10cSrcweir 		return;
2590*cdf0e10cSrcweir 	}
2591*cdf0e10cSrcweir 
2592*cdf0e10cSrcweir 	SetDrawModified( bIsModified );
2593*cdf0e10cSrcweir 
2594*cdf0e10cSrcweir 	if ( bIsModified )
2595*cdf0e10cSrcweir 	{
2596*cdf0e10cSrcweir 		if ( aDocument.IsAutoCalcShellDisabled() )
2597*cdf0e10cSrcweir 			SetDocumentModifiedPending( sal_True );
2598*cdf0e10cSrcweir 		else
2599*cdf0e10cSrcweir 		{
2600*cdf0e10cSrcweir 			SetDocumentModifiedPending( sal_False );
2601*cdf0e10cSrcweir             aDocument.InvalidateStyleSheetUsage();
2602*cdf0e10cSrcweir 			aDocument.InvalidateTableArea();
2603*cdf0e10cSrcweir             aDocument.InvalidateLastTableOpParams();
2604*cdf0e10cSrcweir 			aDocument.Broadcast( SC_HINT_DATACHANGED, BCA_BRDCST_ALWAYS, NULL );
2605*cdf0e10cSrcweir 			if ( aDocument.IsForcedFormulaPending() && aDocument.GetAutoCalc() )
2606*cdf0e10cSrcweir 				aDocument.CalcFormulaTree( sal_True );
2607*cdf0e10cSrcweir 			PostDataChanged();
2608*cdf0e10cSrcweir 
2609*cdf0e10cSrcweir 			//	Detective AutoUpdate:
2610*cdf0e10cSrcweir 			//	Update if formulas were modified (DetectiveDirty) or the list contains
2611*cdf0e10cSrcweir 			//	"Trace Error" entries (#75362# - Trace Error can look completely different
2612*cdf0e10cSrcweir 			//	after changes to non-formula cells).
2613*cdf0e10cSrcweir 
2614*cdf0e10cSrcweir 			ScDetOpList* pList = aDocument.GetDetOpList();
2615*cdf0e10cSrcweir 			if ( pList && ( aDocument.IsDetectiveDirty() || pList->HasAddError() ) &&
2616*cdf0e10cSrcweir 				 pList->Count() && !IsInUndo() && SC_MOD()->GetAppOptions().GetDetectiveAuto() )
2617*cdf0e10cSrcweir 			{
2618*cdf0e10cSrcweir 				GetDocFunc().DetectiveRefresh(sal_True);	// sal_True = caused by automatic update
2619*cdf0e10cSrcweir 			}
2620*cdf0e10cSrcweir 			aDocument.SetDetectiveDirty(sal_False);			// always reset, also if not refreshed
2621*cdf0e10cSrcweir 		}
2622*cdf0e10cSrcweir 
2623*cdf0e10cSrcweir         // #b6697848# notify UNO objects after BCA_BRDCST_ALWAYS etc.
2624*cdf0e10cSrcweir         aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
2625*cdf0e10cSrcweir 	}
2626*cdf0e10cSrcweir }
2627*cdf0e10cSrcweir 
2628*cdf0e10cSrcweir //	SetDrawModified - ohne Formel-Update
2629*cdf0e10cSrcweir //	(Drawing muss auch beim normalen SetDocumentModified upgedated werden,
2630*cdf0e10cSrcweir //	 z.B. bei Tabelle loeschen etc.)
2631*cdf0e10cSrcweir 
2632*cdf0e10cSrcweir void ScDocShell::SetDrawModified( sal_Bool bIsModified /* = sal_True */ )
2633*cdf0e10cSrcweir {
2634*cdf0e10cSrcweir 	sal_Bool bUpdate = ( bIsModified != IsModified() );
2635*cdf0e10cSrcweir 
2636*cdf0e10cSrcweir 	SetModified( bIsModified );
2637*cdf0e10cSrcweir 
2638*cdf0e10cSrcweir     SfxBindings* pBindings = GetViewBindings();
2639*cdf0e10cSrcweir 	if (bUpdate)
2640*cdf0e10cSrcweir 	{
2641*cdf0e10cSrcweir 		if (pBindings)
2642*cdf0e10cSrcweir 		{
2643*cdf0e10cSrcweir 			pBindings->Invalidate( SID_SAVEDOC );
2644*cdf0e10cSrcweir 			pBindings->Invalidate( SID_DOC_MODIFIED );
2645*cdf0e10cSrcweir 		}
2646*cdf0e10cSrcweir 	}
2647*cdf0e10cSrcweir 
2648*cdf0e10cSrcweir 	if (bIsModified)
2649*cdf0e10cSrcweir 	{
2650*cdf0e10cSrcweir         if (pBindings)
2651*cdf0e10cSrcweir         {
2652*cdf0e10cSrcweir             // #i105960# Undo etc used to be volatile.
2653*cdf0e10cSrcweir             // They always have to be invalidated, including drawing layer or row height changes
2654*cdf0e10cSrcweir             // (but not while pPaintLockData is set).
2655*cdf0e10cSrcweir             pBindings->Invalidate( SID_UNDO );
2656*cdf0e10cSrcweir             pBindings->Invalidate( SID_REDO );
2657*cdf0e10cSrcweir             pBindings->Invalidate( SID_REPEAT );
2658*cdf0e10cSrcweir         }
2659*cdf0e10cSrcweir 
2660*cdf0e10cSrcweir 		if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
2661*cdf0e10cSrcweir 		{
2662*cdf0e10cSrcweir 			aDocument.UpdateChartListenerCollection();
2663*cdf0e10cSrcweir 			SFX_APP()->Broadcast(SfxSimpleHint( SC_HINT_DRAW_CHANGED ));	// Navigator
2664*cdf0e10cSrcweir 		}
2665*cdf0e10cSrcweir 		SC_MOD()->AnythingChanged();
2666*cdf0e10cSrcweir 	}
2667*cdf0e10cSrcweir }
2668*cdf0e10cSrcweir 
2669*cdf0e10cSrcweir void ScDocShell::SetInUndo(sal_Bool bSet)
2670*cdf0e10cSrcweir {
2671*cdf0e10cSrcweir 	bIsInUndo = bSet;
2672*cdf0e10cSrcweir }
2673*cdf0e10cSrcweir 
2674*cdf0e10cSrcweir 
2675*cdf0e10cSrcweir void ScDocShell::GetDocStat( ScDocStat& rDocStat )
2676*cdf0e10cSrcweir {
2677*cdf0e10cSrcweir 	SfxPrinter* pPrinter = GetPrinter();
2678*cdf0e10cSrcweir 
2679*cdf0e10cSrcweir 	aDocument.GetDocStat( rDocStat );
2680*cdf0e10cSrcweir 	rDocStat.nPageCount = 0;
2681*cdf0e10cSrcweir 
2682*cdf0e10cSrcweir 	if ( pPrinter )
2683*cdf0e10cSrcweir 		for ( SCTAB i=0; i<rDocStat.nTableCount; i++ )
2684*cdf0e10cSrcweir             rDocStat.nPageCount = sal::static_int_cast<sal_uInt16>( rDocStat.nPageCount +
2685*cdf0e10cSrcweir                 (sal_uInt16) ScPrintFunc( this, pPrinter, i ).GetTotalPages() );
2686*cdf0e10cSrcweir }
2687*cdf0e10cSrcweir 
2688*cdf0e10cSrcweir 
2689*cdf0e10cSrcweir SfxDocumentInfoDialog* __EXPORT ScDocShell::CreateDocumentInfoDialog(
2690*cdf0e10cSrcweir 										 Window *pParent, const SfxItemSet &rSet )
2691*cdf0e10cSrcweir {
2692*cdf0e10cSrcweir 	SfxDocumentInfoDialog* pDlg   = new SfxDocumentInfoDialog( pParent, rSet );
2693*cdf0e10cSrcweir 	ScDocShell*			   pDocSh = PTR_CAST(ScDocShell,SfxObjectShell::Current());
2694*cdf0e10cSrcweir 
2695*cdf0e10cSrcweir 	//nur mit Statistik, wenn dieses Doc auch angezeigt wird, nicht
2696*cdf0e10cSrcweir 	//aus dem Doc-Manager
2697*cdf0e10cSrcweir 
2698*cdf0e10cSrcweir 	if( pDocSh == this )
2699*cdf0e10cSrcweir 	{
2700*cdf0e10cSrcweir 		ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2701*cdf0e10cSrcweir 		DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
2702*cdf0e10cSrcweir 		::CreateTabPage ScDocStatPageCreate = 	pFact->GetTabPageCreatorFunc( RID_SCPAGE_STAT );
2703*cdf0e10cSrcweir 		DBG_ASSERT(ScDocStatPageCreate, "Tabpage create fail!");//CHINA001
2704*cdf0e10cSrcweir 		pDlg->AddTabPage( 42,
2705*cdf0e10cSrcweir 			ScGlobal::GetRscString( STR_DOC_STAT ),
2706*cdf0e10cSrcweir 			ScDocStatPageCreate,
2707*cdf0e10cSrcweir 			NULL);
2708*cdf0e10cSrcweir //CHINA001		pDlg->AddTabPage( 42,
2709*cdf0e10cSrcweir //CHINA001		ScGlobal::GetRscString( STR_DOC_STAT ),
2710*cdf0e10cSrcweir //CHINA001		ScDocStatPage::Create,
2711*cdf0e10cSrcweir //CHINA001		NULL );
2712*cdf0e10cSrcweir 	}
2713*cdf0e10cSrcweir 	return pDlg;
2714*cdf0e10cSrcweir }
2715*cdf0e10cSrcweir 
2716*cdf0e10cSrcweir Window* ScDocShell::GetActiveDialogParent()
2717*cdf0e10cSrcweir {
2718*cdf0e10cSrcweir 	ScTabViewShell* pViewSh	= ScTabViewShell::GetActiveViewShell();
2719*cdf0e10cSrcweir 	if ( pViewSh )
2720*cdf0e10cSrcweir 		return pViewSh->GetDialogParent();
2721*cdf0e10cSrcweir 	else
2722*cdf0e10cSrcweir 		return Application::GetDefDialogParent();
2723*cdf0e10cSrcweir }
2724*cdf0e10cSrcweir 
2725*cdf0e10cSrcweir void ScDocShell::SetSolverSaveData( const ScOptSolverSave& rData )
2726*cdf0e10cSrcweir {
2727*cdf0e10cSrcweir     delete pSolverSaveData;
2728*cdf0e10cSrcweir     pSolverSaveData = new ScOptSolverSave( rData );
2729*cdf0e10cSrcweir }
2730*cdf0e10cSrcweir 
2731*cdf0e10cSrcweir ScSheetSaveData* ScDocShell::GetSheetSaveData()
2732*cdf0e10cSrcweir {
2733*cdf0e10cSrcweir     if (!pSheetSaveData)
2734*cdf0e10cSrcweir         pSheetSaveData = new ScSheetSaveData;
2735*cdf0e10cSrcweir 
2736*cdf0e10cSrcweir     return pSheetSaveData;
2737*cdf0e10cSrcweir }
2738*cdf0e10cSrcweir 
2739*cdf0e10cSrcweir void ScDocShell::UseSheetSaveEntries()
2740*cdf0e10cSrcweir {
2741*cdf0e10cSrcweir     if (pSheetSaveData)
2742*cdf0e10cSrcweir     {
2743*cdf0e10cSrcweir         pSheetSaveData->UseSaveEntries();   // use positions from saved file for next saving
2744*cdf0e10cSrcweir 
2745*cdf0e10cSrcweir         bool bHasEntries = false;
2746*cdf0e10cSrcweir         SCTAB nTabCount = aDocument.GetTableCount();
2747*cdf0e10cSrcweir         SCTAB nTab;
2748*cdf0e10cSrcweir         for (nTab = 0; nTab < nTabCount; ++nTab)
2749*cdf0e10cSrcweir             if (pSheetSaveData->HasStreamPos(nTab))
2750*cdf0e10cSrcweir                 bHasEntries = true;
2751*cdf0e10cSrcweir 
2752*cdf0e10cSrcweir         if (!bHasEntries)
2753*cdf0e10cSrcweir         {
2754*cdf0e10cSrcweir             // if no positions were set (for example, export to other format),
2755*cdf0e10cSrcweir             // reset all "valid" flags
2756*cdf0e10cSrcweir 
2757*cdf0e10cSrcweir             for (nTab = 0; nTab < nTabCount; ++nTab)
2758*cdf0e10cSrcweir                 if (aDocument.IsStreamValid(nTab))
2759*cdf0e10cSrcweir                     aDocument.SetStreamValid(nTab, sal_False);
2760*cdf0e10cSrcweir         }
2761*cdf0e10cSrcweir     }
2762*cdf0e10cSrcweir }
2763*cdf0e10cSrcweir 
2764*cdf0e10cSrcweir // --- ScDocShellModificator ------------------------------------------
2765*cdf0e10cSrcweir 
2766*cdf0e10cSrcweir ScDocShellModificator::ScDocShellModificator( ScDocShell& rDS )
2767*cdf0e10cSrcweir 		:
2768*cdf0e10cSrcweir 		rDocShell( rDS ),
2769*cdf0e10cSrcweir 		aProtector( rDS.GetDocument()->GetRefreshTimerControlAddress() )
2770*cdf0e10cSrcweir {
2771*cdf0e10cSrcweir 	ScDocument* pDoc = rDocShell.GetDocument();
2772*cdf0e10cSrcweir 	bAutoCalcShellDisabled = pDoc->IsAutoCalcShellDisabled();
2773*cdf0e10cSrcweir 	bIdleDisabled = pDoc->IsIdleDisabled();
2774*cdf0e10cSrcweir 	pDoc->SetAutoCalcShellDisabled( sal_True );
2775*cdf0e10cSrcweir 	pDoc->DisableIdle( sal_True );
2776*cdf0e10cSrcweir }
2777*cdf0e10cSrcweir 
2778*cdf0e10cSrcweir 
2779*cdf0e10cSrcweir ScDocShellModificator::~ScDocShellModificator()
2780*cdf0e10cSrcweir {
2781*cdf0e10cSrcweir 	ScDocument* pDoc = rDocShell.GetDocument();
2782*cdf0e10cSrcweir 	pDoc->SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
2783*cdf0e10cSrcweir 	if ( !bAutoCalcShellDisabled && rDocShell.IsDocumentModifiedPending() )
2784*cdf0e10cSrcweir 		rDocShell.SetDocumentModified();	// last one shuts off the lights
2785*cdf0e10cSrcweir 	pDoc->DisableIdle( bIdleDisabled );
2786*cdf0e10cSrcweir }
2787*cdf0e10cSrcweir 
2788*cdf0e10cSrcweir 
2789*cdf0e10cSrcweir void ScDocShellModificator::SetDocumentModified()
2790*cdf0e10cSrcweir {
2791*cdf0e10cSrcweir 	ScDocument* pDoc = rDocShell.GetDocument();
2792*cdf0e10cSrcweir 	if ( !pDoc->IsImportingXML() )
2793*cdf0e10cSrcweir 	{
2794*cdf0e10cSrcweir 		// AutoCalcShellDisabled temporaer restaurieren
2795*cdf0e10cSrcweir 		sal_Bool bDisabled = pDoc->IsAutoCalcShellDisabled();
2796*cdf0e10cSrcweir 		pDoc->SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
2797*cdf0e10cSrcweir 		rDocShell.SetDocumentModified();
2798*cdf0e10cSrcweir 		pDoc->SetAutoCalcShellDisabled( bDisabled );
2799*cdf0e10cSrcweir 	}
2800*cdf0e10cSrcweir 	else
2801*cdf0e10cSrcweir 	{
2802*cdf0e10cSrcweir 		// uno broadcast is necessary for api to work
2803*cdf0e10cSrcweir 		// -> must also be done during xml import
2804*cdf0e10cSrcweir 		pDoc->BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
2805*cdf0e10cSrcweir 	}
2806*cdf0e10cSrcweir }
2807*cdf0e10cSrcweir 
2808*cdf0e10cSrcweir //<!--Added by PengYunQuan for Validity Cell Range Picker
2809*cdf0e10cSrcweir sal_Bool ScDocShell::AcceptStateUpdate() const
2810*cdf0e10cSrcweir {
2811*cdf0e10cSrcweir 	if( SfxObjectShell::AcceptStateUpdate() )
2812*cdf0e10cSrcweir 		return sal_True;
2813*cdf0e10cSrcweir 
2814*cdf0e10cSrcweir 	if( SC_MOD()->Find1RefWindow( SFX_APP()->GetTopWindow() ) )
2815*cdf0e10cSrcweir 		return sal_True;
2816*cdf0e10cSrcweir 
2817*cdf0e10cSrcweir 	return sal_False;
2818*cdf0e10cSrcweir }
2819*cdf0e10cSrcweir //-->Added by PengYunQuan for Validity Cell Range Picker
2820*cdf0e10cSrcweir 
2821*cdf0e10cSrcweir 
2822*cdf0e10cSrcweir bool ScDocShell::IsChangeRecording() const
2823*cdf0e10cSrcweir {
2824*cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2825*cdf0e10cSrcweir     return pChangeTrack != NULL;
2826*cdf0e10cSrcweir }
2827*cdf0e10cSrcweir 
2828*cdf0e10cSrcweir 
2829*cdf0e10cSrcweir bool ScDocShell::HasChangeRecordProtection() const
2830*cdf0e10cSrcweir {
2831*cdf0e10cSrcweir     bool bRes = false;
2832*cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2833*cdf0e10cSrcweir     if (pChangeTrack)
2834*cdf0e10cSrcweir         bRes = pChangeTrack->IsProtected();
2835*cdf0e10cSrcweir     return bRes;
2836*cdf0e10cSrcweir }
2837*cdf0e10cSrcweir 
2838*cdf0e10cSrcweir 
2839*cdf0e10cSrcweir void ScDocShell::SetChangeRecording( bool bActivate )
2840*cdf0e10cSrcweir {
2841*cdf0e10cSrcweir     bool bOldChangeRecording = IsChangeRecording();
2842*cdf0e10cSrcweir 
2843*cdf0e10cSrcweir     if (bActivate)
2844*cdf0e10cSrcweir     {
2845*cdf0e10cSrcweir         aDocument.StartChangeTracking();
2846*cdf0e10cSrcweir         ScChangeViewSettings aChangeViewSet;
2847*cdf0e10cSrcweir         aChangeViewSet.SetShowChanges(sal_True);
2848*cdf0e10cSrcweir         aDocument.SetChangeViewSettings(aChangeViewSet);
2849*cdf0e10cSrcweir     }
2850*cdf0e10cSrcweir     else
2851*cdf0e10cSrcweir     {
2852*cdf0e10cSrcweir         aDocument.EndChangeTracking();
2853*cdf0e10cSrcweir         PostPaintGridAll();
2854*cdf0e10cSrcweir     }
2855*cdf0e10cSrcweir 
2856*cdf0e10cSrcweir     if (bOldChangeRecording != IsChangeRecording())
2857*cdf0e10cSrcweir     {
2858*cdf0e10cSrcweir         UpdateAcceptChangesDialog();
2859*cdf0e10cSrcweir         // Slots invalidieren
2860*cdf0e10cSrcweir         SfxBindings* pBindings = GetViewBindings();
2861*cdf0e10cSrcweir         if (pBindings)
2862*cdf0e10cSrcweir             pBindings->InvalidateAll(sal_False);
2863*cdf0e10cSrcweir     }
2864*cdf0e10cSrcweir }
2865*cdf0e10cSrcweir 
2866*cdf0e10cSrcweir 
2867*cdf0e10cSrcweir bool ScDocShell::SetProtectionPassword( const String &rNewPassword )
2868*cdf0e10cSrcweir {
2869*cdf0e10cSrcweir     bool bRes = false;
2870*cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2871*cdf0e10cSrcweir     if (pChangeTrack)
2872*cdf0e10cSrcweir     {
2873*cdf0e10cSrcweir         sal_Bool bProtected = pChangeTrack->IsProtected();
2874*cdf0e10cSrcweir 
2875*cdf0e10cSrcweir         if (rNewPassword.Len())
2876*cdf0e10cSrcweir         {
2877*cdf0e10cSrcweir             // when password protection is applied change tracking must always be active
2878*cdf0e10cSrcweir             SetChangeRecording( true );
2879*cdf0e10cSrcweir 
2880*cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< sal_Int8 > aProtectionHash;
2881*cdf0e10cSrcweir             SvPasswordHelper::GetHashPassword( aProtectionHash, rNewPassword );
2882*cdf0e10cSrcweir             pChangeTrack->SetProtection( aProtectionHash );
2883*cdf0e10cSrcweir         }
2884*cdf0e10cSrcweir         else
2885*cdf0e10cSrcweir         {
2886*cdf0e10cSrcweir             pChangeTrack->SetProtection( ::com::sun::star::uno::Sequence< sal_Int8 >() );
2887*cdf0e10cSrcweir         }
2888*cdf0e10cSrcweir         bRes = true;
2889*cdf0e10cSrcweir 
2890*cdf0e10cSrcweir         if ( bProtected != pChangeTrack->IsProtected() )
2891*cdf0e10cSrcweir         {
2892*cdf0e10cSrcweir             UpdateAcceptChangesDialog();
2893*cdf0e10cSrcweir             SetDocumentModified();
2894*cdf0e10cSrcweir         }
2895*cdf0e10cSrcweir     }
2896*cdf0e10cSrcweir 
2897*cdf0e10cSrcweir     return bRes;
2898*cdf0e10cSrcweir }
2899*cdf0e10cSrcweir 
2900*cdf0e10cSrcweir 
2901*cdf0e10cSrcweir bool ScDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash )
2902*cdf0e10cSrcweir {
2903*cdf0e10cSrcweir     bool bRes = false;
2904*cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2905*cdf0e10cSrcweir     if (pChangeTrack && pChangeTrack->IsProtected())
2906*cdf0e10cSrcweir     {
2907*cdf0e10cSrcweir         rPasswordHash = pChangeTrack->GetProtection();
2908*cdf0e10cSrcweir         bRes = true;
2909*cdf0e10cSrcweir     }
2910*cdf0e10cSrcweir     return bRes;
2911*cdf0e10cSrcweir }
2912*cdf0e10cSrcweir 
2913*cdf0e10cSrcweir 
2914