summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-05-25 21:35:10 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-05-26 16:39:58 +0200
commitd5bae5b7954a9e6b3cdaccc318080be8d9ae6672 (patch)
treec4ca85c454240cce2042098259631c1747a244c4 /sw/source
parentce5cd186d44e50985ebe3ff6e3e8b0aa262a6f75 (diff)
weld SwFieldListBox
Change-Id: I205ce5b300d869d6424c3552a2799c3b02282ff7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94810 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/crsr/DropDownFormFieldButton.cxx96
1 files changed, 63 insertions, 33 deletions
diff --git a/sw/source/core/crsr/DropDownFormFieldButton.cxx b/sw/source/core/crsr/DropDownFormFieldButton.cxx
index 249bd22100ed..a110ac3f064b 100644
--- a/sw/source/core/crsr/DropDownFormFieldButton.cxx
+++ b/sw/source/core/crsr/DropDownFormFieldButton.cxx
@@ -11,7 +11,9 @@
#include <edtwin.hxx>
#include <bookmrk.hxx>
#include <vcl/floatwin.hxx>
-#include <vcl/lstbox.hxx>
+#include <vcl/InterimItemWindow.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/svapp.hxx>
#include <xmloff/odffields.hxx>
#include <IMark.hxx>
#include <view.hxx>
@@ -20,6 +22,26 @@
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.
@@ -27,10 +49,10 @@ namespace
class SwFieldDialog : public FloatingWindow
{
private:
- VclPtr<ListBox> m_aListBox;
+ VclPtr<SwFieldListBox> m_xListBox;
sw::mark::IFieldmark* m_pFieldmark;
- DECL_LINK(MyListBoxHandler, ListBox&, void);
+ DECL_LINK(MyListBoxHandler, weld::TreeView&, bool);
public:
SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth);
@@ -41,9 +63,11 @@ public:
SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth)
: FloatingWindow(parent, WB_BORDER | WB_SYSTEMWINDOW)
- , m_aListBox(VclPtr<ListBox>::Create(this))
+ , m_xListBox(VclPtr<SwFieldListBox>::Create(this))
, m_pFieldmark(fieldBM)
{
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+
if (fieldBM != nullptr)
{
const sw::mark::IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
@@ -56,12 +80,12 @@ SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, l
{
pListEntries->second >>= vListEntries;
for (OUString const& i : std::as_const(vListEntries))
- m_aListBox->InsertEntry(i);
+ rTreeView.append_text(i);
}
if (!vListEntries.hasElements())
{
- m_aListBox->InsertEntry(SwResId(STR_DROP_DOWN_EMPTY_LIST));
+ rTreeView.append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST));
}
// Select the current one
@@ -72,17 +96,24 @@ SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, l
{
sal_Int32 nSelection = -1;
pResult->second >>= nSelection;
- m_aListBox->SelectEntryPos(nSelection);
+ rTreeView.set_cursor(nSelection);
+ rTreeView.select(nSelection);
}
}
- Size lbSize(m_aListBox->GetOptimalSize());
- lbSize.AdjustWidth(50);
- lbSize.AdjustHeight(20);
+ auto nHeight = rTreeView.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());
+ lbSize.AdjustWidth(4);
+ lbSize.AdjustHeight(4);
lbSize.setWidth(std::max(lbSize.Width(), nMinListWidth));
- m_aListBox->SetSizePixel(lbSize);
- m_aListBox->SetSelectHdl(LINK(this, SwFieldDialog, MyListBoxHandler));
- m_aListBox->Show();
+ m_xListBox->SetSizePixel(lbSize);
+ rTreeView.connect_row_activated(LINK(this, SwFieldDialog, MyListBoxHandler));
+ m_xListBox->Show();
+
+ rTreeView.grab_focus();
SetSizePixel(lbSize);
}
@@ -91,33 +122,32 @@ SwFieldDialog::~SwFieldDialog() { disposeOnce(); }
void SwFieldDialog::dispose()
{
- m_aListBox.disposeAndClear();
+ m_xListBox.disposeAndClear();
FloatingWindow::dispose();
}
-IMPL_LINK(SwFieldDialog, MyListBoxHandler, ListBox&, rBox, void)
+IMPL_LINK(SwFieldDialog, MyListBoxHandler, weld::TreeView&, rBox, bool)
{
- if (!rBox.IsTravelSelect())
+ OUString sSelection = rBox.get_selected_text();
+ if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
{
- 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;
- (*m_pFieldmark->GetParameters())[sKey] <<= nSelection;
- m_pFieldmark->Invalidate();
- SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
- rView.GetDocShell()->SetModified();
- }
-
EndPopupMode();
+ return true;
}
+
+ sal_Int32 nSelection = rBox.get_selected_index();
+ if (nSelection >= 0)
+ {
+ OUString sKey = ODF_FORMDROPDOWN_RESULT;
+ (*m_pFieldmark->GetParameters())[sKey] <<= nSelection;
+ m_pFieldmark->Invalidate();
+ SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
+ rView.GetDocShell()->SetModified();
+ }
+
+ EndPopupMode();
+
+ return true;
}
DropDownFormFieldButton::DropDownFormFieldButton(SwEditWin* pEditWin,