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