diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:44:01 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:47:37 +0100 |
commit | d3f4ee2bc288bc3289e61354e00b40128ae98523 (patch) | |
tree | 15c5f8fb24bec060009dbefec787f09243d41d1d /svtools | |
parent | b5764eb9f4e95c4e77bc04e5556a7729c8de5441 (diff) |
Adapted SvtMatchContext_Impl to safer-to-use salhelper::Thread
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/inc/svtools/inettbc.hxx | 3 | ||||
-rw-r--r-- | svtools/source/control/inettbc.cxx | 66 |
2 files changed, 32 insertions, 37 deletions
diff --git a/svtools/inc/svtools/inettbc.hxx b/svtools/inc/svtools/inettbc.hxx index f842378f8e4e..9d54c68b871d 100644 --- a/svtools/inc/svtools/inettbc.hxx +++ b/svtools/inc/svtools/inettbc.hxx @@ -31,6 +31,7 @@ // includes ***************************************************************** +#include "rtl/ref.hxx" #include "svtools/svtdllapi.h" #include <tools/string.hxx> #include <tools/urlobj.hxx> @@ -47,7 +48,7 @@ friend class SvtURLBox_Impl; Link aOpenHdl; String aBaseURL; String aPlaceHolder; - SvtMatchContext_Impl* pCtx; + rtl::Reference< SvtMatchContext_Impl > pCtx; SvtURLBox_Impl* pImp; INetProtocol eSmartProtocol; sal_Bool bAutoCompleteMode : 1; diff --git a/svtools/source/control/inettbc.cxx b/svtools/source/control/inettbc.cxx index 668a65c35a92..7d4ffe57ee4e 100644 --- a/svtools/source/control/inettbc.cxx +++ b/svtools/source/control/inettbc.cxx @@ -47,7 +47,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> #include <vcl/toolbox.hxx> -#include <osl/thread.hxx> +#include <salhelper/thread.hxx> #include <osl/mutex.hxx> #include <vcl/svapp.hxx> #include <unotools/historyoptions.hxx> @@ -96,7 +96,7 @@ public: } }; -class SvtMatchContext_Impl : public ::osl::Thread +class SvtMatchContext_Impl: public salhelper::Thread { static ::osl::Mutex* pDirMutex; @@ -113,9 +113,9 @@ class SvtMatchContext_Impl : public ::osl::Thread DECL_STATIC_LINK( SvtMatchContext_Impl, Select_Impl, void* ); - virtual void SAL_CALL onTerminated( ); - virtual void SAL_CALL run(); - virtual void SAL_CALL Cancel(); + virtual ~SvtMatchContext_Impl(); + virtual void execute(); + void doExecute(); void Insert( const String& rCompletion, const String& rURL, sal_Bool bForce = sal_False); void ReadFolder( const String& rURL, const String& rMatch, sal_Bool bSmart ); void FillPicklist(std::vector<rtl::OUString>& rPickList); @@ -124,7 +124,6 @@ public: static ::osl::Mutex* GetMutex(); SvtMatchContext_Impl( SvtURLBox* pBoxP, const String& rText ); - ~SvtMatchContext_Impl(); void Stop(); }; @@ -140,7 +139,8 @@ public: SvtMatchContext_Impl::SvtMatchContext_Impl( SvtURLBox* pBoxP, const String& rText ) - : aLink( STATIC_LINK( this, SvtMatchContext_Impl, Select_Impl ) ) + : Thread( "SvtMatchContext_Impl" ) + , aLink( STATIC_LINK( this, SvtMatchContext_Impl, Select_Impl ) ) , aBaseURL( pBoxP->aBaseURL ) , aText( rText ) , pBox( pBoxP ) @@ -151,8 +151,6 @@ SvtMatchContext_Impl::SvtMatchContext_Impl( aLink.CreateMutex(); FillPicklist( aPickList ); - - create(); } SvtMatchContext_Impl::~SvtMatchContext_Impl() @@ -188,22 +186,15 @@ void SvtMatchContext_Impl::FillPicklist(std::vector<rtl::OUString>& rPickList) } } -void SAL_CALL SvtMatchContext_Impl::Cancel() -{ - // Cancel button pressed - terminate(); -} - void SvtMatchContext_Impl::Stop() { bStop = sal_True; - - if( isRunning() ) - terminate(); + terminate(); } -void SvtMatchContext_Impl::onTerminated( ) +void SvtMatchContext_Impl::execute( ) { + doExecute(); aLink.Call( this ); } @@ -220,7 +211,6 @@ IMPL_STATIC_LINK( SvtMatchContext_Impl, Select_Impl, void*, ) if( pThis->bStop ) { // completions was stopped, no display - delete pThis; return 0; } @@ -293,8 +283,7 @@ IMPL_STATIC_LINK( SvtMatchContext_Impl, Select_Impl, void*, ) // the box has this control as a member so we have to set that member // to zero before deleting ourself. - pBox->pCtx = NULL; - delete pThis; + pBox->pCtx.clear(); return 0; } @@ -567,7 +556,7 @@ String SvtURLBox::ParseSmart( String aText, String aBaseURL, String aWorkDir ) } //------------------------------------------------------------------------- -void SvtMatchContext_Impl::run() +void SvtMatchContext_Impl::doExecute() { ::osl::MutexGuard aGuard( GetMutex() ); if( bStop ) @@ -750,19 +739,20 @@ void SvtURLBox::TryAutoComplete( sal_Bool bForce ) aCurText.Erase( nLen ); if( aCurText.Len() && bIsAutoCompleteEnabled ) { - if ( pCtx ) + if ( pCtx.is() ) { pCtx->Stop(); - pCtx = NULL; + pCtx->join(); + pCtx.clear(); } pCtx = new SvtMatchContext_Impl( this, aCurText ); + pCtx->launch(); } } //------------------------------------------------------------------------- SvtURLBox::SvtURLBox( Window* pParent, INetProtocol eSmart ) : ComboBox( pParent , WB_DROPDOWN | WB_AUTOSIZE | WB_AUTOHSCROLL ), - pCtx( 0 ), eSmartProtocol( eSmart ), bAutoCompleteMode( sal_False ), bOnlyDirectories( sal_False ), @@ -783,7 +773,6 @@ SvtURLBox::SvtURLBox( Window* pParent, INetProtocol eSmart ) //------------------------------------------------------------------------- SvtURLBox::SvtURLBox( Window* pParent, WinBits _nStyle, INetProtocol eSmart ) : ComboBox( pParent, _nStyle ), - pCtx( 0 ), eSmartProtocol( eSmart ), bAutoCompleteMode( sal_False ), bOnlyDirectories( sal_False ), @@ -799,7 +788,6 @@ SvtURLBox::SvtURLBox( Window* pParent, WinBits _nStyle, INetProtocol eSmart ) //------------------------------------------------------------------------- SvtURLBox::SvtURLBox( Window* pParent, const ResId& _rResId, INetProtocol eSmart ) : ComboBox( pParent , _rResId ), - pCtx( 0 ), eSmartProtocol( eSmart ), bAutoCompleteMode( sal_False ), bOnlyDirectories( sal_False ), @@ -828,10 +816,10 @@ void SvtURLBox::ImplInit() SvtURLBox::~SvtURLBox() { - if( pCtx ) + if( pCtx.is() ) { pCtx->Stop(); - pCtx = NULL; + pCtx->join(); } delete pImp; @@ -839,15 +827,19 @@ SvtURLBox::~SvtURLBox() void SvtURLBox::UpdatePickList( ) { - if( pCtx ) + if( pCtx.is() ) { pCtx->Stop(); - pCtx = NULL; + pCtx->join(); + pCtx.clear(); } String sText = GetText(); if ( sText.Len() && bIsAutoCompleteEnabled ) + { pCtx = new SvtMatchContext_Impl( this, sText ); + pCtx->launch(); + } } void SvtURLBox::SetSmartProtocol( INetProtocol eProt ) @@ -927,10 +919,11 @@ void SvtURLBox::UpdatePicklistForSmartProtocol_Impl() sal_Bool SvtURLBox::ProcessKey( const KeyCode& rKey ) { // every key input stops the current matching thread - if( pCtx ) + if( pCtx.is() ) { pCtx->Stop(); - pCtx = NULL; + pCtx->join(); + pCtx.clear(); } KeyCode aCode( rKey.GetCode() ); @@ -1068,10 +1061,11 @@ long SvtURLBox::Notify( NotifyEvent &rEvt ) { if( !GetText().Len() ) ClearModifyFlag(); - if ( pCtx ) + if ( pCtx.is() ) { pCtx->Stop(); - pCtx = NULL; + pCtx->join(); + pCtx.clear(); } } |