summaryrefslogtreecommitdiffstats
path: root/sw/source/uibase/frmdlg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/source/uibase/frmdlg
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/source/uibase/frmdlg')
-rw-r--r--sw/source/uibase/frmdlg/colex.cxx607
-rw-r--r--sw/source/uibase/frmdlg/colmgr.cxx161
-rw-r--r--sw/source/uibase/frmdlg/frmmgr.cxx613
3 files changed, 1381 insertions, 0 deletions
diff --git a/sw/source/uibase/frmdlg/colex.cxx b/sw/source/uibase/frmdlg/colex.cxx
new file mode 100644
index 000000000..8d458f016
--- /dev/null
+++ b/sw/source/uibase/frmdlg/colex.cxx
@@ -0,0 +1,607 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cmdid.h>
+#include <hintids.hxx>
+#include <svl/eitem.hxx>
+#include <tools/fract.hxx>
+#include <editeng/lrspitem.hxx>
+#include <editeng/ulspitem.hxx>
+#include <editeng/sizeitem.hxx>
+#include <svx/pageitem.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/frmdiritem.hxx>
+#include <vcl/outdev.hxx>
+#include <vcl/settings.hxx>
+#include <tgrditem.hxx>
+#include <viewopt.hxx>
+#include <colex.hxx>
+#include <colmgr.hxx>
+#include <svx/unobrushitemhelper.hxx>
+
+void SwPageExample::UpdateExample( const SfxItemSet& rSet )
+{
+ if (SfxItemState::DEFAULT <= rSet.GetItemState(RES_FRAMEDIR))
+ {
+ const SvxFrameDirectionItem& rDirItem = rSet.Get(RES_FRAMEDIR);
+ m_bVertical = rDirItem.GetValue() == SvxFrameDirection::Vertical_RL_TB||
+ rDirItem.GetValue() == SvxFrameDirection::Vertical_LR_TB;
+ }
+
+ SfxItemPool* pPool = rSet.GetPool();
+ sal_uInt16 nWhich = pPool->GetWhich( SID_ATTR_PAGE );
+ if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
+ {
+ // alignment
+ const SvxPageItem& rPage = static_cast<const SvxPageItem&>(rSet.Get(nWhich));
+ SetUsage(rPage.GetPageUsage());
+ }
+
+ nWhich = pPool->GetWhich( SID_ATTR_PAGE_SIZE );
+
+ if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
+ {
+ // orientation and size from PageItem
+ const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(rSet.Get( nWhich ));
+ SetSize( rSize.GetSize() );
+ }
+ nWhich = RES_LR_SPACE;
+ if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
+ {
+ // set left and right border
+ const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(rSet.Get( nWhich ));
+
+ SetLeft( rLRSpace.GetLeft() );
+ SetRight( rLRSpace.GetRight() );
+ }
+ else
+ {
+ SetLeft( 0 );
+ SetRight( 0 );
+ }
+
+ nWhich = RES_UL_SPACE;
+
+ if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
+ {
+ // set upper and lower border
+ const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(rSet.Get( nWhich ));
+
+ SetTop( rULSpace.GetUpper() );
+ SetBottom( rULSpace.GetLower() );
+ }
+ else
+ {
+ SetTop( 0 );
+ SetBottom( 0 );
+ }
+
+ // evaluate header-attributes
+ const SfxPoolItem* pItem;
+ if( SfxItemState::SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_HEADERSET),
+ false, &pItem ) )
+ {
+ const SfxItemSet& rHeaderSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
+ const SfxBoolItem& rHeaderOn =
+ static_cast<const SfxBoolItem&>(rHeaderSet.Get( pPool->GetWhich( SID_ATTR_PAGE_ON ) ) );
+
+ if ( rHeaderOn.GetValue() )
+ {
+ const SvxSizeItem& rSize =
+ static_cast<const SvxSizeItem&>(rHeaderSet.Get(pPool->GetWhich(SID_ATTR_PAGE_SIZE)));
+
+ const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(rHeaderSet.Get(
+ pPool->GetWhich(SID_ATTR_ULSPACE)));
+ const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(rHeaderSet.Get(
+ pPool->GetWhich(SID_ATTR_LRSPACE)));
+
+ SetHdHeight( rSize.GetSize().Height() - rUL.GetLower());
+ SetHdDist( rUL.GetLower() );
+ SetHdLeft( rLR.GetLeft() );
+ SetHdRight( rLR.GetRight() );
+ SetHeader( true );
+
+ if(SfxItemState::SET == rHeaderSet.GetItemState(RES_BACKGROUND))
+ {
+ // create FillAttributes from SvxBrushItem //SetHdColor(rItem.GetColor());
+ const SvxBrushItem& rItem = rHeaderSet.Get(RES_BACKGROUND);
+ SfxItemSet aTempSet(*rHeaderSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
+
+ setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
+ setHeaderFillAttributes(
+ std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(
+ aTempSet));
+ }
+ }
+ else
+ SetHeader( false );
+ }
+
+ if( SfxItemState::SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_FOOTERSET),
+ false, &pItem ) )
+ {
+ const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
+ const SfxBoolItem& rFooterOn = rFooterSet.Get( SID_ATTR_PAGE_ON );
+
+ if ( rFooterOn.GetValue() )
+ {
+ const SvxSizeItem& rSize =
+ static_cast<const SvxSizeItem&>(rFooterSet.Get( pPool->GetWhich( SID_ATTR_PAGE_SIZE ) ));
+
+ const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(rFooterSet.Get(
+ pPool->GetWhich( SID_ATTR_ULSPACE ) ));
+ const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(rFooterSet.Get(
+ pPool->GetWhich( SID_ATTR_LRSPACE ) ));
+
+ SetFtHeight( rSize.GetSize().Height() - rUL.GetUpper());
+ SetFtDist( rUL.GetUpper() );
+ SetFtLeft( rLR.GetLeft() );
+ SetFtRight( rLR.GetRight() );
+ SetFooter( true );
+
+ if( rFooterSet.GetItemState( RES_BACKGROUND ) == SfxItemState::SET )
+ {
+ // create FillAttributes from SvxBrushItem //SetFtColor(rItem.GetColor());
+ const SvxBrushItem& rItem = rFooterSet.Get(RES_BACKGROUND);
+ SfxItemSet aTempSet(*rFooterSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
+
+ setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
+ setFooterFillAttributes(
+ std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(
+ aTempSet));
+ }
+ }
+ else
+ SetFooter( false );
+ }
+
+ if(SfxItemState::SET == rSet.GetItemState(RES_BACKGROUND, false, &pItem))
+ {
+ // create FillAttributes from SvxBrushItem
+ const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem);
+ SfxItemSet aTempSet(*rSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
+
+ setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
+ setPageFillAttributes(
+ std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(
+ aTempSet));
+ }
+
+ Invalidate();
+}
+
+void SwColExample::DrawPage(vcl::RenderContext& rRenderContext, const Point& rOrg,
+ const bool bSecond, const bool bEnabled)
+{
+ SwPageExample::DrawPage(rRenderContext, rOrg, bSecond, bEnabled);
+ if (!pColMgr)
+ return;
+ sal_uInt16 nColumnCount = pColMgr->GetCount();
+ if (!nColumnCount)
+ return;
+
+ long nL = GetLeft();
+ long nR = GetRight();
+
+ if (GetUsage() == SvxPageUsage::Mirror && !bSecond)
+ {
+ // swap for mirrored
+ nL = GetRight();
+ nR = GetLeft();
+ }
+
+ rRenderContext.SetFillColor(COL_LIGHTGRAY);
+ tools::Rectangle aRect;
+ aRect.SetRight( rOrg.X() + GetSize().Width() - nR );
+ aRect.SetLeft( rOrg.X() + nL );
+ aRect.SetTop( rOrg.Y() + GetTop() + GetHdHeight() + GetHdDist() );
+ aRect.SetBottom( rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist() );
+ rRenderContext.DrawRect(aRect);
+
+ const tools::Rectangle aDefineRect(aRect);
+ const drawinglayer::attribute::SdrAllFillAttributesHelperPtr& rFillAttributes = getPageFillAttributes();
+
+ if (!rFillAttributes || !rFillAttributes->isUsed())
+ {
+ // If there is no fill, use fallback color
+ const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
+ const Color& rFieldColor = rStyleSettings.GetFieldColor();
+
+ setPageFillAttributes(
+ std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(
+ rFieldColor));
+ }
+
+ // #97495# make sure that the automatic column width's are always equal
+ bool bAutoWidth = pColMgr->IsAutoWidth();
+ sal_Int32 nAutoColWidth = 0;
+ if (bAutoWidth)
+ {
+ sal_Int32 nColumnWidthSum = 0;
+ for (sal_uInt16 i = 0; i < nColumnCount; ++i)
+ nColumnWidthSum += pColMgr->GetColWidth( i );
+ nAutoColWidth = nColumnWidthSum / nColumnCount;
+ }
+
+ for (sal_uInt16 i = 0; i < nColumnCount; ++i)
+ {
+ if (!bAutoWidth)
+ nAutoColWidth = pColMgr->GetColWidth(i);
+
+ if (!m_bVertical)
+ aRect.SetRight( aRect.Left() + nAutoColWidth );
+ else
+ aRect.SetBottom( aRect.Top() + nAutoColWidth );
+
+ // use primitive draw command
+ drawFillAttributes(rRenderContext, getPageFillAttributes(), aRect, aDefineRect);
+
+ if (i < nColumnCount - 1)
+ {
+ if (!m_bVertical)
+ aRect.SetLeft( aRect.Right() + pColMgr->GetGutterWidth(i) );
+ else
+ aRect.SetTop( aRect.Bottom() + pColMgr->GetGutterWidth(i) );
+ }
+ }
+ if (pColMgr->HasLine())
+ {
+ Point aUp(rOrg.X() + nL, rOrg.Y() + GetTop());
+ Point aDown(rOrg.X() + nL,
+ rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist());
+
+ if (pColMgr->GetLineHeightPercent() != 100)
+ {
+ long nLength = !m_bVertical ? aDown.Y() - aUp.Y() : aDown.X() - aUp.X();
+ nLength -= nLength * pColMgr->GetLineHeightPercent() / 100;
+ switch (pColMgr->GetAdjust())
+ {
+ case COLADJ_BOTTOM:
+ if (!m_bVertical)
+ aUp.AdjustY(nLength );
+ else
+ aUp.AdjustX(nLength );
+ break;
+ case COLADJ_TOP:
+ if (!m_bVertical)
+ aDown.AdjustY( -nLength );
+ else
+ aDown.AdjustX( -nLength );
+ break;
+ case COLADJ_CENTER:
+ if (!m_bVertical)
+ {
+ aUp.AdjustY(nLength / 2 );
+ aDown.AdjustY( -(nLength / 2) );
+ }
+ else
+ {
+ aUp.AdjustX(nLength / 2 );
+ aDown.AdjustX( -(nLength / 2) );
+ }
+ break;
+ default:
+ break; // prevent warning
+ }
+ }
+
+ for (sal_uInt16 i = 0; i < nColumnCount - 1; ++i)
+ {
+ int nGutter = pColMgr->GetGutterWidth(i);
+ int nDist = pColMgr->GetColWidth( i ) + nGutter;
+ nDist -= (i == 0) ? nGutter / 2 : 0;
+ if (!m_bVertical)
+ {
+ aUp.AdjustX(nDist );
+ aDown.AdjustX(nDist );
+ }
+ else
+ {
+ aUp.AdjustY(nDist );
+ aDown.AdjustY(nDist );
+ }
+
+ rRenderContext.DrawLine(aUp, aDown);
+ }
+ }
+}
+
+SwColumnOnlyExample::SwColumnOnlyExample()
+ : m_aFrameSize(SvxPaperInfo::GetPaperSize(PAPER_A4)) // DIN A4
+{
+ ::FitToActualSize(m_aCols, static_cast<sal_uInt16>(m_aFrameSize.Width()));
+}
+
+void SwColumnOnlyExample::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
+{
+ rRenderContext.Push(PushFlags::MAPMODE);
+
+ Fraction aScale(m_aWinSize.Height(), m_aFrameSize.Height());
+ MapMode aMapMode(MapUnit::MapTwip);
+ aMapMode.SetScaleX(aScale);
+ aMapMode.SetScaleY(aScale);
+ rRenderContext.SetMapMode(aMapMode);
+
+ const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
+ const Color& rFieldColor = rStyleSettings.GetFieldColor();
+ const Color& rDlgColor = rStyleSettings.GetDialogColor();
+ const Color& rFieldTextColor = SwViewOption::GetFontColor();
+ Color aGrayColor(COL_LIGHTGRAY);
+ if (rFieldColor == aGrayColor)
+ aGrayColor.Invert();
+
+ Size aLogSize(rRenderContext.PixelToLogic(GetOutputSizePixel()));
+ tools::Rectangle aCompleteRect(Point(0,0), aLogSize);
+ rRenderContext.SetLineColor(rDlgColor);
+ rRenderContext.SetFillColor(rDlgColor);
+ rRenderContext.DrawRect(aCompleteRect);
+
+ rRenderContext.SetLineColor(rFieldTextColor);
+ Point aTL((aLogSize.Width() - m_aFrameSize.Width()) / 2,
+ (aLogSize.Height() - m_aFrameSize.Height()) / 2);
+ tools::Rectangle aRect(aTL, m_aFrameSize);
+
+ //draw a shadow rectangle
+ rRenderContext.SetFillColor(COL_GRAY);
+ tools::Rectangle aShadowRect(aRect);
+ aShadowRect.Move(aTL.Y(), aTL.Y());
+ rRenderContext.DrawRect(aShadowRect);
+
+ rRenderContext.SetFillColor(rFieldColor);
+ rRenderContext.DrawRect(aRect);
+
+ rRenderContext.SetFillColor(aGrayColor);
+
+ //column separator?
+ long nLength = aLogSize.Height() - 2 * aTL.Y();
+ Point aUp(aTL);
+ Point aDown(aTL.X(), nLength);
+ bool bLines = false;
+ if (m_aCols.GetLineAdj() != COLADJ_NONE)
+ {
+ bLines = true;
+
+ sal_uInt16 nPercent = m_aCols.GetLineHeight();
+ if (nPercent != 100)
+ {
+ nLength -= nLength * nPercent / 100;
+ switch(m_aCols.GetLineAdj())
+ {
+ case COLADJ_BOTTOM: aUp.AdjustY(nLength ); break;
+ case COLADJ_TOP: aDown.AdjustY( -nLength ); break;
+ case COLADJ_CENTER:
+ aUp.AdjustY(nLength / 2 );
+ aDown.AdjustY( -(nLength / 2) );
+ break;
+ default:
+ break; //prevent warning
+ }
+ }
+
+ }
+ const SwColumns& rCols = m_aCols.GetColumns();
+ sal_uInt16 nColCount = rCols.size();
+ if (nColCount)
+ {
+ rRenderContext.DrawRect(aRect);
+ rRenderContext.SetFillColor(rFieldColor);
+ tools::Rectangle aFrameRect(aTL, m_aFrameSize);
+ long nSum = aTL.X();
+ for (sal_uInt16 i = 0; i < nColCount; i++)
+ {
+ const SwColumn* pCol = &rCols[i];
+ aFrameRect.SetLeft( nSum + pCol->GetLeft() ); //nSum + pCol->GetLeft() + aTL.X();
+ nSum += pCol->GetWishWidth();
+ aFrameRect.SetRight( nSum - pCol->GetRight() );
+ rRenderContext.DrawRect(aFrameRect);
+ }
+ if (bLines)
+ {
+ nSum = aTL.X();
+ for (sal_uInt16 i = 0; i < nColCount - 1; i++)
+ {
+ nSum += rCols[i].GetWishWidth();
+ aUp.setX( nSum );
+ aDown.setX( nSum );
+ rRenderContext.DrawLine(aUp, aDown);
+ }
+ }
+ }
+ rRenderContext.Pop();
+}
+
+void SwColumnOnlyExample::SetColumns(const SwFormatCol& rCol)
+{
+ m_aCols = rCol;
+ sal_uInt16 nWishSum = m_aCols.GetWishWidth();
+ long nFrameWidth = m_aFrameSize.Width();
+ SwColumns& rCols = m_aCols.GetColumns();
+ sal_uInt16 nColCount = rCols.size();
+
+ for(sal_uInt16 i = 0; i < nColCount; i++)
+ {
+ SwColumn* pCol = &rCols[i];
+ long nWish = pCol->GetWishWidth();
+ nWish *= nFrameWidth;
+ nWish /= nWishSum;
+ pCol->SetWishWidth(static_cast<sal_uInt16>(nWish));
+ long nLeft = pCol->GetLeft();
+ nLeft *= nFrameWidth;
+ nLeft /= nWishSum;
+ pCol->SetLeft(static_cast<sal_uInt16>(nLeft));
+ long nRight = pCol->GetRight();
+ nRight *= nFrameWidth;
+ nRight /= nWishSum;
+ pCol->SetRight(static_cast<sal_uInt16>(nRight));
+ }
+ // #97495# make sure that the automatic column width's are always equal
+ if(nColCount && m_aCols.IsOrtho())
+ {
+ sal_Int32 nColumnWidthSum = 0;
+ sal_uInt16 i;
+ for(i = 0; i < nColCount; ++i)
+ {
+ SwColumn* pCol = &rCols[i];
+ nColumnWidthSum += pCol->GetWishWidth();
+ nColumnWidthSum -= (pCol->GetRight() + pCol->GetLeft());
+ }
+ nColumnWidthSum /= nColCount;
+ for(i = 0; i < nColCount; ++i)
+ {
+ SwColumn* pCol = &rCols[i];
+ pCol->SetWishWidth( static_cast< sal_uInt16 >(nColumnWidthSum + pCol->GetRight() + pCol->GetLeft()));
+ }
+ }
+}
+
+void SwColumnOnlyExample::SetDrawingArea(weld::DrawingArea* pDrawingArea)
+{
+ weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
+ OutputDevice& rRefDevice = pDrawingArea->get_ref_device();
+ Size aPrefSize(rRefDevice.LogicToPixel(Size(75, 46), MapMode(MapUnit::MapAppFont)));
+ pDrawingArea->set_size_request(aPrefSize.Width(), aPrefSize.Height());
+}
+
+void SwColumnOnlyExample::Resize()
+{
+ OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
+ rRefDevice.Push(PushFlags::MAPMODE);
+ rRefDevice.SetMapMode(MapMode(MapUnit::MapTwip));
+ m_aWinSize = GetOutputSizePixel();
+ m_aWinSize.AdjustHeight( -4 );
+ m_aWinSize.AdjustWidth( -4 );
+ m_aWinSize = rRefDevice.PixelToLogic(m_aWinSize);
+ rRefDevice.Pop();
+ Invalidate();
+}
+
+SwPageGridExample::SwPageGridExample()
+{
+}
+
+void SwPageGridExample::DrawPage(vcl::RenderContext& rRenderContext, const Point& rOrg,
+ const bool bSecond, const bool bEnabled)
+{
+ SwPageExample::DrawPage(rRenderContext, rOrg, bSecond, bEnabled);
+
+ if (!pGridItem || !pGridItem->GetGridType())
+ return;
+
+ //paint the grid now
+ Color aLineColor = pGridItem->GetColor();
+ if (aLineColor == COL_AUTO)
+ {
+ aLineColor = rRenderContext.GetFillColor();
+ aLineColor.Invert();
+ }
+ rRenderContext.SetLineColor(aLineColor);
+ long nL = GetLeft();
+ long nR = GetRight();
+
+ if (GetUsage() == SvxPageUsage::Mirror && !bSecond)
+ {
+ // rotate for mirrored
+ nL = GetRight();
+ nR = GetLeft();
+ }
+
+ tools::Rectangle aRect;
+ aRect.SetRight( rOrg.X() + GetSize().Width() - nR );
+ aRect.SetLeft( rOrg.X() + nL );
+ aRect.SetTop( rOrg.Y() + GetTop() + GetHdHeight() + GetHdDist() );
+ aRect.SetBottom( rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist() );
+
+ //increase the values to get a 'viewable' preview
+ sal_Int32 nBaseHeight = pGridItem->GetBaseHeight() * 3;
+ sal_Int32 nRubyHeight = pGridItem->GetRubyHeight() * 3;
+
+ //detect height of rectangles
+ tools::Rectangle aRubyRect(aRect.TopLeft(),
+ m_bVertical ?
+ Size(nRubyHeight, aRect.GetHeight()) :
+ Size(aRect.GetWidth(), nRubyHeight));
+ tools::Rectangle aCharRect(aRect.TopLeft(),
+ m_bVertical ?
+ Size(nBaseHeight, aRect.GetHeight()) :
+ Size(aRect.GetWidth(), nBaseHeight));
+
+ sal_Int32 nLineHeight = nBaseHeight + nRubyHeight;
+
+ //detect count of rectangles
+ sal_Int32 nLines = (m_bVertical ? aRect.GetWidth(): aRect.GetHeight()) / nLineHeight;
+ if (nLines > pGridItem->GetLines())
+ nLines = pGridItem->GetLines();
+
+ // determine start position
+ if (m_bVertical)
+ {
+ sal_Int16 nXStart = static_cast<sal_Int16>(aRect.GetWidth() / 2 - nLineHeight * nLines /2);
+ aRubyRect.Move(nXStart, 0);
+ aCharRect.Move(nXStart, 0);
+ }
+ else
+ {
+ sal_Int16 nYStart = static_cast<sal_Int16>(aRect.GetHeight() / 2 - nLineHeight * nLines /2);
+ aRubyRect.Move(0, nYStart);
+ aCharRect.Move(0, nYStart);
+ }
+
+ if (pGridItem->IsRubyTextBelow())
+ m_bVertical ? aRubyRect.Move(nBaseHeight, 0) : aRubyRect.Move(0, nBaseHeight);
+ else
+ m_bVertical ? aCharRect.Move(nRubyHeight, 0) : aCharRect.Move(0, nRubyHeight);
+
+ //vertical lines
+ bool bBothLines = pGridItem->GetGridType() == GRID_LINES_CHARS;
+ rRenderContext.SetFillColor(COL_TRANSPARENT);
+ sal_Int32 nXMove = m_bVertical ? nLineHeight : 0;
+ sal_Int32 nYMove = m_bVertical ? 0 : nLineHeight;
+ for (sal_Int32 nLine = 0; nLine < nLines; nLine++)
+ {
+ rRenderContext.DrawRect(aRubyRect);
+ rRenderContext.DrawRect(aCharRect);
+ if (bBothLines)
+ {
+ Point aStart = aCharRect.TopLeft();
+ Point aEnd = m_bVertical ? aCharRect.TopRight() : aCharRect.BottomLeft();
+ while (m_bVertical ? aStart.Y() < aRect.Bottom(): aStart.X() < aRect.Right())
+ {
+ rRenderContext.DrawLine(aStart, aEnd);
+ if (m_bVertical)
+ aStart.setY( aEnd.AdjustY(nBaseHeight ) );
+ else
+ aStart.setX( aEnd.AdjustX(nBaseHeight ) );
+ }
+ }
+ aRubyRect.Move(nXMove, nYMove);
+ aCharRect.Move(nXMove, nYMove);
+ }
+
+}
+
+void SwPageGridExample::UpdateExample( const SfxItemSet& rSet )
+{
+ pGridItem.reset();
+ //get the grid information
+ if (SfxItemState::DEFAULT <= rSet.GetItemState(RES_TEXTGRID))
+ pGridItem.reset(rSet.Get(RES_TEXTGRID).Clone());
+ SwPageExample::UpdateExample(rSet);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/frmdlg/colmgr.cxx b/sw/source/uibase/frmdlg/colmgr.cxx
new file mode 100644
index 000000000..8dda357ee
--- /dev/null
+++ b/sw/source/uibase/frmdlg/colmgr.cxx
@@ -0,0 +1,161 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <algorithm>
+
+#include <hintids.hxx>
+#include <editeng/lrspitem.hxx>
+#include <osl/diagnose.h>
+
+#include <colmgr.hxx>
+#include <fmtfsize.hxx>
+#include <swtypes.hxx>
+
+// private methods
+
+// set column width to current width
+void FitToActualSize(SwFormatCol& rCol, sal_uInt16 nWidth)
+{
+ const sal_uInt16 nCount = rCol.GetColumns().size();
+ for(sal_uInt16 i = 0; i < nCount; ++i)
+ {
+ const sal_uInt16 nTmp = rCol.CalcColWidth(i, nWidth);
+ auto & col = rCol.GetColumns()[i];
+ col.SetWishWidth(nTmp);
+ // If necessary, shrink borders (as equally as possible) to keep up the invariant that
+ // GetWishWidth() >= GetLeft() + GetRight():
+ sal_uInt32 const borders = col.GetLeft() + col.GetRight();
+ if (borders > nTmp)
+ {
+ auto const shrink = borders - nTmp;
+ auto const half = shrink / 2; // rounds down
+ if (col.GetLeft() < col.GetRight())
+ {
+ auto const shrinkLeft = std::min(sal_uInt32(col.GetLeft()), half);
+ col.SetLeft(col.GetLeft() - shrinkLeft);
+ col.SetRight(col.GetRight() - (shrink - shrinkLeft));
+ }
+ else
+ {
+ auto const shrinkRight = std::min(sal_uInt32(col.GetRight()), half);
+ col.SetLeft(col.GetLeft() - (shrink - shrinkRight));
+ col.SetRight(col.GetRight() - shrinkRight);
+ }
+ }
+ }
+ rCol.SetWishWidth(nWidth);
+}
+
+// public methods
+
+// set column quantity and Gutterwidth
+void SwColMgr::SetCount(sal_uInt16 nCount, sal_uInt16 nGutterWidth)
+{
+ aFormatCol.Init(nCount, nGutterWidth, nWidth);
+ aFormatCol.SetWishWidth(nWidth);
+ aFormatCol.SetGutterWidth(nGutterWidth, nWidth);
+}
+
+sal_uInt16 SwColMgr::GetGutterWidth( sal_uInt16 nPos ) const
+{
+ sal_uInt16 nRet;
+ if(nPos == USHRT_MAX )
+ nRet = GetCount() > 1 ? aFormatCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
+ else
+ {
+ OSL_ENSURE(nPos < GetCount() - 1, "column overindexed" );
+ const SwColumns& rCols = aFormatCol.GetColumns();
+ nRet = rCols[nPos].GetRight() + rCols[nPos + 1].GetLeft();
+ }
+ return nRet;
+}
+
+void SwColMgr::SetGutterWidth(sal_uInt16 nGutterWidth, sal_uInt16 nPos )
+{
+ if(nPos == USHRT_MAX)
+ aFormatCol.SetGutterWidth(nGutterWidth, nWidth);
+ else
+ {
+ OSL_ENSURE(nPos < GetCount() - 1, "column overindexed" );
+ SwColumns& rCols = aFormatCol.GetColumns();
+ sal_uInt16 nGutterWidth2 = nGutterWidth / 2;
+ rCols[nPos].SetRight(nGutterWidth2);
+ rCols[nPos + 1].SetLeft(nGutterWidth2);
+ }
+}
+
+// height separation line
+short SwColMgr::GetLineHeightPercent() const
+{
+ return static_cast<short>(aFormatCol.GetLineHeight());
+}
+void SwColMgr::SetLineHeightPercent(short nPercent)
+{
+ OSL_ENSURE(nPercent <= 100, "line height may be at most 100%");
+ aFormatCol.SetLineHeight(static_cast<sal_uInt8>(nPercent));
+}
+
+// column width
+sal_uInt16 SwColMgr::GetColWidth(sal_uInt16 nIdx) const
+{
+ OSL_ENSURE(nIdx < GetCount(), "Column array overindexed.");
+ return aFormatCol.CalcPrtColWidth(nIdx, nWidth);
+}
+
+void SwColMgr::SetColWidth(sal_uInt16 nIdx, sal_uInt16 nWd)
+{
+ OSL_ENSURE(nIdx < GetCount(), "Column array overindexed.");
+ aFormatCol.GetColumns()[nIdx].SetWishWidth(nWd);
+
+}
+
+// newly set size
+void SwColMgr::SetActualWidth(sal_uInt16 nW)
+{
+ nWidth = nW;
+ ::FitToActualSize(aFormatCol, nW);
+}
+
+// ctor
+SwColMgr::SwColMgr(const SfxItemSet& rSet) :
+ aFormatCol(rSet.Get(RES_COL))
+{
+ nWidth = static_cast<sal_uInt16>(rSet.Get(RES_FRM_SIZE).GetWidth());
+ if (nWidth < MINLAY)
+ nWidth = USHRT_MAX;
+ const SvxLRSpaceItem &rLR = rSet.Get(RES_LR_SPACE);
+ nWidth = nWidth - static_cast<sal_uInt16>(rLR.GetLeft());
+ nWidth = nWidth - static_cast<sal_uInt16>(rLR.GetRight());
+ ::FitToActualSize(aFormatCol, nWidth);
+}
+
+SwColMgr::~SwColMgr()
+{
+}
+
+void SwColMgr::SetLineWidthAndColor(SvxBorderLineStyle eStyle, sal_uLong nLWidth, const Color& rCol)
+{
+ aFormatCol.SetLineStyle(eStyle);
+ aFormatCol.SetLineWidth(nLWidth);
+ aFormatCol.SetLineColor(rCol);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx b/sw/source/uibase/frmdlg/frmmgr.cxx
new file mode 100644
index 000000000..926a949e2
--- /dev/null
+++ b/sw/source/uibase/frmdlg/frmmgr.cxx
@@ -0,0 +1,613 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cmdid.h>
+#include <hintids.hxx>
+
+#include <svl/stritem.hxx>
+#include <editeng/boxitem.hxx>
+#include <editeng/lrspitem.hxx>
+#include <editeng/ulspitem.hxx>
+#include <editeng/shaditem.hxx>
+#include <svx/swframevalidation.hxx>
+#include <svx/xdef.hxx>
+#include <tools/globname.hxx>
+#include <comphelper/classids.hxx>
+#include <fmtclds.hxx>
+#include <wrtsh.hxx>
+#include <view.hxx>
+#include <viewopt.hxx>
+#include <uitool.hxx>
+#include <frmmgr.hxx>
+#include <format.hxx>
+#include <mdiexp.hxx>
+#include <poolfmt.hxx>
+#include <com/sun/star/text/HoriOrientation.hpp>
+#include <com/sun/star/text/VertOrientation.hpp>
+#include <com/sun/star/text/RelOrientation.hpp>
+#include <grfatr.hxx>
+
+using namespace ::com::sun::star;
+
+static sal_uInt16 aFrameMgrRange[] = {
+ RES_FRMATR_BEGIN, RES_FRMATR_END-1, // 87-129
+
+ // RotGrfFlyFrame: Support here, but seems not to be
+ // added in range of m_pOwnSh->GetFlyFrameAttr result
+ // (see below). Tried to find, but could not identify
+ RES_GRFATR_ROTATION, RES_GRFATR_ROTATION, // 132
+
+ // FillAttribute support
+ XATTR_FILL_FIRST, XATTR_FILL_LAST, // 1014-1033
+
+ SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
+ FN_SET_FRM_NAME, FN_SET_FRM_NAME,
+ 0};
+
+// determine frame attributes via Shell
+SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nType, const SvGlobalName* pName ) :
+ m_aSet( static_cast<SwAttrPool&>(pSh->GetAttrPool()), aFrameMgrRange ),
+ m_pOwnSh( pSh ),
+ m_bAbsPos( false ),
+ m_bNewFrame( bNew ),
+ m_bIsInVertical( false ),
+ m_bIsInVerticalL2R( false )
+{
+ if ( m_bNewFrame )
+ {
+ sal_uInt16 nId;
+ switch ( nType )
+ {
+ case Frmmgr_Type::TEXT: nId = RES_POOLFRM_FRAME; break;
+ case Frmmgr_Type::OLE: nId = RES_POOLFRM_OLE; break;
+ case Frmmgr_Type::GRF: nId = RES_POOLFRM_GRAPHIC; break;
+ // set defaults:
+ default: nId=0; break;
+ }
+ m_aSet.SetParent( &m_pOwnSh->GetFormatFromPool( nId )->GetAttrSet());
+ m_aSet.Put( SwFormatFrameSize( SwFrameSize::Minimum, DFLT_WIDTH, DFLT_HEIGHT ));
+ if ( 0 != ::GetHtmlMode(pSh->GetView().GetDocShell()) )
+ m_aSet.Put( SwFormatHoriOrient( 0, text::HoriOrientation::LEFT, text::RelOrientation::PRINT_AREA ) );
+
+ if (nType == Frmmgr_Type::GRF || nType == Frmmgr_Type::OLE)
+ {
+ if (!pName || *pName != SvGlobalName( SO3_SM_CLASSID ))
+ {
+ // Default anchor for new graphics and objects is at-char, except for Math objects.
+ m_aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_CHAR));
+ }
+ }
+ }
+ else if ( nType == Frmmgr_Type::NONE )
+ {
+ m_pOwnSh->GetFlyFrameAttr( m_aSet );
+ bool bRightToLeft;
+ m_bIsInVertical = m_pOwnSh->IsFrameVertical(true, bRightToLeft, m_bIsInVerticalL2R);
+ }
+ ::PrepareBoxInfo( m_aSet, *m_pOwnSh );
+}
+
+SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, const SfxItemSet &rSet ) :
+ m_aSet( rSet ),
+ m_pOwnSh( pSh ),
+ m_bAbsPos( false ),
+ m_bNewFrame( bNew ),
+ m_bIsInVertical(false),
+ m_bIsInVerticalL2R(false)
+{
+ if(!bNew)
+ {
+ bool bRightToLeft;
+ m_bIsInVertical = pSh->IsFrameVertical(true, bRightToLeft, m_bIsInVerticalL2R);
+ }
+}
+
+// Initialise
+void SwFlyFrameAttrMgr::UpdateAttrMgr()
+{
+ if ( !m_bNewFrame && m_pOwnSh->IsFrameSelected() )
+ m_pOwnSh->GetFlyFrameAttr( m_aSet );
+ ::PrepareBoxInfo( m_aSet, *m_pOwnSh );
+}
+
+void SwFlyFrameAttrMgr::UpdateFlyFrame_()
+{
+ const SfxPoolItem* pItem = nullptr;
+
+ if (m_aSet.GetItemState(FN_SET_FRM_NAME, false, &pItem) == SfxItemState::SET)
+ m_pOwnSh->SetFlyName(static_cast<const SfxStringItem *>(pItem)->GetValue());
+
+ m_pOwnSh->SetModified();
+
+ if ( m_bAbsPos )
+ {
+ m_pOwnSh->SetFlyPos( m_aAbsPos );
+ m_bAbsPos = false;
+ }
+}
+
+// change existing Fly-Frame
+void SwFlyFrameAttrMgr::UpdateFlyFrame()
+{
+ OSL_ENSURE( m_pOwnSh->IsFrameSelected(),
+ "no frame selected or no shell, update not possible");
+
+ if( m_pOwnSh->IsFrameSelected() )
+ {
+ //JP 6.8.2001: set never an invalid anchor into the core.
+ const SfxPoolItem *pGItem, *pItem;
+ if( SfxItemState::SET == m_aSet.GetItemState( RES_ANCHOR, false, &pItem ))
+ {
+ SfxItemSet aGetSet( *m_aSet.GetPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} );
+ if( m_pOwnSh->GetFlyFrameAttr( aGetSet ) && 1 == aGetSet.Count() &&
+ SfxItemState::SET == aGetSet.GetItemState( RES_ANCHOR, false, &pGItem )
+ && static_cast<const SwFormatAnchor*>(pGItem)->GetAnchorId() ==
+ static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId() )
+ m_aSet.ClearItem( RES_ANCHOR );
+ }
+
+ // return wg. BASIC
+ if( m_aSet.Count() )
+ {
+ m_pOwnSh->StartAllAction();
+ m_pOwnSh->SetFlyFrameAttr( m_aSet );
+ UpdateFlyFrame_();
+ m_pOwnSh->EndAllAction();
+ }
+ }
+}
+
+// insert frame
+void SwFlyFrameAttrMgr::InsertFlyFrame()
+{
+ m_pOwnSh->StartAllAction();
+
+ bool bRet = nullptr != m_pOwnSh->NewFlyFrame( m_aSet );
+
+ // turn on the right mode at the shell, frame got selected automatically.
+ if ( bRet )
+ {
+ UpdateFlyFrame_();
+ m_pOwnSh->EnterSelFrameMode();
+ FrameNotify(m_pOwnSh, FLY_DRAG_START);
+ }
+ m_pOwnSh->EndAllAction();
+}
+
+// Insert frames of type eAnchorType. Position and size are being set explicitly.
+// Not-allowed values of the enumeration type get corrected.
+void SwFlyFrameAttrMgr::InsertFlyFrame(RndStdIds eAnchorType,
+ const Point &rPos,
+ const Size &rSize )
+{
+ OSL_ENSURE( eAnchorType == RndStdIds::FLY_AT_PAGE ||
+ eAnchorType == RndStdIds::FLY_AT_PARA ||
+ eAnchorType == RndStdIds::FLY_AT_CHAR ||
+ eAnchorType == RndStdIds::FLY_AT_FLY ||
+ eAnchorType == RndStdIds::FLY_AS_CHAR, "invalid frame type" );
+
+ SetPos( rPos );
+
+ SetSize( rSize );
+ SetAnchor( eAnchorType );
+ InsertFlyFrame();
+}
+
+// set anchor
+void SwFlyFrameAttrMgr::SetAnchor( RndStdIds eId )
+{
+ sal_uInt16 nPhyPageNum, nVirtPageNum;
+ m_pOwnSh->GetPageNum( nPhyPageNum, nVirtPageNum );
+
+ m_aSet.Put( SwFormatAnchor( eId, nPhyPageNum ) );
+ if ((RndStdIds::FLY_AT_PAGE == eId) || (RndStdIds::FLY_AT_PARA == eId) || (RndStdIds::FLY_AT_CHAR == eId)
+ || (RndStdIds::FLY_AT_FLY == eId))
+ {
+ SwFormatVertOrient aVertOrient( GetVertOrient() );
+ SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
+ aHoriOrient.SetRelationOrient( text::RelOrientation::FRAME );
+ aVertOrient.SetRelationOrient( text::RelOrientation::FRAME );
+ m_aSet.Put( aVertOrient );
+ m_aSet.Put( aHoriOrient );
+ }
+}
+
+// set the attribute for columns
+void SwFlyFrameAttrMgr::SetCol( const SwFormatCol &rCol )
+{
+ m_aSet.Put( rCol );
+}
+
+// set absolute position
+void SwFlyFrameAttrMgr::SetAbsPos( const Point& rPoint )
+{
+ m_bAbsPos = true;
+ m_aAbsPos = rPoint;
+ SwFormatVertOrient aVertOrient( GetVertOrient() );
+ SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
+ aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
+ aVertOrient.SetVertOrient( text::VertOrientation::NONE );
+ m_aSet.Put( aVertOrient );
+ m_aSet.Put( aHoriOrient );
+}
+
+// check metrics for correctness
+void SwFlyFrameAttrMgr::ValidateMetrics( SvxSwFrameValidation& rVal,
+ const SwPosition* pToCharContentPos,
+ bool bOnlyPercentRefValue )
+{
+ if (!bOnlyPercentRefValue)
+ {
+ rVal.nMinHeight = MINFLY + CalcTopSpace() + CalcBottomSpace();
+ rVal.nMinWidth = MINFLY + CalcLeftSpace()+ CalcRightSpace();
+ }
+
+ SwRect aBoundRect;
+
+ // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
+ // aligned to page for fly frame anchored to paragraph or to character.
+ const RndStdIds eAnchorType = rVal.nAnchorType;
+ const SwFormatFrameSize& rSize = m_aSet.Get(RES_FRM_SIZE);
+ m_pOwnSh->CalcBoundRect( aBoundRect, eAnchorType,
+ rVal.nHRelOrient,
+ rVal.nVRelOrient,
+ pToCharContentPos,
+ rVal.bFollowTextFlow,
+ rVal.bMirror, nullptr, &rVal.aPercentSize,
+ &rSize);
+
+ if (bOnlyPercentRefValue)
+ return;
+
+ // #mongolianlayout#
+ if ( m_bIsInVertical || m_bIsInVerticalL2R )
+ {
+ Point aPos(aBoundRect.Pos());
+ long nTmp = aPos.X();
+ aPos.setX( aPos.Y() );
+ aPos.setY( nTmp );
+ Size aSize(aBoundRect.SSize());
+ nTmp = aSize.Width();
+ aSize.setWidth( aSize.Height() );
+ aSize.setHeight( nTmp );
+ aBoundRect.Chg( aPos, aSize );
+ //exchange width/height to enable correct values
+ nTmp = rVal.nWidth;
+ rVal.nWidth = rVal.nHeight;
+ rVal.nHeight = nTmp;
+ }
+ if ((eAnchorType == RndStdIds::FLY_AT_PAGE) || (eAnchorType == RndStdIds::FLY_AT_FLY))
+ {
+ // MinimalPosition
+ rVal.nMinHPos = aBoundRect.Left();
+ rVal.nMinVPos = aBoundRect.Top();
+ SwTwips nH = rVal.nHPos;
+ SwTwips nV = rVal.nVPos;
+
+ if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
+ {
+ if (rVal.nHoriOrient == text::HoriOrientation::NONE)
+ {
+ rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
+ nH = rVal.nHPos;
+ }
+ else
+ rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
+ }
+
+ if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
+ rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
+
+ if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
+ {
+ if (rVal.nVertOrient == text::VertOrientation::NONE)
+ {
+ rVal.nVPos -= ((rVal.nVPos + rVal.nHeight) - aBoundRect.Bottom());
+ nV = rVal.nVPos;
+ }
+ else
+ rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
+ }
+
+ if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
+ rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
+
+ if ( rVal.nVertOrient != text::VertOrientation::NONE )
+ nV = aBoundRect.Top();
+
+ if ( rVal.nHoriOrient != text::HoriOrientation::NONE )
+ nH = aBoundRect.Left();
+
+ rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
+ rVal.nMaxHeight = aBoundRect.Bottom() - nV;
+
+ rVal.nMaxVPos = aBoundRect.Bottom() - rVal.nHeight;
+ rVal.nMaxWidth = aBoundRect.Right() - nH;
+ }
+ // OD 12.11.2003 #i22341# - handle to character anchored objects vertical
+ // aligned at character or top of line in a special case
+ else if ((eAnchorType == RndStdIds::FLY_AT_PARA) ||
+ ((eAnchorType == RndStdIds::FLY_AT_CHAR) &&
+ (rVal.nVRelOrient != text::RelOrientation::CHAR) &&
+ (rVal.nVRelOrient != text::RelOrientation::TEXT_LINE) ) )
+ {
+ if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
+ {
+ if (rVal.nHoriOrient == text::HoriOrientation::NONE)
+ {
+ rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
+ }
+ else
+ rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
+ }
+
+ // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
+ // and alignment at page areas.
+ const bool bMaxVPosAtBottom = !rVal.bFollowTextFlow ||
+ rVal.nVRelOrient == text::RelOrientation::PAGE_FRAME ||
+ rVal.nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
+ {
+ SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
+ ? aBoundRect.Bottom()
+ : aBoundRect.Height() ) -
+ rVal.nHeight;
+ if ( rVal.nVPos > nTmpMaxVPos )
+ {
+ if (rVal.nVertOrient == text::VertOrientation::NONE)
+ {
+ rVal.nVPos = nTmpMaxVPos;
+ }
+ else
+ {
+ rVal.nHeight = ( bMaxVPosAtBottom
+ ? aBoundRect.Bottom()
+ : aBoundRect.Height() ) - rVal.nVPos;
+ }
+ }
+ }
+
+ rVal.nMinHPos = aBoundRect.Left();
+ rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
+
+ rVal.nMinVPos = aBoundRect.Top();
+ // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
+ if ( bMaxVPosAtBottom )
+ {
+ rVal.nMaxVPos = aBoundRect.Bottom() - rVal.nHeight;
+ }
+ else
+ {
+ rVal.nMaxVPos = aBoundRect.Height() - rVal.nHeight;
+ }
+
+ // maximum width height
+ const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
+ ? aBoundRect.Left()
+ : rVal.nHPos;
+ const SwTwips nV = ( rVal.nVertOrient != text::VertOrientation::NONE )
+ ? aBoundRect.Top()
+ : rVal.nVPos;
+ rVal.nMaxHeight = rVal.nMaxVPos + rVal.nHeight - nV;
+ rVal.nMaxWidth = rVal.nMaxHPos + rVal.nWidth - nH;
+ }
+ // OD 12.11.2003 #i22341# - special case for to character anchored objects
+ // vertical aligned at character or top of line.
+ // Note: (1) positive vertical values are positions above the top of line
+ // (2) negative vertical values are positions below the top of line
+ else if ( (eAnchorType == RndStdIds::FLY_AT_CHAR) &&
+ ( rVal.nVRelOrient == text::RelOrientation::CHAR ||
+ rVal.nVRelOrient == text::RelOrientation::TEXT_LINE ) )
+ {
+ // determine horizontal values
+ rVal.nMinHPos = aBoundRect.Left();
+
+ rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
+ if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
+ {
+ if (rVal.nHoriOrient == text::HoriOrientation::NONE)
+ {
+ rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
+ }
+ else
+ rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
+ }
+
+ const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
+ ? aBoundRect.Left()
+ : rVal.nHPos;
+ rVal.nMaxWidth = rVal.nMaxHPos + rVal.nWidth - nH;
+
+ // determine vertical values
+ rVal.nMinVPos = -( aBoundRect.Bottom() - rVal.nHeight );
+ if ( rVal.nVPos < rVal.nMinVPos &&
+ rVal.nVertOrient == text::VertOrientation::NONE )
+ {
+ rVal.nVPos = rVal.nMinVPos;
+ }
+
+ rVal.nMaxVPos = -aBoundRect.Top();
+ if ( rVal.nVPos > rVal.nMaxVPos &&
+ rVal.nVertOrient == text::VertOrientation::NONE )
+ {
+ rVal.nVPos = rVal.nMaxVPos;
+ }
+
+ if ( rVal.nVertOrient == text::VertOrientation::NONE )
+ {
+ rVal.nMaxHeight = aBoundRect.Bottom() + rVal.nVPos;
+ }
+ else
+ {
+ rVal.nMaxHeight = aBoundRect.Height();
+ }
+ }
+ else if ( eAnchorType == RndStdIds::FLY_AS_CHAR )
+ {
+ rVal.nMinHPos = 0;
+ rVal.nMaxHPos = 0;
+
+ rVal.nMaxHeight = aBoundRect.Height();
+ rVal.nMaxWidth = aBoundRect.Width();
+
+ rVal.nMaxVPos = aBoundRect.Height();
+ rVal.nMinVPos = -aBoundRect.Height() + rVal.nHeight;
+ if (rVal.nMaxVPos < rVal.nMinVPos)
+ {
+ rVal.nMinVPos = rVal.nMaxVPos;
+ rVal.nMaxVPos = -aBoundRect.Height();
+ }
+ }
+ // #mongolianlayout#
+ if ( m_bIsInVertical || m_bIsInVerticalL2R )
+ {
+ //restore width/height exchange
+ long nTmp = rVal.nWidth;
+ rVal.nWidth = rVal.nHeight;
+ rVal.nHeight = nTmp;
+ }
+
+ if (rVal.nMaxWidth < rVal.nWidth)
+ rVal.nWidth = rVal.nMaxWidth;
+ if (rVal.nMaxHeight < rVal.nHeight)
+ rVal.nHeight = rVal.nMaxHeight;
+}
+
+// correction for border
+SwTwips SwFlyFrameAttrMgr::CalcTopSpace()
+{
+ const SvxShadowItem& rShadow = GetShadow();
+ const SvxBoxItem& rBox = GetBox();
+ return rShadow.CalcShadowSpace(SvxShadowItemSide::TOP ) + rBox.CalcLineSpace(SvxBoxItemLine::TOP);
+}
+
+SwTwips SwFlyFrameAttrMgr::CalcBottomSpace()
+{
+ const SvxShadowItem& rShadow = GetShadow();
+ const SvxBoxItem& rBox = GetBox();
+ return rShadow.CalcShadowSpace(SvxShadowItemSide::BOTTOM) + rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
+}
+
+SwTwips SwFlyFrameAttrMgr::CalcLeftSpace()
+{
+ const SvxShadowItem& rShadow = GetShadow();
+ const SvxBoxItem& rBox = GetBox();
+ return rShadow.CalcShadowSpace(SvxShadowItemSide::LEFT) + rBox.CalcLineSpace(SvxBoxItemLine::LEFT);
+}
+
+SwTwips SwFlyFrameAttrMgr::CalcRightSpace()
+{
+ const SvxShadowItem& rShadow = GetShadow();
+ const SvxBoxItem& rBox = GetBox();
+ return rShadow.CalcShadowSpace(SvxShadowItemSide::RIGHT) + rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
+}
+
+// erase attribute from the set
+void SwFlyFrameAttrMgr::DelAttr( sal_uInt16 nId )
+{
+ m_aSet.ClearItem( nId );
+}
+
+void SwFlyFrameAttrMgr::SetLRSpace( long nLeft, long nRight )
+{
+ OSL_ENSURE( LONG_MAX != nLeft && LONG_MAX != nRight, "Which border to set?" );
+
+ SvxLRSpaceItem aTmp( m_aSet.Get( RES_LR_SPACE ) );
+ if( LONG_MAX != nLeft )
+ aTmp.SetLeft( sal_uInt16(nLeft) );
+ if( LONG_MAX != nRight )
+ aTmp.SetRight( sal_uInt16(nRight) );
+ m_aSet.Put( aTmp );
+}
+
+void SwFlyFrameAttrMgr::SetULSpace( long nTop, long nBottom )
+{
+ OSL_ENSURE(LONG_MAX != nTop && LONG_MAX != nBottom, "Which border to set?" );
+
+ SvxULSpaceItem aTmp( m_aSet.Get( RES_UL_SPACE ) );
+ if( LONG_MAX != nTop )
+ aTmp.SetUpper( sal_uInt16(nTop) );
+ if( LONG_MAX != nBottom )
+ aTmp.SetLower( sal_uInt16(nBottom) );
+ m_aSet.Put( aTmp );
+}
+
+void SwFlyFrameAttrMgr::SetPos( const Point& rPoint )
+{
+ SwFormatVertOrient aVertOrient( GetVertOrient() );
+ SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
+
+ aHoriOrient.SetPos ( rPoint.X() );
+ aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
+
+ aVertOrient.SetPos ( rPoint.Y() );
+ aVertOrient.SetVertOrient( text::VertOrientation::NONE );
+
+ m_aSet.Put( aVertOrient );
+ m_aSet.Put( aHoriOrient );
+}
+
+void SwFlyFrameAttrMgr::SetHorzOrientation( sal_Int16 eOrient )
+{
+ SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
+ aHoriOrient.SetHoriOrient( eOrient );
+ m_aSet.Put( aHoriOrient );
+}
+
+void SwFlyFrameAttrMgr::SetVertOrientation( sal_Int16 eOrient )
+{
+ SwFormatVertOrient aVertOrient( GetVertOrient() );
+ aVertOrient.SetVertOrient( eOrient );
+ m_aSet.Put( aVertOrient );
+}
+
+void SwFlyFrameAttrMgr::SetHeightSizeType( SwFrameSize eType )
+{
+ SwFormatFrameSize aSize( GetFrameSize() );
+ aSize.SetHeightSizeType( eType );
+ m_aSet.Put( aSize );
+}
+
+void SwFlyFrameAttrMgr::SetRotation(sal_uInt16 nOld, sal_uInt16 nNew, const Size& rUnrotatedSize)
+{
+ // RotGrfFlyFrame: Central handling of real change of rotation here, all adaptations use this.
+ // Adaptation of pos/size may be wanted in the future. Already tried to keep last Size in
+ // UnrotatedSize in the SwRotationGrf Item, but this will lead to various problems. Also tried
+ // to use m_aSet.Put(...) as in other methods (also tried read methods for Rotation/UnrotatedSize) but
+ // somehow the needed ID (RES_GRFATR_ROTATION) is *not* in the SfxItemSet of the Frame, so for
+ // now set directly. Undo/Redo is preserved by AttributeChange
+ if(nOld != nNew)
+ {
+ m_pOwnSh->SetAttrItem(SwRotationGrf(nNew, rUnrotatedSize));
+ }
+}
+
+void SwFlyFrameAttrMgr::SetSize( const Size& rSize )
+{
+ SwFormatFrameSize aSize( GetFrameSize() );
+ aSize.SetSize(Size(std::max(rSize.Width(), long(MINFLY)), std::max(rSize.Height(), long(MINFLY))));
+ m_aSet.Put( aSize );
+}
+
+void SwFlyFrameAttrMgr::SetAttrSet(const SfxItemSet& rSet)
+{
+ m_aSet.ClearItem();
+ m_aSet.Put( rSet );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */