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