- Localization to Portuguese of Brazil
[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 <stdlib.h>
22 #include "wine/winuser16.h"
23 #include "winbase.h"
24 #include "wownt32.h"
25 #include "task.h"
26 #include "user.h"
27 #include "win.h"
28 #include "winproc.h"
29 #include "cursoricon.h"
30
31 /* handle to handle 16 conversions */
32 #define HANDLE_16(h32)          (LOWORD(h32))
33
34 /* handle16 to handle conversions */
35 #define HANDLE_32(h16)          ((HANDLE)(ULONG_PTR)(h16))
36 #define HINSTANCE_32(h16)       ((HINSTANCE)(ULONG_PTR)(h16))
37
38 #define IS_MENU_STRING_ITEM(flags) \
39     (((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)) == MF_STRING)
40
41 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
42
43
44 struct gray_string_info
45 {
46     GRAYSTRINGPROC16 proc;
47     LPARAM           param;
48     char             str[1];
49 };
50
51 /* callback for 16-bit gray string proc with opaque pointer */
52 static BOOL CALLBACK gray_string_callback( HDC hdc, LPARAM param, INT len )
53 {
54     const struct gray_string_info *info = (struct gray_string_info *)param;
55     WORD args[4];
56     DWORD ret;
57
58     args[3] = HDC_16(hdc);
59     args[2] = HIWORD(info->param);
60     args[1] = LOWORD(info->param);
61     args[0] = len;
62     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
63     return LOWORD(ret);
64 }
65
66 /* callback for 16-bit gray string proc with string pointer */
67 static BOOL CALLBACK gray_string_callback_ptr( HDC hdc, LPARAM param, INT len )
68 {
69     const struct gray_string_info *info;
70     char *str = (char *)param;
71
72     info = (struct gray_string_info *)(str - offsetof( struct gray_string_info, str ));
73     return gray_string_callback( hdc, (LPARAM)info, len );
74 }
75
76 struct draw_state_info
77 {
78     DRAWSTATEPROC16 proc;
79     LPARAM          param;
80 };
81
82 /* callback for 16-bit DrawState functions */
83 static BOOL CALLBACK draw_state_callback( HDC hdc, LPARAM lparam, WPARAM wparam, int cx, int cy )
84 {
85     const struct draw_state_info *info = (struct draw_state_info *)lparam;
86     WORD args[6];
87     DWORD ret;
88
89     args[5] = HDC_16(hdc);
90     args[4] = HIWORD(info->param);
91     args[3] = LOWORD(info->param);
92     args[2] = wparam;
93     args[1] = cx;
94     args[0] = cy;
95     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
96     return LOWORD(ret);
97 }
98
99 /***********************************************************************
100  *              SetCursor (USER.69)
101  */
102 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
103 {
104   return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
105 }
106
107 /***********************************************************************
108  *              ShowCursor (USER.71)
109  */
110 INT16 WINAPI ShowCursor16(BOOL16 bShow)
111 {
112   return ShowCursor(bShow);
113 }
114
115 /***********************************************************************
116  *              DrawIcon (USER.84)
117  */
118 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
119 {
120   return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
121 }
122
123
124 /***********************************************************************
125  *           DrawText    (USER.85)
126  */
127 INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT16 flags )
128 {
129     INT16 ret;
130
131     if (rect)
132     {
133         RECT rect32;
134         CONV_RECT16TO32( rect, &rect32 );
135         ret = DrawTextA( HDC_32(hdc), str, count, &rect32, flags );
136         CONV_RECT32TO16( &rect32, rect );
137     }
138     else ret = DrawTextA( HDC_32(hdc), str, count, NULL, flags);
139     return ret;
140 }
141
142
143 /***********************************************************************
144  *              IconSize (USER.86)
145  *
146  * See "Undocumented Windows". Used by W2.0 paint.exe.
147  */
148 DWORD WINAPI IconSize16(void)
149 {
150   return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
151 }
152
153
154 /**********************************************************************
155  *         CreateMenu    (USER.151)
156  */
157 HMENU16 WINAPI CreateMenu16(void)
158 {
159     return HMENU_16( CreateMenu() );
160 }
161
162
163 /**********************************************************************
164  *         DestroyMenu    (USER.152)
165  */
166 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
167 {
168     return DestroyMenu( HMENU_32(hMenu) );
169 }
170
171
172 /*******************************************************************
173  *         ChangeMenu    (USER.153)
174  */
175 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
176                             UINT16 id, UINT16 flags )
177 {
178     if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND, id, data );
179
180     /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
181     /* for MF_DELETE. We should check the parameters for all others */
182     /* MF_* actions also (anybody got a doc on ChangeMenu?). */
183
184     if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
185     if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE, id, data );
186     if (flags & MF_REMOVE) return RemoveMenu16(hMenu, flags & MF_BYPOSITION ? pos : id,
187                                                flags & ~MF_REMOVE );
188     /* Default: MF_INSERT */
189     return InsertMenu16( hMenu, pos, flags, id, data );
190 }
191
192
193 /*******************************************************************
194  *         CheckMenuItem    (USER.154)
195  */
196 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
197 {
198     return CheckMenuItem( HMENU_32(hMenu), id, flags );
199 }
200
201
202 /**********************************************************************
203  *         EnableMenuItem    (USER.155)
204  */
205 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
206 {
207     return EnableMenuItem( HMENU_32(hMenu), wItemID, wFlags );
208 }
209
210
211 /**********************************************************************
212  *         GetSubMenu    (USER.159)
213  */
214 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
215 {
216     return HMENU_16( GetSubMenu( HMENU_32(hMenu), nPos ) );
217 }
218
219
220 /*******************************************************************
221  *         GetMenuString    (USER.161)
222  */
223 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
224                               LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
225 {
226     return GetMenuStringA( HMENU_32(hMenu), wItemID, str, nMaxSiz, wFlags );
227 }
228
229
230 /**********************************************************************
231  *              WinHelp (USER.171)
232  */
233 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
234                          DWORD dwData )
235 {
236     BOOL ret;
237     DWORD mutex_count;
238
239     /* We might call WinExec() */
240     ReleaseThunkLock(&mutex_count);
241
242     ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
243
244     RestoreThunkLock(mutex_count);
245     return ret;
246 }
247
248
249 /***********************************************************************
250  *              LoadCursor (USER.173)
251  */
252 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
253 {
254   return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
255 }
256
257
258 /***********************************************************************
259  *              LoadIcon (USER.174)
260  */
261 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
262 {
263   return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
264 }
265
266 /**********************************************************************
267  *              LoadBitmap (USER.175)
268  */
269 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
270 {
271   return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
272 }
273
274
275 /***********************************************************************
276  *           GrayString   (USER.185)
277  */
278 BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
279                             LPARAM lParam, INT16 cch, INT16 x, INT16 y,
280                             INT16 cx, INT16 cy )
281 {
282     BOOL ret;
283
284     if (!gsprc) return GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), NULL,
285                                     (LPARAM)MapSL(lParam), cch, x, y, cx, cy );
286
287     if (cch == -1 || (cch && cx && cy))
288     {
289         /* lParam can be treated as an opaque pointer */
290         struct gray_string_info info;
291
292         info.proc  = gsprc;
293         info.param = lParam;
294         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback,
295                            (LPARAM)&info, cch, x, y, cx, cy );
296     }
297     else  /* here we need some string conversions */
298     {
299         char *str16 = MapSL(lParam);
300         struct gray_string_info *info;
301
302         if (!cch) cch = strlen(str16);
303         if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) + cch ))) return FALSE;
304         info->proc  = gsprc;
305         info->param = lParam;
306         memcpy( info->str, str16, cch );
307         ret = GrayStringA( HDC_32(hdc), HBRUSH_32(hbr), gray_string_callback_ptr,
308                            (LPARAM)info->str, cch, x, y, cx, cy );
309         HeapFree( GetProcessHeap(), 0, info );
310     }
311     return ret;
312 }
313
314
315 /***********************************************************************
316  *           TabbedTextOut    (USER.196)
317  */
318 LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
319                              INT16 count, INT16 nb_tabs, const INT16 *tabs16, INT16 tab_org )
320 {
321     LONG ret;
322     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
323     if (!tabs) return 0;
324     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
325     ret = TabbedTextOutA( HDC_32(hdc), x, y, lpstr, count, nb_tabs, tabs, tab_org );
326     HeapFree( GetProcessHeap(), 0, tabs );
327     return ret;
328 }
329
330
331 /***********************************************************************
332  *           GetTabbedTextExtent    (USER.197)
333  */
334 DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count,
335                                     INT16 nb_tabs, const INT16 *tabs16 )
336 {
337     LONG ret;
338     INT i, *tabs = HeapAlloc( GetProcessHeap(), 0, nb_tabs * sizeof(tabs) );
339     if (!tabs) return 0;
340     for (i = 0; i < nb_tabs; i++) tabs[i] = tabs16[i];
341     ret = GetTabbedTextExtentA( HDC_32(hdc), lpstr, count, nb_tabs, tabs );
342     HeapFree( GetProcessHeap(), 0, tabs );
343     return ret;
344 }
345
346
347 /*************************************************************************
348  *              ScrollDC (USER.221)
349  */
350 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
351                           const RECT16 *cliprc, HRGN16 hrgnUpdate,
352                           LPRECT16 rcUpdate )
353 {
354     RECT rect32, clipRect32, rcUpdate32;
355     BOOL16 ret;
356
357     if (rect) CONV_RECT16TO32( rect, &rect32 );
358     if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
359     ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
360                     cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
361                     &rcUpdate32 );
362     if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
363     return ret;
364 }
365
366 /***********************************************************************
367  *              GetCursor (USER.247)
368  */
369 HCURSOR16 WINAPI GetCursor16(void)
370 {
371   return HCURSOR_16(GetCursor());
372 }
373
374
375 /**********************************************************************
376  *         GetMenuState    (USER.250)
377  */
378 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
379 {
380     return GetMenuState( HMENU_32(hMenu), wItemID, wFlags );
381 }
382
383
384 /**********************************************************************
385  *         GetMenuItemCount    (USER.263)
386  */
387 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
388 {
389     return GetMenuItemCount( HMENU_32(hMenu) );
390 }
391
392
393 /**********************************************************************
394  *         GetMenuItemID    (USER.264)
395  */
396 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
397 {
398     return GetMenuItemID( HMENU_32(hMenu), nPos );
399 }
400
401
402 /***********************************************************************
403  *              GlobalAddAtom (USER.268)
404  */
405 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
406 {
407   return GlobalAddAtomA(lpString);
408 }
409
410 /***********************************************************************
411  *              GlobalDeleteAtom (USER.269)
412  */
413 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
414 {
415   return GlobalDeleteAtom(nAtom);
416 }
417
418 /***********************************************************************
419  *              GlobalFindAtom (USER.270)
420  */
421 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
422 {
423   return GlobalFindAtomA(lpString);
424 }
425
426 /***********************************************************************
427  *              GlobalGetAtomName (USER.271)
428  */
429 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
430 {
431   return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
432 }
433
434
435 /***********************************************************************
436  *              GetSysColorBrush (USER.281)
437  */
438 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
439 {
440     return HBRUSH_16( GetSysColorBrush(index) );
441 }
442
443
444 /***********************************************************************
445  *              SelectPalette (USER.282)
446  */
447 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
448 {
449     return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
450 }
451
452 /***********************************************************************
453  *              RealizePalette (USER.283)
454  */
455 UINT16 WINAPI RealizePalette16( HDC16 hdc )
456 {
457     return UserRealizePalette( HDC_32(hdc) );
458 }
459
460
461 /***********************************************************************
462  *              SignalProc (USER.314)
463  */
464 void WINAPI SignalProc16( HANDLE16 hModule, UINT16 code,
465                           UINT16 uExitFn, HINSTANCE16 hInstance, HQUEUE16 hQueue )
466 {
467     if (code == USIG16_DLL_UNLOAD)
468     {
469         /* HOOK_FreeModuleHooks( hModule ); */
470         CLASS_FreeModuleClasses( hModule );
471         CURSORICON_FreeModuleIcons( hModule );
472     }
473 }
474
475
476 /**********************************************************************
477  *              IsMenu    (USER.358)
478  */
479 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
480 {
481     return IsMenu( HMENU_32(hmenu) );
482 }
483
484
485 /**********************************************************************
486  *         SetMenuContextHelpId    (USER.384)
487  */
488 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
489 {
490     return SetMenuContextHelpId( HMENU_32(hMenu), dwContextHelpID );
491 }
492
493
494 /**********************************************************************
495  *         GetMenuContextHelpId    (USER.385)
496  */
497 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
498 {
499     return GetMenuContextHelpId( HMENU_32(hMenu) );
500 }
501
502
503 /***********************************************************************
504  *              LoadImage (USER.389)
505  *
506  */
507 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
508                             INT16 desiredx, INT16 desiredy, UINT16 loadflags)
509 {
510   return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
511                               desiredy, loadflags));
512 }
513
514 /******************************************************************************
515  *              CopyImage (USER.390) Creates new image and copies attributes to it
516  *
517  */
518 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
519                            INT16 desiredy, UINT16 flags)
520 {
521   return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
522                             (INT)desiredy, (UINT)flags));
523 }
524
525 /**********************************************************************
526  *              DrawIconEx (USER.394)
527  */
528 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
529                            INT16 cxWidth, INT16 cyWidth, UINT16 istep,
530                            HBRUSH16 hbr, UINT16 flags)
531 {
532   return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
533                     istep, HBRUSH_32(hbr), flags);
534 }
535
536 /**********************************************************************
537  *              GetIconInfo (USER.395)
538  */
539 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
540 {
541   ICONINFO ii32;
542   BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
543
544   iconinfo->fIcon = ii32.fIcon;
545   iconinfo->xHotspot = ii32.xHotspot;
546   iconinfo->yHotspot = ii32.yHotspot;
547   iconinfo->hbmMask  = HBITMAP_16(ii32.hbmMask);
548   iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
549   return ret;
550 }
551
552 /***********************************************************************
553  *              CreateCursor (USER.406)
554  */
555 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
556                                 INT16 xHotSpot, INT16 yHotSpot,
557                                 INT16 nWidth, INT16 nHeight,
558                                 LPCVOID lpANDbits, LPCVOID lpXORbits)
559 {
560   CURSORICONINFO info;
561
562   info.ptHotSpot.x = xHotSpot;
563   info.ptHotSpot.y = yHotSpot;
564   info.nWidth = nWidth;
565   info.nHeight = nHeight;
566   info.nWidthBytes = 0;
567   info.bPlanes = 1;
568   info.bBitsPerPixel = 1;
569
570   return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
571 }
572
573
574 /*******************************************************************
575  *         InsertMenu    (USER.410)
576  */
577 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
578                             UINT16 id, SEGPTR data )
579 {
580     UINT pos32 = (UINT)pos;
581     if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
582     if (IS_MENU_STRING_ITEM(flags) && data)
583         return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, MapSL(data) );
584     return InsertMenuA( HMENU_32(hMenu), pos32, flags, id, (LPSTR)data );
585 }
586
587
588 /*******************************************************************
589  *         AppendMenu    (USER.411)
590  */
591 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
592 {
593     return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
594 }
595
596
597 /**********************************************************************
598  *         RemoveMenu   (USER.412)
599  */
600 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
601 {
602     return RemoveMenu( HMENU_32(hMenu), nPos, wFlags );
603 }
604
605
606 /**********************************************************************
607  *         DeleteMenu    (USER.413)
608  */
609 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
610 {
611     return DeleteMenu( HMENU_32(hMenu), nPos, wFlags );
612 }
613
614
615 /*******************************************************************
616  *         ModifyMenu    (USER.414)
617  */
618 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
619                             UINT16 id, SEGPTR data )
620 {
621     if (IS_MENU_STRING_ITEM(flags))
622         return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, MapSL(data) );
623     return ModifyMenuA( HMENU_32(hMenu), pos, flags, id, (LPSTR)data );
624 }
625
626
627 /**********************************************************************
628  *         CreatePopupMenu    (USER.415)
629  */
630 HMENU16 WINAPI CreatePopupMenu16(void)
631 {
632     return HMENU_16( CreatePopupMenu() );
633 }
634
635
636 /**********************************************************************
637  *         SetMenuItemBitmaps    (USER.418)
638  */
639 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
640                                     HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
641 {
642     return SetMenuItemBitmaps( HMENU_32(hMenu), nPos, wFlags,
643                                HBITMAP_32(hNewUnCheck), HBITMAP_32(hNewCheck) );
644 }
645
646
647 /*******************************************************************
648  *              InsertMenuItem   (USER.441)
649  *
650  * FIXME: untested
651  */
652 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
653                                 const MENUITEMINFO16 *mii )
654 {
655     MENUITEMINFOA miia;
656
657     miia.cbSize        = sizeof(miia);
658     miia.fMask         = mii->fMask;
659     miia.dwTypeData    = (LPSTR)mii->dwTypeData;
660     miia.fType         = mii->fType;
661     miia.fState        = mii->fState;
662     miia.wID           = mii->wID;
663     miia.hSubMenu      = HMENU_32(mii->hSubMenu);
664     miia.hbmpChecked   = HBITMAP_32(mii->hbmpChecked);
665     miia.hbmpUnchecked = HBITMAP_32(mii->hbmpUnchecked);
666     miia.dwItemData    = mii->dwItemData;
667     miia.cch           = mii->cch;
668     if (IS_MENU_STRING_ITEM(miia.fType))
669         miia.dwTypeData = MapSL(mii->dwTypeData);
670     return InsertMenuItemA( HMENU_32(hmenu), pos, byposition, &miia );
671 }
672
673
674 /**********************************************************************
675  *           DrawState    (USER.449)
676  */
677 BOOL16 WINAPI DrawState16( HDC16 hdc, HBRUSH16 hbr, DRAWSTATEPROC16 func, LPARAM ldata,
678                            WPARAM16 wdata, INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
679 {
680     struct draw_state_info info;
681     UINT opcode = flags & 0xf;
682
683     if (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)
684     {
685         /* make sure DrawStateA doesn't try to use ldata as a pointer */
686         if (!wdata) wdata = strlen( MapSL(ldata) );
687         if (!cx || !cy)
688         {
689             SIZE s;
690             if (!GetTextExtentPoint32A( HDC_32(hdc), MapSL(ldata), wdata, &s )) return FALSE;
691             if (!cx) cx = s.cx;
692             if (!cy) cy = s.cy;
693         }
694     }
695     info.proc  = func;
696     info.param = ldata;
697     return DrawStateA( HDC_32(hdc), HBRUSH_32(hbr), draw_state_callback,
698                        (LPARAM)&info, wdata, x, y, cx, cy, flags );
699 }
700
701
702 /**********************************************************************
703  *              CreateIconFromResourceEx (USER.450)
704  *
705  * FIXME: not sure about exact parameter types
706  */
707 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
708                                           BOOL16 bIcon, DWORD dwVersion,
709                                           INT16 width, INT16 height,
710                                           UINT16 cFlag)
711 {
712   return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
713                                            width, height, cFlag));
714 }
715
716 /***********************************************************************
717  *              DestroyIcon (USER.457)
718  */
719 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
720 {
721   return DestroyIcon32(hIcon, 0);
722 }
723
724 /***********************************************************************
725  *              DestroyCursor (USER.458)
726  */
727 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
728 {
729   return DestroyIcon32(hCursor, 0);
730 }
731
732 /*******************************************************************
733  *                      DRAG_QueryUpdate16
734  *
735  * Recursively find a child that contains spDragInfo->pt point
736  * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
737  */
738 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
739 {
740     BOOL bResult = 0;
741     WPARAM wParam;
742     POINT pt, old_pt;
743     LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
744     RECT tempRect;
745     HWND child;
746
747     if (!IsWindowEnabled(hQueryWnd)) return FALSE;
748
749     old_pt.x = ptrDragInfo->pt.x;
750     old_pt.y = ptrDragInfo->pt.y;
751     pt = old_pt;
752     ScreenToClient( hQueryWnd, &pt );
753     child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
754     if (!child) return FALSE;
755
756     if (child != hQueryWnd)
757     {
758         wParam = 0;
759         if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
760     }
761     else
762     {
763         GetClientRect( hQueryWnd, &tempRect );
764         wParam = !PtInRect( &tempRect, pt );
765     }
766
767     ptrDragInfo->pt.x = pt.x;
768     ptrDragInfo->pt.y = pt.y;
769     ptrDragInfo->hScope = HWND_16(hQueryWnd);
770
771     bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
772
773     if (!bResult)
774     {
775         ptrDragInfo->pt.x = old_pt.x;
776         ptrDragInfo->pt.y = old_pt.y;
777     }
778     return bResult;
779 }
780
781
782 /******************************************************************************
783  *              DragObject (USER.464)
784  */
785 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
786                            HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
787 {
788     MSG msg;
789     LPDRAGINFO16 lpDragInfo;
790     SEGPTR      spDragInfo;
791     HCURSOR     hOldCursor=0, hBummer=0;
792     HGLOBAL16   hDragInfo  = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
793     HCURSOR     hCurrentCursor = 0;
794     HWND16      hCurrentWnd = 0;
795
796     lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
797     spDragInfo = K32WOWGlobalLock16(hDragInfo);
798
799     if( !lpDragInfo || !spDragInfo ) return 0L;
800
801     if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
802     {
803         GlobalFree16(hDragInfo);
804         return 0L;
805     }
806
807     if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
808
809     lpDragInfo->hWnd   = hWnd;
810     lpDragInfo->hScope = 0;
811     lpDragInfo->wFlags = wObj;
812     lpDragInfo->hList  = szList; /* near pointer! */
813     lpDragInfo->hOfStruct = hOfStruct;
814     lpDragInfo->l = 0L;
815
816     SetCapture( HWND_32(hWnd) );
817     ShowCursor( TRUE );
818
819     do
820     {
821         GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
822
823        *(lpDragInfo+1) = *lpDragInfo;
824
825         lpDragInfo->pt.x = msg.pt.x;
826         lpDragInfo->pt.y = msg.pt.y;
827
828         /* update DRAGINFO struct */
829         if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
830             hCurrentCursor = HCURSOR_32(hCursor);
831         else
832         {
833             hCurrentCursor = hBummer;
834             lpDragInfo->hScope = 0;
835         }
836         if( hCurrentCursor )
837             SetCursor(hCurrentCursor);
838
839         /* send WM_DRAGLOOP */
840         SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
841                                           (LPARAM) spDragInfo );
842         /* send WM_DRAGSELECT or WM_DRAGMOVE */
843         if( hCurrentWnd != lpDragInfo->hScope )
844         {
845             if( hCurrentWnd )
846                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
847                        (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
848                                         HIWORD(spDragInfo)) );
849             hCurrentWnd = lpDragInfo->hScope;
850             if( hCurrentWnd )
851                 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
852         }
853         else
854             if( hCurrentWnd )
855                 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
856
857     } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
858
859     ReleaseCapture();
860     ShowCursor( FALSE );
861
862     if( hCursor ) SetCursor(hOldCursor);
863
864     if( hCurrentCursor != hBummer )
865         msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
866                                    (WPARAM16)hWnd, (LPARAM)spDragInfo );
867     else
868         msg.lParam = 0;
869     GlobalFree16(hDragInfo);
870
871     return (DWORD)(msg.lParam);
872 }
873
874
875 /**********************************************************************
876  *          DrawFrameControl  (USER.656)
877  */
878 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
879 {
880     RECT rect32;
881     BOOL ret;
882
883     CONV_RECT16TO32( rc, &rect32 );
884     ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
885     CONV_RECT32TO16( &rect32, rc );
886     return ret;
887 }
888
889 /**********************************************************************
890  *          DrawEdge   (USER.659)
891  */
892 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
893 {
894     RECT rect32;
895     BOOL ret;
896
897     CONV_RECT16TO32( rc, &rect32 );
898     ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
899     CONV_RECT32TO16( &rect32, rc );
900     return ret;
901 }
902
903 /**********************************************************************
904  *              CheckMenuRadioItem (USER.666)
905  */
906 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu, UINT16 first, UINT16 last,
907                                    UINT16 check, BOOL16 bypos)
908 {
909      return CheckMenuRadioItem( HMENU_32(hMenu), first, last, check, bypos );
910 }