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