Release 951003
[wine/multimedia.git] / windows / dialog.c
blob8dc29c4be2ed054b669d9228cfda925e68c7c4c3
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 "ldt.h"
16 #include "stackframe.h"
17 #include "user.h"
18 #include "message.h"
19 #include "stddebug.h"
20 /* #define DEBUG_DIALOG */
21 #include "debug.h"
23 /* Dialog base units */
24 static WORD xBaseUnit = 0, yBaseUnit = 0;
27 /***********************************************************************
28 * DIALOG_Init
30 * Initialisation of the dialog manager.
32 BOOL DIALOG_Init()
34 TEXTMETRIC tm;
35 HDC hdc;
37 /* Calculate the dialog base units */
39 if (!(hdc = GetDC( 0 ))) return FALSE;
40 GetTextMetrics( hdc, &tm );
41 ReleaseDC( 0, hdc );
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 );
51 return TRUE;
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 HWND hwnd;
63 WND *wndPtr = WIN_FindWndPtr( hwndDlg );
64 hwnd = wndPtr->hwndChild;
65 while(hwnd)
67 wndPtr = WIN_FindWndPtr( hwnd );
68 if (wndPtr->dwStyle & WS_TABSTOP) break;
69 hwnd = wndPtr->hwndNext;
71 return hwnd;
75 /***********************************************************************
76 * DIALOG_GetControl
78 * Return the class and text of the control pointed to by ptr,
79 * and return a pointer to the next control.
81 static SEGPTR DIALOG_GetControl( SEGPTR ptr, SEGPTR *class, SEGPTR *text )
83 unsigned char *base = (unsigned char *)PTR_SEG_TO_LIN( ptr );
84 unsigned char *p = base;
86 p += 14; /* size of control header */
88 if (*p & 0x80)
90 *class = MAKEINTRESOURCE( *p );
91 p++;
93 else
95 *class = ptr + (WORD)(p - base);
96 p += strlen(p) + 1;
99 if (*p == 0xff)
101 /* Integer id, not documented (?). Only works for SS_ICON controls */
102 *text = MAKEINTRESOURCE( p[1] + 256 * p[2] );
103 p += 4;
105 else
107 *text = ptr + (WORD)(p - base);
108 p += strlen(p) + 2;
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->header = *(DLGTEMPLATEHEADER *)p;
126 p += 13;
128 /* Get the menu name */
130 if (*p == 0xff)
132 result->menuName = MAKEINTRESOURCE( p[1] + 256 * p[2] );
133 p += 3;
135 else if (*p)
137 result->menuName = template + (WORD)(p - base);
138 p += strlen(p) + 1;
140 else
142 result->menuName = 0;
143 p++;
146 /* Get the class name */
148 if (*p) result->className = template + (WORD)(p - base);
149 else result->className = DIALOG_CLASS_ATOM;
150 p += strlen(p) + 1;
152 /* Get the window caption */
154 result->caption = template + (WORD)(p - base);
155 p += strlen(p) + 1;
157 /* Get the font name */
159 if (result->header.style & DS_SETFONT)
161 result->pointSize = *(WORD *)p;
162 p += sizeof(WORD);
163 result->faceName = template + (WORD)(p - base);
164 p += strlen(p) + 1;
167 return template + (WORD)(p - base);
171 /***********************************************************************
172 * DIALOG_DisplayTemplate
174 static void DIALOG_DisplayTemplate( DLGTEMPLATE * result )
176 dprintf_dialog(stddeb, "DIALOG %d, %d, %d, %d\n", result->header.x, result->header.y,
177 result->header.cx, result->header.cy );
178 dprintf_dialog(stddeb, " STYLE %08lx\n", result->header.style );
179 dprintf_dialog( stddeb, " CAPTION '%s'\n",
180 (char *)PTR_SEG_TO_LIN(result->caption) );
182 if (HIWORD(result->className))
183 dprintf_dialog( stddeb, " CLASS '%s'\n",
184 (char *)PTR_SEG_TO_LIN(result->className) );
185 else
186 dprintf_dialog( stddeb, " CLASS #%d\n", LOWORD(result->className) );
188 if (HIWORD(result->menuName))
189 dprintf_dialog( stddeb, " MENU '%s'\n",
190 (char *)PTR_SEG_TO_LIN(result->menuName) );
191 else if (LOWORD(result->menuName))
192 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
194 if (result->header.style & DS_SETFONT)
195 dprintf_dialog( stddeb, " FONT %d,'%s'\n", result->pointSize,
196 (char *)PTR_SEG_TO_LIN(result->faceName) );
200 /***********************************************************************
201 * CreateDialog (USER.89)
203 HWND CreateDialog( HINSTANCE hInst, SEGPTR dlgTemplate,
204 HWND owner, WNDPROC dlgProc )
206 return CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, 0 );
210 /***********************************************************************
211 * CreateDialogParam (USER.241)
213 HWND CreateDialogParam( HINSTANCE hInst, SEGPTR dlgTemplate,
214 HWND owner, WNDPROC dlgProc, LPARAM param )
216 HWND hwnd = 0;
217 HRSRC hRsrc;
218 HGLOBAL hmem;
219 SEGPTR data;
221 dprintf_dialog(stddeb, "CreateDialogParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
222 hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
224 if (!(hRsrc = FindResource( hInst, dlgTemplate, RT_DIALOG ))) return 0;
225 if (!(hmem = LoadResource( hInst, hRsrc ))) return 0;
226 if (!(data = WIN16_LockResource( hmem ))) hwnd = 0;
227 else hwnd = CreateDialogIndirectParam(hInst, data, owner, dlgProc, param);
228 FreeResource( hmem );
229 return hwnd;
233 /***********************************************************************
234 * CreateDialogIndirect (USER.219)
236 HWND CreateDialogIndirect( HINSTANCE hInst, SEGPTR dlgTemplate,
237 HWND owner, WNDPROC dlgProc )
239 return CreateDialogIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
243 /***********************************************************************
244 * CreateDialogIndirectParam (USER.242)
246 HWND CreateDialogIndirectParam( HINSTANCE hInst, SEGPTR dlgTemplate,
247 HWND owner, WNDPROC dlgProc, LPARAM param )
249 HMENU hMenu = 0;
250 HFONT hFont = 0;
251 HWND hwnd, hwndCtrl;
252 RECT rect;
253 WND * wndPtr;
254 int i;
255 DLGTEMPLATE template;
256 SEGPTR headerPtr;
257 DIALOGINFO * dlgInfo;
258 DWORD exStyle = 0;
259 WORD xUnit = xBaseUnit;
260 WORD yUnit = yBaseUnit;
262 /* Parse dialog template */
264 if (!dlgTemplate) return 0;
265 headerPtr = DIALOG_ParseTemplate( dlgTemplate, &template );
266 if (debugging_dialog) DIALOG_DisplayTemplate( &template );
268 /* Load menu */
270 if (template.menuName) hMenu = LoadMenu( hInst, template.menuName );
272 /* Create custom font if needed */
274 if (template.header.style & DS_SETFONT)
276 /* The font height must be negative as it is a point size */
277 /* (see CreateFont() documentation in the Windows SDK). */
278 hFont = CreateFont( -template.pointSize, 0, 0, 0, FW_DONTCARE,
279 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
280 DEFAULT_QUALITY, FF_DONTCARE,
281 (LPSTR)PTR_SEG_TO_LIN(template.faceName) );
282 if (hFont)
284 TEXTMETRIC tm;
285 HFONT oldFont;
286 HDC hdc;
288 hdc = GetDC(0);
289 oldFont = SelectObject( hdc, hFont );
290 GetTextMetrics( hdc, &tm );
291 SelectObject( hdc, oldFont );
292 ReleaseDC( 0, hdc );
293 xUnit = tm.tmAveCharWidth;
294 yUnit = tm.tmHeight;
295 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
296 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
300 /* Create dialog main window */
302 rect.left = rect.top = 0;
303 rect.right = template.header.cx * xUnit / 4;
304 rect.bottom = template.header.cy * yUnit / 8;
305 if (template.header.style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
306 AdjustWindowRectEx( &rect, template.header.style,
307 hMenu ? TRUE : FALSE , exStyle );
308 rect.right -= rect.left;
309 rect.bottom -= rect.top;
311 if ((INT)template.header.x == CW_USEDEFAULT)
312 rect.left = rect.top = CW_USEDEFAULT;
313 else
315 rect.left += template.header.x * xUnit / 4;
316 rect.top += template.header.y * yUnit / 8;
317 if (!(template.header.style & DS_ABSALIGN))
318 ClientToScreen( owner, (POINT *)&rect );
321 hwnd = CreateWindowEx( exStyle, template.className, template.caption,
322 template.header.style & ~WS_VISIBLE,
323 rect.left, rect.top, rect.right, rect.bottom,
324 owner, hMenu, hInst, (SEGPTR)0 );
325 if (!hwnd)
327 if (hFont) DeleteObject( hFont );
328 if (hMenu) DestroyMenu( hMenu );
329 return 0;
332 /* Create control windows */
334 dprintf_dialog(stddeb, " BEGIN\n" );
336 wndPtr = WIN_FindWndPtr( hwnd );
337 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
338 dlgInfo->msgResult = 0; /* This is used to store the default button id */
339 dlgInfo->hDialogHeap = 0;
341 for (i = 0; i < template.header.nbItems; i++)
343 DLGCONTROLHEADER *header;
344 SEGPTR className, winName;
345 HWND hwndDefButton = 0;
346 char buffer[10];
348 header = (DLGCONTROLHEADER *)PTR_SEG_TO_LIN( headerPtr );
349 headerPtr = DIALOG_GetControl( headerPtr, &className, &winName );
351 if (!HIWORD(className))
353 switch(LOWORD(className))
355 case 0x80: strcpy( buffer, "BUTTON" ); break;
356 case 0x81: strcpy( buffer, "EDIT" ); break;
357 case 0x82: strcpy( buffer, "STATIC" ); break;
358 case 0x83: strcpy( buffer, "LISTBOX" ); break;
359 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
360 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
361 default: buffer[0] = '\0'; break;
363 className = MAKE_SEGPTR(buffer);
366 if (HIWORD(className))
367 dprintf_dialog(stddeb, " %s ", (char*)PTR_SEG_TO_LIN(className));
368 else dprintf_dialog(stddeb, " %04x ", LOWORD(className) );
369 if (HIWORD(winName))
370 dprintf_dialog(stddeb,"'%s'", (char *)PTR_SEG_TO_LIN(winName) );
371 else dprintf_dialog(stddeb,"%04x", LOWORD(winName) );
373 dprintf_dialog(stddeb," %d, %d, %d, %d, %d, %08lx\n",
374 header->id, header->x, header->y,
375 header->cx, header->cy, header->style );
377 if (HIWORD(className) &&
378 !strcmp( (char *)PTR_SEG_TO_LIN(className), "EDIT") &&
379 ((header->style & DS_LOCALEDIT) != DS_LOCALEDIT))
381 if (!dlgInfo->hDialogHeap)
383 dlgInfo->hDialogHeap = GlobalAlloc(GMEM_FIXED, 0x10000);
384 if (!dlgInfo->hDialogHeap)
386 fprintf(stderr,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
387 continue;
389 LocalInit(dlgInfo->hDialogHeap, 0, 0xffff);
391 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
392 header->style | WS_CHILD,
393 header->x * xUnit / 4,
394 header->y * yUnit / 8,
395 header->cx * xUnit / 4,
396 header->cy * yUnit / 8,
397 hwnd, (HMENU)header->id,
398 dlgInfo->hDialogHeap, (SEGPTR)0 );
400 else
402 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
403 header->style | WS_CHILD,
404 header->x * xUnit / 4,
405 header->y * yUnit / 8,
406 header->cx * xUnit / 4,
407 header->cy * yUnit / 8,
408 hwnd, (HMENU)header->id,
409 hInst, (SEGPTR)0 );
412 /* Make the control last one in Z-order, so that controls remain
413 in the order in which they were created */
414 SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
415 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
417 /* Send initialisation messages to the control */
418 if (hFont) SendMessage( hwndCtrl, WM_SETFONT, (WPARAM)hFont, 0 );
419 if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
421 /* If there's already a default push-button, set it back */
422 /* to normal and use this one instead. */
423 if (hwndDefButton)
424 SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE);
425 hwndDefButton = hwndCtrl;
426 dlgInfo->msgResult = GetWindowWord( hwndCtrl, GWW_ID );
430 dprintf_dialog(stddeb, " END\n" );
432 /* Initialise dialog extra data */
434 dlgInfo->dlgProc = dlgProc;
435 dlgInfo->hUserFont = hFont;
436 dlgInfo->hMenu = hMenu;
437 dlgInfo->xBaseUnit = xUnit;
438 dlgInfo->yBaseUnit = yUnit;
439 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
441 /* Send initialisation messages and set focus */
443 if (dlgInfo->hUserFont)
444 SendMessage( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
445 if (SendMessage( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
446 SetFocus( dlgInfo->hwndFocus );
447 if (template.header.style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
448 return hwnd;
452 /***********************************************************************
453 * DIALOG_DoDialogBox
455 static int DIALOG_DoDialogBox( HWND hwnd, HWND owner )
457 WND * wndPtr;
458 DIALOGINFO * dlgInfo;
459 HANDLE msgHandle;
460 MSG* lpmsg;
461 int retval;
463 /* Owner must be a top-level window */
464 owner = WIN_GetTopParent( owner );
465 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
466 if (!(msgHandle = USER_HEAP_ALLOC( sizeof(MSG) ))) return -1;
467 lpmsg = (MSG *) USER_HEAP_LIN_ADDR( msgHandle );
468 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
469 EnableWindow( owner, FALSE );
470 ShowWindow( hwnd, SW_SHOW );
472 while (MSG_InternalGetMessage( USER_HEAP_SEG_ADDR(msgHandle), hwnd, owner,
473 MSGF_DIALOGBOX, PM_REMOVE,
474 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
476 if (!IsDialogMessage( hwnd, lpmsg))
478 TranslateMessage( lpmsg );
479 DispatchMessage( lpmsg );
481 if (dlgInfo->fEnd) break;
483 retval = dlgInfo->msgResult;
484 DestroyWindow( hwnd );
485 USER_HEAP_FREE( msgHandle );
486 EnableWindow( owner, TRUE );
487 return retval;
491 /***********************************************************************
492 * DialogBox (USER.87)
494 int DialogBox( HINSTANCE hInst, SEGPTR dlgTemplate,
495 HWND owner, WNDPROC dlgProc )
497 return DialogBoxParam( hInst, dlgTemplate, owner, dlgProc, 0 );
501 /***********************************************************************
502 * DialogBoxParam (USER.239)
504 int DialogBoxParam( HINSTANCE hInst, SEGPTR dlgTemplate,
505 HWND owner, WNDPROC dlgProc, LPARAM param )
507 HWND hwnd;
509 dprintf_dialog(stddeb, "DialogBoxParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
510 hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
511 hwnd = CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, param );
512 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
513 return -1;
517 /***********************************************************************
518 * DialogBoxIndirect (USER.218)
520 int DialogBoxIndirect( HINSTANCE hInst, HANDLE dlgTemplate,
521 HWND owner, WNDPROC dlgProc )
523 return DialogBoxIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
527 /***********************************************************************
528 * DialogBoxIndirectParam (USER.240)
530 int DialogBoxIndirectParam( HINSTANCE hInst, HANDLE dlgTemplate,
531 HWND owner, WNDPROC dlgProc, LPARAM param )
533 HWND hwnd;
534 SEGPTR ptr;
536 if (!(ptr = (SEGPTR)WIN16_GlobalLock( dlgTemplate ))) return -1;
537 hwnd = CreateDialogIndirectParam( hInst, ptr, owner, dlgProc, param );
538 GlobalUnlock( dlgTemplate );
539 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
540 return -1;
544 /***********************************************************************
545 * EndDialog (USER.88)
547 void EndDialog( HWND hwnd, short retval )
549 WND * wndPtr = WIN_FindWndPtr( hwnd );
550 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
551 dlgInfo->msgResult = retval;
552 dlgInfo->fEnd = TRUE;
553 dprintf_dialog(stddeb, "EndDialog: "NPFMT" %d\n", hwnd, retval );
557 /***********************************************************************
558 * IsDialogMessage (USER.90)
560 BOOL IsDialogMessage( HWND hwndDlg, LPMSG msg )
562 WND * wndPtr;
563 int dlgCode;
565 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return FALSE;
566 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
568 /* Only the key messages get special processing */
569 if ((msg->message != WM_KEYDOWN) &&
570 (msg->message != WM_SYSCHAR) &&
571 (msg->message != WM_CHAR))
572 return FALSE;
574 dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
575 if (dlgCode & DLGC_WANTMESSAGE)
577 DispatchMessage( msg );
578 return TRUE;
581 switch(msg->message)
583 case WM_KEYDOWN:
584 if (dlgCode & DLGC_WANTALLKEYS) break;
585 switch(msg->wParam)
587 case VK_TAB:
588 if (!(dlgCode & DLGC_WANTTAB))
590 SendMessage( hwndDlg, WM_NEXTDLGCTL,
591 (GetKeyState(VK_SHIFT) & 0x80), 0 );
592 return TRUE;
594 break;
596 case VK_RIGHT:
597 case VK_DOWN:
598 if (!(dlgCode & DLGC_WANTARROWS))
600 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),FALSE));
601 return TRUE;
603 break;
605 case VK_LEFT:
606 case VK_UP:
607 if (!(dlgCode & DLGC_WANTARROWS))
609 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),TRUE));
610 return TRUE;
612 break;
614 case VK_ESCAPE:
615 #ifdef WINELIB32
616 SendMessage( hwndDlg, WM_COMMAND,
617 MAKEWPARAM( IDCANCEL, 0 ),
618 (LPARAM)GetDlgItem(hwndDlg,IDCANCEL) );
619 #else
620 SendMessage( hwndDlg, WM_COMMAND, IDCANCEL,
621 MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
622 #endif
623 break;
625 case VK_RETURN:
627 DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 );
628 if (HIWORD(dw) == DC_HASDEFID)
629 #ifdef WINELIB32
630 SendMessage( hwndDlg, WM_COMMAND,
631 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
632 (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ) );
633 else
634 SendMessage( hwndDlg, WM_COMMAND,
635 MAKEWPARAM( IDOK, 0 ),
636 (LPARAM)GetDlgItem(hwndDlg,IDOK) );
637 #else
638 SendMessage( hwndDlg, WM_COMMAND, LOWORD(dw),
639 MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
640 BN_CLICKED ));
641 else
642 SendMessage( hwndDlg, WM_COMMAND, IDOK,
643 MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
644 #endif
646 break;
648 break; /* case WM_KEYDOWN */
651 case WM_CHAR:
652 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
653 break;
655 case WM_SYSCHAR:
656 if (dlgCode & DLGC_WANTALLKEYS) break;
657 break;
660 /* If we get here, the message has not been treated specially */
661 /* and can be sent to its destination window. */
662 DispatchMessage( msg );
663 return TRUE;
667 /****************************************************************
668 * GetDlgCtrlID (USER.277)
670 int GetDlgCtrlID( HWND hwnd )
672 WND *wndPtr = WIN_FindWndPtr(hwnd);
673 if (wndPtr) return wndPtr->wIDmenu;
674 else return 0;
678 /***********************************************************************
679 * GetDlgItem (USER.91)
681 HWND GetDlgItem( HWND hwndDlg, WORD id )
683 HWND curChild;
684 WND * childPtr;
685 WND * wndPtr;
687 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
688 curChild = wndPtr->hwndChild;
689 while(curChild)
691 childPtr = WIN_FindWndPtr( curChild );
692 if (childPtr->wIDmenu == id) return curChild;
693 curChild = childPtr->hwndNext;
695 return 0;
699 /*******************************************************************
700 * SendDlgItemMessage (USER.101)
702 LRESULT SendDlgItemMessage(HWND hwnd, INT id, UINT msg, WPARAM wParam, LPARAM lParam)
704 HWND hwndCtrl = GetDlgItem( hwnd, id );
705 if (hwndCtrl) return SendMessage( hwndCtrl, msg, wParam, lParam );
706 else return 0;
710 /*******************************************************************
711 * SetDlgItemText (USER.92)
713 void SetDlgItemText( HWND hwnd, WORD id, SEGPTR lpString )
715 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (DWORD)lpString );
719 /***********************************************************************
720 * GetDlgItemText (USER.93)
722 int GetDlgItemText( HWND hwnd, WORD id, SEGPTR str, WORD max )
724 return (int)SendDlgItemMessage( hwnd, id, WM_GETTEXT, max, (DWORD)str );
728 /*******************************************************************
729 * SetDlgItemInt (USER.94)
731 void SetDlgItemInt( HWND hwnd, WORD id, WORD value, BOOL fSigned )
733 char str[20];
735 if (fSigned) sprintf( str, "%d", (int)value );
736 else sprintf( str, "%u", value );
737 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, MAKE_SEGPTR(str) );
741 /***********************************************************************
742 * GetDlgItemInt (USER.95)
744 WORD GetDlgItemInt( HWND hwnd, WORD id, BOOL * translated, BOOL fSigned )
746 char str[30];
747 long result = 0;
749 if (translated) *translated = FALSE;
750 if (SendDlgItemMessage( hwnd, id, WM_GETTEXT, 30, MAKE_SEGPTR(str) ))
752 char * endptr;
753 result = strtol( str, &endptr, 10 );
754 if (endptr && (endptr != str)) /* Conversion was successful */
756 if (fSigned)
758 if ((result < -32767) || (result > 32767)) result = 0;
759 else if (translated) *translated = TRUE;
761 else
763 if ((result < 0) || (result > 65535)) result = 0;
764 else if (translated) *translated = TRUE;
768 return (WORD)result;
772 /***********************************************************************
773 * CheckDlgButton (USER.97)
775 void CheckDlgButton( HWND hwnd, WORD id, WORD check )
777 SendDlgItemMessage( hwnd, id, BM_SETCHECK, check, 0 );
781 /***********************************************************************
782 * IsDlgButtonChecked (USER.98)
784 WORD IsDlgButtonChecked( HWND hwnd, WORD id )
786 return (WORD)SendDlgItemMessage( hwnd, id, BM_GETCHECK, 0, 0 );
790 /***********************************************************************
791 * CheckRadioButton (USER.96)
793 void CheckRadioButton( HWND hwndDlg, WORD firstID, WORD lastID, WORD checkID )
795 HWND button = GetWindow( hwndDlg, GW_CHILD );
796 WND *wndPtr;
798 while (button)
800 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
801 if ((wndPtr->wIDmenu == firstID) || (wndPtr->wIDmenu == lastID)) break;
802 button = wndPtr->hwndNext;
804 if (!button) return;
806 if (wndPtr->wIDmenu == lastID)
807 lastID = firstID; /* Buttons are in reverse order */
808 while (button)
810 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
811 SendMessage( button, BM_SETCHECK, (wndPtr->wIDmenu == checkID), 0 );
812 if (wndPtr->wIDmenu == lastID) break;
813 button = wndPtr->hwndNext;
818 /***********************************************************************
819 * GetDialogBaseUnits (USER.243)
821 DWORD GetDialogBaseUnits()
823 return MAKELONG( xBaseUnit, yBaseUnit );
827 /***********************************************************************
828 * MapDialogRect (USER.103)
830 void MapDialogRect( HWND hwnd, LPRECT rect )
832 DIALOGINFO * dlgInfo;
833 WND * wndPtr = WIN_FindWndPtr( hwnd );
834 if (!wndPtr) return;
835 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
836 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
837 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
838 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
839 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
843 /***********************************************************************
844 * GetNextDlgGroupItem (USER.227)
846 HWND GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
848 HWND hwnd, hwndStart;
849 WND * dlgPtr, * ctrlPtr, * wndPtr;
851 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
852 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
853 if (ctrlPtr->hwndParent != hwndDlg) return 0;
855 if (!fPrevious && ctrlPtr->hwndNext) /*Check if next control is in group*/
857 wndPtr = WIN_FindWndPtr( ctrlPtr->hwndNext );
858 if (!(wndPtr->dwStyle & WS_GROUP)) return ctrlPtr->hwndNext;
861 /* Now we will have to find the start of the group */
863 hwndStart = hwnd = dlgPtr->hwndChild;
864 while (hwnd)
866 wndPtr = WIN_FindWndPtr( hwnd );
867 if (wndPtr->dwStyle & WS_GROUP) hwndStart = hwnd; /*Start of a group*/
868 if (hwnd == hwndCtrl) break;
869 hwnd = wndPtr->hwndNext;
872 if (!hwnd) fprintf(stderr, "GetNextDlgGroupItem: hwnd not in dialog!\n");
874 /* only case left for forward search: wraparound */
875 if (!fPrevious) return hwndStart;
877 hwnd = hwndStart;
878 wndPtr = WIN_FindWndPtr( hwnd );
879 hwnd = wndPtr->hwndNext;
880 while (hwnd && (hwnd != hwndCtrl))
882 wndPtr = WIN_FindWndPtr( hwnd );
883 if (wndPtr->dwStyle & WS_GROUP) break;
884 hwndStart = hwnd;
885 hwnd = wndPtr->hwndNext;
887 return hwndStart;
891 /***********************************************************************
892 * GetNextDlgTabItem (USER.228)
894 HWND GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
896 HWND hwnd, hwndLast;
897 WND * dlgPtr, * ctrlPtr, * wndPtr;
899 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
900 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
901 if (ctrlPtr->hwndParent != hwndDlg) return 0;
903 hwndLast = hwndCtrl;
904 hwnd = ctrlPtr->hwndNext;
905 while (1)
907 if (!hwnd) hwnd = dlgPtr->hwndChild;
908 if (hwnd == hwndCtrl) break;
909 wndPtr = WIN_FindWndPtr( hwnd );
910 if ((wndPtr->dwStyle & WS_TABSTOP) && (wndPtr->dwStyle & WS_VISIBLE))
912 hwndLast = hwnd;
913 if (!fPrevious) break;
915 hwnd = wndPtr->hwndNext;
917 return hwndLast;