2 * COMMDLG - File Open Dialogs Win95 look and feel
15 #include "debugtools.h"
21 #include "filedlgbrowser.h"
22 #include "wine/obj_contextmenu.h"
24 DEFAULT_DEBUG_CHANNEL(commdlg);
26 /***********************************************************************
27 * Data structure and global variables
29 typedef struct SFolder
31 int m_iImageIndex; /* Index of picture in image list */
33 int m_iIndent; /* Indentation index */
34 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
38 typedef struct tagLookInInfo
45 /***********************************************************************
46 * Defines and global variables
49 /* Draw item constant */
57 /* SearchItem methods */
60 #define ITEM_NOTFOUND -1
62 /* Undefined windows message sent by CreateViewObject*/
63 #define WM_GETISHELLBROWSER WM_USER+7
66 * Those macros exist in windowsx.h. However, you can't really use them since
67 * they rely on the UNICODE defines and can't be use inside Wine itself.
70 /* Combo box macros */
71 #define CBAddString(hwnd,str) \
72 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
74 #define CBInsertString(hwnd,str,pos) \
75 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
77 #define CBDeleteString(hwnd,pos) \
78 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
80 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
81 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
83 #define CBGetItemDataPtr(hwnd,iItemId) \
84 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
86 #define CBGetLBText(hwnd,iItemId,str) \
87 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
89 #define CBGetCurSel(hwnd) \
90 SendMessageA(hwnd,CB_GETCURSEL,0,0);
92 #define CBSetCurSel(hwnd,pos) \
93 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
95 #define CBGetCount(hwnd) \
96 SendMessageA(hwnd,CB_GETCOUNT,0,0);
97 #define CBShowDropDown(hwnd,show) \
98 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
99 #define CBSetItemHeight(hwnd,index,height) \
100 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
103 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
104 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
106 static const char defaultFilter[] = "*.*";
108 /***********************************************************************
112 /* Internal functions used by the dialog */
113 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam);
114 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
115 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
116 BOOL FILEDLG95_OnOpen(HWND hwnd);
117 static LRESULT FILEDLG95_InitUI(HWND hwnd);
118 static void FILEDLG95_Clean(HWND hwnd);
120 /* Functions used by the shell object */
121 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
122 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
123 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
124 static void FILEDLG95_SHELL_Clean(HWND hwnd);
126 /* Functions used by the filetype combo box */
127 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
128 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
129 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt);
130 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
132 /* Functions used by the Look In combo box */
133 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
134 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
135 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
136 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
137 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
138 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
139 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
140 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
141 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
143 /* Miscellaneous tool functions */
144 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
145 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
146 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
147 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
148 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
150 /* Shell memory allocation */
151 void *MemAlloc(UINT size);
152 void MemFree(void *mem);
154 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
155 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
156 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
157 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
158 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
160 /***********************************************************************
163 * Creates an Open common dialog box that lets the user select
164 * the drive, directory, and the name of a file or set of files to open.
166 * IN : The FileOpenDlgInfos structure associated with the dialog
167 * OUT : TRUE on success
168 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
170 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
178 /* Create the dialog from a template */
180 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
182 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
185 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
186 !(template = LockResource( hDlgTmpl )))
188 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
191 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
192 (LPDLGTEMPLATEA) template,
193 fodInfos->ofnInfos->hwndOwner,
194 (DLGPROC) FileOpenDlgProc95,
197 /* Unable to create the dialog*/
204 /***********************************************************************
207 * Copy the OPENFILENAMEA structure in a FileOpenDlgInfos structure.
208 * Call GetFileName95 with this structure and clean the memory.
210 * IN : The OPENFILENAMEA initialisation structure passed to
211 * GetOpenFileNameA win api function (see filedlg.c)
213 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
217 FileOpenDlgInfos *fodInfos;
219 LPCSTR lpstrFilter = NULL;
220 LPSTR lpstrCustomFilter = NULL;
221 LPCSTR lpstrInitialDir = NULL;
224 /* Initialise FileOpenDlgInfos structure*/
225 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
227 /* Pass in the original ofn */
228 fodInfos->ofnInfos = ofn;
230 /* Save original hInstance value */
231 hInstance = ofn->hInstance;
232 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
234 if (ofn->lpstrFilter)
237 lpstrFilter = ofn->lpstrFilter;
239 /* filter is a list... title\0ext\0......\0\0 */
240 s = (LPSTR)ofn->lpstrFilter;
244 x = (LPSTR)MemAlloc(s-ofn->lpstrFilter);
245 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
246 fodInfos->ofnInfos->lpstrFilter = (LPSTR)x;
248 if (ofn->lpstrCustomFilter)
251 lpstrCustomFilter = ofn->lpstrCustomFilter;
253 /* filter is a list... title\0ext\0......\0\0 */
254 s = (LPSTR)ofn->lpstrCustomFilter;
258 x = MemAlloc(s-ofn->lpstrCustomFilter);
259 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
260 fodInfos->ofnInfos->lpstrCustomFilter = (LPSTR)x;
263 dwFlags = ofn->Flags;
264 fodInfos->ofnInfos->Flags = ofn->Flags|OFN_WINE;
266 /* Replace the NULL lpstrInitialDir by the current folder */
267 lpstrInitialDir = ofn->lpstrInitialDir;
270 fodInfos->ofnInfos->lpstrInitialDir = MemAlloc(MAX_PATH);
271 GetCurrentDirectoryA(MAX_PATH,(LPSTR)fodInfos->ofnInfos->lpstrInitialDir);
274 /* Initialise the dialog property */
275 fodInfos->DlgInfos.dwDlgProp = 0;
276 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
281 ret = GetFileName95(fodInfos);
284 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
285 ret = GetFileName95(fodInfos);
293 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrInitialDir));
294 fodInfos->ofnInfos->lpstrInitialDir = lpstrInitialDir;
298 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrFilter));
299 fodInfos->ofnInfos->lpstrFilter = lpstrFilter;
301 if (lpstrCustomFilter)
303 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrCustomFilter));
304 fodInfos->ofnInfos->lpstrCustomFilter = lpstrCustomFilter;
307 ofn->Flags = dwFlags;
308 ofn->hInstance = hInstance;
309 MemFree((LPVOID)(fodInfos));
313 /***********************************************************************
316 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
317 * Call GetFileName95 with this structure and clean the memory.
319 * IN : The OPENFILENAMEW initialisation structure passed to
320 * GetOpenFileNameW win api function (see filedlg.c)
323 * some more strings are needing to be convertet AtoW
325 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
328 FileOpenDlgInfos *fodInfos;
330 LPCSTR lpstrFilter = NULL;
331 LPSTR lpstrCustomFilter = NULL;
332 LPWSTR lpstrFile = NULL;
335 /* Initialise FileOpenDlgInfos structure*/
336 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
338 /* Pass in the original ofn */
339 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
342 hInstance = fodInfos->ofnInfos->hInstance;
343 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
345 /* Save lpstrFilter */
346 if (ofn->lpstrFilter)
352 lpstrFilter = fodInfos->ofnInfos->lpstrFilter;
354 /* filter is a list... title\0ext\0......\0\0 */
355 s = (LPWSTR)ofn->lpstrFilter;
360 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
361 x = y = (LPSTR)MemAlloc(n);
362 s = (LPWSTR)ofn->lpstrFilter;
369 fodInfos->ofnInfos->lpstrFilter = (LPSTR)y;
371 /* Save lpstrCustomFilter */
372 if (ofn->lpstrCustomFilter)
378 lpstrCustomFilter = fodInfos->ofnInfos->lpstrCustomFilter;
379 /* filter is a list... title\0ext\0......\0\0 */
380 s = (LPWSTR)ofn->lpstrCustomFilter;
384 n = s - ofn->lpstrCustomFilter;
385 x = y = (LPSTR)MemAlloc(n);
386 s = (LPWSTR)ofn->lpstrCustomFilter;
393 fodInfos->ofnInfos->lpstrCustomFilter = (LPSTR)y;
397 dwFlags = fodInfos->ofnInfos->Flags;
398 fodInfos->ofnInfos->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
400 /* Initialise the dialog property */
401 fodInfos->DlgInfos.dwDlgProp = 0;
403 /* allocate ansi filename buffer */
404 lpstrFile = ofn->lpstrFile;
405 ofn->lpstrFile = MemAlloc(ofn->nMaxFile);
410 ret = GetFileName95(fodInfos);
413 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
414 ret = GetFileName95(fodInfos);
422 fodInfos->ofnInfos->Flags = dwFlags;
424 /* Restore lpstrFilter */
425 if (fodInfos->ofnInfos->lpstrFilter)
427 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrFilter));
428 fodInfos->ofnInfos->lpstrFilter = lpstrFilter;
430 if (fodInfos->ofnInfos->lpstrCustomFilter)
432 MemFree((LPVOID)(fodInfos->ofnInfos->lpstrCustomFilter));
433 fodInfos->ofnInfos->lpstrCustomFilter = lpstrCustomFilter;
436 /* Restore hInstance */
437 fodInfos->ofnInfos->hInstance = hInstance;
438 MemFree((LPVOID)(fodInfos));
441 lstrcpynAtoW(lpstrFile, (LPCSTR)ofn->lpstrFile, ofn->nMaxFile);
442 MemFree(ofn->lpstrFile);
443 ofn->lpstrFile = lpstrFile;
448 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
451 HWND hwndChild,hwndStc32;
452 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
454 POINT ptParentClient;
456 ptMoveCtl.x = ptMoveCtl.y = 0;
457 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
458 GetClientRect(hwndParentDlg,&rectParent);
459 GetClientRect(hwndChildDlg,&rectChild);
462 GetWindowRect(hwndStc32,&rectStc32);
463 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
464 CopyRect(&rectTemp,&rectStc32);
466 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
467 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
469 if(rectStc32.right < rectTemp.right)
471 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
476 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
477 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
479 if(rectStc32.bottom < rectTemp.bottom)
481 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
486 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
487 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
492 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL)
494 SetRectEmpty(&rectTemp);
495 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
496 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
497 ptMoveCtl.y = rectParent.bottom-rectParent.top;
500 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
501 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
503 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y,
505 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
506 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
508 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
511 GetWindowRect(hwndStc32,&rectStc32);
512 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
515 SetRect(&rectStc32,0,0,0,0);
521 if(hwndChild != hwndStc32)
523 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
525 GetWindowRect(hwndChild,&rectCtrl);
526 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
529 Check the initial position of the controls relative to the initial
530 position and size of stc32 (before it is expanded).
532 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
534 rectCtrl.left += ptMoveCtl.x;
535 rectCtrl.top += ptMoveCtl.y;
537 else if (rectCtrl.left >= rectTemp.right)
538 rectCtrl.left += ptMoveCtl.x;
539 else if (rectCtrl.top >= rectTemp.bottom)
540 rectCtrl.top += ptMoveCtl.y;
542 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
543 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
544 SWP_NOSIZE | SWP_NOZORDER );
547 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
549 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
553 GetWindowRect(hwndStc32,&rectStc32);
554 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
555 ptMoveCtl.x = rectStc32.left - 0;
556 ptMoveCtl.y = rectStc32.top - 0;
561 if(hwndChild != hwndChildDlg)
564 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
566 GetWindowRect(hwndChild,&rectCtrl);
567 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
569 rectCtrl.left += ptMoveCtl.x;
570 rectCtrl.top += ptMoveCtl.y;
572 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
573 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
574 SWP_NOSIZE |SWP_NOZORDER );
577 while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
584 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
586 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
591 fodInfos = (FileOpenDlgInfos *)lParam;
592 lParam = (LPARAM) fodInfos->ofnInfos;
593 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
594 if(fodInfos && (fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
595 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
599 if(fodInfos && (fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook )
600 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
601 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
604 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos,HWND hwnd)
610 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE || fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
612 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
614 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
616 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
623 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
624 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
626 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
629 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
631 !(template = LockResource( hDlgTmpl )))
633 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
638 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
641 ShowWindow(hChildDlg,SW_SHOW);
645 else if(fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK && fodInfos->ofnInfos->lpfnHook)
649 GetClientRect(hwnd,&rectHwnd);
650 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
651 tmplate.dwExtendedStyle = 0;
655 tmplate.cx = rectHwnd.right-rectHwnd.left;
656 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
658 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
663 /***********************************************************************
664 * SendCustomDlgNotificationMessage
666 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
669 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
671 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
674 if(fodInfos->DlgInfos.hwndCustomDlg)
677 ofnNotify.hdr.hwndFrom=hwndParentDlg;
678 ofnNotify.hdr.idFrom=0;
679 ofnNotify.hdr.code = uCode;
680 ofnNotify.lpOFN = fodInfos->ofnInfos;
681 return SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
686 /***********************************************************************
687 * FILEDLG95_HandleCustomDialogMessages
689 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
691 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
695 char lpstrPath[MAX_PATH];
696 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
697 if(!fodInfos) return -1;
701 case CDM_GETFILEPATH:
702 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
703 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA(lpstrPath);
704 if (lpstrFileSpec==lpstrPath)
706 char lpstrCurrentDir[MAX_PATH];
707 /* Prepend the current path */
708 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
709 if ((LPSTR)lParam!=NULL)
710 wsnprintfA((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
711 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
715 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
716 reqSize=strlen(lpstrPath);
718 /* return the required buffer size */
721 case CDM_GETFOLDERPATH:
722 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
723 if ((LPSTR)lParam!=NULL)
724 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
725 return strlen(lpstrPath);
728 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
729 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA(lpstrPath);
730 if ((LPSTR)lParam!=NULL)
731 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
732 return strlen(lpstrFileSpec);
734 case CDM_SETCONTROLTEXT:
736 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
739 case CDM_HIDECONTROL:
741 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
747 /***********************************************************************
750 * File open dialog procedure
752 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
757 /* Adds the FileOpenDlgInfos in the property list of the dialog
758 so it will be easily accessible through a GetPropA(...) */
759 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) lParam);
761 FILEDLG95_OnWMInitDialog(hwnd, wParam, lParam);
762 ((FileOpenDlgInfos *)lParam)->DlgInfos.hwndCustomDlg =
763 CreateTemplateDialog((FileOpenDlgInfos *)lParam,hwnd);
764 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
767 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
770 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
773 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
779 case WM_GETISHELLBROWSER:
780 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
783 RemovePropA(hwnd, FileOpenDlgInfosStr);
788 LPNMHDR lpnmh = (LPNMHDR)lParam;
791 /* set up the button tooltips strings */
792 if(TTN_GETDISPINFOA == lpnmh->code )
794 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
795 switch(lpnmh->idFrom )
797 /* Up folder button */
798 case FCIDM_TB_UPFOLDER:
799 stringId = IDS_UPFOLDER;
801 /* New folder button */
802 case FCIDM_TB_NEWFOLDER:
803 stringId = IDS_NEWFOLDER;
805 /* List option button */
806 case FCIDM_TB_SMALLICON:
807 stringId = IDS_LISTVIEW;
809 /* Details option button */
810 case FCIDM_TB_REPORTVIEW:
811 stringId = IDS_REPORTVIEW;
814 lpdi->hinst = COMMDLG_hInstance32;
815 lpdi->lpszText = (LPSTR) stringId;
820 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
821 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
826 /***********************************************************************
827 * FILEDLG95_OnWMInitDialog
829 * WM_INITDIALOG message handler
831 static LRESULT FILEDLG95_OnWMInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
833 LPITEMIDLIST pidlItemId;
834 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
838 /* Make sure the common control DLL is loaded */
839 InitCommonControls();
841 /* Initialise shell objects */
842 FILEDLG95_SHELL_Init(hwnd);
844 /* Initialise dialog UI */
845 FILEDLG95_InitUI(hwnd);
847 /* Initialize the Look In combo box*/
848 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
850 /* Initialize the filter combo box */
851 FILEDLG95_FILETYPE_Init(hwnd);
853 /* Get the initial directory pidl */
855 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
859 GetCurrentDirectoryA(MAX_PATH,path);
860 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
865 /* Browse to the initial directory */
866 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId,SBSP_RELATIVE);
868 /* Free pidlItem memory */
869 COMDLG32_SHFree(pidlItemId);
873 /***********************************************************************
876 * Regroups all the cleaning functions of the filedlg
878 void FILEDLG95_Clean(HWND hwnd)
880 FILEDLG95_FILETYPE_Clean(hwnd);
881 FILEDLG95_LOOKIN_Clean(hwnd);
882 FILEDLG95_SHELL_Clean(hwnd);
884 /***********************************************************************
885 * FILEDLG95_OnWMCommand
887 * WM_COMMAND message handler
889 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
891 WORD wNotifyCode = HIWORD(wParam); /* notification code */
892 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
893 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
899 if(FILEDLG95_OnOpen(hwnd))
900 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
904 FILEDLG95_Clean(hwnd);
905 EndDialog(hwnd, FALSE);
907 /* Filetype combo box */
909 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
911 /* LookIn combo box */
913 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
916 /* --- toolbar --- */
917 /* Up folder button */
918 case FCIDM_TB_UPFOLDER:
919 FILEDLG95_SHELL_UpFolder(hwnd);
921 /* New folder button */
922 case FCIDM_TB_NEWFOLDER:
923 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
925 /* List option button */
926 case FCIDM_TB_SMALLICON:
927 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
929 /* Details option button */
930 case FCIDM_TB_REPORTVIEW:
931 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
938 /* Do not use the listview selection anymore */
939 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
943 /***********************************************************************
944 * FILEDLG95_OnWMGetIShellBrowser
946 * WM_GETISHELLBROWSER message handler
948 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
951 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
955 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
961 /***********************************************************************
965 static LRESULT FILEDLG95_InitUI(HWND hwnd)
968 {{VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
969 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
970 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
971 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
972 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
973 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
975 TBADDBITMAP tba = { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR };
978 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
980 TRACE("%p\n", fodInfos);
982 /* Get the hwnd of the controls */
983 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
984 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
985 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
987 /* construct the toolbar */
988 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
989 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
991 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
992 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
994 hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
996 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
997 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
998 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
1000 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
1002 /* fixme: use TB_LOADIMAGES when implemented */
1003 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
1004 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba);
1006 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 6,(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 SetDlgItemTextA(hwnd,IDC_FILENAME,fodInfos->ofnInfos->lpstrFile);
1024 /* Must the open as read only check box be checked ?*/
1025 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
1027 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
1029 /* Must the open as read only check box be hid ?*/
1030 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
1032 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
1034 /* Must the help button be hid ?*/
1035 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
1037 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
1039 /* Resize the height, if open as read only checkbox ad help button
1041 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1042 (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP)) )
1044 RECT rectDlg, rectHelp, rectCancel;
1045 GetWindowRect(hwnd, &rectDlg);
1046 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1047 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1048 /* subtract the height of the help button plus the space between
1049 the help button and the cancel button to the height of the dialog */
1050 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1051 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1052 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1054 /* change Open to Save */
1055 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1057 SetDlgItemTextA(hwnd,IDOK,"Save");
1062 /***********************************************************************
1063 * FILEDLG95_OnOpenMultipleFiles
1065 * Handles the opening of multiple files.
1068 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1070 CHAR lpstrPathSpec[MAX_PATH] = "";
1071 CHAR lpstrTempFileList[MAX_PATH] = "";
1075 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1079 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1081 COMDLG32_SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1082 sizePath = lstrlenA( lpstrPathSpec );
1084 memset( lpstrFile, 0x0, fodInfos->ofnInfos->nMaxFile * sizeof(CHAR) );
1086 if ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST ||
1087 !(fodInfos->ofnInfos->Flags & OFN_EXPLORER ))
1089 LPSTR lpstrTemp = lpstrFileList;
1091 for ( nCount = 0; nCount < nFileCount; nCount++ )
1093 WIN32_FIND_DATAA findData;
1094 CHAR lpstrFindFile[MAX_PATH];
1096 memset( lpstrFindFile, 0x0, MAX_PATH * sizeof(CHAR) );
1098 lstrcpyA( lpstrFindFile, lpstrPathSpec );
1099 lstrcatA( lpstrFindFile, "\\" );
1100 lstrcatA( lpstrFindFile, lpstrTemp );
1102 if ( FindFirstFileA( lpstrFindFile, &findData ) == INVALID_HANDLE_VALUE )
1104 CHAR lpstrNotFound[100];
1108 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1109 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1111 strcpy(tmp, lpstrFindFile);
1113 strcat(tmp, lpstrNotFound);
1115 strcat(tmp, lpstrMsg);
1119 fodInfos->ofnInfos->lpstrTitle,
1120 MB_OK | MB_ICONEXCLAMATION);
1124 if (!(fodInfos->ofnInfos->Flags & OFN_EXPLORER ))
1126 lstrcatA( lpstrTempFileList, findData.cAlternateFileName);
1127 if ( nCount + 1 < nFileCount)
1128 lstrcatA( lpstrTempFileList, " ");
1130 lpstrTemp += strlen(lpstrFileList) + 1;
1134 if ( fodInfos->ofnInfos->Flags & OFN_EXPLORER )
1136 lstrcpyA( lpstrFile, lpstrPathSpec);
1137 memcpy( lpstrFile + sizePath + 1, lpstrFileList, sizeof(CHAR) * sizeUsed );
1141 memcpy( lpstrFile, lpstrTempFileList, sizeof(CHAR) * strlen(lpstrTempFileList));
1144 fodInfos->ofnInfos->nFileOffset = sizePath + 1;
1145 fodInfos->ofnInfos->nFileExtension = 0;
1147 /* clean and exit */
1148 FILEDLG95_Clean(hwnd);
1149 return EndDialog(hwnd,TRUE);
1152 /***********************************************************************
1155 * Ok button WM_COMMAND message handler
1157 * If the function succeeds, the return value is nonzero.
1159 BOOL FILEDLG95_OnOpen(HWND hwnd)
1161 CHAR lpstrSpecifiedByUser[MAX_PATH];
1162 CHAR lpstrFileList[MAX_PATH];
1164 UINT nStrCharCount = 0;
1165 UINT nFileCount = 0;
1166 UINT nFileIndex = 0;
1169 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1171 lpstrSpecifiedByUser[0]=0;
1176 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1178 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrSpecifiedByUser, MAX_PATH);
1179 nStrLen = strlen(lpstrSpecifiedByUser);
1181 while ( nStrCharCount <= nStrLen )
1183 if ( lpstrSpecifiedByUser[nStrCharCount]=='"' )
1186 while ((lpstrSpecifiedByUser[nStrCharCount]!='"') &&
1187 (nStrCharCount <= nStrLen))
1189 lpstrFileList[nFileIndex++] = lpstrSpecifiedByUser[nStrCharCount];
1193 lpstrFileList[nFileIndex++] = '\0';
1201 return FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1205 LPSHELLFOLDER psfDesktop;
1206 LPITEMIDLIST browsePidl;
1207 LPSTR lpstrFileSpec;
1209 char lpstrPathSpec[MAX_PATH];
1210 char lpstrCurrentDir[MAX_PATH];
1211 char lpstrPathAndFile[MAX_PATH];
1213 lpstrPathSpec[0] = '\0';
1214 lpstrCurrentDir[0] = '\0';
1215 lpstrPathAndFile[0] = '\0';
1217 /* Separate the file spec from the path spec
1219 lpstrSpecifiedByUser lpstrPathSpec lpstrFileSpec
1220 C:\TEXT1\TEXT2 C:\TEXT1 TEXT2
1222 if (nFileCount == 0)
1224 lpstrFileSpec = (LPSTR)COMDLG32_PathFindFilenameA(lpstrSpecifiedByUser);
1225 strcpy(lpstrPathSpec,lpstrSpecifiedByUser);
1226 COMDLG32_PathRemoveFileSpecA(lpstrPathSpec);
1229 /* Get the index of the selected item in the filetype combo box */
1230 fodInfos->ofnInfos->nFilterIndex = (DWORD) CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1231 /* nFilterIndex is 1 based while combo GetCurSel return zero based index */
1232 fodInfos->ofnInfos->nFilterIndex++;
1234 /* Get the current directory name */
1235 COMDLG32_SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,
1238 /* Create an absolute path name */
1239 if(lpstrSpecifiedByUser[1] != ':')
1241 switch(lpstrSpecifiedByUser[0])
1243 /* Add drive spec \TEXT => C:\TEXT */
1246 int lenPathSpec=strlen(lpstrPathSpec);
1247 int iCopy = (lenPathSpec!=0?2:3);
1248 memmove(lpstrPathSpec+iCopy,lpstrPathSpec,lenPathSpec);
1249 strncpy(lpstrPathSpec,lpstrCurrentDir,iCopy);
1252 /* Go to parent ..\TEXT */
1256 char lpstrTmp2[MAX_PATH];
1257 LPSTR lpstrTmp = strrchr(lpstrCurrentDir,'\\');
1259 iSize = lpstrTmp - lpstrCurrentDir;
1260 strncpy(lpstrTmp2,lpstrCurrentDir,iSize + 1);
1261 if(strlen(lpstrSpecifiedByUser) <= 3)
1262 *lpstrFileSpec='\0';
1263 if(strcmp(lpstrPathSpec,".."))
1264 strcat(lpstrTmp2,&lpstrPathSpec[3]);
1265 strcpy(lpstrPathSpec,lpstrTmp2);
1270 char lpstrTmp[MAX_PATH];
1272 if(strcmp(&lpstrCurrentDir[strlen(lpstrCurrentDir)-1],"\\"))
1273 strcat(lpstrCurrentDir,"\\");
1274 strcpy(lpstrTmp,lpstrCurrentDir);
1275 strcat(lpstrTmp,lpstrPathSpec);
1276 strcpy(lpstrPathSpec,lpstrTmp);
1281 if(strlen(lpstrPathSpec))
1283 /* Browse to the right directory */
1284 COMDLG32_SHGetDesktopFolder(&psfDesktop);
1285 if((browsePidl = GetPidlFromName(psfDesktop,lpstrPathSpec)))
1287 /* Browse to directory */
1288 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1291 COMDLG32_SHFree(browsePidl);
1295 /* Path does not exist */
1296 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1299 "Path does not exist",
1300 fodInfos->ofnInfos->lpstrTitle,
1301 MB_OK | MB_ICONEXCLAMATION);
1306 strcat(lpstrPathAndFile,lpstrPathSpec);
1307 IShellFolder_Release(psfDesktop);
1311 strcat(lpstrPathAndFile,lpstrCurrentDir);
1314 /* Create the path and file string */
1315 COMDLG32_PathAddBackslashA(lpstrPathAndFile);
1316 strcat(lpstrPathAndFile,lpstrFileSpec);
1318 /* Update the edit field */
1319 SetDlgItemTextA(hwnd,IDC_FILENAME,lpstrFileSpec);
1320 SendDlgItemMessageA(hwnd,IDC_FILENAME,EM_SETSEL,0,-1);
1322 /* Don't go further if we dont have a file spec */
1323 if(!strlen(lpstrFileSpec) || !strcmp(lpstrFileSpec,lpstrPathSpec))
1326 /* Time to check lpstrFileSpec */
1327 /* search => contains * or ? */
1328 /* browse => contains a directory name */
1329 /* file => contains a file name */
1331 /* Check if this is a search */
1332 if(strchr(lpstrFileSpec,'*') || strchr(lpstrFileSpec,'?'))
1336 /* Set the current filter with the current selection */
1337 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1338 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1340 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFileSpec)+1)*2);
1341 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,
1342 (LPSTR)strlwr((LPSTR)lpstrFileSpec));
1344 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1346 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB,
1348 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1353 /* browse if the user specified a directory */
1354 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1356 if (!browsePidl) /* not a directory check the specified file exists */
1359 char lpstrFileSpecTemp[MAX_PATH];
1363 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1364 lpOrg = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, iExt);
1365 if ((int)lpOrg == -1)
1366 lpOrg = NULL; /* we get -1 if the filetype LB is empty */
1371 add user specified extentions to the file one by one and
1372 check if the file exists
1377 if ((lpstrExt = strchr(lpOrg, ';')))
1379 i = lpstrExt - lpOrg;
1383 lpBuf = MemAlloc(i+1);
1384 strncpy(lpBuf, lpOrg, i);
1386 strcpy(lpstrFileSpecTemp, lpstrFileSpec);
1387 if (lpstrFileSpecTemp[strlen(lpstrFileSpecTemp)-1] == '.')
1389 if (strchr(lpBuf, '.'))
1390 strcat(lpstrFileSpecTemp, (strchr(lpBuf, '.')) + 1);
1393 strcat(lpstrFileSpecTemp, strchr(lpBuf, '.'));
1394 browsePidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder,
1396 MemFree((void *)lpBuf);
1399 strcpy(lpstrFileSpec,lpstrFileSpecTemp);
1411 ULONG ulAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
1413 char lpstrFileExist[MAX_PATH + 50];
1415 IShellFolder_GetAttributesOf(fodInfos->Shell.FOIShellFolder,
1420 /* Browse to directory if it is a folder */
1421 if (ulAttr & SFGAO_FOLDER)
1423 if(FAILED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1427 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1430 "Path does not exist",
1431 fodInfos->ofnInfos->lpstrTitle,
1432 MB_OK | MB_ICONEXCLAMATION);
1433 COMDLG32_SHFree(browsePidl);
1437 COMDLG32_SHFree(browsePidl);
1441 /* The file does exist, so ask the user if we should overwrite it */
1442 if((fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) &&
1443 (fodInfos->ofnInfos->Flags & OFN_OVERWRITEPROMPT))
1445 strcpy(lpstrFileExist, lpstrFileSpec);
1446 strcat(lpstrFileExist, " already exists.\nDo you want to replace it?");
1448 nMsgBoxRet = MessageBoxA(hwnd,
1450 fodInfos->ofnInfos->lpstrTitle,
1451 MB_YESNO | MB_ICONEXCLAMATION);
1452 if (nMsgBoxRet == IDNO)
1454 COMDLG32_SHFree(browsePidl);
1458 COMDLG32_SHFree(browsePidl);
1462 /* File does not exist in current directory */
1464 /* The selected file does not exist */
1465 /* Tell the user the selected does not exist */
1466 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1468 char lpstrNotFound[100];
1472 LoadStringA(COMMDLG_hInstance32,
1476 LoadStringA(COMMDLG_hInstance32,
1481 strcpy(tmp,fodInfos->ofnInfos->lpstrFile);
1483 strcat(tmp,lpstrNotFound);
1485 strcat(tmp,lpstrMsg);
1489 fodInfos->ofnInfos->lpstrTitle,
1490 MB_OK | MB_ICONEXCLAMATION);
1493 /* Ask the user if he wants to create the file*/
1494 if(fodInfos->ofnInfos->Flags & OFN_CREATEPROMPT)
1498 LoadStringA(COMMDLG_hInstance32,IDS_CREATEFILE,tmp,100);
1500 if(IDYES == MessageBoxA(hwnd,tmp,fodInfos->ofnInfos->lpstrTitle,
1501 MB_YESNO | MB_ICONQUESTION))
1503 /* Create the file, clean and exit */
1504 FILEDLG95_Clean(hwnd);
1505 return EndDialog(hwnd,TRUE);
1511 /* Open the selected file */
1513 /* Check file extension */
1514 if(!strrchr(lpstrPathAndFile,'.'))
1516 /* if the file has no extension, append the selected
1517 extension of the filetype combo box */
1520 iExt = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1521 lpstrTemp = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iExt);
1523 if((LPSTR)-1 != lpstrTemp)
1525 if((lpstrExt = strchr(lpstrTemp,';')))
1527 int i = lpstrExt - lpstrTemp;
1528 lpstrExt = MemAlloc(i);
1529 strncpy(lpstrExt,&lpstrTemp[1],i-1);
1533 lpstrExt = MemAlloc(strlen(lpstrTemp));
1534 strcpy(lpstrExt,&lpstrTemp[1]);
1537 if(!strcmp(&lpstrExt[1],"*") && fodInfos->ofnInfos->lpstrDefExt)
1540 lpstrExt = MemAlloc(strlen(fodInfos->ofnInfos->lpstrDefExt)+2);
1541 strcat(lpstrExt,".");
1542 strcat(lpstrExt,(LPSTR) fodInfos->ofnInfos->lpstrDefExt);
1544 strcat(lpstrPathAndFile,lpstrExt);
1545 MemFree( lpstrExt );
1548 /* Check that size size of the file does not exceed buffer size */
1549 if(strlen(lpstrPathAndFile) > fodInfos->ofnInfos->nMaxFile)
1551 /* set error FNERR_BUFFERTOSMALL */
1552 FILEDLG95_Clean(hwnd);
1553 return EndDialog(hwnd,FALSE);
1555 strcpy(fodInfos->ofnInfos->lpstrFile,lpstrPathAndFile);
1557 /* Set the lpstrFileTitle of the OPENFILENAME structure */
1558 if(fodInfos->ofnInfos->lpstrFileTitle)
1559 strncpy(fodInfos->ofnInfos->lpstrFileTitle,
1561 fodInfos->ofnInfos->nMaxFileTitle);
1563 /* Check if the file is to be opened as read only */
1564 if(BST_CHECKED == SendDlgItemMessageA(hwnd,
1567 SetFileAttributesA(fodInfos->ofnInfos->lpstrFile,
1568 FILE_ATTRIBUTE_READONLY);
1570 /* nFileExtension and nFileOffset of OPENFILENAME structure */
1571 lpstrTemp = strrchr(fodInfos->ofnInfos->lpstrFile,'\\');
1572 fodInfos->ofnInfos->nFileOffset = lpstrTemp - fodInfos->ofnInfos->lpstrFile + 1;
1573 lpstrTemp = strrchr(fodInfos->ofnInfos->lpstrFile,'.');
1574 fodInfos->ofnInfos->nFileExtension = lpstrTemp - fodInfos->ofnInfos->lpstrFile + 1;
1577 /* clean and exit */
1578 FILEDLG95_Clean(hwnd);
1579 return EndDialog(hwnd,TRUE);
1585 /***********************************************************************
1586 * FILEDLG95_SHELL_Init
1588 * Initialisation of the shell objects
1590 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1592 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1597 * Initialisation of the FileOpenDialogInfos structure
1602 fodInfos->Shell.FOIShellView = NULL;
1603 if(FAILED(COMDLG32_SHGetDesktopFolder(&fodInfos->Shell.FOIShellFolder)))
1607 fodInfos->ShellInfos.hwndOwner = hwnd;
1609 fodInfos->ShellInfos.folderSettings.fFlags = 0;
1610 /* Disable multi-select if flag not set */
1611 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1613 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1615 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1616 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1618 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1619 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1620 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1622 /* Construct the IShellBrowser interface */
1623 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1628 /***********************************************************************
1629 * FILEDLG95_SHELL_ExecuteCommand
1631 * Change the folder option and refresh the view
1632 * If the function succeeds, the return value is nonzero.
1634 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1636 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1639 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1641 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1646 CMINVOKECOMMANDINFO ci;
1647 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1648 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1652 IContextMenu_InvokeCommand(pcm, &ci);
1653 IContextMenu_Release(pcm);
1659 /***********************************************************************
1660 * FILEDLG95_SHELL_UpFolder
1662 * Browse to the specified object
1663 * If the function succeeds, the return value is nonzero.
1665 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1667 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1671 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1680 /***********************************************************************
1681 * FILEDLG95_SHELL_Clean
1683 * Cleans the memory used by shell objects
1685 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1687 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1691 /* clean Shell interfaces */
1692 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1693 IShellView_Release(fodInfos->Shell.FOIShellView);
1694 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1695 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1698 /***********************************************************************
1699 * FILEDLG95_FILETYPE_Init
1701 * Initialisation of the file type combo box
1703 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1705 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1709 if(fodInfos->ofnInfos->lpstrFilter)
1718 /* filter is a list... title\0ext\0......\0\0
1719 * Set the combo item text to the title and the item data
1722 char *lpstrExt = NULL;
1723 LPSTR lpstrExtTmp = NULL;
1726 lpstrTmp = (&((LPBYTE)fodInfos->ofnInfos->lpstrFilter)[iStrIndex]);
1727 if(!strlen(lpstrTmp))
1729 iStrIndex += strlen(lpstrTmp) +1;
1730 /* Get the extension */
1731 lpstrExtTmp = (&((LPBYTE)fodInfos->ofnInfos->lpstrFilter)[iStrIndex]);
1735 lpstrExt = (LPSTR) MemAlloc(strlen(lpstrExtTmp)+1);
1739 strcpy(lpstrExt,lpstrExtTmp);
1741 iStrIndex += strlen(lpstrExt) +1;
1743 /* Add the item at the end of the combo */
1744 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB,lpstrTmp);
1745 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos++,lpstrExt);
1747 /* Set the current filter to the one specified
1748 * in the initialisation structure
1751 /* set default filter index */
1752 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1753 fodInfos->ofnInfos->nFilterIndex = 1;
1754 /* First, check to make sure our index isn't out of bounds. */
1755 if ( fodInfos->ofnInfos->nFilterIndex > iPos )
1756 fodInfos->ofnInfos->nFilterIndex = iPos;
1759 /* Get the current index selection. */
1760 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB,
1761 fodInfos->ofnInfos->nFilterIndex-1);
1763 /* Get the corresponding text string from the combo box. */
1764 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1765 fodInfos->ofnInfos->nFilterIndex-1);
1769 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1770 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,strlwr(lpstrFilter));
1776 /***********************************************************************
1777 * FILEDLG95_FILETYPE_OnCommand
1779 * WM_COMMAND of the file type combo box
1780 * If the function succeeds, the return value is nonzero.
1782 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1784 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1792 /* Get the current item of the filetype combo box */
1793 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1795 /* set the current filter index - indexed from 1 */
1796 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1798 /* Set the current filter with the current selection */
1799 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1800 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1802 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1804 if((int)lpstrFilter != CB_ERR)
1806 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc((strlen(lpstrFilter)+1)*2);
1807 lstrcpyAtoW(fodInfos->ShellInfos.lpstrCurrentFilter,(LPSTR)strlwr((LPSTR)lpstrFilter));
1808 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1811 /* Refresh the actual view to display the included items*/
1812 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1818 /***********************************************************************
1819 * FILEDLG95_FILETYPE_SearchExt
1821 * Search for pidl in the lookin combo box
1822 * returns the index of the found item
1824 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPSTR lpstrExt)
1827 int iCount = CBGetCount(hwnd);
1833 LPSTR ext = (LPSTR) CBGetItemDataPtr(hwnd,i);
1834 if(!strcasecmp(lpstrExt,ext))
1841 /***********************************************************************
1842 * FILEDLG95_FILETYPE_Clean
1844 * Clean the memory used by the filetype combo box
1846 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1848 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1850 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1854 /* Delete each string of the combo and their associated data */
1855 for(iPos = iCount-1;iPos>=0;iPos--)
1857 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos)));
1858 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1860 /* Current filter */
1861 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1862 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1866 /***********************************************************************
1867 * FILEDLG95_LOOKIN_Init
1869 * Initialisation of the look in combo box
1871 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1873 IShellFolder *psfRoot, *psfDrives;
1874 IEnumIDList *lpeRoot, *lpeDrives;
1875 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1877 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1881 liInfos->iMaxIndentation = 0;
1883 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1884 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1886 /* Initialise data of Desktop folder */
1887 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1888 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1889 COMDLG32_SHFree(pidlTmp);
1891 COMDLG32_SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1893 COMDLG32_SHGetDesktopFolder(&psfRoot);
1897 /* enumerate the contents of the desktop */
1898 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1900 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1902 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1904 /* special handling for CSIDL_DRIVES */
1905 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1907 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1909 /* enumerate the drives */
1910 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1912 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1914 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1915 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1916 COMDLG32_SHFree(pidlAbsTmp);
1917 COMDLG32_SHFree(pidlTmp1);
1919 IEnumIDList_Release(lpeDrives);
1921 IShellFolder_Release(psfDrives);
1924 COMDLG32_SHFree(pidlTmp);
1926 IEnumIDList_Release(lpeRoot);
1930 IShellFolder_Release(psfRoot);
1931 COMDLG32_SHFree(pidlDrives);
1935 /***********************************************************************
1936 * FILEDLG95_LOOKIN_DrawItem
1938 * WM_DRAWITEM message handler
1940 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1942 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1943 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1944 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1948 HIMAGELIST ilItemImage;
1950 LPSFOLDER tmpFolder;
1953 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1957 if(pDIStruct->itemID == -1)
1960 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1961 pDIStruct->itemID)))
1965 if(pDIStruct->itemID == liInfos->uSelectedItem)
1967 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1970 sizeof (SHFILEINFOA),
1971 SHGFI_PIDL | SHGFI_SMALLICON |
1972 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1973 SHGFI_DISPLAYNAME );
1977 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1980 sizeof (SHFILEINFOA),
1981 SHGFI_PIDL | SHGFI_SMALLICON |
1982 SHGFI_SYSICONINDEX |
1986 /* Is this item selected ?*/
1987 if(pDIStruct->itemState & ODS_SELECTED)
1989 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
1990 SetBkColor(pDIStruct->hDC,crHighLight);
1991 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
1995 SetTextColor(pDIStruct->hDC,crText);
1996 SetBkColor(pDIStruct->hDC,crWin);
1997 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2000 /* Do not indent item if drawing in the edit of the combo*/
2001 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2004 ilItemImage = (HIMAGELIST) COMDLG32_SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2007 sizeof (SHFILEINFOA),
2008 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2009 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2014 iIndentation = tmpFolder->m_iIndent;
2016 /* Draw text and icon */
2018 /* Initialise the icon display area */
2019 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2020 rectIcon.top = pDIStruct->rcItem.top;
2021 rectIcon.right = rectIcon.left + ICONWIDTH;
2022 rectIcon.bottom = pDIStruct->rcItem.bottom;
2024 /* Initialise the text display area */
2025 rectText.left = rectIcon.right;
2026 rectText.top = pDIStruct->rcItem.top + YTEXTOFFSET;
2027 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2028 rectText.bottom = pDIStruct->rcItem.bottom;
2031 /* Draw the icon from the image list */
2032 COMDLG32_ImageList_Draw(ilItemImage,
2039 /* Draw the associated text */
2040 if(sfi.szDisplayName)
2041 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2047 /***********************************************************************
2048 * FILEDLG95_LOOKIN_OnCommand
2050 * LookIn combo box WM_COMMAND message handler
2051 * If the function succeeds, the return value is nonzero.
2053 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2055 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2057 TRACE("%p\n", fodInfos);
2063 LPSFOLDER tmpFolder;
2066 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2068 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2073 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2074 tmpFolder->pidlItem,
2086 /***********************************************************************
2087 * FILEDLG95_LOOKIN_AddItem
2089 * Adds an absolute pidl item to the lookin combo box
2090 * returns the index of the inserted item
2092 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2094 LPITEMIDLIST pidlNext;
2097 LookInInfos *liInfos;
2104 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2107 tmpFolder = MemAlloc(sizeof(SFOLDER));
2108 tmpFolder->m_iIndent = 0;
2110 /* Calculate the indentation of the item in the lookin*/
2112 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2114 tmpFolder->m_iIndent++;
2117 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl);
2119 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2120 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2122 COMDLG32_SHGetFileInfoA((LPSTR)pidl,
2126 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2127 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES);
2130 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2133 /* Add the item at the end of the list */
2136 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2138 /* Insert the item at the iInsertId position*/
2141 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2144 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2148 MemFree( tmpFolder );
2153 /***********************************************************************
2154 * FILEDLG95_LOOKIN_InsertItemAfterParent
2156 * Insert an item below its parent
2158 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2161 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2166 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2170 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2173 /* Free pidlParent memory */
2174 COMDLG32_SHFree((LPVOID)pidlParent);
2176 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2179 /***********************************************************************
2180 * FILEDLG95_LOOKIN_SelectItem
2182 * Adds an absolute pidl item to the lookin combo box
2183 * returns the index of the inserted item
2185 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2188 LookInInfos *liInfos;
2192 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2194 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2198 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2199 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2204 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2205 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2209 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2211 if(iRemovedItem < iItemPos)
2216 CBSetCurSel(hwnd,iItemPos);
2217 liInfos->uSelectedItem = iItemPos;
2223 /***********************************************************************
2224 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2226 * Remove the item with an expansion level over iExpansionLevel
2228 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2232 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2236 if(liInfos->iMaxIndentation <= 2)
2239 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2242 tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2243 CBDeleteString(hwnd,iItemPos);
2244 liInfos->iMaxIndentation--;
2252 /***********************************************************************
2253 * FILEDLG95_LOOKIN_SearchItem
2255 * Search for pidl in the lookin combo box
2256 * returns the index of the found item
2258 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2261 int iCount = CBGetCount(hwnd);
2267 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2269 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2271 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2279 /***********************************************************************
2280 * FILEDLG95_LOOKIN_Clean
2282 * Clean the memory used by the lookin combo box
2284 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2286 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2288 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2292 /* Delete each string of the combo and their associated data */
2293 for(iPos = iCount-1;iPos>=0;iPos--)
2295 MemFree((LPVOID)(CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos)));
2296 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2298 /* LookInInfos structure */
2299 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2306 /***********************************************************************
2309 * Get the pidl's display name (relative to folder) and
2310 * put it in lpstrFileName.
2312 * Return NOERROR on success,
2316 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2321 TRACE("%p %p\n", lpsf, pidl);
2326 COMDLG32_SHGetDesktopFolder(&lpsf);
2327 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2328 IShellFolder_Release(lpsf);
2332 /* Get the display name of the pidl relative to the folder */
2333 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf,
2338 return StrRetToBufA(&str, pidl,lpstrFileName, MAX_PATH);
2343 /***********************************************************************
2344 * GetShellFolderFromPidl
2346 * pidlRel is the item pidl relative
2347 * Return the IShellFolder of the absolute pidl
2349 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2351 IShellFolder *psf = NULL,*psfParent;
2353 TRACE("%p\n", pidlAbs);
2355 if(SUCCEEDED(COMDLG32_SHGetDesktopFolder(&psfParent)))
2358 if(pidlAbs && pidlAbs->mkid.cb)
2360 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2362 IShellFolder_Release(psfParent);
2366 /* return the desktop */
2372 /***********************************************************************
2375 * Return the LPITEMIDLIST to the parent of the pidl in the list
2377 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2379 LPITEMIDLIST pidlParent;
2381 TRACE("%p\n", pidl);
2383 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2384 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2389 /***********************************************************************
2392 * returns the pidl of the file name relative to folder
2393 * NULL if an error occured
2395 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName)
2399 wchar_t lpwstrDirName[MAX_PATH];
2402 TRACE("sf=%p file=%s\n", psf, lpcstrFileName);
2407 MultiByteToWideChar(CP_ACP,
2411 (LPWSTR)lpwstrDirName,
2414 IShellFolder_ParseDisplayName(psf, 0,
2416 (LPWSTR)lpwstrDirName,
2424 /***********************************************************************
2428 BOOL GetFileExtension(IShellFolder *psf,LPITEMIDLIST pidl,LPSTR lpstrFileExtension)
2430 char FileName[MAX_PATH];
2435 if(SUCCEEDED(GetName(psf,pidl,SHGDN_NORMAL,FileName)))
2437 if(!(pdest = strrchr( FileName, ch )))
2440 result = pdest - FileName + 1;
2441 strcpy(lpstrFileExtension,&FileName[result]);
2448 * Memory allocation methods */
2449 void *MemAlloc(UINT size)
2451 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2454 void MemFree(void *mem)
2458 HeapFree(GetProcessHeap(),0,mem);