winefile: Add the ability to save window position to the registry.
[wine/wine64.git] / programs / winefile / winefile.c
blobafaba102600a9236748ac3c25ed8124227d38d6f
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifdef __WINE__
23 #include "config.h"
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <dirent.h>
30 #endif
32 #define COBJMACROS
34 #include "winefile.h"
35 #include "resource.h"
37 #ifdef _NO_EXTENSIONS
38 #undef _LEFT_FILES
39 #endif
41 #ifndef _MAX_PATH
42 #define _MAX_DRIVE 3
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
46 #define _MAX_PATH 260
47 #endif
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
51 #else
52 #define UNION_MEMBER(x) x
53 #endif
56 #ifdef _SHELL_FOLDERS
57 #define DEFAULT_SPLIT_POS 300
58 #else
59 #define DEFAULT_SPLIT_POS 200
60 #endif
62 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
63 'W','i','n','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
70 enum ENTRY_TYPE {
71 ET_WINDOWS,
72 ET_UNIX,
73 #ifdef _SHELL_FOLDERS
74 ET_SHELL
75 #endif
78 typedef struct _Entry {
79 struct _Entry* next;
80 struct _Entry* down;
81 struct _Entry* up;
83 BOOL expanded;
84 BOOL scanned;
85 int level;
87 WIN32_FIND_DATA data;
89 #ifndef _NO_EXTENSIONS
90 BY_HANDLE_FILE_INFORMATION bhfi;
91 BOOL bhfi_valid;
92 enum ENTRY_TYPE etype;
93 #endif
94 #ifdef _SHELL_FOLDERS
95 LPITEMIDLIST pidl;
96 IShellFolder* folder;
97 HICON hicon;
98 #endif
99 } Entry;
101 typedef struct {
102 Entry entry;
103 TCHAR path[MAX_PATH];
104 TCHAR volname[_MAX_FNAME];
105 TCHAR fs[_MAX_DIR];
106 DWORD drive_type;
107 DWORD fs_flags;
108 } Root;
110 enum COLUMN_FLAGS {
111 COL_SIZE = 0x01,
112 COL_DATE = 0x02,
113 COL_TIME = 0x04,
114 COL_ATTRIBUTES = 0x08,
115 COL_DOSNAMES = 0x10,
116 #ifdef _NO_EXTENSIONS
117 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
118 #else
119 COL_INDEX = 0x20,
120 COL_LINKS = 0x40,
121 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
122 #endif
125 typedef enum {
126 SORT_NAME,
127 SORT_EXT,
128 SORT_SIZE,
129 SORT_DATE
130 } SORT_ORDER;
132 typedef struct {
133 HWND hwnd;
134 #ifndef _NO_EXTENSIONS
135 HWND hwndHeader;
136 #endif
138 #ifndef _NO_EXTENSIONS
139 #define COLUMNS 10
140 #else
141 #define COLUMNS 5
142 #endif
143 int widths[COLUMNS];
144 int positions[COLUMNS+1];
146 BOOL treePane;
147 int visible_cols;
148 Entry* root;
149 Entry* cur;
150 } Pane;
152 typedef struct {
153 HWND hwnd;
154 Pane left;
155 Pane right;
156 int focus_pane; /* 0: left 1: right */
157 WINDOWPLACEMENT pos;
158 int split_pos;
159 BOOL header_wdths_ok;
161 TCHAR path[MAX_PATH];
162 TCHAR filter_pattern[MAX_PATH];
163 int filter_flags;
164 Root root;
166 SORT_ORDER sortOrder;
167 } ChildWnd;
171 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
172 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
173 static void refresh_child(ChildWnd* child);
174 static void refresh_drives(void);
175 static void get_path(Entry* dir, PTSTR path);
176 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
178 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
179 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
183 /* globals */
184 WINEFILE_GLOBALS Globals;
186 static int last_split;
188 /* some common string constants */
189 static const TCHAR sEmpty[] = {'\0'};
190 static const TCHAR sSpace[] = {' ', '\0'};
191 static const TCHAR sNumFmt[] = {'%','d','\0'};
192 static const TCHAR sQMarks[] = {'?','?','?','\0'};
194 /* window class names */
195 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
196 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
198 #ifdef _MSC_VER
199 /* #define LONGLONGARG _T("I64") */
200 static const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
201 static const TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
202 #else
203 /* #define LONGLONGARG _T("L") */
204 static const TCHAR sLongHexFmt[] = {'%','L','X','\0'};
205 static const TCHAR sLongNumFmt[] = {'%','L','d','\0'};
206 #endif
209 /* load resource string */
210 static LPTSTR load_string(LPTSTR buffer, UINT id)
212 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
214 return buffer;
217 #define RS(b, i) load_string(b, i)
220 /* display error message for the specified WIN32 error code */
221 static void display_error(HWND hwnd, DWORD error)
223 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
224 PTSTR msg;
226 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
227 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
228 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
229 else
230 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
232 LocalFree(msg);
236 /* display network error message using WNetGetLastError() */
237 static void display_network_error(HWND hwnd)
239 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
240 DWORD error;
242 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
243 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
246 static VOID WineLicense(HWND Wnd)
248 TCHAR cap[20], text[1024];
249 LoadString(Globals.hInstance, IDS_LICENSE, text, 1024);
250 LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, 20);
251 MessageBox(Wnd, text, cap, MB_ICONINFORMATION | MB_OK);
254 static VOID WineWarranty(HWND Wnd)
256 TCHAR cap[20], text[1024];
257 LoadString(Globals.hInstance, IDS_WARRANTY, text, 1024);
258 LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, 20);
259 MessageBox(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
263 #ifdef __WINE__
265 #ifdef UNICODE
267 /* call vswprintf() in msvcrt.dll */
268 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
269 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
271 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
272 va_list ap;
273 int ret;
275 if (!pvswprintf) {
276 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
277 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
280 va_start(ap, fmt);
281 ret = (*pvswprintf)(buffer, fmt, ap);
282 va_end(ap);
284 return ret;
287 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
289 LPCWSTR p = str;
291 while(*p)
292 ++p;
294 do {
295 if (--p < str)
296 return NULL;
297 } while(*p != c);
299 return p;
302 #define _tcsrchr my_wcsrchr
303 #else /* UNICODE */
304 #define _tcsrchr strrchr
305 #endif /* UNICODE */
307 #endif /* __WINE__ */
310 /* allocate and initialise a directory entry */
311 static Entry* alloc_entry(void)
313 Entry* entry = (Entry*) malloc(sizeof(Entry));
315 #ifdef _SHELL_FOLDERS
316 entry->pidl = NULL;
317 entry->folder = NULL;
318 entry->hicon = 0;
319 #endif
321 return entry;
324 /* free a directory entry */
325 static void free_entry(Entry* entry)
327 #ifdef _SHELL_FOLDERS
328 if (entry->hicon && entry->hicon!=(HICON)-1)
329 DestroyIcon(entry->hicon);
331 if (entry->folder && entry->folder!=Globals.iDesktop)
332 IShellFolder_Release(entry->folder);
334 if (entry->pidl)
335 IMalloc_Free(Globals.iMalloc, entry->pidl);
336 #endif
338 free(entry);
341 /* recursively free all child entries */
342 static void free_entries(Entry* dir)
344 Entry *entry, *next=dir->down;
346 if (next) {
347 dir->down = 0;
349 do {
350 entry = next;
351 next = entry->next;
353 free_entries(entry);
354 free_entry(entry);
355 } while(next);
360 static void read_directory_win(Entry* dir, LPCTSTR path)
362 Entry* first_entry = NULL;
363 Entry* last = NULL;
364 Entry* entry;
366 int level = dir->level + 1;
367 WIN32_FIND_DATA w32fd;
368 HANDLE hFind;
369 #ifndef _NO_EXTENSIONS
370 HANDLE hFile;
371 #endif
373 TCHAR buffer[MAX_PATH], *p;
374 for(p=buffer; *path; )
375 *p++ = *path++;
377 *p++ = '\\';
378 p[0] = '*';
379 p[1] = '\0';
381 hFind = FindFirstFile(buffer, &w32fd);
383 if (hFind != INVALID_HANDLE_VALUE) {
384 do {
385 #ifdef _NO_EXTENSIONS
386 /* hide directory entry "." */
387 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
388 LPCTSTR name = w32fd.cFileName;
390 if (name[0]=='.' && name[1]=='\0')
391 continue;
393 #endif
394 entry = alloc_entry();
396 if (!first_entry)
397 first_entry = entry;
399 if (last)
400 last->next = entry;
402 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
403 entry->down = NULL;
404 entry->up = dir;
405 entry->expanded = FALSE;
406 entry->scanned = FALSE;
407 entry->level = level;
409 #ifndef _NO_EXTENSIONS
410 entry->etype = ET_WINDOWS;
411 entry->bhfi_valid = FALSE;
413 lstrcpy(p, entry->data.cFileName);
415 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
416 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
418 if (hFile != INVALID_HANDLE_VALUE) {
419 if (GetFileInformationByHandle(hFile, &entry->bhfi))
420 entry->bhfi_valid = TRUE;
422 CloseHandle(hFile);
424 #endif
426 last = entry;
427 } while(FindNextFile(hFind, &w32fd));
429 if (last)
430 last->next = NULL;
432 FindClose(hFind);
435 dir->down = first_entry;
436 dir->scanned = TRUE;
440 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
442 Entry* entry;
444 for(entry=dir->down; entry; entry=entry->next) {
445 LPCTSTR p = name;
446 LPCTSTR q = entry->data.cFileName;
448 do {
449 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
450 return entry;
451 } while(tolower(*p++) == tolower(*q++));
453 p = name;
454 q = entry->data.cAlternateFileName;
456 do {
457 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
458 return entry;
459 } while(tolower(*p++) == tolower(*q++));
462 return 0;
466 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
468 TCHAR buffer[MAX_PATH];
469 Entry* entry = &root->entry;
470 LPCTSTR s = path;
471 PTSTR d = buffer;
473 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
475 #ifndef _NO_EXTENSIONS
476 entry->etype = ET_WINDOWS;
477 #endif
479 while(entry) {
480 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
481 *d++ = *s++;
483 while(*s==TEXT('\\') || *s==TEXT('/'))
484 s++;
486 *d++ = TEXT('\\');
487 *d = TEXT('\0');
489 read_directory(entry, buffer, sortOrder, hwnd);
491 if (entry->down)
492 entry->expanded = TRUE;
494 if (!*s)
495 break;
497 entry = find_entry_win(entry, s);
500 SetCursor(old_cursor);
502 return entry;
506 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
508 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
510 struct tm* tm = gmtime(t);
511 SYSTEMTIME stime;
513 if (!tm)
514 return FALSE;
516 stime.wYear = tm->tm_year+1900;
517 stime.wMonth = tm->tm_mon+1;
518 /* stime.wDayOfWeek */
519 stime.wDay = tm->tm_mday;
520 stime.wHour = tm->tm_hour;
521 stime.wMinute = tm->tm_min;
522 stime.wSecond = tm->tm_sec;
524 return SystemTimeToFileTime(&stime, ftime);
527 static void read_directory_unix(Entry* dir, LPCTSTR path)
529 Entry* first_entry = NULL;
530 Entry* last = NULL;
531 Entry* entry;
532 DIR* pdir;
534 int level = dir->level + 1;
535 #ifdef UNICODE
536 char cpath[MAX_PATH];
538 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
539 #else
540 const char* cpath = path;
541 #endif
543 pdir = opendir(cpath);
545 if (pdir) {
546 struct stat st;
547 struct dirent* ent;
548 char buffer[MAX_PATH], *p;
549 const char* s;
551 for(p=buffer,s=cpath; *s; )
552 *p++ = *s++;
554 if (p==buffer || p[-1]!='/')
555 *p++ = '/';
557 while((ent=readdir(pdir))) {
558 entry = alloc_entry();
560 if (!first_entry)
561 first_entry = entry;
563 if (last)
564 last->next = entry;
566 entry->etype = ET_UNIX;
568 strcpy(p, ent->d_name);
569 #ifdef UNICODE
570 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
571 #else
572 lstrcpy(entry->data.cFileName, p);
573 #endif
575 if (!stat(buffer, &st)) {
576 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
578 if (S_ISDIR(st.st_mode))
579 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
581 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
582 entry->data.nFileSizeHigh = st.st_size >> 32;
584 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
585 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
586 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
588 entry->bhfi.nFileIndexLow = ent->d_ino;
589 entry->bhfi.nFileIndexHigh = 0;
591 entry->bhfi.nNumberOfLinks = st.st_nlink;
593 entry->bhfi_valid = TRUE;
594 } else {
595 entry->data.nFileSizeLow = 0;
596 entry->data.nFileSizeHigh = 0;
597 entry->bhfi_valid = FALSE;
600 entry->down = NULL;
601 entry->up = dir;
602 entry->expanded = FALSE;
603 entry->scanned = FALSE;
604 entry->level = level;
606 last = entry;
609 if (last)
610 last->next = NULL;
612 closedir(pdir);
615 dir->down = first_entry;
616 dir->scanned = TRUE;
619 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
621 Entry* entry;
623 for(entry=dir->down; entry; entry=entry->next) {
624 LPCTSTR p = name;
625 LPCTSTR q = entry->data.cFileName;
627 do {
628 if (!*p || *p==TEXT('/'))
629 return entry;
630 } while(*p++ == *q++);
633 return 0;
636 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
638 TCHAR buffer[MAX_PATH];
639 Entry* entry = &root->entry;
640 LPCTSTR s = path;
641 PTSTR d = buffer;
643 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
645 entry->etype = ET_UNIX;
647 while(entry) {
648 while(*s && *s!=TEXT('/'))
649 *d++ = *s++;
651 while(*s == TEXT('/'))
652 s++;
654 *d++ = TEXT('/');
655 *d = TEXT('\0');
657 read_directory(entry, buffer, sortOrder, hwnd);
659 if (entry->down)
660 entry->expanded = TRUE;
662 if (!*s)
663 break;
665 entry = find_entry_unix(entry, s);
668 SetCursor(old_cursor);
670 return entry;
673 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
676 #ifdef _SHELL_FOLDERS
678 #ifdef UNICODE
679 #define get_strret get_strretW
680 #define path_from_pidl path_from_pidlW
681 #else
682 #define get_strret get_strretA
683 #define path_from_pidl path_from_pidlA
684 #endif
687 static void free_strret(STRRET* str)
689 if (str->uType == STRRET_WSTR)
690 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
694 #ifndef UNICODE
696 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
698 LPCSTR s;
699 LPSTR d = dest;
701 for(s=source; count&&(*d++=*s++); )
702 count--;
704 return dest;
707 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
709 switch(str->uType) {
710 case STRRET_WSTR:
711 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
712 break;
714 case STRRET_OFFSET:
715 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
716 break;
718 case STRRET_CSTR:
719 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
723 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
725 STRRET str;
727 /* SHGDN_FORPARSING: get full path of id list */
728 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
730 if (SUCCEEDED(hr)) {
731 get_strretA(&str, &pidl->mkid, buffer, len);
732 free_strret(&str);
733 } else
734 buffer[0] = '\0';
736 return hr;
739 #endif
741 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
743 LPCWSTR s;
744 LPWSTR d = dest;
746 for(s=source; count&&(*d++=*s++); )
747 count--;
749 return dest;
752 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
754 switch(str->uType) {
755 case STRRET_WSTR:
756 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
757 break;
759 case STRRET_OFFSET:
760 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
761 break;
763 case STRRET_CSTR:
764 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
769 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
771 STRRET str;
773 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
775 if (SUCCEEDED(hr)) {
776 get_strret(&str, &pidl->mkid, buffer, len);
777 free_strret(&str);
778 } else
779 buffer[0] = '\0';
781 return hr;
785 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
787 STRRET str;
789 /* SHGDN_FORPARSING: get full path of id list */
790 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
792 if (SUCCEEDED(hr)) {
793 get_strretW(&str, &pidl->mkid, buffer, len);
794 free_strret(&str);
795 } else
796 buffer[0] = '\0';
798 return hr;
802 /* create an item id list from a file system path */
804 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
806 LPITEMIDLIST pidl;
807 HRESULT hr;
808 ULONG len;
810 #ifdef UNICODE
811 LPWSTR buffer = path;
812 #else
813 WCHAR buffer[MAX_PATH];
814 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
815 #endif
817 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
818 if (FAILED(hr))
819 return NULL;
821 return pidl;
825 /* convert an item id list from relative to absolute (=relative to the desktop) format */
827 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
829 if (entry->up && entry->up->etype==ET_SHELL) {
830 IShellFolder* folder = entry->up->folder;
831 WCHAR buffer[MAX_PATH];
833 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
835 if (SUCCEEDED(hr)) {
836 LPITEMIDLIST pidl;
837 ULONG len;
839 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
841 if (SUCCEEDED(hr))
842 return pidl;
844 } else if (entry->etype == ET_WINDOWS) {
845 TCHAR path[MAX_PATH];
847 get_path(entry, path);
849 return get_path_pidl(path, hwnd);
850 } else if (entry->pidl)
851 return ILClone(entry->pidl);
853 return NULL;
857 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
859 IExtractIcon* pExtract;
861 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
862 TCHAR path[_MAX_PATH];
863 unsigned flags;
864 HICON hicon;
865 int idx;
867 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
868 if (!(flags & GIL_NOTFILENAME)) {
869 if (idx == -1)
870 idx = 0; /* special case for some control panel applications */
872 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
873 flags &= ~GIL_DONTCACHE;
874 } else {
875 HICON hIconLarge = 0;
877 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
879 if (SUCCEEDED(hr))
880 DestroyIcon(hIconLarge);
883 return hicon;
887 return 0;
891 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
893 Entry* entry;
895 for(entry=dir->down; entry; entry=entry->next) {
896 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
897 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
898 return entry;
901 return 0;
904 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
906 Entry* entry = &root->entry;
907 Entry* next;
908 LPITEMIDLIST next_pidl = pidl;
909 IShellFolder* folder;
910 IShellFolder* child = NULL;
911 HRESULT hr;
913 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
915 #ifndef _NO_EXTENSIONS
916 entry->etype = ET_SHELL;
917 #endif
919 folder = Globals.iDesktop;
921 while(entry) {
922 entry->pidl = next_pidl;
923 entry->folder = folder;
925 if (!pidl->mkid.cb)
926 break;
928 /* copy first element of item idlist */
929 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
930 memcpy(next_pidl, pidl, pidl->mkid.cb);
931 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
933 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
934 if (!SUCCEEDED(hr))
935 break;
937 read_directory(entry, NULL, sortOrder, hwnd);
939 if (entry->down)
940 entry->expanded = TRUE;
942 next = find_entry_shell(entry, next_pidl);
943 if (!next)
944 break;
946 folder = child;
947 entry = next;
949 /* go to next element */
950 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
953 SetCursor(old_cursor);
955 return entry;
959 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
961 if (!(attribs & SFGAO_FILESYSTEM) ||
962 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
963 WIN32_FILE_ATTRIBUTE_DATA fad;
964 IDataObject* pDataObj;
966 STGMEDIUM medium = {0, {0}, 0};
967 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
969 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
971 if (SUCCEEDED(hr)) {
972 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
974 IDataObject_Release(pDataObj);
976 if (SUCCEEDED(hr)) {
977 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
978 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
980 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
981 w32fdata->dwFileAttributes = fad.dwFileAttributes;
982 w32fdata->ftCreationTime = fad.ftCreationTime;
983 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
984 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
986 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
987 w32fdata->nFileSizeLow = fad.nFileSizeLow;
988 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
992 SetErrorMode(sem_org);
994 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
995 GlobalFree(medium.UNION_MEMBER(hGlobal));
1000 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
1001 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1003 if (attribs & SFGAO_READONLY)
1004 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
1006 if (attribs & SFGAO_COMPRESSED)
1007 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
1011 static void read_directory_shell(Entry* dir, HWND hwnd)
1013 IShellFolder* folder = dir->folder;
1014 int level = dir->level + 1;
1015 HRESULT hr;
1017 IShellFolder* child;
1018 IEnumIDList* idlist;
1020 Entry* first_entry = NULL;
1021 Entry* last = NULL;
1022 Entry* entry;
1024 if (!folder)
1025 return;
1027 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1029 if (SUCCEEDED(hr)) {
1030 for(;;) {
1031 #define FETCH_ITEM_COUNT 32
1032 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1033 SFGAOF attribs;
1034 ULONG cnt = 0;
1035 ULONG n;
1037 memset(pidls, 0, sizeof(pidls));
1039 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1040 if (!SUCCEEDED(hr))
1041 break;
1043 if (hr == S_FALSE)
1044 break;
1046 for(n=0; n<cnt; ++n) {
1047 entry = alloc_entry();
1049 if (!first_entry)
1050 first_entry = entry;
1052 if (last)
1053 last->next = entry;
1055 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1056 entry->bhfi_valid = FALSE;
1058 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1060 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1062 if (SUCCEEDED(hr)) {
1063 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1064 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1066 entry->bhfi_valid = TRUE;
1067 } else
1068 attribs = 0;
1069 } else
1070 attribs = 0;
1072 entry->pidl = pidls[n];
1074 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1075 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1077 if (SUCCEEDED(hr))
1078 entry->folder = child;
1079 else
1080 entry->folder = NULL;
1082 else
1083 entry->folder = NULL;
1085 if (!entry->data.cFileName[0])
1086 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1088 /* get display icons for files and virtual objects */
1089 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1090 !(attribs & SFGAO_FILESYSTEM)) {
1091 entry->hicon = extract_icon(folder, pidls[n]);
1093 if (!entry->hicon)
1094 entry->hicon = (HICON)-1; /* don't try again later */
1097 entry->down = NULL;
1098 entry->up = dir;
1099 entry->expanded = FALSE;
1100 entry->scanned = FALSE;
1101 entry->level = level;
1103 #ifndef _NO_EXTENSIONS
1104 entry->etype = ET_SHELL;
1105 entry->bhfi_valid = FALSE;
1106 #endif
1108 last = entry;
1112 IEnumIDList_Release(idlist);
1115 if (last)
1116 last->next = NULL;
1118 dir->down = first_entry;
1119 dir->scanned = TRUE;
1122 #endif /* _SHELL_FOLDERS */
1125 /* sort order for different directory/file types */
1126 enum TYPE_ORDER {
1127 TO_DIR = 0,
1128 TO_DOT = 1,
1129 TO_DOTDOT = 2,
1130 TO_OTHER_DIR = 3,
1131 TO_FILE = 4
1134 /* distinguish between ".", ".." and any other directory names */
1135 static int TypeOrderFromDirname(LPCTSTR name)
1137 if (name[0] == '.') {
1138 if (name[1] == '\0')
1139 return TO_DOT; /* "." */
1141 if (name[1]=='.' && name[2]=='\0')
1142 return TO_DOTDOT; /* ".." */
1145 return TO_OTHER_DIR; /* anything else */
1148 /* directories first... */
1149 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1151 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1152 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1154 /* Handle "." and ".." as special case and move them at the very first beginning. */
1155 if (order1==TO_DIR && order2==TO_DIR) {
1156 order1 = TypeOrderFromDirname(fd1->cFileName);
1157 order2 = TypeOrderFromDirname(fd2->cFileName);
1160 return order2==order1? 0: order1<order2? -1: 1;
1164 static int compareName(const void* arg1, const void* arg2)
1166 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1167 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1169 int cmp = compareType(fd1, fd2);
1170 if (cmp)
1171 return cmp;
1173 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1176 static int compareExt(const void* arg1, const void* arg2)
1178 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1179 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1180 const TCHAR *name1, *name2, *ext1, *ext2;
1182 int cmp = compareType(fd1, fd2);
1183 if (cmp)
1184 return cmp;
1186 name1 = fd1->cFileName;
1187 name2 = fd2->cFileName;
1189 ext1 = _tcsrchr(name1, TEXT('.'));
1190 ext2 = _tcsrchr(name2, TEXT('.'));
1192 if (ext1)
1193 ext1++;
1194 else
1195 ext1 = sEmpty;
1197 if (ext2)
1198 ext2++;
1199 else
1200 ext2 = sEmpty;
1202 cmp = lstrcmpi(ext1, ext2);
1203 if (cmp)
1204 return cmp;
1206 return lstrcmpi(name1, name2);
1209 static int compareSize(const void* arg1, const void* arg2)
1211 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1212 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1214 int cmp = compareType(fd1, fd2);
1215 if (cmp)
1216 return cmp;
1218 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1220 if (cmp < 0)
1221 return -1;
1222 else if (cmp > 0)
1223 return 1;
1225 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1227 return cmp<0? -1: cmp>0? 1: 0;
1230 static int compareDate(const void* arg1, const void* arg2)
1232 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1233 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1235 int cmp = compareType(fd1, fd2);
1236 if (cmp)
1237 return cmp;
1239 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1243 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1244 compareName, /* SORT_NAME */
1245 compareExt, /* SORT_EXT */
1246 compareSize, /* SORT_SIZE */
1247 compareDate /* SORT_DATE */
1251 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1253 Entry* entry = dir->down;
1254 Entry** array, **p;
1255 int len;
1257 len = 0;
1258 for(entry=dir->down; entry; entry=entry->next)
1259 len++;
1261 if (len) {
1262 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1264 p = array;
1265 for(entry=dir->down; entry; entry=entry->next)
1266 *p++ = entry;
1268 /* call qsort with the appropriate compare function */
1269 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1271 dir->down = array[0];
1273 for(p=array; --len; p++)
1274 p[0]->next = p[1];
1276 (*p)->next = 0;
1278 HeapFree(GetProcessHeap(), 0, array);
1283 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1285 TCHAR buffer[MAX_PATH];
1286 Entry* entry;
1287 LPCTSTR s;
1288 PTSTR d;
1290 #ifdef _SHELL_FOLDERS
1291 if (dir->etype == ET_SHELL)
1293 read_directory_shell(dir, hwnd);
1295 if (Globals.prescan_node) {
1296 s = path;
1297 d = buffer;
1299 while(*s)
1300 *d++ = *s++;
1302 *d++ = TEXT('\\');
1304 for(entry=dir->down; entry; entry=entry->next)
1305 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1306 read_directory_shell(entry, hwnd);
1307 SortDirectory(entry, sortOrder);
1311 else
1312 #endif
1313 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1314 if (dir->etype == ET_UNIX)
1316 read_directory_unix(dir, path);
1318 if (Globals.prescan_node) {
1319 s = path;
1320 d = buffer;
1322 while(*s)
1323 *d++ = *s++;
1325 *d++ = TEXT('/');
1327 for(entry=dir->down; entry; entry=entry->next)
1328 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1329 lstrcpy(d, entry->data.cFileName);
1330 read_directory_unix(entry, buffer);
1331 SortDirectory(entry, sortOrder);
1335 else
1336 #endif
1338 read_directory_win(dir, path);
1340 if (Globals.prescan_node) {
1341 s = path;
1342 d = buffer;
1344 while(*s)
1345 *d++ = *s++;
1347 *d++ = TEXT('\\');
1349 for(entry=dir->down; entry; entry=entry->next)
1350 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1351 lstrcpy(d, entry->data.cFileName);
1352 read_directory_win(entry, buffer);
1353 SortDirectory(entry, sortOrder);
1358 SortDirectory(dir, sortOrder);
1362 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1364 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1365 static const TCHAR sSlash[] = {'/', '\0'};
1366 #endif
1367 static const TCHAR sBackslash[] = {'\\', '\0'};
1369 #ifdef _SHELL_FOLDERS
1370 if (pidl)
1372 /* read shell namespace tree */
1373 root->drive_type = DRIVE_UNKNOWN;
1374 drv[0] = '\\';
1375 drv[1] = '\0';
1376 load_string(root->volname, IDS_DESKTOP);
1377 root->fs_flags = 0;
1378 load_string(root->fs, IDS_SHELL);
1380 return read_tree_shell(root, pidl, sortOrder, hwnd);
1382 else
1383 #endif
1384 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1385 if (*path == '/')
1387 /* read unix file system tree */
1388 root->drive_type = GetDriveType(path);
1390 lstrcat(drv, sSlash);
1391 load_string(root->volname, IDS_ROOT_FS);
1392 root->fs_flags = 0;
1393 load_string(root->fs, IDS_UNIXFS);
1395 lstrcpy(root->path, sSlash);
1397 return read_tree_unix(root, path, sortOrder, hwnd);
1399 #endif
1401 /* read WIN32 file system tree */
1402 root->drive_type = GetDriveType(path);
1404 lstrcat(drv, sBackslash);
1405 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1407 lstrcpy(root->path, drv);
1409 return read_tree_win(root, path, sortOrder, hwnd);
1413 /* flags to filter different file types */
1414 enum TYPE_FILTER {
1415 TF_DIRECTORIES = 0x01,
1416 TF_PROGRAMS = 0x02,
1417 TF_DOCUMENTS = 0x04,
1418 TF_OTHERS = 0x08,
1419 TF_HIDDEN = 0x10,
1420 TF_ALL = 0x1F
1424 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1426 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1427 TCHAR dir_path[MAX_PATH];
1428 TCHAR b1[BUFFER_LEN];
1429 static const TCHAR sAsterics[] = {'*', '\0'};
1431 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1432 Root* root = &child->root;
1433 Entry* entry;
1435 memset(child, 0, sizeof(ChildWnd));
1437 child->left.treePane = TRUE;
1438 child->left.visible_cols = 0;
1440 child->right.treePane = FALSE;
1441 #ifndef _NO_EXTENSIONS
1442 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1443 #else
1444 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1445 #endif
1447 child->pos.length = sizeof(WINDOWPLACEMENT);
1448 child->pos.flags = 0;
1449 child->pos.showCmd = SW_SHOWNORMAL;
1450 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1451 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1452 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1453 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1455 child->focus_pane = 0;
1456 child->split_pos = DEFAULT_SPLIT_POS;
1457 child->sortOrder = SORT_NAME;
1458 child->header_wdths_ok = FALSE;
1460 if (path)
1462 lstrcpy(child->path, path);
1464 _tsplitpath(path, drv, dir, name, ext);
1467 lstrcpy(child->filter_pattern, sAsterics);
1468 child->filter_flags = TF_ALL;
1470 root->entry.level = 0;
1472 lstrcpy(dir_path, drv);
1473 lstrcat(dir_path, dir);
1474 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1476 #ifdef _SHELL_FOLDERS
1477 if (root->entry.etype == ET_SHELL)
1478 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1479 else
1480 #endif
1481 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1483 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1485 child->left.root = &root->entry;
1486 child->right.root = NULL;
1488 set_curdir(child, entry, 0, hwnd);
1490 return child;
1494 /* free all memory associated with a child window */
1495 static void free_child_window(ChildWnd* child)
1497 free_entries(&child->root.entry);
1498 free(child);
1502 /* get full path of specified directory entry */
1503 static void get_path(Entry* dir, PTSTR path)
1505 Entry* entry;
1506 int len = 0;
1507 int level = 0;
1509 #ifdef _SHELL_FOLDERS
1510 if (dir->etype == ET_SHELL)
1512 SFGAOF attribs;
1513 HRESULT hr = S_OK;
1515 path[0] = TEXT('\0');
1517 attribs = 0;
1519 if (dir->folder)
1520 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1522 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1523 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1525 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1528 else
1529 #endif
1531 for(entry=dir; entry; level++) {
1532 LPCTSTR name;
1533 int l;
1536 LPCTSTR s;
1537 name = entry->data.cFileName;
1538 s = name;
1540 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1541 l++;
1544 if (entry->up) {
1545 if (l > 0) {
1546 memmove(path+l+1, path, len*sizeof(TCHAR));
1547 memcpy(path+1, name, l*sizeof(TCHAR));
1548 len += l+1;
1550 #ifndef _NO_EXTENSIONS
1551 if (entry->etype == ET_UNIX)
1552 path[0] = TEXT('/');
1553 else
1554 #endif
1555 path[0] = TEXT('\\');
1558 entry = entry->up;
1559 } else {
1560 memmove(path+l, path, len*sizeof(TCHAR));
1561 memcpy(path, name, l*sizeof(TCHAR));
1562 len += l;
1563 break;
1567 if (!level) {
1568 #ifndef _NO_EXTENSIONS
1569 if (entry->etype == ET_UNIX)
1570 path[len++] = TEXT('/');
1571 else
1572 #endif
1573 path[len++] = TEXT('\\');
1576 path[len] = TEXT('\0');
1580 static windowOptions load_registry_settings(void)
1582 DWORD size;
1583 DWORD type;
1584 HKEY hKey;
1585 windowOptions opts;
1587 RegOpenKeyEx( HKEY_CURRENT_USER, registry_key,
1588 0, KEY_QUERY_VALUE, &hKey );
1590 size = sizeof(DWORD);
1592 if( RegQueryValueEx( hKey, reg_start_x, NULL, &type,
1593 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1594 opts.start_x = CW_USEDEFAULT;
1596 if( RegQueryValueEx( hKey, reg_start_y, NULL, &type,
1597 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1598 opts.start_y = CW_USEDEFAULT;
1600 if( RegQueryValueEx( hKey, reg_width, NULL, &type,
1601 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1602 opts.width = CW_USEDEFAULT;
1604 if( RegQueryValueEx( hKey, reg_height, NULL, &type,
1605 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1606 opts.height = CW_USEDEFAULT;
1608 RegCloseKey( hKey );
1610 return opts;
1613 static void save_registry_settings(void)
1615 WINDOWINFO wi;
1616 HKEY hKey;
1617 INT width, height;
1619 wi.cbSize = sizeof( WINDOWINFO );
1620 GetWindowInfo(Globals.hMainWnd, &wi);
1621 width = wi.rcWindow.right - wi.rcWindow.left;
1622 height = wi.rcWindow.bottom - wi.rcWindow.top;
1624 if ( RegOpenKeyEx( HKEY_CURRENT_USER, registry_key,
1625 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1627 /* Unable to save registry settings - try to create key */
1628 if ( RegCreateKeyEx( HKEY_CURRENT_USER, registry_key,
1629 0, NULL, REG_OPTION_NON_VOLATILE,
1630 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1632 /* FIXME: Cannot create key */
1633 return;
1636 /* Save all of the settings */
1637 RegSetValueEx( hKey, reg_start_x, 0, REG_DWORD,
1638 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1639 RegSetValueEx( hKey, reg_start_y, 0, REG_DWORD,
1640 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1641 RegSetValueEx( hKey, reg_width, 0, REG_DWORD,
1642 (LPBYTE) &width, sizeof(DWORD) );
1643 RegSetValueEx( hKey, reg_height, 0, REG_DWORD,
1644 (LPBYTE) &height, sizeof(DWORD) );
1646 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1647 RegCloseKey( hKey );
1650 static void resize_frame_rect(HWND hwnd, PRECT prect)
1652 int new_top;
1653 RECT rt;
1655 if (IsWindowVisible(Globals.htoolbar)) {
1656 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1657 GetClientRect(Globals.htoolbar, &rt);
1658 prect->top = rt.bottom+3;
1659 prect->bottom -= rt.bottom+3;
1662 if (IsWindowVisible(Globals.hdrivebar)) {
1663 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1664 GetClientRect(Globals.hdrivebar, &rt);
1665 new_top = --prect->top + rt.bottom+3;
1666 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1667 prect->top = new_top;
1668 prect->bottom -= rt.bottom+2;
1671 if (IsWindowVisible(Globals.hstatusbar)) {
1672 int parts[] = {300, 500};
1674 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1675 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1676 GetClientRect(Globals.hstatusbar, &rt);
1677 prect->bottom -= rt.bottom;
1680 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1683 static void resize_frame(HWND hwnd, int cx, int cy)
1685 RECT rect;
1687 rect.left = 0;
1688 rect.top = 0;
1689 rect.right = cx;
1690 rect.bottom = cy;
1692 resize_frame_rect(hwnd, &rect);
1695 static void resize_frame_client(HWND hwnd)
1697 RECT rect;
1699 GetClientRect(hwnd, &rect);
1701 resize_frame_rect(hwnd, &rect);
1705 static HHOOK hcbthook;
1706 static ChildWnd* newchild = NULL;
1708 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1710 if (code==HCBT_CREATEWND && newchild) {
1711 ChildWnd* child = newchild;
1712 newchild = NULL;
1714 child->hwnd = (HWND) wparam;
1715 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1718 return CallNextHookEx(hcbthook, code, wparam, lparam);
1721 static HWND create_child_window(ChildWnd* child)
1723 MDICREATESTRUCT mcs;
1724 int idx;
1726 mcs.szClass = sWINEFILETREE;
1727 mcs.szTitle = (LPTSTR)child->path;
1728 mcs.hOwner = Globals.hInstance;
1729 mcs.x = child->pos.rcNormalPosition.left;
1730 mcs.y = child->pos.rcNormalPosition.top;
1731 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1732 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1733 mcs.style = 0;
1734 mcs.lParam = 0;
1736 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1738 newchild = child;
1739 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1740 if (!child->hwnd) {
1741 UnhookWindowsHookEx(hcbthook);
1742 return 0;
1745 UnhookWindowsHookEx(hcbthook);
1747 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1748 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1750 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
1751 ListBox_SetCurSel(child->left.hwnd, idx);
1753 return child->hwnd;
1757 struct ExecuteDialog {
1758 TCHAR cmd[MAX_PATH];
1759 int cmdshow;
1762 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1764 static struct ExecuteDialog* dlg;
1766 switch(nmsg) {
1767 case WM_INITDIALOG:
1768 dlg = (struct ExecuteDialog*) lparam;
1769 return 1;
1771 case WM_COMMAND: {
1772 int id = (int)wparam;
1774 if (id == IDOK) {
1775 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1776 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1777 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1778 EndDialog(hwnd, id);
1779 } else if (id == IDCANCEL)
1780 EndDialog(hwnd, id);
1782 return 1;}
1785 return 0;
1789 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1791 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1793 switch(nmsg) {
1794 case WM_INITDIALOG:
1795 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1796 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1797 return 1;
1799 case WM_COMMAND: {
1800 int id = (int)wparam;
1802 switch(id) {
1803 case IDOK: {
1804 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1805 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1806 EndDialog(hwnd, id);
1807 break;}
1809 case IDCANCEL:
1810 EndDialog(hwnd, id);
1811 break;
1813 case 254:
1814 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1815 break;
1818 return 1;
1822 return 0;
1826 struct FilterDialog {
1827 TCHAR pattern[MAX_PATH];
1828 int flags;
1831 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1833 static struct FilterDialog* dlg;
1835 switch(nmsg) {
1836 case WM_INITDIALOG:
1837 dlg = (struct FilterDialog*) lparam;
1838 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1839 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES), (dlg->flags&TF_DIRECTORIES? BST_CHECKED: BST_UNCHECKED));
1840 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS), dlg->flags&TF_PROGRAMS? BST_CHECKED: BST_UNCHECKED);
1841 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS), dlg->flags&TF_DOCUMENTS? BST_CHECKED: BST_UNCHECKED);
1842 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS), dlg->flags&TF_OTHERS? BST_CHECKED: BST_UNCHECKED);
1843 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN), dlg->flags&TF_HIDDEN? BST_CHECKED: BST_UNCHECKED);
1844 return 1;
1846 case WM_COMMAND: {
1847 int id = (int)wparam;
1849 if (id == IDOK) {
1850 int flags = 0;
1852 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1854 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES))&BST_CHECKED? TF_DIRECTORIES: 0;
1855 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS))&BST_CHECKED? TF_PROGRAMS: 0;
1856 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS))&BST_CHECKED? TF_DOCUMENTS: 0;
1857 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS))&BST_CHECKED? TF_OTHERS: 0;
1858 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN))&BST_CHECKED? TF_HIDDEN: 0;
1860 dlg->flags = flags;
1862 EndDialog(hwnd, id);
1863 } else if (id == IDCANCEL)
1864 EndDialog(hwnd, id);
1866 return 1;}
1869 return 0;
1873 struct PropertiesDialog {
1874 TCHAR path[MAX_PATH];
1875 Entry entry;
1876 void* pVersionData;
1879 /* Structure used to store enumerated languages and code pages. */
1880 struct LANGANDCODEPAGE {
1881 WORD wLanguage;
1882 WORD wCodePage;
1883 } *lpTranslate;
1885 static LPCSTR InfoStrings[] = {
1886 "Comments",
1887 "CompanyName",
1888 "FileDescription",
1889 "FileVersion",
1890 "InternalName",
1891 "LegalCopyright",
1892 "LegalTrademarks",
1893 "OriginalFilename",
1894 "PrivateBuild",
1895 "ProductName",
1896 "ProductVersion",
1897 "SpecialBuild",
1898 NULL
1901 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1903 int idx = ListBox_GetCurSel(hlbox);
1905 if (idx != LB_ERR) {
1906 LPCTSTR pValue = (LPCTSTR) ListBox_GetItemData(hlbox, idx);
1908 if (pValue)
1909 SetWindowText(hedit, pValue);
1913 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1915 static TCHAR sBackSlash[] = {'\\','\0'};
1916 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'};
1917 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1918 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1919 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1921 if (dwVersionDataLen) {
1922 dlg->pVersionData = malloc(dwVersionDataLen);
1924 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1925 LPVOID pVal;
1926 UINT nValLen;
1928 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1929 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1930 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1931 char buffer[BUFFER_LEN];
1933 sprintf(buffer, "%d.%d.%d.%d",
1934 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1935 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1937 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1941 /* Read the list of languages and code pages. */
1942 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1943 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1944 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1946 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1948 /* Read the file description for each language and code page. */
1949 for(; pTranslate<pEnd; ++pTranslate) {
1950 LPCSTR* p;
1952 for(p=InfoStrings; *p; ++p) {
1953 TCHAR subblock[200];
1954 #ifdef UNICODE
1955 TCHAR infoStr[100];
1956 #endif
1957 LPCTSTR pTxt;
1958 UINT nValLen;
1960 LPCSTR pInfoString = *p;
1961 #ifdef UNICODE
1962 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1963 #else
1964 #define infoStr pInfoString
1965 #endif
1966 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1968 /* Retrieve file description for language and code page */
1969 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1970 int idx = ListBox_AddString(hlbox, infoStr);
1971 ListBox_SetItemData(hlbox, idx, pTxt);
1976 ListBox_SetCurSel(hlbox, 0);
1978 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1984 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1986 static struct PropertiesDialog* dlg;
1988 switch(nmsg) {
1989 case WM_INITDIALOG: {
1990 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1991 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1992 LPWIN32_FIND_DATA pWFD;
1993 ULONGLONG size;
1995 dlg = (struct PropertiesDialog*) lparam;
1996 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
1998 GetWindowText(hwnd, b1, MAX_PATH);
1999 wsprintf(b2, b1, pWFD->cFileName);
2000 SetWindowText(hwnd, b2);
2002 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
2003 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
2005 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
2006 _stprintf(b1, sLongNumFmt, size);
2007 wsprintf(b2, sByteFmt, b1);
2008 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
2010 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
2011 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
2013 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_READONLY), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY? BST_CHECKED: BST_UNCHECKED));
2014 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_ARCHIVE), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE? BST_CHECKED: BST_UNCHECKED));
2015 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_COMPRESSED), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED? BST_CHECKED: BST_UNCHECKED));
2016 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_HIDDEN), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN? BST_CHECKED: BST_UNCHECKED));
2017 Button_SetCheck(GetDlgItem(hwnd,IDC_CHECK_SYSTEM), (pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM? BST_CHECKED: BST_UNCHECKED));
2019 CheckForFileInfo(dlg, hwnd, dlg->path);
2020 return 1;}
2022 case WM_COMMAND: {
2023 int id = (int)wparam;
2025 switch(HIWORD(wparam)) {
2026 case LBN_SELCHANGE: {
2027 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2028 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2029 break;
2032 case BN_CLICKED:
2033 if (id==IDOK || id==IDCANCEL)
2034 EndDialog(hwnd, id);
2037 return 1;}
2039 case WM_NCDESTROY:
2040 free(dlg->pVersionData);
2041 dlg->pVersionData = NULL;
2042 break;
2045 return 0;
2048 static void show_properties_dlg(Entry* entry, HWND hwnd)
2050 struct PropertiesDialog dlg;
2052 memset(&dlg, 0, sizeof(struct PropertiesDialog));
2053 get_path(entry, dlg.path);
2054 memcpy(&dlg.entry, entry, sizeof(Entry));
2056 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
2060 #ifndef _NO_EXTENSIONS
2062 static struct FullScreenParameters {
2063 BOOL mode;
2064 RECT orgPos;
2065 BOOL wasZoomed;
2066 } g_fullscreen = {
2067 FALSE, /* mode */
2068 {0, 0, 0, 0},
2069 FALSE
2072 static void frame_get_clientspace(HWND hwnd, PRECT prect)
2074 RECT rt;
2076 if (!IsIconic(hwnd))
2077 GetClientRect(hwnd, prect);
2078 else {
2079 WINDOWPLACEMENT wp;
2081 GetWindowPlacement(hwnd, &wp);
2083 prect->left = prect->top = 0;
2084 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
2085 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
2086 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
2087 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
2088 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2091 if (IsWindowVisible(Globals.htoolbar)) {
2092 GetClientRect(Globals.htoolbar, &rt);
2093 prect->top += rt.bottom+2;
2096 if (IsWindowVisible(Globals.hdrivebar)) {
2097 GetClientRect(Globals.hdrivebar, &rt);
2098 prect->top += rt.bottom+2;
2101 if (IsWindowVisible(Globals.hstatusbar)) {
2102 GetClientRect(Globals.hstatusbar, &rt);
2103 prect->bottom -= rt.bottom;
2107 static BOOL toggle_fullscreen(HWND hwnd)
2109 RECT rt;
2111 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2112 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2113 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2115 Frame_CalcFrameClient(hwnd, &rt);
2116 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2117 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2119 rt.left = g_fullscreen.orgPos.left-rt.left;
2120 rt.top = g_fullscreen.orgPos.top-rt.top;
2121 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2122 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2124 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2125 } else {
2126 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2127 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2128 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2130 if (g_fullscreen.wasZoomed)
2131 ShowWindow(hwnd, WS_MAXIMIZE);
2134 return g_fullscreen.mode;
2137 static void fullscreen_move(HWND hwnd)
2139 RECT rt, pos;
2140 GetWindowRect(hwnd, &pos);
2142 Frame_CalcFrameClient(hwnd, &rt);
2143 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2144 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2146 rt.left = pos.left-rt.left;
2147 rt.top = pos.top-rt.top;
2148 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2149 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2151 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2154 #endif
2157 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2159 BOOL vis = IsWindowVisible(hchild);
2161 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2163 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2165 #ifndef _NO_EXTENSIONS
2166 if (g_fullscreen.mode)
2167 fullscreen_move(hwnd);
2168 #endif
2170 resize_frame_client(hwnd);
2173 static BOOL activate_drive_window(LPCTSTR path)
2175 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2176 HWND child_wnd;
2178 _tsplitpath(path, drv1, 0, 0, 0);
2180 /* search for a already open window for the same drive */
2181 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2182 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2184 if (child) {
2185 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2187 if (!lstrcmpi(drv2, drv1)) {
2188 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2190 if (IsMinimized(child_wnd))
2191 ShowWindow(child_wnd, SW_SHOWNORMAL);
2193 return TRUE;
2198 return FALSE;
2201 static BOOL activate_fs_window(LPCTSTR filesys)
2203 HWND child_wnd;
2205 /* search for a already open window of the given file system name */
2206 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2207 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2209 if (child) {
2210 if (!lstrcmpi(child->root.fs, filesys)) {
2211 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2213 if (IsMinimized(child_wnd))
2214 ShowWindow(child_wnd, SW_SHOWNORMAL);
2216 return TRUE;
2221 return FALSE;
2224 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2226 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2228 switch(nmsg) {
2229 case WM_CLOSE:
2230 if (Globals.saveSettings == TRUE)
2231 save_registry_settings();
2233 DestroyWindow(hwnd);
2235 /* clear handle variables */
2236 Globals.hMenuFrame = 0;
2237 Globals.hMenuView = 0;
2238 Globals.hMenuOptions = 0;
2239 Globals.hMainWnd = 0;
2240 Globals.hmdiclient = 0;
2241 Globals.hdrivebar = 0;
2242 break;
2244 case WM_DESTROY:
2245 PostQuitMessage(0);
2246 break;
2248 case WM_INITMENUPOPUP: {
2249 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2251 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2252 return 0;
2253 break;}
2255 case WM_COMMAND: {
2256 UINT cmd = LOWORD(wparam);
2257 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2259 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2260 break;
2262 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2263 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2264 ChildWnd* child;
2265 LPCTSTR root = Globals.drives;
2266 int i;
2268 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2269 while(*root)
2270 root++;
2272 if (activate_drive_window(root))
2273 return 0;
2275 _tsplitpath(root, drv, 0, 0, 0);
2277 if (!SetCurrentDirectory(drv)) {
2278 display_error(hwnd, GetLastError());
2279 return 0;
2282 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2283 child = alloc_child_window(path, NULL, hwnd);
2285 if (!create_child_window(child))
2286 free(child);
2287 } else switch(cmd) {
2288 case ID_FILE_EXIT:
2289 SendMessage(hwnd, WM_CLOSE, 0, 0);
2290 break;
2292 case ID_WINDOW_NEW: {
2293 TCHAR path[MAX_PATH];
2294 ChildWnd* child;
2296 GetCurrentDirectory(MAX_PATH, path);
2297 child = alloc_child_window(path, NULL, hwnd);
2299 if (!create_child_window(child))
2300 free(child);
2301 break;}
2303 case ID_REFRESH:
2304 refresh_drives();
2305 break;
2307 case ID_WINDOW_CASCADE:
2308 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2309 break;
2311 case ID_WINDOW_TILE_HORZ:
2312 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2313 break;
2315 case ID_WINDOW_TILE_VERT:
2316 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2317 break;
2319 case ID_WINDOW_ARRANGE:
2320 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2321 break;
2323 case ID_SELECT_FONT: {
2324 TCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
2325 CHOOSEFONT chFont;
2326 LOGFONT lFont;
2328 HDC hdc = GetDC(hwnd);
2329 chFont.lStructSize = sizeof(CHOOSEFONT);
2330 chFont.hwndOwner = hwnd;
2331 chFont.hDC = NULL;
2332 chFont.lpLogFont = &lFont;
2333 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
2334 chFont.rgbColors = RGB(0,0,0);
2335 chFont.lCustData = 0;
2336 chFont.lpfnHook = NULL;
2337 chFont.lpTemplateName = NULL;
2338 chFont.hInstance = Globals.hInstance;
2339 chFont.lpszStyle = NULL;
2340 chFont.nFontType = SIMULATED_FONTTYPE;
2341 chFont.nSizeMin = 0;
2342 chFont.nSizeMax = 24;
2344 if (ChooseFont(&chFont)) {
2345 HWND childWnd;
2346 HFONT hFontOld;
2348 DeleteObject(Globals.hfont);
2349 Globals.hfont = CreateFontIndirect(&lFont);
2350 hFontOld = SelectFont(hdc, Globals.hfont);
2351 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2353 /* change font in all open child windows */
2354 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
2355 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(childWnd, GWLP_USERDATA);
2356 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
2357 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
2358 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2359 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2360 InvalidateRect(child->left.hwnd, NULL, TRUE);
2361 InvalidateRect(child->right.hwnd, NULL, TRUE);
2364 SelectFont(hdc, hFontOld);
2366 else if (CommDlgExtendedError()) {
2367 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
2368 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
2369 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
2372 ReleaseDC(hwnd, hdc);
2373 break;
2376 case ID_VIEW_TOOL_BAR:
2377 toggle_child(hwnd, cmd, Globals.htoolbar);
2378 break;
2380 case ID_VIEW_DRIVE_BAR:
2381 toggle_child(hwnd, cmd, Globals.hdrivebar);
2382 break;
2384 case ID_VIEW_STATUSBAR:
2385 toggle_child(hwnd, cmd, Globals.hstatusbar);
2386 break;
2388 case ID_VIEW_SAVESETTINGS:
2389 Globals.saveSettings = !Globals.saveSettings;
2390 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2391 Globals.saveSettings == TRUE ? MF_CHECKED : MF_UNCHECKED );
2392 break;
2394 case ID_EXECUTE: {
2395 struct ExecuteDialog dlg;
2397 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2399 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2400 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2402 if ((int)hinst <= 32)
2403 display_error(hwnd, GetLastError());
2405 break;}
2407 case ID_CONNECT_NETWORK_DRIVE: {
2408 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2409 if (ret == NO_ERROR)
2410 refresh_drives();
2411 else if (ret != (DWORD)-1) {
2412 if (ret == ERROR_EXTENDED_ERROR)
2413 display_network_error(hwnd);
2414 else
2415 display_error(hwnd, ret);
2417 break;}
2419 case ID_DISCONNECT_NETWORK_DRIVE: {
2420 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2421 if (ret == NO_ERROR)
2422 refresh_drives();
2423 else if (ret != (DWORD)-1) {
2424 if (ret == ERROR_EXTENDED_ERROR)
2425 display_network_error(hwnd);
2426 else
2427 display_error(hwnd, ret);
2429 break;}
2431 case ID_FORMAT_DISK: {
2432 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2433 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2434 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2435 SetErrorMode(sem_org); /* Put it back the way it was. */
2436 break;}
2438 case ID_HELP:
2439 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2440 break;
2442 #ifndef _NO_EXTENSIONS
2443 case ID_VIEW_FULLSCREEN:
2444 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2445 break;
2447 #ifdef __WINE__
2448 case ID_DRIVE_UNIX_FS: {
2449 TCHAR path[MAX_PATH];
2450 #ifdef UNICODE
2451 char cpath[MAX_PATH];
2452 #endif
2453 ChildWnd* child;
2455 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2456 break;
2458 #ifdef UNICODE
2459 getcwd(cpath, MAX_PATH);
2460 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2461 #else
2462 getcwd(path, MAX_PATH);
2463 #endif
2464 child = alloc_child_window(path, NULL, hwnd);
2466 if (!create_child_window(child))
2467 free(child);
2468 break;}
2469 #endif
2470 #ifdef _SHELL_FOLDERS
2471 case ID_DRIVE_SHELL_NS: {
2472 TCHAR path[MAX_PATH];
2473 ChildWnd* child;
2475 if (activate_fs_window(RS(b1,IDS_SHELL)))
2476 break;
2478 GetCurrentDirectory(MAX_PATH, path);
2479 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2481 if (!create_child_window(child))
2482 free(child);
2483 break;}
2484 #endif
2485 #endif
2487 /*TODO: There are even more menu items! */
2489 #ifndef _NO_EXTENSIONS
2490 #ifdef __WINE__
2491 case ID_LICENSE:
2492 WineLicense(Globals.hMainWnd);
2493 break;
2495 case ID_NO_WARRANTY:
2496 WineWarranty(Globals.hMainWnd);
2497 break;
2499 case ID_ABOUT_WINE:
2500 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2501 break;
2502 #endif
2504 case ID_ABOUT:
2505 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2506 break;
2507 #endif /* _NO_EXTENSIONS */
2509 default:
2510 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2511 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2512 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2513 (cmd<SC_SIZE || cmd>SC_RESTORE))
2514 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2516 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2518 break;}
2520 case WM_SIZE:
2521 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2522 break; /* do not pass message to DefFrameProc */
2524 #ifndef _NO_EXTENSIONS
2525 case WM_GETMINMAXINFO: {
2526 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2528 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2529 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2530 break;}
2532 case FRM_CALC_CLIENT:
2533 frame_get_clientspace(hwnd, (PRECT)lparam);
2534 return TRUE;
2535 #endif /* _NO_EXTENSIONS */
2537 default:
2538 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2541 return 0;
2545 static TCHAR g_pos_names[COLUMNS][20] = {
2546 {'\0'} /* symbol */
2549 static const int g_pos_align[] = {
2551 HDF_LEFT, /* Name */
2552 HDF_RIGHT, /* Size */
2553 HDF_LEFT, /* CDate */
2554 #ifndef _NO_EXTENSIONS
2555 HDF_LEFT, /* ADate */
2556 HDF_LEFT, /* MDate */
2557 HDF_LEFT, /* Index */
2558 HDF_CENTER, /* Links */
2559 #endif
2560 HDF_CENTER, /* Attributes */
2561 #ifndef _NO_EXTENSIONS
2562 HDF_LEFT /* Security */
2563 #endif
2566 static void resize_tree(ChildWnd* child, int cx, int cy)
2568 HDWP hdwp = BeginDeferWindowPos(4);
2569 RECT rt;
2571 rt.left = 0;
2572 rt.top = 0;
2573 rt.right = cx;
2574 rt.bottom = cy;
2576 cx = child->split_pos + SPLIT_WIDTH/2;
2578 #ifndef _NO_EXTENSIONS
2580 WINDOWPOS wp;
2581 HD_LAYOUT hdl;
2583 hdl.prc = &rt;
2584 hdl.pwpos = &wp;
2586 Header_Layout(child->left.hwndHeader, &hdl);
2588 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2589 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2590 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2591 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2593 #endif /* _NO_EXTENSIONS */
2595 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);
2596 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2598 EndDeferWindowPos(hdwp);
2602 #ifndef _NO_EXTENSIONS
2604 static HWND create_header(HWND parent, Pane* pane, int id)
2606 HD_ITEM hdi;
2607 int idx;
2609 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2610 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2611 if (!hwnd)
2612 return 0;
2614 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2616 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2618 for(idx=0; idx<COLUMNS; idx++) {
2619 hdi.pszText = g_pos_names[idx];
2620 hdi.fmt = HDF_STRING | g_pos_align[idx];
2621 hdi.cxy = pane->widths[idx];
2622 Header_InsertItem(hwnd, idx, &hdi);
2625 return hwnd;
2628 #endif /* _NO_EXTENSIONS */
2631 static void init_output(HWND hwnd)
2633 static const TCHAR s1000[] = {'1','0','0','0','\0'};
2635 TCHAR b[16];
2636 HFONT old_font;
2637 HDC hdc = GetDC(hwnd);
2639 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2640 Globals.num_sep = b[1];
2641 else
2642 Globals.num_sep = TEXT('.');
2644 old_font = SelectFont(hdc, Globals.hfont);
2645 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2646 SelectFont(hdc, old_font);
2647 ReleaseDC(hwnd, hdc);
2650 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2653 /* calculate preferred width for all visible columns */
2655 static BOOL calc_widths(Pane* pane, BOOL anyway)
2657 int col, x, cx, spc=3*Globals.spaceSize.cx;
2658 int entries = ListBox_GetCount(pane->hwnd);
2659 int orgWidths[COLUMNS];
2660 int orgPositions[COLUMNS+1];
2661 HFONT hfontOld;
2662 HDC hdc;
2663 int cnt;
2665 if (!anyway) {
2666 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2667 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2670 for(col=0; col<COLUMNS; col++)
2671 pane->widths[col] = 0;
2673 hdc = GetDC(pane->hwnd);
2674 hfontOld = SelectFont(hdc, Globals.hfont);
2676 for(cnt=0; cnt<entries; cnt++) {
2677 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2679 DRAWITEMSTRUCT dis;
2681 dis.CtlType = 0;
2682 dis.CtlID = 0;
2683 dis.itemID = 0;
2684 dis.itemAction = 0;
2685 dis.itemState = 0;
2686 dis.hwndItem = pane->hwnd;
2687 dis.hDC = hdc;
2688 dis.rcItem.left = 0;
2689 dis.rcItem.top = 0;
2690 dis.rcItem.right = 0;
2691 dis.rcItem.bottom = 0;
2692 /*dis.itemData = 0; */
2694 draw_item(pane, &dis, entry, COLUMNS);
2697 SelectObject(hdc, hfontOld);
2698 ReleaseDC(pane->hwnd, hdc);
2700 x = 0;
2701 for(col=0; col<COLUMNS; col++) {
2702 pane->positions[col] = x;
2703 cx = pane->widths[col];
2705 if (cx) {
2706 cx += spc;
2708 if (cx < IMAGE_WIDTH)
2709 cx = IMAGE_WIDTH;
2711 pane->widths[col] = cx;
2714 x += cx;
2717 pane->positions[COLUMNS] = x;
2719 ListBox_SetHorizontalExtent(pane->hwnd, x);
2721 /* no change? */
2722 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2723 return FALSE;
2725 /* don't move, if only collapsing an entry */
2726 if (!anyway && pane->widths[0]<orgWidths[0] &&
2727 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2728 pane->widths[0] = orgWidths[0];
2729 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2731 return FALSE;
2734 InvalidateRect(pane->hwnd, 0, TRUE);
2736 return TRUE;
2740 /* calculate one preferred column width */
2742 static void calc_single_width(Pane* pane, int col)
2744 HFONT hfontOld;
2745 int x, cx;
2746 int entries = ListBox_GetCount(pane->hwnd);
2747 int cnt;
2748 HDC hdc;
2750 pane->widths[col] = 0;
2752 hdc = GetDC(pane->hwnd);
2753 hfontOld = SelectFont(hdc, Globals.hfont);
2755 for(cnt=0; cnt<entries; cnt++) {
2756 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2757 DRAWITEMSTRUCT dis;
2759 dis.CtlType = 0;
2760 dis.CtlID = 0;
2761 dis.itemID = 0;
2762 dis.itemAction = 0;
2763 dis.itemState = 0;
2764 dis.hwndItem = pane->hwnd;
2765 dis.hDC = hdc;
2766 dis.rcItem.left = 0;
2767 dis.rcItem.top = 0;
2768 dis.rcItem.right = 0;
2769 dis.rcItem.bottom = 0;
2770 /*dis.itemData = 0; */
2772 draw_item(pane, &dis, entry, col);
2775 SelectObject(hdc, hfontOld);
2776 ReleaseDC(pane->hwnd, hdc);
2778 cx = pane->widths[col];
2780 if (cx) {
2781 cx += 3*Globals.spaceSize.cx;
2783 if (cx < IMAGE_WIDTH)
2784 cx = IMAGE_WIDTH;
2787 pane->widths[col] = cx;
2789 x = pane->positions[col] + cx;
2791 for(; col<COLUMNS; ) {
2792 pane->positions[++col] = x;
2793 x += pane->widths[col];
2796 ListBox_SetHorizontalExtent(pane->hwnd, x);
2800 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2802 for( ; *str&&*pattern; str++,pattern++) {
2803 if (*pattern == '*') {
2804 do pattern++;
2805 while(*pattern == '*');
2807 if (!*pattern)
2808 return TRUE;
2810 for(; *str; str++)
2811 if (*str==*pattern && pattern_match(str, pattern))
2812 return TRUE;
2814 return FALSE;
2816 else if (*str!=*pattern && *pattern!='?')
2817 return FALSE;
2820 if (*str || *pattern)
2821 if (*pattern!='*' || pattern[1]!='\0')
2822 return FALSE;
2824 return TRUE;
2827 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2829 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2831 lstrcpy(b1, str);
2832 lstrcpy(b2, pattern);
2833 CharUpper(b1);
2834 CharUpper(b2);
2836 return pattern_match(b1, b2);
2840 enum FILE_TYPE {
2841 FT_OTHER = 0,
2842 FT_EXECUTABLE = 1,
2843 FT_DOCUMENT = 2
2846 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2849 /* insert listbox entries after index idx */
2851 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2853 Entry* entry = dir;
2855 if (!entry)
2856 return idx;
2858 ShowWindow(pane->hwnd, SW_HIDE);
2860 for(; entry; entry=entry->next) {
2861 #ifndef _LEFT_FILES
2862 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2863 continue;
2864 #endif
2866 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2867 /* don't display entries "." and ".." in the left pane */
2868 if (pane->treePane && entry->data.cFileName[0]==TEXT('.'))
2869 if (
2870 #ifndef _NO_EXTENSIONS
2871 entry->data.cFileName[1]==TEXT('\0') ||
2872 #endif
2873 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2874 continue;
2876 /* filter directories in right pane */
2877 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2878 continue;
2881 /* filter using the file name pattern */
2882 if (pattern)
2883 if (!pattern_imatch(entry->data.cFileName, pattern))
2884 continue;
2886 /* filter system and hidden files */
2887 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2888 continue;
2890 /* filter looking at the file type */
2891 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2892 switch(get_file_type(entry->data.cFileName)) {
2893 case FT_EXECUTABLE:
2894 if (!(filter_flags & TF_PROGRAMS))
2895 continue;
2896 break;
2898 case FT_DOCUMENT:
2899 if (!(filter_flags & TF_DOCUMENTS))
2900 continue;
2901 break;
2903 default: /* TF_OTHERS */
2904 if (!(filter_flags & TF_OTHERS))
2905 continue;
2908 if (idx != -1)
2909 idx++;
2911 ListBox_InsertItemData(pane->hwnd, idx, entry);
2913 if (pane->treePane && entry->expanded)
2914 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2917 ShowWindow(pane->hwnd, SW_SHOW);
2919 return idx;
2923 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2925 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2926 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2927 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2929 float fBytes = (float)bytes;
2931 if (bytes >= 1073741824) /* 1 GB */
2932 wsprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2933 else if (bytes >= 1048576) /* 1 MB */
2934 wsprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2935 else if (bytes >= 1024) /* 1 kB */
2936 wsprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2937 else
2938 _stprintf(buffer, sLongNumFmt, bytes);
2941 static void set_space_status(void)
2943 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2944 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2946 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2947 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2948 format_bytes(b2, ulTotalBytes.QuadPart);
2949 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2950 } else
2951 lstrcpy(buffer, sQMarks);
2953 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2957 static WNDPROC g_orgTreeWndProc;
2959 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2961 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2963 static int s_init = 0;
2964 Entry* entry = pane->root;
2966 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2967 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2968 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2970 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2971 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2973 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2975 /* insert entries into listbox */
2976 if (entry)
2977 insert_entries(pane, entry, pattern, filter_flags, -1);
2979 /* calculate column widths */
2980 if (!s_init) {
2981 s_init = 1;
2982 init_output(pane->hwnd);
2985 calc_widths(pane, TRUE);
2987 #ifndef _NO_EXTENSIONS
2988 pane->hwndHeader = create_header(parent, pane, id_header);
2989 #endif
2993 static void InitChildWindow(ChildWnd* child)
2995 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2996 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
3000 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
3002 SYSTEMTIME systime;
3003 FILETIME lft;
3004 int len = 0;
3006 *buffer = TEXT('\0');
3008 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
3009 return;
3011 if (!FileTimeToLocalFileTime(ft, &lft))
3012 {err: lstrcpy(buffer,sQMarks); return;}
3014 if (!FileTimeToSystemTime(&lft, &systime))
3015 goto err;
3017 if (visible_cols & COL_DATE) {
3018 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
3019 if (!len)
3020 goto err;
3023 if (visible_cols & COL_TIME) {
3024 if (len)
3025 buffer[len-1] = ' ';
3027 buffer[len++] = ' ';
3029 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
3030 buffer[len] = TEXT('\0');
3035 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3037 RECT rt = {0, 0, 0, 0};
3039 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3041 if (rt.right > pane->widths[col])
3042 pane->widths[col] = rt.right;
3045 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3047 RECT rt = {0, 0, 0, 0};
3049 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3050 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3052 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3053 /*FIXME rt (0,0) ??? */
3055 if (rt.right > pane->widths[col])
3056 pane->widths[col] = rt.right;
3060 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
3062 int x = dis->rcItem.left;
3063 RECT rt;
3065 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3066 rt.top = dis->rcItem.top;
3067 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3068 rt.bottom = dis->rcItem.bottom;
3070 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
3073 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3075 int x = dis->rcItem.left;
3076 RECT rt;
3078 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3079 rt.top = dis->rcItem.top;
3080 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3081 rt.bottom = dis->rcItem.bottom;
3083 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3084 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3086 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3089 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3091 int x = dis->rcItem.left;
3092 RECT rt;
3093 LPCTSTR s = str;
3094 TCHAR b[128];
3095 LPTSTR d = b;
3096 int pos;
3098 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3099 rt.top = dis->rcItem.top;
3100 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3101 rt.bottom = dis->rcItem.bottom;
3103 if (*s)
3104 *d++ = *s++;
3106 /* insert number separator characters */
3107 pos = lstrlen(s) % 3;
3109 while(*s)
3110 if (pos--)
3111 *d++ = *s++;
3112 else {
3113 *d++ = Globals.num_sep;
3114 pos = 3;
3117 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3121 static BOOL is_exe_file(LPCTSTR ext)
3123 static const TCHAR executable_extensions[][4] = {
3124 {'C','O','M','\0'},
3125 {'E','X','E','\0'},
3126 {'B','A','T','\0'},
3127 {'C','M','D','\0'},
3128 #ifndef _NO_EXTENSIONS
3129 {'C','M','M','\0'},
3130 {'B','T','M','\0'},
3131 {'A','W','K','\0'},
3132 #endif /* _NO_EXTENSIONS */
3133 {'\0'}
3136 TCHAR ext_buffer[_MAX_EXT];
3137 const TCHAR (*p)[4];
3138 LPCTSTR s;
3139 LPTSTR d;
3141 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3142 d++;
3144 for(p=executable_extensions; (*p)[0]; p++)
3145 if (!lstrcmpi(ext_buffer, *p))
3146 return TRUE;
3148 return FALSE;
3151 static BOOL is_registered_type(LPCTSTR ext)
3153 /* check if there exists a classname for this file extension in the registry */
3154 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3155 return TRUE;
3157 return FALSE;
3160 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3162 LPCTSTR ext = _tcsrchr(filename, '.');
3163 if (!ext)
3164 ext = sEmpty;
3166 if (is_exe_file(ext))
3167 return FT_EXECUTABLE;
3168 else if (is_registered_type(ext))
3169 return FT_DOCUMENT;
3170 else
3171 return FT_OTHER;
3175 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3177 TCHAR buffer[BUFFER_LEN];
3178 DWORD attrs;
3179 int visible_cols = pane->visible_cols;
3180 COLORREF bkcolor, textcolor;
3181 RECT focusRect = dis->rcItem;
3182 HBRUSH hbrush;
3183 enum IMAGE img;
3184 int img_pos, cx;
3185 int col = 0;
3187 if (entry) {
3188 attrs = entry->data.dwFileAttributes;
3190 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3191 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
3192 && entry->data.cFileName[2]==TEXT('\0'))
3193 img = IMG_FOLDER_UP;
3194 #ifndef _NO_EXTENSIONS
3195 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
3196 img = IMG_FOLDER_CUR;
3197 #endif
3198 else if (
3199 #ifdef _NO_EXTENSIONS
3200 entry->expanded ||
3201 #endif
3202 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3203 img = IMG_OPEN_FOLDER;
3204 else
3205 img = IMG_FOLDER;
3206 } else {
3207 switch(get_file_type(entry->data.cFileName)) {
3208 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3209 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3210 default: img = IMG_FILE;
3213 } else {
3214 attrs = 0;
3215 img = IMG_NONE;
3218 if (pane->treePane) {
3219 if (entry) {
3220 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3222 if (calcWidthCol == -1) {
3223 int x;
3224 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3225 Entry* up;
3226 RECT rt_clip;
3227 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3228 HRGN hrgn;
3230 rt_clip.left = dis->rcItem.left;
3231 rt_clip.top = dis->rcItem.top;
3232 rt_clip.right = dis->rcItem.left+pane->widths[col];
3233 rt_clip.bottom = dis->rcItem.bottom;
3235 hrgn = CreateRectRgnIndirect(&rt_clip);
3237 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3238 DeleteObject(hrgn_org);
3239 hrgn_org = 0;
3242 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3243 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3244 DeleteObject(hrgn);
3246 if ((up=entry->up) != NULL) {
3247 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3248 LineTo(dis->hDC, img_pos-2, y);
3250 x = img_pos - IMAGE_WIDTH/2;
3252 do {
3253 x -= IMAGE_WIDTH+TREE_LINE_DX;
3255 if (up->next
3256 #ifndef _LEFT_FILES
3257 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3258 #endif
3260 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3261 LineTo(dis->hDC, x, dis->rcItem.bottom);
3263 } while((up=up->up) != NULL);
3266 x = img_pos - IMAGE_WIDTH/2;
3268 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3269 LineTo(dis->hDC, x, y);
3271 if (entry->next
3272 #ifndef _LEFT_FILES
3273 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3274 #endif
3276 LineTo(dis->hDC, x, dis->rcItem.bottom);
3278 SelectClipRgn(dis->hDC, hrgn_org);
3279 if (hrgn_org) DeleteObject(hrgn_org);
3280 /* SelectObject(dis->hDC, holdPen); */
3281 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3282 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3284 if (right > pane->widths[col])
3285 pane->widths[col] = right;
3287 } else {
3288 img_pos = dis->rcItem.left;
3290 } else {
3291 img_pos = dis->rcItem.left;
3293 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3294 pane->widths[col] = IMAGE_WIDTH;
3297 if (calcWidthCol == -1) {
3298 focusRect.left = img_pos -2;
3300 #ifdef _NO_EXTENSIONS
3301 if (pane->treePane && entry) {
3302 RECT rt = {0};
3304 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3306 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3308 #else
3310 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3311 textcolor = COLOR_COMPRESSED;
3312 else
3313 #endif /* _NO_EXTENSIONS */
3314 textcolor = RGB(0,0,0);
3316 if (dis->itemState & ODS_FOCUS) {
3317 textcolor = RGB(255,255,255);
3318 bkcolor = COLOR_SELECTION;
3319 } else {
3320 bkcolor = RGB(255,255,255);
3323 hbrush = CreateSolidBrush(bkcolor);
3324 FillRect(dis->hDC, &focusRect, hbrush);
3325 DeleteObject(hbrush);
3327 SetBkMode(dis->hDC, TRANSPARENT);
3328 SetTextColor(dis->hDC, textcolor);
3330 cx = pane->widths[col];
3332 if (cx && img!=IMG_NONE) {
3333 if (cx > IMAGE_WIDTH)
3334 cx = IMAGE_WIDTH;
3336 #ifdef _SHELL_FOLDERS
3337 if (entry->hicon && entry->hicon!=(HICON)-1)
3338 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3339 else
3340 #endif
3341 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3342 img_pos, dis->rcItem.top, cx,
3343 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3347 if (!entry)
3348 return;
3350 #ifdef _NO_EXTENSIONS
3351 if (img >= IMG_FOLDER_UP)
3352 return;
3353 #endif
3355 col++;
3357 /* ouput file name */
3358 if (calcWidthCol == -1)
3359 output_text(pane, dis, col, entry->data.cFileName, 0);
3360 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3361 calc_width(pane, dis, col, entry->data.cFileName);
3363 col++;
3365 #ifdef _NO_EXTENSIONS
3366 if (!pane->treePane) {
3367 #endif
3369 /* display file size */
3370 if (visible_cols & COL_SIZE) {
3371 #ifdef _NO_EXTENSIONS
3372 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3373 #endif
3375 ULONGLONG size;
3377 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3379 _stprintf(buffer, sLongNumFmt, size);
3381 if (calcWidthCol == -1)
3382 output_number(pane, dis, col, buffer);
3383 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3384 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3387 col++;
3390 /* display file date */
3391 if (visible_cols & (COL_DATE|COL_TIME)) {
3392 #ifndef _NO_EXTENSIONS
3393 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3394 if (calcWidthCol == -1)
3395 output_text(pane, dis, col, buffer, 0);
3396 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3397 calc_width(pane, dis, col, buffer);
3398 col++;
3400 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3401 if (calcWidthCol == -1)
3402 output_text(pane, dis, col, buffer, 0);
3403 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3404 calc_width(pane, dis, col, buffer);
3405 col++;
3406 #endif /* _NO_EXTENSIONS */
3408 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3409 if (calcWidthCol == -1)
3410 output_text(pane, dis, col, buffer, 0);
3411 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3412 calc_width(pane, dis, col, buffer);
3413 col++;
3416 #ifndef _NO_EXTENSIONS
3417 if (entry->bhfi_valid) {
3418 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3420 if (visible_cols & COL_INDEX) {
3421 _stprintf(buffer, sLongHexFmt, index);
3423 if (calcWidthCol == -1)
3424 output_text(pane, dis, col, buffer, DT_RIGHT);
3425 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3426 calc_width(pane, dis, col, buffer);
3428 col++;
3431 if (visible_cols & COL_LINKS) {
3432 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3434 if (calcWidthCol == -1)
3435 output_text(pane, dis, col, buffer, DT_CENTER);
3436 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3437 calc_width(pane, dis, col, buffer);
3439 col++;
3441 } else
3442 col += 2;
3443 #endif /* _NO_EXTENSIONS */
3445 /* show file attributes */
3446 if (visible_cols & COL_ATTRIBUTES) {
3447 #ifdef _NO_EXTENSIONS
3448 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3449 lstrcpy(buffer, s4Tabs);
3450 #else
3451 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3452 lstrcpy(buffer, s11Tabs);
3453 #endif
3455 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3456 else {
3457 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3458 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3459 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3460 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3461 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3462 #ifndef _NO_EXTENSIONS
3463 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3464 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3465 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3466 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3467 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3468 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3469 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3470 #endif /* _NO_EXTENSIONS */
3473 if (calcWidthCol == -1)
3474 output_tabbed_text(pane, dis, col, buffer);
3475 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3476 calc_tabbed_width(pane, dis, col, buffer);
3478 col++;
3481 /*TODO
3482 if (flags.security) {
3483 static const TCHAR sSecTabs[] = {
3484 ' ','\t',' ','\t',' ','\t',' ',
3485 ' ','\t',' ',
3486 ' ','\t',' ','\t',' ','\t',' ',
3487 ' ','\t',' ',
3488 ' ','\t',' ','\t',' ','\t',' ',
3489 '\0'
3492 DWORD rights = get_access_mask();
3494 lstrcpy(buffer, sSecTabs);
3496 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3497 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3498 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3499 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3500 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3501 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3502 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3503 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3504 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3505 if (rights & WRITE_DAC) buffer[22] = 'C';
3506 if (rights & WRITE_OWNER) buffer[24] = 'O';
3507 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3509 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3512 if (flags.description) {
3513 get_description(buffer);
3514 output_text(dis, col++, buffer, 0, psize);
3518 #ifdef _NO_EXTENSIONS
3521 /* draw focus frame */
3522 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3523 /* Currently [04/2000] Wine neither behaves exactly the same */
3524 /* way as WIN 95 nor like Windows NT... */
3525 HGDIOBJ lastBrush;
3526 HPEN lastPen;
3527 HPEN hpen;
3529 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3530 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3531 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3532 } else
3533 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3535 lastPen = SelectPen(dis->hDC, hpen);
3536 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3537 SetROP2(dis->hDC, R2_XORPEN);
3538 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3539 SelectObject(dis->hDC, lastBrush);
3540 SelectObject(dis->hDC, lastPen);
3541 DeleteObject(hpen);
3543 #endif /* _NO_EXTENSIONS */
3547 #ifdef _NO_EXTENSIONS
3549 static void draw_splitbar(HWND hwnd, int x)
3551 RECT rt;
3552 HDC hdc = GetDC(hwnd);
3554 GetClientRect(hwnd, &rt);
3556 rt.left = x - SPLIT_WIDTH/2;
3557 rt.right = x + SPLIT_WIDTH/2+1;
3559 InvertRect(hdc, &rt);
3561 ReleaseDC(hwnd, hdc);
3564 #endif /* _NO_EXTENSIONS */
3567 #ifndef _NO_EXTENSIONS
3569 static void set_header(Pane* pane)
3571 HD_ITEM item;
3572 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3573 int i=0, x=0;
3575 item.mask = HDI_WIDTH;
3576 item.cxy = 0;
3578 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3579 x += pane->widths[i];
3580 Header_SetItem(pane->hwndHeader, i, &item);
3583 if (i < COLUMNS) {
3584 x += pane->widths[i];
3585 item.cxy = x - scroll_pos;
3586 Header_SetItem(pane->hwndHeader, i++, &item);
3588 for(; i<COLUMNS; i++) {
3589 item.cxy = pane->widths[i];
3590 x += pane->widths[i];
3591 Header_SetItem(pane->hwndHeader, i, &item);
3596 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3598 switch(pnmh->code) {
3599 case HDN_TRACK:
3600 case HDN_ENDTRACK: {
3601 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3602 int idx = phdn->iItem;
3603 int dx = phdn->pitem->cxy - pane->widths[idx];
3604 int i;
3606 RECT clnt;
3607 GetClientRect(pane->hwnd, &clnt);
3609 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3610 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
3612 pane->widths[idx] += dx;
3614 for(i=idx; ++i<=COLUMNS; )
3615 pane->positions[i] += dx;
3618 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3619 RECT rt_scr;
3620 RECT rt_clip;
3622 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3623 rt_scr.top = 0;
3624 rt_scr.right = clnt.right;
3625 rt_scr.bottom = clnt.bottom;
3627 rt_clip.left = pane->positions[idx]-scroll_pos;
3628 rt_clip.top = 0;
3629 rt_clip.right = clnt.right;
3630 rt_clip.bottom = clnt.bottom;
3632 if (rt_scr.left < 0) rt_scr.left = 0;
3633 if (rt_clip.left < 0) rt_clip.left = 0;
3635 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3637 rt_clip.right = pane->positions[idx+1];
3638 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3640 if (pnmh->code == HDN_ENDTRACK) {
3641 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
3643 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3644 set_header(pane);
3648 return FALSE;
3651 case HDN_DIVIDERDBLCLICK: {
3652 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3653 HD_ITEM item;
3655 calc_single_width(pane, phdn->iItem);
3656 item.mask = HDI_WIDTH;
3657 item.cxy = pane->widths[phdn->iItem];
3659 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3660 InvalidateRect(pane->hwnd, 0, TRUE);
3661 break;}
3664 return 0;
3667 #endif /* _NO_EXTENSIONS */
3670 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3672 TCHAR path[MAX_PATH];
3673 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3675 /* delete sub entries in left pane */
3676 for(;;) {
3677 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3678 Entry* sub = (Entry*) res;
3680 if (res==LB_ERR || !sub || sub->level<=entry->level)
3681 break;
3683 ListBox_DeleteString(child->left.hwnd, idx+1);
3686 /* empty right pane */
3687 ListBox_ResetContent(child->right.hwnd);
3689 /* release memory */
3690 free_entries(entry);
3692 /* read contents from disk */
3693 #ifdef _SHELL_FOLDERS
3694 if (entry->etype == ET_SHELL)
3696 read_directory(entry, NULL, child->sortOrder, hwnd);
3698 else
3699 #endif
3701 get_path(entry, path);
3702 read_directory(entry, path, child->sortOrder, hwnd);
3705 /* insert found entries in right pane */
3706 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3707 calc_widths(&child->right, FALSE);
3708 #ifndef _NO_EXTENSIONS
3709 set_header(&child->right);
3710 #endif
3712 child->header_wdths_ok = FALSE;
3714 SetCursor(old_cursor);
3718 /* expand a directory entry */
3720 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3722 int idx;
3723 Entry* p;
3725 if (!dir || dir->expanded || !dir->down)
3726 return FALSE;
3728 p = dir->down;
3730 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3731 p = p->next;
3733 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3734 p->data.cFileName[2]=='\0' && p->next)
3735 p = p->next;
3738 /* no subdirectories ? */
3739 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3740 return FALSE;
3742 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3744 dir->expanded = TRUE;
3746 /* insert entries in left pane */
3747 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3749 if (!child->header_wdths_ok) {
3750 if (calc_widths(&child->left, FALSE)) {
3751 #ifndef _NO_EXTENSIONS
3752 set_header(&child->left);
3753 #endif
3755 child->header_wdths_ok = TRUE;
3759 return TRUE;
3763 static void collapse_entry(Pane* pane, Entry* dir)
3765 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3767 ShowWindow(pane->hwnd, SW_HIDE);
3769 /* hide sub entries */
3770 for(;;) {
3771 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3772 Entry* sub = (Entry*) res;
3774 if (res==LB_ERR || !sub || sub->level<=dir->level)
3775 break;
3777 ListBox_DeleteString(pane->hwnd, idx+1);
3780 dir->expanded = FALSE;
3782 ShowWindow(pane->hwnd, SW_SHOW);
3786 static void refresh_right_pane(ChildWnd* child)
3788 ListBox_ResetContent(child->right.hwnd);
3789 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3790 calc_widths(&child->right, FALSE);
3792 #ifndef _NO_EXTENSIONS
3793 set_header(&child->right);
3794 #endif
3797 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3799 TCHAR path[MAX_PATH];
3801 if (!entry)
3802 return;
3804 path[0] = '\0';
3806 child->left.cur = entry;
3808 child->right.root = entry->down? entry->down: entry;
3809 child->right.cur = entry;
3811 if (!entry->scanned)
3812 scan_entry(child, entry, idx, hwnd);
3813 else
3814 refresh_right_pane(child);
3816 get_path(entry, path);
3817 lstrcpy(child->path, path);
3819 if (child->hwnd) /* only change window title, if the window already exists */
3820 SetWindowText(child->hwnd, path);
3822 if (path[0])
3823 if (SetCurrentDirectory(path))
3824 set_space_status();
3828 static void refresh_child(ChildWnd* child)
3830 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3831 Entry* entry;
3832 int idx;
3834 get_path(child->left.cur, path);
3835 _tsplitpath(path, drv, NULL, NULL, NULL);
3837 child->right.root = NULL;
3839 scan_entry(child, &child->root.entry, 0, child->hwnd);
3841 #ifdef _SHELL_FOLDERS
3842 if (child->root.entry.etype == ET_SHELL)
3843 entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd);
3844 else
3845 #endif
3846 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3848 if (!entry)
3849 entry = &child->root.entry;
3851 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3853 set_curdir(child, entry, 0, child->hwnd);
3855 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
3856 ListBox_SetCurSel(child->left.hwnd, idx);
3860 static void create_drive_bar(void)
3862 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3863 #ifndef _NO_EXTENSIONS
3864 TCHAR b1[BUFFER_LEN];
3865 #endif
3866 int btn = 1;
3867 PTSTR p;
3869 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3871 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3872 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3873 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3875 #ifndef _NO_EXTENSIONS
3876 #ifdef __WINE__
3877 /* insert unix file system button */
3878 b1[0] = '/';
3879 b1[1] = '\0';
3880 b1[2] = '\0';
3881 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3883 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3884 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3885 drivebarBtn.iString++;
3886 #endif
3887 #ifdef _SHELL_FOLDERS
3888 /* insert shell namespace button */
3889 load_string(b1, IDS_SHELL);
3890 b1[lstrlen(b1)+1] = '\0';
3891 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3893 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3894 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3895 drivebarBtn.iString++;
3896 #endif
3898 /* register windows drive root strings */
3899 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3900 #endif
3902 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3904 for(p=Globals.drives; *p; ) {
3905 #ifdef _NO_EXTENSIONS
3906 /* insert drive letter */
3907 TCHAR b[3] = {tolower(*p)};
3908 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3909 #endif
3910 switch(GetDriveType(p)) {
3911 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3912 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3913 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3914 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3915 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3918 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3919 drivebarBtn.idCommand++;
3920 drivebarBtn.iString++;
3922 while(*p++);
3926 static void refresh_drives(void)
3928 RECT rect;
3930 /* destroy drive bar */
3931 DestroyWindow(Globals.hdrivebar);
3932 Globals.hdrivebar = 0;
3934 /* re-create drive bar */
3935 create_drive_bar();
3937 /* update window layout */
3938 GetClientRect(Globals.hMainWnd, &rect);
3939 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3943 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3945 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3947 if ((int)hinst <= 32) {
3948 display_error(hwnd, GetLastError());
3949 return FALSE;
3952 return TRUE;
3956 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3958 TCHAR cmd[MAX_PATH];
3960 #ifdef _SHELL_FOLDERS
3961 if (entry->etype == ET_SHELL) {
3962 BOOL ret = TRUE;
3964 SHELLEXECUTEINFO shexinfo;
3966 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3967 shexinfo.fMask = SEE_MASK_IDLIST;
3968 shexinfo.hwnd = hwnd;
3969 shexinfo.lpVerb = NULL;
3970 shexinfo.lpFile = NULL;
3971 shexinfo.lpParameters = NULL;
3972 shexinfo.lpDirectory = NULL;
3973 shexinfo.nShow = nCmdShow;
3974 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3976 if (!ShellExecuteEx(&shexinfo)) {
3977 display_error(hwnd, GetLastError());
3978 ret = FALSE;
3981 if (shexinfo.lpIDList != entry->pidl)
3982 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3984 return ret;
3986 #endif
3988 get_path(entry, cmd);
3990 /* start program, open document... */
3991 return launch_file(hwnd, cmd, nCmdShow);
3995 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3997 Entry* entry = pane->cur;
3999 if (!entry)
4000 return;
4002 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
4003 int scanned_old = entry->scanned;
4005 if (!scanned_old)
4006 scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd);
4008 #ifndef _NO_EXTENSIONS
4009 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
4010 return;
4011 #endif
4013 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
4014 entry = child->left.cur->up;
4015 collapse_entry(&child->left, entry);
4016 goto focus_entry;
4017 } else if (entry->expanded)
4018 collapse_entry(pane, child->left.cur);
4019 else {
4020 expand_entry(child, child->left.cur);
4022 if (!pane->treePane) focus_entry: {
4023 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
4024 ListBox_SetCurSel(child->left.hwnd, idx);
4025 set_curdir(child, entry, idx, hwnd);
4029 if (!scanned_old) {
4030 calc_widths(pane, FALSE);
4032 #ifndef _NO_EXTENSIONS
4033 set_header(pane);
4034 #endif
4036 } else {
4037 if (GetKeyState(VK_MENU) < 0)
4038 show_properties_dlg(entry, child->hwnd);
4039 else
4040 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
4045 static BOOL pane_command(Pane* pane, UINT cmd)
4047 switch(cmd) {
4048 case ID_VIEW_NAME:
4049 if (pane->visible_cols) {
4050 pane->visible_cols = 0;
4051 calc_widths(pane, TRUE);
4052 #ifndef _NO_EXTENSIONS
4053 set_header(pane);
4054 #endif
4055 InvalidateRect(pane->hwnd, 0, TRUE);
4056 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
4057 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
4058 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4060 break;
4062 case ID_VIEW_ALL_ATTRIBUTES:
4063 if (pane->visible_cols != COL_ALL) {
4064 pane->visible_cols = COL_ALL;
4065 calc_widths(pane, TRUE);
4066 #ifndef _NO_EXTENSIONS
4067 set_header(pane);
4068 #endif
4069 InvalidateRect(pane->hwnd, 0, TRUE);
4070 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
4071 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
4072 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4074 break;
4076 #ifndef _NO_EXTENSIONS
4077 case ID_PREFERRED_SIZES: {
4078 calc_widths(pane, TRUE);
4079 set_header(pane);
4080 InvalidateRect(pane->hwnd, 0, TRUE);
4081 break;}
4082 #endif
4084 /* TODO: more command ids... */
4086 default:
4087 return FALSE;
4090 return TRUE;
4094 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
4096 if (child->sortOrder != sortOrder) {
4097 child->sortOrder = sortOrder;
4098 refresh_child(child);
4102 static void update_view_menu(ChildWnd* child)
4104 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4105 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4106 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4107 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4111 static BOOL is_directory(LPCTSTR target)
4113 /*TODO correctly handle UNIX paths */
4114 DWORD target_attr = GetFileAttributes(target);
4116 if (target_attr == INVALID_FILE_ATTRIBUTES)
4117 return FALSE;
4119 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4122 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4124 TCHAR path[MAX_PATH];
4125 int len;
4127 get_path(pane->cur, path);
4129 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4130 return FALSE;
4132 get_path(pane->cur, source);
4134 /* convert relative targets to absolute paths */
4135 if (path[0]!='/' && path[1]!=':') {
4136 get_path(pane->cur->up, target);
4137 len = lstrlen(target);
4139 if (target[len-1]!='\\' && target[len-1]!='/')
4140 target[len++] = '/';
4142 lstrcpy(target+len, path);
4143 } else
4144 lstrcpy(target, path);
4146 /* If the target already exists as directory, create a new target below this. */
4147 if (is_directory(path)) {
4148 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4149 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4151 _tsplitpath(source, NULL, NULL, fname, ext);
4153 wsprintf(target, sAppend, path, fname, ext);
4156 return TRUE;
4160 static IContextMenu2* s_pctxmenu2 = NULL;
4161 static IContextMenu3* s_pctxmenu3 = NULL;
4163 static void CtxMenu_reset(void)
4165 s_pctxmenu2 = NULL;
4166 s_pctxmenu3 = NULL;
4169 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4171 IContextMenu* pcm = NULL;
4173 CtxMenu_reset();
4175 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4176 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4177 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4178 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4180 if (pcm) {
4181 IContextMenu_Release(pcm1);
4182 return pcm;
4183 } else
4184 return pcm1;
4187 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4189 if (s_pctxmenu3) {
4190 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4191 return TRUE;
4194 if (s_pctxmenu2)
4195 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4196 return TRUE;
4198 return FALSE;
4202 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4204 IContextMenu* pcm;
4205 BOOL executed = FALSE;
4207 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4208 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4210 if (SUCCEEDED(hr)) {
4211 HMENU hmenu = CreatePopupMenu();
4213 pcm = CtxMenu_query_interfaces(pcm);
4215 if (hmenu) {
4216 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4218 if (SUCCEEDED(hr)) {
4219 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4221 CtxMenu_reset();
4223 if (idCmd) {
4224 CMINVOKECOMMANDINFO cmi;
4226 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4227 cmi.fMask = 0;
4228 cmi.hwnd = hwndParent;
4229 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4230 cmi.lpParameters = NULL;
4231 cmi.lpDirectory = NULL;
4232 cmi.nShow = SW_SHOWNORMAL;
4233 cmi.dwHotKey = 0;
4234 cmi.hIcon = 0;
4236 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4237 executed = TRUE;
4239 } else
4240 CtxMenu_reset();
4243 IContextMenu_Release(pcm);
4246 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4250 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4252 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4253 ASSERT(child);
4255 switch(nmsg) {
4256 case WM_DRAWITEM: {
4257 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4258 Entry* entry = (Entry*) dis->itemData;
4260 if (dis->CtlID == IDW_TREE_LEFT)
4261 draw_item(&child->left, dis, entry, -1);
4262 else if (dis->CtlID == IDW_TREE_RIGHT)
4263 draw_item(&child->right, dis, entry, -1);
4264 else
4265 goto draw_menu_item;
4267 return TRUE;}
4269 case WM_CREATE:
4270 InitChildWindow(child);
4271 break;
4273 case WM_NCDESTROY:
4274 free_child_window(child);
4275 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4276 break;
4278 case WM_PAINT: {
4279 PAINTSTRUCT ps;
4280 HBRUSH lastBrush;
4281 RECT rt;
4282 GetClientRect(hwnd, &rt);
4283 BeginPaint(hwnd, &ps);
4284 rt.left = child->split_pos-SPLIT_WIDTH/2;
4285 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4286 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
4287 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4288 SelectObject(ps.hdc, lastBrush);
4289 #ifdef _NO_EXTENSIONS
4290 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4291 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4292 #endif
4293 EndPaint(hwnd, &ps);
4294 break;}
4296 case WM_SETCURSOR:
4297 if (LOWORD(lparam) == HTCLIENT) {
4298 POINT pt;
4299 GetCursorPos(&pt);
4300 ScreenToClient(hwnd, &pt);
4302 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4303 SetCursor(LoadCursor(0, IDC_SIZEWE));
4304 return TRUE;
4307 goto def;
4309 case WM_LBUTTONDOWN: {
4310 RECT rt;
4311 int x = GET_X_LPARAM(lparam);
4313 GetClientRect(hwnd, &rt);
4315 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4316 last_split = child->split_pos;
4317 #ifdef _NO_EXTENSIONS
4318 draw_splitbar(hwnd, last_split);
4319 #endif
4320 SetCapture(hwnd);
4323 break;}
4325 case WM_LBUTTONUP:
4326 if (GetCapture() == hwnd) {
4327 #ifdef _NO_EXTENSIONS
4328 RECT rt;
4329 int x = LOWORD(lparam);
4330 draw_splitbar(hwnd, last_split);
4331 last_split = -1;
4332 GetClientRect(hwnd, &rt);
4333 child->split_pos = x;
4334 resize_tree(child, rt.right, rt.bottom);
4335 #endif
4336 ReleaseCapture();
4338 break;
4340 #ifdef _NO_EXTENSIONS
4341 case WM_CAPTURECHANGED:
4342 if (GetCapture()==hwnd && last_split>=0)
4343 draw_splitbar(hwnd, last_split);
4344 break;
4345 #endif
4347 case WM_KEYDOWN:
4348 if (wparam == VK_ESCAPE)
4349 if (GetCapture() == hwnd) {
4350 RECT rt;
4351 #ifdef _NO_EXTENSIONS
4352 draw_splitbar(hwnd, last_split);
4353 #else
4354 child->split_pos = last_split;
4355 #endif
4356 GetClientRect(hwnd, &rt);
4357 resize_tree(child, rt.right, rt.bottom);
4358 last_split = -1;
4359 ReleaseCapture();
4360 SetCursor(LoadCursor(0, IDC_ARROW));
4362 break;
4364 case WM_MOUSEMOVE:
4365 if (GetCapture() == hwnd) {
4366 RECT rt;
4367 int x = LOWORD(lparam);
4369 #ifdef _NO_EXTENSIONS
4370 HDC hdc = GetDC(hwnd);
4371 GetClientRect(hwnd, &rt);
4373 rt.left = last_split-SPLIT_WIDTH/2;
4374 rt.right = last_split+SPLIT_WIDTH/2+1;
4375 InvertRect(hdc, &rt);
4377 last_split = x;
4378 rt.left = x-SPLIT_WIDTH/2;
4379 rt.right = x+SPLIT_WIDTH/2+1;
4380 InvertRect(hdc, &rt);
4382 ReleaseDC(hwnd, hdc);
4383 #else
4384 GetClientRect(hwnd, &rt);
4386 if (x>=0 && x<rt.right) {
4387 child->split_pos = x;
4388 resize_tree(child, rt.right, rt.bottom);
4389 rt.left = x-SPLIT_WIDTH/2;
4390 rt.right = x+SPLIT_WIDTH/2+1;
4391 InvalidateRect(hwnd, &rt, FALSE);
4392 UpdateWindow(child->left.hwnd);
4393 UpdateWindow(hwnd);
4394 UpdateWindow(child->right.hwnd);
4396 #endif
4398 break;
4400 #ifndef _NO_EXTENSIONS
4401 case WM_GETMINMAXINFO:
4402 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4404 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4406 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4407 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4408 break;}
4409 #endif /* _NO_EXTENSIONS */
4411 case WM_SETFOCUS:
4412 if (SetCurrentDirectory(child->path))
4413 set_space_status();
4414 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4415 break;
4417 case WM_DISPATCH_COMMAND: {
4418 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4420 switch(LOWORD(wparam)) {
4421 case ID_WINDOW_NEW: {
4422 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4424 if (!create_child_window(new_child))
4425 free(new_child);
4427 break;}
4429 case ID_REFRESH:
4430 refresh_drives();
4431 refresh_child(child);
4432 break;
4434 case ID_ACTIVATE:
4435 activate_entry(child, pane, hwnd);
4436 break;
4438 case ID_FILE_MOVE: {
4439 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4441 if (prompt_target(pane, source, target)) {
4442 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4444 source[lstrlen(source)+1] = '\0';
4445 target[lstrlen(target)+1] = '\0';
4447 if (!SHFileOperation(&shfo))
4448 refresh_child(child);
4450 break;}
4452 case ID_FILE_COPY: {
4453 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4455 if (prompt_target(pane, source, target)) {
4456 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4458 source[lstrlen(source)+1] = '\0';
4459 target[lstrlen(target)+1] = '\0';
4461 if (!SHFileOperation(&shfo))
4462 refresh_child(child);
4464 break;}
4466 case ID_FILE_DELETE: {
4467 TCHAR path[BUFFER_LEN];
4468 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
4470 get_path(pane->cur, path);
4472 path[lstrlen(path)+1] = '\0';
4474 if (!SHFileOperation(&shfo))
4475 refresh_child(child);
4476 break;}
4478 case ID_VIEW_SORT_NAME:
4479 set_sort_order(child, SORT_NAME);
4480 break;
4482 case ID_VIEW_SORT_TYPE:
4483 set_sort_order(child, SORT_EXT);
4484 break;
4486 case ID_VIEW_SORT_SIZE:
4487 set_sort_order(child, SORT_SIZE);
4488 break;
4490 case ID_VIEW_SORT_DATE:
4491 set_sort_order(child, SORT_DATE);
4492 break;
4494 case ID_VIEW_FILTER: {
4495 struct FilterDialog dlg;
4497 memset(&dlg, 0, sizeof(struct FilterDialog));
4498 lstrcpy(dlg.pattern, child->filter_pattern);
4499 dlg.flags = child->filter_flags;
4501 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4502 lstrcpy(child->filter_pattern, dlg.pattern);
4503 child->filter_flags = dlg.flags;
4504 refresh_right_pane(child);
4506 break;}
4508 case ID_VIEW_SPLIT: {
4509 last_split = child->split_pos;
4510 #ifdef _NO_EXTENSIONS
4511 draw_splitbar(hwnd, last_split);
4512 #endif
4513 SetCapture(hwnd);
4514 break;}
4516 case ID_EDIT_PROPERTIES:
4517 show_properties_dlg(pane->cur, child->hwnd);
4518 break;
4520 default:
4521 return pane_command(pane, LOWORD(wparam));
4524 return TRUE;}
4526 case WM_COMMAND: {
4527 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4529 switch(HIWORD(wparam)) {
4530 case LBN_SELCHANGE: {
4531 int idx = ListBox_GetCurSel(pane->hwnd);
4532 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4534 if (pane == &child->left)
4535 set_curdir(child, entry, idx, hwnd);
4536 else
4537 pane->cur = entry;
4538 break;}
4540 case LBN_DBLCLK:
4541 activate_entry(child, pane, hwnd);
4542 break;
4544 break;}
4546 #ifndef _NO_EXTENSIONS
4547 case WM_NOTIFY: {
4548 NMHDR* pnmh = (NMHDR*) lparam;
4549 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4550 #endif
4552 #ifdef _SHELL_FOLDERS
4553 case WM_CONTEXTMENU: {
4554 POINT pt, pt_clnt;
4555 Pane* pane;
4556 int idx;
4558 /* first select the current item in the listbox */
4559 HWND hpanel = (HWND) wparam;
4560 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4561 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4562 ScreenToClient(hpanel, &pt_clnt);
4563 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4564 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4566 /* now create the popup menu using shell namespace and IContextMenu */
4567 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4568 idx = ListBox_GetCurSel(pane->hwnd);
4570 if (idx != -1) {
4571 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4573 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4575 if (pidl_abs) {
4576 IShellFolder* parentFolder;
4577 LPCITEMIDLIST pidlLast;
4579 /* get and use the parent folder to display correct context menu in all cases */
4580 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4581 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4582 refresh_child(child);
4584 IShellFolder_Release(parentFolder);
4587 IMalloc_Free(Globals.iMalloc, pidl_abs);
4590 break;}
4591 #endif
4593 case WM_MEASUREITEM:
4594 draw_menu_item:
4595 if (!wparam) /* Is the message menu-related? */
4596 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4597 return TRUE;
4599 break;
4601 case WM_INITMENUPOPUP:
4602 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4603 return 0;
4605 update_view_menu(child);
4606 break;
4608 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4609 if (s_pctxmenu3) {
4610 LRESULT lResult = 0;
4612 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4614 return lResult;
4617 break;
4619 case WM_SIZE:
4620 if (wparam != SIZE_MINIMIZED)
4621 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4622 /* fall through */
4624 default: def:
4625 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4628 return 0;
4632 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4634 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4635 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4636 ASSERT(child);
4638 switch(nmsg) {
4639 #ifndef _NO_EXTENSIONS
4640 case WM_HSCROLL:
4641 set_header(pane);
4642 break;
4643 #endif
4645 case WM_SETFOCUS:
4646 child->focus_pane = pane==&child->right? 1: 0;
4647 ListBox_SetSel(hwnd, TRUE, 1);
4648 /*TODO: check menu items */
4649 break;
4651 case WM_KEYDOWN:
4652 if (wparam == VK_TAB) {
4653 /*TODO: SetFocus(Globals.hdrivebar) */
4654 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4658 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4662 static void InitInstance(HINSTANCE hinstance)
4664 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4666 WNDCLASSEX wcFrame;
4667 WNDCLASS wcChild;
4668 ATOM hChildClass;
4669 int col;
4671 INITCOMMONCONTROLSEX icc = {
4672 sizeof(INITCOMMONCONTROLSEX),
4673 ICC_BAR_CLASSES
4676 HDC hdc = GetDC(0);
4678 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4680 InitCommonControlsEx(&icc);
4683 /* register frame window class */
4685 wcFrame.cbSize = sizeof(WNDCLASSEX);
4686 wcFrame.style = 0;
4687 wcFrame.lpfnWndProc = FrameWndProc;
4688 wcFrame.cbClsExtra = 0;
4689 wcFrame.cbWndExtra = 0;
4690 wcFrame.hInstance = hinstance;
4691 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4692 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4693 wcFrame.hbrBackground = 0;
4694 wcFrame.lpszMenuName = 0;
4695 wcFrame.lpszClassName = sWINEFILEFRAME;
4696 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4697 MAKEINTRESOURCE(IDI_WINEFILE),
4698 IMAGE_ICON,
4699 GetSystemMetrics(SM_CXSMICON),
4700 GetSystemMetrics(SM_CYSMICON),
4701 LR_SHARED);
4703 Globals.hframeClass = RegisterClassEx(&wcFrame);
4706 /* register tree windows class */
4708 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4709 wcChild.lpfnWndProc = ChildWndProc;
4710 wcChild.cbClsExtra = 0;
4711 wcChild.cbWndExtra = 0;
4712 wcChild.hInstance = hinstance;
4713 wcChild.hIcon = 0;
4714 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4715 wcChild.hbrBackground = 0;
4716 wcChild.lpszMenuName = 0;
4717 wcChild.lpszClassName = sWINEFILETREE;
4719 hChildClass = RegisterClass(&wcChild);
4722 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4724 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4726 ReleaseDC(0, hdc);
4728 Globals.hInstance = hinstance;
4730 #ifdef _SHELL_FOLDERS
4731 CoInitialize(NULL);
4732 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4733 SHGetDesktopFolder(&Globals.iDesktop);
4734 #ifdef __WINE__
4735 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4736 #else
4737 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4738 #endif
4739 #endif
4741 /* load column strings */
4742 col = 1;
4744 load_string(g_pos_names[col++], IDS_COL_NAME);
4745 load_string(g_pos_names[col++], IDS_COL_SIZE);
4746 load_string(g_pos_names[col++], IDS_COL_CDATE);
4747 #ifndef _NO_EXTENSIONS
4748 load_string(g_pos_names[col++], IDS_COL_ADATE);
4749 load_string(g_pos_names[col++], IDS_COL_MDATE);
4750 load_string(g_pos_names[col++], IDS_COL_IDX);
4751 load_string(g_pos_names[col++], IDS_COL_LINKS);
4752 #endif
4753 load_string(g_pos_names[col++], IDS_COL_ATTR);
4754 #ifndef _NO_EXTENSIONS
4755 load_string(g_pos_names[col++], IDS_COL_SEC);
4756 #endif
4760 static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4762 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4764 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4765 ChildWnd* child;
4766 HMENU hMenuFrame, hMenuWindow;
4767 windowOptions opts;
4769 CLIENTCREATESTRUCT ccs;
4771 if (Globals.hMainWnd)
4772 return;
4774 opts = load_registry_settings();
4775 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4776 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4778 Globals.hMenuFrame = hMenuFrame;
4779 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4780 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4782 ccs.hWindowMenu = hMenuWindow;
4783 ccs.idFirstChild = IDW_FIRST_CHILD;
4786 /* create main window */
4787 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4788 opts.start_x, opts.start_y, opts.width, opts.height,
4789 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4792 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4793 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4794 0, 0, 0, 0,
4795 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4797 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4798 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4800 create_drive_bar();
4803 TBBUTTON toolbarBtns[] = {
4804 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4805 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4806 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4807 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4808 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4809 /*TODO
4810 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4811 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4812 */ };
4814 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4815 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4816 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4817 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4820 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4821 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4823 /* CreateStatusWindow does not accept WS_BORDER
4824 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4825 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4826 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4828 /*TODO: read paths from registry */
4830 if (!path || !*path) {
4831 GetCurrentDirectory(MAX_PATH, buffer);
4832 path = buffer;
4835 ShowWindow(Globals.hMainWnd, cmdshow);
4837 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4838 /* Shell Namespace as default: */
4839 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4840 #else
4841 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4842 #endif
4844 child->pos.showCmd = SW_SHOWMAXIMIZED;
4845 child->pos.rcNormalPosition.left = 0;
4846 child->pos.rcNormalPosition.top = 0;
4847 child->pos.rcNormalPosition.right = 320;
4848 child->pos.rcNormalPosition.bottom = 280;
4850 if (!create_child_window(child))
4851 free(child);
4853 SetWindowPlacement(child->hwnd, &child->pos);
4855 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4857 Globals.prescan_node = FALSE;
4859 UpdateWindow(Globals.hMainWnd);
4861 if (path && path[0])
4863 int index,count;
4864 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4865 TCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4867 memset(name,0,sizeof(name));
4868 memset(name,0,sizeof(ext));
4869 _tsplitpath(path, drv, dir, name, ext);
4870 if (name[0])
4872 count = ListBox_GetCount(child->right.hwnd);
4873 lstrcpy(fullname,name);
4874 lstrcat(fullname,ext);
4876 for (index = 0; index < count; index ++)
4878 Entry* entry = (Entry*) ListBox_GetItemData(child->right.hwnd,
4879 index);
4880 if (lstrcmp(entry->data.cFileName,fullname)==0 ||
4881 lstrcmp(entry->data.cAlternateFileName,fullname)==0)
4883 ListBox_SetCurSel(child->right.hwnd, index);
4884 SetFocus(child->right.hwnd);
4885 break;
4892 static void ExitInstance(void)
4894 #ifdef _SHELL_FOLDERS
4895 IShellFolder_Release(Globals.iDesktop);
4896 IMalloc_Release(Globals.iMalloc);
4897 CoUninitialize();
4898 #endif
4900 DeleteObject(Globals.hfont);
4901 ImageList_Destroy(Globals.himl);
4904 #ifdef _NO_EXTENSIONS
4906 /* search for already running win[e]files */
4908 static int g_foundPrevInstance = 0;
4910 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4912 TCHAR cls[128];
4914 GetClassName(hwnd, cls, 128);
4916 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4917 g_foundPrevInstance++;
4918 return FALSE;
4921 return TRUE;
4924 /* search for window of given class name to allow only one running instance */
4925 static int find_window_class(LPCTSTR classname)
4927 EnumWindows(EnumWndProc, (LPARAM)classname);
4929 if (g_foundPrevInstance)
4930 return 1;
4932 return 0;
4935 #endif
4937 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4939 MSG msg;
4941 InitInstance(hinstance);
4943 show_frame(0, cmdshow, path);
4945 while(GetMessage(&msg, 0, 0, 0)) {
4946 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4947 continue;
4949 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4950 continue;
4952 TranslateMessage(&msg);
4953 DispatchMessage(&msg);
4956 ExitInstance();
4958 return msg.wParam;
4962 #if defined(UNICODE) && defined(_MSC_VER)
4963 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4964 #else
4965 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4966 #endif
4968 #ifdef _NO_EXTENSIONS
4969 if (find_window_class(sWINEFILEFRAME))
4970 return 1;
4971 #endif
4973 #if defined(UNICODE) && !defined(_MSC_VER)
4974 { /* convert ANSI cmdline into WCS path string */
4975 TCHAR buffer[MAX_PATH];
4976 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4977 winefile_main(hinstance, cmdshow, buffer);
4979 #else
4980 winefile_main(hinstance, cmdshow, cmdline);
4981 #endif
4983 return 0;