d3dx9: Add swizzle and writemask support to the shader assembler.
[wine] / dlls / user.exe16 / dialog.c
1 /*
2  * 16-bit dialog functions
3  *
4  * Copyright 1993, 1994, 1996, 2003 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wownt32.h"
29 #include "wine/winuser16.h"
30 #include "user_private.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(dialog);
34
35 /* Dialog control information */
36 typedef struct
37 {
38     DWORD      style;
39     INT16      x;
40     INT16      y;
41     INT16      cx;
42     INT16      cy;
43     UINT       id;
44     LPCSTR     className;
45     LPCSTR     windowName;
46     LPCVOID    data;
47 } DLG_CONTROL_INFO;
48
49   /* Dialog template */
50 typedef struct
51 {
52     DWORD      style;
53     UINT16     nbItems;
54     INT16      x;
55     INT16      y;
56     INT16      cx;
57     INT16      cy;
58     LPCSTR     menuName;
59     LPCSTR     className;
60     LPCSTR     caption;
61     INT16      pointSize;
62     LPCSTR     faceName;
63 } DLG_TEMPLATE;
64
65 #define DIALOG_CLASS_ATOM MAKEINTATOM(32770)
66
67 /***********************************************************************
68  *           DIALOG_EnableOwner
69  *
70  * Helper function for modal dialogs to enable again the
71  * owner of the dialog box.
72  */
73 static void DIALOG_EnableOwner( HWND hOwner )
74 {
75     /* Owner must be a top-level window */
76     if (hOwner)
77         hOwner = GetAncestor( hOwner, GA_ROOT );
78     if (!hOwner) return;
79     EnableWindow( hOwner, TRUE );
80 }
81
82
83 /***********************************************************************
84  *           DIALOG_DisableOwner
85  *
86  * Helper function for modal dialogs to disable the
87  * owner of the dialog box. Returns TRUE if owner was enabled.
88  */
89 static BOOL DIALOG_DisableOwner( HWND hOwner )
90 {
91     /* Owner must be a top-level window */
92     if (hOwner)
93         hOwner = GetAncestor( hOwner, GA_ROOT );
94     if (!hOwner) return FALSE;
95     if (IsWindowEnabled( hOwner ))
96     {
97         EnableWindow( hOwner, FALSE );
98         return TRUE;
99     }
100     else
101         return FALSE;
102 }
103
104
105 /***********************************************************************
106  *           DIALOG_GetControl16
107  *
108  * Return the class and text of the control pointed to by ptr,
109  * fill the header structure and return a pointer to the next control.
110  */
111 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
112 {
113     static char buffer[10];
114     int int_id;
115
116     info->x       = GET_WORD(p);  p += sizeof(WORD);
117     info->y       = GET_WORD(p);  p += sizeof(WORD);
118     info->cx      = GET_WORD(p);  p += sizeof(WORD);
119     info->cy      = GET_WORD(p);  p += sizeof(WORD);
120     info->id      = GET_WORD(p);  p += sizeof(WORD);
121     info->style   = GET_DWORD(p); p += sizeof(DWORD);
122
123     if (*p & 0x80)
124     {
125         switch((BYTE)*p)
126         {
127             case 0x80: strcpy( buffer, "BUTTON" ); break;
128             case 0x81: strcpy( buffer, "EDIT" ); break;
129             case 0x82: strcpy( buffer, "STATIC" ); break;
130             case 0x83: strcpy( buffer, "LISTBOX" ); break;
131             case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
132             case 0x85: strcpy( buffer, "COMBOBOX" ); break;
133             default:   buffer[0] = '\0'; break;
134         }
135         info->className = buffer;
136         p++;
137     }
138     else
139     {
140         info->className = p;
141         p += strlen(p) + 1;
142     }
143
144     int_id = ((BYTE)*p == 0xff);
145     if (int_id)
146     {
147         /* Integer id, not documented (?). Only works for SS_ICON controls */
148         info->windowName = MAKEINTRESOURCEA(GET_WORD(p+1));
149         p += 3;
150     }
151     else
152     {
153         info->windowName = p;
154         p += strlen(p) + 1;
155     }
156
157     if (*p) info->data = p + 1;
158     else info->data = NULL;
159
160     p += *p + 1;
161
162     TRACE("   %s %s %d, %d, %d, %d, %d, %08x, %p\n",
163           debugstr_a(info->className),  debugstr_a(info->windowName),
164           info->id, info->x, info->y, info->cx, info->cy,
165           info->style, info->data );
166
167     return p;
168 }
169
170
171 /***********************************************************************
172  *           DIALOG_CreateControls16
173  *
174  * Create the control windows for a dialog.
175  */
176 static BOOL DIALOG_CreateControls16( HWND hwnd, LPCSTR template,
177                                      const DLG_TEMPLATE *dlgTemplate, HINSTANCE16 hInst )
178 {
179     DIALOGINFO *dlgInfo = wow_handlers32.get_dialog_info( hwnd, TRUE );
180     DLG_CONTROL_INFO info;
181     HWND hwndCtrl, hwndDefButton = 0;
182     INT items = dlgTemplate->nbItems;
183
184     TRACE(" BEGIN\n" );
185     while (items--)
186     {
187         HINSTANCE16 instance = hInst;
188         SEGPTR segptr;
189
190         template = DIALOG_GetControl16( template, &info );
191         segptr = MapLS( info.data );
192         hwndCtrl = WIN_Handle32( CreateWindowEx16( WS_EX_NOPARENTNOTIFY,
193                                                    info.className, info.windowName,
194                                                    info.style | WS_CHILD,
195                                                    MulDiv(info.x, dlgInfo->xBaseUnit, 4),
196                                                    MulDiv(info.y, dlgInfo->yBaseUnit, 8),
197                                                    MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
198                                                    MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
199                                                    HWND_16(hwnd), (HMENU16)info.id,
200                                                    instance, (LPVOID)segptr ));
201         UnMapLS( segptr );
202
203         if (!hwndCtrl)
204         {
205             if (dlgTemplate->style & DS_NOFAILCREATE) continue;
206             return FALSE;
207         }
208
209             /* Send initialisation messages to the control */
210         if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
211                                              (WPARAM)dlgInfo->hUserFont, 0 );
212         if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
213         {
214               /* If there's already a default push-button, set it back */
215               /* to normal and use this one instead. */
216             if (hwndDefButton)
217                 SendMessageA( hwndDefButton, BM_SETSTYLE,
218                                 BS_PUSHBUTTON,FALSE );
219             hwndDefButton = hwndCtrl;
220             dlgInfo->idResult = GetWindowLongPtrA( hwndCtrl, GWLP_ID );
221         }
222     }
223     TRACE(" END\n" );
224     return TRUE;
225 }
226
227
228 /***********************************************************************
229  *           DIALOG_ParseTemplate16
230  *
231  * Fill a DLG_TEMPLATE structure from the dialog template, and return
232  * a pointer to the first control.
233  */
234 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
235 {
236     result->style   = GET_DWORD(p); p += sizeof(DWORD);
237     result->nbItems = (unsigned char) *p++;
238     result->x       = GET_WORD(p);  p += sizeof(WORD);
239     result->y       = GET_WORD(p);  p += sizeof(WORD);
240     result->cx      = GET_WORD(p);  p += sizeof(WORD);
241     result->cy      = GET_WORD(p);  p += sizeof(WORD);
242
243     TRACE("DIALOG %d, %d, %d, %d\n", result->x, result->y, result->cx, result->cy );
244     TRACE(" STYLE %08x\n", result->style );
245
246     /* Get the menu name */
247
248     switch( (BYTE)*p )
249     {
250     case 0:
251         result->menuName = 0;
252         p++;
253         break;
254     case 0xff:
255         result->menuName = MAKEINTRESOURCEA(GET_WORD( p + 1 ));
256         p += 3;
257         TRACE(" MENU %04x\n", LOWORD(result->menuName) );
258         break;
259     default:
260         result->menuName = p;
261         TRACE(" MENU '%s'\n", p );
262         p += strlen(p) + 1;
263         break;
264     }
265
266     /* Get the class name */
267
268     if (*p)
269     {
270         result->className = p;
271         TRACE(" CLASS '%s'\n", result->className );
272     }
273     else result->className = (LPCSTR)DIALOG_CLASS_ATOM;
274     p += strlen(p) + 1;
275
276     /* Get the window caption */
277
278     result->caption = p;
279     p += strlen(p) + 1;
280     TRACE(" CAPTION '%s'\n", result->caption );
281
282     /* Get the font name */
283
284     result->pointSize = 0;
285     result->faceName = NULL;
286
287     if (result->style & DS_SETFONT)
288     {
289         result->pointSize = GET_WORD(p);
290         p += sizeof(WORD);
291         result->faceName = p;
292         p += strlen(p) + 1;
293         TRACE(" FONT %d,'%s'\n", result->pointSize, result->faceName );
294     }
295     return p;
296 }
297
298
299 /***********************************************************************
300  *           DIALOG_CreateIndirect16
301  *
302  * Creates a dialog box window
303  *
304  * modal = TRUE if we are called from a modal dialog box.
305  * (it's more compatible to do it here, as under Windows the owner
306  * is never disabled if the dialog fails because of an invalid template)
307  */
308 static HWND DIALOG_CreateIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
309                                      HWND owner, DLGPROC16 dlgProc, LPARAM param,
310                                      BOOL modal )
311 {
312     HWND hwnd;
313     RECT rect;
314     POINT pos;
315     SIZE size;
316     DLG_TEMPLATE template;
317     DIALOGINFO * dlgInfo;
318     BOOL ownerEnabled = TRUE;
319     DWORD exStyle = 0;
320     DWORD units = GetDialogBaseUnits();
321     HMENU16 hMenu = 0;
322     HFONT hUserFont = 0;
323     UINT flags = 0;
324     UINT xBaseUnit = LOWORD(units);
325     UINT yBaseUnit = HIWORD(units);
326
327       /* Parse dialog template */
328
329     dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
330
331       /* Load menu */
332
333     if (template.menuName) hMenu = LoadMenu16( hInst, template.menuName );
334
335       /* Create custom font if needed */
336
337     if (template.style & DS_SETFONT)
338     {
339           /* We convert the size to pixels and then make it -ve.  This works
340            * for both +ve and -ve template.pointSize */
341         HDC dc;
342         int pixels;
343         dc = GetDC(0);
344         pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
345         hUserFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
346                                  FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
347                                  PROOF_QUALITY, FF_DONTCARE, template.faceName );
348         if (hUserFont)
349         {
350             SIZE charSize;
351             HFONT hOldFont = SelectObject( dc, hUserFont );
352             charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy );
353             if (charSize.cx)
354             {
355                 xBaseUnit = charSize.cx;
356                 yBaseUnit = charSize.cy;
357             }
358             SelectObject( dc, hOldFont );
359         }
360         ReleaseDC(0, dc);
361         TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
362     }
363
364     /* Create dialog main window */
365
366     rect.left = rect.top = 0;
367     rect.right = MulDiv(template.cx, xBaseUnit, 4);
368     rect.bottom =  MulDiv(template.cy, yBaseUnit, 8);
369     if (template.style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
370     AdjustWindowRectEx( &rect, template.style, (hMenu != 0), exStyle );
371     pos.x = rect.left;
372     pos.y = rect.top;
373     size.cx = rect.right - rect.left;
374     size.cy = rect.bottom - rect.top;
375
376     if (template.x == CW_USEDEFAULT16)
377     {
378         pos.x = pos.y = CW_USEDEFAULT16;
379     }
380     else
381     {
382         HMONITOR monitor = 0;
383         MONITORINFO mon_info;
384
385         mon_info.cbSize = sizeof(mon_info);
386         if (template.style & DS_CENTER)
387         {
388             monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY );
389             GetMonitorInfoW( monitor, &mon_info );
390             pos.x = (mon_info.rcWork.left + mon_info.rcWork.right - size.cx) / 2;
391             pos.y = (mon_info.rcWork.top + mon_info.rcWork.bottom - size.cy) / 2;
392         }
393         else if (template.style & DS_CENTERMOUSE)
394         {
395             GetCursorPos( &pos );
396             monitor = MonitorFromPoint( pos, MONITOR_DEFAULTTOPRIMARY );
397             GetMonitorInfoW( monitor, &mon_info );
398         }
399         else
400         {
401             pos.x += MulDiv(template.x, xBaseUnit, 4);
402             pos.y += MulDiv(template.y, yBaseUnit, 8);
403             if (!(template.style & (WS_CHILD|DS_ABSALIGN))) ClientToScreen( owner, &pos );
404         }
405         if ( !(template.style & WS_CHILD) )
406         {
407             INT dX, dY;
408
409             /* try to fit it into the desktop */
410
411             if (!monitor)
412             {
413                 SetRect( &rect, pos.x, pos.y, pos.x + size.cx, pos.y + size.cy );
414                 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
415                 GetMonitorInfoW( monitor, &mon_info );
416             }
417             if ((dX = pos.x + size.cx + GetSystemMetrics(SM_CXDLGFRAME) - mon_info.rcWork.right) > 0)
418                 pos.x -= dX;
419             if ((dY = pos.y + size.cy + GetSystemMetrics(SM_CYDLGFRAME) - mon_info.rcWork.bottom) > 0)
420                 pos.y -= dY;
421             if( pos.x < mon_info.rcWork.left ) pos.x = mon_info.rcWork.left;
422             if( pos.y < mon_info.rcWork.top ) pos.y = mon_info.rcWork.top;
423         }
424     }
425
426     if (modal)
427     {
428         ownerEnabled = DIALOG_DisableOwner( owner );
429         if (ownerEnabled) flags |= DF_OWNERENABLED;
430     }
431
432     hwnd = WIN_Handle32( CreateWindowEx16(exStyle, template.className,
433                                           template.caption, template.style & ~WS_VISIBLE,
434                                           pos.x, pos.y, size.cx, size.cy,
435                                           HWND_16(owner), hMenu, hInst, NULL ));
436     if (!hwnd)
437     {
438         if (hUserFont) DeleteObject( hUserFont );
439         if (hMenu) DestroyMenu16( hMenu );
440         if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
441         return 0;
442     }
443     dlgInfo = wow_handlers32.get_dialog_info( hwnd, TRUE );
444     dlgInfo->hwndFocus   = 0;
445     dlgInfo->hUserFont   = hUserFont;
446     dlgInfo->hMenu       = HMENU_32( hMenu );
447     dlgInfo->xBaseUnit   = xBaseUnit;
448     dlgInfo->yBaseUnit   = yBaseUnit;
449     dlgInfo->idResult    = 0;
450     dlgInfo->flags       = flags;
451
452     SetWindowLong16( HWND_16(hwnd), DWLP_DLGPROC, (LONG)dlgProc );
453
454     if (hUserFont)
455         SendMessageA( hwnd, WM_SETFONT, (WPARAM)hUserFont, 0 );
456
457     /* Create controls */
458
459     if (DIALOG_CreateControls16( hwnd, dlgTemplate, &template, hInst ))
460     {
461         HWND hwndPreInitFocus;
462
463         /* Send initialisation messages and set focus */
464
465         dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
466
467         hwndPreInitFocus = GetFocus();
468         if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
469         {
470             /* check where the focus is again,
471              * some controls status might have changed in WM_INITDIALOG */
472             dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
473             if( dlgInfo->hwndFocus )
474                 SetFocus( dlgInfo->hwndFocus );
475         }
476         else
477         {
478             /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
479                but the focus has not changed, set the focus where we expect it. */
480             if ((GetFocus() == hwndPreInitFocus) &&
481                 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
482             {
483                 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
484                 if( dlgInfo->hwndFocus )
485                     SetFocus( dlgInfo->hwndFocus );
486             }
487         }
488
489         if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
490         {
491             ShowWindow( hwnd, SW_SHOWNORMAL );  /* SW_SHOW doesn't always work */
492         }
493         return hwnd;
494     }
495     if( IsWindow(hwnd) ) DestroyWindow( hwnd );
496     if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
497     return 0;
498 }
499
500
501 /***********************************************************************
502  *              DialogBox (USER.87)
503  */
504 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
505                           HWND16 owner, DLGPROC16 dlgProc )
506 {
507     return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
508 }
509
510
511 /**************************************************************************
512  *              EndDialog   (USER.88)
513  */
514 BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
515 {
516     return EndDialog( WIN_Handle32(hwnd), retval );
517 }
518
519
520 /***********************************************************************
521  *              CreateDialog (USER.89)
522  */
523 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
524                               HWND16 owner, DLGPROC16 dlgProc )
525 {
526     return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
527 }
528
529
530 /**************************************************************************
531  *              GetDlgItem   (USER.91)
532  */
533 HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
534 {
535     return HWND_16( GetDlgItem( WIN_Handle32(hwndDlg), (UINT16) id ));
536 }
537
538
539 /**************************************************************************
540  *              SetDlgItemText   (USER.92)
541  */
542 void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
543 {
544     SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, lpString );
545 }
546
547
548 /**************************************************************************
549  *              GetDlgItemText   (USER.93)
550  */
551 INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
552 {
553     return SendDlgItemMessage16( hwnd, id, WM_GETTEXT, len, str );
554 }
555
556
557 /**************************************************************************
558  *              SetDlgItemInt   (USER.94)
559  */
560 void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
561 {
562     SetDlgItemInt( WIN_Handle32(hwnd), (UINT)(UINT16)id,
563              (UINT)(fSigned ? (INT16) value : value), fSigned );
564 }
565
566
567 /**************************************************************************
568  *              GetDlgItemInt   (USER.95)
569  */
570 UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated, BOOL16 fSigned )
571 {
572     UINT result;
573     BOOL ok;
574
575     if (translated) *translated = FALSE;
576     result = GetDlgItemInt( WIN_Handle32(hwnd), (UINT)(UINT16)id, &ok, fSigned );
577     if (!ok) return 0;
578     if (fSigned)
579     {
580         if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
581     }
582     else
583     {
584         if (result > 65535) return 0;
585     }
586     if (translated) *translated = TRUE;
587     return (UINT16)result;
588 }
589
590
591 /**************************************************************************
592  *              CheckRadioButton   (USER.96)
593  */
594 BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
595                                   UINT16 lastID, UINT16 checkID )
596 {
597     return CheckRadioButton( WIN_Handle32(hwndDlg), firstID, lastID, checkID );
598 }
599
600
601 /**************************************************************************
602  *              CheckDlgButton   (USER.97)
603  */
604 BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
605 {
606     SendDlgItemMessage16( hwnd, id, BM_SETCHECK16, check, 0 );
607     return TRUE;
608 }
609
610
611 /**************************************************************************
612  *              IsDlgButtonChecked   (USER.98)
613  */
614 UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
615 {
616     return (UINT16)SendDlgItemMessage16( hwnd, id, BM_GETCHECK16, 0, 0 );
617 }
618
619
620 /**************************************************************************
621  *              DlgDirSelect   (USER.99)
622  */
623 BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
624 {
625     return DlgDirSelectEx16( hwnd, str, 128, id );
626 }
627
628
629 /**************************************************************************
630  *              DlgDirList   (USER.100)
631  */
632 INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
633                            INT16 idStatic, UINT16 attrib )
634 {
635     /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
636      * be set automatically (this is different in Win32, and
637      * DIALOG_DlgDirList sends Win32 messages to the control,
638      * so do it here) */
639     if (attrib & DDL_DRIVES) attrib |= DDL_EXCLUSIVE;
640     return DlgDirListA( WIN_Handle32(hDlg), spec, idLBox, idStatic, attrib );
641 }
642
643
644 /**************************************************************************
645  *              SendDlgItemMessage   (USER.101)
646  */
647 LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
648                                      WPARAM16 wParam, LPARAM lParam )
649 {
650     HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
651     if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
652     else return 0;
653 }
654
655
656 /**************************************************************************
657  *              MapDialogRect   (USER.103)
658  */
659 void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
660 {
661     RECT rect32;
662     MapDialogRect( WIN_Handle32(hwnd), &rect32 );
663     rect->left   = rect32.left;
664     rect->right  = rect32.right;
665     rect->top    = rect32.top;
666     rect->bottom = rect32.bottom;
667 }
668
669
670 /**************************************************************************
671  *              DlgDirSelectComboBox   (USER.194)
672  */
673 BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
674 {
675     return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
676 }
677
678
679 /**************************************************************************
680  *              DlgDirListComboBox   (USER.195)
681  */
682 INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
683                                    INT16 idStatic, UINT16 attrib )
684 {
685     return DlgDirListComboBoxA( WIN_Handle32(hDlg), spec, idCBox, idStatic, attrib );
686 }
687
688
689 /***********************************************************************
690  *              DialogBoxIndirect (USER.218)
691  */
692 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
693                                   HWND16 owner, DLGPROC16 dlgProc )
694 {
695     return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
696 }
697
698
699 /***********************************************************************
700  *              CreateDialogIndirect (USER.219)
701  */
702 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
703                                       HWND16 owner, DLGPROC16 dlgProc )
704 {
705     return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
706 }
707
708
709 /**************************************************************************
710  *              GetNextDlgGroupItem   (USER.227)
711  */
712 HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
713                                      BOOL16 fPrevious )
714 {
715     return HWND_16( GetNextDlgGroupItem( WIN_Handle32(hwndDlg), WIN_Handle32(hwndCtrl), fPrevious ));
716 }
717
718
719 /**************************************************************************
720  *              GetNextDlgTabItem   (USER.228)
721  */
722 HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
723                                    BOOL16 fPrevious )
724 {
725     return HWND_16( GetNextDlgTabItem( WIN_Handle32(hwndDlg), WIN_Handle32(hwndCtrl), fPrevious ));
726 }
727
728
729 /***********************************************************************
730  *              DialogBoxParam (USER.239)
731  */
732 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, LPCSTR template,
733                                HWND16 owner16, DLGPROC16 dlgProc, LPARAM param )
734 {
735     HWND hwnd = 0;
736     HRSRC16 hRsrc;
737     HGLOBAL16 hmem;
738     LPCVOID data;
739     int ret = -1;
740
741     if (!(hRsrc = FindResource16( hInst, template, (LPSTR)RT_DIALOG ))) return 0;
742     if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
743     if ((data = LockResource16( hmem )))
744     {
745         HWND owner = WIN_Handle32(owner16);
746         hwnd = DIALOG_CreateIndirect16( hInst, data, owner, dlgProc, param, TRUE );
747         if (hwnd) ret = wow_handlers32.dialog_box_loop( hwnd, owner );
748         GlobalUnlock16( hmem );
749     }
750     FreeResource16( hmem );
751     return ret;
752 }
753
754
755 /***********************************************************************
756  *              DialogBoxIndirectParam (USER.240)
757  */
758 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
759                                        HWND16 owner16, DLGPROC16 dlgProc, LPARAM param )
760 {
761     HWND hwnd, owner = WIN_Handle32( owner16 );
762     LPCVOID ptr;
763
764     if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
765     hwnd = DIALOG_CreateIndirect16( hInst, ptr, owner, dlgProc, param, TRUE );
766     GlobalUnlock16( dlgTemplate );
767     if (hwnd) return wow_handlers32.dialog_box_loop( hwnd, owner );
768     return -1;
769 }
770
771
772 /***********************************************************************
773  *              CreateDialogParam (USER.241)
774  */
775 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
776                                    HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
777 {
778     HWND16 hwnd = 0;
779     HRSRC16 hRsrc;
780     HGLOBAL16 hmem;
781     LPCVOID data;
782
783     TRACE("%04x,%s,%04x,%p,%ld\n",
784           hInst, debugstr_a(dlgTemplate), owner, dlgProc, param );
785
786     if (!(hRsrc = FindResource16( hInst, dlgTemplate, (LPSTR)RT_DIALOG ))) return 0;
787     if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
788     if (!(data = LockResource16( hmem ))) hwnd = 0;
789     else hwnd = CreateDialogIndirectParam16( hInst, data, owner, dlgProc, param );
790     FreeResource16( hmem );
791     return hwnd;
792 }
793
794
795 /***********************************************************************
796  *              CreateDialogIndirectParam (USER.242)
797  */
798 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
799                                            HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
800 {
801     if (!dlgTemplate) return 0;
802     return HWND_16( DIALOG_CreateIndirect16( hInst, dlgTemplate, WIN_Handle32(owner),
803                                              dlgProc, param, FALSE ));
804 }
805
806
807 /**************************************************************************
808  *              DlgDirSelectEx   (USER.422)
809  */
810 BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
811 {
812     return DlgDirSelectExA( WIN_Handle32(hwnd), str, len, id );
813 }
814
815
816 /**************************************************************************
817  *              DlgDirSelectComboBoxEx   (USER.423)
818  */
819 BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
820                                         INT16 id )
821 {
822     return DlgDirSelectComboBoxExA( WIN_Handle32(hwnd), str, len, id );
823 }