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