Changeset 4511 for trunk/src/comdlg32/comdlg32.cpp
- Timestamp:
- Oct 21, 2000, 8:42:42 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comdlg32/comdlg32.cpp
r3223 r4511 1 /* $Id: comdlg32.cpp,v 1.2 5 2000-03-24 18:22:55 achimhaExp $ */1 /* $Id: comdlg32.cpp,v 1.26 2000-10-21 18:42:13 sandervl Exp $ */ 2 2 3 3 /* … … 26 26 ODINDEBUGCHANNEL(COMDLG32-COMDLG32) 27 27 28 // this controls whether we want to use the Open32 OS/2 file dialogs 29 // or our own Win95 like file dialogs 30 #define useWinFileDlg 1 31 32 #if 0 33 #define COMDLG32_CHECKHOOK(a,b,c) \ 34 if(a->Flags & b) \ 35 { \ 36 wndproc = CreateWindowProc((WNDPROC)a->lpfnHook);\ 37 if(wndproc == NULL) \ 38 return(FALSE); \ 39 \ 40 a->lpfnHook = (c)Win32WindowProc::GetOS2Callback();\ 41 } \ 42 a->hwndOwner = Win32ToOS2Handle(a->hwndOwner); 43 44 #define COMDLG32_CHECKHOOK2(a,b,c,d) \ 45 if(a->Flags & b) \ 46 { \ 47 wndproc = CreateWindowProc((WNDPROC)a->d);\ 48 if(wndproc == NULL) \ 49 return(FALSE); \ 50 \ 51 a->d = (c)Win32WindowProc::GetOS2Callback();\ 52 } \ 53 a->hwndOwner = Win32ToOS2Handle(a->hwndOwner); 54 #else 28 55 29 #define COMDLG32_CHECKHOOK(a,b,c) \ 56 30 if(a->Flags & b) \ … … 66 40 } \ 67 41 a->hwndOwner = Win32ToOS2Handle(a->hwndOwner); 68 #endif69 70 71 /*****************************************************************************72 * Name : iFileDlg_ScanFilterToken73 * Purpose : scan for valid / invalid filter tokens and74 * advance array pointer75 * Parameters:76 * Variables :77 * Result :78 * Remark :79 * Status :80 *81 * Author :82 *****************************************************************************/83 84 // scan filter tokens for validity85 static BOOL iFileDlg_ScanFilterToken( LPSTR *plpstrPair )86 {87 LPSTR lpstrTemp;88 LPSTR lpstrNext;89 BOOL fOK = TRUE;90 91 lpstrTemp = *plpstrPair;92 if (lpstrTemp[0] != 0)93 {94 // get filter description95 lpstrTemp = lpstrTemp + strlen(lpstrTemp);96 lpstrNext = lpstrTemp + 1;97 if (lpstrNext[0] == 0)98 fOK = FALSE;99 else100 {101 // get filter mask102 lpstrTemp = lpstrNext;103 lpstrTemp = lpstrTemp + strlen(lpstrTemp);104 lpstrTemp++;105 }106 107 if (fOK)108 *plpstrPair = lpstrTemp;109 }110 return fOK;111 }112 113 114 /*****************************************************************************115 * Name : iFileDlg_CleanFilterArray116 * Purpose : remove erroneous array entries at the end to prevent117 * Open32 complain about them but open the file dialog118 * instead.119 * Parameters:120 * Variables :121 * Result :122 * Remark :123 * Status :124 *125 * Author :126 *****************************************************************************/127 128 static DWORD iFileDlg_CleanFilterArray( LPSTR lpstrFilters)129 {130 DWORD dwCount = 0;131 LPSTR lpstrTemp;132 133 if (lpstrFilters && *lpstrFilters)134 {135 lpstrTemp = lpstrFilters;136 while (lpstrTemp[0] != 0)137 {138 // if an invalid filter token is found, such as found139 // in NT4's Regedit e. g., return number of proper140 // filter tokens.141 // Here however, as were calling Open32, we need142 // to correct the filter array.143 if (iFileDlg_ScanFilterToken(&lpstrTemp) == FALSE)144 {145 //@@@PH two alternative methods:146 // - copy array to new, corrected array while scanning tokens147 // - just overwrite bogus characters at the end of the array148 *lpstrTemp++ = 0; // try string termination149 *lpstrTemp = 0;150 return dwCount;151 }152 153 dwCount++;154 }155 }156 return dwCount;157 }158 159 42 160 43 /***************************************************************************** … … 173 56 LPOPENFILENAMEA, lpofn) 174 57 { 175 if(useWinFileDlg || (lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))) { 176 return GetFileDialog95A(lpofn, SAVE_DIALOG); 177 } 178 179 COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC) 180 181 //Note: fix IBM's proper error checking for NT's lazy check 182 if (lpofn->lpstrFilter != NULL) 183 iFileDlg_CleanFilterArray((LPSTR)lpofn->lpstrFilter); 184 185 return(O32_GetSaveFileName(lpofn)); 58 return GetFileDialog95A(lpofn, SAVE_DIALOG); 186 59 } 187 60 … … 202 75 LPOPENFILENAMEW, lpofn) 203 76 { 204 OPENFILENAMEA ofn; 205 char* szFile; 206 char* szFileTitle; 207 char* szCustFilter; 208 BOOL bResult; 209 210 if(useWinFileDlg || (lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))) { 211 return GetFileDialog95W(lpofn, SAVE_DIALOG); 212 } 213 214 memcpy(&ofn, // make binary copy first to save all the fields 215 lpofn, 216 sizeof(ofn)); 217 218 // convert to ASCII string 219 if ((lpofn->Flags && OFN_ENABLETEMPLATE) && 220 (lpofn->lpTemplateName != NULL)) 221 ofn.lpTemplateName = UnicodeToAsciiString((WCHAR*)lpofn->lpTemplateName); 222 else 223 ofn.lpTemplateName = NULL; 224 225 if (lpofn->lpstrFilter != NULL) 226 ofn.lpstrFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrFilter); 227 228 if (lpofn->lpstrInitialDir != NULL) 229 ofn.lpstrInitialDir = UnicodeToAsciiString((WCHAR*)lpofn->lpstrInitialDir); 230 231 if (lpofn->lpstrTitle != NULL) 232 ofn.lpstrTitle = UnicodeToAsciiString((WCHAR*)lpofn->lpstrTitle); 233 234 if (lpofn->lpstrDefExt != NULL) 235 ofn.lpstrDefExt = UnicodeToAsciiString((WCHAR*)lpofn->lpstrDefExt); 236 237 szFile = (char*)malloc(lpofn->nMaxFile); 238 szFile[0] = 0; 239 240 if (*lpofn->lpstrFile != 0) 241 UnicodeToAscii(lpofn->lpstrFile, 242 szFile); 243 244 if (lpofn->lpstrFileTitle != NULL) 245 { 246 szFileTitle = (char*)malloc(lpofn->nMaxFileTitle); 247 szFileTitle[0] = 0; 248 249 if (*lpofn->lpstrFileTitle != 0) 250 UnicodeToAscii(lpofn->lpstrFileTitle, 251 szFileTitle); 252 } 253 else 254 szFileTitle = NULL; 255 256 if (lpofn->lpstrCustomFilter != NULL) 257 { 258 szCustFilter = (char*)malloc(lpofn->nMaxCustFilter); 259 szCustFilter[0] = 0; 260 261 262 if (*lpofn->lpstrCustomFilter != 0) 263 UnicodeToAscii(lpofn->lpstrCustomFilter, 264 szCustFilter); 265 } 266 else 267 szCustFilter = NULL; 268 269 ofn.lpstrFile = szFile; 270 ofn.lpstrFileTitle = szFileTitle; 271 ofn.lpstrCustomFilter = szCustFilter; 272 273 // call ascii variant of function 274 // @@@PH switch to ODIN_GetSaveFileNameA later 275 bResult = GetSaveFileNameA(&ofn); 276 277 if (ofn.lpTemplateName != NULL) FreeAsciiString((char*)ofn.lpTemplateName); 278 if (ofn.lpstrFilter != NULL) FreeAsciiString((char*)ofn.lpstrFilter); 279 if (ofn.lpstrInitialDir != NULL) FreeAsciiString((char*)ofn.lpstrInitialDir); 280 if (ofn.lpstrTitle != NULL) FreeAsciiString((char*)ofn.lpstrTitle); 281 if (ofn.lpstrDefExt != NULL) FreeAsciiString((char*)ofn.lpstrDefExt); 282 283 // transform back the result 284 AsciiToUnicode(ofn.lpstrFile, 285 lpofn->lpstrFile); 286 free(szFile); 287 288 if (lpofn->lpstrFileTitle != NULL) 289 { 290 AsciiToUnicode(ofn.lpstrFileTitle, 291 lpofn->lpstrFileTitle); 292 free(szFileTitle); 293 } 294 295 if (lpofn->lpstrCustomFilter != NULL) 296 { 297 AsciiToUnicode(ofn.lpstrCustomFilter, 298 lpofn->lpstrCustomFilter); 299 free(szCustFilter); 300 } 301 302 // copy over some altered flags 303 lpofn->nFilterIndex = ofn.nFilterIndex; 304 lpofn->Flags = ofn.Flags; 305 lpofn->nFileOffset = ofn.nFileOffset; 306 lpofn->nFileExtension = ofn.nFileExtension; 307 308 return bResult; 77 return GetFileDialog95W(lpofn, SAVE_DIALOG); 309 78 } 310 79 … … 324 93 LPOPENFILENAMEA, lpofn) 325 94 { 326 BOOL rc; 327 328 CheckCurFS(); 329 if(useWinFileDlg || (lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))) 330 { 331 return GetFileDialog95A(lpofn, OPEN_DIALOG); 332 } 333 COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC) 334 335 //Note: fix IBM's proper error checking for NT's lazy check 336 if (lpofn->lpstrFilter != NULL) 337 iFileDlg_CleanFilterArray((LPSTR)lpofn->lpstrFilter); 338 339 rc = O32_GetOpenFileName(lpofn); 340 CheckCurFS(); 341 return rc; 95 return GetFileDialog95A(lpofn, OPEN_DIALOG); 342 96 } 343 97 … … 357 111 LPOPENFILENAMEW, lpofn) 358 112 { 359 OPENFILENAMEA ofn; 360 char* szFile; 361 char* szFileTitle; 362 char* szCustFilter; 363 BOOL bResult; 364 365 if(useWinFileDlg || (lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))) { 366 return GetFileDialog95W(lpofn, OPEN_DIALOG); 367 } 368 369 memcpy(&ofn, // make binary copy first to save all the fields 370 lpofn, 371 sizeof(ofn)); 372 373 // convert to ASCII string 374 if ((lpofn->Flags && OFN_ENABLETEMPLATE) && 375 (lpofn->lpTemplateName != NULL)) 376 ofn.lpTemplateName = UnicodeToAsciiString((WCHAR*)lpofn->lpTemplateName); 377 else 378 ofn.lpTemplateName = NULL; 379 380 if (lpofn->lpstrFilter != NULL) 381 ofn.lpstrFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrFilter); 382 383 if (lpofn->lpstrInitialDir != NULL) 384 ofn.lpstrInitialDir = UnicodeToAsciiString((WCHAR*)lpofn->lpstrInitialDir); 385 386 if (lpofn->lpstrTitle != NULL) 387 ofn.lpstrTitle = UnicodeToAsciiString((WCHAR*)lpofn->lpstrTitle); 388 389 if (lpofn->lpstrDefExt != NULL) 390 ofn.lpstrDefExt = UnicodeToAsciiString((WCHAR*)lpofn->lpstrDefExt); 391 392 szFile = (char*)malloc(lpofn->nMaxFile); 393 szFile[0] = 0; 394 395 if (*lpofn->lpstrFile != 0) 396 UnicodeToAscii(lpofn->lpstrFile, 397 szFile); 398 399 if (lpofn->lpstrFileTitle != NULL) 400 { 401 szFileTitle = (char*)malloc(lpofn->nMaxFileTitle); 402 szFileTitle[0] = 0; 403 404 if (*lpofn->lpstrFileTitle != 0) 405 UnicodeToAscii(lpofn->lpstrFileTitle, 406 szFileTitle); 407 } 408 else 409 szFileTitle = NULL; 410 411 if (lpofn->lpstrCustomFilter != NULL) 412 { 413 szCustFilter = (char*)malloc(lpofn->nMaxCustFilter); 414 szCustFilter[0] = 0; 415 416 417 if (*lpofn->lpstrCustomFilter != 0) 418 UnicodeToAscii(lpofn->lpstrCustomFilter, 419 szCustFilter); 420 } 421 else 422 szCustFilter = NULL; 423 424 ofn.lpstrFile = szFile; 425 ofn.lpstrFileTitle = szFileTitle; 426 ofn.lpstrCustomFilter = szCustFilter; 427 428 // call ascii variant of function 429 // @@@PH switch to ODIN_GetOpenFileNameA later 430 bResult = GetOpenFileNameA(&ofn); 431 432 if (ofn.lpTemplateName != NULL) FreeAsciiString((char*)ofn.lpTemplateName); 433 if (ofn.lpstrFilter != NULL) FreeAsciiString((char*)ofn.lpstrFilter); 434 if (ofn.lpstrInitialDir != NULL) FreeAsciiString((char*)ofn.lpstrInitialDir); 435 if (ofn.lpstrTitle != NULL) FreeAsciiString((char*)ofn.lpstrTitle); 436 if (ofn.lpstrDefExt != NULL) FreeAsciiString((char*)ofn.lpstrDefExt); 437 438 // transform back the result 439 AsciiToUnicode(ofn.lpstrFile, 440 lpofn->lpstrFile); 441 free(szFile); 442 443 if (lpofn->lpstrFileTitle != NULL) 444 { 445 AsciiToUnicode(ofn.lpstrFileTitle, 446 lpofn->lpstrFileTitle); 447 free(szFileTitle); 448 } 449 450 if (lpofn->lpstrCustomFilter != NULL) 451 { 452 AsciiToUnicode(ofn.lpstrCustomFilter, 453 lpofn->lpstrCustomFilter); 454 free(szCustFilter); 455 } 456 457 // copy over some altered flags 458 lpofn->nFilterIndex = ofn.nFilterIndex; 459 lpofn->Flags = ofn.Flags; 460 lpofn->nFileOffset = ofn.nFileOffset; 461 lpofn->nFileExtension = ofn.nFileExtension; 462 463 return bResult; 464 } 465 113 return GetFileDialog95W(lpofn, OPEN_DIALOG); 114 } 115 116 #if 0 466 117 /***************************************************************************** 467 118 * Name : … … 679 330 return O32_CommDlgExtendedError(); 680 331 } 681 682 332 683 333 /***************************************************************************** … … 806 456 return iResult; 807 457 } 458 #endif 808 459 809 460 /***************************************************************************** … … 887 538 888 539 540 #if 0 889 541 /***************************************************************************** 890 542 * Name : … … 979 631 return bResult; 980 632 } 981 633 #endif 982 634 983 635 /*****************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.