diff options
Diffstat (limited to 'sw/source/ui')
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 10 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 7 | ||||
-rw-r--r-- | sw/source/ui/dialog/swuiexp.cxx | 1 | ||||
-rw-r--r-- | sw/source/ui/fldui/DropDownFormFieldDialog.cxx | 183 |
4 files changed, 201 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: */ |