2 * COMMDLG - File Open Dialogs Win95 look and feel
4 * FIXME: lpstrCustomFilter not handeled
6 * FIXME: if the size of lpstrFile (nMaxFile) is to small the first
7 * two bytes of lpstrFile should contain the needed size
9 * FIXME: algorithm for selecting the initial directory is to simple
11 * FIXME: add to recent docs
13 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
14 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
15 * OFN_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_READONLYRETURN,
16 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
18 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
33 #include "debugtools.h"
39 #include "filedlgbrowser.h"
41 #include "wine/obj_contextmenu.h"
43 DEFAULT_DEBUG_CHANNEL(commdlg);
45 /***********************************************************************
46 * Data structure and global variables
48 typedef struct SFolder
50 int m_iImageIndex; /* Index of picture in image list */
52 int m_iIndent; /* Indentation index */
53 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
57 typedef struct tagLookInInfo
64 /***********************************************************************
65 * Defines and global variables
68 /* Draw item constant */
76 /* SearchItem methods */
79 #define ITEM_NOTFOUND -1
81 /* Undefined windows message sent by CreateViewObject*/
82 #define WM_GETISHELLBROWSER WM_USER+7
85 * Those macros exist in windowsx.h. However, you can't really use them since
86 * they rely on the UNICODE defines and can't be use inside Wine itself.
89 /* Combo box macros */
90 #define CBAddString(hwnd,str) \
91 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
93 #define CBInsertString(hwnd,str,pos) \
94 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
96 #define CBDeleteString(hwnd,pos) \
97 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
99 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
100 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
102 #define CBGetItemDataPtr(hwnd,iItemId) \
103 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
105 #define CBGetLBText(hwnd,iItemId,str) \
106 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
108 #define CBGetCurSel(hwnd) \
109 SendMessageA(hwnd,CB_GETCURSEL,0,0);
111 #define CBSetCurSel(hwnd,pos) \
112 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
114 #define CBGetCount(hwnd) \
115 SendMessageA(hwnd,CB_GETCOUNT,0,0);
116 #define CBShowDropDown(hwnd,show) \
117 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
118 #define CBSetItemHeight(hwnd,index,height) \
119 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
122 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
123 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
125 static const char defaultFilter[] = "*.*";
127 /***********************************************************************
131 /* Internal functions used by the dialog */
132 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam);
133 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
134 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
135 BOOL FILEDLG95_OnOpen(HWND hwnd);
136 static LRESULT FILEDLG95_InitUI(HWND hwnd);
137 static void FILEDLG95_Clean(HWND hwnd);
139 /* Functions used by the shell navigation */
140 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
141 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
142 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
143 static void FILEDLG95_SHELL_Clean(HWND hwnd);
144 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
146 /* Functions used by the filetype combo box */
147 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
148 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
149 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
150 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
152 /* Functions used by the Look In combo box */
153 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
154 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
155 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
156 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
157 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
158 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
159 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
160 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
161 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
163 /* Miscellaneous tool functions */
164 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
165 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
166 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
167 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
168 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
170 /* Shell memory allocation */
171 static void *MemAlloc(UINT size);
172 static void MemFree(void *mem);
174 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
175 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
176 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
177 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
178 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
179 static BOOL BrowseSelectedFolder(HWND hwnd);
181 extern LPSTR _strlwr( LPSTR str );
183 /***********************************************************************
186 * Creates an Open common dialog box that lets the user select
187 * the drive, directory, and the name of a file or set of files to open.
189 * IN : The FileOpenDlgInfos structure associated with the dialog
190 * OUT : TRUE on success
191 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
193 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
201 /* Create the dialog from a template */
203 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
205 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
208 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
209 !(template = LockResource( hDlgTmpl )))
211 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
214 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
215 (LPDLGTEMPLATEA) template,
216 fodInfos->ofnInfos->hwndOwner,
217 (DLGPROC) FileOpenDlgProc95,
220 /* Unable to create the dialog*/
227 /***********************************************************************
230 * Call GetFileName95 with this structure and clean the memory.
232 * IN : The OPENFILENAMEA initialisation structure passed to
233 * GetOpenFileNameA win api function (see filedlg.c)
235 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
239 FileOpenDlgInfos *fodInfos;
241 LPCSTR lpstrInitialDir = NULL;
244 /* Initialise FileOpenDlgInfos structure*/
245 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
246 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
248 /* Pass in the original ofn */
249 fodInfos->ofnInfos = ofn;
251 /* Save original hInstance value */
252 hInstance = ofn->hInstance;
253 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
255 dwFlags = ofn->Flags;
256 ofn->Flags = ofn->Flags|OFN_WINE;
258 /* Replace the NULL lpstrInitialDir by the current folder */
259 if(!ofn->lpstrInitialDir)
261 lpstrInitialDir = ofn->lpstrInitialDir;
262 ofn->lpstrInitialDir = MemAlloc(MAX_PATH);
263 GetCurrentDirectoryA(MAX_PATH,(LPSTR)ofn->lpstrInitialDir);
266 /* Initialise the dialog property */
267 fodInfos->DlgInfos.dwDlgProp = 0;
268 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
273 ret = GetFileName95(fodInfos);
276 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
277 ret = GetFileName95(fodInfos);
285 MemFree((LPVOID)(ofn->lpstrInitialDir));
286 ofn->lpstrInitialDir = lpstrInitialDir;
289 ofn->Flags = dwFlags;
290 ofn->hInstance = hInstance;
291 MemFree((LPVOID)(fodInfos));
295 /***********************************************************************
298 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
299 * Call GetFileName95 with this structure and clean the memory.
301 * IN : The OPENFILENAMEW initialisation structure passed to
302 * GetOpenFileNameW win api function (see filedlg.c)
305 * some more strings are needing to be convertet AtoW
307 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
310 FileOpenDlgInfos *fodInfos;
312 LPCSTR lpstrFilter = NULL;
313 LPSTR lpstrCustomFilter = NULL;
314 LPWSTR lpstrFile = NULL;
317 /* Initialise FileOpenDlgInfos structure*/
318 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
319 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
321 /* Pass in the original ofn */
322 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
325 hInstance = fodInfos->ofnInfos->hInstance;
326 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
328 /* Save lpstrFilter */
329 if (ofn->lpstrFilter)
335 lpstrFilter = fodInfos->ofnInfos->lpstrFilter;
337 /* filter is a list... title\0ext\0......\0\0 */
338 s = (LPWSTR)ofn->lpstrFilter;
343 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
344 x = y = (LPSTR)MemAlloc(n);
345 s = (LPWSTR)ofn->lpstrFilter;
352 fodInfos->ofnInfos->lpstrFilter = (LPSTR)y;
354 /* Save lpstrCustomFilter */
355 if (ofn->lpstrCustomFilter)
361 lpstrCustomFilter = fodInfos->ofnInfos->lpstrCustomFilter;
362 /* filter is a list... title\0ext\0......\0\0 */
363 s = (LPWSTR)ofn->lpstrCustomFilter;
367 n = s - ofn->lpstrCustomFilter;
368 x = y = (LPSTR)MemAlloc(n);
369 s = (LPWSTR)ofn->lpstrCustomFilter;
376 fodInfos->ofnInfos->lpstrCustomFilter = (LPSTR)y;
380 dwFlags = fodInfos->ofnInfos->Flags;
381 fodInfos->ofnInfos->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
383 /* Initialise the dialog property */
384 fodInfos->DlgInfos.dwDlgProp = 0;
386 /* allocate ansi filename buffer */
387 lpstrFile = ofn->lpstrFile;
388 ofn->lpstrFile = MemAlloc(ofn->nMaxFile);
393 ret = GetFileName95(fodInfos);
396 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
397 ret = GetFileName95(fodInfos);
405 fodInfos->ofnInfos->Flags = dwFlags;
407 /* Restore lpstrFilter */
408 if (fodInfos->ofnInfos->lpstrFilter)
410 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrFilter));
411 fodInfos->ofnInfos->lpstrFilter = lpstrFilter;
413 if (fodInfos->ofnInfos->lpstrCustomFilter)
415 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrCustomFilter));
416 fodInfos->ofnInfos->lpstrCustomFilter = lpstrCustomFilter;
419 /* Restore hInstance */
420 fodInfos->ofnInfos->hInstance = hInstance;
421 MemFree((LPVOID)(fodInfos));
424 lstrcpynAtoW(lpstrFile, (LPCSTR)ofn->lpstrFile, ofn->nMaxFile);
425 MemFree(ofn->lpstrFile);
426 ofn->lpstrFile = lpstrFile;
431 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
434 HWND hwndChild,hwndStc32;
435 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
437 POINT ptParentClient;
439 ptMoveCtl.x = ptMoveCtl.y = 0;
440 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
441 GetClientRect(hwndParentDlg,&rectParent);
442 GetClientRect(hwndChildDlg,&rectChild);
445 GetWindowRect(hwndStc32,&rectStc32);
446 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
447 CopyRect(&rectTemp,&rectStc32);
449 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
450 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
452 if(rectStc32.right < rectTemp.right)
454 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
459 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
460 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
462 if(rectStc32.bottom < rectTemp.bottom)
464 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
469 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
470 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
475 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL)
477 SetRectEmpty(&rectTemp);
478 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
479 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
480 ptMoveCtl.y = rectParent.bottom-rectParent.top;
483 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
484 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
486 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y,
488 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
489 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
491 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
494 GetWindowRect(hwndStc32,&rectStc32);
495 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
498 SetRect(&rectStc32,0,0,0,0);
504 if(hwndChild != hwndStc32)
506 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
508 GetWindowRect(hwndChild,&rectCtrl);
509 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
512 Check the initial position of the controls relative to the initial
513 position and size of stc32 (before it is expanded).
515 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
517 rectCtrl.left += ptMoveCtl.x;
518 rectCtrl.top += ptMoveCtl.y;
520 else if (rectCtrl.left >= rectTemp.right)
521 rectCtrl.left += ptMoveCtl.x;
522 else if (rectCtrl.top >= rectTemp.bottom)
523 rectCtrl.top += ptMoveCtl.y;
525 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
526 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
527 SWP_NOSIZE | SWP_NOZORDER );
530 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
532 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
536 GetWindowRect(hwndStc32,&rectStc32);
537 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
538 ptMoveCtl.x = rectStc32.left - 0;
539 ptMoveCtl.y = rectStc32.top - 0;
544 if(hwndChild != hwndChildDlg)
547 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
549 GetWindowRect(hwndChild,&rectCtrl);
550 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
552 rectCtrl.left += ptMoveCtl.x;
553 rectCtrl.top += ptMoveCtl.y;
555 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
556 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
557 SWP_NOSIZE |SWP_NOZORDER );
560 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
567 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
569 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
574 fodInfos = (FileOpenDlgInfos *)lParam;
575 lParam = (LPARAM) fodInfos->ofnInfos;
576 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
577 if(fodInfos && (fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
578 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
582 if(fodInfos && (fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook )
583 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
584 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
587 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos,HWND hwnd)
593 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE || fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
595 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
597 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
599 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
606 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
607 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
609 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
612 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
614 !(template = LockResource( hDlgTmpl )))
616 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
621 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
624 ShowWindow(hChildDlg,SW_SHOW);
628 else if(fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK && fodInfos->ofnInfos->lpfnHook)
632 GetClientRect(hwnd,&rectHwnd);
633 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
634 tmplate.dwExtendedStyle = 0;
638 tmplate.cx = rectHwnd.right-rectHwnd.left;
639 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
641 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
646 /***********************************************************************
647 * SendCustomDlgNotificationMessage
649 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
652 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
654 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
657 if(fodInfos->DlgInfos.hwndCustomDlg)
660 ofnNotify.hdr.hwndFrom=hwndParentDlg;
661 ofnNotify.hdr.idFrom=0;
662 ofnNotify.hdr.code = uCode;
663 ofnNotify.lpOFN = fodInfos->ofnInfos;
664 return SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
669 /***********************************************************************
670 * FILEDLG95_HandleCustomDialogMessages
672 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
674 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
678 char lpstrPath[MAX_PATH];
679 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
680 if(!fodInfos) return -1;
684 case CDM_GETFILEPATH:
685 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
686 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
687 if (lpstrFileSpec==lpstrPath)
689 char lpstrCurrentDir[MAX_PATH];
690 /* Prepend the current path */
691 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
692 if ((LPSTR)lParam!=NULL)
693 wsnprintfA((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
694 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
698 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
699 reqSize=strlen(lpstrPath);
701 /* return the required buffer size */
704 case CDM_GETFOLDERPATH:
705 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
706 if ((LPSTR)lParam!=NULL)
707 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
708 return strlen(lpstrPath);
711 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
712 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFileNameA(lpstrPath);
713 if ((LPSTR)lParam!=NULL)
714 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
715 return strlen(lpstrFileSpec);
717 case CDM_SETCONTROLTEXT:
719 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
722 case CDM_HIDECONTROL:
724 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
730 /***********************************************************************
733 * File open dialog procedure
735 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
740 /* Adds the FileOpenDlgInfos in the property list of the dialog
741 so it will be easily accessible through a GetPropA(...) */
742 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) lParam);
744 FILEDLG95_OnWMInitDialog(hwnd, wParam, lParam);
745 ((FileOpenDlgInfos *)lParam)->DlgInfos.hwndCustomDlg =
746 CreateTemplateDialog((FileOpenDlgInfos *)lParam,hwnd);
747 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
750 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
753 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
756 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
762 case WM_GETISHELLBROWSER:
763 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
766 RemovePropA(hwnd, FileOpenDlgInfosStr);
771 LPNMHDR lpnmh = (LPNMHDR)lParam;
774 /* set up the button tooltips strings */
775 if(TTN_GETDISPINFOA == lpnmh->code )
777 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
778 switch(lpnmh->idFrom )
780 /* Up folder button */
781 case FCIDM_TB_UPFOLDER:
782 stringId = IDS_UPFOLDER;
784 /* New folder button */
785 case FCIDM_TB_NEWFOLDER:
786 stringId = IDS_NEWFOLDER;
788 /* List option button */
789 case FCIDM_TB_SMALLICON:
790 stringId = IDS_LISTVIEW;
792 /* Details option button */
793 case FCIDM_TB_REPORTVIEW:
794 stringId = IDS_REPORTVIEW;
797 case FCIDM_TB_DESKTOP:
798 stringId = IDS_TODESKTOP;
803 lpdi->hinst = COMMDLG_hInstance32;
804 lpdi->lpszText = (LPSTR) stringId;
809 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
810 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
815 /***********************************************************************
816 * FILEDLG95_OnWMInitDialog
818 * WM_INITDIALOG message handler
820 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
822 LPITEMIDLIST pidlItemId;
823 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
825 TRACE("dir=%s file=%s\n",
826 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
828 /* Get the initial directory pidl */
830 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
834 GetCurrentDirectoryA(MAX_PATH,path);
835 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
839 /* Initialise shell objects */
840 FILEDLG95_SHELL_Init(hwnd);
842 /* Initialise dialog UI */
843 FILEDLG95_InitUI(hwnd);
845 /* Initialize the Look In combo box*/
846 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
848 /* Initialize the filter combo box */
849 FILEDLG95_FILETYPE_Init(hwnd);
851 /* Browse to the initial directory */
852 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
854 /* Free pidlItem memory */
855 COMDLG32_SHFree(pidlItemId);
859 /***********************************************************************
862 * Regroups all the cleaning functions of the filedlg
864 void FILEDLG95_Clean(HWND hwnd)
866 FILEDLG95_FILETYPE_Clean(hwnd);
867 FILEDLG95_LOOKIN_Clean(hwnd);
868 FILEDLG95_SHELL_Clean(hwnd);
870 /***********************************************************************
871 * FILEDLG95_OnWMCommand
873 * WM_COMMAND message handler
875 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
877 WORD wNotifyCode = HIWORD(wParam); /* notification code */
878 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
879 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
885 if(FILEDLG95_OnOpen(hwnd))
886 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
890 FILEDLG95_Clean(hwnd);
891 EndDialog(hwnd, FALSE);
893 /* Filetype combo box */
895 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
897 /* LookIn combo box */
899 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
902 /* --- toolbar --- */
903 /* Up folder button */
904 case FCIDM_TB_UPFOLDER:
905 FILEDLG95_SHELL_UpFolder(hwnd);
907 /* New folder button */
908 case FCIDM_TB_NEWFOLDER:
909 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
911 /* List option button */
912 case FCIDM_TB_SMALLICON:
913 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
915 /* Details option button */
916 case FCIDM_TB_REPORTVIEW:
917 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
919 /* Details option button */
920 case FCIDM_TB_DESKTOP:
921 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
928 /* Do not use the listview selection anymore */
929 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
933 /***********************************************************************
934 * FILEDLG95_OnWMGetIShellBrowser
936 * WM_GETISHELLBROWSER message handler
938 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
941 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
945 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
951 /***********************************************************************
955 static LRESULT FILEDLG95_InitUI(HWND hwnd)
959 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
960 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
961 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
962 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
963 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
964 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
965 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
966 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
967 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
971 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
972 { COMDLG32_hInstance, 800 } // desktop icon
977 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
979 TRACE("%p\n", fodInfos);
981 /* Get the hwnd of the controls */
982 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
983 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
984 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
986 /* construct the toolbar */
987 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
988 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
990 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
991 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
993 hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
995 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
996 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
997 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
999 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
1001 /* fixme: use TB_LOADIMAGES when implemented */
1002 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
1003 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
1004 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
1006 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
1007 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
1009 /* Set the window text with the text specified in the OPENFILENAME structure */
1010 if(fodInfos->ofnInfos->lpstrTitle)
1012 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
1014 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1016 SetWindowTextA(hwnd,"Save");
1019 /* Initialise the file name edit control */
1020 if(fodInfos->ofnInfos->lpstrFile)
1022 LPSTR lpstrFile = COMDLG32_PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
1023 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
1026 /* Must the open as read only check box be checked ?*/
1027 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
1029 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
1032 /* Must the open as read only check box be hid ?*/
1033 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
1035 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
1038 /* Must the help button be hid ?*/
1039 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
1041 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
1044 /* Resize the height, if open as read only checkbox ad help button
1046 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1047 (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP)) )
1049 RECT rectDlg, rectHelp, rectCancel;
1050 GetWindowRect(hwnd, &rectDlg);
1051 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1052 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1053 /* subtract the height of the help button plus the space between
1054 the help button and the cancel button to the height of the dialog */
1055 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1056 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1057 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1060 /* change Open to Save FIXME: use resources */
1061 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1063 SetDlgItemTextA(hwnd,IDOK,"&Save");
1064 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1069 /***********************************************************************
1070 * FILEDLG95_OnOpenMultipleFiles
1072 * Handles the opening of multiple files.
1075 * check destination buffer size
1077 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1079 CHAR lpstrPathSpec[MAX_PATH] = "";
1081 UINT nCount, nSizePath;
1082 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1086 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1087 lpstrFile[0] = '\0';
1089 COMDLG32_SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1091 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1092 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1094 LPSTR lpstrTemp = lpstrFileList;
1096 for ( nCount = 0; nCount < nFileCount; nCount++ )
1100 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1103 CHAR lpstrNotFound[100];
1107 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1108 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1110 strcpy(tmp, lpstrTemp);
1112 strcat(tmp, lpstrNotFound);
1114 strcat(tmp, lpstrMsg);
1116 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1120 lpstrTemp += strlen(lpstrFileList) + 1;
1121 COMDLG32_SHFree(pidl);
1125 nSizePath = lstrlenA(lpstrPathSpec);
1126 lstrcpyA( lpstrFile, lpstrPathSpec);
1127 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1129 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1130 fodInfos->ofnInfos->nFileExtension = 0;
1132 /* clean and exit */
1133 FILEDLG95_Clean(hwnd);
1134 return EndDialog(hwnd,TRUE);
1137 /***********************************************************************
1140 * Ok button WM_COMMAND message handler
1142 * If the function succeeds, the return value is nonzero.
1144 #define ONOPEN_BROWSE 1
1145 #define ONOPEN_OPEN 2
1146 #define ONOPEN_SEARCH 3
1147 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1149 char strMsgTitle[MAX_PATH];
1150 char strMsgText [MAX_PATH];
1152 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1154 strMsgTitle[0] = '\0';
1155 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1156 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1159 BOOL FILEDLG95_OnOpen(HWND hwnd)
1161 char * lpstrFileList;
1162 UINT nFileCount = 0;
1165 char lpstrPathAndFile[MAX_PATH];
1166 char lpstrTemp[MAX_PATH];
1167 LPSHELLFOLDER lpsf = NULL;
1169 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1172 TRACE("hwnd=0x%04x\n", hwnd);
1174 /* get the files from the edit control */
1175 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1177 /* try if the user selected a folder in the shellview */
1180 BrowseSelectedFolder(hwnd);
1186 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1190 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1193 Step 1: Build a complete path name from the current folder and
1194 the filename or path in the edit box.
1196 - the path in the edit box is a root path
1197 (with or without drive letter)
1198 - the edit box contains ".." (or a path with ".." in it)
1201 /* Get the current directory name */
1202 if (!COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1204 /* we are in a special folder, default to desktop */
1205 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL, 0, lpstrPathAndFile)))
1208 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1211 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1213 TRACE("current directory=%s\n", lpstrPathAndFile);
1215 /* if the user specifyed a fully qualified path use it */
1216 if(COMDLG32_PathIsRelativeA(lpstrFileList))
1218 strcat(lpstrPathAndFile, lpstrFileList);
1222 /* does the path have a drive letter? */
1223 if (COMDLG32_PathGetDriveNumberA(lpstrFileList) == -1)
1224 strcpy(lpstrPathAndFile+2, lpstrFileList);
1226 strcpy(lpstrPathAndFile, lpstrFileList);
1229 /* resolve "." and ".." */
1230 COMDLG32_PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1231 strcpy(lpstrPathAndFile, lpstrTemp);
1232 TRACE("canon=%s\n", lpstrPathAndFile);
1234 MemFree(lpstrFileList);
1237 Step 2: here we have a cleaned up path
1239 We have to parse the path step by step to see if we have to browse
1240 to a folder if the path points to a directory or the last
1241 valid element is a directory.
1244 lpstrPathAndFile: cleaned up path
1247 nOpenAction = ONOPEN_BROWSE;
1249 /* dont apply any checks with OFN_NOVALIDATE */
1250 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1252 LPSTR lpszTemp, lpszTemp1;
1253 LPITEMIDLIST pidl = NULL;
1255 /* check for invalid chars */
1256 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1258 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1263 if (FAILED (COMDLG32_SHGetDesktopFolder(&lpsf))) return FALSE;
1265 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1268 LPSHELLFOLDER lpsfChild;
1269 WCHAR lpwstrTemp[MAX_PATH];
1270 DWORD dwEaten, dwAttributes;
1272 lpszTemp = COMDLG32_PathFindNextComponentA(lpszTemp);
1274 lstrcpynAtoW(lpwstrTemp, lpszTemp1, lpszTemp - lpszTemp1);
1277 lstrcpyAtoW(lpwstrTemp, lpszTemp1); /* last element */
1278 if(strpbrk(lpszTemp1, "*?") != NULL)
1280 nOpenAction = ONOPEN_SEARCH;
1284 lpszTemp1 = lpszTemp;
1286 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1288 if(lstrlenW(lpwstrTemp)==2) COMDLG32_PathAddBackslashW(lpwstrTemp);
1290 dwAttributes = SFGAO_FOLDER;
1291 if(FAILED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1293 if(*lpszTemp) /* points to trailing null for last path element */
1295 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1297 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1303 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1305 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1309 /* change to the current folder */
1310 nOpenAction = ONOPEN_OPEN;
1315 /* the path component is valid */
1316 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1317 if(dwAttributes & SFGAO_FOLDER)
1319 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1321 ERR("bind to failed\n"); /* should not fail */
1324 IShellFolder_Release(lpsf);
1332 /* end dialog, return value */
1333 nOpenAction = ONOPEN_OPEN;
1336 COMDLG32_SHFree(pidl);
1340 if(pidl) COMDLG32_SHFree(pidl);
1343 /* path is valid, clean the edit box */
1344 SetDlgItemTextA(hwnd,IDC_FILENAME,"");
1347 Step 3: here we have a cleaned up and validated path
1350 lpsf: ShellFolder bound to the rightmost valid path component
1351 lpstrPathAndFile: cleaned up path
1352 nOpenAction: action to do
1354 TRACE("end validate sf=%p\n", lpsf);
1358 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1359 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1362 LPSTR lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1364 /* replace the current filter */
1365 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1366 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1367 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpszTemp)+1)*sizeof(WCHAR));
1368 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpszTemp);
1370 /* set the filter cb to the extension when possible */
1371 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1372 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1375 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1376 TRACE("ONOPEN_BROWSE\n");
1378 IPersistFolder2 * ppf2;
1379 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1381 LPITEMIDLIST pidlCurrent;
1382 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1383 IPersistFolder2_Release(ppf2);
1384 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1386 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1388 else if( nOpenAction == ONOPEN_SEARCH )
1390 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1392 COMDLG32_SHFree(pidlCurrent);
1397 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1398 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1400 /* add default extension */
1401 if (fodInfos->ofnInfos->lpstrDefExt)
1403 if (! *COMDLG32_PathFindExtensionA(lpstrPathAndFile))
1405 strcat(lpstrPathAndFile, ".");
1406 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1410 /* Check that size size of the file does not exceed buffer size */
1411 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile)
1415 /* fill destination buffer */
1416 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1418 /* set filename offset */
1419 lpszTemp = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1420 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1422 /* set extension offset */
1423 lpszTemp = COMDLG32_PathFindExtensionA(lpstrPathAndFile);
1424 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1426 /* set the lpstrFileTitle */
1427 if(fodInfos->ofnInfos->lpstrFileTitle)
1429 LPSTR lpstrFileTitle = COMDLG32_PathFindFileNameA(lpstrPathAndFile);
1430 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1433 FILEDLG95_Clean(hwnd);
1434 ret = EndDialog(hwnd, TRUE);
1438 /* FIXME set error FNERR_BUFFERTOSMALL */
1439 FILEDLG95_Clean(hwnd);
1440 ret = EndDialog(hwnd, FALSE);
1448 if(lpsf) IShellFolder_Release(lpsf);
1452 /***********************************************************************
1453 * FILEDLG95_SHELL_Init
1455 * Initialisation of the shell objects
1457 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1459 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1464 * Initialisation of the FileOpenDialogInfos structure
1470 fodInfos->ShellInfos.hwndOwner = hwnd;
1472 /* Disable multi-select if flag not set */
1473 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1475 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1477 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1478 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1480 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1481 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1482 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1484 /* Construct the IShellBrowser interface */
1485 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1490 /***********************************************************************
1491 * FILEDLG95_SHELL_ExecuteCommand
1493 * Change the folder option and refresh the view
1494 * If the function succeeds, the return value is nonzero.
1496 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1498 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1501 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1503 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1508 CMINVOKECOMMANDINFO ci;
1509 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1510 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1514 IContextMenu_InvokeCommand(pcm, &ci);
1515 IContextMenu_Release(pcm);
1521 /***********************************************************************
1522 * FILEDLG95_SHELL_UpFolder
1524 * Browse to the specified object
1525 * If the function succeeds, the return value is nonzero.
1527 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1529 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1533 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1542 /***********************************************************************
1543 * FILEDLG95_SHELL_BrowseToDesktop
1545 * Browse to the Desktop
1546 * If the function succeeds, the return value is nonzero.
1548 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1550 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1556 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1557 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1558 COMDLG32_SHFree(pidl);
1559 return SUCCEEDED(hres);
1561 /***********************************************************************
1562 * FILEDLG95_SHELL_Clean
1564 * Cleans the memory used by shell objects
1566 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1568 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1572 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1574 /* clean Shell interfaces */
1575 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1576 IShellView_Release(fodInfos->Shell.FOIShellView);
1577 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1578 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1579 if (fodInfos->Shell.FOIDataObject)
1580 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1583 /***********************************************************************
1584 * FILEDLG95_FILETYPE_Init
1586 * Initialisation of the file type combo box
1588 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1590 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1594 if(fodInfos->ofnInfos->lpstrFilter)
1596 int nFilters = 0; /* number of filters */
1598 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1602 /* filter is a list... title\0ext\0......\0\0
1603 * Set the combo item text to the title and the item data
1606 LPCSTR lpstrDisplay;
1610 if(! *lpstrPos) break; /* end */
1611 lpstrDisplay = lpstrPos;
1612 lpstrPos += strlen(lpstrPos) + 1;
1614 /* Copy the extensions */
1615 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1616 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1617 strcpy(lpstrExt,lpstrPos);
1618 lpstrPos += strlen(lpstrPos) + 1;
1620 /* Add the item at the end of the combo */
1621 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1622 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1626 * Set the current filter to the one specified
1627 * in the initialisation structure
1628 * FIXME: lpstrCustomFilter not handled at all
1631 /* set default filter index */
1632 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1633 fodInfos->ofnInfos->nFilterIndex = 1;
1635 /* First, check to make sure our index isn't out of bounds. */
1636 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1637 fodInfos->ofnInfos->nFilterIndex = nFilters;
1639 /* Set the current index selection. */
1640 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1642 /* Get the corresponding text string from the combo box. */
1643 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1644 fodInfos->ofnInfos->nFilterIndex-1);
1646 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1651 _strlwr(lpstrFilter); /* lowercase */
1652 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1653 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter, lpstrFilter);
1659 /***********************************************************************
1660 * FILEDLG95_FILETYPE_OnCommand
1662 * WM_COMMAND of the file type combo box
1663 * If the function succeeds, the return value is nonzero.
1665 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1667 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1675 /* Get the current item of the filetype combo box */
1676 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1678 /* set the current filter index - indexed from 1 */
1679 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1681 /* Set the current filter with the current selection */
1682 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1683 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1685 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1687 if((int)lpstrFilter != CB_ERR)
1689 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1690 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,_strlwr(lpstrFilter));
1691 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1694 /* Refresh the actual view to display the included items*/
1695 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1700 /***********************************************************************
1701 * FILEDLG95_FILETYPE_SearchExt
1703 * searches for a extension in the filetype box
1705 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1707 int i, iCount = CBGetCount(hwnd);
1709 TRACE("%s\n", lpstrExt);
1711 if(iCount != CB_ERR)
1713 for(i=0;i<iCount;i++)
1715 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1722 /***********************************************************************
1723 * FILEDLG95_FILETYPE_Clean
1725 * Clean the memory used by the filetype combo box
1727 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1729 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1731 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1735 /* Delete each string of the combo and their associated data */
1736 if(iCount != CB_ERR)
1738 for(iPos = iCount-1;iPos>=0;iPos--)
1740 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1741 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1744 /* Current filter */
1745 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1746 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1750 /***********************************************************************
1751 * FILEDLG95_LOOKIN_Init
1753 * Initialisation of the look in combo box
1755 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1757 IShellFolder *psfRoot, *psfDrives;
1758 IEnumIDList *lpeRoot, *lpeDrives;
1759 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1761 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1765 liInfos->iMaxIndentation = 0;
1767 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1768 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1770 /* Initialise data of Desktop folder */
1771 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1772 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1773 COMDLG32_SHFree(pidlTmp);
1775 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1777 COMDLG32_SHGetDesktopFolder(&psfRoot);
1781 /* enumerate the contents of the desktop */
1782 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1784 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1786 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1788 /* special handling for CSIDL_DRIVES */
1789 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1791 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1793 /* enumerate the drives */
1794 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1796 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1798 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1799 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1800 COMDLG32_SHFree(pidlAbsTmp);
1801 COMDLG32_SHFree(pidlTmp1);
1803 IEnumIDList_Release(lpeDrives);
1805 IShellFolder_Release(psfDrives);
1808 COMDLG32_SHFree(pidlTmp);
1810 IEnumIDList_Release(lpeRoot);
1814 IShellFolder_Release(psfRoot);
1815 COMDLG32_SHFree(pidlDrives);
1819 /***********************************************************************
1820 * FILEDLG95_LOOKIN_DrawItem
1822 * WM_DRAWITEM message handler
1824 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1826 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1827 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1828 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1832 HIMAGELIST ilItemImage;
1834 LPSFOLDER tmpFolder;
1837 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1841 if(pDIStruct->itemID == -1)
1844 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1845 pDIStruct->itemID)))
1849 if(pDIStruct->itemID == liInfos->uSelectedItem)
1851 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1854 sizeof (SHFILEINFOA),
1855 SHGFI_PIDL | SHGFI_SMALLICON |
1856 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1857 SHGFI_DISPLAYNAME );
1861 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1864 sizeof (SHFILEINFOA),
1865 SHGFI_PIDL | SHGFI_SMALLICON |
1866 SHGFI_SYSICONINDEX |
1870 /* Is this item selected ?*/
1871 if(pDIStruct->itemState & ODS_SELECTED)
1873 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
1874 SetBkColor(pDIStruct->hDC,crHighLight);
1875 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
1879 SetTextColor(pDIStruct->hDC,crText);
1880 SetBkColor(pDIStruct->hDC,crWin);
1881 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
1884 /* Do not indent item if drawing in the edit of the combo*/
1885 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
1888 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1891 sizeof (SHFILEINFOA),
1892 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
1893 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
1898 iIndentation = tmpFolder->m_iIndent;
1900 /* Draw text and icon */
1902 /* Initialise the icon display area */
1903 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
1904 rectIcon.top = pDIStruct->rcItem.top;
1905 rectIcon.right = rectIcon.left + ICONWIDTH;
1906 rectIcon.bottom = pDIStruct->rcItem.bottom;
1908 /* Initialise the text display area */
1909 rectText.left = rectIcon.right;
1910 rectText.top = pDIStruct->rcItem.top + YTEXTOFFSET;
1911 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
1912 rectText.bottom = pDIStruct->rcItem.bottom;
1915 /* Draw the icon from the image list */
1916 COMDLG32_ImageList_Draw(ilItemImage,
1923 /* Draw the associated text */
1924 if(sfi.szDisplayName)
1925 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
1931 /***********************************************************************
1932 * FILEDLG95_LOOKIN_OnCommand
1934 * LookIn combo box WM_COMMAND message handler
1935 * If the function succeeds, the return value is nonzero.
1937 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
1939 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1941 TRACE("%p\n", fodInfos);
1947 LPSFOLDER tmpFolder;
1950 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
1952 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
1957 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1958 tmpFolder->pidlItem,
1970 /***********************************************************************
1971 * FILEDLG95_LOOKIN_AddItem
1973 * Adds an absolute pidl item to the lookin combo box
1974 * returns the index of the inserted item
1976 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
1978 LPITEMIDLIST pidlNext;
1981 LookInInfos *liInfos;
1988 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
1991 tmpFolder = MemAlloc(sizeof(SFOLDER));
1992 tmpFolder->m_iIndent = 0;
1994 /* Calculate the indentation of the item in the lookin*/
1996 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
1998 tmpFolder->m_iIndent++;
2001 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2003 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2004 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2006 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2007 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
2011 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2012 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2015 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2019 /* Add the item at the end of the list */
2022 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2024 /* Insert the item at the iInsertId position*/
2027 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2030 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2034 MemFree( tmpFolder );
2039 /***********************************************************************
2040 * FILEDLG95_LOOKIN_InsertItemAfterParent
2042 * Insert an item below its parent
2044 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2047 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2052 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2056 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2059 /* Free pidlParent memory */
2060 COMDLG32_SHFree((LPVOID)pidlParent);
2062 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2065 /***********************************************************************
2066 * FILEDLG95_LOOKIN_SelectItem
2068 * Adds an absolute pidl item to the lookin combo box
2069 * returns the index of the inserted item
2071 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2074 LookInInfos *liInfos;
2078 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2080 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2084 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2085 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2090 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2091 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2095 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2097 if(iRemovedItem < iItemPos)
2102 CBSetCurSel(hwnd,iItemPos);
2103 liInfos->uSelectedItem = iItemPos;
2109 /***********************************************************************
2110 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2112 * Remove the item with an expansion level over iExpansionLevel
2114 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2118 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2122 if(liInfos->iMaxIndentation <= 2)
2125 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2127 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2128 COMDLG32_SHFree(tmpFolder->pidlItem);
2130 CBDeleteString(hwnd,iItemPos);
2131 liInfos->iMaxIndentation--;
2139 /***********************************************************************
2140 * FILEDLG95_LOOKIN_SearchItem
2142 * Search for pidl in the lookin combo box
2143 * returns the index of the found item
2145 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2148 int iCount = CBGetCount(hwnd);
2152 if (iCount != CB_ERR)
2156 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2158 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2160 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2168 /***********************************************************************
2169 * FILEDLG95_LOOKIN_Clean
2171 * Clean the memory used by the lookin combo box
2173 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2175 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2177 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2181 /* Delete each string of the combo and their associated data */
2182 if (iCount != CB_ERR)
2184 for(iPos = iCount-1;iPos>=0;iPos--)
2186 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2187 COMDLG32_SHFree(tmpFolder->pidlItem);
2189 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2193 /* LookInInfos structure */
2194 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2197 /***********************************************************************
2198 * FILEDLG95_FILENAME_FillFromSelection
2200 * fills the edit box from the cached DataObject
2202 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2204 FileOpenDlgInfos *fodInfos;
2206 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2207 char lpstrTemp[MAX_PATH];
2208 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2211 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2213 /* Count how many files we have */
2214 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2216 /* calculate the string length, count files */
2217 if (nFileSelected >= 1)
2219 nLength += 3; /* first and last quotes, trailing \0 */
2220 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2222 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2226 /* get the total length of the selected file names*/
2227 lpstrTemp[0] = '\0';
2228 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2230 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2232 nLength += lstrlenA( lpstrTemp ) + 3;
2235 COMDLG32_SHFree( pidl );
2240 /* allocate the buffer */
2241 if (nFiles <= 1) nLength = MAX_PATH;
2242 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2243 lpstrAllFile[0] = '\0';
2245 /* Generate the string for the edit control */
2248 lpstrCurrFile = lpstrAllFile;
2249 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2251 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2255 /* get the file name */
2256 lpstrTemp[0] = '\0';
2257 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2259 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2263 *lpstrCurrFile++ = '\"';
2264 lstrcpyA( lpstrCurrFile, lpstrTemp );
2265 lpstrCurrFile += lstrlenA( lpstrTemp );
2266 lstrcpyA( lpstrCurrFile, "\" " );
2271 lstrcpyA( lpstrAllFile, lpstrTemp );
2274 COMDLG32_SHFree( (LPVOID) pidl );
2279 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2280 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2284 /* copied from shell32 to avoid linking to it */
2285 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2290 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2291 COMDLG32_SHFree(src->u.pOleStr);
2295 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2298 case STRRET_OFFSETA:
2299 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2303 FIXME("unknown type!\n");
2306 *(LPSTR)dest = '\0';
2313 /***********************************************************************
2314 * FILEDLG95_FILENAME_GetFileNames
2316 * copys the filenames to a 0-delimited string
2318 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2320 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2321 UINT nStrCharCount = 0; /* index in src buffer */
2322 UINT nFileIndex = 0; /* index in dest buffer */
2323 UINT nFileCount = 0; /* number of files */
2324 UINT nStrLen = 0; /* length of string in edit control */
2325 LPSTR lpstrEdit; /* buffer for string from edit control */
2329 /* get the filenames from the edit control */
2330 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2331 lpstrEdit = MemAlloc(nStrLen+1);
2332 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2334 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2336 *lpstrFileList = MemAlloc(nStrLen);
2339 /* build 0-delimited file list from filenames*/
2340 while ( nStrCharCount <= nStrLen )
2342 if ( lpstrEdit[nStrCharCount]=='"' )
2345 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2347 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2351 (*lpstrFileList)[nFileIndex++] = '\0';
2358 /* single, unquoted string */
2359 if ((nStrLen > 0) && (*sizeUsed == 0) )
2361 strcpy(*lpstrFileList, lpstrEdit);
2362 nFileIndex = strlen(lpstrEdit) + 1;
2363 (*sizeUsed) = nFileIndex;
2368 (*lpstrFileList)[nFileIndex] = '\0';
2375 #define SETDefFormatEtc(fe,cf,med) \
2377 (fe).cfFormat = cf;\
2378 (fe).dwAspect = DVASPECT_CONTENT; \
2385 * DATAOBJECT Helper functions
2388 /***********************************************************************
2389 * COMCTL32_ReleaseStgMedium
2391 * like ReleaseStgMedium from ole32
2393 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2395 if(medium.pUnkForRelease)
2397 IUnknown_Release(medium.pUnkForRelease);
2401 GlobalUnlock(medium.u.hGlobal);
2402 GlobalFree(medium.u.hGlobal);
2406 /***********************************************************************
2407 * GetPidlFromDataObject
2409 * Return pidl(s) by number from the cached DataObject
2411 * nPidlIndex=0 gets the fully qualified root path
2413 LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2417 FORMATETC formatetc;
2418 LPITEMIDLIST pidl = NULL;
2420 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2422 /* Set the FORMATETC structure*/
2423 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2425 /* Get the pidls from IDataObject */
2426 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2428 LPIDA cida = GlobalLock(medium.u.hGlobal);
2429 if(nPidlIndex <= cida->cidl)
2431 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2433 COMCTL32_ReleaseStgMedium(medium);
2438 /***********************************************************************
2441 * Return the number of selected items in the DataObject.
2444 UINT GetNumSelected( IDataObject *doSelected )
2448 FORMATETC formatetc;
2450 TRACE("sv=%p\n", doSelected);
2452 if (!doSelected) return 0;
2454 /* Set the FORMATETC structure*/
2455 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2457 /* Get the pidls from IDataObject */
2458 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2460 LPIDA cida = GlobalLock(medium.u.hGlobal);
2461 retVal = cida->cidl;
2462 COMCTL32_ReleaseStgMedium(medium);
2472 /***********************************************************************
2475 * Get the pidl's display name (relative to folder) and
2476 * put it in lpstrFileName.
2478 * Return NOERROR on success,
2482 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2487 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2492 COMDLG32_SHGetDesktopFolder(&lpsf);
2493 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2494 IShellFolder_Release(lpsf);
2498 /* Get the display name of the pidl relative to the folder */
2499 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2501 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2506 /***********************************************************************
2507 * GetShellFolderFromPidl
2509 * pidlRel is the item pidl relative
2510 * Return the IShellFolder of the absolute pidl
2512 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2514 IShellFolder *psf = NULL,*psfParent;
2516 TRACE("%p\n", pidlAbs);
2518 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2521 if(pidlAbs && pidlAbs->mkid.cb)
2523 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2525 IShellFolder_Release(psfParent);
2529 /* return the desktop */
2535 /***********************************************************************
2538 * Return the LPITEMIDLIST to the parent of the pidl in the list
2540 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2542 LPITEMIDLIST pidlParent;
2544 TRACE("%p\n", pidl);
2546 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2547 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2552 /***********************************************************************
2555 * returns the pidl of the file name relative to folder
2556 * NULL if an error occured
2558 LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2562 WCHAR lpwstrDirName[MAX_PATH];
2564 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2566 if(!lpcstrFileName) return NULL;
2568 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2572 COMDLG32_SHGetDesktopFolder(&lpsf);
2573 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2574 IShellFolder_Release(lpsf);
2578 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2585 BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2587 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2590 TRACE("%p, %p\n", psf, pidl);
2592 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2594 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2595 /* see documentation shell 4.1*/
2596 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2599 /***********************************************************************
2600 * BrowseSelectedFolder
2602 static BOOL BrowseSelectedFolder(HWND hwnd)
2604 BOOL bBrowseSelFolder = FALSE;
2605 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2609 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2611 LPITEMIDLIST pidlSelection;
2613 /* get the file selected */
2614 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2615 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2617 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2618 pidlSelection, SBSP_RELATIVE ) ) )
2620 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2621 MB_OK | MB_ICONEXCLAMATION );
2624 bBrowseSelFolder = TRUE;
2626 COMDLG32_SHFree( pidlSelection );
2629 return bBrowseSelFolder;
2633 * Memory allocation methods */
2634 static void *MemAlloc(UINT size)
2636 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2639 static void MemFree(void *mem)
2643 HeapFree(GetProcessHeap(),0,mem);