[Libreoffice-commits] core.git: framework/source svtools/uiconfig svtools/UIConfig_svt.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 23 12:19:18 UTC 2020


 framework/source/uielement/dropdownboxtoolbarcontroller.cxx |  124 ++++++------
 svtools/UIConfig_svt.mk                                     |    1 
 svtools/uiconfig/ui/combocontrol.ui                         |    3 
 svtools/uiconfig/ui/listcontrol.ui                          |   22 ++
 4 files changed, 86 insertions(+), 64 deletions(-)

New commits:
commit db316cb34526549f53725fd72a53b0795e11b742
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Apr 23 09:33:43 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Apr 23 14:18:43 2020 +0200

    weld ListBoxControl
    
    Change-Id: I7f47814a724920f04ce1638b8afa3549ccb6a7c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92751
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/framework/source/uielement/dropdownboxtoolbarcontroller.cxx b/framework/source/uielement/dropdownboxtoolbarcontroller.cxx
index a14a288a2619..84865f0a0f80 100644
--- a/framework/source/uielement/dropdownboxtoolbarcontroller.cxx
+++ b/framework/source/uielement/dropdownboxtoolbarcontroller.cxx
@@ -21,9 +21,9 @@
 
 #include <com/sun/star/beans/PropertyValue.hpp>
 
+#include <svtools/InterimItemWindow.hxx>
 #include <svtools/toolboxcontroller.hxx>
 #include <vcl/svapp.hxx>
-#include <vcl/lstbox.hxx>
 #include <vcl/toolbox.hxx>
 
 using namespace ::com::sun::star;
@@ -41,26 +41,42 @@ namespace framework
 // Unfortunaltly the events are notified through virtual methods instead
 // of Listeners.
 
-class ListBoxControl : public ListBox
+class ListBoxControl final : public InterimItemWindow
 {
-    public:
-        ListBoxControl( vcl::Window* pParent, WinBits nStyle, DropdownToolbarController* pListBoxListener );
-        virtual ~ListBoxControl() override;
-        virtual void dispose() override;
-
-        virtual void Select() override;
-        virtual void GetFocus() override;
-        virtual void LoseFocus() override;
-        virtual bool PreNotify( NotifyEvent& rNEvt ) override;
-
-    private:
-        DropdownToolbarController* m_pListBoxListener;
+public:
+    ListBoxControl(vcl::Window* pParent, DropdownToolbarController* pListBoxListener);
+    virtual ~ListBoxControl() override;
+    virtual void dispose() override;
+
+    void set_active(int nPos) { m_xWidget->set_active(nPos); }
+    void append_text(const OUString& rStr) { m_xWidget->append_text(rStr); }
+    void insert_text(int nPos, const OUString& rStr) { m_xWidget->insert_text(nPos, rStr); }
+    int get_count() const { return m_xWidget->get_count(); }
+    int find_text(const OUString& rStr) const { return m_xWidget->find_text(rStr); }
+    OUString get_active_text() const { return m_xWidget->get_active_text(); }
+    void clear() { return m_xWidget->clear(); }
+    void remove(int nPos) { m_xWidget->remove(nPos); }
+
+    DECL_LINK(FocusInHdl, weld::Widget&, void);
+    DECL_LINK(FocusOutHdl, weld::Widget&, void);
+    DECL_LINK(ModifyHdl, weld::ComboBox&, void);
+
+private:
+    std::unique_ptr<weld::ComboBox> m_xWidget;
+    DropdownToolbarController* m_pListBoxListener;
 };
 
-ListBoxControl::ListBoxControl( vcl::Window* pParent, WinBits nStyle, DropdownToolbarController* pListBoxListener ) :
-    ListBox( pParent, nStyle )
+ListBoxControl::ListBoxControl(vcl::Window* pParent, DropdownToolbarController* pListBoxListener)
+    : InterimItemWindow(pParent, "svt/ui/listcontrol.ui", "ListControl")
+    , m_xWidget(m_xBuilder->weld_combo_box("listbox"))
     , m_pListBoxListener( pListBoxListener )
 {
+    m_xWidget->connect_focus_in(LINK(this, ListBoxControl, FocusInHdl));
+    m_xWidget->connect_focus_out(LINK(this, ListBoxControl, FocusOutHdl));
+    m_xWidget->connect_changed(LINK(this, ListBoxControl, ModifyHdl));
+
+    m_xWidget->set_size_request(42, -1); // so a later narrow size request can stick
+    SetSizePixel(get_preferred_size());
 }
 
 ListBoxControl::~ListBoxControl()
@@ -71,41 +87,28 @@ ListBoxControl::~ListBoxControl()
 void ListBoxControl::dispose()
 {
     m_pListBoxListener = nullptr;
-    ListBox::dispose();
+    m_xWidget.reset();
+    InterimItemWindow::dispose();
 }
 
-void ListBoxControl::Select()
+IMPL_LINK_NOARG(ListBoxControl, ModifyHdl, weld::ComboBox&, void)
 {
-    ListBox::Select();
-    if ( m_pListBoxListener )
+    if (m_pListBoxListener)
         m_pListBoxListener->Select();
 }
 
-void ListBoxControl::GetFocus()
+IMPL_LINK_NOARG(ListBoxControl, FocusInHdl, weld::Widget&, void)
 {
-    ListBox::GetFocus();
-    if ( m_pListBoxListener )
+    if (m_pListBoxListener)
         m_pListBoxListener->GetFocus();
 }
 
-void ListBoxControl::LoseFocus()
+IMPL_LINK_NOARG(ListBoxControl, FocusOutHdl, weld::Widget&, void)
 {
-    ListBox::LoseFocus();
-    if ( m_pListBoxListener )
+    if (m_pListBoxListener)
         m_pListBoxListener->LoseFocus();
 }
 
-bool ListBoxControl::PreNotify( NotifyEvent& rNEvt )
-{
-    bool bRet = false;
-    if ( m_pListBoxListener )
-        bRet = false;
-    if ( !bRet )
-        bRet = ListBox::PreNotify( rNEvt );
-
-    return bRet;
-}
-
 DropdownToolbarController::DropdownToolbarController(
     const Reference< XComponentContext >&    rxContext,
     const Reference< XFrame >&               rFrame,
@@ -116,17 +119,15 @@ DropdownToolbarController::DropdownToolbarController(
     ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
     ,   m_pListBoxControl( nullptr )
 {
-    m_pListBoxControl = VclPtr<ListBoxControl>::Create( m_xToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this );
+    m_pListBoxControl = VclPtr<ListBoxControl>::Create(m_xToolbar, this);
     if ( nWidth == 0 )
         nWidth = 100;
 
-    // default dropdown size
-    ::Size aLogicalSize( 0, 160 );
-    ::Size aPixelSize = m_pListBoxControl->LogicToPixel(aLogicalSize, MapMode(MapUnit::MapAppFont));
+    // ListBoxControl ctor has set a suitable height already
+    auto nHeight = m_pListBoxControl->GetSizePixel().Height();
 
-    m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
+    m_pListBoxControl->SetSizePixel( ::Size( nWidth, nHeight ));
     m_xToolbar->SetItemWindow( m_nID, m_pListBoxControl );
-    m_pListBoxControl->SetDropDownLineCount( 5 );
 }
 
 DropdownToolbarController::~DropdownToolbarController()
@@ -146,7 +147,7 @@ void SAL_CALL DropdownToolbarController::dispose()
 Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
 {
     Sequence<PropertyValue> aArgs( 2 );
-    OUString aSelectedText = m_pListBoxControl->GetSelectedEntry();
+    OUString aSelectedText = m_pListBoxControl->get_active_text();
 
     // Add key modifier to argument list
     aArgs[0].Name = "KeyModifier";
@@ -158,13 +159,8 @@ Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyM
 
 void DropdownToolbarController::Select()
 {
-    if ( m_pListBoxControl->GetEntryCount() > 0 )
-    {
-        vcl::Window::PointerState aState = m_pListBoxControl->GetPointerState();
-
-        sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODIFIERS_MASK );
-        execute( nKeyModifier );
-    }
+    if (m_pListBoxControl->get_count() > 0)
+        execute(0);
 }
 
 void DropdownToolbarController::GetFocus()
@@ -186,13 +182,13 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
             if ( rControlCommand.Arguments[i].Name == "List" )
             {
                 Sequence< OUString > aList;
-                m_pListBoxControl->Clear();
+                m_pListBoxControl->clear();
 
                 rControlCommand.Arguments[i].Value >>= aList;
-                for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
-                    m_pListBoxControl->InsertEntry( aList[j] );
+                for (sal_Int32 j = 0; j < aList.getLength(); ++j)
+                    m_pListBoxControl->append_text(aList[j]);
 
-                m_pListBoxControl->SelectEntryPos( 0 );
+                m_pListBoxControl->set_active(0);
 
                 // send notification
                 uno::Sequence< beans::NamedValue > aInfo { { "List", css::uno::makeAny(aList) } };
@@ -212,14 +208,14 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
             if ( rControlCommand.Arguments[i].Name == "Text" )
             {
                 if ( rControlCommand.Arguments[i].Value >>= aText )
-                    m_pListBoxControl->InsertEntry( aText, LISTBOX_APPEND );
+                    m_pListBoxControl->append_text(aText);
                 break;
             }
         }
     }
     else if ( rControlCommand.Command == "InsertEntry" )
     {
-        sal_Int32      nPos( LISTBOX_APPEND );
+        sal_Int32 nPos(-1);
         OUString   aText;
         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
         {
@@ -229,7 +225,7 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
                 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
                 {
                     if (( nTmpPos >= 0 ) &&
-                        ( nTmpPos < m_pListBoxControl->GetEntryCount() ))
+                        ( nTmpPos < m_pListBoxControl->get_count() ))
                         nPos = nTmpPos;
                 }
             }
@@ -237,7 +233,7 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
                 rControlCommand.Arguments[i].Value >>= aText;
         }
 
-        m_pListBoxControl->InsertEntry( aText, nPos );
+        m_pListBoxControl->insert_text(nPos, aText);
     }
     else if ( rControlCommand.Command == "RemoveEntryPos" )
     {
@@ -248,8 +244,8 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
                 sal_Int32 nPos( -1 );
                 if ( rControlCommand.Arguments[i].Value >>= nPos )
                 {
-                    if ( 0 <= nPos && nPos < m_pListBoxControl->GetEntryCount() )
-                        m_pListBoxControl->RemoveEntry( nPos );
+                    if ( 0 <= nPos && nPos < m_pListBoxControl->get_count() )
+                        m_pListBoxControl->remove(nPos);
                 }
                 break;
             }
@@ -263,7 +259,11 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
             {
                 OUString aText;
                 if ( rControlCommand.Arguments[i].Value >>= aText )
-                    m_pListBoxControl->RemoveEntry( aText );
+                {
+                    auto nPos = m_pListBoxControl->find_text(aText);
+                    if (nPos != -1)
+                        m_pListBoxControl->remove(nPos);
+                }
                 break;
             }
         }
diff --git a/svtools/UIConfig_svt.mk b/svtools/UIConfig_svt.mk
index 9ffba6766b71..e6c205b37f6d 100644
--- a/svtools/UIConfig_svt.mk
+++ b/svtools/UIConfig_svt.mk
@@ -19,6 +19,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svt,\
 	svtools/uiconfig/ui/graphicexport \
 	svtools/uiconfig/ui/inputbox \
 	svtools/uiconfig/ui/javadisableddialog \
+	svtools/uiconfig/ui/listcontrol \
 	svtools/uiconfig/ui/linewindow \
 	svtools/uiconfig/ui/placeedit \
 	svtools/uiconfig/ui/printersetupdialog \
diff --git a/svtools/uiconfig/ui/combocontrol.ui b/svtools/uiconfig/ui/combocontrol.ui
index 0b16afbe2cdc..b3a8ee9e971c 100644
--- a/svtools/uiconfig/ui/combocontrol.ui
+++ b/svtools/uiconfig/ui/combocontrol.ui
@@ -11,7 +11,6 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="hexpand">True</property>
-        <property name="vexpand">True</property>
         <property name="has_entry">True</property>
         <child internal-child="entry">
           <object class="GtkEntry">
@@ -20,7 +19,7 @@
         </child>
       </object>
       <packing>
-        <property name="expand">False</property>
+        <property name="expand">True</property>
         <property name="fill">True</property>
         <property name="position">0</property>
       </packing>
diff --git a/svtools/uiconfig/ui/listcontrol.ui b/svtools/uiconfig/ui/listcontrol.ui
new file mode 100644
index 000000000000..f814e31dd41d
--- /dev/null
+++ b/svtools/uiconfig/ui/listcontrol.ui
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface domain="svt">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkBox" id="ListControl">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkComboBoxText" id="listbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+      </object>
+      <packing>
+        <property name="expand">True</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list