source: trunk/src/user32/new/windlg.cpp@ 835

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

More dialog update

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