summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2020-04-14 14:49:23 +0530
committerDennis Francis <dennisfrancis.in@gmail.com>2020-05-26 23:17:27 +0530
commitc75d894ae66c306df765315a07e0dad3e78ea60b (patch)
tree1ec84fd4f8364838f10e4027d63ae196e653f086 /editeng
parenta365fc8bc997a9b607d9a58511418c7bfaa5df8a (diff)
lokit: fix edit-text/view-cursor position
in case of views with heterogeneous zooms. 1. EditText render position fix The EditView has an 'output-area' which is used to clip the rectangle we pass to the Paint() call. It also holds on to the ScGridWindow instance where the edit started. The 'output-area' of the EditView is in the coordinates/units of the MapMode of the ScGridWindow it holds. So we need to temporarily change the MapMode and 'output-area' of the EditView in agreement to the device(with the current view's zoom settings) where we are going to paint to. After we call the Paint(), we rollback the original settings of the EditView. 2. EditViewCursor position fix Before this change the cursor position in twips (calculated based on pixel aligned cell position in the view where editing occurred) is broadcasted to all the client-views. If the clients have different zooms, then simply scaling this common cursor position in the client for its zoom is not going to be accurate enough (due to the non-linear Logic->Pixel->Logic transformation involving pixel rounding). This is very visible if you are editing far away from A1 (like Z50). The fix is to turn off this broadcast for calc-cell editing and send view specific edit-cursor invalidation messages. This is accompanied by a online.git patch that removes unnessecary broadcast of view-cursor invalidation messages which messes up things again. "Do not broadcast view-cursor invalidation messages" Change-Id: Ib2fbbe4b6f93f26fc85d6adaa8684dd4397d886f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92631 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com> (cherry picked from commit d58f1e334245f9e136750fbba267c2a941a213cc) Conflicts: editeng/source/editeng/impedit.hxx
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/editview.cxx10
-rw-r--r--editeng/source/editeng/impedit.cxx97
-rw-r--r--editeng/source/editeng/impedit.hxx10
3 files changed, 87 insertions, 30 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index eaa9fe05e932..be91080cceb8 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -475,6 +475,16 @@ void EditView::Command( const CommandEvent& rCEvt )
pImpEditView->Command( rCEvt );
}
+void EditView::SetBroadcastLOKViewCursor(bool bSet)
+{
+ pImpEditView->SetBroadcastLOKViewCursor(bSet);
+}
+
+tools::Rectangle EditView::GetEditCursor() const
+{
+ return pImpEditView->GetEditCursor();
+}
+
void EditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor, bool bActivate )
{
if ( pImpEditView->pEditEngine->HasView( this ) )
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index 7a2a3e412301..6c7360d41fea 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -82,6 +82,7 @@ ImpEditView::ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindo
eSelectionMode = EESelectionMode::Std;
eAnchorMode = EEAnchorMode::TopLeft;
mpEditViewCallbacks = nullptr;
+ mbBroadcastLOKViewCursor = comphelper::LibreOfficeKit::isActive();
nInvMore = 1;
nTravelXPos = TRAVEL_X_DONTKNOW;
nControl = EVControlBits::AUTOSCROLL | EVControlBits::ENABLEPASTE;
@@ -914,6 +915,69 @@ OString buildHyperlinkJSON(const OUString& sText, const OUString& sLink)
} // End of anon namespace
+tools::Rectangle ImpEditView::ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags, sal_Int32& nTextPortionStart,
+ const ParaPortion* pParaPortion) const
+{
+ tools::Rectangle aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, nShowCursorFlags );
+ if ( !IsInsertMode() && !aEditSelection.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.SetRight( aEditCursor.Left() );
+
+ sal_Int32 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true );
+ const TextPortion& rTextPortion = pParaPortion->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 );
+ if ( aTmpRect.Top() != aEditCursor.Top() )
+ aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine );
+ aEditCursor.SetRight( aTmpRect.Left() );
+ }
+ }
+ }
+
+ long nMaxHeight = !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth();
+ if ( aEditCursor.GetHeight() > nMaxHeight )
+ {
+ aEditCursor.SetBottom( aEditCursor.Top() + nMaxHeight - 1 );
+ }
+
+ return aEditCursor;
+}
+
+tools::Rectangle ImpEditView::GetEditCursor() const
+{
+ EditPaM aPaM( aEditSelection.Max() );
+
+ sal_Int32 nTextPortionStart = 0;
+ sal_Int32 nPara = pEditEngine->GetEditDoc().GetPos( aPaM.GetNode() );
+ if (nPara == EE_PARA_NOT_FOUND) // #i94322
+ return tools::Rectangle();
+
+ const ParaPortion* pParaPortion = pEditEngine->GetParaPortions()[nPara];
+
+ GetCursorFlags nShowCursorFlags = nExtraCursorFlags | GetCursorFlags::TextOnly;
+
+ // Use CursorBidiLevel 0/1 in meaning of
+ // 0: prefer portion end, normal mode
+ // 1: prefer portion start
+
+ if ( ( GetCursorBidiLevel() != CURSOR_BIDILEVEL_DONTKNOW ) && GetCursorBidiLevel() )
+ {
+ nShowCursorFlags |= GetCursorFlags::PreferPortionStart;
+ }
+
+ return ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, pParaPortion);
+}
+
void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
{
// No ShowCursor in an empty View ...
@@ -958,36 +1022,8 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
nShowCursorFlags |= GetCursorFlags::PreferPortionStart;
}
- tools::Rectangle aEditCursor = pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, nShowCursorFlags );
- if ( !IsInsertMode() && !aEditSelection.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.SetRight( aEditCursor.Left() );
+ tools::Rectangle aEditCursor = ImplGetEditCursor(aPaM, nShowCursorFlags, nTextPortionStart, pParaPortion);
- sal_Int32 nTextPortion = pParaPortion->GetTextPortions().FindPortion( aPaM.GetIndex(), nTextPortionStart, true );
- const TextPortion& rTextPortion = pParaPortion->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 );
- if ( aTmpRect.Top() != aEditCursor.Top() )
- aTmpRect = pEditEngine->pImpEditEngine->PaMtoEditCursor( aNext, GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine );
- aEditCursor.SetRight( aTmpRect.Left() );
- }
- }
- }
- long nMaxHeight = !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth();
- if ( aEditCursor.GetHeight() > nMaxHeight )
- {
- aEditCursor.SetBottom( aEditCursor.Top() + nMaxHeight - 1 );
- }
if ( bGotoCursor ) // && (!pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() ) )
{
// check if scrolling is necessary...
@@ -1178,7 +1214,8 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
}
SfxLokHelper::notifyVisCursorInvalidation(mpViewShell, sRect, bIsWrong, sHyperlink);
- mpViewShell->NotifyOtherViews(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+ if (mbBroadcastLOKViewCursor)
+ mpViewShell->NotifyOtherViews(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
}
}
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 26c9d25961fa..420bc67d13bf 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -269,6 +269,7 @@ private:
// in Draw/Impress in an OverlayObject which avoids evtl. expensive full
// repaints of the EditView(s)
const EditViewCallbacks* mpEditViewCallbacks;
+ bool mbBroadcastLOKViewCursor;
const EditViewCallbacks* getEditViewCallbacks() const
{
@@ -285,6 +286,11 @@ private:
css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const;
css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetSelection() const;
+ void SetBroadcastLOKViewCursor(bool bSet)
+ {
+ mbBroadcastLOKViewCursor = bSet;
+ }
+
protected:
// DragAndDropClient
@@ -299,6 +305,8 @@ protected:
void HideDDCursor();
void ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly );
+ tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags,
+ sal_Int32& nTextPortionStart, const ParaPortion* pParaPortion) const;
public:
ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindow );
@@ -377,6 +385,8 @@ public:
void CalcAnchorPoint();
void RecalcOutputArea();
+ tools::Rectangle GetEditCursor() const;
+
void ShowCursor( bool bGotoCursor, bool bForceVisCursor );
Pair Scroll( long ndX, long ndY, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );