weld InputDialog

Change-Id: I821dcea904cad7cc6f9394bccf6560624d23729b
Reviewed-on: https://gerrit.libreoffice.org/50756
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/cui/source/options/optjava.cxx b/cui/source/options/optjava.cxx
index 30d9686..50264e9 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 7822183..bef84fc 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 <vcl/dialog.hxx>
#include <sfx2/dllapi.h>
#include <vcl/weld.hxx>

class Edit;
class FixedText;
class PushButton;
class Button;

class SFX2_DLLPUBLIC InputDialog : public ModalDialog
class SFX2_DLLPUBLIC InputDialog
{
private:
    std::unique_ptr<weld::Builder> m_xBuilder;
    std::unique_ptr<weld::Dialog> m_xDialog;
    std::unique_ptr<weld::Entry> m_xEntry;
    std::unique_ptr<weld::Label> m_xLabel;
    std::unique_ptr<weld::Button> m_xHelp;

public:
    InputDialog (const OUString &labelText, vcl::Window *pParent);
    OUString GetEntryText () const;
    void SetEntryText( OUString const & sStr );
    InputDialog(weld::Window* pParent, const OUString &rLabelText);
    short run() { return m_xDialog->run(); }
    OUString GetEntryText() const;
    void SetEntryText(const OUString& rStr);
    void HideHelpBtn();
    virtual ~InputDialog() override;
    virtual void dispose() override;

private:

    DECL_LINK(ClickHdl, Button*, void);

private:

    VclPtr<Edit>       m_pEntry;
    VclPtr<FixedText>  m_pLabel;
    VclPtr<PushButton> m_pOK;
    VclPtr<PushButton> m_pCancel;
    VclPtr<PushButton> m_pHelp;
};

#endif // INCLUDED_SFX2_SOURCE_INC_INPUTDLG_HXX
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 0aad7d0..9a46a19 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<Entry&, void>& rLink) { m_aChangeHdl = rLink; }

diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index b95a7f6..447353c 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 cbcbe2d..ff864dd 100644
--- a/sfx2/source/dialog/inputdlg.cxx
+++ b/sfx2/source/dialog/inputdlg.cxx
@@ -8,59 +8,33 @@
 */

#include <sfx2/inputdlg.hxx>

#include <sfx2/sfxresid.hxx>
#include <vcl/button.hxx>
#include <vcl/edit.hxx>
#include <vcl/fixed.hxx>
#include <vcl/svapp.hxx>

InputDialog::InputDialog(const OUString &rLabelText, vcl::Window *pParent)
    : ModalDialog(pParent, "InputDialog", "sfx/ui/inputdialog.ui")
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"))
{
    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()
{
    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();
    return m_xEntry->get_text();
}

void InputDialog::SetEntryText( OUString const & sStr)
void InputDialog::SetEntryText(const OUString& rStr)
{
    m_pEntry->SetText(sStr);
    m_pEntry->SetCursorAtLast();
}

IMPL_LINK(InputDialog,ClickHdl, Button*, pButton, void)
{
    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 a5388e1..b9c728e 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 5bebaf3..ebef9c1 100644
--- a/sfx2/uiconfig/ui/inputdialog.ui
+++ b/sfx2/uiconfig/ui/inputdialog.ui
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.19.0 -->
<!-- Generated with glade 3.20.2 -->
<interface domain="sfx">
  <requires lib="gtk+" version="3.0"/>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkDialog" id="InputDialog">
    <property name="can_focus">False</property>
    <property name="border_width">6</property>
    <property name="modal">True</property>
    <property name="default_width">0</property>
    <property name="default_height">0</property>
    <property name="type_hint">dialog</property>
    <child internal-child="vbox">
      <object class="GtkBox" id="dialog-vbox1">
@@ -95,7 +98,6 @@
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="hexpand">True</property>
                <property name="invisible_char">•</property>
              </object>
              <packing>
                <property name="left_attach">0</property>
@@ -112,8 +114,12 @@
      </object>
    </child>
    <action-widgets>
      <action-widget response="-11">help</action-widget>
      <action-widget response="-5">ok</action-widget>
      <action-widget response="-6">cancel</action-widget>
    </action-widgets>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 6e45929..02626e6 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 87e981a..6754d2089 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);