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(__WINE__)
48 #define _MAX_FNAME 256
49 #define _MAX_DIR _MAX_FNAME
50 #define _MAX_EXT _MAX_FNAME
54 #ifdef NONAMELESSUNION
55 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
57 #define UNION_MEMBER(x) x
62 #define DEFAULT_SPLIT_POS 300;
64 #define DEFAULT_SPLIT_POS 200;
68 WINEFILE_GLOBALS Globals;
70 extern void WineLicense(HWND hwnd);
71 extern void WineWarranty(HWND hwnd);
81 typedef struct _Entry {
92 #ifndef _NO_EXTENSIONS
93 BY_HANDLE_FILE_INFORMATION bhfi;
95 enum ENTRY_TYPE etype;
106 TCHAR path[MAX_PATH];
107 TCHAR volname[_MAX_FNAME];
117 COL_ATTRIBUTES = 0x08,
119 #ifdef _NO_EXTENSIONS
120 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
124 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
137 #ifndef _NO_EXTENSIONS
141 #ifndef _NO_EXTENSIONS
147 int positions[COLUMNS+1];
159 int focus_pane; /* 0: left 1: right */
162 BOOL header_wdths_ok;
164 TCHAR path[MAX_PATH];
167 SORT_ORDER sortOrder;
171 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
172 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd);
174 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
175 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
176 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
179 static void display_error(HWND hwnd, DWORD error)
183 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
184 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
185 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
187 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
193 /* allocate and initialise a directory entry */
194 static Entry* alloc_entry()
196 Entry* entry = (Entry*) malloc(sizeof(Entry));
198 #ifdef _SHELL_FOLDERS
200 entry->folder = NULL;
207 /* free a directory entry */
208 static void free_entry(Entry* entry)
210 #ifdef _SHELL_FOLDERS
211 if (entry->hicon && entry->hicon!=(HICON)-1)
212 DestroyIcon(entry->hicon);
214 if (entry->folder && entry->folder!=Globals.iDesktop)
215 (*entry->folder->lpVtbl->Release)(entry->folder);
218 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
224 /* recursively free all child entries */
225 static void free_entries(Entry* dir)
227 Entry *entry, *next=dir->down;
243 static void read_directory_win(Entry* dir, LPCTSTR path)
245 Entry* first_entry = NULL;
249 int level = dir->level + 1;
250 WIN32_FIND_DATA w32fd;
252 #ifndef _NO_EXTENSIONS
256 TCHAR buffer[MAX_PATH], *p;
257 for(p=buffer; *path; )
260 lstrcpy(p, TEXT("\\*"));
262 hFind = FindFirstFile(buffer, &w32fd);
264 if (hFind != INVALID_HANDLE_VALUE) {
266 entry = alloc_entry();
274 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
277 entry->expanded = FALSE;
278 entry->scanned = FALSE;
279 entry->level = level;
281 #ifdef _NO_EXTENSIONS
282 /* hide directory entry "." */
283 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
284 LPCTSTR name = entry->data.cFileName;
286 if (name[0]=='.' && name[1]=='\0')
290 entry->etype = ET_WINDOWS;
291 entry->bhfi_valid = FALSE;
293 lstrcpy(p+1, entry->data.cFileName);
295 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
296 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
298 if (hFile != INVALID_HANDLE_VALUE) {
299 if (GetFileInformationByHandle(hFile, &entry->bhfi))
300 entry->bhfi_valid = TRUE;
307 } while(FindNextFile(hFind, &entry->data));
314 dir->down = first_entry;
319 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
323 for(entry=dir->down; entry; entry=entry->next) {
325 LPCTSTR q = entry->data.cFileName;
328 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
330 } while(tolower(*p++) == tolower(*q++));
333 q = entry->data.cAlternateFileName;
336 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
338 } while(tolower(*p++) == tolower(*q++));
345 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
347 TCHAR buffer[MAX_PATH];
348 Entry* entry = &root->entry;
352 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
354 #ifndef _NO_EXTENSIONS
355 entry->etype = ET_WINDOWS;
359 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
362 while(*s==TEXT('\\') || *s==TEXT('/'))
368 read_directory(entry, buffer, sortOrder, hwnd);
371 entry->expanded = TRUE;
376 entry = find_entry_win(entry, s);
379 SetCursor(old_cursor);
385 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
387 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
389 struct tm* tm = gmtime(t);
395 stime.wYear = tm->tm_year+1900;
396 stime.wMonth = tm->tm_mon+1;
397 /* stime.wDayOfWeek */
398 stime.wDay = tm->tm_mday;
399 stime.wHour = tm->tm_hour;
400 stime.wMinute = tm->tm_min;
401 stime.wSecond = tm->tm_sec;
403 return SystemTimeToFileTime(&stime, ftime);
406 static void read_directory_unix(Entry* dir, LPCTSTR path)
408 Entry* first_entry = NULL;
412 int level = dir->level + 1;
414 DIR* pdir = opendir(path);
419 TCHAR buffer[MAX_PATH], *p;
421 for(p=buffer; *path; )
424 if (p==buffer || p[-1]!='/')
427 while((ent=readdir(pdir))) {
428 entry = alloc_entry();
436 entry->etype = ET_UNIX;
438 lstrcpy(entry->data.cFileName, ent->d_name);
439 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
441 strcpy(p, ent->d_name);
443 if (!stat(buffer, &st)) {
444 if (S_ISDIR(st.st_mode))
445 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
447 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
448 entry->data.nFileSizeHigh = st.st_size >> 32;
450 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
451 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
452 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
454 entry->bhfi.nFileIndexLow = ent->d_ino;
455 entry->bhfi.nFileIndexHigh = 0;
457 entry->bhfi.nNumberOfLinks = st.st_nlink;
459 entry->bhfi_valid = TRUE;
461 entry->data.nFileSizeLow = 0;
462 entry->data.nFileSizeHigh = 0;
463 entry->bhfi_valid = FALSE;
468 entry->expanded = FALSE;
469 entry->scanned = FALSE;
470 entry->level = level;
480 dir->down = first_entry;
484 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
488 for(entry=dir->down; entry; entry=entry->next) {
490 LPCTSTR q = entry->data.cFileName;
493 if (!*p || *p==TEXT('/'))
495 } while(*p++ == *q++);
501 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
503 TCHAR buffer[MAX_PATH];
504 Entry* entry = &root->entry;
508 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
510 entry->etype = ET_UNIX;
513 while(*s && *s!=TEXT('/'))
516 while(*s == TEXT('/'))
522 read_directory(entry, buffer, sortOrder, hwnd);
525 entry->expanded = TRUE;
530 entry = find_entry_unix(entry, s);
533 SetCursor(old_cursor);
538 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
541 #ifdef _SHELL_FOLDERS
544 #define tcscpyn strcpyn
545 #define get_strret get_strretW
546 #define path_from_pidl path_from_pidlW
548 #define tcscpyn wcscpyn
549 #define get_strret get_strretA
550 #define path_from_pidl path_from_pidlA
554 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
559 for(s=source; count&&(*d++=*s++); )
565 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
570 for(s=source; count&&(*d++=*s++); )
577 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
581 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
585 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
589 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
593 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
597 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
601 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
605 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
610 static void free_strret(STRRET* str)
612 if (str->uType == STRRET_WSTR)
613 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
617 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
621 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
624 get_strret(&str, &pidl->mkid, buffer, len);
633 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
637 /* SHGDN_FORPARSING: get full path of id list */
638 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
641 get_strretA(&str, &pidl->mkid, buffer, len);
649 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
653 /* SHGDN_FORPARSING: get full path of id list */
654 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
657 get_strretW(&str, &pidl->mkid, buffer, len);
666 /* create an item id list from a file system path */
668 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
675 LPWSTR buffer = path;
677 WCHAR buffer[MAX_PATH];
678 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
681 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
689 /* convert an item id list from relative to absolute (=relative to the desktop) format */
691 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
693 if (entry->up && entry->up->etype==ET_SHELL) {
694 IShellFolder* folder = entry->up->folder;
695 WCHAR buffer[MAX_PATH];
697 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
703 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
714 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
716 IExtractIcon* pExtract;
718 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
719 TCHAR path[_MAX_PATH];
724 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
725 if (!(flags & GIL_NOTFILENAME)) {
727 idx = 0; /* special case for some control panel applications */
729 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
730 flags &= ~GIL_DONTCACHE;
732 HICON hIconLarge = 0;
734 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
737 DestroyIcon(hIconLarge);
748 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
752 for(entry=dir->down; entry; entry=entry->next) {
753 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
754 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
761 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
763 Entry* entry = &root->entry;
765 LPITEMIDLIST next_pidl = pidl;
766 IShellFolder* folder;
767 IShellFolder* child = NULL;
770 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
772 #ifndef _NO_EXTENSIONS
773 entry->etype = ET_SHELL;
776 folder = Globals.iDesktop;
779 entry->pidl = next_pidl;
780 entry->folder = folder;
785 /* copy first element of item idlist */
786 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
787 memcpy(next_pidl, pidl, pidl->mkid.cb);
788 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
790 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
794 read_directory(entry, NULL, sortOrder, hwnd);
797 entry->expanded = TRUE;
799 next = find_entry_shell(entry, next_pidl);
806 /* go to next element */
807 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
810 SetCursor(old_cursor);
816 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
818 if (!(attribs & SFGAO_FILESYSTEM) ||
819 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
820 WIN32_FILE_ATTRIBUTE_DATA fad;
821 IDataObject* pDataObj;
823 STGMEDIUM medium = {0, {0}, 0};
824 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
826 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
829 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
831 (*pDataObj->lpVtbl->Release)(pDataObj);
834 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
835 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
837 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
838 w32fdata->dwFileAttributes = fad.dwFileAttributes;
839 w32fdata->ftCreationTime = fad.ftCreationTime;
840 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
841 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
843 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
844 w32fdata->nFileSizeLow = fad.nFileSizeLow;
845 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
849 SetErrorMode(sem_org);
851 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
852 GlobalFree(medium.UNION_MEMBER(hGlobal));
857 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
858 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
860 if (attribs & SFGAO_READONLY)
861 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
863 if (attribs & SFGAO_COMPRESSED)
864 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
868 static void read_directory_shell(Entry* dir, HWND hwnd)
870 IShellFolder* folder = dir->folder;
871 int level = dir->level + 1;
877 Entry* first_entry = NULL;
884 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
888 #define FETCH_ITEM_COUNT 32
889 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
894 memset(pidls, 0, sizeof(pidls));
896 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
903 for(n=0; n<cnt; ++n) {
904 entry = alloc_entry();
912 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
913 entry->bhfi_valid = FALSE;
915 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
917 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
920 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
921 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
923 entry->bhfi_valid = TRUE;
929 entry->pidl = pidls[n];
931 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
932 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
935 entry->folder = child;
937 entry->folder = NULL;
940 entry->folder = NULL;
942 if (!entry->data.cFileName[0])
943 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
945 /* get display icons for files and virtual objects */
946 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
947 !(attribs & SFGAO_FILESYSTEM)) {
948 entry->hicon = extract_icon(folder, pidls[n]);
951 entry->hicon = (HICON)-1; /* don't try again later */
956 entry->expanded = FALSE;
957 entry->scanned = FALSE;
958 entry->level = level;
960 #ifndef _NO_EXTENSIONS
961 entry->etype = ET_SHELL;
962 entry->bhfi_valid = FALSE;
969 (*idlist->lpVtbl->Release)(idlist);
975 dir->down = first_entry;
979 #endif /* _SHELL_FOLDERS */
982 /* directories first... */
983 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
985 int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
986 int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
988 return dir2==dir1? 0: dir2<dir1? -1: 1;
992 static int compareName(const void* arg1, const void* arg2)
994 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
995 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
997 int cmp = compareType(fd1, fd2);
1001 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1004 static int compareExt(const void* arg1, const void* arg2)
1006 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1007 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1008 const TCHAR *name1, *name2, *ext1, *ext2;
1010 int cmp = compareType(fd1, fd2);
1014 name1 = fd1->cFileName;
1015 name2 = fd2->cFileName;
1017 ext1 = _tcsrchr(name1, TEXT('.'));
1018 ext2 = _tcsrchr(name2, TEXT('.'));
1030 cmp = lstrcmpi(ext1, ext2);
1034 return lstrcmpi(name1, name2);
1037 static int compareSize(const void* arg1, const void* arg2)
1039 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1040 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1042 int cmp = compareType(fd1, fd2);
1046 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1053 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1055 return cmp<0? -1: cmp>0? 1: 0;
1058 static int compareDate(const void* arg1, const void* arg2)
1060 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1061 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1063 int cmp = compareType(fd1, fd2);
1067 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1071 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1072 compareName, /* SORT_NAME */
1073 compareExt, /* SORT_EXT */
1074 compareSize, /* SORT_SIZE */
1075 compareDate /* SORT_DATE */
1079 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1081 Entry* entry = dir->down;
1086 for(entry=dir->down; entry; entry=entry->next)
1090 array = (Entry**) alloca(len*sizeof(Entry*));
1093 for(entry=dir->down; entry; entry=entry->next)
1096 /* call qsort with the appropriate compare function */
1097 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1099 dir->down = array[0];
1101 for(p=array; --len; p++)
1109 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1111 TCHAR buffer[MAX_PATH];
1116 #ifdef _SHELL_FOLDERS
1117 if (dir->etype == ET_SHELL)
1119 read_directory_shell(dir, hwnd);
1121 if (Globals.prescan_node) {
1130 for(entry=dir->down; entry; entry=entry->next)
1131 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1132 read_directory_shell(entry, hwnd);
1133 SortDirectory(entry, sortOrder);
1139 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1140 if (dir->etype == ET_UNIX)
1142 read_directory_unix(dir, path);
1144 if (Globals.prescan_node) {
1153 for(entry=dir->down; entry; entry=entry->next)
1154 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1155 lstrcpy(d, entry->data.cFileName);
1156 read_directory_unix(entry, buffer);
1157 SortDirectory(entry, sortOrder);
1164 read_directory_win(dir, path);
1166 if (Globals.prescan_node) {
1175 for(entry=dir->down; entry; entry=entry->next)
1176 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1177 lstrcpy(d, entry->data.cFileName);
1178 read_directory_win(entry, buffer);
1179 SortDirectory(entry, sortOrder);
1184 SortDirectory(dir, sortOrder);
1188 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1190 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1191 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1192 Root* root = &child->root;
1195 memset(child, 0, sizeof(ChildWnd));
1197 child->left.treePane = TRUE;
1198 child->left.visible_cols = 0;
1200 child->right.treePane = FALSE;
1201 #ifndef _NO_EXTENSIONS
1202 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1204 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1207 child->pos.length = sizeof(WINDOWPLACEMENT);
1208 child->pos.flags = 0;
1209 child->pos.showCmd = SW_SHOWNORMAL;
1210 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1211 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1212 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1213 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1215 child->focus_pane = 0;
1216 child->split_pos = DEFAULT_SPLIT_POS;
1217 child->sortOrder = SORT_NAME;
1218 child->header_wdths_ok = FALSE;
1222 lstrcpy(child->path, path);
1224 _tsplitpath(path, drv, dir, name, ext);
1227 root->entry.level = 0;
1229 #ifdef _SHELL_FOLDERS
1232 root->drive_type = DRIVE_UNKNOWN;
1233 lstrcpy(drv, TEXT("\\"));
1234 lstrcpy(root->volname, TEXT("Desktop"));
1236 lstrcpy(root->fs, TEXT("Shell"));
1238 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1242 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1245 root->drive_type = GetDriveType(path);
1247 lstrcat(drv, TEXT("/"));
1248 lstrcpy(root->volname, TEXT("root fs"));
1250 lstrcpy(root->fs, TEXT("unixfs"));
1252 lstrcpy(root->path, TEXT("/"));
1253 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1258 root->drive_type = GetDriveType(path);
1260 lstrcat(drv, TEXT("\\"));
1261 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1263 lstrcpy(root->path, drv);
1264 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1267 #ifdef _SHELL_FOLDERS
1268 if (root->entry.etype == ET_SHELL)
1269 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1272 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1274 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1276 child->left.root = &root->entry;
1277 child->right.root = NULL;
1279 set_curdir(child, entry, hwnd);
1285 /* free all memory associated with a child window */
1286 static void free_child_window(ChildWnd* child)
1288 free_entries(&child->root.entry);
1293 /* get full path of specified directory entry */
1294 static void get_path(Entry* dir, PTSTR path)
1300 #ifdef _SHELL_FOLDERS
1301 if (dir->etype == ET_SHELL)
1306 path[0] = TEXT('\0');
1311 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1313 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1314 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1316 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1322 for(entry=dir; entry; level++) {
1328 name = entry->data.cFileName;
1331 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1337 memmove(path+l+1, path, len*sizeof(TCHAR));
1338 memcpy(path+1, name, l*sizeof(TCHAR));
1341 #ifndef _NO_EXTENSIONS
1342 if (entry->etype == ET_UNIX)
1343 path[0] = TEXT('/');
1346 path[0] = TEXT('\\');
1351 memmove(path+l, path, len*sizeof(TCHAR));
1352 memcpy(path, name, l*sizeof(TCHAR));
1359 #ifndef _NO_EXTENSIONS
1360 if (entry->etype == ET_UNIX)
1361 path[len++] = TEXT('/');
1364 path[len++] = TEXT('\\');
1367 path[len] = TEXT('\0');
1372 static void resize_frame_rect(HWND hwnd, PRECT prect)
1377 if (IsWindowVisible(Globals.htoolbar)) {
1378 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1379 GetClientRect(Globals.htoolbar, &rt);
1380 prect->top = rt.bottom+3;
1381 prect->bottom -= rt.bottom+3;
1384 if (IsWindowVisible(Globals.hdrivebar)) {
1385 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1386 GetClientRect(Globals.hdrivebar, &rt);
1387 new_top = --prect->top + rt.bottom+3;
1388 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1389 prect->top = new_top;
1390 prect->bottom -= rt.bottom+2;
1393 if (IsWindowVisible(Globals.hstatusbar)) {
1394 int parts[] = {300, 500};
1396 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1397 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1398 GetClientRect(Globals.hstatusbar, &rt);
1399 prect->bottom -= rt.bottom;
1402 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1405 static void resize_frame(HWND hwnd, int cx, int cy)
1414 resize_frame_rect(hwnd, &rect);
1417 static void resize_frame_client(HWND hwnd)
1421 GetClientRect(hwnd, &rect);
1423 resize_frame_rect(hwnd, &rect);
1427 static HHOOK hcbthook;
1428 static ChildWnd* newchild = NULL;
1430 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1432 if (code==HCBT_CREATEWND && newchild) {
1433 ChildWnd* child = newchild;
1436 child->hwnd = (HWND) wparam;
1437 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1440 return CallNextHookEx(hcbthook, code, wparam, lparam);
1443 static HWND create_child_window(ChildWnd* child)
1445 MDICREATESTRUCT mcs;
1448 mcs.szClass = WINEFILETREE;
1449 mcs.szTitle = (LPTSTR)child->path;
1450 mcs.hOwner = Globals.hInstance;
1451 mcs.x = child->pos.rcNormalPosition.left;
1452 mcs.y = child->pos.rcNormalPosition.top;
1453 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1454 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1458 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1461 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1463 UnhookWindowsHookEx(hcbthook);
1467 UnhookWindowsHookEx(hcbthook);
1469 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1470 ListBox_SetCurSel(child->left.hwnd, idx);
1476 struct ExecuteDialog {
1477 TCHAR cmd[MAX_PATH];
1482 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1484 static struct ExecuteDialog* dlg;
1488 dlg = (struct ExecuteDialog*) lparam;
1492 int id = (int)wparam;
1495 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1496 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1497 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1498 EndDialog(hwnd, id);
1499 } else if (id == IDCANCEL)
1500 EndDialog(hwnd, id);
1509 #ifndef _NO_EXTENSIONS
1511 static struct FullScreenParameters {
1521 void frame_get_clientspace(HWND hwnd, PRECT prect)
1525 if (!IsIconic(hwnd))
1526 GetClientRect(hwnd, prect);
1530 GetWindowPlacement(hwnd, &wp);
1532 prect->left = prect->top = 0;
1533 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1534 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1535 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1536 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1537 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1540 if (IsWindowVisible(Globals.htoolbar)) {
1541 GetClientRect(Globals.htoolbar, &rt);
1542 prect->top += rt.bottom+2;
1545 if (IsWindowVisible(Globals.hdrivebar)) {
1546 GetClientRect(Globals.hdrivebar, &rt);
1547 prect->top += rt.bottom+2;
1550 if (IsWindowVisible(Globals.hstatusbar)) {
1551 GetClientRect(Globals.hstatusbar, &rt);
1552 prect->bottom -= rt.bottom;
1556 static BOOL toggle_fullscreen(HWND hwnd)
1560 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1561 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1562 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1564 Frame_CalcFrameClient(hwnd, &rt);
1565 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1566 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1568 rt.left = g_fullscreen.orgPos.left-rt.left;
1569 rt.top = g_fullscreen.orgPos.top-rt.top;
1570 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1571 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1573 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1575 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1576 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1577 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1579 if (g_fullscreen.wasZoomed)
1580 ShowWindow(hwnd, WS_MAXIMIZE);
1583 return g_fullscreen.mode;
1586 static void fullscreen_move(HWND hwnd)
1589 GetWindowRect(hwnd, &pos);
1591 Frame_CalcFrameClient(hwnd, &rt);
1592 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1593 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1595 rt.left = pos.left-rt.left;
1596 rt.top = pos.top-rt.top;
1597 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1598 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1600 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1606 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1608 BOOL vis = IsWindowVisible(hchild);
1610 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1612 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1614 #ifndef _NO_EXTENSIONS
1615 if (g_fullscreen.mode)
1616 fullscreen_move(hwnd);
1619 resize_frame_client(hwnd);
1622 BOOL activate_drive_window(LPCTSTR path)
1624 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1627 _tsplitpath(path, drv1, 0, 0, 0);
1629 /* search for a already open window for the same drive */
1630 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1631 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1634 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1636 if (!lstrcmpi(drv2, drv1)) {
1637 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1639 if (IsMinimized(child_wnd))
1640 ShowWindow(child_wnd, SW_SHOWNORMAL);
1650 BOOL activate_fs_window(LPCTSTR filesys)
1654 /* search for a already open window of the given file system name */
1655 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1656 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1659 if (!lstrcmpi(child->root.fs, filesys)) {
1660 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1662 if (IsMinimized(child_wnd))
1663 ShowWindow(child_wnd, SW_SHOWNORMAL);
1673 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1677 DestroyWindow(hwnd);
1679 /* clear handle variables */
1680 Globals.hMenuFrame = 0;
1681 Globals.hMenuView = 0;
1682 Globals.hMenuOptions = 0;
1683 Globals.hMainWnd = 0;
1684 Globals.hmdiclient = 0;
1685 Globals.hdrivebar = 0;
1689 /* don't exit desktop when closing file manager window */
1690 if (!Globals.hwndParent)
1695 UINT cmd = LOWORD(wparam);
1696 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1698 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1701 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1702 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1704 LPCTSTR root = Globals.drives;
1707 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1711 if (activate_drive_window(root))
1714 _tsplitpath(root, drv, 0, 0, 0);
1716 if (!SetCurrentDirectory(drv)) {
1717 display_error(hwnd, GetLastError());
1721 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1722 child = alloc_child_window(path, NULL, hwnd);
1724 if (!create_child_window(child))
1726 } else switch(cmd) {
1728 SendMessage(hwnd, WM_CLOSE, 0, 0);
1731 case ID_WINDOW_NEW: {
1732 TCHAR path[MAX_PATH];
1735 GetCurrentDirectory(MAX_PATH, path);
1736 child = alloc_child_window(path, NULL, hwnd);
1738 if (!create_child_window(child))
1742 case ID_WINDOW_CASCADE:
1743 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1746 case ID_WINDOW_TILE_HORZ:
1747 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1750 case ID_WINDOW_TILE_VERT:
1751 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1754 case ID_WINDOW_ARRANGE:
1755 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1758 case ID_VIEW_TOOL_BAR:
1759 toggle_child(hwnd, cmd, Globals.htoolbar);
1762 case ID_VIEW_DRIVE_BAR:
1763 toggle_child(hwnd, cmd, Globals.hdrivebar);
1766 case ID_VIEW_STATUSBAR:
1767 toggle_child(hwnd, cmd, Globals.hstatusbar);
1771 struct ExecuteDialog dlg;
1773 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1775 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1776 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1778 if ((int)hinst <= 32)
1779 display_error(hwnd, GetLastError());
1784 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1787 #ifndef _NO_EXTENSIONS
1788 case ID_VIEW_FULLSCREEN:
1789 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1793 case ID_DRIVE_UNIX_FS: {
1794 TCHAR path[MAX_PATH];
1797 if (activate_fs_window(TEXT("unixfs")))
1800 getcwd(path, MAX_PATH);
1801 child = alloc_child_window(path, NULL, hwnd);
1803 if (!create_child_window(child))
1807 #ifdef _SHELL_FOLDERS
1808 case ID_DRIVE_SHELL_NS: {
1809 TCHAR path[MAX_PATH];
1812 if (activate_fs_window(TEXT("Shell")))
1815 GetCurrentDirectory(MAX_PATH, path);
1816 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1818 if (!create_child_window(child))
1824 /*TODO: There are even more menu items! */
1826 #ifndef _NO_EXTENSIONS
1829 WineLicense(Globals.hMainWnd);
1832 case ID_NO_WARRANTY:
1833 WineWarranty(Globals.hMainWnd);
1838 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1841 case ID_ABOUT: /*ID_ABOUT_WINE: */
1842 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1844 #endif /* _NO_EXTENSIONS */
1847 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1848 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1849 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1850 (cmd<SC_SIZE || cmd>SC_RESTORE))
1851 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1853 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1858 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1859 break; /* do not pass message to DefFrameProc */
1861 #ifndef _NO_EXTENSIONS
1862 case WM_GETMINMAXINFO: {
1863 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1865 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1866 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1869 case FRM_CALC_CLIENT:
1870 frame_get_clientspace(hwnd, (PRECT)lparam);
1872 #endif /* _NO_EXTENSIONS */
1875 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1882 static const LPTSTR g_pos_names[COLUMNS] = {
1883 TEXT(""), /* symbol */
1887 #ifndef _NO_EXTENSIONS
1890 TEXT("Index/Inode"),
1892 #endif /* _NO_EXTENSIONS */
1894 #ifndef _NO_EXTENSIONS
1899 static const int g_pos_align[] = {
1901 HDF_LEFT, /* Name */
1902 HDF_RIGHT, /* Size */
1903 HDF_LEFT, /* CDate */
1904 #ifndef _NO_EXTENSIONS
1905 HDF_LEFT, /* ADate */
1906 HDF_LEFT, /* MDate */
1907 HDF_LEFT, /* Index */
1908 HDF_CENTER, /* Links */
1910 HDF_CENTER, /* Attributes */
1911 #ifndef _NO_EXTENSIONS
1912 HDF_LEFT /* Security */
1916 static void resize_tree(ChildWnd* child, int cx, int cy)
1918 HDWP hdwp = BeginDeferWindowPos(4);
1926 cx = child->split_pos + SPLIT_WIDTH/2;
1928 #ifndef _NO_EXTENSIONS
1936 Header_Layout(child->left.hwndHeader, &hdl);
1938 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1939 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1940 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1941 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1943 #endif /* _NO_EXTENSIONS */
1945 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);
1946 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1948 EndDeferWindowPos(hdwp);
1952 #ifndef _NO_EXTENSIONS
1954 static HWND create_header(HWND parent, Pane* pane, int id)
1959 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1960 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1964 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1966 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1968 for(idx=0; idx<COLUMNS; idx++) {
1969 hdi.pszText = g_pos_names[idx];
1970 hdi.fmt = HDF_STRING | g_pos_align[idx];
1971 hdi.cxy = pane->widths[idx];
1972 Header_InsertItem(hwnd, idx, &hdi);
1978 #endif /* _NO_EXTENSIONS */
1981 static void init_output(HWND hwnd)
1985 HDC hdc = GetDC(hwnd);
1987 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1988 Globals.num_sep = b[1];
1990 Globals.num_sep = TEXT('.');
1992 old_font = SelectFont(hdc, Globals.hfont);
1993 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1994 SelectFont(hdc, old_font);
1995 ReleaseDC(hwnd, hdc);
1998 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2001 /* calculate prefered width for all visible columns */
2003 static BOOL calc_widths(Pane* pane, BOOL anyway)
2005 int col, x, cx, spc=3*Globals.spaceSize.cx;
2006 int entries = ListBox_GetCount(pane->hwnd);
2007 int orgWidths[COLUMNS];
2008 int orgPositions[COLUMNS+1];
2014 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2015 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2018 for(col=0; col<COLUMNS; col++)
2019 pane->widths[col] = 0;
2021 hdc = GetDC(pane->hwnd);
2022 hfontOld = SelectFont(hdc, Globals.hfont);
2024 for(cnt=0; cnt<entries; cnt++) {
2025 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2034 dis.hwndItem = pane->hwnd;
2036 dis.rcItem.left = 0;
2038 dis.rcItem.right = 0;
2039 dis.rcItem.bottom = 0;
2040 /*dis.itemData = 0; */
2042 draw_item(pane, &dis, entry, COLUMNS);
2045 SelectObject(hdc, hfontOld);
2046 ReleaseDC(pane->hwnd, hdc);
2049 for(col=0; col<COLUMNS; col++) {
2050 pane->positions[col] = x;
2051 cx = pane->widths[col];
2056 if (cx < IMAGE_WIDTH)
2059 pane->widths[col] = cx;
2065 pane->positions[COLUMNS] = x;
2067 ListBox_SetHorizontalExtent(pane->hwnd, x);
2070 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2073 /* don't move, if only collapsing an entry */
2074 if (!anyway && pane->widths[0]<orgWidths[0] &&
2075 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2076 pane->widths[0] = orgWidths[0];
2077 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2082 InvalidateRect(pane->hwnd, 0, TRUE);
2088 /* calculate one prefered column width */
2090 static void calc_single_width(Pane* pane, int col)
2094 int entries = ListBox_GetCount(pane->hwnd);
2098 pane->widths[col] = 0;
2100 hdc = GetDC(pane->hwnd);
2101 hfontOld = SelectFont(hdc, Globals.hfont);
2103 for(cnt=0; cnt<entries; cnt++) {
2104 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2112 dis.hwndItem = pane->hwnd;
2114 dis.rcItem.left = 0;
2116 dis.rcItem.right = 0;
2117 dis.rcItem.bottom = 0;
2118 /*dis.itemData = 0; */
2120 draw_item(pane, &dis, entry, col);
2123 SelectObject(hdc, hfontOld);
2124 ReleaseDC(pane->hwnd, hdc);
2126 cx = pane->widths[col];
2129 cx += 3*Globals.spaceSize.cx;
2131 if (cx < IMAGE_WIDTH)
2135 pane->widths[col] = cx;
2137 x = pane->positions[col] + cx;
2139 for(; col<COLUMNS; ) {
2140 pane->positions[++col] = x;
2141 x += pane->widths[col];
2144 ListBox_SetHorizontalExtent(pane->hwnd, x);
2148 /* insert listbox entries after index idx */
2150 static void insert_entries(Pane* pane, Entry* dir, int idx)
2157 ShowWindow(pane->hwnd, SW_HIDE);
2159 for(; entry; entry=entry->next) {
2161 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2165 /* don't display entries "." and ".." in the left pane */
2166 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2167 && entry->data.cFileName[0]==TEXT('.'))
2169 #ifndef _NO_EXTENSIONS
2170 entry->data.cFileName[1]==TEXT('\0') ||
2172 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2178 ListBox_InsertItemData(pane->hwnd, idx, entry);
2180 if (pane->treePane && entry->expanded)
2181 insert_entries(pane, entry->down, idx);
2184 ShowWindow(pane->hwnd, SW_SHOW);
2188 static WNDPROC g_orgTreeWndProc;
2190 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2192 static int s_init = 0;
2193 Entry* entry = pane->root;
2195 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2196 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2197 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2199 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2200 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2202 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2204 /* insert entries into listbox */
2206 insert_entries(pane, entry, -1);
2208 /* calculate column widths */
2211 init_output(pane->hwnd);
2214 calc_widths(pane, TRUE);
2216 #ifndef _NO_EXTENSIONS
2217 pane->hwndHeader = create_header(parent, pane, id_header);
2222 static void InitChildWindow(ChildWnd* child)
2224 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2225 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2229 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2235 *buffer = TEXT('\0');
2237 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2240 if (!FileTimeToLocalFileTime(ft, &lft))
2241 {err: _tcscpy(buffer,TEXT("???")); return;}
2243 if (!FileTimeToSystemTime(&lft, &systime))
2246 if (visible_cols & COL_DATE) {
2247 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2252 if (visible_cols & COL_TIME) {
2254 buffer[len-1] = ' ';
2256 buffer[len++] = ' ';
2258 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2259 buffer[len] = TEXT('\0');
2264 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2266 RECT rt = {0, 0, 0, 0};
2268 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2270 if (rt.right > pane->widths[col])
2271 pane->widths[col] = rt.right;
2274 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2276 RECT rt = {0, 0, 0, 0};
2278 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2279 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2281 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2282 /*FIXME rt (0,0) ??? */
2284 if (rt.right > pane->widths[col])
2285 pane->widths[col] = rt.right;
2289 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2291 int x = dis->rcItem.left;
2294 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2295 rt.top = dis->rcItem.top;
2296 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2297 rt.bottom = dis->rcItem.bottom;
2299 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2302 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2304 int x = dis->rcItem.left;
2307 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2308 rt.top = dis->rcItem.top;
2309 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2310 rt.bottom = dis->rcItem.bottom;
2312 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2313 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2315 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2318 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2320 int x = dis->rcItem.left;
2327 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2328 rt.top = dis->rcItem.top;
2329 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2330 rt.bottom = dis->rcItem.bottom;
2335 /* insert number separator characters */
2336 pos = lstrlen(s) % 3;
2342 *d++ = Globals.num_sep;
2346 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2350 static int is_exe_file(LPCTSTR ext)
2352 static const LPCTSTR executable_extensions[] = {
2357 #ifndef _NO_EXTENSIONS
2361 #endif /* _NO_EXTENSIONS */
2365 TCHAR ext_buffer[_MAX_EXT];
2370 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2373 for(p=executable_extensions; *p; p++)
2374 if (!_tcscmp(ext_buffer, *p))
2380 static int is_registered_type(LPCTSTR ext)
2388 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2390 TCHAR buffer[BUFFER_LEN];
2392 int visible_cols = pane->visible_cols;
2393 COLORREF bkcolor, textcolor;
2394 RECT focusRect = dis->rcItem;
2401 attrs = entry->data.dwFileAttributes;
2403 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2404 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2405 && entry->data.cFileName[2]==TEXT('\0'))
2406 img = IMG_FOLDER_UP;
2407 #ifndef _NO_EXTENSIONS
2408 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2409 img = IMG_FOLDER_CUR;
2412 #ifdef _NO_EXTENSIONS
2415 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2416 img = IMG_OPEN_FOLDER;
2420 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2424 if (is_exe_file(ext))
2425 img = IMG_EXECUTABLE;
2426 else if (is_registered_type(ext))
2436 if (pane->treePane) {
2438 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2440 if (calcWidthCol == -1) {
2442 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2445 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2448 rt_clip.left = dis->rcItem.left;
2449 rt_clip.top = dis->rcItem.top;
2450 rt_clip.right = dis->rcItem.left+pane->widths[col];
2451 rt_clip.bottom = dis->rcItem.bottom;
2453 hrgn = CreateRectRgnIndirect(&rt_clip);
2455 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2456 DeleteObject(hrgn_org);
2460 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2461 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2464 if ((up=entry->up) != NULL) {
2465 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2466 LineTo(dis->hDC, img_pos-2, y);
2468 x = img_pos - IMAGE_WIDTH/2;
2471 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2475 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2478 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2479 LineTo(dis->hDC, x, dis->rcItem.bottom);
2481 } while((up=up->up) != NULL);
2484 x = img_pos - IMAGE_WIDTH/2;
2486 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2487 LineTo(dis->hDC, x, y);
2491 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2494 LineTo(dis->hDC, x, dis->rcItem.bottom);
2496 if (entry->down && entry->expanded) {
2497 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2498 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2499 LineTo(dis->hDC, x, dis->rcItem.bottom);
2502 SelectClipRgn(dis->hDC, hrgn_org);
2503 if (hrgn_org) DeleteObject(hrgn_org);
2504 /* SelectObject(dis->hDC, holdPen); */
2505 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2506 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2508 if (right > pane->widths[col])
2509 pane->widths[col] = right;
2512 img_pos = dis->rcItem.left;
2515 img_pos = dis->rcItem.left;
2517 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2518 pane->widths[col] = IMAGE_WIDTH;
2521 if (calcWidthCol == -1) {
2522 focusRect.left = img_pos -2;
2524 #ifdef _NO_EXTENSIONS
2525 if (pane->treePane && entry) {
2528 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2530 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2534 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2535 textcolor = COLOR_COMPRESSED;
2537 #endif /* _NO_EXTENSIONS */
2538 textcolor = RGB(0,0,0);
2540 if (dis->itemState & ODS_FOCUS) {
2541 textcolor = RGB(255,255,255);
2542 bkcolor = COLOR_SELECTION;
2544 bkcolor = RGB(255,255,255);
2547 hbrush = CreateSolidBrush(bkcolor);
2548 FillRect(dis->hDC, &focusRect, hbrush);
2549 DeleteObject(hbrush);
2551 SetBkMode(dis->hDC, TRANSPARENT);
2552 SetTextColor(dis->hDC, textcolor);
2554 cx = pane->widths[col];
2556 if (cx && img!=IMG_NONE) {
2557 if (cx > IMAGE_WIDTH)
2560 #ifdef _SHELL_FOLDERS
2561 if (entry->hicon && entry->hicon!=(HICON)-1)
2562 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2565 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2566 img_pos, dis->rcItem.top, cx,
2567 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2574 #ifdef _NO_EXTENSIONS
2575 if (img >= IMG_FOLDER_UP)
2581 /* ouput file name */
2582 if (calcWidthCol == -1)
2583 output_text(pane, dis, col, entry->data.cFileName, 0);
2584 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2585 calc_width(pane, dis, col, entry->data.cFileName);
2589 #ifdef _NO_EXTENSIONS
2590 if (!pane->treePane) {
2593 /* display file size */
2594 if (visible_cols & COL_SIZE) {
2595 #ifdef _NO_EXTENSIONS
2596 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2601 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2603 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2605 if (calcWidthCol == -1)
2606 output_number(pane, dis, col, buffer);
2607 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2608 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2614 /* display file date */
2615 if (visible_cols & (COL_DATE|COL_TIME)) {
2616 #ifndef _NO_EXTENSIONS
2617 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2618 if (calcWidthCol == -1)
2619 output_text(pane, dis, col, buffer, 0);
2620 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2621 calc_width(pane, dis, col, buffer);
2624 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2625 if (calcWidthCol == -1)
2626 output_text(pane, dis, col, buffer, 0);
2627 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2628 calc_width(pane, dis, col, buffer);
2630 #endif /* _NO_EXTENSIONS */
2632 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2633 if (calcWidthCol == -1)
2634 output_text(pane, dis, col, buffer, 0);
2635 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2636 calc_width(pane, dis, col, buffer);
2640 #ifndef _NO_EXTENSIONS
2641 if (entry->bhfi_valid) {
2642 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2644 if (visible_cols & COL_INDEX) {
2645 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2646 if (calcWidthCol == -1)
2647 output_text(pane, dis, col, buffer, DT_RIGHT);
2648 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2649 calc_width(pane, dis, col, buffer);
2653 if (visible_cols & COL_LINKS) {
2654 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2655 if (calcWidthCol == -1)
2656 output_text(pane, dis, col, buffer, DT_CENTER);
2657 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2658 calc_width(pane, dis, col, buffer);
2663 #endif /* _NO_EXTENSIONS */
2665 /* show file attributes */
2666 if (visible_cols & COL_ATTRIBUTES) {
2667 #ifdef _NO_EXTENSIONS
2668 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2670 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2673 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2675 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2676 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2677 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2678 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2679 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2680 #ifndef _NO_EXTENSIONS
2681 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2682 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2683 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2684 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2685 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2686 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2687 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2688 #endif /* _NO_EXTENSIONS */
2691 if (calcWidthCol == -1)
2692 output_tabbed_text(pane, dis, col, buffer);
2693 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2694 calc_tabbed_width(pane, dis, col, buffer);
2700 if (flags.security) {
2701 DWORD rights = get_access_mask();
2703 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2705 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2706 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2707 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2708 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2709 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2710 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2711 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2712 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2713 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2714 if (rights & WRITE_DAC) buffer[22] = 'C';
2715 if (rights & WRITE_OWNER) buffer[24] = 'O';
2716 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2718 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2721 if (flags.description) {
2722 get_description(buffer);
2723 output_text(dis, col++, buffer, 0, psize);
2727 #ifdef _NO_EXTENSIONS
2730 /* draw focus frame */
2731 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2732 /* Currently [04/2000] Wine neither behaves exactly the same */
2733 /* way as WIN 95 nor like Windows NT... */
2738 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2739 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2740 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2742 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2744 lastPen = SelectPen(dis->hDC, hpen);
2745 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2746 SetROP2(dis->hDC, R2_XORPEN);
2747 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2748 SelectObject(dis->hDC, lastBrush);
2749 SelectObject(dis->hDC, lastPen);
2752 #endif /* _NO_EXTENSIONS */
2756 #ifdef _NO_EXTENSIONS
2758 static void draw_splitbar(HWND hwnd, int x)
2761 HDC hdc = GetDC(hwnd);
2763 GetClientRect(hwnd, &rt);
2765 rt.left = x - SPLIT_WIDTH/2;
2766 rt.right = x + SPLIT_WIDTH/2+1;
2768 InvertRect(hdc, &rt);
2770 ReleaseDC(hwnd, hdc);
2773 #endif /* _NO_EXTENSIONS */
2776 #ifndef _NO_EXTENSIONS
2778 static void set_header(Pane* pane)
2781 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2784 item.mask = HDI_WIDTH;
2787 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2788 x += pane->widths[i];
2789 Header_SetItem(pane->hwndHeader, i, &item);
2793 x += pane->widths[i];
2794 item.cxy = x - scroll_pos;
2795 Header_SetItem(pane->hwndHeader, i++, &item);
2797 for(; i<COLUMNS; i++) {
2798 item.cxy = pane->widths[i];
2799 x += pane->widths[i];
2800 Header_SetItem(pane->hwndHeader, i, &item);
2805 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2807 switch(pnmh->code) {
2809 case HDN_ENDTRACK: {
2810 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2811 int idx = phdn->iItem;
2812 int dx = phdn->pitem->cxy - pane->widths[idx];
2816 GetClientRect(pane->hwnd, &clnt);
2818 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not realy needed with WINELIB) */
2819 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2821 pane->widths[idx] += dx;
2823 for(i=idx; ++i<=COLUMNS; )
2824 pane->positions[i] += dx;
2827 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2831 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2833 rt_scr.right = clnt.right;
2834 rt_scr.bottom = clnt.bottom;
2836 rt_clip.left = pane->positions[idx]-scroll_pos;
2838 rt_clip.right = clnt.right;
2839 rt_clip.bottom = clnt.bottom;
2841 if (rt_scr.left < 0) rt_scr.left = 0;
2842 if (rt_clip.left < 0) rt_clip.left = 0;
2844 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2846 rt_clip.right = pane->positions[idx+1];
2847 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2849 if (pnmh->code == HDN_ENDTRACK) {
2850 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2852 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2860 case HDN_DIVIDERDBLCLICK: {
2861 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2864 calc_single_width(pane, phdn->iItem);
2865 item.mask = HDI_WIDTH;
2866 item.cxy = pane->widths[phdn->iItem];
2868 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2869 InvalidateRect(pane->hwnd, 0, TRUE);
2876 #endif /* _NO_EXTENSIONS */
2879 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2881 TCHAR path[MAX_PATH];
2882 int idx = ListBox_GetCurSel(child->left.hwnd);
2883 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2885 /* delete sub entries in left pane */
2887 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2888 Entry* sub = (Entry*) res;
2890 if (res==LB_ERR || !sub || sub->level<=entry->level)
2893 ListBox_DeleteString(child->left.hwnd, idx+1);
2896 /* empty right pane */
2897 ListBox_ResetContent(child->right.hwnd);
2899 /* release memory */
2900 free_entries(entry);
2902 /* read contents from disk */
2903 #ifdef _SHELL_FOLDERS
2904 if (entry->etype == ET_SHELL)
2906 read_directory(entry, NULL, child->sortOrder, hwnd);
2911 get_path(entry, path);
2912 read_directory(entry, path, child->sortOrder, hwnd);
2915 /* insert found entries in right pane */
2916 insert_entries(&child->right, entry->down, -1);
2917 calc_widths(&child->right, FALSE);
2918 #ifndef _NO_EXTENSIONS
2919 set_header(&child->right);
2922 child->header_wdths_ok = FALSE;
2924 SetCursor(old_cursor);
2928 /* expand a directory entry */
2930 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2935 if (!dir || dir->expanded || !dir->down)
2940 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2943 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2944 p->data.cFileName[2]=='\0' && p->next)
2948 /* no subdirectories ? */
2949 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2952 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2954 dir->expanded = TRUE;
2956 /* insert entries in left pane */
2957 insert_entries(&child->left, p, idx);
2959 if (!child->header_wdths_ok) {
2960 if (calc_widths(&child->left, FALSE)) {
2961 #ifndef _NO_EXTENSIONS
2962 set_header(&child->left);
2965 child->header_wdths_ok = TRUE;
2973 static void collapse_entry(Pane* pane, Entry* dir)
2975 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2977 ShowWindow(pane->hwnd, SW_HIDE);
2979 /* hide sub entries */
2981 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2982 Entry* sub = (Entry*) res;
2984 if (res==LB_ERR || !sub || sub->level<=dir->level)
2987 ListBox_DeleteString(pane->hwnd, idx+1);
2990 dir->expanded = FALSE;
2992 ShowWindow(pane->hwnd, SW_SHOW);
2996 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
2998 TCHAR path[MAX_PATH];
3002 child->left.cur = entry;
3003 child->right.root = entry->down? entry->down: entry;
3004 child->right.cur = entry;
3006 if (!entry->scanned)
3007 scan_entry(child, entry, hwnd);
3009 ListBox_ResetContent(child->right.hwnd);
3010 insert_entries(&child->right, entry->down, -1);
3011 calc_widths(&child->right, FALSE);
3012 #ifndef _NO_EXTENSIONS
3013 set_header(&child->right);
3017 get_path(entry, path);
3018 lstrcpy(child->path, path);
3020 if (child->hwnd) /* only change window title, if the window already exists */
3021 SetWindowText(child->hwnd, path);
3024 SetCurrentDirectory(path);
3028 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3030 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3032 if ((int)hinst <= 32) {
3033 display_error(hwnd, GetLastError());
3041 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3043 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3045 if ((int)hinst <= 32) {
3046 display_error(hwnd, GetLastError());
3055 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3057 TCHAR cmd[MAX_PATH];
3059 #ifdef _SHELL_FOLDERS
3060 if (entry->etype == ET_SHELL) {
3063 SHELLEXECUTEINFO shexinfo;
3065 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3066 shexinfo.fMask = SEE_MASK_IDLIST;
3067 shexinfo.hwnd = hwnd;
3068 shexinfo.nShow = nCmdShow;
3069 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3071 if (!ShellExecuteEx(&shexinfo)) {
3072 display_error(hwnd, GetLastError());
3076 if (shexinfo.lpIDList != entry->pidl)
3077 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3083 get_path(entry, cmd);
3085 /* start program, open document... */
3086 return launch_file(hwnd, cmd, nCmdShow);
3090 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3092 Entry* entry = pane->cur;
3097 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3098 int scanned_old = entry->scanned;
3101 scan_entry(child, entry, hwnd);
3103 #ifndef _NO_EXTENSIONS
3104 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3108 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3109 entry = child->left.cur->up;
3110 collapse_entry(&child->left, entry);
3112 } else if (entry->expanded)
3113 collapse_entry(pane, child->left.cur);
3115 expand_entry(child, child->left.cur);
3117 if (!pane->treePane) focus_entry: {
3118 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3119 ListBox_SetCurSel(child->left.hwnd, idx);
3120 set_curdir(child, entry, hwnd);
3125 calc_widths(pane, FALSE);
3127 #ifndef _NO_EXTENSIONS
3132 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3137 static BOOL pane_command(Pane* pane, UINT cmd)
3141 if (pane->visible_cols) {
3142 pane->visible_cols = 0;
3143 calc_widths(pane, TRUE);
3144 #ifndef _NO_EXTENSIONS
3147 InvalidateRect(pane->hwnd, 0, TRUE);
3148 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3149 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3150 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3154 case ID_VIEW_ALL_ATTRIBUTES:
3155 if (pane->visible_cols != COL_ALL) {
3156 pane->visible_cols = COL_ALL;
3157 calc_widths(pane, TRUE);
3158 #ifndef _NO_EXTENSIONS
3161 InvalidateRect(pane->hwnd, 0, TRUE);
3162 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3163 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3164 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3168 #ifndef _NO_EXTENSIONS
3169 case ID_PREFERED_SIZES: {
3170 calc_widths(pane, TRUE);
3172 InvalidateRect(pane->hwnd, 0, TRUE);
3176 /* TODO: more command ids... */
3186 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3188 static int last_split;
3190 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3195 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3196 Entry* entry = (Entry*) dis->itemData;
3198 if (dis->CtlID == IDW_TREE_LEFT)
3199 draw_item(&child->left, dis, entry, -1);
3201 draw_item(&child->right, dis, entry, -1);
3206 InitChildWindow(child);
3210 free_child_window(child);
3211 SetWindowLong(hwnd, GWL_USERDATA, 0);
3218 GetClientRect(hwnd, &rt);
3219 BeginPaint(hwnd, &ps);
3220 rt.left = child->split_pos-SPLIT_WIDTH/2;
3221 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3222 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3223 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3224 SelectObject(ps.hdc, lastBrush);
3225 #ifdef _NO_EXTENSIONS
3226 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3227 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3229 EndPaint(hwnd, &ps);
3233 if (LOWORD(lparam) == HTCLIENT) {
3236 ScreenToClient(hwnd, &pt);
3238 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3239 SetCursor(LoadCursor(0, IDC_SIZEWE));
3245 case WM_LBUTTONDOWN: {
3247 int x = LOWORD(lparam);
3249 GetClientRect(hwnd, &rt);
3251 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3252 last_split = child->split_pos;
3253 #ifdef _NO_EXTENSIONS
3254 draw_splitbar(hwnd, last_split);
3262 if (GetCapture() == hwnd) {
3263 #ifdef _NO_EXTENSIONS
3265 int x = LOWORD(lparam);
3266 draw_splitbar(hwnd, last_split);
3268 GetClientRect(hwnd, &rt);
3269 child->split_pos = x;
3270 resize_tree(child, rt.right, rt.bottom);
3276 #ifdef _NO_EXTENSIONS
3277 case WM_CAPTURECHANGED:
3278 if (GetCapture()==hwnd && last_split>=0)
3279 draw_splitbar(hwnd, last_split);
3284 if (wparam == VK_ESCAPE)
3285 if (GetCapture() == hwnd) {
3287 #ifdef _NO_EXTENSIONS
3288 draw_splitbar(hwnd, last_split);
3290 child->split_pos = last_split;
3292 GetClientRect(hwnd, &rt);
3293 resize_tree(child, rt.right, rt.bottom);
3296 SetCursor(LoadCursor(0, IDC_ARROW));
3301 if (GetCapture() == hwnd) {
3303 int x = LOWORD(lparam);
3305 #ifdef _NO_EXTENSIONS
3306 HDC hdc = GetDC(hwnd);
3307 GetClientRect(hwnd, &rt);
3309 rt.left = last_split-SPLIT_WIDTH/2;
3310 rt.right = last_split+SPLIT_WIDTH/2+1;
3311 InvertRect(hdc, &rt);
3314 rt.left = x-SPLIT_WIDTH/2;
3315 rt.right = x+SPLIT_WIDTH/2+1;
3316 InvertRect(hdc, &rt);
3318 ReleaseDC(hwnd, hdc);
3320 GetClientRect(hwnd, &rt);
3322 if (x>=0 && x<rt.right) {
3323 child->split_pos = x;
3324 resize_tree(child, rt.right, rt.bottom);
3325 rt.left = x-SPLIT_WIDTH/2;
3326 rt.right = x+SPLIT_WIDTH/2+1;
3327 InvalidateRect(hwnd, &rt, FALSE);
3328 UpdateWindow(child->left.hwnd);
3330 UpdateWindow(child->right.hwnd);
3336 #ifndef _NO_EXTENSIONS
3337 case WM_GETMINMAXINFO:
3338 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3340 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3342 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3343 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3345 #endif /* _NO_EXTENSIONS */
3348 SetCurrentDirectory(child->path);
3349 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3352 case WM_DISPATCH_COMMAND: {
3353 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3355 switch(LOWORD(wparam)) {
3356 case ID_WINDOW_NEW: {
3357 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3359 if (!create_child_window(new_child))
3365 scan_entry(child, pane->cur, hwnd);
3369 activate_entry(child, pane, hwnd);
3373 return pane_command(pane, LOWORD(wparam));
3379 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3381 switch(HIWORD(wparam)) {
3382 case LBN_SELCHANGE: {
3383 int idx = ListBox_GetCurSel(pane->hwnd);
3384 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3386 if (pane == &child->left)
3387 set_curdir(child, entry, hwnd);
3393 activate_entry(child, pane, hwnd);
3398 #ifndef _NO_EXTENSIONS
3400 NMHDR* pnmh = (NMHDR*) lparam;
3401 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3405 if (wparam != SIZE_MINIMIZED)
3406 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3410 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3417 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3419 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3420 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3424 #ifndef _NO_EXTENSIONS
3431 child->focus_pane = pane==&child->right? 1: 0;
3432 ListBox_SetSel(hwnd, TRUE, 1);
3433 /*TODO: check menu items */
3437 if (wparam == VK_TAB) {
3438 /*TODO: SetFocus(Globals.hdrivebar) */
3439 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3443 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3447 static void InitInstance(HINSTANCE hinstance)
3453 INITCOMMONCONTROLSEX icc = {
3454 sizeof(INITCOMMONCONTROLSEX),
3460 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3462 InitCommonControlsEx(&icc);
3465 /* register frame window class */
3467 wcFrame.cbSize = sizeof(WNDCLASSEX);
3469 wcFrame.lpfnWndProc = FrameWndProc;
3470 wcFrame.cbClsExtra = 0;
3471 wcFrame.cbWndExtra = 0;
3472 wcFrame.hInstance = hinstance;
3473 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3474 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3475 wcFrame.hbrBackground = 0;
3476 wcFrame.lpszMenuName = 0;
3477 wcFrame.lpszClassName = WINEFILEFRAME;
3478 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3479 MAKEINTRESOURCE(IDI_WINEFILE),
3481 GetSystemMetrics(SM_CXSMICON),
3482 GetSystemMetrics(SM_CYSMICON),
3485 Globals.hframeClass = RegisterClassEx(&wcFrame);
3488 /* register tree windows class */
3490 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3491 wcChild.lpfnWndProc = ChildWndProc;
3492 wcChild.cbClsExtra = 0;
3493 wcChild.cbWndExtra = 0;
3494 wcChild.hInstance = hinstance;
3496 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3497 wcChild.hbrBackground = 0;
3498 wcChild.lpszMenuName = 0;
3499 wcChild.lpszClassName = WINEFILETREE;
3501 hChildClass = RegisterClass(&wcChild);
3504 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3506 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"));
3510 Globals.hInstance = hinstance;
3512 #ifdef _SHELL_FOLDERS
3514 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3515 SHGetDesktopFolder(&Globals.iDesktop);
3516 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3521 void show_frame(HWND hwndParent, int cmdshow)
3523 TCHAR path[MAX_PATH];
3525 HMENU hMenuFrame, hMenuWindow;
3527 CLIENTCREATESTRUCT ccs;
3529 if (Globals.hMainWnd)
3532 Globals.hwndParent = hwndParent;
3534 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3535 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3537 Globals.hMenuFrame = hMenuFrame;
3538 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3539 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3541 ccs.hWindowMenu = hMenuWindow;
3542 ccs.idFirstChild = IDW_FIRST_CHILD;
3545 /* create main window */
3546 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3547 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3548 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3551 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3552 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3554 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3558 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0};
3562 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3563 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3564 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3565 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3567 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3569 drivebarBtn.fsStyle = TBSTYLE_BUTTON;
3571 #ifndef _NO_EXTENSIONS
3573 /* insert unix file system button */
3574 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3576 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3577 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3578 drivebarBtn.iString++;
3580 #ifdef _SHELL_FOLDERS
3581 /* insert shell namespace button */
3582 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3584 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3585 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3586 drivebarBtn.iString++;
3589 /* register windows drive root strings */
3590 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3593 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3595 for(p=Globals.drives; *p; ) {
3596 #ifdef _NO_EXTENSIONS
3597 /* insert drive letter */
3598 TCHAR b[3] = {tolower(*p)};
3599 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3601 switch(GetDriveType(p)) {
3602 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3603 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3604 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3605 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3606 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3609 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3610 drivebarBtn.idCommand++;
3611 drivebarBtn.iString++;
3618 TBBUTTON toolbarBtns[] = {
3619 {0, 0, 0, TBSTYLE_SEP, {0, 0}, 0, 0},
3620 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3621 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3622 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3623 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0},
3625 {4, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3626 {5, ID_... , TBSTATE_ENABLED, TBSTYLE_BUTTON},
3629 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3630 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3631 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3632 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3635 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3636 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3638 /* CreateStatusWindow does not accept WS_BORDER
3639 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3640 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3641 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3643 /*TODO: read paths and window placements from registry */
3644 GetCurrentDirectory(MAX_PATH, path);
3646 ShowWindow(Globals.hMainWnd, cmdshow);
3648 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3649 /* Shell Namespace as default: */
3650 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3652 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3655 child->pos.showCmd = SW_SHOWMAXIMIZED;
3656 child->pos.rcNormalPosition.left = 0;
3657 child->pos.rcNormalPosition.top = 0;
3658 child->pos.rcNormalPosition.right = 320;
3659 child->pos.rcNormalPosition.bottom = 280;
3661 if (!create_child_window(child))
3664 SetWindowPlacement(child->hwnd, &child->pos);
3666 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3668 Globals.prescan_node = FALSE;
3670 UpdateWindow(Globals.hMainWnd);
3675 #ifdef _SHELL_FOLDERS
3676 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3677 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3681 ImageList_Destroy(Globals.himl);
3685 /* search for already running win[e]files */
3687 static int g_foundPrevInstance = 0;
3689 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3693 GetClassName(hwnd, cls, 128);
3695 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3696 g_foundPrevInstance++;
3703 /* search for window of given class name to allow only one running instance */
3704 int find_window_class(LPCTSTR classname)
3706 EnumWindows(EnumWndProc, (LPARAM)classname);
3708 if (g_foundPrevInstance)
3715 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3719 InitInstance(hinstance);
3721 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3722 if (cmdshow == SW_SHOWNORMAL)
3723 /*TODO: read window placement from registry */
3724 cmdshow = SW_MAXIMIZE;
3727 show_frame(hwndParent, cmdshow);
3729 while(GetMessage(&msg, 0, 0, 0)) {
3730 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3733 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3736 TranslateMessage(&msg);
3737 DispatchMessage(&msg);
3748 int APIENTRY WinMain(HINSTANCE hinstance,
3749 HINSTANCE previnstance,
3753 #ifdef _NO_EXTENSIONS
3754 if (find_window_class(WINEFILEFRAME))
3758 winefile_main(hinstance, 0, cmdshow);