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