From 7df8334b0078b4e8f8fbf5c55d9fdc54398b57b7 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Thu, 14 Apr 2022 12:09:38 +0200 Subject: jsdialog: handle formulabar as textinput MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mostly boilerplate code jsdialog changes: - added force parameter to sendAction - added support for key press/release and command events - moved ActionDataMap to jsdialog namespace for sharing formulabar changes: - added calls to send jsdialog messages with formula - added cursor moving support - on command event Change-Id: I714715133901941ba0758655e2d5907a3bae79f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133010 Reviewed-by: Mert Tumer Tested-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133652 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- sc/source/ui/app/inputhdl.cxx | 44 ++++++++++++++++++++++++++++++++++++++++++- sc/source/ui/app/inputwin.cxx | 28 +++++++++++++++++++++++++++ sc/source/ui/inc/inputhdl.hxx | 2 ++ 3 files changed, 73 insertions(+), 1 deletion(-) (limited to 'sc') diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index f7a41b13d084..a1b7afa38976 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1784,6 +1785,23 @@ void ScInputHandler::LOKPasteFunctionData(const OUString& rFunctionName) } } +void ScInputHandler::LOKSendFormulabarUpdate(const SfxViewShell* pActiveViewSh, + const OUString& rText, + const ESelection& rSelection) +{ + OUString aSelection = + OUString::number(rSelection.nStartPos) + ";" + OUString::number(rSelection.nEndPos); + + std::unique_ptr pData = std::make_unique(); + (*pData)["action_type"] = "setText"; + (*pData)["text"] = rText; + (*pData)["selection"] = aSelection; + + sal_uInt64 nCurrentShellId = reinterpret_cast(pActiveViewSh); + std::string sWindowId = std::to_string(nCurrentShellId) + "formulabar"; + jsdialog::SendAction(sWindowId, "sc_input_window", std::move(pData)); +} + // Calculate selection and display as tip help static OUString lcl_Calculate( const OUString& rFormula, ScDocument& rDoc, const ScAddress &rPos ) { @@ -2710,7 +2728,10 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified ) if (comphelper::LibreOfficeKit::isActive()) { if (pActiveViewSh) + { + // TODO: deprecated? pActiveViewSh->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_FORMULA, aText.toUtf8().getStr()); + } } } @@ -2723,6 +2744,7 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified ) mpEditEngine->QuickFormatDoc(); EditView* pActiveView = pTopView ? pTopView : pTableView; + ESelection aSel; if (pActiveView && pActiveViewSh) { ScViewData& rViewData = pActiveViewSh->GetViewData(); @@ -2731,7 +2753,7 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified ) if (!bNeedGrow) { // Cursor before the end? - ESelection aSel = pActiveView->GetSelection(); + aSel = pActiveView->GetSelection(); aSel.Adjust(); bNeedGrow = ( aSel.nEndPos != mpEditEngine->GetTextLen(aSel.nEndPara) ); } @@ -2747,6 +2769,13 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified ) } } + if (comphelper::LibreOfficeKit::isActive() && pActiveViewSh && pInputWin) + { + ScInputHandler::LOKSendFormulabarUpdate(pActiveViewSh, + ScEditUtil::GetMultilineString(*mpEditEngine), + aSel); + } + UpdateFormulaMode(); bTextValid = false; // Changes only in the EditEngine bInOwnChange = false; @@ -4188,7 +4217,13 @@ void ScInputHandler::NotifyChange( const ScInputHdlState* pState, pInputWin->SetTextString(aString); if (comphelper::LibreOfficeKit::isActive() && pActiveViewSh) + { + EditView* pActiveView = pTopView ? pTopView : pTableView; + ESelection aSel = pActiveView ? pActiveView->GetSelection() : ESelection(); + ScInputHandler::LOKSendFormulabarUpdate(pActiveViewSh, aString, aSel); + // TODO: deprecated? pActiveViewSh->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_FORMULA, aString.toUtf8().getStr()); + } } if ( pInputWin || comphelper::LibreOfficeKit::isActive()) // Named range input @@ -4344,6 +4379,13 @@ void ScInputHandler::InputSelection( const EditView* pView ) // When the selection is changed manually, stop overwriting parentheses ResetAutoPar(); + + if (comphelper::LibreOfficeKit::isActive() && pActiveViewSh) + { + EditView* pActiveView = pTopView ? pTopView : pTableView; + ESelection aSel = pActiveView ? pActiveView->GetSelection() : ESelection(); + ScInputHandler::LOKSendFormulabarUpdate(pActiveViewSh, GetEditString(), aSel); + } } void ScInputHandler::InputChanged( const EditView* pView, bool bFromNotify ) diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index 47c8c0fdb770..e50c682a1703 100644 --- a/sc/source/ui/app/inputwin.cxx +++ b/sc/source/ui/app/inputwin.cxx @@ -1115,6 +1115,8 @@ ScTextWndGroup::ScTextWndGroup(ScInputBarGroup& rParent, ScTabViewShell* pViewSh , mrParent(rParent) { mxScrollWin->connect_vadjustment_changed(LINK(this, ScTextWndGroup, Impl_ScrollHdl)); + if (comphelper::LibreOfficeKit::isActive()) + ScInputHandler::LOKSendFormulabarUpdate(SfxViewShell::Current(), "", ESelection()); } Point ScTextWndGroup::GetCursorScreenPixelPos(bool bBelow) @@ -1734,6 +1736,26 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt ) SC_MOD()->InputChanged( m_xEditView.get() ); } + if ( comphelper::LibreOfficeKit::isActive() && nCommand == CommandEventId::CursorPos ) + { + // LOK uses this to setup caret position because drawingarea is replaced + // with text input field, it sends logical caret position (start, end) not pixels + + StartEditEngine(); + TextGrabFocus(); + + if (!m_xEditView) + return true; + + Point aSelectionStartEnd = rCEvt.GetMousePosPixel(); + m_xEditView->SetSelection(ESelection(0, aSelectionStartEnd.X(), + 0, aSelectionStartEnd.Y())); + + SC_MOD()->InputSelection( m_xEditView.get() ); + + bConsumed = true; + } + bInputMode = false; return bConsumed; @@ -1889,6 +1911,12 @@ static sal_Int32 findFirstNonMatchingChar(const OUString& rStr1, const OUString& void ScTextWnd::SetTextString( const OUString& rNewString ) { + if (comphelper::LibreOfficeKit::isActive()) + { + ESelection aSel = m_xEditView ? m_xEditView->GetSelection() : ESelection(); + ScInputHandler::LOKSendFormulabarUpdate(SfxViewShell::Current(), rNewString, aSel); + } + // Ideally it would be best to create on demand the EditEngine/EditView here, but... for // the initialisation scenario where a cell is first clicked on we end up with the text in the // inputbar window scrolled to the bottom if we do that here ( because the tableview and topview diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index 625d2f7ca1f8..7b06ee3320ed 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -294,6 +294,8 @@ public: tools::Long nTab, const Color& rColor ); void LOKPasteFunctionData(const OUString& rFunctionName); + static void LOKSendFormulabarUpdate(const SfxViewShell* pActiveViewSh, + const OUString& rText, const ESelection& rSelection); }; // ScInputHdlState -- cgit