LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - docuno.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1981 0.0 %
Date: 2014-04-14 Functions: 0 228 0.0 %
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           0 : static const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
     110             : {
     111             :     static const SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
     112             :     {
     113           0 :         {OUString(SC_UNO_APPLYFMDES),              0, getBooleanCppuType(),                                             0, 0},
     114           0 :         {OUString(SC_UNO_AREALINKS),               0, getCppuType((uno::Reference<sheet::XAreaLinks>*)0),               0, 0},
     115           0 :         {OUString(SC_UNO_AUTOCONTFOC),             0, getBooleanCppuType(),                                             0, 0},
     116           0 :         {OUString(SC_UNO_BASICLIBRARIES),          0, getCppuType((uno::Reference< script::XLibraryContainer >*)0),     beans::PropertyAttribute::READONLY, 0},
     117           0 :         {OUString(SC_UNO_DIALOGLIBRARIES),         0, getCppuType((uno::Reference< script::XLibraryContainer >*)0),     beans::PropertyAttribute::READONLY, 0},
     118           0 :         {OUString(SC_UNO_VBAGLOBNAME),             0, getCppuType(static_cast< const OUString * >(0)),                  beans::PropertyAttribute::READONLY, 0},
     119           0 :         {OUString(SC_UNO_CALCASSHOWN),             PROP_UNO_CALCASSHOWN, getBooleanCppuType(),                          0, 0},
     120           0 :         {OUString(SC_UNONAME_CLOCAL),              0, getCppuType((lang::Locale*)0),                                    0, 0},
     121           0 :         {OUString(SC_UNO_CJK_CLOCAL),              0, getCppuType((lang::Locale*)0),                                    0, 0},
     122           0 :         {OUString(SC_UNO_CTL_CLOCAL),              0, getCppuType((lang::Locale*)0),                                    0, 0},
     123           0 :         {OUString(SC_UNO_COLLABELRNG),             0, getCppuType((uno::Reference<sheet::XLabelRanges>*)0),             0, 0},
     124           0 :         {OUString(SC_UNO_DDELINKS),                0, getCppuType((uno::Reference<container::XNameAccess>*)0),          0, 0},
     125           0 :         {OUString(SC_UNO_DEFTABSTOP),              PROP_UNO_DEFTABSTOP, getCppuType((sal_Int16*)0),                     0, 0},
     126           0 :         {OUString(SC_UNO_EXTERNALDOCLINKS),        0, getCppuType((uno::Reference<sheet::XExternalDocLinks>*)0),        0, 0},
     127           0 :         {OUString(SC_UNO_FORBIDDEN),               0, getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0),      beans::PropertyAttribute::READONLY, 0},
     128           0 :         {OUString(SC_UNO_HASDRAWPAGES),            0, getBooleanCppuType(),                                             beans::PropertyAttribute::READONLY, 0},
     129           0 :         {OUString(SC_UNO_IGNORECASE),              PROP_UNO_IGNORECASE, getBooleanCppuType(),                           0, 0},
     130           0 :         {OUString(SC_UNO_ITERENABLED),             PROP_UNO_ITERENABLED, getBooleanCppuType(),                          0, 0},
     131           0 :         {OUString(SC_UNO_ITERCOUNT),               PROP_UNO_ITERCOUNT, getCppuType((sal_Int32*)0),                      0, 0},
     132           0 :         {OUString(SC_UNO_ITEREPSILON),             PROP_UNO_ITEREPSILON, getCppuType((double*)0),                       0, 0},
     133           0 :         {OUString(SC_UNO_LOOKUPLABELS),            PROP_UNO_LOOKUPLABELS, getBooleanCppuType(),                         0, 0},
     134           0 :         {OUString(SC_UNO_MATCHWHOLE),              PROP_UNO_MATCHWHOLE, getBooleanCppuType(),                           0, 0},
     135           0 :         {OUString(SC_UNO_NAMEDRANGES),             0, getCppuType((uno::Reference<sheet::XNamedRanges>*)0),             0, 0},
     136           0 :         {OUString(SC_UNO_DATABASERNG),             0, getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0),          0, 0},
     137           0 :         {OUString(SC_UNO_NULLDATE),                PROP_UNO_NULLDATE, getCppuType((util::Date*)0),                      0, 0},
     138           0 :         {OUString(SC_UNO_ROWLABELRNG),             0, getCppuType((uno::Reference<sheet::XLabelRanges>*)0),             0, 0},
     139           0 :         {OUString(SC_UNO_SHEETLINKS),              0, getCppuType((uno::Reference<container::XNameAccess>*)0),          0, 0},
     140           0 :         {OUString(SC_UNO_SPELLONLINE),             PROP_UNO_SPELLONLINE, getBooleanCppuType(),                          0, 0},
     141           0 :         {OUString(SC_UNO_STANDARDDEC),             PROP_UNO_STANDARDDEC, getCppuType((sal_Int16*)0),                    0, 0},
     142           0 :         {OUString(SC_UNO_REGEXENABLED),            PROP_UNO_REGEXENABLED, getBooleanCppuType(),                         0, 0},
     143           0 :         {OUString(SC_UNO_RUNTIMEUID),              0, getCppuType(static_cast< const OUString * >(0)),                  beans::PropertyAttribute::READONLY, 0},
     144           0 :         {OUString(SC_UNO_HASVALIDSIGNATURES),      0, getBooleanCppuType(),                                             beans::PropertyAttribute::READONLY, 0},
     145           0 :         {OUString(SC_UNO_ISLOADED),                0, getBooleanCppuType(),                                             0, 0},
     146           0 :         {OUString(SC_UNO_ISUNDOENABLED),           0, getBooleanCppuType(),                                             0, 0},
     147           0 :         {OUString(SC_UNO_ISADJUSTHEIGHTENABLED),   0, getBooleanCppuType(),                                             0, 0},
     148           0 :         {OUString(SC_UNO_ISEXECUTELINKENABLED),    0, getBooleanCppuType(),                                             0, 0},
     149           0 :         {OUString(SC_UNO_ISCHANGEREADONLYENABLED), 0, getBooleanCppuType(),                                             0, 0},
     150           0 :         {OUString(SC_UNO_REFERENCEDEVICE),         0, getCppuType((uno::Reference<awt::XDevice>*)0),                    beans::PropertyAttribute::READONLY, 0},
     151           0 :         {OUString("BuildId"),                      0, ::getCppuType(static_cast< const OUString * >(0)),                0, 0},
     152           0 :         {OUString(SC_UNO_CODENAME),                0, getCppuType(static_cast< const OUString * >(0)),                  0, 0},
     153           0 :         {OUString(SC_UNO_INTEROPGRABBAG),          0, ::getCppuType((uno::Sequence< beans::PropertyValue >*)0), 0, 0},
     154             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     155           0 :     };
     156           0 :     return aDocOptPropertyMap_Impl;
     157             : }
     158             : 
     159             : //! StandardDecimals als Property und vom NumberFormatter ????????
     160             : 
     161           0 : static const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
     162             : {
     163             :     static const SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
     164             :     {
     165           0 :         {OUString(SC_UNONAME_MANPAGE),  0,  getBooleanCppuType(),          0, 0 },
     166           0 :         {OUString(SC_UNONAME_NEWPAGE),  0,  getBooleanCppuType(),          0, 0 },
     167           0 :         {OUString(SC_UNONAME_CELLVIS),  0,  getBooleanCppuType(),          0, 0 },
     168           0 :         {OUString(SC_UNONAME_OWIDTH),   0,  getBooleanCppuType(),          0, 0 },
     169           0 :         {OUString(SC_UNONAME_CELLWID),  0,  getCppuType((sal_Int32*)0),    0, 0 },
     170             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     171           0 :     };
     172           0 :     return aColumnsPropertyMap_Impl;
     173             : }
     174             : 
     175           0 : static const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
     176             : {
     177             :     static const SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
     178             :     {
     179           0 :         {OUString(SC_UNONAME_CELLHGT),  0,  getCppuType((sal_Int32*)0),    0, 0 },
     180           0 :         {OUString(SC_UNONAME_CELLFILT), 0,  getBooleanCppuType(),          0, 0 },
     181           0 :         {OUString(SC_UNONAME_OHEIGHT),  0,  getBooleanCppuType(),          0, 0 },
     182           0 :         {OUString(SC_UNONAME_MANPAGE),  0,  getBooleanCppuType(),          0, 0 },
     183           0 :         {OUString(SC_UNONAME_NEWPAGE),  0,  getBooleanCppuType(),          0, 0 },
     184           0 :         {OUString(SC_UNONAME_CELLVIS),  0,  getBooleanCppuType(),          0, 0 },
     185           0 :         {OUString(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, ::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
     186           0 :         {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           0 :     };
     190           0 :     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           0 : void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
     342             : {
     343           0 :     if (pDocSh)
     344           0 :         pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
     345           0 : }
     346             : 
     347           0 : ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
     348             :     SfxBaseModel( pDocSh ),
     349             :     aPropSet( lcl_GetDocOptPropertyMap() ),
     350             :     pDocShell( pDocSh ),
     351             :     pPrintFuncCache( NULL ),
     352             :     pPrinterOptions( NULL ),
     353           0 :     maChangesListeners( m_aMutex )
     354             : {
     355             :     // pDocShell may be NULL if this is the base of a ScDocOptionsObj
     356           0 :     if ( pDocShell )
     357             :     {
     358           0 :         pDocShell->GetDocument()->AddUnoObject(*this);      // SfxModel is derived from SfxListener
     359             :     }
     360           0 : }
     361             : 
     362           0 : ScModelObj::~ScModelObj()
     363             : {
     364           0 :     if (pDocShell)
     365           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
     366             : 
     367           0 :     if (xNumberAgg.is())
     368           0 :         xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
     369             : 
     370           0 :     delete pPrintFuncCache;
     371           0 :     delete pPrinterOptions;
     372           0 : }
     373             : 
     374           0 : uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
     375             : {
     376             :     // pDocShell may be NULL if this is the base of a ScDocOptionsObj
     377           0 :     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           0 :         comphelper::increment( m_refCount );
     382             :         // waehrend des queryInterface braucht man ein Ref auf das
     383             :         // SvNumberFormatsSupplierObj, sonst wird es geloescht.
     384           0 :         uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument()->GetFormatTable() ));
     385             :         {
     386           0 :             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           0 :         xFormatter = NULL;
     392             : 
     393           0 :         if (xNumberAgg.is())
     394           0 :             xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
     395           0 :         comphelper::decrement( m_refCount );
     396             :     } // if ( !xNumberAgg.is() )
     397           0 :     return xNumberAgg;
     398             : }
     399             : 
     400           0 : ScDocument* ScModelObj::GetDocument() const
     401             : {
     402           0 :     if (pDocShell)
     403           0 :         return pDocShell->GetDocument();
     404           0 :     return NULL;
     405             : }
     406             : 
     407           0 : SfxObjectShell* ScModelObj::GetEmbeddedObject() const
     408             : {
     409           0 :     return pDocShell;
     410             : }
     411             : 
     412           0 : void ScModelObj::UpdateAllRowHeights()
     413             : {
     414           0 :     if (pDocShell)
     415           0 :         pDocShell->UpdateAllRowHeights(NULL);
     416           0 : }
     417             : 
     418           0 : void ScModelObj::BeforeXMLLoading()
     419             : {
     420           0 :     if (pDocShell)
     421           0 :         pDocShell->BeforeXMLLoading();
     422           0 : }
     423             : 
     424           0 : void ScModelObj::AfterXMLLoading(bool bRet)
     425             : {
     426           0 :     if (pDocShell)
     427           0 :         pDocShell->AfterXMLLoading(bRet);
     428           0 : }
     429             : 
     430           0 : ScSheetSaveData* ScModelObj::GetSheetSaveData()
     431             : {
     432           0 :     if (pDocShell)
     433           0 :         return pDocShell->GetSheetSaveData();
     434           0 :     return NULL;
     435             : }
     436             : 
     437           0 : void ScModelObj::RepaintRange( const ScRange& rRange )
     438             : {
     439           0 :     if (pDocShell)
     440           0 :         pDocShell->PostPaint( rRange, PAINT_GRID );
     441           0 : }
     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           0 : uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
     450             :                                                 throw(uno::RuntimeException, std::exception)
     451             : {
     452           0 :     SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
     453           0 :     SC_QUERYINTERFACE( document::XActionLockable )
     454           0 :     SC_QUERYINTERFACE( sheet::XCalculatable )
     455           0 :     SC_QUERYINTERFACE( util::XProtectable )
     456           0 :     SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
     457           0 :     SC_QUERYINTERFACE( sheet::XGoalSeek )
     458           0 :     SC_QUERYINTERFACE( sheet::XConsolidatable )
     459           0 :     SC_QUERYINTERFACE( sheet::XDocumentAuditing )
     460           0 :     SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
     461           0 :     SC_QUERYINTERFACE( view::XRenderable )
     462           0 :     SC_QUERYINTERFACE( document::XLinkTargetSupplier )
     463           0 :     SC_QUERYINTERFACE( beans::XPropertySet )
     464           0 :     SC_QUERYINTERFACE( lang::XMultiServiceFactory )
     465           0 :     SC_QUERYINTERFACE( lang::XServiceInfo )
     466           0 :     SC_QUERYINTERFACE( util::XChangesNotifier )
     467           0 :     SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
     468             : 
     469           0 :     uno::Any aRet(SfxBaseModel::queryInterface( rType ));
     470           0 :     if ( !aRet.hasValue()
     471           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
     472           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XController>*)0)
     473           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XFrame>*)0)
     474           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::script::XInvocation>*)0)
     475           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::beans::XFastPropertySet>*)0)
     476           0 :         && rType != ::getCppuType((uno::Reference< com::sun::star::awt::XWindow>*)0))
     477             :     {
     478           0 :         GetFormatter();
     479           0 :         if ( xNumberAgg.is() )
     480           0 :             aRet = xNumberAgg->queryAggregation( rType );
     481             :     }
     482             : 
     483           0 :     return aRet;
     484             : }
     485             : 
     486           0 : void SAL_CALL ScModelObj::acquire() throw()
     487             : {
     488           0 :     SfxBaseModel::acquire();
     489           0 : }
     490             : 
     491           0 : void SAL_CALL ScModelObj::release() throw()
     492             : {
     493           0 :     SfxBaseModel::release();
     494           0 : }
     495             : 
     496           0 : uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException, std::exception)
     497             : {
     498           0 :     static uno::Sequence<uno::Type> aTypes;
     499           0 :     if ( aTypes.getLength() == 0 )
     500             :     {
     501           0 :         uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
     502           0 :         long nParentLen = aParentTypes.getLength();
     503           0 :         const uno::Type* pParentPtr = aParentTypes.getConstArray();
     504             : 
     505           0 :         uno::Sequence<uno::Type> aAggTypes;
     506           0 :         if ( GetFormatter().is() )
     507             :         {
     508           0 :             const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0);
     509           0 :             uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
     510           0 :             if(aNumProv.getValueType() == rProvType)
     511             :             {
     512             :                 uno::Reference<lang::XTypeProvider> xNumProv(
     513           0 :                     *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
     514           0 :                 aAggTypes = xNumProv->getTypes();
     515           0 :             }
     516             :         }
     517           0 :         long nAggLen = aAggTypes.getLength();
     518           0 :         const uno::Type* pAggPtr = aAggTypes.getConstArray();
     519             : 
     520           0 :         const long nThisLen = 16;
     521           0 :         aTypes.realloc( nParentLen + nAggLen + nThisLen );
     522           0 :         uno::Type* pPtr = aTypes.getArray();
     523           0 :         pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0);
     524           0 :         pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
     525           0 :         pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0);
     526           0 :         pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0);
     527           0 :         pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0);
     528           0 :         pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0);
     529           0 :         pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0);
     530           0 :         pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0);
     531           0 :         pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0);
     532           0 :         pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0);
     533           0 :         pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0);
     534           0 :         pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
     535           0 :         pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0);
     536           0 :         pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
     537           0 :         pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XChangesNotifier>*)0);
     538           0 :         pPtr[nParentLen +15] = getCppuType((const uno::Reference<sheet::opencl::XOpenCLSelection>*)0);
     539             : 
     540             :         long i;
     541           0 :         for (i=0; i<nParentLen; i++)
     542           0 :             pPtr[i] = pParentPtr[i];                    // parent types first
     543             : 
     544           0 :         for (i=0; i<nAggLen; i++)
     545           0 :             pPtr[nParentLen+nThisLen+i] = pAggPtr[i];   // aggregated types last
     546             :     }
     547           0 :     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           0 : void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     557             : {
     558             :     //  Not interested in reference update hints here
     559             : 
     560           0 :     if ( rHint.ISA( SfxSimpleHint ) )
     561             :     {
     562           0 :         sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
     563           0 :         if ( nId == SFX_HINT_DYING )
     564             :         {
     565           0 :             pDocShell = NULL;       // has become invalid
     566           0 :             if (xNumberAgg.is())
     567             :             {
     568             :                 SvNumberFormatsSupplierObj* pNumFmt =
     569             :                     SvNumberFormatsSupplierObj::getImplementation(
     570           0 :                         uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
     571           0 :                 if ( pNumFmt )
     572           0 :                     pNumFmt->SetNumberFormatter( NULL );
     573             :             }
     574             : 
     575           0 :             DELETEZ( pPrintFuncCache );     // must be deleted because it has a pointer to the DocShell
     576             :         }
     577           0 :         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           0 :             DELETEZ( pPrintFuncCache );
     583             : 
     584             :             // handle "OnCalculate" sheet events (search also for VBA event handlers)
     585           0 :             if ( pDocShell )
     586             :             {
     587           0 :                 ScDocument* pDoc = pDocShell->GetDocument();
     588           0 :                 if ( pDoc->GetVbaEventProcessor().is() )
     589             :                 {
     590             :                     // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript
     591           0 :                     if ( pDoc->HasAnyCalcNotification() && pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) )
     592           0 :                         HandleCalculateEvents();
     593             :                 }
     594             :                 else
     595             :                 {
     596           0 :                     if ( pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) )
     597           0 :                         HandleCalculateEvents();
     598             :                 }
     599             :             }
     600             :         }
     601             :     }
     602           0 :     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           0 :     SfxBaseModel::Notify( rBC, rHint );     // SfxBaseModel is derived from SfxListener
     622           0 : }
     623             : 
     624             : // XSpreadsheetDocument
     625             : 
     626           0 : uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException, std::exception)
     627             : {
     628           0 :     SolarMutexGuard aGuard;
     629           0 :     if (pDocShell)
     630           0 :         return new ScTableSheetsObj(pDocShell);
     631           0 :     return NULL;
     632             : }
     633             : 
     634             : // XStyleFamiliesSupplier
     635             : 
     636           0 : uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
     637             :                                                 throw(uno::RuntimeException, std::exception)
     638             : {
     639           0 :     SolarMutexGuard aGuard;
     640           0 :     if (pDocShell)
     641           0 :         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           0 : uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException, std::exception)
    1290             : {
    1291           0 :     SolarMutexGuard aGuard;
    1292           0 :     if (pDocShell)
    1293           0 :         return new ScLinkTargetTypesObj(pDocShell);
    1294           0 :     return NULL;
    1295             : }
    1296             : 
    1297             : // XActionLockable
    1298             : 
    1299           0 : sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException, std::exception)
    1300             : {
    1301           0 :     SolarMutexGuard aGuard;
    1302           0 :     sal_Bool bLocked = false;
    1303           0 :     if (pDocShell)
    1304           0 :         bLocked = ( pDocShell->GetLockCount() != 0 );
    1305           0 :     return bLocked;
    1306             : }
    1307             : 
    1308           0 : void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException, std::exception)
    1309             : {
    1310           0 :     SolarMutexGuard aGuard;
    1311           0 :     if (pDocShell)
    1312           0 :         pDocShell->LockDocument();
    1313           0 : }
    1314             : 
    1315           0 : void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException, std::exception)
    1316             : {
    1317           0 :     SolarMutexGuard aGuard;
    1318           0 :     if (pDocShell)
    1319           0 :         pDocShell->UnlockDocument();
    1320           0 : }
    1321             : 
    1322           0 : void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException, std::exception)
    1323             : {
    1324           0 :     SolarMutexGuard aGuard;
    1325           0 :     if (pDocShell)
    1326           0 :         pDocShell->SetLockCount(nLock);
    1327           0 : }
    1328             : 
    1329           0 : sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException, std::exception)
    1330             : {
    1331           0 :     SolarMutexGuard aGuard;
    1332           0 :     sal_uInt16 nRet = 0;
    1333           0 :     if (pDocShell)
    1334             :     {
    1335           0 :         nRet = pDocShell->GetLockCount();
    1336           0 :         pDocShell->SetLockCount(0);
    1337             :     }
    1338           0 :     return nRet;
    1339             : }
    1340             : 
    1341           0 : void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
    1342             : {
    1343           0 :     SolarMutexGuard aGuard;
    1344           0 :     SfxBaseModel::lockControllers();
    1345           0 :     if (pDocShell)
    1346           0 :         pDocShell->LockPaint();
    1347           0 : }
    1348             : 
    1349           0 : void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
    1350             : {
    1351           0 :     SolarMutexGuard aGuard;
    1352           0 :     if (hasControllersLocked())
    1353             :     {
    1354           0 :         SfxBaseModel::unlockControllers();
    1355           0 :         if (pDocShell)
    1356           0 :             pDocShell->UnlockPaint();
    1357           0 :     }
    1358           0 : }
    1359             : 
    1360             : // XCalculate
    1361             : 
    1362           0 : void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException, std::exception)
    1363             : {
    1364           0 :     SolarMutexGuard aGuard;
    1365           0 :     if (pDocShell)
    1366           0 :         pDocShell->DoRecalc(true);
    1367             :     else
    1368             :     {
    1369             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1370           0 :     }
    1371           0 : }
    1372             : 
    1373           0 : void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException, std::exception)
    1374             : {
    1375           0 :     SolarMutexGuard aGuard;
    1376           0 :     if (pDocShell)
    1377           0 :         pDocShell->DoHardRecalc(true);
    1378             :     else
    1379             :     {
    1380             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1381           0 :     }
    1382           0 : }
    1383             : 
    1384           0 : sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException, std::exception)
    1385             : {
    1386           0 :     SolarMutexGuard aGuard;
    1387           0 :     if (pDocShell)
    1388           0 :         return pDocShell->GetDocument()->GetAutoCalc();
    1389             : 
    1390             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1391           0 :     return false;
    1392             : }
    1393             : 
    1394           0 : void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabledIn )
    1395             :                                                 throw(uno::RuntimeException, std::exception)
    1396             : {
    1397           0 :     bool bEnabled(bEnabledIn);
    1398           0 :     SolarMutexGuard aGuard;
    1399           0 :     if (pDocShell)
    1400             :     {
    1401           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1402           0 :         if ( pDoc->GetAutoCalc() != bEnabled )
    1403             :         {
    1404           0 :             pDoc->SetAutoCalc( bEnabled );
    1405           0 :             pDocShell->SetDocumentModified();
    1406             :         }
    1407             :     }
    1408             :     else
    1409             :     {
    1410             :         OSL_FAIL("keine DocShell");     //! Exception oder so?
    1411           0 :     }
    1412           0 : }
    1413             : 
    1414             : // XProtectable
    1415             : 
    1416           0 : void SAL_CALL ScModelObj::protect( const OUString& aPassword ) throw(uno::RuntimeException, std::exception)
    1417             : {
    1418           0 :     SolarMutexGuard aGuard;
    1419             :     // #i108245# if already protected, don't change anything
    1420           0 :     if ( pDocShell && !pDocShell->GetDocument()->IsDocProtected() )
    1421             :     {
    1422           0 :         OUString aString(aPassword);
    1423           0 :         pDocShell->GetDocFunc().Protect( TABLEID_DOC, aString, true );
    1424           0 :     }
    1425           0 : }
    1426             : 
    1427           0 : void SAL_CALL ScModelObj::unprotect( const OUString& aPassword )
    1428             :                         throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
    1429             : {
    1430           0 :     SolarMutexGuard aGuard;
    1431           0 :     if (pDocShell)
    1432             :     {
    1433           0 :         OUString aString(aPassword);
    1434           0 :         sal_Bool bDone = pDocShell->GetDocFunc().Unprotect( TABLEID_DOC, aString, true );
    1435           0 :         if (!bDone)
    1436           0 :             throw lang::IllegalArgumentException();
    1437           0 :     }
    1438           0 : }
    1439             : 
    1440           0 : sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException, std::exception)
    1441             : {
    1442           0 :     SolarMutexGuard aGuard;
    1443           0 :     if (pDocShell)
    1444           0 :         return pDocShell->GetDocument()->IsDocProtected();
    1445             : 
    1446             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1447           0 :     return false;
    1448             : }
    1449             : 
    1450             : // XDrawPagesSupplier
    1451             : 
    1452           0 : uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException, std::exception)
    1453             : {
    1454           0 :     SolarMutexGuard aGuard;
    1455           0 :     if (pDocShell)
    1456           0 :         return new ScDrawPagesObj(pDocShell);
    1457             : 
    1458             :     OSL_FAIL("keine DocShell");     //! Exception oder so?
    1459           0 :     return NULL;
    1460             : }
    1461             : 
    1462             : // XGoalSeek
    1463             : 
    1464           0 : 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           0 :     SolarMutexGuard aGuard;
    1472           0 :     sheet::GoalResult aResult;
    1473           0 :     aResult.Divergence = DBL_MAX;       // nichts gefunden
    1474           0 :     if (pDocShell)
    1475             :     {
    1476           0 :         WaitObject aWait( pDocShell->GetActiveDialogParent() );
    1477           0 :         OUString aGoalString(aGoalValue);
    1478           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1479           0 :         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           0 :                     aGoalString, fValue );
    1484           0 :         aResult.Result = fValue;
    1485           0 :         if (bFound)
    1486           0 :             aResult.Divergence = 0.0;   //! das ist gelogen
    1487             :     }
    1488           0 :     return aResult;
    1489             : }
    1490             : 
    1491             : // XConsolidatable
    1492             : 
    1493           0 : uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
    1494             :                                 sal_Bool bEmpty ) throw(uno::RuntimeException, std::exception)
    1495             : {
    1496           0 :     SolarMutexGuard aGuard;
    1497           0 :     ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
    1498           0 :     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           0 :     return pNew;
    1506             : }
    1507             : 
    1508           0 : void SAL_CALL ScModelObj::consolidate(
    1509             :     const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
    1510             :         throw (uno::RuntimeException, std::exception)
    1511             : {
    1512           0 :     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           0 :     ScConsolidationDescriptor aImpl;
    1519           0 :     aImpl.setFunction( xDescriptor->getFunction() );
    1520           0 :     aImpl.setSources( xDescriptor->getSources() );
    1521           0 :     aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
    1522           0 :     aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
    1523           0 :     aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
    1524           0 :     aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
    1525             : 
    1526           0 :     if (pDocShell)
    1527             :     {
    1528           0 :         const ScConsolidateParam& rParam = aImpl.GetParam();
    1529           0 :         pDocShell->DoConsolidate( rParam, true );
    1530           0 :         pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
    1531           0 :     }
    1532           0 : }
    1533             : 
    1534             : // XDocumentAuditing
    1535             : 
    1536           0 : void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException, std::exception)
    1537             : {
    1538           0 :     SolarMutexGuard aGuard;
    1539           0 :     if (pDocShell)
    1540           0 :         pDocShell->GetDocFunc().DetectiveRefresh();
    1541           0 : }
    1542             : 
    1543             : // XViewDataSupplier
    1544           0 : uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData(  )
    1545             :     throw (uno::RuntimeException, std::exception)
    1546             : {
    1547           0 :     uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
    1548             : 
    1549           0 :     if( !xRet.is() )
    1550             :     {
    1551           0 :         SolarMutexGuard aGuard;
    1552           0 :         if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
    1553             :         {
    1554           0 :             uno::Reference < container::XIndexContainer > xCont = document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() );
    1555           0 :             xRet.set( xCont, uno::UNO_QUERY_THROW );
    1556             : 
    1557           0 :             uno::Sequence< beans::PropertyValue > aSeq;
    1558           0 :             aSeq.realloc(1);
    1559           0 :             OUString sName;
    1560           0 :             pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
    1561           0 :             OUString sOUName(sName);
    1562           0 :             aSeq[0].Name = SC_ACTIVETABLE;
    1563           0 :             aSeq[0].Value <<= sOUName;
    1564           0 :             xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
    1565           0 :         }
    1566             :     }
    1567             : 
    1568           0 :     return xRet;
    1569             : }
    1570             : 
    1571             : //  XPropertySet (Doc-Optionen)
    1572             : //! auch an der Applikation anbieten?
    1573             : 
    1574           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
    1575             :                                                         throw(uno::RuntimeException, std::exception)
    1576             : {
    1577           0 :     SolarMutexGuard aGuard;
    1578             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    1579           0 :         new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
    1580           0 :     return aRef;
    1581             : }
    1582             : 
    1583           0 : 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           0 :     SolarMutexGuard aGuard;
    1590           0 :     OUString aString(aPropertyName);
    1591             : 
    1592           0 :     if (pDocShell)
    1593             :     {
    1594           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1595           0 :         const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
    1596           0 :         ScDocOptions aNewOpt = rOldOpt;
    1597             :         //  Don't recalculate while loading XML, when the formula text is stored
    1598             :         //  Recalculation after loading is handled separately.
    1599           0 :         bool bHardRecalc = !pDoc->IsImportingXML();
    1600             : 
    1601           0 :         sal_Bool bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropSet.getPropertyMap(), aPropertyName, aValue );
    1602           0 :         if (bOpt)
    1603             :         {
    1604             :             // done...
    1605           0 :             if ( aString.equalsAscii( SC_UNO_IGNORECASE ) ||
    1606           0 :                  aString.equalsAscii( SC_UNONAME_REGEXP ) ||
    1607           0 :                  aString.equalsAscii( SC_UNO_LOOKUPLABELS ) )
    1608           0 :                 bHardRecalc = false;
    1609             :         }
    1610           0 :         else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
    1611             :         {
    1612           0 :             lang::Locale aLocale;
    1613           0 :             if ( aValue >>= aLocale )
    1614             :             {
    1615             :                 LanguageType eLatin, eCjk, eCtl;
    1616           0 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1617           0 :                 eLatin = ScUnoConversion::GetLanguage(aLocale);
    1618           0 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1619           0 :             }
    1620             :         }
    1621           0 :         else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
    1622             :         {
    1623           0 :             OUString sCodeName;
    1624           0 :             if ( aValue >>= sCodeName )
    1625           0 :                 pDoc->SetCodeName( sCodeName );
    1626             :         }
    1627           0 :         else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
    1628             :         {
    1629           0 :             lang::Locale aLocale;
    1630           0 :             if ( aValue >>= aLocale )
    1631             :             {
    1632             :                 LanguageType eLatin, eCjk, eCtl;
    1633           0 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1634           0 :                 eCjk = ScUnoConversion::GetLanguage(aLocale);
    1635           0 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1636           0 :             }
    1637             :         }
    1638           0 :         else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
    1639             :         {
    1640           0 :             lang::Locale aLocale;
    1641           0 :             if ( aValue >>= aLocale )
    1642             :             {
    1643             :                 LanguageType eLatin, eCjk, eCtl;
    1644           0 :                 pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1645           0 :                 eCtl = ScUnoConversion::GetLanguage(aLocale);
    1646           0 :                 pDoc->SetLanguage( eLatin, eCjk, eCtl );
    1647           0 :             }
    1648             :         }
    1649           0 :         else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
    1650             :         {
    1651             :             //  model is created if not there
    1652           0 :             ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
    1653           0 :             pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1654             : 
    1655           0 :             SfxBindings* pBindings = pDocShell->GetViewBindings();
    1656           0 :             if (pBindings)
    1657           0 :                 pBindings->Invalidate( SID_FM_OPEN_READONLY );
    1658             :         }
    1659           0 :         else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
    1660             :         {
    1661             :             //  model is created if not there
    1662           0 :             ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
    1663           0 :             pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1664             : 
    1665           0 :             SfxBindings* pBindings = pDocShell->GetViewBindings();
    1666           0 :             if (pBindings)
    1667           0 :                 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
    1668             :         }
    1669           0 :         else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
    1670             :         {
    1671           0 :             pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1672             :         }
    1673           0 :         else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
    1674             :         {
    1675           0 :             sal_Bool bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    1676           0 :             pDoc->EnableUndo( bUndoEnabled );
    1677           0 :             pDocShell->GetUndoManager()->SetMaxUndoActionCount(
    1678             :                 bUndoEnabled
    1679           0 :                 ? officecfg::Office::Common::Undo::Steps::get() : 0);
    1680             :         }
    1681           0 :         else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
    1682             :         {
    1683           0 :             bool bOldAdjustHeightEnabled = pDoc->IsAdjustHeightEnabled();
    1684           0 :             bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    1685           0 :             if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
    1686           0 :                 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
    1687             :         }
    1688           0 :         else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
    1689             :         {
    1690           0 :             pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1691             :         }
    1692           0 :         else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
    1693             :         {
    1694           0 :             pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
    1695             :         }
    1696           0 :         else if ( aString.equalsAscii( "BuildId" ) )
    1697             :         {
    1698           0 :             aValue >>= maBuildId;
    1699             :         }
    1700           0 :         else if ( aString.equalsAscii( "SavedObject" ) )    // set from chart after saving
    1701             :         {
    1702           0 :             OUString aObjName;
    1703           0 :             aValue >>= aObjName;
    1704           0 :             if ( !aObjName.isEmpty() )
    1705           0 :                 pDoc->RestoreChartListener( aObjName );
    1706             :         }
    1707           0 :         else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
    1708             :         {
    1709           0 :             setGrabBagItem(aValue);
    1710             :         }
    1711             : 
    1712           0 :         if ( aNewOpt != rOldOpt )
    1713             :         {
    1714           0 :             pDoc->SetDocOptions( aNewOpt );
    1715             :             //! Recalc only for options that need it?
    1716           0 :             if ( bHardRecalc )
    1717           0 :                 pDocShell->DoHardRecalc( true );
    1718           0 :             pDocShell->SetDocumentModified();
    1719           0 :         }
    1720           0 :     }
    1721           0 : }
    1722             : 
    1723           0 : uno::Any SAL_CALL ScModelObj::getPropertyValue( const OUString& aPropertyName )
    1724             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    1725             :                         uno::RuntimeException, std::exception)
    1726             : {
    1727           0 :     SolarMutexGuard aGuard;
    1728           0 :     OUString aString(aPropertyName);
    1729           0 :     uno::Any aRet;
    1730             : 
    1731           0 :     if (pDocShell)
    1732             :     {
    1733           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1734           0 :         const ScDocOptions& rOpt = pDoc->GetDocOptions();
    1735           0 :         aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropSet.getPropertyMap(), aPropertyName );
    1736           0 :         if ( aRet.hasValue() )
    1737             :         {
    1738             :             // done...
    1739             :         }
    1740           0 :         else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
    1741             :         {
    1742             :             LanguageType eLatin, eCjk, eCtl;
    1743           0 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1744             : 
    1745           0 :             lang::Locale aLocale;
    1746           0 :             ScUnoConversion::FillLocale( aLocale, eLatin );
    1747           0 :             aRet <<= aLocale;
    1748             :         }
    1749           0 :         else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
    1750             :         {
    1751           0 :             OUString sCodeName = pDoc->GetCodeName();
    1752           0 :             aRet <<= sCodeName;
    1753             :         }
    1754             : 
    1755           0 :         else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
    1756             :         {
    1757             :             LanguageType eLatin, eCjk, eCtl;
    1758           0 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1759             : 
    1760           0 :             lang::Locale aLocale;
    1761           0 :             ScUnoConversion::FillLocale( aLocale, eCjk );
    1762           0 :             aRet <<= aLocale;
    1763             :         }
    1764           0 :         else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
    1765             :         {
    1766             :             LanguageType eLatin, eCjk, eCtl;
    1767           0 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
    1768             : 
    1769           0 :             lang::Locale aLocale;
    1770           0 :             ScUnoConversion::FillLocale( aLocale, eCtl );
    1771           0 :             aRet <<= aLocale;
    1772             :         }
    1773           0 :         else if ( aString.equalsAscii( SC_UNO_NAMEDRANGES ) )
    1774             :         {
    1775           0 :             aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
    1776             :         }
    1777           0 :         else if ( aString.equalsAscii( SC_UNO_DATABASERNG ) )
    1778             :         {
    1779           0 :             aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
    1780             :         }
    1781           0 :         else if ( aString.equalsAscii( SC_UNO_UNNAMEDDBRNG ) )
    1782             :         {
    1783           0 :             aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
    1784             :         }
    1785           0 :         else if ( aString.equalsAscii( SC_UNO_COLLABELRNG ) )
    1786             :         {
    1787           0 :             aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, true ));
    1788             :         }
    1789           0 :         else if ( aString.equalsAscii( SC_UNO_ROWLABELRNG ) )
    1790             :         {
    1791           0 :             aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, false ));
    1792             :         }
    1793           0 :         else if ( aString.equalsAscii( SC_UNO_AREALINKS ) )
    1794             :         {
    1795           0 :             aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
    1796             :         }
    1797           0 :         else if ( aString.equalsAscii( SC_UNO_DDELINKS ) )
    1798             :         {
    1799           0 :             aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
    1800             :         }
    1801           0 :         else if ( aString.equalsAscii( SC_UNO_EXTERNALDOCLINKS ) )
    1802             :         {
    1803           0 :             aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
    1804             :         }
    1805           0 :         else if ( aString.equalsAscii( SC_UNO_SHEETLINKS ) )
    1806             :         {
    1807           0 :             aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
    1808             :         }
    1809           0 :         else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
    1810             :         {
    1811             :             // default for no model is TRUE
    1812           0 :             ScDrawLayer* pModel = pDoc->GetDrawLayer();
    1813           0 :             sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
    1814           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
    1815             :         }
    1816           0 :         else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
    1817             :         {
    1818             :             // default for no model is FALSE
    1819           0 :             ScDrawLayer* pModel = pDoc->GetDrawLayer();
    1820           0 :             sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : false;
    1821           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
    1822             :         }
    1823           0 :         else if ( aString.equalsAscii( SC_UNO_FORBIDDEN ) )
    1824             :         {
    1825           0 :             aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
    1826             :         }
    1827           0 :         else if ( aString.equalsAscii( SC_UNO_HASDRAWPAGES ) )
    1828             :         {
    1829           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
    1830             :         }
    1831           0 :         else if ( aString.equalsAscii( SC_UNO_BASICLIBRARIES ) )
    1832             :         {
    1833           0 :             aRet <<= pDocShell->GetBasicContainer();
    1834             :         }
    1835           0 :         else if ( aString.equalsAscii( SC_UNO_DIALOGLIBRARIES ) )
    1836             :         {
    1837           0 :             aRet <<= pDocShell->GetDialogContainer();
    1838             :         }
    1839           0 :         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           0 :         else if ( aString.equalsAscii( SC_UNO_RUNTIMEUID ) )
    1849             :         {
    1850           0 :             aRet <<= getRuntimeUID();
    1851             :         }
    1852           0 :         else if ( aString.equalsAscii( SC_UNO_HASVALIDSIGNATURES ) )
    1853             :         {
    1854           0 :             aRet <<= hasValidSignatures();
    1855             :         }
    1856           0 :         else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
    1857             :         {
    1858           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
    1859             :         }
    1860           0 :         else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
    1861             :         {
    1862           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
    1863             :         }
    1864           0 :         else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
    1865             :         {
    1866           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
    1867             :         }
    1868           0 :         else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
    1869             :         {
    1870           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
    1871             :         }
    1872           0 :         else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
    1873             :         {
    1874           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
    1875             :         }
    1876           0 :         else if ( aString.equalsAscii( SC_UNO_REFERENCEDEVICE ) )
    1877             :         {
    1878           0 :             VCLXDevice* pXDev = new VCLXDevice();
    1879           0 :             pXDev->SetOutputDevice( pDoc->GetRefDevice() );
    1880           0 :             aRet <<= uno::Reference< awt::XDevice >( pXDev );
    1881             :         }
    1882           0 :         else if ( aString.equalsAscii( "BuildId" ) )
    1883             :         {
    1884           0 :             aRet <<= maBuildId;
    1885             :         }
    1886           0 :         else if ( aString.equalsAscii( "InternalDocument" ) )
    1887             :         {
    1888           0 :             ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
    1889             :         }
    1890           0 :         else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
    1891             :         {
    1892           0 :             getGrabBagItem(aRet);
    1893             :         }
    1894             :     }
    1895             : 
    1896           0 :     return aRet;
    1897             : }
    1898             : 
    1899           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
    1900             : 
    1901             : // XMultiServiceFactory
    1902             : 
    1903           0 : css::uno::Reference<css::uno::XInterface> ScModelObj::create(
    1904             :     OUString const & aServiceSpecifier,
    1905             :     css::uno::Sequence<css::uno::Any> const * arguments)
    1906             : {
    1907           0 :     uno::Reference<uno::XInterface> xRet;
    1908           0 :     OUString aNameStr(aServiceSpecifier);
    1909           0 :     sal_uInt16 nType = ScServiceProvider::GetProviderType(aNameStr);
    1910           0 :     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           0 :         switch ( nType )
    1915             :         {
    1916           0 :             case SC_SERVICE_GRADTAB:    xRet.set(xDrawGradTab);     break;
    1917           0 :             case SC_SERVICE_HATCHTAB:   xRet.set(xDrawHatchTab);    break;
    1918           0 :             case SC_SERVICE_BITMAPTAB:  xRet.set(xDrawBitmapTab);   break;
    1919           0 :             case SC_SERVICE_TRGRADTAB:  xRet.set(xDrawTrGradTab);   break;
    1920           0 :             case SC_SERVICE_MARKERTAB:  xRet.set(xDrawMarkerTab);   break;
    1921           0 :             case SC_SERVICE_DASHTAB:    xRet.set(xDrawDashTab);     break;
    1922           0 :             case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv);   break;
    1923           0 :             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           0 :                 ( 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           0 :         if ( !xRet.is() && bCreate )
    1936             :         {
    1937           0 :             xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
    1938             : 
    1939             :             //  store created instance
    1940           0 :             switch ( nType )
    1941             :             {
    1942           0 :                 case SC_SERVICE_GRADTAB:    xDrawGradTab.set(xRet);     break;
    1943           0 :                 case SC_SERVICE_HATCHTAB:   xDrawHatchTab.set(xRet);    break;
    1944           0 :                 case SC_SERVICE_BITMAPTAB:  xDrawBitmapTab.set(xRet);   break;
    1945           0 :                 case SC_SERVICE_TRGRADTAB:  xDrawTrGradTab.set(xRet);   break;
    1946           0 :                 case SC_SERVICE_MARKERTAB:  xDrawMarkerTab.set(xRet);   break;
    1947           0 :                 case SC_SERVICE_DASHTAB:    xDrawDashTab.set(xRet);     break;
    1948           0 :                 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet);   break;
    1949           0 :                 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           0 :             xRet = arguments == 0
    1961             :                 ? SvxFmMSFactory::createInstance(aServiceSpecifier)
    1962             :                 : SvxFmMSFactory::createInstanceWithArguments(
    1963           0 :                     aServiceSpecifier, *arguments);
    1964             :             // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
    1965             :         }
    1966           0 :         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           0 :         uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
    1974           0 :         if ( xShape.is() )
    1975             :         {
    1976           0 :             xRet.clear();               // for aggregation, xShape must be the object's only ref
    1977           0 :             new ScShapeObj( xShape );   // aggregates object and modifies xShape
    1978           0 :             xRet.set(xShape);
    1979           0 :         }
    1980             :     }
    1981           0 :     return xRet;
    1982             : }
    1983             : 
    1984           0 : uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
    1985             :                                 const OUString& aServiceSpecifier )
    1986             :                                 throw(uno::Exception, uno::RuntimeException, std::exception)
    1987             : {
    1988           0 :     SolarMutexGuard aGuard;
    1989           0 :     return create(aServiceSpecifier, 0);
    1990             : }
    1991             : 
    1992           0 : 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           0 :     SolarMutexGuard aGuard;
    2000           0 :     uno::Reference<uno::XInterface> xInt(create(ServiceSpecifier, &aArgs));
    2001             : 
    2002           0 :     if ( aArgs.getLength() )
    2003             :     {
    2004             :         //  used only for cell value binding so far - it can be initialized after creating
    2005             : 
    2006           0 :         uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
    2007           0 :         if ( xInit.is() )
    2008           0 :             xInit->initialize( aArgs );
    2009             :     }
    2010             : 
    2011           0 :     return xInt;
    2012             : }
    2013             : 
    2014           0 : uno::Sequence<OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
    2015             :                                                 throw(uno::RuntimeException, std::exception)
    2016             : {
    2017           0 :     SolarMutexGuard aGuard;
    2018             : 
    2019             :     //! warum sind die Parameter bei concatServiceNames nicht const ???
    2020             :     //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
    2021             :     //!                            SvxFmMSFactory::getAvailableServiceNames() );
    2022             : 
    2023           0 :     uno::Sequence<OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
    2024           0 :     uno::Sequence<OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
    2025             : 
    2026           0 :     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           0 : sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
    2036             :                                                     throw(uno::RuntimeException, std::exception)
    2037             : {
    2038           0 :     return cppu::supportsService(this, rServiceName);
    2039             : }
    2040             : 
    2041           0 : uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
    2042             :                                                     throw(uno::RuntimeException, std::exception)
    2043             : {
    2044           0 :     uno::Sequence<OUString> aRet(3);
    2045           0 :     aRet[0] = SCMODELOBJ_SERVICE;
    2046           0 :     aRet[1] = SCDOCSETTINGS_SERVICE;
    2047           0 :     aRet[2] = SCDOC_SERVICE;
    2048           0 :     return aRet;
    2049             : }
    2050             : 
    2051             : // XUnoTunnel
    2052             : 
    2053           0 : sal_Int64 SAL_CALL ScModelObj::getSomething(
    2054             :                 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
    2055             : {
    2056           0 :     if ( rId.getLength() == 16 &&
    2057           0 :           0 == memcmp( getUnoTunnelId().getConstArray(),
    2058           0 :                                     rId.getConstArray(), 16 ) )
    2059             :     {
    2060           0 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
    2061             :     }
    2062             : 
    2063           0 :     if ( rId.getLength() == 16 &&
    2064           0 :         0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
    2065           0 :                                     rId.getConstArray(), 16 ) )
    2066             :     {
    2067           0 :         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           0 :     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
    2074           0 :     if ( nRet )
    2075           0 :         return nRet;
    2076             : 
    2077           0 :     if ( GetFormatter().is() )
    2078             :     {
    2079           0 :         const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0);
    2080           0 :         uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
    2081           0 :         if(aNumTunnel.getValueType() == rTunnelType)
    2082             :         {
    2083             :             uno::Reference<lang::XUnoTunnel> xTunnelAgg(
    2084           0 :                 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
    2085           0 :             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           0 : const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
    2098             : {
    2099           0 :     return theScModelObjUnoTunnelId::get().getSeq();
    2100             : }
    2101             : 
    2102           0 : ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
    2103             : {
    2104           0 :     ScModelObj* pRet = NULL;
    2105           0 :     uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
    2106           0 :     if (xUT.is())
    2107           0 :         pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
    2108           0 :     return pRet;
    2109             : }
    2110             : 
    2111             : // XChangesNotifier
    2112             : 
    2113           0 : void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
    2114             :     throw (uno::RuntimeException, std::exception)
    2115             : {
    2116           0 :     SolarMutexGuard aGuard;
    2117           0 :     maChangesListeners.addInterface( aListener );
    2118           0 : }
    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           0 : bool ScModelObj::HasChangesListeners() const
    2128             : {
    2129           0 :     if ( maChangesListeners.getLength() > 0 )
    2130           0 :         return true;
    2131             : 
    2132             :     // "change" event set in any sheet?
    2133           0 :     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           0 : ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
    2381           0 :     pDocShell( pDocSh )
    2382             : {
    2383           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2384           0 : }
    2385             : 
    2386           0 : ScDrawPagesObj::~ScDrawPagesObj()
    2387             : {
    2388           0 :     if (pDocShell)
    2389           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2390           0 : }
    2391             : 
    2392           0 : void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2393             : {
    2394             :     //  Referenz-Update interessiert hier nicht
    2395             : 
    2396           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
    2397           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2398             :     {
    2399           0 :         pDocShell = NULL;       // ungueltig geworden
    2400             :     }
    2401           0 : }
    2402             : 
    2403           0 : uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2404             : {
    2405           0 :     if (pDocShell)
    2406             :     {
    2407           0 :         ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
    2408             :         OSL_ENSURE(pDrawLayer,"kann Draw-Layer nicht anlegen");
    2409           0 :         if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
    2410             :         {
    2411           0 :             SdrPage* pPage = pDrawLayer->GetPage((sal_uInt16)nIndex);
    2412             :             OSL_ENSURE(pPage,"Draw-Page nicht gefunden");
    2413           0 :             if (pPage)
    2414             :             {
    2415           0 :                 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
    2416             :             }
    2417             :         }
    2418             :     }
    2419           0 :     return NULL;
    2420             : }
    2421             : 
    2422             : // XDrawPages
    2423             : 
    2424           0 : uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
    2425             :                                             throw(uno::RuntimeException, std::exception)
    2426             : {
    2427           0 :     SolarMutexGuard aGuard;
    2428           0 :     uno::Reference<drawing::XDrawPage> xRet;
    2429           0 :     if (pDocShell)
    2430             :     {
    2431           0 :         OUString aNewName;
    2432           0 :         pDocShell->GetDocument()->CreateValidTabName(aNewName);
    2433           0 :         if ( pDocShell->GetDocFunc().InsertTable( static_cast<SCTAB>(nPos),
    2434           0 :                                                   aNewName, true, true ) )
    2435           0 :             xRet.set(GetObjectByIndex_Impl( nPos ));
    2436             :     }
    2437           0 :     return xRet;
    2438             : }
    2439             : 
    2440           0 : void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
    2441             :                                             throw(uno::RuntimeException, std::exception)
    2442             : {
    2443           0 :     SolarMutexGuard aGuard;
    2444           0 :     SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
    2445           0 :     if ( pDocShell && pImp )
    2446             :     {
    2447           0 :         SdrPage* pPage = pImp->GetSdrPage();
    2448           0 :         if (pPage)
    2449             :         {
    2450           0 :             SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
    2451           0 :             pDocShell->GetDocFunc().DeleteTable( nPageNum, true, true );
    2452             :         }
    2453           0 :     }
    2454           0 : }
    2455             : 
    2456             : // XIndexAccess
    2457             : 
    2458           0 : sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException, std::exception)
    2459             : {
    2460           0 :     SolarMutexGuard aGuard;
    2461           0 :     if (pDocShell)
    2462           0 :         return pDocShell->GetDocument()->GetTableCount();
    2463           0 :     return 0;
    2464             : }
    2465             : 
    2466           0 : uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
    2467             :                             throw(lang::IndexOutOfBoundsException,
    2468             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    2469             : {
    2470           0 :     SolarMutexGuard aGuard;
    2471           0 :     uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
    2472           0 :     if (xPage.is())
    2473           0 :         return uno::makeAny(xPage);
    2474             :     else
    2475           0 :         throw lang::IndexOutOfBoundsException();
    2476             : }
    2477             : 
    2478           0 : uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException, std::exception)
    2479             : {
    2480           0 :     SolarMutexGuard aGuard;
    2481           0 :     return getCppuType((uno::Reference<drawing::XDrawPage>*)0);
    2482             : }
    2483             : 
    2484           0 : sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException, std::exception)
    2485             : {
    2486           0 :     SolarMutexGuard aGuard;
    2487           0 :     return ( getCount() != 0 );
    2488             : }
    2489             : 
    2490           0 : ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
    2491           0 :     pDocShell( pDocSh )
    2492             : {
    2493           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2494           0 : }
    2495             : 
    2496           0 : ScTableSheetsObj::~ScTableSheetsObj()
    2497             : {
    2498           0 :     if (pDocShell)
    2499           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2500           0 : }
    2501             : 
    2502           0 : void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2503             : {
    2504             :     //  Referenz-Update interessiert hier nicht
    2505             : 
    2506           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
    2507           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2508             :     {
    2509           0 :         pDocShell = NULL;       // ungueltig geworden
    2510             :     }
    2511           0 : }
    2512             : 
    2513             : // XSpreadsheets
    2514             : 
    2515           0 : ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2516             : {
    2517           0 :     if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
    2518           0 :         return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
    2519             : 
    2520           0 :     return NULL;
    2521             : }
    2522             : 
    2523           0 : ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const OUString& aName) const
    2524             : {
    2525           0 :     if (pDocShell)
    2526             :     {
    2527             :         SCTAB nIndex;
    2528           0 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2529           0 :             return new ScTableSheetObj( pDocShell, nIndex );
    2530             :     }
    2531           0 :     return NULL;
    2532             : }
    2533             : 
    2534           0 : void SAL_CALL ScTableSheetsObj::insertNewByName( const OUString& aName, sal_Int16 nPosition )
    2535             :                                                 throw(uno::RuntimeException, std::exception)
    2536             : {
    2537           0 :     SolarMutexGuard aGuard;
    2538           0 :     sal_Bool bDone = false;
    2539           0 :     if (pDocShell)
    2540             :     {
    2541           0 :         OUString aNamStr(aName);
    2542           0 :         bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, true, true );
    2543             :     }
    2544           0 :     if (!bDone)
    2545           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2546           0 : }
    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           0 : void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
    2698             :                                 throw(container::NoSuchElementException,
    2699             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    2700             : {
    2701           0 :     SolarMutexGuard aGuard;
    2702           0 :     sal_Bool bDone = false;
    2703           0 :     if (pDocShell)
    2704             :     {
    2705             :         SCTAB nIndex;
    2706           0 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2707           0 :             bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, true, true );
    2708             :         else // not found
    2709           0 :             throw container::NoSuchElementException();
    2710             :     }
    2711             : 
    2712           0 :     if (!bDone)
    2713           0 :         throw uno::RuntimeException();      // NoSuchElementException is handled above
    2714           0 : }
    2715             : 
    2716           0 : 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           0 :     ScDocument* pDocDest = pDocShell->GetDocument();
    2723             : 
    2724             :     // Source document docShell
    2725           0 :     if ( !xDocSrc.is() )
    2726           0 :         throw uno::RuntimeException();
    2727           0 :     ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc);
    2728           0 :     ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject());
    2729             : 
    2730             :     // SourceSheet Position and does srcName exists ?
    2731             :     SCTAB nIndexSrc;
    2732           0 :     if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) )
    2733           0 :         throw lang::IllegalArgumentException();
    2734             : 
    2735             :     // Check the validity of destination index.
    2736           0 :     SCTAB nCount = pDocDest->GetTableCount();
    2737           0 :     SCTAB nIndexDest = static_cast<SCTAB>(nDestPosition);
    2738           0 :     if (nIndexDest > nCount || nIndexDest < 0)
    2739           0 :         throw lang::IndexOutOfBoundsException();
    2740             : 
    2741             :     // Transfert Tab
    2742           0 :     bool bInsertNew = true;
    2743           0 :     bool bNotifyAndPaint = true;
    2744             :     pDocShell->TransferTab(
    2745           0 :         *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint );
    2746             : 
    2747           0 :     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           0 : uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
    2806             :                                                     throw(uno::RuntimeException, std::exception)
    2807             : {
    2808           0 :     SolarMutexGuard aGuard;
    2809           0 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetsEnumeration"));
    2810             : }
    2811             : 
    2812             : // XIndexAccess
    2813             : 
    2814           0 : sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException, std::exception)
    2815             : {
    2816           0 :     SolarMutexGuard aGuard;
    2817           0 :     if (pDocShell)
    2818           0 :         return pDocShell->GetDocument()->GetTableCount();
    2819           0 :     return 0;
    2820             : }
    2821             : 
    2822           0 : uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
    2823             :                             throw(lang::IndexOutOfBoundsException,
    2824             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    2825             : {
    2826           0 :     SolarMutexGuard aGuard;
    2827           0 :     uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
    2828           0 :     if (xSheet.is())
    2829           0 :         return uno::makeAny(xSheet);
    2830             :     else
    2831           0 :         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           0 : uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
    2850             :             throw(container::NoSuchElementException,
    2851             :                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    2852             : {
    2853           0 :     SolarMutexGuard aGuard;
    2854           0 :     uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
    2855           0 :     if (xSheet.is())
    2856           0 :         return uno::makeAny(xSheet);
    2857             :     else
    2858           0 :         throw container::NoSuchElementException();
    2859             : }
    2860             : 
    2861           0 : uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
    2862             :                                                 throw(uno::RuntimeException, std::exception)
    2863             : {
    2864           0 :     SolarMutexGuard aGuard;
    2865           0 :     if (pDocShell)
    2866             :     {
    2867           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    2868           0 :         SCTAB nCount = pDoc->GetTableCount();
    2869           0 :         OUString aName;
    2870           0 :         uno::Sequence<OUString> aSeq(nCount);
    2871           0 :         OUString* pAry = aSeq.getArray();
    2872           0 :         for (SCTAB i=0; i<nCount; i++)
    2873             :         {
    2874           0 :             pDoc->GetName( i, aName );
    2875           0 :             pAry[i] = aName;
    2876             :         }
    2877           0 :         return aSeq;
    2878             :     }
    2879           0 :     return uno::Sequence<OUString>();
    2880             : }
    2881             : 
    2882           0 : sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const OUString& aName )
    2883             :                                         throw(uno::RuntimeException, std::exception)
    2884             : {
    2885           0 :     SolarMutexGuard aGuard;
    2886           0 :     if (pDocShell)
    2887             :     {
    2888             :         SCTAB nIndex;
    2889           0 :         if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
    2890           0 :             return sal_True;
    2891             :     }
    2892           0 :     return false;
    2893             : }
    2894             : 
    2895           0 : ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
    2896             :     pDocShell( pDocSh ),
    2897             :     nTab     ( nT ),
    2898             :     nStartCol( nSC ),
    2899           0 :     nEndCol  ( nEC )
    2900             : {
    2901           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    2902           0 : }
    2903             : 
    2904           0 : ScTableColumnsObj::~ScTableColumnsObj()
    2905             : {
    2906           0 :     if (pDocShell)
    2907           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    2908           0 : }
    2909             : 
    2910           0 : void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    2911             : {
    2912           0 :     if ( rHint.ISA( ScUpdateRefHint ) )
    2913             :     {
    2914             :         //! Referenz-Update fuer Tab und Start/Ende
    2915             :     }
    2916           0 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    2917           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    2918             :     {
    2919           0 :         pDocShell = NULL;       // ungueltig geworden
    2920             :     }
    2921           0 : }
    2922             : 
    2923             : // XTableColumns
    2924             : 
    2925           0 : ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    2926             : {
    2927           0 :     SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
    2928           0 :     if ( pDocShell && nCol <= nEndCol )
    2929           0 :         return new ScTableColumnObj( pDocShell, nCol, nTab );
    2930             : 
    2931           0 :     return NULL;    // falscher Index
    2932             : }
    2933             : 
    2934           0 : ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
    2935             : {
    2936           0 :     SCCOL nCol = 0;
    2937           0 :     OUString aString(aName);
    2938           0 :     if ( ::AlphaToCol( nCol, aString) )
    2939           0 :         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
    2940           0 :             return new ScTableColumnObj( pDocShell, nCol, nTab );
    2941             : 
    2942           0 :     return NULL;
    2943             : }
    2944             : 
    2945           0 : void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
    2946             :                                                 throw(uno::RuntimeException, std::exception)
    2947             : {
    2948           0 :     SolarMutexGuard aGuard;
    2949           0 :     sal_Bool bDone = false;
    2950           0 :     if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
    2951           0 :             nStartCol+nPosition+nCount-1 <= MAXCOL )
    2952             :     {
    2953             :         ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
    2954           0 :                         (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
    2955           0 :         bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSCOLS, true, true );
    2956             :     }
    2957           0 :     if (!bDone)
    2958           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2959           0 : }
    2960             : 
    2961           0 : void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
    2962             :                                                 throw(uno::RuntimeException, std::exception)
    2963             : {
    2964           0 :     SolarMutexGuard aGuard;
    2965           0 :     sal_Bool bDone = false;
    2966             :     //  Der zu loeschende Bereich muss innerhalb des Objekts liegen
    2967           0 :     if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
    2968             :     {
    2969             :         ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
    2970           0 :                         (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
    2971           0 :         bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELCOLS, true, true );
    2972             :     }
    2973           0 :     if (!bDone)
    2974           0 :         throw uno::RuntimeException();      // no other exceptions specified
    2975           0 : }
    2976             : 
    2977             : // XEnumerationAccess
    2978             : 
    2979           0 : uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
    2980             :                                                     throw(uno::RuntimeException, std::exception)
    2981             : {
    2982           0 :     SolarMutexGuard aGuard;
    2983           0 :     return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableColumnsEnumeration"));
    2984             : }
    2985             : 
    2986             : // XIndexAccess
    2987             : 
    2988           0 : sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException, std::exception)
    2989             : {
    2990           0 :     SolarMutexGuard aGuard;
    2991           0 :     return nEndCol - nStartCol + 1;
    2992             : }
    2993             : 
    2994           0 : uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
    2995             :                             throw(lang::IndexOutOfBoundsException,
    2996             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    2997             : {
    2998           0 :     SolarMutexGuard aGuard;
    2999           0 :     uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
    3000           0 :     if (xColumn.is())
    3001           0 :         return uno::makeAny(xColumn);
    3002             :     else
    3003           0 :         throw lang::IndexOutOfBoundsException();
    3004             : }
    3005             : 
    3006           0 : uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException, std::exception)
    3007             : {
    3008           0 :     SolarMutexGuard aGuard;
    3009           0 :     return getCppuType((uno::Reference<table::XCellRange>*)0);
    3010             : }
    3011             : 
    3012           0 : sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException, std::exception)
    3013             : {
    3014           0 :     SolarMutexGuard aGuard;
    3015           0 :     return ( getCount() != 0 );
    3016             : }
    3017             : 
    3018           0 : uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
    3019             :             throw(container::NoSuchElementException,
    3020             :                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    3021             : {
    3022           0 :     SolarMutexGuard aGuard;
    3023           0 :     uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
    3024           0 :     if (xColumn.is())
    3025           0 :         return uno::makeAny(xColumn);
    3026             :     else
    3027           0 :         throw container::NoSuchElementException();
    3028             : }
    3029             : 
    3030           0 : uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
    3031             :                                                 throw(uno::RuntimeException, std::exception)
    3032             : {
    3033           0 :     SolarMutexGuard aGuard;
    3034           0 :     SCCOL nCount = nEndCol - nStartCol + 1;
    3035           0 :     uno::Sequence<OUString> aSeq(nCount);
    3036           0 :     OUString* pAry = aSeq.getArray();
    3037           0 :     for (SCCOL i=0; i<nCount; i++)
    3038           0 :         pAry[i] = ::ScColToAlpha( nStartCol + i );
    3039             : 
    3040           0 :     return aSeq;
    3041             : }
    3042             : 
    3043           0 : sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
    3044             :                                         throw(uno::RuntimeException, std::exception)
    3045             : {
    3046           0 :     SolarMutexGuard aGuard;
    3047           0 :     SCCOL nCol = 0;
    3048           0 :     OUString aString(aName);
    3049           0 :     if ( ::AlphaToCol( nCol, aString) )
    3050           0 :         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
    3051           0 :             return sal_True;
    3052             : 
    3053           0 :     return false;       // nicht gefunden
    3054             : }
    3055             : 
    3056             : // XPropertySet
    3057             : 
    3058           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
    3059             :                                                         throw(uno::RuntimeException, std::exception)
    3060             : {
    3061           0 :     SolarMutexGuard aGuard;
    3062             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    3063           0 :         new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
    3064           0 :     return aRef;
    3065             : }
    3066             : 
    3067           0 : 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           0 :     SolarMutexGuard aGuard;
    3074           0 :     if (!pDocShell)
    3075           0 :         throw uno::RuntimeException();
    3076             : 
    3077           0 :     std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(nStartCol,nEndCol));
    3078           0 :     OUString aNameString(aPropertyName);
    3079           0 :     ScDocFunc& rFunc = pDocShell->GetDocFunc();
    3080             : 
    3081           0 :     if ( aNameString.equalsAscii( SC_UNONAME_CELLWID ) )
    3082             :     {
    3083           0 :         sal_Int32 nNewWidth = 0;
    3084           0 :         if ( aValue >>= nNewWidth )
    3085             :             rFunc.SetWidthOrHeight(
    3086           0 :                 true, aColArr, nTab, SC_SIZE_ORIGINAL, (sal_uInt16)HMMToTwips(nNewWidth), true, true);
    3087             :     }
    3088           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
    3089             :     {
    3090           0 :         sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3091           0 :         ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
    3092           0 :         rFunc.SetWidthOrHeight(true, aColArr, nTab, eMode, 0, true, true);
    3093             :         //  SC_SIZE_DIRECT with size 0: hide
    3094             :     }
    3095           0 :     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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) || aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
    3104             :     {
    3105             :         //! single function to set/remove all breaks?
    3106           0 :         sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3107           0 :         for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
    3108           0 :             if (bSet)
    3109           0 :                 rFunc.InsertPageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
    3110             :             else
    3111           0 :                 rFunc.RemovePageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
    3112           0 :     }
    3113           0 : }
    3114             : 
    3115           0 : uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aPropertyName )
    3116             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    3117             :           uno::RuntimeException, std::exception)
    3118             : {
    3119           0 :     SolarMutexGuard aGuard;
    3120           0 :     if (!pDocShell)
    3121           0 :         throw uno::RuntimeException();
    3122             : 
    3123           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3124           0 :     OUString aNameString(aPropertyName);
    3125           0 :     uno::Any aAny;
    3126             : 
    3127             :     //! loop over all columns for current state?
    3128             : 
    3129           0 :     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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
    3136             :     {
    3137           0 :         bool bVis = !pDoc->ColHidden(nStartCol, nTab);
    3138           0 :         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           0 :     return aAny;
    3157             : }
    3158             : 
    3159           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
    3160             : 
    3161           0 : ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
    3162             :     pDocShell( pDocSh ),
    3163             :     nTab     ( nT ),
    3164             :     nStartRow( nSR ),
    3165           0 :     nEndRow  ( nER )
    3166             : {
    3167           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3168           0 : }
    3169             : 
    3170           0 : ScTableRowsObj::~ScTableRowsObj()
    3171             : {
    3172           0 :     if (pDocShell)
    3173           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3174           0 : }
    3175             : 
    3176           0 : void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3177             : {
    3178           0 :     if ( rHint.ISA( ScUpdateRefHint ) )
    3179             :     {
    3180             :         //! Referenz-Update fuer Tab und Start/Ende
    3181             :     }
    3182           0 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    3183           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3184             :     {
    3185           0 :         pDocShell = NULL;       // ungueltig geworden
    3186             :     }
    3187           0 : }
    3188             : 
    3189             : // XTableRows
    3190             : 
    3191           0 : ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
    3192             : {
    3193           0 :     SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
    3194           0 :     if ( pDocShell && nRow <= nEndRow )
    3195           0 :         return new ScTableRowObj( pDocShell, nRow, nTab );
    3196             : 
    3197           0 :     return NULL;    // falscher Index
    3198             : }
    3199             : 
    3200           0 : void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
    3201             :                                                 throw(uno::RuntimeException, std::exception)
    3202             : {
    3203           0 :     SolarMutexGuard aGuard;
    3204           0 :     sal_Bool bDone = false;
    3205           0 :     if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
    3206           0 :             nStartRow+nPosition+nCount-1 <= MAXROW )
    3207             :     {
    3208             :         ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
    3209           0 :                         MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
    3210           0 :         bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSROWS, true, true );
    3211             :     }
    3212           0 :     if (!bDone)
    3213           0 :         throw uno::RuntimeException();      // no other exceptions specified
    3214           0 : }
    3215             : 
    3216           0 : void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
    3217             :                                                 throw(uno::RuntimeException, std::exception)
    3218             : {
    3219           0 :     SolarMutexGuard aGuard;
    3220           0 :     sal_Bool bDone = false;
    3221             :     //  Der zu loeschende Bereich muss innerhalb des Objekts liegen
    3222           0 :     if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
    3223             :     {
    3224             :         ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
    3225           0 :                         MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
    3226           0 :         bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELROWS, true, true );
    3227             :     }
    3228           0 :     if (!bDone)
    3229           0 :         throw uno::RuntimeException();      // no other exceptions specified
    3230           0 : }
    3231             : 
    3232             : // XEnumerationAccess
    3233             : 
    3234           0 : uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
    3235             :                                                     throw(uno::RuntimeException, std::exception)
    3236             : {
    3237           0 :     SolarMutexGuard aGuard;
    3238           0 :     return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableRowsEnumeration"));
    3239             : }
    3240             : 
    3241             : // XIndexAccess
    3242             : 
    3243           0 : sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException, std::exception)
    3244             : {
    3245           0 :     SolarMutexGuard aGuard;
    3246           0 :     return nEndRow - nStartRow + 1;
    3247             : }
    3248             : 
    3249           0 : uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
    3250             :                             throw(lang::IndexOutOfBoundsException,
    3251             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    3252             : {
    3253           0 :     SolarMutexGuard aGuard;
    3254           0 :     uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
    3255           0 :     if (xRow.is())
    3256           0 :         return uno::makeAny(xRow);
    3257             :     else
    3258           0 :         throw lang::IndexOutOfBoundsException();
    3259             : }
    3260             : 
    3261           0 : uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException, std::exception)
    3262             : {
    3263           0 :     SolarMutexGuard aGuard;
    3264           0 :     return getCppuType((uno::Reference<table::XCellRange>*)0);
    3265             : }
    3266             : 
    3267           0 : sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException, std::exception)
    3268             : {
    3269           0 :     SolarMutexGuard aGuard;
    3270           0 :     return ( getCount() != 0 );
    3271             : }
    3272             : 
    3273             : // XPropertySet
    3274             : 
    3275           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
    3276             :                                                         throw(uno::RuntimeException, std::exception)
    3277             : {
    3278           0 :     SolarMutexGuard aGuard;
    3279             :     static uno::Reference<beans::XPropertySetInfo> aRef(
    3280           0 :         new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
    3281           0 :     return aRef;
    3282             : }
    3283             : 
    3284           0 : 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           0 :     SolarMutexGuard aGuard;
    3291           0 :     if (!pDocShell)
    3292           0 :         throw uno::RuntimeException();
    3293             : 
    3294           0 :     ScDocFunc& rFunc = pDocShell->GetDocFunc();
    3295           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3296           0 :     std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(nStartRow,nEndRow));
    3297           0 :     OUString aNameString(aPropertyName);
    3298             : 
    3299           0 :     if ( aNameString.equalsAscii( SC_UNONAME_OHEIGHT ) )
    3300             :     {
    3301           0 :         sal_Int32 nNewHeight = 0;
    3302           0 :         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           0 :             pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
    3309             :         }
    3310             :         else
    3311             :         {
    3312           0 :             sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3313           0 :             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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLHGT ) )
    3322             :     {
    3323           0 :         sal_Int32 nNewHeight = 0;
    3324           0 :         if ( aValue >>= nNewHeight )
    3325             :         {
    3326           0 :             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           0 :                 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
    3332           0 :                 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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
    3340             :     {
    3341           0 :         sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    3342           0 :         ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
    3343           0 :         rFunc.SetWidthOrHeight(false, aRowArr, nTab, eMode, 0, true, true);
    3344             :         //  SC_SIZE_DIRECT with size 0: hide
    3345             :     }
    3346           0 :     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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLFILT ) )
    3353             :     {
    3354             :         //! undo etc.
    3355           0 :         if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
    3356           0 :             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           0 :     }
    3382           0 : }
    3383             : 
    3384           0 : uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyName )
    3385             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException,
    3386             :           uno::RuntimeException, std::exception)
    3387             : {
    3388           0 :     SolarMutexGuard aGuard;
    3389           0 :     if (!pDocShell)
    3390           0 :         throw uno::RuntimeException();
    3391             : 
    3392           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3393           0 :     OUString aNameString(aPropertyName);
    3394           0 :     uno::Any aAny;
    3395             : 
    3396             :     //! loop over all rows for current state?
    3397             : 
    3398           0 :     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           0 :     else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
    3405             :     {
    3406             :         SCROW nLastRow;
    3407           0 :         bool bVis = !pDoc->RowHidden(nStartRow, nTab, NULL, &nLastRow);
    3408           0 :         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           0 :     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           0 : ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
    3491             :     pDocShell( pDocSh ),
    3492           0 :     nTab( nT )
    3493             : {
    3494           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3495           0 : }
    3496             : 
    3497           0 : ScAnnotationsObj::~ScAnnotationsObj()
    3498             : {
    3499           0 :     if (pDocShell)
    3500           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3501           0 : }
    3502             : 
    3503           0 : void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3504             : {
    3505             :     //! nTab bei Referenz-Update anpassen!!!
    3506             : 
    3507           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
    3508           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3509             :     {
    3510           0 :         pDocShell = NULL;       // ungueltig geworden
    3511             :     }
    3512           0 : }
    3513             : 
    3514           0 : bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
    3515             : {
    3516           0 :     if (!pDocShell)
    3517           0 :         return false;
    3518             : 
    3519           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3520           0 :     rPos = pDoc->GetNotePosition(nIndex);
    3521           0 :     return rPos.IsValid();
    3522             : }
    3523             : 
    3524           0 : ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
    3525             : {
    3526           0 :     if (pDocShell)
    3527             :     {
    3528           0 :         ScAddress aPos;
    3529           0 :         if ( GetAddressByIndex_Impl( nIndex, aPos ) )
    3530           0 :             return new ScAnnotationObj( pDocShell, aPos );
    3531             :     }
    3532           0 :     return NULL;
    3533             : }
    3534             : 
    3535             : // XSheetAnnotations
    3536             : 
    3537           0 : void SAL_CALL ScAnnotationsObj::insertNew(
    3538             :         const table::CellAddress& aPosition, const OUString& rText )
    3539             :                                                 throw(uno::RuntimeException, std::exception)
    3540             : {
    3541           0 :     SolarMutexGuard aGuard;
    3542           0 :     if (pDocShell)
    3543             :     {
    3544             :         OSL_ENSURE( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
    3545           0 :         ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
    3546           0 :         pDocShell->GetDocFunc().ReplaceNote( aPos, rText, 0, 0, true );
    3547           0 :     }
    3548           0 : }
    3549             : 
    3550           0 : void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException, std::exception)
    3551             : {
    3552           0 :     SolarMutexGuard aGuard;
    3553           0 :     if (pDocShell)
    3554             :     {
    3555           0 :         ScAddress aPos;
    3556           0 :         if ( GetAddressByIndex_Impl( nIndex, aPos ) )
    3557             :         {
    3558           0 :             ScMarkData aMarkData;
    3559           0 :             aMarkData.SelectTable( aPos.Tab(), true );
    3560           0 :             aMarkData.SetMultiMarkArea( ScRange(aPos) );
    3561             : 
    3562           0 :             pDocShell->GetDocFunc().DeleteContents( aMarkData, IDF_NOTE, true, true );
    3563             :         }
    3564           0 :     }
    3565           0 : }
    3566             : 
    3567             : // XEnumerationAccess
    3568             : 
    3569           0 : uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
    3570             :                                                     throw(uno::RuntimeException, std::exception)
    3571             : {
    3572             :     //! iterate directly (more efficiently)?
    3573             : 
    3574           0 :     SolarMutexGuard aGuard;
    3575           0 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.CellAnnotationsEnumeration"));
    3576             : }
    3577             : 
    3578             : // XIndexAccess
    3579             : 
    3580           0 : sal_Int32 SAL_CALL ScAnnotationsObj::getCount()
    3581             :     throw(uno::RuntimeException, std::exception)
    3582             : {
    3583           0 :     SolarMutexGuard aGuard;
    3584           0 :     sal_Int32 nCount = 0;
    3585           0 :     if (pDocShell)
    3586             :     {
    3587           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    3588           0 :         const ScRangeList aRangeList( ScRange( 0, 0, nTab, MAXCOL, MAXROW, nTab) );
    3589           0 :         std::vector<sc::NoteEntry> rNotes;
    3590           0 :         pDoc->GetNotesInRange(aRangeList, rNotes);
    3591           0 :         nCount = rNotes.size();
    3592             :     }
    3593           0 :     return nCount;
    3594             : }
    3595             : 
    3596           0 : uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
    3597             :                             throw(lang::IndexOutOfBoundsException,
    3598             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    3599             : {
    3600           0 :     SolarMutexGuard aGuard;
    3601           0 :     uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
    3602           0 :     if (xAnnotation.is())
    3603           0 :         return uno::makeAny(xAnnotation);
    3604             :     else
    3605           0 :         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           0 : ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
    3621             :     pDocShell( pDocSh ),
    3622           0 :     nTab     ( nT )
    3623             : {
    3624           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
    3625           0 : }
    3626             : 
    3627           0 : ScScenariosObj::~ScScenariosObj()
    3628             : {
    3629           0 :     if (pDocShell)
    3630           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    3631           0 : }
    3632             : 
    3633           0 : void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    3634             : {
    3635           0 :     if ( rHint.ISA( ScUpdateRefHint ) )
    3636             :     {
    3637             :         //! Referenz-Update fuer Tab und Start/Ende
    3638             :     }
    3639           0 :     else if ( rHint.ISA( SfxSimpleHint ) &&
    3640           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    3641             :     {
    3642           0 :         pDocShell = NULL;       // ungueltig geworden
    3643             :     }
    3644           0 : }
    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           0 : ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
    3670             : {
    3671           0 :     sal_uInt16 nCount = (sal_uInt16)getCount();
    3672           0 :     if ( pDocShell && nIndex >= 0 && nIndex < nCount )
    3673           0 :         return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
    3674             : 
    3675           0 :     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           0 : 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           0 :     SolarMutexGuard aGuard;
    3693           0 :     if ( pDocShell )
    3694             :     {
    3695           0 :         ScMarkData aMarkData;
    3696           0 :         aMarkData.SelectTable( nTab, true );
    3697             : 
    3698           0 :         sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
    3699           0 :         if (nRangeCount)
    3700             :         {
    3701           0 :             const table::CellRangeAddress* pAry = aRanges.getConstArray();
    3702           0 :             for (sal_uInt16 i=0; i<nRangeCount; i++)
    3703             :             {
    3704             :                 OSL_ENSURE( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
    3705           0 :                 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
    3706           0 :                                 (SCCOL)pAry[i].EndColumn,   (SCROW)pAry[i].EndRow,   nTab );
    3707             : 
    3708           0 :                 aMarkData.SetMultiMarkArea( aRange );
    3709             :             }
    3710             :         }
    3711             : 
    3712           0 :         OUString aNameStr(aName);
    3713           0 :         OUString aCommStr(aComment);
    3714             : 
    3715           0 :         Color aColor( COL_LIGHTGRAY );  // Default
    3716           0 :         sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
    3717             : 
    3718           0 :         pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
    3719           0 :     }
    3720           0 : }
    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           0 : uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
    3734             :                                                     throw(uno::RuntimeException, std::exception)
    3735             : {
    3736           0 :     SolarMutexGuard aGuard;
    3737           0 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.ScenariosEnumeration"));
    3738             : }
    3739             : 
    3740             : // XIndexAccess
    3741             : 
    3742           0 : sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException, std::exception)
    3743             : {
    3744           0 :     SolarMutexGuard aGuard;
    3745           0 :     SCTAB nCount = 0;
    3746           0 :     if ( pDocShell )
    3747             :     {
    3748           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    3749           0 :         if (!pDoc->IsScenario(nTab))
    3750             :         {
    3751           0 :             SCTAB nTabCount = pDoc->GetTableCount();
    3752           0 :             SCTAB nNext = nTab + 1;
    3753           0 :             while (nNext < nTabCount && pDoc->IsScenario(nNext))
    3754             :             {
    3755           0 :                 ++nCount;
    3756           0 :                 ++nNext;
    3757             :             }
    3758             :         }
    3759             :     }
    3760           0 :     return nCount;
    3761             : }
    3762             : 
    3763           0 : uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
    3764             :                             throw(lang::IndexOutOfBoundsException,
    3765             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    3766             : {
    3767           0 :     SolarMutexGuard aGuard;
    3768           0 :     uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
    3769           0 :     if (xScen.is())
    3770           0 :         return uno::makeAny(xScen);
    3771             :     else
    3772           0 :         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           0 : }
    3826             : 
    3827             : 
    3828             : 
    3829             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10