[Libreoffice-commits] core.git: include/xmloff sw/inc sw/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 11 22:17:45 UTC 2019


 include/xmloff/odffields.hxx      |    2 +
 sw/inc/IDocumentMarkAccess.hxx    |    1 
 sw/source/core/crsr/bookmrk.cxx   |   54 ++++++++++++++++++++++++++++++++++++++
 sw/source/core/doc/docbm.cxx      |   18 ++++++++++++
 sw/source/core/inc/bookmrk.hxx    |   20 ++++++++++++++
 sw/source/core/text/itrform2.cxx  |   10 +++++++
 sw/source/core/text/porfld.cxx    |   18 ++++++++++++
 sw/source/core/text/porfld.hxx    |   17 +++++++++++
 sw/source/core/unocore/unobkm.cxx |    4 ++
 9 files changed, 143 insertions(+), 1 deletion(-)

New commits:
commit 0fd05f6503c42df35b16735c7b690e56f1acab30
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri May 31 17:34:51 2019 +0200
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jul 12 00:16:40 2019 +0200

    MSForms: Introduce a new fieldmark class for text-based date field
    
    Change-Id: I3df49c516603fb16601fc0a9c13c6d9ea401207a
    Reviewed-on: https://gerrit.libreoffice.org/75437
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/include/xmloff/odffields.hxx b/include/xmloff/odffields.hxx
index 27525fb39374..82127a57628e 100644
--- a/include/xmloff/odffields.hxx
+++ b/include/xmloff/odffields.hxx
@@ -33,6 +33,8 @@
 #define ODF_FORMDROPDOWN_LISTENTRY "Dropdown_ListEntry"
 #define ODF_FORMDROPDOWN_RESULT "Dropdown_Selected"
 
+#define ODF_FORMDATE "vnd.oasis.opendocument.field.FORMDATE"
+
 #define ODF_TOC "vnd.oasis.opendocument.field.TOC"
 
 #define ODF_HYPERLINK "vnd.oasis.opendocument.field.HYPERLINK"
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 31dd74f9f443..9670e811f044 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -50,6 +50,7 @@ class IDocumentMarkAccess
             TEXT_FIELDMARK,
             CHECKBOX_FIELDMARK,
             DROPDOWN_FIELDMARK,
+            DATE_FIELDMARK,
             NAVIGATOR_REMINDER
         };
 
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index bbe7867f03a2..5d570b96bafe 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -533,6 +533,60 @@ namespace sw { namespace mark
         if(m_pButton)
             m_pButton.disposeAndClear();
     }
+
+    DateFieldmark::DateFieldmark(const SwPaM& rPaM)
+        : NonTextFieldmark(rPaM)
+        //, m_pButton(nullptr)
+    {
+    }
+
+    DateFieldmark::~DateFieldmark()
+    {
+        //m_pButton.disposeAndClear();
+        (void)m_pButton;
+    }
+
+    void DateFieldmark::SetPortionPaintArea(const SwRect& /*rPortionPaintArea*/)
+    {
+        /*if(m_aPortionPaintArea == rPortionPaintArea &&
+           m_pButton && m_pButton->IsVisible())
+            return;
+
+        m_aPortionPaintArea = rPortionPaintArea;
+        if(m_pButton)
+        {
+            m_pButton->Show();
+            m_pButton->CalcPosAndSize(m_aPortionPaintArea);
+            m_pButton->Invalidate();
+        }*/
+        (void)m_pButton;
+    }
+
+    void DateFieldmark::ShowButton(SwEditWin* pEditWin)
+    {
+        if(pEditWin)
+        {
+            //if(!m_pButton)
+            //    m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
+            //m_pButton->CalcPosAndSize(m_aPortionPaintArea);
+            //m_pButton->Show();
+        }
+        (void)m_pButton;
+    }
+
+    void DateFieldmark::HideButton()
+    {
+        //if(m_pButton)
+            //m_pButton->Show(false);
+        (void)m_pButton;
+    }
+
+    void DateFieldmark::RemoveButton()
+    {
+        //if(m_pButton)
+            //m_pButton.disposeAndClear();
+        (void)m_pButton;
+    }
 }}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index b603d5f608b8..0f754c74d798 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -502,6 +502,8 @@ IDocumentMarkAccess::MarkType IDocumentMarkAccess::GetType(const IMark& rBkmk)
         return MarkType::CHECKBOX_FIELDMARK;
     else if(*pMarkTypeInfo == typeid(DropDownFieldmark))
         return MarkType::DROPDOWN_FIELDMARK;
+    else if(*pMarkTypeInfo == typeid(DateFieldmark))
+        return MarkType::DATE_FIELDMARK;
     else if(*pMarkTypeInfo == typeid(NavigatorReminder))
         return MarkType::NAVIGATOR_REMINDER;
     else
@@ -578,6 +580,9 @@ namespace sw { namespace mark
             case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
                 pMark = std::make_unique<DropDownFieldmark>(rPaM);
                 break;
+            case IDocumentMarkAccess::MarkType::DATE_FIELDMARK:
+                pMark = std::make_unique<DateFieldmark>(rPaM);
+                break;
             case IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER:
                 pMark = std::make_unique<NavigatorReminder>(rPaM);
                 break;
@@ -623,6 +628,7 @@ namespace sw { namespace mark
             case IDocumentMarkAccess::MarkType::TEXT_FIELDMARK:
             case IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK:
             case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
+            case IDocumentMarkAccess::MarkType::DATE_FIELDMARK:
                 lcl_InsertMarkSorted(m_vFieldmarks, pMark.get());
                 break;
             case IDocumentMarkAccess::MarkType::ANNOTATIONMARK:
@@ -696,6 +702,12 @@ namespace sw { namespace mark
                     IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK,
                     sw::mark::InsertMode::New);
         }
+        else if(rType == ODF_FORMDATE)
+        {
+            pMark = makeMark( rPaM, rName,
+                    IDocumentMarkAccess::MarkType::DATE_FIELDMARK,
+                    sw::mark::InsertMode::New);
+        }
 
         sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
         if (pFieldMark)
@@ -1107,6 +1119,7 @@ namespace sw { namespace mark
             case IDocumentMarkAccess::MarkType::TEXT_FIELDMARK:
             case IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK:
             case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
+            case IDocumentMarkAccess::MarkType::DATE_FIELDMARK:
                 {
                     auto const ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark.get());
                     if ( ppFieldmark != m_vFieldmarks.end() )
@@ -1274,6 +1287,11 @@ namespace sw { namespace mark
             if (dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
                 bActualChange = true;
         }
+        else if(rNewType == ODF_FORMDATE)
+        {
+            if (dynamic_cast<::sw::mark::DateFieldmark*>(pFieldmark))
+                bActualChange = true;
+        }
 
         if (!bActualChange)
             return nullptr;
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 22b4f94b8de8..30b75bcbe6b1 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -287,6 +287,26 @@ namespace sw {
             SwRect m_aPortionPaintArea;
             VclPtr<DropDownFormFieldButton> m_pButton;
         };
+
+        /// Fieldmark representing a date form field.
+        class DateFieldmark
+            : public NonTextFieldmark
+        {
+        public:
+            DateFieldmark(const SwPaM& rPaM);
+            virtual ~DateFieldmark() override;
+
+            // This method should be called only by the portion so we can now the portion's painting area
+            void SetPortionPaintArea(const SwRect& rPortionPaintArea);
+
+            void ShowButton(SwEditWin* pEditWin);
+            void HideButton();
+            void RemoveButton();
+
+        private:
+            SwRect m_aPortionPaintArea;
+            VclPtr<MenuButton> m_pButton;
+        };
     }
 }
 #endif
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index da17ddeff5da..44893f9b693e 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -863,6 +863,12 @@ namespace sw { namespace mark {
         sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
         return OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH);
     }
+
+    static OUString ExpandDateFieldmark(IFieldmark* /*pBM*/)
+    {
+        sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
+        return OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH);
+    }
 } }
 
 SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const
@@ -910,6 +916,10 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const
                     {
                         pPor = new SwFieldFormDropDownPortion(pBM, sw::mark::ExpandFieldmark(pBM));
                     }
+                    else if (pBM->GetFieldname( ) == ODF_FORMDATE)
+                    {
+                        pPor = new SwFieldFormDatePortion(pBM, sw::mark::ExpandDateFieldmark(pBM));
+                    }
                     /* we need to check for ODF_FORMTEXT for scenario having FormFields inside FORMTEXT.
                      * Otherwise file will crash on open.
                      */
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index bc671fad230d..09ace4f82c84 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -1329,4 +1329,22 @@ void SwFieldFormDropDownPortion::Paint( const SwTextPaintInfo &rInf ) const
     }
 }
 
+SwFieldPortion *SwFieldFormDatePortion::Clone(const OUString &rExpand) const
+{
+    return new SwFieldFormDatePortion(m_pFieldMark, rExpand);
+}
+
+void SwFieldFormDatePortion::Paint( const SwTextPaintInfo &rInf ) const
+{
+    SwFieldPortion::Paint( rInf );
+
+    ::sw::mark::DateFieldmark* pDateField = dynamic_cast< ::sw::mark::DateFieldmark* >(m_pFieldMark);
+    if(pDateField)
+    {
+        SwRect aPaintArea;
+        rInf.CalcRect( *this, &aPaintArea );
+        pDateField->SetPortionPaintArea(aPaintArea);
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/porfld.hxx b/sw/source/core/text/porfld.hxx
index 2508fa899fdd..0363e9d6ab6f 100644
--- a/sw/source/core/text/porfld.hxx
+++ b/sw/source/core/text/porfld.hxx
@@ -232,6 +232,23 @@ private:
     sw::mark::IFieldmark* m_pFieldMark;
 };
 
+class SwFieldFormDatePortion : public SwFieldPortion
+{
+public:
+    explicit SwFieldFormDatePortion(sw::mark::IFieldmark *pFieldMark, const OUString &rExpand)
+        : SwFieldPortion(rExpand)
+        , m_pFieldMark(pFieldMark)
+    {
+    }
+    // Field cloner for SplitGlue
+    virtual SwFieldPortion *Clone( const OUString &rExpand ) const override;
+
+    virtual void Paint( const SwTextPaintInfo &rInf ) const override;
+
+private:
+    sw::mark::IFieldmark* m_pFieldMark;
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index 80d187be70a9..482185361409 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -622,7 +622,7 @@ void SwXFieldmark::setFieldType(const OUString & fieldType)
         throw uno::RuntimeException();
     if(fieldType != getFieldType())
     {
-        if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX)
+        if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX || fieldType == ODF_FORMDATE)
         {
             ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeNonTextFieldmarkType(pBkm, fieldType);
             if (pNewFieldmark)
@@ -670,6 +670,8 @@ SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, ::sw::mark::IMark *const pMark,
             pXBkmk = new SwXFieldmark(true, &rDoc);
         else if (dynamic_cast< ::sw::mark::DropDownFieldmark* >(pMark))
             pXBkmk = new SwXFieldmark(true, &rDoc);
+        else if (dynamic_cast< ::sw::mark::DateFieldmark* >(pMark))
+            pXBkmk = new SwXFieldmark(true, &rDoc);
         else
             pXBkmk = new SwXFieldmark(isReplacementObject, &rDoc);
 


More information about the Libreoffice-commits mailing list