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