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