d3dx9/tests: Use a helper function to set matrix values in math tests.
[wine.git] / dlls / user.exe16 / user.c
blobeac4a19d39fe3c7fcdbcd14d64af7a7ac557c03d
1 /*
2 * Misc 16-bit USER functions
4 * Copyright 1993, 1996 Alexandre Julliard
5 * Copyright 2002 Patrik Stridvall
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
27 #define OEMRESOURCE
29 #include "wine/winuser16.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wownt32.h"
33 #include "user_private.h"
34 #include "wine/list.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(user);
39 /* handle to handle 16 conversions */
40 #define HANDLE_16(h32) (LOWORD(h32))
41 #define HGDIOBJ_16(h32) (LOWORD(h32))
43 /* handle16 to handle conversions */
44 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
45 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
47 #define IS_MENU_STRING_ITEM(flags) \
48 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
50 /* UserSeeUserDo parameters */
51 #define USUD_LOCALALLOC 0x0001
52 #define USUD_LOCALFREE 0x0002
53 #define USUD_LOCALCOMPACT 0x0003
54 #define USUD_LOCALHEAP 0x0004
55 #define USUD_FIRSTCLASS 0x0005
57 #define CID_RESOURCE 0x0001
58 #define CID_WIN32 0x0004
59 #define CID_NONSHARED 0x0008
61 WORD USER_HeapSel = 0; /* USER heap selector */
63 static HINSTANCE16 gdi_inst;
65 struct gray_string_info
67 GRAYSTRINGPROC16 proc;
68 LPARAM param;
69 char str[1];
72 /* callback for 16-bit gray string proc with opaque pointer */
73 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
75 const struct gray_string_info *info = (struct gray_string_info *)param;
76 WORD args[4];
77 DWORD ret;
79 args[3] = HDC_16(hdc);
80 args[2] = HIWORD(info->param);
81 args[1] = LOWORD(info->param);
82 args[0] = len;
83 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
84 return LOWORD(ret);
87 /* callback for 16-bit gray string proc with string pointer */
88 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
90 const struct gray_string_info *info;
91 char *str = (char *)param;
93 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
94 return gray_string_callback( hdc, (LPARAM)info, len );
97 struct draw_state_info
99 DRAWSTATEPROC16 proc;
100 LPARAM param;
103 /* callback for 16-bit DrawState functions */
104 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
106 const struct draw_state_info *info = (struct draw_state_info *)lparam;
107 WORD args[6];
108 DWORD ret;
110 args[5] = HDC_16(hdc);
111 args[4] = HIWORD(info->param);
112 args[3] = LOWORD(info->param);
113 args[2] = wparam;
114 args[1] = cx;
115 args[0] = cy;
116 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
117 return LOWORD(ret);
120 /* This function is a copy of the one in objects/font.c */
121 static void logfont_32_to_16( const LOGFONTA* font32, LPLOGFONT16 font16 )
123 font16->lfHeight = font32->lfHeight;
124 font16->lfWidth = font32->lfWidth;
125 font16->lfEscapement = font32->lfEscapement;
126 font16->lfOrientation = font32->lfOrientation;
127 font16->lfWeight = font32->lfWeight;
128 font16->lfItalic = font32->lfItalic;
129 font16->lfUnderline = font32->lfUnderline;
130 font16->lfStrikeOut = font32->lfStrikeOut;
131 font16->lfCharSet = font32->lfCharSet;
132 font16->lfOutPrecision = font32->lfOutPrecision;
133 font16->lfClipPrecision = font32->lfClipPrecision;
134 font16->lfQuality = font32->lfQuality;
135 font16->lfPitchAndFamily = font32->lfPitchAndFamily;
136 lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
139 static int get_bitmap_width_bytes( int width, int bpp )
141 switch(bpp)
143 case 1:
144 return 2 * ((width+15) / 16);
145 case 4:
146 return 2 * ((width+3) / 4);
147 case 24:
148 width *= 3;
149 /* fall through */
150 case 8:
151 return width + (width & 1);
152 case 16:
153 case 15:
154 return width * 2;
155 case 32:
156 return width * 4;
157 default:
158 WARN("Unknown depth %d, please report.\n", bpp );
160 return -1;
163 /***********************************************************************
164 * Helper for wsprintf16
167 #define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */
168 #define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */
169 #define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */
170 #define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */
171 #define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
172 #define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
174 typedef enum
176 WPR_UNKNOWN,
177 WPR_CHAR,
178 WPR_STRING,
179 WPR_SIGNED,
180 WPR_UNSIGNED,
181 WPR_HEXA
182 } WPRINTF_TYPE;
184 typedef struct
186 UINT flags;
187 UINT width;
188 UINT precision;
189 WPRINTF_TYPE type;
190 } WPRINTF_FORMAT;
192 static INT parse_format( LPCSTR format, WPRINTF_FORMAT *res )
194 LPCSTR p = format;
196 res->flags = 0;
197 res->width = 0;
198 res->precision = 0;
199 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
200 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
201 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
202 while ((*p >= '0') && (*p <= '9')) /* width field */
204 res->width = res->width * 10 + *p - '0';
205 p++;
207 if (*p == '.') /* precision field */
209 p++;
210 while ((*p >= '0') && (*p <= '9'))
212 res->precision = res->precision * 10 + *p - '0';
213 p++;
216 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
217 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
218 switch(*p)
220 case 'c':
221 case 'C': /* no Unicode in Win16 */
222 res->type = WPR_CHAR;
223 break;
224 case 's':
225 case 'S':
226 res->type = WPR_STRING;
227 break;
228 case 'd':
229 case 'i':
230 res->type = WPR_SIGNED;
231 break;
232 case 'u':
233 res->type = WPR_UNSIGNED;
234 break;
235 case 'p':
236 res->width = 8;
237 res->flags |= WPRINTF_ZEROPAD;
238 /* fall through */
239 case 'X':
240 res->flags |= WPRINTF_UPPER_HEX;
241 /* fall through */
242 case 'x':
243 res->type = WPR_HEXA;
244 break;
245 default: /* unknown format char */
246 res->type = WPR_UNKNOWN;
247 p--; /* print format as normal char */
248 break;
250 return (INT)(p - format) + 1;
254 /**********************************************************************
255 * Management of the 16-bit cursors and icons
258 struct cache_entry
260 struct list entry;
261 HINSTANCE16 inst;
262 HRSRC16 rsrc;
263 HRSRC16 group;
264 HICON16 icon;
265 INT count;
268 static struct list icon_cache = LIST_INIT( icon_cache );
270 static const WORD ICON_HOTSPOT = 0x4242;
272 static HICON16 alloc_icon_handle( unsigned int size )
274 HGLOBAL16 handle = GlobalAlloc16( GMEM_MOVEABLE, size + sizeof(ULONG_PTR) );
275 char *ptr = GlobalLock16( handle );
276 memset( ptr + size, 0, sizeof(ULONG_PTR) );
277 GlobalUnlock16( handle );
278 FarSetOwner16( handle, 0 );
279 return handle;
282 static CURSORICONINFO *get_icon_ptr( HICON16 handle )
284 return GlobalLock16( handle );
287 static void release_icon_ptr( HICON16 handle, CURSORICONINFO *ptr )
289 GlobalUnlock16( handle );
292 static HICON store_icon_32( HICON16 icon16, HICON icon )
294 HICON ret = 0;
295 CURSORICONINFO *ptr = get_icon_ptr( icon16 );
297 if (ptr)
299 unsigned int and_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, 1 );
300 unsigned int xor_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, ptr->bBitsPerPixel );
301 if (GlobalSize16( icon16 ) >= sizeof(*ptr) + sizeof(ULONG_PTR) + and_size + xor_size )
303 memcpy( &ret, (char *)(ptr + 1) + and_size + xor_size, sizeof(ret) );
304 memcpy( (char *)(ptr + 1) + and_size + xor_size, &icon, sizeof(icon) );
305 wow_handlers32.set_icon_param( icon, icon16 );
307 release_icon_ptr( icon16, ptr );
309 return ret;
312 static int free_icon_handle( HICON16 handle )
314 HICON icon32;
316 if ((icon32 = store_icon_32( handle, 0 ))) DestroyIcon( icon32 );
317 return GlobalFree16( handle );
320 /* retrieve the 32-bit counterpart of a 16-bit icon, creating it if needed */
321 HICON get_icon_32( HICON16 icon16 )
323 HICON ret = 0;
324 CURSORICONINFO *ptr = get_icon_ptr( icon16 );
326 if (ptr)
328 unsigned int and_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, 1 );
329 unsigned int xor_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, ptr->bBitsPerPixel );
330 if (GlobalSize16( icon16 ) >= sizeof(*ptr) + sizeof(ULONG_PTR) + xor_size + and_size )
332 memcpy( &ret, (char *)(ptr + 1) + xor_size + and_size, sizeof(ret) );
333 if (!ret)
335 ICONINFO iinfo;
337 iinfo.fIcon = (ptr->ptHotSpot.x == ICON_HOTSPOT) && (ptr->ptHotSpot.y == ICON_HOTSPOT);
338 iinfo.xHotspot = ptr->ptHotSpot.x;
339 iinfo.yHotspot = ptr->ptHotSpot.y;
340 iinfo.hbmMask = CreateBitmap( ptr->nWidth, ptr->nHeight, 1, 1, ptr + 1 );
341 iinfo.hbmColor = CreateBitmap( ptr->nWidth, ptr->nHeight, ptr->bPlanes, ptr->bBitsPerPixel,
342 (char *)(ptr + 1) + and_size );
343 ret = CreateIconIndirect( &iinfo );
344 DeleteObject( iinfo.hbmMask );
345 DeleteObject( iinfo.hbmColor );
346 memcpy( (char *)(ptr + 1) + xor_size + and_size, &ret, sizeof(ret) );
347 wow_handlers32.set_icon_param( ret, icon16 );
350 release_icon_ptr( icon16, ptr );
352 return ret;
355 /* retrieve the 16-bit counterpart of a 32-bit icon, creating it if needed */
356 HICON16 get_icon_16( HICON icon )
358 HICON16 ret = wow_handlers32.get_icon_param( icon );
360 if (!ret)
362 ICONINFO info;
363 BITMAP bm;
364 UINT and_size, xor_size;
365 void *xor_bits = NULL, *and_bits;
366 CURSORICONINFO cinfo;
368 if (!(GetIconInfo( icon, &info ))) return 0;
369 GetObjectW( info.hbmMask, sizeof(bm), &bm );
370 and_size = bm.bmHeight * bm.bmWidthBytes;
371 if (!(and_bits = HeapAlloc( GetProcessHeap(), 0, and_size ))) goto done;
372 GetBitmapBits( info.hbmMask, and_size, and_bits );
373 if (info.hbmColor)
375 GetObjectW( info.hbmColor, sizeof(bm), &bm );
376 xor_size = bm.bmHeight * bm.bmWidthBytes;
377 if (!(xor_bits = HeapAlloc( GetProcessHeap(), 0, xor_size ))) goto done;
378 GetBitmapBits( info.hbmColor, xor_size, xor_bits );
380 else
382 bm.bmHeight /= 2;
383 xor_bits = (char *)and_bits + and_size / 2;
385 if (!info.fIcon)
387 cinfo.ptHotSpot.x = info.xHotspot;
388 cinfo.ptHotSpot.y = info.yHotspot;
390 else cinfo.ptHotSpot.x = cinfo.ptHotSpot.y = ICON_HOTSPOT;
392 cinfo.nWidth = bm.bmWidth;
393 cinfo.nHeight = bm.bmHeight;
394 cinfo.nWidthBytes = bm.bmWidthBytes;
395 cinfo.bPlanes = bm.bmPlanes;
396 cinfo.bBitsPerPixel = bm.bmBitsPixel;
398 if ((ret = CreateCursorIconIndirect16( 0, &cinfo, and_bits, xor_bits )))
399 store_icon_32( ret, icon );
401 done:
402 if (info.hbmColor)
404 HeapFree( GetProcessHeap(), 0, xor_bits );
405 DeleteObject( info.hbmColor );
407 HeapFree( GetProcessHeap(), 0, and_bits );
408 DeleteObject( info.hbmMask );
410 return ret;
413 static void add_shared_icon( HINSTANCE16 inst, HRSRC16 rsrc, HRSRC16 group, HICON16 icon )
415 struct cache_entry *cache = HeapAlloc( GetProcessHeap(), 0, sizeof(*cache) );
417 if (!cache) return;
418 cache->inst = inst;
419 cache->rsrc = rsrc;
420 cache->group = group;
421 cache->icon = icon;
422 cache->count = 1;
423 list_add_tail( &icon_cache, &cache->entry );
426 static HICON16 find_shared_icon( HINSTANCE16 inst, HRSRC16 rsrc )
428 struct cache_entry *cache;
430 LIST_FOR_EACH_ENTRY( cache, &icon_cache, struct cache_entry, entry )
432 if (cache->inst != inst || cache->rsrc != rsrc) continue;
433 cache->count++;
434 return cache->icon;
436 return 0;
439 static int release_shared_icon( HICON16 icon )
441 struct cache_entry *cache;
443 LIST_FOR_EACH_ENTRY( cache, &icon_cache, struct cache_entry, entry )
445 if (cache->icon != icon) continue;
446 if (!cache->count) return 0;
447 return --cache->count;
449 return -1;
452 static void free_module_icons( HINSTANCE16 inst )
454 struct cache_entry *cache, *next;
456 LIST_FOR_EACH_ENTRY_SAFE( cache, next, &icon_cache, struct cache_entry, entry )
458 if (cache->inst != inst) continue;
459 list_remove( &cache->entry );
460 free_icon_handle( cache->icon );
461 HeapFree( GetProcessHeap(), 0, cache );
465 /**********************************************************************
466 * Management of the 16-bit clipboard formats
469 struct clipboard_format
471 struct list entry;
472 UINT format;
473 HANDLE16 data;
476 static struct list clipboard_formats = LIST_INIT( clipboard_formats );
478 static void set_clipboard_format( UINT format, HANDLE16 data )
480 struct clipboard_format *fmt;
482 /* replace it if it exists already */
483 LIST_FOR_EACH_ENTRY( fmt, &clipboard_formats, struct clipboard_format, entry )
485 if (fmt->format != format) continue;
486 GlobalFree16( fmt->data );
487 fmt->data = data;
488 return;
491 if ((fmt = HeapAlloc( GetProcessHeap(), 0, sizeof(*fmt) )))
493 fmt->format = format;
494 fmt->data = data;
495 list_add_tail( &clipboard_formats, &fmt->entry );
499 static void free_clipboard_formats(void)
501 struct list *head;
503 while ((head = list_head( &clipboard_formats )))
505 struct clipboard_format *fmt = LIST_ENTRY( head, struct clipboard_format, entry );
506 list_remove( &fmt->entry );
507 GlobalFree16( fmt->data );
508 HeapFree( GetProcessHeap(), 0, fmt );
513 /**********************************************************************
514 * InitApp (USER.5)
516 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
518 /* Create task message queue */
519 return (InitThreadInput16( 0, 0 ) != 0);
523 /***********************************************************************
524 * ExitWindows (USER.7)
526 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
528 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
532 /***********************************************************************
533 * GetTimerResolution (USER.14)
535 LONG WINAPI GetTimerResolution16(void)
537 return (1000);
541 /***********************************************************************
542 * ClipCursor (USER.16)
544 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
546 RECT rect32;
548 if (!rect) return ClipCursor( NULL );
549 rect32.left = rect->left;
550 rect32.top = rect->top;
551 rect32.right = rect->right;
552 rect32.bottom = rect->bottom;
553 return ClipCursor( &rect32 );
557 /***********************************************************************
558 * GetCursorPos (USER.17)
560 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
562 POINT pos;
563 if (!pt) return FALSE;
564 GetCursorPos(&pos);
565 pt->x = pos.x;
566 pt->y = pos.y;
567 return TRUE;
571 /*******************************************************************
572 * AnyPopup (USER.52)
574 BOOL16 WINAPI AnyPopup16(void)
576 return AnyPopup();
580 /***********************************************************************
581 * SetCursor (USER.69)
583 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
585 return get_icon_16( SetCursor( get_icon_32(hCursor) ));
589 /***********************************************************************
590 * SetCursorPos (USER.70)
592 void WINAPI SetCursorPos16( INT16 x, INT16 y )
594 SetCursorPos( x, y );
598 /***********************************************************************
599 * ShowCursor (USER.71)
601 INT16 WINAPI ShowCursor16(BOOL16 bShow)
603 return ShowCursor(bShow);
607 /***********************************************************************
608 * SetRect (USER.72)
610 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
612 rect->left = left;
613 rect->right = right;
614 rect->top = top;
615 rect->bottom = bottom;
619 /***********************************************************************
620 * SetRectEmpty (USER.73)
622 void WINAPI SetRectEmpty16( LPRECT16 rect )
624 rect->left = rect->right = rect->top = rect->bottom = 0;
628 /***********************************************************************
629 * CopyRect (USER.74)
631 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
633 *dest = *src;
634 return TRUE;
638 /***********************************************************************
639 * IsRectEmpty (USER.75)
641 * Bug compat: Windows checks for 0 or negative width/height.
643 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
645 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
649 /***********************************************************************
650 * PtInRect (USER.76)
652 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
654 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
655 (pt.y >= rect->top) && (pt.y < rect->bottom));
659 /***********************************************************************
660 * OffsetRect (USER.77)
662 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
664 rect->left += x;
665 rect->right += x;
666 rect->top += y;
667 rect->bottom += y;
671 /***********************************************************************
672 * InflateRect (USER.78)
674 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
676 rect->left -= x;
677 rect->top -= y;
678 rect->right += x;
679 rect->bottom += y;
683 /***********************************************************************
684 * IntersectRect (USER.79)
686 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
687 const RECT16 *src2 )
689 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
690 (src1->left >= src2->right) || (src2->left >= src1->right) ||
691 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
693 SetRectEmpty16( dest );
694 return FALSE;
696 dest->left = max( src1->left, src2->left );
697 dest->right = min( src1->right, src2->right );
698 dest->top = max( src1->top, src2->top );
699 dest->bottom = min( src1->bottom, src2->bottom );
700 return TRUE;
704 /***********************************************************************
705 * UnionRect (USER.80)
707 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
708 const RECT16 *src2 )
710 if (IsRectEmpty16(src1))
712 if (IsRectEmpty16(src2))
714 SetRectEmpty16( dest );
715 return FALSE;
717 else *dest = *src2;
719 else
721 if (IsRectEmpty16(src2)) *dest = *src1;
722 else
724 dest->left = min( src1->left, src2->left );
725 dest->right = max( src1->right, src2->right );
726 dest->top = min( src1->top, src2->top );
727 dest->bottom = max( src1->bottom, src2->bottom );
730 return TRUE;
734 /***********************************************************************
735 * FillRect (USER.81)
736 * NOTE
737 * The Win16 variant doesn't support special color brushes like
738 * the Win32 one, despite the fact that Win16, as well as Win32,
739 * supports special background brushes for a window class.
741 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
743 HBRUSH prevBrush;
745 /* coordinates are logical so we cannot fast-check 'rect',
746 * it will be done later in the PatBlt().
749 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
750 PatBlt( HDC_32(hdc), rect->left, rect->top,
751 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
752 SelectObject( HDC_32(hdc), prevBrush );
753 return 1;
757 /***********************************************************************
758 * InvertRect (USER.82)
760 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
762 PatBlt( HDC_32(hdc), rect->left, rect->top,
763 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
767 /***********************************************************************
768 * FrameRect (USER.83)
770 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
772 RECT rect;
774 rect.left = rect16->left;
775 rect.top = rect16->top;
776 rect.right = rect16->right;
777 rect.bottom = rect16->bottom;
778 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
782 /***********************************************************************
783 * DrawIcon (USER.84)
785 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
787 return DrawIcon(HDC_32(hdc), x, y, get_icon_32(hIcon) );
791 /***********************************************************************
792 * DrawText (USER.85)
794 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
796 INT16 ret;
798 if (rect)
800 RECT rect32;
802 rect32.left = rect->left;
803 rect32.top = rect->top;
804 rect32.right = rect->right;
805 rect32.bottom = rect->bottom;
806 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
807 rect->left = rect32.left;
808 rect->top = rect32.top;
809 rect->right = rect32.right;
810 rect->bottom = rect32.bottom;
812 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
813 return ret;
817 /***********************************************************************
818 * IconSize (USER.86)
820 * See "Undocumented Windows". Used by W2.0 paint.exe.
822 DWORD WINAPI IconSize16(void)
824 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
828 /***********************************************************************
829 * AdjustWindowRect (USER.102)
831 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
833 return AdjustWindowRectEx16( rect, style, menu, 0 );
837 /***********************************************************************
838 * MessageBeep (USER.104)
840 void WINAPI MessageBeep16( UINT16 i )
842 MessageBeep( i );
846 /**************************************************************************
847 * CloseClipboard (USER.138)
849 BOOL16 WINAPI CloseClipboard16(void)
851 BOOL ret = CloseClipboard();
852 if (ret) free_clipboard_formats();
853 return ret;
857 /**************************************************************************
858 * EmptyClipboard (USER.139)
860 BOOL16 WINAPI EmptyClipboard16(void)
862 BOOL ret = EmptyClipboard();
863 if (ret) free_clipboard_formats();
864 return ret;
868 /**************************************************************************
869 * SetClipboardData (USER.141)
871 HANDLE16 WINAPI SetClipboardData16( UINT16 format, HANDLE16 data16 )
873 HANDLE data32 = 0;
875 switch (format)
877 case CF_BITMAP:
878 case CF_PALETTE:
879 data32 = HGDIOBJ_32( data16 );
880 break;
882 case CF_METAFILEPICT:
884 METAHEADER *header;
885 METAFILEPICT *pict32;
886 METAFILEPICT16 *pict16 = GlobalLock16( data16 );
888 if (pict16)
890 if (!(data32 = GlobalAlloc( GMEM_MOVEABLE, sizeof(*pict32) ))) return 0;
891 pict32 = GlobalLock( data32 );
892 pict32->mm = pict16->mm;
893 pict32->xExt = pict16->xExt;
894 pict32->yExt = pict16->yExt;
895 header = GlobalLock16( pict16->hMF );
896 pict32->hMF = SetMetaFileBitsEx( header->mtSize * 2, (BYTE *)header );
897 GlobalUnlock16( pict16->hMF );
898 GlobalUnlock( data32 );
900 set_clipboard_format( format, data16 );
901 break;
904 case CF_ENHMETAFILE:
905 FIXME( "enhmetafile not supported in 16-bit\n" );
906 return 0;
908 default:
909 if (format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST)
910 data32 = HGDIOBJ_32( data16 );
911 else if (format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST)
912 data32 = HANDLE_32( data16 );
913 else
915 UINT size = GlobalSize16( data16 );
916 void *ptr32, *ptr16 = GlobalLock16( data16 );
917 if (ptr16)
919 if (!(data32 = GlobalAlloc( GMEM_MOVEABLE, size ))) return 0;
920 ptr32 = GlobalLock( data32 );
921 memcpy( ptr32, ptr16, size );
922 GlobalUnlock( data32 );
924 set_clipboard_format( format, data16 );
926 break;
929 if (!SetClipboardData( format, data32 )) return 0;
930 return data16;
934 /**************************************************************************
935 * GetClipboardData (USER.142)
937 HANDLE16 WINAPI GetClipboardData16( UINT16 format )
939 HANDLE data32 = GetClipboardData( format );
940 HANDLE16 data16 = 0;
941 UINT size;
942 void *ptr;
944 if (!data32) return 0;
946 switch (format)
948 case CF_BITMAP:
949 case CF_PALETTE:
950 data16 = HGDIOBJ_16( data32 );
951 break;
953 case CF_METAFILEPICT:
955 METAFILEPICT16 *pict16;
956 METAFILEPICT *pict32 = GlobalLock( data32 );
958 if (pict32)
960 if (!(data16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(*pict16) ))) return 0;
961 pict16 = GlobalLock16( data16 );
962 pict16->mm = pict32->mm;
963 pict16->xExt = pict32->xExt;
964 pict16->yExt = pict32->yExt;
965 size = GetMetaFileBitsEx( pict32->hMF, 0, NULL );
966 pict16->hMF = GlobalAlloc16( GMEM_MOVEABLE, size );
967 ptr = GlobalLock16( pict16->hMF );
968 GetMetaFileBitsEx( pict32->hMF, size, ptr );
969 GlobalUnlock16( pict16->hMF );
970 GlobalUnlock16( data16 );
971 set_clipboard_format( format, data16 );
973 break;
976 case CF_ENHMETAFILE:
977 FIXME( "enhmetafile not supported in 16-bit\n" );
978 return 0;
980 default:
981 if (format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST)
982 data16 = HGDIOBJ_16( data32 );
983 else if (format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST)
984 data16 = HANDLE_16( data32 );
985 else
987 void *ptr16, *ptr32 = GlobalLock( data32 );
988 if (ptr32)
990 size = GlobalSize( data32 );
991 if (!(data16 = GlobalAlloc16( GMEM_MOVEABLE, size ))) return 0;
992 ptr16 = GlobalLock16( data16 );
993 memcpy( ptr16, ptr32, size );
994 GlobalUnlock16( data16 );
995 set_clipboard_format( format, data16 );
998 break;
1000 return data16;
1004 /**************************************************************************
1005 * CountClipboardFormats (USER.143)
1007 INT16 WINAPI CountClipboardFormats16(void)
1009 return CountClipboardFormats();
1013 /**************************************************************************
1014 * EnumClipboardFormats (USER.144)
1016 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
1018 return EnumClipboardFormats( id );
1022 /**************************************************************************
1023 * RegisterClipboardFormat (USER.145)
1025 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
1027 return RegisterClipboardFormatA( name );
1031 /**************************************************************************
1032 * GetClipboardFormatName (USER.146)
1034 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
1036 return GetClipboardFormatNameA( id, buffer, maxlen );
1040 /**********************************************************************
1041 * LoadMenu (USER.150)
1043 HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, LPCSTR name )
1045 HRSRC16 hRsrc;
1046 HGLOBAL16 handle;
1047 HMENU16 hMenu;
1049 if (HIWORD(name) && name[0] == '#') name = ULongToPtr(atoi( name + 1 ));
1050 if (!name) return 0;
1052 instance = GetExePtr( instance );
1053 if (!(hRsrc = FindResource16( instance, name, (LPSTR)RT_MENU ))) return 0;
1054 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
1055 hMenu = LoadMenuIndirect16(LockResource16(handle));
1056 FreeResource16( handle );
1057 return hMenu;
1061 /**********************************************************************
1062 * CreateMenu (USER.151)
1064 HMENU16 WINAPI CreateMenu16(void)
1066 return HMENU_16( CreateMenu() );
1070 /**********************************************************************
1071 * DestroyMenu (USER.152)
1073 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
1075 return DestroyMenu( HMENU_32(hMenu) );
1079 /*******************************************************************
1080 * ChangeMenu (USER.153)
1082 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
1083 UINT16 id, UINT16 flags )
1085 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
1087 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
1088 /* for MF_DELETE. We should check the parameters for all others */
1089 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
1091 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
1092 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
1093 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
1094 flags & ~MF_REMOVE );
1095 /* Default: MF_INSERT */
1096 return InsertMenu16( hMenu, pos, flags, id, data );
1100 /*******************************************************************
1101 * CheckMenuItem (USER.154)
1103 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
1105 return CheckMenuItem( HMENU_32(hMenu), id, flags );
1109 /**********************************************************************
1110 * EnableMenuItem (USER.155)
1112 BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
1114 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
1118 /**********************************************************************
1119 * GetSubMenu (USER.159)
1121 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
1123 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
1127 /*******************************************************************
1128 * GetMenuString (USER.161)
1130 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
1131 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
1133 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
1137 /**********************************************************************
1138 * WinHelp (USER.171)
1140 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
1141 DWORD dwData )
1143 BOOL ret;
1144 DWORD mutex_count;
1146 /* We might call WinExec() */
1147 ReleaseThunkLock(&mutex_count);
1149 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
1151 RestoreThunkLock(mutex_count);
1152 return ret;
1156 /***********************************************************************
1157 * LoadCursor (USER.173)
1159 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
1161 return LoadImage16( hInstance, name, IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE );
1165 /***********************************************************************
1166 * LoadIcon (USER.174)
1168 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
1170 return LoadImage16( hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE );
1173 /**********************************************************************
1174 * LoadBitmap (USER.175)
1176 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
1178 return LoadImage16( hInstance, name, IMAGE_BITMAP, 0, 0, 0 );
1181 /**********************************************************************
1182 * LoadString (USER.176)
1184 INT16 WINAPI LoadString16( HINSTANCE16 instance, UINT16 resource_id, LPSTR buffer, INT16 buflen )
1186 HGLOBAL16 hmem;
1187 HRSRC16 hrsrc;
1188 unsigned char *p;
1189 int string_num;
1190 int ret;
1192 TRACE("inst=%04x id=%04x buff=%p len=%d\n", instance, resource_id, buffer, buflen);
1194 hrsrc = FindResource16( instance, MAKEINTRESOURCEA((resource_id>>4)+1), (LPSTR)RT_STRING );
1195 if (!hrsrc) return 0;
1196 hmem = LoadResource16( instance, hrsrc );
1197 if (!hmem) return 0;
1199 p = LockResource16(hmem);
1200 string_num = resource_id & 0x000f;
1201 while (string_num--) p += *p + 1;
1203 if (buffer == NULL) ret = *p;
1204 else
1206 ret = min(buflen - 1, *p);
1207 if (ret > 0)
1209 memcpy(buffer, p + 1, ret);
1210 buffer[ret] = '\0';
1212 else if (buflen > 1)
1214 buffer[0] = '\0';
1215 ret = 0;
1217 TRACE( "%s loaded\n", debugstr_a(buffer));
1219 FreeResource16( hmem );
1220 return ret;
1223 /**********************************************************************
1224 * LoadAccelerators (USER.177)
1226 HACCEL16 WINAPI LoadAccelerators16(HINSTANCE16 instance, LPCSTR lpTableName)
1228 HRSRC16 hRsrc;
1229 HGLOBAL16 hMem;
1230 ACCEL16 *table16;
1231 HACCEL ret = 0;
1233 TRACE("%04x %s\n", instance, debugstr_a(lpTableName) );
1235 if (!(hRsrc = FindResource16( instance, lpTableName, (LPSTR)RT_ACCELERATOR )) ||
1236 !(hMem = LoadResource16(instance,hRsrc)))
1238 WARN("couldn't find %04x %s\n", instance, debugstr_a(lpTableName));
1239 return 0;
1241 if ((table16 = LockResource16( hMem )))
1243 DWORD i, count = SizeofResource16( instance, hRsrc ) / sizeof(*table16);
1244 ACCEL *table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
1245 if (table)
1247 for (i = 0; i < count; i++)
1249 table[i].fVirt = table16[i].fVirt & 0x7f;
1250 table[i].key = table16[i].key;
1251 table[i].cmd = table16[i].cmd;
1253 ret = CreateAcceleratorTableA( table, count );
1254 HeapFree( GetProcessHeap(), 0, table );
1257 FreeResource16( hMem );
1258 return HACCEL_16(ret);
1261 /***********************************************************************
1262 * GetSystemMetrics (USER.179)
1264 INT16 WINAPI GetSystemMetrics16( INT16 index )
1266 return GetSystemMetrics( index );
1270 /*************************************************************************
1271 * GetSysColor (USER.180)
1273 COLORREF WINAPI GetSysColor16( INT16 index )
1275 return GetSysColor( index );
1279 /*************************************************************************
1280 * SetSysColors (USER.181)
1282 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
1284 INT i, *list;
1286 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
1288 for (i = 0; i < count; i++) list[i] = list16[i];
1289 SetSysColors( count, list, values );
1290 HeapFree( GetProcessHeap(), 0, list );
1295 /***********************************************************************
1296 * GrayString (USER.185)
1298 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
1299 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
1300 INT16 cx, INT16 cy )
1302 BOOL ret;
1304 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
1305 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
1307 if (cch == -1 || (cch && cx && cy))
1309 /* lParam can be treated as an opaque pointer */
1310 struct gray_string_info info;
1312 info.proc = gsprc;
1313 info.param = lParam;
1314 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
1315 (LPARAM)&info, cch, x, y, cx, cy );
1317 else /* here we need some string conversions */
1319 char *str16 = MapSL(lParam);
1320 struct gray_string_info *info;
1322 if (!cch) cch = strlen(str16);
1323 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( struct gray_string_info, str[cch] ));
1324 if (!info) return FALSE;
1325 info->proc = gsprc;
1326 info->param = lParam;
1327 memcpy( info->str, str16, cch );
1328 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
1329 (LPARAM)info->str, cch, x, y, cx, cy );
1330 HeapFree( GetProcessHeap(), 0, info );
1332 return ret;
1336 /***********************************************************************
1337 * SwapMouseButton (USER.186)
1339 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
1341 return SwapMouseButton( fSwap );
1345 /**************************************************************************
1346 * IsClipboardFormatAvailable (USER.193)
1348 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
1350 return IsClipboardFormatAvailable( wFormat );
1354 /***********************************************************************
1355 * TabbedTextOut (USER.196)
1357 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
1358 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
1360 LONG ret;
1361 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(*tabs) );
1362 if (!tabs) return 0;
1363 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
1364 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
1365 HeapFree( GetProcessHeap(), 0, tabs );
1366 return ret;
1370 /***********************************************************************
1371 * GetTabbedTextExtent (USER.197)
1373 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
1374 INT16 nb_tabs, const INT16 *tabs16 )
1376 LONG ret;
1377 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(*tabs) );
1378 if (!tabs) return 0;
1379 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
1380 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
1381 HeapFree( GetProcessHeap(), 0, tabs );
1382 return ret;
1386 /***********************************************************************
1387 * UserSeeUserDo (USER.216)
1389 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
1391 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
1392 HANDLE16 oldDS = stack16->ds;
1393 DWORD ret = (DWORD)-1;
1395 stack16->ds = USER_HeapSel;
1396 switch (wReqType)
1398 case USUD_LOCALALLOC:
1399 ret = LocalAlloc16(wParam1, wParam3);
1400 break;
1401 case USUD_LOCALFREE:
1402 ret = LocalFree16(wParam1);
1403 break;
1404 case USUD_LOCALCOMPACT:
1405 ret = LocalCompact16(wParam3);
1406 break;
1407 case USUD_LOCALHEAP:
1408 ret = USER_HeapSel;
1409 break;
1410 case USUD_FIRSTCLASS:
1411 FIXME("return a pointer to the first window class.\n");
1412 break;
1413 default:
1414 WARN("wReqType %04x (unknown)\n", wReqType);
1416 stack16->ds = oldDS;
1417 return ret;
1421 /***********************************************************************
1422 * LookupMenuHandle (USER.217)
1424 HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
1426 FIXME( "%04x %04x: stub\n", hmenu, id );
1427 return hmenu;
1431 static LPCSTR parse_menu_resource( LPCSTR res, HMENU hMenu, BOOL oldFormat )
1433 WORD flags, id = 0;
1434 LPCSTR str;
1435 BOOL end_flag;
1439 /* Windows 3.00 and later use a WORD for the flags, whereas 1.x and 2.x use a BYTE. */
1440 if (oldFormat)
1442 flags = GET_BYTE(res);
1443 res += sizeof(BYTE);
1445 else
1447 flags = GET_WORD(res);
1448 res += sizeof(WORD);
1451 end_flag = flags & MF_END;
1452 /* Remove MF_END because it has the same value as MF_HILITE */
1453 flags &= ~MF_END;
1454 if (!(flags & MF_POPUP))
1456 id = GET_WORD(res);
1457 res += sizeof(WORD);
1459 str = res;
1460 res += strlen(str) + 1;
1461 if (flags & MF_POPUP)
1463 HMENU hSubMenu = CreatePopupMenu();
1464 if (!hSubMenu) return NULL;
1465 if (!(res = parse_menu_resource( res, hSubMenu, oldFormat ))) return NULL;
1466 AppendMenuA( hMenu, flags, (UINT_PTR)hSubMenu, str );
1468 else /* Not a popup */
1470 AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1472 } while (!end_flag);
1473 return res;
1476 /**********************************************************************
1477 * LoadMenuIndirect (USER.220)
1479 HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
1481 BOOL oldFormat;
1482 HMENU hMenu;
1483 WORD version, offset;
1484 LPCSTR p = template;
1486 TRACE("(%p)\n", template );
1488 /* Windows 1.x and 2.x menus have a slightly different menu format from 3.x menus */
1489 oldFormat = (GetExeVersion16() < 0x0300);
1491 /* Windows 3.00 and later menu items are preceded by a MENUITEMTEMPLATEHEADER structure */
1492 if (!oldFormat)
1494 version = GET_WORD(p);
1495 p += sizeof(WORD);
1496 if (version)
1498 WARN("version must be 0 for Win16 >= 3.00 applications\n" );
1499 return 0;
1501 offset = GET_WORD(p);
1502 p += sizeof(WORD) + offset;
1505 if (!(hMenu = CreateMenu())) return 0;
1506 if (!parse_menu_resource( p, hMenu, oldFormat ))
1508 DestroyMenu( hMenu );
1509 return 0;
1511 return HMENU_16(hMenu);
1515 /*************************************************************************
1516 * ScrollDC (USER.221)
1518 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
1519 const RECT16 *cliprc, HRGN16 hrgnUpdate,
1520 LPRECT16 rcUpdate )
1522 RECT rect32, clipRect32, rcUpdate32;
1523 BOOL16 ret;
1525 if (rect)
1527 rect32.left = rect->left;
1528 rect32.top = rect->top;
1529 rect32.right = rect->right;
1530 rect32.bottom = rect->bottom;
1532 if (cliprc)
1534 clipRect32.left = cliprc->left;
1535 clipRect32.top = cliprc->top;
1536 clipRect32.right = cliprc->right;
1537 clipRect32.bottom = cliprc->bottom;
1539 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
1540 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
1541 &rcUpdate32 );
1542 if (rcUpdate)
1544 rcUpdate->left = rcUpdate32.left;
1545 rcUpdate->top = rcUpdate32.top;
1546 rcUpdate->right = rcUpdate32.right;
1547 rcUpdate->bottom = rcUpdate32.bottom;
1549 return ret;
1553 /***********************************************************************
1554 * GetSystemDebugState (USER.231)
1556 WORD WINAPI GetSystemDebugState16(void)
1558 return 0; /* FIXME */
1562 /***********************************************************************
1563 * EqualRect (USER.244)
1565 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
1567 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1568 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1572 /***********************************************************************
1573 * ExitWindowsExec (USER.246)
1575 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
1577 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
1578 lpszExe, lpszParams);
1579 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
1583 /***********************************************************************
1584 * GetCursor (USER.247)
1586 HCURSOR16 WINAPI GetCursor16(void)
1588 return get_icon_16( GetCursor() );
1592 /**********************************************************************
1593 * GetAsyncKeyState (USER.249)
1595 INT16 WINAPI GetAsyncKeyState16( INT16 key )
1597 return GetAsyncKeyState( key );
1601 /**********************************************************************
1602 * GetMenuState (USER.250)
1604 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
1606 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
1610 /**************************************************************************
1611 * SendDriverMessage (USER.251)
1613 LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
1614 LPARAM lParam2)
1616 FIXME("(%04x, %04x, %08lx, %08lx): stub\n", hDriver, msg, lParam1, lParam2);
1617 return 0;
1621 /**************************************************************************
1622 * OpenDriver (USER.252)
1624 HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2)
1626 FIXME( "(%s, %s, %08lx): stub\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
1627 return 0;
1631 /**************************************************************************
1632 * CloseDriver (USER.253)
1634 LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
1636 FIXME( "(%04x, %08lx, %08lx): stub\n", hDrvr, lParam1, lParam2);
1637 return FALSE;
1641 /**************************************************************************
1642 * GetDriverModuleHandle (USER.254)
1644 HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr)
1646 FIXME("(%04x): stub\n", hDrvr);
1647 return 0;
1651 /**************************************************************************
1652 * DefDriverProc (USER.255)
1654 LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg,
1655 LPARAM lParam1, LPARAM lParam2)
1657 FIXME( "devID=0x%08x hDrv=0x%04x wMsg=%04x lP1=0x%08lx lP2=0x%08lx: stub\n",
1658 dwDevID, hDriv, wMsg, lParam1, lParam2);
1659 return 0;
1663 /**************************************************************************
1664 * GetDriverInfo (USER.256)
1666 struct DRIVERINFOSTRUCT16;
1667 BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, struct DRIVERINFOSTRUCT16 *lpDrvInfo)
1669 FIXME( "(%04x, %p): stub\n", hDrvr, lpDrvInfo);
1670 return FALSE;
1674 /**************************************************************************
1675 * GetNextDriver (USER.257)
1677 HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags)
1679 FIXME( "(%04x, %08x): stub\n", hDrvr, dwFlags);
1680 return 0;
1684 /**********************************************************************
1685 * GetMenuItemCount (USER.263)
1687 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
1689 return GetMenuItemCount( HMENU_32(hMenu) );
1693 /**********************************************************************
1694 * GetMenuItemID (USER.264)
1696 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
1698 return GetMenuItemID( HMENU_32(hMenu), nPos );
1702 /***********************************************************************
1703 * GlobalAddAtom (USER.268)
1705 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
1707 return GlobalAddAtomA(lpString);
1710 /***********************************************************************
1711 * GlobalDeleteAtom (USER.269)
1713 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
1715 return GlobalDeleteAtom(nAtom);
1718 /***********************************************************************
1719 * GlobalFindAtom (USER.270)
1721 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
1723 return GlobalFindAtomA(lpString);
1726 /***********************************************************************
1727 * GlobalGetAtomName (USER.271)
1729 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
1731 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
1735 /***********************************************************************
1736 * ControlPanelInfo (USER.273)
1738 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
1740 FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
1744 /***********************************************************************
1745 * OldSetDeskPattern (USER.279)
1747 BOOL16 WINAPI SetDeskPattern16(void)
1749 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
1753 /***********************************************************************
1754 * GetSysColorBrush (USER.281)
1756 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
1758 return HBRUSH_16( GetSysColorBrush(index) );
1762 /***********************************************************************
1763 * SelectPalette (USER.282)
1765 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
1767 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
1770 /***********************************************************************
1771 * RealizePalette (USER.283)
1773 UINT16 WINAPI RealizePalette16( HDC16 hdc )
1775 return UserRealizePalette( HDC_32(hdc) );
1779 /***********************************************************************
1780 * GetFreeSystemResources (USER.284)
1782 WORD WINAPI GetFreeSystemResources16( WORD resType )
1784 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
1785 HANDLE16 oldDS = stack16->ds;
1786 int userPercent, gdiPercent;
1788 switch(resType)
1790 case GFSR_USERRESOURCES:
1791 stack16->ds = USER_HeapSel;
1792 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1793 gdiPercent = 100;
1794 stack16->ds = oldDS;
1795 break;
1797 case GFSR_GDIRESOURCES:
1798 stack16->ds = gdi_inst;
1799 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1800 userPercent = 100;
1801 stack16->ds = oldDS;
1802 break;
1804 case GFSR_SYSTEMRESOURCES:
1805 stack16->ds = USER_HeapSel;
1806 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1807 stack16->ds = gdi_inst;
1808 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1809 stack16->ds = oldDS;
1810 break;
1812 default:
1813 userPercent = gdiPercent = 0;
1814 break;
1816 TRACE("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
1817 return (WORD)min( userPercent, gdiPercent );
1821 /***********************************************************************
1822 * SetDeskWallPaper (USER.285)
1824 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
1826 return SetDeskWallPaper( filename );
1830 /***********************************************************************
1831 * keybd_event (USER.289)
1833 void WINAPI keybd_event16( CONTEXT *context )
1835 DWORD dwFlags = 0;
1837 if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
1838 if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;
1840 keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
1841 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
1845 /***********************************************************************
1846 * mouse_event (USER.299)
1848 void WINAPI mouse_event16( CONTEXT *context )
1850 mouse_event( LOWORD(context->Eax), LOWORD(context->Ebx), LOWORD(context->Ecx),
1851 LOWORD(context->Edx), MAKELONG(context->Esi, context->Edi) );
1855 /***********************************************************************
1856 * GetClipCursor (USER.309)
1858 void WINAPI GetClipCursor16( RECT16 *rect )
1860 if (rect)
1862 RECT rect32;
1863 GetClipCursor( &rect32 );
1864 rect->left = rect32.left;
1865 rect->top = rect32.top;
1866 rect->right = rect32.right;
1867 rect->bottom = rect32.bottom;
1872 /***********************************************************************
1873 * SignalProc (USER.314)
1875 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
1876 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
1878 if (code == USIG16_DLL_UNLOAD)
1880 hModule = GetExePtr(hModule);
1881 /* HOOK_FreeModuleHooks( hModule ); */
1882 free_module_classes( hModule );
1883 free_module_icons( hModule );
1888 /***********************************************************************
1889 * SetEventHook (USER.321)
1891 * Used by Turbo Debugger for Windows
1893 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
1895 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
1896 return 0;
1900 /**********************************************************************
1901 * EnableHardwareInput (USER.331)
1903 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
1905 FIXME("(%d) - stub\n", bEnable);
1906 return TRUE;
1910 /**********************************************************************
1911 * LoadCursorIconHandler (USER.336)
1913 * Supposed to load resources of Windows 2.x applications.
1915 HGLOBAL16 WINAPI LoadCursorIconHandler16( HGLOBAL16 hResource, HMODULE16 hModule, HRSRC16 hRsrc )
1917 FIXME("(%04x,%04x,%04x): old 2.x resources are not supported!\n", hResource, hModule, hRsrc);
1918 return 0;
1922 /***********************************************************************
1923 * GetMouseEventProc (USER.337)
1925 FARPROC16 WINAPI GetMouseEventProc16(void)
1927 HMODULE16 hmodule = GetModuleHandle16("USER");
1928 return GetProcAddress16( hmodule, "mouse_event" );
1932 /***********************************************************************
1933 * IsUserIdle (USER.333)
1935 BOOL16 WINAPI IsUserIdle16(void)
1937 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
1938 return FALSE;
1939 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
1940 return FALSE;
1941 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
1942 return FALSE;
1943 /* Should check for screen saver activation here ... */
1944 return TRUE;
1948 /**********************************************************************
1949 * LoadDIBIconHandler (USER.357)
1951 * RT_ICON resource loader, installed by USER_SignalProc when module
1952 * is initialized.
1954 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1956 /* If hResource is zero we must allocate a new memory block, if it's
1957 * non-zero but GlobalLock() returns NULL then it was discarded and
1958 * we have to recommit some memory, otherwise we just need to check
1959 * the block size. See LoadProc() in 16-bit SDK for more.
1961 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1962 return 0;
1965 /**********************************************************************
1966 * LoadDIBCursorHandler (USER.356)
1968 * RT_CURSOR resource loader. Same as above.
1970 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1972 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1973 return 0;
1977 /**********************************************************************
1978 * IsMenu (USER.358)
1980 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
1982 return IsMenu( HMENU_32(hmenu) );
1986 /***********************************************************************
1987 * DCHook (USER.362)
1989 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1991 FIXME( "hDC = %x, %i: stub\n", hdc, code );
1992 return FALSE;
1996 /**********************************************************************
1997 * LookupIconIdFromDirectoryEx (USER.364)
1999 * FIXME: exact parameter sizes
2001 INT16 WINAPI LookupIconIdFromDirectoryEx16( LPBYTE dir, BOOL16 bIcon,
2002 INT16 width, INT16 height, UINT16 cFlag )
2004 return LookupIconIdFromDirectoryEx( dir, bIcon, width, height, cFlag );
2008 /***********************************************************************
2009 * CopyIcon (USER.368)
2011 HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
2013 CURSORICONINFO *info = get_icon_ptr( hIcon );
2014 void *and_bits = info + 1;
2015 void *xor_bits = (BYTE *)and_bits + info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2016 HGLOBAL16 ret = CreateCursorIconIndirect16( hInstance, info, and_bits, xor_bits );
2017 release_icon_ptr( hIcon, info );
2018 return ret;
2022 /***********************************************************************
2023 * CopyCursor (USER.369)
2025 HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
2027 CURSORICONINFO *info = get_icon_ptr( hCursor );
2028 void *and_bits = info + 1;
2029 void *xor_bits = (BYTE *)and_bits + info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2030 HGLOBAL16 ret = CreateCursorIconIndirect16( hInstance, info, and_bits, xor_bits );
2031 release_icon_ptr( hCursor, info );
2032 return ret;
2036 /***********************************************************************
2037 * SubtractRect (USER.373)
2039 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
2040 const RECT16 *src2 )
2042 RECT16 tmp;
2044 if (IsRectEmpty16( src1 ))
2046 SetRectEmpty16( dest );
2047 return FALSE;
2049 *dest = *src1;
2050 if (IntersectRect16( &tmp, src1, src2 ))
2052 if (EqualRect16( &tmp, dest ))
2054 SetRectEmpty16( dest );
2055 return FALSE;
2057 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
2059 if (tmp.left == dest->left) dest->left = tmp.right;
2060 else if (tmp.right == dest->right) dest->right = tmp.left;
2062 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
2064 if (tmp.top == dest->top) dest->top = tmp.bottom;
2065 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
2068 return TRUE;
2072 /**********************************************************************
2073 * DllEntryPoint (USER.374)
2075 BOOL WINAPI DllEntryPoint( DWORD reason, HINSTANCE16 inst, WORD ds,
2076 WORD heap, DWORD reserved1, WORD reserved2 )
2078 if (reason != DLL_PROCESS_ATTACH) return TRUE;
2079 if (USER_HeapSel) return TRUE; /* already called */
2081 USER_HeapSel = ds;
2082 register_wow_handlers();
2083 gdi_inst = LoadLibrary16( "gdi.exe" );
2084 LoadLibrary16( "display.drv" );
2085 LoadLibrary16( "keyboard.drv" );
2086 LoadLibrary16( "mouse.drv" );
2087 LoadLibrary16( "user.exe" ); /* make sure it never gets unloaded */
2088 return TRUE;
2092 /**********************************************************************
2093 * SetMenuContextHelpId (USER.384)
2095 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
2097 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
2101 /**********************************************************************
2102 * GetMenuContextHelpId (USER.385)
2104 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
2106 return GetMenuContextHelpId( HMENU_32(hMenu) );
2110 /***********************************************************************
2111 * LoadImage (USER.389)
2113 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type, INT16 cx, INT16 cy, UINT16 flags)
2115 HGLOBAL16 handle;
2116 HRSRC16 hRsrc, hGroupRsrc;
2117 DWORD size;
2119 if (!hinst || (flags & LR_LOADFROMFILE))
2121 if (type == IMAGE_BITMAP)
2122 return HBITMAP_16( LoadImageA( 0, name, type, cx, cy, flags ));
2123 else
2124 return get_icon_16( LoadImageA( 0, name, type, cx, cy, flags ));
2127 hinst = GetExePtr( hinst );
2129 if (flags & LR_DEFAULTSIZE)
2131 if (type == IMAGE_ICON)
2133 if (!cx) cx = GetSystemMetrics(SM_CXICON);
2134 if (!cy) cy = GetSystemMetrics(SM_CYICON);
2136 else if (type == IMAGE_CURSOR)
2138 if (!cx) cx = GetSystemMetrics(SM_CXCURSOR);
2139 if (!cy) cy = GetSystemMetrics(SM_CYCURSOR);
2143 switch (type)
2145 case IMAGE_BITMAP:
2147 HBITMAP ret = 0;
2148 char *ptr;
2149 static const WCHAR prefixW[] = {'b','m','p',0};
2150 BITMAPFILEHEADER header;
2151 WCHAR path[MAX_PATH], filename[MAX_PATH];
2152 HANDLE file;
2154 filename[0] = 0;
2155 if (!(hRsrc = FindResource16( hinst, name, (LPCSTR)RT_BITMAP ))) return 0;
2156 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2157 if (!(ptr = LockResource16( handle ))) goto done;
2158 size = SizeofResource16( hinst, hRsrc );
2160 header.bfType = 0x4d42; /* 'BM' */
2161 header.bfReserved1 = 0;
2162 header.bfReserved2 = 0;
2163 header.bfSize = sizeof(header) + size;
2164 header.bfOffBits = 0; /* not used by the 32-bit loading code */
2166 if (!GetTempPathW( MAX_PATH, path )) goto done;
2167 if (!GetTempFileNameW( path, prefixW, 0, filename )) goto done;
2169 file = CreateFileW( filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
2170 if (file != INVALID_HANDLE_VALUE)
2172 DWORD written;
2173 BOOL ok;
2174 ok = WriteFile( file, &header, sizeof(header), &written, NULL ) && (written == sizeof(header));
2175 if (ok) ok = WriteFile( file, ptr, size, &written, NULL ) && (written == size);
2176 CloseHandle( file );
2177 if (ok) ret = LoadImageW( 0, filename, IMAGE_BITMAP, cx, cy, flags | LR_LOADFROMFILE );
2179 done:
2180 if (filename[0]) DeleteFileW( filename );
2181 FreeResource16( handle );
2182 return HBITMAP_16( ret );
2185 case IMAGE_ICON:
2186 case IMAGE_CURSOR:
2188 HICON16 hIcon = 0;
2189 BYTE *dir, *bits;
2190 INT id = 0;
2192 if (!(hRsrc = FindResource16( hinst, name,
2193 (LPCSTR)(type == IMAGE_ICON ? RT_GROUP_ICON : RT_GROUP_CURSOR ))))
2194 return 0;
2195 hGroupRsrc = hRsrc;
2197 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2198 if ((dir = LockResource16( handle ))) id = LookupIconIdFromDirectory( dir, type == IMAGE_ICON );
2199 FreeResource16( handle );
2200 if (!id) return 0;
2202 if (!(hRsrc = FindResource16( hinst, MAKEINTRESOURCEA(id),
2203 (LPCSTR)(type == IMAGE_ICON ? RT_ICON : RT_CURSOR) ))) return 0;
2205 if ((flags & LR_SHARED) && (hIcon = find_shared_icon( hinst, hRsrc ) ) != 0) return hIcon;
2207 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2208 bits = LockResource16( handle );
2209 size = SizeofResource16( hinst, hRsrc );
2210 hIcon = CreateIconFromResourceEx16( bits, size, type == IMAGE_ICON, 0x00030000, cx, cy, flags );
2211 FreeResource16( handle );
2213 if (hIcon && (flags & LR_SHARED)) add_shared_icon( hinst, hRsrc, hGroupRsrc, hIcon );
2214 return hIcon;
2216 default:
2217 return 0;
2221 /******************************************************************************
2222 * CopyImage (USER.390) Creates new image and copies attributes to it
2225 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
2226 INT16 desiredy, UINT16 flags)
2228 if (flags & LR_COPYFROMRESOURCE) FIXME( "LR_COPYFROMRESOURCE not supported\n" );
2230 switch (type)
2232 case IMAGE_BITMAP:
2233 return HBITMAP_16( CopyImage( HBITMAP_32(hnd), type, desiredx, desiredy, flags ));
2234 case IMAGE_ICON:
2235 case IMAGE_CURSOR:
2236 return CopyIcon16( FarGetOwner16(hnd), hnd );
2237 default:
2238 return 0;
2242 /**********************************************************************
2243 * DrawIconEx (USER.394)
2245 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
2246 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
2247 HBRUSH16 hbr, UINT16 flags)
2249 return DrawIconEx(HDC_32(hdc), xLeft, yTop, get_icon_32(hIcon), cxWidth, cyWidth,
2250 istep, HBRUSH_32(hbr), flags);
2253 /**********************************************************************
2254 * GetIconInfo (USER.395)
2256 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
2258 CURSORICONINFO *info = get_icon_ptr( hIcon );
2259 INT height;
2261 if (!info) return FALSE;
2263 if ((info->ptHotSpot.x == ICON_HOTSPOT) && (info->ptHotSpot.y == ICON_HOTSPOT))
2265 iconinfo->fIcon = TRUE;
2266 iconinfo->xHotspot = info->nWidth / 2;
2267 iconinfo->yHotspot = info->nHeight / 2;
2269 else
2271 iconinfo->fIcon = FALSE;
2272 iconinfo->xHotspot = info->ptHotSpot.x;
2273 iconinfo->yHotspot = info->ptHotSpot.y;
2276 height = info->nHeight;
2278 if (info->bBitsPerPixel > 1)
2280 iconinfo->hbmColor = HBITMAP_16( CreateBitmap( info->nWidth, info->nHeight,
2281 info->bPlanes, info->bBitsPerPixel,
2282 (char *)(info + 1)
2283 + info->nHeight *
2284 get_bitmap_width_bytes(info->nWidth,1) ));
2286 else
2288 iconinfo->hbmColor = 0;
2289 height *= 2;
2292 iconinfo->hbmMask = HBITMAP_16( CreateBitmap( info->nWidth, height, 1, 1, info + 1 ));
2293 release_icon_ptr( hIcon, info );
2294 return TRUE;
2298 /***********************************************************************
2299 * FinalUserInit (USER.400)
2301 void WINAPI FinalUserInit16( void )
2303 /* FIXME: Should chain to FinalGdiInit */
2307 /***********************************************************************
2308 * CreateCursor (USER.406)
2310 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
2311 INT16 xHotSpot, INT16 yHotSpot,
2312 INT16 nWidth, INT16 nHeight,
2313 LPCVOID lpANDbits, LPCVOID lpXORbits)
2315 CURSORICONINFO info;
2317 info.ptHotSpot.x = xHotSpot;
2318 info.ptHotSpot.y = yHotSpot;
2319 info.nWidth = nWidth;
2320 info.nHeight = nHeight;
2321 info.nWidthBytes = 0;
2322 info.bPlanes = 1;
2323 info.bBitsPerPixel = 1;
2325 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
2329 /***********************************************************************
2330 * CreateIcon (USER.407)
2332 HICON16 WINAPI CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth,
2333 INT16 nHeight, BYTE bPlanes, BYTE bBitsPixel,
2334 LPCVOID lpANDbits, LPCVOID lpXORbits )
2336 CURSORICONINFO info;
2338 info.ptHotSpot.x = ICON_HOTSPOT;
2339 info.ptHotSpot.y = ICON_HOTSPOT;
2340 info.nWidth = nWidth;
2341 info.nHeight = nHeight;
2342 info.nWidthBytes = 0;
2343 info.bPlanes = bPlanes;
2344 info.bBitsPerPixel = bBitsPixel;
2346 return CreateCursorIconIndirect16( hInstance, &info, lpANDbits, lpXORbits );
2350 /***********************************************************************
2351 * CreateCursorIconIndirect (USER.408)
2353 HGLOBAL16 WINAPI CreateCursorIconIndirect16( HINSTANCE16 hInstance,
2354 CURSORICONINFO *info,
2355 LPCVOID lpANDbits,
2356 LPCVOID lpXORbits )
2358 HICON16 handle;
2359 CURSORICONINFO *ptr;
2360 int sizeAnd, sizeXor;
2362 hInstance = GetExePtr( hInstance ); /* Make it a module handle */
2363 if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
2364 info->nWidthBytes = get_bitmap_width_bytes(info->nWidth,info->bBitsPerPixel);
2365 sizeXor = info->nHeight * info->nWidthBytes;
2366 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2367 if (!(handle = alloc_icon_handle( sizeof(CURSORICONINFO) + sizeXor + sizeAnd )))
2368 return 0;
2369 FarSetOwner16( handle, hInstance );
2370 ptr = get_icon_ptr( handle );
2371 memcpy( ptr, info, sizeof(*info) );
2372 memcpy( ptr + 1, lpANDbits, sizeAnd );
2373 memcpy( (char *)(ptr + 1) + sizeAnd, lpXORbits, sizeXor );
2374 release_icon_ptr( handle, ptr );
2375 return handle;
2379 /***********************************************************************
2380 * InitThreadInput (USER.409)
2382 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
2384 /* nothing to do here */
2385 return 0xbeef;
2389 /*******************************************************************
2390 * InsertMenu (USER.410)
2392 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
2393 UINT16 id, SEGPTR data )
2395 UINT pos32 = (UINT)pos;
2396 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
2397 if (IS_MENU_STRING_ITEM(flags) && data)
2398 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
2399 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
2403 /*******************************************************************
2404 * AppendMenu (USER.411)
2406 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
2408 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
2412 /**********************************************************************
2413 * RemoveMenu (USER.412)
2415 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
2417 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
2421 /**********************************************************************
2422 * DeleteMenu (USER.413)
2424 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
2426 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
2430 /*******************************************************************
2431 * ModifyMenu (USER.414)
2433 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
2434 UINT16 id, SEGPTR data )
2436 if (IS_MENU_STRING_ITEM(flags))
2437 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
2438 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
2442 /**********************************************************************
2443 * CreatePopupMenu (USER.415)
2445 HMENU16 WINAPI CreatePopupMenu16(void)
2447 return HMENU_16( CreatePopupMenu() );
2451 /**********************************************************************
2452 * SetMenuItemBitmaps (USER.418)
2454 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
2455 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
2457 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
2458 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
2462 /***********************************************************************
2463 * wvsprintf (USER.421)
2465 INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 args )
2467 WPRINTF_FORMAT format;
2468 LPSTR p = buffer;
2469 UINT i, len, sign;
2470 CHAR number[20];
2471 CHAR char_view = 0;
2472 LPCSTR lpcstr_view = NULL;
2473 INT int_view;
2474 SEGPTR seg_str;
2476 while (*spec)
2478 if (*spec != '%') { *p++ = *spec++; continue; }
2479 spec++;
2480 if (*spec == '%') { *p++ = *spec++; continue; }
2481 spec += parse_format( spec, &format );
2482 switch(format.type)
2484 case WPR_CHAR:
2485 char_view = VA_ARG16( args, CHAR );
2486 len = format.precision = 1;
2487 break;
2488 case WPR_STRING:
2489 seg_str = VA_ARG16( args, SEGPTR );
2490 if (IsBadReadPtr16( seg_str, 1 )) lpcstr_view = "";
2491 else lpcstr_view = MapSL( seg_str );
2492 if (!lpcstr_view) lpcstr_view = "(null)";
2493 for (len = 0; !format.precision || (len < format.precision); len++)
2494 if (!lpcstr_view[len]) break;
2495 format.precision = len;
2496 break;
2497 case WPR_SIGNED:
2498 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, INT );
2499 else int_view = VA_ARG16( args, INT16 );
2500 len = sprintf( number, "%d", int_view );
2501 break;
2502 case WPR_UNSIGNED:
2503 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
2504 else int_view = VA_ARG16( args, UINT16 );
2505 len = sprintf( number, "%u", int_view );
2506 break;
2507 case WPR_HEXA:
2508 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
2509 else int_view = VA_ARG16( args, UINT16 );
2510 len = sprintf( number, (format.flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", int_view);
2511 break;
2512 case WPR_UNKNOWN:
2513 continue;
2515 if (format.precision < len) format.precision = len;
2516 if (format.flags & WPRINTF_LEFTALIGN) format.flags &= ~WPRINTF_ZEROPAD;
2517 if ((format.flags & WPRINTF_ZEROPAD) && (format.width > format.precision))
2518 format.precision = format.width;
2519 if (format.flags & WPRINTF_PREFIX_HEX) len += 2;
2521 sign = 0;
2522 if (!(format.flags & WPRINTF_LEFTALIGN))
2523 for (i = format.precision; i < format.width; i++) *p++ = ' ';
2524 switch(format.type)
2526 case WPR_CHAR:
2527 *p = char_view;
2528 /* wsprintf16 ignores null characters */
2529 if (*p != '\0') p++;
2530 else if (format.width > 1) *p++ = ' ';
2531 break;
2532 case WPR_STRING:
2533 if (len) memcpy( p, lpcstr_view, len );
2534 p += len;
2535 break;
2536 case WPR_HEXA:
2537 if (format.flags & WPRINTF_PREFIX_HEX)
2539 *p++ = '0';
2540 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
2541 len -= 2;
2543 /* fall through */
2544 case WPR_SIGNED:
2545 /* Transfer the sign now, just in case it will be zero-padded*/
2546 if (number[0] == '-')
2548 *p++ = '-';
2549 sign = 1;
2551 /* fall through */
2552 case WPR_UNSIGNED:
2553 for (i = len; i < format.precision; i++) *p++ = '0';
2554 if (len > sign) memcpy( p, number + sign, len - sign );
2555 p += len-sign;
2556 break;
2557 case WPR_UNKNOWN:
2558 continue;
2560 if (format.flags & WPRINTF_LEFTALIGN)
2561 for (i = format.precision; i < format.width; i++) *p++ = ' ';
2563 *p = 0;
2564 return p - buffer;
2568 /***********************************************************************
2569 * _wsprintf (USER.420)
2571 INT16 WINAPIV wsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 valist )
2573 return wvsprintf16( buffer, spec, valist );
2577 /***********************************************************************
2578 * lstrcmp (USER.430)
2580 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
2582 int ret;
2583 /* Looks too complicated, but in optimized strcpy we might get
2584 * a 32bit wide difference and would truncate it to 16 bit, so
2585 * erroneously returning equality. */
2586 ret = strcmp( str1, str2 );
2587 if (ret < 0) return -1;
2588 if (ret > 0) return 1;
2589 return 0;
2593 /***********************************************************************
2594 * AnsiUpper (USER.431)
2596 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
2598 /* uppercase only one char if strOrChar < 0x10000 */
2599 if (HIWORD(strOrChar))
2601 CharUpperA( MapSL(strOrChar) );
2602 return strOrChar;
2604 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
2608 /***********************************************************************
2609 * AnsiLower (USER.432)
2611 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
2613 /* lowercase only one char if strOrChar < 0x10000 */
2614 if (HIWORD(strOrChar))
2616 CharLowerA( MapSL(strOrChar) );
2617 return strOrChar;
2619 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
2623 /***********************************************************************
2624 * AnsiUpperBuff (USER.437)
2626 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
2628 CharUpperBuffA( str, len ? len : 65536 );
2629 return len;
2633 /***********************************************************************
2634 * AnsiLowerBuff (USER.438)
2636 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
2638 CharLowerBuffA( str, len ? len : 65536 );
2639 return len;
2643 /*******************************************************************
2644 * InsertMenuItem (USER.441)
2646 * FIXME: untested
2648 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
2649 const MENUITEMINFO16 *mii )
2651 MENUITEMINFOA miia;
2653 miia.cbSize = sizeof(miia);
2654 miia.fMask = mii->fMask;
2655 miia.dwTypeData = (LPSTR)mii->dwTypeData;
2656 miia.fType = mii->fType;
2657 miia.fState = mii->fState;
2658 miia.wID = mii->wID;
2659 miia.hSubMenu = HMENU_32(mii->hSubMenu);
2660 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
2661 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
2662 miia.dwItemData = mii->dwItemData;
2663 miia.cch = mii->cch;
2664 if (IS_MENU_STRING_ITEM(miia.fType))
2665 miia.dwTypeData = MapSL(mii->dwTypeData);
2666 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
2670 /**********************************************************************
2671 * DrawState (USER.449)
2673 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
2674 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
2676 struct draw_state_info info;
2677 UINT opcode = flags & 0xf;
2679 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
2681 /* make sure DrawStateA doesn't try to use ldata as a pointer */
2682 if (!wdata) wdata = strlen( MapSL(ldata) );
2683 if (!cx || !cy)
2685 SIZE s;
2686 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
2687 if (!cx) cx = s.cx;
2688 if (!cy) cy = s.cy;
2691 info.proc = func;
2692 info.param = ldata;
2693 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
2694 (LPARAM)&info, wdata, x, y, cx, cy, flags );
2698 /**********************************************************************
2699 * CreateIconFromResourceEx (USER.450)
2701 * FIXME: not sure about exact parameter types
2703 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
2704 BOOL16 bIcon, DWORD dwVersion,
2705 INT16 width, INT16 height,
2706 UINT16 cFlag)
2708 return get_icon_16( CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, width, height, cFlag ));
2712 /***********************************************************************
2713 * AdjustWindowRectEx (USER.454)
2715 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
2717 RECT rect32;
2718 BOOL ret;
2720 rect32.left = rect->left;
2721 rect32.top = rect->top;
2722 rect32.right = rect->right;
2723 rect32.bottom = rect->bottom;
2724 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
2725 rect->left = rect32.left;
2726 rect->top = rect32.top;
2727 rect->right = rect32.right;
2728 rect->bottom = rect32.bottom;
2729 return ret;
2733 /**********************************************************************
2734 * GetIconID (USER.455)
2736 WORD WINAPI GetIconID16( HGLOBAL16 hResource, DWORD resType )
2738 BYTE *dir = GlobalLock16(hResource);
2740 switch (resType)
2742 case RT_CURSOR:
2743 return LookupIconIdFromDirectoryEx16( dir, FALSE, GetSystemMetrics(SM_CXCURSOR),
2744 GetSystemMetrics(SM_CYCURSOR), LR_MONOCHROME );
2745 case RT_ICON:
2746 return LookupIconIdFromDirectoryEx16( dir, TRUE, GetSystemMetrics(SM_CXICON),
2747 GetSystemMetrics(SM_CYICON), 0 );
2749 return 0;
2753 /**********************************************************************
2754 * LoadIconHandler (USER.456)
2756 HICON16 WINAPI LoadIconHandler16( HGLOBAL16 hResource, BOOL16 bNew )
2758 return CreateIconFromResourceEx16( LockResource16( hResource ), 0xffff, TRUE,
2759 bNew ? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR );
2763 /***********************************************************************
2764 * DestroyIcon (USER.457)
2766 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
2768 int count;
2770 TRACE("%04x\n", hIcon );
2772 count = release_shared_icon( hIcon );
2773 if (count != -1) return !count;
2774 /* assume non-shared */
2775 free_icon_handle( hIcon );
2776 return TRUE;
2779 /***********************************************************************
2780 * DestroyCursor (USER.458)
2782 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
2784 return DestroyIcon16( hCursor );
2788 /***********************************************************************
2789 * DumpIcon (USER.459)
2791 DWORD WINAPI DumpIcon16( SEGPTR pInfo, WORD *lpLen,
2792 SEGPTR *lpXorBits, SEGPTR *lpAndBits )
2794 CURSORICONINFO *info = MapSL( pInfo );
2795 int sizeAnd, sizeXor;
2797 if (!info) return 0;
2798 sizeXor = info->nHeight * info->nWidthBytes;
2799 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2800 if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
2801 if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
2802 if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
2803 return MAKELONG( sizeXor, sizeXor );
2807 /*******************************************************************
2808 * DRAG_QueryUpdate16
2810 * Recursively find a child that contains spDragInfo->pt point
2811 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
2813 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
2815 BOOL bResult;
2816 WPARAM wParam;
2817 POINT pt, old_pt;
2818 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
2819 RECT tempRect;
2820 HWND child;
2822 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
2824 old_pt.x = ptrDragInfo->pt.x;
2825 old_pt.y = ptrDragInfo->pt.y;
2826 pt = old_pt;
2827 ScreenToClient( hQueryWnd, &pt );
2828 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
2829 if (!child) return FALSE;
2831 if (child != hQueryWnd)
2833 wParam = 0;
2834 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
2836 else
2838 GetClientRect( hQueryWnd, &tempRect );
2839 wParam = !PtInRect( &tempRect, pt );
2842 ptrDragInfo->pt.x = pt.x;
2843 ptrDragInfo->pt.y = pt.y;
2844 ptrDragInfo->hScope = HWND_16(hQueryWnd);
2846 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
2848 if (!bResult)
2850 ptrDragInfo->pt.x = old_pt.x;
2851 ptrDragInfo->pt.y = old_pt.y;
2853 return bResult;
2857 /******************************************************************************
2858 * DragObject (USER.464)
2860 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
2861 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
2863 MSG msg;
2864 LPDRAGINFO16 lpDragInfo;
2865 SEGPTR spDragInfo;
2866 HCURSOR hOldCursor=0, hBummer=0, hCursor32;
2867 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
2868 HCURSOR hCurrentCursor = 0;
2869 HWND16 hCurrentWnd = 0;
2871 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
2872 spDragInfo = WOWGlobalLock16(hDragInfo);
2874 if( !lpDragInfo || !spDragInfo ) return 0L;
2876 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
2878 GlobalFree16(hDragInfo);
2879 return 0L;
2882 if ((hCursor32 = get_icon_32( hCursor ))) SetCursor( hCursor32 );
2884 lpDragInfo->hWnd = hWnd;
2885 lpDragInfo->hScope = 0;
2886 lpDragInfo->wFlags = wObj;
2887 lpDragInfo->hList = szList; /* near pointer! */
2888 lpDragInfo->hOfStruct = hOfStruct;
2889 lpDragInfo->l = 0L;
2891 SetCapture( HWND_32(hWnd) );
2892 ShowCursor( TRUE );
2896 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
2898 *(lpDragInfo+1) = *lpDragInfo;
2900 lpDragInfo->pt.x = msg.pt.x;
2901 lpDragInfo->pt.y = msg.pt.y;
2903 /* update DRAGINFO struct */
2904 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
2905 hCurrentCursor = hCursor32;
2906 else
2908 hCurrentCursor = hBummer;
2909 lpDragInfo->hScope = 0;
2911 if( hCurrentCursor )
2912 SetCursor(hCurrentCursor);
2914 /* send WM_DRAGLOOP */
2915 SendMessage16( hWnd, WM_DRAGLOOP, hCurrentCursor != hBummer, spDragInfo );
2916 /* send WM_DRAGSELECT or WM_DRAGMOVE */
2917 if( hCurrentWnd != lpDragInfo->hScope )
2919 if( hCurrentWnd )
2920 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
2921 MAKELPARAM(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
2922 HIWORD(spDragInfo)) );
2923 hCurrentWnd = lpDragInfo->hScope;
2924 if( hCurrentWnd )
2925 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, spDragInfo);
2927 else
2928 if( hCurrentWnd )
2929 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, spDragInfo);
2931 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
2933 ReleaseCapture();
2934 ShowCursor( FALSE );
2936 if( hCursor ) SetCursor(hOldCursor);
2938 if( hCurrentCursor != hBummer )
2939 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
2940 hWnd, spDragInfo );
2941 else
2942 msg.lParam = 0;
2943 GlobalFree16(hDragInfo);
2945 return (DWORD)(msg.lParam);
2949 /***********************************************************************
2950 * DrawFocusRect (USER.466)
2952 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
2954 RECT rect32;
2956 rect32.left = rc->left;
2957 rect32.top = rc->top;
2958 rect32.right = rc->right;
2959 rect32.bottom = rc->bottom;
2960 DrawFocusRect( HDC_32(hdc), &rect32 );
2964 /***********************************************************************
2965 * AnsiNext (USER.472)
2967 SEGPTR WINAPI AnsiNext16(SEGPTR current)
2969 char *ptr = MapSL(current);
2970 return current + (CharNextA(ptr) - ptr);
2974 /***********************************************************************
2975 * AnsiPrev (USER.473)
2977 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
2979 char *ptr = MapSL(current);
2980 return current - (ptr - CharPrevA( start, ptr ));
2984 /****************************************************************************
2985 * GetKeyboardLayoutName (USER.477)
2987 INT16 WINAPI GetKeyboardLayoutName16( LPSTR name )
2989 return GetKeyboardLayoutNameA( name );
2993 /***********************************************************************
2994 * SystemParametersInfo (USER.483)
2996 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
2997 LPVOID lpvParam, UINT16 fuWinIni )
2999 BOOL16 ret;
3001 TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
3003 switch (uAction)
3005 case SPI_GETBEEP:
3006 case SPI_GETSCREENSAVEACTIVE:
3007 case SPI_GETICONTITLEWRAP:
3008 case SPI_GETMENUDROPALIGNMENT:
3009 case SPI_GETFASTTASKSWITCH:
3010 case SPI_GETDRAGFULLWINDOWS:
3012 BOOL tmp;
3013 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3014 if (ret && lpvParam) *(BOOL16 *)lpvParam = tmp;
3015 break;
3018 case SPI_GETBORDER:
3019 case SPI_ICONHORIZONTALSPACING:
3020 case SPI_GETSCREENSAVETIMEOUT:
3021 case SPI_GETGRIDGRANULARITY:
3022 case SPI_GETKEYBOARDDELAY:
3023 case SPI_ICONVERTICALSPACING:
3025 INT tmp;
3026 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3027 if (ret && lpvParam) *(INT16 *)lpvParam = tmp;
3028 break;
3031 case SPI_GETKEYBOARDSPEED:
3032 case SPI_GETMOUSEHOVERWIDTH:
3033 case SPI_GETMOUSEHOVERHEIGHT:
3034 case SPI_GETMOUSEHOVERTIME:
3036 DWORD tmp;
3037 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3038 if (ret && lpvParam) *(WORD *)lpvParam = tmp;
3039 break;
3042 case SPI_GETICONTITLELOGFONT:
3044 LOGFONTA tmp;
3045 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3046 if (ret && lpvParam) logfont_32_to_16( &tmp, (LPLOGFONT16)lpvParam );
3047 break;
3050 case SPI_GETNONCLIENTMETRICS:
3052 NONCLIENTMETRICSA tmp;
3053 LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
3054 if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
3056 tmp.cbSize = sizeof(NONCLIENTMETRICSA);
3057 ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
3058 if (ret)
3060 lpnm16->iBorderWidth = tmp.iBorderWidth;
3061 lpnm16->iScrollWidth = tmp.iScrollWidth;
3062 lpnm16->iScrollHeight = tmp.iScrollHeight;
3063 lpnm16->iCaptionWidth = tmp.iCaptionWidth;
3064 lpnm16->iCaptionHeight = tmp.iCaptionHeight;
3065 lpnm16->iSmCaptionWidth = tmp.iSmCaptionWidth;
3066 lpnm16->iSmCaptionHeight = tmp.iSmCaptionHeight;
3067 lpnm16->iMenuWidth = tmp.iMenuWidth;
3068 lpnm16->iMenuHeight = tmp.iMenuHeight;
3069 logfont_32_to_16( &tmp.lfCaptionFont, &lpnm16->lfCaptionFont );
3070 logfont_32_to_16( &tmp.lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
3071 logfont_32_to_16( &tmp.lfMenuFont, &lpnm16->lfMenuFont );
3072 logfont_32_to_16( &tmp.lfStatusFont, &lpnm16->lfStatusFont );
3073 logfont_32_to_16( &tmp.lfMessageFont, &lpnm16->lfMessageFont );
3076 else /* winfile 95 sets cbSize to 340 */
3077 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
3078 break;
3081 case SPI_GETWORKAREA:
3083 RECT tmp;
3084 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3085 if (ret && lpvParam)
3087 RECT16 *r16 = lpvParam;
3088 r16->left = tmp.left;
3089 r16->top = tmp.top;
3090 r16->right = tmp.right;
3091 r16->bottom = tmp.bottom;
3093 break;
3096 default:
3097 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
3098 break;
3101 return ret;
3105 /***********************************************************************
3106 * USER_489 (USER.489)
3108 LONG WINAPI stub_USER_489(void)
3110 FIXME("stub\n");
3111 return 0;
3115 /***********************************************************************
3116 * USER_490 (USER.490)
3118 LONG WINAPI stub_USER_490(void)
3120 FIXME("stub\n");
3121 return 0;
3125 /***********************************************************************
3126 * USER_492 (USER.492)
3128 LONG WINAPI stub_USER_492(void)
3130 FIXME("stub\n");
3131 return 0;
3135 /***********************************************************************
3136 * USER_496 (USER.496)
3138 LONG WINAPI stub_USER_496(void)
3140 FIXME("stub\n");
3141 return 0;
3145 /***********************************************************************
3146 * FormatMessage (USER.606)
3148 DWORD WINAPI FormatMessage16(
3149 DWORD dwFlags,
3150 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
3151 WORD dwMessageId,
3152 WORD dwLanguageId,
3153 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
3154 WORD nSize,
3155 LPDWORD args ) /* [in] NOTE: va_list *args */
3157 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
3158 LPSTR target,t;
3159 DWORD talloced;
3160 LPSTR from,f;
3161 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
3162 BOOL eos = FALSE;
3163 LPSTR allocstring = NULL;
3165 TRACE("(0x%x,%x,%d,0x%x,%p,%d,%p)\n",
3166 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
3167 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
3168 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
3169 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
3170 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
3171 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
3173 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
3174 FIXME("line wrapping (%u) not supported.\n", width);
3175 from = NULL;
3176 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
3178 char *source = MapSL(lpSource);
3179 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
3180 strcpy( from, source );
3182 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
3183 from = HeapAlloc( GetProcessHeap(),0,200 );
3184 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
3186 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
3187 INT16 bufsize;
3188 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
3190 dwMessageId &= 0xFFFF;
3191 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
3192 if (bufsize) {
3193 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
3194 LoadString16(hinst16,dwMessageId,from,bufsize+1);
3197 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
3198 t = target;
3199 talloced= 100;
3201 #define ADD_TO_T(c) \
3202 do { \
3203 *t++=c;\
3204 if (t-target == talloced) {\
3205 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
3206 t = target+talloced;\
3207 talloced*=2;\
3209 } while(0)
3211 if (from) {
3212 f=from;
3213 while (*f && !eos) {
3214 if (*f=='%') {
3215 int insertnr;
3216 char *fmtstr,*x,*lastf;
3217 DWORD *argliststart;
3219 fmtstr = NULL;
3220 lastf = f;
3221 f++;
3222 if (!*f) {
3223 ADD_TO_T('%');
3224 continue;
3226 switch (*f) {
3227 case '1':case '2':case '3':case '4':case '5':
3228 case '6':case '7':case '8':case '9':
3229 insertnr=*f-'0';
3230 switch (f[1]) {
3231 case '0':case '1':case '2':case '3':
3232 case '4':case '5':case '6':case '7':
3233 case '8':case '9':
3234 f++;
3235 insertnr=insertnr*10+*f-'0';
3236 f++;
3237 break;
3238 default:
3239 f++;
3240 break;
3242 if (*f=='!') {
3243 f++;
3244 if (NULL!=(x=strchr(f,'!'))) {
3245 *x='\0';
3246 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
3247 sprintf(fmtstr,"%%%s",f);
3248 f=x+1;
3249 } else {
3250 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
3251 sprintf(fmtstr,"%%%s",f);
3252 f+=strlen(f); /*at \0*/
3255 else
3257 if(!args) break;
3258 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
3259 strcpy( fmtstr, "%s" );
3261 if (args) {
3262 int ret;
3263 int sz;
3264 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
3266 argliststart=args+insertnr-1;
3268 /* CMF - This makes a BIG assumption about va_list */
3269 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart)) < 0 || ret >= sz) {
3270 LPSTR new_b;
3271 sz = (ret == -1 ? sz + 100 : ret + 1);
3272 new_b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
3273 if (!new_b) break;
3274 b = new_b;
3276 for (x=b; *x; x++) ADD_TO_T(*x);
3277 HeapFree(GetProcessHeap(), 0, b);
3278 } else {
3279 /* NULL args - copy formatstr
3280 * (probably wrong)
3282 while ((lastf<f)&&(*lastf)) {
3283 ADD_TO_T(*lastf++);
3286 HeapFree(GetProcessHeap(),0,fmtstr);
3287 break;
3288 case '0': /* Just stop processing format string */
3289 eos = TRUE;
3290 f++;
3291 break;
3292 case 'n': /* 16 bit version just outputs 'n' */
3293 default:
3294 ADD_TO_T(*f++);
3295 break;
3297 } else { /* '\n' or '\r' gets mapped to "\r\n" */
3298 if(*f == '\n' || *f == '\r') {
3299 if (width == 0) {
3300 ADD_TO_T('\r');
3301 ADD_TO_T('\n');
3302 if(*f++ == '\r' && *f == '\n')
3303 f++;
3305 } else {
3306 ADD_TO_T(*f++);
3310 *t='\0';
3312 talloced = strlen(target)+1;
3313 TRACE("-- %s\n",debugstr_a(target));
3314 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
3315 /* nSize is the MINIMUM size */
3316 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
3317 SEGPTR ptr = LocalLock16(h);
3318 allocstring = MapSL( ptr );
3319 memcpy( allocstring,target,talloced);
3320 LocalUnlock16( h );
3321 *((HLOCAL16*)lpBuffer) = h;
3322 } else
3323 lstrcpynA(lpBuffer,target,nSize);
3324 HeapFree(GetProcessHeap(),0,target);
3325 HeapFree(GetProcessHeap(),0,from);
3326 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
3327 strlen(allocstring):
3328 strlen(lpBuffer);
3330 #undef ADD_TO_T
3333 /**********************************************************************
3334 * DestroyIcon32 (USER.610)
3336 * This routine is actually exported from Win95 USER under the name
3337 * DestroyIcon32 ... The behaviour implemented here should mimic
3338 * the Win95 one exactly, especially the return values, which
3339 * depend on the setting of various flags.
3341 WORD WINAPI DestroyIcon32( HGLOBAL16 handle, UINT16 flags )
3343 WORD retv;
3345 /* Check whether destroying active cursor */
3347 if (GetCursor16() == handle)
3349 WARN("Destroying active cursor!\n" );
3350 return FALSE;
3353 /* Try shared cursor/icon first */
3355 if (!(flags & CID_NONSHARED))
3357 INT count = release_shared_icon( handle );
3358 if (count != -1)
3359 return (flags & CID_WIN32) ? TRUE : (count == 0);
3362 /* Now assume non-shared cursor/icon */
3364 retv = free_icon_handle( handle );
3365 return (flags & CID_RESOURCE)? retv : TRUE;
3369 /***********************************************************************
3370 * ChangeDisplaySettings (USER.620)
3372 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
3374 return ChangeDisplaySettingsA( devmode, flags );
3378 /***********************************************************************
3379 * EnumDisplaySettings (USER.621)
3381 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
3383 return EnumDisplaySettingsA( name, n, devmode );
3386 /**********************************************************************
3387 * DrawFrameControl (USER.656)
3389 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
3391 RECT rect32;
3392 BOOL ret;
3394 rect32.left = rc->left;
3395 rect32.top = rc->top;
3396 rect32.right = rc->right;
3397 rect32.bottom = rc->bottom;
3398 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
3399 rc->left = rect32.left;
3400 rc->top = rect32.top;
3401 rc->right = rect32.right;
3402 rc->bottom = rect32.bottom;
3403 return ret;
3406 /**********************************************************************
3407 * DrawEdge (USER.659)
3409 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
3411 RECT rect32;
3412 BOOL ret;
3414 rect32.left = rc->left;
3415 rect32.top = rc->top;
3416 rect32.right = rc->right;
3417 rect32.bottom = rc->bottom;
3418 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
3419 rc->left = rect32.left;
3420 rc->top = rect32.top;
3421 rc->right = rect32.right;
3422 rc->bottom = rect32.bottom;
3423 return ret;
3426 /**********************************************************************
3427 * CheckMenuRadioItem (USER.666)
3429 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
3430 UINT16 check, BOOL16 bypos)
3432 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );