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