include/vcl/jsdialog/executor.hxx    |    5 +++++
 include/vcl/weld.hxx                 |    2 ++
 vcl/inc/jsdialog/jsdialogbuilder.hxx |   13 +++++++++++++
 vcl/jsdialog/executor.cxx            |   12 ++++++++++++
 vcl/jsdialog/jsdialogbuilder.cxx     |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 64 insertions(+)

New commits:
commit 67208bed556329e45975afb862618d8e7acccaf4
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Jul 7 18:13:18 2023 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Jul 11 12:45:20 2023 +0200

    jsdialog: formatted spin field
    
    Change-Id: I5830dd523e0ccc736a686f38319a6c509e5650be
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154193
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Pranam Lashkari <lpra...@collabora.com>

diff --git a/include/vcl/jsdialog/executor.hxx 
b/include/vcl/jsdialog/executor.hxx
index a9873893e4a7..2f4ffd5aba6c 100644
--- a/include/vcl/jsdialog/executor.hxx
+++ b/include/vcl/jsdialog/executor.hxx
@@ -95,6 +95,11 @@ public:
         rSpinButton.signal_value_changed();
     }
 
+    static void trigger_value_changed(weld::FormattedSpinButton& rSpinButton)
+    {
+        rSpinButton.signal_value_changed();
+    }
+
     static void trigger_closed(weld::Popover& rPopover) { rPopover.popdown(); }
 
     static void trigger_key_press(weld::Widget& rWidget, const KeyEvent& 
rEvent)
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 4397018e2958..bf8feaa16ab5 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1851,6 +1851,8 @@ class EntryFormatter;
 // are managed by a more complex Formatter which can support doubles.
 class VCL_DLLPUBLIC FormattedSpinButton : virtual public Entry
 {
+    friend class ::LOKTrigger;
+
     Link<FormattedSpinButton&, void> m_aValueChangedHdl;
 
 protected:
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 85f6c8140369..060a3e1bb72a 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -295,6 +295,8 @@ public:
     virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OString& id) 
override;
     virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id) 
override;
     virtual std::unique_ptr<weld::SpinButton> weld_spin_button(const OString& 
id) override;
+    virtual std::unique_ptr<weld::FormattedSpinButton>
+    weld_formatted_spin_button(const OString& id) override;
     virtual std::unique_ptr<weld::CheckButton> weld_check_button(const 
OString& id) override;
     virtual std::unique_ptr<weld::DrawingArea>
     weld_drawing_area(const OString& id, const a11yref& rA11yImpl = nullptr,
@@ -643,6 +645,17 @@ public:
     virtual void set_value(sal_Int64 value) override;
 };
 
+class JSFormattedSpinButton final
+    : public JSWidget<SalInstanceFormattedSpinButton, ::FormattedField>
+{
+public:
+    JSFormattedSpinButton(JSDialogSender* pSender, ::FormattedField* pSpin,
+                          SalInstanceBuilder* pBuilder, bool bTakeOwnership);
+
+    virtual void set_text(const OUString& rText) override;
+    void set_text_without_notify(const OUString& rText);
+};
+
 class JSMessageDialog final : public JSWidget<SalInstanceMessageDialog, 
::MessageDialog>
 {
     std::unique_ptr<JSDialogSender> m_pOwnedSender;
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index e509504db24c..01ab13d708d9 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -334,6 +334,18 @@ bool ExecuteAction(const std::string& nWindowId, const 
OString& rWidget, StringM
                     return true;
                 }
             }
+
+            auto pFormattedField = 
dynamic_cast<weld::FormattedSpinButton*>(pWidget);
+            if (pFormattedField)
+            {
+                if (sAction == "change")
+                {
+                    pFormattedField->set_text(rData["data"]);
+                    LOKTrigger::trigger_changed(*pFormattedField);
+                    LOKTrigger::trigger_value_changed(*pFormattedField);
+                    return true;
+                }
+            }
         }
         else if (sControlType == "toolbox")
         {
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 9bb60861aadf..5740e300ae9a 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1069,6 +1069,20 @@ std::unique_ptr<weld::SpinButton> 
JSInstanceBuilder::weld_spin_button(const OStr
     return pWeldWidget;
 }
 
+std::unique_ptr<weld::FormattedSpinButton>
+JSInstanceBuilder::weld_formatted_spin_button(const OString& id)
+{
+    FormattedField* pSpinButton = m_xBuilder->get<FormattedField>(id);
+    auto pWeldWidget = pSpinButton
+                           ? std::make_unique<JSFormattedSpinButton>(this, 
pSpinButton, this, false)
+                           : nullptr;
+
+    if (pWeldWidget)
+        RememberWidget(id, pWeldWidget.get());
+
+    return pWeldWidget;
+}
+
 std::unique_ptr<weld::CheckButton> JSInstanceBuilder::weld_check_button(const 
OString& id)
 {
     CheckBox* pCheckButton = m_xBuilder->get<CheckBox>(id);
@@ -1687,6 +1701,24 @@ void JSSpinButton::set_value(sal_Int64 value)
     sendAction(std::move(pMap));
 }
 
+JSFormattedSpinButton::JSFormattedSpinButton(JSDialogSender* pSender, 
::FormattedField* pSpin,
+                                             SalInstanceBuilder* pBuilder, 
bool bTakeOwnership)
+    : JSWidget<SalInstanceFormattedSpinButton, ::FormattedField>(pSender, 
pSpin, pBuilder,
+                                                                 
bTakeOwnership)
+{
+}
+
+void JSFormattedSpinButton::set_text(const OUString& rText)
+{
+    SalInstanceFormattedSpinButton::set_text(rText);
+    sendUpdate();
+}
+
+void JSFormattedSpinButton::set_text_without_notify(const OUString& rText)
+{
+    SalInstanceFormattedSpinButton::set_text(rText);
+}
+
 JSMessageDialog::JSMessageDialog(JSDialogSender* pSender, ::MessageDialog* 
pDialog,
                                  SalInstanceBuilder* pBuilder, bool 
bTakeOwnership)
     : JSWidget<SalInstanceMessageDialog, ::MessageDialog>(pSender, pDialog, 
pBuilder,

Reply via email to