weld SvRTLInputBox

This (forgotten) dialog is the statbasic "InputBox" dialog

Change-Id: Ifb65fb382be7bd6b5a2ba904e0cb64ddce2485a8
Reviewed-on: https://gerrit.libreoffice.org/52749
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/basic/source/runtime/inputbox.cxx b/basic/source/runtime/inputbox.cxx
index c7f52dc..ae7302f 100644
--- a/basic/source/runtime/inputbox.cxx
+++ b/basic/source/runtime/inputbox.cxx
@@ -18,130 +18,90 @@
 */

#include <tools/lineend.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/edit.hxx>
#include <vcl/dialog.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <runtime.hxx>
#include <stdobj.hxx>
#include <rtlproto.hxx>
#include <memory>

class SvRTLInputBox : public ModalDialog
class SvRTLInputBox : public weld::GenericDialogController
{
    VclPtr<Edit> aEdit;
    VclPtr<OKButton> aOk;
    VclPtr<CancelButton> aCancel;
    VclPtr<FixedText> aPromptText;
    OUString aText;
    std::unique_ptr<weld::Entry> m_xEdit;
    std::unique_ptr<weld::Button> m_xOk;
    std::unique_ptr<weld::Button> m_xCancel;
    std::unique_ptr<weld::Label> m_xPromptText;
    OUString m_aText;

    void PositionDialog( long nXTwips, long nYTwips, const Size& rDlgSize );
    void InitButtons( const Size& rDlgSize );
    void PositionEdit( const Size& rDlgSize );
    void PositionPrompt( const OUString& rPrompt, const Size& rDlgSize );
    DECL_LINK( OkHdl, Button *, void );
    DECL_LINK( CancelHdl, Button *, void );
    void PositionDialog( long nXTwips, long nYTwips );
    void InitButtons();
    void SetPrompt(const OUString& rPrompt);
    DECL_LINK( OkHdl, weld::Button&, void );
    DECL_LINK( CancelHdl, weld::Button&, void );

public:
    SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt, const OUString& rTitle,
    SvRTLInputBox(weld::Window* pParent, const OUString& rPrompt, const OUString& rTitle,
        const OUString& rDefault, long nXTwips, long nYTwips );
    virtual ~SvRTLInputBox() override { disposeOnce(); }
    virtual void dispose() override;
    OUString GetText() const override { return aText; }
    OUString GetText() const { return m_aText; }
};

SvRTLInputBox::SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt,
SvRTLInputBox::SvRTLInputBox(weld::Window* pParent, const OUString& rPrompt,
        const OUString& rTitle, const OUString& rDefault,
        long nXTwips, long nYTwips ) :
    ModalDialog( pParent,WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ),
    aEdit( VclPtr<Edit>::Create(this,  WB_LEFT | WB_BORDER) ),
    aOk( VclPtr<OKButton>::Create(this) ), aCancel( VclPtr<CancelButton>::Create(this) ), aPromptText( VclPtr<FixedText>::Create(this, WB_WORDBREAK) )
        long nXTwips, long nYTwips)
    : GenericDialogController(pParent, "svt/ui/inputbox.ui", "InputBox")
    , m_xEdit(m_xBuilder->weld_entry("entry"))
    , m_xOk(m_xBuilder->weld_button("ok"))
    , m_xCancel(m_xBuilder->weld_button("cancel"))
    , m_xPromptText(m_xBuilder->weld_label("prompt"))
{
    SetMapMode( MapMode( MapUnit::MapAppFont ) );
    Size aDlgSizeApp( 280, 80 );
    PositionDialog( nXTwips, nYTwips, aDlgSizeApp );
    InitButtons( aDlgSizeApp );
    PositionEdit( aDlgSizeApp );
    PositionPrompt( rPrompt, aDlgSizeApp );
    aOk->Show();
    aCancel->Show();
    aEdit->Show();
    aPromptText->Show();
    SetText( rTitle );
    vcl::Font aFont( GetFont());
    Color aColor( GetBackground().GetColor() );
    aFont.SetFillColor( aColor );
    aEdit->SetFont( aFont );
    aEdit->SetText( rDefault );
    aEdit->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
    PositionDialog( nXTwips, nYTwips );
    InitButtons();
    SetPrompt(rPrompt);
    m_xDialog->set_title(rTitle);
    m_xEdit->set_text(rDefault);
    m_xEdit->select_region(0, -1);
}

void SvRTLInputBox::dispose()
void SvRTLInputBox::InitButtons()
{
    aEdit.disposeAndClear();
    aOk.disposeAndClear();
    aCancel.disposeAndClear();
    aPromptText.disposeAndClear();
    ModalDialog::dispose();
    m_xOk->connect_clicked(LINK(this,SvRTLInputBox, OkHdl));
    m_xCancel->connect_clicked(LINK(this,SvRTLInputBox,CancelHdl));
}

void SvRTLInputBox::InitButtons( const Size& rDlgSize )
void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips)
{
    aOk->SetSizePixel( LogicToPixel( Size( 45, 15) ));
    aCancel->SetSizePixel( LogicToPixel( Size( 45, 15) ));
    Point aPos( rDlgSize.Width()-45-10, 5 );
    aOk->SetPosPixel( LogicToPixel( aPos ));
    aPos.AdjustY(16 );
    aCancel->SetPosPixel( LogicToPixel( aPos ));
    aOk->SetClickHdl(LINK(this,SvRTLInputBox, OkHdl));
    aCancel->SetClickHdl(LINK(this,SvRTLInputBox,CancelHdl));
}

void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips, const Size& rDlgSize)
{
    SetSizePixel( LogicToPixel(rDlgSize) );
    if( nXTwips != -1 && nYTwips != -1 )
    {
        Point aDlgPosApp( nXTwips, nYTwips );
        SetPosPixel(LogicToPixel(aDlgPosApp, MapMode(MapUnit::MapTwip)));
        OutputDevice* pDefaultDevice = Application::GetDefaultDevice();
        pDefaultDevice->Push(PushFlags::MAPMODE);
        pDefaultDevice->SetMapMode(MapMode( MapUnit::MapAppFont));
        aDlgPosApp = pDefaultDevice->LogicToPixel(aDlgPosApp, MapMode(MapUnit::MapTwip));
        pDefaultDevice->Pop();
        m_xDialog->window_move(aDlgPosApp.X(), aDlgPosApp.Y());
    }
}

void SvRTLInputBox::PositionEdit( const Size& rDlgSize )
void SvRTLInputBox::SetPrompt(const OUString& rPrompt)
{
    aEdit->SetPosPixel( LogicToPixel( Point( 5,rDlgSize.Height()-35)));
    aEdit->SetSizePixel( LogicToPixel( Size(rDlgSize.Width()-15,12)));
}


void SvRTLInputBox::PositionPrompt(const OUString& rPrompt,const Size& rDlgSize)
{
    if ( rPrompt.isEmpty() )
    if (rPrompt.isEmpty())
        return;
    OUString aText_(convertLineEnd(rPrompt, LINEEND_CR));
    aPromptText->SetPosPixel( LogicToPixel(Point(5,5)));
    aPromptText->SetText( aText_ );
    Size aSize( rDlgSize );
    aSize.AdjustWidth( -70 );
    aSize.AdjustHeight( -50 );
    aPromptText->SetSizePixel( LogicToPixel(aSize));
    m_xPromptText->set_label( aText_ );
}


IMPL_LINK_NOARG( SvRTLInputBox, OkHdl, Button *, void )
IMPL_LINK_NOARG( SvRTLInputBox, OkHdl, weld::Button&, void )
{
    aText = aEdit->GetText();
    EndDialog( 1 );
    m_aText = m_xEdit->get_text();
    m_xDialog->response(RET_OK);
}

IMPL_LINK_NOARG( SvRTLInputBox, CancelHdl, Button *, void )
IMPL_LINK_NOARG( SvRTLInputBox, CancelHdl, weld::Button&, void )
{
    aText.clear();
    EndDialog();
    m_aText.clear();
    m_xDialog->response(RET_CANCEL);
}


// Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )

void SbRtl_InputBox(StarBASIC *, SbxArray & rPar, bool)
@@ -169,10 +129,10 @@ void SbRtl_InputBox(StarBASIC *, SbxArray & rPar, bool)
            nX = rPar.Get(4)->GetLong();
            nY = rPar.Get(5)->GetLong();
        }
        VclPtrInstance<SvRTLInputBox> pDlg(Application::GetDefDialogParent(),
                                           rPrompt,aTitle,aDefault,nX,nY);
        pDlg->Execute();
        rPar.Get(0)->PutString( pDlg->GetText() );
        vcl::Window* pParent = Application::GetDefDialogParent();
        SvRTLInputBox aDlg(pParent ? pParent->GetFrameWeld() : nullptr,rPrompt,aTitle,aDefault,nX,nY);
        aDlg.run();
        rPar.Get(0)->PutString(aDlg.GetText());
    }
}

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index d6d5300..1605129 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -142,6 +142,7 @@ public:
    virtual void set_title(const OUString& rTitle) = 0;
    virtual OUString get_title() const = 0;
    virtual void set_busy_cursor(bool bBusy) = 0;
    virtual void window_move(int x, int y) = 0;

    virtual css::uno::Reference<css::awt::XWindow> GetXWindow() = 0;

diff --git a/svtools/UIConfig_svt.mk b/svtools/UIConfig_svt.mk
index 1d20f6f..bceaebe 100644
--- a/svtools/UIConfig_svt.mk
+++ b/svtools/UIConfig_svt.mk
@@ -13,6 +13,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svt,\
	svtools/uiconfig/ui/addresstemplatedialog \
	svtools/uiconfig/ui/fileviewmenu \
	svtools/uiconfig/ui/graphicexport \
	svtools/uiconfig/ui/inputbox \
	svtools/uiconfig/ui/javadisableddialog \
	svtools/uiconfig/ui/placeedit \
	svtools/uiconfig/ui/printersetupdialog \
diff --git a/svtools/uiconfig/ui/inputbox.ui b/svtools/uiconfig/ui/inputbox.ui
new file mode 100644
index 0000000..760e1e78
--- /dev/null
+++ b/svtools/uiconfig/ui/inputbox.ui
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface domain="svt">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkDialog" id="InputBox">
    <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">
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">12</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="dialog-action_area1">
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="ok">
                <property name="label">gtk-ok</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="can_default">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="cancel">
                <property name="label">gtk-cancel</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="pack_type">end</property>
            <property name="position">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkGrid" id="grid3">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="hexpand">True</property>
            <property name="row_spacing">6</property>
            <property name="column_spacing">12</property>
            <child>
              <object class="GtkLabel" id="prompt">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="use_underline">True</property>
                <property name="mnemonic_widget">entry</property>
                <property name="xalign">0</property>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkEntry" id="entry">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="hexpand">True</property>
                <property name="activates_default">True</property>
              </object>
              <packing>
                <property name="left_attach">1</property>
                <property name="top_attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <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 9e7b13e..56da3de 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -523,6 +523,11 @@ public:
        m_xWindow->setOptimalLayoutSize();
    }

    virtual void window_move(int x, int y) override
    {
        m_xWindow->SetPosPixel(Point(x, y));
    }

    virtual ~SalInstanceWindow() override
    {
        clear_child_help(m_xWindow);
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index f13f408..ca434d2 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1694,6 +1694,11 @@ public:
        gtk_window_resize(m_pWindow, 1, 1);
    }

    virtual void window_move(int x, int y) override
    {
        gtk_window_move(m_pWindow, x, y);
    }

    virtual ~GtkInstanceWindow() override
    {
        if (m_xWindow.is())