diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-07-01 16:08:10 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-07-01 17:40:43 +0200 |
commit | 5cb34f1c38be72047be1c4ed8357c5e87134c6a2 (patch) | |
tree | bc81fda31925aea25d42304fc78feb0185941668 /sw | |
parent | 49cfcf777d03abf59557cad021b4e5c4445de3c0 (diff) |
sw comments on frames: fix UI to be able to annotate with at-char anchors
We used to just comment the doc model position at the end of the
paragraph of the image anchor. Change this, so that in case an at-char
anchored image is commented, first we insert the comment (which creates
a placeholder character), and then we set the annotation range to cover
exactly that placeholder character.
This results in a layout that shows a commented image.
Change-Id: Ie21d62ddb9f55f3e06ee39d9eccfaa0446ce7845
Reviewed-on: https://gerrit.libreoffice.org/74957
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data2/image-comment-at-char.odt | bin | 0 -> 9777 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 28 | ||||
-rw-r--r-- | sw/source/uibase/fldui/fldmgr.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/inc/fldmgr.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/inc/wrtsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 18 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh2.cxx | 18 |
7 files changed, 67 insertions, 3 deletions
diff --git a/sw/qa/extras/uiwriter/data2/image-comment-at-char.odt b/sw/qa/extras/uiwriter/data2/image-comment-at-char.odt Binary files differnew file mode 100644 index 000000000000..a3638ffe7276 --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/image-comment-at-char.odt diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 4a5a014761b6..375b4a3aacda 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -1561,4 +1561,32 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageComment) getProperty<OUString>(getRun(xPara, 5), "TextPortionType")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar) +{ + // Load a document with an at-char image in it. + SwDoc* pDoc = createDoc("image-comment-at-char.odt"); + SwView* pView = pDoc->GetDocShell()->GetView(); + + // Select the image. + pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON); + + // Insert a comment while the image is selected. + pView->GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT, SfxCallMode::SYNCHRON); + + // Verify that the comment is around the image. + // Without the accompanying fix in place, this test would have failed, as the comment was + // anchored at the end of the paragraph, it was not around the image. + uno::Reference<text::XTextRange> xPara = getParagraph(1); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + getProperty<OUString>(getRun(xPara, 1), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), + getProperty<OUString>(getRun(xPara, 2), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Frame"), + getProperty<OUString>(getRun(xPara, 3), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), + getProperty<OUString>(getRun(xPara, 4), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + getProperty<OUString>(getRun(xPara, 5), "TextPortionType")); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index d7ccd768723b..547e71e1283f 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -1500,7 +1500,7 @@ bool SwFieldMgr::InsertField( // insert pCurShell->StartAllAction(); - pCurShell->Insert( *pField ); + pCurShell->Insert(*pField, rData.m_pAnnotationRange.get()); if (TYP_INPUTFLD == rData.m_nTypeId) { diff --git a/sw/source/uibase/inc/fldmgr.hxx b/sw/source/uibase/inc/fldmgr.hxx index 4b8a2707ef01..e954e52b9d56 100644 --- a/sw/source/uibase/inc/fldmgr.hxx +++ b/sw/source/uibase/inc/fldmgr.hxx @@ -80,6 +80,8 @@ struct SwInsertField_Data css::uno::Any m_aDBConnection; css::uno::Any m_aDBColumn; weld::Widget* m_pParent; // parent widget used for SwWrtShell::StartInputFieldDlg() + /// Marks the PostIt field's annotation start/end if it differs from the cursor selection. + std::unique_ptr<SwPaM> m_pAnnotationRange; SwInsertField_Data(sal_uInt16 nType, sal_uInt16 nSub, const OUString& rPar1, const OUString& rPar2, sal_uInt32 nFormatId, SwWrtShell* pShell = nullptr, sal_Unicode cSep = ' ', bool bIsAutoLanguage = true) : diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index 8307327ce135..54e97e0b40d3 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -298,7 +298,7 @@ typedef bool (SwWrtShell:: *FNSimpleMove)(); int IntelligentCut(SelectionType nSelectionType, bool bCut = true); // edit - void Insert(SwField const &); + void Insert(SwField const &, SwPaM* pAnnotationRange = nullptr); void Insert(const OUString &); // graphic void Insert( const OUString &rPath, const OUString &rFilter, diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 0b4ae14c8290..ce49c2ec315f 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1925,6 +1925,24 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq) { Right(CRSR_SKIP_CELLS, /*bSelect=*/true, 1, /*bBasicCall=*/false, /*bVisual=*/true); } + else if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR) + { + // Ending the frame selection positions the cursor at the end of the paragraph, + // move it to the anchor position. + sal_Int32 nCursor = GetCurrentShellCursor().GetPoint()->nContent.GetIndex(); + const SwPosition* pAnchor = pFormat->GetAnchor().GetContentAnchor(); + if (pAnchor) + { + sal_Int32 nDiff = nCursor - pAnchor->nContent.GetIndex(); + if (nDiff > 0) + { + Left(CRSR_SKIP_CELLS, /*bSelect=*/false, nDiff, /*bBasicCall=*/false, + /*bVisual=*/true); + aData.m_pAnnotationRange.reset(new SwPaM( + *GetCurrentShellCursor().Start(), *GetCurrentShellCursor().End())); + } + } + } } } diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index 8897fe213130..e46a1d6c03b8 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -68,7 +68,7 @@ #include <sfx2/event.hxx> #include <sal/log.hxx> -void SwWrtShell::Insert(SwField const &rField) +void SwWrtShell::Insert(SwField const& rField, SwPaM* pAnnotationRange) { ResetCursorStack(); if(!CanInsert()) @@ -82,6 +82,11 @@ void SwWrtShell::Insert(SwField const &rField) bool bDeleted = false; std::unique_ptr<SwPaM> pAnnotationTextRange; + if (pAnnotationRange) + { + pAnnotationTextRange.reset(new SwPaM(*pAnnotationRange->Start(), *pAnnotationRange->End())); + } + if ( HasSelection() ) { if ( rField.GetTyp()->Which() == SwFieldIds::Postit ) @@ -121,6 +126,17 @@ void SwWrtShell::Insert(SwField const &rField) { if ( GetDoc() != nullptr ) { + const SwPaM& rCurrPaM = GetCurrentShellCursor(); + if (*rCurrPaM.Start() == *pAnnotationTextRange->Start() + && *rCurrPaM.End() == *pAnnotationTextRange->End()) + { + // Annotation range was passed in externally, and inserting the postit field shifted + // its start/end positions right by one. Restore the original position for the range + // start. This allows commenting on the placeholder character of the field. + SwIndex& rRangeStart = pAnnotationTextRange->Start()->nContent; + if (rRangeStart.GetIndex() > 0) + --rRangeStart; + } IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess(); pMarksAccess->makeAnnotationMark( *pAnnotationTextRange, OUString() ); } |