source: trunk/src/user32/windlg.cpp@ 1036

Last change on this file since 1036 was 949, checked in by sandervl, 26 years ago

Moved new user32 here

File size: 20.0 KB
Line 
1/* $Id: windlg.cpp,v 1.1 1999-09-15 23:19:02 sandervl Exp $ */
2/*
3 * Win32 dialog apis for OS/2
4 *
5 * Copyright 1999 Sander van Leeuwen
6 *
7 * Parts based on Wine code (990815; window\dialog.c)
8 *
9 * Copyright 1993, 1994, 1996 Alexandre Julliard
10 *
11 * Project Odin Software License can be found in LICENSE.TXT
12 *
13 */
14#include <ctype.h>
15#include <wchar.h>
16#include <os2win.h>
17#include <misc.h>
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include "win32wbase.h"
22#include "win32dlg.h"
23#include <heapstring.h>
24#include <win\drive.h>
25
26static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
27static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
28static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len, INT id, BOOL win32, BOOL unicode, BOOL combo );
29
30//******************************************************************************
31//******************************************************************************
32HWND WIN32API CreateDialogParamA(HINSTANCE hInst, LPCSTR lpszTemplate,
33 HWND hwndOwner, DLGPROC dlgproc,
34 LPARAM lParamInit)
35{
36 HANDLE hrsrc = FindResourceA( hInst, lpszTemplate, RT_DIALOGA );
37
38 if (!hrsrc)
39 return 0;
40
41 return CreateDialogIndirectParamA(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
42 hwndOwner, dlgproc, lParamInit);
43}
44//******************************************************************************
45//******************************************************************************
46HWND WIN32API CreateDialogParamW(HINSTANCE hInst, LPCWSTR lpszTemplate,
47 HWND hwndOwner, DLGPROC dlgproc,
48 LPARAM lParamInit)
49{
50 HANDLE hrsrc = FindResourceW( hInst, lpszTemplate, RT_DIALOGW );
51
52 if (!hrsrc)
53 return 0;
54
55 return CreateDialogIndirectParamW(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
56 hwndOwner, dlgproc, lParamInit);
57}
58//******************************************************************************
59//******************************************************************************
60HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hInst,
61 DLGTEMPLATE *dlgtemplate,
62 HWND hwndParent, DLGPROC dlgproc,
63 LPARAM lParamInit)
64{
65 Win32Dialog *dialog;
66
67 dprintf(("CreateDialogIndirectParamA: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
68
69 if (!dlgtemplate) return 0;
70
71 dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, FALSE);
72
73 if(dialog == NULL)
74 {
75 dprintf(("Win32Dialog creation failed!!"));
76 return 0;
77 }
78 if(GetLastError() != 0)
79 {
80 dprintf(("Win32Dialog error found!!"));
81 delete dialog;
82 return 0;
83 }
84 return dialog->getWindowHandle();
85}
86//******************************************************************************
87//******************************************************************************
88HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hInst,
89 DLGTEMPLATE *dlgtemplate,
90 HWND hwndParent, DLGPROC dlgproc,
91 LPARAM lParamInit)
92{
93 Win32Dialog *dialog;
94
95 dprintf(("CreateDialogIndirectParamW: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
96
97 if (!dlgtemplate) return 0;
98
99 dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, TRUE);
100
101 if(dialog == NULL)
102 {
103 dprintf(("Win32Dialog creation failed!!"));
104 return 0;
105 }
106 if(GetLastError() != 0)
107 {
108 dprintf(("Win32Dialog error found!!"));
109 delete dialog;
110 return 0;
111 }
112 return dialog->getWindowHandle();
113}
114//******************************************************************************
115//******************************************************************************
116INT WIN32API DialogBoxIndirectParamA(HINSTANCE hInst,
117 DLGTEMPLATE *dlgtemplate,
118 HWND hwndParent, DLGPROC dlgproc,
119 LPARAM lParamInit)
120{
121 HWND hwnd = CreateDialogIndirectParamA(hInst, dlgtemplate, hwndParent, dlgproc,
122 lParamInit);
123 if (hwnd)
124 {
125 Win32Dialog *dialog;
126
127 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
128 if(!dialog || !dialog->IsDialog()) {
129 dprintf(("DialogBoxIndirectParamA, dialog %x not found", hwnd));
130 return 0;
131 }
132 return dialog->doDialogBox();
133 }
134 return -1;
135}
136//******************************************************************************
137//******************************************************************************
138INT WIN32API DialogBoxIndirectParamW(HINSTANCE hInst, DLGTEMPLATE *dlgtemplate,
139 HWND hwndParent, DLGPROC dlgproc,
140 LPARAM lParamInit)
141{
142 HWND hwnd = CreateDialogIndirectParamW(hInst, dlgtemplate, hwndParent, dlgproc,
143 lParamInit);
144 if (hwnd)
145 {
146 Win32Dialog *dialog;
147
148 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
149 if(!dialog || !dialog->IsDialog()) {
150 dprintf(("DialogBoxIndirectParamW, dialog %x not found", hwnd));
151 return 0;
152 }
153 return dialog->doDialogBox();
154 }
155 return -1;
156}
157//******************************************************************************
158//******************************************************************************
159int WIN32API DialogBoxParamA(HINSTANCE hInst, LPCSTR lpszTemplate, HWND hwndOwner,
160 DLGPROC dlgproc, LPARAM lParamInit)
161{
162 HWND hwnd = CreateDialogParamA( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
163
164 if (hwnd)
165 {
166 Win32Dialog *dialog;
167
168 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
169 if(!dialog || !dialog->IsDialog()) {
170 dprintf(("DialogBoxParamA, dialog %x not found", hwnd));
171 return 0;
172 }
173 return dialog->doDialogBox();
174 }
175 return -1;
176}
177//******************************************************************************
178//******************************************************************************
179int WIN32API DialogBoxParamW(HINSTANCE hInst, LPCWSTR lpszTemplate, HWND hwndOwner,
180 DLGPROC dlgproc, LPARAM lParamInit)
181{
182 HWND hwnd = CreateDialogParamW( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
183
184 if (hwnd)
185 {
186 Win32Dialog *dialog;
187
188 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
189 if(!dialog || !dialog->IsDialog()) {
190 dprintf(("DialogBoxParamW, dialog %x not found", hwnd));
191 return 0;
192 }
193 return dialog->doDialogBox();
194 }
195 return -1;
196}
197//******************************************************************************
198//******************************************************************************
199BOOL WIN32API IsDlgButtonChecked( HWND hwnd, UINT id)
200{
201 dprintf(("USER32: IsDlgButtonChecked\n"));
202 //CB: get button state
203 return (BOOL)SendDlgItemMessageA(hwnd, id,BM_GETCHECK,0,0);
204}
205//******************************************************************************
206//******************************************************************************
207HWND WIN32API GetNextDlgTabItem(HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
208{
209 Win32Dialog *dialog;
210
211 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwndDlg);
212 if(!dialog || !dialog->IsDialog()) {
213 dprintf(("GetNextDlgTabItem, window %x not found", hwndDlg));
214 return 0;
215 }
216 dprintf(("USER32: GetNextDlgTabItem\n"));
217 return dialog->getNextDlgTabItem(hwndCtrl, fPrevious);
218}
219//******************************************************************************
220//******************************************************************************
221HWND WIN32API GetDlgItem(HWND hwnd, int id)
222{
223 Win32Dialog *dialog;
224 Win32BaseWindow *dlgcontrol;
225
226 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
227 if(!dialog || !dialog->IsDialog()) {
228 dprintf(("GetDlgItem, window %x not found", hwnd));
229 return 0;
230 }
231 dprintf(("USER32: GetDlgItem\n"));
232 dlgcontrol = dialog->getDlgItem(id);
233 if(dlgcontrol) {
234 return dlgcontrol->getWindowHandle();
235 }
236 return 0;
237}
238//******************************************************************************
239//******************************************************************************
240int WIN32API GetDlgCtrlID(HWND hwnd)
241{
242 Win32BaseWindow *dlgcontrol;
243
244 dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
245 if(!dlgcontrol) {
246 dprintf(("GetDlgCtrlID, control %x not found", hwnd));
247 return 0;
248 }
249 dprintf(("USER32: GetDlgCtrlID\n"));
250 return dlgcontrol->getWindowId();
251}
252//******************************************************************************
253//******************************************************************************
254BOOL WIN32API EndDialog(HWND hwnd, int retval)
255{
256 Win32Dialog *dialog;
257
258 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
259 if(!dialog || !dialog->IsDialog()) {
260 dprintf(("GetDlgItem, window %x not found", hwnd));
261 return 0;
262 }
263 dprintf(("USER32: EndDialog\n"));
264 return dialog->endDialog(retval);
265}
266//******************************************************************************
267//******************************************************************************
268BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
269{
270 dprintf(("USER32: CheckDlgButton\n"));
271 //CB: set button state
272 return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
273}
274//******************************************************************************
275//******************************************************************************
276UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
277{
278 return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
279}
280//*****************************************************************************
281//*****************************************************************************
282UINT WIN32API GetDlgItemTextW(HWND hwnd, int id, LPWSTR lpszName, UINT cch)
283{
284 return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
285}
286//******************************************************************************
287//******************************************************************************
288BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL fSigned)
289{
290 char str[20];
291
292 dprintf(("USER32: SetDlgItemInt\n"));
293
294 if (fSigned)
295 sprintf( str, "%d", (INT)uValue );
296 else sprintf( str, "%u", uValue );
297
298 return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
299}
300//******************************************************************************
301//******************************************************************************
302BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
303{
304 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
305}
306//******************************************************************************
307//******************************************************************************
308BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
309{
310 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
311}
312//******************************************************************************
313//******************************************************************************
314UINT WIN32API GetDlgItemInt( HWND arg1, int arg2, PBOOL arg3, BOOL arg4)
315{
316#ifdef DEBUG
317 WriteLog("USER32: GetDlgItemInt\n");
318#endif
319 return O32_GetDlgItemInt(arg1, arg2, arg3, arg4);
320}
321//******************************************************************************
322//******************************************************************************
323HWND WIN32API GetNextDlgGroupItem( HWND arg1, HWND arg2, BOOL arg3)
324{
325#ifdef DEBUG
326 WriteLog("USER32: GetNextDlgGroupItem\n");
327#endif
328 return O32_GetNextDlgGroupItem(arg1, arg2, arg3);
329}
330/***********************************************************************
331 * GetDialogBaseUnits (USER.243) (USER32.233)
332 */
333DWORD WIN32API GetDialogBaseUnits(void)
334{
335 return Win32Dialog::GetDialogBaseUnits();
336}
337//******************************************************************************
338//******************************************************************************
339INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
340{
341 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
342}
343//******************************************************************************
344//******************************************************************************
345int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
346{
347 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
348}
349//******************************************************************************
350//******************************************************************************
351INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
352{
353 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
354}
355//******************************************************************************
356//******************************************************************************
357INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
358{
359 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
360}
361//******************************************************************************
362//******************************************************************************
363BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
364{
365 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
366}
367//******************************************************************************
368//******************************************************************************
369BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
370{
371 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
372}
373//******************************************************************************
374//******************************************************************************
375BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
376{
377 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
378}
379//******************************************************************************
380//******************************************************************************
381BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
382{
383 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
384}
385/**********************************************************************
386 * DIALOG_DlgDirSelect
387 *
388 * Helper function for DlgDirSelect*
389 */
390static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
391 INT id, BOOL win32, BOOL unicode,
392 BOOL combo )
393{
394 char *buffer, *ptr;
395 INT item, size;
396 BOOL ret;
397 HWND listbox = GetDlgItem( hwnd, id );
398
399 if (!listbox) return FALSE;
400
401 item = SendMessageA(listbox, combo ? CB_GETCURSEL
402 : LB_GETCURSEL, 0, 0 );
403 if (item == LB_ERR) return FALSE;
404 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
405 : LB_GETTEXTLEN, 0, 0 );
406 if (size == LB_ERR) return FALSE;
407
408 if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
409
410 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
411 item, (LPARAM)buffer );
412
413 if ((ret = (buffer[0] == '['))) /* drive or directory */
414 {
415 if (buffer[1] == '-') /* drive */
416 {
417 buffer[3] = ':';
418 buffer[4] = 0;
419 ptr = buffer + 2;
420 }
421 else
422 {
423 buffer[strlen(buffer)-1] = '\\';
424 ptr = buffer + 1;
425 }
426 }
427 else ptr = buffer;
428
429 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
430 else lstrcpynA( str, ptr, len );
431
432 free( buffer );
433 return ret;
434}
435
436
437/**********************************************************************
438 * DIALOG_DlgDirList
439 *
440 * Helper function for DlgDirList*
441 */
442static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
443 INT idStatic, UINT attrib, BOOL combo )
444{
445 int drive;
446 HWND hwnd;
447 LPSTR orig_spec = spec;
448
449#define SENDMSG(msg,wparam,lparam) \
450 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
451 : SendMessageA( hwnd, msg, wparam, lparam ))
452
453 if (spec && spec[0] && (spec[1] == ':'))
454 {
455 drive = _toupper( spec[0] ) - 'A';
456 spec += 2;
457 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
458 }
459 else drive = DRIVE_GetCurrentDrive();
460
461 /* If the path exists and is a directory, chdir to it */
462 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
463 else
464 {
465 char *p, *p2;
466 p = spec;
467 if ((p2 = strrchr( p, '\\' ))) p = p2;
468 if ((p2 = strrchr( p, '/' ))) p = p2;
469 if (p != spec)
470 {
471 char sep = *p;
472 *p = 0;
473 if (!DRIVE_Chdir( drive, spec ))
474 {
475 *p = sep; /* Restore the original spec */
476 return FALSE;
477 }
478 spec = p + 1;
479 }
480 }
481
482 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
483 {
484 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
485 if (attrib & DDL_DIRECTORY)
486 {
487 if (!(attrib & DDL_EXCLUSIVE))
488 {
489 if (SENDMSG( combo ? CB_DIR : LB_DIR,
490 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
491 (LPARAM)spec ) == LB_ERR)
492 return FALSE;
493 }
494 if (SENDMSG( combo ? CB_DIR : LB_DIR,
495 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
496 (LPARAM)"*.*" ) == LB_ERR)
497 return FALSE;
498 }
499 else
500 {
501 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
502 (LPARAM)spec ) == LB_ERR)
503 return FALSE;
504 }
505 }
506
507 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
508 {
509 char temp[512], curpath[512];
510 int drive = DRIVE_GetCurrentDrive();
511 strcpy( temp, "A:\\" );
512 temp[0] += drive;
513 lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive), sizeof(temp)-3 );
514 CharLowerA( temp );
515 /* Can't use PostMessage() here, because the string is on the stack */
516 SetDlgItemTextA( hDlg, idStatic, temp );
517 }
518
519 if (orig_spec && (spec != orig_spec))
520 {
521 /* Update the original file spec */
522 char *p = spec;
523 while ((*orig_spec++ = *p++));
524 }
525
526 return TRUE;
527#undef SENDMSG
528}
529
530
531/**********************************************************************
532 * DIALOG_DlgDirListW
533 *
534 * Helper function for DlgDirList*32W
535 */
536static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
537 INT idStatic, UINT attrib, BOOL combo )
538{
539 if (spec)
540 {
541 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
542 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
543 attrib, combo );
544 lstrcpyAtoW( spec, specA );
545 HeapFree( GetProcessHeap(), 0, specA );
546 return ret;
547 }
548 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
549}
550//******************************************************************************
551//******************************************************************************
552
Note: See TracBrowser for help on using the repository browser.