xref: /trunk/main/sc/source/ui/unoobj/cellsuno.cxx (revision d3bd7a82)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include "scitems.hxx"
29 #include <editeng/eeitem.hxx>
30 #include <svx/svdpool.hxx>
31 
32 #include <svx/algitem.hxx>
33 #include <editeng/boxitem.hxx>
34 #include <editeng/brshitem.hxx>
35 #include <editeng/editeng.hxx>
36 #include <editeng/flditem.hxx>
37 #include <svx/fmdpage.hxx>
38 #include <editeng/langitem.hxx>
39 #include <sfx2/linkmgr.hxx>
40 #include <svl/srchitem.hxx>
41 #include <svx/unomid.hxx>
42 #include <editeng/unoprnms.hxx>
43 #include <editeng/unotext.hxx>
44 #include <svx/svdpage.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <svl/zforlist.hxx>
47 #include <svl/zformat.hxx>
48 #include <rtl/uuid.h>
49 #include <float.h>				// DBL_MIN
50 
51 #include <com/sun/star/awt/XBitmap.hpp>
52 #include <com/sun/star/util/CellProtection.hpp>
53 #include <com/sun/star/table/CellHoriJustify.hpp>
54 #include <com/sun/star/table/CellOrientation.hpp>
55 #include <com/sun/star/table/CellVertJustify.hpp>
56 #include <com/sun/star/table/ShadowFormat.hpp>
57 #include <com/sun/star/table/TableBorder.hpp>
58 #include <com/sun/star/sheet/CellFlags.hpp>
59 #include <com/sun/star/sheet/FormulaResult.hpp>
60 #include <com/sun/star/beans/PropertyAttribute.hpp>
61 #include <com/sun/star/lang/Locale.hpp>
62 #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
63 #include <com/sun/star/beans/SetPropertyTolerantFailed.hpp>
64 #include <com/sun/star/text/WritingMode2.hpp>
65 
66 #include "autoform.hxx"
67 #include "cellsuno.hxx"
68 #include "cursuno.hxx"
69 #include "textuno.hxx"
70 #include "editsrc.hxx"
71 #include "notesuno.hxx"
72 #include "fielduno.hxx"
73 #include "docuno.hxx"		// ScTableColumnsObj etc
74 #include "datauno.hxx"
75 #include "dapiuno.hxx"
76 #include "chartuno.hxx"
77 #include "fmtuno.hxx"
78 #include "miscuno.hxx"
79 #include "convuno.hxx"
80 #include "srchuno.hxx"
81 #include "targuno.hxx"
82 #include "tokenuno.hxx"
83 #include "eventuno.hxx"
84 #include "docsh.hxx"
85 #include "markdata.hxx"
86 #include "patattr.hxx"
87 #include "docpool.hxx"
88 #include "docfunc.hxx"
89 #include "dbdocfun.hxx"
90 #include "olinefun.hxx"
91 #include "hints.hxx"
92 #include "cell.hxx"
93 #include "undocell.hxx"
94 #include "undotab.hxx"
95 #include "undoblk.hxx"		// fuer lcl_ApplyBorder - nach docfunc verschieben!
96 #include "stlsheet.hxx"
97 #include "dbcolect.hxx"
98 #include "attrib.hxx"
99 #include "chartarr.hxx"
100 #include "chartlis.hxx"
101 #include "drwlayer.hxx"
102 #include "printfun.hxx"
103 #include "prnsave.hxx"
104 #include "tablink.hxx"
105 #include "dociter.hxx"
106 #include "rangeutl.hxx"
107 #include "conditio.hxx"
108 #include "validat.hxx"
109 #include "sc.hrc"
110 #include "brdcst.hxx"
111 #include "unoguard.hxx"
112 #include "cellform.hxx"
113 #include "globstr.hrc"
114 #include "unonames.hxx"
115 #include "styleuno.hxx"
116 #include "rangeseq.hxx"
117 #include "unowids.hxx"
118 #include "paramisc.hxx"
119 #include "formula/errorcodes.hxx"
120 #include "unoreflist.hxx"
121 #include "formula/grammar.hxx"
122 
123 #include <list>
124 
125 using namespace com::sun::star;
126 
127 //------------------------------------------------------------------------
128 
129 
130 class ScNamedEntry
131 {
132 	String	aName;
133 	ScRange	aRange;
134 
135 public:
ScNamedEntry(const String & rN,const ScRange & rR)136 			ScNamedEntry(const String& rN, const ScRange& rR) :
137 				aName(rN), aRange(rR) {}
138 
GetName() const139 	const String&	GetName() const		{ return aName; }
GetRange() const140 	const ScRange&	GetRange() const	{ return aRange; }
141 };
142 
143 
144 //------------------------------------------------------------------------
145 
146 //	Die Namen in den Maps muessen (nach strcmp) sortiert sein!
147 //!	statt Which-ID 0 special IDs verwenden, und nicht ueber Namen vergleichen !!!!!!!!!
148 
149 //	Left/Right/Top/BottomBorder are mapped directly to the core items,
150 //	not collected/applied to the borders of a range -> ATTR_BORDER can be used directly
151 
lcl_GetCellsPropertySet()152 const SfxItemPropertySet* lcl_GetCellsPropertySet()
153 {
154     static SfxItemPropertyMapEntry aCellsPropertyMap_Impl[] =
155 	{
156         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
157 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
158 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
159 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
160 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
161 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
162 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
163 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
164 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
165 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
166 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
167 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
168 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
169 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
170 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
171 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
172 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
173 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
174 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
175 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
176 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
177 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
178 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
179 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
180 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
181 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
182 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
183 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
184 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
185 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
186 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
187 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
188 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
189 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
190 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
191 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
192 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
193 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
194 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
195 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
196 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
197 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
198 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
199 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
200 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
201 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
202 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
203 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
204 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
205 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
206 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
207 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
208 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
209 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
210 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
211         {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST },
212 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
213 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
214 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
215 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
216 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
217         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
218 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
219 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
220 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
221 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
222 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
223 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
224 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
225 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
226 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
227 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
228 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
229 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
230 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
231 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
232 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
233         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),			    0, 0 },
234 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
235 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
236 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
237 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
238 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
239 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
240 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
241 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
242         {0,0,0,0,0,0}
243 	};
244     static SfxItemPropertySet aCellsPropertySet( aCellsPropertyMap_Impl );
245     return &aCellsPropertySet;
246 }
247 
248 //	CellRange enthaelt alle Eintraege von Cells, zusaetzlich eigene Eintraege
249 //	mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt).
250 
lcl_GetRangePropertySet()251 const SfxItemPropertySet* lcl_GetRangePropertySet()
252 {
253     static SfxItemPropertyMapEntry aRangePropertyMap_Impl[] =
254 	{
255         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
256 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
257 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
258 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
259 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
260 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
261 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
262 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
263 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
264 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
265 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
266 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
267 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
268 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
269 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
270 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
271 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
272 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
273 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
274 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
275 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
276 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
277 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
278 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
279 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
280 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
281 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
282 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
283 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
284 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
285 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
286 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
287 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
288 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
289 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
290 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
291 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
292 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
293 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
294 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
295 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
296 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
297 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
298 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
299 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
300 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
301 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
302 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
303 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
304 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
305 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
306 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
307 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
308 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
309 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
310 		{MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0),	0, MID_HORJUST_HORJUST },
311 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
312 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
313 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
314 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
315 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
316         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
317 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
318 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
319 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
320 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
321 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
322 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
323 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
324 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
325 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
326 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
327 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
328 		{MAP_CHAR_LEN(SC_UNONAME_POS),		SC_WID_UNO_POS,		&getCppuType((awt::Point*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
329 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
330 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
331 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
332 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
333         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),			    0, 0 },
334 		{MAP_CHAR_LEN(SC_UNONAME_SIZE),		SC_WID_UNO_SIZE,	&getCppuType((awt::Size*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
335 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
336 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
337 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
338 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
339 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
340 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
341 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
342 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
343         {0,0,0,0,0,0}
344 	};
345 	static SfxItemPropertySet aRangePropertySet( aRangePropertyMap_Impl );
346     return &aRangePropertySet;
347 }
348 
349 //	Cell enthaelt alle Eintraege von CellRange, zusaetzlich eigene Eintraege
350 //	mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt).
351 
lcl_GetCellPropertySet()352 const SfxItemPropertySet* lcl_GetCellPropertySet()
353 {
354     static SfxItemPropertyMapEntry aCellPropertyMap_Impl[] =
355 	{
356         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
357 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
358 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
359 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
360 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
361 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
362 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
363 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
364 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
365 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
366 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
367 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
368 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
369 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
370 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
371 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
372 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
373 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
374 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
375 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
376 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
377 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
378 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
379 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
380 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
381 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
382 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
383 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
384 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
385 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
386 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
387 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
388 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
389 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
390 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
391 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
392 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
393 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
394 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
395 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
396 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
397 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
398 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
399 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
400 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
401 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
402 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
403 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
404 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
405 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
406 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
407 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
408 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
409 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
410 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
411 		{MAP_CHAR_LEN(SC_UNONAME_FORMLOC),	SC_WID_UNO_FORMLOC,	&getCppuType((rtl::OUString*)0),		0, 0 },
412 		{MAP_CHAR_LEN(SC_UNONAME_FORMRT),	SC_WID_UNO_FORMRT,	&getCppuType((table::CellContentType*)0), 0 | beans::PropertyAttribute::READONLY, 0 },
413 		{MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST },
414 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
415 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
416 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
417 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
418 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
419         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
420 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
421 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
422 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
423 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
424 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
425 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
426 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
427 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
428 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
429 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
430 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
431 		{MAP_CHAR_LEN(SC_UNONAME_POS),		SC_WID_UNO_POS,		&getCppuType((awt::Point*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
432 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
433 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
434 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
435 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
436         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),			    0, 0 },
437 		{MAP_CHAR_LEN(SC_UNONAME_SIZE),		SC_WID_UNO_SIZE,	&getCppuType((awt::Size*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
438 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
439 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
440 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
441 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
442 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
443 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
444 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
445 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
446         {0,0,0,0,0,0}
447 	};
448     static SfxItemPropertySet aCellPropertySet( aCellPropertyMap_Impl );
449     return &aCellPropertySet;
450 }
451 
452 //	Column und Row enthalten alle Eintraege von CellRange, zusaetzlich eigene Eintraege
453 //	mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt).
454 
lcl_GetColumnPropertySet()455 const SfxItemPropertySet* lcl_GetColumnPropertySet()
456 {
457     static SfxItemPropertyMapEntry aColumnPropertyMap_Impl[] =
458 	{
459         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
460 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
461 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
462 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
463 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
464 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
465 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
466 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
467 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
468 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
469 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
470 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
471 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
472 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
473 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
474 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
475 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
476 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
477 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
478 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
479 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
480 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
481 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
482 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
483 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
484 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
485 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
486 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
487 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
488 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
489 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
490 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
491 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
492 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
493 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
494 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
495 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
496 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
497 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
498 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
499 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
500 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
501 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
502 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
503 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
504 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
505 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
506 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
507 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
508 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
509 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
510 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
511 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
512 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
513 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
514 		{MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST },
515 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
516 //		{MAP_CHAR_LEN(SC_UNONAME_CELLFILT),	SC_WID_UNO_CELLFILT,&getBooleanCppuType(),					0, 0 },
517 		{MAP_CHAR_LEN(SC_UNONAME_MANPAGE),	SC_WID_UNO_MANPAGE,	&getBooleanCppuType(),					0, 0 },
518 		{MAP_CHAR_LEN(SC_UNONAME_NEWPAGE),	SC_WID_UNO_NEWPAGE,	&getBooleanCppuType(),					0, 0 },
519 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
520 		{MAP_CHAR_LEN(SC_UNONAME_CELLVIS),	SC_WID_UNO_CELLVIS,	&getBooleanCppuType(),					0, 0 },
521 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
522 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
523 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
524 		{MAP_CHAR_LEN(SC_UNONAME_OWIDTH),	SC_WID_UNO_OWIDTH,	&getBooleanCppuType(),					0, 0 },
525         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
526 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
527 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
528 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
529 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
530 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
531 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
532 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
533 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
534 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
535 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
536 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
537 		{MAP_CHAR_LEN(SC_UNONAME_POS),		SC_WID_UNO_POS,		&getCppuType((awt::Point*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
538 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
539 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
540 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
541 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
542         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),			    0, 0 },
543 		{MAP_CHAR_LEN(SC_UNONAME_SIZE),		SC_WID_UNO_SIZE,	&getCppuType((awt::Size*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
544 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
545 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
546 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
547 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
548 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
549 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
550 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
551 		{MAP_CHAR_LEN(SC_UNONAME_CELLWID),	SC_WID_UNO_CELLWID,	&getCppuType((sal_Int32*)0),			0, 0 },
552 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
553         {0,0,0,0,0,0}
554 	};
555 	static SfxItemPropertySet aColumnPropertySet( aColumnPropertyMap_Impl );
556     return &aColumnPropertySet;
557 }
558 
lcl_GetRowPropertySet()559 const SfxItemPropertySet* lcl_GetRowPropertySet()
560 {
561     static SfxItemPropertyMapEntry aRowPropertyMap_Impl[] =
562 	{
563         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
564 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
565 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
566 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
567 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
568 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
569 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
570 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
571 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
572 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
573 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
574 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
575 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
576 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
577 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
578 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
579 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
580 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
581 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
582 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
583 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
584 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
585 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
586 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
587 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
588 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
589 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
590 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
591 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
592 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
593 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
594 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
595 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
596 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
597 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
598 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
599 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
600 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
601 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
602 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
603 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
604 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
605 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
606 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
607 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
608 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
609 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
610 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
611 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
612 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
613 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
614 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
615 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
616 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
617 		{MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
618 		{MAP_CHAR_LEN(SC_UNONAME_CELLHGT),	SC_WID_UNO_CELLHGT,	&getCppuType((sal_Int32*)0),			0, 0 },
619 		{MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST },
620 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
621 		{MAP_CHAR_LEN(SC_UNONAME_CELLFILT),	SC_WID_UNO_CELLFILT,&getBooleanCppuType(),					0, 0 },
622 		{MAP_CHAR_LEN(SC_UNONAME_MANPAGE),	SC_WID_UNO_MANPAGE,	&getBooleanCppuType(),					0, 0 },
623 		{MAP_CHAR_LEN(SC_UNONAME_NEWPAGE),	SC_WID_UNO_NEWPAGE,	&getBooleanCppuType(),					0, 0 },
624 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
625 		{MAP_CHAR_LEN(SC_UNONAME_CELLVIS),	SC_WID_UNO_CELLVIS,	&getBooleanCppuType(),					0, 0 },
626 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
627 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
628 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
629 		{MAP_CHAR_LEN(SC_UNONAME_OHEIGHT),	SC_WID_UNO_OHEIGHT,	&getBooleanCppuType(),					0, 0 },
630         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
631 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
632 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
633 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
634 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
635 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
636 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
637 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
638 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
639 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
640 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
641 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
642 		{MAP_CHAR_LEN(SC_UNONAME_POS),		SC_WID_UNO_POS,		&getCppuType((awt::Point*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
643 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
644 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
645 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
646 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
647         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),			    0, 0 },
648 		{MAP_CHAR_LEN(SC_UNONAME_SIZE),		SC_WID_UNO_SIZE,	&getCppuType((awt::Size*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
649 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
650 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
651 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
652 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
653 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
654 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
655 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
656 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
657         {0,0,0,0,0,0}
658 	};
659 	static SfxItemPropertySet aRowPropertySet( aRowPropertyMap_Impl );
660     return &aRowPropertySet;
661 }
662 
lcl_GetSheetPropertySet()663 const SfxItemPropertySet* lcl_GetSheetPropertySet()
664 {
665     static SfxItemPropertyMapEntry aSheetPropertyMap_Impl[] =
666 	{
667         {MAP_CHAR_LEN(SC_UNONAME_ABSNAME),	SC_WID_UNO_ABSNAME,	&getCppuType((rtl::OUString*)0),		0 | beans::PropertyAttribute::READONLY, 0 },
668 		{MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(),					0, 0 },
669         {MAP_CHAR_LEN(SC_UNONAME_AUTOPRINT),SC_WID_UNO_AUTOPRINT,&getBooleanCppuType(),					0, 0 },
670 		{MAP_CHAR_LEN(SC_UNONAME_BORDCOL),  SC_WID_UNO_BORDCOL, &getCppuType((sal_Int32*)0),			0, 0 },
671 		{MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS },
672 		{MAP_CHAR_LEN(SC_UNONAME_CELLBACK),	ATTR_BACKGROUND,	&getCppuType((sal_Int32*)0),			0, MID_BACK_COLOR },
673 		{MAP_CHAR_LEN(SC_UNONAME_CELLPRO),	ATTR_PROTECTION,	&getCppuType((util::CellProtection*)0),	0, 0 },
674 		{MAP_CHAR_LEN(SC_UNONAME_CELLSTYL),	SC_WID_UNO_CELLSTYL,&getCppuType((rtl::OUString*)0),		0, 0 },
675 		{MAP_CHAR_LEN(SC_UNONAME_CCOLOR),	ATTR_FONT_COLOR,	&getCppuType((sal_Int32*)0),			0, 0 },
676 		{MAP_CHAR_LEN(SC_UNONAME_COUTL),	ATTR_FONT_CONTOUR,	&getBooleanCppuType(),					0, 0 },
677 		{MAP_CHAR_LEN(SC_UNONAME_CCROSS),	ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(),					0, MID_CROSSED_OUT },
678 		{MAP_CHAR_LEN(SC_UNONAME_CEMPHAS),	ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0),			0, MID_EMPHASIS },
679 		{MAP_CHAR_LEN(SC_UNONAME_CFONT),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
680 		{MAP_CHAR_LEN(SC_UNONAME_CFCHARS),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
681 		{MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
682 		{MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_CHAR_SET },
683 		{MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
684 		{MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
685 		{MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_FAMILY },
686 		{MAP_CHAR_LEN(SC_UNONAME_CFNAME),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
687 		{MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
688 		{MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_FAMILY_NAME },
689 		{MAP_CHAR_LEN(SC_UNONAME_CFPITCH),	ATTR_FONT,			&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
690 		{MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),	ATTR_CJK_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
691 		{MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),	ATTR_CTL_FONT,		&getCppuType((sal_Int16*)0),			0, MID_FONT_PITCH },
692 		{MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),	ATTR_FONT,			&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
693 		{MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),	ATTR_CJK_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
694 		{MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),	ATTR_CTL_FONT,		&getCppuType((rtl::OUString*)0),		0, MID_FONT_STYLE_NAME },
695 		{MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),	ATTR_FONT_HEIGHT,	&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
696 		{MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),	ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
697 		{MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),	ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0),				0, MID_FONTHEIGHT | CONVERT_TWIPS },
698 		{MAP_CHAR_LEN(SC_UNONAME_CLOCAL),	ATTR_FONT_LANGUAGE,	&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
699 		{MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL),	ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
700 		{MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL),	ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0),			0, MID_LANG_LOCALE },
701 		{MAP_CHAR_LEN(SC_UNONAME_COVER),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
702 		{MAP_CHAR_LEN(SC_UNONAME_COVRLCOL),	ATTR_FONT_OVERLINE, &getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
703 		{MAP_CHAR_LEN(SC_UNONAME_COVRLHAS),	ATTR_FONT_OVERLINE, &getBooleanCppuType(),					0, MID_TL_HASCOLOR },
704 		{MAP_CHAR_LEN(SC_UNONAME_CPOST),	ATTR_FONT_POSTURE,	&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
705 		{MAP_CHAR_LEN(SC_UNO_CJK_CPOST),	ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
706 		{MAP_CHAR_LEN(SC_UNO_CTL_CPOST),	ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0),		0, MID_POSTURE },
707 		{MAP_CHAR_LEN(SC_UNONAME_CRELIEF),	ATTR_FONT_RELIEF,	&getCppuType((sal_Int16*)0),			0, MID_RELIEF },
708 		{MAP_CHAR_LEN(SC_UNONAME_CSHADD),	ATTR_FONT_SHADOWED,	&getBooleanCppuType(),					0, 0 },
709 		{MAP_CHAR_LEN(SC_UNONAME_CSTRIKE),	ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0),			0, MID_CROSS_OUT },
710 		{MAP_CHAR_LEN(SC_UNONAME_CUNDER),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0),			0, MID_TL_STYLE },
711 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL),	ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0),			0, MID_TL_COLOR },
712 		{MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS),	ATTR_FONT_UNDERLINE,&getBooleanCppuType(),					0, MID_TL_HASCOLOR },
713 		{MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),	ATTR_FONT_WEIGHT,	&getCppuType((float*)0),				0, MID_WEIGHT },
714 		{MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),	ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
715 		{MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),	ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0),				0, MID_WEIGHT },
716 		{MAP_CHAR_LEN(SC_UNONAME_CWORDMOD),	ATTR_FONT_WORDLINE,	&getBooleanCppuType(),					0, 0 },
717 		{MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR),	SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(),					0, 0 },
718 		{MAP_CHAR_LEN(SC_UNONAME_CHROWHDR),	SC_WID_UNO_CHROWHDR,&getBooleanCppuType(),					0, 0 },
719 		{MAP_CHAR_LEN(SC_UNONAME_CONDFMT),	SC_WID_UNO_CONDFMT,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
720 		{MAP_CHAR_LEN(SC_UNONAME_CONDLOC),	SC_WID_UNO_CONDLOC,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
721 		{MAP_CHAR_LEN(SC_UNONAME_CONDXML),	SC_WID_UNO_CONDXML,	&getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 },
722 		{MAP_CHAR_LEN(SC_UNONAME_COPYBACK),	SC_WID_UNO_COPYBACK,&getBooleanCppuType(),					0, 0 },
723 		{MAP_CHAR_LEN(SC_UNONAME_COPYFORM),	SC_WID_UNO_COPYFORM,&getBooleanCppuType(),					0, 0 },
724 		{MAP_CHAR_LEN(SC_UNONAME_COPYSTYL),	SC_WID_UNO_COPYSTYL,&getBooleanCppuType(),					0, 0 },
725         {MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_BLTR), ATTR_BORDER_BLTR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
726         {MAP_CHAR_LEN(SC_UNONAME_DIAGONAL_TLBR), ATTR_BORDER_TLBR, &::getCppuType((const table::BorderLine*)0), 0, 0 | CONVERT_TWIPS },
727 		{MAP_CHAR_LEN(SC_UNONAME_CELLHJUS),	ATTR_HOR_JUSTIFY,	&getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST },
728 		{MAP_CHAR_LEN(SC_UNONAME_ISACTIVE),	SC_WID_UNO_ISACTIVE,&getBooleanCppuType(),					0, 0 },
729 		{MAP_CHAR_LEN(SC_UNONAME_CELLTRAN),	ATTR_BACKGROUND,	&getBooleanCppuType(),					0, MID_GRAPHIC_TRANSPARENT },
730 		{MAP_CHAR_LEN(SC_UNONAME_WRAP),		ATTR_LINEBREAK,		&getBooleanCppuType(),					0, 0 },
731 		{MAP_CHAR_LEN(SC_UNONAME_CELLVIS),	SC_WID_UNO_CELLVIS,	&getBooleanCppuType(),					0, 0 },
732 		{MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS },
733 		{MAP_CHAR_LEN(SC_UNO_LINKDISPBIT),	SC_WID_UNO_LINKDISPBIT,&getCppuType((uno::Reference<awt::XBitmap>*)0), 0 | beans::PropertyAttribute::READONLY, 0 },
734 		{MAP_CHAR_LEN(SC_UNO_LINKDISPNAME),	SC_WID_UNO_LINKDISPNAME,&getCppuType((rtl::OUString*)0),	0 | beans::PropertyAttribute::READONLY, 0 },
735 		{MAP_CHAR_LEN(SC_UNONAME_NUMFMT),	ATTR_VALUE_FORMAT,	&getCppuType((sal_Int32*)0),			0, 0 },
736 		{MAP_CHAR_LEN(SC_UNONAME_NUMRULES),	SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 },
737         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,       &getCppuType((table::CellOrientation*)0), 0, 0 },
738 		{MAP_CHAR_LEN(SC_UNONAME_PAGESTL),	SC_WID_UNO_PAGESTL,	&getCppuType((rtl::OUString*)0),		0, 0 },
739 		{MAP_CHAR_LEN(SC_UNONAME_PADJUST),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
740 		{MAP_CHAR_LEN(SC_UNONAME_PBMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
741 		{MAP_CHAR_LEN(SC_UNONAME_PINDENT),	ATTR_INDENT,		&getCppuType((sal_Int16*)0),			0, 0 }, //! CONVERT_TWIPS
742 		{MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE,	&getBooleanCppuType(),					0, 0 },
743 		{MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(),					0, 0 },
744 		{MAP_CHAR_LEN(SC_UNONAME_PISHANG),	ATTR_HANGPUNCTUATION,&getBooleanCppuType(),					0, 0 },
745 		{MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE,		&getBooleanCppuType(),					0, 0 },
746 		{MAP_CHAR_LEN(SC_UNONAME_PLASTADJ),	ATTR_HOR_JUSTIFY,	&::getCppuType((const sal_Int16*)0),	0, MID_HORJUST_ADJUST },
747 		{MAP_CHAR_LEN(SC_UNONAME_PLMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
748 		{MAP_CHAR_LEN(SC_UNONAME_PRMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
749 		{MAP_CHAR_LEN(SC_UNONAME_PTMARGIN),	ATTR_MARGIN,		&getCppuType((sal_Int32*)0),			0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
750 		{MAP_CHAR_LEN(SC_UNONAME_POS),		SC_WID_UNO_POS,		&getCppuType((awt::Point*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
751 		{MAP_CHAR_LEN(SC_UNONAME_PRINTBORD),SC_WID_UNO_PRINTBORD,&getBooleanCppuType(),					0, 0 },
752 		{MAP_CHAR_LEN(SC_UNONAME_PROTECT),  SC_WID_UNO_PROTECT,	&getBooleanCppuType(),					0, 0 },
753 		{MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS },
754 		{MAP_CHAR_LEN(SC_UNONAME_ROTANG),	ATTR_ROTATE_VALUE,	&getCppuType((sal_Int32*)0),			0, 0 },
755 		{MAP_CHAR_LEN(SC_UNONAME_ROTREF),	ATTR_ROTATE_MODE,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
756 		{MAP_CHAR_LEN(SC_UNONAME_SHADOW),	ATTR_SHADOW,		&getCppuType((table::ShadowFormat*)0),	0, 0 | CONVERT_TWIPS },
757 		{MAP_CHAR_LEN(SC_UNONAME_SHOWBORD), SC_WID_UNO_SHOWBORD,&getBooleanCppuType(),					0, 0 },
758         {MAP_CHAR_LEN(SC_UNONAME_SHRINK_TO_FIT), ATTR_SHRINKTOFIT, &getBooleanCppuType(),               0, 0 },
759 		{MAP_CHAR_LEN(SC_UNONAME_SIZE),		SC_WID_UNO_SIZE,	&getCppuType((awt::Size*)0),			0 | beans::PropertyAttribute::READONLY, 0 },
760 		{MAP_CHAR_LEN(SC_UNONAME_TBLBORD),	SC_WID_UNO_TBLBORD,	&getCppuType((table::TableBorder*)0),	0, 0 | CONVERT_TWIPS },
761 		{MAP_CHAR_LEN(SC_UNONAME_TABLAYOUT),SC_WID_UNO_TABLAYOUT,&getCppuType((sal_Int16*)0),			0, 0 },
762 		{MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER,		&::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS },
763 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	ATTR_USERDEF,		&getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 },
764 		{MAP_CHAR_LEN(SC_UNONAME_VALIDAT),	SC_WID_UNO_VALIDAT,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
765 		{MAP_CHAR_LEN(SC_UNONAME_VALILOC),	SC_WID_UNO_VALILOC,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
766 		{MAP_CHAR_LEN(SC_UNONAME_VALIXML),	SC_WID_UNO_VALIXML,	&getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 },
767 		{MAP_CHAR_LEN(SC_UNONAME_CELLVJUS),	ATTR_VER_JUSTIFY,	&getCppuType((table::CellVertJustify*)0), 0, 0 },
768 		{MAP_CHAR_LEN(SC_UNONAME_WRITING),	ATTR_WRITINGDIR,	&getCppuType((sal_Int16*)0),			0, 0 },
769         {MAP_CHAR_LEN(SC_UNONAME_TABCOLOR), SC_WID_UNO_TABCOLOR, &getCppuType((sal_Int32*)0), 0, 0 },
770 		{MAP_CHAR_LEN(SC_UNO_CODENAME),        SC_WID_UNO_CODENAME, &getCppuType(static_cast< const rtl::OUString * >(0)),    0, 0},
771         {0,0,0,0,0,0}
772 	};
773 	static SfxItemPropertySet aSheetPropertySet( aSheetPropertyMap_Impl );
774     return &aSheetPropertySet;
775 }
776 
lcl_GetEditPropertyMap()777 const SfxItemPropertyMapEntry* lcl_GetEditPropertyMap()
778 {
779     static SfxItemPropertyMapEntry aEditPropertyMap_Impl[] =
780 	{
781 		SVX_UNOEDIT_CHAR_PROPERTIES,
782 		SVX_UNOEDIT_FONT_PROPERTIES,
783 		SVX_UNOEDIT_PARA_PROPERTIES,
784 		SVX_UNOEDIT_NUMBERING_PROPERTIE,	// for completeness of service ParagraphProperties
785 		{MAP_CHAR_LEN(SC_UNONAME_TEXTUSER),	EE_CHAR_XMLATTRIBS,	&getCppuType((const uno::Reference< container::XNameContainer >*)0), 0, 0},
786 		{MAP_CHAR_LEN(SC_UNONAME_USERDEF),	EE_PARA_XMLATTRIBS,	&getCppuType((const uno::Reference< container::XNameContainer >*)0), 0, 0},
787         {0,0,0,0,0,0}
788 	};
789 	return aEditPropertyMap_Impl;
790 }
lcl_GetEditPropertySet()791 const SvxItemPropertySet* lcl_GetEditPropertySet()
792 {
793 	static SvxItemPropertySet aEditPropertySet( lcl_GetEditPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool() );
794     return &aEditPropertySet;
795 }
796 
797 
798 //------------------------------------------------------------------------
799 
800 //!	diese Funktionen in einen allgemeinen Header verschieben
TwipsToHMM(long nTwips)801 inline long TwipsToHMM(long nTwips)	{ return (nTwips * 127 + 36) / 72; }
HMMToTwips(long nHMM)802 inline long HMMToTwips(long nHMM)	{ return (nHMM * 72 + 63) / 127; }
803 
804 //------------------------------------------------------------------------
805 
806 #define SCCHARPROPERTIES_SERVICE	"com.sun.star.style.CharacterProperties"
807 #define SCPARAPROPERTIES_SERVICE	"com.sun.star.style.ParagraphProperties"
808 #define SCCELLPROPERTIES_SERVICE	"com.sun.star.table.CellProperties"
809 #define SCCELLRANGE_SERVICE			"com.sun.star.table.CellRange"
810 #define SCCELL_SERVICE				"com.sun.star.table.Cell"
811 #define SCSHEETCELLRANGES_SERVICE	"com.sun.star.sheet.SheetCellRanges"
812 #define SCSHEETCELLRANGE_SERVICE	"com.sun.star.sheet.SheetCellRange"
813 #define SCSPREADSHEET_SERVICE		"com.sun.star.sheet.Spreadsheet"
814 #define SCSHEETCELL_SERVICE			"com.sun.star.sheet.SheetCell"
815 
816 SC_SIMPLE_SERVICE_INFO( ScCellFormatsEnumeration, "ScCellFormatsEnumeration", "com.sun.star.sheet.CellFormatRangesEnumeration" )
817 SC_SIMPLE_SERVICE_INFO( ScCellFormatsObj, "ScCellFormatsObj", "com.sun.star.sheet.CellFormatRanges" )
818 SC_SIMPLE_SERVICE_INFO( ScUniqueCellFormatsEnumeration, "ScUniqueCellFormatsEnumeration", "com.sun.star.sheet.UniqueCellFormatRangesEnumeration" )
819 SC_SIMPLE_SERVICE_INFO( ScUniqueCellFormatsObj, "ScUniqueCellFormatsObj", "com.sun.star.sheet.UniqueCellFormatRanges" )
820 SC_SIMPLE_SERVICE_INFO( ScCellRangesBase, "ScCellRangesBase", "stardiv.unknown" )
821 SC_SIMPLE_SERVICE_INFO( ScCellsEnumeration, "ScCellsEnumeration", "com.sun.star.sheet.CellsEnumeration" )
822 SC_SIMPLE_SERVICE_INFO( ScCellsObj, "ScCellsObj", "com.sun.star.sheet.Cells" )
823 SC_SIMPLE_SERVICE_INFO( ScTableColumnObj, "ScTableColumnObj", "com.sun.star.table.TableColumn" )
824 SC_SIMPLE_SERVICE_INFO( ScTableRowObj, "ScTableRowObj", "com.sun.star.table.TableRow" )
825 
826 //------------------------------------------------------------------------
827 
828 SV_IMPL_PTRARR( XModifyListenerArr_Impl, XModifyListenerPtr );
829 SV_IMPL_PTRARR( ScNamedEntryArr_Impl, ScNamedEntryPtr );
830 
831 //------------------------------------------------------------------------
832 
833 //!	ScLinkListener in anderes File verschieben !!!
834 
~ScLinkListener()835 ScLinkListener::~ScLinkListener()
836 {
837 }
838 
Notify(SvtBroadcaster &,const SfxHint & rHint)839 void ScLinkListener::Notify( SvtBroadcaster&, const SfxHint& rHint )
840 {
841 	aLink.Call( (SfxHint*)&rHint );
842 }
843 
844 //------------------------------------------------------------------------
845 
lcl_CopyProperties(beans::XPropertySet & rDest,beans::XPropertySet & rSource)846 void lcl_CopyProperties( beans::XPropertySet& rDest, beans::XPropertySet& rSource )
847 {
848 	uno::Reference<beans::XPropertySetInfo> xInfo(rSource.getPropertySetInfo());
849 	if (xInfo.is())
850 	{
851 		uno::Sequence<beans::Property> aSeq(xInfo->getProperties());
852 		const beans::Property* pAry = aSeq.getConstArray();
853 		sal_uLong nCount = aSeq.getLength();
854 		for (sal_uLong i=0; i<nCount; i++)
855 		{
856 			rtl::OUString aName(pAry[i].Name);
857 			rDest.setPropertyValue( aName, rSource.getPropertyValue( aName ) );
858 		}
859 	}
860 }
861 
lcl_FirstTab(const ScRangeList & rRanges)862 SCTAB lcl_FirstTab( const ScRangeList& rRanges )
863 {
864 	DBG_ASSERT(rRanges.Count() >= 1, "was fuer Ranges ?!?!");
865 	const ScRange* pFirst = rRanges.GetObject(0);
866 	if (pFirst)
867 		return pFirst->aStart.Tab();
868 
869 	return 0;	// soll nicht sein
870 }
871 
lcl_WholeSheet(const ScRangeList & rRanges)872 sal_Bool lcl_WholeSheet( const ScRangeList& rRanges )
873 {
874 	if ( rRanges.Count() == 1 )
875 	{
876 		ScRange* pRange = rRanges.GetObject(0);
877 		if ( pRange && pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
878 					   pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
879 			return sal_True;
880 	}
881 	return sal_False;
882 }
883 
884 //------------------------------------------------------------------------
885 
lcl_SummaryToSubTotal(sheet::GeneralFunction eSummary)886 ScSubTotalFunc lcl_SummaryToSubTotal( sheet::GeneralFunction eSummary )
887 {
888 	ScSubTotalFunc eSubTotal;
889 	switch (eSummary)
890 	{
891 		case sheet::GeneralFunction_SUM:
892 			eSubTotal = SUBTOTAL_FUNC_SUM;
893 			break;
894 		case sheet::GeneralFunction_COUNT:
895 			eSubTotal = SUBTOTAL_FUNC_CNT2;
896 			break;
897 		case sheet::GeneralFunction_AVERAGE:
898 			eSubTotal = SUBTOTAL_FUNC_AVE;
899 			break;
900 		case sheet::GeneralFunction_MAX:
901 			eSubTotal = SUBTOTAL_FUNC_MAX;
902 			break;
903 		case sheet::GeneralFunction_MIN:
904 			eSubTotal = SUBTOTAL_FUNC_MIN;
905 			break;
906 		case sheet::GeneralFunction_PRODUCT:
907 			eSubTotal = SUBTOTAL_FUNC_PROD;
908 			break;
909 		case sheet::GeneralFunction_COUNTNUMS:
910 			eSubTotal = SUBTOTAL_FUNC_CNT;
911 			break;
912 		case sheet::GeneralFunction_STDEV:
913 			eSubTotal = SUBTOTAL_FUNC_STD;
914 			break;
915 		case sheet::GeneralFunction_STDEVP:
916 			eSubTotal = SUBTOTAL_FUNC_STDP;
917 			break;
918 		case sheet::GeneralFunction_VAR:
919 			eSubTotal = SUBTOTAL_FUNC_VAR;
920 			break;
921 		case sheet::GeneralFunction_VARP:
922 			eSubTotal = SUBTOTAL_FUNC_VARP;
923 			break;
924 
925 		case sheet::GeneralFunction_NONE:
926 		case sheet::GeneralFunction_AUTO:
927 		default:
928 			eSubTotal = SUBTOTAL_FUNC_NONE;
929 			break;
930 	}
931 	return eSubTotal;
932 }
933 
934 //------------------------------------------------------------------------
935 
GetBorderLine(SvxBorderLine & rLine,const table::BorderLine & rStruct)936 const SvxBorderLine* ScHelperFunctions::GetBorderLine( SvxBorderLine& rLine, const table::BorderLine& rStruct )
937 {
938 	//	Calc braucht Twips, im Uno-Struct sind 1/100mm
939 
940 	rLine.SetOutWidth( (sal_uInt16)HMMToTwips( rStruct.OuterLineWidth ) );
941 	rLine.SetInWidth(  (sal_uInt16)HMMToTwips( rStruct.InnerLineWidth ) );
942 	rLine.SetDistance( (sal_uInt16)HMMToTwips( rStruct.LineDistance ) );
943 	rLine.SetColor( ColorData( rStruct.Color ) );
944 
945 	if ( rLine.GetOutWidth() || rLine.GetInWidth() || rLine.GetDistance() )
946 		return &rLine;
947 	else
948 		return NULL;
949 }
950 
FillBoxItems(SvxBoxItem & rOuter,SvxBoxInfoItem & rInner,const table::TableBorder & rBorder)951 void ScHelperFunctions::FillBoxItems( SvxBoxItem& rOuter, SvxBoxInfoItem& rInner, const table::TableBorder& rBorder )
952 {
953 	SvxBorderLine aLine;
954 	rOuter.SetDistance( (sal_uInt16)HMMToTwips( rBorder.Distance ) );
955     rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.TopLine ),		BOX_LINE_TOP );
956 	rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.BottomLine ),		BOX_LINE_BOTTOM );
957 	rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.LeftLine ),		BOX_LINE_LEFT );
958 	rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.RightLine ),		BOX_LINE_RIGHT );
959 	rInner.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.HorizontalLine ),	BOXINFO_LINE_HORI );
960 	rInner.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.VerticalLine ),	BOXINFO_LINE_VERT );
961 	rInner.SetValid( VALID_TOP,		 rBorder.IsTopLineValid );
962 	rInner.SetValid( VALID_BOTTOM,	 rBorder.IsBottomLineValid );
963 	rInner.SetValid( VALID_LEFT,	 rBorder.IsLeftLineValid );
964 	rInner.SetValid( VALID_RIGHT,	 rBorder.IsRightLineValid );
965 	rInner.SetValid( VALID_HORI,	 rBorder.IsHorizontalLineValid );
966 	rInner.SetValid( VALID_VERT,	 rBorder.IsVerticalLineValid );
967 	rInner.SetValid( VALID_DISTANCE, rBorder.IsDistanceValid );
968 	rInner.SetTable( sal_True );
969 }
970 
FillBorderLine(table::BorderLine & rStruct,const SvxBorderLine * pLine)971 void ScHelperFunctions::FillBorderLine( table::BorderLine& rStruct, const SvxBorderLine* pLine )
972 {
973 	if (pLine)
974 	{
975 		rStruct.Color		   = pLine->GetColor().GetColor();
976 		rStruct.InnerLineWidth = (sal_Int16)TwipsToHMM( pLine->GetInWidth() );
977 		rStruct.OuterLineWidth = (sal_Int16)TwipsToHMM( pLine->GetOutWidth() );
978 		rStruct.LineDistance   = (sal_Int16)TwipsToHMM( pLine->GetDistance() );
979 	}
980 	else
981 		rStruct.Color = rStruct.InnerLineWidth =
982 			rStruct.OuterLineWidth = rStruct.LineDistance = 0;
983 }
984 
FillTableBorder(table::TableBorder & rBorder,const SvxBoxItem & rOuter,const SvxBoxInfoItem & rInner)985 void ScHelperFunctions::FillTableBorder( table::TableBorder& rBorder,
986 							const SvxBoxItem& rOuter, const SvxBoxInfoItem& rInner )
987 {
988 	ScHelperFunctions::FillBorderLine( rBorder.TopLine, 		rOuter.GetTop() );
989 	ScHelperFunctions::FillBorderLine( rBorder.BottomLine,		rOuter.GetBottom() );
990 	ScHelperFunctions::FillBorderLine( rBorder.LeftLine,		rOuter.GetLeft() );
991 	ScHelperFunctions::FillBorderLine( rBorder.RightLine,		rOuter.GetRight() );
992 	ScHelperFunctions::FillBorderLine( rBorder.HorizontalLine,	rInner.GetHori() );
993 	ScHelperFunctions::FillBorderLine( rBorder.VerticalLine,	rInner.GetVert() );
994 
995 	rBorder.Distance 				= rOuter.GetDistance();
996 	rBorder.IsTopLineValid 			= rInner.IsValid(VALID_TOP);
997 	rBorder.IsBottomLineValid		= rInner.IsValid(VALID_BOTTOM);
998 	rBorder.IsLeftLineValid			= rInner.IsValid(VALID_LEFT);
999 	rBorder.IsRightLineValid		= rInner.IsValid(VALID_RIGHT);
1000 	rBorder.IsHorizontalLineValid 	= rInner.IsValid(VALID_HORI);
1001 	rBorder.IsVerticalLineValid		= rInner.IsValid(VALID_VERT);
1002 	rBorder.IsDistanceValid 		= rInner.IsValid(VALID_DISTANCE);
1003 }
1004 
1005 //------------------------------------------------------------------------
1006 
1007 //!	lcl_ApplyBorder nach docfunc verschieben!
1008 
ApplyBorder(ScDocShell * pDocShell,const ScRangeList & rRanges,const SvxBoxItem & rOuter,const SvxBoxInfoItem & rInner)1009 void ScHelperFunctions::ApplyBorder( ScDocShell* pDocShell, const ScRangeList& rRanges,
1010 						const SvxBoxItem& rOuter, const SvxBoxInfoItem& rInner )
1011 {
1012 	ScDocument* pDoc = pDocShell->GetDocument();
1013 	sal_Bool bUndo(pDoc->IsUndoEnabled());
1014 	ScDocument* pUndoDoc = NULL;
1015 	if (bUndo)
1016 		pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1017 	sal_uLong nCount = rRanges.Count();
1018 	sal_uLong i;
1019 	for (i=0; i<nCount; i++)
1020 	{
1021 		ScRange aRange(*rRanges.GetObject(i));
1022 		SCTAB nTab = aRange.aStart.Tab();
1023 
1024 		if (bUndo)
1025 		{
1026 			if ( i==0 )
1027 				pUndoDoc->InitUndo( pDoc, nTab, nTab );
1028 			else
1029 				pUndoDoc->AddUndoTab( nTab, nTab );
1030 			pDoc->CopyToDocument( aRange, IDF_ATTRIB, sal_False, pUndoDoc );
1031 		}
1032 
1033 		ScMarkData aMark;
1034 		aMark.SetMarkArea( aRange );
1035 		aMark.SelectTable( nTab, sal_True );
1036 
1037 		pDoc->ApplySelectionFrame( aMark, &rOuter, &rInner );
1038 		// RowHeight bei Umrandung alleine nicht noetig
1039 	}
1040 
1041 	if (bUndo)
1042 	{
1043 		pDocShell->GetUndoManager()->AddUndoAction(
1044 				new ScUndoBorder( pDocShell, rRanges, pUndoDoc, rOuter, rInner ) );
1045 	}
1046 
1047 	for (i=0; i<nCount; i++)
1048 		pDocShell->PostPaint( *rRanges.GetObject(i), PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
1049 
1050 	pDocShell->SetDocumentModified();
1051 }
1052 
1053 //! move lcl_PutDataArray to docfunc?
1054 //!	merge loop with ScFunctionAccess::callFunction
1055 
lcl_PutDataArray(ScDocShell & rDocShell,const ScRange & rRange,const uno::Sequence<uno::Sequence<uno::Any>> & aData)1056 sal_Bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange,
1057 						const uno::Sequence< uno::Sequence<uno::Any> >& aData )
1058 {
1059 //	sal_Bool bApi = sal_True;
1060 
1061 	ScDocument* pDoc = rDocShell.GetDocument();
1062 	SCTAB nTab = rRange.aStart.Tab();
1063 	SCCOL nStartCol = rRange.aStart.Col();
1064 	SCROW nStartRow = rRange.aStart.Row();
1065 	SCCOL nEndCol = rRange.aEnd.Col();
1066 	SCROW nEndRow = rRange.aEnd.Row();
1067 	sal_Bool bUndo(pDoc->IsUndoEnabled());
1068 
1069 	if ( !pDoc->IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1070 	{
1071 		//!	error message
1072 		return sal_False;
1073 	}
1074 
1075 	long nCols = 0;
1076 	long nRows = aData.getLength();
1077 	const uno::Sequence<uno::Any>* pArray = aData.getConstArray();
1078 	if ( nRows )
1079 		nCols = pArray[0].getLength();
1080 
1081 	if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1082 	{
1083 		//!	error message?
1084 		return sal_False;
1085 	}
1086 
1087 	ScDocument* pUndoDoc = NULL;
1088 	if ( bUndo )
1089 	{
1090 		pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1091 		pUndoDoc->InitUndo( pDoc, nTab, nTab );
1092         pDoc->CopyToDocument( rRange, IDF_CONTENTS|IDF_NOCAPTIONS, sal_False, pUndoDoc );
1093 	}
1094 
1095 	pDoc->DeleteAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, IDF_CONTENTS );
1096 
1097     /*  #164410# Use double allocation, which will speed up import filters
1098         using XCellRangeData::setDataArray() significantly. */
1099     bool bDoubleAlloc = ScColumn::bDoubleAlloc;
1100     ScColumn::bDoubleAlloc = true;
1101 
1102 	sal_Bool bError = sal_False;
1103 	SCROW nDocRow = nStartRow;
1104 	for (long nRow=0; nRow<nRows; nRow++)
1105 	{
1106 		const uno::Sequence<uno::Any>& rColSeq = pArray[nRow];
1107 		if ( rColSeq.getLength() == nCols )
1108 		{
1109 			SCCOL nDocCol = nStartCol;
1110 			const uno::Any* pColArr = rColSeq.getConstArray();
1111 			for (long nCol=0; nCol<nCols; nCol++)
1112 			{
1113 				const uno::Any& rElement = pColArr[nCol];
1114                 switch( rElement.getValueTypeClass() )
1115                 {
1116                     case uno::TypeClass_VOID:
1117                     {
1118                         // void = "no value"
1119                         pDoc->SetError( nDocCol, nDocRow, nTab, NOTAVAILABLE );
1120                     }
1121                     break;
1122 
1123                     //	#87871# accept integer types because Basic passes a floating point
1124                     //	variable as byte, short or long if it's an integer number.
1125                     case uno::TypeClass_BYTE:
1126                     case uno::TypeClass_SHORT:
1127                     case uno::TypeClass_UNSIGNED_SHORT:
1128                     case uno::TypeClass_LONG:
1129                     case uno::TypeClass_UNSIGNED_LONG:
1130                     case uno::TypeClass_FLOAT:
1131                     case uno::TypeClass_DOUBLE:
1132                     {
1133                         double fVal(0.0);
1134                         rElement >>= fVal;
1135                         pDoc->SetValue( nDocCol, nDocRow, nTab, fVal );
1136                     }
1137                     break;
1138 
1139                     case uno::TypeClass_STRING:
1140                     {
1141                         rtl::OUString aUStr;
1142                         rElement >>= aUStr;
1143                         if ( aUStr.getLength() )
1144                             pDoc->PutCell( nDocCol, nDocRow, nTab, new ScStringCell( aUStr ) );
1145                     }
1146                     break;
1147 
1148                     // accept Sequence<FormulaToken> for formula cells
1149                     case uno::TypeClass_SEQUENCE:
1150                     {
1151                         uno::Sequence< sheet::FormulaToken > aTokens;
1152                         if ( rElement >>= aTokens )
1153                         {
1154                             ScTokenArray aTokenArray;
1155                             ScTokenConversion::ConvertToTokenArray( *pDoc, aTokenArray, aTokens );
1156                             ScAddress aPos( nDocCol, nDocRow, nTab );
1157                             ScBaseCell* pNewCell = new ScFormulaCell( pDoc, aPos, &aTokenArray );
1158                             pDoc->PutCell( aPos, pNewCell );
1159                         }
1160                         else
1161                             bError = true;
1162                     }
1163                     break;
1164 
1165                     default:
1166                         bError = true;		// invalid type
1167                 }
1168 
1169 				++nDocCol;
1170 			}
1171 		}
1172 		else
1173 			bError = sal_True;							// wrong size
1174 
1175 		++nDocRow;
1176 	}
1177     ScColumn::bDoubleAlloc = bDoubleAlloc;
1178 
1179 	sal_Bool bHeight = rDocShell.AdjustRowHeight( nStartRow, nEndRow, nTab );
1180 
1181 	if ( pUndoDoc )
1182 	{
1183 		ScMarkData aDestMark;
1184 		aDestMark.SelectOneTable( nTab );
1185 		rDocShell.GetUndoManager()->AddUndoAction(
1186 			new ScUndoPaste( &rDocShell,
1187 				nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, aDestMark,
1188 				pUndoDoc, NULL, IDF_CONTENTS, NULL,NULL,NULL,NULL, sal_False ) );
1189 	}
1190 
1191 	if (!bHeight)
1192 		rDocShell.PostPaint( rRange, PAINT_GRID );		// AdjustRowHeight may have painted already
1193 
1194 	rDocShell.SetDocumentModified();
1195 
1196 	return !bError;
1197 }
1198 
lcl_PutFormulaArray(ScDocShell & rDocShell,const ScRange & rRange,const uno::Sequence<uno::Sequence<rtl::OUString>> & aData,const::rtl::OUString & rFormulaNmsp,const formula::FormulaGrammar::Grammar eGrammar)1199 sal_Bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange,
1200         const uno::Sequence< uno::Sequence<rtl::OUString> >& aData,
1201         const ::rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar )
1202 {
1203 //	sal_Bool bApi = sal_True;
1204 
1205 	ScDocument* pDoc = rDocShell.GetDocument();
1206 	SCTAB nTab = rRange.aStart.Tab();
1207 	SCCOL nStartCol = rRange.aStart.Col();
1208 	SCROW nStartRow = rRange.aStart.Row();
1209 	SCCOL nEndCol = rRange.aEnd.Col();
1210 	SCROW nEndRow = rRange.aEnd.Row();
1211 	sal_Bool bUndo(pDoc->IsUndoEnabled());
1212 
1213 	if ( !pDoc->IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) )
1214 	{
1215 		//!	error message
1216 		return sal_False;
1217 	}
1218 
1219 	long nCols = 0;
1220 	long nRows = aData.getLength();
1221 	const uno::Sequence<rtl::OUString>* pArray = aData.getConstArray();
1222 	if ( nRows )
1223 		nCols = pArray[0].getLength();
1224 
1225 	if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 )
1226 	{
1227 		//!	error message?
1228 		return sal_False;
1229 	}
1230 
1231 	ScDocument* pUndoDoc = NULL;
1232 	if ( bUndo )
1233 	{
1234 		pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
1235 		pUndoDoc->InitUndo( pDoc, nTab, nTab );
1236 		pDoc->CopyToDocument( rRange, IDF_CONTENTS, sal_False, pUndoDoc );
1237 	}
1238 
1239 	pDoc->DeleteAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, IDF_CONTENTS );
1240 
1241 	ScDocFunc aFunc( rDocShell );		// for InterpretEnglishString
1242 
1243 	sal_Bool bError = sal_False;
1244 	SCROW nDocRow = nStartRow;
1245 	for (long nRow=0; nRow<nRows; nRow++)
1246 	{
1247 		const uno::Sequence<rtl::OUString>& rColSeq = pArray[nRow];
1248 		if ( rColSeq.getLength() == nCols )
1249 		{
1250 			SCCOL nDocCol = nStartCol;
1251 			const rtl::OUString* pColArr = rColSeq.getConstArray();
1252 			for (long nCol=0; nCol<nCols; nCol++)
1253 			{
1254 				String aText(pColArr[nCol]);
1255 				ScAddress aPos( nDocCol, nDocRow, nTab );
1256                 ScBaseCell* pNewCell = aFunc.InterpretEnglishString( aPos, aText, rFormulaNmsp, eGrammar );
1257 				pDoc->PutCell( aPos, pNewCell );
1258 
1259 				++nDocCol;
1260 			}
1261 		}
1262 		else
1263 			bError = sal_True;							// wrong size
1264 
1265 		++nDocRow;
1266 	}
1267 
1268 	sal_Bool bHeight = rDocShell.AdjustRowHeight( nStartRow, nEndRow, nTab );
1269 
1270 	if ( pUndoDoc )
1271 	{
1272 		ScMarkData aDestMark;
1273 		aDestMark.SelectOneTable( nTab );
1274 		rDocShell.GetUndoManager()->AddUndoAction(
1275 			new ScUndoPaste( &rDocShell,
1276 				nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, aDestMark,
1277 				pUndoDoc, NULL, IDF_CONTENTS, NULL,NULL,NULL,NULL, sal_False ) );
1278 	}
1279 
1280 	if (!bHeight)
1281 		rDocShell.PostPaint( rRange, PAINT_GRID );		// AdjustRowHeight may have painted already
1282 
1283 	rDocShell.SetDocumentModified();
1284 
1285 	return !bError;
1286 }
1287 
1288 //	used in ScCellRangeObj::getFormulaArray and ScCellObj::GetInputString_Impl
lcl_GetInputString(ScDocument * pDoc,const ScAddress & rPosition,sal_Bool bEnglish)1289 String lcl_GetInputString( ScDocument* pDoc, const ScAddress& rPosition, sal_Bool bEnglish )
1290 {
1291 	String aVal;
1292 	if ( pDoc )
1293 	{
1294 		ScBaseCell* pCell = pDoc->GetCell( rPosition );
1295 		if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE )
1296 		{
1297 			CellType eType = pCell->GetCellType();
1298 			if ( eType == CELLTYPE_FORMULA )
1299 			{
1300 				ScFormulaCell* pForm = (ScFormulaCell*)pCell;
1301                 pForm->GetFormula( aVal,formula::FormulaGrammar::mapAPItoGrammar( bEnglish, false));
1302 			}
1303 			else
1304 			{
1305                 SvNumberFormatter* pFormatter = bEnglish ? ScGlobal::GetEnglishFormatter() :
1306 															pDoc->GetFormatTable();
1307                 // Since the English formatter was constructed with
1308                 // LANGUAGE_ENGLISH_US the "General" format has index key 0,
1309                 // we don't have to query.
1310 				sal_uInt32 nNumFmt = bEnglish ?
1311 //						pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US) :
1312                         0 :
1313 						pDoc->GetNumberFormat( rPosition );
1314 
1315 				if ( eType == CELLTYPE_EDIT )
1316 				{
1317 					//	GetString an der EditCell macht Leerzeichen aus Umbruechen,
1318 					//	hier werden die Umbrueche aber gebraucht
1319 					const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
1320 					if (pData)
1321 					{
1322 						EditEngine& rEngine = pDoc->GetEditEngine();
1323 						rEngine.SetText( *pData );
1324 						aVal = rEngine.GetText( LINEEND_LF );
1325 					}
1326 				}
1327 				else
1328 					ScCellFormat::GetInputString( pCell, nNumFmt, aVal, *pFormatter );
1329 
1330 				//	ggf. ein ' davorhaengen wie in ScTabViewShell::UpdateInputHandler
1331 				if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
1332 				{
1333 					double fDummy;
1334 					sal_Bool bIsNumberFormat(pFormatter->IsNumberFormat(aVal, nNumFmt, fDummy));
1335 					if ( bIsNumberFormat )
1336 						aVal.Insert('\'',0);
1337 					else if ( aVal.Len() && aVal.GetChar(0) == '\'' )
1338 					{
1339 						//	if the string starts with a "'", add another one because setFormula
1340 						//	strips one (like text input, except for "text" number formats)
1341 						if ( bEnglish || ( pFormatter->GetType(nNumFmt) != NUMBERFORMAT_TEXT ) )
1342 							aVal.Insert('\'',0);
1343 					}
1344 				}
1345 			}
1346 		}
1347 	}
1348 	return aVal;
1349 }
1350 
1351 //------------------------------------------------------------------------
1352 
1353 // Default-ctor fuer SMART_REFLECTION Krempel
ScCellRangesBase()1354 ScCellRangesBase::ScCellRangesBase() :
1355 	pPropSet(lcl_GetCellsPropertySet()),
1356 	pDocShell( NULL ),
1357 	pValueListener( NULL ),
1358 	pCurrentFlat( NULL ),
1359 	pCurrentDeep( NULL ),
1360 	pCurrentDataSet( NULL ),
1361 	pNoDfltCurrentDataSet( NULL ),
1362 	pMarkData( NULL ),
1363     nObjectId( 0 ),
1364 	bChartColAsHdr( sal_False ),
1365 	bChartRowAsHdr( sal_False ),
1366 	bCursorOnly( sal_False ),
1367 	bGotDataChangedHint( sal_False ),
1368 	aValueListeners( 0 )
1369 {
1370 }
1371 
ScCellRangesBase(ScDocShell * pDocSh,const ScRange & rR)1372 ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRange& rR) :
1373 	pPropSet(lcl_GetCellsPropertySet()),
1374 	pDocShell( pDocSh ),
1375 	pValueListener( NULL ),
1376 	pCurrentFlat( NULL ),
1377 	pCurrentDeep( NULL ),
1378 	pCurrentDataSet( NULL ),
1379 	pNoDfltCurrentDataSet( NULL ),
1380 	pMarkData( NULL ),
1381     nObjectId( 0 ),
1382 	bChartColAsHdr( sal_False ),
1383 	bChartRowAsHdr( sal_False ),
1384 	bCursorOnly( sal_False ),
1385 	bGotDataChangedHint( sal_False ),
1386 	aValueListeners( 0 )
1387 {
1388 	ScRange aCellRange(rR);
1389 	aCellRange.Justify();
1390 	aRanges.Append( aCellRange );
1391 
1392     if (pDocShell)  // Null if created with createInstance
1393     {
1394         ScDocument* pDoc = pDocShell->GetDocument();
1395         pDoc->AddUnoObject(*this);
1396         nObjectId = pDoc->GetNewUnoId();
1397     }
1398 }
1399 
ScCellRangesBase(ScDocShell * pDocSh,const ScRangeList & rR)1400 ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRangeList& rR) :
1401 	pPropSet(lcl_GetCellsPropertySet()),
1402 	pDocShell( pDocSh ),
1403 	pValueListener( NULL ),
1404 	pCurrentFlat( NULL ),
1405 	pCurrentDeep( NULL ),
1406 	pCurrentDataSet( NULL ),
1407 	pNoDfltCurrentDataSet( NULL ),
1408 	pMarkData( NULL ),
1409 	aRanges( rR ),
1410     nObjectId( 0 ),
1411 	bChartColAsHdr( sal_False ),
1412 	bChartRowAsHdr( sal_False ),
1413 	bCursorOnly( sal_False ),
1414 	bGotDataChangedHint( sal_False ),
1415 	aValueListeners( 0 )
1416 {
1417     if (pDocShell)  // Null if created with createInstance
1418     {
1419         ScDocument* pDoc = pDocShell->GetDocument();
1420         pDoc->AddUnoObject(*this);
1421         nObjectId = pDoc->GetNewUnoId();
1422     }
1423 }
1424 
~ScCellRangesBase()1425 ScCellRangesBase::~ScCellRangesBase()
1426 {
1427 	//	#107294# call RemoveUnoObject first, so no notification can happen
1428 	//	during ForgetCurrentAttrs
1429 
1430 	if (pDocShell)
1431 		pDocShell->GetDocument()->RemoveUnoObject(*this);
1432 
1433 	ForgetCurrentAttrs();
1434     ForgetMarkData();
1435 
1436 	delete pValueListener;
1437 
1438 	//!	XChartDataChangeEventListener abmelden ??
1439 	//!	(ChartCollection haelt dann auch dieses Objekt fest!)
1440 }
1441 
ForgetCurrentAttrs()1442 void ScCellRangesBase::ForgetCurrentAttrs()
1443 {
1444 	delete pCurrentFlat;
1445 	delete pCurrentDeep;
1446 	delete pCurrentDataSet;
1447 	delete pNoDfltCurrentDataSet;
1448 	pCurrentFlat = NULL;
1449 	pCurrentDeep = NULL;
1450 	pCurrentDataSet = NULL;
1451 	pNoDfltCurrentDataSet = NULL;
1452 
1453     // #i62483# pMarkData can remain unchanged, is deleted only if the range changes (RefChanged)
1454 }
1455 
ForgetMarkData()1456 void ScCellRangesBase::ForgetMarkData()
1457 {
1458     delete pMarkData;
1459     pMarkData = NULL;
1460 }
1461 
GetCurrentAttrsFlat()1462 const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsFlat()
1463 {
1464 	//	get and cache direct cell attributes for this object's range
1465 
1466 	if ( !pCurrentFlat && pDocShell )
1467 	{
1468 		ScDocument* pDoc = pDocShell->GetDocument();
1469 		pCurrentFlat = pDoc->CreateSelectionPattern( *GetMarkData(), sal_False );
1470 	}
1471 	return pCurrentFlat;
1472 }
1473 
GetCurrentAttrsDeep()1474 const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsDeep()
1475 {
1476 	//	get and cache cell attributes (incl. styles) for this object's range
1477 
1478 	if ( !pCurrentDeep && pDocShell )
1479 	{
1480 		ScDocument* pDoc = pDocShell->GetDocument();
1481 		pCurrentDeep = pDoc->CreateSelectionPattern( *GetMarkData(), sal_True );
1482 	}
1483 	return pCurrentDeep;
1484 }
1485 
GetCurrentDataSet(bool bNoDflt)1486 SfxItemSet* ScCellRangesBase::GetCurrentDataSet(bool bNoDflt)
1487 {
1488 	if(!pCurrentDataSet)
1489 	{
1490 		const ScPatternAttr* pPattern = GetCurrentAttrsDeep();
1491 		if ( pPattern )
1492 		{
1493 			//	Dontcare durch Default ersetzen, damit man immer eine Reflection hat
1494 			pCurrentDataSet = new SfxItemSet( pPattern->GetItemSet() );
1495 			pNoDfltCurrentDataSet = new SfxItemSet( pPattern->GetItemSet() );
1496 			pCurrentDataSet->ClearInvalidItems();
1497 		}
1498 	}
1499 	return bNoDflt ? pNoDfltCurrentDataSet : pCurrentDataSet;
1500 }
1501 
GetMarkData()1502 const ScMarkData* ScCellRangesBase::GetMarkData()
1503 {
1504 	if (!pMarkData)
1505 	{
1506 		pMarkData = new ScMarkData();
1507 		pMarkData->MarkFromRangeList( aRanges, sal_False );
1508 	}
1509 	return pMarkData;
1510 }
1511 
Notify(SfxBroadcaster &,const SfxHint & rHint)1512 void ScCellRangesBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
1513 {
1514 	if ( rHint.ISA( ScUpdateRefHint ) )
1515 	{
1516 		const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
1517 
1518         ScDocument* pDoc = pDocShell->GetDocument();
1519         ScRangeList* pUndoRanges = NULL;
1520         if ( pDoc->HasUnoRefUndo() )
1521             pUndoRanges = new ScRangeList( aRanges );
1522 
1523         if ( aRanges.UpdateReference( rRef.GetMode(), pDoc, rRef.GetRange(),
1524 									rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ) )
1525         {
1526             if (rRef.GetMode() == URM_INSDEL &&
1527                 aRanges.Count() == 1 &&
1528                 ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ))
1529             {
1530                 // #101755#; the range size of a sheet does not change
1531                 ScRange* pR = aRanges.First();
1532                 if (pR)
1533                 {
1534                     pR->aStart.SetCol(0);
1535                     pR->aStart.SetRow(0);
1536                     pR->aEnd.SetCol(MAXCOL);
1537                     pR->aEnd.SetRow(MAXROW);
1538                 }
1539             }
1540 			RefChanged();
1541 
1542             // #129050# any change of the range address is broadcast to value (modify) listeners
1543             if ( aValueListeners.Count() )
1544                 bGotDataChangedHint = sal_True;
1545 
1546             if ( pUndoRanges )
1547                 pDoc->AddUnoRefChange( nObjectId, *pUndoRanges );
1548         }
1549 
1550         delete pUndoRanges;
1551 	}
1552 	else if ( rHint.ISA( SfxSimpleHint ) )
1553 	{
1554 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1555 		if ( nId == SFX_HINT_DYING )
1556 		{
1557 			ForgetCurrentAttrs();
1558 			pDocShell = NULL;			// invalid
1559 
1560 			if ( aValueListeners.Count() != 0 )
1561 			{
1562 				//	dispose listeners
1563 
1564 			    lang::EventObject aEvent;
1565 			    aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
1566 			    for ( sal_uInt16 n=0; n<aValueListeners.Count(); n++ )
1567 			        (*aValueListeners[n])->disposing( aEvent );
1568 
1569 				aValueListeners.DeleteAndDestroy( 0, aValueListeners.Count() );
1570 
1571 				//	The listeners can't have the last ref to this, as it's still held
1572 				//	by the DocShell.
1573 			}
1574 		}
1575 		else if ( nId == SFX_HINT_DATACHANGED )
1576 		{
1577 			// document content changed -> forget cached attributes
1578 			ForgetCurrentAttrs();
1579 
1580 			if ( bGotDataChangedHint && pDocShell )
1581 			{
1582 				//	This object was notified of content changes, so one call
1583 				//	for each listener is generated now.
1584 				//	The calls can't be executed directly because the document's
1585 				//	UNO broadcaster list must not be modified.
1586 				//	Instead, add to the document's list of listener calls,
1587 				//	which will be executed directly after the broadcast of
1588 				//	SFX_HINT_DATACHANGED.
1589 
1590 				lang::EventObject aEvent;
1591 				aEvent.Source.set((cppu::OWeakObject*)this);
1592 
1593 				// the EventObject holds a Ref to this object until after the listener calls
1594 
1595 				ScDocument* pDoc = pDocShell->GetDocument();
1596 				for ( sal_uInt16 n=0; n<aValueListeners.Count(); n++ )
1597 					pDoc->AddUnoListenerCall( *aValueListeners[n], aEvent );
1598 
1599 				bGotDataChangedHint = sal_False;
1600 			}
1601 		}
1602         else if ( nId == SC_HINT_CALCALL )
1603         {
1604             // broadcast from DoHardRecalc - set bGotDataChangedHint
1605             // (SFX_HINT_DATACHANGED follows separately)
1606 
1607             if ( aValueListeners.Count() )
1608                 bGotDataChangedHint = sal_True;
1609         }
1610 	}
1611     else if ( rHint.ISA( ScUnoRefUndoHint ) )
1612     {
1613         const ScUnoRefUndoHint& rUndoHint = static_cast<const ScUnoRefUndoHint&>(rHint);
1614         if ( rUndoHint.GetObjectId() == nObjectId )
1615         {
1616             // restore ranges from hint
1617 
1618             aRanges = rUndoHint.GetRanges();
1619 
1620             RefChanged();
1621             if ( aValueListeners.Count() )
1622                 bGotDataChangedHint = sal_True;     // need to broadcast the undo, too
1623         }
1624     }
1625 }
1626 
RefChanged()1627 void ScCellRangesBase::RefChanged()
1628 {
1629 	//!	adjust XChartDataChangeEventListener
1630 
1631 	if ( pValueListener && aValueListeners.Count() != 0 )
1632 	{
1633 		pValueListener->EndListeningAll();
1634 
1635 		ScDocument* pDoc = pDocShell->GetDocument();
1636 		sal_uLong nCount = aRanges.Count();
1637 		for (sal_uLong i=0; i<nCount; i++)
1638 			pDoc->StartListeningArea( *aRanges.GetObject(i), pValueListener );
1639 	}
1640 
1641 	ForgetCurrentAttrs();
1642     ForgetMarkData();
1643 }
1644 
GetDocument() const1645 ScDocument* ScCellRangesBase::GetDocument() const
1646 {
1647 	if (pDocShell)
1648 		return pDocShell->GetDocument();
1649 	else
1650 		return NULL;
1651 }
1652 
InitInsertRange(ScDocShell * pDocSh,const ScRange & rR)1653 void ScCellRangesBase::InitInsertRange(ScDocShell* pDocSh, const ScRange& rR)
1654 {
1655 	if ( !pDocShell && pDocSh )
1656 	{
1657 		pDocShell = pDocSh;
1658 
1659 		ScRange aCellRange(rR);
1660 		aCellRange.Justify();
1661 		aRanges.RemoveAll();
1662 		aRanges.Append( aCellRange );
1663 
1664 		pDocShell->GetDocument()->AddUnoObject(*this);
1665 
1666 		RefChanged();	// Range im Range-Objekt anpassen
1667 	}
1668 }
1669 
AddRange(const ScRange & rRange,const sal_Bool bMergeRanges)1670 void ScCellRangesBase::AddRange(const ScRange& rRange, const sal_Bool bMergeRanges)
1671 {
1672 	if (bMergeRanges)
1673 		aRanges.Join(rRange);
1674 	else
1675 		aRanges.Append(rRange);
1676 	RefChanged();
1677 }
1678 
SetNewRange(const ScRange & rNew)1679 void ScCellRangesBase::SetNewRange(const ScRange& rNew)
1680 {
1681 	ScRange aCellRange(rNew);
1682 	aCellRange.Justify();
1683 
1684 	aRanges.RemoveAll();
1685 	aRanges.Append( aCellRange );
1686 	RefChanged();
1687 }
1688 
SetNewRanges(const ScRangeList & rNew)1689 void ScCellRangesBase::SetNewRanges(const ScRangeList& rNew)
1690 {
1691 	aRanges = rNew;
1692 	RefChanged();
1693 }
1694 
SetCursorOnly(sal_Bool bSet)1695 void ScCellRangesBase::SetCursorOnly( sal_Bool bSet )
1696 {
1697 	//	set for a selection object that is created from the cursor position
1698 	//	without anything selected (may contain several sheets)
1699 
1700 	bCursorOnly = bSet;
1701 }
1702 
queryInterface(const uno::Type & rType)1703 uno::Any SAL_CALL ScCellRangesBase::queryInterface( const uno::Type& rType )
1704 												throw(uno::RuntimeException)
1705 {
1706 	SC_QUERYINTERFACE( beans::XPropertySet )
1707 	SC_QUERYINTERFACE( beans::XMultiPropertySet )
1708     SC_QUERYINTERFACE( beans::XTolerantMultiPropertySet )
1709 	SC_QUERYINTERFACE( beans::XPropertyState )
1710 	SC_QUERYINTERFACE( sheet::XSheetOperation )
1711 	SC_QUERYINTERFACE( chart::XChartDataArray )
1712 	SC_QUERYINTERFACE( chart::XChartData )
1713 	SC_QUERYINTERFACE( util::XIndent )
1714 	SC_QUERYINTERFACE( sheet::XCellRangesQuery )
1715 	SC_QUERYINTERFACE( sheet::XFormulaQuery )
1716 	SC_QUERYINTERFACE( util::XReplaceable )
1717 	SC_QUERYINTERFACE( util::XSearchable )
1718 	SC_QUERYINTERFACE( util::XModifyBroadcaster )
1719 	SC_QUERYINTERFACE( lang::XServiceInfo )
1720 	SC_QUERYINTERFACE( lang::XUnoTunnel )
1721 	SC_QUERYINTERFACE( lang::XTypeProvider )
1722 
1723 	return OWeakObject::queryInterface( rType );
1724 }
1725 
acquire()1726 void SAL_CALL ScCellRangesBase::acquire() throw()
1727 {
1728 	OWeakObject::acquire();
1729 }
1730 
release()1731 void SAL_CALL ScCellRangesBase::release() throw()
1732 {
1733 	OWeakObject::release();
1734 }
1735 
getTypes()1736 uno::Sequence<uno::Type> SAL_CALL ScCellRangesBase::getTypes() throw(uno::RuntimeException)
1737 {
1738 	static uno::Sequence<uno::Type> aTypes;
1739 	if ( aTypes.getLength() == 0 )
1740 	{
1741 		aTypes.realloc(13);
1742 		uno::Type* pPtr = aTypes.getArray();
1743 		pPtr[0] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
1744 		pPtr[1] = getCppuType((const uno::Reference<beans::XMultiPropertySet>*)0);
1745 		pPtr[2] = getCppuType((const uno::Reference<beans::XPropertyState>*)0);
1746 		pPtr[3] = getCppuType((const uno::Reference<sheet::XSheetOperation>*)0);
1747 		pPtr[4] = getCppuType((const uno::Reference<chart::XChartDataArray>*)0);
1748 		pPtr[5] = getCppuType((const uno::Reference<util::XIndent>*)0);
1749 		pPtr[6] = getCppuType((const uno::Reference<sheet::XCellRangesQuery>*)0);
1750 		pPtr[7] = getCppuType((const uno::Reference<sheet::XFormulaQuery>*)0);
1751 		pPtr[8] = getCppuType((const uno::Reference<util::XReplaceable>*)0);
1752 		pPtr[9] = getCppuType((const uno::Reference<util::XModifyBroadcaster>*)0);
1753 		pPtr[10]= getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
1754 		pPtr[11]= getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
1755 		pPtr[12]= getCppuType((const uno::Reference<lang::XTypeProvider>*)0);
1756 	}
1757 	return aTypes;
1758 }
1759 
getImplementationId()1760 uno::Sequence<sal_Int8> SAL_CALL ScCellRangesBase::getImplementationId()
1761 													throw(uno::RuntimeException)
1762 {
1763 	static uno::Sequence< sal_Int8 > aId;
1764 	if( aId.getLength() == 0 )
1765 	{
1766 		aId.realloc( 16 );
1767 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1768 	}
1769 	return aId;
1770 }
1771 
1772 // ---
1773 
PaintRanges_Impl(sal_uInt16 nPart)1774 void ScCellRangesBase::PaintRanges_Impl( sal_uInt16 nPart )
1775 {
1776 	sal_uLong nCount = aRanges.Count();
1777 	for (sal_uLong i=0; i<nCount; i++)
1778 		pDocShell->PostPaint( *aRanges.GetObject(i), nPart );
1779 }
1780 
1781 // XSheetOperation
1782 
computeFunction(sheet::GeneralFunction nFunction)1783 double SAL_CALL ScCellRangesBase::computeFunction( sheet::GeneralFunction nFunction )
1784 												throw(uno::Exception, uno::RuntimeException)
1785 {
1786 	ScUnoGuard aGuard;
1787 	ScMarkData aMark(*GetMarkData());
1788 	aMark.MarkToSimple();
1789 	if (!aMark.IsMarked())
1790 		aMark.SetMarkNegative(sal_True);	// um Dummy Position angeben zu koennen
1791 
1792 	ScAddress aDummy;					// wenn nicht Marked, ignoriert wegen Negative
1793 	double fVal;
1794 	ScSubTotalFunc eFunc = lcl_SummaryToSubTotal( nFunction );
1795 	ScDocument* pDoc = pDocShell->GetDocument();
1796 	if ( !pDoc->GetSelectionFunction( eFunc, aDummy, aMark, fVal ) )
1797 	{
1798 		throw uno::RuntimeException();		//!	own exception?
1799 	}
1800 
1801 	return fVal;
1802 }
1803 
clearContents(sal_Int32 nContentFlags)1804 void SAL_CALL ScCellRangesBase::clearContents( sal_Int32 nContentFlags ) throw(uno::RuntimeException)
1805 {
1806 	ScUnoGuard aGuard;
1807 	if ( aRanges.Count() )
1808 	{
1809 		// only for clearContents: EDITATTR is only used if no contents are deleted
1810         sal_uInt16 nDelFlags = static_cast< sal_uInt16 >( nContentFlags & IDF_ALL );
1811 		if ( ( nContentFlags & IDF_EDITATTR ) && ( nContentFlags & IDF_CONTENTS ) == 0 )
1812 			nDelFlags |= IDF_EDITATTR;
1813 
1814 		ScDocFunc aFunc(*pDocShell);
1815 		aFunc.DeleteContents( *GetMarkData(), nDelFlags, sal_True, sal_True );
1816 	}
1817 	// sonst ist nichts zu tun
1818 }
1819 
1820 // XPropertyState
1821 
GetItemPropertyMap()1822 const SfxItemPropertyMap* ScCellRangesBase::GetItemPropertyMap()
1823 {
1824     return pPropSet->getPropertyMap();
1825 }
1826 
lcl_GetPropertyWhich(const SfxItemPropertySimpleEntry * pEntry,sal_uInt16 & rItemWhich)1827 void lcl_GetPropertyWhich( const SfxItemPropertySimpleEntry* pEntry,
1828                                                 sal_uInt16& rItemWhich )
1829 {
1830 	//	Which-ID des betroffenen Items, auch wenn das Item die Property
1831 	//	nicht alleine behandeln kann
1832     if ( pEntry )
1833 	{
1834         if ( IsScItemWid( pEntry->nWID ) )
1835             rItemWhich = pEntry->nWID;
1836 		else
1837             switch ( pEntry->nWID )
1838 			{
1839 				case SC_WID_UNO_TBLBORD:
1840 					rItemWhich = ATTR_BORDER;
1841 					break;
1842 				case SC_WID_UNO_CONDFMT:
1843 				case SC_WID_UNO_CONDLOC:
1844 				case SC_WID_UNO_CONDXML:
1845 					rItemWhich = ATTR_CONDITIONAL;
1846 					break;
1847 				case SC_WID_UNO_VALIDAT:
1848 				case SC_WID_UNO_VALILOC:
1849 				case SC_WID_UNO_VALIXML:
1850 					rItemWhich = ATTR_VALIDDATA;
1851 					break;
1852 			}
1853 	}
1854 
1855 }
1856 
GetOnePropertyState(sal_uInt16 nItemWhich,const SfxItemPropertySimpleEntry * pEntry)1857 beans::PropertyState ScCellRangesBase::GetOnePropertyState( sal_uInt16 nItemWhich, const SfxItemPropertySimpleEntry* pEntry )
1858 {
1859 	beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE;
1860 	if ( nItemWhich )					// item wid (from map or special case)
1861 	{
1862 		//	For items that contain several properties (like background),
1863 		//	"ambiguous" is returned too often here
1864 
1865 		//	for PropertyState, don't look at styles
1866 		const ScPatternAttr* pPattern = GetCurrentAttrsFlat();
1867 		if ( pPattern )
1868 		{
1869 			SfxItemState eState = pPattern->GetItemSet().GetItemState( nItemWhich, sal_False );
1870 
1871 //           //  if no rotate value is set, look at orientation
1872 //           //! also for a fixed value of 0 (in case orientation is ambiguous)?
1873 //           if ( nItemWhich == ATTR_ROTATE_VALUE && eState == SFX_ITEM_DEFAULT )
1874 //               eState = pPattern->GetItemSet().GetItemState( ATTR_ORIENTATION, sal_False );
1875 
1876 			if ( nItemWhich == ATTR_VALUE_FORMAT && eState == SFX_ITEM_DEFAULT )
1877 				eState = pPattern->GetItemSet().GetItemState( ATTR_LANGUAGE_FORMAT, sal_False );
1878 
1879 			if ( eState == SFX_ITEM_SET )
1880 				eRet = beans::PropertyState_DIRECT_VALUE;
1881 			else if ( eState == SFX_ITEM_DEFAULT )
1882 				eRet = beans::PropertyState_DEFAULT_VALUE;
1883 			else if ( eState == SFX_ITEM_DONTCARE )
1884 				eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1885 			else
1886 			{
1887 				DBG_ERROR("unbekannter ItemState");
1888 			}
1889 		}
1890 	}
1891     else if ( pEntry )
1892 	{
1893         if ( pEntry->nWID == SC_WID_UNO_CHCOLHDR || pEntry->nWID == SC_WID_UNO_CHROWHDR || pEntry->nWID == SC_WID_UNO_ABSNAME )
1894 			eRet = beans::PropertyState_DIRECT_VALUE;
1895         else if ( pEntry->nWID == SC_WID_UNO_CELLSTYL )
1896 		{
1897 			//	a style is always set, there's no default state
1898 			const ScStyleSheet* pStyle = pDocShell->GetDocument()->GetSelectionStyle(*GetMarkData());
1899 			if (pStyle)
1900 				eRet = beans::PropertyState_DIRECT_VALUE;
1901 			else
1902 				eRet = beans::PropertyState_AMBIGUOUS_VALUE;
1903 		}
1904         else if ( pEntry->nWID == SC_WID_UNO_NUMRULES )
1905 			eRet = beans::PropertyState_DEFAULT_VALUE;		// numbering rules are always default
1906 	}
1907 	return eRet;
1908 }
1909 
getPropertyState(const rtl::OUString & aPropertyName)1910 beans::PropertyState SAL_CALL ScCellRangesBase::getPropertyState( const rtl::OUString& aPropertyName )
1911 								throw(beans::UnknownPropertyException, uno::RuntimeException)
1912 {
1913 	ScUnoGuard aGuard;
1914 	if ( aRanges.Count() == 0 )
1915 		throw uno::RuntimeException();
1916 
1917     const SfxItemPropertyMap* pMap = GetItemPropertyMap();     // from derived class
1918 	sal_uInt16 nItemWhich = 0;
1919     const SfxItemPropertySimpleEntry* pEntry  = pMap->getByName( aPropertyName );
1920     lcl_GetPropertyWhich( pEntry, nItemWhich );
1921     return GetOnePropertyState( nItemWhich, pEntry );
1922 }
1923 
getPropertyStates(const uno::Sequence<rtl::OUString> & aPropertyNames)1924 uno::Sequence<beans::PropertyState> SAL_CALL ScCellRangesBase::getPropertyStates(
1925 								const uno::Sequence<rtl::OUString>& aPropertyNames )
1926 							throw(beans::UnknownPropertyException, uno::RuntimeException)
1927 {
1928 	ScUnoGuard aGuard;
1929 
1930     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
1931 
1932 	uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
1933 	beans::PropertyState* pStates = aRet.getArray();
1934 	for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
1935 	{
1936 		sal_uInt16 nItemWhich = 0;
1937         const SfxItemPropertySimpleEntry* pEntry  = pPropertyMap->getByName( aPropertyNames[i] );
1938         lcl_GetPropertyWhich( pEntry, nItemWhich );
1939         pStates[i] = GetOnePropertyState(nItemWhich, pEntry);
1940     }
1941 	return aRet;
1942 }
1943 
setPropertyToDefault(const rtl::OUString & aPropertyName)1944 void SAL_CALL ScCellRangesBase::setPropertyToDefault( const rtl::OUString& aPropertyName )
1945 							throw(beans::UnknownPropertyException, uno::RuntimeException)
1946 {
1947 	ScUnoGuard aGuard;
1948 	if ( pDocShell )
1949 	{
1950         const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
1951 		sal_uInt16 nItemWhich = 0;
1952         const SfxItemPropertySimpleEntry* pEntry  = pPropertyMap->getByName( aPropertyName );
1953         lcl_GetPropertyWhich( pEntry, nItemWhich );
1954 		if ( nItemWhich )				// item wid (from map or special case)
1955 		{
1956 			if ( aRanges.Count() )		// leer = nichts zu tun
1957 			{
1958 				ScDocFunc aFunc(*pDocShell);
1959 
1960 				//!	Bei Items, die mehrere Properties enthalten (z.B. Hintergrund)
1961 				//!	wird hier zuviel zurueckgesetzt
1962 
1963 //               //! for ATTR_ROTATE_VALUE, also reset ATTR_ORIENTATION?
1964 
1965 				sal_uInt16 aWIDs[3];
1966 				aWIDs[0] = nItemWhich;
1967 				if ( nItemWhich == ATTR_VALUE_FORMAT )
1968 				{
1969 					aWIDs[1] = ATTR_LANGUAGE_FORMAT;	// #67847# language for number formats
1970 					aWIDs[2] = 0;
1971 				}
1972 				else
1973 					aWIDs[1] = 0;
1974 				aFunc.ClearItems( *GetMarkData(), aWIDs, sal_True );
1975 			}
1976 		}
1977         else if ( pEntry )
1978 		{
1979             if ( pEntry->nWID == SC_WID_UNO_CHCOLHDR )
1980 				bChartColAsHdr = sal_False;
1981             else if ( pEntry->nWID == SC_WID_UNO_CHROWHDR )
1982 				bChartRowAsHdr = sal_False;
1983             else if ( pEntry->nWID == SC_WID_UNO_CELLSTYL )
1984 			{
1985 				ScDocFunc aFunc(*pDocShell);
1986 				aFunc.ApplyStyle( *GetMarkData(), ScGlobal::GetRscString(STR_STYLENAME_STANDARD), sal_True, sal_True );
1987 			}
1988 		}
1989 	}
1990 }
1991 
getPropertyDefault(const rtl::OUString & aPropertyName)1992 uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault( const rtl::OUString& aPropertyName )
1993 								throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1994 										uno::RuntimeException)
1995 {
1996 	//!	mit getPropertyValue zusammenfassen
1997 
1998 	ScUnoGuard aGuard;
1999 	uno::Any aAny;
2000 
2001 	if ( pDocShell )
2002 	{
2003 		ScDocument* pDoc = pDocShell->GetDocument();
2004         const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2005         const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyName );
2006         if ( pEntry )
2007 		{
2008             if ( IsScItemWid( pEntry->nWID ) )
2009 			{
2010 				const ScPatternAttr* pPattern = pDoc->GetDefPattern();
2011 				if ( pPattern )
2012 				{
2013 					const SfxItemSet& rSet = pPattern->GetItemSet();
2014 
2015                     switch ( pEntry->nWID )     // fuer Item-Spezial-Behandlungen
2016 					{
2017 						case ATTR_VALUE_FORMAT:
2018 							//	default has no language set
2019                             aAny <<= (sal_Int32)( ((const SfxUInt32Item&)rSet.Get(pEntry->nWID)).GetValue() );
2020 							break;
2021 						case ATTR_INDENT:
2022 							aAny <<= (sal_Int16)( TwipsToHMM(((const SfxUInt16Item&)
2023                                             rSet.Get(pEntry->nWID)).GetValue()) );
2024 							break;
2025 						default:
2026 							pPropSet->getPropertyValue(aPropertyName, rSet, aAny);
2027 					}
2028 				}
2029 			}
2030 			else
2031                 switch ( pEntry->nWID )
2032 				{
2033 					case SC_WID_UNO_CHCOLHDR:
2034 					case SC_WID_UNO_CHROWHDR:
2035 						ScUnoHelpFunctions::SetBoolInAny( aAny, sal_False );
2036 						break;
2037 					case SC_WID_UNO_CELLSTYL:
2038 						aAny <<= rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName(
2039 									ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA ) );
2040 						break;
2041 					case SC_WID_UNO_TBLBORD:
2042 						{
2043 							const ScPatternAttr* pPattern = pDoc->GetDefPattern();
2044 							if ( pPattern )
2045 							{
2046 								table::TableBorder aBorder;
2047 								ScHelperFunctions::FillTableBorder( aBorder,
2048 										(const SvxBoxItem&)pPattern->GetItem(ATTR_BORDER),
2049 										(const SvxBoxInfoItem&)pPattern->GetItem(ATTR_BORDER_INNER) );
2050 								aAny <<= aBorder;
2051 							}
2052 						}
2053 						break;
2054 					case SC_WID_UNO_CONDFMT:
2055 					case SC_WID_UNO_CONDLOC:
2056 					case SC_WID_UNO_CONDXML:
2057 						{
2058                             sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_CONDLOC );
2059                             sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_CONDXML );
2060                             formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2061                                     pDoc->GetStorageGrammar() :
2062                                    formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2063 
2064 							aAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
2065 									new ScTableConditionalFormat( pDoc, 0, eGrammar ));
2066 						}
2067 						break;
2068 					case SC_WID_UNO_VALIDAT:
2069 					case SC_WID_UNO_VALILOC:
2070 					case SC_WID_UNO_VALIXML:
2071 						{
2072                             sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_VALILOC );
2073                             sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_VALIXML );
2074                             formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2075                                     pDoc->GetStorageGrammar() :
2076                                    formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2077 
2078 							aAny <<= uno::Reference<beans::XPropertySet>(
2079 									new ScTableValidationObj( pDoc, 0, eGrammar ));
2080 						}
2081 						break;
2082 					case SC_WID_UNO_NUMRULES:
2083 						{
2084 							aAny <<= uno::Reference<container::XIndexReplace>(ScStyleObj::CreateEmptyNumberingRules());
2085 						}
2086 						break;
2087 				}
2088 		}
2089 	}
2090 
2091 	return aAny;
2092 }
2093 
2094 // XPropertySet
2095 
getPropertySetInfo()2096 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangesBase::getPropertySetInfo()
2097 														throw(uno::RuntimeException)
2098 {
2099 	ScUnoGuard aGuard;
2100 	static uno::Reference<beans::XPropertySetInfo> aRef(
2101 		new SfxItemPropertySetInfo( pPropSet->getPropertyMap() ));
2102 	return aRef;
2103 }
2104 
2105 
lcl_SetCellProperty(const SfxItemPropertySimpleEntry & rEntry,const uno::Any & rValue,ScPatternAttr & rPattern,ScDocument * pDoc,sal_uInt16 & rFirstItemId,sal_uInt16 & rSecondItemId)2106 void lcl_SetCellProperty( const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rValue,
2107 							ScPatternAttr& rPattern, ScDocument* pDoc,
2108 							sal_uInt16& rFirstItemId, sal_uInt16& rSecondItemId )
2109 {
2110     rFirstItemId = rEntry.nWID;
2111 	rSecondItemId = 0;
2112 
2113 	SfxItemSet& rSet = rPattern.GetItemSet();
2114     switch ( rEntry.nWID )
2115 	{
2116 		case ATTR_VALUE_FORMAT:
2117 			{
2118 				// #67847# language for number formats
2119 				SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
2120 				sal_uLong nOldFormat = ((const SfxUInt32Item&)rSet.Get( ATTR_VALUE_FORMAT )).GetValue();
2121 				LanguageType eOldLang = ((const SvxLanguageItem&)rSet.Get( ATTR_LANGUAGE_FORMAT )).GetLanguage();
2122 				nOldFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang );
2123 
2124 				sal_Int32 nIntVal = 0;
2125 				if ( rValue >>= nIntVal )
2126 				{
2127 					sal_uLong nNewFormat = (sal_uLong)nIntVal;
2128 					rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
2129 
2130 					const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat );
2131 					LanguageType eNewLang =
2132 						pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
2133 					if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW )
2134 					{
2135 						rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
2136 
2137 						// #40606# if only language is changed,
2138 						// don't touch number format attribute
2139 						sal_uLong nNewMod = nNewFormat % SV_COUNTRY_LANGUAGE_OFFSET;
2140 						if ( nNewMod == ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) &&
2141 							 nNewMod <= SV_MAX_ANZ_STANDARD_FORMATE )
2142 						{
2143 							rFirstItemId = 0;		// don't use ATTR_VALUE_FORMAT value
2144 						}
2145 
2146 						rSecondItemId = ATTR_LANGUAGE_FORMAT;
2147 					}
2148 				}
2149                 else
2150                     throw lang::IllegalArgumentException();
2151 			}
2152 			break;
2153 		case ATTR_INDENT:
2154 			{
2155 				sal_Int16 nIntVal = 0;
2156 				if ( rValue >>= nIntVal )
2157                     rSet.Put( SfxUInt16Item( rEntry.nWID, (sal_uInt16)HMMToTwips(nIntVal) ) );
2158                 else
2159                     throw lang::IllegalArgumentException();
2160 			}
2161 			break;
2162 		case ATTR_ROTATE_VALUE:
2163 			{
2164 				sal_Int32 nRotVal = 0;
2165 				if ( rValue >>= nRotVal )
2166 				{
2167 					//	stored value is always between 0 and 360 deg.
2168 					nRotVal %= 36000;
2169 					if ( nRotVal < 0 )
2170 						nRotVal += 36000;
2171 
2172 					rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, nRotVal ) );
2173 				}
2174                 else
2175                     throw lang::IllegalArgumentException();
2176 			}
2177 			break;
2178         case ATTR_STACKED:
2179             {
2180                 table::CellOrientation eOrient;
2181                 if( rValue >>= eOrient )
2182                 {
2183                     switch( eOrient )
2184                     {
2185                         case table::CellOrientation_STANDARD:
2186                             rSet.Put( SfxBoolItem( ATTR_STACKED, sal_False ) );
2187                         break;
2188                         case table::CellOrientation_TOPBOTTOM:
2189                             rSet.Put( SfxBoolItem( ATTR_STACKED, sal_False ) );
2190                             rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
2191                             rSecondItemId = ATTR_ROTATE_VALUE;
2192                         break;
2193                         case table::CellOrientation_BOTTOMTOP:
2194                             rSet.Put( SfxBoolItem( ATTR_STACKED, sal_False ) );
2195                             rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
2196                             rSecondItemId = ATTR_ROTATE_VALUE;
2197                         break;
2198                         case table::CellOrientation_STACKED:
2199                             rSet.Put( SfxBoolItem( ATTR_STACKED, sal_True ) );
2200                         break;
2201                         default:
2202                         {
2203                             // added to avoid warnings
2204                         }
2205                     }
2206                 }
2207             }
2208             break;
2209 		default:
2210 			{
2211 				lcl_GetCellsPropertySet()->setPropertyValue(rEntry, rValue, rSet);
2212 			}
2213 	}
2214 }
2215 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)2216 void SAL_CALL ScCellRangesBase::setPropertyValue(
2217 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
2218 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2219 						lang::IllegalArgumentException, lang::WrappedTargetException,
2220 						uno::RuntimeException)
2221 {
2222 	ScUnoGuard aGuard;
2223 
2224 	if ( !pDocShell || aRanges.Count() == 0 )
2225 		throw uno::RuntimeException();
2226 
2227     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2228     const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyName );
2229     if ( !pEntry )
2230 		throw beans::UnknownPropertyException();
2231 
2232     SetOnePropertyValue( pEntry, aValue );
2233 }
2234 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)2235 void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
2236 								throw(lang::IllegalArgumentException, uno::RuntimeException)
2237 {
2238     if ( pEntry )
2239 	{
2240         if ( IsScItemWid( pEntry->nWID ) )
2241 		{
2242 			if ( aRanges.Count() )		// leer = nichts zu tun
2243 			{
2244 				ScDocument* pDoc = pDocShell->GetDocument();
2245 				ScDocFunc aFunc(*pDocShell);
2246 
2247 				//	Fuer Teile von zusammengesetzten Items mit mehreren Properties (z.B. Hintergrund)
2248 				//	muss vorher das alte Item aus dem Dokument geholt werden
2249 				//!	Das kann hier aber nicht erkannt werden
2250 				//!	-> eigenes Flag im PropertyMap-Eintrag, oder was ???
2251 				//!	Item direkt von einzelner Position im Bereich holen?
2252 				//	ClearInvalidItems, damit auf jeden Fall ein Item vom richtigen Typ da ist
2253 
2254 				ScPatternAttr aPattern( *GetCurrentAttrsDeep() );
2255 				SfxItemSet& rSet = aPattern.GetItemSet();
2256 				rSet.ClearInvalidItems();
2257 
2258 				sal_uInt16 nFirstItem, nSecondItem;
2259                 lcl_SetCellProperty( *pEntry, aValue, aPattern, pDoc, nFirstItem, nSecondItem );
2260 
2261 				for (sal_uInt16 nWhich = ATTR_PATTERN_START; nWhich <= ATTR_PATTERN_END; nWhich++)
2262 					if ( nWhich != nFirstItem && nWhich != nSecondItem )
2263 						rSet.ClearItem(nWhich);
2264 
2265 				aFunc.ApplyAttributes( *GetMarkData(), aPattern, sal_True, sal_True );
2266 			}
2267 		}
2268 		else		// implemented here
2269             switch ( pEntry->nWID )
2270 			{
2271 				case SC_WID_UNO_CHCOLHDR:
2272 					// chart header flags are set for this object, not stored with document
2273 					bChartColAsHdr = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2274 					break;
2275 				case SC_WID_UNO_CHROWHDR:
2276 					bChartRowAsHdr = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2277 					break;
2278 				case SC_WID_UNO_CELLSTYL:
2279 					{
2280 						rtl::OUString aStrVal;
2281 						aValue >>= aStrVal;
2282 						String aString(ScStyleNameConversion::ProgrammaticToDisplayName(
2283 															aStrVal, SFX_STYLE_FAMILY_PARA ));
2284 						ScDocFunc aFunc(*pDocShell);
2285 						aFunc.ApplyStyle( *GetMarkData(), aString, sal_True, sal_True );
2286 					}
2287 					break;
2288 				case SC_WID_UNO_TBLBORD:
2289 					{
2290 						table::TableBorder aBorder;
2291 						if ( aRanges.Count() && ( aValue >>= aBorder ) )	// empty = nothing to do
2292 						{
2293 							SvxBoxItem aOuter(ATTR_BORDER);
2294 							SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
2295 							ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
2296 
2297 							ScHelperFunctions::ApplyBorder( pDocShell, aRanges, aOuter, aInner );	//! docfunc
2298 						}
2299 					}
2300 					break;
2301 				case SC_WID_UNO_CONDFMT:
2302 				case SC_WID_UNO_CONDLOC:
2303 				case SC_WID_UNO_CONDXML:
2304 					{
2305                         uno::Reference<sheet::XSheetConditionalEntries> xInterface(aValue, uno::UNO_QUERY);
2306 						if ( aRanges.Count() && xInterface.is() )	// leer = nichts zu tun
2307 						{
2308 							ScTableConditionalFormat* pFormat =
2309 									ScTableConditionalFormat::getImplementation( xInterface );
2310 							if (pFormat)
2311 							{
2312 								ScDocument* pDoc = pDocShell->GetDocument();
2313                                 sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_CONDLOC );
2314                                 sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_CONDXML );
2315                                 formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2316                                        formula::FormulaGrammar::GRAM_UNSPECIFIED :
2317                                        formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2318 
2319 								ScConditionalFormat aNew( 0, pDoc );	// Index wird beim Einfuegen gesetzt
2320 								pFormat->FillFormat( aNew, pDoc, eGrammar );
2321 								sal_uLong nIndex = pDoc->AddCondFormat( aNew );
2322 
2323 								ScDocFunc aFunc(*pDocShell);
2324 
2325 								ScPatternAttr aPattern( pDoc->GetPool() );
2326 								aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) );
2327 								aFunc.ApplyAttributes( *GetMarkData(), aPattern, sal_True, sal_True );
2328 							}
2329 						}
2330 					}
2331 					break;
2332 				case SC_WID_UNO_VALIDAT:
2333 				case SC_WID_UNO_VALILOC:
2334 				case SC_WID_UNO_VALIXML:
2335 					{
2336                         uno::Reference<beans::XPropertySet> xInterface(aValue, uno::UNO_QUERY);
2337 						if ( aRanges.Count() && xInterface.is() )	// leer = nichts zu tun
2338 						{
2339 							ScTableValidationObj* pValidObj =
2340 									ScTableValidationObj::getImplementation( xInterface );
2341 							if (pValidObj)
2342 							{
2343 								ScDocument* pDoc = pDocShell->GetDocument();
2344                                 sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_VALILOC );
2345                                 sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_VALIXML );
2346                                 formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2347                                        formula::FormulaGrammar::GRAM_UNSPECIFIED :
2348                                        formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2349 
2350 								ScValidationData* pNewData =
2351 										pValidObj->CreateValidationData( pDoc, eGrammar );
2352 								sal_uLong nIndex = pDoc->AddValidationEntry( *pNewData );
2353 								delete pNewData;
2354 
2355 								ScDocFunc aFunc(*pDocShell);
2356 
2357 								ScPatternAttr aPattern( pDoc->GetPool() );
2358 								aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
2359 								aFunc.ApplyAttributes( *GetMarkData(), aPattern, sal_True, sal_True );
2360 							}
2361 						}
2362 					}
2363 					break;
2364 				// SC_WID_UNO_NUMRULES is ignored...
2365 			}
2366 	}
2367 }
2368 
getPropertyValue(const rtl::OUString & aPropertyName)2369 uno::Any SAL_CALL ScCellRangesBase::getPropertyValue( const rtl::OUString& aPropertyName )
2370 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2371 						uno::RuntimeException)
2372 {
2373 	ScUnoGuard aGuard;
2374 
2375 	if ( !pDocShell || aRanges.Count() == 0 )
2376 		throw uno::RuntimeException();
2377 
2378     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2379     const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyName );
2380     if ( !pEntry )
2381 		throw beans::UnknownPropertyException();
2382 
2383 	uno::Any aAny;
2384     GetOnePropertyValue( pEntry, aAny );
2385 	return aAny;
2386 }
2387 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)2388 void ScCellRangesBase::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
2389 												uno::Any& rAny )
2390 												throw(uno::RuntimeException)
2391 {
2392     if ( pEntry )
2393 	{
2394         if ( IsScItemWid( pEntry->nWID ) )
2395 		{
2396 			SfxItemSet* pDataSet = GetCurrentDataSet();
2397 			if ( pDataSet )
2398 			{
2399                 switch ( pEntry->nWID )     // fuer Item-Spezial-Behandlungen
2400 				{
2401 					case ATTR_VALUE_FORMAT:
2402 						{
2403 							ScDocument* pDoc = pDocShell->GetDocument();
2404 
2405 							sal_uLong nOldFormat = ((const SfxUInt32Item&)
2406 									pDataSet->Get( ATTR_VALUE_FORMAT )).GetValue();
2407 							LanguageType eOldLang = ((const SvxLanguageItem&)
2408 									pDataSet->Get( ATTR_LANGUAGE_FORMAT )).GetLanguage();
2409 							nOldFormat = pDoc->GetFormatTable()->
2410 									GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang );
2411 							rAny <<= (sal_Int32)( nOldFormat );
2412 						}
2413 						break;
2414 					case ATTR_INDENT:
2415 						rAny <<= (sal_Int16)( TwipsToHMM(((const SfxUInt16Item&)
2416                                         pDataSet->Get(pEntry->nWID)).GetValue()) );
2417 						break;
2418                     case ATTR_STACKED:
2419                         {
2420                             sal_Int32 nRot = ((const SfxInt32Item&)pDataSet->Get(ATTR_ROTATE_VALUE)).GetValue();
2421                             sal_Bool bStacked = ((const SfxBoolItem&)pDataSet->Get(pEntry->nWID)).GetValue();
2422                             SvxOrientationItem( nRot, bStacked, 0 ).QueryValue( rAny );
2423                         }
2424                         break;
2425 					default:
2426                         pPropSet->getPropertyValue(*pEntry, *pDataSet, rAny);
2427 				}
2428 			}
2429 		}
2430 		else		// implemented here
2431             switch ( pEntry->nWID )
2432 			{
2433 				case SC_WID_UNO_CHCOLHDR:
2434 					ScUnoHelpFunctions::SetBoolInAny( rAny, bChartColAsHdr );
2435 					break;
2436 				case SC_WID_UNO_CHROWHDR:
2437 					ScUnoHelpFunctions::SetBoolInAny( rAny, bChartRowAsHdr );
2438 					break;
2439 				case SC_WID_UNO_CELLSTYL:
2440 					{
2441 						String aStyleName;
2442 						const ScStyleSheet* pStyle = pDocShell->GetDocument()->GetSelectionStyle(*GetMarkData());
2443 						if (pStyle)
2444 							aStyleName = pStyle->GetName();
2445 						rAny <<= rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName(
2446 																aStyleName, SFX_STYLE_FAMILY_PARA ) );
2447 					}
2448 					break;
2449 				case SC_WID_UNO_TBLBORD:
2450 					{
2451 						//!	loop throgh all ranges
2452 						const ScRange* pFirst = aRanges.GetObject(0);
2453 						if (pFirst)
2454 						{
2455 							SvxBoxItem aOuter(ATTR_BORDER);
2456 							SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
2457 
2458 							ScDocument* pDoc = pDocShell->GetDocument();
2459 							ScMarkData aMark;
2460 							aMark.SetMarkArea( *pFirst );
2461 							aMark.SelectTable( pFirst->aStart.Tab(), sal_True );
2462 							pDoc->GetSelectionFrame( aMark, aOuter, aInner );
2463 
2464 							table::TableBorder aBorder;
2465 							ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner );
2466 							rAny <<= aBorder;
2467 						}
2468 					}
2469 					break;
2470 				case SC_WID_UNO_CONDFMT:
2471 				case SC_WID_UNO_CONDLOC:
2472 				case SC_WID_UNO_CONDXML:
2473 					{
2474 						const ScPatternAttr* pPattern = GetCurrentAttrsDeep();
2475 						if ( pPattern )
2476 						{
2477 							ScDocument* pDoc = pDocShell->GetDocument();
2478                             sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_CONDLOC );
2479                             sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_CONDXML );
2480                             formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2481                                     pDoc->GetStorageGrammar() :
2482                                    formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2483 							sal_uLong nIndex = ((const SfxUInt32Item&)
2484 									pPattern->GetItem(ATTR_CONDITIONAL)).GetValue();
2485 							rAny <<= uno::Reference<sheet::XSheetConditionalEntries>(
2486 									new ScTableConditionalFormat( pDoc, nIndex, eGrammar ));
2487 						}
2488 					}
2489 					break;
2490 				case SC_WID_UNO_VALIDAT:
2491 				case SC_WID_UNO_VALILOC:
2492 				case SC_WID_UNO_VALIXML:
2493 					{
2494 						const ScPatternAttr* pPattern = GetCurrentAttrsDeep();
2495 						if ( pPattern )
2496 						{
2497 							ScDocument* pDoc = pDocShell->GetDocument();
2498                             sal_Bool bEnglish = ( pEntry->nWID != SC_WID_UNO_VALILOC );
2499                             sal_Bool bXML = ( pEntry->nWID == SC_WID_UNO_VALIXML );
2500                             formula::FormulaGrammar::Grammar eGrammar = (bXML ?
2501                                     pDoc->GetStorageGrammar() :
2502                                    formula::FormulaGrammar::mapAPItoGrammar( bEnglish, bXML));
2503 							sal_uLong nIndex = ((const SfxUInt32Item&)
2504 									pPattern->GetItem(ATTR_VALIDDATA)).GetValue();
2505 							rAny <<= uno::Reference<beans::XPropertySet>(
2506 									new ScTableValidationObj( pDoc, nIndex, eGrammar ));
2507 						}
2508 					}
2509 					break;
2510 				case SC_WID_UNO_NUMRULES:
2511 					{
2512 						// always return empty numbering rules object
2513 						rAny <<= uno::Reference<container::XIndexReplace>(ScStyleObj::CreateEmptyNumberingRules());
2514 					}
2515 					break;
2516                 case SC_WID_UNO_ABSNAME:
2517                     {
2518                         String sRet;
2519                         aRanges.Format(sRet, SCR_ABS_3D, pDocShell->GetDocument());
2520                         rAny <<= rtl::OUString(sRet);
2521                     }
2522 			}
2523 	}
2524 }
2525 
addPropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)2526 void SAL_CALL ScCellRangesBase::addPropertyChangeListener( const rtl::OUString& /* aPropertyName */,
2527                             const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
2528 							throw(beans::UnknownPropertyException,
2529 									lang::WrappedTargetException, uno::RuntimeException)
2530 {
2531 	ScUnoGuard aGuard;
2532 	if ( aRanges.Count() == 0 )
2533 		throw uno::RuntimeException();
2534 
2535 	DBG_ERROR("not implemented");
2536 }
2537 
removePropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)2538 void SAL_CALL ScCellRangesBase::removePropertyChangeListener( const rtl::OUString& /* aPropertyName */,
2539                             const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
2540 							throw(beans::UnknownPropertyException,
2541 									lang::WrappedTargetException, uno::RuntimeException)
2542 {
2543 	ScUnoGuard aGuard;
2544 	if ( aRanges.Count() == 0 )
2545 		throw uno::RuntimeException();
2546 
2547 	DBG_ERROR("not implemented");
2548 }
2549 
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2550 void SAL_CALL ScCellRangesBase::addVetoableChangeListener( const rtl::OUString&,
2551 							const uno::Reference<beans::XVetoableChangeListener>&)
2552 							throw(beans::UnknownPropertyException,
2553 								lang::WrappedTargetException, uno::RuntimeException)
2554 {
2555 	DBG_ERROR("not implemented");
2556 }
2557 
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2558 void SAL_CALL ScCellRangesBase::removeVetoableChangeListener( const rtl::OUString&,
2559 							const uno::Reference<beans::XVetoableChangeListener>&)
2560 							throw(beans::UnknownPropertyException,
2561 								lang::WrappedTargetException, uno::RuntimeException)
2562 {
2563 	DBG_ERROR("not implemented");
2564 }
2565 
2566 // XMultiPropertySet
2567 
setPropertyValues(const uno::Sequence<rtl::OUString> & aPropertyNames,const uno::Sequence<uno::Any> & aValues)2568 void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< rtl::OUString >& aPropertyNames,
2569 									const uno::Sequence< uno::Any >& aValues )
2570 								throw (beans::PropertyVetoException,
2571 									lang::IllegalArgumentException,
2572 									lang::WrappedTargetException,
2573 									uno::RuntimeException)
2574 {
2575 	ScUnoGuard aGuard;
2576 
2577 	sal_Int32 nCount(aPropertyNames.getLength());
2578 	sal_Int32 nValues(aValues.getLength());
2579 	if (nCount != nValues)
2580 		throw lang::IllegalArgumentException();
2581 
2582 	if ( pDocShell && nCount )
2583 	{
2584         const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();      // from derived class
2585 		const rtl::OUString* pNames = aPropertyNames.getConstArray();
2586 		const uno::Any* pValues = aValues.getConstArray();
2587 
2588         const SfxItemPropertySimpleEntry** pEntryArray = new const SfxItemPropertySimpleEntry*[nCount];
2589 
2590         sal_Int32 i;
2591         for(i = 0; i < nCount; i++)
2592         {
2593             // first loop: find all properties in map, but handle only CellStyle
2594             // (CellStyle must be set before any other cell properties)
2595 
2596             const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( pNames[i] );
2597             pEntryArray[i] = pEntry;
2598             if (pEntry)
2599             {
2600                 if ( pEntry->nWID == SC_WID_UNO_CELLSTYL )
2601                 {
2602                     try
2603                     {
2604                         SetOnePropertyValue( pEntry, pValues[i] );
2605                     }
2606                     catch ( lang::IllegalArgumentException& )
2607                     {
2608                         DBG_ERROR("exception when setting cell style");     // not supposed to happen
2609                     }
2610                 }
2611             }
2612         }
2613 
2614 		ScDocument* pDoc = pDocShell->GetDocument();
2615 		ScPatternAttr* pOldPattern = NULL;
2616 		ScPatternAttr* pNewPattern = NULL;
2617 
2618 		for(i = 0; i < nCount; i++)
2619 		{
2620             // second loop: handle other properties
2621 
2622             const SfxItemPropertySimpleEntry* pEntry = pEntryArray[i];
2623             if ( pEntry )
2624 			{
2625                 if ( IsScItemWid( pEntry->nWID ) )  // can be handled by SfxItemPropertySet
2626 				{
2627 					if ( !pOldPattern )
2628 					{
2629 						pOldPattern = new ScPatternAttr( *GetCurrentAttrsDeep() );
2630 						pOldPattern->GetItemSet().ClearInvalidItems();
2631 						pNewPattern = new ScPatternAttr( pDoc->GetPool() );
2632 					}
2633 
2634 					//	collect items in pNewPattern, apply with one call after the loop
2635 
2636 					sal_uInt16 nFirstItem, nSecondItem;
2637                     lcl_SetCellProperty( *pEntry, pValues[i], *pOldPattern, pDoc, nFirstItem, nSecondItem );
2638 
2639 					//	put only affected items into new set
2640 					if ( nFirstItem )
2641 						pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2642 					if ( nSecondItem )
2643 						pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2644 				}
2645                 else if ( pEntry->nWID != SC_WID_UNO_CELLSTYL )   // CellStyle is handled above
2646 				{
2647 					//	call virtual method to set a single property
2648                     SetOnePropertyValue( pEntry, pValues[i] );
2649 				}
2650 			}
2651 		}
2652 
2653 		if ( pNewPattern && aRanges.Count() )
2654 		{
2655 			ScDocFunc aFunc(*pDocShell);
2656 			aFunc.ApplyAttributes( *GetMarkData(), *pNewPattern, sal_True, sal_True );
2657 		}
2658 
2659 		delete pNewPattern;
2660 		delete pOldPattern;
2661         delete[] pEntryArray;
2662 	}
2663 }
2664 
getPropertyValues(const uno::Sequence<rtl::OUString> & aPropertyNames)2665 uno::Sequence<uno::Any> SAL_CALL ScCellRangesBase::getPropertyValues(
2666 								const uno::Sequence< rtl::OUString >& aPropertyNames )
2667 									throw (uno::RuntimeException)
2668 {
2669 	ScUnoGuard aGuard;
2670 
2671     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2672 
2673 	uno::Sequence<uno::Any> aRet(aPropertyNames.getLength());
2674 	uno::Any* pProperties = aRet.getArray();
2675 	for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
2676 	{
2677         const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyNames[i] );
2678         GetOnePropertyValue( pEntry, pProperties[i] );
2679     }
2680 	return aRet;
2681 }
2682 
addPropertiesChangeListener(const uno::Sequence<rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)2683 void SAL_CALL ScCellRangesBase::addPropertiesChangeListener( const uno::Sequence< rtl::OUString >& /* aPropertyNames */,
2684                                     const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
2685 								throw (uno::RuntimeException)
2686 {
2687 	DBG_ERROR("not implemented");
2688 }
2689 
removePropertiesChangeListener(const uno::Reference<beans::XPropertiesChangeListener> &)2690 void SAL_CALL ScCellRangesBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
2691 								throw (uno::RuntimeException)
2692 {
2693 	DBG_ERROR("not implemented");
2694 }
2695 
firePropertiesChangeEvent(const uno::Sequence<rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)2696 void SAL_CALL ScCellRangesBase::firePropertiesChangeEvent( const uno::Sequence< rtl::OUString >& /* aPropertyNames */,
2697                                     const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
2698 								throw (uno::RuntimeException)
2699 {
2700 	DBG_ERROR("not implemented");
2701 }
2702 
IMPL_LINK(ScCellRangesBase,ValueListenerHdl,SfxHint *,pHint)2703 IMPL_LINK( ScCellRangesBase, ValueListenerHdl, SfxHint*, pHint )
2704 {
2705 	if ( pDocShell && pHint && pHint->ISA( SfxSimpleHint ) &&
2706 			((const SfxSimpleHint*)pHint)->GetId() & (SC_HINT_DATACHANGED | SC_HINT_DYING) )
2707 	{
2708 		//	This may be called several times for a single change, if several formulas
2709 		//	in the range are notified. So only a flag is set that is checked when
2710 		//	SFX_HINT_DATACHANGED is received.
2711 
2712 		bGotDataChangedHint = sal_True;
2713 	}
2714 	return 0;
2715 }
2716 
2717 // XTolerantMultiPropertySet
setPropertyValuesTolerant(const uno::Sequence<::rtl::OUString> & aPropertyNames,const uno::Sequence<uno::Any> & aValues)2718 uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::setPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames,
2719                                     const uno::Sequence< uno::Any >& aValues )
2720                                     throw (lang::IllegalArgumentException, uno::RuntimeException)
2721 {
2722     ScUnoGuard aGuard;
2723 
2724 	sal_Int32 nCount(aPropertyNames.getLength());
2725 	sal_Int32 nValues(aValues.getLength());
2726 	if (nCount != nValues)
2727 		throw lang::IllegalArgumentException();
2728 
2729 	if ( pDocShell && nCount )
2730 	{
2731         uno::Sequence < beans::SetPropertyTolerantFailed > aReturns(nCount);
2732 	    beans::SetPropertyTolerantFailed* pReturns = aReturns.getArray();
2733 
2734         const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2735 		const rtl::OUString* pNames = aPropertyNames.getConstArray();
2736 		const uno::Any* pValues = aValues.getConstArray();
2737 
2738         const SfxItemPropertySimpleEntry** pMapArray = new const SfxItemPropertySimpleEntry*[nCount];
2739 
2740         sal_Int32 i;
2741         for(i = 0; i < nCount; i++)
2742         {
2743             // first loop: find all properties in map, but handle only CellStyle
2744             // (CellStyle must be set before any other cell properties)
2745 
2746             const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( pNames[i] );
2747             pMapArray[i] = pEntry;
2748             if (pEntry)
2749             {
2750                 if ( pEntry->nWID == SC_WID_UNO_CELLSTYL )
2751                 {
2752                     try
2753                     {
2754                         SetOnePropertyValue( pEntry, pValues[i] );
2755                     }
2756                     catch ( lang::IllegalArgumentException& )
2757                     {
2758                         DBG_ERROR("exception when setting cell style");     // not supposed to happen
2759                     }
2760                 }
2761             }
2762         }
2763 
2764 		ScDocument* pDoc = pDocShell->GetDocument();
2765 		ScPatternAttr* pOldPattern = NULL;
2766 		ScPatternAttr* pNewPattern = NULL;
2767 
2768         sal_Int32 nFailed(0);
2769         for(i = 0; i < nCount; i++)
2770 		{
2771             // second loop: handle other properties
2772 
2773             const SfxItemPropertySimpleEntry* pEntry = pMapArray[i];
2774             if ( pEntry && ((pEntry->nFlags & beans::PropertyAttribute::READONLY) == 0))
2775 			{
2776                 if ( IsScItemWid( pEntry->nWID ) )  // can be handled by SfxItemPropertySet
2777 				{
2778 					if ( !pOldPattern )
2779 					{
2780 						pOldPattern = new ScPatternAttr( *GetCurrentAttrsDeep() );
2781 						pOldPattern->GetItemSet().ClearInvalidItems();
2782 						pNewPattern = new ScPatternAttr( pDoc->GetPool() );
2783 					}
2784 
2785 					//	collect items in pNewPattern, apply with one call after the loop
2786 
2787 					sal_uInt16 nFirstItem, nSecondItem;
2788                     try
2789                     {
2790                         lcl_SetCellProperty( *pEntry, pValues[i], *pOldPattern, pDoc, nFirstItem, nSecondItem );
2791 
2792                         //	put only affected items into new set
2793 					    if ( nFirstItem )
2794 						    pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) );
2795 					    if ( nSecondItem )
2796 						    pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) );
2797                     }
2798 	                catch ( lang::IllegalArgumentException& )
2799 	                {
2800                         pReturns[nFailed].Name = pNames[i];
2801                         pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2802                     }
2803 				}
2804                 else if ( pEntry->nWID != SC_WID_UNO_CELLSTYL )   // CellStyle is handled above
2805 				{
2806 					//	call virtual method to set a single property
2807                     try
2808                     {
2809                         SetOnePropertyValue( pEntry, pValues[i] );
2810                     }
2811 	                catch ( lang::IllegalArgumentException& )
2812 	                {
2813                         pReturns[nFailed].Name = pNames[i];
2814                         pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
2815                     }
2816 				}
2817 			}
2818 			else
2819             {
2820                 pReturns[nFailed].Name = pNames[i];
2821                 if (pEntry)
2822                     pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
2823                 else
2824                     pReturns[nFailed++].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2825             }
2826 		}
2827 
2828 		if ( pNewPattern && aRanges.Count() )
2829 		{
2830 			ScDocFunc aFunc(*pDocShell);
2831 			aFunc.ApplyAttributes( *GetMarkData(), *pNewPattern, sal_True, sal_True );
2832 		}
2833 
2834 		delete pNewPattern;
2835 		delete pOldPattern;
2836         delete[] pMapArray;
2837 
2838         aReturns.realloc(nFailed);
2839 
2840         return aReturns;
2841 	}
2842     return uno::Sequence < beans::SetPropertyTolerantFailed >();
2843 }
2844 
getPropertyValuesTolerant(const uno::Sequence<::rtl::OUString> & aPropertyNames)2845 uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL ScCellRangesBase::getPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames )
2846                                     throw (uno::RuntimeException)
2847 {
2848 	ScUnoGuard aGuard;
2849 
2850     sal_Int32 nCount(aPropertyNames.getLength());
2851     uno::Sequence < beans::GetPropertyTolerantResult > aReturns(nCount);
2852 	beans::GetPropertyTolerantResult* pReturns = aReturns.getArray();
2853 
2854     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2855 
2856 	for(sal_Int32 i = 0; i < nCount; i++)
2857 	{
2858         const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyNames[i] );
2859         if (!pEntry)
2860         {
2861             pReturns[i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2862         }
2863 		else
2864         {
2865         	sal_uInt16 nItemWhich = 0;
2866             lcl_GetPropertyWhich( pEntry, nItemWhich );
2867             pReturns[i].State = GetOnePropertyState( nItemWhich, pEntry );
2868             GetOnePropertyValue( pEntry, pReturns[i].Value );
2869             pReturns[i].Result = beans::TolerantPropertySetResultType::SUCCESS;
2870         }
2871     }
2872     return aReturns;
2873 }
2874 
getDirectPropertyValuesTolerant(const uno::Sequence<::rtl::OUString> & aPropertyNames)2875 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL ScCellRangesBase::getDirectPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames )
2876                                     throw (uno::RuntimeException)
2877 {
2878 	ScUnoGuard aGuard;
2879 
2880     sal_Int32 nCount(aPropertyNames.getLength());
2881     uno::Sequence < beans::GetDirectPropertyTolerantResult > aReturns(nCount);
2882 	beans::GetDirectPropertyTolerantResult* pReturns = aReturns.getArray();
2883 
2884     const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap();     // from derived class
2885 
2886     sal_Int32 j = 0;
2887 	for(sal_Int32 i = 0; i < nCount; i++)
2888 	{
2889         const SfxItemPropertySimpleEntry* pEntry = pPropertyMap->getByName( aPropertyNames[i] );
2890         if (!pEntry)
2891         {
2892             pReturns[i].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
2893         }
2894 		else
2895         {
2896         	sal_uInt16 nItemWhich = 0;
2897             lcl_GetPropertyWhich( pEntry, nItemWhich );
2898             pReturns[j].State = GetOnePropertyState( nItemWhich, pEntry );
2899             if (pReturns[j].State == beans::PropertyState_DIRECT_VALUE)
2900             {
2901                 GetOnePropertyValue( pEntry, pReturns[j].Value );
2902                 pReturns[j].Result = beans::TolerantPropertySetResultType::SUCCESS;
2903                 pReturns[j].Name = aPropertyNames[i];
2904                 ++j;
2905             }
2906         }
2907     }
2908     if (j < nCount)
2909         aReturns.realloc(j);
2910     return aReturns;
2911 }
2912 
2913 // XIndent
2914 
decrementIndent()2915 void SAL_CALL ScCellRangesBase::decrementIndent() throw(::com::sun::star::uno::RuntimeException)
2916 {
2917 	ScUnoGuard aGuard;
2918 	if ( pDocShell && aRanges.Count() )		// leer = nichts zu tun
2919 	{
2920 		ScDocFunc aFunc(*pDocShell);
2921         //#97041#; put only MultiMarked ScMarkData in ChangeIndent
2922         ScMarkData aMarkData(*GetMarkData());
2923         aMarkData.MarkToMulti();
2924 		aFunc.ChangeIndent( aMarkData, sal_False, sal_True );
2925 	}
2926 }
2927 
incrementIndent()2928 void SAL_CALL ScCellRangesBase::incrementIndent() throw(::com::sun::star::uno::RuntimeException)
2929 {
2930 	ScUnoGuard aGuard;
2931 	if ( pDocShell && aRanges.Count() )		// leer = nichts zu tun
2932 	{
2933 		ScDocFunc aFunc(*pDocShell);
2934         //#97041#; put only MultiMarked ScMarkData in ChangeIndent
2935         ScMarkData aMarkData(*GetMarkData());
2936         aMarkData.MarkToMulti();
2937 		aFunc.ChangeIndent( aMarkData, sal_True, sal_True );
2938 	}
2939 }
2940 
2941 // XChartData
2942 
CreateMemChart_Impl() const2943 ScMemChart* ScCellRangesBase::CreateMemChart_Impl() const
2944 {
2945 	if ( pDocShell && aRanges.Count() )
2946 	{
2947 		ScRangeListRef xChartRanges;
2948 		if ( aRanges.Count() == 1 )
2949 		{
2950 			//	ganze Tabelle sinnvoll begrenzen (auf belegten Datenbereich)
2951 			//	(nur hier, Listener werden auf den ganzen Bereich angemeldet)
2952 			//!	direkt testen, ob es ein ScTableSheetObj ist?
2953 
2954 			ScRange* pRange = aRanges.GetObject(0);
2955 			if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
2956 				 pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
2957 			{
2958 				SCTAB nTab = pRange->aStart.Tab();
2959 
2960                 SCCOL nStartX;
2961                 SCROW nStartY; // Anfang holen
2962                 if (!pDocShell->GetDocument()->GetDataStart( nTab, nStartX, nStartY ))
2963                 {
2964 					nStartX = 0;
2965                     nStartY = 0;
2966                 }
2967 
2968                 SCCOL nEndX;
2969                 SCROW nEndY; // Ende holen
2970                 if (!pDocShell->GetDocument()->GetTableArea( nTab, nEndX, nEndY ))
2971                 {
2972 					nEndX = 0;
2973                     nEndY = 0;
2974                 }
2975 
2976 				xChartRanges = new ScRangeList;
2977 				xChartRanges->Append( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
2978 			}
2979 		}
2980 		if (!xChartRanges.Is())			//	sonst Ranges direkt uebernehmen
2981 			xChartRanges = new ScRangeList(aRanges);
2982 		ScChartArray aArr( pDocShell->GetDocument(), xChartRanges, String() );
2983 
2984 		// RowAsHdr = ColHeaders und umgekehrt
2985 		aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );
2986 
2987 		return aArr.CreateMemChart();
2988 	}
2989 	return NULL;
2990 }
2991 
getData()2992 uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData()
2993 												throw(uno::RuntimeException)
2994 {
2995 	ScUnoGuard aGuard;
2996 	ScMemChart* pMemChart = CreateMemChart_Impl();
2997 	if ( pMemChart )
2998 	{
2999 		sal_Int32 nColCount = pMemChart->GetColCount();
3000 		sal_Int32 nRowCount = static_cast<sal_Int32>(pMemChart->GetRowCount());
3001 
3002 		uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount );
3003 		uno::Sequence<double>* pRowAry = aRowSeq.getArray();
3004 		for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
3005 		{
3006 			uno::Sequence<double> aColSeq( nColCount );
3007 			double* pColAry = aColSeq.getArray();
3008 			for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
3009 				pColAry[nCol] = pMemChart->GetData( static_cast<short>(nCol), static_cast<short>(nRow) );
3010 
3011 			pRowAry[nRow] = aColSeq;
3012 		}
3013 
3014 		delete pMemChart;
3015 		return aRowSeq;
3016 	}
3017 
3018 	return uno::Sequence< uno::Sequence<double> >(0);
3019 }
3020 
GetLimitedChartRanges_Impl(long nDataColumns,long nDataRows) const3021 ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( long nDataColumns, long nDataRows ) const
3022 {
3023 	if ( aRanges.Count() == 1 )
3024 	{
3025 		ScRange* pRange = aRanges.GetObject(0);
3026 		if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL &&
3027 			 pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW )
3028 		{
3029 			//	if aRanges is a complete sheet, limit to given size
3030 
3031 			SCTAB nTab = pRange->aStart.Tab();
3032 
3033 			long nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 );
3034 			if ( nEndColumn < 0 )
3035 				nEndColumn = 0;
3036 			if ( nEndColumn > MAXCOL )
3037 				nEndColumn = MAXCOL;
3038 
3039 			long nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 );
3040 			if ( nEndRow < 0 )
3041 				nEndRow = 0;
3042 			if ( nEndRow > MAXROW )
3043 				nEndRow = MAXROW;
3044 
3045 			ScRangeListRef xChartRanges = new ScRangeList;
3046 			xChartRanges->Append( ScRange( 0, 0, nTab, (SCCOL)nEndColumn, (SCROW)nEndRow, nTab ) );
3047 			return xChartRanges;
3048 		}
3049 	}
3050 
3051 	return new ScRangeList(aRanges);		// as-is
3052 }
3053 
setData(const uno::Sequence<uno::Sequence<double>> & aData)3054 void SAL_CALL ScCellRangesBase::setData( const uno::Sequence< uno::Sequence<double> >& aData )
3055 												throw(uno::RuntimeException)
3056 {
3057 	ScUnoGuard aGuard;
3058 	sal_Bool bDone = sal_False;
3059 	long nRowCount = aData.getLength();
3060 	long nColCount = nRowCount ? aData[0].getLength() : 0;
3061 	ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, nRowCount );
3062 	if ( pDocShell && xChartRanges.Is() )
3063 	{
3064 		ScDocument* pDoc = pDocShell->GetDocument();
3065 		ScChartArray aArr( pDoc, xChartRanges, String() );
3066 		aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );		// RowAsHdr = ColHeaders
3067 		const ScChartPositionMap* pPosMap = aArr.GetPositionMap();
3068 		if (pPosMap)
3069 		{
3070 			if ( pPosMap->GetColCount() == static_cast<SCCOL>(nColCount) &&
3071 				 pPosMap->GetRowCount() == static_cast<SCROW>(nRowCount) )
3072 			{
3073 				for (long nRow=0; nRow<nRowCount; nRow++)
3074 				{
3075 					const uno::Sequence<double>& rRowSeq = aData[nRow];
3076 					const double* pArray = rRowSeq.getConstArray();
3077 					nColCount = rRowSeq.getLength();
3078 					for (long nCol=0; nCol<nColCount; nCol++)
3079 					{
3080                         const ScAddress* pPos = pPosMap->GetPosition(
3081                                 sal::static_int_cast<SCCOL>(nCol),
3082 								sal::static_int_cast<SCROW>(nRow) );
3083 						if (pPos)
3084 						{
3085 							double fVal = pArray[nCol];
3086 							if ( fVal == DBL_MIN )
3087 								pDoc->PutCell( *pPos, NULL );		// empty cell
3088 							else
3089 								pDoc->SetValue( pPos->Col(), pPos->Row(), pPos->Tab(), pArray[nCol] );
3090 						}
3091 					}
3092 				}
3093 
3094 				//!	undo
3095 				PaintRanges_Impl( PAINT_GRID );
3096 				pDocShell->SetDocumentModified();
3097 				ForceChartListener_Impl();			// call listeners for this object synchronously
3098 				bDone = sal_True;
3099 			}
3100 		}
3101 	}
3102 
3103 	if (!bDone)
3104 		throw uno::RuntimeException();
3105 }
3106 
getRowDescriptions()3107 uno::Sequence<rtl::OUString> SAL_CALL ScCellRangesBase::getRowDescriptions()
3108 												throw(uno::RuntimeException)
3109 {
3110 	ScUnoGuard aGuard;
3111 	ScMemChart* pMemChart = CreateMemChart_Impl();
3112 	if ( pMemChart )
3113 	{
3114 		sal_Int32 nRowCount = static_cast<sal_Int32>(pMemChart->GetRowCount());
3115 		uno::Sequence<rtl::OUString> aSeq( nRowCount );
3116 		rtl::OUString* pAry = aSeq.getArray();
3117 		for (sal_Int32 nRow = 0; nRow < nRowCount; nRow++)
3118 			pAry[nRow] = pMemChart->GetRowText(static_cast<short>(nRow));
3119 
3120 		delete pMemChart;
3121 		return aSeq;
3122 	}
3123 	return uno::Sequence<rtl::OUString>(0);
3124 }
3125 
setRowDescriptions(const uno::Sequence<rtl::OUString> & aRowDescriptions)3126 void SAL_CALL ScCellRangesBase::setRowDescriptions(
3127 						const uno::Sequence<rtl::OUString>& aRowDescriptions )
3128 												throw(uno::RuntimeException)
3129 {
3130 	ScUnoGuard aGuard;
3131 	sal_Bool bDone = sal_False;
3132 	if ( bChartColAsHdr )
3133 	{
3134 		long nRowCount = aRowDescriptions.getLength();
3135 		ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( 1, nRowCount );
3136 		if ( pDocShell && xChartRanges.Is() )
3137 		{
3138 			ScDocument* pDoc = pDocShell->GetDocument();
3139 			ScChartArray aArr( pDoc, xChartRanges, String() );
3140 			aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );		// RowAsHdr = ColHeaders
3141 			const ScChartPositionMap* pPosMap = aArr.GetPositionMap();
3142 			if (pPosMap)
3143 			{
3144 				if ( pPosMap->GetRowCount() == static_cast<SCROW>(nRowCount) )
3145 				{
3146 					const rtl::OUString* pArray = aRowDescriptions.getConstArray();
3147 					for (long nRow=0; nRow<nRowCount; nRow++)
3148 					{
3149                         const ScAddress* pPos = pPosMap->GetRowHeaderPosition(
3150                                 static_cast<SCSIZE>(nRow) );
3151 						if (pPos)
3152 						{
3153 							String aStr = pArray[nRow];
3154 							if ( aStr.Len() )
3155 								pDoc->PutCell( *pPos, new ScStringCell( aStr ) );
3156 							else
3157 								pDoc->PutCell( *pPos, NULL );		// empty cell
3158 						}
3159 					}
3160 
3161 					//!	undo
3162 					PaintRanges_Impl( PAINT_GRID );
3163 					pDocShell->SetDocumentModified();
3164 					ForceChartListener_Impl();			// call listeners for this object synchronously
3165 					bDone = sal_True;
3166 				}
3167 			}
3168 		}
3169 	}
3170 
3171 	if (!bDone)
3172 		throw uno::RuntimeException();
3173 }
3174 
getColumnDescriptions()3175 uno::Sequence<rtl::OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions()
3176 												throw(uno::RuntimeException)
3177 {
3178 	ScUnoGuard aGuard;
3179 	ScMemChart* pMemChart = CreateMemChart_Impl();
3180 	if ( pMemChart )
3181 	{
3182 		sal_Int32 nColCount = pMemChart->GetColCount();
3183 		uno::Sequence<rtl::OUString> aSeq( nColCount );
3184 		rtl::OUString* pAry = aSeq.getArray();
3185 		for (sal_Int32 nCol = 0; nCol < nColCount; nCol++)
3186 			pAry[nCol] = pMemChart->GetColText(static_cast<short>(nCol));
3187 
3188 		delete pMemChart;
3189 		return aSeq;
3190 	}
3191 	return uno::Sequence<rtl::OUString>(0);
3192 }
3193 
setColumnDescriptions(const uno::Sequence<rtl::OUString> & aColumnDescriptions)3194 void SAL_CALL ScCellRangesBase::setColumnDescriptions(
3195 						const uno::Sequence<rtl::OUString>& aColumnDescriptions )
3196 												throw(uno::RuntimeException)
3197 {
3198 	ScUnoGuard aGuard;
3199 	sal_Bool bDone = sal_False;
3200 	if ( bChartRowAsHdr )
3201 	{
3202 		long nColCount = aColumnDescriptions.getLength();
3203 		ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, 1 );
3204 		if ( pDocShell && xChartRanges.Is() )
3205 		{
3206 			ScDocument* pDoc = pDocShell->GetDocument();
3207 			ScChartArray aArr( pDoc, xChartRanges, String() );
3208 			aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr );		// RowAsHdr = ColHeaders
3209 			const ScChartPositionMap* pPosMap = aArr.GetPositionMap();
3210 			if (pPosMap)
3211 			{
3212 				if ( pPosMap->GetColCount() == static_cast<SCCOL>(nColCount) )
3213 				{
3214 					const rtl::OUString* pArray = aColumnDescriptions.getConstArray();
3215 					for (long nCol=0; nCol<nColCount; nCol++)
3216 					{
3217                         const ScAddress* pPos = pPosMap->GetColHeaderPosition(
3218 							sal::static_int_cast<SCCOL>(nCol) );
3219 						if (pPos)
3220 						{
3221 							String aStr(pArray[nCol]);
3222 							if ( aStr.Len() )
3223 								pDoc->PutCell( *pPos, new ScStringCell( aStr ) );
3224 							else
3225 								pDoc->PutCell( *pPos, NULL );		// empty cell
3226 						}
3227 					}
3228 
3229 					//!	undo
3230 					PaintRanges_Impl( PAINT_GRID );
3231 					pDocShell->SetDocumentModified();
3232 					ForceChartListener_Impl();			// call listeners for this object synchronously
3233 					bDone = sal_True;
3234 				}
3235 			}
3236 		}
3237 	}
3238 
3239 	if (!bDone)
3240 		throw uno::RuntimeException();
3241 }
3242 
ForceChartListener_Impl()3243 void ScCellRangesBase::ForceChartListener_Impl()
3244 {
3245 	//	call Update immediately so the caller to setData etc. can
3246 	//	regognize the listener call
3247 
3248 	if ( pDocShell )
3249 	{
3250 		ScChartListenerCollection* pColl = pDocShell->GetDocument()->GetChartListenerCollection();
3251 		if ( pColl )
3252 		{
3253 			sal_uInt16 nCollCount = pColl->GetCount();
3254 			for ( sal_uInt16 nIndex = 0; nIndex < nCollCount; nIndex++ )
3255 			{
3256 				ScChartListener* pChartListener = (ScChartListener*)pColl->At(nIndex);
3257 				if ( pChartListener &&
3258 						pChartListener->GetUnoSource() == static_cast<chart::XChartData*>(this) &&
3259 						pChartListener->IsDirty() )
3260 					pChartListener->Update();
3261 			}
3262 		}
3263 	}
3264 }
3265 
lcl_UniqueName(ScStrCollection & rColl,const String & rPrefix)3266 String lcl_UniqueName( ScStrCollection& rColl, const String& rPrefix )
3267 {
3268 	long nNumber = 1;
3269 	sal_uInt16 nCollCount = rColl.GetCount();
3270 	while (sal_True)
3271 	{
3272 		String aName(rPrefix);
3273 		aName += String::CreateFromInt32( nNumber );
3274 		sal_Bool bFound = sal_False;
3275 		for (sal_uInt16 i=0; i<nCollCount; i++)
3276 			if ( rColl[i]->GetString() == aName )
3277 			{
3278 				bFound = sal_True;
3279 				break;
3280 			}
3281 		if (!bFound)
3282 			return aName;
3283 		++nNumber;
3284 	}
3285 }
3286 
addChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)3287 void SAL_CALL ScCellRangesBase::addChartDataChangeEventListener( const uno::Reference<
3288 									chart::XChartDataChangeEventListener >& aListener )
3289 								throw(uno::RuntimeException)
3290 {
3291 	ScUnoGuard aGuard;
3292 	if ( pDocShell && aRanges.Count() )
3293 	{
3294 		//!	auf doppelte testen?
3295 
3296 		ScDocument* pDoc = pDocShell->GetDocument();
3297 		ScRangeListRef aRangesRef( new ScRangeList(aRanges) );
3298 		ScChartListenerCollection* pColl = pDoc->GetChartListenerCollection();
3299 		String aName(lcl_UniqueName( *pColl,
3300 						String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("__Uno")) ));
3301 		ScChartListener* pListener = new ScChartListener( aName, pDoc, aRangesRef );
3302 		pListener->SetUno( aListener, this );
3303 		pColl->Insert( pListener );
3304 		pListener->StartListeningTo();
3305 	}
3306 }
3307 
removeChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)3308 void SAL_CALL ScCellRangesBase::removeChartDataChangeEventListener( const uno::Reference<
3309 									chart::XChartDataChangeEventListener >& aListener )
3310 								throw(uno::RuntimeException)
3311 {
3312 	ScUnoGuard aGuard;
3313 	if ( pDocShell && aRanges.Count() )
3314 	{
3315 		ScDocument* pDoc = pDocShell->GetDocument();
3316 		ScChartListenerCollection* pColl = pDoc->GetChartListenerCollection();
3317 		pColl->FreeUno( aListener, this );
3318 	}
3319 }
3320 
getNotANumber()3321 double SAL_CALL	ScCellRangesBase::getNotANumber() throw(::com::sun::star::uno::RuntimeException)
3322 {
3323 	//	im ScChartArray wird DBL_MIN verwendet, weil das Chart es so will
3324 	return DBL_MIN;
3325 }
3326 
isNotANumber(double nNumber)3327 sal_Bool SAL_CALL ScCellRangesBase::isNotANumber( double nNumber ) throw(uno::RuntimeException)
3328 {
3329 	//	im ScChartArray wird DBL_MIN verwendet, weil das Chart es so will
3330 	return (nNumber == DBL_MIN);
3331 }
3332 
3333 // XModifyBroadcaster
3334 
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)3335 void SAL_CALL ScCellRangesBase::addModifyListener( const uno::Reference<util::XModifyListener>& aListener )
3336 								throw(uno::RuntimeException)
3337 {
3338 	ScUnoGuard aGuard;
3339 	if ( aRanges.Count() == 0 )
3340 		throw uno::RuntimeException();
3341 
3342 	uno::Reference<util::XModifyListener> *pObj =
3343 			new uno::Reference<util::XModifyListener>( aListener );
3344 	aValueListeners.Insert( pObj, aValueListeners.Count() );
3345 
3346 	if ( aValueListeners.Count() == 1 )
3347 	{
3348 		if (!pValueListener)
3349 			pValueListener = new ScLinkListener( LINK( this, ScCellRangesBase, ValueListenerHdl ) );
3350 
3351 		ScDocument* pDoc = pDocShell->GetDocument();
3352 		sal_uLong nCount = aRanges.Count();
3353 		for (sal_uLong i=0; i<nCount; i++)
3354 			pDoc->StartListeningArea( *aRanges.GetObject(i), pValueListener );
3355 
3356 		acquire();	// don't lose this object (one ref for all listeners)
3357 	}
3358 }
3359 
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)3360 void SAL_CALL ScCellRangesBase::removeModifyListener( const uno::Reference<util::XModifyListener>& aListener )
3361 								throw(uno::RuntimeException)
3362 {
3363 
3364 	ScUnoGuard aGuard;
3365 	if ( aRanges.Count() == 0 )
3366 		throw uno::RuntimeException();
3367 
3368 	acquire();		// in case the listeners have the last ref - released below
3369 
3370 	sal_uInt16 nCount = aValueListeners.Count();
3371 	for ( sal_uInt16 n=nCount; n--; )
3372 	{
3373 		uno::Reference<util::XModifyListener> *pObj = aValueListeners[n];
3374 		if ( *pObj == aListener )
3375 		{
3376 			aValueListeners.DeleteAndDestroy( n );
3377 
3378 			if ( aValueListeners.Count() == 0 )
3379 			{
3380 				if (pValueListener)
3381 					pValueListener->EndListeningAll();
3382 
3383 				release();		// release the ref for the listeners
3384 			}
3385 
3386 			break;
3387 		}
3388 	}
3389 
3390 	release();		// might delete this object
3391 }
3392 
3393 // XCellRangesQuery
3394 
queryVisibleCells()3395 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryVisibleCells()
3396 									throw(uno::RuntimeException)
3397 {
3398 	ScUnoGuard aGuard;
3399 	if (pDocShell)
3400 	{
3401 		//!	fuer alle Tabellen getrennt, wenn Markierungen pro Tabelle getrennt sind!
3402 		SCTAB nTab = lcl_FirstTab(aRanges);
3403 
3404 		ScMarkData aMarkData(*GetMarkData());
3405 
3406 		ScDocument* pDoc = pDocShell->GetDocument();
3407 		SCCOL nCol = 0, nLastCol;
3408 		while (nCol <= MAXCOL)
3409 		{
3410 			if (pDoc->ColHidden(nCol, nTab, nLastCol))
3411 				// hidden columns.  Unselect them.
3412 				aMarkData.SetMultiMarkArea(ScRange(nCol, 0, nTab, nLastCol, MAXROW, nTab), false);
3413 
3414 			nCol = nLastCol + 1;
3415 		}
3416 
3417 		SCROW nRow = 0, nLastRow;
3418 		while (nRow <= MAXROW)
3419 		{
3420 			if (pDoc->RowHidden(nRow, nTab, nLastRow))
3421 				// These rows are hidden.  Unselect them.
3422 				aMarkData.SetMultiMarkArea(ScRange(0, nRow, nTab, MAXCOL, nLastRow, nTab), false);
3423 
3424 			nRow = nLastRow + 1;
3425 		}
3426 
3427 		ScRangeList aNewRanges;
3428 		aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
3429 		return new ScCellRangesObj( pDocShell, aNewRanges );
3430 	}
3431 
3432 	return NULL;
3433 }
3434 
queryEmptyCells()3435 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryEmptyCells()
3436 									throw(uno::RuntimeException)
3437 {
3438 	ScUnoGuard aGuard;
3439 	if (pDocShell)
3440 	{
3441 		ScDocument* pDoc = pDocShell->GetDocument();
3442 
3443 		ScMarkData aMarkData(*GetMarkData());
3444 
3445 		//	belegte Zellen wegmarkieren
3446 		sal_uLong nCount = aRanges.Count();
3447 		for (sal_uLong i=0; i<nCount; i++)
3448 		{
3449 			ScRange aRange = *aRanges.GetObject(i);
3450 
3451 			ScCellIterator aIter( pDoc, aRange );
3452 			ScBaseCell* pCell = aIter.GetFirst();
3453 			while (pCell)
3454 			{
3455 				//	Notizen zaehlen als nicht-leer
3456                 if ( !pCell->IsBlank() )
3457 					aMarkData.SetMultiMarkArea(
3458 							ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ),
3459 							sal_False );
3460 
3461 				pCell = aIter.GetNext();
3462 			}
3463 		}
3464 
3465 		ScRangeList aNewRanges;
3466 		//	IsMultiMarked reicht hier nicht (wird beim deselektieren nicht zurueckgesetzt)
3467 		//if (aMarkData.HasAnyMultiMarks()) // #20044# should be set for all empty range
3468 		aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
3469 
3470 		return new ScCellRangesObj( pDocShell, aNewRanges );	// aNewRanges kann leer sein
3471 	}
3472 
3473 	return NULL;
3474 }
3475 
queryContentCells(sal_Int16 nContentFlags)3476 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentCells(
3477 													sal_Int16 nContentFlags )
3478 									throw(uno::RuntimeException)
3479 {
3480 	ScUnoGuard aGuard;
3481 	if (pDocShell)
3482 	{
3483 		ScDocument* pDoc = pDocShell->GetDocument();
3484 
3485 		ScMarkData aMarkData;
3486 
3487 		//	passende Zellen selektieren
3488 		sal_uLong nCount = aRanges.Count();
3489 		for (sal_uLong i=0; i<nCount; i++)
3490 		{
3491 			ScRange aRange = *aRanges.GetObject(i);
3492 
3493 			ScCellIterator aIter( pDoc, aRange );
3494 			ScBaseCell* pCell = aIter.GetFirst();
3495 			while (pCell)
3496 			{
3497 				sal_Bool bAdd = sal_False;
3498                 if ( pCell->HasNote() && ( nContentFlags & sheet::CellFlags::ANNOTATION ) )
3499 					bAdd = sal_True;
3500 				else
3501 					switch ( pCell->GetCellType() )
3502 					{
3503 						case CELLTYPE_STRING:
3504 							if ( nContentFlags & sheet::CellFlags::STRING )
3505 								bAdd = sal_True;
3506 							break;
3507 						case CELLTYPE_EDIT:
3508                             if ( (nContentFlags & sheet::CellFlags::STRING) || (nContentFlags & sheet::CellFlags::FORMATTED) )
3509 								bAdd = sal_True;
3510 							break;
3511 						case CELLTYPE_FORMULA:
3512 							if ( nContentFlags & sheet::CellFlags::FORMULA )
3513 								bAdd = sal_True;
3514 							break;
3515 						case CELLTYPE_VALUE:
3516 							if ( (nContentFlags & (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME))
3517 									== (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME) )
3518 								bAdd = sal_True;
3519 							else
3520 							{
3521 								//	Date/Time Erkennung
3522 
3523 								sal_uLong nIndex = (sal_uLong)((SfxUInt32Item*)pDoc->GetAttr(
3524 										aIter.GetCol(), aIter.GetRow(), aIter.GetTab(),
3525 										ATTR_VALUE_FORMAT ))->GetValue();
3526 								short nTyp = pDoc->GetFormatTable()->GetType(nIndex);
3527 								if ((nTyp == NUMBERFORMAT_DATE) || (nTyp == NUMBERFORMAT_TIME) ||
3528 									(nTyp == NUMBERFORMAT_DATETIME))
3529 								{
3530 									if ( nContentFlags & sheet::CellFlags::DATETIME )
3531 										bAdd = sal_True;
3532 								}
3533 								else
3534 								{
3535 									if ( nContentFlags & sheet::CellFlags::VALUE )
3536 										bAdd = sal_True;
3537 								}
3538 							}
3539 							break;
3540                         default:
3541                         {
3542                             // added to avoid warnings
3543                         }
3544 					}
3545 
3546 				if (bAdd)
3547 					aMarkData.SetMultiMarkArea(
3548 							ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ),
3549 							sal_True );
3550 
3551 				pCell = aIter.GetNext();
3552 			}
3553 		}
3554 
3555 		ScRangeList aNewRanges;
3556 		if (aMarkData.IsMultiMarked())
3557 			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
3558 
3559 		return new ScCellRangesObj( pDocShell, aNewRanges );	// aNewRanges kann leer sein
3560 	}
3561 
3562 	return NULL;
3563 }
3564 
queryFormulaCells(sal_Int32 nResultFlags)3565 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryFormulaCells(
3566 													sal_Int32 nResultFlags )
3567 									throw(uno::RuntimeException)
3568 {
3569 	ScUnoGuard aGuard;
3570 	if (pDocShell)
3571 	{
3572 		ScDocument* pDoc = pDocShell->GetDocument();
3573 
3574 		ScMarkData aMarkData;
3575 
3576 		//	passende Zellen selektieren
3577 		sal_uLong nCount = aRanges.Count();
3578 		for (sal_uLong i=0; i<nCount; i++)
3579 		{
3580 			ScRange aRange = *aRanges.GetObject(i);
3581 
3582 			ScCellIterator aIter( pDoc, aRange );
3583 			ScBaseCell* pCell = aIter.GetFirst();
3584 			while (pCell)
3585 			{
3586 				if (pCell->GetCellType() == CELLTYPE_FORMULA)
3587 				{
3588 					ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
3589 					sal_Bool bAdd = sal_False;
3590 					if (pFCell->GetErrCode())
3591 					{
3592 						if ( nResultFlags & sheet::FormulaResult::ERROR )
3593 							bAdd = sal_True;
3594 					}
3595 					else if (pFCell->IsValue())
3596 					{
3597 						if ( nResultFlags & sheet::FormulaResult::VALUE )
3598 							bAdd = sal_True;
3599 					}
3600 					else	// String
3601 					{
3602 						if ( nResultFlags & sheet::FormulaResult::STRING )
3603 							bAdd = sal_True;
3604 					}
3605 
3606 					if (bAdd)
3607 						aMarkData.SetMultiMarkArea(
3608 								ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ),
3609 								sal_True );
3610 				}
3611 
3612 				pCell = aIter.GetNext();
3613 			}
3614 		}
3615 
3616 		ScRangeList aNewRanges;
3617 		if (aMarkData.IsMultiMarked())
3618 			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
3619 
3620 		return new ScCellRangesObj( pDocShell, aNewRanges );	// aNewRanges kann leer sein
3621 	}
3622 
3623 	return NULL;
3624 }
3625 
QueryDifferences_Impl(const table::CellAddress & aCompare,sal_Bool bColumnDiff)3626 uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl(
3627 						const table::CellAddress& aCompare, sal_Bool bColumnDiff)
3628 {
3629 	if (pDocShell)
3630 	{
3631 		sal_uLong nRangeCount = aRanges.Count();
3632 		sal_uLong i;
3633 		ScDocument* pDoc = pDocShell->GetDocument();
3634 		ScMarkData aMarkData;
3635 
3636 		SCCOLROW nCmpPos = bColumnDiff ? (SCCOLROW)aCompare.Row : (SCCOLROW)aCompare.Column;
3637 
3638 		//	zuerst alles selektieren, wo ueberhaupt etwas in der Vergleichsspalte steht
3639 		//	(fuer gleiche Zellen wird die Selektion im zweiten Schritt aufgehoben)
3640 
3641 		SCTAB nTab = lcl_FirstTab(aRanges);	//!	fuer alle Tabellen, wenn Markierungen pro Tabelle!
3642 		ScRange aCmpRange, aCellRange;
3643 		if (bColumnDiff)
3644 			aCmpRange = ScRange( 0,nCmpPos,nTab, MAXCOL,nCmpPos,nTab );
3645 		else
3646 			aCmpRange = ScRange( static_cast<SCCOL>(nCmpPos),0,nTab, static_cast<SCCOL>(nCmpPos),MAXROW,nTab );
3647 		ScCellIterator aCmpIter( pDoc, aCmpRange );
3648 		ScBaseCell* pCmpCell = aCmpIter.GetFirst();
3649 		while (pCmpCell)
3650 		{
3651 			if (pCmpCell->GetCellType() != CELLTYPE_NOTE)
3652 			{
3653 				SCCOLROW nCellPos = bColumnDiff ? static_cast<SCCOLROW>(aCmpIter.GetCol()) : static_cast<SCCOLROW>(aCmpIter.GetRow());
3654 				if (bColumnDiff)
3655                     aCellRange = ScRange( static_cast<SCCOL>(nCellPos),0,nTab,
3656                             static_cast<SCCOL>(nCellPos),MAXROW,nTab );
3657 				else
3658 					aCellRange = ScRange( 0,nCellPos,nTab, MAXCOL,nCellPos,nTab );
3659 
3660 				for (i=0; i<nRangeCount; i++)
3661 				{
3662 					ScRange aRange(*aRanges.GetObject(i));
3663 					if ( aRange.Intersects( aCellRange ) )
3664 					{
3665 						if (bColumnDiff)
3666 						{
3667 							aRange.aStart.SetCol(static_cast<SCCOL>(nCellPos));
3668 							aRange.aEnd.SetCol(static_cast<SCCOL>(nCellPos));
3669 						}
3670 						else
3671 						{
3672 							aRange.aStart.SetRow(nCellPos);
3673 							aRange.aEnd.SetRow(nCellPos);
3674 						}
3675 						aMarkData.SetMultiMarkArea( aRange );
3676 					}
3677 				}
3678 			}
3679 			pCmpCell = aCmpIter.GetNext();
3680 		}
3681 
3682 		//	alle nichtleeren Zellen mit der Vergleichsspalte vergleichen und entsprechend
3683 		//	selektieren oder aufheben
3684 
3685 		ScAddress aCmpAddr;
3686 		for (i=0; i<nRangeCount; i++)
3687 		{
3688 			ScRange aRange(*aRanges.GetObject(i));
3689 
3690 			ScCellIterator aIter( pDoc, aRange );
3691 			ScBaseCell* pCell = aIter.GetFirst();
3692 			while (pCell)
3693 			{
3694 				if (bColumnDiff)
3695 					aCmpAddr = ScAddress( aIter.GetCol(), nCmpPos, aIter.GetTab() );
3696 				else
3697 					aCmpAddr = ScAddress( static_cast<SCCOL>(nCmpPos), aIter.GetRow(), aIter.GetTab() );
3698                 const ScBaseCell* pOtherCell = pDoc->GetCell( aCmpAddr );
3699 
3700                 ScRange aOneRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() );
3701                 if ( !ScBaseCell::CellEqual( pCell, pOtherCell ) )
3702                     aMarkData.SetMultiMarkArea( aOneRange );
3703 				else
3704                     aMarkData.SetMultiMarkArea( aOneRange, sal_False );     // deselect
3705 
3706 				pCell = aIter.GetNext();
3707 			}
3708 		}
3709 
3710 		ScRangeList aNewRanges;
3711 		if (aMarkData.IsMultiMarked())
3712 			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_False );
3713 
3714 		return new ScCellRangesObj( pDocShell, aNewRanges );	// aNewRanges kann leer sein
3715 	}
3716 	return NULL;
3717 }
3718 
queryColumnDifferences(const table::CellAddress & aCompare)3719 uno::Reference<sheet::XSheetCellRanges > SAL_CALL ScCellRangesBase::queryColumnDifferences(
3720 							const table::CellAddress& aCompare ) throw(uno::RuntimeException)
3721 {
3722 	ScUnoGuard aGuard;
3723 	return QueryDifferences_Impl( aCompare, sal_True );
3724 }
3725 
queryRowDifferences(const table::CellAddress & aCompare)3726 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryRowDifferences(
3727 							const table::CellAddress& aCompare ) throw(uno::RuntimeException)
3728 {
3729 	ScUnoGuard aGuard;
3730 	return QueryDifferences_Impl( aCompare, sal_False );
3731 }
3732 
queryIntersection(const table::CellRangeAddress & aRange)3733 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryIntersection(
3734 							const table::CellRangeAddress& aRange ) throw(uno::RuntimeException)
3735 {
3736 	ScUnoGuard aGuard;
3737 	ScRange aMask( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
3738 				   (SCCOL)aRange.EndColumn,   (SCROW)aRange.EndRow,   aRange.Sheet );
3739 
3740 	ScRangeList aNew;
3741 	sal_uLong nCount = aRanges.Count();
3742 	for (sal_uLong i=0; i<nCount; i++)
3743 	{
3744 		ScRange aTemp(*aRanges.GetObject(i));
3745 		if ( aTemp.Intersects( aMask ) )
3746 			aNew.Join( ScRange( Max( aTemp.aStart.Col(), aMask.aStart.Col() ),
3747 								Max( aTemp.aStart.Row(), aMask.aStart.Row() ),
3748 								Max( aTemp.aStart.Tab(), aMask.aStart.Tab() ),
3749 								Min( aTemp.aEnd.Col(), aMask.aEnd.Col() ),
3750 								Min( aTemp.aEnd.Row(), aMask.aEnd.Row() ),
3751 								Min( aTemp.aEnd.Tab(), aMask.aEnd.Tab() ) ) );
3752 	}
3753 
3754 	return new ScCellRangesObj( pDocShell, aNew );	// kann leer sein
3755 }
3756 
3757 // XFormulaQuery
3758 
queryPrecedents(sal_Bool bRecursive)3759 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryPrecedents(
3760 								sal_Bool bRecursive ) throw(uno::RuntimeException)
3761 {
3762 	ScUnoGuard aGuard;
3763 	if ( pDocShell )
3764 	{
3765 		ScDocument* pDoc = pDocShell->GetDocument();
3766 
3767 		ScRangeList aNewRanges(aRanges);
3768 		sal_Bool bFound;
3769 		do
3770 		{
3771 			bFound = sal_False;
3772 
3773 			//	#97205# aMarkData uses aNewRanges, not aRanges, so GetMarkData can't be used
3774 			ScMarkData aMarkData;
3775 			aMarkData.MarkFromRangeList( aNewRanges, sal_False );
3776 			aMarkData.MarkToMulti();		// needed for IsAllMarked
3777 
3778 			sal_uLong nCount = aNewRanges.Count();
3779 			for (sal_uLong nR=0; nR<nCount; nR++)
3780 			{
3781 				ScRange aRange(*aNewRanges.GetObject(nR));
3782 				ScCellIterator aIter( pDoc, aRange );
3783 				ScBaseCell* pCell = aIter.GetFirst();
3784 				while (pCell)
3785 				{
3786 					if ( pCell->GetCellType() == CELLTYPE_FORMULA )
3787 					{
3788 						ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
3789 
3790                         ScDetectiveRefIter aRefIter( pFCell );
3791                         ScRange aRefRange;
3792                         while ( aRefIter.GetNextRef( aRefRange) )
3793 						{
3794 							if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) )
3795 								bFound = sal_True;
3796 							aMarkData.SetMultiMarkArea( aRefRange, sal_True );
3797 						}
3798 					}
3799 					pCell = aIter.GetNext();
3800 				}
3801 			}
3802 
3803 			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_True );
3804 		}
3805 		while ( bRecursive && bFound );
3806 
3807 		return new ScCellRangesObj( pDocShell, aNewRanges );
3808 	}
3809 
3810 	return NULL;
3811 }
3812 
queryDependents(sal_Bool bRecursive)3813 uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryDependents(
3814 								sal_Bool bRecursive ) throw(uno::RuntimeException)
3815 {
3816 	ScUnoGuard aGuard;
3817 	if ( pDocShell )
3818 	{
3819 		ScDocument* pDoc = pDocShell->GetDocument();
3820 
3821 		ScRangeList aNewRanges(aRanges);
3822 		sal_Bool bFound;
3823 		do
3824 		{
3825 			bFound = sal_False;
3826 			sal_uLong nRangesCount = aNewRanges.Count();
3827 
3828 			//	#97205# aMarkData uses aNewRanges, not aRanges, so GetMarkData can't be used
3829 			ScMarkData aMarkData;
3830 			aMarkData.MarkFromRangeList( aNewRanges, sal_False );
3831 			aMarkData.MarkToMulti();		// needed for IsAllMarked
3832 
3833 			SCTAB nTab = lcl_FirstTab(aNewRanges); 				//! alle Tabellen
3834 
3835 			ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab );
3836 			ScBaseCell* pCell = aCellIter.GetFirst();
3837 			while (pCell)
3838 			{
3839 				if (pCell->GetCellType() == CELLTYPE_FORMULA)
3840 				{
3841 					sal_Bool bMark = sal_False;
3842 					ScDetectiveRefIter aIter( (ScFormulaCell*) pCell );
3843                     ScRange aRefRange;
3844 					while ( aIter.GetNextRef( aRefRange) )
3845 					{
3846 						for (sal_uLong nR=0; nR<nRangesCount; nR++)
3847 						{
3848 							ScRange aRange(*aNewRanges.GetObject(nR));
3849 							if (aRange.Intersects(aRefRange))
3850 								bMark = sal_True;					// von Teil des Ranges abhaengig
3851 						}
3852 					}
3853 					if (bMark)
3854 					{
3855 						ScRange aCellRange( aCellIter.GetCol(),
3856 											aCellIter.GetRow(),
3857 											aCellIter.GetTab() );
3858 						if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) )
3859 							bFound = sal_True;
3860 						aMarkData.SetMultiMarkArea( aCellRange, sal_True );
3861 					}
3862 				}
3863 				pCell = aCellIter.GetNext();
3864 			}
3865 
3866 			aMarkData.FillRangeListWithMarks( &aNewRanges, sal_True );
3867 		}
3868 		while ( bRecursive && bFound );
3869 
3870 		return new ScCellRangesObj( pDocShell, aNewRanges );
3871 	}
3872 
3873 	return NULL;
3874 }
3875 
3876 // XSearchable
3877 
createSearchDescriptor()3878 uno::Reference<util::XSearchDescriptor> SAL_CALL ScCellRangesBase::createSearchDescriptor()
3879 															throw(uno::RuntimeException)
3880 {
3881 	ScUnoGuard aGuard;
3882 	return new ScCellSearchObj;
3883 }
3884 
findAll(const uno::Reference<util::XSearchDescriptor> & xDesc)3885 uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangesBase::findAll(
3886 						const uno::Reference<util::XSearchDescriptor>& xDesc )
3887 													throw(uno::RuntimeException)
3888 {
3889 	//	Wenn nichts gefunden wird, soll Null zurueckgegeben werden (?)
3890 	uno::Reference<container::XIndexAccess> xRet;
3891 	if ( pDocShell && xDesc.is() )
3892 	{
3893 		ScCellSearchObj* pSearch = ScCellSearchObj::getImplementation( xDesc );
3894 		if (pSearch)
3895 		{
3896 			SvxSearchItem* pSearchItem = pSearch->GetSearchItem();
3897 			if (pSearchItem)
3898 			{
3899 				ScDocument* pDoc = pDocShell->GetDocument();
3900 				pSearchItem->SetCommand( SVX_SEARCHCMD_FIND_ALL );
3901 				//	immer nur innerhalb dieses Objekts
3902 				pSearchItem->SetSelection( !lcl_WholeSheet(aRanges) );
3903 
3904 				ScMarkData aMark(*GetMarkData());
3905 
3906 				String aDummyUndo;
3907                 SCCOL nCol = 0;
3908                 SCROW nRow = 0;
3909                 SCTAB nTab = 0;
3910                 sal_Bool bFound = pDoc->SearchAndReplace( *pSearchItem, nCol, nRow, nTab,
3911 														aMark, aDummyUndo, NULL );
3912 				if (bFound)
3913 				{
3914 					ScRangeList aNewRanges;
3915 					aMark.FillRangeListWithMarks( &aNewRanges, sal_True );
3916 					//	bei findAll immer CellRanges, egal wieviel gefunden wurde
3917 					xRet.set(new ScCellRangesObj( pDocShell, aNewRanges ));
3918 				}
3919 			}
3920 		}
3921 	}
3922 	return xRet;
3923 }
3924 
Find_Impl(const uno::Reference<util::XSearchDescriptor> & xDesc,const ScAddress * pLastPos)3925 uno::Reference<uno::XInterface> ScCellRangesBase::Find_Impl(
3926 									const uno::Reference<util::XSearchDescriptor>& xDesc,
3927 									const ScAddress* pLastPos )
3928 {
3929 	uno::Reference<uno::XInterface> xRet;
3930 	if ( pDocShell && xDesc.is() )
3931 	{
3932 		ScCellSearchObj* pSearch = ScCellSearchObj::getImplementation( xDesc );
3933 		if (pSearch)
3934 		{
3935 			SvxSearchItem* pSearchItem = pSearch->GetSearchItem();
3936 			if (pSearchItem)
3937 			{
3938 				ScDocument* pDoc = pDocShell->GetDocument();
3939 				pSearchItem->SetCommand( SVX_SEARCHCMD_FIND );
3940 				//	immer nur innerhalb dieses Objekts
3941 				pSearchItem->SetSelection( !lcl_WholeSheet(aRanges) );
3942 
3943 				ScMarkData aMark(*GetMarkData());
3944 
3945                 SCCOL nCol;
3946                 SCROW nRow;
3947                 SCTAB nTab;
3948                 if (pLastPos)
3949 					pLastPos->GetVars( nCol, nRow, nTab );
3950 				else
3951 				{
3952 					nTab = lcl_FirstTab(aRanges);	//! mehrere Tabellen?
3953 					ScDocument::GetSearchAndReplaceStart( *pSearchItem, nCol, nRow );
3954 				}
3955 
3956 				String aDummyUndo;
3957 				sal_Bool bFound = pDoc->SearchAndReplace( *pSearchItem, nCol, nRow, nTab,
3958 														aMark, aDummyUndo, NULL );
3959 				if (bFound)
3960 				{
3961 					ScAddress aFoundPos( nCol, nRow, nTab );
3962 					xRet.set((cppu::OWeakObject*) new ScCellObj( pDocShell, aFoundPos ));
3963 				}
3964 			}
3965 		}
3966 	}
3967 	return xRet;
3968 }
3969 
findFirst(const uno::Reference<util::XSearchDescriptor> & xDesc)3970 uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findFirst(
3971 						const uno::Reference<util::XSearchDescriptor>& xDesc )
3972 												throw(uno::RuntimeException)
3973 {
3974 	ScUnoGuard aGuard;
3975 	return Find_Impl( xDesc, NULL );
3976 }
3977 
findNext(const uno::Reference<uno::XInterface> & xStartAt,const uno::Reference<util::XSearchDescriptor> & xDesc)3978 uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findNext(
3979 						const uno::Reference<uno::XInterface>& xStartAt,
3980 						const uno::Reference<util::XSearchDescriptor >& xDesc )
3981 												throw(uno::RuntimeException)
3982 {
3983 	ScUnoGuard aGuard;
3984 	if ( xStartAt.is() )
3985 	{
3986 		ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xStartAt );
3987 		if ( pRangesImp && pRangesImp->GetDocShell() == pDocShell )
3988 		{
3989 			const ScRangeList& rStartRanges = pRangesImp->GetRangeList();
3990 			if ( rStartRanges.Count() == 1 )
3991 			{
3992 				ScAddress aStartPos = rStartRanges.GetObject(0)->aStart;
3993 				return Find_Impl( xDesc, &aStartPos );
3994 			}
3995 		}
3996 	}
3997 	return NULL;
3998 }
3999 
4000 // XReplaceable
4001 
createReplaceDescriptor()4002 uno::Reference<util::XReplaceDescriptor> SAL_CALL ScCellRangesBase::createReplaceDescriptor()
4003 												throw(uno::RuntimeException)
4004 {
4005 	ScUnoGuard aGuard;
4006 	return new ScCellSearchObj;
4007 }
4008 
replaceAll(const uno::Reference<util::XSearchDescriptor> & xDesc)4009 sal_Int32 SAL_CALL ScCellRangesBase::replaceAll( const uno::Reference<util::XSearchDescriptor>& xDesc )
4010 												throw(uno::RuntimeException)
4011 {
4012 	ScUnoGuard aGuard;
4013 	sal_Int32 nReplaced = 0;
4014 	if ( pDocShell && xDesc.is() )
4015 	{
4016 		ScCellSearchObj* pSearch = ScCellSearchObj::getImplementation( xDesc );
4017 		if (pSearch)
4018 		{
4019 			SvxSearchItem* pSearchItem = pSearch->GetSearchItem();
4020 			if (pSearchItem)
4021 			{
4022 				ScDocument* pDoc = pDocShell->GetDocument();
4023 				sal_Bool bUndo(pDoc->IsUndoEnabled());
4024 				pSearchItem->SetCommand( SVX_SEARCHCMD_REPLACE_ALL );
4025 				//	immer nur innerhalb dieses Objekts
4026 				pSearchItem->SetSelection( !lcl_WholeSheet(aRanges) );
4027 
4028 				ScMarkData aMark(*GetMarkData());
4029 
4030 				SCTAB nTabCount = pDoc->GetTableCount();
4031 				sal_Bool bProtected = !pDocShell->IsEditable();
4032 				for (SCTAB i=0; i<nTabCount; i++)
4033 					if ( aMark.GetTableSelect(i) && pDoc->IsTabProtected(i) )
4034 						bProtected = sal_True;
4035 				if (bProtected)
4036 				{
4037 					//!	Exception, oder was?
4038 				}
4039 				else
4040 				{
4041 					SCTAB nTab = aMark.GetFirstSelected();		// bei SearchAndReplace nicht benutzt
4042                     SCCOL nCol = 0;
4043                     SCROW nRow = 0;
4044 
4045 					String aUndoStr;
4046 					ScDocument* pUndoDoc = NULL;
4047 					if (bUndo)
4048 					{
4049 						pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
4050 						pUndoDoc->InitUndo( pDoc, nTab, nTab );
4051 					}
4052 					for (SCTAB i=0; i<nTabCount; i++)
4053 						if ( aMark.GetTableSelect(i) && i != nTab && bUndo)
4054 							pUndoDoc->AddUndoTab( i, i );
4055 					ScMarkData* pUndoMark = NULL;
4056 					if (bUndo)
4057 						pUndoMark = new ScMarkData(aMark);
4058 
4059 					sal_Bool bFound(sal_False);
4060 					if (bUndo)
4061 						bFound = pDoc->SearchAndReplace( *pSearchItem, nCol, nRow, nTab,
4062 															aMark, aUndoStr, pUndoDoc );
4063 					if (bFound)
4064 					{
4065 						nReplaced = pUndoDoc->GetCellCount();
4066 
4067 						pDocShell->GetUndoManager()->AddUndoAction(
4068 							new ScUndoReplace( pDocShell, *pUndoMark, nCol, nRow, nTab,
4069 														aUndoStr, pUndoDoc, pSearchItem ) );
4070 
4071 						pDocShell->PostPaintGridAll();
4072 						pDocShell->SetDocumentModified();
4073 					}
4074 					else
4075 					{
4076 						delete pUndoDoc;
4077 						delete pUndoMark;
4078 						// nReplaced bleibt 0
4079 					}
4080 				}
4081 			}
4082 		}
4083 	}
4084 	return nReplaced;
4085 }
4086 
4087 // XUnoTunnel
4088 
getSomething(const uno::Sequence<sal_Int8> & rId)4089 sal_Int64 SAL_CALL ScCellRangesBase::getSomething(
4090 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
4091 {
4092 	if ( rId.getLength() == 16 &&
4093           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
4094 									rId.getConstArray(), 16 ) )
4095 	{
4096         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
4097 	}
4098 	return 0;
4099 }
4100 
4101 // static
getUnoTunnelId()4102 const uno::Sequence<sal_Int8>& ScCellRangesBase::getUnoTunnelId()
4103 {
4104 	static uno::Sequence<sal_Int8> * pSeq = 0;
4105 	if( !pSeq )
4106 	{
4107 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
4108 		if( !pSeq )
4109 		{
4110 			static uno::Sequence< sal_Int8 > aSeq( 16 );
4111 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
4112 			pSeq = &aSeq;
4113 		}
4114 	}
4115 	return *pSeq;
4116 }
4117 
4118 // static
getImplementation(const uno::Reference<uno::XInterface> xObj)4119 ScCellRangesBase* ScCellRangesBase::getImplementation( const uno::Reference<uno::XInterface> xObj )
4120 {
4121 	ScCellRangesBase* pRet = NULL;
4122 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
4123 	if (xUT.is())
4124         pRet = reinterpret_cast<ScCellRangesBase*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
4125 	return pRet;
4126 }
4127 
4128 //------------------------------------------------------------------------
4129 
ScCellRangesObj(ScDocShell * pDocSh,const ScRangeList & rR)4130 ScCellRangesObj::ScCellRangesObj(ScDocShell* pDocSh, const ScRangeList& rR) :
4131 	ScCellRangesBase( pDocSh, rR )
4132 {
4133 }
4134 
~ScCellRangesObj()4135 ScCellRangesObj::~ScCellRangesObj()
4136 {
4137 }
4138 
RefChanged()4139 void ScCellRangesObj::RefChanged()
4140 {
4141 	ScCellRangesBase::RefChanged();
4142 
4143 	//	nix weiter...
4144 }
4145 
queryInterface(const uno::Type & rType)4146 uno::Any SAL_CALL ScCellRangesObj::queryInterface( const uno::Type& rType )
4147 												throw(uno::RuntimeException)
4148 {
4149 	SC_QUERYINTERFACE( sheet::XSheetCellRangeContainer )
4150 	SC_QUERYINTERFACE( sheet::XSheetCellRanges )
4151 	SC_QUERYINTERFACE( container::XIndexAccess )
4152 	SC_QUERY_MULTIPLE( container::XElementAccess, container::XIndexAccess )
4153 	SC_QUERYINTERFACE( container::XEnumerationAccess )
4154 	SC_QUERYINTERFACE( container::XNameContainer )
4155 	SC_QUERYINTERFACE( container::XNameReplace )
4156 	SC_QUERYINTERFACE( container::XNameAccess )
4157 
4158 	return ScCellRangesBase::queryInterface( rType );
4159 }
4160 
acquire()4161 void SAL_CALL ScCellRangesObj::acquire() throw()
4162 {
4163 	ScCellRangesBase::acquire();
4164 }
4165 
release()4166 void SAL_CALL ScCellRangesObj::release() throw()
4167 {
4168 	ScCellRangesBase::release();
4169 }
4170 
getTypes()4171 uno::Sequence<uno::Type> SAL_CALL ScCellRangesObj::getTypes() throw(uno::RuntimeException)
4172 {
4173 	static uno::Sequence<uno::Type> aTypes;
4174 	if ( aTypes.getLength() == 0 )
4175 	{
4176 		uno::Sequence<uno::Type> aParentTypes(ScCellRangesBase::getTypes());
4177 		long nParentLen = aParentTypes.getLength();
4178 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
4179 
4180 		aTypes.realloc( nParentLen + 3 );
4181 		uno::Type* pPtr = aTypes.getArray();
4182 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSheetCellRangeContainer>*)0);
4183 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XNameContainer>*)0);
4184 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0);
4185 
4186 		for (long i=0; i<nParentLen; i++)
4187 			pPtr[i] = pParentPtr[i];				// parent types first
4188 	}
4189 	return aTypes;
4190 }
4191 
getImplementationId()4192 uno::Sequence<sal_Int8> SAL_CALL ScCellRangesObj::getImplementationId()
4193 													throw(uno::RuntimeException)
4194 {
4195 	static uno::Sequence< sal_Int8 > aId;
4196 	if( aId.getLength() == 0 )
4197 	{
4198 		aId.realloc( 16 );
4199 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
4200 	}
4201 	return aId;
4202 }
4203 
4204 // XCellRanges
4205 
GetObjectByIndex_Impl(sal_Int32 nIndex) const4206 ScCellRangeObj* ScCellRangesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
4207 {
4208 	ScDocShell* pDocSh = GetDocShell();
4209 	const ScRangeList& rRanges = GetRangeList();
4210     if ( pDocSh && nIndex >= 0 && nIndex < sal::static_int_cast<sal_Int32>(rRanges.Count()) )
4211 	{
4212 		ScRange aRange(*rRanges.GetObject(nIndex));
4213 		if ( aRange.aStart == aRange.aEnd )
4214 			return new ScCellObj( pDocSh, aRange.aStart );
4215 		else
4216 			return new ScCellRangeObj( pDocSh, aRange );
4217 	}
4218 
4219 	return NULL;		// keine DocShell oder falscher Index
4220 }
4221 
getRangeAddresses()4222 uno::Sequence<table::CellRangeAddress> SAL_CALL ScCellRangesObj::getRangeAddresses()
4223 													throw(uno::RuntimeException)
4224 {
4225 	ScUnoGuard aGuard;
4226 	ScDocShell* pDocSh = GetDocShell();
4227 	const ScRangeList& rRanges = GetRangeList();
4228 	sal_uLong nCount = rRanges.Count();
4229 	if ( pDocSh && nCount )
4230 	{
4231 		table::CellRangeAddress aRangeAddress;
4232 		uno::Sequence<table::CellRangeAddress> aSeq(nCount);
4233 		table::CellRangeAddress* pAry = aSeq.getArray();
4234         for (sal_uInt32 i=0; i<nCount; i++)
4235 		{
4236 			ScUnoConversion::FillApiRange( aRangeAddress, *rRanges.GetObject(i) );
4237 			pAry[i] = aRangeAddress;
4238 		}
4239 		return aSeq;
4240 	}
4241 
4242 	return uno::Sequence<table::CellRangeAddress>(0);	// leer ist moeglich
4243 }
4244 
getCells()4245 uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellRangesObj::getCells()
4246 													throw(uno::RuntimeException)
4247 {
4248 	ScUnoGuard aGuard;
4249 
4250 	//	getCells with empty range list is possible (no exception),
4251 	//	the resulting enumeration just has no elements
4252 	//	(same behaviour as a valid range with no cells)
4253 	//	This is handled in ScCellsEnumeration ctor.
4254 
4255 	const ScRangeList& rRanges = GetRangeList();
4256 	ScDocShell* pDocSh = GetDocShell();
4257 	if (pDocSh)
4258 		return new ScCellsObj( pDocSh, rRanges );
4259 	return NULL;
4260 }
4261 
getRangeAddressesAsString()4262 rtl::OUString SAL_CALL ScCellRangesObj::getRangeAddressesAsString()
4263 												throw(uno::RuntimeException)
4264 {
4265 	ScUnoGuard aGuard;
4266 	String aString;
4267 	ScDocShell* pDocSh = GetDocShell();
4268 	const ScRangeList& rRanges = GetRangeList();
4269 	if (pDocSh)
4270 		rRanges.Format( aString, SCA_VALID | SCA_TAB_3D, pDocSh->GetDocument() );
4271 	return aString;
4272 }
4273 
4274 // XSheetCellRangeContainer
4275 
addRangeAddress(const table::CellRangeAddress & rRange,sal_Bool bMergeRanges)4276 void SAL_CALL ScCellRangesObj::addRangeAddress( const table::CellRangeAddress& rRange,
4277 									sal_Bool bMergeRanges )
4278 									throw(::com::sun::star::uno::RuntimeException)
4279 {
4280 	ScUnoGuard aGuard;
4281 	ScRange aRange(static_cast<SCCOL>(rRange.StartColumn),
4282 			static_cast<SCROW>(rRange.StartRow),
4283 			static_cast<SCTAB>(rRange.Sheet),
4284 			static_cast<SCCOL>(rRange.EndColumn),
4285 			static_cast<SCROW>(rRange.EndRow),
4286 			static_cast<SCTAB>(rRange.Sheet));
4287 	AddRange(aRange, bMergeRanges);
4288 }
4289 
lcl_RemoveNamedEntry(ScNamedEntryArr_Impl & rNamedEntries,const ScRange & rRange)4290 void lcl_RemoveNamedEntry( ScNamedEntryArr_Impl& rNamedEntries, const ScRange& rRange )
4291 {
4292 	sal_uInt16 nCount = rNamedEntries.Count();
4293 	for ( sal_uInt16 n=nCount; n--; )
4294 		if ( rNamedEntries[n]->GetRange() == rRange )
4295 			rNamedEntries.DeleteAndDestroy( n );
4296 }
4297 
removeRangeAddress(const table::CellRangeAddress & rRange)4298 void SAL_CALL ScCellRangesObj::removeRangeAddress( const table::CellRangeAddress& rRange )
4299 								throw(::com::sun::star::container::NoSuchElementException,
4300 									::com::sun::star::uno::RuntimeException)
4301 {
4302 	ScUnoGuard aGuard;
4303 	const ScRangeList& rRanges = GetRangeList();
4304 
4305     ScRangeList aSheetRanges;
4306     ScRangeList aNotSheetRanges;
4307     for (sal_uInt32 i = 0; i < rRanges.Count(); ++i)
4308     {
4309         if (rRanges.GetObject(i)->aStart.Tab() == rRange.Sheet)
4310         {
4311             aSheetRanges.Append(*rRanges.GetObject(i));
4312         }
4313         else
4314         {
4315             aNotSheetRanges.Append(*rRanges.GetObject(i));
4316         }
4317     }
4318 	ScMarkData aMarkData;
4319 	aMarkData.MarkFromRangeList( aSheetRanges, sal_False );
4320 	ScRange aRange(static_cast<SCCOL>(rRange.StartColumn),
4321 				static_cast<SCROW>(rRange.StartRow),
4322 				static_cast<SCTAB>(rRange.Sheet),
4323 				static_cast<SCCOL>(rRange.EndColumn),
4324 				static_cast<SCROW>(rRange.EndRow),
4325 				static_cast<SCTAB>(rRange.Sheet));
4326 	if (aMarkData.GetTableSelect( aRange.aStart.Tab() ))
4327     {
4328         aMarkData.MarkToMulti();
4329 		if (aMarkData.IsAllMarked( aRange ) )
4330 		{
4331 			aMarkData.SetMultiMarkArea( aRange, sal_False );
4332 			lcl_RemoveNamedEntry(aNamedEntries, aRange);
4333 		}
4334 		else
4335 			throw container::NoSuchElementException();
4336     }
4337 	SetNewRanges(aNotSheetRanges);
4338 	ScRangeList aNew;
4339 	aMarkData.FillRangeListWithMarks( &aNew, sal_False );
4340     for (sal_uInt32 j = 0; j < aNew.Count(); ++j)
4341     {
4342         AddRange(*aNew.GetObject(j), sal_False);
4343     }
4344 }
4345 
addRangeAddresses(const uno::Sequence<table::CellRangeAddress> & rRanges,sal_Bool bMergeRanges)4346 void SAL_CALL ScCellRangesObj::addRangeAddresses( const uno::Sequence<table::CellRangeAddress >& rRanges,
4347 									sal_Bool bMergeRanges )
4348 									throw(::com::sun::star::uno::RuntimeException)
4349 {
4350 	ScUnoGuard aGuard;
4351 	sal_Int32 nCount(rRanges.getLength());
4352 	if (nCount)
4353 	{
4354 		const table::CellRangeAddress* pRanges = rRanges.getConstArray();
4355 		for (sal_Int32 i = 0; i < rRanges.getLength(); i++, pRanges++)
4356 		{
4357 			ScRange aRange(static_cast<SCCOL>(pRanges->StartColumn),
4358 					static_cast<SCROW>(pRanges->StartRow),
4359 					static_cast<SCTAB>(pRanges->Sheet),
4360 					static_cast<SCCOL>(pRanges->EndColumn),
4361 					static_cast<SCROW>(pRanges->EndRow),
4362 					static_cast<SCTAB>(pRanges->Sheet));
4363 			AddRange(aRange, bMergeRanges);
4364 		}
4365 	}
4366 }
4367 
removeRangeAddresses(const uno::Sequence<table::CellRangeAddress> & rRangeSeq)4368 void SAL_CALL ScCellRangesObj::removeRangeAddresses( const uno::Sequence<table::CellRangeAddress >& rRangeSeq )
4369 								throw(::com::sun::star::container::NoSuchElementException,
4370 									::com::sun::star::uno::RuntimeException)
4371 {
4372     // with this implementation not needed
4373 //	ScUnoGuard aGuard;
4374 
4375 
4376     // use sometimes a better/faster implementation
4377 	sal_uInt32 nCount(rRangeSeq.getLength());
4378 	if (nCount)
4379 	{
4380 		const table::CellRangeAddress* pRanges = rRangeSeq.getConstArray();
4381 		for (sal_uInt32 i=0; i < nCount; ++i, ++pRanges)
4382 		{
4383             removeRangeAddress(*pRanges);
4384 		}
4385 	}
4386 }
4387 
4388 // XNameContainer
4389 
lcl_RemoveNamedEntry(ScNamedEntryArr_Impl & rNamedEntries,const String & rName)4390 void lcl_RemoveNamedEntry( ScNamedEntryArr_Impl& rNamedEntries, const String& rName )
4391 {
4392 	sal_uInt16 nCount = rNamedEntries.Count();
4393 	for ( sal_uInt16 n=nCount; n--; )
4394 		if ( rNamedEntries[n]->GetName() == rName )
4395 			rNamedEntries.DeleteAndDestroy( n );
4396 }
4397 
insertByName(const rtl::OUString & aName,const uno::Any & aElement)4398 void SAL_CALL ScCellRangesObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
4399 							throw(lang::IllegalArgumentException, container::ElementExistException,
4400 									lang::WrappedTargetException, uno::RuntimeException)
4401 {
4402 	ScUnoGuard aGuard;
4403 	ScDocShell* pDocSh = GetDocShell();
4404 	sal_Bool bDone = sal_False;
4405 
4406 	//!	Type of aElement can be some specific interface instead of XInterface
4407 
4408     uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
4409 	if ( pDocSh && xInterface.is() )
4410 	{
4411 		ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xInterface );
4412 		if ( pRangesImp && pRangesImp->GetDocShell() == pDocSh )
4413 		{
4414 			//	if explicit name is given and already existing, throw exception
4415 
4416 			String aNamStr(aName);
4417 			if ( aNamStr.Len() )
4418 			{
4419 				sal_uInt16 nNamedCount = aNamedEntries.Count();
4420 				for (sal_uInt16 n=0; n<nNamedCount; n++)
4421 					if ( aNamedEntries[n]->GetName() == aNamStr )
4422 						throw container::ElementExistException();
4423 			}
4424 
4425 			ScRangeList aNew(GetRangeList());
4426 			const ScRangeList& rAddRanges = pRangesImp->GetRangeList();
4427 			sal_uLong nAddCount = rAddRanges.Count();
4428 			for (sal_uLong i=0; i<nAddCount; i++)
4429 				aNew.Join( *rAddRanges.GetObject(i) );
4430 			SetNewRanges(aNew);
4431 			bDone = sal_True;
4432 
4433 			if ( aName.getLength() && nAddCount == 1 )
4434 			{
4435 				//	if a name is given, also insert into list of named entries
4436 				//	(only possible for a single range)
4437 				//	name is not in aNamedEntries (tested above)
4438 
4439 				ScNamedEntry* pEntry = new ScNamedEntry( aNamStr, *rAddRanges.GetObject(0) );
4440 				aNamedEntries.Insert( pEntry, aNamedEntries.Count() );
4441 			}
4442 		}
4443 	}
4444 
4445 	if (!bDone)
4446 	{
4447 		//	invalid element - double names are handled above
4448 		throw lang::IllegalArgumentException();
4449 	}
4450 }
4451 
lcl_FindRangeByName(const ScRangeList & rRanges,ScDocShell * pDocSh,const String & rName,sal_uLong & rIndex)4452 sal_Bool lcl_FindRangeByName( const ScRangeList& rRanges, ScDocShell* pDocSh,
4453 							const String& rName, sal_uLong& rIndex )
4454 {
4455 	if (pDocSh)
4456 	{
4457 		String aRangeStr;
4458 		ScDocument* pDoc = pDocSh->GetDocument();
4459 		sal_uLong nCount = rRanges.Count();
4460 		for (sal_uLong i=0; i<nCount; i++)
4461 		{
4462 			rRanges.GetObject(i)->Format( aRangeStr, SCA_VALID | SCA_TAB_3D, pDoc );
4463 			if ( aRangeStr == rName )
4464 			{
4465 				rIndex = i;
4466 				return sal_True;
4467 			}
4468 		}
4469 	}
4470 	return sal_False;	// nicht gefunden
4471 }
4472 
lcl_FindRangeOrEntry(const ScNamedEntryArr_Impl & rNamedEntries,const ScRangeList & rRanges,ScDocShell * pDocSh,const String & rName,ScRange & rFound)4473 sal_Bool lcl_FindRangeOrEntry( const ScNamedEntryArr_Impl& rNamedEntries,
4474 							const ScRangeList& rRanges, ScDocShell* pDocSh,
4475 							const String& rName, ScRange& rFound )
4476 {
4477 	//	exact range in list?
4478 
4479 	sal_uLong nIndex = 0;
4480 	if ( lcl_FindRangeByName( rRanges, pDocSh, rName, nIndex ) )
4481 	{
4482 		rFound = *rRanges.GetObject(nIndex);
4483 		return sal_True;
4484 	}
4485 
4486 	//	range contained in selection? (sheet must be specified)
4487 
4488 	ScRange aCellRange;
4489 	sal_uInt16 nParse = aCellRange.ParseAny( rName, pDocSh->GetDocument() );
4490 	if ( ( nParse & ( SCA_VALID | SCA_TAB_3D ) ) == ( SCA_VALID | SCA_TAB_3D ) )
4491 	{
4492 		ScMarkData aMarkData;
4493 		aMarkData.MarkFromRangeList( rRanges, sal_False );
4494 		aMarkData.MarkToMulti();		// needed for IsAllMarked
4495 		if ( aMarkData.IsAllMarked( aCellRange ) )
4496 		{
4497 			rFound = aCellRange;
4498 			return sal_True;
4499 		}
4500 	}
4501 
4502 	//	named entry in this object?
4503 
4504 	if ( rNamedEntries.Count() )
4505 	{
4506 		for ( sal_uInt16 n=0; n<rNamedEntries.Count(); n++ )
4507 			if ( rNamedEntries[n]->GetName() == rName )
4508 			{
4509 				//	test if named entry is contained in rRanges
4510 
4511 				const ScRange& rComp = rNamedEntries[n]->GetRange();
4512 				ScMarkData aMarkData;
4513 				aMarkData.MarkFromRangeList( rRanges, sal_False );
4514 				aMarkData.MarkToMulti();		// needed for IsAllMarked
4515 				if ( aMarkData.IsAllMarked( rComp ) )
4516 				{
4517 					rFound = rComp;
4518 					return sal_True;
4519 				}
4520 			}
4521 	}
4522 
4523 	return sal_False;		// not found
4524 }
4525 
removeByName(const rtl::OUString & aName)4526 void SAL_CALL ScCellRangesObj::removeByName( const rtl::OUString& aName )
4527 								throw(container::NoSuchElementException,
4528 									lang::WrappedTargetException, uno::RuntimeException)
4529 {
4530 	ScUnoGuard aGuard;
4531 	sal_Bool bDone = sal_False;
4532 	String aNameStr(aName);
4533 	ScDocShell* pDocSh = GetDocShell();
4534 	const ScRangeList& rRanges = GetRangeList();
4535 	sal_uLong nIndex = 0;
4536 	if ( lcl_FindRangeByName( rRanges, pDocSh, aNameStr, nIndex ) )
4537 	{
4538 		//	einzelnen Range weglassen
4539 		ScRangeList aNew;
4540 		sal_uLong nCount = rRanges.Count();
4541 		for (sal_uLong i=0; i<nCount; i++)
4542 			if (i != nIndex)
4543 				aNew.Append( *rRanges.GetObject(i) );
4544 		SetNewRanges(aNew);
4545 		bDone = sal_True;
4546 	}
4547 	else if (pDocSh)
4548 	{
4549 		//	deselect any ranges (parsed or named entry)
4550 		ScRangeList aDiff;
4551 		sal_Bool bValid = ( aDiff.Parse( aNameStr, pDocSh->GetDocument() ) & SCA_VALID ) != 0;
4552 		if ( !bValid && aNamedEntries.Count() )
4553 		{
4554 			sal_uInt16 nCount = aNamedEntries.Count();
4555 			for (sal_uInt16 n=0; n<nCount && !bValid; n++)
4556 				if (aNamedEntries[n]->GetName() == aNameStr)
4557 				{
4558 					aDiff.RemoveAll();
4559 					aDiff.Append( aNamedEntries[n]->GetRange() );
4560 					bValid = sal_True;
4561 				}
4562 		}
4563 		if ( bValid )
4564 		{
4565 			ScMarkData aMarkData;
4566 			aMarkData.MarkFromRangeList( rRanges, sal_False );
4567 
4568 			sal_uLong nDiffCount = aDiff.Count();
4569 			for (sal_uLong i=0; i<nDiffCount; i++)
4570 			{
4571 				ScRange* pDiffRange = aDiff.GetObject(i);
4572 				if (aMarkData.GetTableSelect( pDiffRange->aStart.Tab() ))
4573 					aMarkData.SetMultiMarkArea( *pDiffRange, sal_False );
4574 			}
4575 
4576 			ScRangeList aNew;
4577 			aMarkData.FillRangeListWithMarks( &aNew, sal_False );
4578 			SetNewRanges(aNew);
4579 
4580 			bDone = sal_True;		//! error if range was not selected before?
4581 		}
4582 	}
4583 
4584 	if (aNamedEntries.Count())
4585 		lcl_RemoveNamedEntry( aNamedEntries, aNameStr );	//	remove named entry
4586 
4587 	if (!bDone)
4588 		throw container::NoSuchElementException();		// not found
4589 }
4590 
4591 // XNameReplace
4592 
replaceByName(const rtl::OUString & aName,const uno::Any & aElement)4593 void SAL_CALL ScCellRangesObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
4594 							throw(lang::IllegalArgumentException, container::NoSuchElementException,
4595 									lang::WrappedTargetException, uno::RuntimeException)
4596 {
4597 	ScUnoGuard aGuard;
4598 	//!	zusammenfassen?
4599 	removeByName( aName );
4600 	insertByName( aName, aElement );
4601 }
4602 
4603 // XNameAccess
4604 
getByName(const rtl::OUString & aName)4605 uno::Any SAL_CALL ScCellRangesObj::getByName( const rtl::OUString& aName )
4606 			throw(container::NoSuchElementException,
4607 					lang::WrappedTargetException, uno::RuntimeException)
4608 {
4609 	ScUnoGuard aGuard;
4610 	uno::Any aRet;
4611 
4612 	String aNameStr(aName);
4613 	ScDocShell* pDocSh = GetDocShell();
4614 	const ScRangeList& rRanges = GetRangeList();
4615 	ScRange aRange;
4616 	if ( lcl_FindRangeOrEntry( aNamedEntries, rRanges, pDocSh, aNameStr, aRange ) )
4617 	{
4618 		uno::Reference<table::XCellRange> xRange;
4619 		if ( aRange.aStart == aRange.aEnd )
4620 			xRange.set(new ScCellObj( pDocSh, aRange.aStart ));
4621 		else
4622 			xRange.set(new ScCellRangeObj( pDocSh, aRange ));
4623 		aRet <<= xRange;
4624 	}
4625 	else
4626 		throw container::NoSuchElementException();
4627 	return aRet;
4628 }
4629 
lcl_FindEntryName(const ScNamedEntryArr_Impl & rNamedEntries,const ScRange & rRange,String & rName)4630 sal_Bool lcl_FindEntryName( const ScNamedEntryArr_Impl& rNamedEntries,
4631 						const ScRange& rRange, String& rName )
4632 {
4633 	sal_uInt16 nCount = rNamedEntries.Count();
4634 	for (sal_uInt16 i=0; i<nCount; i++)
4635 		if (rNamedEntries[i]->GetRange() == rRange)
4636 		{
4637 			rName = rNamedEntries[i]->GetName();
4638 			return sal_True;
4639 		}
4640 	return sal_False;
4641 }
4642 
getElementNames()4643 uno::Sequence<rtl::OUString> SAL_CALL ScCellRangesObj::getElementNames()
4644 												throw(uno::RuntimeException)
4645 {
4646 	ScUnoGuard aGuard;
4647 
4648 	ScDocShell* pDocSh = GetDocShell();
4649 	const ScRangeList& rRanges = GetRangeList();
4650 	if (pDocSh)
4651 	{
4652 		String aRangeStr;
4653 		ScDocument* pDoc = pDocSh->GetDocument();
4654 		sal_uLong nCount = rRanges.Count();
4655 
4656 		uno::Sequence<rtl::OUString> aSeq(nCount);
4657 		rtl::OUString* pAry = aSeq.getArray();
4658 		for (sal_uLong i=0; i<nCount; i++)
4659 		{
4660 			//	use given name if for exactly this range, otherwise just format
4661 			ScRange aRange = *rRanges.GetObject(i);
4662 			if ( !aNamedEntries.Count() || !lcl_FindEntryName( aNamedEntries, aRange, aRangeStr ) )
4663 				aRange.Format( aRangeStr, SCA_VALID | SCA_TAB_3D, pDoc );
4664 			pAry[i] = aRangeStr;
4665 		}
4666 		return aSeq;
4667 	}
4668 	return uno::Sequence<rtl::OUString>(0);
4669 }
4670 
hasByName(const rtl::OUString & aName)4671 sal_Bool SAL_CALL ScCellRangesObj::hasByName( const rtl::OUString& aName )
4672 										throw(uno::RuntimeException)
4673 {
4674 	ScUnoGuard aGuard;
4675 	String aNameStr(aName);
4676 	ScDocShell* pDocSh = GetDocShell();
4677 	const ScRangeList& rRanges = GetRangeList();
4678 	ScRange aRange;
4679 	return lcl_FindRangeOrEntry( aNamedEntries, rRanges, pDocSh, aNameStr, aRange );
4680 }
4681 
4682 // XEnumerationAccess
4683 
createEnumeration()4684 uno::Reference<container::XEnumeration> SAL_CALL ScCellRangesObj::createEnumeration()
4685 													throw(uno::RuntimeException)
4686 {
4687 	ScUnoGuard aGuard;
4688     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetCellRangesEnumeration")));
4689 }
4690 
4691 // XIndexAccess
4692 
getCount()4693 sal_Int32 SAL_CALL ScCellRangesObj::getCount() throw(uno::RuntimeException)
4694 {
4695 	ScUnoGuard aGuard;
4696 	const ScRangeList& rRanges = GetRangeList();
4697 	return rRanges.Count();
4698 }
4699 
getByIndex(sal_Int32 nIndex)4700 uno::Any SAL_CALL ScCellRangesObj::getByIndex( sal_Int32 nIndex )
4701 							throw(lang::IndexOutOfBoundsException,
4702 									lang::WrappedTargetException, uno::RuntimeException)
4703 {
4704 	ScUnoGuard aGuard;
4705     uno::Reference<table::XCellRange> xRange(GetObjectByIndex_Impl(nIndex));
4706 	if (xRange.is())
4707         return uno::makeAny(xRange);
4708 	else
4709 		throw lang::IndexOutOfBoundsException();
4710 //    return uno::Any();
4711 }
4712 
getElementType()4713 uno::Type SAL_CALL ScCellRangesObj::getElementType() throw(uno::RuntimeException)
4714 {
4715 	ScUnoGuard aGuard;
4716 	return getCppuType((uno::Reference<table::XCellRange>*)0);
4717 }
4718 
hasElements()4719 sal_Bool SAL_CALL ScCellRangesObj::hasElements() throw(uno::RuntimeException)
4720 {
4721 	ScUnoGuard aGuard;
4722 	const ScRangeList& rRanges = GetRangeList();
4723 	return rRanges.Count() != 0;
4724 }
4725 
4726 // XServiceInfo
4727 
getImplementationName()4728 rtl::OUString SAL_CALL ScCellRangesObj::getImplementationName() throw(uno::RuntimeException)
4729 {
4730 	return rtl::OUString::createFromAscii( "ScCellRangesObj" );
4731 }
4732 
supportsService(const rtl::OUString & rServiceName)4733 sal_Bool SAL_CALL ScCellRangesObj::supportsService( const rtl::OUString& rServiceName )
4734 													throw(uno::RuntimeException)
4735 {
4736 	String aServiceStr(rServiceName);
4737 	return aServiceStr.EqualsAscii( SCSHEETCELLRANGES_SERVICE ) ||
4738 		   aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) ||
4739 		   aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) ||
4740 		   aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE );
4741 }
4742 
getSupportedServiceNames()4743 uno::Sequence<rtl::OUString> SAL_CALL ScCellRangesObj::getSupportedServiceNames()
4744 													throw(uno::RuntimeException)
4745 {
4746 	uno::Sequence<rtl::OUString> aRet(4);
4747 	rtl::OUString* pArray = aRet.getArray();
4748 	pArray[0] = rtl::OUString::createFromAscii( SCSHEETCELLRANGES_SERVICE );
4749 	pArray[1] = rtl::OUString::createFromAscii( SCCELLPROPERTIES_SERVICE );
4750 	pArray[2] = rtl::OUString::createFromAscii( SCCHARPROPERTIES_SERVICE );
4751 	pArray[3] = rtl::OUString::createFromAscii( SCPARAPROPERTIES_SERVICE );
4752 	return aRet;
4753 }
4754 
4755 //------------------------------------------------------------------------
4756 
4757 // static
CreateRangeFromDoc(ScDocument * pDoc,const ScRange & rR)4758 uno::Reference<table::XCellRange> ScCellRangeObj::CreateRangeFromDoc( ScDocument* pDoc, const ScRange& rR )
4759 {
4760 	SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
4761 	if ( pObjSh && pObjSh->ISA(ScDocShell) )
4762 		return new ScCellRangeObj( (ScDocShell*) pObjSh, rR );
4763 	return NULL;
4764 }
4765 
4766 //------------------------------------------------------------------------
4767 
ScCellRangeObj(ScDocShell * pDocSh,const ScRange & rR)4768 ScCellRangeObj::ScCellRangeObj(ScDocShell* pDocSh, const ScRange& rR) :
4769 	ScCellRangesBase( pDocSh, rR ),
4770 	pRangePropSet( lcl_GetRangePropertySet() ),
4771 	aRange( rR )
4772 {
4773 	aRange.Justify();		// Anfang / Ende richtig
4774 }
4775 
~ScCellRangeObj()4776 ScCellRangeObj::~ScCellRangeObj()
4777 {
4778 }
4779 
RefChanged()4780 void ScCellRangeObj::RefChanged()
4781 {
4782 	ScCellRangesBase::RefChanged();
4783 
4784 	const ScRangeList& rRanges = GetRangeList();
4785 	DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!");
4786 	const ScRange* pFirst = rRanges.GetObject(0);
4787 	if (pFirst)
4788 	{
4789 		aRange = *pFirst;
4790 		aRange.Justify();
4791 	}
4792 }
4793 
queryInterface(const uno::Type & rType)4794 uno::Any SAL_CALL ScCellRangeObj::queryInterface( const uno::Type& rType )
4795 												throw(uno::RuntimeException)
4796 {
4797 	SC_QUERYINTERFACE( sheet::XCellRangeAddressable )
4798 	SC_QUERYINTERFACE( table::XCellRange )
4799 	SC_QUERYINTERFACE( sheet::XSheetCellRange )
4800 	SC_QUERYINTERFACE( sheet::XArrayFormulaRange )
4801 	SC_QUERYINTERFACE( sheet::XArrayFormulaTokens )
4802 	SC_QUERYINTERFACE( sheet::XCellRangeData )
4803 	SC_QUERYINTERFACE( sheet::XCellRangeFormula )
4804 	SC_QUERYINTERFACE( sheet::XMultipleOperation )
4805 	SC_QUERYINTERFACE( util::XMergeable )
4806 	SC_QUERYINTERFACE( sheet::XCellSeries )
4807 	SC_QUERYINTERFACE( table::XAutoFormattable )
4808 	SC_QUERYINTERFACE( util::XSortable )
4809 	SC_QUERYINTERFACE( sheet::XSheetFilterableEx )
4810 	SC_QUERYINTERFACE( sheet::XSheetFilterable )
4811 	SC_QUERYINTERFACE( sheet::XSubTotalCalculatable )
4812 	SC_QUERYINTERFACE( table::XColumnRowRange )
4813 	SC_QUERYINTERFACE( util::XImportable )
4814 	SC_QUERYINTERFACE( sheet::XCellFormatRangesSupplier )
4815 	SC_QUERYINTERFACE( sheet::XUniqueCellFormatRangesSupplier )
4816 
4817 	return ScCellRangesBase::queryInterface( rType );
4818 }
4819 
acquire()4820 void SAL_CALL ScCellRangeObj::acquire() throw()
4821 {
4822 	ScCellRangesBase::acquire();
4823 }
4824 
release()4825 void SAL_CALL ScCellRangeObj::release() throw()
4826 {
4827 	ScCellRangesBase::release();
4828 }
4829 
getTypes()4830 uno::Sequence<uno::Type> SAL_CALL ScCellRangeObj::getTypes() throw(uno::RuntimeException)
4831 {
4832 	static uno::Sequence<uno::Type> aTypes;
4833 	if ( aTypes.getLength() == 0 )
4834 	{
4835 		uno::Sequence<uno::Type> aParentTypes(ScCellRangesBase::getTypes());
4836 		long nParentLen = aParentTypes.getLength();
4837 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
4838 
4839 		aTypes.realloc( nParentLen + 17 );
4840 		uno::Type* pPtr = aTypes.getArray();
4841 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XCellRangeAddressable>*)0);
4842 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XSheetCellRange>*)0);
4843 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XArrayFormulaRange>*)0);
4844 		pPtr[nParentLen + 3] = getCppuType((const uno::Reference<sheet::XArrayFormulaTokens>*)0);
4845 		pPtr[nParentLen + 4] = getCppuType((const uno::Reference<sheet::XCellRangeData>*)0);
4846 		pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XCellRangeFormula>*)0);
4847 		pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XMultipleOperation>*)0);
4848 		pPtr[nParentLen + 7] = getCppuType((const uno::Reference<util::XMergeable>*)0);
4849 		pPtr[nParentLen + 8] = getCppuType((const uno::Reference<sheet::XCellSeries>*)0);
4850 		pPtr[nParentLen + 9] = getCppuType((const uno::Reference<table::XAutoFormattable>*)0);
4851 		pPtr[nParentLen +10] = getCppuType((const uno::Reference<util::XSortable>*)0);
4852 		pPtr[nParentLen +11] = getCppuType((const uno::Reference<sheet::XSheetFilterableEx>*)0);
4853 		pPtr[nParentLen +12] = getCppuType((const uno::Reference<sheet::XSubTotalCalculatable>*)0);
4854 		pPtr[nParentLen +13] = getCppuType((const uno::Reference<table::XColumnRowRange>*)0);
4855 		pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XImportable>*)0);
4856 		pPtr[nParentLen +15] = getCppuType((const uno::Reference<sheet::XCellFormatRangesSupplier>*)0);
4857 		pPtr[nParentLen +16] = getCppuType((const uno::Reference<sheet::XUniqueCellFormatRangesSupplier>*)0);
4858 
4859 		for (long i=0; i<nParentLen; i++)
4860 			pPtr[i] = pParentPtr[i];				// parent types first
4861 	}
4862 	return aTypes;
4863 }
4864 
getImplementationId()4865 uno::Sequence<sal_Int8> SAL_CALL ScCellRangeObj::getImplementationId()
4866 													throw(uno::RuntimeException)
4867 {
4868 	static uno::Sequence< sal_Int8 > aId;
4869 	if( aId.getLength() == 0 )
4870 	{
4871 		aId.realloc( 16 );
4872 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
4873 	}
4874 	return aId;
4875 }
4876 
4877 // XCellRange
4878 
4879 //	ColumnCount / RowCount sind weggefallen
4880 //!	werden im Writer fuer Tabellen noch gebraucht ???
4881 
GetCellByPosition_Impl(sal_Int32 nColumn,sal_Int32 nRow)4882 uno::Reference<table::XCell> ScCellRangeObj::GetCellByPosition_Impl(
4883 										sal_Int32 nColumn, sal_Int32 nRow )
4884 								throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
4885 {
4886 	ScDocShell* pDocSh = GetDocShell();
4887 	if (!pDocSh)
4888 		throw uno::RuntimeException();
4889 
4890 	if ( nColumn >= 0 && nRow >= 0 )
4891 	{
4892 		sal_Int32 nPosX = aRange.aStart.Col() + nColumn;
4893 		sal_Int32 nPosY = aRange.aStart.Row() + nRow;
4894 
4895 		if ( nPosX <= aRange.aEnd.Col() && nPosY <= aRange.aEnd.Row() )
4896 		{
4897 			ScAddress aNew( (SCCOL)nPosX, (SCROW)nPosY, aRange.aStart.Tab() );
4898 			return new ScCellObj( pDocSh, aNew );
4899 		}
4900 	}
4901 
4902 	throw lang::IndexOutOfBoundsException();
4903 //    return NULL;
4904 }
4905 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)4906 uno::Reference<table::XCell> SAL_CALL ScCellRangeObj::getCellByPosition(
4907 										sal_Int32 nColumn, sal_Int32 nRow )
4908 								throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
4909 {
4910 	ScUnoGuard aGuard;
4911 
4912 	return GetCellByPosition_Impl(nColumn, nRow);
4913 }
4914 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)4915 uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByPosition(
4916 				sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
4917 									throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
4918 {
4919 	ScUnoGuard aGuard;
4920 
4921 	ScDocShell* pDocSh = GetDocShell();
4922 	if (!pDocSh)
4923 		throw uno::RuntimeException();
4924 
4925 	if ( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
4926 	{
4927 		sal_Int32 nStartX = aRange.aStart.Col() + nLeft;
4928 		sal_Int32 nStartY = aRange.aStart.Row() + nTop;
4929 		sal_Int32 nEndX = aRange.aStart.Col() + nRight;
4930 		sal_Int32 nEndY = aRange.aStart.Row() + nBottom;
4931 
4932 		if ( nStartX <= nEndX && nEndX <= aRange.aEnd.Col() &&
4933 			 nStartY <= nEndY && nEndY <= aRange.aEnd.Row() )
4934 		{
4935 			ScRange aNew( (SCCOL)nStartX, (SCROW)nStartY, aRange.aStart.Tab(),
4936 						  (SCCOL)nEndX, (SCROW)nEndY, aRange.aEnd.Tab() );
4937 			return new ScCellRangeObj( pDocSh, aNew );
4938 		}
4939 	}
4940 
4941 	throw lang::IndexOutOfBoundsException();
4942 //    return NULL;
4943 }
4944 
4945 
getCellRangeByName(const rtl::OUString & aName)4946 uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByName(
4947 						const rtl::OUString& aName ) throw(uno::RuntimeException)
4948 {
4949 	return getCellRangeByName( aName, ScAddress::detailsOOOa1 );
4950 }
4951 
getCellRangeByName(const rtl::OUString & aName,const ScAddress::Details & rDetails)4952 uno::Reference<table::XCellRange>  ScCellRangeObj::getCellRangeByName(
4953 						const rtl::OUString& aName, const ScAddress::Details& rDetails  ) throw(uno::RuntimeException)
4954 {
4955 	//	name refers to the whole document (with the range's table as default),
4956 	//	valid only if the range is within this range
4957 
4958 	ScUnoGuard aGuard;
4959 	ScDocShell* pDocSh = GetDocShell();
4960 	if ( pDocSh )
4961 	{
4962 		ScDocument* pDoc = pDocSh->GetDocument();
4963 		SCTAB nTab = aRange.aStart.Tab();
4964 
4965 		ScRange aCellRange;
4966 		sal_Bool bFound = sal_False;
4967 		String aString(aName);
4968 		sal_uInt16 nParse = aCellRange.ParseAny( aString, pDoc, rDetails );
4969 		if ( nParse & SCA_VALID )
4970 		{
4971 			if ( !(nParse & SCA_TAB_3D) )	// keine Tabelle angegeben -> auf dieser Tabelle
4972 			{
4973 				aCellRange.aStart.SetTab(nTab);
4974 				aCellRange.aEnd.SetTab(nTab);
4975 			}
4976 			bFound = sal_True;
4977 		}
4978 		else
4979 		{
4980 			ScRangeUtil aRangeUtil;
4981 			if ( aRangeUtil.MakeRangeFromName( aString, pDoc, nTab, aCellRange, RUTL_NAMES ) ||
4982 				 aRangeUtil.MakeRangeFromName( aString, pDoc, nTab, aCellRange, RUTL_DBASE ) )
4983 				bFound = sal_True;
4984 		}
4985 
4986 		if (bFound)			// valid only if within this object's range
4987 		{
4988 			if (!aRange.In(aCellRange))
4989 				bFound = sal_False;
4990 		}
4991 
4992 		if (bFound)
4993 		{
4994 			if ( aCellRange.aStart == aCellRange.aEnd )
4995 				return new ScCellObj( pDocSh, aCellRange.aStart );
4996 			else
4997 				return new ScCellRangeObj( pDocSh, aCellRange );
4998 		}
4999 	}
5000 
5001 	throw uno::RuntimeException();
5002 //    return NULL;
5003 }
5004 
5005 // XColumnRowRange
5006 
getColumns()5007 uno::Reference<table::XTableColumns> SAL_CALL ScCellRangeObj::getColumns() throw(uno::RuntimeException)
5008 {
5009 	ScUnoGuard aGuard;
5010 	ScDocShell* pDocSh = GetDocShell();
5011 	if (pDocSh)
5012 		return new ScTableColumnsObj( pDocSh, aRange.aStart.Tab(),
5013 										aRange.aStart.Col(), aRange.aEnd.Col() );
5014 
5015 	DBG_ERROR("Dokument ungueltig");
5016 	return NULL;
5017 }
5018 
getRows()5019 uno::Reference<table::XTableRows> SAL_CALL ScCellRangeObj::getRows() throw(uno::RuntimeException)
5020 {
5021 	ScUnoGuard aGuard;
5022 	ScDocShell* pDocSh = GetDocShell();
5023 	if (pDocSh)
5024 		return new ScTableRowsObj( pDocSh, aRange.aStart.Tab(),
5025 									aRange.aStart.Row(), aRange.aEnd.Row() );
5026 
5027 	DBG_ERROR("Dokument ungueltig");
5028 	return NULL;
5029 }
5030 
5031 // XAddressableCellRange
5032 
getRangeAddress()5033 table::CellRangeAddress SAL_CALL ScCellRangeObj::getRangeAddress() throw(uno::RuntimeException)
5034 {
5035 	ScUnoGuard aGuard;
5036 	table::CellRangeAddress aRet;
5037 	ScUnoConversion::FillApiRange( aRet, aRange );
5038 	return aRet;
5039 }
5040 
5041 // XSheetCellRange
5042 
getSpreadsheet()5043 uno::Reference<sheet::XSpreadsheet> SAL_CALL ScCellRangeObj::getSpreadsheet()
5044 												throw(uno::RuntimeException)
5045 {
5046 	ScUnoGuard aGuard;
5047 	ScDocShell* pDocSh = GetDocShell();
5048 	if (pDocSh)
5049 		return new ScTableSheetObj( pDocSh, aRange.aStart.Tab() );
5050 
5051 	DBG_ERROR("Dokument ungueltig");
5052 	return NULL;
5053 }
5054 
5055 // XArrayFormulaRange
5056 
getArrayFormula()5057 rtl::OUString SAL_CALL ScCellRangeObj::getArrayFormula() throw(uno::RuntimeException)
5058 {
5059 	ScUnoGuard aGuard;
5060 
5061 	//	Matrix-Formel, wenn eindeutig Teil einer Matrix,
5062 	//	also wenn Anfang und Ende des Blocks zur selben Matrix gehoeren.
5063 	//	Sonst Leerstring.
5064 
5065 	String aFormula;
5066 	ScDocShell* pDocSh = GetDocShell();
5067 	if (pDocSh)
5068 	{
5069 		ScDocument* pDoc = pDocSh->GetDocument();
5070 		const ScBaseCell* pCell1 = pDoc->GetCell( aRange.aStart );
5071 		const ScBaseCell* pCell2 = pDoc->GetCell( aRange.aEnd );
5072 		if ( pCell1 && pCell2 && pCell1->GetCellType() == CELLTYPE_FORMULA &&
5073 								 pCell2->GetCellType() == CELLTYPE_FORMULA )
5074 		{
5075 			const ScFormulaCell* pFCell1 = (const ScFormulaCell*)pCell1;
5076 			const ScFormulaCell* pFCell2 = (const ScFormulaCell*)pCell2;
5077 			ScAddress aStart1;
5078 			ScAddress aStart2;
5079 			if ( pFCell1->GetMatrixOrigin( aStart1 ) && pFCell2->GetMatrixOrigin( aStart2 ) )
5080 			{
5081 				if ( aStart1 == aStart2 )				// beides dieselbe Matrix
5082 					pFCell1->GetFormula( aFormula );	// egal, von welcher Zelle
5083 			}
5084 		}
5085 	}
5086 	return aFormula;
5087 }
5088 
SetArrayFormula_Impl(const rtl::OUString & rFormula,const rtl::OUString & rFormulaNmsp,const formula::FormulaGrammar::Grammar eGrammar)5089 void ScCellRangeObj::SetArrayFormula_Impl( const rtl::OUString& rFormula,
5090         const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar ) throw(uno::RuntimeException)
5091 {
5092     ScDocShell* pDocSh = GetDocShell();
5093     if (pDocSh)
5094     {
5095         ScDocFunc aFunc(*pDocSh);
5096         if ( rFormula.getLength() )
5097         {
5098             if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) )
5099             {
5100                 //	#74681# don't set array formula for sheet object
5101                 throw uno::RuntimeException();
5102             }
5103 
5104             aFunc.EnterMatrix( aRange, NULL, NULL, rFormula, sal_True, sal_True, rFormulaNmsp, eGrammar );
5105         }
5106         else
5107         {
5108             //	empty string -> erase array formula
5109             ScMarkData aMark;
5110             aMark.SetMarkArea( aRange );
5111             aMark.SelectTable( aRange.aStart.Tab(), sal_True );
5112             aFunc.DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True );
5113         }
5114     }
5115 }
5116 
setArrayFormula(const rtl::OUString & aFormula)5117 void SAL_CALL ScCellRangeObj::setArrayFormula( const rtl::OUString& aFormula )
5118 												throw(uno::RuntimeException)
5119 {
5120 	ScUnoGuard aGuard;
5121     // GRAM_PODF_A1 for API compatibility.
5122     SetArrayFormula_Impl( aFormula, ::rtl::OUString(), formula::FormulaGrammar::GRAM_PODF_A1);
5123 }
5124 
SetArrayFormulaWithGrammar(const rtl::OUString & rFormula,const rtl::OUString & rFormulaNmsp,const formula::FormulaGrammar::Grammar eGrammar)5125 void ScCellRangeObj::SetArrayFormulaWithGrammar( const rtl::OUString& rFormula,
5126         const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar ) throw(uno::RuntimeException)
5127 {
5128 	ScUnoGuard aGuard;
5129     SetArrayFormula_Impl( rFormula, rFormulaNmsp, eGrammar);
5130 }
5131 
5132 // XArrayFormulaTokens
5133 
getArrayTokens()5134 uno::Sequence<sheet::FormulaToken> SAL_CALL ScCellRangeObj::getArrayTokens() throw(uno::RuntimeException)
5135 {
5136     ScUnoGuard aGuard;
5137 
5138     // same cell logic as in getArrayFormula
5139 
5140     uno::Sequence<sheet::FormulaToken> aSequence;
5141     ScDocShell* pDocSh = GetDocShell();
5142     if ( pDocSh )
5143     {
5144         ScDocument* pDoc = pDocSh->GetDocument();
5145         const ScBaseCell* pCell1 = pDoc->GetCell( aRange.aStart );
5146         const ScBaseCell* pCell2 = pDoc->GetCell( aRange.aEnd );
5147         if ( pCell1 && pCell2 && pCell1->GetCellType() == CELLTYPE_FORMULA &&
5148                                  pCell2->GetCellType() == CELLTYPE_FORMULA )
5149         {
5150             const ScFormulaCell* pFCell1 = (const ScFormulaCell*)pCell1;
5151             const ScFormulaCell* pFCell2 = (const ScFormulaCell*)pCell2;
5152             ScAddress aStart1;
5153             ScAddress aStart2;
5154             if ( pFCell1->GetMatrixOrigin( aStart1 ) && pFCell2->GetMatrixOrigin( aStart2 ) )
5155             {
5156                 if ( aStart1 == aStart2 )
5157                 {
5158                     ScTokenArray* pTokenArray = pFCell1->GetCode();
5159                     if ( pTokenArray )
5160                         (void)ScTokenConversion::ConvertToTokenSequence( *pDoc, aSequence, *pTokenArray );
5161                 }
5162             }
5163         }
5164     }
5165     return aSequence;
5166 }
5167 
setArrayTokens(const uno::Sequence<sheet::FormulaToken> & rTokens)5168 void SAL_CALL ScCellRangeObj::setArrayTokens( const uno::Sequence<sheet::FormulaToken>& rTokens ) throw(uno::RuntimeException)
5169 {
5170     ScUnoGuard aGuard;
5171     ScDocShell* pDocSh = GetDocShell();
5172     if ( pDocSh )
5173     {
5174         ScDocFunc aFunc(*pDocSh);
5175         if ( rTokens.getLength() )
5176         {
5177             if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) )
5178             {
5179                 throw uno::RuntimeException();
5180             }
5181 
5182             ScDocument* pDoc = pDocSh->GetDocument();
5183             ScTokenArray aTokenArray;
5184             (void)ScTokenConversion::ConvertToTokenArray( *pDoc, aTokenArray, rTokens );
5185 
5186             // Actually GRAM_PODF_A1 is a don't-care here because of the token
5187             // array being set, it fits with other API compatibility grammars
5188             // though.
5189             aFunc.EnterMatrix( aRange, NULL, &aTokenArray, EMPTY_STRING, sal_True, sal_True, EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1 );
5190         }
5191         else
5192         {
5193             //  empty sequence -> erase array formula
5194             ScMarkData aMark;
5195             aMark.SetMarkArea( aRange );
5196             aMark.SelectTable( aRange.aStart.Tab(), sal_True );
5197             aFunc.DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True );
5198         }
5199     }
5200 }
5201 
5202 // XCellRangeData
5203 
getDataArray()5204 uno::Sequence< uno::Sequence<uno::Any> > SAL_CALL ScCellRangeObj::getDataArray()
5205 									throw(uno::RuntimeException)
5206 {
5207 	ScUnoGuard aGuard;
5208 
5209 	if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) )
5210 	{
5211 		//	don't create a data array for the sheet
5212 		throw uno::RuntimeException();
5213 	}
5214 
5215 	ScDocShell* pDocSh = GetDocShell();
5216 	if (pDocSh)
5217 	{
5218 		uno::Any aAny;
5219 		// bAllowNV = TRUE: errors as void
5220 		if ( ScRangeToSequence::FillMixedArray( aAny, pDocSh->GetDocument(), aRange, sal_True ) )
5221 		{
5222 			uno::Sequence< uno::Sequence<uno::Any> > aSeq;
5223 			if ( aAny >>= aSeq )
5224 				return aSeq;			// success
5225 		}
5226 	}
5227 
5228 	throw uno::RuntimeException();		// no other exceptions specified
5229 //    return uno::Sequence< uno::Sequence<uno::Any> >(0);
5230 }
5231 
setDataArray(const uno::Sequence<uno::Sequence<uno::Any>> & aArray)5232 void SAL_CALL ScCellRangeObj::setDataArray(
5233 						const uno::Sequence< uno::Sequence<uno::Any> >& aArray )
5234 									throw(uno::RuntimeException)
5235 {
5236 	ScUnoGuard aGuard;
5237 
5238 	sal_Bool bDone = sal_False;
5239 	ScDocShell* pDocSh = GetDocShell();
5240 	if (pDocSh)
5241 	{
5242 		//! move lcl_PutDataArray to docfunc?
5243 		bDone = lcl_PutDataArray( *pDocSh, aRange, aArray );
5244 	}
5245 
5246 	if (!bDone)
5247 		throw uno::RuntimeException();		// no other exceptions specified
5248 }
5249 
5250 // XCellRangeFormula
5251 
getFormulaArray()5252 uno::Sequence< uno::Sequence<rtl::OUString> > SAL_CALL ScCellRangeObj::getFormulaArray()
5253 									throw(uno::RuntimeException)
5254 {
5255 	ScUnoGuard aGuard;
5256 
5257 	if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) )
5258 	{
5259 		//	don't create a data array for the sheet
5260 		throw uno::RuntimeException();
5261 	}
5262 
5263 	ScDocShell* pDocSh = GetDocShell();
5264 	if (pDocSh)
5265 	{
5266 		SCCOL nStartCol = aRange.aStart.Col();
5267 		SCROW nStartRow = aRange.aStart.Row();
5268 		SCCOL nEndCol = aRange.aEnd.Col();
5269 		SCROW nEndRow = aRange.aEnd.Row();
5270 		SCCOL nColCount = nEndCol + 1 - nStartCol;
5271 		SCROW nRowCount = nEndRow + 1 - nStartRow;
5272 		SCTAB nTab = aRange.aStart.Tab();
5273 
5274 		uno::Sequence< uno::Sequence<rtl::OUString> > aRowSeq( nRowCount );
5275 		uno::Sequence<rtl::OUString>* pRowAry = aRowSeq.getArray();
5276 		for (SCROW nRowIndex = 0; nRowIndex < nRowCount; nRowIndex++)
5277 		{
5278 			uno::Sequence<rtl::OUString> aColSeq( nColCount );
5279 			rtl::OUString* pColAry = aColSeq.getArray();
5280 			for (SCCOL nColIndex = 0; nColIndex < nColCount; nColIndex++)
5281 				pColAry[nColIndex] = lcl_GetInputString( pDocSh->GetDocument(),
5282 									ScAddress( nStartCol+nColIndex, nStartRow+nRowIndex, nTab ), sal_True );
5283 
5284 			pRowAry[nRowIndex] = aColSeq;
5285 		}
5286 
5287 		return aRowSeq;
5288 	}
5289 
5290 	throw uno::RuntimeException();		// no other exceptions specified
5291 //    return uno::Sequence< uno::Sequence<rtl::OUString> >(0);
5292 }
5293 
setFormulaArray(const uno::Sequence<uno::Sequence<rtl::OUString>> & aArray)5294 void SAL_CALL ScCellRangeObj::setFormulaArray(
5295 						const uno::Sequence< uno::Sequence<rtl::OUString> >& aArray )
5296 									throw(uno::RuntimeException)
5297 {
5298 	ScUnoGuard aGuard;
5299 
5300 	sal_Bool bDone = sal_False;
5301 	ScDocShell* pDocSh = GetDocShell();
5302 	if (pDocSh)
5303 	{
5304         ScExternalRefManager::ApiGuard aExtRefGuard(pDocSh->GetDocument());
5305 
5306         // GRAM_PODF_A1 for API compatibility.
5307         bDone = lcl_PutFormulaArray( *pDocSh, aRange, aArray, EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1 );
5308 	}
5309 
5310 	if (!bDone)
5311 		throw uno::RuntimeException();		// no other exceptions specified
5312 }
5313 
5314 // XMultipleOperation
5315 
setTableOperation(const table::CellRangeAddress & aFormulaRange,sheet::TableOperationMode nMode,const table::CellAddress & aColumnCell,const table::CellAddress & aRowCell)5316 void SAL_CALL ScCellRangeObj::setTableOperation( const table::CellRangeAddress& aFormulaRange,
5317 										sheet::TableOperationMode nMode,
5318 										const table::CellAddress& aColumnCell,
5319 										const table::CellAddress& aRowCell )
5320 									throw(uno::RuntimeException)
5321 {
5322 	ScUnoGuard aGuard;
5323 	ScDocShell* pDocSh = GetDocShell();
5324 	if (pDocSh)
5325 	{
5326 		sal_Bool bError = sal_False;
5327 		ScTabOpParam aParam;
5328 		aParam.aRefFormulaCell = ScRefAddress( (SCCOL)aFormulaRange.StartColumn,
5329 											  (SCROW)aFormulaRange.StartRow, aFormulaRange.Sheet,
5330 											  sal_False, sal_False, sal_False );
5331 		aParam.aRefFormulaEnd  = ScRefAddress( (SCCOL)aFormulaRange.EndColumn,
5332 											  (SCROW)aFormulaRange.EndRow, aFormulaRange.Sheet,
5333 											  sal_False, sal_False, sal_False );
5334 		aParam.aRefRowCell	   = ScRefAddress( (SCCOL)aRowCell.Column,
5335 											  (SCROW)aRowCell.Row, aRowCell.Sheet,
5336 											  sal_False, sal_False, sal_False );
5337 		aParam.aRefColCell	   = ScRefAddress( (SCCOL)aColumnCell.Column,
5338 											  (SCROW)aColumnCell.Row, aColumnCell.Sheet,
5339 											  sal_False, sal_False, sal_False );
5340 		switch (nMode)
5341 		{
5342 			case sheet::TableOperationMode_COLUMN:
5343 				aParam.nMode = 0;
5344 				break;
5345 			case sheet::TableOperationMode_ROW:
5346 				aParam.nMode = 1;
5347 				break;
5348 			case sheet::TableOperationMode_BOTH:
5349 				aParam.nMode = 2;
5350 				break;
5351 			default:
5352 				bError = sal_True;
5353 		}
5354 
5355 		if (!bError)
5356 		{
5357 			ScDocFunc aFunc(*pDocSh);
5358 			aFunc.TabOp( aRange, NULL, aParam, sal_True, sal_True );
5359 		}
5360 	}
5361 }
5362 
5363 // XMergeable
5364 
merge(sal_Bool bMerge)5365 void SAL_CALL ScCellRangeObj::merge( sal_Bool bMerge ) throw(uno::RuntimeException)
5366 {
5367 	ScUnoGuard aGuard;
5368 	ScDocShell* pDocSh = GetDocShell();
5369 	if ( pDocSh )
5370 	{
5371 		ScDocFunc aFunc(*pDocSh);
5372 		if ( bMerge )
5373 			aFunc.MergeCells( aRange, sal_False, sal_True, sal_True );
5374 		else
5375 			aFunc.UnmergeCells( aRange, sal_True, sal_True );
5376 
5377 		//!	Fehler abfangen?
5378 	}
5379 }
5380 
getIsMerged()5381 sal_Bool SAL_CALL ScCellRangeObj::getIsMerged() throw(uno::RuntimeException)
5382 {
5383 	ScUnoGuard aGuard;
5384 	ScDocShell* pDocSh = GetDocShell();
5385 	return pDocSh && pDocSh->GetDocument()->HasAttrib( aRange, HASATTR_MERGED );
5386 }
5387 
5388 // XCellSeries
5389 
fillSeries(sheet::FillDirection nFillDirection,sheet::FillMode nFillMode,sheet::FillDateMode nFillDateMode,double fStep,double fEndValue)5390 void SAL_CALL ScCellRangeObj::fillSeries( sheet::FillDirection nFillDirection,
5391 						sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode,
5392 						double fStep, double fEndValue ) throw(uno::RuntimeException)
5393 {
5394 	ScUnoGuard aGuard;
5395 	ScDocShell* pDocSh = GetDocShell();
5396 	if ( pDocSh )
5397 	{
5398 		sal_Bool bError = sal_False;
5399 
5400         FillDir	eDir = FILL_TO_BOTTOM;
5401 		switch (nFillDirection)
5402 		{
5403 			case sheet::FillDirection_TO_BOTTOM:
5404 				eDir = FILL_TO_BOTTOM;
5405 				break;
5406 			case sheet::FillDirection_TO_RIGHT:
5407 				eDir = FILL_TO_RIGHT;
5408 				break;
5409 			case sheet::FillDirection_TO_TOP:
5410 				eDir = FILL_TO_TOP;
5411 				break;
5412 			case sheet::FillDirection_TO_LEFT:
5413 				eDir = FILL_TO_LEFT;
5414 				break;
5415 			default:
5416 				bError = sal_True;
5417 		}
5418 
5419         FillCmd eCmd = FILL_SIMPLE;
5420 		switch ( nFillMode )
5421 		{
5422 			case sheet::FillMode_SIMPLE:
5423 				eCmd = FILL_SIMPLE;
5424 				break;
5425 			case sheet::FillMode_LINEAR:
5426 				eCmd = FILL_LINEAR;
5427 				break;
5428 			case sheet::FillMode_GROWTH:
5429 				eCmd = FILL_GROWTH;
5430 				break;
5431 			case sheet::FillMode_DATE:
5432 				eCmd = FILL_DATE;
5433 				break;
5434 			case sheet::FillMode_AUTO:
5435 				eCmd = FILL_AUTO;
5436 				break;
5437 			default:
5438 				bError = sal_True;
5439 		}
5440 
5441         FillDateCmd	eDateCmd = FILL_DAY;
5442 		switch ( nFillDateMode )
5443 		{
5444 			case sheet::FillDateMode_FILL_DATE_DAY:
5445 				eDateCmd = FILL_DAY;
5446 				break;
5447 			case sheet::FillDateMode_FILL_DATE_WEEKDAY:
5448 				eDateCmd = FILL_WEEKDAY;
5449 				break;
5450 			case sheet::FillDateMode_FILL_DATE_MONTH:
5451 				eDateCmd = FILL_MONTH;
5452 				break;
5453 			case sheet::FillDateMode_FILL_DATE_YEAR:
5454 				eDateCmd = FILL_YEAR;
5455 				break;
5456 			default:
5457 				bError = sal_True;
5458 		}
5459 
5460 		if (!bError)
5461 		{
5462 			ScDocFunc aFunc(*pDocSh);
5463 			aFunc.FillSeries( aRange, NULL, eDir, eCmd, eDateCmd,
5464 								MAXDOUBLE, fStep, fEndValue, sal_True, sal_True );
5465 		}
5466 	}
5467 }
5468 
fillAuto(sheet::FillDirection nFillDirection,sal_Int32 nSourceCount)5469 void SAL_CALL ScCellRangeObj::fillAuto( sheet::FillDirection nFillDirection,
5470 								sal_Int32 nSourceCount ) throw(uno::RuntimeException)
5471 {
5472 	ScUnoGuard aGuard;
5473 	ScDocShell* pDocSh = GetDocShell();
5474 	if ( pDocSh && nSourceCount )
5475 	{
5476 		ScRange aSourceRange(aRange);
5477         SCsCOLROW nCount = 0;                   // "Dest-Count"
5478         FillDir eDir = FILL_TO_BOTTOM;
5479 		sal_Bool bError = sal_False;
5480 		switch (nFillDirection)
5481 		{
5482 			case sheet::FillDirection_TO_BOTTOM:
5483                 aSourceRange.aEnd.SetRow( static_cast<SCROW>( aSourceRange.aStart.Row() + nSourceCount - 1 ) );
5484 				nCount = aRange.aEnd.Row() - aSourceRange.aEnd.Row();
5485 				eDir = FILL_TO_BOTTOM;
5486 				break;
5487 			case sheet::FillDirection_TO_RIGHT:
5488                 aSourceRange.aEnd.SetCol( static_cast<SCCOL>( aSourceRange.aStart.Col() + nSourceCount - 1 ) );
5489 				nCount = aRange.aEnd.Col() - aSourceRange.aEnd.Col();
5490 				eDir = FILL_TO_RIGHT;
5491 				break;
5492 			case sheet::FillDirection_TO_TOP:
5493                 aSourceRange.aStart.SetRow( static_cast<SCROW>( aSourceRange.aEnd.Row() - nSourceCount + 1 ) );
5494 				nCount = aSourceRange.aStart.Row() - aRange.aStart.Row();
5495 				eDir = FILL_TO_TOP;
5496 				break;
5497 			case sheet::FillDirection_TO_LEFT:
5498                 aSourceRange.aStart.SetCol( static_cast<SCCOL>( aSourceRange.aEnd.Col() - nSourceCount + 1 ) );
5499 				nCount = aSourceRange.aStart.Col() - aRange.aStart.Col();
5500 				eDir = FILL_TO_LEFT;
5501 				break;
5502 			default:
5503 				bError = sal_True;
5504 		}
5505         if (nCount < 0 || nCount > MAXROW)      // overflow
5506 			bError = sal_True;
5507 
5508 		if (!bError)
5509 		{
5510 			ScDocFunc aFunc(*pDocSh);
5511 			aFunc.FillAuto( aSourceRange, NULL, eDir, nCount, sal_True, sal_True );
5512 		}
5513 	}
5514 }
5515 
5516 // XAutoFormattable
5517 
autoFormat(const rtl::OUString & aName)5518 void SAL_CALL ScCellRangeObj::autoFormat( const rtl::OUString& aName )
5519 					throw(lang::IllegalArgumentException, uno::RuntimeException)
5520 {
5521 	ScUnoGuard aGuard;
5522 	ScAutoFormat* pAutoFormat = ScGlobal::GetAutoFormat();
5523 	ScDocShell* pDocSh = GetDocShell();
5524 	if ( pDocSh && pAutoFormat )
5525 	{
5526 		String aNameString(aName);
5527 		sal_uInt16 nCount = pAutoFormat->GetCount();
5528 		sal_uInt16 nIndex;
5529 		String aCompare;
5530 		for (nIndex=0; nIndex<nCount; nIndex++)
5531 		{
5532 			(*pAutoFormat)[nIndex]->GetName(aCompare);
5533 			if ( aCompare == aNameString )						//!	Case-insensitiv ???
5534 				break;
5535 		}
5536 		if (nIndex<nCount)
5537 		{
5538 			ScDocFunc aFunc(*pDocSh);
5539 			aFunc.AutoFormat( aRange, NULL, nIndex, sal_True, sal_True );
5540 		}
5541         else
5542             throw lang::IllegalArgumentException();
5543 	}
5544 }
5545 
5546 // XSortable
5547 
createSortDescriptor()5548 uno::Sequence<beans::PropertyValue> SAL_CALL ScCellRangeObj::createSortDescriptor()
5549 												throw(uno::RuntimeException)
5550 {
5551 	ScUnoGuard aGuard;
5552 	ScSortParam aParam;
5553 	ScDocShell* pDocSh = GetDocShell();
5554 	if ( pDocSh )
5555 	{
5556 		// DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich
5557 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, SC_DBSEL_FORCE_MARK );
5558 		if (pData)
5559 		{
5560 			pData->GetSortParam(aParam);
5561 
5562 			//	im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5563 			ScRange aDBRange;
5564 			pData->GetArea(aDBRange);
5565             SCCOLROW nFieldStart = aParam.bByRow ?
5566                 static_cast<SCCOLROW>(aDBRange.aStart.Col()) :
5567                 static_cast<SCCOLROW>(aDBRange.aStart.Row());
5568 			for (sal_uInt16 i=0; i<MAXSORT; i++)
5569 				if ( aParam.bDoSort[i] && aParam.nField[i] >= nFieldStart )
5570 					aParam.nField[i] -= nFieldStart;
5571 		}
5572 	}
5573 
5574 	uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() );
5575 	ScSortDescriptor::FillProperties( aSeq, aParam );
5576 	return aSeq;
5577 }
5578 
sort(const uno::Sequence<beans::PropertyValue> & aDescriptor)5579 void SAL_CALL ScCellRangeObj::sort( const uno::Sequence<beans::PropertyValue>& aDescriptor )
5580 												throw(uno::RuntimeException)
5581 {
5582 	ScUnoGuard aGuard;
5583 	ScDocShell* pDocSh = GetDocShell();
5584 	if (pDocSh)
5585 	{
5586 		sal_uInt16 i;
5587 		ScSortParam aParam;
5588 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );	// ggf. Bereich anlegen
5589 		if (pData)
5590 		{
5591 			//	alten Einstellungen holen, falls nicht alles neu gesetzt wird
5592 			pData->GetSortParam(aParam);
5593             SCCOLROW nOldStart = aParam.bByRow ?
5594                 static_cast<SCCOLROW>(aRange.aStart.Col()) :
5595                 static_cast<SCCOLROW>(aRange.aStart.Row());
5596 			for (i=0; i<MAXSORT; i++)
5597 				if ( aParam.bDoSort[i] && aParam.nField[i] >= nOldStart )
5598 					aParam.nField[i] -= nOldStart;
5599 		}
5600 
5601 		ScSortDescriptor::FillSortParam( aParam, aDescriptor );
5602 
5603 		//	im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5604 		//	ByRow kann bei FillSortParam umgesetzt worden sein
5605         SCCOLROW nFieldStart = aParam.bByRow ?
5606             static_cast<SCCOLROW>(aRange.aStart.Col()) :
5607             static_cast<SCCOLROW>(aRange.aStart.Row());
5608 		for (i=0; i<MAXSORT; i++)
5609 			aParam.nField[i] += nFieldStart;
5610 
5611 		SCTAB nTab = aRange.aStart.Tab();
5612 		aParam.nCol1 = aRange.aStart.Col();
5613 		aParam.nRow1 = aRange.aStart.Row();
5614 		aParam.nCol2 = aRange.aEnd.Col();
5615 		aParam.nRow2 = aRange.aEnd.Row();
5616 
5617 		pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );		// ggf. Bereich anlegen
5618 
5619 		ScDBDocFunc aFunc(*pDocSh);							// Bereich muss angelegt sein
5620 		aFunc.Sort( nTab, aParam, sal_True, sal_True, sal_True );
5621 	}
5622 }
5623 
5624 // XFilterable
5625 
createFilterDescriptor(sal_Bool bEmpty)5626 uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFilterDescriptor(
5627 								sal_Bool bEmpty ) throw(uno::RuntimeException)
5628 {
5629 	ScUnoGuard aGuard;
5630 	ScDocShell* pDocSh = GetDocShell();
5631 	ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh);
5632 	if ( !bEmpty && pDocSh )
5633 	{
5634 		// DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich
5635 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, SC_DBSEL_FORCE_MARK );
5636 		if (pData)
5637 		{
5638 			ScQueryParam aParam;
5639 			pData->GetQueryParam(aParam);
5640 			//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5641 			ScRange aDBRange;
5642 			pData->GetArea(aDBRange);
5643             SCCOLROW nFieldStart = aParam.bByRow ?
5644                 static_cast<SCCOLROW>(aDBRange.aStart.Col()) :
5645                 static_cast<SCCOLROW>(aDBRange.aStart.Row());
5646 			SCSIZE nCount = aParam.GetEntryCount();
5647 			for (SCSIZE i=0; i<nCount; i++)
5648 			{
5649 				ScQueryEntry& rEntry = aParam.GetEntry(i);
5650 				if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
5651 					rEntry.nField -= nFieldStart;
5652 			}
5653 			pNew->SetParam(aParam);
5654 		}
5655 	}
5656 	return pNew;
5657 }
5658 
filter(const uno::Reference<sheet::XSheetFilterDescriptor> & xDescriptor)5659 void SAL_CALL ScCellRangeObj::filter( const uno::Reference<sheet::XSheetFilterDescriptor>& xDescriptor )
5660 												throw(uno::RuntimeException)
5661 {
5662 	ScUnoGuard aGuard;
5663 
5664 	//	das koennte theoretisch ein fremdes Objekt sein, also nur das
5665 	//	oeffentliche XSheetFilterDescriptor Interface benutzen, um
5666 	//	die Daten in ein ScFilterDescriptor Objekt zu kopieren:
5667 	//!	wenn es schon ein ScFilterDescriptor ist, direkt per getImplementation?
5668 
5669 	ScDocShell* pDocSh = GetDocShell();
5670 	ScFilterDescriptor aImpl(pDocSh);
5671     uno::Reference< sheet::XSheetFilterDescriptor2 > xDescriptor2( xDescriptor, uno::UNO_QUERY );
5672     if ( xDescriptor2.is() )
5673     {
5674         aImpl.setFilterFields2( xDescriptor2->getFilterFields2() );
5675     }
5676     else
5677     {
5678         aImpl.setFilterFields( xDescriptor->getFilterFields() );
5679     }
5680 	//	Rest sind jetzt Properties...
5681 
5682 	uno::Reference<beans::XPropertySet> xPropSet( xDescriptor, uno::UNO_QUERY );
5683 	if (xPropSet.is())
5684 		lcl_CopyProperties( aImpl, *(beans::XPropertySet*)xPropSet.get() );
5685 
5686 	//
5687 	//	ausfuehren...
5688 	//
5689 
5690 	if (pDocSh)
5691 	{
5692 		ScQueryParam aParam = aImpl.GetParam();
5693 		//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5694         SCCOLROW nFieldStart = aParam.bByRow ?
5695             static_cast<SCCOLROW>(aRange.aStart.Col()) :
5696             static_cast<SCCOLROW>(aRange.aStart.Row());
5697 		SCSIZE nCount = aParam.GetEntryCount();
5698 		for (SCSIZE i=0; i<nCount; i++)
5699 		{
5700 			ScQueryEntry& rEntry = aParam.GetEntry(i);
5701 			if (rEntry.bDoQuery)
5702 			{
5703 				rEntry.nField += nFieldStart;
5704 				//	Im Dialog wird immer der String angezeigt -> muss zum Wert passen
5705 				if ( !rEntry.bQueryByString )
5706 					pDocSh->GetDocument()->GetFormatTable()->
5707 						GetInputLineString( rEntry.nVal, 0, *rEntry.pStr );
5708 			}
5709 		}
5710 
5711 		SCTAB nTab = aRange.aStart.Tab();
5712 		aParam.nCol1 = aRange.aStart.Col();
5713 		aParam.nRow1 = aRange.aStart.Row();
5714 		aParam.nCol2 = aRange.aEnd.Col();
5715 		aParam.nRow2 = aRange.aEnd.Row();
5716 
5717 		pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );	// ggf. Bereich anlegen
5718 
5719 		//!	keep source range in filter descriptor
5720 		//!	if created by createFilterDescriptorByObject ???
5721 
5722 		ScDBDocFunc aFunc(*pDocSh);
5723 		aFunc.Query( nTab, aParam, NULL, sal_True, sal_True );	// Bereich muss angelegt sein
5724 	}
5725 }
5726 
5727 //!	get/setAutoFilter als Properties!!!
5728 
5729 // XAdvancedFilterSource
5730 
createFilterDescriptorByObject(const uno::Reference<sheet::XSheetFilterable> & xObject)5731 uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFilterDescriptorByObject(
5732 						const uno::Reference<sheet::XSheetFilterable>& xObject )
5733 												throw(uno::RuntimeException)
5734 {
5735 	ScUnoGuard aGuard;
5736 
5737 	//	this ist hier nicht der Bereich, der gefiltert wird, sondern der
5738 	//	Bereich mit der Abfrage...
5739 
5740 	uno::Reference<sheet::XCellRangeAddressable> xAddr( xObject, uno::UNO_QUERY );
5741 
5742 	ScDocShell* pDocSh = GetDocShell();
5743 	if ( pDocSh && xAddr.is() )
5744 	{
5745 		//!	Test, ob xObject im selben Dokument ist
5746 
5747 		ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh);	//! stattdessen vom Objekt?
5748 		//XSheetFilterDescriptorRef xNew = xObject->createFilterDescriptor(sal_True);
5749 
5750 		ScQueryParam aParam = pNew->GetParam();
5751 		aParam.bHasHeader = sal_True;
5752 
5753 		table::CellRangeAddress aDataAddress(xAddr->getRangeAddress());
5754 		aParam.nCol1 = (SCCOL)aDataAddress.StartColumn;
5755 		aParam.nRow1 = (SCROW)aDataAddress.StartRow;
5756 		aParam.nCol2 = (SCCOL)aDataAddress.EndColumn;
5757 		aParam.nRow2 = (SCROW)aDataAddress.EndRow;
5758 		aParam.nTab  = aDataAddress.Sheet;
5759 
5760 		ScDocument* pDoc = pDocSh->GetDocument();
5761 		sal_Bool bOk = pDoc->CreateQueryParam(
5762 							aRange.aStart.Col(), aRange.aStart.Row(),
5763 							aRange.aEnd.Col(), aRange.aEnd.Row(),
5764 							aRange.aStart.Tab(), aParam );
5765 		if ( bOk )
5766 		{
5767 			//	im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5768             SCCOLROW nFieldStart = aParam.bByRow ?
5769                 static_cast<SCCOLROW>(aDataAddress.StartColumn) :
5770                 static_cast<SCCOLROW>(aDataAddress.StartRow);
5771 			SCSIZE nCount = aParam.GetEntryCount();
5772 			for (SCSIZE i=0; i<nCount; i++)
5773 			{
5774 				ScQueryEntry& rEntry = aParam.GetEntry(i);
5775 				if (rEntry.bDoQuery && rEntry.nField >= nFieldStart)
5776 					rEntry.nField -= nFieldStart;
5777 			}
5778 
5779 			pNew->SetParam( aParam );
5780 			return pNew;
5781 		}
5782 		else
5783 		{
5784 			delete pNew;
5785 			return NULL;		// ungueltig -> null
5786 		}
5787 	}
5788 
5789 	DBG_ERROR("kein Dokument oder kein Bereich");
5790 	return NULL;
5791 }
5792 
5793 // XSubTotalSource
5794 
createSubTotalDescriptor(sal_Bool bEmpty)5795 uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScCellRangeObj::createSubTotalDescriptor(
5796 								sal_Bool bEmpty ) throw(uno::RuntimeException)
5797 {
5798 	ScUnoGuard aGuard;
5799 	ScSubTotalDescriptor* pNew = new ScSubTotalDescriptor;
5800 	ScDocShell* pDocSh = GetDocShell();
5801 	if ( !bEmpty && pDocSh )
5802 	{
5803 		// DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich
5804 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, SC_DBSEL_FORCE_MARK );
5805 		if (pData)
5806 		{
5807 			ScSubTotalParam aParam;
5808 			pData->GetSubTotalParam(aParam);
5809 			//	im SubTotalDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5810 			ScRange aDBRange;
5811 			pData->GetArea(aDBRange);
5812 			SCCOL nFieldStart = aDBRange.aStart.Col();
5813 			for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
5814 			{
5815 				if ( aParam.bGroupActive[i] )
5816 				{
5817 					if ( aParam.nField[i] >= nFieldStart )
5818                         aParam.nField[i] = sal::static_int_cast<SCCOL>( aParam.nField[i] - nFieldStart );
5819 					for (SCCOL j=0; j<aParam.nSubTotals[i]; j++)
5820 						if ( aParam.pSubTotals[i][j] >= nFieldStart )
5821                             aParam.pSubTotals[i][j] = sal::static_int_cast<SCCOL>( aParam.pSubTotals[i][j] - nFieldStart );
5822 				}
5823 			}
5824 			pNew->SetParam(aParam);
5825 		}
5826 	}
5827 	return pNew;
5828 }
5829 
applySubTotals(const uno::Reference<sheet::XSubTotalDescriptor> & xDescriptor,sal_Bool bReplace)5830 void SAL_CALL ScCellRangeObj::applySubTotals(
5831 				const uno::Reference<sheet::XSubTotalDescriptor>& xDescriptor,
5832 				sal_Bool bReplace ) throw(uno::RuntimeException)
5833 {
5834 	ScUnoGuard aGuard;
5835 
5836 	if (!xDescriptor.is()) return;
5837 
5838 	ScDocShell* pDocSh = GetDocShell();
5839 	ScSubTotalDescriptorBase* pImp =
5840 		ScSubTotalDescriptorBase::getImplementation( xDescriptor );
5841 
5842 	if (pDocSh && pImp)
5843 	{
5844 		ScSubTotalParam aParam;
5845 		pImp->GetData(aParam);		// virtuelle Methode der Basisklasse
5846 
5847 		//	im SubTotalDescriptor sind die Fields innerhalb des Bereichs gezaehlt
5848 		SCCOL nFieldStart = aRange.aStart.Col();
5849 		for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
5850 		{
5851 			if ( aParam.bGroupActive[i] )
5852 			{
5853                 aParam.nField[i] = sal::static_int_cast<SCCOL>( aParam.nField[i] + nFieldStart );
5854 				for (SCCOL j=0; j<aParam.nSubTotals[i]; j++)
5855                     aParam.pSubTotals[i][j] = sal::static_int_cast<SCCOL>( aParam.pSubTotals[i][j] + nFieldStart );
5856 			}
5857 		}
5858 
5859 		aParam.bReplace = bReplace;
5860 
5861 		SCTAB nTab = aRange.aStart.Tab();
5862 		aParam.nCol1 = aRange.aStart.Col();
5863 		aParam.nRow1 = aRange.aStart.Row();
5864 		aParam.nCol2 = aRange.aEnd.Col();
5865 		aParam.nRow2 = aRange.aEnd.Row();
5866 
5867 		pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );	// ggf. Bereich anlegen
5868 
5869 		ScDBDocFunc aFunc(*pDocSh);
5870 		aFunc.DoSubTotals( nTab, aParam, NULL, sal_True, sal_True );	// Bereich muss angelegt sein
5871 	}
5872 }
5873 
removeSubTotals()5874 void SAL_CALL ScCellRangeObj::removeSubTotals() throw(uno::RuntimeException)
5875 {
5876 	ScUnoGuard aGuard;
5877 
5878 	ScDocShell* pDocSh = GetDocShell();
5879 	if (pDocSh)
5880 	{
5881 		ScSubTotalParam aParam;
5882 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, SC_DBSEL_FORCE_MARK );
5883 		if (pData)
5884 			pData->GetSubTotalParam(aParam);	// auch bei Remove die Feld-Eintraege behalten
5885 
5886 		aParam.bRemoveOnly = sal_True;
5887 
5888 		SCTAB nTab = aRange.aStart.Tab();
5889 		aParam.nCol1 = aRange.aStart.Col();
5890 		aParam.nRow1 = aRange.aStart.Row();
5891 		aParam.nCol2 = aRange.aEnd.Col();
5892 		aParam.nRow2 = aRange.aEnd.Row();
5893 
5894 		pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );	// ggf. Bereich anlegen
5895 
5896 		ScDBDocFunc aFunc(*pDocSh);
5897 		aFunc.DoSubTotals( nTab, aParam, NULL, sal_True, sal_True );	// Bereich muss angelegt sein
5898 	}
5899 }
5900 
createImportDescriptor(sal_Bool bEmpty)5901 uno::Sequence<beans::PropertyValue> SAL_CALL ScCellRangeObj::createImportDescriptor( sal_Bool bEmpty )
5902 												throw(uno::RuntimeException)
5903 {
5904 	ScUnoGuard aGuard;
5905 	ScImportParam aParam;
5906 	ScDocShell* pDocSh = GetDocShell();
5907 	if ( !bEmpty && pDocSh )
5908 	{
5909 		// DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich
5910 		ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, SC_DBSEL_FORCE_MARK );
5911 		if (pData)
5912 			pData->GetImportParam(aParam);
5913 	}
5914 
5915 	uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() );
5916 	ScImportDescriptor::FillProperties( aSeq, aParam );
5917 	return aSeq;
5918 }
5919 
doImport(const uno::Sequence<beans::PropertyValue> & aDescriptor)5920 void SAL_CALL ScCellRangeObj::doImport( const uno::Sequence<beans::PropertyValue>& aDescriptor )
5921 											throw(uno::RuntimeException)
5922 {
5923 	ScUnoGuard aGuard;
5924 	ScDocShell* pDocSh = GetDocShell();
5925 	if (pDocSh)
5926 	{
5927 		ScImportParam aParam;
5928 		ScImportDescriptor::FillImportParam( aParam, aDescriptor );
5929 
5930 		SCTAB nTab = aRange.aStart.Tab();
5931 		aParam.nCol1 = aRange.aStart.Col();
5932 		aParam.nRow1 = aRange.aStart.Row();
5933 		aParam.nCol2 = aRange.aEnd.Col();
5934 		aParam.nRow2 = aRange.aEnd.Row();
5935 
5936         //! TODO: could we get passed a valid result set by any means?
5937 
5938 		pDocSh->GetDBData( aRange, SC_DB_MAKE, SC_DBSEL_FORCE_MARK );		// ggf. Bereich anlegen
5939 
5940 		ScDBDocFunc aFunc(*pDocSh);							// Bereich muss angelegt sein
5941         aFunc.DoImport( nTab, aParam, NULL, sal_True );         //! Api-Flag as parameter
5942 	}
5943 }
5944 
5945 // XCellFormatRangesSupplier
5946 
getCellFormatRanges()5947 uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangeObj::getCellFormatRanges()
5948 												throw(uno::RuntimeException)
5949 {
5950 	ScUnoGuard aGuard;
5951 	ScDocShell* pDocSh = GetDocShell();
5952 	if ( pDocSh )
5953 		return new ScCellFormatsObj( pDocSh, aRange );
5954 	return NULL;
5955 }
5956 
5957 // XUniqueCellFormatRangesSupplier
5958 
getUniqueCellFormatRanges()5959 uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangeObj::getUniqueCellFormatRanges()
5960 												throw(uno::RuntimeException)
5961 {
5962 	ScUnoGuard aGuard;
5963 	ScDocShell* pDocSh = GetDocShell();
5964 	if ( pDocSh )
5965 		return new ScUniqueCellFormatsObj( pDocSh, aRange );
5966 	return NULL;
5967 }
5968 
5969 // XPropertySet erweitert fuer Range-Properties
5970 
getPropertySetInfo()5971 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangeObj::getPropertySetInfo()
5972 														throw(uno::RuntimeException)
5973 {
5974 	ScUnoGuard aGuard;
5975 	static uno::Reference<beans::XPropertySetInfo> aRef(
5976 		new SfxItemPropertySetInfo( pRangePropSet->getPropertyMap() ));
5977 	return aRef;
5978 }
5979 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)5980 void ScCellRangeObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
5981 								throw(lang::IllegalArgumentException, uno::RuntimeException)
5982 {
5983 	//	Range has only Position and Size in addition to ScCellRangesBase, both are ReadOnly
5984 	//	-> nothing to do here
5985 
5986     ScCellRangesBase::SetOnePropertyValue( pEntry, aValue );
5987 }
5988 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)5989 void ScCellRangeObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
5990 											uno::Any& rAny )
5991 												throw(uno::RuntimeException)
5992 {
5993     if ( pEntry )
5994 	{
5995         if ( pEntry->nWID == SC_WID_UNO_POS )
5996 		{
5997 			ScDocShell* pDocSh = GetDocShell();
5998 			if (pDocSh)
5999 			{
6000 				//	GetMMRect converts using HMM_PER_TWIPS, like the DrawingLayer
6001 				Rectangle aMMRect(pDocSh->GetDocument()->GetMMRect(
6002 										aRange.aStart.Col(), aRange.aStart.Row(),
6003 										aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ));
6004 				awt::Point aPos( aMMRect.Left(), aMMRect.Top() );
6005 				rAny <<= aPos;
6006 			}
6007 		}
6008         else if ( pEntry->nWID == SC_WID_UNO_SIZE )
6009 		{
6010 			ScDocShell* pDocSh = GetDocShell();
6011 			if (pDocSh)
6012 			{
6013 				//	GetMMRect converts using HMM_PER_TWIPS, like the DrawingLayer
6014 				Rectangle aMMRect = pDocSh->GetDocument()->GetMMRect(
6015 										aRange.aStart.Col(), aRange.aStart.Row(),
6016 										aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() );
6017 				Size aSize(aMMRect.GetSize());
6018 				awt::Size aAwtSize( aSize.Width(), aSize.Height() );
6019 				rAny <<= aAwtSize;
6020 			}
6021 		}
6022 		else
6023             ScCellRangesBase::GetOnePropertyValue( pEntry, rAny );
6024 
6025 	}
6026 }
6027 
GetItemPropertyMap()6028 const SfxItemPropertyMap* ScCellRangeObj::GetItemPropertyMap()
6029 {
6030     return pRangePropSet->getPropertyMap();
6031 }
6032 
6033 // XServiceInfo
6034 
getImplementationName()6035 rtl::OUString SAL_CALL ScCellRangeObj::getImplementationName() throw(uno::RuntimeException)
6036 {
6037 	return rtl::OUString::createFromAscii( "ScCellRangeObj" );
6038 }
6039 
supportsService(const rtl::OUString & rServiceName)6040 sal_Bool SAL_CALL ScCellRangeObj::supportsService( const rtl::OUString& rServiceName )
6041 													throw(uno::RuntimeException)
6042 {
6043 	String aServiceStr( rServiceName );
6044 	return aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) ||
6045 		   aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE ) ||
6046 		   aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) ||
6047 		   aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) ||
6048 		   aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE );
6049 }
6050 
getSupportedServiceNames()6051 uno::Sequence<rtl::OUString> SAL_CALL ScCellRangeObj::getSupportedServiceNames()
6052 													throw(uno::RuntimeException)
6053 {
6054 	uno::Sequence<rtl::OUString> aRet(5);
6055 	rtl::OUString* pArray = aRet.getArray();
6056 	pArray[0] = rtl::OUString::createFromAscii( SCSHEETCELLRANGE_SERVICE );
6057 	pArray[1] = rtl::OUString::createFromAscii( SCCELLRANGE_SERVICE );
6058 	pArray[2] = rtl::OUString::createFromAscii( SCCELLPROPERTIES_SERVICE );
6059 	pArray[3] = rtl::OUString::createFromAscii( SCCHARPROPERTIES_SERVICE );
6060 	pArray[4] = rtl::OUString::createFromAscii( SCPARAPROPERTIES_SERVICE );
6061 	return aRet;
6062 }
6063 
6064 //------------------------------------------------------------------------
6065 
GetEditPropertySet()6066 const SvxItemPropertySet* ScCellObj::GetEditPropertySet()      // static
6067 {
6068     return lcl_GetEditPropertySet();
6069 }
GetCellPropertyMap()6070 const SfxItemPropertyMap* ScCellObj::GetCellPropertyMap()
6071 {
6072     return lcl_GetCellPropertySet()->getPropertyMap();
6073 }
6074 
ScCellObj(ScDocShell * pDocSh,const ScAddress & rP)6075 ScCellObj::ScCellObj(ScDocShell* pDocSh, const ScAddress& rP) :
6076 	ScCellRangeObj( pDocSh, ScRange(rP,rP) ),
6077 	pUnoText( NULL ),
6078 	pCellPropSet( lcl_GetCellPropertySet() ),
6079 	aCellPos( rP ),
6080 	nActionLockCount( 0 )
6081 {
6082 	//	pUnoText is allocated on demand (GetUnoText)
6083 	//	can't be aggregated because getString/setString is handled here
6084 }
6085 
GetUnoText()6086 SvxUnoText&	ScCellObj::GetUnoText()
6087 {
6088 	if (!pUnoText)
6089 	{
6090 		pUnoText = new ScCellTextObj( GetDocShell(), aCellPos );
6091 		pUnoText->acquire();
6092 		if (nActionLockCount)
6093 		{
6094 			ScSharedCellEditSource* pEditSource =
6095 				static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource());
6096 			if (pEditSource)
6097 				pEditSource->SetDoUpdateData(sal_False);
6098 		}
6099 	}
6100 	return *pUnoText;
6101 }
6102 
~ScCellObj()6103 ScCellObj::~ScCellObj()
6104 {
6105 	if (pUnoText)
6106 		pUnoText->release();
6107 }
6108 
RefChanged()6109 void ScCellObj::RefChanged()
6110 {
6111 	ScCellRangeObj::RefChanged();
6112 
6113 	const ScRangeList& rRanges = GetRangeList();
6114 	DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!");
6115 	const ScRange* pFirst = rRanges.GetObject(0);
6116 	if (pFirst)
6117 		aCellPos = pFirst->aStart;
6118 }
6119 
queryInterface(const uno::Type & rType)6120 uno::Any SAL_CALL ScCellObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
6121 {
6122 	SC_QUERYINTERFACE( table::XCell )
6123     SC_QUERYINTERFACE( sheet::XFormulaTokens )
6124 	SC_QUERYINTERFACE( sheet::XCellAddressable )
6125 	SC_QUERYINTERFACE( text::XText )
6126 	SC_QUERYINTERFACE( text::XSimpleText )
6127 	SC_QUERYINTERFACE( text::XTextRange )
6128 	SC_QUERYINTERFACE( container::XEnumerationAccess )
6129 	SC_QUERYINTERFACE( container::XElementAccess )
6130 	SC_QUERYINTERFACE( sheet::XSheetAnnotationAnchor )
6131 	SC_QUERYINTERFACE( text::XTextFieldsSupplier )
6132 	SC_QUERYINTERFACE( document::XActionLockable )
6133 
6134 	return ScCellRangeObj::queryInterface( rType );
6135 }
6136 
acquire()6137 void SAL_CALL ScCellObj::acquire() throw()
6138 {
6139 	ScCellRangeObj::acquire();
6140 }
6141 
release()6142 void SAL_CALL ScCellObj::release() throw()
6143 {
6144 	ScCellRangeObj::release();
6145 }
6146 
getTypes()6147 uno::Sequence<uno::Type> SAL_CALL ScCellObj::getTypes() throw(uno::RuntimeException)
6148 {
6149 	static uno::Sequence<uno::Type> aTypes;
6150 	if ( aTypes.getLength() == 0 )
6151 	{
6152 		uno::Sequence<uno::Type> aParentTypes(ScCellRangeObj::getTypes());
6153 		long nParentLen = aParentTypes.getLength();
6154 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
6155 
6156 		aTypes.realloc( nParentLen + 8 );
6157 		uno::Type* pPtr = aTypes.getArray();
6158 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<table::XCell>*)0);
6159 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XCellAddressable>*)0);
6160 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<text::XText>*)0);
6161 		pPtr[nParentLen + 3] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0);
6162 		pPtr[nParentLen + 4] = getCppuType((const uno::Reference<sheet::XSheetAnnotationAnchor>*)0);
6163 		pPtr[nParentLen + 5] = getCppuType((const uno::Reference<text::XTextFieldsSupplier>*)0);
6164 		pPtr[nParentLen + 6] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
6165 		pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XFormulaTokens>*)0);
6166 
6167 		for (long i=0; i<nParentLen; i++)
6168 			pPtr[i] = pParentPtr[i];				// parent types first
6169 	}
6170 	return aTypes;
6171 }
6172 
getImplementationId()6173 uno::Sequence<sal_Int8> SAL_CALL ScCellObj::getImplementationId() throw(uno::RuntimeException)
6174 {
6175 	static uno::Sequence< sal_Int8 > aId;
6176 	if( aId.getLength() == 0 )
6177 	{
6178 		aId.realloc( 16 );
6179 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
6180 	}
6181 	return aId;
6182 }
6183 
6184 //	Hilfsfunktionen
6185 
GetInputString_Impl(sal_Bool bEnglish) const6186 String ScCellObj::GetInputString_Impl(sal_Bool bEnglish) const		// fuer getFormula / FormulaLocal
6187 {
6188     if (GetDocShell())
6189 	    return lcl_GetInputString( GetDocShell()->GetDocument(), aCellPos, bEnglish );
6190     return String();
6191 }
6192 
GetOutputString_Impl(ScDocument * pDoc,const ScAddress & aCellPos)6193 String ScCellObj::GetOutputString_Impl(ScDocument* pDoc, const ScAddress& aCellPos)
6194 {
6195 	String aVal;
6196 	if ( pDoc )
6197 	{
6198 		ScBaseCell* pCell = pDoc->GetCell( aCellPos );
6199 		if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE )
6200 		{
6201 			if ( pCell->GetCellType() == CELLTYPE_EDIT )
6202 			{
6203 				//	GetString an der EditCell macht Leerzeichen aus Umbruechen,
6204 				//	hier werden die Umbrueche aber gebraucht
6205 				const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
6206 				if (pData)
6207 				{
6208 					EditEngine& rEngine = pDoc->GetEditEngine();
6209 					rEngine.SetText( *pData );
6210 					aVal = rEngine.GetText( LINEEND_LF );
6211 				}
6212 				//	Edit-Zellen auch nicht per NumberFormatter formatieren
6213 				//	(passend zur Ausgabe)
6214 			}
6215 			else
6216 			{
6217 				//	wie in GetString am Dokument (column)
6218 				Color* pColor;
6219 				sal_uLong nNumFmt = pDoc->GetNumberFormat( aCellPos );
6220 				ScCellFormat::GetString( pCell, nNumFmt, aVal, &pColor, *pDoc->GetFormatTable() );
6221 			}
6222 		}
6223 	}
6224 	return aVal;
6225 }
6226 
GetOutputString_Impl() const6227 String ScCellObj::GetOutputString_Impl() const
6228 {
6229 	ScDocShell* pDocSh = GetDocShell();
6230 	String aVal;
6231 	if ( pDocSh )
6232         aVal = GetOutputString_Impl(pDocSh->GetDocument(), aCellPos);
6233     return aVal;
6234 }
6235 
SetString_Impl(const String & rString,sal_Bool bInterpret,sal_Bool bEnglish)6236 void ScCellObj::SetString_Impl(const String& rString, sal_Bool bInterpret, sal_Bool bEnglish)
6237 {
6238 	ScDocShell* pDocSh = GetDocShell();
6239 	if ( pDocSh )
6240 	{
6241 		ScDocFunc aFunc(*pDocSh);
6242         // GRAM_PODF_A1 for API compatibility.
6243         (void)aFunc.SetCellText( aCellPos, rString, bInterpret, bEnglish, sal_True, EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1 );
6244 	}
6245 }
6246 
GetValue_Impl() const6247 double ScCellObj::GetValue_Impl() const
6248 {
6249 	ScDocShell* pDocSh = GetDocShell();
6250 	if ( pDocSh )
6251 		return pDocSh->GetDocument()->GetValue( aCellPos );
6252 
6253 	return 0.0;
6254 }
6255 
SetValue_Impl(double fValue)6256 void ScCellObj::SetValue_Impl(double fValue)
6257 {
6258 	ScDocShell* pDocSh = GetDocShell();
6259 	if ( pDocSh )
6260 	{
6261 		ScDocFunc aFunc(*pDocSh);
6262 		(void)aFunc.PutCell( aCellPos, new ScValueCell(fValue), sal_True );
6263 	}
6264 }
6265 
6266 // only for XML import
6267 
SetFormulaResultString(const::rtl::OUString & rResult)6268 void ScCellObj::SetFormulaResultString( const ::rtl::OUString& rResult )
6269 {
6270 	ScDocShell* pDocSh = GetDocShell();
6271 	if ( pDocSh )
6272 	{
6273 		ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos );
6274 		if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
6275 			((ScFormulaCell*)pCell)->SetHybridString( rResult );
6276 	}
6277 }
6278 
SetFormulaResultDouble(double fResult)6279 void ScCellObj::SetFormulaResultDouble( double fResult )
6280 {
6281 	ScDocShell* pDocSh = GetDocShell();
6282 	if ( pDocSh )
6283 	{
6284 		ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos );
6285 		if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
6286 			((ScFormulaCell*)pCell)->SetHybridDouble( fResult );
6287 	}
6288 }
6289 
SetFormulaWithGrammar(const::rtl::OUString & rFormula,const::rtl::OUString & rFormulaNmsp,const formula::FormulaGrammar::Grammar eGrammar)6290 void ScCellObj::SetFormulaWithGrammar( const ::rtl::OUString& rFormula,
6291         const ::rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar )
6292 {
6293     ScDocShell* pDocSh = GetDocShell();
6294     if ( pDocSh )
6295     {
6296         ScDocFunc aFunc(*pDocSh);
6297         aFunc.SetCellText( aCellPos, rFormula, sal_True, sal_True, sal_True, rFormulaNmsp, eGrammar);
6298     }
6299 }
6300 
InputEnglishString(const::rtl::OUString & rText)6301 void ScCellObj::InputEnglishString( const ::rtl::OUString& rText )
6302 {
6303     // This is like a mixture of setFormula and property FormulaLocal:
6304     // The cell's number format is checked for "text", a new cell format may be set,
6305     // but all parsing is in English.
6306 
6307     ScDocShell* pDocSh = GetDocShell();
6308     if ( pDocSh )
6309     {
6310         String aString(rText);
6311         ScDocument* pDoc = pDocSh->GetDocument();
6312         SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
6313         sal_uInt32 nOldFormat = pDoc->GetNumberFormat( aCellPos );
6314         if ( pFormatter->GetType( nOldFormat ) == NUMBERFORMAT_TEXT )
6315         {
6316             SetString_Impl(aString, sal_False, sal_False);      // text cell
6317         }
6318         else
6319         {
6320             ScDocFunc aFunc(*pDocSh);
6321             short nFormatType = 0;
6322             ScBaseCell* pNewCell = aFunc.InterpretEnglishString( aCellPos, aString,
6323                                     EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1, &nFormatType );
6324             if (pNewCell)
6325             {
6326                 if ( ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 && nFormatType != 0 )
6327                 {
6328                     // apply a format for the recognized type and the old format's language
6329                     sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat( *pFormatter, nOldFormat, nFormatType );
6330                     if ( nNewFormat != nOldFormat )
6331                     {
6332                         ScPatternAttr aPattern( pDoc->GetPool() );
6333                         aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
6334                         // ATTR_LANGUAGE_FORMAT remains unchanged
6335                         aFunc.ApplyAttributes( *GetMarkData(), aPattern, sal_True, sal_True );
6336                     }
6337                 }
6338                 // put the cell into the document
6339                 // (after applying the format, so possible formula recalculation already uses the new format)
6340                 (void)aFunc.PutCell( aCellPos, pNewCell, sal_True );
6341             }
6342             else
6343                 SetString_Impl(aString, sal_False, sal_False);      // no cell from InterpretEnglishString, probably empty string
6344         }
6345     }
6346 }
6347 
6348 //	XText
6349 
createTextCursor()6350 uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursor()
6351 													throw(uno::RuntimeException)
6352 {
6353 	ScUnoGuard aGuard;
6354 	return new ScCellTextCursor( *this );
6355 }
6356 
createTextCursorByRange(const uno::Reference<text::XTextRange> & aTextPosition)6357 uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursorByRange(
6358 									const uno::Reference<text::XTextRange>& aTextPosition )
6359 													throw(uno::RuntimeException)
6360 {
6361 	ScUnoGuard aGuard;
6362 	SvxUnoTextCursor* pCursor = new ScCellTextCursor( *this );
6363 	uno::Reference<text::XTextCursor> xCursor(pCursor);
6364 
6365 	SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
6366 	if(pRange)
6367 		pCursor->SetSelection( pRange->GetSelection() );
6368 	else
6369 	{
6370 		ScCellTextCursor* pOther = ScCellTextCursor::getImplementation( aTextPosition );
6371 		if(pOther)
6372 			pCursor->SetSelection( pOther->GetSelection() );
6373 		else
6374 			throw uno::RuntimeException();
6375 	}
6376 
6377 	return xCursor;
6378 }
6379 
getString()6380 rtl::OUString SAL_CALL ScCellObj::getString() throw(uno::RuntimeException)
6381 {
6382 	ScUnoGuard aGuard;
6383 	return GetOutputString_Impl();
6384 }
6385 
setString(const rtl::OUString & aText)6386 void SAL_CALL ScCellObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException)
6387 {
6388 	ScUnoGuard aGuard;
6389 	String aString(aText);
6390 	SetString_Impl(aString, sal_False, sal_False);	// immer Text
6391 
6392 	// don't create pUnoText here if not there
6393 	if (pUnoText)
6394 		pUnoText->SetSelection(ESelection( 0,0, 0,aString.Len() ));
6395 }
6396 
insertString(const uno::Reference<text::XTextRange> & xRange,const rtl::OUString & aString,sal_Bool bAbsorb)6397 void SAL_CALL ScCellObj::insertString( const uno::Reference<text::XTextRange>& xRange,
6398 										const rtl::OUString& aString, sal_Bool bAbsorb )
6399 									throw(uno::RuntimeException)
6400 {
6401 	// special handling for ScCellTextCursor is no longer needed,
6402 	// SvxUnoText::insertString checks for SvxUnoTextRangeBase instead of SvxUnoTextRange
6403 
6404 	ScUnoGuard aGuard;
6405 	GetUnoText().insertString(xRange, aString, bAbsorb);
6406 }
6407 
insertControlCharacter(const uno::Reference<text::XTextRange> & xRange,sal_Int16 nControlCharacter,sal_Bool bAbsorb)6408 void SAL_CALL ScCellObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
6409 												sal_Int16 nControlCharacter, sal_Bool bAbsorb )
6410 									throw(lang::IllegalArgumentException, uno::RuntimeException)
6411 {
6412 	ScUnoGuard aGuard;
6413 	GetUnoText().insertControlCharacter(xRange, nControlCharacter, bAbsorb);
6414 }
6415 
insertTextContent(const uno::Reference<text::XTextRange> & xRange,const uno::Reference<text::XTextContent> & xContent,sal_Bool bAbsorb)6416 void SAL_CALL ScCellObj::insertTextContent( const uno::Reference<text::XTextRange >& xRange,
6417 												const uno::Reference<text::XTextContent >& xContent,
6418 												sal_Bool bAbsorb )
6419 									throw(lang::IllegalArgumentException, uno::RuntimeException)
6420 {
6421 	ScUnoGuard aGuard;
6422 	ScDocShell* pDocSh = GetDocShell();
6423 	if ( pDocSh && xContent.is() )
6424 	{
6425 		ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent );
6426 		SvxUnoTextRangeBase* pTextRange = ScCellTextCursor::getImplementation( xRange );
6427 
6428 #if 0
6429 		if (!pTextRange)
6430 			pTextRange = SvxUnoTextRangeBase::getImplementation( xRange );
6431 
6432 		//!	bei SvxUnoTextRange testen, ob in passendem Objekt !!!
6433 #endif
6434 
6435 		if ( pCellField && !pCellField->IsInserted() && pTextRange )
6436 		{
6437 			SvxEditSource* pEditSource = pTextRange->GetEditSource();
6438 			ESelection aSelection(pTextRange->GetSelection());
6439 
6440 			if (!bAbsorb)
6441 			{
6442 				//	nicht ersetzen -> hinten anhaengen
6443 				aSelection.Adjust();
6444 				aSelection.nStartPara = aSelection.nEndPara;
6445 				aSelection.nStartPos  = aSelection.nEndPos;
6446 			}
6447 
6448 			SvxFieldItem aItem(pCellField->CreateFieldItem());
6449 
6450 			SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
6451 			pForwarder->QuickInsertField( aItem, aSelection );
6452 			pEditSource->UpdateData();
6453 
6454 			//	neue Selektion: ein Zeichen
6455 			aSelection.Adjust();
6456 			aSelection.nEndPara = aSelection.nStartPara;
6457 			aSelection.nEndPos = aSelection.nStartPos + 1;
6458 			pCellField->InitDoc( pDocSh, aCellPos, aSelection );
6459 
6460 			//	#91431# for bAbsorb=sal_False, the new selection must be behind the inserted content
6461 			//	(the xml filter relies on this)
6462 			if (!bAbsorb)
6463 				aSelection.nStartPos = aSelection.nEndPos;
6464 
6465 			pTextRange->SetSelection( aSelection );
6466 
6467 			return;
6468 		}
6469 	}
6470 	GetUnoText().insertTextContent(xRange, xContent, bAbsorb);
6471 }
6472 
removeTextContent(const uno::Reference<text::XTextContent> & xContent)6473 void SAL_CALL ScCellObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent )
6474 								throw(container::NoSuchElementException, uno::RuntimeException)
6475 {
6476 	ScUnoGuard aGuard;
6477 	if ( xContent.is() )
6478 	{
6479 		ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent );
6480 		if ( pCellField && pCellField->IsInserted() )
6481 		{
6482 			//!	Testen, ob das Feld in dieser Zelle ist
6483 			pCellField->DeleteField();
6484 			return;
6485 		}
6486 	}
6487 	GetUnoText().removeTextContent(xContent);
6488 }
6489 
getText()6490 uno::Reference<text::XText> SAL_CALL ScCellObj::getText() throw(uno::RuntimeException)
6491 {
6492 	ScUnoGuard aGuard;
6493 	return this;
6494 }
6495 
getStart()6496 uno::Reference<text::XTextRange> SAL_CALL ScCellObj::getStart() throw(uno::RuntimeException)
6497 {
6498 	ScUnoGuard aGuard;
6499 	return GetUnoText().getStart();
6500 }
6501 
getEnd()6502 uno::Reference<text::XTextRange> SAL_CALL ScCellObj::getEnd() throw(uno::RuntimeException)
6503 {
6504 	ScUnoGuard aGuard;
6505 	return GetUnoText().getEnd();
6506 }
6507 
createEnumeration()6508 uno::Reference<container::XEnumeration> SAL_CALL ScCellObj::createEnumeration()
6509 													throw(uno::RuntimeException)
6510 {
6511 	ScUnoGuard aGuard;
6512 	return GetUnoText().createEnumeration();
6513 }
6514 
getElementType()6515 uno::Type SAL_CALL ScCellObj::getElementType() throw(uno::RuntimeException)
6516 {
6517 	ScUnoGuard aGuard;
6518 	return GetUnoText().getElementType();
6519 }
6520 
hasElements()6521 sal_Bool SAL_CALL ScCellObj::hasElements() throw(uno::RuntimeException)
6522 {
6523 	ScUnoGuard aGuard;
6524 	return GetUnoText().hasElements();
6525 }
6526 
6527 //	XCell
6528 
getFormula()6529 rtl::OUString SAL_CALL ScCellObj::getFormula() throw(uno::RuntimeException)
6530 {
6531 	ScUnoGuard aGuard;
6532 	//	sal_True = englisch
6533 	return GetInputString_Impl(sal_True);
6534 }
6535 
setFormula(const rtl::OUString & aFormula)6536 void SAL_CALL ScCellObj::setFormula( const rtl::OUString& aFormula ) throw(uno::RuntimeException)
6537 {
6538 	ScUnoGuard aGuard;
6539 	String aString(aFormula);
6540 	SetString_Impl(aString, sal_True, sal_True);	// englisch interpretieren
6541 }
6542 
getValue()6543 double SAL_CALL ScCellObj::getValue() throw(uno::RuntimeException)
6544 {
6545 	ScUnoGuard aGuard;
6546 	return GetValue_Impl();
6547 }
6548 
setValue(double nValue)6549 void SAL_CALL ScCellObj::setValue( double nValue ) throw(uno::RuntimeException)
6550 {
6551 	ScUnoGuard aGuard;
6552 	SetValue_Impl(nValue);
6553 }
6554 
getType()6555 table::CellContentType SAL_CALL ScCellObj::getType() throw(uno::RuntimeException)
6556 {
6557 	ScUnoGuard aGuard;
6558 	table::CellContentType eRet = table::CellContentType_EMPTY;
6559 	ScDocShell* pDocSh = GetDocShell();
6560 	if (pDocSh)
6561 	{
6562 		CellType eCalcType = pDocSh->GetDocument()->GetCellType( aCellPos );
6563 		switch (eCalcType)
6564 		{
6565 			case CELLTYPE_VALUE:
6566 				eRet = table::CellContentType_VALUE;
6567 				break;
6568 			case CELLTYPE_STRING:
6569 			case CELLTYPE_EDIT:
6570 				eRet = table::CellContentType_TEXT;
6571 				break;
6572 			case CELLTYPE_FORMULA:
6573 				eRet = table::CellContentType_FORMULA;
6574 				break;
6575 			default:
6576 				eRet = table::CellContentType_EMPTY;
6577 		}
6578 	}
6579 	else
6580 	{
6581 		DBG_ERROR("keine DocShell");		//! Exception oder so?
6582 	}
6583 
6584 	return eRet;
6585 }
6586 
GetResultType_Impl()6587 table::CellContentType ScCellObj::GetResultType_Impl()
6588 {
6589 	ScDocShell* pDocSh = GetDocShell();
6590 	if ( pDocSh )
6591 	{
6592 		ScBaseCell* pCell = pDocSh->GetDocument()->GetCell(aCellPos);
6593 		if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
6594 		{
6595 			sal_Bool bValue = ((ScFormulaCell*)pCell)->IsValue();
6596 			return bValue ? table::CellContentType_VALUE : table::CellContentType_TEXT;
6597 		}
6598 	}
6599 	return getType();	// wenn keine Formel
6600 }
6601 
getError()6602 sal_Int32 SAL_CALL ScCellObj::getError() throw(uno::RuntimeException)
6603 {
6604 	ScUnoGuard aGuard;
6605 	sal_uInt16 nError = 0;
6606 	ScDocShell* pDocSh = GetDocShell();
6607 	if (pDocSh)
6608 	{
6609 		ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos );
6610 		if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
6611 			nError = ((ScFormulaCell*)pCell)->GetErrCode();
6612 		// sonst bleibt's bei 0
6613 	}
6614 	else
6615 	{
6616 		DBG_ERROR("keine DocShell");		//! Exception oder so?
6617 	}
6618 
6619 	return nError;
6620 }
6621 
6622 // XFormulaTokens
6623 
getTokens()6624 uno::Sequence<sheet::FormulaToken> SAL_CALL ScCellObj::getTokens() throw(uno::RuntimeException)
6625 {
6626 	ScUnoGuard aGuard;
6627     uno::Sequence<sheet::FormulaToken> aSequence;
6628     ScDocShell* pDocSh = GetDocShell();
6629     if ( pDocSh )
6630 	{
6631         ScDocument* pDoc = pDocSh->GetDocument();
6632         ScBaseCell* pCell = pDoc->GetCell( aCellPos );
6633         if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
6634         {
6635             ScTokenArray* pTokenArray = static_cast<ScFormulaCell*>(pCell)->GetCode();
6636             if ( pTokenArray )
6637                 (void)ScTokenConversion::ConvertToTokenSequence( *pDoc, aSequence, *pTokenArray );
6638         }
6639 	}
6640     return aSequence;
6641 }
6642 
setTokens(const uno::Sequence<sheet::FormulaToken> & rTokens)6643 void SAL_CALL ScCellObj::setTokens( const uno::Sequence<sheet::FormulaToken>& rTokens ) throw(uno::RuntimeException)
6644 {
6645 	ScUnoGuard aGuard;
6646     ScDocShell* pDocSh = GetDocShell();
6647     if ( pDocSh )
6648 	{
6649 	    ScDocument* pDoc = pDocSh->GetDocument();
6650 	    ScTokenArray aTokenArray;
6651         (void)ScTokenConversion::ConvertToTokenArray( *pDoc, aTokenArray, rTokens );
6652 
6653         ScDocFunc aFunc( *pDocSh );
6654         ScBaseCell* pNewCell = new ScFormulaCell( pDoc, aCellPos, &aTokenArray );
6655         (void)aFunc.PutCell( aCellPos, pNewCell, sal_True );
6656 	}
6657 }
6658 
6659 // XCellAddressable
6660 
getCellAddress()6661 table::CellAddress SAL_CALL ScCellObj::getCellAddress() throw(uno::RuntimeException)
6662 {
6663 	ScUnoGuard aGuard;
6664 	table::CellAddress aAdr;
6665 	aAdr.Sheet	= aCellPos.Tab();
6666 	aAdr.Column	= aCellPos.Col();
6667 	aAdr.Row	= aCellPos.Row();
6668 	return aAdr;
6669 }
6670 
6671 // XSheetAnnotationAnchor
6672 
getAnnotation()6673 uno::Reference<sheet::XSheetAnnotation> SAL_CALL ScCellObj::getAnnotation()
6674 												throw(uno::RuntimeException)
6675 {
6676 	ScUnoGuard aGuard;
6677 	ScDocShell* pDocSh = GetDocShell();
6678 	if ( pDocSh )
6679 		return new ScAnnotationObj( pDocSh, aCellPos );
6680 
6681 	DBG_ERROR("getAnnotation ohne DocShell");
6682 	return NULL;
6683 }
6684 
6685 // XFieldTypesSupplier
6686 
getTextFields()6687 uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellObj::getTextFields()
6688 												throw(uno::RuntimeException)
6689 {
6690 	ScUnoGuard aGuard;
6691 	ScDocShell* pDocSh = GetDocShell();
6692 	if ( pDocSh )
6693 		return new ScCellFieldsObj( pDocSh, aCellPos );
6694 
6695 	return NULL;
6696 }
6697 
getTextFieldMasters()6698 uno::Reference<container::XNameAccess> SAL_CALL ScCellObj::getTextFieldMasters()
6699 												throw(uno::RuntimeException)
6700 {
6701 	//	sowas gibts nicht im Calc (?)
6702 	return NULL;
6703 }
6704 
6705 // XPropertySet erweitert fuer Zell-Properties
6706 
getPropertySetInfo()6707 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellObj::getPropertySetInfo()
6708 														throw(uno::RuntimeException)
6709 {
6710 	ScUnoGuard aGuard;
6711 	static uno::Reference<beans::XPropertySetInfo> aRef(
6712 		new SfxItemPropertySetInfo( pCellPropSet->getPropertyMap() ));
6713 	return aRef;
6714 }
6715 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)6716 void ScCellObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
6717 								throw(lang::IllegalArgumentException, uno::RuntimeException)
6718 {
6719     if ( pEntry )
6720 	{
6721         if ( pEntry->nWID == SC_WID_UNO_FORMLOC )
6722 		{
6723 			rtl::OUString aStrVal;
6724 			aValue >>= aStrVal;
6725 			String aString(aStrVal);
6726 			SetString_Impl(aString, sal_True, sal_False);	// lokal interpretieren
6727 		}
6728         else if ( pEntry->nWID == SC_WID_UNO_FORMRT )
6729 		{
6730 			//	Read-Only
6731 			//!	Exception oder so...
6732 		}
6733 		else
6734             ScCellRangeObj::SetOnePropertyValue( pEntry, aValue );
6735 	}
6736 }
6737 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)6738 void ScCellObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
6739 										uno::Any& rAny )
6740 											throw(uno::RuntimeException)
6741 {
6742     if ( pEntry )
6743 	{
6744         if ( pEntry->nWID == SC_WID_UNO_FORMLOC )
6745 		{
6746 			// sal_False = lokal
6747 			rAny <<= rtl::OUString( GetInputString_Impl(sal_False) );
6748 		}
6749         else if ( pEntry->nWID == SC_WID_UNO_FORMRT )
6750 		{
6751 			table::CellContentType eType = GetResultType_Impl();
6752 			rAny <<= eType;
6753 		}
6754 		else
6755             ScCellRangeObj::GetOnePropertyValue(pEntry, rAny);
6756 	}
6757 }
6758 
GetItemPropertyMap()6759 const SfxItemPropertyMap* ScCellObj::GetItemPropertyMap()
6760 {
6761     return pCellPropSet->getPropertyMap();
6762 }
6763 
6764 // XServiceInfo
6765 
getImplementationName()6766 rtl::OUString SAL_CALL ScCellObj::getImplementationName() throw(uno::RuntimeException)
6767 {
6768 	return rtl::OUString::createFromAscii( "ScCellObj" );
6769 }
6770 
supportsService(const rtl::OUString & rServiceName)6771 sal_Bool SAL_CALL ScCellObj::supportsService( const rtl::OUString& rServiceName )
6772 													throw(uno::RuntimeException)
6773 {
6774 	//	CellRange/SheetCellRange are not in SheetCell service description,
6775 	//	but ScCellObj is used instead of ScCellRangeObj in CellRanges collections,
6776 	//	so it must support them
6777 
6778 	String aServiceStr(rServiceName);
6779 	return aServiceStr.EqualsAscii( SCSHEETCELL_SERVICE ) ||
6780 		   aServiceStr.EqualsAscii( SCCELL_SERVICE ) ||
6781 		   aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) ||
6782 		   aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) ||
6783 		   aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ) ||
6784 		   aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) ||
6785 		   aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE );
6786 }
6787 
getSupportedServiceNames()6788 uno::Sequence<rtl::OUString> SAL_CALL ScCellObj::getSupportedServiceNames()
6789 													throw(uno::RuntimeException)
6790 {
6791 	uno::Sequence<rtl::OUString> aRet(7);
6792 	rtl::OUString* pArray = aRet.getArray();
6793 	pArray[0] = rtl::OUString::createFromAscii( SCSHEETCELL_SERVICE );
6794 	pArray[1] = rtl::OUString::createFromAscii( SCCELL_SERVICE );
6795 	pArray[2] = rtl::OUString::createFromAscii( SCCELLPROPERTIES_SERVICE );
6796 	pArray[3] = rtl::OUString::createFromAscii( SCCHARPROPERTIES_SERVICE );
6797 	pArray[4] = rtl::OUString::createFromAscii( SCPARAPROPERTIES_SERVICE );
6798 	pArray[5] = rtl::OUString::createFromAscii( SCSHEETCELLRANGE_SERVICE );
6799 	pArray[6] = rtl::OUString::createFromAscii( SCCELLRANGE_SERVICE );
6800 	return aRet;
6801 }
6802 
6803 // XActionLockable
6804 
isActionLocked()6805 sal_Bool SAL_CALL ScCellObj::isActionLocked() throw(uno::RuntimeException)
6806 {
6807 	ScUnoGuard aGuard;
6808 	return nActionLockCount != 0;
6809 }
6810 
addActionLock()6811 void SAL_CALL ScCellObj::addActionLock() throw(uno::RuntimeException)
6812 {
6813 	ScUnoGuard aGuard;
6814 	if (!nActionLockCount)
6815 	{
6816 		if (pUnoText)
6817 		{
6818 			ScSharedCellEditSource* pEditSource =
6819 				static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource());
6820 			if (pEditSource)
6821 				pEditSource->SetDoUpdateData(sal_False);
6822 		}
6823 	}
6824 	nActionLockCount++;
6825 }
6826 
removeActionLock()6827 void SAL_CALL ScCellObj::removeActionLock() throw(uno::RuntimeException)
6828 {
6829 	ScUnoGuard aGuard;
6830 	if (nActionLockCount > 0)
6831 	{
6832 		nActionLockCount--;
6833 		if (!nActionLockCount)
6834 		{
6835 			if (pUnoText)
6836 			{
6837 				ScSharedCellEditSource* pEditSource =
6838 					static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource());
6839 				if (pEditSource)
6840 				{
6841 					pEditSource->SetDoUpdateData(sal_True);
6842 					if (pEditSource->IsDirty())
6843 						pEditSource->UpdateData();
6844 				}
6845 			}
6846 		}
6847 	}
6848 }
6849 
setActionLocks(sal_Int16 nLock)6850 void SAL_CALL ScCellObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
6851 {
6852 	ScUnoGuard aGuard;
6853 	if (pUnoText)
6854 	{
6855 		ScSharedCellEditSource* pEditSource =
6856 			static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource());
6857 		if (pEditSource)
6858 		{
6859 			pEditSource->SetDoUpdateData(nLock == 0);
6860 			if ((nActionLockCount > 0) && (nLock == 0) && pEditSource->IsDirty())
6861 				pEditSource->UpdateData();
6862 		}
6863 	}
6864 	nActionLockCount = nLock;
6865 }
6866 
resetActionLocks()6867 sal_Int16 SAL_CALL ScCellObj::resetActionLocks() throw(uno::RuntimeException)
6868 {
6869 	ScUnoGuard aGuard;
6870 	sal_uInt16 nRet(nActionLockCount);
6871 	if (pUnoText)
6872 	{
6873 		ScSharedCellEditSource* pEditSource =
6874 			static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource());
6875 		if (pEditSource)
6876 		{
6877 			pEditSource->SetDoUpdateData(sal_True);
6878 			if (pEditSource->IsDirty())
6879 				pEditSource->UpdateData();
6880 		}
6881 	}
6882 	nActionLockCount = 0;
6883 	return nRet;
6884 }
6885 
6886 //------------------------------------------------------------------------
6887 
ScTableSheetObj(ScDocShell * pDocSh,SCTAB nTab)6888 ScTableSheetObj::ScTableSheetObj( ScDocShell* pDocSh, SCTAB nTab ) :
6889 	ScCellRangeObj( pDocSh, ScRange(0,0,nTab, MAXCOL,MAXROW,nTab) ),
6890 	pSheetPropSet(lcl_GetSheetPropertySet())
6891 {
6892 }
6893 
~ScTableSheetObj()6894 ScTableSheetObj::~ScTableSheetObj()
6895 {
6896 }
6897 
InitInsertSheet(ScDocShell * pDocSh,SCTAB nTab)6898 void ScTableSheetObj::InitInsertSheet(ScDocShell* pDocSh, SCTAB nTab)
6899 {
6900 	InitInsertRange( pDocSh, ScRange(0,0,nTab, MAXCOL,MAXROW,nTab) );
6901 }
6902 
queryInterface(const uno::Type & rType)6903 uno::Any SAL_CALL ScTableSheetObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
6904 {
6905 	SC_QUERYINTERFACE( sheet::XSpreadsheet )
6906 	SC_QUERYINTERFACE( container::XNamed )
6907 	SC_QUERYINTERFACE( sheet::XSheetPageBreak )
6908 	SC_QUERYINTERFACE( sheet::XCellRangeMovement )
6909 	SC_QUERYINTERFACE( table::XTableChartsSupplier )
6910 	SC_QUERYINTERFACE( sheet::XDataPilotTablesSupplier )
6911 	SC_QUERYINTERFACE( sheet::XScenariosSupplier )
6912 	SC_QUERYINTERFACE( sheet::XSheetAnnotationsSupplier )
6913 	SC_QUERYINTERFACE( drawing::XDrawPageSupplier )
6914 	SC_QUERYINTERFACE( sheet::XPrintAreas )
6915 	SC_QUERYINTERFACE( sheet::XSheetAuditing )
6916 	SC_QUERYINTERFACE( sheet::XSheetOutline )
6917 	SC_QUERYINTERFACE( util::XProtectable )
6918 	SC_QUERYINTERFACE( sheet::XScenario )
6919 	SC_QUERYINTERFACE( sheet::XScenarioEnhanced )
6920 	SC_QUERYINTERFACE( sheet::XSheetLinkable )
6921     SC_QUERYINTERFACE( sheet::XExternalSheetName )
6922     SC_QUERYINTERFACE( document::XEventsSupplier )
6923 
6924 	return ScCellRangeObj::queryInterface( rType );
6925 }
6926 
acquire()6927 void SAL_CALL ScTableSheetObj::acquire() throw()
6928 {
6929 	ScCellRangeObj::acquire();
6930 }
6931 
release()6932 void SAL_CALL ScTableSheetObj::release() throw()
6933 {
6934 	ScCellRangeObj::release();
6935 }
6936 
getTypes()6937 uno::Sequence<uno::Type> SAL_CALL ScTableSheetObj::getTypes() throw(uno::RuntimeException)
6938 {
6939 	static uno::Sequence<uno::Type> aTypes;
6940 	if ( aTypes.getLength() == 0 )
6941 	{
6942 		uno::Sequence<uno::Type> aParentTypes = ScCellRangeObj::getTypes();
6943 		long nParentLen = aParentTypes.getLength();
6944 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
6945 
6946 		aTypes.realloc( nParentLen + 18 );
6947 		uno::Type* pPtr = aTypes.getArray();
6948 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheet>*)0);
6949 		pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XNamed>*)0);
6950 		pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XSheetPageBreak>*)0);
6951 		pPtr[nParentLen + 3] = getCppuType((const uno::Reference<sheet::XCellRangeMovement>*)0);
6952 		pPtr[nParentLen + 4] = getCppuType((const uno::Reference<table::XTableChartsSupplier>*)0);
6953 		pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XDataPilotTablesSupplier>*)0);
6954 		pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XScenariosSupplier>*)0);
6955 		pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XSheetAnnotationsSupplier>*)0);
6956 		pPtr[nParentLen + 8] = getCppuType((const uno::Reference<drawing::XDrawPageSupplier>*)0);
6957 		pPtr[nParentLen + 9] = getCppuType((const uno::Reference<sheet::XPrintAreas>*)0);
6958 		pPtr[nParentLen +10] = getCppuType((const uno::Reference<sheet::XSheetAuditing>*)0);
6959 		pPtr[nParentLen +11] = getCppuType((const uno::Reference<sheet::XSheetOutline>*)0);
6960 		pPtr[nParentLen +12] = getCppuType((const uno::Reference<util::XProtectable>*)0);
6961 		pPtr[nParentLen +13] = getCppuType((const uno::Reference<sheet::XScenario>*)0);
6962 		pPtr[nParentLen +14] = getCppuType((const uno::Reference<sheet::XScenarioEnhanced>*)0);
6963 		pPtr[nParentLen +15] = getCppuType((const uno::Reference<sheet::XSheetLinkable>*)0);
6964         pPtr[nParentLen +16] = getCppuType((const uno::Reference<sheet::XExternalSheetName>*)0);
6965         pPtr[nParentLen +17] = getCppuType((const uno::Reference<document::XEventsSupplier>*)0);
6966 
6967 		for (long i=0; i<nParentLen; i++)
6968 			pPtr[i] = pParentPtr[i];				// parent types first
6969 	}
6970 	return aTypes;
6971 }
6972 
getImplementationId()6973 uno::Sequence<sal_Int8> SAL_CALL ScTableSheetObj::getImplementationId() throw(uno::RuntimeException)
6974 {
6975 	static uno::Sequence< sal_Int8 > aId;
6976 	if( aId.getLength() == 0 )
6977 	{
6978 		aId.realloc( 16 );
6979 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
6980 	}
6981 	return aId;
6982 }
6983 
6984 //	Hilfsfunktionen
6985 
GetTab_Impl() const6986 SCTAB ScTableSheetObj::GetTab_Impl() const
6987 {
6988 	const ScRangeList& rRanges = GetRangeList();
6989 	DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!");
6990 	const ScRange* pFirst = rRanges.GetObject(0);
6991 	if (pFirst)
6992 		return pFirst->aStart.Tab();
6993 
6994 	return 0;	// soll nicht sein
6995 }
6996 
6997 // former XSheet
6998 
getCharts()6999 uno::Reference<table::XTableCharts> SAL_CALL ScTableSheetObj::getCharts() throw(uno::RuntimeException)
7000 {
7001 	ScUnoGuard aGuard;
7002 	ScDocShell* pDocSh = GetDocShell();
7003 	if ( pDocSh )
7004 		return new ScChartsObj( pDocSh, GetTab_Impl() );
7005 
7006 	DBG_ERROR("kein Dokument");
7007 	return NULL;
7008 }
7009 
getDataPilotTables()7010 uno::Reference<sheet::XDataPilotTables> SAL_CALL ScTableSheetObj::getDataPilotTables()
7011 												throw(uno::RuntimeException)
7012 {
7013 	ScUnoGuard aGuard;
7014 	ScDocShell* pDocSh = GetDocShell();
7015 	if ( pDocSh )
7016 		return new ScDataPilotTablesObj( pDocSh, GetTab_Impl() );
7017 
7018 	DBG_ERROR("kein Dokument");
7019 	return NULL;
7020 }
7021 
getScenarios()7022 uno::Reference<sheet::XScenarios> SAL_CALL ScTableSheetObj::getScenarios() throw(uno::RuntimeException)
7023 {
7024 	ScUnoGuard aGuard;
7025 	ScDocShell* pDocSh = GetDocShell();
7026 
7027 	if ( pDocSh )
7028 		return new ScScenariosObj( pDocSh, GetTab_Impl() );
7029 
7030 	DBG_ERROR("kein Dokument");
7031 	return NULL;
7032 }
7033 
getAnnotations()7034 uno::Reference<sheet::XSheetAnnotations> SAL_CALL ScTableSheetObj::getAnnotations()
7035 												throw(uno::RuntimeException)
7036 {
7037 	ScUnoGuard aGuard;
7038 	ScDocShell* pDocSh = GetDocShell();
7039 
7040 	if ( pDocSh )
7041 		return new ScAnnotationsObj( pDocSh, GetTab_Impl() );
7042 
7043 	DBG_ERROR("kein Dokument");
7044 	return NULL;
7045 }
7046 
getCellRangeByName(const rtl::OUString & rRange)7047 uno::Reference<table::XCellRange> SAL_CALL ScTableSheetObj::getCellRangeByName(
7048                         const rtl::OUString& rRange ) throw(uno::RuntimeException)
7049 {
7050 	ScUnoGuard aGuard;
7051 	return ScCellRangeObj::getCellRangeByName( rRange );
7052 }
7053 
createCursor()7054 uno::Reference<sheet::XSheetCellCursor> SAL_CALL ScTableSheetObj::createCursor()
7055 												throw(uno::RuntimeException)
7056 {
7057 	ScUnoGuard aGuard;
7058 	ScDocShell* pDocSh = GetDocShell();
7059 	if ( pDocSh )
7060 	{
7061 		//!	einzelne Zelle oder ganze Tabelle???????
7062 		SCTAB nTab = GetTab_Impl();
7063 		return new ScCellCursorObj( pDocSh, ScRange( 0,0,nTab, MAXCOL,MAXROW,nTab ) );
7064 	}
7065 	return NULL;
7066 }
7067 
createCursorByRange(const uno::Reference<sheet::XSheetCellRange> & xCellRange)7068 uno::Reference<sheet::XSheetCellCursor> SAL_CALL ScTableSheetObj::createCursorByRange(
7069 						const uno::Reference<sheet::XSheetCellRange>& xCellRange )
7070 												throw(uno::RuntimeException)
7071 {
7072 	ScUnoGuard aGuard;
7073 	ScDocShell* pDocSh = GetDocShell();
7074 	if ( pDocSh && xCellRange.is() )
7075 	{
7076 		ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xCellRange );
7077 		if (pRangesImp)
7078 		{
7079 			const ScRangeList& rRanges = pRangesImp->GetRangeList();
7080 			DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
7081 			return new ScCellCursorObj( pDocSh, *rRanges.GetObject(0) );
7082 		}
7083 	}
7084 	return NULL;
7085 }
7086 
7087 // XSheetCellRange
7088 
getSpreadsheet()7089 uno::Reference<sheet::XSpreadsheet> SAL_CALL ScTableSheetObj::getSpreadsheet()
7090 												throw(uno::RuntimeException)
7091 {
7092 	ScUnoGuard aGuard;
7093 	return this;		//!???
7094 }
7095 
7096 // XCellRange
7097 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)7098 uno::Reference<table::XCell> SAL_CALL ScTableSheetObj::getCellByPosition(
7099 										sal_Int32 nColumn, sal_Int32 nRow )
7100 								throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
7101 {
7102 	ScUnoGuard aGuard;
7103 	return ScCellRangeObj::GetCellByPosition_Impl(nColumn, nRow);
7104 }
7105 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)7106 uno::Reference<table::XCellRange> SAL_CALL ScTableSheetObj::getCellRangeByPosition(
7107 				sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
7108 								throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
7109 {
7110 	ScUnoGuard aGuard;
7111 	return ScCellRangeObj::getCellRangeByPosition(nLeft,nTop,nRight,nBottom);
7112 }
7113 
getColumnPageBreaks()7114 uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getColumnPageBreaks()
7115 												throw(uno::RuntimeException)
7116 {
7117 	ScUnoGuard aGuard;
7118 	ScDocShell* pDocSh = GetDocShell();
7119 	if ( pDocSh )
7120 	{
7121 		ScDocument* pDoc = pDocSh->GetDocument();
7122 		SCTAB nTab = GetTab_Impl();
7123 
7124 		Size aSize(pDoc->GetPageSize( nTab ));
7125 		if (aSize.Width() && aSize.Height())		// effektive Groesse schon gesetzt?
7126 			pDoc->UpdatePageBreaks( nTab );
7127 		else
7128 		{
7129 			//	Umbrueche updaten wie in ScDocShell::PageStyleModified:
7130 			ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab );
7131 			aPrintFunc.UpdatePages();
7132 		}
7133 
7134 		SCCOL nCount = 0;
7135 		SCCOL nCol;
7136 		for (nCol=0; nCol<=MAXCOL; nCol++)
7137             if (pDoc->HasColBreak(nCol, nTab))
7138 				++nCount;
7139 
7140 		sheet::TablePageBreakData aData;
7141 		uno::Sequence<sheet::TablePageBreakData> aSeq(nCount);
7142 		sheet::TablePageBreakData* pAry = aSeq.getArray();
7143 		sal_uInt16 nPos = 0;
7144 		for (nCol=0; nCol<=MAXCOL; nCol++)
7145 		{
7146             ScBreakType nBreak = pDoc->HasColBreak(nCol, nTab);
7147             if (nBreak)
7148 			{
7149 				aData.Position	  = nCol;
7150                 aData.ManualBreak = (nBreak & BREAK_MANUAL);
7151 				pAry[nPos] = aData;
7152 				++nPos;
7153 			}
7154 		}
7155 		return aSeq;
7156 	}
7157 	return uno::Sequence<sheet::TablePageBreakData>(0);
7158 }
7159 
getRowPageBreaks()7160 uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getRowPageBreaks()
7161 												throw(uno::RuntimeException)
7162 {
7163 	ScUnoGuard aGuard;
7164 	ScDocShell* pDocSh = GetDocShell();
7165 	if ( pDocSh )
7166 	{
7167 		ScDocument* pDoc = pDocSh->GetDocument();
7168 		SCTAB nTab = GetTab_Impl();
7169 
7170 		Size aSize(pDoc->GetPageSize( nTab ));
7171 		if (aSize.Width() && aSize.Height())		// effektive Groesse schon gesetzt?
7172 			pDoc->UpdatePageBreaks( nTab );
7173 		else
7174 		{
7175 			//	Umbrueche updaten wie in ScDocShell::PageStyleModified:
7176 			ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab );
7177 			aPrintFunc.UpdatePages();
7178 		}
7179         return pDoc->GetRowBreakData(nTab);
7180 	}
7181 	return uno::Sequence<sheet::TablePageBreakData>(0);
7182 }
7183 
removeAllManualPageBreaks()7184 void SAL_CALL ScTableSheetObj::removeAllManualPageBreaks() throw(uno::RuntimeException)
7185 {
7186 	ScUnoGuard aGuard;
7187 	ScDocShell* pDocSh = GetDocShell();
7188 	if ( pDocSh )
7189 	{
7190 		//!	docfunc Funktion, auch fuer ScViewFunc::RemoveManualBreaks
7191 
7192 		ScDocument* pDoc = pDocSh->GetDocument();
7193 		sal_Bool bUndo (pDoc->IsUndoEnabled());
7194 		SCTAB nTab = GetTab_Impl();
7195 
7196 		if (bUndo)
7197 		{
7198 			ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
7199 			pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
7200 			pDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, sal_False, pUndoDoc );
7201 			pDocSh->GetUndoManager()->AddUndoAction(
7202 									new ScUndoRemoveBreaks( pDocSh, nTab, pUndoDoc ) );
7203 		}
7204 
7205 		pDoc->RemoveManualBreaks(nTab);
7206 		pDoc->UpdatePageBreaks(nTab);
7207 
7208 		//? UpdatePageBreakData( sal_True );
7209 		pDocSh->SetDocumentModified();
7210 		pDocSh->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
7211 	}
7212 }
7213 
7214 // XNamed
7215 
getName()7216 rtl::OUString SAL_CALL ScTableSheetObj::getName() throw(uno::RuntimeException)
7217 {
7218 	ScUnoGuard aGuard;
7219 	String aName;
7220 	ScDocShell* pDocSh = GetDocShell();
7221 	if ( pDocSh )
7222 		pDocSh->GetDocument()->GetName( GetTab_Impl(), aName );
7223 	return aName;
7224 }
7225 
setName(const rtl::OUString & aNewName)7226 void SAL_CALL ScTableSheetObj::setName( const rtl::OUString& aNewName )
7227 												throw(uno::RuntimeException)
7228 {
7229 	ScUnoGuard aGuard;
7230 	ScDocShell* pDocSh = GetDocShell();
7231 	if ( pDocSh )
7232 	{
7233 		String aString(aNewName);
7234 		ScDocFunc aFunc( *pDocSh );
7235 		aFunc.RenameTable( GetTab_Impl(), aString, sal_True, sal_True );
7236 	}
7237 }
7238 
7239 // XDrawPageSupplier
7240 
getDrawPage()7241 uno::Reference<drawing::XDrawPage> SAL_CALL ScTableSheetObj::getDrawPage()
7242 												throw(uno::RuntimeException)
7243 {
7244 	ScUnoGuard aGuard;
7245 	ScDocShell* pDocSh = GetDocShell();
7246 	if ( pDocSh )
7247 	{
7248 		ScDrawLayer* pDrawLayer = pDocSh->MakeDrawLayer();
7249 		DBG_ASSERT(pDrawLayer,"kann Draw-Layer nicht anlegen");
7250 
7251 		SCTAB nTab = GetTab_Impl();
7252 		SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
7253 		DBG_ASSERT(pPage,"Draw-Page nicht gefunden");
7254 		if (pPage)
7255 			return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
7256 
7257 		//	Das DrawPage-Objekt meldet sich als Listener am SdrModel an
7258 		//	und sollte von dort alle Aktionen mitbekommen
7259 	}
7260 	return NULL;
7261 }
7262 
7263 // XCellMovement
7264 
insertCells(const table::CellRangeAddress & rRangeAddress,sheet::CellInsertMode nMode)7265 void SAL_CALL ScTableSheetObj::insertCells( const table::CellRangeAddress& rRangeAddress,
7266 								sheet::CellInsertMode nMode ) throw(uno::RuntimeException)
7267 {
7268 	ScUnoGuard aGuard;
7269 	ScDocShell* pDocSh = GetDocShell();
7270 	if ( pDocSh )
7271 	{
7272 		sal_Bool bDo = sal_True;
7273         InsCellCmd eCmd = INS_NONE;
7274 		switch (nMode)
7275 		{
7276 			case sheet::CellInsertMode_NONE:	bDo = sal_False;			break;
7277 			case sheet::CellInsertMode_DOWN:	eCmd = INS_CELLSDOWN;	break;
7278 			case sheet::CellInsertMode_RIGHT:	eCmd = INS_CELLSRIGHT;	break;
7279 			case sheet::CellInsertMode_ROWS:	eCmd = INS_INSROWS;		break;
7280 			case sheet::CellInsertMode_COLUMNS: eCmd = INS_INSCOLS;		break;
7281 			default:
7282 				DBG_ERROR("insertCells: falscher Mode");
7283 				bDo = sal_False;
7284 		}
7285 
7286 		if (bDo)
7287 		{
7288 			DBG_ASSERT( rRangeAddress.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" );
7289 			ScRange aScRange;
7290 			ScUnoConversion::FillScRange( aScRange, rRangeAddress );
7291 			ScDocFunc aFunc(*pDocSh);
7292 			aFunc.InsertCells( aScRange, NULL, eCmd, sal_True, sal_True );
7293 		}
7294 	}
7295 }
7296 
removeRange(const table::CellRangeAddress & rRangeAddress,sheet::CellDeleteMode nMode)7297 void SAL_CALL ScTableSheetObj::removeRange( const table::CellRangeAddress& rRangeAddress,
7298 								sheet::CellDeleteMode nMode ) throw(uno::RuntimeException)
7299 {
7300 	ScUnoGuard aGuard;
7301 	ScDocShell* pDocSh = GetDocShell();
7302 	if ( pDocSh )
7303 	{
7304 		sal_Bool bDo = sal_True;
7305         DelCellCmd eCmd = DEL_NONE;
7306 		switch (nMode)
7307 		{
7308 			case sheet::CellDeleteMode_NONE:	 bDo = sal_False;			break;
7309 			case sheet::CellDeleteMode_UP:		 eCmd = DEL_CELLSUP;	break;
7310 			case sheet::CellDeleteMode_LEFT:	 eCmd = DEL_CELLSLEFT;	break;
7311 			case sheet::CellDeleteMode_ROWS:	 eCmd = DEL_DELROWS;	break;
7312 			case sheet::CellDeleteMode_COLUMNS:	 eCmd = DEL_DELCOLS;	break;
7313 			default:
7314 				DBG_ERROR("deleteCells: falscher Mode");
7315 				bDo = sal_False;
7316 		}
7317 
7318 		if (bDo)
7319 		{
7320 			DBG_ASSERT( rRangeAddress.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" );
7321 			ScRange aScRange;
7322 			ScUnoConversion::FillScRange( aScRange, rRangeAddress );
7323 			ScDocFunc aFunc(*pDocSh);
7324 			aFunc.DeleteCells( aScRange, NULL, eCmd, sal_True, sal_True );
7325 		}
7326 	}
7327 }
7328 
moveRange(const table::CellAddress & aDestination,const table::CellRangeAddress & aSource)7329 void SAL_CALL ScTableSheetObj::moveRange( const table::CellAddress& aDestination,
7330 										const table::CellRangeAddress& aSource )
7331 										throw(uno::RuntimeException)
7332 {
7333 	ScUnoGuard aGuard;
7334 	ScDocShell* pDocSh = GetDocShell();
7335 	if ( pDocSh )
7336 	{
7337 		DBG_ASSERT( aSource.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" );
7338 		ScRange aSourceRange;
7339 		ScUnoConversion::FillScRange( aSourceRange, aSource );
7340 		ScAddress aDestPos( (SCCOL)aDestination.Column, (SCROW)aDestination.Row, aDestination.Sheet );
7341 		ScDocFunc aFunc(*pDocSh);
7342 		aFunc.MoveBlock( aSourceRange, aDestPos, sal_True, sal_True, sal_True, sal_True );
7343 	}
7344 }
7345 
copyRange(const table::CellAddress & aDestination,const table::CellRangeAddress & aSource)7346 void SAL_CALL ScTableSheetObj::copyRange( const table::CellAddress& aDestination,
7347 										const table::CellRangeAddress& aSource )
7348 										throw(uno::RuntimeException)
7349 {
7350 	ScUnoGuard aGuard;
7351 	ScDocShell* pDocSh = GetDocShell();
7352 	if ( pDocSh )
7353 	{
7354 		DBG_ASSERT( aSource.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" );
7355 		ScRange aSourceRange;
7356 		ScUnoConversion::FillScRange( aSourceRange, aSource );
7357 		ScAddress aDestPos( (SCCOL)aDestination.Column, (SCROW)aDestination.Row, aDestination.Sheet );
7358 		ScDocFunc aFunc(*pDocSh);
7359 		aFunc.MoveBlock( aSourceRange, aDestPos, sal_False, sal_True, sal_True, sal_True );
7360 	}
7361 }
7362 
7363 // XPrintAreas
7364 
PrintAreaUndo_Impl(ScPrintRangeSaver * pOldRanges)7365 void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges )
7366 {
7367 	//	Umbrueche und Undo
7368 	ScDocShell* pDocSh = GetDocShell();
7369 	ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : 0;
7370 
7371     if(pDocSh && pDoc)
7372 	{
7373 		const bool bUndo(pDoc->IsUndoEnabled());
7374 		const SCTAB nTab(GetTab_Impl());
7375 
7376 		if(bUndo)
7377 		{
7378             pDocSh->GetUndoManager()->AddUndoAction(
7379 			    new ScUndoPrintRange(
7380                     pDocSh,
7381                     nTab,
7382                     pOldRanges,
7383                     pDoc->CreatePrintRangeSaver())); // create new ranges
7384 
7385             // #120105# ownership of old ranges has changed, mark as consumed
7386             pOldRanges = 0;
7387 		}
7388 
7389 		ScPrintFunc(pDocSh, pDocSh->GetPrinter(), nTab).UpdatePages();
7390 		SfxBindings* pBindings = pDocSh->GetViewBindings();
7391 
7392         if(pBindings)
7393         {
7394 			pBindings->Invalidate(SID_DELETE_PRINTAREA);
7395         }
7396 
7397 		pDocSh->SetDocumentModified();
7398 	}
7399 
7400     if(pOldRanges)
7401     {
7402         // #120105# pOldRanges not used, need to cleanup
7403 		delete pOldRanges;
7404     }
7405 }
7406 
getPrintAreas()7407 uno::Sequence<table::CellRangeAddress> SAL_CALL ScTableSheetObj::getPrintAreas()
7408 												throw(uno::RuntimeException)
7409 {
7410 	ScUnoGuard aGuard;
7411 	ScDocShell* pDocSh = GetDocShell();
7412 	if ( pDocSh )
7413 	{
7414 		ScDocument* pDoc = pDocSh->GetDocument();
7415 		SCTAB nTab = GetTab_Impl();
7416 		sal_uInt16 nCount = pDoc->GetPrintRangeCount( nTab );
7417 
7418 		table::CellRangeAddress aRangeAddress;
7419 		uno::Sequence<table::CellRangeAddress> aSeq(nCount);
7420 		table::CellRangeAddress* pAry = aSeq.getArray();
7421 		for (sal_uInt16 i=0; i<nCount; i++)
7422 		{
7423 			const ScRange* pRange = pDoc->GetPrintRange( nTab, i );
7424 			DBG_ASSERT(pRange,"wo ist der Druckbereich");
7425 			if (pRange)
7426 			{
7427 				ScUnoConversion::FillApiRange( aRangeAddress, *pRange );
7428                 aRangeAddress.Sheet = nTab; // core does not care about sheet index
7429 				pAry[i] = aRangeAddress;
7430 			}
7431 		}
7432 		return aSeq;
7433 	}
7434 	return uno::Sequence<table::CellRangeAddress>();
7435 }
7436 
setPrintAreas(const uno::Sequence<table::CellRangeAddress> & aPrintAreas)7437 void SAL_CALL ScTableSheetObj::setPrintAreas(
7438 					const uno::Sequence<table::CellRangeAddress>& aPrintAreas )
7439 												throw(uno::RuntimeException)
7440 {
7441 	ScUnoGuard aGuard;
7442 	ScDocShell* pDocSh = GetDocShell();
7443 	if ( pDocSh )
7444 	{
7445 		ScDocument* pDoc = pDocSh->GetDocument();
7446 		SCTAB nTab = GetTab_Impl();
7447 
7448 		ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
7449 
7450 		sal_uInt16 nCount = (sal_uInt16) aPrintAreas.getLength();
7451         pDoc->ClearPrintRanges( nTab );
7452 		if (nCount)
7453 		{
7454 			ScRange aPrintRange;
7455 			const table::CellRangeAddress* pAry = aPrintAreas.getConstArray();
7456 			for (sal_uInt16 i=0; i<nCount; i++)
7457 			{
7458 				ScUnoConversion::FillScRange( aPrintRange, pAry[i] );
7459                 pDoc->AddPrintRange( nTab, aPrintRange );
7460 			}
7461 		}
7462 
7463 		PrintAreaUndo_Impl( pOldRanges );	// Undo, Umbrueche, Modified etc.
7464 	}
7465 }
7466 
getPrintTitleColumns()7467 sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleColumns() throw(uno::RuntimeException)
7468 {
7469 	ScUnoGuard aGuard;
7470 	ScDocShell* pDocSh = GetDocShell();
7471 	if ( pDocSh )
7472 	{
7473 		ScDocument* pDoc = pDocSh->GetDocument();
7474 		SCTAB nTab = GetTab_Impl();
7475 		return ( pDoc->GetRepeatColRange(nTab) != NULL );
7476 	}
7477 	return sal_False;
7478 }
7479 
setPrintTitleColumns(sal_Bool bPrintTitleColumns)7480 void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns )
7481 													throw(uno::RuntimeException)
7482 {
7483 	ScUnoGuard aGuard;
7484 	ScDocShell* pDocSh = GetDocShell();
7485 	if ( pDocSh )
7486 	{
7487 		ScDocument* pDoc = pDocSh->GetDocument();
7488 		SCTAB nTab = GetTab_Impl();
7489 
7490 		ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
7491 
7492 		if ( bPrintTitleColumns )
7493 		{
7494 			if ( !pDoc->GetRepeatColRange( nTab ) )			// keinen bestehenden Bereich veraendern
7495 			{
7496 				ScRange aNew( 0, 0, nTab, 0, 0, nTab );		// Default
7497 				pDoc->SetRepeatColRange( nTab, &aNew );		// einschalten
7498 			}
7499 		}
7500 		else
7501 			pDoc->SetRepeatColRange( nTab, NULL );			// abschalten
7502 
7503 		PrintAreaUndo_Impl( pOldRanges );	// Undo, Umbrueche, Modified etc.
7504 
7505 		//!	zuletzt gesetzten Bereich beim Abschalten merken und beim Einschalten wiederherstellen ???
7506 	}
7507 }
7508 
getTitleColumns()7509 table::CellRangeAddress SAL_CALL ScTableSheetObj::getTitleColumns() throw(uno::RuntimeException)
7510 {
7511 	ScUnoGuard aGuard;
7512 	table::CellRangeAddress aRet;
7513 	ScDocShell* pDocSh = GetDocShell();
7514 	if ( pDocSh )
7515 	{
7516 		ScDocument* pDoc = pDocSh->GetDocument();
7517 		SCTAB nTab = GetTab_Impl();
7518 		const ScRange* pRange = pDoc->GetRepeatColRange(nTab);
7519 		if (pRange)
7520         {
7521 			ScUnoConversion::FillApiRange( aRet, *pRange );
7522             aRet.Sheet = nTab; // core does not care about sheet index
7523         }
7524 	}
7525 	return aRet;
7526 }
7527 
setTitleColumns(const table::CellRangeAddress & aTitleColumns)7528 void SAL_CALL ScTableSheetObj::setTitleColumns( const table::CellRangeAddress& aTitleColumns )
7529 													throw(uno::RuntimeException)
7530 {
7531 	ScUnoGuard aGuard;
7532 	ScDocShell* pDocSh = GetDocShell();
7533 	if ( pDocSh )
7534 	{
7535 		ScDocument* pDoc = pDocSh->GetDocument();
7536 		SCTAB nTab = GetTab_Impl();
7537 
7538 		ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
7539 
7540 		ScRange aNew;
7541 		ScUnoConversion::FillScRange( aNew, aTitleColumns );
7542 		pDoc->SetRepeatColRange( nTab, &aNew );		// immer auch einschalten
7543 
7544 		PrintAreaUndo_Impl( pOldRanges );			// Undo, Umbrueche, Modified etc.
7545 	}
7546 }
7547 
getPrintTitleRows()7548 sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleRows() throw(uno::RuntimeException)
7549 {
7550 	ScUnoGuard aGuard;
7551 	ScDocShell* pDocSh = GetDocShell();
7552 	if ( pDocSh )
7553 	{
7554 		ScDocument* pDoc = pDocSh->GetDocument();
7555 		SCTAB nTab = GetTab_Impl();
7556 		return ( pDoc->GetRepeatRowRange(nTab) != NULL );
7557 	}
7558 	return sal_False;
7559 }
7560 
setPrintTitleRows(sal_Bool bPrintTitleRows)7561 void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows )
7562 												throw(uno::RuntimeException)
7563 {
7564 	ScUnoGuard aGuard;
7565 	ScDocShell* pDocSh = GetDocShell();
7566 	if ( pDocSh )
7567 	{
7568 		ScDocument* pDoc = pDocSh->GetDocument();
7569 		SCTAB nTab = GetTab_Impl();
7570 
7571 		ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
7572 
7573 		if ( bPrintTitleRows )
7574 		{
7575 			if ( !pDoc->GetRepeatRowRange( nTab ) )			// keinen bestehenden Bereich veraendern
7576 			{
7577 				ScRange aNew( 0, 0, nTab, 0, 0, nTab );		// Default
7578 				pDoc->SetRepeatRowRange( nTab, &aNew );		// einschalten
7579 			}
7580 		}
7581 		else
7582 			pDoc->SetRepeatRowRange( nTab, NULL );			// abschalten
7583 
7584 		PrintAreaUndo_Impl( pOldRanges );	// Undo, Umbrueche, Modified etc.
7585 
7586 		//!	zuletzt gesetzten Bereich beim Abschalten merken und beim Einschalten wiederherstellen ???
7587 	}
7588 }
7589 
getTitleRows()7590 table::CellRangeAddress SAL_CALL ScTableSheetObj::getTitleRows() throw(uno::RuntimeException)
7591 {
7592 	ScUnoGuard aGuard;
7593 	table::CellRangeAddress aRet;
7594 	ScDocShell* pDocSh = GetDocShell();
7595 	if ( pDocSh )
7596 	{
7597 		ScDocument* pDoc = pDocSh->GetDocument();
7598 		SCTAB nTab = GetTab_Impl();
7599 		const ScRange* pRange = pDoc->GetRepeatRowRange(nTab);
7600 		if (pRange)
7601         {
7602 			ScUnoConversion::FillApiRange( aRet, *pRange );
7603             aRet.Sheet = nTab; // core does not care about sheet index
7604         }
7605 	}
7606 	return aRet;
7607 }
7608 
setTitleRows(const table::CellRangeAddress & aTitleRows)7609 void SAL_CALL ScTableSheetObj::setTitleRows( const table::CellRangeAddress& aTitleRows )
7610 													throw(uno::RuntimeException)
7611 {
7612 	ScUnoGuard aGuard;
7613 	ScDocShell* pDocSh = GetDocShell();
7614 	if ( pDocSh )
7615 	{
7616 		ScDocument* pDoc = pDocSh->GetDocument();
7617 		SCTAB nTab = GetTab_Impl();
7618 
7619 		ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver();
7620 
7621 		ScRange aNew;
7622 		ScUnoConversion::FillScRange( aNew, aTitleRows );
7623 		pDoc->SetRepeatRowRange( nTab, &aNew );		// immer auch einschalten
7624 
7625 		PrintAreaUndo_Impl( pOldRanges );			// Undo, Umbrueche, Modified etc.
7626 	}
7627 }
7628 
7629 // XSheetLinkable
7630 
getLinkMode()7631 sheet::SheetLinkMode SAL_CALL ScTableSheetObj::getLinkMode() throw(uno::RuntimeException)
7632 {
7633 	ScUnoGuard aGuard;
7634 	sheet::SheetLinkMode eRet = sheet::SheetLinkMode_NONE;
7635 	ScDocShell* pDocSh = GetDocShell();
7636 	if ( pDocSh )
7637 	{
7638 		sal_uInt8 nMode = pDocSh->GetDocument()->GetLinkMode( GetTab_Impl() );
7639 		if ( nMode == SC_LINK_NORMAL )
7640 			eRet = sheet::SheetLinkMode_NORMAL;
7641 		else if ( nMode == SC_LINK_VALUE )
7642 			eRet = sheet::SheetLinkMode_VALUE;
7643 	}
7644 	return eRet;
7645 }
7646 
setLinkMode(sheet::SheetLinkMode nLinkMode)7647 void SAL_CALL ScTableSheetObj::setLinkMode( sheet::SheetLinkMode nLinkMode )
7648 												throw(uno::RuntimeException)
7649 {
7650 	ScUnoGuard aGuard;
7651 
7652 	//!	Filter und Options aus altem Link suchen
7653 
7654 	rtl::OUString aUrl(getLinkUrl());
7655 	rtl::OUString aSheet(getLinkSheetName());
7656 
7657 	rtl::OUString aEmpty;
7658 	link( aUrl, aSheet, aEmpty, aEmpty, nLinkMode );
7659 }
7660 
getLinkUrl()7661 rtl::OUString SAL_CALL ScTableSheetObj::getLinkUrl() throw(uno::RuntimeException)
7662 {
7663 	ScUnoGuard aGuard;
7664 	String aFile;
7665 	ScDocShell* pDocSh = GetDocShell();
7666 	if ( pDocSh )
7667 		aFile = pDocSh->GetDocument()->GetLinkDoc( GetTab_Impl() );
7668 	return aFile;
7669 }
7670 
setLinkUrl(const rtl::OUString & aLinkUrl)7671 void SAL_CALL ScTableSheetObj::setLinkUrl( const rtl::OUString& aLinkUrl )
7672 												throw(uno::RuntimeException)
7673 {
7674 	ScUnoGuard aGuard;
7675 
7676 	//!	Filter und Options aus altem Link suchen
7677 
7678 	sheet::SheetLinkMode eMode = getLinkMode();
7679 	rtl::OUString aSheet(getLinkSheetName());
7680 
7681 	rtl::OUString aEmpty;
7682 	link( aLinkUrl, aSheet, aEmpty, aEmpty, eMode );
7683 }
7684 
getLinkSheetName()7685 rtl::OUString SAL_CALL ScTableSheetObj::getLinkSheetName() throw(uno::RuntimeException)
7686 {
7687 	ScUnoGuard aGuard;
7688 	String aSheet;
7689 	ScDocShell* pDocSh = GetDocShell();
7690 	if ( pDocSh )
7691 		aSheet = pDocSh->GetDocument()->GetLinkTab( GetTab_Impl() );
7692 	return aSheet;
7693 }
7694 
setLinkSheetName(const rtl::OUString & aLinkSheetName)7695 void SAL_CALL ScTableSheetObj::setLinkSheetName( const rtl::OUString& aLinkSheetName )
7696 												throw(uno::RuntimeException)
7697 {
7698 	ScUnoGuard aGuard;
7699 
7700 	//!	Filter und Options aus altem Link suchen
7701 
7702 	sheet::SheetLinkMode eMode = getLinkMode();
7703 	rtl::OUString aUrl(getLinkUrl());
7704 
7705 	rtl::OUString aEmpty;
7706 	link( aUrl, aLinkSheetName, aEmpty, aEmpty, eMode );
7707 }
7708 
link(const rtl::OUString & aUrl,const rtl::OUString & aSheetName,const rtl::OUString & aFilterName,const rtl::OUString & aFilterOptions,sheet::SheetLinkMode nMode)7709 void SAL_CALL ScTableSheetObj::link( const rtl::OUString& aUrl, const rtl::OUString& aSheetName,
7710 						const rtl::OUString& aFilterName, const rtl::OUString& aFilterOptions,
7711 						sheet::SheetLinkMode nMode ) throw(uno::RuntimeException)
7712 {
7713 	ScUnoGuard aGuard;
7714 	ScDocShell* pDocSh = GetDocShell();
7715 	if ( pDocSh )
7716 	{
7717 		ScDocument* pDoc = pDocSh->GetDocument();
7718 		SCTAB nTab = GetTab_Impl();
7719 
7720 		String aFileString	 (aUrl);
7721 		String aFilterString (aFilterName);
7722 		String aOptString	 (aFilterOptions);
7723 		String aSheetString	 (aSheetName);
7724 
7725 		aFileString = ScGlobal::GetAbsDocName( aFileString, pDocSh );
7726 		if ( !aFilterString.Len() )
7727             ScDocumentLoader::GetFilterName( aFileString, aFilterString, aOptString, sal_True, sal_False );
7728 
7729 		//	remove application prefix from filter name here, so the filter options
7730 		//	aren't reset when the filter name is changed in ScTableLink::DataChanged
7731 		ScDocumentLoader::RemoveAppPrefix( aFilterString );
7732 
7733 		sal_uInt8 nLinkMode = SC_LINK_NONE;
7734 		if ( nMode == sheet::SheetLinkMode_NORMAL )
7735 			nLinkMode = SC_LINK_NORMAL;
7736 		else if ( nMode == sheet::SheetLinkMode_VALUE )
7737 			nLinkMode = SC_LINK_VALUE;
7738 
7739 		sal_uLong nRefresh = 0;
7740 		pDoc->SetLink( nTab, nLinkMode, aFileString, aFilterString, aOptString, aSheetString, nRefresh );
7741 
7742 		pDocSh->UpdateLinks();					// ggf. Link eintragen oder loeschen
7743 		SfxBindings* pBindings = pDocSh->GetViewBindings();
7744 		if (pBindings)
7745 			pBindings->Invalidate(SID_LINKS);
7746 
7747 		//!	Undo fuer Link-Daten an der Table
7748 
7749 		if ( nLinkMode != SC_LINK_NONE && pDoc->IsExecuteLinkEnabled() )		// Link updaten
7750 		{
7751 			//	Update immer, auch wenn der Link schon da war
7752 			//!	Update nur fuer die betroffene Tabelle???
7753 
7754 			sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
7755 			sal_uInt16 nCount = pLinkManager->GetLinks().Count();
7756 			for ( sal_uInt16 i=0; i<nCount; i++ )
7757 			{
7758                 ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
7759 				if (pBase->ISA(ScTableLink))
7760 				{
7761 					ScTableLink* pTabLink = (ScTableLink*)pBase;
7762 					if ( pTabLink->GetFileName() == aFileString )
7763 						pTabLink->Update();							// inkl. Paint&Undo
7764 
7765 					//!	Der Dateiname sollte nur einmal vorkommen (?)
7766 				}
7767 			}
7768 		}
7769 
7770 		//!	Notify fuer ScSheetLinkObj Objekte!!!
7771 	}
7772 }
7773 
7774 // XSheetAuditing
7775 
hideDependents(const table::CellAddress & aPosition)7776 sal_Bool SAL_CALL ScTableSheetObj::hideDependents( const table::CellAddress& aPosition )
7777 												throw(uno::RuntimeException)
7778 {
7779 	ScUnoGuard aGuard;
7780 	ScDocShell* pDocSh = GetDocShell();
7781 	if ( pDocSh )
7782 	{
7783 		SCTAB nTab = GetTab_Impl();
7784 		DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" );
7785 		ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
7786 		ScDocFunc aFunc(*pDocSh);
7787 		return aFunc.DetectiveDelSucc( aPos );
7788 	}
7789 	return sal_False;
7790 }
7791 
hidePrecedents(const table::CellAddress & aPosition)7792 sal_Bool SAL_CALL ScTableSheetObj::hidePrecedents( const table::CellAddress& aPosition )
7793 											throw(uno::RuntimeException)
7794 {
7795 	ScUnoGuard aGuard;
7796 	ScDocShell* pDocSh = GetDocShell();
7797 	if ( pDocSh )
7798 	{
7799 		SCTAB nTab = GetTab_Impl();
7800 		DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" );
7801 		ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
7802 		ScDocFunc aFunc(*pDocSh);
7803 		return aFunc.DetectiveDelPred( aPos );
7804 	}
7805 	return sal_False;
7806 }
7807 
showDependents(const table::CellAddress & aPosition)7808 sal_Bool SAL_CALL ScTableSheetObj::showDependents( const table::CellAddress& aPosition )
7809 											throw(uno::RuntimeException)
7810 {
7811 	ScUnoGuard aGuard;
7812 	ScDocShell* pDocSh = GetDocShell();
7813 	if ( pDocSh )
7814 	{
7815 		SCTAB nTab = GetTab_Impl();
7816 		DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" );
7817 		ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
7818 		ScDocFunc aFunc(*pDocSh);
7819 		return aFunc.DetectiveAddSucc( aPos );
7820 	}
7821 	return sal_False;
7822 }
7823 
showPrecedents(const table::CellAddress & aPosition)7824 sal_Bool SAL_CALL ScTableSheetObj::showPrecedents( const table::CellAddress& aPosition )
7825 											throw(uno::RuntimeException)
7826 {
7827 	ScUnoGuard aGuard;
7828 	ScDocShell* pDocSh = GetDocShell();
7829 	if ( pDocSh )
7830 	{
7831 		SCTAB nTab = GetTab_Impl();
7832 		DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" );
7833 		ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
7834 		ScDocFunc aFunc(*pDocSh);
7835 		return aFunc.DetectiveAddPred( aPos );
7836 	}
7837 	return sal_False;
7838 }
7839 
showErrors(const table::CellAddress & aPosition)7840 sal_Bool SAL_CALL ScTableSheetObj::showErrors( const table::CellAddress& aPosition )
7841 											throw(uno::RuntimeException)
7842 {
7843 	ScUnoGuard aGuard;
7844 	ScDocShell* pDocSh = GetDocShell();
7845 	if ( pDocSh )
7846 	{
7847 		SCTAB nTab = GetTab_Impl();
7848 		DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" );
7849 		ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
7850 		ScDocFunc aFunc(*pDocSh);
7851 		return aFunc.DetectiveAddError( aPos );
7852 	}
7853 	return sal_False;
7854 }
7855 
showInvalid()7856 sal_Bool SAL_CALL ScTableSheetObj::showInvalid() throw(uno::RuntimeException)
7857 {
7858 	ScUnoGuard aGuard;
7859 	ScDocShell* pDocSh = GetDocShell();
7860 	if ( pDocSh )
7861 	{
7862 		ScDocFunc aFunc(*pDocSh);
7863 		return aFunc.DetectiveMarkInvalid( GetTab_Impl() );
7864 	}
7865 	return sal_False;
7866 }
7867 
clearArrows()7868 void SAL_CALL ScTableSheetObj::clearArrows() throw(uno::RuntimeException)
7869 {
7870 	ScUnoGuard aGuard;
7871 	ScDocShell* pDocSh = GetDocShell();
7872 	if ( pDocSh )
7873 	{
7874 		ScDocFunc aFunc(*pDocSh);
7875 		aFunc.DetectiveDelAll( GetTab_Impl() );
7876 	}
7877 }
7878 
7879 // XSheetOutline
7880 
group(const table::CellRangeAddress & rGroupRange,table::TableOrientation nOrientation)7881 void SAL_CALL ScTableSheetObj::group( const table::CellRangeAddress& rGroupRange,
7882 										table::TableOrientation nOrientation )
7883 									throw(uno::RuntimeException)
7884 {
7885 	ScUnoGuard aGuard;
7886 	ScDocShell* pDocSh = GetDocShell();
7887 	if ( pDocSh )
7888 	{
7889 		sal_Bool bColumns = ( nOrientation == table::TableOrientation_COLUMNS );
7890 		ScRange aGroupRange;
7891 		ScUnoConversion::FillScRange( aGroupRange, rGroupRange );
7892 		ScOutlineDocFunc aFunc(*pDocSh);
7893 		aFunc.MakeOutline( aGroupRange, bColumns, sal_True, sal_True );
7894 	}
7895 }
7896 
ungroup(const table::CellRangeAddress & rGroupRange,table::TableOrientation nOrientation)7897 void SAL_CALL ScTableSheetObj::ungroup( const table::CellRangeAddress& rGroupRange,
7898 										table::TableOrientation nOrientation )
7899 									throw(uno::RuntimeException)
7900 {
7901 	ScUnoGuard aGuard;
7902 	ScDocShell* pDocSh = GetDocShell();
7903 	if ( pDocSh )
7904 	{
7905 		sal_Bool bColumns = ( nOrientation == table::TableOrientation_COLUMNS );
7906 		ScRange aGroupRange;
7907 		ScUnoConversion::FillScRange( aGroupRange, rGroupRange );
7908 		ScOutlineDocFunc aFunc(*pDocSh);
7909 		aFunc.RemoveOutline( aGroupRange, bColumns, sal_True, sal_True );
7910 	}
7911 }
7912 
autoOutline(const table::CellRangeAddress & rCellRange)7913 void SAL_CALL ScTableSheetObj::autoOutline( const table::CellRangeAddress& rCellRange )
7914 									throw(uno::RuntimeException)
7915 {
7916 	ScUnoGuard aGuard;
7917 	ScDocShell* pDocSh = GetDocShell();
7918 	if ( pDocSh )
7919 	{
7920 		ScRange aFormulaRange;
7921 		ScUnoConversion::FillScRange( aFormulaRange, rCellRange );
7922 		ScOutlineDocFunc aFunc(*pDocSh);
7923 		aFunc.AutoOutline( aFormulaRange, sal_True, sal_True );
7924 	}
7925 }
7926 
clearOutline()7927 void SAL_CALL ScTableSheetObj::clearOutline() throw(uno::RuntimeException)
7928 {
7929 	ScUnoGuard aGuard;
7930 	ScDocShell* pDocSh = GetDocShell();
7931 	if ( pDocSh )
7932 	{
7933 		SCTAB nTab = GetTab_Impl();
7934 		ScOutlineDocFunc aFunc(*pDocSh);
7935 		aFunc.RemoveAllOutlines( nTab, sal_True, sal_True );
7936 	}
7937 }
7938 
hideDetail(const table::CellRangeAddress & rCellRange)7939 void SAL_CALL ScTableSheetObj::hideDetail( const table::CellRangeAddress& rCellRange )
7940 											throw(uno::RuntimeException)
7941 {
7942 	ScUnoGuard aGuard;
7943 	ScDocShell* pDocSh = GetDocShell();
7944 	if ( pDocSh )
7945 	{
7946 		ScRange aMarkRange;
7947 		ScUnoConversion::FillScRange( aMarkRange, rCellRange );
7948 		ScOutlineDocFunc aFunc(*pDocSh);
7949 		aFunc.HideMarkedOutlines( aMarkRange, sal_True, sal_True );
7950 	}
7951 }
7952 
showDetail(const table::CellRangeAddress & rCellRange)7953 void SAL_CALL ScTableSheetObj::showDetail( const table::CellRangeAddress& rCellRange )
7954 											throw(uno::RuntimeException)
7955 {
7956 	ScUnoGuard aGuard;
7957 	ScDocShell* pDocSh = GetDocShell();
7958 	if ( pDocSh )
7959 	{
7960 		ScRange aMarkRange;
7961 		ScUnoConversion::FillScRange( aMarkRange, rCellRange );
7962 		ScOutlineDocFunc aFunc(*pDocSh);
7963 		aFunc.ShowMarkedOutlines( aMarkRange, sal_True, sal_True );
7964 	}
7965 }
7966 
showLevel(sal_Int16 nLevel,table::TableOrientation nOrientation)7967 void SAL_CALL ScTableSheetObj::showLevel( sal_Int16 nLevel, table::TableOrientation nOrientation )
7968 											throw(uno::RuntimeException)
7969 {
7970 	ScUnoGuard aGuard;
7971 	ScDocShell* pDocSh = GetDocShell();
7972 	if ( pDocSh )
7973 	{
7974 		sal_Bool bColumns = ( nOrientation == table::TableOrientation_COLUMNS );
7975 		SCTAB nTab = GetTab_Impl();
7976 		ScOutlineDocFunc aFunc(*pDocSh);
7977 		aFunc.SelectLevel( nTab, bColumns, nLevel, sal_True, sal_True, sal_True );
7978 	}
7979 }
7980 
7981 // XProtectable
7982 
protect(const rtl::OUString & aPassword)7983 void SAL_CALL ScTableSheetObj::protect( const rtl::OUString& aPassword )
7984 											throw(uno::RuntimeException)
7985 {
7986 	ScUnoGuard aGuard;
7987 	ScDocShell* pDocSh = GetDocShell();
7988     // #i108245# if already protected, don't change anything
7989     if ( pDocSh && !pDocSh->GetDocument()->IsTabProtected( GetTab_Impl() ) )
7990 	{
7991 		String aString(aPassword);
7992 		ScDocFunc aFunc(*pDocSh);
7993 		aFunc.Protect( GetTab_Impl(), aString, sal_True );
7994 	}
7995 }
7996 
unprotect(const rtl::OUString & aPassword)7997 void SAL_CALL ScTableSheetObj::unprotect( const rtl::OUString& aPassword )
7998 							throw(lang::IllegalArgumentException, uno::RuntimeException)
7999 {
8000 	ScUnoGuard aGuard;
8001 	ScDocShell* pDocSh = GetDocShell();
8002 	if ( pDocSh )
8003 	{
8004 		String aString(aPassword);
8005 		ScDocFunc aFunc(*pDocSh);
8006         sal_Bool bDone = aFunc.Unprotect( GetTab_Impl(), aString, sal_True );
8007         if (!bDone)
8008             throw lang::IllegalArgumentException();
8009 	}
8010 }
8011 
isProtected()8012 sal_Bool SAL_CALL ScTableSheetObj::isProtected() throw(uno::RuntimeException)
8013 {
8014 	ScUnoGuard aGuard;
8015 	ScDocShell* pDocSh = GetDocShell();
8016 	if ( pDocSh )
8017 		return pDocSh->GetDocument()->IsTabProtected( GetTab_Impl() );
8018 
8019 	DBG_ERROR("keine DocShell");		//! Exception oder so?
8020 	return sal_False;
8021 }
8022 
8023 // XScenario
8024 
getIsScenario()8025 sal_Bool SAL_CALL ScTableSheetObj::getIsScenario() throw(uno::RuntimeException)
8026 {
8027 	ScUnoGuard aGuard;
8028 	ScDocShell* pDocSh = GetDocShell();
8029 	if ( pDocSh )
8030 		return pDocSh->GetDocument()->IsScenario( GetTab_Impl() );
8031 
8032 	return sal_False;
8033 }
8034 
getScenarioComment()8035 rtl::OUString SAL_CALL ScTableSheetObj::getScenarioComment() throw(uno::RuntimeException)
8036 {
8037 	ScUnoGuard aGuard;
8038 	ScDocShell* pDocSh = GetDocShell();
8039 	if ( pDocSh )
8040 	{
8041 		String aComment;
8042 		Color  aColor;
8043 		sal_uInt16 nFlags;
8044 		pDocSh->GetDocument()->GetScenarioData( GetTab_Impl(), aComment, aColor, nFlags );
8045 		return aComment;
8046 	}
8047 	return rtl::OUString();
8048 }
8049 
setScenarioComment(const rtl::OUString & aScenarioComment)8050 void SAL_CALL ScTableSheetObj::setScenarioComment( const rtl::OUString& aScenarioComment )
8051 												throw(uno::RuntimeException)
8052 {
8053 	ScUnoGuard aGuard;
8054 	ScDocShell* pDocSh = GetDocShell();
8055 	if ( pDocSh )
8056 	{
8057 		ScDocument* pDoc = pDocSh->GetDocument();
8058 		SCTAB nTab = GetTab_Impl();
8059 
8060 		String aName;
8061 		String aComment;
8062 		Color  aColor;
8063 		sal_uInt16 nFlags;
8064 		pDoc->GetName( nTab, aName );
8065 		pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8066 
8067 		aComment = String( aScenarioComment );
8068 
8069 		pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8070 	}
8071 }
8072 
addRanges(const uno::Sequence<table::CellRangeAddress> & rScenRanges)8073 void SAL_CALL ScTableSheetObj::addRanges( const uno::Sequence<table::CellRangeAddress>& rScenRanges )
8074 												throw(uno::RuntimeException)
8075 {
8076 	ScUnoGuard aGuard;
8077 	ScDocShell* pDocSh = GetDocShell();
8078 	if ( pDocSh )
8079 	{
8080 		ScDocument* pDoc = pDocSh->GetDocument();
8081 		SCTAB nTab = GetTab_Impl();
8082 
8083 		if (pDoc->IsScenario(nTab))
8084 		{
8085     		ScMarkData aMarkData;
8086 	    	aMarkData.SelectTable( nTab, sal_True );
8087 
8088 		    sal_uInt16 nRangeCount = (sal_uInt16)rScenRanges.getLength();
8089     		if (nRangeCount)
8090 	    	{
8091 		    	const table::CellRangeAddress* pAry = rScenRanges.getConstArray();
8092 			    for (sal_uInt16 i=0; i<nRangeCount; i++)
8093     			{
8094 	    			DBG_ASSERT( pAry[i].Sheet == nTab, "addRanges mit falscher Tab" );
8095                     ScRange aOneRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
8096                                        (SCCOL)pAry[i].EndColumn,   (SCROW)pAry[i].EndRow,   nTab );
8097 
8098                     aMarkData.SetMultiMarkArea( aOneRange );
8099     			}
8100 	    	}
8101 
8102 		    //	Szenario-Ranges sind durch Attribut gekennzeichnet
8103     		ScPatternAttr aPattern( pDoc->GetPool() );
8104 	    	aPattern.GetItemSet().Put( ScMergeFlagAttr( SC_MF_SCENARIO ) );
8105 		    aPattern.GetItemSet().Put( ScProtectionAttr( sal_True ) );
8106     		ScDocFunc aFunc(*pDocSh);
8107 	    	aFunc.ApplyAttributes( aMarkData, aPattern, sal_True, sal_True );
8108     	}
8109 
8110         // don't use. We should use therefor a private interface, so we can also set the flags.
8111 /*    	else if (nTab > 0 && pDoc->IsImportingXML()) // make this sheet as an scenario and only if it is not the first sheet and only if it is ImportingXML,
8112             // because than no UNDO and repaint is necessary.
8113     	{
8114 		    sal_uInt16 nRangeCount = (sal_uInt16)rScenRanges.getLength();
8115     		if (nRangeCount)
8116 	    	{
8117         		pDoc->SetScenario( nTab, sal_True );
8118 
8119         		// default flags
8120         		Color aColor( COL_LIGHTGRAY );	// Default
8121 		        sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY;
8122 	        	String aComment;
8123 
8124     	    	pDoc->SetScenarioData( nTab, aComment, aColor, nFlags );
8125 		    	const table::CellRangeAddress* pAry = rScenRanges.getConstArray();
8126 			    for (sal_uInt16 i=0; i<nRangeCount; i++)
8127     			{
8128 	    			DBG_ASSERT( pAry[i].Sheet == nTab, "addRanges mit falscher Tab" );
8129         			pDoc->ApplyFlagsTab( (sal_uInt16)pAry[i].StartColumn, (sal_uInt16)pAry[i].StartRow,
8130 		        			(sal_uInt16)pAry[i].EndColumn, (sal_uInt16)pAry[i].EndRow, nTab, SC_MF_SCENARIO );
8131     		    }
8132     	    	pDoc->SetActiveScenario( nTab, sal_True );
8133 
8134     	    	// set to next visible tab
8135     	    	sal_uInt16 j = nTab - 1;
8136     	    	sal_Bool bFinished = sal_False;
8137     	    	while (j < nTab && !bFinished)
8138     	    	{
8139     	    	    if (pDoc->IsVisible(j))
8140     	    	    {
8141     	    	        pDoc->SetVisibleTab(j);
8142     	    	        bFinished = sal_True;
8143     	    	    }
8144     	    	    else
8145     	    	        --j;
8146     	    	}
8147 
8148                 ScDocFunc aFunc(*pDocSh);
8149                 aFunc.SetTableVisible( nTab, sal_False, sal_True );
8150     		}
8151     	}*/
8152     }
8153 }
8154 
apply()8155 void SAL_CALL ScTableSheetObj::apply() throw(uno::RuntimeException)
8156 {
8157 	ScUnoGuard aGuard;
8158 	ScDocShell* pDocSh = GetDocShell();
8159 	if ( pDocSh )
8160 	{
8161 		ScDocument* pDoc = pDocSh->GetDocument();
8162 		SCTAB nTab = GetTab_Impl();
8163 		String aName;
8164 		pDoc->GetName( nTab, aName );		// Name dieses Szenarios
8165 
8166 		SCTAB nDestTab = nTab;
8167 		while ( nDestTab > 0 && pDoc->IsScenario(nDestTab) )
8168 			--nDestTab;
8169 
8170 		if ( !pDoc->IsScenario(nDestTab) )
8171 			pDocSh->UseScenario( nDestTab, aName );
8172 
8173 		//!	sonst Fehler oder so
8174 	}
8175 }
8176 
8177 // XScenarioEnhanced
8178 
getRanges()8179 uno::Sequence< table::CellRangeAddress > SAL_CALL ScTableSheetObj::getRanges(  )
8180                                     throw(uno::RuntimeException)
8181 {
8182 	ScUnoGuard aGuard;
8183 	ScDocShell* pDocSh = GetDocShell();
8184 	if ( pDocSh )
8185 	{
8186 		ScDocument* pDoc = pDocSh->GetDocument();
8187 		SCTAB nTab = GetTab_Impl();
8188         const ScRangeList* pRangeList = pDoc->GetScenarioRanges(nTab);
8189         if (pRangeList)
8190         {
8191     		sal_Int32 nCount = pRangeList->Count();
8192             uno::Sequence< table::CellRangeAddress > aRetRanges(nCount);
8193 	    	table::CellRangeAddress* pAry = aRetRanges.getArray();
8194 	    	for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
8195 		    {
8196 			    const ScRange* pRange = pRangeList->GetObject( nIndex );
8197                 pAry->StartColumn = pRange->aStart.Col();
8198                 pAry->StartRow = pRange->aStart.Row();
8199                 pAry->EndColumn = pRange->aEnd.Col();
8200                 pAry->EndRow = pRange->aEnd.Row();
8201                 pAry->Sheet = pRange->aStart.Tab();
8202                 ++pAry;
8203             }
8204             return aRetRanges;
8205         }
8206     }
8207     return uno::Sequence< table::CellRangeAddress > ();
8208 }
8209 
8210 // XExternalSheetName
8211 
setExternalName(const::rtl::OUString & aUrl,const::rtl::OUString & aSheetName)8212 void ScTableSheetObj::setExternalName( const ::rtl::OUString& aUrl, const ::rtl::OUString& aSheetName )
8213     throw (container::ElementExistException, uno::RuntimeException)
8214 {
8215     ScUnoGuard aGuard;
8216     ScDocShell* pDocSh = GetDocShell();
8217     if ( pDocSh )
8218     {
8219         ScDocument* pDoc = pDocSh->GetDocument();
8220         if ( pDoc )
8221         {
8222             const SCTAB nTab = GetTab_Impl();
8223             const String aAbsDocName( ScGlobal::GetAbsDocName( aUrl, pDocSh ) );
8224             const String aDocTabName( ScGlobal::GetDocTabName( aAbsDocName, aSheetName ) );
8225             if ( !pDoc->RenameTab( nTab, aDocTabName, sal_False /*bUpdateRef*/, sal_True /*bExternalDocument*/ ) )
8226             {
8227                 throw container::ElementExistException( ::rtl::OUString(), *this );
8228             }
8229         }
8230     }
8231 }
8232 
8233 // XEventsSupplier
8234 
getEvents()8235 uno::Reference<container::XNameReplace> SAL_CALL ScTableSheetObj::getEvents() throw (uno::RuntimeException)
8236 {
8237     ScUnoGuard aGuard;
8238     ScDocShell* pDocSh = GetDocShell();
8239     if ( pDocSh )
8240         return new ScSheetEventsObj( pDocSh, GetTab_Impl() );
8241 
8242     return NULL;
8243 }
8244 
8245 // XPropertySet erweitert fuer Sheet-Properties
8246 
getPropertySetInfo()8247 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableSheetObj::getPropertySetInfo()
8248 														throw(uno::RuntimeException)
8249 {
8250 	ScUnoGuard aGuard;
8251 	static uno::Reference<beans::XPropertySetInfo> aRef(
8252 		new SfxItemPropertySetInfo( pSheetPropSet->getPropertyMap() ));
8253 	return aRef;
8254 }
8255 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)8256 void ScTableSheetObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
8257                                 throw(lang::IllegalArgumentException, uno::RuntimeException)
8258 {
8259     if ( pEntry )
8260     {
8261         if ( IsScItemWid( pEntry->nWID ) )
8262         {
8263             //  for Item WIDs, call ScCellRangesBase directly
8264             ScCellRangesBase::SetOnePropertyValue(pEntry, aValue);
8265             return;
8266         }
8267 
8268         //  own properties
8269 
8270         ScDocShell* pDocSh = GetDocShell();
8271         if (!pDocSh)
8272             return;                                                 //! Exception oder so?
8273         ScDocument* pDoc = pDocSh->GetDocument();
8274         SCTAB nTab = GetTab_Impl();
8275         ScDocFunc aFunc(*pDocSh);
8276 
8277         if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
8278         {
8279             rtl::OUString aStrVal;
8280             aValue >>= aStrVal;
8281             String aNewStr(ScStyleNameConversion::ProgrammaticToDisplayName(
8282                                                 aStrVal, SFX_STYLE_FAMILY_PAGE ));
8283 
8284             //! Undo? (auch bei SID_STYLE_APPLY an der View)
8285 
8286             if ( pDoc->GetPageStyle( nTab ) != aNewStr )
8287             {
8288                 pDoc->SetPageStyle( nTab, aNewStr );
8289                 if (!pDoc->IsImportingXML())
8290                 {
8291                     ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages();
8292 
8293                     SfxBindings* pBindings = pDocSh->GetViewBindings();
8294                     if (pBindings)
8295                     {
8296                         pBindings->Invalidate( SID_STYLE_FAMILY4 );
8297                         pBindings->Invalidate( SID_STATUS_PAGESTYLE );
8298                         pBindings->Invalidate( FID_RESET_PRINTZOOM );
8299                         pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
8300                         pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
8301                     }
8302                 }
8303                 pDocSh->SetDocumentModified();
8304             }
8305         }
8306         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
8307         {
8308             sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
8309             aFunc.SetTableVisible( nTab, bVis, sal_True );
8310         }
8311         else if ( pEntry->nWID == SC_WID_UNO_ISACTIVE )
8312         {
8313             if (pDoc->IsScenario(nTab))
8314                 pDoc->SetActiveScenario( nTab, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
8315         }
8316         else if ( pEntry->nWID == SC_WID_UNO_BORDCOL )
8317         {
8318             if (pDoc->IsScenario(nTab))
8319             {
8320                 sal_Int32 nNewColor = 0;
8321                 if (aValue >>= nNewColor)
8322                 {
8323                     String aName;
8324                     String aComment;
8325                     Color  aColor;
8326                     sal_uInt16 nFlags;
8327                     pDoc->GetName( nTab, aName );
8328                     pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8329 
8330                     aColor = Color(static_cast<sal_uInt32>(nNewColor));
8331 
8332                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8333                 }
8334             }
8335         }
8336         else if ( pEntry->nWID == SC_WID_UNO_PROTECT )
8337         {
8338             if (pDoc->IsScenario(nTab))
8339             {
8340                 String aName;
8341                 String aComment;
8342                 Color  aColor;
8343                 sal_uInt16 nFlags;
8344                 pDoc->GetName( nTab, aName );
8345                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8346                 sal_Bool bModify(sal_False);
8347 
8348                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8349                 {
8350                     if (!(nFlags & SC_SCENARIO_PROTECT))
8351                     {
8352                         nFlags |= SC_SCENARIO_PROTECT;
8353                         bModify = sal_True;
8354                     }
8355                 }
8356                 else
8357                 {
8358                     if (nFlags & SC_SCENARIO_PROTECT)
8359                     {
8360                         nFlags -= SC_SCENARIO_PROTECT;
8361                         bModify = sal_True;
8362                     }
8363                 }
8364 
8365                 if (bModify)
8366                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8367             }
8368         }
8369         else if ( pEntry->nWID == SC_WID_UNO_SHOWBORD )
8370         {
8371             if (pDoc->IsScenario(nTab))
8372             {
8373                 String aName;
8374                 String aComment;
8375                 Color  aColor;
8376                 sal_uInt16 nFlags;
8377                 pDoc->GetName( nTab, aName );
8378                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8379                 sal_Bool bModify(sal_False);
8380 
8381                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8382                 {
8383                     if (!(nFlags & SC_SCENARIO_SHOWFRAME))
8384                     {
8385                         nFlags |= SC_SCENARIO_SHOWFRAME;
8386                         bModify = sal_True;
8387                     }
8388                 }
8389                 else
8390                 {
8391                     if (nFlags & SC_SCENARIO_SHOWFRAME)
8392                     {
8393                         nFlags -= SC_SCENARIO_SHOWFRAME;
8394                         bModify = sal_True;
8395                     }
8396                 }
8397 
8398                 if (bModify)
8399                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8400             }
8401         }
8402         else if ( pEntry->nWID == SC_WID_UNO_PRINTBORD )
8403         {
8404             if (pDoc->IsScenario(nTab))
8405             {
8406                 String aName;
8407                 String aComment;
8408                 Color  aColor;
8409                 sal_uInt16 nFlags;
8410                 pDoc->GetName( nTab, aName );
8411                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8412                 sal_Bool bModify(sal_False);
8413 
8414                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8415                 {
8416                     if (!(nFlags & SC_SCENARIO_PRINTFRAME))
8417                     {
8418                         nFlags |= SC_SCENARIO_PRINTFRAME;
8419                         bModify = sal_True;
8420                     }
8421                 }
8422                 else
8423                 {
8424                     if (nFlags & SC_SCENARIO_PRINTFRAME)
8425                     {
8426                         nFlags -= SC_SCENARIO_PRINTFRAME;
8427                         bModify = sal_True;
8428                     }
8429                 }
8430 
8431                 if (bModify)
8432                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8433             }
8434         }
8435         else if ( pEntry->nWID == SC_WID_UNO_COPYBACK )
8436         {
8437             if (pDoc->IsScenario(nTab))
8438             {
8439                 String aName;
8440                 String aComment;
8441                 Color  aColor;
8442                 sal_uInt16 nFlags;
8443                 pDoc->GetName( nTab, aName );
8444                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8445                 sal_Bool bModify(sal_False);
8446 
8447                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8448                 {
8449                     if (!(nFlags & SC_SCENARIO_TWOWAY))
8450                     {
8451                         nFlags |= SC_SCENARIO_TWOWAY;
8452                         bModify = sal_True;
8453                     }
8454                 }
8455                 else
8456                 {
8457                     if (nFlags & SC_SCENARIO_TWOWAY)
8458                     {
8459                         nFlags -= SC_SCENARIO_TWOWAY;
8460                         bModify = sal_True;
8461                     }
8462                 }
8463 
8464                 if (bModify)
8465                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8466             }
8467         }
8468         else if ( pEntry->nWID == SC_WID_UNO_COPYSTYL )
8469         {
8470             if (pDoc->IsScenario(nTab))
8471             {
8472                 String aName;
8473                 String aComment;
8474                 Color  aColor;
8475                 sal_uInt16 nFlags;
8476                 pDoc->GetName( nTab, aName );
8477                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8478                 sal_Bool bModify(sal_False);
8479 
8480                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8481                 {
8482                     if (!(nFlags & SC_SCENARIO_ATTRIB))
8483                     {
8484                         nFlags |= SC_SCENARIO_ATTRIB;
8485                         bModify = sal_True;
8486                     }
8487                 }
8488                 else
8489                 {
8490                     if (nFlags & SC_SCENARIO_ATTRIB)
8491                     {
8492                         nFlags -= SC_SCENARIO_ATTRIB;
8493                         bModify = sal_True;
8494                     }
8495                 }
8496 
8497                 if (bModify)
8498                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8499             }
8500         }
8501         else if ( pEntry->nWID == SC_WID_UNO_COPYFORM )
8502         {
8503             if (pDoc->IsScenario(nTab))
8504             {
8505                 String aName;
8506                 String aComment;
8507                 Color  aColor;
8508                 sal_uInt16 nFlags;
8509                 pDoc->GetName( nTab, aName );
8510                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8511                 sal_Bool bModify(sal_False);
8512 
8513                 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
8514                 {
8515                     if (nFlags & SC_SCENARIO_VALUE)
8516                     {
8517                         nFlags -= SC_SCENARIO_VALUE;
8518                         bModify = sal_True;
8519                     }
8520                 }
8521                 else
8522                 {
8523                     if (!(nFlags & SC_SCENARIO_VALUE))
8524                     {
8525                         nFlags |= SC_SCENARIO_VALUE;
8526                         bModify = sal_True;
8527                     }
8528                 }
8529 
8530                 if (bModify)
8531                     pDocSh->ModifyScenario( nTab, aName, aComment, aColor, nFlags );
8532             }
8533         }
8534         else if ( pEntry->nWID == SC_WID_UNO_TABLAYOUT )
8535         {
8536             sal_Int16 nValue = 0;
8537             if (aValue >>= nValue)
8538             {
8539                 if (nValue == com::sun::star::text::WritingMode2::RL_TB)
8540                     aFunc.SetLayoutRTL(nTab, sal_True, sal_True);
8541                 else
8542                     aFunc.SetLayoutRTL(nTab, sal_False, sal_True);
8543             }
8544         }
8545         else if ( pEntry->nWID == SC_WID_UNO_AUTOPRINT )
8546         {
8547             sal_Bool bAutoPrint = ScUnoHelpFunctions::GetBoolFromAny( aValue );
8548             if (bAutoPrint)
8549                 pDoc->SetPrintEntireSheet( nTab ); // clears all print ranges
8550             else
8551             {
8552                 if (pDoc->IsPrintEntireSheet( nTab ))
8553                     pDoc->ClearPrintRanges( nTab ); // if this flag is true, there are no PrintRanges, so Clear clears only the flag.
8554             }
8555         }
8556         else if ( pEntry->nWID == SC_WID_UNO_TABCOLOR )
8557         {
8558             sal_Int32 nColor = COL_AUTO;
8559             if ( aValue >>= nColor )
8560             {
8561                 const Color aColor( static_cast< ColorData >( nColor ) );
8562                 if ( pDoc->GetTabBgColor( nTab ) != aColor )
8563                     aFunc.SetTabBgColor( nTab, aColor, sal_True, sal_True );
8564             }
8565         }
8566         else if ( pEntry->nWID == SC_WID_UNO_CODENAME )
8567         {
8568             rtl::OUString aCodeName;
8569             if ( pDocSh && ( aValue >>= aCodeName ) )
8570             {
8571                 pDocSh->GetDocument()->SetCodeName( GetTab_Impl(), aCodeName );
8572             }
8573         }
8574         else
8575             ScCellRangeObj::SetOnePropertyValue(pEntry, aValue);        // base class, no Item WID
8576     }
8577 }
8578 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)8579 void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
8580                                             uno::Any& rAny )
8581                                                 throw(uno::RuntimeException)
8582 {
8583     if ( pEntry )
8584     {
8585         ScDocShell* pDocSh = GetDocShell();
8586         if (!pDocSh)
8587             throw uno::RuntimeException();
8588         ScDocument* pDoc = pDocSh->GetDocument();
8589         SCTAB nTab = GetTab_Impl();
8590 
8591         if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
8592         {
8593             rAny <<= rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName(
8594                                 pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE ) );
8595         }
8596         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
8597         {
8598             sal_Bool bVis = pDoc->IsVisible( nTab );
8599             ScUnoHelpFunctions::SetBoolInAny( rAny, bVis );
8600         }
8601         else if ( pEntry->nWID == SC_WID_UNO_LINKDISPBIT )
8602         {
8603             //  no target bitmaps for individual entries (would be all equal)
8604             // ScLinkTargetTypeObj::SetLinkTargetBitmap( aAny, SC_LINKTARGETTYPE_SHEET );
8605         }
8606         else if ( pEntry->nWID == SC_WID_UNO_LINKDISPNAME )
8607         {
8608             //  LinkDisplayName for hyperlink dialog
8609             rAny <<= getName();     // sheet name
8610         }
8611         else if ( pEntry->nWID == SC_WID_UNO_ISACTIVE )
8612         {
8613             if (pDoc->IsScenario(nTab))
8614                 ScUnoHelpFunctions::SetBoolInAny( rAny, pDoc->IsActiveScenario( nTab ));
8615         }
8616         else if ( pEntry->nWID == SC_WID_UNO_BORDCOL )
8617         {
8618             if (pDoc->IsScenario(nTab))
8619             {
8620                 String aComment;
8621                 Color  aColor;
8622                 sal_uInt16 nFlags;
8623                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8624 
8625                 rAny <<= static_cast<sal_Int32>(aColor.GetColor());
8626             }
8627         }
8628         else if ( pEntry->nWID == SC_WID_UNO_PROTECT )
8629         {
8630             if (pDoc->IsScenario(nTab))
8631             {
8632                 String aComment;
8633                 Color  aColor;
8634                 sal_uInt16 nFlags;
8635                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8636 
8637                 ScUnoHelpFunctions::SetBoolInAny( rAny, (nFlags & SC_SCENARIO_PROTECT) != 0 );
8638             }
8639         }
8640         else if ( pEntry->nWID == SC_WID_UNO_SHOWBORD )
8641         {
8642             if (pDoc->IsScenario(nTab))
8643             {
8644                 String aComment;
8645                 Color  aColor;
8646                 sal_uInt16 nFlags;
8647                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8648 
8649                 ScUnoHelpFunctions::SetBoolInAny( rAny, (nFlags & SC_SCENARIO_SHOWFRAME) != 0 );
8650             }
8651         }
8652         else if ( pEntry->nWID == SC_WID_UNO_PRINTBORD )
8653         {
8654             if (pDoc->IsScenario(nTab))
8655             {
8656                 String aComment;
8657                 Color  aColor;
8658                 sal_uInt16 nFlags;
8659                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8660 
8661                 ScUnoHelpFunctions::SetBoolInAny( rAny, (nFlags & SC_SCENARIO_PRINTFRAME) != 0 );
8662             }
8663         }
8664         else if ( pEntry->nWID == SC_WID_UNO_COPYBACK )
8665         {
8666             if (pDoc->IsScenario(nTab))
8667             {
8668                 String aComment;
8669                 Color  aColor;
8670                 sal_uInt16 nFlags;
8671                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8672 
8673                 ScUnoHelpFunctions::SetBoolInAny( rAny, (nFlags & SC_SCENARIO_TWOWAY) != 0 );
8674             }
8675         }
8676         else if ( pEntry->nWID == SC_WID_UNO_COPYSTYL )
8677         {
8678             if (pDoc->IsScenario(nTab))
8679             {
8680                 String aComment;
8681                 Color  aColor;
8682                 sal_uInt16 nFlags;
8683                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8684 
8685                 ScUnoHelpFunctions::SetBoolInAny( rAny, (nFlags & SC_SCENARIO_ATTRIB) != 0 );
8686             }
8687         }
8688         else if ( pEntry->nWID == SC_WID_UNO_COPYFORM )
8689         {
8690             if (pDoc->IsScenario(nTab))
8691             {
8692                 String aComment;
8693                 Color  aColor;
8694                 sal_uInt16 nFlags;
8695                 pDoc->GetScenarioData( nTab, aComment, aColor, nFlags );
8696 
8697                 ScUnoHelpFunctions::SetBoolInAny( rAny, !(nFlags & SC_SCENARIO_VALUE));
8698             }
8699         }
8700         else if ( pEntry->nWID == SC_WID_UNO_TABLAYOUT )
8701         {
8702             if (pDoc->IsLayoutRTL(nTab))
8703                 rAny <<= sal_Int16(com::sun::star::text::WritingMode2::RL_TB);
8704             else
8705                 rAny <<= sal_Int16(com::sun::star::text::WritingMode2::LR_TB);
8706         }
8707         else if ( pEntry->nWID == SC_WID_UNO_AUTOPRINT )
8708         {
8709             sal_Bool bAutoPrint = pDoc->IsPrintEntireSheet( nTab );
8710             ScUnoHelpFunctions::SetBoolInAny( rAny, bAutoPrint );
8711         }
8712         else if ( pEntry->nWID == SC_WID_UNO_TABCOLOR )
8713         {
8714             rAny <<= sal_Int32(pDoc->GetTabBgColor(nTab).GetColor());
8715         }
8716         else if ( pEntry->nWID == SC_WID_UNO_CODENAME )
8717         {
8718             String aCodeName;
8719             if ( pDocSh )
8720                 pDocSh->GetDocument()->GetCodeName( GetTab_Impl(), aCodeName );
8721             rAny <<= rtl::OUString( aCodeName );
8722         }
8723         else
8724             ScCellRangeObj::GetOnePropertyValue(pEntry, rAny);
8725     }
8726 }
8727 
GetItemPropertyMap()8728 const SfxItemPropertyMap* ScTableSheetObj::GetItemPropertyMap()
8729 {
8730     return pSheetPropSet->getPropertyMap();
8731 }
8732 
8733 // XServiceInfo
8734 
getImplementationName()8735 rtl::OUString SAL_CALL ScTableSheetObj::getImplementationName() throw(uno::RuntimeException)
8736 {
8737 	return rtl::OUString::createFromAscii( "ScTableSheetObj" );
8738 }
8739 
supportsService(const rtl::OUString & rServiceName)8740 sal_Bool SAL_CALL ScTableSheetObj::supportsService( const rtl::OUString& rServiceName )
8741 													throw(uno::RuntimeException)
8742 {
8743 	String aServiceStr( rServiceName );
8744 	return aServiceStr.EqualsAscii( SCSPREADSHEET_SERVICE ) ||
8745 		   aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) ||
8746 		   aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE ) ||
8747 		   aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) ||
8748 		   aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) ||
8749 		   aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ) ||
8750 		   aServiceStr.EqualsAscii( SCLINKTARGET_SERVICE );
8751 }
8752 
getSupportedServiceNames()8753 uno::Sequence<rtl::OUString> SAL_CALL ScTableSheetObj::getSupportedServiceNames()
8754 													throw(uno::RuntimeException)
8755 {
8756 	uno::Sequence<rtl::OUString> aRet(7);
8757 	rtl::OUString* pArray = aRet.getArray();
8758 	pArray[0] = rtl::OUString::createFromAscii( SCSPREADSHEET_SERVICE );
8759 	pArray[1] = rtl::OUString::createFromAscii( SCSHEETCELLRANGE_SERVICE );
8760 	pArray[2] = rtl::OUString::createFromAscii( SCCELLRANGE_SERVICE );
8761 	pArray[3] = rtl::OUString::createFromAscii( SCCELLPROPERTIES_SERVICE );
8762 	pArray[4] = rtl::OUString::createFromAscii( SCCHARPROPERTIES_SERVICE );
8763 	pArray[5] = rtl::OUString::createFromAscii( SCPARAPROPERTIES_SERVICE );
8764 	pArray[6] = rtl::OUString::createFromAscii( SCLINKTARGET_SERVICE );
8765 	return aRet;
8766 }
8767 
8768 // XUnoTunnel
8769 
getSomething(const uno::Sequence<sal_Int8> & rId)8770 sal_Int64 SAL_CALL ScTableSheetObj::getSomething(
8771 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
8772 {
8773 	if ( rId.getLength() == 16 &&
8774           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
8775 									rId.getConstArray(), 16 ) )
8776 	{
8777         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
8778 	}
8779 
8780 	return ScCellRangeObj::getSomething( rId );
8781 }
8782 
8783 // static
getUnoTunnelId()8784 const uno::Sequence<sal_Int8>& ScTableSheetObj::getUnoTunnelId()
8785 {
8786 	static uno::Sequence<sal_Int8> * pSeq = 0;
8787 	if( !pSeq )
8788 	{
8789 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
8790 		if( !pSeq )
8791 		{
8792 			static uno::Sequence< sal_Int8 > aSeq( 16 );
8793 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
8794 			pSeq = &aSeq;
8795 		}
8796 	}
8797 	return *pSeq;
8798 }
8799 
8800 // static
getImplementation(const uno::Reference<uno::XInterface> xObj)8801 ScTableSheetObj* ScTableSheetObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
8802 {
8803 	ScTableSheetObj* pRet = NULL;
8804 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
8805 	if (xUT.is())
8806         pRet = reinterpret_cast<ScTableSheetObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
8807 	return pRet;
8808 }
8809 
8810 //------------------------------------------------------------------------
8811 
ScTableColumnObj(ScDocShell * pDocSh,SCCOL nCol,SCTAB nTab)8812 ScTableColumnObj::ScTableColumnObj( ScDocShell* pDocSh, SCCOL nCol, SCTAB nTab ) :
8813 	ScCellRangeObj( pDocSh, ScRange(nCol,0,nTab, nCol,MAXROW,nTab) ),
8814 	pColPropSet(lcl_GetColumnPropertySet())
8815 {
8816 }
8817 
~ScTableColumnObj()8818 ScTableColumnObj::~ScTableColumnObj()
8819 {
8820 }
8821 
queryInterface(const uno::Type & rType)8822 uno::Any SAL_CALL ScTableColumnObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
8823 {
8824 	SC_QUERYINTERFACE( container::XNamed )
8825 
8826 	return ScCellRangeObj::queryInterface( rType );
8827 }
8828 
acquire()8829 void SAL_CALL ScTableColumnObj::acquire() throw()
8830 {
8831 	ScCellRangeObj::acquire();
8832 }
8833 
release()8834 void SAL_CALL ScTableColumnObj::release() throw()
8835 {
8836 	ScCellRangeObj::release();
8837 }
8838 
getTypes()8839 uno::Sequence<uno::Type> SAL_CALL ScTableColumnObj::getTypes() throw(uno::RuntimeException)
8840 {
8841 	static uno::Sequence<uno::Type> aTypes;
8842 	if ( aTypes.getLength() == 0 )
8843 	{
8844 		uno::Sequence<uno::Type> aParentTypes(ScCellRangeObj::getTypes());
8845 		long nParentLen = aParentTypes.getLength();
8846 		const uno::Type* pParentPtr = aParentTypes.getConstArray();
8847 
8848 		aTypes.realloc( nParentLen + 1 );
8849 		uno::Type* pPtr = aTypes.getArray();
8850 		pPtr[nParentLen + 0] = getCppuType((const uno::Reference<container::XNamed>*)0);
8851 
8852 		for (long i=0; i<nParentLen; i++)
8853 			pPtr[i] = pParentPtr[i];				// parent types first
8854 	}
8855 	return aTypes;
8856 }
8857 
getImplementationId()8858 uno::Sequence<sal_Int8> SAL_CALL ScTableColumnObj::getImplementationId() throw(uno::RuntimeException)
8859 {
8860 	static uno::Sequence< sal_Int8 > aId;
8861 	if( aId.getLength() == 0 )
8862 	{
8863 		aId.realloc( 16 );
8864 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
8865 	}
8866 	return aId;
8867 }
8868 
8869 // XNamed
8870 
getName()8871 rtl::OUString SAL_CALL ScTableColumnObj::getName() throw(uno::RuntimeException)
8872 {
8873 	ScUnoGuard aGuard;
8874 
8875 	const ScRange& rRange = GetRange();
8876 	DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "too many columns");
8877 	SCCOL nCol = rRange.aStart.Col();
8878 
8879 	return ScColToAlpha( nCol );		// from global.hxx
8880 }
8881 
setName(const rtl::OUString &)8882 void SAL_CALL ScTableColumnObj::setName( const rtl::OUString& /* aNewName */ )
8883 												throw(uno::RuntimeException)
8884 {
8885 	ScUnoGuard aGuard;
8886 	throw uno::RuntimeException();		// read-only
8887 }
8888 
8889 // XPropertySet erweitert fuer Spalten-Properties
8890 
getPropertySetInfo()8891 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnObj::getPropertySetInfo()
8892 														throw(uno::RuntimeException)
8893 {
8894 	ScUnoGuard aGuard;
8895 	static uno::Reference<beans::XPropertySetInfo> aRef(
8896 		new SfxItemPropertySetInfo( pColPropSet->getPropertyMap() ));
8897 	return aRef;
8898 }
8899 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)8900 void ScTableColumnObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
8901 								throw(lang::IllegalArgumentException, uno::RuntimeException)
8902 {
8903     if ( pEntry )
8904 	{
8905         if ( IsScItemWid( pEntry->nWID ) )
8906 		{
8907 			//	for Item WIDs, call ScCellRangesBase directly
8908             ScCellRangesBase::SetOnePropertyValue(pEntry, aValue);
8909 			return;
8910 		}
8911 
8912 		//	own properties
8913 
8914 		ScDocShell* pDocSh = GetDocShell();
8915 		if (!pDocSh)
8916 			return;													//!	Exception oder so?
8917 		const ScRange& rRange = GetRange();
8918 		DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "zuviele Spalten");
8919 		SCCOL nCol = rRange.aStart.Col();
8920 		SCTAB nTab = rRange.aStart.Tab();
8921 		ScDocFunc aFunc(*pDocSh);
8922 
8923 		SCCOLROW nColArr[2];
8924 		nColArr[0] = nColArr[1] = nCol;
8925 
8926         if ( pEntry->nWID == SC_WID_UNO_CELLWID )
8927 		{
8928 			sal_Int32 nNewWidth = 0;
8929 			if ( aValue >>= nNewWidth )
8930 			{
8931 				//	property is 1/100mm, column width is twips
8932 				nNewWidth = HMMToTwips(nNewWidth);
8933 				aFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, SC_SIZE_ORIGINAL,
8934 										(sal_uInt16)nNewWidth, sal_True, sal_True );
8935 			}
8936 		}
8937         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
8938 		{
8939 			sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
8940 			ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
8941 			aFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, eMode, 0, sal_True, sal_True );
8942 			//	SC_SIZE_DIRECT mit Groesse 0 blendet aus
8943 		}
8944         else if ( pEntry->nWID == SC_WID_UNO_OWIDTH )
8945 		{
8946 			sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
8947 			if (bOpt)
8948 				aFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab,
8949 										SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, sal_True, sal_True );
8950 			// sal_False bei Spalten momentan ohne Auswirkung
8951 		}
8952         else if ( pEntry->nWID == SC_WID_UNO_NEWPAGE || pEntry->nWID == SC_WID_UNO_MANPAGE )
8953 		{
8954 			sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
8955 			if (bSet)
8956 				aFunc.InsertPageBreak( sal_True, rRange.aStart, sal_True, sal_True, sal_True );
8957 			else
8958 				aFunc.RemovePageBreak( sal_True, rRange.aStart, sal_True, sal_True, sal_True );
8959 		}
8960 		else
8961             ScCellRangeObj::SetOnePropertyValue(pEntry, aValue);        // base class, no Item WID
8962 	}
8963 }
8964 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)8965 void ScTableColumnObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
8966 											uno::Any& rAny )
8967 												throw(uno::RuntimeException)
8968 {
8969     if ( pEntry )
8970 	{
8971 		ScDocShell* pDocSh = GetDocShell();
8972 		if (!pDocSh)
8973 			throw uno::RuntimeException();
8974 
8975 		ScDocument* pDoc = pDocSh->GetDocument();
8976 		const ScRange& rRange = GetRange();
8977 		DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "zuviele Spalten");
8978 		SCCOL nCol = rRange.aStart.Col();
8979 		SCTAB nTab = rRange.aStart.Tab();
8980 
8981         if ( pEntry->nWID == SC_WID_UNO_CELLWID )
8982 		{
8983 			// for hidden column, return original height
8984 			sal_uInt16 nWidth = pDoc->GetOriginalWidth( nCol, nTab );
8985 			//	property is 1/100mm, column width is twips
8986 			nWidth = (sal_uInt16) TwipsToHMM(nWidth);
8987 			rAny <<= (sal_Int32)( nWidth );
8988 		}
8989         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
8990 		{
8991 			SCCOL nDummy;
8992 			bool bHidden = pDoc->ColHidden(nCol, nTab, nDummy);
8993 			ScUnoHelpFunctions::SetBoolInAny( rAny, !bHidden );
8994 		}
8995         else if ( pEntry->nWID == SC_WID_UNO_OWIDTH )
8996 		{
8997 			//!	momentan immer gesetzt ??!?!
8998 			sal_Bool bOpt = !(pDoc->GetColFlags( nCol, nTab ) & CR_MANUALSIZE);
8999 			ScUnoHelpFunctions::SetBoolInAny( rAny, bOpt );
9000 		}
9001         else if ( pEntry->nWID == SC_WID_UNO_NEWPAGE )
9002 		{
9003             ScBreakType nBreak = pDoc->HasColBreak(nCol, nTab);
9004             ScUnoHelpFunctions::SetBoolInAny( rAny, nBreak );
9005 		}
9006         else if ( pEntry->nWID == SC_WID_UNO_MANPAGE )
9007 		{
9008             ScBreakType nBreak = pDoc->HasColBreak(nCol, nTab);
9009             ScUnoHelpFunctions::SetBoolInAny(rAny, (nBreak & BREAK_MANUAL));
9010 		}
9011 		else
9012             ScCellRangeObj::GetOnePropertyValue(pEntry, rAny);
9013 	}
9014 }
9015 
GetItemPropertyMap()9016 const SfxItemPropertyMap* ScTableColumnObj::GetItemPropertyMap()
9017 {
9018     return pColPropSet->getPropertyMap();
9019 }
9020 
9021 //------------------------------------------------------------------------
9022 
ScTableRowObj(ScDocShell * pDocSh,SCROW nRow,SCTAB nTab)9023 ScTableRowObj::ScTableRowObj(ScDocShell* pDocSh, SCROW nRow, SCTAB nTab) :
9024 	ScCellRangeObj( pDocSh, ScRange(0,nRow,nTab, MAXCOL,nRow,nTab) ),
9025 	pRowPropSet(lcl_GetRowPropertySet())
9026 {
9027 }
9028 
~ScTableRowObj()9029 ScTableRowObj::~ScTableRowObj()
9030 {
9031 }
9032 
9033 // XPropertySet erweitert fuer Zeilen-Properties
9034 
getPropertySetInfo()9035 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowObj::getPropertySetInfo()
9036 														throw(uno::RuntimeException)
9037 {
9038 	ScUnoGuard aGuard;
9039 	static uno::Reference<beans::XPropertySetInfo> aRef(
9040 		new SfxItemPropertySetInfo( pRowPropSet->getPropertyMap() ));
9041 	return aRef;
9042 }
9043 
SetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)9044 void ScTableRowObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue )
9045 								throw(lang::IllegalArgumentException, uno::RuntimeException)
9046 {
9047     if ( pEntry )
9048 	{
9049         if ( IsScItemWid( pEntry->nWID ) )
9050 		{
9051 			//	for Item WIDs, call ScCellRangesBase directly
9052             ScCellRangesBase::SetOnePropertyValue(pEntry, aValue);
9053 			return;
9054 		}
9055 
9056 		//	own properties
9057 
9058 		ScDocShell* pDocSh = GetDocShell();
9059 		if (!pDocSh)
9060 			return;													//!	Exception oder so?
9061 		ScDocument* pDoc = pDocSh->GetDocument();
9062 		const ScRange& rRange = GetRange();
9063 		DBG_ASSERT(rRange.aStart.Row() == rRange.aEnd.Row(), "zuviele Zeilen");
9064 		SCROW nRow = rRange.aStart.Row();
9065 		SCTAB nTab = rRange.aStart.Tab();
9066 		ScDocFunc aFunc(*pDocSh);
9067 
9068 		SCCOLROW nRowArr[2];
9069 		nRowArr[0] = nRowArr[1] = nRow;
9070 
9071         if ( pEntry->nWID == SC_WID_UNO_CELLHGT )
9072 		{
9073 			sal_Int32 nNewHeight = 0;
9074 			if ( aValue >>= nNewHeight )
9075 			{
9076 				//	property is 1/100mm, row height is twips
9077 				nNewHeight = HMMToTwips(nNewHeight);
9078 				aFunc.SetWidthOrHeight( sal_False, 1, nRowArr, nTab, SC_SIZE_ORIGINAL,
9079 										(sal_uInt16)nNewHeight, sal_True, sal_True );
9080 			}
9081 		}
9082         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
9083 		{
9084 			sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
9085 			ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
9086 			aFunc.SetWidthOrHeight( sal_False, 1, nRowArr, nTab, eMode, 0, sal_True, sal_True );
9087 			//	SC_SIZE_DIRECT mit Groesse 0 blendet aus
9088 		}
9089         else if ( pEntry->nWID == SC_WID_UNO_CELLFILT )
9090 		{
9091 			sal_Bool bFil = ScUnoHelpFunctions::GetBoolFromAny( aValue );
9092 //			ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
9093 //			aFunc.SetWidthOrHeight( sal_False, 1, nRowArr, nTab, eMode, 0, sal_True, sal_True );
9094 			//	SC_SIZE_DIRECT mit Groesse 0 blendet aus
9095             pDoc->SetRowFiltered(nRow, nRow, nTab, bFil);
9096 		}
9097         else if ( pEntry->nWID == SC_WID_UNO_OHEIGHT )
9098 		{
9099 			sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
9100 			if (bOpt)
9101 				aFunc.SetWidthOrHeight( sal_False, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, sal_True, sal_True );
9102 			else
9103 			{
9104 				//	set current height again manually
9105 				sal_uInt16 nHeight = pDoc->GetOriginalHeight( nRow, nTab );
9106 				aFunc.SetWidthOrHeight( sal_False, 1, nRowArr, nTab, SC_SIZE_ORIGINAL, nHeight, sal_True, sal_True );
9107 			}
9108 		}
9109         else if ( pEntry->nWID == SC_WID_UNO_NEWPAGE || pEntry->nWID == SC_WID_UNO_MANPAGE )
9110 		{
9111 			sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
9112 			if (bSet)
9113 				aFunc.InsertPageBreak( sal_False, rRange.aStart, sal_True, sal_True, sal_True );
9114 			else
9115 				aFunc.RemovePageBreak( sal_False, rRange.aStart, sal_True, sal_True, sal_True );
9116 		}
9117 		else
9118             ScCellRangeObj::SetOnePropertyValue(pEntry, aValue);        // base class, no Item WID
9119 	}
9120 }
9121 
GetOnePropertyValue(const SfxItemPropertySimpleEntry * pEntry,uno::Any & rAny)9122 void ScTableRowObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntry,
9123 										uno::Any& rAny )
9124 												throw(uno::RuntimeException)
9125 {
9126     if ( pEntry )
9127 	{
9128 		ScDocShell* pDocSh = GetDocShell();
9129 		if (!pDocSh)
9130 			throw uno::RuntimeException();
9131 		ScDocument* pDoc = pDocSh->GetDocument();
9132 		const ScRange& rRange = GetRange();
9133 		DBG_ASSERT(rRange.aStart.Row() == rRange.aEnd.Row(), "zuviele Zeilen");
9134 		SCROW nRow = rRange.aStart.Row();
9135 		SCTAB nTab = rRange.aStart.Tab();
9136 
9137         if ( pEntry->nWID == SC_WID_UNO_CELLHGT )
9138 		{
9139 			// for hidden row, return original height
9140 			sal_uInt16 nHeight = pDoc->GetOriginalHeight( nRow, nTab );
9141 			//	property is 1/100mm, row height is twips
9142 			nHeight = (sal_uInt16) TwipsToHMM(nHeight);
9143 			rAny <<= (sal_Int32)( nHeight );
9144 		}
9145         else if ( pEntry->nWID == SC_WID_UNO_CELLVIS )
9146 		{
9147             SCROW nDummy;
9148             bool bHidden = pDoc->RowHidden(nRow, nTab, nDummy);
9149             ScUnoHelpFunctions::SetBoolInAny( rAny, !bHidden );
9150 		}
9151         else if ( pEntry->nWID == SC_WID_UNO_CELLFILT )
9152 		{
9153             bool bVis = pDoc->RowFiltered(nRow, nTab);
9154 			ScUnoHelpFunctions::SetBoolInAny( rAny, bVis );
9155 		}
9156         else if ( pEntry->nWID == SC_WID_UNO_OHEIGHT )
9157 		{
9158 			sal_Bool bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CR_MANUALSIZE);
9159 			ScUnoHelpFunctions::SetBoolInAny( rAny, bOpt );
9160 		}
9161         else if ( pEntry->nWID == SC_WID_UNO_NEWPAGE )
9162 		{
9163             ScBreakType nBreak = pDoc->HasRowBreak(nRow, nTab);
9164             ScUnoHelpFunctions::SetBoolInAny( rAny, nBreak );
9165 		}
9166         else if ( pEntry->nWID == SC_WID_UNO_MANPAGE )
9167 		{
9168             ScBreakType nBreak = (pDoc->HasRowBreak(nRow, nTab) & BREAK_MANUAL);
9169             ScUnoHelpFunctions::SetBoolInAny( rAny, nBreak );
9170 		}
9171 		else
9172             ScCellRangeObj::GetOnePropertyValue(pEntry, rAny);
9173 	}
9174 }
9175 
GetItemPropertyMap()9176 const SfxItemPropertyMap* ScTableRowObj::GetItemPropertyMap()
9177 {
9178     return pRowPropSet->getPropertyMap();
9179 }
9180 
9181 //------------------------------------------------------------------------
9182 
ScCellsObj(ScDocShell * pDocSh,const ScRangeList & rR)9183 ScCellsObj::ScCellsObj(ScDocShell* pDocSh, const ScRangeList& rR) :
9184 	pDocShell( pDocSh ),
9185 	aRanges( rR )
9186 {
9187 	pDocShell->GetDocument()->AddUnoObject(*this);
9188 }
9189 
~ScCellsObj()9190 ScCellsObj::~ScCellsObj()
9191 {
9192 	if (pDocShell)
9193 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9194 }
9195 
Notify(SfxBroadcaster &,const SfxHint & rHint)9196 void ScCellsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
9197 {
9198 	if ( rHint.ISA( ScUpdateRefHint ) )
9199 	{
9200 		const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
9201 		aRanges.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(),
9202 										rRef.GetDx(), rRef.GetDy(), rRef.GetDz() );
9203 	}
9204 	else if ( rHint.ISA( SfxSimpleHint ) &&
9205 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
9206 	{
9207 		pDocShell = NULL;		// ungueltig geworden
9208 	}
9209 }
9210 
9211 // XEnumerationAccess
9212 
createEnumeration()9213 uno::Reference<container::XEnumeration> SAL_CALL ScCellsObj::createEnumeration()
9214 													throw(uno::RuntimeException)
9215 {
9216 	ScUnoGuard aGuard;
9217 	if (pDocShell)
9218 		return new ScCellsEnumeration( pDocShell, aRanges );
9219 	return NULL;
9220 }
9221 
getElementType()9222 uno::Type SAL_CALL ScCellsObj::getElementType() throw(uno::RuntimeException)
9223 {
9224 	ScUnoGuard aGuard;
9225 	return getCppuType((uno::Reference<table::XCell>*)0);
9226 }
9227 
hasElements()9228 sal_Bool SAL_CALL ScCellsObj::hasElements() throw(uno::RuntimeException)
9229 {
9230 	ScUnoGuard aGuard;
9231 	sal_Bool bHas = sal_False;
9232 	if ( pDocShell )
9233 	{
9234 		//!	schneller selber testen?
9235 
9236 		uno::Reference<container::XEnumeration> xEnum(new ScCellsEnumeration( pDocShell, aRanges ));
9237 		bHas = xEnum->hasMoreElements();
9238 	}
9239 	return bHas;
9240 }
9241 
9242 //------------------------------------------------------------------------
9243 
ScCellsEnumeration(ScDocShell * pDocSh,const ScRangeList & rR)9244 ScCellsEnumeration::ScCellsEnumeration(ScDocShell* pDocSh, const ScRangeList& rR) :
9245 	pDocShell( pDocSh ),
9246 	aRanges( rR ),
9247 	pMark( NULL ),
9248 	bAtEnd( sal_False )
9249 {
9250 	ScDocument* pDoc = pDocShell->GetDocument();
9251 	pDoc->AddUnoObject(*this);
9252 
9253 	if ( aRanges.Count() == 0 )
9254 		bAtEnd = sal_True;
9255 	else
9256 	{
9257 		SCTAB nTab = 0;
9258 		const ScRange* pFirst = aRanges.GetObject(0);
9259 		if (pFirst)
9260 			nTab = pFirst->aStart.Tab();
9261 		aPos = ScAddress(0,0,nTab);
9262 		CheckPos_Impl();					// aPos auf erste passende Zelle setzen
9263 	}
9264 }
9265 
CheckPos_Impl()9266 void ScCellsEnumeration::CheckPos_Impl()
9267 {
9268 	if (pDocShell)
9269 	{
9270 		sal_Bool bFound = sal_False;
9271 		ScDocument* pDoc = pDocShell->GetDocument();
9272 		ScBaseCell* pCell = pDoc->GetCell(aPos);
9273 		if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE )
9274 		{
9275 			if (!pMark)
9276 			{
9277 				pMark = new ScMarkData;
9278 				pMark->MarkFromRangeList( aRanges, sal_False );
9279 				pMark->MarkToMulti();	// needed for GetNextMarkedCell
9280 			}
9281 			bFound = pMark->IsCellMarked( aPos.Col(), aPos.Row() );
9282 		}
9283 		if (!bFound)
9284 			Advance_Impl();
9285 	}
9286 }
9287 
~ScCellsEnumeration()9288 ScCellsEnumeration::~ScCellsEnumeration()
9289 {
9290 	if (pDocShell)
9291 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9292 	delete pMark;
9293 }
9294 
Advance_Impl()9295 void ScCellsEnumeration::Advance_Impl()
9296 {
9297 	DBG_ASSERT(!bAtEnd,"zuviel Advance_Impl");
9298 	if (!pMark)
9299 	{
9300 		pMark = new ScMarkData;
9301 		pMark->MarkFromRangeList( aRanges, sal_False );
9302 		pMark->MarkToMulti();	// needed for GetNextMarkedCell
9303 	}
9304 
9305 	SCCOL nCol = aPos.Col();
9306 	SCROW nRow = aPos.Row();
9307 	SCTAB nTab = aPos.Tab();
9308 	sal_Bool bFound = pDocShell->GetDocument()->GetNextMarkedCell( nCol, nRow, nTab, *pMark );
9309 	if (bFound)
9310 		aPos.Set( nCol, nRow, nTab );
9311 	else
9312 		bAtEnd = sal_True;		// kommt nix mehr
9313 }
9314 
Notify(SfxBroadcaster &,const SfxHint & rHint)9315 void ScCellsEnumeration::Notify( SfxBroadcaster&, const SfxHint& rHint )
9316 {
9317 	if ( rHint.ISA( ScUpdateRefHint ) )
9318 	{
9319 		if (pDocShell)
9320 		{
9321 			const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
9322 			aRanges.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(),
9323 											rRef.GetDx(), rRef.GetDy(), rRef.GetDz() );
9324 
9325 			delete pMark;		// aus verschobenen Bereichen neu erzeugen
9326 			pMark = NULL;
9327 
9328 			if (!bAtEnd)		// aPos anpassen
9329 			{
9330 				ScRangeList aNew;
9331 				aNew.Append(ScRange(aPos));
9332 				aNew.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(),
9333 										rRef.GetDx(), rRef.GetDy(), rRef.GetDz() );
9334 				if (aNew.Count()==1)
9335 				{
9336 					aPos = aNew.GetObject(0)->aStart;
9337 					CheckPos_Impl();
9338 				}
9339 			}
9340 		}
9341 	}
9342 	else if ( rHint.ISA( SfxSimpleHint ) &&
9343 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
9344 	{
9345 		pDocShell = NULL;		// ungueltig geworden
9346 	}
9347 }
9348 
9349 // XEnumeration
9350 
hasMoreElements()9351 sal_Bool SAL_CALL ScCellsEnumeration::hasMoreElements() throw(uno::RuntimeException)
9352 {
9353 	ScUnoGuard aGuard;
9354 	return !bAtEnd;
9355 }
9356 
nextElement()9357 uno::Any SAL_CALL ScCellsEnumeration::nextElement() throw(container::NoSuchElementException,
9358 										lang::WrappedTargetException, uno::RuntimeException)
9359 {
9360 	ScUnoGuard aGuard;
9361 	if (pDocShell && !bAtEnd)
9362 	{
9363 		// Interface-Typ muss zu ScCellsObj::getElementType passen
9364 
9365         ScAddress aTempPos(aPos);
9366 		Advance_Impl();
9367         return uno::makeAny(uno::Reference<table::XCell>(new ScCellObj( pDocShell, aTempPos )));
9368 	}
9369 
9370 	throw container::NoSuchElementException();		// no more elements
9371 //    return uno::Any();
9372 }
9373 
9374 //------------------------------------------------------------------------
9375 
ScCellFormatsObj(ScDocShell * pDocSh,const ScRange & rRange)9376 ScCellFormatsObj::ScCellFormatsObj(ScDocShell* pDocSh, const ScRange& rRange) :
9377 	pDocShell( pDocSh ),
9378 	aTotalRange( rRange )
9379 {
9380 	ScDocument* pDoc = pDocShell->GetDocument();
9381 	pDoc->AddUnoObject(*this);
9382 
9383 	DBG_ASSERT( aTotalRange.aStart.Tab() == aTotalRange.aEnd.Tab(), "unterschiedliche Tabellen" );
9384 }
9385 
~ScCellFormatsObj()9386 ScCellFormatsObj::~ScCellFormatsObj()
9387 {
9388 	if (pDocShell)
9389 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9390 }
9391 
Notify(SfxBroadcaster &,const SfxHint & rHint)9392 void ScCellFormatsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
9393 {
9394 	if ( rHint.ISA( ScUpdateRefHint ) )
9395 	{
9396 		//!	aTotalRange...
9397 	}
9398 	else if ( rHint.ISA( SfxSimpleHint ) &&
9399 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
9400 	{
9401 		pDocShell = NULL;		// ungueltig geworden
9402 	}
9403 }
9404 
GetObjectByIndex_Impl(long nIndex) const9405 ScCellRangeObj* ScCellFormatsObj::GetObjectByIndex_Impl(long nIndex) const
9406 {
9407 	//!	direkt auf die AttrArrays zugreifen !!!!
9408 
9409 	ScCellRangeObj* pRet = NULL;
9410 	if (pDocShell)
9411 	{
9412 		ScDocument* pDoc = pDocShell->GetDocument();
9413 		long nPos = 0;
9414 		ScAttrRectIterator aIter( pDoc, aTotalRange.aStart.Tab(),
9415 									aTotalRange.aStart.Col(), aTotalRange.aStart.Row(),
9416 									aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() );
9417         SCCOL nCol1, nCol2;
9418         SCROW nRow1, nRow2;
9419         while ( aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) )
9420 		{
9421 			if ( nPos == nIndex )
9422 			{
9423 				SCTAB nTab = aTotalRange.aStart.Tab();
9424 				ScRange aNext( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
9425 
9426 				if ( aNext.aStart == aNext.aEnd )
9427 					pRet = new ScCellObj( pDocShell, aNext.aStart );
9428 				else
9429 					pRet = new ScCellRangeObj( pDocShell, aNext );
9430 			}
9431 			++nPos;
9432 		}
9433 	}
9434 	return pRet;
9435 }
9436 
9437 // XIndexAccess
9438 
getCount()9439 sal_Int32 SAL_CALL ScCellFormatsObj::getCount() throw(uno::RuntimeException)
9440 {
9441 	ScUnoGuard aGuard;
9442 
9443 	//!	direkt auf die AttrArrays zugreifen !!!!
9444 
9445 	long nCount = 0;
9446 	if (pDocShell)
9447 	{
9448 		ScDocument* pDoc = pDocShell->GetDocument();
9449 		ScAttrRectIterator aIter( pDoc, aTotalRange.aStart.Tab(),
9450 									aTotalRange.aStart.Col(), aTotalRange.aStart.Row(),
9451 									aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() );
9452         SCCOL nCol1, nCol2;
9453         SCROW nRow1, nRow2;
9454         while ( aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) )
9455 			++nCount;
9456 	}
9457 	return nCount;
9458 }
9459 
getByIndex(sal_Int32 nIndex)9460 uno::Any SAL_CALL ScCellFormatsObj::getByIndex( sal_Int32 nIndex )
9461 							throw(lang::IndexOutOfBoundsException,
9462 									lang::WrappedTargetException, uno::RuntimeException)
9463 {
9464 	ScUnoGuard aGuard;
9465 
9466 	uno::Reference<table::XCellRange> xRange(GetObjectByIndex_Impl(nIndex));
9467 	if (xRange.is())
9468         return uno::makeAny(xRange);
9469 	else
9470 		throw lang::IndexOutOfBoundsException();
9471 //    return uno::Any();
9472 }
9473 
getElementType()9474 uno::Type SAL_CALL ScCellFormatsObj::getElementType() throw(uno::RuntimeException)
9475 {
9476 	ScUnoGuard aGuard;
9477 	return getCppuType((uno::Reference<table::XCellRange>*)0);
9478 }
9479 
hasElements()9480 sal_Bool SAL_CALL ScCellFormatsObj::hasElements() throw(uno::RuntimeException)
9481 {
9482 	ScUnoGuard aGuard;
9483 	return ( getCount() != 0 );		//! immer groesser 0 ??
9484 }
9485 
9486 // XEnumerationAccess
9487 
createEnumeration()9488 uno::Reference<container::XEnumeration> SAL_CALL ScCellFormatsObj::createEnumeration()
9489 													throw(uno::RuntimeException)
9490 {
9491 	ScUnoGuard aGuard;
9492 	if (pDocShell)
9493 		return new ScCellFormatsEnumeration( pDocShell, aTotalRange );
9494 	return NULL;
9495 }
9496 
9497 //------------------------------------------------------------------------
9498 
ScCellFormatsEnumeration(ScDocShell * pDocSh,const ScRange & rRange)9499 ScCellFormatsEnumeration::ScCellFormatsEnumeration(ScDocShell* pDocSh, const ScRange& rRange) :
9500 	pDocShell( pDocSh ),
9501 	nTab( rRange.aStart.Tab() ),
9502 	pIter( NULL ),
9503 	bAtEnd( sal_False ),
9504 	bDirty( sal_False )
9505 {
9506 	ScDocument* pDoc = pDocShell->GetDocument();
9507 	pDoc->AddUnoObject(*this);
9508 
9509 	DBG_ASSERT( rRange.aStart.Tab() == rRange.aEnd.Tab(),
9510 				"CellFormatsEnumeration: unterschiedliche Tabellen" );
9511 
9512 	pIter = new ScAttrRectIterator( pDoc, nTab,
9513 									rRange.aStart.Col(), rRange.aStart.Row(),
9514 									rRange.aEnd.Col(), rRange.aEnd.Row() );
9515 	Advance_Impl();
9516 }
9517 
~ScCellFormatsEnumeration()9518 ScCellFormatsEnumeration::~ScCellFormatsEnumeration()
9519 {
9520 	if (pDocShell)
9521 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9522 	delete pIter;
9523 }
9524 
Advance_Impl()9525 void ScCellFormatsEnumeration::Advance_Impl()
9526 {
9527 	DBG_ASSERT(!bAtEnd,"zuviel Advance_Impl");
9528 
9529 	if ( pIter )
9530 	{
9531 		if ( bDirty )
9532 		{
9533 			pIter->DataChanged();	// AttrArray-Index neu suchen
9534 			bDirty = sal_False;
9535 		}
9536 
9537         SCCOL nCol1, nCol2;
9538         SCROW nRow1, nRow2;
9539         if ( pIter->GetNext( nCol1, nCol2, nRow1, nRow2 ) )
9540 			aNext = ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
9541 		else
9542 			bAtEnd = sal_True;		// kommt nix mehr
9543 	}
9544 	else
9545 		bAtEnd = sal_True;			// Dok weggekommen oder so
9546 }
9547 
NextObject_Impl()9548 ScCellRangeObj* ScCellFormatsEnumeration::NextObject_Impl()
9549 {
9550 	ScCellRangeObj* pRet = NULL;
9551 	if (pDocShell && !bAtEnd)
9552 	{
9553 		if ( aNext.aStart == aNext.aEnd )
9554 			pRet = new ScCellObj( pDocShell, aNext.aStart );
9555 		else
9556 			pRet = new ScCellRangeObj( pDocShell, aNext );
9557 		Advance_Impl();
9558 	}
9559 	return pRet;
9560 }
9561 
Notify(SfxBroadcaster &,const SfxHint & rHint)9562 void ScCellFormatsEnumeration::Notify( SfxBroadcaster&, const SfxHint& rHint )
9563 {
9564 	if ( rHint.ISA( ScUpdateRefHint ) )
9565 	{
9566 		//!	und nun ???
9567 	}
9568 	else if ( rHint.ISA( SfxSimpleHint ) )
9569 	{
9570 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
9571 		if ( nId == SFX_HINT_DYING )
9572 		{
9573 			pDocShell = NULL;						// ungueltig geworden
9574 			delete pIter;
9575 			pIter = NULL;
9576 		}
9577 		else if ( nId == SFX_HINT_DATACHANGED )
9578 		{
9579 			bDirty = sal_True;			// AttrArray-Index evtl. ungueltig geworden
9580 		}
9581 	}
9582 }
9583 
9584 // XEnumeration
9585 
hasMoreElements()9586 sal_Bool SAL_CALL ScCellFormatsEnumeration::hasMoreElements() throw(uno::RuntimeException)
9587 {
9588 	ScUnoGuard aGuard;
9589 	return !bAtEnd;
9590 }
9591 
nextElement()9592 uno::Any SAL_CALL ScCellFormatsEnumeration::nextElement() throw(container::NoSuchElementException,
9593 										lang::WrappedTargetException, uno::RuntimeException)
9594 {
9595 	ScUnoGuard aGuard;
9596 
9597 	if ( bAtEnd || !pDocShell )
9598 		throw container::NoSuchElementException();		// no more elements
9599 
9600 	// Interface-Typ muss zu ScCellFormatsObj::getElementType passen
9601 
9602     return uno::makeAny(uno::Reference<table::XCellRange> (NextObject_Impl()));
9603 }
9604 
9605 //------------------------------------------------------------------------
9606 
ScUniqueCellFormatsObj(ScDocShell * pDocSh,const ScRange & rRange)9607 ScUniqueCellFormatsObj::ScUniqueCellFormatsObj(ScDocShell* pDocSh, const ScRange& rRange) :
9608 	pDocShell( pDocSh ),
9609 	aTotalRange( rRange ),
9610 	aRangeLists()
9611 {
9612 	pDocShell->GetDocument()->AddUnoObject(*this);
9613 
9614 	DBG_ASSERT( aTotalRange.aStart.Tab() == aTotalRange.aEnd.Tab(), "unterschiedliche Tabellen" );
9615 
9616 	GetObjects_Impl();
9617 }
9618 
~ScUniqueCellFormatsObj()9619 ScUniqueCellFormatsObj::~ScUniqueCellFormatsObj()
9620 {
9621 	if (pDocShell)
9622 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9623 }
9624 
Notify(SfxBroadcaster &,const SfxHint & rHint)9625 void ScUniqueCellFormatsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
9626 {
9627 	if ( rHint.ISA( ScUpdateRefHint ) )
9628 	{
9629 		//!	aTotalRange...
9630 	}
9631 	else if ( rHint.ISA( SfxSimpleHint ) )
9632 	{
9633 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
9634 		if ( nId == SFX_HINT_DYING )
9635 			pDocShell = NULL;						// ungueltig geworden
9636 	}
9637 }
9638 
9639 //
9640 //  Fill the list of formats from the document
9641 //
9642 
9643 // hash code to access the range lists by ScPatternAttr pointer
9644 struct ScPatternHashCode
9645 {
operator ()ScPatternHashCode9646     size_t operator()( const ScPatternAttr* pPattern ) const
9647     {
9648         return reinterpret_cast<size_t>(pPattern);
9649     }
9650 };
9651 
9652 // Hash map to find a range by its start row
9653 typedef ::std::hash_map< SCROW, ScRange > ScRowRangeHashMap;
9654 
9655 typedef ::std::vector<ScRange> ScRangeVector;
9656 
9657 // Hash map entry.
9658 // The Join method depends on the column-wise order of ScAttrRectIterator
9659 class ScUniqueFormatsEntry
9660 {
9661     enum EntryState { STATE_EMPTY, STATE_SINGLE, STATE_COMPLEX };
9662 
9663     EntryState          eState;
9664     ScRange             aSingleRange;
9665     ScRowRangeHashMap   aJoinedRanges;      // "active" ranges to be merged
9666     ScRangeVector       aCompletedRanges;   // ranges that will no longer be touched
9667     ScRangeListRef      aReturnRanges;      // result as ScRangeList for further use
9668 
9669 public:
ScUniqueFormatsEntry()9670                         ScUniqueFormatsEntry() : eState( STATE_EMPTY ) {}
ScUniqueFormatsEntry(const ScUniqueFormatsEntry & r)9671                         ScUniqueFormatsEntry( const ScUniqueFormatsEntry& r ) :
9672                             eState( r.eState ),
9673                             aSingleRange( r.aSingleRange ),
9674                             aJoinedRanges( r.aJoinedRanges ),
9675                             aCompletedRanges( r.aCompletedRanges ),
9676                             aReturnRanges( r.aReturnRanges ) {}
~ScUniqueFormatsEntry()9677                         ~ScUniqueFormatsEntry() {}
9678 
9679     void                Join( const ScRange& rNewRange );
9680     const ScRangeList&  GetRanges();
Clear()9681     void                Clear() { aReturnRanges.Clear(); }  // aJoinedRanges and aCompletedRanges are cleared in GetRanges
9682 };
9683 
Join(const ScRange & rNewRange)9684 void ScUniqueFormatsEntry::Join( const ScRange& rNewRange )
9685 {
9686     // Special-case handling for single range
9687 
9688     if ( eState == STATE_EMPTY )
9689     {
9690         aSingleRange = rNewRange;
9691         eState = STATE_SINGLE;
9692         return;
9693     }
9694     if ( eState == STATE_SINGLE )
9695     {
9696         if ( aSingleRange.aStart.Row() == rNewRange.aStart.Row() &&
9697              aSingleRange.aEnd.Row() == rNewRange.aEnd.Row() &&
9698              aSingleRange.aEnd.Col() + 1 == rNewRange.aStart.Col() )
9699         {
9700             aSingleRange.aEnd.SetCol( rNewRange.aEnd.Col() );
9701             return;     // still a single range
9702         }
9703 
9704         SCROW nSingleRow = aSingleRange.aStart.Row();
9705         aJoinedRanges.insert( ScRowRangeHashMap::value_type( nSingleRow, aSingleRange ) );
9706         eState = STATE_COMPLEX;
9707         // continue normally
9708     }
9709 
9710     // This is called in the order of ScAttrRectIterator results.
9711     // rNewRange can only be joined with an existing entry if it's the same rows, starting in the next column.
9712     // If the old entry for the start row extends to a different end row, or ends in a different column, it
9713     // can be moved to aCompletedRanges because it can't be joined with following iterator results.
9714     // Everything happens within one sheet, so Tab can be ignored.
9715 
9716     SCROW nStartRow = rNewRange.aStart.Row();
9717     ScRowRangeHashMap::iterator aIter( aJoinedRanges.find( nStartRow ) );       // find the active entry for the start row
9718     if ( aIter != aJoinedRanges.end() )
9719     {
9720         ScRange& rOldRange = aIter->second;
9721         if ( rOldRange.aEnd.Row() == rNewRange.aEnd.Row() &&
9722              rOldRange.aEnd.Col() + 1 == rNewRange.aStart.Col() )
9723         {
9724             // extend existing range
9725             rOldRange.aEnd.SetCol( rNewRange.aEnd.Col() );
9726         }
9727         else
9728         {
9729             // move old range to aCompletedRanges, keep rNewRange for joining
9730             aCompletedRanges.push_back( rOldRange );
9731             rOldRange = rNewRange;  // replace in hash map
9732         }
9733     }
9734     else
9735     {
9736         // keep rNewRange for joining
9737         aJoinedRanges.insert( ScRowRangeHashMap::value_type( nStartRow, rNewRange ) );
9738     }
9739 }
9740 
GetRanges()9741 const ScRangeList& ScUniqueFormatsEntry::GetRanges()
9742 {
9743     if ( eState == STATE_SINGLE )
9744     {
9745         aReturnRanges = new ScRangeList;
9746         aReturnRanges->Append( aSingleRange );
9747         return *aReturnRanges;
9748     }
9749 
9750     // move remaining entries from aJoinedRanges to aCompletedRanges
9751 
9752     ScRowRangeHashMap::const_iterator aJoinedEnd = aJoinedRanges.end();
9753     for ( ScRowRangeHashMap::const_iterator aJoinedIter = aJoinedRanges.begin(); aJoinedIter != aJoinedEnd; ++aJoinedIter )
9754         aCompletedRanges.push_back( aJoinedIter->second );
9755     aJoinedRanges.clear();
9756 
9757     // sort all ranges for a predictable API result
9758 
9759     std::sort( aCompletedRanges.begin(), aCompletedRanges.end() );
9760 
9761     // fill and return ScRangeList
9762 
9763     aReturnRanges = new ScRangeList;
9764     ScRangeVector::const_iterator aCompEnd( aCompletedRanges.end() );
9765     for ( ScRangeVector::const_iterator aCompIter( aCompletedRanges.begin() ); aCompIter != aCompEnd; ++aCompIter )
9766         aReturnRanges->Append( *aCompIter );
9767     aCompletedRanges.clear();
9768 
9769     return *aReturnRanges;
9770 }
9771 
9772 typedef ::std::hash_map< const ScPatternAttr*, ScUniqueFormatsEntry, ScPatternHashCode > ScUniqueFormatsHashMap;
9773 
9774 // function object to sort the range lists by start of first range
9775 struct ScUniqueFormatsOrder
9776 {
operator ()ScUniqueFormatsOrder9777     bool operator()( const ScRangeList& rList1, const ScRangeList& rList2 ) const
9778     {
9779         // all range lists have at least one entry
9780         DBG_ASSERT( rList1.Count() > 0 && rList2.Count() > 0, "ScUniqueFormatsOrder: empty list" );
9781 
9782         // compare start positions using ScAddress comparison operator
9783         return ( rList1.GetObject(0)->aStart < rList2.GetObject(0)->aStart );
9784     }
9785 };
9786 
GetObjects_Impl()9787 void ScUniqueCellFormatsObj::GetObjects_Impl()
9788 {
9789 	if (pDocShell)
9790 	{
9791 		ScDocument* pDoc = pDocShell->GetDocument();
9792 		SCTAB nTab = aTotalRange.aStart.Tab();
9793 		ScAttrRectIterator aIter( pDoc, nTab,
9794 									aTotalRange.aStart.Col(), aTotalRange.aStart.Row(),
9795 									aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() );
9796         SCCOL nCol1, nCol2;
9797         SCROW nRow1, nRow2;
9798 
9799         // Collect the ranges for each format in a hash map, to avoid nested loops
9800 
9801         ScUniqueFormatsHashMap aHashMap;
9802 		while (aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) )
9803 		{
9804 			ScRange aRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
9805             const ScPatternAttr* pPattern = pDoc->GetPattern(nCol1, nRow1, nTab);
9806 			aHashMap[pPattern].Join( aRange );
9807 		}
9808 
9809         // Fill the vector aRangeLists with the range lists from the hash map
9810 
9811         aRangeLists.reserve( aHashMap.size() );
9812         ScUniqueFormatsHashMap::iterator aMapIter( aHashMap.begin() );
9813         ScUniqueFormatsHashMap::iterator aMapEnd( aHashMap.end() );
9814         while ( aMapIter != aMapEnd )
9815         {
9816             ScUniqueFormatsEntry& rEntry = aMapIter->second;
9817             const ScRangeList& rRanges = rEntry.GetRanges();
9818             aRangeLists.push_back( rRanges );       // copy ScRangeList
9819             rEntry.Clear();                         // free memory, don't hold both copies of all ranges
9820             ++aMapIter;
9821         }
9822 
9823         // Sort the vector by first range's start position, to avoid random shuffling
9824         // due to using the ScPatterAttr pointers
9825 
9826         ScUniqueFormatsOrder aComp;
9827         ::std::sort( aRangeLists.begin(), aRangeLists.end(), aComp );
9828 	}
9829 }
9830 
9831 // XIndexAccess
9832 
getCount()9833 sal_Int32 SAL_CALL ScUniqueCellFormatsObj::getCount() throw(uno::RuntimeException)
9834 {
9835 	ScUnoGuard aGuard;
9836 
9837 	return aRangeLists.size();
9838 }
9839 
getByIndex(sal_Int32 nIndex)9840 uno::Any SAL_CALL ScUniqueCellFormatsObj::getByIndex( sal_Int32 nIndex )
9841 							throw(lang::IndexOutOfBoundsException,
9842 									lang::WrappedTargetException, uno::RuntimeException)
9843 {
9844 	ScUnoGuard aGuard;
9845 
9846 	if(static_cast<sal_uInt32>(nIndex) < aRangeLists.size())
9847         return uno::makeAny(uno::Reference<sheet::XSheetCellRangeContainer>(new ScCellRangesObj(pDocShell, aRangeLists[nIndex])));
9848 	else
9849 		throw lang::IndexOutOfBoundsException();
9850 //    return uno::Any();
9851 }
9852 
getElementType()9853 uno::Type SAL_CALL ScUniqueCellFormatsObj::getElementType() throw(uno::RuntimeException)
9854 {
9855 	ScUnoGuard aGuard;
9856 	return getCppuType((uno::Reference<sheet::XSheetCellRangeContainer>*)0);
9857 }
9858 
hasElements()9859 sal_Bool SAL_CALL ScUniqueCellFormatsObj::hasElements() throw(uno::RuntimeException)
9860 {
9861 	ScUnoGuard aGuard;
9862 	return ( aRangeLists.size() != 0 );
9863 }
9864 
9865 // XEnumerationAccess
9866 
createEnumeration()9867 uno::Reference<container::XEnumeration> SAL_CALL ScUniqueCellFormatsObj::createEnumeration()
9868 													throw(uno::RuntimeException)
9869 {
9870 	ScUnoGuard aGuard;
9871 	if (pDocShell)
9872 		return new ScUniqueCellFormatsEnumeration( pDocShell, aRangeLists );
9873 	return NULL;
9874 }
9875 
9876 //------------------------------------------------------------------------
9877 
ScUniqueCellFormatsEnumeration(ScDocShell * pDocSh,const ScMyRangeLists & rRangeLists)9878 ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration(ScDocShell* pDocSh, const ScMyRangeLists& rRangeLists) :
9879 	aRangeLists(rRangeLists),
9880 	pDocShell( pDocSh ),
9881 	nCurrentPosition(0)
9882 {
9883 	pDocShell->GetDocument()->AddUnoObject(*this);
9884 }
9885 
~ScUniqueCellFormatsEnumeration()9886 ScUniqueCellFormatsEnumeration::~ScUniqueCellFormatsEnumeration()
9887 {
9888 	if (pDocShell)
9889 		pDocShell->GetDocument()->RemoveUnoObject(*this);
9890 }
9891 
Notify(SfxBroadcaster &,const SfxHint & rHint)9892 void ScUniqueCellFormatsEnumeration::Notify( SfxBroadcaster&, const SfxHint& rHint )
9893 {
9894 	if ( rHint.ISA( ScUpdateRefHint ) )
9895 	{
9896 		//!	und nun ???
9897 	}
9898 	else if ( rHint.ISA( SfxSimpleHint ) )
9899 	{
9900 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
9901 		if ( nId == SFX_HINT_DYING )
9902 			pDocShell = NULL;						// ungueltig geworden
9903 	}
9904 }
9905 
9906 // XEnumeration
9907 
hasMoreElements()9908 sal_Bool SAL_CALL ScUniqueCellFormatsEnumeration::hasMoreElements() throw(uno::RuntimeException)
9909 {
9910 	ScUnoGuard aGuard;
9911 	return static_cast<sal_uInt32>(nCurrentPosition) < aRangeLists.size();
9912 }
9913 
nextElement()9914 uno::Any SAL_CALL ScUniqueCellFormatsEnumeration::nextElement() throw(container::NoSuchElementException,
9915 										lang::WrappedTargetException, uno::RuntimeException)
9916 {
9917 	ScUnoGuard aGuard;
9918 
9919 	if ( !hasMoreElements() || !pDocShell )
9920 		throw container::NoSuchElementException();		// no more elements
9921 
9922 	// Interface-Typ muss zu ScCellFormatsObj::getElementType passen
9923 
9924     return uno::makeAny(uno::Reference<sheet::XSheetCellRangeContainer>(new ScCellRangesObj(pDocShell, aRangeLists[nCurrentPosition++])));
9925 }
9926 
9927 
9928