[Libreoffice-commits] core.git: include/svtools include/toolkit include/vcl solenv/clang-format svtools/Library_svt.mk svtools/source svx/source toolkit/source vcl/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 15 13:03:19 UTC 2020


 include/toolkit/awt/vclxwindows.hxx |   13 +
 include/vcl/calendar.hxx            |    9 -
 solenv/clang-format/excludelist     |    3 
 svtools/Library_svt.mk              |    1 
 svtools/source/control/calendar.cxx |  235 ------------------------------------
 svtools/source/inc/unoiface.hxx     |   14 --
 svtools/source/uno/unoiface.cxx     |   53 --------
 svx/source/fmcomp/gridcell.cxx      |    2 
 toolkit/source/awt/vclxtoolkit.cxx  |   11 +
 toolkit/source/awt/vclxwindows.cxx  |   42 ++++++
 vcl/source/control/calendar.cxx     |  208 +++++++++++++++++++++++++++++++
 11 files changed, 279 insertions(+), 312 deletions(-)

New commits:
commit c8fed68b953e5c1b3101758413fac4809ff3380e
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Jul 15 11:54:52 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Jul 15 15:02:27 2020 +0200

    move SVTXDateField to toolkit
    
    and svtools CalendarField to vcl
    
    Change-Id: I6f3e9a71f21ac7ca70f8172d4f8be4804f3b1c7f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98818
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/toolkit/awt/vclxwindows.hxx b/include/toolkit/awt/vclxwindows.hxx
index 42d3bf95f9f2..af85219b7ef6 100644
--- a/include/toolkit/awt/vclxwindows.hxx
+++ b/include/toolkit/awt/vclxwindows.hxx
@@ -1401,6 +1401,19 @@ public:
     virtual void    GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override;
 };
 
+class SVTXDateField : public VCLXDateField
+{
+public:
+                    SVTXDateField();
+                    virtual ~SVTXDateField() override;
+
+    // css::awt::VclWindowPeer
+    void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
+
+    static void     ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds );
+    virtual void    GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
+};
+
 #endif // INCLUDED_TOOLKIT_AWT_VCLXWINDOWS_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svtools/calendar.hxx b/include/vcl/calendar.hxx
similarity index 93%
rename from include/svtools/calendar.hxx
rename to include/vcl/calendar.hxx
index a547fb450221..a88105e29e59 100644
--- a/include/svtools/calendar.hxx
+++ b/include/vcl/calendar.hxx
@@ -17,11 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#ifndef INCLUDED_SVTOOLS_CALENDAR_HXX
-#define INCLUDED_SVTOOLS_CALENDAR_HXX
+#pragma once
 
 #include <config_options.h>
-#include <svtools/svtdllapi.h>
+#include <vcl/dllapi.h>
 
 #include <vcl/field.hxx>
 #include <vcl/weld.hxx>
@@ -65,7 +64,7 @@ method in CalendarField and create an own calendar there ourselves.
 *************************************************************************/
 
 
-class UNLESS_MERGELIBS(SVT_DLLPUBLIC) CalendarField final : public DateField
+class VCL_DLLPUBLIC CalendarField final : public DateField
 {
 private:
     VclPtr<ImplCFieldFloatWin> mpFloatWin;
@@ -92,6 +91,4 @@ private:
     virtual void    StateChanged( StateChangedType nStateChange ) override;
 };
 
-#endif // INCLUDED_SVTOOLS_CALENDAR_HXX
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index 9108087a4a11..ac6e1e28bdee 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -6565,7 +6565,6 @@ include/svtools/borderhelper.hxx
 include/svtools/borderline.hxx
 include/svtools/brwbox.hxx
 include/svtools/brwhead.hxx
-include/svtools/calendar.hxx
 include/svtools/cliplistener.hxx
 include/svtools/collatorres.hxx
 include/svtools/colorcfg.hxx
@@ -7322,6 +7321,7 @@ include/vcl/builder.hxx
 include/vcl/builderfactory.hxx
 include/vcl/button.hxx
 include/vcl/cairo.hxx
+include/vcl/calendar.hxx
 include/vcl/canvastools.hxx
 include/vcl/checksum.hxx
 include/vcl/commandevent.hxx
@@ -13019,7 +13019,6 @@ svtools/source/contnr/templwin.hxx
 svtools/source/control/accessibleruler.cxx
 svtools/source/control/accessibleruler.hxx
 svtools/source/control/asynclink.cxx
-svtools/source/control/calendar.cxx
 svtools/source/control/collatorres.cxx
 svtools/source/control/ctrlbox.cxx
 svtools/source/control/ctrltool.cxx
diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk
index 3723fe67bb42..63bb7e13205d 100644
--- a/svtools/Library_svt.mk
+++ b/svtools/Library_svt.mk
@@ -92,7 +92,6 @@ $(eval $(call gb_Library_add_exception_objects,svt,\
     svtools/source/contnr/templwin \
     svtools/source/control/accessibleruler \
     svtools/source/control/asynclink \
-    svtools/source/control/calendar \
     svtools/source/control/collatorres \
     svtools/source/control/ctrlbox \
     svtools/source/control/ctrltool \
diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx
deleted file mode 100644
index f768e803185d..000000000000
--- a/svtools/source/control/calendar.cxx
+++ /dev/null
@@ -1,235 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/InterimItemWindow.hxx>
-#include <vcl/event.hxx>
-#include <vcl/dockwin.hxx>
-#include <vcl/svapp.hxx>
-
-#include <svtools/strings.hrc>
-#include <svtools/svtresid.hxx>
-#include <svtools/calendar.hxx>
-
-namespace
-{
-    class ImplCFieldFloat final
-    {
-    private:
-        std::unique_ptr<weld::Builder> mxBuilder;
-        std::unique_ptr<weld::Container> mxContainer;
-        std::unique_ptr<weld::Calendar> mxCalendar;
-        std::unique_ptr<weld::Button> mxTodayBtn;
-        std::unique_ptr<weld::Button> mxNoneBtn;
-
-    public:
-        ImplCFieldFloat(vcl::Window* pContainer)
-            : mxBuilder(Application::CreateInterimBuilder(pContainer, "svt/ui/calendar.ui"))
-            , mxContainer(mxBuilder->weld_container("Calendar"))
-            , mxCalendar(mxBuilder->weld_calendar("date"))
-            , mxTodayBtn(mxBuilder->weld_button("today"))
-            , mxNoneBtn(mxBuilder->weld_button("none"))
-        {
-        }
-
-        weld::Calendar* GetCalendar() { return mxCalendar.get(); }
-        weld::Button*   EnableTodayBtn(bool bEnable);
-        weld::Button*   EnableNoneBtn(bool bEnable);
-
-        void GrabFocus()
-        {
-            mxCalendar->grab_focus();
-        }
-    };
-}
-
-struct ImplCFieldFloatWin : public DockingWindow
-{
-    explicit ImplCFieldFloatWin(vcl::Window* pParent);
-    virtual void dispose() override;
-    virtual ~ImplCFieldFloatWin() override;
-    virtual void GetFocus() override;
-
-    VclPtr<vcl::Window> mxBox;
-    std::unique_ptr<ImplCFieldFloat> mxWidget;
-};
-
-ImplCFieldFloatWin::ImplCFieldFloatWin(vcl::Window* pParent)
-    : DockingWindow(pParent, "InterimDockParent", "svx/ui/interimdockparent.ui")
-    , mxBox(get("box"))
-{
-    setDeferredProperties();
-    mxWidget.reset(new ImplCFieldFloat(mxBox.get()));
-}
-
-ImplCFieldFloatWin::~ImplCFieldFloatWin()
-{
-    disposeOnce();
-}
-
-void ImplCFieldFloatWin::dispose()
-{
-    mxWidget.reset();
-    mxBox.disposeAndClear();
-    DockingWindow::dispose();
-}
-
-void ImplCFieldFloatWin::GetFocus()
-{
-    DockingWindow::GetFocus();
-    if (!mxWidget)
-        return;
-    mxWidget->GrabFocus();
-}
-
-weld::Button* ImplCFieldFloat::EnableTodayBtn(bool bEnable)
-{
-    mxTodayBtn->set_visible(bEnable);
-    return bEnable ? mxTodayBtn.get() : nullptr;
-}
-
-weld::Button* ImplCFieldFloat::EnableNoneBtn(bool bEnable)
-{
-    mxNoneBtn->set_visible(bEnable);
-    return bEnable ? mxNoneBtn.get() : nullptr;
-}
-
-CalendarField::CalendarField(vcl::Window* pParent, WinBits nWinStyle)
-    : DateField(pParent, nWinStyle)
-    , mpFloatWin(nullptr)
-    , mpTodayBtn(nullptr)
-    , mpNoneBtn(nullptr)
-    , mbToday(false)
-    , mbNone(false)
-{
-}
-
-CalendarField::~CalendarField()
-{
-    disposeOnce();
-}
-
-void CalendarField::dispose()
-{
-    mpTodayBtn = nullptr;
-    mpNoneBtn = nullptr;
-    mpFloatWin.disposeAndClear();
-    DateField::dispose();
-}
-
-IMPL_LINK(CalendarField, ImplSelectHdl, weld::Calendar&, rCalendar, void)
-{
-    Date aNewDate = rCalendar.get_date();
-
-    vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
-    mpFloatWin->EnableDocking(false);
-    EndDropDown();
-    GrabFocus();
-    if ( IsEmptyDate() || ( aNewDate != GetDate() ) )
-    {
-        SetDate( aNewDate );
-        SetModifyFlag();
-        Modify();
-    }
-}
-
-IMPL_LINK(CalendarField, ImplClickHdl, weld::Button&, rBtn, void)
-{
-    vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
-    mpFloatWin->EnableDocking(false);
-    EndDropDown();
-    GrabFocus();
-
-    if (&rBtn == mpTodayBtn)
-    {
-        Date aToday( Date::SYSTEM );
-        if ( (aToday != GetDate()) || IsEmptyDate() )
-        {
-            SetDate( aToday );
-            SetModifyFlag();
-            Modify();
-        }
-    }
-    else if (&rBtn == mpNoneBtn)
-    {
-        if ( !IsEmptyDate() )
-        {
-            SetEmptyDate();
-            SetModifyFlag();
-            Modify();
-        }
-    }
-}
-
-IMPL_LINK_NOARG(CalendarField, ImplPopupModeEndHdl, FloatingWindow*, void)
-{
-    EndDropDown();
-    GrabFocus();
-}
-
-bool CalendarField::ShowDropDown( bool bShow )
-{
-    if ( bShow )
-    {
-        if ( !mpFloatWin )
-            mpFloatWin = VclPtr<ImplCFieldFloatWin>::Create( this );
-
-        Date aDate = GetDate();
-        if ( IsEmptyDate() || !aDate.IsValidAndGregorian() )
-        {
-            aDate = Date( Date::SYSTEM );
-        }
-        weld::Calendar* pCalendar = mpFloatWin->mxWidget->GetCalendar();
-        pCalendar->set_date( aDate );
-        pCalendar->connect_activated(LINK(this, CalendarField, ImplSelectHdl));
-        mpTodayBtn = mpFloatWin->mxWidget->EnableTodayBtn(mbToday);
-        mpNoneBtn = mpFloatWin->mxWidget->EnableNoneBtn(mbNone);
-        if (mpTodayBtn)
-            mpTodayBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) );
-        if (mpNoneBtn)
-            mpNoneBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) );
-        Point aPos(GetParent()->OutputToScreenPixel(GetPosPixel()));
-        tools::Rectangle aRect(aPos, GetSizePixel());
-        aRect.AdjustBottom( -1 );
-        DockingManager* pDockingManager = vcl::Window::GetDockingManager();
-        mpFloatWin->EnableDocking(true);
-        pDockingManager->SetPopupModeEndHdl(mpFloatWin, LINK(this, CalendarField, ImplPopupModeEndHdl));
-        pDockingManager->StartPopupMode(mpFloatWin, aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
-    }
-    else
-    {
-        vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
-        mpFloatWin->EnableDocking(false);
-        EndDropDown();
-    }
-    return true;
-}
-
-void CalendarField::StateChanged( StateChangedType nStateChange )
-{
-    DateField::StateChanged( nStateChange );
-
-    if ( ( nStateChange == StateChangedType::Style ) && GetSubEdit() )
-    {
-        WinBits nAllAlignmentBits = ( WB_LEFT | WB_CENTER | WB_RIGHT | WB_TOP | WB_VCENTER | WB_BOTTOM );
-        WinBits nMyAlignment = GetStyle() & nAllAlignmentBits;
-        GetSubEdit()->SetStyle( ( GetSubEdit()->GetStyle() & ~nAllAlignmentBits ) | nMyAlignment );
-    }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/inc/unoiface.hxx b/svtools/source/inc/unoiface.hxx
index 7813b9ffe59c..1d3d5cb8ccd6 100644
--- a/svtools/source/inc/unoiface.hxx
+++ b/svtools/source/inc/unoiface.hxx
@@ -98,18 +98,4 @@ public:
     virtual void    GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
 };
 
-class SVTXDateField : public VCLXDateField
-{
-public:
-                    SVTXDateField();
-                    virtual ~SVTXDateField() override;
-
-    // css::awt::VclWindowPeer
-    void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
-
-    static void     ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds );
-    virtual void    GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
-};
-
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/uno/unoiface.cxx b/svtools/source/uno/unoiface.cxx
index 7f10167cf64a..fbd257f8f13c 100644
--- a/svtools/source/uno/unoiface.cxx
+++ b/svtools/source/uno/unoiface.cxx
@@ -29,7 +29,6 @@
 #include <toolkit/helper/convert.hxx>
 #include <toolkit/helper/property.hxx>
 #include <svl/numuno.hxx>
-#include <svtools/calendar.hxx>
 #include "svtxgridcontrol.hxx"
 #include <table/tablecontrol.hxx>
 
@@ -70,16 +69,6 @@ SAL_DLLPUBLIC_EXPORT vcl::Window* CreateWindow( VCLXWindow** ppNewComp, const cs
             return nullptr;
         }
     }
-    else if (aServiceName.equalsIgnoreAsciiCase("datefield") )
-    {
-        pWindow = VclPtr<CalendarField>::Create( pParent, nWinBits);
-        static_cast<CalendarField*>(pWindow)->EnableToday();
-        static_cast<CalendarField*>(pWindow)->EnableNone();
-        static_cast<CalendarField*>(pWindow)->EnableEmptyFieldValue( true );
-        SVTXDateField * newComp = new SVTXDateField;
-        *ppNewComp = newComp;
-        newComp->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pWindow)) );
-    }
     else if ( aServiceName.equalsIgnoreAsciiCase( "Grid" ) )
     {
         if ( pParent )
@@ -467,46 +456,4 @@ void VCLXMultiLineEdit::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
     VCLXWindow::ImplGetPropertyIds( rIds, true );
 }
 
-SVTXDateField::SVTXDateField()
-    :VCLXDateField()
-{
-}
-
-SVTXDateField::~SVTXDateField()
-{
-}
-
-void SAL_CALL SVTXDateField::setProperty( const OUString& PropertyName, const css::uno::Any& Value )
-{
-    VCLXDateField::setProperty( PropertyName, Value );
-
-    // some properties need to be forwarded to the sub edit, too
-    SolarMutexGuard g;
-    VclPtr< Edit > pSubEdit = GetWindow() ? static_cast< Edit* >( GetWindow().get() )->GetSubEdit() : nullptr;
-    if ( !pSubEdit )
-        return;
-
-    switch ( GetPropertyId( PropertyName ) )
-    {
-    case BASEPROPERTY_TEXTLINECOLOR:
-        if ( !Value.hasValue() )
-            pSubEdit->SetTextLineColor();
-        else
-        {
-            sal_Int32 nColor = 0;
-            if ( Value >>= nColor )
-                pSubEdit->SetTextLineColor( Color( nColor ) );
-        }
-        break;
-    }
-}
-
-void SVTXDateField::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
-{
-    PushPropertyIds( rIds,
-                     BASEPROPERTY_TEXTLINECOLOR,
-                     0);
-    VCLXDateField::ImplGetPropertyIds( rIds );
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx
index b29fdcbc5f79..c6e280205eb9 100644
--- a/svx/source/fmcomp/gridcell.cxx
+++ b/svx/source/fmcomp/gridcell.cxx
@@ -55,7 +55,7 @@
 #include <i18nlangtag/lang.h>
 
 #include <rtl/math.hxx>
-#include <svtools/calendar.hxx>
+#include <vcl/calendar.hxx>
 #include <svl/numuno.hxx>
 #include <svl/zforlist.hxx>
 #include <svx/dialmgr.hxx>
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
index 3671963c4234..eb5273cde27d 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -81,6 +81,7 @@
 #include <controls/filectrl.hxx>
 #include <controls/treecontrolpeer.hxx>
 #include <vcl/toolkit/button.hxx>
+#include <vcl/calendar.hxx>
 #include <vcl/toolkit/combobox.hxx>
 #include <vcl/ctrl.hxx>
 #include <vcl/toolkit/dialog.hxx>
@@ -1815,6 +1816,16 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
                     pNewWindow = VclPtr<DoubleCurrencyField>::Create( pParent, nWinBits );
                     *ppNewComp = new SVTXCurrencyField;
                 }
+                else if (aServiceName == "datefield")
+                {
+                    pNewWindow = VclPtr<CalendarField>::Create(pParent, nWinBits);
+                    static_cast<CalendarField*>(pNewWindow.get())->EnableToday();
+                    static_cast<CalendarField*>(pNewWindow.get())->EnableNone();
+                    static_cast<CalendarField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
+                    SVTXDateField * newComp = new SVTXDateField;
+                    *ppNewComp = newComp;
+                    newComp->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pNewWindow.get())) );
+                }
             break;
             default:
                 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx
index 964cdf0dd3a3..396fa5dade35 100644
--- a/toolkit/source/awt/vclxwindows.cxx
+++ b/toolkit/source/awt/vclxwindows.cxx
@@ -8153,4 +8153,46 @@ void SVTXNumericField::GetPropertyIds( std::vector< sal_uInt16 > &rIds )
     SVTXFormattedField::ImplGetPropertyIds( rIds );
 }
 
+SVTXDateField::SVTXDateField()
+    :VCLXDateField()
+{
+}
+
+SVTXDateField::~SVTXDateField()
+{
+}
+
+void SAL_CALL SVTXDateField::setProperty( const OUString& PropertyName, const css::uno::Any& Value )
+{
+    VCLXDateField::setProperty( PropertyName, Value );
+
+    // some properties need to be forwarded to the sub edit, too
+    SolarMutexGuard g;
+    VclPtr< Edit > pSubEdit = GetWindow() ? static_cast< Edit* >( GetWindow().get() )->GetSubEdit() : nullptr;
+    if ( !pSubEdit )
+        return;
+
+    switch ( GetPropertyId( PropertyName ) )
+    {
+    case BASEPROPERTY_TEXTLINECOLOR:
+        if ( !Value.hasValue() )
+            pSubEdit->SetTextLineColor();
+        else
+        {
+            sal_Int32 nColor = 0;
+            if ( Value >>= nColor )
+                pSubEdit->SetTextLineColor( Color( nColor ) );
+        }
+        break;
+    }
+}
+
+void SVTXDateField::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
+{
+    PushPropertyIds( rIds,
+                     BASEPROPERTY_TEXTLINECOLOR,
+                     0);
+    VCLXDateField::ImplGetPropertyIds( rIds );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/calendar.cxx b/vcl/source/control/calendar.cxx
index c306185f1907..083bfa6d34d6 100644
--- a/vcl/source/control/calendar.cxx
+++ b/vcl/source/control/calendar.cxx
@@ -22,7 +22,9 @@
 #include <vcl/menu.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/event.hxx>
+#include <vcl/calendar.hxx>
 #include <vcl/commandevent.hxx>
+#include <vcl/dockwin.hxx>
 #include <unotools/calendarwrapper.hxx>
 #include <unotools/localedatawrapper.hxx>
 #include <com/sun/star/i18n/Weekdays.hpp>
@@ -1511,4 +1513,210 @@ Size Calendar::GetOptimalSize() const
     return CalcWindowSizePixel();
 }
 
+namespace
+{
+    class ImplCFieldFloat final
+    {
+    private:
+        std::unique_ptr<weld::Builder> mxBuilder;
+        std::unique_ptr<weld::Container> mxContainer;
+        std::unique_ptr<weld::Calendar> mxCalendar;
+        std::unique_ptr<weld::Button> mxTodayBtn;
+        std::unique_ptr<weld::Button> mxNoneBtn;
+
+    public:
+        ImplCFieldFloat(vcl::Window* pContainer)
+            : mxBuilder(Application::CreateInterimBuilder(pContainer, "svt/ui/calendar.ui"))
+            , mxContainer(mxBuilder->weld_container("Calendar"))
+            , mxCalendar(mxBuilder->weld_calendar("date"))
+            , mxTodayBtn(mxBuilder->weld_button("today"))
+            , mxNoneBtn(mxBuilder->weld_button("none"))
+        {
+        }
+
+        weld::Calendar* GetCalendar() { return mxCalendar.get(); }
+        weld::Button*   EnableTodayBtn(bool bEnable);
+        weld::Button*   EnableNoneBtn(bool bEnable);
+
+        void GrabFocus()
+        {
+            mxCalendar->grab_focus();
+        }
+    };
+}
+
+struct ImplCFieldFloatWin : public DockingWindow
+{
+    explicit ImplCFieldFloatWin(vcl::Window* pParent);
+    virtual void dispose() override;
+    virtual ~ImplCFieldFloatWin() override;
+    virtual void GetFocus() override;
+
+    VclPtr<vcl::Window> mxBox;
+    std::unique_ptr<ImplCFieldFloat> mxWidget;
+};
+
+ImplCFieldFloatWin::ImplCFieldFloatWin(vcl::Window* pParent)
+    : DockingWindow(pParent, "InterimDockParent", "svx/ui/interimdockparent.ui")
+    , mxBox(get("box"))
+{
+    setDeferredProperties();
+    mxWidget.reset(new ImplCFieldFloat(mxBox.get()));
+}
+
+ImplCFieldFloatWin::~ImplCFieldFloatWin()
+{
+    disposeOnce();
+}
+
+void ImplCFieldFloatWin::dispose()
+{
+    mxWidget.reset();
+    mxBox.disposeAndClear();
+    DockingWindow::dispose();
+}
+
+void ImplCFieldFloatWin::GetFocus()
+{
+    DockingWindow::GetFocus();
+    if (!mxWidget)
+        return;
+    mxWidget->GrabFocus();
+}
+
+weld::Button* ImplCFieldFloat::EnableTodayBtn(bool bEnable)
+{
+    mxTodayBtn->set_visible(bEnable);
+    return bEnable ? mxTodayBtn.get() : nullptr;
+}
+
+weld::Button* ImplCFieldFloat::EnableNoneBtn(bool bEnable)
+{
+    mxNoneBtn->set_visible(bEnable);
+    return bEnable ? mxNoneBtn.get() : nullptr;
+}
+
+CalendarField::CalendarField(vcl::Window* pParent, WinBits nWinStyle)
+    : DateField(pParent, nWinStyle)
+    , mpFloatWin(nullptr)
+    , mpTodayBtn(nullptr)
+    , mpNoneBtn(nullptr)
+    , mbToday(false)
+    , mbNone(false)
+{
+}
+
+CalendarField::~CalendarField()
+{
+    disposeOnce();
+}
+
+void CalendarField::dispose()
+{
+    mpTodayBtn = nullptr;
+    mpNoneBtn = nullptr;
+    mpFloatWin.disposeAndClear();
+    DateField::dispose();
+}
+
+IMPL_LINK(CalendarField, ImplSelectHdl, weld::Calendar&, rCalendar, void)
+{
+    Date aNewDate = rCalendar.get_date();
+
+    vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
+    mpFloatWin->EnableDocking(false);
+    EndDropDown();
+    GrabFocus();
+    if ( IsEmptyDate() || ( aNewDate != GetDate() ) )
+    {
+        SetDate( aNewDate );
+        SetModifyFlag();
+        Modify();
+    }
+}
+
+IMPL_LINK(CalendarField, ImplClickHdl, weld::Button&, rBtn, void)
+{
+    vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
+    mpFloatWin->EnableDocking(false);
+    EndDropDown();
+    GrabFocus();
+
+    if (&rBtn == mpTodayBtn)
+    {
+        Date aToday( Date::SYSTEM );
+        if ( (aToday != GetDate()) || IsEmptyDate() )
+        {
+            SetDate( aToday );
+            SetModifyFlag();
+            Modify();
+        }
+    }
+    else if (&rBtn == mpNoneBtn)
+    {
+        if ( !IsEmptyDate() )
+        {
+            SetEmptyDate();
+            SetModifyFlag();
+            Modify();
+        }
+    }
+}
+
+IMPL_LINK_NOARG(CalendarField, ImplPopupModeEndHdl, FloatingWindow*, void)
+{
+    EndDropDown();
+    GrabFocus();
+}
+
+bool CalendarField::ShowDropDown( bool bShow )
+{
+    if ( bShow )
+    {
+        if ( !mpFloatWin )
+            mpFloatWin = VclPtr<ImplCFieldFloatWin>::Create( this );
+
+        Date aDate = GetDate();
+        if ( IsEmptyDate() || !aDate.IsValidAndGregorian() )
+        {
+            aDate = Date( Date::SYSTEM );
+        }
+        weld::Calendar* pCalendar = mpFloatWin->mxWidget->GetCalendar();
+        pCalendar->set_date( aDate );
+        pCalendar->connect_activated(LINK(this, CalendarField, ImplSelectHdl));
+        mpTodayBtn = mpFloatWin->mxWidget->EnableTodayBtn(mbToday);
+        mpNoneBtn = mpFloatWin->mxWidget->EnableNoneBtn(mbNone);
+        if (mpTodayBtn)
+            mpTodayBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) );
+        if (mpNoneBtn)
+            mpNoneBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) );
+        Point aPos(GetParent()->OutputToScreenPixel(GetPosPixel()));
+        tools::Rectangle aRect(aPos, GetSizePixel());
+        aRect.AdjustBottom( -1 );
+        DockingManager* pDockingManager = vcl::Window::GetDockingManager();
+        mpFloatWin->EnableDocking(true);
+        pDockingManager->SetPopupModeEndHdl(mpFloatWin, LINK(this, CalendarField, ImplPopupModeEndHdl));
+        pDockingManager->StartPopupMode(mpFloatWin, aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
+    }
+    else
+    {
+        vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin);
+        mpFloatWin->EnableDocking(false);
+        EndDropDown();
+    }
+    return true;
+}
+
+void CalendarField::StateChanged( StateChangedType nStateChange )
+{
+    DateField::StateChanged( nStateChange );
+
+    if ( ( nStateChange == StateChangedType::Style ) && GetSubEdit() )
+    {
+        WinBits nAllAlignmentBits = ( WB_LEFT | WB_CENTER | WB_RIGHT | WB_TOP | WB_VCENTER | WB_BOTTOM );
+        WinBits nMyAlignment = GetStyle() & nAllAlignmentBits;
+        GetSubEdit()->SetStyle( ( GetSubEdit()->GetStyle() & ~nAllAlignmentBits ) | nMyAlignment );
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list