xref: /trunk/main/svx/source/table/cell.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/drawing/BitmapMode.hpp>
28cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
29cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp>
30cdf0e10cSrcweir #include <com/sun/star/table/TableBorder.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
33cdf0e10cSrcweir #include <svl/style.hxx>
34cdf0e10cSrcweir #include <svl/itemset.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <vos/mutex.hxx>
37cdf0e10cSrcweir #include <vcl/svapp.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "svx/sdr/properties/textproperties.hxx"
40cdf0e10cSrcweir #include "editeng/outlobj.hxx"
41cdf0e10cSrcweir #include "editeng/writingmodeitem.hxx"
42cdf0e10cSrcweir #include "svx/svdotable.hxx"
43cdf0e10cSrcweir #include "svx/svdoutl.hxx"
44cdf0e10cSrcweir #include "svx/unoshtxt.hxx"
45cdf0e10cSrcweir #include "svx/svdmodel.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include "tableundo.hxx"
48cdf0e10cSrcweir #include "cell.hxx"
49cdf0e10cSrcweir #include "svx/svdotable.hxx"
50cdf0e10cSrcweir #include "svx/svdoutl.hxx"
51cdf0e10cSrcweir #include "svx/unoshtxt.hxx"
52cdf0e10cSrcweir #include "svx/unoshprp.hxx"
53cdf0e10cSrcweir #include "svx/unoshape.hxx"
54cdf0e10cSrcweir #include "editeng/editobj.hxx"
55cdf0e10cSrcweir #include "editeng/boxitem.hxx"
56cdf0e10cSrcweir #include "svx/xflbstit.hxx"
57cdf0e10cSrcweir #include "svx/xflbmtit.hxx"
58cdf0e10cSrcweir #include <svx/svdpool.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // -----------------------------------------------------------------------------
61cdf0e10cSrcweir 
62cdf0e10cSrcweir using ::rtl::OUString;
63cdf0e10cSrcweir using ::vos::OGuard;
64cdf0e10cSrcweir using namespace ::com::sun::star::uno;
65cdf0e10cSrcweir using namespace ::com::sun::star::beans;
66cdf0e10cSrcweir using namespace ::com::sun::star::lang;
67cdf0e10cSrcweir using namespace ::com::sun::star::text;
68cdf0e10cSrcweir using namespace ::com::sun::star::table;
69cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
70cdf0e10cSrcweir using namespace ::com::sun::star::style;
71cdf0e10cSrcweir using namespace ::com::sun::star::container;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------------
74cdf0e10cSrcweir 
75cdf0e10cSrcweir static const SvxItemPropertySet* ImplGetSvxCellPropertySet()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     // Propertymap fuer einen Outliner Text
78cdf0e10cSrcweir     static const SfxItemPropertyMapEntry aSvxCellPropertyMap[] =
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         FILL_PROPERTIES
81cdf0e10cSrcweir //      { MAP_CHAR_LEN("HasLevels"),                    OWN_ATTR_HASLEVELS,             &::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::READONLY,      0},
82cdf0e10cSrcweir         { MAP_CHAR_LEN("Style"),                        OWN_ATTR_STYLE,                 &::com::sun::star::style::XStyle::static_type(),                                    ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
83cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_WRITINGMODE),      SDRATTR_TEXTDIRECTION,          &::getCppuType( (::com::sun::star::text::WritingMode*) 0 ),                         0,      0},
84cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_HORZADJUST),       SDRATTR_TEXT_HORZADJUST,        &::getCppuType((const ::com::sun::star::drawing::TextHorizontalAdjust*)0),  0,      0}, \
85cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_LEFTDIST),         SDRATTR_TEXT_LEFTDIST,          &::getCppuType((const sal_Int32*)0),        0,      SFX_METRIC_ITEM}, \
86cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_LOWERDIST),        SDRATTR_TEXT_LOWERDIST,         &::getCppuType((const sal_Int32*)0),        0,      SFX_METRIC_ITEM}, \
87cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_RIGHTDIST),        SDRATTR_TEXT_RIGHTDIST,         &::getCppuType((const sal_Int32*)0),        0,      SFX_METRIC_ITEM}, \
88cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_UPPERDIST),        SDRATTR_TEXT_UPPERDIST,         &::getCppuType((const sal_Int32*)0),        0,      SFX_METRIC_ITEM}, \
89cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_VERTADJUST),       SDRATTR_TEXT_VERTADJUST,        &::getCppuType((const ::com::sun::star::drawing::TextVerticalAdjust*)0),    0,      0},\
90cdf0e10cSrcweir         { MAP_CHAR_LEN(UNO_NAME_TEXT_WORDWRAP),         SDRATTR_TEXT_WORDWRAP,          &::getBooleanCppuType(),        0,      0}, \
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         { MAP_CHAR_LEN("TableBorder"),                  OWN_ATTR_TABLEBORDER,           &::getCppuType((const TableBorder*)0), 0, 0 }, \
93cdf0e10cSrcweir         { MAP_CHAR_LEN("TopBorder"),                    SDRATTR_TABLE_BORDER,           &::getCppuType((const BorderLine*)0), 0, TOP_BORDER }, \
94cdf0e10cSrcweir         { MAP_CHAR_LEN("BottomBorder"),                 SDRATTR_TABLE_BORDER,           &::getCppuType((const BorderLine*)0), 0, BOTTOM_BORDER }, \
95cdf0e10cSrcweir         { MAP_CHAR_LEN("LeftBorder"),                   SDRATTR_TABLE_BORDER,           &::getCppuType((const BorderLine*)0), 0, LEFT_BORDER }, \
96cdf0e10cSrcweir         { MAP_CHAR_LEN("RightBorder"),                  SDRATTR_TABLE_BORDER,           &::getCppuType((const BorderLine*)0), 0, RIGHT_BORDER }, \
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         SVX_UNOEDIT_OUTLINER_PROPERTIES,
99cdf0e10cSrcweir         SVX_UNOEDIT_CHAR_PROPERTIES,
100cdf0e10cSrcweir         SVX_UNOEDIT_PARA_PROPERTIES,
101cdf0e10cSrcweir         {0,0,0,0,0,0}
102cdf0e10cSrcweir     };
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     static SvxItemPropertySet aSvxCellPropertySet( aSvxCellPropertyMap, SdrObject::GetGlobalDrawObjectItemPool() );
105cdf0e10cSrcweir     return &aSvxCellPropertySet;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir namespace sdr
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     namespace properties
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         class CellProperties : public TextProperties
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir         protected:
115cdf0e10cSrcweir             // create a new itemset
116cdf0e10cSrcweir             SfxItemSet& CreateObjectSpecificItemSet(SfxItemPool& rPool);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         public:
119cdf0e10cSrcweir             // basic constructor
120cdf0e10cSrcweir             CellProperties(SdrObject& rObj, sdr::table::Cell* pCell );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir             // constructor for copying, but using new object
123cdf0e10cSrcweir             CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             // destructor
126cdf0e10cSrcweir             ~CellProperties();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             // Clone() operator, normally just calls the local copy constructor
129cdf0e10cSrcweir             BaseProperties& Clone(SdrObject& rObj) const;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir             void ForceDefaultAttributes();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             void ItemSetChanged(const SfxItemSet& rSet);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir             void SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir             sdr::table::CellRef mxCell;
140cdf0e10cSrcweir         };
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         // create a new itemset
143cdf0e10cSrcweir         SfxItemSet& CellProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir             return *(new SfxItemSet(rPool,
146cdf0e10cSrcweir 
147cdf0e10cSrcweir                 // range from SdrAttrObj
148cdf0e10cSrcweir                 SDRATTR_START, SDRATTR_SHADOW_LAST,
149cdf0e10cSrcweir                 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
150cdf0e10cSrcweir                 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
151cdf0e10cSrcweir 
152cdf0e10cSrcweir                 // range for SdrTableObj
153cdf0e10cSrcweir                 SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST,
154cdf0e10cSrcweir 
155cdf0e10cSrcweir                 // range from SdrTextObj
156cdf0e10cSrcweir                 EE_ITEMS_START, EE_ITEMS_END,
157cdf0e10cSrcweir 
158cdf0e10cSrcweir                 // end
159cdf0e10cSrcweir                 0, 0));
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         CellProperties::CellProperties(SdrObject& rObj, sdr::table::Cell* pCell)
163cdf0e10cSrcweir         :   TextProperties(rObj)
164cdf0e10cSrcweir         ,   mxCell(pCell)
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         CellProperties::CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell)
169cdf0e10cSrcweir         :   TextProperties(rProps, rObj)
170cdf0e10cSrcweir         ,   mxCell( pCell )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         CellProperties::~CellProperties()
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         BaseProperties& CellProperties::Clone(SdrObject& rObj) const
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             DBG_ERROR("CellProperties::Clone(), does not work yet!");
181cdf0e10cSrcweir             return *(new CellProperties(*this, rObj,0));
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         void CellProperties::ForceDefaultAttributes()
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         void CellProperties::ItemSetChanged(const SfxItemSet& rSet )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
191cdf0e10cSrcweir 
192cdf0e10cSrcweir             if( mxCell.is() )
193cdf0e10cSrcweir             {
194cdf0e10cSrcweir                 OutlinerParaObject* pParaObj = mxCell->GetEditOutlinerParaObject();
195cdf0e10cSrcweir 
196cdf0e10cSrcweir                 bool bOwnParaObj = pParaObj != 0;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir                 if( pParaObj == 0 )
199cdf0e10cSrcweir                     pParaObj = mxCell->GetOutlinerParaObject();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir                 if(pParaObj)
202cdf0e10cSrcweir                 {
203cdf0e10cSrcweir                     // handle outliner attributes
204cdf0e10cSrcweir                     Outliner* pOutliner = 0;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir                     if(mxCell->IsTextEditActive())
207cdf0e10cSrcweir                     {
208cdf0e10cSrcweir                         pOutliner = rObj.GetTextEditOutliner();
209cdf0e10cSrcweir                     }
210cdf0e10cSrcweir                     else
211cdf0e10cSrcweir                     {
212cdf0e10cSrcweir                         pOutliner = &rObj.ImpGetDrawOutliner();
213cdf0e10cSrcweir                         pOutliner->SetText(*pParaObj);
214cdf0e10cSrcweir                     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir                     sal_uInt32 nParaCount(pOutliner->GetParagraphCount());
217cdf0e10cSrcweir 
218cdf0e10cSrcweir                     for(sal_uInt16 nPara = 0; nPara < nParaCount; nPara++)
219cdf0e10cSrcweir                     {
220cdf0e10cSrcweir                         SfxItemSet aSet(pOutliner->GetParaAttribs(nPara));
221cdf0e10cSrcweir                         aSet.Put(rSet);
222cdf0e10cSrcweir                         pOutliner->SetParaAttribs(nPara, aSet);
223cdf0e10cSrcweir                     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir                     if(!mxCell->IsTextEditActive())
226cdf0e10cSrcweir                     {
227cdf0e10cSrcweir                         if(nParaCount)
228cdf0e10cSrcweir                         {
229cdf0e10cSrcweir                             // force ItemSet
230cdf0e10cSrcweir                             GetObjectItemSet();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir                             SfxItemSet aNewSet(pOutliner->GetParaAttribs(0L));
233cdf0e10cSrcweir                             mpItemSet->Put(aNewSet);
234cdf0e10cSrcweir                         }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir                         OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, (sal_uInt16)nParaCount);
237cdf0e10cSrcweir                         pOutliner->Clear();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir                         mxCell->SetOutlinerParaObject(pTemp);
240cdf0e10cSrcweir                     }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir                     if( bOwnParaObj )
243cdf0e10cSrcweir                         delete pParaObj;
244cdf0e10cSrcweir                 }
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir             // call parent
248cdf0e10cSrcweir             AttributeProperties::ItemSetChanged(rSet);
249cdf0e10cSrcweir 
250cdf0e10cSrcweir             if( mxCell.is() )
251cdf0e10cSrcweir                 mxCell->notifyModified();
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         void CellProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
255cdf0e10cSrcweir         {
256cdf0e10cSrcweir             if(pNewItem && (SDRATTR_TEXTDIRECTION == nWhich))
257cdf0e10cSrcweir             {
258cdf0e10cSrcweir                 sal_Bool bVertical(com::sun::star::text::WritingMode_TB_RL == ((SvxWritingModeItem*)pNewItem)->GetValue());
259cdf0e10cSrcweir 
260cdf0e10cSrcweir                 sdr::table::SdrTableObj& rObj = (sdr::table::SdrTableObj&)GetSdrObject();
261cdf0e10cSrcweir                 if( rObj.IsVerticalWriting() != bVertical )
262cdf0e10cSrcweir                     rObj.SetVerticalWriting(bVertical);
263cdf0e10cSrcweir             }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir             // call parent
266cdf0e10cSrcweir             AttributeProperties::ItemChange( nWhich, pNewItem );
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         void CellProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
272cdf0e10cSrcweir         }
273cdf0e10cSrcweir     } // end of namespace properties
274cdf0e10cSrcweir } // end of namespace sdr
275cdf0e10cSrcweir 
276cdf0e10cSrcweir namespace sdr { namespace table {
277cdf0e10cSrcweir 
278cdf0e10cSrcweir // -----------------------------------------------------------------------------
279cdf0e10cSrcweir // Cell
280cdf0e10cSrcweir // -----------------------------------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     rtl::Reference< Cell > xCell( new Cell( rTableObj, pOutlinerParaObject ) );
285cdf0e10cSrcweir     if( xCell->mxTable.is() )
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         Reference< XEventListener > xListener( xCell.get() );
288cdf0e10cSrcweir         xCell->mxTable->addEventListener( xListener );
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir     return xCell;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir // -----------------------------------------------------------------------------
294cdf0e10cSrcweir 
295cdf0e10cSrcweir Cell::Cell( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject ) throw()
296cdf0e10cSrcweir : SdrText( rTableObj, pOutlinerParaObject )
297cdf0e10cSrcweir , SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
298cdf0e10cSrcweir , mpPropSet( ImplGetSvxCellPropertySet() )
299cdf0e10cSrcweir , mpProperties( new sdr::properties::CellProperties( rTableObj, this ) )
300cdf0e10cSrcweir , mnCellContentType( CellContentType_EMPTY )
301cdf0e10cSrcweir , mfValue( 0.0 )
302cdf0e10cSrcweir , mnError( 0 )
303cdf0e10cSrcweir , mbMerged( sal_False )
304cdf0e10cSrcweir , mnRowSpan( 1 )
305cdf0e10cSrcweir , mnColSpan( 1 )
306cdf0e10cSrcweir , mxTable( rTableObj.getTable() )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     if( rTableObj.GetModel() )
309cdf0e10cSrcweir         SetModel( rTableObj.GetModel() );
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir // -----------------------------------------------------------------------------
313cdf0e10cSrcweir 
314cdf0e10cSrcweir Cell::~Cell() throw()
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     dispose();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // -----------------------------------------------------------------------------
320cdf0e10cSrcweir 
321cdf0e10cSrcweir void Cell::dispose()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     if( mxTable.is() )
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         try
326cdf0e10cSrcweir         {
327cdf0e10cSrcweir             Reference< XEventListener > xThis( this );
328cdf0e10cSrcweir             mxTable->removeEventListener( xThis );
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir         catch( Exception& )
331cdf0e10cSrcweir         {
332cdf0e10cSrcweir             DBG_ERROR("Cell::dispose(), exception caught!");
333cdf0e10cSrcweir         }
334cdf0e10cSrcweir         mxTable.clear();
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     if( mpProperties )
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         delete mpProperties;
340cdf0e10cSrcweir         mpProperties = 0;
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir     SetOutlinerParaObject( 0 );
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir // -----------------------------------------------------------------------------
346cdf0e10cSrcweir 
347cdf0e10cSrcweir void Cell::SetModel(SdrModel* pNewModel)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( GetEditSource() );
350cdf0e10cSrcweir     if( (GetModel() != pNewModel) || ( pNewModel && !pTextEditSource) )
351cdf0e10cSrcweir     {
352cdf0e10cSrcweir         if( mpProperties )
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir             SfxItemPool* pItemPool = mpProperties->GetObjectItemSet().GetPool();
355cdf0e10cSrcweir 
356cdf0e10cSrcweir             // test for correct pool in ItemSet; move to new pool if necessary
357cdf0e10cSrcweir             if( pNewModel && pItemPool && pItemPool != &pNewModel->GetItemPool())
358cdf0e10cSrcweir                 mpProperties->MoveToItemPool(pItemPool, &pNewModel->GetItemPool(), pNewModel);
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         if( pTextEditSource )
362cdf0e10cSrcweir         {
363cdf0e10cSrcweir             pTextEditSource->ChangeModel( pNewModel );
364cdf0e10cSrcweir         }
365cdf0e10cSrcweir         else
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             SetEditSource( new SvxTextEditSource( &GetObject(), this, static_cast< XWeak * >( this ) ) );
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         SetStyleSheet( 0, sal_True );
371cdf0e10cSrcweir         SdrText::SetModel( pNewModel );
372cdf0e10cSrcweir         ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir // -----------------------------------------------------------------------------
377cdf0e10cSrcweir 
378cdf0e10cSrcweir void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir     if( (mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || (mbMerged != sal_False) )
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         mnColSpan = nColumnSpan;
383cdf0e10cSrcweir         mnRowSpan = nRowSpan;
384cdf0e10cSrcweir         mbMerged = sal_False;
385cdf0e10cSrcweir         notifyModified();
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir // -----------------------------------------------------------------------------
390cdf0e10cSrcweir 
391cdf0e10cSrcweir void Cell::mergeContent( const CellRef& xSourceCell )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir     SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     if( xSourceCell->hasText() )
396cdf0e10cSrcweir     {
397cdf0e10cSrcweir         SdrOutliner& rOutliner=rTableObj.ImpGetDrawOutliner();
398cdf0e10cSrcweir         rOutliner.SetUpdateMode(sal_True);
399cdf0e10cSrcweir 
400cdf0e10cSrcweir         if( hasText() )
401cdf0e10cSrcweir         {
402cdf0e10cSrcweir             rOutliner.SetText(*GetOutlinerParaObject());
403cdf0e10cSrcweir             rOutliner.AddText(*xSourceCell->GetOutlinerParaObject());
404cdf0e10cSrcweir         }
405cdf0e10cSrcweir         else
406cdf0e10cSrcweir         {
407cdf0e10cSrcweir             rOutliner.SetText(*xSourceCell->GetOutlinerParaObject());
408cdf0e10cSrcweir         }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir         SetOutlinerParaObject( rOutliner.CreateParaObject() );
411cdf0e10cSrcweir         rOutliner.Clear();
412cdf0e10cSrcweir         xSourceCell->SetOutlinerParaObject(rOutliner.CreateParaObject());
413cdf0e10cSrcweir         rOutliner.Clear();
414cdf0e10cSrcweir         SetStyleSheet( GetStyleSheet(), sal_True );
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir // -----------------------------------------------------------------------------
419cdf0e10cSrcweir 
420cdf0e10cSrcweir void Cell::cloneFrom( const CellRef& xCell )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     if( xCell.is() )
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir         replaceContentAndFormating( xCell );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir         mnCellContentType = xCell->mnCellContentType;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         msFormula = xCell->msFormula;
429cdf0e10cSrcweir         mfValue = xCell->mfValue;
430cdf0e10cSrcweir         mnError = xCell->mnError;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         mbMerged = xCell->mbMerged;
433cdf0e10cSrcweir         mnRowSpan = xCell->mnRowSpan;
434cdf0e10cSrcweir         mnColSpan = xCell->mnColSpan;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir     notifyModified();
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir void Cell::replaceContentAndFormating( const CellRef& xSourceCell )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     if( xSourceCell.is() && mpProperties )
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );
445cdf0e10cSrcweir         SetOutlinerParaObject( new OutlinerParaObject(*xSourceCell->GetOutlinerParaObject()) );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
448cdf0e10cSrcweir         SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir         if(rSourceTableObj.GetModel() != rTableObj.GetModel())
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             SetStyleSheet( 0, sal_True );
453cdf0e10cSrcweir         }
454cdf0e10cSrcweir     }
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir // -----------------------------------------------------------------------------
458cdf0e10cSrcweir 
459cdf0e10cSrcweir void Cell::setMerged()
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     if( !mbMerged )
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         mbMerged = sal_True;
464cdf0e10cSrcweir         notifyModified();
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir // -----------------------------------------------------------------------------
469cdf0e10cSrcweir 
470cdf0e10cSrcweir void Cell::notifyModified()
471cdf0e10cSrcweir {
472cdf0e10cSrcweir     if( mxTable.is() )
473cdf0e10cSrcweir         mxTable->setModified( sal_True );
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir // -----------------------------------------------------------------------------
477cdf0e10cSrcweir // SdrTextShape proxy
478cdf0e10cSrcweir // -----------------------------------------------------------------------------
479cdf0e10cSrcweir 
480cdf0e10cSrcweir bool Cell::IsTextEditActive()
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     bool isActive = false;
483cdf0e10cSrcweir     SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
484cdf0e10cSrcweir     if(rTableObj.getActiveCell().get() == this )
485cdf0e10cSrcweir     {
486cdf0e10cSrcweir         OutlinerParaObject* pParaObj = rTableObj.GetEditOutlinerParaObject();
487cdf0e10cSrcweir         if( pParaObj != 0 )
488cdf0e10cSrcweir         {
489cdf0e10cSrcweir             isActive = true;
490cdf0e10cSrcweir             delete pParaObj;
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir     return isActive;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir // -----------------------------------------------------------------------------
497cdf0e10cSrcweir 
498cdf0e10cSrcweir bool Cell::hasText() const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     OutlinerParaObject* pParaObj = GetOutlinerParaObject();
501cdf0e10cSrcweir     if( pParaObj )
502cdf0e10cSrcweir     {
503cdf0e10cSrcweir         const EditTextObject& rTextObj = pParaObj->GetTextObject();
504cdf0e10cSrcweir         if( rTextObj.GetParagraphCount() >= 1 )
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             if( rTextObj.GetParagraphCount() == 1 )
507cdf0e10cSrcweir             {
508cdf0e10cSrcweir                 if( rTextObj.GetText(0).Len() == 0 )
509cdf0e10cSrcweir                     return false;
510cdf0e10cSrcweir             }
511cdf0e10cSrcweir             return true;
512cdf0e10cSrcweir         }
513cdf0e10cSrcweir     }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     return false;
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir // -----------------------------------------------------------------------------
519cdf0e10cSrcweir 
520cdf0e10cSrcweir OutlinerParaObject* Cell::GetEditOutlinerParaObject() const
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
523cdf0e10cSrcweir     if( rTableObj.getActiveCell().get() == this )
524cdf0e10cSrcweir         return rTableObj.GetEditOutlinerParaObject();
525cdf0e10cSrcweir     return 0;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir // -----------------------------------------------------------------------------
529cdf0e10cSrcweir 
530cdf0e10cSrcweir void Cell::SetStyleSheet( SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     // only allow cell styles for cells
533cdf0e10cSrcweir     if( pStyleSheet && pStyleSheet->GetFamily() != SFX_STYLE_FAMILY_FRAME )
534cdf0e10cSrcweir         return;
535cdf0e10cSrcweir 
536cdf0e10cSrcweir     if( mpProperties && (mpProperties->GetStyleSheet() != pStyleSheet) )
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         mpProperties->SetStyleSheet( pStyleSheet, bDontRemoveHardAttr );
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir // -----------------------------------------------------------------------------
543cdf0e10cSrcweir 
544cdf0e10cSrcweir const SfxItemSet& Cell::GetObjectItemSet()
545cdf0e10cSrcweir {
546cdf0e10cSrcweir     if( mpProperties )
547cdf0e10cSrcweir     {
548cdf0e10cSrcweir         return mpProperties->GetObjectItemSet();
549cdf0e10cSrcweir     }
550cdf0e10cSrcweir     else
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         DBG_ERROR("Cell::GetObjectItemSet(), called without properties!");
553cdf0e10cSrcweir         return GetObject().GetObjectItemSet();
554cdf0e10cSrcweir     }
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir void Cell::SetObjectItem(const SfxPoolItem& rItem)
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     if( mpProperties )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         mpProperties->SetObjectItem( rItem );
562cdf0e10cSrcweir         notifyModified();
563cdf0e10cSrcweir     }
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir void Cell::SetMergedItem(const SfxPoolItem& rItem)
567cdf0e10cSrcweir {
568cdf0e10cSrcweir     SetObjectItem(rItem);
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir SfxStyleSheet* Cell::GetStyleSheet() const
572cdf0e10cSrcweir {
573cdf0e10cSrcweir     if( mpProperties )
574cdf0e10cSrcweir         return mpProperties->GetStyleSheet();
575cdf0e10cSrcweir     else
576cdf0e10cSrcweir         return 0;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir // -----------------------------------------------------------------------------
580cdf0e10cSrcweir 
581cdf0e10cSrcweir SfxStyleSheetPool* Cell::GetStyleSheetPool() const
582cdf0e10cSrcweir {
583cdf0e10cSrcweir     if( mpProperties && mpProperties->GetStyleSheet() )
584cdf0e10cSrcweir         return dynamic_cast< SfxStyleSheetPool* >( &mpProperties->GetStyleSheet()->GetPool() );
585cdf0e10cSrcweir     else
586cdf0e10cSrcweir         return 0;
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir // -----------------------------------------------------------------------------
590cdf0e10cSrcweir 
591cdf0e10cSrcweir const Rectangle& Cell::GetCurrentBoundRect() const
592cdf0e10cSrcweir {
593cdf0e10cSrcweir     return maCellRect;
594cdf0e10cSrcweir }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir // -----------------------------------------------------------------------------
597cdf0e10cSrcweir 
598cdf0e10cSrcweir void Cell::TakeTextAnchorRect(Rectangle& rAnchorRect) const
599cdf0e10cSrcweir {
600cdf0e10cSrcweir     rAnchorRect.nLeft = maCellRect.nLeft + GetTextLeftDistance();
601cdf0e10cSrcweir     rAnchorRect.nRight = maCellRect.nRight - GetTextRightDistance();
602cdf0e10cSrcweir     rAnchorRect.nTop = maCellRect.nTop + GetTextUpperDistance();
603cdf0e10cSrcweir     rAnchorRect.nBottom = maCellRect.nBottom - GetTextLowerDistance();
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir // -----------------------------------------------------------------------------
607cdf0e10cSrcweir 
608cdf0e10cSrcweir const SfxItemSet& Cell::GetItemSet() const
609cdf0e10cSrcweir {
610cdf0e10cSrcweir     return mpProperties->GetObjectItemSet();
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir // -----------------------------------------------------------------------------
614cdf0e10cSrcweir 
615cdf0e10cSrcweir void Cell::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, sal_Bool bClearAllItems)
616cdf0e10cSrcweir {
617cdf0e10cSrcweir     if( mpProperties )
618cdf0e10cSrcweir     {
619cdf0e10cSrcweir         mpProperties->SetMergedItemSetAndBroadcast(rSet, bClearAllItems);
620cdf0e10cSrcweir         notifyModified();
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir // -----------------------------------------------------------------------------
625cdf0e10cSrcweir 
626cdf0e10cSrcweir sal_Int32 Cell::getMinimumWidth()
627cdf0e10cSrcweir {
628cdf0e10cSrcweir     return GetTextLeftDistance() + GetTextRightDistance() + 100;
629cdf0e10cSrcweir }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir // -----------------------------------------------------------------------------
632cdf0e10cSrcweir 
633cdf0e10cSrcweir sal_Int32 Cell::getMinimumHeight()
634cdf0e10cSrcweir {
635cdf0e10cSrcweir     if( !mpProperties )
636cdf0e10cSrcweir         return 0;
637cdf0e10cSrcweir 
638cdf0e10cSrcweir     SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
639cdf0e10cSrcweir     sal_Int32 nMinimumHeight = 0;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     Rectangle aTextRect;
642cdf0e10cSrcweir     TakeTextAnchorRect( aTextRect );
643cdf0e10cSrcweir     Size aSize( aTextRect.GetSize() );
644cdf0e10cSrcweir     aSize.Height()=0x0FFFFFFF;
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     SdrOutliner* pEditOutliner = rTableObj.GetCellTextEditOutliner( *this );
647cdf0e10cSrcweir     if(pEditOutliner)
648cdf0e10cSrcweir     {
649cdf0e10cSrcweir         pEditOutliner->SetMaxAutoPaperSize(aSize);
650cdf0e10cSrcweir         nMinimumHeight = pEditOutliner->GetTextHeight()+1;
651cdf0e10cSrcweir     }
652cdf0e10cSrcweir     else /*if ( hasText() )*/
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         Outliner& rOutliner=rTableObj.ImpGetDrawOutliner();
655cdf0e10cSrcweir         rOutliner.SetPaperSize(aSize);
656cdf0e10cSrcweir         rOutliner.SetUpdateMode(sal_True);
657cdf0e10cSrcweir         ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
658cdf0e10cSrcweir 
659cdf0e10cSrcweir         if( GetOutlinerParaObject() )
660cdf0e10cSrcweir         {
661cdf0e10cSrcweir             rOutliner.SetText(*GetOutlinerParaObject());
662cdf0e10cSrcweir         }
663cdf0e10cSrcweir         nMinimumHeight=rOutliner.GetTextHeight()+1;
664cdf0e10cSrcweir         rOutliner.Clear();
665cdf0e10cSrcweir     }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir     nMinimumHeight += GetTextUpperDistance() + GetTextLowerDistance();
668cdf0e10cSrcweir     return nMinimumHeight;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir // -----------------------------------------------------------------------------
672cdf0e10cSrcweir 
673cdf0e10cSrcweir long Cell::GetTextLeftDistance() const
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     return ((SdrTextLeftDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LEFTDIST))).GetValue();
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir // -----------------------------------------------------------------------------
679cdf0e10cSrcweir 
680cdf0e10cSrcweir long Cell::GetTextRightDistance() const
681cdf0e10cSrcweir {
682cdf0e10cSrcweir     return ((SdrTextRightDistItem&)(GetItemSet().Get(SDRATTR_TEXT_RIGHTDIST))).GetValue();
683cdf0e10cSrcweir }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir // -----------------------------------------------------------------------------
686cdf0e10cSrcweir 
687cdf0e10cSrcweir long Cell::GetTextUpperDistance() const
688cdf0e10cSrcweir {
689cdf0e10cSrcweir     return ((SdrTextUpperDistItem&)(GetItemSet().Get(SDRATTR_TEXT_UPPERDIST))).GetValue();
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir // -----------------------------------------------------------------------------
693cdf0e10cSrcweir 
694cdf0e10cSrcweir long Cell::GetTextLowerDistance() const
695cdf0e10cSrcweir {
696cdf0e10cSrcweir     return ((SdrTextLowerDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LOWERDIST))).GetValue();
697cdf0e10cSrcweir }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir // -----------------------------------------------------------------------------
700cdf0e10cSrcweir 
701cdf0e10cSrcweir SdrTextVertAdjust Cell::GetTextVerticalAdjust() const
702cdf0e10cSrcweir {
703cdf0e10cSrcweir     return ((SdrTextVertAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir // -----------------------------------------------------------------------------
707cdf0e10cSrcweir 
708cdf0e10cSrcweir SdrTextHorzAdjust Cell::GetTextHorizontalAdjust() const
709cdf0e10cSrcweir {
710cdf0e10cSrcweir     return ((SdrTextHorzAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_HORZADJUST))).GetValue();
711cdf0e10cSrcweir }
712cdf0e10cSrcweir 
713cdf0e10cSrcweir // -----------------------------------------------------------------------------
714cdf0e10cSrcweir 
715cdf0e10cSrcweir void Cell::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
716cdf0e10cSrcweir {
717cdf0e10cSrcweir     SdrText::SetOutlinerParaObject( pTextObject );
718cdf0e10cSrcweir     maSelection.nStartPara = 0xffff;
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     if( pTextObject == 0 )
721cdf0e10cSrcweir         ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir // -----------------------------------------------------------------------------
725cdf0e10cSrcweir 
726cdf0e10cSrcweir void Cell::AddUndo()
727cdf0e10cSrcweir {
728cdf0e10cSrcweir     SdrObject& rObj = GetObject();
729cdf0e10cSrcweir     if( rObj.IsInserted() && GetModel() && GetModel()->IsUndoEnabled() )
730cdf0e10cSrcweir     {
731cdf0e10cSrcweir         CellRef xCell( this );
732cdf0e10cSrcweir         GetModel()->AddUndo( new CellUndo( &rObj, xCell ) );
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir // -----------------------------------------------------------------------------
737cdf0e10cSrcweir 
738cdf0e10cSrcweir sdr::properties::TextProperties* Cell::CloneProperties( sdr::properties::TextProperties* pProperties, SdrObject& rNewObj, Cell& rNewCell )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir     if( pProperties )
741cdf0e10cSrcweir         return new sdr::properties::CellProperties( *static_cast<sdr::properties::CellProperties*>(pProperties), rNewObj, &rNewCell );
742cdf0e10cSrcweir     else
743cdf0e10cSrcweir         return 0;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir // -----------------------------------------------------------------------------
747cdf0e10cSrcweir 
748cdf0e10cSrcweir sdr::properties::TextProperties* Cell::CloneProperties( SdrObject& rNewObj, Cell& rNewCell )
749cdf0e10cSrcweir {
750cdf0e10cSrcweir     return CloneProperties(mpProperties,rNewObj,rNewCell);
751cdf0e10cSrcweir }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir // -----------------------------------------------------------------------------
754cdf0e10cSrcweir // XInterface
755cdf0e10cSrcweir // -----------------------------------------------------------------------------
756cdf0e10cSrcweir 
757cdf0e10cSrcweir Any SAL_CALL Cell::queryInterface( const Type & rType ) throw(RuntimeException)
758cdf0e10cSrcweir {
759cdf0e10cSrcweir     if( rType == XMergeableCell::static_type() )
760cdf0e10cSrcweir         return Any( Reference< XMergeableCell >( this ) );
761cdf0e10cSrcweir 
762cdf0e10cSrcweir     if( rType == XCell::static_type() )
763cdf0e10cSrcweir         return Any( Reference< XCell >( this ) );
764cdf0e10cSrcweir 
765cdf0e10cSrcweir     if( rType == XLayoutConstrains::static_type() )
766cdf0e10cSrcweir         return Any( Reference< XLayoutConstrains >( this ) );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     if( rType == XEventListener::static_type() )
769cdf0e10cSrcweir         return Any( Reference< XEventListener >( this ) );
770cdf0e10cSrcweir 
771cdf0e10cSrcweir     Any aRet( SvxUnoTextBase::queryAggregation( rType ) );
772cdf0e10cSrcweir     if( aRet.hasValue() )
773cdf0e10cSrcweir         return aRet;
774cdf0e10cSrcweir 
775cdf0e10cSrcweir     return ::cppu::OWeakObject::queryInterface( rType );
776cdf0e10cSrcweir }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir // -----------------------------------------------------------------------------
779cdf0e10cSrcweir 
780cdf0e10cSrcweir void SAL_CALL Cell::acquire() throw ()
781cdf0e10cSrcweir {
782cdf0e10cSrcweir     ::cppu::OWeakObject::acquire();
783cdf0e10cSrcweir }
784cdf0e10cSrcweir 
785cdf0e10cSrcweir // -----------------------------------------------------------------------------
786cdf0e10cSrcweir 
787cdf0e10cSrcweir void SAL_CALL Cell::release() throw ()
788cdf0e10cSrcweir {
789cdf0e10cSrcweir     ::cppu::OWeakObject::release();
790cdf0e10cSrcweir }
791cdf0e10cSrcweir 
792cdf0e10cSrcweir // -----------------------------------------------------------------------------
793cdf0e10cSrcweir // XTypeProvider
794cdf0e10cSrcweir // -----------------------------------------------------------------------------
795cdf0e10cSrcweir 
796cdf0e10cSrcweir Sequence< Type > SAL_CALL Cell::getTypes(  ) throw (RuntimeException)
797cdf0e10cSrcweir {
798cdf0e10cSrcweir     Sequence< Type > aTypes( SvxUnoTextBase::getTypes() );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     sal_Int32 nLen = aTypes.getLength();
801cdf0e10cSrcweir     aTypes.realloc(nLen + 2);
802cdf0e10cSrcweir     aTypes[nLen++] = XMergeableCell::static_type();
803cdf0e10cSrcweir     aTypes[nLen++] = XLayoutConstrains::static_type();
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     return aTypes;
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir // -----------------------------------------------------------------------------
809cdf0e10cSrcweir 
810cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL Cell::getImplementationId(  ) throw (RuntimeException)
811cdf0e10cSrcweir {
812cdf0e10cSrcweir     static ::cppu::OImplementationId* pId = 0;
813cdf0e10cSrcweir     if (! pId)
814cdf0e10cSrcweir     {
815cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
816cdf0e10cSrcweir         if (! pId)
817cdf0e10cSrcweir         {
818cdf0e10cSrcweir             static ::cppu::OImplementationId aId;
819cdf0e10cSrcweir             pId = &aId;
820cdf0e10cSrcweir         }
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir     return pId->getImplementationId();
823cdf0e10cSrcweir }
824cdf0e10cSrcweir 
825cdf0e10cSrcweir // -----------------------------------------------------------------------------
826cdf0e10cSrcweir // XServiceInfo
827cdf0e10cSrcweir // -----------------------------------------------------------------------------
828cdf0e10cSrcweir 
829cdf0e10cSrcweir OUString SAL_CALL Cell::getImplementationName(  ) throw (RuntimeException)
830cdf0e10cSrcweir {
831cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.table.Cell" ) );
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir // -----------------------------------------------------------------------------
835cdf0e10cSrcweir 
836cdf0e10cSrcweir sal_Bool SAL_CALL Cell::supportsService( const OUString& ServiceName ) throw (RuntimeException)
837cdf0e10cSrcweir {
838cdf0e10cSrcweir     if( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.table.cell" ) ) == 0 )
839cdf0e10cSrcweir         return sal_True;
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     if( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.cell" ) ) == 0 )
842cdf0e10cSrcweir         return sal_True;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     return SvxUnoTextBase::supportsService( ServiceName );
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir // -----------------------------------------------------------------------------
848cdf0e10cSrcweir 
849cdf0e10cSrcweir Sequence< OUString > SAL_CALL Cell::getSupportedServiceNames(  ) throw (RuntimeException)
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     Sequence< OUString > aSeq( SvxUnoTextBase::getSupportedServiceNames() );
852cdf0e10cSrcweir     sal_Int32 nIndex = aSeq.getLength();
853cdf0e10cSrcweir     aSeq.realloc( nIndex + 2 );
854cdf0e10cSrcweir     aSeq[nIndex++] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.cell" ) );
855cdf0e10cSrcweir     aSeq[nIndex++] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.cell" ) );
856cdf0e10cSrcweir     return aSeq;
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir // -----------------------------------------------------------------------------
860cdf0e10cSrcweir // XLayoutConstrains
861cdf0e10cSrcweir // -----------------------------------------------------------------------------
862cdf0e10cSrcweir 
863cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL Cell::getMinimumSize(  ) throw (RuntimeException)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir     return ::com::sun::star::awt::Size( getMinimumWidth(),  getMinimumHeight() );
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir // -----------------------------------------------------------------------------
869cdf0e10cSrcweir 
870cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL Cell::getPreferredSize(  ) throw (RuntimeException)
871cdf0e10cSrcweir {
872cdf0e10cSrcweir     return getMinimumSize();
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir // -----------------------------------------------------------------------------
876cdf0e10cSrcweir 
877cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL Cell::calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (RuntimeException)
878cdf0e10cSrcweir {
879cdf0e10cSrcweir     return aNewSize;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir // -----------------------------------------------------------------------------
883cdf0e10cSrcweir // XMergeableCell
884cdf0e10cSrcweir // -----------------------------------------------------------------------------
885cdf0e10cSrcweir 
886cdf0e10cSrcweir sal_Int32 SAL_CALL Cell::getRowSpan() throw (RuntimeException)
887cdf0e10cSrcweir {
888cdf0e10cSrcweir     return mnRowSpan;
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir // -----------------------------------------------------------------------------
892cdf0e10cSrcweir 
893cdf0e10cSrcweir sal_Int32 SAL_CALL Cell::getColumnSpan() throw (RuntimeException)
894cdf0e10cSrcweir {
895cdf0e10cSrcweir     return mnColSpan;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir // -----------------------------------------------------------------------------
899cdf0e10cSrcweir 
900cdf0e10cSrcweir sal_Bool SAL_CALL Cell::isMerged() throw (RuntimeException)
901cdf0e10cSrcweir {
902cdf0e10cSrcweir     return mbMerged;
903cdf0e10cSrcweir }
904cdf0e10cSrcweir 
905cdf0e10cSrcweir // -----------------------------------------------------------------------------
906cdf0e10cSrcweir // XCell
907cdf0e10cSrcweir // -----------------------------------------------------------------------------
908cdf0e10cSrcweir 
909cdf0e10cSrcweir OUString SAL_CALL Cell::getFormula(  ) throw (RuntimeException)
910cdf0e10cSrcweir {
911cdf0e10cSrcweir     return msFormula;
912cdf0e10cSrcweir }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir // -----------------------------------------------------------------------------
915cdf0e10cSrcweir 
916cdf0e10cSrcweir void SAL_CALL Cell::setFormula( const OUString& aFormula ) throw (RuntimeException)
917cdf0e10cSrcweir {
918cdf0e10cSrcweir     if( msFormula != aFormula )
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         msFormula = aFormula;
921cdf0e10cSrcweir     }
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir // -----------------------------------------------------------------------------
925cdf0e10cSrcweir 
926cdf0e10cSrcweir double SAL_CALL Cell::getValue(  ) throw (RuntimeException)
927cdf0e10cSrcweir {
928cdf0e10cSrcweir     return mfValue;
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
931cdf0e10cSrcweir // -----------------------------------------------------------------------------
932cdf0e10cSrcweir 
933cdf0e10cSrcweir void SAL_CALL Cell::setValue( double nValue ) throw (RuntimeException)
934cdf0e10cSrcweir {
935cdf0e10cSrcweir     if( mfValue == nValue )
936cdf0e10cSrcweir     {
937cdf0e10cSrcweir         mfValue = nValue;
938cdf0e10cSrcweir         mnCellContentType = CellContentType_VALUE;
939cdf0e10cSrcweir     }
940cdf0e10cSrcweir }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir // -----------------------------------------------------------------------------
943cdf0e10cSrcweir 
944cdf0e10cSrcweir CellContentType SAL_CALL Cell::getType() throw (RuntimeException)
945cdf0e10cSrcweir {
946cdf0e10cSrcweir     return mnCellContentType;
947cdf0e10cSrcweir }
948cdf0e10cSrcweir 
949cdf0e10cSrcweir // -----------------------------------------------------------------------------
950cdf0e10cSrcweir 
951cdf0e10cSrcweir sal_Int32 SAL_CALL Cell::getError(  ) throw (RuntimeException)
952cdf0e10cSrcweir {
953cdf0e10cSrcweir     return mnError;
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir // -----------------------------------------------------------------------------
957cdf0e10cSrcweir // XPropertySet
958cdf0e10cSrcweir // -----------------------------------------------------------------------------
959cdf0e10cSrcweir 
960cdf0e10cSrcweir Any Cell::GetAnyForItem( SfxItemSet& aSet, const SfxItemPropertySimpleEntry* pMap )
961cdf0e10cSrcweir {
962cdf0e10cSrcweir     Any aAny( SvxItemPropertySet_getPropertyValue( *mpPropSet, pMap, aSet ) );
963cdf0e10cSrcweir 
964cdf0e10cSrcweir     if( *pMap->pType != aAny.getValueType() )
965cdf0e10cSrcweir     {
966cdf0e10cSrcweir         // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
967cdf0e10cSrcweir         if( ( *pMap->pType == ::getCppuType((const sal_Int16*)0)) && aAny.getValueType() == ::getCppuType((const sal_Int32*)0) )
968cdf0e10cSrcweir         {
969cdf0e10cSrcweir             sal_Int32 nValue = 0;
970cdf0e10cSrcweir             aAny >>= nValue;
971cdf0e10cSrcweir             aAny <<= (sal_Int16)nValue;
972cdf0e10cSrcweir         }
973cdf0e10cSrcweir         else
974cdf0e10cSrcweir         {
975cdf0e10cSrcweir             DBG_ERROR("GetAnyForItem() Returnvalue has wrong Type!" );
976cdf0e10cSrcweir         }
977cdf0e10cSrcweir     }
978cdf0e10cSrcweir 
979cdf0e10cSrcweir     return aAny;
980cdf0e10cSrcweir }
981cdf0e10cSrcweir 
982cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL Cell::getPropertySetInfo() throw(RuntimeException)
983cdf0e10cSrcweir {
984cdf0e10cSrcweir     return mpPropSet->getPropertySetInfo();
985cdf0e10cSrcweir }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir // -----------------------------------------------------------------------------
988cdf0e10cSrcweir 
989cdf0e10cSrcweir void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
990cdf0e10cSrcweir {
991cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
992cdf0e10cSrcweir 
993cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
994cdf0e10cSrcweir         throw DisposedException();
995cdf0e10cSrcweir 
996cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName);
997cdf0e10cSrcweir     if( pMap )
998cdf0e10cSrcweir     {
999cdf0e10cSrcweir         if( (pMap->nFlags & PropertyAttribute::READONLY ) != 0 )
1000cdf0e10cSrcweir             throw PropertyVetoException();
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir         switch( pMap->nWID )
1003cdf0e10cSrcweir         {
1004cdf0e10cSrcweir         case OWN_ATTR_STYLE:
1005cdf0e10cSrcweir         {
1006cdf0e10cSrcweir             Reference< XStyle > xStyle;
1007cdf0e10cSrcweir             if( !( rValue >>= xStyle ) )
1008cdf0e10cSrcweir                 throw IllegalArgumentException();
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir             SfxUnoStyleSheet* pStyle = SfxUnoStyleSheet::getUnoStyleSheet(xStyle);
1011cdf0e10cSrcweir             SetStyleSheet( pStyle, sal_True );
1012cdf0e10cSrcweir             return;
1013cdf0e10cSrcweir         }
1014cdf0e10cSrcweir         case OWN_ATTR_TABLEBORDER:
1015cdf0e10cSrcweir         {
1016cdf0e10cSrcweir             if(rValue.getValueType() != ::getCppuType((const TableBorder*)0) )
1017cdf0e10cSrcweir                 break;
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir             const TableBorder* pBorder = (const TableBorder* )rValue.getValue();
1020cdf0e10cSrcweir             if( pBorder == NULL )
1021cdf0e10cSrcweir                 break;
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir             SvxBoxItem aBox( SDRATTR_TABLE_BORDER );
1024cdf0e10cSrcweir             SvxBoxInfoItem aBoxInfo( SDRATTR_TABLE_BORDER_INNER );
1025cdf0e10cSrcweir             SvxBorderLine aLine;
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir             sal_Bool bSet = SvxBoxItem::LineToSvxLine(pBorder->TopLine, aLine, false);
1028cdf0e10cSrcweir             aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_TOP);
1029cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_TOP, pBorder->IsTopLineValid);
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir             bSet = SvxBoxItem::LineToSvxLine(pBorder->BottomLine, aLine, false);
1032cdf0e10cSrcweir             aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_BOTTOM);
1033cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_BOTTOM, pBorder->IsBottomLineValid);
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir             bSet = SvxBoxItem::LineToSvxLine(pBorder->LeftLine, aLine, false);
1036cdf0e10cSrcweir             aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_LEFT);
1037cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_LEFT, pBorder->IsLeftLineValid);
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir             bSet = SvxBoxItem::LineToSvxLine(pBorder->RightLine, aLine, false);
1040cdf0e10cSrcweir             aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_RIGHT);
1041cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_RIGHT, pBorder->IsRightLineValid);
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir             bSet = SvxBoxItem::LineToSvxLine(pBorder->HorizontalLine, aLine, false);
1044cdf0e10cSrcweir             aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_HORI);
1045cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_HORI, pBorder->IsHorizontalLineValid);
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir             bSet = SvxBoxItem::LineToSvxLine(pBorder->VerticalLine, aLine, false);
1048cdf0e10cSrcweir             aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_VERT);
1049cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_VERT, pBorder->IsVerticalLineValid);
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir             aBox.SetDistance(pBorder->Distance, false);
1052cdf0e10cSrcweir             aBoxInfo.SetValid(VALID_DISTANCE, pBorder->IsDistanceValid);
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir             mpProperties->SetObjectItem(aBox);
1055cdf0e10cSrcweir             mpProperties->SetObjectItem(aBoxInfo);
1056cdf0e10cSrcweir             return;
1057cdf0e10cSrcweir         }
1058cdf0e10cSrcweir         case OWN_ATTR_FILLBMP_MODE:
1059cdf0e10cSrcweir         {
1060cdf0e10cSrcweir             BitmapMode eMode;
1061cdf0e10cSrcweir             if(!(rValue >>= eMode) )
1062cdf0e10cSrcweir             {
1063cdf0e10cSrcweir                 sal_Int32 nMode = 0;
1064cdf0e10cSrcweir                 if(!(rValue >>= nMode))
1065cdf0e10cSrcweir                     throw IllegalArgumentException();
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir                     eMode = (BitmapMode)nMode;
1068cdf0e10cSrcweir             }
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir             mpProperties->SetObjectItem( XFillBmpStretchItem( eMode == BitmapMode_STRETCH ) );
1071cdf0e10cSrcweir             mpProperties->SetObjectItem( XFillBmpTileItem( eMode == BitmapMode_REPEAT ) );
1072cdf0e10cSrcweir             return;
1073cdf0e10cSrcweir         }
1074cdf0e10cSrcweir         default:
1075cdf0e10cSrcweir         {
1076cdf0e10cSrcweir             SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1077cdf0e10cSrcweir             aSet.Put(mpProperties->GetItem(pMap->nWID));
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir             bool bSpecial = false;
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir             switch( pMap->nWID )
1082cdf0e10cSrcweir             {
1083cdf0e10cSrcweir                 case XATTR_FILLBITMAP:
1084cdf0e10cSrcweir                 case XATTR_FILLGRADIENT:
1085cdf0e10cSrcweir                 case XATTR_FILLHATCH:
1086cdf0e10cSrcweir                 case XATTR_FILLFLOATTRANSPARENCE:
1087cdf0e10cSrcweir                 case XATTR_LINEEND:
1088cdf0e10cSrcweir                 case XATTR_LINESTART:
1089cdf0e10cSrcweir                 case XATTR_LINEDASH:
1090cdf0e10cSrcweir                 {
1091cdf0e10cSrcweir                     if( pMap->nMemberId == MID_NAME )
1092cdf0e10cSrcweir                     {
1093cdf0e10cSrcweir                         OUString aApiName;
1094cdf0e10cSrcweir                         if( rValue >>= aApiName )
1095cdf0e10cSrcweir                         {
1096cdf0e10cSrcweir                             if( SvxShape::SetFillAttribute( pMap->nWID, aApiName, aSet, GetModel() ) )
1097cdf0e10cSrcweir                                 bSpecial = true;
1098cdf0e10cSrcweir                         }
1099cdf0e10cSrcweir                     }
1100cdf0e10cSrcweir                 }
1101cdf0e10cSrcweir                 break;
1102cdf0e10cSrcweir             }
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir             if( !bSpecial )
1105cdf0e10cSrcweir             {
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir                 if( !SvxUnoTextRangeBase::SetPropertyValueHelper( aSet, pMap, rValue, aSet ))
1108cdf0e10cSrcweir                 {
1109cdf0e10cSrcweir                     if( aSet.GetItemState( pMap->nWID ) != SFX_ITEM_SET )
1110cdf0e10cSrcweir                     {
1111cdf0e10cSrcweir                         // Default aus ItemPool holen
1112cdf0e10cSrcweir                         if(GetModel()->GetItemPool().IsWhich(pMap->nWID))
1113cdf0e10cSrcweir                             aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1114cdf0e10cSrcweir                     }
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir                     if( aSet.GetItemState( pMap->nWID ) == SFX_ITEM_SET )
1117cdf0e10cSrcweir                     {
1118cdf0e10cSrcweir                         SvxItemPropertySet_setPropertyValue( *mpPropSet, pMap, rValue, aSet );
1119cdf0e10cSrcweir                     }
1120cdf0e10cSrcweir                 }
1121cdf0e10cSrcweir             }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir             GetModel()->SetChanged();
1124cdf0e10cSrcweir             mpProperties->SetMergedItemSetAndBroadcast( aSet );
1125cdf0e10cSrcweir             return;
1126cdf0e10cSrcweir         }
1127cdf0e10cSrcweir         }
1128cdf0e10cSrcweir     }
1129cdf0e10cSrcweir     throw UnknownPropertyException();
1130cdf0e10cSrcweir }
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir // -----------------------------------------------------------------------------
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1139cdf0e10cSrcweir         throw DisposedException();
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1142cdf0e10cSrcweir     if( pMap )
1143cdf0e10cSrcweir     {
1144cdf0e10cSrcweir         switch( pMap->nWID )
1145cdf0e10cSrcweir         {
1146cdf0e10cSrcweir /*
1147cdf0e10cSrcweir         case OWN_ATTR_HASLEVELS:
1148cdf0e10cSrcweir         {
1149cdf0e10cSrcweir             return Any( hasLevels() );
1150cdf0e10cSrcweir         }
1151cdf0e10cSrcweir */
1152cdf0e10cSrcweir         case OWN_ATTR_STYLE:
1153cdf0e10cSrcweir         {
1154cdf0e10cSrcweir             return Any( Reference< XStyle >( dynamic_cast< SfxUnoStyleSheet* >( GetStyleSheet() ) ) );
1155cdf0e10cSrcweir         }
1156cdf0e10cSrcweir         case OWN_ATTR_TABLEBORDER:
1157cdf0e10cSrcweir         {
1158cdf0e10cSrcweir             const SvxBoxInfoItem& rBoxInfoItem = static_cast<const SvxBoxInfoItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER_INNER));
1159cdf0e10cSrcweir             const SvxBoxItem& rBox = static_cast<const SvxBoxItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER));
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir             TableBorder aTableBorder;
1162cdf0e10cSrcweir             aTableBorder.TopLine                = SvxBoxItem::SvxLineToLine(rBox.GetTop(), false);
1163cdf0e10cSrcweir             aTableBorder.IsTopLineValid         = rBoxInfoItem.IsValid(VALID_TOP);
1164cdf0e10cSrcweir             aTableBorder.BottomLine             = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), false);
1165cdf0e10cSrcweir             aTableBorder.IsBottomLineValid      = rBoxInfoItem.IsValid(VALID_BOTTOM);
1166cdf0e10cSrcweir             aTableBorder.LeftLine               = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), false);
1167cdf0e10cSrcweir             aTableBorder.IsLeftLineValid        = rBoxInfoItem.IsValid(VALID_LEFT);
1168cdf0e10cSrcweir             aTableBorder.RightLine              = SvxBoxItem::SvxLineToLine(rBox.GetRight(), false);
1169cdf0e10cSrcweir             aTableBorder.IsRightLineValid       = rBoxInfoItem.IsValid(VALID_RIGHT );
1170cdf0e10cSrcweir             aTableBorder.HorizontalLine         = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), false);
1171cdf0e10cSrcweir             aTableBorder.IsHorizontalLineValid  = rBoxInfoItem.IsValid(VALID_HORI);
1172cdf0e10cSrcweir             aTableBorder.VerticalLine           = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), false);
1173cdf0e10cSrcweir             aTableBorder.IsVerticalLineValid    = rBoxInfoItem.IsValid(VALID_VERT);
1174cdf0e10cSrcweir             aTableBorder.Distance               = rBox.GetDistance();
1175cdf0e10cSrcweir             aTableBorder.IsDistanceValid        = rBoxInfoItem.IsValid(VALID_DISTANCE);
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir             return Any( aTableBorder );
1178cdf0e10cSrcweir         }
1179cdf0e10cSrcweir         case OWN_ATTR_FILLBMP_MODE:
1180cdf0e10cSrcweir         {
1181cdf0e10cSrcweir             const XFillBmpStretchItem& rStretchItem = static_cast<const XFillBmpStretchItem&>(mpProperties->GetItem(XATTR_FILLBMP_STRETCH));
1182cdf0e10cSrcweir             const XFillBmpTileItem& rTileItem = static_cast<const XFillBmpTileItem&>(mpProperties->GetItem(XATTR_FILLBMP_TILE));
1183cdf0e10cSrcweir             if( rTileItem.GetValue() )
1184cdf0e10cSrcweir             {
1185cdf0e10cSrcweir                 return Any( BitmapMode_REPEAT );
1186cdf0e10cSrcweir             }
1187cdf0e10cSrcweir             else if( rStretchItem.GetValue() )
1188cdf0e10cSrcweir             {
1189cdf0e10cSrcweir                 return Any(  BitmapMode_STRETCH );
1190cdf0e10cSrcweir             }
1191cdf0e10cSrcweir             else
1192cdf0e10cSrcweir             {
1193cdf0e10cSrcweir                 return Any(  BitmapMode_NO_REPEAT );
1194cdf0e10cSrcweir             }
1195cdf0e10cSrcweir         }
1196cdf0e10cSrcweir         default:
1197cdf0e10cSrcweir         {
1198cdf0e10cSrcweir             SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1199cdf0e10cSrcweir             aSet.Put(mpProperties->GetItem(pMap->nWID));
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir             Any aAny;
1202cdf0e10cSrcweir             if(!SvxUnoTextRangeBase::GetPropertyValueHelper( aSet, pMap, aAny ))
1203cdf0e10cSrcweir             {
1204cdf0e10cSrcweir                 if(!aSet.Count())
1205cdf0e10cSrcweir                 {
1206cdf0e10cSrcweir                     // Default aus ItemPool holen
1207cdf0e10cSrcweir                     if(GetModel()->GetItemPool().IsWhich(pMap->nWID))
1208cdf0e10cSrcweir                         aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1209cdf0e10cSrcweir                 }
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir                 if( aSet.Count() )
1212cdf0e10cSrcweir                     aAny = GetAnyForItem( aSet, pMap );
1213cdf0e10cSrcweir             }
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir             return aAny;
1216cdf0e10cSrcweir         }
1217cdf0e10cSrcweir         }
1218cdf0e10cSrcweir     }
1219cdf0e10cSrcweir     throw UnknownPropertyException();
1220cdf0e10cSrcweir }
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir // -----------------------------------------------------------------------------
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir void SAL_CALL Cell::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir // -----------------------------------------------------------------------------
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir void SAL_CALL Cell::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir // -----------------------------------------------------------------------------
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir void SAL_CALL Cell::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir // -----------------------------------------------------------------------------
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir void SAL_CALL Cell::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir // -----------------------------------------------------------------------------
1247cdf0e10cSrcweir // XMultiPropertySet
1248cdf0e10cSrcweir // -----------------------------------------------------------------------------
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir     OGuard aSolarGuard( Application::GetSolarMutex() );
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1255cdf0e10cSrcweir         throw DisposedException();
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir     const sal_Int32 nCount = aPropertyNames.getLength();
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir     const OUString* pNames = aPropertyNames.getConstArray();
1260cdf0e10cSrcweir     const Any* pValues = aValues.getConstArray();
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pValues++ )
1263cdf0e10cSrcweir     {
1264cdf0e10cSrcweir         try
1265cdf0e10cSrcweir         {
1266cdf0e10cSrcweir             setPropertyValue( *pNames, *pValues );
1267cdf0e10cSrcweir         }
1268cdf0e10cSrcweir         catch( UnknownPropertyException& )
1269cdf0e10cSrcweir         {
1270cdf0e10cSrcweir             DBG_ERROR("svx::Cell::setPropertyValues(), unknown property!" );
1271cdf0e10cSrcweir         }
1272cdf0e10cSrcweir         catch( Exception& )
1273cdf0e10cSrcweir         {
1274cdf0e10cSrcweir             DBG_ERROR("svx::Cell::setPropertyValues(), Exception caught!" );
1275cdf0e10cSrcweir         }
1276cdf0e10cSrcweir     }
1277cdf0e10cSrcweir }
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir // -----------------------------------------------------------------------------
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException)
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir     OGuard aSolarGuard( Application::GetSolarMutex() );
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1286cdf0e10cSrcweir         throw DisposedException();
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir     const sal_Int32 nCount = aPropertyNames.getLength();
1289cdf0e10cSrcweir     const OUString* pNames = aPropertyNames.getConstArray();
1290cdf0e10cSrcweir 
1291cdf0e10cSrcweir     Sequence< Any > aRet( nCount );
1292cdf0e10cSrcweir     Any* pValue = aRet.getArray();
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir     for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pValue++, pNames++ )
1295cdf0e10cSrcweir     {
1296cdf0e10cSrcweir         try
1297cdf0e10cSrcweir         {
1298cdf0e10cSrcweir             *pValue = getPropertyValue( *pNames );
1299cdf0e10cSrcweir         }
1300cdf0e10cSrcweir         catch( UnknownPropertyException& )
1301cdf0e10cSrcweir         {
1302cdf0e10cSrcweir             DBG_ERROR("svx::Cell::setPropertyValues(), unknown property!" );
1303cdf0e10cSrcweir         }
1304cdf0e10cSrcweir         catch( Exception& )
1305cdf0e10cSrcweir         {
1306cdf0e10cSrcweir             DBG_ERROR( "svx::Cell::getPropertyValues(), Exception caught!" );
1307cdf0e10cSrcweir         }
1308cdf0e10cSrcweir     }
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir     return aRet;
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir // -----------------------------------------------------------------------------
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir void SAL_CALL Cell::addPropertiesChangeListener( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir // -----------------------------------------------------------------------------
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir void SAL_CALL Cell::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir // -----------------------------------------------------------------------------
1326cdf0e10cSrcweir 
1327cdf0e10cSrcweir void SAL_CALL Cell::firePropertiesChangeEvent( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1328cdf0e10cSrcweir {
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir // -----------------------------------------------------------------------------
1332cdf0e10cSrcweir // XPropertyState
1333cdf0e10cSrcweir // -----------------------------------------------------------------------------
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1336cdf0e10cSrcweir {
1337cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1340cdf0e10cSrcweir         throw DisposedException();
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir     if( pMap )
1345cdf0e10cSrcweir     {
1346cdf0e10cSrcweir         PropertyState eState;
1347cdf0e10cSrcweir         switch( pMap->nWID )
1348cdf0e10cSrcweir         {
1349cdf0e10cSrcweir         case OWN_ATTR_FILLBMP_MODE:
1350cdf0e10cSrcweir         {
1351cdf0e10cSrcweir             const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir             const bool bStretch = rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET;
1354cdf0e10cSrcweir             const bool bTile = rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET;
1355cdf0e10cSrcweir             if( bStretch || bTile )
1356cdf0e10cSrcweir             {
1357cdf0e10cSrcweir                 eState = PropertyState_DIRECT_VALUE;
1358cdf0e10cSrcweir             }
1359cdf0e10cSrcweir             else
1360cdf0e10cSrcweir             {
1361cdf0e10cSrcweir                 eState = PropertyState_DEFAULT_VALUE;
1362cdf0e10cSrcweir             }
1363cdf0e10cSrcweir         }
1364cdf0e10cSrcweir /*
1365cdf0e10cSrcweir         case OWN_ATTR_HASLEVELS:
1366cdf0e10cSrcweir         {
1367cdf0e10cSrcweir             return PropertyState_DIRECT_VALUE;
1368cdf0e10cSrcweir         }
1369cdf0e10cSrcweir */
1370cdf0e10cSrcweir         case OWN_ATTR_STYLE:
1371cdf0e10cSrcweir         {
1372cdf0e10cSrcweir             return PropertyState_DIRECT_VALUE;
1373cdf0e10cSrcweir         }
1374cdf0e10cSrcweir         case OWN_ATTR_TABLEBORDER:
1375cdf0e10cSrcweir         {
1376cdf0e10cSrcweir             const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1377cdf0e10cSrcweir             if( (rSet.GetItemState( SDRATTR_TABLE_BORDER_INNER, sal_False ) == SFX_ITEM_DEFAULT) && (rSet.GetItemState( SDRATTR_TABLE_BORDER, sal_False ) == SFX_ITEM_DEFAULT) )
1378cdf0e10cSrcweir                 return PropertyState_DEFAULT_VALUE;
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir             return PropertyState_DIRECT_VALUE;
1381cdf0e10cSrcweir         }
1382cdf0e10cSrcweir         default:
1383cdf0e10cSrcweir         {
1384cdf0e10cSrcweir             const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir             switch( rSet.GetItemState( pMap->nWID, sal_False ) )
1387cdf0e10cSrcweir             {
1388cdf0e10cSrcweir             case SFX_ITEM_READONLY:
1389cdf0e10cSrcweir             case SFX_ITEM_SET:
1390cdf0e10cSrcweir                 eState = PropertyState_DIRECT_VALUE;
1391cdf0e10cSrcweir                 break;
1392cdf0e10cSrcweir             case SFX_ITEM_DEFAULT:
1393cdf0e10cSrcweir                 eState = PropertyState_DEFAULT_VALUE;
1394cdf0e10cSrcweir                 break;
1395cdf0e10cSrcweir     //      case SFX_ITEM_UNKNOWN:
1396cdf0e10cSrcweir     //      case SFX_ITEM_DONTCARE:
1397cdf0e10cSrcweir     //      case SFX_ITEM_DISABLED:
1398cdf0e10cSrcweir             default:
1399cdf0e10cSrcweir                 eState = PropertyState_AMBIGUOUS_VALUE;
1400cdf0e10cSrcweir                 break;
1401cdf0e10cSrcweir             }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir             // if a item is set, this doesn't mean we want it :)
1404cdf0e10cSrcweir             if( ( PropertyState_DIRECT_VALUE == eState ) )
1405cdf0e10cSrcweir             {
1406cdf0e10cSrcweir                 switch( pMap->nWID )
1407cdf0e10cSrcweir                 {
1408cdf0e10cSrcweir                 // the following items are disabled by changing the
1409cdf0e10cSrcweir                 // fill style or the line style. so there is no need
1410cdf0e10cSrcweir                 // to export items without names which should be empty
1411cdf0e10cSrcweir                 case XATTR_FILLBITMAP:
1412cdf0e10cSrcweir                 case XATTR_FILLGRADIENT:
1413cdf0e10cSrcweir                 case XATTR_FILLHATCH:
1414cdf0e10cSrcweir                 case XATTR_LINEDASH:
1415cdf0e10cSrcweir                     {
1416cdf0e10cSrcweir                         NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID);
1417cdf0e10cSrcweir                         if( ( pItem == NULL ) || ( pItem->GetName().Len() == 0) )
1418cdf0e10cSrcweir                             eState = PropertyState_DEFAULT_VALUE;
1419cdf0e10cSrcweir                     }
1420cdf0e10cSrcweir                     break;
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir                 // #i36115#
1423cdf0e10cSrcweir                 // If e.g. the LineStart is on NONE and thus the string has length 0, it still
1424cdf0e10cSrcweir                 // may be a hard attribute covering the set LineStart of the parent (Style).
1425cdf0e10cSrcweir                 // #i37644#
1426cdf0e10cSrcweir                 // same is for fill float transparency
1427cdf0e10cSrcweir                 case XATTR_LINEEND:
1428cdf0e10cSrcweir                 case XATTR_LINESTART:
1429cdf0e10cSrcweir                 case XATTR_FILLFLOATTRANSPARENCE:
1430cdf0e10cSrcweir                     {
1431cdf0e10cSrcweir                         NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID);
1432cdf0e10cSrcweir                         if( ( pItem == NULL ) )
1433cdf0e10cSrcweir                             eState = PropertyState_DEFAULT_VALUE;
1434cdf0e10cSrcweir                     }
1435cdf0e10cSrcweir                     break;
1436cdf0e10cSrcweir                 }
1437cdf0e10cSrcweir             }
1438cdf0e10cSrcweir         }
1439cdf0e10cSrcweir         }
1440cdf0e10cSrcweir         return eState;
1441cdf0e10cSrcweir     }
1442cdf0e10cSrcweir     throw UnknownPropertyException();
1443cdf0e10cSrcweir }
1444cdf0e10cSrcweir 
1445cdf0e10cSrcweir // -----------------------------------------------------------------------------
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
1448cdf0e10cSrcweir {
1449cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1452cdf0e10cSrcweir         throw DisposedException();
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir     const sal_Int32 nCount = aPropertyName.getLength();
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir     Sequence< PropertyState > aRet( nCount );
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir     const OUString* pNames = aPropertyName.getConstArray();
1459cdf0e10cSrcweir     PropertyState* pState = aRet.getArray();
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir     for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pState++ )
1462cdf0e10cSrcweir     {
1463cdf0e10cSrcweir         try
1464cdf0e10cSrcweir         {
1465cdf0e10cSrcweir             *pState = getPropertyState( *pNames );
1466cdf0e10cSrcweir         }
1467cdf0e10cSrcweir         catch( Exception& )
1468cdf0e10cSrcweir         {
1469cdf0e10cSrcweir             *pState = PropertyState_AMBIGUOUS_VALUE;
1470cdf0e10cSrcweir         }
1471cdf0e10cSrcweir     }
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir     return aRet;
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir // -----------------------------------------------------------------------------
1477cdf0e10cSrcweir 
1478cdf0e10cSrcweir void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1479cdf0e10cSrcweir {
1480cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1483cdf0e10cSrcweir         throw DisposedException();
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1486cdf0e10cSrcweir     if( pMap )
1487cdf0e10cSrcweir     {
1488cdf0e10cSrcweir         switch( pMap->nWID )
1489cdf0e10cSrcweir         {
1490cdf0e10cSrcweir         case OWN_ATTR_FILLBMP_MODE:
1491cdf0e10cSrcweir         {
1492cdf0e10cSrcweir             mpProperties->ClearObjectItem( XATTR_FILLBMP_STRETCH );
1493cdf0e10cSrcweir             mpProperties->ClearObjectItem( XATTR_FILLBMP_TILE );
1494cdf0e10cSrcweir             break;
1495cdf0e10cSrcweir         }
1496cdf0e10cSrcweir //      case OWN_ATTR_HASLEVELS:
1497cdf0e10cSrcweir         case OWN_ATTR_STYLE:
1498cdf0e10cSrcweir             break;
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir         case OWN_ATTR_TABLEBORDER:
1501cdf0e10cSrcweir         {
1502cdf0e10cSrcweir             mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER_INNER );
1503cdf0e10cSrcweir             mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER );
1504cdf0e10cSrcweir             break;
1505cdf0e10cSrcweir         }
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir         default:
1508cdf0e10cSrcweir         {
1509cdf0e10cSrcweir             mpProperties->ClearObjectItem( pMap->nWID );
1510cdf0e10cSrcweir         }
1511cdf0e10cSrcweir         }
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir         GetModel()->SetChanged();
1514cdf0e10cSrcweir         return;
1515cdf0e10cSrcweir     }
1516cdf0e10cSrcweir     throw UnknownPropertyException();
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir // -----------------------------------------------------------------------------
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir     if( (mpProperties == 0) || (GetModel() == 0) )
1526cdf0e10cSrcweir         throw DisposedException();
1527cdf0e10cSrcweir 
1528cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName);
1529cdf0e10cSrcweir     if( pMap )
1530cdf0e10cSrcweir     {
1531cdf0e10cSrcweir         switch( pMap->nWID )
1532cdf0e10cSrcweir         {
1533cdf0e10cSrcweir         case OWN_ATTR_FILLBMP_MODE:
1534cdf0e10cSrcweir             return Any(  BitmapMode_NO_REPEAT );
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir /*
1537cdf0e10cSrcweir         case OWN_ATTR_HASLEVELS:
1538cdf0e10cSrcweir             return Any( sal_False );
1539cdf0e10cSrcweir */
1540cdf0e10cSrcweir         case OWN_ATTR_STYLE:
1541cdf0e10cSrcweir         {
1542cdf0e10cSrcweir             Reference< XStyle > xStyle;
1543cdf0e10cSrcweir             return Any( xStyle );
1544cdf0e10cSrcweir         }
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir         case OWN_ATTR_TABLEBORDER:
1547cdf0e10cSrcweir         {
1548cdf0e10cSrcweir             TableBorder aBorder;
1549cdf0e10cSrcweir             return Any( aBorder );
1550cdf0e10cSrcweir         }
1551cdf0e10cSrcweir 
1552cdf0e10cSrcweir         default:
1553cdf0e10cSrcweir         {
1554cdf0e10cSrcweir             if(  GetModel()->GetItemPool().IsWhich(pMap->nWID) )
1555cdf0e10cSrcweir             {
1556cdf0e10cSrcweir                 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1557cdf0e10cSrcweir                 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1558cdf0e10cSrcweir                 return GetAnyForItem( aSet, pMap );
1559cdf0e10cSrcweir             }
1560cdf0e10cSrcweir         }
1561cdf0e10cSrcweir         }
1562cdf0e10cSrcweir     }
1563cdf0e10cSrcweir     throw UnknownPropertyException();
1564cdf0e10cSrcweir }
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir // -----------------------------------------------------------------------------
1567cdf0e10cSrcweir // XMultiPropertyStates
1568cdf0e10cSrcweir // -----------------------------------------------------------------------------
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir void SAL_CALL Cell::setAllPropertiesToDefault(  ) throw (RuntimeException)
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir     if( mpProperties )
1573cdf0e10cSrcweir         delete mpProperties;
1574cdf0e10cSrcweir     mpProperties = new sdr::properties::CellProperties( static_cast< SdrTableObj& >( GetObject() ), this );
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir     SdrOutliner& rOutliner = GetObject().ImpGetDrawOutliner();
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir     OutlinerParaObject* pParaObj = GetOutlinerParaObject();
1579cdf0e10cSrcweir     if( pParaObj )
1580cdf0e10cSrcweir     {
1581cdf0e10cSrcweir         rOutliner.SetText(*pParaObj);
1582cdf0e10cSrcweir         sal_uInt32 nParaCount(rOutliner.GetParagraphCount());
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir         if(nParaCount)
1585cdf0e10cSrcweir         {
1586cdf0e10cSrcweir             ESelection aSelection( 0, 0, EE_PARA_ALL, EE_PARA_ALL);
1587cdf0e10cSrcweir             rOutliner.RemoveAttribs(aSelection, sal_True, 0);
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir             OutlinerParaObject* pTemp = rOutliner.CreateParaObject(0, (sal_uInt16)nParaCount);
1590cdf0e10cSrcweir             rOutliner.Clear();
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir             SetOutlinerParaObject(pTemp);
1593cdf0e10cSrcweir         }
1594cdf0e10cSrcweir     }
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir // -----------------------------------------------------------------------------
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir void SAL_CALL Cell::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, RuntimeException)
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir     sal_Int32 nCount = aPropertyNames.getLength();
1602cdf0e10cSrcweir     const OUString* pName = aPropertyNames.getConstArray();
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir     while(nCount--)
1605cdf0e10cSrcweir         setPropertyToDefault( *pName++ );
1606cdf0e10cSrcweir }
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir // -----------------------------------------------------------------------------
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir Sequence< Any > SAL_CALL Cell::getPropertyDefaults( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1611cdf0e10cSrcweir {
1612cdf0e10cSrcweir     sal_Int32 nCount = aPropertyNames.getLength();
1613cdf0e10cSrcweir     Sequence< Any > aDefaults( nCount );
1614cdf0e10cSrcweir     Any* pDefaults = aDefaults.getArray();
1615cdf0e10cSrcweir     const OUString* pName = aPropertyNames.getConstArray();
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir     while(nCount--)
1618cdf0e10cSrcweir         *pDefaults++ = getPropertyDefault( *pName++ );
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir     return aDefaults;
1621cdf0e10cSrcweir }
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir // -----------------------------------------------------------------------------
1624cdf0e10cSrcweir // XFastPropertySet
1625cdf0e10cSrcweir // -----------------------------------------------------------------------------
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir void SAL_CALL Cell::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir     (void)aValue;
1630cdf0e10cSrcweir     (void)nHandle;
1631cdf0e10cSrcweir     throw UnknownPropertyException();
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir // -----------------------------------------------------------------------------
1635cdf0e10cSrcweir // TODO: Refactor this method!
1636cdf0e10cSrcweir Any SAL_CALL Cell::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1637cdf0e10cSrcweir {
1638cdf0e10cSrcweir     (void)nHandle;
1639cdf0e10cSrcweir     throw UnknownPropertyException();
1640cdf0e10cSrcweir }
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir // -----------------------------------------------------------------------------
1643cdf0e10cSrcweir // XText
1644cdf0e10cSrcweir // -----------------------------------------------------------------------------
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir void SAL_CALL Cell::insertTextContent( const Reference< XTextRange >& xRange, const Reference< XTextContent >& xContent, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException)
1647cdf0e10cSrcweir {
1648cdf0e10cSrcweir     SvxUnoTextBase::insertTextContent( xRange, xContent, bAbsorb );
1649cdf0e10cSrcweir     notifyModified();
1650cdf0e10cSrcweir }
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir // -----------------------------------------------------------------------------
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir void SAL_CALL Cell::removeTextContent( const Reference< XTextContent >& xContent ) throw (NoSuchElementException, RuntimeException)
1655cdf0e10cSrcweir {
1656cdf0e10cSrcweir     SvxUnoTextBase::removeTextContent( xContent );
1657cdf0e10cSrcweir     notifyModified();
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir // -----------------------------------------------------------------------------
1661cdf0e10cSrcweir // XSimpleText
1662cdf0e10cSrcweir // -----------------------------------------------------------------------------
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir Reference< XTextCursor > SAL_CALL Cell::createTextCursor(  ) throw (RuntimeException)
1665cdf0e10cSrcweir {
1666cdf0e10cSrcweir     return SvxUnoTextBase::createTextCursor();
1667cdf0e10cSrcweir }
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir // -----------------------------------------------------------------------------
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir Reference< XTextCursor > SAL_CALL Cell::createTextCursorByRange( const Reference< XTextRange >& aTextPosition ) throw (RuntimeException)
1672cdf0e10cSrcweir {
1673cdf0e10cSrcweir     return SvxUnoTextBase::createTextCursorByRange( aTextPosition );
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir // -----------------------------------------------------------------------------
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir void SAL_CALL Cell::insertString( const Reference< XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb ) throw (RuntimeException)
1679cdf0e10cSrcweir {
1680cdf0e10cSrcweir     SvxUnoTextBase::insertString( xRange, aString, bAbsorb );
1681cdf0e10cSrcweir     notifyModified();
1682cdf0e10cSrcweir }
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir // -----------------------------------------------------------------------------
1685cdf0e10cSrcweir 
1686cdf0e10cSrcweir void SAL_CALL Cell::insertControlCharacter( const Reference< XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException)
1687cdf0e10cSrcweir {
1688cdf0e10cSrcweir     SvxUnoTextBase::insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1689cdf0e10cSrcweir     notifyModified();
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir // -----------------------------------------------------------------------------
1693cdf0e10cSrcweir // XTextRange
1694cdf0e10cSrcweir // -----------------------------------------------------------------------------
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir Reference< XText > SAL_CALL Cell::getText(  ) throw (RuntimeException)
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir     return SvxUnoTextBase::getText();
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir // -----------------------------------------------------------------------------
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir Reference< XTextRange > SAL_CALL Cell::getStart(  ) throw (RuntimeException)
1704cdf0e10cSrcweir {
1705cdf0e10cSrcweir     return SvxUnoTextBase::getStart();
1706cdf0e10cSrcweir }
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir // -----------------------------------------------------------------------------
1709cdf0e10cSrcweir 
1710cdf0e10cSrcweir Reference< XTextRange > SAL_CALL Cell::getEnd(  ) throw (RuntimeException)
1711cdf0e10cSrcweir {
1712cdf0e10cSrcweir     return SvxUnoTextBase::getEnd();
1713cdf0e10cSrcweir }
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir // -----------------------------------------------------------------------------
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir OUString SAL_CALL Cell::getString(  ) throw (RuntimeException)
1718cdf0e10cSrcweir {
1719cdf0e10cSrcweir     maSelection.nStartPara = 0xffff;
1720cdf0e10cSrcweir     return SvxUnoTextBase::getString();
1721cdf0e10cSrcweir }
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir // -----------------------------------------------------------------------------
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir void SAL_CALL Cell::setString( const OUString& aString ) throw (RuntimeException)
1726cdf0e10cSrcweir {
1727cdf0e10cSrcweir     SvxUnoTextBase::setString( aString );
1728cdf0e10cSrcweir     notifyModified();
1729cdf0e10cSrcweir }
1730cdf0e10cSrcweir 
1731cdf0e10cSrcweir // XEventListener
1732cdf0e10cSrcweir void SAL_CALL Cell::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
1733cdf0e10cSrcweir {
1734cdf0e10cSrcweir     mxTable.clear();
1735cdf0e10cSrcweir     dispose();
1736cdf0e10cSrcweir }
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir static OUString getCellName( sal_Int32 nCol, sal_Int32 nRow )
1739cdf0e10cSrcweir {
1740cdf0e10cSrcweir     rtl::OUStringBuffer aBuf;
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir     if (nCol < 26*26)
1743cdf0e10cSrcweir     {
1744cdf0e10cSrcweir         if (nCol < 26)
1745cdf0e10cSrcweir             aBuf.append( static_cast<sal_Unicode>( 'A' +
1746cdf0e10cSrcweir                         static_cast<sal_uInt16>(nCol)));
1747cdf0e10cSrcweir         else
1748cdf0e10cSrcweir         {
1749cdf0e10cSrcweir             aBuf.append( static_cast<sal_Unicode>( 'A' +
1750cdf0e10cSrcweir                         (static_cast<sal_uInt16>(nCol) / 26) - 1));
1751cdf0e10cSrcweir             aBuf.append( static_cast<sal_Unicode>( 'A' +
1752cdf0e10cSrcweir                         (static_cast<sal_uInt16>(nCol) % 26)));
1753cdf0e10cSrcweir         }
1754cdf0e10cSrcweir     }
1755cdf0e10cSrcweir     else
1756cdf0e10cSrcweir     {
1757cdf0e10cSrcweir         String aStr;
1758cdf0e10cSrcweir         while (nCol >= 26)
1759cdf0e10cSrcweir         {
1760cdf0e10cSrcweir             sal_Int32 nC = nCol % 26;
1761cdf0e10cSrcweir             aStr += static_cast<sal_Unicode>( 'A' +
1762cdf0e10cSrcweir                     static_cast<sal_uInt16>(nC));
1763cdf0e10cSrcweir             nCol = nCol - nC;
1764cdf0e10cSrcweir             nCol = nCol / 26 - 1;
1765cdf0e10cSrcweir         }
1766cdf0e10cSrcweir         aStr += static_cast<sal_Unicode>( 'A' +
1767cdf0e10cSrcweir                 static_cast<sal_uInt16>(nCol));
1768cdf0e10cSrcweir         aStr.Reverse();
1769cdf0e10cSrcweir         aBuf.append( aStr);
1770cdf0e10cSrcweir     }
1771cdf0e10cSrcweir     aBuf.append( OUString::valueOf(nRow+1) );
1772cdf0e10cSrcweir     return aBuf.makeStringAndClear();
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir OUString Cell::getName()
1776cdf0e10cSrcweir {
1777cdf0e10cSrcweir     // todo: optimize!
1778cdf0e10cSrcweir     OUString sName;
1779cdf0e10cSrcweir     if( mxTable.is() ) try
1780cdf0e10cSrcweir     {
1781cdf0e10cSrcweir         Reference< XCell > xThis( static_cast< XCell* >( this ) );
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir         sal_Int32 nRowCount = mxTable->getRowCount();
1784cdf0e10cSrcweir         sal_Int32 nColCount = mxTable->getColumnCount();
1785cdf0e10cSrcweir         for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ )
1786cdf0e10cSrcweir         {
1787cdf0e10cSrcweir             for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
1788cdf0e10cSrcweir             {
1789cdf0e10cSrcweir                 Reference< XCell > xCell( mxTable->getCellByPosition( nCol, nRow ) );
1790cdf0e10cSrcweir                 if( xCell == xThis )
1791cdf0e10cSrcweir                 {
1792cdf0e10cSrcweir                     return getCellName( nCol, nRow );
1793cdf0e10cSrcweir                 }
1794cdf0e10cSrcweir             }
1795cdf0e10cSrcweir         }
1796cdf0e10cSrcweir     }
1797cdf0e10cSrcweir     catch( Exception& )
1798cdf0e10cSrcweir     {
1799cdf0e10cSrcweir     }
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir     return sName;
1802cdf0e10cSrcweir }
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir } }
1805cdf0e10cSrcweir 
1806