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);
173 static void get_path(Entry* dir, PTSTR path);
175 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
176 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
177 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 static void display_error(HWND hwnd, DWORD error)
184 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
185 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
186 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
188 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
193 static Entry* alloc_entry()
195 Entry* entry = (Entry*) malloc(sizeof(Entry));
197 #ifdef _SHELL_FOLDERS
199 entry->folder = NULL;
206 /* free a directory entry */
207 static void free_entry(Entry* entry)
209 #ifdef _SHELL_FOLDERS
210 if (entry->hicon && entry->hicon!=(HICON)-1)
211 DestroyIcon(entry->hicon);
213 if (entry->folder && entry->folder!=Globals.iDesktop)
214 (*entry->folder->lpVtbl->Release)(entry->folder);
217 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
223 /* recursively free all child entries */
224 static void free_entries(Entry* dir)
226 Entry *entry, *next=dir->down;
242 static void read_directory_win(Entry* dir, LPCTSTR path)
244 Entry* first_entry = NULL;
248 int level = dir->level + 1;
249 WIN32_FIND_DATA w32fd;
251 #ifndef _NO_EXTENSIONS
255 TCHAR buffer[MAX_PATH], *p;
256 for(p=buffer; *path; )
259 lstrcpy(p, TEXT("\\*"));
261 hFind = FindFirstFile(buffer, &w32fd);
263 if (hFind != INVALID_HANDLE_VALUE) {
265 entry = alloc_entry();
273 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
276 entry->expanded = FALSE;
277 entry->scanned = FALSE;
278 entry->level = level;
280 #ifdef _NO_EXTENSIONS
281 /* hide directory entry "." */
282 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
283 LPCTSTR name = entry->data.cFileName;
285 if (name[0]=='.' && name[1]=='\0')
289 entry->etype = ET_WINDOWS;
290 entry->bhfi_valid = FALSE;
292 lstrcpy(p+1, entry->data.cFileName);
294 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
295 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
297 if (hFile != INVALID_HANDLE_VALUE) {
298 if (GetFileInformationByHandle(hFile, &entry->bhfi))
299 entry->bhfi_valid = TRUE;
306 } while(FindNextFile(hFind, &entry->data));
313 dir->down = first_entry;
318 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
322 for(entry=dir->down; entry; entry=entry->next) {
324 LPCTSTR q = entry->data.cFileName;
327 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
329 } while(tolower(*p++) == tolower(*q++));
332 q = entry->data.cAlternateFileName;
335 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
337 } while(tolower(*p++) == tolower(*q++));
344 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
346 TCHAR buffer[MAX_PATH];
347 Entry* entry = &root->entry;
351 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
353 #ifndef _NO_EXTENSIONS
354 entry->etype = ET_WINDOWS;
358 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
361 while(*s==TEXT('\\') || *s==TEXT('/'))
367 read_directory(entry, buffer, sortOrder, hwnd);
370 entry->expanded = TRUE;
375 entry = find_entry_win(entry, s);
378 SetCursor(old_cursor);
384 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
386 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
388 struct tm* tm = gmtime(t);
394 stime.wYear = tm->tm_year+1900;
395 stime.wMonth = tm->tm_mon+1;
396 /* stime.wDayOfWeek */
397 stime.wDay = tm->tm_mday;
398 stime.wHour = tm->tm_hour;
399 stime.wMinute = tm->tm_min;
400 stime.wSecond = tm->tm_sec;
402 return SystemTimeToFileTime(&stime, ftime);
405 static void read_directory_unix(Entry* dir, LPCTSTR path)
407 Entry* first_entry = NULL;
411 int level = dir->level + 1;
413 DIR* pdir = opendir(path);
418 TCHAR buffer[MAX_PATH], *p;
420 for(p=buffer; *path; )
423 if (p==buffer || p[-1]!='/')
426 while((ent=readdir(pdir))) {
427 entry = alloc_entry();
435 entry->etype = ET_UNIX;
437 lstrcpy(entry->data.cFileName, ent->d_name);
438 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
440 strcpy(p, ent->d_name);
442 if (!stat(buffer, &st)) {
443 if (S_ISDIR(st.st_mode))
444 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
446 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
447 entry->data.nFileSizeHigh = st.st_size >> 32;
449 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
450 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
451 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
453 entry->bhfi.nFileIndexLow = ent->d_ino;
454 entry->bhfi.nFileIndexHigh = 0;
456 entry->bhfi.nNumberOfLinks = st.st_nlink;
458 entry->bhfi_valid = TRUE;
460 entry->data.nFileSizeLow = 0;
461 entry->data.nFileSizeHigh = 0;
462 entry->bhfi_valid = FALSE;
467 entry->expanded = FALSE;
468 entry->scanned = FALSE;
469 entry->level = level;
479 dir->down = first_entry;
483 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
487 for(entry=dir->down; entry; entry=entry->next) {
489 LPCTSTR q = entry->data.cFileName;
492 if (!*p || *p==TEXT('/'))
494 } while(*p++ == *q++);
500 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
502 TCHAR buffer[MAX_PATH];
503 Entry* entry = &root->entry;
507 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
509 entry->etype = ET_UNIX;
512 while(*s && *s!=TEXT('/'))
515 while(*s == TEXT('/'))
521 read_directory(entry, buffer, sortOrder, hwnd);
524 entry->expanded = TRUE;
529 entry = find_entry_unix(entry, s);
532 SetCursor(old_cursor);
537 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
540 #ifdef _SHELL_FOLDERS
543 #define tcscpyn strcpyn
544 #define get_strret get_strretW
545 #define path_from_pidl path_from_pidlW
547 #define tcscpyn wcscpyn
548 #define get_strret get_strretA
549 #define path_from_pidl path_from_pidlA
553 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
558 for(s=source; count&&(*d++=*s++); )
564 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
569 for(s=source; count&&(*d++=*s++); )
576 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
580 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
584 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
588 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
592 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
596 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
600 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
604 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
609 static void free_strret(STRRET* str)
611 if (str->uType == STRRET_WSTR)
612 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
616 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
620 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
623 get_strret(&str, &pidl->mkid, buffer, len);
632 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
636 /* SHGDN_FORPARSING: get full path of id list */
637 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
640 get_strretA(&str, &pidl->mkid, buffer, len);
648 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
652 /* SHGDN_FORPARSING: get full path of id list */
653 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
656 get_strretW(&str, &pidl->mkid, buffer, len);
665 /* create an item id list from a file system path */
667 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
674 LPWSTR buffer = path;
676 WCHAR buffer[MAX_PATH];
677 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
680 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
688 /* convert an item id list from relative to absolute (=relative to the desktop) format */
690 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
692 if (entry->up && entry->up->etype==ET_SHELL) {
693 IShellFolder* folder = entry->up->folder;
694 WCHAR buffer[MAX_PATH];
696 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
702 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
707 } else if (entry->etype == ET_WINDOWS) {
708 TCHAR path[MAX_PATH];
710 get_path(entry, path);
712 return get_path_pidl(path, hwnd);
713 } else if (entry->pidl)
714 return ILClone(entry->pidl);
720 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
722 IExtractIcon* pExtract;
724 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
725 TCHAR path[_MAX_PATH];
730 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
731 if (!(flags & GIL_NOTFILENAME)) {
733 idx = 0; /* special case for some control panel applications */
735 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
736 flags &= ~GIL_DONTCACHE;
738 HICON hIconLarge = 0;
740 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
743 DestroyIcon(hIconLarge);
754 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
758 for(entry=dir->down; entry; entry=entry->next) {
759 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
760 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
767 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
769 Entry* entry = &root->entry;
771 LPITEMIDLIST next_pidl = pidl;
772 IShellFolder* folder;
773 IShellFolder* child = NULL;
776 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
778 #ifndef _NO_EXTENSIONS
779 entry->etype = ET_SHELL;
782 folder = Globals.iDesktop;
785 entry->pidl = next_pidl;
786 entry->folder = folder;
791 /* copy first element of item idlist */
792 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
793 memcpy(next_pidl, pidl, pidl->mkid.cb);
794 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
796 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
800 read_directory(entry, NULL, sortOrder, hwnd);
803 entry->expanded = TRUE;
805 next = find_entry_shell(entry, next_pidl);
812 /* go to next element */
813 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
816 SetCursor(old_cursor);
822 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
824 if (!(attribs & SFGAO_FILESYSTEM) ||
825 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
826 WIN32_FILE_ATTRIBUTE_DATA fad;
827 IDataObject* pDataObj;
829 STGMEDIUM medium = {0, {0}, 0};
830 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
832 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
835 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
837 (*pDataObj->lpVtbl->Release)(pDataObj);
840 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
841 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
843 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
844 w32fdata->dwFileAttributes = fad.dwFileAttributes;
845 w32fdata->ftCreationTime = fad.ftCreationTime;
846 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
847 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
849 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
850 w32fdata->nFileSizeLow = fad.nFileSizeLow;
851 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
855 SetErrorMode(sem_org);
857 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
858 GlobalFree(medium.UNION_MEMBER(hGlobal));
863 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
864 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
866 if (attribs & SFGAO_READONLY)
867 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
869 if (attribs & SFGAO_COMPRESSED)
870 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
874 static void read_directory_shell(Entry* dir, HWND hwnd)
876 IShellFolder* folder = dir->folder;
877 int level = dir->level + 1;
883 Entry* first_entry = NULL;
890 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
894 #define FETCH_ITEM_COUNT 32
895 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
900 memset(pidls, 0, sizeof(pidls));
902 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
909 for(n=0; n<cnt; ++n) {
910 entry = alloc_entry();
918 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
919 entry->bhfi_valid = FALSE;
921 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
923 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
926 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
927 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
929 entry->bhfi_valid = TRUE;
935 entry->pidl = pidls[n];
937 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
938 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
941 entry->folder = child;
943 entry->folder = NULL;
946 entry->folder = NULL;
948 if (!entry->data.cFileName[0])
949 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
951 /* get display icons for files and virtual objects */
952 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
953 !(attribs & SFGAO_FILESYSTEM)) {
954 entry->hicon = extract_icon(folder, pidls[n]);
957 entry->hicon = (HICON)-1; /* don't try again later */
962 entry->expanded = FALSE;
963 entry->scanned = FALSE;
964 entry->level = level;
966 #ifndef _NO_EXTENSIONS
967 entry->etype = ET_SHELL;
968 entry->bhfi_valid = FALSE;
975 (*idlist->lpVtbl->Release)(idlist);
981 dir->down = first_entry;
985 #endif /* _SHELL_FOLDERS */
988 /* sort order for different directory/file types */
997 /* distinguish between ".", ".." and any other directory names */
998 static int TypeOrderFromDirname(LPCTSTR name)
1000 if (name[0] == '.') {
1001 if (name[1] == '\0')
1002 return TO_DOT; /* "." */
1004 if (name[1]=='.' && name[2]=='\0')
1005 return TO_DOTDOT; /* ".." */
1008 return TO_OTHER_DIR; /* anything else */
1011 /* directories first... */
1012 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1014 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1015 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1017 /* Handle "." and ".." as special case and move them at the very first beginning. */
1018 if (order1==TO_DIR && order2==TO_DIR) {
1019 order1 = TypeOrderFromDirname(fd1->cFileName);
1020 order2 = TypeOrderFromDirname(fd2->cFileName);
1023 return order2==order1? 0: order1<order2? -1: 1;
1027 static int compareName(const void* arg1, const void* arg2)
1029 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1030 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1032 int cmp = compareType(fd1, fd2);
1036 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1039 static int compareExt(const void* arg1, const void* arg2)
1041 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1042 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1043 const TCHAR *name1, *name2, *ext1, *ext2;
1045 int cmp = compareType(fd1, fd2);
1049 name1 = fd1->cFileName;
1050 name2 = fd2->cFileName;
1052 ext1 = _tcsrchr(name1, TEXT('.'));
1053 ext2 = _tcsrchr(name2, TEXT('.'));
1065 cmp = lstrcmpi(ext1, ext2);
1069 return lstrcmpi(name1, name2);
1072 static int compareSize(const void* arg1, const void* arg2)
1074 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1075 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1077 int cmp = compareType(fd1, fd2);
1081 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1088 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1090 return cmp<0? -1: cmp>0? 1: 0;
1093 static int compareDate(const void* arg1, const void* arg2)
1095 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1096 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1098 int cmp = compareType(fd1, fd2);
1102 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1106 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1107 compareName, /* SORT_NAME */
1108 compareExt, /* SORT_EXT */
1109 compareSize, /* SORT_SIZE */
1110 compareDate /* SORT_DATE */
1114 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1116 Entry* entry = dir->down;
1121 for(entry=dir->down; entry; entry=entry->next)
1125 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1128 for(entry=dir->down; entry; entry=entry->next)
1131 /* call qsort with the appropriate compare function */
1132 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1134 dir->down = array[0];
1136 for(p=array; --len; p++)
1140 HeapFree( GetProcessHeap(), 0, array );
1145 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1147 TCHAR buffer[MAX_PATH];
1152 #ifdef _SHELL_FOLDERS
1153 if (dir->etype == ET_SHELL)
1155 read_directory_shell(dir, hwnd);
1157 if (Globals.prescan_node) {
1166 for(entry=dir->down; entry; entry=entry->next)
1167 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1168 read_directory_shell(entry, hwnd);
1169 SortDirectory(entry, sortOrder);
1175 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1176 if (dir->etype == ET_UNIX)
1178 read_directory_unix(dir, path);
1180 if (Globals.prescan_node) {
1189 for(entry=dir->down; entry; entry=entry->next)
1190 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1191 lstrcpy(d, entry->data.cFileName);
1192 read_directory_unix(entry, buffer);
1193 SortDirectory(entry, sortOrder);
1200 read_directory_win(dir, path);
1202 if (Globals.prescan_node) {
1211 for(entry=dir->down; entry; entry=entry->next)
1212 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1213 lstrcpy(d, entry->data.cFileName);
1214 read_directory_win(entry, buffer);
1215 SortDirectory(entry, sortOrder);
1220 SortDirectory(dir, sortOrder);
1224 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1226 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1227 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1228 Root* root = &child->root;
1231 memset(child, 0, sizeof(ChildWnd));
1233 child->left.treePane = TRUE;
1234 child->left.visible_cols = 0;
1236 child->right.treePane = FALSE;
1237 #ifndef _NO_EXTENSIONS
1238 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1240 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1243 child->pos.length = sizeof(WINDOWPLACEMENT);
1244 child->pos.flags = 0;
1245 child->pos.showCmd = SW_SHOWNORMAL;
1246 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1247 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1248 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1249 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1251 child->focus_pane = 0;
1252 child->split_pos = DEFAULT_SPLIT_POS;
1253 child->sortOrder = SORT_NAME;
1254 child->header_wdths_ok = FALSE;
1258 lstrcpy(child->path, path);
1260 _tsplitpath(path, drv, dir, name, ext);
1263 root->entry.level = 0;
1265 #ifdef _SHELL_FOLDERS
1268 root->drive_type = DRIVE_UNKNOWN;
1269 lstrcpy(drv, TEXT("\\"));
1270 lstrcpy(root->volname, TEXT("Desktop"));
1272 lstrcpy(root->fs, TEXT("Shell"));
1274 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1278 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1281 root->drive_type = GetDriveType(path);
1283 lstrcat(drv, TEXT("/"));
1284 lstrcpy(root->volname, TEXT("root fs"));
1286 lstrcpy(root->fs, TEXT("unixfs"));
1288 lstrcpy(root->path, TEXT("/"));
1289 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1294 root->drive_type = GetDriveType(path);
1296 lstrcat(drv, TEXT("\\"));
1297 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1299 lstrcpy(root->path, drv);
1300 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1303 #ifdef _SHELL_FOLDERS
1304 if (root->entry.etype == ET_SHELL)
1305 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1308 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1310 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1312 child->left.root = &root->entry;
1313 child->right.root = NULL;
1315 set_curdir(child, entry, hwnd);
1321 /* free all memory associated with a child window */
1322 static void free_child_window(ChildWnd* child)
1324 free_entries(&child->root.entry);
1329 /* get full path of specified directory entry */
1330 static void get_path(Entry* dir, PTSTR path)
1336 #ifdef _SHELL_FOLDERS
1337 if (dir->etype == ET_SHELL)
1342 path[0] = TEXT('\0');
1347 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1349 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1350 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1352 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1358 for(entry=dir; entry; level++) {
1364 name = entry->data.cFileName;
1367 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1373 memmove(path+l+1, path, len*sizeof(TCHAR));
1374 memcpy(path+1, name, l*sizeof(TCHAR));
1377 #ifndef _NO_EXTENSIONS
1378 if (entry->etype == ET_UNIX)
1379 path[0] = TEXT('/');
1382 path[0] = TEXT('\\');
1387 memmove(path+l, path, len*sizeof(TCHAR));
1388 memcpy(path, name, l*sizeof(TCHAR));
1395 #ifndef _NO_EXTENSIONS
1396 if (entry->etype == ET_UNIX)
1397 path[len++] = TEXT('/');
1400 path[len++] = TEXT('\\');
1403 path[len] = TEXT('\0');
1408 static void resize_frame_rect(HWND hwnd, PRECT prect)
1413 if (IsWindowVisible(Globals.htoolbar)) {
1414 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1415 GetClientRect(Globals.htoolbar, &rt);
1416 prect->top = rt.bottom+3;
1417 prect->bottom -= rt.bottom+3;
1420 if (IsWindowVisible(Globals.hdrivebar)) {
1421 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1422 GetClientRect(Globals.hdrivebar, &rt);
1423 new_top = --prect->top + rt.bottom+3;
1424 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1425 prect->top = new_top;
1426 prect->bottom -= rt.bottom+2;
1429 if (IsWindowVisible(Globals.hstatusbar)) {
1430 int parts[] = {300, 500};
1432 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1433 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1434 GetClientRect(Globals.hstatusbar, &rt);
1435 prect->bottom -= rt.bottom;
1438 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1441 static void resize_frame(HWND hwnd, int cx, int cy)
1450 resize_frame_rect(hwnd, &rect);
1453 static void resize_frame_client(HWND hwnd)
1457 GetClientRect(hwnd, &rect);
1459 resize_frame_rect(hwnd, &rect);
1463 static HHOOK hcbthook;
1464 static ChildWnd* newchild = NULL;
1466 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1468 if (code==HCBT_CREATEWND && newchild) {
1469 ChildWnd* child = newchild;
1472 child->hwnd = (HWND) wparam;
1473 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1476 return CallNextHookEx(hcbthook, code, wparam, lparam);
1479 static HWND create_child_window(ChildWnd* child)
1481 MDICREATESTRUCT mcs;
1484 mcs.szClass = WINEFILETREE;
1485 mcs.szTitle = (LPTSTR)child->path;
1486 mcs.hOwner = Globals.hInstance;
1487 mcs.x = child->pos.rcNormalPosition.left;
1488 mcs.y = child->pos.rcNormalPosition.top;
1489 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1490 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1494 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1497 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1499 UnhookWindowsHookEx(hcbthook);
1503 UnhookWindowsHookEx(hcbthook);
1505 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1506 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1507 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1508 ListBox_SetCurSel(child->left.hwnd, idx);
1514 struct ExecuteDialog {
1515 TCHAR cmd[MAX_PATH];
1520 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1522 static struct ExecuteDialog* dlg;
1526 dlg = (struct ExecuteDialog*) lparam;
1530 int id = (int)wparam;
1533 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1534 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1535 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1536 EndDialog(hwnd, id);
1537 } else if (id == IDCANCEL)
1538 EndDialog(hwnd, id);
1546 static BOOL CALLBACK sDestinationWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1553 int id = (int)wparam;
1556 dest = malloc(MAX_PATH);
1557 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1558 EndDialog(hwnd, (int)dest);
1560 else if (id == IDCANCEL) EndDialog(hwnd, id);
1561 else if (id == 254) MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1570 #ifndef _NO_EXTENSIONS
1572 static struct FullScreenParameters {
1582 void frame_get_clientspace(HWND hwnd, PRECT prect)
1586 if (!IsIconic(hwnd))
1587 GetClientRect(hwnd, prect);
1591 GetWindowPlacement(hwnd, &wp);
1593 prect->left = prect->top = 0;
1594 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1595 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1596 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1597 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1598 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1601 if (IsWindowVisible(Globals.htoolbar)) {
1602 GetClientRect(Globals.htoolbar, &rt);
1603 prect->top += rt.bottom+2;
1606 if (IsWindowVisible(Globals.hdrivebar)) {
1607 GetClientRect(Globals.hdrivebar, &rt);
1608 prect->top += rt.bottom+2;
1611 if (IsWindowVisible(Globals.hstatusbar)) {
1612 GetClientRect(Globals.hstatusbar, &rt);
1613 prect->bottom -= rt.bottom;
1617 static BOOL toggle_fullscreen(HWND hwnd)
1621 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1622 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1623 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1625 Frame_CalcFrameClient(hwnd, &rt);
1626 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1627 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1629 rt.left = g_fullscreen.orgPos.left-rt.left;
1630 rt.top = g_fullscreen.orgPos.top-rt.top;
1631 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1632 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1634 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1636 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1637 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1638 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1640 if (g_fullscreen.wasZoomed)
1641 ShowWindow(hwnd, WS_MAXIMIZE);
1644 return g_fullscreen.mode;
1647 static void fullscreen_move(HWND hwnd)
1650 GetWindowRect(hwnd, &pos);
1652 Frame_CalcFrameClient(hwnd, &rt);
1653 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1654 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1656 rt.left = pos.left-rt.left;
1657 rt.top = pos.top-rt.top;
1658 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1659 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1661 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1667 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1669 BOOL vis = IsWindowVisible(hchild);
1671 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1673 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1675 #ifndef _NO_EXTENSIONS
1676 if (g_fullscreen.mode)
1677 fullscreen_move(hwnd);
1680 resize_frame_client(hwnd);
1683 BOOL activate_drive_window(LPCTSTR path)
1685 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1688 _tsplitpath(path, drv1, 0, 0, 0);
1690 /* search for a already open window for the same drive */
1691 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1692 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1695 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1697 if (!lstrcmpi(drv2, drv1)) {
1698 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1700 if (IsMinimized(child_wnd))
1701 ShowWindow(child_wnd, SW_SHOWNORMAL);
1711 BOOL activate_fs_window(LPCTSTR filesys)
1715 /* search for a already open window of the given file system name */
1716 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1717 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1720 if (!lstrcmpi(child->root.fs, filesys)) {
1721 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1723 if (IsMinimized(child_wnd))
1724 ShowWindow(child_wnd, SW_SHOWNORMAL);
1734 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1738 DestroyWindow(hwnd);
1740 /* clear handle variables */
1741 Globals.hMenuFrame = 0;
1742 Globals.hMenuView = 0;
1743 Globals.hMenuOptions = 0;
1744 Globals.hMainWnd = 0;
1745 Globals.hmdiclient = 0;
1746 Globals.hdrivebar = 0;
1750 /* don't exit desktop when closing file manager window */
1751 if (!Globals.hwndParent)
1756 UINT cmd = LOWORD(wparam);
1757 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1759 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1762 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1763 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1765 LPCTSTR root = Globals.drives;
1768 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1772 if (activate_drive_window(root))
1775 _tsplitpath(root, drv, 0, 0, 0);
1777 if (!SetCurrentDirectory(drv)) {
1778 display_error(hwnd, GetLastError());
1782 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1783 child = alloc_child_window(path, NULL, hwnd);
1785 if (!create_child_window(child))
1787 } else switch(cmd) {
1789 SendMessage(hwnd, WM_CLOSE, 0, 0);
1792 case ID_WINDOW_NEW: {
1793 TCHAR path[MAX_PATH];
1796 GetCurrentDirectory(MAX_PATH, path);
1797 child = alloc_child_window(path, NULL, hwnd);
1799 if (!create_child_window(child))
1803 case ID_WINDOW_CASCADE:
1804 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1807 case ID_WINDOW_TILE_HORZ:
1808 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1811 case ID_WINDOW_TILE_VERT:
1812 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1815 case ID_WINDOW_ARRANGE:
1816 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1819 case ID_SELECT_FONT: {
1822 HDC hdc = GetDC(hwnd);
1823 char dlg_name[255], dlg_info[255];
1824 chFont.lStructSize = sizeof(CHOOSEFONT);
1825 chFont.hwndOwner = hwnd;
1827 chFont.lpLogFont = &lFont;
1828 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
1829 chFont.rgbColors = RGB(0,0,0);
1830 chFont.lCustData = 0;
1831 chFont.lpfnHook = NULL;
1832 chFont.lpTemplateName = NULL;
1833 chFont.hInstance = Globals.hInstance;
1834 chFont.lpszStyle = NULL;
1835 chFont.nFontType = SIMULATED_FONTTYPE;
1836 chFont.nSizeMin = 0;
1837 chFont.nSizeMax = 24;
1838 if(ChooseFont(&chFont)) {
1839 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, MAX_LOAD_STRING);
1840 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_INFO, dlg_info, MAX_LOAD_STRING);
1841 MessageBox(hwnd,dlg_info,dlg_name,MB_OK|MB_ICONINFORMATION);
1842 Globals.hfont = CreateFontIndirect(&lFont);
1843 SelectFont(hdc, Globals.hfont);
1844 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1846 else if(CommDlgExtendedError()) {
1847 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, MAX_LOAD_STRING);
1848 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, MAX_LOAD_STRING);
1849 MessageBox(hwnd,dlg_info,dlg_name,MB_OK);
1851 ReleaseDC(hwnd,hdc);
1855 case ID_VIEW_TOOL_BAR:
1856 toggle_child(hwnd, cmd, Globals.htoolbar);
1859 case ID_VIEW_DRIVE_BAR:
1860 toggle_child(hwnd, cmd, Globals.hdrivebar);
1863 case ID_VIEW_STATUSBAR:
1864 toggle_child(hwnd, cmd, Globals.hstatusbar);
1868 struct ExecuteDialog dlg;
1870 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1872 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1873 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1875 if ((int)hinst <= 32)
1876 display_error(hwnd, GetLastError());
1881 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1884 #ifndef _NO_EXTENSIONS
1885 case ID_VIEW_FULLSCREEN:
1886 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1890 case ID_DRIVE_UNIX_FS: {
1891 TCHAR path[MAX_PATH];
1894 if (activate_fs_window(TEXT("unixfs")))
1897 getcwd(path, MAX_PATH);
1898 child = alloc_child_window(path, NULL, hwnd);
1900 if (!create_child_window(child))
1904 #ifdef _SHELL_FOLDERS
1905 case ID_DRIVE_SHELL_NS: {
1906 TCHAR path[MAX_PATH];
1909 if (activate_fs_window(TEXT("Shell")))
1912 GetCurrentDirectory(MAX_PATH, path);
1913 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1915 if (!create_child_window(child))
1921 /*TODO: There are even more menu items! */
1923 #ifndef _NO_EXTENSIONS
1926 WineLicense(Globals.hMainWnd);
1929 case ID_NO_WARRANTY:
1930 WineWarranty(Globals.hMainWnd);
1935 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1938 case ID_ABOUT: /*ID_ABOUT_WINE: */
1939 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1941 #endif /* _NO_EXTENSIONS */
1944 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1945 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1946 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1947 (cmd<SC_SIZE || cmd>SC_RESTORE))
1948 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1950 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1955 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1956 break; /* do not pass message to DefFrameProc */
1958 #ifndef _NO_EXTENSIONS
1959 case WM_GETMINMAXINFO: {
1960 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1962 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1963 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1966 case FRM_CALC_CLIENT:
1967 frame_get_clientspace(hwnd, (PRECT)lparam);
1969 #endif /* _NO_EXTENSIONS */
1972 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1979 static const LPTSTR g_pos_names[COLUMNS] = {
1980 TEXT(""), /* symbol */
1984 #ifndef _NO_EXTENSIONS
1987 TEXT("Index/Inode"),
1989 #endif /* _NO_EXTENSIONS */
1991 #ifndef _NO_EXTENSIONS
1996 static const int g_pos_align[] = {
1998 HDF_LEFT, /* Name */
1999 HDF_RIGHT, /* Size */
2000 HDF_LEFT, /* CDate */
2001 #ifndef _NO_EXTENSIONS
2002 HDF_LEFT, /* ADate */
2003 HDF_LEFT, /* MDate */
2004 HDF_LEFT, /* Index */
2005 HDF_CENTER, /* Links */
2007 HDF_CENTER, /* Attributes */
2008 #ifndef _NO_EXTENSIONS
2009 HDF_LEFT /* Security */
2013 static void resize_tree(ChildWnd* child, int cx, int cy)
2015 HDWP hdwp = BeginDeferWindowPos(4);
2023 cx = child->split_pos + SPLIT_WIDTH/2;
2025 #ifndef _NO_EXTENSIONS
2033 Header_Layout(child->left.hwndHeader, &hdl);
2035 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2036 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2037 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2038 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2040 #endif /* _NO_EXTENSIONS */
2042 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);
2043 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2045 EndDeferWindowPos(hdwp);
2049 #ifndef _NO_EXTENSIONS
2051 static HWND create_header(HWND parent, Pane* pane, int id)
2056 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2057 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2061 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2063 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2065 for(idx=0; idx<COLUMNS; idx++) {
2066 hdi.pszText = g_pos_names[idx];
2067 hdi.fmt = HDF_STRING | g_pos_align[idx];
2068 hdi.cxy = pane->widths[idx];
2069 Header_InsertItem(hwnd, idx, &hdi);
2075 #endif /* _NO_EXTENSIONS */
2078 static void init_output(HWND hwnd)
2082 HDC hdc = GetDC(hwnd);
2084 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
2085 Globals.num_sep = b[1];
2087 Globals.num_sep = TEXT('.');
2089 old_font = SelectFont(hdc, Globals.hfont);
2090 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
2091 SelectFont(hdc, old_font);
2092 ReleaseDC(hwnd, hdc);
2095 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2098 /* calculate prefered width for all visible columns */
2100 static BOOL calc_widths(Pane* pane, BOOL anyway)
2102 int col, x, cx, spc=3*Globals.spaceSize.cx;
2103 int entries = ListBox_GetCount(pane->hwnd);
2104 int orgWidths[COLUMNS];
2105 int orgPositions[COLUMNS+1];
2111 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2112 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2115 for(col=0; col<COLUMNS; col++)
2116 pane->widths[col] = 0;
2118 hdc = GetDC(pane->hwnd);
2119 hfontOld = SelectFont(hdc, Globals.hfont);
2121 for(cnt=0; cnt<entries; cnt++) {
2122 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2131 dis.hwndItem = pane->hwnd;
2133 dis.rcItem.left = 0;
2135 dis.rcItem.right = 0;
2136 dis.rcItem.bottom = 0;
2137 /*dis.itemData = 0; */
2139 draw_item(pane, &dis, entry, COLUMNS);
2142 SelectObject(hdc, hfontOld);
2143 ReleaseDC(pane->hwnd, hdc);
2146 for(col=0; col<COLUMNS; col++) {
2147 pane->positions[col] = x;
2148 cx = pane->widths[col];
2153 if (cx < IMAGE_WIDTH)
2156 pane->widths[col] = cx;
2162 pane->positions[COLUMNS] = x;
2164 ListBox_SetHorizontalExtent(pane->hwnd, x);
2167 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2170 /* don't move, if only collapsing an entry */
2171 if (!anyway && pane->widths[0]<orgWidths[0] &&
2172 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2173 pane->widths[0] = orgWidths[0];
2174 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2179 InvalidateRect(pane->hwnd, 0, TRUE);
2185 /* calculate one prefered column width */
2187 static void calc_single_width(Pane* pane, int col)
2191 int entries = ListBox_GetCount(pane->hwnd);
2195 pane->widths[col] = 0;
2197 hdc = GetDC(pane->hwnd);
2198 hfontOld = SelectFont(hdc, Globals.hfont);
2200 for(cnt=0; cnt<entries; cnt++) {
2201 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2209 dis.hwndItem = pane->hwnd;
2211 dis.rcItem.left = 0;
2213 dis.rcItem.right = 0;
2214 dis.rcItem.bottom = 0;
2215 /*dis.itemData = 0; */
2217 draw_item(pane, &dis, entry, col);
2220 SelectObject(hdc, hfontOld);
2221 ReleaseDC(pane->hwnd, hdc);
2223 cx = pane->widths[col];
2226 cx += 3*Globals.spaceSize.cx;
2228 if (cx < IMAGE_WIDTH)
2232 pane->widths[col] = cx;
2234 x = pane->positions[col] + cx;
2236 for(; col<COLUMNS; ) {
2237 pane->positions[++col] = x;
2238 x += pane->widths[col];
2241 ListBox_SetHorizontalExtent(pane->hwnd, x);
2245 /* insert listbox entries after index idx */
2247 static void insert_entries(Pane* pane, Entry* dir, int idx)
2254 ShowWindow(pane->hwnd, SW_HIDE);
2256 for(; entry; entry=entry->next) {
2258 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2262 /* don't display entries "." and ".." in the left pane */
2263 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2264 && entry->data.cFileName[0]==TEXT('.'))
2266 #ifndef _NO_EXTENSIONS
2267 entry->data.cFileName[1]==TEXT('\0') ||
2269 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2275 ListBox_InsertItemData(pane->hwnd, idx, entry);
2277 if (pane->treePane && entry->expanded)
2278 insert_entries(pane, entry->down, idx);
2281 ShowWindow(pane->hwnd, SW_SHOW);
2285 static WNDPROC g_orgTreeWndProc;
2287 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2289 static int s_init = 0;
2290 Entry* entry = pane->root;
2292 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2293 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2294 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2296 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2297 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2299 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2301 /* insert entries into listbox */
2303 insert_entries(pane, entry, -1);
2305 /* calculate column widths */
2308 init_output(pane->hwnd);
2311 calc_widths(pane, TRUE);
2313 #ifndef _NO_EXTENSIONS
2314 pane->hwndHeader = create_header(parent, pane, id_header);
2319 static void InitChildWindow(ChildWnd* child)
2321 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2322 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2326 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2332 *buffer = TEXT('\0');
2334 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2337 if (!FileTimeToLocalFileTime(ft, &lft))
2338 {err: _tcscpy(buffer,TEXT("???")); return;}
2340 if (!FileTimeToSystemTime(&lft, &systime))
2343 if (visible_cols & COL_DATE) {
2344 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2349 if (visible_cols & COL_TIME) {
2351 buffer[len-1] = ' ';
2353 buffer[len++] = ' ';
2355 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2356 buffer[len] = TEXT('\0');
2361 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2363 RECT rt = {0, 0, 0, 0};
2365 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2367 if (rt.right > pane->widths[col])
2368 pane->widths[col] = rt.right;
2371 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2373 RECT rt = {0, 0, 0, 0};
2375 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2376 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2378 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2379 /*FIXME rt (0,0) ??? */
2381 if (rt.right > pane->widths[col])
2382 pane->widths[col] = rt.right;
2386 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2388 int x = dis->rcItem.left;
2391 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2392 rt.top = dis->rcItem.top;
2393 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2394 rt.bottom = dis->rcItem.bottom;
2396 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2399 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2401 int x = dis->rcItem.left;
2404 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2405 rt.top = dis->rcItem.top;
2406 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2407 rt.bottom = dis->rcItem.bottom;
2409 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2410 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2412 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2415 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2417 int x = dis->rcItem.left;
2424 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2425 rt.top = dis->rcItem.top;
2426 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2427 rt.bottom = dis->rcItem.bottom;
2432 /* insert number separator characters */
2433 pos = lstrlen(s) % 3;
2439 *d++ = Globals.num_sep;
2443 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2447 static int is_exe_file(LPCTSTR ext)
2449 static const LPCTSTR executable_extensions[] = {
2454 #ifndef _NO_EXTENSIONS
2458 #endif /* _NO_EXTENSIONS */
2462 TCHAR ext_buffer[_MAX_EXT];
2467 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2470 for(p=executable_extensions; *p; p++)
2471 if (!_tcscmp(ext_buffer, *p))
2477 static int is_registered_type(LPCTSTR ext)
2485 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2487 TCHAR buffer[BUFFER_LEN];
2489 int visible_cols = pane->visible_cols;
2490 COLORREF bkcolor, textcolor;
2491 RECT focusRect = dis->rcItem;
2498 attrs = entry->data.dwFileAttributes;
2500 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2501 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2502 && entry->data.cFileName[2]==TEXT('\0'))
2503 img = IMG_FOLDER_UP;
2504 #ifndef _NO_EXTENSIONS
2505 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2506 img = IMG_FOLDER_CUR;
2509 #ifdef _NO_EXTENSIONS
2512 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2513 img = IMG_OPEN_FOLDER;
2517 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2521 if (is_exe_file(ext))
2522 img = IMG_EXECUTABLE;
2523 else if (is_registered_type(ext))
2533 if (pane->treePane) {
2535 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
2537 if (calcWidthCol == -1) {
2539 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2542 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2545 rt_clip.left = dis->rcItem.left;
2546 rt_clip.top = dis->rcItem.top;
2547 rt_clip.right = dis->rcItem.left+pane->widths[col];
2548 rt_clip.bottom = dis->rcItem.bottom;
2550 hrgn = CreateRectRgnIndirect(&rt_clip);
2552 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2553 DeleteObject(hrgn_org);
2557 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2558 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2561 if ((up=entry->up) != NULL) {
2562 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2563 LineTo(dis->hDC, img_pos-2, y);
2565 x = img_pos - IMAGE_WIDTH/2;
2568 x -= IMAGE_WIDTH+TREE_LINE_DX;
2572 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2575 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2576 LineTo(dis->hDC, x, dis->rcItem.bottom);
2578 } while((up=up->up) != NULL);
2581 x = img_pos - IMAGE_WIDTH/2;
2583 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2584 LineTo(dis->hDC, x, y);
2588 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2591 LineTo(dis->hDC, x, dis->rcItem.bottom);
2593 if (entry->down && entry->expanded) {
2594 x += IMAGE_WIDTH+TREE_LINE_DX;
2595 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT+2, 0);
2596 LineTo(dis->hDC, x, dis->rcItem.bottom);
2599 SelectClipRgn(dis->hDC, hrgn_org);
2600 if (hrgn_org) DeleteObject(hrgn_org);
2601 /* SelectObject(dis->hDC, holdPen); */
2602 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2603 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
2605 if (right > pane->widths[col])
2606 pane->widths[col] = right;
2609 img_pos = dis->rcItem.left;
2612 img_pos = dis->rcItem.left;
2614 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2615 pane->widths[col] = IMAGE_WIDTH;
2618 if (calcWidthCol == -1) {
2619 focusRect.left = img_pos -2;
2621 #ifdef _NO_EXTENSIONS
2622 if (pane->treePane && entry) {
2625 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2627 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
2631 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2632 textcolor = COLOR_COMPRESSED;
2634 #endif /* _NO_EXTENSIONS */
2635 textcolor = RGB(0,0,0);
2637 if (dis->itemState & ODS_FOCUS) {
2638 textcolor = RGB(255,255,255);
2639 bkcolor = COLOR_SELECTION;
2641 bkcolor = RGB(255,255,255);
2644 hbrush = CreateSolidBrush(bkcolor);
2645 FillRect(dis->hDC, &focusRect, hbrush);
2646 if (entry->down && entry->expanded) {
2647 MoveToEx(dis->hDC, img_pos + IMAGE_WIDTH/2 + TREE_LINE_DX, dis->rcItem.top+IMAGE_HEIGHT+2, 0);
2648 LineTo(dis->hDC, img_pos + IMAGE_WIDTH/2 + TREE_LINE_DX, dis->rcItem.bottom);
2650 DeleteObject(hbrush);
2652 SetBkMode(dis->hDC, TRANSPARENT);
2653 SetTextColor(dis->hDC, textcolor);
2655 cx = pane->widths[col];
2657 if (cx && img!=IMG_NONE) {
2659 if (cx > IMAGE_WIDTH)
2662 #ifdef _SHELL_FOLDERS
2663 if (entry->hicon && entry->hicon!=(HICON)-1)
2664 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2667 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2668 img_pos, dis->rcItem.top, cx,
2669 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2676 #ifdef _NO_EXTENSIONS
2677 if (img >= IMG_FOLDER_UP)
2683 /* ouput file name */
2684 if (calcWidthCol == -1)
2685 output_text(pane, dis, col, entry->data.cFileName, 0);
2686 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2687 calc_width(pane, dis, col, entry->data.cFileName);
2691 #ifdef _NO_EXTENSIONS
2692 if (!pane->treePane) {
2695 /* display file size */
2696 if (visible_cols & COL_SIZE) {
2697 #ifdef _NO_EXTENSIONS
2698 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2703 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2705 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2707 if (calcWidthCol == -1)
2708 output_number(pane, dis, col, buffer);
2709 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2710 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2716 /* display file date */
2717 if (visible_cols & (COL_DATE|COL_TIME)) {
2718 #ifndef _NO_EXTENSIONS
2719 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2720 if (calcWidthCol == -1)
2721 output_text(pane, dis, col, buffer, 0);
2722 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2723 calc_width(pane, dis, col, buffer);
2726 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2727 if (calcWidthCol == -1)
2728 output_text(pane, dis, col, buffer, 0);
2729 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2730 calc_width(pane, dis, col, buffer);
2732 #endif /* _NO_EXTENSIONS */
2734 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2735 if (calcWidthCol == -1)
2736 output_text(pane, dis, col, buffer, 0);
2737 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2738 calc_width(pane, dis, col, buffer);
2742 #ifndef _NO_EXTENSIONS
2743 if (entry->bhfi_valid) {
2744 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2746 if (visible_cols & COL_INDEX) {
2747 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2748 if (calcWidthCol == -1)
2749 output_text(pane, dis, col, buffer, DT_RIGHT);
2750 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2751 calc_width(pane, dis, col, buffer);
2755 if (visible_cols & COL_LINKS) {
2756 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2757 if (calcWidthCol == -1)
2758 output_text(pane, dis, col, buffer, DT_CENTER);
2759 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2760 calc_width(pane, dis, col, buffer);
2765 #endif /* _NO_EXTENSIONS */
2767 /* show file attributes */
2768 if (visible_cols & COL_ATTRIBUTES) {
2769 #ifdef _NO_EXTENSIONS
2770 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2772 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2775 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2777 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2778 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2779 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2780 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2781 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2782 #ifndef _NO_EXTENSIONS
2783 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2784 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2785 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2786 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2787 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2788 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2789 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2790 #endif /* _NO_EXTENSIONS */
2793 if (calcWidthCol == -1)
2794 output_tabbed_text(pane, dis, col, buffer);
2795 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2796 calc_tabbed_width(pane, dis, col, buffer);
2802 if (flags.security) {
2803 DWORD rights = get_access_mask();
2805 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2807 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2808 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2809 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2810 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2811 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2812 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2813 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2814 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2815 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2816 if (rights & WRITE_DAC) buffer[22] = 'C';
2817 if (rights & WRITE_OWNER) buffer[24] = 'O';
2818 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2820 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2823 if (flags.description) {
2824 get_description(buffer);
2825 output_text(dis, col++, buffer, 0, psize);
2829 #ifdef _NO_EXTENSIONS
2832 /* draw focus frame */
2833 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2834 /* Currently [04/2000] Wine neither behaves exactly the same */
2835 /* way as WIN 95 nor like Windows NT... */
2840 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2841 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2842 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2844 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2846 lastPen = SelectPen(dis->hDC, hpen);
2847 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2848 SetROP2(dis->hDC, R2_XORPEN);
2849 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2850 SelectObject(dis->hDC, lastBrush);
2851 SelectObject(dis->hDC, lastPen);
2854 #endif /* _NO_EXTENSIONS */
2858 #ifdef _NO_EXTENSIONS
2860 static void draw_splitbar(HWND hwnd, int x)
2863 HDC hdc = GetDC(hwnd);
2865 GetClientRect(hwnd, &rt);
2867 rt.left = x - SPLIT_WIDTH/2;
2868 rt.right = x + SPLIT_WIDTH/2+1;
2870 InvertRect(hdc, &rt);
2872 ReleaseDC(hwnd, hdc);
2875 #endif /* _NO_EXTENSIONS */
2878 #ifndef _NO_EXTENSIONS
2880 static void set_header(Pane* pane)
2883 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2886 item.mask = HDI_WIDTH;
2889 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2890 x += pane->widths[i];
2891 Header_SetItem(pane->hwndHeader, i, &item);
2895 x += pane->widths[i];
2896 item.cxy = x - scroll_pos;
2897 Header_SetItem(pane->hwndHeader, i++, &item);
2899 for(; i<COLUMNS; i++) {
2900 item.cxy = pane->widths[i];
2901 x += pane->widths[i];
2902 Header_SetItem(pane->hwndHeader, i, &item);
2907 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2909 switch(pnmh->code) {
2911 case HDN_ENDTRACK: {
2912 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2913 int idx = phdn->iItem;
2914 int dx = phdn->pitem->cxy - pane->widths[idx];
2918 GetClientRect(pane->hwnd, &clnt);
2920 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2921 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2923 pane->widths[idx] += dx;
2925 for(i=idx; ++i<=COLUMNS; )
2926 pane->positions[i] += dx;
2929 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2933 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2935 rt_scr.right = clnt.right;
2936 rt_scr.bottom = clnt.bottom;
2938 rt_clip.left = pane->positions[idx]-scroll_pos;
2940 rt_clip.right = clnt.right;
2941 rt_clip.bottom = clnt.bottom;
2943 if (rt_scr.left < 0) rt_scr.left = 0;
2944 if (rt_clip.left < 0) rt_clip.left = 0;
2946 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2948 rt_clip.right = pane->positions[idx+1];
2949 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2951 if (pnmh->code == HDN_ENDTRACK) {
2952 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2954 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2962 case HDN_DIVIDERDBLCLICK: {
2963 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2966 calc_single_width(pane, phdn->iItem);
2967 item.mask = HDI_WIDTH;
2968 item.cxy = pane->widths[phdn->iItem];
2970 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2971 InvalidateRect(pane->hwnd, 0, TRUE);
2978 #endif /* _NO_EXTENSIONS */
2981 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2983 TCHAR path[MAX_PATH];
2984 int idx = ListBox_GetCurSel(child->left.hwnd);
2985 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2987 /* delete sub entries in left pane */
2989 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2990 Entry* sub = (Entry*) res;
2992 if (res==LB_ERR || !sub || sub->level<=entry->level)
2995 ListBox_DeleteString(child->left.hwnd, idx+1);
2998 /* empty right pane */
2999 ListBox_ResetContent(child->right.hwnd);
3001 /* release memory */
3002 free_entries(entry);
3004 /* read contents from disk */
3005 #ifdef _SHELL_FOLDERS
3006 if (entry->etype == ET_SHELL)
3008 read_directory(entry, NULL, child->sortOrder, hwnd);
3013 get_path(entry, path);
3014 read_directory(entry, path, child->sortOrder, hwnd);
3017 /* insert found entries in right pane */
3018 insert_entries(&child->right, entry->down, -1);
3019 calc_widths(&child->right, FALSE);
3020 #ifndef _NO_EXTENSIONS
3021 set_header(&child->right);
3024 child->header_wdths_ok = FALSE;
3026 SetCursor(old_cursor);
3030 /* expand a directory entry */
3032 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3037 if (!dir || dir->expanded || !dir->down)
3042 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3045 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3046 p->data.cFileName[2]=='\0' && p->next)
3050 /* no subdirectories ? */
3051 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3054 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3056 dir->expanded = TRUE;
3058 /* insert entries in left pane */
3059 insert_entries(&child->left, p, idx);
3061 if (!child->header_wdths_ok) {
3062 if (calc_widths(&child->left, FALSE)) {
3063 #ifndef _NO_EXTENSIONS
3064 set_header(&child->left);
3067 child->header_wdths_ok = TRUE;
3075 static void collapse_entry(Pane* pane, Entry* dir)
3077 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3079 ShowWindow(pane->hwnd, SW_HIDE);
3081 /* hide sub entries */
3083 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3084 Entry* sub = (Entry*) res;
3086 if (res==LB_ERR || !sub || sub->level<=dir->level)
3089 ListBox_DeleteString(pane->hwnd, idx+1);
3092 dir->expanded = FALSE;
3094 ShowWindow(pane->hwnd, SW_SHOW);
3098 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
3100 TCHAR path[MAX_PATH];
3104 child->left.cur = entry;
3105 child->right.root = entry->down? entry->down: entry;
3106 child->right.cur = entry;
3108 if (!entry->scanned)
3109 scan_entry(child, entry, hwnd);
3111 ListBox_ResetContent(child->right.hwnd);
3112 insert_entries(&child->right, entry->down, -1);
3113 calc_widths(&child->right, FALSE);
3114 #ifndef _NO_EXTENSIONS
3115 set_header(&child->right);
3119 get_path(entry, path);
3120 lstrcpy(child->path, path);
3122 if (child->hwnd) /* only change window title, if the window already exists */
3123 SetWindowText(child->hwnd, path);
3126 SetCurrentDirectory(path);
3130 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3132 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3134 if ((int)hinst <= 32) {
3135 display_error(hwnd, GetLastError());
3143 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3145 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3147 if ((int)hinst <= 32) {
3148 display_error(hwnd, GetLastError());
3157 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3159 TCHAR cmd[MAX_PATH];
3161 #ifdef _SHELL_FOLDERS
3162 if (entry->etype == ET_SHELL) {
3165 SHELLEXECUTEINFO shexinfo;
3167 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3168 shexinfo.fMask = SEE_MASK_IDLIST;
3169 shexinfo.hwnd = hwnd;
3170 shexinfo.lpVerb = NULL;
3171 shexinfo.lpFile = NULL;
3172 shexinfo.lpParameters = NULL;
3173 shexinfo.lpDirectory = NULL;
3174 shexinfo.nShow = nCmdShow;
3175 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3177 if (!ShellExecuteEx(&shexinfo)) {
3178 display_error(hwnd, GetLastError());
3182 if (shexinfo.lpIDList != entry->pidl)
3183 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3189 get_path(entry, cmd);
3191 /* start program, open document... */
3192 return launch_file(hwnd, cmd, nCmdShow);
3196 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3198 Entry* entry = pane->cur;
3203 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3204 int scanned_old = entry->scanned;
3207 scan_entry(child, entry, hwnd);
3209 #ifndef _NO_EXTENSIONS
3210 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3214 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3215 entry = child->left.cur->up;
3216 collapse_entry(&child->left, entry);
3218 } else if (entry->expanded)
3219 collapse_entry(pane, child->left.cur);
3221 expand_entry(child, child->left.cur);
3223 if (!pane->treePane) focus_entry: {
3224 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3225 ListBox_SetCurSel(child->left.hwnd, idx);
3226 set_curdir(child, entry, hwnd);
3231 calc_widths(pane, FALSE);
3233 #ifndef _NO_EXTENSIONS
3238 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3243 static BOOL pane_command(Pane* pane, UINT cmd)
3247 if (pane->visible_cols) {
3248 pane->visible_cols = 0;
3249 calc_widths(pane, TRUE);
3250 #ifndef _NO_EXTENSIONS
3253 InvalidateRect(pane->hwnd, 0, TRUE);
3254 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3255 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3256 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3260 case ID_VIEW_ALL_ATTRIBUTES:
3261 if (pane->visible_cols != COL_ALL) {
3262 pane->visible_cols = COL_ALL;
3263 calc_widths(pane, TRUE);
3264 #ifndef _NO_EXTENSIONS
3267 InvalidateRect(pane->hwnd, 0, TRUE);
3268 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3269 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3270 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3274 #ifndef _NO_EXTENSIONS
3275 case ID_PREFERED_SIZES: {
3276 calc_widths(pane, TRUE);
3278 InvalidateRect(pane->hwnd, 0, TRUE);
3282 /* TODO: more command ids... */
3292 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3296 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3297 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3299 if (SUCCEEDED(hr)) {
3300 HMENU hmenu = CreatePopupMenu();
3303 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3305 if (SUCCEEDED(hr)) {
3306 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3309 CMINVOKECOMMANDINFO cmi;
3311 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3313 cmi.hwnd = hwndParent;
3314 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3315 cmi.lpParameters = NULL;
3316 cmi.lpDirectory = NULL;
3317 cmi.nShow = SW_SHOWNORMAL;
3321 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3326 (*pcm->lpVtbl->Release)(pcm);
3333 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3335 static int last_split;
3337 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3342 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3343 Entry* entry = (Entry*) dis->itemData;
3345 /*dis->rcItem.top*=2;
3346 dis->rcItem.bottom*=2;*/
3347 if (dis->CtlID == IDW_TREE_LEFT)
3348 draw_item(&child->left, dis, entry, -1);
3350 draw_item(&child->right, dis, entry, -1);
3355 InitChildWindow(child);
3359 free_child_window(child);
3360 SetWindowLong(hwnd, GWL_USERDATA, 0);
3367 GetClientRect(hwnd, &rt);
3368 BeginPaint(hwnd, &ps);
3369 rt.left = child->split_pos-SPLIT_WIDTH/2;
3370 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3371 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3372 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3373 SelectObject(ps.hdc, lastBrush);
3374 #ifdef _NO_EXTENSIONS
3375 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3376 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3378 EndPaint(hwnd, &ps);
3382 if (LOWORD(lparam) == HTCLIENT) {
3385 ScreenToClient(hwnd, &pt);
3387 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3388 SetCursor(LoadCursor(0, IDC_SIZEWE));
3394 case WM_LBUTTONDOWN: {
3396 int x = LOWORD(lparam);
3398 GetClientRect(hwnd, &rt);
3400 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3401 last_split = child->split_pos;
3402 #ifdef _NO_EXTENSIONS
3403 draw_splitbar(hwnd, last_split);
3411 if (GetCapture() == hwnd) {
3412 #ifdef _NO_EXTENSIONS
3414 int x = LOWORD(lparam);
3415 draw_splitbar(hwnd, last_split);
3417 GetClientRect(hwnd, &rt);
3418 child->split_pos = x;
3419 resize_tree(child, rt.right, rt.bottom);
3425 #ifdef _NO_EXTENSIONS
3426 case WM_CAPTURECHANGED:
3427 if (GetCapture()==hwnd && last_split>=0)
3428 draw_splitbar(hwnd, last_split);
3433 if (wparam == VK_ESCAPE)
3434 if (GetCapture() == hwnd) {
3436 #ifdef _NO_EXTENSIONS
3437 draw_splitbar(hwnd, last_split);
3439 child->split_pos = last_split;
3441 GetClientRect(hwnd, &rt);
3442 resize_tree(child, rt.right, rt.bottom);
3445 SetCursor(LoadCursor(0, IDC_ARROW));
3450 if (GetCapture() == hwnd) {
3452 int x = LOWORD(lparam);
3454 #ifdef _NO_EXTENSIONS
3455 HDC hdc = GetDC(hwnd);
3456 GetClientRect(hwnd, &rt);
3458 rt.left = last_split-SPLIT_WIDTH/2;
3459 rt.right = last_split+SPLIT_WIDTH/2+1;
3460 InvertRect(hdc, &rt);
3463 rt.left = x-SPLIT_WIDTH/2;
3464 rt.right = x+SPLIT_WIDTH/2+1;
3465 InvertRect(hdc, &rt);
3467 ReleaseDC(hwnd, hdc);
3469 GetClientRect(hwnd, &rt);
3471 if (x>=0 && x<rt.right) {
3472 child->split_pos = x;
3473 resize_tree(child, rt.right, rt.bottom);
3474 rt.left = x-SPLIT_WIDTH/2;
3475 rt.right = x+SPLIT_WIDTH/2+1;
3476 InvalidateRect(hwnd, &rt, FALSE);
3477 UpdateWindow(child->left.hwnd);
3479 UpdateWindow(child->right.hwnd);
3485 #ifndef _NO_EXTENSIONS
3486 case WM_GETMINMAXINFO:
3487 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3489 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3491 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3492 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3494 #endif /* _NO_EXTENSIONS */
3497 SetCurrentDirectory(child->path);
3498 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3501 case WM_DISPATCH_COMMAND: {
3502 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3504 switch(LOWORD(wparam)) {
3505 case ID_WINDOW_NEW: {
3506 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3508 if (!create_child_window(new_child))
3514 scan_entry(child, pane->cur, hwnd);
3518 activate_entry(child, pane, hwnd);
3521 case ID_FILE_MOVE: {
3522 char *new_name,*old_name;
3524 if((int)(new_name=(char *)DialogBox(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, sDestinationWndProc))==1|| (int)new_name==IDCANCEL) break;
3525 old_name = malloc(MAX_PATH);
3526 if(new_name[1]!=':' && new_name[0]!='/') {
3527 get_path(pane->cur->up, old_name);
3528 len = strlen(old_name);
3529 if(old_name[len-1]!='\\') {
3534 strcpy(&old_name[len], new_name);
3535 strcpy(new_name, old_name);
3537 get_path(pane->cur, old_name);
3538 if(MoveFileEx(old_name,new_name,MOVEFILE_COPY_ALLOWED)) {
3539 if(pane->treePane) {
3540 pane->root->scanned=FALSE;
3541 pane->cur=pane->root;
3542 activate_entry(child, pane, hwnd);
3544 else scan_entry(child, pane->root, hwnd);
3547 LoadString(Globals.hInstance, IDS_FILE_MOVE_ERROR, old_name, MAX_PATH);
3548 MessageBox(hwnd, old_name, "WineFile", MB_OK);
3555 return pane_command(pane, LOWORD(wparam));
3561 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3563 switch(HIWORD(wparam)) {
3564 case LBN_SELCHANGE: {
3565 int idx = ListBox_GetCurSel(pane->hwnd);
3566 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3568 if (pane == &child->left)
3569 set_curdir(child, entry, hwnd);
3575 activate_entry(child, pane, hwnd);
3580 #ifndef _NO_EXTENSIONS
3582 NMHDR* pnmh = (NMHDR*) lparam;
3583 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3586 #ifdef _SHELL_FOLDERS
3587 case WM_CONTEXTMENU: {
3591 /* first select the current item in the listbox */
3592 HWND hpanel = (HWND) wparam;
3593 POINTS* ppos = &MAKEPOINTS(lparam);
3594 POINT pt; POINTSTOPOINT(pt, *ppos);
3595 ScreenToClient(hpanel, &pt);
3596 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y));
3597 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
3599 /* now create the popup menu using shell namespace and IContextMenu */
3600 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3601 idx = ListBox_GetCurSel(pane->hwnd);
3605 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3607 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3610 IShellFolder* parentFolder;
3611 LPCITEMIDLIST pidlLast;
3613 /* get and use the parent folder to display correct context menu in all cases */
3614 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3615 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, ppos->x, ppos->y);
3617 (*parentFolder->lpVtbl->Release)(parentFolder);
3620 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
3627 if (wparam != SIZE_MINIMIZED)
3628 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3632 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3639 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3641 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3642 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3646 #ifndef _NO_EXTENSIONS
3653 child->focus_pane = pane==&child->right? 1: 0;
3654 ListBox_SetSel(hwnd, TRUE, 1);
3655 /*TODO: check menu items */
3659 if (wparam == VK_TAB) {
3660 /*TODO: SetFocus(Globals.hdrivebar) */
3661 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3665 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3669 static void InitInstance(HINSTANCE hinstance)
3675 INITCOMMONCONTROLSEX icc = {
3676 sizeof(INITCOMMONCONTROLSEX),
3682 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3684 InitCommonControlsEx(&icc);
3687 /* register frame window class */
3689 wcFrame.cbSize = sizeof(WNDCLASSEX);
3691 wcFrame.lpfnWndProc = FrameWndProc;
3692 wcFrame.cbClsExtra = 0;
3693 wcFrame.cbWndExtra = 0;
3694 wcFrame.hInstance = hinstance;
3695 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3696 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3697 wcFrame.hbrBackground = 0;
3698 wcFrame.lpszMenuName = 0;
3699 wcFrame.lpszClassName = WINEFILEFRAME;
3700 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3701 MAKEINTRESOURCE(IDI_WINEFILE),
3703 GetSystemMetrics(SM_CXSMICON),
3704 GetSystemMetrics(SM_CYSMICON),
3707 Globals.hframeClass = RegisterClassEx(&wcFrame);
3710 /* register tree windows class */
3712 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3713 wcChild.lpfnWndProc = ChildWndProc;
3714 wcChild.cbClsExtra = 0;
3715 wcChild.cbWndExtra = 0;
3716 wcChild.hInstance = hinstance;
3718 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3719 wcChild.hbrBackground = 0;
3720 wcChild.lpszMenuName = 0;
3721 wcChild.lpszClassName = WINEFILETREE;
3723 hChildClass = RegisterClass(&wcChild);
3726 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3728 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Shell Dlg"));
3732 Globals.hInstance = hinstance;
3734 #ifdef _SHELL_FOLDERS
3736 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3737 SHGetDesktopFolder(&Globals.iDesktop);
3738 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3743 void show_frame(HWND hwndParent, int cmdshow)
3745 TCHAR path[MAX_PATH];
3747 HMENU hMenuFrame, hMenuWindow;
3749 CLIENTCREATESTRUCT ccs;
3751 if (Globals.hMainWnd)
3754 Globals.hwndParent = hwndParent;
3756 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3757 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3759 Globals.hMenuFrame = hMenuFrame;
3760 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3761 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3763 ccs.hWindowMenu = hMenuWindow;
3764 ccs.idFirstChild = IDW_FIRST_CHILD;
3767 /* create main window */
3768 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3769 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3770 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3773 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3774 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3776 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3780 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3784 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3785 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3786 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3787 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3789 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3791 drivebarBtn.fsStyle = BTNS_BUTTON;
3793 #ifndef _NO_EXTENSIONS
3795 /* insert unix file system button */
3796 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3798 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3799 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3800 drivebarBtn.iString++;
3802 #ifdef _SHELL_FOLDERS
3803 /* insert shell namespace button */
3804 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3806 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3807 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3808 drivebarBtn.iString++;
3811 /* register windows drive root strings */
3812 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3815 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3817 for(p=Globals.drives; *p; ) {
3818 #ifdef _NO_EXTENSIONS
3819 /* insert drive letter */
3820 TCHAR b[3] = {tolower(*p)};
3821 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3823 switch(GetDriveType(p)) {
3824 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3825 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3826 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3827 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3828 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3831 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3832 drivebarBtn.idCommand++;
3833 drivebarBtn.iString++;
3840 TBBUTTON toolbarBtns[] = {
3841 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3842 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3843 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3844 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3845 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3847 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3848 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3851 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3852 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3853 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3854 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3857 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3858 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3860 /* CreateStatusWindow does not accept WS_BORDER
3861 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3862 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3863 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3865 /*TODO: read paths and window placements from registry */
3866 GetCurrentDirectory(MAX_PATH, path);
3868 ShowWindow(Globals.hMainWnd, cmdshow);
3870 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3871 /* Shell Namespace as default: */
3872 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3874 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3877 child->pos.showCmd = SW_SHOWMAXIMIZED;
3878 child->pos.rcNormalPosition.left = 0;
3879 child->pos.rcNormalPosition.top = 0;
3880 child->pos.rcNormalPosition.right = 320;
3881 child->pos.rcNormalPosition.bottom = 280;
3883 if (!create_child_window(child))
3886 SetWindowPlacement(child->hwnd, &child->pos);
3888 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3890 Globals.prescan_node = FALSE;
3892 UpdateWindow(Globals.hMainWnd);
3897 #ifdef _SHELL_FOLDERS
3898 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3899 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3903 ImageList_Destroy(Globals.himl);
3907 /* search for already running win[e]files */
3909 static int g_foundPrevInstance = 0;
3911 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3915 GetClassName(hwnd, cls, 128);
3917 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3918 g_foundPrevInstance++;
3925 /* search for window of given class name to allow only one running instance */
3926 int find_window_class(LPCTSTR classname)
3928 EnumWindows(EnumWndProc, (LPARAM)classname);
3930 if (g_foundPrevInstance)
3937 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3941 InitInstance(hinstance);
3943 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3944 if (cmdshow == SW_SHOWNORMAL)
3945 /*TODO: read window placement from registry */
3946 cmdshow = SW_MAXIMIZE;
3949 show_frame(hwndParent, cmdshow);
3951 while(GetMessage(&msg, 0, 0, 0)) {
3952 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3955 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3958 TranslateMessage(&msg);
3959 DispatchMessage(&msg);
3970 int APIENTRY WinMain(HINSTANCE hinstance,
3971 HINSTANCE previnstance,
3975 #ifdef _NO_EXTENSIONS
3976 if (find_window_class(WINEFILEFRAME))
3980 winefile_main(hinstance, 0, cmdshow);