summaryrefslogtreecommitdiff
path: root/sw/source/uibase
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-04-26 08:20:50 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-26 12:28:53 +0200
commit6f60a89a6be85d4cbe5840f9d0146eae98dbf543 (patch)
tree17d1fa4c52689ce34480b5b1119d61068d863b89 /sw/source/uibase
parent0aaa964224be38323e4f9e456655da2a8b4c2b66 (diff)
sw content controls, checkbox: toggle the checkbox on click
Implement this by selecting the content control's text (similar to placeholders), then replacing the selection with the content control's relevant state. Change-Id: I280ce45822fe3fd9615511a9a62d23dc230aa275 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133424 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/uibase')
-rw-r--r--sw/source/uibase/wrtsh/wrtsh3.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx b/sw/source/uibase/wrtsh/wrtsh3.cxx
index 2b0b9385467e..35d1d3bd45ee 100644
--- a/sw/source/uibase/wrtsh/wrtsh3.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh3.cxx
@@ -33,6 +33,10 @@
#include <view.hxx>
#include <IMark.hxx>
#include <doc.hxx>
+#include <formatcontentcontrol.hxx>
+#include <IDocumentUndoRedo.hxx>
+#include <SwRewriter.hxx>
+#include <strings.hrc>
using namespace ::com::sun::star;
@@ -88,6 +92,40 @@ bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentContro
(this->*m_fnKillSel)(nullptr, false);
bool bRet = SwCursorShell::GotoFormatContentControl(rContentControl);
+
+ auto pContentControl = const_cast<SwContentControl*>(rContentControl.GetContentControl());
+ if (bRet && pContentControl && pContentControl->GetCheckbox())
+ {
+ // Checkbox: GotoFormatContentControl() selected the old state.
+ LockView(/*bViewLocked=*/true);
+ OUString aOldState;
+ OUString aNewState;
+ if (pContentControl->GetChecked())
+ {
+ aOldState = pContentControl->GetCheckedState();
+ aNewState = pContentControl->GetUncheckedState();
+ }
+ else
+ {
+ aOldState = pContentControl->GetUncheckedState();
+ aNewState = pContentControl->GetCheckedState();
+ }
+ SwRewriter aRewriter;
+ aRewriter.AddRule(UndoArg1, aOldState);
+ aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
+ aRewriter.AddRule(UndoArg3, aNewState);
+ GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter);
+
+ // Toggle the state.
+ DelLeft();
+ pContentControl->SetChecked(!pContentControl->GetChecked());
+ Insert(aNewState);
+
+ GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
+ LockView(/*bViewLocked=*/false);
+ ShowCursor();
+ }
+
if (bRet && IsSelFrameMode())
{
UnSelectFrame();