Ignore:
Timestamp:
Oct 21, 2000, 8:42:42 PM (25 years ago)
Author:
sandervl
Message:

Merged with latest Wine version (Wine 20001002 level (10-21-2000))

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comdlg32/filedlgbrowser.c

    r3256 r4511  
    1 /* $Id: filedlgbrowser.c,v 1.5 2000-03-28 15:26:48 cbratschi Exp $ */
    21/*
    32 *  Implementation of IShellBrowser for the File Open common dialog
     3 *
    44 *
    5  * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
    6  * Project Odin Software License can be found in LICENSE.TXT
    7  *
    8  *  Corel WINE 20000324 level
    95 */
    106
     
    2218#include "unknwn.h"
    2319#include "filedlgbrowser.h"
     20#include "windef.h"
     21#include "wingdi.h"
    2422#include "winuser.h"
     23#include "wine/winestring.h"
    2524#include "heap.h"
     25#include "shlguid.h"
    2626#include "wine/obj_dataobject.h"
    2727#include "debugtools.h"
    2828#include "cdlg.h"
    29 #include "wine/undocshell.h"
    30 
    31 DEFAULT_DEBUG_CHANNEL(commdlg)
    32 
    33 #define SETDefFormatEtc(fe,cf,med) \
    34 { \
    35     (fe).cfFormat = cf;\
    36     (fe).dwAspect = DVASPECT_CONTENT; \
    37     (fe).ptd =NULL;\
    38     (fe).tymed = med;\
    39     (fe).lindex = -1;\
    40 };
    41 
     29
     30DEFAULT_DEBUG_CHANNEL(commdlg);
    4231
    4332/**************************************************************************
     
    9685*   External Prototypes
    9786*/
    98 extern const char *FileOpenDlgInfosStr;
     87extern const char *FileOpenDlgInfosStr; 
    9988
    10089extern HRESULT          GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
     
    121110    FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndOwner,FileOpenDlgInfosStr);
    122111
    123     sb=(IShellBrowserImpl*)SHAlloc(sizeof(IShellBrowserImpl));
     112    sb=(IShellBrowserImpl*)COMDLG32_SHAlloc(sizeof(IShellBrowserImpl));
    124113
    125114    /* Initialisation of the member variables */
     
    131120    sb->lpVtbl2 = &IShellBrowserImpl_ICommDlgBrowser_Vtbl;
    132121
    133     COMDLG32_SHGetSpecialFolderLocation(hwndOwner,
    134                                CSIDL_DESKTOP,
     122    COMDLG32_SHGetSpecialFolderLocation(hwndOwner, CSIDL_DESKTOP,
    135123                               &fodInfos->ShellInfos.pidlAbsCurrent);
    136124
     
    155143*/
    156144HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
    157                                             REFIID riid,
     145                                            REFIID riid, 
    158146                                            LPVOID *ppvObj)
    159147{
     
    165153
    166154    if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
    167     { *ppvObj = This;
     155    { *ppvObj = This; 
    168156    }
    169157    else if(IsEqualIID(riid, &IID_IOleWindow))  /*IOleWindow*/
     
    207195    TRACE("(%p)\n", This);
    208196
    209     if (!--(This->ref))
    210     {
    211       COMDLG32_SHFree(This);
     197    if (!--(This->ref)) 
     198    { 
     199      HeapFree(GetProcessHeap(),0, This);
    212200      return 0;
    213201    }
     
    227215*
    228216*  Note : We will never be window less in the File Open dialog
    229 *
    230 */
    231 HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface,
     217* 
     218*/
     219HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser * iface, 
    232220                                           HWND * phwnd)
    233221{
     
    241229    *phwnd = This->hwndOwner;
    242230
    243     return (*phwnd) ? S_OK : E_UNEXPECTED;
     231    return (*phwnd) ? S_OK : E_UNEXPECTED; 
    244232
    245233}
     
    268256*  See Windows documentation on IShellBrowser::BrowseObject for more details
    269257*
    270 *  This function will override user specified flags and will always
    271 *  use SBSP_DEFBROWSER and SBSP_DEFMODE.
    272 */
    273 HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
    274                                               LPCITEMIDLIST pidl,
     258*  This function will override user specified flags and will always 
     259*  use SBSP_DEFBROWSER and SBSP_DEFMODE. 
     260*/
     261HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface, 
     262                                              LPCITEMIDLIST pidl, 
    275263                                              UINT wFlags)
    276264{
     
    280268    FileOpenDlgInfos *fodInfos;
    281269    LPITEMIDLIST pidlTmp;
    282 
    283     ICOM_THIS(IShellBrowserImpl, iface);
    284 
    285     TRACE("(%p)\n", This);
     270    HWND hwndView;
     271    HWND hDlgWnd;
     272    BOOL bViewHasFocus;
     273
     274    ICOM_THIS(IShellBrowserImpl, iface);
     275
     276    TRACE("(%p)(%p,0x%08x)\n", This, pidl, wFlags);
    286277
    287278    fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
     
    290281    if(wFlags & SBSP_RELATIVE)
    291282    {
    292 
     283       
    293284        /* SBSP_RELATIVE  A relative pidl (relative from the current folder) */
    294         hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
    295                                      pidl,
    296                                      NULL,
    297                                      &IID_IShellFolder,
    298                                      (LPVOID *)&psfTmp);
    299         if(FAILED(hRes))
     285        if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder,
     286             pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp)))
    300287        {
    301             return hRes;
     288            ERR("bind to object failed\n");
     289            return hRes;
    302290        }
    303291        /* create an absolute pidl */
    304292        pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent,
    305293                                                        (LPITEMIDLIST)pidl);
    306 
    307294    }
    308295    else if(wFlags & SBSP_PARENT)
    309296    {
    310297        /* Browse the parent folder (ignores the pidl) */
    311 
    312298        pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent);
    313299        psfTmp = GetShellFolderFromPidl(pidlTmp);
    314300
    315301    }
    316     else
     302    else /* SBSP_ABSOLUTE is 0x0000 */
    317303    {
    318304        /* An absolute pidl (relative from the desktop) */
     
    320306        psfTmp = GetShellFolderFromPidl(pidlTmp);
    321307    }
    322 
    323 
    324     /* Retrieve the IShellFolder interface of the pidl specified folder */
    325     if(!psfTmp)
    326         return E_FAIL;
    327 
    328     /* If the pidl to browse to is equal to the actual pidl ...
     308   
     309    if(!psfTmp) return E_FAIL;
     310
     311    /* If the pidl to browse to is equal to the actual pidl ...
    329312       do nothing and pretend you did it*/
    330313    if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent))
    331314    {
    332315        IShellFolder_Release(psfTmp);
    333         COMDLG32_SHFree(pidlTmp);
     316        COMDLG32_SHFree(pidlTmp);
    334317        return NOERROR;
    335318    }
    336 #ifdef SHELL_NO_DESKTOP
    337 
    338     if(pidlTmp->mkid.cb == 0x00)
    339     {
    340         IShellFolder_Release(psfTmp);
    341                 COMDLG32_SHFree(pidlTmp);
    342         return NOERROR;
    343     }
    344 #endif
    345 
    346     /* Release the current fodInfos->Shell.FOIShellFolder and update its value */
    347     IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
     319
     320    /* Release the current DataObject */
     321    if (fodInfos->Shell.FOIDataObject)
     322    {
     323      IDataObject_Release(fodInfos->Shell.FOIDataObject);
     324      fodInfos->Shell.FOIDataObject = NULL;
     325    }
     326
     327    /* Create the associated view */
     328    if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner,
     329           &IID_IShellView, (LPVOID *)&psvTmp))) return hRes;
     330
     331    /* Check if listview has focus */
     332    bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
     333
     334    /* Get the foldersettings from the old view */
     335    if(fodInfos->Shell.FOIShellView)
     336      IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings);
     337
     338    /* Release the old fodInfos->Shell.FOIShellView and update its value.
     339    We have to update this early since ShellView_CreateViewWindow of native
     340    shell32 calls OnStateChange and needs the correct view here.*/
     341    if(fodInfos->Shell.FOIShellView)
     342    {
     343      IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
     344      IShellView_Release(fodInfos->Shell.FOIShellView);
     345    }
     346    fodInfos->Shell.FOIShellView = psvTmp;
     347
     348    /* Release old FOIShellFolder and update its value */
     349    if (fodInfos->Shell.FOIShellFolder)
     350      IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
    348351    fodInfos->Shell.FOIShellFolder = psfTmp;
    349352
    350     /* Create the associated view */
    351     if(SUCCEEDED(hRes = IShellFolder_CreateViewObject(psfTmp,
    352                                                       fodInfos->ShellInfos.hwndOwner,
    353                                                       &IID_IShellView,
    354                                                       (LPVOID *)&psvTmp)))
    355     {
    356         HWND hwndView;
    357         HWND hDlgWnd;
    358         BOOL bViewHasFocus;
    359 
    360         /* Check if listview has focus */
    361         bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus());
    362 
    363         /* Get the foldersettings from the old view */
    364         if(fodInfos->Shell.FOIShellView)
    365         {
    366           IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView,
    367                                   &fodInfos->ShellInfos.folderSettings);
    368         }
    369 
    370         /* Create the window */
    371         if(SUCCEEDED(hRes = IShellView_CreateViewWindow(psvTmp,
    372                                           NULL,
    373                                           &fodInfos->ShellInfos.folderSettings,
    374                                           fodInfos->Shell.FOIShellBrowser,
    375                                           &fodInfos->ShellInfos.rectView,
    376                                           &hwndView)))
    377         {
    378             /* Fit the created view in the appropriate RECT */
    379             MoveWindow(hwndView,
    380                        fodInfos->ShellInfos.rectView.left,
    381                        fodInfos->ShellInfos.rectView.top,
    382                        fodInfos->ShellInfos.rectView.right-fodInfos->ShellInfos.rectView.left,
    383                        fodInfos->ShellInfos.rectView.bottom-fodInfos->ShellInfos.rectView.top,
    384                        FALSE);
    385 
    386             /* Select the new folder in the Look In combo box of the Open file dialog */
    387 
    388             FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,pidlTmp);
    389 
    390             /* Release old pidlAbsCurrent memory and update its value */
    391             COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
    392             fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
    393 
    394             /* Release the current fodInfos->Shell.FOIShellView and update its value */
    395             if(fodInfos->Shell.FOIShellView)
    396             {
    397                 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
    398                 IShellView_Release(fodInfos->Shell.FOIShellView);
    399             }
    400 #if 0
    401             ShowWindow(fodInfos->ShellInfos.hwndView,SW_HIDE);
    402 #endif
    403             fodInfos->Shell.FOIShellView = psvTmp;
    404 
    405             fodInfos->ShellInfos.hwndView = hwndView;
    406 
    407             /* changes the tab order of the ListView to reflect the window's File Dialog */
    408             hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
    409             SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
    410 
    411             /* Since we destroyed the old view if it had focus set focus
    412                to the newly created view */
    413             if (bViewHasFocus)
    414                 SetFocus(fodInfos->ShellInfos.hwndView);
    415 
    416             return NOERROR;
    417         }
    418     }
    419 
     353    /* Release old pidlAbsCurrent and update its value */
     354    COMDLG32_SHFree((LPVOID)fodInfos->ShellInfos.pidlAbsCurrent);
     355    fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp;
     356
     357    /* Create the window */
     358    TRACE("create view window\n");
     359    if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL,
     360         &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser,
     361         &fodInfos->ShellInfos.rectView, &hwndView))) return hRes;
     362
     363    fodInfos->ShellInfos.hwndView = hwndView;
     364
     365    /* Select the new folder in the Look In combo box of the Open file dialog */
    420366    FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent);
    421     return hRes;
     367
     368    /* changes the tab order of the ListView to reflect the window's File Dialog */
     369    hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN);
     370    SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
     371
     372    /* Since we destroyed the old view if it had focus set focus to the newly created view */
     373    if (bViewHasFocus)
     374      SetFocus(fodInfos->ShellInfos.hwndView);
     375
     376    return hRes;
    422377}
    423378
     
    425380*  IShellBrowserImpl_EnableModelessSB
    426381*/
    427 HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
     382HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,   
    428383                                              BOOL fEnable)
    429 
     384                                             
    430385{
    431386    ICOM_THIS(IShellBrowserImpl, iface);
     
    440395*  IShellBrowserImpl_GetControlWindow
    441396*/
    442 HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
    443                                               UINT id,
     397HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,   
     398                                              UINT id,   
    444399                                              HWND *lphwnd)
    445 
     400                                             
    446401{
    447402    ICOM_THIS(IShellBrowserImpl, iface);
     
    456411*/
    457412HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
    458                                                 DWORD grfMode,
     413                                                DWORD grfMode,   
    459414                                                LPSTREAM *ppStrm)
    460 
    461 {
    462     ICOM_THIS(IShellBrowserImpl, iface);
    463 
    464     TRACE("(%p)\n", This);
    465 
    466     /* Feature not implemented */
    467     return E_NOTIMPL;
    468 }
     415                                             
     416{
     417    ICOM_THIS(IShellBrowserImpl, iface);
     418
     419    TRACE("(%p)\n", This);
     420
     421    /* Feature not implemented */
     422    return E_NOTIMPL;
     423}       
    469424/**************************************************************************
    470425*  IShellBrowserImpl_InsertMenusSB
     
    473428                                           HMENU hmenuShared,
    474429                                           LPOLEMENUGROUPWIDTHS lpMenuWidths)
    475 
     430                                             
    476431{
    477432    ICOM_THIS(IShellBrowserImpl, iface);
     
    487442HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
    488443                                                IShellView *ppshv)
    489 
    490 {
    491     ICOM_THIS(IShellBrowserImpl, iface);
    492 
    493     TRACE("(%p)\n", This);
    494 
    495     /* Feature not implemented */
    496     return E_NOTIMPL;
    497 }
     444                                             
     445{
     446    ICOM_THIS(IShellBrowserImpl, iface);
     447
     448    TRACE("(%p)\n", This);
     449
     450    /* Feature not implemented */
     451    return E_NOTIMPL;
     452}   
    498453/**************************************************************************
    499454*  IShellBrowserImpl_QueryActiveShellView
     
    501456HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
    502457                                                  IShellView **ppshv)
    503 
     458                                             
    504459{
    505460    ICOM_THIS(IShellBrowserImpl, iface);
     
    517472    IShellView_AddRef(fodInfos->Shell.FOIShellView);
    518473    return NOERROR;
    519 }
     474}   
    520475/**************************************************************************
    521476*  IShellBrowserImpl_RemoveMenusSB
     
    523478HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
    524479                                           HMENU hmenuShared)
    525 
    526 {
    527     ICOM_THIS(IShellBrowserImpl, iface);
    528 
    529     TRACE("(%p)\n", This);
    530 
    531     /* Feature not implemented */
    532     return E_NOTIMPL;
    533 }
     480                                             
     481{
     482    ICOM_THIS(IShellBrowserImpl, iface);
     483
     484    TRACE("(%p)\n", This);
     485
     486    /* Feature not implemented */
     487    return E_NOTIMPL;
     488}   
    534489/**************************************************************************
    535490*  IShellBrowserImpl_SendControlMsg
    536491*/
    537 HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
    538                                             UINT id,
    539                                             UINT uMsg,
    540                                             WPARAM wParam,
     492HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,   
     493                                            UINT id,   
     494                                            UINT uMsg,   
     495                                            WPARAM wParam,   
    541496                                            LPARAM lParam,
    542497                                            LRESULT *pret)
    543 
     498                                             
    544499{
    545500    ICOM_THIS(IShellBrowserImpl, iface);
    546501    LRESULT lres;
    547 
     502   
    548503    TRACE("(%p)->(0x%08x 0x%08x 0x%08x 0x%08lx %p)\n", This, id, uMsg, wParam, lParam, pret);
    549504
     
    552507      case FCW_TOOLBAR:
    553508        lres = SendDlgItemMessageA( This->hwndOwner, IDC_TOOLBAR, uMsg, wParam, lParam);
    554         break;
     509        break;
    555510      default:
    556511        FIXME("ctrl id: %x\n", id);
     
    564519*/
    565520HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
    566                                        HMENU hmenuShared,
     521                                       HMENU hmenuShared,   
    567522                                       HOLEMENU holemenuReserved,
    568523                                       HWND hwndActiveObject)
    569 
    570 {
    571     ICOM_THIS(IShellBrowserImpl, iface);
    572 
    573     TRACE("(%p)\n", This);
    574 
    575     /* Feature not implemented */
    576     return E_NOTIMPL;
    577 }
     524                                             
     525{
     526    ICOM_THIS(IShellBrowserImpl, iface);
     527
     528    TRACE("(%p)\n", This);
     529
     530    /* Feature not implemented */
     531    return E_NOTIMPL;
     532}   
    578533/**************************************************************************
    579534*  IShellBrowserImpl_SetStatusTextSB
     
    581536HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
    582537                                             LPCOLESTR lpszStatusText)
    583 
    584 {
    585     ICOM_THIS(IShellBrowserImpl, iface);
    586 
    587     TRACE("(%p)\n", This);
    588 
    589     /* Feature not implemented */
    590     return E_NOTIMPL;
    591 }
     538                                             
     539{
     540    ICOM_THIS(IShellBrowserImpl, iface);
     541
     542    TRACE("(%p)\n", This);
     543
     544    /* Feature not implemented */
     545    return E_NOTIMPL;
     546}   
    592547/**************************************************************************
    593548*  IShellBrowserImpl_SetToolbarItems
    594549*/
    595550HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
    596                                              LPTBBUTTON lpButtons,
    597                                              UINT nButtons,
     551                                             LPTBBUTTON lpButtons,   
     552                                             UINT nButtons,   
    598553                                             UINT uFlags)
    599 
    600 {
    601     ICOM_THIS(IShellBrowserImpl, iface);
    602 
    603     TRACE("(%p)\n", This);
    604 
    605     /* Feature not implemented */
    606     return E_NOTIMPL;
    607 }
     554                                             
     555{
     556    ICOM_THIS(IShellBrowserImpl, iface);
     557
     558    TRACE("(%p)\n", This);
     559
     560    /* Feature not implemented */
     561    return E_NOTIMPL;
     562}   
    608563/**************************************************************************
    609564*  IShellBrowserImpl_TranslateAcceleratorSB
    610565*/
    611566HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
    612                                                     LPMSG lpmsg,
     567                                                    LPMSG lpmsg,   
    613568                                                    WORD wID)
    614 
     569                                             
    615570{
    616571    ICOM_THIS(IShellBrowserImpl, iface);
     
    630585*/
    631586HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_QueryInterface(ICommDlgBrowser *iface,
    632                                             REFIID riid,
     587                                            REFIID riid, 
    633588                                            LPVOID *ppvObj)
    634589{
     
    678633    TRACE("(%p)\n", This);
    679634
    680     fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
    681 
     635    fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr); 
     636   
    682637    /* If the selected object is not a folder, send a IDOK command to parent window */
    683     pidl = GetSelectedPidl(ppshv);
    684     if (pidl)
     638    if((pidl = GetPidlFromDataObject(fodInfos->Shell.FOIDataObject, 1)))
    685639    {
    686640        HRESULT hRes;
     
    688642        ULONG  ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
    689643        IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
    690         if (ulAttr)
    691             hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
    692         /* Tell the dialog that the user selected a file */
     644        if (ulAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER) )
     645        {
     646          hRes = IShellBrowser_BrowseObject((IShellBrowser *)This,pidl,SBSP_RELATIVE);
     647        }
    693648        else
    694         {
    695             hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
    696         }
     649        {
     650          /* Tell the dialog that the user selected a file */
     651          hRes = PostMessageA(This->hwndOwner, WM_COMMAND, IDOK, 0L);
     652        }
    697653
    698654        /* Free memory used by pidl */
     
    715671    _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
    716672
    717     TRACE("(%p)\n", This);
     673    TRACE("(%p shv=%p)\n", This, ppshv);
    718674
    719675    switch (uChange)
     
    721677        case CDBOSC_SETFOCUS:
    722678             /* FIXME: Reset the default button.
    723                 This should be taken care of by defdlg. If control
    724                 other than button receives focus the default button
    725                 should be restored. */
     679                This should be taken care of by defdlg. If control
     680                other than button receives focus the default button
     681                should be restored. */
    726682             SendMessageA(This->hwndOwner, DM_SETDEFID, IDOK, 0);
     683
    727684            break;
    728         case CDBOSC_KILLFOCUS:
    729             {
    730                 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
    731                 if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
    732                     SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
     685        case CDBOSC_KILLFOCUS: 
     686            {
     687                FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
     688                if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
     689                    SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner,IDOK,"&Save");
    733690            }
    734691            break;
     
    736693            return IShellBrowserImpl_ICommDlgBrowser_OnSelChange(iface,ppshv);
    737694        case CDBOSC_RENAME:
     695            /* nothing to do */
    738696            break;
    739697    }
    740698
    741     return NOERROR;
     699    return NOERROR;     
     700}
     701
     702/* copied from shell32 to avoid linking to it */
     703static HRESULT COMDLG32_StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
     704{
     705        TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
     706
     707        switch (src->uType)
     708        {
     709          case STRRET_WSTR:
     710            lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
     711            COMDLG32_SHFree(src->u.pOleStr);
     712            break;
     713
     714          case STRRET_CSTRA:
     715            lstrcpynAtoW((LPWSTR)dest, src->u.cStr, len);
     716            break;
     717
     718          case STRRET_OFFSETA:
     719            if (pidl)
     720            {
     721              lstrcpynAtoW((LPWSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
     722            }
     723            break;
     724
     725          default:
     726            FIXME("unknown type!\n");
     727            if (len)
     728            { *(LPSTR)dest = '\0';
     729            }
     730            return(FALSE);
     731        }
     732        return S_OK;
    742733}
    743734/**************************************************************************
    744735*  IShellBrowserImpl_ICommDlgBrowser_IncludeObject
    745736*/
    746 HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface,
     737HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_IncludeObject(ICommDlgBrowser *iface, 
    747738                                                               IShellView * ppshv,
    748739                                                               LPCITEMIDLIST pidl)
     
    756747
    757748    TRACE("(%p)\n", This);
    758 //CB: slow!!!
     749
    759750    fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
    760751
    761752    ulAttr = SFGAO_HIDDEN | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR | SFGAO_LINK;
    762753    IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidl, &ulAttr);
    763 
     754   
    764755    if( (ulAttr & SFGAO_HIDDEN)                                         /* hidden */
    765756      | !(ulAttr & (SFGAO_FILESYSTEM | SFGAO_FILESYSANCESTOR))) /* special folder */
    766757        return S_FALSE;
     758
    767759    /* always include directorys and links */
    768     if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK))
     760    if(ulAttr & (SFGAO_FOLDER | SFGAO_LINK)) 
    769761        return S_OK;
     762
    770763    /* Check if there is a mask to apply if not */
    771     if(!fodInfos->ShellInfos.lpstrCurrentFilter ||
    772        !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
     764    if(!fodInfos->ShellInfos.lpstrCurrentFilter || !lstrlenW(fodInfos->ShellInfos.lpstrCurrentFilter))
    773765        return S_OK;
    774766
    775     if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_FORPARSING, &str)))
    776     {
    777       if (SUCCEEDED(StrRetToBufW(&str, pidl,szPathW, MAX_PATH)))
     767    if (SUCCEEDED(IShellFolder_GetDisplayNameOf(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str)))
     768    {
     769      if (SUCCEEDED(COMDLG32_StrRetToStrNW(szPathW, MAX_PATH, &str, pidl)))
    778770      {
    779           if (COMDLG32_PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
    780             return S_OK;
     771          if (COMDLG32_PathMatchSpecW(szPathW, fodInfos->ShellInfos.lpstrCurrentFilter))
     772          return S_OK;
    781773      }
    782774    }
    783775    return S_FALSE;
     776
    784777}
    785778
    786779/**************************************************************************
    787780*  IShellBrowserImpl_ICommDlgBrowser_OnSelChange
    788 */
     781*/ 
    789782HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IShellView *ppshv)
    790783{
    791     ULONG             uAttr;
    792784    FileOpenDlgInfos *fodInfos;
    793     UINT              nFiles = 0;                  /* Intial to zero */
    794     UINT              nCurrLength;
    795     UINT              nFileToOpen;
    796     UINT              nAllLength = 2;              /* Include intial '"' and final NULL */
    797     UINT              nSize = MAX_PATH;
    798     UINT              nFileSelected = 0;
    799     LPITEMIDLIST      pidlSelection;
    800     LPSTR             lpstrTemp = NULL;
    801     LPSTR             lpstrAllFile = NULL;
    802     char              lpstrCurrFile[MAX_PATH];
    803785
    804786    _ICOM_THIS_FromICommDlgBrowser(IShellBrowserImpl,iface);
    805787
    806788    fodInfos = (FileOpenDlgInfos *) GetPropA(This->hwndOwner,FileOpenDlgInfosStr);
    807     TRACE("(%p)\n", This);
    808 
    809     /* Locate memory and Get selected item counter */
    810     if((lpstrAllFile = (LPSTR)SHAlloc(nSize * sizeof(char))) != NULL)
    811     {
    812         ZeroMemory(lpstrAllFile, nSize * sizeof(char));
    813         *lpstrAllFile =  '\"';
    814         lpstrTemp = lpstrAllFile + 1;
    815         nFileSelected = GetNumSelected(fodInfos->Shell.FOIShellView);     /* Get all selected counter */
    816     }
    817 
    818     /* Count all selected files we have */
    819     for(nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++)
    820     {   /* get the file selected */
    821         pidlSelection = NULL;
    822         uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
    823         ZeroMemory(lpstrCurrFile, MAX_PATH * sizeof(char));
    824         EnumSelectedPidls(fodInfos->Shell.FOIShellView, nFileToOpen, &pidlSelection);
    825 
    826         /* get the file name and attrib of the selected files*/
    827         GetName(fodInfos->Shell.FOIShellFolder, pidlSelection, SHGDN_NORMAL, lpstrCurrFile);
    828         IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder, 1, &pidlSelection, &uAttr);
    829         COMDLG32_SHFree((LPVOID) pidlSelection);
    830 
    831         if(!uAttr)
    832         {   /* Get the new file name */
    833             nCurrLength = lstrlenA(lpstrCurrFile);
    834             if(nAllLength + nCurrLength + 3 > nSize)
    835             {   /* increase the memory and transfer string to new location */
    836                 nSize += MAX_PATH;
    837                 if((lpstrTemp = (LPSTR)SHAlloc(nSize * sizeof(char))) != NULL)
    838                 {   /* Transfer old file names */
    839                     ZeroMemory(lpstrTemp, nSize * sizeof(char));
    840                     lstrcpyA(lpstrTemp, lpstrAllFile);
    841                     SHFree(lpstrAllFile);
    842                     lpstrAllFile = lpstrTemp;
    843                     lpstrTemp = lpstrAllFile + nAllLength - 1;
    844                 }
    845                 else
    846                 {   /* if failure, stop the loop to get filename */
    847                     nFileSelected = 0;
    848                 }
    849             }
    850 
    851             if(lpstrTemp != NULL)
    852             {   /* Add the new file name */
    853                 nFiles++;
    854                 lstrcpyA(lpstrTemp, lpstrCurrFile);
    855                 *(lpstrTemp + nCurrLength) = '\"';
    856                 *(lpstrTemp + nCurrLength + 1) = ' ';
    857                 *(lpstrTemp + nCurrLength + 2) = '\"';
    858                 nAllLength += nCurrLength + 3;
    859                 lpstrTemp = lpstrAllFile + nAllLength - 1;
    860             }
    861         }
    862     }
    863 
    864     if(lpstrAllFile)
    865     {
    866         if(nFiles > 1)
    867         {
    868             *(lpstrTemp - 2) = '\0';
    869             SetWindowTextA(fodInfos->DlgInfos.hwndFileName, lpstrAllFile);
    870         }
    871         else
    872         {
    873             *(lpstrTemp - 3) = '\0';
    874             SetWindowTextA(fodInfos->DlgInfos.hwndFileName, lpstrAllFile + 1);
    875         }
    876 
    877         fodInfos->DlgInfos.dwDlgProp |= FODPROP_USEVIEW;
    878         SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
    879         SHFree( lpstrAllFile );
    880     }
    881     else
    882     {
    883         SetWindowTextA(fodInfos->DlgInfos.hwndFileName, "");
    884     }
    885 
    886     if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
    887         SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner, IDOK, "&Save");
    888     else
    889         SetDlgItemTextA(fodInfos->ShellInfos.hwndOwner, IDOK, "&Open");
    890 
    891     fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
    892 
    893     return nFileSelected ? S_OK : E_FAIL;
    894 }
    895 
    896 /***********************************************************************
    897  *          GetSelectedPidl
    898  *
    899  * Return the pidl of the first selected item in the view
    900  */
    901 LPITEMIDLIST GetSelectedPidl(IShellView *ppshv)
    902 {
    903 
    904     IDataObject *doSelected;
    905     LPITEMIDLIST pidlSelected = NULL;
    906 
    907     TRACE("sv=%p\n", ppshv);
    908 
    909     /* Get an IDataObject from the view */
    910     if(SUCCEEDED(IShellView_GetItemObject(ppshv,
    911                                           SVGIO_SELECTION,
    912                                           &IID_IDataObject,
    913                                           (LPVOID *)&doSelected)))
    914     {
    915         STGMEDIUM medium;
    916         FORMATETC formatetc;
    917 
    918         /* Set the FORMATETC structure*/
    919         SETDefFormatEtc(formatetc,
    920                         RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
    921                         TYMED_HGLOBAL);
    922 
    923         /* Get the pidl from IDataObject */
    924         if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
    925         {
    926             LPIDA cida = GlobalLock(medium.u.hGlobal);
    927             TRACE("cida=%p\n", cida);
    928             pidlSelected =  COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[1]]));
    929 
    930             if(medium.pUnkForRelease)
    931                 IUnknown_Release(medium.pUnkForRelease);
    932             else
    933             {
    934               GlobalUnlock(medium.u.hGlobal);
    935               GlobalFree(medium.u.hGlobal);
    936             }
    937         }
    938         IDataObject_Release(doSelected);
    939         return pidlSelected;
    940     }
    941 
    942     return NULL;
    943 }
    944 
    945 /***********************************************************************
    946  *          EnumSelectedPidls
    947  *
    948  * Return the pidl(s) of the selected item(s) in the view.
    949  *
    950 */
    951 BOOL EnumSelectedPidls( IShellView *ppshv,  /*[in]*/
    952                         UINT nPidlIndex,  /*[in]*/
    953                         LPITEMIDLIST *pidlSelected /*[out]*/ )
    954 {
    955 
    956     IDataObject *doSelected;
    957     BOOL retVal = TRUE;
    958 
    959     /* Get an IDataObject from the view */
    960     if(SUCCEEDED(IShellView_GetItemObject(ppshv,
    961                                           SVGIO_SELECTION,
    962                                           &IID_IDataObject,
    963                                           (LPVOID *)&doSelected)))
    964     {
    965         STGMEDIUM medium;
    966         FORMATETC formatetc;
    967 
    968         /* Set the FORMATETC structure*/
    969         SETDefFormatEtc(formatetc,
    970                         RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
    971                         TYMED_HGLOBAL);
    972 
    973         /* Get the pidls from IDataObject */
    974         if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
    975         {
    976             LPIDA cida = GlobalLock(medium.u.hGlobal);
    977             if(nPidlIndex < cida->cidl)
    978             {
    979                 *pidlSelected = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex + 1]]));
    980             }
    981             else
    982             {
    983                 retVal = FALSE;
    984             }
    985 
    986             if(medium.pUnkForRelease)
    987             {
    988                 IUnknown_Release(medium.pUnkForRelease);
    989             }
    990             else
    991             {
    992                 GlobalUnlock(medium.u.hGlobal);
    993                 GlobalFree(medium.u.hGlobal);
    994             }
    995         }
    996         IDataObject_Release(doSelected);
    997         return retVal;
    998     }
    999     return FALSE;
    1000 }
    1001 
    1002 /***********************************************************************
    1003  *          GetNumSelected
    1004  *
    1005  * Return the number of selected items in the view.
    1006  *
    1007 */
    1008 UINT GetNumSelected( IShellView *ppshv )
    1009 {
    1010     IDataObject *doSelected;
    1011     UINT retVal = 0;
    1012 
    1013        /* Get an IDataObject from the view */
    1014     if(SUCCEEDED(IShellView_GetItemObject(ppshv,
    1015                                           SVGIO_SELECTION,
    1016                                           &IID_IDataObject,
    1017                                           (LPVOID *)&doSelected)))
    1018     {
    1019         STGMEDIUM medium;
    1020         FORMATETC formatetc;
    1021 
    1022         /* Set the FORMATETC structure*/
    1023         SETDefFormatEtc(formatetc,
    1024                         RegisterClipboardFormatA(CFSTR_SHELLIDLIST),
    1025                         TYMED_HGLOBAL);
    1026 
    1027         /* Get the pidls from IDataObject */
    1028         if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
    1029         {
    1030             LPIDA cida = GlobalLock(medium.u.hGlobal);
    1031             retVal = cida->cidl;
    1032 
    1033             if(medium.pUnkForRelease)
    1034                 IUnknown_Release(medium.pUnkForRelease);
    1035             else
    1036             {
    1037                 GlobalUnlock(medium.u.hGlobal);
    1038                 GlobalFree(medium.u.hGlobal);
    1039             }
    1040         }
    1041         IDataObject_Release(doSelected);
    1042         return retVal;
    1043     }
    1044 
    1045     return 0;
    1046 }
    1047 
    1048 
    1049 
     789    TRACE("(%p do=%p view=%p)\n", This, fodInfos->Shell.FOIDataObject, fodInfos->Shell.FOIShellView);
     790   
     791    /* release old selections */
     792    if (fodInfos->Shell.FOIDataObject)
     793      IDataObject_Release(fodInfos->Shell.FOIDataObject);
     794   
     795    /* get a new DataObject from the ShellView */
     796    if(FAILED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, SVGIO_SELECTION,
     797                              &IID_IDataObject, (LPVOID*)&fodInfos->Shell.FOIDataObject)))
     798      return E_FAIL;
     799                                         
     800    FILEDLG95_FILENAME_FillFromSelection(This->hwndOwner);
     801
     802    SendCustomDlgNotificationMessage(This->hwndOwner, CDN_SELCHANGE);
     803    return S_OK;
     804}
     805
Note: See TracChangeset for help on using the changeset viewer.