From ab63510e104c4b8e42982390357af1281c4b11a7 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sun, 4 Mar 2018 21:28:44 +0000 Subject: weld InputDialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I821dcea904cad7cc6f9394bccf6560624d23729b Reviewed-on: https://gerrit.libreoffice.org/50756 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- cui/source/options/optjava.cxx | 10 +++--- include/sfx2/inputdlg.hxx | 37 ++++++++------------- include/vcl/weld.hxx | 1 + sfx2/source/control/templatelocalview.cxx | 10 +++--- sfx2/source/dialog/inputdlg.cxx | 54 ++++++++----------------------- sfx2/source/doc/templatedlg.cxx | 14 ++++---- sfx2/uiconfig/ui/inputdialog.ui | 12 +++++-- vcl/source/app/salvtables.cxx | 8 +++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 5 +++ 9 files changed, 67 insertions(+), 84 deletions(-) diff --git a/cui/source/options/optjava.cxx b/cui/source/options/optjava.cxx index 30d968607df6..50264e96e777 100644 --- a/cui/source/options/optjava.cxx +++ b/cui/source/options/optjava.cxx @@ -806,14 +806,14 @@ void SvxJavaParameterDlg::EditParameter() if ( nPos != LISTBOX_ENTRY_NOTFOUND ) { - ScopedVclPtrInstance< InputDialog > pParamEditDlg(CuiResId(RID_SVXSTR_JAVA_START_PARAM), this); + InputDialog aParamEditDlg(GetFrameWeld(), CuiResId(RID_SVXSTR_JAVA_START_PARAM)); OUString editableClassPath = m_pAssignedList->GetSelectedEntry(); - pParamEditDlg->SetEntryText( editableClassPath ); - pParamEditDlg->HideHelpBtn(); + aParamEditDlg.SetEntryText(editableClassPath); + aParamEditDlg.HideHelpBtn(); - if(!pParamEditDlg->Execute()) + if (!aParamEditDlg.run()) return; - OUString editedClassPath = comphelper::string::strip( pParamEditDlg->GetEntryText(), ' '); + OUString editedClassPath = comphelper::string::strip(aParamEditDlg.GetEntryText(), ' '); if ( !editedClassPath.isEmpty() && editableClassPath != editedClassPath ) { diff --git a/include/sfx2/inputdlg.hxx b/include/sfx2/inputdlg.hxx index 78221831b74c..bef84fcbd7f7 100644 --- a/include/sfx2/inputdlg.hxx +++ b/include/sfx2/inputdlg.hxx @@ -10,35 +10,24 @@ #ifndef INCLUDED_SFX2_SOURCE_INC_INPUTDLG_HXX #define INCLUDED_SFX2_SOURCE_INC_INPUTDLG_HXX -#include #include +#include -class Edit; -class FixedText; -class PushButton; -class Button; - -class SFX2_DLLPUBLIC InputDialog : public ModalDialog +class SFX2_DLLPUBLIC InputDialog { -public: - InputDialog (const OUString &labelText, vcl::Window *pParent); - OUString GetEntryText () const; - void SetEntryText( OUString const & sStr ); - void HideHelpBtn(); - virtual ~InputDialog() override; - virtual void dispose() override; - private: + std::unique_ptr m_xBuilder; + std::unique_ptr m_xDialog; + std::unique_ptr m_xEntry; + std::unique_ptr m_xLabel; + std::unique_ptr m_xHelp; - DECL_LINK(ClickHdl, Button*, void); - -private: - - VclPtr m_pEntry; - VclPtr m_pLabel; - VclPtr m_pOK; - VclPtr m_pCancel; - VclPtr m_pHelp; +public: + InputDialog(weld::Window* pParent, const OUString &rLabelText); + short run() { return m_xDialog->run(); } + OUString GetEntryText() const; + void SetEntryText(const OUString& rStr); + void HideHelpBtn(); }; #endif // INCLUDED_SFX2_SOURCE_INC_INPUTDLG_HXX diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 0aad7d0d943f..9a46a191e7a0 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -286,6 +286,7 @@ public: virtual OUString get_text() const = 0; virtual void set_width_chars(int nChars) = 0; virtual void select_region(int nStartPos, int nEndPos) = 0; + virtual void set_position(int nCursorPos) = 0; void connect_changed(const Link& rLink) { m_aChangeHdl = rLink; } diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index b95a7f60c535..447353c4b116 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -265,14 +265,14 @@ IMPL_LINK(TemplateLocalView, ContextMenuSelectHdl, Menu*, pMenu, bool) break; case MNI_RENAME: { - ScopedVclPtrInstance< InputDialog > m_pTitleEditDlg( SfxResId(STR_RENAME_TEMPLATE), this); + InputDialog aTitleEditDlg(GetFrameWeld(), SfxResId(STR_RENAME_TEMPLATE)); OUString sOldTitle = maSelectedItem->getTitle(); - m_pTitleEditDlg->SetEntryText( sOldTitle ); - m_pTitleEditDlg->HideHelpBtn(); + aTitleEditDlg.SetEntryText(sOldTitle); + aTitleEditDlg.HideHelpBtn(); - if(!m_pTitleEditDlg->Execute()) + if (!aTitleEditDlg.run()) break; - OUString sNewTitle = comphelper::string::strip( m_pTitleEditDlg->GetEntryText(), ' '); + OUString sNewTitle = comphelper::string::strip(aTitleEditDlg.GetEntryText(), ' '); if ( !sNewTitle.isEmpty() && sNewTitle != sOldTitle ) { diff --git a/sfx2/source/dialog/inputdlg.cxx b/sfx2/source/dialog/inputdlg.cxx index cbcbe2d0b98e..ff864ddd01a5 100644 --- a/sfx2/source/dialog/inputdlg.cxx +++ b/sfx2/source/dialog/inputdlg.cxx @@ -8,59 +8,33 @@ */ #include - #include -#include -#include -#include - -InputDialog::InputDialog(const OUString &rLabelText, vcl::Window *pParent) - : ModalDialog(pParent, "InputDialog", "sfx/ui/inputdialog.ui") -{ - get(m_pEntry, "entry"); - get(m_pLabel, "label"); - get(m_pOK, "ok"); - get(m_pCancel, "cancel"); - get(m_pHelp, "help"); - m_pLabel->SetText(rLabelText); - m_pOK->SetClickHdl(LINK(this,InputDialog,ClickHdl)); - m_pCancel->SetClickHdl(LINK(this,InputDialog,ClickHdl)); -} - -InputDialog::~InputDialog() +#include + +InputDialog::InputDialog(weld::Window* pParent, const OUString &rLabelText) + : m_xBuilder(Application::CreateBuilder(pParent, "sfx/ui/inputdialog.ui")) + , m_xDialog(m_xBuilder->weld_dialog("InputDialog")) + , m_xEntry(m_xBuilder->weld_entry("entry")) + , m_xLabel(m_xBuilder->weld_label("label")) + , m_xHelp(m_xBuilder->weld_button("help")) { - disposeOnce(); -} - -void InputDialog::dispose() -{ - m_pEntry.clear(); - m_pLabel.clear(); - m_pOK.clear(); - m_pCancel.clear(); - m_pHelp.clear(); - ModalDialog::dispose(); + m_xLabel->set_label(rLabelText); } void InputDialog::HideHelpBtn() { - m_pHelp->Hide(); + m_xHelp->hide(); } OUString InputDialog::GetEntryText() const { - return m_pEntry->GetText(); -} - -void InputDialog::SetEntryText( OUString const & sStr) -{ - m_pEntry->SetText(sStr); - m_pEntry->SetCursorAtLast(); + return m_xEntry->get_text(); } -IMPL_LINK(InputDialog,ClickHdl, Button*, pButton, void) +void InputDialog::SetEntryText(const OUString& rStr) { - EndDialog(pButton == m_pOK ? RET_OK : RET_CANCEL); + m_xEntry->set_text(rStr); + m_xEntry->set_position(-1); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index a5388e1a5649..b9c728e19475 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -1114,13 +1114,13 @@ void SfxTemplateManagerDlg::OnTemplateOpen () void SfxTemplateManagerDlg::OnCategoryNew() { - ScopedVclPtrInstance< InputDialog > dlg(SfxResId(STR_INPUT_NEW),this); + InputDialog dlg(GetFrameWeld(), SfxResId(STR_INPUT_NEW)); - int ret = dlg->Execute(); + int ret = dlg.run(); if (ret) { - OUString aName = dlg->GetEntryText(); + OUString aName = dlg.GetEntryText(); if(mpLocalView->createRegion(aName)) mpCBFolder->InsertEntry(aName); @@ -1137,14 +1137,14 @@ void SfxTemplateManagerDlg::OnCategoryNew() void SfxTemplateManagerDlg::OnCategoryRename() { OUString sCategory = mpCBFolder->GetSelectedEntry(); - ScopedVclPtrInstance< InputDialog > dlg(SfxResId(STR_INPUT_NEW),this); + InputDialog dlg(GetFrameWeld(), SfxResId(STR_INPUT_NEW)); - dlg->SetEntryText(sCategory); - int ret = dlg->Execute(); + dlg.SetEntryText(sCategory); + int ret = dlg.run(); if (ret) { - OUString aName = dlg->GetEntryText(); + OUString aName = dlg.GetEntryText(); if(mpLocalView->renameRegion(sCategory, aName)) { diff --git a/sfx2/uiconfig/ui/inputdialog.ui b/sfx2/uiconfig/ui/inputdialog.ui index 5bebaf3508bf..ebef9c13c946 100644 --- a/sfx2/uiconfig/ui/inputdialog.ui +++ b/sfx2/uiconfig/ui/inputdialog.ui @@ -1,10 +1,13 @@ - + - + False 6 + True + 0 + 0 dialog @@ -95,7 +98,6 @@ True True True - 0 @@ -112,8 +114,12 @@ + help ok cancel + + + diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 6e459298a683..02626e61b2d2 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -782,6 +782,14 @@ public: m_xEntry->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); } + virtual void set_position(int nCursorPos) override + { + if (nCursorPos < 0) + m_xEntry->SetCursorAtLast(); + else + m_xEntry->SetSelection(Selection(nCursorPos, nCursorPos)); + } + virtual ~SalInstanceEntry() override { m_xEntry->SetTextFilter(nullptr); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 87e981a7c6fe..6754d2089328 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1900,6 +1900,11 @@ public: gtk_editable_select_region(GTK_EDITABLE(m_pEntry), nStartPos, nEndPos); } + virtual void set_position(int nCursorPos) override + { + gtk_editable_set_position(GTK_EDITABLE(m_pEntry), nCursorPos); + } + virtual ~GtkInstanceEntry() override { g_signal_handler_disconnect(m_pEntry, m_nInsertTextSignalId); -- cgit