1 | /* $Id: windlg.cpp,v 1.2 1999-09-26 14:44:58 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 |
|
---|
26 | static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
|
---|
27 | static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
|
---|
28 | static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len, INT id, BOOL win32, BOOL unicode, BOOL combo );
|
---|
29 |
|
---|
30 | //******************************************************************************
|
---|
31 | //******************************************************************************
|
---|
32 | HWND 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 | //******************************************************************************
|
---|
46 | HWND 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 | //******************************************************************************
|
---|
60 | HWND 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 | //******************************************************************************
|
---|
88 | HWND 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 | //******************************************************************************
|
---|
116 | INT 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 | //******************************************************************************
|
---|
138 | INT 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 | //******************************************************************************
|
---|
159 | int 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 | //******************************************************************************
|
---|
179 | int 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 | //******************************************************************************
|
---|
199 | BOOL 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 | //******************************************************************************
|
---|
207 | HWND 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 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
215 | return 0;
|
---|
216 | }
|
---|
217 | dprintf(("USER32: GetNextDlgTabItem\n"));
|
---|
218 | return dialog->getNextDlgTabItem(hwndCtrl, fPrevious);
|
---|
219 | }
|
---|
220 | //******************************************************************************
|
---|
221 | //******************************************************************************
|
---|
222 | HWND WIN32API GetDlgItem(HWND hwnd, int id)
|
---|
223 | {
|
---|
224 | Win32Dialog *dialog;
|
---|
225 | Win32BaseWindow *dlgcontrol;
|
---|
226 |
|
---|
227 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
228 | if(!dialog || !dialog->IsDialog()) {
|
---|
229 | dprintf(("GetDlgItem, window %x not found", hwnd));
|
---|
230 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
231 | return 0;
|
---|
232 | }
|
---|
233 | dprintf(("USER32: GetDlgItem\n"));
|
---|
234 | dlgcontrol = dialog->getDlgItem(id);
|
---|
235 | if(dlgcontrol) {
|
---|
236 | return dlgcontrol->getWindowHandle();
|
---|
237 | }
|
---|
238 | return 0;
|
---|
239 | }
|
---|
240 | //******************************************************************************
|
---|
241 | //******************************************************************************
|
---|
242 | int WIN32API GetDlgCtrlID(HWND hwnd)
|
---|
243 | {
|
---|
244 | Win32BaseWindow *dlgcontrol;
|
---|
245 |
|
---|
246 | dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
247 | if(!dlgcontrol) {
|
---|
248 | dprintf(("GetDlgCtrlID, control %x not found", hwnd));
|
---|
249 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
250 | return 0;
|
---|
251 | }
|
---|
252 | dprintf(("USER32: GetDlgCtrlID\n"));
|
---|
253 | return dlgcontrol->getWindowId();
|
---|
254 | }
|
---|
255 | //******************************************************************************
|
---|
256 | //******************************************************************************
|
---|
257 | BOOL WIN32API EndDialog(HWND hwnd, int retval)
|
---|
258 | {
|
---|
259 | Win32Dialog *dialog;
|
---|
260 |
|
---|
261 | dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
262 | if(!dialog || !dialog->IsDialog()) {
|
---|
263 | dprintf(("GetDlgItem, window %x not found", hwnd));
|
---|
264 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
265 | return 0;
|
---|
266 | }
|
---|
267 | dprintf(("USER32: EndDialog\n"));
|
---|
268 | return dialog->endDialog(retval);
|
---|
269 | }
|
---|
270 | //******************************************************************************
|
---|
271 | //******************************************************************************
|
---|
272 | BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
|
---|
273 | {
|
---|
274 | dprintf(("USER32: CheckDlgButton\n"));
|
---|
275 | //CB: set button state
|
---|
276 | return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
|
---|
277 | }
|
---|
278 | //******************************************************************************
|
---|
279 | //******************************************************************************
|
---|
280 | UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
|
---|
281 | {
|
---|
282 | return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
|
---|
283 | }
|
---|
284 | //*****************************************************************************
|
---|
285 | //*****************************************************************************
|
---|
286 | UINT WIN32API GetDlgItemTextW(HWND hwnd, int id, LPWSTR lpszName, UINT cch)
|
---|
287 | {
|
---|
288 | return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
|
---|
289 | }
|
---|
290 | //******************************************************************************
|
---|
291 | //******************************************************************************
|
---|
292 | BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL fSigned)
|
---|
293 | {
|
---|
294 | char str[20];
|
---|
295 |
|
---|
296 | dprintf(("USER32: SetDlgItemInt\n"));
|
---|
297 |
|
---|
298 | if (fSigned)
|
---|
299 | sprintf( str, "%d", (INT)uValue );
|
---|
300 | else sprintf( str, "%u", uValue );
|
---|
301 |
|
---|
302 | return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
|
---|
303 | }
|
---|
304 | //******************************************************************************
|
---|
305 | //******************************************************************************
|
---|
306 | BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
|
---|
307 | {
|
---|
308 | return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
|
---|
309 | }
|
---|
310 | //******************************************************************************
|
---|
311 | //******************************************************************************
|
---|
312 | BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
|
---|
313 | {
|
---|
314 | return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
|
---|
315 | }
|
---|
316 | //******************************************************************************
|
---|
317 | //******************************************************************************
|
---|
318 | UINT WIN32API GetDlgItemInt( HWND arg1, int arg2, PBOOL arg3, BOOL arg4)
|
---|
319 | {
|
---|
320 | #ifdef DEBUG
|
---|
321 | WriteLog("USER32: GetDlgItemInt\n");
|
---|
322 | #endif
|
---|
323 | return O32_GetDlgItemInt(arg1, arg2, arg3, arg4);
|
---|
324 | }
|
---|
325 | //******************************************************************************
|
---|
326 | //******************************************************************************
|
---|
327 | HWND WIN32API GetNextDlgGroupItem( HWND arg1, HWND arg2, BOOL arg3)
|
---|
328 | {
|
---|
329 | #ifdef DEBUG
|
---|
330 | WriteLog("USER32: GetNextDlgGroupItem\n");
|
---|
331 | #endif
|
---|
332 | return O32_GetNextDlgGroupItem(arg1, arg2, arg3);
|
---|
333 | }
|
---|
334 | /***********************************************************************
|
---|
335 | * GetDialogBaseUnits (USER.243) (USER32.233)
|
---|
336 | */
|
---|
337 | DWORD WIN32API GetDialogBaseUnits(void)
|
---|
338 | {
|
---|
339 | return Win32Dialog::GetDialogBaseUnits();
|
---|
340 | }
|
---|
341 | //******************************************************************************
|
---|
342 | //******************************************************************************
|
---|
343 | INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
|
---|
344 | {
|
---|
345 | return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
|
---|
346 | }
|
---|
347 | //******************************************************************************
|
---|
348 | //******************************************************************************
|
---|
349 | int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
|
---|
350 | {
|
---|
351 | return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
|
---|
352 | }
|
---|
353 | //******************************************************************************
|
---|
354 | //******************************************************************************
|
---|
355 | INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
|
---|
356 | {
|
---|
357 | return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
|
---|
358 | }
|
---|
359 | //******************************************************************************
|
---|
360 | //******************************************************************************
|
---|
361 | INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
|
---|
362 | {
|
---|
363 | return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
|
---|
364 | }
|
---|
365 | //******************************************************************************
|
---|
366 | //******************************************************************************
|
---|
367 | BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
|
---|
368 | {
|
---|
369 | return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
|
---|
370 | }
|
---|
371 | //******************************************************************************
|
---|
372 | //******************************************************************************
|
---|
373 | BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
|
---|
374 | {
|
---|
375 | return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
|
---|
376 | }
|
---|
377 | //******************************************************************************
|
---|
378 | //******************************************************************************
|
---|
379 | BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
|
---|
380 | {
|
---|
381 | return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
|
---|
382 | }
|
---|
383 | //******************************************************************************
|
---|
384 | //******************************************************************************
|
---|
385 | BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
|
---|
386 | {
|
---|
387 | return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
|
---|
388 | }
|
---|
389 | /**********************************************************************
|
---|
390 | * DIALOG_DlgDirSelect
|
---|
391 | *
|
---|
392 | * Helper function for DlgDirSelect*
|
---|
393 | */
|
---|
394 | static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
|
---|
395 | INT id, BOOL win32, BOOL unicode,
|
---|
396 | BOOL combo )
|
---|
397 | {
|
---|
398 | char *buffer, *ptr;
|
---|
399 | INT item, size;
|
---|
400 | BOOL ret;
|
---|
401 | HWND listbox = GetDlgItem( hwnd, id );
|
---|
402 |
|
---|
403 | if (!listbox) return FALSE;
|
---|
404 |
|
---|
405 | item = SendMessageA(listbox, combo ? CB_GETCURSEL
|
---|
406 | : LB_GETCURSEL, 0, 0 );
|
---|
407 | if (item == LB_ERR) return FALSE;
|
---|
408 | size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
|
---|
409 | : LB_GETTEXTLEN, 0, 0 );
|
---|
410 | if (size == LB_ERR) return FALSE;
|
---|
411 |
|
---|
412 | if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
|
---|
413 |
|
---|
414 | SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
|
---|
415 | item, (LPARAM)buffer );
|
---|
416 |
|
---|
417 | if ((ret = (buffer[0] == '['))) /* drive or directory */
|
---|
418 | {
|
---|
419 | if (buffer[1] == '-') /* drive */
|
---|
420 | {
|
---|
421 | buffer[3] = ':';
|
---|
422 | buffer[4] = 0;
|
---|
423 | ptr = buffer + 2;
|
---|
424 | }
|
---|
425 | else
|
---|
426 | {
|
---|
427 | buffer[strlen(buffer)-1] = '\\';
|
---|
428 | ptr = buffer + 1;
|
---|
429 | }
|
---|
430 | }
|
---|
431 | else ptr = buffer;
|
---|
432 |
|
---|
433 | if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
|
---|
434 | else lstrcpynA( str, ptr, len );
|
---|
435 |
|
---|
436 | free( buffer );
|
---|
437 | return ret;
|
---|
438 | }
|
---|
439 |
|
---|
440 |
|
---|
441 | /**********************************************************************
|
---|
442 | * DIALOG_DlgDirList
|
---|
443 | *
|
---|
444 | * Helper function for DlgDirList*
|
---|
445 | */
|
---|
446 | static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
|
---|
447 | INT idStatic, UINT attrib, BOOL combo )
|
---|
448 | {
|
---|
449 | int drive;
|
---|
450 | HWND hwnd;
|
---|
451 | LPSTR orig_spec = spec;
|
---|
452 |
|
---|
453 | #define SENDMSG(msg,wparam,lparam) \
|
---|
454 | ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
|
---|
455 | : SendMessageA( hwnd, msg, wparam, lparam ))
|
---|
456 |
|
---|
457 | if (spec && spec[0] && (spec[1] == ':'))
|
---|
458 | {
|
---|
459 | drive = _toupper( spec[0] ) - 'A';
|
---|
460 | spec += 2;
|
---|
461 | if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
|
---|
462 | }
|
---|
463 | else drive = DRIVE_GetCurrentDrive();
|
---|
464 |
|
---|
465 | /* If the path exists and is a directory, chdir to it */
|
---|
466 | if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
|
---|
467 | else
|
---|
468 | {
|
---|
469 | char *p, *p2;
|
---|
470 | p = spec;
|
---|
471 | if ((p2 = strrchr( p, '\\' ))) p = p2;
|
---|
472 | if ((p2 = strrchr( p, '/' ))) p = p2;
|
---|
473 | if (p != spec)
|
---|
474 | {
|
---|
475 | char sep = *p;
|
---|
476 | *p = 0;
|
---|
477 | if (!DRIVE_Chdir( drive, spec ))
|
---|
478 | {
|
---|
479 | *p = sep; /* Restore the original spec */
|
---|
480 | return FALSE;
|
---|
481 | }
|
---|
482 | spec = p + 1;
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
|
---|
487 | {
|
---|
488 | SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
|
---|
489 | if (attrib & DDL_DIRECTORY)
|
---|
490 | {
|
---|
491 | if (!(attrib & DDL_EXCLUSIVE))
|
---|
492 | {
|
---|
493 | if (SENDMSG( combo ? CB_DIR : LB_DIR,
|
---|
494 | attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
|
---|
495 | (LPARAM)spec ) == LB_ERR)
|
---|
496 | return FALSE;
|
---|
497 | }
|
---|
498 | if (SENDMSG( combo ? CB_DIR : LB_DIR,
|
---|
499 | (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
|
---|
500 | (LPARAM)"*.*" ) == LB_ERR)
|
---|
501 | return FALSE;
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
|
---|
506 | (LPARAM)spec ) == LB_ERR)
|
---|
507 | return FALSE;
|
---|
508 | }
|
---|
509 | }
|
---|
510 |
|
---|
511 | if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
|
---|
512 | {
|
---|
513 | char temp[512], curpath[512];
|
---|
514 | int drive = DRIVE_GetCurrentDrive();
|
---|
515 | strcpy( temp, "A:\\" );
|
---|
516 | temp[0] += drive;
|
---|
517 | lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive), sizeof(temp)-3 );
|
---|
518 | CharLowerA( temp );
|
---|
519 | /* Can't use PostMessage() here, because the string is on the stack */
|
---|
520 | SetDlgItemTextA( hDlg, idStatic, temp );
|
---|
521 | }
|
---|
522 |
|
---|
523 | if (orig_spec && (spec != orig_spec))
|
---|
524 | {
|
---|
525 | /* Update the original file spec */
|
---|
526 | char *p = spec;
|
---|
527 | while ((*orig_spec++ = *p++));
|
---|
528 | }
|
---|
529 |
|
---|
530 | return TRUE;
|
---|
531 | #undef SENDMSG
|
---|
532 | }
|
---|
533 |
|
---|
534 |
|
---|
535 | /**********************************************************************
|
---|
536 | * DIALOG_DlgDirListW
|
---|
537 | *
|
---|
538 | * Helper function for DlgDirList*32W
|
---|
539 | */
|
---|
540 | static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
|
---|
541 | INT idStatic, UINT attrib, BOOL combo )
|
---|
542 | {
|
---|
543 | if (spec)
|
---|
544 | {
|
---|
545 | LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
|
---|
546 | INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
|
---|
547 | attrib, combo );
|
---|
548 | lstrcpyAtoW( spec, specA );
|
---|
549 | HeapFree( GetProcessHeap(), 0, specA );
|
---|
550 | return ret;
|
---|
551 | }
|
---|
552 | return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
|
---|
553 | }
|
---|
554 | //******************************************************************************
|
---|
555 | //******************************************************************************
|
---|
556 |
|
---|