From f1ff0ec57914e8871f8563cd26ee1b87d562f1c8 Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Mon, 10 Jan 2022 12:03:54 +0530 Subject: lokCalcRTL: fix chart insertion position Change-Id: I573cb19643d7a048f3313aba90fa9b5514c9cc74 --- sc/source/ui/view/tabview.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx index f1aa58eabaf3..4dda1b46aa50 100644 --- a/sc/source/ui/view/tabview.cxx +++ b/sc/source/ui/view/tabview.cxx @@ -1703,9 +1703,12 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange ActivatePart( eUsedPart ); // get the visible rectangle in logic units - + bool bLOKActive = comphelper::LibreOfficeKit::isActive(); MapMode aDrawMode = pWin->GetDrawMapMode(); - tools::Rectangle aVisible( pWin->PixelToLogic( tools::Rectangle( Point(0,0), pWin->GetOutputSizePixel() ), aDrawMode ) ); + tools::Rectangle aVisible( + bLOKActive ? + OutputDevice::LogicToLogic( aViewData.getLOKVisibleArea(), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM) ) + : pWin->PixelToLogic( tools::Rectangle( Point(0,0), pWin->GetOutputSizePixel() ), aDrawMode ) ); ScDocument& rDoc = aViewData.GetDocument(); SCTAB nTab = aViewData.GetTabNo(); @@ -1729,6 +1732,14 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange tools::Rectangle aSelection = rDoc.GetMMRect( rCellRange.aStart.Col(), rCellRange.aStart.Row(), rCellRange.aEnd.Col(), rCellRange.aEnd.Row(), nTab ); + if (bLOKActive && bLayoutRTL) + { + // In this case we operate in negative X coordinates. The rectangle aSelection already + // has negative X coordinates. So the x coordinates in the rectangle aVisible(from getLOKVisibleArea) + // need be negated to match. + aVisible = tools::Rectangle(-aVisible.Right(), aVisible.Top(), -aVisible.Left(), aVisible.Bottom()); + } + tools::Long nLeftSpace = aSelection.Left() - aVisible.Left(); tools::Long nRightSpace = aVisible.Right() - aSelection.Right(); tools::Long nTopSpace = aSelection.Top() - aVisible.Top(); @@ -1755,7 +1766,6 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, const ScRange& rCellRange else if ( nTopSpace >= nNeededHeight || nBottomSpace >= nNeededHeight ) { // second preference: completely above or below the selection - if ( nBottomSpace > nNeededHeight ) // bottom is preferred aInsertPos.setY( aSelection.Bottom() + 1 ); else -- cgit