Removed implementation of LoadDIBIconHandler16 and
[wine/dibdrv.git] / dlls / user / user16.c
blob990980a0ea41a37f93e6136a6fc846c57005241c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
27 #include "wine/winuser16.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wownt32.h"
31 #include "user_private.h"
32 #include "win.h"
33 #include "winproc.h"
34 #include "cursoricon.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(user);
39 /* handle to handle 16 conversions */
40 #define HANDLE_16(h32) (LOWORD(h32))
42 /* handle16 to handle conversions */
43 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
44 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
46 #define IS_MENU_STRING_ITEM(flags) \
47 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
49 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
52 struct gray_string_info
54 GRAYSTRINGPROC16 proc;
55 LPARAM param;
56 char str[1];
59 /* callback for 16-bit gray string proc with opaque pointer */
60 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
62 const struct gray_string_info *info = (struct gray_string_info *)param;
63 WORD args[4];
64 DWORD ret;
66 args[3] = HDC_16(hdc);
67 args[2] = HIWORD(info->param);
68 args[1] = LOWORD(info->param);
69 args[0] = len;
70 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
71 return LOWORD(ret);
74 /* callback for 16-bit gray string proc with string pointer */
75 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
77 const struct gray_string_info *info;
78 char *str = (char *)param;
80 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
81 return gray_string_callback( hdc, (LPARAM)info, len );
84 struct draw_state_info
86 DRAWSTATEPROC16 proc;
87 LPARAM param;
90 /* callback for 16-bit DrawState functions */
91 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
93 const struct draw_state_info *info = (struct draw_state_info *)lparam;
94 WORD args[6];
95 DWORD ret;
97 args[5] = HDC_16(hdc);
98 args[4] = HIWORD(info->param);
99 args[3] = LOWORD(info->param);
100 args[2] = wparam;
101 args[1] = cx;
102 args[0] = cy;
103 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
104 return LOWORD(ret);
108 /**********************************************************************
109 * InitApp (USER.5)
111 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
113 /* Create task message queue */
114 return (InitThreadInput16( 0, 0 ) != 0);
118 /***********************************************************************
119 * ExitWindows (USER.7)
121 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
123 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
127 /***********************************************************************
128 * ClipCursor (USER.16)
130 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
132 RECT rect32;
134 if (!rect) return ClipCursor( NULL );
135 rect32.left = rect->left;
136 rect32.top = rect->top;
137 rect32.right = rect->right;
138 rect32.bottom = rect->bottom;
139 return ClipCursor( &rect32 );
143 /***********************************************************************
144 * GetCursorPos (USER.17)
146 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
148 POINT pos;
149 if (!pt) return 0;
150 GetCursorPos(&pos);
151 pt->x = pos.x;
152 pt->y = pos.y;
153 return 1;
157 /***********************************************************************
158 * SetCursor (USER.69)
160 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
162 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
166 /***********************************************************************
167 * SetCursorPos (USER.70)
169 void WINAPI SetCursorPos16( INT16 x, INT16 y )
171 SetCursorPos( x, y );
175 /***********************************************************************
176 * ShowCursor (USER.71)
178 INT16 WINAPI ShowCursor16(BOOL16 bShow)
180 return ShowCursor(bShow);
184 /***********************************************************************
185 * SetRect (USER.72)
187 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
189 rect->left = left;
190 rect->right = right;
191 rect->top = top;
192 rect->bottom = bottom;
196 /***********************************************************************
197 * SetRectEmpty (USER.73)
199 void WINAPI SetRectEmpty16( LPRECT16 rect )
201 rect->left = rect->right = rect->top = rect->bottom = 0;
205 /***********************************************************************
206 * CopyRect (USER.74)
208 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
210 *dest = *src;
211 return TRUE;
215 /***********************************************************************
216 * IsRectEmpty (USER.75)
218 * Bug compat: Windows checks for 0 or negative width/height.
220 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
222 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
226 /***********************************************************************
227 * PtInRect (USER.76)
229 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
231 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
232 (pt.y >= rect->top) && (pt.y < rect->bottom));
236 /***********************************************************************
237 * OffsetRect (USER.77)
239 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
241 rect->left += x;
242 rect->right += x;
243 rect->top += y;
244 rect->bottom += y;
248 /***********************************************************************
249 * InflateRect (USER.78)
251 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
253 rect->left -= x;
254 rect->top -= y;
255 rect->right += x;
256 rect->bottom += y;
260 /***********************************************************************
261 * IntersectRect (USER.79)
263 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
264 const RECT16 *src2 )
266 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
267 (src1->left >= src2->right) || (src2->left >= src1->right) ||
268 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
270 SetRectEmpty16( dest );
271 return FALSE;
273 dest->left = max( src1->left, src2->left );
274 dest->right = min( src1->right, src2->right );
275 dest->top = max( src1->top, src2->top );
276 dest->bottom = min( src1->bottom, src2->bottom );
277 return TRUE;
281 /***********************************************************************
282 * UnionRect (USER.80)
284 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
285 const RECT16 *src2 )
287 if (IsRectEmpty16(src1))
289 if (IsRectEmpty16(src2))
291 SetRectEmpty16( dest );
292 return FALSE;
294 else *dest = *src2;
296 else
298 if (IsRectEmpty16(src2)) *dest = *src1;
299 else
301 dest->left = min( src1->left, src2->left );
302 dest->right = max( src1->right, src2->right );
303 dest->top = min( src1->top, src2->top );
304 dest->bottom = max( src1->bottom, src2->bottom );
307 return TRUE;
311 /***********************************************************************
312 * FillRect (USER.81)
313 * NOTE
314 * The Win16 variant doesn't support special color brushes like
315 * the Win32 one, despite the fact that Win16, as well as Win32,
316 * supports special background brushes for a window class.
318 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
320 HBRUSH prevBrush;
322 /* coordinates are logical so we cannot fast-check 'rect',
323 * it will be done later in the PatBlt().
326 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
327 PatBlt( HDC_32(hdc), rect->left, rect->top,
328 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
329 SelectObject( HDC_32(hdc), prevBrush );
330 return 1;
334 /***********************************************************************
335 * InvertRect (USER.82)
337 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
339 PatBlt( HDC_32(hdc), rect->left, rect->top,
340 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
344 /***********************************************************************
345 * FrameRect (USER.83)
347 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
349 RECT rect;
351 rect.left = rect16->left;
352 rect.top = rect16->top;
353 rect.right = rect16->right;
354 rect.bottom = rect16->bottom;
355 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
359 /***********************************************************************
360 * DrawIcon (USER.84)
362 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
364 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
368 /***********************************************************************
369 * DrawText (USER.85)
371 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
373 INT16 ret;
375 if (rect)
377 RECT rect32;
379 rect32.left = rect->left;
380 rect32.top = rect->top;
381 rect32.right = rect->right;
382 rect32.bottom = rect->bottom;
383 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
384 rect->left = rect32.left;
385 rect->top = rect32.top;
386 rect->right = rect32.right;
387 rect->bottom = rect32.bottom;
389 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
390 return ret;
394 /***********************************************************************
395 * IconSize (USER.86)
397 * See "Undocumented Windows". Used by W2.0 paint.exe.
399 DWORD WINAPI IconSize16(void)
401 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
405 /***********************************************************************
406 * AdjustWindowRect (USER.102)
408 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
410 return AdjustWindowRectEx16( rect, style, menu, 0 );
414 /**************************************************************************
415 * CloseClipboard (USER.138)
417 BOOL16 WINAPI CloseClipboard16(void)
419 return CloseClipboard();
423 /**************************************************************************
424 * EmptyClipboard (USER.139)
426 BOOL16 WINAPI EmptyClipboard16(void)
428 return EmptyClipboard();
432 /**************************************************************************
433 * CountClipboardFormats (USER.143)
435 INT16 WINAPI CountClipboardFormats16(void)
437 return CountClipboardFormats();
441 /**************************************************************************
442 * EnumClipboardFormats (USER.144)
444 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
446 return EnumClipboardFormats( id );
450 /**************************************************************************
451 * RegisterClipboardFormat (USER.145)
453 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
455 return RegisterClipboardFormatA( name );
459 /**************************************************************************
460 * GetClipboardFormatName (USER.146)
462 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
464 return GetClipboardFormatNameA( id, buffer, maxlen );
468 /**********************************************************************
469 * CreateMenu (USER.151)
471 HMENU16 WINAPI CreateMenu16(void)
473 return HMENU_16( CreateMenu() );
477 /**********************************************************************
478 * DestroyMenu (USER.152)
480 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
482 return DestroyMenu( HMENU_32(hMenu) );
486 /*******************************************************************
487 * ChangeMenu (USER.153)
489 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
490 UINT16 id, UINT16 flags )
492 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
494 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
495 /* for MF_DELETE. We should check the parameters for all others */
496 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
498 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
499 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
500 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
501 flags & ~MF_REMOVE );
502 /* Default: MF_INSERT */
503 return InsertMenu16( hMenu, pos, flags, id, data );
507 /*******************************************************************
508 * CheckMenuItem (USER.154)
510 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
512 return CheckMenuItem( HMENU_32(hMenu), id, flags );
516 /**********************************************************************
517 * EnableMenuItem (USER.155)
519 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
521 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
525 /**********************************************************************
526 * GetSubMenu (USER.159)
528 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
530 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
534 /*******************************************************************
535 * GetMenuString (USER.161)
537 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
538 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
540 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
544 /**********************************************************************
545 * WinHelp (USER.171)
547 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
548 DWORD dwData )
550 BOOL ret;
551 DWORD mutex_count;
553 /* We might call WinExec() */
554 ReleaseThunkLock(&mutex_count);
556 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
558 RestoreThunkLock(mutex_count);
559 return ret;
563 /***********************************************************************
564 * LoadCursor (USER.173)
566 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
568 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
572 /***********************************************************************
573 * LoadIcon (USER.174)
575 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
577 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
580 /**********************************************************************
581 * LoadBitmap (USER.175)
583 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
585 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
589 /***********************************************************************
590 * GetSystemMetrics (USER.179)
592 INT16 WINAPI GetSystemMetrics16( INT16 index )
594 return GetSystemMetrics( index );
598 /*************************************************************************
599 * GetSysColor (USER.180)
601 COLORREF WINAPI GetSysColor16( INT16 index )
603 return GetSysColor( index );
607 /*************************************************************************
608 * SetSysColors (USER.181)
610 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
612 INT i, *list;
614 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
616 for (i = 0; i < count; i++) list[i] = list16[i];
617 SetSysColors( count, list, values );
618 HeapFree( GetProcessHeap(), 0, list );
623 /***********************************************************************
624 * GrayString (USER.185)
626 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
627 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
628 INT16 cx, INT16 cy )
630 BOOL ret;
632 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
633 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
635 if (cch == -1 || (cch && cx && cy))
637 /* lParam can be treated as an opaque pointer */
638 struct gray_string_info info;
640 info.proc = gsprc;
641 info.param = lParam;
642 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
643 (LPARAM)&info, cch, x, y, cx, cy );
645 else /* here we need some string conversions */
647 char *str16 = MapSL(lParam);
648 struct gray_string_info *info;
650 if (!cch) cch = strlen(str16);
651 if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
652 info->proc = gsprc;
653 info->param = lParam;
654 memcpy( info->str, str16, cch );
655 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
656 (LPARAM)info->str, cch, x, y, cx, cy );
657 HeapFree( GetProcessHeap(), 0, info );
659 return ret;
663 /**************************************************************************
664 * IsClipboardFormatAvailable (USER.193)
666 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
668 return IsClipboardFormatAvailable( wFormat );
672 /***********************************************************************
673 * TabbedTextOut (USER.196)
675 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
676 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
678 LONG ret;
679 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
680 if (!tabs) return 0;
681 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
682 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
683 HeapFree( GetProcessHeap(), 0, tabs );
684 return ret;
688 /***********************************************************************
689 * GetTabbedTextExtent (USER.197)
691 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
692 INT16 nb_tabs, const INT16 *tabs16 )
694 LONG ret;
695 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
696 if (!tabs) return 0;
697 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
698 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
699 HeapFree( GetProcessHeap(), 0, tabs );
700 return ret;
704 /*************************************************************************
705 * ScrollDC (USER.221)
707 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
708 const RECT16 *cliprc, HRGN16 hrgnUpdate,
709 LPRECT16 rcUpdate )
711 RECT rect32, clipRect32, rcUpdate32;
712 BOOL16 ret;
714 if (rect)
716 rect32.left = rect->left;
717 rect32.top = rect->top;
718 rect32.right = rect->right;
719 rect32.bottom = rect->bottom;
721 if (cliprc)
723 clipRect32.left = cliprc->left;
724 clipRect32.top = cliprc->top;
725 clipRect32.right = cliprc->right;
726 clipRect32.bottom = cliprc->bottom;
728 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
729 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
730 &rcUpdate32 );
731 if (rcUpdate)
733 rcUpdate->left = rcUpdate32.left;
734 rcUpdate->top = rcUpdate32.top;
735 rcUpdate->right = rcUpdate32.right;
736 rcUpdate->bottom = rcUpdate32.bottom;
738 return ret;
742 /***********************************************************************
743 * GetSystemDebugState (USER.231)
745 WORD WINAPI GetSystemDebugState16(void)
747 return 0; /* FIXME */
751 /***********************************************************************
752 * EqualRect (USER.244)
754 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
756 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
757 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
761 /***********************************************************************
762 * ExitWindowsExec (USER.246)
764 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
766 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
767 lpszExe, lpszParams);
768 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
772 /***********************************************************************
773 * GetCursor (USER.247)
775 HCURSOR16 WINAPI GetCursor16(void)
777 return HCURSOR_16(GetCursor());
781 /**********************************************************************
782 * GetAsyncKeyState (USER.249)
784 INT16 WINAPI GetAsyncKeyState16( INT16 key )
786 return GetAsyncKeyState( key );
790 /**********************************************************************
791 * GetMenuState (USER.250)
793 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
795 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
799 /**********************************************************************
800 * GetMenuItemCount (USER.263)
802 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
804 return GetMenuItemCount( HMENU_32(hMenu) );
808 /**********************************************************************
809 * GetMenuItemID (USER.264)
811 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
813 return GetMenuItemID( HMENU_32(hMenu), nPos );
817 /***********************************************************************
818 * GlobalAddAtom (USER.268)
820 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
822 return GlobalAddAtomA(lpString);
825 /***********************************************************************
826 * GlobalDeleteAtom (USER.269)
828 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
830 return GlobalDeleteAtom(nAtom);
833 /***********************************************************************
834 * GlobalFindAtom (USER.270)
836 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
838 return GlobalFindAtomA(lpString);
841 /***********************************************************************
842 * GlobalGetAtomName (USER.271)
844 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
846 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
850 /***********************************************************************
851 * GetSysColorBrush (USER.281)
853 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
855 return HBRUSH_16( GetSysColorBrush(index) );
859 /***********************************************************************
860 * SelectPalette (USER.282)
862 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
864 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
867 /***********************************************************************
868 * RealizePalette (USER.283)
870 UINT16 WINAPI RealizePalette16( HDC16 hdc )
872 return UserRealizePalette( HDC_32(hdc) );
876 /***********************************************************************
877 * GetClipCursor (USER.309)
879 void WINAPI GetClipCursor16( RECT16 *rect )
881 if (rect)
883 RECT rect32;
884 GetClipCursor( &rect32 );
885 rect->left = rect32.left;
886 rect->top = rect32.top;
887 rect->right = rect32.right;
888 rect->bottom = rect32.bottom;
893 /***********************************************************************
894 * SignalProc (USER.314)
896 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
897 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
899 if (code == USIG16_DLL_UNLOAD)
901 /* HOOK_FreeModuleHooks( hModule ); */
902 CLASS_FreeModuleClasses( hModule );
903 CURSORICON_FreeModuleIcons( hModule );
908 /***********************************************************************
909 * SetEventHook (USER.321)
911 * Used by Turbo Debugger for Windows
913 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
915 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
916 return 0;
920 /**********************************************************************
921 * EnableHardwareInput (USER.331)
923 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
925 FIXME("(%d) - stub\n", bEnable);
926 return TRUE;
930 /***********************************************************************
931 * IsUserIdle (USER.333)
933 BOOL16 WINAPI IsUserIdle16(void)
935 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
936 return FALSE;
937 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
938 return FALSE;
939 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
940 return FALSE;
941 /* Should check for screen saver activation here ... */
942 return TRUE;
946 /**********************************************************************
947 * LoadDIBIconHandler (USER.357)
949 * RT_ICON resource loader, installed by USER_SignalProc when module
950 * is initialized.
952 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
954 /* If hResource is zero we must allocate a new memory block, if it's
955 * non-zero but GlobalLock() returns NULL then it was discarded and
956 * we have to recommit some memory, otherwise we just need to check
957 * the block size. See LoadProc() in 16-bit SDK for more.
959 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
960 return 0;
963 /**********************************************************************
964 * LoadDIBCursorHandler (USER.356)
966 * RT_CURSOR resource loader. Same as above.
968 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
970 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
971 return 0;
975 /**********************************************************************
976 * IsMenu (USER.358)
978 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
980 return IsMenu( HMENU_32(hmenu) );
984 /***********************************************************************
985 * DCHook (USER.362)
987 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
989 FIXME( "hDC = %x, %i: stub\n", hdc, code );
990 return FALSE;
994 /***********************************************************************
995 * SubtractRect (USER.373)
997 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
998 const RECT16 *src2 )
1000 RECT16 tmp;
1002 if (IsRectEmpty16( src1 ))
1004 SetRectEmpty16( dest );
1005 return FALSE;
1007 *dest = *src1;
1008 if (IntersectRect16( &tmp, src1, src2 ))
1010 if (EqualRect16( &tmp, dest ))
1012 SetRectEmpty16( dest );
1013 return FALSE;
1015 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1017 if (tmp.left == dest->left) dest->left = tmp.right;
1018 else if (tmp.right == dest->right) dest->right = tmp.left;
1020 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1022 if (tmp.top == dest->top) dest->top = tmp.bottom;
1023 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1026 return TRUE;
1030 /**********************************************************************
1031 * SetMenuContextHelpId (USER.384)
1033 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1035 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1039 /**********************************************************************
1040 * GetMenuContextHelpId (USER.385)
1042 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1044 return GetMenuContextHelpId( HMENU_32(hMenu) );
1048 /***********************************************************************
1049 * LoadImage (USER.389)
1052 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1053 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1055 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1056 desiredy, loadflags));
1059 /******************************************************************************
1060 * CopyImage (USER.390) Creates new image and copies attributes to it
1063 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1064 INT16 desiredy, UINT16 flags)
1066 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1067 (INT)desiredy, (UINT)flags));
1070 /**********************************************************************
1071 * DrawIconEx (USER.394)
1073 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1074 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1075 HBRUSH16 hbr, UINT16 flags)
1077 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1078 istep, HBRUSH_32(hbr), flags);
1081 /**********************************************************************
1082 * GetIconInfo (USER.395)
1084 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1086 ICONINFO ii32;
1087 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1089 iconinfo->fIcon = ii32.fIcon;
1090 iconinfo->xHotspot = ii32.xHotspot;
1091 iconinfo->yHotspot = ii32.yHotspot;
1092 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
1093 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1094 return ret;
1098 /***********************************************************************
1099 * FinalUserInit (USER.400)
1101 void WINAPI FinalUserInit16( void )
1103 /* FIXME: Should chain to FinalGdiInit */
1107 /***********************************************************************
1108 * CreateCursor (USER.406)
1110 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1111 INT16 xHotSpot, INT16 yHotSpot,
1112 INT16 nWidth, INT16 nHeight,
1113 LPCVOID lpANDbits, LPCVOID lpXORbits)
1115 CURSORICONINFO info;
1117 info.ptHotSpot.x = xHotSpot;
1118 info.ptHotSpot.y = yHotSpot;
1119 info.nWidth = nWidth;
1120 info.nHeight = nHeight;
1121 info.nWidthBytes = 0;
1122 info.bPlanes = 1;
1123 info.bBitsPerPixel = 1;
1125 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1129 /***********************************************************************
1130 * InitThreadInput (USER.409)
1132 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1134 /* nothing to do here */
1135 return 0xbeef;
1139 /*******************************************************************
1140 * InsertMenu (USER.410)
1142 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1143 UINT16 id, SEGPTR data )
1145 UINT pos32 = (UINT)pos;
1146 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1147 if (IS_MENU_STRING_ITEM(flags) && data)
1148 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1149 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1153 /*******************************************************************
1154 * AppendMenu (USER.411)
1156 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1158 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1162 /**********************************************************************
1163 * RemoveMenu (USER.412)
1165 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1167 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1171 /**********************************************************************
1172 * DeleteMenu (USER.413)
1174 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1176 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1180 /*******************************************************************
1181 * ModifyMenu (USER.414)
1183 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1184 UINT16 id, SEGPTR data )
1186 if (IS_MENU_STRING_ITEM(flags))
1187 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1188 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1192 /**********************************************************************
1193 * CreatePopupMenu (USER.415)
1195 HMENU16 WINAPI CreatePopupMenu16(void)
1197 return HMENU_16( CreatePopupMenu() );
1201 /**********************************************************************
1202 * SetMenuItemBitmaps (USER.418)
1204 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1205 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1207 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1208 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1212 /***********************************************************************
1213 * lstrcmp (USER.430)
1215 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1217 return strcmp( str1, str2 );
1221 /***********************************************************************
1222 * AnsiUpper (USER.431)
1224 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1226 /* uppercase only one char if strOrChar < 0x10000 */
1227 if (HIWORD(strOrChar))
1229 CharUpperA( MapSL(strOrChar) );
1230 return strOrChar;
1232 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1236 /***********************************************************************
1237 * AnsiLower (USER.432)
1239 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1241 /* lowercase only one char if strOrChar < 0x10000 */
1242 if (HIWORD(strOrChar))
1244 CharLowerA( MapSL(strOrChar) );
1245 return strOrChar;
1247 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1251 /***********************************************************************
1252 * AnsiUpperBuff (USER.437)
1254 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1256 CharUpperBuffA( str, len ? len : 65536 );
1257 return len;
1261 /***********************************************************************
1262 * AnsiLowerBuff (USER.438)
1264 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1266 CharLowerBuffA( str, len ? len : 65536 );
1267 return len;
1271 /*******************************************************************
1272 * InsertMenuItem (USER.441)
1274 * FIXME: untested
1276 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1277 const MENUITEMINFO16 *mii )
1279 MENUITEMINFOA miia;
1281 miia.cbSize = sizeof(miia);
1282 miia.fMask = mii->fMask;
1283 miia.dwTypeData = (LPSTR)mii->dwTypeData;
1284 miia.fType = mii->fType;
1285 miia.fState = mii->fState;
1286 miia.wID = mii->wID;
1287 miia.hSubMenu = HMENU_32(mii->hSubMenu);
1288 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
1289 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1290 miia.dwItemData = mii->dwItemData;
1291 miia.cch = mii->cch;
1292 if (IS_MENU_STRING_ITEM(miia.fType))
1293 miia.dwTypeData = MapSL(mii->dwTypeData);
1294 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1298 /**********************************************************************
1299 * DrawState (USER.449)
1301 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1302 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1304 struct draw_state_info info;
1305 UINT opcode = flags & 0xf;
1307 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1309 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1310 if (!wdata) wdata = strlen( MapSL(ldata) );
1311 if (!cx || !cy)
1313 SIZE s;
1314 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1315 if (!cx) cx = s.cx;
1316 if (!cy) cy = s.cy;
1319 info.proc = func;
1320 info.param = ldata;
1321 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1322 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1326 /**********************************************************************
1327 * CreateIconFromResourceEx (USER.450)
1329 * FIXME: not sure about exact parameter types
1331 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1332 BOOL16 bIcon, DWORD dwVersion,
1333 INT16 width, INT16 height,
1334 UINT16 cFlag)
1336 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1337 width, height, cFlag));
1341 /***********************************************************************
1342 * AdjustWindowRectEx (USER.454)
1344 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1346 RECT rect32;
1347 BOOL ret;
1349 rect32.left = rect->left;
1350 rect32.top = rect->top;
1351 rect32.right = rect->right;
1352 rect32.bottom = rect->bottom;
1353 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1354 rect->left = rect32.left;
1355 rect->top = rect32.top;
1356 rect->right = rect32.right;
1357 rect->bottom = rect32.bottom;
1358 return ret;
1362 /***********************************************************************
1363 * DestroyIcon (USER.457)
1365 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1367 return DestroyIcon32(hIcon, 0);
1370 /***********************************************************************
1371 * DestroyCursor (USER.458)
1373 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1375 return DestroyIcon32(hCursor, 0);
1378 /*******************************************************************
1379 * DRAG_QueryUpdate16
1381 * Recursively find a child that contains spDragInfo->pt point
1382 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1384 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1386 BOOL bResult = 0;
1387 WPARAM wParam;
1388 POINT pt, old_pt;
1389 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1390 RECT tempRect;
1391 HWND child;
1393 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1395 old_pt.x = ptrDragInfo->pt.x;
1396 old_pt.y = ptrDragInfo->pt.y;
1397 pt = old_pt;
1398 ScreenToClient( hQueryWnd, &pt );
1399 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1400 if (!child) return FALSE;
1402 if (child != hQueryWnd)
1404 wParam = 0;
1405 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1407 else
1409 GetClientRect( hQueryWnd, &tempRect );
1410 wParam = !PtInRect( &tempRect, pt );
1413 ptrDragInfo->pt.x = pt.x;
1414 ptrDragInfo->pt.y = pt.y;
1415 ptrDragInfo->hScope = HWND_16(hQueryWnd);
1417 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1419 if (!bResult)
1421 ptrDragInfo->pt.x = old_pt.x;
1422 ptrDragInfo->pt.y = old_pt.y;
1424 return bResult;
1428 /******************************************************************************
1429 * DragObject (USER.464)
1431 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1432 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1434 MSG msg;
1435 LPDRAGINFO16 lpDragInfo;
1436 SEGPTR spDragInfo;
1437 HCURSOR hOldCursor=0, hBummer=0;
1438 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1439 HCURSOR hCurrentCursor = 0;
1440 HWND16 hCurrentWnd = 0;
1442 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1443 spDragInfo = K32WOWGlobalLock16(hDragInfo);
1445 if( !lpDragInfo || !spDragInfo ) return 0L;
1447 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1449 GlobalFree16(hDragInfo);
1450 return 0L;
1453 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1455 lpDragInfo->hWnd = hWnd;
1456 lpDragInfo->hScope = 0;
1457 lpDragInfo->wFlags = wObj;
1458 lpDragInfo->hList = szList; /* near pointer! */
1459 lpDragInfo->hOfStruct = hOfStruct;
1460 lpDragInfo->l = 0L;
1462 SetCapture( HWND_32(hWnd) );
1463 ShowCursor( TRUE );
1467 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1469 *(lpDragInfo+1) = *lpDragInfo;
1471 lpDragInfo->pt.x = msg.pt.x;
1472 lpDragInfo->pt.y = msg.pt.y;
1474 /* update DRAGINFO struct */
1475 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1476 hCurrentCursor = HCURSOR_32(hCursor);
1477 else
1479 hCurrentCursor = hBummer;
1480 lpDragInfo->hScope = 0;
1482 if( hCurrentCursor )
1483 SetCursor(hCurrentCursor);
1485 /* send WM_DRAGLOOP */
1486 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1487 (LPARAM) spDragInfo );
1488 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1489 if( hCurrentWnd != lpDragInfo->hScope )
1491 if( hCurrentWnd )
1492 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1493 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1494 HIWORD(spDragInfo)) );
1495 hCurrentWnd = lpDragInfo->hScope;
1496 if( hCurrentWnd )
1497 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1499 else
1500 if( hCurrentWnd )
1501 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1503 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1505 ReleaseCapture();
1506 ShowCursor( FALSE );
1508 if( hCursor ) SetCursor(hOldCursor);
1510 if( hCurrentCursor != hBummer )
1511 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1512 (WPARAM16)hWnd, (LPARAM)spDragInfo );
1513 else
1514 msg.lParam = 0;
1515 GlobalFree16(hDragInfo);
1517 return (DWORD)(msg.lParam);
1521 /***********************************************************************
1522 * DrawFocusRect (USER.466)
1524 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1526 RECT rect32;
1528 rect32.left = rc->left;
1529 rect32.top = rc->top;
1530 rect32.right = rc->right;
1531 rect32.bottom = rc->bottom;
1532 DrawFocusRect( HDC_32(hdc), &rect32 );
1536 /***********************************************************************
1537 * AnsiNext (USER.472)
1539 SEGPTR WINAPI AnsiNext16(SEGPTR current)
1541 char *ptr = MapSL(current);
1542 return current + (CharNextA(ptr) - ptr);
1546 /***********************************************************************
1547 * AnsiPrev (USER.473)
1549 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
1551 char *ptr = MapSL(current);
1552 return current - (ptr - CharPrevA( start, ptr ));
1556 /***********************************************************************
1557 * FormatMessage (USER.606)
1559 DWORD WINAPI FormatMessage16(
1560 DWORD dwFlags,
1561 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
1562 WORD dwMessageId,
1563 WORD dwLanguageId,
1564 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
1565 WORD nSize,
1566 LPDWORD args ) /* [in] NOTE: va_list *args */
1568 #ifdef __i386__
1569 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
1570 LPSTR target,t;
1571 DWORD talloced;
1572 LPSTR from,f;
1573 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
1574 BOOL eos = FALSE;
1575 LPSTR allocstring = NULL;
1577 TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
1578 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
1579 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1580 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
1581 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
1582 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1583 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
1585 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
1586 FIXME("line wrapping (%lu) not supported.\n", width);
1587 from = NULL;
1588 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
1590 char *source = MapSL(lpSource);
1591 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
1592 strcpy( from, source );
1594 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
1595 from = HeapAlloc( GetProcessHeap(),0,200 );
1596 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
1598 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
1599 INT16 bufsize;
1600 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
1602 dwMessageId &= 0xFFFF;
1603 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
1604 if (bufsize) {
1605 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
1606 LoadString16(hinst16,dwMessageId,from,bufsize+1);
1609 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
1610 t = target;
1611 talloced= 100;
1613 #define ADD_TO_T(c) \
1614 *t++=c;\
1615 if (t-target == talloced) {\
1616 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
1617 t = target+talloced;\
1618 talloced*=2;\
1621 if (from) {
1622 f=from;
1623 while (*f && !eos) {
1624 if (*f=='%') {
1625 int insertnr;
1626 char *fmtstr,*x,*lastf;
1627 DWORD *argliststart;
1629 fmtstr = NULL;
1630 lastf = f;
1631 f++;
1632 if (!*f) {
1633 ADD_TO_T('%');
1634 continue;
1636 switch (*f) {
1637 case '1':case '2':case '3':case '4':case '5':
1638 case '6':case '7':case '8':case '9':
1639 insertnr=*f-'0';
1640 switch (f[1]) {
1641 case '0':case '1':case '2':case '3':
1642 case '4':case '5':case '6':case '7':
1643 case '8':case '9':
1644 f++;
1645 insertnr=insertnr*10+*f-'0';
1646 f++;
1647 break;
1648 default:
1649 f++;
1650 break;
1652 if (*f=='!') {
1653 f++;
1654 if (NULL!=(x=strchr(f,'!'))) {
1655 *x='\0';
1656 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1657 sprintf(fmtstr,"%%%s",f);
1658 f=x+1;
1659 } else {
1660 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1661 sprintf(fmtstr,"%%%s",f);
1662 f+=strlen(f); /*at \0*/
1665 else
1667 if(!args) break;
1668 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
1669 strcpy( fmtstr, "%s" );
1671 if (args) {
1672 int ret;
1673 int sz;
1674 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
1676 argliststart=args+insertnr-1;
1678 /* CMF - This makes a BIG assumption about va_list */
1679 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
1680 sz = (ret == -1 ? sz + 100 : ret + 1);
1681 b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
1683 for (x=b; *x; x++) ADD_TO_T(*x);
1684 HeapFree(GetProcessHeap(), 0, b);
1685 } else {
1686 /* NULL args - copy formatstr
1687 * (probably wrong)
1689 while ((lastf<f)&&(*lastf)) {
1690 ADD_TO_T(*lastf++);
1693 HeapFree(GetProcessHeap(),0,fmtstr);
1694 break;
1695 case '0': /* Just stop processing format string */
1696 eos = TRUE;
1697 f++;
1698 break;
1699 case 'n': /* 16 bit version just outputs 'n' */
1700 default:
1701 ADD_TO_T(*f++);
1702 break;
1704 } else { /* '\n' or '\r' gets mapped to "\r\n" */
1705 if(*f == '\n' || *f == '\r') {
1706 if (width == 0) {
1707 ADD_TO_T('\r');
1708 ADD_TO_T('\n');
1709 if(*f++ == '\r' && *f == '\n')
1710 f++;
1712 } else {
1713 ADD_TO_T(*f++);
1717 *t='\0';
1719 talloced = strlen(target)+1;
1720 if (nSize && talloced<nSize) {
1721 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
1723 TRACE("-- %s\n",debugstr_a(target));
1724 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
1725 /* nSize is the MINIMUM size */
1726 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
1727 SEGPTR ptr = LocalLock16(h);
1728 allocstring = MapSL( ptr );
1729 memcpy( allocstring,target,talloced);
1730 LocalUnlock16( h );
1731 *((HLOCAL16*)lpBuffer) = h;
1732 } else
1733 lstrcpynA(lpBuffer,target,nSize);
1734 HeapFree(GetProcessHeap(),0,target);
1735 HeapFree(GetProcessHeap(),0,from);
1736 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
1737 strlen(allocstring):
1738 strlen(lpBuffer);
1739 #else
1740 return 0;
1741 #endif /* __i386__ */
1743 #undef ADD_TO_T
1746 /***********************************************************************
1747 * ChangeDisplaySettings (USER.620)
1749 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1751 return ChangeDisplaySettingsA( devmode, flags );
1755 /***********************************************************************
1756 * EnumDisplaySettings (USER.621)
1758 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1760 return EnumDisplaySettingsA( name, n, devmode );
1763 /**********************************************************************
1764 * DrawFrameControl (USER.656)
1766 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1768 RECT rect32;
1769 BOOL ret;
1771 rect32.left = rc->left;
1772 rect32.top = rc->top;
1773 rect32.right = rc->right;
1774 rect32.bottom = rc->bottom;
1775 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1776 rc->left = rect32.left;
1777 rc->top = rect32.top;
1778 rc->right = rect32.right;
1779 rc->bottom = rect32.bottom;
1780 return ret;
1783 /**********************************************************************
1784 * DrawEdge (USER.659)
1786 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1788 RECT rect32;
1789 BOOL ret;
1791 rect32.left = rc->left;
1792 rect32.top = rc->top;
1793 rect32.right = rc->right;
1794 rect32.bottom = rc->bottom;
1795 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1796 rc->left = rect32.left;
1797 rc->top = rect32.top;
1798 rc->right = rect32.right;
1799 rc->bottom = rect32.bottom;
1800 return ret;
1803 /**********************************************************************
1804 * CheckMenuRadioItem (USER.666)
1806 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
1807 UINT16 check, BOOL16 bypos)
1809 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );