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