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