Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qfiledialog_win.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5353#include <qdir.h>
    5454#include <qstringlist.h>
    55 #include <qlibrary.h>
     55#include <private/qsystemlibrary_p.h>
     56#include "qfiledialog_win_p.h"
    5657
    5758#ifndef QT_NO_THREAD
     
    5960#endif
    6061
     62#ifdef Q_WS_WINCE
    6163#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>
     65bool qt_priv_ptr_valid = false;
     66#else
     67//we have to declare them here because they're not present for all SDK/compilers
     68static const IID   QT_IID_IFileOpenDialog  = {0xd57c7288, 0xd4ad, 0x4768, {0xbe, 0x02, 0x9d, 0x96, 0x95, 0x32, 0xd9, 0x60} };
     69static const IID   QT_IID_IShellItem       = {0x43826d1e, 0xe718, 0x42ee, {0xbc, 0x55, 0xa1, 0xe2, 0x61, 0xc3, 0x7b, 0xfe} };
     70static const CLSID QT_CLSID_FileOpenDialog = {0xdc1c5a9c, 0xe88a, 0x4dde, {0xa5, 0xa1, 0x60, 0xf8, 0x2a, 0x20, 0xae, 0xf7} };
    6571#endif
    6672
    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
     74typedef qt_LPITEMIDLIST (WINAPI *PtrSHBrowseForFolder)(qt_BROWSEINFO*);
    10175static PtrSHBrowseForFolder ptrSHBrowseForFolder = 0;
    102 typedef BOOL (WINAPI *PtrSHGetPathFromIDList)(LPITEMIDLIST,LPWSTR);
     76typedef BOOL (WINAPI *PtrSHGetPathFromIDList)(qt_LPITEMIDLIST, LPWSTR);
    10377static PtrSHGetPathFromIDList ptrSHGetPathFromIDList = 0;
    10478typedef HRESULT (WINAPI *PtrSHGetMalloc)(LPMALLOC *);
     
    127101        triedResolve = true;
    128102#if !defined(Q_WS_WINCE)
    129         QLibrary lib(QLatin1String("shell32"));
    130         ptrSHBrowseForFolder = (PtrSHBrowseForFolder) lib.resolve("SHBrowseForFolderW");
    131         ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList) lib.resolve("SHGetPathFromIDListW");
    132         ptrSHGetMalloc = (PtrSHGetMalloc) lib.resolve("SHGetMalloc");
     103        QSystemLibrary lib(L"shell32");
     104        ptrSHBrowseForFolder = (PtrSHBrowseForFolder)lib.resolve("SHBrowseForFolderW");
     105        ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList)lib.resolve("SHGetPathFromIDListW");
     106        ptrSHGetMalloc = (PtrSHGetMalloc)lib.resolve("SHGetMalloc");
    133107#else
    134108        // CE stores them in a different lib and does not use unicode version
    135         HINSTANCE handle = LoadLibraryW(L"Ceshell");
     109        HINSTANCE handle = LoadLibrary(L"Ceshell");
    136110        ptrSHBrowseForFolder = (PtrSHBrowseForFolder)GetProcAddress(handle, L"SHBrowseForFolder");
    137111        ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList)GetProcAddress(handle, L"SHGetPathFromIDList");
     
    245219
    246220    ofn->lStructSize = sizeof(OPENFILENAME);
    247     Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
    248221    ofn->hwndOwner = parent ? parent->winId() : 0;
    249222    ofn->lpstrFilter = (wchar_t*)tFilters.utf16();
     
    422395
    423396
    424 #if defined(USE_COMMON_ITEM_DIALOG)
     397#ifndef Q_WS_WINCE
    425398
    426399typedef HRESULT (WINAPI *PtrSHCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv);
     
    437410    if (!pSHCreateItemFromParsingName) {
    438411        // This function is available only in Vista & above.
    439         QLibrary shellLib(QLatin1String("Shell32"));
     412        QSystemLibrary shellLib(QLatin1String("Shell32"));
    440413        pSHCreateItemFromParsingName = (PtrSHCreateItemFromParsingName)
    441414            shellLib.resolve("SHCreateItemFromParsingName");
     
    470443    if (numFilters) {
    471444        wchar_t *szData = (wchar_t*)winfilters.utf16();
    472         COMDLG_FILTERSPEC *filterSpec = new COMDLG_FILTERSPEC[numFilters];
     445        qt_COMDLG_FILTERSPEC *filterSpec = new qt_COMDLG_FILTERSPEC[numFilters];
    473446        for(int i = 0; i<numFilters; i++) {
    474447            filterSpec[i].pszName = szData+offsets[i*2];
     
    482455    if (!tInitDir.isEmpty()) {
    483456        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));
    487459
    488460        if (SUCCEEDED(hr)) {
     
    523495}
    524496
    525 QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args,
     497static QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args,
    526498                                       QString *initialDirectory,
    527499                                       const QStringList &filterList,
     
    536508    // Multiple selection is allowed only in IFileOpenDialog.
    537509    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));
    542512
    543513    if (SUCCEEDED(hr)) {
     
    613583}
    614584
     585QString 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
    615642#endif
    616643
     
    644671    // GetOpenFileName() will return only one folder name for all the files. To retrieve
    645672    // 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
    647674    if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)
    648675        return qt_win_CID_get_open_file_names(args, initialDirectory, filterLst, selectedFilter, idx);
     
    717744        if (ptrSHGetPathFromIDList) {
    718745            wchar_t path[MAX_PATH];
    719             ptrSHGetPathFromIDList(LPITEMIDLIST(lParam), path);
     746            ptrSHGetPathFromIDList(qt_LPITEMIDLIST(lParam), path);
    720747            QString tmpStr = QString::fromWCharArray(path);
    721748            if (!tmpStr.isEmpty())
     
    729756}
    730757
    731 #ifndef BIF_NEWDIALOGSTYLE
    732 #define BIF_NEWDIALOGSTYLE     0x0040   // Use the new dialog layout with the ability to resize
     758QString 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);
    733763#endif
    734764
    735 
    736 QString qt_win_get_existing_directory(const QFileDialogArgs &args)
    737 {
    738765    QString currentDir = QDir::currentPath();
    739766    QString result;
     
    758785    tTitle = args.caption;
    759786
    760 #if !defined(Q_WS_WINCE)
    761     BROWSEINFO bi;
    762 #else
    763787    qt_BROWSEINFO bi;
    764 #endif
    765788
    766789    Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
     
    776799    qt_win_resolve_libs();
    777800    if (ptrSHBrowseForFolder) {
    778         LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder((BROWSEINFO*)&bi);
     801        qt_LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder(&bi);
    779802        if (pItemIDList) {
    780803            ptrSHGetPathFromIDList(pItemIDList, path);
Note: See TracChangeset for help on using the changeset viewer.