weld ListBoxControl

Change-Id: I7f47814a724920f04ce1638b8afa3549ccb6a7c1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92751
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara
2020-04-23 09:33:43 +01:00
parent 424ffd5ea2
commit db316cb345
4 changed files with 84 additions and 62 deletions

View File

@@ -21,9 +21,9 @@
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <svtools/InterimItemWindow.hxx>
#include <svtools/toolboxcontroller.hxx> #include <svtools/toolboxcontroller.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/toolbox.hxx> #include <vcl/toolbox.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
@@ -41,26 +41,42 @@ namespace framework
// Unfortunaltly the events are notified through virtual methods instead // Unfortunaltly the events are notified through virtual methods instead
// of Listeners. // of Listeners.
class ListBoxControl : public ListBox class ListBoxControl final : public InterimItemWindow
{ {
public: public:
ListBoxControl( vcl::Window* pParent, WinBits nStyle, DropdownToolbarController* pListBoxListener ); ListBoxControl(vcl::Window* pParent, DropdownToolbarController* pListBoxListener);
virtual ~ListBoxControl() override; virtual ~ListBoxControl() override;
virtual void dispose() override; virtual void dispose() override;
virtual void Select() override; void set_active(int nPos) { m_xWidget->set_active(nPos); }
virtual void GetFocus() override; void append_text(const OUString& rStr) { m_xWidget->append_text(rStr); }
virtual void LoseFocus() override; void insert_text(int nPos, const OUString& rStr) { m_xWidget->insert_text(nPos, rStr); }
virtual bool PreNotify( NotifyEvent& rNEvt ) override; 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); }
private: DECL_LINK(FocusInHdl, weld::Widget&, void);
DropdownToolbarController* m_pListBoxListener; 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 ) : ListBoxControl::ListBoxControl(vcl::Window* pParent, DropdownToolbarController* pListBoxListener)
ListBox( pParent, nStyle ) : InterimItemWindow(pParent, "svt/ui/listcontrol.ui", "ListControl")
, m_xWidget(m_xBuilder->weld_combo_box("listbox"))
, m_pListBoxListener( pListBoxListener ) , 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() ListBoxControl::~ListBoxControl()
@@ -71,41 +87,28 @@ ListBoxControl::~ListBoxControl()
void ListBoxControl::dispose() void ListBoxControl::dispose()
{ {
m_pListBoxListener = nullptr; 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(); 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(); 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(); 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( DropdownToolbarController::DropdownToolbarController(
const Reference< XComponentContext >& rxContext, const Reference< XComponentContext >& rxContext,
const Reference< XFrame >& rFrame, const Reference< XFrame >& rFrame,
@@ -116,17 +119,15 @@ DropdownToolbarController::DropdownToolbarController(
ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ) ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
, m_pListBoxControl( nullptr ) , 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 ) if ( nWidth == 0 )
nWidth = 100; nWidth = 100;
// default dropdown size // ListBoxControl ctor has set a suitable height already
::Size aLogicalSize( 0, 160 ); auto nHeight = m_pListBoxControl->GetSizePixel().Height();
::Size aPixelSize = m_pListBoxControl->LogicToPixel(aLogicalSize, MapMode(MapUnit::MapAppFont));
m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() )); m_pListBoxControl->SetSizePixel( ::Size( nWidth, nHeight ));
m_xToolbar->SetItemWindow( m_nID, m_pListBoxControl ); m_xToolbar->SetItemWindow( m_nID, m_pListBoxControl );
m_pListBoxControl->SetDropDownLineCount( 5 );
} }
DropdownToolbarController::~DropdownToolbarController() DropdownToolbarController::~DropdownToolbarController()
@@ -146,7 +147,7 @@ void SAL_CALL DropdownToolbarController::dispose()
Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
{ {
Sequence<PropertyValue> aArgs( 2 ); Sequence<PropertyValue> aArgs( 2 );
OUString aSelectedText = m_pListBoxControl->GetSelectedEntry(); OUString aSelectedText = m_pListBoxControl->get_active_text();
// Add key modifier to argument list // Add key modifier to argument list
aArgs[0].Name = "KeyModifier"; aArgs[0].Name = "KeyModifier";
@@ -158,13 +159,8 @@ Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyM
void DropdownToolbarController::Select() void DropdownToolbarController::Select()
{ {
if ( m_pListBoxControl->GetEntryCount() > 0 ) if (m_pListBoxControl->get_count() > 0)
{ execute(0);
vcl::Window::PointerState aState = m_pListBoxControl->GetPointerState();
sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODIFIERS_MASK );
execute( nKeyModifier );
}
} }
void DropdownToolbarController::GetFocus() void DropdownToolbarController::GetFocus()
@@ -186,13 +182,13 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
if ( rControlCommand.Arguments[i].Name == "List" ) if ( rControlCommand.Arguments[i].Name == "List" )
{ {
Sequence< OUString > aList; Sequence< OUString > aList;
m_pListBoxControl->Clear(); m_pListBoxControl->clear();
rControlCommand.Arguments[i].Value >>= aList; rControlCommand.Arguments[i].Value >>= aList;
for ( sal_Int32 j = 0; j < aList.getLength(); j++ ) for (sal_Int32 j = 0; j < aList.getLength(); ++j)
m_pListBoxControl->InsertEntry( aList[j] ); m_pListBoxControl->append_text(aList[j]);
m_pListBoxControl->SelectEntryPos( 0 ); m_pListBoxControl->set_active(0);
// send notification // send notification
uno::Sequence< beans::NamedValue > aInfo { { "List", css::uno::makeAny(aList) } }; 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].Name == "Text" )
{ {
if ( rControlCommand.Arguments[i].Value >>= aText ) if ( rControlCommand.Arguments[i].Value >>= aText )
m_pListBoxControl->InsertEntry( aText, LISTBOX_APPEND ); m_pListBoxControl->append_text(aText);
break; break;
} }
} }
} }
else if ( rControlCommand.Command == "InsertEntry" ) else if ( rControlCommand.Command == "InsertEntry" )
{ {
sal_Int32 nPos( LISTBOX_APPEND ); sal_Int32 nPos(-1);
OUString aText; OUString aText;
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 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 ( rControlCommand.Arguments[i].Value >>= nTmpPos )
{ {
if (( nTmpPos >= 0 ) && if (( nTmpPos >= 0 ) &&
( nTmpPos < m_pListBoxControl->GetEntryCount() )) ( nTmpPos < m_pListBoxControl->get_count() ))
nPos = nTmpPos; nPos = nTmpPos;
} }
} }
@@ -237,7 +233,7 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
rControlCommand.Arguments[i].Value >>= aText; rControlCommand.Arguments[i].Value >>= aText;
} }
m_pListBoxControl->InsertEntry( aText, nPos ); m_pListBoxControl->insert_text(nPos, aText);
} }
else if ( rControlCommand.Command == "RemoveEntryPos" ) else if ( rControlCommand.Command == "RemoveEntryPos" )
{ {
@@ -248,8 +244,8 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
sal_Int32 nPos( -1 ); sal_Int32 nPos( -1 );
if ( rControlCommand.Arguments[i].Value >>= nPos ) if ( rControlCommand.Arguments[i].Value >>= nPos )
{ {
if ( 0 <= nPos && nPos < m_pListBoxControl->GetEntryCount() ) if ( 0 <= nPos && nPos < m_pListBoxControl->get_count() )
m_pListBoxControl->RemoveEntry( nPos ); m_pListBoxControl->remove(nPos);
} }
break; break;
} }
@@ -263,7 +259,11 @@ void DropdownToolbarController::executeControlCommand( const css::frame::Control
{ {
OUString aText; OUString aText;
if ( rControlCommand.Arguments[i].Value >>= 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; break;
} }
} }

View File

@@ -19,6 +19,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svt,\
svtools/uiconfig/ui/graphicexport \ svtools/uiconfig/ui/graphicexport \
svtools/uiconfig/ui/inputbox \ svtools/uiconfig/ui/inputbox \
svtools/uiconfig/ui/javadisableddialog \ svtools/uiconfig/ui/javadisableddialog \
svtools/uiconfig/ui/listcontrol \
svtools/uiconfig/ui/linewindow \ svtools/uiconfig/ui/linewindow \
svtools/uiconfig/ui/placeedit \ svtools/uiconfig/ui/placeedit \
svtools/uiconfig/ui/printersetupdialog \ svtools/uiconfig/ui/printersetupdialog \

View File

@@ -11,7 +11,6 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="has_entry">True</property> <property name="has_entry">True</property>
<child internal-child="entry"> <child internal-child="entry">
<object class="GtkEntry"> <object class="GtkEntry">
@@ -20,7 +19,7 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>

View File

@@ -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>