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