xref: /aoo41x/main/sc/source/ui/docshell/docsh4.cxx (revision c7be74b1)
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 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
29cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
35cdf0e10cSrcweir #include <math.h>		// prevent conflict between exception and std::exception
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "scitems.hxx"
38cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
39cdf0e10cSrcweir #include <editeng/eeitem.hxx>
40cdf0e10cSrcweir #include <sfx2/objface.hxx>
41cdf0e10cSrcweir #include <sfx2/app.hxx>
42cdf0e10cSrcweir #include <sfx2/bindings.hxx>
43cdf0e10cSrcweir #include <sfx2/docfile.hxx>
44cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
45cdf0e10cSrcweir #include <svtools/ehdl.hxx>
46cdf0e10cSrcweir #include <basic/sbxcore.hxx>
47cdf0e10cSrcweir #include <sfx2/printer.hxx>
48cdf0e10cSrcweir #include <sfx2/request.hxx>
49cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
50cdf0e10cSrcweir #include <svx/ofaitem.hxx>
51cdf0e10cSrcweir #include <sot/formats.hxx>
52cdf0e10cSrcweir #include <svl/whiter.hxx>
53cdf0e10cSrcweir #include <vcl/msgbox.hxx>
54cdf0e10cSrcweir #include <vcl/waitobj.hxx>
55cdf0e10cSrcweir #include <tools/multisel.hxx>
56cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
57cdf0e10cSrcweir #include <svx/drawitem.hxx>
58cdf0e10cSrcweir #include <svx/fmview.hxx>
59cdf0e10cSrcweir #include <svx/pageitem.hxx>
60cdf0e10cSrcweir #include <svx/svditer.hxx>
61cdf0e10cSrcweir #include <svx/svdpage.hxx>
62cdf0e10cSrcweir #include <svx/fmshell.hxx>
63cdf0e10cSrcweir #include <svtools/xwindowitem.hxx>
64cdf0e10cSrcweir #include <sfx2/passwd.hxx>
65cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
66cdf0e10cSrcweir #include <sfx2/docinsert.hxx>
67cdf0e10cSrcweir #include <svl/PasswordHelper.hxx>
68cdf0e10cSrcweir #include <svl/documentlockfile.hxx>
69cdf0e10cSrcweir #include <svl/sharecontrolfile.hxx>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
72cdf0e10cSrcweir #include "docuno.hxx"
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
75cdf0e10cSrcweir #include "docsh.hxx"
76cdf0e10cSrcweir #include "docshimp.hxx"
77cdf0e10cSrcweir #include "docfunc.hxx"
78cdf0e10cSrcweir #include "sc.hrc"
79cdf0e10cSrcweir #include "stlsheet.hxx"
80cdf0e10cSrcweir #include "stlpool.hxx"
81cdf0e10cSrcweir #include "appoptio.hxx"
82cdf0e10cSrcweir #include "globstr.hrc"
83cdf0e10cSrcweir #include "global.hxx"
84cdf0e10cSrcweir //CHINA001 #include "styledlg.hxx"
85cdf0e10cSrcweir //CHINA001 #include "hfedtdlg.hxx"
86cdf0e10cSrcweir #include "dbdocfun.hxx"
87cdf0e10cSrcweir #include "printfun.hxx"              // DrawToDev
88cdf0e10cSrcweir #include "viewdata.hxx"
89cdf0e10cSrcweir #include "tabvwsh.hxx"
90cdf0e10cSrcweir #include "impex.hxx"
91cdf0e10cSrcweir #include "attrib.hxx"
92cdf0e10cSrcweir //CHINA001 #include "corodlg.hxx"
93cdf0e10cSrcweir #include "undodat.hxx"
94cdf0e10cSrcweir #include "autostyl.hxx"
95cdf0e10cSrcweir #include "undocell.hxx"
96cdf0e10cSrcweir #include "undotab.hxx"
97cdf0e10cSrcweir #include "inputhdl.hxx"
98cdf0e10cSrcweir #include "dbcolect.hxx"
99cdf0e10cSrcweir #include "servobj.hxx"
100cdf0e10cSrcweir #include "rangenam.hxx"
101cdf0e10cSrcweir #include "scmod.hxx"
102cdf0e10cSrcweir //CHINA001 #include "scendlg.hxx"
103cdf0e10cSrcweir #include "chgviset.hxx"
104cdf0e10cSrcweir #include "reffact.hxx"
105cdf0e10cSrcweir #include "chartlis.hxx"
106cdf0e10cSrcweir #include "chartpos.hxx"
107cdf0e10cSrcweir #include "waitoff.hxx"
108cdf0e10cSrcweir #include "tablink.hxx"		// ScDocumentLoader statics
109cdf0e10cSrcweir #include "drwlayer.hxx"
110cdf0e10cSrcweir #include "docoptio.hxx"
111cdf0e10cSrcweir #include "undostyl.hxx"
112cdf0e10cSrcweir #include "rangeseq.hxx"
113cdf0e10cSrcweir #include "chgtrack.hxx"
114cdf0e10cSrcweir #include "printopt.hxx"
115cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp>
116cdf0e10cSrcweir #include "scresid.hxx" //add by CHINA001
117cdf0e10cSrcweir #include "scabstdlg.hxx" //CHINA001
118cdf0e10cSrcweir #include "externalrefmgr.hxx"
119cdf0e10cSrcweir #include "sharedocdlg.hxx"
120cdf0e10cSrcweir #include "conditio.hxx"
121cdf0e10cSrcweir #include "sheetevents.hxx"
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //------------------------------------------------------------------
124cdf0e10cSrcweir 
125cdf0e10cSrcweir #define IS_SHARE_HEADER(set) \
126cdf0e10cSrcweir 	((SfxBoolItem&) \
127cdf0e10cSrcweir 		((SvxSetItem&)(set).Get(ATTR_PAGE_HEADERSET)).GetItemSet(). \
128cdf0e10cSrcweir 			Get(ATTR_PAGE_SHARED)).GetValue()
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #define IS_SHARE_FOOTER(set) \
131cdf0e10cSrcweir 	((SfxBoolItem&) \
132cdf0e10cSrcweir 		((SvxSetItem&)(set).Get(ATTR_PAGE_FOOTERSET)).GetItemSet(). \
133cdf0e10cSrcweir 			Get(ATTR_PAGE_SHARED)).GetValue()
134cdf0e10cSrcweir 
135cdf0e10cSrcweir #define IS_AVAILABLE(WhichId,ppItem) \
136cdf0e10cSrcweir     (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
137cdf0e10cSrcweir 
138cdf0e10cSrcweir #define SC_PREVIEW_SIZE_X	10000
139cdf0e10cSrcweir #define SC_PREVIEW_SIZE_Y	12400
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //------------------------------------------------------------------
143cdf0e10cSrcweir 
144cdf0e10cSrcweir void ScDocShell::Execute( SfxRequest& rReq )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	//	SID_SC_RANGE (Range),
147cdf0e10cSrcweir 	//	SID_SC_CELLTEXT (CellText),
148cdf0e10cSrcweir 	//	SID_SC_CELLS (Cells) - removed (old Basic)
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	const SfxItemSet* pReqArgs = rReq.GetArgs();
151cdf0e10cSrcweir 	SfxBindings* pBindings = GetViewBindings();
152cdf0e10cSrcweir 	sal_Bool bUndo (aDocument.IsUndoEnabled());
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	sal_uInt16 nSlot = rReq.GetSlot();
155cdf0e10cSrcweir 	switch ( nSlot )
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		case SID_SC_SETTEXT:
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			const SfxPoolItem* pColItem;
160cdf0e10cSrcweir 			const SfxPoolItem* pRowItem;
161cdf0e10cSrcweir 			const SfxPoolItem* pTabItem;
162cdf0e10cSrcweir 			const SfxPoolItem* pTextItem;
163cdf0e10cSrcweir 			if( pReqArgs && IS_AVAILABLE( FN_PARAM_1, &pColItem ) &&
164cdf0e10cSrcweir 							IS_AVAILABLE( FN_PARAM_2, &pRowItem ) &&
165cdf0e10cSrcweir 							IS_AVAILABLE( FN_PARAM_3, &pTabItem ) &&
166cdf0e10cSrcweir 							IS_AVAILABLE( SID_SC_SETTEXT, &pTextItem ) )
167cdf0e10cSrcweir 			{
168cdf0e10cSrcweir 				//	Parameter sind 1-based !!!
169cdf0e10cSrcweir 				SCCOL nCol = ((SfxInt16Item*)pColItem)->GetValue() - 1;
170cdf0e10cSrcweir 				SCROW nRow = ((SfxInt32Item*)pRowItem)->GetValue() - 1;
171cdf0e10cSrcweir 				SCTAB nTab = ((SfxInt16Item*)pTabItem)->GetValue() - 1;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 				SCTAB nTabCount = aDocument.GetTableCount();
174cdf0e10cSrcweir 				if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) )
175cdf0e10cSrcweir 				{
176cdf0e10cSrcweir 					if ( aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
177cdf0e10cSrcweir 					{
178cdf0e10cSrcweir 						String aVal = ((const SfxStringItem*)pTextItem)->GetValue();
179cdf0e10cSrcweir 						aDocument.SetString( nCol, nRow, nTab, aVal );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 						PostPaintCell( nCol, nRow, nTab );
182cdf0e10cSrcweir 						SetDocumentModified();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 						rReq.Done();
185cdf0e10cSrcweir 						break;
186cdf0e10cSrcweir 					}
187cdf0e10cSrcweir 					else				// geschuetzte Zelle
188cdf0e10cSrcweir 					{
189cdf0e10cSrcweir 						SbxBase::SetError( SbxERR_BAD_PARAMETER );		//! welchen Fehler ?
190cdf0e10cSrcweir 						break;
191cdf0e10cSrcweir 					}
192cdf0e10cSrcweir 				}
193cdf0e10cSrcweir 			}
194cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_NO_OBJECT );
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 		break;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		case SID_SBA_IMPORT:
199cdf0e10cSrcweir 		{
200cdf0e10cSrcweir 			if (pReqArgs)
201cdf0e10cSrcweir 			{
202cdf0e10cSrcweir                 const SfxPoolItem* pItem;
203cdf0e10cSrcweir                 svx::ODataAccessDescriptor aDesc;
204cdf0e10cSrcweir                 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
205cdf0e10cSrcweir                 {
206cdf0e10cSrcweir                     uno::Any aAny = static_cast<const SfxUsrAnyItem*>(pItem)->GetValue();
207cdf0e10cSrcweir                     uno::Sequence<beans::PropertyValue> aProperties;
208cdf0e10cSrcweir                     if ( aAny >>= aProperties )
209cdf0e10cSrcweir                         aDesc.initializeFrom( aProperties );
210cdf0e10cSrcweir                 }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir                 String sTarget;
213cdf0e10cSrcweir 				if ( pReqArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
214cdf0e10cSrcweir 					sTarget = ((const SfxStringItem*)pItem)->GetValue();
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 				sal_Bool bIsNewArea = sal_True;			// Default sal_True (keine Nachfrage)
217cdf0e10cSrcweir 				if ( pReqArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
218cdf0e10cSrcweir 					bIsNewArea = ((const SfxBoolItem*)pItem)->GetValue();
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 				// bei Bedarf neuen Datenbankbereich anlegen
221cdf0e10cSrcweir 				sal_Bool bMakeArea = sal_False;
222cdf0e10cSrcweir 				if (bIsNewArea)
223cdf0e10cSrcweir 				{
224cdf0e10cSrcweir 					ScDBCollection* pDBColl = aDocument.GetDBCollection();
225cdf0e10cSrcweir 					sal_uInt16 nDummy;
226cdf0e10cSrcweir 					if ( !pDBColl || !pDBColl->SearchName( sTarget, nDummy ) )
227cdf0e10cSrcweir 					{
228cdf0e10cSrcweir 						ScAddress aPos;
229cdf0e10cSrcweir 						if ( aPos.Parse( sTarget, &aDocument, aDocument.GetAddressConvention() ) & SCA_VALID )
230cdf0e10cSrcweir 						{
231cdf0e10cSrcweir 							bMakeArea = sal_True;
232cdf0e10cSrcweir 							if (bUndo)
233cdf0e10cSrcweir 							{
234cdf0e10cSrcweir 								String aStrImport = ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
235cdf0e10cSrcweir 								GetUndoManager()->EnterListAction( aStrImport, aStrImport );
236cdf0e10cSrcweir 							}
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 							ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, SC_DBSEL_KEEP );
239cdf0e10cSrcweir 							DBG_ASSERT(pDBData, "kann DB-Daten nicht anlegen");
240cdf0e10cSrcweir 							sTarget = pDBData->GetName();
241cdf0e10cSrcweir 						}
242cdf0e10cSrcweir 					}
243cdf0e10cSrcweir 				}
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 				// nachfragen, bevor alter DB-Bereich ueberschrieben wird
246cdf0e10cSrcweir 				sal_Bool bDo = sal_True;
247cdf0e10cSrcweir 				if (!bIsNewArea)
248cdf0e10cSrcweir 				{
249cdf0e10cSrcweir 					String aTemplate = ScGlobal::GetRscString( STR_IMPORT_REPLACE );
250cdf0e10cSrcweir 					String aMessage = aTemplate.GetToken( 0, '#' );
251cdf0e10cSrcweir 					aMessage += sTarget;
252cdf0e10cSrcweir 					aMessage += aTemplate.GetToken( 1, '#' );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 					QueryBox aBox( 0, WinBits(WB_YES_NO | WB_DEF_YES), aMessage );
255cdf0e10cSrcweir 					bDo = ( aBox.Execute() == RET_YES );
256cdf0e10cSrcweir 				}
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 				if (bDo)
259cdf0e10cSrcweir 				{
260cdf0e10cSrcweir                     ScDBDocFunc(*this).UpdateImport( sTarget, aDesc );
261cdf0e10cSrcweir 					rReq.Done();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 					//	UpdateImport aktualisiert auch die internen Operationen
264cdf0e10cSrcweir 				}
265cdf0e10cSrcweir 				else
266cdf0e10cSrcweir 					rReq.Ignore();
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 				if ( bMakeArea && bUndo)
269cdf0e10cSrcweir 					GetUndoManager()->LeaveListAction();
270cdf0e10cSrcweir 			}
271cdf0e10cSrcweir 			else
272cdf0e10cSrcweir 			{
273cdf0e10cSrcweir 				DBG_ERROR( "arguments expected" );
274cdf0e10cSrcweir 			}
275cdf0e10cSrcweir 		}
276cdf0e10cSrcweir 		break;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		case SID_CHART_SOURCE:
279cdf0e10cSrcweir 		case SID_CHART_ADDSOURCE:
280cdf0e10cSrcweir 			if (pReqArgs)
281cdf0e10cSrcweir 			{
282cdf0e10cSrcweir 				ScDocument* pDoc = GetDocument();
283cdf0e10cSrcweir //                sal_Bool bUndo (pDoc->IsUndoEnabled());
284cdf0e10cSrcweir 				const	SfxPoolItem* pItem;
285cdf0e10cSrcweir 				String	aChartName, aRangeName;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 				ScRange			aSingleRange;
288cdf0e10cSrcweir 				ScRangeListRef	aRangeListRef;
289cdf0e10cSrcweir 				sal_Bool			bMultiRange = sal_False;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 				sal_Bool bColHeaders = sal_True;
292cdf0e10cSrcweir 				sal_Bool bRowHeaders = sal_True;
293cdf0e10cSrcweir 				sal_Bool bColInit = sal_False;
294cdf0e10cSrcweir 				sal_Bool bRowInit = sal_False;
295cdf0e10cSrcweir 				sal_Bool bAddRange = (nSlot == SID_CHART_ADDSOURCE);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 				if( IS_AVAILABLE( SID_CHART_NAME, &pItem ) )
298cdf0e10cSrcweir 					aChartName = ((const SfxStringItem*)pItem)->GetValue();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 				if( IS_AVAILABLE( SID_CHART_SOURCE, &pItem ) )
301cdf0e10cSrcweir 					aRangeName = ((const SfxStringItem*)pItem)->GetValue();
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 				if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
304cdf0e10cSrcweir 				{
305cdf0e10cSrcweir 					bColHeaders = ((const SfxBoolItem*)pItem)->GetValue();
306cdf0e10cSrcweir 					bColInit = sal_True;
307cdf0e10cSrcweir 				}
308cdf0e10cSrcweir 				if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
309cdf0e10cSrcweir 				{
310cdf0e10cSrcweir 					bRowHeaders = ((const SfxBoolItem*)pItem)->GetValue();
311cdf0e10cSrcweir 					bRowInit = sal_True;
312cdf0e10cSrcweir 				}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir                 ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
315cdf0e10cSrcweir 				sal_Bool bValid = ( aSingleRange.ParseAny( aRangeName, pDoc, aDetails ) & SCA_VALID ) != 0;
316cdf0e10cSrcweir 				if (!bValid)
317cdf0e10cSrcweir 				{
318cdf0e10cSrcweir 					aRangeListRef = new ScRangeList;
319cdf0e10cSrcweir 					aRangeListRef->Parse( aRangeName, pDoc );
320cdf0e10cSrcweir 					if ( aRangeListRef->Count() )
321cdf0e10cSrcweir 					{
322cdf0e10cSrcweir 						bMultiRange = sal_True;
323cdf0e10cSrcweir 						aSingleRange = *aRangeListRef->GetObject(0);	// fuer Header
324cdf0e10cSrcweir 						bValid = sal_True;
325cdf0e10cSrcweir 					}
326cdf0e10cSrcweir 					else
327cdf0e10cSrcweir 						aRangeListRef.Clear();
328cdf0e10cSrcweir 				}
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 				ScTabViewShell* pViewSh	= ScTabViewShell::GetActiveViewShell();
331cdf0e10cSrcweir 				if (pViewSh && bValid && aChartName.Len() != 0 )
332cdf0e10cSrcweir 				{
333cdf0e10cSrcweir 					Window*	pParent	= pViewSh->GetDialogParent();
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 					SCCOL nCol1 = aSingleRange.aStart.Col();
336cdf0e10cSrcweir 					SCROW nRow1 = aSingleRange.aStart.Row();
337cdf0e10cSrcweir 					SCCOL nCol2 = aSingleRange.aEnd.Col();
338cdf0e10cSrcweir 					SCROW nRow2 = aSingleRange.aEnd.Row();
339cdf0e10cSrcweir 					SCTAB nTab = aSingleRange.aStart.Tab();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 					//!	immer oder gar nicht begrenzen ???
342cdf0e10cSrcweir 					if (!bMultiRange)
343cdf0e10cSrcweir 						aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 										// Dialog fuer Spalten/Zeilenkoepfe
346cdf0e10cSrcweir 					sal_Bool bOk = sal_True;
347cdf0e10cSrcweir 					if ( !bAddRange && ( !bColInit || !bRowInit ) )
348cdf0e10cSrcweir 					{
349cdf0e10cSrcweir                         ScChartPositioner aChartPositioner( &aDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
350cdf0e10cSrcweir                         if (!bColInit)
351cdf0e10cSrcweir                             bColHeaders = aChartPositioner.HasColHeaders();
352cdf0e10cSrcweir                         if (!bRowInit)
353cdf0e10cSrcweir                             bRowHeaders = aChartPositioner.HasRowHeaders();
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 						//CHINA001 ScColRowLabelDlg aDlg( pParent, bRowHeaders, bColHeaders );
356cdf0e10cSrcweir 						ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
357cdf0e10cSrcweir 						DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 						AbstractScColRowLabelDlg* pDlg = pFact->CreateScColRowLabelDlg( pParent, RID_SCDLG_CHARTCOLROW, bRowHeaders, bColHeaders);
360cdf0e10cSrcweir 						DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
361cdf0e10cSrcweir 						if ( pDlg->Execute() == RET_OK ) //CHINA001 if ( aDlg.Execute() == RET_OK )
362cdf0e10cSrcweir 						{
363cdf0e10cSrcweir 							bColHeaders = pDlg->IsRow();		//CHINA001 bColHeaders = aDlg.IsRow();	// Spaltenkoepfe = 1. Zeile
364cdf0e10cSrcweir 							bRowHeaders = pDlg->IsCol(); //CHINA001 bRowHeaders = aDlg.IsCol();
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 							rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders));
367cdf0e10cSrcweir 							rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders));
368cdf0e10cSrcweir 						}
369cdf0e10cSrcweir 						else
370cdf0e10cSrcweir 							bOk = sal_False;
371cdf0e10cSrcweir 						delete pDlg; //CHINA001
372cdf0e10cSrcweir 					}
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 					if (bOk)			// ausfuehren
375cdf0e10cSrcweir 					{
376cdf0e10cSrcweir 						if (bMultiRange)
377cdf0e10cSrcweir 						{
378cdf0e10cSrcweir 							if (bUndo)
379cdf0e10cSrcweir 							{
380cdf0e10cSrcweir 								GetUndoManager()->AddUndoAction(
381cdf0e10cSrcweir 									new ScUndoChartData( this, aChartName, aRangeListRef,
382cdf0e10cSrcweir 															bColHeaders, bRowHeaders, bAddRange ) );
383cdf0e10cSrcweir 							}
384cdf0e10cSrcweir 							aDocument.UpdateChartArea( aChartName, aRangeListRef,
385cdf0e10cSrcweir 														bColHeaders, bRowHeaders, bAddRange );
386cdf0e10cSrcweir 						}
387cdf0e10cSrcweir 						else
388cdf0e10cSrcweir 						{
389cdf0e10cSrcweir 							ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
390cdf0e10cSrcweir 							if (bUndo)
391cdf0e10cSrcweir 							{
392cdf0e10cSrcweir 								GetUndoManager()->AddUndoAction(
393cdf0e10cSrcweir 									new ScUndoChartData( this, aChartName, aNewRange,
394cdf0e10cSrcweir 															bColHeaders, bRowHeaders, bAddRange ) );
395cdf0e10cSrcweir 							}
396cdf0e10cSrcweir 							aDocument.UpdateChartArea( aChartName, aNewRange,
397cdf0e10cSrcweir 														bColHeaders, bRowHeaders, bAddRange );
398cdf0e10cSrcweir 						}
399cdf0e10cSrcweir 					}
400cdf0e10cSrcweir 				}
401cdf0e10cSrcweir 				else
402cdf0e10cSrcweir 				{
403cdf0e10cSrcweir 					DBG_ERROR("UpdateChartArea: keine ViewShell oder falsche Daten");
404cdf0e10cSrcweir 				}
405cdf0e10cSrcweir 				rReq.Done();
406cdf0e10cSrcweir 			}
407cdf0e10cSrcweir 			else
408cdf0e10cSrcweir 			{
409cdf0e10cSrcweir 				DBG_ERROR("SID_CHART_SOURCE ohne Argumente");
410cdf0e10cSrcweir 			}
411cdf0e10cSrcweir 			break;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 		case FID_AUTO_CALC:
414cdf0e10cSrcweir 			{
415cdf0e10cSrcweir 				sal_Bool bNewVal;
416cdf0e10cSrcweir 				const SfxPoolItem* pItem;
417cdf0e10cSrcweir 				if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
418cdf0e10cSrcweir 					bNewVal = ((const SfxBoolItem*)pItem)->GetValue();
419cdf0e10cSrcweir 				else
420cdf0e10cSrcweir 					bNewVal = !aDocument.GetAutoCalc();		// Toggle fuer Menue
421cdf0e10cSrcweir 				aDocument.SetAutoCalc( bNewVal );
422cdf0e10cSrcweir 				SetDocumentModified();
423cdf0e10cSrcweir 				if (pBindings)
424cdf0e10cSrcweir 				{
425cdf0e10cSrcweir 					pBindings->Invalidate( FID_AUTO_CALC );
426cdf0e10cSrcweir //					pBindings->Invalidate( FID_RECALC );		// jetzt immer enabled
427cdf0e10cSrcweir 				}
428cdf0e10cSrcweir                 rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) );
429cdf0e10cSrcweir 				rReq.Done();
430cdf0e10cSrcweir 			}
431cdf0e10cSrcweir 			break;
432cdf0e10cSrcweir 		case FID_RECALC:
433cdf0e10cSrcweir 			DoRecalc( rReq.IsAPI() );
434cdf0e10cSrcweir 			rReq.Done();
435cdf0e10cSrcweir 			break;
436cdf0e10cSrcweir 		case FID_HARD_RECALC:
437cdf0e10cSrcweir 			DoHardRecalc( rReq.IsAPI() );
438cdf0e10cSrcweir 			rReq.Done();
439cdf0e10cSrcweir 			break;
440cdf0e10cSrcweir 		case SID_UPDATETABLINKS:
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir 				ScDocument* pDoc = GetDocument();
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 				ScLkUpdMode nSet=pDoc->GetLinkMode();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 				sal_uInt16 nDlgRet=RET_NO;
447cdf0e10cSrcweir 				if(nSet==LM_UNKNOWN)
448cdf0e10cSrcweir 				{
449cdf0e10cSrcweir 					ScAppOptions aAppOptions=SC_MOD()->GetAppOptions();
450cdf0e10cSrcweir 					nSet=aAppOptions.GetLinkMode();
451cdf0e10cSrcweir 				}
452cdf0e10cSrcweir 
453cdf0e10cSrcweir                 if (nCanUpdate == com::sun::star::document::UpdateDocMode::NO_UPDATE)
454cdf0e10cSrcweir                     nSet = LM_NEVER;
455cdf0e10cSrcweir                 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::QUIET_UPDATE &&
456cdf0e10cSrcweir                     nSet == LM_ON_DEMAND)
457cdf0e10cSrcweir                     nSet = LM_NEVER;
458cdf0e10cSrcweir                 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::FULL_UPDATE)
459cdf0e10cSrcweir                     nSet = LM_ALWAYS;
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 				if(nSet==LM_ON_DEMAND)
462cdf0e10cSrcweir 				{
463cdf0e10cSrcweir 					QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
464cdf0e10cSrcweir 											 ScGlobal::GetRscString(STR_RELOAD_TABLES) );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 					nDlgRet=aBox.Execute();
467cdf0e10cSrcweir 				}
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 				if (nDlgRet == RET_YES || nSet==LM_ALWAYS)
470cdf0e10cSrcweir 				{
471cdf0e10cSrcweir 					ReloadTabLinks();
472cdf0e10cSrcweir                     aDocument.UpdateExternalRefLinks();
473cdf0e10cSrcweir 					aDocument.UpdateDdeLinks();
474cdf0e10cSrcweir 					aDocument.UpdateAreaLinks();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 					//! Test, ob Fehler
477cdf0e10cSrcweir 					rReq.Done();
478cdf0e10cSrcweir 				}
479cdf0e10cSrcweir 				else
480cdf0e10cSrcweir 					rReq.Ignore();
481cdf0e10cSrcweir 			}
482cdf0e10cSrcweir 			break;
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 		case SID_REIMPORT_AFTER_LOAD:
485cdf0e10cSrcweir 			{
486cdf0e10cSrcweir 				//	wird nach dem Laden aufgerufen, wenn DB-Bereiche mit
487cdf0e10cSrcweir 				//	weggelassenen Daten enthalten sind
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 				sal_Bool bDone = sal_False;
490cdf0e10cSrcweir                 ScDBCollection* pDBColl = aDocument.GetDBCollection();
491cdf0e10cSrcweir 
492cdf0e10cSrcweir                 if ((nCanUpdate != com::sun::star::document::UpdateDocMode::NO_UPDATE) &&
493cdf0e10cSrcweir                    (nCanUpdate != com::sun::star::document::UpdateDocMode::QUIET_UPDATE))
494cdf0e10cSrcweir                 {
495cdf0e10cSrcweir 				    ScRange aRange;
496cdf0e10cSrcweir 				    ScTabViewShell* pViewSh = GetBestViewShell();
497cdf0e10cSrcweir 				    DBG_ASSERT(pViewSh,"SID_REIMPORT_AFTER_LOAD: keine View");
498cdf0e10cSrcweir                     if (pViewSh && pDBColl)
499cdf0e10cSrcweir 				    {
500cdf0e10cSrcweir 					    QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
501cdf0e10cSrcweir 											    ScGlobal::GetRscString(STR_REIMPORT_AFTER_LOAD) );
502cdf0e10cSrcweir 					    if (aBox.Execute() == RET_YES)
503cdf0e10cSrcweir 					    {
504cdf0e10cSrcweir 						    for (sal_uInt16 i=0; i<pDBColl->GetCount(); i++)
505cdf0e10cSrcweir 						    {
506cdf0e10cSrcweir 							    ScDBData* pDBData = (*pDBColl)[i];
507cdf0e10cSrcweir 							    if ( pDBData->IsStripData() &&
508cdf0e10cSrcweir 									    pDBData->HasImportParam() && !pDBData->HasImportSelection() )
509cdf0e10cSrcweir 							    {
510cdf0e10cSrcweir 								    pDBData->GetArea(aRange);
511cdf0e10cSrcweir 								    pViewSh->MarkRange(aRange);
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 								    //	Import und interne Operationen wie SID_REFRESH_DBAREA
514cdf0e10cSrcweir 								    //	(Abfrage auf Import hier nicht noetig)
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 								    ScImportParam aImportParam;
517cdf0e10cSrcweir 								    pDBData->GetImportParam( aImportParam );
518cdf0e10cSrcweir 								    sal_Bool bContinue = pViewSh->ImportData( aImportParam );
519cdf0e10cSrcweir 								    pDBData->SetImportParam( aImportParam );
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 								    //	markieren (Groesse kann sich geaendert haben)
522cdf0e10cSrcweir 								    pDBData->GetArea(aRange);
523cdf0e10cSrcweir 								    pViewSh->MarkRange(aRange);
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 								    if ( bContinue )	// #41905# Fehler beim Import -> Abbruch
526cdf0e10cSrcweir 								    {
527cdf0e10cSrcweir 									    //	interne Operationen, wenn welche gespeichert
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 									    if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
530cdf0e10cSrcweir 																	    pDBData->HasSubTotalParam() )
531cdf0e10cSrcweir 										    pViewSh->RepeatDB();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 									    //	Pivottabellen die den Bereich als Quelldaten haben
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 									    RefreshPivotTables(aRange);
536cdf0e10cSrcweir 								    }
537cdf0e10cSrcweir 							    }
538cdf0e10cSrcweir 						    }
539cdf0e10cSrcweir 						    bDone = sal_True;
540cdf0e10cSrcweir 					    }
541cdf0e10cSrcweir 				    }
542cdf0e10cSrcweir                 }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir                 if ( !bDone && pDBColl )
545cdf0e10cSrcweir                 {
546cdf0e10cSrcweir                     //	wenn nicht, dann aber die abhaengigen Formeln updaten
547cdf0e10cSrcweir                     //! auch fuer einzelne Bereiche, die nicht aktualisiert werden koennen
548cdf0e10cSrcweir 
549cdf0e10cSrcweir                     aDocument.CalcAll();		//! nur die abhaengigen
550cdf0e10cSrcweir                     PostDataChanged();
551cdf0e10cSrcweir                 }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir                 if (bDone)
554cdf0e10cSrcweir 					rReq.Done();
555cdf0e10cSrcweir 				else
556cdf0e10cSrcweir 					rReq.Ignore();
557cdf0e10cSrcweir 			}
558cdf0e10cSrcweir 			break;
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 		case SID_AUTO_STYLE:
562cdf0e10cSrcweir 			DBG_ERROR("use ScAutoStyleHint instead of SID_AUTO_STYLE");
563cdf0e10cSrcweir 			break;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 		case SID_GET_COLORTABLE:
566cdf0e10cSrcweir 			{
567cdf0e10cSrcweir 				//	passende ColorTable ist per PutItem gesetzt worden
568*c7be74b1SArmin Le Grand 				const SvxColorTableItem* pColItem = static_cast< const SvxColorTableItem* >(GetItem(SID_COLOR_TABLE));
569*c7be74b1SArmin Le Grand 				XColorListSharedPtr aTable = pColItem->GetColorTable();
570*c7be74b1SArmin Le Grand 
571*c7be74b1SArmin Le Grand 				rReq.SetReturnValue(SvxColorTableItem(aTable, SID_GET_COLORTABLE));
572cdf0e10cSrcweir 			}
573cdf0e10cSrcweir 			break;
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		case FID_CHG_RECORD:
576cdf0e10cSrcweir 			{
577cdf0e10cSrcweir 				ScDocument* pDoc = GetDocument();
578cdf0e10cSrcweir 				if(pDoc!=NULL)
579cdf0e10cSrcweir 				{
580cdf0e10cSrcweir                     // get argument (recorded macro)
581cdf0e10cSrcweir                     SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FID_CHG_RECORD, sal_False );
582cdf0e10cSrcweir                     sal_Bool bDo = sal_True;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir                     // xmlsec05/06:
585cdf0e10cSrcweir                     // getting real parent window when called from Security-Options TP
586cdf0e10cSrcweir                     Window* pParent = NULL;
587cdf0e10cSrcweir                     const SfxPoolItem* pParentItem;
588cdf0e10cSrcweir                     if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
589cdf0e10cSrcweir                         pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
590cdf0e10cSrcweir 
591cdf0e10cSrcweir                     // desired state
592cdf0e10cSrcweir                     ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
593cdf0e10cSrcweir                     sal_Bool bActivateTracking = (pChangeTrack == 0);   // toggle
594cdf0e10cSrcweir                     if ( pItem )
595cdf0e10cSrcweir                         bActivateTracking = pItem->GetValue();      // from argument
596cdf0e10cSrcweir 
597cdf0e10cSrcweir                     if ( !bActivateTracking )
598cdf0e10cSrcweir 					{
599cdf0e10cSrcweir                         if ( !pItem )
600cdf0e10cSrcweir                         {
601cdf0e10cSrcweir                             // no dialog on playing the macro
602cdf0e10cSrcweir 							WarningBox aBox( pParent ? pParent : GetActiveDialogParent(),
603cdf0e10cSrcweir                                 WinBits(WB_YES_NO | WB_DEF_NO),
604cdf0e10cSrcweir                                 ScGlobal::GetRscString( STR_END_REDLINING ) );
605cdf0e10cSrcweir                             bDo = ( aBox.Execute() == RET_YES );
606cdf0e10cSrcweir                         }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir                         if ( bDo )
609cdf0e10cSrcweir                         {
610cdf0e10cSrcweir                             if ( pChangeTrack->IsProtected() )
611cdf0e10cSrcweir                                 bDo = ExecuteChangeProtectionDialog( NULL );
612cdf0e10cSrcweir                             if ( bDo )
613cdf0e10cSrcweir                             {
614cdf0e10cSrcweir                                 pDoc->EndChangeTracking();
615cdf0e10cSrcweir                                 PostPaintGridAll();
616cdf0e10cSrcweir                             }
617cdf0e10cSrcweir                         }
618cdf0e10cSrcweir 					}
619cdf0e10cSrcweir 					else
620cdf0e10cSrcweir 					{
621cdf0e10cSrcweir 						pDoc->StartChangeTracking();
622cdf0e10cSrcweir 						ScChangeViewSettings aChangeViewSet;
623cdf0e10cSrcweir 						aChangeViewSet.SetShowChanges(sal_True);
624cdf0e10cSrcweir 						pDoc->SetChangeViewSettings(aChangeViewSet);
625cdf0e10cSrcweir 					}
626cdf0e10cSrcweir 
627cdf0e10cSrcweir                     if ( bDo )
628cdf0e10cSrcweir                     {
629cdf0e10cSrcweir                         UpdateAcceptChangesDialog();
630cdf0e10cSrcweir 
631cdf0e10cSrcweir                         // Slots invalidieren
632cdf0e10cSrcweir                         if (pBindings)
633cdf0e10cSrcweir                             pBindings->InvalidateAll(sal_False);
634cdf0e10cSrcweir                         if ( !pItem )
635cdf0e10cSrcweir                             rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) );
636cdf0e10cSrcweir                         rReq.Done();
637cdf0e10cSrcweir                     }
638cdf0e10cSrcweir                     else
639cdf0e10cSrcweir                         rReq.Ignore();
640cdf0e10cSrcweir 				}
641cdf0e10cSrcweir 			}
642cdf0e10cSrcweir 			break;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir         case SID_CHG_PROTECT :
645cdf0e10cSrcweir             {
646cdf0e10cSrcweir                 Window* pParent = NULL;
647cdf0e10cSrcweir                 const SfxPoolItem* pParentItem;
648cdf0e10cSrcweir                 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
649cdf0e10cSrcweir                     pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
650cdf0e10cSrcweir                 if ( ExecuteChangeProtectionDialog( pParent ) )
651cdf0e10cSrcweir                 {
652cdf0e10cSrcweir 					rReq.Done();
653cdf0e10cSrcweir 					SetDocumentModified();
654cdf0e10cSrcweir 				}
655cdf0e10cSrcweir 				else
656cdf0e10cSrcweir 					rReq.Ignore();
657cdf0e10cSrcweir             }
658cdf0e10cSrcweir             break;
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 		case SID_DOCUMENT_MERGE:
661cdf0e10cSrcweir 		case SID_DOCUMENT_COMPARE:
662cdf0e10cSrcweir 			{
663cdf0e10cSrcweir                 sal_Bool bDo = sal_True;
664cdf0e10cSrcweir                 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
665cdf0e10cSrcweir                 if ( pChangeTrack && !pImpl->bIgnoreLostRedliningWarning )
666cdf0e10cSrcweir                 {
667cdf0e10cSrcweir                     if ( nSlot == SID_DOCUMENT_COMPARE )
668cdf0e10cSrcweir                     {   //! old changes trace will be lost
669cdf0e10cSrcweir                         WarningBox aBox( GetActiveDialogParent(),
670cdf0e10cSrcweir                             WinBits(WB_YES_NO | WB_DEF_NO),
671cdf0e10cSrcweir                             ScGlobal::GetRscString( STR_END_REDLINING ) );
672cdf0e10cSrcweir                         if( aBox.Execute() == RET_YES )
673cdf0e10cSrcweir                             bDo = ExecuteChangeProtectionDialog( NULL, sal_True );
674cdf0e10cSrcweir                         else
675cdf0e10cSrcweir                             bDo = sal_False;
676cdf0e10cSrcweir                     }
677cdf0e10cSrcweir                     else    // merge might reject some actions
678cdf0e10cSrcweir                         bDo = ExecuteChangeProtectionDialog( NULL, sal_True );
679cdf0e10cSrcweir                 }
680cdf0e10cSrcweir                 if ( !bDo )
681cdf0e10cSrcweir                 {
682cdf0e10cSrcweir                     rReq.Ignore();
683cdf0e10cSrcweir                     break;
684cdf0e10cSrcweir                 }
685cdf0e10cSrcweir 				SfxApplication* pApp = SFX_APP();
686cdf0e10cSrcweir 				const SfxPoolItem* pItem;
687cdf0e10cSrcweir 				SfxMedium* pMed = NULL;
688cdf0e10cSrcweir 				if ( pReqArgs &&
689cdf0e10cSrcweir 					 pReqArgs->GetItemState( SID_FILE_NAME, sal_True, &pItem ) == SFX_ITEM_SET &&
690cdf0e10cSrcweir 					 pItem->ISA(SfxStringItem) )
691cdf0e10cSrcweir 				{
692cdf0e10cSrcweir 					String aFileName = ((const SfxStringItem*)pItem)->GetValue();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 					String aFilterName;
695cdf0e10cSrcweir 					if ( pReqArgs->GetItemState( SID_FILTER_NAME, sal_True, &pItem ) == SFX_ITEM_SET &&
696cdf0e10cSrcweir 						 pItem->ISA(SfxStringItem) )
697cdf0e10cSrcweir 					{
698cdf0e10cSrcweir 						aFilterName = ((const SfxStringItem*)pItem)->GetValue();
699cdf0e10cSrcweir 					}
700cdf0e10cSrcweir 					String aOptions;
701cdf0e10cSrcweir 					if ( pReqArgs->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) == SFX_ITEM_SET &&
702cdf0e10cSrcweir 						 pItem->ISA(SfxStringItem) )
703cdf0e10cSrcweir 					{
704cdf0e10cSrcweir 						aOptions = ((const SfxStringItem*)pItem)->GetValue();
705cdf0e10cSrcweir 					}
706cdf0e10cSrcweir 					short nVersion = 0;
707cdf0e10cSrcweir 					if ( pReqArgs->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET &&
708cdf0e10cSrcweir 						 pItem->ISA(SfxInt16Item) )
709cdf0e10cSrcweir 					{
710cdf0e10cSrcweir 						nVersion = ((const SfxInt16Item*)pItem)->GetValue();
711cdf0e10cSrcweir 					}
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 					//	kein Filter angegeben -> Detection
714cdf0e10cSrcweir 					if ( !aFilterName.Len() )
715cdf0e10cSrcweir                         ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, sal_True, sal_False );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 					//	filter name from dialog contains application prefix,
718cdf0e10cSrcweir 					//	GetFilter needs name without the prefix.
719cdf0e10cSrcweir 					ScDocumentLoader::RemoveAppPrefix( aFilterName );
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 					const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
722cdf0e10cSrcweir 					SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() );
723cdf0e10cSrcweir 					if ( aOptions.Len() )
724cdf0e10cSrcweir 						pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
725cdf0e10cSrcweir 					if ( nVersion != 0 )
726cdf0e10cSrcweir 						pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
727cdf0e10cSrcweir 					pMed = new SfxMedium( aFileName, STREAM_STD_READ, sal_False, pFilter, pSet );
728cdf0e10cSrcweir 				}
729cdf0e10cSrcweir 				else
730cdf0e10cSrcweir 				{
731cdf0e10cSrcweir                     // start file dialog asynchronous
732cdf0e10cSrcweir                     pImpl->bIgnoreLostRedliningWarning = true;
733cdf0e10cSrcweir                     delete pImpl->pRequest;
734cdf0e10cSrcweir                     pImpl->pRequest = new SfxRequest( rReq );
735cdf0e10cSrcweir                     delete pImpl->pDocInserter;
736cdf0e10cSrcweir                     pImpl->pDocInserter = new ::sfx2::DocumentInserter(
737cdf0e10cSrcweir                         0, String::CreateFromAscii( ScDocShell::Factory().GetShortName() ), 0 );
738cdf0e10cSrcweir                     pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
739cdf0e10cSrcweir                     return ;
740cdf0e10cSrcweir                 }
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 				if ( pMed )		// nun wirklich ausfuehren...
743cdf0e10cSrcweir 				{
744cdf0e10cSrcweir 					SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
745cdf0e10cSrcweir 
746cdf0e10cSrcweir                     // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here
747cdf0e10cSrcweir 					ScDocShell* pOtherDocSh = new ScDocShell;
748cdf0e10cSrcweir                     SfxObjectShellLock aDocShTablesRef = pOtherDocSh;
749cdf0e10cSrcweir 					pOtherDocSh->DoLoad( pMed );
750cdf0e10cSrcweir 					sal_uLong nErr = pOtherDocSh->GetErrorCode();
751cdf0e10cSrcweir 					if (nErr)
752cdf0e10cSrcweir 						ErrorHandler::HandleError( nErr );			// auch Warnings
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 					if ( !pOtherDocSh->GetError() )					// nur Errors
755cdf0e10cSrcweir 					{
756cdf0e10cSrcweir 						sal_Bool bHadTrack = ( aDocument.GetChangeTrack() != NULL );
757cdf0e10cSrcweir                         sal_uLong nStart = 0;
758cdf0e10cSrcweir                         if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
759cdf0e10cSrcweir                         {
760cdf0e10cSrcweir                             nStart = pChangeTrack->GetActionMax() + 1;
761cdf0e10cSrcweir                         }
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 						if ( nSlot == SID_DOCUMENT_COMPARE )
764cdf0e10cSrcweir 							CompareDocument( *pOtherDocSh->GetDocument() );
765cdf0e10cSrcweir 						else
766cdf0e10cSrcweir 							MergeDocument( *pOtherDocSh->GetDocument() );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 						//	show "accept changes" dialog
769cdf0e10cSrcweir 						//! get view for this document!
770cdf0e10cSrcweir                         if ( !IsDocShared() )
771cdf0e10cSrcweir                         {
772cdf0e10cSrcweir                             SfxViewFrame* pViewFrm = SfxViewFrame::Current();
773cdf0e10cSrcweir                             if ( pViewFrm )
774cdf0e10cSrcweir                             {
775cdf0e10cSrcweir                                 pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId(), sal_True ); //@51669
776cdf0e10cSrcweir                             }
777cdf0e10cSrcweir                             if ( pBindings )
778cdf0e10cSrcweir                             {
779cdf0e10cSrcweir                                 pBindings->Invalidate( FID_CHG_ACCEPT );
780cdf0e10cSrcweir                             }
781cdf0e10cSrcweir                         }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 						rReq.SetReturnValue( SfxInt32Item( nSlot, 0 ) );		//! ???????
784cdf0e10cSrcweir 						rReq.Done();
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 						if (!bHadTrack)			//	neu eingeschaltet -> auch anzeigen
787cdf0e10cSrcweir 						{
788cdf0e10cSrcweir 							ScChangeViewSettings* pOldSet = aDocument.GetChangeViewSettings();
789cdf0e10cSrcweir 							if ( !pOldSet || !pOldSet->ShowChanges() )
790cdf0e10cSrcweir 							{
791cdf0e10cSrcweir 								ScChangeViewSettings aChangeViewSet;
792cdf0e10cSrcweir 								aChangeViewSet.SetShowChanges(sal_True);
793cdf0e10cSrcweir 								aDocument.SetChangeViewSettings(aChangeViewSet);
794cdf0e10cSrcweir 							}
795cdf0e10cSrcweir 						}
796cdf0e10cSrcweir                         else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack )
797cdf0e10cSrcweir                         {
798cdf0e10cSrcweir                             sal_uLong nEnd = pChangeTrack->GetActionMax();
799cdf0e10cSrcweir                             if ( nEnd >= nStart )
800cdf0e10cSrcweir                             {
801cdf0e10cSrcweir                                 // only show changes from merged document
802cdf0e10cSrcweir                                 ScChangeViewSettings aChangeViewSet;
803cdf0e10cSrcweir                                 aChangeViewSet.SetShowChanges( sal_True );
804cdf0e10cSrcweir                                 aChangeViewSet.SetShowAccepted( sal_True );
805cdf0e10cSrcweir                                 aChangeViewSet.SetHasActionRange( true );
806cdf0e10cSrcweir                                 aChangeViewSet.SetTheActionRange( nStart, nEnd );
807cdf0e10cSrcweir                                 aDocument.SetChangeViewSettings( aChangeViewSet );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir                                 // update view
810cdf0e10cSrcweir                                 PostPaintExtras();
811cdf0e10cSrcweir                                 PostPaintGridAll();
812cdf0e10cSrcweir                             }
813cdf0e10cSrcweir                         }
814cdf0e10cSrcweir 					}
815cdf0e10cSrcweir 					pOtherDocSh->DoClose();		// delete passiert mit der Ref
816cdf0e10cSrcweir 				}
817cdf0e10cSrcweir 			}
818cdf0e10cSrcweir 			break;
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 		case SID_DELETE_SCENARIO:
821cdf0e10cSrcweir 			if (pReqArgs)
822cdf0e10cSrcweir 			{
823cdf0e10cSrcweir 				const SfxPoolItem* pItem;
824cdf0e10cSrcweir 				if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
825cdf0e10cSrcweir 				{
826cdf0e10cSrcweir 					if ( pItem->ISA(SfxStringItem) )
827cdf0e10cSrcweir 					{
828cdf0e10cSrcweir 						String aName = ((const SfxStringItem*)pItem)->GetValue();
829cdf0e10cSrcweir 						SCTAB nTab;
830cdf0e10cSrcweir 						if (aDocument.GetTable( aName, nTab ))
831cdf0e10cSrcweir 						{
832cdf0e10cSrcweir 							//	DeleteTable von viewfunc nach docfunc verschieben!
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 							ScTabViewShell* pSh = GetBestViewShell();
835cdf0e10cSrcweir 							if ( pSh )
836cdf0e10cSrcweir 							{
837cdf0e10cSrcweir 								//!	SetTabNo in DeleteTable weglassen?
838cdf0e10cSrcweir 								SCTAB nDispTab = pSh->GetViewData()->GetTabNo();
839cdf0e10cSrcweir 								pSh->DeleteTable( nTab );
840cdf0e10cSrcweir 								pSh->SetTabNo(nDispTab);
841cdf0e10cSrcweir 								rReq.Done();
842cdf0e10cSrcweir 							}
843cdf0e10cSrcweir 						}
844cdf0e10cSrcweir 					}
845cdf0e10cSrcweir 				}
846cdf0e10cSrcweir 			}
847cdf0e10cSrcweir 			break;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 		case SID_EDIT_SCENARIO:
850cdf0e10cSrcweir 			{
851cdf0e10cSrcweir 				const SfxPoolItem* pItem;
852cdf0e10cSrcweir 				if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
853cdf0e10cSrcweir 				{
854cdf0e10cSrcweir 					if ( pItem->ISA(SfxStringItem) )
855cdf0e10cSrcweir 					{
856cdf0e10cSrcweir 						String aName = ((const SfxStringItem*)pItem)->GetValue();
857cdf0e10cSrcweir 						SCTAB nTab;
858cdf0e10cSrcweir 						if (aDocument.GetTable( aName, nTab ))
859cdf0e10cSrcweir 						{
860cdf0e10cSrcweir 							if (aDocument.IsScenario(nTab))
861cdf0e10cSrcweir 							{
862cdf0e10cSrcweir 								String aComment;
863cdf0e10cSrcweir 								Color aColor;
864cdf0e10cSrcweir 								sal_uInt16 nFlags;
865cdf0e10cSrcweir 								aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir                                 // Determine if the Sheet that the Scenario was created on
868cdf0e10cSrcweir                                 // is protected. But first we need to find that Sheet.
869cdf0e10cSrcweir                                 // Rewind back to the actual sheet.
870cdf0e10cSrcweir                                 SCTAB nActualTab = nTab;
871cdf0e10cSrcweir                                 do
872cdf0e10cSrcweir                                 {
873cdf0e10cSrcweir                                     nActualTab--;
874cdf0e10cSrcweir                                 }
875cdf0e10cSrcweir                                 while(aDocument.IsScenario(nActualTab));
876cdf0e10cSrcweir                                 sal_Bool bSheetProtected = aDocument.IsTabProtected(nActualTab);
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 								//!	anderen Titel am Dialog setzen
879cdf0e10cSrcweir //CHINA001								ScNewScenarioDlg* pNewDlg =
880cdf0e10cSrcweir //CHINA001								new ScNewScenarioDlg( GetActiveDialogParent(), aName, sal_True, bSheetProtected);
881cdf0e10cSrcweir 								ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
882cdf0e10cSrcweir 								DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 								AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( GetActiveDialogParent(), aName, RID_SCDLG_NEWSCENARIO, sal_True,bSheetProtected);
885cdf0e10cSrcweir 								DBG_ASSERT(pNewDlg, "Dialog create fail!");//CHINA001
886cdf0e10cSrcweir 								pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
887cdf0e10cSrcweir 								if ( pNewDlg->Execute() == RET_OK )
888cdf0e10cSrcweir 								{
889cdf0e10cSrcweir 									pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
890cdf0e10cSrcweir 									ModifyScenario( nTab, aName, aComment, aColor, nFlags );
891cdf0e10cSrcweir 									rReq.Done();
892cdf0e10cSrcweir 								}
893cdf0e10cSrcweir 								delete pNewDlg;
894cdf0e10cSrcweir 							}
895cdf0e10cSrcweir 						}
896cdf0e10cSrcweir 					}
897cdf0e10cSrcweir 				}
898cdf0e10cSrcweir 			}
899cdf0e10cSrcweir 			break;
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 		case SID_ATTR_YEAR2000 :
902cdf0e10cSrcweir 		{
903cdf0e10cSrcweir 			const SfxPoolItem* pItem;
904cdf0e10cSrcweir 			if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
905cdf0e10cSrcweir 			{
906cdf0e10cSrcweir 				if ( pItem->ISA(SfxUInt16Item) )
907cdf0e10cSrcweir 				{
908cdf0e10cSrcweir 					sal_uInt16 nY2k = ((SfxUInt16Item*)pItem)->GetValue();
909cdf0e10cSrcweir 					// immer an den DocOptions setzen, damit das auch fuer SO50
910cdf0e10cSrcweir 					// gespeichert wird (und alle Abfragen bisher auch darauf laufen).
911cdf0e10cSrcweir 					// SetDocOptions propagiert das an den NumberFormatter
912cdf0e10cSrcweir 					ScDocOptions aDocOpt( aDocument.GetDocOptions() );
913cdf0e10cSrcweir 					aDocOpt.SetYear2000( nY2k );
914cdf0e10cSrcweir 					aDocument.SetDocOptions( aDocOpt );
915cdf0e10cSrcweir 					// die FormShell soll es mitbekommen
916cdf0e10cSrcweir 					ScTabViewShell* pSh = GetBestViewShell();
917cdf0e10cSrcweir 					if ( pSh )
918cdf0e10cSrcweir 					{
919cdf0e10cSrcweir 						FmFormShell* pFSh = pSh->GetFormShell();
920cdf0e10cSrcweir 						if ( pFSh )
921cdf0e10cSrcweir 							pFSh->SetY2KState( nY2k );
922cdf0e10cSrcweir 					}
923cdf0e10cSrcweir 				}
924cdf0e10cSrcweir 			}
925cdf0e10cSrcweir 		}
926cdf0e10cSrcweir 		break;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir         case SID_SHARE_DOC:
929cdf0e10cSrcweir             {
930cdf0e10cSrcweir                 ScViewData* pViewData = GetViewData();
931cdf0e10cSrcweir                 if ( !pViewData )
932cdf0e10cSrcweir                 {
933cdf0e10cSrcweir                     rReq.Ignore();
934cdf0e10cSrcweir                     break;
935cdf0e10cSrcweir                 }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir                 ScShareDocumentDlg aDlg( GetActiveDialogParent(), pViewData );
938cdf0e10cSrcweir                 if ( aDlg.Execute() == RET_OK )
939cdf0e10cSrcweir                 {
940cdf0e10cSrcweir                     bool bSetShared = aDlg.IsShareDocumentChecked();
941cdf0e10cSrcweir                     if ( bSetShared != static_cast< bool >( IsDocShared() ) )
942cdf0e10cSrcweir                     {
943cdf0e10cSrcweir                         if ( bSetShared )
944cdf0e10cSrcweir                         {
945cdf0e10cSrcweir                             bool bContinue = true;
946cdf0e10cSrcweir                             if ( HasName() )
947cdf0e10cSrcweir                             {
948cdf0e10cSrcweir                                 QueryBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
949cdf0e10cSrcweir                                     ScGlobal::GetRscString( STR_DOC_WILLBESAVED ) );
950cdf0e10cSrcweir                                 if ( aBox.Execute() == RET_NO )
951cdf0e10cSrcweir                                 {
952cdf0e10cSrcweir                                     bContinue = false;
953cdf0e10cSrcweir                                 }
954cdf0e10cSrcweir                             }
955cdf0e10cSrcweir                             if ( bContinue )
956cdf0e10cSrcweir                             {
957cdf0e10cSrcweir                                 EnableSharedSettings( true );
958cdf0e10cSrcweir 
959cdf0e10cSrcweir                                 SC_MOD()->SetInSharedDocSaving( true );
960cdf0e10cSrcweir                                 if ( !SwitchToShared( sal_True, sal_True ) )
961cdf0e10cSrcweir                                 {
962cdf0e10cSrcweir                                     // TODO/LATER: what should be done in case the switch has failed?
963cdf0e10cSrcweir                                     // for example in case the user has cancelled the saveAs operation
964cdf0e10cSrcweir                                 }
965cdf0e10cSrcweir 
966cdf0e10cSrcweir                                 SC_MOD()->SetInSharedDocSaving( false );
967cdf0e10cSrcweir 
968cdf0e10cSrcweir                                 InvalidateName();
969cdf0e10cSrcweir                                 GetUndoManager()->Clear();
970cdf0e10cSrcweir 
971cdf0e10cSrcweir                                 ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
972cdf0e10cSrcweir                                 if ( pTabView )
973cdf0e10cSrcweir                                 {
974cdf0e10cSrcweir                                     pTabView->UpdateLayerLocks();
975cdf0e10cSrcweir                                 }
976cdf0e10cSrcweir                             }
977cdf0e10cSrcweir                         }
978cdf0e10cSrcweir                         else
979cdf0e10cSrcweir                         {
980cdf0e10cSrcweir                             uno::Reference< frame::XModel > xModel;
981cdf0e10cSrcweir                             try
982cdf0e10cSrcweir                             {
983cdf0e10cSrcweir                                 // load shared file
984cdf0e10cSrcweir                                 xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW );
985cdf0e10cSrcweir                                 uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
986cdf0e10cSrcweir 
987cdf0e10cSrcweir                                 // check if shared flag is set in shared file
988cdf0e10cSrcweir                                 bool bShared = false;
989cdf0e10cSrcweir                                 ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
990cdf0e10cSrcweir                                 if ( pDocObj )
991cdf0e10cSrcweir                                 {
992cdf0e10cSrcweir                     		        ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() );
993cdf0e10cSrcweir                                     if ( pDocShell )
994cdf0e10cSrcweir                                     {
995cdf0e10cSrcweir                                         bShared = pDocShell->HasSharedXMLFlagSet();
996cdf0e10cSrcweir                                     }
997cdf0e10cSrcweir                                 }
998cdf0e10cSrcweir 
999cdf0e10cSrcweir                                 // #i87870# check if shared status was disabled and enabled again
1000cdf0e10cSrcweir                                 bool bOwnEntry = false;
1001cdf0e10cSrcweir                                 try
1002cdf0e10cSrcweir                                 {
1003cdf0e10cSrcweir                                     ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
1004cdf0e10cSrcweir                                     bOwnEntry = aControlFile.HasOwnEntry();
1005cdf0e10cSrcweir                                 }
1006cdf0e10cSrcweir                                 catch ( uno::Exception& )
1007cdf0e10cSrcweir                                 {
1008cdf0e10cSrcweir                                 }
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir                                 if ( bShared && bOwnEntry )
1011cdf0e10cSrcweir                                 {
1012cdf0e10cSrcweir                                     uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
1013cdf0e10cSrcweir                                     if ( xStorable->isReadonly() )
1014cdf0e10cSrcweir                                     {
1015cdf0e10cSrcweir                                         xCloseable->close( sal_True );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir                                         String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) );
1018cdf0e10cSrcweir                                         try
1019cdf0e10cSrcweir                                         {
1020cdf0e10cSrcweir                                             ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
1021cdf0e10cSrcweir                                             uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData();
1022cdf0e10cSrcweir                                             if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
1023cdf0e10cSrcweir                                             {
1024cdf0e10cSrcweir                                                 if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() > 0 )
1025cdf0e10cSrcweir                                                 {
1026cdf0e10cSrcweir                                                     aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
1027cdf0e10cSrcweir                                                 }
1028cdf0e10cSrcweir                                                 else if ( aData[LOCKFILE_SYSUSERNAME_ID].getLength() > 0 )
1029cdf0e10cSrcweir                                                 {
1030cdf0e10cSrcweir                                                     aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
1031cdf0e10cSrcweir                                                 }
1032cdf0e10cSrcweir                                             }
1033cdf0e10cSrcweir                                         }
1034cdf0e10cSrcweir                                         catch ( uno::Exception& )
1035cdf0e10cSrcweir                                         {
1036cdf0e10cSrcweir                                         }
1037cdf0e10cSrcweir                                         String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_TRY_LATER ) );
1038cdf0e10cSrcweir                                         aMessage.SearchAndReplaceAscii( "%1", aUserName );
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir                                         WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ), aMessage );
1041cdf0e10cSrcweir                                         aBox.Execute();
1042cdf0e10cSrcweir                                     }
1043cdf0e10cSrcweir                                     else
1044cdf0e10cSrcweir                                     {
1045cdf0e10cSrcweir                                         WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1046cdf0e10cSrcweir                                             ScGlobal::GetRscString( STR_DOC_DISABLESHARED ) );
1047cdf0e10cSrcweir                                         if ( aBox.Execute() == RET_YES )
1048cdf0e10cSrcweir                                         {
1049cdf0e10cSrcweir                                             xCloseable->close( sal_True );
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir                                             if ( !SwitchToShared( sal_False, sal_True ) )
1052cdf0e10cSrcweir                                             {
1053cdf0e10cSrcweir                                                 // TODO/LATER: what should be done in case the switch has failed?
1054cdf0e10cSrcweir                                                 // for example in case the user has cancelled the saveAs operation
1055cdf0e10cSrcweir                                             }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir                                             EnableSharedSettings( false );
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir                                             if ( pBindings )
1060cdf0e10cSrcweir                                             {
1061cdf0e10cSrcweir                                                 pBindings->ExecuteSynchron( SID_SAVEDOC );
1062cdf0e10cSrcweir                                             }
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir                                             ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1065cdf0e10cSrcweir                                             if ( pTabView )
1066cdf0e10cSrcweir                                             {
1067cdf0e10cSrcweir                                                 pTabView->UpdateLayerLocks();
1068cdf0e10cSrcweir                                             }
1069cdf0e10cSrcweir                                         }
1070cdf0e10cSrcweir                                         else
1071cdf0e10cSrcweir                                         {
1072cdf0e10cSrcweir                                             xCloseable->close( sal_True );
1073cdf0e10cSrcweir                                         }
1074cdf0e10cSrcweir                                     }
1075cdf0e10cSrcweir                                 }
1076cdf0e10cSrcweir                                 else
1077cdf0e10cSrcweir                                 {
1078cdf0e10cSrcweir                                     xCloseable->close( sal_True );
1079cdf0e10cSrcweir                                     WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
1080cdf0e10cSrcweir                                         ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) );
1081cdf0e10cSrcweir                                     aBox.Execute();
1082cdf0e10cSrcweir                                 }
1083cdf0e10cSrcweir                             }
1084cdf0e10cSrcweir                             catch ( uno::Exception& )
1085cdf0e10cSrcweir                             {
1086cdf0e10cSrcweir                                 DBG_ERROR( "SID_SHARE_DOC: caught exception\n" );
1087cdf0e10cSrcweir                                 SC_MOD()->SetInSharedDocSaving( false );
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir                                 try
1090cdf0e10cSrcweir                                 {
1091cdf0e10cSrcweir                                     uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
1092cdf0e10cSrcweir                                     xClose->close( sal_True );
1093cdf0e10cSrcweir                                 }
1094cdf0e10cSrcweir                                 catch ( uno::Exception& )
1095cdf0e10cSrcweir                                 {
1096cdf0e10cSrcweir                                 }
1097cdf0e10cSrcweir                             }
1098cdf0e10cSrcweir                         }
1099cdf0e10cSrcweir                     }
1100cdf0e10cSrcweir                 }
1101cdf0e10cSrcweir                 rReq.Done();
1102cdf0e10cSrcweir             }
1103cdf0e10cSrcweir             break;
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir 		default:
1106cdf0e10cSrcweir 		{
1107cdf0e10cSrcweir 			// kleiner (?) Hack -> forward der Slots an TabViewShell
1108cdf0e10cSrcweir 			ScTabViewShell* pSh = GetBestViewShell();
1109cdf0e10cSrcweir 			if ( pSh )
1110cdf0e10cSrcweir 				pSh->Execute( rReq );
1111cdf0e10cSrcweir 			else
1112cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
1113cdf0e10cSrcweir 		}
1114cdf0e10cSrcweir 	}
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir //------------------------------------------------------------------
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir void UpdateAcceptChangesDialog()
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir     //  update "accept changes" dialog
1123cdf0e10cSrcweir     //! notify all views
1124cdf0e10cSrcweir     SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1125cdf0e10cSrcweir     if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1126cdf0e10cSrcweir     {
1127cdf0e10cSrcweir         SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1128cdf0e10cSrcweir         if ( pChild )
1129cdf0e10cSrcweir             ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
1130cdf0e10cSrcweir     }
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir //------------------------------------------------------------------
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir sal_Bool ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected )
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir     sal_Bool bDone = sal_False;
1138cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
1139cdf0e10cSrcweir     if ( pChangeTrack )
1140cdf0e10cSrcweir     {
1141cdf0e10cSrcweir         sal_Bool bProtected = pChangeTrack->IsProtected();
1142cdf0e10cSrcweir         if ( bJustQueryIfProtected && !bProtected )
1143cdf0e10cSrcweir             return sal_True;
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir         String aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1146cdf0e10cSrcweir         String aText( ScResId( SCSTR_PASSWORD ) );
1147cdf0e10cSrcweir         String aPassword;
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir         SfxPasswordDialog* pDlg = new SfxPasswordDialog(
1150cdf0e10cSrcweir 			_pParent ? _pParent : GetActiveDialogParent(), &aText );
1151cdf0e10cSrcweir         pDlg->SetText( aTitle );
1152cdf0e10cSrcweir         pDlg->SetMinLen( 1 );
1153cdf0e10cSrcweir         pDlg->SetHelpId( GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand() );
1154cdf0e10cSrcweir         pDlg->SetEditHelpId( HID_CHG_PROTECT );
1155cdf0e10cSrcweir         if ( !bProtected )
1156cdf0e10cSrcweir             pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1157cdf0e10cSrcweir         if ( pDlg->Execute() == RET_OK )
1158cdf0e10cSrcweir             aPassword = pDlg->GetPassword();
1159cdf0e10cSrcweir         delete pDlg;
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir         if ( aPassword.Len() )
1162cdf0e10cSrcweir         {
1163cdf0e10cSrcweir             if ( bProtected )
1164cdf0e10cSrcweir             {
1165cdf0e10cSrcweir                 if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1166cdf0e10cSrcweir                 {
1167cdf0e10cSrcweir                     if ( bJustQueryIfProtected )
1168cdf0e10cSrcweir                         bDone = sal_True;
1169cdf0e10cSrcweir                     else
1170cdf0e10cSrcweir                         pChangeTrack->SetProtection(
1171cdf0e10cSrcweir                             com::sun::star::uno::Sequence< sal_Int8 > (0) );
1172cdf0e10cSrcweir                 }
1173cdf0e10cSrcweir                 else
1174cdf0e10cSrcweir                 {
1175cdf0e10cSrcweir                     InfoBox aBox( GetActiveDialogParent(),
1176cdf0e10cSrcweir                         String( ScResId( SCSTR_WRONGPASSWORD ) ) );
1177cdf0e10cSrcweir                     aBox.Execute();
1178cdf0e10cSrcweir                 }
1179cdf0e10cSrcweir             }
1180cdf0e10cSrcweir             else
1181cdf0e10cSrcweir             {
1182cdf0e10cSrcweir                 com::sun::star::uno::Sequence< sal_Int8 > aPass;
1183cdf0e10cSrcweir                 SvPasswordHelper::GetHashPassword( aPass, aPassword );
1184cdf0e10cSrcweir                 pChangeTrack->SetProtection( aPass );
1185cdf0e10cSrcweir             }
1186cdf0e10cSrcweir             if ( bProtected != pChangeTrack->IsProtected() )
1187cdf0e10cSrcweir             {
1188cdf0e10cSrcweir                 UpdateAcceptChangesDialog();
1189cdf0e10cSrcweir                 bDone = sal_True;
1190cdf0e10cSrcweir             }
1191cdf0e10cSrcweir         }
1192cdf0e10cSrcweir     }
1193cdf0e10cSrcweir     else if ( bJustQueryIfProtected )
1194cdf0e10cSrcweir         bDone = sal_True;
1195cdf0e10cSrcweir     return bDone;
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir //------------------------------------------------------------------
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir void ScDocShell::DoRecalc( sal_Bool bApi )
1202cdf0e10cSrcweir {
1203cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
1204cdf0e10cSrcweir 	ScTabViewShell* pSh = GetBestViewShell();
1205cdf0e10cSrcweir 	if ( pSh )
1206cdf0e10cSrcweir 	{
1207cdf0e10cSrcweir 		ScInputHandler* pHdl = SC_MOD()->GetInputHdl(pSh);
1208cdf0e10cSrcweir 		if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1209cdf0e10cSrcweir 		{
1210cdf0e10cSrcweir 			pHdl->FormulaPreview();		// Teilergebnis als QuickHelp
1211cdf0e10cSrcweir 			bDone = sal_True;
1212cdf0e10cSrcweir 		}
1213cdf0e10cSrcweir 		else
1214cdf0e10cSrcweir 		{
1215cdf0e10cSrcweir 			pSh->UpdateInputLine();		// InputEnterHandler
1216cdf0e10cSrcweir 			pSh->UpdateInputHandler();
1217cdf0e10cSrcweir 		}
1218cdf0e10cSrcweir 	}
1219cdf0e10cSrcweir 	if (!bDone)							// sonst Dokument neu berechnen
1220cdf0e10cSrcweir 	{
1221cdf0e10cSrcweir 		WaitObject aWaitObj( GetActiveDialogParent() );
1222cdf0e10cSrcweir 		aDocument.CalcFormulaTree();
1223cdf0e10cSrcweir 		if ( pSh )
1224cdf0e10cSrcweir 			pSh->UpdateCharts(sal_True);
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir         aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir 		//	#47939# Wenn es Charts gibt, dann alles painten, damit nicht
1229cdf0e10cSrcweir 		//	PostDataChanged und die Charts nacheinander kommen und Teile
1230cdf0e10cSrcweir 		//	doppelt gepainted werden.
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir 		ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection();
1233cdf0e10cSrcweir 		if ( pCharts && pCharts->GetCount() )
1234cdf0e10cSrcweir 			PostPaintGridAll();
1235cdf0e10cSrcweir 		else
1236cdf0e10cSrcweir 			PostDataChanged();
1237cdf0e10cSrcweir 	}
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir void ScDocShell::DoHardRecalc( sal_Bool /* bApi */ )
1241cdf0e10cSrcweir {
1242cdf0e10cSrcweir 	WaitObject aWaitObj( GetActiveDialogParent() );
1243cdf0e10cSrcweir 	ScTabViewShell* pSh = GetBestViewShell();
1244cdf0e10cSrcweir 	if ( pSh )
1245cdf0e10cSrcweir 	{
1246cdf0e10cSrcweir 		pSh->UpdateInputLine();		// InputEnterHandler
1247cdf0e10cSrcweir 		pSh->UpdateInputHandler();
1248cdf0e10cSrcweir 	}
1249cdf0e10cSrcweir 	aDocument.CalcAll();
1250cdf0e10cSrcweir 	GetDocFunc().DetectiveRefresh();	// erzeugt eigenes Undo
1251cdf0e10cSrcweir 	if ( pSh )
1252cdf0e10cSrcweir 		pSh->UpdateCharts(sal_True);
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir     // set notification flags for "calculate" event (used in SFX_HINT_DATACHANGED broadcast)
1255cdf0e10cSrcweir     // (might check for the presence of any formulas on each sheet)
1256cdf0e10cSrcweir     SCTAB nTabCount = aDocument.GetTableCount();
1257cdf0e10cSrcweir     SCTAB nTab;
1258cdf0e10cSrcweir     if (aDocument.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true )) // search also for VBA hendler
1259cdf0e10cSrcweir         for (nTab=0; nTab<nTabCount; nTab++)
1260cdf0e10cSrcweir             aDocument.SetCalcNotification(nTab);
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally
1263cdf0e10cSrcweir     // in addition to SFX_HINT_DATACHANGED.
1264cdf0e10cSrcweir     aDocument.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL ) );
1265cdf0e10cSrcweir     aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir     // use hard recalc also to disable stream-copying of all sheets
1268cdf0e10cSrcweir     // (somewhat consistent with charts)
1269cdf0e10cSrcweir     for (nTab=0; nTab<nTabCount; nTab++)
1270cdf0e10cSrcweir         if (aDocument.IsStreamValid(nTab))
1271cdf0e10cSrcweir             aDocument.SetStreamValid(nTab, sal_False);
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir 	PostPaintGridAll();
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir //------------------------------------------------------------------
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir void ScDocShell::DoAutoStyle( const ScRange& rRange, const String& rStyle )
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir 	ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1281cdf0e10cSrcweir 	ScStyleSheet* pStyleSheet =
1282cdf0e10cSrcweir 		pStylePool->FindCaseIns( rStyle, SFX_STYLE_FAMILY_PARA );
1283cdf0e10cSrcweir 	if (!pStyleSheet)
1284cdf0e10cSrcweir 		pStyleSheet = (ScStyleSheet*)
1285cdf0e10cSrcweir 			pStylePool->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA );
1286cdf0e10cSrcweir 	if (pStyleSheet)
1287cdf0e10cSrcweir 	{
1288cdf0e10cSrcweir 		DBG_ASSERT(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1289cdf0e10cSrcweir 						"DoAutoStyle mit mehreren Tabellen");
1290cdf0e10cSrcweir 		SCTAB nTab = rRange.aStart.Tab();
1291cdf0e10cSrcweir 		SCCOL nStartCol = rRange.aStart.Col();
1292cdf0e10cSrcweir 		SCROW nStartRow = rRange.aStart.Row();
1293cdf0e10cSrcweir 		SCCOL nEndCol = rRange.aEnd.Col();
1294cdf0e10cSrcweir 		SCROW nEndRow = rRange.aEnd.Row();
1295cdf0e10cSrcweir 		aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1296cdf0e10cSrcweir 		aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1297cdf0e10cSrcweir 		PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PAINT_GRID );
1298cdf0e10cSrcweir 	}
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir //------------------------------------------------------------------
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
1304cdf0e10cSrcweir {
1305cdf0e10cSrcweir 	sal_uInt16 nId = rHint.GetHint();
1306cdf0e10cSrcweir 	const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1307cdf0e10cSrcweir 	if (!pStyle)
1308cdf0e10cSrcweir 		return;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 	if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PAGE )
1311cdf0e10cSrcweir 	{
1312cdf0e10cSrcweir 		if ( nId == SFX_STYLESHEET_MODIFIED )
1313cdf0e10cSrcweir 		{
1314cdf0e10cSrcweir 			ScDocShellModificator aModificator( *this );
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 			String aNewName = pStyle->GetName();
1317cdf0e10cSrcweir 			String aOldName = aNewName;
1318cdf0e10cSrcweir 			sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended);		// Name geaendert?
1319cdf0e10cSrcweir 			if (bExtended)
1320cdf0e10cSrcweir 				aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 			if ( aNewName != aOldName )
1323cdf0e10cSrcweir 				aDocument.RenamePageStyleInUse( aOldName, aNewName );
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir 			SCTAB nTabCount = aDocument.GetTableCount();
1326cdf0e10cSrcweir 			for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1327cdf0e10cSrcweir 				if (aDocument.GetPageStyle(nTab) == aNewName)	// schon auf neu angepasst
1328cdf0e10cSrcweir 				{
1329cdf0e10cSrcweir 					aDocument.PageStyleModified( nTab, aNewName );
1330cdf0e10cSrcweir 					ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1331cdf0e10cSrcweir 					aPrintFunc.UpdatePages();
1332cdf0e10cSrcweir 				}
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir 			aModificator.SetDocumentModified();
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir 			if (bExtended)
1337cdf0e10cSrcweir 			{
1338cdf0e10cSrcweir 				SfxBindings* pBindings = GetViewBindings();
1339cdf0e10cSrcweir 				if (pBindings)
1340cdf0e10cSrcweir 				{
1341cdf0e10cSrcweir 					pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1342cdf0e10cSrcweir 					pBindings->Invalidate( SID_STYLE_FAMILY4 );
1343cdf0e10cSrcweir 					pBindings->Invalidate( FID_RESET_PRINTZOOM );
1344cdf0e10cSrcweir 					pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1345cdf0e10cSrcweir 					pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1346cdf0e10cSrcweir 				}
1347cdf0e10cSrcweir 			}
1348cdf0e10cSrcweir 		}
1349cdf0e10cSrcweir 	}
1350cdf0e10cSrcweir     else if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PARA )
1351cdf0e10cSrcweir     {
1352cdf0e10cSrcweir         if ( nId == SFX_STYLESHEET_MODIFIED)
1353cdf0e10cSrcweir         {
1354cdf0e10cSrcweir             String aNewName = pStyle->GetName();
1355cdf0e10cSrcweir             String aOldName = aNewName;
1356cdf0e10cSrcweir             sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended);
1357cdf0e10cSrcweir             if (bExtended)
1358cdf0e10cSrcweir                 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1359cdf0e10cSrcweir             if ( aNewName != aOldName )
1360cdf0e10cSrcweir             {
1361cdf0e10cSrcweir                 ScConditionalFormatList* pList = aDocument.GetCondFormList();
1362cdf0e10cSrcweir                 if (pList)
1363cdf0e10cSrcweir                     pList->RenameCellStyle( aOldName,aNewName );
1364cdf0e10cSrcweir             }
1365cdf0e10cSrcweir         }
1366cdf0e10cSrcweir     }
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir 	//	alles andere geht ueber Slots...
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir //	wie in printfun.cxx
1372cdf0e10cSrcweir #define ZOOM_MIN	10
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
1375cdf0e10cSrcweir {
1376cdf0e10cSrcweir 	sal_Bool bUndo(aDocument.IsUndoEnabled());
1377cdf0e10cSrcweir 	String aStyleName = aDocument.GetPageStyle( nTab );
1378cdf0e10cSrcweir 	ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1379cdf0e10cSrcweir 	SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1380cdf0e10cSrcweir 	DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1381cdf0e10cSrcweir 	if ( pStyleSheet )
1382cdf0e10cSrcweir 	{
1383cdf0e10cSrcweir 		ScDocShellModificator aModificator( *this );
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir 		SfxItemSet& rSet = pStyleSheet->GetItemSet();
1386cdf0e10cSrcweir 		if (bUndo)
1387cdf0e10cSrcweir 		{
1388cdf0e10cSrcweir 			sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1389cdf0e10cSrcweir 			sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1390cdf0e10cSrcweir 			GetUndoManager()->AddUndoAction( new ScUndoPrintZoom(
1391cdf0e10cSrcweir 							this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1392cdf0e10cSrcweir 		}
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir 		rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1395cdf0e10cSrcweir 		rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir 		ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1398cdf0e10cSrcweir 		aPrintFunc.UpdatePages();
1399cdf0e10cSrcweir 		aModificator.SetDocumentModified();
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir 		SfxBindings* pBindings = GetViewBindings();
1402cdf0e10cSrcweir 		if (pBindings)
1403cdf0e10cSrcweir 			pBindings->Invalidate( FID_RESET_PRINTZOOM );
1404cdf0e10cSrcweir 	}
1405cdf0e10cSrcweir }
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir sal_Bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir 	sal_Bool bChange = sal_False;
1410cdf0e10cSrcweir 	SCTAB nTab = rRange.aStart.Tab();
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir 	String aStyleName = aDocument.GetPageStyle( nTab );
1413cdf0e10cSrcweir 	ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1414cdf0e10cSrcweir 	SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1415cdf0e10cSrcweir 	DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1416cdf0e10cSrcweir 	if ( pStyleSheet )
1417cdf0e10cSrcweir 	{
1418cdf0e10cSrcweir 		SfxItemSet& rSet = pStyleSheet->GetItemSet();
1419cdf0e10cSrcweir 		sal_Bool bHeaders = ((const SfxBoolItem&)rSet.Get(ATTR_PAGE_HEADERS)).GetValue();
1420cdf0e10cSrcweir 		sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1421cdf0e10cSrcweir 		sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1422cdf0e10cSrcweir 		const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab );
1423cdf0e10cSrcweir 		const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab );
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir 		//	benoetigte Skalierung fuer Selektion ausrechnen
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir 		sal_uInt16 nNewScale = nOldScale;
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 		long nBlkTwipsX = 0;
1430cdf0e10cSrcweir 		if (bHeaders)
1431cdf0e10cSrcweir 			nBlkTwipsX += (long) PRINT_HEADER_WIDTH;
1432cdf0e10cSrcweir 		SCCOL nStartCol = rRange.aStart.Col();
1433cdf0e10cSrcweir 		SCCOL nEndCol = rRange.aEnd.Col();
1434cdf0e10cSrcweir 		if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1435cdf0e10cSrcweir 		{
1436cdf0e10cSrcweir 			for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1437cdf0e10cSrcweir 				nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1438cdf0e10cSrcweir 			if ( nStartCol <= pRepeatCol->aEnd.Col() )
1439cdf0e10cSrcweir 				nStartCol = pRepeatCol->aEnd.Col() + 1;
1440cdf0e10cSrcweir 		}
1441cdf0e10cSrcweir         // legacy compilers' own scope for i
1442cdf0e10cSrcweir         {
1443cdf0e10cSrcweir             for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1444cdf0e10cSrcweir                 nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1445cdf0e10cSrcweir         }
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 		long nBlkTwipsY = 0;
1448cdf0e10cSrcweir 		if (bHeaders)
1449cdf0e10cSrcweir 			nBlkTwipsY += (long) PRINT_HEADER_HEIGHT;
1450cdf0e10cSrcweir 		SCROW nStartRow = rRange.aStart.Row();
1451cdf0e10cSrcweir 		SCROW nEndRow = rRange.aEnd.Row();
1452cdf0e10cSrcweir 		if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1453cdf0e10cSrcweir 		{
1454cdf0e10cSrcweir             nBlkTwipsY += aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
1455cdf0e10cSrcweir                     pRepeatRow->aEnd.Row(), nTab );
1456cdf0e10cSrcweir 			if ( nStartRow <= pRepeatRow->aEnd.Row() )
1457cdf0e10cSrcweir 				nStartRow = pRepeatRow->aEnd.Row() + 1;
1458cdf0e10cSrcweir 		}
1459cdf0e10cSrcweir         nBlkTwipsY += aDocument.GetRowHeight( nStartRow, nEndRow, nTab );
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir 		Size aPhysPage;
1462cdf0e10cSrcweir 		long nHdr, nFtr;
1463cdf0e10cSrcweir 		ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1464cdf0e10cSrcweir 		aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1465cdf0e10cSrcweir 		nBlkTwipsY += nHdr + nFtr;
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 		if ( nBlkTwipsX == 0 )		// #100639# hidden columns/rows may lead to 0
1468cdf0e10cSrcweir 			nBlkTwipsX = 1;
1469cdf0e10cSrcweir 		if ( nBlkTwipsY == 0 )
1470cdf0e10cSrcweir 			nBlkTwipsY = 1;
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir 		long nNeeded = Min( aPhysPage.Width()  * 100 / nBlkTwipsX,
1473cdf0e10cSrcweir 							aPhysPage.Height() * 100 / nBlkTwipsY );
1474cdf0e10cSrcweir 		if ( nNeeded < ZOOM_MIN )
1475cdf0e10cSrcweir 			nNeeded = ZOOM_MIN;			// Begrenzung
1476cdf0e10cSrcweir 		if ( nNeeded < (long) nNewScale )
1477cdf0e10cSrcweir 			nNewScale = (sal_uInt16) nNeeded;
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 		bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1480cdf0e10cSrcweir 		if ( bChange )
1481cdf0e10cSrcweir 			SetPrintZoom( nTab, nNewScale, 0 );
1482cdf0e10cSrcweir 	}
1483cdf0e10cSrcweir 	return bChange;
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir void ScDocShell::PageStyleModified( const String& rStyleName, sal_Bool bApi )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir 	ScDocShellModificator aModificator( *this );
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir 	sal_Bool bWarn = sal_False;
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir 	SCTAB nTabCount = aDocument.GetTableCount();
1493cdf0e10cSrcweir 	SCTAB nUseTab = MAXTAB+1;
1494cdf0e10cSrcweir 	for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1495cdf0e10cSrcweir 		if ( aDocument.GetPageStyle(nTab) == rStyleName &&
1496cdf0e10cSrcweir 				( !bApi || aDocument.GetPageSize(nTab).Width() ) )
1497cdf0e10cSrcweir 			nUseTab = nTab;
1498cdf0e10cSrcweir 								// bei bApi nur, wenn Umbrueche schon angezeigt
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir 	if (ValidTab(nUseTab))		// nicht verwendet -> nichts zu tun
1501cdf0e10cSrcweir 	{
1502cdf0e10cSrcweir 		ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab );	//! ohne CountPages auskommen
1503cdf0e10cSrcweir 		if (!aPrintFunc.UpdatePages())							//	setzt Umbrueche auf allen Tabs
1504cdf0e10cSrcweir 			bWarn = sal_True;
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir 		if (bWarn && !bApi)
1507cdf0e10cSrcweir 		{
1508cdf0e10cSrcweir 			ScWaitCursorOff aWaitOff( GetActiveDialogParent() );
1509cdf0e10cSrcweir 			InfoBox aInfoBox(GetActiveDialogParent(),
1510cdf0e10cSrcweir 							 ScGlobal::GetRscString(STR_PRINT_INVALID_AREA));
1511cdf0e10cSrcweir 			aInfoBox.Execute();
1512cdf0e10cSrcweir 		}
1513cdf0e10cSrcweir 	}
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir 	aModificator.SetDocumentModified();
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir 	SfxBindings* pBindings = GetViewBindings();
1518cdf0e10cSrcweir 	if (pBindings)
1519cdf0e10cSrcweir 	{
1520cdf0e10cSrcweir 		pBindings->Invalidate( FID_RESET_PRINTZOOM );
1521cdf0e10cSrcweir 		pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1522cdf0e10cSrcweir 		pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1523cdf0e10cSrcweir 	}
1524cdf0e10cSrcweir }
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
1527cdf0e10cSrcweir 								   SfxRequest&   rReq,
1528cdf0e10cSrcweir 								   SCTAB		 nCurTab )
1529cdf0e10cSrcweir {
1530cdf0e10cSrcweir 	const SfxItemSet* pReqArgs = rReq.GetArgs();
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir 	switch ( rReq.GetSlot() )
1533cdf0e10cSrcweir 	{
1534cdf0e10cSrcweir 		case SID_STATUS_PAGESTYLE:	// Click auf StatusBar-Control
1535cdf0e10cSrcweir 		case SID_FORMATPAGE:
1536cdf0e10cSrcweir 			{
1537cdf0e10cSrcweir 				if ( pReqArgs != NULL )
1538cdf0e10cSrcweir 				{
1539cdf0e10cSrcweir 				}
1540cdf0e10cSrcweir 				else if ( pReqArgs == NULL )
1541cdf0e10cSrcweir 				{
1542cdf0e10cSrcweir 					sal_Bool bUndo(aDocument.IsUndoEnabled());
1543cdf0e10cSrcweir 					String aOldName = aDocument.GetPageStyle( nCurTab );
1544cdf0e10cSrcweir 					ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1545cdf0e10cSrcweir 					SfxStyleSheetBase* pStyleSheet
1546cdf0e10cSrcweir 						= pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir 					DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir 					if ( pStyleSheet )
1551cdf0e10cSrcweir 					{
1552cdf0e10cSrcweir 						ScStyleSaveData aOldData;
1553cdf0e10cSrcweir 						if (bUndo)
1554cdf0e10cSrcweir 							aOldData.InitFromStyle( pStyleSheet );
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir 						SfxItemSet&		rStyleSet = pStyleSheet->GetItemSet();
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir //CHINA001						ScStyleDlg* pDlg = new ScStyleDlg( GetActiveDialogParent(),
1559cdf0e10cSrcweir //CHINA001						*pStyleSheet,
1560cdf0e10cSrcweir //CHINA001						RID_SCDLG_STYLES_PAGE );
1561cdf0e10cSrcweir //CHINA001
1562cdf0e10cSrcweir 						ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1563cdf0e10cSrcweir 						DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir 						SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE );
1566cdf0e10cSrcweir 						DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir 						if ( pDlg->Execute() == RET_OK )
1569cdf0e10cSrcweir 						{
1570cdf0e10cSrcweir 							const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir 							WaitObject aWait( GetActiveDialogParent() );
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir 							String aNewName = pStyleSheet->GetName();
1575cdf0e10cSrcweir 							if ( aNewName != aOldName &&
1576cdf0e10cSrcweir 								aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1577cdf0e10cSrcweir 							{
1578cdf0e10cSrcweir 								SfxBindings* pBindings = GetViewBindings();
1579cdf0e10cSrcweir 								if (pBindings)
1580cdf0e10cSrcweir 								{
1581cdf0e10cSrcweir 									pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1582cdf0e10cSrcweir 									pBindings->Invalidate( FID_RESET_PRINTZOOM );
1583cdf0e10cSrcweir 								}
1584cdf0e10cSrcweir 							}
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 							if ( pOutSet )
1587cdf0e10cSrcweir 								aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir 							// merken fuer GetState():
1590cdf0e10cSrcweir 							GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1591cdf0e10cSrcweir 							rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 							ScStyleSaveData aNewData;
1594cdf0e10cSrcweir 							aNewData.InitFromStyle( pStyleSheet );
1595cdf0e10cSrcweir 							if (bUndo)
1596cdf0e10cSrcweir 							{
1597cdf0e10cSrcweir 								GetUndoManager()->AddUndoAction(
1598cdf0e10cSrcweir 										new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE,
1599cdf0e10cSrcweir 													aOldData, aNewData ) );
1600cdf0e10cSrcweir 							}
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 							PageStyleModified( aNewName, sal_False );
1603cdf0e10cSrcweir 							rReq.Done();
1604cdf0e10cSrcweir 						}
1605cdf0e10cSrcweir 						delete pDlg;
1606cdf0e10cSrcweir 
1607cdf0e10cSrcweir 						rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY );
1608cdf0e10cSrcweir 					}
1609cdf0e10cSrcweir 				}
1610cdf0e10cSrcweir 			}
1611cdf0e10cSrcweir 			break;
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir 		case SID_HFEDIT:
1614cdf0e10cSrcweir 			{
1615cdf0e10cSrcweir 				if ( pReqArgs != NULL )
1616cdf0e10cSrcweir 				{
1617cdf0e10cSrcweir 				}
1618cdf0e10cSrcweir 				else if ( pReqArgs == NULL )
1619cdf0e10cSrcweir 				{
1620cdf0e10cSrcweir 					String aStr( aDocument.GetPageStyle( nCurTab ) );
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir 					ScStyleSheetPool* pStylePool
1623cdf0e10cSrcweir 						= aDocument.GetStyleSheetPool();
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir 					SfxStyleSheetBase* pStyleSheet
1626cdf0e10cSrcweir 						= pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 					DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 					if ( pStyleSheet )
1631cdf0e10cSrcweir 					{
1632cdf0e10cSrcweir 						SfxItemSet&  rStyleSet = pStyleSheet->GetItemSet();
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 						SvxPageUsage eUsage =
1635cdf0e10cSrcweir 							SvxPageUsage( ((const SvxPageItem&)
1636cdf0e10cSrcweir 											rStyleSet.Get( ATTR_PAGE )).
1637cdf0e10cSrcweir 												GetPageUsage() );
1638cdf0e10cSrcweir 						sal_Bool bShareHeader = IS_SHARE_HEADER(rStyleSet);
1639cdf0e10cSrcweir 						sal_Bool bShareFooter = IS_SHARE_FOOTER(rStyleSet);
1640cdf0e10cSrcweir 						sal_uInt16 nResId = 0;
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 						switch ( eUsage )
1643cdf0e10cSrcweir 						{
1644cdf0e10cSrcweir 							case SVX_PAGE_LEFT:
1645cdf0e10cSrcweir 							case SVX_PAGE_RIGHT:
1646cdf0e10cSrcweir 							{
1647cdf0e10cSrcweir 								if ( bHeaderOn && bFooterOn )
1648cdf0e10cSrcweir 									nResId = RID_SCDLG_HFEDIT;
1649cdf0e10cSrcweir 								else if ( SVX_PAGE_RIGHT == eUsage )
1650cdf0e10cSrcweir 								{
1651cdf0e10cSrcweir 									if ( !bHeaderOn && bFooterOn )
1652cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1653cdf0e10cSrcweir 									else if ( bHeaderOn && !bFooterOn )
1654cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1655cdf0e10cSrcweir 								}
1656cdf0e10cSrcweir 								else
1657cdf0e10cSrcweir 								{
1658cdf0e10cSrcweir 									//	#69193a# respect "shared" setting
1659cdf0e10cSrcweir 									if ( !bHeaderOn && bFooterOn )
1660cdf0e10cSrcweir 										nResId = bShareFooter ?
1661cdf0e10cSrcweir 													RID_SCDLG_HFEDIT_RIGHTFOOTER :
1662cdf0e10cSrcweir 													RID_SCDLG_HFEDIT_LEFTFOOTER;
1663cdf0e10cSrcweir 									else if ( bHeaderOn && !bFooterOn )
1664cdf0e10cSrcweir 										nResId = bShareHeader ?
1665cdf0e10cSrcweir 													RID_SCDLG_HFEDIT_RIGHTHEADER :
1666cdf0e10cSrcweir 													RID_SCDLG_HFEDIT_LEFTHEADER;
1667cdf0e10cSrcweir 								}
1668cdf0e10cSrcweir 							}
1669cdf0e10cSrcweir 							break;
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir 							case SVX_PAGE_MIRROR:
1672cdf0e10cSrcweir 							case SVX_PAGE_ALL:
1673cdf0e10cSrcweir 							default:
1674cdf0e10cSrcweir 							{
1675cdf0e10cSrcweir 								if ( !bShareHeader && !bShareFooter )
1676cdf0e10cSrcweir 								{
1677cdf0e10cSrcweir 									if ( bHeaderOn && bFooterOn )
1678cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_ALL;
1679cdf0e10cSrcweir 									else if ( !bHeaderOn && bFooterOn )
1680cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_FOOTER;
1681cdf0e10cSrcweir 									else if ( bHeaderOn && !bFooterOn )
1682cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_HEADER;
1683cdf0e10cSrcweir 								}
1684cdf0e10cSrcweir 								else if ( bShareHeader && bShareFooter )
1685cdf0e10cSrcweir 								{
1686cdf0e10cSrcweir 									if ( bHeaderOn && bFooterOn )
1687cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT;
1688cdf0e10cSrcweir 									else
1689cdf0e10cSrcweir 									{
1690cdf0e10cSrcweir 										if ( !bHeaderOn && bFooterOn )
1691cdf0e10cSrcweir 											nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1692cdf0e10cSrcweir 										else if ( bHeaderOn && !bFooterOn )
1693cdf0e10cSrcweir 											nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1694cdf0e10cSrcweir 									}
1695cdf0e10cSrcweir 								}
1696cdf0e10cSrcweir 								else if ( !bShareHeader &&  bShareFooter )
1697cdf0e10cSrcweir 								{
1698cdf0e10cSrcweir 									if ( bHeaderOn && bFooterOn )
1699cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_SFTR;
1700cdf0e10cSrcweir 									else if ( !bHeaderOn && bFooterOn )
1701cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1702cdf0e10cSrcweir 									else if ( bHeaderOn && !bFooterOn )
1703cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_HEADER;
1704cdf0e10cSrcweir 								}
1705cdf0e10cSrcweir 								else if (  bShareHeader && !bShareFooter )
1706cdf0e10cSrcweir 								{
1707cdf0e10cSrcweir 									if ( bHeaderOn && bFooterOn )
1708cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_SHDR;
1709cdf0e10cSrcweir 									else if ( !bHeaderOn && bFooterOn )
1710cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_FOOTER;
1711cdf0e10cSrcweir 									else if ( bHeaderOn && !bFooterOn )
1712cdf0e10cSrcweir 										nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1713cdf0e10cSrcweir 								}
1714cdf0e10cSrcweir 							}
1715cdf0e10cSrcweir 						}
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir //CHINA001						ScHFEditDlg* pDlg
1718cdf0e10cSrcweir //CHINA001						= new ScHFEditDlg( SFX_APP()->GetViewFrame(),
1719cdf0e10cSrcweir //CHINA001						GetActiveDialogParent(),
1720cdf0e10cSrcweir //CHINA001						rStyleSet,
1721cdf0e10cSrcweir //CHINA001						aStr,
1722cdf0e10cSrcweir //CHINA001						nResId );
1723cdf0e10cSrcweir //CHINA001
1724cdf0e10cSrcweir 						ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1725cdf0e10cSrcweir 						DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir                         SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
1728cdf0e10cSrcweir 																				GetActiveDialogParent(),
1729cdf0e10cSrcweir 																				rStyleSet,
1730cdf0e10cSrcweir 																				aStr,
1731cdf0e10cSrcweir 																				RID_SCDLG_HFEDIT, nResId);
1732cdf0e10cSrcweir 						DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1733cdf0e10cSrcweir 						if ( pDlg->Execute() == RET_OK )
1734cdf0e10cSrcweir 						{
1735cdf0e10cSrcweir 							const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir 							if ( pOutSet )
1738cdf0e10cSrcweir 								aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir 							SetDocumentModified();
1741cdf0e10cSrcweir 							rReq.Done();
1742cdf0e10cSrcweir 						}
1743cdf0e10cSrcweir 						delete pDlg;
1744cdf0e10cSrcweir 					}
1745cdf0e10cSrcweir 				}
1746cdf0e10cSrcweir 			}
1747cdf0e10cSrcweir 			break;
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir 		default:
1750cdf0e10cSrcweir 		break;
1751cdf0e10cSrcweir 	}
1752cdf0e10cSrcweir }
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir void ScDocShell::GetStatePageStyle( SfxViewShell&   /* rCaller */,
1755cdf0e10cSrcweir 									SfxItemSet&		rSet,
1756cdf0e10cSrcweir 									SCTAB			nCurTab )
1757cdf0e10cSrcweir {
1758cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
1759cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
1760cdf0e10cSrcweir 	while ( nWhich )
1761cdf0e10cSrcweir 	{
1762cdf0e10cSrcweir 		switch (nWhich)
1763cdf0e10cSrcweir 		{
1764cdf0e10cSrcweir 			case SID_STATUS_PAGESTYLE:
1765cdf0e10cSrcweir 				rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) );
1766cdf0e10cSrcweir 				break;
1767cdf0e10cSrcweir 
1768cdf0e10cSrcweir 			case SID_HFEDIT:
1769cdf0e10cSrcweir 				{
1770cdf0e10cSrcweir 					String				aStr	    = aDocument.GetPageStyle( nCurTab );
1771cdf0e10cSrcweir 					ScStyleSheetPool*	pStylePool  = aDocument.GetStyleSheetPool();
1772cdf0e10cSrcweir 					SfxStyleSheetBase*	pStyleSheet = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir 					DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir 					if ( pStyleSheet )
1777cdf0e10cSrcweir 					{
1778cdf0e10cSrcweir 						SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 						GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir 						if ( !bHeaderOn && !bFooterOn )
1783cdf0e10cSrcweir 							rSet.DisableItem( nWhich );
1784cdf0e10cSrcweir 					}
1785cdf0e10cSrcweir 				}
1786cdf0e10cSrcweir 				break;
1787cdf0e10cSrcweir 		}
1788cdf0e10cSrcweir 
1789cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
1790cdf0e10cSrcweir 	}
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir void ScDocShell::GetState( SfxItemSet &rSet )
1794cdf0e10cSrcweir {
1795cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
1796cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
1797cdf0e10cSrcweir 	while ( nWhich )
1798cdf0e10cSrcweir 	{
1799cdf0e10cSrcweir 		switch (nWhich)
1800cdf0e10cSrcweir 		{
1801cdf0e10cSrcweir 			case FID_AUTO_CALC:
1802cdf0e10cSrcweir 				if ( (sal_Bool) aDocument.GetHardRecalcState() )
1803cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
1804cdf0e10cSrcweir 				else
1805cdf0e10cSrcweir 					rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) );
1806cdf0e10cSrcweir 				break;
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir 			case FID_CHG_RECORD:
1809cdf0e10cSrcweir                 if ( IsDocShared() )
1810cdf0e10cSrcweir                     rSet.DisableItem( nWhich );
1811cdf0e10cSrcweir                 else
1812cdf0e10cSrcweir                     rSet.Put( SfxBoolItem( nWhich,
1813cdf0e10cSrcweir                         aDocument.GetChangeTrack() != NULL ) );
1814cdf0e10cSrcweir 				break;
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir             case SID_CHG_PROTECT:
1817cdf0e10cSrcweir 				{
1818cdf0e10cSrcweir                     ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
1819cdf0e10cSrcweir                     if ( pChangeTrack && !IsDocShared() )
1820cdf0e10cSrcweir                         rSet.Put( SfxBoolItem( nWhich,
1821cdf0e10cSrcweir                             pChangeTrack->IsProtected() ) );
1822cdf0e10cSrcweir                     else
1823cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
1824cdf0e10cSrcweir 				}
1825cdf0e10cSrcweir 				break;
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir             case SID_DOCUMENT_COMPARE:
1828cdf0e10cSrcweir                 {
1829cdf0e10cSrcweir                     if ( IsDocShared() )
1830cdf0e10cSrcweir                     {
1831cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
1832cdf0e10cSrcweir                     }
1833cdf0e10cSrcweir                 }
1834cdf0e10cSrcweir                 break;
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir 			//	Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein.
1837cdf0e10cSrcweir 			//	Recalc fuer das Doc war mal wegen #29898# disabled, wenn AutoCalc an war,
1838cdf0e10cSrcweir 			//	ist jetzt wegen #41540# aber auch immer enabled.
1839cdf0e10cSrcweir //			case FID_RECALC:
1840cdf0e10cSrcweir //				if ( aDocument.GetAutoCalc() )
1841cdf0e10cSrcweir //					rSet.DisableItem( nWhich );
1842cdf0e10cSrcweir //				break;
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir 			case SID_TABLES_COUNT:
1845cdf0e10cSrcweir 				rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) );
1846cdf0e10cSrcweir 				break;
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir 			case SID_ATTR_YEAR2000 :
1849cdf0e10cSrcweir 				rSet.Put( SfxUInt16Item( nWhich,
1850cdf0e10cSrcweir 					aDocument.GetDocOptions().GetYear2000() ) );
1851cdf0e10cSrcweir 			break;
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir             case SID_SHARE_DOC:
1854cdf0e10cSrcweir                 {
1855cdf0e10cSrcweir                     if ( IsReadOnly() )
1856cdf0e10cSrcweir                     {
1857cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
1858cdf0e10cSrcweir                     }
1859cdf0e10cSrcweir                 }
1860cdf0e10cSrcweir                 break;
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir             default:
1863cdf0e10cSrcweir                 {
1864cdf0e10cSrcweir                 }
1865cdf0e10cSrcweir                 break;
1866cdf0e10cSrcweir 		}
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
1869cdf0e10cSrcweir 	}
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir void ScDocShell::GetSbxState( SfxItemSet &rSet )
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir 	//	SID_SC_SELECTION (Selection),
1875cdf0e10cSrcweir 	//	SID_SC_ACTIVECELL (ActiveCell),
1876cdf0e10cSrcweir 	//	SID_SC_ACTIVETAB (ActiveTable),
1877cdf0e10cSrcweir 	//	SID_TABLES_GET (Tables),
1878cdf0e10cSrcweir 	//	SID_PIVOT_GET (DataPilotTables) - removed (old Basic)
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir 		//
1881cdf0e10cSrcweir 		//	Wenn hier Slots von der View-Shell executed werden, muss auch der
1882cdf0e10cSrcweir 		//	GetState weitergeleitet werden!
1883cdf0e10cSrcweir 		//
1884cdf0e10cSrcweir 
1885cdf0e10cSrcweir 	ScTabViewShell* pVisibleSh = GetBestViewShell();		// sichtbare View
1886cdf0e10cSrcweir 	if ( pVisibleSh )
1887cdf0e10cSrcweir 		pVisibleSh->GetState( rSet );
1888cdf0e10cSrcweir }
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir void __EXPORT ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect )
1891cdf0e10cSrcweir {
1892cdf0e10cSrcweir //	bIsOle = sal_True;		// jetzt ueber den CreateMode
1893cdf0e10cSrcweir 
1894cdf0e10cSrcweir 	SCTAB nVisTab = aDocument.GetVisibleTab();
1895cdf0e10cSrcweir 	if (!aDocument.HasTable(nVisTab))
1896cdf0e10cSrcweir 		return;
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir     sal_uLong nOldLayoutMode = pDev->GetLayoutMode();
1899cdf0e10cSrcweir     pDev->SetLayoutMode( TEXT_LAYOUT_DEFAULT );     // even if it's the same, to get the metafile action
1900cdf0e10cSrcweir 
1901cdf0e10cSrcweir 	if ( nAspect == ASPECT_THUMBNAIL )
1902cdf0e10cSrcweir 	{
1903cdf0e10cSrcweir 		Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL );
1904cdf0e10cSrcweir 		ScViewData aTmpData( this, NULL );
1905cdf0e10cSrcweir 		aTmpData.SetTabNo(nVisTab);
1906cdf0e10cSrcweir 		aDocument.SnapVisArea( aBoundRect );
1907cdf0e10cSrcweir 		aTmpData.SetScreen( aBoundRect );
1908cdf0e10cSrcweir 		ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True );
1909cdf0e10cSrcweir 	}
1910cdf0e10cSrcweir 	else
1911cdf0e10cSrcweir 	{
1912cdf0e10cSrcweir         Rectangle aBoundRect = SfxObjectShell::GetVisArea();
1913cdf0e10cSrcweir 		ScViewData aTmpData( this, NULL );
1914cdf0e10cSrcweir 		aTmpData.SetTabNo(nVisTab);
1915cdf0e10cSrcweir 		aDocument.SnapVisArea( aBoundRect );
1916cdf0e10cSrcweir 		aTmpData.SetScreen( aBoundRect );
1917cdf0e10cSrcweir 		ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True );
1918cdf0e10cSrcweir 	}
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir     pDev->SetLayoutMode( nOldLayoutMode );
1921cdf0e10cSrcweir }
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir Rectangle __EXPORT ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
1924cdf0e10cSrcweir {
1925cdf0e10cSrcweir 	SfxObjectCreateMode eShellMode = GetCreateMode();
1926cdf0e10cSrcweir 	if ( eShellMode == SFX_CREATE_MODE_ORGANIZER )
1927cdf0e10cSrcweir 	{
1928cdf0e10cSrcweir 		//	ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind
1929cdf0e10cSrcweir 		//	leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet
1930cdf0e10cSrcweir 		return Rectangle();
1931cdf0e10cSrcweir 	}
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir 	if( nAspect == ASPECT_THUMBNAIL )
1934cdf0e10cSrcweir 	{
1935cdf0e10cSrcweir //		Rectangle aArea( 0,0, 3175,3175 );							//	120x120 Pixel in 1:1
1936cdf0e10cSrcweir 		Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X,SC_PREVIEW_SIZE_Y );
1937cdf0e10cSrcweir         sal_Bool bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
1938cdf0e10cSrcweir         if ( bNegativePage )
1939cdf0e10cSrcweir             ScDrawLayer::MirrorRectRTL( aArea );
1940cdf0e10cSrcweir 		aDocument.SnapVisArea( aArea );
1941cdf0e10cSrcweir 		return aArea;
1942cdf0e10cSrcweir 	}
1943cdf0e10cSrcweir 	else if( nAspect == ASPECT_CONTENT && eShellMode != SFX_CREATE_MODE_EMBEDDED )
1944cdf0e10cSrcweir 	{
1945cdf0e10cSrcweir 		//	Visarea holen wie nach Load
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir 		SCTAB nVisTab = aDocument.GetVisibleTab();
1948cdf0e10cSrcweir 		if (!aDocument.HasTable(nVisTab))
1949cdf0e10cSrcweir 		{
1950cdf0e10cSrcweir 			nVisTab = 0;
1951cdf0e10cSrcweir 			((ScDocShell*)this)->aDocument.SetVisibleTab(nVisTab);
1952cdf0e10cSrcweir 		}
1953cdf0e10cSrcweir         SCCOL nStartCol;
1954cdf0e10cSrcweir         SCROW nStartRow;
1955cdf0e10cSrcweir         aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
1956cdf0e10cSrcweir         SCCOL nEndCol;
1957cdf0e10cSrcweir         SCROW nEndRow;
1958cdf0e10cSrcweir         aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
1959cdf0e10cSrcweir 		if (nStartCol>nEndCol)
1960cdf0e10cSrcweir 			nStartCol = nEndCol;
1961cdf0e10cSrcweir 		if (nStartRow>nEndRow)
1962cdf0e10cSrcweir 			nStartRow = nEndRow;
1963cdf0e10cSrcweir 		Rectangle aNewArea = ((ScDocument&)aDocument)
1964cdf0e10cSrcweir 								.GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
1965cdf0e10cSrcweir         //TODO/LATER: different methods for setting VisArea?!
1966cdf0e10cSrcweir         ((ScDocShell*)this)->SfxObjectShell::SetVisArea( aNewArea );
1967cdf0e10cSrcweir 		return aNewArea;
1968cdf0e10cSrcweir 	}
1969cdf0e10cSrcweir 	else
1970cdf0e10cSrcweir         return SfxObjectShell::GetVisArea( nAspect );
1971cdf0e10cSrcweir }
1972cdf0e10cSrcweir 
1973cdf0e10cSrcweir void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
1974cdf0e10cSrcweir 											SCTAB			  nCurTab,
1975cdf0e10cSrcweir 											sal_Bool&			  rbHeader,
1976cdf0e10cSrcweir 											sal_Bool&			  rbFooter )
1977cdf0e10cSrcweir {
1978cdf0e10cSrcweir 	if ( !pStyleSet )
1979cdf0e10cSrcweir 	{
1980cdf0e10cSrcweir 		ScStyleSheetPool*  pStylePool  = aDocument.GetStyleSheetPool();
1981cdf0e10cSrcweir 		SfxStyleSheetBase* pStyleSheet = pStylePool->
1982cdf0e10cSrcweir 											Find( aDocument.GetPageStyle( nCurTab ),
1983cdf0e10cSrcweir 												  SFX_STYLE_FAMILY_PAGE );
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir 		DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir 		if ( pStyleSheet )
1988cdf0e10cSrcweir 			pStyleSet = &pStyleSheet->GetItemSet();
1989cdf0e10cSrcweir 		else
1990cdf0e10cSrcweir 			rbHeader = rbFooter = sal_False;
1991cdf0e10cSrcweir 	}
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir 	DBG_ASSERT( pStyleSet, "PageStyle-Set not found! :-(" );
1994cdf0e10cSrcweir 
1995cdf0e10cSrcweir 	//--------------------------------------------------------------------
1996cdf0e10cSrcweir 
1997cdf0e10cSrcweir 	const SvxSetItem*	pSetItem = NULL;
1998cdf0e10cSrcweir 	const SfxItemSet*	pSet     = NULL;
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir 	pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2001cdf0e10cSrcweir 	pSet     = &pSetItem->GetItemSet();
2002cdf0e10cSrcweir 	rbHeader = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2003cdf0e10cSrcweir 
2004cdf0e10cSrcweir 	pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2005cdf0e10cSrcweir 	pSet     = &pSetItem->GetItemSet();
2006cdf0e10cSrcweir 	rbFooter = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2007cdf0e10cSrcweir }
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir long __EXPORT ScDocShell::DdeGetData( const String& rItem,
2010cdf0e10cSrcweir 									  const String& rMimeType,
2011cdf0e10cSrcweir 									  ::com::sun::star::uno::Any & rValue )
2012cdf0e10cSrcweir {
2013cdf0e10cSrcweir 	if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ) )
2014cdf0e10cSrcweir 	{
2015cdf0e10cSrcweir 		if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2016cdf0e10cSrcweir 		{
2017cdf0e10cSrcweir 			ByteString aFmtByte( aDdeTextFmt, gsl_getSystemTextEncoding() );
2018cdf0e10cSrcweir 			rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2019cdf0e10cSrcweir 										(sal_Int8*)aFmtByte.GetBuffer(),
2020cdf0e10cSrcweir 										aFmtByte.Len() + 1 );
2021cdf0e10cSrcweir 			return 1;
2022cdf0e10cSrcweir 		}
2023cdf0e10cSrcweir 		ScImportExport aObj( &aDocument, rItem );
2024cdf0e10cSrcweir 		if ( !aObj.IsRef() )
2025cdf0e10cSrcweir 			return 0;							// ungueltiger Bereich
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir 		if( aDdeTextFmt.GetChar(0) == 'F' )
2028cdf0e10cSrcweir 			aObj.SetFormulas( sal_True );
2029cdf0e10cSrcweir 		if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2030cdf0e10cSrcweir 			aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2031cdf0e10cSrcweir 		{
2032cdf0e10cSrcweir 			ByteString aData;
2033cdf0e10cSrcweir 			if( aObj.ExportByteString( aData, gsl_getSystemTextEncoding(),
2034cdf0e10cSrcweir 										SOT_FORMATSTR_ID_SYLK ) )
2035cdf0e10cSrcweir 			{
2036cdf0e10cSrcweir 				rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2037cdf0e10cSrcweir 											(sal_Int8*)aData.GetBuffer(),
2038cdf0e10cSrcweir 											aData.Len() + 1 );
2039cdf0e10cSrcweir 				return 1;
2040cdf0e10cSrcweir 			}
2041cdf0e10cSrcweir 			else
2042cdf0e10cSrcweir 				return 0;
2043cdf0e10cSrcweir 		}
2044cdf0e10cSrcweir 		if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2045cdf0e10cSrcweir 			aDdeTextFmt.EqualsAscii( "FCSV" ) )
2046cdf0e10cSrcweir 			aObj.SetSeparator( ',' );
2047cdf0e10cSrcweir         aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2048cdf0e10cSrcweir 		return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2049cdf0e10cSrcweir 	}
2050cdf0e10cSrcweir 
2051cdf0e10cSrcweir 	ScImportExport aObj( &aDocument, rItem );
2052cdf0e10cSrcweir     aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2053cdf0e10cSrcweir 	if( aObj.IsRef() )
2054cdf0e10cSrcweir 		return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2055cdf0e10cSrcweir 	return 0;
2056cdf0e10cSrcweir }
2057cdf0e10cSrcweir 
2058cdf0e10cSrcweir long __EXPORT ScDocShell::DdeSetData( const String& rItem,
2059cdf0e10cSrcweir 										const String& rMimeType,
2060cdf0e10cSrcweir 								const ::com::sun::star::uno::Any & rValue )
2061cdf0e10cSrcweir {
2062cdf0e10cSrcweir 	if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ))
2063cdf0e10cSrcweir 	{
2064cdf0e10cSrcweir 		if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2065cdf0e10cSrcweir 		{
2066cdf0e10cSrcweir 			if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, gsl_getSystemTextEncoding() ) )
2067cdf0e10cSrcweir 			{
2068cdf0e10cSrcweir 				aDdeTextFmt.ToUpperAscii();
2069cdf0e10cSrcweir 				return 1;
2070cdf0e10cSrcweir 			}
2071cdf0e10cSrcweir 			return 0;
2072cdf0e10cSrcweir 		}
2073cdf0e10cSrcweir 		ScImportExport aObj( &aDocument, rItem );
2074cdf0e10cSrcweir 		if( aDdeTextFmt.GetChar(0) == 'F' )
2075cdf0e10cSrcweir 			aObj.SetFormulas( sal_True );
2076cdf0e10cSrcweir 		if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2077cdf0e10cSrcweir 			aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2078cdf0e10cSrcweir 		{
2079cdf0e10cSrcweir 			String aData;
2080cdf0e10cSrcweir 			if ( ScByteSequenceToString::GetString( aData, rValue, gsl_getSystemTextEncoding() ) )
2081cdf0e10cSrcweir 			{
2082cdf0e10cSrcweir 				return aObj.ImportString( aData, SOT_FORMATSTR_ID_SYLK ) ? 1 : 0;
2083cdf0e10cSrcweir 			}
2084cdf0e10cSrcweir 			return 0;
2085cdf0e10cSrcweir 		}
2086cdf0e10cSrcweir 		if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2087cdf0e10cSrcweir 			aDdeTextFmt.EqualsAscii( "FCSV" ) )
2088cdf0e10cSrcweir 			aObj.SetSeparator( ',' );
2089cdf0e10cSrcweir 		return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2090cdf0e10cSrcweir 	}
2091cdf0e10cSrcweir 	ScImportExport aObj( &aDocument, rItem );
2092cdf0e10cSrcweir 	if( aObj.IsRef() )
2093cdf0e10cSrcweir 		return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2094cdf0e10cSrcweir 	return 0;
2095cdf0e10cSrcweir }
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir ::sfx2::SvLinkSource* __EXPORT ScDocShell::DdeCreateLinkSource( const String& rItem )
2098cdf0e10cSrcweir {
2099cdf0e10cSrcweir 	//	only check for valid item string - range is parsed again in ScServerObject ctor
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir 	//  named range?
2102cdf0e10cSrcweir 	String aPos = rItem;
2103cdf0e10cSrcweir 	ScRangeName* pRange = aDocument.GetRangeName();
2104cdf0e10cSrcweir 	if( pRange )
2105cdf0e10cSrcweir 	{
2106cdf0e10cSrcweir 		sal_uInt16 nPos;
2107cdf0e10cSrcweir 		if( pRange->SearchName( aPos, nPos ) )
2108cdf0e10cSrcweir 		{
2109cdf0e10cSrcweir 			ScRangeData* pData = (*pRange)[ nPos ];
2110cdf0e10cSrcweir 			if( pData->HasType( RT_REFAREA )
2111cdf0e10cSrcweir 				|| pData->HasType( RT_ABSAREA )
2112cdf0e10cSrcweir 				|| pData->HasType( RT_ABSPOS ) )
2113cdf0e10cSrcweir 				pData->GetSymbol( aPos );			// continue with the name's contents
2114cdf0e10cSrcweir 		}
2115cdf0e10cSrcweir 	}
2116cdf0e10cSrcweir 
2117cdf0e10cSrcweir     // Address in DDE function must be always parsed as CONV_OOO so that it
2118cdf0e10cSrcweir     // would always work regardless of current address convension.  We do this
2119cdf0e10cSrcweir     // because the address item in a DDE entry is *not* normalized when saved
2120cdf0e10cSrcweir     // into ODF.
2121cdf0e10cSrcweir     ScRange aRange;
2122cdf0e10cSrcweir     bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & SCA_VALID) ||
2123cdf0e10cSrcweir                     (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & SCA_VALID) );
2124cdf0e10cSrcweir 
2125cdf0e10cSrcweir 	ScServerObject* pObj = NULL;			// NULL = error
2126cdf0e10cSrcweir 	if ( bValid )
2127cdf0e10cSrcweir 		pObj = new ScServerObject( this, rItem );
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir 	//	GetLinkManager()->InsertServer() is in the ScServerObject ctor
2130cdf0e10cSrcweir 
2131cdf0e10cSrcweir 	return pObj;
2132cdf0e10cSrcweir }
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir //------------------------------------------------------------------
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir ScViewData* ScDocShell::GetViewData()
2137cdf0e10cSrcweir {
2138cdf0e10cSrcweir 	SfxViewShell* pCur = SfxViewShell::Current();
2139cdf0e10cSrcweir 	ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pCur);
2140cdf0e10cSrcweir 	return pViewSh ? pViewSh->GetViewData() : NULL;
2141cdf0e10cSrcweir }
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir //------------------------------------------------------------------
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir SCTAB ScDocShell::GetCurTab()
2146cdf0e10cSrcweir {
2147cdf0e10cSrcweir 	//!	this must be made non-static and use a ViewShell from this document!
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir 	ScViewData* pViewData = GetViewData();
2150cdf0e10cSrcweir 
2151cdf0e10cSrcweir 	return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2152cdf0e10cSrcweir }
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir ScTabViewShell* ScDocShell::GetBestViewShell( sal_Bool bOnlyVisible )
2155cdf0e10cSrcweir {
2156cdf0e10cSrcweir 	ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
2157cdf0e10cSrcweir 	// falsches Doc?
2158cdf0e10cSrcweir 	if( pViewSh && pViewSh->GetViewData()->GetDocShell() != this )
2159cdf0e10cSrcweir 		pViewSh = NULL;
2160cdf0e10cSrcweir 	if( !pViewSh )
2161cdf0e10cSrcweir 	{
2162cdf0e10cSrcweir 		// 1. ViewShell suchen
2163cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible );
2164cdf0e10cSrcweir 		if( pFrame )
2165cdf0e10cSrcweir 		{
2166cdf0e10cSrcweir 			SfxViewShell* p = pFrame->GetViewShell();
2167cdf0e10cSrcweir 			pViewSh = PTR_CAST(ScTabViewShell,p);
2168cdf0e10cSrcweir 		}
2169cdf0e10cSrcweir 	}
2170cdf0e10cSrcweir 	return pViewSh;
2171cdf0e10cSrcweir }
2172cdf0e10cSrcweir 
2173cdf0e10cSrcweir SfxBindings* ScDocShell::GetViewBindings()
2174cdf0e10cSrcweir {
2175cdf0e10cSrcweir 	//	used to invalidate slots after changes to this document
2176cdf0e10cSrcweir 
2177cdf0e10cSrcweir 	SfxViewShell* pViewSh = GetBestViewShell();
2178cdf0e10cSrcweir 	if (pViewSh)
2179cdf0e10cSrcweir 		return &pViewSh->GetViewFrame()->GetBindings();
2180cdf0e10cSrcweir 	else
2181cdf0e10cSrcweir 		return NULL;
2182cdf0e10cSrcweir }
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir //------------------------------------------------------------------
2185cdf0e10cSrcweir 
2186cdf0e10cSrcweir ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo )		// static
2187cdf0e10cSrcweir {
2188cdf0e10cSrcweir 	ScDocShell* pFound = NULL;
2189cdf0e10cSrcweir 	SfxObjectShell*	pShell = SfxObjectShell::GetFirst();
2190cdf0e10cSrcweir 	sal_uInt16 nShellCnt = 0;
2191cdf0e10cSrcweir 
2192cdf0e10cSrcweir 	while ( pShell && !pFound )
2193cdf0e10cSrcweir 	{
2194cdf0e10cSrcweir 		if ( pShell->Type() == TYPE(ScDocShell) )
2195cdf0e10cSrcweir 		{
2196cdf0e10cSrcweir 			if ( nShellCnt == nDocNo )
2197cdf0e10cSrcweir 				pFound = (ScDocShell*) pShell;
2198cdf0e10cSrcweir 			else
2199cdf0e10cSrcweir 				++nShellCnt;
2200cdf0e10cSrcweir 		}
2201cdf0e10cSrcweir 		pShell = SfxObjectShell::GetNext( *pShell );
2202cdf0e10cSrcweir 	}
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir 	return pFound;
2205cdf0e10cSrcweir }
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir //------------------------------------------------------------------
2208cdf0e10cSrcweir 
2209cdf0e10cSrcweir IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2210cdf0e10cSrcweir {
2211cdf0e10cSrcweir     DBG_ASSERT( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2212cdf0e10cSrcweir     DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir     if ( ERRCODE_NONE == _pFileDlg->GetError() )
2215cdf0e10cSrcweir     {
2216cdf0e10cSrcweir         sal_uInt16 nSlot = pImpl->pRequest->GetSlot();
2217cdf0e10cSrcweir         SfxMedium* pMed = pImpl->pDocInserter->CreateMedium();
2218cdf0e10cSrcweir         // #i87094# If a .odt was selected pMed is NULL.
2219cdf0e10cSrcweir         if (pMed)
2220cdf0e10cSrcweir         {
2221cdf0e10cSrcweir             pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2222cdf0e10cSrcweir             if ( SID_DOCUMENT_COMPARE == nSlot )
2223cdf0e10cSrcweir             {
2224cdf0e10cSrcweir                 if ( pMed->GetFilter() )
2225cdf0e10cSrcweir                     pImpl->pRequest->AppendItem(
2226cdf0e10cSrcweir                             SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2227cdf0e10cSrcweir                 String sOptions = ScDocumentLoader::GetOptions( *pMed );
2228cdf0e10cSrcweir                 if ( sOptions.Len() > 0 )
2229cdf0e10cSrcweir                     pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2230cdf0e10cSrcweir             }
2231cdf0e10cSrcweir             const SfxPoolItem* pItem = NULL;
2232cdf0e10cSrcweir             SfxItemSet* pSet = pMed->GetItemSet();
2233cdf0e10cSrcweir             if ( pSet &&
2234cdf0e10cSrcweir                     pSet->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET &&
2235cdf0e10cSrcweir                     pItem->ISA( SfxInt16Item ) )
2236cdf0e10cSrcweir             {
2237cdf0e10cSrcweir                 pImpl->pRequest->AppendItem( *pItem );
2238cdf0e10cSrcweir             }
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir             Execute( *(pImpl->pRequest) );
2241cdf0e10cSrcweir         }
2242cdf0e10cSrcweir     }
2243cdf0e10cSrcweir 
2244cdf0e10cSrcweir     pImpl->bIgnoreLostRedliningWarning = false;
2245cdf0e10cSrcweir     return 0;
2246cdf0e10cSrcweir }
2247cdf0e10cSrcweir 
2248cdf0e10cSrcweir //------------------------------------------------------------------
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir void ScDocShell::EnableSharedSettings( bool bEnable )
2251cdf0e10cSrcweir {
2252cdf0e10cSrcweir     SetDocumentModified();
2253cdf0e10cSrcweir 
2254cdf0e10cSrcweir     if ( bEnable )
2255cdf0e10cSrcweir     {
2256cdf0e10cSrcweir         aDocument.EndChangeTracking();
2257cdf0e10cSrcweir         aDocument.StartChangeTracking();
2258cdf0e10cSrcweir 
2259cdf0e10cSrcweir         // hide accept or reject changes dialog
2260cdf0e10cSrcweir         sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2261cdf0e10cSrcweir         SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2262cdf0e10cSrcweir         if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2263cdf0e10cSrcweir         {
2264cdf0e10cSrcweir             pViewFrame->ToggleChildWindow( nId );
2265cdf0e10cSrcweir             SfxBindings* pBindings = GetViewBindings();
2266cdf0e10cSrcweir             if ( pBindings )
2267cdf0e10cSrcweir             {
2268cdf0e10cSrcweir                 pBindings->Invalidate( FID_CHG_ACCEPT );
2269cdf0e10cSrcweir             }
2270cdf0e10cSrcweir         }
2271cdf0e10cSrcweir     }
2272cdf0e10cSrcweir     else
2273cdf0e10cSrcweir     {
2274cdf0e10cSrcweir         aDocument.EndChangeTracking();
2275cdf0e10cSrcweir     }
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir     ScChangeViewSettings aChangeViewSet;
2278cdf0e10cSrcweir     aChangeViewSet.SetShowChanges( sal_False );
2279cdf0e10cSrcweir     aDocument.SetChangeViewSettings( aChangeViewSet );
2280cdf0e10cSrcweir }
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2283cdf0e10cSrcweir {
2284cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel;
2285cdf0e10cSrcweir     try
2286cdf0e10cSrcweir     {
2287cdf0e10cSrcweir         SC_MOD()->SetInSharedDocLoading( true );
2288cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory(
2289cdf0e10cSrcweir             ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2290cdf0e10cSrcweir         uno::Reference< frame::XComponentLoader > xLoader(
2291cdf0e10cSrcweir             xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
2292cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
2293cdf0e10cSrcweir         uno::Sequence < beans::PropertyValue > aArgs( 1 );
2294cdf0e10cSrcweir         aArgs[0].Name = ::rtl::OUString::createFromAscii( "Hidden" );
2295cdf0e10cSrcweir         aArgs[0].Value <<= sal_True;
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir         if ( GetMedium() )
2298cdf0e10cSrcweir         {
2299cdf0e10cSrcweir             SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
2300cdf0e10cSrcweir             if ( pPasswordItem && pPasswordItem->GetValue().Len() )
2301cdf0e10cSrcweir             {
2302cdf0e10cSrcweir                 aArgs.realloc( 2 );
2303cdf0e10cSrcweir                 aArgs[1].Name = ::rtl::OUString::createFromAscii( "Password" );
2304cdf0e10cSrcweir                 aArgs[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
2305cdf0e10cSrcweir             }
2306cdf0e10cSrcweir         }
2307cdf0e10cSrcweir 
2308cdf0e10cSrcweir         xModel.set(
2309cdf0e10cSrcweir             xLoader->loadComponentFromURL( GetSharedFileURL(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, aArgs ),
2310cdf0e10cSrcweir             uno::UNO_QUERY_THROW );
2311cdf0e10cSrcweir         SC_MOD()->SetInSharedDocLoading( false );
2312cdf0e10cSrcweir     }
2313cdf0e10cSrcweir     catch ( uno::Exception& )
2314cdf0e10cSrcweir     {
2315cdf0e10cSrcweir         DBG_ERROR( "ScDocShell::LoadSharedDocument(): caught exception\n" );
2316cdf0e10cSrcweir         SC_MOD()->SetInSharedDocLoading( false );
2317cdf0e10cSrcweir         try
2318cdf0e10cSrcweir         {
2319cdf0e10cSrcweir             uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2320cdf0e10cSrcweir             xClose->close( sal_True );
2321cdf0e10cSrcweir             return uno::Reference< frame::XModel >();
2322cdf0e10cSrcweir         }
2323cdf0e10cSrcweir         catch ( uno::Exception& )
2324cdf0e10cSrcweir         {
2325cdf0e10cSrcweir             return uno::Reference< frame::XModel >();
2326cdf0e10cSrcweir         }
2327cdf0e10cSrcweir     }
2328cdf0e10cSrcweir     return xModel;
2329cdf0e10cSrcweir }
2330