diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-13 15:51:44 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-14 09:56:31 +0100 |
commit | 91cc66dfa77cb0130d0bc99875275f7267b7f95a (patch) | |
tree | e0d2841ea721fc4bdf0ff4e1fd125a73e438baef /toolkit/source/awt | |
parent | 26df9f97bfcd3cbc071dde1dc5cba1703c04f1f9 (diff) |
move VCLXFileControl to toolkit
Change-Id: I39bb417fe7e033a8f368fa04d4a30b2388bcddfb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88615
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'toolkit/source/awt')
-rw-r--r-- | toolkit/source/awt/vclxtoolkit.cxx | 6 | ||||
-rw-r--r-- | toolkit/source/awt/vclxwindows.cxx | 289 |
2 files changed, 295 insertions, 0 deletions
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 01c0d3cd2499..bf875134d9cf 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -78,6 +78,7 @@ #include <toolkit/helper/property.hxx> #include <toolkit/helper/convert.hxx> +#include <controls/filectrl.hxx> #include <vcl/button.hxx> #include <vcl/combobox.hxx> #include <vcl/ctrl.hxx> @@ -1802,6 +1803,11 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, pNewWindow = VclPtr<ProgressBar>::Create( pParent, nWinBits ); *ppNewComp = new VCLXProgressBar; } + else if (aServiceName == "filecontrol") + { + pNewWindow = VclPtr<FileControl>::Create( pParent, nWinBits ); + *ppNewComp = new VCLXFileControl; + } break; default: OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" ); diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index 5789fe5ebf80..1a500e869e7e 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -40,6 +40,7 @@ #include <comphelper/processfactory.hxx> #include <sal/log.hxx> +#include <controls/filectrl.hxx> #include <vcl/button.hxx> #include <vcl/graph.hxx> #include <vcl/lstbox.hxx> @@ -6881,4 +6882,292 @@ void VCLXProgressBar::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) VCLXWindow::ImplGetPropertyIds( rIds, true ); } +VCLXFileControl::VCLXFileControl() : maTextListeners( *this ) +{ +} + +VCLXFileControl::~VCLXFileControl() +{ + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( pControl ) + pControl->GetEdit().SetModifyHdl( Link<Edit&,void>() ); +} + +css::uno::Any VCLXFileControl::queryInterface( const css::uno::Type & rType ) +{ + css::uno::Any aRet = ::cppu::queryInterface( rType, + static_cast< css::awt::XTextComponent* >(this), + static_cast< css::awt::XTextLayoutConstrains* >(this), + static_cast< css::lang::XTypeProvider* >(this) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +IMPL_IMPLEMENTATION_ID( VCLXFileControl ) + +// css::lang::XTypeProvider +css::uno::Sequence< css::uno::Type > VCLXFileControl::getTypes() +{ + static const ::cppu::OTypeCollection aTypeList( + cppu::UnoType<css::lang::XTypeProvider>::get(), + cppu::UnoType<css::awt::XTextComponent>::get(), + cppu::UnoType<css::awt::XTextLayoutConstrains>::get(), + VCLXWindow::getTypes() + ); + return aTypeList.getTypes(); +} + +namespace +{ + void lcl_setWinBits( vcl::Window* _pWindow, WinBits _nBits, bool _bSet ) + { + WinBits nStyle = _pWindow->GetStyle(); + if ( _bSet ) + nStyle |= _nBits; + else + nStyle &= ~_nBits; + _pWindow->SetStyle( nStyle ); + } +} + +void SAL_CALL VCLXFileControl::setProperty( const OUString& PropertyName, const css::uno::Any& Value) +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( !pControl ) + return; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_HIDEINACTIVESELECTION: + { + bool bValue(false); + OSL_VERIFY( Value >>= bValue ); + + lcl_setWinBits( pControl, WB_NOHIDESELECTION, !bValue ); + lcl_setWinBits( &pControl->GetEdit(), WB_NOHIDESELECTION, !bValue ); + } + break; + + default: + VCLXWindow::setProperty( PropertyName, Value ); + break; + } +} + +void VCLXFileControl::SetWindow( const VclPtr< vcl::Window > &pWindow ) +{ + VclPtr< FileControl > pPrevFileControl = GetAsDynamic< FileControl >(); + if ( pPrevFileControl ) + pPrevFileControl->SetEditModifyHdl( Link<Edit&,void>() ); + + FileControl* pNewFileControl = dynamic_cast<FileControl*>( pWindow.get() ); + if ( pNewFileControl ) + pNewFileControl->SetEditModifyHdl( LINK( this, VCLXFileControl, ModifyHdl ) ); + + VCLXWindow::SetWindow( pWindow ); +} + +void VCLXFileControl::addTextListener( const css::uno::Reference< css::awt::XTextListener > & l ) +{ + maTextListeners.addInterface( l ); +} + +void VCLXFileControl::removeTextListener( const css::uno::Reference< css::awt::XTextListener > & l ) +{ + maTextListeners.removeInterface( l ); +} + +void VCLXFileControl::setText( const OUString& aText ) +{ + SolarMutexGuard aGuard; + + VclPtr<vcl::Window> pWindow = GetWindow(); + if ( pWindow ) + { + pWindow->SetText( aText ); + + // also in Java a textChanged is triggered, not in VCL. + // css::awt::Toolkit should be JAVA-compliant... + ModifyHdl(); + } +} + +void VCLXFileControl::insertText( const css::awt::Selection& rSel, const OUString& aText ) +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl ) + { + pFileControl->GetEdit().SetSelection( Selection( rSel.Min, rSel.Max ) ); + pFileControl->GetEdit().ReplaceSelected( aText ); + } +} + +OUString VCLXFileControl::getText() +{ + SolarMutexGuard aGuard; + + OUString aText; + VclPtr<vcl::Window> pWindow = GetWindow(); + if ( pWindow ) + aText = pWindow->GetText(); + return aText; +} + +OUString VCLXFileControl::getSelectedText() +{ + SolarMutexGuard aGuard; + + OUString aText; + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl) + aText = pFileControl->GetEdit().GetSelected(); + return aText; + +} + +void VCLXFileControl::setSelection( const css::awt::Selection& aSelection ) +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl ) + pFileControl->GetEdit().SetSelection( Selection( aSelection.Min, aSelection.Max ) ); +} + +css::awt::Selection VCLXFileControl::getSelection() +{ + SolarMutexGuard aGuard; + + css::awt::Selection aSel; + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl ) + { + aSel.Min = pFileControl->GetEdit().GetSelection().Min(); + aSel.Max = pFileControl->GetEdit().GetSelection().Max(); + } + return aSel; +} + +sal_Bool VCLXFileControl::isEditable() +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + return pFileControl && !pFileControl->GetEdit().IsReadOnly() && pFileControl->GetEdit().IsEnabled(); +} + +void VCLXFileControl::setEditable( sal_Bool bEditable ) +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl ) + pFileControl->GetEdit().SetReadOnly( !bEditable ); +} + +void VCLXFileControl::setMaxTextLen( sal_Int16 nLen ) +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + if ( pFileControl ) + pFileControl->GetEdit().SetMaxTextLen( nLen ); +} + +sal_Int16 VCLXFileControl::getMaxTextLen() +{ + SolarMutexGuard aGuard; + + VclPtr< FileControl > pFileControl = GetAs< FileControl >(); + return pFileControl ? pFileControl->GetEdit().GetMaxTextLen() : 0; +} + + +IMPL_LINK_NOARG(VCLXFileControl, ModifyHdl, Edit&, void) +{ + ModifyHdl(); +} + +void VCLXFileControl::ModifyHdl() +{ + css::awt::TextEvent aEvent; + aEvent.Source = static_cast<cppu::OWeakObject*>(this); + maTextListeners.textChanged( aEvent ); +} + +css::awt::Size VCLXFileControl::getMinimumSize() +{ + SolarMutexGuard aGuard; + + css::awt::Size aSz; + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( pControl ) + { + Size aTmpSize = pControl->GetEdit().CalcMinimumSize(); + aTmpSize.AdjustWidth(pControl->GetButton().CalcMinimumSize().Width() ); + aSz = AWTSize(pControl->CalcWindowSize( aTmpSize )); + } + return aSz; +} + +css::awt::Size VCLXFileControl::getPreferredSize() +{ + css::awt::Size aSz = getMinimumSize(); + aSz.Height += 4; + return aSz; +} + +css::awt::Size VCLXFileControl::calcAdjustedSize( const css::awt::Size& rNewSize ) +{ + SolarMutexGuard aGuard; + + css::awt::Size aSz =rNewSize; + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( pControl ) + { + css::awt::Size aMinSz = getMinimumSize(); + if ( aSz.Height != aMinSz.Height ) + aSz.Height = aMinSz.Height; + } + return aSz; +} + +css::awt::Size VCLXFileControl::getMinimumSize( sal_Int16 nCols, sal_Int16 ) +{ + SolarMutexGuard aGuard; + + css::awt::Size aSz; + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( pControl ) + { + aSz = AWTSize(pControl->GetEdit().CalcSize( nCols )); + aSz.Width += pControl->GetButton().CalcMinimumSize().Width(); + } + return aSz; +} + +void VCLXFileControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) +{ + SolarMutexGuard aGuard; + + nCols = 0; + nLines = 1; + VclPtr< FileControl > pControl = GetAs< FileControl >(); + if ( pControl ) + nCols = pControl->GetEdit().GetMaxVisChars(); +} + +void VCLXFileControl::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + // FIXME: elide duplication ? + BASEPROPERTY_HIDEINACTIVESELECTION, + 0); + VCLXWindow::ImplGetPropertyIds( rIds, true ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |