include/vcl/jsdialog/executor.hxx     |    4 ++++
 include/vcl/weld.hxx                  |    2 ++
 svtools/source/brwbox/ebbcontrols.cxx |    2 +-
 svtools/source/control/ctrlbox.cxx    |    4 ++--
 svtools/uiconfig/ui/datewindow.ui     |    2 +-
 vcl/inc/jsdialog/jsdialogbuilder.hxx  |    8 ++++++++
 vcl/jsdialog/enabled.cxx              |    1 +
 vcl/jsdialog/executor.cxx             |   21 +++++++++++++++++++++
 vcl/jsdialog/jsdialogbuilder.cxx      |   19 +++++++++++++++++++
 9 files changed, 59 insertions(+), 4 deletions(-)

New commits:
commit 80f96e0aad80d425e3a54ad46193be3655eb29be
Author:     Szymon Kłos <[email protected]>
AuthorDate: Thu Jul 6 15:44:24 2023 +0200
Commit:     Szymon Kłos <[email protected]>
CommitDate: Wed Jul 12 18:36:58 2023 +0200

    jsdialog: calendar widget
    
    Change-Id: I5b2b8a1516ed2e851309dca6ef3200ed522d1b7b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154136
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Pranam Lashkari <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154361
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <[email protected]>

diff --git a/include/vcl/jsdialog/executor.hxx 
b/include/vcl/jsdialog/executor.hxx
index 005f9f36070d..26fd7070e86c 100644
--- a/include/vcl/jsdialog/executor.hxx
+++ b/include/vcl/jsdialog/executor.hxx
@@ -86,6 +86,10 @@ public:
         rButton.signal_selected(rIdent);
     }
 
+    static void trigger_selected(weld::Calendar& rCalendar) { 
rCalendar.signal_selected(); }
+
+    static void trigger_activated(weld::Calendar& rCalendar) { 
rCalendar.signal_activated(); }
+
     static void trigger_value_changed(weld::SpinButton& rSpinButton)
     {
         rSpinButton.signal_value_changed();
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 8d1b5cf7722f..df1bb05c4575 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1896,6 +1896,8 @@ public:
 
 class VCL_DLLPUBLIC Calendar : virtual public Widget
 {
+    friend class ::LOKTrigger;
+
     Link<Calendar&, void> m_aSelectedHdl;
     Link<Calendar&, void> m_aActivatedHdl;
 
diff --git a/svtools/source/brwbox/ebbcontrols.cxx 
b/svtools/source/brwbox/ebbcontrols.cxx
index dc86194576e2..45b1a3766e76 100644
--- a/svtools/source/brwbox/ebbcontrols.cxx
+++ b/svtools/source/brwbox/ebbcontrols.cxx
@@ -531,7 +531,7 @@ namespace svt
         , m_xMenuButton(m_xBuilder->weld_menu_button("button"))
         , m_xCalendarBuilder(Application::CreateBuilder(m_xMenuButton.get(), 
"svt/ui/datewindow.ui"))
         , m_xTopLevel(m_xCalendarBuilder->weld_widget("date_popup_window"))
-        , m_xCalendar(m_xCalendarBuilder->weld_calendar("date"))
+        , m_xCalendar(m_xCalendarBuilder->weld_calendar("date_picker"))
         , m_xExtras(m_xCalendarBuilder->weld_widget("extras"))
         , m_xTodayBtn(m_xCalendarBuilder->weld_button("today"))
         , m_xNoneBtn(m_xCalendarBuilder->weld_button("none"))
diff --git a/svtools/source/control/ctrlbox.cxx 
b/svtools/source/control/ctrlbox.cxx
index ef6334a856c9..b33051f7c911 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -1576,8 +1576,8 @@ 
SvtCalendarBox::SvtCalendarBox(std::unique_ptr<weld::MenuButton> pControl, bool
     : m_bUseLabel(bUseLabel)
     , m_xControl(std::move(pControl))
     , m_xBuilder(Application::CreateBuilder(m_xControl.get(), 
"svt/ui/datewindow.ui"))
-    , m_xTopLevel(m_xBuilder->weld_widget("date_popup_window"))
-    , m_xCalendar(m_xBuilder->weld_calendar("date"))
+    , m_xTopLevel(m_xBuilder->weld_popover("date_popup_window"))
+    , m_xCalendar(m_xBuilder->weld_calendar("date_picker"))
 {
     m_xControl->set_popover(m_xTopLevel.get());
     m_xCalendar->connect_selected(LINK(this, SvtCalendarBox, SelectHdl));
diff --git a/svtools/uiconfig/ui/datewindow.ui 
b/svtools/uiconfig/ui/datewindow.ui
index 9467cbb73213..265affe4afcb 100644
--- a/svtools/uiconfig/ui/datewindow.ui
+++ b/svtools/uiconfig/ui/datewindow.ui
@@ -14,7 +14,7 @@
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkCalendar" id="date">
+          <object class="GtkCalendar" id="date_picker">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="year">2019</property>
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 4d38d66fe9f1..06e2c6135171 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -314,6 +314,7 @@ public:
     virtual std::unique_ptr<weld::Box> weld_box(const OUString& id) override;
     virtual std::unique_ptr<weld::Widget> weld_widget(const OUString& id) 
override;
     virtual std::unique_ptr<weld::Image> weld_image(const OUString& id) 
override;
+    virtual std::unique_ptr<weld::Calendar> weld_calendar(const OUString& id) 
override;
 
     static weld::MessageDialog*
     CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
@@ -861,4 +862,11 @@ public:
     virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& 
rImage) override;
 };
 
+class JSCalendar : public JSWidget<SalInstanceCalendar, ::Calendar>
+{
+public:
+    JSCalendar(JSDialogSender* pSender, ::Calendar* pCalendar, 
SalInstanceBuilder* pBuilder,
+               bool bTakeOwnership);
+};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index bc80fa12109f..f82ded6c5cad 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -279,6 +279,7 @@ bool isBuilderEnabledForPopup(std::u16string_view rUIFile)
         || rUIFile == u"modules/scalc/ui/floatingborderstyle.ui"
         || rUIFile == u"modules/scalc/ui/floatinglinestyle.ui"
         // svt
+        || rUIFile == u"svt/ui/datewindow.ui"
         || rUIFile == u"svt/ui/linewindow.ui"
         // svx
         || rUIFile == u"svx/ui/colorwindow.ui"
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index af514bc70dde..98babfb65023 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -589,6 +589,27 @@ bool ExecuteAction(const OUString& nWindowId, const 
OUString& rWidget, StringMap
                 }
             }
         }
+        else if (sControlType == "calendar")
+        {
+            auto pCalendar = dynamic_cast<weld::Calendar*>(pWidget);
+            if (pCalendar && sAction == "selectdate")
+            {
+                // MM/DD/YYYY
+                OUString aDate = rData["data"];
+
+                if (aDate.getLength() < 10)
+                    return false;
+
+                sal_Int32 aMonth = o3tl::toInt32(aDate.subView(0, 2));
+                sal_Int32 aDay = o3tl::toInt32(aDate.subView(3, 2));
+                sal_Int32 aYear = o3tl::toInt32(aDate.subView(6, 4));
+
+                pCalendar->set_date(Date(aDay, aMonth, aYear));
+                LOKTrigger::trigger_selected(*pCalendar);
+                LOKTrigger::trigger_activated(*pCalendar);
+                return true;
+            }
+        }
     }
 
     return false;
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index d37c5c2ffb59..0f2f23950add 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1258,6 +1258,19 @@ std::unique_ptr<weld::Image> 
JSInstanceBuilder::weld_image(const OUString& id)
     return pWeldWidget;
 }
 
+std::unique_ptr<weld::Calendar> JSInstanceBuilder::weld_calendar(const 
OUString& id)
+{
+    ::Calendar* pCalendar = m_xBuilder->get<::Calendar>(id);
+
+    auto pWeldWidget
+        = pCalendar ? std::make_unique<JSCalendar>(this, pCalendar, this, 
false) : nullptr;
+
+    if (pWeldWidget)
+        RememberWidget(id, pWeldWidget.get());
+
+    return pWeldWidget;
+}
+
 weld::MessageDialog*
 JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, VclMessageType 
eMessageType,
                                        VclButtonsType eButtonType, const 
OUString& rPrimaryMessage,
@@ -2240,4 +2253,10 @@ void JSImage::set_image(const 
css::uno::Reference<css::graphic::XGraphic>& rImag
     sendUpdate();
 }
 
+JSCalendar::JSCalendar(JSDialogSender* pSender, ::Calendar* pCalendar, 
SalInstanceBuilder* pBuilder,
+                       bool bTakeOwnership)
+    : JSWidget<SalInstanceCalendar, ::Calendar>(pSender, pCalendar, pBuilder, 
bTakeOwnership)
+{
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to