4 * Copyright 1993, 1994, 1996 Alexandre Julliard
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.
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.
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
22 #include "wine/port.h"
37 #include "wine/winuser16.h"
38 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
48 /* Dialog control information */
85 /* Radio button group */
94 /*********************************************************************
95 * dialog class descriptor
97 const struct builtin_class_descr DIALOG_builtin_class
=
99 DIALOG_CLASS_ATOMA
, /* name */
100 CS_GLOBALCLASS
| CS_SAVEBITS
| CS_DBLCLKS
, /* style */
101 DefDlgProcA
, /* procA */
102 DefDlgProcW
, /* procW */
103 DLGWINDOWEXTRA
, /* extra */
104 IDC_ARROW
, /* cursor */
109 /***********************************************************************
112 * Helper function for modal dialogs to enable again the
113 * owner of the dialog box.
115 void DIALOG_EnableOwner( HWND hOwner
)
117 /* Owner must be a top-level window */
119 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
121 EnableWindow( hOwner
, TRUE
);
125 /***********************************************************************
126 * DIALOG_DisableOwner
128 * Helper function for modal dialogs to disable the
129 * owner of the dialog box. Returns TRUE if owner was enabled.
131 BOOL
DIALOG_DisableOwner( HWND hOwner
)
133 /* Owner must be a top-level window */
135 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
136 if (!hOwner
) return FALSE
;
137 if (IsWindowEnabled( hOwner
))
139 EnableWindow( hOwner
, FALSE
);
146 /***********************************************************************
149 * Despite most of MSDN insisting that the horizontal base unit is
150 * tmAveCharWidth it isn't. Knowledge base article Q145994
151 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
152 * says that we should take the average of the 52 English upper and lower
155 BOOL
DIALOG_GetCharSize( HDC hDC
, HFONT hFont
, SIZE
* pSize
)
158 const char *alphabet
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
162 if(!hDC
) return FALSE
;
164 if(hFont
) hFontPrev
= SelectObject(hDC
, hFont
);
165 if(!GetTextMetricsA(hDC
, &tm
)) return FALSE
;
166 if(!GetTextExtentPointA(hDC
, alphabet
, 52, &sz
)) return FALSE
;
168 pSize
->cy
= tm
.tmHeight
;
169 pSize
->cx
= (sz
.cx
/ 26 + 1) / 2;
171 if (hFontPrev
) SelectObject(hDC
, hFontPrev
);
173 TRACE("dlg base units: %ld x %ld\n", pSize
->cx
, pSize
->cy
);
178 /***********************************************************************
179 * DIALOG_GetControl32
181 * Return the class and text of the control pointed to by ptr,
182 * fill the header structure and return a pointer to the next control.
184 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
189 info
->helpId
= GET_DWORD(p
); p
+= 2;
190 info
->exStyle
= GET_DWORD(p
); p
+= 2;
191 info
->style
= GET_DWORD(p
); p
+= 2;
196 info
->style
= GET_DWORD(p
); p
+= 2;
197 info
->exStyle
= GET_DWORD(p
); p
+= 2;
199 info
->x
= GET_WORD(p
); p
++;
200 info
->y
= GET_WORD(p
); p
++;
201 info
->cx
= GET_WORD(p
); p
++;
202 info
->cy
= GET_WORD(p
); p
++;
206 /* id is a DWORD for DIALOGEX */
207 info
->id
= GET_DWORD(p
);
212 info
->id
= GET_WORD(p
);
216 if (GET_WORD(p
) == 0xffff)
218 static const WCHAR class_names
[6][10] =
220 { 'B','u','t','t','o','n', }, /* 0x80 */
221 { 'E','d','i','t', }, /* 0x81 */
222 { 'S','t','a','t','i','c', }, /* 0x82 */
223 { 'L','i','s','t','B','o','x', }, /* 0x83 */
224 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
225 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
227 WORD id
= GET_WORD(p
+1);
228 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
229 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
231 info
->className
= class_names
[id
];
234 info
->className
= NULL
;
235 ERR("Unknown built-in class id %04x\n", id
);
241 info
->className
= (LPCWSTR
)p
;
242 p
+= strlenW( info
->className
) + 1;
245 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
247 info
->windowName
= (LPCWSTR
)(UINT
)GET_WORD(p
+ 1);
252 info
->windowName
= (LPCWSTR
)p
;
253 p
+= strlenW( info
->windowName
) + 1;
256 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
257 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
258 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
259 info
->style
, info
->exStyle
, info
->helpId
);
263 if (TRACE_ON(dialog
))
265 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
268 for (i
= 0; i
< count
; i
++) TRACE( "%04x,", GET_WORD(p
+i
+1) );
273 p
+= GET_WORD(p
) / sizeof(WORD
);
275 else info
->data
= NULL
;
278 /* Next control is on dword boundary */
279 return (const WORD
*)((((int)p
) + 3) & ~3);
283 /***********************************************************************
284 * DIALOG_CreateControls32
286 * Create the control windows for a dialog.
288 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
289 HINSTANCE hInst
, BOOL unicode
)
291 DIALOGINFO
*dlgInfo
= DIALOG_get_info( hwnd
);
292 DLG_CONTROL_INFO info
;
293 HWND hwndCtrl
, hwndDefButton
= 0;
294 INT items
= dlgTemplate
->nbItems
;
299 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
300 dlgTemplate
->dialogEx
);
302 if (info
.style
& WS_BORDER
)
304 info
.style
&= ~WS_BORDER
;
305 info
.exStyle
|= WS_EX_CLIENTEDGE
;
309 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
310 info
.className
, info
.windowName
,
311 info
.style
| WS_CHILD
,
312 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
313 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
314 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
315 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
316 hwnd
, (HMENU
)info
.id
,
317 hInst
, (LPVOID
)info
.data
);
321 LPSTR
class = (LPSTR
)info
.className
;
322 LPSTR caption
= (LPSTR
)info
.windowName
;
326 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
327 class = HeapAlloc( GetProcessHeap(), 0, len
);
328 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
332 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
333 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
334 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
336 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
337 class, caption
, info
.style
| WS_CHILD
,
338 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
339 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
340 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
341 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
342 hwnd
, (HMENU
)info
.id
,
343 hInst
, (LPVOID
)info
.data
);
344 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
345 if (HIWORD(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
349 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
353 /* Send initialisation messages to the control */
354 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
355 (WPARAM
)dlgInfo
->hUserFont
, 0 );
356 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
358 /* If there's already a default push-button, set it back */
359 /* to normal and use this one instead. */
361 SendMessageA( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
362 hwndDefButton
= hwndCtrl
;
363 dlgInfo
->idResult
= GetWindowLongA( hwndCtrl
, GWL_ID
);
371 /***********************************************************************
372 * DIALOG_ParseTemplate32
374 * Fill a DLG_TEMPLATE structure from the dialog template, and return
375 * a pointer to the first control.
377 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
379 const WORD
*p
= (const WORD
*)template;
381 result
->style
= GET_DWORD(p
); p
+= 2;
382 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
384 result
->dialogEx
= TRUE
;
385 result
->helpId
= GET_DWORD(p
); p
+= 2;
386 result
->exStyle
= GET_DWORD(p
); p
+= 2;
387 result
->style
= GET_DWORD(p
); p
+= 2;
391 result
->dialogEx
= FALSE
;
393 result
->exStyle
= GET_DWORD(p
); p
+= 2;
395 result
->nbItems
= GET_WORD(p
); p
++;
396 result
->x
= GET_WORD(p
); p
++;
397 result
->y
= GET_WORD(p
); p
++;
398 result
->cx
= GET_WORD(p
); p
++;
399 result
->cy
= GET_WORD(p
); p
++;
400 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
401 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
402 result
->cx
, result
->cy
, result
->helpId
);
403 TRACE(" STYLE 0x%08lx\n", result
->style
);
404 TRACE(" EXSTYLE 0x%08lx\n", result
->exStyle
);
406 /* Get the menu name */
411 result
->menuName
= NULL
;
415 result
->menuName
= (LPCWSTR
)(UINT
)GET_WORD( p
+ 1 );
417 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
420 result
->menuName
= (LPCWSTR
)p
;
421 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
422 p
+= strlenW( result
->menuName
) + 1;
426 /* Get the class name */
431 result
->className
= DIALOG_CLASS_ATOMW
;
435 result
->className
= (LPCWSTR
)(UINT
)GET_WORD( p
+ 1 );
437 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
440 result
->className
= (LPCWSTR
)p
;
441 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
442 p
+= strlenW( result
->className
) + 1;
446 /* Get the window caption */
448 result
->caption
= (LPCWSTR
)p
;
449 p
+= strlenW( result
->caption
) + 1;
450 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
452 /* Get the font name */
454 if (result
->style
& DS_SETFONT
)
456 result
->pointSize
= GET_WORD(p
);
458 if (result
->dialogEx
)
460 result
->weight
= GET_WORD(p
); p
++;
461 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
465 result
->weight
= FW_DONTCARE
;
466 result
->italic
= FALSE
;
468 result
->faceName
= (LPCWSTR
)p
;
469 p
+= strlenW( result
->faceName
) + 1;
470 TRACE(" FONT %d, %s, %d, %s\n",
471 result
->pointSize
, debugstr_w( result
->faceName
),
472 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
475 /* First control is on dword boundary */
476 return (LPCSTR
)((((int)p
) + 3) & ~3);
480 /***********************************************************************
481 * DIALOG_CreateIndirect
482 * Creates a dialog box window
484 * modal = TRUE if we are called from a modal dialog box.
485 * (it's more compatible to do it here, as under Windows the owner
486 * is never disabled if the dialog fails because of an invalid template)
488 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
489 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
490 BOOL unicode
, BOOL modal
)
495 DLG_TEMPLATE
template;
496 DIALOGINFO
* dlgInfo
;
497 DWORD units
= GetDialogBaseUnits();
498 BOOL ownerEnabled
= TRUE
;
500 /* Parse dialog template */
502 if (!dlgTemplate
) return 0;
503 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
505 /* Initialise dialog extra data */
507 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo
) ))) return 0;
508 dlgInfo
->hwndFocus
= 0;
509 dlgInfo
->hUserFont
= 0;
511 dlgInfo
->xBaseUnit
= LOWORD(units
);
512 dlgInfo
->yBaseUnit
= HIWORD(units
);
513 dlgInfo
->idResult
= 0;
515 dlgInfo
->hDialogHeap
= 0;
519 if (template.menuName
) dlgInfo
->hMenu
= LoadMenuW( hInst
, template.menuName
);
521 /* Create custom font if needed */
523 if (template.style
& DS_SETFONT
)
525 /* We convert the size to pixels and then make it -ve. This works
526 * for both +ve and -ve template.pointSize */
530 pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
531 dlgInfo
->hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
532 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
533 PROOF_QUALITY
, FF_DONTCARE
,
535 if (dlgInfo
->hUserFont
)
538 if (DIALOG_GetCharSize( dc
, dlgInfo
->hUserFont
, &charSize
))
540 dlgInfo
->xBaseUnit
= charSize
.cx
;
541 dlgInfo
->yBaseUnit
= charSize
.cy
;
545 TRACE("units = %d,%d\n", dlgInfo
->xBaseUnit
, dlgInfo
->yBaseUnit
);
548 /* Create dialog main window */
550 rect
.left
= rect
.top
= 0;
551 rect
.right
= MulDiv(template.cx
, dlgInfo
->xBaseUnit
, 4);
552 rect
.bottom
= MulDiv(template.cy
, dlgInfo
->yBaseUnit
, 8);
553 if (template.style
& WS_CHILD
)
554 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
555 if (template.style
& DS_MODALFRAME
)
556 template.exStyle
|= WS_EX_DLGMODALFRAME
;
557 AdjustWindowRectEx( &rect
, template.style
, (dlgInfo
->hMenu
!= 0), template.exStyle
);
558 rect
.right
-= rect
.left
;
559 rect
.bottom
-= rect
.top
;
561 if (template.x
== CW_USEDEFAULT16
)
563 rect
.left
= rect
.top
= CW_USEDEFAULT
;
567 if (template.style
& DS_CENTER
)
569 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
570 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
574 rect
.left
+= MulDiv(template.x
, dlgInfo
->xBaseUnit
, 4);
575 rect
.top
+= MulDiv(template.y
, dlgInfo
->yBaseUnit
, 8);
577 if ( !(template.style
& WS_CHILD
) )
581 if( !(template.style
& DS_ABSALIGN
) )
582 ClientToScreen( owner
, (POINT
*)&rect
);
584 /* try to fit it into the desktop */
586 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
587 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
588 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
589 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
590 if( rect
.left
< 0 ) rect
.left
= 0;
591 if( rect
.top
< 0 ) rect
.top
= 0;
597 ownerEnabled
= DIALOG_DisableOwner( owner
);
598 if (ownerEnabled
) dlgInfo
->flags
|= DF_OWNERENABLED
;
603 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
604 template.style
& ~WS_VISIBLE
,
605 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
606 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
610 LPSTR
class = (LPSTR
)template.className
;
611 LPSTR caption
= (LPSTR
)template.caption
;
615 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
616 class = HeapAlloc( GetProcessHeap(), 0, len
);
617 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class, len
, NULL
, NULL
);
621 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
622 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
623 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption
, len
, NULL
, NULL
);
625 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
626 template.style
& ~WS_VISIBLE
,
627 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
628 owner
, dlgInfo
->hMenu
, hInst
, NULL
);
629 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
630 if (HIWORD(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
635 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
636 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
637 if (modal
&& (dlgInfo
->flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
638 HeapFree( GetProcessHeap(), 0, dlgInfo
);
641 wndPtr
= WIN_GetPtr( hwnd
);
642 wndPtr
->flags
|= WIN_ISDIALOG
;
643 WIN_ReleasePtr( wndPtr
);
645 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
646 SetWindowLongW( hwnd
, DWL_WINE_DIALOGINFO
, (LONG
)dlgInfo
);
648 if (unicode
) SetWindowLongW( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
);
649 else SetWindowLongA( hwnd
, DWL_DLGPROC
, (LONG
)dlgProc
);
651 if (dlgInfo
->hUserFont
)
652 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
654 /* Create controls */
656 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
658 HWND hwndPreInitFocus
;
660 /* Send initialisation messages and set focus */
662 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
664 hwndPreInitFocus
= GetFocus();
665 if (SendMessageA( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
667 /* check where the focus is again,
668 * some controls status might have changed in WM_INITDIALOG */
669 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
670 if( dlgInfo
->hwndFocus
)
671 SetFocus( dlgInfo
->hwndFocus
);
675 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
676 but the focus has not changed, set the focus where we expect it. */
677 if ((GetFocus() == hwndPreInitFocus
) &&
678 (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
680 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
681 if( dlgInfo
->hwndFocus
)
682 SetFocus( dlgInfo
->hwndFocus
);
686 if (template.style
& WS_VISIBLE
&& !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
688 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
692 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
693 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
698 /***********************************************************************
699 * CreateDialogParamA (USER32.@)
701 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
, HWND owner
,
702 DLGPROC dlgProc
, LPARAM param
)
707 if (!(hrsrc
= FindResourceA( hInst
, name
, (LPSTR
)RT_DIALOG
))) return 0;
708 if (!(ptr
= (LPCDLGTEMPLATEA
)LoadResource(hInst
, hrsrc
))) return 0;
709 return CreateDialogIndirectParamA( hInst
, ptr
, owner
, dlgProc
, param
);
713 /***********************************************************************
714 * CreateDialogParamW (USER32.@)
716 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
, HWND owner
,
717 DLGPROC dlgProc
, LPARAM param
)
722 if (!(hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
))) return 0;
723 if (!(ptr
= (LPCDLGTEMPLATEW
)LoadResource(hInst
, hrsrc
))) return 0;
724 return CreateDialogIndirectParamW( hInst
, ptr
, owner
, dlgProc
, param
);
728 /***********************************************************************
729 * CreateDialogIndirectParamAorW (USER32.@)
731 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
, LPCVOID dlgTemplate
,
732 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
735 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, owner
, dlgProc
, param
, !flags
, FALSE
);
738 /***********************************************************************
739 * CreateDialogIndirectParamA (USER32.@)
741 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
, LPCDLGTEMPLATEA dlgTemplate
,
742 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
744 return CreateDialogIndirectParamAorW( hInst
, dlgTemplate
, owner
, dlgProc
, param
, 2 );
747 /***********************************************************************
748 * CreateDialogIndirectParamW (USER32.@)
750 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
, LPCDLGTEMPLATEW dlgTemplate
,
751 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
753 return CreateDialogIndirectParamAorW( hInst
, dlgTemplate
, owner
, dlgProc
, param
, 0 );
757 /***********************************************************************
760 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
762 DIALOGINFO
* dlgInfo
;
765 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
767 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return -1;
769 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
771 ShowWindow( hwnd
, SW_SHOW
);
774 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
776 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
778 /* No message present -> send ENTERIDLE and wait */
779 SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
780 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
783 else if (!GetMessageW( &msg
, 0, 0, 0 )) break;
785 if (!IsWindow( hwnd
)) return -1;
786 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
788 TranslateMessage( &msg
);
789 DispatchMessageW( &msg
);
791 if (dlgInfo
->flags
& DF_END
) break;
794 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
795 retval
= dlgInfo
->idResult
;
796 DestroyWindow( hwnd
);
801 /***********************************************************************
802 * DialogBoxParamA (USER32.@)
804 INT_PTR WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
805 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
811 if (!(hrsrc
= FindResourceA( hInst
, name
, (LPSTR
)RT_DIALOG
))) return 0;
812 if (!(ptr
= (LPCDLGTEMPLATEA
)LoadResource(hInst
, hrsrc
))) return 0;
813 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, dlgProc
, param
, FALSE
, TRUE
);
814 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
819 /***********************************************************************
820 * DialogBoxParamW (USER32.@)
822 INT_PTR WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
823 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
829 if (!(hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
))) return 0;
830 if (!(ptr
= (LPCDLGTEMPLATEW
)LoadResource(hInst
, hrsrc
))) return 0;
831 hwnd
= DIALOG_CreateIndirect( hInst
, ptr
, owner
, dlgProc
, param
, TRUE
, TRUE
);
832 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
837 /***********************************************************************
838 * DialogBoxIndirectParamAorW (USER32.@)
840 INT_PTR WINAPI
DialogBoxIndirectParamAorW( HINSTANCE hInstance
, LPCVOID
template,
841 HWND owner
, DLGPROC dlgProc
,
842 LPARAM param
, DWORD flags
)
844 HWND hwnd
= DIALOG_CreateIndirect( hInstance
, template, owner
, dlgProc
, param
, !flags
, TRUE
);
845 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
849 /***********************************************************************
850 * DialogBoxIndirectParamA (USER32.@)
852 INT_PTR WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCDLGTEMPLATEA
template,
853 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
855 return DialogBoxIndirectParamAorW( hInstance
, template, owner
, dlgProc
, param
, 2 );
859 /***********************************************************************
860 * DialogBoxIndirectParamW (USER32.@)
862 INT_PTR WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCDLGTEMPLATEW
template,
863 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
865 return DialogBoxIndirectParamAorW( hInstance
, template, owner
, dlgProc
, param
, 0 );
868 /***********************************************************************
869 * EndDialog (USER32.@)
871 BOOL WINAPI
EndDialog( HWND hwnd
, INT_PTR retval
)
873 BOOL wasEnabled
= TRUE
;
874 DIALOGINFO
* dlgInfo
;
877 TRACE("%p %d\n", hwnd
, retval
);
879 if (!(dlgInfo
= DIALOG_get_info( hwnd
)))
881 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
884 dlgInfo
->idResult
= retval
;
885 dlgInfo
->flags
|= DF_END
;
886 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
888 if (wasEnabled
&& (owner
= GetWindow( hwnd
, GW_OWNER
)))
889 DIALOG_EnableOwner( owner
);
891 /* Windows sets the focus to the dialog itself in EndDialog */
893 if (IsChild(hwnd
, GetFocus()))
896 /* Don't have to send a ShowWindow(SW_HIDE), just do
897 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
899 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
900 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
902 /* unblock dialog loop */
903 PostMessageA(hwnd
, WM_NULL
, 0, 0);
908 /***********************************************************************
909 * DIALOG_IsAccelerator
911 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
913 HWND hwndControl
= hwnd
;
920 DWORD style
= GetWindowLongW( hwndControl
, GWL_STYLE
);
921 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
923 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
924 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
925 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
927 /* find the accelerator key */
928 LPWSTR p
= buffer
- 2;
932 p
= strchrW( p
+ 2, '&' );
934 while (p
!= NULL
&& p
[1] == '&');
936 /* and check if it's the one we're looking for */
937 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
939 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
941 /* set focus to the control */
942 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
943 /* and bump it on to next */
944 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
946 else if (dlgCode
& DLGC_BUTTON
)
948 /* send BM_CLICK message to the control */
949 SendMessageA( hwndControl
, BM_CLICK
, 0, 0 );
954 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
958 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
960 while (!hwndNext
&& hwndControl
)
962 hwndControl
= GetParent( hwndControl
);
963 if (hwndControl
== hwndDlg
)
965 if(hwnd
==hwndDlg
) /* prevent endless loop */
970 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
973 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
975 hwndControl
= hwndNext
;
977 while (hwndControl
&& (hwndControl
!= hwnd
));
982 /***********************************************************************
983 * DIALOG_FindMsgDestination
985 * The messages that IsDialogMessage sends may not go to the dialog
986 * calling IsDialogMessage if that dialog is a child, and it has the
987 * DS_CONTROL style set.
988 * We propagate up until we hit one that does not have DS_CONTROL, or
989 * whose parent is not a dialog.
991 * This is undocumented behaviour.
993 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
995 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
998 HWND hParent
= GetParent(hwndDlg
);
1001 pParent
= WIN_FindWndPtr(hParent
);
1002 if (!pParent
) break;
1004 if (!(pParent
->flags
& WIN_ISDIALOG
))
1006 WIN_ReleaseWndPtr(pParent
);
1009 WIN_ReleaseWndPtr(pParent
);
1017 /***********************************************************************
1018 * IsDialogMessageW (USER32.@)
1020 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1024 if (CallMsgFilterW( msg
, MSGF_DIALOGBOX
)) return TRUE
;
1026 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1027 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
)) return FALSE
;
1029 hwndDlg
= DIALOG_FindMsgDestination(hwndDlg
);
1031 switch(msg
->message
)
1034 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1035 if (dlgCode
& DLGC_WANTMESSAGE
) break;
1040 if (!(dlgCode
& DLGC_WANTTAB
))
1042 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1051 if (!(dlgCode
& DLGC_WANTARROWS
))
1053 BOOL fPrevious
= (msg
->wParam
== VK_LEFT
|| msg
->wParam
== VK_UP
);
1054 HWND hwndNext
= GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1055 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
1062 SendMessageW( hwndDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1068 DWORD dw
= SendMessageW( hwndDlg
, DM_GETDEFID
, 0, 0 );
1069 if (HIWORD(dw
) == DC_HASDEFID
)
1071 SendMessageW( hwndDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1072 (LPARAM
)GetDlgItem(hwndDlg
, LOWORD(dw
)));
1076 SendMessageW( hwndDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1085 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, msg
->wParam
, (LPARAM
)msg
);
1086 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
1087 if (msg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
1091 if (DIALOG_IsAccelerator( WIN_GetFullHandle(msg
->hwnd
), hwndDlg
, msg
->wParam
))
1093 /* don't translate or dispatch */
1099 TranslateMessage( msg
);
1100 DispatchMessageW( msg
);
1105 /***********************************************************************
1106 * GetDlgCtrlID (USER32.@)
1108 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1110 return GetWindowLongW( hwnd
, GWL_ID
);
1114 /***********************************************************************
1115 * GetDlgItem (USER32.@)
1117 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1120 HWND
*list
= WIN_ListChildren( hwndDlg
);
1123 if (!list
) return 0;
1125 for (i
= 0; list
[i
]; i
++) if (GetWindowLongW( list
[i
], GWL_ID
) == id
) break;
1127 HeapFree( GetProcessHeap(), 0, list
);
1132 /*******************************************************************
1133 * SendDlgItemMessageA (USER32.@)
1135 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1136 WPARAM wParam
, LPARAM lParam
)
1138 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1139 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1144 /*******************************************************************
1145 * SendDlgItemMessageW (USER32.@)
1147 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1148 WPARAM wParam
, LPARAM lParam
)
1150 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1151 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1156 /*******************************************************************
1157 * SetDlgItemTextA (USER32.@)
1159 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1161 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1165 /*******************************************************************
1166 * SetDlgItemTextW (USER32.@)
1168 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1170 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1174 /***********************************************************************
1175 * GetDlgItemTextA (USER32.@)
1177 INT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, UINT len
)
1179 return (INT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1184 /***********************************************************************
1185 * GetDlgItemTextW (USER32.@)
1187 INT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, UINT len
)
1189 return (INT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1194 /*******************************************************************
1195 * SetDlgItemInt (USER32.@)
1197 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1202 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1203 else sprintf( str
, "%u", value
);
1204 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1209 /***********************************************************************
1210 * GetDlgItemInt (USER32.@)
1212 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1219 if (translated
) *translated
= FALSE
;
1220 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1224 result
= strtol( str
, &endptr
, 10 );
1225 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1227 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1232 result
= strtoul( str
, &endptr
, 10 );
1233 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1235 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1237 if (translated
) *translated
= TRUE
;
1238 return (UINT
)result
;
1242 /***********************************************************************
1243 * CheckDlgButton (USER32.@)
1245 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1247 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1252 /***********************************************************************
1253 * IsDlgButtonChecked (USER32.@)
1255 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, UINT id
)
1257 return (UINT
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1261 /***********************************************************************
1264 * Callback function used to check/uncheck radio buttons that fall
1265 * within a specific range of IDs.
1267 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1269 LONG lChildID
= GetWindowLongA(hwndChild
, GWL_ID
);
1270 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1272 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1273 (lChildID
<= lpRadioGroup
->lastID
))
1275 if (lChildID
== lpRadioGroup
->checkID
)
1277 SendMessageA(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1281 SendMessageA(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1289 /***********************************************************************
1290 * CheckRadioButton (USER32.@)
1292 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, UINT firstID
,
1293 UINT lastID
, UINT checkID
)
1295 RADIOGROUP radioGroup
;
1297 radioGroup
.firstID
= firstID
;
1298 radioGroup
.lastID
= lastID
;
1299 radioGroup
.checkID
= checkID
;
1301 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1302 (LPARAM
)&radioGroup
);
1306 /***********************************************************************
1307 * GetDialogBaseUnits (USER.243)
1308 * GetDialogBaseUnits (USER32.@)
1310 DWORD WINAPI
GetDialogBaseUnits(void)
1319 if ((hdc
= GetDC(0)))
1321 if (DIALOG_GetCharSize( hdc
, 0, &size
)) units
= MAKELONG( size
.cx
, size
.cy
);
1322 ReleaseDC( 0, hdc
);
1324 TRACE("base units = %d,%d\n", LOWORD(units
), HIWORD(units
) );
1330 /***********************************************************************
1331 * MapDialogRect (USER32.@)
1333 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1335 DIALOGINFO
* dlgInfo
;
1336 if (!(dlgInfo
= DIALOG_get_info( hwnd
))) return FALSE
;
1337 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1338 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1339 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1340 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1345 /***********************************************************************
1346 * GetNextDlgGroupItem (USER32.@)
1348 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1350 HWND hwnd
, retvalue
;
1352 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1353 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1357 /* if the hwndCtrl is the child of the control in the hwndDlg,
1358 * then the hwndDlg has to be the parent of the hwndCtrl */
1359 if(GetParent(hwndCtrl
) != hwndDlg
&& GetParent(GetParent(hwndCtrl
)) == hwndDlg
)
1360 hwndDlg
= GetParent(hwndCtrl
);
1365 /* Make sure hwndCtrl is a top-level child */
1366 HWND parent
= GetParent( hwndCtrl
);
1367 while (parent
&& parent
!= hwndDlg
) parent
= GetParent(parent
);
1368 if (parent
!= hwndDlg
) return 0;
1372 /* No ctrl specified -> start from the beginning */
1373 if (!(hwndCtrl
= GetWindow( hwndDlg
, GW_CHILD
))) return 0;
1374 if (fPrevious
) hwndCtrl
= GetWindow( hwndCtrl
, GW_HWNDLAST
);
1377 retvalue
= hwndCtrl
;
1378 hwnd
= GetWindow( hwndCtrl
, GW_HWNDNEXT
);
1381 if (!hwnd
|| (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_GROUP
))
1383 /* Wrap-around to the beginning of the group */
1386 hwnd
= GetWindow( hwndDlg
, GW_CHILD
);
1387 for (tmp
= hwnd
; tmp
; tmp
= GetWindow( tmp
, GW_HWNDNEXT
) )
1389 if (GetWindowLongW( tmp
, GWL_STYLE
) & WS_GROUP
) hwnd
= tmp
;
1390 if (tmp
== hwndCtrl
) break;
1393 if (hwnd
== hwndCtrl
) break;
1394 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
1397 if (!fPrevious
) break;
1399 hwnd
= GetWindow( hwnd
, GW_HWNDNEXT
);
1405 /***********************************************************************
1406 * DIALOG_GetNextTabItem
1408 * Helper for GetNextDlgTabItem
1410 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1414 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1416 HWND hChildFirst
= 0;
1420 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1421 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1423 else if (IsChild( hwndMain
, hwndCtrl
))
1425 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1428 if(GetParent(hwndCtrl
) != hwndMain
)
1429 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1433 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDLAST
);
1435 hChildFirst
= GetWindow(hwndCtrl
,GW_HWNDFIRST
);
1445 dsStyle
= GetWindowLongA(hChildFirst
,GWL_STYLE
);
1446 exStyle
= GetWindowLongA(hChildFirst
,GWL_EXSTYLE
);
1447 if( (dsStyle
& DS_CONTROL
|| exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1452 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1454 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1459 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1461 retWnd
= hChildFirst
;
1464 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1466 if(!retWnd
&& hwndCtrl
)
1468 HWND hParent
= GetParent(hwndCtrl
);
1471 if(hParent
== hwndMain
) break;
1472 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1474 hParent
= GetParent(hParent
);
1477 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1479 return retWnd
? retWnd
: hwndCtrl
;
1482 /***********************************************************************
1483 * GetNextDlgTabItem (USER32.@)
1485 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1488 hwndDlg
= WIN_GetFullHandle( hwndDlg
);
1489 hwndCtrl
= WIN_GetFullHandle( hwndCtrl
);
1490 return DIALOG_GetNextTabItem(hwndDlg
,hwndDlg
,hwndCtrl
,fPrevious
);
1493 /**********************************************************************
1494 * DIALOG_DlgDirSelect
1496 * Helper function for DlgDirSelect*
1498 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1499 INT id
, BOOL unicode
, BOOL combo
)
1504 HWND listbox
= GetDlgItem( hwnd
, id
);
1506 TRACE("%p '%s' %d\n", hwnd
, str
, id
);
1507 if (!listbox
) return FALSE
;
1509 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1510 if (item
== LB_ERR
) return FALSE
;
1511 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, 0, 0 );
1512 if (size
== LB_ERR
) return FALSE
;
1514 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
+1 ))) return FALSE
;
1516 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1518 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1520 if (buffer
[1] == '-') /* drive */
1528 buffer
[strlen(buffer
)-1] = '\\';
1536 if (len
> 0 && !MultiByteToWideChar( CP_ACP
, 0, ptr
, -1, (LPWSTR
)str
, len
))
1537 ((LPWSTR
)str
)[len
-1] = 0;
1539 else lstrcpynA( str
, ptr
, len
);
1540 HeapFree( GetProcessHeap(), 0, buffer
);
1541 TRACE("Returning %d '%s'\n", ret
, str
);
1546 /**********************************************************************
1549 * Helper function for DlgDirList*
1551 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
1552 INT idStatic
, UINT attrib
, BOOL combo
)
1555 LPSTR orig_spec
= spec
;
1558 #define SENDMSG(msg,wparam,lparam) \
1559 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
1560 : SendMessageA( hwnd, msg, wparam, lparam ))
1562 TRACE("%p '%s' %d %d %04x\n",
1563 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
1565 /* If the path exists and is a directory, chdir to it */
1566 if (!spec
|| !spec
[0] || SetCurrentDirectoryA( spec
)) spec
= any
;
1571 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
1572 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
1577 if (!SetCurrentDirectoryA( spec
))
1579 *p
= sep
; /* Restore the original spec */
1586 TRACE( "mask=%s\n", spec
);
1588 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1590 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1591 if (attrib
& DDL_DIRECTORY
)
1593 if (!(attrib
& DDL_EXCLUSIVE
))
1595 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1596 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1597 (LPARAM
)spec
) == LB_ERR
)
1600 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
1601 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1602 (LPARAM
)"*.*" ) == LB_ERR
)
1607 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
1608 (LPARAM
)spec
) == LB_ERR
)
1613 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1615 char temp
[MAX_PATH
];
1616 GetCurrentDirectoryA( sizeof(temp
), temp
);
1618 /* Can't use PostMessage() here, because the string is on the stack */
1619 SetDlgItemTextA( hDlg
, idStatic
, temp
);
1622 if (orig_spec
&& (spec
!= orig_spec
))
1624 /* Update the original file spec */
1626 while ((*orig_spec
++ = *p
++));
1634 /**********************************************************************
1635 * DIALOG_DlgDirListW
1637 * Helper function for DlgDirList*W
1639 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1640 INT idStatic
, UINT attrib
, BOOL combo
)
1644 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
1645 INT ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
1647 MultiByteToWideChar( CP_ACP
, 0, specA
, -1, spec
, 0x7fffffff );
1648 HeapFree( GetProcessHeap(), 0, specA
);
1651 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1655 /**********************************************************************
1656 * DlgDirSelectExA (USER32.@)
1658 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
1660 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
);
1664 /**********************************************************************
1665 * DlgDirSelectExW (USER32.@)
1667 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
1669 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, FALSE
);
1673 /**********************************************************************
1674 * DlgDirSelectComboBoxExA (USER32.@)
1676 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
1679 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, TRUE
);
1683 /**********************************************************************
1684 * DlgDirSelectComboBoxExW (USER32.@)
1686 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
1689 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
);
1693 /**********************************************************************
1694 * DlgDirListA (USER32.@)
1696 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1697 INT idStatic
, UINT attrib
)
1699 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1703 /**********************************************************************
1704 * DlgDirListW (USER32.@)
1706 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1707 INT idStatic
, UINT attrib
)
1709 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1713 /**********************************************************************
1714 * DlgDirListComboBoxA (USER32.@)
1716 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
1717 INT idStatic
, UINT attrib
)
1719 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
1723 /**********************************************************************
1724 * DlgDirListComboBoxW (USER32.@)
1726 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
1727 INT idStatic
, UINT attrib
)
1729 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);