[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - 2 commits - sw/qa sw/sdi sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jul 1 14:19:57 UTC 2019
sw/qa/extras/uiwriter/data2/image-comment.odt |binary
sw/qa/extras/uiwriter/uiwriter2.cxx | 34 +++++++++
sw/sdi/_frmsh.sdi | 5 +
sw/source/uibase/inc/frmsh.hxx | 1
sw/source/uibase/inc/wrtsh.hxx | 5 +
sw/source/uibase/shells/frmsh.cxx | 14 +++
sw/source/uibase/shells/textfld.cxx | 65 -----------------
sw/source/uibase/wrtsh/wrtsh1.cxx | 95 ++++++++++++++++++++++++++
8 files changed, 155 insertions(+), 64 deletions(-)
New commits:
commit 736ecbea96ed8c349b84693f9246a92bc417cc32
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jun 18 17:44:33 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jul 1 16:19:32 2019 +0200
sw: implement inserting comments when an as-char image is selected
Only the UI was missing in this case: creating a text selection around
the placeholder character does what the user expects.
(cherry picked from commit 351b9aefe3de7c68e907fdc7926d9b508560320e)
Conflicts:
sw/qa/extras/uiwriter/uiwriter2.cxx
sw/sdi/_frmsh.sdi
sw/source/uibase/inc/frmsh.hxx
sw/source/uibase/shells/frmsh.cxx
sw/source/uibase/wrtsh/wrtsh1.cxx
Change-Id: I1068fcee3e3b6d0a6fa47b37beb1bd1b918a82df
Reviewed-on: https://gerrit.libreoffice.org/74424
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
Tested-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/uiwriter/data2/image-comment.odt b/sw/qa/extras/uiwriter/data2/image-comment.odt
new file mode 100644
index 000000000000..4f0a520bcca3
Binary files /dev/null and b/sw/qa/extras/uiwriter/data2/image-comment.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index b78454a061b4..cc64ae74c37f 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -24,6 +24,10 @@
#include <xmloff/odffields.hxx>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <fmtornt.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
+#include <view.hxx>
+#include <cmdid.h>
namespace
{
@@ -45,6 +49,7 @@ public:
void testDropDownFormFieldInsertion();
void testMixedFormFieldInsertion();
void testTdf122942();
+ void testImageComment();
CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testTdf101534);
@@ -57,6 +62,7 @@ public:
CPPUNIT_TEST(testDropDownFormFieldInsertion);
CPPUNIT_TEST(testMixedFormFieldInsertion);
CPPUNIT_TEST(testTdf122942);
+ CPPUNIT_TEST(testImageComment);
CPPUNIT_TEST_SUITE_END();
private:
@@ -477,6 +483,34 @@ void SwUiWriterTest2::testTdf122942()
#endif
}
+void SwUiWriterTest2::testImageComment()
+{
+ // Load a document with an as-char image in it.
+ SwDoc* pDoc = createDoc("image-comment.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 FN_POSTIT was disabled
+ // in the frame shell.
+ 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"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/sdi/_frmsh.sdi b/sw/sdi/_frmsh.sdi
index 734b50c5ebc1..bd15005dc98d 100644
--- a/sw/sdi/_frmsh.sdi
+++ b/sw/sdi/_frmsh.sdi
@@ -400,5 +400,10 @@ interface BaseTextFrame
ExecMethod = Execute ;
DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
]
+ FN_POSTIT
+ [
+ ExecMethod = ExecField ;
+ StateMethod = NoState ;
+ ]
}
diff --git a/sw/source/uibase/inc/frmsh.hxx b/sw/source/uibase/inc/frmsh.hxx
index f86e0d06501f..cf7ebbb1e139 100644
--- a/sw/source/uibase/inc/frmsh.hxx
+++ b/sw/source/uibase/inc/frmsh.hxx
@@ -35,6 +35,7 @@ public:
virtual ~SwFrameShell() override;
void Execute(SfxRequest &);
+ void ExecField(SfxRequest& rReq);
void GetState(SfxItemSet &);
void ExecFrameStyle(SfxRequest const & rReq);
void GetLineStyleState(SfxItemSet &rSet);
diff --git a/sw/source/uibase/shells/frmsh.cxx b/sw/source/uibase/shells/frmsh.cxx
index 3bf07359d1f3..d53c993df030 100644
--- a/sw/source/uibase/shells/frmsh.cxx
+++ b/sw/source/uibase/shells/frmsh.cxx
@@ -86,6 +86,7 @@
#include <sfx2/msg.hxx>
#include <swslots.hxx>
#include <grfatr.hxx>
+#include <fldmgr.hxx>
using ::editeng::SvxBorderLine;
using namespace ::com::sun::star;
@@ -114,6 +115,19 @@ void SwFrameShell::InitInterface_Impl()
GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Frame_Toolbox);
}
+void SwFrameShell::ExecField(SfxRequest& rReq)
+{
+ SwWrtShell& rSh = GetShell();
+ sal_uInt16 nSlot = rReq.GetSlot();
+ switch (nSlot)
+ {
+ case FN_POSTIT:
+ SwFieldMgr aFieldMgr(&rSh);
+ rSh.InsertPostIt(aFieldMgr, rReq);
+ break;
+ }
+}
+
void SwFrameShell::Execute(SfxRequest &rReq)
{
//First those who do not need FrameMgr.
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 2ce1783a80b0..40d07646592b 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -89,6 +89,7 @@
#include <IMark.hxx>
#include <sfx2/bindings.hxx>
#include <svx/dialmgr.hxx>
+#include <flyfrm.hxx>
// -> #111827#
#include <SwRewriter.hxx>
@@ -1879,6 +1880,27 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq)
GetView().GetEditWin().StopQuickHelp();
SwInsertField_Data aData(TYP_POSTITFLD, 0, sAuthor, sText, 0);
+
+ if (IsSelFrameMode())
+ {
+ SwFlyFrame* pFly = GetSelectedFlyFrame();
+
+ // A frame is selected, end frame selection.
+ EnterStdMode();
+ GetView().AttrChangedNotify(this);
+
+ // Set up text selection, so the anchor of the frame will be the anchor of the
+ // comment.
+ if (pFly)
+ {
+ SwFrameFormat* pFormat = pFly->GetFormat();
+ if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+ {
+ Right(CRSR_SKIP_CELLS, /*bSelect=*/true, 1, /*bBasicCall=*/false, /*bVisual=*/true);
+ }
+ }
+ }
+
rFieldMgr.InsertField( aData );
Push();
commit bbb8ab79db6eec109d128d00df835250e51904dc
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jun 18 12:17:22 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jul 1 16:19:22 2019 +0200
sw: extract postit insert code from SwTextShell::ExecField()
Into a new SwWrtShell::InsertPostIt(), so I can reuse it in
SwFrameShell.
(cherry picked from commit 485e048c391da38f883adfbef920069bd7af2305)
Conflicts:
sw/source/uibase/inc/wrtsh.hxx
sw/source/uibase/wrtsh/wrtsh1.cxx
Change-Id: Ib327aed033067250f021f3857f4ba3adb8e6c597
Reviewed-on: https://gerrit.libreoffice.org/74423
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
Tested-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 936b910d0de6..10d652aadd9a 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -46,6 +46,8 @@ class SvxAutoCorrect;
class NaviContentBookmark;
struct SwCallMouseEvent;
class SfxStringListItem;
+class SwFieldMgr;
+class SfxRequest;
namespace i18nutil {
struct SearchOptions2;
@@ -476,6 +478,9 @@ typedef bool (SwWrtShell:: *FNSimpleMove)();
void ChangeHeaderOrFooter(const OUString& rStyleName, bool bHeader, bool bOn, bool bShowWarning);
virtual void SetShowHeaderFooterSeparator( FrameControlType eControl, bool bShow ) override;
+ /// Inserts a new annotation/comment at the current cursor position / selection.
+ void InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq);
+
private:
SAL_DLLPRIVATE void OpenMark();
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index d810ed63cec2..73ec7c99508f 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -411,70 +411,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
break;
case FN_POSTIT:
{
- SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(aFieldMgr.GetCurField());
- bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == SwFieldIds::Postit);
- if (bNew || GetView().GetPostItMgr()->IsAnswer())
- {
- const SvxPostItAuthorItem* pAuthorItem = rReq.GetArg<SvxPostItAuthorItem>(SID_ATTR_POSTIT_AUTHOR);
- OUString sAuthor;
- if ( pAuthorItem )
- sAuthor = pAuthorItem->GetValue();
- else
- {
- std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
- sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
- }
-
- const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
- OUString sText;
- if ( pTextItem )
- sText = pTextItem->GetValue();
-
- // If we have a text already registered for answer, use that
- if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
- {
- sText = GetView().GetPostItMgr()->GetAnswerText();
- GetView().GetPostItMgr()->RegisterAnswerText(OUString());
- }
-
- if ( rSh.HasSelection() && !rSh.IsTableMode() )
- {
- rSh.KillPams();
- }
-
- // #i120513# Inserting a comment into an autocompletion crashes
- // --> suggestion has to be removed before
- GetView().GetEditWin().StopQuickHelp();
-
- SwInsertField_Data aData(TYP_POSTITFLD, 0, sAuthor, sText, 0);
- aFieldMgr.InsertField( aData );
-
- rSh.Push();
- rSh.SwCursorShell::Left(1, CRSR_SKIP_CHARS);
- pPostIt = static_cast<SwPostItField*>(aFieldMgr.GetCurField());
- rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
- }
-
- // Client has disabled annotations rendering, no need to
- // focus the postit field
- if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
- break;
-
- if (pPostIt)
- {
- SwFieldType* pType = rSh.GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
- SwIterator<SwFormatField,SwFieldType> aIter( *pType );
- SwFormatField* pSwFormatField = aIter.First();
- while( pSwFormatField )
- {
- if ( pSwFormatField->GetField() == pPostIt )
- {
- pSwFormatField->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
- break;
- }
- pSwFormatField = aIter.Next();
- }
- }
+ rSh.InsertPostIt(aFieldMgr, rReq);
}
break;
case SID_EDIT_POSTIT:
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index d401687ec5a3..2ce1783a80b0 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -100,8 +100,13 @@
#include <PostItMgr.hxx>
#include <FrameControlsManager.hxx>
+#include <fldmgr.hxx>
+#include <docufld.hxx>
+#include <IDocumentFieldsAccess.hxx>
+#include <fmtfld.hxx>
#include <sfx2/msgpool.hxx>
+#include <svx/postattr.hxx>
#include <comphelper/lok.hxx>
#include <memory>
@@ -1836,4 +1841,72 @@ void SwWrtShell::SetShowHeaderFooterSeparator( FrameControlType eControl, bool b
GetView().GetEditWin().GetFrameControlsManager().HideControls( eControl );
}
+void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq)
+{
+ SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(rFieldMgr.GetCurField());
+ bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == SwFieldIds::Postit);
+ if (bNew || GetView().GetPostItMgr()->IsAnswer())
+ {
+ const SvxPostItAuthorItem* pAuthorItem = rReq.GetArg<SvxPostItAuthorItem>(SID_ATTR_POSTIT_AUTHOR);
+ OUString sAuthor;
+ if ( pAuthorItem )
+ sAuthor = pAuthorItem->GetValue();
+ else
+ {
+ std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
+ sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
+ }
+
+ const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
+ OUString sText;
+ if ( pTextItem )
+ sText = pTextItem->GetValue();
+
+ // If we have a text already registered for answer, use that
+ if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
+ {
+ sText = GetView().GetPostItMgr()->GetAnswerText();
+ GetView().GetPostItMgr()->RegisterAnswerText(OUString());
+ }
+
+ if ( HasSelection() && !IsTableMode() )
+ {
+ KillPams();
+ }
+
+ // #i120513# Inserting a comment into an autocompletion crashes
+ // --> suggestion has to be removed before
+ GetView().GetEditWin().StopQuickHelp();
+
+ SwInsertField_Data aData(TYP_POSTITFLD, 0, sAuthor, sText, 0);
+ rFieldMgr.InsertField( aData );
+
+ Push();
+ SwCursorShell::Left(1, CRSR_SKIP_CHARS);
+ pPostIt = static_cast<SwPostItField*>(rFieldMgr.GetCurField());
+ Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
+ }
+
+ // Client has disabled annotations rendering, no need to
+ // focus the postit field
+ if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
+ return;
+
+ if (pPostIt)
+ {
+ SwFieldType* pType = GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
+ SwIterator<SwFormatField,SwFieldType> aIter( *pType );
+ SwFormatField* pSwFormatField = aIter.First();
+ while( pSwFormatField )
+ {
+ if ( pSwFormatField->GetField() == pPostIt )
+ {
+ pSwFormatField->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
+ break;
+ }
+ pSwFormatField = aIter.Next();
+ }
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list