diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-07 11:57:21 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-07 15:30:15 +0100 |
commit | 91f54b1990153efd17ea5e33feffd1ec16b0387b (patch) | |
tree | 367bc38c21223a91f4089a408b5c8d0ae2254974 /sfx2/source/inet | |
parent | 30ab660b07ab9aa72624a728d9e1f963507def7c (diff) |
weld URLBox ItemWindow
Change-Id: I7dad000404a188e2f5588b90d73ea9b1236bd301
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88183
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2/source/inet')
-rw-r--r-- | sfx2/source/inet/inettbc.cxx | 106 |
1 files changed, 82 insertions, 24 deletions
diff --git a/sfx2/source/inet/inettbc.cxx b/sfx2/source/inet/inettbc.cxx index c97e9d59bedf..283f0668cebd 100644 --- a/sfx2/source/inet/inettbc.cxx +++ b/sfx2/source/inet/inettbc.cxx @@ -34,6 +34,7 @@ #include <svtools/inettbc.hxx> +#include <sfx2/InterimItemWindow.hxx> #include <sfx2/sfxsids.hrc> using namespace ::com::sun::star::uno; @@ -50,6 +51,7 @@ SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem) SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) : SfxToolBoxControl( nSlotId, nId, rBox ) + , m_bModified(false) { addStatusListener( ".uno:CurrentURL"); } @@ -58,11 +60,64 @@ SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl() { } -SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const +class URLBoxItemWindow final : public InterimItemWindow { - return static_cast<SvtURLBox*>(GetToolBox().GetItemWindow( GetId() )); +private: + std::unique_ptr<URLBox> m_xWidget; + + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); +public: + URLBoxItemWindow(vcl::Window* pParent) + : InterimItemWindow(pParent, "sfx/ui/urlbox.ui", "URLBox") + , m_xWidget(new URLBox(m_xBuilder->weld_combo_box("urlbox"))) + { + m_xWidget->connect_key_press(LINK(this, URLBoxItemWindow, KeyInputHdl)); + + SetSizePixel(m_xWidget->get_preferred_size()); + } + + URLBox* GetURLBox() + { + return m_xWidget.get(); + } + + virtual void dispose() override + { + m_xWidget.reset(); + InterimItemWindow::dispose(); + } + + virtual void GetFocus() override + { + m_xWidget->grab_focus(); + } + + void set_sensitive(bool bSensitive) + { + Enable(bSensitive); + m_xWidget->set_sensitive(bSensitive); + } + + virtual ~URLBoxItemWindow() override + { + disposeOnce(); + } +}; + +IMPL_LINK(URLBoxItemWindow, KeyInputHdl, const KeyEvent&, rKEvt, bool) +{ + return ChildKeyInput(rKEvt); +} + +URLBoxItemWindow* SfxURLToolBoxControl_Impl::GetURLBoxItemWindow() const +{ + return static_cast<URLBoxItemWindow*>(GetToolBox().GetItemWindow(GetId())); } +URLBox* SfxURLToolBoxControl_Impl::GetURLBox() const +{ + return GetURLBoxItemWindow()->GetURLBox(); +} void SfxURLToolBoxControl_Impl::OpenURL( const OUString& rName ) const { @@ -132,27 +187,29 @@ IMPL_STATIC_LINK( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, void*, p, void ) delete pExecuteInfo; } - VclPtr<vcl::Window> SfxURLToolBoxControl_Impl::CreateItemWindow( vcl::Window* pParent ) { - VclPtrInstance<SvtURLBox> pURLBox( pParent ); - pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) ); - pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) ); - return pURLBox.get(); + VclPtrInstance<URLBoxItemWindow> xURLBox(pParent); + URLBox* pURLBox = xURLBox->GetURLBox(); + pURLBox->connect_changed(LINK(this, SfxURLToolBoxControl_Impl, SelectHdl)); + pURLBox->connect_entry_activate(LINK(this, SfxURLToolBoxControl_Impl, OpenHdl)); + return xURLBox; } -IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, SelectHdl, ComboBox&, void) +IMPL_LINK(SfxURLToolBoxControl_Impl, SelectHdl, weld::ComboBox&, rComboBox, void) { - SvtURLBox* pURLBox = GetURLBox(); + m_bModified = true; + + URLBox* pURLBox = GetURLBox(); OUString aName( pURLBox->GetURL() ); - if ( !pURLBox->IsTravelSelect() && !aName.isEmpty() ) + if (rComboBox.changed_by_menu() && !aName.isEmpty()) OpenURL( aName ); } -IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl, SvtURLBox*, void) +IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl, weld::ComboBox&, bool) { - SvtURLBox* pURLBox = GetURLBox(); + URLBox* pURLBox = GetURLBox(); OpenURL( pURLBox->GetURL() ); Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext ); @@ -166,8 +223,9 @@ IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl, SvtURLBox*, void) pWin->ToTop( ToTopFlags::RestoreWhenMin ); } } -} + return true; +} void SfxURLToolBoxControl_Impl::StateChanged ( @@ -179,21 +237,21 @@ void SfxURLToolBoxControl_Impl::StateChanged if ( nSID == SID_OPENURL ) { // Disable URL box if command is disabled - GetURLBox()->Enable( SfxItemState::DISABLED != eState ); + GetURLBoxItemWindow()->set_sensitive( SfxItemState::DISABLED != eState ); } - if ( !GetURLBox()->IsEnabled() ) + if ( !GetURLBoxItemWindow()->IsEnabled() ) return; if( nSID == SID_FOCUSURLBOX ) { - if ( GetURLBox()->IsVisible() ) - GetURLBox()->GrabFocus(); + if ( GetURLBoxItemWindow()->IsVisible() ) + GetURLBoxItemWindow()->GrabFocus(); } - else if ( !GetURLBox()->IsModified() && SfxItemState::DEFAULT == eState ) + else if ( !m_bModified && SfxItemState::DEFAULT == eState ) { - SvtURLBox* pURLBox = GetURLBox(); - pURLBox->Clear(); + URLBox* pURLBox = GetURLBox(); + pURLBox->clear(); const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(ePICKLIST); for (const css::uno::Sequence< css::beans::PropertyValue >& lProps : lList) @@ -212,9 +270,9 @@ void SfxURLToolBoxControl_Impl::StateChanged OUString sFile; if (osl::FileBase::getSystemPathFromFileURL(sMainURL, sFile) == osl::FileBase::E_None) - pURLBox->InsertEntry(sFile); + pURLBox->append_text(sFile); else - pURLBox->InsertEntry(sMainURL); + pURLBox->append_text(sMainURL); } } @@ -224,10 +282,10 @@ void SfxURLToolBoxControl_Impl::StateChanged INetProtocol eProt = aURL.GetProtocol(); if ( eProt == INetProtocol::File ) { - pURLBox->SetText( aURL.PathToFileName() ); + pURLBox->set_entry_text( aURL.PathToFileName() ); } else - pURLBox->SetText( aURL.GetURLNoPass() ); + pURLBox->set_entry_text( aURL.GetURLNoPass() ); } } |