sw/UIConfig_swriter.mk                          |    1 
 sw/source/core/crsr/DropDownFormFieldButton.cxx |   96 +++++++++++++++---------
 sw/uiconfig/swriter/ui/formdropdown.ui          |   61 +++++++++++++++
 3 files changed, 125 insertions(+), 33 deletions(-)

New commits:
commit d5bae5b7954a9e6b3cdaccc318080be8d9ae6672
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon May 25 21:35:10 2020 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue May 26 16:39:58 2020 +0200

    weld SwFieldListBox
    
    Change-Id: I205ce5b300d869d6424c3552a2799c3b02282ff7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94810
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index ea417c9bfb65..f8727a015b82 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -150,6 +150,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
        sw/uiconfig/swriter/ui/floatingsync \
        sw/uiconfig/swriter/ui/formatsectiondialog \
        sw/uiconfig/swriter/ui/formattablepage \
+       sw/uiconfig/swriter/ui/formdropdown \
        sw/uiconfig/swriter/ui/footendnotedialog \
        sw/uiconfig/swriter/ui/footnotepage \
        sw/uiconfig/swriter/ui/footnoteareapage \
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,
diff --git a/sw/uiconfig/swriter/ui/formdropdown.ui 
b/sw/uiconfig/swriter/ui/formdropdown.ui
new file mode 100644
index 000000000000..ec4034e5c89d
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/formdropdown.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.2 -->
+<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="GtkBox" id="FormDropDown">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">6</property>
+    <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="hscrollbar_policy">never</property>
+        <child>
+          <object class="GtkTreeView" id="list">
+            <property name="visible">True</property>
+            <property name="can_focus">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>
+            <property name="activate_on_single_click">True</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="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to