diff options
Diffstat (limited to 'editeng/source/editeng/impedit.cxx')
-rw-r--r-- | editeng/source/editeng/impedit.cxx | 1269 |
1 files changed, 670 insertions, 599 deletions
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 4f0f4ccac865..94d707cf902e 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -22,6 +22,7 @@ #include <editeng/editeng.hxx> #include <editeng/editview.hxx> #include <editeng/outliner.hxx> +#include <editeng/urlfieldhelper.hxx> #include <tools/poly.hxx> #include <editeng/unolingu.hxx> #include <com/sun/star/linguistic2/XDictionary.hpp> @@ -36,6 +37,7 @@ #include <vcl/transfer.hxx> #include <vcl/svapp.hxx> #include <vcl/weldutils.hxx> +#include <vcl/window.hxx> #include <sot/exchange.hxx> #include <sot/formats.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -44,22 +46,20 @@ #include <sfx2/lokhelper.hxx> #include <boost/property_tree/ptree.hpp> -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::linguistic2; +using namespace css; #define SCRLRANGE 20 // Scroll 1/20 of the width/height, when in QueryDrop -static void lcl_AllignToPixel( Point& rPoint, OutputDevice const * pOutDev, short nDiffX, short nDiffY ) +static void lcl_AlignToPixel(Point& rPoint, const OutputDevice& rOutDev, short nDiffX, short nDiffY) { - rPoint = pOutDev->LogicToPixel( rPoint ); + rPoint = rOutDev.LogicToPixel( rPoint ); if ( nDiffX ) rPoint.AdjustX(nDiffX ); if ( nDiffY ) rPoint.AdjustY(nDiffY ); - rPoint = pOutDev->PixelToLogic( rPoint ); + rPoint = rOutDev.PixelToLogic( rPoint ); } LOKSpecialPositioning::LOKSpecialPositioning(const ImpEditView& rImpEditView, MapUnit eUnit, @@ -68,7 +68,8 @@ LOKSpecialPositioning::LOKSpecialPositioning(const ImpEditView& rImpEditView, Ma mrImpEditView(rImpEditView), maOutArea(rOutputArea), maVisDocStartPos(rVisDocStartPos), - meUnit(eUnit) + meUnit(eUnit), + meFlags(LOKSpecialFlags::NONE) { } @@ -177,30 +178,30 @@ Point LOKSpecialPositioning::GetRefPoint() const // class ImpEditView -ImpEditView::ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindow ) : - pEditView(pView), - mpViewShell(nullptr), - mpOtherShell(nullptr), - pEditEngine(pEng), - pOutWin(pWindow), - nInvMore(1), - nControl(EVControlBits::AUTOSCROLL | EVControlBits::ENABLEPASTE), - nTravelXPos(TRAVEL_X_DONTKNOW), - nExtraCursorFlags(GetCursorFlags::NONE), - nCursorBidiLevel(CURSOR_BIDILEVEL_DONTKNOW), - nScrollDiffX(0), - bReadOnly(false), - bClickedInSelection(false), - bActiveDragAndDropListener(false), - aOutArea( Point(), pEng->GetPaperSize() ), - eSelectionMode(EESelectionMode::Std), - eAnchorMode(EEAnchorMode::TopLeft), - mpEditViewCallbacks(nullptr), - mbBroadcastLOKViewCursor(comphelper::LibreOfficeKit::isActive()), - mbSuppressLOKMessages(false) -{ - aEditSelection.Min() = pEng->GetEditDoc().GetStartPaM(); - aEditSelection.Max() = pEng->GetEditDoc().GetEndPaM(); +ImpEditView::ImpEditView(EditView* pView, EditEngine* pEditEngine, vcl::Window* pWindow) + : mpEditView(pView) + , mpViewShell(nullptr) + , mpOtherShell(nullptr) + , mpEditEngine(pEditEngine) + , mpOutputWindow(pWindow) + , mnInvalidateMore(1) + , mnControl(EVControlBits::AUTOSCROLL | EVControlBits::ENABLEPASTE) + , mnTravelXPos(TRAVEL_X_DONTKNOW) + , mnCursorBidiLevel(CURSOR_BIDILEVEL_DONTKNOW) + , mnScrollDiffX(0) + , mbReadOnly(false) + , mbClickedInSelection(false) + , mbActiveDragAndDropListener(false) + , maOutputArea(Point(), mpEditEngine->GetPaperSize()) + , meSelectionMode(EESelectionMode::Std) + , meAnchorMode(EEAnchorMode::TopLeft) + , mpEditViewCallbacks(nullptr) + , mbBroadcastLOKViewCursor(comphelper::LibreOfficeKit::isActive()) + , mbSuppressLOKMessages(false) + , mbNegativeX(false) +{ + maEditSelection.Min() = mpEditEngine->GetEditDoc().GetStartPaM(); + maEditSelection.Max() = mpEditEngine->GetEditDoc().GetEndPaM(); SelectionChanged(); } @@ -209,8 +210,8 @@ ImpEditView::~ImpEditView() { RemoveDragAndDropListeners(); - if ( pOutWin && ( pOutWin->GetCursor() == pCursor.get() ) ) - pOutWin->SetCursor( nullptr ); + if (mpOutputWindow && (mpOutputWindow->GetCursor() == mpCursor.get())) + mpOutputWindow->SetCursor( nullptr ); } void ImpEditView::SetBackgroundColor( const Color& rColor ) @@ -218,6 +219,11 @@ void ImpEditView::SetBackgroundColor( const Color& rColor ) mxBackgroundColor = rColor; } +const Color& ImpEditView::GetBackgroundColor() const +{ + return mxBackgroundColor ? *mxBackgroundColor : GetOutputDevice().GetBackground().GetColor(); +} + void ImpEditView::RegisterViewShell(OutlinerViewShell* pViewShell) { mpViewShell = pViewShell; @@ -236,17 +242,19 @@ const OutlinerViewShell* ImpEditView::GetViewShell() const void ImpEditView::SetEditSelection( const EditSelection& rEditSelection ) { // set state before notification - aEditSelection = rEditSelection; + maEditSelection = rEditSelection; SelectionChanged(); if (comphelper::LibreOfficeKit::isActive()) + { // Tiled rendering: selections are only painted when we are in selection mode. - pEditEngine->SetInSelectionMode(aEditSelection.HasRange()); + getEditEngine().SetInSelectionMode(maEditSelection.HasRange()); + } - if ( pEditEngine->pImpEditEngine->GetNotifyHdl().IsSet() ) + if (getImpEditEngine().GetNotifyHdl().IsSet() ) { - const EditDoc& rDoc = pEditEngine->GetEditDoc(); + const EditDoc& rDoc = getEditEngine().GetEditDoc(); const EditPaM pmEnd = rDoc.GetEndPaM(); EENotifyType eNotifyType; if (rDoc.Count() > 1 && @@ -260,17 +268,18 @@ void ImpEditView::SetEditSelection( const EditSelection& rEditSelection ) eNotifyType = EE_NOTIFY_TEXTVIEWSELECTIONCHANGED; } EENotify aNotify( eNotifyType ); - pEditEngine->pImpEditEngine->GetNotifyHdl().Call( aNotify ); + getImpEditEngine().GetNotifyHdl().Call( aNotify ); } - if(pEditEngine->pImpEditEngine->IsFormatted()) + + if (getImpEditEngine().IsFormatted()) { EENotify aNotify(EE_NOTIFY_PROCESSNOTIFICATIONS); - pEditEngine->pImpEditEngine->GetNotifyHdl().Call(aNotify); + getImpEditEngine().GetNotifyHdl().Call(aNotify); } } /// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input. -static void lcl_translateTwips(vcl::Window const & rParent, vcl::Window& rChild) +static void lcl_translateTwips(const OutputDevice& rParent, OutputDevice& rChild) { // Don't translate if we already have a non-zero origin. // This prevents multiple translate calls that negate @@ -313,14 +322,14 @@ void ImpEditView::SelectionChanged() } // This function is also called when a text's font || size is changed. Because its highlight rectangle must be updated. -void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible) { - VclPtr<vcl::Window> pParent = pOutWin->GetParentWithLOKNotifier(); +void ImpEditView::lokSelectionCallback(const std::optional<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible) { + VclPtr<vcl::Window> pParent = mpOutputWindow->GetParentWithLOKNotifier(); vcl::Region aRegion( *pPolyPoly ); if (pParent && pParent->GetLOKWindowId() != 0) { - const tools::Long nX = pOutWin->GetOutOffXPixel() - pParent->GetOutOffXPixel(); - const tools::Long nY = pOutWin->GetOutOffYPixel() - pParent->GetOutOffYPixel(); + const tools::Long nX = mpOutputWindow->GetOutOffXPixel() - pParent->GetOutOffXPixel(); + const tools::Long nY = mpOutputWindow->GetOutOffYPixel() - pParent->GetOutOffYPixel(); std::vector<tools::Rectangle> aRectangles; aRegion.GetRegionRectangles(aRectangles); @@ -328,7 +337,7 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> std::vector<OString> v; for (tools::Rectangle & rRectangle : aRectangles) { - rRectangle = pOutWin->LogicToPixel(rRectangle); + rRectangle = mpOutputWindow->LogicToPixel(rRectangle); rRectangle.Move(nX, nY); v.emplace_back(rRectangle.toString().getStr()); } @@ -341,34 +350,33 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> aItems.emplace_back("endHandleVisible", OString::boolean(bEndHandleVisible)); pNotifier->notifyWindow(pParent->GetLOKWindowId(), "text_selection", aItems); } - else + else if (mpViewShell) { - pOutWin->Push(PushFlags::MAPMODE); - if (pOutWin->GetMapMode().GetMapUnit() == MapUnit::MapTwip) + mpOutputWindow->GetOutDev()->Push(vcl::PushFlags::MAPMODE); + if (mpOutputWindow->GetMapMode().GetMapUnit() == MapUnit::MapTwip) { // Find the parent that is not right // on top of us to use its offset. - vcl::Window* parent = pOutWin->GetParent(); + vcl::Window* parent = mpOutputWindow->GetParent(); while (parent && - parent->GetOutOffXPixel() == pOutWin->GetOutOffXPixel() && - parent->GetOutOffYPixel() == pOutWin->GetOutOffYPixel()) + parent->GetOutOffXPixel() == mpOutputWindow->GetOutOffXPixel() && + parent->GetOutOffYPixel() == mpOutputWindow->GetOutOffYPixel()) { parent = parent->GetParent(); } if (parent) { - lcl_translateTwips(*parent, *pOutWin); + lcl_translateTwips(*parent->GetOutDev(), *mpOutputWindow->GetOutDev()); } } - bool bMm100ToTwip = !mpLOKSpecialPositioning && - (pOutWin->GetMapMode().GetMapUnit() == MapUnit::Map100thMM); + bool bMm100ToTwip = !mpLOKSpecialPositioning && (mpOutputWindow->GetMapMode().GetMapUnit() == MapUnit::Map100thMM); Point aOrigin; - if (pOutWin->GetMapMode().GetMapUnit() == MapUnit::MapTwip) + if (mpOutputWindow->GetMapMode().GetMapUnit() == MapUnit::MapTwip) // Writer comments: they use editeng, but are separate widgets. - aOrigin = pOutWin->GetMapMode().GetOrigin(); + aOrigin = mpOutputWindow->GetMapMode().GetOrigin(); OString sRectangle; OString sRefPoint; @@ -380,13 +388,13 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> if (!aRectangles.empty()) { - if (pOutWin->IsChart()) + if (mpOutputWindow->IsChart()) { const vcl::Window* pViewShellWindow = mpViewShell->GetEditWindowForActiveOLEObj(); - if (pViewShellWindow && pViewShellWindow->IsAncestorOf(*pOutWin)) + if (pViewShellWindow && pViewShellWindow->IsAncestorOf(*mpOutputWindow)) { - Point aOffsetPx = pOutWin->GetOffsetPixelFrom(*pViewShellWindow); - Point aLogicOffset = pOutWin->PixelToLogic(aOffsetPx); + Point aOffsetPx = mpOutputWindow->GetOffsetPixelFrom(*pViewShellWindow); + Point aLogicOffset = mpOutputWindow->PixelToLogic(aOffsetPx); for (tools::Rectangle& rRect : aRectangles) rRect.Move(aLogicOffset.getX(), aLogicOffset.getY()); } @@ -396,7 +404,9 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> for (tools::Rectangle & rRectangle : aRectangles) { if (bMm100ToTwip) - rRectangle = OutputDevice::LogicToLogic(rRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + { + rRectangle = o3tl::convert(rRectangle, o3tl::Length::mm100, o3tl::Length::twip); + } rRectangle.Move(aOrigin.getX(), aOrigin.getY()); v.emplace_back(rRectangle.toString().getStr()); } @@ -412,7 +422,7 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> if (mpLOKSpecialPositioning) aPayload += ":: " + sRefPoint; - mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_START, aPayload.getStr()); + mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_START, aPayload); tools::Rectangle& rEnd = aRectangles.back(); tools::Rectangle aEnd(rEnd.Right() - 1, rEnd.Top(), rEnd.Right(), rEnd.Bottom()); @@ -421,22 +431,22 @@ void ImpEditView::lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> if (mpLOKSpecialPositioning) aPayload += ":: " + sRefPoint; - mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_END, aPayload.getStr()); + mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_END, aPayload); } if (mpOtherShell) { // Another shell wants to know about our existing selection. if (mpViewShell != mpOtherShell) - mpViewShell->NotifyOtherView(mpOtherShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRectangle); + mpViewShell->NotifyOtherView(mpOtherShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection"_ostr, sRectangle); } else { - mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle.getStr()); - mpViewShell->NotifyOtherViews(LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRectangle); + mpViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle); + mpViewShell->NotifyOtherViews(LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection"_ostr, sRectangle); } - pOutWin->Pop(); + mpOutputWindow->GetOutDev()->Pop(); } } @@ -461,7 +471,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, return; } - if ( eSelectionMode == EESelectionMode::Hidden ) + if (meSelectionMode == EESelectionMode::Hidden) return; // It must be ensured before rendering the selection, that the contents of @@ -472,21 +482,17 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, // pRegion: When not NULL, then only calculate Region. - OutputDevice* pTarget; - if (pTargetDevice) - pTarget = pTargetDevice; - else - pTarget = getEditViewCallbacks() ? &getEditViewCallbacks()->EditViewOutputDevice() : pOutWin; - bool bClipRegion = pTarget->IsClipRegion(); - vcl::Region aOldRegion = pTarget->GetClipRegion(); + OutputDevice& rTarget = pTargetDevice ? *pTargetDevice : GetOutputDevice(); + bool bClipRegion = rTarget.IsClipRegion(); + vcl::Region aOldRegion = rTarget.GetClipRegion(); - std::unique_ptr<tools::PolyPolygon> pPolyPoly; + std::optional<tools::PolyPolygon> pPolyPoly; if ( !pRegion && !comphelper::LibreOfficeKit::isActive()) { - if ( !pEditEngine->pImpEditEngine->GetUpdateMode() ) + if (!getImpEditEngine().IsUpdateLayout()) return; - if ( pEditEngine->pImpEditEngine->IsInUndo() ) + if (getImpEditEngine().IsInUndo()) return; if ( !aTmpSel.HasRange() ) @@ -494,134 +500,140 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, // aTmpOutArea: if OutputArea > Paper width and // Text > Paper width ( over large fields ) - tools::Rectangle aTmpOutArea( aOutArea ); - if ( aTmpOutArea.GetWidth() > pEditEngine->pImpEditEngine->GetPaperSize().Width() ) - aTmpOutArea.SetRight( aTmpOutArea.Left() + pEditEngine->pImpEditEngine->GetPaperSize().Width() ); - pTarget->IntersectClipRegion( aTmpOutArea ); + tools::Rectangle aTmpOutArea(maOutputArea); + if ( aTmpOutArea.GetWidth() > getImpEditEngine().GetPaperSize().Width() ) + aTmpOutArea.SetRight( aTmpOutArea.Left() + getImpEditEngine().GetPaperSize().Width() ); + rTarget.IntersectClipRegion( aTmpOutArea ); - if (pOutWin && pOutWin->GetCursor()) - pOutWin->GetCursor()->Hide(); + if (mpOutputWindow && mpOutputWindow->GetCursor()) + mpOutputWindow->GetCursor()->Hide(); } if (comphelper::LibreOfficeKit::isActive() || pRegion) - pPolyPoly.reset(new tools::PolyPolygon); + pPolyPoly = tools::PolyPolygon(); - DBG_ASSERT( !pEditEngine->IsIdleFormatterActive(), "DrawSelectionXOR: Not formatted!" ); - aTmpSel.Adjust( pEditEngine->GetEditDoc() ); + DBG_ASSERT(!getEditEngine().IsIdleFormatterActive(), "DrawSelectionXOR: Not formatted!"); + aTmpSel.Adjust(getEditEngine().GetEditDoc()); ContentNode* pStartNode = aTmpSel.Min().GetNode(); ContentNode* pEndNode = aTmpSel.Max().GetNode(); - const sal_Int32 nStartPara = pEditEngine->GetEditDoc().GetPos(pStartNode); - const sal_Int32 nEndPara = pEditEngine->GetEditDoc().GetPos(pEndNode); + const sal_Int32 nStartPara = getEditEngine().GetEditDoc().GetPos(pStartNode); + const sal_Int32 nEndPara = getEditEngine().GetEditDoc().GetPos(pEndNode); if (nStartPara == EE_PARA_NOT_FOUND || nEndPara == EE_PARA_NOT_FOUND) return; bool bStartHandleVisible = false; bool bEndHandleVisible = false; + bool bLOKCalcRTL = mpLOKSpecialPositioning && + (mpLOKSpecialPositioning->IsLayoutRTL() || getEditEngine().IsRightToLeft(nStartPara)); - for ( sal_Int32 nPara = nStartPara; nPara <= nEndPara; nPara++ ) - { - ParaPortion* pTmpPortion = pEditEngine->GetParaPortions().SafeGetObject( nPara ); - if (!pTmpPortion) + auto DrawHighlight = [&, nStartLine = sal_Int32(0), nEndLine = sal_Int32(0)]( + const ImpEditEngine::LineAreaInfo& rInfo) mutable { + if (!rInfo.pLine) // Begin of ParaPortion { - SAL_WARN( "editeng", "Portion in Selection not found!" ); - continue; - } - - DBG_ASSERT( !pTmpPortion->IsInvalid(), "Portion in Selection not formatted!" ); - - if ( !pTmpPortion->IsVisible() || pTmpPortion->IsInvalid() ) - continue; - - tools::Long nParaStart = pEditEngine->GetParaPortions().GetYOffset( pTmpPortion ); - if ( ( nParaStart + pTmpPortion->GetHeight() ) < GetVisDocTop() ) - continue; - if ( nParaStart > GetVisDocBottom() ) - break; - - sal_uInt16 nStartLine = 0; - sal_uInt16 nEndLine = pTmpPortion->GetLines().Count() -1; - if ( nPara == nStartPara ) - nStartLine = pTmpPortion->GetLines().FindLine( aTmpSel.Min().GetIndex(), false ); - if ( nPara == nEndPara ) - nEndLine = pTmpPortion->GetLines().FindLine( aTmpSel.Max().GetIndex(), true ); + if (rInfo.nPortion < nStartPara) + return ImpEditEngine::CallbackResult::SkipThisPortion; + if (rInfo.nPortion > nEndPara) + return ImpEditEngine::CallbackResult::Stop; + DBG_ASSERT(!rInfo.rPortion.IsInvalid(), "Portion in Selection not formatted!"); + if (rInfo.rPortion.IsInvalid()) + return ImpEditEngine::CallbackResult::SkipThisPortion; + + if (rInfo.nPortion == nStartPara) + nStartLine = rInfo.rPortion.GetLines().FindLine(aTmpSel.Min().GetIndex(), false); + else + nStartLine = 0; - for ( sal_uInt16 nLine = nStartLine; nLine <= nEndLine; nLine++ ) + if (rInfo.nPortion == nEndPara) + nEndLine = rInfo.rPortion.GetLines().FindLine(aTmpSel.Max().GetIndex(), true); + else + nEndLine = rInfo.rPortion.GetLines().Count() - 1; + } + else // This is a correct ParaPortion { - const EditLine& rLine = pTmpPortion->GetLines()[nLine]; + if (rInfo.nLine < nStartLine) + return ImpEditEngine::CallbackResult::Continue; + if (rInfo.nLine > nEndLine) + return ImpEditEngine::CallbackResult::SkipThisPortion; bool bPartOfLine = false; - sal_Int32 nStartIndex = rLine.GetStart(); - sal_Int32 nEndIndex = rLine.GetEnd(); - if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) && ( nStartIndex != aTmpSel.Min().GetIndex() ) ) + sal_Int32 nStartIndex = rInfo.pLine->GetStart(); + sal_Int32 nEndIndex = rInfo.pLine->GetEnd(); + if ((rInfo.nPortion == nStartPara) && (rInfo.nLine == nStartLine) + && (nStartIndex != aTmpSel.Min().GetIndex())) { nStartIndex = aTmpSel.Min().GetIndex(); bPartOfLine = true; } - if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) && ( nEndIndex != aTmpSel.Max().GetIndex() ) ) + if ((rInfo.nPortion == nEndPara) && (rInfo.nLine == nEndLine) + && (nEndIndex != aTmpSel.Max().GetIndex())) { nEndIndex = aTmpSel.Max().GetIndex(); bPartOfLine = true; } // Can happen if at the beginning of a wrapped line. - if ( nEndIndex < nStartIndex ) + if (nEndIndex < nStartIndex) nEndIndex = nStartIndex; - tools::Rectangle aTmpRect( pEditEngine->pImpEditEngine->GetEditCursor( pTmpPortion, nStartIndex ) ); - Point aTopLeft( aTmpRect.TopLeft() ); - Point aBottomRight( aTmpRect.BottomRight() ); - - aTopLeft.AdjustY(nParaStart ); - aBottomRight.AdjustY(nParaStart ); + tools::Rectangle aTmpRect(getImpEditEngine().GetEditCursor(rInfo.rPortion, *rInfo.pLine, nStartIndex, CursorFlags())); + const Size aLineOffset = getImpEditEngine().getTopLeftDocOffset(rInfo.aArea); + aTmpRect.Move(0, aLineOffset.Height()); // Only paint if in the visible range ... - if ( aTopLeft.Y() > GetVisDocBottom() ) - break; + if (aTmpRect.Top() > GetVisDocBottom()) + return ImpEditEngine::CallbackResult::Continue; - if ( aBottomRight.Y() < GetVisDocTop() ) - continue; + if (aTmpRect.Bottom() < GetVisDocTop()) + return ImpEditEngine::CallbackResult::Continue; - if ( ( nPara == nStartPara ) && ( nLine == nStartLine ) ) + if ((rInfo.nPortion == nStartPara) && (rInfo.nLine == nStartLine)) bStartHandleVisible = true; - if ( ( nPara == nEndPara ) && ( nLine == nEndLine ) ) + if ((rInfo.nPortion == nEndPara) && (rInfo.nLine == nEndLine)) bEndHandleVisible = true; // Now that we have Bidi, the first/last index doesn't have to be the 'most outside' position - if ( !bPartOfLine ) + if (!bPartOfLine) { - Range aLineXPosStartEnd = pEditEngine->GetLineXPosStartEnd(pTmpPortion, &rLine); - aTopLeft.setX( aLineXPosStartEnd.Min() ); - aBottomRight.setX( aLineXPosStartEnd.Max() ); - ImplDrawHighlightRect( pTarget, aTopLeft, aBottomRight, pPolyPoly.get() ); + Range aLineXPosStartEnd = getEditEngine().GetLineXPosStartEnd(rInfo.rPortion, *rInfo.pLine); + aTmpRect.SetLeft(aLineXPosStartEnd.Min()); + aTmpRect.SetRight(aLineXPosStartEnd.Max()); + aTmpRect.Move(aLineOffset.Width(), 0); + ImplDrawHighlightRect(rTarget, aTmpRect.TopLeft(), aTmpRect.BottomRight(), + pPolyPoly ? &*pPolyPoly : nullptr, bLOKCalcRTL); } else { sal_Int32 nTmpStartIndex = nStartIndex; sal_Int32 nWritingDirStart, nTmpEndIndex; - while ( nTmpStartIndex < nEndIndex ) + while (nTmpStartIndex < nEndIndex) { - pEditEngine->pImpEditEngine->GetRightToLeft( nPara, nTmpStartIndex+1, &nWritingDirStart, &nTmpEndIndex ); - if ( nTmpEndIndex > nEndIndex ) + getImpEditEngine().GetRightToLeft(rInfo.nPortion, nTmpStartIndex + 1, + &nWritingDirStart, &nTmpEndIndex); + if (nTmpEndIndex > nEndIndex) nTmpEndIndex = nEndIndex; - DBG_ASSERT( nTmpEndIndex > nTmpStartIndex, "DrawSelectionXOR, Start >= End?" ); + DBG_ASSERT(nTmpEndIndex > nTmpStartIndex, "DrawSelectionXOR, Start >= End?"); - tools::Long nX1 = pEditEngine->GetXPos(pTmpPortion, &rLine, nTmpStartIndex, true); - tools::Long nX2 = pEditEngine->GetXPos(pTmpPortion, &rLine, nTmpEndIndex); + tools::Long nX1 = getEditEngine().GetXPos(rInfo.rPortion, *rInfo.pLine, nTmpStartIndex, true); + tools::Long nX2 = getEditEngine().GetXPos(rInfo.rPortion, *rInfo.pLine, nTmpEndIndex); - Point aPt1( std::min( nX1, nX2 ), aTopLeft.Y() ); - Point aPt2( std::max( nX1, nX2 ), aBottomRight.Y() ); + aTmpRect.SetLeft(std::min(nX1, nX2)); + aTmpRect.SetRight(std::max(nX1, nX2)); + aTmpRect.Move(aLineOffset.Width(), 0); - ImplDrawHighlightRect( pTarget, aPt1, aPt2, pPolyPoly.get() ); + ImplDrawHighlightRect(rTarget, aTmpRect.TopLeft(), aTmpRect.BottomRight(), + pPolyPoly ? &*pPolyPoly : nullptr, bLOKCalcRTL); nTmpStartIndex = nTmpEndIndex; } } } - } + return ImpEditEngine::CallbackResult::Continue; + }; + getImpEditEngine().IterateLineAreas(DrawHighlight, ImpEditEngine::IterFlag::none); - if (comphelper::LibreOfficeKit::isActive() && mpViewShell && pOutWin) + if (comphelper::LibreOfficeKit::isActive() && mpViewShell && mpOutputWindow) lokSelectionCallback(pPolyPoly, bStartHandleVisible, bEndHandleVisible); if (pRegion || comphelper::LibreOfficeKit::isActive()) @@ -632,13 +644,13 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, } else { - if (pOutWin && pOutWin->GetCursor()) - pOutWin->GetCursor()->Show(); + if (mpOutputWindow && mpOutputWindow->GetCursor()) + mpOutputWindow->GetCursor()->Show(); - if ( bClipRegion ) - pTarget->SetClipRegion( aOldRegion ); + if (bClipRegion) + rTarget.SetClipRegion(aOldRegion); else - pTarget->SetClipRegion(); + rTarget.SetClipRegion(); } } @@ -649,18 +661,28 @@ void ImpEditView::GetSelectionRectangles(EditSelection aTmpSel, std::vector<tool aRegion.GetRegionRectangles(rLogicRects); } -void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly ) +void ImpEditView::ImplDrawHighlightRect( OutputDevice& rTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly, bool bLOKCalcRTL ) { if ( rDocPosTopLeft.X() == rDocPosBottomRight.X() ) return; if (mpLOKSpecialPositioning && pPolyPoly) { - MapUnit eDevUnit = _pTarget->GetMapMode().GetMapUnit(); + MapUnit eDevUnit = rTarget.GetMapMode().GetMapUnit(); tools::Rectangle aSelRect(rDocPosTopLeft, rDocPosBottomRight); - aSelRect = mpLOKSpecialPositioning->GetWindowPos(aSelRect, eDevUnit); - const Point aRefPoint = mpLOKSpecialPositioning->GetRefPoint(); - aSelRect.Move(-aRefPoint.X(), -aRefPoint.Y()); + aSelRect = GetWindowPos(aSelRect); + Point aRefPointLogical = GetOutputArea().TopLeft(); + // Get the relative coordinates w.r.t refpoint in display units. + aSelRect.Move(-aRefPointLogical.X(), -aRefPointLogical.Y()); + if (bLOKCalcRTL) + { + tools::Long nMirrorW = GetOutputArea().GetWidth(); + tools::Long nLeft = aSelRect.Left(), nRight = aSelRect.Right(); + aSelRect.SetLeft(nMirrorW - nRight); + aSelRect.SetRight(nMirrorW - nLeft); + } + // Convert from display unit to twips. + aSelRect = OutputDevice::LogicToLogic(aSelRect, MapMode(eDevUnit), MapMode(MapUnit::MapTwip)); tools::Polygon aTmpPoly(4); aTmpPoly[0] = aSelRect.TopLeft(); @@ -671,20 +693,20 @@ void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rD return; } - bool bPixelMode = _pTarget->GetMapMode().GetMapUnit() == MapUnit::MapPixel; + bool bPixelMode = rTarget.GetMapMode().GetMapUnit() == MapUnit::MapPixel; Point aPnt1( GetWindowPos( rDocPosTopLeft ) ); Point aPnt2( GetWindowPos( rDocPosBottomRight ) ); if ( !IsVertical() ) { - lcl_AllignToPixel( aPnt1, _pTarget, +1, 0 ); - lcl_AllignToPixel( aPnt2, _pTarget, 0, ( bPixelMode ? 0 : -1 ) ); + lcl_AlignToPixel(aPnt1, rTarget, +1, 0); + lcl_AlignToPixel(aPnt2, rTarget, 0, (bPixelMode ? 0 : -1)); } else { - lcl_AllignToPixel( aPnt1, _pTarget, 0, +1 ); - lcl_AllignToPixel( aPnt2, _pTarget, ( bPixelMode ? 0 : +1 ), 0 ); + lcl_AlignToPixel(aPnt1, rTarget, 0, +1 ); + lcl_AlignToPixel(aPnt2, rTarget, (bPixelMode ? 0 : +1), 0); } tools::Rectangle aRect( aPnt1, aPnt2 ); @@ -699,20 +721,20 @@ void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rD } else { - vcl::Window* pWindow = dynamic_cast< vcl::Window* >(_pTarget); + vcl::Window* pWindow = rTarget.GetOwnerWindow(); - if(pWindow) + if (pWindow) { - pWindow->Invert( aRect ); + pWindow->GetOutDev()->Invert( aRect ); } else { - _pTarget->Push(PushFlags::LINECOLOR|PushFlags::FILLCOLOR|PushFlags::RASTEROP); - _pTarget->SetLineColor(); - _pTarget->SetFillColor(COL_BLACK); - _pTarget->SetRasterOp(RasterOp::Invert); - _pTarget->DrawRect(aRect); - _pTarget->Pop(); + rTarget.Push(vcl::PushFlags::LINECOLOR|vcl::PushFlags::FILLCOLOR|vcl::PushFlags::RASTEROP); + rTarget.SetLineColor(); + rTarget.SetFillColor(COL_BLACK); + rTarget.SetRasterOp(RasterOp::Invert); + rTarget.DrawRect(aRect); + rTarget.Pop(); } } } @@ -720,12 +742,12 @@ void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rD bool ImpEditView::IsVertical() const { - return pEditEngine->pImpEditEngine->IsVertical(); + return getImpEditEngine().IsEffectivelyVertical(); } bool ImpEditView::IsTopToBottom() const { - return pEditEngine->pImpEditEngine->IsTopToBottom(); + return getImpEditEngine().IsTopToBottom(); } tools::Rectangle ImpEditView::GetVisDocArea() const @@ -738,22 +760,22 @@ Point ImpEditView::GetDocPos( const Point& rWindowPos ) const // Window Position => Position Document Point aPoint; - if ( !pEditEngine->pImpEditEngine->IsVertical() ) + if (!getImpEditEngine().IsEffectivelyVertical()) { - aPoint.setX( rWindowPos.X() - aOutArea.Left() + GetVisDocLeft() ); - aPoint.setY( rWindowPos.Y() - aOutArea.Top() + GetVisDocTop() ); + aPoint.setX( rWindowPos.X() - maOutputArea.Left() + GetVisDocLeft() ); + aPoint.setY( rWindowPos.Y() - maOutputArea.Top() + GetVisDocTop() ); } else { - if (pEditEngine->pImpEditEngine->IsTopToBottom()) + if (getImpEditEngine().IsTopToBottom()) { - aPoint.setX( rWindowPos.Y() - aOutArea.Top() + GetVisDocLeft() ); - aPoint.setY( aOutArea.Right() - rWindowPos.X() + GetVisDocTop() ); + aPoint.setX( rWindowPos.Y() - maOutputArea.Top() + GetVisDocLeft() ); + aPoint.setY( maOutputArea.Right() - rWindowPos.X() + GetVisDocTop() ); } else { - aPoint.setX( aOutArea.Bottom() - rWindowPos.Y() + GetVisDocLeft() ); - aPoint.setY( rWindowPos.X() - aOutArea.Left() + GetVisDocTop() ); + aPoint.setX( maOutputArea.Bottom() - rWindowPos.Y() + GetVisDocLeft() ); + aPoint.setY( rWindowPos.X() - maOutputArea.Left() + GetVisDocTop() ); } } @@ -765,22 +787,22 @@ Point ImpEditView::GetWindowPos( const Point& rDocPos ) const // Document position => window position Point aPoint; - if ( !pEditEngine->pImpEditEngine->IsVertical() ) + if (!getImpEditEngine().IsEffectivelyVertical()) { - aPoint.setX( rDocPos.X() + aOutArea.Left() - GetVisDocLeft() ); - aPoint.setY( rDocPos.Y() + aOutArea.Top() - GetVisDocTop() ); + aPoint.setX( rDocPos.X() + maOutputArea.Left() - GetVisDocLeft() ); + aPoint.setY( rDocPos.Y() + maOutputArea.Top() - GetVisDocTop() ); } else { - if (pEditEngine->pImpEditEngine->IsTopToBottom()) + if (getImpEditEngine().IsTopToBottom()) { - aPoint.setX( aOutArea.Right() - rDocPos.Y() + GetVisDocTop() ); - aPoint.setY( rDocPos.X() + aOutArea.Top() - GetVisDocLeft() ); + aPoint.setX( maOutputArea.Right() - rDocPos.Y() + GetVisDocTop() ); + aPoint.setY( rDocPos.X() + maOutputArea.Top() - GetVisDocLeft() ); } else { - aPoint.setX( aOutArea.Left() + rDocPos.Y() - GetVisDocTop() ); - aPoint.setY( aOutArea.Bottom() - rDocPos.X() + GetVisDocLeft() ); + aPoint.setX( maOutputArea.Left() + rDocPos.Y() - GetVisDocTop() ); + aPoint.setY( maOutputArea.Bottom() - rDocPos.X() + GetVisDocLeft() ); } } @@ -793,7 +815,7 @@ tools::Rectangle ImpEditView::GetWindowPos( const tools::Rectangle& rDocRect ) c Point aPos( GetWindowPos( rDocRect.TopLeft() ) ); Size aSz = rDocRect.GetSize(); tools::Rectangle aRect; - if ( !pEditEngine->pImpEditEngine->IsVertical() ) + if (!getImpEditEngine().IsEffectivelyVertical()) { aRect = tools::Rectangle( aPos, aSz ); } @@ -808,10 +830,10 @@ tools::Rectangle ImpEditView::GetWindowPos( const tools::Rectangle& rDocRect ) c void ImpEditView::SetSelectionMode( EESelectionMode eNewMode ) { - if ( eSelectionMode != eNewMode ) + if (meSelectionMode != eNewMode) { DrawSelectionXOR(); - eSelectionMode = eNewMode; + meSelectionMode = eNewMode; DrawSelectionXOR(); // redraw } } @@ -820,7 +842,7 @@ OutputDevice& ImpEditView::GetOutputDevice() const { if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) return pCallbacks->EditViewOutputDevice(); - return *pOutWin; + return *mpOutputWindow->GetOutDev(); } weld::Widget* ImpEditView::GetPopupParent(tools::Rectangle& rRect) const @@ -831,7 +853,7 @@ weld::Widget* ImpEditView::GetPopupParent(tools::Rectangle& rRect) const if (pParent) return pParent; } - return weld::GetPopupParent(*pOutWin, rRect); + return weld::GetPopupParent(*mpOutputWindow, rRect); } void ImpEditView::SetOutputArea( const tools::Rectangle& rRect ) @@ -840,13 +862,22 @@ void ImpEditView::SetOutputArea( const tools::Rectangle& rRect ) // should be better be aligned on pixels! tools::Rectangle aNewRect(rOutDev.LogicToPixel(rRect)); aNewRect = rOutDev.PixelToLogic(aNewRect); - aOutArea = aNewRect; - if ( !aOutArea.IsWidthEmpty() && aOutArea.Right() < aOutArea.Left() ) - aOutArea.SetRight( aOutArea.Left() ); - if ( !aOutArea.IsHeightEmpty() && aOutArea.Bottom() < aOutArea.Top() ) - aOutArea.SetBottom( aOutArea.Top() ); + maOutputArea = aNewRect; + if (!maOutputArea.IsWidthEmpty() && maOutputArea.Right() < maOutputArea.Left()) + maOutputArea.SetRight(maOutputArea.Left()); + if (!maOutputArea.IsHeightEmpty() && maOutputArea.Bottom() < maOutputArea.Top()) + maOutputArea.SetBottom(maOutputArea.Top()); + + SetScrollDiffX( static_cast<sal_uInt16>(maOutputArea.GetWidth()) * 2 / 10 ); +} + +namespace { + +tools::Rectangle lcl_negateRectX(const tools::Rectangle& rRect) +{ + return tools::Rectangle(-rRect.Right(), rRect.Top(), -rRect.Left(), rRect.Bottom()); +} - SetScrollDiffX( static_cast<sal_uInt16>(aOutArea.GetWidth()) * 2 / 10 ); } void ImpEditView::InvalidateAtWindow(const tools::Rectangle& rRect) @@ -856,107 +887,107 @@ void ImpEditView::InvalidateAtWindow(const tools::Rectangle& rRect) // do not invalidate and trigger a global repaint, but forward // the need for change to the applied EditViewCallback, can e.g. // be used to visualize the active edit text in an OverlayObject - pCallbacks->EditViewInvalidate(rRect); + pCallbacks->EditViewInvalidate(mbNegativeX ? lcl_negateRectX(rRect) : rRect); } else { // classic mode: invalidate and trigger full repaint // of the changed area - GetWindow()->Invalidate(rRect); + GetWindow()->Invalidate(mbNegativeX ? lcl_negateRectX(rRect) : rRect); } } void ImpEditView::ResetOutputArea( const tools::Rectangle& rRect ) { // remember old out area - const tools::Rectangle aOldArea(aOutArea); + const tools::Rectangle aOldArea(maOutputArea); // apply new one SetOutputArea(rRect); // invalidate surrounding areas if update is true - if(aOldArea.IsEmpty() || !pEditEngine->pImpEditEngine->GetUpdateMode()) + if(aOldArea.IsEmpty() || !getImpEditEngine().IsUpdateLayout()) return; // #i119885# use grown area if needed; do when getting bigger OR smaller - const sal_Int32 nMore(DoInvalidateMore() ? GetWindow()->PixelToLogic(Size(nInvMore, 0)).Width() : 0); + const sal_Int32 nMore(DoInvalidateMore() ? GetOutputDevice().PixelToLogic(Size(mnInvalidateMore, 0)).Width() : 0); - if(aOldArea.Left() > aOutArea.Left()) + if (aOldArea.Left() > maOutputArea.Left()) { - const tools::Rectangle aRect(aOutArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Left(), aOldArea.Bottom() + nMore); + const tools::Rectangle aRect(maOutputArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Left(), aOldArea.Bottom() + nMore); InvalidateAtWindow(aRect); } - else if(aOldArea.Left() < aOutArea.Left()) + else if (aOldArea.Left() < maOutputArea.Left()) { - const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Top() - nMore, aOutArea.Left(), aOldArea.Bottom() + nMore); + const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Top() - nMore, maOutputArea.Left(), aOldArea.Bottom() + nMore); InvalidateAtWindow(aRect); } - if(aOldArea.Right() > aOutArea.Right()) + if (aOldArea.Right() > maOutputArea.Right()) { - const tools::Rectangle aRect(aOutArea.Right(), aOldArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Bottom() + nMore); + const tools::Rectangle aRect(maOutputArea.Right(), aOldArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Bottom() + nMore); InvalidateAtWindow(aRect); } - else if(aOldArea.Right() < aOutArea.Right()) + else if (aOldArea.Right() < maOutputArea.Right()) { - const tools::Rectangle aRect(aOldArea.Right(), aOldArea.Top() - nMore, aOutArea.Right() + nMore, aOldArea.Bottom() + nMore); + const tools::Rectangle aRect(aOldArea.Right(), aOldArea.Top() - nMore, maOutputArea.Right() + nMore, aOldArea.Bottom() + nMore); InvalidateAtWindow(aRect); } - if(aOldArea.Top() > aOutArea.Top()) + if (aOldArea.Top() > maOutputArea.Top()) { - const tools::Rectangle aRect(aOldArea.Left() - nMore, aOutArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Top()); + const tools::Rectangle aRect(aOldArea.Left() - nMore, maOutputArea.Top() - nMore, aOldArea.Right() + nMore, aOldArea.Top()); InvalidateAtWindow(aRect); } - else if(aOldArea.Top() < aOutArea.Top()) + else if (aOldArea.Top() < maOutputArea.Top()) { - const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Right() + nMore, aOutArea.Top()); + const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Top() - nMore, aOldArea.Right() + nMore, maOutputArea.Top()); InvalidateAtWindow(aRect); } - if(aOldArea.Bottom() > aOutArea.Bottom()) + if (aOldArea.Bottom() > maOutputArea.Bottom()) { - const tools::Rectangle aRect(aOldArea.Left() - nMore, aOutArea.Bottom(), aOldArea.Right() + nMore, aOldArea.Bottom() + nMore); + const tools::Rectangle aRect(aOldArea.Left() - nMore, maOutputArea.Bottom(), aOldArea.Right() + nMore, aOldArea.Bottom() + nMore); InvalidateAtWindow(aRect); } - else if(aOldArea.Bottom() < aOutArea.Bottom()) + else if (aOldArea.Bottom() < maOutputArea.Bottom()) { - const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Bottom(), aOldArea.Right() + nMore, aOutArea.Bottom() + nMore); + const tools::Rectangle aRect(aOldArea.Left() - nMore, aOldArea.Bottom(), aOldArea.Right() + nMore, maOutputArea.Bottom() + nMore); InvalidateAtWindow(aRect); } } void ImpEditView::RecalcOutputArea() { - Point aNewTopLeft( aOutArea.TopLeft() ); - Size aNewSz( aOutArea.GetSize() ); + Point aNewTopLeft(maOutputArea.TopLeft()); + Size aNewSz(maOutputArea.GetSize()); // X: if ( DoAutoWidth() ) { - if ( pEditEngine->pImpEditEngine->GetStatus().AutoPageWidth() ) - aNewSz.setWidth( pEditEngine->pImpEditEngine->GetPaperSize().Width() ); - switch ( eAnchorMode ) + if (getImpEditEngine().GetStatus().AutoPageWidth()) + aNewSz.setWidth(getImpEditEngine().GetPaperSize().Width()); + switch (meAnchorMode) { case EEAnchorMode::TopLeft: case EEAnchorMode::VCenterLeft: case EEAnchorMode::BottomLeft: { - aNewTopLeft.setX( aAnchorPoint.X() ); + aNewTopLeft.setX(maAnchorPoint.X()); } break; case EEAnchorMode::TopHCenter: case EEAnchorMode::VCenterHCenter: case EEAnchorMode::BottomHCenter: { - aNewTopLeft.setX( aAnchorPoint.X() - aNewSz.Width() / 2 ); + aNewTopLeft.setX(maAnchorPoint.X() - aNewSz.Width() / 2); } break; case EEAnchorMode::TopRight: case EEAnchorMode::VCenterRight: case EEAnchorMode::BottomRight: { - aNewTopLeft.setX( aAnchorPoint.X() - aNewSz.Width() - 1 ); + aNewTopLeft.setX(maAnchorPoint.X() - aNewSz.Width() - 1); } break; } @@ -965,29 +996,29 @@ void ImpEditView::RecalcOutputArea() // Y: if ( DoAutoHeight() ) { - if ( pEditEngine->pImpEditEngine->GetStatus().AutoPageHeight() ) - aNewSz.setHeight( pEditEngine->pImpEditEngine->GetPaperSize().Height() ); - switch ( eAnchorMode ) + if (getImpEditEngine().GetStatus().AutoPageHeight()) + aNewSz.setHeight(getImpEditEngine().GetPaperSize().Height()); + switch (meAnchorMode) { case EEAnchorMode::TopLeft: case EEAnchorMode::TopHCenter: case EEAnchorMode::TopRight: { - aNewTopLeft.setY( aAnchorPoint.Y() ); + aNewTopLeft.setY(maAnchorPoint.Y()); } break; case EEAnchorMode::VCenterLeft: case EEAnchorMode::VCenterHCenter: case EEAnchorMode::VCenterRight: { - aNewTopLeft.setY( aAnchorPoint.Y() - aNewSz.Height() / 2 ); + aNewTopLeft.setY(maAnchorPoint.Y() - aNewSz.Height() / 2); } break; case EEAnchorMode::BottomLeft: case EEAnchorMode::BottomHCenter: case EEAnchorMode::BottomRight: { - aNewTopLeft.setY( aAnchorPoint.Y() - aNewSz.Height() - 1 ); + aNewTopLeft.setY(maAnchorPoint.Y() - aNewSz.Height() - 1); } break; } @@ -995,9 +1026,9 @@ void ImpEditView::RecalcOutputArea() ResetOutputArea( tools::Rectangle( aNewTopLeft, aNewSz ) ); } -void ImpEditView::SetAnchorMode( EEAnchorMode eMode ) +void ImpEditView::SetAnchorMode(EEAnchorMode eMode) { - eAnchorMode = eMode; + meAnchorMode = eMode; CalcAnchorPoint(); } @@ -1006,53 +1037,53 @@ void ImpEditView::CalcAnchorPoint() // GetHeight() and GetWidth() -1, because rectangle calculation not preferred. // X: - switch ( eAnchorMode ) + switch (meAnchorMode) { case EEAnchorMode::TopLeft: case EEAnchorMode::VCenterLeft: case EEAnchorMode::BottomLeft: { - aAnchorPoint.setX( aOutArea.Left() ); + maAnchorPoint.setX(maOutputArea.Left()); } break; case EEAnchorMode::TopHCenter: case EEAnchorMode::VCenterHCenter: case EEAnchorMode::BottomHCenter: { - aAnchorPoint.setX( aOutArea.Left() + (aOutArea.GetWidth()-1) / 2 ); + maAnchorPoint.setX(maOutputArea.Left() + (maOutputArea.GetWidth() - 1) / 2); } break; case EEAnchorMode::TopRight: case EEAnchorMode::VCenterRight: case EEAnchorMode::BottomRight: { - aAnchorPoint.setX( aOutArea.Right() ); + maAnchorPoint.setX(maOutputArea.Right()); } break; } // Y: - switch ( eAnchorMode ) + switch (meAnchorMode) { case EEAnchorMode::TopLeft: case EEAnchorMode::TopHCenter: case EEAnchorMode::TopRight: { - aAnchorPoint.setY( aOutArea.Top() ); + maAnchorPoint.setY(maOutputArea.Top()); } break; case EEAnchorMode::VCenterLeft: case EEAnchorMode::VCenterHCenter: case EEAnchorMode::VCenterRight: { - aAnchorPoint.setY( aOutArea.Top() + (aOutArea.GetHeight()-1) / 2 ); + maAnchorPoint.setY(maOutputArea.Top() + (maOutputArea.GetHeight() - 1) / 2); } break; case EEAnchorMode::BottomLeft: case EEAnchorMode::BottomHCenter: case EEAnchorMode::BottomRight: { - aAnchorPoint.setY( aOutArea.Bottom() - 1 ); + maAnchorPoint.setY(maOutputArea.Bottom() - 1); } break; } @@ -1072,36 +1103,35 @@ boost::property_tree::ptree getHyperlinkPropTree(const OUString& sText, const OU } // End of anon namespace -tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags, sal_Int32& nTextPortionStart, - const ParaPortion* pParaPortion) const +tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, CursorFlags aShowCursorFlags, sal_Int32& nTextPortionStart, ParaPortion const& rParaPortion) const { - tools::Rectangle aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, nShowCursorFlags ); - if ( !IsInsertMode() && !aEditSelection.HasRange() ) + tools::Rectangle aEditCursor = getImpEditEngine().PaMtoEditCursor(aPaM, aShowCursorFlags); + if (!IsInsertMode() && !maEditSelection.HasRange()) { if ( aPaM.GetNode()->Len() && ( aPaM.GetIndex() < aPaM.GetNode()->Len() ) ) { // If we are behind a portion, and the next portion has other direction, we must change position... - aEditCursor.SetLeft( pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GetCursorFlags::TextOnly|GetCursorFlags::PreferPortionStart ).Left() ); + aEditCursor.SetLeft(getImpEditEngine().PaMtoEditCursor(aPaM, CursorFlags{.bTextOnly = true, .bPreferPortionStart = true}).Left()); aEditCursor.SetRight( aEditCursor.Left() ); - sal_Int32 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true ); - const TextPortion& rTextPortion = pParaPortion->GetTextPortions()[nTextPortion]; + sal_Int32 nTextPortion = rParaPortion.GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true ); + const TextPortion& rTextPortion = rParaPortion.GetTextPortions()[nTextPortion]; if ( rTextPortion.GetKind() == PortionKind::TAB ) { aEditCursor.AdjustRight(rTextPortion.GetSize().Width() ); } else { - EditPaM aNext = pEditEngine->CursorRight( aPaM ); - tools::Rectangle aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GetCursorFlags::TextOnly ); + EditPaM aNext = getEditEngine().CursorRight( aPaM ); + tools::Rectangle aTmpRect = getImpEditEngine().PaMtoEditCursor(aNext, CursorFlags{ .bTextOnly = true }); if ( aTmpRect.Top() != aEditCursor.Top() ) - aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine ); + aTmpRect = getImpEditEngine().PaMtoEditCursor(aNext, CursorFlags{ .bTextOnly = true, .bEndOfLine = true }); aEditCursor.SetRight( aTmpRect.Left() ); } } } - tools::Long nMaxHeight = !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth(); + tools::Long nMaxHeight = !IsVertical() ? maOutputArea.GetHeight() : maOutputArea.GetWidth(); if ( aEditCursor.GetHeight() > nMaxHeight ) { aEditCursor.SetBottom( aEditCursor.Top() + nMaxHeight - 1 ); @@ -1112,16 +1142,17 @@ tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nS tools::Rectangle ImpEditView::GetEditCursor() const { - EditPaM aPaM( aEditSelection.Max() ); + EditPaM aPaM(maEditSelection.Max()); sal_Int32 nTextPortionStart = 0; - sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); + sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); if (nPara == EE_PARA_NOT_FOUND) // #i94322 return tools::Rectangle(); - const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara]; + ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); - GetCursorFlags nShowCursorFlags = nExtraCursorFlags | GetCursorFlags::TextOnly; + CursorFlags aShowCursorFlags = maExtraCursorFlags; + aShowCursorFlags.bTextOnly = true; // Use CursorBidiLevel 0/1 in meaning of // 0: prefer portion end, normal mode @@ -1129,46 +1160,47 @@ tools::Rectangle ImpEditView::GetEditCursor() const if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() ) { - nShowCursorFlags |= GetCursorFlags::PreferPortionStart; + aShowCursorFlags.bPreferPortionStart = true; } - return ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, pParaPortion); + return ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); } void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) { // No ShowCursor in an empty View ... - if (aOutArea.IsEmpty()) + if (maOutputArea.IsEmpty()) return; - if ( ( aOutArea.Left() >= aOutArea.Right() ) && ( aOutArea.Top() >= aOutArea.Bottom() ) ) + if ( (maOutputArea.Left() >= maOutputArea.Right() ) && ( maOutputArea.Top() >= maOutputArea.Bottom() ) ) return; - pEditEngine->CheckIdleFormatter(); - if (!pEditEngine->IsFormatted()) - pEditEngine->pImpEditEngine->FormatDoc(); + getEditEngine().CheckIdleFormatter(); + if (!getEditEngine().IsFormatted()) + getImpEditEngine().FormatDoc(); // For some reasons I end up here during the formatting, if the Outliner // is initialized in Paint, because no SetPool(); - if ( pEditEngine->pImpEditEngine->IsFormatting() ) + if (getImpEditEngine().IsFormatting()) return; - if ( !pEditEngine->pImpEditEngine->GetUpdateMode() ) + if (!getImpEditEngine().IsUpdateLayout()) return; - if ( pEditEngine->pImpEditEngine->IsInUndo() ) + if (getImpEditEngine().IsInUndo()) return; - if (pOutWin && pOutWin->GetCursor() != GetCursor()) - pOutWin->SetCursor(GetCursor()); + if (mpOutputWindow && mpOutputWindow->GetCursor() != GetCursor()) + mpOutputWindow->SetCursor(GetCursor()); - EditPaM aPaM( aEditSelection.Max() ); + EditPaM aPaM(maEditSelection.Max()); sal_Int32 nTextPortionStart = 0; - sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); + sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); if (nPara == EE_PARA_NOT_FOUND) // #i94322 return; - const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara]; + ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); - GetCursorFlags nShowCursorFlags = nExtraCursorFlags | GetCursorFlags::TextOnly; + CursorFlags aShowCursorFlags = maExtraCursorFlags; + aShowCursorFlags.bTextOnly = true; // Use CursorBidiLevel 0/1 in meaning of // 0: prefer portion end, normal mode @@ -1176,12 +1208,12 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() ) { - nShowCursorFlags |= GetCursorFlags::PreferPortionStart; + aShowCursorFlags.bPreferPortionStart = true; } - tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, pParaPortion); + tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, aShowCursorFlags, nTextPortionStart, rParaPortion); - if ( bGotoCursor ) // && (!pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() ) ) + if ( bGotoCursor ) // && (!getImpEditEngine().GetStatus().AutoPageSize() ) ) { // check if scrolling is necessary... // if scrolling, then update () and Scroll ()! @@ -1191,7 +1223,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) tools::Rectangle aTmpVisArea( GetVisDocArea() ); // aTmpOutArea: if OutputArea > Paper width and // Text > Paper width ( over large fields ) - tools::Long nMaxTextWidth = !IsVertical() ? pEditEngine->pImpEditEngine->GetPaperSize().Width() : pEditEngine->pImpEditEngine->GetPaperSize().Height(); + tools::Long nMaxTextWidth = !IsVertical() ? getImpEditEngine().GetPaperSize().Width() : getImpEditEngine().GetPaperSize().Height(); if ( aTmpVisArea.GetWidth() > nMaxTextWidth ) aTmpVisArea.SetRight( aTmpVisArea.Left() + nMaxTextWidth ); @@ -1245,11 +1277,11 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) tools::Long nDiffY = !IsVertical() ? nDocDiffY : (IsTopToBottom() ? nDocDiffX : -nDocDiffX); if ( nDiffX ) - pEditEngine->GetInternalEditStatus().GetStatusWord() = pEditEngine->GetInternalEditStatus().GetStatusWord() | EditStatusFlags::HSCROLL; + getEditEngine().GetInternalEditStatus().GetStatusWord() = getEditEngine().GetInternalEditStatus().GetStatusWord() | EditStatusFlags::HSCROLL; if ( nDiffY ) - pEditEngine->GetInternalEditStatus().GetStatusWord() = pEditEngine->GetInternalEditStatus().GetStatusWord() | EditStatusFlags::VSCROLL; + getEditEngine().GetInternalEditStatus().GetStatusWord() = getEditEngine().GetInternalEditStatus().GetStatusWord() | EditStatusFlags::VSCROLL; Scroll( -nDiffX, -nDiffY ); - pEditEngine->pImpEditEngine->DelayedCallStatusHdl(); + getImpEditEngine().DelayedCallStatusHdl(); } } @@ -1316,22 +1348,33 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) MapUnit eDevUnit = rOutDev.GetMapMode().GetMapUnit(); tools::Rectangle aCursorRectPureLogical(aEditCursor.TopLeft(), GetCursor()->GetSize()); - // Get rectangle in window-coordinates from editeng(doc) coordinates. - aCursorRectPureLogical = mpLOKSpecialPositioning->GetWindowPos(aCursorRectPureLogical, eDevUnit); + // Get rectangle in window-coordinates from editeng(doc) coordinates in hmm. + aCursorRectPureLogical = GetWindowPos(aCursorRectPureLogical); + Point aRefPointLogical = GetOutputArea().TopLeft(); + // Get the relative coordinates w.r.t refpoint in display hmm. + aCursorRectPureLogical.Move(-aRefPointLogical.X(), -aRefPointLogical.Y()); + if (getEditEngine().IsRightToLeft(nPara) || mpLOKSpecialPositioning->IsLayoutRTL()) + { + tools::Long nMirrorW = GetOutputArea().GetWidth(); + tools::Long nLeft = aCursorRectPureLogical.Left(), nRight = aCursorRectPureLogical.Right(); + aCursorRectPureLogical.SetLeft(nMirrorW - nRight); + aCursorRectPureLogical.SetRight(nMirrorW - nLeft); + } + // Convert to twips. + aCursorRectPureLogical = OutputDevice::LogicToLogic(aCursorRectPureLogical, MapMode(eDevUnit), MapMode(MapUnit::MapTwip)); + // "refpoint" in print twips. const Point aRefPoint = mpLOKSpecialPositioning->GetRefPoint(); - // Get the relative coordinates w.r.t rRefPoint. - aCursorRectPureLogical.Move(-aRefPoint.X(), -aRefPoint.Y()); aMessageParams.put("relrect", aCursorRectPureLogical.toString()); aMessageParams.put("refpoint", aRefPoint.toString()); } - if (pOutWin && pOutWin->IsChart()) + if (mpOutputWindow && mpOutputWindow->IsChart()) { const vcl::Window* pViewShellWindow = mpViewShell->GetEditWindowForActiveOLEObj(); - if (pViewShellWindow && pViewShellWindow->IsAncestorOf(*pOutWin)) + if (pViewShellWindow && pViewShellWindow->IsAncestorOf(*mpOutputWindow)) { - Point aOffsetPx = pOutWin->GetOffsetPixelFrom(*pViewShellWindow); - Point aLogicOffset = pOutWin->PixelToLogic(aOffsetPx); + Point aOffsetPx = mpOutputWindow->GetOffsetPixelFrom(*pViewShellWindow); + Point aLogicOffset = mpOutputWindow->PixelToLogic(aOffsetPx); aPos.Move(aLogicOffset.getX(), aLogicOffset.getY()); } } @@ -1340,7 +1383,9 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) // LOK output is always in twips, convert from mm100 if necessary. if (rOutDev.GetMapMode().GetMapUnit() == MapUnit::Map100thMM) - aRect = OutputDevice::LogicToLogic(aRect, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + { + aRect = o3tl::convert(aRect, o3tl::Length::mm100, o3tl::Length::twip); + } else if (rOutDev.GetMapMode().GetMapUnit() == MapUnit::MapTwip) { // Writer comments: they use editeng, but are separate widgets. @@ -1367,21 +1412,19 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) else { // is cursor at a misspelled word ? - Reference< linguistic2::XSpellChecker1 > xSpeller( pEditEngine->pImpEditEngine->GetSpeller() ); + uno::Reference<linguistic2::XSpellChecker1> xSpeller(getImpEditEngine().GetSpeller()); bool bIsWrong = xSpeller.is() && IsWrongSpelledWord(aPaM, /*bMarkIfWrong*/ false); + EditView* pActiveView = GetEditViewPtr(); boost::property_tree::ptree aHyperlinkTree; - if (const SvxFieldItem* pFld = GetField(aPos, nullptr, nullptr)) + if (pActiveView && URLFieldHelper::IsCursorAtURLField(*pActiveView)) { - if (auto pUrlField = dynamic_cast<const SvxURLField*>(pFld->GetField())) - { - aHyperlinkTree = getHyperlinkPropTree(pUrlField->GetRepresentation(), pUrlField->GetURL()); - } + if (const SvxFieldItem* pFld = GetField(aPos, nullptr, nullptr)) + if (auto pUrlField = dynamic_cast<const SvxURLField*>(pFld->GetField())) + aHyperlinkTree = getHyperlinkPropTree(pUrlField->GetRepresentation(), pUrlField->GetURL()); } else if (GetEditSelection().HasRange()) { - EditView* pActiveView = GetEditViewPtr(); - if (pActiveView) { const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection(); @@ -1408,15 +1451,15 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, aMessageParams); else pThisShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, - aMessageParams.get<std::string>("rectangle").c_str()); + OString(aMessageParams.get<std::string>("rectangle"))); } } CursorDirection nCursorDir = CursorDirection::NONE; - if ( IsInsertMode() && !aEditSelection.HasRange() && ( pEditEngine->pImpEditEngine->HasDifferentRTLLevels( aPaM.GetNode() ) ) ) + if ( IsInsertMode() && !maEditSelection.HasRange() && (getImpEditEngine().HasDifferentRTLLevels(aPaM.GetNode()) ) ) { - sal_uInt16 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, bool(nShowCursorFlags & GetCursorFlags::PreferPortionStart) ); - const TextPortion& rTextPortion = pParaPortion->GetTextPortions()[nTextPortion]; + sal_uInt16 nTextPortion = rParaPortion.GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, aShowCursorFlags.bPreferPortionStart); + const TextPortion& rTextPortion = rParaPortion.GetTextPortions()[nTextPortion]; if (rTextPortion.IsRightToLeft()) nCursorDir = CursorDirection::RTL; else @@ -1429,9 +1472,9 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) GetCursor()->Show(); { SvxFont aFont; - pEditEngine->SeekCursor( aPaM.GetNode(), aPaM.GetIndex()+1, aFont ); + getEditEngine().SeekCursor( aPaM.GetNode(), aPaM.GetIndex()+1, aFont ); - InputContext aInputContext(aFont, InputContextFlags::Text | InputContextFlags::ExtText); + InputContext aInputContext(std::move(aFont), InputContextFlags::Text | InputContextFlags::ExtText); if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) pCallbacks->EditViewInputContext(aInputContext); else if (auto xWindow = GetWindow()) @@ -1440,7 +1483,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) } else { - pEditEngine->pImpEditEngine->GetStatus().GetStatusWord() = pEditEngine->pImpEditEngine->GetStatus().GetStatusWord() | EditStatusFlags::CURSOROUT; + getImpEditEngine().GetStatus().GetStatusWord() = getImpEditEngine().GetStatus().GetStatusWord() | EditStatusFlags::CURSOROUT; GetCursor()->Hide(); GetCursor()->SetPos( Point( -1, -1 ) ); GetCursor()->SetSize( Size( 0, 0 ) ); @@ -1458,17 +1501,17 @@ void ImpEditView::ScrollStateChange() Pair ImpEditView::Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRangeCheck ) { - DBG_ASSERT( pEditEngine->pImpEditEngine->IsFormatted(), "Scroll: Not formatted!" ); + DBG_ASSERT(getImpEditEngine().IsFormatted(), "Scroll: Not formatted!"); if ( !ndX && !ndY ) return Pair( 0, 0 ); const OutputDevice& rOutDev = GetOutputDevice(); #ifdef DBG_UTIL - tools::Rectangle aR( aOutArea ); + tools::Rectangle aR(maOutputArea); aR = rOutDev.LogicToPixel( aR ); aR = rOutDev.PixelToLogic( aR ); - SAL_WARN_IF( aR != aOutArea, "editeng", "OutArea before Scroll not aligned" ); + SAL_WARN_IF(aR != maOutputArea, "editeng", "OutArea before Scroll not aligned"); #endif tools::Rectangle aNewVisArea( GetVisDocArea() ); @@ -1492,10 +1535,10 @@ Pair ImpEditView::Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRa aNewVisArea.AdjustBottom( -ndX ); } } - if ( ( nRangeCheck == ScrollRangeCheck::PaperWidthTextSize ) && ( aNewVisArea.Bottom() > static_cast<tools::Long>(pEditEngine->pImpEditEngine->GetTextHeight()) ) ) + if ( ( nRangeCheck == ScrollRangeCheck::PaperWidthTextSize ) && ( aNewVisArea.Bottom() > static_cast<tools::Long>(getImpEditEngine().GetTextHeight()) ) ) { // GetTextHeight still optimizing! - tools::Long nDiff = pEditEngine->pImpEditEngine->GetTextHeight() - aNewVisArea.Bottom(); // negative + tools::Long nDiff = getImpEditEngine().GetTextHeight() - aNewVisArea.Bottom(); // negative aNewVisArea.Move( 0, nDiff ); // could end up in the negative area... } if ( aNewVisArea.Top() < 0 ) @@ -1520,9 +1563,9 @@ Pair ImpEditView::Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRa aNewVisArea.AdjustRight(ndY ); } } - if ( ( nRangeCheck == ScrollRangeCheck::PaperWidthTextSize ) && ( aNewVisArea.Right() > static_cast<tools::Long>(pEditEngine->pImpEditEngine->CalcTextWidth( false )) ) ) + if ( ( nRangeCheck == ScrollRangeCheck::PaperWidthTextSize ) && ( aNewVisArea.Right() > static_cast<tools::Long>(getImpEditEngine().CalcTextWidth( false )) ) ) { - tools::Long nDiff = pEditEngine->pImpEditEngine->CalcTextWidth( false ) - aNewVisArea.Right(); // negative + tools::Long nDiff = getImpEditEngine().CalcTextWidth( false ) - aNewVisArea.Right(); // negative aNewVisArea.Move( nDiff, 0 ); // could end up in the negative area... } if ( aNewVisArea.Left() < 0 ) @@ -1545,48 +1588,48 @@ Pair ImpEditView::Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRa vcl::Cursor* pCrsr = GetCursor(); bool bVisCursor = pCrsr->IsVisible(); pCrsr->Hide(); - if (pOutWin) - pOutWin->PaintImmediately(); - if ( !IsVertical() ) - aVisDocStartPos.Move( -nRealDiffX, -nRealDiffY ); + if (mpOutputWindow) + mpOutputWindow->PaintImmediately(); + if (!IsVertical()) + maVisDocStartPos.Move(-nRealDiffX, -nRealDiffY); else { if (IsTopToBottom()) - aVisDocStartPos.Move(-nRealDiffY, nRealDiffX); + maVisDocStartPos.Move(-nRealDiffY, nRealDiffX); else - aVisDocStartPos.Move(nRealDiffY, -nRealDiffX); + maVisDocStartPos.Move(nRealDiffY, -nRealDiffX); } // Move by aligned value does not necessarily result in aligned // rectangle ... - aVisDocStartPos = rOutDev.LogicToPixel( aVisDocStartPos ); - aVisDocStartPos = rOutDev.PixelToLogic( aVisDocStartPos ); - tools::Rectangle aRect( aOutArea ); + maVisDocStartPos = rOutDev.LogicToPixel(maVisDocStartPos); + maVisDocStartPos = rOutDev.PixelToLogic(maVisDocStartPos); + tools::Rectangle aRect(maOutputArea); - if (pOutWin) + if (mpOutputWindow) { - pOutWin->Scroll( nRealDiffX, nRealDiffY, aRect, ScrollFlags::Clip ); + mpOutputWindow->Scroll( nRealDiffX, nRealDiffY, aRect, ScrollFlags::Clip ); } if (comphelper::LibreOfficeKit::isActive() || getEditViewCallbacks()) { // Need to invalidate the window, otherwise no tile will be re-painted. - pEditView->Invalidate(); + GetEditViewPtr()->Invalidate(); } - if (pOutWin) - pOutWin->PaintImmediately(); + if (mpOutputWindow) + mpOutputWindow->PaintImmediately(); pCrsr->SetPos( pCrsr->GetPos() + Point( nRealDiffX, nRealDiffY ) ); if ( bVisCursor ) { tools::Rectangle aCursorRect( pCrsr->GetPos(), pCrsr->GetSize() ); - if ( aOutArea.IsInside( aCursorRect ) ) + if (maOutputArea.Contains(aCursorRect)) pCrsr->Show(); } - if ( pEditEngine->pImpEditEngine->GetNotifyHdl().IsSet() ) + if (getImpEditEngine().GetNotifyHdl().IsSet()) { EENotify aNotify( EE_NOTIFY_TEXTVIEWSCROLLED ); - pEditEngine->pImpEditEngine->GetNotifyHdl().Call( aNotify ); + getImpEditEngine().GetNotifyHdl().Call( aNotify ); } if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) @@ -1601,20 +1644,16 @@ Pair ImpEditView::Scroll( tools::Long ndX, tools::Long ndY, ScrollRangeCheck nRa return Pair( nRealDiffX, nRealDiffY ); } -Reference<css::datatransfer::clipboard::XClipboard> ImpEditView::GetClipboard() const +uno::Reference<datatransfer::clipboard::XClipboard> ImpEditView::GetClipboard() const { + if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) + return pCallbacks->GetClipboard(); if (vcl::Window* pWindow = GetWindow()) return pWindow->GetClipboard(); + SAL_WARN("editeng", "falling back to using GetSystemClipboard"); return GetSystemClipboard(); } -Reference<css::datatransfer::clipboard::XClipboard> ImpEditView::GetSelection() const -{ - if (vcl::Window* pWindow = GetWindow()) - return pWindow->GetPrimarySelection(); - return GetSystemPrimarySelection(); -} - bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * pFrameWin ) { bool bDone = false; @@ -1626,9 +1665,9 @@ bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * p { case KeyFuncType::CUT: { - if ( !bReadOnly ) + if (!mbReadOnly) { - Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); + uno::Reference<datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); CutCopy( aClipBoard, true ); bDone = true; } @@ -1636,19 +1675,19 @@ bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * p break; case KeyFuncType::COPY: { - Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); + uno::Reference<datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); CutCopy( aClipBoard, false ); bDone = true; } break; case KeyFuncType::PASTE: { - if ( !bReadOnly && IsPasteEnabled() ) + if (!mbReadOnly && IsPasteEnabled()) { - pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_PASTE ); - Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); - Paste( aClipBoard, pEditEngine->pImpEditEngine->GetStatus().AllowPasteSpecial() ); - pEditEngine->pImpEditEngine->UndoActionEnd(); + getImpEditEngine().UndoActionStart( EDITUNDO_PASTE ); + uno::Reference<datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard()); + Paste( aClipBoard, getImpEditEngine().GetStatus().AllowPasteSpecial() ); + getImpEditEngine().UndoActionEnd(); bDone = true; } } @@ -1659,60 +1698,60 @@ bool ImpEditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * p } if( !bDone ) - bDone = pEditEngine->PostKeyEvent( rKeyEvent, GetEditViewPtr(), pFrameWin ); + bDone = getEditEngine().PostKeyEvent( rKeyEvent, GetEditViewPtr(), pFrameWin ); return bDone; } bool ImpEditView::MouseButtonUp( const MouseEvent& rMouseEvent ) { - nTravelXPos = TRAVEL_X_DONTKNOW; - nCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; - nExtraCursorFlags = GetCursorFlags::NONE; - bClickedInSelection = false; + mnTravelXPos = TRAVEL_X_DONTKNOW; + mnCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; + maExtraCursorFlags = CursorFlags(); + mbClickedInSelection = false; - if (vcl::Window* pWindow = GetWindow()) + if ( rMouseEvent.IsMiddle() && !mbReadOnly && + Application::GetSettings().GetMouseSettings().GetMiddleButtonAction() == MouseMiddleButtonAction::PasteSelection ) { - if ( rMouseEvent.IsMiddle() && !bReadOnly && - ( pWindow->GetSettings().GetMouseSettings().GetMiddleButtonAction() == MouseMiddleButtonAction::PasteSelection ) ) - { - Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetSelection()); - Paste( aClipBoard ); - } - else if ( rMouseEvent.IsLeft() && GetEditSelection().HasRange() ) - { - Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetSelection()); - CutCopy( aClipBoard, false ); - } + uno::Reference<datatransfer::clipboard::XClipboard> aClipBoard(GetSystemPrimarySelection()); + Paste( aClipBoard ); + } + else if ( rMouseEvent.IsLeft() && GetEditSelection().HasRange() ) + { + uno::Reference<datatransfer::clipboard::XClipboard> aClipBoard(GetSystemPrimarySelection()); + CutCopy( aClipBoard, false ); } - return pEditEngine->pImpEditEngine->MouseButtonUp( rMouseEvent, GetEditViewPtr() ); + return getImpEditEngine().MouseButtonUp( rMouseEvent, GetEditViewPtr() ); } void ImpEditView::ReleaseMouse() { - pEditEngine->pImpEditEngine->ReleaseMouse(); + getImpEditEngine().ReleaseMouse(); } bool ImpEditView::MouseButtonDown( const MouseEvent& rMouseEvent ) { - pEditEngine->CheckIdleFormatter(); // If fast typing and mouse button downs - nTravelXPos = TRAVEL_X_DONTKNOW; - nExtraCursorFlags = GetCursorFlags::NONE; - nCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; - bClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() ); - return pEditEngine->pImpEditEngine->MouseButtonDown( rMouseEvent, GetEditViewPtr() ); + getEditEngine().CheckIdleFormatter(); // If fast typing and mouse button downs + mnTravelXPos = TRAVEL_X_DONTKNOW; + maExtraCursorFlags = CursorFlags(); + mnCursorBidiLevel = CURSOR_BIDILEVEL_DONTKNOW; + bool bPrevUpdateLayout = getImpEditEngine().SetUpdateLayout(true); + mbClickedInSelection = IsSelectionAtPoint( rMouseEvent.GetPosPixel() ); + bool bRet = getImpEditEngine().MouseButtonDown( rMouseEvent, GetEditViewPtr() ); + getImpEditEngine().SetUpdateLayout(bPrevUpdateLayout); + return bRet; } bool ImpEditView::MouseMove( const MouseEvent& rMouseEvent ) { - return pEditEngine->pImpEditEngine->MouseMove( rMouseEvent, GetEditViewPtr() ); + return getImpEditEngine().MouseMove( rMouseEvent, GetEditViewPtr() ); } bool ImpEditView::Command(const CommandEvent& rCEvt) { - pEditEngine->CheckIdleFormatter(); // If fast typing and mouse button down - return pEditEngine->pImpEditEngine->Command(rCEvt, GetEditViewPtr()); + getEditEngine().CheckIdleFormatter(); // If fast typing and mouse button down + return getImpEditEngine().Command(rCEvt, GetEditViewPtr()); } @@ -1720,7 +1759,7 @@ void ImpEditView::SetInsertMode( bool bInsert ) { if ( bInsert != IsInsertMode() ) { - SetFlags( nControl, EVControlBits::OVERWRITE, !bInsert ); + SetFlags(mnControl, EVControlBits::OVERWRITE, !bInsert); ShowCursor( DoAutoScroll(), false ); } } @@ -1730,7 +1769,7 @@ bool ImpEditView::IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong ) bool bIsWrong = false; if ( rPaM.GetNode()->GetWrongList() ) { - EditSelection aSel = pEditEngine->SelectWord( rPaM, css::i18n::WordType::DICTIONARY_WORD ); + EditSelection aSel = getEditEngine().SelectWord( rPaM, css::i18n::WordType::DICTIONARY_WORD ); bIsWrong = rPaM.GetNode()->GetWrongList()->HasWrong( aSel.Min().GetIndex(), aSel.Max().GetIndex() ); if ( bIsWrong && bMarkIfWrong ) { @@ -1745,17 +1784,17 @@ bool ImpEditView::IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong ) OUString ImpEditView::SpellIgnoreWord() { OUString aWord; - if ( pEditEngine->pImpEditEngine->GetSpeller().is() ) + if (getImpEditEngine().GetSpeller().is()) { EditPaM aPaM = GetEditSelection().Max(); if ( !HasSelection() ) { - EditSelection aSel = pEditEngine->SelectWord(aPaM); - aWord = pEditEngine->pImpEditEngine->GetSelected( aSel ); + EditSelection aSel = getEditEngine().SelectWord(aPaM); + aWord = getImpEditEngine().GetSelected( aSel ); } else { - aWord = pEditEngine->pImpEditEngine->GetSelected( GetEditSelection() ); + aWord = getImpEditEngine().GetSelected( GetEditSelection() ); // And deselect DrawSelectionXOR(); SetEditSelection( EditSelection( aPaM, aPaM ) ); @@ -1764,18 +1803,18 @@ OUString ImpEditView::SpellIgnoreWord() if ( !aWord.isEmpty() ) { - Reference< XDictionary > xDic = LinguMgr::GetIgnoreAllList(); + uno::Reference<linguistic2::XDictionary> xDic = LinguMgr::GetIgnoreAllList(); if (xDic.is()) xDic->add( aWord, false, OUString() ); - EditDoc& rDoc = pEditEngine->GetEditDoc(); + EditDoc& rDoc = getEditEngine().GetEditDoc(); sal_Int32 nNodes = rDoc.Count(); for ( sal_Int32 n = 0; n < nNodes; n++ ) { ContentNode* pNode = rDoc.GetObject( n ); pNode->GetWrongList()->MarkWrongsInvalid(); } - pEditEngine->pImpEditEngine->DoOnlineSpelling( aPaM.GetNode() ); - pEditEngine->pImpEditEngine->StartOnlineSpellTimer(); + getImpEditEngine().DoOnlineSpelling( aPaM.GetNode() ); + getImpEditEngine().StartOnlineSpellTimer(); } } return aWord; @@ -1785,27 +1824,29 @@ void ImpEditView::DeleteSelected() { DrawSelectionXOR(); - pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_DELETE ); + getImpEditEngine().UndoActionStart( EDITUNDO_DELETE ); - EditPaM aPaM = pEditEngine->pImpEditEngine->DeleteSelected( GetEditSelection() ); + EditPaM aPaM = getImpEditEngine().DeleteSelected( GetEditSelection() ); - pEditEngine->pImpEditEngine->UndoActionEnd(); + getImpEditEngine().UndoActionEnd(); SetEditSelection( EditSelection( aPaM, aPaM ) ); DrawSelectionXOR(); - pEditEngine->pImpEditEngine->FormatAndUpdate( GetEditViewPtr() ); + getImpEditEngine().FormatAndLayout( GetEditViewPtr() ); ShowCursor( DoAutoScroll(), true ); } const SvxFieldItem* ImpEditView::GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const { - if( !GetOutputArea().IsInside( rPos ) ) + if( !GetOutputArea().Contains( rPos ) ) return nullptr; Point aDocPos( GetDocPos( rPos ) ); - EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false); + EditPaM aPaM = getEditEngine().GetPaM(aDocPos, false); + if (!aPaM) + return nullptr; if ( aPaM.GetIndex() == aPaM.GetNode()->Len() ) { @@ -1818,13 +1859,13 @@ const SvxFieldItem* ImpEditView::GetField( const Point& rPos, sal_Int32* pPara, for (size_t nAttr = rAttrs.size(); nAttr; ) { const EditCharAttrib& rAttr = *rAttrs[--nAttr]; - if (rAttr.GetStart() == nXPos) + if (rAttr.GetStart() == nXPos || rAttr.GetEnd() == nXPos) { if (rAttr.Which() == EE_FEATURE_FIELD) { DBG_ASSERT(dynamic_cast<const SvxFieldItem*>(rAttr.GetItem()), "No FieldItem..."); if ( pPara ) - *pPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); + *pPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); if ( pPos ) *pPos = rAttr.GetStart(); return static_cast<const SvxFieldItem*>(rAttr.GetItem()); @@ -1839,19 +1880,21 @@ bool ImpEditView::IsBulletArea( const Point& rPos, sal_Int32* pPara ) if ( pPara ) *pPara = EE_PARA_NOT_FOUND; - if( !GetOutputArea().IsInside( rPos ) ) + if( !GetOutputArea().Contains( rPos ) ) return false; Point aDocPos( GetDocPos( rPos ) ); - EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false); + EditPaM aPaM = getEditEngine().GetPaM(aDocPos, false); + if (!aPaM) + return false; if ( aPaM.GetIndex() == 0 ) { - sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); - tools::Rectangle aBulletArea = pEditEngine->GetBulletArea( nPara ); - tools::Long nY = pEditEngine->GetDocPosTopLeft( nPara ).Y(); - const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara]; - nY += pParaPortion->GetFirstLineOffset(); + sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); + tools::Rectangle aBulletArea = getEditEngine().GetBulletArea( nPara ); + tools::Long nY = getEditEngine().GetDocPosTopLeft( nPara ).Y(); + ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); + nY += rParaPortion.GetFirstLineOffset(); if ( ( aDocPos.Y() > ( nY + aBulletArea.Top() ) ) && ( aDocPos.Y() < ( nY + aBulletArea.Bottom() ) ) && ( aDocPos.X() > ( aBulletArea.Left() ) ) && @@ -1866,12 +1909,12 @@ bool ImpEditView::IsBulletArea( const Point& rPos, sal_Int32* pPara ) return false; } -void ImpEditView::CutCopy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bCut ) +void ImpEditView::CutCopy(uno::Reference<datatransfer::clipboard::XClipboard> const & rxClipboard, bool bCut ) { if ( !(rxClipboard.is() && HasSelection()) ) return; - uno::Reference<datatransfer::XTransferable> xData = pEditEngine->CreateTransferable( GetEditSelection() ); + uno::Reference<datatransfer::XTransferable> xData = getEditEngine().CreateTransferable( GetEditSelection() ); { SolarMutexReleaser aReleaser; @@ -1893,18 +1936,18 @@ void ImpEditView::CutCopy( css::uno::Reference< css::datatransfer::clipboard::XC if (bCut) { - pEditEngine->pImpEditEngine->UndoActionStart(EDITUNDO_CUT); + getImpEditEngine().UndoActionStart(EDITUNDO_CUT); DeleteSelected(); - pEditEngine->pImpEditEngine->UndoActionEnd(); + getImpEditEngine().UndoActionEnd(); } } -void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial ) +void ImpEditView::Paste(uno::Reference<datatransfer::clipboard::XClipboard> const & rxClipboard, bool bUseSpecial, SotClipboardFormatId format) { if ( !rxClipboard.is() ) return; - uno::Reference< datatransfer::XTransferable > xDataObj; + uno::Reference<datatransfer::XTransferable> xDataObj; try { @@ -1918,18 +1961,18 @@ void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XCli if ( !xDataObj.is() || !EditEngine::HasValidData( xDataObj ) ) return; - pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_PASTE ); + getImpEditEngine().UndoActionStart( EDITUNDO_PASTE ); EditSelection aSel( GetEditSelection() ); if ( aSel.HasRange() ) { DrawSelectionXOR(); - aSel = pEditEngine->DeleteSelection(aSel); + aSel = getEditEngine().DeleteSelection(aSel); } PasteOrDropInfos aPasteOrDropInfos; - aPasteOrDropInfos.nStartPara = pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() ); - pEditEngine->HandleBeginPasteOrDrop(aPasteOrDropInfos); + aPasteOrDropInfos.nStartPara = getEditEngine().GetEditDoc().GetPos( aSel.Min().GetNode() ); + getEditEngine().HandleBeginPasteOrDrop(aPasteOrDropInfos); if ( DoSingleLinePaste() ) { @@ -1944,7 +1987,7 @@ void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XCli aData >>= aTmpText; OUString aText(convertLineEnd(aTmpText, LINEEND_LF)); aText = aText.replaceAll( OUStringChar(LINE_SEP), " " ); - aSel = pEditEngine->InsertText(aSel, aText); + aSel = getEditEngine().InsertText(aSel, aText); } catch( ... ) { @@ -1957,18 +2000,18 @@ void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XCli // Prevent notifications of paragraph inserts et al that would trigger // a11y to format content in a half-ready state when obtaining // paragraphs. Collect and broadcast when done instead. - aSel = pEditEngine->InsertText( + aSel = getEditEngine().InsertText( xDataObj, OUString(), aSel.Min(), - bUseSpecial && pEditEngine->GetInternalEditStatus().AllowPasteSpecial()); + bUseSpecial && getEditEngine().GetInternalEditStatus().AllowPasteSpecial(), format); } - aPasteOrDropInfos.nEndPara = pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() ); - pEditEngine->HandleEndPasteOrDrop(aPasteOrDropInfos); + aPasteOrDropInfos.nEndPara = getEditEngine().GetEditDoc().GetPos( aSel.Max().GetNode() ); + getEditEngine().HandleEndPasteOrDrop(aPasteOrDropInfos); - pEditEngine->pImpEditEngine->UndoActionEnd(); + getImpEditEngine().UndoActionEnd(); SetEditSelection( aSel ); - pEditEngine->pImpEditEngine->UpdateSelections(); - pEditEngine->pImpEditEngine->FormatAndUpdate( GetEditViewPtr() ); + getImpEditEngine().UpdateSelections(); + getImpEditEngine().FormatAndLayout( GetEditViewPtr() ); ShowCursor( DoAutoScroll(), true ); } @@ -1979,11 +2022,11 @@ bool ImpEditView::IsInSelection( const EditPaM& rPaM ) if ( !aSel.HasRange() ) return false; - aSel.Adjust( pEditEngine->GetEditDoc() ); + aSel.Adjust(getEditEngine().GetEditDoc()); - sal_Int32 nStartNode = pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() ); - sal_Int32 nEndNode = pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() ); - sal_Int32 nCurNode = pEditEngine->GetEditDoc().GetPos( rPaM.GetNode() ); + sal_Int32 nStartNode = getEditEngine().GetEditDoc().GetPos( aSel.Min().GetNode() ); + sal_Int32 nEndNode = getEditEngine().GetEditDoc().GetPos( aSel.Max().GetNode() ); + sal_Int32 nCurNode = getEditEngine().GetEditDoc().GetPos( rPaM.GetNode() ); if ( ( nCurNode > nStartNode ) && ( nCurNode < nEndNode ) ) return true; @@ -2002,9 +2045,32 @@ bool ImpEditView::IsInSelection( const EditPaM& rPaM ) return false; } +bool ImpEditView::IsSelectionFullPara() const +{ + if (!IsSelectionInSinglePara()) + return false; + + sal_Int32 nSelectionStartPos = GetEditSelection().Min().GetIndex(); + sal_Int32 nSelectionEndPos = GetEditSelection().Max().GetIndex(); + + if (nSelectionStartPos > nSelectionEndPos) + std::swap(nSelectionStartPos, nSelectionEndPos); + + if (nSelectionStartPos != 0) + return false; + + const ContentNode* pNode = GetEditSelection().Min().GetNode(); + return pNode->Len() == nSelectionEndPos; +} + +bool ImpEditView::IsSelectionInSinglePara() const +{ + return GetEditSelection().Min().GetNode() == GetEditSelection().Max().GetNode(); +} + void ImpEditView::CreateAnchor() { - pEditEngine->SetInSelectionMode(true); + getEditEngine().SetInSelectionMode(true); EditSelection aNewSelection(GetEditSelection()); aNewSelection.Min() = aNewSelection.Max(); SetEditSelection(aNewSelection); @@ -2013,16 +2079,16 @@ void ImpEditView::CreateAnchor() void ImpEditView::DeselectAll() { - pEditEngine->SetInSelectionMode(false); + getEditEngine().SetInSelectionMode(false); DrawSelectionXOR(); EditSelection aNewSelection(GetEditSelection()); aNewSelection.Min() = aNewSelection.Max(); SetEditSelection(aNewSelection); // const_cast<EditPaM&>(GetEditSelection().Min()) = GetEditSelection().Max(); - if (comphelper::LibreOfficeKit::isActive() && mpViewShell) + if (comphelper::LibreOfficeKit::isActive() && mpViewShell && mpOutputWindow) { - VclPtr<vcl::Window> pParent = pOutWin->GetParentWithLOKNotifier(); + VclPtr<vcl::Window> pParent = mpOutputWindow->GetParentWithLOKNotifier(); if (pParent && pParent->GetLOKWindowId()) { const vcl::ILibreOfficeKitNotifier* pNotifier = pParent->GetLOKNotifier(); @@ -2035,26 +2101,26 @@ void ImpEditView::DeselectAll() bool ImpEditView::IsSelectionAtPoint( const Point& rPosPixel ) { - if ( pDragAndDropInfo && pDragAndDropInfo->pField ) + if (mpDragAndDropInfo && mpDragAndDropInfo->pField) return true; // Logical units ... const OutputDevice& rOutDev = GetOutputDevice(); Point aMousePos = rOutDev.PixelToLogic(rPosPixel); - if ( ( !GetOutputArea().IsInside( aMousePos ) ) && !pEditEngine->pImpEditEngine->IsInSelectionMode() ) + if ( ( !GetOutputArea().Contains( aMousePos ) ) && !getImpEditEngine().IsInSelectionMode() ) { return false; } Point aDocPos( GetDocPos( aMousePos ) ); - EditPaM aPaM = pEditEngine->GetPaM(aDocPos, false); + EditPaM aPaM = getEditEngine().GetPaM(aDocPos, false); return IsInSelection( aPaM ); } bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel ) { - pEditEngine->CheckIdleFormatter(); + getEditEngine().CheckIdleFormatter(); Point aMousePos( rPointPixel ); @@ -2062,7 +2128,7 @@ bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel ) const OutputDevice& rOutDev = GetOutputDevice(); aMousePos = rOutDev.PixelToLogic( aMousePos ); - if ( ( !GetOutputArea().IsInside( aMousePos ) ) && !pEditEngine->pImpEditEngine->IsInSelectionMode() ) + if ( ( !GetOutputArea().Contains( aMousePos ) ) && !getImpEditEngine().IsInSelectionMode() ) { return false; } @@ -2072,7 +2138,7 @@ bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel ) // Can be optimized: first go through the lines within a paragraph for PAM, // then again with the PaM for the Rect, even though the line is already // known... This must not be, though! - EditPaM aPaM = pEditEngine->GetPaM(aDocPos); + EditPaM aPaM = getEditEngine().GetPaM(aDocPos); bool bGotoCursor = DoAutoScroll(); // aTmpNewSel: Diff between old and new, not the new selection, unless for tiled rendering @@ -2083,10 +2149,14 @@ bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel ) EditSelection aNewEditSelection( GetEditSelection() ); aNewEditSelection.Max() = aPaM; - if (!pEditEngine->GetSelectionEngine().HasAnchor()) + if (!getEditEngine().GetSelectionEngine().HasAnchor()) { if ( aNewEditSelection.Min() != aPaM ) - pEditEngine->CursorMoved(aNewEditSelection.Min().GetNode()); + { + const ContentNode* pNode(aNewEditSelection.Min().GetNode()); + if (nullptr != pNode) + pNode->checkAndDeleteEmptyAttribs(); + } aNewEditSelection.Min() = aPaM; } else @@ -2100,29 +2170,29 @@ bool ImpEditView::SetCursorAtPoint( const Point& rPointPixel ) SetEditSelection( aNewEditSelection ); } - bool bForceCursor = pDragAndDropInfo == nullptr && !pEditEngine->pImpEditEngine->IsInSelectionMode(); + bool bForceCursor = mpDragAndDropInfo == nullptr && !getImpEditEngine().IsInSelectionMode(); ShowCursor( bGotoCursor, bForceCursor ); return true; } void ImpEditView::HideDDCursor() { - if ( pDragAndDropInfo && pDragAndDropInfo->bVisCursor ) + if (mpDragAndDropInfo && mpDragAndDropInfo->bVisCursor) { OutputDevice& rOutDev = GetOutputDevice(); - rOutDev.DrawOutDev( pDragAndDropInfo->aCurSavedCursor.TopLeft(), pDragAndDropInfo->aCurSavedCursor.GetSize(), - Point(0,0), pDragAndDropInfo->aCurSavedCursor.GetSize(),*pDragAndDropInfo->pBackground ); - pDragAndDropInfo->bVisCursor = false; + rOutDev.DrawOutDev(mpDragAndDropInfo->aCurSavedCursor.TopLeft(), mpDragAndDropInfo->aCurSavedCursor.GetSize(), + Point(0,0), mpDragAndDropInfo->aCurSavedCursor.GetSize(),*mpDragAndDropInfo->pBackground); + mpDragAndDropInfo->bVisCursor = false; } } void ImpEditView::ShowDDCursor( const tools::Rectangle& rRect ) { - if ( !pDragAndDropInfo || pDragAndDropInfo->bVisCursor ) + if (!mpDragAndDropInfo || mpDragAndDropInfo->bVisCursor) return; - if (pOutWin && pOutWin->GetCursor()) - pOutWin->GetCursor()->Hide(); + if (mpOutputWindow && mpOutputWindow->GetCursor()) + mpOutputWindow->GetCursor()->Hide(); OutputDevice& rOutDev = GetOutputDevice(); Color aOldFillColor = rOutDev.GetFillColor(); @@ -2134,71 +2204,67 @@ void ImpEditView::ShowDDCursor( const tools::Rectangle& rRect ) aSaveRect.AdjustRight(1 ); aSaveRect.AdjustBottom(1 ); -#ifdef DBG_UTIL - Size aNewSzPx( aSaveRect.GetSize() ); -#endif - if ( !pDragAndDropInfo->pBackground ) + if (!mpDragAndDropInfo->pBackground) { - pDragAndDropInfo->pBackground = VclPtr<VirtualDevice>::Create(rOutDev); + mpDragAndDropInfo->pBackground = VclPtr<VirtualDevice>::Create(rOutDev); MapMode aMapMode( rOutDev.GetMapMode() ); aMapMode.SetOrigin( Point( 0, 0 ) ); - pDragAndDropInfo->pBackground->SetMapMode( aMapMode ); + mpDragAndDropInfo->pBackground->SetMapMode( aMapMode ); } -#ifdef DBG_UTIL - Size aCurSzPx( pDragAndDropInfo->pBackground->GetOutputSizePixel() ); + Size aNewSzPx( aSaveRect.GetSize() ); + Size aCurSzPx(mpDragAndDropInfo->pBackground->GetOutputSizePixel()); if ( ( aCurSzPx.Width() < aNewSzPx.Width() ) ||( aCurSzPx.Height() < aNewSzPx.Height() ) ) { - bool bDone = pDragAndDropInfo->pBackground->SetOutputSizePixel( aNewSzPx ); + bool bDone = mpDragAndDropInfo->pBackground->SetOutputSizePixel( aNewSzPx ); DBG_ASSERT( bDone, "Virtual Device broken?" ); } -#endif aSaveRect = rOutDev.PixelToLogic( aSaveRect ); - pDragAndDropInfo->pBackground->DrawOutDev( Point(0,0), aSaveRect.GetSize(), + mpDragAndDropInfo->pBackground->DrawOutDev( Point(0,0), aSaveRect.GetSize(), aSaveRect.TopLeft(), aSaveRect.GetSize(), rOutDev ); - pDragAndDropInfo->aCurSavedCursor = aSaveRect; + mpDragAndDropInfo->aCurSavedCursor = aSaveRect; // Draw Cursor... rOutDev.DrawRect( rRect ); - pDragAndDropInfo->bVisCursor = true; - pDragAndDropInfo->aCurCursor = rRect; + mpDragAndDropInfo->bVisCursor = true; + mpDragAndDropInfo->aCurCursor = rRect; rOutDev.SetFillColor( aOldFillColor ); } void ImpEditView::dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& rDGE) { - DBG_ASSERT( !pDragAndDropInfo, "dragGestureRecognized - DragAndDropInfo exist!" ); + DBG_ASSERT(!mpDragAndDropInfo, "dragGestureRecognized - DragAndDropInfo exist!"); SolarMutexGuard aVclGuard; - pDragAndDropInfo.reset(); + mpDragAndDropInfo.reset(); Point aMousePosPixel( rDGE.DragOriginX, rDGE.DragOriginY ); EditSelection aCopySel( GetEditSelection() ); - aCopySel.Adjust( pEditEngine->GetEditDoc() ); + aCopySel.Adjust(getEditEngine().GetEditDoc()); - if ( HasSelection() && bClickedInSelection ) + if (HasSelection() && mbClickedInSelection) { - pDragAndDropInfo.reset(new DragAndDropInfo()); + mpDragAndDropInfo.reset(new DragAndDropInfo); } else { // Field?! sal_Int32 nPara; sal_Int32 nPos; - Point aMousePos = GetWindow()->PixelToLogic( aMousePosPixel ); + Point aMousePos = GetOutputDevice().PixelToLogic( aMousePosPixel ); const SvxFieldItem* pField = GetField( aMousePos, &nPara, &nPos ); if ( pField ) { - pDragAndDropInfo.reset(new DragAndDropInfo()); - pDragAndDropInfo->pField = pField; - ContentNode* pNode = pEditEngine->GetEditDoc().GetObject( nPara ); + mpDragAndDropInfo.reset(new DragAndDropInfo); + mpDragAndDropInfo->pField = pField; + ContentNode* pNode = getEditEngine().GetEditDoc().GetObject( nPara ); aCopySel = EditSelection( EditPaM( pNode, nPos ), EditPaM( pNode, nPos+1 ) ); SetEditSelection(aCopySel); DrawSelectionXOR(); @@ -2207,17 +2273,17 @@ void ImpEditView::dragGestureRecognized(const css::datatransfer::dnd::DragGestur } else if ( IsBulletArea( aMousePos, &nPara ) ) { - pDragAndDropInfo.reset(new DragAndDropInfo()); - pDragAndDropInfo->bOutlinerMode = true; - EditPaM aStartPaM( pEditEngine->GetEditDoc().GetObject( nPara ), 0 ); + mpDragAndDropInfo.reset(new DragAndDropInfo); + mpDragAndDropInfo->bOutlinerMode = true; + EditPaM aStartPaM(getEditEngine().GetEditDoc().GetObject(nPara), 0); EditPaM aEndPaM( aStartPaM ); - const SfxInt16Item& rLevel = pEditEngine->GetParaAttrib( nPara, EE_PARA_OUTLLEVEL ); - for ( sal_Int32 n = nPara +1; n < pEditEngine->GetEditDoc().Count(); n++ ) + const SfxInt16Item& rLevel = getEditEngine().GetParaAttrib(nPara, EE_PARA_OUTLLEVEL); + for ( sal_Int32 n = nPara +1; n < getEditEngine().GetEditDoc().Count(); n++ ) { - const SfxInt16Item& rL = pEditEngine->GetParaAttrib( n, EE_PARA_OUTLLEVEL ); + const SfxInt16Item& rL = getEditEngine().GetParaAttrib( n, EE_PARA_OUTLLEVEL ); if ( rL.GetValue() > rLevel.GetValue() ) { - aEndPaM.SetNode( pEditEngine->GetEditDoc().GetObject( n ) ); + aEndPaM.SetNode( getEditEngine().GetEditDoc().GetObject( n ) ); } else { @@ -2229,22 +2295,22 @@ void ImpEditView::dragGestureRecognized(const css::datatransfer::dnd::DragGestur } } - if ( !pDragAndDropInfo ) + if (!mpDragAndDropInfo) return; - pDragAndDropInfo->bStarterOfDD = true; + mpDragAndDropInfo->bStarterOfDD = true; // Sensitive area to be scrolled. Size aSz( 5, 0 ); - aSz = GetWindow()->PixelToLogic( aSz ); - pDragAndDropInfo->nSensibleRange = static_cast<sal_uInt16>(aSz.Width()); - pDragAndDropInfo->nCursorWidth = static_cast<sal_uInt16>(aSz.Width()) / 2; - pDragAndDropInfo->aBeginDragSel = pEditEngine->pImpEditEngine->CreateESel( aCopySel ); + aSz = GetOutputDevice().PixelToLogic( aSz ); + mpDragAndDropInfo->nSensibleRange = static_cast<sal_uInt16>(aSz.Width()); + mpDragAndDropInfo->nCursorWidth = static_cast<sal_uInt16>(aSz.Width()) / 2; + mpDragAndDropInfo->aBeginDragSel = getImpEditEngine().CreateESel( aCopySel ); - uno::Reference<datatransfer::XTransferable> xData = pEditEngine->CreateTransferable(aCopySel); + uno::Reference<datatransfer::XTransferable> xData = getEditEngine().CreateTransferable(aCopySel); - sal_Int8 nActions = bReadOnly ? datatransfer::dnd::DNDConstants::ACTION_COPY : datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE; + sal_Int8 nActions = mbReadOnly ? datatransfer::dnd::DNDConstants::ACTION_COPY : datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE; rDGE.DragSource->startDrag( rDGE, nActions, 0 /*cursor*/, 0 /*image*/, xData, mxDnDListener ); // If Drag&Move in an Engine, then Copy&Del has to be optional! @@ -2255,37 +2321,37 @@ void ImpEditView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent { SolarMutexGuard aVclGuard; - DBG_ASSERT( pDragAndDropInfo, "ImpEditView::dragDropEnd: pDragAndDropInfo is NULL!" ); + DBG_ASSERT(mpDragAndDropInfo, "ImpEditView::dragDropEnd: mpDragAndDropInfo is NULL!"); // #123688# Shouldn't happen, but seems to happen... - if ( !pDragAndDropInfo ) + if (!mpDragAndDropInfo) return; - if ( !bReadOnly && rDSDE.DropSuccess && !pDragAndDropInfo->bOutlinerMode && ( rDSDE.DropAction & datatransfer::dnd::DNDConstants::ACTION_MOVE ) ) + if (!mbReadOnly && rDSDE.DropSuccess && !mpDragAndDropInfo->bOutlinerMode && ( rDSDE.DropAction & datatransfer::dnd::DNDConstants::ACTION_MOVE ) ) { - if ( pDragAndDropInfo->bStarterOfDD && pDragAndDropInfo->bDroppedInMe ) + if (mpDragAndDropInfo->bStarterOfDD && mpDragAndDropInfo->bDroppedInMe ) { // DropPos: Where was it dropped, irrespective of length. - ESelection aDropPos( pDragAndDropInfo->aDropSel.nStartPara, pDragAndDropInfo->aDropSel.nStartPos, pDragAndDropInfo->aDropSel.nStartPara, pDragAndDropInfo->aDropSel.nStartPos ); - ESelection aToBeDelSel = pDragAndDropInfo->aBeginDragSel; - ESelection aNewSel( pDragAndDropInfo->aDropSel.nEndPara, pDragAndDropInfo->aDropSel.nEndPos, - pDragAndDropInfo->aDropSel.nEndPara, pDragAndDropInfo->aDropSel.nEndPos ); - bool bBeforeSelection = aDropPos < pDragAndDropInfo->aBeginDragSel; - sal_Int32 nParaDiff = pDragAndDropInfo->aBeginDragSel.nEndPara - pDragAndDropInfo->aBeginDragSel.nStartPara; + ESelection aDropPos(mpDragAndDropInfo->aDropSel.nStartPara, mpDragAndDropInfo->aDropSel.nStartPos, mpDragAndDropInfo->aDropSel.nStartPara, mpDragAndDropInfo->aDropSel.nStartPos ); + ESelection aToBeDelSel = mpDragAndDropInfo->aBeginDragSel; + ESelection aNewSel( mpDragAndDropInfo->aDropSel.nEndPara, mpDragAndDropInfo->aDropSel.nEndPos, + mpDragAndDropInfo->aDropSel.nEndPara, mpDragAndDropInfo->aDropSel.nEndPos ); + bool bBeforeSelection = aDropPos < mpDragAndDropInfo->aBeginDragSel; + sal_Int32 nParaDiff = mpDragAndDropInfo->aBeginDragSel.nEndPara - mpDragAndDropInfo->aBeginDragSel.nStartPara; if ( bBeforeSelection ) { // Adjust aToBeDelSel. - DBG_ASSERT( pDragAndDropInfo->aBeginDragSel.nStartPara >= pDragAndDropInfo->aDropSel.nStartPara, "But not before? "); + DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.nStartPara >= mpDragAndDropInfo->aDropSel.nStartPara, "But not before? "); aToBeDelSel.nStartPara = aToBeDelSel.nStartPara + nParaDiff; aToBeDelSel.nEndPara = aToBeDelSel.nEndPara + nParaDiff; // To correct the character? - if ( aToBeDelSel.nStartPara == pDragAndDropInfo->aDropSel.nEndPara ) + if ( aToBeDelSel.nStartPara == mpDragAndDropInfo->aDropSel.nEndPara ) { sal_uInt16 nMoreChars; - if ( pDragAndDropInfo->aDropSel.nStartPara == pDragAndDropInfo->aDropSel.nEndPara ) - nMoreChars = pDragAndDropInfo->aDropSel.nEndPos - pDragAndDropInfo->aDropSel.nStartPos; + if (mpDragAndDropInfo->aDropSel.nStartPara == mpDragAndDropInfo->aDropSel.nEndPara ) + nMoreChars = mpDragAndDropInfo->aDropSel.nEndPos - mpDragAndDropInfo->aDropSel.nStartPos; else - nMoreChars = pDragAndDropInfo->aDropSel.nEndPos; + nMoreChars = mpDragAndDropInfo->aDropSel.nEndPos; aToBeDelSel.nStartPos = aToBeDelSel.nStartPos + nMoreChars; if ( aToBeDelSel.nStartPara == aToBeDelSel.nEndPara ) @@ -2297,17 +2363,17 @@ void ImpEditView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent { // aToBeDelSel is ok, but the selection of the View // has to be adapted, if it was deleted before! - DBG_ASSERT( pDragAndDropInfo->aBeginDragSel.nStartPara <= pDragAndDropInfo->aDropSel.nStartPara, "But not before? "); + DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.nStartPara <= mpDragAndDropInfo->aDropSel.nStartPara, "But not before? "); aNewSel.nStartPara = aNewSel.nStartPara - nParaDiff; aNewSel.nEndPara = aNewSel.nEndPara - nParaDiff; // To correct the character? - if ( pDragAndDropInfo->aBeginDragSel.nEndPara == pDragAndDropInfo->aDropSel.nStartPara ) + if (mpDragAndDropInfo->aBeginDragSel.nEndPara == mpDragAndDropInfo->aDropSel.nStartPara ) { sal_uInt16 nLessChars; - if ( pDragAndDropInfo->aBeginDragSel.nStartPara == pDragAndDropInfo->aBeginDragSel.nEndPara ) - nLessChars = pDragAndDropInfo->aBeginDragSel.nEndPos - pDragAndDropInfo->aBeginDragSel.nStartPos; + if (mpDragAndDropInfo->aBeginDragSel.nStartPara == mpDragAndDropInfo->aBeginDragSel.nEndPara ) + nLessChars = mpDragAndDropInfo->aBeginDragSel.nEndPos - mpDragAndDropInfo->aBeginDragSel.nStartPos; else - nLessChars = pDragAndDropInfo->aBeginDragSel.nEndPos; + nLessChars = mpDragAndDropInfo->aBeginDragSel.nEndPos; aNewSel.nStartPos = aNewSel.nStartPos - nLessChars; if ( aNewSel.nStartPara == aNewSel.nEndPara ) aNewSel.nEndPos = aNewSel.nEndPos - nLessChars; @@ -2315,89 +2381,89 @@ void ImpEditView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent } DrawSelectionXOR(); - EditSelection aDelSel( pEditEngine->pImpEditEngine->CreateSel( aToBeDelSel ) ); - DBG_ASSERT( !aDelSel.DbgIsBuggy( pEditEngine->GetEditDoc() ), "ToBeDel is buggy!" ); - pEditEngine->DeleteSelection(aDelSel); + EditSelection aDelSel(getImpEditEngine().CreateSel(aToBeDelSel)); + DBG_ASSERT( !aDelSel.DbgIsBuggy(getEditEngine().GetEditDoc()), "ToBeDel is buggy!"); + getEditEngine().DeleteSelection(aDelSel); if ( !bBeforeSelection ) { - DBG_ASSERT( !pEditEngine->pImpEditEngine->CreateSel( aNewSel ).DbgIsBuggy(pEditEngine->GetEditDoc()), "Bad" ); - SetEditSelection( pEditEngine->pImpEditEngine->CreateSel( aNewSel ) ); + DBG_ASSERT(!getImpEditEngine().CreateSel(aNewSel).DbgIsBuggy(getEditEngine().GetEditDoc()), "Bad"); + SetEditSelection(getImpEditEngine().CreateSel(aNewSel)); } - pEditEngine->pImpEditEngine->FormatAndUpdate( pEditEngine->pImpEditEngine->GetActiveView() ); + getImpEditEngine().FormatAndLayout(getImpEditEngine().GetActiveView()); DrawSelectionXOR(); } else { // other EditEngine ... - if (pEditEngine->HasText()) // #88630# SC is removing the content when switching the task + if (getEditEngine().HasText()) // #88630# SC is removing the content when switching the task DeleteSelected(); } } - if ( pDragAndDropInfo->bUndoAction ) - pEditEngine->pImpEditEngine->UndoActionEnd(); + if (mpDragAndDropInfo->bUndoAction) + getImpEditEngine().UndoActionEnd(); HideDDCursor(); ShowCursor( DoAutoScroll(), true ); - pDragAndDropInfo.reset(); - pEditEngine->GetEndDropHdl().Call(GetEditViewPtr()); + mpDragAndDropInfo.reset(); + getEditEngine().GetEndDropHdl().Call(GetEditViewPtr()); } void ImpEditView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE ) { SolarMutexGuard aVclGuard; - DBG_ASSERT( pDragAndDropInfo, "Drop - No Drag&Drop info?!" ); + DBG_ASSERT(mpDragAndDropInfo, "Drop - No Drag&Drop info?!"); - if ( !(pDragAndDropInfo && pDragAndDropInfo->bDragAccepted) ) + if (!(mpDragAndDropInfo && mpDragAndDropInfo->bDragAccepted)) return; - pEditEngine->GetBeginDropHdl().Call(GetEditViewPtr()); + getEditEngine().GetBeginDropHdl().Call(GetEditViewPtr()); bool bChanges = false; HideDDCursor(); - if ( pDragAndDropInfo->bStarterOfDD ) + if (mpDragAndDropInfo->bStarterOfDD) { - pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_DRAGANDDROP ); - pDragAndDropInfo->bUndoAction = true; + getImpEditEngine().UndoActionStart( EDITUNDO_DRAGANDDROP ); + mpDragAndDropInfo->bUndoAction = true; } - if ( pDragAndDropInfo->bOutlinerMode ) + if (mpDragAndDropInfo->bOutlinerMode) { bChanges = true; - GetEditViewPtr()->MoveParagraphs( Range( pDragAndDropInfo->aBeginDragSel.nStartPara, pDragAndDropInfo->aBeginDragSel.nEndPara ), pDragAndDropInfo->nOutlinerDropDest ); + GetEditViewPtr()->MoveParagraphs(Range(mpDragAndDropInfo->aBeginDragSel.nStartPara, mpDragAndDropInfo->aBeginDragSel.nEndPara ), mpDragAndDropInfo->nOutlinerDropDest); } else { - uno::Reference< datatransfer::XTransferable > xDataObj = rDTDE.Transferable; + uno::Reference<datatransfer::XTransferable> xDataObj = rDTDE.Transferable; if ( xDataObj.is() ) { bChanges = true; // remove Selection ... DrawSelectionXOR(); - EditPaM aPaM( pDragAndDropInfo->aDropDest ); + EditPaM aPaM(mpDragAndDropInfo->aDropDest); PasteOrDropInfos aPasteOrDropInfos; - aPasteOrDropInfos.nStartPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); - pEditEngine->HandleBeginPasteOrDrop(aPasteOrDropInfos); + aPasteOrDropInfos.nStartPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); + getEditEngine().HandleBeginPasteOrDrop(aPasteOrDropInfos); - EditSelection aNewSel = pEditEngine->InsertText( - xDataObj, OUString(), aPaM, pEditEngine->GetInternalEditStatus().AllowPasteSpecial()); + EditSelection aNewSel = getEditEngine().InsertText( + xDataObj, OUString(), aPaM, getEditEngine().GetInternalEditStatus().AllowPasteSpecial()); - aPasteOrDropInfos.nEndPara = pEditEngine->GetEditDoc().GetPos( aNewSel.Max().GetNode() ); - pEditEngine->HandleEndPasteOrDrop(aPasteOrDropInfos); + aPasteOrDropInfos.nEndPara = getEditEngine().GetEditDoc().GetPos( aNewSel.Max().GetNode() ); + getEditEngine().HandleEndPasteOrDrop(aPasteOrDropInfos); SetEditSelection( aNewSel ); - pEditEngine->pImpEditEngine->FormatAndUpdate( pEditEngine->pImpEditEngine->GetActiveView() ); - if ( pDragAndDropInfo->bStarterOfDD ) + getImpEditEngine().FormatAndLayout(getImpEditEngine().GetActiveView()); + if (mpDragAndDropInfo->bStarterOfDD) { // Only set if the same engine! - pDragAndDropInfo->aDropSel.nStartPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); - pDragAndDropInfo->aDropSel.nStartPos = aPaM.GetIndex(); - pDragAndDropInfo->aDropSel.nEndPara = pEditEngine->GetEditDoc().GetPos( aNewSel.Max().GetNode() ); - pDragAndDropInfo->aDropSel.nEndPos = aNewSel.Max().GetIndex(); - pDragAndDropInfo->bDroppedInMe = true; + mpDragAndDropInfo->aDropSel.nStartPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); + mpDragAndDropInfo->aDropSel.nStartPos = aPaM.GetIndex(); + mpDragAndDropInfo->aDropSel.nEndPara = getEditEngine().GetEditDoc().GetPos( aNewSel.Max().GetNode() ); + mpDragAndDropInfo->aDropSel.nEndPos = aNewSel.Max().GetIndex(); + mpDragAndDropInfo->bDroppedInMe = true; } } } @@ -2407,9 +2473,9 @@ void ImpEditView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE rDTDE.Context->acceptDrop( rDTDE.DropAction ); } - if ( !pDragAndDropInfo->bStarterOfDD ) + if (!mpDragAndDropInfo->bStarterOfDD) { - pDragAndDropInfo.reset(); + mpDragAndDropInfo.reset(); } rDTDE.Context->dropComplete( bChanges ); @@ -2419,10 +2485,10 @@ void ImpEditView::dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEv { SolarMutexGuard aVclGuard; - if ( !pDragAndDropInfo ) - pDragAndDropInfo.reset(new DragAndDropInfo()); + if (!mpDragAndDropInfo) + mpDragAndDropInfo.reset(new DragAndDropInfo); - pDragAndDropInfo->bHasValidData = false; + mpDragAndDropInfo->bHasValidData = false; // Check for supported format... // Only check for text, will also be there if bin or rtf @@ -2434,7 +2500,7 @@ void ImpEditView::dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEv { if( TransferableDataHelper::IsEqual( pFlavors[n], aTextFlavor ) ) { - pDragAndDropInfo->bHasValidData = true; + mpDragAndDropInfo->bHasValidData = true; break; } } @@ -2448,9 +2514,9 @@ void ImpEditView::dragExit( const css::datatransfer::dnd::DropTargetEvent& ) HideDDCursor(); - if ( pDragAndDropInfo && !pDragAndDropInfo->bStarterOfDD ) + if (mpDragAndDropInfo && !mpDragAndDropInfo->bStarterOfDD) { - pDragAndDropInfo.reset(); + mpDragAndDropInfo.reset(); } } @@ -2465,9 +2531,9 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD bool bAccept = false; - if ( GetOutputArea().IsInside( aMousePos ) && !bReadOnly ) + if (GetOutputArea().Contains( aMousePos ) && !mbReadOnly) { - if ( pDragAndDropInfo && pDragAndDropInfo->bHasValidData ) + if (mpDragAndDropInfo && mpDragAndDropInfo->bHasValidData) { bAccept = true; @@ -2477,14 +2543,14 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD tools::Long nScrollX = 0; tools::Long nScrollY = 0; // Check if in the sensitive area - if ( ( (aMousePos.X()-pDragAndDropInfo->nSensibleRange) < GetOutputArea().Left() ) && ( ( aMousePos.X() + pDragAndDropInfo->nSensibleRange ) > GetOutputArea().Left() ) ) + if ( ( (aMousePos.X() - mpDragAndDropInfo->nSensibleRange) < GetOutputArea().Left() ) && ( ( aMousePos.X() + mpDragAndDropInfo->nSensibleRange ) > GetOutputArea().Left() ) ) nScrollX = GetOutputArea().GetWidth() / SCRLRANGE; - else if ( ( (aMousePos.X()+pDragAndDropInfo->nSensibleRange) > GetOutputArea().Right() ) && ( ( aMousePos.X() - pDragAndDropInfo->nSensibleRange ) < GetOutputArea().Right() ) ) + else if ( ( (aMousePos.X() + mpDragAndDropInfo->nSensibleRange) > GetOutputArea().Right() ) && ( ( aMousePos.X() - mpDragAndDropInfo->nSensibleRange ) < GetOutputArea().Right() ) ) nScrollX = -( GetOutputArea().GetWidth() / SCRLRANGE ); - if ( ( (aMousePos.Y()-pDragAndDropInfo->nSensibleRange) < GetOutputArea().Top() ) && ( ( aMousePos.Y() + pDragAndDropInfo->nSensibleRange ) > GetOutputArea().Top() ) ) + if ( ( (aMousePos.Y() - mpDragAndDropInfo->nSensibleRange) < GetOutputArea().Top() ) && ( ( aMousePos.Y() + mpDragAndDropInfo->nSensibleRange ) > GetOutputArea().Top() ) ) nScrollY = GetOutputArea().GetHeight() / SCRLRANGE; - else if ( ( (aMousePos.Y()+pDragAndDropInfo->nSensibleRange) > GetOutputArea().Bottom() ) && ( ( aMousePos.Y() - pDragAndDropInfo->nSensibleRange ) < GetOutputArea().Bottom() ) ) + else if ( ( (aMousePos.Y() + mpDragAndDropInfo->nSensibleRange) > GetOutputArea().Bottom() ) && ( ( aMousePos.Y() - mpDragAndDropInfo->nSensibleRange ) < GetOutputArea().Bottom() ) ) nScrollY = -( GetOutputArea().GetHeight() / SCRLRANGE ); if ( nScrollX || nScrollY ) @@ -2495,27 +2561,27 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD } Point aDocPos( GetDocPos( aMousePos ) ); - EditPaM aPaM = pEditEngine->GetPaM( aDocPos ); - pDragAndDropInfo->aDropDest = aPaM; - if ( pDragAndDropInfo->bOutlinerMode ) + EditPaM aPaM = getEditEngine().GetPaM( aDocPos ); + mpDragAndDropInfo->aDropDest = aPaM; + if (mpDragAndDropInfo->bOutlinerMode) { - sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() ); - ParaPortion* pPPortion = pEditEngine->GetParaPortions().SafeGetObject( nPara ); + sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); + ParaPortion* pPPortion = getEditEngine().GetParaPortions().SafeGetObject( nPara ); if (pPPortion) { - tools::Long nDestParaStartY = pEditEngine->GetParaPortions().GetYOffset( pPPortion ); + tools::Long nDestParaStartY = getEditEngine().GetParaPortions().GetYOffset( pPPortion ); tools::Long nRel = aDocPos.Y() - nDestParaStartY; if ( nRel < ( pPPortion->GetHeight() / 2 ) ) { - pDragAndDropInfo->nOutlinerDropDest = nPara; + mpDragAndDropInfo->nOutlinerDropDest = nPara; } else { - pDragAndDropInfo->nOutlinerDropDest = nPara+1; + mpDragAndDropInfo->nOutlinerDropDest = nPara+1; } - if( ( pDragAndDropInfo->nOutlinerDropDest >= pDragAndDropInfo->aBeginDragSel.nStartPara ) && - ( pDragAndDropInfo->nOutlinerDropDest <= (pDragAndDropInfo->aBeginDragSel.nEndPara+1) ) ) + if ((mpDragAndDropInfo->nOutlinerDropDest >= mpDragAndDropInfo->aBeginDragSel.nStartPara) && + (mpDragAndDropInfo->nOutlinerDropDest <= (mpDragAndDropInfo->aBeginDragSel.nEndPara + 1))) { bAccept = false; } @@ -2524,9 +2590,9 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD else if ( HasSelection() ) { // it must not be dropped into a selection - EPaM aP = pEditEngine->pImpEditEngine->CreateEPaM( aPaM ); + EPaM aP = getImpEditEngine().CreateEPaM( aPaM ); ESelection aDestSel( aP.nPara, aP.nIndex, aP.nPara, aP.nIndex); - ESelection aCurSel = pEditEngine->pImpEditEngine->CreateESel( GetEditSelection() ); + ESelection aCurSel = getImpEditEngine().CreateESel( GetEditSelection() ); aCurSel.Adjust(); if ( !(aDestSel < aCurSel) && !(aDestSel > aCurSel) ) { @@ -2536,25 +2602,25 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD if ( bAccept ) { tools::Rectangle aEditCursor; - if ( pDragAndDropInfo->bOutlinerMode ) + if (mpDragAndDropInfo->bOutlinerMode) { tools::Long nDDYPos(0); - if ( pDragAndDropInfo->nOutlinerDropDest < pEditEngine->GetEditDoc().Count() ) + if (mpDragAndDropInfo->nOutlinerDropDest < getEditEngine().GetEditDoc().Count()) { - ParaPortion* pPPortion = pEditEngine->GetParaPortions().SafeGetObject( pDragAndDropInfo->nOutlinerDropDest ); + ParaPortion* pPPortion = getEditEngine().GetParaPortions().SafeGetObject(mpDragAndDropInfo->nOutlinerDropDest); if (pPPortion) - nDDYPos = pEditEngine->GetParaPortions().GetYOffset( pPPortion ); + nDDYPos = getEditEngine().GetParaPortions().GetYOffset( pPPortion ); } else { - nDDYPos = pEditEngine->pImpEditEngine->GetTextHeight(); + nDDYPos = getImpEditEngine().GetTextHeight(); } Point aStartPos( 0, nDDYPos ); aStartPos = GetWindowPos( aStartPos ); Point aEndPos( GetOutputArea().GetWidth(), nDDYPos ); aEndPos = GetWindowPos( aEndPos ); aEditCursor = rOutDev.LogicToPixel( tools::Rectangle( aStartPos, aEndPos ) ); - if ( !pEditEngine->IsVertical() ) + if (!getEditEngine().IsEffectivelyVertical()) { aEditCursor.AdjustTop( -1 ); aEditCursor.AdjustBottom( 1 ); @@ -2576,21 +2642,21 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD } else { - aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM ); + aEditCursor = getImpEditEngine().PaMtoEditCursor( aPaM ); Point aTopLeft( GetWindowPos( aEditCursor.TopLeft() ) ); aEditCursor.SetPos( aTopLeft ); - aEditCursor.SetRight( aEditCursor.Left() + pDragAndDropInfo->nCursorWidth ); + aEditCursor.SetRight(aEditCursor.Left() + mpDragAndDropInfo->nCursorWidth); aEditCursor = rOutDev.LogicToPixel( aEditCursor ); aEditCursor = rOutDev.PixelToLogic( aEditCursor ); } - bool bCursorChanged = !pDragAndDropInfo->bVisCursor || ( pDragAndDropInfo->aCurCursor != aEditCursor ); + bool bCursorChanged = !mpDragAndDropInfo->bVisCursor || (mpDragAndDropInfo->aCurCursor != aEditCursor); if ( bCursorChanged ) { HideDDCursor(); ShowDDCursor(aEditCursor ); } - pDragAndDropInfo->bDragAccepted = true; + mpDragAndDropInfo->bDragAccepted = true; rDTDE.Context->acceptDrag( rDTDE.DropAction ); } } @@ -2599,30 +2665,29 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD if ( !bAccept ) { HideDDCursor(); - if (pDragAndDropInfo) - pDragAndDropInfo->bDragAccepted = false; + if (mpDragAndDropInfo) + mpDragAndDropInfo->bDragAccepted = false; rDTDE.Context->rejectDrag(); } } void ImpEditView::AddDragAndDropListeners() { - if (bActiveDragAndDropListener) + if (mbActiveDragAndDropListener) return; - css::uno::Reference<css::datatransfer::dnd::XDropTarget> xDropTarget; + uno::Reference<datatransfer::dnd::XDropTarget> xDropTarget; if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) xDropTarget = pCallbacks->GetDropTarget(); - else if (GetWindow()) - xDropTarget = GetWindow()->GetDropTarget(); + else if (auto xWindow = GetWindow()) + xDropTarget = xWindow->GetDropTarget(); if (!xDropTarget.is()) return; - vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper(this); - mxDnDListener = pDnDWrapper; + mxDnDListener = new vcl::unohelper::DragAndDropWrapper(this); - css::uno::Reference<css::datatransfer::dnd::XDragGestureRecognizer> xDragGestureRecognizer(xDropTarget, uno::UNO_QUERY); + uno::Reference<datatransfer::dnd::XDragGestureRecognizer> xDragGestureRecognizer(xDropTarget, uno::UNO_QUERY); if (xDragGestureRecognizer.is()) { uno::Reference<datatransfer::dnd::XDragGestureListener> xDGL(mxDnDListener, uno::UNO_QUERY); @@ -2634,32 +2699,32 @@ void ImpEditView::AddDragAndDropListeners() xDropTarget->setActive(true); xDropTarget->setDefaultActions(datatransfer::dnd::DNDConstants::ACTION_COPY_OR_MOVE); - bActiveDragAndDropListener = true; + mbActiveDragAndDropListener = true; } void ImpEditView::RemoveDragAndDropListeners() { - if (!bActiveDragAndDropListener) + if (!mbActiveDragAndDropListener) return; - css::uno::Reference<css::datatransfer::dnd::XDropTarget> xDropTarget; + uno::Reference<datatransfer::dnd::XDropTarget> xDropTarget; if (EditViewCallbacks* pCallbacks = getEditViewCallbacks()) xDropTarget = pCallbacks->GetDropTarget(); - else if (GetWindow()) - xDropTarget = GetWindow()->GetDropTarget(); + else if (auto xWindow = GetWindow()) + xDropTarget = xWindow->GetDropTarget(); - if (!xDropTarget.is()) - return; - - css::uno::Reference<css::datatransfer::dnd::XDragGestureRecognizer> xDragGestureRecognizer(xDropTarget, uno::UNO_QUERY); - if (xDragGestureRecognizer.is()) + if (xDropTarget.is()) { - uno::Reference<datatransfer::dnd::XDragGestureListener> xDGL(mxDnDListener, uno::UNO_QUERY); - xDragGestureRecognizer->removeDragGestureListener(xDGL); - } + uno::Reference<datatransfer::dnd::XDragGestureRecognizer> xDragGestureRecognizer(xDropTarget, uno::UNO_QUERY); + if (xDragGestureRecognizer.is()) + { + uno::Reference<datatransfer::dnd::XDragGestureListener> xDGL(mxDnDListener, uno::UNO_QUERY); + xDragGestureRecognizer->removeDragGestureListener(xDGL); + } - uno::Reference<datatransfer::dnd::XDropTargetListener> xDTL(mxDnDListener, uno::UNO_QUERY); - xDropTarget->removeDropTargetListener(xDTL); + uno::Reference<datatransfer::dnd::XDropTargetListener> xDTL(mxDnDListener, uno::UNO_QUERY); + xDropTarget->removeDropTargetListener(xDTL); + } if ( mxDnDListener.is() ) { @@ -2667,7 +2732,7 @@ void ImpEditView::RemoveDragAndDropListeners() mxDnDListener.clear(); } - bActiveDragAndDropListener = false; + mbActiveDragAndDropListener = false; } void ImpEditView::InitLOKSpecialPositioning(MapUnit eUnit, @@ -2686,7 +2751,7 @@ void ImpEditView::SetLOKSpecialOutputArea(const tools::Rectangle& rOutputArea) mpLOKSpecialPositioning->SetOutputArea(rOutputArea); } -tools::Rectangle ImpEditView::GetLOKSpecialOutputArea() const +const tools::Rectangle & ImpEditView::GetLOKSpecialOutputArea() const { assert(mpLOKSpecialPositioning); return mpLOKSpecialPositioning->GetOutputArea(); @@ -2709,4 +2774,10 @@ bool ImpEditView::HasLOKSpecialPositioning() const return bool(mpLOKSpecialPositioning); } +void ImpEditView::SetLOKSpecialFlags(LOKSpecialFlags eFlags) +{ + assert(mpLOKSpecialPositioning); + mpLOKSpecialPositioning->SetFlags(eFlags); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |