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

Generated by: LCOV version 1.10