Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / viewtab.cxx
blob26bfba7b8b18f7c507ce631917c33b89e226eaca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
21 #include <uitool.hxx>
22 #include <svx/rulritem.hxx>
23 #include <svx/xflclit.hxx>
24 #include <svx/xflgrit.hxx>
25 #include <svx/xflhtit.hxx>
26 #include <svx/xbtmpit.hxx>
27 #include <svx/xfillit0.hxx>
28 #include <tools/UnitConversion.hxx>
29 #include <editeng/tstpitem.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <editeng/lrspitem.hxx>
33 #include <editeng/ulspitem.hxx>
34 #include <editeng/boxitem.hxx>
35 #include <editeng/frmdiritem.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/whiter.hxx>
38 #include <svx/ruler.hxx>
39 #include <editeng/protitem.hxx>
40 #include <svl/rectitem.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <fmtfsize.hxx>
43 #include <fmthdft.hxx>
44 #include <fmtclds.hxx>
45 #include <fmtornt.hxx>
46 #include <frmatr.hxx>
47 #include <view.hxx>
48 #include <wrtsh.hxx>
49 #include <cmdid.h>
50 #include <viewopt.hxx>
51 #include <tabcol.hxx>
52 #include <frmfmt.hxx>
53 #include <pagedesc.hxx>
54 #include <wview.hxx>
55 #include <fmtcol.hxx>
56 #include <section.hxx>
57 #include <ndtxt.hxx>
58 #include <pam.hxx>
59 #include <comphelper/lok.hxx>
60 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
61 #include <boost/property_tree/json_parser.hpp>
62 #include <osl/diagnose.h>
64 #include <IDocumentSettingAccess.hxx>
66 using namespace ::com::sun::star;
68 // Pack columns
69 static void lcl_FillSvxColumn(const SwFormatCol& rCol,
70 tools::Long nTotalWidth,
71 SvxColumnItem& rColItem,
72 tools::Long nDistance)
74 const SwColumns& rCols = rCol.GetColumns();
76 bool bOrtho = rCol.IsOrtho() && !rCols.empty();
77 tools::Long nInnerWidth = 0;
78 if( bOrtho )
80 nInnerWidth = nTotalWidth;
81 for (const auto & i : rCols)
83 nInnerWidth -= i.GetLeft() + i.GetRight();
85 if( nInnerWidth < 0 )
86 nInnerWidth = 0;
87 else
88 nInnerWidth /= rCols.size();
91 tools::Long nWidth = 0;
92 for ( size_t i = 0; i < rCols.size(); ++i )
94 const SwColumn* pCol = &rCols[i];
95 const tools::Long nStart = pCol->GetLeft() + nWidth + nDistance;
96 if( bOrtho )
97 nWidth += nInnerWidth + pCol->GetLeft() + pCol->GetRight();
98 else
99 nWidth += rCol.CalcColWidth(i, static_cast< sal_uInt16 >(nTotalWidth));
100 const tools::Long nEnd = nWidth - pCol->GetRight() + nDistance;
102 SvxColumnDescription aColDesc(nStart, nEnd, true);
103 rColItem.Append(aColDesc);
107 // Transfer ColumnItem in ColumnInfo
108 static void lcl_ConvertToCols(const SvxColumnItem& rColItem,
109 tools::Long nTotalWidth,
110 SwFormatCol& rCols)
112 OSL_ENSURE( rCols.GetNumCols() == rColItem.Count(), "Column count mismatch" );
113 // ruler executes that change the columns shortly after the selection has changed
114 // can result in a crash
115 if(rCols.GetNumCols() != rColItem.Count())
116 return;
118 sal_uInt16 nLeft = 0;
119 SwTwips nSumAll= 0; // Sum up all columns and margins
121 SwColumns& rArr = rCols.GetColumns();
123 // Tabcols sequentially
124 for( sal_uInt16 i=0; i < rColItem.Count()-1; ++i )
126 OSL_ENSURE(rColItem[i+1].nStart >= rColItem[i].nEnd,"overlapping columns" );
127 const tools::Long nStart = std::max(rColItem[i+1].nStart, rColItem[i].nEnd);
128 const sal_uInt16 nRight = o3tl::narrowing<sal_uInt16>((nStart - rColItem[i].nEnd) / 2);
130 const tools::Long nWidth = rColItem[i].nEnd - rColItem[i].nStart + nLeft + nRight;
132 SwColumn* pCol = &rArr[i];
133 pCol->SetWishWidth( sal_uInt16(tools::Long(rCols.GetWishWidth()) * nWidth / nTotalWidth ));
134 pCol->SetLeft( nLeft );
135 pCol->SetRight( nRight );
136 nSumAll += pCol->GetWishWidth();
138 nLeft = nRight;
140 rArr[rColItem.Count()-1].SetLeft( nLeft );
142 // The difference between the total sum of the desired width and the so far
143 // calculated columns and margins should result in the width of the last column.
144 rArr[rColItem.Count()-1].SetWishWidth( rCols.GetWishWidth() - o3tl::narrowing<sal_uInt16>(nSumAll) );
146 rCols.SetOrtho(false, 0, 0 );
149 // Delete tabs
150 static void lcl_EraseDefTabs(SvxTabStopItem& rTabStops)
152 // Delete DefTabs
153 for ( sal_uInt16 i = 0; i < rTabStops.Count(); )
155 // Here also throw out the DefTab to zero
156 if ( SvxTabAdjust::Default == rTabStops[i].GetAdjustment() ||
157 rTabStops[i].GetTabPos() == 0 )
159 rTabStops.Remove(i);
160 continue;
162 ++i;
166 // Flip page margin
167 void SwView::SwapPageMargin(const SwPageDesc& rDesc, SvxLRSpaceItem& rLRSpace)
169 sal_uInt16 nPhyPage, nVirPage;
170 GetWrtShell().GetPageNum( nPhyPage, nVirPage );
172 if ( rDesc.GetUseOn() == UseOnPage::Mirror && (nPhyPage % 2) == 0 )
174 tools::Long nTmp = rLRSpace.GetRight();
175 rLRSpace.SetRight( rLRSpace.GetLeft() );
176 rLRSpace.SetLeft( nTmp );
180 // If the frame border is moved, the column separator
181 // should stay in the same absolute position.
182 static void lcl_Scale(tools::Long& nVal, tools::Long nScale)
184 nVal *= nScale;
185 nVal >>= 8;
188 static void ResizeFrameCols(SwFormatCol& rCol,
189 tools::Long nOldWidth,
190 tools::Long nNewWidth,
191 tools::Long nLeftDelta )
193 SwColumns& rArr = rCol.GetColumns();
194 tools::Long nWishSum = static_cast<tools::Long>(rCol.GetWishWidth());
195 tools::Long nWishDiff = (nWishSum * 100/nOldWidth * nNewWidth) / 100 - nWishSum;
196 tools::Long nNewWishWidth = nWishSum + nWishDiff;
197 if(nNewWishWidth > 0xffffl)
199 // If the desired width is getting too large, then all values
200 // must be scaled appropriately.
201 tools::Long nScale = (0xffffl << 8)/ nNewWishWidth;
202 for(SwColumn & i : rArr)
204 SwColumn* pCol = &i;
205 tools::Long nVal = pCol->GetWishWidth();
206 lcl_Scale(nVal, nScale);
207 pCol->SetWishWidth(o3tl::narrowing<sal_uInt16>(nVal));
208 nVal = pCol->GetLeft();
209 lcl_Scale(nVal, nScale);
210 pCol->SetLeft(o3tl::narrowing<sal_uInt16>(nVal));
211 nVal = pCol->GetRight();
212 lcl_Scale(nVal, nScale);
213 pCol->SetRight(o3tl::narrowing<sal_uInt16>(nVal));
215 lcl_Scale(nNewWishWidth, nScale);
216 lcl_Scale(nWishDiff, nScale);
218 rCol.SetWishWidth( o3tl::narrowing<sal_uInt16>(nNewWishWidth) );
220 if( nLeftDelta >= 2 || nLeftDelta <= -2)
221 rArr.front().SetWishWidth(rArr.front().GetWishWidth() + o3tl::narrowing<sal_uInt16>(nWishDiff));
222 else
223 rArr.back().SetWishWidth(rArr.back().GetWishWidth() + o3tl::narrowing<sal_uInt16>(nWishDiff));
224 // Reset auto width
225 rCol.SetOrtho(false, 0, 0 );
228 // Here all changes to the tab bar will be shot again into the model.
229 void SwView::ExecTabWin( SfxRequest const & rReq )
231 SwWrtShell &rSh = GetWrtShell();
232 const FrameTypeFlags nFrameType = rSh.IsObjSelected() ?
233 FrameTypeFlags::DRAWOBJ :
234 rSh.GetFrameType(nullptr,true);
235 const bool bFrameSelection = rSh.IsFrameSelected();
236 const bool bBrowse = rSh.GetViewOptions()->getBrowseMode();
238 const sal_uInt16 nSlot = rReq.GetSlot();
239 const SfxItemSet* pReqArgs = rReq.GetArgs();
240 const size_t nDescId = rSh.GetCurPageDesc();
241 const SwPageDesc& rDesc = rSh.GetPageDesc( nDescId );
243 const bool bVerticalWriting = rSh.IsInVerticalText();
244 const SwFormatHeader& rHeaderFormat = rDesc.GetMaster().GetHeader();
245 SwFrameFormat *pHeaderFormat = const_cast<SwFrameFormat*>(rHeaderFormat.GetHeaderFormat());
247 const SwFormatFooter& rFooterFormat = rDesc.GetMaster().GetFooter();
248 SwFrameFormat *pFooterFormat = const_cast<SwFrameFormat*>(rFooterFormat.GetFooterFormat());
250 const SwFormatFrameSize &rFrameSize = rDesc.GetMaster().GetFrameSize();
252 const SwRect& rPageRect = rSh.GetAnyCurRect(CurRectType::Page);
253 const tools::Long nPageWidth = bBrowse ? rPageRect.Width() : rFrameSize.GetWidth();
254 const tools::Long nPageHeight = bBrowse ? rPageRect.Height() : rFrameSize.GetHeight();
256 bool bUnlockView = false;
257 rSh.StartAllAction();
258 bool bSect = bool(nFrameType & FrameTypeFlags::COLSECT);
260 switch (nSlot)
262 case SID_ATTR_LONG_LRSPACE:
263 if ( pReqArgs )
265 SvxLongLRSpaceItem aLongLR( pReqArgs->Get( SID_ATTR_LONG_LRSPACE ) );
266 SvxLRSpaceItem aLR(RES_LR_SPACE);
267 if ( !bSect && (bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY) )
269 SwFrameFormat* pFormat = rSh.GetFlyFrameFormat();
270 const SwRect &rRect = rSh.GetAnyCurRect(CurRectType::FlyEmbedded);
272 bool bVerticalFrame(false);
274 bool bRTL;
275 bool bVertL2R;
276 bVerticalFrame = ( bFrameSelection &&
277 rSh.IsFrameVertical(true, bRTL, bVertL2R) ) ||
278 ( !bFrameSelection && bVerticalWriting);
280 tools::Long nDeltaX = bVerticalFrame ?
281 rRect.Right() - rPageRect.Right() + aLongLR.GetRight() :
282 rPageRect.Left() + aLongLR.GetLeft() - rRect.Left();
284 SfxItemSetFixed<RES_FRM_SIZE, RES_FRM_SIZE,
285 RES_VERT_ORIENT, RES_HORI_ORIENT,
286 RES_COL, RES_COL> aSet( GetPool() );
288 if(bVerticalFrame)
290 SwFormatVertOrient aVertOrient(pFormat->GetVertOrient());
291 aVertOrient.SetVertOrient(text::VertOrientation::NONE);
292 aVertOrient.SetPos(aVertOrient.GetPos() + nDeltaX );
293 aSet.Put( aVertOrient );
295 else
297 SwFormatHoriOrient aHoriOrient( pFormat->GetHoriOrient() );
298 aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
299 aHoriOrient.SetPos( aHoriOrient.GetPos() + nDeltaX );
300 aSet.Put( aHoriOrient );
303 SwFormatFrameSize aSize( pFormat->GetFrameSize() );
304 tools::Long nOldWidth = aSize.GetWidth();
306 if(aSize.GetWidthPercent())
308 SwRect aRect;
309 rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
310 tools::Long nPrtWidth = aRect.Width();
311 aSize.SetWidthPercent(sal_uInt8((nPageWidth - aLongLR.GetLeft() - aLongLR.GetRight()) * 100 /nPrtWidth));
313 else
314 aSize.SetWidth( nPageWidth -
315 (aLongLR.GetLeft() + aLongLR.GetRight()));
317 if( nFrameType & FrameTypeFlags::COLUMN )
319 SwFormatCol aCol(pFormat->GetCol());
321 ::ResizeFrameCols(aCol, nOldWidth, aSize.GetWidth(), nDeltaX );
322 aSet.Put(aCol);
325 aSet.Put( aSize );
327 rSh.StartAction();
328 rSh.Push();
329 rSh.SetFlyFrameAttr( aSet );
330 // Cancel the frame selection
331 if(!bFrameSelection && rSh.IsFrameSelected())
333 rSh.UnSelectFrame();
334 rSh.LeaveSelFrameMode();
336 rSh.Pop();
337 rSh.EndAction();
339 else if ( nFrameType & ( FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER ))
341 // Subtract out page margins
342 tools::Long nOld = rDesc.GetMaster().GetLRSpace().GetLeft();
343 aLongLR.SetLeft( nOld > aLongLR.GetLeft() ? 0 : aLongLR.GetLeft() - nOld );
345 nOld = rDesc.GetMaster().GetLRSpace().GetRight();
346 aLongLR.SetRight( nOld > aLongLR.GetRight() ? 0 : aLongLR.GetRight() - nOld );
347 aLR.SetLeft(aLongLR.GetLeft());
348 aLR.SetRight(aLongLR.GetRight());
350 if ( nFrameType & FrameTypeFlags::HEADER && pHeaderFormat )
351 pHeaderFormat->SetFormatAttr( aLR );
352 else if( nFrameType & FrameTypeFlags::FOOTER && pFooterFormat )
353 pFooterFormat->SetFormatAttr( aLR );
355 else if( nFrameType == FrameTypeFlags::DRAWOBJ)
357 SwRect aRect( rSh.GetObjRect() );
358 aRect.Left( aLongLR.GetLeft() + rPageRect.Left() );
359 aRect.Right( rPageRect.Right() - aLongLR.GetRight());
360 rSh.SetObjRect( aRect );
362 else if(bSect || rSh.IsDirectlyInSection())
364 //change the section indents and the columns if available
365 //at first determine the changes
366 SwRect aSectRect = rSh.GetAnyCurRect(CurRectType::SectionPrt);
367 const SwRect aTmpRect = rSh.GetAnyCurRect(CurRectType::Section);
368 aSectRect.Pos() += aTmpRect.Pos();
369 tools::Long nLeftDiff = aLongLR.GetLeft() - static_cast<tools::Long>(aSectRect.Left() - rPageRect.Left() );
370 tools::Long nRightDiff = aLongLR.GetRight() - static_cast<tools::Long>( rPageRect.Right() - aSectRect.Right());
371 //change the LRSpaceItem of the section accordingly
372 const SwSection* pCurrSect = rSh.GetCurrSection();
373 const SwSectionFormat* pSectFormat = pCurrSect->GetFormat();
374 SvxLRSpaceItem aLRTmp = pSectFormat->GetLRSpace();
375 aLRTmp.SetLeft(aLRTmp.GetLeft() + nLeftDiff);
376 aLRTmp.SetRight(aLRTmp.GetRight() + nRightDiff);
377 SfxItemSetFixed<RES_LR_SPACE, RES_LR_SPACE, RES_COL, RES_COL> aSet(rSh.GetAttrPool());
378 aSet.Put(aLRTmp);
379 //change the first/last column
380 if(bSect)
382 SwFormatCol aCols( pSectFormat->GetCol() );
383 tools::Long nDiffWidth = nLeftDiff + nRightDiff;
384 ::ResizeFrameCols(aCols, aSectRect.Width(), aSectRect.Width() - nDiffWidth, nLeftDiff );
385 aSet.Put( aCols );
387 SwSectionData aData(*pCurrSect);
388 rSh.UpdateSection(rSh.GetSectionFormatPos(*pSectFormat), aData, &aSet);
390 else
391 { // Adjust page margins
392 aLR.SetLeft(aLongLR.GetLeft());
393 aLR.SetRight(aLongLR.GetRight());
394 SwapPageMargin( rDesc, aLR );
395 SwPageDesc aDesc( rDesc );
396 aDesc.GetMaster().SetFormatAttr( aLR );
397 rSh.ChgPageDesc( nDescId, aDesc );
400 break;
402 // apply new left and right margins to current page style
403 case SID_ATTR_PAGE_LRSPACE:
404 if ( pReqArgs )
406 const SvxLongLRSpaceItem& aLongLR( pReqArgs->Get( SID_ATTR_PAGE_LRSPACE ) );
408 SwPageDesc aDesc( rDesc );
410 SvxLRSpaceItem aLR( RES_LR_SPACE );
411 aLR.SetLeft(aLongLR.GetLeft());
412 aLR.SetRight(aLongLR.GetRight());
413 SwapPageMargin( rDesc, aLR );
414 aDesc.GetMaster().SetFormatAttr( aLR );
416 rSh.ChgPageDesc( nDescId, aDesc );
418 break;
420 case SID_ATTR_LONG_ULSPACE:
421 if ( pReqArgs )
423 SvxLongULSpaceItem aLongULSpace( pReqArgs->Get( SID_ATTR_LONG_ULSPACE ) );
425 if( bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY )
427 SwFrameFormat* pFormat = rSh.GetFlyFrameFormat();
428 const SwRect &rRect = rSh.GetAnyCurRect(CurRectType::FlyEmbedded);
429 const tools::Long nDeltaY = rPageRect.Top() + aLongULSpace.GetUpper() - rRect.Top();
430 const tools::Long nHeight = nPageHeight - (aLongULSpace.GetUpper() + aLongULSpace.GetLower());
432 SfxItemSetFixed<RES_FRM_SIZE, RES_FRM_SIZE,
433 RES_VERT_ORIENT, RES_HORI_ORIENT> aSet( GetPool() );
434 //which of the orientation attributes is to be put depends on the frame's environment
435 bool bRTL;
436 bool bVertL2R;
437 if ( ( bFrameSelection &&
438 rSh.IsFrameVertical(true, bRTL, bVertL2R ) ) ||
439 ( !bFrameSelection && bVerticalWriting ) )
441 SwFormatHoriOrient aHoriOrient(pFormat->GetHoriOrient());
442 aHoriOrient.SetHoriOrient(text::HoriOrientation::NONE);
443 aHoriOrient.SetPos(aHoriOrient.GetPos() + nDeltaY );
444 aSet.Put( aHoriOrient );
446 else
448 SwFormatVertOrient aVertOrient(pFormat->GetVertOrient());
449 aVertOrient.SetVertOrient(text::VertOrientation::NONE);
450 aVertOrient.SetPos(aVertOrient.GetPos() + nDeltaY );
451 aSet.Put( aVertOrient );
453 SwFormatFrameSize aSize(pFormat->GetFrameSize());
454 if(aSize.GetHeightPercent())
456 SwRect aRect;
457 rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
458 tools::Long nPrtHeight = aRect.Height();
459 aSize.SetHeightPercent(sal_uInt8(nHeight * 100 /nPrtHeight));
461 else
462 aSize.SetHeight(nHeight );
464 aSet.Put( aSize );
465 rSh.SetFlyFrameAttr( aSet );
467 else if( nFrameType == FrameTypeFlags::DRAWOBJ )
469 SwRect aRect( rSh.GetObjRect() );
470 aRect.Top( aLongULSpace.GetUpper() + rPageRect.Top() );
471 aRect.Bottom( rPageRect.Bottom() - aLongULSpace.GetLower() );
472 rSh.SetObjRect( aRect ) ;
474 else if(bVerticalWriting && (bSect || rSh.IsDirectlyInSection()))
476 //change the section indents and the columns if available
477 //at first determine the changes
478 SwRect aSectRect = rSh.GetAnyCurRect(CurRectType::SectionPrt);
479 const SwRect aTmpRect = rSh.GetAnyCurRect(CurRectType::Section);
480 aSectRect.Pos() += aTmpRect.Pos();
481 const tools::Long nLeftDiff = aLongULSpace.GetUpper() - static_cast<tools::Long>(aSectRect.Top() - rPageRect.Top());
482 const tools::Long nRightDiff = aLongULSpace.GetLower() - static_cast<tools::Long>(nPageHeight - aSectRect.Bottom() + rPageRect.Top());
483 //change the LRSpaceItem of the section accordingly
484 const SwSection* pCurrSect = rSh.GetCurrSection();
485 const SwSectionFormat* pSectFormat = pCurrSect->GetFormat();
486 SvxLRSpaceItem aLR = pSectFormat->GetLRSpace();
487 aLR.SetLeft(aLR.GetLeft() + nLeftDiff);
488 aLR.SetRight(aLR.GetRight() + nRightDiff);
489 SfxItemSetFixed<RES_LR_SPACE, RES_LR_SPACE, RES_COL, RES_COL> aSet(rSh.GetAttrPool());
490 aSet.Put(aLR);
491 //change the first/last column
492 if(bSect)
494 SwFormatCol aCols( pSectFormat->GetCol() );
495 tools::Long nDiffWidth = nLeftDiff + nRightDiff;
496 ::ResizeFrameCols(aCols, aSectRect.Height(), aSectRect.Height() - nDiffWidth, nLeftDiff );
497 aSet.Put( aCols );
499 SwSectionData aData(*pCurrSect);
500 rSh.UpdateSection(rSh.GetSectionFormatPos(*pSectFormat), aData, &aSet);
502 else
503 { SwPageDesc aDesc( rDesc );
505 if ( nFrameType & ( FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER ))
508 const bool bHead = bool(nFrameType & FrameTypeFlags::HEADER);
509 SvxULSpaceItem aUL( rDesc.GetMaster().GetULSpace() );
510 if ( bHead )
511 aUL.SetUpper( o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper()) );
512 else
513 aUL.SetLower( o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower()) );
514 aDesc.GetMaster().SetFormatAttr( aUL );
516 if( (bHead && pHeaderFormat) || (!bHead && pFooterFormat) )
518 SwFormatFrameSize aSz( bHead ? pHeaderFormat->GetFrameSize() :
519 pFooterFormat->GetFrameSize() );
520 aSz.SetHeightSizeType( SwFrameSize::Fixed );
521 aSz.SetHeight(nPageHeight - aLongULSpace.GetLower() -
522 aLongULSpace.GetUpper() );
523 if ( bHead )
524 pHeaderFormat->SetFormatAttr( aSz );
525 else
526 pFooterFormat->SetFormatAttr( aSz );
529 else
531 SvxULSpaceItem aUL(RES_UL_SPACE);
532 aUL.SetUpper(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper()));
533 aUL.SetLower(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower()));
534 aDesc.GetMaster().SetFormatAttr(aUL);
537 rSh.ChgPageDesc( nDescId, aDesc );
540 break;
542 // apply new top and bottom margins to current page style
543 case SID_ATTR_PAGE_ULSPACE:
544 if ( pReqArgs )
546 const SvxLongULSpaceItem& aLongULSpace( pReqArgs->Get( SID_ATTR_PAGE_ULSPACE ) );
548 SwPageDesc aDesc( rDesc );
550 SvxULSpaceItem aUL(RES_UL_SPACE);
551 aUL.SetUpper(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper()));
552 aUL.SetLower(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower()));
553 aDesc.GetMaster().SetFormatAttr(aUL);
555 rSh.ChgPageDesc( nDescId, aDesc );
557 break;
559 case SID_ATTR_PAGE_COLUMN:
560 if ( pReqArgs )
562 const SfxInt16Item aColumnItem( static_cast<const SfxInt16Item&>(pReqArgs->Get(nSlot)) );
563 const sal_uInt16 nPageColumnType = aColumnItem.GetValue();
565 // nPageColumnType =
566 // 1 - single-columned page
567 // 2 - two-columned page
568 // 3 - three-columned page
569 // 4 - two-columned page with left column width of 2/3 of page width
570 // 5 - two-columned page with right column width of 2/3 of page width
572 sal_uInt16 nCount = 2;
573 if ( nPageColumnType == 1 )
575 nCount = 0;
577 else if ( nPageColumnType == 3 )
579 nCount = 3;
582 const sal_uInt16 nGutterWidth = 0;
584 const SvxLRSpaceItem aLR( rDesc.GetMaster().GetLRSpace() );
585 const tools::Long nLeft = aLR.GetLeft();
586 const tools::Long nRight = aLR.GetRight();
587 const tools::Long nWidth = nPageWidth - nLeft - nRight;
589 SwFormatCol aCols( rDesc.GetMaster().GetCol() );
590 aCols.Init( nCount, nGutterWidth, nWidth );
591 aCols.SetWishWidth( nWidth );
592 aCols.SetGutterWidth( nGutterWidth, nWidth );
593 aCols.SetOrtho( false, nGutterWidth, nWidth );
595 tools::Long nColumnLeft = 0;
596 tools::Long nColumnRight = 0;
597 if ( nPageColumnType == 4 )
599 nColumnRight = static_cast<tools::Long>(nWidth/3);
600 nColumnLeft = nWidth - nColumnRight;
601 aCols.GetColumns()[0].SetWishWidth( nColumnLeft );
602 aCols.GetColumns()[1].SetWishWidth( nColumnRight );
604 else if ( nPageColumnType == 5 )
606 nColumnLeft = static_cast<tools::Long>(nWidth/3);
607 nColumnRight = nWidth - nColumnLeft;
608 aCols.GetColumns()[0].SetWishWidth( nColumnLeft );
609 aCols.GetColumns()[1].SetWishWidth( nColumnRight );
612 SwPageDesc aDesc( rDesc );
613 aDesc.GetMaster().SetFormatAttr( aCols );
614 rSh.ChgPageDesc( rSh.GetCurPageDesc(), aDesc );
616 break;
618 case SID_ATTR_TABSTOP_VERTICAL:
619 case SID_ATTR_TABSTOP:
620 if (pReqArgs)
622 const sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
623 SvxTabStopItem aTabStops( static_cast<const SvxTabStopItem&>(pReqArgs->
624 Get( nWhich )));
625 aTabStops.SetWhich(RES_PARATR_TABSTOP);
626 const SvxTabStopItem& rDefTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
628 // Default tab at pos 0
629 SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_FIRSTLINE> aSet(GetPool());
630 rSh.GetCurAttr( aSet );
631 const SvxFirstLineIndentItem & rFirstLine(aSet.Get(RES_MARGIN_FIRSTLINE));
633 if (rFirstLine.GetTextFirstLineOffset() < 0)
635 SvxTabStop aSwTabStop( 0, SvxTabAdjust::Default );
636 aTabStops.Insert( aSwTabStop );
639 // Populate with default tabs.
640 ::MakeDefTabs( ::GetTabDist( rDefTabs ), aTabStops );
642 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
643 if( pColl && pColl->IsAutoUpdateOnDirectFormat() )
645 SfxItemSetFixed<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP> aTmp(GetPool());
646 aTmp.Put(aTabStops);
647 rSh.AutoUpdatePara( pColl, aTmp );
649 else
650 rSh.SetAttrItem( aTabStops );
652 break;
653 case SID_TABSTOP_ADD_OR_CHANGE:
654 if (pReqArgs)
656 const auto aIndexItem = static_cast<const SfxInt32Item&>(pReqArgs->Get(SID_TABSTOP_ATTR_INDEX));
657 const auto aPositionItem = static_cast<const SfxInt32Item&>(pReqArgs->Get(SID_TABSTOP_ATTR_POSITION));
658 const auto aRemoveItem = static_cast<const SfxBoolItem&>(pReqArgs->Get(SID_TABSTOP_ATTR_REMOVE));
659 const sal_Int32 nIndex = aIndexItem.GetValue();
660 const sal_Int32 nPosition = aPositionItem.GetValue();
661 const bool bRemove = aRemoveItem.GetValue();
665 SfxItemSetFixed<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP> aItemSet(GetPool());
666 rSh.GetCurAttr(aItemSet);
667 SvxTabStopItem aTabStopItem(aItemSet.Get(RES_PARATR_TABSTOP));
668 lcl_EraseDefTabs(aTabStopItem);
670 if (nIndex < aTabStopItem.Count())
672 if (nIndex == -1)
674 SvxTabStop aSwTabStop(0, SvxTabAdjust::Default);
675 aTabStopItem.Insert(aSwTabStop);
677 const SvxTabStopItem& rDefaultTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
678 MakeDefTabs(GetTabDist(rDefaultTabs), aTabStopItem);
680 SvxTabStop aTabStop(nPosition);
681 aTabStopItem.Insert(aTabStop);
683 else
685 SvxTabStop aTabStop = aTabStopItem.At(nIndex);
686 aTabStopItem.Remove(nIndex);
687 if (!bRemove)
689 aTabStop.GetTabPos() = nPosition;
690 aTabStopItem.Insert(aTabStop);
692 SvxTabStop aSwTabStop(0, SvxTabAdjust::Default);
693 aTabStopItem.Insert(aSwTabStop);
695 const SvxTabStopItem& rDefaultTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
696 MakeDefTabs(GetTabDist(rDefaultTabs), aTabStopItem);
698 rSh.SetAttrItem(aTabStopItem);
701 break;
702 case SID_PARAGRAPH_CHANGE_STATE:
704 if (pReqArgs)
706 SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_RIGHT> aLRSpaceSet(GetPool());
707 rSh.GetCurAttr( aLRSpaceSet );
709 if (const SfxStringItem *fLineIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_FIRST_LINE_INDENT))
711 SvxFirstLineIndentItem firstLine(aLRSpaceSet.Get(RES_MARGIN_FIRSTLINE));
712 const OUString ratio = fLineIndent->GetValue();
713 firstLine.SetTextFirstLineOffset(nPageWidth * ratio.toFloat());
714 rSh.SetAttrItem(firstLine);
716 else if (const SfxStringItem *pLeftIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_LEFT_INDENT))
718 SvxTextLeftMarginItem leftMargin(aLRSpaceSet.Get(RES_MARGIN_TEXTLEFT));
719 const OUString ratio = pLeftIndent->GetValue();
720 // this used to call SetLeft() but was probably a bug
721 leftMargin.SetTextLeft(nPageWidth * ratio.toFloat());
722 rSh.SetAttrItem(leftMargin);
724 else if (const SfxStringItem *pRightIndent = pReqArgs->GetItemIfSet(SID_PARAGRAPH_RIGHT_INDENT))
726 SvxRightMarginItem rightMargin(aLRSpaceSet.Get(RES_MARGIN_RIGHT));
727 const OUString ratio = pRightIndent->GetValue();
728 rightMargin.SetRight(nPageWidth * ratio.toFloat());
729 rSh.SetAttrItem(rightMargin);
732 break;
734 case SID_HANGING_INDENT:
736 SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_RIGHT> aLRSpaceSet(GetPool());
737 rSh.GetCurAttr( aLRSpaceSet );
738 SvxFirstLineIndentItem firstLine(aLRSpaceSet.Get(RES_MARGIN_FIRSTLINE));
739 SvxTextLeftMarginItem leftMargin(aLRSpaceSet.Get(RES_MARGIN_TEXTLEFT));
740 leftMargin.SetTextLeft(leftMargin.GetTextLeft() + firstLine.GetTextFirstLineOffset());
741 firstLine.SetTextFirstLineOffset((firstLine.GetTextFirstLineOffset()) * -1);
742 firstLine.SetAutoFirst(false); // old code would do this, is it wanted?
743 rSh.SetAttrItem(firstLine);
744 rSh.SetAttrItem(leftMargin);
745 break;
748 case SID_ATTR_PARA_LRSPACE_VERTICAL:
749 case SID_ATTR_PARA_LRSPACE:
750 if ( pReqArgs )
752 SvxLRSpaceItem aParaMargin(static_cast<const SvxLRSpaceItem&>(pReqArgs->Get(nSlot)));
754 aParaMargin.SetRight( aParaMargin.GetRight() - m_nRightBorderDistance );
755 aParaMargin.SetTextLeft(aParaMargin.GetTextLeft() - m_nLeftBorderDistance );
757 aParaMargin.SetWhich( RES_LR_SPACE );
758 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
760 SvxFirstLineIndentItem firstLine(RES_MARGIN_FIRSTLINE);
761 firstLine.SetTextFirstLineOffset(aParaMargin.GetTextFirstLineOffset(), aParaMargin.GetPropTextFirstLineOffset());
762 firstLine.SetAutoFirst(aParaMargin.IsAutoFirst());
763 SvxTextLeftMarginItem const leftMargin(aParaMargin.GetTextLeft(), RES_MARGIN_TEXTLEFT);
764 SvxRightMarginItem const rightMargin(aParaMargin.GetRight(), RES_MARGIN_RIGHT);
766 // #i23726#
767 if (m_pNumRuleNodeFromDoc)
769 // --> #i42922# Mouse move of numbering label
770 // has to consider the left indent of the paragraph
771 SfxItemSetFixed<RES_MARGIN_TEXTLEFT, RES_MARGIN_TEXTLEFT> aSet( GetPool() );
772 rSh.GetCurAttr( aSet );
773 const SvxTextLeftMarginItem & rLeftMargin(aSet.Get(RES_MARGIN_TEXTLEFT));
775 SwPosition aPos(*m_pNumRuleNodeFromDoc);
776 // #i90078#
777 rSh.SetIndent(static_cast<short>(aParaMargin.GetTextLeft() - rLeftMargin.GetTextLeft()), aPos);
778 // #i42921# invalidate state of indent in order to get a ruler update.
779 aParaMargin.SetWhich( nSlot );
780 GetViewFrame().GetBindings().SetState( aParaMargin );
782 else if( pColl && pColl->IsAutoUpdateOnDirectFormat() )
784 SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_RIGHT> aSet(GetPool());
785 aSet.Put(firstLine);
786 aSet.Put(leftMargin);
787 aSet.Put(rightMargin);
788 rSh.AutoUpdatePara( pColl, aSet);
790 else
792 rSh.SetAttrItem(firstLine);
793 rSh.SetAttrItem(leftMargin);
794 rSh.SetAttrItem(rightMargin);
797 if ( aParaMargin.GetTextFirstLineOffset() < 0 )
799 SfxItemSetFixed<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP> aSet( GetPool() );
801 rSh.GetCurAttr( aSet );
802 const SvxTabStopItem& rTabStops = aSet.Get(RES_PARATR_TABSTOP);
804 // Do we have a tab at position zero?
805 sal_uInt16 i;
807 for ( i = 0; i < rTabStops.Count(); ++i )
808 if ( rTabStops[i].GetTabPos() == 0 )
809 break;
811 if ( i >= rTabStops.Count() )
813 // No DefTab
814 std::unique_ptr<SvxTabStopItem> aTabStops(rTabStops.Clone());
816 ::lcl_EraseDefTabs(*aTabStops);
818 SvxTabStop aSwTabStop( 0, SvxTabAdjust::Default );
819 aTabStops->Insert(aSwTabStop);
821 const SvxTabStopItem& rDefTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
822 ::MakeDefTabs( ::GetTabDist(rDefTabs), *aTabStops );
824 if( pColl && pColl->IsAutoUpdateOnDirectFormat())
826 SfxItemSetFixed<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP> aSetTmp(GetPool());
827 aSetTmp.Put(std::move(aTabStops));
828 rSh.AutoUpdatePara( pColl, aSetTmp );
830 else
831 rSh.SetAttrItem( *aTabStops );
835 break;
837 case SID_ATTR_PARA_ULSPACE:
838 if ( pReqArgs )
840 SvxULSpaceItem aParaMargin(static_cast<const SvxULSpaceItem&>(pReqArgs->Get(nSlot)));
842 aParaMargin.SetUpper( aParaMargin.GetUpper() );
843 aParaMargin.SetLower(aParaMargin.GetLower());
845 aParaMargin.SetWhich( RES_UL_SPACE );
846 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
847 if( pColl && pColl->IsAutoUpdateOnDirectFormat() )
849 SfxItemSetFixed<RES_UL_SPACE, RES_UL_SPACE> aSet(GetPool());
850 aSet.Put(aParaMargin);
851 rSh.AutoUpdatePara( pColl, aSet);
853 else
854 rSh.SetAttrItem( aParaMargin );
856 break;
857 case SID_PARASPACE_INCREASE:
858 case SID_PARASPACE_DECREASE:
860 SfxItemSetFixed<RES_UL_SPACE, RES_UL_SPACE> aULSpaceSet( GetPool() );
861 rSh.GetCurAttr( aULSpaceSet );
862 SvxULSpaceItem aULSpace( aULSpaceSet.Get( RES_UL_SPACE ) );
863 sal_uInt16 nUpper = aULSpace.GetUpper();
864 sal_uInt16 nLower = aULSpace.GetLower();
866 if ( nSlot == SID_PARASPACE_INCREASE )
868 nUpper = std::min< sal_uInt16 >( nUpper + 57, 5670 );
869 nLower = std::min< sal_uInt16 >( nLower + 57, 5670 );
871 else
873 nUpper = std::max< sal_Int16 >( nUpper - 57, 0 );
874 nLower = std::max< sal_Int16 >( nLower - 57, 0 );
877 aULSpace.SetUpper( nUpper );
878 aULSpace.SetLower( nLower );
880 SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
881 if( pColl && pColl->IsAutoUpdateOnDirectFormat() )
883 aULSpaceSet.Put( aULSpace );
884 rSh.AutoUpdatePara( pColl, aULSpaceSet );
886 else
887 rSh.SetAttrItem( aULSpace, SetAttrMode::DEFAULT, true );
889 break;
891 case SID_RULER_CHANGE_STATE:
892 if (pReqArgs)
894 if ( const SfxStringItem *pMargin1 = pReqArgs->GetItemIfSet(SID_RULER_MARGIN1) )
896 const OUString ratio = pMargin1->GetValue();
897 GetHRuler().SetValues(RulerChangeType::MARGIN1, GetHRuler().GetPageWidth() * ratio.toFloat());
899 else if ( const SfxStringItem *pMargin2 = pReqArgs->GetItemIfSet(SID_RULER_MARGIN2) )
901 const OUString ratio = pMargin2->GetValue();
902 GetHRuler().SetValues(RulerChangeType::MARGIN2, GetHRuler().GetPageWidth() * ratio.toFloat());
905 break;
906 case SID_RULER_BORDERS_VERTICAL:
907 case SID_RULER_BORDERS:
908 if ( pReqArgs )
910 SvxColumnItem aColItem(static_cast<const SvxColumnItem&>(pReqArgs->Get(nSlot)));
912 if( m_bSetTabColFromDoc || (!bSect && rSh.GetTableFormat()) )
914 OSL_ENSURE(aColItem.Count(), "ColDesc is empty!!");
916 const bool bSingleLine = rReq.
917 GetArgs()->Get(SID_RULER_ACT_LINE_ONLY).GetValue();
919 SwTabCols aTabCols;
920 if ( m_bSetTabColFromDoc )
921 rSh.GetMouseTabCols( aTabCols, m_aTabColFromDocPos );
922 else
923 rSh.GetTabCols(aTabCols);
925 // left table border
926 tools::Long nBorder = static_cast<tools::Long>(aColItem.GetLeft() - aTabCols.GetLeftMin());
927 aTabCols.SetLeft( nBorder );
929 nBorder = (bVerticalWriting ? nPageHeight : nPageWidth) - aTabCols.GetLeftMin() - aColItem.GetRight();
931 if ( aColItem.GetRight() > 0 )
932 aTabCols.SetRight( nBorder );
934 // Tabcols sequentially
935 // The last column is defined by the edge.
936 // Columns in right-to-left tables need to be mirrored
937 bool bIsTableRTL =
938 IsTabColFromDoc() ?
939 rSh.IsMouseTableRightToLeft(m_aTabColFromDocPos)
940 : rSh.IsTableRightToLeft();
941 const size_t nColCount = aColItem.Count() - 1;
942 if(bIsTableRTL)
944 for ( size_t i = 0; i < nColCount && i < aTabCols.Count(); ++i )
946 const SvxColumnDescription& rCol = aColItem[nColCount - i];
947 aTabCols[i] = aTabCols.GetRight() - rCol.nStart;
948 aTabCols.SetHidden( i, !rCol.bVisible );
951 else
953 for ( size_t i = 0; i < nColCount && i < aTabCols.Count(); ++i )
955 const SvxColumnDescription& rCol = aColItem[i];
956 aTabCols[i] = rCol.nEnd + aTabCols.GetLeft();
957 aTabCols.SetHidden( i, !rCol.bVisible );
961 if ( m_bSetTabColFromDoc )
963 if( !rSh.IsViewLocked() )
965 bUnlockView = true;
966 rSh.LockView( true );
968 rSh.SetMouseTabCols( aTabCols, bSingleLine,
969 m_aTabColFromDocPos );
971 else
972 rSh.SetTabCols(aTabCols, bSingleLine);
975 else
977 if ( bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY || bSect)
979 SwSectionFormat *pSectFormat = nullptr;
980 SfxItemSetFixed<RES_COL, RES_COL> aSet( GetPool() );
981 if(bSect)
983 SwSection *pSect = rSh.GetAnySection();
984 OSL_ENSURE( pSect, "Which section?");
985 pSectFormat = pSect->GetFormat();
987 else
989 rSh.GetFlyFrameAttr( aSet );
991 SwFormatCol aCols(
992 bSect ?
993 pSectFormat->GetCol() :
994 aSet.Get( RES_COL, false ));
995 SwRect aCurRect = rSh.GetAnyCurRect(bSect ? CurRectType::SectionPrt : CurRectType::FlyEmbeddedPrt);
996 const tools::Long lWidth = bVerticalWriting ? aCurRect.Height() : aCurRect.Width();
997 ::lcl_ConvertToCols( aColItem, lWidth, aCols );
998 aSet.Put( aCols );
999 if(bSect)
1000 rSh.SetSectionAttr( aSet, pSectFormat );
1001 else
1003 rSh.StartAction();
1004 rSh.Push();
1005 rSh.SetFlyFrameAttr( aSet );
1006 // Cancel the frame selection again
1007 if(!bFrameSelection && rSh.IsFrameSelected())
1009 rSh.UnSelectFrame();
1010 rSh.LeaveSelFrameMode();
1012 rSh.Pop();
1013 rSh.EndAction();
1016 else
1018 SwFormatCol aCols( rDesc.GetMaster().GetCol() );
1019 const SwRect aPrtRect = rSh.GetAnyCurRect(CurRectType::PagePrt);
1020 ::lcl_ConvertToCols( aColItem,
1021 bVerticalWriting ? aPrtRect.Height() : aPrtRect.Width(),
1022 aCols );
1023 SwPageDesc aDesc( rDesc );
1024 aDesc.GetMaster().SetFormatAttr( aCols );
1025 rSh.ChgPageDesc( rSh.GetCurPageDesc(), aDesc );
1029 break;
1031 case SID_RULER_ROWS :
1032 case SID_RULER_ROWS_VERTICAL:
1033 if (pReqArgs)
1035 SvxColumnItem aColItem(static_cast<const SvxColumnItem&>(pReqArgs->Get(nSlot)));
1037 if( m_bSetTabColFromDoc || (!bSect && rSh.GetTableFormat()) )
1039 OSL_ENSURE(aColItem.Count(), "ColDesc is empty!!");
1041 SwTabCols aTabCols;
1042 if ( m_bSetTabRowFromDoc )
1043 rSh.GetMouseTabRows( aTabCols, m_aTabColFromDocPos );
1044 else
1045 rSh.GetTabRows(aTabCols);
1047 if ( bVerticalWriting )
1049 aTabCols.SetRight(nPageWidth - aColItem.GetRight() - aColItem.GetLeft());
1050 aTabCols.SetLeftMin(aColItem.GetLeft());
1052 else
1054 tools::Long nBorder = nPageHeight - aTabCols.GetLeftMin() - aColItem.GetRight();
1055 aTabCols.SetRight( nBorder );
1058 const size_t nColItems = aColItem.Count() - 1;
1059 if(bVerticalWriting)
1061 for ( size_t i = nColItems; i; --i )
1063 const SvxColumnDescription& rCol = aColItem[i - 1];
1064 tools::Long nColumnPos = aTabCols.GetRight() - rCol.nEnd ;
1065 aTabCols[i - 1] = nColumnPos;
1066 aTabCols.SetHidden( i - 1, !rCol.bVisible );
1069 else
1071 for ( size_t i = 0; i < nColItems; ++i )
1073 const SvxColumnDescription& rCol = aColItem[i];
1074 aTabCols[i] = rCol.nEnd + aTabCols.GetLeft();
1075 aTabCols.SetHidden( i, !rCol.bVisible );
1078 bool bSingleLine = false;
1079 if( const SfxBoolItem* pSingleLine = rReq.GetArgs()->GetItemIfSet(SID_RULER_ACT_LINE_ONLY, false) )
1080 bSingleLine = pSingleLine->GetValue();
1081 if ( m_bSetTabRowFromDoc )
1083 if( !rSh.IsViewLocked() )
1085 bUnlockView = true;
1086 rSh.LockView( true );
1088 rSh.SetMouseTabRows( aTabCols, bSingleLine, m_aTabColFromDocPos );
1090 else
1091 rSh.SetTabRows(aTabCols, bSingleLine);
1094 break;
1095 case SID_TABLE_CHANGE_CURRENT_BORDER_POSITION:
1097 if (pReqArgs)
1099 const SfxStringItem *pBorderType = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_TYPE);
1100 const SfxUInt16Item *pIndex = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_INDEX);
1101 const SfxInt32Item *pOffset = pReqArgs->GetItemIfSet(SID_TABLE_BORDER_OFFSET);
1102 constexpr tools::Long constDistanceOffset = 40;
1104 if (pBorderType && pIndex && pOffset)
1106 const OUString sType = pBorderType->GetValue();
1107 const sal_uInt16 nIndex = pIndex->GetValue();
1108 const sal_Int32 nOffset = pOffset->GetValue();
1110 if (sType.startsWith("column"))
1112 SwTabCols aTabCols;
1113 rSh.GetTabCols(aTabCols);
1115 if (sType == "column-left")
1117 tools::Long nNewPosition = aTabCols.GetLeft() + nOffset;
1118 if(aTabCols.Count() > 0)
1120 auto & rEntry = aTabCols.GetEntry(0);
1121 nNewPosition = std::min(nNewPosition, rEntry.nPos - constDistanceOffset);
1123 aTabCols.SetLeft(nNewPosition);
1125 else if (sType == "column-right")
1127 tools::Long nNewPosition = aTabCols.GetRight() + nOffset;
1128 if(aTabCols.Count() > 0)
1130 auto & rEntry = aTabCols.GetEntry(aTabCols.Count() - 1);
1131 nNewPosition = std::max(nNewPosition, rEntry.nPos + constDistanceOffset);
1133 aTabCols.SetRight(nNewPosition);
1135 else if (sType == "column-middle" && nIndex < aTabCols.Count())
1137 auto & rEntry = aTabCols.GetEntry(nIndex);
1138 tools::Long nNewPosition = rEntry.nPos + nOffset;
1139 nNewPosition = std::clamp(nNewPosition, rEntry.nMin, rEntry.nMax - constDistanceOffset);
1140 rEntry.nPos = nNewPosition;
1143 rSh.SetTabCols(aTabCols, false);
1145 else if (sType.startsWith("row"))
1147 SwTabCols aTabRows;
1148 rSh.GetTabRows(aTabRows);
1150 if (sType == "row-left")
1152 auto & rEntry = aTabRows.GetEntry(0);
1153 tools::Long nNewPosition = aTabRows.GetLeft() + nOffset;
1154 nNewPosition = std::min(nNewPosition, rEntry.nPos - constDistanceOffset);
1155 aTabRows.SetLeft(nNewPosition);
1157 else if (sType == "row-right")
1159 tools::Long nNewPosition = aTabRows.GetRight() + nOffset;
1160 if(aTabRows.Count() > 0)
1162 auto & rEntry = aTabRows.GetEntry(aTabRows.Count() - 1);
1163 nNewPosition = std::max(nNewPosition, rEntry.nPos + constDistanceOffset);
1165 aTabRows.SetRight(nNewPosition);
1167 else if (sType == "row-middle" && nIndex < aTabRows.Count())
1169 auto & rEntry = aTabRows.GetEntry(nIndex);
1170 tools::Long nNewPosition = rEntry.nPos + nOffset;
1171 nNewPosition = std::clamp(nNewPosition, rEntry.nMin, rEntry.nMax - constDistanceOffset);
1172 rEntry.nPos = nNewPosition;
1175 rSh.SetTabRows(aTabRows, false);
1180 break;
1181 case SID_ATTR_PAGE_HEADER:
1183 if ( pReqArgs )
1185 const bool bHeaderOn = static_cast<const SfxBoolItem&>(pReqArgs->Get(SID_ATTR_PAGE_HEADER)).GetValue();
1186 SwPageDesc aDesc(rDesc);
1187 SwFrameFormat &rMaster = aDesc.GetMaster();
1188 rMaster.SetFormatAttr( SwFormatHeader( bHeaderOn ));
1189 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1192 break;
1193 case SID_ATTR_PAGE_HEADER_LRMARGIN:
1195 if ( pReqArgs && rDesc.GetMaster().GetHeader().IsActive() )
1197 const SvxLongLRSpaceItem& aLongLR = pReqArgs->Get(SID_ATTR_PAGE_HEADER_LRMARGIN);
1198 SvxLRSpaceItem aLR(RES_LR_SPACE);
1199 SwPageDesc aDesc(rDesc);
1200 aLR.SetLeft(aLongLR.GetLeft());
1201 aLR.SetRight(aLongLR.GetRight());
1202 SwFrameFormat* pFormat = const_cast<SwFrameFormat*>(aDesc.GetMaster().GetHeader().GetHeaderFormat());
1203 pFormat->SetFormatAttr( aLR );
1204 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1207 break;
1208 case SID_ATTR_PAGE_HEADER_SPACING:
1210 if ( pReqArgs && rDesc.GetMaster().GetHeader().IsActive())
1212 const SvxLongULSpaceItem& aLongUL = pReqArgs->Get(SID_ATTR_PAGE_HEADER_SPACING);
1213 SwPageDesc aDesc(rDesc);
1214 SvxULSpaceItem aUL(0, aLongUL.GetLower(), RES_UL_SPACE );
1215 SwFrameFormat* pFormat = const_cast<SwFrameFormat*>(aDesc.GetMaster().GetHeader().GetHeaderFormat());
1216 pFormat->SetFormatAttr( aUL );
1217 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1220 break;
1221 case SID_ATTR_PAGE_HEADER_LAYOUT:
1223 if ( pReqArgs && rDesc.GetMaster().GetHeader().IsActive())
1225 const SfxInt16Item& aLayoutItem = pReqArgs->Get(SID_ATTR_PAGE_HEADER_LAYOUT);
1226 sal_uInt16 nLayout = aLayoutItem.GetValue();
1227 SwPageDesc aDesc(rDesc);
1228 aDesc.ChgHeaderShare((nLayout>>1) == 0);
1229 aDesc.ChgFirstShare((nLayout % 2) == 0); // FIXME control changes for both header footer - tdf#100287
1230 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1233 break;
1234 case SID_ATTR_PAGE_FOOTER:
1236 if ( pReqArgs )
1238 const bool bFooterOn = static_cast<const SfxBoolItem&>(pReqArgs->Get(SID_ATTR_PAGE_FOOTER)).GetValue();
1239 SwPageDesc aDesc(rDesc);
1240 SwFrameFormat &rMaster = aDesc.GetMaster();
1241 rMaster.SetFormatAttr( SwFormatFooter( bFooterOn ));
1242 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1245 break;
1246 case SID_ATTR_PAGE_FOOTER_LRMARGIN:
1248 if ( pReqArgs && rDesc.GetMaster().GetFooter().IsActive() )
1250 const SvxLongLRSpaceItem& aLongLR = pReqArgs->Get(SID_ATTR_PAGE_FOOTER_LRMARGIN);
1251 SvxLRSpaceItem aLR(RES_LR_SPACE);
1252 SwPageDesc aDesc(rDesc);
1253 aLR.SetLeft(aLongLR.GetLeft());
1254 aLR.SetRight(aLongLR.GetRight());
1255 SwFrameFormat* pFormat = const_cast<SwFrameFormat*>(aDesc.GetMaster().GetFooter().GetFooterFormat());
1256 pFormat->SetFormatAttr( aLR );
1257 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1260 break;
1261 case SID_ATTR_PAGE_FOOTER_SPACING:
1263 if ( pReqArgs && rDesc.GetMaster().GetFooter().IsActive())
1265 const SvxLongULSpaceItem& aLongUL = pReqArgs->Get(SID_ATTR_PAGE_FOOTER_SPACING);
1266 SwPageDesc aDesc(rDesc);
1267 SvxULSpaceItem aUL(aLongUL.GetUpper(), 0, RES_UL_SPACE );
1268 SwFrameFormat* pFormat = const_cast<SwFrameFormat*>(aDesc.GetMaster().GetFooter().GetFooterFormat());
1269 pFormat->SetFormatAttr( aUL );
1270 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1273 break;
1274 case SID_ATTR_PAGE_FOOTER_LAYOUT:
1276 if ( pReqArgs && rDesc.GetMaster().GetFooter().IsActive())
1278 const SfxInt16Item& aLayoutItem = pReqArgs->Get(SID_ATTR_PAGE_FOOTER_LAYOUT);
1279 sal_uInt16 nLayout = aLayoutItem.GetValue();
1280 SwPageDesc aDesc(rDesc);
1281 aDesc.ChgFooterShare((nLayout>>1) == 0);
1282 aDesc.ChgFirstShare((nLayout % 2) == 0); // FIXME control changes for both header footer - tdf#100287
1283 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1286 break;
1288 case SID_ATTR_PAGE_COLOR:
1289 case SID_ATTR_PAGE_FILLSTYLE:
1290 case SID_ATTR_PAGE_GRADIENT:
1291 case SID_ATTR_PAGE_HATCH:
1292 case SID_ATTR_PAGE_BITMAP:
1294 if(pReqArgs)
1296 SwPageDesc aDesc(rDesc);
1297 SwFrameFormat &rMaster = aDesc.GetMaster();
1298 switch (nSlot)
1300 case SID_ATTR_PAGE_FILLSTYLE:
1302 XFillStyleItem aFSItem( pReqArgs->Get( XATTR_FILLSTYLE ) );
1303 drawing::FillStyle eXFS = aFSItem.GetValue();
1305 if ( eXFS == drawing::FillStyle_NONE )
1306 rMaster.SetFormatAttr( XFillStyleItem( eXFS ) );
1308 break;
1310 case SID_ATTR_PAGE_COLOR:
1312 XFillColorItem aColorItem( pReqArgs->Get( XATTR_FILLCOLOR ) );
1313 rMaster.SetFormatAttr( XFillStyleItem( drawing::FillStyle_SOLID ) );
1314 rMaster.SetFormatAttr( aColorItem );
1316 break;
1318 case SID_ATTR_PAGE_GRADIENT:
1320 XFillGradientItem aGradientItem( pReqArgs->Get( XATTR_FILLGRADIENT ) );
1321 rMaster.SetFormatAttr( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
1322 rMaster.SetFormatAttr( aGradientItem );
1324 break;
1326 case SID_ATTR_PAGE_HATCH:
1328 XFillHatchItem aHatchItem( pReqArgs->Get( XATTR_FILLHATCH ) );
1329 rMaster.SetFormatAttr( XFillStyleItem( drawing::FillStyle_HATCH ) );
1330 rMaster.SetFormatAttr( aHatchItem );
1332 break;
1334 case SID_ATTR_PAGE_BITMAP:
1336 XFillBitmapItem aBitmapItem( pReqArgs->Get( XATTR_FILLBITMAP ) );
1337 rMaster.SetFormatAttr( XFillStyleItem( drawing::FillStyle_BITMAP ) );
1338 rMaster.SetFormatAttr( aBitmapItem );
1340 break;
1342 default:
1343 break;
1345 rSh.ChgPageDesc(rSh.GetCurPageDesc(), aDesc);
1348 break;
1350 default:
1351 OSL_ENSURE( false, "wrong SlotId");
1353 rSh.EndAllAction();
1355 if( bUnlockView )
1356 rSh.LockView( false );
1358 m_bSetTabColFromDoc = m_bSetTabRowFromDoc = m_bTabColFromDoc = m_bTabRowFromDoc = false;
1359 SetNumRuleNodeFromDoc(nullptr);
1362 // Here the status of the tab bar will be determined.
1363 // This means that all relevant attributes at the CursorPos
1364 // will be submitted to the tab bar.
1365 void SwView::StateTabWin(SfxItemSet& rSet)
1367 SwWrtShell &rSh = GetWrtShell();
1369 const Point* pPt = IsTabColFromDoc() || IsTabRowFromDoc() ? &m_aTabColFromDocPos : nullptr;
1370 const FrameTypeFlags nFrameType = rSh.IsObjSelected()
1371 ? FrameTypeFlags::DRAWOBJ
1372 : rSh.GetFrameType( pPt, true );
1374 const bool bFrameSelection = rSh.IsFrameSelected();
1375 const bool bBrowse = rSh.GetViewOptions()->getBrowseMode();
1376 // PageOffset/limiter
1377 const SwRect& rPageRect = rSh.GetAnyCurRect( CurRectType::Page, pPt );
1378 const SwRect& rPagePrtRect = rSh.GetAnyCurRect( CurRectType::PagePrt, pPt );
1379 const tools::Long nPageWidth = rPageRect.Width();
1380 const tools::Long nPageHeight = rPageRect.Height();
1382 const SwPageDesc& rDesc = rSh.GetPageDesc(
1383 IsTabColFromDoc() || m_bTabRowFromDoc ?
1384 rSh.GetMousePageDesc(m_aTabColFromDocPos) : rSh.GetCurPageDesc() );
1386 const SvxFrameDirectionItem& rFrameDir = rDesc.GetMaster().GetFrameDir();
1387 const bool bVerticalWriting = rSh.IsInVerticalText();
1389 //enable tab stop display on the rulers depending on the writing direction
1390 WinBits nRulerStyle = m_pHRuler->GetStyle() & ~WB_EXTRAFIELD;
1391 m_pHRuler->SetStyle(bVerticalWriting||bBrowse ? nRulerStyle : nRulerStyle|WB_EXTRAFIELD);
1392 nRulerStyle = m_pVRuler->GetStyle() & ~WB_EXTRAFIELD;
1393 m_pVRuler->SetStyle(bVerticalWriting ? nRulerStyle|WB_EXTRAFIELD : nRulerStyle);
1395 //#i24363# tab stops relative to indent
1396 bool bRelative = rSh.getIDocumentSettingAccess().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT);
1397 m_pHRuler->SetTabsRelativeToIndent( bRelative );
1398 m_pVRuler->SetTabsRelativeToIndent( bRelative );
1400 SvxLRSpaceItem aPageLRSpace( rDesc.GetMaster().GetLRSpace() );
1401 SwapPageMargin( rDesc, aPageLRSpace );
1403 SfxItemSetFixed<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP,
1404 RES_MARGIN_FIRSTLINE, RES_MARGIN_RIGHT,
1405 RES_UL_SPACE, RES_UL_SPACE> aCoreSet( GetPool() );
1406 // get also the list level indent values, if needed.
1407 rSh.GetCurAttr( aCoreSet, true );
1408 const SelectionType nSelType = rSh.GetSelectionType();
1410 SfxWhichIter aIter( rSet );
1411 sal_uInt16 nWhich = aIter.FirstWhich();
1413 while ( nWhich )
1415 switch ( nWhich )
1418 case SID_ATTR_PAGE_COLUMN:
1420 sal_uInt16 nColumnType = 0;
1422 const SwFrameFormat& rMaster = rDesc.GetMaster();
1423 const SwFormatCol& aCol(rMaster.GetCol());
1424 const sal_uInt16 nCols = aCol.GetNumCols();
1425 if ( nCols == 0 )
1427 nColumnType = 1;
1429 else if ( nCols == 2 )
1431 const sal_uInt16 nColLeft = aCol.CalcPrtColWidth(0, aCol.GetWishWidth());
1432 const sal_uInt16 nColRight = aCol.CalcPrtColWidth(1, aCol.GetWishWidth());
1434 if ( abs(nColLeft - nColRight) <= 10 )
1436 nColumnType = 2;
1438 else if( abs(nColLeft - nColRight*2) < 20 )
1440 nColumnType = 4;
1442 else if( abs(nColLeft*2 - nColRight) < 20 )
1444 nColumnType = 5;
1447 else if( nCols == 3 )
1449 nColumnType = 3;
1451 else
1452 nColumnType = nCols;
1454 rSet.Put( SfxInt16Item( SID_ATTR_PAGE_COLUMN, nColumnType ) );
1456 break;
1458 case SID_ATTR_LONG_LRSPACE:
1460 SvxLongLRSpaceItem aLongLR( aPageLRSpace.GetLeft(),
1461 aPageLRSpace.GetRight(),
1462 SID_ATTR_LONG_LRSPACE);
1463 if(bBrowse)
1465 aLongLR.SetLeft(rPagePrtRect.Left());
1466 aLongLR.SetRight(nPageWidth - rPagePrtRect.Right());
1468 if ( ( nFrameType & FrameTypeFlags::HEADER || nFrameType & FrameTypeFlags::FOOTER ) &&
1469 !(nFrameType & FrameTypeFlags::COLSECT) )
1471 SwFrameFormat *pFormat = const_cast<SwFrameFormat*>((nFrameType & FrameTypeFlags::HEADER) ?
1472 rDesc.GetMaster().GetHeader().GetHeaderFormat() :
1473 rDesc.GetMaster().GetFooter().GetFooterFormat());
1474 if( pFormat )// #i80890# if rDesc is not the one belonging to the current page is might crash
1476 SwRect aRect( rSh.GetAnyCurRect( CurRectType::HeaderFooter, pPt));
1477 aRect.Pos() -= rSh.GetAnyCurRect( CurRectType::Page, pPt ).Pos();
1478 const SvxLRSpaceItem& aLR = pFormat->GetLRSpace();
1479 aLongLR.SetLeft ( aLR.GetLeft() + aRect.Left() );
1480 aLongLR.SetRight( nPageWidth - aRect.Right() + aLR.GetRight() );
1483 else
1485 SwRect aRect;
1486 if( !bFrameSelection && ((nFrameType & FrameTypeFlags::COLSECT) || rSh.IsDirectlyInSection()) )
1488 aRect = rSh.GetAnyCurRect(CurRectType::SectionPrt, pPt);
1489 const SwRect aTmpRect = rSh.GetAnyCurRect(CurRectType::Section, pPt);
1490 aRect.Pos() += aTmpRect.Pos();
1493 else if ( bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY )
1494 aRect = rSh.GetAnyCurRect(CurRectType::FlyEmbedded, pPt);
1495 else if( nFrameType & FrameTypeFlags::DRAWOBJ)
1496 aRect = rSh.GetObjRect();
1498 if( aRect.Width() )
1500 // make relative to page position:
1501 aLongLR.SetLeft(aRect.Left() - rPageRect.Left());
1502 aLongLR.SetRight(rPageRect.Right() - aRect.Right());
1505 rSet.Put( aLongLR );
1507 break;
1509 // provide left and right margins of current page style
1510 case SID_ATTR_PAGE_LRSPACE:
1512 const SvxLRSpaceItem aTmpPageLRSpace( rDesc.GetMaster().GetLRSpace() );
1513 const SvxLongLRSpaceItem aLongLR(
1514 aTmpPageLRSpace.GetLeft(),
1515 aTmpPageLRSpace.GetRight(),
1516 SID_ATTR_PAGE_LRSPACE );
1517 rSet.Put( aLongLR );
1519 break;
1521 case SID_ATTR_LONG_ULSPACE:
1523 // Page margin top bottom
1524 SvxULSpaceItem aUL( rDesc.GetMaster().GetULSpace() );
1525 SvxLongULSpaceItem aLongUL( static_cast<tools::Long>(aUL.GetUpper()),
1526 static_cast<tools::Long>(aUL.GetLower()),
1527 SID_ATTR_LONG_ULSPACE);
1529 if ( bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY )
1531 // Convert document coordinates into page coordinates.
1532 const SwRect &rRect = rSh.GetAnyCurRect(CurRectType::FlyEmbedded, pPt);
1533 aLongUL.SetUpper(rRect.Top() - rPageRect.Top());
1534 aLongUL.SetLower(rPageRect.Bottom() - rRect.Bottom());
1536 else if ( nFrameType & FrameTypeFlags::HEADER || nFrameType & FrameTypeFlags::FOOTER )
1538 SwRect aRect( rSh.GetAnyCurRect( CurRectType::HeaderFooter, pPt));
1539 aRect.Pos() -= rSh.GetAnyCurRect( CurRectType::Page, pPt ).Pos();
1540 aLongUL.SetUpper( aRect.Top() );
1541 aLongUL.SetLower( nPageHeight - aRect.Bottom() );
1543 else if( nFrameType & FrameTypeFlags::DRAWOBJ)
1545 const SwRect &rRect = rSh.GetObjRect();
1546 aLongUL.SetUpper(rRect.Top() - rPageRect.Top());
1547 aLongUL.SetLower(rPageRect.Bottom() - rRect.Bottom());
1549 else if(bBrowse)
1551 aLongUL.SetUpper(rPagePrtRect.Top());
1552 aLongUL.SetLower(nPageHeight - rPagePrtRect.Bottom());
1554 rSet.Put( aLongUL );
1556 break;
1558 // provide top and bottom margins of current page style
1559 case SID_ATTR_PAGE_ULSPACE:
1561 const SvxULSpaceItem aUL( rDesc.GetMaster().GetULSpace() );
1562 SvxLongULSpaceItem aLongUL(
1563 static_cast<tools::Long>(aUL.GetUpper()),
1564 static_cast<tools::Long>(aUL.GetLower()),
1565 SID_ATTR_PAGE_ULSPACE );
1567 rSet.Put( aLongUL );
1569 break;
1571 case SID_ATTR_TABSTOP_VERTICAL :
1572 case RES_PARATR_TABSTOP:
1574 if ( dynamic_cast< const SwWebView *>( this ) != nullptr ||
1575 IsTabColFromDoc() ||
1576 IsTabRowFromDoc() ||
1577 ( nSelType & SelectionType::Graphic ) ||
1578 ( nSelType & SelectionType::Frame ) ||
1579 ( nSelType & SelectionType::Ole ) ||
1580 (aCoreSet.GetItemState(RES_MARGIN_FIRSTLINE) < SfxItemState::DEFAULT) ||
1581 (aCoreSet.GetItemState(RES_MARGIN_TEXTLEFT) < SfxItemState::DEFAULT) ||
1582 (!bVerticalWriting && (SID_ATTR_TABSTOP_VERTICAL == nWhich) ) ||
1583 ( bVerticalWriting && (RES_PARATR_TABSTOP == nWhich))
1585 rSet.DisableItem( nWhich );
1586 else
1588 SvxTabStopItem aTabStops(aCoreSet.Get( RES_PARATR_TABSTOP ));
1590 const SvxTabStopItem& rDefTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
1592 OSL_ENSURE(m_pHRuler, "why is there no ruler?");
1593 const tools::Long nDefTabDist = ::GetTabDist(rDefTabs);
1594 m_pHRuler->SetDefTabDist( nDefTabDist );
1595 m_pVRuler->SetDefTabDist( nDefTabDist );
1596 ::lcl_EraseDefTabs(aTabStops);
1597 aTabStops.SetWhich(nWhich);
1598 rSet.Put(aTabStops);
1600 if (comphelper::LibreOfficeKit::isActive() && nWhich == RES_PARATR_TABSTOP)
1602 boost::property_tree::ptree aRootTree;
1603 boost::property_tree::ptree aEntries;
1605 for (sal_uInt16 i = 0; i < aTabStops.Count(); ++i)
1607 SvxTabStop const & rTabStop = aTabStops[i];
1608 boost::property_tree::ptree aEntry;
1609 aEntry.put("position", convertTwipToMm100(rTabStop.GetTabPos()));
1610 aEntry.put("type", sal_uInt16(rTabStop.GetAdjustment()));
1611 aEntry.put("decimal", OUString(rTabStop.GetDecimal()));
1612 aEntry.put("fill", OUString(rTabStop.GetFill()));
1613 aEntries.push_back(std::make_pair("", aEntry));
1615 aRootTree.push_back(std::make_pair("tabstops", aEntries));
1617 std::stringstream aStream;
1618 boost::property_tree::write_json(aStream, aRootTree);
1619 rSh.GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TAB_STOP_LIST, OString(aStream.str()));
1622 break;
1625 case SID_HANGING_INDENT:
1627 SfxItemState e = aCoreSet.GetItemState(RES_MARGIN_FIRSTLINE);
1628 if( e == SfxItemState::DISABLED )
1629 rSet.DisableItem(nWhich);
1630 break;
1633 case SID_ATTR_PARA_LRSPACE_VERTICAL:
1634 case SID_ATTR_PARA_LRSPACE:
1635 case SID_ATTR_PARA_LEFTSPACE:
1636 case SID_ATTR_PARA_RIGHTSPACE:
1637 case SID_ATTR_PARA_FIRSTLINESPACE:
1639 if ( nSelType & SelectionType::Graphic ||
1640 nSelType & SelectionType::Frame ||
1641 nSelType & SelectionType::Ole ||
1642 nFrameType == FrameTypeFlags::DRAWOBJ ||
1643 (!bVerticalWriting && (SID_ATTR_PARA_LRSPACE_VERTICAL == nWhich)) ||
1644 ( bVerticalWriting && (SID_ATTR_PARA_LRSPACE == nWhich))
1647 rSet.DisableItem(nWhich);
1649 else
1651 std::shared_ptr<SvxLRSpaceItem> aLR(std::make_shared<SvxLRSpaceItem>(RES_LR_SPACE));
1652 if ( !IsTabColFromDoc() )
1654 SvxFirstLineIndentItem const& rFirstLine(aCoreSet.Get(RES_MARGIN_FIRSTLINE));
1655 SvxTextLeftMarginItem const& rLeftMargin(aCoreSet.Get(RES_MARGIN_TEXTLEFT));
1656 SvxRightMarginItem const& rRightMargin(aCoreSet.Get(RES_MARGIN_RIGHT));
1657 aLR->SetTextFirstLineOffset(rFirstLine.GetTextFirstLineOffset(), rFirstLine.GetPropTextFirstLineOffset());
1658 aLR->SetAutoFirst(rFirstLine.IsAutoFirst());
1659 aLR->SetTextLeft(rLeftMargin.GetTextLeft(), rLeftMargin.GetPropLeft());
1660 aLR->SetRight(rRightMargin.GetRight(), rRightMargin.GetPropRight());
1662 // #i23726#
1663 if (m_pNumRuleNodeFromDoc)
1665 short nOffset = static_cast< short >(aLR->GetTextLeft() +
1666 // #i42922# Mouse move of numbering label
1667 // has to consider the left indent of the paragraph
1668 m_pNumRuleNodeFromDoc->GetLeftMarginWithNum( true ) );
1670 short nFLOffset;
1671 m_pNumRuleNodeFromDoc->GetFirstLineOfsWithNum( nFLOffset );
1673 aLR->SetLeft( nOffset + nFLOffset );
1676 aLR->SetWhich(nWhich);
1677 rSet.Put(*aLR);
1679 break;
1682 case SID_ATTR_PARA_ULSPACE:
1683 case SID_ATTR_PARA_ABOVESPACE:
1684 case SID_ATTR_PARA_BELOWSPACE:
1685 case SID_PARASPACE_INCREASE:
1686 case SID_PARASPACE_DECREASE:
1688 SvxULSpaceItem aUL = aCoreSet.Get(RES_UL_SPACE);
1689 SfxItemState e = aCoreSet.GetItemState(RES_UL_SPACE);
1690 if( e >= SfxItemState::DEFAULT )
1692 if ( !aUL.GetUpper() && !aUL.GetLower() )
1693 rSet.DisableItem( SID_PARASPACE_DECREASE );
1694 else if ( aUL.GetUpper() >= 5670 && aUL.GetLower() >= 5670 )
1695 rSet.DisableItem( SID_PARASPACE_INCREASE );
1696 if ( nWhich == SID_ATTR_PARA_ULSPACE
1697 || nWhich == SID_ATTR_PARA_ABOVESPACE
1698 || nWhich == SID_ATTR_PARA_BELOWSPACE
1701 aUL.SetWhich( nWhich );
1702 rSet.Put( aUL );
1705 else
1707 rSet.DisableItem( SID_PARASPACE_INCREASE );
1708 rSet.DisableItem( SID_PARASPACE_DECREASE );
1709 rSet.InvalidateItem( SID_ATTR_PARA_ULSPACE );
1710 rSet.InvalidateItem( SID_ATTR_PARA_ABOVESPACE );
1711 rSet.InvalidateItem( SID_ATTR_PARA_BELOWSPACE );
1714 break;
1716 case SID_RULER_BORDER_DISTANCE:
1718 m_nLeftBorderDistance = 0;
1719 m_nRightBorderDistance = 0;
1720 SfxItemSetFixed<RES_BOX, RES_BOX,
1721 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER> aCoreSet2(GetPool());
1722 if ( nSelType & SelectionType::Graphic ||
1723 nSelType & SelectionType::Frame ||
1724 nSelType & SelectionType::Ole ||
1725 nFrameType == FrameTypeFlags::DRAWOBJ )
1726 rSet.DisableItem(SID_RULER_BORDER_DISTANCE);
1727 else
1729 SvxLRSpaceItem aDistLR(SID_RULER_BORDER_DISTANCE);
1730 if(nFrameType & FrameTypeFlags::FLY_ANY)
1732 if( IsTabColFromDoc() )
1734 const SwRect& rFlyPrtRect = rSh.GetAnyCurRect( CurRectType::FlyEmbeddedPrt, pPt );
1735 aDistLR.SetLeft(rFlyPrtRect.Left());
1736 aDistLR.SetRight(rFlyPrtRect.Left());
1737 rSet.Put(aDistLR);
1739 else
1741 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
1742 aCoreSet2.Put(aBoxInfo);
1743 rSh.GetFlyFrameAttr(aCoreSet2);
1744 const SvxBoxItem& rBox = aCoreSet2.Get(RES_BOX);
1745 aDistLR.SetLeft(rBox.GetDistance(SvxBoxItemLine::LEFT));
1746 aDistLR.SetRight(rBox.GetDistance(SvxBoxItemLine::RIGHT));
1747 rSet.Put(aDistLR);
1749 //add the paragraph border distance
1750 SfxItemSetFixed<RES_BOX, RES_BOX> aCoreSet1( GetPool() );
1751 rSh.GetCurAttr( aCoreSet1 );
1752 const SvxBoxItem& rParaBox = aCoreSet1.Get(RES_BOX);
1753 aDistLR.SetLeft(aDistLR.GetLeft() + rParaBox.GetDistance(SvxBoxItemLine::LEFT));
1754 aDistLR.SetRight(aDistLR.GetRight() + rParaBox.GetDistance(SvxBoxItemLine::RIGHT));
1756 m_nLeftBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetLeft());
1757 m_nRightBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetRight());
1759 else if ( IsTabColFromDoc() ||
1760 ( rSh.GetTableFormat() && !bFrameSelection &&
1761 !(nFrameType & FrameTypeFlags::COLSECT ) ) )
1763 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
1764 aBoxInfo.SetTable(false);
1765 aBoxInfo.SetDist(true);
1766 aCoreSet2.Put(aBoxInfo);
1767 rSh.GetTabBorders( aCoreSet2 );
1768 const SvxBoxItem& rBox = aCoreSet2.Get(RES_BOX);
1769 aDistLR.SetLeft(rBox.GetDistance(SvxBoxItemLine::LEFT));
1770 aDistLR.SetRight(rBox.GetDistance(SvxBoxItemLine::RIGHT));
1771 rSet.Put(aDistLR);
1773 //add the border distance of the paragraph
1774 SfxItemSetFixed<RES_BOX, RES_BOX> aCoreSet1( GetPool() );
1775 rSh.GetCurAttr( aCoreSet1 );
1776 const SvxBoxItem& rParaBox = aCoreSet1.Get(RES_BOX);
1777 aDistLR.SetLeft(aDistLR.GetLeft() + rParaBox.GetDistance(SvxBoxItemLine::LEFT));
1778 aDistLR.SetRight(aDistLR.GetRight() + rParaBox.GetDistance(SvxBoxItemLine::RIGHT));
1779 m_nLeftBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetLeft());
1780 m_nRightBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetRight());
1782 else if ( !rSh.IsDirectlyInSection() )
1784 //get the page/header/footer border distance
1785 const SwFrameFormat& rMaster = rDesc.GetMaster();
1786 const SvxBoxItem& rBox = rMaster.GetAttrSet().Get(RES_BOX);
1787 aDistLR.SetLeft(rBox.GetDistance(SvxBoxItemLine::LEFT));
1788 aDistLR.SetRight(rBox.GetDistance(SvxBoxItemLine::RIGHT));
1790 const SvxBoxItem* pBox = nullptr;
1791 if(nFrameType & FrameTypeFlags::HEADER)
1793 rMaster.GetHeader();
1794 const SwFormatHeader& rHeaderFormat = rMaster.GetHeader();
1795 SwFrameFormat *pHeaderFormat = const_cast<SwFrameFormat*>(rHeaderFormat.GetHeaderFormat());
1796 if( pHeaderFormat )// #i80890# if rDesc is not the one belonging to the current page is might crash
1797 pBox = & pHeaderFormat->GetBox();
1799 else if(nFrameType & FrameTypeFlags::FOOTER )
1801 const SwFormatFooter& rFooterFormat = rMaster.GetFooter();
1802 SwFrameFormat *pFooterFormat = const_cast<SwFrameFormat*>(rFooterFormat.GetFooterFormat());
1803 if( pFooterFormat )// #i80890# if rDesc is not the one belonging to the current page is might crash
1804 pBox = & pFooterFormat->GetBox();
1806 if(pBox)
1808 aDistLR.SetLeft(pBox->GetDistance(SvxBoxItemLine::LEFT));
1809 aDistLR.SetRight(pBox->GetDistance(SvxBoxItemLine::RIGHT));
1811 rSet.Put(aDistLR);
1813 //add the border distance of the paragraph
1814 rSh.GetCurAttr(aCoreSet2);
1815 const SvxBoxItem& rParaBox = aCoreSet2.Get(RES_BOX);
1816 aDistLR.SetLeft(aDistLR.GetLeft() + rParaBox.GetDistance(SvxBoxItemLine::LEFT));
1817 aDistLR.SetRight(aDistLR.GetRight() + rParaBox.GetDistance(SvxBoxItemLine::RIGHT));
1818 m_nLeftBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetLeft());
1819 m_nRightBorderDistance = static_cast< sal_uInt16 >(aDistLR.GetRight());
1823 break;
1825 case SID_RULER_TEXT_RIGHT_TO_LEFT:
1827 if ( nSelType & SelectionType::Graphic ||
1828 nSelType & SelectionType::Frame ||
1829 nSelType & SelectionType::Ole ||
1830 nFrameType == FrameTypeFlags::DRAWOBJ)
1831 rSet.DisableItem(nWhich);
1832 else
1834 bool bFlag = rSh.IsInRightToLeftText();
1835 rSet.Put(SfxBoolItem(nWhich, bFlag));
1838 break;
1840 case SID_RULER_BORDERS_VERTICAL:
1841 case SID_RULER_BORDERS:
1843 bool bFrameHasVerticalColumns(false);
1845 bool bFrameRTL;
1846 bool bFrameVertL2R;
1847 bFrameHasVerticalColumns = rSh.IsFrameVertical(false, bFrameRTL, bFrameVertL2R) &&
1848 bFrameSelection;
1850 bool bHasTable = ( IsTabColFromDoc() ||
1851 ( rSh.GetTableFormat() && !bFrameSelection &&
1852 !(nFrameType & FrameTypeFlags::COLSECT ) ) );
1854 bool bTableVertical = bHasTable && rSh.IsTableVertical();
1856 if(((SID_RULER_BORDERS_VERTICAL == nWhich) &&
1857 ((bHasTable && !bTableVertical) ||
1858 (!bVerticalWriting && !bFrameSelection && !bHasTable ) ||
1859 ( bFrameSelection && !bFrameHasVerticalColumns))) ||
1860 ((SID_RULER_BORDERS == nWhich) &&
1861 ((bHasTable && bTableVertical) ||
1862 (bVerticalWriting && !bFrameSelection&& !bHasTable) || bFrameHasVerticalColumns)))
1863 rSet.DisableItem(nWhich);
1864 else if ( bHasTable )
1866 SwTabCols aTabCols;
1867 size_t nNum = 0;
1868 m_bSetTabColFromDoc = IsTabColFromDoc();
1869 if ( m_bSetTabColFromDoc )
1871 rSh.GetMouseTabCols( aTabCols, m_aTabColFromDocPos );
1872 nNum = rSh.GetCurMouseTabColNum( m_aTabColFromDocPos );
1874 else
1876 rSh.GetTabCols( aTabCols );
1877 nNum = rSh.GetCurTabColNum();
1878 if(rSh.IsTableRightToLeft())
1879 nNum = aTabCols.Count() - nNum;
1882 OSL_ENSURE(nNum <= aTabCols.Count(), "TabCol not found");
1883 const int nLft = aTabCols.GetLeftMin() + aTabCols.GetLeft();
1884 const int nRgt = (bTableVertical ? nPageHeight : nPageWidth) -
1885 (aTabCols.GetLeftMin() + aTabCols.GetRight());
1887 const sal_uInt16 nL = static_cast< sal_uInt16 >(std::max(nLft, 0));
1888 const sal_uInt16 nR = static_cast< sal_uInt16 >(std::max(nRgt, 0));
1890 SvxColumnItem aColItem(nNum, nL, nR);
1892 tools::Long nStart = 0;
1893 tools::Long nEnd = 0;
1895 //columns in right-to-left tables need to be mirrored
1896 bool bIsTableRTL =
1897 IsTabColFromDoc() ?
1898 rSh.IsMouseTableRightToLeft(m_aTabColFromDocPos)
1899 : rSh.IsTableRightToLeft();
1900 if(bIsTableRTL)
1902 for ( size_t i = aTabCols.Count(); i; --i )
1904 const SwTabColsEntry& rEntry = aTabCols.GetEntry( i - 1 );
1905 nEnd = aTabCols.GetRight() - rEntry.nPos;
1906 SvxColumnDescription aColDesc( nStart, nEnd,
1907 aTabCols.GetRight() - rEntry.nMax,
1908 aTabCols.GetRight() - rEntry.nMin,
1909 !aTabCols.IsHidden(i - 1) );
1910 aColItem.Append(aColDesc);
1911 nStart = nEnd;
1913 SvxColumnDescription aColDesc(nStart,
1914 aTabCols.GetRight() - aTabCols.GetLeft(), true);
1915 aColItem.Append(aColDesc);
1917 else
1919 for ( size_t i = 0; i < aTabCols.Count(); ++i )
1921 const SwTabColsEntry& rEntry = aTabCols.GetEntry( i );
1922 nEnd = rEntry.nPos - aTabCols.GetLeft();
1923 SvxColumnDescription aColDesc( nStart, nEnd,
1924 rEntry.nMin - aTabCols.GetLeft(), rEntry.nMax - aTabCols.GetLeft(),
1925 !aTabCols.IsHidden(i) );
1926 aColItem.Append(aColDesc);
1927 nStart = nEnd;
1929 SvxColumnDescription aColDesc(nStart, aTabCols.GetRight() - aTabCols.GetLeft(),
1930 0, 0, true);
1931 aColItem.Append(aColDesc);
1933 aColItem.SetWhich(nWhich);
1934 rSet.Put(aColItem);
1936 else if ( bFrameSelection || nFrameType & ( FrameTypeFlags::COLUMN | FrameTypeFlags::COLSECT ) )
1938 // Out of frame or page?
1939 sal_uInt16 nNum = 0;
1940 if(bFrameSelection)
1942 const SwFrameFormat* pFormat = rSh.GetFlyFrameFormat();
1943 if(pFormat)
1944 nNum = pFormat->GetCol().GetNumCols();
1946 else
1947 nNum = rSh.GetCurColNum();
1950 // For that matter FrameTypeFlags::COLSECT should not be included
1951 // if the border is selected!
1952 !bFrameSelection &&
1953 nFrameType & FrameTypeFlags::COLSECT )
1955 const SwSection *pSect = rSh.GetAnySection(false, pPt);
1956 OSL_ENSURE( pSect, "Which section?");
1957 if( pSect )
1959 SwSectionFormat const *pFormat = pSect->GetFormat();
1960 const SwFormatCol& rCol = pFormat->GetCol();
1961 if (rSh.IsColRightToLeft())
1962 nNum = rCol.GetColumns().size() - nNum;
1963 else
1964 --nNum;
1965 SvxColumnItem aColItem(nNum);
1966 SwRect aRect = rSh.GetAnyCurRect(CurRectType::SectionPrt, pPt);
1967 const SwRect aTmpRect = rSh.GetAnyCurRect(CurRectType::Section, pPt);
1969 ::lcl_FillSvxColumn(rCol, bVerticalWriting ? aRect.Height() : aRect.Width(), aColItem, 0);
1971 if(bVerticalWriting)
1973 aRect.Pos() += Point(aTmpRect.Left(), aTmpRect.Top());
1974 aRect.Pos().AdjustY( -(rPageRect.Top()) );
1975 aColItem.SetLeft(aRect.Top());
1976 aColItem.SetRight(nPageHeight - aRect.Bottom());
1978 else
1980 aRect.Pos() += aTmpRect.Pos();
1982 // make relative to page position:
1983 aColItem.SetLeft (o3tl::narrowing<sal_uInt16>( aRect.Left() - rPageRect.Left() ));
1984 aColItem.SetRight(o3tl::narrowing<sal_uInt16>( rPageRect.Right() - aRect.Right()));
1986 aColItem.SetOrtho(aColItem.CalcOrtho());
1988 aColItem.SetWhich(nWhich);
1989 rSet.Put(aColItem);
1992 else if( bFrameSelection || nFrameType & FrameTypeFlags::FLY_ANY )
1994 // Columns in frame
1995 if ( nNum )
1997 const SwFrameFormat* pFormat = rSh.GetFlyFrameFormat() ;
1999 const SwFormatCol& rCol = pFormat->GetCol();
2000 if (rSh.IsColRightToLeft())
2001 nNum = rCol.GetColumns().size() - nNum;
2002 else
2003 nNum--;
2004 SvxColumnItem aColItem(nNum);
2005 const SwRect &rSizeRect = rSh.GetAnyCurRect(CurRectType::FlyEmbeddedPrt, pPt);
2007 bool bUseVertical = bFrameHasVerticalColumns || (!bFrameSelection && bVerticalWriting);
2008 const tools::Long lWidth = bUseVertical ? rSizeRect.Height() : rSizeRect.Width();
2009 const SwRect &rRect = rSh.GetAnyCurRect(CurRectType::FlyEmbedded, pPt);
2010 tools::Long nDist2 = ((bUseVertical ? rRect.Height() : rRect.Width()) - lWidth) /2;
2011 ::lcl_FillSvxColumn(rCol, lWidth, aColItem, nDist2);
2013 if(bUseVertical)
2015 aColItem.SetLeft(rRect.Top()- rPageRect.Top());
2016 aColItem.SetRight(nPageHeight + rPageRect.Top() - rRect.Bottom());
2018 else
2020 aColItem.SetLeft(rRect.Left() - rPageRect.Left());
2021 aColItem.SetRight(rPageRect.Right() - rRect.Right());
2024 aColItem.SetOrtho(aColItem.CalcOrtho());
2026 aColItem.SetWhich(nWhich);
2027 rSet.Put(aColItem);
2029 else
2030 rSet.DisableItem(nWhich);
2032 else
2033 { // Columns on the page
2034 const SwFrameFormat& rMaster = rDesc.GetMaster();
2035 SwFormatCol aCol(rMaster.GetCol());
2036 if(rFrameDir.GetValue() == SvxFrameDirection::Horizontal_RL_TB)
2037 nNum = aCol.GetColumns().size() - nNum;
2038 else
2039 nNum--;
2041 SvxColumnItem aColItem(nNum);
2042 const SwRect aPrtRect = rSh.GetAnyCurRect(CurRectType::PagePrt, pPt);
2043 const SvxBoxItem& rBox = rMaster.GetFormatAttr(RES_BOX);
2044 tools::Long nDist = rBox.GetSmallestDistance();
2046 lcl_FillSvxColumn(
2047 aCol,
2048 bVerticalWriting ? aPrtRect.Height() : aPrtRect.Width(),
2049 aColItem, nDist);
2051 if(bBrowse)
2053 if (bVerticalWriting)
2055 aColItem.SetLeft(o3tl::narrowing<sal_uInt16>(rPagePrtRect.Top()));
2056 aColItem.SetRight(sal_uInt16(nPageHeight - rPagePrtRect.Bottom()));
2058 else
2060 aColItem.SetLeft(o3tl::narrowing<sal_uInt16>(rPagePrtRect.Left()));
2061 aColItem.SetRight(sal_uInt16(nPageWidth - rPagePrtRect.Right()));
2064 else
2066 if (bVerticalWriting)
2068 SvxULSpaceItem aUL( rDesc.GetMaster().GetULSpace() );
2069 aColItem.SetLeft (aUL.GetUpper());
2070 aColItem.SetRight(aUL.GetLower());
2072 else
2074 aColItem.SetLeft (aPageLRSpace.GetLeft());
2075 aColItem.SetRight(aPageLRSpace.GetRight());
2078 aColItem.SetOrtho(aColItem.CalcOrtho());
2080 aColItem.SetWhich(nWhich);
2081 rSet.Put(aColItem);
2084 else
2085 rSet.DisableItem(nWhich);
2086 break;
2089 case SID_RULER_ROWS :
2090 case SID_RULER_ROWS_VERTICAL:
2092 bool bFrameHasVerticalColumns(false);
2094 bool bFrameRTL;
2095 bool bFrameVertL2R;
2096 bFrameHasVerticalColumns = rSh.IsFrameVertical(false, bFrameRTL, bFrameVertL2R) &&
2097 bFrameSelection;
2100 if(((SID_RULER_ROWS == nWhich) &&
2101 ((!bVerticalWriting && !bFrameSelection) || (bFrameSelection && !bFrameHasVerticalColumns))) ||
2102 ((SID_RULER_ROWS_VERTICAL == nWhich) &&
2103 ((bVerticalWriting && !bFrameSelection) || bFrameHasVerticalColumns)))
2104 rSet.DisableItem(nWhich);
2105 else if ( IsTabRowFromDoc() ||
2106 ( rSh.GetTableFormat() && !bFrameSelection &&
2107 !(nFrameType & FrameTypeFlags::COLSECT ) ) )
2109 SwTabCols aTabCols;
2110 m_bSetTabRowFromDoc = IsTabRowFromDoc();
2111 if ( m_bSetTabRowFromDoc )
2113 rSh.GetMouseTabRows( aTabCols, m_aTabColFromDocPos );
2115 else
2117 rSh.GetTabRows( aTabCols );
2120 const int nLft = aTabCols.GetLeftMin();
2121 const int nRgt = (bVerticalWriting ? nPageWidth : nPageHeight) -
2122 (aTabCols.GetLeftMin() + aTabCols.GetRight());
2124 const sal_uInt16 nL = static_cast< sal_uInt16 >(std::max(nLft, 0));
2125 const sal_uInt16 nR = static_cast< sal_uInt16 >(std::max(nRgt, 0));
2127 SvxColumnItem aColItem(0, nL, nR);
2129 tools::Long nStart = 0;
2130 tools::Long nEnd = 0;
2132 for ( size_t i = 0; i < aTabCols.Count(); ++i )
2134 const SwTabColsEntry& rEntry = aTabCols.GetEntry( i );
2135 if(bVerticalWriting)
2137 nEnd = aTabCols.GetRight() - rEntry.nPos;
2138 SvxColumnDescription aColDesc( nStart, nEnd,
2139 std::max(tools::Long(0), aTabCols.GetRight() - rEntry.nMax),
2140 std::max(tools::Long(0), aTabCols.GetRight() - rEntry.nMin),
2141 !aTabCols.IsHidden(i) );
2142 aColItem.Append(aColDesc);
2144 else
2146 nEnd = rEntry.nPos - aTabCols.GetLeft();
2147 SvxColumnDescription aColDesc( nStart, nEnd,
2148 rEntry.nMin - aTabCols.GetLeft(),
2149 rEntry.nMax - aTabCols.GetLeft(),
2150 !aTabCols.IsHidden(i) );
2151 aColItem.Append(aColDesc);
2153 nStart = nEnd;
2155 if(bVerticalWriting)
2156 nEnd = aTabCols.GetRight();
2157 else
2158 nEnd = aTabCols.GetLeft();
2160 SvxColumnDescription aColDesc( nStart, nEnd,
2161 aTabCols.GetRight(),
2162 aTabCols.GetRight(),
2163 false );
2164 aColItem.Append(aColDesc);
2166 aColItem.SetWhich(nWhich);
2167 rSet.Put(aColItem);
2169 else
2170 rSet.DisableItem(nWhich);
2172 break;
2174 case SID_RULER_PAGE_POS:
2176 SvxPagePosSizeItem aPagePosSize(
2177 Point( rPageRect.Left(), rPageRect.Top()) , nPageWidth, nPageHeight);
2179 rSet.Put(aPagePosSize);
2180 break;
2183 case SID_RULER_LR_MIN_MAX:
2185 tools::Rectangle aRectangle;
2186 if( ( nFrameType & FrameTypeFlags::COLSECT ) && !IsTabColFromDoc() &&
2187 ( nFrameType & ( FrameTypeFlags::TABLE|FrameTypeFlags::COLUMN ) ) )
2189 if( nFrameType & FrameTypeFlags::TABLE )
2191 const size_t nNum = rSh.GetCurTabColNum();
2192 SwTabCols aTabCols;
2193 rSh.GetTabCols( aTabCols );
2195 const int nLft = aTabCols.GetLeftMin() + aTabCols.GetLeft();
2196 const int nRgt = nPageWidth -(aTabCols.GetLeftMin() + aTabCols.GetRight());
2198 const sal_uInt16 nL = static_cast< sal_uInt16 >(std::max(nLft, 0));
2199 const sal_uInt16 nR = static_cast< sal_uInt16 >(std::max(nRgt, 0));
2201 aRectangle.SetLeft( nL );
2202 if(nNum > 1)
2203 aRectangle.AdjustLeft(aTabCols[nNum - 2] );
2204 if(nNum)
2205 aRectangle.AdjustLeft(MINLAY );
2206 if(aTabCols.Count() <= nNum + 1 )
2207 aRectangle.SetRight( nR );
2208 else
2209 aRectangle.SetRight( nPageWidth - (nL + aTabCols[nNum + 1]) );
2211 if(nNum < aTabCols.Count())
2212 aRectangle.AdjustRight(MINLAY );
2214 else
2216 const SwFrameFormat* pFormat = rSh.GetFlyFrameFormat();
2217 const SwFormatCol* pCols = pFormat ? &pFormat->GetCol():
2218 &rDesc.GetMaster().GetCol();
2219 const SwColumns& rCols = pCols->GetColumns();
2220 sal_uInt16 nNum = rSh.GetCurOutColNum();
2221 const sal_uInt16 nCount = std::min(sal_uInt16(nNum + 1), sal_uInt16(rCols.size()));
2222 const SwRect aRect( rSh.GetAnyCurRect( pFormat
2223 ? CurRectType::FlyEmbeddedPrt
2224 : CurRectType::PagePrt, pPt ));
2225 const SwRect aAbsRect( rSh.GetAnyCurRect( pFormat
2226 ? CurRectType::FlyEmbedded
2227 : CurRectType::Page, pPt ));
2229 // The width of the frame or within the page margins.
2230 const sal_uInt16 nTotalWidth = o3tl::narrowing<sal_uInt16>(aRect.Width());
2231 // The entire frame width - The difference is twice the distance to the edge.
2232 const sal_uInt16 nOuterWidth = o3tl::narrowing<sal_uInt16>(aAbsRect.Width());
2233 int nWidth = 0,
2234 nEnd = 0;
2235 aRectangle.SetLeft( 0 );
2236 for ( sal_uInt16 i = 0; i < nCount; ++i )
2238 const SwColumn* pCol = &rCols[i];
2239 const int nStart = pCol->GetLeft() + nWidth;
2240 if(i == nNum - 2)
2241 aRectangle.SetLeft( nStart );
2242 nWidth += pCols->CalcColWidth( i, nTotalWidth );
2243 nEnd = nWidth - pCol->GetRight();
2245 aRectangle.SetRight( rPageRect.Right() - nEnd );
2246 aRectangle.AdjustLeft( -(rPageRect.Left()) );
2248 if(nNum > 1)
2250 aRectangle.AdjustLeft(MINLAY );
2251 aRectangle.AdjustLeft(aRect.Left() );
2253 if(pFormat) // Range in frame - here you may up to the edge
2255 aRectangle.SetLeft(0);
2256 aRectangle.SetRight(0);
2258 else
2260 // Move the rectangle to the correct absolute position.
2261 aRectangle.AdjustLeft(aAbsRect.Left() );
2262 aRectangle.AdjustRight( -(aAbsRect.Left()) );
2263 // Include distance to the border.
2264 aRectangle.AdjustRight( -((nOuterWidth - nTotalWidth) / 2) );
2267 if(nNum < rCols.size())
2269 aRectangle.AdjustRight(MINLAY );
2271 else
2272 // Right is only the margin now.
2273 aRectangle.SetRight( 0 );
2277 else if ( ((nFrameType & FrameTypeFlags::TABLE) || IsTabColFromDoc()) &&
2278 !bFrameSelection )
2280 bool bColumn;
2281 if ( IsTabColFromDoc() )
2282 bColumn = rSh.GetCurMouseColNum( m_aTabColFromDocPos ) != 0;
2283 else
2284 bColumn = bool(nFrameType & (FrameTypeFlags::COLUMN|FrameTypeFlags::FLY_ANY|FrameTypeFlags::COLSECTOUTTAB));
2286 if ( !bColumn )
2288 if( nFrameType & FrameTypeFlags::FLY_ANY && IsTabColFromDoc() )
2290 SwRect aRect( rSh.GetAnyCurRect(
2291 CurRectType::FlyEmbeddedPrt, pPt ) );
2292 aRect.Pos() += rSh.GetAnyCurRect( CurRectType::FlyEmbedded,
2293 pPt ).Pos();
2295 aRectangle.SetLeft( aRect.Left() - rPageRect.Left() );
2296 aRectangle.SetRight( rPageRect.Right() - aRect.Right() );
2298 else if( bBrowse )
2300 aRectangle.SetLeft( rPagePrtRect.Left() );
2301 aRectangle.SetRight( nPageWidth - rPagePrtRect.Right() );
2303 else
2305 aRectangle.SetLeft( aPageLRSpace.GetLeft() );
2306 aRectangle.SetRight( aPageLRSpace.GetRight() );
2309 else
2310 { // Here only for table in multi-column pages and borders.
2311 bool bSectOutTable = bool(nFrameType & FrameTypeFlags::TABLE);
2312 bool bFrame = bool(nFrameType & FrameTypeFlags::FLY_ANY);
2313 bool bColSct = bool(nFrameType & ( bSectOutTable
2314 ? FrameTypeFlags::COLSECTOUTTAB
2315 : FrameTypeFlags::COLSECT )
2317 //So you can also drag with the mouse, without being in the table.
2318 CurRectType eRecType = CurRectType::PagePrt;
2319 size_t nNum = IsTabColFromDoc() ?
2320 rSh.GetCurMouseColNum( m_aTabColFromDocPos ):
2321 rSh.GetCurOutColNum();
2322 const SwFrameFormat* pFormat = nullptr;
2323 if( bColSct )
2325 eRecType = bSectOutTable ? CurRectType::SectionOutsideTable
2326 : CurRectType::Section;
2327 const SwSection *pSect = rSh.GetAnySection( bSectOutTable, pPt );
2328 OSL_ENSURE( pSect, "Which section?");
2329 pFormat = pSect->GetFormat();
2331 else if( bFrame )
2333 pFormat = rSh.GetFlyFrameFormat();
2334 eRecType = CurRectType::FlyEmbeddedPrt;
2337 const SwFormatCol* pCols = pFormat ? &pFormat->GetCol():
2338 &rDesc.GetMaster().GetCol();
2339 const SwColumns& rCols = pCols->GetColumns();
2340 const sal_uInt16 nBorder = pFormat
2341 ? pFormat->GetBox().GetSmallestDistance()
2342 : rDesc.GetMaster().GetBox().GetSmallestDistance();
2344 // RECT_FLY_PRT_EMBEDDED returns the relative position to RECT_FLY_EMBEDDED
2345 // the absolute position must be added here
2347 SwRect aRect( rSh.GetAnyCurRect( eRecType, pPt ) );
2348 if(CurRectType::FlyEmbeddedPrt == eRecType)
2349 aRect.Pos() += rSh.GetAnyCurRect( CurRectType::FlyEmbedded,
2350 pPt ).Pos();
2352 const sal_uInt16 nTotalWidth = o3tl::narrowing<sal_uInt16>(aRect.Width());
2353 // Initialize nStart and nEnd for nNum == 0
2354 int nWidth = 0,
2355 nStart = 0,
2356 nEnd = nTotalWidth;
2358 if( nNum > rCols.size() )
2360 OSL_ENSURE( false, "wrong FormatCol is being edited!" );
2361 nNum = rCols.size();
2364 for( size_t i = 0; i < nNum; ++i )
2366 const SwColumn* pCol = &rCols[i];
2367 nStart = pCol->GetLeft() + nWidth;
2368 nWidth += pCols->CalcColWidth( o3tl::narrowing<sal_uInt16>(i), nTotalWidth );
2369 nEnd = nWidth - pCol->GetRight();
2371 if( bFrame || bColSct )
2373 aRectangle.SetLeft( aRect.Left() - rPageRect.Left() + nStart );
2374 aRectangle.SetRight( nPageWidth - aRectangle.Left() - nEnd + nStart );
2376 else if(!bBrowse)
2378 aRectangle.SetLeft( aPageLRSpace.GetLeft() + nStart );
2379 aRectangle.SetRight( nPageWidth - nEnd - aPageLRSpace.GetLeft() );
2381 else
2383 tools::Long nLeft = rPagePrtRect.Left();
2384 aRectangle.SetLeft( nStart + nLeft );
2385 aRectangle.SetRight( nPageWidth - nEnd - nLeft );
2387 if(!bFrame)
2389 aRectangle.AdjustLeft(nBorder );
2390 aRectangle.AdjustRight( -nBorder );
2394 else if ( nFrameType & ( FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER ))
2396 aRectangle.SetLeft( aPageLRSpace.GetLeft() );
2397 aRectangle.SetRight( aPageLRSpace.GetRight() );
2399 else
2401 aRectangle.SetLeft(0);
2402 aRectangle.SetRight(0);
2405 SfxRectangleItem aLR( SID_RULER_LR_MIN_MAX , aRectangle);
2406 rSet.Put(aLR);
2408 break;
2410 case SID_RULER_PROTECT:
2412 if(bFrameSelection)
2414 FlyProtectFlags nProtect = m_pWrtShell->IsSelObjProtected( FlyProtectFlags::Size|FlyProtectFlags::Pos|FlyProtectFlags::Content );
2416 SvxProtectItem aProt(SID_RULER_PROTECT);
2417 aProt.SetContentProtect(bool(nProtect & FlyProtectFlags::Content));
2418 aProt.SetSizeProtect (bool(nProtect & FlyProtectFlags::Size));
2419 aProt.SetPosProtect (bool(nProtect & FlyProtectFlags::Pos));
2420 rSet.Put(aProt);
2422 else
2424 SvxProtectItem aProtect(SID_RULER_PROTECT);
2425 if(bBrowse && !(nFrameType & (FrameTypeFlags::DRAWOBJ|FrameTypeFlags::COLUMN)) && !rSh.GetTableFormat())
2427 aProtect.SetSizeProtect(true);
2428 aProtect.SetPosProtect(true);
2430 rSet.Put(aProtect);
2433 break;
2435 case SID_ATTR_PAGE_HEADER:
2436 case SID_ATTR_PAGE_HEADER_LRMARGIN:
2437 case SID_ATTR_PAGE_HEADER_SPACING:
2438 case SID_ATTR_PAGE_HEADER_LAYOUT:
2440 const SwFormatHeader& rHeader = rDesc.GetMaster().GetHeader();
2441 bool bHeaderOn = rHeader.IsActive();
2442 rSet.Put( SfxBoolItem(SID_ATTR_PAGE_HEADER, bHeaderOn ) );
2443 if(bHeaderOn)
2445 const SvxLRSpaceItem* pLR = rHeader.GetHeaderFormat()->GetAttrSet().GetItem(SID_ATTR_LRSPACE);
2446 const SvxULSpaceItem* pUL = rHeader.GetHeaderFormat()->GetAttrSet().GetItem(SID_ATTR_ULSPACE);
2447 if (pLR && pUL)
2449 SvxLongLRSpaceItem aLR(pLR->GetLeft(), pLR->GetRight(), SID_ATTR_PAGE_HEADER_LRMARGIN);
2450 rSet.Put(aLR);
2451 SvxLongULSpaceItem aUL( pUL->GetUpper(), pUL->GetLower(), SID_ATTR_PAGE_HEADER_SPACING);
2452 rSet.Put(aUL);
2455 bool bShared = !rDesc.IsHeaderShared();
2456 bool bFirst = !rDesc.IsFirstShared(); // FIXME control changes for both header footer - tdf#100287
2457 sal_uInt16 nLayout = (static_cast<int>(bShared)<<1) + static_cast<int>(bFirst);
2458 SfxInt16Item aLayoutItem(SID_ATTR_PAGE_HEADER_LAYOUT, nLayout);
2459 rSet.Put(aLayoutItem);
2462 break;
2463 case SID_ATTR_PAGE_FOOTER:
2464 case SID_ATTR_PAGE_FOOTER_LRMARGIN:
2465 case SID_ATTR_PAGE_FOOTER_SPACING:
2466 case SID_ATTR_PAGE_FOOTER_LAYOUT:
2468 const SwFormatFooter& rFooter = rDesc.GetMaster().GetFooter();
2469 bool bFooterOn = rFooter.IsActive();
2470 rSet.Put( SfxBoolItem(SID_ATTR_PAGE_FOOTER, bFooterOn ) );
2471 if (bFooterOn)
2473 if (const SvxLRSpaceItem* rLR = rFooter.GetFooterFormat()->GetAttrSet().GetItem<SvxLRSpaceItem>(SID_ATTR_LRSPACE))
2475 SvxLongLRSpaceItem aLR(rLR->GetLeft(), rLR->GetRight(), SID_ATTR_PAGE_FOOTER_LRMARGIN);
2476 rSet.Put(aLR);
2478 if (const SvxULSpaceItem* rUL = rFooter.GetFooterFormat()->GetAttrSet().GetItem<SvxULSpaceItem>(SID_ATTR_ULSPACE))
2480 SvxLongULSpaceItem aUL( rUL->GetUpper(), rUL->GetLower(), SID_ATTR_PAGE_FOOTER_SPACING);
2481 rSet.Put(aUL);
2483 bool bShared = !rDesc.IsFooterShared();
2484 bool bFirst = !rDesc.IsFirstShared(); // FIXME control changes for both header footer - tdf#100287
2485 sal_uInt16 nLayout = (static_cast<int>(bShared)<<1) + static_cast<int>(bFirst);
2486 SfxInt16Item aLayoutItem(SID_ATTR_PAGE_FOOTER_LAYOUT, nLayout);
2487 rSet.Put(aLayoutItem);
2490 break;
2492 case SID_ATTR_PAGE_COLOR:
2493 case SID_ATTR_PAGE_FILLSTYLE:
2494 case SID_ATTR_PAGE_GRADIENT:
2495 case SID_ATTR_PAGE_HATCH:
2496 case SID_ATTR_PAGE_BITMAP:
2498 SfxItemSet aSet = rDesc.GetMaster().GetAttrSet();
2499 if (const auto pFillStyleItem = aSet.GetItem(XATTR_FILLSTYLE))
2501 drawing::FillStyle eXFS = pFillStyleItem->GetValue();
2502 XFillStyleItem aFillStyleItem( eXFS );
2503 aFillStyleItem.SetWhich( SID_ATTR_PAGE_FILLSTYLE );
2504 rSet.Put(aFillStyleItem);
2506 switch(eXFS)
2508 case drawing::FillStyle_SOLID:
2510 if (const auto pItem = aSet.GetItem<XFillColorItem>(XATTR_FILLCOLOR, false))
2512 Color aColor = pItem->GetColorValue();
2513 XFillColorItem aFillColorItem( OUString(), aColor );
2514 aFillColorItem.SetWhich( SID_ATTR_PAGE_COLOR );
2515 rSet.Put( aFillColorItem );
2517 break;
2520 case drawing::FillStyle_GRADIENT:
2522 const basegfx::BGradient& aBGradient = aSet.GetItem<XFillGradientItem>( XATTR_FILLGRADIENT )->GetGradientValue();
2523 XFillGradientItem aFillGradientItem( OUString(), aBGradient, SID_ATTR_PAGE_GRADIENT );
2524 rSet.Put( aFillGradientItem );
2526 break;
2528 case drawing::FillStyle_HATCH:
2530 const XFillHatchItem *pFillHatchItem( aSet.GetItem<XFillHatchItem>( XATTR_FILLHATCH ) );
2531 XFillHatchItem aFillHatchItem( pFillHatchItem->GetName(), pFillHatchItem->GetHatchValue());
2532 aFillHatchItem.SetWhich( SID_ATTR_PAGE_HATCH );
2533 rSet.Put( aFillHatchItem );
2535 break;
2537 case drawing::FillStyle_BITMAP:
2539 const XFillBitmapItem *pFillBitmapItem = aSet.GetItem<XFillBitmapItem>( XATTR_FILLBITMAP );
2540 XFillBitmapItem aFillBitmapItem( pFillBitmapItem->GetName(), pFillBitmapItem->GetGraphicObject() );
2541 aFillBitmapItem.SetWhich( SID_ATTR_PAGE_BITMAP );
2542 rSet.Put( aFillBitmapItem );
2544 break;
2545 case drawing::FillStyle_NONE:
2548 break;
2550 default:
2551 break;
2554 break;
2558 nWhich = aIter.NextWhich();
2562 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */