1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "macros.h"
25 
26 IMPLEMENT_THUNK( user32, WINDOWS, BOOL, WINAPI, DrawStateW,
27 (
28 	HDC				hdc,			// handle to device context
29 	HBRUSH			hbr,			// handle to brush
30 	DRAWSTATEPROC	lpOutputFunc,	// pointer to callback function
31 	LPARAM			lData,			// image information
32 	WPARAM			wData,			// more image information
33 	int				x,				// horizontal location of image
34 	int				y,				// vertical location of image
35 	int				cx,				// width of image
36 	int				cy,				// height of image
37 	UINT			fuFlags			// image type and state
38 
39 ))
40 {
41 	switch ( fuFlags & 0x000F )
42 	{
43 	case DST_TEXT:
44 	case DST_PREFIXTEXT:
45 		{
46 			LPSTR	lpTextA = NULL;
47 
48 			if ( lData )
49 			{
50 				int	cchWideChar = (int) (wData ? wData : -1);
51 				int	cchNeeded = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lData, cchWideChar, NULL, 0, NULL, NULL );
52 
53 				lpTextA = (LPSTR)_alloca( cchNeeded * sizeof(CHAR) );
54 
55 				if ( !lpTextA )
56 				{
57 					SetLastError( ERROR_OUTOFMEMORY );
58 					return FALSE;
59 				}
60 
61 				WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)lData, cchWideChar, lpTextA, cchNeeded, NULL, NULL );
62 
63 			}
64 
65 			return DrawStateA( hdc, hbr, lpOutputFunc, (LPARAM)lpTextA, wData, x, y, cx, cy, fuFlags );
66 		}
67 	default:
68 		return DrawStateA( hdc, hbr, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags );
69 	}
70 }
71