Function Wizard: don't overwrite an unlisted function

* in a spreadsheet cell enter =LOG(foobar(SIN(1)))
* invoke Function Wizard on that cell (Ctrl+F2)
  LOG(foobar(SIN(1))) is marked in Formula edit field
* activate Functions page
  LOG(foobar(SIN(1))) is marked in Formula edit field
  Function LOG is selected
* click Next button
  foobar(SIN(1)) is marked in Formula edit field
  Function ABS is selected
* click Next button
  foobar(SIN(1)) is overwritten with ABS( )
* only Cancel solves the problem

foobar() could be any user defined or macro function that have no
function description in the Formula Wizard.

Change-Id: I1cb69a9e38c0b8f251d783bd0f67b4b24ade50d0
This commit is contained in:
Eike Rathke
2016-01-08 22:08:40 +01:00
parent 077cc9fbaa
commit 8aee44c94f
3 changed files with 22 additions and 8 deletions

View File

@@ -1041,7 +1041,16 @@ IMPL_LINK_TYPED( FormulaDlg_Impl, BtnHdl, Button*, pBtn, void )
} }
else if ( pBtn == m_pBtnForward ) else if ( pBtn == m_pBtnForward )
{ {
const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() ); const IFunctionDescription* pDesc;
sal_Int32 nSelFunc = pFuncPage->GetFunction();
if (nSelFunc != LISTBOX_ENTRY_NOTFOUND)
pDesc = pFuncPage->GetFuncDesc( nSelFunc );
else
{
// Do not overwrite the selected formula expression, just edit the
// unlisted function.
pFuncDesc = pDesc = nullptr;
}
if(pDesc==pFuncDesc || !pFuncPage->IsVisible()) if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
EditNextFunc( true ); EditNextFunc( true );
@@ -1963,7 +1972,7 @@ void FormEditData::Reset()
nMode = 0; nMode = 0;
nFStart = 0; nFStart = 0;
nCatSel = 1; //! oder 0 (zuletzt benutzte) nCatSel = 1; //! oder 0 (zuletzt benutzte)
nFuncSel = 0; nFuncSel = LISTBOX_ENTRY_NOTFOUND;
nOffset = 0; nOffset = 0;
nEdFocus = 0; nEdFocus = 0;
bMatrix = false; bMatrix = false;

View File

@@ -155,7 +155,9 @@ void FuncPage::UpdateFunctionList()
m_pLbFunction->SetUpdateMode( true ); m_pLbFunction->SetUpdateMode( true );
m_pLbFunction->SelectEntryPos(0); // Ensure no function is selected so the Next button doesn't overwrite a
// function that is not in the list with an arbitrary selected one.
m_pLbFunction->SetNoSelection();
if(IsVisible()) SelHdl(*m_pLbFunction); if(IsVisible()) SelHdl(*m_pLbFunction);
} }
@@ -198,7 +200,10 @@ sal_Int32 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
void FuncPage::SetFunction(sal_Int32 nFunc) void FuncPage::SetFunction(sal_Int32 nFunc)
{ {
m_pLbFunction->SelectEntryPos(nFunc); if (nFunc == LISTBOX_ENTRY_NOTFOUND)
m_pLbFunction->SetNoSelection();
else
m_pLbFunction->SelectEntryPos(nFunc);
} }
void FuncPage::SetFocus() void FuncPage::SetFocus()

View File

@@ -37,8 +37,8 @@ public:
inline sal_uInt16 GetMode() const { return nMode; } inline sal_uInt16 GetMode() const { return nMode; }
inline sal_Int32 GetFStart() const { return nFStart; } inline sal_Int32 GetFStart() const { return nFStart; }
inline sal_uInt16 GetCatSel() const { return nCatSel; } inline sal_Int32 GetCatSel() const { return nCatSel; }
inline sal_uInt16 GetFuncSel() const { return nFuncSel; } inline sal_Int32 GetFuncSel() const { return nFuncSel; }
inline sal_uInt16 GetOffset() const { return nOffset; } inline sal_uInt16 GetOffset() const { return nOffset; }
inline sal_uInt16 GetEdFocus() const { return nEdFocus; } inline sal_uInt16 GetEdFocus() const { return nEdFocus; }
inline const OUString& GetUndoStr() const { return aUndoStr; } inline const OUString& GetUndoStr() const { return aUndoStr; }
@@ -63,8 +63,8 @@ protected:
private: private:
sal_uInt16 nMode; // enum ScFormulaDlgMode sal_uInt16 nMode; // enum ScFormulaDlgMode
sal_Int32 nFStart; sal_Int32 nFStart;
sal_uInt16 nCatSel; sal_Int32 nCatSel;
sal_uInt16 nFuncSel; sal_Int32 nFuncSel;
sal_uInt16 nOffset; sal_uInt16 nOffset;
sal_uInt16 nEdFocus; sal_uInt16 nEdFocus;
OUString aUndoStr; OUString aUndoStr;