[Libreoffice-commits] core.git: Branch 'feature/gsoc14-draw-chained-text-boxes' - include/svx svx/source

matteocam matteo.campanelli at gmail.com
Thu Jul 23 16:39:57 PDT 2015


 include/svx/textchaincursor.hxx       |    4 +
 svx/source/svdraw/svdedxv.cxx         |    3 +
 svx/source/svdraw/textchaincursor.cxx |   85 +++++++++++++++++++++-------------
 3 files changed, 61 insertions(+), 31 deletions(-)

New commits:
commit 4ded1c96716ac12fabda495901f677d366265926
Author: matteocam <matteo.campanelli at gmail.com>
Date:   Fri Jul 24 01:38:16 2015 +0200

    Add specific method for detecting event
    
    Change-Id: I3030f4a5c80bcade440fb66d578430abb15dfc44

diff --git a/include/svx/textchaincursor.hxx b/include/svx/textchaincursor.hxx
index ce5200f..b56dd72 100644
--- a/include/svx/textchaincursor.hxx
+++ b/include/svx/textchaincursor.hxx
@@ -23,6 +23,7 @@
 class SdrObjEditView;
 class SdrTextObj;
 class KeyEvent;
+class SdrOutliner;
 
 
 class TextChainCursorManager
@@ -39,6 +40,9 @@ private:
     const SdrTextObj *mpTextObj;
 
     void impChangeEditingTextObj(SdrTextObj *pTargetTextObj, ESelection aNewSel) const;
+    void impDetectEvent(const KeyEvent& rKEvt,
+                        CursorChainingEvent *pOutCursorEvt,
+                        ESelection *pOutSel) const;
 };
 
 
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index 15e2228..c9428dc 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -1266,6 +1266,9 @@ bool SdrObjEditView::ImpHandleMotionThroughBoxesKeyInput(const KeyEvent& rKEvt,
     else
         return false;
 
+    if (!pTextObj->IsChainable())
+        return false;
+
     TextChainCursorManager aCursorManager(this, pTextObj);
     if( aCursorManager.HandleKeyEvent(rKEvt) ) {
         // Possibly do other stuff here if necessary...
diff --git a/svx/source/svdraw/textchaincursor.cxx b/svx/source/svdraw/textchaincursor.cxx
index a0def07..7ca44f7 100644
--- a/svx/source/svdraw/textchaincursor.cxx
+++ b/svx/source/svdraw/textchaincursor.cxx
@@ -30,49 +30,73 @@ TextChainCursorManager::TextChainCursorManager(SdrObjEditView *pEditView, const
     mpEditView(pEditView),
     mpTextObj(pTextObj)
 {
+    assert(mpEditView);
+    assert(mpTextObj);
 
 }
 
 bool TextChainCursorManager::HandleKeyEvent( const KeyEvent& rKEvt ) const
 {
-    bool bHandled = false;
+    ESelection aNewSel;
+    CursorChainingEvent aCursorEvent;
+
+    // check what the cursor/event situation looks like
+    impDetectEvent(rKEvt, &aCursorEvent, &aNewSel);
+
+    if (aCursorEvent == CursorChainingEvent::NULL_EVENT)
+        return false;
+    else {
+        HandleCursorEvent(aCursorEvent, aNewSel);
+        return true;
+    }
+}
+
+void TextChainCursorManager::impDetectEvent(const KeyEvent& rKEvt,
+                                            CursorChainingEvent *pOutCursorEvt,
+                                            ESelection *pOutSel) const
+{
+    SdrOutliner *pOutl = mpEditView->GetTextEditOutliner();
+    OutlinerView *pOLV = mpEditView->GetTextEditOutlinerView();
 
-    // XXX: Find a clean way to do this (even cleaner than the code commented below)
-    // if( pTextEditOutlinerView->IsKeyEventPushingOutOfPage(rKevt, pWin)
-    //       pWin = HandleKeyPushingOutOfBox(rKevt);
     KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction();
-    sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
-    ESelection aCurSel = mpEditView->GetTextEditOutlinerView()->GetSelection();
 
-    if (mpTextObj && mpTextObj->IsChainable() && mpTextObj->GetNextLinkInChain() &&
-        eFunc ==  KeyFuncType::DONTKNOW)
+    // We need to have this KeyFuncType
+    if (eFunc !=  KeyFuncType::DONTKNOW)
     {
-        SdrOutliner *pOutl = mpEditView->GetTextEditOutliner();
-        sal_Int32 nLastPara = pOutl->GetParagraphCount()-1;
-        OUString aLastParaText = pOutl->GetText(pOutl->GetParagraph(nLastPara));
-        sal_Int32 nLastParaLen = aLastParaText.getLength();
-
-        if (nCode == KEY_RIGHT &&
-            aCurSel.nEndPara == nLastPara &&
-            aCurSel.nEndPos == nLastParaLen
-            )
-        {
-            fprintf(stderr, "[CHAIN - CURSOR] Trying to move to next box\n" );
-
-            // Move to next box
-            mpEditView->SdrEndTextEdit();
-            SdrTextObj *pNextLink = mpTextObj->GetNextLinkInChain();
-            mpEditView->SdrBeginTextEdit(pNextLink);
-            bHandled = true;
-        }
+        *pOutCursorEvt = CursorChainingEvent::NULL_EVENT;
+        return;
+    }
 
+    sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
+    ESelection aCurSel = pOLV->GetSelection();
+
+    sal_Int32 nLastPara = pOutl->GetParagraphCount()-1;
+    OUString aLastParaText = pOutl->GetText(pOutl->GetParagraph(nLastPara));
+    sal_Int32 nLastParaLen = aLastParaText.getLength();
+
+    bool bAtEndOfTextContent =
+        (aCurSel.nEndPara == nLastPara) &&
+        (aCurSel.nEndPos == nLastParaLen);
+
+    if (nCode == KEY_RIGHT && bAtEndOfTextContent)
+    {
+        *pOutCursorEvt = CursorChainingEvent::TO_NEXT_LINK;
+        // Selection unchanged: we are at the beginning of the box
     }
-    return bHandled;
+
+    // if (nCode == KEY_LEFT && bAtStartOfTextContent) ...
+
+    // If arrived here there is no event detected
+    *pOutCursorEvt = CursorChainingEvent::NULL_EVENT;
+
 }
 
-void TextChainCursorManager::HandleCursorEvent(const CursorChainingEvent aCurEvt,
-                           const ESelection  aNewSel) const
+void TextChainCursorManager::HandleCursorEvent(
+                            const CursorChainingEvent aCurEvt,
+                            const ESelection  aNewSel)
+                            const
 {
+
     OutlinerView* pOLV = mpEditView->GetTextEditOutlinerView();
     SdrTextObj *pNextLink = mpTextObj->GetNextLinkInChain();
     SdrTextObj *pPrevLink = mpTextObj->GetPrevLinkInChain();
@@ -99,8 +123,7 @@ void TextChainCursorManager::HandleCursorEvent(const CursorChainingEvent aCurEvt
 
 void TextChainCursorManager::impChangeEditingTextObj(SdrTextObj *pTargetTextObj, ESelection aNewSel) const
 {
-    if (!pTargetTextObj)
-        return;
+    assert(pTargetTextObj);
 
     mpEditView->SdrEndTextEdit();
     mpEditView->SdrBeginTextEdit(pTargetTextObj);


More information about the Libreoffice-commits mailing list