summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-02-16 21:20:03 +0100
committerAndras Timar <andras.timar@collabora.com>2019-02-17 11:05:14 +0100
commit7f8004ef1be04413ffe6cded00fc7535608f27fc (patch)
treecfbf81fac4685b577955f5e5c7158485c868df71 /sw/source
parent8c9aa1c4188417cca592047c2994082c14add2d2 (diff)
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. Reviewed-on: https://gerrit.libreoffice.org/67909 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit 117da8dab05986380db586f1fae6a2f0af9ce389) Change-Id: I6222aba9b211afeb0e9d10d97a49347921ff7353 Reviewed-on: https://gerrit.libreoffice.org/67924 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/ui/dialog/swdlgfact.cxx10
-rw-r--r--sw/source/ui/dialog/swdlgfact.hxx7
-rw-r--r--sw/source/ui/dialog/swuiexp.cxx1
-rw-r--r--sw/source/ui/fldui/DropDownFormFieldDialog.cxx183
-rw-r--r--sw/source/uibase/inc/DropDownFormFieldDialog.hxx65
5 files changed, 266 insertions, 0 deletions
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx
index e06a6b4a3910..172c59989013 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>
@@ -86,6 +87,7 @@
#include <uiborder.hxx>
#include <mmresultdialogs.hxx>
+
using namespace ::com::sun::star;
IMPL_ABSTDLG_BASE(AbstractSwWordCountFloatDlg_Impl);
@@ -99,9 +101,11 @@ IMPL_ABSTDLG_BASE(AbstractTabDialog_Impl);
IMPL_ABSTDLG_BASE(AbstractSwConvertTableDlg_Impl);
IMPL_ABSTDLG_BASE(AbstractSwInsertDBColAutoPilot_Impl);
IMPL_ABSTDLG_BASE(AbstractDropDownFieldDialog_Impl);
+IMPL_ABSTDLG_BASE(AbstractDropDownFormFieldDialog_Impl);
IMPL_ABSTDLG_BASE(AbstractSwLabDlg_Impl);
IMPL_ABSTDLG_BASE(AbstractSwSelGlossaryDlg_Impl);
IMPL_ABSTDLG_BASE(AbstractSwAutoFormatDlg_Impl);
+
IMPL_ABSTDLG_BASE(AbstractSwFieldDlg_Impl);
IMPL_ABSTDLG_BASE(AbstractSwRenameXNamedDlg_Impl);
IMPL_ABSTDLG_BASE(AbstractSwModalRedlineAcceptDlg_Impl);
@@ -771,6 +775,12 @@ VclPtr<AbstractDropDownFieldDialog> SwAbstractDialogFactory_Impl::CreateDropDown
return VclPtr<AbstractDropDownFieldDialog_Impl>::Create( pDlg );
}
+VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateDropDownFormFieldDialog(sw::mark::IFieldmark* pDropDownField)
+{
+ VclPtr<sw::DropDownFormFieldDialog> pDlg = VclPtr<sw::DropDownFormFieldDialog>::Create(nullptr, pDropDownField);
+ return VclPtr<VclAbstractDialog_Impl>::Create( pDlg );
+}
+
VclPtr<SfxAbstractTabDialog> SwAbstractDialogFactory_Impl::CreateSwEnvDlg ( vcl::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 337bdf6bc4aa..63aa088a8e8e 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -44,6 +44,7 @@ class SwSplitTableDlg;
namespace sw
{
class DropDownFieldDialog;
+class DropDownFormFieldDialog;
}
#define DECL_ABSTDLG_BASE(Class,DialogClass) \
@@ -167,6 +168,11 @@ class AbstractDropDownFieldDialog_Impl : public AbstractDropDownFieldDialog
virtual bool NextButtonPressed() const override;
};
+class AbstractDropDownFormFieldDialog_Impl : public VclAbstractDialog
+{
+ DECL_ABSTDLG_BASE(AbstractDropDownFormFieldDialog_Impl, sw::DropDownFormFieldDialog)
+};
+
class AbstractSwLabDlg_Impl : public AbstractSwLabDlg
{
DECL_ABSTDLG_BASE(AbstractSwLabDlg_Impl,SwLabDlg)
@@ -403,6 +409,7 @@ public:
virtual VclPtr<AbstractDropDownFieldDialog> CreateDropDownFieldDialog(SwWrtShell &rSh,
SwField* pField, bool bPrevButton, bool bNextButton) override;
+ virtual VclPtr<VclAbstractDialog> CreateDropDownFormFieldDialog(sw::mark::IFieldmark* pDropDownField) override;
virtual VclPtr<SfxAbstractTabDialog> CreateSwEnvDlg ( vcl::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pWrtSh, Printer* pPrt, bool bInsert ) override;
virtual VclPtr<AbstractSwLabDlg> CreateSwLabDlg(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 4e73ff5fe4c2..6398698961aa 100644
--- a/sw/source/ui/dialog/swuiexp.cxx
+++ b/sw/source/ui/dialog/swuiexp.cxx
@@ -25,6 +25,7 @@
#include <convert.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..0a80eae05300
--- /dev/null
+++ b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
@@ -0,0 +1,183 @@
+/* -*- 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(vcl::Window* pParent,
+ mark::IFieldmark* pDropDownField)
+ : SvxStandardDialog(pParent, "DropDownFormFieldDialog",
+ "modules/swriter/ui/dropdownformfielddialog.ui")
+ , m_pDropDownField(pDropDownField)
+ , m_bListHasChanged(false)
+{
+ get(m_xListItemEntry, "item_entry");
+ get(m_xListAddButton, "add_button");
+ get(m_xListItemsTreeView, "items_treeview");
+ get(m_xListRemoveButton, "remove_button");
+ get(m_xListUpButton, "up_button");
+ get(m_xListDownButton, "down_button");
+
+ m_xListItemsTreeView->set_width_request(m_xListItemEntry->get_preferred_size().Width());
+ m_xListItemsTreeView->set_height_request(m_xListItemEntry->get_preferred_size().Height() * 5);
+
+ m_xListItemsTreeView->SetSelectHdl(LINK(this, DropDownFormFieldDialog, SelectHdl));
+
+ m_xListItemEntry->SetModifyHdl(LINK(this, DropDownFormFieldDialog, ModifyEditHdl));
+ m_xListItemEntry->SetReturnActionLink(LINK(this, DropDownFormFieldDialog, ReturnActionHdl));
+
+ Link<Button*, void> aPushButtonLink(LINK(this, DropDownFormFieldDialog, ButtonPushedHdl));
+ m_xListAddButton->SetClickHdl(aPushButtonLink);
+ m_xListRemoveButton->SetClickHdl(aPushButtonLink);
+ m_xListUpButton->SetClickHdl(aPushButtonLink);
+ m_xListDownButton->SetClickHdl(aPushButtonLink);
+
+ InitControls();
+}
+
+DropDownFormFieldDialog::~DropDownFormFieldDialog() {}
+
+IMPL_LINK_NOARG(DropDownFormFieldDialog, SelectHdl, ListBox&, void) { UpdateButtons(); }
+
+IMPL_LINK_NOARG(DropDownFormFieldDialog, ModifyEditHdl, Edit&, void) { UpdateButtons(); }
+
+IMPL_LINK_NOARG(DropDownFormFieldDialog, ReturnActionHdl, ReturnActionEdit&, void)
+{
+ AppendItemToList();
+}
+
+IMPL_LINK(DropDownFormFieldDialog, ButtonPushedHdl, Button*, pButton, void)
+{
+ if (pButton == m_xListAddButton)
+ {
+ AppendItemToList();
+ }
+ else if (m_xListItemsTreeView->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND)
+ {
+ int nSelPos = m_xListItemsTreeView->GetSelectedEntryPos();
+ if (pButton == m_xListRemoveButton)
+ {
+ m_xListItemsTreeView->RemoveEntry(nSelPos);
+ m_xListItemsTreeView->SelectEntryPos(nSelPos > 0 ? nSelPos - 1 : 0);
+ }
+ else if (pButton == m_xListUpButton)
+ {
+ const OUString sEntry = m_xListItemsTreeView->GetSelectedEntry();
+ m_xListItemsTreeView->RemoveEntry(nSelPos);
+ nSelPos--;
+ m_xListItemsTreeView->InsertEntry(sEntry, nSelPos);
+ m_xListItemsTreeView->SelectEntryPos(nSelPos);
+ }
+ else if (pButton == m_xListDownButton)
+ {
+ const OUString sEntry = m_xListItemsTreeView->GetSelectedEntry();
+ m_xListItemsTreeView->RemoveEntry(nSelPos);
+ nSelPos++;
+ m_xListItemsTreeView->InsertEntry(sEntry, nSelPos);
+ m_xListItemsTreeView->SelectEntryPos(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->InsertEntry(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->SelectEntry(vListEntries[nSelection]);
+ }
+ }
+ }
+ UpdateButtons();
+}
+
+void DropDownFormFieldDialog::AppendItemToList()
+{
+ if (m_xListAddButton->IsEnabled())
+ {
+ const OUString sEntry(m_xListItemEntry->GetText());
+ if (!sEntry.isEmpty())
+ {
+ m_xListItemsTreeView->InsertEntry(sEntry);
+ m_xListItemsTreeView->SelectEntry(sEntry);
+ m_bListHasChanged = true;
+
+ // Clear entry
+ m_xListItemEntry->SetText(OUString());
+ m_xListItemEntry->GrabFocus();
+ }
+ UpdateButtons();
+ }
+}
+
+void DropDownFormFieldDialog::UpdateButtons()
+{
+ m_xListAddButton->Enable(
+ !m_xListItemEntry->GetText().isEmpty()
+ && (LISTBOX_ENTRY_NOTFOUND
+ == m_xListItemsTreeView->GetEntryPos(m_xListItemEntry->GetText())));
+
+ int nSelPos = m_xListItemsTreeView->GetSelectedEntryPos();
+ m_xListRemoveButton->Enable(nSelPos != LISTBOX_ENTRY_NOTFOUND);
+ m_xListUpButton->Enable(nSelPos != LISTBOX_ENTRY_NOTFOUND && nSelPos != 0);
+ m_xListDownButton->Enable(nSelPos != LISTBOX_ENTRY_NOTFOUND
+ && nSelPos < m_xListItemsTreeView->GetEntryCount() - 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->GetEntryCount());
+ for (int nIndex = 0; nIndex < m_xListItemsTreeView->GetEntryCount(); ++nIndex)
+ {
+ vListEntries[nIndex] = m_xListItemsTreeView->GetEntry(nIndex);
+ }
+
+ if (vListEntries.getLength() != 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..e9150feb0d47
--- /dev/null
+++ b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
@@ -0,0 +1,65 @@
+/* -*- 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/lstbox.hxx>
+#include <vcl/button.hxx>
+#include <vcl/edit.hxx>
+#include <vcl/window.hxx>
+#include <svx/stddlg.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 SvxStandardDialog
+{
+private:
+ mark::IFieldmark* m_pDropDownField;
+ bool m_bListHasChanged;
+
+ VclPtr<ReturnActionEdit> m_xListItemEntry;
+ VclPtr<PushButton> m_xListAddButton;
+
+ VclPtr<ListBox> m_xListItemsTreeView;
+
+ VclPtr<PushButton> m_xListRemoveButton;
+ VclPtr<PushButton> m_xListUpButton;
+ VclPtr<PushButton> m_xListDownButton;
+
+ DECL_LINK(SelectHdl, ListBox&, void);
+ DECL_LINK(ModifyEditHdl, Edit&, void);
+ DECL_LINK(ReturnActionHdl, ReturnActionEdit&, void);
+ DECL_LINK(ButtonPushedHdl, Button*, void);
+
+ void InitControls();
+ void AppendItemToList();
+ void UpdateButtons();
+ virtual void Apply() override;
+
+public:
+ DropDownFormFieldDialog(vcl::Window* pParent, mark::IFieldmark* pDropDownField);
+ virtual ~DropDownFormFieldDialog() override;
+};
+
+} // namespace sw
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */