| 1 | /* | 
|---|
| 2 | * COMMDLG - File Open Dialogs Win95 look and feel | 
|---|
| 3 | * | 
|---|
| 4 | * FIXME: The whole concept of handling unicode is badly broken. | 
|---|
| 5 | *      many hook-messages expecting a pointer to a | 
|---|
| 6 | *      OPENFILENAMEA or W structure. With the current architecture | 
|---|
| 7 | *      we would have to convert the beast at every call to a hook. | 
|---|
| 8 | *      we have to find a better solution but if would likely cause | 
|---|
| 9 | *      a complete rewrite with after we shouldhandle the | 
|---|
| 10 | *      OPENFILENAME structure without any converting (jsch). | 
|---|
| 11 | * | 
|---|
| 12 | * FIXME: any hook gets a OPENFILENAMEA structure | 
|---|
| 13 | * | 
|---|
| 14 | * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too | 
|---|
| 15 | * | 
|---|
| 16 | * FIXME: old style hook messages are not implemented (except FILEOKSTRING) | 
|---|
| 17 | * | 
|---|
| 18 | * FIXME: lpstrCustomFilter not handled | 
|---|
| 19 | * | 
|---|
| 20 | * FIXME: if the size of lpstrFile (nMaxFile) is too small the first | 
|---|
| 21 | * two bytes of lpstrFile should contain the needed size | 
|---|
| 22 | * | 
|---|
| 23 | * FIXME: algorithm for selecting the initial directory is too simple | 
|---|
| 24 | * | 
|---|
| 25 | * FIXME: add to recent docs | 
|---|
| 26 | * | 
|---|
| 27 | * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT, | 
|---|
| 28 | * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT, | 
|---|
| 29 | * OFN_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN, | 
|---|
| 30 | * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS | 
|---|
| 31 | * | 
|---|
| 32 | * FIXME: lCustData for lpfnHook (WM_INITDIALOG) | 
|---|
| 33 | * | 
|---|
| 34 | * | 
|---|
| 35 | */ | 
|---|
| 36 | #ifdef __WIN32OS2__ | 
|---|
| 37 | #include <windef.h> | 
|---|
| 38 | #include <winbase.h> | 
|---|
| 39 | #include <wingdi.h> | 
|---|
| 40 | #include <winuser.h> | 
|---|
| 41 | #include <heapstring.h> | 
|---|
| 42 | #include <misc.h> | 
|---|
| 43 | #include <win\shlwapi.h> | 
|---|
| 44 |  | 
|---|
| 45 | #define MapHModuleSL(a) a | 
|---|
| 46 | #define MapHModuleLS(a) a | 
|---|
| 47 | #endif | 
|---|
| 48 |  | 
|---|
| 49 | #include <ctype.h> | 
|---|
| 50 | #include <stdlib.h> | 
|---|
| 51 | #include <stdio.h> | 
|---|
| 52 | #include <string.h> | 
|---|
| 53 |  | 
|---|
| 54 | #include "winbase.h" | 
|---|
| 55 | #include "ntddk.h" | 
|---|
| 56 | #include "wine/winestring.h" | 
|---|
| 57 | #include "ldt.h" | 
|---|
| 58 | #include "heap.h" | 
|---|
| 59 | #include "commdlg.h" | 
|---|
| 60 | #include "dlgs.h" | 
|---|
| 61 | #include "cdlg.h" | 
|---|
| 62 | #include "debugtools.h" | 
|---|
| 63 | #include "cderr.h" | 
|---|
| 64 | #include "tweak.h" | 
|---|
| 65 | #include "winnls.h" | 
|---|
| 66 | #include "shellapi.h" | 
|---|
| 67 | #include "shlguid.h" | 
|---|
| 68 | #include "filedlgbrowser.h" | 
|---|
| 69 | #include "shlwapi.h" | 
|---|
| 70 | #include "wine/obj_contextmenu.h" | 
|---|
| 71 |  | 
|---|
| 72 | DEFAULT_DEBUG_CHANNEL(commdlg); | 
|---|
| 73 |  | 
|---|
| 74 | #define UNIMPLEMENTED_FLAGS \ | 
|---|
| 75 | (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\ | 
|---|
| 76 | OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\ | 
|---|
| 77 | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\ | 
|---|
| 78 | OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/) | 
|---|
| 79 |  | 
|---|
| 80 | #define IsHooked(fodInfos) \ | 
|---|
| 81 | ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook) | 
|---|
| 82 | /*********************************************************************** | 
|---|
| 83 | * Data structure and global variables | 
|---|
| 84 | */ | 
|---|
| 85 | typedef struct SFolder | 
|---|
| 86 | { | 
|---|
| 87 | int m_iImageIndex;    /* Index of picture in image list */ | 
|---|
| 88 | HIMAGELIST hImgList; | 
|---|
| 89 | int m_iIndent;      /* Indentation index */ | 
|---|
| 90 | LPITEMIDLIST pidlItem;  /* absolute pidl of the item */ | 
|---|
| 91 |  | 
|---|
| 92 | } SFOLDER,*LPSFOLDER; | 
|---|
| 93 |  | 
|---|
| 94 | typedef struct tagLookInInfo | 
|---|
| 95 | { | 
|---|
| 96 | int iMaxIndentation; | 
|---|
| 97 | UINT uSelectedItem; | 
|---|
| 98 | } LookInInfos; | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | /*********************************************************************** | 
|---|
| 102 | * Defines and global variables | 
|---|
| 103 | */ | 
|---|
| 104 |  | 
|---|
| 105 | /* Draw item constant */ | 
|---|
| 106 | #define ICONWIDTH 18 | 
|---|
| 107 | #define XTEXTOFFSET 3 | 
|---|
| 108 |  | 
|---|
| 109 | /* AddItem flags*/ | 
|---|
| 110 | #define LISTEND -1 | 
|---|
| 111 |  | 
|---|
| 112 | /* SearchItem methods */ | 
|---|
| 113 | #define SEARCH_PIDL 1 | 
|---|
| 114 | #define SEARCH_EXP  2 | 
|---|
| 115 | #define ITEM_NOTFOUND -1 | 
|---|
| 116 |  | 
|---|
| 117 | /* Undefined windows message sent by CreateViewObject*/ | 
|---|
| 118 | #define WM_GETISHELLBROWSER  WM_USER+7 | 
|---|
| 119 |  | 
|---|
| 120 | /* NOTE | 
|---|
| 121 | * Those macros exist in windowsx.h. However, you can't really use them since | 
|---|
| 122 | * they rely on the UNICODE defines and can't be used inside Wine itself. | 
|---|
| 123 | */ | 
|---|
| 124 |  | 
|---|
| 125 | /* Combo box macros */ | 
|---|
| 126 | #define CBAddString(hwnd,str) \ | 
|---|
| 127 | SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str); | 
|---|
| 128 |  | 
|---|
| 129 | #define CBInsertString(hwnd,str,pos) \ | 
|---|
| 130 | SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str); | 
|---|
| 131 |  | 
|---|
| 132 | #define CBDeleteString(hwnd,pos) \ | 
|---|
| 133 | SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0); | 
|---|
| 134 |  | 
|---|
| 135 | #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \ | 
|---|
| 136 | SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr); | 
|---|
| 137 |  | 
|---|
| 138 | #define CBGetItemDataPtr(hwnd,iItemId) \ | 
|---|
| 139 | SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0) | 
|---|
| 140 |  | 
|---|
| 141 | #define CBGetLBText(hwnd,iItemId,str) \ | 
|---|
| 142 | SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str); | 
|---|
| 143 |  | 
|---|
| 144 | #define CBGetCurSel(hwnd) \ | 
|---|
| 145 | SendMessageA(hwnd,CB_GETCURSEL,0,0); | 
|---|
| 146 |  | 
|---|
| 147 | #define CBSetCurSel(hwnd,pos) \ | 
|---|
| 148 | SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0); | 
|---|
| 149 |  | 
|---|
| 150 | #define CBGetCount(hwnd) \ | 
|---|
| 151 | SendMessageA(hwnd,CB_GETCOUNT,0,0); | 
|---|
| 152 | #define CBShowDropDown(hwnd,show) \ | 
|---|
| 153 | SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0); | 
|---|
| 154 | #define CBSetItemHeight(hwnd,index,height) \ | 
|---|
| 155 | SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height); | 
|---|
| 156 |  | 
|---|
| 157 |  | 
|---|
| 158 | const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */ | 
|---|
| 159 | const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */ | 
|---|
| 160 |  | 
|---|
| 161 | static const char defaultFilter[] = "*.*"; | 
|---|
| 162 |  | 
|---|
| 163 | /*********************************************************************** | 
|---|
| 164 | * Prototypes | 
|---|
| 165 | */ | 
|---|
| 166 |  | 
|---|
| 167 | /* Internal functions used by the dialog */ | 
|---|
| 168 | static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam); | 
|---|
| 169 | static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam); | 
|---|
| 170 | static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd); | 
|---|
| 171 | BOOL    FILEDLG95_OnOpen(HWND hwnd); | 
|---|
| 172 | static LRESULT FILEDLG95_InitControls(HWND hwnd); | 
|---|
| 173 | static void    FILEDLG95_Clean(HWND hwnd); | 
|---|
| 174 |  | 
|---|
| 175 | /* Functions used by the shell navigation */ | 
|---|
| 176 | static LRESULT FILEDLG95_SHELL_Init(HWND hwnd); | 
|---|
| 177 | static BOOL    FILEDLG95_SHELL_UpFolder(HWND hwnd); | 
|---|
| 178 | static BOOL    FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb); | 
|---|
| 179 | static void    FILEDLG95_SHELL_Clean(HWND hwnd); | 
|---|
| 180 | static BOOL    FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd); | 
|---|
| 181 |  | 
|---|
| 182 | /* Functions used by the filetype combo box */ | 
|---|
| 183 | static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd); | 
|---|
| 184 | static BOOL    FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode); | 
|---|
| 185 | static int     FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt); | 
|---|
| 186 | static void    FILEDLG95_FILETYPE_Clean(HWND hwnd); | 
|---|
| 187 |  | 
|---|
| 188 | /* Functions used by the Look In combo box */ | 
|---|
| 189 | static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo); | 
|---|
| 190 | static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct); | 
|---|
| 191 | static BOOL    FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode); | 
|---|
| 192 | static int     FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId); | 
|---|
| 193 | static int     FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod); | 
|---|
| 194 | static int     FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl); | 
|---|
| 195 | static int     FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd); | 
|---|
| 196 | int     FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl); | 
|---|
| 197 | static void    FILEDLG95_LOOKIN_Clean(HWND hwnd); | 
|---|
| 198 |  | 
|---|
| 199 | /* Miscellaneous tool functions */ | 
|---|
| 200 | HRESULT       GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName); | 
|---|
| 201 | HRESULT       GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName); | 
|---|
| 202 | IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs); | 
|---|
| 203 | LPITEMIDLIST  GetParentPidl(LPITEMIDLIST pidl); | 
|---|
| 204 | LPITEMIDLIST  GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName); | 
|---|
| 205 |  | 
|---|
| 206 | /* Shell memory allocation */ | 
|---|
| 207 | static void *MemAlloc(UINT size); | 
|---|
| 208 | static void MemFree(void *mem); | 
|---|
| 209 |  | 
|---|
| 210 | BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos); | 
|---|
| 211 | HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 
|---|
| 212 | HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode); | 
|---|
| 213 | HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 
|---|
| 214 | BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed); | 
|---|
| 215 | static BOOL BrowseSelectedFolder(HWND hwnd); | 
|---|
| 216 |  | 
|---|
| 217 | /*********************************************************************** | 
|---|
| 218 | *      GetFileName95 | 
|---|
| 219 | * | 
|---|
| 220 | * Creates an Open common dialog box that lets the user select | 
|---|
| 221 | * the drive, directory, and the name of a file or set of files to open. | 
|---|
| 222 | * | 
|---|
| 223 | * IN  : The FileOpenDlgInfos structure associated with the dialog | 
|---|
| 224 | * OUT : TRUE on success | 
|---|
| 225 | *       FALSE on cancel, error, close or filename-does-not-fit-in-buffer. | 
|---|
| 226 | */ | 
|---|
| 227 | BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos) | 
|---|
| 228 | { | 
|---|
| 229 |  | 
|---|
| 230 | LRESULT lRes; | 
|---|
| 231 | LPCVOID template; | 
|---|
| 232 | HRSRC hRes; | 
|---|
| 233 | HANDLE hDlgTmpl = 0; | 
|---|
| 234 |  | 
|---|
| 235 | /* test for missing functionality */ | 
|---|
| 236 | if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS) | 
|---|
| 237 | { | 
|---|
| 238 | FIXME("Flags 0x%08lx not yet implemented\n", | 
|---|
| 239 | fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS); | 
|---|
| 240 | } | 
|---|
| 241 |  | 
|---|
| 242 | /* Create the dialog from a template */ | 
|---|
| 243 |  | 
|---|
| 244 | if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA))) | 
|---|
| 245 | { | 
|---|
| 246 | COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); | 
|---|
| 247 | return FALSE; | 
|---|
| 248 | } | 
|---|
| 249 | if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) || | 
|---|
| 250 | !(template = LockResource( hDlgTmpl ))) | 
|---|
| 251 | { | 
|---|
| 252 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); | 
|---|
| 253 | return FALSE; | 
|---|
| 254 | } | 
|---|
| 255 |  | 
|---|
| 256 | /* old style hook messages */ | 
|---|
| 257 | if (IsHooked(fodInfos)) | 
|---|
| 258 | { | 
|---|
| 259 | fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRING); | 
|---|
| 260 | fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRING); | 
|---|
| 261 | fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRING); | 
|---|
| 262 | fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRING); | 
|---|
| 263 | } | 
|---|
| 264 |  | 
|---|
| 265 | lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32, | 
|---|
| 266 | (LPDLGTEMPLATEA) template, | 
|---|
| 267 | fodInfos->ofnInfos->hwndOwner, | 
|---|
| 268 | (DLGPROC) FileOpenDlgProc95, | 
|---|
| 269 | (LPARAM) fodInfos); | 
|---|
| 270 |  | 
|---|
| 271 | /* Unable to create the dialog */ | 
|---|
| 272 | if( lRes == -1) | 
|---|
| 273 | return FALSE; | 
|---|
| 274 |  | 
|---|
| 275 | return lRes; | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | /*********************************************************************** | 
|---|
| 279 | *      GetFileDialog95A | 
|---|
| 280 | * | 
|---|
| 281 | * Call GetFileName95 with this structure and clean the memory. | 
|---|
| 282 | * | 
|---|
| 283 | * IN  : The OPENFILENAMEA initialisation structure passed to | 
|---|
| 284 | *       GetOpenFileNameA win api function (see filedlg.c) | 
|---|
| 285 | */ | 
|---|
| 286 | BOOL  WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType) | 
|---|
| 287 | { | 
|---|
| 288 |  | 
|---|
| 289 | BOOL ret; | 
|---|
| 290 | FileOpenDlgInfos *fodInfos; | 
|---|
| 291 | HINSTANCE hInstance; | 
|---|
| 292 | LPCSTR lpstrInitialDir = (LPCSTR)-1; | 
|---|
| 293 | DWORD dwFlags = 0; | 
|---|
| 294 |  | 
|---|
| 295 | /* Initialise FileOpenDlgInfos structure*/ | 
|---|
| 296 | fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos)); | 
|---|
| 297 | ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos)); | 
|---|
| 298 |  | 
|---|
| 299 | /* Pass in the original ofn */ | 
|---|
| 300 | fodInfos->ofnInfos = ofn; | 
|---|
| 301 |  | 
|---|
| 302 | /* Save original hInstance value */ | 
|---|
| 303 | hInstance = ofn->hInstance; | 
|---|
| 304 | fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance); | 
|---|
| 305 |  | 
|---|
| 306 | dwFlags = ofn->Flags; | 
|---|
| 307 | ofn->Flags = ofn->Flags|OFN_WINE; | 
|---|
| 308 |  | 
|---|
| 309 | /* Initialise the dialog property */ | 
|---|
| 310 | fodInfos->DlgInfos.dwDlgProp = 0; | 
|---|
| 311 | fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL; | 
|---|
| 312 |  | 
|---|
| 313 | switch(iDlgType) | 
|---|
| 314 | { | 
|---|
| 315 | case OPEN_DIALOG : | 
|---|
| 316 | ret = GetFileName95(fodInfos); | 
|---|
| 317 | break; | 
|---|
| 318 | case SAVE_DIALOG : | 
|---|
| 319 | fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG; | 
|---|
| 320 | ret = GetFileName95(fodInfos); | 
|---|
| 321 | break; | 
|---|
| 322 | default : | 
|---|
| 323 | ret = 0; | 
|---|
| 324 | } | 
|---|
| 325 |  | 
|---|
| 326 | if (lpstrInitialDir != (LPCSTR)-1) | 
|---|
| 327 | { | 
|---|
| 328 | MemFree((LPVOID)(ofn->lpstrInitialDir)); | 
|---|
| 329 | ofn->lpstrInitialDir = lpstrInitialDir; | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | ofn->Flags = dwFlags; | 
|---|
| 333 | ofn->hInstance = hInstance; | 
|---|
| 334 | MemFree((LPVOID)(fodInfos)); | 
|---|
| 335 | return ret; | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | /*********************************************************************** | 
|---|
| 339 | *      GetFileDialog95W | 
|---|
| 340 | * | 
|---|
| 341 | * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure. | 
|---|
| 342 | * Call GetFileName95 with this structure and clean the memory. | 
|---|
| 343 | * | 
|---|
| 344 | * FIXME: lpstrCustomFilter has to converted back | 
|---|
| 345 | * | 
|---|
| 346 | */ | 
|---|
| 347 |  | 
|---|
| 348 | /* converting IN arguments */ | 
|---|
| 349 | #define AllocInArgWtoA(arg, save) \ | 
|---|
| 350 | if(arg) \ | 
|---|
| 351 | { \ | 
|---|
| 352 | save = arg; \ | 
|---|
| 353 | arg =  MemAlloc(lstrlenW(arg)); \ | 
|---|
| 354 | lstrcpyWtoA((LPSTR)arg, save); \ | 
|---|
| 355 | } | 
|---|
| 356 |  | 
|---|
| 357 | #define FreeInArg(arg, save) \ | 
|---|
| 358 | if(arg) \ | 
|---|
| 359 | { \ | 
|---|
| 360 | MemFree((LPSTR)arg); \ | 
|---|
| 361 | arg = save; \ | 
|---|
| 362 | } | 
|---|
| 363 |  | 
|---|
| 364 | /* converting OUT arguments */ | 
|---|
| 365 | #define AllocOutArgWtoA(arg, save, len) \ | 
|---|
| 366 | if(arg) \ | 
|---|
| 367 | { \ | 
|---|
| 368 | save = arg; \ | 
|---|
| 369 | arg = MemAlloc(len); \ | 
|---|
| 370 | } | 
|---|
| 371 |  | 
|---|
| 372 | #define FreeOutArg(arg, save, len) \ | 
|---|
| 373 | if(arg) \ | 
|---|
| 374 | { \ | 
|---|
| 375 | lstrcpynAtoW(save, (LPCSTR)arg, len); \ | 
|---|
| 376 | MemFree(arg); \ | 
|---|
| 377 | arg = save; \ | 
|---|
| 378 | } | 
|---|
| 379 |  | 
|---|
| 380 | BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType) | 
|---|
| 381 | { | 
|---|
| 382 | BOOL ret; | 
|---|
| 383 | FileOpenDlgInfos *fodInfos; | 
|---|
| 384 | HINSTANCE hInstance; | 
|---|
| 385 |  | 
|---|
| 386 | /* out arguments */ | 
|---|
| 387 | LPWSTR lpstrFile = NULL; | 
|---|
| 388 | LPWSTR lpstrFileTitle = NULL; | 
|---|
| 389 |  | 
|---|
| 390 | /* in/out arguments */ | 
|---|
| 391 | LPWSTR lpstrCustomFilter = NULL; | 
|---|
| 392 |  | 
|---|
| 393 | /* input arguments */ | 
|---|
| 394 | LPCWSTR lpstrFilter = NULL; | 
|---|
| 395 | LPCWSTR lpstrInitialDir = NULL; | 
|---|
| 396 | LPCWSTR lpstrTitle = NULL; | 
|---|
| 397 | LPCWSTR lpstrDefExt = NULL; | 
|---|
| 398 | LPCWSTR lpTemplateName = NULL; | 
|---|
| 399 | DWORD dwFlags; | 
|---|
| 400 |  | 
|---|
| 401 | /* Initialise FileOpenDlgInfos structure*/ | 
|---|
| 402 | fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos)); | 
|---|
| 403 | ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos)); | 
|---|
| 404 |  | 
|---|
| 405 | /*  Pass in the original ofn */ | 
|---|
| 406 | fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn; | 
|---|
| 407 |  | 
|---|
| 408 | /* convert lpstrFilter */ | 
|---|
| 409 | if (ofn->lpstrFilter) | 
|---|
| 410 | { | 
|---|
| 411 | LPCWSTR  s; | 
|---|
| 412 | LPSTR x, y; | 
|---|
| 413 | int n; | 
|---|
| 414 |  | 
|---|
| 415 | lpstrFilter = ofn->lpstrFilter; | 
|---|
| 416 |  | 
|---|
| 417 | /* filter is a list...  title\0ext\0......\0\0 */ | 
|---|
| 418 | s = ofn->lpstrFilter; | 
|---|
| 419 |  | 
|---|
| 420 | while (*s) s = s+lstrlenW(s)+1; | 
|---|
| 421 | s++; | 
|---|
| 422 | n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */ | 
|---|
| 423 | x = y = (LPSTR)MemAlloc(n); | 
|---|
| 424 | s = (LPWSTR)ofn->lpstrFilter; | 
|---|
| 425 | while (*s) | 
|---|
| 426 | { | 
|---|
| 427 | lstrcpyWtoA(x,s); | 
|---|
| 428 | x+=strlen(x)+1; | 
|---|
| 429 | s+=lstrlenW(s)+1; | 
|---|
| 430 | } | 
|---|
| 431 | *x=0; | 
|---|
| 432 | #ifdef __WIN32OS2__ | 
|---|
| 433 | ofn->lpstrFilter = (LPWSTR)y; | 
|---|
| 434 | #else | 
|---|
| 435 | (LPSTR)ofn->lpstrFilter = y; | 
|---|
| 436 | #endif | 
|---|
| 437 | } | 
|---|
| 438 |  | 
|---|
| 439 | /* convert lpstrCustomFilter */ | 
|---|
| 440 | if (ofn->lpstrCustomFilter) | 
|---|
| 441 | { | 
|---|
| 442 | LPWSTR  s; | 
|---|
| 443 | LPSTR x,y; | 
|---|
| 444 | int n; | 
|---|
| 445 |  | 
|---|
| 446 | lpstrCustomFilter = ofn->lpstrCustomFilter; | 
|---|
| 447 | /* filter is a list...  title\0ext\0......\0\0 */ | 
|---|
| 448 | s = ofn->lpstrCustomFilter; | 
|---|
| 449 | while (*s) s = s+lstrlenW(s)+1; | 
|---|
| 450 | s++; | 
|---|
| 451 | n = s - ofn->lpstrCustomFilter; | 
|---|
| 452 | x = y = (LPSTR)MemAlloc(n); | 
|---|
| 453 | s = ofn->lpstrCustomFilter; | 
|---|
| 454 | while (*s) | 
|---|
| 455 | { | 
|---|
| 456 | lstrcpyWtoA(x,s); | 
|---|
| 457 | x+=strlen(x)+1; | 
|---|
| 458 | s+=lstrlenW(s)+1; | 
|---|
| 459 | } | 
|---|
| 460 | *x=0; | 
|---|
| 461 | #ifdef __WIN32OS2__ | 
|---|
| 462 | ofn->lpstrCustomFilter = (LPWSTR)y; | 
|---|
| 463 | #else | 
|---|
| 464 | (LPSTR)ofn->lpstrCustomFilter = y; | 
|---|
| 465 | #endif | 
|---|
| 466 | } | 
|---|
| 467 |  | 
|---|
| 468 | /* convert string arguments, save others */ | 
|---|
| 469 | AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile); | 
|---|
| 470 | AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); | 
|---|
| 471 | AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir); | 
|---|
| 472 | AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle); | 
|---|
| 473 | AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt); | 
|---|
| 474 | AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName); | 
|---|
| 475 | dwFlags = ofn->Flags; | 
|---|
| 476 | hInstance = ofn->hInstance; | 
|---|
| 477 |  | 
|---|
| 478 | ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE; | 
|---|
| 479 | ofn->hInstance = MapHModuleLS(ofn->hInstance); | 
|---|
| 480 |  | 
|---|
| 481 | switch(iDlgType) | 
|---|
| 482 | { | 
|---|
| 483 | case OPEN_DIALOG : | 
|---|
| 484 | ret = GetFileName95(fodInfos); | 
|---|
| 485 | break; | 
|---|
| 486 | case SAVE_DIALOG : | 
|---|
| 487 | fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG; | 
|---|
| 488 | ret = GetFileName95(fodInfos); | 
|---|
| 489 | break; | 
|---|
| 490 | default : | 
|---|
| 491 | ret = 0; | 
|---|
| 492 | } | 
|---|
| 493 |  | 
|---|
| 494 | /* restore saved IN arguments and convert OUT arguments back */ | 
|---|
| 495 | ofn->Flags = dwFlags; | 
|---|
| 496 | ofn->hInstance = hInstance; | 
|---|
| 497 | FreeInArg(ofn->lpstrFilter, lpstrFilter); | 
|---|
| 498 | FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter); | 
|---|
| 499 | FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile); | 
|---|
| 500 | FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); | 
|---|
| 501 | FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir); | 
|---|
| 502 | FreeInArg(ofn->lpstrTitle, lpstrTitle); | 
|---|
| 503 | FreeInArg(ofn->lpstrDefExt, lpstrDefExt); | 
|---|
| 504 | FreeInArg(ofn->lpTemplateName, lpTemplateName); | 
|---|
| 505 |  | 
|---|
| 506 | MemFree((LPVOID)(fodInfos)); | 
|---|
| 507 | return ret; | 
|---|
| 508 | } | 
|---|
| 509 |  | 
|---|
| 510 | void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg) | 
|---|
| 511 | { | 
|---|
| 512 | HWND hwndChild,hwndStc32; | 
|---|
| 513 | RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp; | 
|---|
| 514 | POINT ptMoveCtl; | 
|---|
| 515 | POINT ptParentClient; | 
|---|
| 516 |  | 
|---|
| 517 | TRACE("\n"); | 
|---|
| 518 |  | 
|---|
| 519 | ptMoveCtl.x = ptMoveCtl.y = 0; | 
|---|
| 520 | hwndStc32=GetDlgItem(hwndChildDlg,stc32); | 
|---|
| 521 | GetClientRect(hwndParentDlg,&rectParent); | 
|---|
| 522 | GetClientRect(hwndChildDlg,&rectChild); | 
|---|
| 523 |  | 
|---|
| 524 | if(hwndStc32) | 
|---|
| 525 | { | 
|---|
| 526 | GetWindowRect(hwndStc32,&rectStc32); | 
|---|
| 527 | MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2); | 
|---|
| 528 | CopyRect(&rectTemp,&rectStc32); | 
|---|
| 529 |  | 
|---|
| 530 | SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top)); | 
|---|
| 531 | SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE); | 
|---|
| 532 |  | 
|---|
| 533 | if(rectStc32.right < rectTemp.right) | 
|---|
| 534 | { | 
|---|
| 535 | ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left)); | 
|---|
| 536 | ptMoveCtl.x = 0; | 
|---|
| 537 | } | 
|---|
| 538 | else | 
|---|
| 539 | { | 
|---|
| 540 | ptMoveCtl.x = (rectStc32.right - rectTemp.right); | 
|---|
| 541 | ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right)); | 
|---|
| 542 | } | 
|---|
| 543 |  | 
|---|
| 544 | if(rectStc32.bottom < rectTemp.bottom) | 
|---|
| 545 | { | 
|---|
| 546 | ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top)); | 
|---|
| 547 | ptMoveCtl.y = 0; | 
|---|
| 548 | } | 
|---|
| 549 | else | 
|---|
| 550 | { | 
|---|
| 551 | ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom); | 
|---|
| 552 | ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom)); | 
|---|
| 553 | } | 
|---|
| 554 | } | 
|---|
| 555 | else | 
|---|
| 556 | { | 
|---|
| 557 | if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return; | 
|---|
| 558 |  | 
|---|
| 559 | SetRectEmpty(&rectTemp); | 
|---|
| 560 | ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left)); | 
|---|
| 561 | ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top); | 
|---|
| 562 | ptMoveCtl.y = rectParent.bottom-rectParent.top; | 
|---|
| 563 | ptMoveCtl.x=0; | 
|---|
| 564 | } | 
|---|
| 565 | SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y); | 
|---|
| 566 | AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE)); | 
|---|
| 567 |  | 
|---|
| 568 | SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER ); | 
|---|
| 569 | SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left), | 
|---|
| 570 | (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER); | 
|---|
| 571 |  | 
|---|
| 572 | hwndChild = GetWindow(hwndChildDlg,GW_CHILD); | 
|---|
| 573 | if(hwndStc32) | 
|---|
| 574 | { | 
|---|
| 575 | GetWindowRect(hwndStc32,&rectStc32); | 
|---|
| 576 | MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2); | 
|---|
| 577 | } | 
|---|
| 578 | else | 
|---|
| 579 | SetRect(&rectStc32,0,0,0,0); | 
|---|
| 580 |  | 
|---|
| 581 | if (hwndChild ) | 
|---|
| 582 | { | 
|---|
| 583 | do | 
|---|
| 584 | { | 
|---|
| 585 | if(hwndChild != hwndStc32) | 
|---|
| 586 | { | 
|---|
| 587 | if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE) | 
|---|
| 588 | continue; | 
|---|
| 589 | GetWindowRect(hwndChild,&rectCtrl); | 
|---|
| 590 | MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2); | 
|---|
| 591 |  | 
|---|
| 592 | /* | 
|---|
| 593 | Check the initial position of the controls relative to the initial | 
|---|
| 594 | position and size of stc32 (before it is expanded). | 
|---|
| 595 | */ | 
|---|
| 596 | if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom) | 
|---|
| 597 | { | 
|---|
| 598 | rectCtrl.left += ptMoveCtl.x; | 
|---|
| 599 | rectCtrl.top  += ptMoveCtl.y; | 
|---|
| 600 | } | 
|---|
| 601 | else if (rectCtrl.left >= rectTemp.right) | 
|---|
| 602 | { | 
|---|
| 603 | rectCtrl.left += ptMoveCtl.x; | 
|---|
| 604 | } | 
|---|
| 605 | else if (rectCtrl.top >= rectTemp.bottom) | 
|---|
| 606 | { | 
|---|
| 607 | rectCtrl.top  += ptMoveCtl.y; | 
|---|
| 608 | } | 
|---|
| 609 |  | 
|---|
| 610 | SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top, | 
|---|
| 611 | rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top, | 
|---|
| 612 | SWP_NOSIZE | SWP_NOZORDER ); | 
|---|
| 613 | } | 
|---|
| 614 | } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL); | 
|---|
| 615 | } | 
|---|
| 616 | hwndChild = GetWindow(hwndParentDlg,GW_CHILD); | 
|---|
| 617 |  | 
|---|
| 618 | if(hwndStc32) | 
|---|
| 619 | { | 
|---|
| 620 | GetWindowRect(hwndStc32,&rectStc32); | 
|---|
| 621 | MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2); | 
|---|
| 622 | ptMoveCtl.x = rectStc32.left - 0; | 
|---|
| 623 | ptMoveCtl.y = rectStc32.top - 0; | 
|---|
| 624 | if (hwndChild ) | 
|---|
| 625 | { | 
|---|
| 626 | do | 
|---|
| 627 | { | 
|---|
| 628 | if(hwndChild != hwndChildDlg) | 
|---|
| 629 | { | 
|---|
| 630 | if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE) | 
|---|
| 631 | continue; | 
|---|
| 632 | GetWindowRect(hwndChild,&rectCtrl); | 
|---|
| 633 | MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2); | 
|---|
| 634 |  | 
|---|
| 635 | rectCtrl.left += ptMoveCtl.x; | 
|---|
| 636 | rectCtrl.top += ptMoveCtl.y; | 
|---|
| 637 |  | 
|---|
| 638 | SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top, | 
|---|
| 639 | rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top, | 
|---|
| 640 | SWP_NOSIZE |SWP_NOZORDER ); | 
|---|
| 641 | } | 
|---|
| 642 | } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL); | 
|---|
| 643 | } | 
|---|
| 644 | } | 
|---|
| 645 | } | 
|---|
| 646 |  | 
|---|
| 647 |  | 
|---|
| 648 | HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 649 | { | 
|---|
| 650 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr); | 
|---|
| 651 |  | 
|---|
| 652 | #if 0 | 
|---|
| 653 | TRACE("0x%04x\n", uMsg); | 
|---|
| 654 | #endif | 
|---|
| 655 |  | 
|---|
| 656 | switch(uMsg) | 
|---|
| 657 | { | 
|---|
| 658 | case WM_INITDIALOG: | 
|---|
| 659 | { | 
|---|
| 660 | fodInfos = (FileOpenDlgInfos *)lParam; | 
|---|
| 661 | lParam = (LPARAM) fodInfos->ofnInfos; | 
|---|
| 662 | ArrangeCtrlPositions(hwnd,GetParent(hwnd)); | 
|---|
| 663 |  | 
|---|
| 664 | if(fodInfos && IsHooked(fodInfos)) | 
|---|
| 665 | return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam); | 
|---|
| 666 | return 0; | 
|---|
| 667 | } | 
|---|
| 668 | } | 
|---|
| 669 |  | 
|---|
| 670 | if(fodInfos && IsHooked(fodInfos)) | 
|---|
| 671 | return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam); | 
|---|
| 672 |  | 
|---|
| 673 | return DefWindowProcA(hwnd,uMsg,wParam,lParam); | 
|---|
| 674 | } | 
|---|
| 675 |  | 
|---|
| 676 | HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd) | 
|---|
| 677 | { | 
|---|
| 678 | LPCVOID template; | 
|---|
| 679 | HRSRC hRes; | 
|---|
| 680 | HANDLE hDlgTmpl = 0; | 
|---|
| 681 | HWND hChildDlg = 0; | 
|---|
| 682 |  | 
|---|
| 683 | TRACE("\n"); | 
|---|
| 684 |  | 
|---|
| 685 | if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE || | 
|---|
| 686 | fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE) | 
|---|
| 687 | { | 
|---|
| 688 | if (fodInfos->ofnInfos->Flags  & OFN_ENABLETEMPLATEHANDLE) | 
|---|
| 689 | { | 
|---|
| 690 | if( !(template = LockResource( fodInfos->ofnInfos->hInstance))) | 
|---|
| 691 | { | 
|---|
| 692 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); | 
|---|
| 693 | return (HWND)NULL; | 
|---|
| 694 | } | 
|---|
| 695 | } | 
|---|
| 696 | else | 
|---|
| 697 | { | 
|---|
| 698 | if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance), | 
|---|
| 699 | (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA))) | 
|---|
| 700 | { | 
|---|
| 701 | COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); | 
|---|
| 702 | return (HWND)NULL; | 
|---|
| 703 | } | 
|---|
| 704 | if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance), | 
|---|
| 705 | hRes )) || !(template = LockResource( hDlgTmpl ))) | 
|---|
| 706 | { | 
|---|
| 707 | COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE); | 
|---|
| 708 | return (HWND)NULL; | 
|---|
| 709 | } | 
|---|
| 710 | } | 
|---|
| 711 |  | 
|---|
| 712 | hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos); | 
|---|
| 713 | if(hChildDlg) | 
|---|
| 714 | { | 
|---|
| 715 | ShowWindow(hChildDlg,SW_SHOW); | 
|---|
| 716 | return hChildDlg; | 
|---|
| 717 | } | 
|---|
| 718 | } | 
|---|
| 719 | else if( IsHooked(fodInfos)) | 
|---|
| 720 | { | 
|---|
| 721 | RECT rectHwnd; | 
|---|
| 722 | DLGTEMPLATE tmplate; | 
|---|
| 723 | GetClientRect(hwnd,&rectHwnd); | 
|---|
| 724 | tmplate.style = WS_CHILD | WS_CLIPSIBLINGS; | 
|---|
| 725 | tmplate.dwExtendedStyle = 0; | 
|---|
| 726 | tmplate.cdit = 0; | 
|---|
| 727 | tmplate.x = 0; | 
|---|
| 728 | tmplate.y = 0; | 
|---|
| 729 | tmplate.cx = rectHwnd.right-rectHwnd.left; | 
|---|
| 730 | tmplate.cy = rectHwnd.bottom-rectHwnd.top; | 
|---|
| 731 |  | 
|---|
| 732 | return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos); | 
|---|
| 733 | } | 
|---|
| 734 | return (HWND)NULL; | 
|---|
| 735 | } | 
|---|
| 736 |  | 
|---|
| 737 | /*********************************************************************** | 
|---|
| 738 | *          SendCustomDlgNotificationMessage | 
|---|
| 739 | * | 
|---|
| 740 | * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog | 
|---|
| 741 | */ | 
|---|
| 742 |  | 
|---|
| 743 | HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode) | 
|---|
| 744 | { | 
|---|
| 745 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr); | 
|---|
| 746 |  | 
|---|
| 747 | TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode); | 
|---|
| 748 |  | 
|---|
| 749 | if(!fodInfos) return 0; | 
|---|
| 750 |  | 
|---|
| 751 | if(fodInfos->ofnInfos->Flags & OFN_UNICODE) | 
|---|
| 752 | FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!"); | 
|---|
| 753 |  | 
|---|
| 754 | if(fodInfos->DlgInfos.hwndCustomDlg) | 
|---|
| 755 | { | 
|---|
| 756 | OFNOTIFYA ofnNotify; | 
|---|
| 757 | HRESULT ret; | 
|---|
| 758 | ofnNotify.hdr.hwndFrom=hwndParentDlg; | 
|---|
| 759 | ofnNotify.hdr.idFrom=0; | 
|---|
| 760 | ofnNotify.hdr.code = uCode; | 
|---|
| 761 | ofnNotify.lpOFN = fodInfos->ofnInfos; | 
|---|
| 762 | TRACE("CALL NOTIFY for %x\n", uCode); | 
|---|
| 763 | ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify); | 
|---|
| 764 | TRACE("RET NOTIFY\n"); | 
|---|
| 765 | return ret; | 
|---|
| 766 | } | 
|---|
| 767 | return TRUE; | 
|---|
| 768 | } | 
|---|
| 769 |  | 
|---|
| 770 | /*********************************************************************** | 
|---|
| 771 | *         FILEDLG95_HandleCustomDialogMessages | 
|---|
| 772 | * | 
|---|
| 773 | * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages | 
|---|
| 774 | */ | 
|---|
| 775 | HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 776 | { | 
|---|
| 777 | LPSTR lpstrFileSpec; | 
|---|
| 778 | int reqSize; | 
|---|
| 779 | char lpstrPath[MAX_PATH]; | 
|---|
| 780 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 781 | if(!fodInfos) return -1; | 
|---|
| 782 |  | 
|---|
| 783 | switch(uMsg) | 
|---|
| 784 | { | 
|---|
| 785 | case CDM_GETFILEPATH: | 
|---|
| 786 | GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath)); | 
|---|
| 787 | lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath); | 
|---|
| 788 | if (lpstrFileSpec==lpstrPath) | 
|---|
| 789 | { | 
|---|
| 790 | char lpstrCurrentDir[MAX_PATH]; | 
|---|
| 791 | /* Prepend the current path */ | 
|---|
| 792 | COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir); | 
|---|
| 793 | if ((LPSTR)lParam!=NULL) | 
|---|
| 794 | wsnprintfA((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath); | 
|---|
| 795 | reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1; | 
|---|
| 796 | } | 
|---|
| 797 | else | 
|---|
| 798 | { | 
|---|
| 799 | lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam); | 
|---|
| 800 | reqSize=strlen(lpstrPath); | 
|---|
| 801 | } | 
|---|
| 802 | /* return the required buffer size */ | 
|---|
| 803 | return reqSize; | 
|---|
| 804 |  | 
|---|
| 805 | case CDM_GETFOLDERPATH: | 
|---|
| 806 | COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath); | 
|---|
| 807 | if ((LPSTR)lParam!=NULL) | 
|---|
| 808 | lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam); | 
|---|
| 809 | return strlen(lpstrPath); | 
|---|
| 810 |  | 
|---|
| 811 | case CDM_GETSPEC: | 
|---|
| 812 | reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath)); | 
|---|
| 813 | lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath); | 
|---|
| 814 | if ((LPSTR)lParam!=NULL) | 
|---|
| 815 | lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam); | 
|---|
| 816 | return strlen(lpstrFileSpec); | 
|---|
| 817 |  | 
|---|
| 818 | case CDM_SETCONTROLTEXT: | 
|---|
| 819 | if ( 0 != lParam ) | 
|---|
| 820 | SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam ); | 
|---|
| 821 | return TRUE; | 
|---|
| 822 |  | 
|---|
| 823 | case CDM_HIDECONTROL: | 
|---|
| 824 | case CDM_SETDEFEXT: | 
|---|
| 825 | FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n"); | 
|---|
| 826 | return -1; | 
|---|
| 827 | } | 
|---|
| 828 | return TRUE; | 
|---|
| 829 | } | 
|---|
| 830 |  | 
|---|
| 831 | /*********************************************************************** | 
|---|
| 832 | *          FileOpenDlgProc95 | 
|---|
| 833 | * | 
|---|
| 834 | * File open dialog procedure | 
|---|
| 835 | */ | 
|---|
| 836 | HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 837 | { | 
|---|
| 838 | #if 0 | 
|---|
| 839 | TRACE("0x%04x 0x%04x\n", hwnd, uMsg); | 
|---|
| 840 | #endif | 
|---|
| 841 |  | 
|---|
| 842 | switch(uMsg) | 
|---|
| 843 | { | 
|---|
| 844 | case WM_INITDIALOG: | 
|---|
| 845 | { | 
|---|
| 846 | FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam; | 
|---|
| 847 |  | 
|---|
| 848 | /* Adds the FileOpenDlgInfos in the property list of the dialog | 
|---|
| 849 | so it will be easily accessible through a GetPropA(...) */ | 
|---|
| 850 | SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos); | 
|---|
| 851 |  | 
|---|
| 852 | fodInfos->DlgInfos.hwndCustomDlg = | 
|---|
| 853 | CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd); | 
|---|
| 854 |  | 
|---|
| 855 | FILEDLG95_InitControls(hwnd); | 
|---|
| 856 | SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE); | 
|---|
| 857 | FILEDLG95_FillControls(hwnd, wParam, lParam); | 
|---|
| 858 | return 0; | 
|---|
| 859 | } | 
|---|
| 860 | case WM_COMMAND: | 
|---|
| 861 | return FILEDLG95_OnWMCommand(hwnd, wParam, lParam); | 
|---|
| 862 | case WM_DRAWITEM: | 
|---|
| 863 | { | 
|---|
| 864 | switch(((LPDRAWITEMSTRUCT)lParam)->CtlID) | 
|---|
| 865 | { | 
|---|
| 866 | case IDC_LOOKIN: | 
|---|
| 867 | FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam); | 
|---|
| 868 | return TRUE; | 
|---|
| 869 | } | 
|---|
| 870 | } | 
|---|
| 871 | return FALSE; | 
|---|
| 872 |  | 
|---|
| 873 | case WM_GETISHELLBROWSER: | 
|---|
| 874 | return FILEDLG95_OnWMGetIShellBrowser(hwnd); | 
|---|
| 875 |  | 
|---|
| 876 | case WM_DESTROY: | 
|---|
| 877 | RemovePropA(hwnd, FileOpenDlgInfosStr); | 
|---|
| 878 | return FALSE; | 
|---|
| 879 |  | 
|---|
| 880 | case WM_NOTIFY: | 
|---|
| 881 | { | 
|---|
| 882 | LPNMHDR lpnmh = (LPNMHDR)lParam; | 
|---|
| 883 | UINT stringId = -1; | 
|---|
| 884 |  | 
|---|
| 885 | /* set up the button tooltips strings */ | 
|---|
| 886 | if(TTN_GETDISPINFOA == lpnmh->code ) | 
|---|
| 887 | { | 
|---|
| 888 | LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam; | 
|---|
| 889 | switch(lpnmh->idFrom ) | 
|---|
| 890 | { | 
|---|
| 891 | /* Up folder button */ | 
|---|
| 892 | case FCIDM_TB_UPFOLDER: | 
|---|
| 893 | stringId = IDS_UPFOLDER; | 
|---|
| 894 | break; | 
|---|
| 895 | /* New folder button */ | 
|---|
| 896 | case FCIDM_TB_NEWFOLDER: | 
|---|
| 897 | stringId = IDS_NEWFOLDER; | 
|---|
| 898 | break; | 
|---|
| 899 | /* List option button */ | 
|---|
| 900 | case FCIDM_TB_SMALLICON: | 
|---|
| 901 | stringId = IDS_LISTVIEW; | 
|---|
| 902 | break; | 
|---|
| 903 | /* Details option button */ | 
|---|
| 904 | case FCIDM_TB_REPORTVIEW: | 
|---|
| 905 | stringId = IDS_REPORTVIEW; | 
|---|
| 906 | break; | 
|---|
| 907 | /* Desktop button */ | 
|---|
| 908 | case FCIDM_TB_DESKTOP: | 
|---|
| 909 | stringId = IDS_TODESKTOP; | 
|---|
| 910 | break; | 
|---|
| 911 | default: | 
|---|
| 912 | stringId = 0; | 
|---|
| 913 | } | 
|---|
| 914 | lpdi->hinst = COMMDLG_hInstance32; | 
|---|
| 915 | lpdi->lpszText =  (LPSTR) stringId; | 
|---|
| 916 | } | 
|---|
| 917 | return FALSE; | 
|---|
| 918 | } | 
|---|
| 919 | default : | 
|---|
| 920 | if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST) | 
|---|
| 921 | return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam); | 
|---|
| 922 | return FALSE; | 
|---|
| 923 | } | 
|---|
| 924 | } | 
|---|
| 925 |  | 
|---|
| 926 | /*********************************************************************** | 
|---|
| 927 | *      FILEDLG95_InitControls | 
|---|
| 928 | * | 
|---|
| 929 | * WM_INITDIALOG message handler (before hook notification) | 
|---|
| 930 | */ | 
|---|
| 931 | static LRESULT FILEDLG95_InitControls(HWND hwnd) | 
|---|
| 932 | { | 
|---|
| 933 | TBBUTTON tbb[] = | 
|---|
| 934 | { | 
|---|
| 935 | {0,                 0,                   TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 }, | 
|---|
| 936 | {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER,   TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }, | 
|---|
| 937 | {0,                 0,                   TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 }, | 
|---|
| 938 | {VIEW_NEWFOLDER+1,  FCIDM_TB_DESKTOP,    TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }, | 
|---|
| 939 | {0,                 0,                   TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 }, | 
|---|
| 940 | {VIEW_NEWFOLDER,    FCIDM_TB_NEWFOLDER,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }, | 
|---|
| 941 | {0,                 0,                   TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 }, | 
|---|
| 942 | {VIEW_LIST,         FCIDM_TB_SMALLICON,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }, | 
|---|
| 943 | {VIEW_DETAILS,      FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }, | 
|---|
| 944 | }; | 
|---|
| 945 | TBADDBITMAP tba[] = | 
|---|
| 946 | { | 
|---|
| 947 | { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR }, | 
|---|
| 948 | { COMDLG32_hInstance, 800 }                  // desktop icon | 
|---|
| 949 | }; | 
|---|
| 950 |  | 
|---|
| 951 | RECT rectTB; | 
|---|
| 952 |  | 
|---|
| 953 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 954 |  | 
|---|
| 955 | TRACE("%p\n", fodInfos); | 
|---|
| 956 |  | 
|---|
| 957 | /* Get the hwnd of the controls */ | 
|---|
| 958 | fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME); | 
|---|
| 959 | fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE); | 
|---|
| 960 | fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN); | 
|---|
| 961 |  | 
|---|
| 962 | /* construct the toolbar */ | 
|---|
| 963 | GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB); | 
|---|
| 964 | MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2); | 
|---|
| 965 |  | 
|---|
| 966 | fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL, | 
|---|
| 967 | WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE, | 
|---|
| 968 | 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL); | 
|---|
| 969 |  | 
|---|
| 970 | SetWindowPos(fodInfos->DlgInfos.hwndTB, 0, | 
|---|
| 971 | rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top, | 
|---|
| 972 | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER ); | 
|---|
| 973 |  | 
|---|
| 974 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); | 
|---|
| 975 |  | 
|---|
| 976 | /* fixme: use TB_LOADIMAGES when implemented */ | 
|---|
| 977 | /*  SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/ | 
|---|
| 978 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]); | 
|---|
| 979 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]); | 
|---|
| 980 |  | 
|---|
| 981 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb); | 
|---|
| 982 | SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0); | 
|---|
| 983 |  | 
|---|
| 984 | /* Set the window text with the text specified in the OPENFILENAME structure */ | 
|---|
| 985 | if(fodInfos->ofnInfos->lpstrTitle) | 
|---|
| 986 | { | 
|---|
| 987 | SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle); | 
|---|
| 988 | } | 
|---|
| 989 | else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) | 
|---|
| 990 | { | 
|---|
| 991 | SetWindowTextA(hwnd,"Save"); | 
|---|
| 992 | } | 
|---|
| 993 |  | 
|---|
| 994 | /* Initialise the file name edit control */ | 
|---|
| 995 | if(fodInfos->ofnInfos->lpstrFile) | 
|---|
| 996 | { | 
|---|
| 997 | LPSTR lpstrFile = COMDLG32_PathFindFileNameA(fodInfos->ofnInfos->lpstrFile); | 
|---|
| 998 | SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile); | 
|---|
| 999 | } | 
|---|
| 1000 |  | 
|---|
| 1001 | /* Must the open as read only check box be checked ?*/ | 
|---|
| 1002 | if(fodInfos->ofnInfos->Flags & OFN_READONLY) | 
|---|
| 1003 | { | 
|---|
| 1004 | SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0); | 
|---|
| 1005 | } | 
|---|
| 1006 |  | 
|---|
| 1007 | /* Must the open as read only check box be hid ?*/ | 
|---|
| 1008 | if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) | 
|---|
| 1009 | { | 
|---|
| 1010 | ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE); | 
|---|
| 1011 | } | 
|---|
| 1012 |  | 
|---|
| 1013 | /* Must the help button be hid ?*/ | 
|---|
| 1014 | if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP)) | 
|---|
| 1015 | { | 
|---|
| 1016 | ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE); | 
|---|
| 1017 | } | 
|---|
| 1018 |  | 
|---|
| 1019 | /* Resize the height, if open as read only checkbox ad help button | 
|---|
| 1020 | are hidden and we are not using a custom template */ | 
|---|
| 1021 | if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) && | 
|---|
| 1022 | (!(fodInfos->ofnInfos->Flags & | 
|---|
| 1023 | (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE)))) | 
|---|
| 1024 | { | 
|---|
| 1025 | RECT rectDlg, rectHelp, rectCancel; | 
|---|
| 1026 | GetWindowRect(hwnd, &rectDlg); | 
|---|
| 1027 | GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp); | 
|---|
| 1028 | GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel); | 
|---|
| 1029 | /* subtract the height of the help button plus the space between | 
|---|
| 1030 | the help button and the cancel button to the height of the dialog */ | 
|---|
| 1031 | SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left, | 
|---|
| 1032 | (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom), | 
|---|
| 1033 | SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER); | 
|---|
| 1034 | } | 
|---|
| 1035 |  | 
|---|
| 1036 | /* change Open to Save FIXME: use resources */ | 
|---|
| 1037 | if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) | 
|---|
| 1038 | { | 
|---|
| 1039 | SetDlgItemTextA(hwnd,IDOK,"&Save"); | 
|---|
| 1040 | SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in"); | 
|---|
| 1041 | } | 
|---|
| 1042 | return 0; | 
|---|
| 1043 | } | 
|---|
| 1044 |  | 
|---|
| 1045 | /*********************************************************************** | 
|---|
| 1046 | *      FILEDLG95_FillControls | 
|---|
| 1047 | * | 
|---|
| 1048 | * WM_INITDIALOG message handler (after hook notification) | 
|---|
| 1049 | */ | 
|---|
| 1050 | static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1051 | { | 
|---|
| 1052 | LPITEMIDLIST pidlItemId = NULL; | 
|---|
| 1053 |  | 
|---|
| 1054 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam; | 
|---|
| 1055 |  | 
|---|
| 1056 | TRACE("dir=%s file=%s\n", | 
|---|
| 1057 | fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile); | 
|---|
| 1058 |  | 
|---|
| 1059 | /* Get the initial directory pidl */ | 
|---|
| 1060 |  | 
|---|
| 1061 | if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir))) | 
|---|
| 1062 | { | 
|---|
| 1063 | char path[MAX_PATH]; | 
|---|
| 1064 |  | 
|---|
| 1065 | GetCurrentDirectoryA(MAX_PATH,path); | 
|---|
| 1066 | pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path); | 
|---|
| 1067 | } | 
|---|
| 1068 |  | 
|---|
| 1069 | /* Initialise shell objects */ | 
|---|
| 1070 | FILEDLG95_SHELL_Init(hwnd); | 
|---|
| 1071 |  | 
|---|
| 1072 | /* Initialize the Look In combo box */ | 
|---|
| 1073 | FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB); | 
|---|
| 1074 |  | 
|---|
| 1075 | /* Initialize the filter combo box */ | 
|---|
| 1076 | FILEDLG95_FILETYPE_Init(hwnd); | 
|---|
| 1077 |  | 
|---|
| 1078 | /* Browse to the initial directory */ | 
|---|
| 1079 | IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE); | 
|---|
| 1080 |  | 
|---|
| 1081 | /* Free pidlItem memory */ | 
|---|
| 1082 | COMDLG32_SHFree(pidlItemId); | 
|---|
| 1083 |  | 
|---|
| 1084 | return TRUE; | 
|---|
| 1085 | } | 
|---|
| 1086 | /*********************************************************************** | 
|---|
| 1087 | *      FILEDLG95_Clean | 
|---|
| 1088 | * | 
|---|
| 1089 | * Regroups all the cleaning functions of the filedlg | 
|---|
| 1090 | */ | 
|---|
| 1091 | void FILEDLG95_Clean(HWND hwnd) | 
|---|
| 1092 | { | 
|---|
| 1093 | FILEDLG95_FILETYPE_Clean(hwnd); | 
|---|
| 1094 | FILEDLG95_LOOKIN_Clean(hwnd); | 
|---|
| 1095 | FILEDLG95_SHELL_Clean(hwnd); | 
|---|
| 1096 | } | 
|---|
| 1097 | /*********************************************************************** | 
|---|
| 1098 | *      FILEDLG95_OnWMCommand | 
|---|
| 1099 | * | 
|---|
| 1100 | * WM_COMMAND message handler | 
|---|
| 1101 | */ | 
|---|
| 1102 | static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1103 | { | 
|---|
| 1104 | WORD wNotifyCode = HIWORD(wParam); /* notification code */ | 
|---|
| 1105 | WORD wID = LOWORD(wParam);         /* item, control, or accelerator identifier */ | 
|---|
| 1106 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1107 |  | 
|---|
| 1108 | switch(wID) | 
|---|
| 1109 | { | 
|---|
| 1110 | /* OK button */ | 
|---|
| 1111 | case IDOK: | 
|---|
| 1112 | if(FILEDLG95_OnOpen(hwnd)) | 
|---|
| 1113 | SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK); | 
|---|
| 1114 | break; | 
|---|
| 1115 | /* Cancel button */ | 
|---|
| 1116 | case IDCANCEL: | 
|---|
| 1117 | FILEDLG95_Clean(hwnd); | 
|---|
| 1118 | EndDialog(hwnd, FALSE); | 
|---|
| 1119 | break; | 
|---|
| 1120 | /* Filetype combo box */ | 
|---|
| 1121 | case IDC_FILETYPE: | 
|---|
| 1122 | FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode); | 
|---|
| 1123 | break; | 
|---|
| 1124 | /* LookIn combo box */ | 
|---|
| 1125 | case IDC_LOOKIN: | 
|---|
| 1126 | FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode); | 
|---|
| 1127 | break; | 
|---|
| 1128 |  | 
|---|
| 1129 | /* --- toolbar --- */ | 
|---|
| 1130 | /* Up folder button */ | 
|---|
| 1131 | case FCIDM_TB_UPFOLDER: | 
|---|
| 1132 | FILEDLG95_SHELL_UpFolder(hwnd); | 
|---|
| 1133 | break; | 
|---|
| 1134 | /* New folder button */ | 
|---|
| 1135 | case FCIDM_TB_NEWFOLDER: | 
|---|
| 1136 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER); | 
|---|
| 1137 | break; | 
|---|
| 1138 | /* List option button */ | 
|---|
| 1139 | case FCIDM_TB_SMALLICON: | 
|---|
| 1140 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST); | 
|---|
| 1141 | break; | 
|---|
| 1142 | /* Details option button */ | 
|---|
| 1143 | case FCIDM_TB_REPORTVIEW: | 
|---|
| 1144 | FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS); | 
|---|
| 1145 | break; | 
|---|
| 1146 | /* Details option button */ | 
|---|
| 1147 | case FCIDM_TB_DESKTOP: | 
|---|
| 1148 | FILEDLG95_SHELL_BrowseToDesktop(hwnd); | 
|---|
| 1149 | break; | 
|---|
| 1150 |  | 
|---|
| 1151 | case IDC_FILENAME: | 
|---|
| 1152 | break; | 
|---|
| 1153 |  | 
|---|
| 1154 | } | 
|---|
| 1155 | /* Do not use the listview selection anymore */ | 
|---|
| 1156 | fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW; | 
|---|
| 1157 | return 0; | 
|---|
| 1158 | } | 
|---|
| 1159 |  | 
|---|
| 1160 | /*********************************************************************** | 
|---|
| 1161 | *      FILEDLG95_OnWMGetIShellBrowser | 
|---|
| 1162 | * | 
|---|
| 1163 | * WM_GETISHELLBROWSER message handler | 
|---|
| 1164 | */ | 
|---|
| 1165 | static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd) | 
|---|
| 1166 | { | 
|---|
| 1167 |  | 
|---|
| 1168 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1169 |  | 
|---|
| 1170 | TRACE("\n"); | 
|---|
| 1171 |  | 
|---|
| 1172 | SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser); | 
|---|
| 1173 |  | 
|---|
| 1174 | return TRUE; | 
|---|
| 1175 | } | 
|---|
| 1176 |  | 
|---|
| 1177 |  | 
|---|
| 1178 | /*********************************************************************** | 
|---|
| 1179 | *      FILEDLG95_OnOpenMultipleFiles | 
|---|
| 1180 | * | 
|---|
| 1181 | * Handles the opening of multiple files. | 
|---|
| 1182 | * | 
|---|
| 1183 | * FIXME | 
|---|
| 1184 | *  check destination buffer size | 
|---|
| 1185 | */ | 
|---|
| 1186 | BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed) | 
|---|
| 1187 | { | 
|---|
| 1188 | CHAR   lpstrPathSpec[MAX_PATH] = ""; | 
|---|
| 1189 | LPSTR  lpstrFile; | 
|---|
| 1190 | UINT   nCount, nSizePath; | 
|---|
| 1191 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1192 |  | 
|---|
| 1193 | TRACE("\n"); | 
|---|
| 1194 |  | 
|---|
| 1195 | lpstrFile = fodInfos->ofnInfos->lpstrFile; | 
|---|
| 1196 | lpstrFile[0] = '\0'; | 
|---|
| 1197 |  | 
|---|
| 1198 | COMDLG32_SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec ); | 
|---|
| 1199 |  | 
|---|
| 1200 | if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) && | 
|---|
| 1201 | ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)) | 
|---|
| 1202 | { | 
|---|
| 1203 | LPSTR lpstrTemp = lpstrFileList; | 
|---|
| 1204 |  | 
|---|
| 1205 | for ( nCount = 0; nCount < nFileCount; nCount++ ) | 
|---|
| 1206 | { | 
|---|
| 1207 | LPITEMIDLIST pidl; | 
|---|
| 1208 |  | 
|---|
| 1209 | pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp); | 
|---|
| 1210 | if (!pidl) | 
|---|
| 1211 | { | 
|---|
| 1212 | CHAR lpstrNotFound[100]; | 
|---|
| 1213 | CHAR lpstrMsg[100]; | 
|---|
| 1214 | CHAR tmp[400]; | 
|---|
| 1215 |  | 
|---|
| 1216 | LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100); | 
|---|
| 1217 | LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100); | 
|---|
| 1218 |  | 
|---|
| 1219 | strcpy(tmp, lpstrTemp); | 
|---|
| 1220 | strcat(tmp, "\n"); | 
|---|
| 1221 | strcat(tmp, lpstrNotFound); | 
|---|
| 1222 | strcat(tmp, "\n"); | 
|---|
| 1223 | strcat(tmp, lpstrMsg); | 
|---|
| 1224 |  | 
|---|
| 1225 | MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION); | 
|---|
| 1226 | return FALSE; | 
|---|
| 1227 | } | 
|---|
| 1228 |  | 
|---|
| 1229 | /* move to the next file in the list of files */ | 
|---|
| 1230 | lpstrTemp += strlen(lpstrTemp) + 1; | 
|---|
| 1231 | COMDLG32_SHFree(pidl); | 
|---|
| 1232 | } | 
|---|
| 1233 | } | 
|---|
| 1234 |  | 
|---|
| 1235 | nSizePath = strlen(lpstrPathSpec); | 
|---|
| 1236 | strcpy( lpstrFile, lpstrPathSpec); | 
|---|
| 1237 | memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed ); | 
|---|
| 1238 |  | 
|---|
| 1239 | fodInfos->ofnInfos->nFileOffset = nSizePath + 1; | 
|---|
| 1240 | fodInfos->ofnInfos->nFileExtension = 0; | 
|---|
| 1241 |  | 
|---|
| 1242 | /* clean and exit */ | 
|---|
| 1243 | FILEDLG95_Clean(hwnd); | 
|---|
| 1244 | return EndDialog(hwnd,TRUE); | 
|---|
| 1245 | } | 
|---|
| 1246 |  | 
|---|
| 1247 | /*********************************************************************** | 
|---|
| 1248 | *      FILEDLG95_OnOpen | 
|---|
| 1249 | * | 
|---|
| 1250 | * Ok button WM_COMMAND message handler | 
|---|
| 1251 | * | 
|---|
| 1252 | * If the function succeeds, the return value is nonzero. | 
|---|
| 1253 | */ | 
|---|
| 1254 | #define ONOPEN_BROWSE 1 | 
|---|
| 1255 | #define ONOPEN_OPEN   2 | 
|---|
| 1256 | #define ONOPEN_SEARCH 3 | 
|---|
| 1257 | static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText) | 
|---|
| 1258 | { | 
|---|
| 1259 | char strMsgTitle[MAX_PATH]; | 
|---|
| 1260 | char strMsgText [MAX_PATH]; | 
|---|
| 1261 | if (idCaption) | 
|---|
| 1262 | LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle)); | 
|---|
| 1263 | else | 
|---|
| 1264 | strMsgTitle[0] = '\0'; | 
|---|
| 1265 | LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText)); | 
|---|
| 1266 | MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND); | 
|---|
| 1267 | } | 
|---|
| 1268 |  | 
|---|
| 1269 | BOOL FILEDLG95_OnOpen(HWND hwnd) | 
|---|
| 1270 | { | 
|---|
| 1271 | char * lpstrFileList; | 
|---|
| 1272 | UINT nFileCount = 0; | 
|---|
| 1273 | UINT sizeUsed = 0; | 
|---|
| 1274 | BOOL ret = TRUE; | 
|---|
| 1275 | char lpstrPathAndFile[MAX_PATH]; | 
|---|
| 1276 | char lpstrTemp[MAX_PATH]; | 
|---|
| 1277 | LPSHELLFOLDER lpsf = NULL; | 
|---|
| 1278 | int nOpenAction; | 
|---|
| 1279 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1280 |  | 
|---|
| 1281 | TRACE("hwnd=0x%04x\n", hwnd); | 
|---|
| 1282 |  | 
|---|
| 1283 | /* get the files from the edit control */ | 
|---|
| 1284 | nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed); | 
|---|
| 1285 |  | 
|---|
| 1286 | /* try if the user selected a folder in the shellview */ | 
|---|
| 1287 | if(nFileCount == 0) | 
|---|
| 1288 | { | 
|---|
| 1289 | BrowseSelectedFolder(hwnd); | 
|---|
| 1290 | return FALSE; | 
|---|
| 1291 | } | 
|---|
| 1292 |  | 
|---|
| 1293 | if(nFileCount > 1) | 
|---|
| 1294 | { | 
|---|
| 1295 | ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed); | 
|---|
| 1296 | goto ret; | 
|---|
| 1297 | } | 
|---|
| 1298 |  | 
|---|
| 1299 | TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList); | 
|---|
| 1300 |  | 
|---|
| 1301 | /* | 
|---|
| 1302 | Step 1:  Build a complete path name from the current folder and | 
|---|
| 1303 | the filename or path in the edit box. | 
|---|
| 1304 | Special cases: | 
|---|
| 1305 | - the path in the edit box is a root path | 
|---|
| 1306 | (with or without drive letter) | 
|---|
| 1307 | - the edit box contains ".." (or a path with ".." in it) | 
|---|
| 1308 | */ | 
|---|
| 1309 |  | 
|---|
| 1310 | /* Get the current directory name */ | 
|---|
| 1311 | if (!COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile)) | 
|---|
| 1312 | { | 
|---|
| 1313 | /* we are in a special folder, default to desktop */ | 
|---|
| 1314 | if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL, 0, lpstrPathAndFile))) | 
|---|
| 1315 | { | 
|---|
| 1316 | /* last fallback */ | 
|---|
| 1317 | GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile); | 
|---|
| 1318 | } | 
|---|
| 1319 | } | 
|---|
| 1320 | COMDLG32_PathAddBackslashA(lpstrPathAndFile); | 
|---|
| 1321 |  | 
|---|
| 1322 | TRACE("current directory=%s\n", lpstrPathAndFile); | 
|---|
| 1323 |  | 
|---|
| 1324 | /* if the user specifyed a fully qualified path use it */ | 
|---|
| 1325 | if(COMDLG32_PathIsRelativeA(lpstrFileList)) | 
|---|
| 1326 | { | 
|---|
| 1327 | strcat(lpstrPathAndFile, lpstrFileList); | 
|---|
| 1328 | } | 
|---|
| 1329 | else | 
|---|
| 1330 | { | 
|---|
| 1331 | /* does the path have a drive letter? */ | 
|---|
| 1332 | if (COMDLG32_PathGetDriveNumberA(lpstrFileList) == -1) | 
|---|
| 1333 | strcpy(lpstrPathAndFile+2, lpstrFileList); | 
|---|
| 1334 | else | 
|---|
| 1335 | strcpy(lpstrPathAndFile, lpstrFileList); | 
|---|
| 1336 | } | 
|---|
| 1337 |  | 
|---|
| 1338 | /* resolve "." and ".." */ | 
|---|
| 1339 | COMDLG32_PathCanonicalizeA(lpstrTemp, lpstrPathAndFile ); | 
|---|
| 1340 | strcpy(lpstrPathAndFile, lpstrTemp); | 
|---|
| 1341 | TRACE("canon=%s\n", lpstrPathAndFile); | 
|---|
| 1342 |  | 
|---|
| 1343 | MemFree(lpstrFileList); | 
|---|
| 1344 |  | 
|---|
| 1345 | /* | 
|---|
| 1346 | Step 2: here we have a cleaned up path | 
|---|
| 1347 |  | 
|---|
| 1348 | We have to parse the path step by step to see if we have to browse | 
|---|
| 1349 | to a folder if the path points to a directory or the last | 
|---|
| 1350 | valid element is a directory. | 
|---|
| 1351 |  | 
|---|
| 1352 | valid variables: | 
|---|
| 1353 | lpstrPathAndFile: cleaned up path | 
|---|
| 1354 | */ | 
|---|
| 1355 |  | 
|---|
| 1356 | nOpenAction = ONOPEN_BROWSE; | 
|---|
| 1357 |  | 
|---|
| 1358 | /* dont apply any checks with OFN_NOVALIDATE */ | 
|---|
| 1359 | if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE)) | 
|---|
| 1360 | { | 
|---|
| 1361 | LPSTR lpszTemp, lpszTemp1; | 
|---|
| 1362 | LPITEMIDLIST pidl = NULL; | 
|---|
| 1363 |  | 
|---|
| 1364 | /* check for invalid chars */ | 
|---|
| 1365 | if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL) | 
|---|
| 1366 | { | 
|---|
| 1367 | FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME); | 
|---|
| 1368 | ret = FALSE; | 
|---|
| 1369 | goto ret; | 
|---|
| 1370 | } | 
|---|
| 1371 |  | 
|---|
| 1372 | if (FAILED (COMDLG32_SHGetDesktopFolder(&lpsf))) return FALSE; | 
|---|
| 1373 |  | 
|---|
| 1374 | lpszTemp1 = lpszTemp = lpstrPathAndFile; | 
|---|
| 1375 | while (lpszTemp1) | 
|---|
| 1376 | { | 
|---|
| 1377 | LPSHELLFOLDER lpsfChild; | 
|---|
| 1378 | WCHAR lpwstrTemp[MAX_PATH]; | 
|---|
| 1379 | DWORD dwEaten, dwAttributes; | 
|---|
| 1380 |  | 
|---|
| 1381 | lpszTemp = COMDLG32_PathFindNextComponentA(lpszTemp); | 
|---|
| 1382 |  | 
|---|
| 1383 | if (!lpszTemp) break; /* end of path */ | 
|---|
| 1384 |  | 
|---|
| 1385 | if(*lpszTemp) | 
|---|
| 1386 | lstrcpynAtoW(lpwstrTemp, lpszTemp1, lpszTemp - lpszTemp1); | 
|---|
| 1387 | else | 
|---|
| 1388 | { | 
|---|
| 1389 | lstrcpyAtoW(lpwstrTemp, lpszTemp1);     /* last element */ | 
|---|
| 1390 |  | 
|---|
| 1391 | /* if the last element is a wildcard do a search */ | 
|---|
| 1392 | if(strpbrk(lpszTemp1, "*?") != NULL) | 
|---|
| 1393 | { | 
|---|
| 1394 | nOpenAction = ONOPEN_SEARCH; | 
|---|
| 1395 | break; | 
|---|
| 1396 | } | 
|---|
| 1397 | } | 
|---|
| 1398 | lpszTemp1 = lpszTemp; | 
|---|
| 1399 |  | 
|---|
| 1400 | TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf); | 
|---|
| 1401 |  | 
|---|
| 1402 | if(lstrlenW(lpwstrTemp)==2) COMDLG32_PathAddBackslashW(lpwstrTemp); | 
|---|
| 1403 |  | 
|---|
| 1404 | dwAttributes = SFGAO_FOLDER; | 
|---|
| 1405 | if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes))) | 
|---|
| 1406 | { | 
|---|
| 1407 | /* the path component is valid, we have a pidl of the next path component */ | 
|---|
| 1408 | TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl); | 
|---|
| 1409 | if(dwAttributes & SFGAO_FOLDER) | 
|---|
| 1410 | { | 
|---|
| 1411 | if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild))) | 
|---|
| 1412 | { | 
|---|
| 1413 | ERR("bind to failed\n"); /* should not fail */ | 
|---|
| 1414 | break; | 
|---|
| 1415 | } | 
|---|
| 1416 | IShellFolder_Release(lpsf); | 
|---|
| 1417 | lpsf = lpsfChild; | 
|---|
| 1418 | lpsfChild = NULL; | 
|---|
| 1419 | } | 
|---|
| 1420 | else | 
|---|
| 1421 | { | 
|---|
| 1422 | TRACE("value\n"); | 
|---|
| 1423 |  | 
|---|
| 1424 | /* end dialog, return value */ | 
|---|
| 1425 | nOpenAction = ONOPEN_OPEN; | 
|---|
| 1426 | break; | 
|---|
| 1427 | } | 
|---|
| 1428 | COMDLG32_SHFree(pidl); | 
|---|
| 1429 | pidl = NULL; | 
|---|
| 1430 | } | 
|---|
| 1431 | else | 
|---|
| 1432 | { | 
|---|
| 1433 | if(*lpszTemp)   /* points to trailing null for last path element */ | 
|---|
| 1434 | { | 
|---|
| 1435 | if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST) | 
|---|
| 1436 | { | 
|---|
| 1437 | FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING); | 
|---|
| 1438 | break; | 
|---|
| 1439 | } | 
|---|
| 1440 | } | 
|---|
| 1441 | else | 
|---|
| 1442 | { | 
|---|
| 1443 | if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST) | 
|---|
| 1444 | { | 
|---|
| 1445 | FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING); | 
|---|
| 1446 | break; | 
|---|
| 1447 | } | 
|---|
| 1448 | } | 
|---|
| 1449 | /* change to the current folder */ | 
|---|
| 1450 | nOpenAction = ONOPEN_OPEN; | 
|---|
| 1451 | break; | 
|---|
| 1452 | } | 
|---|
| 1453 | } | 
|---|
| 1454 | if(pidl) COMDLG32_SHFree(pidl); | 
|---|
| 1455 | } | 
|---|
| 1456 |  | 
|---|
| 1457 | /* | 
|---|
| 1458 | Step 3: here we have a cleaned up and validated path | 
|---|
| 1459 |  | 
|---|
| 1460 | valid variables: | 
|---|
| 1461 | lpsf:             ShellFolder bound to the rightmost valid path component | 
|---|
| 1462 | lpstrPathAndFile: cleaned up path | 
|---|
| 1463 | nOpenAction:      action to do | 
|---|
| 1464 | */ | 
|---|
| 1465 | TRACE("end validate sf=%p\n", lpsf); | 
|---|
| 1466 |  | 
|---|
| 1467 | switch(nOpenAction) | 
|---|
| 1468 | { | 
|---|
| 1469 | case ONOPEN_SEARCH:   /* set the current filter to the file mask and refresh */ | 
|---|
| 1470 | TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile); | 
|---|
| 1471 | { | 
|---|
| 1472 | int iPos; | 
|---|
| 1473 | LPSTR lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile); | 
|---|
| 1474 |  | 
|---|
| 1475 | /* replace the current filter */ | 
|---|
| 1476 | if(fodInfos->ShellInfos.lpstrCurrentFilter) | 
|---|
| 1477 | MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); | 
|---|
| 1478 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpszTemp)+1)*sizeof(WCHAR)); | 
|---|
| 1479 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpszTemp); | 
|---|
| 1480 |  | 
|---|
| 1481 | /* set the filter cb to the extension when possible */ | 
|---|
| 1482 | if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp))) | 
|---|
| 1483 | CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos); | 
|---|
| 1484 | } | 
|---|
| 1485 | /* fall through */ | 
|---|
| 1486 | case ONOPEN_BROWSE:   /* browse to the highest folder we could bind to */ | 
|---|
| 1487 | TRACE("ONOPEN_BROWSE\n"); | 
|---|
| 1488 | { | 
|---|
| 1489 | IPersistFolder2 * ppf2; | 
|---|
| 1490 | if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2))) | 
|---|
| 1491 | { | 
|---|
| 1492 | LPITEMIDLIST pidlCurrent; | 
|---|
| 1493 | IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent); | 
|---|
| 1494 | IPersistFolder2_Release(ppf2); | 
|---|
| 1495 | if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent)) | 
|---|
| 1496 | { | 
|---|
| 1497 | IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE); | 
|---|
| 1498 | } | 
|---|
| 1499 | else if( nOpenAction == ONOPEN_SEARCH ) | 
|---|
| 1500 | { | 
|---|
| 1501 | IShellView_Refresh(fodInfos->Shell.FOIShellView); | 
|---|
| 1502 | } | 
|---|
| 1503 | COMDLG32_SHFree(pidlCurrent); | 
|---|
| 1504 | } | 
|---|
| 1505 | } | 
|---|
| 1506 | ret = FALSE; | 
|---|
| 1507 | break; | 
|---|
| 1508 | case ONOPEN_OPEN:   /* fill in the return struct and close the dialog */ | 
|---|
| 1509 | TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile); | 
|---|
| 1510 | { | 
|---|
| 1511 | /* add default extension */ | 
|---|
| 1512 | if (fodInfos->ofnInfos->lpstrDefExt) | 
|---|
| 1513 | { | 
|---|
| 1514 | if (! *COMDLG32_PathFindExtensionA(lpstrPathAndFile)) | 
|---|
| 1515 | { | 
|---|
| 1516 | strcat(lpstrPathAndFile, "."); | 
|---|
| 1517 | strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt); | 
|---|
| 1518 | } | 
|---|
| 1519 | } | 
|---|
| 1520 |  | 
|---|
| 1521 | /* Check that size size of the file does not exceed buffer size */ | 
|---|
| 1522 | if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile) | 
|---|
| 1523 | { | 
|---|
| 1524 | LPSTR lpszTemp; | 
|---|
| 1525 |  | 
|---|
| 1526 | /* fill destination buffer */ | 
|---|
| 1527 | strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile); | 
|---|
| 1528 |  | 
|---|
| 1529 | /* set filename offset */ | 
|---|
| 1530 | lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile); | 
|---|
| 1531 | fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile; | 
|---|
| 1532 |  | 
|---|
| 1533 | /* set extension offset */ | 
|---|
| 1534 | lpszTemp = COMDLG32_PathFindExtensionA(lpstrPathAndFile); | 
|---|
| 1535 | fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0; | 
|---|
| 1536 |  | 
|---|
| 1537 | /* set the lpstrFileTitle */ | 
|---|
| 1538 | if(fodInfos->ofnInfos->lpstrFileTitle) | 
|---|
| 1539 | { | 
|---|
| 1540 | LPSTR lpstrFileTitle = COMDLG32_PathFindFileNameA(lpstrPathAndFile); | 
|---|
| 1541 | strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle); | 
|---|
| 1542 | } | 
|---|
| 1543 |  | 
|---|
| 1544 | /* ask the hook if we can close */ | 
|---|
| 1545 | if(IsHooked(fodInfos)) | 
|---|
| 1546 | { | 
|---|
| 1547 | /* FIXME we are sending ASCII-structures. Does not work with NT */ | 
|---|
| 1548 | /* first old style */ | 
|---|
| 1549 | TRACE("---\n"); | 
|---|
| 1550 | #ifndef __WIN32OS2__ | 
|---|
| 1551 | //-->> crashes Adobe Acrobat 4.0 | 
|---|
| 1552 | CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook, hwnd, | 
|---|
| 1553 | fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos); | 
|---|
| 1554 | if (GetWindowLongA(hwnd, DWL_MSGRESULT)) | 
|---|
| 1555 | { | 
|---|
| 1556 | TRACE("cancled\n"); | 
|---|
| 1557 | ret = FALSE; | 
|---|
| 1558 | goto ret; | 
|---|
| 1559 | } | 
|---|
| 1560 | #endif | 
|---|
| 1561 | } | 
|---|
| 1562 |  | 
|---|
| 1563 | TRACE("close\n"); | 
|---|
| 1564 | FILEDLG95_Clean(hwnd); | 
|---|
| 1565 | ret = EndDialog(hwnd, TRUE); | 
|---|
| 1566 | } | 
|---|
| 1567 | else | 
|---|
| 1568 | { | 
|---|
| 1569 | /* FIXME set error FNERR_BUFFERTOSMALL */ | 
|---|
| 1570 | FILEDLG95_Clean(hwnd); | 
|---|
| 1571 | ret = EndDialog(hwnd, FALSE); | 
|---|
| 1572 | } | 
|---|
| 1573 | goto ret; | 
|---|
| 1574 | } | 
|---|
| 1575 | break; | 
|---|
| 1576 | } | 
|---|
| 1577 |  | 
|---|
| 1578 | ret: | 
|---|
| 1579 | if(lpsf) IShellFolder_Release(lpsf); | 
|---|
| 1580 | return ret; | 
|---|
| 1581 | } | 
|---|
| 1582 |  | 
|---|
| 1583 | /*********************************************************************** | 
|---|
| 1584 | *      FILEDLG95_SHELL_Init | 
|---|
| 1585 | * | 
|---|
| 1586 | * Initialisation of the shell objects | 
|---|
| 1587 | */ | 
|---|
| 1588 | static HRESULT FILEDLG95_SHELL_Init(HWND hwnd) | 
|---|
| 1589 | { | 
|---|
| 1590 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1591 |  | 
|---|
| 1592 | TRACE("\n"); | 
|---|
| 1593 |  | 
|---|
| 1594 | /* | 
|---|
| 1595 | * Initialisation of the FileOpenDialogInfos structure | 
|---|
| 1596 | */ | 
|---|
| 1597 |  | 
|---|
| 1598 | /* Shell */ | 
|---|
| 1599 |  | 
|---|
| 1600 | /*ShellInfos */ | 
|---|
| 1601 | fodInfos->ShellInfos.hwndOwner = hwnd; | 
|---|
| 1602 |  | 
|---|
| 1603 | /* Disable multi-select if flag not set */ | 
|---|
| 1604 | if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)) | 
|---|
| 1605 | { | 
|---|
| 1606 | fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL; | 
|---|
| 1607 | } | 
|---|
| 1608 | fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT; | 
|---|
| 1609 | fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST; | 
|---|
| 1610 |  | 
|---|
| 1611 | GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView); | 
|---|
| 1612 | ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left); | 
|---|
| 1613 | ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right); | 
|---|
| 1614 |  | 
|---|
| 1615 | /* Construct the IShellBrowser interface */ | 
|---|
| 1616 | fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd); | 
|---|
| 1617 |  | 
|---|
| 1618 | return NOERROR; | 
|---|
| 1619 | } | 
|---|
| 1620 |  | 
|---|
| 1621 | /*********************************************************************** | 
|---|
| 1622 | *      FILEDLG95_SHELL_ExecuteCommand | 
|---|
| 1623 | * | 
|---|
| 1624 | * Change the folder option and refresh the view | 
|---|
| 1625 | * If the function succeeds, the return value is nonzero. | 
|---|
| 1626 | */ | 
|---|
| 1627 | static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb) | 
|---|
| 1628 | { | 
|---|
| 1629 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1630 |  | 
|---|
| 1631 | IContextMenu * pcm; | 
|---|
| 1632 | TRACE("(0x%08x,%p)\n", hwnd, lpVerb); | 
|---|
| 1633 |  | 
|---|
| 1634 | if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView, | 
|---|
| 1635 | SVGIO_BACKGROUND, | 
|---|
| 1636 | &IID_IContextMenu, | 
|---|
| 1637 | (LPVOID*)&pcm))) | 
|---|
| 1638 | { | 
|---|
| 1639 | CMINVOKECOMMANDINFO ci; | 
|---|
| 1640 | ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO)); | 
|---|
| 1641 | ci.cbSize = sizeof(CMINVOKECOMMANDINFO); | 
|---|
| 1642 | ci.lpVerb = lpVerb; | 
|---|
| 1643 | ci.hwnd = hwnd; | 
|---|
| 1644 |  | 
|---|
| 1645 | IContextMenu_InvokeCommand(pcm, &ci); | 
|---|
| 1646 | IContextMenu_Release(pcm); | 
|---|
| 1647 | } | 
|---|
| 1648 |  | 
|---|
| 1649 | return FALSE; | 
|---|
| 1650 | } | 
|---|
| 1651 |  | 
|---|
| 1652 | /*********************************************************************** | 
|---|
| 1653 | *      FILEDLG95_SHELL_UpFolder | 
|---|
| 1654 | * | 
|---|
| 1655 | * Browse to the specified object | 
|---|
| 1656 | * If the function succeeds, the return value is nonzero. | 
|---|
| 1657 | */ | 
|---|
| 1658 | static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd) | 
|---|
| 1659 | { | 
|---|
| 1660 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1661 |  | 
|---|
| 1662 | TRACE("\n"); | 
|---|
| 1663 |  | 
|---|
| 1664 | if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, | 
|---|
| 1665 | NULL, | 
|---|
| 1666 | SBSP_PARENT))) | 
|---|
| 1667 | { | 
|---|
| 1668 | return TRUE; | 
|---|
| 1669 | } | 
|---|
| 1670 | return FALSE; | 
|---|
| 1671 | } | 
|---|
| 1672 |  | 
|---|
| 1673 | /*********************************************************************** | 
|---|
| 1674 | *      FILEDLG95_SHELL_BrowseToDesktop | 
|---|
| 1675 | * | 
|---|
| 1676 | * Browse to the Desktop | 
|---|
| 1677 | * If the function succeeds, the return value is nonzero. | 
|---|
| 1678 | */ | 
|---|
| 1679 | static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd) | 
|---|
| 1680 | { | 
|---|
| 1681 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1682 | LPITEMIDLIST pidl; | 
|---|
| 1683 | HRESULT hres; | 
|---|
| 1684 |  | 
|---|
| 1685 | TRACE("\n"); | 
|---|
| 1686 |  | 
|---|
| 1687 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl); | 
|---|
| 1688 | hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE); | 
|---|
| 1689 | COMDLG32_SHFree(pidl); | 
|---|
| 1690 | return SUCCEEDED(hres); | 
|---|
| 1691 | } | 
|---|
| 1692 | /*********************************************************************** | 
|---|
| 1693 | *      FILEDLG95_SHELL_Clean | 
|---|
| 1694 | * | 
|---|
| 1695 | * Cleans the memory used by shell objects | 
|---|
| 1696 | */ | 
|---|
| 1697 | static void FILEDLG95_SHELL_Clean(HWND hwnd) | 
|---|
| 1698 | { | 
|---|
| 1699 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1700 |  | 
|---|
| 1701 | TRACE("\n"); | 
|---|
| 1702 |  | 
|---|
| 1703 | COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent); | 
|---|
| 1704 |  | 
|---|
| 1705 | /* clean Shell interfaces */ | 
|---|
| 1706 | IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView); | 
|---|
| 1707 | IShellView_Release(fodInfos->Shell.FOIShellView); | 
|---|
| 1708 | IShellFolder_Release(fodInfos->Shell.FOIShellFolder); | 
|---|
| 1709 | IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser); | 
|---|
| 1710 | if (fodInfos->Shell.FOIDataObject) | 
|---|
| 1711 | IDataObject_Release(fodInfos->Shell.FOIDataObject); | 
|---|
| 1712 | } | 
|---|
| 1713 |  | 
|---|
| 1714 | /*********************************************************************** | 
|---|
| 1715 | *      FILEDLG95_FILETYPE_Init | 
|---|
| 1716 | * | 
|---|
| 1717 | * Initialisation of the file type combo box | 
|---|
| 1718 | */ | 
|---|
| 1719 | static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd) | 
|---|
| 1720 | { | 
|---|
| 1721 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1722 |  | 
|---|
| 1723 | TRACE("\n"); | 
|---|
| 1724 |  | 
|---|
| 1725 | if(fodInfos->ofnInfos->lpstrFilter) | 
|---|
| 1726 | { | 
|---|
| 1727 | int nFilters = 0;   /* number of filters */ | 
|---|
| 1728 | LPSTR lpstrFilter; | 
|---|
| 1729 | LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter; | 
|---|
| 1730 |  | 
|---|
| 1731 | for(;;) | 
|---|
| 1732 | { | 
|---|
| 1733 | /* filter is a list...  title\0ext\0......\0\0 | 
|---|
| 1734 | * Set the combo item text to the title and the item data | 
|---|
| 1735 | *  to the ext | 
|---|
| 1736 | */ | 
|---|
| 1737 | LPCSTR lpstrDisplay; | 
|---|
| 1738 | LPSTR lpstrExt; | 
|---|
| 1739 |  | 
|---|
| 1740 | /* Get the title */ | 
|---|
| 1741 | if(! *lpstrPos) break;    /* end */ | 
|---|
| 1742 | lpstrDisplay = lpstrPos; | 
|---|
| 1743 | lpstrPos += strlen(lpstrPos) + 1; | 
|---|
| 1744 |  | 
|---|
| 1745 | /* Copy the extensions */ | 
|---|
| 1746 | if (! *lpstrPos) return E_FAIL;   /* malformed filter */ | 
|---|
| 1747 | if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL; | 
|---|
| 1748 | strcpy(lpstrExt,lpstrPos); | 
|---|
| 1749 | lpstrPos += strlen(lpstrPos) + 1; | 
|---|
| 1750 |  | 
|---|
| 1751 | /* Add the item at the end of the combo */ | 
|---|
| 1752 | CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay); | 
|---|
| 1753 | CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt); | 
|---|
| 1754 | nFilters++; | 
|---|
| 1755 | } | 
|---|
| 1756 | /* | 
|---|
| 1757 | * Set the current filter to the one specified | 
|---|
| 1758 | * in the initialisation structure | 
|---|
| 1759 | * FIXME: lpstrCustomFilter not handled at all | 
|---|
| 1760 | */ | 
|---|
| 1761 |  | 
|---|
| 1762 | /* set default filter index */ | 
|---|
| 1763 | if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL) | 
|---|
| 1764 | fodInfos->ofnInfos->nFilterIndex = 1; | 
|---|
| 1765 |  | 
|---|
| 1766 | /* First, check to make sure our index isn't out of bounds. */ | 
|---|
| 1767 | if ( fodInfos->ofnInfos->nFilterIndex > nFilters ) | 
|---|
| 1768 | fodInfos->ofnInfos->nFilterIndex = nFilters; | 
|---|
| 1769 |  | 
|---|
| 1770 | /* Set the current index selection. */ | 
|---|
| 1771 | CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1); | 
|---|
| 1772 |  | 
|---|
| 1773 | /* Get the corresponding text string from the combo box. */ | 
|---|
| 1774 | lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, | 
|---|
| 1775 | fodInfos->ofnInfos->nFilterIndex-1); | 
|---|
| 1776 |  | 
|---|
| 1777 | if ((INT)lpstrFilter == CB_ERR)  /* control is empty */ | 
|---|
| 1778 | lpstrFilter = NULL; | 
|---|
| 1779 |  | 
|---|
| 1780 | if(lpstrFilter) | 
|---|
| 1781 | { | 
|---|
| 1782 | _strlwr(lpstrFilter);     /* lowercase */ | 
|---|
| 1783 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2); | 
|---|
| 1784 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpstrFilter); | 
|---|
| 1785 | } | 
|---|
| 1786 | } | 
|---|
| 1787 | return NOERROR; | 
|---|
| 1788 | } | 
|---|
| 1789 |  | 
|---|
| 1790 | /*********************************************************************** | 
|---|
| 1791 | *      FILEDLG95_FILETYPE_OnCommand | 
|---|
| 1792 | * | 
|---|
| 1793 | * WM_COMMAND of the file type combo box | 
|---|
| 1794 | * If the function succeeds, the return value is nonzero. | 
|---|
| 1795 | */ | 
|---|
| 1796 | static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode) | 
|---|
| 1797 | { | 
|---|
| 1798 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1799 |  | 
|---|
| 1800 | switch(wNotifyCode) | 
|---|
| 1801 | { | 
|---|
| 1802 | case CBN_SELENDOK: | 
|---|
| 1803 | { | 
|---|
| 1804 | LPSTR lpstrFilter; | 
|---|
| 1805 |  | 
|---|
| 1806 | /* Get the current item of the filetype combo box */ | 
|---|
| 1807 | int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB); | 
|---|
| 1808 |  | 
|---|
| 1809 | /* set the current filter index - indexed from 1 */ | 
|---|
| 1810 | fodInfos->ofnInfos->nFilterIndex = iItem + 1; | 
|---|
| 1811 |  | 
|---|
| 1812 | /* Set the current filter with the current selection */ | 
|---|
| 1813 | if(fodInfos->ShellInfos.lpstrCurrentFilter) | 
|---|
| 1814 | MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); | 
|---|
| 1815 |  | 
|---|
| 1816 | lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, | 
|---|
| 1817 | iItem); | 
|---|
| 1818 | if((int)lpstrFilter != CB_ERR) | 
|---|
| 1819 | { | 
|---|
| 1820 | fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2); | 
|---|
| 1821 | lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,_strlwr(lpstrFilter)); | 
|---|
| 1822 | SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE); | 
|---|
| 1823 | } | 
|---|
| 1824 |  | 
|---|
| 1825 | /* Refresh the actual view to display the included items*/ | 
|---|
| 1826 | IShellView_Refresh(fodInfos->Shell.FOIShellView); | 
|---|
| 1827 | } | 
|---|
| 1828 | } | 
|---|
| 1829 | return FALSE; | 
|---|
| 1830 | } | 
|---|
| 1831 | /*********************************************************************** | 
|---|
| 1832 | *      FILEDLG95_FILETYPE_SearchExt | 
|---|
| 1833 | * | 
|---|
| 1834 | * searches for a extension in the filetype box | 
|---|
| 1835 | */ | 
|---|
| 1836 | static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt) | 
|---|
| 1837 | { | 
|---|
| 1838 | int i, iCount = CBGetCount(hwnd); | 
|---|
| 1839 |  | 
|---|
| 1840 | TRACE("%s\n", lpstrExt); | 
|---|
| 1841 |  | 
|---|
| 1842 | if(iCount != CB_ERR) | 
|---|
| 1843 | { | 
|---|
| 1844 | for(i=0;i<iCount;i++) | 
|---|
| 1845 | { | 
|---|
| 1846 | if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i))) | 
|---|
| 1847 | return i; | 
|---|
| 1848 | } | 
|---|
| 1849 | } | 
|---|
| 1850 | return -1; | 
|---|
| 1851 | } | 
|---|
| 1852 |  | 
|---|
| 1853 | /*********************************************************************** | 
|---|
| 1854 | *      FILEDLG95_FILETYPE_Clean | 
|---|
| 1855 | * | 
|---|
| 1856 | * Clean the memory used by the filetype combo box | 
|---|
| 1857 | */ | 
|---|
| 1858 | static void FILEDLG95_FILETYPE_Clean(HWND hwnd) | 
|---|
| 1859 | { | 
|---|
| 1860 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 1861 | int iPos; | 
|---|
| 1862 | int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB); | 
|---|
| 1863 |  | 
|---|
| 1864 | TRACE("\n"); | 
|---|
| 1865 |  | 
|---|
| 1866 | /* Delete each string of the combo and their associated data */ | 
|---|
| 1867 | if(iCount != CB_ERR) | 
|---|
| 1868 | { | 
|---|
| 1869 | for(iPos = iCount-1;iPos>=0;iPos--) | 
|---|
| 1870 | { | 
|---|
| 1871 | MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos)); | 
|---|
| 1872 | CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos); | 
|---|
| 1873 | } | 
|---|
| 1874 | } | 
|---|
| 1875 | /* Current filter */ | 
|---|
| 1876 | if(fodInfos->ShellInfos.lpstrCurrentFilter) | 
|---|
| 1877 | MemFree(fodInfos->ShellInfos.lpstrCurrentFilter); | 
|---|
| 1878 |  | 
|---|
| 1879 | } | 
|---|
| 1880 |  | 
|---|
| 1881 | /*********************************************************************** | 
|---|
| 1882 | *      FILEDLG95_LOOKIN_Init | 
|---|
| 1883 | * | 
|---|
| 1884 | * Initialisation of the look in combo box | 
|---|
| 1885 | */ | 
|---|
| 1886 | static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo) | 
|---|
| 1887 | { | 
|---|
| 1888 | IShellFolder  *psfRoot, *psfDrives; | 
|---|
| 1889 | IEnumIDList   *lpeRoot, *lpeDrives; | 
|---|
| 1890 | LPITEMIDLIST  pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp; | 
|---|
| 1891 |  | 
|---|
| 1892 | LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos)); | 
|---|
| 1893 |  | 
|---|
| 1894 | TRACE("\n"); | 
|---|
| 1895 |  | 
|---|
| 1896 | liInfos->iMaxIndentation = 0; | 
|---|
| 1897 |  | 
|---|
| 1898 | SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos); | 
|---|
| 1899 |  | 
|---|
| 1900 | /* set item height for both text field and listbox */ | 
|---|
| 1901 | CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON)); | 
|---|
| 1902 | CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON)); | 
|---|
| 1903 |  | 
|---|
| 1904 | /* Initialise data of Desktop folder */ | 
|---|
| 1905 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp); | 
|---|
| 1906 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND); | 
|---|
| 1907 | COMDLG32_SHFree(pidlTmp); | 
|---|
| 1908 |  | 
|---|
| 1909 | COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives); | 
|---|
| 1910 |  | 
|---|
| 1911 | COMDLG32_SHGetDesktopFolder(&psfRoot); | 
|---|
| 1912 |  | 
|---|
| 1913 | if (psfRoot) | 
|---|
| 1914 | { | 
|---|
| 1915 | /* enumerate the contents of the desktop */ | 
|---|
| 1916 | if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot))) | 
|---|
| 1917 | { | 
|---|
| 1918 | while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL)) | 
|---|
| 1919 | { | 
|---|
| 1920 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND); | 
|---|
| 1921 |  | 
|---|
| 1922 | /* special handling for CSIDL_DRIVES */ | 
|---|
| 1923 | if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives)) | 
|---|
| 1924 | { | 
|---|
| 1925 | if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives))) | 
|---|
| 1926 | { | 
|---|
| 1927 | /* enumerate the drives */ | 
|---|
| 1928 | if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives))) | 
|---|
| 1929 | { | 
|---|
| 1930 | while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL)) | 
|---|
| 1931 | { | 
|---|
| 1932 | pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1); | 
|---|
| 1933 | FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND); | 
|---|
| 1934 | COMDLG32_SHFree(pidlAbsTmp); | 
|---|
| 1935 | COMDLG32_SHFree(pidlTmp1); | 
|---|
| 1936 | } | 
|---|
| 1937 | IEnumIDList_Release(lpeDrives); | 
|---|
| 1938 | } | 
|---|
| 1939 | IShellFolder_Release(psfDrives); | 
|---|
| 1940 | } | 
|---|
| 1941 | } | 
|---|
| 1942 | COMDLG32_SHFree(pidlTmp); | 
|---|
| 1943 | } | 
|---|
| 1944 | IEnumIDList_Release(lpeRoot); | 
|---|
| 1945 | } | 
|---|
| 1946 | } | 
|---|
| 1947 |  | 
|---|
| 1948 | IShellFolder_Release(psfRoot); | 
|---|
| 1949 | COMDLG32_SHFree(pidlDrives); | 
|---|
| 1950 | return NOERROR; | 
|---|
| 1951 | } | 
|---|
| 1952 |  | 
|---|
| 1953 | /*********************************************************************** | 
|---|
| 1954 | *      FILEDLG95_LOOKIN_DrawItem | 
|---|
| 1955 | * | 
|---|
| 1956 | * WM_DRAWITEM message handler | 
|---|
| 1957 | */ | 
|---|
| 1958 | static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) | 
|---|
| 1959 | { | 
|---|
| 1960 | COLORREF crWin = GetSysColor(COLOR_WINDOW); | 
|---|
| 1961 | COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT); | 
|---|
| 1962 | COLORREF crText = GetSysColor(COLOR_WINDOWTEXT); | 
|---|
| 1963 | RECT rectText; | 
|---|
| 1964 | RECT rectIcon; | 
|---|
| 1965 | SHFILEINFOA sfi; | 
|---|
| 1966 | HIMAGELIST ilItemImage; | 
|---|
| 1967 | int iIndentation; | 
|---|
| 1968 | TEXTMETRICA tm; | 
|---|
| 1969 | LPSFOLDER tmpFolder; | 
|---|
| 1970 |  | 
|---|
| 1971 |  | 
|---|
| 1972 | LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr); | 
|---|
| 1973 |  | 
|---|
| 1974 | TRACE("\n"); | 
|---|
| 1975 |  | 
|---|
| 1976 | if(pDIStruct->itemID == -1) | 
|---|
| 1977 | return 0; | 
|---|
| 1978 |  | 
|---|
| 1979 | if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem, | 
|---|
| 1980 | pDIStruct->itemID))) | 
|---|
| 1981 | return 0; | 
|---|
| 1982 |  | 
|---|
| 1983 |  | 
|---|
| 1984 | if(pDIStruct->itemID == liInfos->uSelectedItem) | 
|---|
| 1985 | { | 
|---|
| 1986 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, | 
|---|
| 1987 | 0, | 
|---|
| 1988 | &sfi, | 
|---|
| 1989 | sizeof (SHFILEINFOA), | 
|---|
| 1990 | SHGFI_PIDL | SHGFI_SMALLICON | | 
|---|
| 1991 | SHGFI_OPENICON | SHGFI_SYSICONINDEX    | | 
|---|
| 1992 | SHGFI_DISPLAYNAME ); | 
|---|
| 1993 | } | 
|---|
| 1994 | else | 
|---|
| 1995 | { | 
|---|
| 1996 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, | 
|---|
| 1997 | 0, | 
|---|
| 1998 | &sfi, | 
|---|
| 1999 | sizeof (SHFILEINFOA), | 
|---|
| 2000 | SHGFI_PIDL | SHGFI_SMALLICON | | 
|---|
| 2001 | SHGFI_SYSICONINDEX | | 
|---|
| 2002 | SHGFI_DISPLAYNAME); | 
|---|
| 2003 | } | 
|---|
| 2004 |  | 
|---|
| 2005 | /* Is this item selected ? */ | 
|---|
| 2006 | if(pDIStruct->itemState & ODS_SELECTED) | 
|---|
| 2007 | { | 
|---|
| 2008 | SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText))); | 
|---|
| 2009 | SetBkColor(pDIStruct->hDC,crHighLight); | 
|---|
| 2010 | FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight); | 
|---|
| 2011 | } | 
|---|
| 2012 | else | 
|---|
| 2013 | { | 
|---|
| 2014 | SetTextColor(pDIStruct->hDC,crText); | 
|---|
| 2015 | SetBkColor(pDIStruct->hDC,crWin); | 
|---|
| 2016 | FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin); | 
|---|
| 2017 | } | 
|---|
| 2018 |  | 
|---|
| 2019 | /* Do not indent item if drawing in the edit of the combo */ | 
|---|
| 2020 | if(pDIStruct->itemState & ODS_COMBOBOXEDIT) | 
|---|
| 2021 | { | 
|---|
| 2022 | iIndentation = 0; | 
|---|
| 2023 | ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, | 
|---|
| 2024 | 0, | 
|---|
| 2025 | &sfi, | 
|---|
| 2026 | sizeof (SHFILEINFOA), | 
|---|
| 2027 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON | 
|---|
| 2028 | | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME  ); | 
|---|
| 2029 |  | 
|---|
| 2030 | } | 
|---|
| 2031 | else | 
|---|
| 2032 | { | 
|---|
| 2033 | iIndentation = tmpFolder->m_iIndent; | 
|---|
| 2034 | } | 
|---|
| 2035 | /* Draw text and icon */ | 
|---|
| 2036 |  | 
|---|
| 2037 | /* Initialise the icon display area */ | 
|---|
| 2038 | rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation; | 
|---|
| 2039 | rectIcon.top = pDIStruct->rcItem.top; | 
|---|
| 2040 | rectIcon.right = rectIcon.left + ICONWIDTH; | 
|---|
| 2041 | rectIcon.bottom = pDIStruct->rcItem.bottom; | 
|---|
| 2042 |  | 
|---|
| 2043 | /* Initialise the text display area */ | 
|---|
| 2044 | GetTextMetricsA(pDIStruct->hDC, &tm); | 
|---|
| 2045 | rectText.left = rectIcon.right; | 
|---|
| 2046 | rectText.top = | 
|---|
| 2047 | (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2; | 
|---|
| 2048 | rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET; | 
|---|
| 2049 | rectText.bottom = | 
|---|
| 2050 | (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2; | 
|---|
| 2051 |  | 
|---|
| 2052 | /* Draw the icon from the image list */ | 
|---|
| 2053 | COMDLG32_ImageList_Draw(ilItemImage, | 
|---|
| 2054 | sfi.iIcon, | 
|---|
| 2055 | pDIStruct->hDC, | 
|---|
| 2056 | rectIcon.left, | 
|---|
| 2057 | rectIcon.top, | 
|---|
| 2058 | ILD_TRANSPARENT ); | 
|---|
| 2059 |  | 
|---|
| 2060 | /* Draw the associated text */ | 
|---|
| 2061 | if(sfi.szDisplayName) | 
|---|
| 2062 | TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName)); | 
|---|
| 2063 |  | 
|---|
| 2064 |  | 
|---|
| 2065 | return NOERROR; | 
|---|
| 2066 | } | 
|---|
| 2067 |  | 
|---|
| 2068 | /*********************************************************************** | 
|---|
| 2069 | *      FILEDLG95_LOOKIN_OnCommand | 
|---|
| 2070 | * | 
|---|
| 2071 | * LookIn combo box WM_COMMAND message handler | 
|---|
| 2072 | * If the function succeeds, the return value is nonzero. | 
|---|
| 2073 | */ | 
|---|
| 2074 | static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode) | 
|---|
| 2075 | { | 
|---|
| 2076 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 2077 |  | 
|---|
| 2078 | TRACE("%p\n", fodInfos); | 
|---|
| 2079 |  | 
|---|
| 2080 | switch(wNotifyCode) | 
|---|
| 2081 | { | 
|---|
| 2082 | case CBN_SELENDOK: | 
|---|
| 2083 | { | 
|---|
| 2084 | LPSFOLDER tmpFolder; | 
|---|
| 2085 | int iItem; | 
|---|
| 2086 |  | 
|---|
| 2087 | iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB); | 
|---|
| 2088 |  | 
|---|
| 2089 | if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB, | 
|---|
| 2090 | iItem))) | 
|---|
| 2091 | return FALSE; | 
|---|
| 2092 |  | 
|---|
| 2093 |  | 
|---|
| 2094 | if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, | 
|---|
| 2095 | tmpFolder->pidlItem, | 
|---|
| 2096 | SBSP_ABSOLUTE))) | 
|---|
| 2097 | { | 
|---|
| 2098 | return TRUE; | 
|---|
| 2099 | } | 
|---|
| 2100 | break; | 
|---|
| 2101 | } | 
|---|
| 2102 |  | 
|---|
| 2103 | } | 
|---|
| 2104 | return FALSE; | 
|---|
| 2105 | } | 
|---|
| 2106 |  | 
|---|
| 2107 | /*********************************************************************** | 
|---|
| 2108 | *      FILEDLG95_LOOKIN_AddItem | 
|---|
| 2109 | * | 
|---|
| 2110 | * Adds an absolute pidl item to the lookin combo box | 
|---|
| 2111 | * returns the index of the inserted item | 
|---|
| 2112 | */ | 
|---|
| 2113 | static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId) | 
|---|
| 2114 | { | 
|---|
| 2115 | LPITEMIDLIST pidlNext; | 
|---|
| 2116 | SHFILEINFOA sfi; | 
|---|
| 2117 | SFOLDER *tmpFolder; | 
|---|
| 2118 | LookInInfos *liInfos; | 
|---|
| 2119 |  | 
|---|
| 2120 | TRACE("%08x\n", iInsertId); | 
|---|
| 2121 |  | 
|---|
| 2122 | if(!pidl) | 
|---|
| 2123 | return -1; | 
|---|
| 2124 |  | 
|---|
| 2125 | if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr))) | 
|---|
| 2126 | return -1; | 
|---|
| 2127 |  | 
|---|
| 2128 | tmpFolder = MemAlloc(sizeof(SFOLDER)); | 
|---|
| 2129 | tmpFolder->m_iIndent = 0; | 
|---|
| 2130 |  | 
|---|
| 2131 | /* Calculate the indentation of the item in the lookin*/ | 
|---|
| 2132 | pidlNext = pidl; | 
|---|
| 2133 | while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) ) | 
|---|
| 2134 | { | 
|---|
| 2135 | tmpFolder->m_iIndent++; | 
|---|
| 2136 | } | 
|---|
| 2137 |  | 
|---|
| 2138 | tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/ | 
|---|
| 2139 |  | 
|---|
| 2140 | if(tmpFolder->m_iIndent > liInfos->iMaxIndentation) | 
|---|
| 2141 | liInfos->iMaxIndentation = tmpFolder->m_iIndent; | 
|---|
| 2142 |  | 
|---|
| 2143 | sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM; | 
|---|
| 2144 | COMDLG32_SHGetFileInfoA((LPSTR)pidl, | 
|---|
| 2145 | 0, | 
|---|
| 2146 | &sfi, | 
|---|
| 2147 | sizeof(sfi), | 
|---|
| 2148 | SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX | 
|---|
| 2149 | | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED); | 
|---|
| 2150 |  | 
|---|
| 2151 | TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes); | 
|---|
| 2152 |  | 
|---|
| 2153 | if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM)) | 
|---|
| 2154 | { | 
|---|
| 2155 | int iItemID; | 
|---|
| 2156 |  | 
|---|
| 2157 | TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent); | 
|---|
| 2158 |  | 
|---|
| 2159 | /* Add the item at the end of the list */ | 
|---|
| 2160 | if(iInsertId < 0) | 
|---|
| 2161 | { | 
|---|
| 2162 | iItemID = CBAddString(hwnd,sfi.szDisplayName); | 
|---|
| 2163 | } | 
|---|
| 2164 | /* Insert the item at the iInsertId position*/ | 
|---|
| 2165 | else | 
|---|
| 2166 | { | 
|---|
| 2167 | iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId); | 
|---|
| 2168 | } | 
|---|
| 2169 |  | 
|---|
| 2170 | CBSetItemDataPtr(hwnd,iItemID,tmpFolder); | 
|---|
| 2171 | return iItemID; | 
|---|
| 2172 | } | 
|---|
| 2173 |  | 
|---|
| 2174 | MemFree( tmpFolder ); | 
|---|
| 2175 | return -1; | 
|---|
| 2176 |  | 
|---|
| 2177 | } | 
|---|
| 2178 |  | 
|---|
| 2179 | /*********************************************************************** | 
|---|
| 2180 | *      FILEDLG95_LOOKIN_InsertItemAfterParent | 
|---|
| 2181 | * | 
|---|
| 2182 | * Insert an item below its parent | 
|---|
| 2183 | */ | 
|---|
| 2184 | static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl) | 
|---|
| 2185 | { | 
|---|
| 2186 |  | 
|---|
| 2187 | LPITEMIDLIST pidlParent = GetParentPidl(pidl); | 
|---|
| 2188 | int iParentPos; | 
|---|
| 2189 |  | 
|---|
| 2190 | TRACE("\n"); | 
|---|
| 2191 |  | 
|---|
| 2192 | iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL); | 
|---|
| 2193 |  | 
|---|
| 2194 | if(iParentPos < 0) | 
|---|
| 2195 | { | 
|---|
| 2196 | iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent); | 
|---|
| 2197 | } | 
|---|
| 2198 |  | 
|---|
| 2199 | /* Free pidlParent memory */ | 
|---|
| 2200 | COMDLG32_SHFree((LPVOID)pidlParent); | 
|---|
| 2201 |  | 
|---|
| 2202 | return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1); | 
|---|
| 2203 | } | 
|---|
| 2204 |  | 
|---|
| 2205 | /*********************************************************************** | 
|---|
| 2206 | *      FILEDLG95_LOOKIN_SelectItem | 
|---|
| 2207 | * | 
|---|
| 2208 | * Adds an absolute pidl item to the lookin combo box | 
|---|
| 2209 | * returns the index of the inserted item | 
|---|
| 2210 | */ | 
|---|
| 2211 | int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl) | 
|---|
| 2212 | { | 
|---|
| 2213 | int iItemPos; | 
|---|
| 2214 | LookInInfos *liInfos; | 
|---|
| 2215 |  | 
|---|
| 2216 | TRACE("\n"); | 
|---|
| 2217 |  | 
|---|
| 2218 | iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL); | 
|---|
| 2219 |  | 
|---|
| 2220 | liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr); | 
|---|
| 2221 |  | 
|---|
| 2222 | if(iItemPos < 0) | 
|---|
| 2223 | { | 
|---|
| 2224 | while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1); | 
|---|
| 2225 | iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl); | 
|---|
| 2226 | } | 
|---|
| 2227 |  | 
|---|
| 2228 | else | 
|---|
| 2229 | { | 
|---|
| 2230 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos); | 
|---|
| 2231 | while(liInfos->iMaxIndentation > tmpFolder->m_iIndent) | 
|---|
| 2232 | { | 
|---|
| 2233 | int iRemovedItem; | 
|---|
| 2234 |  | 
|---|
| 2235 | if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd))) | 
|---|
| 2236 | break; | 
|---|
| 2237 | if(iRemovedItem < iItemPos) | 
|---|
| 2238 | iItemPos--; | 
|---|
| 2239 | } | 
|---|
| 2240 | } | 
|---|
| 2241 |  | 
|---|
| 2242 | CBSetCurSel(hwnd,iItemPos); | 
|---|
| 2243 | liInfos->uSelectedItem = iItemPos; | 
|---|
| 2244 |  | 
|---|
| 2245 | return 0; | 
|---|
| 2246 |  | 
|---|
| 2247 | } | 
|---|
| 2248 |  | 
|---|
| 2249 | /*********************************************************************** | 
|---|
| 2250 | *      FILEDLG95_LOOKIN_RemoveMostExpandedItem | 
|---|
| 2251 | * | 
|---|
| 2252 | * Remove the item with an expansion level over iExpansionLevel | 
|---|
| 2253 | */ | 
|---|
| 2254 | static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd) | 
|---|
| 2255 | { | 
|---|
| 2256 | int iItemPos; | 
|---|
| 2257 |  | 
|---|
| 2258 | LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr); | 
|---|
| 2259 |  | 
|---|
| 2260 | TRACE("\n"); | 
|---|
| 2261 |  | 
|---|
| 2262 | if(liInfos->iMaxIndentation <= 2) | 
|---|
| 2263 | return -1; | 
|---|
| 2264 |  | 
|---|
| 2265 | if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0) | 
|---|
| 2266 | { | 
|---|
| 2267 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos); | 
|---|
| 2268 | COMDLG32_SHFree(tmpFolder->pidlItem); | 
|---|
| 2269 | MemFree(tmpFolder); | 
|---|
| 2270 | CBDeleteString(hwnd,iItemPos); | 
|---|
| 2271 | liInfos->iMaxIndentation--; | 
|---|
| 2272 |  | 
|---|
| 2273 | return iItemPos; | 
|---|
| 2274 | } | 
|---|
| 2275 |  | 
|---|
| 2276 | return -1; | 
|---|
| 2277 | } | 
|---|
| 2278 |  | 
|---|
| 2279 | /*********************************************************************** | 
|---|
| 2280 | *      FILEDLG95_LOOKIN_SearchItem | 
|---|
| 2281 | * | 
|---|
| 2282 | * Search for pidl in the lookin combo box | 
|---|
| 2283 | * returns the index of the found item | 
|---|
| 2284 | */ | 
|---|
| 2285 | static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod) | 
|---|
| 2286 | { | 
|---|
| 2287 | int i = 0; | 
|---|
| 2288 | int iCount = CBGetCount(hwnd); | 
|---|
| 2289 |  | 
|---|
| 2290 | TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod); | 
|---|
| 2291 |  | 
|---|
| 2292 | if (iCount != CB_ERR) | 
|---|
| 2293 | { | 
|---|
| 2294 | for(;i<iCount;i++) | 
|---|
| 2295 | { | 
|---|
| 2296 | LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i); | 
|---|
| 2297 |  | 
|---|
| 2298 | if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem)) | 
|---|
| 2299 | return i; | 
|---|
| 2300 | if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg) | 
|---|
| 2301 | return i; | 
|---|
| 2302 | } | 
|---|
| 2303 | } | 
|---|
| 2304 |  | 
|---|
| 2305 | return -1; | 
|---|
| 2306 | } | 
|---|
| 2307 |  | 
|---|
| 2308 | /*********************************************************************** | 
|---|
| 2309 | *      FILEDLG95_LOOKIN_Clean | 
|---|
| 2310 | * | 
|---|
| 2311 | * Clean the memory used by the lookin combo box | 
|---|
| 2312 | */ | 
|---|
| 2313 | static void FILEDLG95_LOOKIN_Clean(HWND hwnd) | 
|---|
| 2314 | { | 
|---|
| 2315 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 2316 | int iPos; | 
|---|
| 2317 | int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB); | 
|---|
| 2318 |  | 
|---|
| 2319 | TRACE("\n"); | 
|---|
| 2320 |  | 
|---|
| 2321 | /* Delete each string of the combo and their associated data */ | 
|---|
| 2322 | if (iCount != CB_ERR) | 
|---|
| 2323 | { | 
|---|
| 2324 | for(iPos = iCount-1;iPos>=0;iPos--) | 
|---|
| 2325 | { | 
|---|
| 2326 | SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos); | 
|---|
| 2327 | COMDLG32_SHFree(tmpFolder->pidlItem); | 
|---|
| 2328 | MemFree(tmpFolder); | 
|---|
| 2329 | CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos); | 
|---|
| 2330 | } | 
|---|
| 2331 | } | 
|---|
| 2332 |  | 
|---|
| 2333 | /* LookInInfos structure */ | 
|---|
| 2334 | RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr); | 
|---|
| 2335 |  | 
|---|
| 2336 | } | 
|---|
| 2337 | /*********************************************************************** | 
|---|
| 2338 | * FILEDLG95_FILENAME_FillFromSelection | 
|---|
| 2339 | * | 
|---|
| 2340 | * fills the edit box from the cached DataObject | 
|---|
| 2341 | */ | 
|---|
| 2342 | void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd) | 
|---|
| 2343 | { | 
|---|
| 2344 | FileOpenDlgInfos *fodInfos; | 
|---|
| 2345 | LPITEMIDLIST      pidl; | 
|---|
| 2346 | UINT              nFiles = 0, nFileToOpen, nFileSelected, nLength = 0; | 
|---|
| 2347 | char              lpstrTemp[MAX_PATH]; | 
|---|
| 2348 | LPSTR             lpstrAllFile = NULL, lpstrCurrFile = NULL; | 
|---|
| 2349 |  | 
|---|
| 2350 | TRACE("\n"); | 
|---|
| 2351 | fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 2352 |  | 
|---|
| 2353 | /* Count how many files we have */ | 
|---|
| 2354 | nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject ); | 
|---|
| 2355 |  | 
|---|
| 2356 | /* calculate the string length, count files */ | 
|---|
| 2357 | if (nFileSelected >= 1) | 
|---|
| 2358 | { | 
|---|
| 2359 | nLength += 3;     /* first and last quotes, trailing \0 */ | 
|---|
| 2360 | for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ ) | 
|---|
| 2361 | { | 
|---|
| 2362 | pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 ); | 
|---|
| 2363 |  | 
|---|
| 2364 | if (pidl) | 
|---|
| 2365 | { | 
|---|
| 2366 | /* get the total length of the selected file names*/ | 
|---|
| 2367 | lpstrTemp[0] = '\0'; | 
|---|
| 2368 | GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp ); | 
|---|
| 2369 |  | 
|---|
| 2370 | if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */ | 
|---|
| 2371 | { | 
|---|
| 2372 | nLength += strlen( lpstrTemp ) + 3; | 
|---|
| 2373 | nFiles++; | 
|---|
| 2374 | } | 
|---|
| 2375 | COMDLG32_SHFree( pidl ); | 
|---|
| 2376 | } | 
|---|
| 2377 | } | 
|---|
| 2378 | } | 
|---|
| 2379 |  | 
|---|
| 2380 | /* allocate the buffer */ | 
|---|
| 2381 | if (nFiles <= 1) nLength = MAX_PATH; | 
|---|
| 2382 | lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength); | 
|---|
| 2383 | lpstrAllFile[0] = '\0'; | 
|---|
| 2384 |  | 
|---|
| 2385 | /* Generate the string for the edit control */ | 
|---|
| 2386 | if(nFiles >= 1) | 
|---|
| 2387 | { | 
|---|
| 2388 | lpstrCurrFile = lpstrAllFile; | 
|---|
| 2389 | for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ ) | 
|---|
| 2390 | { | 
|---|
| 2391 | pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 ); | 
|---|
| 2392 |  | 
|---|
| 2393 | if (pidl) | 
|---|
| 2394 | { | 
|---|
| 2395 | /* get the file name */ | 
|---|
| 2396 | lpstrTemp[0] = '\0'; | 
|---|
| 2397 | GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp ); | 
|---|
| 2398 |  | 
|---|
| 2399 | if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */ | 
|---|
| 2400 | { | 
|---|
| 2401 | if ( nFiles > 1) | 
|---|
| 2402 | { | 
|---|
| 2403 | *lpstrCurrFile++ =  '\"'; | 
|---|
| 2404 | strcpy( lpstrCurrFile, lpstrTemp ); | 
|---|
| 2405 | lpstrCurrFile += strlen( lpstrTemp ); | 
|---|
| 2406 | strcpy( lpstrCurrFile, "\" " ); | 
|---|
| 2407 | lpstrCurrFile += 2; | 
|---|
| 2408 | } | 
|---|
| 2409 | else | 
|---|
| 2410 | { | 
|---|
| 2411 | strcpy( lpstrAllFile, lpstrTemp ); | 
|---|
| 2412 | } | 
|---|
| 2413 | } | 
|---|
| 2414 | COMDLG32_SHFree( (LPVOID) pidl ); | 
|---|
| 2415 | } | 
|---|
| 2416 | } | 
|---|
| 2417 | } | 
|---|
| 2418 |  | 
|---|
| 2419 | SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile ); | 
|---|
| 2420 | HeapFree(GetProcessHeap(),0, lpstrAllFile ); | 
|---|
| 2421 | } | 
|---|
| 2422 |  | 
|---|
| 2423 |  | 
|---|
| 2424 | /* copied from shell32 to avoid linking to it */ | 
|---|
| 2425 | static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl) | 
|---|
| 2426 | { | 
|---|
| 2427 | switch (src->uType) | 
|---|
| 2428 | { | 
|---|
| 2429 | case STRRET_WSTR: | 
|---|
| 2430 | WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL); | 
|---|
| 2431 | COMDLG32_SHFree(src->u.pOleStr); | 
|---|
| 2432 | break; | 
|---|
| 2433 |  | 
|---|
| 2434 | case STRRET_CSTRA: | 
|---|
| 2435 | lstrcpynA((LPSTR)dest, src->u.cStr, len); | 
|---|
| 2436 | break; | 
|---|
| 2437 |  | 
|---|
| 2438 | case STRRET_OFFSETA: | 
|---|
| 2439 | lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len); | 
|---|
| 2440 | break; | 
|---|
| 2441 |  | 
|---|
| 2442 | default: | 
|---|
| 2443 | FIXME("unknown type!\n"); | 
|---|
| 2444 | if (len) | 
|---|
| 2445 | { | 
|---|
| 2446 | *(LPSTR)dest = '\0'; | 
|---|
| 2447 | } | 
|---|
| 2448 | return(FALSE); | 
|---|
| 2449 | } | 
|---|
| 2450 | return S_OK; | 
|---|
| 2451 | } | 
|---|
| 2452 |  | 
|---|
| 2453 | /*********************************************************************** | 
|---|
| 2454 | * FILEDLG95_FILENAME_GetFileNames | 
|---|
| 2455 | * | 
|---|
| 2456 | * copies the filenames to a 0-delimited string list (A\0B\0C\0\0) | 
|---|
| 2457 | */ | 
|---|
| 2458 | int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed) | 
|---|
| 2459 | { | 
|---|
| 2460 | FileOpenDlgInfos *fodInfos  = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 2461 | UINT nStrCharCount = 0; /* index in src buffer */ | 
|---|
| 2462 | UINT nFileIndex = 0;    /* index in dest buffer */ | 
|---|
| 2463 | UINT nFileCount = 0;    /* number of files */ | 
|---|
| 2464 | UINT nStrLen = 0;       /* length of string in edit control */ | 
|---|
| 2465 | LPSTR lpstrEdit;        /* buffer for string from edit control */ | 
|---|
| 2466 |  | 
|---|
| 2467 | TRACE("\n"); | 
|---|
| 2468 |  | 
|---|
| 2469 | /* get the filenames from the edit control */ | 
|---|
| 2470 | nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0); | 
|---|
| 2471 | lpstrEdit = MemAlloc(nStrLen+1); | 
|---|
| 2472 | GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1); | 
|---|
| 2473 |  | 
|---|
| 2474 | TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit); | 
|---|
| 2475 |  | 
|---|
| 2476 | /* we might get single filename without any '"', | 
|---|
| 2477 | * so we need nStrLen + terminating \0 + end-of-list \0 */ | 
|---|
| 2478 | *lpstrFileList = MemAlloc(nStrLen+2); | 
|---|
| 2479 | *sizeUsed = 0; | 
|---|
| 2480 |  | 
|---|
| 2481 | /* build 0-delimited file list from filenames */ | 
|---|
| 2482 | while ( nStrCharCount <= nStrLen ) | 
|---|
| 2483 | { | 
|---|
| 2484 | if ( lpstrEdit[nStrCharCount]=='"' ) | 
|---|
| 2485 | { | 
|---|
| 2486 | nStrCharCount++; | 
|---|
| 2487 | while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen)) | 
|---|
| 2488 | { | 
|---|
| 2489 | (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount]; | 
|---|
| 2490 | (*sizeUsed)++; | 
|---|
| 2491 | nStrCharCount++; | 
|---|
| 2492 | } | 
|---|
| 2493 | (*lpstrFileList)[nFileIndex++] = '\0'; | 
|---|
| 2494 | (*sizeUsed)++; | 
|---|
| 2495 | nFileCount++; | 
|---|
| 2496 | } | 
|---|
| 2497 | nStrCharCount++; | 
|---|
| 2498 | } | 
|---|
| 2499 |  | 
|---|
| 2500 | /* single, unquoted string */ | 
|---|
| 2501 | if ((nStrLen > 0) && (*sizeUsed == 0) ) | 
|---|
| 2502 | { | 
|---|
| 2503 | strcpy(*lpstrFileList, lpstrEdit); | 
|---|
| 2504 | nFileIndex = strlen(lpstrEdit) + 1; | 
|---|
| 2505 | (*sizeUsed) = nFileIndex; | 
|---|
| 2506 | nFileCount = 1; | 
|---|
| 2507 | } | 
|---|
| 2508 |  | 
|---|
| 2509 | /* trailing \0 */ | 
|---|
| 2510 | (*lpstrFileList)[nFileIndex] = '\0'; | 
|---|
| 2511 | (*sizeUsed)++; | 
|---|
| 2512 |  | 
|---|
| 2513 | MemFree(lpstrEdit); | 
|---|
| 2514 | return nFileCount; | 
|---|
| 2515 | } | 
|---|
| 2516 |  | 
|---|
| 2517 | #define SETDefFormatEtc(fe,cf,med) \ | 
|---|
| 2518 | { \ | 
|---|
| 2519 | (fe).cfFormat = cf;\ | 
|---|
| 2520 | (fe).dwAspect = DVASPECT_CONTENT; \ | 
|---|
| 2521 | (fe).ptd =NULL;\ | 
|---|
| 2522 | (fe).tymed = med;\ | 
|---|
| 2523 | (fe).lindex = -1;\ | 
|---|
| 2524 | }; | 
|---|
| 2525 |  | 
|---|
| 2526 | /* | 
|---|
| 2527 | * DATAOBJECT Helper functions | 
|---|
| 2528 | */ | 
|---|
| 2529 |  | 
|---|
| 2530 | /*********************************************************************** | 
|---|
| 2531 | * COMCTL32_ReleaseStgMedium | 
|---|
| 2532 | * | 
|---|
| 2533 | * like ReleaseStgMedium from ole32 | 
|---|
| 2534 | */ | 
|---|
| 2535 | static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium) | 
|---|
| 2536 | { | 
|---|
| 2537 | if(medium.pUnkForRelease) | 
|---|
| 2538 | { | 
|---|
| 2539 | IUnknown_Release(medium.pUnkForRelease); | 
|---|
| 2540 | } | 
|---|
| 2541 | else | 
|---|
| 2542 | { | 
|---|
| 2543 | GlobalUnlock(medium.u.hGlobal); | 
|---|
| 2544 | GlobalFree(medium.u.hGlobal); | 
|---|
| 2545 | } | 
|---|
| 2546 | } | 
|---|
| 2547 |  | 
|---|
| 2548 | /*********************************************************************** | 
|---|
| 2549 | *          GetPidlFromDataObject | 
|---|
| 2550 | * | 
|---|
| 2551 | * Return pidl(s) by number from the cached DataObject | 
|---|
| 2552 | * | 
|---|
| 2553 | * nPidlIndex=0 gets the fully qualified root path | 
|---|
| 2554 | */ | 
|---|
| 2555 | LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex) | 
|---|
| 2556 | { | 
|---|
| 2557 |  | 
|---|
| 2558 | STGMEDIUM medium; | 
|---|
| 2559 | FORMATETC formatetc; | 
|---|
| 2560 | LPITEMIDLIST pidl = NULL; | 
|---|
| 2561 |  | 
|---|
| 2562 | TRACE("sv=%p index=%u\n", doSelected, nPidlIndex); | 
|---|
| 2563 |  | 
|---|
| 2564 | /* Set the FORMATETC structure*/ | 
|---|
| 2565 | SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL); | 
|---|
| 2566 |  | 
|---|
| 2567 | /* Get the pidls from IDataObject */ | 
|---|
| 2568 | if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium))) | 
|---|
| 2569 | { | 
|---|
| 2570 | LPIDA cida = GlobalLock(medium.u.hGlobal); | 
|---|
| 2571 | if(nPidlIndex <= cida->cidl) | 
|---|
| 2572 | { | 
|---|
| 2573 | pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]])); | 
|---|
| 2574 | } | 
|---|
| 2575 | COMCTL32_ReleaseStgMedium(medium); | 
|---|
| 2576 | } | 
|---|
| 2577 | return pidl; | 
|---|
| 2578 | } | 
|---|
| 2579 |  | 
|---|
| 2580 | /*********************************************************************** | 
|---|
| 2581 | *          GetNumSelected | 
|---|
| 2582 | * | 
|---|
| 2583 | * Return the number of selected items in the DataObject. | 
|---|
| 2584 | * | 
|---|
| 2585 | */ | 
|---|
| 2586 | UINT GetNumSelected( IDataObject *doSelected ) | 
|---|
| 2587 | { | 
|---|
| 2588 | UINT retVal = 0; | 
|---|
| 2589 | STGMEDIUM medium; | 
|---|
| 2590 | FORMATETC formatetc; | 
|---|
| 2591 |  | 
|---|
| 2592 | TRACE("sv=%p\n", doSelected); | 
|---|
| 2593 |  | 
|---|
| 2594 | if (!doSelected) return 0; | 
|---|
| 2595 |  | 
|---|
| 2596 | /* Set the FORMATETC structure*/ | 
|---|
| 2597 | SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL); | 
|---|
| 2598 |  | 
|---|
| 2599 | /* Get the pidls from IDataObject */ | 
|---|
| 2600 | if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium))) | 
|---|
| 2601 | { | 
|---|
| 2602 | LPIDA cida = GlobalLock(medium.u.hGlobal); | 
|---|
| 2603 | retVal = cida->cidl; | 
|---|
| 2604 | COMCTL32_ReleaseStgMedium(medium); | 
|---|
| 2605 | return retVal; | 
|---|
| 2606 | } | 
|---|
| 2607 | return 0; | 
|---|
| 2608 | } | 
|---|
| 2609 |  | 
|---|
| 2610 | /* | 
|---|
| 2611 | * TOOLS | 
|---|
| 2612 | */ | 
|---|
| 2613 |  | 
|---|
| 2614 | /*********************************************************************** | 
|---|
| 2615 | *      GetName | 
|---|
| 2616 | * | 
|---|
| 2617 | * Get the pidl's display name (relative to folder) and | 
|---|
| 2618 | * put it in lpstrFileName. | 
|---|
| 2619 | * | 
|---|
| 2620 | * Return NOERROR on success, | 
|---|
| 2621 | * E_FAIL otherwise | 
|---|
| 2622 | */ | 
|---|
| 2623 |  | 
|---|
| 2624 | HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName) | 
|---|
| 2625 | { | 
|---|
| 2626 | STRRET str; | 
|---|
| 2627 | HRESULT hRes; | 
|---|
| 2628 |  | 
|---|
| 2629 | TRACE("sf=%p pidl=%p\n", lpsf, pidl); | 
|---|
| 2630 |  | 
|---|
| 2631 | if(!lpsf) | 
|---|
| 2632 | { | 
|---|
| 2633 | HRESULT hRes; | 
|---|
| 2634 | COMDLG32_SHGetDesktopFolder(&lpsf); | 
|---|
| 2635 | hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName); | 
|---|
| 2636 | IShellFolder_Release(lpsf); | 
|---|
| 2637 | return hRes; | 
|---|
| 2638 | } | 
|---|
| 2639 |  | 
|---|
| 2640 | /* Get the display name of the pidl relative to the folder */ | 
|---|
| 2641 | if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str))) | 
|---|
| 2642 | { | 
|---|
| 2643 | return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl); | 
|---|
| 2644 | } | 
|---|
| 2645 | return E_FAIL; | 
|---|
| 2646 | } | 
|---|
| 2647 |  | 
|---|
| 2648 | /*********************************************************************** | 
|---|
| 2649 | *      GetShellFolderFromPidl | 
|---|
| 2650 | * | 
|---|
| 2651 | * pidlRel is the item pidl relative | 
|---|
| 2652 | * Return the IShellFolder of the absolute pidl | 
|---|
| 2653 | */ | 
|---|
| 2654 | IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs) | 
|---|
| 2655 | { | 
|---|
| 2656 | IShellFolder *psf = NULL,*psfParent; | 
|---|
| 2657 |  | 
|---|
| 2658 | TRACE("%p\n", pidlAbs); | 
|---|
| 2659 |  | 
|---|
| 2660 | if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent))) | 
|---|
| 2661 | { | 
|---|
| 2662 | psf = psfParent; | 
|---|
| 2663 | if(pidlAbs && pidlAbs->mkid.cb) | 
|---|
| 2664 | { | 
|---|
| 2665 | if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf))) | 
|---|
| 2666 | { | 
|---|
| 2667 | IShellFolder_Release(psfParent); | 
|---|
| 2668 | return psf; | 
|---|
| 2669 | } | 
|---|
| 2670 | } | 
|---|
| 2671 | /* return the desktop */ | 
|---|
| 2672 | return psfParent; | 
|---|
| 2673 | } | 
|---|
| 2674 | return NULL; | 
|---|
| 2675 | } | 
|---|
| 2676 |  | 
|---|
| 2677 | /*********************************************************************** | 
|---|
| 2678 | *      GetParentPidl | 
|---|
| 2679 | * | 
|---|
| 2680 | * Return the LPITEMIDLIST to the parent of the pidl in the list | 
|---|
| 2681 | */ | 
|---|
| 2682 | LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl) | 
|---|
| 2683 | { | 
|---|
| 2684 | LPITEMIDLIST pidlParent; | 
|---|
| 2685 |  | 
|---|
| 2686 | TRACE("%p\n", pidl); | 
|---|
| 2687 |  | 
|---|
| 2688 | pidlParent = COMDLG32_PIDL_ILClone(pidl); | 
|---|
| 2689 | COMDLG32_PIDL_ILRemoveLastID(pidlParent); | 
|---|
| 2690 |  | 
|---|
| 2691 | return pidlParent; | 
|---|
| 2692 | } | 
|---|
| 2693 |  | 
|---|
| 2694 | /*********************************************************************** | 
|---|
| 2695 | *      GetPidlFromName | 
|---|
| 2696 | * | 
|---|
| 2697 | * returns the pidl of the file name relative to folder | 
|---|
| 2698 | * NULL if an error occured | 
|---|
| 2699 | */ | 
|---|
| 2700 | LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName) | 
|---|
| 2701 | { | 
|---|
| 2702 | LPITEMIDLIST pidl; | 
|---|
| 2703 | ULONG ulEaten; | 
|---|
| 2704 | WCHAR lpwstrDirName[MAX_PATH]; | 
|---|
| 2705 |  | 
|---|
| 2706 | TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName); | 
|---|
| 2707 |  | 
|---|
| 2708 | #ifdef __WIN32OS2__ | 
|---|
| 2709 | if(!lpcstrFileName || *lpcstrFileName == 0) return NULL; | 
|---|
| 2710 | #else | 
|---|
| 2711 | if(!lpcstrFileName) return NULL; | 
|---|
| 2712 | #endif | 
|---|
| 2713 |  | 
|---|
| 2714 | MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH); | 
|---|
| 2715 |  | 
|---|
| 2716 | if(!lpsf) | 
|---|
| 2717 | { | 
|---|
| 2718 | COMDLG32_SHGetDesktopFolder(&lpsf); | 
|---|
| 2719 | pidl = GetPidlFromName(lpsf, lpcstrFileName); | 
|---|
| 2720 | IShellFolder_Release(lpsf); | 
|---|
| 2721 | } | 
|---|
| 2722 | else | 
|---|
| 2723 | { | 
|---|
| 2724 | IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL); | 
|---|
| 2725 | } | 
|---|
| 2726 | return pidl; | 
|---|
| 2727 | } | 
|---|
| 2728 |  | 
|---|
| 2729 | /* | 
|---|
| 2730 | */ | 
|---|
| 2731 | BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl) | 
|---|
| 2732 | { | 
|---|
| 2733 | ULONG uAttr  = SFGAO_FOLDER | SFGAO_HASSUBFOLDER; | 
|---|
| 2734 | HRESULT ret; | 
|---|
| 2735 |  | 
|---|
| 2736 | TRACE("%p, %p\n", psf, pidl); | 
|---|
| 2737 |  | 
|---|
| 2738 | ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr ); | 
|---|
| 2739 |  | 
|---|
| 2740 | TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret); | 
|---|
| 2741 | /* see documentation shell 4.1*/ | 
|---|
| 2742 | return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER); | 
|---|
| 2743 | } | 
|---|
| 2744 |  | 
|---|
| 2745 | /*********************************************************************** | 
|---|
| 2746 | *      BrowseSelectedFolder | 
|---|
| 2747 | */ | 
|---|
| 2748 | static BOOL BrowseSelectedFolder(HWND hwnd) | 
|---|
| 2749 | { | 
|---|
| 2750 | BOOL bBrowseSelFolder = FALSE; | 
|---|
| 2751 | FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); | 
|---|
| 2752 |  | 
|---|
| 2753 | TRACE("\n"); | 
|---|
| 2754 |  | 
|---|
| 2755 | if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1) | 
|---|
| 2756 | { | 
|---|
| 2757 | LPITEMIDLIST pidlSelection; | 
|---|
| 2758 |  | 
|---|
| 2759 | /* get the file selected */ | 
|---|
| 2760 | pidlSelection  = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1); | 
|---|
| 2761 | if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection)) | 
|---|
| 2762 | { | 
|---|
| 2763 | if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser, | 
|---|
| 2764 | pidlSelection, SBSP_RELATIVE ) ) ) | 
|---|
| 2765 | { | 
|---|
| 2766 | MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle, | 
|---|
| 2767 | MB_OK | MB_ICONEXCLAMATION ); | 
|---|
| 2768 | } | 
|---|
| 2769 |  | 
|---|
| 2770 | bBrowseSelFolder = TRUE; | 
|---|
| 2771 | } | 
|---|
| 2772 | COMDLG32_SHFree( pidlSelection ); | 
|---|
| 2773 | } | 
|---|
| 2774 |  | 
|---|
| 2775 | return bBrowseSelFolder; | 
|---|
| 2776 | } | 
|---|
| 2777 |  | 
|---|
| 2778 | /* | 
|---|
| 2779 | * Memory allocation methods */ | 
|---|
| 2780 | static void *MemAlloc(UINT size) | 
|---|
| 2781 | { | 
|---|
| 2782 | return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size); | 
|---|
| 2783 | } | 
|---|
| 2784 |  | 
|---|
| 2785 | static void MemFree(void *mem) | 
|---|
| 2786 | { | 
|---|
| 2787 | if(mem) | 
|---|
| 2788 | { | 
|---|
| 2789 | HeapFree(GetProcessHeap(),0,mem); | 
|---|
| 2790 | } | 
|---|
| 2791 | } | 
|---|
| 2792 |  | 
|---|