comctl32/tests: Use CRT allocation functions.
[wine.git] / dlls / user.exe16 / user.c
blobe1b44d28101bc985e893fec5fec3d214c885ca65
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 "ntuser.h"
35 #include "wine/list.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(user);
40 /* handle to handle 16 conversions */
41 #define HANDLE_16(h32) (LOWORD(h32))
42 #define HGDIOBJ_16(h32) (LOWORD(h32))
44 /* handle16 to handle conversions */
45 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
46 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
48 #define IS_MENU_STRING_ITEM(flags) \
49 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
51 /* UserSeeUserDo parameters */
52 #define USUD_LOCALALLOC 0x0001
53 #define USUD_LOCALFREE 0x0002
54 #define USUD_LOCALCOMPACT 0x0003
55 #define USUD_LOCALHEAP 0x0004
56 #define USUD_FIRSTCLASS 0x0005
58 #define CID_RESOURCE 0x0001
59 #define CID_WIN32 0x0004
60 #define CID_NONSHARED 0x0008
62 WORD USER_HeapSel = 0; /* USER heap selector */
64 static HINSTANCE16 gdi_inst;
66 struct gray_string_info
68 GRAYSTRINGPROC16 proc;
69 LPARAM param;
70 char str[1];
73 /* callback for 16-bit gray string proc with opaque pointer */
74 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
76 const struct gray_string_info *info = (struct gray_string_info *)param;
77 WORD args[4];
78 DWORD ret;
80 args[3] = HDC_16(hdc);
81 args[2] = HIWORD(info->param);
82 args[1] = LOWORD(info->param);
83 args[0] = len;
84 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
85 return LOWORD(ret);
88 /* callback for 16-bit gray string proc with string pointer */
89 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
91 const struct gray_string_info *info = CONTAINING_RECORD( (void *)param, struct gray_string_info, str );
92 return gray_string_callback( hdc, (LPARAM)info, len );
95 struct draw_state_info
97 DRAWSTATEPROC16 proc;
98 LPARAM param;
101 /* callback for 16-bit DrawState functions */
102 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
104 const struct draw_state_info *info = (struct draw_state_info *)lparam;
105 WORD args[6];
106 DWORD ret;
108 args[5] = HDC_16(hdc);
109 args[4] = HIWORD(info->param);
110 args[3] = LOWORD(info->param);
111 args[2] = wparam;
112 args[1] = cx;
113 args[0] = cy;
114 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
115 return LOWORD(ret);
118 /* This function is a copy of the one in objects/font.c */
119 static void logfont_32_to_16( const LOGFONTA* font32, LPLOGFONT16 font16 )
121 font16->lfHeight = font32->lfHeight;
122 font16->lfWidth = font32->lfWidth;
123 font16->lfEscapement = font32->lfEscapement;
124 font16->lfOrientation = font32->lfOrientation;
125 font16->lfWeight = font32->lfWeight;
126 font16->lfItalic = font32->lfItalic;
127 font16->lfUnderline = font32->lfUnderline;
128 font16->lfStrikeOut = font32->lfStrikeOut;
129 font16->lfCharSet = font32->lfCharSet;
130 font16->lfOutPrecision = font32->lfOutPrecision;
131 font16->lfClipPrecision = font32->lfClipPrecision;
132 font16->lfQuality = font32->lfQuality;
133 font16->lfPitchAndFamily = font32->lfPitchAndFamily;
134 lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
137 static int get_bitmap_width_bytes( int width, int bpp )
139 switch(bpp)
141 case 1:
142 return 2 * ((width+15) / 16);
143 case 4:
144 return 2 * ((width+3) / 4);
145 case 24:
146 width *= 3;
147 /* fall through */
148 case 8:
149 return width + (width & 1);
150 case 16:
151 case 15:
152 return width * 2;
153 case 32:
154 return width * 4;
155 default:
156 WARN("Unknown depth %d, please report.\n", bpp );
158 return -1;
161 /***********************************************************************
162 * Helper for wsprintf16
165 #define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */
166 #define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */
167 #define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */
168 #define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */
169 #define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
170 #define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
172 typedef enum
174 WPR_UNKNOWN,
175 WPR_CHAR,
176 WPR_STRING,
177 WPR_SIGNED,
178 WPR_UNSIGNED,
179 WPR_HEXA
180 } WPRINTF_TYPE;
182 typedef struct
184 UINT flags;
185 UINT width;
186 UINT precision;
187 WPRINTF_TYPE type;
188 } WPRINTF_FORMAT;
190 static INT parse_format( LPCSTR format, WPRINTF_FORMAT *res )
192 LPCSTR p = format;
194 res->flags = 0;
195 res->width = 0;
196 res->precision = 0;
197 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
198 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
199 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
200 while ((*p >= '0') && (*p <= '9')) /* width field */
202 res->width = res->width * 10 + *p - '0';
203 p++;
205 if (*p == '.') /* precision field */
207 p++;
208 while ((*p >= '0') && (*p <= '9'))
210 res->precision = res->precision * 10 + *p - '0';
211 p++;
214 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
215 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
216 switch(*p)
218 case 'c':
219 case 'C': /* no Unicode in Win16 */
220 res->type = WPR_CHAR;
221 break;
222 case 's':
223 case 'S':
224 res->type = WPR_STRING;
225 break;
226 case 'd':
227 case 'i':
228 res->type = WPR_SIGNED;
229 break;
230 case 'u':
231 res->type = WPR_UNSIGNED;
232 break;
233 case 'p':
234 res->width = 8;
235 res->flags |= WPRINTF_ZEROPAD;
236 /* fall through */
237 case 'X':
238 res->flags |= WPRINTF_UPPER_HEX;
239 /* fall through */
240 case 'x':
241 res->type = WPR_HEXA;
242 break;
243 default: /* unknown format char */
244 res->type = WPR_UNKNOWN;
245 p--; /* print format as normal char */
246 break;
248 return (INT)(p - format) + 1;
252 /**********************************************************************
253 * Management of the 16-bit cursors and icons
256 struct cache_entry
258 struct list entry;
259 HINSTANCE16 inst;
260 HRSRC16 rsrc;
261 HRSRC16 group;
262 HICON16 icon;
263 INT count;
266 static struct list icon_cache = LIST_INIT( icon_cache );
268 static const WORD ICON_HOTSPOT = 0x4242;
270 static HICON16 alloc_icon_handle( unsigned int size )
272 HGLOBAL16 handle = GlobalAlloc16( GMEM_MOVEABLE, size + sizeof(ULONG_PTR) );
273 char *ptr = GlobalLock16( handle );
274 memset( ptr + size, 0, sizeof(ULONG_PTR) );
275 GlobalUnlock16( handle );
276 FarSetOwner16( handle, 0 );
277 return handle;
280 static CURSORICONINFO *get_icon_ptr( HICON16 handle )
282 return GlobalLock16( handle );
285 static void release_icon_ptr( HICON16 handle, CURSORICONINFO *ptr )
287 GlobalUnlock16( handle );
290 static HICON store_icon_32( HICON16 icon16, HICON icon )
292 HICON ret = 0;
293 CURSORICONINFO *ptr = get_icon_ptr( icon16 );
295 if (ptr)
297 unsigned int and_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, 1 );
298 unsigned int xor_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, ptr->bBitsPerPixel );
299 if (GlobalSize16( icon16 ) >= sizeof(*ptr) + sizeof(ULONG_PTR) + and_size + xor_size )
301 memcpy( &ret, (char *)(ptr + 1) + and_size + xor_size, sizeof(ret) );
302 memcpy( (char *)(ptr + 1) + and_size + xor_size, &icon, sizeof(icon) );
303 NtUserSetIconParam( icon, icon16 );
305 release_icon_ptr( icon16, ptr );
307 return ret;
310 static int free_icon_handle( HICON16 handle )
312 HICON icon32;
314 if ((icon32 = store_icon_32( handle, 0 ))) DestroyIcon( icon32 );
315 return GlobalFree16( handle );
318 /* retrieve the 32-bit counterpart of a 16-bit icon, creating it if needed */
319 HICON get_icon_32( HICON16 icon16 )
321 HICON ret = 0;
322 CURSORICONINFO *ptr = get_icon_ptr( icon16 );
324 if (ptr)
326 unsigned int and_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, 1 );
327 unsigned int xor_size = ptr->nHeight * get_bitmap_width_bytes( ptr->nWidth, ptr->bBitsPerPixel );
328 if (GlobalSize16( icon16 ) >= sizeof(*ptr) + sizeof(ULONG_PTR) + xor_size + and_size )
330 memcpy( &ret, (char *)(ptr + 1) + xor_size + and_size, sizeof(ret) );
331 if (!ret)
333 ICONINFO iinfo;
335 iinfo.fIcon = (ptr->ptHotSpot.x == ICON_HOTSPOT) && (ptr->ptHotSpot.y == ICON_HOTSPOT);
336 iinfo.xHotspot = ptr->ptHotSpot.x;
337 iinfo.yHotspot = ptr->ptHotSpot.y;
338 iinfo.hbmMask = CreateBitmap( ptr->nWidth, ptr->nHeight, 1, 1, ptr + 1 );
339 iinfo.hbmColor = CreateBitmap( ptr->nWidth, ptr->nHeight, ptr->bPlanes, ptr->bBitsPerPixel,
340 (char *)(ptr + 1) + and_size );
341 ret = CreateIconIndirect( &iinfo );
342 DeleteObject( iinfo.hbmMask );
343 DeleteObject( iinfo.hbmColor );
344 memcpy( (char *)(ptr + 1) + xor_size + and_size, &ret, sizeof(ret) );
345 NtUserSetIconParam( ret, icon16 );
348 release_icon_ptr( icon16, ptr );
350 return ret;
353 /* retrieve the 16-bit counterpart of a 32-bit icon, creating it if needed */
354 HICON16 get_icon_16( HICON icon )
356 HICON16 ret = NtUserGetIconParam( icon );
358 if (!ret)
360 ICONINFO info;
361 BITMAP bm;
362 UINT and_size, xor_size;
363 void *xor_bits = NULL, *and_bits;
364 CURSORICONINFO cinfo;
366 if (!(GetIconInfo( icon, &info ))) return 0;
367 GetObjectW( info.hbmMask, sizeof(bm), &bm );
368 and_size = bm.bmHeight * bm.bmWidthBytes;
369 if (!(and_bits = HeapAlloc( GetProcessHeap(), 0, and_size ))) goto done;
370 GetBitmapBits( info.hbmMask, and_size, and_bits );
371 if (info.hbmColor)
373 GetObjectW( info.hbmColor, sizeof(bm), &bm );
374 xor_size = bm.bmHeight * bm.bmWidthBytes;
375 if (!(xor_bits = HeapAlloc( GetProcessHeap(), 0, xor_size ))) goto done;
376 GetBitmapBits( info.hbmColor, xor_size, xor_bits );
378 else
380 bm.bmHeight /= 2;
381 xor_bits = (char *)and_bits + and_size / 2;
383 if (!info.fIcon)
385 cinfo.ptHotSpot.x = info.xHotspot;
386 cinfo.ptHotSpot.y = info.yHotspot;
388 else cinfo.ptHotSpot.x = cinfo.ptHotSpot.y = ICON_HOTSPOT;
390 cinfo.nWidth = bm.bmWidth;
391 cinfo.nHeight = bm.bmHeight;
392 cinfo.nWidthBytes = bm.bmWidthBytes;
393 cinfo.bPlanes = bm.bmPlanes;
394 cinfo.bBitsPerPixel = bm.bmBitsPixel;
396 if ((ret = CreateCursorIconIndirect16( 0, &cinfo, and_bits, xor_bits )))
397 store_icon_32( ret, icon );
399 done:
400 if (info.hbmColor)
402 HeapFree( GetProcessHeap(), 0, xor_bits );
403 DeleteObject( info.hbmColor );
405 HeapFree( GetProcessHeap(), 0, and_bits );
406 DeleteObject( info.hbmMask );
408 return ret;
411 static void add_shared_icon( HINSTANCE16 inst, HRSRC16 rsrc, HRSRC16 group, HICON16 icon )
413 struct cache_entry *cache = HeapAlloc( GetProcessHeap(), 0, sizeof(*cache) );
415 if (!cache) return;
416 cache->inst = inst;
417 cache->rsrc = rsrc;
418 cache->group = group;
419 cache->icon = icon;
420 cache->count = 1;
421 list_add_tail( &icon_cache, &cache->entry );
424 static HICON16 find_shared_icon( HINSTANCE16 inst, HRSRC16 rsrc )
426 struct cache_entry *cache;
428 LIST_FOR_EACH_ENTRY( cache, &icon_cache, struct cache_entry, entry )
430 if (cache->inst != inst || cache->rsrc != rsrc) continue;
431 cache->count++;
432 return cache->icon;
434 return 0;
437 static int release_shared_icon( HICON16 icon )
439 struct cache_entry *cache;
441 LIST_FOR_EACH_ENTRY( cache, &icon_cache, struct cache_entry, entry )
443 if (cache->icon != icon) continue;
444 if (!cache->count) return 0;
445 return --cache->count;
447 return -1;
450 static void free_module_icons( HINSTANCE16 inst )
452 struct cache_entry *cache, *next;
454 LIST_FOR_EACH_ENTRY_SAFE( cache, next, &icon_cache, struct cache_entry, entry )
456 if (cache->inst != inst) continue;
457 list_remove( &cache->entry );
458 free_icon_handle( cache->icon );
459 HeapFree( GetProcessHeap(), 0, cache );
463 /**********************************************************************
464 * Management of the 16-bit clipboard formats
467 struct clipboard_format
469 struct list entry;
470 UINT format;
471 HANDLE16 data;
474 static struct list clipboard_formats = LIST_INIT( clipboard_formats );
476 static void set_clipboard_format( UINT format, HANDLE16 data )
478 struct clipboard_format *fmt;
480 /* replace it if it exists already */
481 LIST_FOR_EACH_ENTRY( fmt, &clipboard_formats, struct clipboard_format, entry )
483 if (fmt->format != format) continue;
484 GlobalFree16( fmt->data );
485 fmt->data = data;
486 return;
489 if ((fmt = HeapAlloc( GetProcessHeap(), 0, sizeof(*fmt) )))
491 fmt->format = format;
492 fmt->data = data;
493 list_add_tail( &clipboard_formats, &fmt->entry );
497 static void free_clipboard_formats(void)
499 struct list *head;
501 while ((head = list_head( &clipboard_formats )))
503 struct clipboard_format *fmt = LIST_ENTRY( head, struct clipboard_format, entry );
504 list_remove( &fmt->entry );
505 GlobalFree16( fmt->data );
506 HeapFree( GetProcessHeap(), 0, fmt );
511 /***********************************************************************
512 * OldExitWindows (USER.2)
514 void WINAPI OldExitWindows16(void)
516 ExitWindows16(0, 0);
520 /**********************************************************************
521 * InitApp (USER.5)
523 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
525 /* Create task message queue */
526 return (InitThreadInput16( 0, 0 ) != 0);
530 /***********************************************************************
531 * ExitWindows (USER.7)
533 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
535 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
539 /***********************************************************************
540 * GetTimerResolution (USER.14)
542 LONG WINAPI GetTimerResolution16(void)
544 return (1000);
548 /***********************************************************************
549 * ClipCursor (USER.16)
551 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
553 RECT rect32;
555 if (!rect) return ClipCursor( NULL );
556 rect32.left = rect->left;
557 rect32.top = rect->top;
558 rect32.right = rect->right;
559 rect32.bottom = rect->bottom;
560 return ClipCursor( &rect32 );
564 /***********************************************************************
565 * GetCursorPos (USER.17)
567 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
569 POINT pos;
570 if (!pt) return FALSE;
571 GetCursorPos(&pos);
572 pt->x = pos.x;
573 pt->y = pos.y;
574 return TRUE;
578 /*******************************************************************
579 * AnyPopup (USER.52)
581 BOOL16 WINAPI AnyPopup16(void)
583 return AnyPopup();
587 /***********************************************************************
588 * SetCursor (USER.69)
590 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
592 return get_icon_16( SetCursor( get_icon_32(hCursor) ));
596 /***********************************************************************
597 * SetCursorPos (USER.70)
599 void WINAPI SetCursorPos16( INT16 x, INT16 y )
601 SetCursorPos( x, y );
605 /***********************************************************************
606 * ShowCursor (USER.71)
608 INT16 WINAPI ShowCursor16(BOOL16 bShow)
610 return ShowCursor(bShow);
614 /***********************************************************************
615 * SetRect (USER.72)
617 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
619 rect->left = left;
620 rect->right = right;
621 rect->top = top;
622 rect->bottom = bottom;
626 /***********************************************************************
627 * SetRectEmpty (USER.73)
629 void WINAPI SetRectEmpty16( LPRECT16 rect )
631 rect->left = rect->right = rect->top = rect->bottom = 0;
635 /***********************************************************************
636 * CopyRect (USER.74)
638 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
640 *dest = *src;
641 return TRUE;
645 /***********************************************************************
646 * IsRectEmpty (USER.75)
648 * Bug compat: Windows checks for 0 or negative width/height.
650 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
652 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
656 /***********************************************************************
657 * PtInRect (USER.76)
659 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
661 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
662 (pt.y >= rect->top) && (pt.y < rect->bottom));
666 /***********************************************************************
667 * OffsetRect (USER.77)
669 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
671 rect->left += x;
672 rect->right += x;
673 rect->top += y;
674 rect->bottom += y;
678 /***********************************************************************
679 * InflateRect (USER.78)
681 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
683 rect->left -= x;
684 rect->top -= y;
685 rect->right += x;
686 rect->bottom += y;
690 /***********************************************************************
691 * IntersectRect (USER.79)
693 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
694 const RECT16 *src2 )
696 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
697 (src1->left >= src2->right) || (src2->left >= src1->right) ||
698 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
700 SetRectEmpty16( dest );
701 return FALSE;
703 dest->left = max( src1->left, src2->left );
704 dest->right = min( src1->right, src2->right );
705 dest->top = max( src1->top, src2->top );
706 dest->bottom = min( src1->bottom, src2->bottom );
707 return TRUE;
711 /***********************************************************************
712 * UnionRect (USER.80)
714 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
715 const RECT16 *src2 )
717 if (IsRectEmpty16(src1))
719 if (IsRectEmpty16(src2))
721 SetRectEmpty16( dest );
722 return FALSE;
724 else *dest = *src2;
726 else
728 if (IsRectEmpty16(src2)) *dest = *src1;
729 else
731 dest->left = min( src1->left, src2->left );
732 dest->right = max( src1->right, src2->right );
733 dest->top = min( src1->top, src2->top );
734 dest->bottom = max( src1->bottom, src2->bottom );
737 return TRUE;
741 /***********************************************************************
742 * FillRect (USER.81)
743 * NOTE
744 * The Win16 variant doesn't support special color brushes like
745 * the Win32 one, despite the fact that Win16, as well as Win32,
746 * supports special background brushes for a window class.
748 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
750 HBRUSH prevBrush;
752 /* coordinates are logical so we cannot fast-check 'rect',
753 * it will be done later in the PatBlt().
756 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
757 PatBlt( HDC_32(hdc), rect->left, rect->top,
758 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
759 SelectObject( HDC_32(hdc), prevBrush );
760 return 1;
764 /***********************************************************************
765 * InvertRect (USER.82)
767 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
769 PatBlt( HDC_32(hdc), rect->left, rect->top,
770 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
774 /***********************************************************************
775 * FrameRect (USER.83)
777 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
779 RECT rect;
781 rect.left = rect16->left;
782 rect.top = rect16->top;
783 rect.right = rect16->right;
784 rect.bottom = rect16->bottom;
785 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
789 /***********************************************************************
790 * DrawIcon (USER.84)
792 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
794 return DrawIcon(HDC_32(hdc), x, y, get_icon_32(hIcon) );
798 /***********************************************************************
799 * DrawText (USER.85)
801 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
803 INT16 ret;
805 if (rect)
807 RECT rect32;
809 rect32.left = rect->left;
810 rect32.top = rect->top;
811 rect32.right = rect->right;
812 rect32.bottom = rect->bottom;
813 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
814 rect->left = rect32.left;
815 rect->top = rect32.top;
816 rect->right = rect32.right;
817 rect->bottom = rect32.bottom;
819 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
820 return ret;
824 /***********************************************************************
825 * IconSize (USER.86)
827 * See "Undocumented Windows". Used by W2.0 paint.exe.
829 DWORD WINAPI IconSize16(void)
831 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
835 /***********************************************************************
836 * AdjustWindowRect (USER.102)
838 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
840 return AdjustWindowRectEx16( rect, style, menu, 0 );
844 /***********************************************************************
845 * MessageBeep (USER.104)
847 void WINAPI MessageBeep16( UINT16 i )
849 MessageBeep( i );
853 /**************************************************************************
854 * CloseClipboard (USER.138)
856 BOOL16 WINAPI CloseClipboard16(void)
858 BOOL ret = CloseClipboard();
859 if (ret) free_clipboard_formats();
860 return ret;
864 /**************************************************************************
865 * EmptyClipboard (USER.139)
867 BOOL16 WINAPI EmptyClipboard16(void)
869 BOOL ret = EmptyClipboard();
870 if (ret) free_clipboard_formats();
871 return ret;
875 /**************************************************************************
876 * SetClipboardData (USER.141)
878 HANDLE16 WINAPI SetClipboardData16( UINT16 format, HANDLE16 data16 )
880 HANDLE data32 = 0;
882 switch (format)
884 case CF_BITMAP:
885 case CF_PALETTE:
886 data32 = HGDIOBJ_32( data16 );
887 break;
889 case CF_METAFILEPICT:
891 METAHEADER *header;
892 METAFILEPICT *pict32;
893 METAFILEPICT16 *pict16 = GlobalLock16( data16 );
895 if (pict16)
897 if (!(data32 = GlobalAlloc( GMEM_MOVEABLE, sizeof(*pict32) ))) return 0;
898 pict32 = GlobalLock( data32 );
899 pict32->mm = pict16->mm;
900 pict32->xExt = pict16->xExt;
901 pict32->yExt = pict16->yExt;
902 header = GlobalLock16( pict16->hMF );
903 pict32->hMF = SetMetaFileBitsEx( header->mtSize * 2, (BYTE *)header );
904 GlobalUnlock16( pict16->hMF );
905 GlobalUnlock( data32 );
907 set_clipboard_format( format, data16 );
908 break;
911 case CF_ENHMETAFILE:
912 FIXME( "enhmetafile not supported in 16-bit\n" );
913 return 0;
915 default:
916 if (format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST)
917 data32 = HGDIOBJ_32( data16 );
918 else if (format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST)
919 data32 = HANDLE_32( data16 );
920 else
922 UINT size = GlobalSize16( data16 );
923 void *ptr32, *ptr16 = GlobalLock16( data16 );
924 if (ptr16)
926 if (!(data32 = GlobalAlloc( GMEM_MOVEABLE, size ))) return 0;
927 ptr32 = GlobalLock( data32 );
928 memcpy( ptr32, ptr16, size );
929 GlobalUnlock( data32 );
931 set_clipboard_format( format, data16 );
933 break;
936 if (!SetClipboardData( format, data32 )) return 0;
937 return data16;
941 /**************************************************************************
942 * GetClipboardData (USER.142)
944 HANDLE16 WINAPI GetClipboardData16( UINT16 format )
946 HANDLE data32 = GetClipboardData( format );
947 HANDLE16 data16 = 0;
948 UINT size;
949 void *ptr;
951 if (!data32) return 0;
953 switch (format)
955 case CF_BITMAP:
956 case CF_PALETTE:
957 data16 = HGDIOBJ_16( data32 );
958 break;
960 case CF_METAFILEPICT:
962 METAFILEPICT16 *pict16;
963 METAFILEPICT *pict32 = GlobalLock( data32 );
965 if (pict32)
967 if (!(data16 = GlobalAlloc16( GMEM_MOVEABLE, sizeof(*pict16) ))) return 0;
968 pict16 = GlobalLock16( data16 );
969 pict16->mm = pict32->mm;
970 pict16->xExt = pict32->xExt;
971 pict16->yExt = pict32->yExt;
972 size = GetMetaFileBitsEx( pict32->hMF, 0, NULL );
973 pict16->hMF = GlobalAlloc16( GMEM_MOVEABLE, size );
974 ptr = GlobalLock16( pict16->hMF );
975 GetMetaFileBitsEx( pict32->hMF, size, ptr );
976 GlobalUnlock16( pict16->hMF );
977 GlobalUnlock16( data16 );
978 set_clipboard_format( format, data16 );
980 break;
983 case CF_ENHMETAFILE:
984 FIXME( "enhmetafile not supported in 16-bit\n" );
985 return 0;
987 default:
988 if (format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST)
989 data16 = HGDIOBJ_16( data32 );
990 else if (format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST)
991 data16 = HANDLE_16( data32 );
992 else
994 void *ptr16, *ptr32 = GlobalLock( data32 );
995 if (ptr32)
997 size = GlobalSize( data32 );
998 if (!(data16 = GlobalAlloc16( GMEM_MOVEABLE, size ))) return 0;
999 ptr16 = GlobalLock16( data16 );
1000 memcpy( ptr16, ptr32, size );
1001 GlobalUnlock16( data16 );
1002 set_clipboard_format( format, data16 );
1005 break;
1007 return data16;
1011 /**************************************************************************
1012 * CountClipboardFormats (USER.143)
1014 INT16 WINAPI CountClipboardFormats16(void)
1016 return CountClipboardFormats();
1020 /**************************************************************************
1021 * EnumClipboardFormats (USER.144)
1023 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
1025 return EnumClipboardFormats( id );
1029 /**************************************************************************
1030 * RegisterClipboardFormat (USER.145)
1032 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
1034 return RegisterClipboardFormatA( name );
1038 /**************************************************************************
1039 * GetClipboardFormatName (USER.146)
1041 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
1043 return GetClipboardFormatNameA( id, buffer, maxlen );
1047 /**********************************************************************
1048 * LoadMenu (USER.150)
1050 HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, LPCSTR name )
1052 HRSRC16 hRsrc;
1053 HGLOBAL16 handle;
1054 HMENU16 hMenu;
1056 if (HIWORD(name) && name[0] == '#') name = ULongToPtr(atoi( name + 1 ));
1057 if (!name) return 0;
1059 instance = GetExePtr( instance );
1060 if (!(hRsrc = FindResource16( instance, name, (LPSTR)RT_MENU ))) return 0;
1061 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
1062 hMenu = LoadMenuIndirect16(LockResource16(handle));
1063 FreeResource16( handle );
1064 return hMenu;
1068 /**********************************************************************
1069 * CreateMenu (USER.151)
1071 HMENU16 WINAPI CreateMenu16(void)
1073 return HMENU_16( CreateMenu() );
1077 /**********************************************************************
1078 * DestroyMenu (USER.152)
1080 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
1082 return DestroyMenu( HMENU_32(hMenu) );
1086 /*******************************************************************
1087 * ChangeMenu (USER.153)
1089 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
1090 UINT16 id, UINT16 flags )
1092 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
1094 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
1095 /* for MF_DELETE. We should check the parameters for all others */
1096 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
1098 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
1099 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
1100 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
1101 flags & ~MF_REMOVE );
1102 /* Default: MF_INSERT */
1103 return InsertMenu16( hMenu, pos, flags, id, data );
1107 /*******************************************************************
1108 * CheckMenuItem (USER.154)
1110 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
1112 return CheckMenuItem( HMENU_32(hMenu), id, flags );
1116 /**********************************************************************
1117 * EnableMenuItem (USER.155)
1119 BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
1121 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
1125 /**********************************************************************
1126 * GetSubMenu (USER.159)
1128 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
1130 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
1134 /*******************************************************************
1135 * GetMenuString (USER.161)
1137 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
1138 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
1140 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
1144 /**********************************************************************
1145 * WinHelp (USER.171)
1147 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
1148 DWORD dwData )
1150 BOOL ret;
1151 DWORD mutex_count;
1153 /* We might call WinExec() */
1154 ReleaseThunkLock(&mutex_count);
1156 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
1158 RestoreThunkLock(mutex_count);
1159 return ret;
1163 /***********************************************************************
1164 * LoadCursor (USER.173)
1166 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
1168 return LoadImage16( hInstance, name, IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE );
1172 /***********************************************************************
1173 * LoadIcon (USER.174)
1175 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
1177 return LoadImage16( hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE );
1180 /**********************************************************************
1181 * LoadBitmap (USER.175)
1183 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
1185 return LoadImage16( hInstance, name, IMAGE_BITMAP, 0, 0, 0 );
1188 /**********************************************************************
1189 * LoadString (USER.176)
1191 INT16 WINAPI LoadString16( HINSTANCE16 instance, UINT16 resource_id, LPSTR buffer, INT16 buflen )
1193 HGLOBAL16 hmem;
1194 HRSRC16 hrsrc;
1195 unsigned char *p;
1196 int string_num;
1197 int ret;
1199 TRACE("inst=%04x id=%04x buff=%p len=%d\n", instance, resource_id, buffer, buflen);
1201 hrsrc = FindResource16( instance, MAKEINTRESOURCEA((resource_id>>4)+1), (LPSTR)RT_STRING );
1202 if (!hrsrc) return 0;
1203 hmem = LoadResource16( instance, hrsrc );
1204 if (!hmem) return 0;
1206 p = LockResource16(hmem);
1207 string_num = resource_id & 0x000f;
1208 while (string_num--) p += *p + 1;
1210 if (buffer == NULL) ret = *p;
1211 else
1213 ret = min(buflen - 1, *p);
1214 if (ret > 0)
1216 memcpy(buffer, p + 1, ret);
1217 buffer[ret] = '\0';
1219 else if (buflen > 1)
1221 buffer[0] = '\0';
1222 ret = 0;
1224 TRACE( "%s loaded\n", debugstr_a(buffer));
1226 FreeResource16( hmem );
1227 return ret;
1230 /**********************************************************************
1231 * LoadAccelerators (USER.177)
1233 HACCEL16 WINAPI LoadAccelerators16(HINSTANCE16 instance, LPCSTR lpTableName)
1235 HRSRC16 hRsrc;
1236 HGLOBAL16 hMem;
1237 ACCEL16 *table16;
1238 HACCEL ret = 0;
1240 TRACE("%04x %s\n", instance, debugstr_a(lpTableName) );
1242 if (!(hRsrc = FindResource16( instance, lpTableName, (LPSTR)RT_ACCELERATOR )) ||
1243 !(hMem = LoadResource16(instance,hRsrc)))
1245 WARN("couldn't find %04x %s\n", instance, debugstr_a(lpTableName));
1246 return 0;
1248 if ((table16 = LockResource16( hMem )))
1250 DWORD i, count = SizeofResource16( instance, hRsrc ) / sizeof(*table16);
1251 ACCEL *table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
1252 if (table)
1254 for (i = 0; i < count; i++)
1256 table[i].fVirt = table16[i].fVirt & 0x7f;
1257 table[i].key = table16[i].key;
1258 table[i].cmd = table16[i].cmd;
1260 ret = CreateAcceleratorTableA( table, count );
1261 HeapFree( GetProcessHeap(), 0, table );
1264 FreeResource16( hMem );
1265 return HACCEL_16(ret);
1268 /***********************************************************************
1269 * GetSystemMetrics (USER.179)
1271 INT16 WINAPI GetSystemMetrics16( INT16 index )
1273 return GetSystemMetrics( index );
1277 /*************************************************************************
1278 * GetSysColor (USER.180)
1280 COLORREF WINAPI GetSysColor16( INT16 index )
1282 return GetSysColor( index );
1286 /*************************************************************************
1287 * SetSysColors (USER.181)
1289 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
1291 INT i, *list;
1293 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
1295 for (i = 0; i < count; i++) list[i] = list16[i];
1296 SetSysColors( count, list, values );
1297 HeapFree( GetProcessHeap(), 0, list );
1302 /***********************************************************************
1303 * GrayString (USER.185)
1305 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
1306 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
1307 INT16 cx, INT16 cy )
1309 BOOL ret;
1311 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
1312 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
1314 if (cch == -1 || (cch && cx && cy))
1316 /* lParam can be treated as an opaque pointer */
1317 struct gray_string_info info;
1319 info.proc = gsprc;
1320 info.param = lParam;
1321 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
1322 (LPARAM)&info, cch, x, y, cx, cy );
1324 else /* here we need some string conversions */
1326 char *str16 = MapSL(lParam);
1327 struct gray_string_info *info;
1329 if (!cch) cch = strlen(str16);
1330 info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( struct gray_string_info, str[cch] ));
1331 if (!info) return FALSE;
1332 info->proc = gsprc;
1333 info->param = lParam;
1334 memcpy( info->str, str16, cch );
1335 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
1336 (LPARAM)info->str, cch, x, y, cx, cy );
1337 HeapFree( GetProcessHeap(), 0, info );
1339 return ret;
1343 /***********************************************************************
1344 * SwapMouseButton (USER.186)
1346 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
1348 return SwapMouseButton( fSwap );
1352 /**************************************************************************
1353 * IsClipboardFormatAvailable (USER.193)
1355 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
1357 return IsClipboardFormatAvailable( wFormat );
1361 /***********************************************************************
1362 * TabbedTextOut (USER.196)
1364 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
1365 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
1367 LONG ret;
1368 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(*tabs) );
1369 if (!tabs) return 0;
1370 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
1371 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
1372 HeapFree( GetProcessHeap(), 0, tabs );
1373 return ret;
1377 /***********************************************************************
1378 * GetTabbedTextExtent (USER.197)
1380 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
1381 INT16 nb_tabs, const INT16 *tabs16 )
1383 LONG ret;
1384 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(*tabs) );
1385 if (!tabs) return 0;
1386 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
1387 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
1388 HeapFree( GetProcessHeap(), 0, tabs );
1389 return ret;
1393 /***********************************************************************
1394 * UserSeeUserDo (USER.216)
1396 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
1398 HANDLE16 oldDS = CURRENT_DS;
1399 DWORD ret = (DWORD)-1;
1401 CURRENT_DS = USER_HeapSel;
1402 switch (wReqType)
1404 case USUD_LOCALALLOC:
1405 ret = LocalAlloc16(wParam1, wParam3);
1406 break;
1407 case USUD_LOCALFREE:
1408 ret = LocalFree16(wParam1);
1409 break;
1410 case USUD_LOCALCOMPACT:
1411 ret = LocalCompact16(wParam3);
1412 break;
1413 case USUD_LOCALHEAP:
1414 ret = USER_HeapSel;
1415 break;
1416 case USUD_FIRSTCLASS:
1417 FIXME("return a pointer to the first window class.\n");
1418 break;
1419 default:
1420 WARN("wReqType %04x (unknown)\n", wReqType);
1422 CURRENT_DS = oldDS;
1423 return ret;
1427 /***********************************************************************
1428 * LookupMenuHandle (USER.217)
1430 HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
1432 FIXME( "%04x %04x: stub\n", hmenu, id );
1433 return hmenu;
1437 static LPCSTR parse_menu_resource( LPCSTR res, HMENU hMenu, BOOL oldFormat )
1439 WORD flags, id = 0;
1440 LPCSTR str;
1441 BOOL end_flag;
1445 /* Windows 3.00 and later use a WORD for the flags, whereas 1.x and 2.x use a BYTE. */
1446 if (oldFormat)
1448 flags = GET_BYTE(res);
1449 res += sizeof(BYTE);
1451 else
1453 flags = GET_WORD(res);
1454 res += sizeof(WORD);
1457 end_flag = flags & MF_END;
1458 /* Remove MF_END because it has the same value as MF_HILITE */
1459 flags &= ~MF_END;
1460 if (!(flags & MF_POPUP))
1462 id = GET_WORD(res);
1463 res += sizeof(WORD);
1465 str = res;
1466 res += strlen(str) + 1;
1467 if (flags & MF_POPUP)
1469 HMENU hSubMenu = CreatePopupMenu();
1470 if (!hSubMenu) return NULL;
1471 if (!(res = parse_menu_resource( res, hSubMenu, oldFormat ))) return NULL;
1472 AppendMenuA( hMenu, flags, (UINT_PTR)hSubMenu, str );
1474 else /* Not a popup */
1476 AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1478 } while (!end_flag);
1479 return res;
1482 /**********************************************************************
1483 * LoadMenuIndirect (USER.220)
1485 HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
1487 BOOL oldFormat;
1488 HMENU hMenu;
1489 WORD version, offset;
1490 LPCSTR p = template;
1492 TRACE("(%p)\n", template );
1494 /* Windows 1.x and 2.x menus have a slightly different menu format from 3.x menus */
1495 oldFormat = (GetExeVersion16() < 0x0300);
1497 /* Windows 3.00 and later menu items are preceded by a MENUITEMTEMPLATEHEADER structure */
1498 if (!oldFormat)
1500 version = GET_WORD(p);
1501 p += sizeof(WORD);
1502 if (version)
1504 WARN("version must be 0 for Win16 >= 3.00 applications\n" );
1505 return 0;
1507 offset = GET_WORD(p);
1508 p += sizeof(WORD) + offset;
1511 if (!(hMenu = CreateMenu())) return 0;
1512 if (!parse_menu_resource( p, hMenu, oldFormat ))
1514 DestroyMenu( hMenu );
1515 return 0;
1517 return HMENU_16(hMenu);
1521 /*************************************************************************
1522 * ScrollDC (USER.221)
1524 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
1525 const RECT16 *cliprc, HRGN16 hrgnUpdate,
1526 LPRECT16 rcUpdate )
1528 RECT rect32, clipRect32, rcUpdate32;
1529 BOOL16 ret;
1531 if (rect)
1533 rect32.left = rect->left;
1534 rect32.top = rect->top;
1535 rect32.right = rect->right;
1536 rect32.bottom = rect->bottom;
1538 if (cliprc)
1540 clipRect32.left = cliprc->left;
1541 clipRect32.top = cliprc->top;
1542 clipRect32.right = cliprc->right;
1543 clipRect32.bottom = cliprc->bottom;
1545 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
1546 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
1547 &rcUpdate32 );
1548 if (rcUpdate)
1550 rcUpdate->left = rcUpdate32.left;
1551 rcUpdate->top = rcUpdate32.top;
1552 rcUpdate->right = rcUpdate32.right;
1553 rcUpdate->bottom = rcUpdate32.bottom;
1555 return ret;
1559 /***********************************************************************
1560 * GetSystemDebugState (USER.231)
1562 WORD WINAPI GetSystemDebugState16(void)
1564 return 0; /* FIXME */
1568 /***********************************************************************
1569 * EqualRect (USER.244)
1571 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
1573 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1574 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1578 /***********************************************************************
1579 * ExitWindowsExec (USER.246)
1581 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
1583 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
1584 lpszExe, lpszParams);
1585 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
1589 /***********************************************************************
1590 * GetCursor (USER.247)
1592 HCURSOR16 WINAPI GetCursor16(void)
1594 return get_icon_16( GetCursor() );
1598 /**********************************************************************
1599 * GetAsyncKeyState (USER.249)
1601 INT16 WINAPI GetAsyncKeyState16( INT16 key )
1603 return GetAsyncKeyState( key );
1607 /**********************************************************************
1608 * GetMenuState (USER.250)
1610 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
1612 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
1616 /**************************************************************************
1617 * SendDriverMessage (USER.251)
1619 LRESULT WINAPI SendDriverMessage16(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
1620 LPARAM lParam2)
1622 FIXME("(%04x, %04x, %08Ix, %08Ix): stub\n", hDriver, msg, lParam1, lParam2);
1623 return 0;
1627 /**************************************************************************
1628 * OpenDriver (USER.252)
1630 HDRVR16 WINAPI OpenDriver16(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam2)
1632 FIXME( "(%s, %s, %08Ix): stub\n", debugstr_a(lpDriverName), debugstr_a(lpSectionName), lParam2);
1633 return 0;
1637 /**************************************************************************
1638 * CloseDriver (USER.253)
1640 LRESULT WINAPI CloseDriver16(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
1642 FIXME( "(%04x, %08Ix, %08Ix): stub\n", hDrvr, lParam1, lParam2);
1643 return FALSE;
1647 /**************************************************************************
1648 * GetDriverModuleHandle (USER.254)
1650 HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDrvr)
1652 FIXME("(%04x): stub\n", hDrvr);
1653 return 0;
1657 /**************************************************************************
1658 * DefDriverProc (USER.255)
1660 LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg,
1661 LPARAM lParam1, LPARAM lParam2)
1663 FIXME( "devID=0x%08lx hDrv=0x%04x wMsg=%04x lP1=0x%08Ix lP2=0x%08Ix: stub\n",
1664 dwDevID, hDriv, wMsg, lParam1, lParam2);
1665 return 0;
1669 /**************************************************************************
1670 * GetDriverInfo (USER.256)
1672 struct DRIVERINFOSTRUCT16;
1673 BOOL16 WINAPI GetDriverInfo16(HDRVR16 hDrvr, struct DRIVERINFOSTRUCT16 *lpDrvInfo)
1675 FIXME( "(%04x, %p): stub\n", hDrvr, lpDrvInfo);
1676 return FALSE;
1680 /**************************************************************************
1681 * GetNextDriver (USER.257)
1683 HDRVR16 WINAPI GetNextDriver16(HDRVR16 hDrvr, DWORD dwFlags)
1685 FIXME( "(%04x, %08lx): stub\n", hDrvr, dwFlags);
1686 return 0;
1690 /**********************************************************************
1691 * GetMenuItemCount (USER.263)
1693 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
1695 return GetMenuItemCount( HMENU_32(hMenu) );
1699 /**********************************************************************
1700 * GetMenuItemID (USER.264)
1702 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
1704 return GetMenuItemID( HMENU_32(hMenu), nPos );
1708 /***********************************************************************
1709 * GlobalAddAtom (USER.268)
1711 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
1713 return GlobalAddAtomA(lpString);
1716 /***********************************************************************
1717 * GlobalDeleteAtom (USER.269)
1719 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
1721 return GlobalDeleteAtom(nAtom);
1724 /***********************************************************************
1725 * GlobalFindAtom (USER.270)
1727 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
1729 return GlobalFindAtomA(lpString);
1732 /***********************************************************************
1733 * GlobalGetAtomName (USER.271)
1735 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
1737 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
1741 /***********************************************************************
1742 * ControlPanelInfo (USER.273)
1744 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
1746 FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
1750 /***********************************************************************
1751 * OldSetDeskPattern (USER.279)
1753 BOOL16 WINAPI SetDeskPattern16(void)
1755 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
1759 /***********************************************************************
1760 * GetSysColorBrush (USER.281)
1762 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
1764 return HBRUSH_16( GetSysColorBrush(index) );
1768 /***********************************************************************
1769 * SelectPalette (USER.282)
1771 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
1773 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
1776 /***********************************************************************
1777 * RealizePalette (USER.283)
1779 UINT16 WINAPI RealizePalette16( HDC16 hdc )
1781 return UserRealizePalette( HDC_32(hdc) );
1785 /***********************************************************************
1786 * GetFreeSystemResources (USER.284)
1788 WORD WINAPI GetFreeSystemResources16( WORD resType )
1790 HANDLE16 oldDS = CURRENT_DS;
1791 int userPercent, gdiPercent;
1793 switch(resType)
1795 case GFSR_USERRESOURCES:
1796 CURRENT_DS = USER_HeapSel;
1797 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1798 gdiPercent = 100;
1799 CURRENT_DS = oldDS;
1800 break;
1802 case GFSR_GDIRESOURCES:
1803 CURRENT_DS = gdi_inst;
1804 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1805 userPercent = 100;
1806 CURRENT_DS = oldDS;
1807 break;
1809 case GFSR_SYSTEMRESOURCES:
1810 CURRENT_DS = USER_HeapSel;
1811 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1812 CURRENT_DS = gdi_inst;
1813 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
1814 CURRENT_DS = oldDS;
1815 break;
1817 default:
1818 userPercent = gdiPercent = 0;
1819 break;
1821 TRACE("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
1822 return (WORD)min( userPercent, gdiPercent );
1826 /***********************************************************************
1827 * SetDeskWallPaper (USER.285)
1829 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
1831 return SetDeskWallPaper( filename );
1835 /***********************************************************************
1836 * keybd_event (USER.289)
1838 void WINAPI keybd_event16( CONTEXT *context )
1840 DWORD dwFlags = 0;
1842 if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
1843 if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;
1845 keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
1846 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
1850 /***********************************************************************
1851 * mouse_event (USER.299)
1853 void WINAPI mouse_event16( CONTEXT *context )
1855 mouse_event( LOWORD(context->Eax), LOWORD(context->Ebx), LOWORD(context->Ecx),
1856 LOWORD(context->Edx), MAKELONG(context->Esi, context->Edi) );
1860 /***********************************************************************
1861 * GetClipCursor (USER.309)
1863 void WINAPI GetClipCursor16( RECT16 *rect )
1865 if (rect)
1867 RECT rect32;
1868 GetClipCursor( &rect32 );
1869 rect->left = rect32.left;
1870 rect->top = rect32.top;
1871 rect->right = rect32.right;
1872 rect->bottom = rect32.bottom;
1877 /***********************************************************************
1878 * SignalProc (USER.314)
1880 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
1881 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
1883 if (code == USIG16_DLL_UNLOAD)
1885 hModule = GetExePtr(hModule);
1886 /* HOOK_FreeModuleHooks( hModule ); */
1887 free_module_classes( hModule );
1888 free_module_icons( hModule );
1893 /***********************************************************************
1894 * SetEventHook (USER.321)
1896 * Used by Turbo Debugger for Windows
1898 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
1900 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
1901 return 0;
1905 /**********************************************************************
1906 * EnableHardwareInput (USER.331)
1908 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
1910 FIXME("(%d) - stub\n", bEnable);
1911 return TRUE;
1915 /**********************************************************************
1916 * LoadCursorIconHandler (USER.336)
1918 * Supposed to load resources of Windows 2.x applications.
1920 HGLOBAL16 WINAPI LoadCursorIconHandler16( HGLOBAL16 hResource, HMODULE16 hModule, HRSRC16 hRsrc )
1922 FIXME("(%04x,%04x,%04x): old 2.x resources are not supported!\n", hResource, hModule, hRsrc);
1923 return 0;
1927 /***********************************************************************
1928 * GetMouseEventProc (USER.337)
1930 FARPROC16 WINAPI GetMouseEventProc16(void)
1932 HMODULE16 hmodule = GetModuleHandle16("USER");
1933 return GetProcAddress16( hmodule, "mouse_event" );
1937 /***********************************************************************
1938 * IsUserIdle (USER.333)
1940 BOOL16 WINAPI IsUserIdle16(void)
1942 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
1943 return FALSE;
1944 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
1945 return FALSE;
1946 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
1947 return FALSE;
1948 /* Should check for screen saver activation here ... */
1949 return TRUE;
1953 /**********************************************************************
1954 * LoadDIBIconHandler (USER.357)
1956 * RT_ICON resource loader, installed by USER_SignalProc when module
1957 * is initialized.
1959 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1961 /* If hResource is zero we must allocate a new memory block, if it's
1962 * non-zero but GlobalLock() returns NULL then it was discarded and
1963 * we have to recommit some memory, otherwise we just need to check
1964 * the block size. See LoadProc() in 16-bit SDK for more.
1966 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1967 return 0;
1970 /**********************************************************************
1971 * LoadDIBCursorHandler (USER.356)
1973 * RT_CURSOR resource loader. Same as above.
1975 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1977 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1978 return 0;
1982 /**********************************************************************
1983 * IsMenu (USER.358)
1985 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
1987 return IsMenu( HMENU_32(hmenu) );
1991 /***********************************************************************
1992 * DCHook (USER.362)
1994 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1996 FIXME( "hDC = %x, %i: stub\n", hdc, code );
1997 return FALSE;
2001 /**********************************************************************
2002 * LookupIconIdFromDirectoryEx (USER.364)
2004 * FIXME: exact parameter sizes
2006 INT16 WINAPI LookupIconIdFromDirectoryEx16( LPBYTE dir, BOOL16 bIcon,
2007 INT16 width, INT16 height, UINT16 cFlag )
2009 return LookupIconIdFromDirectoryEx( dir, bIcon, width, height, cFlag );
2013 /***********************************************************************
2014 * CopyIcon (USER.368)
2016 HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
2018 CURSORICONINFO *info = get_icon_ptr( hIcon );
2019 void *and_bits = info + 1;
2020 void *xor_bits = (BYTE *)and_bits + info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2021 HGLOBAL16 ret = CreateCursorIconIndirect16( hInstance, info, and_bits, xor_bits );
2022 release_icon_ptr( hIcon, info );
2023 return ret;
2027 /***********************************************************************
2028 * CopyCursor (USER.369)
2030 HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
2032 CURSORICONINFO *info = get_icon_ptr( hCursor );
2033 void *and_bits = info + 1;
2034 void *xor_bits = (BYTE *)and_bits + info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2035 HGLOBAL16 ret = CreateCursorIconIndirect16( hInstance, info, and_bits, xor_bits );
2036 release_icon_ptr( hCursor, info );
2037 return ret;
2041 /***********************************************************************
2042 * SubtractRect (USER.373)
2044 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
2045 const RECT16 *src2 )
2047 RECT16 tmp;
2049 if (IsRectEmpty16( src1 ))
2051 SetRectEmpty16( dest );
2052 return FALSE;
2054 *dest = *src1;
2055 if (IntersectRect16( &tmp, src1, src2 ))
2057 if (EqualRect16( &tmp, dest ))
2059 SetRectEmpty16( dest );
2060 return FALSE;
2062 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
2064 if (tmp.left == dest->left) dest->left = tmp.right;
2065 else if (tmp.right == dest->right) dest->right = tmp.left;
2067 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
2069 if (tmp.top == dest->top) dest->top = tmp.bottom;
2070 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
2073 return TRUE;
2077 /**********************************************************************
2078 * DllEntryPoint (USER.374)
2080 BOOL WINAPI DllEntryPoint( DWORD reason, HINSTANCE16 inst, WORD ds,
2081 WORD heap, DWORD reserved1, WORD reserved2 )
2083 if (reason != DLL_PROCESS_ATTACH) return TRUE;
2084 if (USER_HeapSel) return TRUE; /* already called */
2086 USER_HeapSel = ds;
2087 register_wow_handlers();
2088 gdi_inst = LoadLibrary16( "gdi.exe" );
2089 LoadLibrary16( "display.drv" );
2090 LoadLibrary16( "keyboard.drv" );
2091 LoadLibrary16( "mouse.drv" );
2092 LoadLibrary16( "user.exe" ); /* make sure it never gets unloaded */
2093 return TRUE;
2097 /**********************************************************************
2098 * SetMenuContextHelpId (USER.384)
2100 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
2102 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
2106 /**********************************************************************
2107 * GetMenuContextHelpId (USER.385)
2109 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
2111 return GetMenuContextHelpId( HMENU_32(hMenu) );
2115 /***********************************************************************
2116 * LoadImage (USER.389)
2118 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type, INT16 cx, INT16 cy, UINT16 flags)
2120 HGLOBAL16 handle;
2121 HRSRC16 hRsrc, hGroupRsrc;
2122 DWORD size;
2124 if (!hinst || (flags & LR_LOADFROMFILE))
2126 if (type == IMAGE_BITMAP)
2127 return HBITMAP_16( LoadImageA( 0, name, type, cx, cy, flags ));
2128 else
2129 return get_icon_16( LoadImageA( 0, name, type, cx, cy, flags ));
2132 hinst = GetExePtr( hinst );
2134 if (flags & LR_DEFAULTSIZE)
2136 if (type == IMAGE_ICON)
2138 if (!cx) cx = GetSystemMetrics(SM_CXICON);
2139 if (!cy) cy = GetSystemMetrics(SM_CYICON);
2141 else if (type == IMAGE_CURSOR)
2143 if (!cx) cx = GetSystemMetrics(SM_CXCURSOR);
2144 if (!cy) cy = GetSystemMetrics(SM_CYCURSOR);
2148 switch (type)
2150 case IMAGE_BITMAP:
2152 HBITMAP ret = 0;
2153 char *ptr;
2154 static const WCHAR prefixW[] = {'b','m','p',0};
2155 BITMAPFILEHEADER header;
2156 WCHAR path[MAX_PATH], filename[MAX_PATH];
2157 HANDLE file;
2159 filename[0] = 0;
2160 if (!(hRsrc = FindResource16( hinst, name, (LPCSTR)RT_BITMAP ))) return 0;
2161 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2162 if (!(ptr = LockResource16( handle ))) goto done;
2163 size = SizeofResource16( hinst, hRsrc );
2165 header.bfType = 0x4d42; /* 'BM' */
2166 header.bfReserved1 = 0;
2167 header.bfReserved2 = 0;
2168 header.bfSize = sizeof(header) + size;
2169 header.bfOffBits = 0; /* not used by the 32-bit loading code */
2171 if (!GetTempPathW( MAX_PATH, path )) goto done;
2172 if (!GetTempFileNameW( path, prefixW, 0, filename )) goto done;
2174 file = CreateFileW( filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
2175 if (file != INVALID_HANDLE_VALUE)
2177 DWORD written;
2178 BOOL ok;
2179 ok = WriteFile( file, &header, sizeof(header), &written, NULL ) && (written == sizeof(header));
2180 if (ok) ok = WriteFile( file, ptr, size, &written, NULL ) && (written == size);
2181 CloseHandle( file );
2182 if (ok) ret = LoadImageW( 0, filename, IMAGE_BITMAP, cx, cy, flags | LR_LOADFROMFILE );
2184 done:
2185 if (filename[0]) DeleteFileW( filename );
2186 FreeResource16( handle );
2187 return HBITMAP_16( ret );
2190 case IMAGE_ICON:
2191 case IMAGE_CURSOR:
2193 HICON16 hIcon = 0;
2194 BYTE *dir, *bits;
2195 INT id = 0;
2197 if (!(hRsrc = FindResource16( hinst, name,
2198 (LPCSTR)(type == IMAGE_ICON ? RT_GROUP_ICON : RT_GROUP_CURSOR ))))
2199 return 0;
2200 hGroupRsrc = hRsrc;
2202 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2203 if ((dir = LockResource16( handle ))) id = LookupIconIdFromDirectory( dir, type == IMAGE_ICON );
2204 FreeResource16( handle );
2205 if (!id) return 0;
2207 if (!(hRsrc = FindResource16( hinst, MAKEINTRESOURCEA(id),
2208 (LPCSTR)(type == IMAGE_ICON ? RT_ICON : RT_CURSOR) ))) return 0;
2210 if ((flags & LR_SHARED) && (hIcon = find_shared_icon( hinst, hRsrc ) ) != 0) return hIcon;
2212 if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
2213 bits = LockResource16( handle );
2214 size = SizeofResource16( hinst, hRsrc );
2215 hIcon = CreateIconFromResourceEx16( bits, size, type == IMAGE_ICON, 0x00030000, cx, cy, flags );
2216 FreeResource16( handle );
2218 if (hIcon && (flags & LR_SHARED)) add_shared_icon( hinst, hRsrc, hGroupRsrc, hIcon );
2219 return hIcon;
2221 default:
2222 return 0;
2226 /******************************************************************************
2227 * CopyImage (USER.390) Creates new image and copies attributes to it
2230 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
2231 INT16 desiredy, UINT16 flags)
2233 if (flags & LR_COPYFROMRESOURCE) FIXME( "LR_COPYFROMRESOURCE not supported\n" );
2235 switch (type)
2237 case IMAGE_BITMAP:
2238 return HBITMAP_16( CopyImage( HBITMAP_32(hnd), type, desiredx, desiredy, flags ));
2239 case IMAGE_ICON:
2240 case IMAGE_CURSOR:
2241 return CopyIcon16( FarGetOwner16(hnd), hnd );
2242 default:
2243 return 0;
2247 /**********************************************************************
2248 * DrawIconEx (USER.394)
2250 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
2251 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
2252 HBRUSH16 hbr, UINT16 flags)
2254 return DrawIconEx(HDC_32(hdc), xLeft, yTop, get_icon_32(hIcon), cxWidth, cyWidth,
2255 istep, HBRUSH_32(hbr), flags);
2258 /**********************************************************************
2259 * GetIconInfo (USER.395)
2261 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
2263 CURSORICONINFO *info = get_icon_ptr( hIcon );
2264 INT height;
2266 if (!info) return FALSE;
2268 if ((info->ptHotSpot.x == ICON_HOTSPOT) && (info->ptHotSpot.y == ICON_HOTSPOT))
2270 iconinfo->fIcon = TRUE;
2271 iconinfo->xHotspot = info->nWidth / 2;
2272 iconinfo->yHotspot = info->nHeight / 2;
2274 else
2276 iconinfo->fIcon = FALSE;
2277 iconinfo->xHotspot = info->ptHotSpot.x;
2278 iconinfo->yHotspot = info->ptHotSpot.y;
2281 height = info->nHeight;
2283 if (info->bBitsPerPixel > 1)
2285 iconinfo->hbmColor = HBITMAP_16( CreateBitmap( info->nWidth, info->nHeight,
2286 info->bPlanes, info->bBitsPerPixel,
2287 (char *)(info + 1)
2288 + info->nHeight *
2289 get_bitmap_width_bytes(info->nWidth,1) ));
2291 else
2293 iconinfo->hbmColor = 0;
2294 height *= 2;
2297 iconinfo->hbmMask = HBITMAP_16( CreateBitmap( info->nWidth, height, 1, 1, info + 1 ));
2298 release_icon_ptr( hIcon, info );
2299 return TRUE;
2303 /***********************************************************************
2304 * FinalUserInit (USER.400)
2306 void WINAPI FinalUserInit16( void )
2308 /* FIXME: Should chain to FinalGdiInit */
2312 /***********************************************************************
2313 * CreateCursor (USER.406)
2315 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
2316 INT16 xHotSpot, INT16 yHotSpot,
2317 INT16 nWidth, INT16 nHeight,
2318 LPCVOID lpANDbits, LPCVOID lpXORbits)
2320 CURSORICONINFO info;
2322 info.ptHotSpot.x = xHotSpot;
2323 info.ptHotSpot.y = yHotSpot;
2324 info.nWidth = nWidth;
2325 info.nHeight = nHeight;
2326 info.nWidthBytes = 0;
2327 info.bPlanes = 1;
2328 info.bBitsPerPixel = 1;
2330 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
2334 /***********************************************************************
2335 * CreateIcon (USER.407)
2337 HICON16 WINAPI CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth,
2338 INT16 nHeight, BYTE bPlanes, BYTE bBitsPixel,
2339 LPCVOID lpANDbits, LPCVOID lpXORbits )
2341 CURSORICONINFO info;
2343 info.ptHotSpot.x = ICON_HOTSPOT;
2344 info.ptHotSpot.y = ICON_HOTSPOT;
2345 info.nWidth = nWidth;
2346 info.nHeight = nHeight;
2347 info.nWidthBytes = 0;
2348 info.bPlanes = bPlanes;
2349 info.bBitsPerPixel = bBitsPixel;
2351 return CreateCursorIconIndirect16( hInstance, &info, lpANDbits, lpXORbits );
2355 /***********************************************************************
2356 * CreateCursorIconIndirect (USER.408)
2358 HGLOBAL16 WINAPI CreateCursorIconIndirect16( HINSTANCE16 hInstance,
2359 CURSORICONINFO *info,
2360 LPCVOID lpANDbits,
2361 LPCVOID lpXORbits )
2363 HICON16 handle;
2364 CURSORICONINFO *ptr;
2365 int sizeAnd, sizeXor;
2367 hInstance = GetExePtr( hInstance ); /* Make it a module handle */
2368 if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
2369 info->nWidthBytes = get_bitmap_width_bytes(info->nWidth,info->bBitsPerPixel);
2370 sizeXor = info->nHeight * info->nWidthBytes;
2371 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2372 if (!(handle = alloc_icon_handle( sizeof(CURSORICONINFO) + sizeXor + sizeAnd )))
2373 return 0;
2374 FarSetOwner16( handle, hInstance );
2375 ptr = get_icon_ptr( handle );
2376 memcpy( ptr, info, sizeof(*info) );
2377 memcpy( ptr + 1, lpANDbits, sizeAnd );
2378 memcpy( (char *)(ptr + 1) + sizeAnd, lpXORbits, sizeXor );
2379 release_icon_ptr( handle, ptr );
2380 return handle;
2384 /***********************************************************************
2385 * InitThreadInput (USER.409)
2387 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
2389 /* nothing to do here */
2390 return 0xbeef;
2394 /*******************************************************************
2395 * InsertMenu (USER.410)
2397 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
2398 UINT16 id, SEGPTR data )
2400 UINT pos32 = (UINT)pos;
2401 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
2402 if (IS_MENU_STRING_ITEM(flags) && data)
2403 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
2405 /* If "data" is an HBITMAP, the high WORD will contain the application's DGROUP selector if the
2406 * application cast (LPSTR)hBitmap rather than (LPSTR)(LONG)hBitmap. */
2407 if (flags & MF_BITMAP) data = (SEGPTR)HBITMAP_32(LOWORD(data));
2408 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
2412 /*******************************************************************
2413 * AppendMenu (USER.411)
2415 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
2417 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
2421 /**********************************************************************
2422 * RemoveMenu (USER.412)
2424 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
2426 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
2430 /**********************************************************************
2431 * DeleteMenu (USER.413)
2433 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
2435 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
2439 /*******************************************************************
2440 * ModifyMenu (USER.414)
2442 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
2443 UINT16 id, SEGPTR data )
2445 if (IS_MENU_STRING_ITEM(flags))
2446 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
2447 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
2451 /**********************************************************************
2452 * CreatePopupMenu (USER.415)
2454 HMENU16 WINAPI CreatePopupMenu16(void)
2456 return HMENU_16( CreatePopupMenu() );
2460 /**********************************************************************
2461 * SetMenuItemBitmaps (USER.418)
2463 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
2464 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
2466 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
2467 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
2471 /***********************************************************************
2472 * wvsprintf (USER.421)
2474 INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 args )
2476 WPRINTF_FORMAT format;
2477 LPSTR p = buffer;
2478 UINT i, len, sign;
2479 CHAR number[20];
2480 CHAR char_view = 0;
2481 LPCSTR lpcstr_view = NULL;
2482 INT int_view;
2483 SEGPTR seg_str;
2485 while (*spec)
2487 if (*spec != '%') { *p++ = *spec++; continue; }
2488 spec++;
2489 if (*spec == '%') { *p++ = *spec++; continue; }
2490 spec += parse_format( spec, &format );
2491 switch(format.type)
2493 case WPR_CHAR:
2494 char_view = VA_ARG16( args, CHAR );
2495 len = format.precision = 1;
2496 break;
2497 case WPR_STRING:
2498 seg_str = VA_ARG16( args, SEGPTR );
2499 if (IsBadReadPtr16( seg_str, 1 )) lpcstr_view = "";
2500 else lpcstr_view = MapSL( seg_str );
2501 if (!lpcstr_view) lpcstr_view = "(null)";
2502 for (len = 0; !format.precision || (len < format.precision); len++)
2503 if (!lpcstr_view[len]) break;
2504 format.precision = len;
2505 break;
2506 case WPR_SIGNED:
2507 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, INT );
2508 else int_view = VA_ARG16( args, INT16 );
2509 len = sprintf( number, "%d", int_view );
2510 break;
2511 case WPR_UNSIGNED:
2512 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
2513 else int_view = VA_ARG16( args, UINT16 );
2514 len = sprintf( number, "%u", int_view );
2515 break;
2516 case WPR_HEXA:
2517 if (format.flags & WPRINTF_LONG) int_view = VA_ARG16( args, UINT );
2518 else int_view = VA_ARG16( args, UINT16 );
2519 len = sprintf( number, (format.flags & WPRINTF_UPPER_HEX) ? "%X" : "%x", int_view);
2520 break;
2521 case WPR_UNKNOWN:
2522 continue;
2524 if (format.precision < len) format.precision = len;
2525 if (format.flags & WPRINTF_LEFTALIGN) format.flags &= ~WPRINTF_ZEROPAD;
2526 if ((format.flags & WPRINTF_ZEROPAD) && (format.width > format.precision))
2527 format.precision = format.width;
2528 if (format.flags & WPRINTF_PREFIX_HEX) len += 2;
2530 sign = 0;
2531 if (!(format.flags & WPRINTF_LEFTALIGN))
2532 for (i = format.precision; i < format.width; i++) *p++ = ' ';
2533 switch(format.type)
2535 case WPR_CHAR:
2536 *p = char_view;
2537 /* wsprintf16 ignores null characters */
2538 if (*p != '\0') p++;
2539 else if (format.width > 1) *p++ = ' ';
2540 break;
2541 case WPR_STRING:
2542 if (len) memcpy( p, lpcstr_view, len );
2543 p += len;
2544 break;
2545 case WPR_HEXA:
2546 if (format.flags & WPRINTF_PREFIX_HEX)
2548 *p++ = '0';
2549 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
2550 len -= 2;
2552 /* fall through */
2553 case WPR_SIGNED:
2554 /* Transfer the sign now, just in case it will be zero-padded*/
2555 if (number[0] == '-')
2557 *p++ = '-';
2558 sign = 1;
2560 /* fall through */
2561 case WPR_UNSIGNED:
2562 for (i = len; i < format.precision; i++) *p++ = '0';
2563 if (len > sign) memcpy( p, number + sign, len - sign );
2564 p += len-sign;
2565 break;
2566 case WPR_UNKNOWN:
2567 continue;
2569 if (format.flags & WPRINTF_LEFTALIGN)
2570 for (i = format.precision; i < format.width; i++) *p++ = ' ';
2572 *p = 0;
2573 return p - buffer;
2577 /***********************************************************************
2578 * _wsprintf (USER.420)
2580 INT16 WINAPIV wsprintf16( LPSTR buffer, LPCSTR spec, VA_LIST16 valist )
2582 return wvsprintf16( buffer, spec, valist );
2586 /***********************************************************************
2587 * lstrcmp (USER.430)
2589 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
2591 int ret;
2592 /* Looks too complicated, but in optimized strcpy we might get
2593 * a 32bit wide difference and would truncate it to 16 bit, so
2594 * erroneously returning equality. */
2595 ret = strcmp( str1, str2 );
2596 if (ret < 0) return -1;
2597 if (ret > 0) return 1;
2598 return 0;
2602 /***********************************************************************
2603 * AnsiUpper (USER.431)
2605 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
2607 /* uppercase only one char if strOrChar < 0x10000 */
2608 if (HIWORD(strOrChar))
2610 CharUpperA( MapSL(strOrChar) );
2611 return strOrChar;
2613 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
2617 /***********************************************************************
2618 * AnsiLower (USER.432)
2620 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
2622 /* lowercase only one char if strOrChar < 0x10000 */
2623 if (HIWORD(strOrChar))
2625 CharLowerA( MapSL(strOrChar) );
2626 return strOrChar;
2628 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
2632 /***********************************************************************
2633 * AnsiUpperBuff (USER.437)
2635 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
2637 CharUpperBuffA( str, len ? len : 65536 );
2638 return len;
2642 /***********************************************************************
2643 * AnsiLowerBuff (USER.438)
2645 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
2647 CharLowerBuffA( str, len ? len : 65536 );
2648 return len;
2652 /*******************************************************************
2653 * InsertMenuItem (USER.441)
2655 * FIXME: untested
2657 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
2658 const MENUITEMINFO16 *mii )
2660 MENUITEMINFOA miia;
2662 miia.cbSize = sizeof(miia);
2663 miia.fMask = mii->fMask;
2664 miia.dwTypeData = (LPSTR)mii->dwTypeData;
2665 miia.fType = mii->fType;
2666 miia.fState = mii->fState;
2667 miia.wID = mii->wID;
2668 miia.hSubMenu = HMENU_32(mii->hSubMenu);
2669 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
2670 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
2671 miia.dwItemData = mii->dwItemData;
2672 miia.cch = mii->cch;
2673 if (IS_MENU_STRING_ITEM(miia.fType))
2674 miia.dwTypeData = MapSL(mii->dwTypeData);
2675 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
2679 /**********************************************************************
2680 * DrawState (USER.449)
2682 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
2683 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
2685 struct draw_state_info info;
2686 UINT opcode = flags & 0xf;
2688 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
2690 /* make sure DrawStateA doesn't try to use ldata as a pointer */
2691 if (!wdata) wdata = strlen( MapSL(ldata) );
2692 if (!cx || !cy)
2694 SIZE s;
2695 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
2696 if (!cx) cx = s.cx;
2697 if (!cy) cy = s.cy;
2700 info.proc = func;
2701 info.param = ldata;
2702 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
2703 (LPARAM)&info, wdata, x, y, cx, cy, flags );
2707 /**********************************************************************
2708 * CreateIconFromResourceEx (USER.450)
2710 * FIXME: not sure about exact parameter types
2712 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
2713 BOOL16 bIcon, DWORD dwVersion,
2714 INT16 width, INT16 height,
2715 UINT16 cFlag)
2717 return get_icon_16( CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, width, height, cFlag ));
2721 /***********************************************************************
2722 * AdjustWindowRectEx (USER.454)
2724 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
2726 RECT rect32;
2727 BOOL ret;
2729 rect32.left = rect->left;
2730 rect32.top = rect->top;
2731 rect32.right = rect->right;
2732 rect32.bottom = rect->bottom;
2733 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
2734 rect->left = rect32.left;
2735 rect->top = rect32.top;
2736 rect->right = rect32.right;
2737 rect->bottom = rect32.bottom;
2738 return ret;
2742 /**********************************************************************
2743 * GetIconID (USER.455)
2745 WORD WINAPI GetIconID16( HGLOBAL16 hResource, DWORD resType )
2747 BYTE *dir = GlobalLock16(hResource);
2749 switch (resType)
2751 case RT_CURSOR:
2752 return LookupIconIdFromDirectoryEx16( dir, FALSE, GetSystemMetrics(SM_CXCURSOR),
2753 GetSystemMetrics(SM_CYCURSOR), LR_MONOCHROME );
2754 case RT_ICON:
2755 return LookupIconIdFromDirectoryEx16( dir, TRUE, GetSystemMetrics(SM_CXICON),
2756 GetSystemMetrics(SM_CYICON), 0 );
2758 return 0;
2762 /**********************************************************************
2763 * LoadIconHandler (USER.456)
2765 HICON16 WINAPI LoadIconHandler16( HGLOBAL16 hResource, BOOL16 bNew )
2767 return CreateIconFromResourceEx16( LockResource16( hResource ), 0xffff, TRUE,
2768 bNew ? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR );
2772 /***********************************************************************
2773 * DestroyIcon (USER.457)
2775 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
2777 int count;
2779 TRACE("%04x\n", hIcon );
2781 count = release_shared_icon( hIcon );
2782 if (count != -1) return !count;
2783 /* assume non-shared */
2784 free_icon_handle( hIcon );
2785 return TRUE;
2788 /***********************************************************************
2789 * DestroyCursor (USER.458)
2791 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
2793 return DestroyIcon16( hCursor );
2797 /***********************************************************************
2798 * DumpIcon (USER.459)
2800 DWORD WINAPI DumpIcon16( SEGPTR pInfo, WORD *lpLen,
2801 SEGPTR *lpXorBits, SEGPTR *lpAndBits )
2803 CURSORICONINFO *info = MapSL( pInfo );
2804 int sizeAnd, sizeXor;
2806 if (!info) return 0;
2807 sizeXor = info->nHeight * info->nWidthBytes;
2808 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
2809 if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
2810 if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
2811 if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
2812 return MAKELONG( sizeXor, sizeXor );
2816 /*******************************************************************
2817 * DRAG_QueryUpdate16
2819 * Recursively find a child that contains spDragInfo->pt point
2820 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
2822 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
2824 BOOL bResult;
2825 WPARAM wParam;
2826 POINT pt, old_pt;
2827 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
2828 RECT tempRect;
2829 HWND child;
2831 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
2833 old_pt.x = ptrDragInfo->pt.x;
2834 old_pt.y = ptrDragInfo->pt.y;
2835 pt = old_pt;
2836 ScreenToClient( hQueryWnd, &pt );
2837 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
2838 if (!child) return FALSE;
2840 if (child != hQueryWnd)
2842 wParam = 0;
2843 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
2845 else
2847 GetClientRect( hQueryWnd, &tempRect );
2848 wParam = !PtInRect( &tempRect, pt );
2851 ptrDragInfo->pt.x = pt.x;
2852 ptrDragInfo->pt.y = pt.y;
2853 ptrDragInfo->hScope = HWND_16(hQueryWnd);
2855 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
2857 if (!bResult)
2859 ptrDragInfo->pt.x = old_pt.x;
2860 ptrDragInfo->pt.y = old_pt.y;
2862 return bResult;
2866 /******************************************************************************
2867 * DragObject (USER.464)
2869 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
2870 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
2872 MSG msg;
2873 LPDRAGINFO16 lpDragInfo;
2874 SEGPTR spDragInfo;
2875 HCURSOR hOldCursor=0, hBummer=0, hCursor32;
2876 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
2877 HCURSOR hCurrentCursor = 0;
2878 HWND16 hCurrentWnd = 0;
2880 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
2881 spDragInfo = WOWGlobalLock16(hDragInfo);
2883 if( !lpDragInfo || !spDragInfo ) return 0L;
2885 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
2887 GlobalFree16(hDragInfo);
2888 return 0L;
2891 if ((hCursor32 = get_icon_32( hCursor ))) SetCursor( hCursor32 );
2893 lpDragInfo->hWnd = hWnd;
2894 lpDragInfo->hScope = 0;
2895 lpDragInfo->wFlags = wObj;
2896 lpDragInfo->hList = szList; /* near pointer! */
2897 lpDragInfo->hOfStruct = hOfStruct;
2898 lpDragInfo->l = 0L;
2900 SetCapture( HWND_32(hWnd) );
2901 ShowCursor( TRUE );
2905 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
2907 *(lpDragInfo+1) = *lpDragInfo;
2909 lpDragInfo->pt.x = msg.pt.x;
2910 lpDragInfo->pt.y = msg.pt.y;
2912 /* update DRAGINFO struct */
2913 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
2914 hCurrentCursor = hCursor32;
2915 else
2917 hCurrentCursor = hBummer;
2918 lpDragInfo->hScope = 0;
2920 if( hCurrentCursor )
2921 SetCursor(hCurrentCursor);
2923 /* send WM_DRAGLOOP */
2924 SendMessage16( hWnd, WM_DRAGLOOP, hCurrentCursor != hBummer, spDragInfo );
2925 /* send WM_DRAGSELECT or WM_DRAGMOVE */
2926 if( hCurrentWnd != lpDragInfo->hScope )
2928 if( hCurrentWnd )
2929 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
2930 MAKELPARAM(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
2931 HIWORD(spDragInfo)) );
2932 hCurrentWnd = lpDragInfo->hScope;
2933 if( hCurrentWnd )
2934 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, spDragInfo);
2936 else
2937 if( hCurrentWnd )
2938 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, spDragInfo);
2940 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
2942 ReleaseCapture();
2943 ShowCursor( FALSE );
2945 if( hCursor ) SetCursor(hOldCursor);
2947 if( hCurrentCursor != hBummer )
2948 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
2949 hWnd, spDragInfo );
2950 else
2951 msg.lParam = 0;
2952 GlobalFree16(hDragInfo);
2954 return (DWORD)(msg.lParam);
2958 /***********************************************************************
2959 * DrawFocusRect (USER.466)
2961 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
2963 RECT rect32;
2965 rect32.left = rc->left;
2966 rect32.top = rc->top;
2967 rect32.right = rc->right;
2968 rect32.bottom = rc->bottom;
2969 DrawFocusRect( HDC_32(hdc), &rect32 );
2973 /***********************************************************************
2974 * AnsiNext (USER.472)
2976 SEGPTR WINAPI AnsiNext16(SEGPTR current)
2978 char *ptr = MapSL(current);
2979 return current + (CharNextA(ptr) - ptr);
2983 /***********************************************************************
2984 * AnsiPrev (USER.473)
2986 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
2988 char *ptr = MapSL(current);
2989 return current - (ptr - CharPrevA( start, ptr ));
2993 /****************************************************************************
2994 * GetKeyboardLayoutName (USER.477)
2996 INT16 WINAPI GetKeyboardLayoutName16( LPSTR name )
2998 return GetKeyboardLayoutNameA( name );
3002 /***********************************************************************
3003 * SystemParametersInfo (USER.483)
3005 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
3006 LPVOID lpvParam, UINT16 fuWinIni )
3008 BOOL16 ret;
3010 TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
3012 switch (uAction)
3014 case SPI_GETBEEP:
3015 case SPI_GETSCREENSAVEACTIVE:
3016 case SPI_GETICONTITLEWRAP:
3017 case SPI_GETMENUDROPALIGNMENT:
3018 case SPI_GETFASTTASKSWITCH:
3019 case SPI_GETDRAGFULLWINDOWS:
3021 BOOL tmp;
3022 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3023 if (ret && lpvParam) *(BOOL16 *)lpvParam = tmp;
3024 break;
3027 case SPI_GETBORDER:
3028 case SPI_ICONHORIZONTALSPACING:
3029 case SPI_GETSCREENSAVETIMEOUT:
3030 case SPI_GETGRIDGRANULARITY:
3031 case SPI_GETKEYBOARDDELAY:
3032 case SPI_ICONVERTICALSPACING:
3034 INT tmp;
3035 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3036 if (ret && lpvParam) *(INT16 *)lpvParam = tmp;
3037 break;
3040 case SPI_GETKEYBOARDSPEED:
3041 case SPI_GETMOUSEHOVERWIDTH:
3042 case SPI_GETMOUSEHOVERHEIGHT:
3043 case SPI_GETMOUSEHOVERTIME:
3045 DWORD tmp;
3046 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3047 if (ret && lpvParam) *(WORD *)lpvParam = tmp;
3048 break;
3051 case SPI_GETICONTITLELOGFONT:
3053 LOGFONTA tmp;
3054 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3055 if (ret && lpvParam) logfont_32_to_16( &tmp, (LPLOGFONT16)lpvParam );
3056 break;
3059 case SPI_GETNONCLIENTMETRICS:
3061 NONCLIENTMETRICSA tmp;
3062 LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
3063 if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
3065 tmp.cbSize = sizeof(NONCLIENTMETRICSA);
3066 ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
3067 if (ret)
3069 lpnm16->iBorderWidth = tmp.iBorderWidth;
3070 lpnm16->iScrollWidth = tmp.iScrollWidth;
3071 lpnm16->iScrollHeight = tmp.iScrollHeight;
3072 lpnm16->iCaptionWidth = tmp.iCaptionWidth;
3073 lpnm16->iCaptionHeight = tmp.iCaptionHeight;
3074 lpnm16->iSmCaptionWidth = tmp.iSmCaptionWidth;
3075 lpnm16->iSmCaptionHeight = tmp.iSmCaptionHeight;
3076 lpnm16->iMenuWidth = tmp.iMenuWidth;
3077 lpnm16->iMenuHeight = tmp.iMenuHeight;
3078 logfont_32_to_16( &tmp.lfCaptionFont, &lpnm16->lfCaptionFont );
3079 logfont_32_to_16( &tmp.lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
3080 logfont_32_to_16( &tmp.lfMenuFont, &lpnm16->lfMenuFont );
3081 logfont_32_to_16( &tmp.lfStatusFont, &lpnm16->lfStatusFont );
3082 logfont_32_to_16( &tmp.lfMessageFont, &lpnm16->lfMessageFont );
3085 else /* winfile 95 sets cbSize to 340 */
3086 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
3087 break;
3090 case SPI_GETWORKAREA:
3092 RECT tmp;
3093 ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
3094 if (ret && lpvParam)
3096 RECT16 *r16 = lpvParam;
3097 r16->left = tmp.left;
3098 r16->top = tmp.top;
3099 r16->right = tmp.right;
3100 r16->bottom = tmp.bottom;
3102 break;
3105 default:
3106 ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
3107 break;
3110 return ret;
3114 /***********************************************************************
3115 * USER_489 (USER.489)
3117 LONG WINAPI stub_USER_489(void)
3119 FIXME("stub\n");
3120 return 0;
3124 /***********************************************************************
3125 * USER_490 (USER.490)
3127 LONG WINAPI stub_USER_490(void)
3129 FIXME("stub\n");
3130 return 0;
3134 /***********************************************************************
3135 * USER_492 (USER.492)
3137 LONG WINAPI stub_USER_492(void)
3139 FIXME("stub\n");
3140 return 0;
3144 /***********************************************************************
3145 * USER_496 (USER.496)
3147 LONG WINAPI stub_USER_496(void)
3149 FIXME("stub\n");
3150 return 0;
3154 /***********************************************************************
3155 * FormatMessage (USER.606)
3157 DWORD WINAPI FormatMessage16(
3158 DWORD dwFlags,
3159 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
3160 WORD dwMessageId,
3161 WORD dwLanguageId,
3162 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
3163 WORD nSize,
3164 LPDWORD args ) /* [in] NOTE: va_list *args */
3166 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
3167 LPSTR target,t;
3168 DWORD talloced;
3169 LPSTR from,f;
3170 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
3171 BOOL eos = FALSE;
3172 LPSTR allocstring = NULL;
3174 TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
3175 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
3176 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
3177 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
3178 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
3179 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
3180 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
3182 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
3183 FIXME("line wrapping (%lu) not supported.\n", width);
3184 from = NULL;
3185 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
3187 char *source = MapSL(lpSource);
3188 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
3189 strcpy( from, source );
3191 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
3192 from = HeapAlloc( GetProcessHeap(),0,200 );
3193 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
3195 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
3196 INT16 bufsize;
3197 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
3199 dwMessageId &= 0xFFFF;
3200 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
3201 if (bufsize) {
3202 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
3203 LoadString16(hinst16,dwMessageId,from,bufsize+1);
3206 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
3207 t = target;
3208 talloced= 100;
3210 #define ADD_TO_T(c) \
3211 do { \
3212 *t++=c;\
3213 if (t-target == talloced) {\
3214 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
3215 t = target+talloced;\
3216 talloced*=2;\
3218 } while(0)
3220 if (from) {
3221 f=from;
3222 while (*f && !eos) {
3223 if (*f=='%') {
3224 int insertnr;
3225 char *fmtstr,*x,*lastf;
3226 DWORD *argliststart;
3228 fmtstr = NULL;
3229 lastf = f;
3230 f++;
3231 if (!*f) {
3232 ADD_TO_T('%');
3233 continue;
3235 switch (*f) {
3236 case '1':case '2':case '3':case '4':case '5':
3237 case '6':case '7':case '8':case '9':
3238 insertnr=*f-'0';
3239 switch (f[1]) {
3240 case '0':case '1':case '2':case '3':
3241 case '4':case '5':case '6':case '7':
3242 case '8':case '9':
3243 f++;
3244 insertnr=insertnr*10+*f-'0';
3245 f++;
3246 break;
3247 default:
3248 f++;
3249 break;
3251 if (*f=='!') {
3252 f++;
3253 if (NULL!=(x=strchr(f,'!'))) {
3254 *x='\0';
3255 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
3256 sprintf(fmtstr,"%%%s",f);
3257 f=x+1;
3258 } else {
3259 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
3260 sprintf(fmtstr,"%%%s",f);
3261 f+=strlen(f); /*at \0*/
3264 else
3266 if(!args) break;
3267 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
3268 strcpy( fmtstr, "%s" );
3270 if (args) {
3271 int ret;
3272 int sz;
3273 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
3275 argliststart=args+insertnr-1;
3277 /* CMF - This makes a BIG assumption about va_list */
3278 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart)) < 0 || ret >= sz) {
3279 LPSTR new_b;
3280 sz = (ret == -1 ? sz + 100 : ret + 1);
3281 new_b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
3282 if (!new_b) break;
3283 b = new_b;
3285 for (x=b; *x; x++) ADD_TO_T(*x);
3286 HeapFree(GetProcessHeap(), 0, b);
3287 } else {
3288 /* NULL args - copy formatstr
3289 * (probably wrong)
3291 while ((lastf<f)&&(*lastf)) {
3292 ADD_TO_T(*lastf++);
3295 HeapFree(GetProcessHeap(),0,fmtstr);
3296 break;
3297 case '0': /* Just stop processing format string */
3298 eos = TRUE;
3299 f++;
3300 break;
3301 case 'n': /* 16 bit version just outputs 'n' */
3302 default:
3303 ADD_TO_T(*f++);
3304 break;
3306 } else { /* '\n' or '\r' gets mapped to "\r\n" */
3307 if(*f == '\n' || *f == '\r') {
3308 if (width == 0) {
3309 ADD_TO_T('\r');
3310 ADD_TO_T('\n');
3311 if(*f++ == '\r' && *f == '\n')
3312 f++;
3314 } else {
3315 ADD_TO_T(*f++);
3319 *t='\0';
3321 talloced = strlen(target)+1;
3322 TRACE("-- %s\n",debugstr_a(target));
3323 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
3324 /* nSize is the MINIMUM size */
3325 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
3326 SEGPTR ptr = LocalLock16(h);
3327 allocstring = MapSL( ptr );
3328 memcpy( allocstring,target,talloced);
3329 LocalUnlock16( h );
3330 *((HLOCAL16*)lpBuffer) = h;
3331 } else
3332 lstrcpynA(lpBuffer,target,nSize);
3333 HeapFree(GetProcessHeap(),0,target);
3334 HeapFree(GetProcessHeap(),0,from);
3335 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
3336 strlen(allocstring):
3337 strlen(lpBuffer);
3339 #undef ADD_TO_T
3342 /**********************************************************************
3343 * DestroyIcon32 (USER.610)
3345 * This routine is actually exported from Win95 USER under the name
3346 * DestroyIcon32 ... The behaviour implemented here should mimic
3347 * the Win95 one exactly, especially the return values, which
3348 * depend on the setting of various flags.
3350 WORD WINAPI DestroyIcon32( HGLOBAL16 handle, UINT16 flags )
3352 WORD retv;
3354 /* Check whether destroying active cursor */
3356 if (GetCursor16() == handle)
3358 WARN("Destroying active cursor!\n" );
3359 return FALSE;
3362 /* Try shared cursor/icon first */
3364 if (!(flags & CID_NONSHARED))
3366 INT count = release_shared_icon( handle );
3367 if (count != -1)
3368 return (flags & CID_WIN32) ? TRUE : (count == 0);
3371 /* Now assume non-shared cursor/icon */
3373 retv = free_icon_handle( handle );
3374 return (flags & CID_RESOURCE)? retv : TRUE;
3378 /***********************************************************************
3379 * ChangeDisplaySettings (USER.620)
3381 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
3383 return ChangeDisplaySettingsA( devmode, flags );
3387 /***********************************************************************
3388 * EnumDisplaySettings (USER.621)
3390 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
3392 return EnumDisplaySettingsA( name, n, devmode );
3395 /**********************************************************************
3396 * DrawFrameControl (USER.656)
3398 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
3400 RECT rect32;
3401 BOOL ret;
3403 rect32.left = rc->left;
3404 rect32.top = rc->top;
3405 rect32.right = rc->right;
3406 rect32.bottom = rc->bottom;
3407 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
3408 rc->left = rect32.left;
3409 rc->top = rect32.top;
3410 rc->right = rect32.right;
3411 rc->bottom = rect32.bottom;
3412 return ret;
3415 /**********************************************************************
3416 * DrawEdge (USER.659)
3418 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
3420 RECT rect32;
3421 BOOL ret;
3423 rect32.left = rc->left;
3424 rect32.top = rc->top;
3425 rect32.right = rc->right;
3426 rect32.bottom = rc->bottom;
3427 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
3428 rc->left = rect32.left;
3429 rc->top = rect32.top;
3430 rc->right = rect32.right;
3431 rc->bottom = rect32.bottom;
3432 return ret;
3435 /**********************************************************************
3436 * CheckMenuRadioItem (USER.666)
3438 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
3439 UINT16 check, BOOL16 bypos)
3441 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );