LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/docshell - docsh4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 127 1132 11.2 %
Date: 2012-12-17 Functions: 11 31 35.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10