From 6f60a89a6be85d4cbe5840f9d0146eae98dbf543 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 26 Apr 2022 08:20:50 +0200 Subject: 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 Tested-by: Jenkins --- sw/source/uibase/wrtsh/wrtsh3.cxx | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'sw/source/uibase') 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 #include #include +#include +#include +#include +#include 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(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(); -- cgit v1.2.3