Fixed some errors in function prototypes.
[wine] / dlls / user / user16.c
1 /*
2  * Misc 16-bit USER functions
3  *
4  * Copyright 2002 Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include "wine/winuser16.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wownt32.h"
27 #include "user_private.h"
28 #include "win.h"
29 #include "winproc.h"
30 #include "cursoricon.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(user);
34
35 /* handle to handle 16 conversions */
36 #define HANDLE_16(h32)          (LOWORD(h32))
37
38 /* handle16 to handle conversions */
39 #define HANDLE_32(h16)          ((HANDLE)(ULONG_PTR)(h16))
40 #define HINSTANCE_32(h16)       ((HINSTANCE)(ULONG_PTR)(h16))
41
42 #define IS_MENU_STRING_ITEM(flags) \
43     (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
44
45 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
46
47
48 struct gray_string_info
49 {
50     GRAYSTRINGPROC16 proc;
51     LPARAM           param;
52     char             str[1];
53 };
54
55 /* callback for 16-bit gray string proc with opaque pointer */
56 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
57 {
58     const struct gray_string_info *info = (struct gray_string_info *)param;
59     WORD args[4];
60     DWORD ret;
61
62     args[3] = HDC_16(hdc);
63     args[2] = HIWORD(info->param);
64     args[1] = LOWORD(info->param);
65     args[0] = len;
66     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
67     return LOWORD(ret);
68 }
69
70 /* callback for 16-bit gray string proc with string pointer */
71 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
72 {
73     const struct gray_string_info *info;
74     char *str = (char *)param;
75
76     info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
77     return gray_string_callback( hdc, (LPARAM)info, len );
78 }
79
80 struct draw_state_info
81 {
82     DRAWSTATEPROC16 proc;
83     LPARAM          param;
84 };
85
86 /* callback for 16-bit DrawState functions */
87 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
88 {
89     const struct draw_state_info *info = (struct draw_state_info *)lparam;
90     WORD args[6];
91     DWORD ret;
92
93     args[5] = HDC_16(hdc);
94     args[4] = HIWORD(info->param);
95     args[3] = LOWORD(info->param);
96     args[2] = wparam;
97     args[1] = cx;
98     args[0] = cy;
99     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
100     return LOWORD(ret);
101 }
102
103
104 /**********************************************************************
105  *              InitApp (USER.5)
106  */
107 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
108 {
109     /* Create task message queue */
110     return (InitThreadInput16( 0, 0 ) != 0);
111 }
112
113
114 /***********************************************************************
115  *              ExitWindows (USER.7)
116  */
117 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
118 {
119     return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
120 }
121
122
123 /***********************************************************************
124  *              ClipCursor (USER.16)
125  */
126 BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
127 {
128     RECT rect32;
129
130     if (!rect) return ClipCursor( NULL );
131     rect32.left   = rect->left;
132     rect32.top    = rect->top;
133     rect32.right  = rect->right;
134     rect32.bottom = rect->bottom;
135     return ClipCursor( &rect32 );
136 }
137
138
139 /***********************************************************************
140  *              GetCursorPos (USER.17)
141  */
142 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
143 {
144     POINT pos;
145     if (!pt) return 0;
146     GetCursorPos(&pos);
147     pt->x = pos.x;
148     pt->y = pos.y;
149     return 1;
150 }
151
152
153 /***********************************************************************
154  *              SetCursor (USER.69)
155  */
156 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
157 {
158   return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
159 }
160
161
162 /***********************************************************************
163  *              SetCursorPos (USER.70)
164  */
165 void WINAPI SetCursorPos16( INT16 x, INT16 y )
166 {
167     SetCursorPos( x, y );
168 }
169
170
171 /***********************************************************************
172  *              ShowCursor (USER.71)
173  */
174 INT16 WINAPI ShowCursor16(BOOL16 bShow)
175 {
176   return ShowCursor(bShow);
177 }
178
179
180 /***********************************************************************
181  *              FillRect (USER.81)
182  * NOTE
183  *   The Win16 variant doesn't support special color brushes like
184  *   the Win32 one, despite the fact that Win16, as well as Win32,
185  *   supports special background brushes for a window class.
186  */
187 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
188 {
189     HBRUSH prevBrush;
190
191     /* coordinates are logical so we cannot fast-check 'rect',
192      * it will be done later in the PatBlt().
193      */
194
195     if (!(prevBrush = SelectObject( HDC_32(hdc), HBRUSH_32(hbrush) ))) return 0;
196     PatBlt( HDC_32(hdc), rect->left, rect->top,
197               rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
198     SelectObject( HDC_32(hdc), prevBrush );
199     return 1;
200 }
201
202
203 /***********************************************************************
204  *              InvertRect (USER.82)
205  */
206 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
207 {
208     PatBlt( HDC_32(hdc), rect->left, rect->top,
209               rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
210 }
211
212
213 /***********************************************************************
214  *              FrameRect (USER.83)
215  */
216 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
217 {
218     RECT rect;
219
220     rect.left   = rect16->left;
221     rect.top    = rect16->top;
222     rect.right  = rect16->right;
223     rect.bottom = rect16->bottom;
224     return FrameRect( HDC_32(hdc), &rect, HBRUSH_32(hbrush) );
225 }
226
227
228 /***********************************************************************
229  *              DrawIcon (USER.84)
230  */
231 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
232 {
233   return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
234 }
235
236
237 /***********************************************************************
238  *           DrawText    (USER.85)
239  */
240 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
241 {
242     INT16 ret;
243
244     if (rect)
245     {
246         RECT rect32;
247
248         rect32.left   = rect->left;
249         rect32.top    = rect->top;
250         rect32.right  = rect->right;
251         rect32.bottom = rect->bottom;
252         ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
253         rect->left   = rect32.left;
254         rect->top    = rect32.top;
255         rect->right  = rect32.right;
256         rect->bottom = rect32.bottom;
257     }
258     else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
259     return ret;
260 }
261
262
263 /***********************************************************************
264  *              IconSize (USER.86)
265  *
266  * See "Undocumented Windows". Used by W2.0 paint.exe.
267  */
268 DWORD WINAPI IconSize16(void)
269 {
270   return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
271 }
272
273
274 /***********************************************************************
275  *              AdjustWindowRect (USER.102)
276  */
277 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
278 {
279     return AdjustWindowRectEx16( rect, style, menu, 0 );
280 }
281
282
283 /**************************************************************************
284  *              CloseClipboard (USER.138)
285  */
286 BOOL16 WINAPI CloseClipboard16(void)
287 {
288     return CloseClipboard();
289 }
290
291
292 /**************************************************************************
293  *              EmptyClipboard (USER.139)
294  */
295 BOOL16 WINAPI EmptyClipboard16(void)
296 {
297     return EmptyClipboard();
298 }
299
300
301 /**************************************************************************
302  *              CountClipboardFormats (USER.143)
303  */
304 INT16 WINAPI CountClipboardFormats16(void)
305 {
306     return CountClipboardFormats();
307 }
308
309
310 /**************************************************************************
311  *              EnumClipboardFormats (USER.144)
312  */
313 UINT16 WINAPI EnumClipboardFormats16( UINT16 id )
314 {
315     return EnumClipboardFormats( id );
316 }
317
318
319 /**************************************************************************
320  *              RegisterClipboardFormat (USER.145)
321  */
322 UINT16 WINAPI RegisterClipboardFormat16( LPCSTR name )
323 {
324     return RegisterClipboardFormatA( name );
325 }
326
327
328 /**************************************************************************
329  *              GetClipboardFormatName (USER.146)
330  */
331 INT16 WINAPI GetClipboardFormatName16( UINT16 id, LPSTR buffer, INT16 maxlen )
332 {
333     return GetClipboardFormatNameA( id, buffer, maxlen );
334 }
335
336
337 /**********************************************************************
338  *         CreateMenu    (USER.151)
339  */
340 HMENU16 WINAPI CreateMenu16(void)
341 {
342     return HMENU_16( CreateMenu() );
343 }
344
345
346 /**********************************************************************
347  *         DestroyMenu    (USER.152)
348  */
349 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
350 {
351     return DestroyMenu( HMENU_32(hMenu) );
352 }
353
354
355 /*******************************************************************
356  *         ChangeMenu    (USER.153)
357  */
358 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
359                             UINT16 id, UINT16 flags )
360 {
361     if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
362
363     /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
364     /* for MF_DELETE. We should check the parameters for all others */
365     /* MF_* actions also (anybody got a doc on ChangeMenu?). */
366
367     if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
368     if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
369     if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
370                                                flags & ~MF_REMOVE );
371     /* Default: MF_INSERT */
372     return InsertMenu16( hMenu, pos, flags, id, data );
373 }
374
375
376 /*******************************************************************
377  *         CheckMenuItem    (USER.154)
378  */
379 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
380 {
381     return CheckMenuItem( HMENU_32(hMenu), id, flags );
382 }
383
384
385 /**********************************************************************
386  *         EnableMenuItem    (USER.155)
387  */
388 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
389 {
390     return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
391 }
392
393
394 /**********************************************************************
395  *         GetSubMenu    (USER.159)
396  */
397 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
398 {
399     return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
400 }
401
402
403 /*******************************************************************
404  *         GetMenuString    (USER.161)
405  */
406 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
407                               LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
408 {
409     return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
410 }
411
412
413 /**********************************************************************
414  *              WinHelp (USER.171)
415  */
416 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
417                          DWORD dwData )
418 {
419     BOOL ret;
420     DWORD mutex_count;
421
422     /* We might call WinExec() */
423     ReleaseThunkLock(&mutex_count);
424
425     ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
426
427     RestoreThunkLock(mutex_count);
428     return ret;
429 }
430
431
432 /***********************************************************************
433  *              LoadCursor (USER.173)
434  */
435 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
436 {
437   return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
438 }
439
440
441 /***********************************************************************
442  *              LoadIcon (USER.174)
443  */
444 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
445 {
446   return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
447 }
448
449 /**********************************************************************
450  *              LoadBitmap (USER.175)
451  */
452 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
453 {
454   return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
455 }
456
457
458 /***********************************************************************
459  *              GetSystemMetrics (USER.179)
460  */
461 INT16 WINAPI GetSystemMetrics16( INT16 index )
462 {
463     return GetSystemMetrics( index );
464 }
465
466
467 /*************************************************************************
468  *              GetSysColor (USER.180)
469  */
470 COLORREF WINAPI GetSysColor16( INT16 index )
471 {
472     return GetSysColor( index );
473 }
474
475
476 /*************************************************************************
477  *              SetSysColors (USER.181)
478  */
479 VOID WINAPI SetSysColors16( INT16 count, const INT16 *list16, const COLORREF *values )
480 {
481     INT i, *list;
482
483     if ((list = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*list) )))
484     {
485         for (i = 0; i < count; i++) list[i] = list16[i];
486         SetSysColors( count, list, values );
487         HeapFree( GetProcessHeap(), 0, list );
488     }
489 }
490
491
492 /***********************************************************************
493  *           GrayString   (USER.185)
494  */
495 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
496                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
497                             INT16 cx, INT16 cy )
498 {
499     BOOL ret;
500
501     if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
502                                     (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
503
504     if (cch == -1 || (cch && cx && cy))
505     {
506         /* lParam can be treated as an opaque pointer */
507         struct gray_string_info info;
508
509         info.proc  = gsprc;
510         info.param = lParam;
511         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
512                            (LPARAM)&info, cch, x, y, cx, cy );
513     }
514     else  /* here we need some string conversions */
515     {
516         char *str16 = MapSL(lParam);
517         struct gray_string_info *info;
518
519         if (!cch) cch = strlen(str16);
520         if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
521         info->proc  = gsprc;
522         info->param = lParam;
523         memcpy( info->str, str16, cch );
524         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
525                            (LPARAM)info->str, cch, x, y, cx, cy );
526         HeapFree( GetProcessHeap(), 0, info );
527     }
528     return ret;
529 }
530
531
532 /**************************************************************************
533  *              IsClipboardFormatAvailable (USER.193)
534  */
535 BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
536 {
537     return IsClipboardFormatAvailable( wFormat );
538 }
539
540
541 /***********************************************************************
542  *           TabbedTextOut    (USER.196)
543  */
544 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
545                              INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
546 {
547     LONG ret;
548     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
549     if (!tabs) return 0;
550     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
551     ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
552     HeapFree( GetProcessHeap(), 0, tabs );
553     return ret;
554 }
555
556
557 /***********************************************************************
558  *           GetTabbedTextExtent    (USER.197)
559  */
560 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
561                                     INT16 nb_tabs, const INT16 *tabs16 )
562 {
563     LONG ret;
564     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
565     if (!tabs) return 0;
566     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
567     ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
568     HeapFree( GetProcessHeap(), 0, tabs );
569     return ret;
570 }
571
572
573 /*************************************************************************
574  *              ScrollDC (USER.221)
575  */
576 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
577                           const RECT16 *cliprc, HRGN16 hrgnUpdate,
578                           LPRECT16 rcUpdate )
579 {
580     RECT rect32, clipRect32, rcUpdate32;
581     BOOL16 ret;
582
583     if (rect)
584     {
585         rect32.left   = rect->left;
586         rect32.top    = rect->top;
587         rect32.right  = rect->right;
588         rect32.bottom = rect->bottom;
589     }
590     if (cliprc)
591     {
592         clipRect32.left   = cliprc->left;
593         clipRect32.top    = cliprc->top;
594         clipRect32.right  = cliprc->right;
595         clipRect32.bottom = cliprc->bottom;
596     }
597     ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
598                     cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
599                     &rcUpdate32 );
600     if (rcUpdate)
601     {
602         rcUpdate->left   = rcUpdate32.left;
603         rcUpdate->top    = rcUpdate32.top;
604         rcUpdate->right  = rcUpdate32.right;
605         rcUpdate->bottom = rcUpdate32.bottom;
606     }
607     return ret;
608 }
609
610
611 /***********************************************************************
612  *              GetSystemDebugState (USER.231)
613  */
614 WORD WINAPI GetSystemDebugState16(void)
615 {
616     return 0;  /* FIXME */
617 }
618
619
620 /***********************************************************************
621  *              ExitWindowsExec (USER.246)
622  */
623 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
624 {
625     TRACE("Should run the following in DOS-mode: \"%s %s\"\n",
626           lpszExe, lpszParams);
627     return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
628 }
629
630
631 /***********************************************************************
632  *              GetCursor (USER.247)
633  */
634 HCURSOR16 WINAPI GetCursor16(void)
635 {
636   return HCURSOR_16(GetCursor());
637 }
638
639
640 /**********************************************************************
641  *              GetAsyncKeyState (USER.249)
642  */
643 INT16 WINAPI GetAsyncKeyState16( INT16 key )
644 {
645     return GetAsyncKeyState( key );
646 }
647
648
649 /**********************************************************************
650  *         GetMenuState    (USER.250)
651  */
652 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
653 {
654     return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
655 }
656
657
658 /**********************************************************************
659  *         GetMenuItemCount    (USER.263)
660  */
661 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
662 {
663     return GetMenuItemCount( HMENU_32(hMenu) );
664 }
665
666
667 /**********************************************************************
668  *         GetMenuItemID    (USER.264)
669  */
670 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
671 {
672     return GetMenuItemID( HMENU_32(hMenu), nPos );
673 }
674
675
676 /***********************************************************************
677  *              GlobalAddAtom (USER.268)
678  */
679 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
680 {
681   return GlobalAddAtomA(lpString);
682 }
683
684 /***********************************************************************
685  *              GlobalDeleteAtom (USER.269)
686  */
687 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
688 {
689   return GlobalDeleteAtom(nAtom);
690 }
691
692 /***********************************************************************
693  *              GlobalFindAtom (USER.270)
694  */
695 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
696 {
697   return GlobalFindAtomA(lpString);
698 }
699
700 /***********************************************************************
701  *              GlobalGetAtomName (USER.271)
702  */
703 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
704 {
705   return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
706 }
707
708
709 /***********************************************************************
710  *              GetSysColorBrush (USER.281)
711  */
712 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
713 {
714     return HBRUSH_16( GetSysColorBrush(index) );
715 }
716
717
718 /***********************************************************************
719  *              SelectPalette (USER.282)
720  */
721 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
722 {
723     return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
724 }
725
726 /***********************************************************************
727  *              RealizePalette (USER.283)
728  */
729 UINT16 WINAPI RealizePalette16( HDC16 hdc )
730 {
731     return UserRealizePalette( HDC_32(hdc) );
732 }
733
734
735 /***********************************************************************
736  *              GetClipCursor (USER.309)
737  */
738 void WINAPI GetClipCursor16( RECT16 *rect )
739 {
740     if (rect)
741     {
742         RECT rect32;
743         GetClipCursor( &rect32 );
744         rect->left   = rect32.left;
745         rect->top    = rect32.top;
746         rect->right  = rect32.right;
747         rect->bottom = rect32.bottom;
748     }
749 }
750
751
752 /***********************************************************************
753  *              SignalProc (USER.314)
754  */
755 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
756                           UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
757 {
758     if (code == USIG16_DLL_UNLOAD)
759     {
760         /* HOOK_FreeModuleHooks( hModule ); */
761         CLASS_FreeModuleClasses( hModule );
762         CURSORICON_FreeModuleIcons( hModule );
763     }
764 }
765
766
767 /***********************************************************************
768  *              SetEventHook (USER.321)
769  *
770  *      Used by Turbo Debugger for Windows
771  */
772 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
773 {
774     FIXME("(lpfnEventHook=%p): stub\n", lpfnEventHook);
775     return 0;
776 }
777
778
779 /**********************************************************************
780  *              EnableHardwareInput (USER.331)
781  */
782 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
783 {
784     FIXME("(%d) - stub\n", bEnable);
785     return TRUE;
786 }
787
788
789 /***********************************************************************
790  *              IsUserIdle (USER.333)
791  */
792 BOOL16 WINAPI IsUserIdle16(void)
793 {
794     if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
795         return FALSE;
796     if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
797         return FALSE;
798     if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
799         return FALSE;
800     /* Should check for screen saver activation here ... */
801     return TRUE;
802 }
803
804
805 /**********************************************************************
806  *              IsMenu    (USER.358)
807  */
808 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
809 {
810     return IsMenu( HMENU_32(hmenu) );
811 }
812
813
814 /**********************************************************************
815  *         SetMenuContextHelpId    (USER.384)
816  */
817 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
818 {
819     return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
820 }
821
822
823 /**********************************************************************
824  *         GetMenuContextHelpId    (USER.385)
825  */
826 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
827 {
828     return GetMenuContextHelpId( HMENU_32(hMenu) );
829 }
830
831
832 /***********************************************************************
833  *              LoadImage (USER.389)
834  *
835  */
836 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
837                             INT16 desiredx, INT16 desiredy, UINT16 loadflags)
838 {
839   return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
840                               desiredy, loadflags));
841 }
842
843 /******************************************************************************
844  *              CopyImage (USER.390) Creates new image and copies attributes to it
845  *
846  */
847 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
848                            INT16 desiredy, UINT16 flags)
849 {
850   return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
851                             (INT)desiredy, (UINT)flags));
852 }
853
854 /**********************************************************************
855  *              DrawIconEx (USER.394)
856  */
857 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
858                            INT16 cxWidth, INT16 cyWidth, UINT16 istep,
859                            HBRUSH16 hbr, UINT16 flags)
860 {
861   return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
862                     istep, HBRUSH_32(hbr), flags);
863 }
864
865 /**********************************************************************
866  *              GetIconInfo (USER.395)
867  */
868 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
869 {
870   ICONINFO ii32;
871   BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
872
873   iconinfo->fIcon = ii32.fIcon;
874   iconinfo->xHotspot = ii32.xHotspot;
875   iconinfo->yHotspot = ii32.yHotspot;
876   iconinfo->hbmMask  = HBITMAP_16(ii32.hbmMask);
877   iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
878   return ret;
879 }
880
881
882 /***********************************************************************
883  *              FinalUserInit (USER.400)
884  */
885 void WINAPI FinalUserInit16( void )
886 {
887     /* FIXME: Should chain to FinalGdiInit */
888 }
889
890
891 /***********************************************************************
892  *              CreateCursor (USER.406)
893  */
894 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
895                                 INT16 xHotSpot, INT16 yHotSpot,
896                                 INT16 nWidth, INT16 nHeight,
897                                 LPCVOID lpANDbits, LPCVOID lpXORbits)
898 {
899   CURSORICONINFO info;
900
901   info.ptHotSpot.x = xHotSpot;
902   info.ptHotSpot.y = yHotSpot;
903   info.nWidth = nWidth;
904   info.nHeight = nHeight;
905   info.nWidthBytes = 0;
906   info.bPlanes = 1;
907   info.bBitsPerPixel = 1;
908
909   return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
910 }
911
912
913 /*******************************************************************
914  *         InsertMenu    (USER.410)
915  */
916 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
917                             UINT16 id, SEGPTR data )
918 {
919     UINT pos32 = (UINT)pos;
920     if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
921     if (IS_MENU_STRING_ITEM(flags) && data)
922         return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
923     return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
924 }
925
926
927 /*******************************************************************
928  *         AppendMenu    (USER.411)
929  */
930 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
931 {
932     return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
933 }
934
935
936 /**********************************************************************
937  *         RemoveMenu   (USER.412)
938  */
939 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
940 {
941     return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
942 }
943
944
945 /**********************************************************************
946  *         DeleteMenu    (USER.413)
947  */
948 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
949 {
950     return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
951 }
952
953
954 /*******************************************************************
955  *         ModifyMenu    (USER.414)
956  */
957 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
958                             UINT16 id, SEGPTR data )
959 {
960     if (IS_MENU_STRING_ITEM(flags))
961         return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
962     return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
963 }
964
965
966 /**********************************************************************
967  *         CreatePopupMenu    (USER.415)
968  */
969 HMENU16 WINAPI CreatePopupMenu16(void)
970 {
971     return HMENU_16( CreatePopupMenu() );
972 }
973
974
975 /**********************************************************************
976  *         SetMenuItemBitmaps    (USER.418)
977  */
978 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
979                                     HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
980 {
981     return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
982                                HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
983 }
984
985
986 /*******************************************************************
987  *              InsertMenuItem   (USER.441)
988  *
989  * FIXME: untested
990  */
991 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
992                                 const MENUITEMINFO16 *mii )
993 {
994     MENUITEMINFOA miia;
995
996     miia.cbSize        = sizeof(miia);
997     miia.fMask         = mii->fMask;
998     miia.dwTypeData    = (LPSTR)mii->dwTypeData;
999     miia.fType         = mii->fType;
1000     miia.fState        = mii->fState;
1001     miia.wID           = mii->wID;
1002     miia.hSubMenu      = HMENU_32(mii->hSubMenu);
1003     miia.hbmpChecked   = HBITMAP_32(mii->hbmpChecked);
1004     miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
1005     miia.dwItemData    = mii->dwItemData;
1006     miia.cch           = mii->cch;
1007     if (IS_MENU_STRING_ITEM(miia.fType))
1008         miia.dwTypeData = MapSL(mii->dwTypeData);
1009     return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
1010 }
1011
1012
1013 /**********************************************************************
1014  *           DrawState    (USER.449)
1015  */
1016 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
1017                            WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
1018 {
1019     struct draw_state_info info;
1020     UINT opcode = flags & 0xf;
1021
1022     if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
1023     {
1024         /* make sure DrawStateA doesn't try to use ldata as a pointer */
1025         if (!wdata) wdata = strlen( MapSL(ldata) );
1026         if (!cx || !cy)
1027         {
1028             SIZE s;
1029             if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
1030             if (!cx) cx = s.cx;
1031             if (!cy) cy = s.cy;
1032         }
1033     }
1034     info.proc  = func;
1035     info.param = ldata;
1036     return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
1037                        (LPARAM)&info, wdata, x, y, cx, cy, flags );
1038 }
1039
1040
1041 /**********************************************************************
1042  *              CreateIconFromResourceEx (USER.450)
1043  *
1044  * FIXME: not sure about exact parameter types
1045  */
1046 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
1047                                           BOOL16 bIcon, DWORD dwVersion,
1048                                           INT16 width, INT16 height,
1049                                           UINT16 cFlag)
1050 {
1051   return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
1052                                            width, height, cFlag));
1053 }
1054
1055
1056 /***********************************************************************
1057  *              AdjustWindowRectEx (USER.454)
1058  */
1059 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style, BOOL16 menu, DWORD exStyle )
1060 {
1061     RECT rect32;
1062     BOOL ret;
1063
1064     rect32.left   = rect->left;
1065     rect32.top    = rect->top;
1066     rect32.right  = rect->right;
1067     rect32.bottom = rect->bottom;
1068     ret = AdjustWindowRectEx( &rect32, style, menu, exStyle );
1069     rect->left   = rect32.left;
1070     rect->top    = rect32.top;
1071     rect->right  = rect32.right;
1072     rect->bottom = rect32.bottom;
1073     return ret;
1074 }
1075
1076
1077 /***********************************************************************
1078  *              DestroyIcon (USER.457)
1079  */
1080 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
1081 {
1082   return DestroyIcon32(hIcon, 0);
1083 }
1084
1085 /***********************************************************************
1086  *              DestroyCursor (USER.458)
1087  */
1088 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
1089 {
1090   return DestroyIcon32(hCursor, 0);
1091 }
1092
1093 /*******************************************************************
1094  *                      DRAG_QueryUpdate16
1095  *
1096  * Recursively find a child that contains spDragInfo->pt point
1097  * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
1098  */
1099 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
1100 {
1101     BOOL bResult = 0;
1102     WPARAM wParam;
1103     POINT pt, old_pt;
1104     LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
1105     RECT tempRect;
1106     HWND child;
1107
1108     if (!IsWindowEnabled(hQueryWnd)) return FALSE;
1109
1110     old_pt.x = ptrDragInfo->pt.x;
1111     old_pt.y = ptrDragInfo->pt.y;
1112     pt = old_pt;
1113     ScreenToClient( hQueryWnd, &pt );
1114     child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
1115     if (!child) return FALSE;
1116
1117     if (child != hQueryWnd)
1118     {
1119         wParam = 0;
1120         if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
1121     }
1122     else
1123     {
1124         GetClientRect( hQueryWnd, &tempRect );
1125         wParam = !PtInRect( &tempRect, pt );
1126     }
1127
1128     ptrDragInfo->pt.x = pt.x;
1129     ptrDragInfo->pt.y = pt.y;
1130     ptrDragInfo->hScope = HWND_16(hQueryWnd);
1131
1132     bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
1133
1134     if (!bResult)
1135     {
1136         ptrDragInfo->pt.x = old_pt.x;
1137         ptrDragInfo->pt.y = old_pt.y;
1138     }
1139     return bResult;
1140 }
1141
1142
1143 /******************************************************************************
1144  *              DragObject (USER.464)
1145  */
1146 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
1147                            HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
1148 {
1149     MSG msg;
1150     LPDRAGINFO16 lpDragInfo;
1151     SEGPTR      spDragInfo;
1152     HCURSOR     hOldCursor=0, hBummer=0;
1153     HGLOBAL16   hDragInfo  = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
1154     HCURSOR     hCurrentCursor = 0;
1155     HWND16      hCurrentWnd = 0;
1156
1157     lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
1158     spDragInfo = K32WOWGlobalLock16(hDragInfo);
1159
1160     if( !lpDragInfo || !spDragInfo ) return 0L;
1161
1162     if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
1163     {
1164         GlobalFree16(hDragInfo);
1165         return 0L;
1166     }
1167
1168     if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
1169
1170     lpDragInfo->hWnd   = hWnd;
1171     lpDragInfo->hScope = 0;
1172     lpDragInfo->wFlags = wObj;
1173     lpDragInfo->hList  = szList; /* near pointer! */
1174     lpDragInfo->hOfStruct = hOfStruct;
1175     lpDragInfo->l = 0L;
1176
1177     SetCapture( HWND_32(hWnd) );
1178     ShowCursor( TRUE );
1179
1180     do
1181     {
1182         GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
1183
1184        *(lpDragInfo+1) = *lpDragInfo;
1185
1186         lpDragInfo->pt.x = msg.pt.x;
1187         lpDragInfo->pt.y = msg.pt.y;
1188
1189         /* update DRAGINFO struct */
1190         if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
1191             hCurrentCursor = HCURSOR_32(hCursor);
1192         else
1193         {
1194             hCurrentCursor = hBummer;
1195             lpDragInfo->hScope = 0;
1196         }
1197         if( hCurrentCursor )
1198             SetCursor(hCurrentCursor);
1199
1200         /* send WM_DRAGLOOP */
1201         SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
1202                                           (LPARAM) spDragInfo );
1203         /* send WM_DRAGSELECT or WM_DRAGMOVE */
1204         if( hCurrentWnd != lpDragInfo->hScope )
1205         {
1206             if( hCurrentWnd )
1207                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
1208                        (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
1209                                         HIWORD(spDragInfo)) );
1210             hCurrentWnd = lpDragInfo->hScope;
1211             if( hCurrentWnd )
1212                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
1213         }
1214         else
1215             if( hCurrentWnd )
1216                 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
1217
1218     } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
1219
1220     ReleaseCapture();
1221     ShowCursor( FALSE );
1222
1223     if( hCursor ) SetCursor(hOldCursor);
1224
1225     if( hCurrentCursor != hBummer )
1226         msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
1227                                    (WPARAM16)hWnd, (LPARAM)spDragInfo );
1228     else
1229         msg.lParam = 0;
1230     GlobalFree16(hDragInfo);
1231
1232     return (DWORD)(msg.lParam);
1233 }
1234
1235
1236 /***********************************************************************
1237  *              DrawFocusRect (USER.466)
1238  */
1239 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1240 {
1241     RECT rect32;
1242
1243     rect32.left   = rc->left;
1244     rect32.top    = rc->top;
1245     rect32.right  = rc->right;
1246     rect32.bottom = rc->bottom;
1247     DrawFocusRect( HDC_32(hdc), &rect32 );
1248 }
1249
1250
1251 /***********************************************************************
1252  *              ChangeDisplaySettings (USER.620)
1253  */
1254 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
1255 {
1256     return ChangeDisplaySettingsA( devmode, flags );
1257 }
1258
1259
1260 /***********************************************************************
1261  *              EnumDisplaySettings (USER.621)
1262  */
1263 BOOL16 WINAPI EnumDisplaySettings16( LPCSTR name, DWORD n, LPDEVMODEA devmode )
1264 {
1265     return EnumDisplaySettingsA( name, n, devmode );
1266 }
1267
1268 /**********************************************************************
1269  *          DrawFrameControl  (USER.656)
1270  */
1271 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
1272 {
1273     RECT rect32;
1274     BOOL ret;
1275
1276     rect32.left   = rc->left;
1277     rect32.top    = rc->top;
1278     rect32.right  = rc->right;
1279     rect32.bottom = rc->bottom;
1280     ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
1281     rc->left   = rect32.left;
1282     rc->top    = rect32.top;
1283     rc->right  = rect32.right;
1284     rc->bottom = rect32.bottom;
1285     return ret;
1286 }
1287
1288 /**********************************************************************
1289  *          DrawEdge   (USER.659)
1290  */
1291 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
1292 {
1293     RECT rect32;
1294     BOOL ret;
1295
1296     rect32.left   = rc->left;
1297     rect32.top    = rc->top;
1298     rect32.right  = rc->right;
1299     rect32.bottom = rc->bottom;
1300     ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
1301     rc->left   = rect32.left;
1302     rc->top    = rect32.top;
1303     rc->right  = rect32.right;
1304     rc->bottom = rect32.bottom;
1305     return ret;
1306 }
1307
1308 /**********************************************************************
1309  *              CheckMenuRadioItem (USER.666)
1310  */
1311 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
1312                                    UINT16 check, BOOL16 bypos)
1313 {
1314      return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );
1315 }