LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/unoobj - docuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 618 1922 32.2 %
Date: 2012-12-27 Functions: 70 216 32.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10