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);
194 /* allocate and initialise a directory entry */
195 static Entry* alloc_entry()
197 Entry* entry = (Entry*) malloc(sizeof(Entry));
199 #ifdef _SHELL_FOLDERS
201 entry->folder = NULL;
208 /* free a directory entry */
209 static void free_entry(Entry* entry)
211 #ifdef _SHELL_FOLDERS
212 if (entry->hicon && entry->hicon!=(HICON)-1)
213 DestroyIcon(entry->hicon);
215 if (entry->folder && entry->folder!=Globals.iDesktop)
216 (*entry->folder->lpVtbl->Release)(entry->folder);
219 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
225 /* recursively free all child entries */
226 static void free_entries(Entry* dir)
228 Entry *entry, *next=dir->down;
244 static void read_directory_win(Entry* dir, LPCTSTR path)
246 Entry* first_entry = NULL;
250 int level = dir->level + 1;
251 WIN32_FIND_DATA w32fd;
253 #ifndef _NO_EXTENSIONS
257 TCHAR buffer[MAX_PATH], *p;
258 for(p=buffer; *path; )
261 lstrcpy(p, TEXT("\\*"));
263 hFind = FindFirstFile(buffer, &w32fd);
265 if (hFind != INVALID_HANDLE_VALUE) {
267 entry = alloc_entry();
275 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
278 entry->expanded = FALSE;
279 entry->scanned = FALSE;
280 entry->level = level;
282 #ifdef _NO_EXTENSIONS
283 /* hide directory entry "." */
284 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
285 LPCTSTR name = entry->data.cFileName;
287 if (name[0]=='.' && name[1]=='\0')
291 entry->etype = ET_WINDOWS;
292 entry->bhfi_valid = FALSE;
294 lstrcpy(p+1, entry->data.cFileName);
296 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
297 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
299 if (hFile != INVALID_HANDLE_VALUE) {
300 if (GetFileInformationByHandle(hFile, &entry->bhfi))
301 entry->bhfi_valid = TRUE;
308 } while(FindNextFile(hFind, &entry->data));
315 dir->down = first_entry;
320 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
324 for(entry=dir->down; entry; entry=entry->next) {
326 LPCTSTR q = entry->data.cFileName;
329 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
331 } while(tolower(*p++) == tolower(*q++));
334 q = entry->data.cAlternateFileName;
337 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
339 } while(tolower(*p++) == tolower(*q++));
346 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
348 TCHAR buffer[MAX_PATH];
349 Entry* entry = &root->entry;
353 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
355 #ifndef _NO_EXTENSIONS
356 entry->etype = ET_WINDOWS;
360 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
363 while(*s==TEXT('\\') || *s==TEXT('/'))
369 read_directory(entry, buffer, sortOrder, hwnd);
372 entry->expanded = TRUE;
377 entry = find_entry_win(entry, s);
380 SetCursor(old_cursor);
386 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
388 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
390 struct tm* tm = gmtime(t);
396 stime.wYear = tm->tm_year+1900;
397 stime.wMonth = tm->tm_mon+1;
398 /* stime.wDayOfWeek */
399 stime.wDay = tm->tm_mday;
400 stime.wHour = tm->tm_hour;
401 stime.wMinute = tm->tm_min;
402 stime.wSecond = tm->tm_sec;
404 return SystemTimeToFileTime(&stime, ftime);
407 static void read_directory_unix(Entry* dir, LPCTSTR path)
409 Entry* first_entry = NULL;
413 int level = dir->level + 1;
415 DIR* pdir = opendir(path);
420 TCHAR buffer[MAX_PATH], *p;
422 for(p=buffer; *path; )
425 if (p==buffer || p[-1]!='/')
428 while((ent=readdir(pdir))) {
429 entry = alloc_entry();
437 entry->etype = ET_UNIX;
439 lstrcpy(entry->data.cFileName, ent->d_name);
440 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
442 strcpy(p, ent->d_name);
444 if (!stat(buffer, &st)) {
445 if (S_ISDIR(st.st_mode))
446 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
448 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
449 entry->data.nFileSizeHigh = st.st_size >> 32;
451 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
452 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
453 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
455 entry->bhfi.nFileIndexLow = ent->d_ino;
456 entry->bhfi.nFileIndexHigh = 0;
458 entry->bhfi.nNumberOfLinks = st.st_nlink;
460 entry->bhfi_valid = TRUE;
462 entry->data.nFileSizeLow = 0;
463 entry->data.nFileSizeHigh = 0;
464 entry->bhfi_valid = FALSE;
469 entry->expanded = FALSE;
470 entry->scanned = FALSE;
471 entry->level = level;
481 dir->down = first_entry;
485 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
489 for(entry=dir->down; entry; entry=entry->next) {
491 LPCTSTR q = entry->data.cFileName;
494 if (!*p || *p==TEXT('/'))
496 } while(*p++ == *q++);
502 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
504 TCHAR buffer[MAX_PATH];
505 Entry* entry = &root->entry;
509 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
511 entry->etype = ET_UNIX;
514 while(*s && *s!=TEXT('/'))
517 while(*s == TEXT('/'))
523 read_directory(entry, buffer, sortOrder, hwnd);
526 entry->expanded = TRUE;
531 entry = find_entry_unix(entry, s);
534 SetCursor(old_cursor);
539 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
542 #ifdef _SHELL_FOLDERS
545 #define tcscpyn strcpyn
546 #define get_strret get_strretW
547 #define path_from_pidl path_from_pidlW
549 #define tcscpyn wcscpyn
550 #define get_strret get_strretA
551 #define path_from_pidl path_from_pidlA
555 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
560 for(s=source; count&&(*d++=*s++); )
566 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
571 for(s=source; count&&(*d++=*s++); )
578 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
582 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
586 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
590 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
594 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
598 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
602 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
606 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
611 static void free_strret(STRRET* str)
613 if (str->uType == STRRET_WSTR)
614 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
618 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
622 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
625 get_strret(&str, &pidl->mkid, buffer, len);
634 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
638 /* SHGDN_FORPARSING: get full path of id list */
639 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
642 get_strretA(&str, &pidl->mkid, buffer, len);
650 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
654 /* SHGDN_FORPARSING: get full path of id list */
655 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
658 get_strretW(&str, &pidl->mkid, buffer, len);
667 /* create an item id list from a file system path */
669 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
676 LPWSTR buffer = path;
678 WCHAR buffer[MAX_PATH];
679 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
682 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
690 /* convert an item id list from relative to absolute (=relative to the desktop) format */
692 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
694 if (entry->up && entry->up->etype==ET_SHELL) {
695 IShellFolder* folder = entry->up->folder;
696 WCHAR buffer[MAX_PATH];
698 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
704 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
709 } else if (entry->etype == ET_WINDOWS) {
710 TCHAR path[MAX_PATH];
712 get_path(entry, path);
714 return get_path_pidl(path, hwnd);
715 } else if (entry->pidl)
716 return ILClone(entry->pidl);
722 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
724 IExtractIcon* pExtract;
726 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
727 TCHAR path[_MAX_PATH];
732 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
733 if (!(flags & GIL_NOTFILENAME)) {
735 idx = 0; /* special case for some control panel applications */
737 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
738 flags &= ~GIL_DONTCACHE;
740 HICON hIconLarge = 0;
742 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
745 DestroyIcon(hIconLarge);
756 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
760 for(entry=dir->down; entry; entry=entry->next) {
761 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
762 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
769 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
771 Entry* entry = &root->entry;
773 LPITEMIDLIST next_pidl = pidl;
774 IShellFolder* folder;
775 IShellFolder* child = NULL;
778 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
780 #ifndef _NO_EXTENSIONS
781 entry->etype = ET_SHELL;
784 folder = Globals.iDesktop;
787 entry->pidl = next_pidl;
788 entry->folder = folder;
793 /* copy first element of item idlist */
794 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
795 memcpy(next_pidl, pidl, pidl->mkid.cb);
796 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
798 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
802 read_directory(entry, NULL, sortOrder, hwnd);
805 entry->expanded = TRUE;
807 next = find_entry_shell(entry, next_pidl);
814 /* go to next element */
815 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
818 SetCursor(old_cursor);
824 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
826 if (!(attribs & SFGAO_FILESYSTEM) ||
827 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
828 WIN32_FILE_ATTRIBUTE_DATA fad;
829 IDataObject* pDataObj;
831 STGMEDIUM medium = {0, {0}, 0};
832 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
834 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
837 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
839 (*pDataObj->lpVtbl->Release)(pDataObj);
842 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
843 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
845 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
846 w32fdata->dwFileAttributes = fad.dwFileAttributes;
847 w32fdata->ftCreationTime = fad.ftCreationTime;
848 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
849 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
851 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
852 w32fdata->nFileSizeLow = fad.nFileSizeLow;
853 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
857 SetErrorMode(sem_org);
859 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
860 GlobalFree(medium.UNION_MEMBER(hGlobal));
865 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
866 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
868 if (attribs & SFGAO_READONLY)
869 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
871 if (attribs & SFGAO_COMPRESSED)
872 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
876 static void read_directory_shell(Entry* dir, HWND hwnd)
878 IShellFolder* folder = dir->folder;
879 int level = dir->level + 1;
885 Entry* first_entry = NULL;
892 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
896 #define FETCH_ITEM_COUNT 32
897 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
902 memset(pidls, 0, sizeof(pidls));
904 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
911 for(n=0; n<cnt; ++n) {
912 entry = alloc_entry();
920 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
921 entry->bhfi_valid = FALSE;
923 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
925 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
928 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
929 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
931 entry->bhfi_valid = TRUE;
937 entry->pidl = pidls[n];
939 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
940 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
943 entry->folder = child;
945 entry->folder = NULL;
948 entry->folder = NULL;
950 if (!entry->data.cFileName[0])
951 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
953 /* get display icons for files and virtual objects */
954 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
955 !(attribs & SFGAO_FILESYSTEM)) {
956 entry->hicon = extract_icon(folder, pidls[n]);
959 entry->hicon = (HICON)-1; /* don't try again later */
964 entry->expanded = FALSE;
965 entry->scanned = FALSE;
966 entry->level = level;
968 #ifndef _NO_EXTENSIONS
969 entry->etype = ET_SHELL;
970 entry->bhfi_valid = FALSE;
977 (*idlist->lpVtbl->Release)(idlist);
983 dir->down = first_entry;
987 #endif /* _SHELL_FOLDERS */
990 /* directories first... */
991 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
993 int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
994 int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
996 return dir2==dir1? 0: dir2<dir1? -1: 1;
1000 static int compareName(const void* arg1, const void* arg2)
1002 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1003 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1005 int cmp = compareType(fd1, fd2);
1009 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1012 static int compareExt(const void* arg1, const void* arg2)
1014 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1015 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1016 const TCHAR *name1, *name2, *ext1, *ext2;
1018 int cmp = compareType(fd1, fd2);
1022 name1 = fd1->cFileName;
1023 name2 = fd2->cFileName;
1025 ext1 = _tcsrchr(name1, TEXT('.'));
1026 ext2 = _tcsrchr(name2, TEXT('.'));
1038 cmp = lstrcmpi(ext1, ext2);
1042 return lstrcmpi(name1, name2);
1045 static int compareSize(const void* arg1, const void* arg2)
1047 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1048 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1050 int cmp = compareType(fd1, fd2);
1054 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1061 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1063 return cmp<0? -1: cmp>0? 1: 0;
1066 static int compareDate(const void* arg1, const void* arg2)
1068 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1069 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1071 int cmp = compareType(fd1, fd2);
1075 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1079 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1080 compareName, /* SORT_NAME */
1081 compareExt, /* SORT_EXT */
1082 compareSize, /* SORT_SIZE */
1083 compareDate /* SORT_DATE */
1087 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1089 Entry* entry = dir->down;
1094 for(entry=dir->down; entry; entry=entry->next)
1098 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1101 for(entry=dir->down; entry; entry=entry->next)
1104 /* call qsort with the appropriate compare function */
1105 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1107 dir->down = array[0];
1109 for(p=array; --len; p++)
1113 HeapFree( GetProcessHeap(), 0, array );
1118 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1120 TCHAR buffer[MAX_PATH];
1125 #ifdef _SHELL_FOLDERS
1126 if (dir->etype == ET_SHELL)
1128 read_directory_shell(dir, hwnd);
1130 if (Globals.prescan_node) {
1139 for(entry=dir->down; entry; entry=entry->next)
1140 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1141 read_directory_shell(entry, hwnd);
1142 SortDirectory(entry, sortOrder);
1148 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1149 if (dir->etype == ET_UNIX)
1151 read_directory_unix(dir, path);
1153 if (Globals.prescan_node) {
1162 for(entry=dir->down; entry; entry=entry->next)
1163 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1164 lstrcpy(d, entry->data.cFileName);
1165 read_directory_unix(entry, buffer);
1166 SortDirectory(entry, sortOrder);
1173 read_directory_win(dir, path);
1175 if (Globals.prescan_node) {
1184 for(entry=dir->down; entry; entry=entry->next)
1185 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1186 lstrcpy(d, entry->data.cFileName);
1187 read_directory_win(entry, buffer);
1188 SortDirectory(entry, sortOrder);
1193 SortDirectory(dir, sortOrder);
1197 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1199 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1200 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1201 Root* root = &child->root;
1204 memset(child, 0, sizeof(ChildWnd));
1206 child->left.treePane = TRUE;
1207 child->left.visible_cols = 0;
1209 child->right.treePane = FALSE;
1210 #ifndef _NO_EXTENSIONS
1211 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1213 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1216 child->pos.length = sizeof(WINDOWPLACEMENT);
1217 child->pos.flags = 0;
1218 child->pos.showCmd = SW_SHOWNORMAL;
1219 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1220 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1221 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1222 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1224 child->focus_pane = 0;
1225 child->split_pos = DEFAULT_SPLIT_POS;
1226 child->sortOrder = SORT_NAME;
1227 child->header_wdths_ok = FALSE;
1231 lstrcpy(child->path, path);
1233 _tsplitpath(path, drv, dir, name, ext);
1236 root->entry.level = 0;
1238 #ifdef _SHELL_FOLDERS
1241 root->drive_type = DRIVE_UNKNOWN;
1242 lstrcpy(drv, TEXT("\\"));
1243 lstrcpy(root->volname, TEXT("Desktop"));
1245 lstrcpy(root->fs, TEXT("Shell"));
1247 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1251 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1254 root->drive_type = GetDriveType(path);
1256 lstrcat(drv, TEXT("/"));
1257 lstrcpy(root->volname, TEXT("root fs"));
1259 lstrcpy(root->fs, TEXT("unixfs"));
1261 lstrcpy(root->path, TEXT("/"));
1262 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1267 root->drive_type = GetDriveType(path);
1269 lstrcat(drv, TEXT("\\"));
1270 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1272 lstrcpy(root->path, drv);
1273 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1276 #ifdef _SHELL_FOLDERS
1277 if (root->entry.etype == ET_SHELL)
1278 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1281 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1283 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1285 child->left.root = &root->entry;
1286 child->right.root = NULL;
1288 set_curdir(child, entry, hwnd);
1294 /* free all memory associated with a child window */
1295 static void free_child_window(ChildWnd* child)
1297 free_entries(&child->root.entry);
1302 /* get full path of specified directory entry */
1303 static void get_path(Entry* dir, PTSTR path)
1309 #ifdef _SHELL_FOLDERS
1310 if (dir->etype == ET_SHELL)
1315 path[0] = TEXT('\0');
1320 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1322 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1323 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1325 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1331 for(entry=dir; entry; level++) {
1337 name = entry->data.cFileName;
1340 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1346 memmove(path+l+1, path, len*sizeof(TCHAR));
1347 memcpy(path+1, name, l*sizeof(TCHAR));
1350 #ifndef _NO_EXTENSIONS
1351 if (entry->etype == ET_UNIX)
1352 path[0] = TEXT('/');
1355 path[0] = TEXT('\\');
1360 memmove(path+l, path, len*sizeof(TCHAR));
1361 memcpy(path, name, l*sizeof(TCHAR));
1368 #ifndef _NO_EXTENSIONS
1369 if (entry->etype == ET_UNIX)
1370 path[len++] = TEXT('/');
1373 path[len++] = TEXT('\\');
1376 path[len] = TEXT('\0');
1381 static void resize_frame_rect(HWND hwnd, PRECT prect)
1386 if (IsWindowVisible(Globals.htoolbar)) {
1387 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1388 GetClientRect(Globals.htoolbar, &rt);
1389 prect->top = rt.bottom+3;
1390 prect->bottom -= rt.bottom+3;
1393 if (IsWindowVisible(Globals.hdrivebar)) {
1394 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1395 GetClientRect(Globals.hdrivebar, &rt);
1396 new_top = --prect->top + rt.bottom+3;
1397 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1398 prect->top = new_top;
1399 prect->bottom -= rt.bottom+2;
1402 if (IsWindowVisible(Globals.hstatusbar)) {
1403 int parts[] = {300, 500};
1405 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1406 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1407 GetClientRect(Globals.hstatusbar, &rt);
1408 prect->bottom -= rt.bottom;
1411 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1414 static void resize_frame(HWND hwnd, int cx, int cy)
1423 resize_frame_rect(hwnd, &rect);
1426 static void resize_frame_client(HWND hwnd)
1430 GetClientRect(hwnd, &rect);
1432 resize_frame_rect(hwnd, &rect);
1436 static HHOOK hcbthook;
1437 static ChildWnd* newchild = NULL;
1439 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1441 if (code==HCBT_CREATEWND && newchild) {
1442 ChildWnd* child = newchild;
1445 child->hwnd = (HWND) wparam;
1446 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1449 return CallNextHookEx(hcbthook, code, wparam, lparam);
1452 static HWND create_child_window(ChildWnd* child)
1454 MDICREATESTRUCT mcs;
1457 mcs.szClass = WINEFILETREE;
1458 mcs.szTitle = (LPTSTR)child->path;
1459 mcs.hOwner = Globals.hInstance;
1460 mcs.x = child->pos.rcNormalPosition.left;
1461 mcs.y = child->pos.rcNormalPosition.top;
1462 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1463 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1467 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1470 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1472 UnhookWindowsHookEx(hcbthook);
1476 UnhookWindowsHookEx(hcbthook);
1478 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1479 ListBox_SetCurSel(child->left.hwnd, idx);
1485 struct ExecuteDialog {
1486 TCHAR cmd[MAX_PATH];
1491 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1493 static struct ExecuteDialog* dlg;
1497 dlg = (struct ExecuteDialog*) lparam;
1501 int id = (int)wparam;
1504 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1505 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1506 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1507 EndDialog(hwnd, id);
1508 } else if (id == IDCANCEL)
1509 EndDialog(hwnd, id);
1518 #ifndef _NO_EXTENSIONS
1520 static struct FullScreenParameters {
1530 void frame_get_clientspace(HWND hwnd, PRECT prect)
1534 if (!IsIconic(hwnd))
1535 GetClientRect(hwnd, prect);
1539 GetWindowPlacement(hwnd, &wp);
1541 prect->left = prect->top = 0;
1542 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1543 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1544 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1545 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1546 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1549 if (IsWindowVisible(Globals.htoolbar)) {
1550 GetClientRect(Globals.htoolbar, &rt);
1551 prect->top += rt.bottom+2;
1554 if (IsWindowVisible(Globals.hdrivebar)) {
1555 GetClientRect(Globals.hdrivebar, &rt);
1556 prect->top += rt.bottom+2;
1559 if (IsWindowVisible(Globals.hstatusbar)) {
1560 GetClientRect(Globals.hstatusbar, &rt);
1561 prect->bottom -= rt.bottom;
1565 static BOOL toggle_fullscreen(HWND hwnd)
1569 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1570 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1571 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1573 Frame_CalcFrameClient(hwnd, &rt);
1574 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1575 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1577 rt.left = g_fullscreen.orgPos.left-rt.left;
1578 rt.top = g_fullscreen.orgPos.top-rt.top;
1579 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1580 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1582 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1584 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1585 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1586 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1588 if (g_fullscreen.wasZoomed)
1589 ShowWindow(hwnd, WS_MAXIMIZE);
1592 return g_fullscreen.mode;
1595 static void fullscreen_move(HWND hwnd)
1598 GetWindowRect(hwnd, &pos);
1600 Frame_CalcFrameClient(hwnd, &rt);
1601 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1602 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1604 rt.left = pos.left-rt.left;
1605 rt.top = pos.top-rt.top;
1606 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1607 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1609 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1615 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1617 BOOL vis = IsWindowVisible(hchild);
1619 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1621 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1623 #ifndef _NO_EXTENSIONS
1624 if (g_fullscreen.mode)
1625 fullscreen_move(hwnd);
1628 resize_frame_client(hwnd);
1631 BOOL activate_drive_window(LPCTSTR path)
1633 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1636 _tsplitpath(path, drv1, 0, 0, 0);
1638 /* search for a already open window for the same drive */
1639 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1640 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1643 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1645 if (!lstrcmpi(drv2, drv1)) {
1646 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1648 if (IsMinimized(child_wnd))
1649 ShowWindow(child_wnd, SW_SHOWNORMAL);
1659 BOOL activate_fs_window(LPCTSTR filesys)
1663 /* search for a already open window of the given file system name */
1664 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1665 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1668 if (!lstrcmpi(child->root.fs, filesys)) {
1669 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1671 if (IsMinimized(child_wnd))
1672 ShowWindow(child_wnd, SW_SHOWNORMAL);
1682 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1686 DestroyWindow(hwnd);
1688 /* clear handle variables */
1689 Globals.hMenuFrame = 0;
1690 Globals.hMenuView = 0;
1691 Globals.hMenuOptions = 0;
1692 Globals.hMainWnd = 0;
1693 Globals.hmdiclient = 0;
1694 Globals.hdrivebar = 0;
1698 /* don't exit desktop when closing file manager window */
1699 if (!Globals.hwndParent)
1704 UINT cmd = LOWORD(wparam);
1705 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1707 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1710 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1711 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1713 LPCTSTR root = Globals.drives;
1716 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1720 if (activate_drive_window(root))
1723 _tsplitpath(root, drv, 0, 0, 0);
1725 if (!SetCurrentDirectory(drv)) {
1726 display_error(hwnd, GetLastError());
1730 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1731 child = alloc_child_window(path, NULL, hwnd);
1733 if (!create_child_window(child))
1735 } else switch(cmd) {
1737 SendMessage(hwnd, WM_CLOSE, 0, 0);
1740 case ID_WINDOW_NEW: {
1741 TCHAR path[MAX_PATH];
1744 GetCurrentDirectory(MAX_PATH, path);
1745 child = alloc_child_window(path, NULL, hwnd);
1747 if (!create_child_window(child))
1751 case ID_WINDOW_CASCADE:
1752 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1755 case ID_WINDOW_TILE_HORZ:
1756 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1759 case ID_WINDOW_TILE_VERT:
1760 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1763 case ID_WINDOW_ARRANGE:
1764 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1767 case ID_VIEW_TOOL_BAR:
1768 toggle_child(hwnd, cmd, Globals.htoolbar);
1771 case ID_VIEW_DRIVE_BAR:
1772 toggle_child(hwnd, cmd, Globals.hdrivebar);
1775 case ID_VIEW_STATUSBAR:
1776 toggle_child(hwnd, cmd, Globals.hstatusbar);
1780 struct ExecuteDialog dlg;
1782 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1784 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1785 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1787 if ((int)hinst <= 32)
1788 display_error(hwnd, GetLastError());
1793 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1796 #ifndef _NO_EXTENSIONS
1797 case ID_VIEW_FULLSCREEN:
1798 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1802 case ID_DRIVE_UNIX_FS: {
1803 TCHAR path[MAX_PATH];
1806 if (activate_fs_window(TEXT("unixfs")))
1809 getcwd(path, MAX_PATH);
1810 child = alloc_child_window(path, NULL, hwnd);
1812 if (!create_child_window(child))
1816 #ifdef _SHELL_FOLDERS
1817 case ID_DRIVE_SHELL_NS: {
1818 TCHAR path[MAX_PATH];
1821 if (activate_fs_window(TEXT("Shell")))
1824 GetCurrentDirectory(MAX_PATH, path);
1825 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1827 if (!create_child_window(child))
1833 /*TODO: There are even more menu items! */
1835 #ifndef _NO_EXTENSIONS
1838 WineLicense(Globals.hMainWnd);
1841 case ID_NO_WARRANTY:
1842 WineWarranty(Globals.hMainWnd);
1847 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1850 case ID_ABOUT: /*ID_ABOUT_WINE: */
1851 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1853 #endif /* _NO_EXTENSIONS */
1856 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1857 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1858 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1859 (cmd<SC_SIZE || cmd>SC_RESTORE))
1860 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1862 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1867 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1868 break; /* do not pass message to DefFrameProc */
1870 #ifndef _NO_EXTENSIONS
1871 case WM_GETMINMAXINFO: {
1872 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1874 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1875 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1878 case FRM_CALC_CLIENT:
1879 frame_get_clientspace(hwnd, (PRECT)lparam);
1881 #endif /* _NO_EXTENSIONS */
1884 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1891 static const LPTSTR g_pos_names[COLUMNS] = {
1892 TEXT(""), /* symbol */
1896 #ifndef _NO_EXTENSIONS
1899 TEXT("Index/Inode"),
1901 #endif /* _NO_EXTENSIONS */
1903 #ifndef _NO_EXTENSIONS
1908 static const int g_pos_align[] = {
1910 HDF_LEFT, /* Name */
1911 HDF_RIGHT, /* Size */
1912 HDF_LEFT, /* CDate */
1913 #ifndef _NO_EXTENSIONS
1914 HDF_LEFT, /* ADate */
1915 HDF_LEFT, /* MDate */
1916 HDF_LEFT, /* Index */
1917 HDF_CENTER, /* Links */
1919 HDF_CENTER, /* Attributes */
1920 #ifndef _NO_EXTENSIONS
1921 HDF_LEFT /* Security */
1925 static void resize_tree(ChildWnd* child, int cx, int cy)
1927 HDWP hdwp = BeginDeferWindowPos(4);
1935 cx = child->split_pos + SPLIT_WIDTH/2;
1937 #ifndef _NO_EXTENSIONS
1945 Header_Layout(child->left.hwndHeader, &hdl);
1947 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1948 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1949 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1950 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1952 #endif /* _NO_EXTENSIONS */
1954 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);
1955 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1957 EndDeferWindowPos(hdwp);
1961 #ifndef _NO_EXTENSIONS
1963 static HWND create_header(HWND parent, Pane* pane, int id)
1968 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1969 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1973 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1975 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1977 for(idx=0; idx<COLUMNS; idx++) {
1978 hdi.pszText = g_pos_names[idx];
1979 hdi.fmt = HDF_STRING | g_pos_align[idx];
1980 hdi.cxy = pane->widths[idx];
1981 Header_InsertItem(hwnd, idx, &hdi);
1987 #endif /* _NO_EXTENSIONS */
1990 static void init_output(HWND hwnd)
1994 HDC hdc = GetDC(hwnd);
1996 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1997 Globals.num_sep = b[1];
1999 Globals.num_sep = TEXT('.');
2001 old_font = SelectFont(hdc, Globals.hfont);
2002 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
2003 SelectFont(hdc, old_font);
2004 ReleaseDC(hwnd, hdc);
2007 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2010 /* calculate prefered width for all visible columns */
2012 static BOOL calc_widths(Pane* pane, BOOL anyway)
2014 int col, x, cx, spc=3*Globals.spaceSize.cx;
2015 int entries = ListBox_GetCount(pane->hwnd);
2016 int orgWidths[COLUMNS];
2017 int orgPositions[COLUMNS+1];
2023 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2024 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2027 for(col=0; col<COLUMNS; col++)
2028 pane->widths[col] = 0;
2030 hdc = GetDC(pane->hwnd);
2031 hfontOld = SelectFont(hdc, Globals.hfont);
2033 for(cnt=0; cnt<entries; cnt++) {
2034 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2043 dis.hwndItem = pane->hwnd;
2045 dis.rcItem.left = 0;
2047 dis.rcItem.right = 0;
2048 dis.rcItem.bottom = 0;
2049 /*dis.itemData = 0; */
2051 draw_item(pane, &dis, entry, COLUMNS);
2054 SelectObject(hdc, hfontOld);
2055 ReleaseDC(pane->hwnd, hdc);
2058 for(col=0; col<COLUMNS; col++) {
2059 pane->positions[col] = x;
2060 cx = pane->widths[col];
2065 if (cx < IMAGE_WIDTH)
2068 pane->widths[col] = cx;
2074 pane->positions[COLUMNS] = x;
2076 ListBox_SetHorizontalExtent(pane->hwnd, x);
2079 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2082 /* don't move, if only collapsing an entry */
2083 if (!anyway && pane->widths[0]<orgWidths[0] &&
2084 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2085 pane->widths[0] = orgWidths[0];
2086 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2091 InvalidateRect(pane->hwnd, 0, TRUE);
2097 /* calculate one prefered column width */
2099 static void calc_single_width(Pane* pane, int col)
2103 int entries = ListBox_GetCount(pane->hwnd);
2107 pane->widths[col] = 0;
2109 hdc = GetDC(pane->hwnd);
2110 hfontOld = SelectFont(hdc, Globals.hfont);
2112 for(cnt=0; cnt<entries; cnt++) {
2113 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2121 dis.hwndItem = pane->hwnd;
2123 dis.rcItem.left = 0;
2125 dis.rcItem.right = 0;
2126 dis.rcItem.bottom = 0;
2127 /*dis.itemData = 0; */
2129 draw_item(pane, &dis, entry, col);
2132 SelectObject(hdc, hfontOld);
2133 ReleaseDC(pane->hwnd, hdc);
2135 cx = pane->widths[col];
2138 cx += 3*Globals.spaceSize.cx;
2140 if (cx < IMAGE_WIDTH)
2144 pane->widths[col] = cx;
2146 x = pane->positions[col] + cx;
2148 for(; col<COLUMNS; ) {
2149 pane->positions[++col] = x;
2150 x += pane->widths[col];
2153 ListBox_SetHorizontalExtent(pane->hwnd, x);
2157 /* insert listbox entries after index idx */
2159 static void insert_entries(Pane* pane, Entry* dir, int idx)
2166 ShowWindow(pane->hwnd, SW_HIDE);
2168 for(; entry; entry=entry->next) {
2170 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2174 /* don't display entries "." and ".." in the left pane */
2175 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2176 && entry->data.cFileName[0]==TEXT('.'))
2178 #ifndef _NO_EXTENSIONS
2179 entry->data.cFileName[1]==TEXT('\0') ||
2181 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2187 ListBox_InsertItemData(pane->hwnd, idx, entry);
2189 if (pane->treePane && entry->expanded)
2190 insert_entries(pane, entry->down, idx);
2193 ShowWindow(pane->hwnd, SW_SHOW);
2197 static WNDPROC g_orgTreeWndProc;
2199 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2201 static int s_init = 0;
2202 Entry* entry = pane->root;
2204 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2205 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2206 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2208 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2209 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2211 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2213 /* insert entries into listbox */
2215 insert_entries(pane, entry, -1);
2217 /* calculate column widths */
2220 init_output(pane->hwnd);
2223 calc_widths(pane, TRUE);
2225 #ifndef _NO_EXTENSIONS
2226 pane->hwndHeader = create_header(parent, pane, id_header);
2231 static void InitChildWindow(ChildWnd* child)
2233 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2234 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2238 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2244 *buffer = TEXT('\0');
2246 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2249 if (!FileTimeToLocalFileTime(ft, &lft))
2250 {err: _tcscpy(buffer,TEXT("???")); return;}
2252 if (!FileTimeToSystemTime(&lft, &systime))
2255 if (visible_cols & COL_DATE) {
2256 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2261 if (visible_cols & COL_TIME) {
2263 buffer[len-1] = ' ';
2265 buffer[len++] = ' ';
2267 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2268 buffer[len] = TEXT('\0');
2273 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2275 RECT rt = {0, 0, 0, 0};
2277 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2279 if (rt.right > pane->widths[col])
2280 pane->widths[col] = rt.right;
2283 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2285 RECT rt = {0, 0, 0, 0};
2287 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2288 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2290 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2291 /*FIXME rt (0,0) ??? */
2293 if (rt.right > pane->widths[col])
2294 pane->widths[col] = rt.right;
2298 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2300 int x = dis->rcItem.left;
2303 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2304 rt.top = dis->rcItem.top;
2305 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2306 rt.bottom = dis->rcItem.bottom;
2308 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2311 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2313 int x = dis->rcItem.left;
2316 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2317 rt.top = dis->rcItem.top;
2318 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2319 rt.bottom = dis->rcItem.bottom;
2321 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2322 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2324 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2327 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2329 int x = dis->rcItem.left;
2336 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2337 rt.top = dis->rcItem.top;
2338 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2339 rt.bottom = dis->rcItem.bottom;
2344 /* insert number separator characters */
2345 pos = lstrlen(s) % 3;
2351 *d++ = Globals.num_sep;
2355 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2359 static int is_exe_file(LPCTSTR ext)
2361 static const LPCTSTR executable_extensions[] = {
2366 #ifndef _NO_EXTENSIONS
2370 #endif /* _NO_EXTENSIONS */
2374 TCHAR ext_buffer[_MAX_EXT];
2379 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2382 for(p=executable_extensions; *p; p++)
2383 if (!_tcscmp(ext_buffer, *p))
2389 static int is_registered_type(LPCTSTR ext)
2397 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2399 TCHAR buffer[BUFFER_LEN];
2401 int visible_cols = pane->visible_cols;
2402 COLORREF bkcolor, textcolor;
2403 RECT focusRect = dis->rcItem;
2410 attrs = entry->data.dwFileAttributes;
2412 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2413 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2414 && entry->data.cFileName[2]==TEXT('\0'))
2415 img = IMG_FOLDER_UP;
2416 #ifndef _NO_EXTENSIONS
2417 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2418 img = IMG_FOLDER_CUR;
2421 #ifdef _NO_EXTENSIONS
2424 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2425 img = IMG_OPEN_FOLDER;
2429 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2433 if (is_exe_file(ext))
2434 img = IMG_EXECUTABLE;
2435 else if (is_registered_type(ext))
2445 if (pane->treePane) {
2447 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2449 if (calcWidthCol == -1) {
2451 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2454 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2457 rt_clip.left = dis->rcItem.left;
2458 rt_clip.top = dis->rcItem.top;
2459 rt_clip.right = dis->rcItem.left+pane->widths[col];
2460 rt_clip.bottom = dis->rcItem.bottom;
2462 hrgn = CreateRectRgnIndirect(&rt_clip);
2464 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2465 DeleteObject(hrgn_org);
2469 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2470 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2473 if ((up=entry->up) != NULL) {
2474 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2475 LineTo(dis->hDC, img_pos-2, y);
2477 x = img_pos - IMAGE_WIDTH/2;
2480 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2484 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2487 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2488 LineTo(dis->hDC, x, dis->rcItem.bottom);
2490 } while((up=up->up) != NULL);
2493 x = img_pos - IMAGE_WIDTH/2;
2495 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2496 LineTo(dis->hDC, x, y);
2500 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2503 LineTo(dis->hDC, x, dis->rcItem.bottom);
2505 if (entry->down && entry->expanded) {
2506 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2507 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2508 LineTo(dis->hDC, x, dis->rcItem.bottom);
2511 SelectClipRgn(dis->hDC, hrgn_org);
2512 if (hrgn_org) DeleteObject(hrgn_org);
2513 /* SelectObject(dis->hDC, holdPen); */
2514 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2515 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2517 if (right > pane->widths[col])
2518 pane->widths[col] = right;
2521 img_pos = dis->rcItem.left;
2524 img_pos = dis->rcItem.left;
2526 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2527 pane->widths[col] = IMAGE_WIDTH;
2530 if (calcWidthCol == -1) {
2531 focusRect.left = img_pos -2;
2533 #ifdef _NO_EXTENSIONS
2534 if (pane->treePane && entry) {
2537 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2539 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2543 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2544 textcolor = COLOR_COMPRESSED;
2546 #endif /* _NO_EXTENSIONS */
2547 textcolor = RGB(0,0,0);
2549 if (dis->itemState & ODS_FOCUS) {
2550 textcolor = RGB(255,255,255);
2551 bkcolor = COLOR_SELECTION;
2553 bkcolor = RGB(255,255,255);
2556 hbrush = CreateSolidBrush(bkcolor);
2557 FillRect(dis->hDC, &focusRect, hbrush);
2558 DeleteObject(hbrush);
2560 SetBkMode(dis->hDC, TRANSPARENT);
2561 SetTextColor(dis->hDC, textcolor);
2563 cx = pane->widths[col];
2565 if (cx && img!=IMG_NONE) {
2566 if (cx > IMAGE_WIDTH)
2569 #ifdef _SHELL_FOLDERS
2570 if (entry->hicon && entry->hicon!=(HICON)-1)
2571 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2574 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2575 img_pos, dis->rcItem.top, cx,
2576 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2583 #ifdef _NO_EXTENSIONS
2584 if (img >= IMG_FOLDER_UP)
2590 /* ouput file name */
2591 if (calcWidthCol == -1)
2592 output_text(pane, dis, col, entry->data.cFileName, 0);
2593 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2594 calc_width(pane, dis, col, entry->data.cFileName);
2598 #ifdef _NO_EXTENSIONS
2599 if (!pane->treePane) {
2602 /* display file size */
2603 if (visible_cols & COL_SIZE) {
2604 #ifdef _NO_EXTENSIONS
2605 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2610 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2612 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2614 if (calcWidthCol == -1)
2615 output_number(pane, dis, col, buffer);
2616 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2617 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2623 /* display file date */
2624 if (visible_cols & (COL_DATE|COL_TIME)) {
2625 #ifndef _NO_EXTENSIONS
2626 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2627 if (calcWidthCol == -1)
2628 output_text(pane, dis, col, buffer, 0);
2629 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2630 calc_width(pane, dis, col, buffer);
2633 format_date(&entry->data.ftLastAccessTime, 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);
2639 #endif /* _NO_EXTENSIONS */
2641 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2642 if (calcWidthCol == -1)
2643 output_text(pane, dis, col, buffer, 0);
2644 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2645 calc_width(pane, dis, col, buffer);
2649 #ifndef _NO_EXTENSIONS
2650 if (entry->bhfi_valid) {
2651 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2653 if (visible_cols & COL_INDEX) {
2654 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2655 if (calcWidthCol == -1)
2656 output_text(pane, dis, col, buffer, DT_RIGHT);
2657 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2658 calc_width(pane, dis, col, buffer);
2662 if (visible_cols & COL_LINKS) {
2663 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2664 if (calcWidthCol == -1)
2665 output_text(pane, dis, col, buffer, DT_CENTER);
2666 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2667 calc_width(pane, dis, col, buffer);
2672 #endif /* _NO_EXTENSIONS */
2674 /* show file attributes */
2675 if (visible_cols & COL_ATTRIBUTES) {
2676 #ifdef _NO_EXTENSIONS
2677 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2679 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2682 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2684 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2685 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2686 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2687 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2688 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2689 #ifndef _NO_EXTENSIONS
2690 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2691 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2692 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2693 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2694 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2695 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2696 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2697 #endif /* _NO_EXTENSIONS */
2700 if (calcWidthCol == -1)
2701 output_tabbed_text(pane, dis, col, buffer);
2702 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2703 calc_tabbed_width(pane, dis, col, buffer);
2709 if (flags.security) {
2710 DWORD rights = get_access_mask();
2712 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2714 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2715 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2716 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2717 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2718 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2719 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2720 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2721 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2722 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2723 if (rights & WRITE_DAC) buffer[22] = 'C';
2724 if (rights & WRITE_OWNER) buffer[24] = 'O';
2725 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2727 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2730 if (flags.description) {
2731 get_description(buffer);
2732 output_text(dis, col++, buffer, 0, psize);
2736 #ifdef _NO_EXTENSIONS
2739 /* draw focus frame */
2740 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2741 /* Currently [04/2000] Wine neither behaves exactly the same */
2742 /* way as WIN 95 nor like Windows NT... */
2747 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2748 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2749 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2751 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2753 lastPen = SelectPen(dis->hDC, hpen);
2754 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2755 SetROP2(dis->hDC, R2_XORPEN);
2756 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2757 SelectObject(dis->hDC, lastBrush);
2758 SelectObject(dis->hDC, lastPen);
2761 #endif /* _NO_EXTENSIONS */
2765 #ifdef _NO_EXTENSIONS
2767 static void draw_splitbar(HWND hwnd, int x)
2770 HDC hdc = GetDC(hwnd);
2772 GetClientRect(hwnd, &rt);
2774 rt.left = x - SPLIT_WIDTH/2;
2775 rt.right = x + SPLIT_WIDTH/2+1;
2777 InvertRect(hdc, &rt);
2779 ReleaseDC(hwnd, hdc);
2782 #endif /* _NO_EXTENSIONS */
2785 #ifndef _NO_EXTENSIONS
2787 static void set_header(Pane* pane)
2790 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2793 item.mask = HDI_WIDTH;
2796 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2797 x += pane->widths[i];
2798 Header_SetItem(pane->hwndHeader, i, &item);
2802 x += pane->widths[i];
2803 item.cxy = x - scroll_pos;
2804 Header_SetItem(pane->hwndHeader, i++, &item);
2806 for(; i<COLUMNS; i++) {
2807 item.cxy = pane->widths[i];
2808 x += pane->widths[i];
2809 Header_SetItem(pane->hwndHeader, i, &item);
2814 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2816 switch(pnmh->code) {
2818 case HDN_ENDTRACK: {
2819 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2820 int idx = phdn->iItem;
2821 int dx = phdn->pitem->cxy - pane->widths[idx];
2825 GetClientRect(pane->hwnd, &clnt);
2827 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2828 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2830 pane->widths[idx] += dx;
2832 for(i=idx; ++i<=COLUMNS; )
2833 pane->positions[i] += dx;
2836 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2840 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2842 rt_scr.right = clnt.right;
2843 rt_scr.bottom = clnt.bottom;
2845 rt_clip.left = pane->positions[idx]-scroll_pos;
2847 rt_clip.right = clnt.right;
2848 rt_clip.bottom = clnt.bottom;
2850 if (rt_scr.left < 0) rt_scr.left = 0;
2851 if (rt_clip.left < 0) rt_clip.left = 0;
2853 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2855 rt_clip.right = pane->positions[idx+1];
2856 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2858 if (pnmh->code == HDN_ENDTRACK) {
2859 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2861 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2869 case HDN_DIVIDERDBLCLICK: {
2870 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2873 calc_single_width(pane, phdn->iItem);
2874 item.mask = HDI_WIDTH;
2875 item.cxy = pane->widths[phdn->iItem];
2877 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2878 InvalidateRect(pane->hwnd, 0, TRUE);
2885 #endif /* _NO_EXTENSIONS */
2888 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2890 TCHAR path[MAX_PATH];
2891 int idx = ListBox_GetCurSel(child->left.hwnd);
2892 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2894 /* delete sub entries in left pane */
2896 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2897 Entry* sub = (Entry*) res;
2899 if (res==LB_ERR || !sub || sub->level<=entry->level)
2902 ListBox_DeleteString(child->left.hwnd, idx+1);
2905 /* empty right pane */
2906 ListBox_ResetContent(child->right.hwnd);
2908 /* release memory */
2909 free_entries(entry);
2911 /* read contents from disk */
2912 #ifdef _SHELL_FOLDERS
2913 if (entry->etype == ET_SHELL)
2915 read_directory(entry, NULL, child->sortOrder, hwnd);
2920 get_path(entry, path);
2921 read_directory(entry, path, child->sortOrder, hwnd);
2924 /* insert found entries in right pane */
2925 insert_entries(&child->right, entry->down, -1);
2926 calc_widths(&child->right, FALSE);
2927 #ifndef _NO_EXTENSIONS
2928 set_header(&child->right);
2931 child->header_wdths_ok = FALSE;
2933 SetCursor(old_cursor);
2937 /* expand a directory entry */
2939 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2944 if (!dir || dir->expanded || !dir->down)
2949 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2952 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2953 p->data.cFileName[2]=='\0' && p->next)
2957 /* no subdirectories ? */
2958 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2961 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2963 dir->expanded = TRUE;
2965 /* insert entries in left pane */
2966 insert_entries(&child->left, p, idx);
2968 if (!child->header_wdths_ok) {
2969 if (calc_widths(&child->left, FALSE)) {
2970 #ifndef _NO_EXTENSIONS
2971 set_header(&child->left);
2974 child->header_wdths_ok = TRUE;
2982 static void collapse_entry(Pane* pane, Entry* dir)
2984 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2986 ShowWindow(pane->hwnd, SW_HIDE);
2988 /* hide sub entries */
2990 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2991 Entry* sub = (Entry*) res;
2993 if (res==LB_ERR || !sub || sub->level<=dir->level)
2996 ListBox_DeleteString(pane->hwnd, idx+1);
2999 dir->expanded = FALSE;
3001 ShowWindow(pane->hwnd, SW_SHOW);
3005 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
3007 TCHAR path[MAX_PATH];
3011 child->left.cur = entry;
3012 child->right.root = entry->down? entry->down: entry;
3013 child->right.cur = entry;
3015 if (!entry->scanned)
3016 scan_entry(child, entry, hwnd);
3018 ListBox_ResetContent(child->right.hwnd);
3019 insert_entries(&child->right, entry->down, -1);
3020 calc_widths(&child->right, FALSE);
3021 #ifndef _NO_EXTENSIONS
3022 set_header(&child->right);
3026 get_path(entry, path);
3027 lstrcpy(child->path, path);
3029 if (child->hwnd) /* only change window title, if the window already exists */
3030 SetWindowText(child->hwnd, path);
3033 SetCurrentDirectory(path);
3037 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3039 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3041 if ((int)hinst <= 32) {
3042 display_error(hwnd, GetLastError());
3050 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3052 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3054 if ((int)hinst <= 32) {
3055 display_error(hwnd, GetLastError());
3064 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3066 TCHAR cmd[MAX_PATH];
3068 #ifdef _SHELL_FOLDERS
3069 if (entry->etype == ET_SHELL) {
3072 SHELLEXECUTEINFO shexinfo;
3074 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3075 shexinfo.fMask = SEE_MASK_IDLIST;
3076 shexinfo.hwnd = hwnd;
3077 shexinfo.lpVerb = NULL;
3078 shexinfo.lpFile = NULL;
3079 shexinfo.lpParameters = NULL;
3080 shexinfo.lpDirectory = NULL;
3081 shexinfo.nShow = nCmdShow;
3082 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3084 if (!ShellExecuteEx(&shexinfo)) {
3085 display_error(hwnd, GetLastError());
3089 if (shexinfo.lpIDList != entry->pidl)
3090 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3096 get_path(entry, cmd);
3098 /* start program, open document... */
3099 return launch_file(hwnd, cmd, nCmdShow);
3103 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3105 Entry* entry = pane->cur;
3110 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3111 int scanned_old = entry->scanned;
3114 scan_entry(child, entry, hwnd);
3116 #ifndef _NO_EXTENSIONS
3117 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3121 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3122 entry = child->left.cur->up;
3123 collapse_entry(&child->left, entry);
3125 } else if (entry->expanded)
3126 collapse_entry(pane, child->left.cur);
3128 expand_entry(child, child->left.cur);
3130 if (!pane->treePane) focus_entry: {
3131 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3132 ListBox_SetCurSel(child->left.hwnd, idx);
3133 set_curdir(child, entry, hwnd);
3138 calc_widths(pane, FALSE);
3140 #ifndef _NO_EXTENSIONS
3145 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3150 static BOOL pane_command(Pane* pane, UINT cmd)
3154 if (pane->visible_cols) {
3155 pane->visible_cols = 0;
3156 calc_widths(pane, TRUE);
3157 #ifndef _NO_EXTENSIONS
3160 InvalidateRect(pane->hwnd, 0, TRUE);
3161 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3162 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3163 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3167 case ID_VIEW_ALL_ATTRIBUTES:
3168 if (pane->visible_cols != COL_ALL) {
3169 pane->visible_cols = COL_ALL;
3170 calc_widths(pane, TRUE);
3171 #ifndef _NO_EXTENSIONS
3174 InvalidateRect(pane->hwnd, 0, TRUE);
3175 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3176 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3177 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3181 #ifndef _NO_EXTENSIONS
3182 case ID_PREFERED_SIZES: {
3183 calc_widths(pane, TRUE);
3185 InvalidateRect(pane->hwnd, 0, TRUE);
3189 /* TODO: more command ids... */
3199 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3203 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3204 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3206 if (SUCCEEDED(hr)) {
3207 HMENU hmenu = CreatePopupMenu();
3210 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3212 if (SUCCEEDED(hr)) {
3213 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3216 CMINVOKECOMMANDINFO cmi;
3218 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3220 cmi.hwnd = hwndParent;
3221 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3222 cmi.lpParameters = NULL;
3223 cmi.lpDirectory = NULL;
3224 cmi.nShow = SW_SHOWNORMAL;
3228 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3233 (*pcm->lpVtbl->Release)(pcm);
3240 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3242 static int last_split;
3244 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3249 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3250 Entry* entry = (Entry*) dis->itemData;
3252 if (dis->CtlID == IDW_TREE_LEFT)
3253 draw_item(&child->left, dis, entry, -1);
3255 draw_item(&child->right, dis, entry, -1);
3260 InitChildWindow(child);
3264 free_child_window(child);
3265 SetWindowLong(hwnd, GWL_USERDATA, 0);
3272 GetClientRect(hwnd, &rt);
3273 BeginPaint(hwnd, &ps);
3274 rt.left = child->split_pos-SPLIT_WIDTH/2;
3275 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3276 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3277 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3278 SelectObject(ps.hdc, lastBrush);
3279 #ifdef _NO_EXTENSIONS
3280 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3281 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3283 EndPaint(hwnd, &ps);
3287 if (LOWORD(lparam) == HTCLIENT) {
3290 ScreenToClient(hwnd, &pt);
3292 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3293 SetCursor(LoadCursor(0, IDC_SIZEWE));
3299 case WM_LBUTTONDOWN: {
3301 int x = LOWORD(lparam);
3303 GetClientRect(hwnd, &rt);
3305 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3306 last_split = child->split_pos;
3307 #ifdef _NO_EXTENSIONS
3308 draw_splitbar(hwnd, last_split);
3316 if (GetCapture() == hwnd) {
3317 #ifdef _NO_EXTENSIONS
3319 int x = LOWORD(lparam);
3320 draw_splitbar(hwnd, last_split);
3322 GetClientRect(hwnd, &rt);
3323 child->split_pos = x;
3324 resize_tree(child, rt.right, rt.bottom);
3330 #ifdef _NO_EXTENSIONS
3331 case WM_CAPTURECHANGED:
3332 if (GetCapture()==hwnd && last_split>=0)
3333 draw_splitbar(hwnd, last_split);
3338 if (wparam == VK_ESCAPE)
3339 if (GetCapture() == hwnd) {
3341 #ifdef _NO_EXTENSIONS
3342 draw_splitbar(hwnd, last_split);
3344 child->split_pos = last_split;
3346 GetClientRect(hwnd, &rt);
3347 resize_tree(child, rt.right, rt.bottom);
3350 SetCursor(LoadCursor(0, IDC_ARROW));
3355 if (GetCapture() == hwnd) {
3357 int x = LOWORD(lparam);
3359 #ifdef _NO_EXTENSIONS
3360 HDC hdc = GetDC(hwnd);
3361 GetClientRect(hwnd, &rt);
3363 rt.left = last_split-SPLIT_WIDTH/2;
3364 rt.right = last_split+SPLIT_WIDTH/2+1;
3365 InvertRect(hdc, &rt);
3368 rt.left = x-SPLIT_WIDTH/2;
3369 rt.right = x+SPLIT_WIDTH/2+1;
3370 InvertRect(hdc, &rt);
3372 ReleaseDC(hwnd, hdc);
3374 GetClientRect(hwnd, &rt);
3376 if (x>=0 && x<rt.right) {
3377 child->split_pos = x;
3378 resize_tree(child, rt.right, rt.bottom);
3379 rt.left = x-SPLIT_WIDTH/2;
3380 rt.right = x+SPLIT_WIDTH/2+1;
3381 InvalidateRect(hwnd, &rt, FALSE);
3382 UpdateWindow(child->left.hwnd);
3384 UpdateWindow(child->right.hwnd);
3390 #ifndef _NO_EXTENSIONS
3391 case WM_GETMINMAXINFO:
3392 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3394 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3396 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3397 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3399 #endif /* _NO_EXTENSIONS */
3402 SetCurrentDirectory(child->path);
3403 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3406 case WM_DISPATCH_COMMAND: {
3407 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3409 switch(LOWORD(wparam)) {
3410 case ID_WINDOW_NEW: {
3411 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3413 if (!create_child_window(new_child))
3419 scan_entry(child, pane->cur, hwnd);
3423 activate_entry(child, pane, hwnd);
3427 return pane_command(pane, LOWORD(wparam));
3433 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3435 switch(HIWORD(wparam)) {
3436 case LBN_SELCHANGE: {
3437 int idx = ListBox_GetCurSel(pane->hwnd);
3438 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3440 if (pane == &child->left)
3441 set_curdir(child, entry, hwnd);
3447 activate_entry(child, pane, hwnd);
3452 #ifndef _NO_EXTENSIONS
3454 NMHDR* pnmh = (NMHDR*) lparam;
3455 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3458 #ifdef _SHELL_FOLDERS
3459 case WM_CONTEXTMENU: {
3463 /* first select the current item in the listbox */
3464 HWND hpanel = (HWND) wparam;
3465 POINTS* ppos = &MAKEPOINTS(lparam);
3466 POINT pt; POINTSTOPOINT(pt, *ppos);
3467 ScreenToClient(hpanel, &pt);
3468 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y));
3469 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
3471 /* now create the popup menu using shell namespace and IContextMenu */
3472 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3473 idx = ListBox_GetCurSel(pane->hwnd);
3477 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3479 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3482 IShellFolder* parentFolder;
3483 LPCITEMIDLIST pidlLast;
3485 /* get and use the parent folder to display correct context menu in all cases */
3486 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3487 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, ppos->x, ppos->y);
3489 (*parentFolder->lpVtbl->Release)(parentFolder);
3492 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
3499 if (wparam != SIZE_MINIMIZED)
3500 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3504 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3511 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3513 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3514 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3518 #ifndef _NO_EXTENSIONS
3525 child->focus_pane = pane==&child->right? 1: 0;
3526 ListBox_SetSel(hwnd, TRUE, 1);
3527 /*TODO: check menu items */
3531 if (wparam == VK_TAB) {
3532 /*TODO: SetFocus(Globals.hdrivebar) */
3533 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3537 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3541 static void InitInstance(HINSTANCE hinstance)
3547 INITCOMMONCONTROLSEX icc = {
3548 sizeof(INITCOMMONCONTROLSEX),
3554 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3556 InitCommonControlsEx(&icc);
3559 /* register frame window class */
3561 wcFrame.cbSize = sizeof(WNDCLASSEX);
3563 wcFrame.lpfnWndProc = FrameWndProc;
3564 wcFrame.cbClsExtra = 0;
3565 wcFrame.cbWndExtra = 0;
3566 wcFrame.hInstance = hinstance;
3567 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3568 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3569 wcFrame.hbrBackground = 0;
3570 wcFrame.lpszMenuName = 0;
3571 wcFrame.lpszClassName = WINEFILEFRAME;
3572 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3573 MAKEINTRESOURCE(IDI_WINEFILE),
3575 GetSystemMetrics(SM_CXSMICON),
3576 GetSystemMetrics(SM_CYSMICON),
3579 Globals.hframeClass = RegisterClassEx(&wcFrame);
3582 /* register tree windows class */
3584 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3585 wcChild.lpfnWndProc = ChildWndProc;
3586 wcChild.cbClsExtra = 0;
3587 wcChild.cbWndExtra = 0;
3588 wcChild.hInstance = hinstance;
3590 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3591 wcChild.hbrBackground = 0;
3592 wcChild.lpszMenuName = 0;
3593 wcChild.lpszClassName = WINEFILETREE;
3595 hChildClass = RegisterClass(&wcChild);
3598 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3600 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"));
3604 Globals.hInstance = hinstance;
3606 #ifdef _SHELL_FOLDERS
3608 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3609 SHGetDesktopFolder(&Globals.iDesktop);
3610 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3615 void show_frame(HWND hwndParent, int cmdshow)
3617 TCHAR path[MAX_PATH];
3619 HMENU hMenuFrame, hMenuWindow;
3621 CLIENTCREATESTRUCT ccs;
3623 if (Globals.hMainWnd)
3626 Globals.hwndParent = hwndParent;
3628 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3629 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3631 Globals.hMenuFrame = hMenuFrame;
3632 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3633 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3635 ccs.hWindowMenu = hMenuWindow;
3636 ccs.idFirstChild = IDW_FIRST_CHILD;
3639 /* create main window */
3640 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3641 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3642 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3645 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3646 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3648 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3652 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3656 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3657 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3658 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3659 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3661 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3663 drivebarBtn.fsStyle = BTNS_BUTTON;
3665 #ifndef _NO_EXTENSIONS
3667 /* insert unix file system button */
3668 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3670 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3671 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3672 drivebarBtn.iString++;
3674 #ifdef _SHELL_FOLDERS
3675 /* insert shell namespace button */
3676 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3678 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3679 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3680 drivebarBtn.iString++;
3683 /* register windows drive root strings */
3684 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3687 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3689 for(p=Globals.drives; *p; ) {
3690 #ifdef _NO_EXTENSIONS
3691 /* insert drive letter */
3692 TCHAR b[3] = {tolower(*p)};
3693 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3695 switch(GetDriveType(p)) {
3696 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3697 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3698 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3699 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3700 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3703 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3704 drivebarBtn.idCommand++;
3705 drivebarBtn.iString++;
3712 TBBUTTON toolbarBtns[] = {
3713 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3714 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3715 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3716 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3717 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3719 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3720 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3723 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3724 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3725 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3726 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3729 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3730 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3732 /* CreateStatusWindow does not accept WS_BORDER
3733 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3734 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3735 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3737 /*TODO: read paths and window placements from registry */
3738 GetCurrentDirectory(MAX_PATH, path);
3740 ShowWindow(Globals.hMainWnd, cmdshow);
3742 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3743 /* Shell Namespace as default: */
3744 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3746 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3749 child->pos.showCmd = SW_SHOWMAXIMIZED;
3750 child->pos.rcNormalPosition.left = 0;
3751 child->pos.rcNormalPosition.top = 0;
3752 child->pos.rcNormalPosition.right = 320;
3753 child->pos.rcNormalPosition.bottom = 280;
3755 if (!create_child_window(child))
3758 SetWindowPlacement(child->hwnd, &child->pos);
3760 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3762 Globals.prescan_node = FALSE;
3764 UpdateWindow(Globals.hMainWnd);
3769 #ifdef _SHELL_FOLDERS
3770 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3771 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3775 ImageList_Destroy(Globals.himl);
3779 /* search for already running win[e]files */
3781 static int g_foundPrevInstance = 0;
3783 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3787 GetClassName(hwnd, cls, 128);
3789 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3790 g_foundPrevInstance++;
3797 /* search for window of given class name to allow only one running instance */
3798 int find_window_class(LPCTSTR classname)
3800 EnumWindows(EnumWndProc, (LPARAM)classname);
3802 if (g_foundPrevInstance)
3809 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3813 InitInstance(hinstance);
3815 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3816 if (cmdshow == SW_SHOWNORMAL)
3817 /*TODO: read window placement from registry */
3818 cmdshow = SW_MAXIMIZE;
3821 show_frame(hwndParent, cmdshow);
3823 while(GetMessage(&msg, 0, 0, 0)) {
3824 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3827 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3830 TranslateMessage(&msg);
3831 DispatchMessage(&msg);
3842 int APIENTRY WinMain(HINSTANCE hinstance,
3843 HINSTANCE previnstance,
3847 #ifdef _NO_EXTENSIONS
3848 if (find_window_class(WINEFILEFRAME))
3852 winefile_main(hinstance, 0, cmdshow);