diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-09-21 12:09:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-09-21 13:21:16 +0200 |
commit | 37656a47d8797d45d706a17ab8843dcb8db90bbc (patch) | |
tree | 8b0e71d7ed7cb23826dada1ddf9f6226575ae0b6 /sw | |
parent | 7cecf19a1f553b57b5d1cd81a9a99f51ee424a24 (diff) |
sw content controls, combo box: make the dropdown case read-only
Dropdown should be read-only (select from existing list items only),
combo box should be read-write (accepting free-form user input as well).
Now that we have a combo box, allow editing a combo box's content, but
turn dropdown into a read-only control.
Change-Id: Ie9434eaf2580be8ce154ec1126f7768eb9401254
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140338
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/core/crsr/crsr.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/crsr/pam.cxx | 11 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh3.cxx | 2 |
3 files changed, 31 insertions, 1 deletions
diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx index 759b236d16ac..243abd0e20d1 100644 --- a/sw/qa/core/crsr/crsr.cxx +++ b/sw/qa/core/crsr/crsr.cxx @@ -19,11 +19,13 @@ #include <comphelper/propertysequence.hxx> #include <svl/srchitem.hxx> #include <vcl/scheduler.hxx> +#include <comphelper/propertyvalue.hxx> #include <docsh.hxx> #include <unotxdoc.hxx> #include <wrtsh.hxx> #include <ndtxt.hxx> +#include <formatcontentcontrol.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/crsr/data/"; @@ -183,6 +185,23 @@ CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testTdf135451) CPPUNIT_ASSERT_EQUAL(OUString("a"), pWrtShell->GetSelText()); } +CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testDropdownContentControl) +{ + // Given a document with a dropdown content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // When entering the content control: + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + // Then make sure that the cursor is read-only: + // Without the accompanying fix in place, this test would have failed, it was possible to type + // into the drop-down content control, providing content that is not one of the list items. + CPPUNIT_ASSERT(pWrtShell->HasReadonlySel()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 5f8f3ec86eb6..2b4e8cc0bf9c 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -957,7 +957,16 @@ bool SwPaM::HasReadonlySel(bool bFormView, bool const isReplace) const = rFormatContentControl.GetContentControl(); if (pContentControl && !pContentControl->GetReadWrite()) { - bRet = pContentControl->GetCheckbox() || pContentControl->GetPicture(); + switch (pContentControl->GetType()) + { + case SwContentControlType::CHECKBOX: + case SwContentControlType::PICTURE: + case SwContentControlType::DROP_DOWN_LIST: + bRet = true; + break; + default: + break; + } } } } diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx b/sw/source/uibase/wrtsh/wrtsh3.cxx index 27ca0353bac1..58204886933e 100644 --- a/sw/source/uibase/wrtsh/wrtsh3.cxx +++ b/sw/source/uibase/wrtsh/wrtsh3.cxx @@ -172,9 +172,11 @@ bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentContro GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter); // Update the content. + pContentControl->SetReadWrite(true); DelLeft(); pContentControl->SetSelectedListItem(std::nullopt); Insert(aNewState); + pContentControl->SetReadWrite(false); GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter); LockView(/*bViewLocked=*/false); |