xref: /trunk/main/sw/source/core/unocore/unotbl.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 // STL includes
29 #include <list>
30 
31 #include <svx/svxids.hrc>
32 #include <editeng/memberids.hrc>
33 #include <float.h> // for DBL_MIN
34 #include <swtypes.hxx>
35 #include <cmdid.h>
36 #include <unotbl.hxx>
37 #include <unostyle.hxx>
38 #include <section.hxx>
39 #include <unocrsr.hxx>
40 #include <svx/unomid.hxx>
41 #include <hints.hxx>
42 #include <swtblfmt.hxx>
43 #include <doc.hxx>
44 #include <IDocumentUndoRedo.hxx>
45 #include <shellres.hxx>
46 #include <docary.hxx>
47 #include <ndole.hxx>
48 #include <frame.hxx>
49 #include <vcl/svapp.hxx>
50 #include <fmtfsize.hxx>
51 #include <tblafmt.hxx>
52 #include <tabcol.hxx>
53 #include <cellatr.hxx>
54 #include <fmtpdsc.hxx>
55 #include <pagedesc.hxx>
56 #define _SVSTDARR_STRINGS
57 #include <svl/svstdarr.hxx>
58 #include <viewsh.hxx>
59 #include <tabfrm.hxx>
60 #include <redline.hxx>
61 #include <unoredline.hxx>
62 #include <unoprnms.hxx>
63 #include <unocrsrhelper.hxx>
64 #include <com/sun/star/text/WrapTextMode.hpp>
65 #include <com/sun/star/text/TextContentAnchorType.hpp>
66 #include <com/sun/star/text/TableColumnSeparator.hpp>
67 #include <com/sun/star/text/XTextSection.hpp>
68 #include <com/sun/star/table/ShadowFormat.hpp>
69 #include <com/sun/star/table/TableBorder.hpp>
70 #include <com/sun/star/table/TableBorderDistances.hpp>
71 #include <com/sun/star/style/PageStyleLayout.hpp>
72 #include <com/sun/star/style/BreakType.hpp>
73 #include <com/sun/star/style/GraphicLocation.hpp>
74 #include <com/sun/star/beans/PropertyAttribute.hpp>
75 #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
76 #include <com/sun/star/chart/ChartDataChangeEvent.hpp>
77 #include <com/sun/star/chart2/data/XDataSequence.hpp>
78 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
79 #include <com/sun/star/table/CellContentType.hpp>
80 #include <unotbl.hxx>
81 #include <unotextrange.hxx>
82 #include <unotextcursor.hxx>
83 #include <unoparagraph.hxx>
84 #include <svl/zforlist.hxx>     // SvNumberFormatter
85 #include <editeng/brkitem.hxx>
86 #include <editeng/shaditem.hxx>
87 #include <editeng/lrspitem.hxx>
88 #include <editeng/ulspitem.hxx>
89 #include <fmtornt.hxx>
90 #include <editeng/keepitem.hxx>
91 #include <fmtlsplt.hxx>
92 #include <swundo.hxx>
93 #include <vos/mutex.hxx>
94 #include <SwStyleNameMapper.hxx>
95 #include <frmatr.hxx>
96 #include <crsskip.hxx>
97 #include <unochart.hxx>
98 #include <sortopt.hxx>
99 #include <rtl/math.hxx>
100 #include <switerator.hxx>
101 
102 using namespace ::com::sun::star;
103 using ::rtl::OUString;
104 
105 
106 //-----------------------------------------------------------------------------
107 // from swtable.cxx
108 extern void lcl_GetTblBoxColStr( sal_uInt16 nCol, String& rNm );
109 
110 #define UNO_TABLE_COLUMN_SUM    10000
111 
lcl_SvxLineToLine(const SvxBorderLine * pLine)112 table::BorderLine lcl_SvxLineToLine(const SvxBorderLine* pLine)
113 {
114  	table::BorderLine aLine;
115 	if(pLine)
116 	{
117 		aLine.Color			 = pLine->GetColor().GetColor() ;
118 		aLine.InnerLineWidth = TWIP_TO_MM100_UNSIGNED( pLine->GetInWidth() );
119 		aLine.OuterLineWidth = TWIP_TO_MM100_UNSIGNED( pLine->GetOutWidth() );
120 		aLine.LineDistance	 = TWIP_TO_MM100_UNSIGNED( pLine->GetDistance() );
121 	}
122 	else
123 		aLine.Color			 = aLine.InnerLineWidth = aLine.OuterLineWidth = aLine.LineDistance	 = 0;
124 	return aLine;
125 }
126 
lcl_LineToSvxLine(const table::BorderLine & rLine,SvxBorderLine & rSvxLine)127 sal_Bool lcl_LineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine)
128 {
129 	rSvxLine.SetColor(   Color(rLine.Color));
130 	rSvxLine.SetInWidth( MM100_TO_TWIP( rLine.InnerLineWidth ) );
131 	rSvxLine.SetOutWidth(MM100_TO_TWIP( rLine.OuterLineWidth ) );
132 	rSvxLine.SetDistance(MM100_TO_TWIP( rLine.LineDistance	) );
133 	sal_Bool bRet = rLine.InnerLineWidth > 0 || rLine.OuterLineWidth > 0;
134 	return bRet;
135 }
136 
lcl_SetSpecialProperty(SwFrmFmt * pFmt,const SfxItemPropertySimpleEntry * pEntry,const uno::Any & aValue)137 void lcl_SetSpecialProperty(SwFrmFmt* pFmt, const SfxItemPropertySimpleEntry* pEntry, const uno::Any& aValue)
138 	throw (lang::IllegalArgumentException)
139 {
140 	//Sonderbehandlung fuer "Nicht-Items"
141     switch(pEntry->nWID)
142 	{
143 		case  FN_TABLE_HEADLINE_REPEAT:
144         case  FN_TABLE_HEADLINE_COUNT:
145 		{
146 			SwTable* pTable = SwTable::FindTable( pFmt );
147 			{
148 				UnoActionContext aAction(pFmt->GetDoc());
149                 if( pEntry->nWID == FN_TABLE_HEADLINE_REPEAT)
150                 {
151                     sal_Bool bVal = *(sal_Bool*)aValue.getValue();
152                     pFmt->GetDoc()->SetRowsToRepeat( *pTable, bVal ? 1 : 0 );
153                 }
154                 else
155                 {
156                     sal_Int32 nRepeat = 0;
157                     aValue >>= nRepeat;
158                     if( nRepeat >= 0 && nRepeat < USHRT_MAX )
159                         pFmt->GetDoc()->SetRowsToRepeat( *pTable, (sal_uInt16) nRepeat );
160                 }
161 			}
162 		}
163 		break;
164 		case  FN_TABLE_IS_RELATIVE_WIDTH:
165 		case  FN_TABLE_WIDTH:
166 		case  FN_TABLE_RELATIVE_WIDTH:
167 		{
168 			sal_Int32 nWidth = 0;
169 			SwFmtFrmSize aSz( pFmt->GetFrmSize() );
170             if(FN_TABLE_WIDTH == pEntry->nWID)
171 			{
172 				aValue >>= nWidth;
173 				aSz.SetWidthPercent(0);
174 				aSz.SetWidth ( MM100_TO_TWIP ( nWidth ) );
175 			}
176             else if(FN_TABLE_RELATIVE_WIDTH == pEntry->nWID)
177 			{
178 				sal_Int16 nSet = 0;
179 				aValue >>= nSet;
180 				if(nSet && nSet <=100)
181 					aSz.SetWidthPercent( (sal_uInt8)nSet );
182 			}
183             else if(FN_TABLE_IS_RELATIVE_WIDTH == pEntry->nWID)
184 			{
185 				sal_Bool bPercent = *(sal_Bool*)aValue.getValue();
186 				if(!bPercent)
187 					aSz.SetWidthPercent(0);
188 				else
189 				{
190 					lang::IllegalArgumentException aExcept;
191 					aExcept.Message = C2U("relative width cannot be switched on with this property");
192 					throw aExcept;
193 				}
194 			}
195 			pFmt->GetDoc()->SetAttr(aSz, *pFmt);
196 		}
197 		break;
198 		case RES_PAGEDESC:
199 		{
200 			OUString uTemp;
201 			aValue >>= uTemp;
202 			String sPageStyle = uTemp;
203 			const SwPageDesc* pDesc = 0;
204 			if(sPageStyle.Len())
205 			{
206 				SwStyleNameMapper::FillUIName(sPageStyle, sPageStyle, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True );
207                 pDesc = ::GetPageDescByName_Impl(*pFmt->GetDoc(), sPageStyle);
208             }
209             SwFmtPageDesc aDesc( pDesc );
210             pFmt->GetDoc()->SetAttr(aDesc, *pFmt);
211 		}
212 		break;
213 		default:
214 			throw lang::IllegalArgumentException();
215 	}
216 }
217 
lcl_GetSpecialProperty(SwFrmFmt * pFmt,const SfxItemPropertySimpleEntry * pEntry)218 uno::Any lcl_GetSpecialProperty(SwFrmFmt* pFmt, const SfxItemPropertySimpleEntry* pEntry )
219 {
220 	uno::Any aRet;
221     switch(pEntry->nWID)
222 	{
223 		case  FN_TABLE_HEADLINE_REPEAT:
224         case  FN_TABLE_HEADLINE_COUNT:
225 		{
226 			SwTable* pTable = SwTable::FindTable( pFmt );
227             sal_uInt16 nRepeat = pTable->GetRowsToRepeat();
228             if(pEntry->nWID == FN_TABLE_HEADLINE_REPEAT)
229             {
230                 sal_Bool bTemp = nRepeat > 0;
231                 aRet.setValue(&bTemp, ::getCppuBooleanType());
232             }
233             else
234                 aRet <<= (sal_Int32)nRepeat;
235 		}
236 		break;
237 		case  FN_TABLE_WIDTH:
238 		case  FN_TABLE_IS_RELATIVE_WIDTH:
239 		case  FN_TABLE_RELATIVE_WIDTH:
240 		{
241 			const SwFmtFrmSize& rSz = pFmt->GetFrmSize();
242             if(FN_TABLE_WIDTH == pEntry->nWID)
243 				rSz.QueryValue(aRet, MID_FRMSIZE_WIDTH|CONVERT_TWIPS);
244             else if(FN_TABLE_RELATIVE_WIDTH == pEntry->nWID)
245 				rSz.QueryValue(aRet, MID_FRMSIZE_REL_WIDTH);
246 			else
247 			{
248 				sal_Bool bTemp = 0 != rSz.GetWidthPercent();
249 				aRet.setValue(&bTemp, ::getBooleanCppuType());
250 			}
251 		}
252 		break;
253 		case RES_PAGEDESC:
254 		{
255 			const SfxItemSet& rSet = pFmt->GetAttrSet();
256 			const SfxPoolItem* pItem;
257 			String sPDesc;
258 			if(SFX_ITEM_SET == rSet.GetItemState(RES_PAGEDESC, sal_False, &pItem))
259 			{
260 				const SwPageDesc* pDsc = ((const SwFmtPageDesc*)pItem)->GetPageDesc();
261 				if(pDsc)
262 				{
263 				   sPDesc = SwStyleNameMapper::GetProgName(pDsc->GetName(), nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
264 				}
265 			}
266 			aRet <<= OUString(sPDesc);
267 		}
268 		break;
269 		case RES_ANCHOR :
270 			aRet <<= text::TextContentAnchorType_AT_PARAGRAPH;
271 		break;
272 		case FN_UNO_ANCHOR_TYPES :
273 		{
274 			uno::Sequence<text::TextContentAnchorType> aTypes(1);
275 		 	text::TextContentAnchorType* pArray = aTypes.getArray();
276 			pArray[0] = text::TextContentAnchorType_AT_PARAGRAPH;
277 			aRet <<= aTypes;
278 		}
279 		break;
280 		case FN_UNO_WRAP :
281 		{
282 			aRet <<= text::WrapTextMode_NONE;
283 		}
284 		break;
285 		case FN_PARAM_LINK_DISPLAY_NAME :
286 			aRet <<= OUString(pFmt->GetName());
287 		break;
288 		case FN_UNO_REDLINE_NODE_START:
289 		case FN_UNO_REDLINE_NODE_END:
290 		{
291 			SwTable* pTable = SwTable::FindTable( pFmt );
292 			SwNode* pTblNode = pTable->GetTableNode();
293             if(FN_UNO_REDLINE_NODE_END == pEntry->nWID)
294 				pTblNode = pTblNode->EndOfSectionNode();
295 			const SwRedlineTbl& rRedTbl = pFmt->GetDoc()->GetRedlineTbl();
296 			for(sal_uInt16 nRed = 0; nRed < rRedTbl.Count(); nRed++)
297 			{
298 				const SwRedline* pRedline = rRedTbl[nRed];
299 				const SwNode* pRedPointNode = pRedline->GetNode(sal_True);
300 				const SwNode* pRedMarkNode = pRedline->GetNode(sal_False);
301 				if(pRedPointNode == pTblNode || pRedMarkNode == pTblNode)
302 				{
303                     const SwNode* pStartOfRedline = SwNodeIndex(*pRedPointNode) <= SwNodeIndex(*pRedMarkNode) ?
304                         pRedPointNode : pRedMarkNode;
305                     sal_Bool bIsStart = pStartOfRedline == pTblNode;
306                     aRet <<= SwXRedlinePortion::CreateRedlineProperties(*pRedline, bIsStart);
307 					break;
308 				}
309 			}
310 		}
311 		break;
312 	}
313 	return aRet;
314 }
315 
316 // returns the position for the cell with the specified name
317 // (note that the indices rColumn and rRow are 0 based here)
318 // Also since the implementations of tables does not really have
319 // columns using this function is appropriate only for tables
320 // that are not complex (i.e. where IsTblComplex() returns false).
321 //
322 // returns: both indices for column and row (all >= 0) if everything was Ok.
323 //          At least one value < 0 if sth was wrong.
324 //
325 // Sample for naming scheme of cell in a single row (in groups a 26):
326 // A1..Z1, a1..z1, AA1..AZ1, Aa1..Az1, BA1..BZ1, Ba1..Bz1, ...
lcl_GetCellPosition(const String & rCellName,sal_Int32 & rColumn,sal_Int32 & rRow)327 void lcl_GetCellPosition( const String &rCellName,
328         sal_Int32 &rColumn, sal_Int32 &rRow)
329 {
330     rColumn = rRow = -1;    // default return values indicating failure
331     xub_StrLen nLen = rCellName.Len();
332     if (nLen)
333     {
334         const sal_Unicode *pBuf = rCellName.GetBuffer();
335         const sal_Unicode *pEnd = pBuf + nLen;
336         while (pBuf < pEnd && !('0' <= *pBuf && *pBuf <= '9'))
337             ++pBuf;
338         // start of number found?
339         if (pBuf < pEnd && ('0' <= *pBuf && *pBuf <= '9'))
340         {
341             String aColTxt( rCellName.GetBuffer(), static_cast< xub_StrLen >(pBuf - rCellName.GetBuffer()) );
342             String aRowTxt( pBuf, static_cast< xub_StrLen >(rCellName.GetBuffer() + nLen - pBuf) );
343             if (aColTxt.Len() && aRowTxt.Len())
344             {
345                 sal_Int32 nColIdx = 0;
346 				sal_Int32 nLength = aColTxt.Len();
347                 for (xub_StrLen i = 0;  i < nLength;  ++i)
348                 {
349 					nColIdx = 52 * nColIdx;
350 					if (i < nLength - 1)
351 						++nColIdx;
352                     sal_Unicode cChar = aColTxt.GetBuffer()[i];
353                     if ('A' <= cChar && cChar <= 'Z')
354                         nColIdx = nColIdx + (cChar - 'A');
355                     else if ('a' <= cChar && cChar <= 'z')
356                         nColIdx = nColIdx + (26 + cChar - 'a');
357                     else
358                     {
359                         nColIdx = -1;   // sth failed
360                         break;
361                     }
362                 }
363 
364                 rColumn = nColIdx;
365                 rRow    = aRowTxt.ToInt32() - 1;	// - 1 because indices ought to be 0 based
366             }
367         }
368     }
369 #if OSL_DEBUG_LEVEL > 1
370     DBG_ASSERT( rColumn != -1 && rRow != -1, "failed to get column or row index" );
371 #endif
372 }
373 
374 
375 // arguments: must be non-empty strings with valid cell names
376 //
377 // returns: -1 if first cell < second cell
378 //           0 if both cells are equal
379 //          +1 if the first cell > second cell
380 //
381 // Note: this function probably also make sense only
382 //      for cell names of non-complex tables
lcl_CompareCellsByRowFirst(const String & rCellName1,const String & rCellName2)383 int lcl_CompareCellsByRowFirst( const String &rCellName1, const String &rCellName2 )
384 {
385     sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
386     lcl_GetCellPosition( rCellName1, nCol1, nRow1 );
387     lcl_GetCellPosition( rCellName2, nCol2, nRow2 );
388 
389     if (nRow1 < nRow2 || (nRow1 == nRow2 && nCol1 < nCol2))
390         return -1;
391     else if (nCol1 == nCol2 && nRow1 == nRow2)
392         return 0;
393     else
394         return +1;
395 }
396 
397 
398 // arguments: must be non-empty strings with valid cell names
399 //
400 // returns: -1 if first cell < second cell
401 //           0 if both cells are equal
402 //          +1 if the first cell > second cell
403 //
404 // Note: this function probably also make sense only
405 //      for cell names of non-complex tables
lcl_CompareCellsByColFirst(const String & rCellName1,const String & rCellName2)406 int lcl_CompareCellsByColFirst( const String &rCellName1, const String &rCellName2 )
407 {
408     sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
409     lcl_GetCellPosition( rCellName1, nCol1, nRow1 );
410     lcl_GetCellPosition( rCellName2, nCol2, nRow2 );
411 
412     if (nCol1 < nCol2 || (nCol1 == nCol2 && nRow1 < nRow2))
413         return -1;
414     else if (nRow1 == nRow2 && nCol1 == nCol2)
415         return 0;
416     else
417         return +1;
418 }
419 
420 
421 // arguments: must be non-empty strings with valid cell names
422 //
423 // returns: -1 if first cell range < second cell range
424 //           0 if both cell ranges are identical
425 //          +1 if the first cell range > second cell range
426 //
427 // Note: this function probably also make sense only
428 //      for cell names of non-complex tables
lcl_CompareCellRanges(const String & rRange1StartCell,const String & rRange1EndCell,const String & rRange2StartCell,const String & rRange2EndCell,sal_Bool bCmpColsFirst)429 int lcl_CompareCellRanges(
430         const String &rRange1StartCell, const String &rRange1EndCell,
431         const String &rRange2StartCell, const String &rRange2EndCell,
432         sal_Bool bCmpColsFirst )
433 {
434     int (*pCompareCells)( const String &, const String & ) =
435             bCmpColsFirst ? &lcl_CompareCellsByColFirst : &lcl_CompareCellsByRowFirst;
436 
437     int nCmpResStartCells = pCompareCells( rRange1StartCell, rRange2StartCell );
438     if ((-1 == nCmpResStartCells ) ||
439          ( 0 == nCmpResStartCells &&
440           -1 == pCompareCells( rRange1EndCell, rRange2EndCell ) ))
441         return -1;
442     else if (0 == nCmpResStartCells &&
443              0 == pCompareCells( rRange1EndCell, rRange2EndCell ))
444         return 0;
445     else
446         return +1;
447 }
448 
449 
450 // returns the cell name for the cell at the specified position
451 // (note that the indices nColumn and nRow are 0 based here)
lcl_GetCellName(sal_Int32 nColumn,sal_Int32 nRow)452 String lcl_GetCellName( sal_Int32 nColumn, sal_Int32 nRow )
453 {
454 #if OSL_DEBUG_LEVEL > 1
455 	{
456 		sal_Int32 nCol, nRow2;
457 		lcl_GetCellPosition( String::CreateFromAscii("z1"), nCol, nRow2);
458 		DBG_ASSERT( nCol == 51, "lcl_GetCellPosition failed" );
459 		lcl_GetCellPosition( String::CreateFromAscii("AA1"), nCol, nRow2);
460 		DBG_ASSERT( nCol == 52, "lcl_GetCellPosition failed" );
461 		lcl_GetCellPosition( String::CreateFromAscii("AB1"), nCol, nRow2);
462 		DBG_ASSERT( nCol == 53, "lcl_GetCellPosition failed" );
463 		lcl_GetCellPosition( String::CreateFromAscii("BB1"), nCol, nRow2);
464 		DBG_ASSERT( nCol == 105, "lcl_GetCellPosition failed" );
465 	}
466 #endif
467 
468     String sCellName;
469     if (nColumn < 0 || nRow < 0)
470         return sCellName;
471 	lcl_GetTblBoxColStr( static_cast< sal_uInt16 >(nColumn), sCellName );
472     sCellName += String::CreateFromInt32( nRow + 1 );
473     return sCellName;
474 }
475 
476 /** Find the top left or bottom right corner box in given table.
477   Consider nested lines when finding the box.
478 
479   @param i_pTable the table
480 
481   @param i_bTopLeft if true, find top left box, otherwise find bottom
482          right box
483  */
484 
lcl_FindCornerTableBox(const SwTableLines & rTableLines,const bool i_bTopLeft)485 const SwTableBox* lcl_FindCornerTableBox(const SwTableLines& rTableLines, const bool i_bTopLeft)
486 {
487     bool bFirst = true;
488     const SwTableBox* pBox = 0;
489     do
490     {
491         const SwTableLines& rLines(bFirst ? rTableLines : pBox->GetTabLines());
492         bFirst = false;
493         OSL_ASSERT(rLines.Count() != 0);
494         if (rLines.Count() != 0)
495         {
496             const SwTableLine* pLine(rLines[i_bTopLeft ? 0 : rLines.Count() - 1]);
497             OSL_ASSERT(pLine);
498             const SwTableBoxes& rBoxes(pLine->GetTabBoxes());
499             OSL_ASSERT(rBoxes.Count() != 0);
500             pBox = rBoxes[i_bTopLeft ? 0 : rBoxes.Count() - 1];
501             OSL_ASSERT(pBox);
502         }
503         else
504         {
505             pBox = 0;
506         }
507     } while (pBox && !pBox->GetSttNd());
508     return pBox;
509 }
510 
511 // start cell should be in the upper-left corner of the range and
512 // end cell in the lower-right.
513 // I.e. from the four possible representation
514 //      A1:C5, C5:A1, A5:C1, C1:A5
515 // only A1:C5 is the one to use
lcl_NormalizeRange(String & rCell1,String & rCell2)516 void lcl_NormalizeRange(
517     String &rCell1,     // will hold the upper-left cell of the range upon return
518     String &rCell2 )    // will hold the lower-right cell of the range upon return
519 {
520     sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
521     lcl_GetCellPosition( rCell1, nCol1, nRow1 );
522     lcl_GetCellPosition( rCell2, nCol2, nRow2 );
523     if (nCol2 < nCol1 || nRow2 < nRow1)
524     {
525         rCell1  = lcl_GetCellName( Min(nCol1, nCol2), Min(nRow1, nRow2) );
526         rCell2  = lcl_GetCellName( Max(nCol1, nCol2), Max(nRow1, nRow2) );
527     }
528 
529 }
530 
Normalize()531 void SwRangeDescriptor::Normalize()
532 {
533     if (nTop > nBottom)
534     {
535         sal_Int32 nTmp = nTop;
536         nTop = nBottom;
537         nBottom = nTmp;
538     }
539     if (nLeft > nRight)
540     {
541         sal_Int32 nTmp = nLeft;
542         nLeft = nRight;
543         nRight = nTmp;
544     }
545 }
546 
547 
lcl_CreateXCell(SwFrmFmt * pFmt,sal_Int32 nColumn,sal_Int32 nRow)548 SwXCell* lcl_CreateXCell(SwFrmFmt* pFmt, sal_Int32 nColumn, sal_Int32 nRow)
549 {
550 	SwXCell* pXCell = 0;
551 	String sCellName = lcl_GetCellName(nColumn, nRow);
552 	SwTable* pTable = SwTable::FindTable( pFmt );
553     SwTableBox* pBox = (SwTableBox*)pTable->GetTblBox( sCellName );
554 	if(pBox)
555 	{
556 		pXCell = SwXCell::CreateXCell(pFmt, pBox, pTable);
557 	}
558 	return pXCell;
559 }
560 
lcl_InspectLines(SwTableLines & rLines,SvStrings & rAllNames)561 void lcl_InspectLines(SwTableLines& rLines, SvStrings& rAllNames)
562 {
563 	for( sal_uInt16 i = 0; i < rLines.Count(); i++ )
564 	{
565 		SwTableLine* pLine = rLines[i];
566 		SwTableBoxes& rBoxes = pLine->GetTabBoxes();
567 		for(sal_uInt16 j = 0; j < rBoxes.Count(); j++)
568 		{
569 			SwTableBox* pBox = rBoxes[j];
570             if(pBox->GetName().Len() && pBox->getRowSpan() > 0 )
571 				rAllNames.Insert(new String(pBox->GetName()), rAllNames.Count());
572 			SwTableLines& rBoxLines = pBox->GetTabLines();
573 			if(rBoxLines.Count())
574 			{
575 				lcl_InspectLines(rBoxLines, rAllNames);
576 			}
577 		}
578 	}
579 }
580 
lcl_FormatTable(SwFrmFmt * pTblFmt)581 void lcl_FormatTable(SwFrmFmt* pTblFmt)
582 {
583 	SwIterator<SwFrm,SwFmt> aIter( *pTblFmt );
584 	for( SwFrm* pFrm = aIter.First(); pFrm; pFrm = aIter.Next() )
585     {
586         // mba: no TYPEINFO for SwTabFrm
587 		if( pFrm->IsTabFrm() )
588 		{
589 			if(pFrm->IsValid())
590 				pFrm->InvalidatePos();
591 			((SwTabFrm*)pFrm)->SetONECalcLowers();
592 			((SwTabFrm*)pFrm)->Calc();
593 		}
594 	}
595 }
596 
lcl_CrsrSelect(SwPaM * pCrsr,sal_Bool bExpand)597 void lcl_CrsrSelect(SwPaM* pCrsr, sal_Bool bExpand)
598 {
599 	if(bExpand)
600 	{
601 		if(!pCrsr->HasMark())
602 			pCrsr->SetMark();
603 	}
604 	else if(pCrsr->HasMark())
605 		pCrsr->DeleteMark();
606 
607 }
608 
lcl_GetTblSeparators(uno::Any & rRet,SwTable * pTable,SwTableBox * pBox,sal_Bool bRow)609 void lcl_GetTblSeparators(uno::Any& rRet, SwTable* pTable, SwTableBox* pBox, sal_Bool bRow)
610 {
611 	SwTabCols aCols;
612 	aCols.SetLeftMin ( 0 );
613 	aCols.SetLeft    ( 0 );
614 	aCols.SetRight   ( UNO_TABLE_COLUMN_SUM );
615 	aCols.SetRightMax( UNO_TABLE_COLUMN_SUM );
616 
617 	pTable->GetTabCols( aCols, pBox, sal_False, bRow );
618 
619 	sal_uInt16 nSepCount = aCols.Count();
620 	uno::Sequence< text::TableColumnSeparator> aColSeq(nSepCount);
621  	text::TableColumnSeparator* pArray = aColSeq.getArray();
622 	sal_Bool bError = sal_False;
623 	for(sal_uInt16 i = 0; i < nSepCount; i++)
624 	{
625         pArray[i].Position = static_cast< sal_Int16 >(aCols[i]);
626 		pArray[i].IsVisible = !aCols.IsHidden(i);
627 		if(!bRow && !pArray[i].IsVisible)
628 		{
629 			bError = sal_True;
630 			break;
631 		}
632 	}
633 	if(!bError)
634 		rRet.setValue(&aColSeq, ::getCppuType((uno::Sequence< text::TableColumnSeparator>*)0));
635 
636 }
637 
lcl_SetTblSeparators(const uno::Any & rVal,SwTable * pTable,SwTableBox * pBox,sal_Bool bRow,SwDoc * pDoc)638 void lcl_SetTblSeparators(const uno::Any& rVal, SwTable* pTable, SwTableBox* pBox, sal_Bool bRow, SwDoc* pDoc)
639 {
640 	SwTabCols aOldCols;
641 
642 	aOldCols.SetLeftMin ( 0 );
643 	aOldCols.SetLeft    ( 0 );
644 	aOldCols.SetRight   ( UNO_TABLE_COLUMN_SUM );
645 	aOldCols.SetRightMax( UNO_TABLE_COLUMN_SUM );
646 
647 	pTable->GetTabCols( aOldCols, pBox, sal_False, bRow );
648 	sal_uInt16 nOldCount = aOldCols.Count();
649     //there's no use in setting tab cols if there's only one column
650     if( !nOldCount )
651         return;
652 
653 	const uno::Sequence< text::TableColumnSeparator>* pSepSeq =
654 				(uno::Sequence< text::TableColumnSeparator>*) rVal.getValue();
655 	if(pSepSeq && pSepSeq->getLength() == nOldCount)
656 	{
657 		SwTabCols aCols(aOldCols);
658 		sal_Bool bError = sal_False;
659 		const text::TableColumnSeparator* pArray = pSepSeq->getConstArray();
660 		sal_Int32 nLastValue = 0;
661 		//sal_Int32 nTblWidth = aCols.GetRight() - aCols.GetLeft();
662 		for(sal_uInt16 i = 0; i < nOldCount; i++)
663 		{
664 			aCols[i] = pArray[i].Position;
665 			if(pArray[i].IsVisible == aCols.IsHidden(i) ||
666 				(!bRow && aCols.IsHidden(i)) ||
667 				long(aCols[i] - long(nLastValue)) < 0 ||
668 				UNO_TABLE_COLUMN_SUM < aCols[i] )
669 			{
670 				bError = sal_True;
671 				break;
672 			}
673 			nLastValue = aCols[i];
674 		}
675 		if(!bError)
676 		{
677 			pDoc->SetTabCols(*pTable, aCols, aOldCols, pBox, bRow );
678 		}
679 	}
680 }
681 
lcl_getString(SwXCell & rCell)682 inline rtl::OUString lcl_getString( SwXCell &rCell )
683 {
684     // getString is a member function of the base class...
685     return rCell.getString();
686 }
687 /*  non UNO function call to set string in SwXCell */
lcl_setString(SwXCell & rCell,const rtl::OUString & rTxt,sal_Bool bKeepNumberFmt)688 void lcl_setString( SwXCell &rCell, const rtl::OUString &rTxt,
689         sal_Bool bKeepNumberFmt )
690 {
691     if(rCell.IsValid())
692 	{
693         SwFrmFmt* pBoxFmt = rCell.pBox->ClaimFrmFmt();
694 		pBoxFmt->LockModify();
695         pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMULA );
696         pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
697         if (!bKeepNumberFmt)
698             pBoxFmt->SetFmtAttr( SwTblBoxNumFormat(NUMBERFORMAT_TEXT) );
699 		pBoxFmt->UnlockModify();
700 	}
701     rCell.SwXText::setString(rTxt);
702 }
703 /* non UNO function call to get value from SwXCell */
lcl_getValue(SwXCell & rCell)704 double lcl_getValue( SwXCell &rCell )
705 {
706     double fRet;
707     if(rCell.IsValid() && rCell.getString().getLength()!=0)
708         fRet = rCell.pBox->GetFrmFmt()->GetTblBoxValue().GetValue();
709     else
710         ::rtl::math::setNan( &fRet );
711     return fRet;
712 }
713 /* non UNO function call to set value in SwXCell */
lcl_setValue(SwXCell & rCell,double nVal)714 void lcl_setValue( SwXCell &rCell, double nVal )
715 {
716     if(rCell.IsValid())
717 	{
718 		// Der Text mu? zunaechst (vielleicht) geloescht werden
719         sal_uLong nNdPos = rCell.pBox->IsValidNumTxtNd( sal_True );
720 		if(ULONG_MAX != nNdPos)
721             lcl_setString( rCell, OUString(), sal_True );   // sal_True == keep number format
722         SwDoc* pDoc = rCell.GetDoc();
723 		UnoActionContext aAction(pDoc);
724         SwFrmFmt* pBoxFmt = rCell.pBox->ClaimFrmFmt();
725 		SfxItemSet aSet(pDoc->GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE);
726 		const SfxPoolItem* pItem;
727 
728 		//!! do we need to set a new number format? Yes, if
729 		// - there is no current number format
730 		// - the current number format is not a number format according to the number formatter, but rather a text format
731 		// - the current number format is not even a valid number formatter number format, but rather Writer's own 'special' text number format
732 		if(SFX_ITEM_SET != pBoxFmt->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, sal_True, &pItem)
733 			||  pDoc->GetNumberFormatter()->IsTextFormat(((SwTblBoxNumFormat*)pItem)->GetValue())
734 			||	((SwTblBoxNumFormat*)pItem)->GetValue() == NUMBERFORMAT_TEXT)
735 		{
736 			aSet.Put(SwTblBoxNumFormat(0));
737 		}
738 
739         SwTblBoxValue aVal(nVal);
740 		aSet.Put(aVal);
741         pDoc->SetTblBoxFormulaAttrs( *rCell.pBox, aSet );
742 		//Tabelle aktualisieren
743         SwTableFmlUpdate aTblUpdate( SwTable::FindTable( rCell.GetFrmFmt() ));
744 		pDoc->UpdateTblFlds( &aTblUpdate );
745 	}
746 }
747 /******************************************************************
748  * SwXCell
749  ******************************************************************/
750 TYPEINIT1(SwXCell, SwClient);
751 
SwXCell(SwFrmFmt * pTblFmt,SwTableBox * pBx,sal_uInt16 nPos)752 SwXCell::SwXCell(SwFrmFmt* pTblFmt, SwTableBox* pBx, sal_uInt16 nPos ) :
753 	SwXText(pTblFmt->GetDoc(), CURSOR_TBLTEXT),
754 	SwClient(pTblFmt),
755     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_CELL)),
756 	pBox(pBx),
757 	pStartNode(0),
758     nFndPos(nPos)
759 {
760 }
761 
SwXCell(SwFrmFmt * pTblFmt,const SwStartNode & rStartNode)762 SwXCell::SwXCell(SwFrmFmt* pTblFmt, const SwStartNode& rStartNode) :
763 	SwXText(pTblFmt->GetDoc(), CURSOR_TBLTEXT),
764 	SwClient(pTblFmt),
765     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_CELL)),
766 	pBox(0),
767 	pStartNode(&rStartNode),
768     nFndPos(USHRT_MAX)
769 {
770 }
771 
~SwXCell()772 SwXCell::~SwXCell()
773 {
774 
775 }
776 
getUnoTunnelId()777 const uno::Sequence< sal_Int8 > & SwXCell::getUnoTunnelId()
778 {
779     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
780 	return aSeq;
781 }
782 
getSomething(const uno::Sequence<sal_Int8> & rId)783 sal_Int64 SAL_CALL SwXCell::getSomething( const uno::Sequence< sal_Int8 >& rId )
784 	throw(uno::RuntimeException)
785 {
786     if( rId.getLength() == 16
787         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
788 										rId.getConstArray(), 16 ) )
789     {
790 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
791     }
792     else
793         return SwXText::getSomething(rId);
794 }
795 
getTypes()796 uno::Sequence< uno::Type > SAL_CALL SwXCell::getTypes(  ) throw(uno::RuntimeException)
797 {
798     static uno::Sequence< uno::Type > aRetTypes;
799     if(!aRetTypes.getLength())
800     {
801         aRetTypes = SwXCellBaseClass::getTypes();
802         uno::Sequence< uno::Type > aTextTypes = SwXText::getTypes();
803 
804         long nIndex = aRetTypes.getLength();
805         aRetTypes.realloc(
806             aRetTypes.getLength() +
807             aTextTypes.getLength());
808 
809         uno::Type* pRetTypes = aRetTypes.getArray();
810 
811         const uno::Type* pTextTypes = aTextTypes.getConstArray();
812         for(long nPos = 0; nPos <aTextTypes.getLength(); nPos++)
813             pRetTypes[nIndex++] = pTextTypes[nPos];
814     }
815     return aRetTypes;
816 }
817 
getImplementationId()818 uno::Sequence< sal_Int8 > SAL_CALL SwXCell::getImplementationId(  ) throw(uno::RuntimeException)
819 {
820     vos::OGuard aGuard(Application::GetSolarMutex());
821     static uno::Sequence< sal_Int8 > aId( 16 );
822     static sal_Bool bInit = sal_False;
823     if(!bInit)
824     {
825         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
826         bInit = sal_True;
827     }
828     return aId;
829 }
830 
acquire()831 void SAL_CALL SwXCell::acquire(  ) throw()
832 {
833 	SwXCellBaseClass::acquire();
834 }
835 
release()836 void SAL_CALL SwXCell::release(  ) throw()
837 {
838 	SwXCellBaseClass::release();
839 }
840 
queryInterface(const uno::Type & aType)841 uno::Any SAL_CALL SwXCell::queryInterface( const uno::Type& aType )
842 	throw (uno::RuntimeException)
843 {
844 	uno::Any aRet = SwXCellBaseClass::queryInterface(aType);
845 	if(aRet.getValueType() == ::getCppuVoidType())
846 		aRet = SwXText::queryInterface(aType);
847 	return aRet;
848 }
849 
GetStartNode() const850 const SwStartNode *SwXCell::GetStartNode() const
851 {
852 	const SwStartNode *pSttNd = 0;
853 
854 	if( pStartNode || ((SwXCell *)this)->IsValid() )
855 		pSttNd = pStartNode ? pStartNode : pBox->GetSttNd();
856 
857 	return pSttNd;
858 }
859 
860 uno::Reference< text::XTextCursor >
CreateCursor()861 SwXCell::CreateCursor() throw (uno::RuntimeException)
862 {
863 	return createTextCursor();
864 }
865 
IsValid() const866 bool SwXCell::IsValid() const
867 {
868     // FIXME: this is now a const method, to make SwXText::IsValid invisible
869     // but the const_cast here are still ridiculous. TODO: find a better way.
870 	SwFrmFmt* pTblFmt = pBox ? GetFrmFmt() : 0;
871 	if(!pTblFmt)
872     {
873         const_cast<SwXCell*>(this)->pBox = 0;
874     }
875 	else
876 	{
877 		SwTable* pTable = SwTable::FindTable( pTblFmt );
878         SwTableBox const*const pFoundBox =
879             const_cast<SwXCell*>(this)->FindBox(pTable, pBox);
880         if (!pFoundBox)
881         {
882             const_cast<SwXCell*>(this)->pBox = 0;
883         }
884 	}
885 	return 0 != pBox;
886 }
887 
getFormula(void)888 OUString SwXCell::getFormula(void) throw( uno::RuntimeException )
889 {
890 	vos::OGuard aGuard(Application::GetSolarMutex());
891 	OUString sRet;
892 	if(IsValid())
893 	{
894 		SwTblBoxFormula aFormula( pBox->GetFrmFmt()->GetTblBoxFormula() );
895 		SwTable* pTable = SwTable::FindTable( GetFrmFmt() );
896 		aFormula.PtrToBoxNm( pTable );
897 		sRet = aFormula.GetFormula();
898 	}
899 	return sRet;
900 }
901 
setFormula(const OUString & rFormula)902 void SwXCell::setFormula(const OUString& rFormula) throw( uno::RuntimeException )
903 {
904 	vos::OGuard aGuard(Application::GetSolarMutex());
905 	if(IsValid())
906 	{
907 		// Der Text mu? zunaechst (vielleicht) geloescht werden
908 		sal_uInt32 nNdPos = pBox->IsValidNumTxtNd( sal_True );
909 		if(USHRT_MAX == nNdPos)
910             lcl_setString( *this, OUString(), sal_True );
911 		String sFml(rFormula);
912 		if( sFml.EraseLeadingChars().Len() && '=' == sFml.GetChar( 0 ) )
913 					sFml.Erase( 0, 1 );
914 		SwTblBoxFormula aFml( sFml );
915 		SwDoc* pMyDoc = GetDoc();
916 		UnoActionContext aAction(pMyDoc);
917 		SfxItemSet aSet(pMyDoc->GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_FORMULA);
918 		const SfxPoolItem* pItem;
919 		SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
920 		if(SFX_ITEM_SET != pBoxFmt->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, sal_True, &pItem)
921 			||  pMyDoc->GetNumberFormatter()->IsTextFormat(((SwTblBoxNumFormat*)pItem)->GetValue()))
922 		{
923 			aSet.Put(SwTblBoxNumFormat(0));
924 		}
925 		aSet.Put(aFml);
926 		GetDoc()->SetTblBoxFormulaAttrs( *pBox, aSet );
927 		//Tabelle aktualisieren
928 		SwTableFmlUpdate aTblUpdate( SwTable::FindTable( GetFrmFmt() ));
929 		pMyDoc->UpdateTblFlds( &aTblUpdate );
930 	}
931 }
932 
getValue(void)933 double SwXCell::getValue(void) throw( uno::RuntimeException )
934 {
935 	vos::OGuard aGuard(Application::GetSolarMutex());
936 
937     double const fRet = lcl_getValue( *this );
938     // #i112652# a table cell may contain NaN as a value, do not filter that
939     return fRet;
940 }
941 
setValue(double rValue)942 void SwXCell::setValue(double rValue) throw( uno::RuntimeException )
943 {
944 	vos::OGuard aGuard(Application::GetSolarMutex());
945     lcl_setValue( *this, rValue );
946 }
947 
getType(void)948 table::CellContentType SwXCell::getType(void) throw( uno::RuntimeException )
949 {
950 	vos::OGuard aGuard(Application::GetSolarMutex());
951 
952 	table::CellContentType nRes = table::CellContentType_EMPTY;
953 	sal_uInt32 nNdPos = pBox->IsFormulaOrValueBox();
954 	switch (nNdPos)
955 	{
956 		case 0 :					nRes = table::CellContentType_TEXT; break;
957 		case USHRT_MAX :			nRes = table::CellContentType_EMPTY; break;
958 		case RES_BOXATR_VALUE :		nRes = table::CellContentType_VALUE; break;
959 		case RES_BOXATR_FORMULA :	nRes = table::CellContentType_FORMULA; break;
960 		default :
961 			DBG_ERROR( "unexpected case" );
962 	}
963 	return  nRes;
964 }
965 
setString(const OUString & aString)966 void SwXCell::setString(const OUString& aString) throw( uno::RuntimeException )
967 {
968 	vos::OGuard aGuard(Application::GetSolarMutex());
969     lcl_setString( *this, aString );
970 }
971 
972 
getError(void)973 sal_Int32 SwXCell::getError(void) throw( uno::RuntimeException )
974 {
975 	vos::OGuard aGuard(Application::GetSolarMutex());
976 	OUString sContent = getString();
977 	return sContent.equals(ViewShell::GetShellRes()->aCalc_Error);
978 }
979 
createTextCursor(void)980 uno::Reference< text::XTextCursor >  SwXCell::createTextCursor(void) throw( uno::RuntimeException )
981 {
982 	vos::OGuard aGuard(Application::GetSolarMutex());
983 	uno::Reference< text::XTextCursor >  	aRef;
984 	if(pStartNode || IsValid())
985 	{
986 		const SwStartNode* pSttNd = pStartNode ? pStartNode : pBox->GetSttNd();
987 		SwPosition aPos(*pSttNd);
988         SwXTextCursor *const pXCursor =
989             new SwXTextCursor(*GetDoc(), this, CURSOR_TBLTEXT, aPos);
990         SwUnoCrsr *const pUnoCrsr = pXCursor->GetCursor();
991 		pUnoCrsr->Move(fnMoveForward, fnGoNode);
992         aRef =  static_cast<text::XWordCursor*>(pXCursor);
993 //		// no Cursor in protected sections
994 //		SwCrsrSaveState aSave( *pUnoCrsr );
995 //		if(pUnoCrsr->IsInProtectTable( sal_True ) ||
996 //          pUnoCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE | nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ))
997 //			throw( uno::RuntimeException() );
998 	}
999 	else
1000 		throw uno::RuntimeException();
1001 	return aRef;
1002 }
1003 
createTextCursorByRange(const uno::Reference<text::XTextRange> & xTextPosition)1004 uno::Reference< text::XTextCursor >  SwXCell::createTextCursorByRange(const uno::Reference< text::XTextRange > & xTextPosition)
1005 														throw( uno::RuntimeException )
1006 {
1007 	vos::OGuard aGuard(Application::GetSolarMutex());
1008 	uno::Reference< text::XTextCursor >  aRef;
1009 	SwUnoInternalPaM aPam(*GetDoc());
1010     if ((pStartNode || IsValid())
1011         && ::sw::XTextRangeToSwPaM(aPam, xTextPosition))
1012 	{
1013 		const SwStartNode* pSttNd = pStartNode ? pStartNode : pBox->GetSttNd();
1014 		//skip sections
1015         SwStartNode* p1 = aPam.GetNode()->StartOfSectionNode();
1016 		while(p1->IsSectionNode())
1017             p1 = p1->StartOfSectionNode();
1018 
1019 		if( p1 == pSttNd )
1020         {
1021             aRef = static_cast<text::XWordCursor*>(
1022                     new SwXTextCursor(*GetDoc(), this, CURSOR_TBLTEXT,
1023                         *aPam.GetPoint(), aPam.GetMark()));
1024         }
1025 	}
1026 	else
1027 		throw uno::RuntimeException();
1028 	return aRef;
1029 }
1030 
getPropertySetInfo(void)1031 uno::Reference< beans::XPropertySetInfo >  SwXCell::getPropertySetInfo(void) throw( uno::RuntimeException )
1032 {
1033     static uno::Reference< beans::XPropertySetInfo >  xRef = m_pPropSet->getPropertySetInfo();
1034 	return xRef;
1035 }
1036 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)1037 void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
1038     throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
1039 {
1040 	vos::OGuard aGuard(Application::GetSolarMutex());
1041 	if(IsValid())
1042 	{
1043         const SfxItemPropertySimpleEntry* pEntry =
1044             m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1045         if( !pEntry )
1046         {
1047             beans::UnknownPropertyException aEx;
1048             aEx.Message = rPropertyName;
1049             throw( aEx );
1050         }
1051         if( pEntry->nWID == FN_UNO_CELL_ROW_SPAN )
1052         {
1053             sal_Int32 nRowSpan = 0;
1054             if( aValue >>= nRowSpan )
1055                 pBox->setRowSpan( nRowSpan );
1056         }
1057         else
1058         {
1059             SwFrmFmt* pBoxFmt = pBox->ClaimFrmFmt();
1060             SwAttrSet aSet(pBoxFmt->GetAttrSet());
1061             m_pPropSet->setPropertyValue(rPropertyName, aValue, aSet);
1062             pBoxFmt->GetDoc()->SetAttr(aSet, *pBoxFmt);
1063         }
1064 	}
1065 }
1066 
getPropertyValue(const OUString & rPropertyName)1067 uno::Any SwXCell::getPropertyValue(const OUString& rPropertyName)
1068 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1069 {
1070 	vos::OGuard aGuard(Application::GetSolarMutex());
1071 	uno::Any aRet;
1072 	if(IsValid())
1073 	{
1074         const SfxItemPropertySimpleEntry* pEntry =
1075                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1076         if( !pEntry )
1077         {
1078             beans::UnknownPropertyException aEx;
1079             aEx.Message = rPropertyName;
1080             throw( aEx );
1081         }
1082         switch( pEntry->nWID )
1083         {
1084             case FN_UNO_CELL_ROW_SPAN:
1085                 aRet <<= pBox->getRowSpan();
1086             break;
1087             case FN_UNO_TEXT_SECTION:
1088             {
1089                 SwFrmFmt* pTblFmt = GetFrmFmt();
1090                 SwTable* pTable = SwTable::FindTable( pTblFmt );
1091                 SwTableNode* pTblNode = pTable->GetTableNode();
1092                 SwSectionNode* pSectionNode =  pTblNode->FindSectionNode();
1093                 if(pSectionNode)
1094                 {
1095                     const SwSection& rSect = pSectionNode->GetSection();
1096                     uno::Reference< text::XTextSection >  xSect =
1097                                     SwXTextSections::GetObject( *rSect.GetFmt() );
1098                     aRet <<= xSect;
1099                 }
1100             }
1101             break;
1102             case FN_UNO_CELL_NAME:
1103                 aRet <<= OUString ( pBox->GetName() );
1104             break;
1105             case FN_UNO_REDLINE_NODE_START:
1106             case FN_UNO_REDLINE_NODE_END:
1107             {
1108                 //redline can only be returned if it's a living object
1109                 aRet = SwXText::getPropertyValue(rPropertyName);
1110             }
1111             break;
1112             default:
1113             {
1114                 const SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
1115                 const SwAttrSet& rSet = pBoxFmt->GetAttrSet();
1116                 m_pPropSet->getPropertyValue(rPropertyName, rSet, aRet);
1117             }
1118         }
1119 	}
1120 	return aRet;
1121 }
1122 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1123 void SwXCell::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1124 {
1125 	DBG_WARNING("not implemented");
1126 }
1127 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1128 void SwXCell::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1129 {
1130 	DBG_WARNING("not implemented");
1131 }
1132 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1133 void SwXCell::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1134 {
1135 	DBG_WARNING("not implemented");
1136 }
1137 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1138 void SwXCell::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1139 {
1140 	DBG_WARNING("not implemented");
1141 }
1142 
createEnumeration(void)1143 uno::Reference< container::XEnumeration >  SwXCell::createEnumeration(void) throw( uno::RuntimeException )
1144 {
1145 	vos::OGuard aGuard(Application::GetSolarMutex());
1146 	uno::Reference< container::XEnumeration >  aRef;
1147 	if(IsValid())
1148 	{
1149 		const SwStartNode* pSttNd = pBox->GetSttNd();
1150 		SwPosition aPos(*pSttNd);
1151         ::std::auto_ptr<SwUnoCrsr> pUnoCursor(
1152             GetDoc()->CreateUnoCrsr(aPos, sal_False));
1153         pUnoCursor->Move(fnMoveForward, fnGoNode);
1154 
1155         // remember table and start node for later travelling
1156         // (used in export of tables in tables)
1157         SwTable const*const pTable( & pSttNd->FindTableNode()->GetTable() );
1158         SwXParagraphEnumeration *const pEnum =
1159             new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_TBLTEXT,
1160                     pSttNd, pTable);
1161 
1162 		aRef = pEnum;
1163 //		// no Cursor in protected sections
1164 //		SwCrsrSaveState aSave( *pUnoCrsr );
1165 //		if(pUnoCrsr->IsInProtectTable( sal_True ) ||
1166 //          pUnoCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE | nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ))
1167 //			throw( uno::RuntimeException() );
1168 	}
1169 	return aRef;
1170 }
1171 
getElementType(void)1172 uno::Type SAL_CALL SwXCell::getElementType(void) throw( uno::RuntimeException )
1173 {
1174 	return ::getCppuType((const uno::Reference<text::XTextRange>*)0);
1175 
1176 }
1177 
hasElements(void)1178 sal_Bool SwXCell::hasElements(void) throw( uno::RuntimeException )
1179 {
1180 	return sal_True;
1181 }
1182 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1183 void SwXCell::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
1184 {
1185 	ClientModify(this, pOld, pNew);
1186 }
1187 
CreateXCell(SwFrmFmt * pTblFmt,SwTableBox * pBox,SwTable * pTable)1188 SwXCell* SwXCell::CreateXCell(SwFrmFmt* pTblFmt, SwTableBox* pBox, SwTable *pTable )
1189 {
1190 	SwXCell* pRet = 0;
1191 	if(pTblFmt && pBox)
1192 	{
1193 		if( !pTable )
1194 			pTable = SwTable::FindTable( pTblFmt );
1195 		sal_uInt16 nPos = USHRT_MAX;
1196 		SwTableBox* pFoundBox =
1197             pTable->GetTabSortBoxes().Seek_Entry( pBox, &nPos ) ? pBox : NULL;
1198 
1199 		//wenn es die Box gibt, dann wird auch eine Zelle zurueckgegeben
1200 		if(pFoundBox)
1201 		{
1202 			SwIterator<SwXCell,SwFmt> aIter( *pTblFmt );
1203 			SwXCell* pXCell = aIter.First();
1204 			while( pXCell )
1205 			{
1206 				// gibt es eine passende Zelle bereits?
1207 				if(pXCell->GetTblBox() == pBox)
1208 					break;
1209 				pXCell = aIter.Next();
1210 			}
1211 			//sonst anlegen
1212 			if(!pXCell)
1213                 pXCell = new SwXCell(pTblFmt, pBox, nPos );
1214 			pRet = pXCell;
1215 		}
1216 	}
1217 	return pRet;
1218 }
1219 /* does box exist in given table? */
FindBox(SwTable * pTable,SwTableBox * pBox2)1220 SwTableBox* SwXCell::FindBox(SwTable* pTable, SwTableBox* pBox2)
1221 {
1222     // check if nFndPos happens to point to the right table box
1223 	if( nFndPos < pTable->GetTabSortBoxes().Count() &&
1224 		pBox2 == pTable->GetTabSortBoxes()[ nFndPos ] )
1225 		return pBox2;
1226 
1227     // if not, seek the entry (and return, if successful)
1228 	if( pTable->GetTabSortBoxes().Seek_Entry( pBox2, &nFndPos ))
1229 		return pBox2;
1230 
1231     // box not found: reset nFndPos pointer
1232 	nFndPos = USHRT_MAX;
1233 	return 0;
1234 }
1235 
getImplementationName(void)1236 OUString SwXCell::getImplementationName(void) throw( uno::RuntimeException )
1237 {
1238 	return C2U("SwXCell");
1239 }
1240 
supportsService(const OUString & rServiceName)1241 sal_Bool SwXCell::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1242 {
1243 	String sServiceName(rServiceName);
1244     return sServiceName.EqualsAscii("com.sun.star.text.CellProperties");
1245 }
1246 
getSupportedServiceNames(void)1247 uno::Sequence< OUString > SwXCell::getSupportedServiceNames(void) throw( uno::RuntimeException )
1248 {
1249     uno::Sequence< OUString > aRet(1);
1250 	OUString* pArray = aRet.getArray();
1251     pArray[0] = C2U("com.sun.star.text.CellProperties");
1252 	return aRet;
1253 }
1254 
1255 /******************************************************************
1256  * SwXTextTableRow
1257  ******************************************************************/
1258 
getImplementationName(void)1259 OUString SwXTextTableRow::getImplementationName(void) throw( uno::RuntimeException )
1260 {
1261 	return C2U("SwXTextTableRow");
1262 }
1263 
supportsService(const OUString & rServiceName)1264 sal_Bool SwXTextTableRow::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1265 {
1266 	return C2U("com.sun.star.text.TextTableRow") == rServiceName;
1267 }
1268 
getSupportedServiceNames(void)1269 uno::Sequence< OUString > SwXTextTableRow::getSupportedServiceNames(void) throw( uno::RuntimeException )
1270 {
1271 	uno::Sequence< OUString > aRet(1);
1272 	OUString* pArray = aRet.getArray();
1273 	pArray[0] = C2U("com.sun.star.text.TextTableRow");
1274 	return aRet;
1275 }
1276 TYPEINIT1(SwXTextTableRow, SwClient);
1277 
SwXTextTableRow(SwFrmFmt * pFmt,SwTableLine * pLn)1278 SwXTextTableRow::SwXTextTableRow(SwFrmFmt* pFmt, SwTableLine* pLn) :
1279 	SwClient(pFmt),
1280     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_ROW)),
1281 	pLine(pLn)
1282 {
1283 
1284 }
1285 
~SwXTextTableRow()1286 SwXTextTableRow::~SwXTextTableRow()
1287 {
1288 
1289 }
1290 
getPropertySetInfo(void)1291 uno::Reference< beans::XPropertySetInfo >  SwXTextTableRow::getPropertySetInfo(void) throw( uno::RuntimeException )
1292 {
1293     static uno::Reference< beans::XPropertySetInfo >  xRef = m_pPropSet->getPropertySetInfo();
1294 	return xRef;
1295 }
1296 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)1297 void SwXTextTableRow::setPropertyValue(const OUString& rPropertyName,
1298 	const uno::Any& aValue)
1299 	throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
1300 {
1301 	vos::OGuard aGuard(Application::GetSolarMutex());
1302 	SwFrmFmt* pFmt = GetFrmFmt();
1303 	if(pFmt)
1304 	{
1305 		SwTable* pTable = SwTable::FindTable( pFmt );
1306 		SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, pLine);
1307 		if(pLn)
1308 		{
1309             const SfxItemPropertySimpleEntry* pEntry =
1310                 m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1311 			SwDoc* pDoc = pFmt->GetDoc();
1312             if (!pEntry)
1313 				throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1314             if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1315                 throw beans::PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1316 
1317             switch(pEntry->nWID)
1318 			{
1319 				case FN_UNO_ROW_HEIGHT:
1320 				case FN_UNO_ROW_AUTO_HEIGHT:
1321 				{
1322 					SwFmtFrmSize aFrmSize(pLn->GetFrmFmt()->GetFrmSize());
1323                     if(FN_UNO_ROW_AUTO_HEIGHT== pEntry->nWID)
1324 					{
1325 						sal_Bool bSet = *(sal_Bool*)aValue.getValue();
1326                         aFrmSize.SetHeightSizeType(bSet ? ATT_VAR_SIZE : ATT_FIX_SIZE);
1327 					}
1328 					else
1329 					{
1330 						sal_Int32 nHeight = 0;
1331 						aValue >>= nHeight;
1332 					 	Size aSz(aFrmSize.GetSize());
1333 						aSz.Height() = MM100_TO_TWIP(nHeight);
1334 						aFrmSize.SetSize(aSz);
1335 					}
1336 					pDoc->SetAttr(aFrmSize, *pLn->ClaimFrmFmt());
1337 				}
1338 				break;
1339 				case FN_UNO_TABLE_COLUMN_SEPARATORS:
1340                 {
1341                     UnoActionContext aContext(pDoc);
1342                     SwTable* pTable2 = SwTable::FindTable( pFmt );
1343                     lcl_SetTblSeparators(aValue, pTable2, pLine->GetTabBoxes()[0], sal_True, pDoc);
1344 				}
1345 				break;
1346 				default:
1347 				{
1348 					SwFrmFmt* pLnFmt = pLn->ClaimFrmFmt();
1349 					SwAttrSet aSet(pLnFmt->GetAttrSet());
1350                     m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
1351 					pDoc->SetAttr(aSet, *pLnFmt);
1352 				}
1353 			}
1354 		}
1355 	}
1356 }
1357 
getPropertyValue(const OUString & rPropertyName)1358 uno::Any SwXTextTableRow::getPropertyValue(const OUString& rPropertyName) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1359 {
1360 	vos::OGuard aGuard(Application::GetSolarMutex());
1361 	uno::Any aRet;
1362 	SwFrmFmt* pFmt = GetFrmFmt();
1363 	if(pFmt)
1364 	{
1365 		SwTable* pTable = SwTable::FindTable( pFmt );
1366 		SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, pLine);
1367 		if(pLn)
1368 		{
1369             const SfxItemPropertySimpleEntry* pEntry =
1370                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1371             if (!pEntry)
1372 				throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1373 
1374             switch(pEntry->nWID)
1375 			{
1376 				case FN_UNO_ROW_HEIGHT:
1377 				case FN_UNO_ROW_AUTO_HEIGHT:
1378 				{
1379 					const SwFmtFrmSize& rSize = pLn->GetFrmFmt()->GetFrmSize();
1380                     if(FN_UNO_ROW_AUTO_HEIGHT== pEntry->nWID)
1381 					{
1382                         sal_Bool bTmp =  ATT_VAR_SIZE == rSize.GetHeightSizeType();
1383 						aRet.setValue(&bTmp, ::getCppuBooleanType());
1384 					}
1385 					else
1386 						aRet <<= (sal_Int32)(TWIP_TO_MM100(rSize.GetSize().Height()));
1387 				}
1388 				break;
1389 				case FN_UNO_TABLE_COLUMN_SEPARATORS:
1390 				{
1391 					lcl_GetTblSeparators(aRet, pTable, pLine->GetTabBoxes()[0], sal_True);
1392 				}
1393 				break;
1394 				default:
1395 				{
1396 					const SwAttrSet& rSet = pLn->GetFrmFmt()->GetAttrSet();
1397                     m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
1398 				}
1399 			}
1400 		}
1401 	}
1402 	return aRet;
1403 }
1404 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1405 void SwXTextTableRow::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1406 {
1407 	DBG_WARNING("not implemented");
1408 }
1409 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1410 void SwXTextTableRow::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1411 {
1412 	DBG_WARNING("not implemented");
1413 }
1414 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1415 void SwXTextTableRow::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1416 {
1417 	DBG_WARNING("not implemented");
1418 }
1419 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1420 void SwXTextTableRow::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1421 {
1422 	DBG_WARNING("not implemented");
1423 }
1424 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1425 void SwXTextTableRow::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
1426 {
1427 	ClientModify(this, pOld, pNew);
1428 }
1429 
FindLine(SwTable * pTable,SwTableLine * pLine)1430 SwTableLine* SwXTextTableRow::FindLine(SwTable* pTable, SwTableLine* pLine)
1431 {
1432 	SwTableLine* pRet = 0;
1433 	SwTableLines &rLines = pTable->GetTabLines();
1434 	for(sal_uInt16 i = 0; i < rLines.Count(); i++)
1435 		if(rLines.GetObject(i) == pLine)
1436 		{
1437 			pRet = pLine;
1438 			break;
1439 		}
1440 	return pRet;
1441 }
1442 
1443 /******************************************************************
1444  * SwXTextTableCursor
1445  ******************************************************************/
1446 
getImplementationName(void)1447 OUString SwXTextTableCursor::getImplementationName(void) throw( uno::RuntimeException )
1448 {
1449 	return C2U("SwXTextTableCursor");
1450 }
1451 
supportsService(const OUString & rServiceName)1452 sal_Bool SwXTextTableCursor::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1453 {
1454 	return C2U("com.sun.star.text.TextTableCursor") == rServiceName;
1455 }
1456 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(SwXTextTableCursor,SwXTextTableCursor_Base,OTextCursorHelper) const1457 IMPLEMENT_FORWARD_XINTERFACE2(SwXTextTableCursor,SwXTextTableCursor_Base,OTextCursorHelper)
1458 const SwPaM*		SwXTextTableCursor::GetPaM() const	{ return GetCrsr(); }
GetPaM()1459 SwPaM*				SwXTextTableCursor::GetPaM()		{ return GetCrsr(); }
GetDoc() const1460 const SwDoc* 		SwXTextTableCursor::GetDoc() const	{ return GetFrmFmt()->GetDoc(); }
GetDoc()1461 SwDoc* 				SwXTextTableCursor::GetDoc()		{ return GetFrmFmt()->GetDoc(); }
GetCrsr() const1462 const SwUnoCrsr*	SwXTextTableCursor::GetCrsr() const	{ return (SwUnoCrsr*)aCrsrDepend.GetRegisteredIn(); }
GetCrsr()1463 SwUnoCrsr*			SwXTextTableCursor::GetCrsr()		{ return (SwUnoCrsr*)aCrsrDepend.GetRegisteredIn(); }
1464 
getSupportedServiceNames(void)1465 uno::Sequence< OUString > SwXTextTableCursor::getSupportedServiceNames(void) throw( uno::RuntimeException )
1466 {
1467 	uno::Sequence< OUString > aRet(1);
1468 	OUString* pArray = aRet.getArray();
1469 	pArray[0] = C2U("com.sun.star.text.TextTableCursor");
1470 	return aRet;
1471 }
1472 
SwXTextTableCursor(SwFrmFmt * pFmt,SwTableBox * pBox)1473 SwXTextTableCursor::SwXTextTableCursor(SwFrmFmt* pFmt, SwTableBox* pBox) :
1474 	SwClient(pFmt),
1475 	aCrsrDepend(this, 0),
1476     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_CURSOR))
1477 {
1478 	SwDoc* pDoc = pFmt->GetDoc();
1479 	const SwStartNode* pSttNd = pBox->GetSttNd();
1480 	SwPosition aPos(*pSttNd);
1481 	SwUnoCrsr* pUnoCrsr = pDoc->CreateUnoCrsr(aPos, sal_True);
1482 	pUnoCrsr->Move( fnMoveForward, fnGoNode );
1483 	pUnoCrsr->Add(&aCrsrDepend);
1484     SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1485 	pTblCrsr->MakeBoxSels();
1486 }
1487 
SwXTextTableCursor(SwFrmFmt & rTableFmt,const SwTableCursor * pTableSelection)1488 SwXTextTableCursor::SwXTextTableCursor(SwFrmFmt& rTableFmt,	const SwTableCursor* pTableSelection) :
1489 	SwClient(&rTableFmt),
1490 	aCrsrDepend(this, 0),
1491     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_CURSOR))
1492 {
1493 	SwUnoCrsr* pUnoCrsr = pTableSelection->GetDoc()->CreateUnoCrsr(*pTableSelection->GetPoint(), sal_True);
1494 	if(pTableSelection->HasMark())
1495 	{
1496 		pUnoCrsr->SetMark();
1497 		*pUnoCrsr->GetMark() = *pTableSelection->GetMark();
1498 	}
1499 	const SwSelBoxes& rBoxes = pTableSelection->GetBoxes();
1500     SwTableCursor* pTableCrsr = dynamic_cast<SwTableCursor*>(pUnoCrsr);
1501 	for(sal_uInt16 i = 0; i < rBoxes.Count(); i++)
1502 		pTableCrsr->InsertBox( *rBoxes.GetObject(i) );
1503 
1504 	pUnoCrsr->Add(&aCrsrDepend);
1505     SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1506 	pTblCrsr->MakeBoxSels();
1507 }
1508 
~SwXTextTableCursor()1509 SwXTextTableCursor::~SwXTextTableCursor()
1510 {
1511     vos::OGuard aGuard(Application::GetSolarMutex());
1512     SwUnoCrsr* pUnoCrsr = GetCrsr();
1513 	if(pUnoCrsr)
1514 		delete pUnoCrsr;
1515 }
1516 
getRangeName(void)1517 OUString SwXTextTableCursor::getRangeName(void) throw( uno::RuntimeException )
1518 {
1519 	vos::OGuard aGuard(Application::GetSolarMutex());
1520 	OUString aRet;
1521 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1522 
1523     //!! see also SwChartDataSequence::getSourceRangeRepresentation
1524 	if(pUnoCrsr)
1525 	{
1526         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1527 		pTblCrsr->MakeBoxSels();
1528 		const SwStartNode* pNode = pTblCrsr->GetPoint()->nNode.GetNode().FindTableBoxStartNode();
1529 		const SwTable* pTable = SwTable::FindTable( GetFrmFmt() );
1530 		const SwTableBox* pEndBox = pTable->GetTblBox( pNode->GetIndex());
1531 		String aTmp( pEndBox->GetName() );
1532 
1533 		if(pTblCrsr->HasMark())
1534 		{
1535 			pNode = pTblCrsr->GetMark()->nNode.GetNode().FindTableBoxStartNode();
1536 			const SwTableBox* pStartBox = pTable->GetTblBox( pNode->GetIndex());
1537 			if(pEndBox != pStartBox)
1538 			{
1539 				// need to switch start and end?
1540 				if (*pTblCrsr->GetPoint() < *pTblCrsr->GetMark())
1541 				{
1542 					const SwTableBox* pTmpBox = pStartBox;
1543 					pStartBox = pEndBox;
1544 					pEndBox = pTmpBox;
1545 				}
1546 
1547 				aTmp  = pStartBox->GetName();
1548 				aTmp += ':';
1549 				aTmp += pEndBox->GetName();
1550 			}
1551 		}
1552 		aRet = aTmp;
1553 	}
1554 	return aRet;
1555 }
1556 
gotoCellByName(const OUString & CellName,sal_Bool Expand)1557 sal_Bool SwXTextTableCursor::gotoCellByName(const OUString& CellName, sal_Bool Expand)
1558 	throw( uno::RuntimeException )
1559 {
1560 	vos::OGuard aGuard(Application::GetSolarMutex());
1561 	sal_Bool bRet = sal_False;
1562 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1563 	if(pUnoCrsr)
1564 	{
1565 		SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1566 		lcl_CrsrSelect(	pTblCrsr, Expand );
1567 		String sCellName(CellName);
1568 		bRet = pTblCrsr->GotoTblBox(sCellName);
1569 	}
1570 	return bRet;
1571 }
1572 
goLeft(sal_Int16 Count,sal_Bool Expand)1573 sal_Bool SwXTextTableCursor::goLeft(sal_Int16 Count, sal_Bool Expand) throw( uno::RuntimeException )
1574 {
1575 	vos::OGuard aGuard(Application::GetSolarMutex());
1576 	sal_Bool bRet = sal_False;
1577 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1578 	if(pUnoCrsr)
1579 	{
1580         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1581 		lcl_CrsrSelect(	pTblCrsr, Expand );
1582         bRet = pTblCrsr->Left( Count,CRSR_SKIP_CHARS, sal_False, sal_False);
1583 	}
1584 	return bRet;
1585 }
1586 
goRight(sal_Int16 Count,sal_Bool Expand)1587 sal_Bool SwXTextTableCursor::goRight(sal_Int16 Count, sal_Bool Expand) throw( uno::RuntimeException )
1588 {
1589 	vos::OGuard aGuard(Application::GetSolarMutex());
1590 	sal_Bool bRet = sal_False;
1591 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1592 	if(pUnoCrsr)
1593 	{
1594         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1595 		lcl_CrsrSelect(	pTblCrsr, Expand );
1596         bRet = pTblCrsr->Right( Count, CRSR_SKIP_CHARS, sal_False, sal_False);
1597 	}
1598 	return bRet;
1599 }
1600 
goUp(sal_Int16 Count,sal_Bool Expand)1601 sal_Bool SwXTextTableCursor::goUp(sal_Int16 Count, sal_Bool Expand) throw( uno::RuntimeException )
1602 {
1603 	vos::OGuard aGuard(Application::GetSolarMutex());
1604 	sal_Bool bRet = sal_False;
1605 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1606 	if(pUnoCrsr)
1607 	{
1608         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1609 		lcl_CrsrSelect(	pTblCrsr, Expand );
1610 		bRet = pTblCrsr->UpDown(sal_True, Count, 0, 0);
1611 	}
1612 	return bRet;
1613 }
1614 
goDown(sal_Int16 Count,sal_Bool Expand)1615 sal_Bool SwXTextTableCursor::goDown(sal_Int16 Count, sal_Bool Expand) throw( uno::RuntimeException )
1616 {
1617 	vos::OGuard aGuard(Application::GetSolarMutex());
1618 	sal_Bool bRet = sal_False;
1619 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1620 	if(pUnoCrsr)
1621 	{
1622         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1623 		lcl_CrsrSelect(	pTblCrsr, Expand );
1624 		bRet = pTblCrsr->UpDown(sal_False, Count, 0, 0);
1625 	}
1626 	return bRet;
1627 }
1628 
gotoStart(sal_Bool Expand)1629 void SwXTextTableCursor::gotoStart(sal_Bool Expand) throw( uno::RuntimeException )
1630 {
1631 	vos::OGuard aGuard(Application::GetSolarMutex());
1632 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1633 	if(pUnoCrsr)
1634 	{
1635         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1636 		lcl_CrsrSelect(	pTblCrsr, Expand );
1637 		pTblCrsr->MoveTable(fnTableCurr, fnTableStart);
1638 	}
1639 }
1640 
gotoEnd(sal_Bool Expand)1641 void SwXTextTableCursor::gotoEnd(sal_Bool Expand) throw( uno::RuntimeException )
1642 {
1643 	vos::OGuard aGuard(Application::GetSolarMutex());
1644 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1645 	if(pUnoCrsr)
1646 	{
1647         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1648 		lcl_CrsrSelect(	pTblCrsr, Expand );
1649 		pTblCrsr->MoveTable(fnTableCurr, fnTableEnd);
1650 	}
1651 }
1652 
mergeRange(void)1653 sal_Bool SwXTextTableCursor::mergeRange(void) throw( uno::RuntimeException )
1654 {
1655 	vos::OGuard aGuard(Application::GetSolarMutex());
1656 	sal_Bool bRet = sal_False;
1657 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1658 	if(pUnoCrsr)
1659 	{
1660 		{
1661 			// hier muessen die Actions aufgehoben werden
1662 			UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc());
1663 		}
1664         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1665 		pTblCrsr->MakeBoxSels();
1666 
1667 		{
1668 			UnoActionContext aContext(pUnoCrsr->GetDoc());
1669 			bRet = TBLMERGE_OK == pTblCrsr->GetDoc()->MergeTbl(*pTblCrsr);
1670             if(bRet)
1671             {
1672                 sal_uInt16 nCount = pTblCrsr->GetBoxesCount();
1673                 while(nCount--)
1674                     pTblCrsr->DeleteBox(nCount);
1675             }
1676 		}
1677         pTblCrsr->MakeBoxSels();
1678 	}
1679 	return bRet;
1680 }
1681 
splitRange(sal_Int16 Count,sal_Bool Horizontal)1682 sal_Bool SwXTextTableCursor::splitRange(sal_Int16 Count, sal_Bool Horizontal) throw( uno::RuntimeException )
1683 {
1684 	vos::OGuard aGuard(Application::GetSolarMutex());
1685     if (Count <= 0)
1686         throw uno::RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal first argument: needs to be > 0" ) ), static_cast < cppu::OWeakObject * > ( this ) );
1687 	sal_Bool bRet = sal_False;
1688 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1689 	if(pUnoCrsr)
1690 	{
1691 		{
1692 			// hier muessen die Actions aufgehoben werden
1693 			UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc());
1694 		}
1695         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1696 		pTblCrsr->MakeBoxSels();
1697 		{
1698 			UnoActionContext aContext(pUnoCrsr->GetDoc());
1699 			bRet = pTblCrsr->GetDoc()->SplitTbl( pTblCrsr->GetBoxes(), !Horizontal, Count );
1700 		}
1701 		pTblCrsr->MakeBoxSels();
1702 	}
1703 	return bRet;
1704 }
1705 
getPropertySetInfo(void)1706 uno::Reference< beans::XPropertySetInfo >  SwXTextTableCursor::getPropertySetInfo(void) throw( uno::RuntimeException )
1707 {
1708     static uno::Reference< beans::XPropertySetInfo >  xRef = m_pPropSet->getPropertySetInfo();
1709 	return xRef;
1710 }
1711 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)1712 void SwXTextTableCursor::setPropertyValue(const OUString& rPropertyName,
1713 														const uno::Any& aValue)
1714 			throw( beans::UnknownPropertyException,
1715 						beans::PropertyVetoException,
1716  					lang::IllegalArgumentException,
1717  					lang::WrappedTargetException,
1718  					uno::RuntimeException)
1719 {
1720 	vos::OGuard aGuard(Application::GetSolarMutex());
1721 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1722 	if(pUnoCrsr)
1723 	{
1724         SwStartNode* pSttNode = pUnoCrsr->GetNode()->StartOfSectionNode();
1725 		const SwTableNode* pTblNode = pSttNode->FindTableNode();
1726 		lcl_FormatTable((SwFrmFmt*)pTblNode->GetTable().GetFrmFmt());
1727         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1728         const SfxItemPropertySimpleEntry* pEntry =
1729                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1730         if(pEntry)
1731 		{
1732             if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1733                 throw beans::PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1734 			pTblCrsr->MakeBoxSels();
1735 			SwDoc* pDoc = pUnoCrsr->GetDoc();
1736             switch(pEntry->nWID )
1737 			{
1738 				case FN_UNO_TABLE_CELL_BACKGROUND:
1739 				{
1740                     SvxBrushItem aBrush( RES_BACKGROUND );
1741                     pDoc->GetBoxAttr( *pUnoCrsr, aBrush );
1742                     aBrush.PutValue(aValue, pEntry->nMemberId);
1743 					pDoc->SetBoxAttr( *pUnoCrsr, aBrush );
1744 
1745 				}
1746 				break;
1747 				case RES_BOXATR_FORMAT:
1748 				{
1749 					SfxUInt32Item aNumberFormat(RES_BOXATR_FORMAT);
1750 					aNumberFormat.PutValue(aValue, 0);
1751 					pDoc->SetBoxAttr( *pUnoCrsr, aNumberFormat);
1752 				}
1753 				break;
1754 				case FN_UNO_PARA_STYLE:
1755                     SwUnoCursorHelper::SetTxtFmtColl(aValue, *pUnoCrsr);
1756 				break;
1757 				default:
1758 				{
1759                     SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID );
1760                     SwUnoCursorHelper::GetCrsrAttr(pTblCrsr->GetSelRing(),
1761                             aItemSet);
1762 
1763                     if (!SwUnoCursorHelper::SetCursorPropertyValue(
1764                             *pEntry, aValue, pTblCrsr->GetSelRing(), aItemSet))
1765                     {
1766                         m_pPropSet->setPropertyValue(*pEntry, aValue, aItemSet);
1767                     }
1768                     SwUnoCursorHelper::SetCrsrAttr(pTblCrsr->GetSelRing(),
1769                             aItemSet, nsSetAttrMode::SETATTR_DEFAULT, true);
1770 				}
1771 			}
1772 		}
1773 		else
1774         	throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1775 	}
1776 }
1777 
getPropertyValue(const OUString & rPropertyName)1778 uno::Any SwXTextTableCursor::getPropertyValue(const OUString& rPropertyName)
1779 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1780 {
1781 	vos::OGuard aGuard(Application::GetSolarMutex());
1782 	uno::Any aRet;
1783 	SwUnoCrsr* pUnoCrsr = GetCrsr();
1784 	if(pUnoCrsr)
1785 	{
1786         SwStartNode* pSttNode = pUnoCrsr->GetNode()->StartOfSectionNode();
1787 		const SwTableNode* pTblNode = pSttNode->FindTableNode();
1788 		lcl_FormatTable((SwFrmFmt*)pTblNode->GetTable().GetFrmFmt());
1789         SwUnoTableCrsr* pTblCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
1790         const SfxItemPropertySimpleEntry* pEntry =
1791                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1792         if(pEntry)
1793 		{
1794 			pTblCrsr->MakeBoxSels();
1795             switch(pEntry->nWID )
1796 			{
1797 				case FN_UNO_TABLE_CELL_BACKGROUND:
1798 				{
1799                     SvxBrushItem aBrush( RES_BACKGROUND );
1800                     if(pTblCrsr->GetDoc()->GetBoxAttr( *pUnoCrsr, aBrush ))
1801                         aBrush.QueryValue(aRet, pEntry->nMemberId);
1802 
1803 				}
1804 				break;
1805 				case RES_BOXATR_FORMAT:
1806 					//GetAttr fuer Tabellenselektion am Doc fehlt noch
1807 					DBG_WARNING("not implemented");
1808 				break;
1809 				case FN_UNO_PARA_STYLE:
1810 				{
1811                     SwFmtColl *const pFmt =
1812                         SwUnoCursorHelper::GetCurTxtFmtColl(*pUnoCrsr, sal_False);
1813 					OUString sRet;
1814 					if(pFmt)
1815 						sRet = pFmt->GetName();
1816 					aRet <<= sRet;
1817 				}
1818 				break;
1819 				default:
1820 				{
1821 					SfxItemSet aSet(pTblCrsr->GetDoc()->GetAttrPool(),
1822 						RES_CHRATR_BEGIN, 		RES_FRMATR_END -1,
1823 						RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1824 						0L);
1825 					// erstmal die Attribute des Cursors
1826                     SwUnoCursorHelper::GetCrsrAttr(pTblCrsr->GetSelRing(),
1827                             aSet);
1828                     m_pPropSet->getPropertyValue(*pEntry, aSet, aRet);
1829 				}
1830 			}
1831 		}
1832 		else
1833 	        throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1834 	}
1835 	return aRet;
1836 }
1837 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1838 void SwXTextTableCursor::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1839 {
1840 	DBG_WARNING("not implemented");
1841 }
1842 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1843 void SwXTextTableCursor::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1844 {
1845 	DBG_WARNING("not implemented");
1846 }
1847 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1848 void SwXTextTableCursor::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1849 {
1850 	DBG_WARNING("not implemented");
1851 }
1852 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1853 void SwXTextTableCursor::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1854 {
1855 	DBG_WARNING("not implemented");
1856 }
1857 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1858 void SwXTextTableCursor::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
1859 {
1860 	ClientModify(this, pOld, pNew);
1861 }
1862 /******************************************************************
1863  * SwXTextTable
1864  ******************************************************************/
1865 /****************************************************************************
1866 	Tabellenbeschreibung
1867 ****************************************************************************/
1868 
1869 class SwTableProperties_Impl
1870 {
1871     SwUnoCursorHelper::SwAnyMapHelper aAnyMap;
1872 public:
1873     SwTableProperties_Impl();
1874 	~SwTableProperties_Impl();
1875 
1876     void        SetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& aVal);
1877     sal_Bool    GetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& rpAny);
1878 
1879     void        ApplyTblAttr(const SwTable& rTbl, SwDoc& rDoc);
1880 };
1881 
1882 
SwTableProperties_Impl()1883 SwTableProperties_Impl::SwTableProperties_Impl()
1884 {
1885 }
1886 
~SwTableProperties_Impl()1887 SwTableProperties_Impl::~SwTableProperties_Impl()
1888 {
1889 }
1890 
SetProperty(sal_uInt16 nWhichId,sal_uInt16 nMemberId,const uno::Any & rVal)1891 void SwTableProperties_Impl::SetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& rVal)
1892 {
1893     aAnyMap.SetValue( nWhichId, nMemberId, rVal );
1894 }
1895 
GetProperty(sal_uInt16 nWhichId,sal_uInt16 nMemberId,const uno::Any * & rpAny)1896 sal_Bool SwTableProperties_Impl::GetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& rpAny )
1897 {
1898     return aAnyMap.FillValue( nWhichId, nMemberId, rpAny );
1899 }
1900 
ApplyTblAttr(const SwTable & rTbl,SwDoc & rDoc)1901 void	SwTableProperties_Impl::ApplyTblAttr(const SwTable& rTbl, SwDoc& rDoc)
1902 {
1903 	SfxItemSet aSet(rDoc.GetAttrPool(),
1904 		RES_LAYOUT_SPLIT, 	RES_LAYOUT_SPLIT,
1905 		RES_BACKGROUND,		RES_BACKGROUND,
1906 		RES_FRM_SIZE,		RES_UL_SPACE,
1907 		RES_HORI_ORIENT,	RES_HORI_ORIENT,
1908 		RES_BREAK, 			RES_BREAK,
1909 		RES_KEEP,			RES_KEEP,
1910 		RES_SHADOW, 		RES_SHADOW,
1911 		RES_PAGEDESC, 		RES_PAGEDESC,
1912 		0
1913 		);
1914     const uno::Any* pRepHead;
1915 	const SwFrmFmt &rFrmFmt = *rTbl.GetFrmFmt();
1916     if(GetProperty(FN_TABLE_HEADLINE_REPEAT, 0xff, pRepHead ))
1917 	{
1918 		sal_Bool bVal = *(sal_Bool*)pRepHead->getValue();
1919         ((SwTable&)rTbl).SetRowsToRepeat( bVal ? 1 : 0 );  // TODO MULTIHEADER
1920 	}
1921 
1922     const uno::Any* pBackColor   = 0;
1923     GetProperty(RES_BACKGROUND, MID_BACK_COLOR, pBackColor );
1924     const uno::Any* pBackTrans  = 0;
1925     GetProperty(RES_BACKGROUND, MID_GRAPHIC_TRANSPARENT, pBackTrans );
1926     const uno::Any* pGrLoc      = 0;
1927     GetProperty(RES_BACKGROUND, MID_GRAPHIC_POSITION, pGrLoc    );
1928     const uno::Any* pGrURL      = 0;
1929     GetProperty(RES_BACKGROUND, MID_GRAPHIC_URL, pGrURL     );
1930     const uno::Any* pGrFilter   = 0;
1931     GetProperty(RES_BACKGROUND, MID_GRAPHIC_FILTER, pGrFilter     );
1932 
1933 	if(pBackColor||pBackTrans||pGrURL||pGrFilter||pGrLoc)
1934 	{
1935         SvxBrushItem aBrush ( rFrmFmt.GetBackground() );
1936 		if(pBackColor)
1937 			aBrush.PutValue(*pBackColor, MID_BACK_COLOR);
1938 		if(pBackTrans)
1939 			aBrush.PutValue(*pBackTrans, MID_GRAPHIC_TRANSPARENT);
1940 		if(pGrURL)
1941 			aBrush.PutValue(*pGrURL, MID_GRAPHIC_URL);
1942 		if(pGrFilter)
1943 			aBrush.PutValue(*pGrFilter, MID_GRAPHIC_FILTER);
1944 		if(pGrLoc)
1945 			aBrush.PutValue(*pGrLoc, MID_GRAPHIC_POSITION);
1946 		aSet.Put(aBrush);
1947 	}
1948 
1949 	sal_Bool bPutBreak = sal_True;
1950     const uno::Any* pPage;
1951     if(GetProperty(FN_UNO_PAGE_STYLE, 0, pPage) || GetProperty(RES_PAGEDESC, 0xff, pPage))
1952 	{
1953 		OUString uTmp;
1954 		(*pPage) >>= uTmp;
1955 		String sPageStyle = uTmp;
1956 		if(sPageStyle.Len())
1957 		{
1958 			SwStyleNameMapper::FillUIName(sPageStyle, sPageStyle, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True );
1959 			const SwPageDesc* pDesc = ::GetPageDescByName_Impl(rDoc, sPageStyle);
1960 			if(pDesc)
1961 			{
1962 				SwFmtPageDesc aDesc( pDesc );
1963                 const uno::Any* pPgNo;
1964                 if(GetProperty(RES_PAGEDESC, MID_PAGEDESC_PAGENUMOFFSET, pPgNo ))
1965 				{
1966 					sal_Int16 nTmp = 0;
1967 					(*pPgNo) >>= nTmp;
1968 					aDesc.SetNumOffset( nTmp );
1969 				}
1970 				aSet.Put(aDesc);
1971 				bPutBreak = sal_False;
1972 			}
1973 
1974 		}
1975 	}
1976     const uno::Any* pBreak;
1977     if(bPutBreak && GetProperty(RES_BREAK, 0, pBreak))
1978 	{
1979 		SvxFmtBreakItem aBreak ( rFrmFmt.GetBreak() );
1980 		aBreak.PutValue(*pBreak, 0);
1981 		aSet.Put(aBreak);
1982 	}
1983     const uno::Any* pShadow;
1984     if(GetProperty(RES_SHADOW, 0, pShadow))
1985 	{
1986 		SvxShadowItem aShd ( rFrmFmt.GetShadow() );
1987 		aShd.PutValue(*pShadow, CONVERT_TWIPS);
1988 		aSet.Put(aShd);
1989 	}
1990     const uno::Any* pKeep;
1991     if(GetProperty(RES_KEEP, 0, pKeep))
1992 	{
1993 		SvxFmtKeepItem aKeep( rFrmFmt.GetKeep() );
1994 		aKeep.PutValue(*pKeep, 0);
1995 		aSet.Put(aKeep);
1996 	}
1997 
1998 	sal_Bool bFullAlign = sal_True;
1999     const uno::Any* pHOrient;
2000     if(GetProperty(RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, pHOrient))
2001 	{
2002 		SwFmtHoriOrient aOrient ( rFrmFmt.GetHoriOrient() );
2003 		((SfxPoolItem&)aOrient).PutValue(*pHOrient, MID_HORIORIENT_ORIENT|CONVERT_TWIPS);
2004         bFullAlign = (aOrient.GetHoriOrient() == text::HoriOrientation::FULL);
2005 		aSet.Put(aOrient);
2006 	}
2007 
2008 
2009     const uno::Any* pSzRel       = 0;
2010     GetProperty(FN_TABLE_IS_RELATIVE_WIDTH, 0xff, pSzRel  );
2011     const uno::Any* pRelWidth   = 0;
2012     GetProperty(FN_TABLE_RELATIVE_WIDTH, 0xff, pRelWidth);
2013     const uno::Any* pWidth      = 0;
2014     GetProperty(FN_TABLE_WIDTH, 0xff, pWidth  );
2015 
2016 	sal_Bool bPutSize = pWidth != 0;
2017 	SwFmtFrmSize aSz( ATT_VAR_SIZE);
2018 	if(pWidth)
2019 	{
2020 		((SfxPoolItem&)aSz).PutValue(*pWidth, MID_FRMSIZE_WIDTH);
2021 		bPutSize = sal_True;
2022 	}
2023 	sal_Bool bTemp = pSzRel ? *(sal_Bool*)pSzRel->getValue() : sal_False;
2024 	if(pSzRel && bTemp && pRelWidth)
2025 	{
2026 		((SfxPoolItem&)aSz).PutValue(*pRelWidth, MID_FRMSIZE_REL_WIDTH|CONVERT_TWIPS);
2027 		bPutSize = sal_True;
2028 	}
2029 	if(bPutSize)
2030 	{
2031 		if(!aSz.GetWidth())
2032 			aSz.SetWidth(MINLAY);
2033 		aSet.Put(aSz);
2034 	}
2035     const uno::Any* pL      = 0;
2036     GetProperty(RES_LR_SPACE, MID_L_MARGIN|CONVERT_TWIPS, pL);
2037     const uno::Any* pR      = 0;
2038     GetProperty(RES_LR_SPACE, MID_R_MARGIN|CONVERT_TWIPS, pR);
2039 	if(pL||pR)
2040 	{
2041 		SvxLRSpaceItem aLR ( rFrmFmt.GetLRSpace() );
2042 		if(pL)
2043 			((SfxPoolItem&)aLR).PutValue(*pL, MID_L_MARGIN|CONVERT_TWIPS);
2044 		if(pR)
2045 			((SfxPoolItem&)aLR).PutValue(*pR, MID_R_MARGIN|CONVERT_TWIPS);
2046 		aSet.Put(aLR);
2047 	}
2048     const uno::Any* pU      = 0;
2049     GetProperty(RES_UL_SPACE, MID_UP_MARGIN|CONVERT_TWIPS, pU);
2050     const uno::Any* pLo     = 0;
2051     GetProperty(RES_UL_SPACE, MID_LO_MARGIN|CONVERT_TWIPS, pLo);
2052 	if(pU||pLo)
2053 	{
2054 		SvxULSpaceItem aUL ( rFrmFmt.GetULSpace() );
2055 		if(pU)
2056 			((SfxPoolItem&)aUL).PutValue(*pU, MID_UP_MARGIN|CONVERT_TWIPS);
2057 		if(pLo)
2058 			((SfxPoolItem&)aUL).PutValue(*pLo, MID_LO_MARGIN|CONVERT_TWIPS);
2059 		aSet.Put(aUL);
2060 	}
2061     const::uno::Any* pSplit;
2062     if(GetProperty(RES_LAYOUT_SPLIT, 0, pSplit ))
2063 	{
2064 		sal_Bool bTmp = *(sal_Bool*)pSplit->getValue();
2065 		SwFmtLayoutSplit aSp(bTmp);
2066 		aSet.Put(aSp);
2067 	}
2068 
2069 	//TODO: folgende Propertiers noch impl.
2070 //	FN_UNO_RANGE_ROW_LABEL
2071 //	FN_UNO_RANGE_COL_LABEL
2072 //	FN_UNO_TABLE_BORDER
2073 
2074 	if(aSet.Count())
2075 	{
2076 		rDoc.SetAttr( aSet, *rTbl.GetFrmFmt() );
2077 	}
2078 }
2079 
getUnoTunnelId()2080 const uno::Sequence< sal_Int8 > & SwXTextTable::getUnoTunnelId()
2081 {
2082     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
2083 	return aSeq;
2084 }
2085 
getSomething(const uno::Sequence<sal_Int8> & rId)2086 sal_Int64 SAL_CALL SwXTextTable::getSomething( const uno::Sequence< sal_Int8 >& rId )
2087 	throw(uno::RuntimeException)
2088 {
2089     if( rId.getLength() == 16
2090         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2091 										rId.getConstArray(), 16 ) )
2092     {
2093 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
2094     }
2095 	return 0;
2096 }
2097 
TYPEINIT1(SwXTextTable,SwClient)2098 TYPEINIT1(SwXTextTable, SwClient)
2099 
2100 
2101 SwXTextTable::SwXTextTable() :
2102     aLstnrCntnr( (text::XTextTable*)this),
2103     aChartLstnrCntnr( (text::XTextTable*)this),
2104     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE)),
2105     pTableProps(new SwTableProperties_Impl),
2106 	bIsDescriptor(sal_True),
2107 	nRows(2),
2108 	nColumns(2),
2109 	bFirstRowAsLabel(sal_False),
2110 	bFirstColumnAsLabel(sal_False)
2111 {
2112 }
2113 
SwXTextTable(SwFrmFmt & rFrmFmt)2114 SwXTextTable::SwXTextTable(SwFrmFmt& rFrmFmt) :
2115 	SwClient( &rFrmFmt ),
2116     aLstnrCntnr( (text::XTextTable*)this),
2117     aChartLstnrCntnr( (text::XTextTable*)this),
2118     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE)),
2119 	pTableProps(0),
2120 	bIsDescriptor(sal_False),
2121 	nRows(0),
2122 	nColumns(0),
2123 	bFirstRowAsLabel(sal_False),
2124 	bFirstColumnAsLabel(sal_False)
2125 {
2126 }
2127 
~SwXTextTable()2128 SwXTextTable::~SwXTextTable()
2129 {
2130 	delete pTableProps;
2131 }
2132 
initialize(sal_Int32 nR,sal_Int32 nC)2133 void SwXTextTable::initialize(sal_Int32 nR, sal_Int32 nC) throw( uno::RuntimeException )
2134 {
2135 	if(!bIsDescriptor || nR <= 0 || nC <= 0 || nR >= USHRT_MAX || nC >= USHRT_MAX )
2136 		throw uno::RuntimeException();
2137 	else
2138 	{
2139 		nRows = (sal_uInt16)nR;
2140 		nColumns = (sal_uInt16)nC;
2141 	}
2142 }
2143 
getRows(void)2144 uno::Reference< table::XTableRows >  SwXTextTable::getRows(void) throw( uno::RuntimeException )
2145 {
2146 	vos::OGuard aGuard(Application::GetSolarMutex());
2147 	uno::Reference< table::XTableRows >  xRet;
2148 	if (SwFrmFmt* pFmt = GetFrmFmt())
2149     {
2150         SwXTableRows* pRows = SwIterator<SwXTableRows,SwFmt>::FirstElement(*pFmt);
2151         if (!pRows)
2152             pRows = new SwXTableRows(*pFmt);
2153 		xRet = pRows;
2154     }
2155     if (!xRet.is())
2156 		throw uno::RuntimeException();
2157 	return xRet;
2158 }
2159 
getColumns(void)2160 uno::Reference< table::XTableColumns >  SwXTextTable::getColumns(void) throw( uno::RuntimeException )
2161 {
2162 	vos::OGuard aGuard(Application::GetSolarMutex());
2163 	uno::Reference< table::XTableColumns >  xRet;
2164 	if (SwFrmFmt* pFmt = GetFrmFmt())
2165     {
2166         SwXTableColumns* pCols = SwIterator<SwXTableColumns,SwFmt>::FirstElement(*pFmt);
2167         if (!pCols)
2168             pCols = new SwXTableColumns(*pFmt);
2169         xRet = pCols;
2170     }
2171     if (!xRet.is())
2172 		throw uno::RuntimeException();
2173 	return xRet;
2174 }
2175 
getCellByName(const OUString & CellName)2176 uno::Reference< table::XCell >  SwXTextTable::getCellByName(const OUString& CellName) throw( uno::RuntimeException )
2177 {
2178 	vos::OGuard aGuard(Application::GetSolarMutex());
2179 	uno::Reference< table::XCell >  xRet;
2180 	SwFrmFmt* pFmt = GetFrmFmt();
2181 	if(pFmt)
2182 	{
2183 		SwTable* pTable = SwTable::FindTable( pFmt );
2184 		String sCellName(CellName);
2185         SwTableBox* pBox = (SwTableBox*)pTable->GetTblBox( sCellName );
2186 		if(pBox)
2187 		{
2188 			xRet = SwXCell::CreateXCell(pFmt, pBox);
2189 		}
2190 	}
2191 	else
2192 		throw uno::RuntimeException();
2193 	return xRet;
2194 }
2195 
getCellNames(void)2196 uno::Sequence< OUString > SwXTextTable::getCellNames(void) throw( uno::RuntimeException )
2197 {
2198 	vos::OGuard aGuard(Application::GetSolarMutex());
2199 	SwFrmFmt* pFmt = GetFrmFmt();
2200 	if(pFmt)
2201 	{
2202 		SwTable* pTable = SwTable::FindTable( pFmt );
2203 		  // gibts an der Tabelle und an allen Boxen
2204 		SwTableLines& rTblLines = pTable->GetTabLines();
2205 		SvStrings aAllNames;
2206 		lcl_InspectLines(rTblLines, aAllNames);
2207 		uno::Sequence< OUString > aRet(aAllNames.Count());
2208 		OUString* pArray = aRet.getArray();
2209 		for(sal_uInt16 i = aAllNames.Count(); i; i--)
2210 		{
2211 			String* pObject = aAllNames.GetObject(i-1);
2212 			pArray[i - 1] = *pObject;
2213 			aAllNames.Remove(i - 1);
2214 			delete pObject;
2215 		}
2216 		return aRet;
2217 	}
2218 	return uno::Sequence< OUString >();
2219 }
2220 
createCursorByCellName(const OUString & CellName)2221 uno::Reference< text::XTextTableCursor >  SwXTextTable::createCursorByCellName(const OUString& CellName)
2222 	throw( uno::RuntimeException )
2223 {
2224 	vos::OGuard aGuard(Application::GetSolarMutex());
2225 	uno::Reference< text::XTextTableCursor >  xRet;
2226 	SwFrmFmt* pFmt = GetFrmFmt();
2227 	if(pFmt)
2228 	{
2229 		SwTable* pTable = SwTable::FindTable( pFmt );
2230 		String sCellName(CellName);
2231         SwTableBox* pBox = (SwTableBox*)pTable->GetTblBox( sCellName );
2232 		if(pBox && pBox->getRowSpan() > 0 )
2233 		{
2234 			xRet = new SwXTextTableCursor(pFmt, pBox);
2235 		}
2236 	}
2237 	if(!xRet.is())
2238 		throw uno::RuntimeException();
2239 	return xRet;
2240 }
2241 
attachToRange(const uno::Reference<text::XTextRange> & xTextRange)2242 void SwXTextTable::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
2243 	throw( lang::IllegalArgumentException, uno::RuntimeException )
2244 {
2245     // attachToRange must only be called once
2246     if(!bIsDescriptor)  /* already attached ? */
2247         throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "SwXTextTable: already attached to range." ) ), static_cast < cppu::OWeakObject * > ( this ) );
2248 
2249 	uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
2250 	SwXTextRange* pRange = 0;
2251 	OTextCursorHelper* pCursor = 0;
2252 	if(xRangeTunnel.is())
2253 	{
2254 		pRange 	= reinterpret_cast< SwXTextRange * >(
2255 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
2256 		pCursor = reinterpret_cast< OTextCursorHelper * >(
2257 				sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
2258 	}
2259 	SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
2260 	if(pDoc && nRows && nColumns)
2261 	{
2262 		SwUnoInternalPaM aPam(*pDoc);
2263 		//das muss jetzt sal_True liefern
2264         ::sw::XTextRangeToSwPaM(aPam, xTextRange);
2265 
2266 		{
2267 			UnoActionContext aCont( pDoc );
2268 
2269             pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
2270 			const SwTable *pTable = 0;
2271 			if( 0 != aPam.Start()->nContent.GetIndex() )
2272 			{
2273 				pDoc->SplitNode(*aPam.Start(), false );
2274 			}
2275 			//TODO: wenn es der letzte Absatz ist, dann muss noch ein Absatz angehaengt werden!
2276 			if( aPam.HasMark() )
2277 			{
2278 				pDoc->DeleteAndJoin(aPam);
2279 				aPam.DeleteMark();
2280 			}
2281             pTable = pDoc->InsertTable( SwInsertTableOptions( tabopts::HEADLINE | tabopts::DEFAULT_BORDER | tabopts::SPLIT_LAYOUT, 0 ),
2282 										*aPam.GetPoint(),
2283 										nRows,
2284 										nColumns,
2285                                         text::HoriOrientation::FULL );
2286 			if(pTable)
2287 			{
2288 				// hier muessen die Properties des Descriptors ausgewertet werden
2289 				pTableProps->ApplyTblAttr(*pTable, *pDoc);
2290 				SwFrmFmt* pTblFmt = pTable->GetFrmFmt();
2291                 lcl_FormatTable( pTblFmt );
2292 
2293 				pTblFmt->Add(this);
2294 				if(m_sTableName.Len())
2295 				{
2296 					sal_uInt16 nIndex = 1;
2297 					const String sTmpName(m_sTableName);
2298 					String sTmpNameIndex(sTmpName);
2299 					while(pDoc->FindTblFmtByName( sTmpNameIndex, sal_True ) && nIndex < USHRT_MAX)
2300 					{
2301 						sTmpNameIndex = sTmpName;
2302 						sTmpNameIndex += nIndex++;
2303 					}
2304 					pDoc->SetTableName( *pTblFmt, sTmpNameIndex);
2305 				}
2306 
2307                 const::uno::Any* pName;
2308                 if(pTableProps->GetProperty(FN_UNO_TABLE_NAME, 0, pName))
2309 				{
2310 					OUString sTmp;
2311 					(*pName) >>= sTmp;
2312 					setName(sTmp);
2313 				}
2314 				bIsDescriptor = sal_False;
2315 				DELETEZ(pTableProps);
2316             }
2317             pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
2318         }
2319     }
2320     else
2321 		throw lang::IllegalArgumentException();
2322 }
2323 
attach(const uno::Reference<text::XTextRange> & xTextRange)2324 void SwXTextTable::attach(const uno::Reference< text::XTextRange > & xTextRange)
2325 		throw( lang::IllegalArgumentException, uno::RuntimeException )
2326 {
2327 	vos::OGuard aGuard(Application::GetSolarMutex());
2328     attachToRange( xTextRange );
2329 }
2330 
getAnchor(void)2331 uno::Reference< text::XTextRange >  SwXTextTable::getAnchor(void)
2332 		throw( uno::RuntimeException )
2333 {
2334 	vos::OGuard aGuard(Application::GetSolarMutex());
2335 	SwFrmFmt* pFmt = GetFrmFmt();
2336 	if(!pFmt)
2337 		throw uno::RuntimeException();
2338 	uno::Reference< text::XTextRange >  xRet = new SwXTextRange(*pFmt);
2339 	return xRet;
2340 }
2341 
dispose(void)2342 void SwXTextTable::dispose(void) throw( uno::RuntimeException )
2343 {
2344 	vos::OGuard aGuard(Application::GetSolarMutex());
2345 	SwFrmFmt* pFmt = GetFrmFmt();
2346 	if(pFmt)
2347 	{
2348 		SwTable* pTable = SwTable::FindTable( pFmt );
2349 		SwTableSortBoxes& rBoxes = pTable->GetTabSortBoxes();
2350 		SwSelBoxes aSelBoxes;
2351 		aSelBoxes.Insert(rBoxes.GetData(), rBoxes.Count());
2352 		pFmt->GetDoc()->DeleteRowCol(aSelBoxes);
2353 	}
2354 	else
2355 		throw uno::RuntimeException();
2356 }
2357 
addEventListener(const uno::Reference<lang::XEventListener> & aListener)2358 void SwXTextTable::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2359 {
2360 	if(!GetRegisteredIn())
2361 		throw uno::RuntimeException();
2362 	aLstnrCntnr.AddListener(aListener);
2363 }
2364 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)2365 void SwXTextTable::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
2366 {
2367 	if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
2368 		throw uno::RuntimeException();
2369 }
2370 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)2371 uno::Reference< table::XCell >  SwXTextTable::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow)
2372 	throw( uno::RuntimeException, lang::IndexOutOfBoundsException )
2373 {
2374 	vos::OGuard aGuard(Application::GetSolarMutex());
2375 	uno::Reference< table::XCell >  aRef;
2376 	SwFrmFmt* pFmt = GetFrmFmt();
2377 	// Sheet interessiert nicht
2378 	if(nColumn >= 0 && nRow >= 0 && nColumn < USHRT_MAX && nRow < USHRT_MAX && pFmt)
2379 	{
2380 		SwXCell* pXCell = lcl_CreateXCell(pFmt, nColumn, nRow);
2381 		if(pXCell)
2382 			aRef = pXCell;
2383 	}
2384 	if(!aRef.is())
2385 		throw lang::IndexOutOfBoundsException();
2386 	return aRef;
2387 
2388 }
2389 
GetRangeByName(SwFrmFmt * pFmt,SwTable * pTable,const String & rTLName,const String & rBRName,SwRangeDescriptor & rDesc)2390 uno::Reference< table::XCellRange >  SwXTextTable::GetRangeByName(SwFrmFmt* pFmt, SwTable* pTable,
2391 					const String& rTLName, const String& rBRName,
2392 					SwRangeDescriptor& rDesc)
2393 {
2394 	vos::OGuard aGuard(Application::GetSolarMutex());
2395 	uno::Reference< table::XCellRange >  aRef;
2396 	String sTLName(rTLName);
2397 	String sBRName(rBRName);
2398     const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
2399 	if(pTLBox)
2400 	{
2401 		// hier muessen die Actions aufgehoben werden
2402 		UnoActionRemoveContext aRemoveContext(pFmt->GetDoc());
2403 		const SwStartNode* pSttNd = pTLBox->GetSttNd();
2404 		SwPosition aPos(*pSttNd);
2405 		// Cursor in die obere linke Zelle des Ranges setzen
2406 		SwUnoCrsr* pUnoCrsr = pFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
2407 		pUnoCrsr->Move( fnMoveForward, fnGoNode );
2408 		pUnoCrsr->SetRemainInSection( sal_False );
2409         const SwTableBox* pBRBox = pTable->GetTblBox( sBRName );
2410 		if(pBRBox)
2411 		{
2412 			pUnoCrsr->SetMark();
2413 			pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd();
2414 			pUnoCrsr->Move( fnMoveForward, fnGoNode );
2415             SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
2416 			pCrsr->MakeBoxSels();
2417 			// pUnoCrsr wird uebergeben und nicht geloescht
2418 			SwXCellRange* pCellRange = new SwXCellRange(pUnoCrsr, *pFmt, rDesc);
2419 			aRef = pCellRange;
2420 		}
2421 		else
2422 			delete pUnoCrsr;
2423 	}
2424 	return aRef;
2425 }
2426 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)2427 uno::Reference< table::XCellRange >  SwXTextTable::getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop,
2428 				sal_Int32 nRight, sal_Int32 nBottom)
2429 	throw( uno::RuntimeException, lang::IndexOutOfBoundsException )
2430 {
2431 	vos::OGuard aGuard(Application::GetSolarMutex());
2432 	uno::Reference< table::XCellRange >  aRef;
2433 	SwFrmFmt* pFmt = GetFrmFmt();
2434 	if(pFmt && nRight < USHRT_MAX && nBottom < USHRT_MAX &&
2435 		nLeft <= nRight && nTop <= nBottom &&
2436 			nLeft >= 0 && nRight >= 0 && nTop >= 0 && nBottom >= 0 )
2437 	{
2438 		SwTable* pTable = SwTable::FindTable( pFmt );
2439 		if(!pTable->IsTblComplex())
2440 		{
2441 			SwRangeDescriptor aDesc;
2442             aDesc.nTop    = nTop;
2443             aDesc.nBottom = nBottom;
2444             aDesc.nLeft   = nLeft;
2445             aDesc.nRight  = nRight;
2446 			String sTLName = lcl_GetCellName(aDesc.nLeft, aDesc.nTop);
2447 			String sBRName = lcl_GetCellName(aDesc.nRight, aDesc.nBottom);
2448 
2449             // please note that according to the 'if' statement at the begin
2450             // sTLName:sBRName already denotes the normalized range string
2451 
2452 			aRef = GetRangeByName(pFmt, pTable, sTLName, sBRName, aDesc);
2453 		}
2454 	}
2455 	if(!aRef.is())
2456 		throw lang::IndexOutOfBoundsException();
2457 	return aRef;
2458 }
2459 
getCellRangeByName(const OUString & aRange)2460 uno::Reference< table::XCellRange >  SwXTextTable::getCellRangeByName(const OUString& aRange)
2461 	throw( uno::RuntimeException )
2462 {
2463 	vos::OGuard aGuard(Application::GetSolarMutex());
2464 	uno::Reference< table::XCellRange >  aRef;
2465 	SwFrmFmt* pFmt = GetFrmFmt();
2466 	if(pFmt)
2467 	{
2468 		SwTable* pTable = SwTable::FindTable( pFmt );
2469 		if(!pTable->IsTblComplex())
2470 		{
2471 			String sRange(aRange);
2472 			String sTLName(sRange.GetToken(0, ':'));
2473 			String sBRName(sRange.GetToken(1, ':'));
2474             if(!sTLName.Len() || !sBRName.Len())
2475 				throw uno::RuntimeException();
2476 			SwRangeDescriptor aDesc;
2477             aDesc.nTop = aDesc.nLeft = aDesc.nBottom = aDesc.nRight = -1;
2478             lcl_GetCellPosition(sTLName, aDesc.nLeft, aDesc.nTop );
2479             lcl_GetCellPosition(sBRName, aDesc.nRight, aDesc.nBottom );
2480 
2481             // we should normalize the range now (e.g. A5:C1 will become A1:C5)
2482             // since (depending on what is done later) it will be troublesome
2483             // elsewhere when the cursor in the implementation does not
2484             // point to the top-left and bottom-right cells
2485             aDesc.Normalize();
2486 
2487             aRef = GetRangeByName(pFmt, pTable, sTLName, sBRName, aDesc);
2488 		}
2489 	}
2490 	if(!aRef.is())
2491 		throw uno::RuntimeException();
2492 	return aRef;
2493 }
2494 
getDataArray()2495 uno::Sequence< uno::Sequence< uno::Any > > SAL_CALL SwXTextTable::getDataArray()
2496     throw (uno::RuntimeException)
2497 {
2498     // see SwXTextTable::getData(...) also
2499 
2500     vos::OGuard aGuard(Application::GetSolarMutex());
2501 	sal_Int16 nRowCount = getRowCount();
2502 	sal_Int16 nColCount = getColumnCount();
2503 	if(!nRowCount || !nColCount)
2504 	{
2505 		uno::RuntimeException aRuntime;
2506 		aRuntime.Message = C2U("Table too complex");
2507 		throw aRuntime;
2508 	}
2509 	SwFrmFmt* pFmt = GetFrmFmt();
2510     uno::Sequence< uno::Sequence< uno::Any > > aRowSeq(nRowCount);
2511 	if(pFmt)
2512 	{
2513         uno::Sequence< uno::Any > * pRowArray = aRowSeq.getArray();
2514         for(sal_uInt16 nRow = 0; nRow < nRowCount; nRow++)
2515 		{
2516             uno::Sequence< uno::Any >  aColSeq(nColCount);
2517             uno::Any * pColArray = aColSeq.getArray();
2518             uno::Reference< table::XCell > xCellRef;
2519             for(sal_uInt16 nCol = 0; nCol < nColCount; nCol++)
2520 			{
2521                 SwXCell* pXCell = lcl_CreateXCell(pFmt, nCol, nRow);
2522                 //! keep (additional) reference to object to prevent implicit destruction
2523                 //! in following UNO calls (when object will get referenced)
2524                 xCellRef = pXCell;
2525                 SwTableBox * pBox = pXCell ? pXCell->GetTblBox() : 0;
2526                 if(!pBox)
2527 				{
2528 					throw uno::RuntimeException();
2529 				}
2530                 else
2531                 {
2532 					// check if table box value item is set
2533 					SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
2534 					sal_Bool bIsNum = pBoxFmt->GetItemState( RES_BOXATR_VALUE, sal_False ) == SFX_ITEM_SET;
2535 					//const SfxPoolItem* pItem;
2536 					//SwDoc* pDoc = pXCell->GetDoc();
2537 					//sal_Bool bIsText = (SFX_ITEM_SET != pBoxFmt->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, sal_True, &pItem)
2538 					//			||  pDoc->GetNumberFormatter()->IsTextFormat(((SwTblBoxNumFormat*)pItem)->GetValue())
2539 					//			||	((SwTblBoxNumFormat*)pItem)->GetValue() == NUMBERFORMAT_TEXT);
2540 
2541                     if(!bIsNum/*bIsText*/)
2542                         pColArray[nCol] <<= lcl_getString(*pXCell);
2543                     else
2544                         pColArray[nCol] <<= lcl_getValue(*pXCell);
2545                 }
2546 			}
2547             pRowArray[nRow] = aColSeq;
2548 		}
2549 	}
2550 	else
2551 		throw uno::RuntimeException();
2552 	return aRowSeq;
2553 }
2554 
setDataArray(const uno::Sequence<uno::Sequence<uno::Any>> & rArray)2555 void SAL_CALL SwXTextTable::setDataArray(
2556         const uno::Sequence< uno::Sequence< uno::Any > >& rArray )
2557     throw (uno::RuntimeException)
2558 {
2559     // see SwXTextTable::setData(...) also
2560 
2561     vos::OGuard aGuard(Application::GetSolarMutex());
2562     sal_Int16 nRowCount = getRowCount();
2563     sal_Int16 nColCount = getColumnCount();
2564 
2565 	SwFrmFmt* pFmt = GetFrmFmt();
2566     if(pFmt)
2567 	{
2568 		SwTable* pTable = SwTable::FindTable( pFmt );
2569         if(pTable->IsTblComplex())
2570 		{
2571             uno::RuntimeException aRuntime;
2572             aRuntime.Message = C2U("Table too complex");
2573             throw aRuntime;
2574 		}
2575 
2576         if(rArray.getLength() != nRowCount)
2577 		{
2578 			throw uno::RuntimeException();
2579 		}
2580         const uno::Sequence< uno::Any >* pRowArray = rArray.getConstArray();
2581         for(sal_uInt16 nRow = 0; nRow < nRowCount; nRow++)
2582 		{
2583             const uno::Sequence< uno::Any >& rColSeq = pRowArray[nRow];
2584             if(rColSeq.getLength() != nColCount)
2585 			{
2586 				throw uno::RuntimeException();
2587 			}
2588             const uno::Any * pColArray = rColSeq.getConstArray();
2589             uno::Reference< table::XCell > xCellRef;
2590             for(sal_uInt16 nCol = 0; nCol < nColCount; nCol++)
2591 			{
2592                 SwXCell* pXCell = lcl_CreateXCell(pFmt, nCol, nRow);
2593                 //! keep (additional) reference to object to prevent implicit destruction
2594                 //! in following UNO calls (when object will get referenced)
2595                 xCellRef = pXCell;
2596                 SwTableBox * pBox = pXCell ? pXCell->GetTblBox() : 0;
2597                 if(!pBox)
2598 				{
2599 					throw uno::RuntimeException();
2600 				}
2601                 else
2602                 {
2603                     const uno::Any &rAny = pColArray[nCol];
2604                     if (uno::TypeClass_STRING == rAny.getValueTypeClass())
2605                         lcl_setString( *pXCell, *(rtl::OUString *) rAny.getValue() );
2606                     else
2607                     {
2608                         double d = 0;
2609                         // #i20067# don't throw exception just do nothing if
2610                         // there is no value set
2611                         if( (rAny >>= d) )
2612                             lcl_setValue( *pXCell, d );
2613 						else
2614 							lcl_setString( *pXCell, OUString(), sal_True );
2615 
2616                     }
2617                 }
2618 			}
2619 		}
2620 	}
2621 }
2622 
getData(void)2623 uno::Sequence< uno::Sequence< double > > SwXTextTable::getData(void)
2624 										throw( uno::RuntimeException )
2625 {
2626 	vos::OGuard aGuard(Application::GetSolarMutex());
2627 	sal_Int16 nRowCount = getRowCount();
2628 	sal_Int16 nColCount = getColumnCount();
2629 	if(!nRowCount || !nColCount)
2630 	{
2631 		uno::RuntimeException aRuntime;
2632 		aRuntime.Message = C2U("Table too complex");
2633 		throw aRuntime;
2634 	}
2635 	//
2636 	SwFrmFmt* pFmt = GetFrmFmt();
2637 	uno::Sequence< uno::Sequence< double > > aRowSeq(bFirstRowAsLabel ? nRowCount - 1 : nRowCount);
2638 	if(pFmt)
2639 	{
2640 		uno::Sequence< double >* pArray = aRowSeq.getArray();
2641 
2642 		sal_uInt16 nRowStart = bFirstRowAsLabel ? 1 : 0;
2643 		for(sal_uInt16 nRow = nRowStart; nRow < nRowCount; nRow++)
2644 		{
2645 			uno::Sequence< double >  aColSeq(bFirstColumnAsLabel ? nColCount - 1 : nColCount);
2646 			double* pColArray = aColSeq.getArray();
2647 			sal_uInt16 nColStart = bFirstColumnAsLabel ? 1 : 0;
2648 			for(sal_uInt16 nCol = nColStart; nCol < nColCount; nCol++)
2649 			{
2650 				uno::Reference< table::XCell >  xCell = getCellByPosition(nCol, nRow);
2651 				if(!xCell.is())
2652 				{
2653 					throw uno::RuntimeException();
2654 				}
2655 				pColArray[nCol - nColStart] = xCell->getValue();
2656 			}
2657 			pArray[nRow - nRowStart] = aColSeq;
2658 		}
2659 	}
2660 	else
2661 		throw uno::RuntimeException();
2662 	return aRowSeq;
2663 }
2664 
setData(const uno::Sequence<uno::Sequence<double>> & rData)2665 void SwXTextTable::setData(const uno::Sequence< uno::Sequence< double > >& rData)
2666 										throw( uno::RuntimeException )
2667 {
2668 	vos::OGuard aGuard(Application::GetSolarMutex());
2669 	sal_Int16 nRowCount = getRowCount();
2670 	sal_Int16 nColCount = getColumnCount();
2671 	sal_Bool bChanged = sal_False;
2672 
2673 	if(!nRowCount || !nColCount)
2674 	{
2675 		uno::RuntimeException aRuntime;
2676 		aRuntime.Message = C2U("Table too complex");
2677 		throw aRuntime;
2678 	}
2679 	SwFrmFmt* pFmt = GetFrmFmt();
2680 	if(pFmt )
2681 	{
2682 		sal_uInt16 nRowStart = bFirstRowAsLabel ? 1 : 0;
2683 		if(rData.getLength() < nRowCount - nRowStart)
2684 		{
2685 			throw uno::RuntimeException();
2686 		}
2687 		const uno::Sequence< double >* pRowArray = rData.getConstArray();
2688 		for(sal_uInt16 nRow = nRowStart; nRow < nRowCount; nRow++)
2689 		{
2690 			const uno::Sequence< double >& rColSeq = pRowArray[nRow - nRowStart];
2691 			sal_uInt16 nColStart = bFirstColumnAsLabel ? 1 : 0;
2692 			if(rColSeq.getLength() < nColCount - nColStart)
2693 			{
2694 				throw uno::RuntimeException();
2695 			}
2696 			const double * pColArray = rColSeq.getConstArray();
2697 			for(sal_uInt16 nCol = nColStart; nCol < nColCount; nCol++)
2698 			{
2699 				uno::Reference< table::XCell >  xCell = getCellByPosition(nCol, nRow);
2700 				if(!xCell.is())
2701 				{
2702 					throw uno::RuntimeException();
2703 				}
2704 				xCell->setValue(pColArray[nCol - nColStart]);
2705 				bChanged=sal_True;
2706 			}
2707 		}
2708 		if ( bChanged )
2709 			aChartLstnrCntnr.ChartDataChanged();
2710 	}
2711 }
2712 
getRowDescriptions(void)2713 uno::Sequence< OUString > SwXTextTable::getRowDescriptions(void) throw( uno::RuntimeException )
2714 {
2715 	vos::OGuard aGuard(Application::GetSolarMutex());
2716 	sal_Int16 nRowCount = getRowCount();
2717 	if(!nRowCount)
2718 	{
2719 		uno::RuntimeException aRuntime;
2720 		aRuntime.Message = C2U("Table too complex");
2721 		throw aRuntime;
2722 	}
2723 	uno::Sequence< OUString > aRet(bFirstColumnAsLabel ? nRowCount - 1 : nRowCount);
2724 	SwFrmFmt* pFmt = GetFrmFmt();
2725 	if(pFmt)
2726 	{
2727 		OUString* pArray = aRet.getArray();
2728 		if(bFirstColumnAsLabel)
2729 		{
2730 			sal_uInt16 nStart = bFirstRowAsLabel ? 1 : 0;
2731 			for(sal_uInt16 i = nStart; i < nRowCount; i++)
2732 			{
2733 				uno::Reference< table::XCell >  xCell = getCellByPosition(0, i);
2734 				if(!xCell.is())
2735 				{
2736 					//exception ...
2737 					break;
2738 				}
2739 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
2740 				pArray[i - nStart] = xText->getString();
2741 			}
2742 		}
2743 		else
2744 		{
2745 			DBG_ERROR("Wo kommen die Labels her?");
2746 		}
2747 	}
2748 	else
2749 		throw uno::RuntimeException();
2750 	return aRet;
2751 }
2752 
setRowDescriptions(const uno::Sequence<OUString> & rRowDesc)2753 void SwXTextTable::setRowDescriptions(const uno::Sequence< OUString >& rRowDesc) throw( uno::RuntimeException )
2754 {
2755 	vos::OGuard aGuard(Application::GetSolarMutex());
2756 	SwFrmFmt* pFmt = GetFrmFmt();
2757 	if(pFmt)
2758 	{
2759 		sal_Int16 nRowCount = getRowCount();
2760 		if(!nRowCount || rRowDesc.getLength() < (bFirstRowAsLabel ? nRowCount - 1 : nRowCount))
2761 		{
2762 			throw uno::RuntimeException();
2763 		}
2764 		const OUString* pArray = rRowDesc.getConstArray();
2765 		if(bFirstColumnAsLabel)
2766 		{
2767 			sal_uInt16 nStart = bFirstRowAsLabel ? 1 : 0;
2768 			for(sal_uInt16 i = nStart; i < nRowCount; i++)
2769 			{
2770 				uno::Reference< table::XCell >  xCell = getCellByPosition(0, i);
2771 				if(!xCell.is())
2772 				{
2773 					throw uno::RuntimeException();
2774 				}
2775 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
2776 				xText->setString(pArray[i - nStart]);
2777 			}
2778 		}
2779 		else
2780 		{
2781 			DBG_ERROR("Wohin mit den Labels?");
2782 		}
2783 	}
2784 	else
2785 		throw uno::RuntimeException();
2786 }
2787 
getColumnDescriptions(void)2788 uno::Sequence< OUString > SwXTextTable::getColumnDescriptions(void)
2789 												throw( uno::RuntimeException )
2790 {
2791 	vos::OGuard aGuard(Application::GetSolarMutex());
2792 	sal_Int16 nColCount = getColumnCount();
2793 	if(!nColCount)
2794 	{
2795 		uno::RuntimeException aRuntime;
2796 		aRuntime.Message = C2U("Table too complex");
2797 		throw aRuntime;
2798 	}
2799 	uno::Sequence< OUString > aRet(bFirstRowAsLabel ? nColCount - 1 : nColCount);
2800 	SwFrmFmt* pFmt = GetFrmFmt();
2801 	if(pFmt)
2802 	{
2803 		OUString* pArray = aRet.getArray();
2804 		if(bFirstRowAsLabel)
2805 		{
2806 			sal_uInt16 nStart = bFirstColumnAsLabel ? 1 : 0;
2807 			for(sal_uInt16 i = nStart; i < nColCount; i++)
2808 			{
2809 				uno::Reference< table::XCell >  xCell = getCellByPosition(i, 0);
2810 				if(!xCell.is())
2811 				{
2812 					throw uno::RuntimeException();
2813 				}
2814 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
2815 
2816 				pArray[i - nStart] = xText->getString();
2817 			}
2818 		}
2819 		else
2820 		{
2821 			DBG_ERROR("Wo kommen die Labels her?");
2822 		}
2823 	}
2824 	else
2825 		throw uno::RuntimeException();
2826 	return aRet;
2827 }
2828 
setColumnDescriptions(const uno::Sequence<OUString> & rColumnDesc)2829 void SwXTextTable::setColumnDescriptions(const uno::Sequence< OUString >& rColumnDesc) throw( uno::RuntimeException )
2830 {
2831 	vos::OGuard aGuard(Application::GetSolarMutex());
2832 	sal_Int16 nColCount = getColumnCount();
2833 	if(!nColCount)
2834 	{
2835 		uno::RuntimeException aRuntime;
2836 		aRuntime.Message = C2U("Table too complex");
2837 		throw aRuntime;
2838 	}
2839 	SwFrmFmt* pFmt = GetFrmFmt();
2840 	if(pFmt)
2841 	{
2842 		const OUString* pArray = rColumnDesc.getConstArray();
2843 		if(bFirstRowAsLabel && rColumnDesc.getLength() >= nColCount - bFirstColumnAsLabel ? 1 : 0)
2844 		{
2845 			sal_uInt16 nStart = bFirstColumnAsLabel ? 1 : 0;
2846 			for(sal_uInt16 i = nStart; i < nColCount; i++)
2847 			{
2848 				uno::Reference< table::XCell >  xCell = getCellByPosition(i, 0);
2849 				if(!xCell.is())
2850 				{
2851 					throw uno::RuntimeException();
2852 				}
2853 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
2854 				xText->setString(pArray[i - nStart]);
2855 			}
2856 		}
2857 		else
2858 		{
2859 			DBG_ERROR("Wo kommen die Labels her?");
2860 		}
2861 	}
2862 	else
2863 		throw uno::RuntimeException();
2864 }
2865 
addChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)2866 void SwXTextTable::addChartDataChangeEventListener(
2867 	const uno::Reference< chart::XChartDataChangeEventListener > & aListener)
2868 		throw( uno::RuntimeException )
2869 {
2870 	if(!GetRegisteredIn())
2871 		throw uno::RuntimeException();
2872 	aChartLstnrCntnr.AddListener(aListener.get());
2873 }
2874 
removeChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)2875 void SwXTextTable::removeChartDataChangeEventListener(
2876 	const uno::Reference< chart::XChartDataChangeEventListener > & aListener)
2877 		throw( uno::RuntimeException )
2878 {
2879 	if(!GetRegisteredIn() || !aChartLstnrCntnr.RemoveListener(aListener.get()))
2880 		throw uno::RuntimeException();
2881 }
2882 
isNotANumber(double nNumber)2883 sal_Bool SwXTextTable::isNotANumber(double nNumber) throw( uno::RuntimeException )
2884 {
2885 	// We use DBL_MIN because starcalc does (which uses it because chart
2886 	// wants it that way!)
2887 	return ( nNumber == DBL_MIN );
2888 }
2889 
getNotANumber(void)2890 double SwXTextTable::getNotANumber(void) throw( uno::RuntimeException )
2891 {
2892 	// We use DBL_MIN because starcalc does (which uses it because chart
2893 	// wants it that way!)
2894 	return DBL_MIN;
2895 }
2896 
createSortDescriptor(void)2897 uno::Sequence< beans::PropertyValue > SwXTextTable::createSortDescriptor(void)
2898 	throw( uno::RuntimeException )
2899 {
2900 	vos::OGuard aGuard(Application::GetSolarMutex());
2901 
2902     return SwUnoCursorHelper::CreateSortDescriptor(true);
2903 }
2904 
sort(const uno::Sequence<beans::PropertyValue> & rDescriptor)2905 void SwXTextTable::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
2906 	throw( uno::RuntimeException )
2907 {
2908 	vos::OGuard aGuard(Application::GetSolarMutex());
2909 	SwSortOptions aSortOpt;
2910 	SwFrmFmt* pFmt = GetFrmFmt();
2911 	if(pFmt &&
2912         SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
2913 	{
2914 		SwTable* pTable = SwTable::FindTable( pFmt );
2915 		SwSelBoxes aBoxes;
2916 		const SwTableSortBoxes& rTBoxes = pTable->GetTabSortBoxes();
2917 		for( sal_uInt16 n = 0; n < rTBoxes.Count(); ++n )
2918 		{
2919 			SwTableBox* pBox = rTBoxes[ n ];
2920 			aBoxes.Insert( pBox );
2921 		}
2922 		UnoActionContext aContext( pFmt->GetDoc() );
2923 		pFmt->GetDoc()->SortTbl(aBoxes, aSortOpt);
2924 	}
2925 }
2926 
autoFormat(const OUString & aName)2927 void SwXTextTable::autoFormat(const OUString& aName) throw( lang::IllegalArgumentException, uno::RuntimeException )
2928 {
2929 	vos::OGuard aGuard(Application::GetSolarMutex());
2930 	SwFrmFmt* pFmt = GetFrmFmt();
2931 	if(pFmt)
2932 	{
2933 		SwTable* pTable = SwTable::FindTable( pFmt );
2934 		if(!pTable->IsTblComplex())
2935 		{
2936 
2937 			String sAutoFmtName(aName);
2938 			SwTableAutoFmtTbl aAutoFmtTbl;
2939 			aAutoFmtTbl.Load();
2940 			for( sal_uInt16 i = aAutoFmtTbl.Count(); i; )
2941 				if( sAutoFmtName == aAutoFmtTbl[ --i ]->GetName() )
2942 				{
2943 					SwSelBoxes aBoxes;
2944 					const SwTableSortBoxes& rTBoxes = pTable->GetTabSortBoxes();
2945 					for( sal_uInt16 n = 0; n < rTBoxes.Count(); ++n )
2946 					{
2947 						SwTableBox* pBox = rTBoxes[ n ];
2948 						aBoxes.Insert( pBox );
2949 					}
2950 					UnoActionContext aContext( pFmt->GetDoc() );
2951 					pFmt->GetDoc()->SetTableAutoFmt( aBoxes, *aAutoFmtTbl[i] );
2952 					break;
2953 				}
2954 		}
2955 	}
2956 	else
2957 		throw uno::RuntimeException();
2958 }
2959 
getPropertySetInfo(void)2960 uno::Reference< beans::XPropertySetInfo >  SwXTextTable::getPropertySetInfo(void) throw( uno::RuntimeException )
2961 {
2962     static uno::Reference< beans::XPropertySetInfo >  xRef = m_pPropSet->getPropertySetInfo();
2963 	return xRef;
2964 }
2965 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)2966 void SwXTextTable::setPropertyValue(const OUString& rPropertyName,
2967 													const uno::Any& aValue)
2968 		throw( beans::UnknownPropertyException, beans::PropertyVetoException,
2969 				lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
2970 {
2971 	vos::OGuard aGuard(Application::GetSolarMutex());
2972 	SwFrmFmt* pFmt = GetFrmFmt();
2973 	if(!aValue.hasValue())
2974 		throw lang::IllegalArgumentException();
2975     const SfxItemPropertySimpleEntry* pEntry =
2976                                 m_pPropSet->getPropertyMap()->getByName(rPropertyName);
2977     if( !pEntry )
2978         throw lang::IllegalArgumentException();
2979     if(pFmt)
2980 	{
2981         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
2982             throw beans::PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
2983 
2984         if(0xFF == pEntry->nMemberId)
2985 		{
2986             lcl_SetSpecialProperty(pFmt, pEntry, aValue);
2987 		}
2988 		else
2989 		{
2990             switch(pEntry->nWID)
2991 			{
2992                 case UNO_NAME_TABLE_NAME :
2993                 {
2994                     ::rtl::OUString sName;
2995                     aValue >>= sName;
2996                     setName( sName );
2997                 }
2998                 break;
2999                 case FN_UNO_RANGE_ROW_LABEL:
3000 				{
3001 					sal_Bool bTmp = *(sal_Bool*)aValue.getValue();
3002 					if(bFirstRowAsLabel != bTmp)
3003 					{
3004 						aChartLstnrCntnr.ChartDataChanged();
3005 						bFirstRowAsLabel = bTmp;
3006 					}
3007 				}
3008 				break;
3009 				case FN_UNO_RANGE_COL_LABEL:
3010 				{
3011 					sal_Bool bTmp = *(sal_Bool*)aValue.getValue();
3012 					if(bFirstColumnAsLabel != bTmp)
3013 					{
3014 						aChartLstnrCntnr.ChartDataChanged();
3015 						bFirstColumnAsLabel = bTmp;
3016 					}
3017 				}
3018 				break;
3019 				case FN_UNO_TABLE_BORDER:
3020 				{
3021 					const table::TableBorder* pBorder =
3022 							(const table::TableBorder* )aValue.getValue();
3023 					if(aValue.getValueType() == ::getCppuType((const table::TableBorder* )0)
3024 						&& pBorder)
3025 					{
3026 						SwDoc* pDoc = pFmt->GetDoc();
3027                         SwFrm* pFrm = SwIterator<SwFrm,SwFmt>::FirstElement( *pFmt );
3028 						//Tabellen ohne Layout (unsichtbare Header/Footer )
3029 						if( pFrm )
3030 						{
3031 							lcl_FormatTable(pFmt);
3032 							SwTable* pTable = SwTable::FindTable( pFmt );
3033 							SwTableLines &rLines = pTable->GetTabLines();
3034 
3035 
3036 							// hier muessen die Actions aufgehoben werden
3037 							UnoActionRemoveContext aRemoveContext(pDoc);
3038                             const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true);
3039 							const SwStartNode* pSttNd = pTLBox->GetSttNd();
3040 							SwPosition aPos(*pSttNd);
3041 							// Cursor in die obere linke Zelle des Ranges setzen
3042 							SwUnoCrsr* pUnoCrsr = pDoc->CreateUnoCrsr(aPos, sal_True);
3043 							pUnoCrsr->Move( fnMoveForward, fnGoNode );
3044 							pUnoCrsr->SetRemainInSection( sal_False );
3045 
3046 
3047 
3048                             const SwTableBox* pBRBox = lcl_FindCornerTableBox(rLines, false);
3049 							pUnoCrsr->SetMark();
3050 							pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd();
3051 							pUnoCrsr->Move( fnMoveForward, fnGoNode );
3052                             SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
3053 							pCrsr->MakeBoxSels();
3054 
3055 							SfxItemSet aSet(pDoc->GetAttrPool(),
3056 											RES_BOX, RES_BOX,
3057 											SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
3058 											0);
3059 
3060                             SvxBoxItem aBox( RES_BOX );
3061                             SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
3062 							SvxBorderLine aLine;
3063 
3064 							sal_Bool bSet = lcl_LineToSvxLine(pBorder->TopLine, aLine);
3065 							aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_TOP);
3066 							aBoxInfo.SetValid(VALID_TOP, pBorder->IsTopLineValid);
3067 
3068 							bSet = lcl_LineToSvxLine(pBorder->BottomLine, aLine);
3069 							aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_BOTTOM);
3070 							aBoxInfo.SetValid(VALID_BOTTOM, pBorder->IsBottomLineValid);
3071 
3072 							bSet = lcl_LineToSvxLine(pBorder->LeftLine, aLine);
3073 							aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_LEFT);
3074 							aBoxInfo.SetValid(VALID_LEFT, pBorder->IsLeftLineValid);
3075 
3076 							bSet = lcl_LineToSvxLine(pBorder->RightLine, aLine);
3077 							aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_RIGHT);
3078 							aBoxInfo.SetValid(VALID_RIGHT, pBorder->IsRightLineValid);
3079 
3080 							bSet = lcl_LineToSvxLine(pBorder->HorizontalLine, aLine);
3081 							aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_HORI);
3082 							aBoxInfo.SetValid(VALID_HORI, pBorder->IsHorizontalLineValid);
3083 
3084 							bSet = lcl_LineToSvxLine(pBorder->VerticalLine, aLine);
3085 							aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_VERT);
3086 							aBoxInfo.SetValid(VALID_VERT, pBorder->IsVerticalLineValid);
3087 
3088 							aBox.SetDistance((sal_uInt16)MM100_TO_TWIP(pBorder->Distance));
3089 							aBoxInfo.SetValid(VALID_DISTANCE, pBorder->IsDistanceValid);
3090 
3091 							aSet.Put(aBox);
3092 							aSet.Put(aBoxInfo);
3093 
3094 							pDoc->SetTabBorders(*pCrsr, aSet);
3095 							delete pUnoCrsr;
3096 						}
3097 					}
3098 				}
3099 				break;
3100                 case FN_UNO_TABLE_BORDER_DISTANCES:
3101                 {
3102                     table::TableBorderDistances aTableBorderDistances;
3103                     if( !(aValue >>= aTableBorderDistances) ||
3104                         (!aTableBorderDistances.IsLeftDistanceValid &&
3105                         !aTableBorderDistances.IsRightDistanceValid &&
3106                         !aTableBorderDistances.IsTopDistanceValid &&
3107                         !aTableBorderDistances.IsBottomDistanceValid ))
3108                         break;
3109 
3110                     sal_uInt16 nLeftDistance =     MM100_TO_TWIP_UNSIGNED( aTableBorderDistances.LeftDistance);
3111                     sal_uInt16 nRightDistance =    MM100_TO_TWIP_UNSIGNED( aTableBorderDistances.RightDistance);
3112                     sal_uInt16 nTopDistance =      MM100_TO_TWIP_UNSIGNED( aTableBorderDistances.TopDistance);
3113                     sal_uInt16 nBottomDistance =   MM100_TO_TWIP_UNSIGNED( aTableBorderDistances.BottomDistance);
3114                     SwDoc* pDoc = pFmt->GetDoc();
3115                     SwTable* pTable = SwTable::FindTable( pFmt );
3116                     SwTableLines &rLines = pTable->GetTabLines();
3117                     pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_START, NULL);
3118                     for(sal_uInt16 i = 0; i < rLines.Count(); i++)
3119                     {
3120                         SwTableLine* pLine = rLines.GetObject(i);
3121                         SwTableBoxes& rBoxes = pLine->GetTabBoxes();
3122                         for(sal_uInt16 k = 0; k < rBoxes.Count(); k++)
3123                         {
3124                             SwTableBox* pBox = rBoxes.GetObject(k);
3125                             const SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
3126                             const SvxBoxItem& rBox = pBoxFmt->GetBox();
3127                             if(
3128                                 (aTableBorderDistances.IsLeftDistanceValid && nLeftDistance !=   rBox.GetDistance( BOX_LINE_LEFT )) ||
3129                                 (aTableBorderDistances.IsRightDistanceValid && nRightDistance !=  rBox.GetDistance( BOX_LINE_RIGHT )) ||
3130                                 (aTableBorderDistances.IsTopDistanceValid && nTopDistance !=    rBox.GetDistance( BOX_LINE_TOP )) ||
3131                                 (aTableBorderDistances.IsBottomDistanceValid && nBottomDistance != rBox.GetDistance( BOX_LINE_BOTTOM )))
3132                             {
3133                                 SvxBoxItem aSetBox( rBox );
3134                                 SwFrmFmt* pSetBoxFmt = pBox->ClaimFrmFmt();
3135                                 if( aTableBorderDistances.IsLeftDistanceValid )
3136                                     aSetBox.SetDistance( nLeftDistance, BOX_LINE_LEFT );
3137                                 if( aTableBorderDistances.IsRightDistanceValid )
3138                                     aSetBox.SetDistance( nRightDistance, BOX_LINE_RIGHT );
3139                                 if( aTableBorderDistances.IsTopDistanceValid )
3140                                     aSetBox.SetDistance( nTopDistance, BOX_LINE_TOP );
3141                                 if( aTableBorderDistances.IsBottomDistanceValid )
3142                                     aSetBox.SetDistance( nBottomDistance, BOX_LINE_BOTTOM );
3143                                 pDoc->SetAttr( aSetBox, *pSetBoxFmt );
3144                             }
3145                         }
3146                     }
3147                     pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, NULL);
3148                 }
3149                 break;
3150 				case FN_UNO_TABLE_COLUMN_SEPARATORS:
3151 				{
3152                     UnoActionContext aContext(pFmt->GetDoc());
3153 					SwTable* pTable = SwTable::FindTable( pFmt );
3154 					lcl_SetTblSeparators(aValue, pTable, pTable->GetTabLines()[0]->GetTabBoxes()[0], sal_False, pFmt->GetDoc());
3155 				}
3156 				break;
3157 				case FN_UNO_TABLE_COLUMN_RELATIVE_SUM:/*_readonly_*/ break;
3158 				default:
3159 				{
3160 					SwAttrSet aSet(pFmt->GetAttrSet());
3161                     m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
3162 					pFmt->GetDoc()->SetAttr(aSet, *pFmt);
3163 				}
3164 			}
3165 		}
3166 	}
3167 	else if(bIsDescriptor)
3168 	{
3169 		String aPropertyName(rPropertyName);
3170         pTableProps->SetProperty( pEntry->nWID, pEntry->nMemberId, aValue);
3171 	}
3172 	else
3173 		throw uno::RuntimeException();
3174 }
3175 
getPropertyValue(const OUString & rPropertyName)3176 uno::Any SwXTextTable::getPropertyValue(const OUString& rPropertyName) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3177 {
3178 	vos::OGuard aGuard(Application::GetSolarMutex());
3179 	uno::Any aRet;
3180 	SwFrmFmt* pFmt = GetFrmFmt();
3181     const SfxItemPropertySimpleEntry* pEntry =
3182                                 m_pPropSet->getPropertyMap()->getByName(rPropertyName);
3183 	if(pFmt)
3184 	{
3185         if (!pEntry)
3186 			throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
3187 
3188         if(0xFF == pEntry->nMemberId)
3189 		{
3190             aRet = lcl_GetSpecialProperty(pFmt, pEntry );
3191 		}
3192 		else
3193 		{
3194             switch(pEntry->nWID)
3195 			{
3196                 case UNO_NAME_TABLE_NAME:
3197                 {
3198                     aRet <<= getName();
3199                 }
3200                 break;
3201                 case  FN_UNO_ANCHOR_TYPES:
3202                 case  FN_UNO_TEXT_WRAP:
3203                 case  FN_UNO_ANCHOR_TYPE:
3204                     ::sw::GetDefaultTextContentValue(
3205                             aRet, OUString(), pEntry->nWID);
3206                 break;
3207 				case FN_UNO_RANGE_ROW_LABEL:
3208 				{
3209 					sal_Bool bTemp = bFirstRowAsLabel;
3210 					aRet.setValue(&bTemp, ::getCppuBooleanType());
3211 				}
3212 				break;
3213 				case FN_UNO_RANGE_COL_LABEL:
3214 				{
3215 					sal_Bool bTemp = bFirstColumnAsLabel;
3216 					aRet.setValue(&bTemp, ::getCppuBooleanType());
3217 				}
3218 				break;
3219 				case FN_UNO_TABLE_BORDER:
3220 				{
3221 					SwDoc* pDoc = pFmt->GetDoc();
3222                     SwFrm* pFrm = SwIterator<SwFrm,SwFmt>::FirstElement( *pFmt );
3223 					//Tabellen ohne Layout (unsichtbare Header/Footer )
3224 					if( pFrm )
3225 					{
3226 						lcl_FormatTable(pFmt);
3227 						SwTable* pTable = SwTable::FindTable( pFmt );
3228 						SwTableLines &rLines = pTable->GetTabLines();
3229 
3230 						// hier muessen die Actions aufgehoben werden
3231 						UnoActionRemoveContext aRemoveContext(pDoc);
3232                         const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true);
3233 						const SwStartNode* pSttNd = pTLBox->GetSttNd();
3234 						SwPosition aPos(*pSttNd);
3235 						// Cursor in die obere linke Zelle des Ranges setzen
3236 						SwUnoCrsr* pUnoCrsr = pDoc->CreateUnoCrsr(aPos, sal_True);
3237 						pUnoCrsr->Move( fnMoveForward, fnGoNode );
3238 						pUnoCrsr->SetRemainInSection( sal_False );
3239 
3240                         const SwTableBox* pBRBox = lcl_FindCornerTableBox(rLines, false);
3241 						pUnoCrsr->SetMark();
3242                         const SwStartNode* pLastNd = pBRBox->GetSttNd();
3243                         pUnoCrsr->GetPoint()->nNode = *pLastNd;
3244 
3245 						pUnoCrsr->Move( fnMoveForward, fnGoNode );
3246                         SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
3247 						pCrsr->MakeBoxSels();
3248 
3249 						SfxItemSet aSet(pDoc->GetAttrPool(),
3250 										RES_BOX, RES_BOX,
3251 										SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
3252 										0);
3253                         aSet.Put(SvxBoxInfoItem( SID_ATTR_BORDER_INNER ));
3254 						pDoc->GetTabBorders(*pCrsr, aSet);
3255 						const SvxBoxInfoItem& rBoxInfoItem = (const SvxBoxInfoItem&)aSet.Get(SID_ATTR_BORDER_INNER);
3256 						const SvxBoxItem& rBox = (const SvxBoxItem&)aSet.Get(RES_BOX);
3257 
3258 					 	table::TableBorder aTableBorder;
3259 						aTableBorder.TopLine 				= lcl_SvxLineToLine(rBox.GetTop());
3260 						aTableBorder.IsTopLineValid 		= rBoxInfoItem.IsValid(VALID_TOP);
3261 						aTableBorder.BottomLine				= lcl_SvxLineToLine(rBox.GetBottom());
3262 						aTableBorder.IsBottomLineValid		= rBoxInfoItem.IsValid(VALID_BOTTOM);
3263 						aTableBorder.LeftLine				= lcl_SvxLineToLine(rBox.GetLeft());
3264 						aTableBorder.IsLeftLineValid		= rBoxInfoItem.IsValid(VALID_LEFT);
3265 						aTableBorder.RightLine				= lcl_SvxLineToLine(rBox.GetRight());
3266 						aTableBorder.IsRightLineValid		= rBoxInfoItem.IsValid(VALID_RIGHT );
3267 						aTableBorder.HorizontalLine			= lcl_SvxLineToLine(rBoxInfoItem.GetHori());
3268 						aTableBorder.IsHorizontalLineValid 	= rBoxInfoItem.IsValid(VALID_HORI);
3269 						aTableBorder.VerticalLine			= lcl_SvxLineToLine(rBoxInfoItem.GetVert());
3270 						aTableBorder.IsVerticalLineValid	= rBoxInfoItem.IsValid(VALID_VERT);
3271 						aTableBorder.Distance 				= TWIP_TO_MM100_UNSIGNED( rBox.GetDistance() );
3272 						aTableBorder.IsDistanceValid 		= rBoxInfoItem.IsValid(VALID_DISTANCE);
3273 						aRet.setValue(&aTableBorder, ::getCppuType((const table::TableBorder*)0));
3274 						delete pUnoCrsr;
3275 					}
3276 				}
3277 				break;
3278                 case FN_UNO_TABLE_BORDER_DISTANCES :
3279                 {
3280                     table::TableBorderDistances aTableBorderDistances( 0, sal_True, 0, sal_True, 0, sal_True, 0, sal_True ) ;
3281                     SwTable* pTable = SwTable::FindTable( pFmt );
3282                     const SwTableLines &rLines = pTable->GetTabLines();
3283                     bool bFirst = true;
3284                     sal_uInt16 nLeftDistance = 0;
3285                     sal_uInt16 nRightDistance = 0;
3286                     sal_uInt16 nTopDistance = 0;
3287                     sal_uInt16 nBottomDistance = 0;
3288 
3289                     for(sal_uInt16 i = 0; i < rLines.Count(); i++)
3290                     {
3291                         const SwTableLine* pLine = rLines.GetObject(i);
3292                         const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
3293                         for(sal_uInt16 k = 0; k < rBoxes.Count(); k++)
3294                         {
3295                             const SwTableBox* pBox = rBoxes.GetObject(k);
3296                             SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
3297                             const SvxBoxItem& rBox = pBoxFmt->GetBox();
3298                             if( bFirst )
3299                             {
3300                                 nLeftDistance =     TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_LEFT   ));
3301                                 nRightDistance =    TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_RIGHT  ));
3302                                 nTopDistance =      TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_TOP    ));
3303                                 nBottomDistance =   TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_BOTTOM ));
3304                                 bFirst = false;
3305                             }
3306                             else
3307                             {
3308                                 if( aTableBorderDistances.IsLeftDistanceValid &&
3309                                     nLeftDistance != TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_LEFT   )))
3310                                     aTableBorderDistances.IsLeftDistanceValid = sal_False;
3311                                 if( aTableBorderDistances.IsRightDistanceValid &&
3312                                     nRightDistance != TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_RIGHT   )))
3313                                     aTableBorderDistances.IsRightDistanceValid = sal_False;
3314                                 if( aTableBorderDistances.IsTopDistanceValid &&
3315                                     nTopDistance != TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_TOP   )))
3316                                     aTableBorderDistances.IsTopDistanceValid = sal_False;
3317                                 if( aTableBorderDistances.IsBottomDistanceValid &&
3318                                     nBottomDistance != TWIP_TO_MM100_UNSIGNED( rBox.GetDistance( BOX_LINE_BOTTOM   )))
3319                                     aTableBorderDistances.IsBottomDistanceValid = sal_False;
3320                             }
3321 
3322                         }
3323                         if( !aTableBorderDistances.IsLeftDistanceValid &&
3324                                 !aTableBorderDistances.IsRightDistanceValid &&
3325                                 !aTableBorderDistances.IsTopDistanceValid &&
3326                                 !aTableBorderDistances.IsBottomDistanceValid )
3327                             break;
3328                     }
3329                     if( aTableBorderDistances.IsLeftDistanceValid)
3330                         aTableBorderDistances.LeftDistance = nLeftDistance;
3331                     if( aTableBorderDistances.IsRightDistanceValid)
3332                         aTableBorderDistances.RightDistance  = nRightDistance;
3333                     if( aTableBorderDistances.IsTopDistanceValid)
3334                         aTableBorderDistances.TopDistance    = nTopDistance;
3335                     if( aTableBorderDistances.IsBottomDistanceValid)
3336                         aTableBorderDistances.BottomDistance = nBottomDistance;
3337 
3338                     aRet <<= aTableBorderDistances;
3339                 }
3340                 break;
3341 				case FN_UNO_TABLE_COLUMN_SEPARATORS:
3342 				{
3343 					SwTable* pTable = SwTable::FindTable( pFmt );
3344 					lcl_GetTblSeparators(aRet, pTable, pTable->GetTabLines()[0]->GetTabBoxes()[0], sal_False);
3345 				}
3346 				break;
3347 				case FN_UNO_TABLE_COLUMN_RELATIVE_SUM:
3348 					aRet <<= (sal_Int16) UNO_TABLE_COLUMN_SUM;
3349 				break;
3350 				case RES_ANCHOR:
3351 					//AnchorType ist readonly und maybevoid und wird nicht geliefert
3352 				break;
3353 				case FN_UNO_TEXT_SECTION:
3354 				{
3355 					SwTable* pTable = SwTable::FindTable( pFmt );
3356 					SwTableNode* pTblNode = pTable->GetTableNode();
3357 					SwSectionNode* pSectionNode =  pTblNode->FindSectionNode();
3358 					if(pSectionNode)
3359 					{
3360 						const SwSection& rSect = pSectionNode->GetSection();
3361 						uno::Reference< text::XTextSection >  xSect =
3362 										SwXTextSections::GetObject( *rSect.GetFmt() );
3363 						aRet <<= xSect;
3364 					}
3365 				}
3366 				break;
3367 				default:
3368 				{
3369 					const SwAttrSet& rSet = pFmt->GetAttrSet();
3370                     m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
3371 				}
3372 			}
3373 		}
3374 	}
3375 	else if(bIsDescriptor)
3376 	{
3377         const uno::Any* pAny = 0;
3378 		String aPropertyName(rPropertyName);
3379         if(!pTableProps->GetProperty(pEntry->nWID, pEntry->nMemberId, pAny))
3380 			throw lang::IllegalArgumentException();
3381 		else if(pAny)
3382 			aRet = *pAny;
3383 	}
3384 	else
3385 		throw uno::RuntimeException();
3386 	return aRet;
3387 }
3388 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)3389 void SwXTextTable::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3390 {
3391 	DBG_WARNING("not implemented");
3392 }
3393 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)3394 void SwXTextTable::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3395 {
3396 	DBG_WARNING("not implemented");
3397 }
3398 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)3399 void SwXTextTable::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3400 {
3401 	DBG_WARNING("not implemented");
3402 }
3403 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)3404 void SwXTextTable::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3405 {
3406 	DBG_WARNING("not implemented");
3407 }
3408 
getName(void)3409 OUString SwXTextTable::getName(void) throw( uno::RuntimeException )
3410 {
3411 	vos::OGuard aGuard(Application::GetSolarMutex());
3412 	String sRet;
3413 	SwFrmFmt* pFmt = GetFrmFmt();
3414 	if(!pFmt && !bIsDescriptor)
3415 		throw uno::RuntimeException();
3416 	if(pFmt)
3417 	{
3418 		sRet = pFmt->GetName();
3419 	}
3420 	else
3421 		sRet = m_sTableName;
3422 	return sRet;
3423 }
3424 
setName(const OUString & rName)3425 void SwXTextTable::setName(const OUString& rName) throw( uno::RuntimeException )
3426 {
3427 	vos::OGuard aGuard(Application::GetSolarMutex());
3428 	SwFrmFmt* pFmt = GetFrmFmt();
3429 	String sNewTblName(rName);
3430 	if((!pFmt && !bIsDescriptor) ||
3431 		!sNewTblName.Len() ||
3432 			STRING_NOTFOUND != sNewTblName.Search('.') ||
3433 				STRING_NOTFOUND != sNewTblName.Search(' ')  )
3434 		throw uno::RuntimeException();
3435 
3436 	if(pFmt)
3437 	{
3438 		const String aOldName( pFmt->GetName() );
3439 		sal_Bool bNameFound = sal_False;
3440 		SwFrmFmt* pTmpFmt;
3441 		const SwFrmFmts* pTbl = pFmt->GetDoc()->GetTblFrmFmts();
3442 		for( sal_uInt16 i = pTbl->Count(); i; )
3443 			if( !( pTmpFmt = (*pTbl)[ --i ] )->IsDefault() &&
3444 				pTmpFmt->GetName() == sNewTblName &&
3445 							pFmt->GetDoc()->IsUsed( *pTmpFmt ))
3446 			{
3447 				bNameFound = sal_True;
3448 				break;
3449 			}
3450 
3451 		if(bNameFound)
3452 		{
3453 			throw uno::RuntimeException();
3454 		}
3455 		pFmt->SetName( sNewTblName );
3456 
3457 
3458 		SwStartNode *pStNd;
3459 		SwNodeIndex aIdx( *pFmt->GetDoc()->GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
3460 		while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
3461 		{
3462 			aIdx++;
3463             SwNode *const pNd = & aIdx.GetNode();
3464 			if ( pNd->IsOLENode() &&
3465 				aOldName == ((SwOLENode*)pNd)->GetChartTblName() )
3466 			{
3467 				((SwOLENode*)pNd)->SetChartTblName( sNewTblName );
3468 
3469 				((SwOLENode*)pNd)->GetOLEObj();
3470 
3471                 SwTable* pTable = SwTable::FindTable( pFmt );
3472                 //TL_CHART2: chart needs to be notfied about name changes
3473                 pFmt->GetDoc()->UpdateCharts( pTable->GetFrmFmt()->GetName() );
3474 			}
3475 			aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
3476 		}
3477 		pFmt->GetDoc()->SetModified();
3478 	}
3479 	else
3480 		m_sTableName = sNewTblName;
3481 }
3482 
getRowCount(void)3483 sal_uInt16 SwXTextTable::getRowCount(void)
3484 {
3485 	vos::OGuard aGuard(Application::GetSolarMutex());
3486 	sal_Int16 nRet = 0;
3487 	SwFrmFmt* pFmt = GetFrmFmt();
3488 	if(pFmt)
3489 	{
3490 		SwTable* pTable = SwTable::FindTable( pFmt );
3491 		if(!pTable->IsTblComplex())
3492 		{
3493 			nRet = pTable->GetTabLines().Count();
3494 		}
3495 	}
3496 	return nRet;
3497 }
3498 
getColumnCount(void)3499 sal_uInt16 SwXTextTable::getColumnCount(void)
3500 {
3501 	vos::OGuard aGuard(Application::GetSolarMutex());
3502 	SwFrmFmt* pFmt = GetFrmFmt();
3503 	sal_Int16 nRet = 0;
3504 	if(pFmt)
3505 	{
3506 		SwTable* pTable = SwTable::FindTable( pFmt );
3507 		if(!pTable->IsTblComplex())
3508 		{
3509 			SwTableLines& rLines = pTable->GetTabLines();
3510 			SwTableLine* pLine = rLines.GetObject(0);
3511 			nRet = pLine->GetTabBoxes().Count();
3512 		}
3513 	}
3514 	return nRet;
3515 }
3516 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)3517 void SwXTextTable::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
3518 {
3519 	if(pOld && pOld->Which() == RES_REMOVE_UNO_OBJECT &&
3520 		(void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
3521 			((SwModify*)GetRegisteredIn())->Remove(this);
3522 	else
3523 		ClientModify(this, pOld, pNew);
3524 	if(!GetRegisteredIn())
3525 	{
3526 		aLstnrCntnr.Disposing();
3527 		aChartLstnrCntnr.Disposing();
3528 	}
3529 	else
3530 		aChartLstnrCntnr.ChartDataChanged();
3531 }
3532 
getImplementationName(void)3533 OUString SAL_CALL SwXTextTable::getImplementationName(void) throw( uno::RuntimeException )
3534 {
3535 	return C2U("SwXTextTable");
3536 }
3537 
supportsService(const OUString & rServiceName)3538 sal_Bool SwXTextTable::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
3539 {
3540 	String sServiceName(rServiceName);
3541 	return (sServiceName.EqualsAscii("com.sun.star.document.LinkTarget")  ||
3542             sServiceName.EqualsAscii("com.sun.star.text.TextTable")  ||
3543             sServiceName.EqualsAscii("com.sun.star.text.TextContent") ||
3544             sServiceName.EqualsAscii("com.sun.star.text.TextSortable"));
3545 }
3546 
getSupportedServiceNames(void)3547 uno::Sequence< OUString > SwXTextTable::getSupportedServiceNames(void) throw( uno::RuntimeException )
3548 {
3549     uno::Sequence< OUString > aRet(4);
3550 	OUString* pArr = aRet.getArray();
3551     pArr[0] = C2U("com.sun.star.document.LinkTarget");
3552     pArr[1] = C2U("com.sun.star.text.TextTable");
3553 	pArr[2] = C2U("com.sun.star.text.TextContent");
3554     pArr[2] = C2U("com.sun.star.text.TextSortable");
3555 	return aRet;
3556 }
3557 
3558 /******************************************************************
3559  *
3560  ******************************************************************/
3561 
getUnoTunnelId()3562 const uno::Sequence< sal_Int8 > & SwXCellRange::getUnoTunnelId()
3563 {
3564     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
3565 	return aSeq;
3566 }
3567 
getSomething(const uno::Sequence<sal_Int8> & rId)3568 sal_Int64 SAL_CALL SwXCellRange::getSomething( const uno::Sequence< sal_Int8 >& rId )
3569 	throw(uno::RuntimeException)
3570 {
3571     if( rId.getLength() == 16
3572         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
3573 										rId.getConstArray(), 16 ) )
3574     {
3575 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
3576     }
3577 	return 0;
3578 }
3579 
3580 TYPEINIT1(SwXCellRange, SwClient);
3581 
getImplementationName(void)3582 OUString SwXCellRange::getImplementationName(void) throw( uno::RuntimeException )
3583 {
3584 	return C2U("SwXCellRange");
3585 }
3586 
supportsService(const OUString & rServiceName)3587 sal_Bool SwXCellRange::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
3588 {
3589 	return
3590 		rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.text.CellRange" ) ) ||
3591 	 	rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.CharacterProperties" ) ) ||
3592         rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.CharacterPropertiesAsian" ) ) ||
3593         rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.CharacterPropertiesComplex") ) ||
3594         rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.ParagraphProperties" ) ) ||
3595         rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.ParagraphPropertiesAsian" ) ) ||
3596         rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.style.ParagraphPropertiesComplex" ) );
3597 }
3598 
getSupportedServiceNames(void)3599 uno::Sequence< OUString > SwXCellRange::getSupportedServiceNames(void) throw( uno::RuntimeException )
3600 {
3601     uno::Sequence< OUString > aRet(7);
3602 	OUString* pArray = aRet.getArray();
3603 	pArray[0] = C2U("com.sun.star.text.CellRange");
3604  	pArray[1] = C2U("com.sun.star.style.CharacterProperties");
3605     pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
3606     pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
3607     pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
3608     pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
3609     pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
3610 	return aRet;
3611 }
3612 
3613 
SwXCellRange(SwUnoCrsr * pCrsr,SwFrmFmt & rFrmFmt,SwRangeDescriptor & rDesc)3614 SwXCellRange::SwXCellRange(SwUnoCrsr* pCrsr, SwFrmFmt& rFrmFmt,
3615 	SwRangeDescriptor& rDesc)
3616 	:
3617 	SwClient(&rFrmFmt),
3618 	aCursorDepend(this, pCrsr),
3619 	aChartLstnrCntnr((cppu::OWeakObject*)this),
3620 	aRgDesc(rDesc),
3621     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_RANGE)),
3622 	pTblCrsr(pCrsr),
3623 	bFirstRowAsLabel(sal_False),
3624 	bFirstColumnAsLabel(sal_False)
3625 {
3626     aRgDesc.Normalize();
3627 }
3628 
~SwXCellRange()3629 SwXCellRange::~SwXCellRange()
3630 {
3631     vos::OGuard aGuard(Application::GetSolarMutex());
3632     delete pTblCrsr;
3633 }
3634 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)3635 uno::Reference< table::XCell >  SwXCellRange::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow)
3636 	throw( uno::RuntimeException, lang::IndexOutOfBoundsException )
3637 {
3638 	vos::OGuard aGuard(Application::GetSolarMutex());
3639 	uno::Reference< table::XCell >  aRet;
3640 	SwFrmFmt* pFmt = GetFrmFmt();
3641 	if(pFmt)
3642 	{
3643 		if(nColumn >= 0 && nRow >= 0 &&
3644 			 getColumnCount() > nColumn && getRowCount() > nRow )
3645 		{
3646 			SwXCell* pXCell = lcl_CreateXCell(pFmt,
3647 					aRgDesc.nLeft + nColumn, aRgDesc.nTop + nRow);
3648 			if(pXCell)
3649 				aRet = pXCell;
3650 		}
3651 	}
3652 	if(!aRet.is())
3653 		throw lang::IndexOutOfBoundsException();
3654 	return aRet;
3655 }
3656 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)3657 uno::Reference< table::XCellRange >  SwXCellRange::getCellRangeByPosition(
3658 		sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
3659 	throw( uno::RuntimeException, lang::IndexOutOfBoundsException )
3660 {
3661 	vos::OGuard aGuard(Application::GetSolarMutex());
3662 	uno::Reference< table::XCellRange >  aRet;
3663 	SwFrmFmt* pFmt = GetFrmFmt();
3664 	if(pFmt && getColumnCount() > nRight && getRowCount() > nBottom &&
3665 		nLeft <= nRight && nTop <= nBottom
3666 		&& nLeft >= 0 && nRight >= 0 && nTop >= 0 && nBottom >= 0 )
3667 	{
3668 		SwTable* pTable = SwTable::FindTable( pFmt );
3669 		if(!pTable->IsTblComplex())
3670 		{
3671 			SwRangeDescriptor aNewDesc;
3672             aNewDesc.nTop    = nTop + aRgDesc.nTop;
3673             aNewDesc.nBottom = nBottom + aRgDesc.nTop;
3674             aNewDesc.nLeft   = nLeft + aRgDesc.nLeft;
3675             aNewDesc.nRight  = nRight + aRgDesc.nLeft;
3676             aNewDesc.Normalize();
3677 			String sTLName = lcl_GetCellName(aNewDesc.nLeft, aNewDesc.nTop);
3678 			String sBRName = lcl_GetCellName(aNewDesc.nRight, aNewDesc.nBottom);
3679             const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
3680 			if(pTLBox)
3681 			{
3682 				// hier muessen die Actions aufgehoben
3683 				UnoActionRemoveContext aRemoveContext(pFmt->GetDoc());
3684 				const SwStartNode* pSttNd = pTLBox->GetSttNd();
3685 				SwPosition aPos(*pSttNd);
3686 				// Cursor in die obere linke Zelle des Ranges setzen
3687 				SwUnoCrsr* pUnoCrsr = pFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
3688 				pUnoCrsr->Move( fnMoveForward, fnGoNode );
3689 				pUnoCrsr->SetRemainInSection( sal_False );
3690                 const SwTableBox* pBRBox = pTable->GetTblBox( sBRName );
3691 				if(pBRBox)
3692 				{
3693 					pUnoCrsr->SetMark();
3694 					pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd();
3695 					pUnoCrsr->Move( fnMoveForward, fnGoNode );
3696                     SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
3697 					pCrsr->MakeBoxSels();
3698 					// pUnoCrsr wird uebergeben und nicht geloescht
3699 					SwXCellRange* pCellRange = new SwXCellRange(pUnoCrsr, *pFmt, aNewDesc);
3700 					aRet = pCellRange;
3701 				}
3702 				else
3703 					delete pUnoCrsr;
3704 			}
3705 		}
3706 	}
3707 	if(!aRet.is())
3708 		throw lang::IndexOutOfBoundsException();
3709 	return aRet;
3710 
3711 }
3712 
getCellRangeByName(const OUString & rRange)3713 uno::Reference< table::XCellRange >  SwXCellRange::getCellRangeByName(const OUString& rRange)
3714 		throw( uno::RuntimeException )
3715 {
3716 	vos::OGuard aGuard(Application::GetSolarMutex());
3717 	String sRange(rRange);
3718 	String sTLName(sRange.GetToken(0, ':'));
3719 	String sBRName(sRange.GetToken(1, ':'));
3720 	if(!sTLName.Len() || !sBRName.Len())
3721 		throw uno::RuntimeException();
3722 	SwRangeDescriptor aDesc;
3723     aDesc.nTop = aDesc.nLeft = aDesc.nBottom = aDesc.nRight = -1;
3724     lcl_GetCellPosition( sTLName, aDesc.nLeft, aDesc.nTop );
3725     lcl_GetCellPosition( sBRName, aDesc.nRight, aDesc.nBottom );
3726     aDesc.Normalize();
3727 	return getCellRangeByPosition(aDesc.nLeft - aRgDesc.nLeft, aDesc.nTop - aRgDesc.nTop,
3728 				aDesc.nRight - aRgDesc.nLeft, aDesc.nBottom - aRgDesc.nTop);
3729 }
3730 
getPropertySetInfo(void)3731 uno::Reference< beans::XPropertySetInfo >  SwXCellRange::getPropertySetInfo(void) throw( uno::RuntimeException )
3732 {
3733     static uno::Reference< beans::XPropertySetInfo >  xRef = m_pPropSet->getPropertySetInfo();
3734 	return xRef;
3735 }
3736 
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)3737 void SwXCellRange::setPropertyValue(const OUString& rPropertyName,
3738 	const uno::Any& aValue) throw( beans::UnknownPropertyException,
3739 		beans::PropertyVetoException, lang::IllegalArgumentException,
3740 			lang::WrappedTargetException, uno::RuntimeException )
3741 {
3742 	vos::OGuard aGuard(Application::GetSolarMutex());
3743 	SwFrmFmt* pFmt = GetFrmFmt();
3744 	if(pFmt)
3745 	{
3746 		/* ASK OLIVER
3747 		lcl_FormatTable(pFmt);*/
3748         const SfxItemPropertySimpleEntry* pEntry =
3749                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
3750         if(pEntry)
3751 		{
3752             if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
3753                 throw beans::PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
3754 
3755 			SwDoc* pDoc = pTblCrsr->GetDoc();
3756             {
3757                 // remove actions to enable box selection
3758                 UnoActionRemoveContext aRemoveContext(pDoc);
3759             }
3760             SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pTblCrsr);
3761             pCrsr->MakeBoxSels();
3762             switch(pEntry->nWID )
3763 			{
3764 				case FN_UNO_TABLE_CELL_BACKGROUND:
3765 				{
3766                     SvxBrushItem aBrush( RES_BACKGROUND );
3767                     pDoc->GetBoxAttr( *pTblCrsr, aBrush );
3768                     ((SfxPoolItem&)aBrush).PutValue(aValue, pEntry->nMemberId);
3769 					pDoc->SetBoxAttr( *pTblCrsr, aBrush );
3770 
3771 				}
3772 				break;
3773                 case RES_BOX :
3774                 {
3775                     SfxItemSet aSet(pDoc->GetAttrPool(),
3776                                     RES_BOX, RES_BOX,
3777                                     SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
3778                                     0);
3779                     SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
3780                     aBoxInfo.SetValid(0xff, sal_False);
3781                     sal_uInt8 nValid = 0;
3782                     switch(pEntry->nMemberId & ~CONVERT_TWIPS)
3783                     {
3784                         case  LEFT_BORDER :             nValid = VALID_LEFT; break;
3785                         case  RIGHT_BORDER:             nValid = VALID_RIGHT; break;
3786                         case  TOP_BORDER  :             nValid = VALID_TOP; break;
3787                         case  BOTTOM_BORDER:            nValid = VALID_BOTTOM; break;
3788                         case  LEFT_BORDER_DISTANCE :
3789                         case  RIGHT_BORDER_DISTANCE:
3790                         case  TOP_BORDER_DISTANCE  :
3791                         case  BOTTOM_BORDER_DISTANCE:
3792                             nValid = VALID_DISTANCE;
3793                         break;
3794                     }
3795                     aBoxInfo.SetValid(nValid, sal_True);
3796 
3797 
3798                     aSet.Put(aBoxInfo);
3799                     pDoc->GetTabBorders(*pCrsr, aSet);
3800 
3801                     aSet.Put(aBoxInfo);
3802                     SvxBoxItem aBoxItem((const SvxBoxItem&)aSet.Get(RES_BOX));
3803                     ((SfxPoolItem&)aBoxItem).PutValue(aValue, pEntry->nMemberId);
3804                     aSet.Put(aBoxItem);
3805                     pDoc->SetTabBorders( *pTblCrsr, aSet );
3806                 }
3807                 break;
3808                 case RES_BOXATR_FORMAT:
3809 				{
3810 					SfxUInt32Item aNumberFormat(RES_BOXATR_FORMAT);
3811 					((SfxPoolItem&)aNumberFormat).PutValue(aValue, 0);
3812 					pDoc->SetBoxAttr( *pCrsr, aNumberFormat);
3813 				}
3814 				break;
3815 				case FN_UNO_RANGE_ROW_LABEL:
3816 				{
3817 					sal_Bool bTmp = *(sal_Bool*)aValue.getValue();
3818 					if(bFirstRowAsLabel != bTmp)
3819 					{
3820 						aChartLstnrCntnr.ChartDataChanged();
3821 						bFirstRowAsLabel = bTmp;
3822 					}
3823 				}
3824 				break;
3825 				case FN_UNO_RANGE_COL_LABEL:
3826 				{
3827 					sal_Bool bTmp = *(sal_Bool*)aValue.getValue();
3828 					if(bFirstColumnAsLabel != bTmp)
3829 					{
3830 						aChartLstnrCntnr.ChartDataChanged();
3831 						bFirstColumnAsLabel = bTmp;
3832 					}
3833 				}
3834 				break;
3835                 default:
3836 				{
3837                     SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID );
3838                     SwUnoCursorHelper::GetCrsrAttr(pCrsr->GetSelRing(),
3839                             aItemSet);
3840 
3841                     if (!SwUnoCursorHelper::SetCursorPropertyValue(
3842                             *pEntry, aValue, pCrsr->GetSelRing(), aItemSet))
3843                     {
3844                         m_pPropSet->setPropertyValue(*pEntry, aValue, aItemSet);
3845                     }
3846                     SwUnoCursorHelper::SetCrsrAttr(pCrsr->GetSelRing(),
3847                             aItemSet, nsSetAttrMode::SETATTR_DEFAULT, true);
3848 				}
3849 			}
3850 		}
3851 		else
3852 	        throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
3853 	}
3854 }
3855 
getPropertyValue(const OUString & rPropertyName)3856 uno::Any SwXCellRange::getPropertyValue(const OUString& rPropertyName) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3857 {
3858 	vos::OGuard aGuard(Application::GetSolarMutex());
3859 	uno::Any aRet;
3860 	SwFrmFmt* pFmt = GetFrmFmt();
3861 	if(pFmt)
3862 	{
3863 		/* ASK OLIVER
3864 		lcl_FormatTable(pFmt);*/
3865         const SfxItemPropertySimpleEntry* pEntry =
3866                                     m_pPropSet->getPropertyMap()->getByName(rPropertyName);
3867         if(pEntry)
3868 		{
3869             switch(pEntry->nWID )
3870 			{
3871 				case FN_UNO_TABLE_CELL_BACKGROUND:
3872 				{
3873                     SvxBrushItem aBrush( RES_BACKGROUND );
3874                     if(pTblCrsr->GetDoc()->GetBoxAttr( *pTblCrsr, aBrush ))
3875                         aBrush.QueryValue(aRet, pEntry->nMemberId);
3876 
3877 				}
3878 				break;
3879                 case RES_BOX :
3880                 {
3881                     SwDoc* pDoc = pTblCrsr->GetDoc();
3882                     SfxItemSet aSet(pDoc->GetAttrPool(),
3883                                     RES_BOX, RES_BOX,
3884                                     SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
3885                                     0);
3886                     aSet.Put(SvxBoxInfoItem( SID_ATTR_BORDER_INNER ));
3887                     pDoc->GetTabBorders(*pTblCrsr, aSet);
3888                     const SvxBoxItem& rBoxItem = ((const SvxBoxItem&)aSet.Get(RES_BOX));
3889                     rBoxItem.QueryValue(aRet, pEntry->nMemberId);
3890                 }
3891                 break;
3892                 case RES_BOXATR_FORMAT:
3893 					//GetAttr fuer Tabellenselektion am Doc fehlt noch
3894 					DBG_WARNING("not implemented");
3895 				break;
3896 				case FN_UNO_PARA_STYLE:
3897 				{
3898                     SwFmtColl *const pTmpFmt =
3899                         SwUnoCursorHelper::GetCurTxtFmtColl(*pTblCrsr, sal_False);
3900 					OUString sRet;
3901 					if(pFmt)
3902 						sRet = pTmpFmt->GetName();
3903 					aRet <<= sRet;
3904 				}
3905 				break;
3906 				case FN_UNO_RANGE_ROW_LABEL:
3907 				{
3908 					sal_Bool bTemp = bFirstRowAsLabel;
3909 					aRet.setValue(&bTemp, ::getCppuBooleanType());
3910 				}
3911 				break;
3912 				case FN_UNO_RANGE_COL_LABEL:
3913 				{
3914 					sal_Bool bTemp = bFirstColumnAsLabel;
3915 					aRet.setValue(&bTemp, ::getCppuBooleanType());
3916 				}
3917 				break;
3918 				default:
3919 				{
3920 					SfxItemSet aSet(pTblCrsr->GetDoc()->GetAttrPool(),
3921 						RES_CHRATR_BEGIN, 		RES_FRMATR_END -1,
3922 						RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
3923 						RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
3924 						0L);
3925 					// erstmal die Attribute des Cursors
3926                     SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pTblCrsr);
3927                     SwUnoCursorHelper::GetCrsrAttr(pCrsr->GetSelRing(), aSet);
3928                     m_pPropSet->getPropertyValue(*pEntry, aSet, aRet);
3929 				}
3930 			}
3931 		}
3932 		else
3933 	       throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
3934 	}
3935 	return aRet;
3936 }
3937 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)3938 void SwXCellRange::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3939 {
3940 	DBG_WARNING("not implemented");
3941 }
3942 
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)3943 void SwXCellRange::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3944 {
3945 	DBG_WARNING("not implemented");
3946 }
3947 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)3948 void SwXCellRange::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3949 {
3950 	DBG_WARNING("not implemented");
3951 }
3952 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)3953 void SwXCellRange::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
3954 {
3955 	DBG_WARNING("not implemented");
3956 }
3957 
GetDataSequence(uno::Sequence<uno::Any> * pAnySeq,uno::Sequence<OUString> * pTxtSeq,uno::Sequence<double> * pDblSeq,sal_Bool bForceNumberResults)3958 void SwXCellRange::GetDataSequence(
3959         uno::Sequence< uno::Any >   *pAnySeq,   //-> first pointer != 0 is used
3960         uno::Sequence< OUString >   *pTxtSeq,   //-> as output sequence
3961         uno::Sequence< double >     *pDblSeq,   //-> (previous data gets overwritten)
3962         sal_Bool bForceNumberResults )          //-> when 'true' requires to make an
3963                                                 // extra effort to return a value different
3964                                                 // from 0 even if the cell is formatted to text
3965     throw (uno::RuntimeException)
3966 {
3967     vos::OGuard aGuard(Application::GetSolarMutex());
3968 
3969     // compare to SwXCellRange::getDataArray (note different return types though)
3970 
3971     sal_Int16 nRowCount = getRowCount();
3972     sal_Int16 nColCount = getColumnCount();
3973     //
3974     if(!nRowCount || !nColCount)
3975     {
3976         uno::RuntimeException aRuntime;
3977         aRuntime.Message = C2U("Table too complex");
3978         throw aRuntime;
3979     }
3980 
3981     sal_Int32 nSize = nRowCount * nColCount;
3982     if (pAnySeq)
3983         pAnySeq->realloc( nSize );
3984     else if (pTxtSeq)
3985         pTxtSeq->realloc( nSize );
3986     else if (pDblSeq)
3987         pDblSeq->realloc( nSize );
3988     else
3989     {
3990         DBG_ERROR( "argument missing" );
3991         return;
3992     }
3993     uno::Any   *pAnyData = pAnySeq ? pAnySeq->getArray() : 0;
3994     OUString   *pTxtData = pTxtSeq ? pTxtSeq->getArray() : 0;
3995     double     *pDblData = pDblSeq ? pDblSeq->getArray() : 0;
3996 
3997     sal_Int32 nDtaCnt = 0;
3998     SwFrmFmt* pFmt = GetFrmFmt();
3999     if(pFmt)
4000     {
4001         double fNan;
4002         ::rtl::math::setNan( & fNan );
4003 
4004         uno::Reference< table::XCell > xCellRef;
4005         for(sal_uInt16 nRow = 0; nRow < nRowCount; nRow++)
4006         {
4007             for(sal_uInt16 nCol = 0; nCol < nColCount; nCol++)
4008             {
4009                 SwXCell * pXCell = lcl_CreateXCell(pFmt,
4010                                     aRgDesc.nLeft + nCol,
4011                                     aRgDesc.nTop + nRow);
4012                 //! keep (additional) reference to object to prevent implicit destruction
4013                 //! in following UNO calls (when object will get referenced)
4014                 xCellRef = pXCell;
4015                 SwTableBox * pBox = pXCell ? pXCell->GetTblBox() : 0;
4016                 if(!pBox)
4017                 {
4018                     throw uno::RuntimeException();
4019                 }
4020                 else
4021                 {
4022                     if (pAnyData)
4023                     {
4024                         // check if table box value item is set
4025                         sal_Bool bIsNum = pBox->GetFrmFmt()->GetItemState( RES_BOXATR_VALUE, sal_False ) == SFX_ITEM_SET;
4026                         //sal_uLong nNdPos = pBox->IsValidNumTxtNd( sal_True );
4027                         if (!bIsNum/* && ULONG_MAX == nNdPos*/)
4028                             pAnyData[nDtaCnt++] <<= lcl_getString(*pXCell);
4029                         else
4030                             pAnyData[nDtaCnt++] <<= lcl_getValue(*pXCell);
4031                     }
4032                     else if (pTxtData)
4033                         pTxtData[nDtaCnt++] = lcl_getString(*pXCell);
4034                     else if (pDblData)
4035                     {
4036                         double fVal = fNan;
4037                         if (!bForceNumberResults || table::CellContentType_TEXT != pXCell->getType())
4038                             fVal = lcl_getValue(*pXCell);
4039                         else
4040                         {
4041                             DBG_ASSERT( table::CellContentType_TEXT == pXCell->getType(),
4042                                     "this branch of 'if' is only for text formatted cells" );
4043 
4044                             // now we'll try to get a useful numerical value
4045                             // from the text in the cell...
4046 
4047                             sal_uInt32 nFIndex;
4048                             SvNumberFormatter* pNumFormatter = pTblCrsr->GetDoc()->GetNumberFormatter();
4049 
4050                             // look for SwTblBoxNumFormat value in parents as well
4051                             const SfxPoolItem* pItem;
4052 							SwFrmFmt *pBoxFmt = pXCell->GetTblBox()->GetFrmFmt();
4053                             SfxItemState eState = pBoxFmt->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, sal_True, &pItem);
4054 
4055                             if (eState == SFX_ITEM_SET)
4056                             {
4057                                 // please note that the language of the numberformat
4058                                 // is implicitly coded into the below value as well
4059                                 nFIndex = ((SwTblBoxNumFormat*)pItem)->GetValue();
4060 
4061 								// since the current value indicates a text format but the call
4062 								// to 'IsNumberFormat' below won't work for text formats
4063 								// we need to get rid of the part that indicates the text format.
4064 								// According to ER this can be done like this:
4065 								nFIndex -= (nFIndex % SV_COUNTRY_LANGUAGE_OFFSET);
4066                             }
4067                             else
4068                             {
4069                                 // system language is probably not the best possible choice
4070                                 // but since we have to guess anyway (because the language of at
4071                                 // the text is NOT the one used for the number format!)
4072                                 // it is at least conform to to what is used in
4073                                 // SwTableShell::Execute when
4074                                 // SID_ATTR_NUMBERFORMAT_VALUE is set...
4075                                 LanguageType eLang = LANGUAGE_SYSTEM;
4076                                 nFIndex = pNumFormatter->GetStandardIndex( eLang );
4077                             }
4078 
4079                             OUString aTxt( lcl_getString(*pXCell) );
4080                             double fTmp;
4081                             if (pNumFormatter->IsNumberFormat( aTxt, nFIndex, fTmp ))
4082                                 fVal = fTmp;
4083                         }
4084                         pDblData[nDtaCnt++] = fVal;
4085                     }
4086                     else {
4087                         DBG_ERROR( "output sequence missing" );
4088                     }
4089                 }
4090             }
4091         }
4092     }
4093     DBG_ASSERT( nDtaCnt == nSize, "size mismatch. Invalid cell range?" );
4094     if (pAnySeq)
4095         pAnySeq->realloc( nDtaCnt );
4096     else if (pTxtSeq)
4097         pTxtSeq->realloc( nDtaCnt );
4098     else if (pDblSeq)
4099         pDblSeq->realloc( nDtaCnt );
4100 }
4101 
getDataArray()4102 uno::Sequence< uno::Sequence< uno::Any > > SAL_CALL SwXCellRange::getDataArray()
4103     throw (uno::RuntimeException)
4104 {
4105     // see SwXCellRange::getData also
4106     // also see SwXCellRange::GetDataSequence
4107 
4108 	vos::OGuard aGuard(Application::GetSolarMutex());
4109 	sal_Int16 nRowCount = getRowCount();
4110 	sal_Int16 nColCount = getColumnCount();
4111 	//
4112 	if(!nRowCount || !nColCount)
4113 	{
4114 		uno::RuntimeException aRuntime;
4115 		aRuntime.Message = C2U("Table too complex");
4116 		throw aRuntime;
4117 	}
4118     uno::Sequence< uno::Sequence< uno::Any > > aRowSeq(nRowCount);
4119 	SwFrmFmt* pFmt = GetFrmFmt();
4120 	if(pFmt)
4121 	{
4122         uno::Sequence< uno::Any >* pRowArray = aRowSeq.getArray();
4123         uno::Reference< table::XCell > xCellRef;
4124         for(sal_uInt16 nRow = 0; nRow < nRowCount; nRow++)
4125 		{
4126             uno::Sequence< uno::Any > aColSeq(nColCount);
4127             uno::Any * pColArray = aColSeq.getArray();
4128             for(sal_uInt16 nCol = 0; nCol < nColCount; nCol++)
4129 			{
4130                 SwXCell * pXCell = lcl_CreateXCell(pFmt,
4131                                     aRgDesc.nLeft + nCol,
4132                                     aRgDesc.nTop + nRow);
4133                 //! keep (additional) reference to object to prevent implicit destruction
4134                 //! in following UNO calls (when object will get referenced)
4135                 xCellRef = pXCell;
4136                 SwTableBox * pBox = pXCell ? pXCell->GetTblBox() : 0;
4137                 if(!pBox)
4138 				{
4139 					throw uno::RuntimeException();
4140 				}
4141                 else
4142                 {
4143 					// check if table box value item is set
4144 					SwFrmFmt* pBoxFmt = pBox->GetFrmFmt();
4145 					sal_Bool bIsNum = pBoxFmt->GetItemState( RES_BOXATR_VALUE, sal_False ) == SFX_ITEM_SET;
4146 					//const SfxPoolItem* pItem;
4147 					//SwDoc* pDoc = pXCell->GetDoc();
4148 					//sal_Bool bIsText = (SFX_ITEM_SET != pBoxFmt->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, sal_True, &pItem)
4149 					//			||  pDoc->GetNumberFormatter()->IsTextFormat(((SwTblBoxNumFormat*)pItem)->GetValue())
4150 					//			||	((SwTblBoxNumFormat*)pItem)->GetValue() == NUMBERFORMAT_TEXT);
4151 
4152                     if(!bIsNum/*bIsText*/)
4153                         pColArray[nCol] <<= lcl_getString(*pXCell);
4154                     else
4155                         pColArray[nCol] <<= lcl_getValue(*pXCell);
4156                 }
4157 			}
4158             pRowArray[nRow] = aColSeq;
4159 		}
4160 	}
4161 	return aRowSeq;
4162 }
4163 
setDataArray(const uno::Sequence<uno::Sequence<uno::Any>> & rArray)4164 void SAL_CALL SwXCellRange::setDataArray(
4165         const uno::Sequence< uno::Sequence< uno::Any > >& rArray )
4166     throw (uno::RuntimeException)
4167 {
4168     // see SwXCellRange::setData also
4169 
4170 	vos::OGuard aGuard(Application::GetSolarMutex());
4171 	sal_Int16 nRowCount = getRowCount();
4172 	sal_Int16 nColCount = getColumnCount();
4173 	if(!nRowCount || !nColCount)
4174 	{
4175 		uno::RuntimeException aRuntime;
4176 		aRuntime.Message = C2U("Table too complex");
4177 		throw aRuntime;
4178 	}
4179 	SwFrmFmt* pFmt = GetFrmFmt();
4180 	if(pFmt )
4181 	{
4182         if(rArray.getLength() != nRowCount)
4183 		{
4184 			throw uno::RuntimeException();
4185 		}
4186         const uno::Sequence< uno::Any >* pRowArray = rArray.getConstArray();
4187         for(sal_uInt16 nRow = 0; nRow < nRowCount; nRow++)
4188 		{
4189             const uno::Sequence< uno::Any >& rColSeq = pRowArray[nRow];
4190             if(rColSeq.getLength() != nColCount)
4191 			{
4192 				throw uno::RuntimeException();
4193 			}
4194             const uno::Any * pColArray = rColSeq.getConstArray();
4195             uno::Reference< table::XCell > xCellRef;
4196             for(sal_uInt16 nCol = 0; nCol < nColCount; nCol++)
4197 			{
4198                 SwXCell * pXCell = lcl_CreateXCell(pFmt,
4199                                     aRgDesc.nLeft + nCol,
4200                                     aRgDesc.nTop + nRow);
4201                 //! keep (additional) reference to object to prevent implicit destruction
4202                 //! in following UNO calls (when object will get referenced)
4203                 xCellRef = pXCell;
4204                 SwTableBox * pBox = pXCell ? pXCell->GetTblBox() : 0;
4205                 if(!pBox)
4206 				{
4207 					throw uno::RuntimeException();
4208 				}
4209                 else
4210                 {
4211                     const uno::Any &rAny = pColArray[nCol];
4212                     if (uno::TypeClass_STRING == rAny.getValueTypeClass())
4213                         lcl_setString( *pXCell, *(rtl::OUString *) rAny.getValue() );
4214                     else
4215                     {
4216                         double d = 0;
4217                         // #i20067# don't throw exception just do nothing if
4218                         // there is no value set
4219                         if( (rAny >>= d) )
4220                             lcl_setValue( *pXCell, d );
4221 						else
4222 							lcl_setString( *pXCell, OUString(), sal_True );
4223                     }
4224                 }
4225 			}
4226 		}
4227 	}
4228 }
4229 
getData(void)4230 uno::Sequence< uno::Sequence< double > > SwXCellRange::getData(void) throw( uno::RuntimeException )
4231 {
4232 	vos::OGuard aGuard(Application::GetSolarMutex());
4233 	sal_Int16 nRowCount = getRowCount();
4234 	sal_Int16 nColCount = getColumnCount();
4235 	//
4236 	if(!nRowCount || !nColCount)
4237 	{
4238 		uno::RuntimeException aRuntime;
4239 		aRuntime.Message = C2U("Table too complex");
4240 		throw aRuntime;
4241 	}
4242 	uno::Sequence< uno::Sequence< double > > aRowSeq(bFirstRowAsLabel ? nRowCount - 1 : nRowCount);
4243 	SwFrmFmt* pFmt = GetFrmFmt();
4244 	if(pFmt)
4245 	{
4246 		uno::Sequence< double >* pRowArray = aRowSeq.getArray();
4247 
4248 		sal_uInt16 nRowStart = bFirstRowAsLabel ? 1 : 0;
4249 		for(sal_uInt16 nRow = nRowStart; nRow < nRowCount; nRow++)
4250 		{
4251 			uno::Sequence< double > aColSeq(bFirstColumnAsLabel ? nColCount - 1 : nColCount);
4252 			double * pArray = aColSeq.getArray();
4253 			sal_uInt16 nColStart = bFirstColumnAsLabel ? 1 : 0;
4254 			for(sal_uInt16 nCol = nColStart; nCol < nColCount; nCol++)
4255 			{
4256 				uno::Reference< table::XCell >  xCell = getCellByPosition(nCol, nRow);
4257 				if(!xCell.is())
4258 				{
4259 					throw uno::RuntimeException();
4260 				}
4261 				pArray[nCol - nColStart] = xCell->getValue();
4262 			}
4263 			pRowArray[nRow - nRowStart] = aColSeq;
4264 		}
4265 	}
4266 	return aRowSeq;
4267 }
4268 
setData(const uno::Sequence<uno::Sequence<double>> & rData)4269 void SwXCellRange::setData(const uno::Sequence< uno::Sequence< double > >& rData)
4270 												throw( uno::RuntimeException )
4271 {
4272 	vos::OGuard aGuard(Application::GetSolarMutex());
4273 	sal_Int16 nRowCount = getRowCount();
4274 	sal_Int16 nColCount = getColumnCount();
4275 	if(!nRowCount || !nColCount)
4276 	{
4277 		uno::RuntimeException aRuntime;
4278 		aRuntime.Message = C2U("Table too complex");
4279 		throw aRuntime;
4280 	}
4281 	SwFrmFmt* pFmt = GetFrmFmt();
4282 	if(pFmt )
4283 	{
4284 		sal_uInt16 nRowStart = bFirstRowAsLabel ? 1 : 0;
4285 		if(rData.getLength() < nRowCount - nRowStart)
4286 		{
4287 			throw uno::RuntimeException();
4288 		}
4289 		const uno::Sequence< double >* pRowArray = rData.getConstArray();
4290 		for(sal_uInt16 nRow = nRowStart; nRow < nRowCount; nRow++)
4291 		{
4292 			const uno::Sequence< double >& rColSeq = pRowArray[nRow - nRowStart];
4293 			sal_uInt16 nColStart = bFirstColumnAsLabel ? 1 : 0;
4294 			if(rColSeq.getLength() < nColCount - nColStart)
4295 			{
4296 				throw uno::RuntimeException();
4297 			}
4298 			const double * pColArray = rColSeq.getConstArray();
4299 			for(sal_uInt16 nCol = nColStart; nCol < nColCount; nCol++)
4300 			{
4301 				uno::Reference< table::XCell >  xCell = getCellByPosition(nCol, nRow);
4302 				if(!xCell.is())
4303 				{
4304 					throw uno::RuntimeException();
4305 				}
4306 				xCell->setValue(pColArray[nCol - nColStart]);
4307 			}
4308 		}
4309 	}
4310 }
4311 
getRowDescriptions(void)4312 uno::Sequence< OUString > SwXCellRange::getRowDescriptions(void)
4313 											throw( uno::RuntimeException )
4314 {
4315 	vos::OGuard aGuard(Application::GetSolarMutex());
4316 	sal_Int16 nRowCount = getRowCount();
4317 	if(!nRowCount)
4318 	{
4319 		uno::RuntimeException aRuntime;
4320 		aRuntime.Message = C2U("Table too complex");
4321 		throw aRuntime;
4322 	}
4323 	uno::Sequence< OUString > aRet(bFirstColumnAsLabel ? nRowCount - 1 : nRowCount);
4324 	SwFrmFmt* pFmt = GetFrmFmt();
4325 	if(pFmt)
4326 	{
4327 		OUString* pArray = aRet.getArray();
4328 		if(bFirstColumnAsLabel)
4329 		{
4330 			sal_uInt16 nStart = bFirstRowAsLabel ? 1 : 0;
4331 			for(sal_uInt16 i = nStart; i < nRowCount; i++)
4332 			{
4333 				uno::Reference< table::XCell >  xCell = getCellByPosition(0, i);
4334 				if(!xCell.is())
4335 				{
4336 					throw uno::RuntimeException();
4337 				}
4338 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
4339 				pArray[i - nStart] = xText->getString();
4340 			}
4341 		}
4342 		else
4343 		{
4344 			DBG_ERROR("Wo kommen die Labels her?");
4345 		}
4346 	}
4347 	else
4348 		throw uno::RuntimeException();
4349 	return aRet;
4350 }
4351 
setRowDescriptions(const uno::Sequence<OUString> & rRowDesc)4352 void SwXCellRange::setRowDescriptions(const uno::Sequence< OUString >& rRowDesc)
4353 													throw( uno::RuntimeException )
4354 {
4355 	vos::OGuard aGuard(Application::GetSolarMutex());
4356 	SwFrmFmt* pFmt = GetFrmFmt();
4357 	if(pFmt)
4358 	{
4359 		sal_Int16 nRowCount = getRowCount();
4360 		if(!nRowCount || rRowDesc.getLength() < bFirstRowAsLabel ? nRowCount - 1 : nRowCount)
4361 		{
4362 			throw uno::RuntimeException();
4363 		}
4364 		const OUString* pArray = rRowDesc.getConstArray();
4365 		if(bFirstColumnAsLabel)
4366 		{
4367 			sal_uInt16 nStart = bFirstRowAsLabel ? 1 : 0;
4368 			for(sal_uInt16 i = nStart; i < nRowCount; i++)
4369 			{
4370 				uno::Reference< table::XCell >  xCell = getCellByPosition(0, i);
4371 				if(!xCell.is())
4372 				{
4373 					throw uno::RuntimeException();
4374 				}
4375 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
4376 				xText->setString(pArray[i - nStart]);
4377 			}
4378 		}
4379 		else
4380 		{
4381 			DBG_ERROR("Wohin mit den Labels?");
4382 		}
4383 	}
4384 }
4385 
getColumnDescriptions(void)4386 uno::Sequence< OUString > SwXCellRange::getColumnDescriptions(void)
4387 										throw( uno::RuntimeException )
4388 {
4389 	vos::OGuard aGuard(Application::GetSolarMutex());
4390 	sal_Int16 nColCount = getColumnCount();
4391 	if(!nColCount)
4392 	{
4393 		uno::RuntimeException aRuntime;
4394 		aRuntime.Message = C2U("Table too complex");
4395 		throw aRuntime;
4396 	}
4397 	uno::Sequence< OUString > aRet(bFirstRowAsLabel ? nColCount - 1 : nColCount);
4398 	SwFrmFmt* pFmt = GetFrmFmt();
4399 	if(pFmt)
4400 	{
4401 		OUString* pArray = aRet.getArray();
4402 		if(bFirstRowAsLabel)
4403 		{
4404 			sal_uInt16 nStart = bFirstColumnAsLabel ? 1 : 0;
4405 			for(sal_uInt16 i = nStart; i < nColCount; i++)
4406 			{
4407 				uno::Reference< table::XCell >  xCell = getCellByPosition(i, 0);
4408 				if(!xCell.is())
4409 				{
4410 					throw uno::RuntimeException();
4411 				}
4412 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
4413 				pArray[i - nStart] = xText->getString();
4414 			}
4415 		}
4416 		else
4417 		{
4418 			DBG_ERROR("Wo kommen die Labels her?");
4419 		}
4420 	}
4421 	else
4422 		throw uno::RuntimeException();
4423 	return aRet;
4424 }
4425 
setColumnDescriptions(const uno::Sequence<OUString> & ColumnDesc)4426 void SwXCellRange::setColumnDescriptions(const uno::Sequence< OUString >& ColumnDesc)
4427 														throw( uno::RuntimeException )
4428 {
4429 	vos::OGuard aGuard(Application::GetSolarMutex());
4430 	sal_Int16 nColCount = getColumnCount();
4431 	SwFrmFmt* pFmt = GetFrmFmt();
4432 	if(pFmt)
4433 	{
4434 		const OUString* pArray = ColumnDesc.getConstArray();
4435 		if(bFirstRowAsLabel && ColumnDesc.getLength() >= nColCount - bFirstColumnAsLabel ? 1 : 0)
4436 		{
4437 			sal_uInt16 nStart = bFirstColumnAsLabel ? 1 : 0;
4438 			for(sal_uInt16 i = nStart; i < nColCount; i++)
4439 			{
4440 				uno::Reference< table::XCell >  xCell = getCellByPosition(i, 0);
4441 				if(!xCell.is())
4442 				{
4443 					throw uno::RuntimeException();
4444 				}
4445 				uno::Reference< text::XText >  xText(xCell, uno::UNO_QUERY);
4446 
4447 				xText->setString(pArray[i - nStart]);
4448 			}
4449 		}
4450 		else
4451 		{
4452 			DBG_ERROR("Wo kommen die Labels her?");
4453 		}
4454 	}
4455 }
4456 
addChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)4457 void SwXCellRange::addChartDataChangeEventListener(const uno::Reference< chart::XChartDataChangeEventListener > & aListener) throw( uno::RuntimeException )
4458 {
4459 	if(!GetRegisteredIn())
4460 		throw uno::RuntimeException();
4461 	aChartLstnrCntnr.AddListener(aListener.get());
4462 }
4463 
removeChartDataChangeEventListener(const uno::Reference<chart::XChartDataChangeEventListener> & aListener)4464 void SwXCellRange::removeChartDataChangeEventListener(const uno::Reference< chart::XChartDataChangeEventListener > & aListener) throw( uno::RuntimeException )
4465 {
4466 	if(!GetRegisteredIn() || !aChartLstnrCntnr.RemoveListener(aListener.get()))
4467 		throw uno::RuntimeException();
4468 }
4469 
isNotANumber(double)4470 sal_Bool SwXCellRange::isNotANumber(double /*fNumber*/) throw( uno::RuntimeException )
4471 {
4472 	DBG_WARNING("not implemented");
4473 	return sal_False;
4474 
4475 }
4476 
getNotANumber(void)4477 double SwXCellRange::getNotANumber(void) throw( uno::RuntimeException )
4478 {
4479 	DBG_WARNING("not implemented");
4480 	return 0.;
4481 }
4482 
createSortDescriptor(void)4483 uno::Sequence< beans::PropertyValue > SwXCellRange::createSortDescriptor(void) throw( uno::RuntimeException )
4484 {
4485 	vos::OGuard aGuard(Application::GetSolarMutex());
4486 
4487     return SwUnoCursorHelper::CreateSortDescriptor(true);
4488 }
4489 
sort(const uno::Sequence<beans::PropertyValue> & rDescriptor)4490 void SAL_CALL SwXCellRange::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
4491 	throw( uno::RuntimeException )
4492 {
4493 	vos::OGuard aGuard(Application::GetSolarMutex());
4494 	SwSortOptions aSortOpt;
4495 	SwFrmFmt* pFmt = GetFrmFmt();
4496 	if(pFmt &&
4497         SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
4498 	{
4499         SwUnoTableCrsr* pTableCrsr = dynamic_cast<SwUnoTableCrsr*>(pTblCrsr);
4500 		pTableCrsr->MakeBoxSels();
4501 		UnoActionContext aContext( pFmt->GetDoc() );
4502 		pFmt->GetDoc()->SortTbl(pTableCrsr->GetBoxes(), aSortOpt);
4503 	}
4504 }
4505 
getColumnCount(void)4506 sal_uInt16 SwXCellRange::getColumnCount(void)
4507 {
4508 	return static_cast< sal_uInt16 >(aRgDesc.nRight - aRgDesc.nLeft + 1);
4509 }
4510 
getRowCount(void)4511 sal_uInt16 SwXCellRange::getRowCount(void)
4512 {
4513 	return static_cast< sal_uInt16 >(aRgDesc.nBottom - aRgDesc.nTop + 1);
4514 }
4515 
GetTblCrsr() const4516 const SwUnoCrsr* SwXCellRange::GetTblCrsr() const
4517 {
4518     const SwUnoCrsr* pRet = 0;
4519     SwFrmFmt* pFmt = GetFrmFmt();
4520     if(pFmt)
4521         pRet = pTblCrsr;
4522     return pRet;
4523 }
4524 
4525 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)4526 void SwXCellRange::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
4527 {
4528 	ClientModify(this, pOld, pNew );
4529 	if(!GetRegisteredIn() || !aCursorDepend.GetRegisteredIn())
4530 	{
4531 		/*
4532 		 * Not sure if this will cause a memory leak - this pTblCrsr
4533 		 * is deleted in SwDoc and GPFs here when deleted again
4534 		 * if(!aCursorDepend.GetRegisteredIn())
4535 			delete pTblCrsr;
4536 		 */
4537 		pTblCrsr = 0;
4538 		aChartLstnrCntnr.Disposing();
4539 	}
4540 	else
4541 		aChartLstnrCntnr.ChartDataChanged();
4542 }
4543 
4544 /******************************************************************
4545  *	SwXTableRows
4546  ******************************************************************/
4547 
getImplementationName(void)4548 OUString SwXTableRows::getImplementationName(void) throw( uno::RuntimeException )
4549 {
4550 	return C2U("SwXTableRows");
4551 }
4552 
supportsService(const OUString & rServiceName)4553 sal_Bool SwXTableRows::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
4554 {
4555 	return C2U("com.sun.star.text.TableRows") == rServiceName;
4556 }
4557 
getSupportedServiceNames(void)4558 uno::Sequence< OUString > SwXTableRows::getSupportedServiceNames(void) throw( uno::RuntimeException )
4559 {
4560 	uno::Sequence< OUString > aRet(1);
4561 	OUString* pArray = aRet.getArray();
4562 	pArray[0] = C2U("com.sun.star.text.TableRows");
4563 	return aRet;
4564 }
4565 TYPEINIT1(SwXTableRows, SwClient);
4566 
SwXTableRows(SwFrmFmt & rFrmFmt)4567 SwXTableRows::SwXTableRows(SwFrmFmt& rFrmFmt) :
4568 	SwClient(&rFrmFmt)
4569 {
4570 }
4571 
~SwXTableRows()4572 SwXTableRows::~SwXTableRows()
4573 {
4574 }
4575 
getCount(void)4576 sal_Int32 SwXTableRows::getCount(void) throw( uno::RuntimeException )
4577 {
4578 	vos::OGuard aGuard(Application::GetSolarMutex());
4579 	sal_Int32 nRet = 0;
4580 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4581 	if(!pFrmFmt)
4582 		throw uno::RuntimeException();
4583 	else
4584 	{
4585 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4586 		nRet = pTable->GetTabLines().Count();
4587 	}
4588 	return nRet;
4589 }
4590 
getByIndex(sal_Int32 nIndex)4591 uno::Any SwXTableRows::getByIndex(sal_Int32 nIndex)
4592 	throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
4593 {
4594 	vos::OGuard aGuard(Application::GetSolarMutex());
4595 	uno::Any aRet;
4596 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4597 	if(!pFrmFmt || nIndex < 0 )
4598 		throw lang::IndexOutOfBoundsException();
4599 	else
4600 	{
4601 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4602 		if(pTable->GetTabLines().Count() > nIndex)
4603 		{
4604 			SwTableLine* pLine = pTable->GetTabLines().GetObject((sal_uInt16)nIndex);
4605 			SwIterator<SwXTextTableRow,SwFmt> aIter( *pFrmFmt );
4606 			SwXTextTableRow* pXRow = aIter.First();
4607 			while( pXRow )
4608 			{
4609 				// gibt es eine passende Zelle bereits?
4610 				if(pXRow->GetTblRow() == pLine)
4611 					break;
4612                 pXRow = aIter.Next();
4613 			}
4614 			//sonst anlegen
4615 			if(!pXRow)
4616 				pXRow = new SwXTextTableRow(pFrmFmt, pLine);
4617 			uno::Reference< beans::XPropertySet >  xRet =
4618 									(beans::XPropertySet*)pXRow;
4619 			aRet.setValue(&xRet, ::getCppuType((const uno::Reference<beans::XPropertySet>*)0));
4620 		}
4621 		else
4622 			throw lang::IndexOutOfBoundsException();
4623 	}
4624 	return aRet;
4625 }
4626 
getElementType(void)4627 uno::Type SAL_CALL SwXTableRows::getElementType(void) throw( uno::RuntimeException )
4628 {
4629 	return ::getCppuType((const uno::Reference<beans::XPropertySet>*)0);
4630 }
4631 
hasElements(void)4632 sal_Bool SwXTableRows::hasElements(void) throw( uno::RuntimeException )
4633 {
4634 	vos::OGuard aGuard(Application::GetSolarMutex());
4635 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4636 	if(!pFrmFmt)
4637 		throw uno::RuntimeException();
4638 	//es gibt keine Tabelle ohne Zeilen
4639 	return sal_True;
4640 }
4641 
insertByIndex(sal_Int32 nIndex,sal_Int32 nCount)4642 void SwXTableRows::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) throw( uno::RuntimeException )
4643 {
4644 	vos::OGuard aGuard(Application::GetSolarMutex());
4645     if (nCount == 0)
4646         return;
4647 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4648 	if(!pFrmFmt)
4649 		throw uno::RuntimeException();
4650 	else
4651 	{
4652 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4653 		if(!pTable->IsTblComplex())
4654 		{
4655 			sal_uInt16 nRowCount = pTable->GetTabLines().Count();
4656 			if (nCount <= 0 || !(0 <= nIndex && nIndex <= nRowCount))
4657 			{
4658 				uno::RuntimeException aExcept;
4659 				aExcept.Message = C2U("Illegal arguments");
4660 				throw aExcept;
4661 			}
4662 
4663 			String sTLName = lcl_GetCellName(0, nIndex);
4664             const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
4665 			sal_Bool bAppend = sal_False;
4666 			if(!pTLBox)
4667 			{
4668 				bAppend = sal_True;
4669 				// am Ende anfuegen, dazu muss der Cursor in die letzte Zeile!
4670 				SwTableLines& rLines = pTable->GetTabLines();
4671 				SwTableLine* pLine = rLines.GetObject(rLines.Count() -1);
4672 				SwTableBoxes& rBoxes = pLine->GetTabBoxes();
4673 				pTLBox = rBoxes.GetObject(0);
4674 			}
4675 			if(pTLBox)
4676 			{
4677 				const SwStartNode* pSttNd = pTLBox->GetSttNd();
4678 				SwPosition aPos(*pSttNd);
4679 				// Cursor in die obere linke Zelle des Ranges setzen
4680 				UnoActionContext aAction(pFrmFmt->GetDoc());
4681 				SwUnoCrsr* pUnoCrsr = pFrmFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
4682 				pUnoCrsr->Move( fnMoveForward, fnGoNode );
4683 
4684                 {
4685                     // remove actions
4686                     UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc());
4687                 }
4688 
4689 				pFrmFmt->GetDoc()->InsertRow(*pUnoCrsr, (sal_uInt16)nCount, bAppend);
4690 				delete pUnoCrsr;
4691 			}
4692 		}
4693 	}
4694 }
4695 
removeByIndex(sal_Int32 nIndex,sal_Int32 nCount)4696 void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) throw( uno::RuntimeException )
4697 {
4698 	vos::OGuard aGuard(Application::GetSolarMutex());
4699     if (nCount == 0)
4700         return;
4701 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4702 	if(!pFrmFmt || nIndex < 0 || nCount <=0 )
4703 		throw uno::RuntimeException();
4704 	else
4705 	{
4706         sal_Bool bSuccess = sal_False;
4707         SwTable* pTable = SwTable::FindTable( pFrmFmt );
4708 		if(!pTable->IsTblComplex())
4709 		{
4710             String sTLName = lcl_GetCellName(0, nIndex);
4711             const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
4712             if(pTLBox)
4713             {
4714                 {
4715                     // hier muessen die Actions aufgehoben werden
4716                     UnoActionRemoveContext aRemoveContext(pFrmFmt->GetDoc());
4717                 }
4718                 const SwStartNode* pSttNd = pTLBox->GetSttNd();
4719                 SwPosition aPos(*pSttNd);
4720                 // Cursor in die obere linke Zelle des Ranges setzen
4721                 SwUnoCrsr* pUnoCrsr = pFrmFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
4722                 pUnoCrsr->Move( fnMoveForward, fnGoNode );
4723                 pUnoCrsr->SetRemainInSection( sal_False );
4724                 String sBLName = lcl_GetCellName(0, nIndex + nCount - 1);
4725                 const SwTableBox* pBLBox = pTable->GetTblBox( sBLName );
4726                 if(pBLBox)
4727                 {
4728                     pUnoCrsr->SetMark();
4729                     pUnoCrsr->GetPoint()->nNode = *pBLBox->GetSttNd();
4730                     pUnoCrsr->Move( fnMoveForward, fnGoNode );
4731                     SwUnoTableCrsr* pCrsr =
4732                         dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
4733                     pCrsr->MakeBoxSels();
4734                     {   // Die Klammer ist wichtig
4735                         UnoActionContext aAction(pFrmFmt->GetDoc());
4736                         pFrmFmt->GetDoc()->DeleteRow(*pUnoCrsr);
4737                         delete pUnoCrsr;
4738                         bSuccess = sal_True;
4739                     }
4740                     {
4741                         // hier muessen die Actions aufgehoben werden
4742                         UnoActionRemoveContext aRemoveContext(pFrmFmt->GetDoc());
4743                     }
4744                 }
4745             }
4746 		}
4747         if(!bSuccess)
4748         {
4749             uno::RuntimeException aExcept;
4750             aExcept.Message = C2U("Illegal arguments");
4751             throw aExcept;
4752         }
4753     }
4754 }
4755 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)4756 void SwXTableRows::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
4757 {
4758 	ClientModify(this, pOld, pNew);
4759 }
4760 
4761 /******************************************************************
4762  * SwXTableColumns
4763  ******************************************************************/
4764 
getImplementationName(void)4765 OUString SwXTableColumns::getImplementationName(void) throw( uno::RuntimeException )
4766 {
4767 	return C2U("SwXTableColumns");
4768 }
4769 
supportsService(const OUString & rServiceName)4770 sal_Bool SwXTableColumns::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
4771 {
4772 	return C2U("com.sun.star.text.TableColumns") == rServiceName;
4773 }
4774 
getSupportedServiceNames(void)4775 uno::Sequence< OUString > SwXTableColumns::getSupportedServiceNames(void) throw( uno::RuntimeException )
4776 {
4777 	uno::Sequence< OUString > aRet(1);
4778 	OUString* pArray = aRet.getArray();
4779 	pArray[0] = C2U("com.sun.star.text.TableColumns");
4780 	return aRet;
4781 }
4782 TYPEINIT1(SwXTableColumns, SwClient);
4783 
SwXTableColumns(SwFrmFmt & rFrmFmt)4784 SwXTableColumns::SwXTableColumns(SwFrmFmt& rFrmFmt) :
4785 	SwClient(&rFrmFmt)
4786 {
4787 }
4788 
~SwXTableColumns()4789 SwXTableColumns::~SwXTableColumns()
4790 {
4791 }
4792 
getCount(void)4793 sal_Int32 SwXTableColumns::getCount(void) throw( uno::RuntimeException )
4794 {
4795 	vos::OGuard aGuard(Application::GetSolarMutex());
4796 	sal_Int32 nRet = 0;
4797 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4798 	if(!pFrmFmt)
4799 		throw uno::RuntimeException();
4800 	else
4801 	{
4802 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4803 		if(!pTable->IsTblComplex())
4804 		{
4805 			SwTableLines& rLines = pTable->GetTabLines();
4806 			SwTableLine* pLine = rLines.GetObject(0);
4807 			nRet = pLine->GetTabBoxes().Count();
4808 		}
4809 	}
4810 	return nRet;
4811 }
4812 
getByIndex(sal_Int32 nIndex)4813 uno::Any SwXTableColumns::getByIndex(sal_Int32 nIndex)
4814 	throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
4815 {
4816 	vos::OGuard aGuard(Application::GetSolarMutex());
4817 	uno::Reference< uno::XInterface >  xRet;
4818 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4819 	if(!pFrmFmt)
4820 		throw uno::RuntimeException();
4821 	else
4822 	{
4823 		sal_uInt16 nCount = 0;
4824 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4825 		if(!pTable->IsTblComplex())
4826 		{
4827 			SwTableLines& rLines = pTable->GetTabLines();
4828 			SwTableLine* pLine = rLines.GetObject(0);
4829 			nCount = pLine->GetTabBoxes().Count();
4830 		}
4831 		if(nCount <= nIndex || nIndex < 0)
4832 			throw lang::IndexOutOfBoundsException();
4833         xRet = uno::Reference<uno::XInterface>();   //!! writer tables do not have columns !!
4834 	}
4835 	return uno::Any(&xRet, ::getCppuType((const uno::Reference<uno::XInterface>*)0));
4836 }
4837 
getElementType(void)4838 uno::Type SAL_CALL SwXTableColumns::getElementType(void) throw( uno::RuntimeException )
4839 {
4840 	return ::getCppuType((uno::Reference<uno::XInterface>*)0);
4841 }
4842 
hasElements(void)4843 sal_Bool SwXTableColumns::hasElements(void) throw( uno::RuntimeException )
4844 {
4845 	vos::OGuard aGuard(Application::GetSolarMutex());
4846 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4847 	if(!pFrmFmt)
4848 		throw uno::RuntimeException();
4849 	return sal_True;
4850 }
4851 
insertByIndex(sal_Int32 nIndex,sal_Int32 nCount)4852 void SwXTableColumns::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) throw( uno::RuntimeException )
4853 {
4854 	vos::OGuard aGuard(Application::GetSolarMutex());
4855 	if (nCount == 0)
4856 		return;
4857 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4858 	if(!pFrmFmt)
4859 		throw uno::RuntimeException();
4860 	else
4861 	{
4862 		SwTable* pTable = SwTable::FindTable( pFrmFmt );
4863 		if(!pTable->IsTblComplex())
4864 		{
4865 			SwTableLines& rLines = pTable->GetTabLines();
4866 			SwTableLine* pLine = rLines.GetObject(0);
4867 			sal_uInt16 nColCount = pLine->GetTabBoxes().Count();
4868 			if (nCount <= 0 || !(0 <= nIndex && nIndex <= nColCount))
4869 			{
4870 				uno::RuntimeException aExcept;
4871 				aExcept.Message = C2U("Illegal arguments");
4872 				throw aExcept;
4873 			}
4874 
4875 			String sTLName = lcl_GetCellName(nIndex, 0);
4876             const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
4877 			sal_Bool bAppend = sal_False;
4878 			if(!pTLBox)
4879 			{
4880 				bAppend = sal_True;
4881 				// am Ende anfuegen, dazu muss der Cursor in die letzte Spalte!
4882 				SwTableBoxes& rBoxes = pLine->GetTabBoxes();
4883 				pTLBox = rBoxes.GetObject(rBoxes.Count() - 1);
4884 			}
4885 			if(pTLBox)
4886 			{
4887 				const SwStartNode* pSttNd = pTLBox->GetSttNd();
4888 				SwPosition aPos(*pSttNd);
4889 				UnoActionContext aAction(pFrmFmt->GetDoc());
4890 				SwUnoCrsr* pUnoCrsr = pFrmFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
4891 				pUnoCrsr->Move( fnMoveForward, fnGoNode );
4892 
4893         		{
4894                     // remove actions
4895 			        UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc());
4896 		        }
4897 
4898 				pFrmFmt->GetDoc()->InsertCol(*pUnoCrsr, (sal_uInt16)nCount, bAppend);
4899 				delete pUnoCrsr;
4900 			}
4901 		}
4902 	}
4903 }
4904 
removeByIndex(sal_Int32 nIndex,sal_Int32 nCount)4905 void SwXTableColumns::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) throw( uno::RuntimeException )
4906 {
4907 	vos::OGuard aGuard(Application::GetSolarMutex());
4908 	if (nCount == 0)
4909 		return;
4910 	SwFrmFmt* pFrmFmt = GetFrmFmt();
4911 	if(!pFrmFmt|| nIndex < 0 || nCount <=0 )
4912 		throw uno::RuntimeException();
4913 	else
4914 	{
4915         sal_Bool bSuccess = sal_False;
4916         SwTable* pTable = SwTable::FindTable( pFrmFmt );
4917 		if(!pTable->IsTblComplex())
4918 		{
4919             String sTLName = lcl_GetCellName(nIndex, 0);
4920             const SwTableBox* pTLBox = pTable->GetTblBox( sTLName );
4921             if(pTLBox)
4922             {
4923                 {
4924                     // hier muessen die Actions aufgehoben werden
4925                     UnoActionRemoveContext aRemoveContext(pFrmFmt->GetDoc());
4926                 }
4927                 const SwStartNode* pSttNd = pTLBox->GetSttNd();
4928                 SwPosition aPos(*pSttNd);
4929                 // Cursor in die obere linke Zelle des Ranges setzen
4930                 SwUnoCrsr* pUnoCrsr = pFrmFmt->GetDoc()->CreateUnoCrsr(aPos, sal_True);
4931                 pUnoCrsr->Move( fnMoveForward, fnGoNode );
4932                 pUnoCrsr->SetRemainInSection( sal_False );
4933                 String sTRName = lcl_GetCellName(nIndex + nCount - 1, 0);
4934                 const SwTableBox* pTRBox = pTable->GetTblBox( sTRName );
4935                 if(pTRBox)
4936                 {
4937                     pUnoCrsr->SetMark();
4938                     pUnoCrsr->GetPoint()->nNode = *pTRBox->GetSttNd();
4939                     pUnoCrsr->Move( fnMoveForward, fnGoNode );
4940                     SwUnoTableCrsr* pCrsr =
4941                         dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr);
4942                     pCrsr->MakeBoxSels();
4943                     {   // Die Klammer ist wichtig
4944                         UnoActionContext aAction(pFrmFmt->GetDoc());
4945                         pFrmFmt->GetDoc()->DeleteCol(*pUnoCrsr);
4946                         delete pUnoCrsr;
4947                         bSuccess = sal_True;
4948                     }
4949                     {
4950                         // hier muessen die Actions aufgehoben werden
4951                         UnoActionRemoveContext aRemoveContext(pFrmFmt->GetDoc());
4952                     }
4953                 }
4954             }
4955         }
4956         if(!bSuccess)
4957         {
4958             uno::RuntimeException aExcept;
4959             aExcept.Message = C2U("Illegal arguments");
4960             throw aExcept;
4961         }
4962     }
4963 }
4964 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)4965 void SwXTableColumns::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
4966 {
4967 	ClientModify(this, pOld, pNew);
4968 }
4969 
ChartDataChanged()4970 void SwChartEventListenerContainer::ChartDataChanged()
4971 {
4972 	if(pListenerArr)
4973 	{
4974 		//TODO: find appropriate settings of the Event
4975 		lang::EventObject aObj(pxParent);
4976 		chart::ChartDataChangeEvent aEvent;
4977     	aEvent.Type = chart::ChartDataChangeType_ALL;
4978     	aEvent.StartColumn = 0;
4979     	aEvent.EndColumn = 1;
4980     	aEvent.StartRow = 0;
4981     	aEvent.EndRow = 1;
4982 
4983 		for(sal_uInt16 i = 0; i < pListenerArr->Count(); i++)
4984 		{
4985 			try
4986 			{
4987 				XEventListenerPtr pElem = pListenerArr->GetObject(i);
4988 				uno::Reference<lang::XEventListener> xEventListener = *pElem;
4989 				uno::Reference<chart::XChartDataChangeEventListener> xChartEventListener = (chart::XChartDataChangeEventListener*)(*pElem).get();
4990 				xChartEventListener->chartDataChanged( aEvent );
4991 			}
4992 			catch(uno::Exception const &)
4993 			{
4994 			}
4995 		}
4996 	}
4997 }
4998 
4999 ///////////////////////////////////////////////////////////////////////////
5000 
5001