- remove <tchar.h> and <wchar.h> header usage by switching to WIN32
[wine/multimedia.git] / programs / winefile / winefile.c
blob819fee27ea985979b655daf5c3617c5c7f8a710f
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 #include "winefile.h"
32 #include "resource.h"
34 #ifdef _NO_EXTENSIONS
35 #undef _LEFT_FILES
36 #endif
38 #ifndef _MAX_PATH
39 #define _MAX_DRIVE 3
40 #define _MAX_FNAME 256
41 #define _MAX_DIR _MAX_FNAME
42 #define _MAX_EXT _MAX_FNAME
43 #define _MAX_PATH 260
44 #endif
46 #ifdef NONAMELESSUNION
47 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
48 #else
49 #define UNION_MEMBER(x) x
50 #endif
53 #ifdef _SHELL_FOLDERS
54 #define DEFAULT_SPLIT_POS 300
55 #else
56 #define DEFAULT_SPLIT_POS 200
57 #endif
60 enum ENTRY_TYPE {
61 ET_WINDOWS,
62 ET_UNIX,
63 #ifdef _SHELL_FOLDERS
64 ET_SHELL
65 #endif
68 typedef struct _Entry {
69 struct _Entry* next;
70 struct _Entry* down;
71 struct _Entry* up;
73 BOOL expanded;
74 BOOL scanned;
75 int level;
77 WIN32_FIND_DATA data;
79 #ifndef _NO_EXTENSIONS
80 BY_HANDLE_FILE_INFORMATION bhfi;
81 BOOL bhfi_valid;
82 enum ENTRY_TYPE etype;
83 #endif
84 #ifdef _SHELL_FOLDERS
85 LPITEMIDLIST pidl;
86 IShellFolder* folder;
87 HICON hicon;
88 #endif
89 } Entry;
91 typedef struct {
92 Entry entry;
93 TCHAR path[MAX_PATH];
94 TCHAR volname[_MAX_FNAME];
95 TCHAR fs[_MAX_DIR];
96 DWORD drive_type;
97 DWORD fs_flags;
98 } Root;
100 enum COLUMN_FLAGS {
101 COL_SIZE = 0x01,
102 COL_DATE = 0x02,
103 COL_TIME = 0x04,
104 COL_ATTRIBUTES = 0x08,
105 COL_DOSNAMES = 0x10,
106 #ifdef _NO_EXTENSIONS
107 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
108 #else
109 COL_INDEX = 0x20,
110 COL_LINKS = 0x40,
111 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
112 #endif
115 typedef enum {
116 SORT_NAME,
117 SORT_EXT,
118 SORT_SIZE,
119 SORT_DATE
120 } SORT_ORDER;
122 typedef struct {
123 HWND hwnd;
124 #ifndef _NO_EXTENSIONS
125 HWND hwndHeader;
126 #endif
128 #ifndef _NO_EXTENSIONS
129 #define COLUMNS 10
130 #else
131 #define COLUMNS 5
132 #endif
133 int widths[COLUMNS];
134 int positions[COLUMNS+1];
136 BOOL treePane;
137 int visible_cols;
138 Entry* root;
139 Entry* cur;
140 } Pane;
142 typedef struct {
143 HWND hwnd;
144 Pane left;
145 Pane right;
146 int focus_pane; /* 0: left 1: right */
147 WINDOWPLACEMENT pos;
148 int split_pos;
149 BOOL header_wdths_ok;
151 TCHAR path[MAX_PATH];
152 TCHAR filter_pattern[MAX_PATH];
153 int filter_flags;
154 Root root;
156 SORT_ORDER sortOrder;
157 } ChildWnd;
161 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
162 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
163 static void refresh_child(ChildWnd* child);
164 static void refresh_drives(void);
165 static void get_path(Entry* dir, PTSTR path);
166 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
168 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
169 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
170 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
173 /* globals */
174 WINEFILE_GLOBALS Globals;
176 static int last_split;
178 /* some common string constants */
179 const static TCHAR sEmpty[] = {'\0'};
180 const static TCHAR sSpace[] = {' ', '\0'};
181 const static TCHAR sNumFmt[] = {'%','d','\0'};
182 const static TCHAR sQMarks[] = {'?','?','?','\0'};
184 /* window class names */
185 const static TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
186 const static TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
188 #ifdef _MSC_VER
189 /* #define LONGLONGARG _T("I64") */
190 const static TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
191 const static TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
192 #else
193 /* #define LONGLONGARG _T("L") */
194 const static TCHAR sLongHexFmt[] = {'%','L','X','\0'};
195 const static TCHAR sLongNumFmt[] = {'%','L','d','\0'};
196 #endif
199 /* load resource string */
200 static LPTSTR load_string(LPTSTR buffer, UINT id)
202 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
204 return buffer;
207 #define RS(b, i) load_string(b, i)
210 /* display error message for the specified WIN32 error code */
211 static void display_error(HWND hwnd, DWORD error)
213 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
214 PTSTR msg;
216 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
217 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
218 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
219 else
220 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
222 LocalFree(msg);
226 /* display network error message using WNetGetLastError() */
227 static void display_network_error(HWND hwnd)
229 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
230 DWORD error;
232 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
233 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
237 #ifdef __WINE__
239 #ifdef UNICODE
241 /* call vswprintf() in msvcrt.dll */
242 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
243 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
245 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
246 va_list ap;
247 int ret;
249 if (!pvswprintf) {
250 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
251 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
254 va_start(ap, fmt);
255 ret = (*pvswprintf)(buffer, fmt, ap);
256 va_end(ap);
258 return ret;
261 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
263 LPCWSTR p = str;
265 while(*p)
266 ++p;
268 do {
269 if (--p < str)
270 return NULL;
271 } while(*p != c);
273 return p;
276 #define _tcsrchr my_wcsrchr
277 #else /* UNICODE */
278 #define _tcsrchr strrchr
279 #endif /* UNICODE */
281 #endif /* __WINE__ */
284 /* allocate and initialise a directory entry */
285 static Entry* alloc_entry(void)
287 Entry* entry = (Entry*) malloc(sizeof(Entry));
289 #ifdef _SHELL_FOLDERS
290 entry->pidl = NULL;
291 entry->folder = NULL;
292 entry->hicon = 0;
293 #endif
295 return entry;
298 /* free a directory entry */
299 static void free_entry(Entry* entry)
301 #ifdef _SHELL_FOLDERS
302 if (entry->hicon && entry->hicon!=(HICON)-1)
303 DestroyIcon(entry->hicon);
305 if (entry->folder && entry->folder!=Globals.iDesktop)
306 (*entry->folder->lpVtbl->Release)(entry->folder);
308 if (entry->pidl)
309 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
310 #endif
312 free(entry);
315 /* recursively free all child entries */
316 static void free_entries(Entry* dir)
318 Entry *entry, *next=dir->down;
320 if (next) {
321 dir->down = 0;
323 do {
324 entry = next;
325 next = entry->next;
327 free_entries(entry);
328 free_entry(entry);
329 } while(next);
334 static void read_directory_win(Entry* dir, LPCTSTR path)
336 Entry* first_entry = NULL;
337 Entry* last = NULL;
338 Entry* entry;
340 int level = dir->level + 1;
341 WIN32_FIND_DATA w32fd;
342 HANDLE hFind;
343 #ifndef _NO_EXTENSIONS
344 HANDLE hFile;
345 #endif
347 TCHAR buffer[MAX_PATH], *p;
348 for(p=buffer; *path; )
349 *p++ = *path++;
351 *p++ = '\\';
352 p[0] = '*';
353 p[1] = '\0';
355 hFind = FindFirstFile(buffer, &w32fd);
357 if (hFind != INVALID_HANDLE_VALUE) {
358 do {
359 #ifdef _NO_EXTENSIONS
360 /* hide directory entry "." */
361 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
362 LPCTSTR name = w32fd.cFileName;
364 if (name[0]=='.' && name[1]=='\0')
365 continue;
367 #endif
368 entry = alloc_entry();
370 if (!first_entry)
371 first_entry = entry;
373 if (last)
374 last->next = entry;
376 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
377 entry->down = NULL;
378 entry->up = dir;
379 entry->expanded = FALSE;
380 entry->scanned = FALSE;
381 entry->level = level;
383 #ifndef _NO_EXTENSIONS
384 entry->etype = ET_WINDOWS;
385 entry->bhfi_valid = FALSE;
387 lstrcpy(p, entry->data.cFileName);
389 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
390 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
392 if (hFile != INVALID_HANDLE_VALUE) {
393 if (GetFileInformationByHandle(hFile, &entry->bhfi))
394 entry->bhfi_valid = TRUE;
396 CloseHandle(hFile);
398 #endif
400 last = entry;
401 } while(FindNextFile(hFind, &w32fd));
403 if (last)
404 last->next = NULL;
406 FindClose(hFind);
409 dir->down = first_entry;
410 dir->scanned = TRUE;
414 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
416 Entry* entry;
418 for(entry=dir->down; entry; entry=entry->next) {
419 LPCTSTR p = name;
420 LPCTSTR q = entry->data.cFileName;
422 do {
423 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
424 return entry;
425 } while(tolower(*p++) == tolower(*q++));
427 p = name;
428 q = entry->data.cAlternateFileName;
430 do {
431 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
432 return entry;
433 } while(tolower(*p++) == tolower(*q++));
436 return 0;
440 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
442 TCHAR buffer[MAX_PATH];
443 Entry* entry = &root->entry;
444 LPCTSTR s = path;
445 PTSTR d = buffer;
447 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
449 #ifndef _NO_EXTENSIONS
450 entry->etype = ET_WINDOWS;
451 #endif
453 while(entry) {
454 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
455 *d++ = *s++;
457 while(*s==TEXT('\\') || *s==TEXT('/'))
458 s++;
460 *d++ = TEXT('\\');
461 *d = TEXT('\0');
463 read_directory(entry, buffer, sortOrder, hwnd);
465 if (entry->down)
466 entry->expanded = TRUE;
468 if (!*s)
469 break;
471 entry = find_entry_win(entry, s);
474 SetCursor(old_cursor);
476 return entry;
480 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
482 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
484 struct tm* tm = gmtime(t);
485 SYSTEMTIME stime;
487 if (!tm)
488 return FALSE;
490 stime.wYear = tm->tm_year+1900;
491 stime.wMonth = tm->tm_mon+1;
492 /* stime.wDayOfWeek */
493 stime.wDay = tm->tm_mday;
494 stime.wHour = tm->tm_hour;
495 stime.wMinute = tm->tm_min;
496 stime.wSecond = tm->tm_sec;
498 return SystemTimeToFileTime(&stime, ftime);
501 static void read_directory_unix(Entry* dir, LPCTSTR path)
503 Entry* first_entry = NULL;
504 Entry* last = NULL;
505 Entry* entry;
506 DIR* pdir;
508 int level = dir->level + 1;
509 #ifdef UNICODE
510 char cpath[MAX_PATH];
512 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
513 #else
514 const char* cpath = path;
515 #endif
517 pdir = opendir(cpath);
519 if (pdir) {
520 struct stat st;
521 struct dirent* ent;
522 char buffer[MAX_PATH], *p;
523 const char* s;
525 for(p=buffer,s=cpath; *s; )
526 *p++ = *s++;
528 if (p==buffer || p[-1]!='/')
529 *p++ = '/';
531 while((ent=readdir(pdir))) {
532 entry = alloc_entry();
534 if (!first_entry)
535 first_entry = entry;
537 if (last)
538 last->next = entry;
540 entry->etype = ET_UNIX;
542 strcpy(p, ent->d_name);
543 #ifdef UNICODE
544 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
545 #else
546 lstrcpy(entry->data.cFileName, p);
547 #endif
549 if (!stat(buffer, &st)) {
550 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
552 if (S_ISDIR(st.st_mode))
553 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
555 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
556 entry->data.nFileSizeHigh = st.st_size >> 32;
558 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
559 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
560 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
562 entry->bhfi.nFileIndexLow = ent->d_ino;
563 entry->bhfi.nFileIndexHigh = 0;
565 entry->bhfi.nNumberOfLinks = st.st_nlink;
567 entry->bhfi_valid = TRUE;
568 } else {
569 entry->data.nFileSizeLow = 0;
570 entry->data.nFileSizeHigh = 0;
571 entry->bhfi_valid = FALSE;
574 entry->down = NULL;
575 entry->up = dir;
576 entry->expanded = FALSE;
577 entry->scanned = FALSE;
578 entry->level = level;
580 last = entry;
583 if (last)
584 last->next = NULL;
586 closedir(pdir);
589 dir->down = first_entry;
590 dir->scanned = TRUE;
593 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
595 Entry* entry;
597 for(entry=dir->down; entry; entry=entry->next) {
598 LPCTSTR p = name;
599 LPCTSTR q = entry->data.cFileName;
601 do {
602 if (!*p || *p==TEXT('/'))
603 return entry;
604 } while(*p++ == *q++);
607 return 0;
610 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
612 TCHAR buffer[MAX_PATH];
613 Entry* entry = &root->entry;
614 LPCTSTR s = path;
615 PTSTR d = buffer;
617 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
619 entry->etype = ET_UNIX;
621 while(entry) {
622 while(*s && *s!=TEXT('/'))
623 *d++ = *s++;
625 while(*s == TEXT('/'))
626 s++;
628 *d++ = TEXT('/');
629 *d = TEXT('\0');
631 read_directory(entry, buffer, sortOrder, hwnd);
633 if (entry->down)
634 entry->expanded = TRUE;
636 if (!*s)
637 break;
639 entry = find_entry_unix(entry, s);
642 SetCursor(old_cursor);
644 return entry;
647 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
650 #ifdef _SHELL_FOLDERS
652 #ifdef UNICODE
653 #define get_strret get_strretW
654 #define path_from_pidl path_from_pidlW
655 #else
656 #define get_strret get_strretA
657 #define path_from_pidl path_from_pidlA
658 #endif
661 static void free_strret(STRRET* str)
663 if (str->uType == STRRET_WSTR)
664 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
668 #ifndef UNICODE
670 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
672 LPCSTR s;
673 LPSTR d = dest;
675 for(s=source; count&&(*d++=*s++); )
676 count--;
678 return dest;
681 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
683 switch(str->uType) {
684 case STRRET_WSTR:
685 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
686 break;
688 case STRRET_OFFSET:
689 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
690 break;
692 case STRRET_CSTR:
693 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
697 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
699 STRRET str;
701 /* SHGDN_FORPARSING: get full path of id list */
702 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
704 if (SUCCEEDED(hr)) {
705 get_strretA(&str, &pidl->mkid, buffer, len);
706 free_strret(&str);
707 } else
708 buffer[0] = '\0';
710 return hr;
713 #endif
715 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
717 LPCWSTR s;
718 LPWSTR d = dest;
720 for(s=source; count&&(*d++=*s++); )
721 count--;
723 return dest;
726 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
728 switch(str->uType) {
729 case STRRET_WSTR:
730 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
731 break;
733 case STRRET_OFFSET:
734 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
735 break;
737 case STRRET_CSTR:
738 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
743 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
745 STRRET str;
747 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
749 if (SUCCEEDED(hr)) {
750 get_strret(&str, &pidl->mkid, buffer, len);
751 free_strret(&str);
752 } else
753 buffer[0] = '\0';
755 return hr;
759 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
761 STRRET str;
763 /* SHGDN_FORPARSING: get full path of id list */
764 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
766 if (SUCCEEDED(hr)) {
767 get_strretW(&str, &pidl->mkid, buffer, len);
768 free_strret(&str);
769 } else
770 buffer[0] = '\0';
772 return hr;
776 /* create an item id list from a file system path */
778 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
780 LPITEMIDLIST pidl;
781 HRESULT hr;
782 ULONG len;
784 #ifdef UNICODE
785 LPWSTR buffer = path;
786 #else
787 WCHAR buffer[MAX_PATH];
788 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
789 #endif
791 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
792 if (FAILED(hr))
793 return NULL;
795 return pidl;
799 /* convert an item id list from relative to absolute (=relative to the desktop) format */
801 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
803 if (entry->up && entry->up->etype==ET_SHELL) {
804 IShellFolder* folder = entry->up->folder;
805 WCHAR buffer[MAX_PATH];
807 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
809 if (SUCCEEDED(hr)) {
810 LPITEMIDLIST pidl;
811 ULONG len;
813 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
815 if (SUCCEEDED(hr))
816 return pidl;
818 } else if (entry->etype == ET_WINDOWS) {
819 TCHAR path[MAX_PATH];
821 get_path(entry, path);
823 return get_path_pidl(path, hwnd);
824 } else if (entry->pidl)
825 return ILClone(entry->pidl);
827 return NULL;
831 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
833 IExtractIcon* pExtract;
835 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
836 TCHAR path[_MAX_PATH];
837 unsigned flags;
838 HICON hicon;
839 int idx;
841 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
842 if (!(flags & GIL_NOTFILENAME)) {
843 if (idx == -1)
844 idx = 0; /* special case for some control panel applications */
846 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
847 flags &= ~GIL_DONTCACHE;
848 } else {
849 HICON hIconLarge = 0;
851 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
853 if (SUCCEEDED(hr))
854 DestroyIcon(hIconLarge);
857 return hicon;
861 return 0;
865 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
867 Entry* entry;
869 for(entry=dir->down; entry; entry=entry->next) {
870 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
871 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
872 return entry;
875 return 0;
878 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
880 Entry* entry = &root->entry;
881 Entry* next;
882 LPITEMIDLIST next_pidl = pidl;
883 IShellFolder* folder;
884 IShellFolder* child = NULL;
885 HRESULT hr;
887 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
889 #ifndef _NO_EXTENSIONS
890 entry->etype = ET_SHELL;
891 #endif
893 folder = Globals.iDesktop;
895 while(entry) {
896 entry->pidl = next_pidl;
897 entry->folder = folder;
899 if (!pidl->mkid.cb)
900 break;
902 /* copy first element of item idlist */
903 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
904 memcpy(next_pidl, pidl, pidl->mkid.cb);
905 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
907 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
908 if (!SUCCEEDED(hr))
909 break;
911 read_directory(entry, NULL, sortOrder, hwnd);
913 if (entry->down)
914 entry->expanded = TRUE;
916 next = find_entry_shell(entry, next_pidl);
917 if (!next)
918 break;
920 folder = child;
921 entry = next;
923 /* go to next element */
924 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
927 SetCursor(old_cursor);
929 return entry;
933 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
935 if (!(attribs & SFGAO_FILESYSTEM) ||
936 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
937 WIN32_FILE_ATTRIBUTE_DATA fad;
938 IDataObject* pDataObj;
940 STGMEDIUM medium = {0, {0}, 0};
941 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
943 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
945 if (SUCCEEDED(hr)) {
946 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
948 (*pDataObj->lpVtbl->Release)(pDataObj);
950 if (SUCCEEDED(hr)) {
951 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
952 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
954 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
955 w32fdata->dwFileAttributes = fad.dwFileAttributes;
956 w32fdata->ftCreationTime = fad.ftCreationTime;
957 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
958 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
960 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
961 w32fdata->nFileSizeLow = fad.nFileSizeLow;
962 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
966 SetErrorMode(sem_org);
968 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
969 GlobalFree(medium.UNION_MEMBER(hGlobal));
974 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
975 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
977 if (attribs & SFGAO_READONLY)
978 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
980 if (attribs & SFGAO_COMPRESSED)
981 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
985 static void read_directory_shell(Entry* dir, HWND hwnd)
987 IShellFolder* folder = dir->folder;
988 int level = dir->level + 1;
989 HRESULT hr;
991 IShellFolder* child;
992 IEnumIDList* idlist;
994 Entry* first_entry = NULL;
995 Entry* last = NULL;
996 Entry* entry;
998 if (!folder)
999 return;
1001 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1003 if (SUCCEEDED(hr)) {
1004 for(;;) {
1005 #define FETCH_ITEM_COUNT 32
1006 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1007 SFGAOF attribs;
1008 ULONG cnt = 0;
1009 ULONG n;
1011 memset(pidls, 0, sizeof(pidls));
1013 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1014 if (!SUCCEEDED(hr))
1015 break;
1017 if (hr == S_FALSE)
1018 break;
1020 for(n=0; n<cnt; ++n) {
1021 entry = alloc_entry();
1023 if (!first_entry)
1024 first_entry = entry;
1026 if (last)
1027 last->next = entry;
1029 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1030 entry->bhfi_valid = FALSE;
1032 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1034 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1036 if (SUCCEEDED(hr)) {
1037 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1038 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1040 entry->bhfi_valid = TRUE;
1041 } else
1042 attribs = 0;
1043 } else
1044 attribs = 0;
1046 entry->pidl = pidls[n];
1048 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1049 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1051 if (SUCCEEDED(hr))
1052 entry->folder = child;
1053 else
1054 entry->folder = NULL;
1056 else
1057 entry->folder = NULL;
1059 if (!entry->data.cFileName[0])
1060 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1062 /* get display icons for files and virtual objects */
1063 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1064 !(attribs & SFGAO_FILESYSTEM)) {
1065 entry->hicon = extract_icon(folder, pidls[n]);
1067 if (!entry->hicon)
1068 entry->hicon = (HICON)-1; /* don't try again later */
1071 entry->down = NULL;
1072 entry->up = dir;
1073 entry->expanded = FALSE;
1074 entry->scanned = FALSE;
1075 entry->level = level;
1077 #ifndef _NO_EXTENSIONS
1078 entry->etype = ET_SHELL;
1079 entry->bhfi_valid = FALSE;
1080 #endif
1082 last = entry;
1086 (*idlist->lpVtbl->Release)(idlist);
1089 if (last)
1090 last->next = NULL;
1092 dir->down = first_entry;
1093 dir->scanned = TRUE;
1096 #endif /* _SHELL_FOLDERS */
1099 /* sort order for different directory/file types */
1100 enum TYPE_ORDER {
1101 TO_DIR = 0,
1102 TO_DOT = 1,
1103 TO_DOTDOT = 2,
1104 TO_OTHER_DIR = 3,
1105 TO_FILE = 4
1108 /* distinguish between ".", ".." and any other directory names */
1109 static int TypeOrderFromDirname(LPCTSTR name)
1111 if (name[0] == '.') {
1112 if (name[1] == '\0')
1113 return TO_DOT; /* "." */
1115 if (name[1]=='.' && name[2]=='\0')
1116 return TO_DOTDOT; /* ".." */
1119 return TO_OTHER_DIR; /* anything else */
1122 /* directories first... */
1123 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1125 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1126 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1128 /* Handle "." and ".." as special case and move them at the very first beginning. */
1129 if (order1==TO_DIR && order2==TO_DIR) {
1130 order1 = TypeOrderFromDirname(fd1->cFileName);
1131 order2 = TypeOrderFromDirname(fd2->cFileName);
1134 return order2==order1? 0: order1<order2? -1: 1;
1138 static int compareName(const void* arg1, const void* arg2)
1140 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1141 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1143 int cmp = compareType(fd1, fd2);
1144 if (cmp)
1145 return cmp;
1147 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1150 static int compareExt(const void* arg1, const void* arg2)
1152 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1153 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1154 const TCHAR *name1, *name2, *ext1, *ext2;
1156 int cmp = compareType(fd1, fd2);
1157 if (cmp)
1158 return cmp;
1160 name1 = fd1->cFileName;
1161 name2 = fd2->cFileName;
1163 ext1 = _tcsrchr(name1, TEXT('.'));
1164 ext2 = _tcsrchr(name2, TEXT('.'));
1166 if (ext1)
1167 ext1++;
1168 else
1169 ext1 = sEmpty;
1171 if (ext2)
1172 ext2++;
1173 else
1174 ext2 = sEmpty;
1176 cmp = lstrcmpi(ext1, ext2);
1177 if (cmp)
1178 return cmp;
1180 return lstrcmpi(name1, name2);
1183 static int compareSize(const void* arg1, const void* arg2)
1185 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1186 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1188 int cmp = compareType(fd1, fd2);
1189 if (cmp)
1190 return cmp;
1192 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1194 if (cmp < 0)
1195 return -1;
1196 else if (cmp > 0)
1197 return 1;
1199 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1201 return cmp<0? -1: cmp>0? 1: 0;
1204 static int compareDate(const void* arg1, const void* arg2)
1206 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1207 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1209 int cmp = compareType(fd1, fd2);
1210 if (cmp)
1211 return cmp;
1213 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1217 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1218 compareName, /* SORT_NAME */
1219 compareExt, /* SORT_EXT */
1220 compareSize, /* SORT_SIZE */
1221 compareDate /* SORT_DATE */
1225 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1227 Entry* entry = dir->down;
1228 Entry** array, **p;
1229 int len;
1231 len = 0;
1232 for(entry=dir->down; entry; entry=entry->next)
1233 len++;
1235 if (len) {
1236 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1238 p = array;
1239 for(entry=dir->down; entry; entry=entry->next)
1240 *p++ = entry;
1242 /* call qsort with the appropriate compare function */
1243 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1245 dir->down = array[0];
1247 for(p=array; --len; p++)
1248 p[0]->next = p[1];
1250 (*p)->next = 0;
1252 HeapFree(GetProcessHeap(), 0, array);
1257 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1259 TCHAR buffer[MAX_PATH];
1260 Entry* entry;
1261 LPCTSTR s;
1262 PTSTR d;
1264 #ifdef _SHELL_FOLDERS
1265 if (dir->etype == ET_SHELL)
1267 read_directory_shell(dir, hwnd);
1269 if (Globals.prescan_node) {
1270 s = path;
1271 d = buffer;
1273 while(*s)
1274 *d++ = *s++;
1276 *d++ = TEXT('\\');
1278 for(entry=dir->down; entry; entry=entry->next)
1279 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1280 read_directory_shell(entry, hwnd);
1281 SortDirectory(entry, sortOrder);
1285 else
1286 #endif
1287 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1288 if (dir->etype == ET_UNIX)
1290 read_directory_unix(dir, path);
1292 if (Globals.prescan_node) {
1293 s = path;
1294 d = buffer;
1296 while(*s)
1297 *d++ = *s++;
1299 *d++ = TEXT('/');
1301 for(entry=dir->down; entry; entry=entry->next)
1302 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1303 lstrcpy(d, entry->data.cFileName);
1304 read_directory_unix(entry, buffer);
1305 SortDirectory(entry, sortOrder);
1309 else
1310 #endif
1312 read_directory_win(dir, path);
1314 if (Globals.prescan_node) {
1315 s = path;
1316 d = buffer;
1318 while(*s)
1319 *d++ = *s++;
1321 *d++ = TEXT('\\');
1323 for(entry=dir->down; entry; entry=entry->next)
1324 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1325 lstrcpy(d, entry->data.cFileName);
1326 read_directory_win(entry, buffer);
1327 SortDirectory(entry, sortOrder);
1332 SortDirectory(dir, sortOrder);
1336 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1338 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1339 const static TCHAR sSlash[] = {'/', '\0'};
1340 #endif
1341 const static TCHAR sBackslash[] = {'\\', '\0'};
1343 #ifdef _SHELL_FOLDERS
1344 if (pidl)
1346 /* read shell namespace tree */
1347 root->drive_type = DRIVE_UNKNOWN;
1348 drv[0] = '\\';
1349 drv[1] = '\0';
1350 load_string(root->volname, IDS_DESKTOP);
1351 root->fs_flags = 0;
1352 load_string(root->fs, IDS_SHELL);
1354 return read_tree_shell(root, pidl, sortOrder, hwnd);
1356 else
1357 #endif
1358 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1359 if (*path == '/')
1361 /* read unix file system tree */
1362 root->drive_type = GetDriveType(path);
1364 lstrcat(drv, sSlash);
1365 load_string(root->volname, IDS_ROOT_FS);
1366 root->fs_flags = 0;
1367 load_string(root->fs, IDS_UNIXFS);
1369 lstrcpy(root->path, sSlash);
1371 return read_tree_unix(root, path, sortOrder, hwnd);
1373 #endif
1375 /* read WIN32 file system tree */
1376 root->drive_type = GetDriveType(path);
1378 lstrcat(drv, sBackslash);
1379 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1381 lstrcpy(root->path, drv);
1383 return read_tree_win(root, path, sortOrder, hwnd);
1387 /* flags to filter different file types */
1388 enum TYPE_FILTER {
1389 TF_DIRECTORIES = 0x01,
1390 TF_PROGRAMS = 0x02,
1391 TF_DOCUMENTS = 0x04,
1392 TF_OTHERS = 0x08,
1393 TF_HIDDEN = 0x10,
1394 TF_ALL = 0x1F
1398 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1400 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1401 TCHAR b1[BUFFER_LEN];
1402 const static TCHAR sAsterics[] = {'*', '\0'};
1404 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1405 Root* root = &child->root;
1406 Entry* entry;
1408 memset(child, 0, sizeof(ChildWnd));
1410 child->left.treePane = TRUE;
1411 child->left.visible_cols = 0;
1413 child->right.treePane = FALSE;
1414 #ifndef _NO_EXTENSIONS
1415 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1416 #else
1417 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1418 #endif
1420 child->pos.length = sizeof(WINDOWPLACEMENT);
1421 child->pos.flags = 0;
1422 child->pos.showCmd = SW_SHOWNORMAL;
1423 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1424 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1425 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1426 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1428 child->focus_pane = 0;
1429 child->split_pos = DEFAULT_SPLIT_POS;
1430 child->sortOrder = SORT_NAME;
1431 child->header_wdths_ok = FALSE;
1433 if (path)
1435 lstrcpy(child->path, path);
1437 _tsplitpath(path, drv, dir, name, ext);
1440 lstrcpy(child->filter_pattern, sAsterics);
1441 child->filter_flags = TF_ALL;
1443 root->entry.level = 0;
1445 entry = read_tree(root, path, pidl, drv, child->sortOrder, hwnd);
1447 #ifdef _SHELL_FOLDERS
1448 if (root->entry.etype == ET_SHELL)
1449 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1450 else
1451 #endif
1452 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1454 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1456 child->left.root = &root->entry;
1457 child->right.root = NULL;
1459 set_curdir(child, entry, 0, hwnd);
1461 return child;
1465 /* free all memory associated with a child window */
1466 static void free_child_window(ChildWnd* child)
1468 free_entries(&child->root.entry);
1469 free(child);
1473 /* get full path of specified directory entry */
1474 static void get_path(Entry* dir, PTSTR path)
1476 Entry* entry;
1477 int len = 0;
1478 int level = 0;
1480 #ifdef _SHELL_FOLDERS
1481 if (dir->etype == ET_SHELL)
1483 SFGAOF attribs;
1484 HRESULT hr = S_OK;
1486 path[0] = TEXT('\0');
1488 attribs = 0;
1490 if (dir->folder)
1491 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1493 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1494 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1496 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1499 else
1500 #endif
1502 for(entry=dir; entry; level++) {
1503 LPCTSTR name;
1504 int l;
1507 LPCTSTR s;
1508 name = entry->data.cFileName;
1509 s = name;
1511 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1512 l++;
1515 if (entry->up) {
1516 if (l > 0) {
1517 memmove(path+l+1, path, len*sizeof(TCHAR));
1518 memcpy(path+1, name, l*sizeof(TCHAR));
1519 len += l+1;
1521 #ifndef _NO_EXTENSIONS
1522 if (entry->etype == ET_UNIX)
1523 path[0] = TEXT('/');
1524 else
1525 #endif
1526 path[0] = TEXT('\\');
1529 entry = entry->up;
1530 } else {
1531 memmove(path+l, path, len*sizeof(TCHAR));
1532 memcpy(path, name, l*sizeof(TCHAR));
1533 len += l;
1534 break;
1538 if (!level) {
1539 #ifndef _NO_EXTENSIONS
1540 if (entry->etype == ET_UNIX)
1541 path[len++] = TEXT('/');
1542 else
1543 #endif
1544 path[len++] = TEXT('\\');
1547 path[len] = TEXT('\0');
1552 static void resize_frame_rect(HWND hwnd, PRECT prect)
1554 int new_top;
1555 RECT rt;
1557 if (IsWindowVisible(Globals.htoolbar)) {
1558 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1559 GetClientRect(Globals.htoolbar, &rt);
1560 prect->top = rt.bottom+3;
1561 prect->bottom -= rt.bottom+3;
1564 if (IsWindowVisible(Globals.hdrivebar)) {
1565 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1566 GetClientRect(Globals.hdrivebar, &rt);
1567 new_top = --prect->top + rt.bottom+3;
1568 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1569 prect->top = new_top;
1570 prect->bottom -= rt.bottom+2;
1573 if (IsWindowVisible(Globals.hstatusbar)) {
1574 int parts[] = {300, 500};
1576 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1577 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1578 GetClientRect(Globals.hstatusbar, &rt);
1579 prect->bottom -= rt.bottom;
1582 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1585 static void resize_frame(HWND hwnd, int cx, int cy)
1587 RECT rect;
1589 rect.left = 0;
1590 rect.top = 0;
1591 rect.right = cx;
1592 rect.bottom = cy;
1594 resize_frame_rect(hwnd, &rect);
1597 static void resize_frame_client(HWND hwnd)
1599 RECT rect;
1601 GetClientRect(hwnd, &rect);
1603 resize_frame_rect(hwnd, &rect);
1607 static HHOOK hcbthook;
1608 static ChildWnd* newchild = NULL;
1610 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1612 if (code==HCBT_CREATEWND && newchild) {
1613 ChildWnd* child = newchild;
1614 newchild = NULL;
1616 child->hwnd = (HWND) wparam;
1617 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1620 return CallNextHookEx(hcbthook, code, wparam, lparam);
1623 static HWND create_child_window(ChildWnd* child)
1625 MDICREATESTRUCT mcs;
1626 int idx;
1628 mcs.szClass = sWINEFILETREE;
1629 mcs.szTitle = (LPTSTR)child->path;
1630 mcs.hOwner = Globals.hInstance;
1631 mcs.x = child->pos.rcNormalPosition.left;
1632 mcs.y = child->pos.rcNormalPosition.top;
1633 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1634 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1635 mcs.style = 0;
1636 mcs.lParam = 0;
1638 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1640 newchild = child;
1641 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1642 if (!child->hwnd) {
1643 UnhookWindowsHookEx(hcbthook);
1644 return 0;
1647 UnhookWindowsHookEx(hcbthook);
1649 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1650 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1652 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
1653 ListBox_SetCurSel(child->left.hwnd, idx);
1655 return child->hwnd;
1659 struct ExecuteDialog {
1660 TCHAR cmd[MAX_PATH];
1661 int cmdshow;
1664 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1666 static struct ExecuteDialog* dlg;
1668 switch(nmsg) {
1669 case WM_INITDIALOG:
1670 dlg = (struct ExecuteDialog*) lparam;
1671 return 1;
1673 case WM_COMMAND: {
1674 int id = (int)wparam;
1676 if (id == IDOK) {
1677 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1678 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1679 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1680 EndDialog(hwnd, id);
1681 } else if (id == IDCANCEL)
1682 EndDialog(hwnd, id);
1684 return 1;}
1687 return 0;
1691 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1693 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1695 switch(nmsg) {
1696 case WM_INITDIALOG:
1697 SetWindowLong(hwnd, GWL_USERDATA, lparam);
1698 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1699 return 1;
1701 case WM_COMMAND: {
1702 int id = (int)wparam;
1704 switch(id) {
1705 case IDOK: {
1706 LPTSTR dest = (LPTSTR) GetWindowLong(hwnd, GWL_USERDATA);
1707 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1708 EndDialog(hwnd, id);
1709 break;}
1711 case IDCANCEL:
1712 EndDialog(hwnd, id);
1713 break;
1715 case 254:
1716 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1717 break;
1720 return 1;
1724 return 0;
1728 struct FilterDialog {
1729 TCHAR pattern[MAX_PATH];
1730 int flags;
1733 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1735 static struct FilterDialog* dlg;
1737 switch(nmsg) {
1738 case WM_INITDIALOG:
1739 dlg = (struct FilterDialog*) lparam;
1740 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1741 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES), (dlg->flags&TF_DIRECTORIES? BST_CHECKED: BST_UNCHECKED));
1742 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS), dlg->flags&TF_PROGRAMS? BST_CHECKED: BST_UNCHECKED);
1743 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS), dlg->flags&TF_DOCUMENTS? BST_CHECKED: BST_UNCHECKED);
1744 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS), dlg->flags&TF_OTHERS? BST_CHECKED: BST_UNCHECKED);
1745 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN), dlg->flags&TF_HIDDEN? BST_CHECKED: BST_UNCHECKED);
1746 return 1;
1748 case WM_COMMAND: {
1749 int id = (int)wparam;
1751 if (id == IDOK) {
1752 int flags = 0;
1754 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1756 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES))&BST_CHECKED? TF_DIRECTORIES: 0;
1757 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS))&BST_CHECKED? TF_PROGRAMS: 0;
1758 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS))&BST_CHECKED? TF_DOCUMENTS: 0;
1759 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS))&BST_CHECKED? TF_OTHERS: 0;
1760 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN))&BST_CHECKED? TF_HIDDEN: 0;
1762 dlg->flags = flags;
1764 EndDialog(hwnd, id);
1765 } else if (id == IDCANCEL)
1766 EndDialog(hwnd, id);
1768 return 1;}
1771 return 0;
1775 struct PropertiesDialog {
1776 TCHAR path[MAX_PATH];
1777 Entry entry;
1778 void* pVersionData;
1781 /* Structure used to store enumerated languages and code pages. */
1782 struct LANGANDCODEPAGE {
1783 WORD wLanguage;
1784 WORD wCodePage;
1785 } *lpTranslate;
1787 static LPCSTR InfoStrings[] = {
1788 "Comments",
1789 "CompanyName",
1790 "FileDescription",
1791 "FileVersion",
1792 "InternalName",
1793 "LegalCopyright",
1794 "LegalTrademarks",
1795 "OriginalFilename",
1796 "PrivateBuild",
1797 "ProductName",
1798 "ProductVersion",
1799 "SpecialBuild",
1800 NULL
1803 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1805 int idx = ListBox_GetCurSel(hlbox);
1807 if (idx != LB_ERR) {
1808 LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx);
1810 if (pValue)
1811 SetWindowText(hedit, pValue);
1815 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1817 static TCHAR sBackSlash[] = {'\\','\0'};
1818 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'};
1819 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1820 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1821 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1823 if (dwVersionDataLen) {
1824 dlg->pVersionData = malloc(dwVersionDataLen);
1826 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1827 LPVOID pVal;
1828 UINT nValLen;
1830 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1831 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1832 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1833 char buffer[BUFFER_LEN];
1835 sprintf(buffer, "%d.%d.%d.%d",
1836 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1837 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1839 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1843 /* Read the list of languages and code pages. */
1844 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1845 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1846 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1848 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1850 /* Read the file description for each language and code page. */
1851 for(; pTranslate<pEnd; ++pTranslate) {
1852 LPCSTR* p;
1854 for(p=InfoStrings; *p; ++p) {
1855 TCHAR subblock[200];
1856 #ifdef UNICODE
1857 TCHAR infoStr[100];
1858 #endif
1859 LPCTSTR pTxt;
1860 UINT nValLen;
1862 LPCSTR pInfoString = *p;
1863 #ifdef UNICODE
1864 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1865 #else
1866 #define infoStr pInfoString
1867 #endif
1868 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1870 /* Retrieve file description for language and code page */
1871 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1872 int idx = ListBox_AddString(hlbox, infoStr);
1873 ListBox_SetItemData(hlbox, idx, pTxt);
1878 ListBox_SetCurSel(hlbox, 0);
1880 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1886 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1888 static struct PropertiesDialog* dlg;
1890 switch(nmsg) {
1891 case WM_INITDIALOG: {
1892 const static TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1893 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1894 LPWIN32_FIND_DATA pWFD;
1895 ULONGLONG size;
1897 dlg = (struct PropertiesDialog*) lparam;
1898 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
1900 GetWindowText(hwnd, b1, MAX_PATH);
1901 wsprintf(b2, b1, pWFD->cFileName);
1902 SetWindowText(hwnd, b2);
1904 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1905 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1907 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
1908 _stprintf(b1, sLongNumFmt, size);
1909 wsprintf(b2, sByteFmt, b1);
1910 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1912 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1913 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1915 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_READONLY), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY? BST_CHECKED: BST_UNCHECKED));
1916 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_ARCHIVE), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE? BST_CHECKED: BST_UNCHECKED));
1917 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_COMPRESSED), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED? BST_CHECKED: BST_UNCHECKED));
1918 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_HIDDEN), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN? BST_CHECKED: BST_UNCHECKED));
1919 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_SYSTEM), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM? BST_CHECKED: BST_UNCHECKED));
1921 CheckForFileInfo(dlg, hwnd, dlg->path);
1922 return 1;}
1924 case WM_COMMAND: {
1925 int id = (int)wparam;
1927 switch(HIWORD(wparam)) {
1928 case LBN_SELCHANGE: {
1929 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1930 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1931 break;
1934 case BN_CLICKED:
1935 if (id==IDOK || id==IDCANCEL)
1936 EndDialog(hwnd, id);
1939 return 1;}
1941 case WM_NCDESTROY:
1942 free(dlg->pVersionData);
1943 dlg->pVersionData = NULL;
1944 break;
1947 return 0;
1950 static void show_properties_dlg(Entry* entry, HWND hwnd)
1952 struct PropertiesDialog dlg;
1954 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1955 get_path(entry, dlg.path);
1956 memcpy(&dlg.entry, entry, sizeof(Entry));
1958 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1962 #ifndef _NO_EXTENSIONS
1964 static struct FullScreenParameters {
1965 BOOL mode;
1966 RECT orgPos;
1967 BOOL wasZoomed;
1968 } g_fullscreen = {
1969 FALSE, /* mode */
1970 {0, 0, 0, 0},
1971 FALSE
1974 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1976 RECT rt;
1978 if (!IsIconic(hwnd))
1979 GetClientRect(hwnd, prect);
1980 else {
1981 WINDOWPLACEMENT wp;
1983 GetWindowPlacement(hwnd, &wp);
1985 prect->left = prect->top = 0;
1986 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1987 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1988 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1989 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1990 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1993 if (IsWindowVisible(Globals.htoolbar)) {
1994 GetClientRect(Globals.htoolbar, &rt);
1995 prect->top += rt.bottom+2;
1998 if (IsWindowVisible(Globals.hdrivebar)) {
1999 GetClientRect(Globals.hdrivebar, &rt);
2000 prect->top += rt.bottom+2;
2003 if (IsWindowVisible(Globals.hstatusbar)) {
2004 GetClientRect(Globals.hstatusbar, &rt);
2005 prect->bottom -= rt.bottom;
2009 static BOOL toggle_fullscreen(HWND hwnd)
2011 RECT rt;
2013 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2014 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2015 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2017 Frame_CalcFrameClient(hwnd, &rt);
2018 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2019 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2021 rt.left = g_fullscreen.orgPos.left-rt.left;
2022 rt.top = g_fullscreen.orgPos.top-rt.top;
2023 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2024 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2026 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2027 } else {
2028 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2029 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2030 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2032 if (g_fullscreen.wasZoomed)
2033 ShowWindow(hwnd, WS_MAXIMIZE);
2036 return g_fullscreen.mode;
2039 static void fullscreen_move(HWND hwnd)
2041 RECT rt, pos;
2042 GetWindowRect(hwnd, &pos);
2044 Frame_CalcFrameClient(hwnd, &rt);
2045 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2046 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2048 rt.left = pos.left-rt.left;
2049 rt.top = pos.top-rt.top;
2050 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2051 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2053 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2056 #endif
2059 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2061 BOOL vis = IsWindowVisible(hchild);
2063 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2065 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2067 #ifndef _NO_EXTENSIONS
2068 if (g_fullscreen.mode)
2069 fullscreen_move(hwnd);
2070 #endif
2072 resize_frame_client(hwnd);
2075 static BOOL activate_drive_window(LPCTSTR path)
2077 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2078 HWND child_wnd;
2080 _tsplitpath(path, drv1, 0, 0, 0);
2082 /* search for a already open window for the same drive */
2083 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2084 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
2086 if (child) {
2087 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2089 if (!lstrcmpi(drv2, drv1)) {
2090 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2092 if (IsMinimized(child_wnd))
2093 ShowWindow(child_wnd, SW_SHOWNORMAL);
2095 return TRUE;
2100 return FALSE;
2103 static BOOL activate_fs_window(LPCTSTR filesys)
2105 HWND child_wnd;
2107 /* search for a already open window of the given file system name */
2108 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2109 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
2111 if (child) {
2112 if (!lstrcmpi(child->root.fs, filesys)) {
2113 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2115 if (IsMinimized(child_wnd))
2116 ShowWindow(child_wnd, SW_SHOWNORMAL);
2118 return TRUE;
2123 return FALSE;
2126 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2128 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2130 switch(nmsg) {
2131 case WM_CLOSE:
2132 DestroyWindow(hwnd);
2134 /* clear handle variables */
2135 Globals.hMenuFrame = 0;
2136 Globals.hMenuView = 0;
2137 Globals.hMenuOptions = 0;
2138 Globals.hMainWnd = 0;
2139 Globals.hmdiclient = 0;
2140 Globals.hdrivebar = 0;
2141 break;
2143 case WM_DESTROY:
2144 /* don't exit desktop when closing file manager window */
2145 if (!Globals.hwndParent)
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;
2248 Globals.hfont = CreateFontIndirect(&lFont);
2249 SelectFont(hdc, Globals.hfont);
2250 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2252 /* change font in all open child windows */
2253 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
2254 ChildWnd* child = (ChildWnd*) GetWindowLong(childWnd, GWL_USERDATA);
2255 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
2256 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
2257 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2258 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2259 InvalidateRect(child->left.hwnd, NULL, TRUE);
2260 InvalidateRect(child->right.hwnd, NULL, TRUE);
2263 else if (CommDlgExtendedError()) {
2264 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
2265 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
2266 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
2269 ReleaseDC(hwnd, hdc);
2270 break;
2273 case ID_VIEW_TOOL_BAR:
2274 toggle_child(hwnd, cmd, Globals.htoolbar);
2275 break;
2277 case ID_VIEW_DRIVE_BAR:
2278 toggle_child(hwnd, cmd, Globals.hdrivebar);
2279 break;
2281 case ID_VIEW_STATUSBAR:
2282 toggle_child(hwnd, cmd, Globals.hstatusbar);
2283 break;
2285 case ID_EXECUTE: {
2286 struct ExecuteDialog dlg;
2288 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2290 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2291 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2293 if ((int)hinst <= 32)
2294 display_error(hwnd, GetLastError());
2296 break;}
2298 case ID_CONNECT_NETWORK_DRIVE: {
2299 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2300 if (ret == NO_ERROR)
2301 refresh_drives();
2302 else if (ret != (DWORD)-1) {
2303 if (ret == ERROR_EXTENDED_ERROR)
2304 display_network_error(hwnd);
2305 else
2306 display_error(hwnd, ret);
2308 break;}
2310 case ID_DISCONNECT_NETWORK_DRIVE: {
2311 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2312 if (ret == NO_ERROR)
2313 refresh_drives();
2314 else if (ret != (DWORD)-1) {
2315 if (ret == ERROR_EXTENDED_ERROR)
2316 display_network_error(hwnd);
2317 else
2318 display_error(hwnd, ret);
2320 break;}
2322 case ID_FORMAT_DISK: {
2323 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2324 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2325 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2326 SetErrorMode(sem_org); /* Put it back the way it was. */
2327 break;}
2329 case ID_HELP:
2330 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2331 break;
2333 #ifndef _NO_EXTENSIONS
2334 case ID_VIEW_FULLSCREEN:
2335 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2336 break;
2338 #ifdef __WINE__
2339 case ID_DRIVE_UNIX_FS: {
2340 TCHAR path[MAX_PATH];
2341 #ifdef UNICODE
2342 char cpath[MAX_PATH];
2343 #endif
2344 ChildWnd* child;
2346 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2347 break;
2349 #ifdef UNICODE
2350 getcwd(cpath, MAX_PATH);
2351 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2352 #else
2353 getcwd(path, MAX_PATH);
2354 #endif
2355 child = alloc_child_window(path, NULL, hwnd);
2357 if (!create_child_window(child))
2358 free(child);
2359 break;}
2360 #endif
2361 #ifdef _SHELL_FOLDERS
2362 case ID_DRIVE_SHELL_NS: {
2363 TCHAR path[MAX_PATH];
2364 ChildWnd* child;
2366 if (activate_fs_window(RS(b1,IDS_SHELL)))
2367 break;
2369 GetCurrentDirectory(MAX_PATH, path);
2370 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2372 if (!create_child_window(child))
2373 free(child);
2374 break;}
2375 #endif
2376 #endif
2378 /*TODO: There are even more menu items! */
2380 #ifndef _NO_EXTENSIONS
2381 #ifdef __WINE__
2382 case ID_LICENSE:
2383 WineLicense(Globals.hMainWnd);
2384 break;
2386 case ID_NO_WARRANTY:
2387 WineWarranty(Globals.hMainWnd);
2388 break;
2389 #endif
2391 case ID_ABOUT_WINE:
2392 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2393 break;
2395 case ID_ABOUT:
2396 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2397 break;
2398 #endif /* _NO_EXTENSIONS */
2400 default:
2401 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2402 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2403 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2404 (cmd<SC_SIZE || cmd>SC_RESTORE))
2405 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2407 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2409 break;}
2411 case WM_SIZE:
2412 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2413 break; /* do not pass message to DefFrameProc */
2415 #ifndef _NO_EXTENSIONS
2416 case WM_GETMINMAXINFO: {
2417 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2419 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2420 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2421 break;}
2423 case FRM_CALC_CLIENT:
2424 frame_get_clientspace(hwnd, (PRECT)lparam);
2425 return TRUE;
2426 #endif /* _NO_EXTENSIONS */
2428 default:
2429 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2432 return 0;
2436 static TCHAR g_pos_names[COLUMNS][20] = {
2437 {'\0'} /* symbol */
2440 static const int g_pos_align[] = {
2442 HDF_LEFT, /* Name */
2443 HDF_RIGHT, /* Size */
2444 HDF_LEFT, /* CDate */
2445 #ifndef _NO_EXTENSIONS
2446 HDF_LEFT, /* ADate */
2447 HDF_LEFT, /* MDate */
2448 HDF_LEFT, /* Index */
2449 HDF_CENTER, /* Links */
2450 #endif
2451 HDF_CENTER, /* Attributes */
2452 #ifndef _NO_EXTENSIONS
2453 HDF_LEFT /* Security */
2454 #endif
2457 static void resize_tree(ChildWnd* child, int cx, int cy)
2459 HDWP hdwp = BeginDeferWindowPos(4);
2460 RECT rt;
2462 rt.left = 0;
2463 rt.top = 0;
2464 rt.right = cx;
2465 rt.bottom = cy;
2467 cx = child->split_pos + SPLIT_WIDTH/2;
2469 #ifndef _NO_EXTENSIONS
2471 WINDOWPOS wp;
2472 HD_LAYOUT hdl;
2474 hdl.prc = &rt;
2475 hdl.pwpos = &wp;
2477 Header_Layout(child->left.hwndHeader, &hdl);
2479 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2480 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2481 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2482 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2484 #endif /* _NO_EXTENSIONS */
2486 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);
2487 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2489 EndDeferWindowPos(hdwp);
2493 #ifndef _NO_EXTENSIONS
2495 static HWND create_header(HWND parent, Pane* pane, int id)
2497 HD_ITEM hdi;
2498 int idx;
2500 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2501 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2502 if (!hwnd)
2503 return 0;
2505 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2507 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2509 for(idx=0; idx<COLUMNS; idx++) {
2510 hdi.pszText = g_pos_names[idx];
2511 hdi.fmt = HDF_STRING | g_pos_align[idx];
2512 hdi.cxy = pane->widths[idx];
2513 Header_InsertItem(hwnd, idx, &hdi);
2516 return hwnd;
2519 #endif /* _NO_EXTENSIONS */
2522 static void init_output(HWND hwnd)
2524 const static TCHAR s1000[] = {'1','0','0','0','\0'};
2526 TCHAR b[16];
2527 HFONT old_font;
2528 HDC hdc = GetDC(hwnd);
2530 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2531 Globals.num_sep = b[1];
2532 else
2533 Globals.num_sep = TEXT('.');
2535 old_font = SelectFont(hdc, Globals.hfont);
2536 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2537 SelectFont(hdc, old_font);
2538 ReleaseDC(hwnd, hdc);
2541 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2544 /* calculate preferred width for all visible columns */
2546 static BOOL calc_widths(Pane* pane, BOOL anyway)
2548 int col, x, cx, spc=3*Globals.spaceSize.cx;
2549 int entries = ListBox_GetCount(pane->hwnd);
2550 int orgWidths[COLUMNS];
2551 int orgPositions[COLUMNS+1];
2552 HFONT hfontOld;
2553 HDC hdc;
2554 int cnt;
2556 if (!anyway) {
2557 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2558 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2561 for(col=0; col<COLUMNS; col++)
2562 pane->widths[col] = 0;
2564 hdc = GetDC(pane->hwnd);
2565 hfontOld = SelectFont(hdc, Globals.hfont);
2567 for(cnt=0; cnt<entries; cnt++) {
2568 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2570 DRAWITEMSTRUCT dis;
2572 dis.CtlType = 0;
2573 dis.CtlID = 0;
2574 dis.itemID = 0;
2575 dis.itemAction = 0;
2576 dis.itemState = 0;
2577 dis.hwndItem = pane->hwnd;
2578 dis.hDC = hdc;
2579 dis.rcItem.left = 0;
2580 dis.rcItem.top = 0;
2581 dis.rcItem.right = 0;
2582 dis.rcItem.bottom = 0;
2583 /*dis.itemData = 0; */
2585 draw_item(pane, &dis, entry, COLUMNS);
2588 SelectObject(hdc, hfontOld);
2589 ReleaseDC(pane->hwnd, hdc);
2591 x = 0;
2592 for(col=0; col<COLUMNS; col++) {
2593 pane->positions[col] = x;
2594 cx = pane->widths[col];
2596 if (cx) {
2597 cx += spc;
2599 if (cx < IMAGE_WIDTH)
2600 cx = IMAGE_WIDTH;
2602 pane->widths[col] = cx;
2605 x += cx;
2608 pane->positions[COLUMNS] = x;
2610 ListBox_SetHorizontalExtent(pane->hwnd, x);
2612 /* no change? */
2613 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2614 return FALSE;
2616 /* don't move, if only collapsing an entry */
2617 if (!anyway && pane->widths[0]<orgWidths[0] &&
2618 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2619 pane->widths[0] = orgWidths[0];
2620 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2622 return FALSE;
2625 InvalidateRect(pane->hwnd, 0, TRUE);
2627 return TRUE;
2631 /* calculate one preferred column width */
2633 static void calc_single_width(Pane* pane, int col)
2635 HFONT hfontOld;
2636 int x, cx;
2637 int entries = ListBox_GetCount(pane->hwnd);
2638 int cnt;
2639 HDC hdc;
2641 pane->widths[col] = 0;
2643 hdc = GetDC(pane->hwnd);
2644 hfontOld = SelectFont(hdc, Globals.hfont);
2646 for(cnt=0; cnt<entries; cnt++) {
2647 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2648 DRAWITEMSTRUCT dis;
2650 dis.CtlType = 0;
2651 dis.CtlID = 0;
2652 dis.itemID = 0;
2653 dis.itemAction = 0;
2654 dis.itemState = 0;
2655 dis.hwndItem = pane->hwnd;
2656 dis.hDC = hdc;
2657 dis.rcItem.left = 0;
2658 dis.rcItem.top = 0;
2659 dis.rcItem.right = 0;
2660 dis.rcItem.bottom = 0;
2661 /*dis.itemData = 0; */
2663 draw_item(pane, &dis, entry, col);
2666 SelectObject(hdc, hfontOld);
2667 ReleaseDC(pane->hwnd, hdc);
2669 cx = pane->widths[col];
2671 if (cx) {
2672 cx += 3*Globals.spaceSize.cx;
2674 if (cx < IMAGE_WIDTH)
2675 cx = IMAGE_WIDTH;
2678 pane->widths[col] = cx;
2680 x = pane->positions[col] + cx;
2682 for(; col<COLUMNS; ) {
2683 pane->positions[++col] = x;
2684 x += pane->widths[col];
2687 ListBox_SetHorizontalExtent(pane->hwnd, x);
2691 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2693 for( ; *str&&*pattern; str++,pattern++) {
2694 if (*pattern == '*') {
2695 do pattern++;
2696 while(*pattern == '*');
2698 if (!*pattern)
2699 return TRUE;
2701 for(; *str; str++)
2702 if (*str==*pattern && pattern_match(str, pattern))
2703 return TRUE;
2705 return FALSE;
2707 else if (*str!=*pattern && *pattern!='?')
2708 return FALSE;
2711 if (*str || *pattern)
2712 if (*pattern!='*' || pattern[1]!='\0')
2713 return FALSE;
2715 return TRUE;
2718 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2720 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2722 lstrcpy(b1, str);
2723 lstrcpy(b2, pattern);
2724 CharUpper(b1);
2725 CharUpper(b2);
2727 return pattern_match(b1, b2);
2731 enum FILE_TYPE {
2732 FT_OTHER = 0,
2733 FT_EXECUTABLE = 1,
2734 FT_DOCUMENT = 2
2737 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2740 /* insert listbox entries after index idx */
2742 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2744 Entry* entry = dir;
2746 if (!entry)
2747 return idx;
2749 ShowWindow(pane->hwnd, SW_HIDE);
2751 for(; entry; entry=entry->next) {
2752 #ifndef _LEFT_FILES
2753 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2754 continue;
2755 #endif
2757 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2758 /* don't display entries "." and ".." in the left pane */
2759 if (pane->treePane && entry->data.cFileName[0]==TEXT('.'))
2760 if (
2761 #ifndef _NO_EXTENSIONS
2762 entry->data.cFileName[1]==TEXT('\0') ||
2763 #endif
2764 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2765 continue;
2767 /* filter directories in right pane */
2768 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2769 continue;
2772 /* filter using the file name pattern */
2773 if (pattern)
2774 if (!pattern_imatch(entry->data.cFileName, pattern))
2775 continue;
2777 /* filter system and hidden files */
2778 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2779 continue;
2781 /* filter looking at the file type */
2782 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2783 switch(get_file_type(entry->data.cFileName)) {
2784 case FT_EXECUTABLE:
2785 if (!(filter_flags & TF_PROGRAMS))
2786 continue;
2787 break;
2789 case FT_DOCUMENT:
2790 if (!(filter_flags & TF_DOCUMENTS))
2791 continue;
2792 break;
2794 default: /* TF_OTHERS */
2795 if (!(filter_flags & TF_OTHERS))
2796 continue;
2799 if (idx != -1)
2800 idx++;
2802 ListBox_InsertItemData(pane->hwnd, idx, entry);
2804 if (pane->treePane && entry->expanded)
2805 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2808 ShowWindow(pane->hwnd, SW_SHOW);
2810 return idx;
2814 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2816 const static TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2817 const static TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2818 const static TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2820 float fBytes = (float)bytes;
2822 if (bytes >= 1073741824) /* 1 GB */
2823 wsprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2824 else if (bytes >= 1048576) /* 1 MB */
2825 wsprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2826 else if (bytes >= 1024) /* 1 kB */
2827 wsprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2828 else
2829 _stprintf(buffer, sLongNumFmt, bytes);
2832 static void set_space_status(void)
2834 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2835 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2837 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2838 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2839 format_bytes(b2, ulTotalBytes.QuadPart);
2840 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2841 } else
2842 lstrcpy(buffer, sQMarks);
2844 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2848 static WNDPROC g_orgTreeWndProc;
2850 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2852 const static TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2854 static int s_init = 0;
2855 Entry* entry = pane->root;
2857 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2858 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2859 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2861 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2862 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2864 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2866 /* insert entries into listbox */
2867 if (entry)
2868 insert_entries(pane, entry, pattern, filter_flags, -1);
2870 /* calculate column widths */
2871 if (!s_init) {
2872 s_init = 1;
2873 init_output(pane->hwnd);
2876 calc_widths(pane, TRUE);
2878 #ifndef _NO_EXTENSIONS
2879 pane->hwndHeader = create_header(parent, pane, id_header);
2880 #endif
2884 static void InitChildWindow(ChildWnd* child)
2886 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2887 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2891 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2893 SYSTEMTIME systime;
2894 FILETIME lft;
2895 int len = 0;
2897 *buffer = TEXT('\0');
2899 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2900 return;
2902 if (!FileTimeToLocalFileTime(ft, &lft))
2903 {err: lstrcpy(buffer,sQMarks); return;}
2905 if (!FileTimeToSystemTime(&lft, &systime))
2906 goto err;
2908 if (visible_cols & COL_DATE) {
2909 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2910 if (!len)
2911 goto err;
2914 if (visible_cols & COL_TIME) {
2915 if (len)
2916 buffer[len-1] = ' ';
2918 buffer[len++] = ' ';
2920 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2921 buffer[len] = TEXT('\0');
2926 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2928 RECT rt = {0, 0, 0, 0};
2930 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2932 if (rt.right > pane->widths[col])
2933 pane->widths[col] = rt.right;
2936 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2938 RECT rt = {0, 0, 0, 0};
2940 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2941 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2943 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2944 /*FIXME rt (0,0) ??? */
2946 if (rt.right > pane->widths[col])
2947 pane->widths[col] = rt.right;
2951 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2953 int x = dis->rcItem.left;
2954 RECT rt;
2956 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2957 rt.top = dis->rcItem.top;
2958 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2959 rt.bottom = dis->rcItem.bottom;
2961 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2964 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2966 int x = dis->rcItem.left;
2967 RECT rt;
2969 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2970 rt.top = dis->rcItem.top;
2971 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2972 rt.bottom = dis->rcItem.bottom;
2974 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2975 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2977 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2980 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2982 int x = dis->rcItem.left;
2983 RECT rt;
2984 LPCTSTR s = str;
2985 TCHAR b[128];
2986 LPTSTR d = b;
2987 int pos;
2989 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2990 rt.top = dis->rcItem.top;
2991 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2992 rt.bottom = dis->rcItem.bottom;
2994 if (*s)
2995 *d++ = *s++;
2997 /* insert number separator characters */
2998 pos = lstrlen(s) % 3;
3000 while(*s)
3001 if (pos--)
3002 *d++ = *s++;
3003 else {
3004 *d++ = Globals.num_sep;
3005 pos = 3;
3008 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3012 static BOOL is_exe_file(LPCTSTR ext)
3014 static const TCHAR executable_extensions[][4] = {
3015 {'C','O','M','\0'},
3016 {'E','X','E','\0'},
3017 {'B','A','T','\0'},
3018 {'C','M','D','\0'},
3019 #ifndef _NO_EXTENSIONS
3020 {'C','M','M','\0'},
3021 {'B','T','M','\0'},
3022 {'A','W','K','\0'},
3023 #endif /* _NO_EXTENSIONS */
3024 {'\0'}
3027 TCHAR ext_buffer[_MAX_EXT];
3028 const TCHAR (*p)[4];
3029 LPCTSTR s;
3030 LPTSTR d;
3032 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3033 d++;
3035 for(p=executable_extensions; (*p)[0]; p++)
3036 if (!lstrcmpi(ext_buffer, *p))
3037 return TRUE;
3039 return FALSE;
3042 static BOOL is_registered_type(LPCTSTR ext)
3044 /* check if there exists a classname for this file extension in the registry */
3045 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3046 return TRUE;
3048 return FALSE;
3051 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3053 LPCTSTR ext = _tcsrchr(filename, '.');
3054 if (!ext)
3055 ext = sEmpty;
3057 if (is_exe_file(ext))
3058 return FT_EXECUTABLE;
3059 else if (is_registered_type(ext))
3060 return FT_DOCUMENT;
3061 else
3062 return FT_OTHER;
3066 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3068 TCHAR buffer[BUFFER_LEN];
3069 DWORD attrs;
3070 int visible_cols = pane->visible_cols;
3071 COLORREF bkcolor, textcolor;
3072 RECT focusRect = dis->rcItem;
3073 HBRUSH hbrush;
3074 enum IMAGE img;
3075 int img_pos, cx;
3076 int col = 0;
3078 if (entry) {
3079 attrs = entry->data.dwFileAttributes;
3081 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3082 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
3083 && entry->data.cFileName[2]==TEXT('\0'))
3084 img = IMG_FOLDER_UP;
3085 #ifndef _NO_EXTENSIONS
3086 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
3087 img = IMG_FOLDER_CUR;
3088 #endif
3089 else if (
3090 #ifdef _NO_EXTENSIONS
3091 entry->expanded ||
3092 #endif
3093 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3094 img = IMG_OPEN_FOLDER;
3095 else
3096 img = IMG_FOLDER;
3097 } else {
3098 switch(get_file_type(entry->data.cFileName)) {
3099 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3100 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3101 default: img = IMG_FILE;
3104 } else {
3105 attrs = 0;
3106 img = IMG_NONE;
3109 if (pane->treePane) {
3110 if (entry) {
3111 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3113 if (calcWidthCol == -1) {
3114 int x;
3115 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3116 Entry* up;
3117 RECT rt_clip;
3118 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3119 HRGN hrgn;
3121 rt_clip.left = dis->rcItem.left;
3122 rt_clip.top = dis->rcItem.top;
3123 rt_clip.right = dis->rcItem.left+pane->widths[col];
3124 rt_clip.bottom = dis->rcItem.bottom;
3126 hrgn = CreateRectRgnIndirect(&rt_clip);
3128 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3129 DeleteObject(hrgn_org);
3130 hrgn_org = 0;
3133 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3134 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3135 DeleteObject(hrgn);
3137 if ((up=entry->up) != NULL) {
3138 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3139 LineTo(dis->hDC, img_pos-2, y);
3141 x = img_pos - IMAGE_WIDTH/2;
3143 do {
3144 x -= IMAGE_WIDTH+TREE_LINE_DX;
3146 if (up->next
3147 #ifndef _LEFT_FILES
3148 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3149 #endif
3151 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3152 LineTo(dis->hDC, x, dis->rcItem.bottom);
3154 } while((up=up->up) != NULL);
3157 x = img_pos - IMAGE_WIDTH/2;
3159 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3160 LineTo(dis->hDC, x, y);
3162 if (entry->next
3163 #ifndef _LEFT_FILES
3164 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3165 #endif
3167 LineTo(dis->hDC, x, dis->rcItem.bottom);
3169 SelectClipRgn(dis->hDC, hrgn_org);
3170 if (hrgn_org) DeleteObject(hrgn_org);
3171 /* SelectObject(dis->hDC, holdPen); */
3172 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3173 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3175 if (right > pane->widths[col])
3176 pane->widths[col] = right;
3178 } else {
3179 img_pos = dis->rcItem.left;
3181 } else {
3182 img_pos = dis->rcItem.left;
3184 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3185 pane->widths[col] = IMAGE_WIDTH;
3188 if (calcWidthCol == -1) {
3189 focusRect.left = img_pos -2;
3191 #ifdef _NO_EXTENSIONS
3192 if (pane->treePane && entry) {
3193 RECT rt = {0};
3195 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3197 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3199 #else
3201 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3202 textcolor = COLOR_COMPRESSED;
3203 else
3204 #endif /* _NO_EXTENSIONS */
3205 textcolor = RGB(0,0,0);
3207 if (dis->itemState & ODS_FOCUS) {
3208 textcolor = RGB(255,255,255);
3209 bkcolor = COLOR_SELECTION;
3210 } else {
3211 bkcolor = RGB(255,255,255);
3214 hbrush = CreateSolidBrush(bkcolor);
3215 FillRect(dis->hDC, &focusRect, hbrush);
3216 DeleteObject(hbrush);
3218 SetBkMode(dis->hDC, TRANSPARENT);
3219 SetTextColor(dis->hDC, textcolor);
3221 cx = pane->widths[col];
3223 if (cx && img!=IMG_NONE) {
3224 if (cx > IMAGE_WIDTH)
3225 cx = IMAGE_WIDTH;
3227 #ifdef _SHELL_FOLDERS
3228 if (entry->hicon && entry->hicon!=(HICON)-1)
3229 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3230 else
3231 #endif
3232 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3233 img_pos, dis->rcItem.top, cx,
3234 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3238 if (!entry)
3239 return;
3241 #ifdef _NO_EXTENSIONS
3242 if (img >= IMG_FOLDER_UP)
3243 return;
3244 #endif
3246 col++;
3248 /* ouput file name */
3249 if (calcWidthCol == -1)
3250 output_text(pane, dis, col, entry->data.cFileName, 0);
3251 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3252 calc_width(pane, dis, col, entry->data.cFileName);
3254 col++;
3256 #ifdef _NO_EXTENSIONS
3257 if (!pane->treePane) {
3258 #endif
3260 /* display file size */
3261 if (visible_cols & COL_SIZE) {
3262 #ifdef _NO_EXTENSIONS
3263 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3264 #endif
3266 ULONGLONG size;
3268 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3270 _stprintf(buffer, sLongNumFmt, size);
3272 if (calcWidthCol == -1)
3273 output_number(pane, dis, col, buffer);
3274 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3275 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3278 col++;
3281 /* display file date */
3282 if (visible_cols & (COL_DATE|COL_TIME)) {
3283 #ifndef _NO_EXTENSIONS
3284 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3285 if (calcWidthCol == -1)
3286 output_text(pane, dis, col, buffer, 0);
3287 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3288 calc_width(pane, dis, col, buffer);
3289 col++;
3291 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3292 if (calcWidthCol == -1)
3293 output_text(pane, dis, col, buffer, 0);
3294 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3295 calc_width(pane, dis, col, buffer);
3296 col++;
3297 #endif /* _NO_EXTENSIONS */
3299 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3300 if (calcWidthCol == -1)
3301 output_text(pane, dis, col, buffer, 0);
3302 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3303 calc_width(pane, dis, col, buffer);
3304 col++;
3307 #ifndef _NO_EXTENSIONS
3308 if (entry->bhfi_valid) {
3309 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3311 if (visible_cols & COL_INDEX) {
3312 _stprintf(buffer, sLongHexFmt, index);
3314 if (calcWidthCol == -1)
3315 output_text(pane, dis, col, buffer, DT_RIGHT);
3316 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3317 calc_width(pane, dis, col, buffer);
3319 col++;
3322 if (visible_cols & COL_LINKS) {
3323 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3325 if (calcWidthCol == -1)
3326 output_text(pane, dis, col, buffer, DT_CENTER);
3327 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3328 calc_width(pane, dis, col, buffer);
3330 col++;
3332 } else
3333 col += 2;
3334 #endif /* _NO_EXTENSIONS */
3336 /* show file attributes */
3337 if (visible_cols & COL_ATTRIBUTES) {
3338 #ifdef _NO_EXTENSIONS
3339 const static TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3340 lstrcpy(buffer, s4Tabs);
3341 #else
3342 const static TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3343 lstrcpy(buffer, s11Tabs);
3344 #endif
3346 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3347 else {
3348 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3349 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3350 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3351 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3352 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3353 #ifndef _NO_EXTENSIONS
3354 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3355 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3356 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3357 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3358 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3359 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3360 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3361 #endif /* _NO_EXTENSIONS */
3364 if (calcWidthCol == -1)
3365 output_tabbed_text(pane, dis, col, buffer);
3366 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3367 calc_tabbed_width(pane, dis, col, buffer);
3369 col++;
3372 /*TODO
3373 if (flags.security) {
3374 const static TCHAR sSecTabs[] = {
3375 ' ','\t',' ','\t',' ','\t',' ',
3376 ' ','\t',' ',
3377 ' ','\t',' ','\t',' ','\t',' ',
3378 ' ','\t',' ',
3379 ' ','\t',' ','\t',' ','\t',' ',
3380 '\0'
3383 DWORD rights = get_access_mask();
3385 lstrcpy(buffer, sSecTabs);
3387 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3388 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3389 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3390 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3391 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3392 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3393 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3394 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3395 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3396 if (rights & WRITE_DAC) buffer[22] = 'C';
3397 if (rights & WRITE_OWNER) buffer[24] = 'O';
3398 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3400 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3403 if (flags.description) {
3404 get_description(buffer);
3405 output_text(dis, col++, buffer, 0, psize);
3409 #ifdef _NO_EXTENSIONS
3412 /* draw focus frame */
3413 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3414 /* Currently [04/2000] Wine neither behaves exactly the same */
3415 /* way as WIN 95 nor like Windows NT... */
3416 HGDIOBJ lastBrush;
3417 HPEN lastPen;
3418 HPEN hpen;
3420 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3421 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3422 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3423 } else
3424 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3426 lastPen = SelectPen(dis->hDC, hpen);
3427 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3428 SetROP2(dis->hDC, R2_XORPEN);
3429 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3430 SelectObject(dis->hDC, lastBrush);
3431 SelectObject(dis->hDC, lastPen);
3432 DeleteObject(hpen);
3434 #endif /* _NO_EXTENSIONS */
3438 #ifdef _NO_EXTENSIONS
3440 static void draw_splitbar(HWND hwnd, int x)
3442 RECT rt;
3443 HDC hdc = GetDC(hwnd);
3445 GetClientRect(hwnd, &rt);
3447 rt.left = x - SPLIT_WIDTH/2;
3448 rt.right = x + SPLIT_WIDTH/2+1;
3450 InvertRect(hdc, &rt);
3452 ReleaseDC(hwnd, hdc);
3455 #endif /* _NO_EXTENSIONS */
3458 #ifndef _NO_EXTENSIONS
3460 static void set_header(Pane* pane)
3462 HD_ITEM item;
3463 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3464 int i=0, x=0;
3466 item.mask = HDI_WIDTH;
3467 item.cxy = 0;
3469 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3470 x += pane->widths[i];
3471 Header_SetItem(pane->hwndHeader, i, &item);
3474 if (i < COLUMNS) {
3475 x += pane->widths[i];
3476 item.cxy = x - scroll_pos;
3477 Header_SetItem(pane->hwndHeader, i++, &item);
3479 for(; i<COLUMNS; i++) {
3480 item.cxy = pane->widths[i];
3481 x += pane->widths[i];
3482 Header_SetItem(pane->hwndHeader, i, &item);
3487 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3489 switch(pnmh->code) {
3490 case HDN_TRACK:
3491 case HDN_ENDTRACK: {
3492 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3493 int idx = phdn->iItem;
3494 int dx = phdn->pitem->cxy - pane->widths[idx];
3495 int i;
3497 RECT clnt;
3498 GetClientRect(pane->hwnd, &clnt);
3500 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3501 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
3503 pane->widths[idx] += dx;
3505 for(i=idx; ++i<=COLUMNS; )
3506 pane->positions[i] += dx;
3509 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3510 RECT rt_scr;
3511 RECT rt_clip;
3513 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3514 rt_scr.top = 0;
3515 rt_scr.right = clnt.right;
3516 rt_scr.bottom = clnt.bottom;
3518 rt_clip.left = pane->positions[idx]-scroll_pos;
3519 rt_clip.top = 0;
3520 rt_clip.right = clnt.right;
3521 rt_clip.bottom = clnt.bottom;
3523 if (rt_scr.left < 0) rt_scr.left = 0;
3524 if (rt_clip.left < 0) rt_clip.left = 0;
3526 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3528 rt_clip.right = pane->positions[idx+1];
3529 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3531 if (pnmh->code == HDN_ENDTRACK) {
3532 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
3534 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3535 set_header(pane);
3539 return FALSE;
3542 case HDN_DIVIDERDBLCLICK: {
3543 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3544 HD_ITEM item;
3546 calc_single_width(pane, phdn->iItem);
3547 item.mask = HDI_WIDTH;
3548 item.cxy = pane->widths[phdn->iItem];
3550 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3551 InvalidateRect(pane->hwnd, 0, TRUE);
3552 break;}
3555 return 0;
3558 #endif /* _NO_EXTENSIONS */
3561 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3563 TCHAR path[MAX_PATH];
3564 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3566 /* delete sub entries in left pane */
3567 for(;;) {
3568 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3569 Entry* sub = (Entry*) res;
3571 if (res==LB_ERR || !sub || sub->level<=entry->level)
3572 break;
3574 ListBox_DeleteString(child->left.hwnd, idx+1);
3577 /* empty right pane */
3578 ListBox_ResetContent(child->right.hwnd);
3580 /* release memory */
3581 free_entries(entry);
3583 /* read contents from disk */
3584 #ifdef _SHELL_FOLDERS
3585 if (entry->etype == ET_SHELL)
3587 read_directory(entry, NULL, child->sortOrder, hwnd);
3589 else
3590 #endif
3592 get_path(entry, path);
3593 read_directory(entry, path, child->sortOrder, hwnd);
3596 /* insert found entries in right pane */
3597 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3598 calc_widths(&child->right, FALSE);
3599 #ifndef _NO_EXTENSIONS
3600 set_header(&child->right);
3601 #endif
3603 child->header_wdths_ok = FALSE;
3605 SetCursor(old_cursor);
3609 /* expand a directory entry */
3611 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3613 int idx;
3614 Entry* p;
3616 if (!dir || dir->expanded || !dir->down)
3617 return FALSE;
3619 p = dir->down;
3621 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3622 p = p->next;
3624 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3625 p->data.cFileName[2]=='\0' && p->next)
3626 p = p->next;
3629 /* no subdirectories ? */
3630 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3631 return FALSE;
3633 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3635 dir->expanded = TRUE;
3637 /* insert entries in left pane */
3638 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3640 if (!child->header_wdths_ok) {
3641 if (calc_widths(&child->left, FALSE)) {
3642 #ifndef _NO_EXTENSIONS
3643 set_header(&child->left);
3644 #endif
3646 child->header_wdths_ok = TRUE;
3650 return TRUE;
3654 static void collapse_entry(Pane* pane, Entry* dir)
3656 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3658 ShowWindow(pane->hwnd, SW_HIDE);
3660 /* hide sub entries */
3661 for(;;) {
3662 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3663 Entry* sub = (Entry*) res;
3665 if (res==LB_ERR || !sub || sub->level<=dir->level)
3666 break;
3668 ListBox_DeleteString(pane->hwnd, idx+1);
3671 dir->expanded = FALSE;
3673 ShowWindow(pane->hwnd, SW_SHOW);
3677 static void refresh_right_pane(ChildWnd* child)
3679 ListBox_ResetContent(child->right.hwnd);
3680 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3681 calc_widths(&child->right, FALSE);
3683 #ifndef _NO_EXTENSIONS
3684 set_header(&child->right);
3685 #endif
3688 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3690 TCHAR path[MAX_PATH];
3692 if (!entry)
3693 return;
3695 path[0] = '\0';
3697 child->left.cur = entry;
3699 child->right.root = entry->down? entry->down: entry;
3700 child->right.cur = entry;
3702 if (!entry->scanned)
3703 scan_entry(child, entry, idx, hwnd);
3704 else
3705 refresh_right_pane(child);
3707 get_path(entry, path);
3708 lstrcpy(child->path, path);
3710 if (child->hwnd) /* only change window title, if the window already exists */
3711 SetWindowText(child->hwnd, path);
3713 if (path[0])
3714 if (SetCurrentDirectory(path))
3715 set_space_status();
3719 static void refresh_child(ChildWnd* child)
3721 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3722 Entry* entry;
3723 int idx;
3725 get_path(child->left.cur, path);
3726 _tsplitpath(path, drv, NULL, NULL, NULL);
3728 child->right.root = NULL;
3730 scan_entry(child, &child->root.entry, 0, child->hwnd);
3732 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3734 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3736 set_curdir(child, entry, 0, child->hwnd);
3738 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
3739 ListBox_SetCurSel(child->left.hwnd, idx);
3743 static void create_drive_bar(void)
3745 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3746 #ifndef _NO_EXTENSIONS
3747 TCHAR b1[BUFFER_LEN];
3748 #endif
3749 int btn = 1;
3750 PTSTR p;
3752 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3754 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3755 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3756 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3758 #ifndef _NO_EXTENSIONS
3759 #ifdef __WINE__
3760 /* insert unix file system button */
3761 b1[0] = '/';
3762 b1[1] = '\0';
3763 b1[2] = '\0';
3764 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3766 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3767 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3768 drivebarBtn.iString++;
3769 #endif
3770 #ifdef _SHELL_FOLDERS
3771 /* insert shell namespace button */
3772 load_string(b1, IDS_SHELL);
3773 b1[lstrlen(b1)+1] = '\0';
3774 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3776 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3777 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3778 drivebarBtn.iString++;
3779 #endif
3781 /* register windows drive root strings */
3782 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3783 #endif
3785 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3787 for(p=Globals.drives; *p; ) {
3788 #ifdef _NO_EXTENSIONS
3789 /* insert drive letter */
3790 TCHAR b[3] = {tolower(*p)};
3791 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3792 #endif
3793 switch(GetDriveType(p)) {
3794 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3795 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3796 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3797 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3798 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3801 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3802 drivebarBtn.idCommand++;
3803 drivebarBtn.iString++;
3805 while(*p++);
3809 static void refresh_drives(void)
3811 RECT rect;
3813 /* destroy drive bar */
3814 DestroyWindow(Globals.hdrivebar);
3815 Globals.hdrivebar = 0;
3817 /* re-create drive bar */
3818 create_drive_bar();
3820 /* update window layout */
3821 GetClientRect(Globals.hMainWnd, &rect);
3822 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3826 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3828 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3830 if ((int)hinst <= 32) {
3831 display_error(hwnd, GetLastError());
3832 return FALSE;
3835 return TRUE;
3839 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3841 TCHAR cmd[MAX_PATH];
3843 #ifdef _SHELL_FOLDERS
3844 if (entry->etype == ET_SHELL) {
3845 BOOL ret = TRUE;
3847 SHELLEXECUTEINFO shexinfo;
3849 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3850 shexinfo.fMask = SEE_MASK_IDLIST;
3851 shexinfo.hwnd = hwnd;
3852 shexinfo.lpVerb = NULL;
3853 shexinfo.lpFile = NULL;
3854 shexinfo.lpParameters = NULL;
3855 shexinfo.lpDirectory = NULL;
3856 shexinfo.nShow = nCmdShow;
3857 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3859 if (!ShellExecuteEx(&shexinfo)) {
3860 display_error(hwnd, GetLastError());
3861 ret = FALSE;
3864 if (shexinfo.lpIDList != entry->pidl)
3865 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3867 return ret;
3869 #endif
3871 get_path(entry, cmd);
3873 /* start program, open document... */
3874 return launch_file(hwnd, cmd, nCmdShow);
3878 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3880 Entry* entry = pane->cur;
3882 if (!entry)
3883 return;
3885 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3886 int scanned_old = entry->scanned;
3888 if (!scanned_old)
3889 scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd);
3891 #ifndef _NO_EXTENSIONS
3892 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3893 return;
3894 #endif
3896 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3897 entry = child->left.cur->up;
3898 collapse_entry(&child->left, entry);
3899 goto focus_entry;
3900 } else if (entry->expanded)
3901 collapse_entry(pane, child->left.cur);
3902 else {
3903 expand_entry(child, child->left.cur);
3905 if (!pane->treePane) focus_entry: {
3906 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3907 ListBox_SetCurSel(child->left.hwnd, idx);
3908 set_curdir(child, entry, idx, hwnd);
3912 if (!scanned_old) {
3913 calc_widths(pane, FALSE);
3915 #ifndef _NO_EXTENSIONS
3916 set_header(pane);
3917 #endif
3919 } else {
3920 if (GetKeyState(VK_MENU) < 0)
3921 show_properties_dlg(entry, child->hwnd);
3922 else
3923 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3928 static BOOL pane_command(Pane* pane, UINT cmd)
3930 switch(cmd) {
3931 case ID_VIEW_NAME:
3932 if (pane->visible_cols) {
3933 pane->visible_cols = 0;
3934 calc_widths(pane, TRUE);
3935 #ifndef _NO_EXTENSIONS
3936 set_header(pane);
3937 #endif
3938 InvalidateRect(pane->hwnd, 0, TRUE);
3939 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3940 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3941 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3943 break;
3945 case ID_VIEW_ALL_ATTRIBUTES:
3946 if (pane->visible_cols != COL_ALL) {
3947 pane->visible_cols = COL_ALL;
3948 calc_widths(pane, TRUE);
3949 #ifndef _NO_EXTENSIONS
3950 set_header(pane);
3951 #endif
3952 InvalidateRect(pane->hwnd, 0, TRUE);
3953 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3954 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3955 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3957 break;
3959 #ifndef _NO_EXTENSIONS
3960 case ID_PREFERRED_SIZES: {
3961 calc_widths(pane, TRUE);
3962 set_header(pane);
3963 InvalidateRect(pane->hwnd, 0, TRUE);
3964 break;}
3965 #endif
3967 /* TODO: more command ids... */
3969 default:
3970 return FALSE;
3973 return TRUE;
3977 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3979 if (child->sortOrder != sortOrder) {
3980 child->sortOrder = sortOrder;
3981 refresh_child(child);
3985 static void update_view_menu(ChildWnd* child)
3987 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3988 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3989 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3990 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3994 static BOOL is_directory(LPCTSTR target)
3996 /*TODO correctly handle UNIX paths */
3997 DWORD target_attr = GetFileAttributes(target);
3999 if (target_attr == INVALID_FILE_ATTRIBUTES)
4000 return FALSE;
4002 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4005 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4007 TCHAR path[MAX_PATH];
4008 int len;
4010 get_path(pane->cur, path);
4012 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4013 return FALSE;
4015 get_path(pane->cur, source);
4017 /* convert relative targets to absolute paths */
4018 if (path[0]!='/' && path[1]!=':') {
4019 get_path(pane->cur->up, target);
4020 len = lstrlen(target);
4022 if (target[len-1]!='\\' && target[len-1]!='/')
4023 target[len++] = '/';
4025 lstrcpy(target+len, path);
4026 } else
4027 lstrcpy(target, path);
4029 /* If the target already exists as directory, create a new target below this. */
4030 if (is_directory(path)) {
4031 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4032 const static TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4034 _tsplitpath(source, NULL, NULL, fname, ext);
4036 wsprintf(target, sAppend, path, fname, ext);
4039 return TRUE;
4043 static IContextMenu2* s_pctxmenu2 = NULL;
4044 static IContextMenu3* s_pctxmenu3 = NULL;
4046 static void CtxMenu_reset(void)
4048 s_pctxmenu2 = NULL;
4049 s_pctxmenu3 = NULL;
4052 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4054 IContextMenu* pcm = NULL;
4056 CtxMenu_reset();
4058 if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4059 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4060 else if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4061 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4063 if (pcm) {
4064 (*pcm1->lpVtbl->Release)(pcm1);
4065 return pcm;
4066 } else
4067 return pcm1;
4070 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4072 if (s_pctxmenu3) {
4073 if (SUCCEEDED((*s_pctxmenu3->lpVtbl->HandleMenuMsg)(s_pctxmenu3, nmsg, wparam, lparam)))
4074 return TRUE;
4077 if (s_pctxmenu2)
4078 if (SUCCEEDED((*s_pctxmenu2->lpVtbl->HandleMenuMsg)(s_pctxmenu2, nmsg, wparam, lparam)))
4079 return TRUE;
4081 return FALSE;
4085 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4087 IContextMenu* pcm;
4088 BOOL executed = FALSE;
4090 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4091 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4093 if (SUCCEEDED(hr)) {
4094 HMENU hmenu = CreatePopupMenu();
4096 pcm = CtxMenu_query_interfaces(pcm);
4098 if (hmenu) {
4099 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4101 if (SUCCEEDED(hr)) {
4102 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4104 CtxMenu_reset();
4106 if (idCmd) {
4107 CMINVOKECOMMANDINFO cmi;
4109 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4110 cmi.fMask = 0;
4111 cmi.hwnd = hwndParent;
4112 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4113 cmi.lpParameters = NULL;
4114 cmi.lpDirectory = NULL;
4115 cmi.nShow = SW_SHOWNORMAL;
4116 cmi.dwHotKey = 0;
4117 cmi.hIcon = 0;
4119 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
4120 executed = TRUE;
4122 } else
4123 CtxMenu_reset();
4126 (*pcm->lpVtbl->Release)(pcm);
4129 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4133 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4135 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
4136 ASSERT(child);
4138 switch(nmsg) {
4139 case WM_DRAWITEM: {
4140 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4141 Entry* entry = (Entry*) dis->itemData;
4143 if (dis->CtlID == IDW_TREE_LEFT)
4144 draw_item(&child->left, dis, entry, -1);
4145 else if (dis->CtlID == IDW_TREE_RIGHT)
4146 draw_item(&child->right, dis, entry, -1);
4147 else
4148 goto draw_menu_item;
4150 return TRUE;}
4152 case WM_CREATE:
4153 InitChildWindow(child);
4154 break;
4156 case WM_NCDESTROY:
4157 free_child_window(child);
4158 SetWindowLong(hwnd, GWL_USERDATA, 0);
4159 break;
4161 case WM_PAINT: {
4162 PAINTSTRUCT ps;
4163 HBRUSH lastBrush;
4164 RECT rt;
4165 GetClientRect(hwnd, &rt);
4166 BeginPaint(hwnd, &ps);
4167 rt.left = child->split_pos-SPLIT_WIDTH/2;
4168 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4169 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
4170 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4171 SelectObject(ps.hdc, lastBrush);
4172 #ifdef _NO_EXTENSIONS
4173 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4174 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4175 #endif
4176 EndPaint(hwnd, &ps);
4177 break;}
4179 case WM_SETCURSOR:
4180 if (LOWORD(lparam) == HTCLIENT) {
4181 POINT pt;
4182 GetCursorPos(&pt);
4183 ScreenToClient(hwnd, &pt);
4185 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4186 SetCursor(LoadCursor(0, IDC_SIZEWE));
4187 return TRUE;
4190 goto def;
4192 case WM_LBUTTONDOWN: {
4193 RECT rt;
4194 int x = GET_X_LPARAM(lparam);
4196 GetClientRect(hwnd, &rt);
4198 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4199 last_split = child->split_pos;
4200 #ifdef _NO_EXTENSIONS
4201 draw_splitbar(hwnd, last_split);
4202 #endif
4203 SetCapture(hwnd);
4206 break;}
4208 case WM_LBUTTONUP:
4209 if (GetCapture() == hwnd) {
4210 #ifdef _NO_EXTENSIONS
4211 RECT rt;
4212 int x = LOWORD(lparam);
4213 draw_splitbar(hwnd, last_split);
4214 last_split = -1;
4215 GetClientRect(hwnd, &rt);
4216 child->split_pos = x;
4217 resize_tree(child, rt.right, rt.bottom);
4218 #endif
4219 ReleaseCapture();
4221 break;
4223 #ifdef _NO_EXTENSIONS
4224 case WM_CAPTURECHANGED:
4225 if (GetCapture()==hwnd && last_split>=0)
4226 draw_splitbar(hwnd, last_split);
4227 break;
4228 #endif
4230 case WM_KEYDOWN:
4231 if (wparam == VK_ESCAPE)
4232 if (GetCapture() == hwnd) {
4233 RECT rt;
4234 #ifdef _NO_EXTENSIONS
4235 draw_splitbar(hwnd, last_split);
4236 #else
4237 child->split_pos = last_split;
4238 #endif
4239 GetClientRect(hwnd, &rt);
4240 resize_tree(child, rt.right, rt.bottom);
4241 last_split = -1;
4242 ReleaseCapture();
4243 SetCursor(LoadCursor(0, IDC_ARROW));
4245 break;
4247 case WM_MOUSEMOVE:
4248 if (GetCapture() == hwnd) {
4249 RECT rt;
4250 int x = LOWORD(lparam);
4252 #ifdef _NO_EXTENSIONS
4253 HDC hdc = GetDC(hwnd);
4254 GetClientRect(hwnd, &rt);
4256 rt.left = last_split-SPLIT_WIDTH/2;
4257 rt.right = last_split+SPLIT_WIDTH/2+1;
4258 InvertRect(hdc, &rt);
4260 last_split = x;
4261 rt.left = x-SPLIT_WIDTH/2;
4262 rt.right = x+SPLIT_WIDTH/2+1;
4263 InvertRect(hdc, &rt);
4265 ReleaseDC(hwnd, hdc);
4266 #else
4267 GetClientRect(hwnd, &rt);
4269 if (x>=0 && x<rt.right) {
4270 child->split_pos = x;
4271 resize_tree(child, rt.right, rt.bottom);
4272 rt.left = x-SPLIT_WIDTH/2;
4273 rt.right = x+SPLIT_WIDTH/2+1;
4274 InvalidateRect(hwnd, &rt, FALSE);
4275 UpdateWindow(child->left.hwnd);
4276 UpdateWindow(hwnd);
4277 UpdateWindow(child->right.hwnd);
4279 #endif
4281 break;
4283 #ifndef _NO_EXTENSIONS
4284 case WM_GETMINMAXINFO:
4285 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4287 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4289 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4290 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4291 break;}
4292 #endif /* _NO_EXTENSIONS */
4294 case WM_SETFOCUS:
4295 if (SetCurrentDirectory(child->path))
4296 set_space_status();
4297 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4298 break;
4300 case WM_DISPATCH_COMMAND: {
4301 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4303 switch(LOWORD(wparam)) {
4304 case ID_WINDOW_NEW: {
4305 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4307 if (!create_child_window(new_child))
4308 free(new_child);
4310 break;}
4312 case ID_REFRESH:
4313 refresh_drives();
4314 refresh_child(child);
4315 break;
4317 case ID_ACTIVATE:
4318 activate_entry(child, pane, hwnd);
4319 break;
4321 case ID_FILE_MOVE: {
4322 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4324 if (prompt_target(pane, source, target)) {
4325 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4327 source[lstrlen(source)+1] = '\0';
4328 target[lstrlen(target)+1] = '\0';
4330 if (!SHFileOperation(&shfo))
4331 refresh_child(child);
4333 break;}
4335 case ID_FILE_COPY: {
4336 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4338 if (prompt_target(pane, source, target)) {
4339 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4341 source[lstrlen(source)+1] = '\0';
4342 target[lstrlen(target)+1] = '\0';
4344 if (!SHFileOperation(&shfo))
4345 refresh_child(child);
4347 break;}
4349 case ID_FILE_DELETE: {
4350 TCHAR path[BUFFER_LEN];
4351 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
4353 get_path(pane->cur, path);
4355 path[lstrlen(path)+1] = '\0';
4357 if (!SHFileOperation(&shfo))
4358 refresh_child(child);
4359 break;}
4361 case ID_VIEW_SORT_NAME:
4362 set_sort_order(child, SORT_NAME);
4363 break;
4365 case ID_VIEW_SORT_TYPE:
4366 set_sort_order(child, SORT_EXT);
4367 break;
4369 case ID_VIEW_SORT_SIZE:
4370 set_sort_order(child, SORT_SIZE);
4371 break;
4373 case ID_VIEW_SORT_DATE:
4374 set_sort_order(child, SORT_DATE);
4375 break;
4377 case ID_VIEW_FILTER: {
4378 struct FilterDialog dlg;
4380 memset(&dlg, 0, sizeof(struct FilterDialog));
4381 lstrcpy(dlg.pattern, child->filter_pattern);
4382 dlg.flags = child->filter_flags;
4384 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4385 lstrcpy(child->filter_pattern, dlg.pattern);
4386 child->filter_flags = dlg.flags;
4387 refresh_right_pane(child);
4389 break;}
4391 case ID_VIEW_SPLIT: {
4392 last_split = child->split_pos;
4393 #ifdef _NO_EXTENSIONS
4394 draw_splitbar(hwnd, last_split);
4395 #endif
4396 SetCapture(hwnd);
4397 break;}
4399 case ID_EDIT_PROPERTIES:
4400 show_properties_dlg(pane->cur, child->hwnd);
4401 break;
4403 default:
4404 return pane_command(pane, LOWORD(wparam));
4407 return TRUE;}
4409 case WM_COMMAND: {
4410 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4412 switch(HIWORD(wparam)) {
4413 case LBN_SELCHANGE: {
4414 int idx = ListBox_GetCurSel(pane->hwnd);
4415 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4417 if (pane == &child->left)
4418 set_curdir(child, entry, idx, hwnd);
4419 else
4420 pane->cur = entry;
4421 break;}
4423 case LBN_DBLCLK:
4424 activate_entry(child, pane, hwnd);
4425 break;
4427 break;}
4429 #ifndef _NO_EXTENSIONS
4430 case WM_NOTIFY: {
4431 NMHDR* pnmh = (NMHDR*) lparam;
4432 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4433 #endif
4435 #ifdef _SHELL_FOLDERS
4436 case WM_CONTEXTMENU: {
4437 POINT pt, pt_clnt;
4438 Pane* pane;
4439 int idx;
4441 /* first select the current item in the listbox */
4442 HWND hpanel = (HWND) wparam;
4443 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4444 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4445 ScreenToClient(hpanel, &pt_clnt);
4446 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4447 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4449 /* now create the popup menu using shell namespace and IContextMenu */
4450 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4451 idx = ListBox_GetCurSel(pane->hwnd);
4453 if (idx != -1) {
4454 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4456 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4458 if (pidl_abs) {
4459 IShellFolder* parentFolder;
4460 LPCITEMIDLIST pidlLast;
4462 /* get and use the parent folder to display correct context menu in all cases */
4463 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4464 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4465 refresh_child(child);
4467 (*parentFolder->lpVtbl->Release)(parentFolder);
4470 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
4473 break;}
4474 #endif
4476 case WM_MEASUREITEM:
4477 draw_menu_item:
4478 if (!wparam) /* Is the message menu-related? */
4479 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4480 return TRUE;
4482 break;
4484 case WM_INITMENUPOPUP:
4485 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4486 return 0;
4488 update_view_menu(child);
4489 break;
4491 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4492 if (s_pctxmenu3) {
4493 LRESULT lResult = 0;
4495 (*s_pctxmenu3->lpVtbl->HandleMenuMsg2)(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4497 return lResult;
4500 break;
4502 case WM_SIZE:
4503 if (wparam != SIZE_MINIMIZED)
4504 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4505 /* fall through */
4507 default: def:
4508 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4511 return 0;
4515 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4517 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
4518 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
4519 ASSERT(child);
4521 switch(nmsg) {
4522 #ifndef _NO_EXTENSIONS
4523 case WM_HSCROLL:
4524 set_header(pane);
4525 break;
4526 #endif
4528 case WM_SETFOCUS:
4529 child->focus_pane = pane==&child->right? 1: 0;
4530 ListBox_SetSel(hwnd, TRUE, 1);
4531 /*TODO: check menu items */
4532 break;
4534 case WM_KEYDOWN:
4535 if (wparam == VK_TAB) {
4536 /*TODO: SetFocus(Globals.hdrivebar) */
4537 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4541 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4545 static void InitInstance(HINSTANCE hinstance)
4547 const static TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4549 WNDCLASSEX wcFrame;
4550 WNDCLASS wcChild;
4551 ATOM hChildClass;
4552 int col;
4554 INITCOMMONCONTROLSEX icc = {
4555 sizeof(INITCOMMONCONTROLSEX),
4556 ICC_BAR_CLASSES
4559 HDC hdc = GetDC(0);
4561 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4563 InitCommonControlsEx(&icc);
4566 /* register frame window class */
4568 wcFrame.cbSize = sizeof(WNDCLASSEX);
4569 wcFrame.style = 0;
4570 wcFrame.lpfnWndProc = FrameWndProc;
4571 wcFrame.cbClsExtra = 0;
4572 wcFrame.cbWndExtra = 0;
4573 wcFrame.hInstance = hinstance;
4574 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4575 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4576 wcFrame.hbrBackground = 0;
4577 wcFrame.lpszMenuName = 0;
4578 wcFrame.lpszClassName = sWINEFILEFRAME;
4579 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4580 MAKEINTRESOURCE(IDI_WINEFILE),
4581 IMAGE_ICON,
4582 GetSystemMetrics(SM_CXSMICON),
4583 GetSystemMetrics(SM_CYSMICON),
4584 LR_SHARED);
4586 Globals.hframeClass = RegisterClassEx(&wcFrame);
4589 /* register tree windows class */
4591 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4592 wcChild.lpfnWndProc = ChildWndProc;
4593 wcChild.cbClsExtra = 0;
4594 wcChild.cbWndExtra = 0;
4595 wcChild.hInstance = hinstance;
4596 wcChild.hIcon = 0;
4597 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4598 wcChild.hbrBackground = 0;
4599 wcChild.lpszMenuName = 0;
4600 wcChild.lpszClassName = sWINEFILETREE;
4602 hChildClass = RegisterClass(&wcChild);
4605 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4607 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4609 ReleaseDC(0, hdc);
4611 Globals.hInstance = hinstance;
4613 #ifdef _SHELL_FOLDERS
4614 CoInitialize(NULL);
4615 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4616 SHGetDesktopFolder(&Globals.iDesktop);
4617 #ifdef __WINE__
4618 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4619 #else
4620 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4621 #endif
4622 #endif
4624 /* load column strings */
4625 col = 1;
4627 load_string(g_pos_names[col++], IDS_COL_NAME);
4628 load_string(g_pos_names[col++], IDS_COL_SIZE);
4629 load_string(g_pos_names[col++], IDS_COL_CDATE);
4630 #ifndef _NO_EXTENSIONS
4631 load_string(g_pos_names[col++], IDS_COL_ADATE);
4632 load_string(g_pos_names[col++], IDS_COL_MDATE);
4633 load_string(g_pos_names[col++], IDS_COL_IDX);
4634 load_string(g_pos_names[col++], IDS_COL_LINKS);
4635 #endif
4636 load_string(g_pos_names[col++], IDS_COL_ATTR);
4637 #ifndef _NO_EXTENSIONS
4638 load_string(g_pos_names[col++], IDS_COL_SEC);
4639 #endif
4643 static void show_frame(HWND hwndParent, int cmdshow)
4645 const static TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4647 TCHAR path[MAX_PATH], b1[BUFFER_LEN];
4648 ChildWnd* child;
4649 HMENU hMenuFrame, hMenuWindow;
4651 CLIENTCREATESTRUCT ccs;
4653 if (Globals.hMainWnd)
4654 return;
4656 Globals.hwndParent = hwndParent;
4658 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4659 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4661 Globals.hMenuFrame = hMenuFrame;
4662 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4663 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4665 ccs.hWindowMenu = hMenuWindow;
4666 ccs.idFirstChild = IDW_FIRST_CHILD;
4669 /* create main window */
4670 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4671 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
4672 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4675 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4676 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4677 0, 0, 0, 0,
4678 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4681 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4683 create_drive_bar();
4686 TBBUTTON toolbarBtns[] = {
4687 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4688 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4689 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4690 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4691 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4692 /*TODO
4693 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4694 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4695 */ };
4697 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4698 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4699 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4700 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4703 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4704 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4706 /* CreateStatusWindow does not accept WS_BORDER
4707 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4708 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4709 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4711 /*TODO: read paths and window placements from registry */
4712 GetCurrentDirectory(MAX_PATH, path);
4714 ShowWindow(Globals.hMainWnd, cmdshow);
4716 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4717 /* Shell Namespace as default: */
4718 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4719 #else
4720 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4721 #endif
4723 child->pos.showCmd = SW_SHOWMAXIMIZED;
4724 child->pos.rcNormalPosition.left = 0;
4725 child->pos.rcNormalPosition.top = 0;
4726 child->pos.rcNormalPosition.right = 320;
4727 child->pos.rcNormalPosition.bottom = 280;
4729 if (!create_child_window(child))
4730 free(child);
4732 SetWindowPlacement(child->hwnd, &child->pos);
4734 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4736 Globals.prescan_node = FALSE;
4738 UpdateWindow(Globals.hMainWnd);
4741 static void ExitInstance(void)
4743 #ifdef _SHELL_FOLDERS
4744 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
4745 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
4746 CoUninitialize();
4747 #endif
4749 ImageList_Destroy(Globals.himl);
4752 #ifdef _NO_EXTENSIONS
4754 /* search for already running win[e]files */
4756 static int g_foundPrevInstance = 0;
4758 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4760 TCHAR cls[128];
4762 GetClassName(hwnd, cls, 128);
4764 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4765 g_foundPrevInstance++;
4766 return FALSE;
4769 return TRUE;
4772 /* search for window of given class name to allow only one running instance */
4773 static int find_window_class(LPCTSTR classname)
4775 EnumWindows(EnumWndProc, (LPARAM)classname);
4777 if (g_foundPrevInstance)
4778 return 1;
4780 return 0;
4783 #endif
4785 static int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
4787 MSG msg;
4789 InitInstance(hinstance);
4791 if (cmdshow == SW_SHOWNORMAL)
4792 /*TODO: read window placement from registry */
4793 cmdshow = SW_MAXIMIZE;
4795 show_frame(hwndParent, cmdshow);
4797 while(GetMessage(&msg, 0, 0, 0)) {
4798 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4799 continue;
4801 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4802 continue;
4804 TranslateMessage(&msg);
4805 DispatchMessage(&msg);
4808 ExitInstance();
4810 return msg.wParam;
4814 int APIENTRY WinMain(HINSTANCE hinstance,
4815 HINSTANCE previnstance,
4816 LPSTR cmdline,
4817 int cmdshow)
4819 #ifdef _NO_EXTENSIONS
4820 if (find_window_class(sWINEFILEFRAME))
4821 return 1;
4822 #endif
4824 winefile_main(hinstance, 0, cmdshow);
4826 return 0;