Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : :
31 : : #include <tools/errinf.hxx>
32 : : #include <vcl/svapp.hxx>
33 : : #include <basegfx/vector/b2dvector.hxx>
34 : : #include <svx/svxids.hrc>
35 : : #include <editeng/protitem.hxx>
36 : : #include <editeng/brshitem.hxx>
37 : : #include <editeng/frmdiritem.hxx>
38 : : #include <svtools/ruler.hxx>
39 : : #include <swwait.hxx>
40 : : #include <fmtfsize.hxx>
41 : : #include <fmtornt.hxx>
42 : : #include <frmatr.hxx>
43 : : #include <docary.hxx>
44 : : #include <fesh.hxx>
45 : : #include <doc.hxx>
46 : : #include <cntfrm.hxx>
47 : : #include <rootfrm.hxx>
48 : : #include <pagefrm.hxx>
49 : : #include <tabfrm.hxx>
50 : : #include <rowfrm.hxx>
51 : : #include <cellfrm.hxx>
52 : : #include <flyfrm.hxx>
53 : : #include <dflyobj.hxx>
54 : : #include <swtable.hxx>
55 : : #include <swddetbl.hxx>
56 : : #include <ndtxt.hxx>
57 : : #include <calc.hxx>
58 : : #include <tabcol.hxx>
59 : : #include <cellatr.hxx>
60 : : #include <pam.hxx>
61 : : #include <viscrs.hxx>
62 : : #include <tblsel.hxx>
63 : : #include <swtblfmt.hxx>
64 : : #include <swerror.h>
65 : : #include <swundo.hxx>
66 : : #include <frmtool.hxx>
67 : :
68 : : #include <node.hxx> // #i23726#
69 : : // OD 2004-05-24 #i28701#
70 : : #include <sortedobjs.hxx>
71 : :
72 : : using namespace ::com::sun::star;
73 : :
74 : :
75 : : // also see swtable.cxx
76 : : #define COLFUZZY 20L
77 : :
78 : 0 : inline sal_Bool IsSame( long nA, long nB ) { return Abs(nA-nB) <= COLFUZZY; }
79 : : inline sal_Bool IsNear( long nA, long nB, long nTolerance ) { return Abs( nA - nB ) <= nTolerance; }
80 : :
81 : : // table column cache
82 : : SwTabCols *pLastCols = 0;
83 : : const SwTable *pColumnCacheLastTable = 0;
84 : : const SwTabFrm *pColumnCacheLastTabFrm = 0;
85 : : const SwFrm *pColumnCacheLastCellFrm = 0;
86 : :
87 : : // table row cache
88 : : SwTabCols *pLastRows = 0;
89 : : const SwTable *pRowCacheLastTable = 0;
90 : : const SwTabFrm *pRowCacheLastTabFrm = 0;
91 : : const SwFrm *pRowCacheLastCellFrm = 0;
92 : :
93 : :
94 : : class TblWait
95 : : {
96 : : SwWait *pWait;
97 : : public:
98 : : TblWait( sal_uInt16 nCnt, SwFrm *pFrm, SwDocShell &rDocShell, sal_uInt16 nCnt2 = 0);
99 [ # # ]: 0 : ~TblWait() { delete pWait; }
100 : : };
101 : :
102 : 0 : TblWait::TblWait( sal_uInt16 nCnt, SwFrm *pFrm, SwDocShell &rDocShell, sal_uInt16 nCnt2):
103 : 0 : pWait( 0 )
104 : : {
105 : : sal_Bool bWait = 20 < nCnt || 20 < nCnt2 || (pFrm &&
106 [ # # ][ # # ]: 0 : 20 < pFrm->ImplFindTabFrm()->GetTable()->GetTabLines().size());
[ # # ][ # # ]
107 [ # # ]: 0 : if( bWait )
108 [ # # ]: 0 : pWait = new SwWait( rDocShell, sal_True );
109 : 0 : }
110 : :
111 : :
112 : 0 : void SwFEShell::ParkCursorInTab()
113 : : {
114 [ # # ]: 0 : SwCursor * pSwCrsr = GetSwCrsr();
115 : :
116 : : OSL_ENSURE(pSwCrsr, "no SwCursor");
117 : :
118 [ # # ][ # # ]: 0 : SwPosition aStartPos = *pSwCrsr->GetPoint(), aEndPos = aStartPos;
119 : :
120 : 0 : SwCursor * pTmpCrsr = (SwCursor *) pSwCrsr;
121 : :
122 : : /* Search least and greatest position in current cursor ring.
123 : : */
124 [ # # ]: 0 : do
125 : : {
126 : 0 : const SwPosition * pPt = pTmpCrsr->GetPoint(),
127 : 0 : * pMk = pTmpCrsr->GetMark();
128 : :
129 [ # # ][ # # ]: 0 : if (*pPt < aStartPos)
130 [ # # ]: 0 : aStartPos = *pPt;
131 : :
132 [ # # ][ # # ]: 0 : if (*pPt > aEndPos)
133 [ # # ]: 0 : aEndPos = *pPt;
134 : :
135 [ # # ][ # # ]: 0 : if (*pMk < aStartPos)
136 [ # # ]: 0 : aStartPos = *pMk;
137 : :
138 [ # # ][ # # ]: 0 : if (*pMk > aEndPos)
139 [ # # ]: 0 : aEndPos = *pMk;
140 : :
141 : 0 : pTmpCrsr = (SwCursor *) pTmpCrsr->GetNext();
142 : : }
143 : : while (pTmpCrsr != pSwCrsr);
144 : :
145 [ # # ]: 0 : KillPams();
146 : :
147 : : /* @@@ semantic: SwCursor::operator=() is not implemented @@@ */
148 : :
149 : : /* Set cursor to end of selection to ensure IsLastCellInRow works
150 : : properly. */
151 : : {
152 [ # # ]: 0 : SwCursor aTmpCrsr( aEndPos, 0, false );
153 [ # # ][ # # ]: 0 : *pSwCrsr = aTmpCrsr;
154 : : }
155 : :
156 : : /* Move the cursor out of the columns to delete and stay in the
157 : : same row. If the table has only one column the cursor will
158 : : stay in the row and the shell will take care of it. */
159 [ # # ][ # # ]: 0 : if (IsLastCellInRow())
160 : : {
161 : : /* If the cursor is in the last row of the table, first
162 : : try to move it to the previous cell. If that fails move
163 : : it to the next cell. */
164 : :
165 : : {
166 [ # # ]: 0 : SwCursor aTmpCrsr( aStartPos, 0, false );
167 [ # # ][ # # ]: 0 : *pSwCrsr = aTmpCrsr;
168 : : }
169 : :
170 [ # # ][ # # ]: 0 : if (! pSwCrsr->GoPrevCell())
171 : : {
172 [ # # ]: 0 : SwCursor aTmpCrsr( aEndPos, 0, false );
173 [ # # ]: 0 : *pSwCrsr = aTmpCrsr;
174 [ # # ][ # # ]: 0 : pSwCrsr->GoNextCell();
175 : : }
176 : : }
177 : : else
178 : : {
179 : : /* If the cursor is not in the last row of the table, first
180 : : try to move it to the next cell. If that fails move it
181 : : to the previous cell. */
182 : :
183 : : {
184 [ # # ]: 0 : SwCursor aTmpCrsr( aEndPos, 0, false );
185 [ # # ][ # # ]: 0 : *pSwCrsr = aTmpCrsr;
186 : : }
187 : :
188 [ # # ][ # # ]: 0 : if (! pSwCrsr->GoNextCell())
189 : : {
190 [ # # ]: 0 : SwCursor aTmpCrsr( aStartPos, 0, false );
191 [ # # ]: 0 : *pSwCrsr = aTmpCrsr;
192 [ # # ][ # # ]: 0 : pSwCrsr->GoPrevCell();
193 : : }
194 [ # # ][ # # ]: 0 : }
195 : 0 : }
196 : :
197 : : /***********************************************************************
198 : : #* Class : SwFEShell
199 : : #* Methods : InsertRow(), InsertCol
200 : : #***********************************************************************/
201 : 0 : sal_Bool SwFEShell::InsertRow( sal_uInt16 nCnt, sal_Bool bBehind )
202 : : {
203 : : // check if Point/Mark of current cursor are in a table
204 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
205 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
206 : 0 : return sal_False;
207 : :
208 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
209 : : {
210 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
211 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
212 : 0 : return sal_False;
213 : : }
214 : :
215 [ # # ]: 0 : SET_CURR_SHELL( this );
216 [ # # ]: 0 : StartAllAction();
217 : :
218 : : // search boxes via the layout
219 [ # # ]: 0 : SwSelBoxes aBoxes;
220 [ # # ]: 0 : GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_ROW );
221 : :
222 [ # # ][ # # ]: 0 : TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.size() );
223 : :
224 : 0 : sal_Bool bRet = sal_False;
225 [ # # ]: 0 : if ( aBoxes.size() )
226 [ # # ]: 0 : bRet = GetDoc()->InsertRow( aBoxes, nCnt, bBehind );
227 : :
228 [ # # ]: 0 : EndAllActionAndCall();
229 [ # # ]: 0 : return bRet;
230 : : }
231 : :
232 : 0 : sal_Bool SwFEShell::InsertCol( sal_uInt16 nCnt, sal_Bool bBehind )
233 : : {
234 : : // check if Point/Mark of current cursor are in a table
235 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
236 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
237 : 0 : return sal_False;
238 : :
239 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
240 : : {
241 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
242 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
243 : 0 : return sal_False;
244 : : }
245 : :
246 [ # # ]: 0 : SET_CURR_SHELL( this );
247 : :
248 [ # # ][ # # ]: 0 : if( !CheckSplitCells( *this, nCnt + 1, nsSwTblSearchType::TBLSEARCH_COL ) )
249 : : {
250 : : ErrorHandler::HandleError( ERR_TBLINSCOL_ERROR,
251 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
252 : 0 : return sal_False;
253 : : }
254 : :
255 [ # # ]: 0 : StartAllAction();
256 : : // search boxes via the layout
257 [ # # ]: 0 : SwSelBoxes aBoxes;
258 [ # # ]: 0 : GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_COL );
259 : :
260 [ # # ][ # # ]: 0 : TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.size() );
261 : :
262 : 0 : sal_Bool bRet = sal_False;
263 [ # # ]: 0 : if( !aBoxes.empty() )
264 [ # # ]: 0 : bRet = GetDoc()->InsertCol( aBoxes, nCnt, bBehind );
265 : :
266 [ # # ]: 0 : EndAllActionAndCall();
267 [ # # ]: 0 : return bRet;
268 : : }
269 : :
270 : : /***********************************************************************
271 : : #* Class : SwFEShell
272 : : #* Methoden : DeleteRow(), DeleteCol()
273 : : #***********************************************************************/
274 : :
275 : : /**
276 : : Determines if the current cursor is in the last row of the table.
277 : : */
278 : 0 : sal_Bool SwFEShell::IsLastCellInRow() const
279 : : {
280 [ # # ]: 0 : SwTabCols aTabCols;
281 [ # # ]: 0 : GetTabCols( aTabCols );
282 : 0 : sal_Bool bResult = sal_False;
283 : :
284 [ # # ][ # # ]: 0 : if (IsTableRightToLeft())
285 : : /* If the table is right-to-left the last row is the most left one. */
286 [ # # ]: 0 : bResult = 0 == GetCurTabColNum();
287 : : else
288 : : /* If the table is left-to-right the last row is the most right one. */
289 [ # # ][ # # ]: 0 : bResult = aTabCols.Count() == GetCurTabColNum();
290 : :
291 : 0 : return bResult;
292 : : }
293 : :
294 : 0 : sal_Bool SwFEShell::DeleteCol()
295 : : {
296 : : // check if Point/Mark of current cursor are in a table
297 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
298 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
299 : 0 : return sal_False;
300 : :
301 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
302 : : {
303 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
304 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
305 : 0 : return sal_False;
306 : : }
307 : :
308 [ # # ]: 0 : SET_CURR_SHELL( this );
309 [ # # ]: 0 : StartAllAction();
310 : :
311 : : // search boxes via the layout
312 : : sal_Bool bRet;
313 [ # # ]: 0 : SwSelBoxes aBoxes;
314 [ # # ]: 0 : GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_COL );
315 [ # # ]: 0 : if ( !aBoxes.empty() )
316 : : {
317 [ # # ][ # # ]: 0 : TblWait( aBoxes.size(), pFrm, *GetDoc()->GetDocShell() );
318 : :
319 : : // remove crsr from the deletion area.
320 : : // Put them behind/on the table; via the
321 : : // document position they will be put to the old position
322 [ # # ]: 0 : while( !pFrm->IsCellFrm() )
323 : 0 : pFrm = pFrm->GetUpper();
324 : :
325 [ # # ]: 0 : ParkCursorInTab();
326 : :
327 : : // then delete the column
328 [ # # ]: 0 : StartUndo(UNDO_COL_DELETE);
329 [ # # ]: 0 : bRet = GetDoc()->DeleteRowCol( aBoxes, true );
330 [ # # ]: 0 : EndUndo(UNDO_COL_DELETE);
331 : :
332 : : }
333 : : else
334 : 0 : bRet = sal_False;
335 : :
336 [ # # ]: 0 : EndAllActionAndCall();
337 [ # # ]: 0 : return bRet;
338 : : }
339 : :
340 : 0 : sal_Bool SwFEShell::DeleteRow()
341 : : {
342 : : // check if Point/Mark of current cursor are in a table
343 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
344 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
345 : 0 : return sal_False;
346 : :
347 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
348 : : {
349 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
350 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
351 : 0 : return sal_False;
352 : : }
353 : :
354 [ # # ]: 0 : SET_CURR_SHELL( this );
355 [ # # ]: 0 : StartAllAction();
356 : :
357 : : // search for boxes via the layout
358 : : sal_Bool bRet;
359 [ # # ]: 0 : SwSelBoxes aBoxes;
360 [ # # ]: 0 : GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_ROW );
361 : :
362 [ # # ]: 0 : if( !aBoxes.empty() )
363 : : {
364 [ # # ][ # # ]: 0 : TblWait( aBoxes.size(), pFrm, *GetDoc()->GetDocShell() );
365 : :
366 : : // Delete cursors from the deletion area.
367 : : // Then the cursor is:
368 : : // 1. the following row, if there is another row after this
369 : : // 2. the preceding row, if there is another row before this
370 : : // 3. otherwise below the table
371 : : {
372 [ # # ]: 0 : SwTableNode* pTblNd = ((SwCntntFrm*)pFrm)->GetNode()->FindTableNode();
373 : :
374 : : // search all boxes / lines
375 [ # # ]: 0 : _FndBox aFndBox( 0, 0 );
376 : : {
377 : 0 : _FndPara aPara( aBoxes, &aFndBox );
378 [ # # ]: 0 : ForEach_FndLineCopyCol( pTblNd->GetTable().GetTabLines(), &aPara );
379 : : }
380 : :
381 [ # # ]: 0 : if( aFndBox.GetLines().empty() )
382 : : {
383 [ # # ]: 0 : EndAllActionAndCall();
384 : 0 : return sal_False;
385 : : }
386 : :
387 [ # # ]: 0 : KillPams();
388 : :
389 : 0 : _FndBox* pFndBox = &aFndBox;
390 [ # # # # ]: 0 : while( 1 == pFndBox->GetLines().size() &&
[ # # ]
391 [ # # ]: 0 : 1 == pFndBox->GetLines().front().GetBoxes().size() )
392 : : {
393 [ # # ][ # # ]: 0 : _FndBox* pTmp = &pFndBox->GetLines().front().GetBoxes()[0];
394 [ # # ]: 0 : if( pTmp->GetBox()->GetSttNd() )
395 : 0 : break; // otherwise too far
396 : 0 : pFndBox = pTmp;
397 : : }
398 : :
399 [ # # ]: 0 : SwTableLine* pDelLine = pFndBox->GetLines().back().GetLine();
400 [ # # ]: 0 : SwTableBox* pDelBox = pDelLine->GetTabBoxes().back();
401 [ # # ]: 0 : while( !pDelBox->GetSttNd() )
402 : : {
403 [ # # ]: 0 : SwTableLine* pLn = pDelBox->GetTabLines().back();
404 [ # # ]: 0 : pDelBox = pLn->GetTabBoxes().back();
405 : : }
406 : 0 : SwTableBox* pNextBox = pDelLine->FindNextBox( pTblNd->GetTable(),
407 [ # # ]: 0 : pDelBox, sal_True );
408 [ # # # # ]: 0 : while( pNextBox &&
[ # # ]
409 [ # # ]: 0 : pNextBox->GetFrmFmt()->GetProtect().IsCntntProtected() )
410 [ # # ]: 0 : pNextBox = pNextBox->FindNextBox( pTblNd->GetTable(), pNextBox );
411 : :
412 [ # # ]: 0 : if( !pNextBox ) // no next? then the previous
413 : : {
414 [ # # ]: 0 : pDelLine = pFndBox->GetLines().front().GetLine();
415 : 0 : pDelBox = pDelLine->GetTabBoxes()[ 0 ];
416 [ # # ]: 0 : while( !pDelBox->GetSttNd() )
417 : 0 : pDelBox = pDelBox->GetTabLines()[0]->GetTabBoxes()[0];
418 : 0 : pNextBox = pDelLine->FindPreviousBox( pTblNd->GetTable(),
419 [ # # ]: 0 : pDelBox, sal_True );
420 [ # # # # ]: 0 : while( pNextBox &&
[ # # ]
421 [ # # ]: 0 : pNextBox->GetFrmFmt()->GetProtect().IsCntntProtected() )
422 [ # # ]: 0 : pNextBox = pNextBox->FindPreviousBox( pTblNd->GetTable(), pNextBox );
423 : : }
424 : :
425 : : sal_uLong nIdx;
426 [ # # ]: 0 : if( pNextBox ) // put cursor here
427 [ # # ]: 0 : nIdx = pNextBox->GetSttIdx() + 1;
428 : : else // otherwise below the table
429 : 0 : nIdx = pTblNd->EndOfSectionIndex() + 1;
430 : :
431 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( GetDoc()->GetNodes(), nIdx );
432 : 0 : SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
433 [ # # ]: 0 : if( !pCNd )
434 [ # # ][ # # ]: 0 : pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
435 : :
436 [ # # ]: 0 : if( pCNd )
437 : : {
438 [ # # ]: 0 : SwPaM* pPam = GetCrsr();
439 [ # # ]: 0 : pPam->GetPoint()->nNode = aIdx;
440 [ # # ][ # # ]: 0 : pPam->GetPoint()->nContent.Assign( pCNd, 0 );
441 [ # # ]: 0 : pPam->SetMark(); // both want something
442 [ # # ]: 0 : pPam->DeleteMark();
443 [ # # ][ # # ]: 0 : }
[ # # ]
444 : : }
445 : :
446 : : // now delete the lines
447 [ # # ]: 0 : StartUndo(UNDO_ROW_DELETE);
448 [ # # ]: 0 : bRet = GetDoc()->DeleteRowCol( aBoxes );
449 [ # # ]: 0 : EndUndo(UNDO_ROW_DELETE);
450 : : }
451 : : else
452 : 0 : bRet = sal_False;
453 : :
454 [ # # ]: 0 : EndAllActionAndCall();
455 [ # # ]: 0 : return bRet;
456 : : }
457 : :
458 : : /***********************************************************************
459 : : #* Class : SwFEShell
460 : : #* Methods : MergeTab(), SplitTab()
461 : : #***********************************************************************/
462 : :
463 : 0 : sal_uInt16 SwFEShell::MergeTab()
464 : : {
465 : : // check if Point/Mark of current cursor are in a table
466 : 0 : sal_uInt16 nRet = TBLMERGE_NOSELECTION;
467 [ # # ]: 0 : if( IsTableMode() )
468 : : {
469 : 0 : SwShellTableCrsr* pTableCrsr = GetTableCrsr();
470 : 0 : const SwTableNode* pTblNd = pTableCrsr->GetNode()->FindTableNode();
471 [ # # ]: 0 : if( pTblNd->GetTable().ISA( SwDDETable ))
472 : : {
473 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
474 : 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
475 : : }
476 : : else
477 : : {
478 [ # # ]: 0 : SET_CURR_SHELL( this );
479 [ # # ]: 0 : StartAllAction();
480 : :
481 : 0 : TblWait( pTableCrsr->GetBoxesCount(), 0, *GetDoc()->GetDocShell(),
482 [ # # ][ # # ]: 0 : pTblNd->GetTable().GetTabLines().size() );
483 : :
484 [ # # ]: 0 : nRet = GetDoc()->MergeTbl( *pTableCrsr );
485 : :
486 [ # # ]: 0 : KillPams();
487 : :
488 [ # # ][ # # ]: 0 : EndAllActionAndCall();
489 : : }
490 : : }
491 : 0 : return nRet;
492 : : }
493 : :
494 : 0 : sal_Bool SwFEShell::SplitTab( sal_Bool bVert, sal_uInt16 nCnt, sal_Bool bSameHeight )
495 : : {
496 : : // check if Point/Mark of current cursor are in a table
497 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
498 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
499 : 0 : return sal_False;
500 : :
501 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
502 : : {
503 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
504 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
505 : 0 : return sal_False;
506 : : }
507 : :
508 [ # # ]: 0 : SET_CURR_SHELL( this );
509 : :
510 [ # # ][ # # ]: 0 : if( bVert && !CheckSplitCells( *this, nCnt + 1 ) )
[ # # ][ # # ]
511 : : {
512 : : ErrorHandler::HandleError( ERR_TBLSPLIT_ERROR,
513 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
514 : 0 : return sal_False;
515 : : }
516 [ # # ]: 0 : StartAllAction();
517 : : // search boxes via the layout
518 : : sal_Bool bRet;
519 [ # # ]: 0 : SwSelBoxes aBoxes;
520 [ # # ]: 0 : GetTblSel( *this, aBoxes );
521 [ # # ]: 0 : if( !aBoxes.empty() )
522 : : {
523 [ # # ][ # # ]: 0 : TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.size() );
524 : :
525 : : // now delete the columns
526 [ # # ]: 0 : bRet = GetDoc()->SplitTbl( aBoxes, bVert, nCnt, bSameHeight );
527 : :
528 [ # # ]: 0 : DELETEZ( pLastCols );
529 [ # # ]: 0 : DELETEZ( pLastRows );
530 : : }
531 : : else
532 : 0 : bRet = sal_False;
533 [ # # ]: 0 : EndAllActionAndCall();
534 [ # # ]: 0 : return bRet;
535 : : }
536 : :
537 : :
538 : : /***********************************************************************
539 : : #* Class : SwFEShell
540 : : #* Methods : _GetTabCols
541 : : #***********************************************************************/
542 : 10 : void SwFEShell::_GetTabCols( SwTabCols &rToFill, const SwFrm *pBox ) const
543 : : {
544 : 10 : const SwTabFrm *pTab = pBox->FindTabFrm();
545 [ + + ]: 10 : if ( pLastCols )
546 : : {
547 : 8 : sal_Bool bDel = sal_True;
548 [ + - ]: 8 : if ( pColumnCacheLastTable == pTab->GetTable() )
549 : : {
550 : 8 : bDel = sal_False;
551 [ - + ][ # # ]: 8 : SWRECTFN( pTab )
[ # # ][ - + ]
552 : :
553 : 8 : const SwPageFrm* pPage = pTab->FindPageFrm();
554 [ + - ]: 8 : const sal_uLong nLeftMin = (pTab->Frm().*fnRect->fnGetLeft)() -
555 [ + - ]: 8 : (pPage->Frm().*fnRect->fnGetLeft)();
556 [ + - ]: 8 : const sal_uLong nRightMax = (pTab->Frm().*fnRect->fnGetRight)() -
557 [ + - ]: 8 : (pPage->Frm().*fnRect->fnGetLeft)();
558 : :
559 [ - + ]: 8 : if ( pColumnCacheLastTabFrm != pTab )
560 : : {
561 : : // if TabFrm was changed, we only shift a little bit
562 : : // as the width is the same
563 [ # # ][ # # ]: 0 : SWRECTFNX( pColumnCacheLastTabFrm )
[ # # ][ # # ]
564 [ # # ][ # # ]: 0 : if( (pColumnCacheLastTabFrm->Frm().*fnRectX->fnGetWidth)() ==
565 [ # # ]: 0 : (pTab->Frm().*fnRect->fnGetWidth)() )
566 : : {
567 : 0 : pLastCols->SetLeftMin( nLeftMin );
568 : :
569 : 0 : pColumnCacheLastTabFrm = pTab;
570 : : }
571 : : else
572 : 0 : bDel = sal_True;
573 : : }
574 : :
575 [ + - + - : 40 : if ( !bDel &&
+ - + - +
- ][ + - ]
576 : 8 : pLastCols->GetLeftMin () == (sal_uInt16)nLeftMin &&
577 [ + - ]: 8 : pLastCols->GetLeft () == (sal_uInt16)(pTab->Prt().*fnRect->fnGetLeft)() &&
578 [ + - ]: 8 : pLastCols->GetRight () == (sal_uInt16)(pTab->Prt().*fnRect->fnGetRight)()&&
579 : 8 : pLastCols->GetRightMax() == (sal_uInt16)nRightMax - pLastCols->GetLeftMin() )
580 : : {
581 [ - + ]: 8 : if ( pColumnCacheLastCellFrm != pBox )
582 : : {
583 : : pTab->GetTable()->GetTabCols( *pLastCols,
584 : 0 : ((SwCellFrm*)pBox)->GetTabBox(), sal_True);
585 : 0 : pColumnCacheLastCellFrm = pBox;
586 : : }
587 : 8 : rToFill = *pLastCols;
588 : : }
589 : : else
590 : 0 : bDel = sal_True;
591 : : }
592 [ - + ]: 8 : if ( bDel )
593 [ # # ]: 0 : DELETEZ(pLastCols);
594 : : }
595 [ + + ]: 10 : if ( !pLastCols )
596 : : {
597 : 2 : GetDoc()->GetTabCols( rToFill, 0, (SwCellFrm*)pBox );
598 : :
599 [ + - ]: 2 : pLastCols = new SwTabCols( rToFill );
600 : 2 : pColumnCacheLastTable = pTab->GetTable();
601 : 2 : pColumnCacheLastTabFrm = pTab;
602 : 2 : pColumnCacheLastCellFrm= pBox;
603 : : }
604 : :
605 : : #if OSL_DEBUG_LEVEL > 1
606 : : SwTabColsEntry aEntry;
607 : : for ( sal_uInt16 i = 0; i < rToFill.Count(); ++i )
608 : : {
609 : : aEntry = rToFill.GetEntry( i );
610 : : (void)aEntry;
611 : : }
612 : : #endif
613 : 10 : }
614 : :
615 : : /***********************************************************************
616 : : #* Class : SwFEShell
617 : : #* Methods : _GetTabRows
618 : : #***********************************************************************/
619 : 5 : void SwFEShell::_GetTabRows( SwTabCols &rToFill, const SwFrm *pBox ) const
620 : : {
621 : 5 : const SwTabFrm *pTab = pBox->FindTabFrm();
622 [ + + ]: 5 : if ( pLastRows )
623 : : {
624 : 3 : sal_Bool bDel = sal_True;
625 [ + - ]: 3 : if ( pRowCacheLastTable == pTab->GetTable() )
626 : : {
627 : 3 : bDel = sal_False;
628 [ - + ][ # # ]: 3 : SWRECTFN( pTab )
[ # # ][ - + ]
629 : 3 : const SwPageFrm* pPage = pTab->FindPageFrm();
630 : : const long nLeftMin = ( bVert ?
631 : 0 : pTab->GetPrtLeft() - pPage->Frm().Left() :
632 [ - + ]: 3 : pTab->GetPrtTop() - pPage->Frm().Top() );
633 [ - + ]: 3 : const long nLeft = bVert ? LONG_MAX : 0;
634 [ + - ]: 3 : const long nRight = (pTab->Prt().*fnRect->fnGetHeight)();
635 [ - + ]: 3 : const long nRightMax = bVert ? nRight : LONG_MAX;
636 : :
637 [ + - ][ - + ]: 3 : if ( pRowCacheLastTabFrm != pTab ||
638 : : pRowCacheLastCellFrm != pBox )
639 : 0 : bDel = sal_True;
640 : :
641 [ + - + - : 15 : if ( !bDel &&
+ - + - +
- ][ + - ]
642 : 3 : pLastRows->GetLeftMin () == nLeftMin &&
643 : 3 : pLastRows->GetLeft () == nLeft &&
644 : 3 : pLastRows->GetRight () == nRight &&
645 : 3 : pLastRows->GetRightMax() == nRightMax )
646 : : {
647 : 3 : rToFill = *pLastRows;
648 : : }
649 : : else
650 : 0 : bDel = sal_True;
651 : : }
652 [ - + ]: 3 : if ( bDel )
653 [ # # ]: 0 : DELETEZ(pLastRows);
654 : : }
655 [ + + ]: 5 : if ( !pLastRows )
656 : : {
657 : 2 : GetDoc()->GetTabRows( rToFill, 0, (SwCellFrm*)pBox );
658 : :
659 [ + - ]: 2 : pLastRows = new SwTabCols( rToFill );
660 : 2 : pRowCacheLastTable = pTab->GetTable();
661 : 2 : pRowCacheLastTabFrm = pTab;
662 : 2 : pRowCacheLastCellFrm= pBox;
663 : : }
664 : 5 : }
665 : :
666 : : /***********************************************************************
667 : : #* Class : SwFEShell
668 : : #* Methods : SetTabCols(), GetTabCols()
669 : : #***********************************************************************/
670 : 0 : void SwFEShell::SetTabCols( const SwTabCols &rNew, sal_Bool bCurRowOnly )
671 : : {
672 [ # # ]: 0 : SwFrm *pBox = GetCurrFrm();
673 [ # # ][ # # ]: 0 : if( !pBox || !pBox->IsInTab() )
[ # # ][ # # ]
674 : 0 : return;
675 : :
676 [ # # ]: 0 : SET_CURR_SHELL( this );
677 [ # # ]: 0 : StartAllAction();
678 : :
679 [ # # ]: 0 : do {
680 : 0 : pBox = pBox->GetUpper();
681 : 0 : } while ( !pBox->IsCellFrm() );
682 : :
683 [ # # ]: 0 : GetDoc()->SetTabCols( rNew, bCurRowOnly, 0, (SwCellFrm*)pBox );
684 [ # # ][ # # ]: 0 : EndAllActionAndCall();
685 : : }
686 : :
687 : 10 : void SwFEShell::GetTabCols( SwTabCols &rToFill ) const
688 : : {
689 : 10 : const SwFrm *pFrm = GetCurrFrm();
690 [ - + ][ - + ]: 10 : if( !pFrm || !pFrm->IsInTab() )
[ + - ]
691 : 10 : return;
692 [ - + ]: 10 : do
693 : 10 : { pFrm = pFrm->GetUpper();
694 : 10 : } while ( !pFrm->IsCellFrm() );
695 : :
696 : 10 : _GetTabCols( rToFill, pFrm );
697 : : }
698 : :
699 : 5 : void SwFEShell::GetTabRows( SwTabCols &rToFill ) const
700 : : {
701 : 5 : const SwFrm *pFrm = GetCurrFrm();
702 [ - + ][ - + ]: 5 : if( !pFrm || !pFrm->IsInTab() )
[ + - ]
703 : 5 : return;
704 [ - + ]: 5 : do
705 : 5 : { pFrm = pFrm->GetUpper();
706 : 5 : } while ( !pFrm->IsCellFrm() );
707 : :
708 : 5 : _GetTabRows( rToFill, pFrm );
709 : : }
710 : :
711 : 0 : void SwFEShell::SetTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly )
712 : : {
713 [ # # ]: 0 : SwFrm *pBox = GetCurrFrm();
714 [ # # ][ # # ]: 0 : if( !pBox || !pBox->IsInTab() )
[ # # ][ # # ]
715 : 0 : return;
716 : :
717 [ # # ]: 0 : SET_CURR_SHELL( this );
718 [ # # ]: 0 : StartAllAction();
719 : :
720 [ # # ]: 0 : do {
721 : 0 : pBox = pBox->GetUpper();
722 : 0 : } while ( !pBox->IsCellFrm() );
723 : :
724 [ # # ]: 0 : GetDoc()->SetTabRows( rNew, bCurColOnly, 0, (SwCellFrm*)pBox );
725 [ # # ][ # # ]: 0 : EndAllActionAndCall();
726 : : }
727 : :
728 : 0 : void SwFEShell::GetMouseTabRows( SwTabCols &rToFill, const Point &rPt ) const
729 : : {
730 : 0 : const SwFrm *pBox = GetBox( rPt );
731 [ # # ]: 0 : if ( pBox )
732 : 0 : _GetTabRows( rToFill, pBox );
733 : 0 : }
734 : :
735 : 0 : void SwFEShell::SetMouseTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly, const Point &rPt )
736 : : {
737 : 0 : const SwFrm *pBox = GetBox( rPt );
738 [ # # ]: 0 : if( pBox )
739 : : {
740 [ # # ]: 0 : SET_CURR_SHELL( this );
741 [ # # ]: 0 : StartAllAction();
742 [ # # ]: 0 : GetDoc()->SetTabRows( rNew, bCurColOnly, 0, (SwCellFrm*)pBox );
743 [ # # ][ # # ]: 0 : EndAllActionAndCall();
744 : : }
745 : 0 : }
746 : :
747 : : /***********************************************************************
748 : : * Class : SwFEShell
749 : : * Methods : SetRowSplit(), GetRowSplit()
750 : : ***********************************************************************/
751 : :
752 : 0 : void SwFEShell::SetRowSplit( const SwFmtRowSplit& rNew )
753 : : {
754 [ # # ]: 0 : SET_CURR_SHELL( this );
755 [ # # ]: 0 : StartAllAction();
756 [ # # ][ # # ]: 0 : GetDoc()->SetRowSplit( *getShellCrsr( false ), rNew );
757 [ # # ][ # # ]: 0 : EndAllActionAndCall();
758 : 0 : }
759 : :
760 : 0 : void SwFEShell::GetRowSplit( SwFmtRowSplit*& rpSz ) const
761 : : {
762 : 0 : GetDoc()->GetRowSplit( *getShellCrsr( false ), rpSz );
763 : 0 : }
764 : :
765 : :
766 : : /***********************************************************************
767 : : * Class : SwFEShell
768 : : * Methods : SetRowHeight(), GetRowHeight()
769 : : ***********************************************************************/
770 : 0 : void SwFEShell::SetRowHeight( const SwFmtFrmSize &rNew )
771 : : {
772 [ # # ]: 0 : SET_CURR_SHELL( this );
773 [ # # ]: 0 : StartAllAction();
774 [ # # ][ # # ]: 0 : GetDoc()->SetRowHeight( *getShellCrsr( false ), rNew );
775 [ # # ][ # # ]: 0 : EndAllActionAndCall();
776 : 0 : }
777 : :
778 : : /******************************************************************************
779 : : * SwTwips SwFEShell::GetRowHeight() const
780 : : ******************************************************************************/
781 : 0 : void SwFEShell::GetRowHeight( SwFmtFrmSize *& rpSz ) const
782 : : {
783 : 0 : GetDoc()->GetRowHeight( *getShellCrsr( false ), rpSz );
784 : 0 : }
785 : :
786 : 3 : sal_Bool SwFEShell::BalanceRowHeight( sal_Bool bTstOnly )
787 : : {
788 [ + - ]: 3 : SET_CURR_SHELL( this );
789 [ - + ]: 3 : if( !bTstOnly )
790 [ # # ]: 0 : StartAllAction();
791 [ + - ][ + - ]: 3 : sal_Bool bRet = GetDoc()->BalanceRowHeight( *getShellCrsr( false ), bTstOnly );
792 [ - + ]: 3 : if( !bTstOnly )
793 [ # # ]: 0 : EndAllActionAndCall();
794 [ + - ]: 3 : return bRet;
795 : : }
796 : :
797 : : /******************************************************************************
798 : : * void SwFEShell::SetRowBackground()
799 : : ******************************************************************************/
800 : 0 : void SwFEShell::SetRowBackground( const SvxBrushItem &rNew )
801 : : {
802 [ # # ]: 0 : SET_CURR_SHELL( this );
803 [ # # ]: 0 : StartAllAction();
804 [ # # ][ # # ]: 0 : GetDoc()->SetRowBackground( *getShellCrsr( false ), rNew );
805 [ # # ][ # # ]: 0 : EndAllActionAndCall();
806 : 0 : }
807 : :
808 : : /******************************************************************************
809 : : * SwTwips SwFEShell::GetRowBackground() const
810 : : ******************************************************************************/
811 : 0 : sal_Bool SwFEShell::GetRowBackground( SvxBrushItem &rToFill ) const
812 : : {
813 : 0 : return GetDoc()->GetRowBackground( *getShellCrsr( false ), rToFill );
814 : : }
815 : :
816 : : /***********************************************************************
817 : : #* Class : SwFEShell
818 : : #* Methods : SetTabBorders(), GetTabBorders()
819 : : #***********************************************************************/
820 : :
821 : 0 : void SwFEShell::SetTabBorders( const SfxItemSet& rSet )
822 : : {
823 [ # # ]: 0 : SET_CURR_SHELL( this );
824 [ # # ]: 0 : StartAllAction();
825 [ # # ][ # # ]: 0 : GetDoc()->SetTabBorders( *getShellCrsr( false ), rSet );
826 [ # # ][ # # ]: 0 : EndAllActionAndCall();
827 : 0 : }
828 : :
829 : 0 : void SwFEShell::SetTabLineStyle( const Color* pColor, sal_Bool bSetLine,
830 : : const editeng::SvxBorderLine* pBorderLine )
831 : : {
832 [ # # ]: 0 : SET_CURR_SHELL( this );
833 [ # # ]: 0 : StartAllAction();
834 [ # # ]: 0 : GetDoc()->SetTabLineStyle( *getShellCrsr( false ),
835 [ # # ]: 0 : pColor, bSetLine, pBorderLine );
836 [ # # ][ # # ]: 0 : EndAllActionAndCall();
837 : 0 : }
838 : :
839 : 27 : void SwFEShell::GetTabBorders( SfxItemSet& rSet ) const
840 : : {
841 : 27 : GetDoc()->GetTabBorders( *getShellCrsr( false ), rSet );
842 : 27 : }
843 : :
844 : :
845 : : /***********************************************************************
846 : : #* Class : SwFEShell
847 : : #* Methods : SetBoxBackground(), GetBoxBackground()
848 : : #***********************************************************************/
849 : 0 : void SwFEShell::SetBoxBackground( const SvxBrushItem &rNew )
850 : : {
851 [ # # ]: 0 : SET_CURR_SHELL( this );
852 [ # # ]: 0 : StartAllAction();
853 [ # # ][ # # ]: 0 : GetDoc()->SetBoxAttr( *getShellCrsr( false ), rNew );
854 [ # # ][ # # ]: 0 : EndAllActionAndCall();
855 : 0 : }
856 : :
857 : 6 : sal_Bool SwFEShell::GetBoxBackground( SvxBrushItem &rToFill ) const
858 : : {
859 : 6 : return GetDoc()->GetBoxAttr( *getShellCrsr( false ), rToFill );
860 : : }
861 : :
862 : : /***********************************************************************
863 : : #* Class : SwFEShell
864 : : #* Methods : SetBoxDirection(), GetBoxDirection()
865 : : #***********************************************************************/
866 : 0 : void SwFEShell::SetBoxDirection( const SvxFrameDirectionItem& rNew )
867 : : {
868 [ # # ]: 0 : SET_CURR_SHELL( this );
869 [ # # ]: 0 : StartAllAction();
870 [ # # ][ # # ]: 0 : GetDoc()->SetBoxAttr( *getShellCrsr( false ), rNew );
871 [ # # ][ # # ]: 0 : EndAllActionAndCall();
872 : 0 : }
873 : :
874 : 0 : sal_Bool SwFEShell::GetBoxDirection( SvxFrameDirectionItem& rToFill ) const
875 : : {
876 : 0 : return GetDoc()->GetBoxAttr( *getShellCrsr( false ), rToFill );
877 : : }
878 : :
879 : : /***********************************************************************
880 : : #* Class : SwFEShell
881 : : #* Methods : SetBoxAlign, SetBoxAlign
882 : : #***********************************************************************/
883 : 0 : void SwFEShell::SetBoxAlign( sal_uInt16 nAlign )
884 : : {
885 [ # # ]: 0 : SET_CURR_SHELL( this );
886 [ # # ]: 0 : StartAllAction();
887 [ # # ][ # # ]: 0 : GetDoc()->SetBoxAlign( *getShellCrsr( false ), nAlign );
888 [ # # ][ # # ]: 0 : EndAllActionAndCall();
889 : 0 : }
890 : :
891 : 27 : sal_uInt16 SwFEShell::GetBoxAlign() const
892 : : {
893 : 27 : return GetDoc()->GetBoxAlign( *getShellCrsr( false ) );
894 : : }
895 : :
896 : : /***********************************************************************
897 : : #* Class : SwFEShell
898 : : #* Methods : SetTabBackground(), GetTabBackground()
899 : : #***********************************************************************/
900 : 0 : void SwFEShell::SetTabBackground( const SvxBrushItem &rNew )
901 : : {
902 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
903 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
904 : 0 : return;
905 : :
906 [ # # ]: 0 : SET_CURR_SHELL( this );
907 [ # # ]: 0 : StartAllAction();
908 [ # # ][ # # ]: 0 : GetDoc()->SetAttr( rNew, *pFrm->ImplFindTabFrm()->GetFmt() );
[ # # ]
909 [ # # ]: 0 : EndAllAction(); // no call, nothing changes!
910 [ # # ][ # # ]: 0 : GetDoc()->SetModified();
911 : : }
912 : :
913 : 0 : void SwFEShell::GetTabBackground( SvxBrushItem &rToFill ) const
914 : : {
915 : 0 : SwFrm *pFrm = GetCurrFrm();
916 [ # # ][ # # ]: 0 : if( pFrm && pFrm->IsInTab() )
[ # # ]
917 : 0 : rToFill = pFrm->ImplFindTabFrm()->GetFmt()->GetBackground();
918 : 0 : }
919 : :
920 : :
921 : : /***********************************************************************
922 : : #* Class : SwFEShell
923 : : #* Methods : HasWholeTabSelection()
924 : : #***********************************************************************/
925 : 0 : sal_Bool SwFEShell::HasWholeTabSelection() const
926 : : {
927 : : // whole table selected?
928 [ # # ]: 0 : if ( IsTableMode() )
929 : : {
930 [ # # ]: 0 : SwSelBoxes aBoxes;
931 [ # # ]: 0 : ::GetTblSelCrs( *this, aBoxes );
932 [ # # ]: 0 : if( !aBoxes.empty() )
933 : : {
934 [ # # ]: 0 : const SwTableNode *pTblNd = IsCrsrInTbl();
935 : : return pTblNd &&
936 [ # # ][ # # ]: 0 : aBoxes[0]->GetSttIdx() - 1 == pTblNd->EndOfSectionNode()->StartOfSectionIndex() &&
937 [ # # # # ]: 0 : aBoxes.back()->GetSttNd()->EndOfSectionIndex() + 1 == pTblNd->EndOfSectionIndex();
[ # # ][ # # ]
938 [ # # ]: 0 : }
939 : : }
940 : 0 : return sal_False;
941 : : }
942 : :
943 : 0 : sal_Bool SwFEShell::HasBoxSelection() const
944 : : {
945 [ # # ]: 0 : if(!IsCrsrInTbl())
946 : 0 : return sal_False;
947 : : // whole table selected?
948 [ # # ]: 0 : if( IsTableMode() )
949 : 0 : return sal_True;
950 : 0 : SwPaM* pPam = GetCrsr();
951 : : // empty boxes are also selected as the absence of selection
952 : 0 : sal_Bool bChg = sal_False;
953 [ # # ]: 0 : if( pPam->GetPoint() == pPam->End())
954 : : {
955 : 0 : bChg = sal_True;
956 : 0 : pPam->Exchange();
957 : : }
958 : : SwNode* pNd;
959 [ # # # # : 0 : if( pPam->GetPoint()->nNode.GetIndex() -1 ==
# # ][ # # ]
960 : 0 : ( pNd = pPam->GetNode())->StartOfSectionIndex() &&
961 : 0 : !pPam->GetPoint()->nContent.GetIndex() &&
962 : 0 : pPam->GetMark()->nNode.GetIndex() + 1 ==
963 : 0 : pNd->EndOfSectionIndex())
964 : : {
965 [ # # ]: 0 : SwNodeIndex aIdx( *pNd->EndOfSectionNode(), -1 );
966 : 0 : SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
967 [ # # ]: 0 : if( !pCNd )
968 : : {
969 [ # # ][ # # ]: 0 : pCNd = GetDoc()->GetNodes().GoPrevious( &aIdx );
970 : : OSL_ENSURE( pCNd, "no ContentNode in box ??" );
971 : : }
972 [ # # ][ # # ]: 0 : if( pPam->GetMark()->nContent == pCNd->Len() )
973 : : {
974 [ # # ]: 0 : if( bChg )
975 : 0 : pPam->Exchange();
976 : 0 : return sal_True;
977 [ # # ][ # # ]: 0 : }
978 : : }
979 [ # # ]: 0 : if( bChg )
980 : 0 : pPam->Exchange();
981 : 0 : return sal_False;
982 : : }
983 : :
984 : : /***********************************************************************
985 : : #* Class : SwFEShell
986 : : #* Methods : ProtectCells(), UnProtectCells()
987 : : #***********************************************************************/
988 : 0 : void SwFEShell::ProtectCells()
989 : : {
990 [ # # ]: 0 : SvxProtectItem aProt( RES_PROTECT );
991 : 0 : aProt.SetCntntProtect( sal_True );
992 : :
993 [ # # ]: 0 : SET_CURR_SHELL( this );
994 [ # # ]: 0 : StartAllAction();
995 : :
996 [ # # ][ # # ]: 0 : GetDoc()->SetBoxAttr( *getShellCrsr( false ), aProt );
997 : :
998 [ # # ][ # # ]: 0 : if( !IsCrsrReadonly() )
999 : : {
1000 [ # # ]: 0 : if( IsTableMode() )
1001 [ # # ]: 0 : ClearMark();
1002 [ # # ]: 0 : ParkCursorInTab();
1003 : : }
1004 [ # # ][ # # ]: 0 : EndAllActionAndCall();
[ # # ]
1005 : 0 : }
1006 : :
1007 : : // cancel table selection
1008 : 0 : void SwFEShell::UnProtectCells()
1009 : : {
1010 [ # # ]: 0 : SET_CURR_SHELL( this );
1011 [ # # ]: 0 : StartAllAction();
1012 : :
1013 [ # # ]: 0 : SwSelBoxes aBoxes;
1014 [ # # ]: 0 : if( IsTableMode() )
1015 [ # # ]: 0 : ::GetTblSelCrs( *this, aBoxes );
1016 : : else
1017 : : {
1018 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
1019 [ # # ]: 0 : do {
[ # # # # ]
1020 : 0 : pFrm = pFrm->GetUpper();
1021 : 0 : } while ( pFrm && !pFrm->IsCellFrm() );
1022 [ # # ]: 0 : if( pFrm )
1023 : : {
1024 : 0 : SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
1025 [ # # ]: 0 : aBoxes.insert( pBox );
1026 : : }
1027 : : }
1028 : :
1029 [ # # ]: 0 : if( !aBoxes.empty() )
1030 [ # # ]: 0 : GetDoc()->UnProtectCells( aBoxes );
1031 : :
1032 [ # # ][ # # ]: 0 : EndAllActionAndCall();
1033 : 0 : }
1034 : :
1035 : 0 : void SwFEShell::UnProtectTbls()
1036 : : {
1037 [ # # ]: 0 : SET_CURR_SHELL( this );
1038 [ # # ]: 0 : StartAllAction();
1039 [ # # ][ # # ]: 0 : GetDoc()->UnProtectTbls( *GetCrsr() );
1040 [ # # ][ # # ]: 0 : EndAllActionAndCall();
1041 : 0 : }
1042 : :
1043 : 0 : sal_Bool SwFEShell::HasTblAnyProtection( const String* pTblName,
1044 : : sal_Bool* pFullTblProtection )
1045 : : {
1046 : 0 : return GetDoc()->HasTblAnyProtection( GetCrsr()->GetPoint(), pTblName,
1047 : 0 : pFullTblProtection );
1048 : : }
1049 : :
1050 : 0 : sal_Bool SwFEShell::CanUnProtectCells() const
1051 : : {
1052 : 0 : sal_Bool bUnProtectAvailable = sal_False;
1053 : 0 : const SwTableNode *pTblNd = IsCrsrInTbl();
1054 [ # # ][ # # ]: 0 : if( pTblNd && !pTblNd->IsProtect() )
[ # # ]
1055 : : {
1056 [ # # ]: 0 : SwSelBoxes aBoxes;
1057 [ # # ]: 0 : if( IsTableMode() )
1058 [ # # ]: 0 : ::GetTblSelCrs( *this, aBoxes );
1059 : : else
1060 : : {
1061 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
1062 [ # # ]: 0 : do {
[ # # # # ]
1063 : 0 : pFrm = pFrm->GetUpper();
1064 : 0 : } while ( pFrm && !pFrm->IsCellFrm() );
1065 [ # # ]: 0 : if( pFrm )
1066 : : {
1067 : 0 : SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
1068 [ # # ]: 0 : aBoxes.insert( pBox );
1069 : : }
1070 : : }
1071 [ # # ]: 0 : if( !aBoxes.empty() )
1072 [ # # ]: 0 : bUnProtectAvailable = ::HasProtectedCells( aBoxes );
1073 : : }
1074 : 0 : return bUnProtectAvailable;
1075 : : }
1076 : :
1077 : : /***********************************************************************
1078 : : #* Class : SwFEShell
1079 : : #* Methods : GetRowsToRepeat(), SetRowsToRepeat()
1080 : : #***********************************************************************/
1081 : 0 : sal_uInt16 SwFEShell::GetRowsToRepeat() const
1082 : : {
1083 : 0 : const SwFrm *pFrm = GetCurrFrm();
1084 [ # # ]: 0 : const SwTabFrm *pTab = pFrm ? pFrm->FindTabFrm() : 0;
1085 [ # # ]: 0 : if( pTab )
1086 : 0 : return pTab->GetTable()->GetRowsToRepeat();
1087 : 0 : return 0;
1088 : : }
1089 : :
1090 : 0 : void SwFEShell::SetRowsToRepeat( sal_uInt16 nSet )
1091 : : {
1092 : 0 : SwFrm *pFrm = GetCurrFrm();
1093 [ # # ]: 0 : SwTabFrm *pTab = pFrm ? pFrm->FindTabFrm() : 0;
1094 [ # # ][ # # ]: 0 : if( pTab && pTab->GetTable()->GetRowsToRepeat() != nSet )
[ # # ]
1095 : : {
1096 [ # # ]: 0 : SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
1097 [ # # ]: 0 : SET_CURR_SHELL( this );
1098 [ # # ]: 0 : StartAllAction();
1099 [ # # ]: 0 : GetDoc()->SetRowsToRepeat( *pTab->GetTable(), nSet );
1100 [ # # ][ # # ]: 0 : EndAllActionAndCall();
[ # # ]
1101 : : }
1102 : 0 : }
1103 : :
1104 : : /*-------------------------------------------------------------------------
1105 : : returns the number of rows consecutively selected from top
1106 : : -----------------------------------------------------------------------*/
1107 : 0 : sal_uInt16 lcl_GetRowNumber( const SwPosition& rPos )
1108 : : {
1109 : 0 : sal_uInt16 nRet = USHRT_MAX;
1110 : 0 : Point aTmpPt;
1111 : : const SwCntntNode *pNd;
1112 : : const SwCntntFrm *pFrm;
1113 : :
1114 [ # # ]: 0 : if( 0 != ( pNd = rPos.nNode.GetNode().GetCntntNode() ))
1115 [ # # ][ # # ]: 0 : pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aTmpPt, &rPos, sal_False );
1116 : : else
1117 : 0 : pFrm = 0;
1118 : :
1119 [ # # ][ # # ]: 0 : if ( pFrm && pFrm->IsInTab() )
[ # # ][ # # ]
1120 : : {
1121 : 0 : const SwFrm* pRow = pFrm->GetUpper();
1122 [ # # ]: 0 : while ( !pRow->GetUpper()->IsTabFrm() )
1123 : 0 : pRow = pRow->GetUpper();
1124 : :
1125 : 0 : const SwTabFrm* pTabFrm = (const SwTabFrm*)pRow->GetUpper();
1126 : 0 : const SwTableLine* pTabLine = static_cast<const SwRowFrm*>(pRow)->GetTabLine();
1127 : :
1128 : 0 : sal_uInt16 nI = 0;
1129 [ # # ]: 0 : while ( nI < pTabFrm->GetTable()->GetTabLines().size() )
1130 : : {
1131 [ # # ]: 0 : if ( pTabFrm->GetTable()->GetTabLines()[ nI ] == pTabLine )
1132 : : {
1133 : 0 : nRet = nI;
1134 : 0 : break;
1135 : : }
1136 : 0 : ++nI;
1137 : : }
1138 : : }
1139 : :
1140 : 0 : return nRet;
1141 : : }
1142 : 0 : sal_uInt16 SwFEShell::GetRowSelectionFromTop() const
1143 : : {
1144 : 0 : sal_uInt16 nRet = 0;
1145 [ # # ][ # # ]: 0 : const SwPaM* pPaM = IsTableMode() ? GetTableCrsr() : _GetCrsr();
[ # # ]
1146 : 0 : const sal_uInt16 nPtLine = lcl_GetRowNumber( *pPaM->GetPoint() );
1147 : :
1148 [ # # ]: 0 : if ( !IsTableMode() )
1149 : : {
1150 [ # # ]: 0 : nRet = 0 == nPtLine ? 1 : 0;
1151 : : }
1152 : : else
1153 : : {
1154 : 0 : const sal_uInt16 nMkLine = lcl_GetRowNumber( *pPaM->GetMark() );
1155 : :
1156 [ # # ][ # # ]: 0 : if ( ( nPtLine == 0 && nMkLine != USHRT_MAX ) ||
[ # # ][ # # ]
1157 : : ( nMkLine == 0 && nPtLine != USHRT_MAX ) )
1158 : : {
1159 : 0 : nRet = Max( nPtLine, nMkLine ) + 1;
1160 : : }
1161 : : }
1162 : :
1163 : 0 : return nRet;
1164 : : }
1165 : :
1166 : : /*
1167 : : * 1. case: bRepeat = true
1168 : : * returns true if the current frame is located inside a table headline in
1169 : : * a follow frame
1170 : : *
1171 : : * 2. case: bRepeat = false
1172 : : * returns true if the current frame is localed inside a table headline OR
1173 : : * inside the first line of a table!!!
1174 : : */
1175 : 9 : sal_Bool SwFEShell::CheckHeadline( bool bRepeat ) const
1176 : : {
1177 : 9 : sal_Bool bRet = sal_False;
1178 [ + + ]: 9 : if ( !IsTableMode() )
1179 : : {
1180 : 3 : SwFrm *pFrm = GetCurrFrm(); // DONE MULTIIHEADER
1181 [ + - ][ + - ]: 3 : if ( pFrm && pFrm->IsInTab() )
[ + - ]
1182 : : {
1183 : 3 : SwTabFrm* pTab = pFrm->FindTabFrm();
1184 [ + - ]: 3 : if ( bRepeat )
1185 : : {
1186 [ - + ][ # # ]: 3 : bRet = pTab->IsFollow() && pTab->IsInHeadline( *pFrm );
1187 : : }
1188 : : else
1189 : : {
1190 : 0 : bRet = ((SwLayoutFrm*)pTab->Lower())->IsAnLower( pFrm ) ||
1191 [ # # ][ # # ]: 0 : pTab->IsInHeadline( *pFrm );
1192 : : }
1193 : : }
1194 : : }
1195 : 9 : return bRet;
1196 : : }
1197 : :
1198 : : /***********************************************************************
1199 : : #* Class : SwFEShell
1200 : : #* Methoden : AdjustCellWidth()
1201 : : #***********************************************************************/
1202 : :
1203 : 0 : void SwFEShell::AdjustCellWidth( sal_Bool bBalance )
1204 : : {
1205 [ # # ]: 0 : SET_CURR_SHELL( this );
1206 [ # # ]: 0 : StartAllAction();
1207 : :
1208 : : // switch on wait-cursor, as we do not know how
1209 : : // much content is affected
1210 [ # # ]: 0 : TblWait aWait( USHRT_MAX, 0, *GetDoc()->GetDocShell() );
1211 : :
1212 [ # # ][ # # ]: 0 : GetDoc()->AdjustCellWidth( *getShellCrsr( false ), bBalance );
1213 [ # # ][ # # ]: 0 : EndAllActionAndCall();
[ # # ]
1214 : 0 : }
1215 : :
1216 : 6 : sal_Bool SwFEShell::IsAdjustCellWidthAllowed( sal_Bool bBalance ) const
1217 : : {
1218 : : // at least one row with content should be contained in the selection
1219 : :
1220 [ + - ]: 6 : SwFrm *pFrm = GetCurrFrm();
1221 [ + - ][ + - ]: 6 : if( !pFrm || !pFrm->IsInTab() )
[ - + ][ - + ]
1222 : 0 : return sal_False;
1223 : :
1224 [ + - ]: 6 : SwSelBoxes aBoxes;
1225 [ + - ]: 6 : ::GetTblSelCrs( *this, aBoxes );
1226 : :
1227 [ + + ]: 6 : if ( bBalance )
1228 : 3 : return aBoxes.size() > 1;
1229 : :
1230 [ + - ]: 3 : if ( aBoxes.empty() )
1231 : : {
1232 [ - + ]: 3 : do
1233 : 3 : { pFrm = pFrm->GetUpper();
1234 : 3 : } while ( !pFrm->IsCellFrm() );
1235 : 3 : SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
1236 [ + - ]: 3 : aBoxes.insert( pBox );
1237 : : }
1238 : :
1239 [ + + ]: 6 : for ( sal_uInt16 i = 0; i < aBoxes.size(); ++i )
1240 : : {
1241 [ + - ]: 3 : SwTableBox *pBox = aBoxes[i];
1242 [ + - ]: 3 : if ( pBox->GetSttNd() )
1243 : : {
1244 [ + - ]: 3 : SwNodeIndex aIdx( *pBox->GetSttNd(), 1 );
1245 : 3 : SwTxtNode* pCNd = aIdx.GetNode().GetTxtNode();
1246 [ - + ]: 3 : if( !pCNd )
1247 [ # # ][ # # ]: 0 : pCNd = (SwTxtNode*)GetDoc()->GetNodes().GoNext( &aIdx );
1248 : :
1249 [ + + ]: 6 : while ( pCNd )
1250 : : {
1251 [ - + ]: 3 : if ( pCNd->GetTxt().Len() )
1252 : 0 : return sal_True;
1253 [ + - ]: 3 : ++aIdx;
1254 : 3 : pCNd = aIdx.GetNode().GetTxtNode();
1255 [ + - ][ + - ]: 3 : }
1256 : : }
1257 : : }
1258 : 6 : return sal_False;
1259 : : }
1260 : :
1261 : : // AutoFormat for the table/table selection
1262 : 0 : sal_Bool SwFEShell::SetTableAutoFmt( const SwTableAutoFmt& rNew )
1263 : : {
1264 [ # # ]: 0 : SwTableNode *pTblNd = (SwTableNode*)IsCrsrInTbl();
1265 [ # # ][ # # ]: 0 : if( !pTblNd || pTblNd->GetTable().IsTblComplex() )
[ # # ][ # # ]
1266 : 0 : return sal_False;
1267 : :
1268 [ # # ]: 0 : SwSelBoxes aBoxes;
1269 : :
1270 [ # # ]: 0 : if ( !IsTableMode() ) // if cursors are not current
1271 [ # # ]: 0 : GetCrsr();
1272 : :
1273 : : // whole table or only current selection
1274 [ # # ]: 0 : if( IsTableMode() )
1275 [ # # ]: 0 : ::GetTblSelCrs( *this, aBoxes );
1276 : : else
1277 : : {
1278 : 0 : const SwTableSortBoxes& rTBoxes = pTblNd->GetTable().GetTabSortBoxes();
1279 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rTBoxes.size(); ++n )
1280 : : {
1281 [ # # ]: 0 : SwTableBox* pBox = rTBoxes[ n ];
1282 [ # # ]: 0 : aBoxes.insert( pBox );
1283 : : }
1284 : : }
1285 : :
1286 : : sal_Bool bRet;
1287 [ # # ]: 0 : if( !aBoxes.empty() )
1288 : : {
1289 [ # # ]: 0 : SET_CURR_SHELL( this );
1290 [ # # ]: 0 : StartAllAction();
1291 [ # # ]: 0 : bRet = GetDoc()->SetTableAutoFmt( aBoxes, rNew );
1292 [ # # ]: 0 : DELETEZ( pLastCols );
1293 [ # # ]: 0 : DELETEZ( pLastRows );
1294 [ # # ][ # # ]: 0 : EndAllActionAndCall();
1295 : : }
1296 : : else
1297 : 0 : bRet = sal_False;
1298 : 0 : return bRet;
1299 : : }
1300 : :
1301 : 0 : sal_Bool SwFEShell::GetTableAutoFmt( SwTableAutoFmt& rGet )
1302 : : {
1303 [ # # ]: 0 : const SwTableNode *pTblNd = IsCrsrInTbl();
1304 [ # # ][ # # ]: 0 : if( !pTblNd || pTblNd->GetTable().IsTblComplex() )
[ # # ][ # # ]
1305 : 0 : return sal_False;
1306 : :
1307 [ # # ]: 0 : SwSelBoxes aBoxes;
1308 : :
1309 [ # # ]: 0 : if ( !IsTableMode() ) // if cursor are not current
1310 [ # # ]: 0 : GetCrsr();
1311 : :
1312 : : // whole table or only current selection
1313 [ # # ]: 0 : if( IsTableMode() )
1314 [ # # ]: 0 : ::GetTblSelCrs( *this, aBoxes );
1315 : : else
1316 : : {
1317 : 0 : const SwTableSortBoxes& rTBoxes = pTblNd->GetTable().GetTabSortBoxes();
1318 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rTBoxes.size(); ++n )
1319 : : {
1320 [ # # ]: 0 : SwTableBox* pBox = rTBoxes[ n ];
1321 [ # # ]: 0 : aBoxes.insert( pBox );
1322 : : }
1323 : : }
1324 : :
1325 [ # # ]: 0 : return GetDoc()->GetTableAutoFmt( aBoxes, rGet );
1326 : : }
1327 : :
1328 : : /***********************************************************************
1329 : : #* Class : SwFEShell
1330 : : #* Methoden : DeleteTblSel()
1331 : : #***********************************************************************/
1332 : 0 : sal_Bool SwFEShell::DeleteTblSel()
1333 : : {
1334 : : // check if SPoint/Mark of current cursor are in a table
1335 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
1336 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
1337 : 0 : return sal_False;
1338 : :
1339 [ # # ][ # # ]: 0 : if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ][ # # ]
1340 : : {
1341 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
1342 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
1343 : 0 : return sal_False;
1344 : : }
1345 : :
1346 [ # # ]: 0 : SET_CURR_SHELL( this );
1347 [ # # ]: 0 : StartAllAction();
1348 : :
1349 : : // search boxes via the layout
1350 : : sal_Bool bRet;
1351 [ # # ]: 0 : SwSelBoxes aBoxes;
1352 [ # # ]: 0 : GetTblSelCrs( *this, aBoxes );
1353 [ # # ]: 0 : if( !aBoxes.empty() )
1354 : : {
1355 [ # # ][ # # ]: 0 : TblWait( aBoxes.size(), pFrm, *GetDoc()->GetDocShell() );
1356 : :
1357 : : // cursor should be removed from deletion area.
1358 : : // Put them behind/on the table; via the document
1359 : : // position they'll be set to the old position
1360 [ # # ]: 0 : while( !pFrm->IsCellFrm() )
1361 : 0 : pFrm = pFrm->GetUpper();
1362 [ # # ][ # # ]: 0 : ParkCrsr( SwNodeIndex( *((SwCellFrm*)pFrm)->GetTabBox()->GetSttNd() ));
[ # # ]
1363 : :
1364 [ # # ]: 0 : bRet = GetDoc()->DeleteRowCol( aBoxes );
1365 : :
1366 [ # # ]: 0 : DELETEZ( pLastCols );
1367 [ # # ]: 0 : DELETEZ( pLastRows );
1368 : : }
1369 : : else
1370 : 0 : bRet = sal_False;
1371 [ # # ]: 0 : EndAllActionAndCall();
1372 [ # # ]: 0 : return bRet;
1373 : : }
1374 : :
1375 : : /*************************************************************************
1376 : : |*
1377 : : |* SwFEShell::GetCurTabColNum()
1378 : : |*
1379 : : |*************************************************************************/
1380 : 5 : sal_uInt16 SwFEShell::GetCurTabColNum() const
1381 : : {
1382 : : //!!!GetCurMouseTabColNum() mitpflegen!!!!
1383 : 5 : sal_uInt16 nRet = 0;
1384 : :
1385 : 5 : SwFrm *pFrm = GetCurrFrm();
1386 : : OSL_ENSURE( pFrm, "Crsr parked?" );
1387 : :
1388 : : // check if SPoint/Mark of current cursor are in a table
1389 [ + - ][ + - ]: 5 : if( pFrm && pFrm->IsInTab() )
[ + - ]
1390 : : {
1391 [ - + ]: 5 : do { // JP 26.09.95: why compare with CntntFrame
1392 : : // and not with CellFrame ????
1393 : 5 : pFrm = pFrm->GetUpper();
1394 : 5 : } while ( !pFrm->IsCellFrm() );
1395 [ + - ][ - + ]: 5 : SWRECTFN( pFrm )
[ # # ][ # # ]
[ - + ]
1396 : :
1397 [ + - ]: 5 : const SwPageFrm* pPage = pFrm->FindPageFrm();
1398 : :
1399 : : // get TabCols, as only via these we get to the position
1400 [ + - ]: 5 : SwTabCols aTabCols;
1401 [ + - ]: 5 : GetTabCols( aTabCols );
1402 : :
1403 [ + - ][ + - ]: 5 : if( pFrm->FindTabFrm()->IsRightToLeft() )
[ - + ]
1404 : : {
1405 [ # # ][ # # ]: 0 : long nX = (pFrm->Frm().*fnRect->fnGetRight)() - (pPage->Frm().*fnRect->fnGetLeft)();
[ # # ][ # # ]
1406 : :
1407 : 0 : const long nRight = aTabCols.GetLeftMin() + aTabCols.GetRight();;
1408 : :
1409 [ # # ][ # # ]: 0 : if ( !::IsSame( nX, nRight ) )
1410 : : {
1411 : 0 : nX = nRight - nX + aTabCols.GetLeft();
1412 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
1413 [ # # ][ # # ]: 0 : if ( ::IsSame( nX, aTabCols[i] ) )
[ # # ]
1414 : : {
1415 : 0 : nRet = i + 1;
1416 : 0 : break;
1417 : : }
1418 : : }
1419 : : }
1420 : : else
1421 : : {
1422 [ + - ][ + - ]: 5 : const long nX = (pFrm->Frm().*fnRect->fnGetLeft)() -
1423 [ + - ][ + - ]: 5 : (pPage->Frm().*fnRect->fnGetLeft)();
1424 : :
1425 : 5 : const long nLeft = aTabCols.GetLeftMin();
1426 : :
1427 [ - + ][ + - ]: 5 : if ( !::IsSame( nX, nLeft + aTabCols.GetLeft() ) )
1428 : : {
1429 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
1430 [ # # ][ # # ]: 0 : if ( ::IsSame( nX, nLeft + aTabCols[i] ) )
[ # # ]
1431 : : {
1432 : 0 : nRet = i + 1;
1433 : 0 : break;
1434 : : }
1435 : : }
1436 : 5 : }
1437 : : }
1438 : 5 : return nRet;
1439 : : }
1440 : :
1441 : : /*************************************************************************
1442 : : |*
1443 : : |* SwFEShell::GetBox()
1444 : : |*
1445 : : |*************************************************************************/
1446 : :
1447 : 0 : const SwFrm *lcl_FindFrmInTab( const SwLayoutFrm *pLay, const Point &rPt, SwTwips nFuzzy )
1448 : : {
1449 : 0 : const SwFrm *pFrm = pLay->Lower();
1450 : :
1451 [ # # ][ # # ]: 0 : while( pFrm && pLay->IsAnLower( pFrm ) )
[ # # ]
1452 : : {
1453 [ # # ]: 0 : if ( pFrm->Frm().IsNear( rPt, nFuzzy ) )
1454 : : {
1455 [ # # ]: 0 : if ( pFrm->IsLayoutFrm() )
1456 : : {
1457 : 0 : const SwFrm *pTmp = ::lcl_FindFrmInTab( (SwLayoutFrm*)pFrm, rPt, nFuzzy );
1458 [ # # ]: 0 : if ( pTmp )
1459 : 0 : return pTmp;
1460 : : }
1461 : :
1462 : 0 : return pFrm;
1463 : : }
1464 : :
1465 : 0 : pFrm = pFrm->FindNext();
1466 : : }
1467 : :
1468 : 0 : return 0;
1469 : : }
1470 : :
1471 : 0 : const SwCellFrm *lcl_FindFrm( const SwLayoutFrm *pLay, const Point &rPt,
1472 : : SwTwips nFuzzy, bool* pbRow, bool* pbCol )
1473 : : {
1474 : : // bMouseMoveRowCols :
1475 : : // Method is called for
1476 : : // - Moving columns/rows with the mouse or
1477 : : // - Enhanced table selection
1478 : 0 : const bool bMouseMoveRowCols = 0 == pbCol;
1479 : :
1480 : 0 : bool bCloseToRow = false;
1481 : 0 : bool bCloseToCol = false;
1482 : :
1483 : 0 : const SwFrm *pFrm = pLay->ContainsCntnt();
1484 : 0 : const SwFrm* pRet = 0;
1485 : :
1486 [ # # ]: 0 : if ( pFrm )
1487 : : {
1488 [ # # ]: 0 : do
[ # # # # ]
1489 : : {
1490 [ # # ]: 0 : if ( pFrm->IsInTab() )
1491 : 0 : pFrm = ((SwFrm*)pFrm)->ImplFindTabFrm();
1492 : :
1493 [ # # ]: 0 : if ( pFrm->IsTabFrm() )
1494 : : {
1495 : 0 : Point aPt( rPt );
1496 : 0 : bool bSearchForFrmInTab = true;
1497 : 0 : SwTwips nTmpFuzzy = nFuzzy;
1498 : :
1499 [ # # ]: 0 : if ( !bMouseMoveRowCols )
1500 : : {
1501 : : // We ignore nested tables for the enhanced table selection:
1502 [ # # ][ # # ]: 0 : while ( pFrm->GetUpper()->IsInTab() )
1503 [ # # ]: 0 : pFrm = pFrm->GetUpper()->FindTabFrm();
1504 : :
1505 : : // We first check if the given point is 'close' to the left or top
1506 : : // border of the table frame:
1507 : : OSL_ENSURE( pFrm, "Nested table frame without outer table" );
1508 [ # # ][ # # ]: 0 : SWRECTFN( pFrm )
[ # # ][ # # ]
[ # # ]
1509 [ # # ]: 0 : const bool bRTL = pFrm->IsRightToLeft();
1510 : :
1511 : 0 : SwRect aTabRect = pFrm->Prt();
1512 : 0 : aTabRect.Pos() += pFrm->Frm().Pos();
1513 : :
1514 : : const SwTwips nLeft = bRTL ?
1515 [ # # ]: 0 : (aTabRect.*fnRect->fnGetRight)() :
1516 [ # # ][ # # ]: 0 : (aTabRect.*fnRect->fnGetLeft)();
[ # # ][ # # ]
1517 [ # # ][ # # ]: 0 : const SwTwips nTop = (aTabRect.*fnRect->fnGetTop)();
1518 : :
1519 [ # # ]: 0 : SwTwips& rPointX = bVert ? aPt.Y() : aPt.X();
1520 [ # # ]: 0 : SwTwips& rPointY = bVert ? aPt.X() : aPt.Y();
1521 : :
1522 [ # # ][ # # ]: 0 : const SwTwips nXDiff = (*fnRect->fnXDiff)( nLeft, rPointX ) * ( bRTL ? (-1) : 1 );
1523 [ # # ]: 0 : const SwTwips nYDiff = (*fnRect->fnYDiff)( nTop, rPointY );
1524 : :
1525 [ # # ][ # # ]: 0 : bCloseToRow = nXDiff >= 0 && nXDiff < nFuzzy;
1526 [ # # ][ # # ]: 0 : bCloseToCol = nYDiff >= 0 && nYDiff < nFuzzy;
1527 : :
1528 [ # # ][ # # ]: 0 : if ( bCloseToCol && 2 * nYDiff > nFuzzy )
1529 : : {
1530 : 0 : const SwFrm* pPrev = pFrm->GetPrev();
1531 [ # # ]: 0 : if ( pPrev )
1532 : : {
1533 : 0 : SwRect aPrevRect = pPrev->Prt();
1534 : 0 : aPrevRect.Pos() += pPrev->Frm().Pos();
1535 : :
1536 [ # # ][ # # ]: 0 : if( aPrevRect.IsInside( rPt ) )
1537 : : {
1538 : 0 : bCloseToCol = false;
1539 : : }
1540 : : }
1541 : :
1542 : : }
1543 : :
1544 : : // If we found the point to be 'close' to the left or top border
1545 : : // of the table frame, we adjust the point to be on that border:
1546 [ # # ][ # # ]: 0 : if ( bCloseToRow && bCloseToCol )
1547 [ # # ][ # # ]: 0 : aPt = bRTL ? aTabRect.TopRight() : (aTabRect.*fnRect->fnGetPos)();
[ # # ][ # # ]
1548 [ # # ]: 0 : else if ( bCloseToRow )
1549 : 0 : rPointX = nLeft;
1550 [ # # ]: 0 : else if ( bCloseToCol )
1551 : 0 : rPointY = nTop;
1552 : :
1553 [ # # ][ # # ]: 0 : if ( !bCloseToRow && !bCloseToCol )
1554 : 0 : bSearchForFrmInTab = false;
1555 : :
1556 : : // Since the point has been adjusted, we call lcl_FindFrmInTab()
1557 : : // with a fuzzy value of 1:
1558 : 0 : nTmpFuzzy = 1;
1559 : : }
1560 : :
1561 : : const SwFrm* pTmp = bSearchForFrmInTab ?
1562 : : ::lcl_FindFrmInTab( (SwLayoutFrm*)pFrm, aPt, nTmpFuzzy ) :
1563 [ # # ][ # # ]: 0 : 0;
1564 : :
1565 [ # # ]: 0 : if ( pTmp )
1566 : : {
1567 : 0 : pFrm = pTmp;
1568 : : break;
1569 : : }
1570 : : }
1571 : 0 : pFrm = pFrm->FindNextCnt();
1572 : :
1573 : 0 : } while ( pFrm && pLay->IsAnLower( pFrm ) );
1574 : : }
1575 : :
1576 [ # # ][ # # ]: 0 : if ( pFrm && pFrm->IsInTab() && pLay->IsAnLower( pFrm ) )
[ # # ][ # # ]
1577 : : {
1578 [ # # ]: 0 : do
1579 : : {
1580 : : // We allow mouse drag of table borders within nested tables,
1581 : : // but disallow hotspot selection of nested tables.
1582 [ # # ]: 0 : if ( bMouseMoveRowCols )
1583 : : {
1584 : : // find the next cell frame
1585 [ # # ][ # # ]: 0 : while ( pFrm && !pFrm->IsCellFrm() )
[ # # ]
1586 : 0 : pFrm = pFrm->GetUpper();
1587 : : }
1588 : : else
1589 : : {
1590 : : // find the most upper cell frame:
1591 [ # # # # : 0 : while ( pFrm &&
# # # # ]
[ # # ]
1592 : 0 : ( !pFrm->IsCellFrm() ||
1593 : 0 : !pFrm->GetUpper()->GetUpper()->IsTabFrm() ||
1594 : 0 : pFrm->GetUpper()->GetUpper()->GetUpper()->IsInTab() ) )
1595 : 0 : pFrm = pFrm->GetUpper();
1596 : : }
1597 : :
1598 [ # # ]: 0 : if ( pFrm ) // Note: this condition should be the same like the while condition!!!
1599 : : {
1600 : : // #i32329# Enhanced table selection
1601 : : // used for hotspot selection of tab/cols/rows
1602 [ # # ]: 0 : if ( !bMouseMoveRowCols )
1603 : : {
1604 : :
1605 : : OSL_ENSURE( pbCol && pbRow, "pbCol or pbRow missing" );
1606 : :
1607 [ # # ][ # # ]: 0 : if ( bCloseToRow || bCloseToCol )
1608 : : {
1609 : 0 : *pbRow = bCloseToRow;
1610 : 0 : *pbCol = bCloseToCol;
1611 : 0 : pRet = pFrm;
1612 : 0 : break;
1613 : : }
1614 : : }
1615 : : else
1616 : : {
1617 : : // used for mouse move of columns/rows
1618 [ # # ]: 0 : const SwTabFrm* pTabFrm = pFrm->FindTabFrm();
1619 : 0 : SwRect aTabRect = pTabFrm->Prt();
1620 : 0 : aTabRect.Pos() += pTabFrm->Frm().Pos();
1621 : :
1622 [ # # ][ # # ]: 0 : SWRECTFN( pTabFrm )
[ # # ][ # # ]
[ # # ]
1623 : :
1624 [ # # ][ # # ]: 0 : const SwTwips nTabTop = (aTabRect.*fnRect->fnGetTop)();
1625 [ # # ]: 0 : const SwTwips nMouseTop = bVert ? rPt.X() : rPt.Y();
1626 : :
1627 : : // Do not allow to drag upper table border:
1628 [ # # ][ # # ]: 0 : if ( !::IsSame( nTabTop, nMouseTop ) )
1629 : : {
1630 [ # # ][ # # ]: 0 : if ( ::IsSame( pFrm->Frm().Left(), rPt.X() ) ||
[ # # ][ # # ]
1631 [ # # ]: 0 : ::IsSame( pFrm->Frm().Right(),rPt.X() ) )
1632 : : {
1633 [ # # ]: 0 : if ( pbRow ) *pbRow = false;
1634 : 0 : pRet = pFrm;
1635 : : break;
1636 : : }
1637 [ # # ][ # # ]: 0 : if ( ::IsSame( pFrm->Frm().Top(), rPt.Y() ) ||
[ # # ][ # # ]
1638 [ # # ]: 0 : ::IsSame( pFrm->Frm().Bottom(),rPt.Y() ) )
1639 : : {
1640 [ # # ]: 0 : if ( pbRow ) *pbRow = true;
1641 : 0 : pRet = pFrm;
1642 : : break;
1643 : : }
1644 : : }
1645 : : }
1646 : :
1647 : 0 : pFrm = pFrm->GetUpper();
1648 : : }
1649 : : } while ( pFrm );
1650 : : }
1651 : :
1652 : : // robust:
1653 : : OSL_ENSURE( !pRet || pRet->IsCellFrm(), "lcl_FindFrm() is supposed to find a cell frame!" );
1654 [ # # ][ # # ]: 0 : return pRet && pRet->IsCellFrm() ? static_cast<const SwCellFrm*>(pRet) : 0;
1655 : : }
1656 : :
1657 : : //
1658 : : // pbCol = 0 => Used for moving table rows/cols with mouse
1659 : : // pbCol != 0 => Used for selecting table/rows/cols
1660 : : //
1661 : : #define ENHANCED_TABLE_SELECTION_FUZZY 10
1662 : :
1663 : 0 : const SwFrm* SwFEShell::GetBox( const Point &rPt, bool* pbRow, bool* pbCol ) const
1664 : : {
1665 : 0 : const SwPageFrm *pPage = (SwPageFrm*)GetLayout()->Lower();
1666 : 0 : Window* pOutWin = GetWin();
1667 : 0 : SwTwips nFuzzy = COLFUZZY;
1668 [ # # ]: 0 : if( pOutWin )
1669 : : {
1670 : : // #i32329# Enhanced table selection
1671 [ # # ]: 0 : SwTwips nSize = pbCol ? ENHANCED_TABLE_SELECTION_FUZZY : RULER_MOUSE_MARGINWIDTH;
1672 : 0 : Size aTmp( nSize, nSize );
1673 [ # # ]: 0 : aTmp = pOutWin->PixelToLogic( aTmp );
1674 : 0 : nFuzzy = aTmp.Width();
1675 : : }
1676 : :
1677 [ # # ][ # # ]: 0 : while ( pPage && !pPage->Frm().IsNear( rPt, nFuzzy ) )
[ # # ]
1678 : 0 : pPage = (SwPageFrm*)pPage->GetNext();
1679 : :
1680 : 0 : const SwCellFrm *pFrm = 0;
1681 [ # # ]: 0 : if ( pPage )
1682 : : {
1683 : : // We cannot search the box by GetCrsrOfst or GetCntntPos.
1684 : : // This would lead to a performance collapse for documents
1685 : : // with a lot of paragraphs/tables on one page
1686 : : //(BrowseMode!)
1687 : :
1688 : : // check flys first
1689 [ # # ]: 0 : if ( pPage->GetSortedObjs() )
1690 : : {
1691 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; !pFrm && i < pPage->GetSortedObjs()->Count(); ++i )
[ # # ]
1692 : : {
1693 : 0 : SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
1694 [ # # ]: 0 : if ( pObj->ISA(SwFlyFrm) )
1695 : : {
1696 : : pFrm = lcl_FindFrm( static_cast<SwFlyFrm*>(pObj),
1697 [ # # ]: 0 : rPt, nFuzzy, pbRow, pbCol );
1698 : : }
1699 : : }
1700 : : }
1701 : 0 : const SwLayoutFrm *pLay = (SwLayoutFrm*)pPage->Lower();
1702 [ # # ][ # # ]: 0 : while ( pLay && !pFrm )
[ # # ]
1703 : : {
1704 : 0 : pFrm = lcl_FindFrm( pLay, rPt, nFuzzy, pbRow, pbCol );
1705 : 0 : pLay = (SwLayoutFrm*)pLay->GetNext();
1706 : : }
1707 : : }
1708 : 0 : return pFrm;
1709 : : }
1710 : :
1711 : : /* Helper function*/
1712 : : /* calculated the distance between Point rC and Line Segment (rA, rB) */
1713 : 0 : double lcl_DistancePoint2Segment( const Point& rA, const Point& rB, const Point& rC )
1714 : : {
1715 : 0 : double nRet = 0;
1716 : :
1717 : 0 : const basegfx::B2DVector aBC( rC.X() - rB.X(), rC.Y() - rB.Y() );
1718 : 0 : const basegfx::B2DVector aAB( rB.X() - rA.X(), rB.Y() - rA.Y() );
1719 [ # # ]: 0 : const double nDot1 = aBC.scalar( aAB );
1720 : :
1721 [ # # ]: 0 : if ( nDot1 > 0 ) // check outside case 1
1722 [ # # ]: 0 : nRet = aBC.getLength();
1723 : : else
1724 : : {
1725 : 0 : const basegfx::B2DVector aAC( rC.X() - rA.X(), rC.Y() - rA.Y() );
1726 : 0 : const basegfx::B2DVector aBA( rA.X() - rB.X(), rA.Y() - rB.Y() );
1727 [ # # ]: 0 : const double nDot2 = aAC.scalar( aBA );
1728 : :
1729 [ # # ]: 0 : if ( nDot2 > 0 ) // check outside case 2
1730 [ # # ]: 0 : nRet = aAC.getLength();
1731 : : else
1732 : : {
1733 [ # # ]: 0 : const double nDiv = aAB.getLength();
1734 [ # # ][ # # ]: 0 : nRet = nDiv ? aAB.cross( aAC ) / nDiv : 0;
1735 : 0 : }
1736 : : }
1737 : :
1738 : 0 : return Abs(nRet);
1739 : : }
1740 : :
1741 : : /* Helper function*/
1742 : 0 : Point lcl_ProjectOntoClosestTableFrm( const SwTabFrm& rTab, const Point& rPoint, bool bRowDrag )
1743 : : {
1744 : 0 : Point aRet( rPoint );
1745 : 0 : const SwTabFrm* pCurrentTab = &rTab;
1746 [ # # ]: 0 : const bool bVert = pCurrentTab->IsVertical();
1747 [ # # ]: 0 : const bool bRTL = pCurrentTab->IsRightToLeft();
1748 : :
1749 : : // Western Layout:
1750 : : // bRowDrag = true => compare to left border of table
1751 : : // bRowDrag = false => compare to top border of table
1752 : :
1753 : : // Asian Layout:
1754 : : // bRowDrag = true => compare to right border of table
1755 : : // bRowDrag = false => compare to top border of table
1756 : :
1757 : : // RTL Layout:
1758 : : // bRowDrag = true => compare to right border of table
1759 : : // bRowDrag = false => compare to top border of table
1760 : 0 : bool bLeft = false;
1761 : 0 : bool bRight = false;
1762 : :
1763 [ # # ]: 0 : if ( bRowDrag )
1764 : : {
1765 [ # # ][ # # ]: 0 : if ( bVert || bRTL )
1766 : 0 : bRight = true;
1767 : : else
1768 : 0 : bLeft = true;
1769 : : }
1770 : :
1771 : : // used to find the minimal distance
1772 : 0 : double nMin = -1;
1773 : 0 : Point aMin1;
1774 : 0 : Point aMin2;
1775 : :
1776 : 0 : Point aS1;
1777 : 0 : Point aS2;
1778 : :
1779 [ # # ]: 0 : while ( pCurrentTab )
1780 : : {
1781 : 0 : SwRect aTabRect( pCurrentTab->Prt() );
1782 : 0 : aTabRect += pCurrentTab->Frm().Pos();
1783 : :
1784 [ # # ]: 0 : if ( bLeft )
1785 : : {
1786 : : // distance to left table border
1787 [ # # ]: 0 : aS1 = aTabRect.TopLeft();
1788 [ # # ]: 0 : aS2 = aTabRect.BottomLeft();
1789 : : }
1790 [ # # ]: 0 : else if ( bRight )
1791 : : {
1792 : : // distance to right table border
1793 [ # # ]: 0 : aS1 = aTabRect.TopRight();
1794 [ # # ]: 0 : aS2 = aTabRect.BottomRight();
1795 : : }
1796 : : else //if ( bTop )
1797 : : {
1798 : : // distance to top table border
1799 [ # # ]: 0 : aS1 = aTabRect.TopLeft();
1800 [ # # ]: 0 : aS2 = aTabRect.TopRight();
1801 : : }
1802 : :
1803 [ # # ]: 0 : const double nDist = lcl_DistancePoint2Segment( aS1, aS2, rPoint );
1804 : :
1805 [ # # ][ # # ]: 0 : if ( nDist < nMin || -1 == nMin )
1806 : : {
1807 : 0 : aMin1 = aS1;
1808 : 0 : aMin2 = aS2;
1809 : 0 : nMin = nDist;
1810 : : }
1811 : :
1812 : 0 : pCurrentTab = pCurrentTab->GetFollow();
1813 : : }
1814 : :
1815 : : // project onto closest line:
1816 [ # # ][ # # ]: 0 : if ( bLeft || bRight )
1817 : : {
1818 : 0 : aRet.X() = aMin1.X();
1819 [ # # ]: 0 : if ( aRet.Y() > aMin2.Y() )
1820 : 0 : aRet.Y() = aMin2.Y();
1821 [ # # ]: 0 : else if ( aRet.Y() < aMin1.Y() )
1822 : 0 : aRet.Y() = aMin1.Y();
1823 : : }
1824 : : else
1825 : : {
1826 : 0 : aRet.Y() = aMin1.Y();
1827 [ # # ]: 0 : if ( aRet.X() > aMin2.X() )
1828 : 0 : aRet.X() = aMin2.X();
1829 [ # # ]: 0 : else if ( aRet.X() < aMin1.X() )
1830 : 0 : aRet.X() = aMin1.X();
1831 : : }
1832 : :
1833 : 0 : return aRet;
1834 : : }
1835 : :
1836 : : // #i32329# Enhanced table selection
1837 : 0 : bool SwFEShell::SelTblRowCol( const Point& rPt, const Point* pEnd, bool bRowDrag )
1838 : : {
1839 : 0 : bool bRet = false;
1840 : 0 : Point aEndPt;
1841 [ # # ]: 0 : if ( pEnd )
1842 : 0 : aEndPt = *pEnd;
1843 : :
1844 : 0 : SwPosition* ppPos[2] = { 0, 0 };
1845 : 0 : Point paPt [2] = { rPt, aEndPt };
1846 : 0 : bool pbRow[2] = { 0, 0 };
1847 : 0 : bool pbCol[2] = { 0, 0 };
1848 : :
1849 : : // pEnd is set during dragging.
1850 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < ( pEnd ? 2 : 1 ); ++i )
1851 : : {
1852 : : const SwCellFrm* pFrm =
1853 [ # # ]: 0 : static_cast<const SwCellFrm*>(GetBox( paPt[i], &pbRow[i], &pbCol[i] ) );
1854 : :
1855 [ # # ]: 0 : if( pFrm )
1856 : : {
1857 [ # # ][ # # ]: 0 : while( pFrm->Lower() && pFrm->Lower()->IsRowFrm() )
[ # # ]
1858 : 0 : pFrm = static_cast<const SwCellFrm*>( static_cast<const SwLayoutFrm*>( pFrm->Lower() )->Lower() );
1859 [ # # ][ # # ]: 0 : if( pFrm && pFrm->GetTabBox()->GetSttNd() &&
[ # # ][ # # ]
1860 [ # # ]: 0 : pFrm->GetTabBox()->GetSttNd()->IsInProtectSect() )
1861 : 0 : pFrm = 0;
1862 : : }
1863 : :
1864 [ # # ]: 0 : if ( pFrm )
1865 : : {
1866 [ # # ]: 0 : const SwCntntFrm* pCntnt = ::GetCellCntnt( *pFrm );
1867 : :
1868 [ # # ][ # # ]: 0 : if ( pCntnt && pCntnt->IsTxtFrm() )
[ # # ]
1869 : : {
1870 [ # # ][ # # ]: 0 : ppPos[i] = new SwPosition( *pCntnt->GetNode() );
1871 [ # # ][ # # ]: 0 : ppPos[i]->nContent.Assign( const_cast<SwCntntNode*>(pCntnt->GetNode()), 0 );
1872 : :
1873 : : // paPt[i] will not be used any longer, now we use it to store
1874 : : // a position inside the content frame
1875 [ # # ]: 0 : paPt[i] = pCntnt->Frm().Center();
1876 : : }
1877 : : }
1878 : :
1879 : : // no calculation of end frame if start frame has not been found.
1880 [ # # ][ # # ]: 0 : if ( 1 == i || !ppPos[0] || !pEnd )
[ # # ]
1881 : : break;
1882 : :
1883 : : // find 'closest' table frame to pEnd:
1884 [ # # ]: 0 : const SwTabFrm* pCurrentTab = pFrm->FindTabFrm();
1885 [ # # ]: 0 : if ( pCurrentTab->IsFollow() )
1886 [ # # ]: 0 : pCurrentTab = pCurrentTab->FindMaster( true );
1887 : :
1888 [ # # ]: 0 : const Point aProjection = lcl_ProjectOntoClosestTableFrm( *pCurrentTab, *pEnd, bRowDrag );
1889 : 0 : paPt[1] = aProjection;
1890 : : }
1891 : :
1892 [ # # ]: 0 : if ( ppPos[0] )
1893 : : {
1894 : 0 : SwShellCrsr* pCrsr = _GetCrsr();
1895 [ # # ]: 0 : SwCrsrSaveState aSaveState( *pCrsr );
1896 [ # # ]: 0 : SwPosition aOldPos( *pCrsr->GetPoint() );
1897 : :
1898 [ # # ]: 0 : pCrsr->DeleteMark();
1899 [ # # ]: 0 : *pCrsr->GetPoint() = *ppPos[0];
1900 : 0 : pCrsr->GetPtPos() = paPt[0];
1901 : :
1902 [ # # ][ # # ]: 0 : if ( !pCrsr->IsInProtectTable( sal_False, sal_True ) )
1903 : : {
1904 : 0 : bool bNewSelection = true;
1905 : :
1906 [ # # ]: 0 : if ( ppPos[1] )
1907 : : {
1908 [ # # ]: 0 : if ( ppPos[1]->nNode.GetNode().StartOfSectionNode() !=
1909 : 0 : aOldPos.nNode.GetNode().StartOfSectionNode() )
1910 : : {
1911 [ # # ]: 0 : pCrsr->SetMark();
1912 [ # # ]: 0 : SwCrsrSaveState aSaveState2( *pCrsr );
1913 [ # # ]: 0 : *pCrsr->GetPoint() = *ppPos[1];
1914 : 0 : pCrsr->GetPtPos() = paPt[1];
1915 : :
1916 [ # # ][ # # ]: 0 : if ( pCrsr->IsInProtectTable( sal_False, sal_False ) )
1917 : : {
1918 [ # # ]: 0 : pCrsr->RestoreSavePos();
1919 : 0 : bNewSelection = false;
1920 [ # # ]: 0 : }
1921 : : }
1922 : : else
1923 : : {
1924 [ # # ]: 0 : pCrsr->RestoreSavePos();
1925 : 0 : bNewSelection = false;
1926 : : }
1927 : : }
1928 : :
1929 [ # # ]: 0 : if ( bNewSelection )
1930 : : {
1931 : : // #i35543# SelTblRowCol should remove any existing
1932 : : // table cursor:
1933 [ # # ]: 0 : if ( IsTableMode() )
1934 [ # # ]: 0 : TblCrsrToCursor();
1935 : :
1936 [ # # ][ # # ]: 0 : if ( pbRow[0] && pbCol[0] )
1937 [ # # ]: 0 : bRet = SwCrsrShell::SelTbl();
1938 [ # # ]: 0 : else if ( pbRow[0] )
1939 [ # # ]: 0 : bRet = SwCrsrShell::_SelTblRowOrCol( true, true );
1940 [ # # ]: 0 : else if ( pbCol[0] )
1941 [ # # ]: 0 : bRet = SwCrsrShell::_SelTblRowOrCol( false, true );
1942 : : }
1943 : : else
1944 : 0 : bRet = true;
1945 : : }
1946 : :
1947 [ # # ][ # # ]: 0 : delete ppPos[0];
1948 [ # # ][ # # ]: 0 : delete ppPos[1];
[ # # ][ # # ]
1949 : : }
1950 : :
1951 : 0 : return bRet;
1952 : : }
1953 : :
1954 : :
1955 : : /*************************************************************************
1956 : : |*
1957 : : |* SwFEShell::WhichMouseTabCol()
1958 : : |*
1959 : : |*************************************************************************/
1960 : 0 : sal_uInt8 SwFEShell::WhichMouseTabCol( const Point &rPt ) const
1961 : : {
1962 : 0 : sal_uInt8 nRet = SW_TABCOL_NONE;
1963 : 0 : bool bRow = false;
1964 : 0 : bool bCol = false;
1965 : 0 : bool bSelect = false;
1966 : :
1967 : : // First try: Do we get the row/col move cursor?
1968 [ # # ]: 0 : SwCellFrm* pFrm = (SwCellFrm*)GetBox( rPt, &bRow, 0 );
1969 : :
1970 [ # # ]: 0 : if ( !pFrm )
1971 : : {
1972 : : // Second try: Do we get the row/col/tab selection cursor?
1973 [ # # ]: 0 : pFrm = (SwCellFrm*)GetBox( rPt, &bRow, &bCol );
1974 : 0 : bSelect = true;
1975 : : }
1976 : :
1977 [ # # ]: 0 : if( pFrm )
1978 : : {
1979 [ # # ][ # # ]: 0 : while( pFrm->Lower() && pFrm->Lower()->IsRowFrm() )
[ # # ]
1980 : 0 : pFrm = (SwCellFrm*)((SwLayoutFrm*)pFrm->Lower())->Lower();
1981 [ # # ][ # # ]: 0 : if( pFrm && pFrm->GetTabBox()->GetSttNd() &&
[ # # ][ # # ]
1982 [ # # ]: 0 : pFrm->GetTabBox()->GetSttNd()->IsInProtectSect() )
1983 : 0 : pFrm = 0;
1984 : : }
1985 : :
1986 [ # # ]: 0 : if( pFrm )
1987 : : {
1988 [ # # ]: 0 : if ( !bSelect )
1989 : : {
1990 [ # # ][ # # ]: 0 : if ( pFrm->IsVertical() )
1991 [ # # ]: 0 : nRet = bRow ? SW_TABCOL_VERT : SW_TABROW_VERT;
1992 : : else
1993 [ # # ]: 0 : nRet = bRow ? SW_TABROW_HORI : SW_TABCOL_HORI;
1994 : : }
1995 : : else
1996 : : {
1997 [ # # ]: 0 : const SwTabFrm* pTabFrm = pFrm->FindTabFrm();
1998 [ # # ][ # # ]: 0 : if ( pTabFrm->IsVertical() )
1999 : : {
2000 [ # # ][ # # ]: 0 : if ( bRow && bCol )
2001 : : {
2002 : 0 : nRet = SW_TABSEL_VERT;
2003 : : }
2004 [ # # ]: 0 : else if ( bRow )
2005 : : {
2006 : 0 : nRet = SW_TABROWSEL_VERT;
2007 : : }
2008 [ # # ]: 0 : else if ( bCol )
2009 : : {
2010 : 0 : nRet = SW_TABCOLSEL_VERT;
2011 : : }
2012 : : }
2013 : : else
2014 : : {
2015 [ # # ][ # # ]: 0 : if ( bRow && bCol )
2016 : : {
2017 [ # # ]: 0 : nRet = pTabFrm->IsRightToLeft() ?
2018 : : SW_TABSEL_HORI_RTL :
2019 [ # # ]: 0 : SW_TABSEL_HORI;
2020 : : }
2021 [ # # ]: 0 : else if ( bRow )
2022 : : {
2023 [ # # ]: 0 : nRet = pTabFrm->IsRightToLeft() ?
2024 : : SW_TABROWSEL_HORI_RTL :
2025 [ # # ]: 0 : SW_TABROWSEL_HORI;
2026 : : }
2027 [ # # ]: 0 : else if ( bCol )
2028 : : {
2029 : 0 : nRet = SW_TABCOLSEL_HORI;
2030 : : }
2031 : : }
2032 : : }
2033 : : }
2034 : :
2035 : 0 : return nRet;
2036 : : }
2037 : :
2038 : : // -> #i23726#
2039 : 0 : SwTxtNode * SwFEShell::GetNumRuleNodeAtPos( const Point &rPt)
2040 : : {
2041 : 0 : SwTxtNode * pResult = NULL;
2042 : :
2043 : : SwContentAtPos aCntntAtPos
2044 [ # # ]: 0 : (SwContentAtPos::SW_NUMLABEL);
2045 : :
2046 [ # # ][ # # ]: 0 : if( GetContentAtPos(rPt, aCntntAtPos) && aCntntAtPos.aFnd.pNode)
[ # # ][ # # ]
2047 : 0 : pResult = aCntntAtPos.aFnd.pNode->GetTxtNode();
2048 : :
2049 [ # # ]: 0 : return pResult;
2050 : : }
2051 : :
2052 : 0 : sal_Bool SwFEShell::IsNumLabel( const Point &rPt, int nMaxOffset )
2053 : : {
2054 : 0 : sal_Bool bResult = sal_False;
2055 : :
2056 : : SwContentAtPos aCntntAtPos
2057 [ # # ]: 0 : (SwContentAtPos::SW_NUMLABEL);
2058 : :
2059 [ # # ][ # # ]: 0 : if( GetContentAtPos(rPt, aCntntAtPos))
2060 : : {
2061 [ # # ][ # # ]: 0 : if ((nMaxOffset >= 0 && aCntntAtPos.nDist <= nMaxOffset) ||
[ # # ]
2062 : : (nMaxOffset < 0))
2063 : 0 : bResult = sal_True;
2064 : : }
2065 : :
2066 [ # # ]: 0 : return bResult;
2067 : : }
2068 : : // <- #i23726#
2069 : :
2070 : : // #i42921#
2071 : 0 : bool SwFEShell::IsVerticalModeAtNdAndPos( const SwTxtNode& _rTxtNode,
2072 : : const Point& _rDocPos ) const
2073 : : {
2074 : 0 : bool bRet( false );
2075 : :
2076 : : const short nTextDir =
2077 [ # # ]: 0 : _rTxtNode.GetTextDirection( SwPosition(_rTxtNode), &_rDocPos );
2078 [ # # # ]: 0 : switch ( nTextDir )
2079 : : {
2080 : : case -1:
2081 : : case FRMDIR_HORI_RIGHT_TOP:
2082 : : case FRMDIR_HORI_LEFT_TOP:
2083 : : {
2084 : 0 : bRet = false;
2085 : : }
2086 : 0 : break;
2087 : : case FRMDIR_VERT_TOP_LEFT:
2088 : : case FRMDIR_VERT_TOP_RIGHT:
2089 : : {
2090 : 0 : bRet = true;
2091 : : }
2092 : 0 : break;
2093 : : }
2094 : :
2095 : 0 : return bRet;
2096 : : }
2097 : :
2098 : : /*************************************************************************
2099 : : |*
2100 : : |* SwFEShell::GetMouseTabCols()
2101 : : |*
2102 : : |*************************************************************************/
2103 : 0 : void SwFEShell::GetMouseTabCols( SwTabCols &rToFill, const Point &rPt ) const
2104 : : {
2105 : 0 : const SwFrm *pBox = GetBox( rPt );
2106 [ # # ]: 0 : if ( pBox )
2107 : 0 : _GetTabCols( rToFill, pBox );
2108 : 0 : }
2109 : :
2110 : 0 : void SwFEShell::SetMouseTabCols( const SwTabCols &rNew, sal_Bool bCurRowOnly,
2111 : : const Point &rPt )
2112 : : {
2113 : 0 : const SwFrm *pBox = GetBox( rPt );
2114 [ # # ]: 0 : if( pBox )
2115 : : {
2116 [ # # ]: 0 : SET_CURR_SHELL( this );
2117 [ # # ]: 0 : StartAllAction();
2118 [ # # ]: 0 : GetDoc()->SetTabCols( rNew, bCurRowOnly, 0, (SwCellFrm*)pBox );
2119 [ # # ][ # # ]: 0 : EndAllActionAndCall();
2120 : : }
2121 : 0 : }
2122 : :
2123 : : /*************************************************************************
2124 : : |*
2125 : : |* SwFEShell::GetMouseColNum(), GetMouseTabColNum()
2126 : : |*
2127 : : |*************************************************************************/
2128 : 0 : sal_uInt16 SwFEShell::GetCurMouseColNum( const Point &rPt,
2129 : : SwGetCurColNumPara* pPara ) const
2130 : : {
2131 : 0 : return _GetCurColNum( GetBox( rPt ), pPara );
2132 : : }
2133 : :
2134 : 0 : sal_uInt16 SwFEShell::GetCurMouseTabColNum( const Point &rPt ) const
2135 : : {
2136 : : //!!!GetCurTabColNum() mitpflegen!!!!
2137 : 0 : sal_uInt16 nRet = 0;
2138 : :
2139 : 0 : const SwFrm *pFrm = GetBox( rPt );
2140 : : OSL_ENSURE( pFrm, "Table not found" );
2141 [ # # ]: 0 : if( pFrm )
2142 : : {
2143 : 0 : const long nX = pFrm->Frm().Left();
2144 : :
2145 : : // get TabCols, only via these we get the position
2146 [ # # ]: 0 : SwTabCols aTabCols;
2147 [ # # ]: 0 : GetMouseTabCols( aTabCols, rPt );
2148 : :
2149 : 0 : const long nLeft = aTabCols.GetLeftMin();
2150 : :
2151 [ # # ][ # # ]: 0 : if ( !::IsSame( nX, nLeft + aTabCols.GetLeft() ) )
2152 : : {
2153 [ # # ][ # # ]: 0 : for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
2154 [ # # ][ # # ]: 0 : if ( ::IsSame( nX, nLeft + aTabCols[i] ) )
[ # # ]
2155 : : {
2156 : 0 : nRet = i + 1;
2157 : 0 : break;
2158 : : }
2159 : 0 : }
2160 : : }
2161 : 0 : return nRet;
2162 : : }
2163 : :
2164 : 170 : void ClearFEShellTabCols()
2165 : : {
2166 [ + + ]: 170 : DELETEZ( pLastCols );
2167 [ + + ]: 170 : DELETEZ( pLastRows );
2168 : 170 : }
2169 : :
2170 : : /*************************************************************************
2171 : : |*
2172 : : |* SwFEShell::GetTblAttr(), SetTblAttr()
2173 : : |*
2174 : : |*************************************************************************/
2175 : 0 : void SwFEShell::GetTblAttr( SfxItemSet &rSet ) const
2176 : : {
2177 : 0 : SwFrm *pFrm = GetCurrFrm();
2178 [ # # ][ # # ]: 0 : if( pFrm && pFrm->IsInTab() )
[ # # ]
2179 : 0 : rSet.Put( pFrm->ImplFindTabFrm()->GetFmt()->GetAttrSet() );
2180 : 0 : }
2181 : :
2182 : 0 : void SwFEShell::SetTblAttr( const SfxItemSet &rNew )
2183 : : {
2184 : 0 : SwFrm *pFrm = GetCurrFrm();
2185 [ # # ][ # # ]: 0 : if( pFrm && pFrm->IsInTab() )
[ # # ]
2186 : : {
2187 [ # # ]: 0 : SET_CURR_SHELL( this );
2188 [ # # ]: 0 : StartAllAction();
2189 [ # # ]: 0 : SwTabFrm *pTab = pFrm->FindTabFrm();
2190 [ # # ]: 0 : pTab->GetTable()->SetHTMLTableLayout( 0 );
2191 [ # # ][ # # ]: 0 : GetDoc()->SetAttr( rNew, *pTab->GetFmt() );
2192 [ # # ]: 0 : GetDoc()->SetModified();
2193 [ # # ][ # # ]: 0 : EndAllActionAndCall();
2194 : : }
2195 : 0 : }
2196 : :
2197 : : /** move cursor within a table into previous/next row (same column)
2198 : : * @param pShell cursor shell whose cursor is to be moved
2199 : : * @param bUp true: move up, false: move down
2200 : : * @returns true if successful
2201 : : */
2202 : 0 : bool lcl_GoTableRow( SwCrsrShell* pShell, bool bUp )
2203 : : {
2204 : : OSL_ENSURE( pShell != NULL, "need shell" );
2205 : :
2206 : 0 : bool bRet = false;
2207 : :
2208 : 0 : SwPaM* pPam = pShell->GetCrsr();
2209 : 0 : const SwStartNode* pTableBox = pPam->GetNode()->FindTableBoxStartNode();
2210 : : OSL_ENSURE( pTableBox != NULL, "I'm living in a box... NOT!" );
2211 : :
2212 : : // move cursor to start node of table box
2213 : 0 : pPam->GetPoint()->nNode = pTableBox->GetIndex();
2214 : 0 : pPam->GetPoint()->nContent.Assign( NULL, 0 );
2215 : 0 : GoInCntnt( *pPam, fnMoveForward );
2216 : :
2217 : : // go to beginning end of table box
2218 [ # # ]: 0 : SwPosSection fnPosSect = bUp ? fnSectionStart : fnSectionEnd;
2219 : 0 : pShell->MoveSection( fnSectionCurr, fnPosSect );
2220 : :
2221 : : // and go up/down into next content
2222 [ # # ]: 0 : bRet = bUp ? pShell->Up() : pShell->Down();
2223 : :
2224 : 0 : return bRet;
2225 : : }
2226 : :
2227 : : // aender eine Zellenbreite/-Hoehe/Spaltenbreite/Zeilenhoehe
2228 : 0 : sal_Bool SwFEShell::SetColRowWidthHeight( sal_uInt16 eType, sal_uInt16 nDiff )
2229 : : {
2230 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
2231 [ # # ][ # # ]: 0 : if( !pFrm || !pFrm->IsInTab() )
[ # # ][ # # ]
2232 : 0 : return sal_False;
2233 : :
2234 [ # # ][ # # ]: 0 : if( nsTblChgWidthHeightType::WH_FLAG_INSDEL & eType &&
[ # # ]
2235 [ # # ][ # # ]: 0 : pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
[ # # ]
2236 : : {
2237 : : ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
2238 [ # # ]: 0 : ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
2239 : 0 : return sal_False;
2240 : : }
2241 : :
2242 [ # # ]: 0 : SET_CURR_SHELL( this );
2243 [ # # ]: 0 : StartAllAction();
2244 : :
2245 [ # # ]: 0 : do {
2246 : 0 : pFrm = pFrm->GetUpper();
2247 : 0 : } while( !pFrm->IsCellFrm() );
2248 : :
2249 [ # # ]: 0 : SwTabFrm *pTab = pFrm->ImplFindTabFrm();
2250 : :
2251 : : // if the table is in relative values (USHRT_MAX)
2252 : : // then it should be recalculated to absolute values now
2253 [ # # ][ # # ]: 0 : const SwFmtFrmSize& rTblFrmSz = pTab->GetFmt()->GetFrmSize();
2254 [ # # ][ # # ]: 0 : SWRECTFN( pTab )
[ # # ][ # # ]
[ # # ]
2255 [ # # ][ # # ]: 0 : long nPrtWidth = (pTab->Prt().*fnRect->fnGetWidth)();
2256 [ # # ][ # # : 0 : if( TBLVAR_CHGABS == pTab->GetTable()->GetTblChgMode() &&
# # # # ]
[ # # ]
2257 : : ( eType & nsTblChgWidthHeightType::WH_COL_LEFT || eType & nsTblChgWidthHeightType::WH_COL_RIGHT ) &&
2258 [ # # ][ # # ]: 0 : text::HoriOrientation::NONE == pTab->GetFmt()->GetHoriOrient().GetHoriOrient() &&
2259 : 0 : nPrtWidth != rTblFrmSz.GetWidth() )
2260 : : {
2261 [ # # ]: 0 : SwFmtFrmSize aSz( rTblFrmSz );
2262 : 0 : aSz.SetWidth( pTab->Prt().Width() );
2263 [ # # ][ # # ]: 0 : pTab->GetFmt()->SetFmtAttr( aSz );
[ # # ]
2264 : : }
2265 : :
2266 [ # # ]: 0 : if( (eType & (nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL)) ==
2267 : : (nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL) )
2268 : : {
2269 [ # # ][ # # ]: 0 : nDiff = sal_uInt16((pFrm->Frm().*fnRect->fnGetWidth)());
2270 : :
2271 : : // we must move the cursor outside the current cell before
2272 : : // deleting the cells.
2273 : : TblChgWidthHeightType eTmp =
2274 : 0 : static_cast<TblChgWidthHeightType>( eType & 0xfff );
2275 [ # # # # : 0 : switch( eTmp )
# ]
2276 : : {
2277 : : case nsTblChgWidthHeightType::WH_ROW_TOP:
2278 [ # # ]: 0 : lcl_GoTableRow( this, true );
2279 : 0 : break;
2280 : : case nsTblChgWidthHeightType::WH_ROW_BOTTOM:
2281 [ # # ]: 0 : lcl_GoTableRow( this, false );
2282 : 0 : break;
2283 : : case nsTblChgWidthHeightType::WH_COL_LEFT:
2284 [ # # ]: 0 : GoPrevCell();
2285 : 0 : break;
2286 : : case nsTblChgWidthHeightType::WH_COL_RIGHT:
2287 [ # # ]: 0 : GoNextCell();
2288 : 0 : break;
2289 : : default:
2290 : 0 : break;
2291 : : }
2292 : : }
2293 : :
2294 : 0 : SwTwips nLogDiff = nDiff;
2295 [ # # ][ # # ]: 0 : nLogDiff *= pTab->GetFmt()->GetFrmSize().GetWidth();
2296 : 0 : nLogDiff /= nPrtWidth;
2297 : :
2298 : : /** The cells are destroyed in here */
2299 : : sal_Bool bRet = GetDoc()->SetColRowWidthHeight(
2300 : 0 : *(SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox(),
2301 [ # # ]: 0 : eType, nDiff, nLogDiff );
2302 : :
2303 [ # # ]: 0 : delete pLastCols, pLastCols = 0;
2304 [ # # ]: 0 : EndAllActionAndCall();
2305 : :
2306 [ # # ][ # # ]: 0 : if( bRet && (eType & (nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL)) == nsTblChgWidthHeightType::WH_FLAG_INSDEL )
2307 : : {
2308 [ # # # # : 0 : switch(eType & ~(nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL))
# ]
2309 : : {
2310 : : case nsTblChgWidthHeightType::WH_CELL_LEFT:
2311 : : case nsTblChgWidthHeightType::WH_COL_LEFT:
2312 [ # # ]: 0 : GoPrevCell();
2313 : 0 : break;
2314 : :
2315 : : case nsTblChgWidthHeightType::WH_CELL_RIGHT:
2316 : : case nsTblChgWidthHeightType::WH_COL_RIGHT:
2317 [ # # ]: 0 : GoNextCell();
2318 : 0 : break;
2319 : :
2320 : : case nsTblChgWidthHeightType::WH_CELL_TOP:
2321 : : case nsTblChgWidthHeightType::WH_ROW_TOP:
2322 [ # # ]: 0 : lcl_GoTableRow( this, true );
2323 : 0 : break;
2324 : :
2325 : : case nsTblChgWidthHeightType::WH_CELL_BOTTOM:
2326 : : case nsTblChgWidthHeightType::WH_ROW_BOTTOM:
2327 [ # # ]: 0 : lcl_GoTableRow( this, false );
2328 : 0 : break;
2329 : : }
2330 : : }
2331 : :
2332 [ # # ]: 0 : return bRet;
2333 : : }
2334 : :
2335 : 0 : sal_Bool lcl_IsFormulaSelBoxes( const SwTable& rTbl, const SwTblBoxFormula& rFml,
2336 : : SwCellFrms& rCells )
2337 : : {
2338 [ # # ]: 0 : SwTblBoxFormula aTmp( rFml );
2339 [ # # ]: 0 : SwSelBoxes aBoxes;
2340 : :
2341 [ # # ][ # # ]: 0 : for( sal_uInt16 nSelBoxes = aTmp.GetBoxesOfFormula( rTbl,aBoxes ); nSelBoxes; )
2342 : : {
2343 [ # # ]: 0 : SwTableBox* pBox = aBoxes[ --nSelBoxes ];
2344 : 0 : SwCellFrms::iterator iC;
2345 [ # # ][ # # ]: 0 : for( iC = rCells.begin(); iC != rCells.end(); ++iC )
[ # # ]
2346 [ # # ]: 0 : if( (*iC)->GetTabBox() == pBox )
2347 : 0 : break; // found
2348 : :
2349 [ # # ]: 0 : if( iC == rCells.end() )
2350 : 0 : return sal_False;
2351 : : }
2352 : :
2353 [ # # ]: 0 : return sal_True;
2354 : : }
2355 : :
2356 : : // ask formula for auto-sum
2357 : 0 : sal_Bool SwFEShell::GetAutoSum( String& rFml ) const
2358 : : {
2359 [ # # ]: 0 : SwFrm *pFrm = GetCurrFrm();
2360 [ # # ][ # # ]: 0 : SwTabFrm *pTab = pFrm ? pFrm->ImplFindTabFrm() : 0;
2361 [ # # ]: 0 : if( !pTab )
2362 : 0 : return sal_False;
2363 : :
2364 [ # # ]: 0 : rFml = rtl::OUString::createFromAscii( sCalc_Sum );
2365 : :
2366 [ # # ]: 0 : SwCellFrms aCells;
2367 [ # # ][ # # ]: 0 : if( ::GetAutoSumSel( *this, aCells ))
2368 : : {
2369 : 0 : sal_uInt16 nW = 0, nInsPos = 0;
2370 [ # # ]: 0 : for( size_t n = aCells.size(); n; )
2371 : : {
2372 [ # # ]: 0 : SwCellFrm* pCFrm = aCells[ --n ];
2373 [ # # ]: 0 : sal_uInt16 nBoxW = pCFrm->GetTabBox()->IsFormulaOrValueBox();
2374 [ # # ]: 0 : if( !nBoxW )
2375 : : break;
2376 : :
2377 [ # # ]: 0 : if( !nW )
2378 : : {
2379 [ # # ]: 0 : if( USHRT_MAX == nBoxW )
2380 : 0 : continue; // skip space at beginning
2381 : :
2382 [ # # ]: 0 : rFml += '(';
2383 : 0 : nInsPos = rFml.Len();
2384 : :
2385 : : // formula only if box is contained
2386 [ # # ][ # # ]: 0 : if( RES_BOXATR_FORMULA == nBoxW &&
[ # # ]
2387 : 0 : !::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
2388 [ # # # # ]: 0 : GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells))
2389 : : {
2390 : 0 : nW = RES_BOXATR_VALUE;
2391 : : // restore previous spaces!
2392 [ # # ]: 0 : for( size_t i = aCells.size(); n+1 < i; )
2393 : : {
2394 [ # # ]: 0 : String sTmp(rtl::OUString("|<"));
2395 [ # # ][ # # ]: 0 : sTmp += aCells[ --i ]->GetTabBox()->GetName();
[ # # ][ # # ]
2396 [ # # ]: 0 : sTmp += '>';
2397 [ # # ]: 0 : rFml.Insert( sTmp, nInsPos );
2398 [ # # ]: 0 : }
2399 : : }
2400 : : else
2401 : 0 : nW = nBoxW;
2402 : : }
2403 [ # # ]: 0 : else if( RES_BOXATR_VALUE == nW )
2404 : : {
2405 : : // search for values, Value/Formula/Text found -> include
2406 [ # # ][ # # ]: 0 : if( RES_BOXATR_FORMULA == nBoxW &&
[ # # ]
2407 : 0 : ::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
2408 [ # # # # ]: 0 : GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells ))
2409 : : break;
2410 [ # # ]: 0 : else if( USHRT_MAX != nBoxW )
2411 [ # # ]: 0 : rFml.Insert( cListDelim, nInsPos );
2412 : : else
2413 : : break;
2414 : : }
2415 [ # # ]: 0 : else if( RES_BOXATR_FORMULA == nW )
2416 : : {
2417 : : // only continue search when the current formula points to
2418 : : // all boxes contained in the selection
2419 [ # # ]: 0 : if( RES_BOXATR_FORMULA == nBoxW )
2420 : : {
2421 [ # # ]: 0 : if( !::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
2422 [ # # # # ]: 0 : GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells ))
2423 : : {
2424 : : // redo only for values!
2425 : :
2426 : 0 : nW = RES_BOXATR_VALUE;
2427 [ # # ]: 0 : rFml.Erase( nInsPos );
2428 : : // restore previous spaces!
2429 [ # # ]: 0 : for( size_t i = aCells.size(); n+1 < i; )
2430 : : {
2431 [ # # ]: 0 : String sTmp(rtl::OUString("|<" ));
2432 [ # # ][ # # ]: 0 : sTmp += aCells[ --i ]->GetTabBox()->GetName();
[ # # ][ # # ]
2433 [ # # ]: 0 : sTmp += '>';
2434 [ # # ]: 0 : rFml.Insert( sTmp, nInsPos );
2435 [ # # ]: 0 : }
2436 : : }
2437 : : else
2438 [ # # ]: 0 : rFml.Insert( cListDelim, nInsPos );
2439 : : }
2440 [ # # ]: 0 : else if( USHRT_MAX == nBoxW )
2441 : : break;
2442 : : else
2443 : 0 : continue; // ignore this box
2444 : : }
2445 : : else
2446 : : // all other stuff terminates the loop
2447 : : // possibly allow texts??
2448 : : break;
2449 : :
2450 : 0 : rtl::OUStringBuffer sTmp;
2451 [ # # ]: 0 : sTmp.append('<');
2452 [ # # ][ # # ]: 0 : sTmp.append(pCFrm->GetTabBox()->GetName());
[ # # ][ # # ]
2453 [ # # ]: 0 : sTmp.append('>');
2454 [ # # ][ # # ]: 0 : rFml.Insert( sTmp.makeStringAndClear(), nInsPos );
[ # # ][ # # ]
2455 : 0 : }
2456 [ # # ]: 0 : if( nW )
2457 : : {
2458 [ # # ]: 0 : rFml += ')';
2459 : : }
2460 : : }
2461 : :
2462 : 0 : return sal_True;
2463 : : }
2464 : :
2465 : 10 : sal_Bool SwFEShell::IsTableRightToLeft() const
2466 : : {
2467 : 10 : SwFrm *pFrm = GetCurrFrm();
2468 [ - + ][ - + ]: 10 : if( !pFrm || !pFrm->IsInTab() )
[ + - ]
2469 : 0 : return sal_False;
2470 : :
2471 : 10 : return pFrm->ImplFindTabFrm()->IsRightToLeft();
2472 : : }
2473 : :
2474 : 0 : sal_Bool SwFEShell::IsMouseTableRightToLeft(const Point &rPt) const
2475 : : {
2476 : 0 : SwFrm *pFrm = (SwFrm *)GetBox( rPt );
2477 [ # # ]: 0 : const SwTabFrm* pTabFrm = pFrm ? pFrm->ImplFindTabFrm() : 0;
2478 : : OSL_ENSURE( pTabFrm, "Table not found" );
2479 [ # # ]: 0 : return pTabFrm ? pTabFrm->IsRightToLeft() : sal_False;
2480 : : }
2481 : :
2482 : 10 : sal_Bool SwFEShell::IsTableVertical() const
2483 : : {
2484 : 10 : SwFrm *pFrm = GetCurrFrm();
2485 [ - + ][ - + ]: 10 : if( !pFrm || !pFrm->IsInTab() )
[ + - ]
2486 : 0 : return sal_False;
2487 : :
2488 : 10 : return pFrm->ImplFindTabFrm()->IsVertical();
2489 : : }
2490 : :
2491 : :
2492 : :
2493 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|