[Libreoffice-commits] core.git: Branch 'feature/msforms' - 4 commits - officecfg/registry sw/inc sw/Library_swui.mk sw/sdi sw/source sw/uiconfig sw/UIConfig_swriter.mk

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Feb 15 18:26:27 UTC 2019


Rebased ref, commits from common ancestor:
commit 1995af364f6d6d0532210583eb7c26a3f9368f68
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Feb 15 17:50:18 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Feb 15 19:24:01 2019 +0100

    MSForms: Rework the MS compatible Forms menu a bit
    
    * DateField is saved as a content control in MSO file formats
    so let have it under content controls submenu
    * The MS compatible forms menu is a Writer specific thing so better
    to have the related commands as Writer commands.
    
    Change-Id: I2d66130f54c055a422f56b18ff2c98667e4f6469

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 5e8709ba4938..ccaed35731b0 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -6833,16 +6833,6 @@
           <value xml:lang="en-US">More Fields</value>
         </prop>
       </node>
-      <node oor:name=".uno:MSCompatActiveXControls" oor:op="replace">
-        <prop oor:name="Label" oor:type="xs:string">
-          <value xml:lang="en-US">ActiveX Controls</value>
-        </prop>
-      </node>
-      <node oor:name=".uno:MSCompatLegacyControls" oor:op="replace">
-        <prop oor:name="Label" oor:type="xs:string">
-          <value xml:lang="en-US">Legacy Forms</value>
-        </prop>
-      </node>
     </node>
   </node>
 </oor:component-data>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
index cc136f04a7c6..e88f44c8e6ce 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
@@ -3402,6 +3402,21 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:MSCompatActiveXControls" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">ActiveX Controls</value>
+        </prop>
+      </node>
+      <node oor:name=".uno:MSCompatLegacyControls" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Legacy Form Fields</value>
+        </prop>
+      </node>
+      <node oor:name=".uno:MSCompatContentControls" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Content Controls</value>
+        </prop>
+      </node>
     </node>
   </node>
 </oor:component-data>
diff --git a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml
index 4c8e34467d3e..4d157908dd71 100644
--- a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml
+++ b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml
@@ -21,7 +21,6 @@
           <menu:menuitem menu:id=".uno:RadioButton"/>
           <menu:menuitem menu:id=".uno:ListBox"/>
           <menu:menuitem menu:id=".uno:Pushbutton"/>
-          <menu:menuitem menu:id=".uno:DateField"/>
         </menu:menupopup>
       </menu:menu>
       <menu:menu menu:id=".uno:MSCompatLegacyControls">
@@ -31,6 +30,11 @@
           <menu:menuitem menu:id=".uno:DropDownFormField"/>
         </menu:menupopup>
       </menu:menu>
+      <menu:menu menu:id=".uno:MSCompatContentControls">
+        <menu:menupopup>
+          <menu:menuitem menu:id=".uno:DateField"/>
+        </menu:menupopup>
+      </menu:menu>
     </menu:menupopup>
   </menu:menu>
 </menu:menubar>
commit a764f7bb8fc799950a74eae98743664abca0297b
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Feb 15 14:11:37 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Feb 15 19:24:00 2019 +0100

    MSForms: Make Control Properties menu to work with drop-down form field
    
    Always forward the Execute and State method to the form shell,
    so if a form control is selected the Control Properites will
    work correctly.
    Otherwise we check whether there is any field next to the cursor.
    
    Change-Id: I25055c17d887a2f2a716d8325f46825cc408179e

diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index f8c2daee6d65..3724ee041ecc 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1694,5 +1694,11 @@ interface BaseText
         StateMethod = StateField ;
     ]
 
+    SID_FM_CTL_PROPERTIES
+    [
+        ExecMethod = Execute ;
+        StateMethod = GetState ;
+    ]
+
 }  // end of interface text
 
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index fd759463b971..270fcabc08dc 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -119,6 +119,8 @@
 #include <svx/drawitem.hxx>
 #include <numrule.hxx>
 #include <memory>
+#include <xmloff/odffields.hxx>
+#include <swabstdlg.hxx>
 
 using namespace ::com::sun::star;
 using namespace com::sun::star::beans;
@@ -1367,6 +1369,32 @@ void SwTextShell::Execute(SfxRequest &rReq)
         GetView().UpdateWordCount(this, nSlot);
     }
     break;
+    case SID_FM_CTL_PROPERTIES:
+    {
+        SwPosition aPos(*GetShell().GetCursor()->GetPoint());
+        sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+        if ( !pFieldBM )
+        {
+            --aPos.nContent;
+            pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+        }
+
+        if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN )
+        {
+            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+            ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateDropDownFormFieldDialog(rWrtSh.GetView().GetFrameWeld(), pFieldBM));
+            pDlg->Execute();
+            pFieldBM->Invalidate();
+            rWrtSh.InvalidateWindows( rWrtSh.GetView().GetVisArea() );
+        }
+        else
+        {
+            SfxRequest aReq( GetView().GetViewFrame(), SID_FM_CTL_PROPERTIES );
+            aReq.AppendItem( SfxBoolItem( SID_FM_CTL_PROPERTIES, true ) );
+            rWrtSh.GetView().GetFormShell()->Execute( aReq );
+        }
+    }
+    break;
     default:
         OSL_ENSURE(false, "wrong dispatcher");
         return;
@@ -1906,6 +1934,37 @@ void SwTextShell::GetState( SfxItemSet &rSet )
                     rSet.DisableItem(nWhich);
             }
             break;
+            case SID_FM_CTL_PROPERTIES:
+            {
+                bool bDisable = false;
+
+                // First get the state from the form shell
+                SfxItemSet aSet(GetShell().GetAttrPool(), svl::Items<SID_FM_CTL_PROPERTIES, SID_FM_CTL_PROPERTIES>{});
+                aSet.Put(SfxBoolItem( SID_FM_CTL_PROPERTIES, true ));
+                GetShell().GetView().GetFormShell()->GetState( aSet );
+
+                if(SfxItemState::DISABLED == aSet.GetItemState(SID_FM_CTL_PROPERTIES))
+                {
+                    bDisable = true;
+                }
+
+                // Enable it if we have a valid object other than what form shell knows
+                SwPosition aPos(*GetShell().GetCursor()->GetPoint());
+                sw::mark::IFieldmark* pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+                if ( !pFieldBM )
+                {
+                    --aPos.nContent;
+                    pFieldBM = GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+                }
+                if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN )
+                {
+                    bDisable = false;
+                }
+
+                if(bDisable)
+                    rSet.DisableItem(nWhich);
+            }
+            break;
         }
         nWhich = aIter.NextWhich();
     }
commit abc31f38ccbe6e4b30c11331be02f0b5201214de
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Thu Feb 14 13:15:41 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Feb 15 19:23:59 2019 +0100

    MSForms: Don't show popup dialog of drop-down field when there is no item list
    
    Change-Id: Ife361e0ee18437da6f188e77713ea51403b70dbc

diff --git a/sw/source/uibase/uiview/viewling.cxx b/sw/source/uibase/uiview/viewling.cxx
index 935f974ce75a..c29c1637ab87 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -912,6 +912,17 @@ IMPL_LINK_NOARG(SwView, FieldPopupModeEndHdl, FloatingWindow*, void)
 
 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 );
commit 30b28dbd73291e834b04d9b50df1735f845c9bca
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Feb 15 19:23:53 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Feb 15 19:23:53 2019 +0100

    MSForms: Introduce a properties dialog for Drop-down form field
    
    - Dialog created similar to the edit dialog of Input field
    - On the dialog, the user can edit the list of the drop down field
    - This dialog is only for editing of the field, so the user can't select
    an item from the list to display in the field.
    
    Change-Id: I6222aba9b211afeb0e9d10d97a49347921ff7353

diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk
index bbacb517f697..2da933936257 100644
--- a/sw/Library_swui.mk
+++ b/sw/Library_swui.mk
@@ -110,6 +110,7 @@ $(eval $(call gb_Library_add_exception_objects,swui,\
     sw/source/ui/envelp/labprt \
     sw/source/ui/envelp/mailmrge \
     sw/source/ui/fldui/DropDownFieldDialog \
+    sw/source/ui/fldui/DropDownFormFieldDialog \
     sw/source/ui/fldui/FldRefTreeListBox \
     sw/source/ui/fldui/changedb \
     sw/source/ui/fldui/flddb \
diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index 5e03ab5d3d7f..4e0b7ecfc037 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -123,6 +123,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
 	sw/uiconfig/swriter/ui/datasourcesunavailabledialog \
 	sw/uiconfig/swriter/ui/dropcapspage \
 	sw/uiconfig/swriter/ui/dropdownfielddialog \
+	sw/uiconfig/swriter/ui/dropdownformfielddialog \
 	sw/uiconfig/swriter/ui/editcategories \
 	sw/uiconfig/swriter/ui/editfielddialog \
 	sw/uiconfig/swriter/ui/editsectiondialog \
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 075d41e873c0..7f0b059bb0a4 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -76,6 +76,9 @@ namespace com{namespace sun{namespace star{
     namespace container { class XNamed; }
 }}}
 
+
+namespace sw { namespace mark { class IFieldmark; } }
+
 typedef   void (*SwLabDlgMethod) (css::uno::Reference< css::frame::XModel> const & xModel, const SwLabItem& rItem);
 
 typedef OUString    (*GlossaryGetCurrGroup)();
@@ -387,6 +390,7 @@ public:
 
     virtual VclPtr<AbstractDropDownFieldDialog> CreateDropDownFieldDialog(weld::Window* pParent, SwWrtShell &rSh,
         SwField* pField, bool bPrevButton, bool bNextButton) = 0;
+    virtual VclPtr<VclAbstractDialog> CreateDropDownFormFieldDialog(weld::Window* pParent, sw::mark::IFieldmark* pDropDownField) = 0;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwEnvDlg(weld::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert) = 0;
 
     virtual VclPtr<AbstractSwLabDlg> CreateSwLabDlg(weld::Window* pParent, const SfxItemSet& rSet,
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx
index 4fc4ec7f085d..00956ff68cd0 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -40,6 +40,7 @@
 #include <docfnote.hxx>
 #include <docstdlg.hxx>
 #include <DropDownFieldDialog.hxx>
+#include <DropDownFormFieldDialog.hxx>
 #include <envlop.hxx>
 #include <label.hxx>
 #include <drpcps.hxx>
@@ -85,6 +86,7 @@
 #include <uiborder.hxx>
 #include <mmresultdialogs.hxx>
 
+
 using namespace ::com::sun::star;
 using namespace css::frame;
 using namespace css::uno;
@@ -171,6 +173,11 @@ short AbstractDropDownFieldDialog_Impl::Execute()
     return m_xDlg->run();
 }
 
+short AbstractDropDownFormFieldDialog_Impl::Execute()
+{
+    return m_xDlg->run();
+}
+
 short AbstractSwLabDlg_Impl::Execute()
 {
     return m_xDlg->run();
@@ -834,6 +841,11 @@ VclPtr<AbstractDropDownFieldDialog> SwAbstractDialogFactory_Impl::CreateDropDown
     return VclPtr<AbstractDropDownFieldDialog_Impl>::Create(std::make_unique<sw::DropDownFieldDialog>(pParent, rSh, pField, bPrevButton, bNextButton));
 }
 
+VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateDropDownFormFieldDialog(weld::Window *pParent, sw::mark::IFieldmark* pDropDownField)
+{
+    return VclPtr<AbstractDropDownFormFieldDialog_Impl>::Create(o3tl::make_unique<sw::DropDownFormFieldDialog>(pParent, pDropDownField));
+}
+
 VclPtr<SfxAbstractTabDialog> SwAbstractDialogFactory_Impl::CreateSwEnvDlg(weld::Window* pParent, const SfxItemSet& rSet,
                                                                  SwWrtShell* pWrtSh, Printer* pPrt,
                                                                  bool bInsert)
diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx
index 067097fcd3aa..76516edbc40b 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -49,6 +49,7 @@ class SwSplitTableDlg;
 namespace sw
 {
 class DropDownFieldDialog;
+class DropDownFormFieldDialog;
 }
 
 #define DECL_ABSTDLG_BASE(Class,DialogClass)        \
@@ -303,6 +304,18 @@ public:
     virtual bool          NextButtonPressed() const override;
 };
 
+class AbstractDropDownFormFieldDialog_Impl : public VclAbstractDialog
+{
+protected:
+    std::unique_ptr<sw::DropDownFormFieldDialog> m_xDlg;
+public:
+    explicit AbstractDropDownFormFieldDialog_Impl(std::unique_ptr<sw::DropDownFormFieldDialog> p)
+        : m_xDlg(std::move(p))
+    {
+    }
+    virtual short Execute() override;
+};
+
 class AbstractSwLabDlg_Impl  : public AbstractSwLabDlg
 {
 protected:
@@ -613,6 +626,7 @@ public:
 
     virtual VclPtr<AbstractDropDownFieldDialog> CreateDropDownFieldDialog(weld::Window* pParent, SwWrtShell &rSh,
         SwField* pField, bool bPrevButton, bool bNextButton) override;
+    virtual VclPtr<VclAbstractDialog> CreateDropDownFormFieldDialog(weld::Window* pParent, sw::mark::IFieldmark* pDropDownField) override;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwEnvDlg(weld::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert) override;
     virtual VclPtr<AbstractSwLabDlg> CreateSwLabDlg(weld::Window* pParent, const SfxItemSet& rSet,
                                                      SwDBManager* pDBManager, bool bLabel) override;
diff --git a/sw/source/ui/dialog/swuiexp.cxx b/sw/source/ui/dialog/swuiexp.cxx
index c016cc6189a4..048904334f8b 100644
--- a/sw/source/ui/dialog/swuiexp.cxx
+++ b/sw/source/ui/dialog/swuiexp.cxx
@@ -27,6 +27,7 @@
 #include <srtdlg.hxx>
 #include <dbinsdlg.hxx>
 #include <DropDownFieldDialog.hxx>
+#include <DropDownFormFieldDialog.hxx>
 #include <fldtdlg.hxx>
 #include <glossary.hxx>
 #include <inpdlg.hxx>
diff --git a/sw/source/ui/fldui/DropDownFormFieldDialog.cxx b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
new file mode 100644
index 000000000000..cb00cc2a255b
--- /dev/null
+++ b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
@@ -0,0 +1,191 @@
+/* -*- 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 <DropDownFormFieldDialog.hxx>
+#include <vcl/event.hxx>
+#include <IMark.hxx>
+#include <xmloff/odffields.hxx>
+
+namespace sw
+{
+DropDownFormFieldDialog::DropDownFormFieldDialog(weld::Window* pParent,
+                                                 mark::IFieldmark* pDropDownField)
+    : GenericDialogController(pParent, "modules/swriter/ui/dropdownformfielddialog.ui",
+                              "DropDownFormFieldDialog")
+    , m_pDropDownField(pDropDownField)
+    , m_bListHasChanged(false)
+    , m_xListItemEntry(m_xBuilder->weld_entry("item_entry"))
+    , m_xListAddButton(m_xBuilder->weld_button("add_button"))
+    , m_xListItemsTreeView(m_xBuilder->weld_tree_view("items_treeview"))
+    , m_xListRemoveButton(m_xBuilder->weld_button("remove_button"))
+    , m_xListUpButton(m_xBuilder->weld_button("up_button"))
+    , m_xListDownButton(m_xBuilder->weld_button("down_button"))
+{
+    getDialog()->connect_key_press(LINK(this, DropDownFormFieldDialog, KeyPressedHdl));
+    getDialog()->connect_key_release(LINK(this, DropDownFormFieldDialog, KeyReleasedHdl));
+
+    m_xListItemsTreeView->set_size_request(m_xListItemEntry->get_preferred_size().Width(),
+                                           m_xListItemEntry->get_preferred_size().Height() * 5);
+    m_xListItemsTreeView->connect_changed(LINK(this, DropDownFormFieldDialog, ListChangedHdl));
+
+    Link<weld::Button&, void> aPushButtonLink(LINK(this, DropDownFormFieldDialog, ButtonPushedHdl));
+    m_xListAddButton->connect_clicked(aPushButtonLink);
+    m_xListRemoveButton->connect_clicked(aPushButtonLink);
+    m_xListUpButton->connect_clicked(aPushButtonLink);
+    m_xListDownButton->connect_clicked(aPushButtonLink);
+
+    InitControls();
+}
+
+DropDownFormFieldDialog::~DropDownFormFieldDialog() {}
+
+IMPL_LINK_NOARG(DropDownFormFieldDialog, ListChangedHdl, weld::TreeView&, void) { UpdateButtons(); }
+
+IMPL_LINK(DropDownFormFieldDialog, KeyPressedHdl, const KeyEvent&, rEvent, bool)
+{
+    if (m_xListItemEntry->has_focus() && rEvent.GetKeyCode().GetCode() == KEY_RETURN)
+    {
+        AppendItemToList();
+    }
+    return false; // Call the dialog's input handler too
+}
+
+IMPL_LINK_NOARG(DropDownFormFieldDialog, KeyReleasedHdl, const KeyEvent&, bool)
+{
+    if (m_xListItemEntry->has_focus())
+    {
+        UpdateButtons();
+    }
+    return false; // Call the dialog's input handler too
+}
+
+IMPL_LINK(DropDownFormFieldDialog, ButtonPushedHdl, weld::Button&, rButton, void)
+{
+    if (&rButton == m_xListAddButton.get())
+    {
+        AppendItemToList();
+    }
+    else if (m_xListItemsTreeView->get_selected_index() != -1)
+    {
+        int nSelPos = m_xListItemsTreeView->get_selected_index();
+        if (&rButton == m_xListRemoveButton.get())
+        {
+            m_xListItemsTreeView->remove(nSelPos);
+            m_xListItemsTreeView->select(nSelPos > 0 ? nSelPos - 1 : 0);
+        }
+        else if (&rButton == m_xListUpButton.get())
+        {
+            const OUString sEntry = m_xListItemsTreeView->get_selected_text();
+            m_xListItemsTreeView->remove(nSelPos);
+            nSelPos--;
+            m_xListItemsTreeView->insert_text(nSelPos, sEntry);
+            m_xListItemsTreeView->select(nSelPos);
+        }
+        else if (&rButton == m_xListDownButton.get())
+        {
+            const OUString sEntry = m_xListItemsTreeView->get_selected_text();
+            m_xListItemsTreeView->remove(nSelPos);
+            nSelPos++;
+            m_xListItemsTreeView->insert_text(nSelPos, sEntry);
+            m_xListItemsTreeView->select(nSelPos);
+        }
+        m_bListHasChanged = true;
+    }
+    UpdateButtons();
+}
+
+void DropDownFormFieldDialog::InitControls()
+{
+    if (m_pDropDownField != nullptr)
+    {
+        const mark::IFieldmark::parameter_map_t* const pParameters
+            = m_pDropDownField->GetParameters();
+
+        auto pListEntries = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
+        if (pListEntries != pParameters->end())
+        {
+            css::uno::Sequence<OUString> vListEntries;
+            pListEntries->second >>= vListEntries;
+            for (const OUString& rItem : vListEntries)
+                m_xListItemsTreeView->append_text(rItem);
+
+            // Select the current one
+            auto pResult = pParameters->find(ODF_FORMDROPDOWN_RESULT);
+            if (pResult != pParameters->end())
+            {
+                sal_Int32 nSelection = -1;
+                pResult->second >>= nSelection;
+                m_xListItemsTreeView->select_text(vListEntries[nSelection]);
+            }
+        }
+    }
+    UpdateButtons();
+}
+
+void DropDownFormFieldDialog::AppendItemToList()
+{
+    if (m_xListAddButton->get_sensitive())
+    {
+        const OUString sEntry(m_xListItemEntry->get_text());
+        if (!sEntry.isEmpty())
+        {
+            m_xListItemsTreeView->append_text(sEntry);
+            m_xListItemsTreeView->select_text(sEntry);
+            m_bListHasChanged = true;
+
+            // Clear entry
+            m_xListItemEntry->set_text(OUString());
+            m_xListItemEntry->grab_focus();
+        }
+        UpdateButtons();
+    }
+}
+
+void DropDownFormFieldDialog::UpdateButtons()
+{
+    m_xListAddButton->set_sensitive(!m_xListItemEntry->get_text().isEmpty()
+                                    && m_xListItemsTreeView->find_text(m_xListItemEntry->get_text())
+                                           == -1);
+
+    int nSelPos = m_xListItemsTreeView->get_selected_index();
+    m_xListRemoveButton->set_sensitive(nSelPos != -1);
+    m_xListUpButton->set_sensitive(nSelPos > 0);
+    m_xListDownButton->set_sensitive(nSelPos != -1
+                                     && nSelPos < m_xListItemsTreeView->n_children() - 1);
+}
+
+void DropDownFormFieldDialog::Apply()
+{
+    if (m_pDropDownField != nullptr && m_bListHasChanged)
+    {
+        mark::IFieldmark::parameter_map_t* pParameters = m_pDropDownField->GetParameters();
+
+        css::uno::Sequence<OUString> vListEntries(m_xListItemsTreeView->n_children());
+        for (int nIndex = 0; nIndex < m_xListItemsTreeView->n_children(); ++nIndex)
+        {
+            vListEntries[nIndex] = m_xListItemsTreeView->get_text(nIndex);
+        }
+
+        if (m_xListItemsTreeView->n_children() != 0)
+        {
+            (*pParameters)[ODF_FORMDROPDOWN_LISTENTRY] <<= vListEntries;
+        }
+        else
+        {
+            pParameters->erase(ODF_FORMDROPDOWN_LISTENTRY);
+        }
+
+        // After editing the drop down field's list we don't specify the selected item
+        pParameters->erase(ODF_FORMDROPDOWN_RESULT);
+    }
+}
+
+} // namespace sw
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/uibase/inc/DropDownFormFieldDialog.hxx b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
new file mode 100644
index 000000000000..3fbb59db0ebc
--- /dev/null
+++ b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
@@ -0,0 +1,69 @@
+/* -*- 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_UIBASE_INC_DROPDOWNFORMFIELDDIALOG_HXX
+#define INCLUDED_SW_SOURCE_UIBASE_INC_DROPDOWNFORMFIELDDIALOG_HXX
+
+#include <vcl/weld.hxx>
+#include "actctrl.hxx"
+
+namespace sw
+{
+namespace mark
+{
+class IFieldmark;
+}
+} // namespace sw
+
+/// Dialog to specify the properties of drop-down form field
+namespace sw
+{
+class DropDownFormFieldDialog : public weld::GenericDialogController
+{
+private:
+    mark::IFieldmark* m_pDropDownField;
+    bool m_bListHasChanged;
+
+    std::unique_ptr<weld::Entry> m_xListItemEntry;
+    std::unique_ptr<weld::Button> m_xListAddButton;
+
+    std::unique_ptr<weld::TreeView> m_xListItemsTreeView;
+
+    std::unique_ptr<weld::Button> m_xListRemoveButton;
+    std::unique_ptr<weld::Button> m_xListUpButton;
+    std::unique_ptr<weld::Button> m_xListDownButton;
+
+    DECL_LINK(ListChangedHdl, weld::TreeView&, void);
+    DECL_LINK(KeyPressedHdl, const KeyEvent&, bool);
+    DECL_LINK(KeyReleasedHdl, const KeyEvent&, bool);
+    DECL_LINK(ButtonPushedHdl, weld::Button&, void);
+
+    void InitControls();
+    void AppendItemToList();
+    void UpdateButtons();
+    void Apply();
+
+public:
+    DropDownFormFieldDialog(weld::Window* pParent, mark::IFieldmark* pDropDownField);
+    virtual ~DropDownFormFieldDialog() override;
+
+    virtual short run() override
+    {
+        short nRet = GenericDialogController::run();
+        if (nRet == RET_OK)
+            Apply();
+        return nRet;
+    }
+};
+
+} // namespace sw
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/uiconfig/swriter/ui/dropdownformfielddialog.ui b/sw/uiconfig/swriter/ui/dropdownformfielddialog.ui
new file mode 100644
index 000000000000..3a170b7cf41d
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/dropdownformfielddialog.ui
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface domain="sw">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkTreeStore" id="liststore1">
+    <columns>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkDialog" id="DropDownFormFieldDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">6</property>
+    <property name="title" translatable="yes" context="dropdownformfielddialog|DropDownFormFieldDialog">Drop-down Form Field</property>
+    <property name="resizable">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="ok">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="help">
+                <property name="label">gtk-help</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+                <property name="secondary">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="list_grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="row_spacing">12</property>
+            <child>
+              <object class="GtkGrid" id="grid9">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="row_spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="item_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes" context="dropdownformfielddialog|item_label">Item</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">item_entry</property>
+                    <property name="xalign">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="item_entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="add_button">
+                <property name="label">gtk-add</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="halign">start</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid" id="grid6">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="row_spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="listitem_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes" context="dropdownformfielddialog|listitem_label">Items on list</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">items_treeview</property>
+                    <property name="xalign">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <property name="shadow_type">in</property>
+                    <child>
+                      <object class="GtkTreeView" id="items_treeview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hexpand">True</property>
+                        <property name="vexpand">True</property>
+                        <property name="model">liststore1</property>
+                        <property name="headers_visible">False</property>
+                        <property name="headers_clickable">False</property>
+                        <property name="search_column">0</property>
+                        <property name="show_expanders">False</property>
+                        <child internal-child="selection">
+                          <object class="GtkTreeSelection" id="treeview-selection1"/>
+                        </child>
+                        <child>
+                          <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                            <child>
+                              <object class="GtkCellRendererText" id="cellrenderertext1"/>
+                              <attributes>
+                                <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButtonBox" id="buttonbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <property name="layout_style">start</property>
+                    <child>
+                      <object class="GtkButton" id="remove_button">
+                        <property name="label">gtk-remove</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="up_button">
+                        <property name="label" translatable="yes" context="dropdownformfielddialog|up">Move Up</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="down_button">
+                        <property name="label" translatable="yes" context="dropdownformfielddialog|down">Move Down</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-5">ok</action-widget>
+      <action-widget response="-6">cancel</action-widget>
+      <action-widget response="-11">help</action-widget>
+    </action-widgets>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list