From 9cb1a07dc2760a30d7f321aa7fa4ce2a460dfa6c Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 1 Jun 2022 08:30:03 +0200 Subject: sw content controls, date: add LOK API - send a LOK_CALLBACK_CONTENT_CONTROL with date=true when entering a date content control - extend lok::Document::sendContentControlEvent() to be able to set the date of a date content control (after the client's date picker is closed) - update gtktiledviewer to work with these Change-Id: I0abf21eb1d4ba233050f0aa2607b68740c048262 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135214 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/source/core/crsr/viscrs.cxx | 5 ++++ sw/source/uibase/uno/unotxdoc.cxx | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'sw/source') diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 9863e1a75324..ba3d49893233 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -708,6 +708,11 @@ void SwSelPaintRects::HighlightContentControl() } } + if (pContentControl && pContentControl->GetDate()) + { + aJson.put("date", "true"); + } + std::unique_ptr pJson(aJson.extractData()); GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL, pJson.get()); } diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 57998981f02e..b3f6e2e7487f 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3359,6 +3359,11 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) return std::vector(); } +namespace +{ +inline constexpr OUStringLiteral SELECTED_DATE_FORMAT = u"YYYY-MM-DD"; +} + void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments) { auto it = rArguments.find("type"); @@ -3421,6 +3426,62 @@ void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments) pView->GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_GRAPHIC, SfxCallMode::SYNCHRON, { &aItem }); } + else if (it->second == "date") + { + SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell(); + const SwPosition* pStart = pWrtShell->GetCursor()->Start(); + SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode(); + if (!pTextNode) + { + return; + } + + SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pStart->nContent.GetIndex(), + RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT); + if (!pAttr) + { + return; + } + + auto pTextContentControl = static_txtattr_cast(pAttr); + const SwFormatContentControl& rFormatContentControl + = pTextContentControl->GetContentControl(); + std::shared_ptr pContentControl + = rFormatContentControl.GetContentControl(); + if (!pContentControl->GetDate()) + { + return; + } + + it = rArguments.find("selected"); + if (it == rArguments.end()) + { + return; + } + + OUString aSelectedDate = it->second.replaceAll("T00:00:00Z", ""); + SwDoc& rDoc = pTextNode->GetDoc(); + SvNumberFormatter* pNumberFormatter = rDoc.GetNumberFormatter(); + sal_uInt32 nFormat + = pNumberFormatter->GetEntryKey(SELECTED_DATE_FORMAT, LANGUAGE_ENGLISH_US); + if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) + { + sal_Int32 nCheckPos = 0; + SvNumFormatType nType; + OUString sFormat = SELECTED_DATE_FORMAT; + pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, LANGUAGE_ENGLISH_US); + } + + if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) + { + return; + } + + double dCurrentDate = 0; + pNumberFormatter->IsNumberFormat(aSelectedDate, nFormat, dCurrentDate); + pContentControl->SetSelectedDate(dCurrentDate); + pWrtShell->GotoContentControl(rFormatContentControl); + } } int SwXTextDocument::getPart() -- cgit