4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
28 #include <sys/types.h>
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #define UNION_MEMBER(x) x
57 #define DEFAULT_SPLIT_POS 300
59 #define DEFAULT_SPLIT_POS 200
62 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
69 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
79 typedef struct _Entry {
90 #ifndef _NO_EXTENSIONS
91 BY_HANDLE_FILE_INFORMATION bhfi;
93 enum ENTRY_TYPE etype;
104 TCHAR path[MAX_PATH];
105 TCHAR volname[_MAX_FNAME];
115 COL_ATTRIBUTES = 0x08,
117 #ifdef _NO_EXTENSIONS
118 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
122 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
135 #ifndef _NO_EXTENSIONS
139 #ifndef _NO_EXTENSIONS
145 int positions[COLUMNS+1];
157 int focus_pane; /* 0: left 1: right */
160 BOOL header_wdths_ok;
162 TCHAR path[MAX_PATH];
163 TCHAR filter_pattern[MAX_PATH];
167 SORT_ORDER sortOrder;
172 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
173 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
174 static void refresh_child(ChildWnd* child);
175 static void refresh_drives(void);
176 static void get_path(Entry* dir, PTSTR path);
177 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
179 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
181 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
185 WINEFILE_GLOBALS Globals;
187 static int last_split;
189 /* some common string constants */
190 static const TCHAR sEmpty[] = {'\0'};
191 static const WCHAR sSpace[] = {' ', '\0'};
192 static const TCHAR sNumFmt[] = {'%','d','\0'};
193 static const TCHAR sQMarks[] = {'?','?','?','\0'};
195 /* window class names */
196 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
197 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
200 /* #define LONGLONGARG _T("I64") */
201 static const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
202 static const TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
204 /* #define LONGLONGARG _T("L") */
205 static const TCHAR sLongHexFmt[] = {'%','L','X','\0'};
206 static const TCHAR sLongNumFmt[] = {'%','L','d','\0'};
210 /* load resource string */
211 static LPTSTR load_string(LPTSTR buffer, UINT id)
213 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
218 #define RS(b, i) load_string(b, i)
221 /* display error message for the specified WIN32 error code */
222 static void display_error(HWND hwnd, DWORD error)
224 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
227 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
228 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
229 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
231 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
237 /* display network error message using WNetGetLastError() */
238 static void display_network_error(HWND hwnd)
240 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
243 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
244 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
247 static inline BOOL get_check(HWND hwnd, INT id)
249 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
252 static inline INT set_check(HWND hwnd, INT id, BOOL on)
254 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
257 static inline void choose_font(HWND hwnd)
259 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
263 HDC hdc = GetDC(hwnd);
264 chFont.lStructSize = sizeof(CHOOSEFONT);
265 chFont.hwndOwner = hwnd;
267 chFont.lpLogFont = &lFont;
268 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
269 chFont.rgbColors = RGB(0,0,0);
270 chFont.lCustData = 0;
271 chFont.lpfnHook = NULL;
272 chFont.lpTemplateName = NULL;
273 chFont.hInstance = Globals.hInstance;
274 chFont.lpszStyle = NULL;
275 chFont.nFontType = SIMULATED_FONTTYPE;
277 chFont.nSizeMax = 24;
279 if (ChooseFontW(&chFont)) {
283 DeleteObject(Globals.hfont);
284 Globals.hfont = CreateFontIndirectW(&lFont);
285 hFontOld = SelectObject(hdc, Globals.hfont);
286 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
288 /* change font in all open child windows */
289 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
290 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
291 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
292 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
293 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
294 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
295 InvalidateRect(child->left.hwnd, NULL, TRUE);
296 InvalidateRect(child->right.hwnd, NULL, TRUE);
299 SelectObject(hdc, hFontOld);
301 else if (CommDlgExtendedError()) {
302 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
303 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
304 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
307 ReleaseDC(hwnd, hdc);
314 /* call vswprintf() in msvcrt.dll */
315 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
316 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
318 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
323 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
324 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
328 ret = (*pvswprintf)(buffer, fmt, ap);
334 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
349 #define _tcsrchr my_wcsrchr
351 #define _tcsrchr strrchr
354 #endif /* __WINE__ */
357 /* allocate and initialise a directory entry */
358 static Entry* alloc_entry(void)
360 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
362 #ifdef _SHELL_FOLDERS
364 entry->folder = NULL;
371 /* free a directory entry */
372 static void free_entry(Entry* entry)
374 #ifdef _SHELL_FOLDERS
375 if (entry->hicon && entry->hicon!=(HICON)-1)
376 DestroyIcon(entry->hicon);
378 if (entry->folder && entry->folder!=Globals.iDesktop)
379 IShellFolder_Release(entry->folder);
382 IMalloc_Free(Globals.iMalloc, entry->pidl);
385 HeapFree(GetProcessHeap(), 0, entry);
388 /* recursively free all child entries */
389 static void free_entries(Entry* dir)
391 Entry *entry, *next=dir->down;
407 static void read_directory_win(Entry* dir, LPCTSTR path)
409 Entry* first_entry = NULL;
413 int level = dir->level + 1;
414 WIN32_FIND_DATA w32fd;
416 #ifndef _NO_EXTENSIONS
420 TCHAR buffer[MAX_PATH], *p;
421 for(p=buffer; *path; )
428 hFind = FindFirstFile(buffer, &w32fd);
430 if (hFind != INVALID_HANDLE_VALUE) {
432 #ifdef _NO_EXTENSIONS
433 /* hide directory entry "." */
434 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
435 LPCTSTR name = w32fd.cFileName;
437 if (name[0]=='.' && name[1]=='\0')
441 entry = alloc_entry();
449 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
452 entry->expanded = FALSE;
453 entry->scanned = FALSE;
454 entry->level = level;
456 #ifndef _NO_EXTENSIONS
457 entry->etype = ET_WINDOWS;
458 entry->bhfi_valid = FALSE;
460 lstrcpy(p, entry->data.cFileName);
462 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
463 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
465 if (hFile != INVALID_HANDLE_VALUE) {
466 if (GetFileInformationByHandle(hFile, &entry->bhfi))
467 entry->bhfi_valid = TRUE;
474 } while(FindNextFile(hFind, &w32fd));
482 dir->down = first_entry;
487 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
491 for(entry=dir->down; entry; entry=entry->next) {
493 LPCTSTR q = entry->data.cFileName;
496 if (!*p || *p == '\\' || *p == '/')
498 } while(tolower(*p++) == tolower(*q++));
501 q = entry->data.cAlternateFileName;
504 if (!*p || *p == '\\' || *p == '/')
506 } while(tolower(*p++) == tolower(*q++));
513 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
515 TCHAR buffer[MAX_PATH];
516 Entry* entry = &root->entry;
520 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
522 #ifndef _NO_EXTENSIONS
523 entry->etype = ET_WINDOWS;
527 while(*s && *s != '\\' && *s != '/')
530 while(*s == '\\' || *s == '/')
536 read_directory(entry, buffer, sortOrder, hwnd);
539 entry->expanded = TRUE;
544 entry = find_entry_win(entry, s);
547 SetCursor(old_cursor);
553 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
555 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
557 struct tm* tm = gmtime(t);
563 stime.wYear = tm->tm_year+1900;
564 stime.wMonth = tm->tm_mon+1;
565 /* stime.wDayOfWeek */
566 stime.wDay = tm->tm_mday;
567 stime.wHour = tm->tm_hour;
568 stime.wMinute = tm->tm_min;
569 stime.wSecond = tm->tm_sec;
571 return SystemTimeToFileTime(&stime, ftime);
574 static void read_directory_unix(Entry* dir, LPCTSTR path)
576 Entry* first_entry = NULL;
581 int level = dir->level + 1;
583 char cpath[MAX_PATH];
585 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
587 const char* cpath = path;
590 pdir = opendir(cpath);
595 char buffer[MAX_PATH], *p;
598 for(p=buffer,s=cpath; *s; )
601 if (p==buffer || p[-1]!='/')
604 while((ent=readdir(pdir))) {
605 entry = alloc_entry();
613 entry->etype = ET_UNIX;
615 strcpy(p, ent->d_name);
617 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
619 lstrcpy(entry->data.cFileName, p);
622 if (!stat(buffer, &st)) {
623 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
625 if (S_ISDIR(st.st_mode))
626 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
628 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
629 entry->data.nFileSizeHigh = st.st_size >> 32;
631 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
632 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
633 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
635 entry->bhfi.nFileIndexLow = ent->d_ino;
636 entry->bhfi.nFileIndexHigh = 0;
638 entry->bhfi.nNumberOfLinks = st.st_nlink;
640 entry->bhfi_valid = TRUE;
642 entry->data.nFileSizeLow = 0;
643 entry->data.nFileSizeHigh = 0;
644 entry->bhfi_valid = FALSE;
649 entry->expanded = FALSE;
650 entry->scanned = FALSE;
651 entry->level = level;
662 dir->down = first_entry;
666 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
670 for(entry=dir->down; entry; entry=entry->next) {
672 LPCTSTR q = entry->data.cFileName;
675 if (!*p || *p == '/')
677 } while(*p++ == *q++);
683 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
685 TCHAR buffer[MAX_PATH];
686 Entry* entry = &root->entry;
690 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
692 entry->etype = ET_UNIX;
695 while(*s && *s != '/')
704 read_directory(entry, buffer, sortOrder, hwnd);
707 entry->expanded = TRUE;
712 entry = find_entry_unix(entry, s);
715 SetCursor(old_cursor);
720 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
723 #ifdef _SHELL_FOLDERS
726 #define get_strret get_strretW
727 #define path_from_pidl path_from_pidlW
729 #define get_strret get_strretA
730 #define path_from_pidl path_from_pidlA
734 static void free_strret(STRRET* str)
736 if (str->uType == STRRET_WSTR)
737 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
743 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
748 for(s=source; count&&(*d++=*s++); )
754 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
758 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
762 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
766 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
770 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
774 /* SHGDN_FORPARSING: get full path of id list */
775 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
778 get_strretA(&str, &pidl->mkid, buffer, len);
788 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
793 for(s=source; count&&(*d++=*s++); )
799 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
803 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
807 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
811 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
816 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
820 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
823 get_strret(&str, &pidl->mkid, buffer, len);
832 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
836 /* SHGDN_FORPARSING: get full path of id list */
837 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
840 get_strretW(&str, &pidl->mkid, buffer, len);
849 /* create an item id list from a file system path */
851 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
858 LPWSTR buffer = path;
860 WCHAR buffer[MAX_PATH];
861 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
864 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
872 /* convert an item id list from relative to absolute (=relative to the desktop) format */
874 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
876 if (entry->up && entry->up->etype==ET_SHELL) {
877 IShellFolder* folder = entry->up->folder;
878 WCHAR buffer[MAX_PATH];
880 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
886 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
891 } else if (entry->etype == ET_WINDOWS) {
892 TCHAR path[MAX_PATH];
894 get_path(entry, path);
896 return get_path_pidl(path, hwnd);
897 } else if (entry->pidl)
898 return ILClone(entry->pidl);
904 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
906 IExtractIcon* pExtract;
908 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
909 TCHAR path[_MAX_PATH];
914 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
915 if (!(flags & GIL_NOTFILENAME)) {
917 idx = 0; /* special case for some control panel applications */
919 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
920 flags &= ~GIL_DONTCACHE;
922 HICON hIconLarge = 0;
924 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
927 DestroyIcon(hIconLarge);
938 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
942 for(entry=dir->down; entry; entry=entry->next) {
943 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
944 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
951 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
953 Entry* entry = &root->entry;
955 LPITEMIDLIST next_pidl = pidl;
956 IShellFolder* folder;
957 IShellFolder* child = NULL;
960 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
962 #ifndef _NO_EXTENSIONS
963 entry->etype = ET_SHELL;
966 folder = Globals.iDesktop;
969 entry->pidl = next_pidl;
970 entry->folder = folder;
975 /* copy first element of item idlist */
976 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
977 memcpy(next_pidl, pidl, pidl->mkid.cb);
978 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
980 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
984 read_directory(entry, NULL, sortOrder, hwnd);
987 entry->expanded = TRUE;
989 next = find_entry_shell(entry, next_pidl);
996 /* go to next element */
997 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
1000 SetCursor(old_cursor);
1006 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
1008 if (!(attribs & SFGAO_FILESYSTEM) ||
1009 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
1010 WIN32_FILE_ATTRIBUTE_DATA fad;
1011 IDataObject* pDataObj;
1013 STGMEDIUM medium = {0, {0}, 0};
1014 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
1016 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
1018 if (SUCCEEDED(hr)) {
1019 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
1021 IDataObject_Release(pDataObj);
1023 if (SUCCEEDED(hr)) {
1024 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
1025 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
1027 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
1028 w32fdata->dwFileAttributes = fad.dwFileAttributes;
1029 w32fdata->ftCreationTime = fad.ftCreationTime;
1030 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
1031 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
1033 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1034 w32fdata->nFileSizeLow = fad.nFileSizeLow;
1035 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
1039 SetErrorMode(sem_org);
1041 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
1042 GlobalFree(medium.UNION_MEMBER(hGlobal));
1047 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
1048 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1050 if (attribs & SFGAO_READONLY)
1051 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
1053 if (attribs & SFGAO_COMPRESSED)
1054 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
1058 static void read_directory_shell(Entry* dir, HWND hwnd)
1060 IShellFolder* folder = dir->folder;
1061 int level = dir->level + 1;
1064 IShellFolder* child;
1065 IEnumIDList* idlist;
1067 Entry* first_entry = NULL;
1074 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1076 if (SUCCEEDED(hr)) {
1078 #define FETCH_ITEM_COUNT 32
1079 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1084 memset(pidls, 0, sizeof(pidls));
1086 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1093 for(n=0; n<cnt; ++n) {
1094 entry = alloc_entry();
1097 first_entry = entry;
1102 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1103 entry->bhfi_valid = FALSE;
1105 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1107 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1109 if (SUCCEEDED(hr)) {
1110 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1111 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1113 entry->bhfi_valid = TRUE;
1119 entry->pidl = pidls[n];
1121 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1122 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1125 entry->folder = child;
1127 entry->folder = NULL;
1130 entry->folder = NULL;
1132 if (!entry->data.cFileName[0])
1133 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1135 /* get display icons for files and virtual objects */
1136 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1137 !(attribs & SFGAO_FILESYSTEM)) {
1138 entry->hicon = extract_icon(folder, pidls[n]);
1141 entry->hicon = (HICON)-1; /* don't try again later */
1146 entry->expanded = FALSE;
1147 entry->scanned = FALSE;
1148 entry->level = level;
1150 #ifndef _NO_EXTENSIONS
1151 entry->etype = ET_SHELL;
1152 entry->bhfi_valid = FALSE;
1159 IEnumIDList_Release(idlist);
1165 dir->down = first_entry;
1166 dir->scanned = TRUE;
1169 #endif /* _SHELL_FOLDERS */
1172 /* sort order for different directory/file types */
1181 /* distinguish between ".", ".." and any other directory names */
1182 static int TypeOrderFromDirname(LPCTSTR name)
1184 if (name[0] == '.') {
1185 if (name[1] == '\0')
1186 return TO_DOT; /* "." */
1188 if (name[1]=='.' && name[2]=='\0')
1189 return TO_DOTDOT; /* ".." */
1192 return TO_OTHER_DIR; /* anything else */
1195 /* directories first... */
1196 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1198 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1199 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1201 /* Handle "." and ".." as special case and move them at the very first beginning. */
1202 if (order1==TO_DIR && order2==TO_DIR) {
1203 order1 = TypeOrderFromDirname(fd1->cFileName);
1204 order2 = TypeOrderFromDirname(fd2->cFileName);
1207 return order2==order1? 0: order1<order2? -1: 1;
1211 static int compareName(const void* arg1, const void* arg2)
1213 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1214 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1216 int cmp = compareType(fd1, fd2);
1220 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1223 static int compareExt(const void* arg1, const void* arg2)
1225 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1226 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1227 const TCHAR *name1, *name2, *ext1, *ext2;
1229 int cmp = compareType(fd1, fd2);
1233 name1 = fd1->cFileName;
1234 name2 = fd2->cFileName;
1236 ext1 = _tcsrchr(name1, '.');
1237 ext2 = _tcsrchr(name2, '.');
1249 cmp = lstrcmpi(ext1, ext2);
1253 return lstrcmpi(name1, name2);
1256 static int compareSize(const void* arg1, const void* arg2)
1258 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1259 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1261 int cmp = compareType(fd1, fd2);
1265 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1272 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1274 return cmp<0? -1: cmp>0? 1: 0;
1277 static int compareDate(const void* arg1, const void* arg2)
1279 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1280 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1282 int cmp = compareType(fd1, fd2);
1286 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1290 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1291 compareName, /* SORT_NAME */
1292 compareExt, /* SORT_EXT */
1293 compareSize, /* SORT_SIZE */
1294 compareDate /* SORT_DATE */
1298 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1300 Entry* entry = dir->down;
1305 for(entry=dir->down; entry; entry=entry->next)
1309 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1312 for(entry=dir->down; entry; entry=entry->next)
1315 /* call qsort with the appropriate compare function */
1316 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1318 dir->down = array[0];
1320 for(p=array; --len; p++)
1325 HeapFree(GetProcessHeap(), 0, array);
1330 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1332 TCHAR buffer[MAX_PATH];
1337 #ifdef _SHELL_FOLDERS
1338 if (dir->etype == ET_SHELL)
1340 read_directory_shell(dir, hwnd);
1342 if (Globals.prescan_node) {
1351 for(entry=dir->down; entry; entry=entry->next)
1352 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1353 read_directory_shell(entry, hwnd);
1354 SortDirectory(entry, sortOrder);
1360 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1361 if (dir->etype == ET_UNIX)
1363 read_directory_unix(dir, path);
1365 if (Globals.prescan_node) {
1374 for(entry=dir->down; entry; entry=entry->next)
1375 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1376 lstrcpy(d, entry->data.cFileName);
1377 read_directory_unix(entry, buffer);
1378 SortDirectory(entry, sortOrder);
1385 read_directory_win(dir, path);
1387 if (Globals.prescan_node) {
1396 for(entry=dir->down; entry; entry=entry->next)
1397 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1398 lstrcpy(d, entry->data.cFileName);
1399 read_directory_win(entry, buffer);
1400 SortDirectory(entry, sortOrder);
1405 SortDirectory(dir, sortOrder);
1409 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1411 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1412 static const TCHAR sSlash[] = {'/', '\0'};
1414 static const TCHAR sBackslash[] = {'\\', '\0'};
1416 #ifdef _SHELL_FOLDERS
1419 /* read shell namespace tree */
1420 root->drive_type = DRIVE_UNKNOWN;
1423 load_string(root->volname, IDS_DESKTOP);
1425 load_string(root->fs, IDS_SHELL);
1427 return read_tree_shell(root, pidl, sortOrder, hwnd);
1431 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1434 /* read unix file system tree */
1435 root->drive_type = GetDriveType(path);
1437 lstrcat(drv, sSlash);
1438 load_string(root->volname, IDS_ROOT_FS);
1440 load_string(root->fs, IDS_UNIXFS);
1442 lstrcpy(root->path, sSlash);
1444 return read_tree_unix(root, path, sortOrder, hwnd);
1448 /* read WIN32 file system tree */
1449 root->drive_type = GetDriveType(path);
1451 lstrcat(drv, sBackslash);
1452 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1454 lstrcpy(root->path, drv);
1456 return read_tree_win(root, path, sortOrder, hwnd);
1460 /* flags to filter different file types */
1462 TF_DIRECTORIES = 0x01,
1464 TF_DOCUMENTS = 0x04,
1471 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1473 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1474 TCHAR dir_path[MAX_PATH];
1475 TCHAR b1[BUFFER_LEN];
1476 static const TCHAR sAsterics[] = {'*', '\0'};
1478 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1479 Root* root = &child->root;
1482 memset(child, 0, sizeof(ChildWnd));
1484 child->left.treePane = TRUE;
1485 child->left.visible_cols = 0;
1487 child->right.treePane = FALSE;
1488 #ifndef _NO_EXTENSIONS
1489 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1491 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1494 child->pos.length = sizeof(WINDOWPLACEMENT);
1495 child->pos.flags = 0;
1496 child->pos.showCmd = SW_SHOWNORMAL;
1497 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1498 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1499 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1500 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1502 child->focus_pane = 0;
1503 child->split_pos = DEFAULT_SPLIT_POS;
1504 child->sortOrder = SORT_NAME;
1505 child->header_wdths_ok = FALSE;
1509 lstrcpy(child->path, path);
1511 _tsplitpath(path, drv, dir, name, ext);
1514 lstrcpy(child->filter_pattern, sAsterics);
1515 child->filter_flags = TF_ALL;
1517 root->entry.level = 0;
1519 lstrcpy(dir_path, drv);
1520 lstrcat(dir_path, dir);
1521 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1523 #ifdef _SHELL_FOLDERS
1524 if (root->entry.etype == ET_SHELL)
1525 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1528 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1530 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1532 child->left.root = &root->entry;
1533 child->right.root = NULL;
1535 set_curdir(child, entry, 0, hwnd);
1541 /* free all memory associated with a child window */
1542 static void free_child_window(ChildWnd* child)
1544 free_entries(&child->root.entry);
1545 HeapFree(GetProcessHeap(), 0, child);
1549 /* get full path of specified directory entry */
1550 static void get_path(Entry* dir, PTSTR path)
1556 #ifdef _SHELL_FOLDERS
1557 if (dir->etype == ET_SHELL)
1567 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1569 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1570 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1572 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1578 for(entry=dir; entry; level++) {
1584 name = entry->data.cFileName;
1587 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1593 memmove(path+l+1, path, len*sizeof(TCHAR));
1594 memcpy(path+1, name, l*sizeof(TCHAR));
1597 #ifndef _NO_EXTENSIONS
1598 if (entry->etype == ET_UNIX)
1607 memmove(path+l, path, len*sizeof(TCHAR));
1608 memcpy(path, name, l*sizeof(TCHAR));
1615 #ifndef _NO_EXTENSIONS
1616 if (entry->etype == ET_UNIX)
1627 static windowOptions load_registry_settings(void)
1635 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1636 0, KEY_QUERY_VALUE, &hKey );
1638 size = sizeof(DWORD);
1640 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1641 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1642 opts.start_x = CW_USEDEFAULT;
1644 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1645 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1646 opts.start_y = CW_USEDEFAULT;
1648 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1649 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1650 opts.width = CW_USEDEFAULT;
1652 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1653 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1654 opts.height = CW_USEDEFAULT;
1655 size=sizeof(logfont);
1656 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1657 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1658 GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1660 RegCloseKey( hKey );
1662 Globals.hfont = CreateFontIndirect(&logfont);
1666 static void save_registry_settings(void)
1673 wi.cbSize = sizeof( WINDOWINFO );
1674 GetWindowInfo(Globals.hMainWnd, &wi);
1675 width = wi.rcWindow.right - wi.rcWindow.left;
1676 height = wi.rcWindow.bottom - wi.rcWindow.top;
1678 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1679 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1681 /* Unable to save registry settings - try to create key */
1682 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1683 0, NULL, REG_OPTION_NON_VOLATILE,
1684 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1686 /* FIXME: Cannot create key */
1690 /* Save all of the settings */
1691 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1692 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1693 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1694 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1695 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1696 (LPBYTE) &width, sizeof(DWORD) );
1697 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1698 (LPBYTE) &height, sizeof(DWORD) );
1699 GetObject(Globals.hfont, sizeof(logfont), &logfont);
1700 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1701 (LPBYTE) &logfont, sizeof(LOGFONT) );
1703 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1704 RegCloseKey( hKey );
1707 static void resize_frame_rect(HWND hwnd, PRECT prect)
1712 if (IsWindowVisible(Globals.htoolbar)) {
1713 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1714 GetClientRect(Globals.htoolbar, &rt);
1715 prect->top = rt.bottom+3;
1716 prect->bottom -= rt.bottom+3;
1719 if (IsWindowVisible(Globals.hdrivebar)) {
1720 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1721 GetClientRect(Globals.hdrivebar, &rt);
1722 new_top = --prect->top + rt.bottom+3;
1723 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1724 prect->top = new_top;
1725 prect->bottom -= rt.bottom+2;
1728 if (IsWindowVisible(Globals.hstatusbar)) {
1729 int parts[] = {300, 500};
1731 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1732 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1733 GetClientRect(Globals.hstatusbar, &rt);
1734 prect->bottom -= rt.bottom;
1737 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1740 static void resize_frame(HWND hwnd, int cx, int cy)
1749 resize_frame_rect(hwnd, &rect);
1752 static void resize_frame_client(HWND hwnd)
1756 GetClientRect(hwnd, &rect);
1758 resize_frame_rect(hwnd, &rect);
1762 static HHOOK hcbthook;
1763 static ChildWnd* newchild = NULL;
1765 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1767 if (code==HCBT_CREATEWND && newchild) {
1768 ChildWnd* child = newchild;
1771 child->hwnd = (HWND) wparam;
1772 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1775 return CallNextHookEx(hcbthook, code, wparam, lparam);
1778 static HWND create_child_window(ChildWnd* child)
1780 MDICREATESTRUCT mcs;
1783 mcs.szClass = sWINEFILETREE;
1784 mcs.szTitle = (LPTSTR)child->path;
1785 mcs.hOwner = Globals.hInstance;
1786 mcs.x = child->pos.rcNormalPosition.left;
1787 mcs.y = child->pos.rcNormalPosition.top;
1788 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1789 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1793 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1796 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1798 UnhookWindowsHookEx(hcbthook);
1802 UnhookWindowsHookEx(hcbthook);
1804 SendMessage(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1805 SendMessage(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1807 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1808 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
1814 struct ExecuteDialog {
1815 TCHAR cmd[MAX_PATH];
1819 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1821 static struct ExecuteDialog* dlg;
1825 dlg = (struct ExecuteDialog*) lparam;
1829 int id = (int)wparam;
1832 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1833 dlg->cmdshow = get_check(hwnd,214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL;
1834 EndDialog(hwnd, id);
1835 } else if (id == IDCANCEL)
1836 EndDialog(hwnd, id);
1845 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1847 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1851 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1852 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1856 int id = (int)wparam;
1860 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1861 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1862 EndDialog(hwnd, id);
1866 EndDialog(hwnd, id);
1870 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1882 struct FilterDialog {
1883 TCHAR pattern[MAX_PATH];
1887 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1889 static struct FilterDialog* dlg;
1893 dlg = (struct FilterDialog*) lparam;
1894 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1895 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1896 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1897 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1898 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1899 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1903 int id = (int)wparam;
1908 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1910 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1911 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1912 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1913 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1914 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1918 EndDialog(hwnd, id);
1919 } else if (id == IDCANCEL)
1920 EndDialog(hwnd, id);
1929 struct PropertiesDialog {
1930 TCHAR path[MAX_PATH];
1935 /* Structure used to store enumerated languages and code pages. */
1936 struct LANGANDCODEPAGE {
1941 static LPCSTR InfoStrings[] = {
1957 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1959 int idx = SendMessage(hlbox, LB_GETCURSEL, 0, 0);
1961 if (idx != LB_ERR) {
1962 LPCTSTR pValue = (LPCTSTR) SendMessage(hlbox, LB_GETITEMDATA, idx, 0);
1965 SetWindowText(hedit, pValue);
1969 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1971 static TCHAR sBackSlash[] = {'\\','\0'};
1972 static TCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1973 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1974 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1975 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1977 if (dwVersionDataLen) {
1978 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1980 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1984 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1985 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1986 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1987 char buffer[BUFFER_LEN];
1989 sprintf(buffer, "%d.%d.%d.%d",
1990 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1991 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1993 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1997 /* Read the list of languages and code pages. */
1998 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1999 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
2000 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
2002 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2004 /* Read the file description for each language and code page. */
2005 for(; pTranslate<pEnd; ++pTranslate) {
2008 for(p=InfoStrings; *p; ++p) {
2009 TCHAR subblock[200];
2016 LPCSTR pInfoString = *p;
2018 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
2020 #define infoStr pInfoString
2022 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
2024 /* Retrieve file description for language and code page */
2025 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
2026 int idx = SendMessage(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
2027 SendMessage(hlbox, LB_SETITEMDATA, idx, (LPARAM) pTxt);
2032 SendMessage(hlbox, LB_SETCURSEL, 0, 0);
2034 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2040 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2042 static struct PropertiesDialog* dlg;
2045 case WM_INITDIALOG: {
2046 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
2047 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2048 LPWIN32_FIND_DATA pWFD;
2051 dlg = (struct PropertiesDialog*) lparam;
2052 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
2054 GetWindowText(hwnd, b1, MAX_PATH);
2055 wsprintf(b2, b1, pWFD->cFileName);
2056 SetWindowText(hwnd, b2);
2058 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
2059 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
2061 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
2062 _stprintf(b1, sLongNumFmt, size);
2063 wsprintf(b2, sByteFmt, b1);
2064 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
2066 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
2067 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
2069 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
2070 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
2071 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
2072 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
2073 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
2075 CheckForFileInfo(dlg, hwnd, dlg->path);
2079 int id = (int)wparam;
2081 switch(HIWORD(wparam)) {
2082 case LBN_SELCHANGE: {
2083 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2084 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2089 if (id==IDOK || id==IDCANCEL)
2090 EndDialog(hwnd, id);
2096 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
2097 dlg->pVersionData = NULL;
2104 static void show_properties_dlg(Entry* entry, HWND hwnd)
2106 struct PropertiesDialog dlg;
2108 memset(&dlg, 0, sizeof(struct PropertiesDialog));
2109 get_path(entry, dlg.path);
2110 memcpy(&dlg.entry, entry, sizeof(Entry));
2112 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
2116 #ifndef _NO_EXTENSIONS
2118 static struct FullScreenParameters {
2128 static void frame_get_clientspace(HWND hwnd, PRECT prect)
2132 if (!IsIconic(hwnd))
2133 GetClientRect(hwnd, prect);
2137 GetWindowPlacement(hwnd, &wp);
2139 prect->left = prect->top = 0;
2140 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
2141 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
2142 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
2143 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
2144 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2147 if (IsWindowVisible(Globals.htoolbar)) {
2148 GetClientRect(Globals.htoolbar, &rt);
2149 prect->top += rt.bottom+2;
2152 if (IsWindowVisible(Globals.hdrivebar)) {
2153 GetClientRect(Globals.hdrivebar, &rt);
2154 prect->top += rt.bottom+2;
2157 if (IsWindowVisible(Globals.hstatusbar)) {
2158 GetClientRect(Globals.hstatusbar, &rt);
2159 prect->bottom -= rt.bottom;
2163 static BOOL toggle_fullscreen(HWND hwnd)
2167 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2168 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2169 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2171 Frame_CalcFrameClient(hwnd, &rt);
2172 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2173 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2175 rt.left = g_fullscreen.orgPos.left-rt.left;
2176 rt.top = g_fullscreen.orgPos.top-rt.top;
2177 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2178 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2180 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2182 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2183 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2184 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2186 if (g_fullscreen.wasZoomed)
2187 ShowWindow(hwnd, WS_MAXIMIZE);
2190 return g_fullscreen.mode;
2193 static void fullscreen_move(HWND hwnd)
2196 GetWindowRect(hwnd, &pos);
2198 Frame_CalcFrameClient(hwnd, &rt);
2199 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2200 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2202 rt.left = pos.left-rt.left;
2203 rt.top = pos.top-rt.top;
2204 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2205 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2207 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2213 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2215 BOOL vis = IsWindowVisible(hchild);
2217 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2219 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2221 #ifndef _NO_EXTENSIONS
2222 if (g_fullscreen.mode)
2223 fullscreen_move(hwnd);
2226 resize_frame_client(hwnd);
2229 static BOOL activate_drive_window(LPCTSTR path)
2231 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2234 _tsplitpath(path, drv1, 0, 0, 0);
2236 /* search for a already open window for the same drive */
2237 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2238 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2241 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2243 if (!lstrcmpi(drv2, drv1)) {
2244 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2246 if (IsIconic(child_wnd))
2247 ShowWindow(child_wnd, SW_SHOWNORMAL);
2257 static BOOL activate_fs_window(LPCTSTR filesys)
2261 /* search for a already open window of the given file system name */
2262 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2263 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2266 if (!lstrcmpi(child->root.fs, filesys)) {
2267 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2269 if (IsIconic(child_wnd))
2270 ShowWindow(child_wnd, SW_SHOWNORMAL);
2280 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2282 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2286 if (Globals.saveSettings)
2287 save_registry_settings();
2289 DestroyWindow(hwnd);
2291 /* clear handle variables */
2292 Globals.hMenuFrame = 0;
2293 Globals.hMenuView = 0;
2294 Globals.hMenuOptions = 0;
2295 Globals.hMainWnd = 0;
2296 Globals.hmdiclient = 0;
2297 Globals.hdrivebar = 0;
2304 case WM_INITMENUPOPUP: {
2305 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2307 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2312 UINT cmd = LOWORD(wparam);
2313 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2315 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2318 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2319 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2321 LPCTSTR root = Globals.drives;
2324 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2328 if (activate_drive_window(root))
2331 _tsplitpath(root, drv, 0, 0, 0);
2333 if (!SetCurrentDirectory(drv)) {
2334 display_error(hwnd, GetLastError());
2338 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2339 child = alloc_child_window(path, NULL, hwnd);
2341 if (!create_child_window(child))
2342 HeapFree(GetProcessHeap(), 0, child);
2343 } else switch(cmd) {
2345 SendMessage(hwnd, WM_CLOSE, 0, 0);
2348 case ID_WINDOW_NEW: {
2349 TCHAR path[MAX_PATH];
2352 GetCurrentDirectory(MAX_PATH, path);
2353 child = alloc_child_window(path, NULL, hwnd);
2355 if (!create_child_window(child))
2356 HeapFree(GetProcessHeap(), 0, child);
2363 case ID_WINDOW_CASCADE:
2364 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2367 case ID_WINDOW_TILE_HORZ:
2368 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2371 case ID_WINDOW_TILE_VERT:
2372 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2375 case ID_WINDOW_ARRANGE:
2376 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2379 case ID_SELECT_FONT:
2383 case ID_VIEW_TOOL_BAR:
2384 toggle_child(hwnd, cmd, Globals.htoolbar);
2387 case ID_VIEW_DRIVE_BAR:
2388 toggle_child(hwnd, cmd, Globals.hdrivebar);
2391 case ID_VIEW_STATUSBAR:
2392 toggle_child(hwnd, cmd, Globals.hstatusbar);
2395 case ID_VIEW_SAVESETTINGS:
2396 Globals.saveSettings = !Globals.saveSettings;
2397 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2398 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2402 struct ExecuteDialog dlg;
2404 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2406 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2407 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2409 if ((int)hinst <= 32)
2410 display_error(hwnd, GetLastError());
2414 case ID_CONNECT_NETWORK_DRIVE: {
2415 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2416 if (ret == NO_ERROR)
2418 else if (ret != (DWORD)-1) {
2419 if (ret == ERROR_EXTENDED_ERROR)
2420 display_network_error(hwnd);
2422 display_error(hwnd, ret);
2426 case ID_DISCONNECT_NETWORK_DRIVE: {
2427 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2428 if (ret == NO_ERROR)
2430 else if (ret != (DWORD)-1) {
2431 if (ret == ERROR_EXTENDED_ERROR)
2432 display_network_error(hwnd);
2434 display_error(hwnd, ret);
2438 case ID_FORMAT_DISK: {
2439 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2440 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2441 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2442 SetErrorMode(sem_org); /* Put it back the way it was. */
2446 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2449 #ifndef _NO_EXTENSIONS
2450 case ID_VIEW_FULLSCREEN:
2451 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2455 case ID_DRIVE_UNIX_FS: {
2456 TCHAR path[MAX_PATH];
2458 char cpath[MAX_PATH];
2462 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2466 getcwd(cpath, MAX_PATH);
2467 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2469 getcwd(path, MAX_PATH);
2471 child = alloc_child_window(path, NULL, hwnd);
2473 if (!create_child_window(child))
2474 HeapFree(GetProcessHeap(), 0, child);
2477 #ifdef _SHELL_FOLDERS
2478 case ID_DRIVE_SHELL_NS: {
2479 TCHAR path[MAX_PATH];
2482 if (activate_fs_window(RS(b1,IDS_SHELL)))
2485 GetCurrentDirectory(MAX_PATH, path);
2486 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2488 if (!create_child_window(child))
2489 HeapFree(GetProcessHeap(), 0, child);
2494 /*TODO: There are even more menu items! */
2497 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL,
2498 LoadImage( Globals.hInstance, MAKEINTRESOURCE(IDI_WINEFILE),
2499 IMAGE_ICON, 48, 48, LR_SHARED ));
2503 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2504 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2505 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2506 (cmd<SC_SIZE || cmd>SC_RESTORE))
2507 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2509 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2514 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2515 break; /* do not pass message to DefFrameProc */
2517 case WM_DEVICECHANGE:
2518 SendMessage(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2521 #ifndef _NO_EXTENSIONS
2522 case WM_GETMINMAXINFO: {
2523 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2525 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2526 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2529 case FRM_CALC_CLIENT:
2530 frame_get_clientspace(hwnd, (PRECT)lparam);
2532 #endif /* _NO_EXTENSIONS */
2535 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2542 static TCHAR g_pos_names[COLUMNS][20] = {
2546 static const int g_pos_align[] = {
2548 HDF_LEFT, /* Name */
2549 HDF_RIGHT, /* Size */
2550 HDF_LEFT, /* CDate */
2551 #ifndef _NO_EXTENSIONS
2552 HDF_LEFT, /* ADate */
2553 HDF_LEFT, /* MDate */
2554 HDF_LEFT, /* Index */
2555 HDF_CENTER, /* Links */
2557 HDF_CENTER, /* Attributes */
2558 #ifndef _NO_EXTENSIONS
2559 HDF_LEFT /* Security */
2563 static void resize_tree(ChildWnd* child, int cx, int cy)
2565 HDWP hdwp = BeginDeferWindowPos(4);
2573 cx = child->split_pos + SPLIT_WIDTH/2;
2575 #ifndef _NO_EXTENSIONS
2583 SendMessage(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2585 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2586 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2587 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2588 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2590 #endif /* _NO_EXTENSIONS */
2592 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);
2593 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2595 EndDeferWindowPos(hdwp);
2599 #ifndef _NO_EXTENSIONS
2601 static HWND create_header(HWND parent, Pane* pane, int id)
2606 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2607 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2611 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2613 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2615 for(idx=0; idx<COLUMNS; idx++) {
2616 hdi.pszText = g_pos_names[idx];
2617 hdi.fmt = HDF_STRING | g_pos_align[idx];
2618 hdi.cxy = pane->widths[idx];
2619 SendMessage(hwnd, HDM_INSERTITEM, idx, (LPARAM) &hdi);
2625 #endif /* _NO_EXTENSIONS */
2628 static void init_output(HWND hwnd)
2630 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2633 HDC hdc = GetDC(hwnd);
2635 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2636 Globals.num_sep = b[1];
2638 Globals.num_sep = '.';
2640 old_font = SelectObject(hdc, Globals.hfont);
2641 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2642 SelectObject(hdc, old_font);
2643 ReleaseDC(hwnd, hdc);
2646 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2649 /* calculate preferred width for all visible columns */
2651 static BOOL calc_widths(Pane* pane, BOOL anyway)
2653 int col, x, cx, spc=3*Globals.spaceSize.cx;
2654 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2655 int orgWidths[COLUMNS];
2656 int orgPositions[COLUMNS+1];
2662 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2663 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2666 for(col=0; col<COLUMNS; col++)
2667 pane->widths[col] = 0;
2669 hdc = GetDC(pane->hwnd);
2670 hfontOld = SelectObject(hdc, Globals.hfont);
2672 for(cnt=0; cnt<entries; cnt++) {
2673 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2682 dis.hwndItem = pane->hwnd;
2684 dis.rcItem.left = 0;
2686 dis.rcItem.right = 0;
2687 dis.rcItem.bottom = 0;
2688 /*dis.itemData = 0; */
2690 draw_item(pane, &dis, entry, COLUMNS);
2693 SelectObject(hdc, hfontOld);
2694 ReleaseDC(pane->hwnd, hdc);
2697 for(col=0; col<COLUMNS; col++) {
2698 pane->positions[col] = x;
2699 cx = pane->widths[col];
2704 if (cx < IMAGE_WIDTH)
2707 pane->widths[col] = cx;
2713 pane->positions[COLUMNS] = x;
2715 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2718 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2721 /* don't move, if only collapsing an entry */
2722 if (!anyway && pane->widths[0]<orgWidths[0] &&
2723 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2724 pane->widths[0] = orgWidths[0];
2725 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2730 InvalidateRect(pane->hwnd, 0, TRUE);
2736 /* calculate one preferred column width */
2738 static void calc_single_width(Pane* pane, int col)
2742 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2746 pane->widths[col] = 0;
2748 hdc = GetDC(pane->hwnd);
2749 hfontOld = SelectObject(hdc, Globals.hfont);
2751 for(cnt=0; cnt<entries; cnt++) {
2752 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2760 dis.hwndItem = pane->hwnd;
2762 dis.rcItem.left = 0;
2764 dis.rcItem.right = 0;
2765 dis.rcItem.bottom = 0;
2766 /*dis.itemData = 0; */
2768 draw_item(pane, &dis, entry, col);
2771 SelectObject(hdc, hfontOld);
2772 ReleaseDC(pane->hwnd, hdc);
2774 cx = pane->widths[col];
2777 cx += 3*Globals.spaceSize.cx;
2779 if (cx < IMAGE_WIDTH)
2783 pane->widths[col] = cx;
2785 x = pane->positions[col] + cx;
2787 for(; col<COLUMNS; ) {
2788 pane->positions[++col] = x;
2789 x += pane->widths[col];
2792 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2796 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2798 for( ; *str&&*pattern; str++,pattern++) {
2799 if (*pattern == '*') {
2801 while(*pattern == '*');
2807 if (*str==*pattern && pattern_match(str, pattern))
2812 else if (*str!=*pattern && *pattern!='?')
2816 if (*str || *pattern)
2817 if (*pattern!='*' || pattern[1]!='\0')
2823 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2825 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2828 lstrcpy(b2, pattern);
2832 return pattern_match(b1, b2);
2842 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2845 /* insert listbox entries after index idx */
2847 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2854 ShowWindow(pane->hwnd, SW_HIDE);
2856 for(; entry; entry=entry->next) {
2858 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2862 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2863 /* don't display entries "." and ".." in the left pane */
2864 if (pane->treePane && entry->data.cFileName[0] == '.')
2866 #ifndef _NO_EXTENSIONS
2867 entry->data.cFileName[1] == '\0' ||
2869 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2872 /* filter directories in right pane */
2873 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2877 /* filter using the file name pattern */
2879 if (!pattern_imatch(entry->data.cFileName, pattern))
2882 /* filter system and hidden files */
2883 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2886 /* filter looking at the file type */
2887 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2888 switch(get_file_type(entry->data.cFileName)) {
2890 if (!(filter_flags & TF_PROGRAMS))
2895 if (!(filter_flags & TF_DOCUMENTS))
2899 default: /* TF_OTHERS */
2900 if (!(filter_flags & TF_OTHERS))
2907 SendMessage(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM) entry);
2909 if (pane->treePane && entry->expanded)
2910 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2913 ShowWindow(pane->hwnd, SW_SHOW);
2919 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2921 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2922 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2923 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2925 float fBytes = (float)bytes;
2927 if (bytes >= 1073741824) /* 1 GB */
2928 _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2929 else if (bytes >= 1048576) /* 1 MB */
2930 _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2931 else if (bytes >= 1024) /* 1 kB */
2932 _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2934 _stprintf(buffer, sLongNumFmt, bytes);
2937 static void set_space_status(void)
2939 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2940 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2942 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2943 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2944 format_bytes(b2, ulTotalBytes.QuadPart);
2945 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2947 lstrcpy(buffer, sQMarks);
2949 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2953 static WNDPROC g_orgTreeWndProc;
2955 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2957 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2959 static int s_init = 0;
2960 Entry* entry = pane->root;
2962 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2963 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2964 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2966 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2967 g_orgTreeWndProc = (WNDPROC) SetWindowLongPtr(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2969 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2971 /* insert entries into listbox */
2973 insert_entries(pane, entry, pattern, filter_flags, -1);
2975 /* calculate column widths */
2978 init_output(pane->hwnd);
2981 calc_widths(pane, TRUE);
2983 #ifndef _NO_EXTENSIONS
2984 pane->hwndHeader = create_header(parent, pane, id_header);
2989 static void InitChildWindow(ChildWnd* child)
2991 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2992 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2996 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
3004 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
3007 if (!FileTimeToLocalFileTime(ft, &lft))
3008 {err: lstrcpy(buffer,sQMarks); return;}
3010 if (!FileTimeToSystemTime(&lft, &systime))
3013 if (visible_cols & COL_DATE) {
3014 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
3019 if (visible_cols & COL_TIME) {
3021 buffer[len-1] = ' ';
3023 buffer[len++] = ' ';
3025 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
3031 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3033 RECT rt = {0, 0, 0, 0};
3035 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3037 if (rt.right > pane->widths[col])
3038 pane->widths[col] = rt.right;
3041 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3043 RECT rt = {0, 0, 0, 0};
3045 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3046 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3048 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3049 /*FIXME rt (0,0) ??? */
3051 if (rt.right > pane->widths[col])
3052 pane->widths[col] = rt.right;
3056 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
3058 int x = dis->rcItem.left;
3061 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3062 rt.top = dis->rcItem.top;
3063 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3064 rt.bottom = dis->rcItem.bottom;
3066 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
3069 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3071 int x = dis->rcItem.left;
3074 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3075 rt.top = dis->rcItem.top;
3076 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3077 rt.bottom = dis->rcItem.bottom;
3079 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3080 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3082 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3085 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3087 int x = dis->rcItem.left;
3094 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3095 rt.top = dis->rcItem.top;
3096 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3097 rt.bottom = dis->rcItem.bottom;
3102 /* insert number separator characters */
3103 pos = lstrlen(s) % 3;
3109 *d++ = Globals.num_sep;
3113 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3117 static BOOL is_exe_file(LPCTSTR ext)
3119 static const TCHAR executable_extensions[][4] = {
3124 #ifndef _NO_EXTENSIONS
3128 #endif /* _NO_EXTENSIONS */
3132 TCHAR ext_buffer[_MAX_EXT];
3133 const TCHAR (*p)[4];
3137 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3140 for(p=executable_extensions; (*p)[0]; p++)
3141 if (!lstrcmpi(ext_buffer, *p))
3147 static BOOL is_registered_type(LPCTSTR ext)
3149 /* check if there exists a classname for this file extension in the registry */
3150 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3156 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3158 LPCTSTR ext = _tcsrchr(filename, '.');
3162 if (is_exe_file(ext))
3163 return FT_EXECUTABLE;
3164 else if (is_registered_type(ext))
3171 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3173 TCHAR buffer[BUFFER_LEN];
3175 int visible_cols = pane->visible_cols;
3176 COLORREF bkcolor, textcolor;
3177 RECT focusRect = dis->rcItem;
3184 attrs = entry->data.dwFileAttributes;
3186 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3187 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3188 && entry->data.cFileName[2] == '\0')
3189 img = IMG_FOLDER_UP;
3190 #ifndef _NO_EXTENSIONS
3191 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3192 img = IMG_FOLDER_CUR;
3195 #ifdef _NO_EXTENSIONS
3198 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3199 img = IMG_OPEN_FOLDER;
3203 switch(get_file_type(entry->data.cFileName)) {
3204 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3205 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3206 default: img = IMG_FILE;
3214 if (pane->treePane) {
3216 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3218 if (calcWidthCol == -1) {
3220 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3223 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3226 rt_clip.left = dis->rcItem.left;
3227 rt_clip.top = dis->rcItem.top;
3228 rt_clip.right = dis->rcItem.left+pane->widths[col];
3229 rt_clip.bottom = dis->rcItem.bottom;
3231 hrgn = CreateRectRgnIndirect(&rt_clip);
3233 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3234 DeleteObject(hrgn_org);
3238 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3239 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3242 if ((up=entry->up) != NULL) {
3243 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3244 LineTo(dis->hDC, img_pos-2, y);
3246 x = img_pos - IMAGE_WIDTH/2;
3249 x -= IMAGE_WIDTH+TREE_LINE_DX;
3253 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3256 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3257 LineTo(dis->hDC, x, dis->rcItem.bottom);
3259 } while((up=up->up) != NULL);
3262 x = img_pos - IMAGE_WIDTH/2;
3264 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3265 LineTo(dis->hDC, x, y);
3269 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3272 LineTo(dis->hDC, x, dis->rcItem.bottom);
3274 SelectClipRgn(dis->hDC, hrgn_org);
3275 if (hrgn_org) DeleteObject(hrgn_org);
3276 /* SelectObject(dis->hDC, holdPen); */
3277 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3278 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3280 if (right > pane->widths[col])
3281 pane->widths[col] = right;
3284 img_pos = dis->rcItem.left;
3287 img_pos = dis->rcItem.left;
3289 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3290 pane->widths[col] = IMAGE_WIDTH;
3293 if (calcWidthCol == -1) {
3294 focusRect.left = img_pos -2;
3296 #ifdef _NO_EXTENSIONS
3297 if (pane->treePane && entry) {
3300 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3302 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3306 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3307 textcolor = COLOR_COMPRESSED;
3309 #endif /* _NO_EXTENSIONS */
3310 textcolor = RGB(0,0,0);
3312 if (dis->itemState & ODS_FOCUS) {
3313 textcolor = RGB(255,255,255);
3314 bkcolor = COLOR_SELECTION;
3316 bkcolor = RGB(255,255,255);
3319 hbrush = CreateSolidBrush(bkcolor);
3320 FillRect(dis->hDC, &focusRect, hbrush);
3321 DeleteObject(hbrush);
3323 SetBkMode(dis->hDC, TRANSPARENT);
3324 SetTextColor(dis->hDC, textcolor);
3326 cx = pane->widths[col];
3328 if (cx && img!=IMG_NONE) {
3329 if (cx > IMAGE_WIDTH)
3332 #ifdef _SHELL_FOLDERS
3333 if (entry->hicon && entry->hicon!=(HICON)-1)
3334 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3337 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3338 img_pos, dis->rcItem.top, cx,
3339 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3346 #ifdef _NO_EXTENSIONS
3347 if (img >= IMG_FOLDER_UP)
3353 /* ouput file name */
3354 if (calcWidthCol == -1)
3355 output_text(pane, dis, col, entry->data.cFileName, 0);
3356 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3357 calc_width(pane, dis, col, entry->data.cFileName);
3361 #ifdef _NO_EXTENSIONS
3362 if (!pane->treePane) {
3365 /* display file size */
3366 if (visible_cols & COL_SIZE) {
3367 #ifdef _NO_EXTENSIONS
3368 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3373 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3375 _stprintf(buffer, sLongNumFmt, size);
3377 if (calcWidthCol == -1)
3378 output_number(pane, dis, col, buffer);
3379 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3380 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3386 /* display file date */
3387 if (visible_cols & (COL_DATE|COL_TIME)) {
3388 #ifndef _NO_EXTENSIONS
3389 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3390 if (calcWidthCol == -1)
3391 output_text(pane, dis, col, buffer, 0);
3392 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3393 calc_width(pane, dis, col, buffer);
3396 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3397 if (calcWidthCol == -1)
3398 output_text(pane, dis, col, buffer, 0);
3399 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3400 calc_width(pane, dis, col, buffer);
3402 #endif /* _NO_EXTENSIONS */
3404 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3405 if (calcWidthCol == -1)
3406 output_text(pane, dis, col, buffer, 0);
3407 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3408 calc_width(pane, dis, col, buffer);
3412 #ifndef _NO_EXTENSIONS
3413 if (entry->bhfi_valid) {
3414 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3416 if (visible_cols & COL_INDEX) {
3417 _stprintf(buffer, sLongHexFmt, index);
3419 if (calcWidthCol == -1)
3420 output_text(pane, dis, col, buffer, DT_RIGHT);
3421 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3422 calc_width(pane, dis, col, buffer);
3427 if (visible_cols & COL_LINKS) {
3428 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3430 if (calcWidthCol == -1)
3431 output_text(pane, dis, col, buffer, DT_CENTER);
3432 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3433 calc_width(pane, dis, col, buffer);
3439 #endif /* _NO_EXTENSIONS */
3441 /* show file attributes */
3442 if (visible_cols & COL_ATTRIBUTES) {
3443 #ifdef _NO_EXTENSIONS
3444 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3445 lstrcpy(buffer, s4Tabs);
3447 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3448 lstrcpy(buffer, s11Tabs);
3451 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3453 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3454 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3455 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3456 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3457 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3458 #ifndef _NO_EXTENSIONS
3459 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3460 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3461 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3462 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3463 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3464 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3465 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3466 #endif /* _NO_EXTENSIONS */
3469 if (calcWidthCol == -1)
3470 output_tabbed_text(pane, dis, col, buffer);
3471 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3472 calc_tabbed_width(pane, dis, col, buffer);
3478 if (flags.security) {
3479 static const TCHAR sSecTabs[] = {
3480 ' ','\t',' ','\t',' ','\t',' ',
3482 ' ','\t',' ','\t',' ','\t',' ',
3484 ' ','\t',' ','\t',' ','\t',' ',
3488 DWORD rights = get_access_mask();
3490 lstrcpy(buffer, sSecTabs);
3492 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3493 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3494 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3495 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3496 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3497 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3498 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3499 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3500 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3501 if (rights & WRITE_DAC) buffer[22] = 'C';
3502 if (rights & WRITE_OWNER) buffer[24] = 'O';
3503 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3505 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3508 if (flags.description) {
3509 get_description(buffer);
3510 output_text(dis, col++, buffer, 0, psize);
3514 #ifdef _NO_EXTENSIONS
3517 /* draw focus frame */
3518 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3519 /* Currently [04/2000] Wine neither behaves exactly the same */
3520 /* way as WIN 95 nor like Windows NT... */
3525 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3526 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3527 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3529 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3531 lastPen = SelectPen(dis->hDC, hpen);
3532 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3533 SetROP2(dis->hDC, R2_XORPEN);
3534 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3535 SelectObject(dis->hDC, lastBrush);
3536 SelectObject(dis->hDC, lastPen);
3539 #endif /* _NO_EXTENSIONS */
3543 #ifdef _NO_EXTENSIONS
3545 static void draw_splitbar(HWND hwnd, int x)
3548 HDC hdc = GetDC(hwnd);
3550 GetClientRect(hwnd, &rt);
3552 rt.left = x - SPLIT_WIDTH/2;
3553 rt.right = x + SPLIT_WIDTH/2+1;
3555 InvertRect(hdc, &rt);
3557 ReleaseDC(hwnd, hdc);
3560 #endif /* _NO_EXTENSIONS */
3563 #ifndef _NO_EXTENSIONS
3565 static void set_header(Pane* pane)
3568 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3571 item.mask = HDI_WIDTH;
3574 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3575 x += pane->widths[i];
3576 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3580 x += pane->widths[i];
3581 item.cxy = x - scroll_pos;
3582 SendMessage(pane->hwndHeader, HDM_SETITEM, i++, (LPARAM) &item);
3584 for(; i<COLUMNS; i++) {
3585 item.cxy = pane->widths[i];
3586 x += pane->widths[i];
3587 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3592 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3594 switch(pnmh->code) {
3595 case HDN_ITEMCHANGED: {
3596 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3597 int idx = phdn->iItem;
3598 int dx = phdn->pitem->cxy - pane->widths[idx];
3602 GetClientRect(pane->hwnd, &clnt);
3604 pane->widths[idx] += dx;
3606 for(i=idx; ++i<=COLUMNS; )
3607 pane->positions[i] += dx;
3610 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3614 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3616 rt_scr.right = clnt.right;
3617 rt_scr.bottom = clnt.bottom;
3619 rt_clip.left = pane->positions[idx]-scroll_pos;
3621 rt_clip.right = clnt.right;
3622 rt_clip.bottom = clnt.bottom;
3624 if (rt_scr.left < 0) rt_scr.left = 0;
3625 if (rt_clip.left < 0) rt_clip.left = 0;
3627 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3629 rt_clip.right = pane->positions[idx+1];
3630 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3632 if (pnmh->code == HDN_ENDTRACK) {
3633 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3635 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3643 case HDN_DIVIDERDBLCLICK: {
3644 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3647 calc_single_width(pane, phdn->iItem);
3648 item.mask = HDI_WIDTH;
3649 item.cxy = pane->widths[phdn->iItem];
3651 SendMessage(pane->hwndHeader, HDM_SETITEM, phdn->iItem, (LPARAM) &item);
3652 InvalidateRect(pane->hwnd, 0, TRUE);
3659 #endif /* _NO_EXTENSIONS */
3662 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3664 TCHAR path[MAX_PATH];
3665 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3667 /* delete sub entries in left pane */
3669 LRESULT res = SendMessage(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3670 Entry* sub = (Entry*) res;
3672 if (res==LB_ERR || !sub || sub->level<=entry->level)
3675 SendMessage(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3678 /* empty right pane */
3679 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3681 /* release memory */
3682 free_entries(entry);
3684 /* read contents from disk */
3685 #ifdef _SHELL_FOLDERS
3686 if (entry->etype == ET_SHELL)
3688 read_directory(entry, NULL, child->sortOrder, hwnd);
3693 get_path(entry, path);
3694 read_directory(entry, path, child->sortOrder, hwnd);
3697 /* insert found entries in right pane */
3698 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3699 calc_widths(&child->right, FALSE);
3700 #ifndef _NO_EXTENSIONS
3701 set_header(&child->right);
3704 child->header_wdths_ok = FALSE;
3706 SetCursor(old_cursor);
3710 /* expand a directory entry */
3712 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3717 if (!dir || dir->expanded || !dir->down)
3722 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3725 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3726 p->data.cFileName[2]=='\0' && p->next)
3730 /* no subdirectories ? */
3731 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3734 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3736 dir->expanded = TRUE;
3738 /* insert entries in left pane */
3739 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3741 if (!child->header_wdths_ok) {
3742 if (calc_widths(&child->left, FALSE)) {
3743 #ifndef _NO_EXTENSIONS
3744 set_header(&child->left);
3747 child->header_wdths_ok = TRUE;
3755 static void collapse_entry(Pane* pane, Entry* dir)
3757 int idx = SendMessage(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3759 ShowWindow(pane->hwnd, SW_HIDE);
3761 /* hide sub entries */
3763 LRESULT res = SendMessage(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3764 Entry* sub = (Entry*) res;
3766 if (res==LB_ERR || !sub || sub->level<=dir->level)
3769 SendMessage(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3772 dir->expanded = FALSE;
3774 ShowWindow(pane->hwnd, SW_SHOW);
3778 static void refresh_right_pane(ChildWnd* child)
3780 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3781 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3782 calc_widths(&child->right, FALSE);
3784 #ifndef _NO_EXTENSIONS
3785 set_header(&child->right);
3789 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3791 TCHAR path[MAX_PATH];
3798 child->left.cur = entry;
3800 child->right.root = entry->down? entry->down: entry;
3801 child->right.cur = entry;
3803 if (!entry->scanned)
3804 scan_entry(child, entry, idx, hwnd);
3806 refresh_right_pane(child);
3808 get_path(entry, path);
3809 lstrcpy(child->path, path);
3811 if (child->hwnd) /* only change window title, if the window already exists */
3812 SetWindowText(child->hwnd, path);
3815 if (SetCurrentDirectory(path))
3820 static void refresh_child(ChildWnd* child)
3822 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3826 get_path(child->left.cur, path);
3827 _tsplitpath(path, drv, NULL, NULL, NULL);
3829 child->right.root = NULL;
3831 scan_entry(child, &child->root.entry, 0, child->hwnd);
3833 #ifdef _SHELL_FOLDERS
3834 if (child->root.entry.etype == ET_SHELL)
3835 entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd);
3838 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3841 entry = &child->root.entry;
3843 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3845 set_curdir(child, entry, 0, child->hwnd);
3847 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3848 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
3852 static void create_drive_bar(void)
3854 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3855 #ifndef _NO_EXTENSIONS
3856 TCHAR b1[BUFFER_LEN];
3861 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3863 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3864 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3865 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3867 #ifndef _NO_EXTENSIONS
3869 /* insert unix file system button */
3873 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3875 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3876 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3877 drivebarBtn.iString++;
3879 #ifdef _SHELL_FOLDERS
3880 /* insert shell namespace button */
3881 load_string(b1, IDS_SHELL);
3882 b1[lstrlen(b1)+1] = '\0';
3883 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3885 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3886 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3887 drivebarBtn.iString++;
3890 /* register windows drive root strings */
3891 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3894 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3896 for(p=Globals.drives; *p; ) {
3897 #ifdef _NO_EXTENSIONS
3898 /* insert drive letter */
3899 TCHAR b[3] = {tolower(*p)};
3900 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3902 switch(GetDriveType(p)) {
3903 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3904 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3905 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3906 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3907 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3910 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3911 drivebarBtn.idCommand++;
3912 drivebarBtn.iString++;
3918 static void refresh_drives(void)
3922 /* destroy drive bar */
3923 DestroyWindow(Globals.hdrivebar);
3924 Globals.hdrivebar = 0;
3926 /* re-create drive bar */
3929 /* update window layout */
3930 GetClientRect(Globals.hMainWnd, &rect);
3931 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3935 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3937 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3939 if ((int)hinst <= 32) {
3940 display_error(hwnd, GetLastError());
3948 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3950 TCHAR cmd[MAX_PATH];
3952 #ifdef _SHELL_FOLDERS
3953 if (entry->etype == ET_SHELL) {
3956 SHELLEXECUTEINFO shexinfo;
3958 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3959 shexinfo.fMask = SEE_MASK_IDLIST;
3960 shexinfo.hwnd = hwnd;
3961 shexinfo.lpVerb = NULL;
3962 shexinfo.lpFile = NULL;
3963 shexinfo.lpParameters = NULL;
3964 shexinfo.lpDirectory = NULL;
3965 shexinfo.nShow = nCmdShow;
3966 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3968 if (!ShellExecuteEx(&shexinfo)) {
3969 display_error(hwnd, GetLastError());
3973 if (shexinfo.lpIDList != entry->pidl)
3974 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3980 get_path(entry, cmd);
3982 /* start program, open document... */
3983 return launch_file(hwnd, cmd, nCmdShow);
3987 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3989 Entry* entry = pane->cur;
3994 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3995 int scanned_old = entry->scanned;
3999 int idx = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
4000 scan_entry(child, entry, idx, hwnd);
4003 #ifndef _NO_EXTENSIONS
4004 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
4008 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
4009 entry = child->left.cur->up;
4010 collapse_entry(&child->left, entry);
4012 } else if (entry->expanded)
4013 collapse_entry(pane, child->left.cur);
4015 expand_entry(child, child->left.cur);
4017 if (!pane->treePane) focus_entry: {
4018 int idxstart = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
4019 int idx = SendMessage(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
4020 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
4021 set_curdir(child, entry, idx, hwnd);
4026 calc_widths(pane, FALSE);
4028 #ifndef _NO_EXTENSIONS
4033 if (GetKeyState(VK_MENU) < 0)
4034 show_properties_dlg(entry, child->hwnd);
4036 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
4041 static BOOL pane_command(Pane* pane, UINT cmd)
4045 if (pane->visible_cols) {
4046 pane->visible_cols = 0;
4047 calc_widths(pane, TRUE);
4048 #ifndef _NO_EXTENSIONS
4051 InvalidateRect(pane->hwnd, 0, TRUE);
4052 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
4053 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
4054 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4058 case ID_VIEW_ALL_ATTRIBUTES:
4059 if (pane->visible_cols != COL_ALL) {
4060 pane->visible_cols = COL_ALL;
4061 calc_widths(pane, TRUE);
4062 #ifndef _NO_EXTENSIONS
4065 InvalidateRect(pane->hwnd, 0, TRUE);
4066 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
4067 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
4068 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4072 #ifndef _NO_EXTENSIONS
4073 case ID_PREFERRED_SIZES: {
4074 calc_widths(pane, TRUE);
4076 InvalidateRect(pane->hwnd, 0, TRUE);
4080 /* TODO: more command ids... */
4090 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
4092 if (child->sortOrder != sortOrder) {
4093 child->sortOrder = sortOrder;
4094 refresh_child(child);
4098 static void update_view_menu(ChildWnd* child)
4100 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4101 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4102 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4103 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4107 static BOOL is_directory(LPCTSTR target)
4109 /*TODO correctly handle UNIX paths */
4110 DWORD target_attr = GetFileAttributes(target);
4112 if (target_attr == INVALID_FILE_ATTRIBUTES)
4115 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4118 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4120 TCHAR path[MAX_PATH];
4123 get_path(pane->cur, path);
4125 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4128 get_path(pane->cur, source);
4130 /* convert relative targets to absolute paths */
4131 if (path[0]!='/' && path[1]!=':') {
4132 get_path(pane->cur->up, target);
4133 len = lstrlen(target);
4135 if (target[len-1]!='\\' && target[len-1]!='/')
4136 target[len++] = '/';
4138 lstrcpy(target+len, path);
4140 lstrcpy(target, path);
4142 /* If the target already exists as directory, create a new target below this. */
4143 if (is_directory(path)) {
4144 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4145 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4147 _tsplitpath(source, NULL, NULL, fname, ext);
4149 wsprintf(target, sAppend, path, fname, ext);
4156 static IContextMenu2* s_pctxmenu2 = NULL;
4157 static IContextMenu3* s_pctxmenu3 = NULL;
4159 static void CtxMenu_reset(void)
4165 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4167 IContextMenu* pcm = NULL;
4171 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4172 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4173 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4174 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4177 IContextMenu_Release(pcm1);
4183 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4186 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4191 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4198 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4201 BOOL executed = FALSE;
4203 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4204 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4206 if (SUCCEEDED(hr)) {
4207 HMENU hmenu = CreatePopupMenu();
4209 pcm = CtxMenu_query_interfaces(pcm);
4212 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4214 if (SUCCEEDED(hr)) {
4215 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4220 CMINVOKECOMMANDINFO cmi;
4222 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4224 cmi.hwnd = hwndParent;
4225 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4226 cmi.lpParameters = NULL;
4227 cmi.lpDirectory = NULL;
4228 cmi.nShow = SW_SHOWNORMAL;
4232 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4239 IContextMenu_Release(pcm);
4242 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4246 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4248 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4253 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4254 Entry* entry = (Entry*) dis->itemData;
4256 if (dis->CtlID == IDW_TREE_LEFT)
4257 draw_item(&child->left, dis, entry, -1);
4258 else if (dis->CtlID == IDW_TREE_RIGHT)
4259 draw_item(&child->right, dis, entry, -1);
4261 goto draw_menu_item;
4266 InitChildWindow(child);
4270 free_child_window(child);
4271 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4278 GetClientRect(hwnd, &rt);
4279 BeginPaint(hwnd, &ps);
4280 rt.left = child->split_pos-SPLIT_WIDTH/2;
4281 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4282 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4283 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4284 SelectObject(ps.hdc, lastBrush);
4285 #ifdef _NO_EXTENSIONS
4286 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4287 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4289 EndPaint(hwnd, &ps);
4293 if (LOWORD(lparam) == HTCLIENT) {
4296 ScreenToClient(hwnd, &pt);
4298 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4299 SetCursor(LoadCursor(0, IDC_SIZEWE));
4305 case WM_LBUTTONDOWN: {
4307 int x = (short)LOWORD(lparam);
4309 GetClientRect(hwnd, &rt);
4311 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4312 last_split = child->split_pos;
4313 #ifdef _NO_EXTENSIONS
4314 draw_splitbar(hwnd, last_split);
4322 if (GetCapture() == hwnd) {
4323 #ifdef _NO_EXTENSIONS
4325 int x = (short)LOWORD(lparam);
4326 draw_splitbar(hwnd, last_split);
4328 GetClientRect(hwnd, &rt);
4329 child->split_pos = x;
4330 resize_tree(child, rt.right, rt.bottom);
4336 #ifdef _NO_EXTENSIONS
4337 case WM_CAPTURECHANGED:
4338 if (GetCapture()==hwnd && last_split>=0)
4339 draw_splitbar(hwnd, last_split);
4344 if (wparam == VK_ESCAPE)
4345 if (GetCapture() == hwnd) {
4347 #ifdef _NO_EXTENSIONS
4348 draw_splitbar(hwnd, last_split);
4350 child->split_pos = last_split;
4352 GetClientRect(hwnd, &rt);
4353 resize_tree(child, rt.right, rt.bottom);
4356 SetCursor(LoadCursor(0, IDC_ARROW));
4361 if (GetCapture() == hwnd) {
4363 int x = (short)LOWORD(lparam);
4365 #ifdef _NO_EXTENSIONS
4366 HDC hdc = GetDC(hwnd);
4367 GetClientRect(hwnd, &rt);
4369 rt.left = last_split-SPLIT_WIDTH/2;
4370 rt.right = last_split+SPLIT_WIDTH/2+1;
4371 InvertRect(hdc, &rt);
4374 rt.left = x-SPLIT_WIDTH/2;
4375 rt.right = x+SPLIT_WIDTH/2+1;
4376 InvertRect(hdc, &rt);
4378 ReleaseDC(hwnd, hdc);
4380 GetClientRect(hwnd, &rt);
4382 if (x>=0 && x<rt.right) {
4383 child->split_pos = x;
4384 resize_tree(child, rt.right, rt.bottom);
4385 rt.left = x-SPLIT_WIDTH/2;
4386 rt.right = x+SPLIT_WIDTH/2+1;
4387 InvalidateRect(hwnd, &rt, FALSE);
4388 UpdateWindow(child->left.hwnd);
4390 UpdateWindow(child->right.hwnd);
4396 #ifndef _NO_EXTENSIONS
4397 case WM_GETMINMAXINFO:
4398 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4400 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4402 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4403 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4405 #endif /* _NO_EXTENSIONS */
4408 if (SetCurrentDirectory(child->path))
4410 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4413 case WM_DISPATCH_COMMAND: {
4414 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4416 switch(LOWORD(wparam)) {
4417 case ID_WINDOW_NEW: {
4418 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4420 if (!create_child_window(new_child))
4421 HeapFree(GetProcessHeap(), 0, new_child);
4427 refresh_child(child);
4431 activate_entry(child, pane, hwnd);
4434 case ID_FILE_MOVE: {
4435 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4437 if (prompt_target(pane, source, target)) {
4438 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4440 source[lstrlen(source)+1] = '\0';
4441 target[lstrlen(target)+1] = '\0';
4443 if (!SHFileOperation(&shfo))
4444 refresh_child(child);
4448 case ID_FILE_COPY: {
4449 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4451 if (prompt_target(pane, source, target)) {
4452 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4454 source[lstrlen(source)+1] = '\0';
4455 target[lstrlen(target)+1] = '\0';
4457 if (!SHFileOperation(&shfo))
4458 refresh_child(child);
4462 case ID_FILE_DELETE: {
4463 TCHAR path[BUFFER_LEN];
4464 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
4466 get_path(pane->cur, path);
4468 path[lstrlen(path)+1] = '\0';
4470 if (!SHFileOperation(&shfo))
4471 refresh_child(child);
4474 case ID_VIEW_SORT_NAME:
4475 set_sort_order(child, SORT_NAME);
4478 case ID_VIEW_SORT_TYPE:
4479 set_sort_order(child, SORT_EXT);
4482 case ID_VIEW_SORT_SIZE:
4483 set_sort_order(child, SORT_SIZE);
4486 case ID_VIEW_SORT_DATE:
4487 set_sort_order(child, SORT_DATE);
4490 case ID_VIEW_FILTER: {
4491 struct FilterDialog dlg;
4493 memset(&dlg, 0, sizeof(struct FilterDialog));
4494 lstrcpy(dlg.pattern, child->filter_pattern);
4495 dlg.flags = child->filter_flags;
4497 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4498 lstrcpy(child->filter_pattern, dlg.pattern);
4499 child->filter_flags = dlg.flags;
4500 refresh_right_pane(child);
4504 case ID_VIEW_SPLIT: {
4505 last_split = child->split_pos;
4506 #ifdef _NO_EXTENSIONS
4507 draw_splitbar(hwnd, last_split);
4512 case ID_EDIT_PROPERTIES:
4513 show_properties_dlg(pane->cur, child->hwnd);
4517 return pane_command(pane, LOWORD(wparam));
4523 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4525 switch(HIWORD(wparam)) {
4526 case LBN_SELCHANGE: {
4527 int idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4528 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4530 if (pane == &child->left)
4531 set_curdir(child, entry, idx, hwnd);
4537 activate_entry(child, pane, hwnd);
4542 #ifndef _NO_EXTENSIONS
4544 NMHDR* pnmh = (NMHDR*) lparam;
4545 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4548 #ifdef _SHELL_FOLDERS
4549 case WM_CONTEXTMENU: {
4554 /* first select the current item in the listbox */
4555 HWND hpanel = (HWND) wparam;
4556 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4557 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4558 ScreenToClient(hpanel, &pt_clnt);
4559 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4560 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4562 /* now create the popup menu using shell namespace and IContextMenu */
4563 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4564 idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4567 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4569 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4572 IShellFolder* parentFolder;
4573 LPCITEMIDLIST pidlLast;
4575 /* get and use the parent folder to display correct context menu in all cases */
4576 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4577 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4578 refresh_child(child);
4580 IShellFolder_Release(parentFolder);
4583 IMalloc_Free(Globals.iMalloc, pidl_abs);
4589 case WM_MEASUREITEM:
4591 if (!wparam) /* Is the message menu-related? */
4592 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4597 case WM_INITMENUPOPUP:
4598 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4601 update_view_menu(child);
4604 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4606 LRESULT lResult = 0;
4608 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4616 if (wparam != SIZE_MINIMIZED)
4617 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4621 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4628 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4630 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4631 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4635 #ifndef _NO_EXTENSIONS
4642 child->focus_pane = pane==&child->right? 1: 0;
4643 SendMessage(hwnd, LB_SETSEL, TRUE, 1);
4644 /*TODO: check menu items */
4648 if (wparam == VK_TAB) {
4649 /*TODO: SetFocus(Globals.hdrivebar) */
4650 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4654 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4658 static void InitInstance(HINSTANCE hinstance)
4660 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4667 INITCOMMONCONTROLSEX icc = {
4668 sizeof(INITCOMMONCONTROLSEX),
4674 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4676 InitCommonControlsEx(&icc);
4679 /* register frame window class */
4681 wcFrame.cbSize = sizeof(WNDCLASSEX);
4683 wcFrame.lpfnWndProc = FrameWndProc;
4684 wcFrame.cbClsExtra = 0;
4685 wcFrame.cbWndExtra = 0;
4686 wcFrame.hInstance = hinstance;
4687 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4688 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4689 wcFrame.hbrBackground = 0;
4690 wcFrame.lpszMenuName = 0;
4691 wcFrame.lpszClassName = sWINEFILEFRAME;
4692 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4693 MAKEINTRESOURCE(IDI_WINEFILE),
4695 GetSystemMetrics(SM_CXSMICON),
4696 GetSystemMetrics(SM_CYSMICON),
4699 Globals.hframeClass = RegisterClassEx(&wcFrame);
4702 /* register tree windows class */
4704 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4705 wcChild.lpfnWndProc = ChildWndProc;
4706 wcChild.cbClsExtra = 0;
4707 wcChild.cbWndExtra = 0;
4708 wcChild.hInstance = hinstance;
4710 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4711 wcChild.hbrBackground = 0;
4712 wcChild.lpszMenuName = 0;
4713 wcChild.lpszClassName = sWINEFILETREE;
4715 hChildClass = RegisterClass(&wcChild);
4718 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4720 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4724 Globals.hInstance = hinstance;
4726 #ifdef _SHELL_FOLDERS
4728 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4729 SHGetDesktopFolder(&Globals.iDesktop);
4731 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4733 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4737 /* load column strings */
4740 load_string(g_pos_names[col++], IDS_COL_NAME);
4741 load_string(g_pos_names[col++], IDS_COL_SIZE);
4742 load_string(g_pos_names[col++], IDS_COL_CDATE);
4743 #ifndef _NO_EXTENSIONS
4744 load_string(g_pos_names[col++], IDS_COL_ADATE);
4745 load_string(g_pos_names[col++], IDS_COL_MDATE);
4746 load_string(g_pos_names[col++], IDS_COL_IDX);
4747 load_string(g_pos_names[col++], IDS_COL_LINKS);
4749 load_string(g_pos_names[col++], IDS_COL_ATTR);
4750 #ifndef _NO_EXTENSIONS
4751 load_string(g_pos_names[col++], IDS_COL_SEC);
4756 static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4758 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4760 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4762 HMENU hMenuFrame, hMenuWindow;
4765 CLIENTCREATESTRUCT ccs;
4767 if (Globals.hMainWnd)
4770 opts = load_registry_settings();
4771 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4772 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4774 Globals.hMenuFrame = hMenuFrame;
4775 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4776 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4778 ccs.hWindowMenu = hMenuWindow;
4779 ccs.idFirstChild = IDW_FIRST_CHILD;
4782 /* create main window */
4783 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4784 opts.start_x, opts.start_y, opts.width, opts.height,
4785 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4788 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4789 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4791 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4793 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4794 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4799 TBBUTTON toolbarBtns[] = {
4800 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4801 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4802 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4803 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4804 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4806 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4807 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4810 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4811 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4812 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4813 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4816 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4817 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4819 /* CreateStatusWindow does not accept WS_BORDER
4820 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4821 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4822 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4824 /*TODO: read paths from registry */
4826 if (!path || !*path) {
4827 GetCurrentDirectory(MAX_PATH, buffer);
4831 ShowWindow(Globals.hMainWnd, cmdshow);
4833 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4834 /* Shell Namespace as default: */
4835 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4837 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4840 child->pos.showCmd = SW_SHOWMAXIMIZED;
4841 child->pos.rcNormalPosition.left = 0;
4842 child->pos.rcNormalPosition.top = 0;
4843 child->pos.rcNormalPosition.right = 320;
4844 child->pos.rcNormalPosition.bottom = 280;
4846 if (!create_child_window(child))
4847 HeapFree(GetProcessHeap(), 0, child);
4849 SetWindowPlacement(child->hwnd, &child->pos);
4851 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4853 Globals.prescan_node = FALSE;
4855 UpdateWindow(Globals.hMainWnd);
4857 if (path && path[0])
4860 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4861 TCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4863 memset(name,0,sizeof(name));
4864 memset(name,0,sizeof(ext));
4865 _tsplitpath(path, drv, dir, name, ext);
4868 count = SendMessage(child->right.hwnd, LB_GETCOUNT, 0, 0);
4869 lstrcpy(fullname,name);
4870 lstrcat(fullname,ext);
4872 for (index = 0; index < count; index ++)
4874 Entry* entry = (Entry*) SendMessage(child->right.hwnd, LB_GETITEMDATA, index, 0);
4875 if (lstrcmp(entry->data.cFileName,fullname)==0 ||
4876 lstrcmp(entry->data.cAlternateFileName,fullname)==0)
4878 SendMessage(child->right.hwnd, LB_SETCURSEL, index, 0);
4879 SetFocus(child->right.hwnd);
4887 static void ExitInstance(void)
4889 #ifdef _SHELL_FOLDERS
4890 IShellFolder_Release(Globals.iDesktop);
4891 IMalloc_Release(Globals.iMalloc);
4895 DeleteObject(Globals.hfont);
4896 ImageList_Destroy(Globals.himl);
4899 #ifdef _NO_EXTENSIONS
4901 /* search for already running win[e]files */
4903 static int g_foundPrevInstance = 0;
4905 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4909 GetClassName(hwnd, cls, 128);
4911 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4912 g_foundPrevInstance++;
4919 /* search for window of given class name to allow only one running instance */
4920 static int find_window_class(LPCTSTR classname)
4922 EnumWindows(EnumWndProc, (LPARAM)classname);
4924 if (g_foundPrevInstance)
4932 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4936 InitInstance(hinstance);
4938 show_frame(0, cmdshow, path);
4940 while(GetMessage(&msg, 0, 0, 0)) {
4941 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4944 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4947 TranslateMessage(&msg);
4948 DispatchMessage(&msg);
4957 #if defined(UNICODE) && defined(_MSC_VER)
4958 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4960 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4963 #ifdef _NO_EXTENSIONS
4964 if (find_window_class(sWINEFILEFRAME))
4968 #if defined(UNICODE) && !defined(_MSC_VER)
4969 { /* convert ANSI cmdline into WCS path string */
4970 TCHAR buffer[MAX_PATH];
4971 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4972 winefile_main(hinstance, cmdshow, buffer);
4975 winefile_main(hinstance, cmdshow, cmdline);