summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2022-04-14 12:09:38 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2022-05-01 20:18:52 +0200
commit7df8334b0078b4e8f8fbf5c55d9fdc54398b57b7 (patch)
treeb481558d291aec0ccb67eec7e991b5116e4e1f77 /sc
parent3dd8b19b814e959d00235df8bc08f9892f45dd87 (diff)
jsdialog: handle formulabar as textinput
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 <mert.tumer@collabora.com> Tested-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133652 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/app/inputhdl.cxx44
-rw-r--r--sc/source/ui/app/inputwin.cxx28
-rw-r--r--sc/source/ui/inc/inputhdl.hxx2
3 files changed, 73 insertions, 1 deletions
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 <unotools/localedatawrapper.hxx>
#include <unotools/charclass.hxx>
#include <vcl/help.hxx>
+#include <vcl/jsdialog/executor.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/cursor.hxx>
#include <vcl/settings.hxx>
@@ -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<jsdialog::ActionDataMap> pData = std::make_unique<jsdialog::ActionDataMap>();
+ (*pData)["action_type"] = "setText";
+ (*pData)["text"] = rText;
+ (*pData)["selection"] = aSelection;
+
+ sal_uInt64 nCurrentShellId = reinterpret_cast<sal_uInt64>(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