msvcrt: Require exact uppercase and lowercase format in printf routines.
[wine/dibdrv.git] / programs / winefile / winefile.c
blob1f6eeeeef5c59451d7ade1e69dae5e7d631c03ab
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifdef __WINE__
22 #include "config.h"
23 #include "wine/port.h"
25 /* for unix filesystem function calls */
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <dirent.h>
29 #endif
31 #define COBJMACROS
33 #include "winefile.h"
34 #include "resource.h"
36 #ifdef _NO_EXTENSIONS
37 #undef _LEFT_FILES
38 #endif
40 #ifndef _MAX_PATH
41 #define _MAX_DRIVE 3
42 #define _MAX_FNAME 256
43 #define _MAX_DIR _MAX_FNAME
44 #define _MAX_EXT _MAX_FNAME
45 #define _MAX_PATH 260
46 #endif
48 #ifdef NONAMELESSUNION
49 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
50 #else
51 #define UNION_MEMBER(x) x
52 #endif
55 #ifdef _SHELL_FOLDERS
56 #define DEFAULT_SPLIT_POS 300
57 #else
58 #define DEFAULT_SPLIT_POS 200
59 #endif
62 enum ENTRY_TYPE {
63 ET_WINDOWS,
64 ET_UNIX,
65 #ifdef _SHELL_FOLDERS
66 ET_SHELL
67 #endif
70 typedef struct _Entry {
71 struct _Entry* next;
72 struct _Entry* down;
73 struct _Entry* up;
75 BOOL expanded;
76 BOOL scanned;
77 int level;
79 WIN32_FIND_DATA data;
81 #ifndef _NO_EXTENSIONS
82 BY_HANDLE_FILE_INFORMATION bhfi;
83 BOOL bhfi_valid;
84 enum ENTRY_TYPE etype;
85 #endif
86 #ifdef _SHELL_FOLDERS
87 LPITEMIDLIST pidl;
88 IShellFolder* folder;
89 HICON hicon;
90 #endif
91 } Entry;
93 typedef struct {
94 Entry entry;
95 TCHAR path[MAX_PATH];
96 TCHAR volname[_MAX_FNAME];
97 TCHAR fs[_MAX_DIR];
98 DWORD drive_type;
99 DWORD fs_flags;
100 } Root;
102 enum COLUMN_FLAGS {
103 COL_SIZE = 0x01,
104 COL_DATE = 0x02,
105 COL_TIME = 0x04,
106 COL_ATTRIBUTES = 0x08,
107 COL_DOSNAMES = 0x10,
108 #ifdef _NO_EXTENSIONS
109 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
110 #else
111 COL_INDEX = 0x20,
112 COL_LINKS = 0x40,
113 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
114 #endif
117 typedef enum {
118 SORT_NAME,
119 SORT_EXT,
120 SORT_SIZE,
121 SORT_DATE
122 } SORT_ORDER;
124 typedef struct {
125 HWND hwnd;
126 #ifndef _NO_EXTENSIONS
127 HWND hwndHeader;
128 #endif
130 #ifndef _NO_EXTENSIONS
131 #define COLUMNS 10
132 #else
133 #define COLUMNS 5
134 #endif
135 int widths[COLUMNS];
136 int positions[COLUMNS+1];
138 BOOL treePane;
139 int visible_cols;
140 Entry* root;
141 Entry* cur;
142 } Pane;
144 typedef struct {
145 HWND hwnd;
146 Pane left;
147 Pane right;
148 int focus_pane; /* 0: left 1: right */
149 WINDOWPLACEMENT pos;
150 int split_pos;
151 BOOL header_wdths_ok;
153 TCHAR path[MAX_PATH];
154 TCHAR filter_pattern[MAX_PATH];
155 int filter_flags;
156 Root root;
158 SORT_ORDER sortOrder;
159 } ChildWnd;
163 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
164 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
165 static void refresh_child(ChildWnd* child);
166 static void refresh_drives(void);
167 static void get_path(Entry* dir, PTSTR path);
168 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
170 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
171 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
172 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
175 /* globals */
176 WINEFILE_GLOBALS Globals;
178 static int last_split;
180 /* some common string constants */
181 static const TCHAR sEmpty[] = {'\0'};
182 static const TCHAR sSpace[] = {' ', '\0'};
183 static const TCHAR sNumFmt[] = {'%','d','\0'};
184 static const TCHAR sQMarks[] = {'?','?','?','\0'};
186 /* window class names */
187 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
188 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
190 #ifdef _MSC_VER
191 /* #define LONGLONGARG _T("I64") */
192 static const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
193 static const TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
194 #else
195 /* #define LONGLONGARG _T("L") */
196 static const TCHAR sLongHexFmt[] = {'%','L','X','\0'};
197 static const TCHAR sLongNumFmt[] = {'%','L','d','\0'};
198 #endif
201 /* load resource string */
202 static LPTSTR load_string(LPTSTR buffer, UINT id)
204 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
206 return buffer;
209 #define RS(b, i) load_string(b, i)
212 /* display error message for the specified WIN32 error code */
213 static void display_error(HWND hwnd, DWORD error)
215 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
216 PTSTR msg;
218 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
219 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
220 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
221 else
222 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
224 LocalFree(msg);
228 /* display network error message using WNetGetLastError() */
229 static void display_network_error(HWND hwnd)
231 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
232 DWORD error;
234 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
235 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
239 #ifdef __WINE__
241 #ifdef UNICODE
243 /* call vswprintf() in msvcrt.dll */
244 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
245 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
247 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
248 va_list ap;
249 int ret;
251 if (!pvswprintf) {
252 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
253 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
256 va_start(ap, fmt);
257 ret = (*pvswprintf)(buffer, fmt, ap);
258 va_end(ap);
260 return ret;
263 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
265 LPCWSTR p = str;
267 while(*p)
268 ++p;
270 do {
271 if (--p < str)
272 return NULL;
273 } while(*p != c);
275 return p;
278 #define _tcsrchr my_wcsrchr
279 #else /* UNICODE */
280 #define _tcsrchr strrchr
281 #endif /* UNICODE */
283 #endif /* __WINE__ */
286 /* allocate and initialise a directory entry */
287 static Entry* alloc_entry(void)
289 Entry* entry = (Entry*) malloc(sizeof(Entry));
291 #ifdef _SHELL_FOLDERS
292 entry->pidl = NULL;
293 entry->folder = NULL;
294 entry->hicon = 0;
295 #endif
297 return entry;
300 /* free a directory entry */
301 static void free_entry(Entry* entry)
303 #ifdef _SHELL_FOLDERS
304 if (entry->hicon && entry->hicon!=(HICON)-1)
305 DestroyIcon(entry->hicon);
307 if (entry->folder && entry->folder!=Globals.iDesktop)
308 IShellFolder_Release(entry->folder);
310 if (entry->pidl)
311 IMalloc_Free(Globals.iMalloc, entry->pidl);
312 #endif
314 free(entry);
317 /* recursively free all child entries */
318 static void free_entries(Entry* dir)
320 Entry *entry, *next=dir->down;
322 if (next) {
323 dir->down = 0;
325 do {
326 entry = next;
327 next = entry->next;
329 free_entries(entry);
330 free_entry(entry);
331 } while(next);
336 static void read_directory_win(Entry* dir, LPCTSTR path)
338 Entry* first_entry = NULL;
339 Entry* last = NULL;
340 Entry* entry;
342 int level = dir->level + 1;
343 WIN32_FIND_DATA w32fd;
344 HANDLE hFind;
345 #ifndef _NO_EXTENSIONS
346 HANDLE hFile;
347 #endif
349 TCHAR buffer[MAX_PATH], *p;
350 for(p=buffer; *path; )
351 *p++ = *path++;
353 *p++ = '\\';
354 p[0] = '*';
355 p[1] = '\0';
357 hFind = FindFirstFile(buffer, &w32fd);
359 if (hFind != INVALID_HANDLE_VALUE) {
360 do {
361 #ifdef _NO_EXTENSIONS
362 /* hide directory entry "." */
363 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
364 LPCTSTR name = w32fd.cFileName;
366 if (name[0]=='.' && name[1]=='\0')
367 continue;
369 #endif
370 entry = alloc_entry();
372 if (!first_entry)
373 first_entry = entry;
375 if (last)
376 last->next = entry;
378 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
379 entry->down = NULL;
380 entry->up = dir;
381 entry->expanded = FALSE;
382 entry->scanned = FALSE;
383 entry->level = level;
385 #ifndef _NO_EXTENSIONS
386 entry->etype = ET_WINDOWS;
387 entry->bhfi_valid = FALSE;
389 lstrcpy(p, entry->data.cFileName);
391 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
392 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
394 if (hFile != INVALID_HANDLE_VALUE) {
395 if (GetFileInformationByHandle(hFile, &entry->bhfi))
396 entry->bhfi_valid = TRUE;
398 CloseHandle(hFile);
400 #endif
402 last = entry;
403 } while(FindNextFile(hFind, &w32fd));
405 if (last)
406 last->next = NULL;
408 FindClose(hFind);
411 dir->down = first_entry;
412 dir->scanned = TRUE;
416 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
418 Entry* entry;
420 for(entry=dir->down; entry; entry=entry->next) {
421 LPCTSTR p = name;
422 LPCTSTR q = entry->data.cFileName;
424 do {
425 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
426 return entry;
427 } while(tolower(*p++) == tolower(*q++));
429 p = name;
430 q = entry->data.cAlternateFileName;
432 do {
433 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
434 return entry;
435 } while(tolower(*p++) == tolower(*q++));
438 return 0;
442 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
444 TCHAR buffer[MAX_PATH];
445 Entry* entry = &root->entry;
446 LPCTSTR s = path;
447 PTSTR d = buffer;
449 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
451 #ifndef _NO_EXTENSIONS
452 entry->etype = ET_WINDOWS;
453 #endif
455 while(entry) {
456 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
457 *d++ = *s++;
459 while(*s==TEXT('\\') || *s==TEXT('/'))
460 s++;
462 *d++ = TEXT('\\');
463 *d = TEXT('\0');
465 read_directory(entry, buffer, sortOrder, hwnd);
467 if (entry->down)
468 entry->expanded = TRUE;
470 if (!*s)
471 break;
473 entry = find_entry_win(entry, s);
476 SetCursor(old_cursor);
478 return entry;
482 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
484 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
486 struct tm* tm = gmtime(t);
487 SYSTEMTIME stime;
489 if (!tm)
490 return FALSE;
492 stime.wYear = tm->tm_year+1900;
493 stime.wMonth = tm->tm_mon+1;
494 /* stime.wDayOfWeek */
495 stime.wDay = tm->tm_mday;
496 stime.wHour = tm->tm_hour;
497 stime.wMinute = tm->tm_min;
498 stime.wSecond = tm->tm_sec;
500 return SystemTimeToFileTime(&stime, ftime);
503 static void read_directory_unix(Entry* dir, LPCTSTR path)
505 Entry* first_entry = NULL;
506 Entry* last = NULL;
507 Entry* entry;
508 DIR* pdir;
510 int level = dir->level + 1;
511 #ifdef UNICODE
512 char cpath[MAX_PATH];
514 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
515 #else
516 const char* cpath = path;
517 #endif
519 pdir = opendir(cpath);
521 if (pdir) {
522 struct stat st;
523 struct dirent* ent;
524 char buffer[MAX_PATH], *p;
525 const char* s;
527 for(p=buffer,s=cpath; *s; )
528 *p++ = *s++;
530 if (p==buffer || p[-1]!='/')
531 *p++ = '/';
533 while((ent=readdir(pdir))) {
534 entry = alloc_entry();
536 if (!first_entry)
537 first_entry = entry;
539 if (last)
540 last->next = entry;
542 entry->etype = ET_UNIX;
544 strcpy(p, ent->d_name);
545 #ifdef UNICODE
546 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
547 #else
548 lstrcpy(entry->data.cFileName, p);
549 #endif
551 if (!stat(buffer, &st)) {
552 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
554 if (S_ISDIR(st.st_mode))
555 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
557 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
558 entry->data.nFileSizeHigh = st.st_size >> 32;
560 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
561 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
562 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
564 entry->bhfi.nFileIndexLow = ent->d_ino;
565 entry->bhfi.nFileIndexHigh = 0;
567 entry->bhfi.nNumberOfLinks = st.st_nlink;
569 entry->bhfi_valid = TRUE;
570 } else {
571 entry->data.nFileSizeLow = 0;
572 entry->data.nFileSizeHigh = 0;
573 entry->bhfi_valid = FALSE;
576 entry->down = NULL;
577 entry->up = dir;
578 entry->expanded = FALSE;
579 entry->scanned = FALSE;
580 entry->level = level;
582 last = entry;
585 if (last)
586 last->next = NULL;
588 closedir(pdir);
591 dir->down = first_entry;
592 dir->scanned = TRUE;
595 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
597 Entry* entry;
599 for(entry=dir->down; entry; entry=entry->next) {
600 LPCTSTR p = name;
601 LPCTSTR q = entry->data.cFileName;
603 do {
604 if (!*p || *p==TEXT('/'))
605 return entry;
606 } while(*p++ == *q++);
609 return 0;
612 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
614 TCHAR buffer[MAX_PATH];
615 Entry* entry = &root->entry;
616 LPCTSTR s = path;
617 PTSTR d = buffer;
619 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
621 entry->etype = ET_UNIX;
623 while(entry) {
624 while(*s && *s!=TEXT('/'))
625 *d++ = *s++;
627 while(*s == TEXT('/'))
628 s++;
630 *d++ = TEXT('/');
631 *d = TEXT('\0');
633 read_directory(entry, buffer, sortOrder, hwnd);
635 if (entry->down)
636 entry->expanded = TRUE;
638 if (!*s)
639 break;
641 entry = find_entry_unix(entry, s);
644 SetCursor(old_cursor);
646 return entry;
649 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
652 #ifdef _SHELL_FOLDERS
654 #ifdef UNICODE
655 #define get_strret get_strretW
656 #define path_from_pidl path_from_pidlW
657 #else
658 #define get_strret get_strretA
659 #define path_from_pidl path_from_pidlA
660 #endif
663 static void free_strret(STRRET* str)
665 if (str->uType == STRRET_WSTR)
666 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
670 #ifndef UNICODE
672 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
674 LPCSTR s;
675 LPSTR d = dest;
677 for(s=source; count&&(*d++=*s++); )
678 count--;
680 return dest;
683 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
685 switch(str->uType) {
686 case STRRET_WSTR:
687 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
688 break;
690 case STRRET_OFFSET:
691 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
692 break;
694 case STRRET_CSTR:
695 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
699 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
701 STRRET str;
703 /* SHGDN_FORPARSING: get full path of id list */
704 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
706 if (SUCCEEDED(hr)) {
707 get_strretA(&str, &pidl->mkid, buffer, len);
708 free_strret(&str);
709 } else
710 buffer[0] = '\0';
712 return hr;
715 #endif
717 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
719 LPCWSTR s;
720 LPWSTR d = dest;
722 for(s=source; count&&(*d++=*s++); )
723 count--;
725 return dest;
728 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
730 switch(str->uType) {
731 case STRRET_WSTR:
732 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
733 break;
735 case STRRET_OFFSET:
736 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
737 break;
739 case STRRET_CSTR:
740 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
745 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
747 STRRET str;
749 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
751 if (SUCCEEDED(hr)) {
752 get_strret(&str, &pidl->mkid, buffer, len);
753 free_strret(&str);
754 } else
755 buffer[0] = '\0';
757 return hr;
761 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
763 STRRET str;
765 /* SHGDN_FORPARSING: get full path of id list */
766 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
768 if (SUCCEEDED(hr)) {
769 get_strretW(&str, &pidl->mkid, buffer, len);
770 free_strret(&str);
771 } else
772 buffer[0] = '\0';
774 return hr;
778 /* create an item id list from a file system path */
780 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
782 LPITEMIDLIST pidl;
783 HRESULT hr;
784 ULONG len;
786 #ifdef UNICODE
787 LPWSTR buffer = path;
788 #else
789 WCHAR buffer[MAX_PATH];
790 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
791 #endif
793 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
794 if (FAILED(hr))
795 return NULL;
797 return pidl;
801 /* convert an item id list from relative to absolute (=relative to the desktop) format */
803 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
805 if (entry->up && entry->up->etype==ET_SHELL) {
806 IShellFolder* folder = entry->up->folder;
807 WCHAR buffer[MAX_PATH];
809 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
811 if (SUCCEEDED(hr)) {
812 LPITEMIDLIST pidl;
813 ULONG len;
815 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
817 if (SUCCEEDED(hr))
818 return pidl;
820 } else if (entry->etype == ET_WINDOWS) {
821 TCHAR path[MAX_PATH];
823 get_path(entry, path);
825 return get_path_pidl(path, hwnd);
826 } else if (entry->pidl)
827 return ILClone(entry->pidl);
829 return NULL;
833 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
835 IExtractIcon* pExtract;
837 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
838 TCHAR path[_MAX_PATH];
839 unsigned flags;
840 HICON hicon;
841 int idx;
843 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
844 if (!(flags & GIL_NOTFILENAME)) {
845 if (idx == -1)
846 idx = 0; /* special case for some control panel applications */
848 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
849 flags &= ~GIL_DONTCACHE;
850 } else {
851 HICON hIconLarge = 0;
853 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
855 if (SUCCEEDED(hr))
856 DestroyIcon(hIconLarge);
859 return hicon;
863 return 0;
867 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
869 Entry* entry;
871 for(entry=dir->down; entry; entry=entry->next) {
872 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
873 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
874 return entry;
877 return 0;
880 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
882 Entry* entry = &root->entry;
883 Entry* next;
884 LPITEMIDLIST next_pidl = pidl;
885 IShellFolder* folder;
886 IShellFolder* child = NULL;
887 HRESULT hr;
889 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
891 #ifndef _NO_EXTENSIONS
892 entry->etype = ET_SHELL;
893 #endif
895 folder = Globals.iDesktop;
897 while(entry) {
898 entry->pidl = next_pidl;
899 entry->folder = folder;
901 if (!pidl->mkid.cb)
902 break;
904 /* copy first element of item idlist */
905 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
906 memcpy(next_pidl, pidl, pidl->mkid.cb);
907 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
909 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
910 if (!SUCCEEDED(hr))
911 break;
913 read_directory(entry, NULL, sortOrder, hwnd);
915 if (entry->down)
916 entry->expanded = TRUE;
918 next = find_entry_shell(entry, next_pidl);
919 if (!next)
920 break;
922 folder = child;
923 entry = next;
925 /* go to next element */
926 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
929 SetCursor(old_cursor);
931 return entry;
935 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
937 if (!(attribs & SFGAO_FILESYSTEM) ||
938 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
939 WIN32_FILE_ATTRIBUTE_DATA fad;
940 IDataObject* pDataObj;
942 STGMEDIUM medium = {0, {0}, 0};
943 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
945 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
947 if (SUCCEEDED(hr)) {
948 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
950 IDataObject_Release(pDataObj);
952 if (SUCCEEDED(hr)) {
953 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
954 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
956 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
957 w32fdata->dwFileAttributes = fad.dwFileAttributes;
958 w32fdata->ftCreationTime = fad.ftCreationTime;
959 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
960 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
962 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
963 w32fdata->nFileSizeLow = fad.nFileSizeLow;
964 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
968 SetErrorMode(sem_org);
970 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
971 GlobalFree(medium.UNION_MEMBER(hGlobal));
976 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
977 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
979 if (attribs & SFGAO_READONLY)
980 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
982 if (attribs & SFGAO_COMPRESSED)
983 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
987 static void read_directory_shell(Entry* dir, HWND hwnd)
989 IShellFolder* folder = dir->folder;
990 int level = dir->level + 1;
991 HRESULT hr;
993 IShellFolder* child;
994 IEnumIDList* idlist;
996 Entry* first_entry = NULL;
997 Entry* last = NULL;
998 Entry* entry;
1000 if (!folder)
1001 return;
1003 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1005 if (SUCCEEDED(hr)) {
1006 for(;;) {
1007 #define FETCH_ITEM_COUNT 32
1008 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1009 SFGAOF attribs;
1010 ULONG cnt = 0;
1011 ULONG n;
1013 memset(pidls, 0, sizeof(pidls));
1015 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1016 if (!SUCCEEDED(hr))
1017 break;
1019 if (hr == S_FALSE)
1020 break;
1022 for(n=0; n<cnt; ++n) {
1023 entry = alloc_entry();
1025 if (!first_entry)
1026 first_entry = entry;
1028 if (last)
1029 last->next = entry;
1031 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1032 entry->bhfi_valid = FALSE;
1034 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1036 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1038 if (SUCCEEDED(hr)) {
1039 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1040 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1042 entry->bhfi_valid = TRUE;
1043 } else
1044 attribs = 0;
1045 } else
1046 attribs = 0;
1048 entry->pidl = pidls[n];
1050 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1051 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1053 if (SUCCEEDED(hr))
1054 entry->folder = child;
1055 else
1056 entry->folder = NULL;
1058 else
1059 entry->folder = NULL;
1061 if (!entry->data.cFileName[0])
1062 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1064 /* get display icons for files and virtual objects */
1065 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1066 !(attribs & SFGAO_FILESYSTEM)) {
1067 entry->hicon = extract_icon(folder, pidls[n]);
1069 if (!entry->hicon)
1070 entry->hicon = (HICON)-1; /* don't try again later */
1073 entry->down = NULL;
1074 entry->up = dir;
1075 entry->expanded = FALSE;
1076 entry->scanned = FALSE;
1077 entry->level = level;
1079 #ifndef _NO_EXTENSIONS
1080 entry->etype = ET_SHELL;
1081 entry->bhfi_valid = FALSE;
1082 #endif
1084 last = entry;
1088 IEnumIDList_Release(idlist);
1091 if (last)
1092 last->next = NULL;
1094 dir->down = first_entry;
1095 dir->scanned = TRUE;
1098 #endif /* _SHELL_FOLDERS */
1101 /* sort order for different directory/file types */
1102 enum TYPE_ORDER {
1103 TO_DIR = 0,
1104 TO_DOT = 1,
1105 TO_DOTDOT = 2,
1106 TO_OTHER_DIR = 3,
1107 TO_FILE = 4
1110 /* distinguish between ".", ".." and any other directory names */
1111 static int TypeOrderFromDirname(LPCTSTR name)
1113 if (name[0] == '.') {
1114 if (name[1] == '\0')
1115 return TO_DOT; /* "." */
1117 if (name[1]=='.' && name[2]=='\0')
1118 return TO_DOTDOT; /* ".." */
1121 return TO_OTHER_DIR; /* anything else */
1124 /* directories first... */
1125 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1127 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1128 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1130 /* Handle "." and ".." as special case and move them at the very first beginning. */
1131 if (order1==TO_DIR && order2==TO_DIR) {
1132 order1 = TypeOrderFromDirname(fd1->cFileName);
1133 order2 = TypeOrderFromDirname(fd2->cFileName);
1136 return order2==order1? 0: order1<order2? -1: 1;
1140 static int compareName(const void* arg1, const void* arg2)
1142 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1143 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1145 int cmp = compareType(fd1, fd2);
1146 if (cmp)
1147 return cmp;
1149 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1152 static int compareExt(const void* arg1, const void* arg2)
1154 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1155 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1156 const TCHAR *name1, *name2, *ext1, *ext2;
1158 int cmp = compareType(fd1, fd2);
1159 if (cmp)
1160 return cmp;
1162 name1 = fd1->cFileName;
1163 name2 = fd2->cFileName;
1165 ext1 = _tcsrchr(name1, TEXT('.'));
1166 ext2 = _tcsrchr(name2, TEXT('.'));
1168 if (ext1)
1169 ext1++;
1170 else
1171 ext1 = sEmpty;
1173 if (ext2)
1174 ext2++;
1175 else
1176 ext2 = sEmpty;
1178 cmp = lstrcmpi(ext1, ext2);
1179 if (cmp)
1180 return cmp;
1182 return lstrcmpi(name1, name2);
1185 static int compareSize(const void* arg1, const void* arg2)
1187 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1188 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1190 int cmp = compareType(fd1, fd2);
1191 if (cmp)
1192 return cmp;
1194 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1196 if (cmp < 0)
1197 return -1;
1198 else if (cmp > 0)
1199 return 1;
1201 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1203 return cmp<0? -1: cmp>0? 1: 0;
1206 static int compareDate(const void* arg1, const void* arg2)
1208 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1209 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1211 int cmp = compareType(fd1, fd2);
1212 if (cmp)
1213 return cmp;
1215 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1219 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1220 compareName, /* SORT_NAME */
1221 compareExt, /* SORT_EXT */
1222 compareSize, /* SORT_SIZE */
1223 compareDate /* SORT_DATE */
1227 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1229 Entry* entry = dir->down;
1230 Entry** array, **p;
1231 int len;
1233 len = 0;
1234 for(entry=dir->down; entry; entry=entry->next)
1235 len++;
1237 if (len) {
1238 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1240 p = array;
1241 for(entry=dir->down; entry; entry=entry->next)
1242 *p++ = entry;
1244 /* call qsort with the appropriate compare function */
1245 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1247 dir->down = array[0];
1249 for(p=array; --len; p++)
1250 p[0]->next = p[1];
1252 (*p)->next = 0;
1254 HeapFree(GetProcessHeap(), 0, array);
1259 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1261 TCHAR buffer[MAX_PATH];
1262 Entry* entry;
1263 LPCTSTR s;
1264 PTSTR d;
1266 #ifdef _SHELL_FOLDERS
1267 if (dir->etype == ET_SHELL)
1269 read_directory_shell(dir, hwnd);
1271 if (Globals.prescan_node) {
1272 s = path;
1273 d = buffer;
1275 while(*s)
1276 *d++ = *s++;
1278 *d++ = TEXT('\\');
1280 for(entry=dir->down; entry; entry=entry->next)
1281 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1282 read_directory_shell(entry, hwnd);
1283 SortDirectory(entry, sortOrder);
1287 else
1288 #endif
1289 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1290 if (dir->etype == ET_UNIX)
1292 read_directory_unix(dir, path);
1294 if (Globals.prescan_node) {
1295 s = path;
1296 d = buffer;
1298 while(*s)
1299 *d++ = *s++;
1301 *d++ = TEXT('/');
1303 for(entry=dir->down; entry; entry=entry->next)
1304 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1305 lstrcpy(d, entry->data.cFileName);
1306 read_directory_unix(entry, buffer);
1307 SortDirectory(entry, sortOrder);
1311 else
1312 #endif
1314 read_directory_win(dir, path);
1316 if (Globals.prescan_node) {
1317 s = path;
1318 d = buffer;
1320 while(*s)
1321 *d++ = *s++;
1323 *d++ = TEXT('\\');
1325 for(entry=dir->down; entry; entry=entry->next)
1326 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1327 lstrcpy(d, entry->data.cFileName);
1328 read_directory_win(entry, buffer);
1329 SortDirectory(entry, sortOrder);
1334 SortDirectory(dir, sortOrder);
1338 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1340 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1341 static const TCHAR sSlash[] = {'/', '\0'};
1342 #endif
1343 static const TCHAR sBackslash[] = {'\\', '\0'};
1345 #ifdef _SHELL_FOLDERS
1346 if (pidl)
1348 /* read shell namespace tree */
1349 root->drive_type = DRIVE_UNKNOWN;
1350 drv[0] = '\\';
1351 drv[1] = '\0';
1352 load_string(root->volname, IDS_DESKTOP);
1353 root->fs_flags = 0;
1354 load_string(root->fs, IDS_SHELL);
1356 return read_tree_shell(root, pidl, sortOrder, hwnd);
1358 else
1359 #endif
1360 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1361 if (*path == '/')
1363 /* read unix file system tree */
1364 root->drive_type = GetDriveType(path);
1366 lstrcat(drv, sSlash);
1367 load_string(root->volname, IDS_ROOT_FS);
1368 root->fs_flags = 0;
1369 load_string(root->fs, IDS_UNIXFS);
1371 lstrcpy(root->path, sSlash);
1373 return read_tree_unix(root, path, sortOrder, hwnd);
1375 #endif
1377 /* read WIN32 file system tree */
1378 root->drive_type = GetDriveType(path);
1380 lstrcat(drv, sBackslash);
1381 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1383 lstrcpy(root->path, drv);
1385 return read_tree_win(root, path, sortOrder, hwnd);
1389 /* flags to filter different file types */
1390 enum TYPE_FILTER {
1391 TF_DIRECTORIES = 0x01,
1392 TF_PROGRAMS = 0x02,
1393 TF_DOCUMENTS = 0x04,
1394 TF_OTHERS = 0x08,
1395 TF_HIDDEN = 0x10,
1396 TF_ALL = 0x1F
1400 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1402 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1403 TCHAR b1[BUFFER_LEN];
1404 static const TCHAR sAsterics[] = {'*', '\0'};
1406 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1407 Root* root = &child->root;
1408 Entry* entry;
1410 memset(child, 0, sizeof(ChildWnd));
1412 child->left.treePane = TRUE;
1413 child->left.visible_cols = 0;
1415 child->right.treePane = FALSE;
1416 #ifndef _NO_EXTENSIONS
1417 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1418 #else
1419 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1420 #endif
1422 child->pos.length = sizeof(WINDOWPLACEMENT);
1423 child->pos.flags = 0;
1424 child->pos.showCmd = SW_SHOWNORMAL;
1425 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1426 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1427 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1428 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1430 child->focus_pane = 0;
1431 child->split_pos = DEFAULT_SPLIT_POS;
1432 child->sortOrder = SORT_NAME;
1433 child->header_wdths_ok = FALSE;
1435 if (path)
1437 lstrcpy(child->path, path);
1439 _tsplitpath(path, drv, dir, name, ext);
1442 lstrcpy(child->filter_pattern, sAsterics);
1443 child->filter_flags = TF_ALL;
1445 root->entry.level = 0;
1447 entry = read_tree(root, path, pidl, drv, child->sortOrder, hwnd);
1449 #ifdef _SHELL_FOLDERS
1450 if (root->entry.etype == ET_SHELL)
1451 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1452 else
1453 #endif
1454 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1456 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1458 child->left.root = &root->entry;
1459 child->right.root = NULL;
1461 set_curdir(child, entry, 0, hwnd);
1463 return child;
1467 /* free all memory associated with a child window */
1468 static void free_child_window(ChildWnd* child)
1470 free_entries(&child->root.entry);
1471 free(child);
1475 /* get full path of specified directory entry */
1476 static void get_path(Entry* dir, PTSTR path)
1478 Entry* entry;
1479 int len = 0;
1480 int level = 0;
1482 #ifdef _SHELL_FOLDERS
1483 if (dir->etype == ET_SHELL)
1485 SFGAOF attribs;
1486 HRESULT hr = S_OK;
1488 path[0] = TEXT('\0');
1490 attribs = 0;
1492 if (dir->folder)
1493 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1495 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1496 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1498 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1501 else
1502 #endif
1504 for(entry=dir; entry; level++) {
1505 LPCTSTR name;
1506 int l;
1509 LPCTSTR s;
1510 name = entry->data.cFileName;
1511 s = name;
1513 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1514 l++;
1517 if (entry->up) {
1518 if (l > 0) {
1519 memmove(path+l+1, path, len*sizeof(TCHAR));
1520 memcpy(path+1, name, l*sizeof(TCHAR));
1521 len += l+1;
1523 #ifndef _NO_EXTENSIONS
1524 if (entry->etype == ET_UNIX)
1525 path[0] = TEXT('/');
1526 else
1527 #endif
1528 path[0] = TEXT('\\');
1531 entry = entry->up;
1532 } else {
1533 memmove(path+l, path, len*sizeof(TCHAR));
1534 memcpy(path, name, l*sizeof(TCHAR));
1535 len += l;
1536 break;
1540 if (!level) {
1541 #ifndef _NO_EXTENSIONS
1542 if (entry->etype == ET_UNIX)
1543 path[len++] = TEXT('/');
1544 else
1545 #endif
1546 path[len++] = TEXT('\\');
1549 path[len] = TEXT('\0');
1554 static void resize_frame_rect(HWND hwnd, PRECT prect)
1556 int new_top;
1557 RECT rt;
1559 if (IsWindowVisible(Globals.htoolbar)) {
1560 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1561 GetClientRect(Globals.htoolbar, &rt);
1562 prect->top = rt.bottom+3;
1563 prect->bottom -= rt.bottom+3;
1566 if (IsWindowVisible(Globals.hdrivebar)) {
1567 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1568 GetClientRect(Globals.hdrivebar, &rt);
1569 new_top = --prect->top + rt.bottom+3;
1570 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1571 prect->top = new_top;
1572 prect->bottom -= rt.bottom+2;
1575 if (IsWindowVisible(Globals.hstatusbar)) {
1576 int parts[] = {300, 500};
1578 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1579 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1580 GetClientRect(Globals.hstatusbar, &rt);
1581 prect->bottom -= rt.bottom;
1584 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1587 static void resize_frame(HWND hwnd, int cx, int cy)
1589 RECT rect;
1591 rect.left = 0;
1592 rect.top = 0;
1593 rect.right = cx;
1594 rect.bottom = cy;
1596 resize_frame_rect(hwnd, &rect);
1599 static void resize_frame_client(HWND hwnd)
1601 RECT rect;
1603 GetClientRect(hwnd, &rect);
1605 resize_frame_rect(hwnd, &rect);
1609 static HHOOK hcbthook;
1610 static ChildWnd* newchild = NULL;
1612 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1614 if (code==HCBT_CREATEWND && newchild) {
1615 ChildWnd* child = newchild;
1616 newchild = NULL;
1618 child->hwnd = (HWND) wparam;
1619 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1622 return CallNextHookEx(hcbthook, code, wparam, lparam);
1625 static HWND create_child_window(ChildWnd* child)
1627 MDICREATESTRUCT mcs;
1628 int idx;
1630 mcs.szClass = sWINEFILETREE;
1631 mcs.szTitle = (LPTSTR)child->path;
1632 mcs.hOwner = Globals.hInstance;
1633 mcs.x = child->pos.rcNormalPosition.left;
1634 mcs.y = child->pos.rcNormalPosition.top;
1635 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1636 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1637 mcs.style = 0;
1638 mcs.lParam = 0;
1640 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1642 newchild = child;
1643 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1644 if (!child->hwnd) {
1645 UnhookWindowsHookEx(hcbthook);
1646 return 0;
1649 UnhookWindowsHookEx(hcbthook);
1651 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1652 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1654 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
1655 ListBox_SetCurSel(child->left.hwnd, idx);
1657 return child->hwnd;
1661 struct ExecuteDialog {
1662 TCHAR cmd[MAX_PATH];
1663 int cmdshow;
1666 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1668 static struct ExecuteDialog* dlg;
1670 switch(nmsg) {
1671 case WM_INITDIALOG:
1672 dlg = (struct ExecuteDialog*) lparam;
1673 return 1;
1675 case WM_COMMAND: {
1676 int id = (int)wparam;
1678 if (id == IDOK) {
1679 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1680 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1681 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1682 EndDialog(hwnd, id);
1683 } else if (id == IDCANCEL)
1684 EndDialog(hwnd, id);
1686 return 1;}
1689 return 0;
1693 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1695 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1697 switch(nmsg) {
1698 case WM_INITDIALOG:
1699 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1700 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1701 return 1;
1703 case WM_COMMAND: {
1704 int id = (int)wparam;
1706 switch(id) {
1707 case IDOK: {
1708 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1709 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1710 EndDialog(hwnd, id);
1711 break;}
1713 case IDCANCEL:
1714 EndDialog(hwnd, id);
1715 break;
1717 case 254:
1718 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1719 break;
1722 return 1;
1726 return 0;
1730 struct FilterDialog {
1731 TCHAR pattern[MAX_PATH];
1732 int flags;
1735 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1737 static struct FilterDialog* dlg;
1739 switch(nmsg) {
1740 case WM_INITDIALOG:
1741 dlg = (struct FilterDialog*) lparam;
1742 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1743 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES), (dlg->flags&TF_DIRECTORIES? BST_CHECKED: BST_UNCHECKED));
1744 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS), dlg->flags&TF_PROGRAMS? BST_CHECKED: BST_UNCHECKED);
1745 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS), dlg->flags&TF_DOCUMENTS? BST_CHECKED: BST_UNCHECKED);
1746 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS), dlg->flags&TF_OTHERS? BST_CHECKED: BST_UNCHECKED);
1747 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN), dlg->flags&TF_HIDDEN? BST_CHECKED: BST_UNCHECKED);
1748 return 1;
1750 case WM_COMMAND: {
1751 int id = (int)wparam;
1753 if (id == IDOK) {
1754 int flags = 0;
1756 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1758 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES))&BST_CHECKED? TF_DIRECTORIES: 0;
1759 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS))&BST_CHECKED? TF_PROGRAMS: 0;
1760 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS))&BST_CHECKED? TF_DOCUMENTS: 0;
1761 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS))&BST_CHECKED? TF_OTHERS: 0;
1762 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN))&BST_CHECKED? TF_HIDDEN: 0;
1764 dlg->flags = flags;
1766 EndDialog(hwnd, id);
1767 } else if (id == IDCANCEL)
1768 EndDialog(hwnd, id);
1770 return 1;}
1773 return 0;
1777 struct PropertiesDialog {
1778 TCHAR path[MAX_PATH];
1779 Entry entry;
1780 void* pVersionData;
1783 /* Structure used to store enumerated languages and code pages. */
1784 struct LANGANDCODEPAGE {
1785 WORD wLanguage;
1786 WORD wCodePage;
1787 } *lpTranslate;
1789 static LPCSTR InfoStrings[] = {
1790 "Comments",
1791 "CompanyName",
1792 "FileDescription",
1793 "FileVersion",
1794 "InternalName",
1795 "LegalCopyright",
1796 "LegalTrademarks",
1797 "OriginalFilename",
1798 "PrivateBuild",
1799 "ProductName",
1800 "ProductVersion",
1801 "SpecialBuild",
1802 NULL
1805 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1807 int idx = ListBox_GetCurSel(hlbox);
1809 if (idx != LB_ERR) {
1810 LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx);
1812 if (pValue)
1813 SetWindowText(hedit, pValue);
1817 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1819 static TCHAR sBackSlash[] = {'\\','\0'};
1820 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'};
1821 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1822 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1823 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1825 if (dwVersionDataLen) {
1826 dlg->pVersionData = malloc(dwVersionDataLen);
1828 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1829 LPVOID pVal;
1830 UINT nValLen;
1832 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1833 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1834 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1835 char buffer[BUFFER_LEN];
1837 sprintf(buffer, "%d.%d.%d.%d",
1838 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1839 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1841 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1845 /* Read the list of languages and code pages. */
1846 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1847 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1848 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1850 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1852 /* Read the file description for each language and code page. */
1853 for(; pTranslate<pEnd; ++pTranslate) {
1854 LPCSTR* p;
1856 for(p=InfoStrings; *p; ++p) {
1857 TCHAR subblock[200];
1858 #ifdef UNICODE
1859 TCHAR infoStr[100];
1860 #endif
1861 LPCTSTR pTxt;
1862 UINT nValLen;
1864 LPCSTR pInfoString = *p;
1865 #ifdef UNICODE
1866 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1867 #else
1868 #define infoStr pInfoString
1869 #endif
1870 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1872 /* Retrieve file description for language and code page */
1873 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1874 int idx = ListBox_AddString(hlbox, infoStr);
1875 ListBox_SetItemData(hlbox, idx, pTxt);
1880 ListBox_SetCurSel(hlbox, 0);
1882 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1888 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1890 static struct PropertiesDialog* dlg;
1892 switch(nmsg) {
1893 case WM_INITDIALOG: {
1894 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1895 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1896 LPWIN32_FIND_DATA pWFD;
1897 ULONGLONG size;
1899 dlg = (struct PropertiesDialog*) lparam;
1900 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
1902 GetWindowText(hwnd, b1, MAX_PATH);
1903 wsprintf(b2, b1, pWFD->cFileName);
1904 SetWindowText(hwnd, b2);
1906 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1907 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1909 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
1910 _stprintf(b1, sLongNumFmt, size);
1911 wsprintf(b2, sByteFmt, b1);
1912 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1914 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1915 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1917 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_READONLY), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY? BST_CHECKED: BST_UNCHECKED));
1918 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_ARCHIVE), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE? BST_CHECKED: BST_UNCHECKED));
1919 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_COMPRESSED), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED? BST_CHECKED: BST_UNCHECKED));
1920 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_HIDDEN), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN? BST_CHECKED: BST_UNCHECKED));
1921 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_SYSTEM), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM? BST_CHECKED: BST_UNCHECKED));
1923 CheckForFileInfo(dlg, hwnd, dlg->path);
1924 return 1;}
1926 case WM_COMMAND: {
1927 int id = (int)wparam;
1929 switch(HIWORD(wparam)) {
1930 case LBN_SELCHANGE: {
1931 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1932 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1933 break;
1936 case BN_CLICKED:
1937 if (id==IDOK || id==IDCANCEL)
1938 EndDialog(hwnd, id);
1941 return 1;}
1943 case WM_NCDESTROY:
1944 free(dlg->pVersionData);
1945 dlg->pVersionData = NULL;
1946 break;
1949 return 0;
1952 static void show_properties_dlg(Entry* entry, HWND hwnd)
1954 struct PropertiesDialog dlg;
1956 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1957 get_path(entry, dlg.path);
1958 memcpy(&dlg.entry, entry, sizeof(Entry));
1960 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1964 #ifndef _NO_EXTENSIONS
1966 static struct FullScreenParameters {
1967 BOOL mode;
1968 RECT orgPos;
1969 BOOL wasZoomed;
1970 } g_fullscreen = {
1971 FALSE, /* mode */
1972 {0, 0, 0, 0},
1973 FALSE
1976 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1978 RECT rt;
1980 if (!IsIconic(hwnd))
1981 GetClientRect(hwnd, prect);
1982 else {
1983 WINDOWPLACEMENT wp;
1985 GetWindowPlacement(hwnd, &wp);
1987 prect->left = prect->top = 0;
1988 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1989 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1990 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1991 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1992 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1995 if (IsWindowVisible(Globals.htoolbar)) {
1996 GetClientRect(Globals.htoolbar, &rt);
1997 prect->top += rt.bottom+2;
2000 if (IsWindowVisible(Globals.hdrivebar)) {
2001 GetClientRect(Globals.hdrivebar, &rt);
2002 prect->top += rt.bottom+2;
2005 if (IsWindowVisible(Globals.hstatusbar)) {
2006 GetClientRect(Globals.hstatusbar, &rt);
2007 prect->bottom -= rt.bottom;
2011 static BOOL toggle_fullscreen(HWND hwnd)
2013 RECT rt;
2015 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2016 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2017 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2019 Frame_CalcFrameClient(hwnd, &rt);
2020 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2021 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2023 rt.left = g_fullscreen.orgPos.left-rt.left;
2024 rt.top = g_fullscreen.orgPos.top-rt.top;
2025 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2026 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2028 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2029 } else {
2030 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2031 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2032 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2034 if (g_fullscreen.wasZoomed)
2035 ShowWindow(hwnd, WS_MAXIMIZE);
2038 return g_fullscreen.mode;
2041 static void fullscreen_move(HWND hwnd)
2043 RECT rt, pos;
2044 GetWindowRect(hwnd, &pos);
2046 Frame_CalcFrameClient(hwnd, &rt);
2047 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2048 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2050 rt.left = pos.left-rt.left;
2051 rt.top = pos.top-rt.top;
2052 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2053 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2055 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2058 #endif
2061 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2063 BOOL vis = IsWindowVisible(hchild);
2065 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2067 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2069 #ifndef _NO_EXTENSIONS
2070 if (g_fullscreen.mode)
2071 fullscreen_move(hwnd);
2072 #endif
2074 resize_frame_client(hwnd);
2077 static BOOL activate_drive_window(LPCTSTR path)
2079 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2080 HWND child_wnd;
2082 _tsplitpath(path, drv1, 0, 0, 0);
2084 /* search for a already open window for the same drive */
2085 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2086 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2088 if (child) {
2089 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2091 if (!lstrcmpi(drv2, drv1)) {
2092 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2094 if (IsMinimized(child_wnd))
2095 ShowWindow(child_wnd, SW_SHOWNORMAL);
2097 return TRUE;
2102 return FALSE;
2105 static BOOL activate_fs_window(LPCTSTR filesys)
2107 HWND child_wnd;
2109 /* search for a already open window of the given file system name */
2110 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2111 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2113 if (child) {
2114 if (!lstrcmpi(child->root.fs, filesys)) {
2115 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2117 if (IsMinimized(child_wnd))
2118 ShowWindow(child_wnd, SW_SHOWNORMAL);
2120 return TRUE;
2125 return FALSE;
2128 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2130 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2132 switch(nmsg) {
2133 case WM_CLOSE:
2134 DestroyWindow(hwnd);
2136 /* clear handle variables */
2137 Globals.hMenuFrame = 0;
2138 Globals.hMenuView = 0;
2139 Globals.hMenuOptions = 0;
2140 Globals.hMainWnd = 0;
2141 Globals.hmdiclient = 0;
2142 Globals.hdrivebar = 0;
2143 break;
2145 case WM_DESTROY:
2146 PostQuitMessage(0);
2147 break;
2149 case WM_INITMENUPOPUP: {
2150 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2152 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2153 return 0;
2154 break;}
2156 case WM_COMMAND: {
2157 UINT cmd = LOWORD(wparam);
2158 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2160 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2161 break;
2163 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2164 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2165 ChildWnd* child;
2166 LPCTSTR root = Globals.drives;
2167 int i;
2169 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2170 while(*root)
2171 root++;
2173 if (activate_drive_window(root))
2174 return 0;
2176 _tsplitpath(root, drv, 0, 0, 0);
2178 if (!SetCurrentDirectory(drv)) {
2179 display_error(hwnd, GetLastError());
2180 return 0;
2183 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2184 child = alloc_child_window(path, NULL, hwnd);
2186 if (!create_child_window(child))
2187 free(child);
2188 } else switch(cmd) {
2189 case ID_FILE_EXIT:
2190 SendMessage(hwnd, WM_CLOSE, 0, 0);
2191 break;
2193 case ID_WINDOW_NEW: {
2194 TCHAR path[MAX_PATH];
2195 ChildWnd* child;
2197 GetCurrentDirectory(MAX_PATH, path);
2198 child = alloc_child_window(path, NULL, hwnd);
2200 if (!create_child_window(child))
2201 free(child);
2202 break;}
2204 case ID_REFRESH:
2205 refresh_drives();
2206 break;
2208 case ID_WINDOW_CASCADE:
2209 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2210 break;
2212 case ID_WINDOW_TILE_HORZ:
2213 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2214 break;
2216 case ID_WINDOW_TILE_VERT:
2217 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2218 break;
2220 case ID_WINDOW_ARRANGE:
2221 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2222 break;
2224 case ID_SELECT_FONT: {
2225 TCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
2226 CHOOSEFONT chFont;
2227 LOGFONT lFont;
2229 HDC hdc = GetDC(hwnd);
2230 chFont.lStructSize = sizeof(CHOOSEFONT);
2231 chFont.hwndOwner = hwnd;
2232 chFont.hDC = NULL;
2233 chFont.lpLogFont = &lFont;
2234 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
2235 chFont.rgbColors = RGB(0,0,0);
2236 chFont.lCustData = 0;
2237 chFont.lpfnHook = NULL;
2238 chFont.lpTemplateName = NULL;
2239 chFont.hInstance = Globals.hInstance;
2240 chFont.lpszStyle = NULL;
2241 chFont.nFontType = SIMULATED_FONTTYPE;
2242 chFont.nSizeMin = 0;
2243 chFont.nSizeMax = 24;
2245 if (ChooseFont(&chFont)) {
2246 HWND childWnd;
2247 HFONT hFontOld;
2249 DeleteObject(Globals.hfont);
2250 Globals.hfont = CreateFontIndirect(&lFont);
2251 hFontOld = SelectFont(hdc, Globals.hfont);
2252 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2254 /* change font in all open child windows */
2255 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
2256 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(childWnd, GWLP_USERDATA);
2257 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
2258 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
2259 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2260 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2261 InvalidateRect(child->left.hwnd, NULL, TRUE);
2262 InvalidateRect(child->right.hwnd, NULL, TRUE);
2265 SelectFont(hdc, hFontOld);
2267 else if (CommDlgExtendedError()) {
2268 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
2269 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
2270 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
2273 ReleaseDC(hwnd, hdc);
2274 break;
2277 case ID_VIEW_TOOL_BAR:
2278 toggle_child(hwnd, cmd, Globals.htoolbar);
2279 break;
2281 case ID_VIEW_DRIVE_BAR:
2282 toggle_child(hwnd, cmd, Globals.hdrivebar);
2283 break;
2285 case ID_VIEW_STATUSBAR:
2286 toggle_child(hwnd, cmd, Globals.hstatusbar);
2287 break;
2289 case ID_EXECUTE: {
2290 struct ExecuteDialog dlg;
2292 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2294 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2295 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2297 if ((int)hinst <= 32)
2298 display_error(hwnd, GetLastError());
2300 break;}
2302 case ID_CONNECT_NETWORK_DRIVE: {
2303 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2304 if (ret == NO_ERROR)
2305 refresh_drives();
2306 else if (ret != (DWORD)-1) {
2307 if (ret == ERROR_EXTENDED_ERROR)
2308 display_network_error(hwnd);
2309 else
2310 display_error(hwnd, ret);
2312 break;}
2314 case ID_DISCONNECT_NETWORK_DRIVE: {
2315 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2316 if (ret == NO_ERROR)
2317 refresh_drives();
2318 else if (ret != (DWORD)-1) {
2319 if (ret == ERROR_EXTENDED_ERROR)
2320 display_network_error(hwnd);
2321 else
2322 display_error(hwnd, ret);
2324 break;}
2326 case ID_FORMAT_DISK: {
2327 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2328 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2329 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2330 SetErrorMode(sem_org); /* Put it back the way it was. */
2331 break;}
2333 case ID_HELP:
2334 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2335 break;
2337 #ifndef _NO_EXTENSIONS
2338 case ID_VIEW_FULLSCREEN:
2339 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2340 break;
2342 #ifdef __WINE__
2343 case ID_DRIVE_UNIX_FS: {
2344 TCHAR path[MAX_PATH];
2345 #ifdef UNICODE
2346 char cpath[MAX_PATH];
2347 #endif
2348 ChildWnd* child;
2350 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2351 break;
2353 #ifdef UNICODE
2354 getcwd(cpath, MAX_PATH);
2355 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2356 #else
2357 getcwd(path, MAX_PATH);
2358 #endif
2359 child = alloc_child_window(path, NULL, hwnd);
2361 if (!create_child_window(child))
2362 free(child);
2363 break;}
2364 #endif
2365 #ifdef _SHELL_FOLDERS
2366 case ID_DRIVE_SHELL_NS: {
2367 TCHAR path[MAX_PATH];
2368 ChildWnd* child;
2370 if (activate_fs_window(RS(b1,IDS_SHELL)))
2371 break;
2373 GetCurrentDirectory(MAX_PATH, path);
2374 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2376 if (!create_child_window(child))
2377 free(child);
2378 break;}
2379 #endif
2380 #endif
2382 /*TODO: There are even more menu items! */
2384 #ifndef _NO_EXTENSIONS
2385 #ifdef __WINE__
2386 case ID_LICENSE:
2387 WineLicense(Globals.hMainWnd);
2388 break;
2390 case ID_NO_WARRANTY:
2391 WineWarranty(Globals.hMainWnd);
2392 break;
2394 case ID_ABOUT_WINE:
2395 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2396 break;
2397 #endif
2399 case ID_ABOUT:
2400 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2401 break;
2402 #endif /* _NO_EXTENSIONS */
2404 default:
2405 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2406 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2407 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2408 (cmd<SC_SIZE || cmd>SC_RESTORE))
2409 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2411 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2413 break;}
2415 case WM_SIZE:
2416 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2417 break; /* do not pass message to DefFrameProc */
2419 #ifndef _NO_EXTENSIONS
2420 case WM_GETMINMAXINFO: {
2421 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2423 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2424 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2425 break;}
2427 case FRM_CALC_CLIENT:
2428 frame_get_clientspace(hwnd, (PRECT)lparam);
2429 return TRUE;
2430 #endif /* _NO_EXTENSIONS */
2432 default:
2433 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2436 return 0;
2440 static TCHAR g_pos_names[COLUMNS][20] = {
2441 {'\0'} /* symbol */
2444 static const int g_pos_align[] = {
2446 HDF_LEFT, /* Name */
2447 HDF_RIGHT, /* Size */
2448 HDF_LEFT, /* CDate */
2449 #ifndef _NO_EXTENSIONS
2450 HDF_LEFT, /* ADate */
2451 HDF_LEFT, /* MDate */
2452 HDF_LEFT, /* Index */
2453 HDF_CENTER, /* Links */
2454 #endif
2455 HDF_CENTER, /* Attributes */
2456 #ifndef _NO_EXTENSIONS
2457 HDF_LEFT /* Security */
2458 #endif
2461 static void resize_tree(ChildWnd* child, int cx, int cy)
2463 HDWP hdwp = BeginDeferWindowPos(4);
2464 RECT rt;
2466 rt.left = 0;
2467 rt.top = 0;
2468 rt.right = cx;
2469 rt.bottom = cy;
2471 cx = child->split_pos + SPLIT_WIDTH/2;
2473 #ifndef _NO_EXTENSIONS
2475 WINDOWPOS wp;
2476 HD_LAYOUT hdl;
2478 hdl.prc = &rt;
2479 hdl.pwpos = &wp;
2481 Header_Layout(child->left.hwndHeader, &hdl);
2483 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2484 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2485 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2486 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2488 #endif /* _NO_EXTENSIONS */
2490 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);
2491 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2493 EndDeferWindowPos(hdwp);
2497 #ifndef _NO_EXTENSIONS
2499 static HWND create_header(HWND parent, Pane* pane, int id)
2501 HD_ITEM hdi;
2502 int idx;
2504 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2505 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2506 if (!hwnd)
2507 return 0;
2509 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2511 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2513 for(idx=0; idx<COLUMNS; idx++) {
2514 hdi.pszText = g_pos_names[idx];
2515 hdi.fmt = HDF_STRING | g_pos_align[idx];
2516 hdi.cxy = pane->widths[idx];
2517 Header_InsertItem(hwnd, idx, &hdi);
2520 return hwnd;
2523 #endif /* _NO_EXTENSIONS */
2526 static void init_output(HWND hwnd)
2528 static const TCHAR s1000[] = {'1','0','0','0','\0'};
2530 TCHAR b[16];
2531 HFONT old_font;
2532 HDC hdc = GetDC(hwnd);
2534 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2535 Globals.num_sep = b[1];
2536 else
2537 Globals.num_sep = TEXT('.');
2539 old_font = SelectFont(hdc, Globals.hfont);
2540 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2541 SelectFont(hdc, old_font);
2542 ReleaseDC(hwnd, hdc);
2545 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2548 /* calculate preferred width for all visible columns */
2550 static BOOL calc_widths(Pane* pane, BOOL anyway)
2552 int col, x, cx, spc=3*Globals.spaceSize.cx;
2553 int entries = ListBox_GetCount(pane->hwnd);
2554 int orgWidths[COLUMNS];
2555 int orgPositions[COLUMNS+1];
2556 HFONT hfontOld;
2557 HDC hdc;
2558 int cnt;
2560 if (!anyway) {
2561 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2562 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2565 for(col=0; col<COLUMNS; col++)
2566 pane->widths[col] = 0;
2568 hdc = GetDC(pane->hwnd);
2569 hfontOld = SelectFont(hdc, Globals.hfont);
2571 for(cnt=0; cnt<entries; cnt++) {
2572 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2574 DRAWITEMSTRUCT dis;
2576 dis.CtlType = 0;
2577 dis.CtlID = 0;
2578 dis.itemID = 0;
2579 dis.itemAction = 0;
2580 dis.itemState = 0;
2581 dis.hwndItem = pane->hwnd;
2582 dis.hDC = hdc;
2583 dis.rcItem.left = 0;
2584 dis.rcItem.top = 0;
2585 dis.rcItem.right = 0;
2586 dis.rcItem.bottom = 0;
2587 /*dis.itemData = 0; */
2589 draw_item(pane, &dis, entry, COLUMNS);
2592 SelectObject(hdc, hfontOld);
2593 ReleaseDC(pane->hwnd, hdc);
2595 x = 0;
2596 for(col=0; col<COLUMNS; col++) {
2597 pane->positions[col] = x;
2598 cx = pane->widths[col];
2600 if (cx) {
2601 cx += spc;
2603 if (cx < IMAGE_WIDTH)
2604 cx = IMAGE_WIDTH;
2606 pane->widths[col] = cx;
2609 x += cx;
2612 pane->positions[COLUMNS] = x;
2614 ListBox_SetHorizontalExtent(pane->hwnd, x);
2616 /* no change? */
2617 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2618 return FALSE;
2620 /* don't move, if only collapsing an entry */
2621 if (!anyway && pane->widths[0]<orgWidths[0] &&
2622 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2623 pane->widths[0] = orgWidths[0];
2624 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2626 return FALSE;
2629 InvalidateRect(pane->hwnd, 0, TRUE);
2631 return TRUE;
2635 /* calculate one preferred column width */
2637 static void calc_single_width(Pane* pane, int col)
2639 HFONT hfontOld;
2640 int x, cx;
2641 int entries = ListBox_GetCount(pane->hwnd);
2642 int cnt;
2643 HDC hdc;
2645 pane->widths[col] = 0;
2647 hdc = GetDC(pane->hwnd);
2648 hfontOld = SelectFont(hdc, Globals.hfont);
2650 for(cnt=0; cnt<entries; cnt++) {
2651 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2652 DRAWITEMSTRUCT dis;
2654 dis.CtlType = 0;
2655 dis.CtlID = 0;
2656 dis.itemID = 0;
2657 dis.itemAction = 0;
2658 dis.itemState = 0;
2659 dis.hwndItem = pane->hwnd;
2660 dis.hDC = hdc;
2661 dis.rcItem.left = 0;
2662 dis.rcItem.top = 0;
2663 dis.rcItem.right = 0;
2664 dis.rcItem.bottom = 0;
2665 /*dis.itemData = 0; */
2667 draw_item(pane, &dis, entry, col);
2670 SelectObject(hdc, hfontOld);
2671 ReleaseDC(pane->hwnd, hdc);
2673 cx = pane->widths[col];
2675 if (cx) {
2676 cx += 3*Globals.spaceSize.cx;
2678 if (cx < IMAGE_WIDTH)
2679 cx = IMAGE_WIDTH;
2682 pane->widths[col] = cx;
2684 x = pane->positions[col] + cx;
2686 for(; col<COLUMNS; ) {
2687 pane->positions[++col] = x;
2688 x += pane->widths[col];
2691 ListBox_SetHorizontalExtent(pane->hwnd, x);
2695 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2697 for( ; *str&&*pattern; str++,pattern++) {
2698 if (*pattern == '*') {
2699 do pattern++;
2700 while(*pattern == '*');
2702 if (!*pattern)
2703 return TRUE;
2705 for(; *str; str++)
2706 if (*str==*pattern && pattern_match(str, pattern))
2707 return TRUE;
2709 return FALSE;
2711 else if (*str!=*pattern && *pattern!='?')
2712 return FALSE;
2715 if (*str || *pattern)
2716 if (*pattern!='*' || pattern[1]!='\0')
2717 return FALSE;
2719 return TRUE;
2722 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2724 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2726 lstrcpy(b1, str);
2727 lstrcpy(b2, pattern);
2728 CharUpper(b1);
2729 CharUpper(b2);
2731 return pattern_match(b1, b2);
2735 enum FILE_TYPE {
2736 FT_OTHER = 0,
2737 FT_EXECUTABLE = 1,
2738 FT_DOCUMENT = 2
2741 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2744 /* insert listbox entries after index idx */
2746 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2748 Entry* entry = dir;
2750 if (!entry)
2751 return idx;
2753 ShowWindow(pane->hwnd, SW_HIDE);
2755 for(; entry; entry=entry->next) {
2756 #ifndef _LEFT_FILES
2757 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2758 continue;
2759 #endif
2761 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2762 /* don't display entries "." and ".." in the left pane */
2763 if (pane->treePane && entry->data.cFileName[0]==TEXT('.'))
2764 if (
2765 #ifndef _NO_EXTENSIONS
2766 entry->data.cFileName[1]==TEXT('\0') ||
2767 #endif
2768 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2769 continue;
2771 /* filter directories in right pane */
2772 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2773 continue;
2776 /* filter using the file name pattern */
2777 if (pattern)
2778 if (!pattern_imatch(entry->data.cFileName, pattern))
2779 continue;
2781 /* filter system and hidden files */
2782 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2783 continue;
2785 /* filter looking at the file type */
2786 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2787 switch(get_file_type(entry->data.cFileName)) {
2788 case FT_EXECUTABLE:
2789 if (!(filter_flags & TF_PROGRAMS))
2790 continue;
2791 break;
2793 case FT_DOCUMENT:
2794 if (!(filter_flags & TF_DOCUMENTS))
2795 continue;
2796 break;
2798 default: /* TF_OTHERS */
2799 if (!(filter_flags & TF_OTHERS))
2800 continue;
2803 if (idx != -1)
2804 idx++;
2806 ListBox_InsertItemData(pane->hwnd, idx, entry);
2808 if (pane->treePane && entry->expanded)
2809 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2812 ShowWindow(pane->hwnd, SW_SHOW);
2814 return idx;
2818 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2820 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2821 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2822 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2824 float fBytes = (float)bytes;
2826 if (bytes >= 1073741824) /* 1 GB */
2827 wsprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2828 else if (bytes >= 1048576) /* 1 MB */
2829 wsprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2830 else if (bytes >= 1024) /* 1 kB */
2831 wsprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2832 else
2833 _stprintf(buffer, sLongNumFmt, bytes);
2836 static void set_space_status(void)
2838 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2839 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2841 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2842 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2843 format_bytes(b2, ulTotalBytes.QuadPart);
2844 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2845 } else
2846 lstrcpy(buffer, sQMarks);
2848 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2852 static WNDPROC g_orgTreeWndProc;
2854 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2856 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2858 static int s_init = 0;
2859 Entry* entry = pane->root;
2861 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2862 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2863 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2865 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2866 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2868 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2870 /* insert entries into listbox */
2871 if (entry)
2872 insert_entries(pane, entry, pattern, filter_flags, -1);
2874 /* calculate column widths */
2875 if (!s_init) {
2876 s_init = 1;
2877 init_output(pane->hwnd);
2880 calc_widths(pane, TRUE);
2882 #ifndef _NO_EXTENSIONS
2883 pane->hwndHeader = create_header(parent, pane, id_header);
2884 #endif
2888 static void InitChildWindow(ChildWnd* child)
2890 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2891 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2895 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2897 SYSTEMTIME systime;
2898 FILETIME lft;
2899 int len = 0;
2901 *buffer = TEXT('\0');
2903 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2904 return;
2906 if (!FileTimeToLocalFileTime(ft, &lft))
2907 {err: lstrcpy(buffer,sQMarks); return;}
2909 if (!FileTimeToSystemTime(&lft, &systime))
2910 goto err;
2912 if (visible_cols & COL_DATE) {
2913 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2914 if (!len)
2915 goto err;
2918 if (visible_cols & COL_TIME) {
2919 if (len)
2920 buffer[len-1] = ' ';
2922 buffer[len++] = ' ';
2924 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2925 buffer[len] = TEXT('\0');
2930 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2932 RECT rt = {0, 0, 0, 0};
2934 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2936 if (rt.right > pane->widths[col])
2937 pane->widths[col] = rt.right;
2940 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2942 RECT rt = {0, 0, 0, 0};
2944 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2945 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2947 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2948 /*FIXME rt (0,0) ??? */
2950 if (rt.right > pane->widths[col])
2951 pane->widths[col] = rt.right;
2955 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2957 int x = dis->rcItem.left;
2958 RECT rt;
2960 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2961 rt.top = dis->rcItem.top;
2962 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2963 rt.bottom = dis->rcItem.bottom;
2965 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2968 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2970 int x = dis->rcItem.left;
2971 RECT rt;
2973 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2974 rt.top = dis->rcItem.top;
2975 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2976 rt.bottom = dis->rcItem.bottom;
2978 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2979 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2981 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2984 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2986 int x = dis->rcItem.left;
2987 RECT rt;
2988 LPCTSTR s = str;
2989 TCHAR b[128];
2990 LPTSTR d = b;
2991 int pos;
2993 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2994 rt.top = dis->rcItem.top;
2995 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2996 rt.bottom = dis->rcItem.bottom;
2998 if (*s)
2999 *d++ = *s++;
3001 /* insert number separator characters */
3002 pos = lstrlen(s) % 3;
3004 while(*s)
3005 if (pos--)
3006 *d++ = *s++;
3007 else {
3008 *d++ = Globals.num_sep;
3009 pos = 3;
3012 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3016 static BOOL is_exe_file(LPCTSTR ext)
3018 static const TCHAR executable_extensions[][4] = {
3019 {'C','O','M','\0'},
3020 {'E','X','E','\0'},
3021 {'B','A','T','\0'},
3022 {'C','M','D','\0'},
3023 #ifndef _NO_EXTENSIONS
3024 {'C','M','M','\0'},
3025 {'B','T','M','\0'},
3026 {'A','W','K','\0'},
3027 #endif /* _NO_EXTENSIONS */
3028 {'\0'}
3031 TCHAR ext_buffer[_MAX_EXT];
3032 const TCHAR (*p)[4];
3033 LPCTSTR s;
3034 LPTSTR d;
3036 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3037 d++;
3039 for(p=executable_extensions; (*p)[0]; p++)
3040 if (!lstrcmpi(ext_buffer, *p))
3041 return TRUE;
3043 return FALSE;
3046 static BOOL is_registered_type(LPCTSTR ext)
3048 /* check if there exists a classname for this file extension in the registry */
3049 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3050 return TRUE;
3052 return FALSE;
3055 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3057 LPCTSTR ext = _tcsrchr(filename, '.');
3058 if (!ext)
3059 ext = sEmpty;
3061 if (is_exe_file(ext))
3062 return FT_EXECUTABLE;
3063 else if (is_registered_type(ext))
3064 return FT_DOCUMENT;
3065 else
3066 return FT_OTHER;
3070 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3072 TCHAR buffer[BUFFER_LEN];
3073 DWORD attrs;
3074 int visible_cols = pane->visible_cols;
3075 COLORREF bkcolor, textcolor;
3076 RECT focusRect = dis->rcItem;
3077 HBRUSH hbrush;
3078 enum IMAGE img;
3079 int img_pos, cx;
3080 int col = 0;
3082 if (entry) {
3083 attrs = entry->data.dwFileAttributes;
3085 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3086 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
3087 && entry->data.cFileName[2]==TEXT('\0'))
3088 img = IMG_FOLDER_UP;
3089 #ifndef _NO_EXTENSIONS
3090 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
3091 img = IMG_FOLDER_CUR;
3092 #endif
3093 else if (
3094 #ifdef _NO_EXTENSIONS
3095 entry->expanded ||
3096 #endif
3097 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3098 img = IMG_OPEN_FOLDER;
3099 else
3100 img = IMG_FOLDER;
3101 } else {
3102 switch(get_file_type(entry->data.cFileName)) {
3103 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3104 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3105 default: img = IMG_FILE;
3108 } else {
3109 attrs = 0;
3110 img = IMG_NONE;
3113 if (pane->treePane) {
3114 if (entry) {
3115 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3117 if (calcWidthCol == -1) {
3118 int x;
3119 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3120 Entry* up;
3121 RECT rt_clip;
3122 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3123 HRGN hrgn;
3125 rt_clip.left = dis->rcItem.left;
3126 rt_clip.top = dis->rcItem.top;
3127 rt_clip.right = dis->rcItem.left+pane->widths[col];
3128 rt_clip.bottom = dis->rcItem.bottom;
3130 hrgn = CreateRectRgnIndirect(&rt_clip);
3132 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3133 DeleteObject(hrgn_org);
3134 hrgn_org = 0;
3137 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3138 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3139 DeleteObject(hrgn);
3141 if ((up=entry->up) != NULL) {
3142 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3143 LineTo(dis->hDC, img_pos-2, y);
3145 x = img_pos - IMAGE_WIDTH/2;
3147 do {
3148 x -= IMAGE_WIDTH+TREE_LINE_DX;
3150 if (up->next
3151 #ifndef _LEFT_FILES
3152 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3153 #endif
3155 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3156 LineTo(dis->hDC, x, dis->rcItem.bottom);
3158 } while((up=up->up) != NULL);
3161 x = img_pos - IMAGE_WIDTH/2;
3163 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3164 LineTo(dis->hDC, x, y);
3166 if (entry->next
3167 #ifndef _LEFT_FILES
3168 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3169 #endif
3171 LineTo(dis->hDC, x, dis->rcItem.bottom);
3173 SelectClipRgn(dis->hDC, hrgn_org);
3174 if (hrgn_org) DeleteObject(hrgn_org);
3175 /* SelectObject(dis->hDC, holdPen); */
3176 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3177 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3179 if (right > pane->widths[col])
3180 pane->widths[col] = right;
3182 } else {
3183 img_pos = dis->rcItem.left;
3185 } else {
3186 img_pos = dis->rcItem.left;
3188 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3189 pane->widths[col] = IMAGE_WIDTH;
3192 if (calcWidthCol == -1) {
3193 focusRect.left = img_pos -2;
3195 #ifdef _NO_EXTENSIONS
3196 if (pane->treePane && entry) {
3197 RECT rt = {0};
3199 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3201 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3203 #else
3205 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3206 textcolor = COLOR_COMPRESSED;
3207 else
3208 #endif /* _NO_EXTENSIONS */
3209 textcolor = RGB(0,0,0);
3211 if (dis->itemState & ODS_FOCUS) {
3212 textcolor = RGB(255,255,255);
3213 bkcolor = COLOR_SELECTION;
3214 } else {
3215 bkcolor = RGB(255,255,255);
3218 hbrush = CreateSolidBrush(bkcolor);
3219 FillRect(dis->hDC, &focusRect, hbrush);
3220 DeleteObject(hbrush);
3222 SetBkMode(dis->hDC, TRANSPARENT);
3223 SetTextColor(dis->hDC, textcolor);
3225 cx = pane->widths[col];
3227 if (cx && img!=IMG_NONE) {
3228 if (cx > IMAGE_WIDTH)
3229 cx = IMAGE_WIDTH;
3231 #ifdef _SHELL_FOLDERS
3232 if (entry->hicon && entry->hicon!=(HICON)-1)
3233 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3234 else
3235 #endif
3236 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3237 img_pos, dis->rcItem.top, cx,
3238 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3242 if (!entry)
3243 return;
3245 #ifdef _NO_EXTENSIONS
3246 if (img >= IMG_FOLDER_UP)
3247 return;
3248 #endif
3250 col++;
3252 /* ouput file name */
3253 if (calcWidthCol == -1)
3254 output_text(pane, dis, col, entry->data.cFileName, 0);
3255 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3256 calc_width(pane, dis, col, entry->data.cFileName);
3258 col++;
3260 #ifdef _NO_EXTENSIONS
3261 if (!pane->treePane) {
3262 #endif
3264 /* display file size */
3265 if (visible_cols & COL_SIZE) {
3266 #ifdef _NO_EXTENSIONS
3267 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3268 #endif
3270 ULONGLONG size;
3272 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3274 _stprintf(buffer, sLongNumFmt, size);
3276 if (calcWidthCol == -1)
3277 output_number(pane, dis, col, buffer);
3278 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3279 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3282 col++;
3285 /* display file date */
3286 if (visible_cols & (COL_DATE|COL_TIME)) {
3287 #ifndef _NO_EXTENSIONS
3288 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3289 if (calcWidthCol == -1)
3290 output_text(pane, dis, col, buffer, 0);
3291 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3292 calc_width(pane, dis, col, buffer);
3293 col++;
3295 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3296 if (calcWidthCol == -1)
3297 output_text(pane, dis, col, buffer, 0);
3298 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3299 calc_width(pane, dis, col, buffer);
3300 col++;
3301 #endif /* _NO_EXTENSIONS */
3303 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3304 if (calcWidthCol == -1)
3305 output_text(pane, dis, col, buffer, 0);
3306 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3307 calc_width(pane, dis, col, buffer);
3308 col++;
3311 #ifndef _NO_EXTENSIONS
3312 if (entry->bhfi_valid) {
3313 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3315 if (visible_cols & COL_INDEX) {
3316 _stprintf(buffer, sLongHexFmt, index);
3318 if (calcWidthCol == -1)
3319 output_text(pane, dis, col, buffer, DT_RIGHT);
3320 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3321 calc_width(pane, dis, col, buffer);
3323 col++;
3326 if (visible_cols & COL_LINKS) {
3327 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3329 if (calcWidthCol == -1)
3330 output_text(pane, dis, col, buffer, DT_CENTER);
3331 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3332 calc_width(pane, dis, col, buffer);
3334 col++;
3336 } else
3337 col += 2;
3338 #endif /* _NO_EXTENSIONS */
3340 /* show file attributes */
3341 if (visible_cols & COL_ATTRIBUTES) {
3342 #ifdef _NO_EXTENSIONS
3343 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3344 lstrcpy(buffer, s4Tabs);
3345 #else
3346 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3347 lstrcpy(buffer, s11Tabs);
3348 #endif
3350 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3351 else {
3352 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3353 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3354 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3355 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3356 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3357 #ifndef _NO_EXTENSIONS
3358 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3359 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3360 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3361 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3362 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3363 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3364 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3365 #endif /* _NO_EXTENSIONS */
3368 if (calcWidthCol == -1)
3369 output_tabbed_text(pane, dis, col, buffer);
3370 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3371 calc_tabbed_width(pane, dis, col, buffer);
3373 col++;
3376 /*TODO
3377 if (flags.security) {
3378 static const TCHAR sSecTabs[] = {
3379 ' ','\t',' ','\t',' ','\t',' ',
3380 ' ','\t',' ',
3381 ' ','\t',' ','\t',' ','\t',' ',
3382 ' ','\t',' ',
3383 ' ','\t',' ','\t',' ','\t',' ',
3384 '\0'
3387 DWORD rights = get_access_mask();
3389 lstrcpy(buffer, sSecTabs);
3391 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3392 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3393 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3394 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3395 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3396 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3397 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3398 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3399 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3400 if (rights & WRITE_DAC) buffer[22] = 'C';
3401 if (rights & WRITE_OWNER) buffer[24] = 'O';
3402 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3404 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3407 if (flags.description) {
3408 get_description(buffer);
3409 output_text(dis, col++, buffer, 0, psize);
3413 #ifdef _NO_EXTENSIONS
3416 /* draw focus frame */
3417 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3418 /* Currently [04/2000] Wine neither behaves exactly the same */
3419 /* way as WIN 95 nor like Windows NT... */
3420 HGDIOBJ lastBrush;
3421 HPEN lastPen;
3422 HPEN hpen;
3424 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3425 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3426 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3427 } else
3428 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3430 lastPen = SelectPen(dis->hDC, hpen);
3431 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3432 SetROP2(dis->hDC, R2_XORPEN);
3433 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3434 SelectObject(dis->hDC, lastBrush);
3435 SelectObject(dis->hDC, lastPen);
3436 DeleteObject(hpen);
3438 #endif /* _NO_EXTENSIONS */
3442 #ifdef _NO_EXTENSIONS
3444 static void draw_splitbar(HWND hwnd, int x)
3446 RECT rt;
3447 HDC hdc = GetDC(hwnd);
3449 GetClientRect(hwnd, &rt);
3451 rt.left = x - SPLIT_WIDTH/2;
3452 rt.right = x + SPLIT_WIDTH/2+1;
3454 InvertRect(hdc, &rt);
3456 ReleaseDC(hwnd, hdc);
3459 #endif /* _NO_EXTENSIONS */
3462 #ifndef _NO_EXTENSIONS
3464 static void set_header(Pane* pane)
3466 HD_ITEM item;
3467 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3468 int i=0, x=0;
3470 item.mask = HDI_WIDTH;
3471 item.cxy = 0;
3473 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3474 x += pane->widths[i];
3475 Header_SetItem(pane->hwndHeader, i, &item);
3478 if (i < COLUMNS) {
3479 x += pane->widths[i];
3480 item.cxy = x - scroll_pos;
3481 Header_SetItem(pane->hwndHeader, i++, &item);
3483 for(; i<COLUMNS; i++) {
3484 item.cxy = pane->widths[i];
3485 x += pane->widths[i];
3486 Header_SetItem(pane->hwndHeader, i, &item);
3491 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3493 switch(pnmh->code) {
3494 case HDN_TRACK:
3495 case HDN_ENDTRACK: {
3496 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3497 int idx = phdn->iItem;
3498 int dx = phdn->pitem->cxy - pane->widths[idx];
3499 int i;
3501 RECT clnt;
3502 GetClientRect(pane->hwnd, &clnt);
3504 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3505 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
3507 pane->widths[idx] += dx;
3509 for(i=idx; ++i<=COLUMNS; )
3510 pane->positions[i] += dx;
3513 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3514 RECT rt_scr;
3515 RECT rt_clip;
3517 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3518 rt_scr.top = 0;
3519 rt_scr.right = clnt.right;
3520 rt_scr.bottom = clnt.bottom;
3522 rt_clip.left = pane->positions[idx]-scroll_pos;
3523 rt_clip.top = 0;
3524 rt_clip.right = clnt.right;
3525 rt_clip.bottom = clnt.bottom;
3527 if (rt_scr.left < 0) rt_scr.left = 0;
3528 if (rt_clip.left < 0) rt_clip.left = 0;
3530 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3532 rt_clip.right = pane->positions[idx+1];
3533 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3535 if (pnmh->code == HDN_ENDTRACK) {
3536 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
3538 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3539 set_header(pane);
3543 return FALSE;
3546 case HDN_DIVIDERDBLCLICK: {
3547 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3548 HD_ITEM item;
3550 calc_single_width(pane, phdn->iItem);
3551 item.mask = HDI_WIDTH;
3552 item.cxy = pane->widths[phdn->iItem];
3554 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3555 InvalidateRect(pane->hwnd, 0, TRUE);
3556 break;}
3559 return 0;
3562 #endif /* _NO_EXTENSIONS */
3565 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3567 TCHAR path[MAX_PATH];
3568 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3570 /* delete sub entries in left pane */
3571 for(;;) {
3572 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3573 Entry* sub = (Entry*) res;
3575 if (res==LB_ERR || !sub || sub->level<=entry->level)
3576 break;
3578 ListBox_DeleteString(child->left.hwnd, idx+1);
3581 /* empty right pane */
3582 ListBox_ResetContent(child->right.hwnd);
3584 /* release memory */
3585 free_entries(entry);
3587 /* read contents from disk */
3588 #ifdef _SHELL_FOLDERS
3589 if (entry->etype == ET_SHELL)
3591 read_directory(entry, NULL, child->sortOrder, hwnd);
3593 else
3594 #endif
3596 get_path(entry, path);
3597 read_directory(entry, path, child->sortOrder, hwnd);
3600 /* insert found entries in right pane */
3601 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3602 calc_widths(&child->right, FALSE);
3603 #ifndef _NO_EXTENSIONS
3604 set_header(&child->right);
3605 #endif
3607 child->header_wdths_ok = FALSE;
3609 SetCursor(old_cursor);
3613 /* expand a directory entry */
3615 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3617 int idx;
3618 Entry* p;
3620 if (!dir || dir->expanded || !dir->down)
3621 return FALSE;
3623 p = dir->down;
3625 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3626 p = p->next;
3628 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3629 p->data.cFileName[2]=='\0' && p->next)
3630 p = p->next;
3633 /* no subdirectories ? */
3634 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3635 return FALSE;
3637 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3639 dir->expanded = TRUE;
3641 /* insert entries in left pane */
3642 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3644 if (!child->header_wdths_ok) {
3645 if (calc_widths(&child->left, FALSE)) {
3646 #ifndef _NO_EXTENSIONS
3647 set_header(&child->left);
3648 #endif
3650 child->header_wdths_ok = TRUE;
3654 return TRUE;
3658 static void collapse_entry(Pane* pane, Entry* dir)
3660 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3662 ShowWindow(pane->hwnd, SW_HIDE);
3664 /* hide sub entries */
3665 for(;;) {
3666 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3667 Entry* sub = (Entry*) res;
3669 if (res==LB_ERR || !sub || sub->level<=dir->level)
3670 break;
3672 ListBox_DeleteString(pane->hwnd, idx+1);
3675 dir->expanded = FALSE;
3677 ShowWindow(pane->hwnd, SW_SHOW);
3681 static void refresh_right_pane(ChildWnd* child)
3683 ListBox_ResetContent(child->right.hwnd);
3684 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3685 calc_widths(&child->right, FALSE);
3687 #ifndef _NO_EXTENSIONS
3688 set_header(&child->right);
3689 #endif
3692 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3694 TCHAR path[MAX_PATH];
3696 if (!entry)
3697 return;
3699 path[0] = '\0';
3701 child->left.cur = entry;
3703 child->right.root = entry->down? entry->down: entry;
3704 child->right.cur = entry;
3706 if (!entry->scanned)
3707 scan_entry(child, entry, idx, hwnd);
3708 else
3709 refresh_right_pane(child);
3711 get_path(entry, path);
3712 lstrcpy(child->path, path);
3714 if (child->hwnd) /* only change window title, if the window already exists */
3715 SetWindowText(child->hwnd, path);
3717 if (path[0])
3718 if (SetCurrentDirectory(path))
3719 set_space_status();
3723 static void refresh_child(ChildWnd* child)
3725 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3726 Entry* entry;
3727 int idx;
3729 get_path(child->left.cur, path);
3730 _tsplitpath(path, drv, NULL, NULL, NULL);
3732 child->right.root = NULL;
3734 scan_entry(child, &child->root.entry, 0, child->hwnd);
3736 #ifdef _SHELL_FOLDERS
3737 if (child->root.entry.etype == ET_SHELL)
3738 entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd);
3739 else
3740 #endif
3741 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3743 if (!entry)
3744 entry = &child->root.entry;
3746 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3748 set_curdir(child, entry, 0, child->hwnd);
3750 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
3751 ListBox_SetCurSel(child->left.hwnd, idx);
3755 static void create_drive_bar(void)
3757 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3758 #ifndef _NO_EXTENSIONS
3759 TCHAR b1[BUFFER_LEN];
3760 #endif
3761 int btn = 1;
3762 PTSTR p;
3764 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3766 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3767 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3768 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3770 #ifndef _NO_EXTENSIONS
3771 #ifdef __WINE__
3772 /* insert unix file system button */
3773 b1[0] = '/';
3774 b1[1] = '\0';
3775 b1[2] = '\0';
3776 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3778 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3779 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3780 drivebarBtn.iString++;
3781 #endif
3782 #ifdef _SHELL_FOLDERS
3783 /* insert shell namespace button */
3784 load_string(b1, IDS_SHELL);
3785 b1[lstrlen(b1)+1] = '\0';
3786 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3788 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3789 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3790 drivebarBtn.iString++;
3791 #endif
3793 /* register windows drive root strings */
3794 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3795 #endif
3797 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3799 for(p=Globals.drives; *p; ) {
3800 #ifdef _NO_EXTENSIONS
3801 /* insert drive letter */
3802 TCHAR b[3] = {tolower(*p)};
3803 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3804 #endif
3805 switch(GetDriveType(p)) {
3806 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3807 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3808 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3809 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3810 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3813 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3814 drivebarBtn.idCommand++;
3815 drivebarBtn.iString++;
3817 while(*p++);
3821 static void refresh_drives(void)
3823 RECT rect;
3825 /* destroy drive bar */
3826 DestroyWindow(Globals.hdrivebar);
3827 Globals.hdrivebar = 0;
3829 /* re-create drive bar */
3830 create_drive_bar();
3832 /* update window layout */
3833 GetClientRect(Globals.hMainWnd, &rect);
3834 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3838 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3840 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3842 if ((int)hinst <= 32) {
3843 display_error(hwnd, GetLastError());
3844 return FALSE;
3847 return TRUE;
3851 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3853 TCHAR cmd[MAX_PATH];
3855 #ifdef _SHELL_FOLDERS
3856 if (entry->etype == ET_SHELL) {
3857 BOOL ret = TRUE;
3859 SHELLEXECUTEINFO shexinfo;
3861 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3862 shexinfo.fMask = SEE_MASK_IDLIST;
3863 shexinfo.hwnd = hwnd;
3864 shexinfo.lpVerb = NULL;
3865 shexinfo.lpFile = NULL;
3866 shexinfo.lpParameters = NULL;
3867 shexinfo.lpDirectory = NULL;
3868 shexinfo.nShow = nCmdShow;
3869 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3871 if (!ShellExecuteEx(&shexinfo)) {
3872 display_error(hwnd, GetLastError());
3873 ret = FALSE;
3876 if (shexinfo.lpIDList != entry->pidl)
3877 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3879 return ret;
3881 #endif
3883 get_path(entry, cmd);
3885 /* start program, open document... */
3886 return launch_file(hwnd, cmd, nCmdShow);
3890 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3892 Entry* entry = pane->cur;
3894 if (!entry)
3895 return;
3897 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3898 int scanned_old = entry->scanned;
3900 if (!scanned_old)
3901 scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd);
3903 #ifndef _NO_EXTENSIONS
3904 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3905 return;
3906 #endif
3908 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3909 entry = child->left.cur->up;
3910 collapse_entry(&child->left, entry);
3911 goto focus_entry;
3912 } else if (entry->expanded)
3913 collapse_entry(pane, child->left.cur);
3914 else {
3915 expand_entry(child, child->left.cur);
3917 if (!pane->treePane) focus_entry: {
3918 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3919 ListBox_SetCurSel(child->left.hwnd, idx);
3920 set_curdir(child, entry, idx, hwnd);
3924 if (!scanned_old) {
3925 calc_widths(pane, FALSE);
3927 #ifndef _NO_EXTENSIONS
3928 set_header(pane);
3929 #endif
3931 } else {
3932 if (GetKeyState(VK_MENU) < 0)
3933 show_properties_dlg(entry, child->hwnd);
3934 else
3935 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3940 static BOOL pane_command(Pane* pane, UINT cmd)
3942 switch(cmd) {
3943 case ID_VIEW_NAME:
3944 if (pane->visible_cols) {
3945 pane->visible_cols = 0;
3946 calc_widths(pane, TRUE);
3947 #ifndef _NO_EXTENSIONS
3948 set_header(pane);
3949 #endif
3950 InvalidateRect(pane->hwnd, 0, TRUE);
3951 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3952 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3953 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3955 break;
3957 case ID_VIEW_ALL_ATTRIBUTES:
3958 if (pane->visible_cols != COL_ALL) {
3959 pane->visible_cols = COL_ALL;
3960 calc_widths(pane, TRUE);
3961 #ifndef _NO_EXTENSIONS
3962 set_header(pane);
3963 #endif
3964 InvalidateRect(pane->hwnd, 0, TRUE);
3965 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3966 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3967 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3969 break;
3971 #ifndef _NO_EXTENSIONS
3972 case ID_PREFERRED_SIZES: {
3973 calc_widths(pane, TRUE);
3974 set_header(pane);
3975 InvalidateRect(pane->hwnd, 0, TRUE);
3976 break;}
3977 #endif
3979 /* TODO: more command ids... */
3981 default:
3982 return FALSE;
3985 return TRUE;
3989 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3991 if (child->sortOrder != sortOrder) {
3992 child->sortOrder = sortOrder;
3993 refresh_child(child);
3997 static void update_view_menu(ChildWnd* child)
3999 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4000 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4001 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4002 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4006 static BOOL is_directory(LPCTSTR target)
4008 /*TODO correctly handle UNIX paths */
4009 DWORD target_attr = GetFileAttributes(target);
4011 if (target_attr == INVALID_FILE_ATTRIBUTES)
4012 return FALSE;
4014 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4017 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4019 TCHAR path[MAX_PATH];
4020 int len;
4022 get_path(pane->cur, path);
4024 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4025 return FALSE;
4027 get_path(pane->cur, source);
4029 /* convert relative targets to absolute paths */
4030 if (path[0]!='/' && path[1]!=':') {
4031 get_path(pane->cur->up, target);
4032 len = lstrlen(target);
4034 if (target[len-1]!='\\' && target[len-1]!='/')
4035 target[len++] = '/';
4037 lstrcpy(target+len, path);
4038 } else
4039 lstrcpy(target, path);
4041 /* If the target already exists as directory, create a new target below this. */
4042 if (is_directory(path)) {
4043 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4044 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4046 _tsplitpath(source, NULL, NULL, fname, ext);
4048 wsprintf(target, sAppend, path, fname, ext);
4051 return TRUE;
4055 static IContextMenu2* s_pctxmenu2 = NULL;
4056 static IContextMenu3* s_pctxmenu3 = NULL;
4058 static void CtxMenu_reset(void)
4060 s_pctxmenu2 = NULL;
4061 s_pctxmenu3 = NULL;
4064 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4066 IContextMenu* pcm = NULL;
4068 CtxMenu_reset();
4070 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4071 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4072 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4073 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4075 if (pcm) {
4076 IContextMenu_Release(pcm1);
4077 return pcm;
4078 } else
4079 return pcm1;
4082 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4084 if (s_pctxmenu3) {
4085 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4086 return TRUE;
4089 if (s_pctxmenu2)
4090 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4091 return TRUE;
4093 return FALSE;
4097 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4099 IContextMenu* pcm;
4100 BOOL executed = FALSE;
4102 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4103 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4105 if (SUCCEEDED(hr)) {
4106 HMENU hmenu = CreatePopupMenu();
4108 pcm = CtxMenu_query_interfaces(pcm);
4110 if (hmenu) {
4111 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4113 if (SUCCEEDED(hr)) {
4114 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4116 CtxMenu_reset();
4118 if (idCmd) {
4119 CMINVOKECOMMANDINFO cmi;
4121 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4122 cmi.fMask = 0;
4123 cmi.hwnd = hwndParent;
4124 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4125 cmi.lpParameters = NULL;
4126 cmi.lpDirectory = NULL;
4127 cmi.nShow = SW_SHOWNORMAL;
4128 cmi.dwHotKey = 0;
4129 cmi.hIcon = 0;
4131 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4132 executed = TRUE;
4134 } else
4135 CtxMenu_reset();
4138 IContextMenu_Release(pcm);
4141 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4145 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4147 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4148 ASSERT(child);
4150 switch(nmsg) {
4151 case WM_DRAWITEM: {
4152 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4153 Entry* entry = (Entry*) dis->itemData;
4155 if (dis->CtlID == IDW_TREE_LEFT)
4156 draw_item(&child->left, dis, entry, -1);
4157 else if (dis->CtlID == IDW_TREE_RIGHT)
4158 draw_item(&child->right, dis, entry, -1);
4159 else
4160 goto draw_menu_item;
4162 return TRUE;}
4164 case WM_CREATE:
4165 InitChildWindow(child);
4166 break;
4168 case WM_NCDESTROY:
4169 free_child_window(child);
4170 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4171 break;
4173 case WM_PAINT: {
4174 PAINTSTRUCT ps;
4175 HBRUSH lastBrush;
4176 RECT rt;
4177 GetClientRect(hwnd, &rt);
4178 BeginPaint(hwnd, &ps);
4179 rt.left = child->split_pos-SPLIT_WIDTH/2;
4180 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4181 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
4182 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4183 SelectObject(ps.hdc, lastBrush);
4184 #ifdef _NO_EXTENSIONS
4185 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4186 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4187 #endif
4188 EndPaint(hwnd, &ps);
4189 break;}
4191 case WM_SETCURSOR:
4192 if (LOWORD(lparam) == HTCLIENT) {
4193 POINT pt;
4194 GetCursorPos(&pt);
4195 ScreenToClient(hwnd, &pt);
4197 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4198 SetCursor(LoadCursor(0, IDC_SIZEWE));
4199 return TRUE;
4202 goto def;
4204 case WM_LBUTTONDOWN: {
4205 RECT rt;
4206 int x = GET_X_LPARAM(lparam);
4208 GetClientRect(hwnd, &rt);
4210 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4211 last_split = child->split_pos;
4212 #ifdef _NO_EXTENSIONS
4213 draw_splitbar(hwnd, last_split);
4214 #endif
4215 SetCapture(hwnd);
4218 break;}
4220 case WM_LBUTTONUP:
4221 if (GetCapture() == hwnd) {
4222 #ifdef _NO_EXTENSIONS
4223 RECT rt;
4224 int x = LOWORD(lparam);
4225 draw_splitbar(hwnd, last_split);
4226 last_split = -1;
4227 GetClientRect(hwnd, &rt);
4228 child->split_pos = x;
4229 resize_tree(child, rt.right, rt.bottom);
4230 #endif
4231 ReleaseCapture();
4233 break;
4235 #ifdef _NO_EXTENSIONS
4236 case WM_CAPTURECHANGED:
4237 if (GetCapture()==hwnd && last_split>=0)
4238 draw_splitbar(hwnd, last_split);
4239 break;
4240 #endif
4242 case WM_KEYDOWN:
4243 if (wparam == VK_ESCAPE)
4244 if (GetCapture() == hwnd) {
4245 RECT rt;
4246 #ifdef _NO_EXTENSIONS
4247 draw_splitbar(hwnd, last_split);
4248 #else
4249 child->split_pos = last_split;
4250 #endif
4251 GetClientRect(hwnd, &rt);
4252 resize_tree(child, rt.right, rt.bottom);
4253 last_split = -1;
4254 ReleaseCapture();
4255 SetCursor(LoadCursor(0, IDC_ARROW));
4257 break;
4259 case WM_MOUSEMOVE:
4260 if (GetCapture() == hwnd) {
4261 RECT rt;
4262 int x = LOWORD(lparam);
4264 #ifdef _NO_EXTENSIONS
4265 HDC hdc = GetDC(hwnd);
4266 GetClientRect(hwnd, &rt);
4268 rt.left = last_split-SPLIT_WIDTH/2;
4269 rt.right = last_split+SPLIT_WIDTH/2+1;
4270 InvertRect(hdc, &rt);
4272 last_split = x;
4273 rt.left = x-SPLIT_WIDTH/2;
4274 rt.right = x+SPLIT_WIDTH/2+1;
4275 InvertRect(hdc, &rt);
4277 ReleaseDC(hwnd, hdc);
4278 #else
4279 GetClientRect(hwnd, &rt);
4281 if (x>=0 && x<rt.right) {
4282 child->split_pos = x;
4283 resize_tree(child, rt.right, rt.bottom);
4284 rt.left = x-SPLIT_WIDTH/2;
4285 rt.right = x+SPLIT_WIDTH/2+1;
4286 InvalidateRect(hwnd, &rt, FALSE);
4287 UpdateWindow(child->left.hwnd);
4288 UpdateWindow(hwnd);
4289 UpdateWindow(child->right.hwnd);
4291 #endif
4293 break;
4295 #ifndef _NO_EXTENSIONS
4296 case WM_GETMINMAXINFO:
4297 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4299 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4301 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4302 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4303 break;}
4304 #endif /* _NO_EXTENSIONS */
4306 case WM_SETFOCUS:
4307 if (SetCurrentDirectory(child->path))
4308 set_space_status();
4309 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4310 break;
4312 case WM_DISPATCH_COMMAND: {
4313 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4315 switch(LOWORD(wparam)) {
4316 case ID_WINDOW_NEW: {
4317 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4319 if (!create_child_window(new_child))
4320 free(new_child);
4322 break;}
4324 case ID_REFRESH:
4325 refresh_drives();
4326 refresh_child(child);
4327 break;
4329 case ID_ACTIVATE:
4330 activate_entry(child, pane, hwnd);
4331 break;
4333 case ID_FILE_MOVE: {
4334 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4336 if (prompt_target(pane, source, target)) {
4337 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4339 source[lstrlen(source)+1] = '\0';
4340 target[lstrlen(target)+1] = '\0';
4342 if (!SHFileOperation(&shfo))
4343 refresh_child(child);
4345 break;}
4347 case ID_FILE_COPY: {
4348 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4350 if (prompt_target(pane, source, target)) {
4351 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4353 source[lstrlen(source)+1] = '\0';
4354 target[lstrlen(target)+1] = '\0';
4356 if (!SHFileOperation(&shfo))
4357 refresh_child(child);
4359 break;}
4361 case ID_FILE_DELETE: {
4362 TCHAR path[BUFFER_LEN];
4363 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
4365 get_path(pane->cur, path);
4367 path[lstrlen(path)+1] = '\0';
4369 if (!SHFileOperation(&shfo))
4370 refresh_child(child);
4371 break;}
4373 case ID_VIEW_SORT_NAME:
4374 set_sort_order(child, SORT_NAME);
4375 break;
4377 case ID_VIEW_SORT_TYPE:
4378 set_sort_order(child, SORT_EXT);
4379 break;
4381 case ID_VIEW_SORT_SIZE:
4382 set_sort_order(child, SORT_SIZE);
4383 break;
4385 case ID_VIEW_SORT_DATE:
4386 set_sort_order(child, SORT_DATE);
4387 break;
4389 case ID_VIEW_FILTER: {
4390 struct FilterDialog dlg;
4392 memset(&dlg, 0, sizeof(struct FilterDialog));
4393 lstrcpy(dlg.pattern, child->filter_pattern);
4394 dlg.flags = child->filter_flags;
4396 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4397 lstrcpy(child->filter_pattern, dlg.pattern);
4398 child->filter_flags = dlg.flags;
4399 refresh_right_pane(child);
4401 break;}
4403 case ID_VIEW_SPLIT: {
4404 last_split = child->split_pos;
4405 #ifdef _NO_EXTENSIONS
4406 draw_splitbar(hwnd, last_split);
4407 #endif
4408 SetCapture(hwnd);
4409 break;}
4411 case ID_EDIT_PROPERTIES:
4412 show_properties_dlg(pane->cur, child->hwnd);
4413 break;
4415 default:
4416 return pane_command(pane, LOWORD(wparam));
4419 return TRUE;}
4421 case WM_COMMAND: {
4422 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4424 switch(HIWORD(wparam)) {
4425 case LBN_SELCHANGE: {
4426 int idx = ListBox_GetCurSel(pane->hwnd);
4427 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4429 if (pane == &child->left)
4430 set_curdir(child, entry, idx, hwnd);
4431 else
4432 pane->cur = entry;
4433 break;}
4435 case LBN_DBLCLK:
4436 activate_entry(child, pane, hwnd);
4437 break;
4439 break;}
4441 #ifndef _NO_EXTENSIONS
4442 case WM_NOTIFY: {
4443 NMHDR* pnmh = (NMHDR*) lparam;
4444 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4445 #endif
4447 #ifdef _SHELL_FOLDERS
4448 case WM_CONTEXTMENU: {
4449 POINT pt, pt_clnt;
4450 Pane* pane;
4451 int idx;
4453 /* first select the current item in the listbox */
4454 HWND hpanel = (HWND) wparam;
4455 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4456 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4457 ScreenToClient(hpanel, &pt_clnt);
4458 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4459 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4461 /* now create the popup menu using shell namespace and IContextMenu */
4462 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4463 idx = ListBox_GetCurSel(pane->hwnd);
4465 if (idx != -1) {
4466 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4468 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4470 if (pidl_abs) {
4471 IShellFolder* parentFolder;
4472 LPCITEMIDLIST pidlLast;
4474 /* get and use the parent folder to display correct context menu in all cases */
4475 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4476 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4477 refresh_child(child);
4479 IShellFolder_Release(parentFolder);
4482 IMalloc_Free(Globals.iMalloc, pidl_abs);
4485 break;}
4486 #endif
4488 case WM_MEASUREITEM:
4489 draw_menu_item:
4490 if (!wparam) /* Is the message menu-related? */
4491 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4492 return TRUE;
4494 break;
4496 case WM_INITMENUPOPUP:
4497 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4498 return 0;
4500 update_view_menu(child);
4501 break;
4503 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4504 if (s_pctxmenu3) {
4505 LRESULT lResult = 0;
4507 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4509 return lResult;
4512 break;
4514 case WM_SIZE:
4515 if (wparam != SIZE_MINIMIZED)
4516 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4517 /* fall through */
4519 default: def:
4520 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4523 return 0;
4527 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4529 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4530 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4531 ASSERT(child);
4533 switch(nmsg) {
4534 #ifndef _NO_EXTENSIONS
4535 case WM_HSCROLL:
4536 set_header(pane);
4537 break;
4538 #endif
4540 case WM_SETFOCUS:
4541 child->focus_pane = pane==&child->right? 1: 0;
4542 ListBox_SetSel(hwnd, TRUE, 1);
4543 /*TODO: check menu items */
4544 break;
4546 case WM_KEYDOWN:
4547 if (wparam == VK_TAB) {
4548 /*TODO: SetFocus(Globals.hdrivebar) */
4549 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4553 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4557 static void InitInstance(HINSTANCE hinstance)
4559 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4561 WNDCLASSEX wcFrame;
4562 WNDCLASS wcChild;
4563 ATOM hChildClass;
4564 int col;
4566 INITCOMMONCONTROLSEX icc = {
4567 sizeof(INITCOMMONCONTROLSEX),
4568 ICC_BAR_CLASSES
4571 HDC hdc = GetDC(0);
4573 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4575 InitCommonControlsEx(&icc);
4578 /* register frame window class */
4580 wcFrame.cbSize = sizeof(WNDCLASSEX);
4581 wcFrame.style = 0;
4582 wcFrame.lpfnWndProc = FrameWndProc;
4583 wcFrame.cbClsExtra = 0;
4584 wcFrame.cbWndExtra = 0;
4585 wcFrame.hInstance = hinstance;
4586 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4587 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4588 wcFrame.hbrBackground = 0;
4589 wcFrame.lpszMenuName = 0;
4590 wcFrame.lpszClassName = sWINEFILEFRAME;
4591 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4592 MAKEINTRESOURCE(IDI_WINEFILE),
4593 IMAGE_ICON,
4594 GetSystemMetrics(SM_CXSMICON),
4595 GetSystemMetrics(SM_CYSMICON),
4596 LR_SHARED);
4598 Globals.hframeClass = RegisterClassEx(&wcFrame);
4601 /* register tree windows class */
4603 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4604 wcChild.lpfnWndProc = ChildWndProc;
4605 wcChild.cbClsExtra = 0;
4606 wcChild.cbWndExtra = 0;
4607 wcChild.hInstance = hinstance;
4608 wcChild.hIcon = 0;
4609 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4610 wcChild.hbrBackground = 0;
4611 wcChild.lpszMenuName = 0;
4612 wcChild.lpszClassName = sWINEFILETREE;
4614 hChildClass = RegisterClass(&wcChild);
4617 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4619 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4621 ReleaseDC(0, hdc);
4623 Globals.hInstance = hinstance;
4625 #ifdef _SHELL_FOLDERS
4626 CoInitialize(NULL);
4627 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4628 SHGetDesktopFolder(&Globals.iDesktop);
4629 #ifdef __WINE__
4630 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4631 #else
4632 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4633 #endif
4634 #endif
4636 /* load column strings */
4637 col = 1;
4639 load_string(g_pos_names[col++], IDS_COL_NAME);
4640 load_string(g_pos_names[col++], IDS_COL_SIZE);
4641 load_string(g_pos_names[col++], IDS_COL_CDATE);
4642 #ifndef _NO_EXTENSIONS
4643 load_string(g_pos_names[col++], IDS_COL_ADATE);
4644 load_string(g_pos_names[col++], IDS_COL_MDATE);
4645 load_string(g_pos_names[col++], IDS_COL_IDX);
4646 load_string(g_pos_names[col++], IDS_COL_LINKS);
4647 #endif
4648 load_string(g_pos_names[col++], IDS_COL_ATTR);
4649 #ifndef _NO_EXTENSIONS
4650 load_string(g_pos_names[col++], IDS_COL_SEC);
4651 #endif
4655 static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4657 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4659 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4660 ChildWnd* child;
4661 HMENU hMenuFrame, hMenuWindow;
4663 CLIENTCREATESTRUCT ccs;
4665 if (Globals.hMainWnd)
4666 return;
4668 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4669 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4671 Globals.hMenuFrame = hMenuFrame;
4672 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4673 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4675 ccs.hWindowMenu = hMenuWindow;
4676 ccs.idFirstChild = IDW_FIRST_CHILD;
4679 /* create main window */
4680 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4681 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
4682 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4685 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4686 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4687 0, 0, 0, 0,
4688 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4691 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4693 create_drive_bar();
4696 TBBUTTON toolbarBtns[] = {
4697 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4698 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4699 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4700 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4701 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4702 /*TODO
4703 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4704 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4705 */ };
4707 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4708 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4709 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4710 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4713 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4714 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4716 /* CreateStatusWindow does not accept WS_BORDER
4717 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4718 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4719 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4721 /*TODO: read paths and window placements from registry */
4723 if (!path || !*path) {
4724 GetCurrentDirectory(MAX_PATH, buffer);
4725 path = buffer;
4728 ShowWindow(Globals.hMainWnd, cmdshow);
4730 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4731 /* Shell Namespace as default: */
4732 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4733 #else
4734 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4735 #endif
4737 child->pos.showCmd = SW_SHOWMAXIMIZED;
4738 child->pos.rcNormalPosition.left = 0;
4739 child->pos.rcNormalPosition.top = 0;
4740 child->pos.rcNormalPosition.right = 320;
4741 child->pos.rcNormalPosition.bottom = 280;
4743 if (!create_child_window(child))
4744 free(child);
4746 SetWindowPlacement(child->hwnd, &child->pos);
4748 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4750 Globals.prescan_node = FALSE;
4752 UpdateWindow(Globals.hMainWnd);
4755 static void ExitInstance(void)
4757 #ifdef _SHELL_FOLDERS
4758 IShellFolder_Release(Globals.iDesktop);
4759 IMalloc_Release(Globals.iMalloc);
4760 CoUninitialize();
4761 #endif
4763 DeleteObject(Globals.hfont);
4764 ImageList_Destroy(Globals.himl);
4767 #ifdef _NO_EXTENSIONS
4769 /* search for already running win[e]files */
4771 static int g_foundPrevInstance = 0;
4773 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4775 TCHAR cls[128];
4777 GetClassName(hwnd, cls, 128);
4779 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4780 g_foundPrevInstance++;
4781 return FALSE;
4784 return TRUE;
4787 /* search for window of given class name to allow only one running instance */
4788 static int find_window_class(LPCTSTR classname)
4790 EnumWindows(EnumWndProc, (LPARAM)classname);
4792 if (g_foundPrevInstance)
4793 return 1;
4795 return 0;
4798 #endif
4800 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4802 MSG msg;
4804 InitInstance(hinstance);
4806 if (cmdshow == SW_SHOWNORMAL)
4807 /*TODO: read window placement from registry */
4808 cmdshow = SW_MAXIMIZE;
4810 show_frame(0, cmdshow, path);
4812 while(GetMessage(&msg, 0, 0, 0)) {
4813 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4814 continue;
4816 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4817 continue;
4819 TranslateMessage(&msg);
4820 DispatchMessage(&msg);
4823 ExitInstance();
4825 return msg.wParam;
4829 #if defined(UNICODE) && defined(_MSC_VER)
4830 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4831 #else
4832 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4833 #endif
4835 #ifdef _NO_EXTENSIONS
4836 if (find_window_class(sWINEFILEFRAME))
4837 return 1;
4838 #endif
4840 #if defined(UNICODE) && !defined(_MSC_VER)
4841 { /* convert ANSI cmdline into WCS path string */
4842 TCHAR buffer[MAX_PATH];
4843 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4844 winefile_main(hinstance, cmdshow, buffer);
4846 #else
4847 winefile_main(hinstance, cmdshow, cmdline);
4848 #endif
4850 return 0;