From bb9e8a3c1015941b29b69bdf7ed709236c1017ca Mon Sep 17 00:00:00 2001 From: Tino Rachui Date: Fri, 15 Jun 2001 14:26:07 +0000 Subject: #86986#added support for new filepicker api --- sysui/source/win32/misc/WinImplHelper.cxx | 268 ++++++++++++++++++++++++++---- sysui/source/win32/misc/WinImplHelper.hxx | 48 +++++- 2 files changed, 275 insertions(+), 41 deletions(-) (limited to 'sysui/source') diff --git a/sysui/source/win32/misc/WinImplHelper.cxx b/sysui/source/win32/misc/WinImplHelper.cxx index 144ed621dba1..f52e2164157d 100644 --- a/sysui/source/win32/misc/WinImplHelper.cxx +++ b/sysui/source/win32/misc/WinImplHelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WinImplHelper.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: tra $ $Date: 2001-05-10 10:59:04 $ + * last change: $Author: tra $ $Date: 2001-06-15 15:26:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,6 +75,10 @@ #include "WinImplHelper.hxx" #endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include +#endif + #include //------------------------------------------------------------ @@ -82,6 +86,11 @@ //------------------------------------------------------------ using rtl::OUString; +using ::com::sun::star::lang::IllegalArgumentException; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Sequence; //------------------------------------------------------------ // determine if we are running under Win2000 @@ -113,76 +122,267 @@ sal_Bool SAL_CALL IsWin2000( ) // //------------------------------------------------------------ -OUString SAL_CALL getCurrentComboboxItem( HWND hwndCbo ) +void SAL_CALL ListboxAddString( HWND hwnd, const OUString& aString ) +{ + LRESULT rc = SendMessageW( + hwnd, CB_ADDSTRING, 0, reinterpret_cast< LPARAM >(aString.getStr( )) ); + + OSL_ASSERT( (CB_ERR != rc) && (CB_ERRSPACE != rc) ); +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +OUString SAL_CALL ListboxGetString( HWND hwnd, sal_Int32 aPosition ) { - LRESULT currentIndex = SendMessageW( hwndCbo, CB_GETCURSEL, 0, 0 ); + OSL_ASSERT( IsWindow( hwnd ) ); + + OUString aString; - OUString aItem; + LRESULT lItem = + SendMessageW( hwnd, CB_GETLBTEXTLEN, aPosition, 0 ); - if ( CB_ERR != currentIndex ) + if ( (CB_ERR != lItem) && (lItem > 0) ) { - LRESULT lenItem = - SendMessageW( hwndCbo, CB_GETLBTEXTLEN, ( WPARAM ) currentIndex, 0 ); + // message returns the len of a combobox item + // without trailing '\0' that's why += 1 + lItem++; - if ( (CB_ERR != lenItem) && (lenItem > 0) ) - { - // message returns the len of a combobox item - // without trailing '\0' that's why + 1 - lenItem++; + CAutoUnicodeBuffer aBuff( lItem ); + + LRESULT lRet = + SendMessageW( + hwnd, CB_GETLBTEXT, aPosition, + reinterpret_cast(&aBuff) ); + + OSL_ASSERT( lRet != CB_ERR ); + + if ( CB_ERR != lRet ) + aString = OUString( aBuff, lRet ); + } + + return aString; +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void SAL_CALL ListboxAddItem( HWND hwnd, const Any& aItem, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); + + if ( !aItem.hasValue( ) || + aItem.getValueType( ) != getCppuType((OUString*)0) ) + throw IllegalArgumentException( + OUString::createFromAscii( "invalid value type or any has no value" ), + rXInterface, + aArgPos ); + + OUString cbItem; + aItem >>= cbItem; + + ListboxAddString( hwnd, cbItem ); +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void SAL_CALL ListboxAddItems( HWND hwnd, const Any& aItemList, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); + + if ( !aItemList.hasValue( ) || + aItemList.getValueType( ) != getCppuType((Sequence*)0) ) + throw IllegalArgumentException( + OUString::createFromAscii( "invalid value type or any has no value" ), + rXInterface, + aArgPos ); + + Sequence< OUString > aStringList; + aItemList >>= aStringList; + + sal_Int32 nItemCount = aStringList.getLength( ); + for( sal_Int32 i = 0; i < nItemCount; i++ ) + { + ListboxAddString( hwnd, aStringList[i] ); + } +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void SAL_CALL ListboxDeleteItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); - CAutoUnicodeBuffer aBuff( lenItem ); + if ( !aPosition.hasValue( ) || + aPosition.getValueType( ) != getCppuType((sal_Int32*)0) ) + throw IllegalArgumentException( + OUString::createFromAscii( "invalid value type or any has no value" ), + rXInterface, + aArgPos ); - LRESULT lRet = - SendMessageW( - hwndCbo, - CB_GETLBTEXT, - ( WPARAM ) currentIndex, - ( LPARAM ) &aBuff ); - OSL_ASSERT( lRet == ( lenItem - 1 ) ); + sal_Int32 nPos; + aPosition >>= nPos; - aItem = OUString( aBuff, lenItem ); + LRESULT lRet = SendMessage( hwnd, CB_DELETESTRING, nPos, 0 ); + + // if the return value is CB_ERR the given + // index was not correct + if ( CB_ERR == lRet ) + throw IllegalArgumentException( + OUString::createFromAscii( "inavlid item position" ), + rXInterface, + aArgPos ); +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void SAL_CALL ListboxDeleteItems( HWND hwnd, const Any& /*unused*/, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); + + LRESULT lRet = 0; + + do + { + // the return value on success is the number + // of remaining elements in the listbox + lRet = SendMessageW( hwnd, CB_DELETESTRING, 0, 0 ); + } + while ( (lRet != CB_ERR) && (lRet > 0) ); +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void SAL_CALL ListboxSetSelectedItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); + + if ( !aPosition.hasValue( ) || + aPosition.getValueType( ) != getCppuType((sal_Int32*)0) ) + throw IllegalArgumentException( + OUString::createFromAscii( "invalid value type or any has no value" ), + rXInterface, + aArgPos ); + + sal_Int32 nPos; + aPosition >>= nPos; + + if ( nPos < -1 ) + throw IllegalArgumentException( + OUString::createFromAscii("invalid index"), + rXInterface, + aArgPos ); + + LRESULT lRet = SendMessageW( hwnd, CB_SETCURSEL, nPos, 0 ); + + if ( (CB_ERR == lRet) && (-1 != nPos) ) + throw IllegalArgumentException( + OUString::createFromAscii("invalid index"), + rXInterface, + aArgPos ); +} + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +Any SAL_CALL ListboxGetItems( HWND hwnd ) +{ + OSL_ASSERT( IsWindow( hwnd ) ); + + LRESULT nItemCount = SendMessageW( hwnd, CB_GETCOUNT, 0, 0 ); + + Sequence< OUString > aItemList; + + if ( CB_ERR != nItemCount ) + { + aItemList.realloc( nItemCount ); + + for ( sal_Int32 i = 0; i < nItemCount; i++ ) + { + aItemList[i] = ListboxGetString( hwnd, i ); } } - return aItem; + Any aAny; + aAny <<= aItemList; + + return aAny; } //------------------------------------------------------------ // //------------------------------------------------------------ -sal_Bool SAL_CALL addComboboxItem( HWND hwndCbo, const rtl::OUString& aItem ) +Any SAL_CALL ListboxGetSelectedItem( HWND hwnd ) { - LRESULT rc = SendMessageW( - hwndCbo, CB_ADDSTRING, 0, reinterpret_cast< LPARAM >(aItem.getStr( )) ); - return ( (CB_ERR != rc) && (CB_ERRSPACE != rc) ); + OSL_ASSERT( IsWindow( hwnd ) ); + + LRESULT idxItem = SendMessageW( hwnd, CB_GETCURSEL, 0, 0 ); + + Any aAny; + aAny <<= ListboxGetString( hwnd, idxItem ); + + return aAny; } //------------------------------------------------------------ // //------------------------------------------------------------ -sal_Bool SAL_CALL getCheckboxState( HWND hwndCbx ) +Any SAL_CALL CheckboxGetState( HWND hwnd ) { - LRESULT cbxState = SendMessageW( hwndCbx, BM_GETCHECK, 0, 0 ); - return ( cbxState == BST_CHECKED ) ? sal_True : sal_False; + OSL_ASSERT( IsWindow( hwnd ) ); + + LRESULT lChkState = SendMessageW( hwnd, BM_GETCHECK, 0, 0 ); + sal_Bool bChkState = (lChkState == BST_CHECKED) ? sal_True : sal_False; + Any aAny; + aAny.setValue( &bChkState, getCppuType((sal_Bool*)0) ); + return aAny; } //------------------------------------------------------------ // //------------------------------------------------------------ -void SAL_CALL setCheckboxState( HWND hwndCbx, sal_Bool bCheckState ) +void SAL_CALL CheckboxSetState( + HWND hwnd, const ::com::sun::star::uno::Any& aState, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( IllegalArgumentException ) { + OSL_ASSERT( IsWindow( hwnd ) ); + + if ( !aState.hasValue( ) || + aState.getValueType( ) != getCppuType((sal_Bool*)0) ) + throw IllegalArgumentException( + OUString::createFromAscii( "invalid value type or any has no value" ), + rXInterface, + aArgPos ); + + sal_Bool bCheckState = *reinterpret_cast< const sal_Bool* >( aState.getValue( ) ); WPARAM wParam = bCheckState ? BST_CHECKED : BST_UNCHECKED; - SendMessageW( hwndCbx, BM_SETCHECK, wParam, 0 ); + SendMessageW( hwnd, BM_SETCHECK, wParam, 0 ); } //------------------------------------------------------------ // //------------------------------------------------------------ -sal_uInt32 _wcslenex( const sal_Unicode* pStr ) +sal_uInt32 SAL_CALL _wcslenex( const sal_Unicode* pStr ) { if ( !pStr ) return 0; @@ -196,4 +396,4 @@ sal_uInt32 _wcslenex( const sal_Unicode* pStr ) } return strLen; -} \ No newline at end of file +} diff --git a/sysui/source/win32/misc/WinImplHelper.hxx b/sysui/source/win32/misc/WinImplHelper.hxx index d15bc1c0b0a7..cc3891b549b3 100644 --- a/sysui/source/win32/misc/WinImplHelper.hxx +++ b/sysui/source/win32/misc/WinImplHelper.hxx @@ -2,9 +2,9 @@ * * $RCSfile: WinImplHelper.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tra $ $Date: 2001-04-26 08:57:05 $ + * last change: $Author: tra $ $Date: 2001-06-15 15:26:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,22 +77,56 @@ #include +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include +#endif + +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include +#endif + //------------------------------------------------------------------------ // deklarations //------------------------------------------------------------------------ sal_Bool SAL_CALL IsWin2000( ); -rtl::OUString SAL_CALL getCurrentComboboxItem( HWND hwndCbo ); -sal_Bool SAL_CALL addComboboxItem( HWND hwndCbo, const rtl::OUString& aItem ); +// set actions +void SAL_CALL ListboxAddItem( + HWND hwnd, const ::com::sun::star::uno::Any& aItem, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang::IllegalArgumentException ); + +void SAL_CALL ListboxAddItems( + HWND hwnd, const ::com::sun::star::uno::Any& aItemList, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang:: IllegalArgumentException ); + +void SAL_CALL ListboxDeleteItem( + HWND hwnd, const ::com::sun::star::uno::Any& aPosition, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang::IllegalArgumentException ); + +void SAL_CALL ListboxDeleteItems( + HWND hwnd, const ::com::sun::star::uno::Any& aUnused, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang::IllegalArgumentException ); + +void SAL_CALL ListboxSetSelectedItem( + HWND hwnd, const ::com::sun::star::uno::Any& aPosition, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang::IllegalArgumentException ); + +// get actions +::com::sun::star::uno::Any SAL_CALL ListboxGetItems( HWND hwnd ); +::com::sun::star::uno::Any SAL_CALL ListboxGetSelectedItem( HWND hwnd ); + +// checkbox helper functions +::com::sun::star::uno::Any SAL_CALL CheckboxGetState( HWND hwnd ); -sal_Bool SAL_CALL getCheckboxState( HWND hwndCbx ); -void SAL_CALL setCheckboxState( HWND hwndCbx, sal_Bool bCheckState ); +void SAL_CALL CheckboxSetState( + HWND hwnd, const ::com::sun::star::uno::Any& aState, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rXInterface, sal_Int16 aArgPos ) + throw( ::com::sun::star::lang::IllegalArgumentException ); // calculates the length of '\0' separated and '\0\0' // ending strings used in some Win32 functions // e.g. Filter\0*.txt\0\0 // the returned length excludes the last '\0' -sal_uInt32 _wcslenex( const sal_Unicode* pStr ); +sal_uInt32 SAL_CALL _wcslenex( const sal_Unicode* pStr ); #endif -- cgit v1.2.3