[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - 2 commits - include/vcl sw/inc sw/Library_sw.mk sw/source writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Mar 18 09:16:37 UTC 2019


 include/vcl/window.hxx                            |    2 
 sw/Library_sw.mk                                  |    1 
 sw/inc/IDocumentMarkAccess.hxx                    |    6 
 sw/inc/strings.hrc                                |    3 
 sw/inc/view.hxx                                   |    4 
 sw/source/core/crsr/DropDownFormFieldButton.cxx   |  255 ++++++++++++++++++++++
 sw/source/core/crsr/bookmrk.cxx                   |   74 ++++++
 sw/source/core/crsr/crsrsh.cxx                    |    2 
 sw/source/core/doc/docbm.cxx                      |  107 ++++++++-
 sw/source/core/inc/DropDownFormFieldButton.hxx    |   54 ++++
 sw/source/core/inc/MarkManager.hxx                |   11 
 sw/source/core/inc/bookmrk.hxx                    |   26 ++
 sw/source/core/inc/unobookmark.hxx                |    2 
 sw/source/core/text/itrform2.cxx                  |    6 
 sw/source/core/text/porfld.cxx                    |   16 +
 sw/source/core/text/porfld.hxx                    |    8 
 sw/source/core/unocore/unobkm.cxx                 |   23 +
 sw/source/uibase/docvw/edtwin.cxx                 |    6 
 sw/source/uibase/shells/textsh1.cxx               |   13 -
 sw/source/uibase/uiview/view.cxx                  |    3 
 sw/source/uibase/uiview/viewling.cxx              |  110 ---------
 writerfilter/source/dmapper/FormControlHelper.cxx |   17 +
 22 files changed, 610 insertions(+), 139 deletions(-)

New commits:
commit 7dd9f08ee6fa9b93bfab244ada9ee10cb3465b25
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Mar 13 15:40:35 2019 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Mar 18 10:16:26 2019 +0100

    MSForms: Add a drop-down button for drop-down form field
    
    * Introduce a editing frame with a button for drop-down form field.
    ** The frame is mouse transparent.
    ** Pushing the button opens the popup window with the items of the field.
    * The button is visible when the cursor is inside the field.
    
    Reviewed-on: https://gerrit.libreoffice.org/68961
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    (cherry picked from commit 10be5b6ce972dff517f3ceed41cab04d3e051f57)
    
    Change-Id: I5c7db138d14380899fee046c95a5afe14cfea213
    Reviewed-on: https://gerrit.libreoffice.org/69195
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 6dc4ee3d8613..c678296d084c 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -624,7 +624,7 @@ protected:
 
     SAL_DLLPRIVATE void                 ImplInvalidate( const vcl::Region* rRegion, InvalidateFlags nFlags );
 
-    SAL_DLLPRIVATE WindowHitTest        ImplHitTest( const Point& rFramePos );
+    virtual WindowHitTest               ImplHitTest( const Point& rFramePos );
 
     SAL_DLLPRIVATE void                 ImplSetMouseTransparent( bool bTransparent );
 
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 7483038d8ad5..492ccaf7c8a1 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -149,6 +149,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/crsr/crsrsh \
     sw/source/core/crsr/crstrvl \
     sw/source/core/crsr/crstrvl1 \
+    sw/source/core/crsr/DropDownFormFieldButton \
     sw/source/core/crsr/findattr \
     sw/source/core/crsr/findcoll \
     sw/source/core/crsr/findfmt \
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index cbd523c012b1..d7111112612f 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -27,6 +27,7 @@
 class SwPaM;
 struct SwPosition;
 class SwTextNode;
+class SwCursorShell;
 
 namespace sw { namespace mark {
     class SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
@@ -258,6 +259,9 @@ class IDocumentMarkAccess
         virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
         virtual ::sw::mark::IFieldmark* changeNonTextFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0;
 
+        virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) = 0;
+        virtual void ClearFieldActivation() = 0;
+
         // Annotation Marks
         virtual const_iterator_t getAnnotationMarksBegin() const = 0;
         virtual const_iterator_t getAnnotationMarksEnd() const = 0;
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index e0edcb4ab7c0..8c1cc47a85e8 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1325,6 +1325,9 @@
 #define STR_MENU_UP                             NC_("STR_MENU_UP", "~Upwards")
 #define STR_MENU_DOWN                           NC_("STR_MENU_DOWN", "Do~wnwards")
 
+
+#define STR_DROP_DOWN_EMPTY_LIST                NC_("STR_DROP_DOWN_EMPTY_LIST", "No Item specified")
+
 /*--------------------------------------------------------------------
     Description: Classification strings
  --------------------------------------------------------------------*/
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index 82a736801d61..1b29bb63203d 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -210,7 +210,6 @@ class SW_DLLPUBLIC SwView: public SfxViewShell
     SwPostItMgr         *m_pPostItMgr;
 
     SelectionType       m_nSelectionType;
-    VclPtr<FloatingWindow> m_pFieldPopup;
     sal_uInt16          m_nPageCnt;
 
     // current draw mode
@@ -267,8 +266,6 @@ class SW_DLLPUBLIC SwView: public SfxViewShell
 
     DECL_DLLPRIVATE_LINK( TimeoutHdl, Timer*, void );
 
-    DECL_DLLPRIVATE_LINK( FieldPopupModeEndHdl, FloatingWindow*, void );
-
     inline long                  GetXScroll() const;
     inline long                  GetYScroll() const;
     SAL_DLLPRIVATE Point         AlignToPixel(const Point& rPt) const;
@@ -425,7 +422,6 @@ public:
 
     void            SpellError(LanguageType eLang);
     bool            ExecSpellPopup( const Point& rPt );
-    void                ExecFieldPopup( const Point& rPt, sw::mark::IFieldmark *fieldBM );
     void            ExecSmartTagPopup( const Point& rPt );
 
     DECL_LINK( OnlineSpellCallback, SpellCallbackInfo&, void );
diff --git a/sw/source/core/crsr/DropDownFormFieldButton.cxx b/sw/source/core/crsr/DropDownFormFieldButton.cxx
new file mode 100644
index 000000000000..5eb46e080bc0
--- /dev/null
+++ b/sw/source/core/crsr/DropDownFormFieldButton.cxx
@@ -0,0 +1,255 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include <DropDownFormFieldButton.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+#include <edtwin.hxx>
+#include <basegfx/color/bcolortools.hxx>
+#include <viewopt.hxx>
+#include <bookmrk.hxx>
+#include <vcl/floatwin.hxx>
+#include <vcl/event.hxx>
+#include <vcl/lstbox.hxx>
+#include <xmloff/odffields.hxx>
+#include <IMark.hxx>
+#include <view.hxx>
+#include <docsh.hxx>
+#include <strings.hrc>
+
+/**
+ * Popup dialog for drop-down form field showing the list items of the field.
+ * The user can select the item using this popup while filling in a form.
+ */
+class SwFieldDialog : public FloatingWindow
+{
+private:
+    VclPtr<ListBox> aListBox;
+    sw::mark::IFieldmark* pFieldmark;
+
+    DECL_LINK(MyListBoxHandler, ListBox&, void);
+
+public:
+    SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth);
+    virtual ~SwFieldDialog() override;
+    virtual void dispose() override;
+};
+
+SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth)
+    : FloatingWindow(parent, WB_BORDER | WB_SYSTEMWINDOW)
+    , aListBox(VclPtr<ListBox>::Create(this))
+    , pFieldmark(fieldBM)
+{
+    if (fieldBM != nullptr)
+    {
+        const sw::mark::IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
+
+        OUString sListKey = ODF_FORMDROPDOWN_LISTENTRY;
+        sw::mark::IFieldmark::parameter_map_t::const_iterator pListEntries
+            = pParameters->find(sListKey);
+        if (pListEntries != pParameters->end())
+        {
+            css::uno::Sequence<OUString> vListEntries;
+            pListEntries->second >>= vListEntries;
+            for (OUString const& i : vListEntries)
+                aListBox->InsertEntry(i);
+        }
+        else
+        {
+            aListBox->InsertEntry(SwResId(STR_DROP_DOWN_EMPTY_LIST));
+        }
+
+        // Select the current one
+        OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
+        sw::mark::IFieldmark::parameter_map_t::const_iterator pResult
+            = pParameters->find(sResultKey);
+        if (pResult != pParameters->end())
+        {
+            sal_Int32 nSelection = -1;
+            pResult->second >>= nSelection;
+            aListBox->SelectEntryPos(nSelection);
+        }
+    }
+
+    Size lbSize(aListBox->GetOptimalSize());
+    lbSize.AdjustWidth(50);
+    lbSize.AdjustHeight(20);
+    lbSize.setWidth(std::max(lbSize.Width(), nMinListWidth));
+    aListBox->SetSizePixel(lbSize);
+    aListBox->SetSelectHdl(LINK(this, SwFieldDialog, MyListBoxHandler));
+    aListBox->Show();
+
+    SetSizePixel(lbSize);
+}
+
+SwFieldDialog::~SwFieldDialog() { disposeOnce(); }
+
+void SwFieldDialog::dispose()
+{
+    aListBox.disposeAndClear();
+    FloatingWindow::dispose();
+}
+
+IMPL_LINK(SwFieldDialog, MyListBoxHandler, ListBox&, rBox, void)
+{
+    if (!rBox.IsTravelSelect())
+    {
+        OUString sSelection = rBox.GetSelectedEntry();
+        if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
+        {
+            EndPopupMode();
+            return;
+        }
+
+        sal_Int32 nSelection = rBox.GetSelectedEntryPos();
+        if (nSelection >= 0)
+        {
+            OUString sKey = ODF_FORMDROPDOWN_RESULT;
+            (*pFieldmark->GetParameters())[sKey] <<= nSelection;
+            pFieldmark->Invalidate();
+            SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
+            rView.GetDocShell()->SetModified();
+        }
+
+        EndPopupMode();
+    }
+}
+
+DropDownFormFieldButton::DropDownFormFieldButton(SwEditWin* pEditWin,
+                                                 sw::mark::DropDownFieldmark& rFieldmark)
+    : MenuButton(pEditWin, WB_DIALOGCONTROL)
+    , m_rFieldmark(rFieldmark)
+{
+    assert(GetParent());
+    assert(dynamic_cast<SwEditWin*>(GetParent()));
+}
+
+DropDownFormFieldButton::~DropDownFormFieldButton() { disposeOnce(); }
+
+void DropDownFormFieldButton::dispose()
+{
+    m_pFieldPopup.disposeAndClear();
+    MenuButton::dispose();
+}
+
+void DropDownFormFieldButton::CalcPosAndSize(const SwRect& rPortionPaintArea)
+{
+    assert(GetParent());
+
+    Point aBoxPos = GetParent()->LogicToPixel(rPortionPaintArea.Pos());
+    Size aBoxSize = GetParent()->LogicToPixel(rPortionPaintArea.SSize());
+
+    // First calculate the size of the frame around the field
+    int nPadding = aBoxSize.Height() / 4;
+    aBoxPos.MoveX(-nPadding);
+    aBoxPos.MoveY(-nPadding);
+    aBoxSize.AdjustWidth(2 * nPadding);
+    aBoxSize.AdjustHeight(2 * nPadding);
+
+    m_aFieldFramePixel = tools::Rectangle(aBoxPos, aBoxSize);
+
+    // Then extend the size with the button area
+    aBoxSize.AdjustWidth(GetParent()->LogicToPixel(rPortionPaintArea.SSize()).Height());
+
+    SetPosSizePixel(aBoxPos, aBoxSize);
+}
+
+void DropDownFormFieldButton::MouseButtonUp(const MouseEvent&)
+{
+    assert(GetParent());
+
+    Point aPixPos = GetPosPixel();
+    aPixPos.MoveY(GetSizePixel().Height());
+
+    m_pFieldPopup = VclPtr<SwFieldDialog>::Create(static_cast<SwEditWin*>(GetParent()),
+                                                  &m_rFieldmark, GetSizePixel().Width());
+    m_pFieldPopup->SetPopupModeEndHdl(LINK(this, DropDownFormFieldButton, FieldPopupModeEndHdl));
+
+    tools::Rectangle aRect(GetParent()->OutputToScreenPixel(aPixPos), Size(0, 0));
+    m_pFieldPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
+    Invalidate();
+}
+
+IMPL_LINK_NOARG(DropDownFormFieldButton, FieldPopupModeEndHdl, FloatingWindow*, void)
+{
+    m_pFieldPopup.disposeAndClear();
+    m_rFieldmark.Invalidate();
+    // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
+    Show(false);
+    Invalidate();
+}
+
+static basegfx::BColor lcl_GetFillColor(const basegfx::BColor& rLineColor, double aLuminance)
+{
+    basegfx::BColor aHslLine = basegfx::utils::rgb2hsl(rLineColor);
+    aHslLine.setZ(aLuminance);
+    return basegfx::utils::hsl2rgb(aHslLine);
+}
+
+void DropDownFormFieldButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
+{
+    SetMapMode(MapMode(MapUnit::MapPixel));
+
+    //const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+    Color aLineColor = COL_BLACK;
+    Color aFillColor
+        = Color(lcl_GetFillColor(aLineColor.getBColor(), (m_pFieldPopup ? 0.5 : 0.75)));
+
+    // Draw the frame around the field
+    // GTK3 backend cuts down the frame's top and left border, to avoid that add a padding around the frame
+    int nPadding = 1;
+    Point aPos(nPadding, nPadding);
+    Size aSize(m_aFieldFramePixel.GetSize().Width() - nPadding,
+               m_aFieldFramePixel.GetSize().Height() - 2 * nPadding);
+    const tools::Rectangle aFrameRect(tools::Rectangle(aPos, aSize));
+    rRenderContext.SetLineColor(aLineColor);
+    rRenderContext.SetFillColor(COL_TRANSPARENT);
+    rRenderContext.DrawRect(aFrameRect);
+
+    // Draw the button next to the frame
+    Point aButtonPos(aFrameRect.TopLeft());
+    aButtonPos.MoveX(aFrameRect.GetSize().getWidth() - 1);
+    Size aButtonSize(aFrameRect.GetSize());
+    aButtonSize.setWidth(GetSizePixel().getWidth() - aFrameRect.getWidth() - nPadding);
+    const tools::Rectangle aButtonRect(tools::Rectangle(aButtonPos, aButtonSize));
+
+    // Background & border
+    rRenderContext.SetLineColor(aLineColor);
+    rRenderContext.SetFillColor(aFillColor);
+    rRenderContext.DrawRect(aButtonRect);
+
+    // the arrowhead
+    rRenderContext.SetLineColor(aLineColor);
+    rRenderContext.SetFillColor(aLineColor);
+
+    Point aCenter(aButtonPos.X() + (aButtonSize.Width() / 2),
+                  aButtonPos.Y() + (aButtonSize.Height() / 2));
+    Size aArrowSize(aButtonSize.Width() / 4, aButtonSize.Height() / 10);
+
+    tools::Polygon aPoly(3);
+    aPoly.SetPoint(Point(aCenter.X() - aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 0);
+    aPoly.SetPoint(Point(aCenter.X() + aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 1);
+    aPoly.SetPoint(Point(aCenter.X(), aCenter.Y() + aArrowSize.Height()), 2);
+    rRenderContext.DrawPolygon(aPoly);
+}
+
+WindowHitTest DropDownFormFieldButton::ImplHitTest(const Point& rFramePos)
+{
+    // We need to check whether the position hits the button (the frame should be mouse transparent)
+    WindowHitTest aResult = MenuButton::ImplHitTest(rFramePos);
+    if (aResult != WindowHitTest::Inside)
+        return aResult;
+    else
+    {
+        return rFramePos.X() >= m_aFieldFramePixel.Right() ? WindowHitTest::Inside
+                                                           : WindowHitTest::Transparent;
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index c80fb490aa1b..1b29071f38d5 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -36,6 +36,7 @@
 #include <libxml/xmlwriter.h>
 #include <comphelper/random.hxx>
 #include <comphelper/anytostring.hxx>
+#include <edtwin.hxx>
 
 using namespace ::sw::mark;
 using namespace ::com::sun::star;
@@ -481,11 +482,13 @@ namespace sw { namespace mark
 
     DropDownFieldmark::DropDownFieldmark(const SwPaM& rPaM)
         : Fieldmark(rPaM)
+        , m_pButton(nullptr)
     {
     }
 
     DropDownFieldmark::~DropDownFieldmark()
     {
+        m_pButton.disposeAndClear();
     }
 
     void DropDownFieldmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const eMode)
@@ -511,6 +514,44 @@ namespace sw { namespace mark
         lcl_RemoveFieldMarks(this, pDoc,
                 CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT);
     }
+
+    void DropDownFieldmark::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 DropDownFieldmark::ShowButton(SwEditWin* pEditWin)
+    {
+        if(pEditWin)
+        {
+            if(!m_pButton)
+                m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
+            m_pButton->CalcPosAndSize(m_aPortionPaintArea);
+            m_pButton->Show();
+        }
+    }
+
+    void DropDownFieldmark::HideButton()
+    {
+        if(m_pButton)
+            m_pButton->Show(false);
+    }
+
+    void DropDownFieldmark::RemoveButton()
+    {
+        if(m_pButton)
+            m_pButton.disposeAndClear();
+    }
 }}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 7f7e17a8a65a..2e607d313931 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1876,6 +1876,8 @@ void SwCursorShell::UpdateCursor( sal_uInt16 eFlags, bool bIdleEnd )
 
     if( m_bSVCursorVis )
         m_pVisibleCursor->Show(); // show again
+
+    getIDocumentMarkAccess()->NotifyCursorUpdate(*this);
 }
 
 void SwCursorShell::RefreshBlockCursor()
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 727655250a2e..a7ee56eafca9 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -54,6 +54,7 @@
 #include <viscrs.hxx>
 #include <edimp.hxx>
 #include <tools/datetimeutils.hxx>
+#include <view.hxx>
 
 using namespace ::sw::mark;
 
@@ -372,6 +373,7 @@ namespace sw { namespace mark
         , m_vFieldmarks()
         , m_vAnnotationMarks()
         , m_pDoc(&rDoc)
+        , m_pLastActiveFieldmark(nullptr)
     { }
 
     ::sw::mark::IMark* MarkManager::makeMark(const SwPaM& rPaM,
@@ -961,6 +963,9 @@ namespace sw { namespace mark
                     IDocumentMarkAccess::iterator_t ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark);
                     if ( ppFieldmark != m_vFieldmarks.end() )
                     {
+                        if(m_pLastActiveFieldmark == ppFieldmark->get())
+                            ClearFieldActivation();
+
                         m_vFieldmarks.erase(ppFieldmark);
                         ret.reset(new LazyFieldmarkDeleter(*ppMark, m_pDoc));
                     }
@@ -1037,6 +1042,7 @@ namespace sw { namespace mark
 
     void MarkManager::clearAllMarks()
     {
+        ClearFieldActivation();
         m_vFieldmarks.clear();
         m_vBookmarks.clear();
         m_aMarkNamesSet.clear();
@@ -1124,10 +1130,61 @@ namespace sw { namespace mark
         SwPaM aPaM(pFieldmark->GetMarkPos());
 
         // Remove the old fieldmark and create a new one with the new type
-        deleteFieldmarkAt(*aPaM.GetPoint());
-        return makeNoTextFieldBookmark(aPaM, sName, rNewType);
+        if(aPaM.GetPoint()->nContent > 0)
+        {
+            --aPaM.GetPoint()->nContent;
+            SwPosition aNewPos (aPaM.GetPoint()->nNode, aPaM.GetPoint()->nContent);
+            deleteFieldmarkAt(aNewPos);
+            return makeNoTextFieldBookmark(aPaM, sName, rNewType);
+        }
+        return nullptr;
+    }
+
+    void MarkManager::NotifyCursorUpdate(const SwCursorShell& rCursorShell)
+    {
+        SwView* pSwView = dynamic_cast<SwView *>(rCursorShell.GetSfxViewShell());
+        if(!pSwView)
+            return;
+
+        SwEditWin& rEditWin = pSwView->GetEditWin();
+        SwPosition aPos(*rCursorShell.GetCursor()->GetPoint());
+        IFieldmark* pFieldBM = getFieldmarkFor(aPos);
+        DropDownFieldmark* pNewActiveFieldmark = nullptr;
+        if ((!pFieldBM || pFieldBM->GetFieldname() != ODF_FORMDROPDOWN)
+            && aPos.nContent.GetIndex() > 0 )
+        {
+            --aPos.nContent;
+            pFieldBM = getFieldmarkFor(aPos);
+        }
+
+        if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN )
+        {
+            if (m_pLastActiveFieldmark != pFieldBM)
+            {
+                DropDownFieldmark* pDropDownFm = dynamic_cast<DropDownFieldmark*>(pFieldBM);
+                pDropDownFm->ShowButton(&rEditWin);
+                pNewActiveFieldmark = pDropDownFm;
+            }
+            else
+            {
+                pNewActiveFieldmark = m_pLastActiveFieldmark;
+            }
+        }
+
+        if(pNewActiveFieldmark != m_pLastActiveFieldmark)
+        {
+            ClearFieldActivation();
+            m_pLastActiveFieldmark = pNewActiveFieldmark;
+        }
     }
 
+    void MarkManager::ClearFieldActivation()
+    {
+        if(m_pLastActiveFieldmark)
+            m_pLastActiveFieldmark->RemoveButton();
+
+        m_pLastActiveFieldmark = nullptr;
+    }
 
     IFieldmark* MarkManager::getDropDownFor(const SwPosition& rPos) const
     {
diff --git a/sw/source/core/inc/DropDownFormFieldButton.hxx b/sw/source/core/inc/DropDownFormFieldButton.hxx
new file mode 100644
index 000000000000..1013ef177580
--- /dev/null
+++ b/sw/source/core/inc/DropDownFormFieldButton.hxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#ifndef INCLUDED_SW_SOURCE_CORE_TEXT_DROPDOWNFORMEFIELDBUTTO_HXX
+#define INCLUDED_SW_SOURCE_CORE_TEXT_DROPDOWNFORMEFIELDBUTTO_HXX
+
+#include <vcl/menubtn.hxx>
+#include <swrect.hxx>
+
+class SwFieldFormDropDownPortion;
+class SwEditWin;
+class FloatingWindow;
+namespace sw
+{
+namespace mark
+{
+class DropDownFieldmark;
+}
+} // namespace sw
+
+/**
+ * This button is shown when the cursor is in a drop-down form field.
+ * The user can select an item of the field using this button while filling in a form.
+ */
+class DropDownFormFieldButton : public MenuButton
+{
+public:
+    DropDownFormFieldButton(SwEditWin* pEditWin, sw::mark::DropDownFieldmark& rFieldMark);
+    virtual ~DropDownFormFieldButton() override;
+    virtual void dispose() override;
+
+    void CalcPosAndSize(const SwRect& rPortionPaintArea);
+
+    virtual void MouseButtonUp(const MouseEvent& rMEvt) override;
+    DECL_LINK(FieldPopupModeEndHdl, FloatingWindow*, void);
+
+    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
+    virtual WindowHitTest ImplHitTest(const Point& rFramePos) override;
+
+private:
+    tools::Rectangle m_aFieldFramePixel;
+    sw::mark::DropDownFieldmark& m_rFieldmark;
+    VclPtr<FloatingWindow> m_pFieldPopup;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 4544bae57b85..6ca604a29976 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -24,11 +24,16 @@
 #include <IDocumentMarkAccess.hxx>
 #include <unordered_set>
 #include <unordered_map>
+#include <memory>
+
+class SwCursorShell;
 
 namespace sw {
     namespace mark {
     typedef std::unordered_map<OUString, sal_Int32> MarkBasenameMapUniqueOffset_t;
 
+    class DropDownFieldmark;
+
     class MarkManager
         : virtual public IDocumentMarkAccess
     {
@@ -88,6 +93,9 @@ namespace sw {
             virtual void deleteFieldmarkAt(const SwPosition& rPos) override;
             virtual ::sw::mark::IFieldmark* changeNonTextFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) override;
 
+            virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) override;
+            virtual void ClearFieldActivation() override;
+
             void dumpAsXml(struct _xmlTextWriter* pWriter) const;
 
             // Annotation Marks
@@ -126,6 +134,8 @@ namespace sw {
             container_t m_vAnnotationMarks;
 
             SwDoc * const m_pDoc;
+
+            sw::mark::DropDownFieldmark* m_pLastActiveFieldmark;
     };
     } // namespace mark
 }
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 59089c846d43..c1deca2ea810 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -28,6 +28,8 @@
 #include <rtl/ustring.hxx>
 #include <IMark.hxx>
 #include <swserv.hxx>
+#include <swrect.hxx>
+#include "DropDownFormFieldButton.hxx"
 
 namespace com {
     namespace sun {
@@ -41,6 +43,7 @@ namespace com {
 
 struct SwPosition;  // fwd Decl. wg. UI
 class SwDoc;
+class SwEditWin;
 
 namespace sw {
     namespace mark {
@@ -256,6 +259,17 @@ namespace sw {
             virtual ~DropDownFieldmark() override;
             virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override;
             virtual void ReleaseDoc(SwDoc* const pDoc) 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<DropDownFormFieldButton> m_pButton;
         };
     }
 }
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index d0ddd033aef7..0fd7f0bb4c76 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -906,7 +906,7 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const
                     }
                     else if (pBM->GetFieldname( ) == ODF_FORMDROPDOWN)
                     {
-                        pPor = new SwFieldFormDropDownPortion(sw::mark::ExpandFieldmark(pBM));
+                        pPor = new SwFieldFormDropDownPortion(pBM, sw::mark::ExpandFieldmark(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 777165819b55..de30d4e9cfc3 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -42,6 +42,7 @@
 #include <accessibilityoptions.hxx>
 #include <editeng/lrspitem.hxx>
 #include <unicode/ubidi.h>
+#include <bookmrk.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1315,7 +1316,20 @@ sal_uInt16 SwCombinedPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
 
 SwFieldPortion *SwFieldFormDropDownPortion::Clone(const OUString &rExpand) const
 {
-    return new SwFieldFormDropDownPortion(rExpand);
+    return new SwFieldFormDropDownPortion(m_pFieldMark, rExpand);
+}
+
+void SwFieldFormDropDownPortion::Paint( const SwTextPaintInfo &rInf ) const
+{
+    SwFieldPortion::Paint( rInf );
+
+    ::sw::mark::DropDownFieldmark* pDropDownField = dynamic_cast< ::sw::mark::DropDownFieldmark* >(m_pFieldMark);
+    if(pDropDownField)
+    {
+        SwRect aPaintArea;
+        rInf.CalcRect( *this, &aPaintArea );
+        pDropDownField->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 38fc08993c0d..a18f1343451b 100644
--- a/sw/source/core/text/porfld.hxx
+++ b/sw/source/core/text/porfld.hxx
@@ -226,12 +226,18 @@ namespace sw { namespace mark {
 class SwFieldFormDropDownPortion : public SwFieldPortion
 {
 public:
-    explicit SwFieldFormDropDownPortion(const OUString &rExpand)
+    explicit SwFieldFormDropDownPortion(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
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 29177bfaebff..3a93172afe41 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -4673,12 +4673,6 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
                                         rCheckboxFm.SetChecked(!rCheckboxFm.IsChecked());
                                         rCheckboxFm.Invalidate();
                                         rSh.InvalidateWindows( m_rView.GetVisArea() );
-                                    } else if ( fieldBM->GetFieldname() == ODF_FORMDROPDOWN ) {
-                                        m_rView.ExecFieldPopup( aDocPt, fieldBM );
-                                        fieldBM->Invalidate();
-                                        rSh.InvalidateWindows( m_rView.GetVisArea() );
-                                    } else {
-                                        // unknown type..
                                     }
                                 }
                             }
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index a6495ea935de..7c54938843a0 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -120,6 +120,7 @@
 #include <memory>
 #include <xmloff/odffields.hxx>
 #include <swabstdlg.hxx>
+#include <bookmrk.hxx>
 
 using namespace ::com::sun::star;
 using namespace com::sun::star::beans;
@@ -1401,10 +1402,14 @@ void SwTextShell::Execute(SfxRequest &rReq)
         {
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDropDownFormFieldDialog(pFieldBM));
-            pDlg->Execute();
-            pFieldBM->Invalidate();
-            rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() );
-            rWrtSh.UpdateCursor(); // cursor position might be invalid
+            if (pDlg->Execute() == RET_OK)
+            {
+                pFieldBM->Invalidate();
+                rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() );
+                rWrtSh.UpdateCursor(); // cursor position might be invalid
+                // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
+                dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldBM)->HideButton();
+            }
         }
         else
         {
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 103713df7a07..6ae64dad73ec 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1054,6 +1054,9 @@ SwView::~SwView()
     SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", "");
     SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY");
 
+    // Need to remove activated field's button before disposing EditWin.
+    GetWrtShell().getIDocumentMarkAccess()->ClearFieldActivation();
+
     GetViewFrame()->GetWindow().RemoveChildEventListener( LINK( this, SwView, WindowChildEventListener ) );
     delete m_pPostItMgr;
     m_pPostItMgr = nullptr;
diff --git a/sw/source/uibase/uiview/viewling.cxx b/sw/source/uibase/uiview/viewling.cxx
index a3b719efe928..0e6ad813cfad 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -830,114 +830,4 @@ void SwView::ExecSmartTagPopup( const Point& rPt )
     m_pWrtShell->LockView( bOldViewLock );
 }
 
-class SwFieldDialog : public FloatingWindow
-{
-private:
-    VclPtr<ListBox> aListBox;
-    IFieldmark *pFieldmark;
-
-    DECL_LINK( MyListBoxHandler, ListBox&, void );
-
-public:
-    SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM );
-    virtual ~SwFieldDialog() override;
-    virtual void dispose() override;
-};
-
-SwFieldDialog::SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM ) :
-    FloatingWindow( parent, WB_BORDER | WB_SYSTEMWINDOW ),
-    aListBox(VclPtr<ListBox>::Create(this)),
-    pFieldmark( fieldBM )
-{
-    if ( fieldBM != nullptr )
-    {
-        const IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
-
-        OUString sListKey = ODF_FORMDROPDOWN_LISTENTRY;
-        IFieldmark::parameter_map_t::const_iterator pListEntries = pParameters->find( sListKey );
-        if(pListEntries != pParameters->end())
-        {
-            Sequence< OUString > vListEntries;
-            pListEntries->second >>= vListEntries;
-            for( OUString const & i : vListEntries)
-                aListBox->InsertEntry(i);
-        }
-
-        // Select the current one
-        OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
-        IFieldmark::parameter_map_t::const_iterator pResult = pParameters->find( sResultKey );
-        if ( pResult != pParameters->end() )
-        {
-            sal_Int32 nSelection = -1;
-            pResult->second >>= nSelection;
-            aListBox->SelectEntryPos( nSelection );
-        }
-    }
-
-    Size lbSize(aListBox->GetOptimalSize());
-    lbSize.Width()+=50;
-    lbSize.Height()+=20;
-    aListBox->SetSizePixel(lbSize);
-    aListBox->SetSelectHdl( LINK( this, SwFieldDialog, MyListBoxHandler ) );
-    aListBox->Show();
-
-    SetSizePixel( lbSize );
-}
-
-SwFieldDialog::~SwFieldDialog()
-{
-    disposeOnce();
-}
-
-void SwFieldDialog::dispose()
-{
-    aListBox.disposeAndClear();
-    FloatingWindow::dispose();
-}
-
-IMPL_LINK( SwFieldDialog, MyListBoxHandler, ListBox&, rBox, void )
-{
-    if ( !rBox.IsTravelSelect() )
-    {
-        sal_Int32 selection = rBox.GetSelectedEntryPos();
-        if ( selection >= 0 )
-        {
-            OUString sKey = ODF_FORMDROPDOWN_RESULT;
-            (*pFieldmark->GetParameters())[ sKey ] <<= selection;
-            pFieldmark->Invalidate();
-            SwView& rView = static_cast<SwEditWin*>( GetParent() )->GetView();
-            rView.GetDocShell()->SetModified();
-        }
-
-        EndPopupMode();
-    }
-}
-
-IMPL_LINK_NOARG(SwView, FieldPopupModeEndHdl, FloatingWindow*, void)
-{
-    m_pFieldPopup.disposeAndClear();
-}
-
-void SwView::ExecFieldPopup( const Point& rPt, IFieldmark *fieldBM )
-{
-    // Don't show popup if there is no list item
-    auto pListEntries = fieldBM->GetParameters()->find( ODF_FORMDROPDOWN_LISTENTRY );
-    Sequence< OUString > vListEntries;
-    if(pListEntries != fieldBM->GetParameters()->end())
-    {
-        pListEntries->second >>= vListEntries;
-    }
-
-    if(vListEntries.getLength() == 0)
-        return;
-
-    const Point aPixPos = GetEditWin().LogicToPixel( rPt );
-
-    m_pFieldPopup = VclPtr<SwFieldDialog>::Create( m_pEditWin, fieldBM );
-    m_pFieldPopup->SetPopupModeEndHdl( LINK( this, SwView, FieldPopupModeEndHdl ) );
-
-    tools::Rectangle aRect( m_pEditWin->OutputToScreenPixel( aPixPos ), Size( 0, 0 ) );
-    m_pFieldPopup->StartPopupMode( aRect, FloatWinPopupFlags::Down|FloatWinPopupFlags::GrabFocus );
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit fbb148af3f175ad21bc5bea61a611c52e83f9eed
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sat Mar 9 14:44:50 2019 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Mar 18 10:16:12 2019 +0100

    MSForms: Introduce a new IFieldMark for drop-down form field
    
    * It was weird anyway that a drop-down form field was represented
    as an CheckboxFieldmark.
    * It will be useful for later commits, to have a separate field type
    for drop-down field.
    * Needed to fix-up the API a bit because it was designed to specify
    the field type after initialization. I solved it in a way to not break
    the API behavior. Hopefully it's not very slow.
    
    Reviewed-on: https://gerrit.libreoffice.org/68960
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    (cherry picked from commit f66a83c95c21b4311918a64bb85016857b49f4d4)
    
    Change-Id: I3103e6b1c36289b27b62ab9ca7dfeebc14901c8a
    Reviewed-on: https://gerrit.libreoffice.org/69194
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 823326e2b8ac..cbd523c012b1 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -47,6 +47,7 @@ class IDocumentMarkAccess
             ANNOTATIONMARK,
             TEXT_FIELDMARK,
             CHECKBOX_FIELDMARK,
+            DROPDOWN_FIELDMARK,
             NAVIGATOR_REMINDER
         };
 
@@ -255,6 +256,7 @@ class IDocumentMarkAccess
         virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const=0;
 
         virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
+        virtual ::sw::mark::IFieldmark* changeNonTextFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0;
 
         // Annotation Marks
         virtual const_iterator_t getAnnotationMarksBegin() const = 0;
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 630bfe9c11d1..c80fb490aa1b 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -478,6 +478,39 @@ namespace sw { namespace mark
             pResult->second >>= bResult;
         return bResult;
     }
+
+    DropDownFieldmark::DropDownFieldmark(const SwPaM& rPaM)
+        : Fieldmark(rPaM)
+    {
+    }
+
+    DropDownFieldmark::~DropDownFieldmark()
+    {
+    }
+
+    void DropDownFieldmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const eMode)
+    {
+        if (eMode == sw::mark::InsertMode::New)
+        {
+            lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT);
+
+            // For some reason the end mark is moved from 1 by the Insert:
+            // we don't want this for checkboxes
+            SwPosition aNewEndPos = GetMarkEnd();
+            aNewEndPos.nContent--;
+            SetMarkEndPos( aNewEndPos );
+        }
+        else
+        {
+            lcl_AssertFieldMarksSet(this, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT);
+        }
+    }
+
+    void DropDownFieldmark::ReleaseDoc(SwDoc* const pDoc)
+    {
+        lcl_RemoveFieldMarks(this, pDoc,
+                CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT);
+    }
 }}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index ccc3d5382ffb..727655250a2e 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -338,6 +338,8 @@ IDocumentMarkAccess::MarkType IDocumentMarkAccess::GetType(const IMark& rBkmk)
         return MarkType::TEXT_FIELDMARK;
     else if(*pMarkTypeInfo == typeid(CheckboxFieldmark))
         return MarkType::CHECKBOX_FIELDMARK;
+    else if(*pMarkTypeInfo == typeid(DropDownFieldmark))
+        return MarkType::DROPDOWN_FIELDMARK;
     else if(*pMarkTypeInfo == typeid(NavigatorReminder))
         return MarkType::NAVIGATOR_REMINDER;
     else
@@ -414,6 +416,9 @@ namespace sw { namespace mark
             case IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK:
                 pMark = std::shared_ptr<IMark>(new CheckboxFieldmark(rPaM));
                 break;
+            case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
+                pMark = std::shared_ptr<IMark>(new DropDownFieldmark(rPaM));
+                break;
             case IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER:
                 pMark = std::shared_ptr<IMark>(new NavigatorReminder(rPaM));
                 break;
@@ -463,6 +468,7 @@ namespace sw { namespace mark
                 break;
             case IDocumentMarkAccess::MarkType::TEXT_FIELDMARK:
             case IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK:
+            case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
                 lcl_InsertMarkSorted(m_vFieldmarks, pMark);
                 break;
             case IDocumentMarkAccess::MarkType::ANNOTATIONMARK:
@@ -524,9 +530,20 @@ namespace sw { namespace mark
         bool bEnableSetModified = m_pDoc->getIDocumentState().IsEnableSetModified();
         m_pDoc->getIDocumentState().SetEnableSetModified(false);
 
-        sw::mark::IMark* pMark = makeMark( rPaM, rName,
-                IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK,
-                sw::mark::InsertMode::New);
+        sw::mark::IMark* pMark = nullptr;
+        if(rType == ODF_FORMCHECKBOX)
+        {
+            pMark = makeMark( rPaM, rName,
+                    IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK,
+                    sw::mark::InsertMode::New);
+        }
+        else if(rType == ODF_FORMDROPDOWN)
+        {
+            pMark = makeMark( rPaM, rName,
+                    IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK,
+                    sw::mark::InsertMode::New);
+        }
+
         sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
         if (pFieldMark)
             pFieldMark->SetFieldname( rType );
@@ -939,6 +956,7 @@ namespace sw { namespace mark
 
             case IDocumentMarkAccess::MarkType::TEXT_FIELDMARK:
             case IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK:
+            case IDocumentMarkAccess::MarkType::DROPDOWN_FIELDMARK:
                 {
                     IDocumentMarkAccess::iterator_t ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark);
                     if ( ppFieldmark != m_vFieldmarks.end() )
@@ -1084,6 +1102,32 @@ namespace sw { namespace mark
         deleteMark(lcl_FindMark(m_vAllMarks, *pFieldmark));
     }
 
+    ::sw::mark::IFieldmark* MarkManager::changeNonTextFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType)
+    {
+        bool bActualChange = false;
+        if(rNewType == ODF_FORMDROPDOWN)
+        {
+            if (dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark))
+                bActualChange = true;
+        }
+        else if(rNewType == ODF_FORMCHECKBOX)
+        {
+            if (dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
+                bActualChange = true;
+        }
+
+        if (!bActualChange)
+            return nullptr;
+
+        // Store attributes needed to create the new fieldmark
+        OUString sName = pFieldmark->GetName();
+        SwPaM aPaM(pFieldmark->GetMarkPos());
+
+        // Remove the old fieldmark and create a new one with the new type
+        deleteFieldmarkAt(*aPaM.GetPoint());
+        return makeNoTextFieldBookmark(aPaM, sName, rNewType);
+    }
+
 
     IFieldmark* MarkManager::getDropDownFor(const SwPosition& rPos) const
     {
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 7a3612bb6131..4544bae57b85 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -86,6 +86,7 @@ namespace sw {
             virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const override;
 
             virtual void deleteFieldmarkAt(const SwPosition& rPos) override;
+            virtual ::sw::mark::IFieldmark* changeNonTextFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) override;
 
             void dumpAsXml(struct _xmlTextWriter* pWriter) const;
 
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 6daa37d1d7e4..59089c846d43 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -234,6 +234,7 @@ namespace sw {
             virtual void ReleaseDoc(SwDoc* const pDoc) override;
         };
 
+        /// Fieldmark representing a checkbox form field.
         class CheckboxFieldmark
             : virtual public ICheckboxFieldmark
             , public Fieldmark
@@ -245,6 +246,17 @@ namespace sw {
             bool IsChecked() const override;
             void SetChecked(bool checked) override;
         };
+
+        /// Fieldmark representing a drop-down form field.
+        class DropDownFieldmark
+            : public Fieldmark
+        {
+        public:
+            DropDownFieldmark(const SwPaM& rPaM);
+            virtual ~DropDownFieldmark() override;
+            virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override;
+            virtual void ReleaseDoc(SwDoc* const pDoc) override;
+        };
     }
 }
 #endif
diff --git a/sw/source/core/inc/unobookmark.hxx b/sw/source/core/inc/unobookmark.hxx
index 7ec058e086bd..569cf8b8d5b3 100644
--- a/sw/source/core/inc/unobookmark.hxx
+++ b/sw/source/core/inc/unobookmark.hxx
@@ -67,6 +67,8 @@ protected:
 
     const ::sw::mark::IMark* GetBookmark() const;
 
+    IDocumentMarkAccess* GetIDocumentMarkAccess();
+
     void registerInMark( SwXBookmark& rXMark, ::sw::mark::IMark* const pMarkBase );
 
     virtual ~SwXBookmark() override;
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 93f4aa72df4b..d0ddd033aef7 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -915,10 +915,6 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const
                     {
                         pPor = new SwFieldMarkPortion();
                     }
-                    else
-                    {
-                        assert( false );        // unknown type...
-                    }
                 }
             }
             if( !pPor )
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index d3212fbbe245..7b2d93467316 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -124,6 +124,11 @@ const ::sw::mark::IMark* SwXBookmark::GetBookmark() const
     return m_pImpl->m_pRegisteredBookmark;
 }
 
+IDocumentMarkAccess* SwXBookmark::GetIDocumentMarkAccess()
+{
+    return m_pImpl->m_pDoc->getIDocumentMarkAccess();
+}
+
 SwXBookmark::SwXBookmark(SwDoc *const pDoc)
     : m_pImpl( new SwXBookmark::Impl(pDoc) )
 {
@@ -551,7 +556,21 @@ void SwXFieldmark::setFieldType(const OUString & fieldType)
         dynamic_cast<const IFieldmark*>(GetBookmark()));
     if(!pBkm)
         throw uno::RuntimeException();
-    pBkm->SetFieldname(fieldType);
+    if(fieldType != getFieldType())
+    {
+        if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX)
+        {
+            ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeNonTextFieldmarkType(pBkm, fieldType);
+            if (pNewFieldmark)
+            {
+                registerInMark(*this, pNewFieldmark);
+                return;
+            }
+        }
+
+        // We did not generate a new fieldmark, so set the type ID
+        pBkm->SetFieldname(fieldType);
+    }
 }
 
 uno::Reference<container::XNameContainer> SwXFieldmark::getParameters()
@@ -585,6 +604,8 @@ SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, ::sw::mark::IMark *const pMark,
             pXBkmk = new SwXFieldmark(false, &rDoc);
         else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(pMark))
             pXBkmk = new SwXFieldmark(true, &rDoc);
+        else if (dynamic_cast< ::sw::mark::DropDownFieldmark* >(pMark))
+            pXBkmk = new SwXFieldmark(true, &rDoc);
         else
             pXBkmk = new SwXFieldmark(isReplacementObject, &rDoc);
 
diff --git a/writerfilter/source/dmapper/FormControlHelper.cxx b/writerfilter/source/dmapper/FormControlHelper.cxx
index 13e64697f6b0..01285831954f 100644
--- a/writerfilter/source/dmapper/FormControlHelper.cxx
+++ b/writerfilter/source/dmapper/FormControlHelper.cxx
@@ -202,6 +202,20 @@ bool FormControlHelper::createCheckbox(uno::Reference<text::XTextRange> const& x
 
 void FormControlHelper::processField(uno::Reference<text::XFormField> const& xFormField)
 {
+    // Set field type first before adding parameters.
+    if (m_pImpl->m_eFieldId == FIELD_FORMTEXT )
+    {
+        xFormField->setFieldType(ODF_FORMTEXT);
+    }
+    else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX )
+    {
+        xFormField->setFieldType(ODF_FORMCHECKBOX);
+    }
+    else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN )
+    {
+        xFormField->setFieldType(ODF_FORMDROPDOWN);
+    }
+
     uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters();
     uno::Reference<container::XNamed> xNamed( xFormField, uno::UNO_QUERY );
     if ( m_pFFData && xNamed.is() && xNameCont.is() )
@@ -209,7 +223,6 @@ void FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
 
         if (m_pImpl->m_eFieldId == FIELD_FORMTEXT )
         {
-            xFormField->setFieldType(ODF_FORMTEXT);
             if (  !m_pFFData->getName().isEmpty() )
             {
                 xNamed->setName( m_pFFData->getName() );
@@ -217,7 +230,6 @@ void FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
         }
         else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX )
         {
-            xFormField->setFieldType(ODF_FORMCHECKBOX);
             uno::Reference<beans::XPropertySet> xPropSet(xFormField, uno::UNO_QUERY);
             uno::Any aAny;
             aAny <<= m_pFFData->getCheckboxChecked();
@@ -226,7 +238,6 @@ void FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
         }
         else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN )
         {
-            xFormField->setFieldType(ODF_FORMDROPDOWN);
             const FFDataHandler::DropDownEntries_t& rEntries = m_pFFData->getDropDownEntries();
             if (!rEntries.empty())
             {


More information about the Libreoffice-commits mailing list