1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //------------------------------------------------------------------------ 32*cdf0e10cSrcweir // includes 33*cdf0e10cSrcweir //------------------------------------------------------------------------ 34*cdf0e10cSrcweir #include <osl/diagnose.h> 35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36*cdf0e10cSrcweir #include "AutoBuffer.hxx" 37*cdf0e10cSrcweir #include "WinImplHelper.hxx" 38*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //------------------------------------------------------------ 41*cdf0e10cSrcweir // namespace directives 42*cdf0e10cSrcweir //------------------------------------------------------------ 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using rtl::OUString; 45*cdf0e10cSrcweir using rtl::OUStringBuffer; 46*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 47*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 48*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 49*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 50*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //------------------------------------------------------------ 53*cdf0e10cSrcweir // 54*cdf0e10cSrcweir //------------------------------------------------------------ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir const rtl::OUString TILDE = OUString::createFromAscii( "~" ); 57*cdf0e10cSrcweir const sal_Unicode TILDE_SIGN = L'~'; 58*cdf0e10cSrcweir const rtl::OUString AMPERSAND = OUString::createFromAscii( "&" ); 59*cdf0e10cSrcweir const sal_Unicode AMPERSAND_SIGN = L'&'; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //------------------------------------------------------------ 62*cdf0e10cSrcweir // OS NAME Platform Major Minor 63*cdf0e10cSrcweir // 64*cdf0e10cSrcweir // Windows NT 3.51 VER_PLATFORM_WIN32_NT 3 51 65*cdf0e10cSrcweir // Windows NT 4.0 VER_PLATFORM_WIN32_NT 4 0 66*cdf0e10cSrcweir // Windows 2000 VER_PLATFORM_WIN32_NT 5 0 67*cdf0e10cSrcweir // Windows XP VER_PLATFORM_WIN32_NT 5 1 68*cdf0e10cSrcweir // Windows Vista VER_PLATFORM_WIN32_NT 6 0 69*cdf0e10cSrcweir // Windows 7 VER_PLATFORM_WIN32_NT 6 1 70*cdf0e10cSrcweir // Windows 95 VER_PLATFORM_WIN32_WINDOWS 4 0 71*cdf0e10cSrcweir // Windows 98 VER_PLATFORM_WIN32_WINDOWS 4 10 72*cdf0e10cSrcweir // Windows ME VER_PLATFORM_WIN32_WINDOWS 4 90 73*cdf0e10cSrcweir //------------------------------------------------------------ 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir bool SAL_CALL IsWindowsVersion(unsigned int PlatformId, unsigned int MajorVersion, int MinorVersion = -1) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir OSVERSIONINFO osvi; 78*cdf0e10cSrcweir osvi.dwOSVersionInfoSize = sizeof(osvi); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir if(!GetVersionEx(&osvi)) 81*cdf0e10cSrcweir return false; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir bool bRet = (PlatformId == osvi.dwPlatformId) && 84*cdf0e10cSrcweir (MajorVersion == osvi.dwMajorVersion); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir if (MinorVersion > -1) 87*cdf0e10cSrcweir bRet = bRet && 88*cdf0e10cSrcweir (sal::static_int_cast< unsigned int >(MinorVersion) == 89*cdf0e10cSrcweir osvi.dwMinorVersion); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir return bRet; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //------------------------------------------------------------ 95*cdf0e10cSrcweir // determine if we are running under Vista or newer OS 96*cdf0e10cSrcweir //------------------------------------------------------------ 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir bool SAL_CALL IsWindowsVistaOrNewer() 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir OSVERSIONINFO osvi; 101*cdf0e10cSrcweir osvi.dwOSVersionInfoSize = sizeof(osvi); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if(!GetVersionEx(&osvi)) 104*cdf0e10cSrcweir return false; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir bool bRet = (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId) && 107*cdf0e10cSrcweir (osvi.dwMajorVersion >= 6); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir bRet = bRet && 110*cdf0e10cSrcweir (osvi.dwMinorVersion >= 111*cdf0e10cSrcweir sal::static_int_cast< unsigned int >(0)); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir return bRet; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir //------------------------------------------------------------ 117*cdf0e10cSrcweir // determine if we are running under Windows 7 118*cdf0e10cSrcweir //------------------------------------------------------------ 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir bool SAL_CALL IsWindows7() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_NT, 6, 1); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir //------------------------------------------------------------ 126*cdf0e10cSrcweir // determine if we are running under Windows Vista 127*cdf0e10cSrcweir //------------------------------------------------------------ 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir bool SAL_CALL IsWindowsVista() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_NT, 6, 0); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //------------------------------------------------------------ 135*cdf0e10cSrcweir // determine if we are running under Windows XP 136*cdf0e10cSrcweir //------------------------------------------------------------ 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir bool SAL_CALL IsWindowsXP() 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_NT, 5, 1); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir //------------------------------------------------------------ 144*cdf0e10cSrcweir // determine if we are running under Windows 2000 145*cdf0e10cSrcweir //------------------------------------------------------------ 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir bool SAL_CALL IsWindows2000() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_NT, 5, 0); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //------------------------------------------------------------ 153*cdf0e10cSrcweir // 154*cdf0e10cSrcweir //------------------------------------------------------------ 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir bool SAL_CALL IsWindows98() 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_WINDOWS, 4, 10); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir //------------------------------------------------------------ 162*cdf0e10cSrcweir // 163*cdf0e10cSrcweir //------------------------------------------------------------ 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir bool SAL_CALL IsWindowsME() 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir return IsWindowsVersion(VER_PLATFORM_WIN32_WINDOWS, 4, 90); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //------------------------------------------------------------ 171*cdf0e10cSrcweir // 172*cdf0e10cSrcweir //------------------------------------------------------------ 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir bool SAL_CALL IsWindows2000Platform() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // POST: return true if we are at least on Windows 2000 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // WRONG!: return IsWindowsVersion(VER_PLATFORM_WIN32_NT, 5); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir OSVERSIONINFO osvi; 181*cdf0e10cSrcweir ZeroMemory(&osvi, sizeof(osvi)); 182*cdf0e10cSrcweir osvi.dwOSVersionInfoSize = sizeof(osvi); 183*cdf0e10cSrcweir GetVersionEx(&osvi); 184*cdf0e10cSrcweir if ( osvi.dwMajorVersion >= 5 ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir return true; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir return false; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir //------------------------------------------------------------ 192*cdf0e10cSrcweir // 193*cdf0e10cSrcweir //------------------------------------------------------------ 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void SAL_CALL ListboxAddString( HWND hwnd, const OUString& aString ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir LRESULT rc = SendMessageW( 198*cdf0e10cSrcweir hwnd, CB_ADDSTRING, 0, reinterpret_cast< LPARAM >(aString.getStr( )) ); 199*cdf0e10cSrcweir (void) rc; // avoid warning 200*cdf0e10cSrcweir OSL_ASSERT( (CB_ERR != rc) && (CB_ERRSPACE != rc) ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir //------------------------------------------------------------ 204*cdf0e10cSrcweir // 205*cdf0e10cSrcweir //------------------------------------------------------------ 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir OUString SAL_CALL ListboxGetString( HWND hwnd, sal_Int32 aPosition ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir OUString aString; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir LRESULT lItem = 214*cdf0e10cSrcweir SendMessageW( hwnd, CB_GETLBTEXTLEN, aPosition, 0 ); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir if ( (CB_ERR != lItem) && (lItem > 0) ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir // message returns the len of a combobox item 219*cdf0e10cSrcweir // without trailing '\0' that's why += 1 220*cdf0e10cSrcweir lItem++; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir CAutoUnicodeBuffer aBuff( lItem ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir LRESULT lRet = 225*cdf0e10cSrcweir SendMessageW( 226*cdf0e10cSrcweir hwnd, CB_GETLBTEXT, aPosition, 227*cdf0e10cSrcweir reinterpret_cast<LPARAM>(&aBuff) ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir OSL_ASSERT( lRet != CB_ERR ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if ( CB_ERR != lRet ) 232*cdf0e10cSrcweir aString = OUString( aBuff, lRet ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir return aString; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //------------------------------------------------------------ 239*cdf0e10cSrcweir // 240*cdf0e10cSrcweir //------------------------------------------------------------ 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir void SAL_CALL ListboxAddItem( HWND hwnd, const Any& aItem, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) 243*cdf0e10cSrcweir throw( IllegalArgumentException ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir if ( !aItem.hasValue( ) || 248*cdf0e10cSrcweir aItem.getValueType( ) != getCppuType((OUString*)0) ) 249*cdf0e10cSrcweir throw IllegalArgumentException( 250*cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ), 251*cdf0e10cSrcweir rXInterface, 252*cdf0e10cSrcweir aArgPos ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir OUString cbItem; 255*cdf0e10cSrcweir aItem >>= cbItem; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir ListboxAddString( hwnd, cbItem ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //------------------------------------------------------------ 261*cdf0e10cSrcweir // 262*cdf0e10cSrcweir //------------------------------------------------------------ 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir void SAL_CALL ListboxAddItems( HWND hwnd, const Any& aItemList, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) 265*cdf0e10cSrcweir throw( IllegalArgumentException ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir if ( !aItemList.hasValue( ) || 270*cdf0e10cSrcweir aItemList.getValueType( ) != getCppuType((Sequence<OUString>*)0) ) 271*cdf0e10cSrcweir throw IllegalArgumentException( 272*cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ), 273*cdf0e10cSrcweir rXInterface, 274*cdf0e10cSrcweir aArgPos ); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir Sequence< OUString > aStringList; 277*cdf0e10cSrcweir aItemList >>= aStringList; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir sal_Int32 nItemCount = aStringList.getLength( ); 280*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nItemCount; i++ ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir ListboxAddString( hwnd, aStringList[i] ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir //------------------------------------------------------------ 287*cdf0e10cSrcweir // 288*cdf0e10cSrcweir //------------------------------------------------------------ 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir void SAL_CALL ListboxDeleteItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) 291*cdf0e10cSrcweir throw( IllegalArgumentException ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir if ( !aPosition.hasValue( ) || 296*cdf0e10cSrcweir ( (aPosition.getValueType( ) != getCppuType((sal_Int32*)0)) && 297*cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int16*)0)) && 298*cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int8*)0)) ) ) 299*cdf0e10cSrcweir throw IllegalArgumentException( 300*cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ), 301*cdf0e10cSrcweir rXInterface, 302*cdf0e10cSrcweir aArgPos ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir sal_Int32 nPos; 305*cdf0e10cSrcweir aPosition >>= nPos; 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir LRESULT lRet = SendMessage( hwnd, CB_DELETESTRING, nPos, 0 ); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // if the return value is CB_ERR the given 310*cdf0e10cSrcweir // index was not correct 311*cdf0e10cSrcweir if ( CB_ERR == lRet ) 312*cdf0e10cSrcweir throw IllegalArgumentException( 313*cdf0e10cSrcweir OUString::createFromAscii( "inavlid item position" ), 314*cdf0e10cSrcweir rXInterface, 315*cdf0e10cSrcweir aArgPos ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir //------------------------------------------------------------ 319*cdf0e10cSrcweir // 320*cdf0e10cSrcweir //------------------------------------------------------------ 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir void SAL_CALL ListboxDeleteItems( HWND hwnd, const Any&, const Reference< XInterface >&, sal_Int16 ) 323*cdf0e10cSrcweir throw( IllegalArgumentException ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir LRESULT lRet = 0; 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir do 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir // the return value on success is the number 332*cdf0e10cSrcweir // of remaining elements in the listbox 333*cdf0e10cSrcweir lRet = SendMessageW( hwnd, CB_DELETESTRING, 0, 0 ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir while ( (lRet != CB_ERR) && (lRet > 0) ); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir //------------------------------------------------------------ 339*cdf0e10cSrcweir // 340*cdf0e10cSrcweir //------------------------------------------------------------ 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir void SAL_CALL ListboxSetSelectedItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) 343*cdf0e10cSrcweir throw( IllegalArgumentException ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir if ( !aPosition.hasValue( ) || 348*cdf0e10cSrcweir ( (aPosition.getValueType( ) != getCppuType((sal_Int32*)0)) && 349*cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int16*)0)) && 350*cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int8*)0)) ) ) 351*cdf0e10cSrcweir throw IllegalArgumentException( 352*cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ), 353*cdf0e10cSrcweir rXInterface, 354*cdf0e10cSrcweir aArgPos ); 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir sal_Int32 nPos; 357*cdf0e10cSrcweir aPosition >>= nPos; 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir if ( nPos < -1 ) 360*cdf0e10cSrcweir throw IllegalArgumentException( 361*cdf0e10cSrcweir OUString::createFromAscii("invalid index"), 362*cdf0e10cSrcweir rXInterface, 363*cdf0e10cSrcweir aArgPos ); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir LRESULT lRet = SendMessageW( hwnd, CB_SETCURSEL, nPos, 0 ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir if ( (CB_ERR == lRet) && (-1 != nPos) ) 368*cdf0e10cSrcweir throw IllegalArgumentException( 369*cdf0e10cSrcweir OUString::createFromAscii("invalid index"), 370*cdf0e10cSrcweir rXInterface, 371*cdf0e10cSrcweir aArgPos ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir //------------------------------------------------------------ 375*cdf0e10cSrcweir // 376*cdf0e10cSrcweir //------------------------------------------------------------ 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir Any SAL_CALL ListboxGetItems( HWND hwnd ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir LRESULT nItemCount = SendMessageW( hwnd, CB_GETCOUNT, 0, 0 ); 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir Sequence< OUString > aItemList; 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir if ( CB_ERR != nItemCount ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir aItemList.realloc( nItemCount ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nItemCount; i++ ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir aItemList[i] = ListboxGetString( hwnd, i ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir Any aAny; 397*cdf0e10cSrcweir aAny <<= aItemList; 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir return aAny; 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir //------------------------------------------------------------ 403*cdf0e10cSrcweir // 404*cdf0e10cSrcweir //------------------------------------------------------------ 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir Any SAL_CALL ListboxGetSelectedItem( HWND hwnd ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir LRESULT idxItem = SendMessageW( hwnd, CB_GETCURSEL, 0, 0 ); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir Any aAny; 413*cdf0e10cSrcweir aAny <<= ListboxGetString( hwnd, idxItem ); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir return aAny; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir //------------------------------------------------------------ 419*cdf0e10cSrcweir // 420*cdf0e10cSrcweir //------------------------------------------------------------ 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir Any SAL_CALL ListboxGetSelectedItemIndex( HWND hwnd ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir LRESULT idxItem = SendMessageW( hwnd, CB_GETCURSEL, 0, 0 ); 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir Any aAny; 429*cdf0e10cSrcweir aAny <<= static_cast< sal_Int32 >( idxItem ); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir return aAny; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir //------------------------------------------------------------ 435*cdf0e10cSrcweir // 436*cdf0e10cSrcweir //------------------------------------------------------------ 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir Any SAL_CALL CheckboxGetState( HWND hwnd ) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir LRESULT lChkState = SendMessageW( hwnd, BM_GETCHECK, 0, 0 ); 443*cdf0e10cSrcweir sal_Bool bChkState = (lChkState == BST_CHECKED) ? sal_True : sal_False; 444*cdf0e10cSrcweir Any aAny; 445*cdf0e10cSrcweir aAny.setValue( &bChkState, getCppuType((sal_Bool*)0) ); 446*cdf0e10cSrcweir return aAny; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir //------------------------------------------------------------ 450*cdf0e10cSrcweir // 451*cdf0e10cSrcweir //------------------------------------------------------------ 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir void SAL_CALL CheckboxSetState( 454*cdf0e10cSrcweir HWND hwnd, const ::com::sun::star::uno::Any& aState, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos ) 455*cdf0e10cSrcweir throw( IllegalArgumentException ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) ); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir if ( !aState.hasValue( ) || 460*cdf0e10cSrcweir aState.getValueType( ) != getCppuType((sal_Bool*)0) ) 461*cdf0e10cSrcweir throw IllegalArgumentException( 462*cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ), 463*cdf0e10cSrcweir rXInterface, 464*cdf0e10cSrcweir aArgPos ); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir sal_Bool bCheckState = *reinterpret_cast< const sal_Bool* >( aState.getValue( ) ); 467*cdf0e10cSrcweir WPARAM wParam = bCheckState ? BST_CHECKED : BST_UNCHECKED; 468*cdf0e10cSrcweir SendMessageW( hwnd, BM_SETCHECK, wParam, 0 ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir //------------------------------------------------------------ 472*cdf0e10cSrcweir // 473*cdf0e10cSrcweir //------------------------------------------------------------ 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir sal_uInt32 SAL_CALL _wcslenex( const sal_Unicode* pStr ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir if ( !pStr ) 478*cdf0e10cSrcweir return 0; 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir const sal_Unicode* pTemp = pStr; 481*cdf0e10cSrcweir sal_uInt32 strLen = 0; 482*cdf0e10cSrcweir while( *pTemp || *(pTemp + 1) ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir pTemp++; 485*cdf0e10cSrcweir strLen++; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir return strLen; 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir //------------------------------------------------------------ 492*cdf0e10cSrcweir // 493*cdf0e10cSrcweir //------------------------------------------------------------ 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir void Replace( const OUString& aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer& aBuffer ) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir OSL_ASSERT( aLabel.getLength( ) ); 498*cdf0e10cSrcweir OSL_ASSERT( aBuffer.getCapacity( ) >= (aLabel.getLength( )) ); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir sal_Int32 i = 0; 501*cdf0e10cSrcweir const sal_Unicode* pCurrent = aLabel.getStr( ); 502*cdf0e10cSrcweir const sal_Unicode* pNext = aLabel.getStr( ) + 1; 503*cdf0e10cSrcweir const sal_Unicode* pEnd = aLabel.getStr( ) + aLabel.getLength( ); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir while( pCurrent < pEnd ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir OSL_ASSERT( pNext <= pEnd ); 508*cdf0e10cSrcweir OSL_ASSERT( (i >= 0) && (i < aBuffer.getCapacity( )) ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir if ( OldChar == *pCurrent ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir if ( OldChar == *pNext ) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir // two OldChars in line will 515*cdf0e10cSrcweir // be replaced by one 516*cdf0e10cSrcweir // e.g. ~~ -> ~ 517*cdf0e10cSrcweir aBuffer.insert( i, *pCurrent ); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // skip the next one 520*cdf0e10cSrcweir pCurrent++; 521*cdf0e10cSrcweir pNext++; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir else 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir // one OldChar will be replace 526*cdf0e10cSrcweir // by NexChar 527*cdf0e10cSrcweir aBuffer.insert( i, NewChar ); 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir else if ( *pCurrent == NewChar ) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir // a NewChar will be replaced by 533*cdf0e10cSrcweir // two NewChars 534*cdf0e10cSrcweir // e.g. & -> && 535*cdf0e10cSrcweir aBuffer.insert( i++, *pCurrent ); 536*cdf0e10cSrcweir aBuffer.insert( i, *pCurrent ); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir else 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir aBuffer.insert( i, *pCurrent ); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir pCurrent++; 544*cdf0e10cSrcweir pNext++; 545*cdf0e10cSrcweir i++; 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir //------------------------------------------------------------ 550*cdf0e10cSrcweir // converts a soffice label to a windows label 551*cdf0e10cSrcweir // the following rules for character replacements 552*cdf0e10cSrcweir // will be done: 553*cdf0e10cSrcweir // '~' -> '&' 554*cdf0e10cSrcweir // '~~' -> '~' 555*cdf0e10cSrcweir // '&' -> '&&' 556*cdf0e10cSrcweir //------------------------------------------------------------ 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir OUString SOfficeToWindowsLabel( const rtl::OUString& aSOLabel ) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir OUString aWinLabel = aSOLabel; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir if ( (aWinLabel.indexOf( TILDE ) > -1) || (aWinLabel.indexOf( AMPERSAND ) > -1) ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir sal_Int32 nStrLen = aWinLabel.getLength( ); 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir // in the worst case the new string is 567*cdf0e10cSrcweir // doubled in length, maybe some waste 568*cdf0e10cSrcweir // of memory but how long is a label 569*cdf0e10cSrcweir // normaly(?) 570*cdf0e10cSrcweir rtl::OUStringBuffer aBuffer( nStrLen * 2 ); 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir Replace( aWinLabel, TILDE_SIGN, AMPERSAND_SIGN, aBuffer ); 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir aWinLabel = aBuffer.makeStringAndClear( ); 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir return aWinLabel; 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir //------------------------------------------------------------ 581*cdf0e10cSrcweir // converts a windows label to a soffice label 582*cdf0e10cSrcweir // the following rules for character replacements 583*cdf0e10cSrcweir // will be done: 584*cdf0e10cSrcweir // '&' -> '~' 585*cdf0e10cSrcweir // '&&' -> '&' 586*cdf0e10cSrcweir // '~' -> '~~' 587*cdf0e10cSrcweir //------------------------------------------------------------ 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir OUString WindowsToSOfficeLabel( const rtl::OUString& aWinLabel ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir OUString aSOLabel = aWinLabel; 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir if ( (aSOLabel.indexOf( TILDE ) > -1) || (aSOLabel.indexOf( AMPERSAND ) > -1) ) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir sal_Int32 nStrLen = aSOLabel.getLength( ); 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir // in the worst case the new string is 598*cdf0e10cSrcweir // doubled in length, maybe some waste 599*cdf0e10cSrcweir // of memory but how long is a label 600*cdf0e10cSrcweir // normaly(?) 601*cdf0e10cSrcweir rtl::OUStringBuffer aBuffer( nStrLen * 2 ); 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir Replace( aSOLabel, AMPERSAND_SIGN, TILDE_SIGN, aBuffer ); 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir aSOLabel = aBuffer.makeStringAndClear( ); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir return aSOLabel; 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir 611