From 31f896bb6ef922cf4250c6b971fb9d24a60592b5 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 21 Feb 2019 21:22:15 +0100 Subject: sw btlr writing mode shell: fix up/down cursor travelling By teaching SwEditWin::KeyInput() about 2 vertical modes: the existing tbrl one and the new btlr one. Up now correctly goes to the next character and down to the previous one. Change-Id: I71faebe62e5fa3892b37e8bea6c15d1fb84df5d1 Reviewed-on: https://gerrit.libreoffice.org/68183 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/inc/crsrsh.hxx | 3 +-- sw/qa/extras/layout/layout.cxx | 13 +++++++++++++ sw/source/core/crsr/crsrsh.cxx | 3 ++- sw/source/core/docnode/node.cxx | 4 +++- sw/source/uibase/docvw/edtwin.cxx | 28 ++++++++++++++++++++++------ sw/source/uibase/inc/edtwin.hxx | 5 +++-- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index 423ed92fb1b4..e8144d4a52ba 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -258,8 +258,6 @@ private: SAL_DLLPRIVATE bool LRMargin( bool, bool bAPI = false ); SAL_DLLPRIVATE bool IsAtLRMargin( bool, bool bAPI = false ) const; - SAL_DLLPRIVATE SvxFrameDirection GetTextDirection( const Point* pPt = nullptr ) const; - SAL_DLLPRIVATE bool isInHiddenTextFrame(SwShellCursor* pShellCursor); SAL_DLLPRIVATE bool GoStartWordImpl(); @@ -811,6 +809,7 @@ public: const SwRangeRedline* SelPrevRedline(); const SwRangeRedline* GotoRedline( SwRedlineTable::size_type nArrPos, bool bSelect ); + SAL_DLLPRIVATE SvxFrameDirection GetTextDirection( const Point* pPt = nullptr ) const; // is cursor or the point in/over a vertical formatted text? bool IsInVerticalText( const Point* pPt = nullptr ) const; // is cursor or the point in/over a right to left formatted text? diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index cb94560ab03a..a1f805d42bd9 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -14,10 +14,13 @@ #include #include #include +#include #include #include #include #include +#include +#include static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/"; @@ -2836,6 +2839,16 @@ void SwLayoutWriter::testBtlrCell() // range was 2273 -> 2835, the good vertical position is 2730, the bad one was 1830. CPPUNIT_ASSERT_GREATER(nFirstParaMiddle, rCharRect.Top()); CPPUNIT_ASSERT_LESS(nFirstParaBottom, rCharRect.Top()); + + // Test that pressing "up" at the start of the cell goes to the next character position. + sal_Int32 nIndex = pWrtShell->GetCursor()->Start()->nContent.GetIndex(); + KeyEvent aKeyEvent(0, KEY_UP); + SwEditWin& rEditWin = pShell->GetView()->GetEditWin(); + rEditWin.KeyInput(aKeyEvent); + Scheduler::ProcessEventsToIdle(); + // Without the accompanying fix in place, this test would have failed: "up" was interpreted as + // logical "left", which does nothing if you're at the start of the text anyway. + CPPUNIT_ASSERT_EQUAL(nIndex + 1, pWrtShell->GetCursor()->Start()->nContent.GetIndex()); #endif } diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 18b2d348e5c0..8d36a0e9e6f7 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -3276,7 +3276,8 @@ SvxFrameDirection SwCursorShell::GetTextDirection( const Point* pPt ) const bool SwCursorShell::IsInVerticalText( const Point* pPt ) const { const SvxFrameDirection nDir = GetTextDirection( pPt ); - return SvxFrameDirection::Vertical_RL_TB == nDir || SvxFrameDirection::Vertical_LR_TB == nDir; + return SvxFrameDirection::Vertical_RL_TB == nDir || SvxFrameDirection::Vertical_LR_TB == nDir + || nDir == SvxFrameDirection::Vertical_LR_BT; } bool SwCursorShell::IsInRightToLeftText() const diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 2ef8b3400a85..56c20dc229d0 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -1993,7 +1993,9 @@ SvxFrameDirection SwContentNode::GetTextDirection( const SwPosition& rPos, { if ( pFrame->IsVertical() ) { - if ( pFrame->IsRightToLeft() ) + if (pFrame->IsVertLRBT()) + nRet = SvxFrameDirection::Vertical_LR_BT; + else if (pFrame->IsRightToLeft()) nRet = SvxFrameDirection::Vertical_LR_TB; else nRet = SvxFrameDirection::Vertical_RL_TB; diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 9d947f235f38..22458d77b710 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -1454,12 +1454,28 @@ void SwEditWin::KeyInput(const KeyEvent &rKEvt) if( ( bVertText && ( !bTableCursor || bVertTable ) ) || ( bTableCursor && bVertTable ) ) { - // Attempt to integrate cursor travelling for mongolian layout does not work. - // Thus, back to previous mapping of cursor keys to direction keys. - if( KEY_UP == nKey ) nKey = KEY_LEFT; - else if( KEY_DOWN == nKey ) nKey = KEY_RIGHT; - else if( KEY_LEFT == nKey ) nKey = KEY_DOWN; - else /* KEY_RIGHT == nKey */ nKey = KEY_UP; + SvxFrameDirection eDirection = rSh.GetTextDirection(); + if (eDirection == SvxFrameDirection::Vertical_LR_BT) + { + // Map from physical to logical, so rotate clockwise. + if (KEY_UP == nKey) + nKey = KEY_RIGHT; + else if (KEY_DOWN == nKey) + nKey = KEY_LEFT; + else if (KEY_LEFT == nKey) + nKey = KEY_UP; + else /* KEY_RIGHT == nKey */ + nKey = KEY_DOWN; + } + else + { + // Attempt to integrate cursor travelling for mongolian layout does not work. + // Thus, back to previous mapping of cursor keys to direction keys. + if( KEY_UP == nKey ) nKey = KEY_LEFT; + else if( KEY_DOWN == nKey ) nKey = KEY_RIGHT; + else if( KEY_LEFT == nKey ) nKey = KEY_DOWN; + else /* KEY_RIGHT == nKey */ nKey = KEY_UP; + } } if ( rSh.IsInRightToLeftText() ) diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx index 0f63aa229884..abb7f4cd68a4 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -56,12 +56,13 @@ enum class SdrHitKind; To translate the pixel positions from the buffer OutputDevice to the real pixel positions, use the PixelToLogic methods of this class. */ -class SwEditWin final : public vcl::Window, +class SW_DLLPUBLIC SwEditWin final : public vcl::Window, public DropTargetHelper, public DragSourceHelper { static QuickHelpData* m_pQuickHlpData; - static long m_nDDStartPosX, m_nDDStartPosY; + static long m_nDDStartPosX; + static long m_nDDStartPosY; Color m_aWaterCanTextColor; // text color; for the watering can Color m_aWaterCanTextBackColor; // text background; for the watering can -- cgit v1.2.3