connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx | 5 connectivity/source/drivers/mysqlc/mysqlc_statement.cxx | 25 +- connectivity/source/drivers/mysqlc/mysqlc_statement.hxx | 51 ++-- sc/source/ui/app/inputhdl.cxx | 77 +++++- sc/source/ui/view/cellsh3.cxx | 121 +++++++++- sc/source/ui/view/tabvwshc.cxx | 7 6 files changed, 227 insertions(+), 59 deletions(-)
New commits: commit 244e1823c41221d53b0dc7b6d9595514930f8cca Author: Lionel Elie Mamane <[email protected]> AuthorDate: Sat May 9 16:01:12 2020 +0200 Commit: Lionel Elie Mamane <[email protected]> CommitDate: Sun May 10 07:38:17 2020 +0200 mysql-sdbc: better separate what resultset provides what interface PreparedStatement should not provide XStatement (!!) since MySQL does not support multiple results for prepared statements, PreparedStatement should not expose a XMultipleResults interface Move those out of the common base to Statement itself. Change-Id: Ice7478089441e1def6fd65ff117eb31d04ec46ab Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93864 Tested-by: Jenkins Reviewed-by: Lionel Elie Mamane <[email protected]> diff --git a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx index 3c4edaf411ac..0177b15dbd03 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx @@ -93,11 +93,6 @@ public: sal_Bool SAL_CALL execute() override; Reference<css::sdbc::XConnection> SAL_CALL getConnection() override; - // XStatement - using OCommonStatement::execute; - using OCommonStatement::executeQuery; - using OCommonStatement::executeUpdate; - // XParameters void SAL_CALL setNull(sal_Int32 parameter, sal_Int32 sqlType) override; diff --git a/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx b/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx index b7073be5e6ec..0082f96b61d1 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx @@ -88,6 +88,11 @@ Sequence<Type> SAL_CALL OCommonStatement::getTypes() return concatSequences(aTypes.getTypes(), OCommonStatement_IBase::getTypes()); } +Sequence<Type> SAL_CALL OStatement::getTypes() +{ + return concatSequences(OStatement_BASE::getTypes(), OCommonStatement::getTypes()); +} + void SAL_CALL OCommonStatement::cancel() { MutexGuard aGuard(m_aMutex); @@ -114,7 +119,7 @@ void SAL_CALL OCommonStatement::close() // mysqlc_sdbc_driver::throwFeatureNotImplementedException("com:sun:star:sdbc:XBatchExecution"); // } -sal_Bool SAL_CALL OCommonStatement::execute(const OUString& sql) +sal_Bool SAL_CALL OStatement::execute(const OUString& sql) { MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); @@ -139,7 +144,7 @@ sal_Bool SAL_CALL OCommonStatement::execute(const OUString& sql) return getResult(); } -Reference<XResultSet> SAL_CALL OCommonStatement::executeQuery(const OUString& sql) +Reference<XResultSet> SAL_CALL OStatement::executeQuery(const OUString& sql) { bool isRS(execute(sql)); // if a MySQL error occurred, it was already thrown and the below is not executed @@ -156,7 +161,7 @@ Reference<XResultSet> SAL_CALL OCommonStatement::executeQuery(const OUString& sq return m_xResultSet; } -Reference<XConnection> SAL_CALL OCommonStatement::getConnection() +Reference<XConnection> SAL_CALL OStatement::getConnection() { MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); @@ -165,14 +170,14 @@ Reference<XConnection> SAL_CALL OCommonStatement::getConnection() return m_xConnection.get(); } -sal_Int32 SAL_CALL OCommonStatement::getUpdateCount() { return m_nAffectedRows; } +sal_Int32 SAL_CALL OStatement::getUpdateCount() { return m_nAffectedRows; } Any SAL_CALL OStatement::queryInterface(const Type& rType) { - Any aRet = ::cppu::queryInterface(rType, static_cast<XServiceInfo*>(this)); + Any aRet = OCommonStatement::queryInterface(rType); if (!aRet.hasValue()) { - aRet = OCommonStatement::queryInterface(rType); + aRet = OStatement_BASE::queryInterface(rType); } return aRet; } @@ -193,7 +198,7 @@ Any SAL_CALL OStatement::queryInterface(const Type& rType) // mysqlc_sdbc_driver::throwFeatureNotImplementedException("com:sun:star:sdbc:XBatchExecution"); // } -sal_Int32 SAL_CALL OCommonStatement::executeUpdate(const OUString& sql) +sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql) { MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); @@ -202,7 +207,7 @@ sal_Int32 SAL_CALL OCommonStatement::executeUpdate(const OUString& sql) return m_nAffectedRows; } -Reference<XResultSet> SAL_CALL OCommonStatement::getResultSet() +Reference<XResultSet> SAL_CALL OStatement::getResultSet() { MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); @@ -210,7 +215,7 @@ Reference<XResultSet> SAL_CALL OCommonStatement::getResultSet() return m_xResultSet; } -sal_Bool OCommonStatement::getResult() +bool OStatement::getResult() { // all callers already reset that assert(!m_xResultSet.is()); @@ -245,7 +250,7 @@ sal_Bool OCommonStatement::getResult() return false; } -sal_Bool SAL_CALL OCommonStatement::getMoreResults() +sal_Bool SAL_CALL OStatement::getMoreResults() { MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); diff --git a/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx b/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx index d74e0a6456ce..4416ccceb150 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx @@ -32,7 +32,7 @@ #include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/util/XCancellable.hpp> -#include <cppuhelper/compbase5.hxx> +#include <cppuhelper/compbase3.hxx> #include <rtl/ref.hxx> namespace connectivity @@ -43,10 +43,10 @@ using ::com::sun::star::sdbc::SQLException; using ::com::sun::star::sdbc::SQLWarning; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Type; -typedef ::cppu::WeakComponentImplHelper5<css::sdbc::XStatement, css::sdbc::XWarningsSupplier, - css::util::XCancellable, css::sdbc::XCloseable, - css::sdbc::XMultipleResults> +typedef ::cppu::WeakComponentImplHelper3<css::sdbc::XWarningsSupplier, css::util::XCancellable, + css::sdbc::XCloseable> OCommonStatement_IBase; //************ Class: OCommonStatement @@ -71,7 +71,6 @@ protected: protected: void closeResultSet(); - sal_Bool getResult(); // OPropertyArrayUsageHelper ::cppu::IPropertyArrayHelper* createArrayHelper() const override; @@ -98,10 +97,7 @@ public: // XInterface void SAL_CALL release() throw() override; - void SAL_CALL acquire() throw() override; - - // XInterface Any SAL_CALL queryInterface(const css::uno::Type& rType) override; //XTypeProvider @@ -110,15 +106,6 @@ public: // XPropertySet css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; - // XStatement - css::uno::Reference<css::sdbc::XResultSet> SAL_CALL executeQuery(const OUString& sql) override; - - sal_Int32 SAL_CALL executeUpdate(const OUString& sql) override; - - sal_Bool SAL_CALL execute(const OUString& sql) override; - - css::uno::Reference<css::sdbc::XConnection> SAL_CALL getConnection() override; - // XWarningsSupplier Any SAL_CALL getWarnings() override; @@ -130,13 +117,6 @@ public: // XCloseable void SAL_CALL close() override; - // XMultipleResults - css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getResultSet() override; - - sal_Int32 SAL_CALL getUpdateCount() override; - - sal_Bool SAL_CALL getMoreResults() override; - // other methods OConnection* getOwnConnection() const { return m_xConnection.get(); } @@ -144,11 +124,16 @@ private: using ::cppu::OPropertySetHelper::getFastPropertyValue; }; -class OStatement final : public OCommonStatement, public css::lang::XServiceInfo +typedef ::cppu::ImplHelper3<css::lang::XServiceInfo, css::sdbc::XMultipleResults, + css::sdbc::XStatement> + OStatement_BASE; +class OStatement final : public OCommonStatement, public OStatement_BASE { virtual ~OStatement() override = default; + bool getResult(); + public: // A constructor which is required for the return of the objects OStatement(OConnection* _pConnection) @@ -162,11 +147,25 @@ public: virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + //XInterface Any SAL_CALL queryInterface(const css::uno::Type& rType) override; - void SAL_CALL acquire() throw() override; void SAL_CALL release() throw() override; + //XTypeProvider + css::uno::Sequence<Type> SAL_CALL getTypes() override; + + // XStatement + css::uno::Reference<css::sdbc::XResultSet> SAL_CALL executeQuery(const OUString& sql) override; + sal_Int32 SAL_CALL executeUpdate(const OUString& sql) override; + sal_Bool SAL_CALL execute(const OUString& sql) override; + css::uno::Reference<css::sdbc::XConnection> SAL_CALL getConnection() override; + + // XMultipleResults + css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getResultSet() override; + sal_Int32 SAL_CALL getUpdateCount() override; + sal_Bool SAL_CALL getMoreResults() override; + // XBatchExecution // void SAL_CALL addBatch(const OUString& sql) override; commit 300bded85303b1821226329d6b985c197e55c68f Author: Marco Cecchetti <[email protected]> AuthorDate: Wed Feb 12 15:01:19 2020 +0100 Commit: Andras Timar <[email protected]> CommitDate: Sun May 10 07:38:09 2020 +0200 lok: formula bar: send whole function list Change-Id: Ibbd142652f3190387700f820e56c494b61bfa658 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93341 Tested-by: Jenkins Reviewed-by: Andras Timar <[email protected]> diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index e0073b6e5a80..d3f8aa8ec392 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -1314,6 +1314,10 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec { if (rFuncStrVec.size()) { + auto aPos = pFormulaData->begin(); + sal_uInt32 nCurIndex = std::distance(aPos, miAutoPosFormula); + const sal_uInt32 nSize = pFormulaData->size(); + OUString aFuncNameStr; OUString aDescFuncNameStr; OStringBuffer aPayload; @@ -1340,6 +1344,9 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec if ( !ppFDesc->getFunctionName().isEmpty() ) { aPayload.append("{"); + aPayload.append("\"index\": "); + aPayload.append(OString::number(nCurIndex)); + aPayload.append(", "); aPayload.append("\"signature\": \""); aPayload.append(escapeJSON(ppFDesc->getSignature())); aPayload.append("\", "); @@ -1348,6 +1355,9 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec aPayload.append("\"}, "); } } + ++nCurIndex; + if (nCurIndex == nSize) + nCurIndex = 0; } sal_Int32 nLen = aPayload.getLength(); aPayload[nLen - 2] = ' '; @@ -1510,6 +1520,34 @@ void completeFunction( EditView* pView, const OUString& rInsert, bool& rParInser { ESelection aSel = pView->GetSelection(); + bool bNoInitialLetter = false; + OUString aOld = pView->GetEditEngine()->GetText(0); + // in case we want just insert a function and not completing + if ( comphelper::LibreOfficeKit::isActive() ) + { + ESelection aSelRange = aSel; + --aSelRange.nStartPos; + --aSelRange.nEndPos; + pView->SetSelection(aSelRange); + pView->SelectCurrentWord(); + + if ( aOld == "=" ) + { + bNoInitialLetter = true; + aSelRange.nStartPos = 1; + aSelRange.nEndPos = 1; + pView->SetSelection(aSelRange); + } + else if ( pView->GetSelected().startsWith("()") ) + { + bNoInitialLetter = true; + ++aSelRange.nStartPos; + ++aSelRange.nEndPos; + pView->SetSelection(aSelRange); + } + } + + if(!bNoInitialLetter) { const sal_Int32 nMinLen = std::max(aSel.nEndPos - aSel.nStartPos, sal_Int32(1)); // Since transliteration service is used to test for match, the replaced string could be @@ -1543,7 +1581,6 @@ void completeFunction( EditView* pView, const OUString& rInsert, bool& rParInser // Do not insert parentheses after function names if there already are some // (e.g. if the function name was edited). ESelection aWordSel = pView->GetSelection(); - OUString aOld = pView->GetEditEngine()->GetText(0); // aWordSel.EndPos points one behind string if word at end if (aWordSel.nEndPos < aOld.getLength()) @@ -1602,16 +1639,34 @@ void ScInputHandler::PasteFunctionData() void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex ) { - if (pFormulaData && miAutoPosFormula != pFormulaData->end() && nIndex < pFormulaData->size()) - { - auto aPos = pFormulaData->begin(); - sal_uInt32 nCurIndex = std::distance(aPos, miAutoPosFormula); - nIndex += nCurIndex; - if (nIndex >= pFormulaData->size()) - nIndex -= pFormulaData->size(); - std::advance(aPos, nIndex); - miAutoPosFormula = aPos; - PasteFunctionData(); + if (pActiveViewSh && (pTopView || pTableView)) + { + bool bEdit = false; + OUString aFormula; + EditView* pEditView = pTopView ? pTopView : pTableView; + const EditEngine* pEditEngine = pEditView->GetEditEngine(); + if (pEditEngine) + { + aFormula = pEditEngine->GetText(0); + bEdit = aFormula.getLength() > 1 && (aFormula[0] == '=' || aFormula[0] == '+' || aFormula[0] == '-'); + } + + if ( !bEdit ) + { + OUString aNewFormula('='); + if ( aFormula.startsWith("=") ) + aNewFormula = aFormula; + + InputReplaceSelection( aNewFormula ); + } + + if (pFormulaData && nIndex < pFormulaData->size()) + { + auto aPos = pFormulaData->begin(); + std::advance(aPos, nIndex); + miAutoPosFormula = aPos; + PasteFunctionData(); + } } } diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx index 002261f57d61..9158748a9c98 100644 --- a/sc/source/ui/view/cellsh3.cxx +++ b/sc/source/ui/view/cellsh3.cxx @@ -20,6 +20,7 @@ #include <scitems.hxx> #include <editeng/editview.hxx> #include <editeng/editeng.hxx> +#include <formula/formulahelper.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> @@ -40,6 +41,7 @@ #include <cellsh.hxx> #include <inputhdl.hxx> #include <editable.hxx> +#include <funcdesc.hxx> #include <markdata.hxx> #include <scabstdlg.hxx> #include <columnspanset.hxx> @@ -54,6 +56,103 @@ using sc::HMMToTwips; using sc::TwipsToEvenHMM; +namespace +{ +/// Rid ourselves of unwanted " quoted json characters. +OString escapeJSON(const OUString &aStr) +{ + OUString aEscaped = aStr; + aEscaped = aEscaped.replaceAll("\n", " "); + aEscaped = aEscaped.replaceAll("\"", "'"); + return OUStringToOString(aEscaped, RTL_TEXTENCODING_UTF8); +} + +void lcl_lokGetWholeFunctionList() +{ + const SfxViewShell* pViewShell = SfxViewShell::Current(); + if (comphelper::LibreOfficeKit::isActive() + && pViewShell && pViewShell->isLOKMobilePhone()) + { + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + sal_uInt32 nListCount = pFuncList->GetCount(); + std::set<OUString> aFuncNameOrderedSet; + for(sal_uInt32 i = 0; i < nListCount; ++i) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction( i ); + if ( pDesc->mxFuncName ) + { + aFuncNameOrderedSet.insert(*pDesc->mxFuncName); + } + } + ScFunctionMgr* pFuncManager = ScGlobal::GetStarCalcFunctionMgr(); + if (pFuncManager && aFuncNameOrderedSet.size()) + { + OStringBuffer aPayload; + aPayload.append("{ \"wholeList\": true, "); + aPayload.append("\"categories\": [ "); + + formula::FormulaHelper aHelper(pFuncManager); + sal_uInt32 nCategoryCount = pFuncManager->getCount(); + for (sal_uInt32 i = 0; i < nCategoryCount; ++i) + { + OUString sCategoryName = ScFunctionMgr::GetCategoryName(i); + aPayload.append("{"); + aPayload.append("\"name\": \""); + aPayload.append(escapeJSON(sCategoryName)); + aPayload.append("\"}, "); + } + sal_Int32 nLen = aPayload.getLength(); + aPayload[nLen - 2] = ' '; + aPayload[nLen - 1] = ']'; + aPayload.append(", "); + + OUString aDescFuncNameStr; + aPayload.append("\"functions\": [ "); + sal_uInt32 nCurIndex = 0; + for (const OUString& aFuncNameStr : aFuncNameOrderedSet) + { + aDescFuncNameStr = aFuncNameStr + "()"; + sal_Int32 nNextFStart = 0; + const formula::IFunctionDescription* ppFDesc; + ::std::vector< OUString > aArgs; + OUString eqPlusFuncName = "=" + aDescFuncNameStr; + if ( aHelper.GetNextFunc( eqPlusFuncName, false, nNextFStart, nullptr, &ppFDesc, &aArgs ) ) + { + if ( ppFDesc && !ppFDesc->getFunctionName().isEmpty() ) + { + if (ppFDesc->getCategory()) + { + aPayload.append("{"); + aPayload.append("\"index\": "); + aPayload.append(OString::number(nCurIndex)); + aPayload.append(", "); + aPayload.append("\"category\": "); + aPayload.append(OString::number(ppFDesc->getCategory()->getNumber())); + aPayload.append(", "); + aPayload.append("\"signature\": \""); + aPayload.append(escapeJSON(ppFDesc->getSignature())); + aPayload.append("\", "); + aPayload.append("\"description\": \""); + aPayload.append(escapeJSON(ppFDesc->getDescription())); + aPayload.append("\"}, "); + } + } + } + ++nCurIndex; + } + nLen = aPayload.getLength(); + aPayload[nLen - 2] = ' '; + aPayload[nLen - 1] = ']'; + aPayload.append(" }"); + + OString s = aPayload.makeStringAndClear(); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CALC_FUNCTION_LIST, s.getStr()); + } + } +} + +} // end namespace + void ScCellShell::Execute( SfxRequest& rReq ) { ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); @@ -314,11 +413,23 @@ void ScCellShell::Execute( SfxRequest& rReq ) case SID_OPENDLG_FUNCTION: { - sal_uInt16 nId = SID_OPENDLG_FUNCTION; - SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); - SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); - bool bVis = comphelper::LibreOfficeKit::isActive() || pWnd == nullptr; - pScMod->SetRefDialog( nId, bVis ); + const SfxViewShell* pViewShell = SfxViewShell::Current(); + if (comphelper::LibreOfficeKit::isActive() + && pViewShell && pViewShell->isLOKMobilePhone()) + { + // not set the dialog id in the mobile case or we would + // not be able to get cell address pasted in the edit view + // by just tapping on them + lcl_lokGetWholeFunctionList(); + } + else + { + sal_uInt16 nId = SID_OPENDLG_FUNCTION; + SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); + SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); + bool bVis = comphelper::LibreOfficeKit::isActive() || pWnd == nullptr; + pScMod->SetRefDialog( nId, bVis ); + } rReq.Ignore(); } break; diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx index 918437db53cc..afb406b4863a 100644 --- a/sc/source/ui/view/tabvwshc.cxx +++ b/sc/source/ui/view/tabvwshc.cxx @@ -394,8 +394,11 @@ std::shared_ptr<SfxModelessDialogController> ScTabViewShell::CreateRefDialogCont } case SID_OPENDLG_FUNCTION: { - // dialog checks, what is in the cell - xResult = std::make_shared<ScFormulaDlg>(pB, pCW, pParent, &GetViewData(),ScGlobal::GetStarCalcFunctionMgr()); + if (!isLOKMobilePhone()) + { + // dialog checks, what is in the cell + xResult = std::make_shared<ScFormulaDlg>(pB, pCW, pParent, &GetViewData(),ScGlobal::GetStarCalcFunctionMgr()); + } break; } case WID_CONDFRMT_REF: _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
