4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 /* for read_directory_unix() */
30 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
45 #define _MAX_FNAME 256
46 #define _MAX_DIR _MAX_FNAME
47 #define _MAX_EXT _MAX_FNAME
51 #ifdef NONAMELESSUNION
52 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
54 #define UNION_MEMBER(x) x
59 #define DEFAULT_SPLIT_POS 300
61 #define DEFAULT_SPLIT_POS 200
73 typedef struct _Entry {
84 #ifndef _NO_EXTENSIONS
85 BY_HANDLE_FILE_INFORMATION bhfi;
87 enum ENTRY_TYPE etype;
99 TCHAR volname[_MAX_FNAME];
109 COL_ATTRIBUTES = 0x08,
111 #ifdef _NO_EXTENSIONS
112 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
116 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
129 #ifndef _NO_EXTENSIONS
133 #ifndef _NO_EXTENSIONS
139 int positions[COLUMNS+1];
151 int focus_pane; /* 0: left 1: right */
154 BOOL header_wdths_ok;
156 TCHAR path[MAX_PATH];
157 TCHAR filter_pattern[MAX_PATH];
161 SORT_ORDER sortOrder;
166 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
167 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
168 static void refresh_child(ChildWnd* child);
169 static void refresh_drives();
170 static void get_path(Entry* dir, PTSTR path);
171 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
173 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
174 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
175 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
179 WINEFILE_GLOBALS Globals;
181 static int last_split;
183 /* some common string constants */
184 const static TCHAR sEmpty[] = {'\0'};
185 const static TCHAR sSpace[] = {' ', '\0'};
186 const static TCHAR sNumFmt[] = {'%','d','\0'};
187 const static TCHAR sQMarks[] = {'?','?','?','\0'};
189 /* window class names */
190 const static TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
191 const static TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
194 /* #define LONGLONGARG _T("I64") */
195 const static TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
196 const static TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
198 /* #define LONGLONGARG _T("L") */
199 const static TCHAR sLongHexFmt[] = {'%','L','X','\0'};
200 const static TCHAR sLongNumFmt[] = {'%','L','d','\0'};
204 /* load resource string */
205 static LPTSTR load_string(LPTSTR buffer, UINT id)
207 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
212 #define RS(b, i) load_string(b, i)
215 /* display error message for the specified WIN32 error code */
216 static void display_error(HWND hwnd, DWORD error)
218 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
221 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
222 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
223 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
225 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
231 /* display network error message using WNetGetLastError() */
232 static void display_network_error(HWND hwnd)
234 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
237 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
238 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
242 /* allocate and initialise a directory entry */
243 static Entry* alloc_entry()
245 Entry* entry = (Entry*) malloc(sizeof(Entry));
247 #ifdef _SHELL_FOLDERS
249 entry->folder = NULL;
256 /* free a directory entry */
257 static void free_entry(Entry* entry)
259 #ifdef _SHELL_FOLDERS
260 if (entry->hicon && entry->hicon!=(HICON)-1)
261 DestroyIcon(entry->hicon);
263 if (entry->folder && entry->folder!=Globals.iDesktop)
264 (*entry->folder->lpVtbl->Release)(entry->folder);
267 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
273 /* recursively free all child entries */
274 static void free_entries(Entry* dir)
276 Entry *entry, *next=dir->down;
292 static void read_directory_win(Entry* dir, LPCTSTR path)
294 Entry* first_entry = NULL;
298 int level = dir->level + 1;
299 WIN32_FIND_DATA w32fd;
301 #ifndef _NO_EXTENSIONS
305 TCHAR buffer[MAX_PATH], *p;
306 for(p=buffer; *path; )
313 hFind = FindFirstFile(buffer, &w32fd);
315 if (hFind != INVALID_HANDLE_VALUE) {
317 #ifdef _NO_EXTENSIONS
318 /* hide directory entry "." */
319 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
320 LPCTSTR name = w32fd.cFileName;
322 if (name[0]=='.' && name[1]=='\0')
326 entry = alloc_entry();
334 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
337 entry->expanded = FALSE;
338 entry->scanned = FALSE;
339 entry->level = level;
341 #ifndef _NO_EXTENSIONS
342 entry->etype = ET_WINDOWS;
343 entry->bhfi_valid = FALSE;
345 lstrcpy(p, entry->data.cFileName);
347 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
348 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
350 if (hFile != INVALID_HANDLE_VALUE) {
351 if (GetFileInformationByHandle(hFile, &entry->bhfi))
352 entry->bhfi_valid = TRUE;
359 } while(FindNextFile(hFind, &w32fd));
367 dir->down = first_entry;
372 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
376 for(entry=dir->down; entry; entry=entry->next) {
378 LPCTSTR q = entry->data.cFileName;
381 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
383 } while(tolower(*p++) == tolower(*q++));
386 q = entry->data.cAlternateFileName;
389 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
391 } while(tolower(*p++) == tolower(*q++));
398 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
400 TCHAR buffer[MAX_PATH];
401 Entry* entry = &root->entry;
405 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
407 #ifndef _NO_EXTENSIONS
408 entry->etype = ET_WINDOWS;
412 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
415 while(*s==TEXT('\\') || *s==TEXT('/'))
421 read_directory(entry, buffer, sortOrder, hwnd);
424 entry->expanded = TRUE;
429 entry = find_entry_win(entry, s);
432 SetCursor(old_cursor);
438 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
440 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
442 struct tm* tm = gmtime(t);
448 stime.wYear = tm->tm_year+1900;
449 stime.wMonth = tm->tm_mon+1;
450 /* stime.wDayOfWeek */
451 stime.wDay = tm->tm_mday;
452 stime.wHour = tm->tm_hour;
453 stime.wMinute = tm->tm_min;
454 stime.wSecond = tm->tm_sec;
456 return SystemTimeToFileTime(&stime, ftime);
459 static void read_directory_unix(Entry* dir, LPCTSTR path)
461 Entry* first_entry = NULL;
465 int level = dir->level + 1;
467 DIR* pdir = opendir(path);
472 TCHAR buffer[MAX_PATH], *p;
474 for(p=buffer; *path; )
477 if (p==buffer || p[-1]!='/')
480 while((ent=readdir(pdir))) {
481 entry = alloc_entry();
489 entry->etype = ET_UNIX;
491 lstrcpy(entry->data.cFileName, ent->d_name);
492 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
494 strcpy(p, ent->d_name);
496 if (!stat(buffer, &st)) {
497 if (S_ISDIR(st.st_mode))
498 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
500 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
501 entry->data.nFileSizeHigh = st.st_size >> 32;
503 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
504 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
505 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
507 entry->bhfi.nFileIndexLow = ent->d_ino;
508 entry->bhfi.nFileIndexHigh = 0;
510 entry->bhfi.nNumberOfLinks = st.st_nlink;
512 entry->bhfi_valid = TRUE;
514 entry->data.nFileSizeLow = 0;
515 entry->data.nFileSizeHigh = 0;
516 entry->bhfi_valid = FALSE;
521 entry->expanded = FALSE;
522 entry->scanned = FALSE;
523 entry->level = level;
534 dir->down = first_entry;
538 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
542 for(entry=dir->down; entry; entry=entry->next) {
544 LPCTSTR q = entry->data.cFileName;
547 if (!*p || *p==TEXT('/'))
549 } while(*p++ == *q++);
555 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
557 TCHAR buffer[MAX_PATH];
558 Entry* entry = &root->entry;
562 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
564 entry->etype = ET_UNIX;
567 while(*s && *s!=TEXT('/'))
570 while(*s == TEXT('/'))
576 read_directory(entry, buffer, sortOrder, hwnd);
579 entry->expanded = TRUE;
584 entry = find_entry_unix(entry, s);
587 SetCursor(old_cursor);
592 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
595 #ifdef _SHELL_FOLDERS
598 #define tcscpyn strcpyn
599 #define get_strret get_strretW
600 #define path_from_pidl path_from_pidlW
602 #define tcscpyn wcscpyn
603 #define get_strret get_strretA
604 #define path_from_pidl path_from_pidlA
608 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
613 for(s=source; count&&(*d++=*s++); )
619 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
624 for(s=source; count&&(*d++=*s++); )
631 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
635 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
639 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
643 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
647 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
651 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
655 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
659 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
664 static void free_strret(STRRET* str)
666 if (str->uType == STRRET_WSTR)
667 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
671 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
675 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
678 get_strret(&str, &pidl->mkid, buffer, len);
687 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
691 /* SHGDN_FORPARSING: get full path of id list */
692 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
695 get_strretA(&str, &pidl->mkid, buffer, len);
703 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
707 /* SHGDN_FORPARSING: get full path of id list */
708 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
711 get_strretW(&str, &pidl->mkid, buffer, len);
720 /* create an item id list from a file system path */
722 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
729 LPWSTR buffer = path;
731 WCHAR buffer[MAX_PATH];
732 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
735 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
743 /* convert an item id list from relative to absolute (=relative to the desktop) format */
745 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
747 if (entry->up && entry->up->etype==ET_SHELL) {
748 IShellFolder* folder = entry->up->folder;
749 WCHAR buffer[MAX_PATH];
751 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
757 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
762 } else if (entry->etype == ET_WINDOWS) {
763 TCHAR path[MAX_PATH];
765 get_path(entry, path);
767 return get_path_pidl(path, hwnd);
768 } else if (entry->pidl)
769 return ILClone(entry->pidl);
775 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
777 IExtractIcon* pExtract;
779 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
780 TCHAR path[_MAX_PATH];
785 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
786 if (!(flags & GIL_NOTFILENAME)) {
788 idx = 0; /* special case for some control panel applications */
790 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
791 flags &= ~GIL_DONTCACHE;
793 HICON hIconLarge = 0;
795 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
798 DestroyIcon(hIconLarge);
809 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
813 for(entry=dir->down; entry; entry=entry->next) {
814 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
815 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
822 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
824 Entry* entry = &root->entry;
826 LPITEMIDLIST next_pidl = pidl;
827 IShellFolder* folder;
828 IShellFolder* child = NULL;
831 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
833 #ifndef _NO_EXTENSIONS
834 entry->etype = ET_SHELL;
837 folder = Globals.iDesktop;
840 entry->pidl = next_pidl;
841 entry->folder = folder;
846 /* copy first element of item idlist */
847 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
848 memcpy(next_pidl, pidl, pidl->mkid.cb);
849 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
851 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
855 read_directory(entry, NULL, sortOrder, hwnd);
858 entry->expanded = TRUE;
860 next = find_entry_shell(entry, next_pidl);
867 /* go to next element */
868 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
871 SetCursor(old_cursor);
877 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
879 if (!(attribs & SFGAO_FILESYSTEM) ||
880 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
881 WIN32_FILE_ATTRIBUTE_DATA fad;
882 IDataObject* pDataObj;
884 STGMEDIUM medium = {0, {0}, 0};
885 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
887 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
890 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
892 (*pDataObj->lpVtbl->Release)(pDataObj);
895 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
896 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
898 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
899 w32fdata->dwFileAttributes = fad.dwFileAttributes;
900 w32fdata->ftCreationTime = fad.ftCreationTime;
901 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
902 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
904 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
905 w32fdata->nFileSizeLow = fad.nFileSizeLow;
906 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
910 SetErrorMode(sem_org);
912 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
913 GlobalFree(medium.UNION_MEMBER(hGlobal));
918 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
919 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
921 if (attribs & SFGAO_READONLY)
922 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
924 if (attribs & SFGAO_COMPRESSED)
925 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
929 static void read_directory_shell(Entry* dir, HWND hwnd)
931 IShellFolder* folder = dir->folder;
932 int level = dir->level + 1;
938 Entry* first_entry = NULL;
945 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
949 #define FETCH_ITEM_COUNT 32
950 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
955 memset(pidls, 0, sizeof(pidls));
957 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
964 for(n=0; n<cnt; ++n) {
965 entry = alloc_entry();
973 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
974 entry->bhfi_valid = FALSE;
976 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
978 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
981 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
982 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
984 entry->bhfi_valid = TRUE;
990 entry->pidl = pidls[n];
992 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
993 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
996 entry->folder = child;
998 entry->folder = NULL;
1001 entry->folder = NULL;
1003 if (!entry->data.cFileName[0])
1004 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1006 /* get display icons for files and virtual objects */
1007 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1008 !(attribs & SFGAO_FILESYSTEM)) {
1009 entry->hicon = extract_icon(folder, pidls[n]);
1012 entry->hicon = (HICON)-1; /* don't try again later */
1017 entry->expanded = FALSE;
1018 entry->scanned = FALSE;
1019 entry->level = level;
1021 #ifndef _NO_EXTENSIONS
1022 entry->etype = ET_SHELL;
1023 entry->bhfi_valid = FALSE;
1030 (*idlist->lpVtbl->Release)(idlist);
1036 dir->down = first_entry;
1037 dir->scanned = TRUE;
1040 #endif /* _SHELL_FOLDERS */
1043 /* sort order for different directory/file types */
1052 /* distinguish between ".", ".." and any other directory names */
1053 static int TypeOrderFromDirname(LPCTSTR name)
1055 if (name[0] == '.') {
1056 if (name[1] == '\0')
1057 return TO_DOT; /* "." */
1059 if (name[1]=='.' && name[2]=='\0')
1060 return TO_DOTDOT; /* ".." */
1063 return TO_OTHER_DIR; /* anything else */
1066 /* directories first... */
1067 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1069 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1070 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1072 /* Handle "." and ".." as special case and move them at the very first beginning. */
1073 if (order1==TO_DIR && order2==TO_DIR) {
1074 order1 = TypeOrderFromDirname(fd1->cFileName);
1075 order2 = TypeOrderFromDirname(fd2->cFileName);
1078 return order2==order1? 0: order1<order2? -1: 1;
1082 static int compareName(const void* arg1, const void* arg2)
1084 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1085 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1087 int cmp = compareType(fd1, fd2);
1091 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1094 static int compareExt(const void* arg1, const void* arg2)
1096 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1097 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1098 const TCHAR *name1, *name2, *ext1, *ext2;
1100 int cmp = compareType(fd1, fd2);
1104 name1 = fd1->cFileName;
1105 name2 = fd2->cFileName;
1107 ext1 = _tcsrchr(name1, TEXT('.'));
1108 ext2 = _tcsrchr(name2, TEXT('.'));
1120 cmp = lstrcmpi(ext1, ext2);
1124 return lstrcmpi(name1, name2);
1127 static int compareSize(const void* arg1, const void* arg2)
1129 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1130 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1132 int cmp = compareType(fd1, fd2);
1136 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1143 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1145 return cmp<0? -1: cmp>0? 1: 0;
1148 static int compareDate(const void* arg1, const void* arg2)
1150 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1151 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1153 int cmp = compareType(fd1, fd2);
1157 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1161 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1162 compareName, /* SORT_NAME */
1163 compareExt, /* SORT_EXT */
1164 compareSize, /* SORT_SIZE */
1165 compareDate /* SORT_DATE */
1169 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1171 Entry* entry = dir->down;
1176 for(entry=dir->down; entry; entry=entry->next)
1180 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1183 for(entry=dir->down; entry; entry=entry->next)
1186 /* call qsort with the appropriate compare function */
1187 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1189 dir->down = array[0];
1191 for(p=array; --len; p++)
1196 HeapFree(GetProcessHeap(), 0, array);
1201 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1203 TCHAR buffer[MAX_PATH];
1208 #ifdef _SHELL_FOLDERS
1209 if (dir->etype == ET_SHELL)
1211 read_directory_shell(dir, hwnd);
1213 if (Globals.prescan_node) {
1222 for(entry=dir->down; entry; entry=entry->next)
1223 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1224 read_directory_shell(entry, hwnd);
1225 SortDirectory(entry, sortOrder);
1231 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1232 if (dir->etype == ET_UNIX)
1234 read_directory_unix(dir, path);
1236 if (Globals.prescan_node) {
1245 for(entry=dir->down; entry; entry=entry->next)
1246 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1247 lstrcpy(d, entry->data.cFileName);
1248 read_directory_unix(entry, buffer);
1249 SortDirectory(entry, sortOrder);
1256 read_directory_win(dir, path);
1258 if (Globals.prescan_node) {
1267 for(entry=dir->down; entry; entry=entry->next)
1268 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1269 lstrcpy(d, entry->data.cFileName);
1270 read_directory_win(entry, buffer);
1271 SortDirectory(entry, sortOrder);
1276 SortDirectory(dir, sortOrder);
1280 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1282 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1283 const static TCHAR sSlash[] = {'/', '\0'};
1285 const static TCHAR sBackslash[] = {'\\', '\0'};
1287 #ifdef _SHELL_FOLDERS
1290 /* read shell namespace tree */
1291 root->drive_type = DRIVE_UNKNOWN;
1294 load_string(root->volname, IDS_DESKTOP);
1296 load_string(root->fs, IDS_SHELL);
1298 return read_tree_shell(root, pidl, sortOrder, hwnd);
1302 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1305 /* read unix file system tree */
1306 root->drive_type = GetDriveType(path);
1308 lstrcat(drv, sSlash);
1309 load_string(root->volname, IDS_ROOT_FS);
1311 load_string(root->fs, IDS_UNIXFS);
1313 lstrcpy(root->path, sSlash);
1315 return read_tree_unix(root, path, sortOrder, hwnd);
1319 /* read WIN32 file system tree */
1320 root->drive_type = GetDriveType(path);
1322 lstrcat(drv, sBackslash);
1323 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1325 lstrcpy(root->path, drv);
1327 return read_tree_win(root, path, sortOrder, hwnd);
1331 /* flags to filter different file types */
1333 TF_DIRECTORIES = 0x01,
1335 TF_DOCUMENTS = 0x04,
1342 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1344 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1345 TCHAR b1[BUFFER_LEN];
1346 const static TCHAR sAsterics[] = {'*', '\0'};
1348 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1349 Root* root = &child->root;
1352 memset(child, 0, sizeof(ChildWnd));
1354 child->left.treePane = TRUE;
1355 child->left.visible_cols = 0;
1357 child->right.treePane = FALSE;
1358 #ifndef _NO_EXTENSIONS
1359 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1361 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1364 child->pos.length = sizeof(WINDOWPLACEMENT);
1365 child->pos.flags = 0;
1366 child->pos.showCmd = SW_SHOWNORMAL;
1367 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1368 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1369 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1370 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1372 child->focus_pane = 0;
1373 child->split_pos = DEFAULT_SPLIT_POS;
1374 child->sortOrder = SORT_NAME;
1375 child->header_wdths_ok = FALSE;
1379 lstrcpy(child->path, path);
1381 _tsplitpath(path, drv, dir, name, ext);
1384 _tcscpy(child->filter_pattern, sAsterics);
1385 child->filter_flags = TF_ALL;
1387 root->entry.level = 0;
1389 entry = read_tree(root, path, pidl, drv, child->sortOrder, hwnd);
1391 #ifdef _SHELL_FOLDERS
1392 if (root->entry.etype == ET_SHELL)
1393 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1396 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1398 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1400 child->left.root = &root->entry;
1401 child->right.root = NULL;
1403 set_curdir(child, entry, 0, hwnd);
1409 /* free all memory associated with a child window */
1410 static void free_child_window(ChildWnd* child)
1412 free_entries(&child->root.entry);
1417 /* get full path of specified directory entry */
1418 static void get_path(Entry* dir, PTSTR path)
1424 #ifdef _SHELL_FOLDERS
1425 if (dir->etype == ET_SHELL)
1430 path[0] = TEXT('\0');
1435 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1437 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1438 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1440 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1446 for(entry=dir; entry; level++) {
1452 name = entry->data.cFileName;
1455 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1461 memmove(path+l+1, path, len*sizeof(TCHAR));
1462 memcpy(path+1, name, l*sizeof(TCHAR));
1465 #ifndef _NO_EXTENSIONS
1466 if (entry->etype == ET_UNIX)
1467 path[0] = TEXT('/');
1470 path[0] = TEXT('\\');
1475 memmove(path+l, path, len*sizeof(TCHAR));
1476 memcpy(path, name, l*sizeof(TCHAR));
1483 #ifndef _NO_EXTENSIONS
1484 if (entry->etype == ET_UNIX)
1485 path[len++] = TEXT('/');
1488 path[len++] = TEXT('\\');
1491 path[len] = TEXT('\0');
1496 static void resize_frame_rect(HWND hwnd, PRECT prect)
1501 if (IsWindowVisible(Globals.htoolbar)) {
1502 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1503 GetClientRect(Globals.htoolbar, &rt);
1504 prect->top = rt.bottom+3;
1505 prect->bottom -= rt.bottom+3;
1508 if (IsWindowVisible(Globals.hdrivebar)) {
1509 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1510 GetClientRect(Globals.hdrivebar, &rt);
1511 new_top = --prect->top + rt.bottom+3;
1512 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1513 prect->top = new_top;
1514 prect->bottom -= rt.bottom+2;
1517 if (IsWindowVisible(Globals.hstatusbar)) {
1518 int parts[] = {300, 500};
1520 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1521 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1522 GetClientRect(Globals.hstatusbar, &rt);
1523 prect->bottom -= rt.bottom;
1526 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1529 static void resize_frame(HWND hwnd, int cx, int cy)
1538 resize_frame_rect(hwnd, &rect);
1541 static void resize_frame_client(HWND hwnd)
1545 GetClientRect(hwnd, &rect);
1547 resize_frame_rect(hwnd, &rect);
1551 static HHOOK hcbthook;
1552 static ChildWnd* newchild = NULL;
1554 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1556 if (code==HCBT_CREATEWND && newchild) {
1557 ChildWnd* child = newchild;
1560 child->hwnd = (HWND) wparam;
1561 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1564 return CallNextHookEx(hcbthook, code, wparam, lparam);
1567 static HWND create_child_window(ChildWnd* child)
1569 MDICREATESTRUCT mcs;
1572 mcs.szClass = sWINEFILETREE;
1573 mcs.szTitle = (LPTSTR)child->path;
1574 mcs.hOwner = Globals.hInstance;
1575 mcs.x = child->pos.rcNormalPosition.left;
1576 mcs.y = child->pos.rcNormalPosition.top;
1577 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1578 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1582 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1585 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1587 UnhookWindowsHookEx(hcbthook);
1591 UnhookWindowsHookEx(hcbthook);
1593 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1594 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1596 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
1597 ListBox_SetCurSel(child->left.hwnd, idx);
1603 struct ExecuteDialog {
1604 TCHAR cmd[MAX_PATH];
1608 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1610 static struct ExecuteDialog* dlg;
1614 dlg = (struct ExecuteDialog*) lparam;
1618 int id = (int)wparam;
1621 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1622 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1623 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1624 EndDialog(hwnd, id);
1625 } else if (id == IDCANCEL)
1626 EndDialog(hwnd, id);
1635 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1637 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1641 SetWindowLong(hwnd, GWL_USERDATA, lparam);
1642 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1646 int id = (int)wparam;
1650 LPTSTR dest = (LPTSTR) GetWindowLong(hwnd, GWL_USERDATA);
1651 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1652 EndDialog(hwnd, id);
1656 EndDialog(hwnd, id);
1660 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1672 struct FilterDialog {
1673 TCHAR pattern[MAX_PATH];
1677 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1679 static struct FilterDialog* dlg;
1683 dlg = (struct FilterDialog*) lparam;
1684 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1685 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES), (dlg->flags&TF_DIRECTORIES? BST_CHECKED: BST_UNCHECKED));
1686 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS), dlg->flags&TF_PROGRAMS? BST_CHECKED: BST_UNCHECKED);
1687 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS), dlg->flags&TF_DOCUMENTS? BST_CHECKED: BST_UNCHECKED);
1688 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS), dlg->flags&TF_OTHERS? BST_CHECKED: BST_UNCHECKED);
1689 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN), dlg->flags&TF_HIDDEN? BST_CHECKED: BST_UNCHECKED);
1693 int id = (int)wparam;
1698 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1700 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES))&BST_CHECKED? TF_DIRECTORIES: 0;
1701 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS))&BST_CHECKED? TF_PROGRAMS: 0;
1702 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS))&BST_CHECKED? TF_DOCUMENTS: 0;
1703 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS))&BST_CHECKED? TF_OTHERS: 0;
1704 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN))&BST_CHECKED? TF_HIDDEN: 0;
1708 EndDialog(hwnd, id);
1709 } else if (id == IDCANCEL)
1710 EndDialog(hwnd, id);
1719 struct PropertiesDialog {
1720 TCHAR path[MAX_PATH];
1725 /* Structure used to store enumerated languages and code pages. */
1726 struct LANGANDCODEPAGE {
1731 static LPCSTR InfoStrings[] = {
1747 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1749 int idx = ListBox_GetCurSel(hlbox);
1751 if (idx != LB_ERR) {
1752 LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx);
1755 SetWindowText(hedit, pValue);
1759 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1761 static TCHAR sBackSlash[] = {'\\','\0'};
1762 static TCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1763 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1764 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1765 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1767 if (dwVersionDataLen) {
1768 dlg->pVersionData = malloc(dwVersionDataLen);
1770 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1774 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1775 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1776 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1777 char buffer[BUFFER_LEN];
1779 sprintf(buffer, "%d.%d.%d.%d",
1780 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1781 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1783 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1787 /* Read the list of languages and code pages. */
1788 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1789 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1790 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1792 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1794 /* Read the file description for each language and code page. */
1795 for(; pTranslate<pEnd; ++pTranslate) {
1798 for(p=InfoStrings; *p; ++p) {
1799 TCHAR subblock[200];
1806 LPCSTR pInfoString = *p;
1808 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1810 #define infoStr pInfoString
1812 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1814 /* Retrieve file description for language and code page */
1815 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1816 int idx = ListBox_AddString(hlbox, infoStr);
1817 ListBox_SetItemData(hlbox, idx, pTxt);
1822 ListBox_SetCurSel(hlbox, 0);
1824 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1830 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1832 static struct PropertiesDialog* dlg;
1835 case WM_INITDIALOG: {
1836 const static TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1837 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1838 LPWIN32_FIND_DATA pWFD;
1841 dlg = (struct PropertiesDialog*) lparam;
1842 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
1844 GetWindowText(hwnd, b1, MAX_PATH);
1845 wsprintf(b2, b1, pWFD->cFileName);
1846 SetWindowText(hwnd, b2);
1848 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1849 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1851 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
1852 _stprintf(b1, sLongNumFmt, size);
1853 _stprintf(b2, sByteFmt, b1);
1854 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1856 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1857 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1859 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_READONLY), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY? BST_CHECKED: BST_UNCHECKED));
1860 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_ARCHIVE), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE? BST_CHECKED: BST_UNCHECKED));
1861 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_COMPRESSED), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED? BST_CHECKED: BST_UNCHECKED));
1862 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_HIDDEN), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN? BST_CHECKED: BST_UNCHECKED));
1863 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_SYSTEM), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM? BST_CHECKED: BST_UNCHECKED));
1865 CheckForFileInfo(dlg, hwnd, dlg->path);
1869 int id = (int)wparam;
1871 switch(HIWORD(wparam)) {
1872 case LBN_SELCHANGE: {
1873 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1874 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1879 if (id==IDOK || id==IDCANCEL)
1880 EndDialog(hwnd, id);
1886 free(dlg->pVersionData);
1887 dlg->pVersionData = NULL;
1894 static void show_properties_dlg(Entry* entry, HWND hwnd)
1896 struct PropertiesDialog dlg;
1898 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1899 get_path(entry, dlg.path);
1900 memcpy(&dlg.entry, entry, sizeof(Entry));
1902 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1906 #ifndef _NO_EXTENSIONS
1908 static struct FullScreenParameters {
1918 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1922 if (!IsIconic(hwnd))
1923 GetClientRect(hwnd, prect);
1927 GetWindowPlacement(hwnd, &wp);
1929 prect->left = prect->top = 0;
1930 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1931 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1932 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1933 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1934 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1937 if (IsWindowVisible(Globals.htoolbar)) {
1938 GetClientRect(Globals.htoolbar, &rt);
1939 prect->top += rt.bottom+2;
1942 if (IsWindowVisible(Globals.hdrivebar)) {
1943 GetClientRect(Globals.hdrivebar, &rt);
1944 prect->top += rt.bottom+2;
1947 if (IsWindowVisible(Globals.hstatusbar)) {
1948 GetClientRect(Globals.hstatusbar, &rt);
1949 prect->bottom -= rt.bottom;
1953 static BOOL toggle_fullscreen(HWND hwnd)
1957 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1958 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1959 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1961 Frame_CalcFrameClient(hwnd, &rt);
1962 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1963 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1965 rt.left = g_fullscreen.orgPos.left-rt.left;
1966 rt.top = g_fullscreen.orgPos.top-rt.top;
1967 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1968 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1970 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1972 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1973 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1974 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1976 if (g_fullscreen.wasZoomed)
1977 ShowWindow(hwnd, WS_MAXIMIZE);
1980 return g_fullscreen.mode;
1983 static void fullscreen_move(HWND hwnd)
1986 GetWindowRect(hwnd, &pos);
1988 Frame_CalcFrameClient(hwnd, &rt);
1989 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1990 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1992 rt.left = pos.left-rt.left;
1993 rt.top = pos.top-rt.top;
1994 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1995 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1997 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2003 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2005 BOOL vis = IsWindowVisible(hchild);
2007 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2009 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2011 #ifndef _NO_EXTENSIONS
2012 if (g_fullscreen.mode)
2013 fullscreen_move(hwnd);
2016 resize_frame_client(hwnd);
2019 static BOOL activate_drive_window(LPCTSTR path)
2021 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2024 _tsplitpath(path, drv1, 0, 0, 0);
2026 /* search for a already open window for the same drive */
2027 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2028 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
2031 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2033 if (!lstrcmpi(drv2, drv1)) {
2034 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2036 if (IsMinimized(child_wnd))
2037 ShowWindow(child_wnd, SW_SHOWNORMAL);
2047 static BOOL activate_fs_window(LPCTSTR filesys)
2051 /* search for a already open window of the given file system name */
2052 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2053 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
2056 if (!lstrcmpi(child->root.fs, filesys)) {
2057 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2059 if (IsMinimized(child_wnd))
2060 ShowWindow(child_wnd, SW_SHOWNORMAL);
2070 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2072 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2076 DestroyWindow(hwnd);
2078 /* clear handle variables */
2079 Globals.hMenuFrame = 0;
2080 Globals.hMenuView = 0;
2081 Globals.hMenuOptions = 0;
2082 Globals.hMainWnd = 0;
2083 Globals.hmdiclient = 0;
2084 Globals.hdrivebar = 0;
2088 /* don't exit desktop when closing file manager window */
2089 if (!Globals.hwndParent)
2093 case WM_INITMENUPOPUP: {
2094 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2096 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2101 UINT cmd = LOWORD(wparam);
2102 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2104 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2107 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2108 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2110 LPCTSTR root = Globals.drives;
2113 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2117 if (activate_drive_window(root))
2120 _tsplitpath(root, drv, 0, 0, 0);
2122 if (!SetCurrentDirectory(drv)) {
2123 display_error(hwnd, GetLastError());
2127 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2128 child = alloc_child_window(path, NULL, hwnd);
2130 if (!create_child_window(child))
2132 } else switch(cmd) {
2134 SendMessage(hwnd, WM_CLOSE, 0, 0);
2137 case ID_WINDOW_NEW: {
2138 TCHAR path[MAX_PATH];
2141 GetCurrentDirectory(MAX_PATH, path);
2142 child = alloc_child_window(path, NULL, hwnd);
2144 if (!create_child_window(child))
2152 case ID_WINDOW_CASCADE:
2153 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2156 case ID_WINDOW_TILE_HORZ:
2157 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2160 case ID_WINDOW_TILE_VERT:
2161 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2164 case ID_WINDOW_ARRANGE:
2165 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2168 case ID_SELECT_FONT: {
2169 TCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
2173 HDC hdc = GetDC(hwnd);
2174 chFont.lStructSize = sizeof(CHOOSEFONT);
2175 chFont.hwndOwner = hwnd;
2177 chFont.lpLogFont = &lFont;
2178 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
2179 chFont.rgbColors = RGB(0,0,0);
2180 chFont.lCustData = 0;
2181 chFont.lpfnHook = NULL;
2182 chFont.lpTemplateName = NULL;
2183 chFont.hInstance = Globals.hInstance;
2184 chFont.lpszStyle = NULL;
2185 chFont.nFontType = SIMULATED_FONTTYPE;
2186 chFont.nSizeMin = 0;
2187 chFont.nSizeMax = 24;
2189 if (ChooseFont(&chFont)) {
2192 Globals.hfont = CreateFontIndirect(&lFont);
2193 SelectFont(hdc, Globals.hfont);
2194 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2196 /* change font in all open child windows */
2197 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
2198 ChildWnd* child = (ChildWnd*) GetWindowLong(childWnd, GWL_USERDATA);
2199 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
2200 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
2201 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2202 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2203 InvalidateRect(child->left.hwnd, NULL, TRUE);
2204 InvalidateRect(child->right.hwnd, NULL, TRUE);
2207 else if (CommDlgExtendedError()) {
2208 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
2209 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
2210 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
2213 ReleaseDC(hwnd, hdc);
2217 case ID_VIEW_TOOL_BAR:
2218 toggle_child(hwnd, cmd, Globals.htoolbar);
2221 case ID_VIEW_DRIVE_BAR:
2222 toggle_child(hwnd, cmd, Globals.hdrivebar);
2225 case ID_VIEW_STATUSBAR:
2226 toggle_child(hwnd, cmd, Globals.hstatusbar);
2230 struct ExecuteDialog dlg;
2232 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2234 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2235 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2237 if ((int)hinst <= 32)
2238 display_error(hwnd, GetLastError());
2242 case ID_CONNECT_NETWORK_DRIVE: {
2243 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2244 if (ret == NO_ERROR)
2246 else if (ret != (DWORD)-1) {
2247 if (ret == ERROR_EXTENDED_ERROR)
2248 display_network_error(hwnd);
2250 display_error(hwnd, ret);
2254 case ID_DISCONNECT_NETWORK_DRIVE: {
2255 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2256 if (ret == NO_ERROR)
2258 else if (ret != (DWORD)-1) {
2259 if (ret == ERROR_EXTENDED_ERROR)
2260 display_network_error(hwnd);
2262 display_error(hwnd, ret);
2266 case ID_FORMAT_DISK: {
2267 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2268 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2269 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2270 SetErrorMode(sem_org); /* Put it back the way it was. */
2274 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2277 #ifndef _NO_EXTENSIONS
2278 case ID_VIEW_FULLSCREEN:
2279 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2283 case ID_DRIVE_UNIX_FS: {
2284 TCHAR path[MAX_PATH];
2287 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2290 getcwd(path, MAX_PATH);
2291 child = alloc_child_window(path, NULL, hwnd);
2293 if (!create_child_window(child))
2297 #ifdef _SHELL_FOLDERS
2298 case ID_DRIVE_SHELL_NS: {
2299 TCHAR path[MAX_PATH];
2302 if (activate_fs_window(RS(b1,IDS_SHELL)))
2305 GetCurrentDirectory(MAX_PATH, path);
2306 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2308 if (!create_child_window(child))
2314 /*TODO: There are even more menu items! */
2316 #ifndef _NO_EXTENSIONS
2319 WineLicense(Globals.hMainWnd);
2322 case ID_NO_WARRANTY:
2323 WineWarranty(Globals.hMainWnd);
2328 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2332 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2334 #endif /* _NO_EXTENSIONS */
2337 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2338 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2339 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2340 (cmd<SC_SIZE || cmd>SC_RESTORE))
2341 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2343 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2348 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2349 break; /* do not pass message to DefFrameProc */
2351 #ifndef _NO_EXTENSIONS
2352 case WM_GETMINMAXINFO: {
2353 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2355 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2356 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2359 case FRM_CALC_CLIENT:
2360 frame_get_clientspace(hwnd, (PRECT)lparam);
2362 #endif /* _NO_EXTENSIONS */
2365 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2372 static TCHAR g_pos_names[COLUMNS][20] = {
2376 static const int g_pos_align[] = {
2378 HDF_LEFT, /* Name */
2379 HDF_RIGHT, /* Size */
2380 HDF_LEFT, /* CDate */
2381 #ifndef _NO_EXTENSIONS
2382 HDF_LEFT, /* ADate */
2383 HDF_LEFT, /* MDate */
2384 HDF_LEFT, /* Index */
2385 HDF_CENTER, /* Links */
2387 HDF_CENTER, /* Attributes */
2388 #ifndef _NO_EXTENSIONS
2389 HDF_LEFT /* Security */
2393 static void resize_tree(ChildWnd* child, int cx, int cy)
2395 HDWP hdwp = BeginDeferWindowPos(4);
2403 cx = child->split_pos + SPLIT_WIDTH/2;
2405 #ifndef _NO_EXTENSIONS
2413 Header_Layout(child->left.hwndHeader, &hdl);
2415 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2416 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2417 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2418 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2420 #endif /* _NO_EXTENSIONS */
2422 DeferWindowPos(hdwp, child->left.hwnd, 0, rt.left, rt.top, child->split_pos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2423 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2425 EndDeferWindowPos(hdwp);
2429 #ifndef _NO_EXTENSIONS
2431 static HWND create_header(HWND parent, Pane* pane, int id)
2436 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2437 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2441 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2443 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2445 for(idx=0; idx<COLUMNS; idx++) {
2446 hdi.pszText = g_pos_names[idx];
2447 hdi.fmt = HDF_STRING | g_pos_align[idx];
2448 hdi.cxy = pane->widths[idx];
2449 Header_InsertItem(hwnd, idx, &hdi);
2455 #endif /* _NO_EXTENSIONS */
2458 static void init_output(HWND hwnd)
2460 const static TCHAR s1000[] = {'1','0','0','0','\0'};
2464 HDC hdc = GetDC(hwnd);
2466 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2467 Globals.num_sep = b[1];
2469 Globals.num_sep = TEXT('.');
2471 old_font = SelectFont(hdc, Globals.hfont);
2472 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2473 SelectFont(hdc, old_font);
2474 ReleaseDC(hwnd, hdc);
2477 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2480 /* calculate preferred width for all visible columns */
2482 static BOOL calc_widths(Pane* pane, BOOL anyway)
2484 int col, x, cx, spc=3*Globals.spaceSize.cx;
2485 int entries = ListBox_GetCount(pane->hwnd);
2486 int orgWidths[COLUMNS];
2487 int orgPositions[COLUMNS+1];
2493 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2494 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2497 for(col=0; col<COLUMNS; col++)
2498 pane->widths[col] = 0;
2500 hdc = GetDC(pane->hwnd);
2501 hfontOld = SelectFont(hdc, Globals.hfont);
2503 for(cnt=0; cnt<entries; cnt++) {
2504 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2513 dis.hwndItem = pane->hwnd;
2515 dis.rcItem.left = 0;
2517 dis.rcItem.right = 0;
2518 dis.rcItem.bottom = 0;
2519 /*dis.itemData = 0; */
2521 draw_item(pane, &dis, entry, COLUMNS);
2524 SelectObject(hdc, hfontOld);
2525 ReleaseDC(pane->hwnd, hdc);
2528 for(col=0; col<COLUMNS; col++) {
2529 pane->positions[col] = x;
2530 cx = pane->widths[col];
2535 if (cx < IMAGE_WIDTH)
2538 pane->widths[col] = cx;
2544 pane->positions[COLUMNS] = x;
2546 ListBox_SetHorizontalExtent(pane->hwnd, x);
2549 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2552 /* don't move, if only collapsing an entry */
2553 if (!anyway && pane->widths[0]<orgWidths[0] &&
2554 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2555 pane->widths[0] = orgWidths[0];
2556 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2561 InvalidateRect(pane->hwnd, 0, TRUE);
2567 /* calculate one preferred column width */
2569 static void calc_single_width(Pane* pane, int col)
2573 int entries = ListBox_GetCount(pane->hwnd);
2577 pane->widths[col] = 0;
2579 hdc = GetDC(pane->hwnd);
2580 hfontOld = SelectFont(hdc, Globals.hfont);
2582 for(cnt=0; cnt<entries; cnt++) {
2583 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2591 dis.hwndItem = pane->hwnd;
2593 dis.rcItem.left = 0;
2595 dis.rcItem.right = 0;
2596 dis.rcItem.bottom = 0;
2597 /*dis.itemData = 0; */
2599 draw_item(pane, &dis, entry, col);
2602 SelectObject(hdc, hfontOld);
2603 ReleaseDC(pane->hwnd, hdc);
2605 cx = pane->widths[col];
2608 cx += 3*Globals.spaceSize.cx;
2610 if (cx < IMAGE_WIDTH)
2614 pane->widths[col] = cx;
2616 x = pane->positions[col] + cx;
2618 for(; col<COLUMNS; ) {
2619 pane->positions[++col] = x;
2620 x += pane->widths[col];
2623 ListBox_SetHorizontalExtent(pane->hwnd, x);
2627 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2629 for( ; *str&&*pattern; str++,pattern++) {
2630 if (*pattern == '*') {
2632 while(*pattern == '*');
2638 if (_totupper(*str)==_totupper(*pattern) && pattern_match(str, pattern))
2643 else if (_totupper(*str)!=_totupper(*pattern) && *pattern!='?')
2647 if (*str || *pattern)
2648 if (*pattern!='*' || pattern[1]!='\0')
2661 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2664 /* insert listbox entries after index idx */
2666 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2673 ShowWindow(pane->hwnd, SW_HIDE);
2675 for(; entry; entry=entry->next) {
2677 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2681 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2682 /* don't display entries "." and ".." in the left pane */
2683 if (pane->treePane && entry->data.cFileName[0]==TEXT('.'))
2685 #ifndef _NO_EXTENSIONS
2686 entry->data.cFileName[1]==TEXT('\0') ||
2688 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2691 /* filter directories in right pane */
2692 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2696 /* filter using the file name pattern */
2698 if (!pattern_match(entry->data.cFileName, pattern))
2701 /* filter system and hidden files */
2702 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2705 /* filter looking at the file type */
2706 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2707 switch(get_file_type(entry->data.cFileName)) {
2709 if (!(filter_flags & TF_PROGRAMS))
2714 if (!(filter_flags & TF_DOCUMENTS))
2718 default: /* TF_OTHERS */
2719 if (!(filter_flags & TF_OTHERS))
2726 ListBox_InsertItemData(pane->hwnd, idx, entry);
2728 if (pane->treePane && entry->expanded)
2729 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2732 ShowWindow(pane->hwnd, SW_SHOW);
2738 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2740 const static TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2741 const static TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2742 const static TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2744 float fBytes = (float)bytes;
2746 if (bytes >= 1073741824) /* 1 GB */
2747 _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2748 else if (bytes >= 1048576) /* 1 MB */
2749 _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2750 else if (bytes >= 1024) /* 1 kB */
2751 _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2753 _stprintf(buffer, sLongNumFmt, bytes);
2756 static void set_space_status(void)
2758 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2759 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2761 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2762 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2763 format_bytes(b2, ulTotalBytes.QuadPart);
2764 _stprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2766 _tcscpy(buffer, sQMarks);
2768 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2772 static WNDPROC g_orgTreeWndProc;
2774 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2776 const static TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2778 static int s_init = 0;
2779 Entry* entry = pane->root;
2781 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2782 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2783 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2785 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2786 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2788 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2790 /* insert entries into listbox */
2792 insert_entries(pane, entry, pattern, filter_flags, -1);
2794 /* calculate column widths */
2797 init_output(pane->hwnd);
2800 calc_widths(pane, TRUE);
2802 #ifndef _NO_EXTENSIONS
2803 pane->hwndHeader = create_header(parent, pane, id_header);
2808 static void InitChildWindow(ChildWnd* child)
2810 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2811 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2815 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2821 *buffer = TEXT('\0');
2823 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2826 if (!FileTimeToLocalFileTime(ft, &lft))
2827 {err: _tcscpy(buffer,sQMarks); return;}
2829 if (!FileTimeToSystemTime(&lft, &systime))
2832 if (visible_cols & COL_DATE) {
2833 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2838 if (visible_cols & COL_TIME) {
2840 buffer[len-1] = ' ';
2842 buffer[len++] = ' ';
2844 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2845 buffer[len] = TEXT('\0');
2850 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2852 RECT rt = {0, 0, 0, 0};
2854 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2856 if (rt.right > pane->widths[col])
2857 pane->widths[col] = rt.right;
2860 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2862 RECT rt = {0, 0, 0, 0};
2864 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2865 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2867 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2868 /*FIXME rt (0,0) ??? */
2870 if (rt.right > pane->widths[col])
2871 pane->widths[col] = rt.right;
2875 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2877 int x = dis->rcItem.left;
2880 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2881 rt.top = dis->rcItem.top;
2882 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2883 rt.bottom = dis->rcItem.bottom;
2885 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2888 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2890 int x = dis->rcItem.left;
2893 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2894 rt.top = dis->rcItem.top;
2895 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2896 rt.bottom = dis->rcItem.bottom;
2898 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2899 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2901 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2904 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2906 int x = dis->rcItem.left;
2913 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2914 rt.top = dis->rcItem.top;
2915 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2916 rt.bottom = dis->rcItem.bottom;
2921 /* insert number separator characters */
2922 pos = lstrlen(s) % 3;
2928 *d++ = Globals.num_sep;
2932 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2936 static BOOL is_exe_file(LPCTSTR ext)
2938 static const TCHAR executable_extensions[][4] = {
2943 #ifndef _NO_EXTENSIONS
2947 #endif /* _NO_EXTENSIONS */
2951 TCHAR ext_buffer[_MAX_EXT];
2952 const TCHAR (*p)[4];
2956 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2959 for(p=executable_extensions; (*p)[0]; p++)
2960 if (!_tcsicmp(ext_buffer, *p))
2966 static BOOL is_registered_type(LPCTSTR ext)
2968 /* check if there exists a classname for this file extension in the registry */
2969 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2975 static enum FILE_TYPE get_file_type(LPCTSTR filename)
2977 LPCTSTR ext = _tcsrchr(filename, '.');
2981 if (is_exe_file(ext))
2982 return FT_EXECUTABLE;
2983 else if (is_registered_type(ext))
2990 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2992 TCHAR buffer[BUFFER_LEN];
2994 int visible_cols = pane->visible_cols;
2995 COLORREF bkcolor, textcolor;
2996 RECT focusRect = dis->rcItem;
3003 attrs = entry->data.dwFileAttributes;
3005 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3006 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
3007 && entry->data.cFileName[2]==TEXT('\0'))
3008 img = IMG_FOLDER_UP;
3009 #ifndef _NO_EXTENSIONS
3010 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
3011 img = IMG_FOLDER_CUR;
3014 #ifdef _NO_EXTENSIONS
3017 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3018 img = IMG_OPEN_FOLDER;
3022 switch(get_file_type(entry->data.cFileName)) {
3023 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3024 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3025 default: img = IMG_FILE;
3033 if (pane->treePane) {
3035 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3037 if (calcWidthCol == -1) {
3039 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3042 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3045 rt_clip.left = dis->rcItem.left;
3046 rt_clip.top = dis->rcItem.top;
3047 rt_clip.right = dis->rcItem.left+pane->widths[col];
3048 rt_clip.bottom = dis->rcItem.bottom;
3050 hrgn = CreateRectRgnIndirect(&rt_clip);
3052 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3053 DeleteObject(hrgn_org);
3057 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3058 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3061 if ((up=entry->up) != NULL) {
3062 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3063 LineTo(dis->hDC, img_pos-2, y);
3065 x = img_pos - IMAGE_WIDTH/2;
3068 x -= IMAGE_WIDTH+TREE_LINE_DX;
3072 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3075 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3076 LineTo(dis->hDC, x, dis->rcItem.bottom);
3078 } while((up=up->up) != NULL);
3081 x = img_pos - IMAGE_WIDTH/2;
3083 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3084 LineTo(dis->hDC, x, y);
3088 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3091 LineTo(dis->hDC, x, dis->rcItem.bottom);
3093 SelectClipRgn(dis->hDC, hrgn_org);
3094 if (hrgn_org) DeleteObject(hrgn_org);
3095 /* SelectObject(dis->hDC, holdPen); */
3096 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3097 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3099 if (right > pane->widths[col])
3100 pane->widths[col] = right;
3103 img_pos = dis->rcItem.left;
3106 img_pos = dis->rcItem.left;
3108 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3109 pane->widths[col] = IMAGE_WIDTH;
3112 if (calcWidthCol == -1) {
3113 focusRect.left = img_pos -2;
3115 #ifdef _NO_EXTENSIONS
3116 if (pane->treePane && entry) {
3119 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3121 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3125 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3126 textcolor = COLOR_COMPRESSED;
3128 #endif /* _NO_EXTENSIONS */
3129 textcolor = RGB(0,0,0);
3131 if (dis->itemState & ODS_FOCUS) {
3132 textcolor = RGB(255,255,255);
3133 bkcolor = COLOR_SELECTION;
3135 bkcolor = RGB(255,255,255);
3138 hbrush = CreateSolidBrush(bkcolor);
3139 FillRect(dis->hDC, &focusRect, hbrush);
3140 DeleteObject(hbrush);
3142 SetBkMode(dis->hDC, TRANSPARENT);
3143 SetTextColor(dis->hDC, textcolor);
3145 cx = pane->widths[col];
3147 if (cx && img!=IMG_NONE) {
3149 if (cx > IMAGE_WIDTH)
3152 #ifdef _SHELL_FOLDERS
3153 if (entry->hicon && entry->hicon!=(HICON)-1)
3154 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3157 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3158 img_pos, dis->rcItem.top, cx,
3159 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3166 #ifdef _NO_EXTENSIONS
3167 if (img >= IMG_FOLDER_UP)
3173 /* ouput file name */
3174 if (calcWidthCol == -1)
3175 output_text(pane, dis, col, entry->data.cFileName, 0);
3176 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3177 calc_width(pane, dis, col, entry->data.cFileName);
3181 #ifdef _NO_EXTENSIONS
3182 if (!pane->treePane) {
3185 /* display file size */
3186 if (visible_cols & COL_SIZE) {
3187 #ifdef _NO_EXTENSIONS
3188 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3193 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3195 _stprintf(buffer, sLongNumFmt, size);
3197 if (calcWidthCol == -1)
3198 output_number(pane, dis, col, buffer);
3199 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3200 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3206 /* display file date */
3207 if (visible_cols & (COL_DATE|COL_TIME)) {
3208 #ifndef _NO_EXTENSIONS
3209 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3210 if (calcWidthCol == -1)
3211 output_text(pane, dis, col, buffer, 0);
3212 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3213 calc_width(pane, dis, col, buffer);
3216 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3217 if (calcWidthCol == -1)
3218 output_text(pane, dis, col, buffer, 0);
3219 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3220 calc_width(pane, dis, col, buffer);
3222 #endif /* _NO_EXTENSIONS */
3224 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3225 if (calcWidthCol == -1)
3226 output_text(pane, dis, col, buffer, 0);
3227 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3228 calc_width(pane, dis, col, buffer);
3232 #ifndef _NO_EXTENSIONS
3233 if (entry->bhfi_valid) {
3234 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3236 if (visible_cols & COL_INDEX) {
3237 _stprintf(buffer, sLongHexFmt, index);
3239 if (calcWidthCol == -1)
3240 output_text(pane, dis, col, buffer, DT_RIGHT);
3241 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3242 calc_width(pane, dis, col, buffer);
3247 if (visible_cols & COL_LINKS) {
3248 _stprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3250 if (calcWidthCol == -1)
3251 output_text(pane, dis, col, buffer, DT_CENTER);
3252 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3253 calc_width(pane, dis, col, buffer);
3259 #endif /* _NO_EXTENSIONS */
3261 /* show file attributes */
3262 if (visible_cols & COL_ATTRIBUTES) {
3263 #ifdef _NO_EXTENSIONS
3264 const static TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3265 _tcscpy(buffer, s4Tabs);
3267 const static TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3268 _tcscpy(buffer, s11Tabs);
3271 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3273 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3274 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3275 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3276 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3277 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3278 #ifndef _NO_EXTENSIONS
3279 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3280 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3281 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3282 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3283 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3284 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3285 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3286 #endif /* _NO_EXTENSIONS */
3289 if (calcWidthCol == -1)
3290 output_tabbed_text(pane, dis, col, buffer);
3291 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3292 calc_tabbed_width(pane, dis, col, buffer);
3298 if (flags.security) {
3299 const static TCHAR sSecTabs[] = {
3300 ' ','\t',' ','\t',' ','\t',' ',
3302 ' ','\t',' ','\t',' ','\t',' ',
3304 ' ','\t',' ','\t',' ','\t',' ',
3308 DWORD rights = get_access_mask();
3310 tcscpy(buffer, sSecTabs);
3312 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3313 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3314 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3315 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3316 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3317 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3318 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3319 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3320 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3321 if (rights & WRITE_DAC) buffer[22] = 'C';
3322 if (rights & WRITE_OWNER) buffer[24] = 'O';
3323 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3325 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3328 if (flags.description) {
3329 get_description(buffer);
3330 output_text(dis, col++, buffer, 0, psize);
3334 #ifdef _NO_EXTENSIONS
3337 /* draw focus frame */
3338 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3339 /* Currently [04/2000] Wine neither behaves exactly the same */
3340 /* way as WIN 95 nor like Windows NT... */
3345 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3346 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3347 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3349 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3351 lastPen = SelectPen(dis->hDC, hpen);
3352 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3353 SetROP2(dis->hDC, R2_XORPEN);
3354 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3355 SelectObject(dis->hDC, lastBrush);
3356 SelectObject(dis->hDC, lastPen);
3359 #endif /* _NO_EXTENSIONS */
3363 #ifdef _NO_EXTENSIONS
3365 static void draw_splitbar(HWND hwnd, int x)
3368 HDC hdc = GetDC(hwnd);
3370 GetClientRect(hwnd, &rt);
3372 rt.left = x - SPLIT_WIDTH/2;
3373 rt.right = x + SPLIT_WIDTH/2+1;
3375 InvertRect(hdc, &rt);
3377 ReleaseDC(hwnd, hdc);
3380 #endif /* _NO_EXTENSIONS */
3383 #ifndef _NO_EXTENSIONS
3385 static void set_header(Pane* pane)
3388 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3391 item.mask = HDI_WIDTH;
3394 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3395 x += pane->widths[i];
3396 Header_SetItem(pane->hwndHeader, i, &item);
3400 x += pane->widths[i];
3401 item.cxy = x - scroll_pos;
3402 Header_SetItem(pane->hwndHeader, i++, &item);
3404 for(; i<COLUMNS; i++) {
3405 item.cxy = pane->widths[i];
3406 x += pane->widths[i];
3407 Header_SetItem(pane->hwndHeader, i, &item);
3412 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3414 switch(pnmh->code) {
3416 case HDN_ENDTRACK: {
3417 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3418 int idx = phdn->iItem;
3419 int dx = phdn->pitem->cxy - pane->widths[idx];
3423 GetClientRect(pane->hwnd, &clnt);
3425 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3426 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
3428 pane->widths[idx] += dx;
3430 for(i=idx; ++i<=COLUMNS; )
3431 pane->positions[i] += dx;
3434 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3438 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3440 rt_scr.right = clnt.right;
3441 rt_scr.bottom = clnt.bottom;
3443 rt_clip.left = pane->positions[idx]-scroll_pos;
3445 rt_clip.right = clnt.right;
3446 rt_clip.bottom = clnt.bottom;
3448 if (rt_scr.left < 0) rt_scr.left = 0;
3449 if (rt_clip.left < 0) rt_clip.left = 0;
3451 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3453 rt_clip.right = pane->positions[idx+1];
3454 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3456 if (pnmh->code == HDN_ENDTRACK) {
3457 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
3459 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3467 case HDN_DIVIDERDBLCLICK: {
3468 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3471 calc_single_width(pane, phdn->iItem);
3472 item.mask = HDI_WIDTH;
3473 item.cxy = pane->widths[phdn->iItem];
3475 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3476 InvalidateRect(pane->hwnd, 0, TRUE);
3483 #endif /* _NO_EXTENSIONS */
3486 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3488 TCHAR path[MAX_PATH];
3489 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3491 /* delete sub entries in left pane */
3493 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3494 Entry* sub = (Entry*) res;
3496 if (res==LB_ERR || !sub || sub->level<=entry->level)
3499 ListBox_DeleteString(child->left.hwnd, idx+1);
3502 /* empty right pane */
3503 ListBox_ResetContent(child->right.hwnd);
3505 /* release memory */
3506 free_entries(entry);
3508 /* read contents from disk */
3509 #ifdef _SHELL_FOLDERS
3510 if (entry->etype == ET_SHELL)
3512 read_directory(entry, NULL, child->sortOrder, hwnd);
3517 get_path(entry, path);
3518 read_directory(entry, path, child->sortOrder, hwnd);
3521 /* insert found entries in right pane */
3522 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3523 calc_widths(&child->right, FALSE);
3524 #ifndef _NO_EXTENSIONS
3525 set_header(&child->right);
3528 child->header_wdths_ok = FALSE;
3530 SetCursor(old_cursor);
3534 /* expand a directory entry */
3536 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3541 if (!dir || dir->expanded || !dir->down)
3546 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3549 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3550 p->data.cFileName[2]=='\0' && p->next)
3554 /* no subdirectories ? */
3555 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3558 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3560 dir->expanded = TRUE;
3562 /* insert entries in left pane */
3563 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3565 if (!child->header_wdths_ok) {
3566 if (calc_widths(&child->left, FALSE)) {
3567 #ifndef _NO_EXTENSIONS
3568 set_header(&child->left);
3571 child->header_wdths_ok = TRUE;
3579 static void collapse_entry(Pane* pane, Entry* dir)
3581 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3583 ShowWindow(pane->hwnd, SW_HIDE);
3585 /* hide sub entries */
3587 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3588 Entry* sub = (Entry*) res;
3590 if (res==LB_ERR || !sub || sub->level<=dir->level)
3593 ListBox_DeleteString(pane->hwnd, idx+1);
3596 dir->expanded = FALSE;
3598 ShowWindow(pane->hwnd, SW_SHOW);
3602 static void refresh_right_pane(ChildWnd* child)
3604 ListBox_ResetContent(child->right.hwnd);
3605 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3606 calc_widths(&child->right, FALSE);
3608 #ifndef _NO_EXTENSIONS
3609 set_header(&child->right);
3613 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3615 TCHAR path[MAX_PATH];
3619 child->left.cur = entry;
3621 child->right.root = entry->down? entry->down: entry;
3622 child->right.cur = entry;
3624 if (!entry->scanned)
3625 scan_entry(child, entry, idx, hwnd);
3627 refresh_right_pane(child);
3629 get_path(entry, path);
3630 lstrcpy(child->path, path);
3632 if (child->hwnd) /* only change window title, if the window already exists */
3633 SetWindowText(child->hwnd, path);
3636 if (SetCurrentDirectory(path))
3641 static void refresh_child(ChildWnd* child)
3643 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3647 get_path(child->left.cur, path);
3648 _tsplitpath(path, drv, NULL, NULL, NULL);
3650 child->right.root = NULL;
3652 scan_entry(child, &child->root.entry, 0, child->hwnd);
3654 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3656 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3658 set_curdir(child, entry, 0, child->hwnd);
3660 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
3661 ListBox_SetCurSel(child->left.hwnd, idx);
3665 static void create_drive_bar(void)
3667 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3668 #ifndef _NO_EXTENSIONS
3669 TCHAR b1[BUFFER_LEN];
3674 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3676 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3677 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3678 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3680 #ifndef _NO_EXTENSIONS
3682 /* insert unix file system button */
3686 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3688 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3689 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3690 drivebarBtn.iString++;
3692 #ifdef _SHELL_FOLDERS
3693 /* insert shell namespace button */
3694 load_string(b1, IDS_SHELL);
3695 b1[lstrlen(b1)+1] = '\0';
3696 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3698 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3699 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3700 drivebarBtn.iString++;
3703 /* register windows drive root strings */
3704 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3707 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3709 for(p=Globals.drives; *p; ) {
3710 #ifdef _NO_EXTENSIONS
3711 /* insert drive letter */
3712 TCHAR b[3] = {tolower(*p)};
3713 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3715 switch(GetDriveType(p)) {
3716 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3717 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3718 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3719 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3720 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3723 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3724 drivebarBtn.idCommand++;
3725 drivebarBtn.iString++;
3731 static void refresh_drives(void)
3735 /* destroy drive bar */
3736 DestroyWindow(Globals.hdrivebar);
3737 Globals.hdrivebar = 0;
3739 /* re-create drive bar */
3742 /* update window layout */
3743 GetClientRect(Globals.hMainWnd, &rect);
3744 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3748 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3750 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3752 if ((int)hinst <= 32) {
3753 display_error(hwnd, GetLastError());
3761 static BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3763 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3765 if ((int)hinst <= 32) {
3766 display_error(hwnd, GetLastError());
3775 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3777 TCHAR cmd[MAX_PATH];
3779 #ifdef _SHELL_FOLDERS
3780 if (entry->etype == ET_SHELL) {
3783 SHELLEXECUTEINFO shexinfo;
3785 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3786 shexinfo.fMask = SEE_MASK_IDLIST;
3787 shexinfo.hwnd = hwnd;
3788 shexinfo.lpVerb = NULL;
3789 shexinfo.lpFile = NULL;
3790 shexinfo.lpParameters = NULL;
3791 shexinfo.lpDirectory = NULL;
3792 shexinfo.nShow = nCmdShow;
3793 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3795 if (!ShellExecuteEx(&shexinfo)) {
3796 display_error(hwnd, GetLastError());
3800 if (shexinfo.lpIDList != entry->pidl)
3801 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3807 get_path(entry, cmd);
3809 /* start program, open document... */
3810 return launch_file(hwnd, cmd, nCmdShow);
3814 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3816 Entry* entry = pane->cur;
3821 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3822 int scanned_old = entry->scanned;
3825 scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd);
3827 #ifndef _NO_EXTENSIONS
3828 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3832 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3833 entry = child->left.cur->up;
3834 collapse_entry(&child->left, entry);
3836 } else if (entry->expanded)
3837 collapse_entry(pane, child->left.cur);
3839 expand_entry(child, child->left.cur);
3841 if (!pane->treePane) focus_entry: {
3842 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3843 ListBox_SetCurSel(child->left.hwnd, idx);
3844 set_curdir(child, entry, idx, hwnd);
3849 calc_widths(pane, FALSE);
3851 #ifndef _NO_EXTENSIONS
3856 if (GetKeyState(VK_MENU) < 0)
3857 show_properties_dlg(entry, child->hwnd);
3859 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3864 static BOOL pane_command(Pane* pane, UINT cmd)
3868 if (pane->visible_cols) {
3869 pane->visible_cols = 0;
3870 calc_widths(pane, TRUE);
3871 #ifndef _NO_EXTENSIONS
3874 InvalidateRect(pane->hwnd, 0, TRUE);
3875 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3876 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3877 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3881 case ID_VIEW_ALL_ATTRIBUTES:
3882 if (pane->visible_cols != COL_ALL) {
3883 pane->visible_cols = COL_ALL;
3884 calc_widths(pane, TRUE);
3885 #ifndef _NO_EXTENSIONS
3888 InvalidateRect(pane->hwnd, 0, TRUE);
3889 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3890 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3891 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3895 #ifndef _NO_EXTENSIONS
3896 case ID_PREFERRED_SIZES: {
3897 calc_widths(pane, TRUE);
3899 InvalidateRect(pane->hwnd, 0, TRUE);
3903 /* TODO: more command ids... */
3913 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3915 if (child->sortOrder != sortOrder) {
3916 child->sortOrder = sortOrder;
3917 refresh_child(child);
3921 static void update_view_menu(ChildWnd* child)
3923 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3924 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3925 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3926 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3930 static BOOL is_directory(LPCTSTR target)
3932 /*TODO correctly handle UNIX paths */
3933 DWORD target_attr = GetFileAttributes(target);
3935 if (target_attr == INVALID_FILE_ATTRIBUTES)
3938 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
3941 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
3943 TCHAR path[MAX_PATH];
3946 get_path(pane->cur, path);
3948 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
3951 get_path(pane->cur, source);
3953 /* convert relative targets to absolute paths */
3954 if (path[0]!='/' && path[1]!=':') {
3955 get_path(pane->cur->up, target);
3956 len = lstrlen(target);
3958 if (target[len-1]!='\\' && target[len-1]!='/')
3959 target[len++] = '/';
3961 lstrcpy(target+len, path);
3963 lstrcpy(target, path);
3965 /* If the target already exists as directory, create a new target below this. */
3966 if (is_directory(path)) {
3967 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
3968 const static TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
3970 _tsplitpath(source, NULL, NULL, fname, ext);
3972 wsprintf(target, sAppend, path, fname, ext);
3979 static IContextMenu2* s_pctxmenu2 = NULL;
3980 static IContextMenu3* s_pctxmenu3 = NULL;
3982 static void CtxMenu_reset()
3988 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
3990 IContextMenu* pcm = NULL;
3994 if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
3995 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
3996 else if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
3997 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4000 (*pcm1->lpVtbl->Release)(pcm1);
4006 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4009 if (SUCCEEDED((*s_pctxmenu3->lpVtbl->HandleMenuMsg)(s_pctxmenu3, nmsg, wparam, lparam)))
4014 if (SUCCEEDED((*s_pctxmenu2->lpVtbl->HandleMenuMsg)(s_pctxmenu2, nmsg, wparam, lparam)))
4021 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4024 BOOL executed = FALSE;
4026 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4027 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4029 if (SUCCEEDED(hr)) {
4030 HMENU hmenu = CreatePopupMenu();
4032 pcm = CtxMenu_query_interfaces(pcm);
4035 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4037 if (SUCCEEDED(hr)) {
4038 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4043 CMINVOKECOMMANDINFO cmi;
4045 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4047 cmi.hwnd = hwndParent;
4048 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4049 cmi.lpParameters = NULL;
4050 cmi.lpDirectory = NULL;
4051 cmi.nShow = SW_SHOWNORMAL;
4055 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
4062 (*pcm->lpVtbl->Release)(pcm);
4065 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4069 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4071 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
4076 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4077 Entry* entry = (Entry*) dis->itemData;
4079 if (dis->CtlID == IDW_TREE_LEFT)
4080 draw_item(&child->left, dis, entry, -1);
4081 else if (dis->CtlID == IDW_TREE_RIGHT)
4082 draw_item(&child->right, dis, entry, -1);
4084 goto draw_menu_item;
4089 InitChildWindow(child);
4093 free_child_window(child);
4094 SetWindowLong(hwnd, GWL_USERDATA, 0);
4101 GetClientRect(hwnd, &rt);
4102 BeginPaint(hwnd, &ps);
4103 rt.left = child->split_pos-SPLIT_WIDTH/2;
4104 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4105 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
4106 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4107 SelectObject(ps.hdc, lastBrush);
4108 #ifdef _NO_EXTENSIONS
4109 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4110 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4112 EndPaint(hwnd, &ps);
4116 if (LOWORD(lparam) == HTCLIENT) {
4119 ScreenToClient(hwnd, &pt);
4121 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4122 SetCursor(LoadCursor(0, IDC_SIZEWE));
4128 case WM_LBUTTONDOWN: {
4130 int x = GET_X_LPARAM(lparam);
4132 GetClientRect(hwnd, &rt);
4134 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4135 last_split = child->split_pos;
4136 #ifdef _NO_EXTENSIONS
4137 draw_splitbar(hwnd, last_split);
4145 if (GetCapture() == hwnd) {
4146 #ifdef _NO_EXTENSIONS
4148 int x = LOWORD(lparam);
4149 draw_splitbar(hwnd, last_split);
4151 GetClientRect(hwnd, &rt);
4152 child->split_pos = x;
4153 resize_tree(child, rt.right, rt.bottom);
4159 #ifdef _NO_EXTENSIONS
4160 case WM_CAPTURECHANGED:
4161 if (GetCapture()==hwnd && last_split>=0)
4162 draw_splitbar(hwnd, last_split);
4167 if (wparam == VK_ESCAPE)
4168 if (GetCapture() == hwnd) {
4170 #ifdef _NO_EXTENSIONS
4171 draw_splitbar(hwnd, last_split);
4173 child->split_pos = last_split;
4175 GetClientRect(hwnd, &rt);
4176 resize_tree(child, rt.right, rt.bottom);
4179 SetCursor(LoadCursor(0, IDC_ARROW));
4184 if (GetCapture() == hwnd) {
4186 int x = LOWORD(lparam);
4188 #ifdef _NO_EXTENSIONS
4189 HDC hdc = GetDC(hwnd);
4190 GetClientRect(hwnd, &rt);
4192 rt.left = last_split-SPLIT_WIDTH/2;
4193 rt.right = last_split+SPLIT_WIDTH/2+1;
4194 InvertRect(hdc, &rt);
4197 rt.left = x-SPLIT_WIDTH/2;
4198 rt.right = x+SPLIT_WIDTH/2+1;
4199 InvertRect(hdc, &rt);
4201 ReleaseDC(hwnd, hdc);
4203 GetClientRect(hwnd, &rt);
4205 if (x>=0 && x<rt.right) {
4206 child->split_pos = x;
4207 resize_tree(child, rt.right, rt.bottom);
4208 rt.left = x-SPLIT_WIDTH/2;
4209 rt.right = x+SPLIT_WIDTH/2+1;
4210 InvalidateRect(hwnd, &rt, FALSE);
4211 UpdateWindow(child->left.hwnd);
4213 UpdateWindow(child->right.hwnd);
4219 #ifndef _NO_EXTENSIONS
4220 case WM_GETMINMAXINFO:
4221 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4223 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4225 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4226 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4228 #endif /* _NO_EXTENSIONS */
4231 if (SetCurrentDirectory(child->path))
4233 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4236 case WM_DISPATCH_COMMAND: {
4237 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4239 switch(LOWORD(wparam)) {
4240 case ID_WINDOW_NEW: {
4241 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4243 if (!create_child_window(new_child))
4250 refresh_child(child);
4254 activate_entry(child, pane, hwnd);
4257 case ID_FILE_MOVE: {
4258 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4260 if (prompt_target(pane, source, target)) {
4261 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4263 source[lstrlen(source)+1] = '\0';
4264 target[lstrlen(target)+1] = '\0';
4266 if (!SHFileOperation(&shfo))
4267 refresh_child(child);
4271 case ID_FILE_COPY: {
4272 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4274 if (prompt_target(pane, source, target)) {
4275 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4277 source[lstrlen(source)+1] = '\0';
4278 target[lstrlen(target)+1] = '\0';
4280 if (!SHFileOperation(&shfo))
4281 refresh_child(child);
4285 case ID_FILE_DELETE: {
4286 TCHAR path[BUFFER_LEN];
4287 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
4289 get_path(pane->cur, path);
4291 path[lstrlen(path)+1] = '\0';
4293 if (!SHFileOperation(&shfo))
4294 refresh_child(child);
4297 case ID_VIEW_SORT_NAME:
4298 set_sort_order(child, SORT_NAME);
4301 case ID_VIEW_SORT_TYPE:
4302 set_sort_order(child, SORT_EXT);
4305 case ID_VIEW_SORT_SIZE:
4306 set_sort_order(child, SORT_SIZE);
4309 case ID_VIEW_SORT_DATE:
4310 set_sort_order(child, SORT_DATE);
4313 case ID_VIEW_FILTER: {
4314 struct FilterDialog dlg;
4316 memset(&dlg, 0, sizeof(struct FilterDialog));
4317 _tcscpy(dlg.pattern, child->filter_pattern);
4318 dlg.flags = child->filter_flags;
4320 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4321 _tcscpy(child->filter_pattern, dlg.pattern);
4322 child->filter_flags = dlg.flags;
4323 refresh_right_pane(child);
4327 case ID_VIEW_SPLIT: {
4328 last_split = child->split_pos;
4329 #ifdef _NO_EXTENSIONS
4330 draw_splitbar(hwnd, last_split);
4335 case ID_EDIT_PROPERTIES:
4336 show_properties_dlg(pane->cur, child->hwnd);
4340 return pane_command(pane, LOWORD(wparam));
4346 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4348 switch(HIWORD(wparam)) {
4349 case LBN_SELCHANGE: {
4350 int idx = ListBox_GetCurSel(pane->hwnd);
4351 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4353 if (pane == &child->left)
4354 set_curdir(child, entry, idx, hwnd);
4360 activate_entry(child, pane, hwnd);
4365 #ifndef _NO_EXTENSIONS
4367 NMHDR* pnmh = (NMHDR*) lparam;
4368 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4371 #ifdef _SHELL_FOLDERS
4372 case WM_CONTEXTMENU: {
4377 /* first select the current item in the listbox */
4378 HWND hpanel = (HWND) wparam;
4379 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4380 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4381 ScreenToClient(hpanel, &pt_clnt);
4382 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4383 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4385 /* now create the popup menu using shell namespace and IContextMenu */
4386 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4387 idx = ListBox_GetCurSel(pane->hwnd);
4390 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4392 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4395 IShellFolder* parentFolder;
4396 LPCITEMIDLIST pidlLast;
4398 /* get and use the parent folder to display correct context menu in all cases */
4399 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4400 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4401 refresh_child(child);
4403 (*parentFolder->lpVtbl->Release)(parentFolder);
4406 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
4412 case WM_MEASUREITEM:
4414 if (!wparam) /* Is the message menu-related? */
4415 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4420 case WM_INITMENUPOPUP:
4421 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4424 update_view_menu(child);
4427 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4429 LRESULT lResult = 0;
4431 (*s_pctxmenu3->lpVtbl->HandleMenuMsg2)(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4439 if (wparam != SIZE_MINIMIZED)
4440 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4444 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4451 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4453 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
4454 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
4458 #ifndef _NO_EXTENSIONS
4465 child->focus_pane = pane==&child->right? 1: 0;
4466 ListBox_SetSel(hwnd, TRUE, 1);
4467 /*TODO: check menu items */
4471 if (wparam == VK_TAB) {
4472 /*TODO: SetFocus(Globals.hdrivebar) */
4473 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4477 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4481 static void InitInstance(HINSTANCE hinstance)
4483 const static TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4490 INITCOMMONCONTROLSEX icc = {
4491 sizeof(INITCOMMONCONTROLSEX),
4497 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4499 InitCommonControlsEx(&icc);
4502 /* register frame window class */
4504 wcFrame.cbSize = sizeof(WNDCLASSEX);
4506 wcFrame.lpfnWndProc = FrameWndProc;
4507 wcFrame.cbClsExtra = 0;
4508 wcFrame.cbWndExtra = 0;
4509 wcFrame.hInstance = hinstance;
4510 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4511 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4512 wcFrame.hbrBackground = 0;
4513 wcFrame.lpszMenuName = 0;
4514 wcFrame.lpszClassName = sWINEFILEFRAME;
4515 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4516 MAKEINTRESOURCE(IDI_WINEFILE),
4518 GetSystemMetrics(SM_CXSMICON),
4519 GetSystemMetrics(SM_CYSMICON),
4522 Globals.hframeClass = RegisterClassEx(&wcFrame);
4525 /* register tree windows class */
4527 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4528 wcChild.lpfnWndProc = ChildWndProc;
4529 wcChild.cbClsExtra = 0;
4530 wcChild.cbWndExtra = 0;
4531 wcChild.hInstance = hinstance;
4533 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4534 wcChild.hbrBackground = 0;
4535 wcChild.lpszMenuName = 0;
4536 wcChild.lpszClassName = sWINEFILETREE;
4538 hChildClass = RegisterClass(&wcChild);
4541 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4543 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4547 Globals.hInstance = hinstance;
4549 #ifdef _SHELL_FOLDERS
4551 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4552 SHGetDesktopFolder(&Globals.iDesktop);
4554 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4556 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4560 /* load column strings */
4563 load_string(g_pos_names[col++], IDS_COL_NAME);
4564 load_string(g_pos_names[col++], IDS_COL_SIZE);
4565 load_string(g_pos_names[col++], IDS_COL_CDATE);
4566 #ifndef _NO_EXTENSIONS
4567 load_string(g_pos_names[col++], IDS_COL_ADATE);
4568 load_string(g_pos_names[col++], IDS_COL_MDATE);
4569 load_string(g_pos_names[col++], IDS_COL_IDX);
4570 load_string(g_pos_names[col++], IDS_COL_LINKS);
4572 load_string(g_pos_names[col++], IDS_COL_ATTR);
4573 #ifndef _NO_EXTENSIONS
4574 load_string(g_pos_names[col++], IDS_COL_SEC);
4579 static void show_frame(HWND hwndParent, int cmdshow)
4581 const static TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4583 TCHAR path[MAX_PATH], b1[BUFFER_LEN];
4585 HMENU hMenuFrame, hMenuWindow;
4587 CLIENTCREATESTRUCT ccs;
4589 if (Globals.hMainWnd)
4592 Globals.hwndParent = hwndParent;
4594 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4595 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4597 Globals.hMenuFrame = hMenuFrame;
4598 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4599 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4601 ccs.hWindowMenu = hMenuWindow;
4602 ccs.idFirstChild = IDW_FIRST_CHILD;
4605 /* create main window */
4606 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4607 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
4608 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4611 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4612 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4614 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4617 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4622 TBBUTTON toolbarBtns[] = {
4623 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4624 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4625 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4626 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4627 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4629 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4630 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4633 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4634 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4635 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4636 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4639 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4640 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4642 /* CreateStatusWindow does not accept WS_BORDER
4643 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4644 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4645 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4647 /*TODO: read paths and window placements from registry */
4648 GetCurrentDirectory(MAX_PATH, path);
4650 ShowWindow(Globals.hMainWnd, cmdshow);
4652 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4653 /* Shell Namespace as default: */
4654 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4656 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4659 child->pos.showCmd = SW_SHOWMAXIMIZED;
4660 child->pos.rcNormalPosition.left = 0;
4661 child->pos.rcNormalPosition.top = 0;
4662 child->pos.rcNormalPosition.right = 320;
4663 child->pos.rcNormalPosition.bottom = 280;
4665 if (!create_child_window(child))
4668 SetWindowPlacement(child->hwnd, &child->pos);
4670 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4672 Globals.prescan_node = FALSE;
4674 UpdateWindow(Globals.hMainWnd);
4677 static void ExitInstance(void)
4679 #ifdef _SHELL_FOLDERS
4680 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
4681 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
4685 ImageList_Destroy(Globals.himl);
4688 #ifdef _NO_EXTENSIONS
4690 /* search for already running win[e]files */
4692 static int g_foundPrevInstance = 0;
4694 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4698 GetClassName(hwnd, cls, 128);
4700 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4701 g_foundPrevInstance++;
4708 /* search for window of given class name to allow only one running instance */
4709 static int find_window_class(LPCTSTR classname)
4711 EnumWindows(EnumWndProc, (LPARAM)classname);
4713 if (g_foundPrevInstance)
4721 static int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
4725 InitInstance(hinstance);
4727 if (cmdshow == SW_SHOWNORMAL)
4728 /*TODO: read window placement from registry */
4729 cmdshow = SW_MAXIMIZE;
4731 show_frame(hwndParent, cmdshow);
4733 while(GetMessage(&msg, 0, 0, 0)) {
4734 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4737 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4740 TranslateMessage(&msg);
4741 DispatchMessage(&msg);
4750 int APIENTRY WinMain(HINSTANCE hinstance,
4751 HINSTANCE previnstance,
4755 #ifdef _NO_EXTENSIONS
4756 if (find_window_class(sWINEFILEFRAME))
4760 winefile_main(hinstance, 0, cmdshow);