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 = HeapAlloc(GetProcessHeap(), 0, 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++)
1105 HeapFree( GetProcessHeap(), 0, array );
1110 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1112 TCHAR buffer[MAX_PATH];
1117 #ifdef _SHELL_FOLDERS
1118 if (dir->etype == ET_SHELL)
1120 read_directory_shell(dir, hwnd);
1122 if (Globals.prescan_node) {
1131 for(entry=dir->down; entry; entry=entry->next)
1132 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1133 read_directory_shell(entry, hwnd);
1134 SortDirectory(entry, sortOrder);
1140 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1141 if (dir->etype == ET_UNIX)
1143 read_directory_unix(dir, path);
1145 if (Globals.prescan_node) {
1154 for(entry=dir->down; entry; entry=entry->next)
1155 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1156 lstrcpy(d, entry->data.cFileName);
1157 read_directory_unix(entry, buffer);
1158 SortDirectory(entry, sortOrder);
1165 read_directory_win(dir, path);
1167 if (Globals.prescan_node) {
1176 for(entry=dir->down; entry; entry=entry->next)
1177 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1178 lstrcpy(d, entry->data.cFileName);
1179 read_directory_win(entry, buffer);
1180 SortDirectory(entry, sortOrder);
1185 SortDirectory(dir, sortOrder);
1189 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1191 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1192 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1193 Root* root = &child->root;
1196 memset(child, 0, sizeof(ChildWnd));
1198 child->left.treePane = TRUE;
1199 child->left.visible_cols = 0;
1201 child->right.treePane = FALSE;
1202 #ifndef _NO_EXTENSIONS
1203 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1205 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1208 child->pos.length = sizeof(WINDOWPLACEMENT);
1209 child->pos.flags = 0;
1210 child->pos.showCmd = SW_SHOWNORMAL;
1211 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1212 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1213 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1214 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1216 child->focus_pane = 0;
1217 child->split_pos = DEFAULT_SPLIT_POS;
1218 child->sortOrder = SORT_NAME;
1219 child->header_wdths_ok = FALSE;
1223 lstrcpy(child->path, path);
1225 _tsplitpath(path, drv, dir, name, ext);
1228 root->entry.level = 0;
1230 #ifdef _SHELL_FOLDERS
1233 root->drive_type = DRIVE_UNKNOWN;
1234 lstrcpy(drv, TEXT("\\"));
1235 lstrcpy(root->volname, TEXT("Desktop"));
1237 lstrcpy(root->fs, TEXT("Shell"));
1239 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1243 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1246 root->drive_type = GetDriveType(path);
1248 lstrcat(drv, TEXT("/"));
1249 lstrcpy(root->volname, TEXT("root fs"));
1251 lstrcpy(root->fs, TEXT("unixfs"));
1253 lstrcpy(root->path, TEXT("/"));
1254 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1259 root->drive_type = GetDriveType(path);
1261 lstrcat(drv, TEXT("\\"));
1262 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1264 lstrcpy(root->path, drv);
1265 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1268 #ifdef _SHELL_FOLDERS
1269 if (root->entry.etype == ET_SHELL)
1270 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1273 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1275 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1277 child->left.root = &root->entry;
1278 child->right.root = NULL;
1280 set_curdir(child, entry, hwnd);
1286 /* free all memory associated with a child window */
1287 static void free_child_window(ChildWnd* child)
1289 free_entries(&child->root.entry);
1294 /* get full path of specified directory entry */
1295 static void get_path(Entry* dir, PTSTR path)
1301 #ifdef _SHELL_FOLDERS
1302 if (dir->etype == ET_SHELL)
1307 path[0] = TEXT('\0');
1312 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1314 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1315 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1317 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1323 for(entry=dir; entry; level++) {
1329 name = entry->data.cFileName;
1332 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1338 memmove(path+l+1, path, len*sizeof(TCHAR));
1339 memcpy(path+1, name, l*sizeof(TCHAR));
1342 #ifndef _NO_EXTENSIONS
1343 if (entry->etype == ET_UNIX)
1344 path[0] = TEXT('/');
1347 path[0] = TEXT('\\');
1352 memmove(path+l, path, len*sizeof(TCHAR));
1353 memcpy(path, name, l*sizeof(TCHAR));
1360 #ifndef _NO_EXTENSIONS
1361 if (entry->etype == ET_UNIX)
1362 path[len++] = TEXT('/');
1365 path[len++] = TEXT('\\');
1368 path[len] = TEXT('\0');
1373 static void resize_frame_rect(HWND hwnd, PRECT prect)
1378 if (IsWindowVisible(Globals.htoolbar)) {
1379 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1380 GetClientRect(Globals.htoolbar, &rt);
1381 prect->top = rt.bottom+3;
1382 prect->bottom -= rt.bottom+3;
1385 if (IsWindowVisible(Globals.hdrivebar)) {
1386 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1387 GetClientRect(Globals.hdrivebar, &rt);
1388 new_top = --prect->top + rt.bottom+3;
1389 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1390 prect->top = new_top;
1391 prect->bottom -= rt.bottom+2;
1394 if (IsWindowVisible(Globals.hstatusbar)) {
1395 int parts[] = {300, 500};
1397 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1398 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1399 GetClientRect(Globals.hstatusbar, &rt);
1400 prect->bottom -= rt.bottom;
1403 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1406 static void resize_frame(HWND hwnd, int cx, int cy)
1415 resize_frame_rect(hwnd, &rect);
1418 static void resize_frame_client(HWND hwnd)
1422 GetClientRect(hwnd, &rect);
1424 resize_frame_rect(hwnd, &rect);
1428 static HHOOK hcbthook;
1429 static ChildWnd* newchild = NULL;
1431 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1433 if (code==HCBT_CREATEWND && newchild) {
1434 ChildWnd* child = newchild;
1437 child->hwnd = (HWND) wparam;
1438 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1441 return CallNextHookEx(hcbthook, code, wparam, lparam);
1444 static HWND create_child_window(ChildWnd* child)
1446 MDICREATESTRUCT mcs;
1449 mcs.szClass = WINEFILETREE;
1450 mcs.szTitle = (LPTSTR)child->path;
1451 mcs.hOwner = Globals.hInstance;
1452 mcs.x = child->pos.rcNormalPosition.left;
1453 mcs.y = child->pos.rcNormalPosition.top;
1454 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1455 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1459 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1462 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1464 UnhookWindowsHookEx(hcbthook);
1468 UnhookWindowsHookEx(hcbthook);
1470 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1471 ListBox_SetCurSel(child->left.hwnd, idx);
1477 struct ExecuteDialog {
1478 TCHAR cmd[MAX_PATH];
1483 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1485 static struct ExecuteDialog* dlg;
1489 dlg = (struct ExecuteDialog*) lparam;
1493 int id = (int)wparam;
1496 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1497 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1498 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1499 EndDialog(hwnd, id);
1500 } else if (id == IDCANCEL)
1501 EndDialog(hwnd, id);
1510 #ifndef _NO_EXTENSIONS
1512 static struct FullScreenParameters {
1522 void frame_get_clientspace(HWND hwnd, PRECT prect)
1526 if (!IsIconic(hwnd))
1527 GetClientRect(hwnd, prect);
1531 GetWindowPlacement(hwnd, &wp);
1533 prect->left = prect->top = 0;
1534 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1535 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1536 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1537 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1538 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1541 if (IsWindowVisible(Globals.htoolbar)) {
1542 GetClientRect(Globals.htoolbar, &rt);
1543 prect->top += rt.bottom+2;
1546 if (IsWindowVisible(Globals.hdrivebar)) {
1547 GetClientRect(Globals.hdrivebar, &rt);
1548 prect->top += rt.bottom+2;
1551 if (IsWindowVisible(Globals.hstatusbar)) {
1552 GetClientRect(Globals.hstatusbar, &rt);
1553 prect->bottom -= rt.bottom;
1557 static BOOL toggle_fullscreen(HWND hwnd)
1561 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1562 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1563 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1565 Frame_CalcFrameClient(hwnd, &rt);
1566 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1567 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1569 rt.left = g_fullscreen.orgPos.left-rt.left;
1570 rt.top = g_fullscreen.orgPos.top-rt.top;
1571 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1572 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1574 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1576 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1577 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1578 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1580 if (g_fullscreen.wasZoomed)
1581 ShowWindow(hwnd, WS_MAXIMIZE);
1584 return g_fullscreen.mode;
1587 static void fullscreen_move(HWND hwnd)
1590 GetWindowRect(hwnd, &pos);
1592 Frame_CalcFrameClient(hwnd, &rt);
1593 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1594 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1596 rt.left = pos.left-rt.left;
1597 rt.top = pos.top-rt.top;
1598 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1599 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1601 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1607 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1609 BOOL vis = IsWindowVisible(hchild);
1611 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1613 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1615 #ifndef _NO_EXTENSIONS
1616 if (g_fullscreen.mode)
1617 fullscreen_move(hwnd);
1620 resize_frame_client(hwnd);
1623 BOOL activate_drive_window(LPCTSTR path)
1625 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1628 _tsplitpath(path, drv1, 0, 0, 0);
1630 /* search for a already open window for the same drive */
1631 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1632 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1635 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1637 if (!lstrcmpi(drv2, drv1)) {
1638 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1640 if (IsMinimized(child_wnd))
1641 ShowWindow(child_wnd, SW_SHOWNORMAL);
1651 BOOL activate_fs_window(LPCTSTR filesys)
1655 /* search for a already open window of the given file system name */
1656 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1657 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1660 if (!lstrcmpi(child->root.fs, filesys)) {
1661 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1663 if (IsMinimized(child_wnd))
1664 ShowWindow(child_wnd, SW_SHOWNORMAL);
1674 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1678 DestroyWindow(hwnd);
1680 /* clear handle variables */
1681 Globals.hMenuFrame = 0;
1682 Globals.hMenuView = 0;
1683 Globals.hMenuOptions = 0;
1684 Globals.hMainWnd = 0;
1685 Globals.hmdiclient = 0;
1686 Globals.hdrivebar = 0;
1690 /* don't exit desktop when closing file manager window */
1691 if (!Globals.hwndParent)
1696 UINT cmd = LOWORD(wparam);
1697 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1699 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1702 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1703 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1705 LPCTSTR root = Globals.drives;
1708 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1712 if (activate_drive_window(root))
1715 _tsplitpath(root, drv, 0, 0, 0);
1717 if (!SetCurrentDirectory(drv)) {
1718 display_error(hwnd, GetLastError());
1722 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1723 child = alloc_child_window(path, NULL, hwnd);
1725 if (!create_child_window(child))
1727 } else switch(cmd) {
1729 SendMessage(hwnd, WM_CLOSE, 0, 0);
1732 case ID_WINDOW_NEW: {
1733 TCHAR path[MAX_PATH];
1736 GetCurrentDirectory(MAX_PATH, path);
1737 child = alloc_child_window(path, NULL, hwnd);
1739 if (!create_child_window(child))
1743 case ID_WINDOW_CASCADE:
1744 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1747 case ID_WINDOW_TILE_HORZ:
1748 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1751 case ID_WINDOW_TILE_VERT:
1752 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1755 case ID_WINDOW_ARRANGE:
1756 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1759 case ID_VIEW_TOOL_BAR:
1760 toggle_child(hwnd, cmd, Globals.htoolbar);
1763 case ID_VIEW_DRIVE_BAR:
1764 toggle_child(hwnd, cmd, Globals.hdrivebar);
1767 case ID_VIEW_STATUSBAR:
1768 toggle_child(hwnd, cmd, Globals.hstatusbar);
1772 struct ExecuteDialog dlg;
1774 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1776 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1777 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1779 if ((int)hinst <= 32)
1780 display_error(hwnd, GetLastError());
1785 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1788 #ifndef _NO_EXTENSIONS
1789 case ID_VIEW_FULLSCREEN:
1790 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1794 case ID_DRIVE_UNIX_FS: {
1795 TCHAR path[MAX_PATH];
1798 if (activate_fs_window(TEXT("unixfs")))
1801 getcwd(path, MAX_PATH);
1802 child = alloc_child_window(path, NULL, hwnd);
1804 if (!create_child_window(child))
1808 #ifdef _SHELL_FOLDERS
1809 case ID_DRIVE_SHELL_NS: {
1810 TCHAR path[MAX_PATH];
1813 if (activate_fs_window(TEXT("Shell")))
1816 GetCurrentDirectory(MAX_PATH, path);
1817 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1819 if (!create_child_window(child))
1825 /*TODO: There are even more menu items! */
1827 #ifndef _NO_EXTENSIONS
1830 WineLicense(Globals.hMainWnd);
1833 case ID_NO_WARRANTY:
1834 WineWarranty(Globals.hMainWnd);
1839 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1842 case ID_ABOUT: /*ID_ABOUT_WINE: */
1843 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1845 #endif /* _NO_EXTENSIONS */
1848 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1849 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1850 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1851 (cmd<SC_SIZE || cmd>SC_RESTORE))
1852 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1854 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1859 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1860 break; /* do not pass message to DefFrameProc */
1862 #ifndef _NO_EXTENSIONS
1863 case WM_GETMINMAXINFO: {
1864 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1866 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1867 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1870 case FRM_CALC_CLIENT:
1871 frame_get_clientspace(hwnd, (PRECT)lparam);
1873 #endif /* _NO_EXTENSIONS */
1876 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1883 static const LPTSTR g_pos_names[COLUMNS] = {
1884 TEXT(""), /* symbol */
1888 #ifndef _NO_EXTENSIONS
1891 TEXT("Index/Inode"),
1893 #endif /* _NO_EXTENSIONS */
1895 #ifndef _NO_EXTENSIONS
1900 static const int g_pos_align[] = {
1902 HDF_LEFT, /* Name */
1903 HDF_RIGHT, /* Size */
1904 HDF_LEFT, /* CDate */
1905 #ifndef _NO_EXTENSIONS
1906 HDF_LEFT, /* ADate */
1907 HDF_LEFT, /* MDate */
1908 HDF_LEFT, /* Index */
1909 HDF_CENTER, /* Links */
1911 HDF_CENTER, /* Attributes */
1912 #ifndef _NO_EXTENSIONS
1913 HDF_LEFT /* Security */
1917 static void resize_tree(ChildWnd* child, int cx, int cy)
1919 HDWP hdwp = BeginDeferWindowPos(4);
1927 cx = child->split_pos + SPLIT_WIDTH/2;
1929 #ifndef _NO_EXTENSIONS
1937 Header_Layout(child->left.hwndHeader, &hdl);
1939 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1940 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1941 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1942 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1944 #endif /* _NO_EXTENSIONS */
1946 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);
1947 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1949 EndDeferWindowPos(hdwp);
1953 #ifndef _NO_EXTENSIONS
1955 static HWND create_header(HWND parent, Pane* pane, int id)
1960 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1961 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1965 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1967 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1969 for(idx=0; idx<COLUMNS; idx++) {
1970 hdi.pszText = g_pos_names[idx];
1971 hdi.fmt = HDF_STRING | g_pos_align[idx];
1972 hdi.cxy = pane->widths[idx];
1973 Header_InsertItem(hwnd, idx, &hdi);
1979 #endif /* _NO_EXTENSIONS */
1982 static void init_output(HWND hwnd)
1986 HDC hdc = GetDC(hwnd);
1988 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1989 Globals.num_sep = b[1];
1991 Globals.num_sep = TEXT('.');
1993 old_font = SelectFont(hdc, Globals.hfont);
1994 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1995 SelectFont(hdc, old_font);
1996 ReleaseDC(hwnd, hdc);
1999 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2002 /* calculate prefered width for all visible columns */
2004 static BOOL calc_widths(Pane* pane, BOOL anyway)
2006 int col, x, cx, spc=3*Globals.spaceSize.cx;
2007 int entries = ListBox_GetCount(pane->hwnd);
2008 int orgWidths[COLUMNS];
2009 int orgPositions[COLUMNS+1];
2015 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2016 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2019 for(col=0; col<COLUMNS; col++)
2020 pane->widths[col] = 0;
2022 hdc = GetDC(pane->hwnd);
2023 hfontOld = SelectFont(hdc, Globals.hfont);
2025 for(cnt=0; cnt<entries; cnt++) {
2026 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2035 dis.hwndItem = pane->hwnd;
2037 dis.rcItem.left = 0;
2039 dis.rcItem.right = 0;
2040 dis.rcItem.bottom = 0;
2041 /*dis.itemData = 0; */
2043 draw_item(pane, &dis, entry, COLUMNS);
2046 SelectObject(hdc, hfontOld);
2047 ReleaseDC(pane->hwnd, hdc);
2050 for(col=0; col<COLUMNS; col++) {
2051 pane->positions[col] = x;
2052 cx = pane->widths[col];
2057 if (cx < IMAGE_WIDTH)
2060 pane->widths[col] = cx;
2066 pane->positions[COLUMNS] = x;
2068 ListBox_SetHorizontalExtent(pane->hwnd, x);
2071 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2074 /* don't move, if only collapsing an entry */
2075 if (!anyway && pane->widths[0]<orgWidths[0] &&
2076 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2077 pane->widths[0] = orgWidths[0];
2078 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2083 InvalidateRect(pane->hwnd, 0, TRUE);
2089 /* calculate one prefered column width */
2091 static void calc_single_width(Pane* pane, int col)
2095 int entries = ListBox_GetCount(pane->hwnd);
2099 pane->widths[col] = 0;
2101 hdc = GetDC(pane->hwnd);
2102 hfontOld = SelectFont(hdc, Globals.hfont);
2104 for(cnt=0; cnt<entries; cnt++) {
2105 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2113 dis.hwndItem = pane->hwnd;
2115 dis.rcItem.left = 0;
2117 dis.rcItem.right = 0;
2118 dis.rcItem.bottom = 0;
2119 /*dis.itemData = 0; */
2121 draw_item(pane, &dis, entry, col);
2124 SelectObject(hdc, hfontOld);
2125 ReleaseDC(pane->hwnd, hdc);
2127 cx = pane->widths[col];
2130 cx += 3*Globals.spaceSize.cx;
2132 if (cx < IMAGE_WIDTH)
2136 pane->widths[col] = cx;
2138 x = pane->positions[col] + cx;
2140 for(; col<COLUMNS; ) {
2141 pane->positions[++col] = x;
2142 x += pane->widths[col];
2145 ListBox_SetHorizontalExtent(pane->hwnd, x);
2149 /* insert listbox entries after index idx */
2151 static void insert_entries(Pane* pane, Entry* dir, int idx)
2158 ShowWindow(pane->hwnd, SW_HIDE);
2160 for(; entry; entry=entry->next) {
2162 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2166 /* don't display entries "." and ".." in the left pane */
2167 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2168 && entry->data.cFileName[0]==TEXT('.'))
2170 #ifndef _NO_EXTENSIONS
2171 entry->data.cFileName[1]==TEXT('\0') ||
2173 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2179 ListBox_InsertItemData(pane->hwnd, idx, entry);
2181 if (pane->treePane && entry->expanded)
2182 insert_entries(pane, entry->down, idx);
2185 ShowWindow(pane->hwnd, SW_SHOW);
2189 static WNDPROC g_orgTreeWndProc;
2191 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2193 static int s_init = 0;
2194 Entry* entry = pane->root;
2196 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2197 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2198 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2200 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2201 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2203 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2205 /* insert entries into listbox */
2207 insert_entries(pane, entry, -1);
2209 /* calculate column widths */
2212 init_output(pane->hwnd);
2215 calc_widths(pane, TRUE);
2217 #ifndef _NO_EXTENSIONS
2218 pane->hwndHeader = create_header(parent, pane, id_header);
2223 static void InitChildWindow(ChildWnd* child)
2225 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2226 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2230 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2236 *buffer = TEXT('\0');
2238 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2241 if (!FileTimeToLocalFileTime(ft, &lft))
2242 {err: _tcscpy(buffer,TEXT("???")); return;}
2244 if (!FileTimeToSystemTime(&lft, &systime))
2247 if (visible_cols & COL_DATE) {
2248 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2253 if (visible_cols & COL_TIME) {
2255 buffer[len-1] = ' ';
2257 buffer[len++] = ' ';
2259 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2260 buffer[len] = TEXT('\0');
2265 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2267 RECT rt = {0, 0, 0, 0};
2269 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2271 if (rt.right > pane->widths[col])
2272 pane->widths[col] = rt.right;
2275 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2277 RECT rt = {0, 0, 0, 0};
2279 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2280 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2282 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2283 /*FIXME rt (0,0) ??? */
2285 if (rt.right > pane->widths[col])
2286 pane->widths[col] = rt.right;
2290 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2292 int x = dis->rcItem.left;
2295 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2296 rt.top = dis->rcItem.top;
2297 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2298 rt.bottom = dis->rcItem.bottom;
2300 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2303 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2305 int x = dis->rcItem.left;
2308 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2309 rt.top = dis->rcItem.top;
2310 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2311 rt.bottom = dis->rcItem.bottom;
2313 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2314 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2316 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2319 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2321 int x = dis->rcItem.left;
2328 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2329 rt.top = dis->rcItem.top;
2330 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2331 rt.bottom = dis->rcItem.bottom;
2336 /* insert number separator characters */
2337 pos = lstrlen(s) % 3;
2343 *d++ = Globals.num_sep;
2347 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2351 static int is_exe_file(LPCTSTR ext)
2353 static const LPCTSTR executable_extensions[] = {
2358 #ifndef _NO_EXTENSIONS
2362 #endif /* _NO_EXTENSIONS */
2366 TCHAR ext_buffer[_MAX_EXT];
2371 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2374 for(p=executable_extensions; *p; p++)
2375 if (!_tcscmp(ext_buffer, *p))
2381 static int is_registered_type(LPCTSTR ext)
2389 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2391 TCHAR buffer[BUFFER_LEN];
2393 int visible_cols = pane->visible_cols;
2394 COLORREF bkcolor, textcolor;
2395 RECT focusRect = dis->rcItem;
2402 attrs = entry->data.dwFileAttributes;
2404 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2405 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2406 && entry->data.cFileName[2]==TEXT('\0'))
2407 img = IMG_FOLDER_UP;
2408 #ifndef _NO_EXTENSIONS
2409 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2410 img = IMG_FOLDER_CUR;
2413 #ifdef _NO_EXTENSIONS
2416 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2417 img = IMG_OPEN_FOLDER;
2421 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2425 if (is_exe_file(ext))
2426 img = IMG_EXECUTABLE;
2427 else if (is_registered_type(ext))
2437 if (pane->treePane) {
2439 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2441 if (calcWidthCol == -1) {
2443 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2446 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2449 rt_clip.left = dis->rcItem.left;
2450 rt_clip.top = dis->rcItem.top;
2451 rt_clip.right = dis->rcItem.left+pane->widths[col];
2452 rt_clip.bottom = dis->rcItem.bottom;
2454 hrgn = CreateRectRgnIndirect(&rt_clip);
2456 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2457 DeleteObject(hrgn_org);
2461 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2462 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2465 if ((up=entry->up) != NULL) {
2466 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2467 LineTo(dis->hDC, img_pos-2, y);
2469 x = img_pos - IMAGE_WIDTH/2;
2472 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2476 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2479 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2480 LineTo(dis->hDC, x, dis->rcItem.bottom);
2482 } while((up=up->up) != NULL);
2485 x = img_pos - IMAGE_WIDTH/2;
2487 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2488 LineTo(dis->hDC, x, y);
2492 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2495 LineTo(dis->hDC, x, dis->rcItem.bottom);
2497 if (entry->down && entry->expanded) {
2498 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2499 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2500 LineTo(dis->hDC, x, dis->rcItem.bottom);
2503 SelectClipRgn(dis->hDC, hrgn_org);
2504 if (hrgn_org) DeleteObject(hrgn_org);
2505 /* SelectObject(dis->hDC, holdPen); */
2506 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2507 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2509 if (right > pane->widths[col])
2510 pane->widths[col] = right;
2513 img_pos = dis->rcItem.left;
2516 img_pos = dis->rcItem.left;
2518 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2519 pane->widths[col] = IMAGE_WIDTH;
2522 if (calcWidthCol == -1) {
2523 focusRect.left = img_pos -2;
2525 #ifdef _NO_EXTENSIONS
2526 if (pane->treePane && entry) {
2529 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2531 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2535 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2536 textcolor = COLOR_COMPRESSED;
2538 #endif /* _NO_EXTENSIONS */
2539 textcolor = RGB(0,0,0);
2541 if (dis->itemState & ODS_FOCUS) {
2542 textcolor = RGB(255,255,255);
2543 bkcolor = COLOR_SELECTION;
2545 bkcolor = RGB(255,255,255);
2548 hbrush = CreateSolidBrush(bkcolor);
2549 FillRect(dis->hDC, &focusRect, hbrush);
2550 DeleteObject(hbrush);
2552 SetBkMode(dis->hDC, TRANSPARENT);
2553 SetTextColor(dis->hDC, textcolor);
2555 cx = pane->widths[col];
2557 if (cx && img!=IMG_NONE) {
2558 if (cx > IMAGE_WIDTH)
2561 #ifdef _SHELL_FOLDERS
2562 if (entry->hicon && entry->hicon!=(HICON)-1)
2563 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2566 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2567 img_pos, dis->rcItem.top, cx,
2568 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2575 #ifdef _NO_EXTENSIONS
2576 if (img >= IMG_FOLDER_UP)
2582 /* ouput file name */
2583 if (calcWidthCol == -1)
2584 output_text(pane, dis, col, entry->data.cFileName, 0);
2585 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2586 calc_width(pane, dis, col, entry->data.cFileName);
2590 #ifdef _NO_EXTENSIONS
2591 if (!pane->treePane) {
2594 /* display file size */
2595 if (visible_cols & COL_SIZE) {
2596 #ifdef _NO_EXTENSIONS
2597 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2602 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2604 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2606 if (calcWidthCol == -1)
2607 output_number(pane, dis, col, buffer);
2608 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2609 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2615 /* display file date */
2616 if (visible_cols & (COL_DATE|COL_TIME)) {
2617 #ifndef _NO_EXTENSIONS
2618 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2619 if (calcWidthCol == -1)
2620 output_text(pane, dis, col, buffer, 0);
2621 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2622 calc_width(pane, dis, col, buffer);
2625 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2626 if (calcWidthCol == -1)
2627 output_text(pane, dis, col, buffer, 0);
2628 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2629 calc_width(pane, dis, col, buffer);
2631 #endif /* _NO_EXTENSIONS */
2633 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2634 if (calcWidthCol == -1)
2635 output_text(pane, dis, col, buffer, 0);
2636 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2637 calc_width(pane, dis, col, buffer);
2641 #ifndef _NO_EXTENSIONS
2642 if (entry->bhfi_valid) {
2643 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2645 if (visible_cols & COL_INDEX) {
2646 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2647 if (calcWidthCol == -1)
2648 output_text(pane, dis, col, buffer, DT_RIGHT);
2649 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2650 calc_width(pane, dis, col, buffer);
2654 if (visible_cols & COL_LINKS) {
2655 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2656 if (calcWidthCol == -1)
2657 output_text(pane, dis, col, buffer, DT_CENTER);
2658 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2659 calc_width(pane, dis, col, buffer);
2664 #endif /* _NO_EXTENSIONS */
2666 /* show file attributes */
2667 if (visible_cols & COL_ATTRIBUTES) {
2668 #ifdef _NO_EXTENSIONS
2669 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2671 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2674 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2676 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2677 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2678 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2679 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2680 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2681 #ifndef _NO_EXTENSIONS
2682 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2683 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2684 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2685 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2686 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2687 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2688 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2689 #endif /* _NO_EXTENSIONS */
2692 if (calcWidthCol == -1)
2693 output_tabbed_text(pane, dis, col, buffer);
2694 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2695 calc_tabbed_width(pane, dis, col, buffer);
2701 if (flags.security) {
2702 DWORD rights = get_access_mask();
2704 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2706 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2707 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2708 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2709 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2710 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2711 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2712 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2713 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2714 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2715 if (rights & WRITE_DAC) buffer[22] = 'C';
2716 if (rights & WRITE_OWNER) buffer[24] = 'O';
2717 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2719 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2722 if (flags.description) {
2723 get_description(buffer);
2724 output_text(dis, col++, buffer, 0, psize);
2728 #ifdef _NO_EXTENSIONS
2731 /* draw focus frame */
2732 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2733 /* Currently [04/2000] Wine neither behaves exactly the same */
2734 /* way as WIN 95 nor like Windows NT... */
2739 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2740 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2741 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2743 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2745 lastPen = SelectPen(dis->hDC, hpen);
2746 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2747 SetROP2(dis->hDC, R2_XORPEN);
2748 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2749 SelectObject(dis->hDC, lastBrush);
2750 SelectObject(dis->hDC, lastPen);
2753 #endif /* _NO_EXTENSIONS */
2757 #ifdef _NO_EXTENSIONS
2759 static void draw_splitbar(HWND hwnd, int x)
2762 HDC hdc = GetDC(hwnd);
2764 GetClientRect(hwnd, &rt);
2766 rt.left = x - SPLIT_WIDTH/2;
2767 rt.right = x + SPLIT_WIDTH/2+1;
2769 InvertRect(hdc, &rt);
2771 ReleaseDC(hwnd, hdc);
2774 #endif /* _NO_EXTENSIONS */
2777 #ifndef _NO_EXTENSIONS
2779 static void set_header(Pane* pane)
2782 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2785 item.mask = HDI_WIDTH;
2788 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2789 x += pane->widths[i];
2790 Header_SetItem(pane->hwndHeader, i, &item);
2794 x += pane->widths[i];
2795 item.cxy = x - scroll_pos;
2796 Header_SetItem(pane->hwndHeader, i++, &item);
2798 for(; i<COLUMNS; i++) {
2799 item.cxy = pane->widths[i];
2800 x += pane->widths[i];
2801 Header_SetItem(pane->hwndHeader, i, &item);
2806 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2808 switch(pnmh->code) {
2810 case HDN_ENDTRACK: {
2811 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2812 int idx = phdn->iItem;
2813 int dx = phdn->pitem->cxy - pane->widths[idx];
2817 GetClientRect(pane->hwnd, &clnt);
2819 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not realy needed with WINELIB) */
2820 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2822 pane->widths[idx] += dx;
2824 for(i=idx; ++i<=COLUMNS; )
2825 pane->positions[i] += dx;
2828 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2832 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2834 rt_scr.right = clnt.right;
2835 rt_scr.bottom = clnt.bottom;
2837 rt_clip.left = pane->positions[idx]-scroll_pos;
2839 rt_clip.right = clnt.right;
2840 rt_clip.bottom = clnt.bottom;
2842 if (rt_scr.left < 0) rt_scr.left = 0;
2843 if (rt_clip.left < 0) rt_clip.left = 0;
2845 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2847 rt_clip.right = pane->positions[idx+1];
2848 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2850 if (pnmh->code == HDN_ENDTRACK) {
2851 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2853 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2861 case HDN_DIVIDERDBLCLICK: {
2862 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2865 calc_single_width(pane, phdn->iItem);
2866 item.mask = HDI_WIDTH;
2867 item.cxy = pane->widths[phdn->iItem];
2869 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2870 InvalidateRect(pane->hwnd, 0, TRUE);
2877 #endif /* _NO_EXTENSIONS */
2880 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2882 TCHAR path[MAX_PATH];
2883 int idx = ListBox_GetCurSel(child->left.hwnd);
2884 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2886 /* delete sub entries in left pane */
2888 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2889 Entry* sub = (Entry*) res;
2891 if (res==LB_ERR || !sub || sub->level<=entry->level)
2894 ListBox_DeleteString(child->left.hwnd, idx+1);
2897 /* empty right pane */
2898 ListBox_ResetContent(child->right.hwnd);
2900 /* release memory */
2901 free_entries(entry);
2903 /* read contents from disk */
2904 #ifdef _SHELL_FOLDERS
2905 if (entry->etype == ET_SHELL)
2907 read_directory(entry, NULL, child->sortOrder, hwnd);
2912 get_path(entry, path);
2913 read_directory(entry, path, child->sortOrder, hwnd);
2916 /* insert found entries in right pane */
2917 insert_entries(&child->right, entry->down, -1);
2918 calc_widths(&child->right, FALSE);
2919 #ifndef _NO_EXTENSIONS
2920 set_header(&child->right);
2923 child->header_wdths_ok = FALSE;
2925 SetCursor(old_cursor);
2929 /* expand a directory entry */
2931 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2936 if (!dir || dir->expanded || !dir->down)
2941 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2944 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2945 p->data.cFileName[2]=='\0' && p->next)
2949 /* no subdirectories ? */
2950 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2953 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2955 dir->expanded = TRUE;
2957 /* insert entries in left pane */
2958 insert_entries(&child->left, p, idx);
2960 if (!child->header_wdths_ok) {
2961 if (calc_widths(&child->left, FALSE)) {
2962 #ifndef _NO_EXTENSIONS
2963 set_header(&child->left);
2966 child->header_wdths_ok = TRUE;
2974 static void collapse_entry(Pane* pane, Entry* dir)
2976 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2978 ShowWindow(pane->hwnd, SW_HIDE);
2980 /* hide sub entries */
2982 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2983 Entry* sub = (Entry*) res;
2985 if (res==LB_ERR || !sub || sub->level<=dir->level)
2988 ListBox_DeleteString(pane->hwnd, idx+1);
2991 dir->expanded = FALSE;
2993 ShowWindow(pane->hwnd, SW_SHOW);
2997 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
2999 TCHAR path[MAX_PATH];
3003 child->left.cur = entry;
3004 child->right.root = entry->down? entry->down: entry;
3005 child->right.cur = entry;
3007 if (!entry->scanned)
3008 scan_entry(child, entry, hwnd);
3010 ListBox_ResetContent(child->right.hwnd);
3011 insert_entries(&child->right, entry->down, -1);
3012 calc_widths(&child->right, FALSE);
3013 #ifndef _NO_EXTENSIONS
3014 set_header(&child->right);
3018 get_path(entry, path);
3019 lstrcpy(child->path, path);
3021 if (child->hwnd) /* only change window title, if the window already exists */
3022 SetWindowText(child->hwnd, path);
3025 SetCurrentDirectory(path);
3029 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3031 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3033 if ((int)hinst <= 32) {
3034 display_error(hwnd, GetLastError());
3042 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3044 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3046 if ((int)hinst <= 32) {
3047 display_error(hwnd, GetLastError());
3056 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3058 TCHAR cmd[MAX_PATH];
3060 #ifdef _SHELL_FOLDERS
3061 if (entry->etype == ET_SHELL) {
3064 SHELLEXECUTEINFO shexinfo;
3066 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3067 shexinfo.fMask = SEE_MASK_IDLIST;
3068 shexinfo.hwnd = hwnd;
3069 shexinfo.lpVerb = NULL;
3070 shexinfo.lpFile = NULL;
3071 shexinfo.lpParameters = NULL;
3072 shexinfo.lpDirectory = NULL;
3073 shexinfo.nShow = nCmdShow;
3074 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3076 if (!ShellExecuteEx(&shexinfo)) {
3077 display_error(hwnd, GetLastError());
3081 if (shexinfo.lpIDList != entry->pidl)
3082 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3088 get_path(entry, cmd);
3090 /* start program, open document... */
3091 return launch_file(hwnd, cmd, nCmdShow);
3095 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3097 Entry* entry = pane->cur;
3102 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3103 int scanned_old = entry->scanned;
3106 scan_entry(child, entry, hwnd);
3108 #ifndef _NO_EXTENSIONS
3109 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3113 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3114 entry = child->left.cur->up;
3115 collapse_entry(&child->left, entry);
3117 } else if (entry->expanded)
3118 collapse_entry(pane, child->left.cur);
3120 expand_entry(child, child->left.cur);
3122 if (!pane->treePane) focus_entry: {
3123 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3124 ListBox_SetCurSel(child->left.hwnd, idx);
3125 set_curdir(child, entry, hwnd);
3130 calc_widths(pane, FALSE);
3132 #ifndef _NO_EXTENSIONS
3137 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3142 static BOOL pane_command(Pane* pane, UINT cmd)
3146 if (pane->visible_cols) {
3147 pane->visible_cols = 0;
3148 calc_widths(pane, TRUE);
3149 #ifndef _NO_EXTENSIONS
3152 InvalidateRect(pane->hwnd, 0, TRUE);
3153 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3154 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3155 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3159 case ID_VIEW_ALL_ATTRIBUTES:
3160 if (pane->visible_cols != COL_ALL) {
3161 pane->visible_cols = COL_ALL;
3162 calc_widths(pane, TRUE);
3163 #ifndef _NO_EXTENSIONS
3166 InvalidateRect(pane->hwnd, 0, TRUE);
3167 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3168 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3169 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3173 #ifndef _NO_EXTENSIONS
3174 case ID_PREFERED_SIZES: {
3175 calc_widths(pane, TRUE);
3177 InvalidateRect(pane->hwnd, 0, TRUE);
3181 /* TODO: more command ids... */
3191 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3193 static int last_split;
3195 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3200 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3201 Entry* entry = (Entry*) dis->itemData;
3203 if (dis->CtlID == IDW_TREE_LEFT)
3204 draw_item(&child->left, dis, entry, -1);
3206 draw_item(&child->right, dis, entry, -1);
3211 InitChildWindow(child);
3215 free_child_window(child);
3216 SetWindowLong(hwnd, GWL_USERDATA, 0);
3223 GetClientRect(hwnd, &rt);
3224 BeginPaint(hwnd, &ps);
3225 rt.left = child->split_pos-SPLIT_WIDTH/2;
3226 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3227 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3228 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3229 SelectObject(ps.hdc, lastBrush);
3230 #ifdef _NO_EXTENSIONS
3231 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3232 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3234 EndPaint(hwnd, &ps);
3238 if (LOWORD(lparam) == HTCLIENT) {
3241 ScreenToClient(hwnd, &pt);
3243 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3244 SetCursor(LoadCursor(0, IDC_SIZEWE));
3250 case WM_LBUTTONDOWN: {
3252 int x = LOWORD(lparam);
3254 GetClientRect(hwnd, &rt);
3256 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3257 last_split = child->split_pos;
3258 #ifdef _NO_EXTENSIONS
3259 draw_splitbar(hwnd, last_split);
3267 if (GetCapture() == hwnd) {
3268 #ifdef _NO_EXTENSIONS
3270 int x = LOWORD(lparam);
3271 draw_splitbar(hwnd, last_split);
3273 GetClientRect(hwnd, &rt);
3274 child->split_pos = x;
3275 resize_tree(child, rt.right, rt.bottom);
3281 #ifdef _NO_EXTENSIONS
3282 case WM_CAPTURECHANGED:
3283 if (GetCapture()==hwnd && last_split>=0)
3284 draw_splitbar(hwnd, last_split);
3289 if (wparam == VK_ESCAPE)
3290 if (GetCapture() == hwnd) {
3292 #ifdef _NO_EXTENSIONS
3293 draw_splitbar(hwnd, last_split);
3295 child->split_pos = last_split;
3297 GetClientRect(hwnd, &rt);
3298 resize_tree(child, rt.right, rt.bottom);
3301 SetCursor(LoadCursor(0, IDC_ARROW));
3306 if (GetCapture() == hwnd) {
3308 int x = LOWORD(lparam);
3310 #ifdef _NO_EXTENSIONS
3311 HDC hdc = GetDC(hwnd);
3312 GetClientRect(hwnd, &rt);
3314 rt.left = last_split-SPLIT_WIDTH/2;
3315 rt.right = last_split+SPLIT_WIDTH/2+1;
3316 InvertRect(hdc, &rt);
3319 rt.left = x-SPLIT_WIDTH/2;
3320 rt.right = x+SPLIT_WIDTH/2+1;
3321 InvertRect(hdc, &rt);
3323 ReleaseDC(hwnd, hdc);
3325 GetClientRect(hwnd, &rt);
3327 if (x>=0 && x<rt.right) {
3328 child->split_pos = x;
3329 resize_tree(child, rt.right, rt.bottom);
3330 rt.left = x-SPLIT_WIDTH/2;
3331 rt.right = x+SPLIT_WIDTH/2+1;
3332 InvalidateRect(hwnd, &rt, FALSE);
3333 UpdateWindow(child->left.hwnd);
3335 UpdateWindow(child->right.hwnd);
3341 #ifndef _NO_EXTENSIONS
3342 case WM_GETMINMAXINFO:
3343 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3345 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3347 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3348 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3350 #endif /* _NO_EXTENSIONS */
3353 SetCurrentDirectory(child->path);
3354 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3357 case WM_DISPATCH_COMMAND: {
3358 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3360 switch(LOWORD(wparam)) {
3361 case ID_WINDOW_NEW: {
3362 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3364 if (!create_child_window(new_child))
3370 scan_entry(child, pane->cur, hwnd);
3374 activate_entry(child, pane, hwnd);
3378 return pane_command(pane, LOWORD(wparam));
3384 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3386 switch(HIWORD(wparam)) {
3387 case LBN_SELCHANGE: {
3388 int idx = ListBox_GetCurSel(pane->hwnd);
3389 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3391 if (pane == &child->left)
3392 set_curdir(child, entry, hwnd);
3398 activate_entry(child, pane, hwnd);
3403 #ifndef _NO_EXTENSIONS
3405 NMHDR* pnmh = (NMHDR*) lparam;
3406 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3410 if (wparam != SIZE_MINIMIZED)
3411 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3415 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3422 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3424 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3425 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3429 #ifndef _NO_EXTENSIONS
3436 child->focus_pane = pane==&child->right? 1: 0;
3437 ListBox_SetSel(hwnd, TRUE, 1);
3438 /*TODO: check menu items */
3442 if (wparam == VK_TAB) {
3443 /*TODO: SetFocus(Globals.hdrivebar) */
3444 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3448 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3452 static void InitInstance(HINSTANCE hinstance)
3458 INITCOMMONCONTROLSEX icc = {
3459 sizeof(INITCOMMONCONTROLSEX),
3465 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3467 InitCommonControlsEx(&icc);
3470 /* register frame window class */
3472 wcFrame.cbSize = sizeof(WNDCLASSEX);
3474 wcFrame.lpfnWndProc = FrameWndProc;
3475 wcFrame.cbClsExtra = 0;
3476 wcFrame.cbWndExtra = 0;
3477 wcFrame.hInstance = hinstance;
3478 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3479 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3480 wcFrame.hbrBackground = 0;
3481 wcFrame.lpszMenuName = 0;
3482 wcFrame.lpszClassName = WINEFILEFRAME;
3483 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3484 MAKEINTRESOURCE(IDI_WINEFILE),
3486 GetSystemMetrics(SM_CXSMICON),
3487 GetSystemMetrics(SM_CYSMICON),
3490 Globals.hframeClass = RegisterClassEx(&wcFrame);
3493 /* register tree windows class */
3495 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3496 wcChild.lpfnWndProc = ChildWndProc;
3497 wcChild.cbClsExtra = 0;
3498 wcChild.cbWndExtra = 0;
3499 wcChild.hInstance = hinstance;
3501 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3502 wcChild.hbrBackground = 0;
3503 wcChild.lpszMenuName = 0;
3504 wcChild.lpszClassName = WINEFILETREE;
3506 hChildClass = RegisterClass(&wcChild);
3509 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3511 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"));
3515 Globals.hInstance = hinstance;
3517 #ifdef _SHELL_FOLDERS
3519 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3520 SHGetDesktopFolder(&Globals.iDesktop);
3521 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3526 void show_frame(HWND hwndParent, int cmdshow)
3528 TCHAR path[MAX_PATH];
3530 HMENU hMenuFrame, hMenuWindow;
3532 CLIENTCREATESTRUCT ccs;
3534 if (Globals.hMainWnd)
3537 Globals.hwndParent = hwndParent;
3539 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3540 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3542 Globals.hMenuFrame = hMenuFrame;
3543 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3544 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3546 ccs.hWindowMenu = hMenuWindow;
3547 ccs.idFirstChild = IDW_FIRST_CHILD;
3550 /* create main window */
3551 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3552 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3553 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3556 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3557 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3559 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3563 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3567 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3568 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3569 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3570 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3572 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3574 drivebarBtn.fsStyle = BTNS_BUTTON;
3576 #ifndef _NO_EXTENSIONS
3578 /* insert unix file system button */
3579 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3581 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3582 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3583 drivebarBtn.iString++;
3585 #ifdef _SHELL_FOLDERS
3586 /* insert shell namespace button */
3587 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3589 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3590 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3591 drivebarBtn.iString++;
3594 /* register windows drive root strings */
3595 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3598 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3600 for(p=Globals.drives; *p; ) {
3601 #ifdef _NO_EXTENSIONS
3602 /* insert drive letter */
3603 TCHAR b[3] = {tolower(*p)};
3604 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3606 switch(GetDriveType(p)) {
3607 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3608 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3609 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3610 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3611 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3614 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3615 drivebarBtn.idCommand++;
3616 drivebarBtn.iString++;
3623 TBBUTTON toolbarBtns[] = {
3624 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3625 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3626 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3627 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3628 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3630 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3631 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3634 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3635 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3636 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3637 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3640 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3641 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3643 /* CreateStatusWindow does not accept WS_BORDER
3644 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3645 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3646 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3648 /*TODO: read paths and window placements from registry */
3649 GetCurrentDirectory(MAX_PATH, path);
3651 ShowWindow(Globals.hMainWnd, cmdshow);
3653 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3654 /* Shell Namespace as default: */
3655 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3657 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3660 child->pos.showCmd = SW_SHOWMAXIMIZED;
3661 child->pos.rcNormalPosition.left = 0;
3662 child->pos.rcNormalPosition.top = 0;
3663 child->pos.rcNormalPosition.right = 320;
3664 child->pos.rcNormalPosition.bottom = 280;
3666 if (!create_child_window(child))
3669 SetWindowPlacement(child->hwnd, &child->pos);
3671 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3673 Globals.prescan_node = FALSE;
3675 UpdateWindow(Globals.hMainWnd);
3680 #ifdef _SHELL_FOLDERS
3681 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3682 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3686 ImageList_Destroy(Globals.himl);
3690 /* search for already running win[e]files */
3692 static int g_foundPrevInstance = 0;
3694 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3698 GetClassName(hwnd, cls, 128);
3700 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3701 g_foundPrevInstance++;
3708 /* search for window of given class name to allow only one running instance */
3709 int find_window_class(LPCTSTR classname)
3711 EnumWindows(EnumWndProc, (LPARAM)classname);
3713 if (g_foundPrevInstance)
3720 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3724 InitInstance(hinstance);
3726 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3727 if (cmdshow == SW_SHOWNORMAL)
3728 /*TODO: read window placement from registry */
3729 cmdshow = SW_MAXIMIZE;
3732 show_frame(hwndParent, cmdshow);
3734 while(GetMessage(&msg, 0, 0, 0)) {
3735 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3738 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3741 TranslateMessage(&msg);
3742 DispatchMessage(&msg);
3753 int APIENTRY WinMain(HINSTANCE hinstance,
3754 HINSTANCE previnstance,
3758 #ifdef _NO_EXTENSIONS
3759 if (find_window_class(WINEFILEFRAME))
3763 winefile_main(hinstance, 0, cmdshow);