From 3d648f76ac90fe8e28691313d0d4e78a8278e511 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 9 Apr 2019 11:23:48 +0100 Subject: weld ScCorrelationDialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is first of the calc dialogs with a range selector, so some temp scaffolding is required during interim case of both welded/unwelded in existence Change-Id: I5480179092da7b56864cef066af781b35f735ebc Reviewed-on: https://gerrit.libreoffice.org/70474 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- formula/source/ui/dlg/formula.cxx | 21 +++++ formula/source/ui/dlg/funcutl.cxx | 180 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) (limited to 'formula') diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx index 68120f6bbd51..e7c5fede138d 100644 --- a/formula/source/ui/dlg/formula.cxx +++ b/formula/source/ui/dlg/formula.cxx @@ -77,6 +77,8 @@ class FormulaDlg_Impl public: ::std::pair RefInputStartBefore( RefEdit* pEdit, RefButton* pButton ); + static ::std::pair + RefInputStartBefore( WeldRefEdit* pEdit, WeldRefButton* pButton ); void RefInputStartAfter(); void RefInputDoneAfter( bool bForced ); bool CalcValue( const OUString& rStrExp, OUString& rStrResult, bool bForceMatrixFormula = false ); @@ -1522,6 +1524,15 @@ void FormulaDlg_Impl::UpdateSelection() return aPair; } +::std::pair FormulaDlg_Impl::RefInputStartBefore( WeldRefEdit* pEdit, WeldRefButton* pButton ) +{ + assert(!pEdit && !pButton); + ::std::pair aPair; + aPair.first = pButton; + aPair.second = pEdit; + return aPair; +} + void FormulaDlg_Impl::RefInputStartAfter() { m_pRefBtn->SetEndImage(); @@ -1779,6 +1790,11 @@ void FormulaModalDialog::Update() return m_pImpl->RefInputStartBefore( pEdit, pButton ); } +::std::pair FormulaModalDialog::RefInputStartBefore( WeldRefEdit* pEdit, WeldRefButton* pButton ) +{ + return formula::FormulaDlg_Impl::RefInputStartBefore(pEdit, pButton); +} + void FormulaModalDialog::RefInputStartAfter() { m_pImpl->RefInputStartAfter(); @@ -1868,6 +1884,11 @@ void FormulaDlg::DoEnter() return m_pImpl->RefInputStartBefore( pEdit, pButton ); } +::std::pair FormulaDlg::RefInputStartBefore( WeldRefEdit* pEdit, WeldRefButton* pButton ) +{ + return formula::FormulaDlg_Impl::RefInputStartBefore(pEdit, pButton); +} + void FormulaDlg::RefInputStartAfter() { m_pImpl->RefInputStartAfter(); diff --git a/formula/source/ui/dlg/funcutl.cxx b/formula/source/ui/dlg/funcutl.cxx index 9499992b6b7e..47c3d408d63e 100644 --- a/formula/source/ui/dlg/funcutl.cxx +++ b/formula/source/ui/dlg/funcutl.cxx @@ -517,6 +517,112 @@ IMPL_LINK_NOARG(RefEdit, UpdateHdl, Timer *, void) pAnyRefDlg->ShowReference( GetText() ); } +// class RefEdit + +WeldRefEdit::WeldRefEdit(std::unique_ptr xControl) + : xEntry(std::move(xControl)) + , aIdle("formula RefEdit Idle") + , pAnyRefDlg(nullptr) + , pLabelWidget(nullptr) +{ + xEntry->connect_focus_in(LINK(this, WeldRefEdit, GetFocus)); + xEntry->connect_focus_out(LINK(this, WeldRefEdit, LoseFocus)); + xEntry->connect_key_press(LINK(this, WeldRefEdit, KeyInput)); + xEntry->connect_changed(LINK(this, WeldRefEdit, Modify)); + aIdle.SetInvokeHandler( LINK( this, WeldRefEdit, UpdateHdl ) ); +} + +WeldRefEdit::~WeldRefEdit() +{ + aIdle.ClearInvokeHandler(); + aIdle.Stop(); +} + +void WeldRefEdit::SetRefString( const OUString& rStr ) +{ + // Prevent unwanted side effects by setting only a differing string. + // See commit message for reasons. + if (xEntry->get_text() != rStr) + xEntry->set_text(rStr); +} + +void WeldRefEdit::SetRefValid(bool bValid) +{ + xEntry->set_error(!bValid); +} + +void WeldRefEdit::SetText(const OUString& rStr) +{ + xEntry->set_text(rStr); + UpdateHdl( &aIdle ); +} + +void WeldRefEdit::StartUpdateData() +{ + aIdle.Start(); +} + +void WeldRefEdit::SetReferences(IControlReferenceHandler* pDlg, weld::Label* pLabel) +{ + pAnyRefDlg = pDlg; + pLabelWidget = pLabel; + + if( pDlg ) + { + aIdle.SetInvokeHandler(LINK(this, WeldRefEdit, UpdateHdl)); + } + else + { + aIdle.ClearInvokeHandler(); + aIdle.Stop(); + } +} + +IMPL_LINK_NOARG(WeldRefEdit, Modify, weld::Entry&, void) +{ + maModifyHdl.Call(*this); + if (pAnyRefDlg) + pAnyRefDlg->HideReference(); +} + +IMPL_LINK(WeldRefEdit, KeyInput, const KeyEvent&, rKEvt, bool) +{ + const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); + if (pAnyRefDlg && !rKeyCode.GetModifier() && rKeyCode.GetCode() == KEY_F2) + { + pAnyRefDlg->ReleaseFocus( this ); + return true; + } + + switch (rKeyCode.GetCode()) + { + case KEY_RETURN: + case KEY_ESCAPE: + return maActivateHdl.Call(*GetWidget()); + } + + return false; +} + +IMPL_LINK_NOARG(WeldRefEdit, GetFocus, weld::Widget&, void) +{ + maGetFocusHdl.Call(*this); + StartUpdateData(); +} + +IMPL_LINK_NOARG(WeldRefEdit, LoseFocus, weld::Widget&, void) +{ + maLoseFocusHdl.Call(*this); + if( pAnyRefDlg ) + pAnyRefDlg->HideReference(); +} + +IMPL_LINK_NOARG(WeldRefEdit, UpdateHdl, Timer *, void) +{ + if( pAnyRefDlg ) + pAnyRefDlg->ShowReference(xEntry->get_text()); +} + //class RefButton RefButton::RefButton( vcl::Window* _pParent, WinBits nStyle ) : ImageButton(_pParent, nStyle), @@ -590,6 +696,80 @@ void RefButton::LoseFocus() pRefEdit->Modify(); } +//class RefButton +WeldRefButton::WeldRefButton(std::unique_ptr xControl) + : xButton(std::move(xControl)) + , pAnyRefDlg( nullptr ) + , pRefEdit( nullptr ) +{ + xButton->connect_focus_in(LINK(this, WeldRefButton, GetFocus)); + xButton->connect_focus_out(LINK(this, WeldRefButton, LoseFocus)); + xButton->connect_key_press(LINK(this, WeldRefButton, KeyInput)); + xButton->connect_clicked(LINK(this, WeldRefButton, Click)); + SetStartImage(); +} + +WeldRefButton::~WeldRefButton() +{ +} + +void WeldRefButton::SetStartImage() +{ + xButton->set_from_icon_name(RID_BMP_REFBTN1); + xButton->set_tooltip_text(ForResId(RID_STR_SHRINK)); +} + +void WeldRefButton::SetEndImage() +{ + xButton->set_from_icon_name(RID_BMP_REFBTN2); + xButton->set_tooltip_text(ForResId(RID_STR_EXPAND)); +} + +void WeldRefButton::SetReferences( IControlReferenceHandler* pDlg, WeldRefEdit* pEdit ) +{ + pAnyRefDlg = pDlg; + pRefEdit = pEdit; +} + +IMPL_LINK_NOARG(WeldRefButton, Click, weld::Button&, void) +{ + if( pAnyRefDlg ) + pAnyRefDlg->ToggleCollapsed( pRefEdit, this ); +} + +IMPL_LINK(WeldRefButton, KeyInput, const KeyEvent&, rKEvt, bool) +{ + const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); + if (pAnyRefDlg && !rKeyCode.GetModifier() && rKeyCode.GetCode() == KEY_F2) + { + pAnyRefDlg->ReleaseFocus( pRefEdit ); + return true; + } + + switch (rKeyCode.GetCode()) + { + case KEY_RETURN: + case KEY_ESCAPE: + return maActivateHdl.Call(*GetWidget()); + } + + return false; +} + +IMPL_LINK_NOARG(WeldRefButton, GetFocus, weld::Widget&, void) +{ + maGetFocusHdl.Call(*this); + if (pRefEdit) + pRefEdit->StartUpdateData(); +} + +IMPL_LINK_NOARG(WeldRefButton, LoseFocus, weld::Widget&, void) +{ + maLoseFocusHdl.Call(*this); + if (pRefEdit) + pRefEdit->DoModify(); +} + } // formula /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit