Release 950109
[wine/multimedia.git] / windows / dialog.c
blobead08ba7e04903fe2fa1142a8c9ca6585bd4e823
1 /*
2 * Dialog functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1993, 1994";
7 */
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include "windows.h"
13 #include "dialog.h"
14 #include "win.h"
15 #include "user.h"
16 #include "message.h"
17 #include "heap.h"
18 #include "stddebug.h"
19 /* #define DEBUG_DIALOG */
20 #include "debug.h"
22 /* Dialog base units */
23 static WORD xBaseUnit = 0, yBaseUnit = 0;
26 /***********************************************************************
27 * DIALOG_Init
29 * Initialisation of the dialog manager.
31 BOOL DIALOG_Init()
33 TEXTMETRIC tm;
34 HDC hdc;
36 /* Calculate the dialog base units */
38 if (!(hdc = GetDC( 0 ))) return FALSE;
39 GetTextMetrics( hdc, &tm );
40 ReleaseDC( 0, hdc );
41 xBaseUnit = tm.tmAveCharWidth;
42 yBaseUnit = tm.tmHeight;
44 /* Dialog units are based on a proportional system font */
45 /* so we adjust them a bit for a fixed font. */
46 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) xBaseUnit = xBaseUnit * 5 / 4;
48 dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
49 xBaseUnit, yBaseUnit );
50 return TRUE;
54 /***********************************************************************
55 * DIALOG_GetFirstTabItem
57 * Return the first item of the dialog that has the WS_TABSTOP style.
59 HWND DIALOG_GetFirstTabItem( HWND hwndDlg )
61 HWND hwnd;
62 WND *wndPtr = WIN_FindWndPtr( hwndDlg );
63 hwnd = wndPtr->hwndChild;
64 while(hwnd)
66 wndPtr = WIN_FindWndPtr( hwnd );
67 if (wndPtr->dwStyle & WS_TABSTOP) break;
68 hwnd = wndPtr->hwndNext;
70 return hwnd;
74 /***********************************************************************
75 * DIALOG_GetControl
77 * Return the class and text of the control pointed to by ptr,
78 * and return a pointer to the next control.
80 static DLGCONTROLHEADER * DIALOG_GetControl( DLGCONTROLHEADER * ptr,
81 char ** class, char ** text )
83 unsigned char * p = (unsigned char *)ptr;
84 p += 14; /* size of control header */
86 if (*p & 0x80)
88 switch(*p++)
90 case 0x80: *class = "BUTTON"; break;
91 case 0x81: *class = "EDIT"; break;
92 case 0x82: *class = "STATIC"; break;
93 case 0x83: *class = "LISTBOX"; break;
94 case 0x84: *class = "SCROLLBAR"; break;
95 case 0x85: *class = "COMBOBOX"; break;
96 default: *class = ""; break;
99 else
101 *class = p;
102 p += strlen(p) + 1;
104 if (*p == 0xff)
106 /* Integer id, not documented (?). Only works for SS_ICON controls */
107 *text = (char *)MAKEINTRESOURCE( p[1] + 256*p[2] );
108 p += 4;
110 else
112 *text = p;
113 p += strlen(p) + 2;
115 return (DLGCONTROLHEADER *)p;
119 /***********************************************************************
120 * DIALOG_ParseTemplate
122 * Fill a DLGTEMPLATE structure from the dialog template, and return
123 * a pointer to the first control.
125 static DLGCONTROLHEADER * DIALOG_ParseTemplate( LPCSTR template,
126 DLGTEMPLATE * result )
128 unsigned char * p = (unsigned char *)template;
130 result->header = (DLGTEMPLATEHEADER *)p;
131 p += 13;
133 result->menuName = p;
134 if (*p == 0xff) p += 3;
135 else p += strlen(p) + 1;
137 if (*p) result->className = p;
138 else result->className = DIALOG_CLASS_NAME;
139 p += strlen(p) + 1;
141 result->caption = p;
142 p += strlen(p) + 1;
144 if (result->header->style & DS_SETFONT)
146 result->pointSize = *(WORD *)p; p += sizeof(WORD);
147 result->faceName = p; p += strlen(p) + 1;
150 return (DLGCONTROLHEADER *)p;
154 /***********************************************************************
155 * DIALOG_DisplayTemplate
157 static void DIALOG_DisplayTemplate( DLGTEMPLATE * result )
159 dprintf_dialog(stddeb, "DIALOG %d, %d, %d, %d\n", result->header->x, result->header->y,
160 result->header->cx, result->header->cy );
161 dprintf_dialog(stddeb, " STYLE %08lx\n", result->header->style );
162 dprintf_dialog(stddeb, " CAPTION '%s'\n", result->caption );
163 dprintf_dialog(stddeb, " CLASS '%s'\n", result->className );
164 if (result->menuName[0] == 0xff)
165 dprintf_dialog(stddeb, " MENU %d\n", result->menuName[1] + 256*result->menuName[2] );
166 else
167 dprintf_dialog(stddeb, " MENU '%s'\n", result->menuName );
168 if (result->header->style & DS_SETFONT)
169 dprintf_dialog(stddeb, " FONT %d,'%s'\n", result->pointSize, result->faceName );
173 /***********************************************************************
174 * CreateDialog (USER.89)
176 HWND CreateDialog( HINSTANCE hInst, LPCSTR dlgTemplate,
177 HWND owner, WNDPROC dlgProc )
179 return CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, 0 );
183 /***********************************************************************
184 * CreateDialogParam (USER.241)
186 HWND CreateDialogParam( HINSTANCE hInst, LPCSTR dlgTemplate,
187 HWND owner, WNDPROC dlgProc, LPARAM param )
189 HWND hwnd = 0;
190 HANDLE hres, hmem;
191 LPCSTR data;
193 dprintf_dialog(stddeb, "CreateDialogParam: %d,'%p',%d,%p,%ld\n",
194 hInst, dlgTemplate, owner, dlgProc, param );
196 /* FIXME: MAKEINTRESOURCE should be replaced by RT_DIALOG */
197 if (!(hres = FindResource( hInst, dlgTemplate, MAKEINTRESOURCE(0x8005) )))
198 return 0;
199 if (!(hmem = LoadResource( hInst, hres ))) return 0;
200 if (!(data = LockResource( hmem ))) hwnd = 0;
201 else hwnd = CreateDialogIndirectParam(hInst, data, owner, dlgProc, param);
202 FreeResource( hmem );
203 return hwnd;
207 /***********************************************************************
208 * CreateDialogIndirect (USER.219)
210 HWND CreateDialogIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
211 HWND owner, WNDPROC dlgProc )
213 return CreateDialogIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
217 /***********************************************************************
218 * CreateDialogIndirectParam (USER.242)
220 HWND CreateDialogIndirectParam( HINSTANCE hInst, LPCSTR dlgTemplate,
221 HWND owner, WNDPROC dlgProc, LPARAM param )
223 HMENU hMenu;
224 HFONT hFont = 0;
225 HWND hwnd, hwndCtrl;
226 RECT rect;
227 WND * wndPtr;
228 int i;
229 DLGTEMPLATE template;
230 DLGCONTROLHEADER * header;
231 DIALOGINFO * dlgInfo;
232 DWORD exStyle = 0;
233 WORD xUnit = xBaseUnit;
234 WORD yUnit = yBaseUnit;
236 /* Parse dialog template */
238 if (!dlgTemplate) return 0;
239 header = DIALOG_ParseTemplate( dlgTemplate, &template );
240 if(debugging_dialog)DIALOG_DisplayTemplate( &template );
242 /* Load menu */
244 switch (template.menuName[0])
246 case 0x00:
247 hMenu = 0;
248 break;
249 case 0xff:
250 hMenu = LoadMenu( hInst, MAKEINTRESOURCE( template.menuName[1] +
251 256*template.menuName[2] ));
252 break;
253 default:
254 hMenu = LoadMenu( hInst, template.menuName );
255 break;
258 /* Create custom font if needed */
260 if (template.header->style & DS_SETFONT)
262 /* The font height must be negative as it is a point size */
263 /* (see CreateFont() documentation in the Windows SDK). */
264 hFont = CreateFont( -template.pointSize, 0, 0, 0, FW_DONTCARE,
265 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
266 DEFAULT_QUALITY, FF_DONTCARE, template.faceName );
267 if (hFont)
269 TEXTMETRIC tm;
270 HFONT oldFont;
271 HDC hdc;
273 hdc = GetDC(0);
274 oldFont = SelectObject( hdc, hFont );
275 GetTextMetrics( hdc, &tm );
276 SelectObject( hdc, oldFont );
277 ReleaseDC( 0, hdc );
278 xUnit = tm.tmAveCharWidth;
279 yUnit = tm.tmHeight;
280 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
281 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
285 /* Create dialog main window */
287 rect.left = rect.top = 0;
288 if (!(template.header->style & DS_ABSALIGN))
289 ClientToScreen( owner, (POINT *)&rect );
290 rect.right = rect.left + template.header->cx * xUnit / 4;
291 rect.bottom = rect.top + template.header->cy * yUnit / 8;
292 if (template.header->style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
293 AdjustWindowRectEx( &rect, template.header->style, hMenu, exStyle );
295 hwnd = CreateWindowEx( exStyle, template.className, template.caption,
296 template.header->style,
297 rect.left + template.header->x * xUnit / 4,
298 rect.top + template.header->y * yUnit / 8,
299 rect.right - rect.left, rect.bottom - rect.top,
300 owner, hMenu, hInst,
301 NULL );
302 if (!hwnd)
304 if (hFont) DeleteObject( hFont );
305 if (hMenu) DestroyMenu( hMenu );
306 return 0;
309 /* Create control windows */
311 dprintf_dialog(stddeb, " BEGIN\n" );
313 wndPtr = WIN_FindWndPtr( hwnd );
314 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
315 dlgInfo->msgResult = 0; /* This is used to store the default button id */
316 dlgInfo->hDialogHeap = 0;
318 for (i = 0; i < template.header->nbItems; i++)
320 DLGCONTROLHEADER * next_header;
321 LPSTR class, text;
322 HWND hwndDefButton = 0;
323 next_header = DIALOG_GetControl( header, &class, &text );
325 dprintf_dialog(stddeb, " %s ", class);
326 if ((int)text & 0xffff0000)
327 dprintf_dialog(stddeb,"'%s'", text);
328 else
329 dprintf_dialog(stddeb,"%4X", (int)text & 0xffff);
330 dprintf_dialog(stddeb," %d, %d, %d, %d, %d, %08lx\n",
331 header->id, header->x, header->y,
332 header->cx, header->cy, header->style );
334 if ((strcmp(class, "EDIT") == 0) &&
335 ((header->style & DS_LOCALEDIT) != DS_LOCALEDIT)) {
336 if (!dlgInfo->hDialogHeap) {
337 dlgInfo->hDialogHeap = GlobalAlloc(GMEM_FIXED, 0x10000);
338 if (!dlgInfo->hDialogHeap) {
339 fprintf(stderr,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
340 continue;
342 HEAP_LocalInit(dlgInfo->hDialogHeap, GlobalLock(dlgInfo->hDialogHeap), 0x10000);
344 header->style |= WS_CHILD;
345 hwndCtrl = CreateWindowEx( WS_EX_NOPARENTNOTIFY,
346 class, text, header->style,
347 header->x * xUnit / 4, header->y * yUnit / 8,
348 header->cx * xUnit / 4, header->cy * yUnit / 8,
349 hwnd, header->id, dlgInfo->hDialogHeap, NULL );
351 else
353 header->style |= WS_CHILD;
354 hwndCtrl = CreateWindowEx( WS_EX_NOPARENTNOTIFY,
355 class, text, header->style,
356 header->x * xUnit / 4, header->y * yUnit / 8,
357 header->cx * xUnit / 4, header->cy * yUnit / 8,
358 hwnd, header->id, hInst, NULL );
360 /* Make the control last one in Z-order, so that controls remain
361 in the order in which they were created */
362 SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
363 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
365 /* Send initialisation messages to the control */
366 if (hFont) SendMessage( hwndCtrl, WM_SETFONT, hFont, 0 );
367 if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
369 /* If there's already a default push-button, set it back */
370 /* to normal and use this one instead. */
371 if (hwndDefButton)
372 SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE);
373 hwndDefButton = hwndCtrl;
374 dlgInfo->msgResult = header->id;
376 header = next_header;
379 dprintf_dialog(stddeb, " END\n" );
381 /* Initialise dialog extra data */
383 dlgInfo->dlgProc = dlgProc;
384 dlgInfo->hUserFont = hFont;
385 dlgInfo->hMenu = hMenu;
386 dlgInfo->xBaseUnit = xUnit;
387 dlgInfo->yBaseUnit = yUnit;
388 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
390 /* Send initialisation messages and set focus */
392 if (dlgInfo->hUserFont)
393 SendMessage( hwnd, WM_SETFONT, dlgInfo->hUserFont, 0 );
394 if (SendMessage( hwnd, WM_INITDIALOG, dlgInfo->hwndFocus, param ))
395 SetFocus( dlgInfo->hwndFocus );
397 return hwnd;
401 /***********************************************************************
402 * DIALOG_DoDialogBox
404 static int DIALOG_DoDialogBox( HWND hwnd, HWND owner )
406 WND * wndPtr;
407 DIALOGINFO * dlgInfo;
408 HANDLE msgHandle;
409 MSG* lpmsg;
410 int retval;
412 /* Owner must be a top-level window */
413 while (owner && GetParent(owner)) owner = GetParent(owner);
414 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
415 if (!(msgHandle = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(MSG)))) return -1;
416 lpmsg = (MSG *) USER_HEAP_ADDR( msgHandle );
417 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
418 EnableWindow( owner, FALSE );
419 ShowWindow( hwnd, SW_SHOW );
421 while (MSG_InternalGetMessage( lpmsg, hwnd, owner,
422 MSGF_DIALOGBOX, PM_REMOVE,
423 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
425 if (!IsDialogMessage( hwnd, lpmsg))
427 TranslateMessage( lpmsg );
428 DispatchMessage( lpmsg );
430 if (dlgInfo->fEnd) break;
432 retval = dlgInfo->msgResult;
433 DestroyWindow( hwnd );
434 USER_HEAP_FREE( msgHandle );
435 EnableWindow( owner, TRUE );
436 return retval;
440 /***********************************************************************
441 * DialogBox (USER.87)
443 int DialogBox( HINSTANCE hInst, LPCSTR dlgTemplate,
444 HWND owner, WNDPROC dlgProc )
446 return DialogBoxParam( hInst, dlgTemplate, owner, dlgProc, 0 );
450 /***********************************************************************
451 * DialogBoxParam (USER.239)
453 int DialogBoxParam( HINSTANCE hInst, LPCSTR dlgTemplate,
454 HWND owner, WNDPROC dlgProc, LPARAM param )
456 HWND hwnd;
458 dprintf_dialog(stddeb, "DialogBoxParam: %d,'%p',%d,%p,%ld\n",
459 hInst, dlgTemplate, owner, dlgProc, param );
460 hwnd = CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, param );
461 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
462 return -1;
466 /***********************************************************************
467 * DialogBoxIndirect (USER.218)
469 int DialogBoxIndirect( HINSTANCE hInst, HANDLE dlgTemplate,
470 HWND owner, WNDPROC dlgProc )
472 return DialogBoxIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
476 /***********************************************************************
477 * DialogBoxIndirectParam (USER.240)
479 int DialogBoxIndirectParam( HINSTANCE hInst, HANDLE dlgTemplate,
480 HWND owner, WNDPROC dlgProc, LPARAM param )
482 HWND hwnd;
483 LPCSTR ptr;
485 if (!(ptr = GlobalLock( dlgTemplate ))) return -1;
486 hwnd = CreateDialogIndirectParam( hInst, ptr, owner, dlgProc, param );
487 GlobalUnlock( dlgTemplate );
488 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
489 return -1;
493 /***********************************************************************
494 * DialogBoxIndirectParamPtr
495 * like DialogBoxIndirectParam, but expects pointer to template
497 int DialogBoxIndirectParamPtr(HINSTANCE hInst,LPCSTR dlgTemplate,
498 HWND owner, WNDPROC dlgProc, LPARAM param)
500 HWND hwnd;
501 hwnd = CreateDialogIndirectParam( hInst, dlgTemplate, owner, dlgProc, param );
502 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
503 return -1;
506 /***********************************************************************
507 * DialogBoxIndirectPtr
508 * like DialogBoxIndirect, but expects pointer to template
510 int DialogBoxIndirectPtr( HINSTANCE hInst, LPCSTR dlgTemplate,
511 HWND owner, WNDPROC dlgProc)
513 return DialogBoxIndirectParamPtr(hInst, dlgTemplate, owner, dlgProc, 0);
516 /***********************************************************************
517 * EndDialog (USER.88)
519 void EndDialog( HWND hwnd, short retval )
521 WND * wndPtr = WIN_FindWndPtr( hwnd );
522 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
523 dlgInfo->msgResult = retval;
524 dlgInfo->fEnd = TRUE;
525 dprintf_dialog(stddeb, "EndDialog: %d %d\n", hwnd, retval );
529 /***********************************************************************
530 * IsDialogMessage (USER.90)
532 BOOL IsDialogMessage( HWND hwndDlg, LPMSG msg )
534 WND * wndPtr;
535 int dlgCode;
537 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return FALSE;
538 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
540 /* Only the key messages get special processing */
541 if ((msg->message != WM_KEYDOWN) &&
542 (msg->message != WM_SYSCHAR) &&
543 (msg->message != WM_CHAR))
544 return FALSE;
546 dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
547 if (dlgCode & DLGC_WANTMESSAGE)
549 DispatchMessage( msg );
550 return TRUE;
553 switch(msg->message)
555 case WM_KEYDOWN:
556 if (dlgCode & DLGC_WANTALLKEYS) break;
557 switch(msg->wParam)
559 case VK_TAB:
560 if (!(dlgCode & DLGC_WANTTAB))
562 SendMessage( hwndDlg, WM_NEXTDLGCTL,
563 (GetKeyState(VK_SHIFT) & 0x80), 0 );
564 return TRUE;
566 break;
568 case VK_RIGHT:
569 case VK_DOWN:
570 if (!(dlgCode & DLGC_WANTARROWS))
572 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),FALSE));
573 return TRUE;
575 break;
577 case VK_LEFT:
578 case VK_UP:
579 if (!(dlgCode & DLGC_WANTARROWS))
581 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),TRUE));
582 return TRUE;
584 break;
586 case VK_ESCAPE:
587 SendMessage( hwndDlg, WM_COMMAND, IDCANCEL,
588 MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
589 break;
591 case VK_RETURN:
593 DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 );
594 if (HIWORD(dw) == DC_HASDEFID)
595 SendMessage( hwndDlg, WM_COMMAND, LOWORD(dw),
596 MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
597 BN_CLICKED ));
598 else
599 SendMessage( hwndDlg, WM_COMMAND, IDOK,
600 MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
602 break;
604 break; /* case WM_KEYDOWN */
607 case WM_CHAR:
608 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
609 break;
611 case WM_SYSCHAR:
612 if (dlgCode & DLGC_WANTALLKEYS) break;
613 break;
616 /* If we get here, the message has not been treated specially */
617 /* and can be sent to its destination window. */
618 DispatchMessage( msg );
619 return TRUE;
623 /****************************************************************
624 * GetDlgCtrlID (USER.277)
626 int GetDlgCtrlID( HWND hwnd )
628 WND *wndPtr = WIN_FindWndPtr(hwnd);
629 if (wndPtr) return wndPtr->wIDmenu;
630 else return 0;
634 /***********************************************************************
635 * GetDlgItem (USER.91)
637 HWND GetDlgItem( HWND hwndDlg, WORD id )
639 HWND curChild;
640 WND * childPtr;
641 WND * wndPtr;
643 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
644 curChild = wndPtr->hwndChild;
645 while(curChild)
647 childPtr = WIN_FindWndPtr( curChild );
648 if (childPtr->wIDmenu == id) return curChild;
649 curChild = childPtr->hwndNext;
651 return 0;
655 /*******************************************************************
656 * SendDlgItemMessage (USER.101)
658 LONG SendDlgItemMessage(HWND hwnd, WORD id, UINT msg, WORD wParam, LONG lParam)
660 HWND hwndCtrl = GetDlgItem( hwnd, id );
661 if (hwndCtrl) return SendMessage( hwndCtrl, msg, wParam, lParam );
662 else return 0;
666 /*******************************************************************
667 * SetDlgItemText (USER.92)
669 void SetDlgItemText( HWND hwnd, WORD id, LPSTR lpString )
671 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (DWORD)lpString );
675 /***********************************************************************
676 * GetDlgItemText (USER.93)
678 int GetDlgItemText( HWND hwnd, WORD id, LPSTR str, WORD max )
680 return (int)SendDlgItemMessage( hwnd, id, WM_GETTEXT, max, (DWORD)str );
684 /*******************************************************************
685 * SetDlgItemInt (USER.94)
687 void SetDlgItemInt( HWND hwnd, WORD id, WORD value, BOOL fSigned )
689 HANDLE hText = USER_HEAP_ALLOC(0, 10 );
690 char * str = (char *) USER_HEAP_ADDR( hText );
692 if (fSigned) sprintf( str, "%d", value );
693 else sprintf( str, "%u", value );
694 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (DWORD)str );
695 USER_HEAP_FREE( hText );
699 /***********************************************************************
700 * GetDlgItemInt (USER.95)
702 WORD GetDlgItemInt( HWND hwnd, WORD id, BOOL * translated, BOOL fSigned )
704 int len;
705 HANDLE hText;
706 long result = 0;
707 char * str;
709 if (translated) *translated = FALSE;
710 if (!(len = SendDlgItemMessage( hwnd, id, WM_GETTEXTLENGTH, 0, 0 )))
711 return 0;
712 if (!(hText = USER_HEAP_ALLOC(0, len+1 )))
713 return 0;
714 str = (char *) USER_HEAP_ADDR( hText );
715 if (SendDlgItemMessage( hwnd, id, WM_GETTEXT, len+1, (DWORD)str ))
717 char * endptr;
718 result = strtol( str, &endptr, 10 );
719 if (endptr && (endptr != str)) /* Conversion was successful */
721 if (fSigned)
723 if ((result < -32767) || (result > 32767)) result = 0;
724 else if (translated) *translated = TRUE;
726 else
728 if ((result < 0) || (result > 65535)) result = 0;
729 else if (translated) *translated = TRUE;
733 USER_HEAP_FREE( hText );
734 return (WORD)result;
738 /***********************************************************************
739 * CheckDlgButton (USER.97)
741 void CheckDlgButton( HWND hwnd, WORD id, WORD check )
743 SendDlgItemMessage( hwnd, id, BM_SETCHECK, check, 0 );
747 /***********************************************************************
748 * IsDlgButtonChecked (USER.98)
750 WORD IsDlgButtonChecked( HWND hwnd, WORD id )
752 return (WORD)SendDlgItemMessage( hwnd, id, BM_GETCHECK, 0, 0 );
756 /***********************************************************************
757 * CheckRadioButton (USER.96)
759 void CheckRadioButton( HWND hwndDlg, WORD firstID, WORD lastID, WORD checkID )
761 HWND button = GetWindow( hwndDlg, GW_CHILD );
762 WND *wndPtr;
764 while (button)
766 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
767 if ((wndPtr->wIDmenu == firstID) || (wndPtr->wIDmenu == lastID)) break;
768 button = wndPtr->hwndNext;
770 if (!button) return;
772 if (wndPtr->wIDmenu == lastID)
773 lastID = firstID; /* Buttons are in reverse order */
774 while (button)
776 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
777 SendMessage( button, BM_SETCHECK, (wndPtr->wIDmenu == checkID), 0 );
778 if (wndPtr->wIDmenu == lastID) break;
779 button = wndPtr->hwndNext;
784 /***********************************************************************
785 * GetDialogBaseUnits (USER.243)
787 DWORD GetDialogBaseUnits()
789 return MAKELONG( xBaseUnit, yBaseUnit );
793 /***********************************************************************
794 * MapDialogRect (USER.103)
796 void MapDialogRect( HWND hwnd, LPRECT rect )
798 DIALOGINFO * dlgInfo;
799 WND * wndPtr = WIN_FindWndPtr( hwnd );
800 if (!wndPtr) return;
801 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
802 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
803 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
804 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
805 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
809 /***********************************************************************
810 * GetNextDlgGroupItem (USER.227)
812 HWND GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
814 HWND hwnd, hwndStart;
815 WND * dlgPtr, * ctrlPtr, * wndPtr;
817 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
818 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
819 if (ctrlPtr->hwndParent != hwndDlg) return 0;
821 if (!fPrevious && ctrlPtr->hwndNext) /*Check if next control is in group*/
823 wndPtr = WIN_FindWndPtr( ctrlPtr->hwndNext );
824 if (!(wndPtr->dwStyle & WS_GROUP)) return ctrlPtr->hwndNext;
827 if (ctrlPtr->dwStyle & WS_GROUP) /* Control is the first of the group */
829 if (!fPrevious) return hwndCtrl; /* Control is alone in his group */
830 hwnd = ctrlPtr->hwndNext;
831 while(hwnd) /* Find last control of the group */
833 wndPtr = WIN_FindWndPtr( hwnd );
834 if (wndPtr->dwStyle & WS_GROUP) break;
835 hwndCtrl = hwnd;
836 hwnd = wndPtr->hwndNext;
838 return hwndCtrl;
841 /* Now we will have to find the start of the group */
843 hwndStart = hwnd = dlgPtr->hwndChild;
844 while (hwnd)
846 wndPtr = WIN_FindWndPtr( hwnd );
847 if (wndPtr->dwStyle & WS_GROUP) hwndStart = hwnd; /*Start of a group*/
848 if (hwnd == hwndCtrl)
850 /* We found the control -> hwndStart is the first of the group */
851 if (!fPrevious) return hwndStart;
853 while(hwndStart) /* Find the control placed before hwndCtrl */
855 wndPtr = WIN_FindWndPtr( hwndStart );
856 if (wndPtr->hwndNext == hwndCtrl) return hwndStart;
857 hwndStart = wndPtr->hwndNext;
859 break;
861 hwnd = wndPtr->hwndNext;
863 return hwndCtrl; /* Not found -> return original control */
867 /***********************************************************************
868 * GetNextDlgTabItem (USER.228)
870 HWND GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
872 HWND hwnd, hwndLast;
873 WND * dlgPtr, * ctrlPtr, * wndPtr;
875 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
876 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
877 if (ctrlPtr->hwndParent != hwndDlg) return 0;
879 hwndLast = hwndCtrl;
880 hwnd = ctrlPtr->hwndNext;
881 while (1)
883 if (!hwnd) hwnd = dlgPtr->hwndChild;
884 if (hwnd == hwndCtrl) break;
885 wndPtr = WIN_FindWndPtr( hwnd );
886 if (wndPtr->dwStyle & WS_TABSTOP)
888 hwndLast = hwnd;
889 if (!fPrevious) break;
891 hwnd = wndPtr->hwndNext;
893 return hwndLast;