LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/unoobj - docuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1117 1922 58.1 %
Date: 2013-07-09 Functions: 138 216 63.9 %
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 "scitems.hxx"
      21             : #include <svx/fmdpage.hxx>
      22             : #include <svx/fmview.hxx>
      23             : #include <svx/svditer.hxx>
      24             : #include <svx/svdpage.hxx>
      25             : #include <svx/svxids.hrc>
      26             : #include <svx/unoshape.hxx>
      27             : 
      28             : #include <officecfg/Office/Common.hxx>
      29             : #include <svl/numuno.hxx>
      30             : #include <svl/smplhint.hxx>
      31             : #include <unotools/moduleoptions.hxx>
      32             : #include <sfx2/printer.hxx>
      33             : #include <sfx2/bindings.hxx>
      34             : #include <vcl/pdfextoutdevdata.hxx>
      35             : #include <vcl/waitobj.hxx>
      36             : #include <unotools/charclass.hxx>
      37             : #include <tools/multisel.hxx>
      38             : #include <tools/resary.hxx>
      39             : #include <toolkit/awt/vclxdevice.hxx>
      40             : 
      41             : #include <ctype.h>
      42             : #include <float.h>  // DBL_MAX
      43             : 
      44             : #include <com/sun/star/util/Date.hpp>
      45             : #include <com/sun/star/sheet/XNamedRanges.hpp>
      46             : #include <com/sun/star/sheet/XLabelRanges.hpp>
      47             : #include <com/sun/star/sheet/XSelectedSheetsSupplier.hpp>
      48             : #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
      49             : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
      50             : #include <com/sun/star/script/XLibraryContainer.hpp>
      51             : #include <com/sun/star/lang/XInitialization.hpp>
      52             : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
      53             : #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
      54             : #include <com/sun/star/document/IndexedPropertyValues.hpp>
      55             : #include <com/sun/star/script/XInvocation.hpp>
      56             : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
      57             : #include <comphelper/processfactory.hxx>
      58             : #include <comphelper/servicehelper.hxx>
      59             : #include <comphelper/string.hxx>
      60             : 
      61             : #include "docuno.hxx"
      62             : #include "cellsuno.hxx"
      63             : #include "nameuno.hxx"
      64             : #include "datauno.hxx"
      65             : #include "miscuno.hxx"
      66             : #include "notesuno.hxx"
      67             : #include "styleuno.hxx"
      68             : #include "linkuno.hxx"
      69             : #include "servuno.hxx"
      70             : #include "targuno.hxx"
      71             : #include "convuno.hxx"
      72             : #include "optuno.hxx"
      73             : #include "forbiuno.hxx"
      74             : #include "docsh.hxx"
      75             : #include "hints.hxx"
      76             : #include "docfunc.hxx"
      77             : #include "postit.hxx"
      78             : #include "dociter.hxx"
      79             : #include "formulacell.hxx"
      80             : #include "drwlayer.hxx"
      81             : #include "rangeutl.hxx"
      82             : #include "markdata.hxx"
      83             : #include "docoptio.hxx"
      84             : #include "unonames.hxx"
      85             : #include "shapeuno.hxx"
      86             : #include "viewuno.hxx"
      87             : #include "tabvwsh.hxx"
      88             : #include "printfun.hxx"
      89             : #include "pfuncache.hxx"
      90             : #include "scmod.hxx"
      91             : #include "ViewSettingsSequenceDefines.hxx"
      92             : #include "sheetevents.hxx"
      93             : #include "sc.hrc"
      94             : #include "scresid.hxx"
      95             : 
      96             : using namespace com::sun::star;
      97             : 
      98             : // #i111553# provides the name of the VBA constant for this document type (e.g. 'ThisExcelDoc' for Calc)
      99             : #define SC_UNO_VBAGLOBNAME "VBAGlobalConstantName"
     100             : 
     101             : //------------------------------------------------------------------------
     102             : 
     103             : //  alles ohne Which-ID, Map nur fuer PropertySetInfo
     104             : 
     105             : //! umbenennen, sind nicht mehr nur Options
     106         577 : static const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
     107             : {
     108             :     static SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
     109             :     {
     110          31 :         {MAP_CHAR_LEN(SC_UNO_APPLYFMDES),        0, &getBooleanCppuType(),                                    0, 0},
     111          31 :         {MAP_CHAR_LEN(SC_UNO_AREALINKS),         0, &getCppuType((uno::Reference<sheet::XAreaLinks>*)0),      0, 0},
     112          31 :         {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC),       0, &getBooleanCppuType(),                                    0, 0},
     113          31 :         {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES),    0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
     114          31 :         {MAP_CHAR_LEN(SC_UNO_DIALOGLIBRARIES),   0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
     115          31 :         {MAP_CHAR_LEN(SC_UNO_VBAGLOBNAME),       0, &getCppuType(static_cast< const OUString * >(0)),    beans::PropertyAttribute::READONLY, 0},
     116          31 :         {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN),       PROP_UNO_CALCASSHOWN, &getBooleanCppuType(),                                    0, 0},
     117          31 :         {MAP_CHAR_LEN(SC_UNONAME_CLOCAL),        0, &getCppuType((lang::Locale*)0),                           0, 0},
     118          31 :         {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),        0, &getCppuType((lang::Locale*)0),                           0, 0},
     119          31 :         {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),        0, &getCppuType((lang::Locale*)0),                           0, 0},
     120          31 :         {MAP_CHAR_LEN(SC_UNO_COLLABELRNG),       0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0),    0, 0},
     121          31 :         {MAP_CHAR_LEN(SC_UNO_DDELINKS),          0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
     122          31 :         {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP),        PROP_UNO_DEFTABSTOP, &getCppuType((sal_Int16*)0),                              0, 0},
     123          31 :         {MAP_CHAR_LEN(SC_UNO_EXTERNALDOCLINKS),  0, &getCppuType((uno::Reference<sheet::XExternalDocLinks>*)0), 0, 0},
     124          31 :         {MAP_CHAR_LEN(SC_UNO_FORBIDDEN),         0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY, 0},
     125          31 :         {MAP_CHAR_LEN(SC_UNO_HASDRAWPAGES),      0, &getBooleanCppuType(),                                    beans::PropertyAttribute::READONLY, 0},
     126          31 :         {MAP_CHAR_LEN(SC_UNO_IGNORECASE),        PROP_UNO_IGNORECASE, &getBooleanCppuType(),                                    0, 0},
     127          31 :         {MAP_CHAR_LEN(SC_UNO_ITERENABLED),       PROP_UNO_ITERENABLED, &getBooleanCppuType(),                                    0, 0},
     128          31 :         {MAP_CHAR_LEN(SC_UNO_ITERCOUNT),         PROP_UNO_ITERCOUNT, &getCppuType((sal_Int32*)0),                              0, 0},
     129          31 :         {MAP_CHAR_LEN(SC_UNO_ITEREPSILON),       PROP_UNO_ITEREPSILON, &getCppuType((double*)0),                                 0, 0},
     130          31 :         {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS),      PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(),                                    0, 0},
     131          31 :         {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE),        PROP_UNO_MATCHWHOLE, &getBooleanCppuType(),                                    0, 0},
     132          31 :         {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES),       0, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0),    0, 0},
     133          31 :         {MAP_CHAR_LEN(SC_UNO_DATABASERNG),       0, &getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0), 0, 0},
     134          31 :         {MAP_CHAR_LEN(SC_UNO_NULLDATE),          PROP_UNO_NULLDATE, &getCppuType((util::Date*)0),                             0, 0},
     135          31 :         {MAP_CHAR_LEN(SC_UNO_ROWLABELRNG),       0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0),    0, 0},
     136          31 :         {MAP_CHAR_LEN(SC_UNO_SHEETLINKS),        0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
     137          31 :         {MAP_CHAR_LEN(SC_UNO_SPELLONLINE),       PROP_UNO_SPELLONLINE, &getBooleanCppuType(),                                    0, 0},
     138          31 :         {MAP_CHAR_LEN(SC_UNO_STANDARDDEC),       PROP_UNO_STANDARDDEC, &getCppuType((sal_Int16*)0),                              0, 0},
     139          31 :         {MAP_CHAR_LEN(SC_UNO_REGEXENABLED),      PROP_UNO_REGEXENABLED, &getBooleanCppuType(),                                    0, 0},
     140          31 :         {MAP_CHAR_LEN(SC_UNO_RUNTIMEUID),        0, &getCppuType(static_cast< const OUString * >(0)),    beans::PropertyAttribute::READONLY, 0},
     141          31 :         {MAP_CHAR_LEN(SC_UNO_HASVALIDSIGNATURES),0, &getBooleanCppuType(),                                    beans::PropertyAttribute::READONLY, 0},
     142          31 :         {MAP_CHAR_LEN(SC_UNO_ISLOADED),          0, &getBooleanCppuType(),                                    0, 0},
     143          31 :         {MAP_CHAR_LEN(SC_UNO_ISUNDOENABLED),     0, &getBooleanCppuType(),                                    0, 0},
     144          31 :         {MAP_CHAR_LEN(SC_UNO_ISADJUSTHEIGHTENABLED), 0, &getBooleanCppuType(),                                0, 0},
     145          31 :         {MAP_CHAR_LEN(SC_UNO_ISEXECUTELINKENABLED), 0, &getBooleanCppuType(),                                 0, 0},
     146          31 :         {MAP_CHAR_LEN(SC_UNO_ISCHANGEREADONLYENABLED), 0, &getBooleanCppuType(),                              0, 0},
     147          31 :         {MAP_CHAR_LEN(SC_UNO_REFERENCEDEVICE),   0, &getCppuType((uno::Reference<awt::XDevice>*)0),           beans::PropertyAttribute::READONLY, 0},
     148          31 :         {MAP_CHAR_LEN("BuildId"),                0, &::getCppuType(static_cast< const OUString * >(0)), 0, 0},
     149          31 :         {MAP_CHAR_LEN(SC_UNO_CODENAME),        0, &getCppuType(static_cast< const OUString * >(0)),    0, 0},
     150             : 
     151             :         {0,0,0,0,0,0}
     152        1817 :     };
     153         577 :     return aDocOptPropertyMap_Impl;
     154             : }
     155             : 
     156             : //! StandardDecimals als Property und vom NumberFormatter ????????
     157             : 
     158          20 : static const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
     159             : {
     160             :     static SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
     161             :     {
     162          20 :         {MAP_CHAR_LEN(SC_UNONAME_MANPAGE),  0,  &getBooleanCppuType(),          0, 0 },
     163          20 :         {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE),  0,  &getBooleanCppuType(),          0, 0 },
     164          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLVIS),  0,  &getBooleanCppuType(),          0, 0 },
     165          20 :         {MAP_CHAR_LEN(SC_UNONAME_OWIDTH),   0,  &getBooleanCppuType(),          0, 0 },
     166          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLWID),  0,  &getCppuType((sal_Int32*)0),    0, 0 },
     167             :         {0,0,0,0,0,0}
     168         120 :     };
     169          20 :     return aColumnsPropertyMap_Impl;
     170             : }
     171             : 
     172          20 : static const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
     173             : {
     174             :     static SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
     175             :     {
     176          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLHGT),  0,  &getCppuType((sal_Int32*)0),    0, 0 },
     177          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), 0,  &getBooleanCppuType(),          0, 0 },
     178          20 :         {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT),  0,  &getBooleanCppuType(),          0, 0 },
     179          20 :         {MAP_CHAR_LEN(SC_UNONAME_MANPAGE),  0,  &getBooleanCppuType(),          0, 0 },
     180          20 :         {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE),  0,  &getBooleanCppuType(),          0, 0 },
     181          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLVIS),  0,  &getBooleanCppuType(),          0, 0 },
     182          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
     183          20 :         {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
     184             :         // not sorted, not used with SfxItemPropertyMapEntry::GetByName
     185             :         {0,0,0,0,0,0}
     186         180 :     };
     187          20 :     return aRowsPropertyMap_Impl;
     188             : }
     189             : 
     190             : using sc::HMMToTwips;
     191             : using sc::TwipsToHMM;
     192             : 
     193             : //------------------------------------------------------------------------
     194             : 
     195             : #define SCMODELOBJ_SERVICE          "com.sun.star.sheet.SpreadsheetDocument"
     196             : #define SCDOCSETTINGS_SERVICE       "com.sun.star.sheet.SpreadsheetDocumentSettings"
     197             : #define SCDOC_SERVICE               "com.sun.star.document.OfficeDocument"
     198             : 
     199           0 : SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
     200           0 : SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
     201           0 : SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
     202           0 : SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
     203           0 : SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
     204           0 : SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
     205           0 : SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
     206             : 
     207             : //------------------------------------------------------------------------
     208             : 
     209           0 : class ScPrintUIOptions : public vcl::PrinterOptionsHelper
     210             : {
     211             : public:
     212             :     ScPrintUIOptions();
     213             :     void SetDefaults();
     214             : };
     215             : 
     216           0 : ScPrintUIOptions::ScPrintUIOptions()
     217             : {
     218           0 :     const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
     219           0 :     sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
     220           0 :     sal_Bool bSuppress = rPrintOpt.GetSkipEmpty();
     221             : 
     222           0 :     ResStringArray aStrings( ScResId( SCSTR_PRINT_OPTIONS ) );
     223             :     OSL_ENSURE( aStrings.Count() >= 10, "resource incomplete" );
     224           0 :     if( aStrings.Count() < 10 ) // bad resource ?
     225           0 :         return;
     226             : 
     227           0 :     sal_Int32 nNumProps= 9, nIdx = 0;
     228             : 
     229           0 :     m_aUIProperties.realloc(nNumProps);
     230             : 
     231             :     // load the writer PrinterOptions into the custom tab
     232           0 :     m_aUIProperties[nIdx].Name = OUString("OptionsUIFile");
     233           0 :     m_aUIProperties[nIdx++].Value <<= OUString("modules/scalc/ui/printeroptions.ui");
     234             : 
     235             :     // create Section for spreadsheet (results in an extra tab page in dialog)
     236           0 :     SvtModuleOptions aOpt;
     237           0 :     String aAppGroupname( aStrings.GetString( 9 ) );
     238             :     aAppGroupname.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ),
     239           0 :                                     aOpt.GetModuleName( SvtModuleOptions::E_SCALC ) );
     240           0 :     m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, OUString());
     241             : 
     242             :     // show subgroup for pages
     243           0 :     m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("pages", OUString(aStrings.GetString(0)), OUString());
     244             : 
     245             :     // create a bool option for empty pages
     246           0 :     m_aUIProperties[nIdx++].Value = setBoolControlOpt("includeemptypages", OUString( aStrings.GetString( 1 ) ),
     247             :                                                   ".HelpID:vcl:PrintDialog:IsIncludeEmptyPages:CheckBox",
     248             :                                                   "IsIncludeEmptyPages",
     249           0 :                                                   ! bSuppress);
     250             :     // show Subgroup for print content
     251           0 :     vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
     252           0 :     aPrintRangeOpt.maGroupHint = OUString( "PrintRange" );
     253           0 :     m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("printrange", OUString(aStrings.GetString(2)),
     254             :                                                       OUString(),
     255           0 :                                                       aPrintRangeOpt);
     256             : 
     257             :     // create a choice for the content to create
     258           0 :     uno::Sequence< OUString > aChoices( 3 ), aHelpIds( 3 ), aWidgetIds( 3 );
     259           0 :     aChoices[0] = aStrings.GetString( 3 );
     260           0 :     aHelpIds[0] = OUString( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" );
     261           0 :     aWidgetIds[0] = "printallsheets";
     262           0 :     aChoices[1] = aStrings.GetString( 4 );
     263           0 :     aHelpIds[1] = OUString( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" );
     264           0 :     aWidgetIds[1] = "printselectedsheets";
     265           0 :     aChoices[2] = aStrings.GetString( 5 );
     266           0 :     aHelpIds[2] = OUString( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2" );
     267           0 :     aWidgetIds[2] = "printselectedcells";
     268           0 :     m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
     269             :                                                     aHelpIds, "PrintContent",
     270           0 :                                                     aChoices, nContent );
     271             : 
     272             :     // show Subgroup for print range
     273           0 :     aPrintRangeOpt.mbInternalOnly = sal_True;
     274           0 :     m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("fromwhich", OUString(aStrings.GetString(6)),
     275             :                                                       OUString(),
     276           0 :                                                       aPrintRangeOpt);
     277             : 
     278             :     // create a choice for the range to print
     279           0 :     OUString aPrintRangeName( "PrintRange" );
     280           0 :     aChoices.realloc( 2 );
     281           0 :     aHelpIds.realloc( 2 );
     282           0 :     aWidgetIds.realloc( 2 );
     283           0 :     aChoices[0] = aStrings.GetString( 7 );
     284           0 :     aHelpIds[0] = OUString( ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:0" );
     285           0 :     aWidgetIds[0] = "printallpages";
     286           0 :     aChoices[1] = aStrings.GetString( 8 );
     287           0 :     aHelpIds[1] = OUString( ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:1" );
     288           0 :     aWidgetIds[1] = "printpages";
     289           0 :     m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
     290             :                                                     aHelpIds,
     291             :                                                     aPrintRangeName,
     292             :                                                     aChoices,
     293           0 :                                                     0 );
     294             : 
     295             :     // create a an Edit dependent on "Pages" selected
     296           0 :     vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, sal_True );
     297           0 :     m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
     298             :                                                       ".HelpID:vcl:PrintDialog:PageRange:Edit",
     299           0 :                                                       "PageRange", OUString(), aPageRangeOpt);
     300             : 
     301           0 :     assert(nIdx == nNumProps);
     302             : }
     303             : 
     304           0 : void ScPrintUIOptions::SetDefaults()
     305             : {
     306             :     // re-initialize the default values from print options
     307             : 
     308           0 :     const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
     309           0 :     sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
     310           0 :     sal_Bool bSuppress = rPrintOpt.GetSkipEmpty();
     311             : 
     312           0 :     for (sal_Int32 nUIPos=0; nUIPos<m_aUIProperties.getLength(); ++nUIPos)
     313             :     {
     314           0 :         uno::Sequence<beans::PropertyValue> aUIProp;
     315           0 :         if ( m_aUIProperties[nUIPos].Value >>= aUIProp )
     316             :         {
     317           0 :             for (sal_Int32 nPropPos=0; nPropPos<aUIProp.getLength(); ++nPropPos)
     318             :             {
     319           0 :                 OUString aName = aUIProp[nPropPos].Name;
     320           0 :                 if ( aName == "Property" )
     321             :                 {
     322           0 :                     beans::PropertyValue aPropertyValue;
     323           0 :                     if ( aUIProp[nPropPos].Value >>= aPropertyValue )
     324             :                     {
     325           0 :                         if ( aPropertyValue.Name == "PrintContent" )
     326             :                         {
     327           0 :                             aPropertyValue.Value <<= nContent;
     328           0 :                             aUIProp[nPropPos].Value <<= aPropertyValue;
     329             :                         }
     330           0 :                         else if ( aPropertyValue.Name == "IsIncludeEmptyPages" )
     331             :                         {
     332           0 :                             ScUnoHelpFunctions::SetBoolInAny( aPropertyValue.Value, ! bSuppress );
     333           0 :                             aUIProp[nPropPos].Value <<= aPropertyValue;
     334             :                         }
     335           0 :                     }
     336             :                 }
     337           0 :             }
     338           0 :             m_aUIProperties[nUIPos].Value <<= aUIProp;
     339             :         }
     340           0 :     }
     341           0 : }
     342             : 
     343         577 : void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
     344             : {
     345         577 :     if (pDocSh)
     346         577 :         pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
     347         577 : }
     348             : 
     349         577 : ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
     350             :     SfxBaseModel( pDocSh ),
     351             :     aPropSet( lcl_GetDocOptPropertyMap() ),
     352             :     pDocShell( pDocSh ),
     353             :     pPrintFuncCache( NULL ),
     354             :     pPrinterOptions( NULL ),
     355         577 :     maChangesListeners( m_aMutex )
     356             : {
     357             :     // pDocShell may be NULL if this is the base of a ScDocOptionsObj
     358         577 :     if ( pDocShell )
     359             :     {
     360         577 :         pDocShell->GetDocument()->AddUnoObject(*this);      // SfxModel is derived from SfxListener
     361             :     }
     362         577 : }
     363             : 
     364        1296 : ScModelObj::~ScModelObj()
     365             : {
     366         432 :     if (pDocShell)
     367           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
     368             : 
     369         432 :     if (xNumberAgg.is())
     370         112 :         xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
     371             : 
     372         432 :     delete pPrintFuncCache;
     373         432 :     delete pPrinterOptions;
     374         864 : }
     375             : 
     376        7265 : uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
     377             : {
     378             :     // pDocShell may be NULL if this is the base of a ScDocOptionsObj
     379        7265 :     if ( !xNumberAgg.is() && pDocShell )
     380             :     {
     381             :         // setDelegator veraendert den RefCount, darum eine Referenz selber halten
     382             :         // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
     383         157 :         comphelper::increment( m_refCount );
     384             :         // waehrend des queryInterface braucht man ein Ref auf das
     385             :         // SvNumberFormatsSupplierObj, sonst wird es geloescht.
     386         157 :         uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument()->GetFormatTable() ));
     387             :         {
     388         157 :             xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
     389             :             // extra block to force deletion of the temporary before setDelegator
     390             :         }
     391             : 
     392             :         // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
     393         157 :         xFormatter = NULL;
     394             : 
     395         157 :         if (xNumberAgg.is())
     396         157 :             xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
     397         157 :         comphelper::decrement( m_refCount );
     398             :     } // if ( !xNumberAgg.is() )
     399        7265 :     return xNumberAgg;
     400             : }
     401             : 
     402         507 : ScDocument* ScModelObj::GetDocument() const
     403             : {
     404         507 :     if (pDocShell)
     405         507 :         return pDocShell->GetDocument();
     406           0 :     return NULL;
     407             : }
     408             : 
     409         247 : SfxObjectShell* ScModelObj::GetEmbeddedObject() const
     410             : {
     411         247 :     return pDocShell;
     412             : }
     413             : 
     414           0 : void ScModelObj::UpdateAllRowHeights()
     415             : {
     416           0 :     if (pDocShell)
     417           0 :         pDocShell->UpdateAllRowHeights(NULL);
     418           0 : }
     419             : 
     420           1 : void ScModelObj::BeforeXMLLoading()
     421             : {
     422           1 :     if (pDocShell)
     423           1 :         pDocShell->BeforeXMLLoading();
     424           1 : }
     425             : 
     426           1 : void ScModelObj::AfterXMLLoading(sal_Bool bRet)
     427             : {
     428           1 :     if (pDocShell)
     429           1 :         pDocShell->AfterXMLLoading(bRet);
     430           1 : }
     431             : 
     432        1602 : ScSheetSaveData* ScModelObj::GetSheetSaveData()
     433             : {
     434        1602 :     if (pDocShell)
     435        1602 :         return pDocShell->GetSheetSaveData();
     436           0 :     return NULL;
     437             : }
     438             : 
     439         160 : void ScModelObj::RepaintRange( const ScRange& rRange )
     440             : {
     441         160 :     if (pDocShell)
     442         160 :         pDocShell->PostPaint( rRange, PAINT_GRID );
     443         160 : }
     444             : 
     445           0 : void ScModelObj::RepaintRange( const ScRangeList& rRange )
     446             : {
     447           0 :     if (pDocShell)
     448           0 :         pDocShell->PostPaint( rRange, PAINT_GRID );
     449           0 : }
     450             : 
     451      145101 : uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
     452             :                                                 throw(uno::RuntimeException)
     453             : {
     454      145101 :     SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
     455      144248 :     SC_QUERYINTERFACE( document::XActionLockable )
     456      143648 :     SC_QUERYINTERFACE( sheet::XCalculatable )
     457      143610 :     SC_QUERYINTERFACE( util::XProtectable )
     458      143609 :     SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
     459      143585 :     SC_QUERYINTERFACE( sheet::XGoalSeek )
     460      143582 :     SC_QUERYINTERFACE( sheet::XConsolidatable )
     461      143580 :     SC_QUERYINTERFACE( sheet::XDocumentAuditing )
     462      143579 :     SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
     463      142938 :     SC_QUERYINTERFACE( view::XRenderable )
     464      142938 :     SC_QUERYINTERFACE( document::XLinkTargetSupplier )
     465      142937 :     SC_QUERYINTERFACE( beans::XPropertySet )
     466      139409 :     SC_QUERYINTERFACE( lang::XMultiServiceFactory )
     467      137157 :     SC_QUERYINTERFACE( lang::XServiceInfo )
     468      136305 :     SC_QUERYINTERFACE( util::XChangesNotifier )
     469             : 
     470      136280 :     uno::Any aRet(SfxBaseModel::queryInterface( rType ));
     471      272560 :     if ( !aRet.hasValue()
     472       19630 :         && rType != ::getCppuType((uno::Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
     473       19630 :         && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XController>*)0)
     474       14969 :         && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XFrame>*)0)
     475       10308 :         && rType != ::getCppuType((uno::Reference< com::sun::star::script::XInvocation>*)0)
     476       10038 :         && rType != ::getCppuType((uno::Reference< com::sun::star::beans::XFastPropertySet>*)0)
     477      146292 :         && rType != ::getCppuType((uno::Reference< com::sun::star::awt::XWindow>*)0))
     478             :     {
     479        6525 :         GetFormatter();
     480        6525 :         if ( xNumberAgg.is() )
     481        6525 :             aRet = xNumberAgg->queryAggregation( rType );
     482             :     }
     483             : 
     484      136280 :     return aRet;
     485             : }
     486             : 
     487      689258 : void SAL_CALL ScModelObj::acquire() throw()
     488             : {
     489      689258 :     SfxBaseModel::acquire();
     490      689258 : }
     491             : 
     492      688788 : void SAL_CALL ScModelObj::release() throw()
     493             : {
     494      688788 :     SfxBaseModel::release();
     495      688788 : }
     496             : 
     497         264 : uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException)
     498             : {
     499         264 :     static uno::Sequence<uno::Type> aTypes;
     500         264 :     if ( aTypes.getLength() == 0 )
     501             :     {
     502          26 :         uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
     503          26 :         long nParentLen = aParentTypes.getLength();
     504          26 :         const uno::Type* pParentPtr = aParentTypes.getConstArray();
     505             : 
     506          52 :         uno::Sequence<uno::Type> aAggTypes;
     507          26 :         if ( GetFormatter().is() )
     508             :         {
     509          26 :             const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0);
     510          26 :             uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
     511          26 :             if(aNumProv.getValueType() == rProvType)
     512             :             {
     513             :                 uno::Reference<lang::XTypeProvider> xNumProv(
     514          26 :                     *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
     515          26 :                 aAggTypes = xNumProv->getTypes();
     516          26 :             }
     517             :         }
     518          26 :         long nAggLen = aAggTypes.getLength();
     519          26 :         const uno::Type* pAggPtr = aAggTypes.getConstArray();
     520             : 
     521          26 :         const long nThisLen = 15;
     522          26 :         aTypes.realloc( nParentLen + nAggLen + nThisLen );
     523          26 :         uno::Type* pPtr = aTypes.getArray();
     524          26 :         pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0);
     525          26 :         pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
     526          26 :         pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0);
     527          26 :         pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0);
     528          26 :         pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0);
     529          26 :         pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0);
     530          26 :         pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0);
     531          26 :         pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0);
     532          26 :         pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0);
     533          26 :         pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0);
     534          26 :         pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0);
     535          26 :         pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
     536          26 :         pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0);
     537          26 :         pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
     538          26 :         pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XChangesNotifier>*)0);
     539             : 
     540             :         long i;
     541         910 :         for (i=0; i<nParentLen; i++)
     542         884 :             pPtr[i] = pParentPtr[i];                    // parent types first
     543             : 
     544         156 :         for (i=0; i<nAggLen; i++)
     545         156 :             pPtr[nParentLen+nThisLen+i] = pAggPtr[i];   // aggregated types last
     546             :     }
     547         264 :     return aTypes;
     548             : }
     549             : 
     550             : namespace
     551             : {
     552             :     class theScModelObjImplementationId : public rtl::Static< UnoTunnelIdInit, theScModelObjImplementationId > {};
     553             : }
     554             : 
     555         264 : uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
     556             :                                                     throw(uno::RuntimeException)
     557             : {
     558         264 :     return theScModelObjImplementationId::get().getSeq();
     559             : }
     560             : 
     561       53088 : void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     562             : {
     563             :     //  Not interested in reference update hints here
     564             : 
     565       53088 :     if ( rHint.ISA( SfxSimpleHint ) )
     566             :     {
     567       39167 :         sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
     568       39167 :         if ( nId == SFX_HINT_DYING )
     569             :         {
     570         468 :             pDocShell = NULL;       // has become invalid
     571         468 :             if (xNumberAgg.is())
     572             :             {
     573             :                 SvNumberFormatsSupplierObj* pNumFmt =
     574             :                     SvNumberFormatsSupplierObj::getImplementation(
     575         148 :                         uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
     576         148 :                 if ( pNumFmt )
     577         148 :                     pNumFmt->SetNumberFormatter( NULL );
     578             :             }
     579             : 
     580         468 :             DELETEZ( pPrintFuncCache );     // must be deleted because it has a pointer to the DocShell
     581             :         }
     582       38699 :         else if ( nId == SFX_HINT_DATACHANGED )
     583             :         {
     584             :             //  cached data for rendering become invalid when contents change
     585             :             //  (if a broadcast is added to SetDrawModified, is has to be tested here, too)
     586             : 
     587       19063 :             DELETEZ( pPrintFuncCache );
     588             : 
     589             :             // handle "OnCalculate" sheet events (search also for VBA event handlers)
     590       19063 :             if ( pDocShell )
     591             :             {
     592       19063 :                 ScDocument* pDoc = pDocShell->GetDocument();
     593       19063 :                 if ( pDoc->GetVbaEventProcessor().is() )
     594             :                 {
     595             :                     // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript
     596        4367 :                     if ( pDoc->HasAnyCalcNotification() && pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) )
     597           0 :                         HandleCalculateEvents();
     598             :                 }
     599             :                 else
     600             :                 {
     601       14696 :                     if ( pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) )
     602           0 :                         HandleCalculateEvents();
     603             :                 }
     604             :             }
     605             :         }
     606             :     }
     607       13921 :     else if ( rHint.ISA( ScPointerChangedHint ) )
     608             :     {
     609           0 :         sal_uInt16 nFlags = ((const ScPointerChangedHint&)rHint).GetFlags();
     610           0 :         if (nFlags & SC_POINTERCHANGED_NUMFMT)
     611             :         {
     612             :             //  NumberFormatter-Pointer am Uno-Objekt neu setzen
     613             : 
     614           0 :             if (GetFormatter().is())
     615             :             {
     616             :                 SvNumberFormatsSupplierObj* pNumFmt =
     617             :                     SvNumberFormatsSupplierObj::getImplementation(
     618           0 :                         uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
     619           0 :                 if ( pNumFmt && pDocShell )
     620           0 :                     pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() );
     621             :             }
     622             :         }
     623             :     }
     624             : 
     625             :     // always call parent - SfxBaseModel might need to handle the same hints again
     626       53088 :     SfxBaseModel::Notify( rBC, rHint );     // SfxBaseModel is derived from SfxListener
     627       53088 : }
     628             : 
     629             : // XSpreadsheetDocument
     630             : 
     631         930 : uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException)
     632             : {
     633         930 :     SolarMutexGuard aGuard;
     634         930 :     if (pDocShell)
     635         930 :         return new ScTableSheetsObj(pDocShell);
     636           0 :     return NULL;
     637             : }
     638             : 
     639             : // XStyleFamiliesSupplier
     640             : 
     641         641 : uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
     642             :                                                 throw(uno::RuntimeException)
     643             : {
     644         641 :     SolarMutexGuard aGuard;
     645         641 :     if (pDocShell)
     646         641 :         return new ScStyleFamiliesObj(pDocShell);
     647           0 :     return NULL;
     648             : }
     649             : 
     650             : // XRenderable
     651             : 
     652           0 : static OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
     653             : {
     654           0 :     OutputDevice* pRet = NULL;
     655           0 :     const beans::PropertyValue* pPropArray = rOptions.getConstArray();
     656           0 :     long nPropCount = rOptions.getLength();
     657           0 :     for (long i = 0; i < nPropCount; i++)
     658             :     {
     659           0 :         const beans::PropertyValue& rProp = pPropArray[i];
     660           0 :         String aPropName(rProp.Name);
     661             : 
     662           0 :         if (aPropName.EqualsAscii( SC_UNONAME_RENDERDEV ))
     663             :         {
     664           0 :             uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
     665           0 :             if ( xRenderDevice.is() )
     666             :             {
     667           0 :                 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
     668           0 :                 if ( pDevice )
     669             :                 {
     670           0 :                     pRet = pDevice->GetOutputDevice();
     671           0 :                     pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
     672             :                 }
     673           0 :             }
     674             :         }
     675           0 :     }
     676           0 :     return pRet;
     677             : }
     678             : 
     679           0 : static bool lcl_ParseTarget( const String& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
     680             :                         bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
     681             : {
     682             :     // test in same order as in SID_CURRENTCELL execute
     683             : 
     684           0 :     ScAddress aAddress;
     685           0 :     ScRangeUtil aRangeUtil;
     686             :     SCTAB nNameTab;
     687           0 :     sal_Int32 nNumeric = 0;
     688             : 
     689           0 :     bool bRangeValid = false;
     690           0 :     bool bRectValid = false;
     691             : 
     692           0 :     if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
     693             :     {
     694           0 :         bRangeValid = true;             // range reference
     695             :     }
     696           0 :     else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
     697             :     {
     698           0 :         rTargetRange = aAddress;
     699           0 :         bRangeValid = true;             // cell reference
     700             :     }
     701           0 :     else if ( aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
     702           0 :               aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
     703             :     {
     704           0 :         bRangeValid = true;             // named range or database range
     705             :     }
     706           0 :     else if ( comphelper::string::isdigitAsciiString(rTarget) &&
     707           0 :               ( nNumeric = rTarget.ToInt32() ) > 0 && nNumeric <= MAXROW+1 )
     708             :     {
     709             :         // row number is always mapped to cell A(row) on the same sheet
     710           0 :         rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab );     // target row number is 1-based
     711           0 :         bRangeValid = true;             // row number
     712             :     }
     713           0 :     else if ( pDoc->GetTable( rTarget, nNameTab ) )
     714             :     {
     715           0 :         rTargetRange = ScAddress(0,0,nNameTab);
     716           0 :         bRangeValid = true;             // sheet name
     717           0 :         rIsSheet = true;                // needs special handling (first page of the sheet)
     718             :     }
     719             :     else
     720             :     {
     721             :         // look for named drawing object
     722             : 
     723           0 :         ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     724           0 :         if ( pDrawLayer )
     725             :         {
     726           0 :             SCTAB nTabCount = pDoc->GetTableCount();
     727           0 :             for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
     728             :             {
     729           0 :                 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
     730             :                 OSL_ENSURE(pPage,"Page ?");
     731           0 :                 if (pPage)
     732             :                 {
     733           0 :                     SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
     734           0 :                     SdrObject* pObject = aIter.Next();
     735           0 :                     while (pObject && !bRangeValid)
     736             :                     {
     737           0 :                         if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
     738             :                         {
     739           0 :                             rTargetRect = pObject->GetLogicRect();              // 1/100th mm
     740           0 :                             rTargetRange = pDoc->GetRange( i, rTargetRect );    // underlying cells
     741           0 :                             bRangeValid = bRectValid = true;                    // rectangle is valid
     742             :                         }
     743           0 :                         pObject = aIter.Next();
     744           0 :                     }
     745             :                 }
     746             :             }
     747             :         }
     748             :     }
     749           0 :     if ( bRangeValid && !bRectValid )
     750             :     {
     751             :         //  get rectangle for cell range
     752           0 :         rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
     753           0 :                                        rTargetRange.aEnd.Col(),   rTargetRange.aEnd.Row(),
     754           0 :                                        rTargetRange.aStart.Tab() );
     755             :     }
     756             : 
     757           0 :     return bRangeValid;
     758             : }
     759             : 
     760           0 : bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
     761             :                                      const uno::Sequence< beans::PropertyValue >& rOptions,
     762             :                                      ScMarkData& rMark,
     763             :                                      ScPrintSelectionStatus& rStatus, String& rPagesStr ) const
     764             : {
     765             :     OSL_ENSURE( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
     766             :     OSL_ENSURE( pDocShell, "FillRenderMarkData: DocShell must be set" );
     767             : 
     768           0 :     bool bDone = false;
     769             : 
     770           0 :     uno::Reference<frame::XController> xView;
     771             : 
     772             :     // defaults when no options are passed: all sheets, include empty pages
     773           0 :     sal_Bool bSelectedSheetsOnly = false;
     774           0 :     sal_Bool bIncludeEmptyPages = true;
     775             : 
     776           0 :     bool bHasPrintContent = false;
     777           0 :     sal_Int32 nPrintContent = 0;        // all sheets / selected sheets / selected cells
     778           0 :     sal_Int32 nPrintRange = 0;          // all pages / pages
     779           0 :     OUString aPageRange;           // "pages" edit value
     780             : 
     781           0 :     for( sal_Int32 i = 0, nLen = rOptions.getLength(); i < nLen; i++ )
     782             :     {
     783           0 :         if ( rOptions[i].Name == "IsOnlySelectedSheets" )
     784             :         {
     785           0 :             rOptions[i].Value >>= bSelectedSheetsOnly;
     786             :         }
     787           0 :         else if ( rOptions[i].Name == "IsIncludeEmptyPages" )
     788             :         {
     789           0 :             rOptions[i].Value >>= bIncludeEmptyPages;
     790             :         }
     791           0 :         else if ( rOptions[i].Name == "PageRange" )
     792             :         {
     793           0 :             rOptions[i].Value >>= aPageRange;
     794             :         }
     795           0 :         else if ( rOptions[i].Name == "PrintRange" )
     796             :         {
     797           0 :             rOptions[i].Value >>= nPrintRange;
     798             :         }
     799           0 :         else if ( rOptions[i].Name == "PrintContent" )
     800             :         {
     801           0 :             bHasPrintContent = true;
     802           0 :             rOptions[i].Value >>= nPrintContent;
     803             :         }
     804           0 :         else if ( rOptions[i].Name == "View" )
     805             :         {
     806           0 :             rOptions[i].Value >>= xView;
     807             :         }
     808             :     }
     809             : 
     810             :     // "Print Content" selection wins over "Selected Sheets" option
     811           0 :     if ( bHasPrintContent )
     812           0 :         bSelectedSheetsOnly = ( nPrintContent != 0 );
     813             : 
     814           0 :     uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
     815           0 :     if ( xInterface.is() )
     816             :     {
     817           0 :         ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
     818           0 :         uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
     819           0 :         if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
     820             :         {
     821           0 :             bool bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
     822           0 :             bool bCursor = pSelObj->IsCursorOnly();
     823           0 :             const ScRangeList& rRanges = pSelObj->GetRangeList();
     824             : 
     825           0 :             rMark.MarkFromRangeList( rRanges, false );
     826           0 :             rMark.MarkToSimple();
     827             : 
     828           0 :             if ( rMark.IsMultiMarked() )
     829             :             {
     830             :                 // #i115266# copy behavior of old printing:
     831             :                 // treat multiple selection like a single selection with the enclosing range
     832           0 :                 ScRange aMultiMarkArea;
     833           0 :                 rMark.GetMultiMarkArea( aMultiMarkArea );
     834           0 :                 rMark.ResetMark();
     835           0 :                 rMark.SetMarkArea( aMultiMarkArea );
     836             :             }
     837             : 
     838           0 :             if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
     839             :             {
     840             :                 // a sheet object is treated like an empty selection: print the used area of the sheet
     841             : 
     842           0 :                 if ( bCursor || bSheet )                // nothing selected -> use whole tables
     843             :                 {
     844           0 :                     rMark.ResetMark();      // doesn't change table selection
     845           0 :                     rStatus.SetMode( SC_PRINTSEL_CURSOR );
     846             :                 }
     847             :                 else
     848           0 :                     rStatus.SetMode( SC_PRINTSEL_RANGE );
     849             : 
     850           0 :                 rStatus.SetRanges( rRanges );
     851           0 :                 bDone = true;
     852             :             }
     853             :             // multi selection isn't supported
     854             :         }
     855           0 :         else if( xShapes.is() )
     856             :         {
     857             :             //print a selected ole object
     858           0 :             uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
     859           0 :             if( xIndexAccess.is() )
     860             :             {
     861             :                 // multi selection isn't supported yet
     862           0 :                 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
     863           0 :                 SvxShape* pShape = SvxShape::getImplementation( xShape );
     864           0 :                 if( pShape )
     865             :                 {
     866           0 :                     SdrObject *pSdrObj = pShape->GetSdrObject();
     867           0 :                     if( pDocShell )
     868             :                     {
     869           0 :                         ScDocument* pDoc = pDocShell->GetDocument();
     870           0 :                         if( pDoc && pSdrObj )
     871             :                         {
     872           0 :                             Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
     873           0 :                             SCTAB nCurrentTab = ScDocShell::GetCurTab();
     874           0 :                             ScRange aRange = pDoc->GetRange( nCurrentTab, aObjRect );
     875           0 :                             rMark.SetMarkArea( aRange );
     876             : 
     877           0 :                             if( rMark.IsMarked() && !rMark.IsMultiMarked() )
     878             :                             {
     879           0 :                                 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
     880           0 :                                 bDone = true;
     881             :                             }
     882             :                         }
     883             :                     }
     884           0 :                 }
     885           0 :             }
     886             :         }
     887           0 :         else if ( ScModelObj::getImplementation( xInterface ) == this )
     888             :         {
     889             :             //  render the whole document
     890             :             //  -> no selection, all sheets
     891             : 
     892           0 :             SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
     893           0 :             for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
     894           0 :                 rMark.SelectTable( nTab, sal_True );
     895           0 :             rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
     896           0 :             bDone = true;
     897           0 :         }
     898             :         // other selection types aren't supported
     899             :     }
     900             : 
     901             :     // restrict to selected sheets if a view is available
     902           0 :     uno::Reference<sheet::XSelectedSheetsSupplier> xSelectedSheets(xView, uno::UNO_QUERY);
     903           0 :     if (bSelectedSheetsOnly && xSelectedSheets.is())
     904             :     {
     905           0 :         uno::Sequence<sal_Int32> aSelected = xSelectedSheets->getSelectedSheets();
     906           0 :         ScMarkData::MarkedTabsType aSelectedTabs;
     907           0 :         SCTAB nMaxTab = pDocShell->GetDocument()->GetTableCount() -1;
     908           0 :         for (sal_Int32 i = 0, n = aSelected.getLength(); i < n; ++i)
     909             :         {
     910           0 :             SCTAB nSelected = static_cast<SCTAB>(aSelected[i]);
     911           0 :             if (ValidTab(nSelected, nMaxTab))
     912           0 :                 aSelectedTabs.insert(static_cast<SCTAB>(aSelected[i]));
     913             :         }
     914           0 :         rMark.SetSelectedTabs(aSelectedTabs);
     915             :     }
     916             : 
     917           0 :     ScPrintOptions aNewOptions;
     918           0 :     aNewOptions.SetSkipEmpty( !bIncludeEmptyPages );
     919           0 :     aNewOptions.SetAllSheets( !bSelectedSheetsOnly );
     920           0 :     rStatus.SetOptions( aNewOptions );
     921             : 
     922             :     // "PrintRange" enables (1) or disables (0) the "PageRange" edit
     923           0 :     if ( nPrintRange == 1 )
     924           0 :         rPagesStr = aPageRange;
     925             :     else
     926           0 :         rPagesStr.Erase();
     927             : 
     928           0 :     return bDone;
     929             : }
     930             : 
     931             : 
     932           0 : sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& aSelection,
     933             :                                     const uno::Sequence<beans::PropertyValue>& rOptions )
     934             :                                 throw (lang::IllegalArgumentException, uno::RuntimeException)
     935             : {
     936           0 :     SolarMutexGuard aGuard;
     937           0 :     if (!pDocShell)
     938             :     {
     939             :         throw lang::DisposedException( OUString(),
     940           0 :                 static_cast< sheet::XSpreadsheetDocument* >(this) );
     941             :     }
     942             : 
     943           0 :     ScMarkData aMark;
     944           0 :     ScPrintSelectionStatus aStatus;
     945           0 :     String aPagesStr;
     946           0 :     if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
     947           0 :         return 0;
     948             : 
     949             :     //  The same ScPrintFuncCache object in pPrintFuncCache is used as long as
     950             :     //  the same selection is used (aStatus) and the document isn't changed
     951             :     //  (pPrintFuncCache is cleared in Notify handler)
     952             : 
     953           0 :     if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
     954             :     {
     955           0 :         delete pPrintFuncCache;
     956           0 :         pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
     957             :     }
     958           0 :     sal_Int32 nPages = pPrintFuncCache->GetPageCount();
     959             : 
     960           0 :     sal_Int32 nSelectCount = nPages;
     961           0 :     if ( aPagesStr.Len() )
     962             :     {
     963           0 :         StringRangeEnumerator aRangeEnum( aPagesStr, 0, nPages-1 );
     964           0 :         nSelectCount = aRangeEnum.size();
     965             :     }
     966           0 :     return nSelectCount;
     967             : }
     968             : 
     969           0 : static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const String& rPagesStr, sal_Int32 nTotalPages )
     970             : {
     971           0 :     if ( !rPagesStr.Len() )
     972           0 :         return nSelRenderer;
     973             : 
     974           0 :     StringRangeEnumerator aRangeEnum( rPagesStr, 0, nTotalPages-1 );
     975           0 :     StringRangeEnumerator::Iterator aIter = aRangeEnum.begin();
     976           0 :     StringRangeEnumerator::Iterator aEnd  = aRangeEnum.end();
     977           0 :     for ( ; nSelRenderer > 0 && aIter != aEnd; --nSelRenderer )
     978           0 :         ++aIter;
     979             : 
     980           0 :     return *aIter; // returns -1 if reached the end
     981             : }
     982             : 
     983           0 : uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nSelRenderer,
     984             :                                     const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& rOptions  )
     985             :                                 throw (lang::IllegalArgumentException, uno::RuntimeException)
     986             : {
     987           0 :     SolarMutexGuard aGuard;
     988           0 :     if (!pDocShell)
     989             :     {
     990             :         throw lang::DisposedException( OUString(),
     991           0 :                 static_cast< sheet::XSpreadsheetDocument* >(this) );
     992             :     }
     993             : 
     994           0 :     ScMarkData aMark;
     995           0 :     ScPrintSelectionStatus aStatus;
     996           0 :     String aPagesStr;
     997             :     // #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
     998           0 :     long nTotalPages = 0;
     999           0 :     if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
    1000             :     {
    1001           0 :         if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
    1002             :         {
    1003           0 :             delete pPrintFuncCache;
    1004           0 :             pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
    1005             :         }
    1006           0 :         nTotalPages = pPrintFuncCache->GetPageCount();
    1007             :     }
    1008           0 :     sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
    1009           0 :     if ( nRenderer < 0 )
    1010             :     {
    1011           0 :         if ( nSelRenderer == 0 )
    1012             :         {
    1013             :             // getRenderer(0) is used to query the settings, so it must always return something
    1014             : 
    1015           0 :             SCTAB nCurTab = 0;      //! use current sheet from view?
    1016           0 :             ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
    1017           0 :             Size aTwips = aDefaultFunc.GetPageSize();
    1018           0 :             awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
    1019             : 
    1020           0 :             uno::Sequence<beans::PropertyValue> aSequence(1);
    1021           0 :             beans::PropertyValue* pArray = aSequence.getArray();
    1022           0 :             pArray[0].Name = OUString( SC_UNONAME_PAGESIZE );
    1023           0 :             pArray[0].Value <<= aPageSize;
    1024             : 
    1025           0 :             if( ! pPrinterOptions )
    1026           0 :                 pPrinterOptions = new ScPrintUIOptions;
    1027             :             else
    1028           0 :                 pPrinterOptions->SetDefaults();
    1029           0 :             pPrinterOptions->appendPrintUIOptions( aSequence );
    1030           0 :             return aSequence;
    1031             :         }
    1032             :         else
    1033           0 :             throw lang::IllegalArgumentException();
    1034             :     }
    1035             : 
    1036             :     //  printer is used as device (just for page layout), draw view is not needed
    1037             : 
    1038           0 :     SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
    1039             : 
    1040           0 :     ScRange aRange;
    1041           0 :     const ScRange* pSelRange = NULL;
    1042           0 :     if ( aMark.IsMarked() )
    1043             :     {
    1044           0 :         aMark.GetMarkArea( aRange );
    1045           0 :         pSelRange = &aRange;
    1046             :     }
    1047             :     ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
    1048           0 :                         pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
    1049           0 :     aFunc.SetRenderFlag( sal_True );
    1050             : 
    1051           0 :     Range aPageRange( nRenderer+1, nRenderer+1 );
    1052           0 :     MultiSelection aPage( aPageRange );
    1053           0 :     aPage.SetTotalRange( Range(0,RANGE_MAX) );
    1054           0 :     aPage.Select( aPageRange );
    1055             : 
    1056           0 :     long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
    1057           0 :     long nTabStart = pPrintFuncCache->GetTabStart( nTab );
    1058             : 
    1059           0 :     (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, NULL );
    1060             : 
    1061           0 :     ScRange aCellRange;
    1062           0 :     sal_Bool bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
    1063           0 :     Size aTwips = aFunc.GetPageSize();
    1064           0 :     awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
    1065             : 
    1066           0 :     long nPropCount = bWasCellRange ? 3 : 2;
    1067           0 :     uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
    1068           0 :     beans::PropertyValue* pArray = aSequence.getArray();
    1069           0 :     pArray[0].Name = OUString( SC_UNONAME_PAGESIZE );
    1070           0 :     pArray[0].Value <<= aPageSize;
    1071             :     // #i111158# all positions are relative to the whole page, including non-printable area
    1072           0 :     pArray[1].Name = OUString( SC_UNONAME_INC_NP_AREA );
    1073           0 :     pArray[1].Value = uno::makeAny( sal_True );
    1074           0 :     if ( bWasCellRange )
    1075             :     {
    1076             :         table::CellRangeAddress aRangeAddress( nTab,
    1077           0 :                         aCellRange.aStart.Col(), aCellRange.aStart.Row(),
    1078           0 :                         aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
    1079           0 :         pArray[2].Name = OUString( SC_UNONAME_SOURCERANGE );
    1080           0 :         pArray[2].Value <<= aRangeAddress;
    1081             :     }
    1082             : 
    1083           0 :     if( ! pPrinterOptions )
    1084           0 :         pPrinterOptions = new ScPrintUIOptions;
    1085             :     else
    1086           0 :         pPrinterOptions->SetDefaults();
    1087           0 :     pPrinterOptions->appendPrintUIOptions( aSequence );
    1088           0 :     return aSequence;
    1089             : }
    1090             : 
    1091           0 : void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelection,
    1092             :                                     const uno::Sequence<beans::PropertyValue>& rOptions )
    1093             :                                 throw(lang::IllegalArgumentException, uno::RuntimeException)
    1094             : {
    1095           0 :     SolarMutexGuard aGuard;
    1096           0 :     if (!pDocShell)
    1097             :     {
    1098             :         throw lang::DisposedException( OUString(),
    1099           0 :                 static_cast< sheet::XSpreadsheetDocument* >(this) );
    1100             :     }
    1101             : 
    1102           0 :     ScMarkData aMark;
    1103           0 :     ScPrintSelectionStatus aStatus;
    1104           0 :     String aPagesStr;
    1105           0 :     if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
    1106           0 :         throw lang::IllegalArgumentException();
    1107             : 
    1108           0 :     if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
    1109             :     {
    1110           0 :         delete pPrintFuncCache;
    1111           0 :         pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
    1112             :     }
    1113           0 :     long nTotalPages = pPrintFuncCache->GetPageCount();
    1114           0 :     sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
    1115           0 :     if ( nRenderer < 0 )
    1116           0 :         throw lang::IllegalArgumentException();
    1117             : 
    1118           0 :     OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
    1119           0 :     if ( !pDev )
    1120           0 :         throw lang::IllegalArgumentException();
    1121             : 
    1122           0 :     SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
    1123           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1124             : 
    1125           0 :     FmFormView* pDrawView = NULL;
    1126             : 
    1127             :     // #114135#
    1128           0 :     ScDrawLayer* pModel = pDoc->GetDrawLayer();
    1129             : 
    1130           0 :     if( pModel )
    1131             :     {
    1132           0 :         pDrawView = new FmFormView( pModel, pDev );
    1133           0 :         pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
    1134           0 :         pDrawView->SetPrintPreview( sal_True );
    1135             :     }
    1136             : 
    1137           0 :     ScRange aRange;
    1138           0 :     const ScRange* pSelRange = NULL;
    1139           0 :     if ( aMark.IsMarked() )
    1140             :     {
    1141           0 :         aMark.GetMarkArea( aRange );
    1142           0 :         pSelRange = &aRange;
    1143             :     }
    1144             : 
    1145             :     //  to increase performance, ScPrintState might be used here for subsequent
    1146             :     //  pages of the same sheet
    1147             : 
    1148           0 :     ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
    1149           0 :     aFunc.SetDrawView( pDrawView );
    1150           0 :     aFunc.SetRenderFlag( sal_True );
    1151           0 :     if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
    1152           0 :         aFunc.SetExclusivelyDrawOleAndDrawObjects();
    1153             : 
    1154           0 :     Range aPageRange( nRenderer+1, nRenderer+1 );
    1155           0 :     MultiSelection aPage( aPageRange );
    1156           0 :     aPage.SetTotalRange( Range(0,RANGE_MAX) );
    1157           0 :     aPage.Select( aPageRange );
    1158             : 
    1159           0 :     long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
    1160           0 :     long nTabStart = pPrintFuncCache->GetTabStart( nTab );
    1161             : 
    1162           0 :     vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
    1163           0 :     if ( nRenderer == nTabStart )
    1164             :     {
    1165             :         // first page of a sheet: add outline item for the sheet name
    1166             : 
    1167           0 :         if ( pPDFData && pPDFData->GetIsExportBookmarks() )
    1168             :         {
    1169             :             // the sheet starts at the top of the page
    1170           0 :             Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
    1171           0 :             sal_Int32 nDestID = pPDFData->CreateDest( aArea );
    1172           0 :             OUString aTabName;
    1173           0 :             pDoc->GetName( nTab, aTabName );
    1174           0 :             sal_Int32 nParent = -1;     // top-level
    1175           0 :             pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
    1176             :         }
    1177             :         // #i56629# add the named destination stuff
    1178           0 :         if( pPDFData && pPDFData->GetIsExportNamedDestinations() )
    1179             :         {
    1180           0 :             Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
    1181           0 :             OUString aTabName;
    1182           0 :             pDoc->GetName( nTab, aTabName );
    1183             :             //need the PDF page number here
    1184           0 :             pPDFData->CreateNamedDest( aTabName, aArea );
    1185             :         }
    1186             :     }
    1187             : 
    1188           0 :     (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, true, NULL );
    1189             : 
    1190             :     //  resolve the hyperlinks for PDF export
    1191             : 
    1192           0 :     if ( pPDFData )
    1193             :     {
    1194             :         //  iterate over the hyperlinks that were output for this page
    1195             : 
    1196           0 :         std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
    1197           0 :         std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
    1198           0 :         std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
    1199           0 :         while ( aIter != aIEnd )
    1200             :         {
    1201           0 :             OUString aBookmark = aIter->aBookmark;
    1202           0 :             if ( aBookmark.toChar() == (sal_Unicode) '#' )
    1203             :             {
    1204             :                 //  try to resolve internal link
    1205             : 
    1206           0 :                 String aTarget( aBookmark.copy( 1 ) );
    1207             : 
    1208           0 :                 ScRange aTargetRange;
    1209           0 :                 Rectangle aTargetRect;      // 1/100th mm
    1210           0 :                 bool bIsSheet = false;
    1211           0 :                 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, pDoc, nTab );
    1212             : 
    1213           0 :                 if ( bValid )
    1214             :                 {
    1215           0 :                     sal_Int32 nPage = -1;
    1216           0 :                     Rectangle aArea;
    1217           0 :                     if ( bIsSheet )
    1218             :                     {
    1219             :                         //  Get first page for sheet (if nothing from that sheet is printed,
    1220             :                         //  this page can show a different sheet)
    1221           0 :                         nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
    1222           0 :                         aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
    1223             :                     }
    1224             :                     else
    1225             :                     {
    1226           0 :                         pPrintFuncCache->InitLocations( aMark, pDev );      // does nothing if already initialized
    1227             : 
    1228           0 :                         ScPrintPageLocation aLocation;
    1229           0 :                         if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
    1230             :                         {
    1231           0 :                             nPage = aLocation.nPage;
    1232             : 
    1233             :                             // get the rectangle of the page's cell range in 1/100th mm
    1234           0 :                             ScRange aLocRange = aLocation.aCellRange;
    1235             :                             Rectangle aLocationMM = pDoc->GetMMRect(
    1236           0 :                                        aLocRange.aStart.Col(), aLocRange.aStart.Row(),
    1237           0 :                                        aLocRange.aEnd.Col(),   aLocRange.aEnd.Row(),
    1238           0 :                                        aLocRange.aStart.Tab() );
    1239           0 :                             Rectangle aLocationPixel = aLocation.aRectangle;
    1240             : 
    1241             :                             // Scale and move the target rectangle from aLocationMM to aLocationPixel,
    1242             :                             // to get the target rectangle in pixels.
    1243             : 
    1244           0 :                             Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
    1245           0 :                             Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
    1246             : 
    1247           0 :                             long nX1 = aLocationPixel.Left() + (long)
    1248           0 :                                 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
    1249           0 :                             long nX2 = aLocationPixel.Left() + (long)
    1250           0 :                                 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
    1251           0 :                             long nY1 = aLocationPixel.Top() + (long)
    1252           0 :                                 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
    1253           0 :                             long nY2 = aLocationPixel.Top() + (long)
    1254           0 :                                 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
    1255             : 
    1256           0 :                             if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
    1257           0 :                             if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
    1258           0 :                             if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
    1259           0 :                             if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
    1260             : 
    1261             :                             // The link target area is interpreted using the device's MapMode at
    1262             :                             // the time of the CreateDest call, so PixelToLogic can be used here,
    1263             :                             // regardless of the MapMode that is actually selected.
    1264             : 
    1265           0 :                             aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
    1266             :                         }
    1267             :                     }
    1268             : 
    1269           0 :                     if ( nPage >= 0 )
    1270           0 :                         pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
    1271           0 :                 }
    1272             :             }
    1273             :             else
    1274             :             {
    1275             :                 //  external link, use as-is
    1276           0 :                 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
    1277             :             }
    1278           0 :             ++aIter;
    1279           0 :         }
    1280           0 :         rBookmarks.clear();
    1281             :     }
    1282             : 
    1283           0 :     if ( pDrawView )
    1284           0 :         pDrawView->HideSdrPage();
    1285           0 :     delete pDrawView;
    1286           0 : }
    1287             : 
    1288             : // XLinkTargetSupplier
    1289             : 
    1290           1 : uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException)
    1291             : {
    1292           1 :     SolarMutexGuard aGuard;
    1293           1 :     if (pDocShell)
    1294           1 :         return new ScLinkTargetTypesObj(pDocShell);
    1295           0 :     return NULL;
    1296             : }
    1297             : 
    1298             : // XActionLockable
    1299             : 
    1300           3 : sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException)
    1301             : {
    1302           3 :     SolarMutexGuard aGuard;
    1303           3 :     sal_Bool bLocked = false;
    1304           3 :     if (pDocShell)
    1305           3 :         bLocked = ( pDocShell->GetLockCount() != 0 );
    1306           3 :     return bLocked;
    1307             : }
    1308             : 
    1309         304 : void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException)
    1310             : {
    1311         304 :     SolarMutexGuard aGuard;
    1312         304 :     if (pDocShell)
    1313         304 :         pDocShell->LockDocument();
    1314         304 : }
    1315             : 
    1316         298 : void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException)
    1317             : {
    1318         298 :     SolarMutexGuard aGuard;
    1319         298 :     if (pDocShell)
    1320         298 :         pDocShell->UnlockDocument();
    1321         298 : }
    1322             : 
    1323           1 : void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
    1324             : {
    1325           1 :     SolarMutexGuard aGuard;
    1326           1 :     if (pDocShell)
    1327           1 :         pDocShell->SetLockCount(nLock);
    1328           1 : }
    1329             : 
    1330           1 : sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException)
    1331             : {
    1332           1 :     SolarMutexGuard aGuard;
    1333           1 :     sal_uInt16 nRet = 0;
    1334           1 :     if (pDocShell)
    1335             :     {
    1336           1 :         nRet = pDocShell->GetLockCount();
    1337           1 :         pDocShell->SetLockCount(0);
    1338             :     }
    1339           1 :     return nRet;
    1340             : }
    1341             : 
    1342          34 : void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException)
    1343             : {
    1344          34 :     SolarMutexGuard aGuard;
    1345          34 :     SfxBaseModel::lockControllers();
    1346          34 :     if (pDocShell)
    1347          34 :         pDocShell->LockPaint();
    1348          34 : }
    1349             : 
    1350          59 : void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException)
    1351             : {
    1352          59 :     SolarMutexGuard aGuard;
    1353          59 :     if (hasControllersLocked())
    1354             :     {
    1355          34 :         SfxBaseModel::unlockControllers();
    1356          34 :         if (pDocShell)
    1357          34 :             pDocShell->UnlockPaint();
    1358          59 :     }
    1359          59 : }
    1360             : 
    1361             : // XCalculate
    1362             : 
    1363           4 : void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException)
    1364             : {
    1365           4 :     SolarMutexGuard aGuard;
    1366           4 :     if (pDocShell)
    1367           4 :         pDocShell->DoRecalc(sal_True);
    1368             :     else
    1369             :     {
    1370             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1371           4 :     }
    1372           4 : }
    1373             : 
    1374           4 : void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException)
    1375             : {
    1376           4 :     SolarMutexGuard aGuard;
    1377           4 :     if (pDocShell)
    1378           4 :         pDocShell->DoHardRecalc(sal_True);
    1379             :     else
    1380             :     {
    1381             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1382           4 :     }
    1383           4 : }
    1384             : 
    1385           9 : sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException)
    1386             : {
    1387           9 :     SolarMutexGuard aGuard;
    1388           9 :     if (pDocShell)
    1389           9 :         return pDocShell->GetDocument()->GetAutoCalc();
    1390             : 
    1391             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1392           0 :     return false;
    1393             : }
    1394             : 
    1395          28 : void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabledIn )
    1396             :                                                 throw(uno::RuntimeException)
    1397             : {
    1398          28 :     bool bEnabled(bEnabledIn);
    1399          28 :     SolarMutexGuard aGuard;
    1400          28 :     if (pDocShell)
    1401             :     {
    1402          28 :         ScDocument* pDoc = pDocShell->GetDocument();
    1403          28 :         if ( pDoc->GetAutoCalc() != bEnabled )
    1404             :         {
    1405           6 :             pDoc->SetAutoCalc( bEnabled );
    1406           6 :             pDocShell->SetDocumentModified();
    1407             :         }
    1408             :     }
    1409             :     else
    1410             :     {
    1411             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1412          28 :     }
    1413          28 : }
    1414             : 
    1415             : // XProtectable
    1416             : 
    1417           1 : void SAL_CALL ScModelObj::protect( const OUString& aPassword ) throw(uno::RuntimeException)
    1418             : {
    1419           1 :     SolarMutexGuard aGuard;
    1420             :     // #i108245# if already protected, don't change anything
    1421           1 :     if ( pDocShell && !pDocShell->GetDocument()->IsDocProtected() )
    1422             :     {
    1423           1 :         String aString(aPassword);
    1424           1 :         pDocShell->GetDocFunc().Protect( TABLEID_DOC, aString, sal_True );
    1425           1 :     }
    1426           1 : }
    1427             : 
    1428           2 : void SAL_CALL ScModelObj::unprotect( const OUString& aPassword )
    1429             :                         throw(lang::IllegalArgumentException, uno::RuntimeException)
    1430             : {
    1431           2 :     SolarMutexGuard aGuard;
    1432           2 :     if (pDocShell)
    1433             :     {
    1434           2 :         String aString(aPassword);
    1435           2 :         sal_Bool bDone = pDocShell->GetDocFunc().Unprotect( TABLEID_DOC, aString, sal_True );
    1436           2 :         if (!bDone)
    1437           1 :             throw lang::IllegalArgumentException();
    1438           2 :     }
    1439           1 : }
    1440             : 
    1441           3 : sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException)
    1442             : {
    1443           3 :     SolarMutexGuard aGuard;
    1444           3 :     if (pDocShell)
    1445           3 :         return pDocShell->GetDocument()->IsDocProtected();
    1446             : 
    1447             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1448           0 :     return false;
    1449             : }
    1450             : 
    1451             : // XDrawPagesSupplier
    1452             : 
    1453          25 : uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException)
    1454             : {
    1455          25 :     SolarMutexGuard aGuard;
    1456          25 :     if (pDocShell)
    1457          25 :         return new ScDrawPagesObj(pDocShell);
    1458             : 
    1459             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1460           0 :     return NULL;
    1461             : }
    1462             : 
    1463             : // XGoalSeek
    1464             : 
    1465           5 : sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
    1466             :                                 const table::CellAddress& aFormulaPosition,
    1467             :                                 const table::CellAddress& aVariablePosition,
    1468             :                                 const OUString& aGoalValue )
    1469             :                                     throw(uno::RuntimeException)
    1470             : {
    1471           5 :     SolarMutexGuard aGuard;
    1472           5 :     sheet::GoalResult aResult;
    1473           5 :     aResult.Divergence = DBL_MAX;       // nichts gefunden
    1474           5 :     if (pDocShell)
    1475             :     {
    1476           5 :         WaitObject aWait( pDocShell->GetActiveDialogParent() );
    1477          10 :         String aGoalString(aGoalValue);
    1478           5 :         ScDocument* pDoc = pDocShell->GetDocument();
    1479           5 :         double fValue = 0.0;
    1480             :         sal_Bool bFound = pDoc->Solver(
    1481             :                     (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
    1482             :                     (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
    1483           5 :                     aGoalString, fValue );
    1484           5 :         aResult.Result = fValue;
    1485           5 :         if (bFound)
    1486           9 :             aResult.Divergence = 0.0;   //! das ist gelogen
    1487             :     }
    1488           5 :     return aResult;
    1489             : }
    1490             : 
    1491             : // XConsolidatable
    1492             : 
    1493           2 : uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
    1494             :                                 sal_Bool bEmpty ) throw(uno::RuntimeException)
    1495             : {
    1496           2 :     SolarMutexGuard aGuard;
    1497           2 :     ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
    1498           2 :     if ( pDocShell && !bEmpty )
    1499             :     {
    1500           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1501           0 :         const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData();
    1502           0 :         if (pParam)
    1503           0 :             pNew->SetParam( *pParam );
    1504             :     }
    1505           2 :     return pNew;
    1506             : }
    1507             : 
    1508           1 : void SAL_CALL ScModelObj::consolidate(
    1509             :         const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
    1510             :                                                 throw(uno::RuntimeException)
    1511             : {
    1512           1 :     SolarMutexGuard aGuard;
    1513             :     //  das koennte theoretisch ein fremdes Objekt sein, also nur das
    1514             :     //  oeffentliche XConsolidationDescriptor Interface benutzen, um
    1515             :     //  die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
    1516             :     //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
    1517             : 
    1518           2 :     ScConsolidationDescriptor aImpl;
    1519           1 :     aImpl.setFunction( xDescriptor->getFunction() );
    1520           1 :     aImpl.setSources( xDescriptor->getSources() );
    1521           1 :     aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
    1522           1 :     aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
    1523           1 :     aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
    1524           1 :     aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
    1525             : 
    1526           1 :     if (pDocShell)
    1527             :     {
    1528           1 :         const ScConsolidateParam& rParam = aImpl.GetParam();
    1529           1 :         pDocShell->DoConsolidate( rParam, sal_True );
    1530           1 :         pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
    1531           1 :     }
    1532           1 : }
    1533             : 
    1534             : // XDocumentAuditing
    1535             : 
    1536           1 : void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException)
    1537             : {
    1538           1 :     SolarMutexGuard aGuard;
    1539           1 :     if (pDocShell)
    1540           1 :         pDocShell->GetDocFunc().DetectiveRefresh();
    1541           1 : }
    1542             : 
    1543             : // XViewDataSupplier
    1544         506 : uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData(  )
    1545             :     throw (uno::RuntimeException)
    1546             : {
    1547         506 :     uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
    1548             : 
    1549         506 :     if( !xRet.is() )
    1550             :     {
    1551         184 :         SolarMutexGuard aGuard;
    1552         184 :         if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
    1553             :         {
    1554           6 :             uno::Reference < container::XIndexContainer > xCont = document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() );
    1555           6 :             xRet.set( xCont, uno::UNO_QUERY_THROW );
    1556             : 
    1557          12 :             uno::Sequence< beans::PropertyValue > aSeq;
    1558           6 :             aSeq.realloc(1);
    1559          12 :             OUString sName;
    1560           6 :             pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
    1561          12 :             OUString sOUName(sName);
    1562           6 :             aSeq[0].Name = OUString(SC_ACTIVETABLE);
    1563           6 :             aSeq[0].Value <<= sOUName;
    1564          12 :             xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
    1565         184 :         }
    1566             :     }
    1567             : 
    1568         506 :     return xRet;
    1569             : }
    1570             : 
    1571             : //  XPropertySet (Doc-Optionen)
    1572             : //! auch an der Applikation anbieten?
    1573             : 
    1574         713 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
    1575             :                                                         throw(uno::RuntimeException)
    1576             : {
    1577         713 :     SolarMutexGuard aGuard;
    1578             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    1579         713 :         new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
    1580         713 :     return aRef;
    1581             : }
    1582             : 
    1583        1412 : void SAL_CALL ScModelObj::setPropertyValue(
    1584             :                         const OUString& aPropertyName, const uno::Any& aValue )
    1585             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
    1586             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
    1587             :                         uno::RuntimeException)
    1588             : {
    1589        1412 :     SolarMutexGuard aGuard;
    1590        2824 :     String aString(aPropertyName);
    1591             : 
    1592        1412 :     if (pDocShell)
    1593             :     {
    1594        1412 :         ScDocument* pDoc = pDocShell->GetDocument();
    1595        1412 :         const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
    1596        1412 :         ScDocOptions aNewOpt = rOldOpt;
    1597             :         //  Don't recalculate while loading XML, when the formula text is stored
    1598             :         //  Recalculation after loading is handled separately.
    1599        1412 :         bool bHardRecalc = !pDoc->IsImportingXML();
    1600             : 
    1601        1412 :         sal_Bool bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropSet.getPropertyMap(), aPropertyName, aValue );
    1602        1412 :         if (bOpt)
    1603             :         {
    1604             :             // done...
    1605        2631 :             if ( aString.EqualsAscii( SC_UNO_IGNORECASE ) ||
    1606        1618 :                  aString.EqualsAscii( SC_UNONAME_REGEXP ) ||
    1607         707 :                  aString.EqualsAscii( SC_UNO_LOOKUPLABELS ) )
    1608         306 :                 bHardRecalc = false;
    1609             :         }
    1610         501 :         else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
    1611             :         {
    1612           6 :             lang::Locale aLocale;
    1613           6 :             if ( aValue >>= aLocale )
    1614             :             {
    1615             :                 LanguageType eLatin, eCjk, eCtl;
    1616           6 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1617           6 :                 eLatin = ScUnoConversion::GetLanguage(aLocale);
    1618           6 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1619           6 :             }
    1620             :         }
    1621         495 :         else if ( aString.EqualsAscii( SC_UNO_CODENAME ) )
    1622             :         {
    1623          25 :             OUString sCodeName;
    1624          25 :             if ( aValue >>= sCodeName )
    1625          25 :                 pDoc->SetCodeName( sCodeName );
    1626             :         }
    1627         470 :         else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
    1628             :         {
    1629           6 :             lang::Locale aLocale;
    1630           6 :             if ( aValue >>= aLocale )
    1631             :             {
    1632             :                 LanguageType eLatin, eCjk, eCtl;
    1633           6 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1634           6 :                 eCjk = ScUnoConversion::GetLanguage(aLocale);
    1635           6 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1636           6 :             }
    1637             :         }
    1638         464 :         else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
    1639             :         {
    1640           6 :             lang::Locale aLocale;
    1641           6 :             if ( aValue >>= aLocale )
    1642             :             {
    1643             :                 LanguageType eLatin, eCjk, eCtl;
    1644           6 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1645           6 :                 eCtl = ScUnoConversion::GetLanguage(aLocale);
    1646           6 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1647           6 :             }
    1648             :         }
    1649         458 :         else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
    1650             :         {
    1651             :             //  model is created if not there
    1652          90 :             ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
    1653          90 :             pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1654             : 
    1655          90 :             SfxBindings* pBindings = pDocShell->GetViewBindings();
    1656          90 :             if (pBindings)
    1657           5 :                 pBindings->Invalidate( SID_FM_OPEN_READONLY );
    1658             :         }
    1659         368 :         else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
    1660             :         {
    1661             :             //  model is created if not there
    1662          23 :             ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
    1663          23 :             pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1664             : 
    1665          23 :             SfxBindings* pBindings = pDocShell->GetViewBindings();
    1666          23 :             if (pBindings)
    1667           5 :                 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
    1668             :         }
    1669         345 :         else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
    1670             :         {
    1671          25 :             pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1672             :         }
    1673         320 :         else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
    1674             :         {
    1675          46 :             sal_Bool bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    1676          46 :             pDoc->EnableUndo( bUndoEnabled );
    1677          46 :             pDocShell->GetUndoManager()->SetMaxUndoActionCount(
    1678             :                 bUndoEnabled
    1679          46 :                 ? officecfg::Office::Common::Undo::Steps::get() : 0);
    1680             :         }
    1681         274 :         else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
    1682             :         {
    1683          46 :             bool bOldAdjustHeightEnabled = pDoc->IsAdjustHeightEnabled();
    1684          46 :             bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    1685          46 :             if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
    1686          46 :                 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
    1687             :         }
    1688         228 :         else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
    1689             :         {
    1690          46 :             pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1691             :         }
    1692         182 :         else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
    1693             :         {
    1694          46 :             pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1695             :         }
    1696         136 :         else if ( aString.EqualsAscii( "BuildId" ) )
    1697             :         {
    1698          79 :             aValue >>= maBuildId;
    1699             :         }
    1700          57 :         else if ( aString.EqualsAscii( "SavedObject" ) )    // set from chart after saving
    1701             :         {
    1702           1 :             OUString aObjName;
    1703           1 :             aValue >>= aObjName;
    1704           1 :             if ( !aObjName.isEmpty() )
    1705           1 :                 pDoc->RestoreChartListener( aObjName );
    1706             :         }
    1707             : 
    1708        1412 :         if ( aNewOpt != rOldOpt )
    1709             :         {
    1710         157 :             pDoc->SetDocOptions( aNewOpt );
    1711             :             //! Recalc only for options that need it?
    1712         157 :             if ( bHardRecalc )
    1713          59 :                 pDocShell->DoHardRecalc( sal_True );
    1714         157 :             pDocShell->SetDocumentModified();
    1715        1412 :         }
    1716        1412 :     }
    1717        1412 : }
    1718             : 
    1719        3455 : uno::Any SAL_CALL ScModelObj::getPropertyValue( const OUString& aPropertyName )
    1720             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    1721             :                         uno::RuntimeException)
    1722             : {
    1723        3455 :     SolarMutexGuard aGuard;
    1724        6910 :     String aString(aPropertyName);
    1725        3455 :     uno::Any aRet;
    1726             : 
    1727        3455 :     if (pDocShell)
    1728             :     {
    1729        3455 :         ScDocument* pDoc = pDocShell->GetDocument();
    1730        3455 :         const ScDocOptions& rOpt = pDoc->GetDocOptions();
    1731        3455 :         aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropSet.getPropertyMap(), aPropertyName );
    1732        3455 :         if ( aRet.hasValue() )
    1733             :         {
    1734             :             // done...
    1735             :         }
    1736        3223 :         else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
    1737             :         {
    1738             :             LanguageType eLatin, eCjk, eCtl;
    1739          14 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1740             : 
    1741          14 :             lang::Locale aLocale;
    1742          14 :             ScUnoConversion::FillLocale( aLocale, eLatin );
    1743          14 :             aRet <<= aLocale;
    1744             :         }
    1745        3209 :         else if ( aString.EqualsAscii( SC_UNO_CODENAME ) )
    1746             :         {
    1747         282 :             OUString sCodeName = pDoc->GetCodeName();
    1748         282 :             aRet <<= sCodeName;
    1749             :         }
    1750             : 
    1751        2927 :         else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
    1752             :         {
    1753             :             LanguageType eLatin, eCjk, eCtl;
    1754          14 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1755             : 
    1756          14 :             lang::Locale aLocale;
    1757          14 :             ScUnoConversion::FillLocale( aLocale, eCjk );
    1758          14 :             aRet <<= aLocale;
    1759             :         }
    1760        2913 :         else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
    1761             :         {
    1762             :             LanguageType eLatin, eCjk, eCtl;
    1763          14 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1764             : 
    1765          14 :             lang::Locale aLocale;
    1766          14 :             ScUnoConversion::FillLocale( aLocale, eCtl );
    1767          14 :             aRet <<= aLocale;
    1768             :         }
    1769        2899 :         else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) )
    1770             :         {
    1771        1455 :             aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
    1772             :         }
    1773        1444 :         else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) )
    1774             :         {
    1775          21 :             aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
    1776             :         }
    1777        1423 :         else if ( aString.EqualsAscii( SC_UNO_UNNAMEDDBRNG ) )
    1778             :         {
    1779          13 :             aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
    1780             :         }
    1781        1410 :         else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) )
    1782             :         {
    1783          15 :             aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, sal_True ));
    1784             :         }
    1785        1395 :         else if ( aString.EqualsAscii( SC_UNO_ROWLABELRNG ) )
    1786             :         {
    1787          12 :             aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, false ));
    1788             :         }
    1789        1383 :         else if ( aString.EqualsAscii( SC_UNO_AREALINKS ) )
    1790             :         {
    1791          29 :             aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
    1792             :         }
    1793        1354 :         else if ( aString.EqualsAscii( SC_UNO_DDELINKS ) )
    1794             :         {
    1795          15 :             aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
    1796             :         }
    1797        1339 :         else if ( aString.EqualsAscii( SC_UNO_EXTERNALDOCLINKS ) )
    1798             :         {
    1799           2 :             aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
    1800             :         }
    1801        1337 :         else if ( aString.EqualsAscii( SC_UNO_SHEETLINKS ) )
    1802             :         {
    1803           6 :             aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
    1804             :         }
    1805        1331 :         else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
    1806             :         {
    1807             :             // default for no model is TRUE
    1808          12 :             ScDrawLayer* pModel = pDoc->GetDrawLayer();
    1809          12 :             sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
    1810          12 :             ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
    1811             :         }
    1812        1319 :         else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
    1813             :         {
    1814             :             // default for no model is FALSE
    1815          12 :             ScDrawLayer* pModel = pDoc->GetDrawLayer();
    1816          12 :             sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : false;
    1817          12 :             ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
    1818             :         }
    1819        1307 :         else if ( aString.EqualsAscii( SC_UNO_FORBIDDEN ) )
    1820             :         {
    1821           4 :             aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
    1822             :         }
    1823        1303 :         else if ( aString.EqualsAscii( SC_UNO_HASDRAWPAGES ) )
    1824             :         {
    1825           4 :             ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
    1826             :         }
    1827        1299 :         else if ( aString.EqualsAscii( SC_UNO_BASICLIBRARIES ) )
    1828             :         {
    1829         143 :             aRet <<= pDocShell->GetBasicContainer();
    1830             :         }
    1831        1156 :         else if ( aString.EqualsAscii( SC_UNO_DIALOGLIBRARIES ) )
    1832             :         {
    1833           2 :             aRet <<= pDocShell->GetDialogContainer();
    1834             :         }
    1835        1154 :         else if ( aString.EqualsAscii( SC_UNO_VBAGLOBNAME ) )
    1836             :         {
    1837             :             /*  #i111553# This property provides the name of the constant that
    1838             :                 will be used to store this model in the global Basic manager.
    1839             :                 That constant will be equivelant to 'ThisComponent' but for
    1840             :                 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
    1841             :                 constant can co-exist, as required by VBA. */
    1842           0 :             aRet <<= OUString( "ThisExcelDoc" );
    1843             :         }
    1844        1154 :         else if ( aString.EqualsAscii( SC_UNO_RUNTIMEUID ) )
    1845             :         {
    1846         485 :             aRet <<= getRuntimeUID();
    1847             :         }
    1848         669 :         else if ( aString.EqualsAscii( SC_UNO_HASVALIDSIGNATURES ) )
    1849             :         {
    1850           0 :             aRet <<= hasValidSignatures();
    1851             :         }
    1852         669 :         else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
    1853             :         {
    1854          10 :             ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
    1855             :         }
    1856         659 :         else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
    1857             :         {
    1858          10 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
    1859             :         }
    1860         649 :         else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
    1861             :         {
    1862          10 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
    1863             :         }
    1864         639 :         else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
    1865             :         {
    1866          10 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
    1867             :         }
    1868         629 :         else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
    1869             :         {
    1870          10 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
    1871             :         }
    1872         619 :         else if ( aString.EqualsAscii( SC_UNO_REFERENCEDEVICE ) )
    1873             :         {
    1874         146 :             VCLXDevice* pXDev = new VCLXDevice();
    1875         146 :             pXDev->SetOutputDevice( pDoc->GetRefDevice() );
    1876         146 :             aRet <<= uno::Reference< awt::XDevice >( pXDev );
    1877             :         }
    1878         473 :         else if ( aString.EqualsAscii( "BuildId" ) )
    1879             :         {
    1880          10 :             aRet <<= maBuildId;
    1881             :         }
    1882         463 :         else if ( aString.EqualsAscii( "InternalDocument" ) )
    1883             :         {
    1884           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
    1885             :         }
    1886             :     }
    1887             : 
    1888        6910 :     return aRet;
    1889             : }
    1890             : 
    1891           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
    1892             : 
    1893             : // XMultiServiceFactory
    1894             : 
    1895        2461 : uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
    1896             :                                 const OUString& aServiceSpecifier )
    1897             :                                 throw(uno::Exception, uno::RuntimeException)
    1898             : {
    1899        2461 :     SolarMutexGuard aGuard;
    1900        2461 :     uno::Reference<uno::XInterface> xRet;
    1901        4922 :     String aNameStr(aServiceSpecifier);
    1902        2461 :     sal_uInt16 nType = ScServiceProvider::GetProviderType(aNameStr);
    1903        2461 :     if ( nType != SC_SERVICE_INVALID )
    1904             :     {
    1905             :         //  drawing layer tables must be kept as long as the model is alive
    1906             :         //  return stored instance if already set
    1907        2201 :         switch ( nType )
    1908             :         {
    1909           9 :             case SC_SERVICE_GRADTAB:    xRet.set(xDrawGradTab);     break;
    1910           9 :             case SC_SERVICE_HATCHTAB:   xRet.set(xDrawHatchTab);    break;
    1911           9 :             case SC_SERVICE_BITMAPTAB:  xRet.set(xDrawBitmapTab);   break;
    1912           9 :             case SC_SERVICE_TRGRADTAB:  xRet.set(xDrawTrGradTab);   break;
    1913          20 :             case SC_SERVICE_MARKERTAB:  xRet.set(xDrawMarkerTab);   break;
    1914           9 :             case SC_SERVICE_DASHTAB:    xRet.set(xDrawDashTab);     break;
    1915          62 :             case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv);   break;
    1916          29 :             case SC_SERVICE_VBAOBJECTPROVIDER: xRet.set(xObjProvider); break;
    1917             :         }
    1918             : 
    1919             :         // #i64497# If a chart is in a temporary document during clipoard paste,
    1920             :         // there should be no data provider, so that own data is used
    1921             :         bool bCreate =
    1922             :             ! ( nType == SC_SERVICE_CHDATAPROV &&
    1923        2201 :                 ( pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL ));
    1924             :         // this should never happen, i.e. the temporary document should never be
    1925             :         // loaded, because this unlinks the data
    1926             :         OSL_ASSERT( bCreate );
    1927             : 
    1928        2201 :         if ( !xRet.is() && bCreate )
    1929             :         {
    1930        2145 :             xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
    1931             : 
    1932             :             //  store created instance
    1933        2139 :             switch ( nType )
    1934             :             {
    1935           8 :                 case SC_SERVICE_GRADTAB:    xDrawGradTab.set(xRet);     break;
    1936           8 :                 case SC_SERVICE_HATCHTAB:   xDrawHatchTab.set(xRet);    break;
    1937           8 :                 case SC_SERVICE_BITMAPTAB:  xDrawBitmapTab.set(xRet);   break;
    1938           8 :                 case SC_SERVICE_TRGRADTAB:  xDrawTrGradTab.set(xRet);   break;
    1939          19 :                 case SC_SERVICE_MARKERTAB:  xDrawMarkerTab.set(xRet);   break;
    1940           8 :                 case SC_SERVICE_DASHTAB:    xDrawDashTab.set(xRet);     break;
    1941          12 :                 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet);   break;
    1942          26 :                 case SC_SERVICE_VBAOBJECTPROVIDER: xObjProvider.set(xRet); break;
    1943             :             }
    1944             :         }
    1945             :     }
    1946             :     else
    1947             :     {
    1948             :         //  alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
    1949             :         //  da wird dann 'ne Exception geworfen, wenn's nicht passt...
    1950             : 
    1951             :         try
    1952             :         {
    1953         260 :             xRet.set(SvxFmMSFactory::createInstance(aServiceSpecifier));
    1954             :             // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
    1955             :         }
    1956          38 :         catch ( lang::ServiceNotRegisteredException & )
    1957             :         {
    1958             :         }
    1959             : 
    1960             :         //  if the drawing factory created a shape, a ScShapeObj has to be used
    1961             :         //  to support own properties like ImageMap:
    1962             : 
    1963         260 :         uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
    1964         260 :         if ( xShape.is() )
    1965             :         {
    1966         172 :             xRet.clear();               // for aggregation, xShape must be the object's only ref
    1967         172 :             new ScShapeObj( xShape );   // aggregates object and modifies xShape
    1968         172 :             xRet.set(xShape);
    1969         260 :         }
    1970             :     }
    1971        4916 :     return xRet;
    1972             : }
    1973             : 
    1974           4 : uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
    1975             :                                 const OUString& ServiceSpecifier,
    1976             :                                 const uno::Sequence<uno::Any>& aArgs )
    1977             :                                 throw(uno::Exception, uno::RuntimeException)
    1978             : {
    1979             :     //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
    1980             : 
    1981           4 :     SolarMutexGuard aGuard;
    1982           4 :     uno::Reference<uno::XInterface> xInt(createInstance(ServiceSpecifier));
    1983             : 
    1984           4 :     if ( aArgs.getLength() )
    1985             :     {
    1986             :         //  used only for cell value binding so far - it can be initialized after creating
    1987             : 
    1988           4 :         uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
    1989           4 :         if ( xInit.is() )
    1990           4 :             xInit->initialize( aArgs );
    1991             :     }
    1992             : 
    1993           4 :     return xInt;
    1994             : }
    1995             : 
    1996          37 : uno::Sequence<OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
    1997             :                                                 throw(uno::RuntimeException)
    1998             : {
    1999          37 :     SolarMutexGuard aGuard;
    2000             : 
    2001             :     //! warum sind die Parameter bei concatServiceNames nicht const ???
    2002             :     //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
    2003             :     //!                            SvxFmMSFactory::getAvailableServiceNames() );
    2004             : 
    2005          74 :     uno::Sequence<OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
    2006          74 :     uno::Sequence<OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
    2007             : 
    2008          74 :     return concatServiceNames( aMyServices, aDrawServices );
    2009             : }
    2010             : 
    2011             : // XServiceInfo
    2012             : 
    2013           0 : OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException)
    2014             : {
    2015           0 :     return OUString( "ScModelObj" );
    2016             : }
    2017             : 
    2018         783 : sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
    2019             :                                                     throw(uno::RuntimeException)
    2020             : {
    2021         783 :     String aServiceStr(rServiceName);
    2022        1388 :     return aServiceStr.EqualsAscii( SCMODELOBJ_SERVICE ) ||
    2023        1386 :            aServiceStr.EqualsAscii( SCDOCSETTINGS_SERVICE ) ||
    2024        1386 :            aServiceStr.EqualsAscii( SCDOC_SERVICE );
    2025             : }
    2026             : 
    2027         248 : uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
    2028             :                                                     throw(uno::RuntimeException)
    2029             : {
    2030         248 :     uno::Sequence<OUString> aRet(2);
    2031         248 :     OUString* pArray = aRet.getArray();
    2032         248 :     pArray[0] = OUString( SCMODELOBJ_SERVICE );
    2033         248 :     pArray[1] = OUString( SCDOCSETTINGS_SERVICE );
    2034         248 :     return aRet;
    2035             : }
    2036             : 
    2037             : // XUnoTunnel
    2038             : 
    2039       16305 : sal_Int64 SAL_CALL ScModelObj::getSomething(
    2040             :                 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
    2041             : {
    2042       32610 :     if ( rId.getLength() == 16 &&
    2043       16305 :           0 == memcmp( getUnoTunnelId().getConstArray(),
    2044       32610 :                                     rId.getConstArray(), 16 ) )
    2045             :     {
    2046        2433 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
    2047             :     }
    2048             : 
    2049       27744 :     if ( rId.getLength() == 16 &&
    2050       13872 :         0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
    2051       27744 :                                     rId.getConstArray(), 16 ) )
    2052             :     {
    2053         314 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
    2054             :     }
    2055             : 
    2056             :     //  aggregated number formats supplier has XUnoTunnel, too
    2057             :     //  interface from aggregated object must be obtained via queryAggregation
    2058             : 
    2059       13558 :     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
    2060       13558 :     if ( nRet )
    2061       12844 :         return nRet;
    2062             : 
    2063         714 :     if ( GetFormatter().is() )
    2064             :     {
    2065         714 :         const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0);
    2066         714 :         uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
    2067         714 :         if(aNumTunnel.getValueType() == rTunnelType)
    2068             :         {
    2069             :             uno::Reference<lang::XUnoTunnel> xTunnelAgg(
    2070         714 :                 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
    2071         714 :             return xTunnelAgg->getSomething( rId );
    2072           0 :         }
    2073             :     }
    2074             : 
    2075           0 :     return 0;
    2076             : }
    2077             : 
    2078             : namespace
    2079             : {
    2080             :     class theScModelObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScModelObjUnoTunnelId> {};
    2081             : }
    2082             : 
    2083       18738 : const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
    2084             : {
    2085       18738 :     return theScModelObjUnoTunnelId::get().getSeq();
    2086             : }
    2087             : 
    2088        2433 : ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
    2089             : {
    2090        2433 :     ScModelObj* pRet = NULL;
    2091        2433 :     uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
    2092        2433 :     if (xUT.is())
    2093        2433 :         pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
    2094        2433 :     return pRet;
    2095             : }
    2096             : 
    2097             : // XChangesNotifier
    2098             : 
    2099          25 : void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
    2100             :     throw (uno::RuntimeException)
    2101             : {
    2102          25 :     SolarMutexGuard aGuard;
    2103          25 :     maChangesListeners.addInterface( aListener );
    2104          25 : }
    2105             : 
    2106           0 : void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
    2107             :     throw (uno::RuntimeException)
    2108             : {
    2109           0 :     SolarMutexGuard aGuard;
    2110           0 :     maChangesListeners.removeInterface( aListener );
    2111           0 : }
    2112             : 
    2113          16 : bool ScModelObj::HasChangesListeners() const
    2114             : {
    2115          16 :     if ( maChangesListeners.getLength() > 0 )
    2116           0 :         return true;
    2117             : 
    2118             :     // "change" event set in any sheet?
    2119          16 :     return pDocShell && pDocShell->GetDocument()->HasAnySheetEventScript(SC_SHEETEVENT_CHANGE);
    2120             : }
    2121             : 
    2122           0 : void ScModelObj::NotifyChanges( const OUString& rOperation, const ScRangeList& rRanges,
    2123             :     const uno::Sequence< beans::PropertyValue >& rProperties )
    2124             : {
    2125           0 :     if ( pDocShell && HasChangesListeners() )
    2126             :     {
    2127           0 :         util::ChangesEvent aEvent;
    2128           0 :         aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
    2129           0 :         aEvent.Base <<= aEvent.Source;
    2130             : 
    2131           0 :         size_t nRangeCount = rRanges.size();
    2132           0 :         aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
    2133           0 :         for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
    2134             :         {
    2135           0 :             uno::Reference< table::XCellRange > xRangeObj;
    2136             : 
    2137           0 :             ScRange aRange( *rRanges[ nIndex ] );
    2138           0 :             if ( aRange.aStart == aRange.aEnd )
    2139             :             {
    2140           0 :                 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
    2141             :             }
    2142             :             else
    2143             :             {
    2144           0 :                 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
    2145             :             }
    2146             : 
    2147           0 :             util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
    2148           0 :             rChange.Accessor <<= rOperation;
    2149           0 :             rChange.Element <<= rProperties;
    2150           0 :             rChange.ReplacedElement <<= xRangeObj;
    2151           0 :         }
    2152             : 
    2153           0 :         ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
    2154           0 :         while ( aIter.hasMoreElements() )
    2155             :         {
    2156             :             try
    2157             :             {
    2158           0 :                 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
    2159             :             }
    2160           0 :             catch( uno::Exception& )
    2161             :             {
    2162             :             }
    2163           0 :         }
    2164             :     }
    2165             : 
    2166             :     // handle sheet events
    2167             :     //! separate method with ScMarkData? Then change HasChangesListeners back.
    2168           0 :     if ( rOperation.compareToAscii("cell-change") == 0 && pDocShell )
    2169             :     {
    2170           0 :         ScMarkData aMarkData;
    2171           0 :         aMarkData.MarkFromRangeList( rRanges, false );
    2172           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    2173           0 :         SCTAB nTabCount = pDoc->GetTableCount();
    2174           0 :         ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
    2175           0 :         for (; itr != itrEnd && *itr < nTabCount; ++itr)
    2176             :         {
    2177           0 :             SCTAB nTab = *itr;
    2178           0 :             const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
    2179           0 :             if (pEvents)
    2180             :             {
    2181           0 :                 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CHANGE);
    2182           0 :                 if (pScript)
    2183             :                 {
    2184           0 :                     ScRangeList aTabRanges;     // collect ranges on this sheet
    2185           0 :                     size_t nRangeCount = rRanges.size();
    2186           0 :                     for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
    2187             :                     {
    2188           0 :                         ScRange aRange( *rRanges[ nIndex ] );
    2189           0 :                         if ( aRange.aStart.Tab() == nTab )
    2190           0 :                             aTabRanges.Append( aRange );
    2191             :                     }
    2192           0 :                     size_t nTabRangeCount = aTabRanges.size();
    2193           0 :                     if ( nTabRangeCount > 0 )
    2194             :                     {
    2195           0 :                         uno::Reference<uno::XInterface> xTarget;
    2196           0 :                         if ( nTabRangeCount == 1 )
    2197             :                         {
    2198           0 :                             ScRange aRange( *aTabRanges[ 0 ] );
    2199           0 :                             if ( aRange.aStart == aRange.aEnd )
    2200           0 :                                 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellObj( pDocShell, aRange.aStart ) ) );
    2201             :                             else
    2202           0 :                                 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangeObj( pDocShell, aRange ) ) );
    2203             :                         }
    2204             :                         else
    2205           0 :                             xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangesObj( pDocShell, aTabRanges ) ) );
    2206             : 
    2207           0 :                         uno::Sequence<uno::Any> aParams(1);
    2208           0 :                         aParams[0] <<= xTarget;
    2209             : 
    2210           0 :                         uno::Any aRet;
    2211           0 :                         uno::Sequence<sal_Int16> aOutArgsIndex;
    2212           0 :                         uno::Sequence<uno::Any> aOutArgs;
    2213             : 
    2214           0 :                         /*ErrCode eRet =*/ pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
    2215           0 :                     }
    2216             :                 }
    2217             :             }
    2218           0 :         }
    2219             :     }
    2220           0 : }
    2221             : 
    2222           0 : void ScModelObj::HandleCalculateEvents()
    2223             : {
    2224           0 :     if (pDocShell)
    2225             :     {
    2226           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    2227             :         // don't call events before the document is visible
    2228             :         // (might also set a flag on SFX_EVENT_LOADFINISHED and only disable while loading)
    2229           0 :         if ( pDoc->IsDocVisible() )
    2230             :         {
    2231           0 :             SCTAB nTabCount = pDoc->GetTableCount();
    2232           0 :             for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
    2233             :             {
    2234           0 :                 if (pDoc->HasCalcNotification(nTab))
    2235             :                 {
    2236           0 :                     if (const ScSheetEvents* pEvents = pDoc->GetSheetEvents( nTab ))
    2237             :                     {
    2238           0 :                         if (const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CALCULATE))
    2239             :                         {
    2240           0 :                             uno::Any aRet;
    2241           0 :                             uno::Sequence<uno::Any> aParams;
    2242           0 :                             uno::Sequence<sal_Int16> aOutArgsIndex;
    2243           0 :                             uno::Sequence<uno::Any> aOutArgs;
    2244           0 :                             pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
    2245             :                         }
    2246             :                     }
    2247             : 
    2248             :                     try
    2249             :                     {
    2250           0 :                         uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
    2251           0 :                         uno::Sequence< uno::Any > aArgs( 1 );
    2252           0 :                         aArgs[ 0 ] <<= nTab;
    2253           0 :                         xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_CALCULATE ), aArgs );
    2254             :                     }
    2255           0 :                     catch( uno::Exception& )
    2256             :                     {
    2257             :                     }
    2258             :                 }
    2259             :             }
    2260             :         }
    2261           0 :         pDoc->ResetCalcNotifications();
    2262             :     }
    2263           0 : }
    2264             : 
    2265             : //------------------------------------------------------------------------
    2266             : 
    2267          25 : ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
    2268          25 :     pDocShell( pDocSh )
    2269             : {
    2270          25 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2271          25 : }
    2272             : 
    2273          75 : ScDrawPagesObj::~ScDrawPagesObj()
    2274             : {
    2275          25 :     if (pDocShell)
    2276          19 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2277          50 : }
    2278             : 
    2279         127 : void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2280             : {
    2281             :     //  Referenz-Update interessiert hier nicht
    2282             : 
    2283         252 :     if ( rHint.ISA( SfxSimpleHint ) &&
    2284         125 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2285             :     {
    2286           6 :         pDocShell = NULL;       // ungueltig geworden
    2287             :     }
    2288         127 : }
    2289             : 
    2290          58 : uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2291             : {
    2292          58 :     if (pDocShell)
    2293             :     {
    2294          58 :         ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
    2295             :         OSL_ENSURE(pDrawLayer,"kann Draw-Layer nicht anlegen");
    2296          58 :         if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
    2297             :         {
    2298          57 :             SdrPage* pPage = pDrawLayer->GetPage((sal_uInt16)nIndex);
    2299             :             OSL_ENSURE(pPage,"Draw-Page nicht gefunden");
    2300          57 :             if (pPage)
    2301             :             {
    2302          57 :                 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
    2303             :             }
    2304             :         }
    2305             :     }
    2306           1 :     return NULL;
    2307             : }
    2308             : 
    2309             : // XDrawPages
    2310             : 
    2311           7 : uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
    2312             :                                             throw(uno::RuntimeException)
    2313             : {
    2314           7 :     SolarMutexGuard aGuard;
    2315           7 :     uno::Reference<drawing::XDrawPage> xRet;
    2316           7 :     if (pDocShell)
    2317             :     {
    2318           7 :         OUString aNewName;
    2319           7 :         pDocShell->GetDocument()->CreateValidTabName(aNewName);
    2320          21 :         if ( pDocShell->GetDocFunc().InsertTable( static_cast<SCTAB>(nPos),
    2321          14 :                                                   aNewName, true, true ) )
    2322           7 :             xRet.set(GetObjectByIndex_Impl( nPos ));
    2323             :     }
    2324           7 :     return xRet;
    2325             : }
    2326             : 
    2327           1 : void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
    2328             :                                             throw(uno::RuntimeException)
    2329             : {
    2330           1 :     SolarMutexGuard aGuard;
    2331           1 :     SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
    2332           1 :     if ( pDocShell && pImp )
    2333             :     {
    2334           1 :         SdrPage* pPage = pImp->GetSdrPage();
    2335           1 :         if (pPage)
    2336             :         {
    2337           1 :             SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
    2338           1 :             pDocShell->GetDocFunc().DeleteTable( nPageNum, sal_True, sal_True );
    2339             :         }
    2340           1 :     }
    2341           1 : }
    2342             : 
    2343             : // XIndexAccess
    2344             : 
    2345          23 : sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException)
    2346             : {
    2347          23 :     SolarMutexGuard aGuard;
    2348          23 :     if (pDocShell)
    2349          23 :         return pDocShell->GetDocument()->GetTableCount();
    2350           0 :     return 0;
    2351             : }
    2352             : 
    2353          51 : uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
    2354             :                             throw(lang::IndexOutOfBoundsException,
    2355             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2356             : {
    2357          51 :     SolarMutexGuard aGuard;
    2358         102 :     uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
    2359          51 :     if (xPage.is())
    2360         100 :         return uno::makeAny(xPage);
    2361             :     else
    2362          52 :         throw lang::IndexOutOfBoundsException();
    2363             : }
    2364             : 
    2365           1 : uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException)
    2366             : {
    2367           1 :     SolarMutexGuard aGuard;
    2368           1 :     return getCppuType((uno::Reference<drawing::XDrawPage>*)0);
    2369             : }
    2370             : 
    2371           1 : sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException)
    2372             : {
    2373           1 :     SolarMutexGuard aGuard;
    2374           1 :     return ( getCount() != 0 );
    2375             : }
    2376             : 
    2377             : //------------------------------------------------------------------------
    2378             : 
    2379         930 : ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
    2380         930 :     pDocShell( pDocSh )
    2381             : {
    2382         930 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2383         930 : }
    2384             : 
    2385        2787 : ScTableSheetsObj::~ScTableSheetsObj()
    2386             : {
    2387         929 :     if (pDocShell)
    2388         817 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2389        1858 : }
    2390             : 
    2391        4097 : void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2392             : {
    2393             :     //  Referenz-Update interessiert hier nicht
    2394             : 
    2395        8068 :     if ( rHint.ISA( SfxSimpleHint ) &&
    2396        3971 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2397             :     {
    2398         113 :         pDocShell = NULL;       // ungueltig geworden
    2399             :     }
    2400        4097 : }
    2401             : 
    2402             : // XSpreadsheets
    2403             : 
    2404         767 : ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2405             : {
    2406         767 :     if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
    2407         766 :         return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
    2408             : 
    2409           1 :     return NULL;
    2410             : }
    2411             : 
    2412         164 : ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const OUString& aName) const
    2413             : {
    2414         164 :     if (pDocShell)
    2415             :     {
    2416             :         SCTAB nIndex;
    2417         164 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2418         164 :             return new ScTableSheetObj( pDocShell, nIndex );
    2419             :     }
    2420           0 :     return NULL;
    2421             : }
    2422             : 
    2423          35 : void SAL_CALL ScTableSheetsObj::insertNewByName( const OUString& aName, sal_Int16 nPosition )
    2424             :                                                 throw(uno::RuntimeException)
    2425             : {
    2426          35 :     SolarMutexGuard aGuard;
    2427          35 :     sal_Bool bDone = false;
    2428          35 :     if (pDocShell)
    2429             :     {
    2430          35 :         String aNamStr(aName);
    2431          35 :         bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, sal_True, sal_True );
    2432             :     }
    2433          35 :     if (!bDone)
    2434           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2435          35 : }
    2436             : 
    2437           0 : void SAL_CALL ScTableSheetsObj::moveByName( const OUString& aName, sal_Int16 nDestination )
    2438             :                                             throw(uno::RuntimeException)
    2439             : {
    2440           0 :     SolarMutexGuard aGuard;
    2441           0 :     sal_Bool bDone = false;
    2442           0 :     if (pDocShell)
    2443             :     {
    2444             :         SCTAB nSource;
    2445           0 :         if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
    2446           0 :             bDone = pDocShell->MoveTable( nSource, nDestination, false, sal_True );
    2447             :     }
    2448           0 :     if (!bDone)
    2449           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2450           0 : }
    2451             : 
    2452           0 : void SAL_CALL ScTableSheetsObj::copyByName( const OUString& aName,
    2453             :                                 const OUString& aCopy, sal_Int16 nDestination )
    2454             :                                                 throw(uno::RuntimeException)
    2455             : {
    2456           0 :     SolarMutexGuard aGuard;
    2457           0 :     sal_Bool bDone = false;
    2458           0 :     if (pDocShell)
    2459             :     {
    2460           0 :         String aNewStr(aCopy);
    2461             :         SCTAB nSource;
    2462           0 :         if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
    2463             :         {
    2464           0 :             bDone = pDocShell->MoveTable( nSource, nDestination, sal_True, sal_True );
    2465           0 :             if (bDone)
    2466             :             {
    2467             :                 // #i92477# any index past the last sheet means "append" in MoveTable
    2468           0 :                 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
    2469           0 :                 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();    // count after copying
    2470           0 :                 if (nResultTab >= nTabCount)
    2471           0 :                     nResultTab = nTabCount - 1;
    2472             : 
    2473           0 :                 bDone = pDocShell->GetDocFunc().RenameTable( nResultTab, aNewStr,
    2474           0 :                                                              sal_True, sal_True );
    2475             :             }
    2476           0 :         }
    2477             :     }
    2478           0 :     if (!bDone)
    2479           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2480           0 : }
    2481             : 
    2482           0 : void SAL_CALL ScTableSheetsObj::insertByName( const OUString& aName, const uno::Any& aElement )
    2483             :                             throw(lang::IllegalArgumentException, container::ElementExistException,
    2484             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2485             : {
    2486           0 :     SolarMutexGuard aGuard;
    2487           0 :     sal_Bool bDone = false;
    2488           0 :     sal_Bool bIllArg = false;
    2489             : 
    2490             :     //! Type of aElement can be some specific interface instead of XInterface
    2491             : 
    2492           0 :     if ( pDocShell )
    2493             :     {
    2494           0 :         uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
    2495           0 :         if ( xInterface.is() )
    2496             :         {
    2497           0 :             ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
    2498           0 :             if ( pSheetObj && !pSheetObj->GetDocShell() )   // noch nicht eingefuegt?
    2499             :             {
    2500           0 :                 ScDocument* pDoc = pDocShell->GetDocument();
    2501           0 :                 String aNamStr(aName);
    2502             :                 SCTAB nDummy;
    2503           0 :                 if ( pDoc->GetTable( aNamStr, nDummy ) )
    2504             :                 {
    2505             :                     //  name already exists
    2506           0 :                     throw container::ElementExistException();
    2507             :                 }
    2508             :                 else
    2509             :                 {
    2510           0 :                     SCTAB nPosition = pDoc->GetTableCount();
    2511           0 :                     bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr,
    2512           0 :                                                                  sal_True, sal_True );
    2513           0 :                     if (bDone)
    2514           0 :                         pSheetObj->InitInsertSheet( pDocShell, nPosition );
    2515             :                     //  Dokument und neuen Range am Objekt setzen
    2516           0 :                 }
    2517             :             }
    2518             :             else
    2519           0 :                 bIllArg = sal_True;
    2520             :         }
    2521             :         else
    2522           0 :             bIllArg = sal_True;
    2523             :     }
    2524             : 
    2525           0 :     if (!bDone)
    2526             :     {
    2527           0 :         if (bIllArg)
    2528           0 :             throw lang::IllegalArgumentException();
    2529             :         else
    2530           0 :             throw uno::RuntimeException();      // ElementExistException is handled above
    2531           0 :     }
    2532           0 : }
    2533             : 
    2534           0 : void SAL_CALL ScTableSheetsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
    2535             :                             throw(lang::IllegalArgumentException, container::NoSuchElementException,
    2536             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2537             : {
    2538           0 :     SolarMutexGuard aGuard;
    2539           0 :     sal_Bool bDone = false;
    2540           0 :     sal_Bool bIllArg = false;
    2541             : 
    2542             :     //! Type of aElement can be some specific interface instead of XInterface
    2543             : 
    2544           0 :     if ( pDocShell )
    2545             :     {
    2546           0 :         uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
    2547           0 :         if ( xInterface.is() )
    2548             :         {
    2549           0 :             ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
    2550           0 :             if ( pSheetObj && !pSheetObj->GetDocShell() )   // noch nicht eingefuegt?
    2551             :             {
    2552             :                 SCTAB nPosition;
    2553           0 :                 if ( pDocShell->GetDocument()->GetTable( aName, nPosition ) )
    2554             :                 {
    2555           0 :                     if ( pDocShell->GetDocFunc().DeleteTable( nPosition, sal_True, sal_True ) )
    2556             :                     {
    2557             :                         //  InsertTable kann jetzt eigentlich nicht schiefgehen...
    2558           0 :                         String aNamStr(aName);
    2559           0 :                         bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, sal_True, sal_True );
    2560           0 :                         if (bDone)
    2561           0 :                             pSheetObj->InitInsertSheet( pDocShell, nPosition );
    2562             :                     }
    2563             :                 }
    2564             :                 else
    2565             :                 {
    2566             :                     //  not found
    2567           0 :                     throw container::NoSuchElementException();
    2568             :                 }
    2569             :             }
    2570             :             else
    2571           0 :                 bIllArg = sal_True;
    2572             :         }
    2573             :         else
    2574           0 :             bIllArg = sal_True;
    2575             :     }
    2576             : 
    2577           0 :     if (!bDone)
    2578             :     {
    2579           0 :         if (bIllArg)
    2580           0 :             throw lang::IllegalArgumentException();
    2581             :         else
    2582           0 :             throw uno::RuntimeException();      // NoSuchElementException is handled above
    2583           0 :     }
    2584           0 : }
    2585             : 
    2586          18 : void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
    2587             :                                 throw(container::NoSuchElementException,
    2588             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2589             : {
    2590          18 :     SolarMutexGuard aGuard;
    2591          18 :     sal_Bool bDone = false;
    2592          18 :     if (pDocShell)
    2593             :     {
    2594             :         SCTAB nIndex;
    2595          18 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2596          17 :             bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, sal_True, sal_True );
    2597             :         else // not found
    2598           1 :             throw container::NoSuchElementException();
    2599             :     }
    2600             : 
    2601          17 :     if (!bDone)
    2602           0 :         throw uno::RuntimeException();      // NoSuchElementException is handled above
    2603          17 : }
    2604             : 
    2605           1 : sal_Int32 ScTableSheetsObj::importSheet(
    2606             :     const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc,
    2607             :     const OUString& srcName, const sal_Int32 nDestPosition )
    2608             :         throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException )
    2609             : {
    2610             :     //pDocShell is the destination
    2611           1 :     ScDocument* pDocDest = pDocShell->GetDocument();
    2612             : 
    2613             :     // Source document docShell
    2614           1 :     if ( !xDocSrc.is() )
    2615           0 :         throw uno::RuntimeException();
    2616           1 :     ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc);
    2617           1 :     ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject());
    2618             : 
    2619             :     // SourceSheet Position and does srcName exists ?
    2620             :     SCTAB nIndexSrc;
    2621           1 :     if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) )
    2622           0 :         throw lang::IllegalArgumentException();
    2623             : 
    2624             :     // Check the validity of destination index.
    2625           1 :     SCTAB nCount = pDocDest->GetTableCount();
    2626           1 :     SCTAB nIndexDest = static_cast<SCTAB>(nDestPosition);
    2627           1 :     if (nIndexDest > nCount || nIndexDest < 0)
    2628           0 :         throw lang::IndexOutOfBoundsException();
    2629             : 
    2630             :     // Transfert Tab
    2631           1 :     bool bInsertNew = true;
    2632           1 :     bool bNotifyAndPaint = true;
    2633             :     pDocShell->TransferTab(
    2634           1 :         *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint );
    2635             : 
    2636           1 :     return nIndexDest;
    2637             : }
    2638             : 
    2639             : // XCellRangesAccess
    2640             : 
    2641           0 : uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
    2642             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
    2643             : {
    2644           0 :     SolarMutexGuard aGuard;
    2645           0 :     uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
    2646           0 :     if (! xSheet.is())
    2647           0 :         throw lang::IndexOutOfBoundsException();
    2648             : 
    2649           0 :     return xSheet->getCellByPosition(nColumn, nRow);
    2650             : }
    2651             : 
    2652           0 : uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
    2653             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
    2654             : {
    2655           0 :     SolarMutexGuard aGuard;
    2656           0 :     uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
    2657           0 :     if (! xSheet.is())
    2658           0 :         throw lang::IndexOutOfBoundsException();
    2659             : 
    2660           0 :     return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
    2661             : }
    2662             : 
    2663           0 : uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const OUString& aRange )
    2664             :     throw (lang::IllegalArgumentException, uno::RuntimeException)
    2665             : {
    2666           0 :     SolarMutexGuard aGuard;
    2667           0 :     uno::Sequence < uno::Reference < table::XCellRange > > xRet;
    2668             : 
    2669           0 :     ScRangeList aRangeList;
    2670           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    2671           0 :     if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, pDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
    2672             :     {
    2673           0 :         size_t nCount = aRangeList.size();
    2674           0 :         if (nCount)
    2675             :         {
    2676           0 :             xRet.realloc(nCount);
    2677           0 :             for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
    2678             :             {
    2679           0 :                 const ScRange* pRange = aRangeList[ nIndex ];
    2680           0 :                 if( pRange )
    2681           0 :                     xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
    2682             :             }
    2683             :         }
    2684             :         else
    2685           0 :             throw lang::IllegalArgumentException();
    2686             :     }
    2687             :     else
    2688           0 :         throw lang::IllegalArgumentException();
    2689           0 :     return xRet;
    2690             : }
    2691             : 
    2692             : // XEnumerationAccess
    2693             : 
    2694           1 : uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
    2695             :                                                     throw(uno::RuntimeException)
    2696             : {
    2697           1 :     SolarMutexGuard aGuard;
    2698           1 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetsEnumeration"));
    2699             : }
    2700             : 
    2701             : // XIndexAccess
    2702             : 
    2703         156 : sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException)
    2704             : {
    2705         156 :     SolarMutexGuard aGuard;
    2706         156 :     if (pDocShell)
    2707         156 :         return pDocShell->GetDocument()->GetTableCount();
    2708           0 :     return 0;
    2709             : }
    2710             : 
    2711         767 : uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
    2712             :                             throw(lang::IndexOutOfBoundsException,
    2713             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2714             : {
    2715         767 :     SolarMutexGuard aGuard;
    2716        1534 :     uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
    2717         767 :     if (xSheet.is())
    2718        1532 :         return uno::makeAny(xSheet);
    2719             :     else
    2720         768 :         throw lang::IndexOutOfBoundsException();
    2721             : //    return uno::Any();
    2722             : }
    2723             : 
    2724           0 : uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException)
    2725             : {
    2726           0 :     SolarMutexGuard aGuard;
    2727           0 :     return getCppuType((uno::Reference<sheet::XSpreadsheet>*)0);
    2728             : }
    2729             : 
    2730           0 : sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException)
    2731             : {
    2732           0 :     SolarMutexGuard aGuard;
    2733           0 :     return ( getCount() != 0 );
    2734             : }
    2735             : 
    2736             : // XNameAccess
    2737             : 
    2738         164 : uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
    2739             :             throw(container::NoSuchElementException,
    2740             :                     lang::WrappedTargetException, uno::RuntimeException)
    2741             : {
    2742         164 :     SolarMutexGuard aGuard;
    2743         328 :     uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
    2744         164 :     if (xSheet.is())
    2745         328 :         return uno::makeAny(xSheet);
    2746             :     else
    2747         164 :         throw container::NoSuchElementException();
    2748             : }
    2749             : 
    2750          16 : uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
    2751             :                                                 throw(uno::RuntimeException)
    2752             : {
    2753          16 :     SolarMutexGuard aGuard;
    2754          16 :     if (pDocShell)
    2755             :     {
    2756          16 :         ScDocument* pDoc = pDocShell->GetDocument();
    2757          16 :         SCTAB nCount = pDoc->GetTableCount();
    2758          16 :         OUString aName;
    2759          32 :         uno::Sequence<OUString> aSeq(nCount);
    2760          16 :         OUString* pAry = aSeq.getArray();
    2761          32 :         for (SCTAB i=0; i<nCount; i++)
    2762             :         {
    2763          16 :             pDoc->GetName( i, aName );
    2764          16 :             pAry[i] = aName;
    2765             :         }
    2766          32 :         return aSeq;
    2767             :     }
    2768           0 :     return uno::Sequence<OUString>();
    2769             : }
    2770             : 
    2771          26 : sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const OUString& aName )
    2772             :                                         throw(uno::RuntimeException)
    2773             : {
    2774          26 :     SolarMutexGuard aGuard;
    2775          26 :     if (pDocShell)
    2776             :     {
    2777             :         SCTAB nIndex;
    2778          26 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2779           2 :             return sal_True;
    2780             :     }
    2781          24 :     return false;
    2782             : }
    2783             : 
    2784             : //------------------------------------------------------------------------
    2785             : 
    2786         429 : ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
    2787             :     pDocShell( pDocSh ),
    2788             :     nTab     ( nT ),
    2789             :     nStartCol( nSC ),
    2790         429 :     nEndCol  ( nEC )
    2791             : {
    2792         429 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2793         429 : }
    2794             : 
    2795        1287 : ScTableColumnsObj::~ScTableColumnsObj()
    2796             : {
    2797         429 :     if (pDocShell)
    2798         422 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2799         858 : }
    2800             : 
    2801         652 : void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2802             : {
    2803         652 :     if ( rHint.ISA( ScUpdateRefHint ) )
    2804             :     {
    2805             :         //! Referenz-Update fuer Tab und Start/Ende
    2806             :     }
    2807        1292 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    2808         646 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2809             :     {
    2810           7 :         pDocShell = NULL;       // ungueltig geworden
    2811             :     }
    2812         652 : }
    2813             : 
    2814             : // XTableColumns
    2815             : 
    2816        1070 : ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2817             : {
    2818        1070 :     SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
    2819        1070 :     if ( pDocShell && nCol <= nEndCol )
    2820        1068 :         return new ScTableColumnObj( pDocShell, nCol, nTab );
    2821             : 
    2822           2 :     return NULL;    // falscher Index
    2823             : }
    2824             : 
    2825           2 : ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
    2826             : {
    2827           2 :     SCCOL nCol = 0;
    2828           2 :     String aString(aName);
    2829           2 :     if ( ::AlphaToCol( nCol, aString) )
    2830           1 :         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
    2831           1 :             return new ScTableColumnObj( pDocShell, nCol, nTab );
    2832             : 
    2833           1 :     return NULL;
    2834             : }
    2835             : 
    2836           6 : void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
    2837             :                                                 throw(uno::RuntimeException)
    2838             : {
    2839           6 :     SolarMutexGuard aGuard;
    2840           6 :     sal_Bool bDone = false;
    2841           9 :     if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
    2842           3 :             nStartCol+nPosition+nCount-1 <= MAXCOL )
    2843             :     {
    2844             :         ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
    2845           3 :                         (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
    2846           3 :         bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSCOLS, sal_True, sal_True );
    2847             :     }
    2848           6 :     if (!bDone)
    2849           3 :         throw uno::RuntimeException();      // no other exceptions specified
    2850           3 : }
    2851             : 
    2852           6 : void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
    2853             :                                                 throw(uno::RuntimeException)
    2854             : {
    2855           6 :     SolarMutexGuard aGuard;
    2856           6 :     sal_Bool bDone = false;
    2857             :     //  Der zu loeschende Bereich muss innerhalb des Objekts liegen
    2858           6 :     if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
    2859             :     {
    2860             :         ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
    2861           3 :                         (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
    2862           3 :         bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELCOLS, sal_True, sal_True );
    2863             :     }
    2864           6 :     if (!bDone)
    2865           3 :         throw uno::RuntimeException();      // no other exceptions specified
    2866           3 : }
    2867             : 
    2868             : // XEnumerationAccess
    2869             : 
    2870           2 : uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
    2871             :                                                     throw(uno::RuntimeException)
    2872             : {
    2873           2 :     SolarMutexGuard aGuard;
    2874           2 :     return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableColumnsEnumeration"));
    2875             : }
    2876             : 
    2877             : // XIndexAccess
    2878             : 
    2879        1186 : sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException)
    2880             : {
    2881        1186 :     SolarMutexGuard aGuard;
    2882        1186 :     return nEndCol - nStartCol + 1;
    2883             : }
    2884             : 
    2885        1070 : uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
    2886             :                             throw(lang::IndexOutOfBoundsException,
    2887             :                                     lang::WrappedTargetException, uno::RuntimeException)
    2888             : {
    2889        1070 :     SolarMutexGuard aGuard;
    2890        2140 :     uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
    2891        1070 :     if (xColumn.is())
    2892        2136 :         return uno::makeAny(xColumn);
    2893             :     else
    2894        1072 :         throw lang::IndexOutOfBoundsException();
    2895             : }
    2896             : 
    2897           1 : uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException)
    2898             : {
    2899           1 :     SolarMutexGuard aGuard;
    2900           1 :     return getCppuType((uno::Reference<table::XCellRange>*)0);
    2901             : }
    2902             : 
    2903           1 : sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException)
    2904             : {
    2905           1 :     SolarMutexGuard aGuard;
    2906           1 :     return ( getCount() != 0 );
    2907             : }
    2908             : 
    2909           2 : uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
    2910             :             throw(container::NoSuchElementException,
    2911             :                     lang::WrappedTargetException, uno::RuntimeException)
    2912             : {
    2913           2 :     SolarMutexGuard aGuard;
    2914           4 :     uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
    2915           2 :     if (xColumn.is())
    2916           2 :         return uno::makeAny(xColumn);
    2917             :     else
    2918           3 :         throw container::NoSuchElementException();
    2919             : }
    2920             : 
    2921           1 : uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
    2922             :                                                 throw(uno::RuntimeException)
    2923             : {
    2924           1 :     SolarMutexGuard aGuard;
    2925           1 :     SCCOL nCount = nEndCol - nStartCol + 1;
    2926           1 :     uno::Sequence<OUString> aSeq(nCount);
    2927           1 :     OUString* pAry = aSeq.getArray();
    2928        1025 :     for (SCCOL i=0; i<nCount; i++)
    2929        1024 :         pAry[i] = ::ScColToAlpha( nStartCol + i );
    2930             : 
    2931           1 :     return aSeq;
    2932             : }
    2933             : 
    2934           2 : sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
    2935             :                                         throw(uno::RuntimeException)
    2936             : {
    2937           2 :     SolarMutexGuard aGuard;
    2938           2 :     SCCOL nCol = 0;
    2939           4 :     String aString(aName);
    2940           2 :     if ( ::AlphaToCol( nCol, aString) )
    2941           1 :         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
    2942           1 :             return sal_True;
    2943             : 
    2944           3 :     return false;       // nicht gefunden
    2945             : }
    2946             : 
    2947             : // XPropertySet
    2948             : 
    2949         259 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
    2950             :                                                         throw(uno::RuntimeException)
    2951             : {
    2952         259 :     SolarMutexGuard aGuard;
    2953             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    2954         259 :         new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
    2955         259 :     return aRef;
    2956             : }
    2957             : 
    2958         785 : void SAL_CALL ScTableColumnsObj::setPropertyValue(
    2959             :                         const OUString& aPropertyName, const uno::Any& aValue )
    2960             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
    2961             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
    2962             :                         uno::RuntimeException)
    2963             : {
    2964         785 :     SolarMutexGuard aGuard;
    2965         785 :     if (!pDocShell)
    2966           0 :         throw uno::RuntimeException();
    2967             : 
    2968             :     SCCOLROW nColArr[2];
    2969         785 :     nColArr[0] = nStartCol;
    2970         785 :     nColArr[1] = nEndCol;
    2971        1570 :     String aNameString(aPropertyName);
    2972         785 :     ScDocFunc& rFunc = pDocShell->GetDocFunc();
    2973             : 
    2974         785 :     if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
    2975             :     {
    2976         259 :         sal_Int32 nNewWidth = 0;
    2977         259 :         if ( aValue >>= nNewWidth )
    2978             :             rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, SC_SIZE_ORIGINAL,
    2979         259 :                                     (sal_uInt16)HMMToTwips(nNewWidth), sal_True, sal_True );
    2980             :     }
    2981         526 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
    2982             :     {
    2983         267 :         sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    2984         267 :         ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
    2985         267 :         rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, eMode, 0, sal_True, sal_True );
    2986             :         //  SC_SIZE_DIRECT with size 0: hide
    2987             :     }
    2988         259 :     else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
    2989             :     {
    2990           0 :         sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    2991           0 :         if (bOpt)
    2992             :             rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab,
    2993           0 :                                     SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, sal_True, sal_True );
    2994             :         // sal_False for columns currently has no effect
    2995             :     }
    2996         259 :     else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
    2997             :     {
    2998             :         //! single function to set/remove all breaks?
    2999         259 :         sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3000        6758 :         for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
    3001        6499 :             if (bSet)
    3002           0 :                 rFunc.InsertPageBreak( sal_True, ScAddress(nCol,0,nTab), sal_True, sal_True, sal_True );
    3003             :             else
    3004        6499 :                 rFunc.RemovePageBreak( sal_True, ScAddress(nCol,0,nTab), sal_True, sal_True, sal_True );
    3005         785 :     }
    3006         785 : }
    3007             : 
    3008          26 : uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aPropertyName )
    3009             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    3010             :                         uno::RuntimeException)
    3011             : {
    3012          26 :     SolarMutexGuard aGuard;
    3013          26 :     if (!pDocShell)
    3014           0 :         throw uno::RuntimeException();
    3015             : 
    3016          26 :     ScDocument* pDoc = pDocShell->GetDocument();
    3017          52 :     String aNameString(aPropertyName);
    3018          26 :     uno::Any aAny;
    3019             : 
    3020             :     //! loop over all columns for current state?
    3021             : 
    3022          26 :     if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
    3023             :     {
    3024             :         // for hidden column, return original height
    3025           0 :         sal_uInt16 nWidth = pDoc->GetOriginalWidth( nStartCol, nTab );
    3026           0 :         aAny <<= (sal_Int32)TwipsToHMM(nWidth);
    3027             :     }
    3028          26 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
    3029             :     {
    3030          26 :         bool bVis = !pDoc->ColHidden(nStartCol, nTab);
    3031          26 :         ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
    3032             :     }
    3033           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
    3034             :     {
    3035           0 :         sal_Bool bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
    3036           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
    3037             :     }
    3038           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
    3039             :     {
    3040           0 :         ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
    3041           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
    3042             :     }
    3043           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
    3044             :     {
    3045           0 :         ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
    3046           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
    3047             :     }
    3048             : 
    3049          52 :     return aAny;
    3050             : }
    3051             : 
    3052           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
    3053             : 
    3054             : //------------------------------------------------------------------------
    3055             : 
    3056        2180 : ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
    3057             :     pDocShell( pDocSh ),
    3058             :     nTab     ( nT ),
    3059             :     nStartRow( nSR ),
    3060        2180 :     nEndRow  ( nER )
    3061             : {
    3062        2180 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3063        2180 : }
    3064             : 
    3065        6540 : ScTableRowsObj::~ScTableRowsObj()
    3066             : {
    3067        2180 :     if (pDocShell)
    3068        2175 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3069        4360 : }
    3070             : 
    3071         132 : void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3072             : {
    3073         132 :     if ( rHint.ISA( ScUpdateRefHint ) )
    3074             :     {
    3075             :         //! Referenz-Update fuer Tab und Start/Ende
    3076             :     }
    3077         260 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    3078         130 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3079             :     {
    3080           5 :         pDocShell = NULL;       // ungueltig geworden
    3081             :     }
    3082         132 : }
    3083             : 
    3084             : // XTableRows
    3085             : 
    3086          72 : ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    3087             : {
    3088          72 :     SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
    3089          72 :     if ( pDocShell && nRow <= nEndRow )
    3090          71 :         return new ScTableRowObj( pDocShell, nRow, nTab );
    3091             : 
    3092           1 :     return NULL;    // falscher Index
    3093             : }
    3094             : 
    3095           2 : void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
    3096             :                                                 throw(uno::RuntimeException)
    3097             : {
    3098           2 :     SolarMutexGuard aGuard;
    3099           2 :     sal_Bool bDone = false;
    3100           3 :     if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
    3101           1 :             nStartRow+nPosition+nCount-1 <= MAXROW )
    3102             :     {
    3103             :         ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
    3104           1 :                         MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
    3105           1 :         bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSROWS, sal_True, sal_True );
    3106             :     }
    3107           2 :     if (!bDone)
    3108           1 :         throw uno::RuntimeException();      // no other exceptions specified
    3109           1 : }
    3110             : 
    3111           2 : void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
    3112             :                                                 throw(uno::RuntimeException)
    3113             : {
    3114           2 :     SolarMutexGuard aGuard;
    3115           2 :     sal_Bool bDone = false;
    3116             :     //  Der zu loeschende Bereich muss innerhalb des Objekts liegen
    3117           2 :     if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
    3118             :     {
    3119             :         ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
    3120           1 :                         MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
    3121           1 :         bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELROWS, sal_True, sal_True );
    3122             :     }
    3123           2 :     if (!bDone)
    3124           1 :         throw uno::RuntimeException();      // no other exceptions specified
    3125           1 : }
    3126             : 
    3127             : // XEnumerationAccess
    3128             : 
    3129           1 : uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
    3130             :                                                     throw(uno::RuntimeException)
    3131             : {
    3132           1 :     SolarMutexGuard aGuard;
    3133           1 :     return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableRowsEnumeration"));
    3134             : }
    3135             : 
    3136             : // XIndexAccess
    3137             : 
    3138         114 : sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException)
    3139             : {
    3140         114 :     SolarMutexGuard aGuard;
    3141         114 :     return nEndRow - nStartRow + 1;
    3142             : }
    3143             : 
    3144          72 : uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
    3145             :                             throw(lang::IndexOutOfBoundsException,
    3146             :                                     lang::WrappedTargetException, uno::RuntimeException)
    3147             : {
    3148          72 :     SolarMutexGuard aGuard;
    3149         144 :     uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
    3150          72 :     if (xRow.is())
    3151         142 :         return uno::makeAny(xRow);
    3152             :     else
    3153          73 :         throw lang::IndexOutOfBoundsException();
    3154             : }
    3155             : 
    3156           1 : uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException)
    3157             : {
    3158           1 :     SolarMutexGuard aGuard;
    3159           1 :     return getCppuType((uno::Reference<table::XCellRange>*)0);
    3160             : }
    3161             : 
    3162           1 : sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException)
    3163             : {
    3164           1 :     SolarMutexGuard aGuard;
    3165           1 :     return ( getCount() != 0 );
    3166             : }
    3167             : 
    3168             : // XPropertySet
    3169             : 
    3170        1994 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
    3171             :                                                         throw(uno::RuntimeException)
    3172             : {
    3173        1994 :     SolarMutexGuard aGuard;
    3174             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    3175        1994 :         new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
    3176        1994 :     return aRef;
    3177             : }
    3178             : 
    3179        1995 : void SAL_CALL ScTableRowsObj::setPropertyValue(
    3180             :                         const OUString& aPropertyName, const uno::Any& aValue )
    3181             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
    3182             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
    3183             :                         uno::RuntimeException)
    3184             : {
    3185        1995 :     SolarMutexGuard aGuard;
    3186        1995 :     if (!pDocShell)
    3187           0 :         throw uno::RuntimeException();
    3188             : 
    3189        1995 :     ScDocFunc& rFunc = pDocShell->GetDocFunc();
    3190        1995 :     ScDocument* pDoc = pDocShell->GetDocument();
    3191             :     SCCOLROW nRowArr[2];
    3192        1995 :     nRowArr[0] = nStartRow;
    3193        1995 :     nRowArr[1] = nEndRow;
    3194        3990 :     String aNameString(aPropertyName);
    3195             : 
    3196        1995 :     if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
    3197             :     {
    3198        1919 :         sal_Int32 nNewHeight = 0;
    3199        1919 :         if ( pDoc->IsImportingXML() && ( aValue >>= nNewHeight ) )
    3200             :         {
    3201             :             // used to set the stored row height for rows with optimal height when loading.
    3202             : 
    3203             :             // TODO: It's probably cleaner to use a different property name
    3204             :             // for this.
    3205        1882 :             pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
    3206             :         }
    3207             :         else
    3208             :         {
    3209          37 :             sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3210          37 :             if (bOpt)
    3211           0 :                 rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, sal_True, sal_True );
    3212             :             else
    3213             :             {
    3214             :                 //! manually set old heights again?
    3215             :             }
    3216             :         }
    3217             :     }
    3218          76 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
    3219             :     {
    3220          37 :         sal_Int32 nNewHeight = 0;
    3221          37 :         if ( aValue >>= nNewHeight )
    3222             :         {
    3223          37 :             if (pDoc->IsImportingXML())
    3224             :             {
    3225             :                 // TODO: This is a band-aid fix.  Eventually we need to
    3226             :                 // re-work ods' style import to get it to set styles to
    3227             :                 // ScDocument directly.
    3228          37 :                 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
    3229          37 :                 pDoc->SetManualHeight( nStartRow, nEndRow, nTab, true );
    3230             :             }
    3231             :             else
    3232             :                 rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, SC_SIZE_ORIGINAL,
    3233           0 :                                         (sal_uInt16)HMMToTwips(nNewHeight), sal_True, sal_True );
    3234             :         }
    3235             :     }
    3236          39 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
    3237             :     {
    3238          25 :         sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3239          25 :         ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
    3240          25 :         rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, eMode, 0, sal_True, sal_True );
    3241             :         //  SC_SIZE_DIRECT with size 0: hide
    3242             :     }
    3243          14 :     else if ( aNameString.EqualsAscii( SC_UNONAME_VISFLAG ) )
    3244             :     {
    3245             :         // #i116460# Shortcut to only set the flag, without drawing layer update etc.
    3246             :         // Should only be used from import filters.
    3247           0 :         pDoc->SetRowHidden(nStartRow, nEndRow, nTab, !ScUnoHelpFunctions::GetBoolFromAny( aValue ));
    3248             :     }
    3249          14 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
    3250             :     {
    3251             :         //! undo etc.
    3252          14 :         if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
    3253          14 :             pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, true);
    3254             :         else
    3255           0 :             pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, false);
    3256             :     }
    3257           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE) )
    3258             :     {
    3259             :         //! single function to set/remove all breaks?
    3260           0 :         sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3261           0 :         for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
    3262           0 :             if (bSet)
    3263           0 :                 rFunc.InsertPageBreak( false, ScAddress(0,nRow,nTab), sal_True, sal_True, sal_True );
    3264             :             else
    3265           0 :                 rFunc.RemovePageBreak( false, ScAddress(0,nRow,nTab), sal_True, sal_True, sal_True );
    3266             :     }
    3267           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
    3268             :     {
    3269             :         // #i57867# Background color is specified for row styles in the file format,
    3270             :         // so it has to be supported along with the row properties (import only).
    3271             : 
    3272             :         // Use ScCellRangeObj to set the property for all cells in the rows
    3273             :         // (this means, the "row attribute" must be set before individual cell attributes).
    3274             : 
    3275           0 :         ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
    3276           0 :         uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
    3277           0 :         xRangeObj->setPropertyValue( aPropertyName, aValue );
    3278        1995 :     }
    3279        1995 : }
    3280             : 
    3281          45 : uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyName )
    3282             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    3283             :                         uno::RuntimeException)
    3284             : {
    3285          45 :     SolarMutexGuard aGuard;
    3286          45 :     if (!pDocShell)
    3287           0 :         throw uno::RuntimeException();
    3288             : 
    3289          45 :     ScDocument* pDoc = pDocShell->GetDocument();
    3290          90 :     String aNameString(aPropertyName);
    3291          45 :     uno::Any aAny;
    3292             : 
    3293             :     //! loop over all rows for current state?
    3294             : 
    3295          45 :     if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
    3296             :     {
    3297             :         // for hidden row, return original height
    3298           0 :         sal_uInt16 nHeight = pDoc->GetOriginalHeight( nStartRow, nTab );
    3299           0 :         aAny <<= (sal_Int32)TwipsToHMM(nHeight);
    3300             :     }
    3301          45 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
    3302             :     {
    3303             :         SCROW nLastRow;
    3304          45 :         bool bVis = !pDoc->RowHidden(nStartRow, nTab, NULL, &nLastRow);
    3305          45 :         ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
    3306             :     }
    3307           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
    3308             :     {
    3309           0 :         bool bVis = pDoc->RowFiltered(nStartRow, nTab);
    3310           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
    3311             :     }
    3312           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
    3313             :     {
    3314           0 :         sal_Bool bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
    3315           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
    3316             :     }
    3317           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
    3318             :     {
    3319           0 :         ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
    3320           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
    3321             :     }
    3322           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
    3323             :     {
    3324           0 :         ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
    3325           0 :         ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
    3326             :     }
    3327           0 :     else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
    3328             :     {
    3329             :         // Use ScCellRangeObj to get the property from the cell range
    3330             :         // (for completeness only, this is not used by the XML filter).
    3331             : 
    3332           0 :         ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
    3333           0 :         uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
    3334           0 :         aAny = xRangeObj->getPropertyValue( aPropertyName );
    3335             :     }
    3336             : 
    3337          90 :     return aAny;
    3338             : }
    3339             : 
    3340           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
    3341             : 
    3342             : //------------------------------------------------------------------------
    3343             : 
    3344           0 : ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
    3345             : {
    3346           0 :     if (pDocShell)
    3347           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3348           0 : }
    3349             : 
    3350           0 : void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3351             : {
    3352             :     //  Referenz-Update interessiert hier nicht
    3353             : 
    3354           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
    3355           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3356             :     {
    3357           0 :         pDocShell = NULL;       // ungueltig geworden
    3358             :     }
    3359           0 : }
    3360             : 
    3361             : // XPropertySet
    3362             : 
    3363           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
    3364             :                                                         throw(uno::RuntimeException)
    3365             : {
    3366             :     //! muss noch
    3367           0 :     return NULL;
    3368             : }
    3369             : 
    3370           0 : void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
    3371             :                         const OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
    3372             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
    3373             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
    3374             :                         uno::RuntimeException)
    3375             : {
    3376             :     //! muss noch
    3377           0 : }
    3378             : 
    3379           0 : uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const OUString& /* aPropertyName */ )
    3380             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    3381             :                         uno::RuntimeException)
    3382             : {
    3383             :     //! muss noch
    3384           0 :     return uno::Any();
    3385             : }
    3386             : 
    3387           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
    3388             : 
    3389             : //------------------------------------------------------------------------
    3390             : 
    3391          14 : ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
    3392             :     pDocShell( pDocSh ),
    3393          14 :     nTab( nT )
    3394             : {
    3395          14 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3396          14 : }
    3397             : 
    3398          42 : ScAnnotationsObj::~ScAnnotationsObj()
    3399             : {
    3400          14 :     if (pDocShell)
    3401          12 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3402          28 : }
    3403             : 
    3404          11 : void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3405             : {
    3406             :     //! nTab bei Referenz-Update anpassen!!!
    3407             : 
    3408          22 :     if ( rHint.ISA( SfxSimpleHint ) &&
    3409          11 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3410             :     {
    3411           2 :         pDocShell = NULL;       // ungueltig geworden
    3412             :     }
    3413          11 : }
    3414             : 
    3415           6 : bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
    3416             : {
    3417           6 :     if (pDocShell)
    3418             :     {
    3419           6 :         sal_Int32 nFound = 0;
    3420           6 :         ScDocument* pDoc = pDocShell->GetDocument();
    3421           6 :         const ScNotes* pNotes = pDoc->GetNotes(nTab);
    3422          16 :         for (ScNotes::const_iterator itr = pNotes->begin(); itr != pNotes->end(); ++itr)
    3423             :         {
    3424          15 :             if (nFound == nIndex)
    3425             :             {
    3426           5 :                 rPos = ScAddress( itr->first.first, itr->first.second, nTab );
    3427           5 :                 return true;
    3428             :             }
    3429          10 :             ++nFound;
    3430             :         }
    3431             :     }
    3432           1 :     return false;
    3433             : }
    3434             : 
    3435           4 : ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
    3436             : {
    3437           4 :     if (pDocShell)
    3438             :     {
    3439           4 :         ScAddress aPos;
    3440           4 :         if ( GetAddressByIndex_Impl( nIndex, aPos ) )
    3441           3 :             return new ScAnnotationObj( pDocShell, aPos );
    3442             :     }
    3443           1 :     return NULL;
    3444             : }
    3445             : 
    3446             : // XSheetAnnotations
    3447             : 
    3448           7 : void SAL_CALL ScAnnotationsObj::insertNew(
    3449             :         const table::CellAddress& aPosition, const OUString& rText )
    3450             :                                                 throw(uno::RuntimeException)
    3451             : {
    3452           7 :     SolarMutexGuard aGuard;
    3453           7 :     if (pDocShell)
    3454             :     {
    3455             :         OSL_ENSURE( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
    3456           7 :         ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
    3457           7 :         pDocShell->GetDocFunc().ReplaceNote( aPos, rText, 0, 0, sal_True );
    3458           7 :     }
    3459           7 : }
    3460             : 
    3461           2 : void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException)
    3462             : {
    3463           2 :     SolarMutexGuard aGuard;
    3464           2 :     if (pDocShell)
    3465             :     {
    3466           2 :         ScAddress aPos;
    3467           2 :         if ( GetAddressByIndex_Impl( nIndex, aPos ) )
    3468             :         {
    3469           2 :             ScMarkData aMarkData;
    3470           2 :             aMarkData.SelectTable( aPos.Tab(), sal_True );
    3471           2 :             aMarkData.SetMultiMarkArea( ScRange(aPos) );
    3472             : 
    3473           2 :             pDocShell->GetDocFunc().DeleteContents( aMarkData, IDF_NOTE, sal_True, sal_True );
    3474             :         }
    3475           2 :     }
    3476           2 : }
    3477             : 
    3478             : // XEnumerationAccess
    3479             : 
    3480          11 : uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
    3481             :                                                     throw(uno::RuntimeException)
    3482             : {
    3483             :     //! iterate directly (more efficiently)?
    3484             : 
    3485          11 :     SolarMutexGuard aGuard;
    3486          11 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.CellAnnotationsEnumeration"));
    3487             : }
    3488             : 
    3489             : // XIndexAccess
    3490             : 
    3491          19 : sal_Int32 SAL_CALL ScAnnotationsObj::getCount() throw(uno::RuntimeException)
    3492             : {
    3493          19 :     SolarMutexGuard aGuard;
    3494          19 :     sal_uLong nCount = 0;
    3495          19 :     if (pDocShell)
    3496             :     {
    3497          19 :         ScDocument* pDoc = pDocShell->GetDocument();
    3498          19 :         nCount = pDoc->GetNotes(nTab)->size();
    3499             :     }
    3500          19 :     return nCount;
    3501             : }
    3502             : 
    3503           4 : uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
    3504             :                             throw(lang::IndexOutOfBoundsException,
    3505             :                                     lang::WrappedTargetException, uno::RuntimeException)
    3506             : {
    3507           4 :     SolarMutexGuard aGuard;
    3508           8 :     uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
    3509           4 :     if (xAnnotation.is())
    3510           6 :         return uno::makeAny(xAnnotation);
    3511             :     else
    3512           5 :         throw lang::IndexOutOfBoundsException();
    3513             : }
    3514             : 
    3515           0 : uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException)
    3516             : {
    3517           0 :     SolarMutexGuard aGuard;
    3518           0 :     return getCppuType((uno::Reference<sheet::XSheetAnnotation>*)0);
    3519             : }
    3520             : 
    3521           0 : sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException)
    3522             : {
    3523           0 :     SolarMutexGuard aGuard;
    3524           0 :     return ( getCount() != 0 );
    3525             : }
    3526             : 
    3527             : //------------------------------------------------------------------------
    3528             : 
    3529           2 : ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
    3530             :     pDocShell( pDocSh ),
    3531           2 :     nTab     ( nT )
    3532             : {
    3533           2 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3534           2 : }
    3535             : 
    3536           6 : ScScenariosObj::~ScScenariosObj()
    3537             : {
    3538           2 :     if (pDocShell)
    3539           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3540           4 : }
    3541             : 
    3542           3 : void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3543             : {
    3544           3 :     if ( rHint.ISA( ScUpdateRefHint ) )
    3545             :     {
    3546             :         //! Referenz-Update fuer Tab und Start/Ende
    3547             :     }
    3548           6 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    3549           3 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3550             :     {
    3551           2 :         pDocShell = NULL;       // ungueltig geworden
    3552             :     }
    3553           3 : }
    3554             : 
    3555             : // XScenarios
    3556             : 
    3557           0 : sal_Bool ScScenariosObj::GetScenarioIndex_Impl( const OUString& rName, SCTAB& rIndex )
    3558             : {
    3559             :     //! Case-insensitiv ????
    3560             : 
    3561           0 :     if ( pDocShell )
    3562             :     {
    3563           0 :         OUString aTabName;
    3564           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    3565           0 :         SCTAB nCount = (SCTAB)getCount();
    3566           0 :         for (SCTAB i=0; i<nCount; i++)
    3567           0 :             if (pDoc->GetName( nTab+i+1, aTabName ))
    3568           0 :                 if (aTabName.equals(rName))
    3569             :                 {
    3570           0 :                     rIndex = i;
    3571           0 :                     return sal_True;
    3572           0 :                 }
    3573             :     }
    3574             : 
    3575           0 :     return false;
    3576             : }
    3577             : 
    3578           2 : ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
    3579             : {
    3580           2 :     sal_uInt16 nCount = (sal_uInt16)getCount();
    3581           2 :     if ( pDocShell && nIndex >= 0 && nIndex < nCount )
    3582           1 :         return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
    3583             : 
    3584           1 :     return NULL;    // kein Dokument oder falscher Index
    3585             : }
    3586             : 
    3587           0 : ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const OUString& aName)
    3588             : {
    3589             :     SCTAB nIndex;
    3590           0 :     if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
    3591           0 :         return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
    3592             : 
    3593           0 :     return NULL;    // nicht gefunden
    3594             : }
    3595             : 
    3596           1 : void SAL_CALL ScScenariosObj::addNewByName( const OUString& aName,
    3597             :                                 const uno::Sequence<table::CellRangeAddress>& aRanges,
    3598             :                                 const OUString& aComment )
    3599             :                                     throw(uno::RuntimeException)
    3600             : {
    3601           1 :     SolarMutexGuard aGuard;
    3602           1 :     if ( pDocShell )
    3603             :     {
    3604           1 :         ScMarkData aMarkData;
    3605           1 :         aMarkData.SelectTable( nTab, sal_True );
    3606             : 
    3607           1 :         sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
    3608           1 :         if (nRangeCount)
    3609             :         {
    3610           1 :             const table::CellRangeAddress* pAry = aRanges.getConstArray();
    3611           2 :             for (sal_uInt16 i=0; i<nRangeCount; i++)
    3612             :             {
    3613             :                 OSL_ENSURE( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
    3614           2 :                 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
    3615           3 :                                 (SCCOL)pAry[i].EndColumn,   (SCROW)pAry[i].EndRow,   nTab );
    3616             : 
    3617           1 :                 aMarkData.SetMultiMarkArea( aRange );
    3618             :             }
    3619             :         }
    3620             : 
    3621           2 :         String aNameStr(aName);
    3622           2 :         String aCommStr(aComment);
    3623             : 
    3624           1 :         Color aColor( COL_LIGHTGRAY );  // Default
    3625           1 :         sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
    3626             : 
    3627           2 :         pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
    3628           1 :     }
    3629           1 : }
    3630             : 
    3631           0 : void SAL_CALL ScScenariosObj::removeByName( const OUString& aName )
    3632             :                                             throw(uno::RuntimeException)
    3633             : {
    3634           0 :     SolarMutexGuard aGuard;
    3635             :     SCTAB nIndex;
    3636           0 :     if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
    3637           0 :         pDocShell->GetDocFunc().DeleteTable( nTab+nIndex+1, sal_True, sal_True );
    3638           0 : }
    3639             : 
    3640             : // XEnumerationAccess
    3641             : 
    3642           1 : uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
    3643             :                                                     throw(uno::RuntimeException)
    3644             : {
    3645           1 :     SolarMutexGuard aGuard;
    3646           1 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.ScenariosEnumeration"));
    3647             : }
    3648             : 
    3649             : // XIndexAccess
    3650             : 
    3651           4 : sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException)
    3652             : {
    3653           4 :     SolarMutexGuard aGuard;
    3654           4 :     SCTAB nCount = 0;
    3655           4 :     if ( pDocShell )
    3656             :     {
    3657           4 :         ScDocument* pDoc = pDocShell->GetDocument();
    3658           4 :         if (!pDoc->IsScenario(nTab))
    3659             :         {
    3660           4 :             SCTAB nTabCount = pDoc->GetTableCount();
    3661           4 :             SCTAB nNext = nTab + 1;
    3662          12 :             while (nNext < nTabCount && pDoc->IsScenario(nNext))
    3663             :             {
    3664           4 :                 ++nCount;
    3665           4 :                 ++nNext;
    3666             :             }
    3667             :         }
    3668             :     }
    3669           4 :     return nCount;
    3670             : }
    3671             : 
    3672           2 : uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
    3673             :                             throw(lang::IndexOutOfBoundsException,
    3674             :                                     lang::WrappedTargetException, uno::RuntimeException)
    3675             : {
    3676           2 :     SolarMutexGuard aGuard;
    3677           4 :     uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
    3678           2 :     if (xScen.is())
    3679           2 :         return uno::makeAny(xScen);
    3680             :     else
    3681           3 :         throw lang::IndexOutOfBoundsException();
    3682             : }
    3683             : 
    3684           0 : uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException)
    3685             : {
    3686           0 :     SolarMutexGuard aGuard;
    3687           0 :     return getCppuType((uno::Reference<sheet::XScenario>*)0);
    3688             : }
    3689             : 
    3690           0 : sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException)
    3691             : {
    3692           0 :     SolarMutexGuard aGuard;
    3693           0 :     return ( getCount() != 0 );
    3694             : }
    3695             : 
    3696           0 : uno::Any SAL_CALL ScScenariosObj::getByName( const OUString& aName )
    3697             :             throw(container::NoSuchElementException,
    3698             :                     lang::WrappedTargetException, uno::RuntimeException)
    3699             : {
    3700           0 :     SolarMutexGuard aGuard;
    3701           0 :     uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
    3702           0 :     if (xScen.is())
    3703           0 :         return uno::makeAny(xScen);
    3704             :     else
    3705           0 :         throw container::NoSuchElementException();
    3706             : }
    3707             : 
    3708           0 : uno::Sequence<OUString> SAL_CALL ScScenariosObj::getElementNames()
    3709             :                                                 throw(uno::RuntimeException)
    3710             : {
    3711           0 :     SolarMutexGuard aGuard;
    3712           0 :     SCTAB nCount = (SCTAB)getCount();
    3713           0 :     uno::Sequence<OUString> aSeq(nCount);
    3714             : 
    3715           0 :     if ( pDocShell )    // sonst ist auch Count = 0
    3716             :     {
    3717           0 :         OUString aTabName;
    3718           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    3719           0 :         OUString* pAry = aSeq.getArray();
    3720           0 :         for (SCTAB i=0; i<nCount; i++)
    3721           0 :             if (pDoc->GetName( nTab+i+1, aTabName ))
    3722           0 :                 pAry[i] = aTabName;
    3723             :     }
    3724             : 
    3725           0 :     return aSeq;
    3726             : }
    3727             : 
    3728           0 : sal_Bool SAL_CALL ScScenariosObj::hasByName( const OUString& aName )
    3729             :                                         throw(uno::RuntimeException)
    3730             : {
    3731           0 :     SolarMutexGuard aGuard;
    3732             :     SCTAB nIndex;
    3733           0 :     return GetScenarioIndex_Impl( aName, nIndex );
    3734          93 : }
    3735             : 
    3736             : 
    3737             : 
    3738             : 
    3739             : 
    3740             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10