4 * Copyright 1993, 1994 Alexandre Julliard
16 #include "stackframe.h"
20 /* #define DEBUG_DIALOG */
23 /* Dialog base units */
24 WORD xBaseUnit
= 0, yBaseUnit
= 0;
27 /***********************************************************************
30 * Initialisation of the dialog manager.
37 /* Calculate the dialog base units */
39 if (!(hdc
= GetDC( 0 ))) return FALSE
;
40 GetTextMetrics( hdc
, &tm
);
42 xBaseUnit
= tm
.tmAveCharWidth
;
43 yBaseUnit
= tm
.tmHeight
;
45 /* Dialog units are based on a proportional system font */
46 /* so we adjust them a bit for a fixed font. */
47 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) xBaseUnit
= xBaseUnit
* 5 / 4;
49 dprintf_dialog( stddeb
, "DIALOG_Init: base units = %d,%d\n",
50 xBaseUnit
, yBaseUnit
);
55 /***********************************************************************
56 * DIALOG_GetFirstTabItem
58 * Return the first item of the dialog that has the WS_TABSTOP style.
60 HWND
DIALOG_GetFirstTabItem( HWND hwndDlg
)
62 WND
*pWnd
= WIN_FindWndPtr( hwndDlg
);
63 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
64 if (pWnd
->dwStyle
& WS_TABSTOP
) return pWnd
->hwndSelf
;
69 /***********************************************************************
72 * Return the class and text of the control pointed to by ptr,
73 * fill the header structure and return a pointer to the next control.
75 static SEGPTR
DIALOG_GetControl( SEGPTR ptr
, DLGCONTROLHEADER
*header
,
76 SEGPTR
*class, SEGPTR
*text
)
78 unsigned char *base
= (unsigned char *)PTR_SEG_TO_LIN( ptr
);
79 unsigned char *p
= base
;
81 header
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
82 header
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
83 header
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
84 header
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
85 header
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
86 header
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
90 *class = MAKEINTRESOURCE( *p
);
95 *class = ptr
+ (WORD
)(p
- base
);
101 /* Integer id, not documented (?). Only works for SS_ICON controls */
102 *text
= MAKEINTRESOURCE( GET_WORD(p
+1) );
107 *text
= ptr
+ (WORD
)(p
- base
);
110 return ptr
+ (WORD
)(p
- base
);
114 /***********************************************************************
115 * DIALOG_ParseTemplate
117 * Fill a DLGTEMPLATE structure from the dialog template, and return
118 * a pointer to the first control.
120 static SEGPTR
DIALOG_ParseTemplate( SEGPTR
template, DLGTEMPLATE
* result
)
122 unsigned char *base
= (unsigned char *)PTR_SEG_TO_LIN(template);
123 unsigned char * p
= base
;
125 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
126 result
->nbItems
= *p
++;
127 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
128 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
129 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
130 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
132 /* Get the menu name */
136 result
->menuName
= MAKEINTRESOURCE( GET_WORD(p
+1) );
141 result
->menuName
= template + (WORD
)(p
- base
);
146 result
->menuName
= 0;
150 /* Get the class name */
152 if (*p
) result
->className
= template + (WORD
)(p
- base
);
153 else result
->className
= DIALOG_CLASS_ATOM
;
156 /* Get the window caption */
158 result
->caption
= template + (WORD
)(p
- base
);
161 /* Get the font name */
163 if (result
->style
& DS_SETFONT
)
165 result
->pointSize
= GET_WORD(p
);
167 result
->faceName
= template + (WORD
)(p
- base
);
171 return template + (WORD
)(p
- base
);
175 /***********************************************************************
176 * DIALOG_DisplayTemplate
178 static void DIALOG_DisplayTemplate( DLGTEMPLATE
* result
)
180 dprintf_dialog(stddeb
, "DIALOG %d, %d, %d, %d\n", result
->x
, result
->y
,
181 result
->cx
, result
->cy
);
182 dprintf_dialog(stddeb
, " STYLE %08lx\n", result
->style
);
183 dprintf_dialog( stddeb
, " CAPTION '%s'\n",
184 (char *)PTR_SEG_TO_LIN(result
->caption
) );
186 if (HIWORD(result
->className
))
187 dprintf_dialog( stddeb
, " CLASS '%s'\n",
188 (char *)PTR_SEG_TO_LIN(result
->className
) );
190 dprintf_dialog( stddeb
, " CLASS #%d\n", LOWORD(result
->className
) );
192 if (HIWORD(result
->menuName
))
193 dprintf_dialog( stddeb
, " MENU '%s'\n",
194 (char *)PTR_SEG_TO_LIN(result
->menuName
) );
195 else if (LOWORD(result
->menuName
))
196 dprintf_dialog(stddeb
, " MENU %04x\n", LOWORD(result
->menuName
) );
198 if (result
->style
& DS_SETFONT
)
199 dprintf_dialog( stddeb
, " FONT %d,'%s'\n", result
->pointSize
,
200 (char *)PTR_SEG_TO_LIN(result
->faceName
) );
204 /***********************************************************************
205 * CreateDialog (USER.89)
207 HWND
CreateDialog( HINSTANCE hInst
, SEGPTR dlgTemplate
,
208 HWND owner
, DLGPROC dlgProc
)
210 return CreateDialogParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
214 /***********************************************************************
215 * CreateDialogParam (USER.241)
217 HWND
CreateDialogParam( HINSTANCE hInst
, SEGPTR dlgTemplate
,
218 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
225 dprintf_dialog(stddeb
, "CreateDialogParam: %04x,%08lx,%04x,%08lx,%ld\n",
226 hInst
, (DWORD
)dlgTemplate
, owner
, (DWORD
)dlgProc
, param
);
228 if (!(hRsrc
= FindResource( hInst
, dlgTemplate
, RT_DIALOG
))) return 0;
229 if (!(hmem
= LoadResource( hInst
, hRsrc
))) return 0;
230 if (!(data
= WIN16_LockResource( hmem
))) hwnd
= 0;
231 else hwnd
= CreateDialogIndirectParam(hInst
, data
, owner
, dlgProc
, param
);
232 FreeResource( hmem
);
237 /***********************************************************************
238 * CreateDialogIndirect (USER.219)
240 HWND
CreateDialogIndirect( HINSTANCE hInst
, SEGPTR dlgTemplate
,
241 HWND owner
, DLGPROC dlgProc
)
243 return CreateDialogIndirectParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
247 /***********************************************************************
248 * CreateDialogIndirectParam (USER.242)
250 HWND
CreateDialogIndirectParam( HINSTANCE hInst
, SEGPTR dlgTemplate
,
251 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
259 DLGTEMPLATE
template;
261 DIALOGINFO
* dlgInfo
;
263 WORD xUnit
= xBaseUnit
;
264 WORD yUnit
= yBaseUnit
;
266 /* Parse dialog template */
268 if (!dlgTemplate
) return 0;
269 headerPtr
= DIALOG_ParseTemplate( dlgTemplate
, &template );
270 if (debugging_dialog
) DIALOG_DisplayTemplate( &template );
274 if (template.menuName
) hMenu
= LoadMenu( hInst
, template.menuName
);
276 /* Create custom font if needed */
278 if (template.style
& DS_SETFONT
)
280 /* The font height must be negative as it is a point size */
281 /* (see CreateFont() documentation in the Windows SDK). */
282 hFont
= CreateFont( -template.pointSize
, 0, 0, 0, FW_DONTCARE
,
283 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
284 DEFAULT_QUALITY
, FF_DONTCARE
,
285 (LPSTR
)PTR_SEG_TO_LIN(template.faceName
) );
293 oldFont
= SelectObject( hdc
, hFont
);
294 GetTextMetrics( hdc
, &tm
);
295 SelectObject( hdc
, oldFont
);
297 xUnit
= tm
.tmAveCharWidth
;
299 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
300 xBaseUnit
= xBaseUnit
* 5 / 4; /* See DIALOG_Init() */
304 /* Create dialog main window */
306 rect
.left
= rect
.top
= 0;
307 rect
.right
= template.cx
* xUnit
/ 4;
308 rect
.bottom
= template.cy
* yUnit
/ 8;
309 if (template.style
& DS_MODALFRAME
) exStyle
|= WS_EX_DLGMODALFRAME
;
310 AdjustWindowRectEx16( &rect
, template.style
,
311 hMenu
? TRUE
: FALSE
, exStyle
);
312 rect
.right
-= rect
.left
;
313 rect
.bottom
-= rect
.top
;
315 if ((INT16
)template.x
== CW_USEDEFAULT16
)
316 rect
.left
= rect
.top
= CW_USEDEFAULT16
;
319 rect
.left
+= template.x
* xUnit
/ 4;
320 rect
.top
+= template.y
* yUnit
/ 8;
321 if (!(template.style
& DS_ABSALIGN
))
322 ClientToScreen16( owner
, (POINT16
*)&rect
);
325 hwnd
= CreateWindowEx16( exStyle
, template.className
, template.caption
,
326 template.style
& ~WS_VISIBLE
,
327 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
328 owner
, hMenu
, hInst
, (SEGPTR
)0 );
331 if (hFont
) DeleteObject( hFont
);
332 if (hMenu
) DestroyMenu( hMenu
);
335 wndPtr
= WIN_FindWndPtr( hwnd
);
337 /* Create control windows */
339 dprintf_dialog(stddeb
, " BEGIN\n" );
341 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
342 dlgInfo
->msgResult
= 0; /* This is used to store the default button id */
343 dlgInfo
->hDialogHeap
= 0;
345 for (i
= 0; i
< template.nbItems
; i
++)
347 DLGCONTROLHEADER header
;
348 SEGPTR className
, winName
;
349 HWND hwndDefButton
= 0;
352 headerPtr
= DIALOG_GetControl( headerPtr
, &header
,
353 &className
, &winName
);
355 if (!HIWORD(className
))
357 switch(LOWORD(className
))
359 case 0x80: strcpy( buffer
, "BUTTON" ); break;
360 case 0x81: strcpy( buffer
, "EDIT" ); break;
361 case 0x82: strcpy( buffer
, "STATIC" ); break;
362 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
363 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
364 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
365 default: buffer
[0] = '\0'; break;
367 className
= MAKE_SEGPTR(buffer
);
370 if (HIWORD(className
))
371 dprintf_dialog(stddeb
, " %s ", (char*)PTR_SEG_TO_LIN(className
));
372 else dprintf_dialog(stddeb
, " %04x ", LOWORD(className
) );
374 dprintf_dialog(stddeb
,"'%s'", (char *)PTR_SEG_TO_LIN(winName
) );
375 else dprintf_dialog(stddeb
,"%04x", LOWORD(winName
) );
377 dprintf_dialog(stddeb
," %d, %d, %d, %d, %d, %08lx\n",
378 header
.id
, header
.x
, header
.y
,
379 header
.cx
, header
.cy
, header
.style
);
381 if (HIWORD(className
) &&
382 !strcmp( (char *)PTR_SEG_TO_LIN(className
), "EDIT") &&
383 ((header
.style
& DS_LOCALEDIT
) != DS_LOCALEDIT
))
385 if (!dlgInfo
->hDialogHeap
)
387 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
388 if (!dlgInfo
->hDialogHeap
)
390 fprintf(stderr
,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
393 LocalInit(dlgInfo
->hDialogHeap
, 0, 0xffff);
395 hwndCtrl
= CreateWindowEx16(WS_EX_NOPARENTNOTIFY
, className
, winName
,
396 header
.style
| WS_CHILD
,
397 header
.x
* xUnit
/ 4,
398 header
.y
* yUnit
/ 8,
399 header
.cx
* xUnit
/ 4,
400 header
.cy
* yUnit
/ 8,
401 hwnd
, (HMENU
)header
.id
,
402 dlgInfo
->hDialogHeap
, (SEGPTR
)0 );
406 hwndCtrl
= CreateWindowEx16( WS_EX_NOPARENTNOTIFY
, className
,
408 header
.style
| WS_CHILD
,
409 header
.x
* xUnit
/ 4,
410 header
.y
* yUnit
/ 8,
411 header
.cx
* xUnit
/ 4,
412 header
.cy
* yUnit
/ 8,
413 hwnd
, (HMENU
)header
.id
,
417 /* Make the control last one in Z-order, so that controls remain
418 in the order in which they were created */
419 SetWindowPos( hwndCtrl
, HWND_BOTTOM
, 0, 0, 0, 0,
420 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
422 /* Send initialisation messages to the control */
423 if (hFont
) SendMessage16( hwndCtrl
, WM_SETFONT
, (WPARAM
)hFont
, 0 );
424 if (SendMessage16( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
426 /* If there's already a default push-button, set it back */
427 /* to normal and use this one instead. */
429 SendMessage32A( hwndDefButton
, BM_SETSTYLE32
,
430 BS_PUSHBUTTON
,FALSE
);
431 hwndDefButton
= hwndCtrl
;
432 dlgInfo
->msgResult
= GetWindowWord( hwndCtrl
, GWW_ID
);
436 dprintf_dialog(stddeb
, " END\n" );
438 /* Initialise dialog extra data */
440 dlgInfo
->dlgProc
= dlgProc
;
441 dlgInfo
->hUserFont
= hFont
;
442 dlgInfo
->hMenu
= hMenu
;
443 dlgInfo
->xBaseUnit
= xUnit
;
444 dlgInfo
->yBaseUnit
= yUnit
;
445 dlgInfo
->hwndFocus
= DIALOG_GetFirstTabItem( hwnd
);
447 /* Send initialisation messages and set focus */
449 if (dlgInfo
->hUserFont
)
450 SendMessage16( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
451 if (SendMessage16( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
452 SetFocus( dlgInfo
->hwndFocus
);
453 if (template.style
& WS_VISIBLE
) ShowWindow(hwnd
, SW_SHOW
);
458 /***********************************************************************
461 int DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
464 DIALOGINFO
* dlgInfo
;
469 /* Owner must be a top-level window */
470 owner
= WIN_GetTopParent( owner
);
471 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return -1;
472 if (!(msgHandle
= USER_HEAP_ALLOC( sizeof(MSG
) ))) return -1;
473 lpmsg
= (MSG
*) USER_HEAP_LIN_ADDR( msgHandle
);
474 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
475 EnableWindow( owner
, FALSE
);
476 ShowWindow( hwnd
, SW_SHOW
);
478 while (MSG_InternalGetMessage( (SEGPTR
)USER_HEAP_SEG_ADDR(msgHandle
), hwnd
, owner
,
479 MSGF_DIALOGBOX
, PM_REMOVE
,
480 !(wndPtr
->dwStyle
& DS_NOIDLEMSG
) ))
482 if (!IsDialogMessage( hwnd
, lpmsg
))
484 TranslateMessage( lpmsg
);
485 DispatchMessage( lpmsg
);
487 if (dlgInfo
->fEnd
) break;
489 retval
= dlgInfo
->msgResult
;
490 DestroyWindow( hwnd
);
491 USER_HEAP_FREE( msgHandle
);
492 EnableWindow( owner
, TRUE
);
497 /***********************************************************************
498 * DialogBox (USER.87)
500 INT
DialogBox( HINSTANCE hInst
, SEGPTR dlgTemplate
,
501 HWND owner
, DLGPROC dlgProc
)
503 return DialogBoxParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
507 /***********************************************************************
508 * DialogBoxParam (USER.239)
510 INT
DialogBoxParam( HINSTANCE hInst
, SEGPTR dlgTemplate
,
511 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
515 dprintf_dialog(stddeb
, "DialogBoxParam: %04x,%08lx,%04x,%08lx,%ld\n",
516 hInst
, (DWORD
)dlgTemplate
, owner
, (DWORD
)dlgProc
, param
);
517 hwnd
= CreateDialogParam( hInst
, dlgTemplate
, owner
, dlgProc
, param
);
518 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
523 /***********************************************************************
524 * DialogBoxIndirect (USER.218)
526 INT
DialogBoxIndirect( HINSTANCE hInst
, HANDLE dlgTemplate
,
527 HWND owner
, DLGPROC dlgProc
)
529 return DialogBoxIndirectParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
533 /***********************************************************************
534 * DialogBoxIndirectParam (USER.240)
536 INT
DialogBoxIndirectParam( HINSTANCE hInst
, HANDLE dlgTemplate
,
537 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
542 if (!(ptr
= (SEGPTR
)WIN16_GlobalLock16( dlgTemplate
))) return -1;
543 hwnd
= CreateDialogIndirectParam( hInst
, ptr
, owner
, dlgProc
, param
);
544 GlobalUnlock16( dlgTemplate
);
545 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
550 /***********************************************************************
551 * EndDialog (USER.88)
553 BOOL
EndDialog( HWND hwnd
, INT retval
)
555 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
556 DIALOGINFO
* dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
557 dlgInfo
->msgResult
= retval
;
558 dlgInfo
->fEnd
= TRUE
;
559 dprintf_dialog(stddeb
, "EndDialog: %04x %d\n", hwnd
, retval
);
564 /***********************************************************************
565 * IsDialogMessage (USER.90)
567 BOOL
IsDialogMessage( HWND hwndDlg
, LPMSG msg
)
572 if (!(wndPtr
= WIN_FindWndPtr( hwndDlg
))) return FALSE
;
573 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
)) return FALSE
;
575 /* Only the key messages get special processing */
576 if ((msg
->message
!= WM_KEYDOWN
) &&
577 (msg
->message
!= WM_SYSCHAR
) &&
578 (msg
->message
!= WM_CHAR
))
581 dlgCode
= SendMessage16( msg
->hwnd
, WM_GETDLGCODE
, 0, 0 );
582 if (dlgCode
& DLGC_WANTMESSAGE
)
584 DispatchMessage( msg
);
591 if (dlgCode
& DLGC_WANTALLKEYS
) break;
595 if (!(dlgCode
& DLGC_WANTTAB
))
597 SendMessage16( hwndDlg
, WM_NEXTDLGCTL
,
598 (GetKeyState(VK_SHIFT
) & 0x80), 0 );
605 if (!(dlgCode
& DLGC_WANTARROWS
))
607 SetFocus(GetNextDlgGroupItem(hwndDlg
,GetFocus(),FALSE
));
614 if (!(dlgCode
& DLGC_WANTARROWS
))
616 SetFocus(GetNextDlgGroupItem(hwndDlg
,GetFocus(),TRUE
));
623 SendMessage32A( hwndDlg
, WM_COMMAND
,
624 MAKEWPARAM( IDCANCEL
, 0 ),
625 (LPARAM
)GetDlgItem(hwndDlg
,IDCANCEL
) );
627 SendMessage16( hwndDlg
, WM_COMMAND
, IDCANCEL
,
628 MAKELPARAM( GetDlgItem(hwndDlg
,IDCANCEL
), 0 ));
634 DWORD dw
= SendMessage16( hwndDlg
, DM_GETDEFID
, 0, 0 );
635 if (HIWORD(dw
) == DC_HASDEFID
)
637 SendMessage32A( hwndDlg
, WM_COMMAND
,
638 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
639 (LPARAM
)GetDlgItem( hwndDlg
, LOWORD(dw
) ) );
641 SendMessage32A( hwndDlg
, WM_COMMAND
,
642 MAKEWPARAM( IDOK
, 0 ),
643 (LPARAM
)GetDlgItem(hwndDlg
,IDOK
) );
645 SendMessage16( hwndDlg
, WM_COMMAND
, LOWORD(dw
),
646 MAKELPARAM( GetDlgItem( hwndDlg
, LOWORD(dw
) ),
649 SendMessage16( hwndDlg
, WM_COMMAND
, IDOK
,
650 MAKELPARAM( GetDlgItem(hwndDlg
,IDOK
), 0 ));
656 TranslateMessage( msg
);
658 break; /* case WM_KEYDOWN */
662 if (dlgCode
& (DLGC_WANTALLKEYS
| DLGC_WANTCHARS
)) break;
666 if (dlgCode
& DLGC_WANTALLKEYS
) break;
670 /* If we get here, the message has not been treated specially */
671 /* and can be sent to its destination window. */
672 DispatchMessage( msg
);
677 /****************************************************************
678 * GetDlgCtrlID (USER.277)
680 int GetDlgCtrlID( HWND hwnd
)
682 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
683 if (wndPtr
) return wndPtr
->wIDmenu
;
688 /***********************************************************************
689 * GetDlgItem (USER.91)
691 HWND
GetDlgItem( HWND hwndDlg
, WORD id
)
695 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
696 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
697 if (pWnd
->wIDmenu
== id
) return pWnd
->hwndSelf
;
702 /*******************************************************************
703 * SendDlgItemMessage16 (USER.101)
705 LRESULT
SendDlgItemMessage16( HWND16 hwnd
, INT16 id
, UINT16 msg
,
706 WPARAM16 wParam
, LPARAM lParam
)
708 HWND16 hwndCtrl
= GetDlgItem( hwnd
, id
);
709 if (hwndCtrl
) return SendMessage16( hwndCtrl
, msg
, wParam
, lParam
);
714 /*******************************************************************
715 * SendDlgItemMessage32A (USER32.451)
717 LRESULT
SendDlgItemMessage32A( HWND32 hwnd
, INT32 id
, UINT32 msg
,
718 WPARAM32 wParam
, LPARAM lParam
)
720 HWND hwndCtrl
= GetDlgItem( (HWND16
)hwnd
, (INT16
)id
);
721 if (hwndCtrl
) return SendMessage32A( hwndCtrl
, msg
, wParam
, lParam
);
726 /*******************************************************************
727 * SendDlgItemMessage32W (USER32.452)
729 LRESULT
SendDlgItemMessage32W( HWND32 hwnd
, INT32 id
, UINT32 msg
,
730 WPARAM32 wParam
, LPARAM lParam
)
732 HWND hwndCtrl
= GetDlgItem( (HWND16
)hwnd
, (INT16
)id
);
733 if (hwndCtrl
) return SendMessage32W( hwndCtrl
, msg
, wParam
, lParam
);
738 /*******************************************************************
739 * SetDlgItemText16 (USER.92)
741 void SetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR lpString
)
743 SendDlgItemMessage16( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
747 /*******************************************************************
748 * SetDlgItemText32A (USER32.477)
750 void SetDlgItemText32A( HWND32 hwnd
, INT32 id
, LPCSTR lpString
)
752 SendDlgItemMessage32A( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
756 /*******************************************************************
757 * SetDlgItemText32W (USER32.478)
759 void SetDlgItemText32W( HWND32 hwnd
, INT32 id
, LPCWSTR lpString
)
761 SendDlgItemMessage32W( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
765 /***********************************************************************
766 * GetDlgItemText16 (USER.93)
768 INT16
GetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR str
, UINT16 len
)
770 return (INT16
)SendDlgItemMessage16( hwnd
, id
, WM_GETTEXT
,
775 /***********************************************************************
776 * GetDlgItemText32A (USER32.236)
778 INT32
GetDlgItemText32A( HWND32 hwnd
, INT32 id
, LPSTR str
, UINT32 len
)
780 return (INT32
)SendDlgItemMessage32A( hwnd
, id
, WM_GETTEXT
,
785 /***********************************************************************
786 * GetDlgItemText32W (USER32.237)
788 INT32
GetDlgItemText32W( HWND32 hwnd
, INT32 id
, LPWSTR str
, UINT32 len
)
790 return (INT32
)SendDlgItemMessage32W( hwnd
, id
, WM_GETTEXT
,
795 /*******************************************************************
796 * SetDlgItemInt16 (USER.94)
798 void SetDlgItemInt16( HWND16 hwnd
, INT16 id
, UINT16 value
, BOOL16 fSigned
)
800 char *str
= (char *)SEGPTR_ALLOC( 20 * sizeof(char) );
803 if (fSigned
) sprintf( str
, "%d", (INT32
)(INT16
)value
);
804 else sprintf( str
, "%u", value
);
805 SendDlgItemMessage16( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)SEGPTR_GET(str
) );
810 /*******************************************************************
811 * SetDlgItemInt32 (USER32.476)
813 void SetDlgItemInt32( HWND32 hwnd
, INT32 id
, UINT32 value
, BOOL32 fSigned
)
817 if (fSigned
) sprintf( str
, "%d", (INT32
)value
);
818 else sprintf( str
, "%u", value
);
819 SendDlgItemMessage32A( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
823 /***********************************************************************
824 * GetDlgItemInt (USER.95)
826 WORD
GetDlgItemInt( HWND hwnd
, WORD id
, BOOL
* translated
, BOOL fSigned
)
831 if (translated
) *translated
= FALSE
;
832 if (!(str
= (char *)SEGPTR_ALLOC( 30 * sizeof(char) ))) return 0;
833 if (SendDlgItemMessage16( hwnd
, id
, WM_GETTEXT
, 30, (LPARAM
)SEGPTR_GET(str
)))
836 result
= strtol( str
, &endptr
, 10 );
837 if (endptr
&& (endptr
!= str
)) /* Conversion was successful */
841 if ((result
< -32767) || (result
> 32767)) result
= 0;
842 else if (translated
) *translated
= TRUE
;
846 if ((result
< 0) || (result
> 65535)) result
= 0;
847 else if (translated
) *translated
= TRUE
;
856 /***********************************************************************
857 * CheckDlgButton (USER.97)
859 BOOL
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
861 SendDlgItemMessage32A( hwnd
, id
, BM_SETCHECK32
, check
, 0 );
866 /***********************************************************************
867 * IsDlgButtonChecked (USER.98)
869 WORD
IsDlgButtonChecked( HWND hwnd
, WORD id
)
871 return (WORD
)SendDlgItemMessage16( hwnd
, id
, BM_GETCHECK16
, 0, 0 );
875 /***********************************************************************
876 * CheckRadioButton (USER.96)
878 BOOL
CheckRadioButton( HWND hwndDlg
, UINT firstID
, UINT lastID
, UINT checkID
)
880 WND
*pWnd
= WIN_FindWndPtr( hwndDlg
);
881 if (!pWnd
) return FALSE
;
883 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
884 if ((pWnd
->wIDmenu
== firstID
) || (pWnd
->wIDmenu
== lastID
)) break;
885 if (!pWnd
) return FALSE
;
887 if (pWnd
->wIDmenu
== lastID
)
888 lastID
= firstID
; /* Buttons are in reverse order */
891 SendMessage32A( pWnd
->hwndSelf
, BM_SETCHECK32
,
892 (pWnd
->wIDmenu
== checkID
), 0 );
893 if (pWnd
->wIDmenu
== lastID
) break;
900 /***********************************************************************
901 * GetDialogBaseUnits (USER.243)
903 DWORD
GetDialogBaseUnits()
905 return MAKELONG( xBaseUnit
, yBaseUnit
);
909 /***********************************************************************
910 * MapDialogRect16 (USER.103)
912 void MapDialogRect16( HWND16 hwnd
, LPRECT16 rect
)
914 DIALOGINFO
* dlgInfo
;
915 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
917 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
918 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
919 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
920 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
921 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
925 /***********************************************************************
926 * MapDialogRect32 (USER32.381)
928 void MapDialogRect32( HWND32 hwnd
, LPRECT32 rect
)
930 DIALOGINFO
* dlgInfo
;
931 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
933 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
934 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
935 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
936 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
937 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
941 /***********************************************************************
942 * GetNextDlgGroupItem (USER.227)
944 HWND
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
946 WND
*pWnd
, *pWndStart
, *pWndCtrl
, *pWndDlg
;
948 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
949 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
))) return 0;
950 if (pWndCtrl
->parent
!= pWndDlg
) return 0;
952 if (!fPrevious
&& pWndCtrl
->next
) /* Check if next control is in group */
954 if (!(pWndCtrl
->next
->dwStyle
& WS_GROUP
))
955 return pWndCtrl
->next
->hwndSelf
;
958 /* Now we will have to find the start of the group */
960 for (pWnd
= pWndStart
= pWndDlg
->child
; pWnd
; pWnd
= pWnd
->next
)
962 if (pWnd
->dwStyle
& WS_GROUP
) pWndStart
= pWnd
; /* Start of a group */
963 if (pWnd
== pWndCtrl
) break;
966 if (!pWnd
) fprintf(stderr
, "GetNextDlgGroupItem: hwnd not in dialog!\n");
968 /* only case left for forward search: wraparound */
969 if (!fPrevious
) return pWndStart
->hwndSelf
;
971 pWnd
= pWndStart
->next
;
972 while (pWnd
&& (pWnd
!= pWndCtrl
))
974 if (pWnd
->dwStyle
& WS_GROUP
) break;
978 return pWndStart
->hwndSelf
;
982 /***********************************************************************
983 * GetNextDlgTabItem (USER.228)
985 HWND
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
987 WND
*pWnd
, *pWndLast
, *pWndCtrl
, *pWndDlg
;
989 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
990 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
))) return 0;
991 if (pWndCtrl
->parent
!= pWndDlg
) return 0;
994 pWnd
= pWndCtrl
->next
;
997 if (!pWnd
) pWnd
= pWndDlg
->child
;
998 if (pWnd
== pWndCtrl
) break;
999 if ((pWnd
->dwStyle
& WS_TABSTOP
) && (pWnd
->dwStyle
& WS_VISIBLE
))
1002 if (!fPrevious
) break;
1006 return pWndLast
->hwndSelf
;