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