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