summaryrefslogtreecommitdiff
path: root/sw/source/core/crsr/DropDownFormFieldButton.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/core/crsr/DropDownFormFieldButton.cxx')
-rw-r--r--sw/source/core/crsr/DropDownFormFieldButton.cxx165
1 files changed, 52 insertions, 113 deletions
diff --git a/sw/source/core/crsr/DropDownFormFieldButton.cxx b/sw/source/core/crsr/DropDownFormFieldButton.cxx
index 5a876f907f96..2198fcf80982 100644
--- a/sw/source/core/crsr/DropDownFormFieldButton.cxx
+++ b/sw/source/core/crsr/DropDownFormFieldButton.cxx
@@ -9,10 +9,7 @@
#include <DropDownFormFieldButton.hxx>
#include <edtwin.hxx>
-#include <bookmrk.hxx>
-#include <vcl/event.hxx>
-#include <vcl/floatwin.hxx>
-#include <vcl/InterimItemWindow.hxx>
+#include <bookmark.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <xmloff/odffields.hxx>
@@ -21,146 +18,76 @@
#include <docsh.hxx>
#include <strings.hrc>
-namespace
-{
-class SwFieldListBox final : public InterimItemWindow
-{
-private:
- std::unique_ptr<weld::TreeView> m_xTreeView;
-
-public:
- SwFieldListBox(vcl::Window* pParent)
- : InterimItemWindow(pParent, "modules/swriter/ui/formdropdown.ui", "FormDropDown")
- , m_xTreeView(m_xBuilder->weld_tree_view("list"))
- {
- }
- weld::TreeView& get_widget() { return *m_xTreeView; }
- virtual ~SwFieldListBox() override { disposeOnce(); }
- virtual void dispose() override
- {
- m_xTreeView.reset();
- InterimItemWindow::dispose();
- }
-};
-
/**
* 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<SwFieldListBox> m_xListBox;
- sw::mark::IFieldmark* m_pFieldmark;
-
- DECL_LINK(MyListBoxHandler, weld::TreeView&, bool);
- DECL_STATIC_LINK(SwFieldDialog, KeyInputHdl, const KeyEvent&, bool);
-
-public:
- SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, tools::Long nMinListWidth);
- virtual ~SwFieldDialog() override;
- virtual void dispose() override;
-};
-}
-SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM,
- tools::Long nMinListWidth)
- : FloatingWindow(parent, WB_BORDER | WB_SYSTEMWINDOW)
- , m_xListBox(VclPtr<SwFieldListBox>::Create(this))
- , m_pFieldmark(fieldBM)
+void DropDownFormFieldButton::InitDropdown()
{
- weld::TreeView& rTreeView = m_xListBox->get_widget();
+ const sw::mark::IFieldmark::parameter_map_t* const pParameters = m_rFieldmark.GetParameters();
+
+ sw::mark::IFieldmark::parameter_map_t::const_iterator pListEntries
+ = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
+ css::uno::Sequence<OUString> vListEntries;
+ if (pListEntries != pParameters->end())
+ {
+ pListEntries->second >>= vListEntries;
+ for (OUString const& i : vListEntries)
+ m_xTreeView->append_text(i);
+ }
+
+ if (!vListEntries.hasElements())
+ {
+ m_xTreeView->append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST));
+ }
- if (fieldBM != nullptr)
+ // Select the current one
+ sw::mark::IFieldmark::parameter_map_t::const_iterator pResult
+ = pParameters->find(ODF_FORMDROPDOWN_RESULT);
+ if (pResult != pParameters->end())
{
- const sw::mark::IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
-
- sw::mark::IFieldmark::parameter_map_t::const_iterator pListEntries
- = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
- css::uno::Sequence<OUString> vListEntries;
- if (pListEntries != pParameters->end())
- {
- pListEntries->second >>= vListEntries;
- for (OUString const& i : std::as_const(vListEntries))
- rTreeView.append_text(i);
- }
-
- if (!vListEntries.hasElements())
- {
- rTreeView.append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST));
- }
-
- // Select the current one
- sw::mark::IFieldmark::parameter_map_t::const_iterator pResult
- = pParameters->find(ODF_FORMDROPDOWN_RESULT);
- if (pResult != pParameters->end())
- {
- sal_Int32 nSelection = -1;
- pResult->second >>= nSelection;
- rTreeView.set_cursor(nSelection);
- rTreeView.select(nSelection);
- }
+ sal_Int32 nSelection = -1;
+ pResult->second >>= nSelection;
+ m_xTreeView->set_cursor(nSelection);
+ m_xTreeView->select(nSelection);
}
- auto nHeight = rTreeView.get_height_rows(
+ auto nHeight = m_xTreeView->get_height_rows(
std::min<int>(Application::GetSettings().GetStyleSettings().GetListBoxMaximumLineCount(),
- rTreeView.n_children()));
- rTreeView.set_size_request(-1, nHeight);
- Size lbSize(rTreeView.get_preferred_size());
+ m_xTreeView->n_children()));
+ m_xTreeView->set_size_request(-1, nHeight);
+ Size lbSize(m_xTreeView->get_preferred_size());
lbSize.AdjustWidth(4);
lbSize.AdjustHeight(4);
+ auto nMinListWidth = GetSizePixel().Width();
lbSize.setWidth(std::max(lbSize.Width(), nMinListWidth));
- m_xListBox->SetSizePixel(lbSize);
- rTreeView.connect_row_activated(LINK(this, SwFieldDialog, MyListBoxHandler));
- rTreeView.connect_key_press(LINK(this, SwFieldDialog, KeyInputHdl));
- m_xListBox->Show();
-
- rTreeView.grab_focus();
-
- SetSizePixel(lbSize);
-}
-
-SwFieldDialog::~SwFieldDialog() { disposeOnce(); }
-
-void SwFieldDialog::dispose()
-{
- m_xListBox.disposeAndClear();
- FloatingWindow::dispose();
+ m_xTreeView->set_size_request(lbSize.Width(), lbSize.Height());
}
-IMPL_LINK(SwFieldDialog, MyListBoxHandler, weld::TreeView&, rBox, bool)
+IMPL_LINK(DropDownFormFieldButton, MyListBoxHandler, weld::TreeView&, rBox, bool)
{
OUString sSelection = rBox.get_selected_text();
if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
{
- EndPopupMode();
+ m_xFieldPopup->popdown();
return true;
}
sal_Int32 nSelection = rBox.get_selected_index();
if (nSelection >= 0)
{
- (*m_pFieldmark->GetParameters())[ODF_FORMDROPDOWN_RESULT] <<= nSelection;
- m_pFieldmark->Invalidate();
+ (*m_rFieldmark.GetParameters())[ODF_FORMDROPDOWN_RESULT] <<= nSelection;
+ m_rFieldmark.Invalidate();
SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
rView.GetDocShell()->SetModified();
}
- EndPopupMode();
+ m_xFieldPopup->popdown();
return true;
}
-IMPL_STATIC_LINK(SwFieldDialog, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
-{
- bool bDone = false;
- vcl::KeyCode aCode = rKeyEvent.GetKeyCode();
- // nowhere to tab to
- if (aCode.GetCode() == KEY_TAB)
- bDone = true;
- return bDone;
-}
-
DropDownFormFieldButton::DropDownFormFieldButton(SwEditWin* pEditWin,
sw::mark::DropDownFieldmark& rFieldmark)
: FormFieldButton(pEditWin, rFieldmark)
@@ -169,10 +96,22 @@ DropDownFormFieldButton::DropDownFormFieldButton(SwEditWin* pEditWin,
DropDownFormFieldButton::~DropDownFormFieldButton() { disposeOnce(); }
-void DropDownFormFieldButton::InitPopup()
+void DropDownFormFieldButton::LaunchPopup()
+{
+ m_xFieldPopupBuilder
+ = Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/formdropdown.ui");
+ m_xFieldPopup = m_xFieldPopupBuilder->weld_popover("FormDropDown");
+ m_xTreeView = m_xFieldPopupBuilder->weld_tree_view("list");
+ InitDropdown();
+ m_xTreeView->connect_row_activated(LINK(this, DropDownFormFieldButton, MyListBoxHandler));
+ FormFieldButton::LaunchPopup();
+ m_xTreeView->grab_focus();
+}
+
+void DropDownFormFieldButton::DestroyPopup()
{
- m_pFieldPopup = VclPtr<SwFieldDialog>::Create(static_cast<SwEditWin*>(GetParent()),
- &m_rFieldmark, GetSizePixel().Width());
+ m_xTreeView.reset();
+ FormFieldButton::DestroyPopup();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */