4 * Copyright 2000 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"
28 #define NONAMELESSUNION
32 /* for read_directory_unix() */
33 #if !defined(_NO_EXTENSIONS) && !defined(_WIN32)
46 #define _MAX_FNAME 256
47 #define _MAX_DIR _MAX_FNAME
48 #define _MAX_EXT _MAX_FNAME
52 #ifdef NONAMELESSUNION
53 #define UNION_MEMBER(x) DUMMYUNIONNAME.##x
55 #define UNION_MEMBER(x) x
60 #define DEFAULT_SPLIT_POS 300;
62 #define DEFAULT_SPLIT_POS 200;
66 WINEFILE_GLOBALS Globals;
68 extern void WineLicense(HWND hwnd);
69 extern void WineWarranty(HWND hwnd);
79 typedef struct _Entry {
90 #ifndef _NO_EXTENSIONS
91 BY_HANDLE_FILE_INFORMATION bhfi;
93 enum ENTRY_TYPE etype;
104 TCHAR path[MAX_PATH];
105 TCHAR volname[_MAX_FNAME];
115 COL_ATTRIBUTES = 0x08,
117 #ifdef _NO_EXTENSIONS
118 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
122 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
135 #ifndef _NO_EXTENSIONS
139 #ifndef _NO_EXTENSIONS
145 int positions[COLUMNS+1];
157 int focus_pane; /* 0: left 1: right */
160 BOOL header_wdths_ok;
162 TCHAR path[MAX_PATH];
165 SORT_ORDER sortOrder;
169 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
170 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd);
172 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
173 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
174 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
177 static void display_error(HWND hwnd, DWORD error)
181 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
182 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
183 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
185 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
191 /* allocate and initialise a directory entry */
192 static Entry* alloc_entry()
194 Entry* entry = (Entry*) malloc(sizeof(Entry));
196 #ifdef _SHELL_FOLDERS
198 entry->folder = NULL;
205 /* free a directory entry */
206 static void free_entry(Entry* entry)
208 #ifdef _SHELL_FOLDERS
209 if (entry->hicon && entry->hicon!=(HICON)-1)
210 DestroyIcon(entry->hicon);
212 if (entry->folder && entry->folder!=Globals.iDesktop)
213 (*entry->folder->lpVtbl->Release)(entry->folder);
216 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
222 /* recursively free all child entries */
223 static void free_entries(Entry* dir)
225 Entry *entry, *next=dir->down;
241 static void read_directory_win(Entry* dir, LPCTSTR path)
243 Entry* first_entry = NULL;
247 int level = dir->level + 1;
248 WIN32_FIND_DATA w32fd;
250 #ifndef _NO_EXTENSIONS
254 TCHAR buffer[MAX_PATH], *p;
255 for(p=buffer; *path; )
258 lstrcpy(p, TEXT("\\*"));
260 hFind = FindFirstFile(buffer, &w32fd);
262 if (hFind != INVALID_HANDLE_VALUE) {
264 entry = alloc_entry();
272 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
275 entry->expanded = FALSE;
276 entry->scanned = FALSE;
277 entry->level = level;
279 #ifdef _NO_EXTENSIONS
280 /* hide directory entry "." */
281 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
282 LPCTSTR name = entry->data.cFileName;
284 if (name[0]=='.' && name[1]=='\0')
288 entry->etype = ET_WINDOWS;
289 entry->bhfi_valid = FALSE;
291 lstrcpy(p+1, entry->data.cFileName);
293 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
294 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
296 if (hFile != INVALID_HANDLE_VALUE) {
297 if (GetFileInformationByHandle(hFile, &entry->bhfi))
298 entry->bhfi_valid = TRUE;
305 } while(FindNextFile(hFind, &entry->data));
312 dir->down = first_entry;
317 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
321 for(entry=dir->down; entry; entry=entry->next) {
323 LPCTSTR q = entry->data.cFileName;
326 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
328 } while(tolower(*p++) == tolower(*q++));
331 q = entry->data.cAlternateFileName;
334 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
336 } while(tolower(*p++) == tolower(*q++));
343 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
345 TCHAR buffer[MAX_PATH];
346 Entry* entry = &root->entry;
350 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
352 #ifndef _NO_EXTENSIONS
353 entry->etype = ET_WINDOWS;
357 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
360 while(*s==TEXT('\\') || *s==TEXT('/'))
366 read_directory(entry, buffer, sortOrder, hwnd);
369 entry->expanded = TRUE;
374 entry = find_entry_win(entry, s);
377 SetCursor(old_cursor);
383 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
385 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
387 struct tm* tm = gmtime(t);
393 stime.wYear = tm->tm_year+1900;
394 stime.wMonth = tm->tm_mon+1;
395 /* stime.wDayOfWeek */
396 stime.wDay = tm->tm_mday;
397 stime.wHour = tm->tm_hour;
398 stime.wMinute = tm->tm_min;
399 stime.wSecond = tm->tm_sec;
401 return SystemTimeToFileTime(&stime, ftime);
404 static void read_directory_unix(Entry* dir, LPCTSTR path)
406 Entry* first_entry = NULL;
410 int level = dir->level + 1;
412 DIR* pdir = opendir(path);
417 TCHAR buffer[MAX_PATH], *p;
419 for(p=buffer; *path; )
422 if (p==buffer || p[-1]!='/')
425 while((ent=readdir(pdir))) {
426 entry = alloc_entry();
434 entry->etype = ET_UNIX;
436 lstrcpy(entry->data.cFileName, ent->d_name);
437 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
439 strcpy(p, ent->d_name);
441 if (!stat(buffer, &st)) {
442 if (S_ISDIR(st.st_mode))
443 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
445 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
446 entry->data.nFileSizeHigh = st.st_size >> 32;
448 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
449 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
450 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
452 entry->bhfi.nFileIndexLow = ent->d_ino;
453 entry->bhfi.nFileIndexHigh = 0;
455 entry->bhfi.nNumberOfLinks = st.st_nlink;
457 entry->bhfi_valid = TRUE;
459 entry->data.nFileSizeLow = 0;
460 entry->data.nFileSizeHigh = 0;
461 entry->bhfi_valid = FALSE;
466 entry->expanded = FALSE;
467 entry->scanned = FALSE;
468 entry->level = level;
478 dir->down = first_entry;
482 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
486 for(entry=dir->down; entry; entry=entry->next) {
488 LPCTSTR q = entry->data.cFileName;
491 if (!*p || *p==TEXT('/'))
493 } while(*p++ == *q++);
499 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
501 TCHAR buffer[MAX_PATH];
502 Entry* entry = &root->entry;
506 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
508 entry->etype = ET_UNIX;
511 while(*s && *s!=TEXT('/'))
514 while(*s == TEXT('/'))
520 read_directory(entry, buffer, sortOrder, hwnd);
523 entry->expanded = TRUE;
528 entry = find_entry_unix(entry, s);
531 SetCursor(old_cursor);
536 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
539 #ifdef _SHELL_FOLDERS
542 #define tcscpyn strcpyn
543 #define get_strret get_strretW
544 #define path_from_pidl path_from_pidlW
546 #define tcscpyn wcscpyn
547 #define get_strret get_strretA
548 #define path_from_pidl path_from_pidlA
552 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
557 for(s=source; count&&(*d++=*s++); )
563 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
568 for(s=source; count&&(*d++=*s++); )
575 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
579 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
583 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
587 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
591 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
595 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
599 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
603 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
608 static void free_strret(STRRET* str)
610 if (str->uType == STRRET_WSTR)
611 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
615 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
619 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
622 get_strret(&str, &pidl->mkid, buffer, len);
631 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
635 /* SHGDN_FORPARSING: get full path of id list */
636 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
639 get_strretA(&str, &pidl->mkid, buffer, len);
647 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
651 /* SHGDN_FORPARSING: get full path of id list */
652 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
655 get_strretW(&str, &pidl->mkid, buffer, len);
664 /* create an item id list from a file system path */
666 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
673 LPWSTR buffer = path;
675 WCHAR buffer[MAX_PATH];
676 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
679 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
687 /* convert an item id list from relative to absolute (=relative to the desktop) format */
689 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
691 if (entry->up && entry->up->etype==ET_SHELL) {
692 IShellFolder* folder = entry->up->folder;
693 WCHAR buffer[MAX_PATH];
695 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
701 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
712 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
714 IExtractIcon* pExtract;
716 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
717 TCHAR path[_MAX_PATH];
722 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
723 if (!(flags & GIL_NOTFILENAME)) {
725 idx = 0; /* special case for some control panel applications */
727 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
728 flags &= ~GIL_DONTCACHE;
730 HICON hIconLarge = 0;
732 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
735 DestroyIcon(hIconLarge);
746 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
750 for(entry=dir->down; entry; entry=entry->next) {
751 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
752 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
759 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
761 Entry* entry = &root->entry;
763 LPITEMIDLIST next_pidl = pidl;
764 IShellFolder* folder;
765 IShellFolder* child = NULL;
768 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
770 #ifndef _NO_EXTENSIONS
771 entry->etype = ET_SHELL;
774 folder = Globals.iDesktop;
777 entry->pidl = next_pidl;
778 entry->folder = folder;
783 /* copy first element of item idlist */
784 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
785 memcpy(next_pidl, pidl, pidl->mkid.cb);
786 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
788 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
792 read_directory(entry, NULL, sortOrder, hwnd);
795 entry->expanded = TRUE;
797 next = find_entry_shell(entry, next_pidl);
804 /* go to next element */
805 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
808 SetCursor(old_cursor);
814 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
816 if (!(attribs & SFGAO_FILESYSTEM) ||
817 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
818 WIN32_FILE_ATTRIBUTE_DATA fad;
819 IDataObject* pDataObj;
821 STGMEDIUM medium = {0, {0}, 0};
822 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
824 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
827 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
829 (*pDataObj->lpVtbl->Release)(pDataObj);
832 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
833 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
835 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
836 w32fdata->dwFileAttributes = fad.dwFileAttributes;
837 w32fdata->ftCreationTime = fad.ftCreationTime;
838 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
839 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
841 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
842 w32fdata->nFileSizeLow = fad.nFileSizeLow;
843 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
847 SetErrorMode(sem_org);
849 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
850 GlobalFree(medium.UNION_MEMBER(hGlobal));
855 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
856 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
858 if (attribs & SFGAO_READONLY)
859 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
861 if (attribs & SFGAO_COMPRESSED)
862 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
866 static void read_directory_shell(Entry* dir, HWND hwnd)
868 IShellFolder* folder = dir->folder;
869 int level = dir->level + 1;
875 Entry* first_entry = NULL;
882 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
886 #define FETCH_ITEM_COUNT 32
887 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
892 memset(pidls, 0, sizeof(pidls));
894 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
901 for(n=0; n<cnt; ++n) {
902 entry = alloc_entry();
910 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
911 entry->bhfi_valid = FALSE;
913 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
915 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
918 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
919 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
921 entry->bhfi_valid = TRUE;
927 entry->pidl = pidls[n];
929 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
930 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
933 entry->folder = child;
935 entry->folder = NULL;
938 entry->folder = NULL;
940 if (!entry->data.cFileName[0])
941 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
943 /* get display icons for files and virtual objects */
944 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
945 !(attribs & SFGAO_FILESYSTEM)) {
946 entry->hicon = extract_icon(folder, pidls[n]);
949 entry->hicon = (HICON)-1; /* don't try again later */
954 entry->expanded = FALSE;
955 entry->scanned = FALSE;
956 entry->level = level;
958 #ifndef _NO_EXTENSIONS
959 entry->etype = ET_SHELL;
960 entry->bhfi_valid = FALSE;
967 (*idlist->lpVtbl->Release)(idlist);
973 dir->down = first_entry;
977 #endif /* _SHELL_FOLDERS */
980 /* directories first... */
981 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
983 int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
984 int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
986 return dir2==dir1? 0: dir2<dir1? -1: 1;
990 static int compareName(const void* arg1, const void* arg2)
992 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
993 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
995 int cmp = compareType(fd1, fd2);
999 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1002 static int compareExt(const void* arg1, const void* arg2)
1004 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1005 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1006 const TCHAR *name1, *name2, *ext1, *ext2;
1008 int cmp = compareType(fd1, fd2);
1012 name1 = fd1->cFileName;
1013 name2 = fd2->cFileName;
1015 ext1 = _tcsrchr(name1, TEXT('.'));
1016 ext2 = _tcsrchr(name2, TEXT('.'));
1028 cmp = lstrcmpi(ext1, ext2);
1032 return lstrcmpi(name1, name2);
1035 static int compareSize(const void* arg1, const void* arg2)
1037 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1038 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1040 int cmp = compareType(fd1, fd2);
1044 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1051 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1053 return cmp<0? -1: cmp>0? 1: 0;
1056 static int compareDate(const void* arg1, const void* arg2)
1058 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1059 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1061 int cmp = compareType(fd1, fd2);
1065 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1069 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1070 compareName, /* SORT_NAME */
1071 compareExt, /* SORT_EXT */
1072 compareSize, /* SORT_SIZE */
1073 compareDate /* SORT_DATE */
1077 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1079 Entry* entry = dir->down;
1084 for(entry=dir->down; entry; entry=entry->next)
1088 array = (Entry**) alloca(len*sizeof(Entry*));
1091 for(entry=dir->down; entry; entry=entry->next)
1094 /* call qsort with the appropriate compare function */
1095 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1097 dir->down = array[0];
1099 for(p=array; --len; p++)
1107 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1109 TCHAR buffer[MAX_PATH];
1114 #ifdef _SHELL_FOLDERS
1115 if (dir->etype == ET_SHELL)
1117 read_directory_shell(dir, hwnd);
1119 if (Globals.prescan_node) {
1128 for(entry=dir->down; entry; entry=entry->next)
1129 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1130 read_directory_shell(entry, hwnd);
1131 SortDirectory(entry, sortOrder);
1137 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1138 if (dir->etype == ET_UNIX)
1140 read_directory_unix(dir, path);
1142 if (Globals.prescan_node) {
1151 for(entry=dir->down; entry; entry=entry->next)
1152 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1153 lstrcpy(d, entry->data.cFileName);
1154 read_directory_unix(entry, buffer);
1155 SortDirectory(entry, sortOrder);
1162 read_directory_win(dir, path);
1164 if (Globals.prescan_node) {
1173 for(entry=dir->down; entry; entry=entry->next)
1174 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1175 lstrcpy(d, entry->data.cFileName);
1176 read_directory_win(entry, buffer);
1177 SortDirectory(entry, sortOrder);
1182 SortDirectory(dir, sortOrder);
1186 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1188 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1189 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1190 Root* root = &child->root;
1193 memset(child, 0, sizeof(ChildWnd));
1195 child->left.treePane = TRUE;
1196 child->left.visible_cols = 0;
1198 child->right.treePane = FALSE;
1199 #ifndef _NO_EXTENSIONS
1200 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1202 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1205 child->pos.length = sizeof(WINDOWPLACEMENT);
1206 child->pos.flags = 0;
1207 child->pos.showCmd = SW_SHOWNORMAL;
1208 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1209 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1210 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1211 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1213 child->focus_pane = 0;
1214 child->split_pos = DEFAULT_SPLIT_POS;
1215 child->sortOrder = SORT_NAME;
1216 child->header_wdths_ok = FALSE;
1220 lstrcpy(child->path, path);
1222 _tsplitpath(path, drv, dir, name, ext);
1225 root->entry.level = 0;
1227 #ifdef _SHELL_FOLDERS
1230 root->drive_type = DRIVE_UNKNOWN;
1231 lstrcpy(drv, TEXT("\\"));
1232 lstrcpy(root->volname, TEXT("Desktop"));
1234 lstrcpy(root->fs, TEXT("Shell"));
1236 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1240 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1243 root->drive_type = GetDriveType(path);
1245 lstrcat(drv, TEXT("/"));
1246 lstrcpy(root->volname, TEXT("root fs"));
1248 lstrcpy(root->fs, TEXT("unixfs"));
1250 lstrcpy(root->path, TEXT("/"));
1251 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1256 root->drive_type = GetDriveType(path);
1258 lstrcat(drv, TEXT("\\"));
1259 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1261 lstrcpy(root->path, drv);
1262 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1265 #ifdef _SHELL_FOLDERS
1266 if (root->entry.etype == ET_SHELL)
1267 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1270 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1272 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1274 child->left.root = &root->entry;
1275 child->right.root = NULL;
1277 set_curdir(child, entry, hwnd);
1283 /* free all memory associated with a child window */
1284 static void free_child_window(ChildWnd* child)
1286 free_entries(&child->root.entry);
1291 /* get full path of specified directory entry */
1292 static void get_path(Entry* dir, PTSTR path)
1298 #ifdef _SHELL_FOLDERS
1299 if (dir->etype == ET_SHELL)
1304 path[0] = TEXT('\0');
1309 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1311 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1312 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1314 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1320 for(entry=dir; entry; level++) {
1326 name = entry->data.cFileName;
1329 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1335 memmove(path+l+1, path, len*sizeof(TCHAR));
1336 memcpy(path+1, name, l*sizeof(TCHAR));
1339 #ifndef _NO_EXTENSIONS
1340 if (entry->etype == ET_UNIX)
1341 path[0] = TEXT('/');
1344 path[0] = TEXT('\\');
1349 memmove(path+l, path, len*sizeof(TCHAR));
1350 memcpy(path, name, l*sizeof(TCHAR));
1357 #ifndef _NO_EXTENSIONS
1358 if (entry->etype == ET_UNIX)
1359 path[len++] = TEXT('/');
1362 path[len++] = TEXT('\\');
1365 path[len] = TEXT('\0');
1370 static void resize_frame_rect(HWND hwnd, PRECT prect)
1375 if (IsWindowVisible(Globals.htoolbar)) {
1376 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1377 GetClientRect(Globals.htoolbar, &rt);
1378 prect->top = rt.bottom+3;
1379 prect->bottom -= rt.bottom+3;
1382 if (IsWindowVisible(Globals.hdrivebar)) {
1383 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1384 GetClientRect(Globals.hdrivebar, &rt);
1385 new_top = --prect->top + rt.bottom+3;
1386 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1387 prect->top = new_top;
1388 prect->bottom -= rt.bottom+2;
1391 if (IsWindowVisible(Globals.hstatusbar)) {
1392 int parts[] = {300, 500};
1394 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1395 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1396 GetClientRect(Globals.hstatusbar, &rt);
1397 prect->bottom -= rt.bottom;
1400 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1403 static void resize_frame(HWND hwnd, int cx, int cy)
1412 resize_frame_rect(hwnd, &rect);
1415 static void resize_frame_client(HWND hwnd)
1419 GetClientRect(hwnd, &rect);
1421 resize_frame_rect(hwnd, &rect);
1425 static HHOOK hcbthook;
1426 static ChildWnd* newchild = NULL;
1428 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1430 if (code==HCBT_CREATEWND && newchild) {
1431 ChildWnd* child = newchild;
1434 child->hwnd = (HWND) wparam;
1435 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1438 return CallNextHookEx(hcbthook, code, wparam, lparam);
1441 static HWND create_child_window(ChildWnd* child)
1443 MDICREATESTRUCT mcs;
1446 mcs.szClass = WINEFILETREE;
1447 mcs.szTitle = (LPTSTR)child->path;
1448 mcs.hOwner = Globals.hInstance;
1449 mcs.x = child->pos.rcNormalPosition.left;
1450 mcs.y = child->pos.rcNormalPosition.top;
1451 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1452 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1456 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1459 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1461 UnhookWindowsHookEx(hcbthook);
1465 UnhookWindowsHookEx(hcbthook);
1467 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1468 ListBox_SetCurSel(child->left.hwnd, idx);
1474 struct ExecuteDialog {
1475 TCHAR cmd[MAX_PATH];
1480 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1482 static struct ExecuteDialog* dlg;
1486 dlg = (struct ExecuteDialog*) lparam;
1490 int id = (int)wparam;
1493 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1494 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1495 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1496 EndDialog(hwnd, id);
1497 } else if (id == IDCANCEL)
1498 EndDialog(hwnd, id);
1507 #ifndef _NO_EXTENSIONS
1509 static struct FullScreenParameters {
1519 void frame_get_clientspace(HWND hwnd, PRECT prect)
1523 if (!IsIconic(hwnd))
1524 GetClientRect(hwnd, prect);
1528 GetWindowPlacement(hwnd, &wp);
1530 prect->left = prect->top = 0;
1531 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1532 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1533 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1534 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1535 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1538 if (IsWindowVisible(Globals.htoolbar)) {
1539 GetClientRect(Globals.htoolbar, &rt);
1540 prect->top += rt.bottom+2;
1543 if (IsWindowVisible(Globals.hdrivebar)) {
1544 GetClientRect(Globals.hdrivebar, &rt);
1545 prect->top += rt.bottom+2;
1548 if (IsWindowVisible(Globals.hstatusbar)) {
1549 GetClientRect(Globals.hstatusbar, &rt);
1550 prect->bottom -= rt.bottom;
1554 static BOOL toggle_fullscreen(HWND hwnd)
1558 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1559 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1560 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1562 Frame_CalcFrameClient(hwnd, &rt);
1563 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1564 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1566 rt.left = g_fullscreen.orgPos.left-rt.left;
1567 rt.top = g_fullscreen.orgPos.top-rt.top;
1568 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1569 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1571 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1573 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1574 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1575 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1577 if (g_fullscreen.wasZoomed)
1578 ShowWindow(hwnd, WS_MAXIMIZE);
1581 return g_fullscreen.mode;
1584 static void fullscreen_move(HWND hwnd)
1587 GetWindowRect(hwnd, &pos);
1589 Frame_CalcFrameClient(hwnd, &rt);
1590 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1591 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1593 rt.left = pos.left-rt.left;
1594 rt.top = pos.top-rt.top;
1595 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1596 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1598 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1604 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1606 BOOL vis = IsWindowVisible(hchild);
1608 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1610 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1612 #ifndef _NO_EXTENSIONS
1613 if (g_fullscreen.mode)
1614 fullscreen_move(hwnd);
1617 resize_frame_client(hwnd);
1620 BOOL activate_drive_window(LPCTSTR path)
1622 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1625 _tsplitpath(path, drv1, 0, 0, 0);
1627 /* search for a already open window for the same drive */
1628 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1629 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1632 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1634 if (!lstrcmpi(drv2, drv1)) {
1635 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1637 if (IsMinimized(child_wnd))
1638 ShowWindow(child_wnd, SW_SHOWNORMAL);
1648 BOOL activate_fs_window(LPCTSTR filesys)
1652 /* search for a already open window of the given file system name */
1653 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1654 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1657 if (!lstrcmpi(child->root.fs, filesys)) {
1658 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1660 if (IsMinimized(child_wnd))
1661 ShowWindow(child_wnd, SW_SHOWNORMAL);
1671 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1675 DestroyWindow(hwnd);
1677 /* clear handle variables */
1678 Globals.hMenuFrame = 0;
1679 Globals.hMenuView = 0;
1680 Globals.hMenuOptions = 0;
1681 Globals.hMainWnd = 0;
1682 Globals.hmdiclient = 0;
1683 Globals.hdrivebar = 0;
1687 /* don't exit desktop when closing file manager window */
1688 if (!Globals.hwndParent)
1693 UINT cmd = LOWORD(wparam);
1694 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1696 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1699 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1700 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1702 LPCTSTR root = Globals.drives;
1705 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1709 if (activate_drive_window(root))
1712 _tsplitpath(root, drv, 0, 0, 0);
1714 if (!SetCurrentDirectory(drv)) {
1715 display_error(hwnd, GetLastError());
1719 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1720 child = alloc_child_window(path, NULL, hwnd);
1722 if (!create_child_window(child))
1724 } else switch(cmd) {
1726 SendMessage(hwnd, WM_CLOSE, 0, 0);
1729 case ID_WINDOW_NEW: {
1730 TCHAR path[MAX_PATH];
1733 GetCurrentDirectory(MAX_PATH, path);
1734 child = alloc_child_window(path, NULL, hwnd);
1736 if (!create_child_window(child))
1740 case ID_WINDOW_CASCADE:
1741 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1744 case ID_WINDOW_TILE_HORZ:
1745 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1748 case ID_WINDOW_TILE_VERT:
1749 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1752 case ID_WINDOW_ARRANGE:
1753 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1756 case ID_VIEW_TOOL_BAR:
1757 toggle_child(hwnd, cmd, Globals.htoolbar);
1760 case ID_VIEW_DRIVE_BAR:
1761 toggle_child(hwnd, cmd, Globals.hdrivebar);
1764 case ID_VIEW_STATUSBAR:
1765 toggle_child(hwnd, cmd, Globals.hstatusbar);
1769 struct ExecuteDialog dlg;
1771 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1773 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1774 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1776 if ((int)hinst <= 32)
1777 display_error(hwnd, GetLastError());
1782 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1785 #ifndef _NO_EXTENSIONS
1786 case ID_VIEW_FULLSCREEN:
1787 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1791 case ID_DRIVE_UNIX_FS: {
1792 TCHAR path[MAX_PATH];
1795 if (activate_fs_window(TEXT("unixfs")))
1798 getcwd(path, MAX_PATH);
1799 child = alloc_child_window(path, NULL, hwnd);
1801 if (!create_child_window(child))
1805 #ifdef _SHELL_FOLDERS
1806 case ID_DRIVE_SHELL_NS: {
1807 TCHAR path[MAX_PATH];
1810 if (activate_fs_window(TEXT("Shell")))
1813 GetCurrentDirectory(MAX_PATH, path);
1814 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1816 if (!create_child_window(child))
1822 /*TODO: There are even more menu items! */
1824 #ifndef _NO_EXTENSIONS
1827 WineLicense(Globals.hMainWnd);
1830 case ID_NO_WARRANTY:
1831 WineWarranty(Globals.hMainWnd);
1836 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1839 case ID_ABOUT: /*ID_ABOUT_WINE: */
1840 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1842 #endif /* _NO_EXTENSIONS */
1845 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1846 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1847 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1848 (cmd<SC_SIZE || cmd>SC_RESTORE))
1849 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1851 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1856 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1857 break; /* do not pass message to DefFrameProc */
1859 #ifndef _NO_EXTENSIONS
1860 case WM_GETMINMAXINFO: {
1861 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1863 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1864 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1867 case FRM_CALC_CLIENT:
1868 frame_get_clientspace(hwnd, (PRECT)lparam);
1870 #endif /* _NO_EXTENSIONS */
1873 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1880 static const LPTSTR g_pos_names[COLUMNS] = {
1881 TEXT(""), /* symbol */
1885 #ifndef _NO_EXTENSIONS
1888 TEXT("Index/Inode"),
1890 #endif /* _NO_EXTENSIONS */
1892 #ifndef _NO_EXTENSIONS
1897 static const int g_pos_align[] = {
1899 HDF_LEFT, /* Name */
1900 HDF_RIGHT, /* Size */
1901 HDF_LEFT, /* CDate */
1902 #ifndef _NO_EXTENSIONS
1903 HDF_LEFT, /* ADate */
1904 HDF_LEFT, /* MDate */
1905 HDF_LEFT, /* Index */
1906 HDF_CENTER, /* Links */
1908 HDF_CENTER, /* Attributes */
1909 #ifndef _NO_EXTENSIONS
1910 HDF_LEFT /* Security */
1914 static void resize_tree(ChildWnd* child, int cx, int cy)
1916 HDWP hdwp = BeginDeferWindowPos(4);
1924 cx = child->split_pos + SPLIT_WIDTH/2;
1926 #ifndef _NO_EXTENSIONS
1934 Header_Layout(child->left.hwndHeader, &hdl);
1936 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1937 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1938 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1939 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1941 #endif /* _NO_EXTENSIONS */
1943 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);
1944 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1946 EndDeferWindowPos(hdwp);
1950 #ifndef _NO_EXTENSIONS
1952 static HWND create_header(HWND parent, Pane* pane, int id)
1957 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1958 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1962 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1964 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1966 for(idx=0; idx<COLUMNS; idx++) {
1967 hdi.pszText = g_pos_names[idx];
1968 hdi.fmt = HDF_STRING | g_pos_align[idx];
1969 hdi.cxy = pane->widths[idx];
1970 Header_InsertItem(hwnd, idx, &hdi);
1976 #endif /* _NO_EXTENSIONS */
1979 static void init_output(HWND hwnd)
1983 HDC hdc = GetDC(hwnd);
1985 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1986 Globals.num_sep = b[1];
1988 Globals.num_sep = TEXT('.');
1990 old_font = SelectFont(hdc, Globals.hfont);
1991 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1992 SelectFont(hdc, old_font);
1993 ReleaseDC(hwnd, hdc);
1996 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
1999 /* calculate prefered width for all visible columns */
2001 static BOOL calc_widths(Pane* pane, BOOL anyway)
2003 int col, x, cx, spc=3*Globals.spaceSize.cx;
2004 int entries = ListBox_GetCount(pane->hwnd);
2005 int orgWidths[COLUMNS];
2006 int orgPositions[COLUMNS+1];
2012 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2013 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2016 for(col=0; col<COLUMNS; col++)
2017 pane->widths[col] = 0;
2019 hdc = GetDC(pane->hwnd);
2020 hfontOld = SelectFont(hdc, Globals.hfont);
2022 for(cnt=0; cnt<entries; cnt++) {
2023 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2032 dis.hwndItem = pane->hwnd;
2034 dis.rcItem.left = 0;
2036 dis.rcItem.right = 0;
2037 dis.rcItem.bottom = 0;
2038 /*dis.itemData = 0; */
2040 draw_item(pane, &dis, entry, COLUMNS);
2043 SelectObject(hdc, hfontOld);
2044 ReleaseDC(pane->hwnd, hdc);
2047 for(col=0; col<COLUMNS; col++) {
2048 pane->positions[col] = x;
2049 cx = pane->widths[col];
2054 if (cx < IMAGE_WIDTH)
2057 pane->widths[col] = cx;
2063 pane->positions[COLUMNS] = x;
2065 ListBox_SetHorizontalExtent(pane->hwnd, x);
2068 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2071 /* don't move, if only collapsing an entry */
2072 if (!anyway && pane->widths[0]<orgWidths[0] &&
2073 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2074 pane->widths[0] = orgWidths[0];
2075 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2080 InvalidateRect(pane->hwnd, 0, TRUE);
2086 /* calculate one prefered column width */
2088 static void calc_single_width(Pane* pane, int col)
2092 int entries = ListBox_GetCount(pane->hwnd);
2096 pane->widths[col] = 0;
2098 hdc = GetDC(pane->hwnd);
2099 hfontOld = SelectFont(hdc, Globals.hfont);
2101 for(cnt=0; cnt<entries; cnt++) {
2102 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2110 dis.hwndItem = pane->hwnd;
2112 dis.rcItem.left = 0;
2114 dis.rcItem.right = 0;
2115 dis.rcItem.bottom = 0;
2116 /*dis.itemData = 0; */
2118 draw_item(pane, &dis, entry, col);
2121 SelectObject(hdc, hfontOld);
2122 ReleaseDC(pane->hwnd, hdc);
2124 cx = pane->widths[col];
2127 cx += 3*Globals.spaceSize.cx;
2129 if (cx < IMAGE_WIDTH)
2133 pane->widths[col] = cx;
2135 x = pane->positions[col] + cx;
2137 for(; col<COLUMNS; ) {
2138 pane->positions[++col] = x;
2139 x += pane->widths[col];
2142 ListBox_SetHorizontalExtent(pane->hwnd, x);
2146 /* insert listbox entries after index idx */
2148 static void insert_entries(Pane* pane, Entry* dir, int idx)
2155 ShowWindow(pane->hwnd, SW_HIDE);
2157 for(; entry; entry=entry->next) {
2159 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2163 /* don't display entries "." and ".." in the left pane */
2164 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2165 && entry->data.cFileName[0]==TEXT('.'))
2167 #ifndef _NO_EXTENSIONS
2168 entry->data.cFileName[1]==TEXT('\0') ||
2170 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2176 ListBox_InsertItemData(pane->hwnd, idx, entry);
2178 if (pane->treePane && entry->expanded)
2179 insert_entries(pane, entry->down, idx);
2182 ShowWindow(pane->hwnd, SW_SHOW);
2186 static WNDPROC g_orgTreeWndProc;
2188 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2190 static int s_init = 0;
2191 Entry* entry = pane->root;
2193 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2194 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2195 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2197 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2198 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2200 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2202 /* insert entries into listbox */
2204 insert_entries(pane, entry, -1);
2206 /* calculate column widths */
2209 init_output(pane->hwnd);
2212 calc_widths(pane, TRUE);
2214 #ifndef _NO_EXTENSIONS
2215 pane->hwndHeader = create_header(parent, pane, id_header);
2220 static void InitChildWindow(ChildWnd* child)
2222 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2223 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2227 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2233 *buffer = TEXT('\0');
2235 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2238 if (!FileTimeToLocalFileTime(ft, &lft))
2239 {err: _tcscpy(buffer,TEXT("???")); return;}
2241 if (!FileTimeToSystemTime(&lft, &systime))
2244 if (visible_cols & COL_DATE) {
2245 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2250 if (visible_cols & COL_TIME) {
2252 buffer[len-1] = ' ';
2254 buffer[len++] = ' ';
2256 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2257 buffer[len] = TEXT('\0');
2262 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2264 RECT rt = {0, 0, 0, 0};
2266 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2268 if (rt.right > pane->widths[col])
2269 pane->widths[col] = rt.right;
2272 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2274 RECT rt = {0, 0, 0, 0};
2276 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2277 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2279 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2280 /*FIXME rt (0,0) ??? */
2282 if (rt.right > pane->widths[col])
2283 pane->widths[col] = rt.right;
2287 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2289 int x = dis->rcItem.left;
2292 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2293 rt.top = dis->rcItem.top;
2294 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2295 rt.bottom = dis->rcItem.bottom;
2297 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2300 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2302 int x = dis->rcItem.left;
2305 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2306 rt.top = dis->rcItem.top;
2307 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2308 rt.bottom = dis->rcItem.bottom;
2310 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2311 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2313 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2316 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2318 int x = dis->rcItem.left;
2325 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2326 rt.top = dis->rcItem.top;
2327 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2328 rt.bottom = dis->rcItem.bottom;
2333 /* insert number separator characters */
2334 pos = lstrlen(s) % 3;
2340 *d++ = Globals.num_sep;
2344 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2348 static int is_exe_file(LPCTSTR ext)
2350 static const LPCTSTR executable_extensions[] = {
2355 #ifndef _NO_EXTENSIONS
2359 #endif /* _NO_EXTENSIONS */
2363 TCHAR ext_buffer[_MAX_EXT];
2368 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2371 for(p=executable_extensions; *p; p++)
2372 if (!_tcscmp(ext_buffer, *p))
2378 static int is_registered_type(LPCTSTR ext)
2386 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2388 TCHAR buffer[BUFFER_LEN];
2390 int visible_cols = pane->visible_cols;
2391 COLORREF bkcolor, textcolor;
2392 RECT focusRect = dis->rcItem;
2399 attrs = entry->data.dwFileAttributes;
2401 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2402 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2403 && entry->data.cFileName[2]==TEXT('\0'))
2404 img = IMG_FOLDER_UP;
2405 #ifndef _NO_EXTENSIONS
2406 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2407 img = IMG_FOLDER_CUR;
2410 #ifdef _NO_EXTENSIONS
2413 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2414 img = IMG_OPEN_FOLDER;
2418 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2422 if (is_exe_file(ext))
2423 img = IMG_EXECUTABLE;
2424 else if (is_registered_type(ext))
2434 if (pane->treePane) {
2436 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2438 if (calcWidthCol == -1) {
2440 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2443 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2446 rt_clip.left = dis->rcItem.left;
2447 rt_clip.top = dis->rcItem.top;
2448 rt_clip.right = dis->rcItem.left+pane->widths[col];
2449 rt_clip.bottom = dis->rcItem.bottom;
2451 hrgn = CreateRectRgnIndirect(&rt_clip);
2453 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2454 DeleteObject(hrgn_org);
2458 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2459 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2462 if ((up=entry->up) != NULL) {
2463 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2464 LineTo(dis->hDC, img_pos-2, y);
2466 x = img_pos - IMAGE_WIDTH/2;
2469 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2473 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2476 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2477 LineTo(dis->hDC, x, dis->rcItem.bottom);
2479 } while((up=up->up) != NULL);
2482 x = img_pos - IMAGE_WIDTH/2;
2484 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2485 LineTo(dis->hDC, x, y);
2489 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2492 LineTo(dis->hDC, x, dis->rcItem.bottom);
2494 if (entry->down && entry->expanded) {
2495 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2496 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2497 LineTo(dis->hDC, x, dis->rcItem.bottom);
2500 SelectClipRgn(dis->hDC, hrgn_org);
2501 if (hrgn_org) DeleteObject(hrgn_org);
2502 /* SelectObject(dis->hDC, holdPen); */
2503 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2504 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2506 if (right > pane->widths[col])
2507 pane->widths[col] = right;
2510 img_pos = dis->rcItem.left;
2513 img_pos = dis->rcItem.left;
2515 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2516 pane->widths[col] = IMAGE_WIDTH;
2519 if (calcWidthCol == -1) {
2520 focusRect.left = img_pos -2;
2522 #ifdef _NO_EXTENSIONS
2523 if (pane->treePane && entry) {
2526 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2528 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2532 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2533 textcolor = COLOR_COMPRESSED;
2535 #endif /* _NO_EXTENSIONS */
2536 textcolor = RGB(0,0,0);
2538 if (dis->itemState & ODS_FOCUS) {
2539 textcolor = RGB(255,255,255);
2540 bkcolor = COLOR_SELECTION;
2542 bkcolor = RGB(255,255,255);
2545 hbrush = CreateSolidBrush(bkcolor);
2546 FillRect(dis->hDC, &focusRect, hbrush);
2547 DeleteObject(hbrush);
2549 SetBkMode(dis->hDC, TRANSPARENT);
2550 SetTextColor(dis->hDC, textcolor);
2552 cx = pane->widths[col];
2554 if (cx && img!=IMG_NONE) {
2555 if (cx > IMAGE_WIDTH)
2558 #ifdef _SHELL_FOLDERS
2559 if (entry->hicon && entry->hicon!=(HICON)-1)
2560 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2563 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2564 img_pos, dis->rcItem.top, cx,
2565 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2572 #ifdef _NO_EXTENSIONS
2573 if (img >= IMG_FOLDER_UP)
2579 /* ouput file name */
2580 if (calcWidthCol == -1)
2581 output_text(pane, dis, col, entry->data.cFileName, 0);
2582 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2583 calc_width(pane, dis, col, entry->data.cFileName);
2587 #ifdef _NO_EXTENSIONS
2588 if (!pane->treePane) {
2591 /* display file size */
2592 if (visible_cols & COL_SIZE) {
2593 #ifdef _NO_EXTENSIONS
2594 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2599 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2601 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2603 if (calcWidthCol == -1)
2604 output_number(pane, dis, col, buffer);
2605 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2606 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2612 /* display file date */
2613 if (visible_cols & (COL_DATE|COL_TIME)) {
2614 #ifndef _NO_EXTENSIONS
2615 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2616 if (calcWidthCol == -1)
2617 output_text(pane, dis, col, buffer, 0);
2618 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2619 calc_width(pane, dis, col, buffer);
2622 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2623 if (calcWidthCol == -1)
2624 output_text(pane, dis, col, buffer, 0);
2625 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2626 calc_width(pane, dis, col, buffer);
2628 #endif /* _NO_EXTENSIONS */
2630 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2631 if (calcWidthCol == -1)
2632 output_text(pane, dis, col, buffer, 0);
2633 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2634 calc_width(pane, dis, col, buffer);
2638 #ifndef _NO_EXTENSIONS
2639 if (entry->bhfi_valid) {
2640 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2642 if (visible_cols & COL_INDEX) {
2643 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2644 if (calcWidthCol == -1)
2645 output_text(pane, dis, col, buffer, DT_RIGHT);
2646 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2647 calc_width(pane, dis, col, buffer);
2651 if (visible_cols & COL_LINKS) {
2652 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2653 if (calcWidthCol == -1)
2654 output_text(pane, dis, col, buffer, DT_CENTER);
2655 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2656 calc_width(pane, dis, col, buffer);
2661 #endif /* _NO_EXTENSIONS */
2663 /* show file attributes */
2664 if (visible_cols & COL_ATTRIBUTES) {
2665 #ifdef _NO_EXTENSIONS
2666 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2668 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2671 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2673 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2674 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2675 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2676 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2677 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2678 #ifndef _NO_EXTENSIONS
2679 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2680 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2681 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2682 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2683 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2684 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2685 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2686 #endif /* _NO_EXTENSIONS */
2689 if (calcWidthCol == -1)
2690 output_tabbed_text(pane, dis, col, buffer);
2691 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2692 calc_tabbed_width(pane, dis, col, buffer);
2698 if (flags.security) {
2699 DWORD rights = get_access_mask();
2701 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2703 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2704 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2705 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2706 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2707 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2708 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2709 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2710 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2711 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2712 if (rights & WRITE_DAC) buffer[22] = 'C';
2713 if (rights & WRITE_OWNER) buffer[24] = 'O';
2714 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2716 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2719 if (flags.description) {
2720 get_description(buffer);
2721 output_text(dis, col++, buffer, 0, psize);
2725 #ifdef _NO_EXTENSIONS
2728 /* draw focus frame */
2729 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2730 /* Currently [04/2000] Wine neither behaves exactly the same */
2731 /* way as WIN 95 nor like Windows NT... */
2736 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2737 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2738 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2740 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2742 lastPen = SelectPen(dis->hDC, hpen);
2743 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2744 SetROP2(dis->hDC, R2_XORPEN);
2745 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2746 SelectObject(dis->hDC, lastBrush);
2747 SelectObject(dis->hDC, lastPen);
2750 #endif /* _NO_EXTENSIONS */
2754 #ifdef _NO_EXTENSIONS
2756 static void draw_splitbar(HWND hwnd, int x)
2759 HDC hdc = GetDC(hwnd);
2761 GetClientRect(hwnd, &rt);
2763 rt.left = x - SPLIT_WIDTH/2;
2764 rt.right = x + SPLIT_WIDTH/2+1;
2766 InvertRect(hdc, &rt);
2768 ReleaseDC(hwnd, hdc);
2771 #endif /* _NO_EXTENSIONS */
2774 #ifndef _NO_EXTENSIONS
2776 static void set_header(Pane* pane)
2779 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2782 item.mask = HDI_WIDTH;
2785 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2786 x += pane->widths[i];
2787 Header_SetItem(pane->hwndHeader, i, &item);
2791 x += pane->widths[i];
2792 item.cxy = x - scroll_pos;
2793 Header_SetItem(pane->hwndHeader, i++, &item);
2795 for(; i<COLUMNS; i++) {
2796 item.cxy = pane->widths[i];
2797 x += pane->widths[i];
2798 Header_SetItem(pane->hwndHeader, i, &item);
2803 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2805 switch(pnmh->code) {
2807 case HDN_ENDTRACK: {
2808 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2809 int idx = phdn->iItem;
2810 int dx = phdn->pitem->cxy - pane->widths[idx];
2814 GetClientRect(pane->hwnd, &clnt);
2816 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not realy needed with WINELIB) */
2817 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2819 pane->widths[idx] += dx;
2821 for(i=idx; ++i<=COLUMNS; )
2822 pane->positions[i] += dx;
2825 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2829 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2831 rt_scr.right = clnt.right;
2832 rt_scr.bottom = clnt.bottom;
2834 rt_clip.left = pane->positions[idx]-scroll_pos;
2836 rt_clip.right = clnt.right;
2837 rt_clip.bottom = clnt.bottom;
2839 if (rt_scr.left < 0) rt_scr.left = 0;
2840 if (rt_clip.left < 0) rt_clip.left = 0;
2842 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2844 rt_clip.right = pane->positions[idx+1];
2845 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2847 if (pnmh->code == HDN_ENDTRACK) {
2848 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2850 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2858 case HDN_DIVIDERDBLCLICK: {
2859 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2862 calc_single_width(pane, phdn->iItem);
2863 item.mask = HDI_WIDTH;
2864 item.cxy = pane->widths[phdn->iItem];
2866 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2867 InvalidateRect(pane->hwnd, 0, TRUE);
2874 #endif /* _NO_EXTENSIONS */
2877 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2879 TCHAR path[MAX_PATH];
2880 int idx = ListBox_GetCurSel(child->left.hwnd);
2881 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2883 /* delete sub entries in left pane */
2885 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2886 Entry* sub = (Entry*) res;
2888 if (res==LB_ERR || !sub || sub->level<=entry->level)
2891 ListBox_DeleteString(child->left.hwnd, idx+1);
2894 /* empty right pane */
2895 ListBox_ResetContent(child->right.hwnd);
2897 /* release memory */
2898 free_entries(entry);
2900 /* read contents from disk */
2901 #ifdef _SHELL_FOLDERS
2902 if (entry->etype == ET_SHELL)
2904 read_directory(entry, NULL, child->sortOrder, hwnd);
2909 get_path(entry, path);
2910 read_directory(entry, path, child->sortOrder, hwnd);
2913 /* insert found entries in right pane */
2914 insert_entries(&child->right, entry->down, -1);
2915 calc_widths(&child->right, FALSE);
2916 #ifndef _NO_EXTENSIONS
2917 set_header(&child->right);
2920 child->header_wdths_ok = FALSE;
2922 SetCursor(old_cursor);
2926 /* expand a directory entry */
2928 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2933 if (!dir || dir->expanded || !dir->down)
2938 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2941 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2942 p->data.cFileName[2]=='\0' && p->next)
2946 /* no subdirectories ? */
2947 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2950 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2952 dir->expanded = TRUE;
2954 /* insert entries in left pane */
2955 insert_entries(&child->left, p, idx);
2957 if (!child->header_wdths_ok) {
2958 if (calc_widths(&child->left, FALSE)) {
2959 #ifndef _NO_EXTENSIONS
2960 set_header(&child->left);
2963 child->header_wdths_ok = TRUE;
2971 static void collapse_entry(Pane* pane, Entry* dir)
2973 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2975 ShowWindow(pane->hwnd, SW_HIDE);
2977 /* hide sub entries */
2979 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2980 Entry* sub = (Entry*) res;
2982 if (res==LB_ERR || !sub || sub->level<=dir->level)
2985 ListBox_DeleteString(pane->hwnd, idx+1);
2988 dir->expanded = FALSE;
2990 ShowWindow(pane->hwnd, SW_SHOW);
2994 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
2996 TCHAR path[MAX_PATH];
3000 child->left.cur = entry;
3001 child->right.root = entry->down? entry->down: entry;
3002 child->right.cur = entry;
3004 if (!entry->scanned)
3005 scan_entry(child, entry, hwnd);
3007 ListBox_ResetContent(child->right.hwnd);
3008 insert_entries(&child->right, entry->down, -1);
3009 calc_widths(&child->right, FALSE);
3010 #ifndef _NO_EXTENSIONS
3011 set_header(&child->right);
3015 get_path(entry, path);
3016 lstrcpy(child->path, path);
3018 if (child->hwnd) /* only change window title, if the window already exists */
3019 SetWindowText(child->hwnd, path);
3022 SetCurrentDirectory(path);
3026 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3028 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3030 if ((int)hinst <= 32) {
3031 display_error(hwnd, GetLastError());
3039 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3041 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3043 if ((int)hinst <= 32) {
3044 display_error(hwnd, GetLastError());
3053 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3055 TCHAR cmd[MAX_PATH];
3057 #ifdef _SHELL_FOLDERS
3058 if (entry->etype == ET_SHELL) {
3061 SHELLEXECUTEINFO shexinfo;
3063 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3064 shexinfo.fMask = SEE_MASK_IDLIST;
3065 shexinfo.hwnd = hwnd;
3066 shexinfo.nShow = nCmdShow;
3067 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3069 if (!ShellExecuteEx(&shexinfo)) {
3070 display_error(hwnd, GetLastError());
3074 if (shexinfo.lpIDList != entry->pidl)
3075 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3081 get_path(entry, cmd);
3083 /* start program, open document... */
3084 return launch_file(hwnd, cmd, nCmdShow);
3088 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3090 Entry* entry = pane->cur;
3095 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3096 int scanned_old = entry->scanned;
3099 scan_entry(child, entry, hwnd);
3101 #ifndef _NO_EXTENSIONS
3102 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3106 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3107 entry = child->left.cur->up;
3108 collapse_entry(&child->left, entry);
3110 } else if (entry->expanded)
3111 collapse_entry(pane, child->left.cur);
3113 expand_entry(child, child->left.cur);
3115 if (!pane->treePane) focus_entry: {
3116 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3117 ListBox_SetCurSel(child->left.hwnd, idx);
3118 set_curdir(child, entry, hwnd);
3123 calc_widths(pane, FALSE);
3125 #ifndef _NO_EXTENSIONS
3130 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3135 static BOOL pane_command(Pane* pane, UINT cmd)
3139 if (pane->visible_cols) {
3140 pane->visible_cols = 0;
3141 calc_widths(pane, TRUE);
3142 #ifndef _NO_EXTENSIONS
3145 InvalidateRect(pane->hwnd, 0, TRUE);
3146 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3147 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3148 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3152 case ID_VIEW_ALL_ATTRIBUTES:
3153 if (pane->visible_cols != COL_ALL) {
3154 pane->visible_cols = COL_ALL;
3155 calc_widths(pane, TRUE);
3156 #ifndef _NO_EXTENSIONS
3159 InvalidateRect(pane->hwnd, 0, TRUE);
3160 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3161 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3162 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3166 #ifndef _NO_EXTENSIONS
3167 case ID_PREFERED_SIZES: {
3168 calc_widths(pane, TRUE);
3170 InvalidateRect(pane->hwnd, 0, TRUE);
3174 /* TODO: more command ids... */
3184 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3186 static int last_split;
3188 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3193 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3194 Entry* entry = (Entry*) dis->itemData;
3196 if (dis->CtlID == IDW_TREE_LEFT)
3197 draw_item(&child->left, dis, entry, -1);
3199 draw_item(&child->right, dis, entry, -1);
3204 InitChildWindow(child);
3208 free_child_window(child);
3209 SetWindowLong(hwnd, GWL_USERDATA, 0);
3216 GetClientRect(hwnd, &rt);
3217 BeginPaint(hwnd, &ps);
3218 rt.left = child->split_pos-SPLIT_WIDTH/2;
3219 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3220 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3221 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3222 SelectObject(ps.hdc, lastBrush);
3223 #ifdef _NO_EXTENSIONS
3224 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3225 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3227 EndPaint(hwnd, &ps);
3231 if (LOWORD(lparam) == HTCLIENT) {
3234 ScreenToClient(hwnd, &pt);
3236 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3237 SetCursor(LoadCursor(0, IDC_SIZEWE));
3243 case WM_LBUTTONDOWN: {
3245 int x = LOWORD(lparam);
3247 GetClientRect(hwnd, &rt);
3249 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3250 last_split = child->split_pos;
3251 #ifdef _NO_EXTENSIONS
3252 draw_splitbar(hwnd, last_split);
3260 if (GetCapture() == hwnd) {
3261 #ifdef _NO_EXTENSIONS
3263 int x = LOWORD(lparam);
3264 draw_splitbar(hwnd, last_split);
3266 GetClientRect(hwnd, &rt);
3267 child->split_pos = x;
3268 resize_tree(child, rt.right, rt.bottom);
3274 #ifdef _NO_EXTENSIONS
3275 case WM_CAPTURECHANGED:
3276 if (GetCapture()==hwnd && last_split>=0)
3277 draw_splitbar(hwnd, last_split);
3282 if (wparam == VK_ESCAPE)
3283 if (GetCapture() == hwnd) {
3285 #ifdef _NO_EXTENSIONS
3286 draw_splitbar(hwnd, last_split);
3288 child->split_pos = last_split;
3290 GetClientRect(hwnd, &rt);
3291 resize_tree(child, rt.right, rt.bottom);
3294 SetCursor(LoadCursor(0, IDC_ARROW));
3299 if (GetCapture() == hwnd) {
3301 int x = LOWORD(lparam);
3303 #ifdef _NO_EXTENSIONS
3304 HDC hdc = GetDC(hwnd);
3305 GetClientRect(hwnd, &rt);
3307 rt.left = last_split-SPLIT_WIDTH/2;
3308 rt.right = last_split+SPLIT_WIDTH/2+1;
3309 InvertRect(hdc, &rt);
3312 rt.left = x-SPLIT_WIDTH/2;
3313 rt.right = x+SPLIT_WIDTH/2+1;
3314 InvertRect(hdc, &rt);
3316 ReleaseDC(hwnd, hdc);
3318 GetClientRect(hwnd, &rt);
3320 if (x>=0 && x<rt.right) {
3321 child->split_pos = x;
3322 resize_tree(child, rt.right, rt.bottom);
3323 rt.left = x-SPLIT_WIDTH/2;
3324 rt.right = x+SPLIT_WIDTH/2+1;
3325 InvalidateRect(hwnd, &rt, FALSE);
3326 UpdateWindow(child->left.hwnd);
3328 UpdateWindow(child->right.hwnd);
3334 #ifndef _NO_EXTENSIONS
3335 case WM_GETMINMAXINFO:
3336 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3338 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3340 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3341 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3343 #endif /* _NO_EXTENSIONS */
3346 SetCurrentDirectory(child->path);
3347 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3350 case WM_DISPATCH_COMMAND: {
3351 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3353 switch(LOWORD(wparam)) {
3354 case ID_WINDOW_NEW: {
3355 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3357 if (!create_child_window(new_child))
3363 scan_entry(child, pane->cur, hwnd);
3367 activate_entry(child, pane, hwnd);
3371 return pane_command(pane, LOWORD(wparam));
3377 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3379 switch(HIWORD(wparam)) {
3380 case LBN_SELCHANGE: {
3381 int idx = ListBox_GetCurSel(pane->hwnd);
3382 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3384 if (pane == &child->left)
3385 set_curdir(child, entry, hwnd);
3391 activate_entry(child, pane, hwnd);
3396 #ifndef _NO_EXTENSIONS
3398 NMHDR* pnmh = (NMHDR*) lparam;
3399 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3403 if (wparam != SIZE_MINIMIZED)
3404 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3408 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3415 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3417 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3418 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3422 #ifndef _NO_EXTENSIONS
3429 child->focus_pane = pane==&child->right? 1: 0;
3430 ListBox_SetSel(hwnd, TRUE, 1);
3431 /*TODO: check menu items */
3435 if (wparam == VK_TAB) {
3436 /*TODO: SetFocus(Globals.hdrivebar) */
3437 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3441 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3445 static void InitInstance(HINSTANCE hinstance)
3451 INITCOMMONCONTROLSEX icc = {
3452 sizeof(INITCOMMONCONTROLSEX),
3458 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3460 InitCommonControlsEx(&icc);
3463 /* register frame window class */
3465 wcFrame.cbSize = sizeof(WNDCLASSEX);
3467 wcFrame.lpfnWndProc = FrameWndProc;
3468 wcFrame.cbClsExtra = 0;
3469 wcFrame.cbWndExtra = 0;
3470 wcFrame.hInstance = hinstance;
3471 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3472 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3473 wcFrame.hbrBackground = 0;
3474 wcFrame.lpszMenuName = 0;
3475 wcFrame.lpszClassName = WINEFILEFRAME;
3476 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3477 MAKEINTRESOURCE(IDI_WINEFILE),
3479 GetSystemMetrics(SM_CXSMICON),
3480 GetSystemMetrics(SM_CYSMICON),
3483 Globals.hframeClass = RegisterClassEx(&wcFrame);
3486 /* register tree windows class */
3488 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3489 wcChild.lpfnWndProc = ChildWndProc;
3490 wcChild.cbClsExtra = 0;
3491 wcChild.cbWndExtra = 0;
3492 wcChild.hInstance = hinstance;
3494 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3495 wcChild.hbrBackground = 0;
3496 wcChild.lpszMenuName = 0;
3497 wcChild.lpszClassName = WINEFILETREE;
3499 hChildClass = RegisterClass(&wcChild);
3502 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3504 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
3508 Globals.hInstance = hinstance;
3510 #ifdef _SHELL_FOLDERS
3512 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3513 SHGetDesktopFolder(&Globals.iDesktop);
3514 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3519 void show_frame(HWND hwndParent, int cmdshow)
3521 TCHAR path[MAX_PATH];
3523 HMENU hMenuFrame, hMenuWindow;
3525 CLIENTCREATESTRUCT ccs;
3527 if (Globals.hMainWnd)
3530 Globals.hwndParent = hwndParent;
3532 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3533 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3535 Globals.hMenuFrame = hMenuFrame;
3536 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3537 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3539 ccs.hWindowMenu = hMenuWindow;
3540 ccs.idFirstChild = IDW_FIRST_CHILD;
3543 /* create main window */
3544 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3545 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3546 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3549 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3550 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3552 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3556 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0};
3560 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3561 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3562 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3563 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3565 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3567 drivebarBtn.fsStyle = TBSTYLE_BUTTON;
3569 #ifndef _NO_EXTENSIONS
3571 /* insert unix file system button */
3572 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3574 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3575 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3576 drivebarBtn.iString++;
3578 #ifdef _SHELL_FOLDERS
3579 /* insert shell namespace button */
3580 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3582 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3583 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3584 drivebarBtn.iString++;
3587 /* register windows drive root strings */
3588 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3591 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3593 for(p=Globals.drives; *p; ) {
3594 #ifdef _NO_EXTENSIONS
3595 /* insert drive letter */
3596 TCHAR b[3] = {tolower(*p)};
3597 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3599 switch(GetDriveType(p)) {
3600 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3601 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3602 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3603 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3604 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3607 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3608 drivebarBtn.idCommand++;
3609 drivebarBtn.iString++;
3616 TBBUTTON toolbarBtns[] = {
3617 {0, 0, 0, TBSTYLE_SEP, {0, 0}, 0, 0},
3618 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3619 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3620 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3621 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3623 {4, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3624 {5, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3627 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3628 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3629 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3630 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3633 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3634 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3636 /* CreateStatusWindow does not accept WS_BORDER
3637 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3638 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3639 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3641 /*TODO: read paths and window placements from registry */
3642 GetCurrentDirectory(MAX_PATH, path);
3644 ShowWindow(Globals.hMainWnd, cmdshow);
3646 #if defined(_SHELL_FOLDERS) && !defined(_WINE_)
3647 /* Shell Namespace as default: */
3648 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3650 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3653 child->pos.showCmd = SW_SHOWMAXIMIZED;
3654 child->pos.rcNormalPosition.left = 0;
3655 child->pos.rcNormalPosition.top = 0;
3656 child->pos.rcNormalPosition.right = 320;
3657 child->pos.rcNormalPosition.bottom = 280;
3659 if (!create_child_window(child))
3662 SetWindowPlacement(child->hwnd, &child->pos);
3664 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3666 Globals.prescan_node = FALSE;
3668 UpdateWindow(Globals.hMainWnd);
3673 #ifdef _SHELL_FOLDERS
3674 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3675 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3679 ImageList_Destroy(Globals.himl);
3683 /* search for already running win[e]files */
3685 static int g_foundPrevInstance = 0;
3687 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3691 GetClassName(hwnd, cls, 128);
3693 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3694 g_foundPrevInstance++;
3701 /* search for window of given class name to allow only one running instance */
3702 int find_window_class(LPCTSTR classname)
3704 EnumWindows(EnumWndProc, (LPARAM)classname);
3706 if (g_foundPrevInstance)
3713 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3717 InitInstance(hinstance);
3719 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3720 if (cmdshow == SW_SHOWNORMAL)
3721 /*TODO: read window placement from registry */
3722 cmdshow = SW_MAXIMIZE;
3725 show_frame(hwndParent, cmdshow);
3727 while(GetMessage(&msg, 0, 0, 0)) {
3728 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3731 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3734 TranslateMessage(&msg);
3735 DispatchMessage(&msg);
3746 int APIENTRY WinMain(HINSTANCE hinstance,
3747 HINSTANCE previnstance,
3751 #ifdef _NO_EXTENSIONS
3752 if (find_window_class(WINEFILEFRAME))
3756 winefile_main(hinstance, 0, cmdshow);