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