xref: /AOO41X/main/sc/source/ui/unoobj/afmtuno.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "scitems.hxx"
34*cdf0e10cSrcweir #include <editeng/memberids.hrc>
35*cdf0e10cSrcweir #include <tools/debug.hxx>
36*cdf0e10cSrcweir #include <tools/shl.hxx>
37*cdf0e10cSrcweir #include <svl/poolitem.hxx>
38*cdf0e10cSrcweir #include <svx/unomid.hxx>
39*cdf0e10cSrcweir #include "unowids.hxx"
40*cdf0e10cSrcweir #include <rtl/uuid.h>
41*cdf0e10cSrcweir #include <com/sun/star/table/BorderLine.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/table/CellVertJustify.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/table/ShadowLocation.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/table/TableBorder.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/table/ShadowFormat.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/table/CellContentType.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/table/TableOrientation.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/table/CellHoriJustify.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/util/SortField.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/util/SortFieldType.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/table/CellOrientation.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/awt/SimpleFontMetric.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/awt/CharSet.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/awt/FontWidth.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/awt/XFont.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/awt/FontType.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/awt/FontFamily.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/awt/FontPitch.hpp>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #include "afmtuno.hxx"
68*cdf0e10cSrcweir #include "miscuno.hxx"
69*cdf0e10cSrcweir #include "autoform.hxx"
70*cdf0e10cSrcweir #include "unoguard.hxx"
71*cdf0e10cSrcweir #include "scdll.hxx"
72*cdf0e10cSrcweir #include "unonames.hxx"
73*cdf0e10cSrcweir #include "cellsuno.hxx"
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir using namespace ::com::sun::star;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir //------------------------------------------------------------------------
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir //	ein AutoFormat hat immer 16 Eintraege
80*cdf0e10cSrcweir #define SC_AF_FIELD_COUNT 16
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir //------------------------------------------------------------------------
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //	AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetAutoFormatMap()
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aAutoFormatMap_Impl[] =
89*cdf0e10cSrcweir 	{
90*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCBACK),	0,	&::getBooleanCppuType(),	0, 0 },
91*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCBORD),	0,	&::getBooleanCppuType(),	0, 0 },
92*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCFONT),	0,	&::getBooleanCppuType(),	0, 0 },
93*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCJUST),	0,	&::getBooleanCppuType(),	0, 0 },
94*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCNUM),	0,	&::getBooleanCppuType(),	0, 0 },
95*cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNONAME_INCWIDTH),	0,	&::getBooleanCppuType(),	0, 0 },
96*cdf0e10cSrcweir         {0,0,0,0,0,0}
97*cdf0e10cSrcweir 	};
98*cdf0e10cSrcweir 	return aAutoFormatMap_Impl;
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir //!	Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly)
102*cdf0e10cSrcweir //! table::TableBorder ??!?
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetAutoFieldMap()
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     static SfxItemPropertyMapEntry aAutoFieldMap_Impl[] =
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND,        &::getCppuType((const sal_Int32*)0),        0, MID_BACK_COLOR },
109*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CCOLOR),   ATTR_FONT_COLOR,        &::getCppuType((const sal_Int32*)0),        0, 0 },
110*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_COUTL),    ATTR_FONT_CONTOUR,      &::getBooleanCppuType(),                    0, 0 },
111*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CCROSS),   ATTR_FONT_CROSSEDOUT,   &::getBooleanCppuType(),                    0, MID_CROSSED_OUT },
112*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFONT),    ATTR_FONT,              &::getCppuType((const sal_Int16*)0),        0, MID_FONT_FAMILY },
113*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFCHARS),  ATTR_FONT,              &::getCppuType((sal_Int16*)0),              0, MID_FONT_CHAR_SET },
114*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS),  ATTR_CJK_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_CHAR_SET },
115*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS),  ATTR_CTL_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_CHAR_SET },
116*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL),  ATTR_FONT,              &::getCppuType((sal_Int16*)0),              0, MID_FONT_FAMILY },
117*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL),  ATTR_CJK_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_FAMILY },
118*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL),  ATTR_CTL_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_FAMILY },
119*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFNAME),   ATTR_FONT,              &::getCppuType((rtl::OUString*)0),          0, MID_FONT_FAMILY_NAME },
120*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME),   ATTR_CJK_FONT,          &::getCppuType((rtl::OUString*)0),          0, MID_FONT_FAMILY_NAME },
121*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME),   ATTR_CTL_FONT,          &::getCppuType((rtl::OUString*)0),          0, MID_FONT_FAMILY_NAME },
122*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFPITCH),  ATTR_FONT,              &::getCppuType((sal_Int16*)0),              0, MID_FONT_PITCH },
123*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH),  ATTR_CJK_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_PITCH },
124*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH),  ATTR_CTL_FONT,          &::getCppuType((sal_Int16*)0),              0, MID_FONT_PITCH },
125*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE),  ATTR_FONT,              &::getCppuType((rtl::OUString*)0),          0, MID_FONT_STYLE_NAME },
126*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE),  ATTR_CJK_FONT,          &::getCppuType((rtl::OUString*)0),          0, MID_FONT_STYLE_NAME },
127*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE),  ATTR_CTL_FONT,          &::getCppuType((rtl::OUString*)0),          0, MID_FONT_STYLE_NAME },
128*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT),  ATTR_FONT_HEIGHT,       &::getCppuType((float*)0),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
129*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT),  ATTR_CJK_FONT_HEIGHT,   &::getCppuType((float*)0),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
130*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT),  ATTR_CTL_FONT_HEIGHT,   &::getCppuType((float*)0),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
131*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_COVER),    ATTR_FONT_OVERLINE,     &::getCppuType((const sal_Int16*)0),        0, MID_TL_STYLE },
132*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CPOST),    ATTR_FONT_POSTURE,      &::getCppuType((awt::FontSlant*)0),         0, MID_POSTURE },
133*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CPOST),    ATTR_CJK_FONT_POSTURE,  &::getCppuType((awt::FontSlant*)0),         0, MID_POSTURE },
134*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CPOST),    ATTR_CTL_FONT_POSTURE,  &::getCppuType((awt::FontSlant*)0),         0, MID_POSTURE },
135*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CSHADD),   ATTR_FONT_SHADOWED,     &::getBooleanCppuType(),                    0, 0 },
136*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_TBLBORD),  SC_WID_UNO_TBLBORD,     &::getCppuType((table::TableBorder*)0),     0, 0 | CONVERT_TWIPS },
137*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CUNDER),   ATTR_FONT_UNDERLINE,    &::getCppuType((const sal_Int16*)0),        0, MID_TL_STYLE },
138*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT),  ATTR_FONT_WEIGHT,       &::getCppuType((float*)0),                  0, MID_WEIGHT },
139*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT),  ATTR_CJK_FONT_WEIGHT,   &::getCppuType((float*)0),                  0, MID_WEIGHT },
140*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT),  ATTR_CTL_FONT_WEIGHT,   &::getCppuType((float*)0),                  0, MID_WEIGHT },
141*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY,       &::getCppuType((const table::CellHoriJustify*)0),   0, 0 },
142*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND,        &::getBooleanCppuType(),                    0, MID_GRAPHIC_TRANSPARENT },
143*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_WRAP),     ATTR_LINEBREAK,         &::getBooleanCppuType(),                    0, 0 },
144*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CELLORI),  ATTR_STACKED,           &::getCppuType((const table::CellOrientation*)0),   0, 0 },
145*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN,            &::getCppuType((const sal_Int32*)0),        0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
146*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN,            &::getCppuType((const sal_Int32*)0),        0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
147*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN,            &::getCppuType((const sal_Int32*)0),        0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
148*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN,            &::getCppuType((const sal_Int32*)0),        0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
149*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ROTANG),   ATTR_ROTATE_VALUE,      &::getCppuType((const sal_Int32*)0),        0, 0 },
150*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_ROTREF),   ATTR_ROTATE_MODE,       &::getCppuType((const table::CellVertJustify*)0),   0, 0 },
151*cdf0e10cSrcweir         {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY,       &::getCppuType((const table::CellVertJustify*)0),   0, 0 },
152*cdf0e10cSrcweir         {0,0,0,0,0,0}
153*cdf0e10cSrcweir 	};
154*cdf0e10cSrcweir 	return aAutoFieldMap_Impl;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //------------------------------------------------------------------------
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir #define SCAUTOFORMATSOBJ_SERVICE	"com.sun.star.sheet.TableAutoFormats"
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" )
162*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" )
163*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE )
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //------------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir sal_Bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const String& rName, sal_uInt16& rOutIndex )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	String aEntryName;
170*cdf0e10cSrcweir 	sal_uInt16 nCount = rFormats.GetCount();
171*cdf0e10cSrcweir 	for( sal_uInt16 nPos=0; nPos<nCount; nPos++ )
172*cdf0e10cSrcweir 	{
173*cdf0e10cSrcweir 		ScAutoFormatData* pEntry = rFormats[nPos];
174*cdf0e10cSrcweir 		pEntry->GetName( aEntryName );
175*cdf0e10cSrcweir 		if ( aEntryName == rName )
176*cdf0e10cSrcweir 		{
177*cdf0e10cSrcweir 			rOutIndex = nPos;
178*cdf0e10cSrcweir 			return sal_True;
179*cdf0e10cSrcweir 		}
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir 	return sal_False;		// is nich
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //------------------------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir ScAutoFormatsObj::ScAutoFormatsObj()
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	//!	Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten
189*cdf0e10cSrcweir 	//!	bekannt sein, damit Aenderungen gebroadcasted werden koennen
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir ScAutoFormatsObj::~ScAutoFormatsObj()
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir // stuff for exService_...
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir uno::Reference<uno::XInterface>	SAL_CALL ScAutoFormatsObj_CreateInstance(
199*cdf0e10cSrcweir 						const uno::Reference<lang::XMultiServiceFactory>& )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	ScUnoGuard aGuard;
202*cdf0e10cSrcweir 	ScDLL::Init();
203*cdf0e10cSrcweir 	static uno::Reference< uno::XInterface > xInst((::cppu::OWeakObject*) new ScAutoFormatsObj);
204*cdf0e10cSrcweir 	return xInst;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir rtl::OUString ScAutoFormatsObj::getImplementationName_Static()
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "stardiv.StarCalc.ScAutoFormatsObj" );
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir uno::Sequence<rtl::OUString> ScAutoFormatsObj::getSupportedServiceNames_Static()
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(1);
215*cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
216*cdf0e10cSrcweir 	pArray[0] = rtl::OUString::createFromAscii( SCAUTOFORMATSOBJ_SERVICE );
217*cdf0e10cSrcweir 	return aRet;
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir // XTableAutoFormats
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir ScAutoFormatObj* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
225*cdf0e10cSrcweir 	if (pFormats && nIndex < pFormats->GetCount())
226*cdf0e10cSrcweir 		return new ScAutoFormatObj(nIndex);
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	return NULL;	// falscher Index
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir ScAutoFormatObj* ScAutoFormatsObj::GetObjectByName_Impl(const rtl::OUString& aName)
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
234*cdf0e10cSrcweir 	if (pFormats)
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir 		String aString(aName);
237*cdf0e10cSrcweir 		sal_uInt16 nIndex;
238*cdf0e10cSrcweir 		if (lcl_FindAutoFormatIndex( *pFormats, aString, nIndex ))
239*cdf0e10cSrcweir 			return GetObjectByIndex_Impl(nIndex);
240*cdf0e10cSrcweir 	}
241*cdf0e10cSrcweir 	return NULL;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // container::XNameContainer
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void SAL_CALL ScAutoFormatsObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
247*cdf0e10cSrcweir 							throw(lang::IllegalArgumentException, container::ElementExistException,
248*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	ScUnoGuard aGuard;
251*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
252*cdf0e10cSrcweir 	//	Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein...
253*cdf0e10cSrcweir     uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY);
254*cdf0e10cSrcweir 	if ( xInterface.is() )
255*cdf0e10cSrcweir 	{
256*cdf0e10cSrcweir 		ScAutoFormatObj* pFormatObj = ScAutoFormatObj::getImplementation( xInterface );
257*cdf0e10cSrcweir 		if ( pFormatObj && !pFormatObj->IsInserted() )	// noch nicht eingefuegt?
258*cdf0e10cSrcweir 		{
259*cdf0e10cSrcweir 			String aNameStr(aName);
260*cdf0e10cSrcweir 			ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 			sal_uInt16 nDummy;
263*cdf0e10cSrcweir 			if (pFormats && !lcl_FindAutoFormatIndex( *pFormats, aNameStr, nDummy ))
264*cdf0e10cSrcweir 			{
265*cdf0e10cSrcweir 				ScAutoFormatData* pNew = new ScAutoFormatData();
266*cdf0e10cSrcweir 				pNew->SetName( aNameStr );
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 				if (pFormats->Insert( pNew ))
269*cdf0e10cSrcweir 				{
270*cdf0e10cSrcweir 					//!	Notify fuer andere Objekte
271*cdf0e10cSrcweir 					pFormats->Save();	// sofort speichern
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 					sal_uInt16 nNewIndex;
274*cdf0e10cSrcweir 					if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nNewIndex ))
275*cdf0e10cSrcweir 					{
276*cdf0e10cSrcweir 						pFormatObj->InitFormat( nNewIndex );	// kann jetzt benutzt werden
277*cdf0e10cSrcweir 						bDone = sal_True;
278*cdf0e10cSrcweir 					}
279*cdf0e10cSrcweir 				}
280*cdf0e10cSrcweir 				else
281*cdf0e10cSrcweir 				{
282*cdf0e10cSrcweir 					delete pNew;
283*cdf0e10cSrcweir 					DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
284*cdf0e10cSrcweir 					throw uno::RuntimeException();
285*cdf0e10cSrcweir 				}
286*cdf0e10cSrcweir 			}
287*cdf0e10cSrcweir 			else
288*cdf0e10cSrcweir 			{
289*cdf0e10cSrcweir 				throw container::ElementExistException();
290*cdf0e10cSrcweir 			}
291*cdf0e10cSrcweir 		}
292*cdf0e10cSrcweir 	}
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	if (!bDone)
295*cdf0e10cSrcweir 	{
296*cdf0e10cSrcweir 		//	other errors are handled above
297*cdf0e10cSrcweir 		throw lang::IllegalArgumentException();
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir void SAL_CALL ScAutoFormatsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
302*cdf0e10cSrcweir 							throw(lang::IllegalArgumentException, container::NoSuchElementException,
303*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir 	ScUnoGuard aGuard;
306*cdf0e10cSrcweir 	//!	zusammenfassen?
307*cdf0e10cSrcweir 	removeByName( aName );
308*cdf0e10cSrcweir 	insertByName( aName, aElement );
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir void SAL_CALL ScAutoFormatsObj::removeByName( const rtl::OUString& aName )
312*cdf0e10cSrcweir 								throw(container::NoSuchElementException,
313*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir 	ScUnoGuard aGuard;
316*cdf0e10cSrcweir 	String aNameStr(aName);
317*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	sal_uInt16 nIndex;
320*cdf0e10cSrcweir 	if (pFormats && lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex ))
321*cdf0e10cSrcweir 	{
322*cdf0e10cSrcweir 		pFormats->AtFree( nIndex );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 		//!	Notify fuer andere Objekte
325*cdf0e10cSrcweir 		pFormats->Save();	// sofort speichern
326*cdf0e10cSrcweir 	}
327*cdf0e10cSrcweir 	else
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		throw container::NoSuchElementException();
330*cdf0e10cSrcweir 	}
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir // container::XEnumerationAccess
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
336*cdf0e10cSrcweir 													throw(uno::RuntimeException)
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir 	ScUnoGuard aGuard;
339*cdf0e10cSrcweir     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir // container::XIndexAccess
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAutoFormatsObj::getCount() throw(uno::RuntimeException)
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir 	ScUnoGuard aGuard;
347*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
348*cdf0e10cSrcweir 	if (pFormats)
349*cdf0e10cSrcweir 		return pFormats->GetCount();
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 	return 0;
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
355*cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
356*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir 	ScUnoGuard aGuard;
359*cdf0e10cSrcweir 	uno::Reference< container::XNamed >  xFormat(GetObjectByIndex_Impl((sal_uInt16)nIndex));
360*cdf0e10cSrcweir 	if (!xFormat.is())
361*cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
362*cdf0e10cSrcweir     return uno::makeAny(xFormat);
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir uno::Type SAL_CALL ScAutoFormatsObj::getElementType() throw(uno::RuntimeException)
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir 	ScUnoGuard aGuard;
368*cdf0e10cSrcweir 	return ::getCppuType((const uno::Reference< container::XNamed >*)0);	// muss zu getByIndex passen
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir sal_Bool SAL_CALL ScAutoFormatsObj::hasElements() throw(uno::RuntimeException)
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir 	ScUnoGuard aGuard;
374*cdf0e10cSrcweir 	return ( getCount() != 0 );
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir // container::XNameAccess
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir uno::Any SAL_CALL ScAutoFormatsObj::getByName( const rtl::OUString& aName )
380*cdf0e10cSrcweir 			throw(container::NoSuchElementException,
381*cdf0e10cSrcweir 					lang::WrappedTargetException, uno::RuntimeException)
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir 	ScUnoGuard aGuard;
384*cdf0e10cSrcweir 	uno::Reference< container::XNamed >  xFormat(GetObjectByName_Impl(aName));
385*cdf0e10cSrcweir 	if (!xFormat.is())
386*cdf0e10cSrcweir 		throw container::NoSuchElementException();
387*cdf0e10cSrcweir     return uno::makeAny(xFormat);
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
391*cdf0e10cSrcweir 												throw(uno::RuntimeException)
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir 	ScUnoGuard aGuard;
394*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
395*cdf0e10cSrcweir 	if (pFormats)
396*cdf0e10cSrcweir 	{
397*cdf0e10cSrcweir 		String aName;
398*cdf0e10cSrcweir 		sal_uInt16 nCount = pFormats->GetCount();
399*cdf0e10cSrcweir 		uno::Sequence<rtl::OUString> aSeq(nCount);
400*cdf0e10cSrcweir 		rtl::OUString* pAry = aSeq.getArray();
401*cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nCount; i++)
402*cdf0e10cSrcweir 		{
403*cdf0e10cSrcweir 			(*pFormats)[i]->GetName(aName);
404*cdf0e10cSrcweir 			pAry[i] = aName;
405*cdf0e10cSrcweir 		}
406*cdf0e10cSrcweir 		return aSeq;
407*cdf0e10cSrcweir 	}
408*cdf0e10cSrcweir 	return uno::Sequence<rtl::OUString>(0);
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const rtl::OUString& aName )
412*cdf0e10cSrcweir 										throw(uno::RuntimeException)
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir 	ScUnoGuard aGuard;
415*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
416*cdf0e10cSrcweir 	if (pFormats)
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		String aString(aName);
419*cdf0e10cSrcweir 		sal_uInt16 nDummy;
420*cdf0e10cSrcweir 		return lcl_FindAutoFormatIndex( *pFormats, aString, nDummy );
421*cdf0e10cSrcweir 	}
422*cdf0e10cSrcweir 	return sal_False;
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir //------------------------------------------------------------------------
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
428*cdf0e10cSrcweir 	aPropSet( lcl_GetAutoFormatMap() ),
429*cdf0e10cSrcweir 	nFormatIndex( nIndex )
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir 	//!	Listening !!!
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir ScAutoFormatObj::~ScAutoFormatObj()
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	//	Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
437*cdf0e10cSrcweir 	//	gespeichert, damit sie z.B. im Writer sichtbar sind
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 	if (IsInserted())
440*cdf0e10cSrcweir 	{
441*cdf0e10cSrcweir 		ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
442*cdf0e10cSrcweir 		if ( pFormats && pFormats->IsSaveLater() )
443*cdf0e10cSrcweir 			pFormats->Save();
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 		// Save() setzt SaveLater Flag zurueck
446*cdf0e10cSrcweir 	}
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex )
450*cdf0e10cSrcweir {
451*cdf0e10cSrcweir 	DBG_ASSERT( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat mehrfach" );
452*cdf0e10cSrcweir 	nFormatIndex = nNewIndex;
453*cdf0e10cSrcweir 	//!	Listening !!!
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir // XUnoTunnel
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir sal_Int64 SAL_CALL ScAutoFormatObj::getSomething(
459*cdf0e10cSrcweir 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
462*cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
463*cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
464*cdf0e10cSrcweir 	{
465*cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
466*cdf0e10cSrcweir 	}
467*cdf0e10cSrcweir 	return 0;
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir // static
471*cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId()
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
474*cdf0e10cSrcweir 	if( !pSeq )
475*cdf0e10cSrcweir 	{
476*cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
477*cdf0e10cSrcweir 		if( !pSeq )
478*cdf0e10cSrcweir 		{
479*cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
480*cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
481*cdf0e10cSrcweir 			pSeq = &aSeq;
482*cdf0e10cSrcweir 		}
483*cdf0e10cSrcweir 	}
484*cdf0e10cSrcweir 	return *pSeq;
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir // static
488*cdf0e10cSrcweir ScAutoFormatObj* ScAutoFormatObj::getImplementation(
489*cdf0e10cSrcweir 						const uno::Reference<uno::XInterface> xObj )
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir 	ScAutoFormatObj* pRet = NULL;
492*cdf0e10cSrcweir 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
493*cdf0e10cSrcweir 	if (xUT.is())
494*cdf0e10cSrcweir         pRet = reinterpret_cast<ScAutoFormatObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
495*cdf0e10cSrcweir 	return pRet;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir void ScAutoFormatObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir 	//	spaeter...
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir // XTableAutoFormat
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
508*cdf0e10cSrcweir 		return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 	return NULL;
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir // container::XEnumerationAccess
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
516*cdf0e10cSrcweir 													throw(uno::RuntimeException)
517*cdf0e10cSrcweir {
518*cdf0e10cSrcweir 	ScUnoGuard aGuard;
519*cdf0e10cSrcweir 	return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir // container::XIndexAccess
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAutoFormatObj::getCount() throw(uno::RuntimeException)
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir 	ScUnoGuard aGuard;
527*cdf0e10cSrcweir 	if (IsInserted())
528*cdf0e10cSrcweir 		return SC_AF_FIELD_COUNT;	// immer 16 Elemente
529*cdf0e10cSrcweir 	else
530*cdf0e10cSrcweir 		return 0;
531*cdf0e10cSrcweir }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
534*cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
535*cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir 	ScUnoGuard aGuard;
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getCount() )
540*cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 	if (IsInserted())
543*cdf0e10cSrcweir         return uno::makeAny(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl((sal_uInt16)nIndex)));
544*cdf0e10cSrcweir     return uno::Any();
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir uno::Type SAL_CALL ScAutoFormatObj::getElementType() throw(uno::RuntimeException)
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir 	ScUnoGuard aGuard;
550*cdf0e10cSrcweir 	return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);	// muss zu getByIndex passen
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir sal_Bool SAL_CALL ScAutoFormatObj::hasElements() throw(uno::RuntimeException)
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	ScUnoGuard aGuard;
556*cdf0e10cSrcweir 	return ( getCount() != 0 );
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir // container::XNamed
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir rtl::OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException)
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	ScUnoGuard aGuard;
564*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
565*cdf0e10cSrcweir 	if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
566*cdf0e10cSrcweir 	{
567*cdf0e10cSrcweir 		String aName;
568*cdf0e10cSrcweir 		(*pFormats)[nFormatIndex]->GetName(aName);
569*cdf0e10cSrcweir 		return aName;
570*cdf0e10cSrcweir 	}
571*cdf0e10cSrcweir 	return rtl::OUString();
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir void SAL_CALL ScAutoFormatObj::setName( const rtl::OUString& aNewName )
575*cdf0e10cSrcweir 												throw(uno::RuntimeException)
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir 	ScUnoGuard aGuard;
578*cdf0e10cSrcweir 	String aNewString(aNewName);
579*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 	sal_uInt16 nDummy;
582*cdf0e10cSrcweir 	if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount() &&
583*cdf0e10cSrcweir 			!lcl_FindAutoFormatIndex( *pFormats, aNewString, nDummy ))
584*cdf0e10cSrcweir 	{
585*cdf0e10cSrcweir 		ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
586*cdf0e10cSrcweir 		DBG_ASSERT(pData,"AutoFormat Daten nicht da");
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 		ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
589*cdf0e10cSrcweir 		pNew->SetName( aNewString );
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 		pFormats->AtFree( nFormatIndex );
592*cdf0e10cSrcweir 		if (pFormats->Insert( pNew ))
593*cdf0e10cSrcweir 		{
594*cdf0e10cSrcweir 			nFormatIndex = pFormats->IndexOf( pNew );	// ist evtl. anders einsortiert...
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 			//!	Notify fuer andere Objekte
597*cdf0e10cSrcweir 			pFormats->SetSaveLater(sal_True);
598*cdf0e10cSrcweir 		}
599*cdf0e10cSrcweir 		else
600*cdf0e10cSrcweir 		{
601*cdf0e10cSrcweir 			delete pNew;
602*cdf0e10cSrcweir 			DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
603*cdf0e10cSrcweir 			nFormatIndex = 0;		//! alter Index ist ungueltig
604*cdf0e10cSrcweir 		}
605*cdf0e10cSrcweir 	}
606*cdf0e10cSrcweir 	else
607*cdf0e10cSrcweir 	{
608*cdf0e10cSrcweir 		//	not inserted or name exists
609*cdf0e10cSrcweir 		throw uno::RuntimeException();
610*cdf0e10cSrcweir 	}
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir // beans::XPropertySet
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo()
616*cdf0e10cSrcweir 														throw(uno::RuntimeException)
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir 	ScUnoGuard aGuard;
619*cdf0e10cSrcweir 	static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
620*cdf0e10cSrcweir 	return aRef;
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir void SAL_CALL ScAutoFormatObj::setPropertyValue(
624*cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
625*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
626*cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
627*cdf0e10cSrcweir 						uno::RuntimeException)
628*cdf0e10cSrcweir {
629*cdf0e10cSrcweir 	ScUnoGuard aGuard;
630*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
631*cdf0e10cSrcweir 	if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
632*cdf0e10cSrcweir 	{
633*cdf0e10cSrcweir 		ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
634*cdf0e10cSrcweir 		DBG_ASSERT(pData,"AutoFormat Daten nicht da");
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 		String aPropString(aPropertyName);
637*cdf0e10cSrcweir 		sal_Bool bBool = sal_Bool();
638*cdf0e10cSrcweir 		if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ) && (aValue >>= bBool))
639*cdf0e10cSrcweir 			pData->SetIncludeBackground( bBool );
640*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ) && (aValue >>= bBool))
641*cdf0e10cSrcweir 			pData->SetIncludeFrame( bBool );
642*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ) && (aValue >>= bBool))
643*cdf0e10cSrcweir 			pData->SetIncludeFont( bBool );
644*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ) && (aValue >>= bBool))
645*cdf0e10cSrcweir 			pData->SetIncludeJustify( bBool );
646*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ) && (aValue >>= bBool))
647*cdf0e10cSrcweir 			pData->SetIncludeValueFormat( bBool );
648*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ) && (aValue >>= bBool))
649*cdf0e10cSrcweir 			pData->SetIncludeWidthHeight( bBool );
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 		// else Fehler
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		//!	Notify fuer andere Objekte
654*cdf0e10cSrcweir 		pFormats->SetSaveLater(sal_True);
655*cdf0e10cSrcweir 	}
656*cdf0e10cSrcweir }
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const rtl::OUString& aPropertyName )
659*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
660*cdf0e10cSrcweir 						uno::RuntimeException)
661*cdf0e10cSrcweir {
662*cdf0e10cSrcweir 	ScUnoGuard aGuard;
663*cdf0e10cSrcweir 	uno::Any aAny;
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
666*cdf0e10cSrcweir 	if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
667*cdf0e10cSrcweir 	{
668*cdf0e10cSrcweir 		ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
669*cdf0e10cSrcweir 		DBG_ASSERT(pData,"AutoFormat Daten nicht da");
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 		sal_Bool bValue;
672*cdf0e10cSrcweir 		sal_Bool bError = sal_False;
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 		String aPropString(aPropertyName);
675*cdf0e10cSrcweir 		if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ))
676*cdf0e10cSrcweir 			bValue = pData->GetIncludeBackground();
677*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ))
678*cdf0e10cSrcweir 			bValue = pData->GetIncludeFrame();
679*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ))
680*cdf0e10cSrcweir 			bValue = pData->GetIncludeFont();
681*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ))
682*cdf0e10cSrcweir 			bValue = pData->GetIncludeJustify();
683*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ))
684*cdf0e10cSrcweir 			bValue = pData->GetIncludeValueFormat();
685*cdf0e10cSrcweir 		else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ))
686*cdf0e10cSrcweir 			bValue = pData->GetIncludeWidthHeight();
687*cdf0e10cSrcweir 		else
688*cdf0e10cSrcweir 			bError = sal_True;		// unbekannte Property
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir 		if (!bError)
691*cdf0e10cSrcweir 			aAny <<= bValue;
692*cdf0e10cSrcweir 	}
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 	return aAny;
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj )
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir //------------------------------------------------------------------------
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) :
702*cdf0e10cSrcweir 	aPropSet( lcl_GetAutoFieldMap() ),
703*cdf0e10cSrcweir 	nFormatIndex( nFormat ),
704*cdf0e10cSrcweir 	nFieldIndex( nField )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir 	//!	Listening !!!
707*cdf0e10cSrcweir }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
710*cdf0e10cSrcweir {
711*cdf0e10cSrcweir }
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
714*cdf0e10cSrcweir {
715*cdf0e10cSrcweir 	//	spaeter...
716*cdf0e10cSrcweir }
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir // beans::XPropertySet
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
721*cdf0e10cSrcweir 														throw(uno::RuntimeException)
722*cdf0e10cSrcweir {
723*cdf0e10cSrcweir 	ScUnoGuard aGuard;
724*cdf0e10cSrcweir 	static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
725*cdf0e10cSrcweir 	return aRef;
726*cdf0e10cSrcweir }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
729*cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
730*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
731*cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
732*cdf0e10cSrcweir 						uno::RuntimeException)
733*cdf0e10cSrcweir {
734*cdf0e10cSrcweir 	ScUnoGuard aGuard;
735*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
736*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry =
737*cdf0e10cSrcweir             aPropSet.getPropertyMap()->getByName( aPropertyName );
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir     if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() )
740*cdf0e10cSrcweir 	{
741*cdf0e10cSrcweir 		ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir         if ( IsScItemWid( pEntry->nWID ) )
744*cdf0e10cSrcweir         {
745*cdf0e10cSrcweir             if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
746*cdf0e10cSrcweir 		    {
747*cdf0e10cSrcweir                 sal_Bool bDone = sal_False;
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir                 switch( pEntry->nWID )
750*cdf0e10cSrcweir                 {
751*cdf0e10cSrcweir                     case ATTR_STACKED:
752*cdf0e10cSrcweir                     {
753*cdf0e10cSrcweir                         table::CellOrientation eOrient;
754*cdf0e10cSrcweir                         if( aValue >>= eOrient )
755*cdf0e10cSrcweir                         {
756*cdf0e10cSrcweir                             switch( eOrient )
757*cdf0e10cSrcweir                             {
758*cdf0e10cSrcweir                                 case table::CellOrientation_STANDARD:
759*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
760*cdf0e10cSrcweir                                 break;
761*cdf0e10cSrcweir                                 case table::CellOrientation_TOPBOTTOM:
762*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
763*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
764*cdf0e10cSrcweir                                 break;
765*cdf0e10cSrcweir                                 case table::CellOrientation_BOTTOMTOP:
766*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
767*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
768*cdf0e10cSrcweir                                 break;
769*cdf0e10cSrcweir                                 case table::CellOrientation_STACKED:
770*cdf0e10cSrcweir                                     pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_True ) );
771*cdf0e10cSrcweir                                 break;
772*cdf0e10cSrcweir                                 default:
773*cdf0e10cSrcweir                                 {
774*cdf0e10cSrcweir                                     // added to avoid warnings
775*cdf0e10cSrcweir                                 }
776*cdf0e10cSrcweir                             }
777*cdf0e10cSrcweir                             bDone = sal_True;
778*cdf0e10cSrcweir                         }
779*cdf0e10cSrcweir                     }
780*cdf0e10cSrcweir                     break;
781*cdf0e10cSrcweir                     default:
782*cdf0e10cSrcweir                         SfxPoolItem* pNewItem = pItem->Clone();
783*cdf0e10cSrcweir                         bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
784*cdf0e10cSrcweir                         if (bDone)
785*cdf0e10cSrcweir                             pData->PutItem( nFieldIndex, *pNewItem );
786*cdf0e10cSrcweir                         delete pNewItem;
787*cdf0e10cSrcweir                 }
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir                 if (bDone)
790*cdf0e10cSrcweir                     //! Notify fuer andere Objekte?
791*cdf0e10cSrcweir                     pFormats->SetSaveLater(sal_True);
792*cdf0e10cSrcweir 		    }
793*cdf0e10cSrcweir         }
794*cdf0e10cSrcweir         else
795*cdf0e10cSrcweir         {
796*cdf0e10cSrcweir             switch (pEntry->nWID)
797*cdf0e10cSrcweir             {
798*cdf0e10cSrcweir 				case SC_WID_UNO_TBLBORD:
799*cdf0e10cSrcweir 					{
800*cdf0e10cSrcweir 						table::TableBorder aBorder;
801*cdf0e10cSrcweir 						if ( aValue >>= aBorder )	// empty = nothing to do
802*cdf0e10cSrcweir 						{
803*cdf0e10cSrcweir 							SvxBoxItem aOuter(ATTR_BORDER);
804*cdf0e10cSrcweir 							SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
805*cdf0e10cSrcweir                             ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
806*cdf0e10cSrcweir 				            pData->PutItem( nFieldIndex, aOuter );
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir 				            //!	Notify fuer andere Objekte?
809*cdf0e10cSrcweir 				            pFormats->SetSaveLater(sal_True);
810*cdf0e10cSrcweir 						}
811*cdf0e10cSrcweir 					}
812*cdf0e10cSrcweir 					break;
813*cdf0e10cSrcweir             }
814*cdf0e10cSrcweir         }
815*cdf0e10cSrcweir 	}
816*cdf0e10cSrcweir }
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
819*cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
820*cdf0e10cSrcweir 						uno::RuntimeException)
821*cdf0e10cSrcweir {
822*cdf0e10cSrcweir 	ScUnoGuard aGuard;
823*cdf0e10cSrcweir 	uno::Any aVal;
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 	ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
826*cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pEntry =
827*cdf0e10cSrcweir             aPropSet.getPropertyMap()->getByName( aPropertyName );
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir     if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() )
830*cdf0e10cSrcweir 	{
831*cdf0e10cSrcweir 		const ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir         if ( IsScItemWid( pEntry->nWID ) )
834*cdf0e10cSrcweir         {
835*cdf0e10cSrcweir             if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
836*cdf0e10cSrcweir             {
837*cdf0e10cSrcweir                 switch( pEntry->nWID )
838*cdf0e10cSrcweir                 {
839*cdf0e10cSrcweir                     case ATTR_STACKED:
840*cdf0e10cSrcweir                     {
841*cdf0e10cSrcweir                         const SfxInt32Item* pRotItem = (const SfxInt32Item*)pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE );
842*cdf0e10cSrcweir                         sal_Int32 nRot = pRotItem ? pRotItem->GetValue() : 0;
843*cdf0e10cSrcweir                         sal_Bool bStacked = ((const SfxBoolItem*)pItem)->GetValue();
844*cdf0e10cSrcweir                         SvxOrientationItem( nRot, bStacked, 0 ).QueryValue( aVal );
845*cdf0e10cSrcweir                     }
846*cdf0e10cSrcweir                     break;
847*cdf0e10cSrcweir                     default:
848*cdf0e10cSrcweir                         pItem->QueryValue( aVal, pEntry->nMemberId );
849*cdf0e10cSrcweir                 }
850*cdf0e10cSrcweir             }
851*cdf0e10cSrcweir         }
852*cdf0e10cSrcweir         else
853*cdf0e10cSrcweir         {
854*cdf0e10cSrcweir             switch (pEntry->nWID)
855*cdf0e10cSrcweir             {
856*cdf0e10cSrcweir 				case SC_WID_UNO_TBLBORD:
857*cdf0e10cSrcweir 					{
858*cdf0e10cSrcweir                         const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
859*cdf0e10cSrcweir                         if (pItem)
860*cdf0e10cSrcweir                         {
861*cdf0e10cSrcweir 						    SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem)));
862*cdf0e10cSrcweir 						    SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 						    table::TableBorder aBorder;
865*cdf0e10cSrcweir 						    ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner );
866*cdf0e10cSrcweir 						    aVal <<= aBorder;
867*cdf0e10cSrcweir                         }
868*cdf0e10cSrcweir     				}
869*cdf0e10cSrcweir 					break;
870*cdf0e10cSrcweir             }
871*cdf0e10cSrcweir         }
872*cdf0e10cSrcweir 	}
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir 	return aVal;
875*cdf0e10cSrcweir }
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir //------------------------------------------------------------------------
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 
883