Changeset 846 for trunk/src/gui/dialogs/qfiledialog_win.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/dialogs/qfiledialog_win.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 53 53 #include <qdir.h> 54 54 #include <qstringlist.h> 55 #include <qlibrary.h> 55 #include <private/qsystemlibrary_p.h> 56 #include "qfiledialog_win_p.h" 56 57 57 58 #ifndef QT_NO_THREAD … … 59 60 #endif 60 61 62 #ifdef Q_WS_WINCE 61 63 #include <shlobj.h> 62 //At some point we can hope that mingw will support that interface 63 #if !defined(Q_WS_WINCE) && !defined(Q_CC_MINGW) 64 #include <shobjidl.h> 64 #include <commdlg.h> 65 bool qt_priv_ptr_valid = false; 66 #else 67 //we have to declare them here because they're not present for all SDK/compilers 68 static const IID QT_IID_IFileOpenDialog = {0xd57c7288, 0xd4ad, 0x4768, {0xbe, 0x02, 0x9d, 0x96, 0x95, 0x32, 0xd9, 0x60} }; 69 static const IID QT_IID_IShellItem = {0x43826d1e, 0xe718, 0x42ee, {0xbc, 0x55, 0xa1, 0xe2, 0x61, 0xc3, 0x7b, 0xfe} }; 70 static const CLSID QT_CLSID_FileOpenDialog = {0xdc1c5a9c, 0xe88a, 0x4dde, {0xa5, 0xa1, 0x60, 0xf8, 0x2a, 0x20, 0xae, 0xf7} }; 65 71 #endif 66 72 67 #include <objbase.h> 68 69 #if defined(__IFileDialog_INTERFACE_DEFINED__) \ 70 && defined(__IFileOpenDialog_INTERFACE_DEFINED__) 71 #define USE_COMMON_ITEM_DIALOG 72 #endif 73 74 #ifdef Q_WS_WINCE 75 #include <commdlg.h> 76 # ifndef BFFM_SETSELECTION 77 # define BFFM_SETSELECTION (WM_USER + 102) 78 # endif 79 // Windows Mobile has a broken definition for BROWSEINFO 80 // Only compile fix 81 typedef struct qt_priv_browseinfo { 82 HWND hwndOwner; 83 LPCITEMIDLIST pidlRoot; 84 LPWSTR pszDisplayName; 85 LPCWSTR lpszTitle; 86 UINT ulFlags; 87 BFFCALLBACK lpfn; 88 LPARAM lParam; 89 int iImage; 90 } qt_BROWSEINFO; 91 bool qt_priv_ptr_valid = false; 92 #endif 93 94 95 // Don't remove the lines below! 96 // 97 // resolving the W methods manually is needed, because Windows 95 doesn't include 98 // these methods in Shell32.lib (not even stubs!), so you'd get an unresolved symbol 99 // when Qt calls getExistingDirectory(), etc. 100 typedef LPITEMIDLIST (WINAPI *PtrSHBrowseForFolder)(BROWSEINFO*); 73 74 typedef qt_LPITEMIDLIST (WINAPI *PtrSHBrowseForFolder)(qt_BROWSEINFO*); 101 75 static PtrSHBrowseForFolder ptrSHBrowseForFolder = 0; 102 typedef BOOL (WINAPI *PtrSHGetPathFromIDList)( LPITEMIDLIST,LPWSTR);76 typedef BOOL (WINAPI *PtrSHGetPathFromIDList)(qt_LPITEMIDLIST, LPWSTR); 103 77 static PtrSHGetPathFromIDList ptrSHGetPathFromIDList = 0; 104 78 typedef HRESULT (WINAPI *PtrSHGetMalloc)(LPMALLOC *); … … 127 101 triedResolve = true; 128 102 #if !defined(Q_WS_WINCE) 129 Q Library lib(QLatin1String("shell32"));130 ptrSHBrowseForFolder = (PtrSHBrowseForFolder) 131 ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList) 132 ptrSHGetMalloc = (PtrSHGetMalloc) 103 QSystemLibrary lib(L"shell32"); 104 ptrSHBrowseForFolder = (PtrSHBrowseForFolder)lib.resolve("SHBrowseForFolderW"); 105 ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList)lib.resolve("SHGetPathFromIDListW"); 106 ptrSHGetMalloc = (PtrSHGetMalloc)lib.resolve("SHGetMalloc"); 133 107 #else 134 108 // CE stores them in a different lib and does not use unicode version 135 HINSTANCE handle = LoadLibrary W(L"Ceshell");109 HINSTANCE handle = LoadLibrary(L"Ceshell"); 136 110 ptrSHBrowseForFolder = (PtrSHBrowseForFolder)GetProcAddress(handle, L"SHBrowseForFolder"); 137 111 ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList)GetProcAddress(handle, L"SHGetPathFromIDList"); … … 245 219 246 220 ofn->lStructSize = sizeof(OPENFILENAME); 247 Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));248 221 ofn->hwndOwner = parent ? parent->winId() : 0; 249 222 ofn->lpstrFilter = (wchar_t*)tFilters.utf16(); … … 422 395 423 396 424 #if defined(USE_COMMON_ITEM_DIALOG)397 #ifndef Q_WS_WINCE 425 398 426 399 typedef HRESULT (WINAPI *PtrSHCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); … … 437 410 if (!pSHCreateItemFromParsingName) { 438 411 // This function is available only in Vista & above. 439 Q Library shellLib(QLatin1String("Shell32"));412 QSystemLibrary shellLib(QLatin1String("Shell32")); 440 413 pSHCreateItemFromParsingName = (PtrSHCreateItemFromParsingName) 441 414 shellLib.resolve("SHCreateItemFromParsingName"); … … 470 443 if (numFilters) { 471 444 wchar_t *szData = (wchar_t*)winfilters.utf16(); 472 COMDLG_FILTERSPEC *filterSpec = newCOMDLG_FILTERSPEC[numFilters];445 qt_COMDLG_FILTERSPEC *filterSpec = new qt_COMDLG_FILTERSPEC[numFilters]; 473 446 for(int i = 0; i<numFilters; i++) { 474 447 filterSpec[i].pszName = szData+offsets[i*2]; … … 482 455 if (!tInitDir.isEmpty()) { 483 456 IShellItem *psiDefaultFolder; 484 hr = pSHCreateItemFromParsingName((wchar_t*)tInitDir.utf16(), 485 NULL, 486 IID_PPV_ARGS(&psiDefaultFolder)); 457 hr = pSHCreateItemFromParsingName((wchar_t*)tInitDir.utf16(), NULL, QT_IID_IShellItem, 458 reinterpret_cast<void**>(&psiDefaultFolder)); 487 459 488 460 if (SUCCEEDED(hr)) { … … 523 495 } 524 496 525 QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args,497 static QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args, 526 498 QString *initialDirectory, 527 499 const QStringList &filterList, … … 536 508 // Multiple selection is allowed only in IFileOpenDialog. 537 509 IFileOpenDialog *pfd = 0; 538 HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, 539 NULL, 540 CLSCTX_INPROC_SERVER, 541 IID_PPV_ARGS(&pfd)); 510 HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, QT_IID_IFileOpenDialog, 511 reinterpret_cast<void**>(&pfd)); 542 512 543 513 if (SUCCEEDED(hr)) { … … 613 583 } 614 584 585 QString qt_win_CID_get_existing_directory(const QFileDialogArgs &args) 586 { 587 QString result; 588 QDialog modal_widget; 589 modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); 590 modal_widget.setParent(args.parent, Qt::Window); 591 QApplicationPrivate::enterModal(&modal_widget); 592 593 IFileOpenDialog *pfd = 0; 594 HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, 595 QT_IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd)); 596 597 if (SUCCEEDED(hr)) { 598 qt_win_set_IFileDialogOptions(pfd, args.selection, 599 args.directory, args.caption, 600 QStringList(), QFileDialog::ExistingFiles, 601 args.options); 602 603 // Set the FOS_PICKFOLDERS flag 604 DWORD newOptions; 605 hr = pfd->GetOptions(&newOptions); 606 newOptions |= FOS_PICKFOLDERS; 607 if (SUCCEEDED(hr) && SUCCEEDED((hr = pfd->SetOptions(newOptions)))) { 608 QWidget *parentWindow = args.parent; 609 if (parentWindow) 610 parentWindow = parentWindow->window(); 611 else 612 parentWindow = QApplication::activeWindow(); 613 614 // Show the file dialog. 615 hr = pfd->Show(parentWindow ? parentWindow->winId() : 0); 616 if (SUCCEEDED(hr)) { 617 // Retrieve the result 618 IShellItem *psi = 0; 619 hr = pfd->GetResult(&psi); 620 if (SUCCEEDED(hr)) { 621 // Retrieve the file name from shell item. 622 wchar_t *pszPath; 623 hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); 624 if (SUCCEEDED(hr)) { 625 result = QString::fromWCharArray(pszPath); 626 CoTaskMemFree(pszPath); 627 } 628 psi->Release(); // Free the current item. 629 } 630 } 631 } 632 } 633 QApplicationPrivate::leaveModal(&modal_widget); 634 635 qt_win_eatMouseMove(); 636 637 if (pfd) 638 pfd->Release(); 639 return result; 640 } 641 615 642 #endif 616 643 … … 644 671 // GetOpenFileName() will return only one folder name for all the files. To retrieve 645 672 // the correct path for all selected files, we have to use Common Item Dialog interfaces. 646 #if defined(USE_COMMON_ITEM_DIALOG)673 #ifndef Q_WS_WINCE 647 674 if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) 648 675 return qt_win_CID_get_open_file_names(args, initialDirectory, filterLst, selectedFilter, idx); … … 717 744 if (ptrSHGetPathFromIDList) { 718 745 wchar_t path[MAX_PATH]; 719 ptrSHGetPathFromIDList( LPITEMIDLIST(lParam), path);746 ptrSHGetPathFromIDList(qt_LPITEMIDLIST(lParam), path); 720 747 QString tmpStr = QString::fromWCharArray(path); 721 748 if (!tmpStr.isEmpty()) … … 729 756 } 730 757 731 #ifndef BIF_NEWDIALOGSTYLE 732 #define BIF_NEWDIALOGSTYLE 0x0040 // Use the new dialog layout with the ability to resize 758 QString qt_win_get_existing_directory(const QFileDialogArgs &args) 759 { 760 #ifndef Q_WS_WINCE 761 if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) 762 return qt_win_CID_get_existing_directory(args); 733 763 #endif 734 764 735 736 QString qt_win_get_existing_directory(const QFileDialogArgs &args)737 {738 765 QString currentDir = QDir::currentPath(); 739 766 QString result; … … 758 785 tTitle = args.caption; 759 786 760 #if !defined(Q_WS_WINCE)761 BROWSEINFO bi;762 #else763 787 qt_BROWSEINFO bi; 764 #endif765 788 766 789 Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created)); … … 776 799 qt_win_resolve_libs(); 777 800 if (ptrSHBrowseForFolder) { 778 LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder((BROWSEINFO*)&bi);801 qt_LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder(&bi); 779 802 if (pItemIDList) { 780 803 ptrSHGetPathFromIDList(pItemIDList, path);
Note:
See TracChangeset
for help on using the changeset viewer.