summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-01-28 13:10:33 +0000
committerCaolán McNamara <caolanm@redhat.com>2015-01-28 13:49:28 +0000
commitd04540a55f533279d2b404223cc625fa251a6ea2 (patch)
treebddf3889ba50d0bf249af8532eed6a260e74dceb
parent2208e85c5fc48f43be48b2240cc95421b47f1eb1 (diff)
Resolves: fdo#50640 make sure we don't move away from the current field
by accident by trying to select the entire field if its inside an invisible area where WrtShell::Right will skip automatically to the next visible area Change-Id: Iafe9ebd1430db8e6022fec89729d0abb62dad0bb
-rw-r--r--sw/source/ui/fldui/fldedt.cxx65
-rw-r--r--sw/source/uibase/inc/fldedt.hxx4
2 files changed, 44 insertions, 25 deletions
diff --git a/sw/source/ui/fldui/fldedt.cxx b/sw/source/ui/fldui/fldedt.cxx
index 8a1eb1eb0690..32dd26eebaff 100644
--- a/sw/source/ui/fldui/fldedt.cxx
+++ b/sw/source/ui/fldui/fldedt.cxx
@@ -49,6 +49,44 @@
#include <boost/scoped_ptr.hpp>
#include <swuiexp.hxx>
+void SwFldEditDlg::EnsureSelection(SwField *pCurFld, SwFldMgr &rMgr)
+{
+ if (pSh->CrsrInsideInputFld())
+ {
+ // move cursor to start of Input Field
+ SwInputField* pInputFld = dynamic_cast<SwInputField*>(pCurFld);
+ if (pInputFld && pInputFld->GetFmtFld())
+ {
+ pSh->GotoField( *(pInputFld->GetFmtFld()) );
+ }
+ }
+
+ /* Only create selection if there is none already.
+ Normalize PaM instead of swapping. */
+ if (!pSh->HasSelection())
+ {
+ SwShellCrsr* pCrsr = pSh->getShellCrsr(true);
+ SwPosition aOrigPos(*pCrsr->GetPoint());
+
+ //After this attempt it is possible that rMgr.GetCurFld() != pCurFld if
+ //the field was in e.g. a zero height portion and so invisible in which
+ //case it will be skipped over
+ pSh->Right(CRSR_SKIP_CHARS, true, 1, false );
+ //So (fdo#50640) if it didn't work then reposition back to the original
+ //location where the field was
+ SwField *pRealCurFld = rMgr.GetCurFld();
+ bool bSelectionFailed = pCurFld != pRealCurFld;
+ if (bSelectionFailed)
+ {
+ pCrsr->DeleteMark();
+ *pCrsr->GetPoint() = aOrigPos;
+ }
+ }
+
+ pSh->NormalizePam();
+
+ assert(pCurFld == rMgr.GetCurFld());
+}
SwFldEditDlg::SwFldEditDlg(SwView& rVw)
: SfxSingleTabDialog(&rVw.GetViewFrame()->GetWindow(), 0,
@@ -62,28 +100,12 @@ SwFldEditDlg::SwFldEditDlg(SwView& rVw)
SwFldMgr aMgr(pSh);
SwField *pCurFld = aMgr.GetCurFld();
- if(!pCurFld)
+ if (!pCurFld)
return;
SwViewShell::SetCareWin(this);
- if ( pSh->CrsrInsideInputFld() )
- {
- // move cursor to start of Input Field
- SwInputField* pInputFld = dynamic_cast<SwInputField*>(pCurFld);
- if ( pInputFld != NULL
- && pInputFld->GetFmtFld() != NULL )
- {
- pSh->GotoField( *(pInputFld->GetFmtFld()) );
- }
- }
-
- if ( ! pSh->HasSelection() )
- {
- pSh->Right(CRSR_SKIP_CHARS, true, 1, false);
- }
-
- pSh->NormalizePam();
+ EnsureSelection(pCurFld, aMgr);
sal_uInt16 nGroup = aMgr.GetGroup(false, pCurFld->GetTypeId(), pCurFld->GetSubType());
@@ -254,12 +276,7 @@ IMPL_LINK( SwFldEditDlg, NextPrevHdl, Button *, pButton )
rMgr.GoNextPrev( bNext, pOldTyp );
pCurFld = rMgr.GetCurFld();
- /* #108536# Only create selection if there is none
- already. Normalize PaM instead of swapping. */
- if ( ! pSh->HasSelection() )
- pSh->Right(CRSR_SKIP_CHARS, true, 1, false );
-
- pSh->NormalizePam();
+ EnsureSelection(pCurFld, rMgr);
sal_uInt16 nGroup = rMgr.GetGroup(false, pCurFld->GetTypeId(), pCurFld->GetSubType());
diff --git a/sw/source/uibase/inc/fldedt.hxx b/sw/source/uibase/inc/fldedt.hxx
index 0c859e9fd69d..26dc320e0a04 100644
--- a/sw/source/uibase/inc/fldedt.hxx
+++ b/sw/source/uibase/inc/fldedt.hxx
@@ -23,6 +23,7 @@
class SwView;
class SwWrtShell;
+class SwFldMgr;
class SwFldEditDlg : public SfxSingleTabDialog
{
@@ -37,9 +38,10 @@ class SwFldEditDlg : public SfxSingleTabDialog
void Init();
SfxTabPage* CreatePage(sal_uInt16 nGroup);
+ void EnsureSelection(SwField *pCurFld, SwFldMgr &rMgr);
public:
- SwFldEditDlg(SwView& rVw);
+ SwFldEditDlg(SwView& rVw);
virtual ~SwFldEditDlg();
DECL_LINK(OKHdl, void *);