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