Fixed callback parameters (bogus hWave); added acm conversion for
[wine.git] / dlls / commdlg / filedlg95.c
blob15c7afe918c4a9223b37d46dd6d69c338b23c32e
1 /*
2 * COMMDLG - File Open Dialogs Win95 look and feel
4 * FIXME: The whole concept of handling unicode is badly broken.
5 * many hook-messages expecting a pointer to a
6 * OPENFILENAMEA or W structure. With the current architecture
7 * we would have to convert the beast at every call to a hook.
8 * we have to find a better solution but if would likely cause
9 * a complete rewrite with after we shouldhandle the
10 * OPENFILENAME structure without any converting (jsch).
12 * FIXME: any hook gets a OPENFILENAMEA structure
14 * FIXME: CDN_FILEOK is wrong implemented, other CDN_ messages likely too
16 * FIXME: old style hook messages are not implemented (except FILEOKSTRING)
18 * FIXME: lpstrCustomFilter not handled
20 * FIXME: if the size of lpstrFile (nMaxFile) is too small the first
21 * two bytes of lpstrFile should contain the needed size
23 * FIXME: algorithm for selecting the initial directory is too simple
25 * FIXME: add to recent docs
27 * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT,
28 * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_EXTENSIONDIFFERENT,
29 * OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN,
30 * OFN_NOTESTFILECREATE, OFN_OVERWRITEPROMPT, OFN_USEMONIKERS
32 * FIXME: lCustData for lpfnHook (WM_INITDIALOG)
36 #include <ctype.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
41 #include "winbase.h"
42 #include "ntddk.h"
43 #include "winnls.h"
44 #include "heap.h"
45 #include "commdlg.h"
46 #include "dlgs.h"
47 #include "cdlg.h"
48 #include "debugtools.h"
49 #include "cderr.h"
50 #include "shellapi.h"
51 #include "shlguid.h"
52 #include "filedlgbrowser.h"
53 #include "shlwapi.h"
54 #include "wine/obj_contextmenu.h"
56 DEFAULT_DEBUG_CHANNEL(commdlg);
58 #define UNIMPLEMENTED_FLAGS \
59 (OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\
60 OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING | OFN_EXTENSIONDIFFERENT |\
61 OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\
62 OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT /*| OFN_USEMONIKERS*/)
64 #define IsHooked(fodInfos) \
65 ((fodInfos->ofnInfos->Flags & OFN_ENABLEHOOK) && fodInfos->ofnInfos->lpfnHook)
66 /***********************************************************************
67 * Data structure and global variables
69 typedef struct SFolder
71 int m_iImageIndex; /* Index of picture in image list */
72 HIMAGELIST hImgList;
73 int m_iIndent; /* Indentation index */
74 LPITEMIDLIST pidlItem; /* absolute pidl of the item */
76 } SFOLDER,*LPSFOLDER;
78 typedef struct tagLookInInfo
80 int iMaxIndentation;
81 UINT uSelectedItem;
82 } LookInInfos;
85 /***********************************************************************
86 * Defines and global variables
89 /* Draw item constant */
90 #define ICONWIDTH 18
91 #define XTEXTOFFSET 3
93 /* AddItem flags*/
94 #define LISTEND -1
96 /* SearchItem methods */
97 #define SEARCH_PIDL 1
98 #define SEARCH_EXP 2
99 #define ITEM_NOTFOUND -1
101 /* Undefined windows message sent by CreateViewObject*/
102 #define WM_GETISHELLBROWSER WM_USER+7
104 /* NOTE
105 * Those macros exist in windowsx.h. However, you can't really use them since
106 * they rely on the UNICODE defines and can't be used inside Wine itself.
109 /* Combo box macros */
110 #define CBAddString(hwnd,str) \
111 SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str);
113 #define CBInsertString(hwnd,str,pos) \
114 SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str);
116 #define CBDeleteString(hwnd,pos) \
117 SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0);
119 #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \
120 SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr);
122 #define CBGetItemDataPtr(hwnd,iItemId) \
123 SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0)
125 #define CBGetLBText(hwnd,iItemId,str) \
126 SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str);
128 #define CBGetCurSel(hwnd) \
129 SendMessageA(hwnd,CB_GETCURSEL,0,0);
131 #define CBSetCurSel(hwnd,pos) \
132 SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0);
134 #define CBGetCount(hwnd) \
135 SendMessageA(hwnd,CB_GETCOUNT,0,0);
136 #define CBShowDropDown(hwnd,show) \
137 SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0);
138 #define CBSetItemHeight(hwnd,index,height) \
139 SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height);
142 const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */
143 const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */
145 static const char defaultFilter[] = "*.*";
147 /***********************************************************************
148 * Prototypes
151 /* Internal functions used by the dialog */
152 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam);
153 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
154 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd);
155 BOOL FILEDLG95_OnOpen(HWND hwnd);
156 static LRESULT FILEDLG95_InitControls(HWND hwnd);
157 static void FILEDLG95_Clean(HWND hwnd);
159 /* Functions used by the shell navigation */
160 static LRESULT FILEDLG95_SHELL_Init(HWND hwnd);
161 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd);
162 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
163 static void FILEDLG95_SHELL_Clean(HWND hwnd);
164 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);
166 /* Functions used by the filetype combo box */
167 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);
168 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);
169 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt);
170 static void FILEDLG95_FILETYPE_Clean(HWND hwnd);
172 /* Functions used by the Look In combo box */
173 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);
174 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);
175 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);
176 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);
177 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod);
178 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl);
179 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
180 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);
181 static void FILEDLG95_LOOKIN_Clean(HWND hwnd);
183 /* Miscellaneous tool functions */
184 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);
185 HRESULT GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);
186 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);
187 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl);
188 LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);
190 /* Shell memory allocation */
191 static void *MemAlloc(UINT size);
192 static void MemFree(void *mem);
194 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);
195 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
196 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);
197 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
198 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);
199 static BOOL BrowseSelectedFolder(HWND hwnd);
201 /***********************************************************************
202 * GetFileName95
204 * Creates an Open common dialog box that lets the user select
205 * the drive, directory, and the name of a file or set of files to open.
207 * IN : The FileOpenDlgInfos structure associated with the dialog
208 * OUT : TRUE on success
209 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
211 BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)
214 LRESULT lRes;
215 LPCVOID template;
216 HRSRC hRes;
217 HANDLE hDlgTmpl = 0;
219 /* test for missing functionality */
220 if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS)
222 FIXME("Flags 0x%08lx not yet implemented\n",
223 fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS);
226 /* Create the dialog from a template */
228 if(!(hRes = FindResourceA(COMMDLG_hInstance32,MAKEINTRESOURCEA(NEWFILEOPENORD),RT_DIALOGA)))
230 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
231 return FALSE;
233 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hRes )) ||
234 !(template = LockResource( hDlgTmpl )))
236 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
237 return FALSE;
240 /* old style hook messages */
241 if (IsHooked(fodInfos))
243 fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
244 fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
245 fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRINGA);
246 fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA);
249 lRes = DialogBoxIndirectParamA(COMMDLG_hInstance32,
250 (LPDLGTEMPLATEA) template,
251 fodInfos->ofnInfos->hwndOwner,
252 (DLGPROC) FileOpenDlgProc95,
253 (LPARAM) fodInfos);
255 /* Unable to create the dialog */
256 if( lRes == -1)
257 return FALSE;
259 return lRes;
262 /***********************************************************************
263 * GetFileDialog95A
265 * Call GetFileName95 with this structure and clean the memory.
267 * IN : The OPENFILENAMEA initialisation structure passed to
268 * GetOpenFileNameA win api function (see filedlg.c)
270 BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
273 BOOL ret;
274 FileOpenDlgInfos *fodInfos;
275 HINSTANCE hInstance;
276 LPCSTR lpstrInitialDir = (LPCSTR)-1;
277 LPSTR lpstrSavDir = NULL;
278 DWORD dwFlags = 0;
280 /* Initialise FileOpenDlgInfos structure*/
281 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
282 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
284 /* Pass in the original ofn */
285 fodInfos->ofnInfos = ofn;
287 /* Save original hInstance value */
288 hInstance = ofn->hInstance;
289 fodInfos->ofnInfos->hInstance = MapHModuleLS(ofn->hInstance);
291 /* save current directory */
292 if (ofn->Flags & OFN_NOCHANGEDIR)
294 lpstrSavDir = MemAlloc(MAX_PATH);
295 GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
298 dwFlags = ofn->Flags;
299 ofn->Flags = ofn->Flags|OFN_WINE;
301 /* Initialise the dialog property */
302 fodInfos->DlgInfos.dwDlgProp = 0;
303 fodInfos->DlgInfos.hwndCustomDlg = (HWND)NULL;
305 switch(iDlgType)
307 case OPEN_DIALOG :
308 ret = GetFileName95(fodInfos);
309 break;
310 case SAVE_DIALOG :
311 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
312 ret = GetFileName95(fodInfos);
313 break;
314 default :
315 ret = 0;
318 if (lpstrSavDir)
320 SetCurrentDirectoryA(lpstrSavDir);
321 MemFree(lpstrSavDir);
324 if (lpstrInitialDir != (LPCSTR)-1)
326 MemFree((LPVOID)(ofn->lpstrInitialDir));
327 ofn->lpstrInitialDir = lpstrInitialDir;
330 ofn->Flags = dwFlags;
331 ofn->hInstance = hInstance;
332 MemFree((LPVOID)(fodInfos));
333 return ret;
336 /***********************************************************************
337 * GetFileDialog95W
339 * Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
340 * Call GetFileName95 with this structure and clean the memory.
342 * FIXME: lpstrCustomFilter has to converted back
346 /* converting IN arguments */
347 #define AllocInArgWtoA(arg, save) \
348 if(arg) \
350 DWORD _len = WideCharToMultiByte( CP_ACP, 0, arg, -1, NULL, 0, NULL, NULL ); \
351 save = arg; \
352 arg = MemAlloc(_len); \
353 WideCharToMultiByte( CP_ACP, 0, save, -1, (LPSTR)arg, _len, NULL, NULL ); \
356 #define FreeInArg(arg, save) \
357 if(arg) \
359 MemFree((LPSTR)arg); \
360 arg = save; \
363 /* converting OUT arguments */
364 #define AllocOutArgWtoA(arg, save, len) \
365 if(arg) \
367 save = arg; \
368 arg = MemAlloc(len); \
371 #define FreeOutArg(arg, save, len) \
372 if(arg) \
374 MultiByteToWideChar( CP_ACP, 0, (LPCSTR)(arg), -1, (save), (len) ); \
375 MemFree(arg); \
376 arg = save; \
379 BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
381 BOOL ret;
382 FileOpenDlgInfos *fodInfos;
383 HINSTANCE hInstance;
385 /* out arguments */
386 LPWSTR lpstrFile = NULL;
387 LPWSTR lpstrFileTitle = NULL;
389 /* in/out arguments */
390 LPWSTR lpstrCustomFilter = NULL;
392 /* input arguments */
393 LPCWSTR lpstrFilter = NULL;
394 LPCWSTR lpstrInitialDir = NULL;
395 LPCWSTR lpstrTitle = NULL;
396 LPCWSTR lpstrDefExt = NULL;
397 LPCWSTR lpTemplateName = NULL;
398 DWORD dwFlags;
400 /* Initialise FileOpenDlgInfos structure*/
401 fodInfos = (FileOpenDlgInfos*)MemAlloc(sizeof(FileOpenDlgInfos));
402 ZeroMemory(fodInfos, sizeof(FileOpenDlgInfos));
404 /* Pass in the original ofn */
405 fodInfos->ofnInfos = (LPOPENFILENAMEA) ofn;
407 /* convert lpstrFilter */
408 if (ofn->lpstrFilter)
410 LPCWSTR s;
411 LPSTR y;
412 int n, len;
414 lpstrFilter = ofn->lpstrFilter;
416 /* filter is a list... title\0ext\0......\0\0 */
417 s = ofn->lpstrFilter;
419 while (*s) s = s+strlenW(s)+1;
420 s++;
421 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
422 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0, NULL, NULL );
423 y = (LPSTR)MemAlloc(len);
424 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrFilter, n, y, len, NULL, NULL );
425 (LPSTR)ofn->lpstrFilter = y;
428 /* convert lpstrCustomFilter */
429 if (ofn->lpstrCustomFilter)
431 LPWSTR s;
432 LPSTR y;
433 int n, len;
435 lpstrCustomFilter = ofn->lpstrCustomFilter;
436 /* filter is a list... title\0ext\0......\0\0 */
437 s = ofn->lpstrCustomFilter;
438 while (*s) s = s+strlenW(s)+1;
439 s++;
440 n = s - ofn->lpstrCustomFilter;
441 len = WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0, NULL, NULL );
442 y = (LPSTR)MemAlloc(len);
443 WideCharToMultiByte( CP_ACP, 0, ofn->lpstrCustomFilter, n, y, len, NULL, NULL );
444 (LPSTR)ofn->lpstrCustomFilter = y;
447 /* convert string arguments, save others */
448 AllocOutArgWtoA(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
449 AllocOutArgWtoA(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
450 AllocInArgWtoA(ofn->lpstrInitialDir, lpstrInitialDir);
451 AllocInArgWtoA(ofn->lpstrTitle, lpstrTitle);
452 AllocInArgWtoA(ofn->lpstrDefExt, lpstrDefExt);
453 AllocInArgWtoA(ofn->lpTemplateName, lpTemplateName);
454 dwFlags = ofn->Flags;
455 hInstance = ofn->hInstance;
457 ofn->Flags = ofn->Flags|OFN_WINE|OFN_UNICODE;
458 ofn->hInstance = MapHModuleLS(ofn->hInstance);
460 switch(iDlgType)
462 case OPEN_DIALOG :
463 ret = GetFileName95(fodInfos);
464 break;
465 case SAVE_DIALOG :
466 fodInfos->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
467 ret = GetFileName95(fodInfos);
468 break;
469 default :
470 ret = 0;
473 /* restore saved IN arguments and convert OUT arguments back */
474 ofn->Flags = dwFlags;
475 ofn->hInstance = hInstance;
476 FreeInArg(ofn->lpstrFilter, lpstrFilter);
477 FreeInArg(ofn->lpstrCustomFilter, lpstrCustomFilter);
478 FreeOutArg(ofn->lpstrFile, lpstrFile, ofn->nMaxFile);
479 FreeOutArg(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle);
480 FreeInArg(ofn->lpstrInitialDir, lpstrInitialDir);
481 FreeInArg(ofn->lpstrTitle, lpstrTitle);
482 FreeInArg(ofn->lpstrDefExt, lpstrDefExt);
483 FreeInArg(ofn->lpTemplateName, lpTemplateName);
485 MemFree((LPVOID)(fodInfos));
486 return ret;
489 void ArrangeCtrlPositions( HWND hwndChildDlg, HWND hwndParentDlg)
491 HWND hwndChild,hwndStc32;
492 RECT rectParent, rectChild, rectCtrl, rectStc32, rectTemp;
493 POINT ptMoveCtl;
494 POINT ptParentClient;
496 TRACE("\n");
498 ptMoveCtl.x = ptMoveCtl.y = 0;
499 hwndStc32=GetDlgItem(hwndChildDlg,stc32);
500 GetClientRect(hwndParentDlg,&rectParent);
501 GetClientRect(hwndChildDlg,&rectChild);
503 if(hwndStc32)
505 GetWindowRect(hwndStc32,&rectStc32);
506 MapWindowPoints(0, hwndChildDlg,(LPPOINT)&rectStc32,2);
507 CopyRect(&rectTemp,&rectStc32);
509 SetRect(&rectStc32,rectStc32.left,rectStc32.top,rectStc32.left + (rectParent.right-rectParent.left),rectStc32.top+(rectParent.bottom-rectParent.top));
510 SetWindowPos(hwndStc32,0,rectStc32.left,rectStc32.top,rectStc32.right-rectStc32.left,rectStc32.bottom-rectStc32.top,SWP_NOMOVE|SWP_NOZORDER | SWP_NOACTIVATE);
512 if(rectStc32.right < rectTemp.right)
514 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
515 ptMoveCtl.x = 0;
517 else
519 ptMoveCtl.x = (rectStc32.right - rectTemp.right);
520 ptParentClient.x = max((rectParent.right-rectParent.left),((rectChild.right-rectChild.left)+rectStc32.right-rectTemp.right));
523 if(rectStc32.bottom < rectTemp.bottom)
525 ptParentClient.y = max((rectParent.bottom-rectParent.top),(rectChild.bottom-rectChild.top));
526 ptMoveCtl.y = 0;
528 else
530 ptMoveCtl.y = (rectStc32.bottom - rectTemp.bottom);
531 ptParentClient.y = max((rectParent.bottom-rectParent.top),((rectChild.bottom-rectChild.top)+rectStc32.bottom-rectTemp.bottom));
534 else
536 if( (GetWindow(hwndChildDlg,GW_CHILD)) == (HWND) NULL) return;
538 SetRectEmpty(&rectTemp);
539 ptParentClient.x = max((rectParent.right-rectParent.left),(rectChild.right-rectChild.left));
540 ptParentClient.y = (rectParent.bottom-rectParent.top) + (rectChild.bottom-rectChild.top);
541 ptMoveCtl.y = rectParent.bottom-rectParent.top;
542 ptMoveCtl.x=0;
544 SetRect(&rectParent,rectParent.left,rectParent.top,rectParent.left+ptParentClient.x,rectParent.top+ptParentClient.y);
545 AdjustWindowRectEx( &rectParent,GetWindowLongA(hwndParentDlg,GWL_STYLE),FALSE,GetWindowLongA(hwndParentDlg,GWL_EXSTYLE));
547 SetWindowPos(hwndChildDlg, 0, 0,0, ptParentClient.x,ptParentClient.y, SWP_NOZORDER );
548 SetWindowPos(hwndParentDlg, 0, rectParent.left,rectParent.top, (rectParent.right- rectParent.left),
549 (rectParent.bottom-rectParent.top),SWP_NOMOVE | SWP_NOZORDER);
551 hwndChild = GetWindow(hwndChildDlg,GW_CHILD);
552 if(hwndStc32)
554 GetWindowRect(hwndStc32,&rectStc32);
555 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
557 else
558 SetRect(&rectStc32,0,0,0,0);
560 if (hwndChild )
564 if(hwndChild != hwndStc32)
566 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
567 continue;
568 GetWindowRect(hwndChild,&rectCtrl);
569 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
572 Check the initial position of the controls relative to the initial
573 position and size of stc32 (before it is expanded).
575 if (rectCtrl.left >= rectTemp.right && rectCtrl.top >= rectTemp.bottom)
577 rectCtrl.left += ptMoveCtl.x;
578 rectCtrl.top += ptMoveCtl.y;
580 else if (rectCtrl.left >= rectTemp.right)
582 rectCtrl.left += ptMoveCtl.x;
584 else if (rectCtrl.top >= rectTemp.bottom)
586 rectCtrl.top += ptMoveCtl.y;
589 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
590 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
591 SWP_NOSIZE | SWP_NOZORDER );
593 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
595 hwndChild = GetWindow(hwndParentDlg,GW_CHILD);
597 if(hwndStc32)
599 GetWindowRect(hwndStc32,&rectStc32);
600 MapWindowPoints( 0, hwndChildDlg,(LPPOINT)&rectStc32,2);
601 ptMoveCtl.x = rectStc32.left - 0;
602 ptMoveCtl.y = rectStc32.top - 0;
603 if (hwndChild )
607 if(hwndChild != hwndChildDlg)
609 if (GetWindowLongA( hwndChild, GWL_STYLE ) & WS_MAXIMIZE)
610 continue;
611 GetWindowRect(hwndChild,&rectCtrl);
612 MapWindowPoints( 0, hwndParentDlg,(LPPOINT)&rectCtrl,2);
614 rectCtrl.left += ptMoveCtl.x;
615 rectCtrl.top += ptMoveCtl.y;
617 SetWindowPos( hwndChild, 0, rectCtrl.left, rectCtrl.top,
618 rectCtrl.right-rectCtrl.left,rectCtrl.bottom-rectCtrl.top,
619 SWP_NOSIZE |SWP_NOZORDER );
621 } while ((hwndChild=GetWindow( hwndChild, GW_HWNDNEXT )) != (HWND)NULL);
627 HRESULT WINAPI FileOpenDlgProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
629 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(GetParent(hwnd),FileOpenDlgInfosStr);
631 #if 0
632 TRACE("0x%04x\n", uMsg);
633 #endif
635 switch(uMsg)
637 case WM_INITDIALOG:
639 fodInfos = (FileOpenDlgInfos *)lParam;
640 lParam = (LPARAM) fodInfos->ofnInfos;
641 ArrangeCtrlPositions(hwnd,GetParent(hwnd));
643 if(fodInfos && IsHooked(fodInfos))
644 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
645 return 0;
649 if(fodInfos && IsHooked(fodInfos))
650 return CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,hwnd,uMsg,wParam,lParam);
652 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
655 HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
657 LPCVOID template;
658 HRSRC hRes;
659 HANDLE hDlgTmpl = 0;
660 HWND hChildDlg = 0;
662 TRACE("\n");
664 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATE ||
665 fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
667 if (fodInfos->ofnInfos->Flags & OFN_ENABLETEMPLATEHANDLE)
669 if( !(template = LockResource( fodInfos->ofnInfos->hInstance)))
671 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
672 return (HWND)NULL;
675 else
677 if (!(hRes = FindResourceA(MapHModuleSL(fodInfos->ofnInfos->hInstance),
678 (fodInfos->ofnInfos->lpTemplateName), RT_DIALOGA)))
680 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
681 return (HWND)NULL;
683 if (!(hDlgTmpl = LoadResource( MapHModuleSL(fodInfos->ofnInfos->hInstance),
684 hRes )) || !(template = LockResource( hDlgTmpl )))
686 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
687 return (HWND)NULL;
691 hChildDlg= CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,template,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
692 if(hChildDlg)
694 ShowWindow(hChildDlg,SW_SHOW);
695 return hChildDlg;
698 else if( IsHooked(fodInfos))
700 RECT rectHwnd;
701 DLGTEMPLATE tmplate;
702 GetClientRect(hwnd,&rectHwnd);
703 tmplate.style = WS_CHILD | WS_CLIPSIBLINGS;
704 tmplate.dwExtendedStyle = 0;
705 tmplate.cdit = 0;
706 tmplate.x = 0;
707 tmplate.y = 0;
708 tmplate.cx = rectHwnd.right-rectHwnd.left;
709 tmplate.cy = rectHwnd.bottom-rectHwnd.top;
711 return CreateDialogIndirectParamA(fodInfos->ofnInfos->hInstance,&tmplate,hwnd,(DLGPROC)FileOpenDlgProcUserTemplate,(LPARAM)fodInfos);
713 return (HWND)NULL;
716 /***********************************************************************
717 * SendCustomDlgNotificationMessage
719 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog
722 HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
724 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);
726 TRACE("0x%04x 0x%04x\n",hwndParentDlg, uCode);
728 if(!fodInfos) return 0;
730 if(fodInfos->ofnInfos->Flags & OFN_UNICODE)
731 FIXME("sending OPENFILENAMEA structure. Hook is expecting OPENFILENAMEW!\n");
733 if(fodInfos->DlgInfos.hwndCustomDlg)
735 OFNOTIFYA ofnNotify;
736 HRESULT ret;
737 ofnNotify.hdr.hwndFrom=hwndParentDlg;
738 ofnNotify.hdr.idFrom=0;
739 ofnNotify.hdr.code = uCode;
740 ofnNotify.lpOFN = fodInfos->ofnInfos;
741 TRACE("CALL NOTIFY for %x\n", uCode);
742 ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);
743 TRACE("RET NOTIFY\n");
744 return ret;
746 return TRUE;
749 /***********************************************************************
750 * FILEDLG95_HandleCustomDialogMessages
752 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages
754 HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
756 LPSTR lpstrFileSpec;
757 int reqSize;
758 char lpstrPath[MAX_PATH];
759 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
760 if(!fodInfos) return -1;
762 switch(uMsg)
764 case CDM_GETFILEPATH:
765 GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
766 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
767 if (lpstrFileSpec==lpstrPath)
769 char lpstrCurrentDir[MAX_PATH];
770 /* Prepend the current path */
771 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);
772 if ((LPSTR)lParam!=NULL)
773 snprintf((LPSTR)lParam,(int)wParam,"%s\\%s",lpstrCurrentDir,lpstrPath);
774 reqSize=strlen(lpstrCurrentDir)+1+strlen(lpstrPath)+1;
776 else
778 lstrcpynA((LPSTR)lParam,(LPSTR)lpstrPath,(int)wParam);
779 reqSize=strlen(lpstrPath);
781 /* return the required buffer size */
782 return reqSize;
784 case CDM_GETFOLDERPATH:
785 SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);
786 if ((LPSTR)lParam!=NULL)
787 lstrcpynA((LPSTR)lParam,lpstrPath,(int)wParam);
788 return strlen(lpstrPath);
790 case CDM_GETSPEC:
791 reqSize=GetDlgItemTextA(hwnd,IDC_FILENAME,lpstrPath, sizeof(lpstrPath));
792 lpstrFileSpec = (LPSTR)PathFindFileNameA(lpstrPath);
793 if ((LPSTR)lParam!=NULL)
794 lstrcpynA((LPSTR)lParam, lpstrFileSpec, (int)wParam);
795 return strlen(lpstrFileSpec);
797 case CDM_SETCONTROLTEXT:
798 if ( 0 != lParam )
799 SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );
800 return TRUE;
802 case CDM_HIDECONTROL:
803 case CDM_SETDEFEXT:
804 FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");
805 return -1;
807 return TRUE;
810 /***********************************************************************
811 * FileOpenDlgProc95
813 * File open dialog procedure
815 HRESULT WINAPI FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
817 #if 0
818 TRACE("0x%04x 0x%04x\n", hwnd, uMsg);
819 #endif
821 switch(uMsg)
823 case WM_INITDIALOG:
825 FileOpenDlgInfos * fodInfos = (FileOpenDlgInfos *)lParam;
827 /* Adds the FileOpenDlgInfos in the property list of the dialog
828 so it will be easily accessible through a GetPropA(...) */
829 SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos);
831 fodInfos->DlgInfos.hwndCustomDlg =
832 CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd);
834 FILEDLG95_InitControls(hwnd);
835 SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE);
836 FILEDLG95_FillControls(hwnd, wParam, lParam);
837 SendCustomDlgNotificationMessage(hwnd,CDN_SELCHANGE);
838 SetWindowPos(fodInfos->DlgInfos.hwndCustomDlg, HWND_BOTTOM,
839 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
840 return 0;
842 case WM_COMMAND:
843 return FILEDLG95_OnWMCommand(hwnd, wParam, lParam);
844 case WM_DRAWITEM:
846 switch(((LPDRAWITEMSTRUCT)lParam)->CtlID)
848 case IDC_LOOKIN:
849 FILEDLG95_LOOKIN_DrawItem((LPDRAWITEMSTRUCT) lParam);
850 return TRUE;
853 return FALSE;
855 case WM_GETISHELLBROWSER:
856 return FILEDLG95_OnWMGetIShellBrowser(hwnd);
858 case WM_DESTROY:
859 RemovePropA(hwnd, FileOpenDlgInfosStr);
860 return FALSE;
862 case WM_NOTIFY:
864 LPNMHDR lpnmh = (LPNMHDR)lParam;
865 UINT stringId = -1;
867 /* set up the button tooltips strings */
868 if(TTN_GETDISPINFOA == lpnmh->code )
870 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
871 switch(lpnmh->idFrom )
873 /* Up folder button */
874 case FCIDM_TB_UPFOLDER:
875 stringId = IDS_UPFOLDER;
876 break;
877 /* New folder button */
878 case FCIDM_TB_NEWFOLDER:
879 stringId = IDS_NEWFOLDER;
880 break;
881 /* List option button */
882 case FCIDM_TB_SMALLICON:
883 stringId = IDS_LISTVIEW;
884 break;
885 /* Details option button */
886 case FCIDM_TB_REPORTVIEW:
887 stringId = IDS_REPORTVIEW;
888 break;
889 /* Desktop button */
890 case FCIDM_TB_DESKTOP:
891 stringId = IDS_TODESKTOP;
892 break;
893 default:
894 stringId = 0;
896 lpdi->hinst = COMMDLG_hInstance32;
897 lpdi->lpszText = (LPSTR) stringId;
899 return FALSE;
901 default :
902 if(uMsg >= CDM_FIRST && uMsg <= CDM_LAST)
903 return FILEDLG95_HandleCustomDialogMessages(hwnd, uMsg, wParam, lParam);
904 return FALSE;
908 /***********************************************************************
909 * FILEDLG95_InitControls
911 * WM_INITDIALOG message handler (before hook notification)
913 static LRESULT FILEDLG95_InitControls(HWND hwnd)
915 TBBUTTON tbb[] =
917 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
918 {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
919 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
920 {VIEW_NEWFOLDER+1, FCIDM_TB_DESKTOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
921 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
922 {VIEW_NEWFOLDER, FCIDM_TB_NEWFOLDER, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
923 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
924 {VIEW_LIST, FCIDM_TB_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
925 {VIEW_DETAILS, FCIDM_TB_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
927 TBADDBITMAP tba[] =
929 { HINST_COMMCTRL, IDB_VIEW_SMALL_COLOR },
930 { COMDLG32_hInstance, 800 } // desktop icon
933 RECT rectTB;
935 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
937 TRACE("%p\n", fodInfos);
939 /* Get the hwnd of the controls */
940 fodInfos->DlgInfos.hwndFileName = GetDlgItem(hwnd,IDC_FILENAME);
941 fodInfos->DlgInfos.hwndFileTypeCB = GetDlgItem(hwnd,IDC_FILETYPE);
942 fodInfos->DlgInfos.hwndLookInCB = GetDlgItem(hwnd,IDC_LOOKIN);
944 /* construct the toolbar */
945 GetWindowRect(GetDlgItem(hwnd,IDC_TOOLBARSTATIC),&rectTB);
946 MapWindowPoints( 0, hwnd,(LPPOINT)&rectTB,2);
948 fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, (LPSTR) NULL,
949 WS_CHILD | WS_GROUP | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE,
950 0, 0, 150, 26, hwnd, (HMENU) IDC_TOOLBAR, COMMDLG_hInstance32, NULL);
952 SetWindowPos(fodInfos->DlgInfos.hwndTB, 0,
953 rectTB.left,rectTB.top, rectTB.right-rectTB.left, rectTB.bottom-rectTB.top,
954 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
956 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
958 /* fixme: use TB_LOADIMAGES when implemented */
959 /* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/
960 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]);
961 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]);
963 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb);
964 SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0);
966 /* Set the window text with the text specified in the OPENFILENAME structure */
967 if(fodInfos->ofnInfos->lpstrTitle)
969 SetWindowTextA(hwnd,fodInfos->ofnInfos->lpstrTitle);
971 else if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
973 SetWindowTextA(hwnd,"Save");
976 /* Initialise the file name edit control */
977 if(fodInfos->ofnInfos->lpstrFile)
979 LPSTR lpstrFile = PathFindFileNameA(fodInfos->ofnInfos->lpstrFile);
980 SetDlgItemTextA(hwnd, IDC_FILENAME, lpstrFile);
983 /* Must the open as read only check box be checked ?*/
984 if(fodInfos->ofnInfos->Flags & OFN_READONLY)
986 SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0);
989 /* Must the open as read only check box be hid ?*/
990 if(fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY)
992 ShowWindow(GetDlgItem(hwnd,IDC_OPENREADONLY),SW_HIDE);
995 /* Must the help button be hid ?*/
996 if (!(fodInfos->ofnInfos->Flags & OFN_SHOWHELP))
998 ShowWindow(GetDlgItem(hwnd, pshHelp), SW_HIDE);
1001 /* Resize the height, if open as read only checkbox ad help button
1002 are hidden and we are not using a custom template */
1003 if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) &&
1004 (!(fodInfos->ofnInfos->Flags &
1005 (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))))
1007 RECT rectDlg, rectHelp, rectCancel;
1008 GetWindowRect(hwnd, &rectDlg);
1009 GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp);
1010 GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel);
1011 /* subtract the height of the help button plus the space between
1012 the help button and the cancel button to the height of the dialog */
1013 SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left,
1014 (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom),
1015 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
1018 /* change Open to Save FIXME: use resources */
1019 if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG)
1021 SetDlgItemTextA(hwnd,IDOK,"&Save");
1022 SetDlgItemTextA(hwnd,IDC_LOOKINSTATIC,"Save &in");
1024 return 0;
1027 /***********************************************************************
1028 * FILEDLG95_FillControls
1030 * WM_INITDIALOG message handler (after hook notification)
1032 static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam)
1034 LPITEMIDLIST pidlItemId = NULL;
1036 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam;
1038 TRACE("dir=%s file=%s\n",
1039 fodInfos->ofnInfos->lpstrInitialDir, fodInfos->ofnInfos->lpstrFile);
1041 /* Get the initial directory pidl */
1043 if(!(pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder,fodInfos->ofnInfos->lpstrInitialDir)))
1045 char path[MAX_PATH];
1047 GetCurrentDirectoryA(MAX_PATH,path);
1048 pidlItemId = GetPidlFromName(fodInfos->Shell.FOIShellFolder, path);
1051 /* Initialise shell objects */
1052 FILEDLG95_SHELL_Init(hwnd);
1054 /* Initialize the Look In combo box */
1055 FILEDLG95_LOOKIN_Init(fodInfos->DlgInfos.hwndLookInCB);
1057 /* Initialize the filter combo box */
1058 FILEDLG95_FILETYPE_Init(hwnd);
1060 /* Browse to the initial directory */
1061 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,pidlItemId, SBSP_ABSOLUTE);
1063 /* Free pidlItem memory */
1064 COMDLG32_SHFree(pidlItemId);
1066 return TRUE;
1068 /***********************************************************************
1069 * FILEDLG95_Clean
1071 * Regroups all the cleaning functions of the filedlg
1073 void FILEDLG95_Clean(HWND hwnd)
1075 FILEDLG95_FILETYPE_Clean(hwnd);
1076 FILEDLG95_LOOKIN_Clean(hwnd);
1077 FILEDLG95_SHELL_Clean(hwnd);
1079 /***********************************************************************
1080 * FILEDLG95_OnWMCommand
1082 * WM_COMMAND message handler
1084 static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
1086 WORD wNotifyCode = HIWORD(wParam); /* notification code */
1087 WORD wID = LOWORD(wParam); /* item, control, or accelerator identifier */
1088 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1090 switch(wID)
1092 /* OK button */
1093 case IDOK:
1094 if(FILEDLG95_OnOpen(hwnd))
1095 SendCustomDlgNotificationMessage(hwnd,CDN_FILEOK);
1096 break;
1097 /* Cancel button */
1098 case IDCANCEL:
1099 FILEDLG95_Clean(hwnd);
1100 EndDialog(hwnd, FALSE);
1101 break;
1102 /* Filetype combo box */
1103 case IDC_FILETYPE:
1104 FILEDLG95_FILETYPE_OnCommand(hwnd,wNotifyCode);
1105 break;
1106 /* LookIn combo box */
1107 case IDC_LOOKIN:
1108 FILEDLG95_LOOKIN_OnCommand(hwnd,wNotifyCode);
1109 break;
1111 /* --- toolbar --- */
1112 /* Up folder button */
1113 case FCIDM_TB_UPFOLDER:
1114 FILEDLG95_SHELL_UpFolder(hwnd);
1115 break;
1116 /* New folder button */
1117 case FCIDM_TB_NEWFOLDER:
1118 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_NEWFOLDER);
1119 break;
1120 /* List option button */
1121 case FCIDM_TB_SMALLICON:
1122 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWLIST);
1123 break;
1124 /* Details option button */
1125 case FCIDM_TB_REPORTVIEW:
1126 FILEDLG95_SHELL_ExecuteCommand(hwnd,CMDSTR_VIEWDETAILS);
1127 break;
1128 /* Details option button */
1129 case FCIDM_TB_DESKTOP:
1130 FILEDLG95_SHELL_BrowseToDesktop(hwnd);
1131 break;
1133 case IDC_FILENAME:
1134 break;
1137 /* Do not use the listview selection anymore */
1138 fodInfos->DlgInfos.dwDlgProp &= ~FODPROP_USEVIEW;
1139 return 0;
1142 /***********************************************************************
1143 * FILEDLG95_OnWMGetIShellBrowser
1145 * WM_GETISHELLBROWSER message handler
1147 static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd)
1150 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1152 TRACE("\n");
1154 SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)fodInfos->Shell.FOIShellBrowser);
1156 return TRUE;
1160 /***********************************************************************
1161 * FILEDLG95_OnOpenMultipleFiles
1163 * Handles the opening of multiple files.
1165 * FIXME
1166 * check destination buffer size
1168 BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPSTR lpstrFileList, UINT nFileCount, UINT sizeUsed)
1170 CHAR lpstrPathSpec[MAX_PATH] = "";
1171 LPSTR lpstrFile;
1172 UINT nCount, nSizePath;
1173 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1175 TRACE("\n");
1177 lpstrFile = fodInfos->ofnInfos->lpstrFile;
1178 lpstrFile[0] = '\0';
1180 SHGetPathFromIDListA( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );
1182 if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&
1183 ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST))
1185 LPSTR lpstrTemp = lpstrFileList;
1187 for ( nCount = 0; nCount < nFileCount; nCount++ )
1189 LPITEMIDLIST pidl;
1191 pidl = GetPidlFromName(fodInfos->Shell.FOIShellFolder, lpstrTemp);
1192 if (!pidl)
1194 CHAR lpstrNotFound[100];
1195 CHAR lpstrMsg[100];
1196 CHAR tmp[400];
1198 LoadStringA(COMMDLG_hInstance32, IDS_FILENOTFOUND, lpstrNotFound, 100);
1199 LoadStringA(COMMDLG_hInstance32, IDS_VERIFYFILE, lpstrMsg, 100);
1201 strcpy(tmp, lpstrTemp);
1202 strcat(tmp, "\n");
1203 strcat(tmp, lpstrNotFound);
1204 strcat(tmp, "\n");
1205 strcat(tmp, lpstrMsg);
1207 MessageBoxA(hwnd, tmp, fodInfos->ofnInfos->lpstrTitle, MB_OK | MB_ICONEXCLAMATION);
1208 return FALSE;
1211 /* move to the next file in the list of files */
1212 lpstrTemp += strlen(lpstrTemp) + 1;
1213 COMDLG32_SHFree(pidl);
1217 nSizePath = strlen(lpstrPathSpec);
1218 strcpy( lpstrFile, lpstrPathSpec);
1219 memcpy( lpstrFile + nSizePath + 1, lpstrFileList, sizeUsed );
1221 fodInfos->ofnInfos->nFileOffset = nSizePath + 1;
1222 fodInfos->ofnInfos->nFileExtension = 0;
1224 /* clean and exit */
1225 FILEDLG95_Clean(hwnd);
1226 return EndDialog(hwnd,TRUE);
1229 /***********************************************************************
1230 * FILEDLG95_OnOpen
1232 * Ok button WM_COMMAND message handler
1234 * If the function succeeds, the return value is nonzero.
1236 #define ONOPEN_BROWSE 1
1237 #define ONOPEN_OPEN 2
1238 #define ONOPEN_SEARCH 3
1239 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)
1241 char strMsgTitle[MAX_PATH];
1242 char strMsgText [MAX_PATH];
1243 if (idCaption)
1244 LoadStringA(COMDLG32_hInstance, idCaption, strMsgTitle, sizeof(strMsgTitle));
1245 else
1246 strMsgTitle[0] = '\0';
1247 LoadStringA(COMDLG32_hInstance, idText, strMsgText, sizeof(strMsgText));
1248 MessageBoxA(hwnd,strMsgText, strMsgTitle, MB_OK | MB_ICONHAND);
1251 BOOL FILEDLG95_OnOpen(HWND hwnd)
1253 char * lpstrFileList;
1254 UINT nFileCount = 0;
1255 UINT sizeUsed = 0;
1256 BOOL ret = TRUE;
1257 char lpstrPathAndFile[MAX_PATH];
1258 char lpstrTemp[MAX_PATH];
1259 LPSHELLFOLDER lpsf = NULL;
1260 int nOpenAction;
1261 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1263 TRACE("hwnd=0x%04x\n", hwnd);
1265 /* get the files from the edit control */
1266 nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed);
1268 /* try if the user selected a folder in the shellview */
1269 if(nFileCount == 0)
1271 BrowseSelectedFolder(hwnd);
1272 return FALSE;
1275 if(nFileCount > 1)
1277 ret = FILEDLG95_OnOpenMultipleFiles(hwnd, lpstrFileList, nFileCount, sizeUsed);
1278 goto ret;
1281 TRACE("count=%u len=%u file=%s\n", nFileCount, sizeUsed, lpstrFileList);
1284 Step 1: Build a complete path name from the current folder and
1285 the filename or path in the edit box.
1286 Special cases:
1287 - the path in the edit box is a root path
1288 (with or without drive letter)
1289 - the edit box contains ".." (or a path with ".." in it)
1292 /* Get the current directory name */
1293 if (!SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))
1295 /* we are in a special folder, default to desktop */
1296 if(FAILED(COMDLG32_SHGetFolderPathA(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))
1298 /* last fallback */
1299 GetCurrentDirectoryA(MAX_PATH, lpstrPathAndFile);
1302 PathAddBackslashA(lpstrPathAndFile);
1304 TRACE("current directory=%s\n", lpstrPathAndFile);
1306 /* if the user specifyed a fully qualified path use it */
1307 if(PathIsRelativeA(lpstrFileList))
1309 strcat(lpstrPathAndFile, lpstrFileList);
1311 else
1313 /* does the path have a drive letter? */
1314 if (PathGetDriveNumberA(lpstrFileList) == -1)
1315 strcpy(lpstrPathAndFile+2, lpstrFileList);
1316 else
1317 strcpy(lpstrPathAndFile, lpstrFileList);
1320 /* resolve "." and ".." */
1321 PathCanonicalizeA(lpstrTemp, lpstrPathAndFile );
1322 strcpy(lpstrPathAndFile, lpstrTemp);
1323 TRACE("canon=%s\n", lpstrPathAndFile);
1325 MemFree(lpstrFileList);
1328 Step 2: here we have a cleaned up path
1330 We have to parse the path step by step to see if we have to browse
1331 to a folder if the path points to a directory or the last
1332 valid element is a directory.
1334 valid variables:
1335 lpstrPathAndFile: cleaned up path
1338 nOpenAction = ONOPEN_BROWSE;
1340 /* dont apply any checks with OFN_NOVALIDATE */
1341 if(!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE))
1343 LPSTR lpszTemp, lpszTemp1;
1344 LPITEMIDLIST pidl = NULL;
1346 /* check for invalid chars */
1347 if(strpbrk(lpstrPathAndFile+3, "/:<>|") != NULL)
1349 FILEDLG95_OnOpenMessage(hwnd, IDS_INVALID_FILENAME_TITLE, IDS_INVALID_FILENAME);
1350 ret = FALSE;
1351 goto ret;
1354 if (FAILED (SHGetDesktopFolder(&lpsf))) return FALSE;
1356 lpszTemp1 = lpszTemp = lpstrPathAndFile;
1357 while (lpszTemp1)
1359 LPSHELLFOLDER lpsfChild;
1360 WCHAR lpwstrTemp[MAX_PATH];
1361 DWORD dwEaten, dwAttributes;
1363 lpszTemp = PathFindNextComponentA(lpszTemp);
1365 if (!lpszTemp) break; /* end of path */
1367 if(*lpszTemp)
1369 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszTemp1, lpszTemp - lpszTemp1,
1370 lpwstrTemp, MAX_PATH );
1371 lpwstrTemp[len] = 0;
1373 else
1375 MultiByteToWideChar( CP_ACP, 0, lpszTemp1, -1,
1376 lpwstrTemp, sizeof(lpwstrTemp)/sizeof(WCHAR) );
1378 /* if the last element is a wildcard do a search */
1379 if(strpbrk(lpszTemp1, "*?") != NULL)
1381 nOpenAction = ONOPEN_SEARCH;
1382 break;
1385 lpszTemp1 = lpszTemp;
1387 TRACE("parse now=%s next=%s sf=%p\n",debugstr_w(lpwstrTemp), debugstr_a(lpszTemp), lpsf);
1389 if(lstrlenW(lpwstrTemp)==2) PathAddBackslashW(lpwstrTemp);
1391 dwAttributes = SFGAO_FOLDER;
1392 if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes)))
1394 /* the path component is valid, we have a pidl of the next path component */
1395 TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl);
1396 if(dwAttributes & SFGAO_FOLDER)
1398 if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild)))
1400 ERR("bind to failed\n"); /* should not fail */
1401 break;
1403 IShellFolder_Release(lpsf);
1404 lpsf = lpsfChild;
1405 lpsfChild = NULL;
1407 else
1409 TRACE("value\n");
1411 /* end dialog, return value */
1412 nOpenAction = ONOPEN_OPEN;
1413 break;
1415 COMDLG32_SHFree(pidl);
1416 pidl = NULL;
1418 else
1420 if(*lpszTemp) /* points to trailing null for last path element */
1422 if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST)
1424 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_PATHNOTEXISTING);
1425 break;
1428 else
1430 if(fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST)
1432 FILEDLG95_OnOpenMessage(hwnd, 0, IDS_FILENOTEXISTING);
1433 break;
1436 /* change to the current folder */
1437 nOpenAction = ONOPEN_OPEN;
1438 break;
1441 if(pidl) COMDLG32_SHFree(pidl);
1445 Step 3: here we have a cleaned up and validated path
1447 valid variables:
1448 lpsf: ShellFolder bound to the rightmost valid path component
1449 lpstrPathAndFile: cleaned up path
1450 nOpenAction: action to do
1452 TRACE("end validate sf=%p\n", lpsf);
1454 switch(nOpenAction)
1456 case ONOPEN_SEARCH: /* set the current filter to the file mask and refresh */
1457 TRACE("ONOPEN_SEARCH %s\n", lpstrPathAndFile);
1459 int iPos;
1460 LPSTR lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1461 DWORD len;
1463 /* replace the current filter */
1464 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1465 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1466 len = MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1, NULL, 0 );
1467 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR));
1468 MultiByteToWideChar( CP_ACP, 0, lpszTemp, -1,
1469 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1471 /* set the filter cb to the extension when possible */
1472 if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))
1473 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);
1475 /* fall through */
1476 case ONOPEN_BROWSE: /* browse to the highest folder we could bind to */
1477 TRACE("ONOPEN_BROWSE\n");
1479 IPersistFolder2 * ppf2;
1480 if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))
1482 LPITEMIDLIST pidlCurrent;
1483 IPersistFolder2_GetCurFolder(ppf2, &pidlCurrent);
1484 IPersistFolder2_Release(ppf2);
1485 if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent))
1487 IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);
1489 else if( nOpenAction == ONOPEN_SEARCH )
1491 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1493 COMDLG32_SHFree(pidlCurrent);
1496 ret = FALSE;
1497 break;
1498 case ONOPEN_OPEN: /* fill in the return struct and close the dialog */
1499 TRACE("ONOPEN_OPEN %s\n", lpstrPathAndFile);
1501 /* add default extension */
1502 if (fodInfos->ofnInfos->lpstrDefExt)
1504 if (! *PathFindExtensionA(lpstrPathAndFile))
1506 strcat(lpstrPathAndFile, ".");
1507 strcat(lpstrPathAndFile, fodInfos->ofnInfos->lpstrDefExt);
1511 /* Check that the size of the file does not exceed buffer size.
1512 (Allow for extra \0 if OFN_MULTISELECT is set.) */
1513 if(strlen(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile -
1514 ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0))
1516 LPSTR lpszTemp;
1518 /* fill destination buffer */
1519 strcpy(fodInfos->ofnInfos->lpstrFile, lpstrPathAndFile);
1520 if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT)
1521 fodInfos->ofnInfos->lpstrFile[strlen(fodInfos->ofnInfos->lpstrFile)
1522 + 1] = '\0';
1524 /* set filename offset */
1525 lpszTemp = PathFindFileNameA(lpstrPathAndFile);
1526 fodInfos->ofnInfos->nFileOffset = lpszTemp - lpstrPathAndFile;
1528 /* set extension offset */
1529 lpszTemp = PathFindExtensionA(lpstrPathAndFile);
1530 fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? lpszTemp - lpstrPathAndFile + 1 : 0;
1532 /* set the lpstrFileTitle */
1533 if(fodInfos->ofnInfos->lpstrFileTitle)
1535 LPSTR lpstrFileTitle = PathFindFileNameA(lpstrPathAndFile);
1536 strncpy(fodInfos->ofnInfos->lpstrFileTitle, lpstrFileTitle, fodInfos->ofnInfos->nMaxFileTitle);
1539 /* ask the hook if we can close */
1540 if(IsHooked(fodInfos))
1542 /* FIXME we are sending ASCII-structures. Does not work with NT */
1543 /* first old style */
1544 TRACE("---\n");
1545 CallWindowProcA((WNDPROC)fodInfos->ofnInfos->lpfnHook,
1546 fodInfos->DlgInfos.hwndCustomDlg,
1547 fodInfos->HookMsg.fileokstring, 0, (LPARAM)fodInfos->ofnInfos);
1548 if (GetWindowLongA(hwnd, DWL_MSGRESULT))
1550 TRACE("cancled\n");
1551 ret = FALSE;
1552 goto ret;
1556 TRACE("close\n");
1557 FILEDLG95_Clean(hwnd);
1558 ret = EndDialog(hwnd, TRUE);
1560 else
1562 /* FIXME set error FNERR_BUFFERTOSMALL */
1563 FILEDLG95_Clean(hwnd);
1564 ret = EndDialog(hwnd, FALSE);
1566 goto ret;
1568 break;
1571 ret:
1572 if(lpsf) IShellFolder_Release(lpsf);
1573 return ret;
1576 /***********************************************************************
1577 * FILEDLG95_SHELL_Init
1579 * Initialisation of the shell objects
1581 static HRESULT FILEDLG95_SHELL_Init(HWND hwnd)
1583 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1585 TRACE("\n");
1588 * Initialisation of the FileOpenDialogInfos structure
1591 /* Shell */
1593 /*ShellInfos */
1594 fodInfos->ShellInfos.hwndOwner = hwnd;
1596 /* Disable multi-select if flag not set */
1597 if (!(fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT))
1599 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_SINGLESEL;
1601 fodInfos->ShellInfos.folderSettings.fFlags |= FWF_AUTOARRANGE | FWF_ALIGNLEFT;
1602 fodInfos->ShellInfos.folderSettings.ViewMode = FVM_LIST;
1604 GetWindowRect(GetDlgItem(hwnd,IDC_SHELLSTATIC),&fodInfos->ShellInfos.rectView);
1605 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.left);
1606 ScreenToClient(hwnd,(LPPOINT)&fodInfos->ShellInfos.rectView.right);
1608 /* Construct the IShellBrowser interface */
1609 fodInfos->Shell.FOIShellBrowser = IShellBrowserImpl_Construct(hwnd);
1611 return NOERROR;
1614 /***********************************************************************
1615 * FILEDLG95_SHELL_ExecuteCommand
1617 * Change the folder option and refresh the view
1618 * If the function succeeds, the return value is nonzero.
1620 static BOOL FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb)
1622 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1624 IContextMenu * pcm;
1625 TRACE("(0x%08x,%p)\n", hwnd, lpVerb);
1627 if(SUCCEEDED(IShellView_GetItemObject(fodInfos->Shell.FOIShellView,
1628 SVGIO_BACKGROUND,
1629 &IID_IContextMenu,
1630 (LPVOID*)&pcm)))
1632 CMINVOKECOMMANDINFO ci;
1633 ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
1634 ci.cbSize = sizeof(CMINVOKECOMMANDINFO);
1635 ci.lpVerb = lpVerb;
1636 ci.hwnd = hwnd;
1638 IContextMenu_InvokeCommand(pcm, &ci);
1639 IContextMenu_Release(pcm);
1642 return FALSE;
1645 /***********************************************************************
1646 * FILEDLG95_SHELL_UpFolder
1648 * Browse to the specified object
1649 * If the function succeeds, the return value is nonzero.
1651 static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
1653 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1655 TRACE("\n");
1657 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
1658 NULL,
1659 SBSP_PARENT)))
1661 return TRUE;
1663 return FALSE;
1666 /***********************************************************************
1667 * FILEDLG95_SHELL_BrowseToDesktop
1669 * Browse to the Desktop
1670 * If the function succeeds, the return value is nonzero.
1672 static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
1674 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1675 LPITEMIDLIST pidl;
1676 HRESULT hres;
1678 TRACE("\n");
1680 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);
1681 hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);
1682 COMDLG32_SHFree(pidl);
1683 return SUCCEEDED(hres);
1685 /***********************************************************************
1686 * FILEDLG95_SHELL_Clean
1688 * Cleans the memory used by shell objects
1690 static void FILEDLG95_SHELL_Clean(HWND hwnd)
1692 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1694 TRACE("\n");
1696 COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent);
1698 /* clean Shell interfaces */
1699 IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView);
1700 IShellView_Release(fodInfos->Shell.FOIShellView);
1701 IShellFolder_Release(fodInfos->Shell.FOIShellFolder);
1702 IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser);
1703 if (fodInfos->Shell.FOIDataObject)
1704 IDataObject_Release(fodInfos->Shell.FOIDataObject);
1707 /***********************************************************************
1708 * FILEDLG95_FILETYPE_Init
1710 * Initialisation of the file type combo box
1712 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
1714 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1716 TRACE("\n");
1718 if(fodInfos->ofnInfos->lpstrFilter)
1720 int nFilters = 0; /* number of filters */
1721 LPSTR lpstrFilter;
1722 LPCSTR lpstrPos = fodInfos->ofnInfos->lpstrFilter;
1724 for(;;)
1726 /* filter is a list... title\0ext\0......\0\0
1727 * Set the combo item text to the title and the item data
1728 * to the ext
1730 LPCSTR lpstrDisplay;
1731 LPSTR lpstrExt;
1733 /* Get the title */
1734 if(! *lpstrPos) break; /* end */
1735 lpstrDisplay = lpstrPos;
1736 lpstrPos += strlen(lpstrPos) + 1;
1738 /* Copy the extensions */
1739 if (! *lpstrPos) return E_FAIL; /* malformed filter */
1740 if (!(lpstrExt = (LPSTR) MemAlloc(strlen(lpstrPos)+1))) return E_FAIL;
1741 strcpy(lpstrExt,lpstrPos);
1742 lpstrPos += strlen(lpstrPos) + 1;
1744 /* Add the item at the end of the combo */
1745 CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay);
1746 CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt);
1747 nFilters++;
1750 * Set the current filter to the one specified
1751 * in the initialisation structure
1752 * FIXME: lpstrCustomFilter not handled at all
1755 /* set default filter index */
1756 if(fodInfos->ofnInfos->nFilterIndex == 0 && fodInfos->ofnInfos->lpstrCustomFilter == NULL)
1757 fodInfos->ofnInfos->nFilterIndex = 1;
1759 /* First, check to make sure our index isn't out of bounds. */
1760 if ( fodInfos->ofnInfos->nFilterIndex > nFilters )
1761 fodInfos->ofnInfos->nFilterIndex = nFilters;
1763 /* Set the current index selection. */
1764 CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->ofnInfos->nFilterIndex-1);
1766 /* Get the corresponding text string from the combo box. */
1767 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1768 fodInfos->ofnInfos->nFilterIndex-1);
1770 if ((INT)lpstrFilter == CB_ERR) /* control is empty */
1771 lpstrFilter = NULL;
1773 if(lpstrFilter)
1775 DWORD len;
1776 _strlwr(lpstrFilter); /* lowercase */
1777 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1778 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1779 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1780 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1783 return NOERROR;
1786 /***********************************************************************
1787 * FILEDLG95_FILETYPE_OnCommand
1789 * WM_COMMAND of the file type combo box
1790 * If the function succeeds, the return value is nonzero.
1792 static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode)
1794 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1796 switch(wNotifyCode)
1798 case CBN_SELENDOK:
1800 LPSTR lpstrFilter;
1802 /* Get the current item of the filetype combo box */
1803 int iItem = CBGetCurSel(fodInfos->DlgInfos.hwndFileTypeCB);
1805 /* set the current filter index - indexed from 1 */
1806 fodInfos->ofnInfos->nFilterIndex = iItem + 1;
1808 /* Set the current filter with the current selection */
1809 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1810 MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter);
1812 lpstrFilter = (LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,
1813 iItem);
1814 if((int)lpstrFilter != CB_ERR)
1816 DWORD len;
1817 _strlwr(lpstrFilter); /* lowercase */
1818 len = MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1, NULL, 0 );
1819 fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) );
1820 MultiByteToWideChar( CP_ACP, 0, lpstrFilter, -1,
1821 fodInfos->ShellInfos.lpstrCurrentFilter, len );
1822 SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE);
1825 /* Refresh the actual view to display the included items*/
1826 IShellView_Refresh(fodInfos->Shell.FOIShellView);
1829 return FALSE;
1831 /***********************************************************************
1832 * FILEDLG95_FILETYPE_SearchExt
1834 * searches for a extension in the filetype box
1836 static int FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCSTR lpstrExt)
1838 int i, iCount = CBGetCount(hwnd);
1840 TRACE("%s\n", lpstrExt);
1842 if(iCount != CB_ERR)
1844 for(i=0;i<iCount;i++)
1846 if(!strcasecmp(lpstrExt,(LPSTR)CBGetItemDataPtr(hwnd,i)))
1847 return i;
1850 return -1;
1853 /***********************************************************************
1854 * FILEDLG95_FILETYPE_Clean
1856 * Clean the memory used by the filetype combo box
1858 static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
1860 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
1861 int iPos;
1862 int iCount = CBGetCount(fodInfos->DlgInfos.hwndFileTypeCB);
1864 TRACE("\n");
1866 /* Delete each string of the combo and their associated data */
1867 if(iCount != CB_ERR)
1869 for(iPos = iCount-1;iPos>=0;iPos--)
1871 MemFree((LPSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,iPos));
1872 CBDeleteString(fodInfos->DlgInfos.hwndFileTypeCB,iPos);
1875 /* Current filter */
1876 if(fodInfos->ShellInfos.lpstrCurrentFilter)
1877 MemFree(fodInfos->ShellInfos.lpstrCurrentFilter);
1881 /***********************************************************************
1882 * FILEDLG95_LOOKIN_Init
1884 * Initialisation of the look in combo box
1886 static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
1888 IShellFolder *psfRoot, *psfDrives;
1889 IEnumIDList *lpeRoot, *lpeDrives;
1890 LPITEMIDLIST pidlDrives, pidlTmp, pidlTmp1, pidlAbsTmp;
1892 LookInInfos *liInfos = MemAlloc(sizeof(LookInInfos));
1894 TRACE("\n");
1896 liInfos->iMaxIndentation = 0;
1898 SetPropA(hwndCombo, LookInInfosStr, (HANDLE) liInfos);
1900 /* set item height for both text field and listbox */
1901 CBSetItemHeight(hwndCombo,-1,GetSystemMetrics(SM_CYSMICON));
1902 CBSetItemHeight(hwndCombo,0,GetSystemMetrics(SM_CYSMICON));
1904 /* Initialise data of Desktop folder */
1905 SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidlTmp);
1906 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1907 COMDLG32_SHFree(pidlTmp);
1909 SHGetSpecialFolderLocation(0,CSIDL_DRIVES,&pidlDrives);
1911 SHGetDesktopFolder(&psfRoot);
1913 if (psfRoot)
1915 /* enumerate the contents of the desktop */
1916 if(SUCCEEDED(IShellFolder_EnumObjects(psfRoot, hwndCombo, SHCONTF_FOLDERS, &lpeRoot)))
1918 while (S_OK == IEnumIDList_Next(lpeRoot, 1, &pidlTmp, NULL))
1920 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlTmp,LISTEND);
1922 /* special handling for CSIDL_DRIVES */
1923 if (COMDLG32_PIDL_ILIsEqual(pidlTmp, pidlDrives))
1925 if(SUCCEEDED(IShellFolder_BindToObject(psfRoot, pidlTmp, NULL, &IID_IShellFolder, (LPVOID*)&psfDrives)))
1927 /* enumerate the drives */
1928 if(SUCCEEDED(IShellFolder_EnumObjects(psfDrives, hwndCombo,SHCONTF_FOLDERS, &lpeDrives)))
1930 while (S_OK == IEnumIDList_Next(lpeDrives, 1, &pidlTmp1, NULL))
1932 pidlAbsTmp = COMDLG32_PIDL_ILCombine(pidlTmp, pidlTmp1);
1933 FILEDLG95_LOOKIN_AddItem(hwndCombo, pidlAbsTmp,LISTEND);
1934 COMDLG32_SHFree(pidlAbsTmp);
1935 COMDLG32_SHFree(pidlTmp1);
1937 IEnumIDList_Release(lpeDrives);
1939 IShellFolder_Release(psfDrives);
1942 COMDLG32_SHFree(pidlTmp);
1944 IEnumIDList_Release(lpeRoot);
1948 IShellFolder_Release(psfRoot);
1949 COMDLG32_SHFree(pidlDrives);
1950 return NOERROR;
1953 /***********************************************************************
1954 * FILEDLG95_LOOKIN_DrawItem
1956 * WM_DRAWITEM message handler
1958 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct)
1960 COLORREF crWin = GetSysColor(COLOR_WINDOW);
1961 COLORREF crHighLight = GetSysColor(COLOR_HIGHLIGHT);
1962 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1963 RECT rectText;
1964 RECT rectIcon;
1965 SHFILEINFOA sfi;
1966 HIMAGELIST ilItemImage;
1967 int iIndentation;
1968 TEXTMETRICA tm;
1969 LPSFOLDER tmpFolder;
1972 LookInInfos *liInfos = (LookInInfos *)GetPropA(pDIStruct->hwndItem,LookInInfosStr);
1974 TRACE("\n");
1976 if(pDIStruct->itemID == -1)
1977 return 0;
1979 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(pDIStruct->hwndItem,
1980 pDIStruct->itemID)))
1981 return 0;
1984 if(pDIStruct->itemID == liInfos->uSelectedItem)
1986 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1988 &sfi,
1989 sizeof (SHFILEINFOA),
1990 SHGFI_PIDL | SHGFI_SMALLICON |
1991 SHGFI_OPENICON | SHGFI_SYSICONINDEX |
1992 SHGFI_DISPLAYNAME );
1994 else
1996 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
1998 &sfi,
1999 sizeof (SHFILEINFOA),
2000 SHGFI_PIDL | SHGFI_SMALLICON |
2001 SHGFI_SYSICONINDEX |
2002 SHGFI_DISPLAYNAME);
2005 /* Is this item selected ? */
2006 if(pDIStruct->itemState & ODS_SELECTED)
2008 SetTextColor(pDIStruct->hDC,(0x00FFFFFF & ~(crText)));
2009 SetBkColor(pDIStruct->hDC,crHighLight);
2010 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crHighLight);
2012 else
2014 SetTextColor(pDIStruct->hDC,crText);
2015 SetBkColor(pDIStruct->hDC,crWin);
2016 FillRect(pDIStruct->hDC,&pDIStruct->rcItem,(HBRUSH)crWin);
2019 /* Do not indent item if drawing in the edit of the combo */
2020 if(pDIStruct->itemState & ODS_COMBOBOXEDIT)
2022 iIndentation = 0;
2023 ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem,
2025 &sfi,
2026 sizeof (SHFILEINFOA),
2027 SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON
2028 | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME );
2031 else
2033 iIndentation = tmpFolder->m_iIndent;
2035 /* Draw text and icon */
2037 /* Initialise the icon display area */
2038 rectIcon.left = pDIStruct->rcItem.left + ICONWIDTH/2 * iIndentation;
2039 rectIcon.top = pDIStruct->rcItem.top;
2040 rectIcon.right = rectIcon.left + ICONWIDTH;
2041 rectIcon.bottom = pDIStruct->rcItem.bottom;
2043 /* Initialise the text display area */
2044 GetTextMetricsA(pDIStruct->hDC, &tm);
2045 rectText.left = rectIcon.right;
2046 rectText.top =
2047 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2;
2048 rectText.right = pDIStruct->rcItem.right + XTEXTOFFSET;
2049 rectText.bottom =
2050 (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom + tm.tmHeight) / 2;
2052 /* Draw the icon from the image list */
2053 ImageList_Draw(ilItemImage,
2054 sfi.iIcon,
2055 pDIStruct->hDC,
2056 rectIcon.left,
2057 rectIcon.top,
2058 ILD_TRANSPARENT );
2060 /* Draw the associated text */
2061 if(sfi.szDisplayName)
2062 TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName));
2065 return NOERROR;
2068 /***********************************************************************
2069 * FILEDLG95_LOOKIN_OnCommand
2071 * LookIn combo box WM_COMMAND message handler
2072 * If the function succeeds, the return value is nonzero.
2074 static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
2076 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2078 TRACE("%p\n", fodInfos);
2080 switch(wNotifyCode)
2082 case CBN_SELENDOK:
2084 LPSFOLDER tmpFolder;
2085 int iItem;
2087 iItem = CBGetCurSel(fodInfos->DlgInfos.hwndLookInCB);
2089 if(!(tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,
2090 iItem)))
2091 return FALSE;
2094 if(SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser,
2095 tmpFolder->pidlItem,
2096 SBSP_ABSOLUTE)))
2098 return TRUE;
2100 break;
2104 return FALSE;
2107 /***********************************************************************
2108 * FILEDLG95_LOOKIN_AddItem
2110 * Adds an absolute pidl item to the lookin combo box
2111 * returns the index of the inserted item
2113 static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId)
2115 LPITEMIDLIST pidlNext;
2116 SHFILEINFOA sfi;
2117 SFOLDER *tmpFolder;
2118 LookInInfos *liInfos;
2120 TRACE("%08x\n", iInsertId);
2122 if(!pidl)
2123 return -1;
2125 if(!(liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr)))
2126 return -1;
2128 tmpFolder = MemAlloc(sizeof(SFOLDER));
2129 tmpFolder->m_iIndent = 0;
2131 /* Calculate the indentation of the item in the lookin*/
2132 pidlNext = pidl;
2133 while( (pidlNext=COMDLG32_PIDL_ILGetNext(pidlNext)) )
2135 tmpFolder->m_iIndent++;
2138 tmpFolder->pidlItem = COMDLG32_PIDL_ILClone(pidl); /* FIXME: memory leak*/
2140 if(tmpFolder->m_iIndent > liInfos->iMaxIndentation)
2141 liInfos->iMaxIndentation = tmpFolder->m_iIndent;
2143 sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
2144 SHGetFileInfoA((LPSTR)pidl,
2146 &sfi,
2147 sizeof(sfi),
2148 SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX
2149 | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED);
2151 TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes);
2153 if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM))
2155 int iItemID;
2157 TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent);
2159 /* Add the item at the end of the list */
2160 if(iInsertId < 0)
2162 iItemID = CBAddString(hwnd,sfi.szDisplayName);
2164 /* Insert the item at the iInsertId position*/
2165 else
2167 iItemID = CBInsertString(hwnd,sfi.szDisplayName,iInsertId);
2170 CBSetItemDataPtr(hwnd,iItemID,tmpFolder);
2171 return iItemID;
2174 MemFree( tmpFolder );
2175 return -1;
2179 /***********************************************************************
2180 * FILEDLG95_LOOKIN_InsertItemAfterParent
2182 * Insert an item below its parent
2184 static int FILEDLG95_LOOKIN_InsertItemAfterParent(HWND hwnd,LPITEMIDLIST pidl)
2187 LPITEMIDLIST pidlParent = GetParentPidl(pidl);
2188 int iParentPos;
2190 TRACE("\n");
2192 iParentPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidlParent,SEARCH_PIDL);
2194 if(iParentPos < 0)
2196 iParentPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidlParent);
2199 /* Free pidlParent memory */
2200 COMDLG32_SHFree((LPVOID)pidlParent);
2202 return FILEDLG95_LOOKIN_AddItem(hwnd,pidl,iParentPos + 1);
2205 /***********************************************************************
2206 * FILEDLG95_LOOKIN_SelectItem
2208 * Adds an absolute pidl item to the lookin combo box
2209 * returns the index of the inserted item
2211 int FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl)
2213 int iItemPos;
2214 LookInInfos *liInfos;
2216 TRACE("\n");
2218 iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)pidl,SEARCH_PIDL);
2220 liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2222 if(iItemPos < 0)
2224 while(FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd) > -1);
2225 iItemPos = FILEDLG95_LOOKIN_InsertItemAfterParent(hwnd,pidl);
2228 else
2230 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2231 while(liInfos->iMaxIndentation > tmpFolder->m_iIndent)
2233 int iRemovedItem;
2235 if(-1 == (iRemovedItem = FILEDLG95_LOOKIN_RemoveMostExpandedItem(hwnd)))
2236 break;
2237 if(iRemovedItem < iItemPos)
2238 iItemPos--;
2242 CBSetCurSel(hwnd,iItemPos);
2243 liInfos->uSelectedItem = iItemPos;
2245 return 0;
2249 /***********************************************************************
2250 * FILEDLG95_LOOKIN_RemoveMostExpandedItem
2252 * Remove the item with an expansion level over iExpansionLevel
2254 static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd)
2256 int iItemPos;
2258 LookInInfos *liInfos = (LookInInfos *)GetPropA(hwnd,LookInInfosStr);
2260 TRACE("\n");
2262 if(liInfos->iMaxIndentation <= 2)
2263 return -1;
2265 if((iItemPos = FILEDLG95_LOOKIN_SearchItem(hwnd,(WPARAM)liInfos->iMaxIndentation,SEARCH_EXP)) >=0)
2267 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,iItemPos);
2268 COMDLG32_SHFree(tmpFolder->pidlItem);
2269 MemFree(tmpFolder);
2270 CBDeleteString(hwnd,iItemPos);
2271 liInfos->iMaxIndentation--;
2273 return iItemPos;
2276 return -1;
2279 /***********************************************************************
2280 * FILEDLG95_LOOKIN_SearchItem
2282 * Search for pidl in the lookin combo box
2283 * returns the index of the found item
2285 static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMethod)
2287 int i = 0;
2288 int iCount = CBGetCount(hwnd);
2290 TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod);
2292 if (iCount != CB_ERR)
2294 for(;i<iCount;i++)
2296 LPSFOLDER tmpFolder = (LPSFOLDER) CBGetItemDataPtr(hwnd,i);
2298 if(iSearchMethod == SEARCH_PIDL && COMDLG32_PIDL_ILIsEqual((LPITEMIDLIST)searchArg,tmpFolder->pidlItem))
2299 return i;
2300 if(iSearchMethod == SEARCH_EXP && tmpFolder->m_iIndent == (int)searchArg)
2301 return i;
2305 return -1;
2308 /***********************************************************************
2309 * FILEDLG95_LOOKIN_Clean
2311 * Clean the memory used by the lookin combo box
2313 static void FILEDLG95_LOOKIN_Clean(HWND hwnd)
2315 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2316 int iPos;
2317 int iCount = CBGetCount(fodInfos->DlgInfos.hwndLookInCB);
2319 TRACE("\n");
2321 /* Delete each string of the combo and their associated data */
2322 if (iCount != CB_ERR)
2324 for(iPos = iCount-1;iPos>=0;iPos--)
2326 SFOLDER *tmpFolder = (LPSFOLDER) CBGetItemDataPtr(fodInfos->DlgInfos.hwndLookInCB,iPos);
2327 COMDLG32_SHFree(tmpFolder->pidlItem);
2328 MemFree(tmpFolder);
2329 CBDeleteString(fodInfos->DlgInfos.hwndLookInCB,iPos);
2333 /* LookInInfos structure */
2334 RemovePropA(fodInfos->DlgInfos.hwndLookInCB,LookInInfosStr);
2337 /***********************************************************************
2338 * FILEDLG95_FILENAME_FillFromSelection
2340 * fills the edit box from the cached DataObject
2342 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
2344 FileOpenDlgInfos *fodInfos;
2345 LPITEMIDLIST pidl;
2346 UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0;
2347 char lpstrTemp[MAX_PATH];
2348 LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL;
2350 TRACE("\n");
2351 fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2353 /* Count how many files we have */
2354 nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
2356 /* calculate the string length, count files */
2357 if (nFileSelected >= 1)
2359 nLength += 3; /* first and last quotes, trailing \0 */
2360 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2362 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2364 if (pidl)
2366 /* get the total length of the selected file names*/
2367 lpstrTemp[0] = '\0';
2368 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2370 if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */
2372 nLength += strlen( lpstrTemp ) + 3;
2373 nFiles++;
2375 COMDLG32_SHFree( pidl );
2380 /* allocate the buffer */
2381 if (nFiles <= 1) nLength = MAX_PATH;
2382 lpstrAllFile = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength);
2383 lpstrAllFile[0] = '\0';
2385 /* Generate the string for the edit control */
2386 if(nFiles >= 1)
2388 lpstrCurrFile = lpstrAllFile;
2389 for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
2391 pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
2393 if (pidl)
2395 /* get the file name */
2396 lpstrTemp[0] = '\0';
2397 GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER, lpstrTemp );
2399 if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
2401 if ( nFiles > 1)
2403 *lpstrCurrFile++ = '\"';
2404 strcpy( lpstrCurrFile, lpstrTemp );
2405 lpstrCurrFile += strlen( lpstrTemp );
2406 strcpy( lpstrCurrFile, "\" " );
2407 lpstrCurrFile += 2;
2409 else
2411 strcpy( lpstrAllFile, lpstrTemp );
2414 COMDLG32_SHFree( (LPVOID) pidl );
2419 SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
2420 HeapFree(GetProcessHeap(),0, lpstrAllFile );
2424 /* copied from shell32 to avoid linking to it */
2425 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)
2427 switch (src->uType)
2429 case STRRET_WSTR:
2430 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
2431 COMDLG32_SHFree(src->u.pOleStr);
2432 break;
2434 case STRRET_CSTRA:
2435 lstrcpynA((LPSTR)dest, src->u.cStr, len);
2436 break;
2438 case STRRET_OFFSETA:
2439 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
2440 break;
2442 default:
2443 FIXME("unknown type!\n");
2444 if (len)
2446 *(LPSTR)dest = '\0';
2448 return(FALSE);
2450 return S_OK;
2453 /***********************************************************************
2454 * FILEDLG95_FILENAME_GetFileNames
2456 * copies the filenames to a 0-delimited string list (A\0B\0C\0\0)
2458 int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPSTR * lpstrFileList, UINT * sizeUsed)
2460 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2461 UINT nStrCharCount = 0; /* index in src buffer */
2462 UINT nFileIndex = 0; /* index in dest buffer */
2463 UINT nFileCount = 0; /* number of files */
2464 UINT nStrLen = 0; /* length of string in edit control */
2465 LPSTR lpstrEdit; /* buffer for string from edit control */
2467 TRACE("\n");
2469 /* get the filenames from the edit control */
2470 nStrLen = SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0);
2471 lpstrEdit = MemAlloc(nStrLen+1);
2472 GetDlgItemTextA(hwnd, IDC_FILENAME, lpstrEdit, nStrLen+1);
2474 TRACE("nStrLen=%u str=%s\n", nStrLen, lpstrEdit);
2476 /* we might get single filename without any '"',
2477 * so we need nStrLen + terminating \0 + end-of-list \0 */
2478 *lpstrFileList = MemAlloc(nStrLen+2);
2479 *sizeUsed = 0;
2481 /* build 0-delimited file list from filenames */
2482 while ( nStrCharCount <= nStrLen )
2484 if ( lpstrEdit[nStrCharCount]=='"' )
2486 nStrCharCount++;
2487 while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen))
2489 (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount];
2490 (*sizeUsed)++;
2491 nStrCharCount++;
2493 (*lpstrFileList)[nFileIndex++] = '\0';
2494 (*sizeUsed)++;
2495 nFileCount++;
2497 nStrCharCount++;
2500 /* single, unquoted string */
2501 if ((nStrLen > 0) && (*sizeUsed == 0) )
2503 strcpy(*lpstrFileList, lpstrEdit);
2504 nFileIndex = strlen(lpstrEdit) + 1;
2505 (*sizeUsed) = nFileIndex;
2506 nFileCount = 1;
2509 /* trailing \0 */
2510 (*lpstrFileList)[nFileIndex] = '\0';
2511 (*sizeUsed)++;
2513 MemFree(lpstrEdit);
2514 return nFileCount;
2517 #define SETDefFormatEtc(fe,cf,med) \
2519 (fe).cfFormat = cf;\
2520 (fe).dwAspect = DVASPECT_CONTENT; \
2521 (fe).ptd =NULL;\
2522 (fe).tymed = med;\
2523 (fe).lindex = -1;\
2527 * DATAOBJECT Helper functions
2530 /***********************************************************************
2531 * COMCTL32_ReleaseStgMedium
2533 * like ReleaseStgMedium from ole32
2535 static void COMCTL32_ReleaseStgMedium (STGMEDIUM medium)
2537 if(medium.pUnkForRelease)
2539 IUnknown_Release(medium.pUnkForRelease);
2541 else
2543 GlobalUnlock(medium.u.hGlobal);
2544 GlobalFree(medium.u.hGlobal);
2548 /***********************************************************************
2549 * GetPidlFromDataObject
2551 * Return pidl(s) by number from the cached DataObject
2553 * nPidlIndex=0 gets the fully qualified root path
2555 LPITEMIDLIST GetPidlFromDataObject ( IDataObject *doSelected, UINT nPidlIndex)
2558 STGMEDIUM medium;
2559 FORMATETC formatetc;
2560 LPITEMIDLIST pidl = NULL;
2562 TRACE("sv=%p index=%u\n", doSelected, nPidlIndex);
2564 /* Set the FORMATETC structure*/
2565 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2567 /* Get the pidls from IDataObject */
2568 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2570 LPIDA cida = GlobalLock(medium.u.hGlobal);
2571 if(nPidlIndex <= cida->cidl)
2573 pidl = COMDLG32_PIDL_ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[nPidlIndex]]));
2575 COMCTL32_ReleaseStgMedium(medium);
2577 return pidl;
2580 /***********************************************************************
2581 * GetNumSelected
2583 * Return the number of selected items in the DataObject.
2586 UINT GetNumSelected( IDataObject *doSelected )
2588 UINT retVal = 0;
2589 STGMEDIUM medium;
2590 FORMATETC formatetc;
2592 TRACE("sv=%p\n", doSelected);
2594 if (!doSelected) return 0;
2596 /* Set the FORMATETC structure*/
2597 SETDefFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
2599 /* Get the pidls from IDataObject */
2600 if(SUCCEEDED(IDataObject_GetData(doSelected,&formatetc,&medium)))
2602 LPIDA cida = GlobalLock(medium.u.hGlobal);
2603 retVal = cida->cidl;
2604 COMCTL32_ReleaseStgMedium(medium);
2605 return retVal;
2607 return 0;
2611 * TOOLS
2614 /***********************************************************************
2615 * GetName
2617 * Get the pidl's display name (relative to folder) and
2618 * put it in lpstrFileName.
2620 * Return NOERROR on success,
2621 * E_FAIL otherwise
2624 HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)
2626 STRRET str;
2627 HRESULT hRes;
2629 TRACE("sf=%p pidl=%p\n", lpsf, pidl);
2631 if(!lpsf)
2633 HRESULT hRes;
2634 SHGetDesktopFolder(&lpsf);
2635 hRes = GetName(lpsf,pidl,dwFlags,lpstrFileName);
2636 IShellFolder_Release(lpsf);
2637 return hRes;
2640 /* Get the display name of the pidl relative to the folder */
2641 if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str)))
2643 return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl);
2645 return E_FAIL;
2648 /***********************************************************************
2649 * GetShellFolderFromPidl
2651 * pidlRel is the item pidl relative
2652 * Return the IShellFolder of the absolute pidl
2654 IShellFolder *GetShellFolderFromPidl(LPITEMIDLIST pidlAbs)
2656 IShellFolder *psf = NULL,*psfParent;
2658 TRACE("%p\n", pidlAbs);
2660 if(SUCCEEDED(SHGetDesktopFolder(&psfParent)))
2662 psf = psfParent;
2663 if(pidlAbs && pidlAbs->mkid.cb)
2665 if(SUCCEEDED(IShellFolder_BindToObject(psfParent, pidlAbs, NULL, &IID_IShellFolder, (LPVOID*)&psf)))
2667 IShellFolder_Release(psfParent);
2668 return psf;
2671 /* return the desktop */
2672 return psfParent;
2674 return NULL;
2677 /***********************************************************************
2678 * GetParentPidl
2680 * Return the LPITEMIDLIST to the parent of the pidl in the list
2682 LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl)
2684 LPITEMIDLIST pidlParent;
2686 TRACE("%p\n", pidl);
2688 pidlParent = COMDLG32_PIDL_ILClone(pidl);
2689 COMDLG32_PIDL_ILRemoveLastID(pidlParent);
2691 return pidlParent;
2694 /***********************************************************************
2695 * GetPidlFromName
2697 * returns the pidl of the file name relative to folder
2698 * NULL if an error occurred
2700 LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPCSTR lpcstrFileName)
2702 LPITEMIDLIST pidl;
2703 ULONG ulEaten;
2704 WCHAR lpwstrDirName[MAX_PATH];
2706 TRACE("sf=%p file=%s\n", lpsf, lpcstrFileName);
2708 if(!lpcstrFileName) return NULL;
2709 if(!*lpcstrFileName) return NULL;
2711 MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpcstrFileName,-1,(LPWSTR)lpwstrDirName,MAX_PATH);
2713 if(!lpsf)
2715 SHGetDesktopFolder(&lpsf);
2716 pidl = GetPidlFromName(lpsf, lpcstrFileName);
2717 IShellFolder_Release(lpsf);
2719 else
2721 IShellFolder_ParseDisplayName(lpsf, 0, NULL, (LPWSTR)lpwstrDirName, &ulEaten, &pidl, NULL);
2723 return pidl;
2728 BOOL IsPidlFolder (LPSHELLFOLDER psf, LPITEMIDLIST pidl)
2730 ULONG uAttr = SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
2731 HRESULT ret;
2733 TRACE("%p, %p\n", psf, pidl);
2735 ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr );
2737 TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret);
2738 /* see documentation shell 4.1*/
2739 return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER);
2742 /***********************************************************************
2743 * BrowseSelectedFolder
2745 static BOOL BrowseSelectedFolder(HWND hwnd)
2747 BOOL bBrowseSelFolder = FALSE;
2748 FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);
2750 TRACE("\n");
2752 if (GetNumSelected(fodInfos->Shell.FOIDataObject) == 1)
2754 LPITEMIDLIST pidlSelection;
2756 /* get the file selected */
2757 pidlSelection = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, 1);
2758 if (IsPidlFolder (fodInfos->Shell.FOIShellFolder, pidlSelection))
2760 if ( FAILED( IShellBrowser_BrowseObject( fodInfos->Shell.FOIShellBrowser,
2761 pidlSelection, SBSP_RELATIVE ) ) )
2763 MessageBoxA( hwnd, "Path does not exist", fodInfos->ofnInfos->lpstrTitle,
2764 MB_OK | MB_ICONEXCLAMATION );
2767 bBrowseSelFolder = TRUE;
2769 COMDLG32_SHFree( pidlSelection );
2772 return bBrowseSelFolder;
2776 * Memory allocation methods */
2777 static void *MemAlloc(UINT size)
2779 return HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
2782 static void MemFree(void *mem)
2784 if(mem)
2786 HeapFree(GetProcessHeap(),0,mem);