1*6d3a6a0bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*6d3a6a0bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*6d3a6a0bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*6d3a6a0bSAndrew Rist * distributed with this work for additional information
6*6d3a6a0bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*6d3a6a0bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*6d3a6a0bSAndrew Rist * "License"); you may not use this file except in compliance
9*6d3a6a0bSAndrew Rist * with the License. You may obtain a copy of the License at
10*6d3a6a0bSAndrew Rist *
11*6d3a6a0bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*6d3a6a0bSAndrew Rist *
13*6d3a6a0bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*6d3a6a0bSAndrew Rist * software distributed under the License is distributed on an
15*6d3a6a0bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d3a6a0bSAndrew Rist * KIND, either express or implied. See the License for the
17*6d3a6a0bSAndrew Rist * specific language governing permissions and limitations
18*6d3a6a0bSAndrew Rist * under the License.
19*6d3a6a0bSAndrew Rist *
20*6d3a6a0bSAndrew Rist *************************************************************/
21*6d3a6a0bSAndrew Rist
22*6d3a6a0bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir //------------------------------------------------------------------------
25cdf0e10cSrcweir // includes
26cdf0e10cSrcweir //------------------------------------------------------------------------
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir #include "AutoBuffer.hxx"
30cdf0e10cSrcweir #include "WinImplHelper.hxx"
31cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <systools/win32/user9x.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir //------------------------------------------------------------
36cdf0e10cSrcweir // namespace directives
37cdf0e10cSrcweir //------------------------------------------------------------
38cdf0e10cSrcweir
39cdf0e10cSrcweir using rtl::OUString;
40cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
41cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
42cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
43cdf0e10cSrcweir using ::com::sun::star::uno::Any;
44cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
45cdf0e10cSrcweir
46cdf0e10cSrcweir //------------------------------------------------------------
47cdf0e10cSrcweir // determine if we are running under Win2000
48cdf0e10cSrcweir //------------------------------------------------------------
49cdf0e10cSrcweir
IsWin2000()50cdf0e10cSrcweir sal_Bool SAL_CALL IsWin2000( )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir OSVERSIONINFOEX osvi;
53cdf0e10cSrcweir BOOL bOsVersionInfoEx;
54cdf0e10cSrcweir sal_Bool bRet = sal_False;
55cdf0e10cSrcweir
56cdf0e10cSrcweir osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
57cdf0e10cSrcweir bOsVersionInfoEx = GetVersionEx( ( OSVERSIONINFO* )&osvi );
58cdf0e10cSrcweir if( !bOsVersionInfoEx )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir // if OSVERSIONINFOEX doesn't work
61cdf0e10cSrcweir osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
62cdf0e10cSrcweir if( !GetVersionEx( ( OSVERSIONINFO* )&osvi ) )
63cdf0e10cSrcweir return sal_False;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir if( ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId ) && ( osvi.dwMajorVersion >= 5 ) )
67cdf0e10cSrcweir bRet = sal_True;
68cdf0e10cSrcweir
69cdf0e10cSrcweir return bRet;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir //------------------------------------------------------------
73cdf0e10cSrcweir //
74cdf0e10cSrcweir //------------------------------------------------------------
75cdf0e10cSrcweir
ListboxAddString(HWND hwnd,const OUString & aString)76cdf0e10cSrcweir void SAL_CALL ListboxAddString( HWND hwnd, const OUString& aString )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir LRESULT rc = SendMessageW(
79cdf0e10cSrcweir hwnd, CB_ADDSTRING, 0, reinterpret_cast< LPARAM >(aString.getStr( )) );
80cdf0e10cSrcweir
81cdf0e10cSrcweir OSL_ASSERT( (CB_ERR != rc) && (CB_ERRSPACE != rc) );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //------------------------------------------------------------
85cdf0e10cSrcweir //
86cdf0e10cSrcweir //------------------------------------------------------------
87cdf0e10cSrcweir
ListboxGetString(HWND hwnd,sal_Int32 aPosition)88cdf0e10cSrcweir OUString SAL_CALL ListboxGetString( HWND hwnd, sal_Int32 aPosition )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
91cdf0e10cSrcweir
92cdf0e10cSrcweir OUString aString;
93cdf0e10cSrcweir
94cdf0e10cSrcweir LRESULT lItem =
95cdf0e10cSrcweir SendMessageW( hwnd, CB_GETLBTEXTLEN, aPosition, 0 );
96cdf0e10cSrcweir
97cdf0e10cSrcweir if ( (CB_ERR != lItem) && (lItem > 0) )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir // message returns the len of a combobox item
100cdf0e10cSrcweir // without trailing '\0' that's why += 1
101cdf0e10cSrcweir lItem++;
102cdf0e10cSrcweir
103cdf0e10cSrcweir CAutoUnicodeBuffer aBuff( lItem );
104cdf0e10cSrcweir
105cdf0e10cSrcweir LRESULT lRet =
106cdf0e10cSrcweir SendMessageW(
107cdf0e10cSrcweir hwnd, CB_GETLBTEXT, aPosition,
108cdf0e10cSrcweir reinterpret_cast<LPARAM>(&aBuff) );
109cdf0e10cSrcweir
110cdf0e10cSrcweir OSL_ASSERT( lRet != CB_ERR );
111cdf0e10cSrcweir
112cdf0e10cSrcweir if ( CB_ERR != lRet )
113cdf0e10cSrcweir aString = OUString( aBuff, lRet );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir return aString;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir //------------------------------------------------------------
120cdf0e10cSrcweir //
121cdf0e10cSrcweir //------------------------------------------------------------
122cdf0e10cSrcweir
ListboxAddItem(HWND hwnd,const Any & aItem,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)123cdf0e10cSrcweir void SAL_CALL ListboxAddItem( HWND hwnd, const Any& aItem, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
124cdf0e10cSrcweir throw( IllegalArgumentException )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( !aItem.hasValue( ) ||
129cdf0e10cSrcweir aItem.getValueType( ) != getCppuType((OUString*)0) )
130cdf0e10cSrcweir throw IllegalArgumentException(
131cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ),
132cdf0e10cSrcweir rXInterface,
133cdf0e10cSrcweir aArgPos );
134cdf0e10cSrcweir
135cdf0e10cSrcweir OUString cbItem;
136cdf0e10cSrcweir aItem >>= cbItem;
137cdf0e10cSrcweir
138cdf0e10cSrcweir ListboxAddString( hwnd, cbItem );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir //------------------------------------------------------------
142cdf0e10cSrcweir //
143cdf0e10cSrcweir //------------------------------------------------------------
144cdf0e10cSrcweir
ListboxAddItems(HWND hwnd,const Any & aItemList,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)145cdf0e10cSrcweir void SAL_CALL ListboxAddItems( HWND hwnd, const Any& aItemList, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
146cdf0e10cSrcweir throw( IllegalArgumentException )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
149cdf0e10cSrcweir
150cdf0e10cSrcweir if ( !aItemList.hasValue( ) ||
151cdf0e10cSrcweir aItemList.getValueType( ) != getCppuType((Sequence<OUString>*)0) )
152cdf0e10cSrcweir throw IllegalArgumentException(
153cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ),
154cdf0e10cSrcweir rXInterface,
155cdf0e10cSrcweir aArgPos );
156cdf0e10cSrcweir
157cdf0e10cSrcweir Sequence< OUString > aStringList;
158cdf0e10cSrcweir aItemList >>= aStringList;
159cdf0e10cSrcweir
160cdf0e10cSrcweir sal_Int32 nItemCount = aStringList.getLength( );
161cdf0e10cSrcweir for( sal_Int32 i = 0; i < nItemCount; i++ )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir ListboxAddString( hwnd, aStringList[i] );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir //------------------------------------------------------------
168cdf0e10cSrcweir //
169cdf0e10cSrcweir //------------------------------------------------------------
170cdf0e10cSrcweir
ListboxDeleteItem(HWND hwnd,const Any & aPosition,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)171cdf0e10cSrcweir void SAL_CALL ListboxDeleteItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
172cdf0e10cSrcweir throw( IllegalArgumentException )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
175cdf0e10cSrcweir
176cdf0e10cSrcweir if ( !aPosition.hasValue( ) ||
177cdf0e10cSrcweir ( (aPosition.getValueType( ) != getCppuType((sal_Int32*)0)) &&
178cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int16*)0)) &&
179cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int8*)0)) ) )
180cdf0e10cSrcweir throw IllegalArgumentException(
181cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ),
182cdf0e10cSrcweir rXInterface,
183cdf0e10cSrcweir aArgPos );
184cdf0e10cSrcweir
185cdf0e10cSrcweir sal_Int32 nPos;
186cdf0e10cSrcweir aPosition >>= nPos;
187cdf0e10cSrcweir
188cdf0e10cSrcweir LRESULT lRet = SendMessage( hwnd, CB_DELETESTRING, nPos, 0 );
189cdf0e10cSrcweir
190cdf0e10cSrcweir // if the return value is CB_ERR the given
191cdf0e10cSrcweir // index was not correct
192cdf0e10cSrcweir if ( CB_ERR == lRet )
193cdf0e10cSrcweir throw IllegalArgumentException(
194cdf0e10cSrcweir OUString::createFromAscii( "inavlid item position" ),
195cdf0e10cSrcweir rXInterface,
196cdf0e10cSrcweir aArgPos );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir //------------------------------------------------------------
200cdf0e10cSrcweir //
201cdf0e10cSrcweir //------------------------------------------------------------
202cdf0e10cSrcweir
ListboxDeleteItems(HWND hwnd,const Any &,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)203cdf0e10cSrcweir void SAL_CALL ListboxDeleteItems( HWND hwnd, const Any& /*unused*/, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
204cdf0e10cSrcweir throw( IllegalArgumentException )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
207cdf0e10cSrcweir
208cdf0e10cSrcweir LRESULT lRet = 0;
209cdf0e10cSrcweir
210cdf0e10cSrcweir do
211cdf0e10cSrcweir {
212cdf0e10cSrcweir // the return value on success is the number
213cdf0e10cSrcweir // of remaining elements in the listbox
214cdf0e10cSrcweir lRet = SendMessageW( hwnd, CB_DELETESTRING, 0, 0 );
215cdf0e10cSrcweir }
216cdf0e10cSrcweir while ( (lRet != CB_ERR) && (lRet > 0) );
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir //------------------------------------------------------------
220cdf0e10cSrcweir //
221cdf0e10cSrcweir //------------------------------------------------------------
222cdf0e10cSrcweir
ListboxSetSelectedItem(HWND hwnd,const Any & aPosition,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)223cdf0e10cSrcweir void SAL_CALL ListboxSetSelectedItem( HWND hwnd, const Any& aPosition, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
224cdf0e10cSrcweir throw( IllegalArgumentException )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
227cdf0e10cSrcweir
228cdf0e10cSrcweir if ( !aPosition.hasValue( ) ||
229cdf0e10cSrcweir ( (aPosition.getValueType( ) != getCppuType((sal_Int32*)0)) &&
230cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int16*)0)) &&
231cdf0e10cSrcweir (aPosition.getValueType( ) != getCppuType((sal_Int8*)0)) ) )
232cdf0e10cSrcweir throw IllegalArgumentException(
233cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ),
234cdf0e10cSrcweir rXInterface,
235cdf0e10cSrcweir aArgPos );
236cdf0e10cSrcweir
237cdf0e10cSrcweir sal_Int32 nPos;
238cdf0e10cSrcweir aPosition >>= nPos;
239cdf0e10cSrcweir
240cdf0e10cSrcweir if ( nPos < -1 )
241cdf0e10cSrcweir throw IllegalArgumentException(
242cdf0e10cSrcweir OUString::createFromAscii("invalid index"),
243cdf0e10cSrcweir rXInterface,
244cdf0e10cSrcweir aArgPos );
245cdf0e10cSrcweir
246cdf0e10cSrcweir LRESULT lRet = SendMessageW( hwnd, CB_SETCURSEL, nPos, 0 );
247cdf0e10cSrcweir
248cdf0e10cSrcweir if ( (CB_ERR == lRet) && (-1 != nPos) )
249cdf0e10cSrcweir throw IllegalArgumentException(
250cdf0e10cSrcweir OUString::createFromAscii("invalid index"),
251cdf0e10cSrcweir rXInterface,
252cdf0e10cSrcweir aArgPos );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir //------------------------------------------------------------
256cdf0e10cSrcweir //
257cdf0e10cSrcweir //------------------------------------------------------------
258cdf0e10cSrcweir
ListboxGetItems(HWND hwnd)259cdf0e10cSrcweir Any SAL_CALL ListboxGetItems( HWND hwnd )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
262cdf0e10cSrcweir
263cdf0e10cSrcweir LRESULT nItemCount = SendMessageW( hwnd, CB_GETCOUNT, 0, 0 );
264cdf0e10cSrcweir
265cdf0e10cSrcweir Sequence< OUString > aItemList;
266cdf0e10cSrcweir
267cdf0e10cSrcweir if ( CB_ERR != nItemCount )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir aItemList.realloc( nItemCount );
270cdf0e10cSrcweir
271cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nItemCount; i++ )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir aItemList[i] = ListboxGetString( hwnd, i );
274cdf0e10cSrcweir }
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir Any aAny;
278cdf0e10cSrcweir aAny <<= aItemList;
279cdf0e10cSrcweir
280cdf0e10cSrcweir return aAny;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir //------------------------------------------------------------
284cdf0e10cSrcweir //
285cdf0e10cSrcweir //------------------------------------------------------------
286cdf0e10cSrcweir
ListboxGetSelectedItem(HWND hwnd)287cdf0e10cSrcweir Any SAL_CALL ListboxGetSelectedItem( HWND hwnd )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
290cdf0e10cSrcweir
291cdf0e10cSrcweir LRESULT idxItem = SendMessageW( hwnd, CB_GETCURSEL, 0, 0 );
292cdf0e10cSrcweir
293cdf0e10cSrcweir Any aAny;
294cdf0e10cSrcweir aAny <<= ListboxGetString( hwnd, idxItem );
295cdf0e10cSrcweir
296cdf0e10cSrcweir return aAny;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
299cdf0e10cSrcweir //------------------------------------------------------------
300cdf0e10cSrcweir //
301cdf0e10cSrcweir //------------------------------------------------------------
302cdf0e10cSrcweir
CheckboxGetState(HWND hwnd)303cdf0e10cSrcweir Any SAL_CALL CheckboxGetState( HWND hwnd )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
306cdf0e10cSrcweir
307cdf0e10cSrcweir LRESULT lChkState = SendMessageW( hwnd, BM_GETCHECK, 0, 0 );
308cdf0e10cSrcweir sal_Bool bChkState = (lChkState == BST_CHECKED) ? sal_True : sal_False;
309cdf0e10cSrcweir Any aAny;
310cdf0e10cSrcweir aAny.setValue( &bChkState, getCppuType((sal_Bool*)0) );
311cdf0e10cSrcweir return aAny;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314cdf0e10cSrcweir //------------------------------------------------------------
315cdf0e10cSrcweir //
316cdf0e10cSrcweir //------------------------------------------------------------
317cdf0e10cSrcweir
CheckboxSetState(HWND hwnd,const::com::sun::star::uno::Any & aState,const Reference<XInterface> & rXInterface,sal_Int16 aArgPos)318cdf0e10cSrcweir void SAL_CALL CheckboxSetState(
319cdf0e10cSrcweir HWND hwnd, const ::com::sun::star::uno::Any& aState, const Reference< XInterface >& rXInterface, sal_Int16 aArgPos )
320cdf0e10cSrcweir throw( IllegalArgumentException )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir OSL_ASSERT( IsWindow( hwnd ) );
323cdf0e10cSrcweir
324cdf0e10cSrcweir if ( !aState.hasValue( ) ||
325cdf0e10cSrcweir aState.getValueType( ) != getCppuType((sal_Bool*)0) )
326cdf0e10cSrcweir throw IllegalArgumentException(
327cdf0e10cSrcweir OUString::createFromAscii( "invalid value type or any has no value" ),
328cdf0e10cSrcweir rXInterface,
329cdf0e10cSrcweir aArgPos );
330cdf0e10cSrcweir
331cdf0e10cSrcweir sal_Bool bCheckState = *reinterpret_cast< const sal_Bool* >( aState.getValue( ) );
332cdf0e10cSrcweir WPARAM wParam = bCheckState ? BST_CHECKED : BST_UNCHECKED;
333cdf0e10cSrcweir SendMessageW( hwnd, BM_SETCHECK, wParam, 0 );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir
336cdf0e10cSrcweir //------------------------------------------------------------
337cdf0e10cSrcweir //
338cdf0e10cSrcweir //------------------------------------------------------------
339cdf0e10cSrcweir
_wcslenex(const sal_Unicode * pStr)340cdf0e10cSrcweir sal_uInt32 SAL_CALL _wcslenex( const sal_Unicode* pStr )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir if ( !pStr )
343cdf0e10cSrcweir return 0;
344cdf0e10cSrcweir
345cdf0e10cSrcweir const sal_Unicode* pTemp = pStr;
346cdf0e10cSrcweir sal_uInt32 strLen = 0;
347cdf0e10cSrcweir while( *pTemp || *(pTemp + 1) )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir pTemp++;
350cdf0e10cSrcweir strLen++;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir
353cdf0e10cSrcweir return strLen;
354cdf0e10cSrcweir }
355