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