user32: Get rid of the 16-bit heap support.
[wine/multimedia.git] / dlls / user32 / user16.c
blob5ca88372d20e18f33359d3af1611086c66f7cc87
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 "win.h"
35 #include "controls.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))
43 /* handle16 to handle conversions */
44 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
45 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
47 #define IS_MENU_STRING_ITEM(flags) \
48 (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
50 /* UserSeeUserDo parameters */
51 #define USUD_LOCALALLOC 0x0001
52 #define USUD_LOCALFREE 0x0002
53 #define USUD_LOCALCOMPACT 0x0003
54 #define USUD_LOCALHEAP 0x0004
55 #define USUD_FIRSTCLASS 0x0005
57 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
59 WORD USER_HeapSel = 0; /* USER heap selector */
61 struct gray_string_info
63 GRAYSTRINGPROC16 proc;
64 LPARAM param;
65 char str[1];
68 /* callback for 16-bit gray string proc with opaque pointer */
69 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
71 const struct gray_string_info *info = (struct gray_string_info *)param;
72 WORD args[4];
73 DWORD ret;
75 args[3] = HDC_16(hdc);
76 args[2] = HIWORD(info->param);
77 args[1] = LOWORD(info->param);
78 args[0] = len;
79 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
80 return LOWORD(ret);
83 /* callback for 16-bit gray string proc with string pointer */
84 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
86 const struct gray_string_info *info;
87 char *str = (char *)param;
89 info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
90 return gray_string_callback( hdc, (LPARAM)info, len );
93 struct draw_state_info
95 DRAWSTATEPROC16 proc;
96 LPARAM param;
99 /* callback for 16-bit DrawState functions */
100 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
102 const struct draw_state_info *info = (struct draw_state_info *)lparam;
103 WORD args[6];
104 DWORD ret;
106 args[5] = HDC_16(hdc);
107 args[4] = HIWORD(info->param);
108 args[3] = LOWORD(info->param);
109 args[2] = wparam;
110 args[1] = cx;
111 args[0] = cy;
112 WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
113 return LOWORD(ret);
117 /**********************************************************************
118 * InitApp (USER.5)
120 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
122 /* Create task message queue */
123 return (InitThreadInput16( 0, 0 ) != 0);
127 /***********************************************************************
128 * ExitWindows (USER.7)
130 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
132 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
136 /***********************************************************************
137 * GetTimerResolution (USER.14)
139 LONG WINAPI GetTimerResolution16(void)
141 return (1000);
145 /***********************************************************************
146 * ClipCursor (USER.16)
148 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
150 RECT rect32;
152 if (!rect) return ClipCursor( NULL );
153 rect32.left = rect->left;
154 rect32.top = rect->top;
155 rect32.right = rect->right;
156 rect32.bottom = rect->bottom;
157 return ClipCursor( &rect32 );
161 /***********************************************************************
162 * GetCursorPos (USER.17)
164 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
166 POINT pos;
167 if (!pt) return 0;
168 GetCursorPos(&pos);
169 pt->x = pos.x;
170 pt->y = pos.y;
171 return 1;
175 /***********************************************************************
176 * SetCursor (USER.69)
178 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
180 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
184 /***********************************************************************
185 * SetCursorPos (USER.70)
187 void WINAPI SetCursorPos16( INT16 x, INT16 y )
189 SetCursorPos( x, y );
193 /***********************************************************************
194 * ShowCursor (USER.71)
196 INT16 WINAPI ShowCursor16(BOOL16 bShow)
198 return ShowCursor(bShow);
202 /***********************************************************************
203 * SetRect (USER.72)
205 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom )
207 rect->left = left;
208 rect->right = right;
209 rect->top = top;
210 rect->bottom = bottom;
214 /***********************************************************************
215 * SetRectEmpty (USER.73)
217 void WINAPI SetRectEmpty16( LPRECT16 rect )
219 rect->left = rect->right = rect->top = rect->bottom = 0;
223 /***********************************************************************
224 * CopyRect (USER.74)
226 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
228 *dest = *src;
229 return TRUE;
233 /***********************************************************************
234 * IsRectEmpty (USER.75)
236 * Bug compat: Windows checks for 0 or negative width/height.
238 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
240 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
244 /***********************************************************************
245 * PtInRect (USER.76)
247 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
249 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
250 (pt.y >= rect->top) && (pt.y < rect->bottom));
254 /***********************************************************************
255 * OffsetRect (USER.77)
257 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
259 rect->left += x;
260 rect->right += x;
261 rect->top += y;
262 rect->bottom += y;
266 /***********************************************************************
267 * InflateRect (USER.78)
269 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
271 rect->left -= x;
272 rect->top -= y;
273 rect->right += x;
274 rect->bottom += y;
278 /***********************************************************************
279 * IntersectRect (USER.79)
281 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
282 const RECT16 *src2 )
284 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
285 (src1->left >= src2->right) || (src2->left >= src1->right) ||
286 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
288 SetRectEmpty16( dest );
289 return FALSE;
291 dest->left = max( src1->left, src2->left );
292 dest->right = min( src1->right, src2->right );
293 dest->top = max( src1->top, src2->top );
294 dest->bottom = min( src1->bottom, src2->bottom );
295 return TRUE;
299 /***********************************************************************
300 * UnionRect (USER.80)
302 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
303 const RECT16 *src2 )
305 if (IsRectEmpty16(src1))
307 if (IsRectEmpty16(src2))
309 SetRectEmpty16( dest );
310 return FALSE;
312 else *dest = *src2;
314 else
316 if (IsRectEmpty16(src2)) *dest = *src1;
317 else
319 dest->left = min( src1->left, src2->left );
320 dest->right = max( src1->right, src2->right );
321 dest->top = min( src1->top, src2->top );
322 dest->bottom = max( src1->bottom, src2->bottom );
325 return TRUE;
329 /***********************************************************************
330 * FillRect (USER.81)
331 * NOTE
332 * The Win16 variant doesn't support special color brushes like
333 * the Win32 one, despite the fact that Win16, as well as Win32,
334 * supports special background brushes for a window class.
336 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
338 HBRUSH prevBrush;
340 /* coordinates are logical so we cannot fast-check 'rect',
341 * it will be done later in the PatBlt().
344 if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
345 PatBlt( HDC_32(hdc), rect->left, rect->top,
346 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
347 SelectObject( HDC_32(hdc), prevBrush );
348 return 1;
352 /***********************************************************************
353 * InvertRect (USER.82)
355 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
357 PatBlt( HDC_32(hdc), rect->left, rect->top,
358 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
362 /***********************************************************************
363 * FrameRect (USER.83)
365 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
367 RECT rect;
369 rect.left = rect16->left;
370 rect.top = rect16->top;
371 rect.right = rect16->right;
372 rect.bottom = rect16->bottom;
373 return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
377 /***********************************************************************
378 * DrawIcon (USER.84)
380 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
382 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
386 /***********************************************************************
387 * DrawText (USER.85)
389 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
391 INT16 ret;
393 if (rect)
395 RECT rect32;
397 rect32.left = rect->left;
398 rect32.top = rect->top;
399 rect32.right = rect->right;
400 rect32.bottom = rect->bottom;
401 ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
402 rect->left = rect32.left;
403 rect->top = rect32.top;
404 rect->right = rect32.right;
405 rect->bottom = rect32.bottom;
407 else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
408 return ret;
412 /***********************************************************************
413 * IconSize (USER.86)
415 * See "Undocumented Windows". Used by W2.0 paint.exe.
417 DWORD WINAPI IconSize16(void)
419 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
423 /***********************************************************************
424 * AdjustWindowRect (USER.102)
426 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
428 return AdjustWindowRectEx16( rect, style, menu, 0 );
432 /***********************************************************************
433 * MessageBeep (USER.104)
435 void WINAPI MessageBeep16( UINT16 i )
437 MessageBeep( i );
441 /**************************************************************************
442 * CloseClipboard (USER.138)
444 BOOL16 WINAPI CloseClipboard16(void)
446 return CloseClipboard();
450 /**************************************************************************
451 * EmptyClipboard (USER.139)
453 BOOL16 WINAPI EmptyClipboard16(void)
455 return EmptyClipboard();
459 /**************************************************************************
460 * CountClipboardFormats (USER.143)
462 INT16 WINAPI CountClipboardFormats16(void)
464 return CountClipboardFormats();
468 /**************************************************************************
469 * EnumClipboardFormats (USER.144)
471 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
473 return EnumClipboardFormats( id );
477 /**************************************************************************
478 * RegisterClipboardFormat (USER.145)
480 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
482 return RegisterClipboardFormatA( name );
486 /**************************************************************************
487 * GetClipboardFormatName (USER.146)
489 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
491 return GetClipboardFormatNameA( id, buffer, maxlen );
495 /**********************************************************************
496 * CreateMenu (USER.151)
498 HMENU16 WINAPI CreateMenu16(void)
500 return HMENU_16( CreateMenu() );
504 /**********************************************************************
505 * DestroyMenu (USER.152)
507 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
509 return DestroyMenu( HMENU_32(hMenu) );
513 /*******************************************************************
514 * ChangeMenu (USER.153)
516 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
517 UINT16 id, UINT16 flags )
519 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
521 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
522 /* for MF_DELETE. We should check the parameters for all others */
523 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
525 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
526 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
527 if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
528 flags & ~MF_REMOVE );
529 /* Default: MF_INSERT */
530 return InsertMenu16( hMenu, pos, flags, id, data );
534 /*******************************************************************
535 * CheckMenuItem (USER.154)
537 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
539 return CheckMenuItem( HMENU_32(hMenu), id, flags );
543 /**********************************************************************
544 * EnableMenuItem (USER.155)
546 BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
548 return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
552 /**********************************************************************
553 * GetSubMenu (USER.159)
555 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
557 return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
561 /*******************************************************************
562 * GetMenuString (USER.161)
564 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
565 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
567 return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
571 /**********************************************************************
572 * WinHelp (USER.171)
574 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
575 DWORD dwData )
577 BOOL ret;
578 DWORD mutex_count;
580 /* We might call WinExec() */
581 ReleaseThunkLock(&mutex_count);
583 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
585 RestoreThunkLock(mutex_count);
586 return ret;
590 /***********************************************************************
591 * LoadCursor (USER.173)
593 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
595 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
599 /***********************************************************************
600 * LoadIcon (USER.174)
602 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
604 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
607 /**********************************************************************
608 * LoadBitmap (USER.175)
610 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
612 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
616 /***********************************************************************
617 * GetSystemMetrics (USER.179)
619 INT16 WINAPI GetSystemMetrics16( INT16 index )
621 return GetSystemMetrics( index );
625 /*************************************************************************
626 * GetSysColor (USER.180)
628 COLORREF WINAPI GetSysColor16( INT16 index )
630 return GetSysColor( index );
634 /*************************************************************************
635 * SetSysColors (USER.181)
637 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
639 INT i, *list;
641 if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
643 for (i = 0; i < count; i++) list[i] = list16[i];
644 SetSysColors( count, list, values );
645 HeapFree( GetProcessHeap(), 0, list );
650 /***********************************************************************
651 * GrayString (USER.185)
653 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
654 LPARAM lParam, INT16 cch, INT16 x, INT16 y,
655 INT16 cx, INT16 cy )
657 BOOL ret;
659 if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
660 (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
662 if (cch == -1 || (cch && cx && cy))
664 /* lParam can be treated as an opaque pointer */
665 struct gray_string_info info;
667 info.proc = gsprc;
668 info.param = lParam;
669 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
670 (LPARAM)&info, cch, x, y, cx, cy );
672 else /* here we need some string conversions */
674 char *str16 = MapSL(lParam);
675 struct gray_string_info *info;
677 if (!cch) cch = strlen(str16);
678 if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
679 info->proc = gsprc;
680 info->param = lParam;
681 memcpy( info->str, str16, cch );
682 ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
683 (LPARAM)info->str, cch, x, y, cx, cy );
684 HeapFree( GetProcessHeap(), 0, info );
686 return ret;
690 /***********************************************************************
691 * SwapMouseButton (USER.186)
693 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
695 return SwapMouseButton( fSwap );
699 /**************************************************************************
700 * IsClipboardFormatAvailable (USER.193)
702 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
704 return IsClipboardFormatAvailable( wFormat );
708 /***********************************************************************
709 * TabbedTextOut (USER.196)
711 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
712 INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
714 LONG ret;
715 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
716 if (!tabs) return 0;
717 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
718 ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
719 HeapFree( GetProcessHeap(), 0, tabs );
720 return ret;
724 /***********************************************************************
725 * GetTabbedTextExtent (USER.197)
727 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
728 INT16 nb_tabs, const INT16 *tabs16 )
730 LONG ret;
731 INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
732 if (!tabs) return 0;
733 for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
734 ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
735 HeapFree( GetProcessHeap(), 0, tabs );
736 return ret;
740 /***********************************************************************
741 * UserSeeUserDo (USER.216)
743 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
745 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
746 HANDLE16 oldDS = stack16->ds;
747 DWORD ret = (DWORD)-1;
749 stack16->ds = USER_HeapSel;
750 switch (wReqType)
752 case USUD_LOCALALLOC:
753 ret = LocalAlloc16(wParam1, wParam3);
754 break;
755 case USUD_LOCALFREE:
756 ret = LocalFree16(wParam1);
757 break;
758 case USUD_LOCALCOMPACT:
759 ret = LocalCompact16(wParam3);
760 break;
761 case USUD_LOCALHEAP:
762 ret = USER_HeapSel;
763 break;
764 case USUD_FIRSTCLASS:
765 FIXME("return a pointer to the first window class.\n");
766 break;
767 default:
768 WARN("wReqType %04x (unknown)\n", wReqType);
770 stack16->ds = oldDS;
771 return ret;
775 /*************************************************************************
776 * ScrollDC (USER.221)
778 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
779 const RECT16 *cliprc, HRGN16 hrgnUpdate,
780 LPRECT16 rcUpdate )
782 RECT rect32, clipRect32, rcUpdate32;
783 BOOL16 ret;
785 if (rect)
787 rect32.left = rect->left;
788 rect32.top = rect->top;
789 rect32.right = rect->right;
790 rect32.bottom = rect->bottom;
792 if (cliprc)
794 clipRect32.left = cliprc->left;
795 clipRect32.top = cliprc->top;
796 clipRect32.right = cliprc->right;
797 clipRect32.bottom = cliprc->bottom;
799 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
800 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
801 &rcUpdate32 );
802 if (rcUpdate)
804 rcUpdate->left = rcUpdate32.left;
805 rcUpdate->top = rcUpdate32.top;
806 rcUpdate->right = rcUpdate32.right;
807 rcUpdate->bottom = rcUpdate32.bottom;
809 return ret;
813 /***********************************************************************
814 * GetSystemDebugState (USER.231)
816 WORD WINAPI GetSystemDebugState16(void)
818 return 0; /* FIXME */
822 /***********************************************************************
823 * EqualRect (USER.244)
825 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
827 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
828 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
832 /***********************************************************************
833 * ExitWindowsExec (USER.246)
835 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
837 TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
838 lpszExe, lpszParams);
839 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
843 /***********************************************************************
844 * GetCursor (USER.247)
846 HCURSOR16 WINAPI GetCursor16(void)
848 return HCURSOR_16(GetCursor());
852 /**********************************************************************
853 * GetAsyncKeyState (USER.249)
855 INT16 WINAPI GetAsyncKeyState16( INT16 key )
857 return GetAsyncKeyState( key );
861 /**********************************************************************
862 * GetMenuState (USER.250)
864 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
866 return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
870 /**********************************************************************
871 * GetMenuItemCount (USER.263)
873 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
875 return GetMenuItemCount( HMENU_32(hMenu) );
879 /**********************************************************************
880 * GetMenuItemID (USER.264)
882 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
884 return GetMenuItemID( HMENU_32(hMenu), nPos );
888 /***********************************************************************
889 * GlobalAddAtom (USER.268)
891 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
893 return GlobalAddAtomA(lpString);
896 /***********************************************************************
897 * GlobalDeleteAtom (USER.269)
899 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
901 return GlobalDeleteAtom(nAtom);
904 /***********************************************************************
905 * GlobalFindAtom (USER.270)
907 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
909 return GlobalFindAtomA(lpString);
912 /***********************************************************************
913 * GlobalGetAtomName (USER.271)
915 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
917 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
921 /***********************************************************************
922 * ControlPanelInfo (USER.273)
924 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
926 FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
930 /***********************************************************************
931 * OldSetDeskPattern (USER.279)
933 BOOL16 WINAPI SetDeskPattern16(void)
935 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
939 /***********************************************************************
940 * GetSysColorBrush (USER.281)
942 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
944 return HBRUSH_16( GetSysColorBrush(index) );
948 /***********************************************************************
949 * SelectPalette (USER.282)
951 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
953 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
956 /***********************************************************************
957 * RealizePalette (USER.283)
959 UINT16 WINAPI RealizePalette16( HDC16 hdc )
961 return UserRealizePalette( HDC_32(hdc) );
965 /***********************************************************************
966 * GetFreeSystemResources (USER.284)
968 WORD WINAPI GetFreeSystemResources16( WORD resType )
970 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
971 HANDLE16 oldDS = stack16->ds;
972 HINSTANCE16 gdi_inst;
973 int userPercent, gdiPercent;
975 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
977 switch(resType)
979 case GFSR_USERRESOURCES:
980 stack16->ds = USER_HeapSel;
981 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
982 gdiPercent = 100;
983 stack16->ds = oldDS;
984 break;
986 case GFSR_GDIRESOURCES:
987 stack16->ds = gdi_inst;
988 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
989 userPercent = 100;
990 stack16->ds = oldDS;
991 break;
993 case GFSR_SYSTEMRESOURCES:
994 stack16->ds = USER_HeapSel;
995 userPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
996 stack16->ds = gdi_inst;
997 gdiPercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
998 stack16->ds = oldDS;
999 break;
1001 default:
1002 userPercent = gdiPercent = 0;
1003 break;
1005 FreeLibrary16( gdi_inst );
1006 TRACE("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
1007 return (WORD)min( userPercent, gdiPercent );
1011 /***********************************************************************
1012 * SetDeskWallPaper (USER.285)
1014 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
1016 return SetDeskWallPaper( filename );
1020 /***********************************************************************
1021 * keybd_event (USER.289)
1023 void WINAPI keybd_event16( CONTEXT86 *context )
1025 DWORD dwFlags = 0;
1027 if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
1028 if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;
1030 keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
1031 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
1035 /***********************************************************************
1036 * mouse_event (USER.299)
1038 void WINAPI mouse_event16( CONTEXT86 *context )
1040 mouse_event( LOWORD(context->Eax), LOWORD(context->Ebx), LOWORD(context->Ecx),
1041 LOWORD(context->Edx), MAKELONG(context->Esi, context->Edi) );
1045 /***********************************************************************
1046 * GetClipCursor (USER.309)
1048 void WINAPI GetClipCursor16( RECT16 *rect )
1050 if (rect)
1052 RECT rect32;
1053 GetClipCursor( &rect32 );
1054 rect->left = rect32.left;
1055 rect->top = rect32.top;
1056 rect->right = rect32.right;
1057 rect->bottom = rect32.bottom;
1062 /***********************************************************************
1063 * SignalProc (USER.314)
1065 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
1066 UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
1068 if (code == USIG16_DLL_UNLOAD)
1070 /* HOOK_FreeModuleHooks( hModule ); */
1071 CLASS_FreeModuleClasses( hModule );
1072 CURSORICON_FreeModuleIcons( hModule );
1077 /***********************************************************************
1078 * SetEventHook (USER.321)
1080 * Used by Turbo Debugger for Windows
1082 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
1084 FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
1085 return 0;
1089 /**********************************************************************
1090 * EnableHardwareInput (USER.331)
1092 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
1094 FIXME("(%d) - stub\n", bEnable);
1095 return TRUE;
1099 /***********************************************************************
1100 * GetMouseEventProc (USER.337)
1102 FARPROC16 WINAPI GetMouseEventProc16(void)
1104 HMODULE16 hmodule = GetModuleHandle16("USER");
1105 return GetProcAddress16( hmodule, "mouse_event" );
1109 /***********************************************************************
1110 * IsUserIdle (USER.333)
1112 BOOL16 WINAPI IsUserIdle16(void)
1114 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
1115 return FALSE;
1116 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
1117 return FALSE;
1118 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
1119 return FALSE;
1120 /* Should check for screen saver activation here ... */
1121 return TRUE;
1125 /**********************************************************************
1126 * LoadDIBIconHandler (USER.357)
1128 * RT_ICON resource loader, installed by USER_SignalProc when module
1129 * is initialized.
1131 HGLOBAL16 WINAPI LoadDIBIconHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1133 /* If hResource is zero we must allocate a new memory block, if it's
1134 * non-zero but GlobalLock() returns NULL then it was discarded and
1135 * we have to recommit some memory, otherwise we just need to check
1136 * the block size. See LoadProc() in 16-bit SDK for more.
1138 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1139 return 0;
1142 /**********************************************************************
1143 * LoadDIBCursorHandler (USER.356)
1145 * RT_CURSOR resource loader. Same as above.
1147 HGLOBAL16 WINAPI LoadDIBCursorHandler16( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
1149 FIXME( "%x %x %x: stub, not supported anymore\n", hMemObj, hModule, hRsrc );
1150 return 0;
1154 /**********************************************************************
1155 * IsMenu (USER.358)
1157 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
1159 return IsMenu( HMENU_32(hmenu) );
1163 /***********************************************************************
1164 * DCHook (USER.362)
1166 BOOL16 WINAPI DCHook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1168 FIXME( "hDC = %x, %i: stub\n", hdc, code );
1169 return FALSE;
1173 /***********************************************************************
1174 * SubtractRect (USER.373)
1176 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
1177 const RECT16 *src2 )
1179 RECT16 tmp;
1181 if (IsRectEmpty16( src1 ))
1183 SetRectEmpty16( dest );
1184 return FALSE;
1186 *dest = *src1;
1187 if (IntersectRect16( &tmp, src1, src2 ))
1189 if (EqualRect16( &tmp, dest ))
1191 SetRectEmpty16( dest );
1192 return FALSE;
1194 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1196 if (tmp.left == dest->left) dest->left = tmp.right;
1197 else if (tmp.right == dest->right) dest->right = tmp.left;
1199 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1201 if (tmp.top == dest->top) dest->top = tmp.bottom;
1202 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1205 return TRUE;
1209 /**********************************************************************
1210 * DllEntryPoint (USER.374)
1212 BOOL WINAPI DllEntryPoint( DWORD reason, HINSTANCE16 inst, WORD ds,
1213 WORD heap, DWORD reserved1, WORD reserved2 )
1215 if (reason != DLL_PROCESS_ATTACH) return TRUE;
1216 if (USER_HeapSel) return TRUE; /* already called */
1218 USER_HeapSel = ds;
1219 return TRUE;
1223 /**********************************************************************
1224 * SetMenuContextHelpId (USER.384)
1226 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
1228 return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
1232 /**********************************************************************
1233 * GetMenuContextHelpId (USER.385)
1235 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
1237 return GetMenuContextHelpId( HMENU_32(hMenu) );
1241 /***********************************************************************
1242 * LoadImage (USER.389)
1245 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
1246 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
1248 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
1249 desiredy, loadflags));
1252 /******************************************************************************
1253 * CopyImage (USER.390) Creates new image and copies attributes to it
1256 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
1257 INT16 desiredy, UINT16 flags)
1259 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
1260 (INT)desiredy, (UINT)flags));
1263 /**********************************************************************
1264 * DrawIconEx (USER.394)
1266 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
1267 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
1268 HBRUSH16 hbr, UINT16 flags)
1270 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
1271 istep, HBRUSH_32(hbr), flags);
1274 /**********************************************************************
1275 * GetIconInfo (USER.395)
1277 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
1279 ICONINFO ii32;
1280 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
1282 iconinfo->fIcon = ii32.fIcon;
1283 iconinfo->xHotspot = ii32.xHotspot;
1284 iconinfo->yHotspot = ii32.yHotspot;
1285 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
1286 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
1287 return ret;
1291 /***********************************************************************
1292 * FinalUserInit (USER.400)
1294 void WINAPI FinalUserInit16( void )
1296 /* FIXME: Should chain to FinalGdiInit */
1300 /***********************************************************************
1301 * CreateCursor (USER.406)
1303 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
1304 INT16 xHotSpot, INT16 yHotSpot,
1305 INT16 nWidth, INT16 nHeight,
1306 LPCVOID lpANDbits, LPCVOID lpXORbits)
1308 CURSORICONINFO info;
1310 info.ptHotSpot.x = xHotSpot;
1311 info.ptHotSpot.y = yHotSpot;
1312 info.nWidth = nWidth;
1313 info.nHeight = nHeight;
1314 info.nWidthBytes = 0;
1315 info.bPlanes = 1;
1316 info.bBitsPerPixel = 1;
1318 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
1322 /***********************************************************************
1323 * InitThreadInput (USER.409)
1325 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1327 /* nothing to do here */
1328 return 0xbeef;
1332 /*******************************************************************
1333 * InsertMenu (USER.410)
1335 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1336 UINT16 id, SEGPTR data )
1338 UINT pos32 = (UINT)pos;
1339 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
1340 if (IS_MENU_STRING_ITEM(flags) && data)
1341 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
1342 return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
1346 /*******************************************************************
1347 * AppendMenu (USER.411)
1349 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
1351 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
1355 /**********************************************************************
1356 * RemoveMenu (USER.412)
1358 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1360 return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
1364 /**********************************************************************
1365 * DeleteMenu (USER.413)
1367 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
1369 return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
1373 /*******************************************************************
1374 * ModifyMenu (USER.414)
1376 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
1377 UINT16 id, SEGPTR data )
1379 if (IS_MENU_STRING_ITEM(flags))
1380 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
1381 return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
1385 /**********************************************************************
1386 * CreatePopupMenu (USER.415)
1388 HMENU16 WINAPI CreatePopupMenu16(void)
1390 return HMENU_16( CreatePopupMenu() );
1394 /**********************************************************************
1395 * SetMenuItemBitmaps (USER.418)
1397 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
1398 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
1400 return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
1401 HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
1405 /***********************************************************************
1406 * lstrcmp (USER.430)
1408 INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
1410 return strcmp( str1, str2 );
1414 /***********************************************************************
1415 * AnsiUpper (USER.431)
1417 SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
1419 /* uppercase only one char if strOrChar < 0x10000 */
1420 if (HIWORD(strOrChar))
1422 CharUpperA( MapSL(strOrChar) );
1423 return strOrChar;
1425 else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
1429 /***********************************************************************
1430 * AnsiLower (USER.432)
1432 SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
1434 /* lowercase only one char if strOrChar < 0x10000 */
1435 if (HIWORD(strOrChar))
1437 CharLowerA( MapSL(strOrChar) );
1438 return strOrChar;
1440 else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
1444 /***********************************************************************
1445 * AnsiUpperBuff (USER.437)
1447 UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
1449 CharUpperBuffA( str, len ? len : 65536 );
1450 return len;
1454 /***********************************************************************
1455 * AnsiLowerBuff (USER.438)
1457 UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
1459 CharLowerBuffA( str, len ? len : 65536 );
1460 return len;
1464 /*******************************************************************
1465 * InsertMenuItem (USER.441)
1467 * FIXME: untested
1469 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
1470 const MENUITEMINFO16 *mii )
1472 MENUITEMINFOA miia;
1474 miia.cbSize = sizeof(miia);
1475 miia.fMask = mii->fMask;
1476 miia.dwTypeData = (LPSTR)mii->dwTypeData;
1477 miia.fType = mii->fType;
1478 miia.fState = mii->fState;
1479 miia.wID = mii->wID;
1480 miia.hSubMenu = HMENU_32(mii->hSubMenu);
1481 miia.hbmpChecked = HBITMAP_32(mii->hbmpChecked);
1482 miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1483 miia.dwItemData = mii->dwItemData;
1484 miia.cch = mii->cch;
1485 if (IS_MENU_STRING_ITEM(miia.fType))
1486 miia.dwTypeData = MapSL(mii->dwTypeData);
1487 return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1491 /**********************************************************************
1492 * DrawState (USER.449)
1494 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1495 WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1497 struct draw_state_info info;
1498 UINT opcode = flags & 0xf;
1500 if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1502 /* make sure DrawStateA doesn't try to use ldata as a pointer */
1503 if (!wdata) wdata = strlen( MapSL(ldata) );
1504 if (!cx || !cy)
1506 SIZE s;
1507 if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1508 if (!cx) cx = s.cx;
1509 if (!cy) cy = s.cy;
1512 info.proc = func;
1513 info.param = ldata;
1514 return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1515 (LPARAM)&info, wdata, x, y, cx, cy, flags );
1519 /**********************************************************************
1520 * CreateIconFromResourceEx (USER.450)
1522 * FIXME: not sure about exact parameter types
1524 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1525 BOOL16 bIcon, DWORD dwVersion,
1526 INT16 width, INT16 height,
1527 UINT16 cFlag)
1529 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1530 width, height, cFlag));
1534 /***********************************************************************
1535 * AdjustWindowRectEx (USER.454)
1537 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1539 RECT rect32;
1540 BOOL ret;
1542 rect32.left = rect->left;
1543 rect32.top = rect->top;
1544 rect32.right = rect->right;
1545 rect32.bottom = rect->bottom;
1546 ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1547 rect->left = rect32.left;
1548 rect->top = rect32.top;
1549 rect->right = rect32.right;
1550 rect->bottom = rect32.bottom;
1551 return ret;
1555 /***********************************************************************
1556 * DestroyIcon (USER.457)
1558 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1560 return DestroyIcon32(hIcon, 0);
1563 /***********************************************************************
1564 * DestroyCursor (USER.458)
1566 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1568 return DestroyIcon32(hCursor, 0);
1571 /*******************************************************************
1572 * DRAG_QueryUpdate16
1574 * Recursively find a child that contains spDragInfo->pt point
1575 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1577 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1579 BOOL bResult = 0;
1580 WPARAM wParam;
1581 POINT pt, old_pt;
1582 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1583 RECT tempRect;
1584 HWND child;
1586 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1588 old_pt.x = ptrDragInfo->pt.x;
1589 old_pt.y = ptrDragInfo->pt.y;
1590 pt = old_pt;
1591 ScreenToClient( hQueryWnd, &pt );
1592 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1593 if (!child) return FALSE;
1595 if (child != hQueryWnd)
1597 wParam = 0;
1598 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1600 else
1602 GetClientRect( hQueryWnd, &tempRect );
1603 wParam = !PtInRect( &tempRect, pt );
1606 ptrDragInfo->pt.x = pt.x;
1607 ptrDragInfo->pt.y = pt.y;
1608 ptrDragInfo->hScope = HWND_16(hQueryWnd);
1610 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1612 if (!bResult)
1614 ptrDragInfo->pt.x = old_pt.x;
1615 ptrDragInfo->pt.y = old_pt.y;
1617 return bResult;
1621 /******************************************************************************
1622 * DragObject (USER.464)
1624 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1625 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1627 MSG msg;
1628 LPDRAGINFO16 lpDragInfo;
1629 SEGPTR spDragInfo;
1630 HCURSOR hOldCursor=0, hBummer=0;
1631 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1632 HCURSOR hCurrentCursor = 0;
1633 HWND16 hCurrentWnd = 0;
1635 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1636 spDragInfo = WOWGlobalLock16(hDragInfo);
1638 if( !lpDragInfo || !spDragInfo ) return 0L;
1640 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1642 GlobalFree16(hDragInfo);
1643 return 0L;
1646 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1648 lpDragInfo->hWnd = hWnd;
1649 lpDragInfo->hScope = 0;
1650 lpDragInfo->wFlags = wObj;
1651 lpDragInfo->hList = szList; /* near pointer! */
1652 lpDragInfo->hOfStruct = hOfStruct;
1653 lpDragInfo->l = 0L;
1655 SetCapture( HWND_32(hWnd) );
1656 ShowCursor( TRUE );
1660 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1662 *(lpDragInfo+1) = *lpDragInfo;
1664 lpDragInfo->pt.x = msg.pt.x;
1665 lpDragInfo->pt.y = msg.pt.y;
1667 /* update DRAGINFO struct */
1668 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1669 hCurrentCursor = HCURSOR_32(hCursor);
1670 else
1672 hCurrentCursor = hBummer;
1673 lpDragInfo->hScope = 0;
1675 if( hCurrentCursor )
1676 SetCursor(hCurrentCursor);
1678 /* send WM_DRAGLOOP */
1679 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1680 (LPARAM) spDragInfo );
1681 /* send WM_DRAGSELECT or WM_DRAGMOVE */
1682 if( hCurrentWnd != lpDragInfo->hScope )
1684 if( hCurrentWnd )
1685 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1686 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1687 HIWORD(spDragInfo)) );
1688 hCurrentWnd = lpDragInfo->hScope;
1689 if( hCurrentWnd )
1690 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1692 else
1693 if( hCurrentWnd )
1694 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1696 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1698 ReleaseCapture();
1699 ShowCursor( FALSE );
1701 if( hCursor ) SetCursor(hOldCursor);
1703 if( hCurrentCursor != hBummer )
1704 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1705 (WPARAM16)hWnd, (LPARAM)spDragInfo );
1706 else
1707 msg.lParam = 0;
1708 GlobalFree16(hDragInfo);
1710 return (DWORD)(msg.lParam);
1714 /***********************************************************************
1715 * DrawFocusRect (USER.466)
1717 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1719 RECT rect32;
1721 rect32.left = rc->left;
1722 rect32.top = rc->top;
1723 rect32.right = rc->right;
1724 rect32.bottom = rc->bottom;
1725 DrawFocusRect( HDC_32(hdc), &rect32 );
1729 /***********************************************************************
1730 * AnsiNext (USER.472)
1732 SEGPTR WINAPI AnsiNext16(SEGPTR current)
1734 char *ptr = MapSL(current);
1735 return current + (CharNextA(ptr) - ptr);
1739 /***********************************************************************
1740 * AnsiPrev (USER.473)
1742 SEGPTR WINAPI AnsiPrev16( LPCSTR start, SEGPTR current )
1744 char *ptr = MapSL(current);
1745 return current - (ptr - CharPrevA( start, ptr ));
1749 /****************************************************************************
1750 * GetKeyboardLayoutName (USER.477)
1752 INT16 WINAPI GetKeyboardLayoutName16( LPSTR name )
1754 return GetKeyboardLayoutNameA( name );
1758 /***********************************************************************
1759 * FormatMessage (USER.606)
1761 DWORD WINAPI FormatMessage16(
1762 DWORD dwFlags,
1763 SEGPTR lpSource, /* [in] NOTE: not always a valid pointer */
1764 WORD dwMessageId,
1765 WORD dwLanguageId,
1766 LPSTR lpBuffer, /* [out] NOTE: *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
1767 WORD nSize,
1768 LPDWORD args ) /* [in] NOTE: va_list *args */
1770 #ifdef __i386__
1771 /* This implementation is completely dependent on the format of the va_list on x86 CPUs */
1772 LPSTR target,t;
1773 DWORD talloced;
1774 LPSTR from,f;
1775 DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
1776 BOOL eos = FALSE;
1777 LPSTR allocstring = NULL;
1779 TRACE("(0x%x,%x,%d,0x%x,%p,%d,%p)\n",
1780 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
1781 if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1782 && (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
1783 if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
1784 &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
1785 || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
1787 if (width && width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
1788 FIXME("line wrapping (%u) not supported.\n", width);
1789 from = NULL;
1790 if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
1792 char *source = MapSL(lpSource);
1793 from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 );
1794 strcpy( from, source );
1796 else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
1797 from = HeapAlloc( GetProcessHeap(),0,200 );
1798 sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
1800 else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
1801 INT16 bufsize;
1802 HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff);
1804 dwMessageId &= 0xFFFF;
1805 bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
1806 if (bufsize) {
1807 from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
1808 LoadString16(hinst16,dwMessageId,from,bufsize+1);
1811 target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
1812 t = target;
1813 talloced= 100;
1815 #define ADD_TO_T(c) \
1816 *t++=c;\
1817 if (t-target == talloced) {\
1818 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\
1819 t = target+talloced;\
1820 talloced*=2;\
1823 if (from) {
1824 f=from;
1825 while (*f && !eos) {
1826 if (*f=='%') {
1827 int insertnr;
1828 char *fmtstr,*x,*lastf;
1829 DWORD *argliststart;
1831 fmtstr = NULL;
1832 lastf = f;
1833 f++;
1834 if (!*f) {
1835 ADD_TO_T('%');
1836 continue;
1838 switch (*f) {
1839 case '1':case '2':case '3':case '4':case '5':
1840 case '6':case '7':case '8':case '9':
1841 insertnr=*f-'0';
1842 switch (f[1]) {
1843 case '0':case '1':case '2':case '3':
1844 case '4':case '5':case '6':case '7':
1845 case '8':case '9':
1846 f++;
1847 insertnr=insertnr*10+*f-'0';
1848 f++;
1849 break;
1850 default:
1851 f++;
1852 break;
1854 if (*f=='!') {
1855 f++;
1856 if (NULL!=(x=strchr(f,'!'))) {
1857 *x='\0';
1858 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1859 sprintf(fmtstr,"%%%s",f);
1860 f=x+1;
1861 } else {
1862 fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2);
1863 sprintf(fmtstr,"%%%s",f);
1864 f+=strlen(f); /*at \0*/
1867 else
1869 if(!args) break;
1870 fmtstr=HeapAlloc( GetProcessHeap(), 0, 3 );
1871 strcpy( fmtstr, "%s" );
1873 if (args) {
1874 int ret;
1875 int sz;
1876 LPSTR b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
1878 argliststart=args+insertnr-1;
1880 /* CMF - This makes a BIG assumption about va_list */
1881 while ((ret = vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) || (ret >= sz)) {
1882 sz = (ret == -1 ? sz + 100 : ret + 1);
1883 b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz);
1885 for (x=b; *x; x++) ADD_TO_T(*x);
1886 HeapFree(GetProcessHeap(), 0, b);
1887 } else {
1888 /* NULL args - copy formatstr
1889 * (probably wrong)
1891 while ((lastf<f)&&(*lastf)) {
1892 ADD_TO_T(*lastf++);
1895 HeapFree(GetProcessHeap(),0,fmtstr);
1896 break;
1897 case '0': /* Just stop processing format string */
1898 eos = TRUE;
1899 f++;
1900 break;
1901 case 'n': /* 16 bit version just outputs 'n' */
1902 default:
1903 ADD_TO_T(*f++);
1904 break;
1906 } else { /* '\n' or '\r' gets mapped to "\r\n" */
1907 if(*f == '\n' || *f == '\r') {
1908 if (width == 0) {
1909 ADD_TO_T('\r');
1910 ADD_TO_T('\n');
1911 if(*f++ == '\r' && *f == '\n')
1912 f++;
1914 } else {
1915 ADD_TO_T(*f++);
1919 *t='\0';
1921 talloced = strlen(target)+1;
1922 if (nSize && talloced<nSize) {
1923 target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize);
1925 TRACE("-- %s\n",debugstr_a(target));
1926 if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
1927 /* nSize is the MINIMUM size */
1928 HLOCAL16 h = LocalAlloc16(LPTR,talloced);
1929 SEGPTR ptr = LocalLock16(h);
1930 allocstring = MapSL( ptr );
1931 memcpy( allocstring,target,talloced);
1932 LocalUnlock16( h );
1933 *((HLOCAL16*)lpBuffer) = h;
1934 } else
1935 lstrcpynA(lpBuffer,target,nSize);
1936 HeapFree(GetProcessHeap(),0,target);
1937 HeapFree(GetProcessHeap(),0,from);
1938 return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
1939 strlen(allocstring):
1940 strlen(lpBuffer);
1941 #else
1942 return 0;
1943 #endif /* __i386__ */
1945 #undef ADD_TO_T
1948 /***********************************************************************
1949 * ChangeDisplaySettings (USER.620)
1951 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1953 return ChangeDisplaySettingsA( devmode, flags );
1957 /***********************************************************************
1958 * EnumDisplaySettings (USER.621)
1960 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1962 return EnumDisplaySettingsA( name, n, devmode );
1965 /**********************************************************************
1966 * DrawFrameControl (USER.656)
1968 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1970 RECT rect32;
1971 BOOL ret;
1973 rect32.left = rc->left;
1974 rect32.top = rc->top;
1975 rect32.right = rc->right;
1976 rect32.bottom = rc->bottom;
1977 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1978 rc->left = rect32.left;
1979 rc->top = rect32.top;
1980 rc->right = rect32.right;
1981 rc->bottom = rect32.bottom;
1982 return ret;
1985 /**********************************************************************
1986 * DrawEdge (USER.659)
1988 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1990 RECT rect32;
1991 BOOL ret;
1993 rect32.left = rc->left;
1994 rect32.top = rc->top;
1995 rect32.right = rc->right;
1996 rect32.bottom = rc->bottom;
1997 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1998 rc->left = rect32.left;
1999 rc->top = rect32.top;
2000 rc->right = rect32.right;
2001 rc->bottom = rect32.bottom;
2002 return ret;
2005 /**********************************************************************
2006 * CheckMenuRadioItem (USER.666)
2008 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
2009 UINT16 check, BOOL16 bypos)
2011 return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );