- use ID_SELECT_FONT in german menu
[wine/hacks.git] / programs / winefile / winefile.c
blob82c09fad2310e39860fa5e00289893aa0fa36371
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifdef __WINE__
22 #include "config.h"
23 #include "wine/port.h"
24 #endif
26 #include <locale.h>
28 #define NONAMELESSUNION
29 #include "winefile.h"
30 #include "resource.h"
32 /* for read_directory_unix() */
33 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
34 #include <dirent.h>
35 #include <sys/stat.h>
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
39 #include <time.h>
40 #endif
42 #ifdef _NO_EXTENSIONS
43 #undef _LEFT_FILES
44 #endif
46 #ifndef _MAX_PATH
47 #define _MAX_DRIVE 3
48 #define _MAX_FNAME 256
49 #define _MAX_DIR _MAX_FNAME
50 #define _MAX_EXT _MAX_FNAME
51 #define _MAX_PATH 260
52 #endif
54 #ifdef NONAMELESSUNION
55 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
56 #else
57 #define UNION_MEMBER(x) x
58 #endif
61 #ifdef _SHELL_FOLDERS
62 #define DEFAULT_SPLIT_POS 300
63 #else
64 #define DEFAULT_SPLIT_POS 200
65 #endif
68 WINEFILE_GLOBALS Globals;
70 extern void WineLicense(HWND hwnd);
71 extern void WineWarranty(HWND hwnd);
73 enum ENTRY_TYPE {
74 ET_WINDOWS,
75 ET_UNIX,
76 #ifdef _SHELL_FOLDERS
77 ET_SHELL
78 #endif
81 typedef struct _Entry {
82 struct _Entry* next;
83 struct _Entry* down;
84 struct _Entry* up;
86 BOOL expanded;
87 BOOL scanned;
88 int level;
90 WIN32_FIND_DATA data;
92 #ifndef _NO_EXTENSIONS
93 BY_HANDLE_FILE_INFORMATION bhfi;
94 BOOL bhfi_valid;
95 enum ENTRY_TYPE etype;
96 #endif
97 #ifdef _SHELL_FOLDERS
98 LPITEMIDLIST pidl;
99 IShellFolder* folder;
100 HICON hicon;
101 #endif
102 } Entry;
104 typedef struct {
105 Entry entry;
106 TCHAR path[MAX_PATH];
107 TCHAR volname[_MAX_FNAME];
108 TCHAR fs[_MAX_DIR];
109 DWORD drive_type;
110 DWORD fs_flags;
111 } Root;
113 enum COLUMN_FLAGS {
114 COL_SIZE = 0x01,
115 COL_DATE = 0x02,
116 COL_TIME = 0x04,
117 COL_ATTRIBUTES = 0x08,
118 COL_DOSNAMES = 0x10,
119 #ifdef _NO_EXTENSIONS
120 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
121 #else
122 COL_INDEX = 0x20,
123 COL_LINKS = 0x40,
124 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
125 #endif
128 typedef enum {
129 SORT_NAME,
130 SORT_EXT,
131 SORT_SIZE,
132 SORT_DATE
133 } SORT_ORDER;
135 typedef struct {
136 HWND hwnd;
137 #ifndef _NO_EXTENSIONS
138 HWND hwndHeader;
139 #endif
141 #ifndef _NO_EXTENSIONS
142 #define COLUMNS 10
143 #else
144 #define COLUMNS 5
145 #endif
146 int widths[COLUMNS];
147 int positions[COLUMNS+1];
149 BOOL treePane;
150 int visible_cols;
151 Entry* root;
152 Entry* cur;
153 } Pane;
155 typedef struct {
156 HWND hwnd;
157 Pane left;
158 Pane right;
159 int focus_pane; /* 0: left 1: right */
160 WINDOWPLACEMENT pos;
161 int split_pos;
162 BOOL header_wdths_ok;
164 TCHAR path[MAX_PATH];
165 Root root;
167 SORT_ORDER sortOrder;
168 } ChildWnd;
171 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
172 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd);
173 static void get_path(Entry* dir, PTSTR path);
175 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
176 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
177 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 /* load resource string */
181 static LPTSTR load_string(LPTSTR buffer, UINT id)
183 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
185 return buffer;
188 #define RS(b, i) load_string(b, i)
191 /* display error message for the specified WIN32 error code */
192 static void display_error(HWND hwnd, DWORD error)
194 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
195 PTSTR msg;
197 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
198 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
199 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
200 else
201 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
203 LocalFree(msg);
206 /* allocate and initialise a directory entry */
207 static Entry* alloc_entry()
209 Entry* entry = (Entry*) malloc(sizeof(Entry));
211 #ifdef _SHELL_FOLDERS
212 entry->pidl = NULL;
213 entry->folder = NULL;
214 entry->hicon = 0;
215 #endif
217 return entry;
220 /* free a directory entry */
221 static void free_entry(Entry* entry)
223 #ifdef _SHELL_FOLDERS
224 if (entry->hicon && entry->hicon!=(HICON)-1)
225 DestroyIcon(entry->hicon);
227 if (entry->folder && entry->folder!=Globals.iDesktop)
228 (*entry->folder->lpVtbl->Release)(entry->folder);
230 if (entry->pidl)
231 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
232 #endif
234 free(entry);
237 /* recursively free all child entries */
238 static void free_entries(Entry* dir)
240 Entry *entry, *next=dir->down;
242 if (next) {
243 dir->down = 0;
245 do {
246 entry = next;
247 next = entry->next;
249 free_entries(entry);
250 free_entry(entry);
251 } while(next);
256 static void read_directory_win(Entry* dir, LPCTSTR path)
258 Entry* first_entry = NULL;
259 Entry* last = NULL;
260 Entry* entry;
262 int level = dir->level + 1;
263 WIN32_FIND_DATA w32fd;
264 HANDLE hFind;
265 #ifndef _NO_EXTENSIONS
266 HANDLE hFile;
267 #endif
269 TCHAR buffer[MAX_PATH], *p;
270 for(p=buffer; *path; )
271 *p++ = *path++;
273 lstrcpy(p, TEXT("\\*"));
275 hFind = FindFirstFile(buffer, &w32fd);
277 if (hFind != INVALID_HANDLE_VALUE) {
278 do {
279 entry = alloc_entry();
281 if (!first_entry)
282 first_entry = entry;
284 if (last)
285 last->next = entry;
287 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
288 entry->down = NULL;
289 entry->up = dir;
290 entry->expanded = FALSE;
291 entry->scanned = FALSE;
292 entry->level = level;
294 #ifdef _NO_EXTENSIONS
295 /* hide directory entry "." */
296 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
297 LPCTSTR name = entry->data.cFileName;
299 if (name[0]=='.' && name[1]=='\0')
300 continue;
302 #else
303 entry->etype = ET_WINDOWS;
304 entry->bhfi_valid = FALSE;
306 lstrcpy(p+1, entry->data.cFileName);
308 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
309 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
311 if (hFile != INVALID_HANDLE_VALUE) {
312 if (GetFileInformationByHandle(hFile, &entry->bhfi))
313 entry->bhfi_valid = TRUE;
315 CloseHandle(hFile);
317 #endif
319 last = entry;
320 } while(FindNextFile(hFind, &entry->data));
322 last->next = NULL;
324 FindClose(hFind);
327 dir->down = first_entry;
328 dir->scanned = TRUE;
332 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
334 Entry* entry;
336 for(entry=dir->down; entry; entry=entry->next) {
337 LPCTSTR p = name;
338 LPCTSTR q = entry->data.cFileName;
340 do {
341 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
342 return entry;
343 } while(tolower(*p++) == tolower(*q++));
345 p = name;
346 q = entry->data.cAlternateFileName;
348 do {
349 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
350 return entry;
351 } while(tolower(*p++) == tolower(*q++));
354 return 0;
358 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
360 TCHAR buffer[MAX_PATH];
361 Entry* entry = &root->entry;
362 LPCTSTR s = path;
363 PTSTR d = buffer;
365 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
367 #ifndef _NO_EXTENSIONS
368 entry->etype = ET_WINDOWS;
369 #endif
371 while(entry) {
372 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
373 *d++ = *s++;
375 while(*s==TEXT('\\') || *s==TEXT('/'))
376 s++;
378 *d++ = TEXT('\\');
379 *d = TEXT('\0');
381 read_directory(entry, buffer, sortOrder, hwnd);
383 if (entry->down)
384 entry->expanded = TRUE;
386 if (!*s)
387 break;
389 entry = find_entry_win(entry, s);
392 SetCursor(old_cursor);
394 return entry;
398 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
400 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
402 struct tm* tm = gmtime(t);
403 SYSTEMTIME stime;
405 if (!tm)
406 return FALSE;
408 stime.wYear = tm->tm_year+1900;
409 stime.wMonth = tm->tm_mon+1;
410 /* stime.wDayOfWeek */
411 stime.wDay = tm->tm_mday;
412 stime.wHour = tm->tm_hour;
413 stime.wMinute = tm->tm_min;
414 stime.wSecond = tm->tm_sec;
416 return SystemTimeToFileTime(&stime, ftime);
419 static void read_directory_unix(Entry* dir, LPCTSTR path)
421 Entry* first_entry = NULL;
422 Entry* last = NULL;
423 Entry* entry;
425 int level = dir->level + 1;
427 DIR* pdir = opendir(path);
429 if (pdir) {
430 struct stat st;
431 struct dirent* ent;
432 TCHAR buffer[MAX_PATH], *p;
434 for(p=buffer; *path; )
435 *p++ = *path++;
437 if (p==buffer || p[-1]!='/')
438 *p++ = '/';
440 while((ent=readdir(pdir))) {
441 entry = alloc_entry();
443 if (!first_entry)
444 first_entry = entry;
446 if (last)
447 last->next = entry;
449 entry->etype = ET_UNIX;
451 lstrcpy(entry->data.cFileName, ent->d_name);
452 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
454 strcpy(p, ent->d_name);
456 if (!stat(buffer, &st)) {
457 if (S_ISDIR(st.st_mode))
458 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
460 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
461 entry->data.nFileSizeHigh = st.st_size >> 32;
463 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
464 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
465 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
467 entry->bhfi.nFileIndexLow = ent->d_ino;
468 entry->bhfi.nFileIndexHigh = 0;
470 entry->bhfi.nNumberOfLinks = st.st_nlink;
472 entry->bhfi_valid = TRUE;
473 } else {
474 entry->data.nFileSizeLow = 0;
475 entry->data.nFileSizeHigh = 0;
476 entry->bhfi_valid = FALSE;
479 entry->down = NULL;
480 entry->up = dir;
481 entry->expanded = FALSE;
482 entry->scanned = FALSE;
483 entry->level = level;
485 last = entry;
488 last->next = NULL;
490 closedir(pdir);
493 dir->down = first_entry;
494 dir->scanned = TRUE;
497 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
499 Entry* entry;
501 for(entry=dir->down; entry; entry=entry->next) {
502 LPCTSTR p = name;
503 LPCTSTR q = entry->data.cFileName;
505 do {
506 if (!*p || *p==TEXT('/'))
507 return entry;
508 } while(*p++ == *q++);
511 return 0;
514 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
516 TCHAR buffer[MAX_PATH];
517 Entry* entry = &root->entry;
518 LPCTSTR s = path;
519 PTSTR d = buffer;
521 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
523 entry->etype = ET_UNIX;
525 while(entry) {
526 while(*s && *s!=TEXT('/'))
527 *d++ = *s++;
529 while(*s == TEXT('/'))
530 s++;
532 *d++ = TEXT('/');
533 *d = TEXT('\0');
535 read_directory(entry, buffer, sortOrder, hwnd);
537 if (entry->down)
538 entry->expanded = TRUE;
540 if (!*s)
541 break;
543 entry = find_entry_unix(entry, s);
546 SetCursor(old_cursor);
548 return entry;
551 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
554 #ifdef _SHELL_FOLDERS
556 #ifdef UNICODE
557 #define tcscpyn strcpyn
558 #define get_strret get_strretW
559 #define path_from_pidl path_from_pidlW
560 #else
561 #define tcscpyn wcscpyn
562 #define get_strret get_strretA
563 #define path_from_pidl path_from_pidlA
564 #endif
567 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
569 LPCSTR s;
570 LPSTR d = dest;
572 for(s=source; count&&(*d++=*s++); )
573 count--;
575 return dest;
578 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
580 LPCWSTR s;
581 LPWSTR d = dest;
583 for(s=source; count&&(*d++=*s++); )
584 count--;
586 return dest;
590 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
592 switch(str->uType) {
593 case STRRET_WSTR:
594 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
595 break;
597 case STRRET_OFFSET:
598 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
599 break;
601 case STRRET_CSTR:
602 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
606 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
608 switch(str->uType) {
609 case STRRET_WSTR:
610 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
611 break;
613 case STRRET_OFFSET:
614 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
615 break;
617 case STRRET_CSTR:
618 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
623 static void free_strret(STRRET* str)
625 if (str->uType == STRRET_WSTR)
626 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
630 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
632 STRRET str;
634 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
636 if (SUCCEEDED(hr)) {
637 get_strret(&str, &pidl->mkid, buffer, len);
638 free_strret(&str);
639 } else
640 buffer[0] = '\0';
642 return hr;
646 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
648 STRRET str;
650 /* SHGDN_FORPARSING: get full path of id list */
651 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
653 if (SUCCEEDED(hr)) {
654 get_strretA(&str, &pidl->mkid, buffer, len);
655 free_strret(&str);
656 } else
657 buffer[0] = '\0';
659 return hr;
662 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
664 STRRET str;
666 /* SHGDN_FORPARSING: get full path of id list */
667 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
669 if (SUCCEEDED(hr)) {
670 get_strretW(&str, &pidl->mkid, buffer, len);
671 free_strret(&str);
672 } else
673 buffer[0] = '\0';
675 return hr;
679 /* create an item id list from a file system path */
681 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
683 LPITEMIDLIST pidl;
684 HRESULT hr;
685 ULONG len;
687 #ifdef UNICODE
688 LPWSTR buffer = path;
689 #else
690 WCHAR buffer[MAX_PATH];
691 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
692 #endif
694 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
695 if (FAILED(hr))
696 return NULL;
698 return pidl;
702 /* convert an item id list from relative to absolute (=relative to the desktop) format */
704 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
706 if (entry->up && entry->up->etype==ET_SHELL) {
707 IShellFolder* folder = entry->up->folder;
708 WCHAR buffer[MAX_PATH];
710 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
712 if (SUCCEEDED(hr)) {
713 LPITEMIDLIST pidl;
714 ULONG len;
716 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
718 if (SUCCEEDED(hr))
719 return pidl;
721 } else if (entry->etype == ET_WINDOWS) {
722 TCHAR path[MAX_PATH];
724 get_path(entry, path);
726 return get_path_pidl(path, hwnd);
727 } else if (entry->pidl)
728 return ILClone(entry->pidl);
730 return NULL;
734 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
736 IExtractIcon* pExtract;
738 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
739 TCHAR path[_MAX_PATH];
740 unsigned flags;
741 HICON hicon;
742 int idx;
744 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
745 if (!(flags & GIL_NOTFILENAME)) {
746 if (idx == -1)
747 idx = 0; /* special case for some control panel applications */
749 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
750 flags &= ~GIL_DONTCACHE;
751 } else {
752 HICON hIconLarge = 0;
754 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
756 if (SUCCEEDED(hr))
757 DestroyIcon(hIconLarge);
760 return hicon;
764 return 0;
768 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
770 Entry* entry;
772 for(entry=dir->down; entry; entry=entry->next) {
773 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
774 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
775 return entry;
778 return 0;
781 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
783 Entry* entry = &root->entry;
784 Entry* next;
785 LPITEMIDLIST next_pidl = pidl;
786 IShellFolder* folder;
787 IShellFolder* child = NULL;
788 HRESULT hr;
790 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
792 #ifndef _NO_EXTENSIONS
793 entry->etype = ET_SHELL;
794 #endif
796 folder = Globals.iDesktop;
798 while(entry) {
799 entry->pidl = next_pidl;
800 entry->folder = folder;
802 if (!pidl->mkid.cb)
803 break;
805 /* copy first element of item idlist */
806 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
807 memcpy(next_pidl, pidl, pidl->mkid.cb);
808 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
810 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
811 if (!SUCCEEDED(hr))
812 break;
814 read_directory(entry, NULL, sortOrder, hwnd);
816 if (entry->down)
817 entry->expanded = TRUE;
819 next = find_entry_shell(entry, next_pidl);
820 if (!next)
821 break;
823 folder = child;
824 entry = next;
826 /* go to next element */
827 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
830 SetCursor(old_cursor);
832 return entry;
836 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
838 if (!(attribs & SFGAO_FILESYSTEM) ||
839 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
840 WIN32_FILE_ATTRIBUTE_DATA fad;
841 IDataObject* pDataObj;
843 STGMEDIUM medium = {0, {0}, 0};
844 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
846 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
848 if (SUCCEEDED(hr)) {
849 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
851 (*pDataObj->lpVtbl->Release)(pDataObj);
853 if (SUCCEEDED(hr)) {
854 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
855 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
857 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
858 w32fdata->dwFileAttributes = fad.dwFileAttributes;
859 w32fdata->ftCreationTime = fad.ftCreationTime;
860 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
861 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
863 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
864 w32fdata->nFileSizeLow = fad.nFileSizeLow;
865 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
869 SetErrorMode(sem_org);
871 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
872 GlobalFree(medium.UNION_MEMBER(hGlobal));
877 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
878 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
880 if (attribs & SFGAO_READONLY)
881 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
883 if (attribs & SFGAO_COMPRESSED)
884 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
888 static void read_directory_shell(Entry* dir, HWND hwnd)
890 IShellFolder* folder = dir->folder;
891 int level = dir->level + 1;
892 HRESULT hr;
894 IShellFolder* child;
895 IEnumIDList* idlist;
897 Entry* first_entry = NULL;
898 Entry* last = NULL;
899 Entry* entry;
901 if (!folder)
902 return;
904 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
906 if (SUCCEEDED(hr)) {
907 for(;;) {
908 #define FETCH_ITEM_COUNT 32
909 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
910 SFGAOF attribs;
911 ULONG cnt = 0;
912 ULONG n;
914 memset(pidls, 0, sizeof(pidls));
916 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
917 if (!SUCCEEDED(hr))
918 break;
920 if (hr == S_FALSE)
921 break;
923 for(n=0; n<cnt; ++n) {
924 entry = alloc_entry();
926 if (!first_entry)
927 first_entry = entry;
929 if (last)
930 last->next = entry;
932 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
933 entry->bhfi_valid = FALSE;
935 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
937 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
939 if (SUCCEEDED(hr)) {
940 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
941 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
943 entry->bhfi_valid = TRUE;
944 } else
945 attribs = 0;
946 } else
947 attribs = 0;
949 entry->pidl = pidls[n];
951 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
952 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
954 if (SUCCEEDED(hr))
955 entry->folder = child;
956 else
957 entry->folder = NULL;
959 else
960 entry->folder = NULL;
962 if (!entry->data.cFileName[0])
963 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
965 /* get display icons for files and virtual objects */
966 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
967 !(attribs & SFGAO_FILESYSTEM)) {
968 entry->hicon = extract_icon(folder, pidls[n]);
970 if (!entry->hicon)
971 entry->hicon = (HICON)-1; /* don't try again later */
974 entry->down = NULL;
975 entry->up = dir;
976 entry->expanded = FALSE;
977 entry->scanned = FALSE;
978 entry->level = level;
980 #ifndef _NO_EXTENSIONS
981 entry->etype = ET_SHELL;
982 entry->bhfi_valid = FALSE;
983 #endif
985 last = entry;
989 (*idlist->lpVtbl->Release)(idlist);
992 if (last)
993 last->next = NULL;
995 dir->down = first_entry;
996 dir->scanned = TRUE;
999 #endif /* _SHELL_FOLDERS */
1002 /* sort order for different directory/file types */
1003 enum TYPE_ORDER {
1004 TO_DIR = 0,
1005 TO_DOT = 1,
1006 TO_DOTDOT = 2,
1007 TO_OTHER_DIR = 3,
1008 TO_FILE = 4
1011 /* distinguish between ".", ".." and any other directory names */
1012 static int TypeOrderFromDirname(LPCTSTR name)
1014 if (name[0] == '.') {
1015 if (name[1] == '\0')
1016 return TO_DOT; /* "." */
1018 if (name[1]=='.' && name[2]=='\0')
1019 return TO_DOTDOT; /* ".." */
1022 return TO_OTHER_DIR; /* anything else */
1025 /* directories first... */
1026 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1028 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1029 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1031 /* Handle "." and ".." as special case and move them at the very first beginning. */
1032 if (order1==TO_DIR && order2==TO_DIR) {
1033 order1 = TypeOrderFromDirname(fd1->cFileName);
1034 order2 = TypeOrderFromDirname(fd2->cFileName);
1037 return order2==order1? 0: order1<order2? -1: 1;
1041 static int compareName(const void* arg1, const void* arg2)
1043 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1044 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1046 int cmp = compareType(fd1, fd2);
1047 if (cmp)
1048 return cmp;
1050 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1053 static int compareExt(const void* arg1, const void* arg2)
1055 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1056 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1057 const TCHAR *name1, *name2, *ext1, *ext2;
1059 int cmp = compareType(fd1, fd2);
1060 if (cmp)
1061 return cmp;
1063 name1 = fd1->cFileName;
1064 name2 = fd2->cFileName;
1066 ext1 = _tcsrchr(name1, TEXT('.'));
1067 ext2 = _tcsrchr(name2, TEXT('.'));
1069 if (ext1)
1070 ext1++;
1071 else
1072 ext1 = TEXT("");
1074 if (ext2)
1075 ext2++;
1076 else
1077 ext2 = TEXT("");
1079 cmp = lstrcmpi(ext1, ext2);
1080 if (cmp)
1081 return cmp;
1083 return lstrcmpi(name1, name2);
1086 static int compareSize(const void* arg1, const void* arg2)
1088 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1089 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1091 int cmp = compareType(fd1, fd2);
1092 if (cmp)
1093 return cmp;
1095 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1097 if (cmp < 0)
1098 return -1;
1099 else if (cmp > 0)
1100 return 1;
1102 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1104 return cmp<0? -1: cmp>0? 1: 0;
1107 static int compareDate(const void* arg1, const void* arg2)
1109 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1110 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1112 int cmp = compareType(fd1, fd2);
1113 if (cmp)
1114 return cmp;
1116 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1120 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1121 compareName, /* SORT_NAME */
1122 compareExt, /* SORT_EXT */
1123 compareSize, /* SORT_SIZE */
1124 compareDate /* SORT_DATE */
1128 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1130 Entry* entry = dir->down;
1131 Entry** array, **p;
1132 int len;
1134 len = 0;
1135 for(entry=dir->down; entry; entry=entry->next)
1136 len++;
1138 if (len) {
1139 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1141 p = array;
1142 for(entry=dir->down; entry; entry=entry->next)
1143 *p++ = entry;
1145 /* call qsort with the appropriate compare function */
1146 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1148 dir->down = array[0];
1150 for(p=array; --len; p++)
1151 p[0]->next = p[1];
1153 (*p)->next = 0;
1154 HeapFree( GetProcessHeap(), 0, array );
1159 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1161 TCHAR buffer[MAX_PATH];
1162 Entry* entry;
1163 LPCTSTR s;
1164 PTSTR d;
1166 #ifdef _SHELL_FOLDERS
1167 if (dir->etype == ET_SHELL)
1169 read_directory_shell(dir, hwnd);
1171 if (Globals.prescan_node) {
1172 s = path;
1173 d = buffer;
1175 while(*s)
1176 *d++ = *s++;
1178 *d++ = TEXT('\\');
1180 for(entry=dir->down; entry; entry=entry->next)
1181 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1182 read_directory_shell(entry, hwnd);
1183 SortDirectory(entry, sortOrder);
1187 else
1188 #endif
1189 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1190 if (dir->etype == ET_UNIX)
1192 read_directory_unix(dir, path);
1194 if (Globals.prescan_node) {
1195 s = path;
1196 d = buffer;
1198 while(*s)
1199 *d++ = *s++;
1201 *d++ = TEXT('/');
1203 for(entry=dir->down; entry; entry=entry->next)
1204 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1205 lstrcpy(d, entry->data.cFileName);
1206 read_directory_unix(entry, buffer);
1207 SortDirectory(entry, sortOrder);
1211 else
1212 #endif
1214 read_directory_win(dir, path);
1216 if (Globals.prescan_node) {
1217 s = path;
1218 d = buffer;
1220 while(*s)
1221 *d++ = *s++;
1223 *d++ = TEXT('\\');
1225 for(entry=dir->down; entry; entry=entry->next)
1226 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1227 lstrcpy(d, entry->data.cFileName);
1228 read_directory_win(entry, buffer);
1229 SortDirectory(entry, sortOrder);
1234 SortDirectory(dir, sortOrder);
1238 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1240 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1241 TCHAR b1[BUFFER_LEN];
1243 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1244 Root* root = &child->root;
1245 Entry* entry;
1247 memset(child, 0, sizeof(ChildWnd));
1249 child->left.treePane = TRUE;
1250 child->left.visible_cols = 0;
1252 child->right.treePane = FALSE;
1253 #ifndef _NO_EXTENSIONS
1254 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1255 #else
1256 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1257 #endif
1259 child->pos.length = sizeof(WINDOWPLACEMENT);
1260 child->pos.flags = 0;
1261 child->pos.showCmd = SW_SHOWNORMAL;
1262 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1263 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1264 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1265 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1267 child->focus_pane = 0;
1268 child->split_pos = DEFAULT_SPLIT_POS;
1269 child->sortOrder = SORT_NAME;
1270 child->header_wdths_ok = FALSE;
1272 if (path)
1274 lstrcpy(child->path, path);
1276 _tsplitpath(path, drv, dir, name, ext);
1279 root->entry.level = 0;
1281 #ifdef _SHELL_FOLDERS
1282 if (pidl)
1284 root->drive_type = DRIVE_UNKNOWN;
1285 lstrcpy(drv, TEXT("\\"));
1286 lstrcpy(root->volname, TEXT("Desktop"));
1287 root->fs_flags = 0;
1288 lstrcpy(root->fs, TEXT("Shell"));
1290 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1292 else
1293 #endif
1294 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1295 if (*path == '/')
1297 root->drive_type = GetDriveType(path);
1299 lstrcat(drv, TEXT("/"));
1300 lstrcpy(root->volname, TEXT("root fs"));
1301 root->fs_flags = 0;
1302 lstrcpy(root->fs, TEXT("unixfs"));
1304 lstrcpy(root->path, TEXT("/"));
1305 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1307 else
1308 #endif
1310 root->drive_type = GetDriveType(path);
1312 lstrcat(drv, TEXT("\\"));
1313 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1315 lstrcpy(root->path, drv);
1316 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1319 #ifdef _SHELL_FOLDERS
1320 if (root->entry.etype == ET_SHELL)
1321 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1322 else
1323 #endif
1324 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1326 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1328 child->left.root = &root->entry;
1329 child->right.root = NULL;
1331 set_curdir(child, entry, hwnd);
1333 return child;
1337 /* free all memory associated with a child window */
1338 static void free_child_window(ChildWnd* child)
1340 free_entries(&child->root.entry);
1341 free(child);
1345 /* get full path of specified directory entry */
1346 static void get_path(Entry* dir, PTSTR path)
1348 Entry* entry;
1349 int len = 0;
1350 int level = 0;
1352 #ifdef _SHELL_FOLDERS
1353 if (dir->etype == ET_SHELL)
1355 SFGAOF attribs;
1356 HRESULT hr = S_OK;
1358 path[0] = TEXT('\0');
1360 attribs = 0;
1362 if (dir->folder)
1363 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1365 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1366 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1368 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1371 else
1372 #endif
1374 for(entry=dir; entry; level++) {
1375 LPCTSTR name;
1376 int l;
1379 LPCTSTR s;
1380 name = entry->data.cFileName;
1381 s = name;
1383 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1384 l++;
1387 if (entry->up) {
1388 if (l > 0) {
1389 memmove(path+l+1, path, len*sizeof(TCHAR));
1390 memcpy(path+1, name, l*sizeof(TCHAR));
1391 len += l+1;
1393 #ifndef _NO_EXTENSIONS
1394 if (entry->etype == ET_UNIX)
1395 path[0] = TEXT('/');
1396 else
1397 #endif
1398 path[0] = TEXT('\\');
1401 entry = entry->up;
1402 } else {
1403 memmove(path+l, path, len*sizeof(TCHAR));
1404 memcpy(path, name, l*sizeof(TCHAR));
1405 len += l;
1406 break;
1410 if (!level) {
1411 #ifndef _NO_EXTENSIONS
1412 if (entry->etype == ET_UNIX)
1413 path[len++] = TEXT('/');
1414 else
1415 #endif
1416 path[len++] = TEXT('\\');
1419 path[len] = TEXT('\0');
1424 static void resize_frame_rect(HWND hwnd, PRECT prect)
1426 int new_top;
1427 RECT rt;
1429 if (IsWindowVisible(Globals.htoolbar)) {
1430 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1431 GetClientRect(Globals.htoolbar, &rt);
1432 prect->top = rt.bottom+3;
1433 prect->bottom -= rt.bottom+3;
1436 if (IsWindowVisible(Globals.hdrivebar)) {
1437 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1438 GetClientRect(Globals.hdrivebar, &rt);
1439 new_top = --prect->top + rt.bottom+3;
1440 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1441 prect->top = new_top;
1442 prect->bottom -= rt.bottom+2;
1445 if (IsWindowVisible(Globals.hstatusbar)) {
1446 int parts[] = {300, 500};
1448 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1449 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1450 GetClientRect(Globals.hstatusbar, &rt);
1451 prect->bottom -= rt.bottom;
1454 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1457 static void resize_frame(HWND hwnd, int cx, int cy)
1459 RECT rect;
1461 rect.left = 0;
1462 rect.top = 0;
1463 rect.right = cx;
1464 rect.bottom = cy;
1466 resize_frame_rect(hwnd, &rect);
1469 static void resize_frame_client(HWND hwnd)
1471 RECT rect;
1473 GetClientRect(hwnd, &rect);
1475 resize_frame_rect(hwnd, &rect);
1479 static HHOOK hcbthook;
1480 static ChildWnd* newchild = NULL;
1482 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1484 if (code==HCBT_CREATEWND && newchild) {
1485 ChildWnd* child = newchild;
1486 newchild = NULL;
1488 child->hwnd = (HWND) wparam;
1489 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1492 return CallNextHookEx(hcbthook, code, wparam, lparam);
1495 static HWND create_child_window(ChildWnd* child)
1497 MDICREATESTRUCT mcs;
1498 int idx;
1500 mcs.szClass = WINEFILETREE;
1501 mcs.szTitle = (LPTSTR)child->path;
1502 mcs.hOwner = Globals.hInstance;
1503 mcs.x = child->pos.rcNormalPosition.left;
1504 mcs.y = child->pos.rcNormalPosition.top;
1505 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1506 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1507 mcs.style = 0;
1508 mcs.lParam = 0;
1510 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1512 newchild = child;
1513 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1514 if (!child->hwnd) {
1515 UnhookWindowsHookEx(hcbthook);
1516 return 0;
1519 UnhookWindowsHookEx(hcbthook);
1521 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1522 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1523 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1524 ListBox_SetCurSel(child->left.hwnd, idx);
1526 return child->hwnd;
1530 struct ExecuteDialog {
1531 TCHAR cmd[MAX_PATH];
1532 int cmdshow;
1536 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1538 static struct ExecuteDialog* dlg;
1540 switch(nmsg) {
1541 case WM_INITDIALOG:
1542 dlg = (struct ExecuteDialog*) lparam;
1543 return 1;
1545 case WM_COMMAND: {
1546 int id = (int)wparam;
1548 if (id == IDOK) {
1549 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1550 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1551 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1552 EndDialog(hwnd, id);
1553 } else if (id == IDCANCEL)
1554 EndDialog(hwnd, id);
1556 return 1;}
1559 return 0;
1562 static BOOL CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1564 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1566 switch(nmsg) {
1567 case WM_INITDIALOG:
1568 SetWindowLong(hwnd, GWL_USERDATA, lparam);
1569 return 1;
1571 case WM_COMMAND: {
1572 int id = (int)wparam;
1574 switch(id) {
1575 case IDOK: {
1576 LPTSTR dest = (LPTSTR) GetWindowLong(hwnd, GWL_USERDATA);
1577 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1578 EndDialog(hwnd, id);
1579 break;}
1581 case IDCANCEL:
1582 EndDialog(hwnd, id);
1583 break;
1585 case 254:
1586 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1587 break;
1590 return 1;
1594 return 0;
1598 #ifndef _NO_EXTENSIONS
1600 static struct FullScreenParameters {
1601 BOOL mode;
1602 RECT orgPos;
1603 BOOL wasZoomed;
1604 } g_fullscreen = {
1605 FALSE, /* mode */
1606 {0, 0, 0, 0},
1607 FALSE
1610 void frame_get_clientspace(HWND hwnd, PRECT prect)
1612 RECT rt;
1614 if (!IsIconic(hwnd))
1615 GetClientRect(hwnd, prect);
1616 else {
1617 WINDOWPLACEMENT wp;
1619 GetWindowPlacement(hwnd, &wp);
1621 prect->left = prect->top = 0;
1622 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1623 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1624 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1625 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1626 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1629 if (IsWindowVisible(Globals.htoolbar)) {
1630 GetClientRect(Globals.htoolbar, &rt);
1631 prect->top += rt.bottom+2;
1634 if (IsWindowVisible(Globals.hdrivebar)) {
1635 GetClientRect(Globals.hdrivebar, &rt);
1636 prect->top += rt.bottom+2;
1639 if (IsWindowVisible(Globals.hstatusbar)) {
1640 GetClientRect(Globals.hstatusbar, &rt);
1641 prect->bottom -= rt.bottom;
1645 static BOOL toggle_fullscreen(HWND hwnd)
1647 RECT rt;
1649 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1650 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1651 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1653 Frame_CalcFrameClient(hwnd, &rt);
1654 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1655 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1657 rt.left = g_fullscreen.orgPos.left-rt.left;
1658 rt.top = g_fullscreen.orgPos.top-rt.top;
1659 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1660 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1662 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1663 } else {
1664 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1665 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1666 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1668 if (g_fullscreen.wasZoomed)
1669 ShowWindow(hwnd, WS_MAXIMIZE);
1672 return g_fullscreen.mode;
1675 static void fullscreen_move(HWND hwnd)
1677 RECT rt, pos;
1678 GetWindowRect(hwnd, &pos);
1680 Frame_CalcFrameClient(hwnd, &rt);
1681 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1682 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1684 rt.left = pos.left-rt.left;
1685 rt.top = pos.top-rt.top;
1686 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1687 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1689 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1692 #endif
1695 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1697 BOOL vis = IsWindowVisible(hchild);
1699 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1701 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1703 #ifndef _NO_EXTENSIONS
1704 if (g_fullscreen.mode)
1705 fullscreen_move(hwnd);
1706 #endif
1708 resize_frame_client(hwnd);
1711 BOOL activate_drive_window(LPCTSTR path)
1713 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1714 HWND child_wnd;
1716 _tsplitpath(path, drv1, 0, 0, 0);
1718 /* search for a already open window for the same drive */
1719 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1720 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1722 if (child) {
1723 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1725 if (!lstrcmpi(drv2, drv1)) {
1726 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1728 if (IsMinimized(child_wnd))
1729 ShowWindow(child_wnd, SW_SHOWNORMAL);
1731 return TRUE;
1736 return FALSE;
1739 BOOL activate_fs_window(LPCTSTR filesys)
1741 HWND child_wnd;
1743 /* search for a already open window of the given file system name */
1744 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1745 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1747 if (child) {
1748 if (!lstrcmpi(child->root.fs, filesys)) {
1749 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1751 if (IsMinimized(child_wnd))
1752 ShowWindow(child_wnd, SW_SHOWNORMAL);
1754 return TRUE;
1759 return FALSE;
1762 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1764 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1766 switch(nmsg) {
1767 case WM_CLOSE:
1768 DestroyWindow(hwnd);
1770 /* clear handle variables */
1771 Globals.hMenuFrame = 0;
1772 Globals.hMenuView = 0;
1773 Globals.hMenuOptions = 0;
1774 Globals.hMainWnd = 0;
1775 Globals.hmdiclient = 0;
1776 Globals.hdrivebar = 0;
1777 break;
1779 case WM_DESTROY:
1780 /* don't exit desktop when closing file manager window */
1781 if (!Globals.hwndParent)
1782 PostQuitMessage(0);
1783 break;
1785 case WM_COMMAND: {
1786 UINT cmd = LOWORD(wparam);
1787 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1789 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1790 break;
1792 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1793 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1794 ChildWnd* child;
1795 LPCTSTR root = Globals.drives;
1796 int i;
1798 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1799 while(*root)
1800 root++;
1802 if (activate_drive_window(root))
1803 return 0;
1805 _tsplitpath(root, drv, 0, 0, 0);
1807 if (!SetCurrentDirectory(drv)) {
1808 display_error(hwnd, GetLastError());
1809 return 0;
1812 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1813 child = alloc_child_window(path, NULL, hwnd);
1815 if (!create_child_window(child))
1816 free(child);
1817 } else switch(cmd) {
1818 case ID_FILE_EXIT:
1819 SendMessage(hwnd, WM_CLOSE, 0, 0);
1820 break;
1822 case ID_WINDOW_NEW: {
1823 TCHAR path[MAX_PATH];
1824 ChildWnd* child;
1826 GetCurrentDirectory(MAX_PATH, path);
1827 child = alloc_child_window(path, NULL, hwnd);
1829 if (!create_child_window(child))
1830 free(child);
1831 break;}
1833 case ID_WINDOW_CASCADE:
1834 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1835 break;
1837 case ID_WINDOW_TILE_HORZ:
1838 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1839 break;
1841 case ID_WINDOW_TILE_VERT:
1842 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1843 break;
1845 case ID_WINDOW_ARRANGE:
1846 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1847 break;
1849 case ID_SELECT_FONT: {
1850 TCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
1851 CHOOSEFONT chFont;
1852 LOGFONT lFont;
1854 HDC hdc = GetDC(hwnd);
1855 chFont.lStructSize = sizeof(CHOOSEFONT);
1856 chFont.hwndOwner = hwnd;
1857 chFont.hDC = NULL;
1858 chFont.lpLogFont = &lFont;
1859 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
1860 chFont.rgbColors = RGB(0,0,0);
1861 chFont.lCustData = 0;
1862 chFont.lpfnHook = NULL;
1863 chFont.lpTemplateName = NULL;
1864 chFont.hInstance = Globals.hInstance;
1865 chFont.lpszStyle = NULL;
1866 chFont.nFontType = SIMULATED_FONTTYPE;
1867 chFont.nSizeMin = 0;
1868 chFont.nSizeMax = 24;
1870 if (ChooseFont(&chFont)) {
1871 HWND childWnd;
1873 Globals.hfont = CreateFontIndirect(&lFont);
1874 SelectFont(hdc, Globals.hfont);
1875 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
1877 /* change font in all open child windows */
1878 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
1879 ChildWnd* child = (ChildWnd*) GetWindowLong(childWnd, GWL_USERDATA);
1880 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
1881 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
1882 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1883 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1884 InvalidateRect(child->left.hwnd, NULL, TRUE);
1885 InvalidateRect(child->right.hwnd, NULL, TRUE);
1888 else if (CommDlgExtendedError()) {
1889 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
1890 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
1891 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
1894 ReleaseDC(hwnd, hdc);
1895 break;
1898 case ID_VIEW_TOOL_BAR:
1899 toggle_child(hwnd, cmd, Globals.htoolbar);
1900 break;
1902 case ID_VIEW_DRIVE_BAR:
1903 toggle_child(hwnd, cmd, Globals.hdrivebar);
1904 break;
1906 case ID_VIEW_STATUSBAR:
1907 toggle_child(hwnd, cmd, Globals.hstatusbar);
1908 break;
1910 case ID_EXECUTE: {
1911 struct ExecuteDialog dlg;
1913 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1915 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1916 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1918 if ((int)hinst <= 32)
1919 display_error(hwnd, GetLastError());
1921 break;}
1923 case ID_HELP:
1924 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
1925 break;
1927 #ifndef _NO_EXTENSIONS
1928 case ID_VIEW_FULLSCREEN:
1929 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1930 break;
1932 #ifdef __WINE__
1933 case ID_DRIVE_UNIX_FS: {
1934 TCHAR path[MAX_PATH];
1935 ChildWnd* child;
1937 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
1938 break;
1940 getcwd(path, MAX_PATH);
1941 child = alloc_child_window(path, NULL, hwnd);
1943 if (!create_child_window(child))
1944 free(child);
1945 break;}
1946 #endif
1947 #ifdef _SHELL_FOLDERS
1948 case ID_DRIVE_SHELL_NS: {
1949 TCHAR path[MAX_PATH];
1950 ChildWnd* child;
1952 if (activate_fs_window(RS(b1,IDS_SHELL)))
1953 break;
1955 GetCurrentDirectory(MAX_PATH, path);
1956 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1958 if (!create_child_window(child))
1959 free(child);
1960 break;}
1961 #endif
1962 #endif
1964 /*TODO: There are even more menu items! */
1966 #ifndef _NO_EXTENSIONS
1967 #ifdef __WINE__
1968 case ID_LICENSE:
1969 WineLicense(Globals.hMainWnd);
1970 break;
1972 case ID_NO_WARRANTY:
1973 WineWarranty(Globals.hMainWnd);
1974 break;
1975 #endif
1977 case ID_ABOUT_WINE:
1978 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
1979 break;
1981 case ID_ABOUT: /*ID_ABOUT_WINE: */
1982 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
1983 break;
1984 #endif /* _NO_EXTENSIONS */
1986 default:
1987 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1988 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1989 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1990 (cmd<SC_SIZE || cmd>SC_RESTORE))
1991 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
1993 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1995 break;}
1997 case WM_SIZE:
1998 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1999 break; /* do not pass message to DefFrameProc */
2001 #ifndef _NO_EXTENSIONS
2002 case WM_GETMINMAXINFO: {
2003 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2005 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2006 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2007 break;}
2009 case FRM_CALC_CLIENT:
2010 frame_get_clientspace(hwnd, (PRECT)lparam);
2011 return TRUE;
2012 #endif /* _NO_EXTENSIONS */
2014 default:
2015 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2018 return 0;
2022 static const LPTSTR g_pos_names[COLUMNS] = {
2023 TEXT(""), /* symbol */
2024 TEXT("Name"),
2025 TEXT("Size"),
2026 TEXT("CDate"),
2027 #ifndef _NO_EXTENSIONS
2028 TEXT("ADate"),
2029 TEXT("MDate"),
2030 TEXT("Index/Inode"),
2031 TEXT("Links"),
2032 #endif /* _NO_EXTENSIONS */
2033 TEXT("Attributes"),
2034 #ifndef _NO_EXTENSIONS
2035 TEXT("Security")
2036 #endif
2039 static const int g_pos_align[] = {
2041 HDF_LEFT, /* Name */
2042 HDF_RIGHT, /* Size */
2043 HDF_LEFT, /* CDate */
2044 #ifndef _NO_EXTENSIONS
2045 HDF_LEFT, /* ADate */
2046 HDF_LEFT, /* MDate */
2047 HDF_LEFT, /* Index */
2048 HDF_CENTER, /* Links */
2049 #endif
2050 HDF_CENTER, /* Attributes */
2051 #ifndef _NO_EXTENSIONS
2052 HDF_LEFT /* Security */
2053 #endif
2056 static void resize_tree(ChildWnd* child, int cx, int cy)
2058 HDWP hdwp = BeginDeferWindowPos(4);
2059 RECT rt;
2061 rt.left = 0;
2062 rt.top = 0;
2063 rt.right = cx;
2064 rt.bottom = cy;
2066 cx = child->split_pos + SPLIT_WIDTH/2;
2068 #ifndef _NO_EXTENSIONS
2070 WINDOWPOS wp;
2071 HD_LAYOUT hdl;
2073 hdl.prc = &rt;
2074 hdl.pwpos = &wp;
2076 Header_Layout(child->left.hwndHeader, &hdl);
2078 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2079 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2080 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2081 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2083 #endif /* _NO_EXTENSIONS */
2085 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);
2086 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2088 EndDeferWindowPos(hdwp);
2092 #ifndef _NO_EXTENSIONS
2094 static HWND create_header(HWND parent, Pane* pane, int id)
2096 HD_ITEM hdi;
2097 int idx;
2099 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2100 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2101 if (!hwnd)
2102 return 0;
2104 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2106 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2108 for(idx=0; idx<COLUMNS; idx++) {
2109 hdi.pszText = g_pos_names[idx];
2110 hdi.fmt = HDF_STRING | g_pos_align[idx];
2111 hdi.cxy = pane->widths[idx];
2112 Header_InsertItem(hwnd, idx, &hdi);
2115 return hwnd;
2118 #endif /* _NO_EXTENSIONS */
2121 static void init_output(HWND hwnd)
2123 TCHAR b[16];
2124 HFONT old_font;
2125 HDC hdc = GetDC(hwnd);
2127 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
2128 Globals.num_sep = b[1];
2129 else
2130 Globals.num_sep = TEXT('.');
2132 old_font = SelectFont(hdc, Globals.hfont);
2133 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
2134 SelectFont(hdc, old_font);
2135 ReleaseDC(hwnd, hdc);
2138 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2141 /* calculate prefered width for all visible columns */
2143 static BOOL calc_widths(Pane* pane, BOOL anyway)
2145 int col, x, cx, spc=3*Globals.spaceSize.cx;
2146 int entries = ListBox_GetCount(pane->hwnd);
2147 int orgWidths[COLUMNS];
2148 int orgPositions[COLUMNS+1];
2149 HFONT hfontOld;
2150 HDC hdc;
2151 int cnt;
2153 if (!anyway) {
2154 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2155 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2158 for(col=0; col<COLUMNS; col++)
2159 pane->widths[col] = 0;
2161 hdc = GetDC(pane->hwnd);
2162 hfontOld = SelectFont(hdc, Globals.hfont);
2164 for(cnt=0; cnt<entries; cnt++) {
2165 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2167 DRAWITEMSTRUCT dis;
2169 dis.CtlType = 0;
2170 dis.CtlID = 0;
2171 dis.itemID = 0;
2172 dis.itemAction = 0;
2173 dis.itemState = 0;
2174 dis.hwndItem = pane->hwnd;
2175 dis.hDC = hdc;
2176 dis.rcItem.left = 0;
2177 dis.rcItem.top = 0;
2178 dis.rcItem.right = 0;
2179 dis.rcItem.bottom = 0;
2180 /*dis.itemData = 0; */
2182 draw_item(pane, &dis, entry, COLUMNS);
2185 SelectObject(hdc, hfontOld);
2186 ReleaseDC(pane->hwnd, hdc);
2188 x = 0;
2189 for(col=0; col<COLUMNS; col++) {
2190 pane->positions[col] = x;
2191 cx = pane->widths[col];
2193 if (cx) {
2194 cx += spc;
2196 if (cx < IMAGE_WIDTH)
2197 cx = IMAGE_WIDTH;
2199 pane->widths[col] = cx;
2202 x += cx;
2205 pane->positions[COLUMNS] = x;
2207 ListBox_SetHorizontalExtent(pane->hwnd, x);
2209 /* no change? */
2210 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2211 return FALSE;
2213 /* don't move, if only collapsing an entry */
2214 if (!anyway && pane->widths[0]<orgWidths[0] &&
2215 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2216 pane->widths[0] = orgWidths[0];
2217 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2219 return FALSE;
2222 InvalidateRect(pane->hwnd, 0, TRUE);
2224 return TRUE;
2228 /* calculate one prefered column width */
2230 static void calc_single_width(Pane* pane, int col)
2232 HFONT hfontOld;
2233 int x, cx;
2234 int entries = ListBox_GetCount(pane->hwnd);
2235 int cnt;
2236 HDC hdc;
2238 pane->widths[col] = 0;
2240 hdc = GetDC(pane->hwnd);
2241 hfontOld = SelectFont(hdc, Globals.hfont);
2243 for(cnt=0; cnt<entries; cnt++) {
2244 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2245 DRAWITEMSTRUCT dis;
2247 dis.CtlType = 0;
2248 dis.CtlID = 0;
2249 dis.itemID = 0;
2250 dis.itemAction = 0;
2251 dis.itemState = 0;
2252 dis.hwndItem = pane->hwnd;
2253 dis.hDC = hdc;
2254 dis.rcItem.left = 0;
2255 dis.rcItem.top = 0;
2256 dis.rcItem.right = 0;
2257 dis.rcItem.bottom = 0;
2258 /*dis.itemData = 0; */
2260 draw_item(pane, &dis, entry, col);
2263 SelectObject(hdc, hfontOld);
2264 ReleaseDC(pane->hwnd, hdc);
2266 cx = pane->widths[col];
2268 if (cx) {
2269 cx += 3*Globals.spaceSize.cx;
2271 if (cx < IMAGE_WIDTH)
2272 cx = IMAGE_WIDTH;
2275 pane->widths[col] = cx;
2277 x = pane->positions[col] + cx;
2279 for(; col<COLUMNS; ) {
2280 pane->positions[++col] = x;
2281 x += pane->widths[col];
2284 ListBox_SetHorizontalExtent(pane->hwnd, x);
2288 /* insert listbox entries after index idx */
2290 static void insert_entries(Pane* pane, Entry* dir, int idx)
2292 Entry* entry = dir;
2294 if (!entry)
2295 return;
2297 ShowWindow(pane->hwnd, SW_HIDE);
2299 for(; entry; entry=entry->next) {
2300 #ifndef _LEFT_FILES
2301 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2302 continue;
2303 #endif
2305 /* don't display entries "." and ".." in the left pane */
2306 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2307 && entry->data.cFileName[0]==TEXT('.'))
2308 if (
2309 #ifndef _NO_EXTENSIONS
2310 entry->data.cFileName[1]==TEXT('\0') ||
2311 #endif
2312 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2313 continue;
2315 if (idx != -1)
2316 idx++;
2318 ListBox_InsertItemData(pane->hwnd, idx, entry);
2320 if (pane->treePane && entry->expanded)
2321 insert_entries(pane, entry->down, idx);
2324 ShowWindow(pane->hwnd, SW_SHOW);
2328 static WNDPROC g_orgTreeWndProc;
2330 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2332 static int s_init = 0;
2333 Entry* entry = pane->root;
2335 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2336 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2337 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2339 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2340 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2342 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2344 /* insert entries into listbox */
2345 if (entry)
2346 insert_entries(pane, entry, -1);
2348 /* calculate column widths */
2349 if (!s_init) {
2350 s_init = 1;
2351 init_output(pane->hwnd);
2354 calc_widths(pane, TRUE);
2356 #ifndef _NO_EXTENSIONS
2357 pane->hwndHeader = create_header(parent, pane, id_header);
2358 #endif
2362 static void InitChildWindow(ChildWnd* child)
2364 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2365 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2369 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2371 SYSTEMTIME systime;
2372 FILETIME lft;
2373 int len = 0;
2375 *buffer = TEXT('\0');
2377 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2378 return;
2380 if (!FileTimeToLocalFileTime(ft, &lft))
2381 {err: _tcscpy(buffer,TEXT("???")); return;}
2383 if (!FileTimeToSystemTime(&lft, &systime))
2384 goto err;
2386 if (visible_cols & COL_DATE) {
2387 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2388 if (!len)
2389 goto err;
2392 if (visible_cols & COL_TIME) {
2393 if (len)
2394 buffer[len-1] = ' ';
2396 buffer[len++] = ' ';
2398 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2399 buffer[len] = TEXT('\0');
2404 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2406 RECT rt = {0, 0, 0, 0};
2408 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2410 if (rt.right > pane->widths[col])
2411 pane->widths[col] = rt.right;
2414 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2416 RECT rt = {0, 0, 0, 0};
2418 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2419 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2421 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2422 /*FIXME rt (0,0) ??? */
2424 if (rt.right > pane->widths[col])
2425 pane->widths[col] = rt.right;
2429 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2431 int x = dis->rcItem.left;
2432 RECT rt;
2434 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2435 rt.top = dis->rcItem.top;
2436 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2437 rt.bottom = dis->rcItem.bottom;
2439 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2442 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2444 int x = dis->rcItem.left;
2445 RECT rt;
2447 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2448 rt.top = dis->rcItem.top;
2449 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2450 rt.bottom = dis->rcItem.bottom;
2452 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2453 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2455 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2458 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2460 int x = dis->rcItem.left;
2461 RECT rt;
2462 LPCTSTR s = str;
2463 TCHAR b[128];
2464 LPTSTR d = b;
2465 int pos;
2467 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2468 rt.top = dis->rcItem.top;
2469 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2470 rt.bottom = dis->rcItem.bottom;
2472 if (*s)
2473 *d++ = *s++;
2475 /* insert number separator characters */
2476 pos = lstrlen(s) % 3;
2478 while(*s)
2479 if (pos--)
2480 *d++ = *s++;
2481 else {
2482 *d++ = Globals.num_sep;
2483 pos = 3;
2486 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2490 static int is_exe_file(LPCTSTR ext)
2492 static const LPCTSTR executable_extensions[] = {
2493 TEXT("COM"),
2494 TEXT("EXE"),
2495 TEXT("BAT"),
2496 TEXT("CMD"),
2497 #ifndef _NO_EXTENSIONS
2498 TEXT("CMM"),
2499 TEXT("BTM"),
2500 TEXT("AWK"),
2501 #endif /* _NO_EXTENSIONS */
2505 TCHAR ext_buffer[_MAX_EXT];
2506 const LPCTSTR* p;
2507 LPCTSTR s;
2508 LPTSTR d;
2510 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2511 d++;
2513 for(p=executable_extensions; *p; p++)
2514 if (!_tcscmp(ext_buffer, *p))
2515 return 1;
2517 return 0;
2520 static int is_registered_type(LPCTSTR ext)
2522 /* TODO */
2524 return 1;
2528 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2530 TCHAR buffer[BUFFER_LEN];
2531 DWORD attrs;
2532 int visible_cols = pane->visible_cols;
2533 COLORREF bkcolor, textcolor;
2534 RECT focusRect = dis->rcItem;
2535 HBRUSH hbrush;
2536 enum IMAGE img;
2537 int img_pos, cx;
2538 int col = 0;
2540 if (entry) {
2541 attrs = entry->data.dwFileAttributes;
2543 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2544 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2545 && entry->data.cFileName[2]==TEXT('\0'))
2546 img = IMG_FOLDER_UP;
2547 #ifndef _NO_EXTENSIONS
2548 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2549 img = IMG_FOLDER_CUR;
2550 #endif
2551 else if (
2552 #ifdef _NO_EXTENSIONS
2553 entry->expanded ||
2554 #endif
2555 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2556 img = IMG_OPEN_FOLDER;
2557 else
2558 img = IMG_FOLDER;
2559 } else {
2560 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2561 if (!ext)
2562 ext = TEXT("");
2564 if (is_exe_file(ext))
2565 img = IMG_EXECUTABLE;
2566 else if (is_registered_type(ext))
2567 img = IMG_DOCUMENT;
2568 else
2569 img = IMG_FILE;
2571 } else {
2572 attrs = 0;
2573 img = IMG_NONE;
2576 if (pane->treePane) {
2577 if (entry) {
2578 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
2580 if (calcWidthCol == -1) {
2581 int x;
2582 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2583 Entry* up;
2584 RECT rt_clip;
2585 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2586 HRGN hrgn;
2588 rt_clip.left = dis->rcItem.left;
2589 rt_clip.top = dis->rcItem.top;
2590 rt_clip.right = dis->rcItem.left+pane->widths[col];
2591 rt_clip.bottom = dis->rcItem.bottom;
2593 hrgn = CreateRectRgnIndirect(&rt_clip);
2595 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2596 DeleteObject(hrgn_org);
2597 hrgn_org = 0;
2600 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2601 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2602 DeleteObject(hrgn);
2604 if ((up=entry->up) != NULL) {
2605 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2606 LineTo(dis->hDC, img_pos-2, y);
2608 x = img_pos - IMAGE_WIDTH/2;
2610 do {
2611 x -= IMAGE_WIDTH+TREE_LINE_DX;
2613 if (up->next
2614 #ifndef _LEFT_FILES
2615 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2616 #endif
2618 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2619 LineTo(dis->hDC, x, dis->rcItem.bottom);
2621 } while((up=up->up) != NULL);
2624 x = img_pos - IMAGE_WIDTH/2;
2626 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2627 LineTo(dis->hDC, x, y);
2629 if (entry->next
2630 #ifndef _LEFT_FILES
2631 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2632 #endif
2634 LineTo(dis->hDC, x, dis->rcItem.bottom);
2636 if (entry->down && entry->expanded) {
2637 x += IMAGE_WIDTH+TREE_LINE_DX;
2638 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT+2, 0);
2639 LineTo(dis->hDC, x, dis->rcItem.bottom);
2642 SelectClipRgn(dis->hDC, hrgn_org);
2643 if (hrgn_org) DeleteObject(hrgn_org);
2644 /* SelectObject(dis->hDC, holdPen); */
2645 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2646 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
2648 if (right > pane->widths[col])
2649 pane->widths[col] = right;
2651 } else {
2652 img_pos = dis->rcItem.left;
2654 } else {
2655 img_pos = dis->rcItem.left;
2657 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2658 pane->widths[col] = IMAGE_WIDTH;
2661 if (calcWidthCol == -1) {
2662 focusRect.left = img_pos -2;
2664 #ifdef _NO_EXTENSIONS
2665 if (pane->treePane && entry) {
2666 RECT rt = {0};
2668 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2670 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
2672 #else
2674 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2675 textcolor = COLOR_COMPRESSED;
2676 else
2677 #endif /* _NO_EXTENSIONS */
2678 textcolor = RGB(0,0,0);
2680 if (dis->itemState & ODS_FOCUS) {
2681 textcolor = RGB(255,255,255);
2682 bkcolor = COLOR_SELECTION;
2683 } else {
2684 bkcolor = RGB(255,255,255);
2687 hbrush = CreateSolidBrush(bkcolor);
2688 FillRect(dis->hDC, &focusRect, hbrush);
2689 DeleteObject(hbrush);
2691 SetBkMode(dis->hDC, TRANSPARENT);
2692 SetTextColor(dis->hDC, textcolor);
2694 cx = pane->widths[col];
2696 if (cx && img!=IMG_NONE) {
2698 if (cx > IMAGE_WIDTH)
2699 cx = IMAGE_WIDTH;
2701 #ifdef _SHELL_FOLDERS
2702 if (entry->hicon && entry->hicon!=(HICON)-1)
2703 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2704 else
2705 #endif
2706 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2707 img_pos, dis->rcItem.top, cx,
2708 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2712 if (!entry)
2713 return;
2715 #ifdef _NO_EXTENSIONS
2716 if (img >= IMG_FOLDER_UP)
2717 return;
2718 #endif
2720 col++;
2722 /* ouput file name */
2723 if (calcWidthCol == -1)
2724 output_text(pane, dis, col, entry->data.cFileName, 0);
2725 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2726 calc_width(pane, dis, col, entry->data.cFileName);
2728 col++;
2730 #ifdef _NO_EXTENSIONS
2731 if (!pane->treePane) {
2732 #endif
2734 /* display file size */
2735 if (visible_cols & COL_SIZE) {
2736 #ifdef _NO_EXTENSIONS
2737 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2738 #endif
2740 ULONGLONG size;
2742 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2744 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2746 if (calcWidthCol == -1)
2747 output_number(pane, dis, col, buffer);
2748 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2749 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2752 col++;
2755 /* display file date */
2756 if (visible_cols & (COL_DATE|COL_TIME)) {
2757 #ifndef _NO_EXTENSIONS
2758 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2759 if (calcWidthCol == -1)
2760 output_text(pane, dis, col, buffer, 0);
2761 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2762 calc_width(pane, dis, col, buffer);
2763 col++;
2765 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2766 if (calcWidthCol == -1)
2767 output_text(pane, dis, col, buffer, 0);
2768 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2769 calc_width(pane, dis, col, buffer);
2770 col++;
2771 #endif /* _NO_EXTENSIONS */
2773 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2774 if (calcWidthCol == -1)
2775 output_text(pane, dis, col, buffer, 0);
2776 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2777 calc_width(pane, dis, col, buffer);
2778 col++;
2781 #ifndef _NO_EXTENSIONS
2782 if (entry->bhfi_valid) {
2783 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2785 if (visible_cols & COL_INDEX) {
2786 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2787 if (calcWidthCol == -1)
2788 output_text(pane, dis, col, buffer, DT_RIGHT);
2789 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2790 calc_width(pane, dis, col, buffer);
2791 col++;
2794 if (visible_cols & COL_LINKS) {
2795 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2796 if (calcWidthCol == -1)
2797 output_text(pane, dis, col, buffer, DT_CENTER);
2798 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2799 calc_width(pane, dis, col, buffer);
2800 col++;
2802 } else
2803 col += 2;
2804 #endif /* _NO_EXTENSIONS */
2806 /* show file attributes */
2807 if (visible_cols & COL_ATTRIBUTES) {
2808 #ifdef _NO_EXTENSIONS
2809 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2810 #else
2811 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2812 #endif
2814 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2815 else {
2816 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2817 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2818 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2819 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2820 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2821 #ifndef _NO_EXTENSIONS
2822 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2823 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2824 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2825 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2826 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2827 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2828 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2829 #endif /* _NO_EXTENSIONS */
2832 if (calcWidthCol == -1)
2833 output_tabbed_text(pane, dis, col, buffer);
2834 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2835 calc_tabbed_width(pane, dis, col, buffer);
2837 col++;
2840 /*TODO
2841 if (flags.security) {
2842 DWORD rights = get_access_mask();
2844 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2846 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2847 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2848 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2849 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2850 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2851 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2852 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2853 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2854 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2855 if (rights & WRITE_DAC) buffer[22] = 'C';
2856 if (rights & WRITE_OWNER) buffer[24] = 'O';
2857 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2859 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2862 if (flags.description) {
2863 get_description(buffer);
2864 output_text(dis, col++, buffer, 0, psize);
2868 #ifdef _NO_EXTENSIONS
2871 /* draw focus frame */
2872 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2873 /* Currently [04/2000] Wine neither behaves exactly the same */
2874 /* way as WIN 95 nor like Windows NT... */
2875 HGDIOBJ lastBrush;
2876 HPEN lastPen;
2877 HPEN hpen;
2879 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2880 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2881 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2882 } else
2883 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2885 lastPen = SelectPen(dis->hDC, hpen);
2886 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2887 SetROP2(dis->hDC, R2_XORPEN);
2888 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2889 SelectObject(dis->hDC, lastBrush);
2890 SelectObject(dis->hDC, lastPen);
2891 DeleteObject(hpen);
2893 #endif /* _NO_EXTENSIONS */
2897 #ifdef _NO_EXTENSIONS
2899 static void draw_splitbar(HWND hwnd, int x)
2901 RECT rt;
2902 HDC hdc = GetDC(hwnd);
2904 GetClientRect(hwnd, &rt);
2906 rt.left = x - SPLIT_WIDTH/2;
2907 rt.right = x + SPLIT_WIDTH/2+1;
2909 InvertRect(hdc, &rt);
2911 ReleaseDC(hwnd, hdc);
2914 #endif /* _NO_EXTENSIONS */
2917 #ifndef _NO_EXTENSIONS
2919 static void set_header(Pane* pane)
2921 HD_ITEM item;
2922 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2923 int i=0, x=0;
2925 item.mask = HDI_WIDTH;
2926 item.cxy = 0;
2928 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2929 x += pane->widths[i];
2930 Header_SetItem(pane->hwndHeader, i, &item);
2933 if (i < COLUMNS) {
2934 x += pane->widths[i];
2935 item.cxy = x - scroll_pos;
2936 Header_SetItem(pane->hwndHeader, i++, &item);
2938 for(; i<COLUMNS; i++) {
2939 item.cxy = pane->widths[i];
2940 x += pane->widths[i];
2941 Header_SetItem(pane->hwndHeader, i, &item);
2946 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2948 switch(pnmh->code) {
2949 case HDN_TRACK:
2950 case HDN_ENDTRACK: {
2951 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2952 int idx = phdn->iItem;
2953 int dx = phdn->pitem->cxy - pane->widths[idx];
2954 int i;
2956 RECT clnt;
2957 GetClientRect(pane->hwnd, &clnt);
2959 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2960 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2962 pane->widths[idx] += dx;
2964 for(i=idx; ++i<=COLUMNS; )
2965 pane->positions[i] += dx;
2968 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2969 RECT rt_scr;
2970 RECT rt_clip;
2972 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2973 rt_scr.top = 0;
2974 rt_scr.right = clnt.right;
2975 rt_scr.bottom = clnt.bottom;
2977 rt_clip.left = pane->positions[idx]-scroll_pos;
2978 rt_clip.top = 0;
2979 rt_clip.right = clnt.right;
2980 rt_clip.bottom = clnt.bottom;
2982 if (rt_scr.left < 0) rt_scr.left = 0;
2983 if (rt_clip.left < 0) rt_clip.left = 0;
2985 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2987 rt_clip.right = pane->positions[idx+1];
2988 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2990 if (pnmh->code == HDN_ENDTRACK) {
2991 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2993 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2994 set_header(pane);
2998 return FALSE;
3001 case HDN_DIVIDERDBLCLICK: {
3002 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3003 HD_ITEM item;
3005 calc_single_width(pane, phdn->iItem);
3006 item.mask = HDI_WIDTH;
3007 item.cxy = pane->widths[phdn->iItem];
3009 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3010 InvalidateRect(pane->hwnd, 0, TRUE);
3011 break;}
3014 return 0;
3017 #endif /* _NO_EXTENSIONS */
3020 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
3022 TCHAR path[MAX_PATH];
3023 int idx = ListBox_GetCurSel(child->left.hwnd);
3024 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3026 /* delete sub entries in left pane */
3027 for(;;) {
3028 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3029 Entry* sub = (Entry*) res;
3031 if (res==LB_ERR || !sub || sub->level<=entry->level)
3032 break;
3034 ListBox_DeleteString(child->left.hwnd, idx+1);
3037 /* empty right pane */
3038 ListBox_ResetContent(child->right.hwnd);
3040 /* release memory */
3041 free_entries(entry);
3043 /* read contents from disk */
3044 #ifdef _SHELL_FOLDERS
3045 if (entry->etype == ET_SHELL)
3047 read_directory(entry, NULL, child->sortOrder, hwnd);
3049 else
3050 #endif
3052 get_path(entry, path);
3053 read_directory(entry, path, child->sortOrder, hwnd);
3056 /* insert found entries in right pane */
3057 insert_entries(&child->right, entry->down, -1);
3058 calc_widths(&child->right, FALSE);
3059 #ifndef _NO_EXTENSIONS
3060 set_header(&child->right);
3061 #endif
3063 child->header_wdths_ok = FALSE;
3065 SetCursor(old_cursor);
3069 /* expand a directory entry */
3071 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3073 int idx;
3074 Entry* p;
3076 if (!dir || dir->expanded || !dir->down)
3077 return FALSE;
3079 p = dir->down;
3081 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3082 p = p->next;
3084 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3085 p->data.cFileName[2]=='\0' && p->next)
3086 p = p->next;
3089 /* no subdirectories ? */
3090 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3091 return FALSE;
3093 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3095 dir->expanded = TRUE;
3097 /* insert entries in left pane */
3098 insert_entries(&child->left, p, idx);
3100 if (!child->header_wdths_ok) {
3101 if (calc_widths(&child->left, FALSE)) {
3102 #ifndef _NO_EXTENSIONS
3103 set_header(&child->left);
3104 #endif
3106 child->header_wdths_ok = TRUE;
3110 return TRUE;
3114 static void collapse_entry(Pane* pane, Entry* dir)
3116 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3118 ShowWindow(pane->hwnd, SW_HIDE);
3120 /* hide sub entries */
3121 for(;;) {
3122 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3123 Entry* sub = (Entry*) res;
3125 if (res==LB_ERR || !sub || sub->level<=dir->level)
3126 break;
3128 ListBox_DeleteString(pane->hwnd, idx+1);
3131 dir->expanded = FALSE;
3133 ShowWindow(pane->hwnd, SW_SHOW);
3137 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
3139 TCHAR path[MAX_PATH];
3141 path[0] = '\0';
3143 child->left.cur = entry;
3144 child->right.root = entry->down? entry->down: entry;
3145 child->right.cur = entry;
3147 if (!entry->scanned)
3148 scan_entry(child, entry, hwnd);
3149 else {
3150 ListBox_ResetContent(child->right.hwnd);
3151 insert_entries(&child->right, entry->down, -1);
3152 calc_widths(&child->right, FALSE);
3153 #ifndef _NO_EXTENSIONS
3154 set_header(&child->right);
3155 #endif
3158 get_path(entry, path);
3159 lstrcpy(child->path, path);
3161 if (child->hwnd) /* only change window title, if the window already exists */
3162 SetWindowText(child->hwnd, path);
3164 if (path[0])
3165 SetCurrentDirectory(path);
3169 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3171 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3173 if ((int)hinst <= 32) {
3174 display_error(hwnd, GetLastError());
3175 return FALSE;
3178 return TRUE;
3181 #ifdef UNICODE
3182 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3184 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3186 if ((int)hinst <= 32) {
3187 display_error(hwnd, GetLastError());
3188 return FALSE;
3191 return TRUE;
3193 #endif
3196 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3198 TCHAR cmd[MAX_PATH];
3200 #ifdef _SHELL_FOLDERS
3201 if (entry->etype == ET_SHELL) {
3202 BOOL ret = TRUE;
3204 SHELLEXECUTEINFO shexinfo;
3206 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3207 shexinfo.fMask = SEE_MASK_IDLIST;
3208 shexinfo.hwnd = hwnd;
3209 shexinfo.lpVerb = NULL;
3210 shexinfo.lpFile = NULL;
3211 shexinfo.lpParameters = NULL;
3212 shexinfo.lpDirectory = NULL;
3213 shexinfo.nShow = nCmdShow;
3214 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3216 if (!ShellExecuteEx(&shexinfo)) {
3217 display_error(hwnd, GetLastError());
3218 ret = FALSE;
3221 if (shexinfo.lpIDList != entry->pidl)
3222 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3224 return ret;
3226 #endif
3228 get_path(entry, cmd);
3230 /* start program, open document... */
3231 return launch_file(hwnd, cmd, nCmdShow);
3235 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3237 Entry* entry = pane->cur;
3239 if (!entry)
3240 return;
3242 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3243 int scanned_old = entry->scanned;
3245 if (!scanned_old)
3246 scan_entry(child, entry, hwnd);
3248 #ifndef _NO_EXTENSIONS
3249 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3250 return;
3251 #endif
3253 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3254 entry = child->left.cur->up;
3255 collapse_entry(&child->left, entry);
3256 goto focus_entry;
3257 } else if (entry->expanded)
3258 collapse_entry(pane, child->left.cur);
3259 else {
3260 expand_entry(child, child->left.cur);
3262 if (!pane->treePane) focus_entry: {
3263 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3264 ListBox_SetCurSel(child->left.hwnd, idx);
3265 set_curdir(child, entry, hwnd);
3269 if (!scanned_old) {
3270 calc_widths(pane, FALSE);
3272 #ifndef _NO_EXTENSIONS
3273 set_header(pane);
3274 #endif
3276 } else {
3277 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3282 static BOOL pane_command(Pane* pane, UINT cmd)
3284 switch(cmd) {
3285 case ID_VIEW_NAME:
3286 if (pane->visible_cols) {
3287 pane->visible_cols = 0;
3288 calc_widths(pane, TRUE);
3289 #ifndef _NO_EXTENSIONS
3290 set_header(pane);
3291 #endif
3292 InvalidateRect(pane->hwnd, 0, TRUE);
3293 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3294 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3295 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3297 break;
3299 case ID_VIEW_ALL_ATTRIBUTES:
3300 if (pane->visible_cols != COL_ALL) {
3301 pane->visible_cols = COL_ALL;
3302 calc_widths(pane, TRUE);
3303 #ifndef _NO_EXTENSIONS
3304 set_header(pane);
3305 #endif
3306 InvalidateRect(pane->hwnd, 0, TRUE);
3307 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3308 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3309 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3311 break;
3313 #ifndef _NO_EXTENSIONS
3314 case ID_PREFERED_SIZES: {
3315 calc_widths(pane, TRUE);
3316 set_header(pane);
3317 InvalidateRect(pane->hwnd, 0, TRUE);
3318 break;}
3319 #endif
3321 /* TODO: more command ids... */
3323 default:
3324 return FALSE;
3327 return TRUE;
3331 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3333 IContextMenu* pcm;
3335 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3336 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3338 if (SUCCEEDED(hr)) {
3339 HMENU hmenu = CreatePopupMenu();
3341 if (hmenu) {
3342 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3344 if (SUCCEEDED(hr)) {
3345 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3347 if (idCmd) {
3348 CMINVOKECOMMANDINFO cmi;
3350 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3351 cmi.fMask = 0;
3352 cmi.hwnd = hwndParent;
3353 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3354 cmi.lpParameters = NULL;
3355 cmi.lpDirectory = NULL;
3356 cmi.nShow = SW_SHOWNORMAL;
3357 cmi.dwHotKey = 0;
3358 cmi.hIcon = 0;
3360 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3365 (*pcm->lpVtbl->Release)(pcm);
3368 return hr;
3372 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3374 static int last_split;
3376 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3377 ASSERT(child);
3379 switch(nmsg) {
3380 case WM_DRAWITEM: {
3381 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3382 Entry* entry = (Entry*) dis->itemData;
3384 if (dis->CtlID == IDW_TREE_LEFT)
3385 draw_item(&child->left, dis, entry, -1);
3386 else
3387 draw_item(&child->right, dis, entry, -1);
3389 return TRUE;}
3391 case WM_CREATE:
3392 InitChildWindow(child);
3393 break;
3395 case WM_NCDESTROY:
3396 free_child_window(child);
3397 SetWindowLong(hwnd, GWL_USERDATA, 0);
3398 break;
3400 case WM_PAINT: {
3401 PAINTSTRUCT ps;
3402 HBRUSH lastBrush;
3403 RECT rt;
3404 GetClientRect(hwnd, &rt);
3405 BeginPaint(hwnd, &ps);
3406 rt.left = child->split_pos-SPLIT_WIDTH/2;
3407 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3408 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3409 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3410 SelectObject(ps.hdc, lastBrush);
3411 #ifdef _NO_EXTENSIONS
3412 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3413 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3414 #endif
3415 EndPaint(hwnd, &ps);
3416 break;}
3418 case WM_SETCURSOR:
3419 if (LOWORD(lparam) == HTCLIENT) {
3420 POINT pt;
3421 GetCursorPos(&pt);
3422 ScreenToClient(hwnd, &pt);
3424 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3425 SetCursor(LoadCursor(0, IDC_SIZEWE));
3426 return TRUE;
3429 goto def;
3431 case WM_LBUTTONDOWN: {
3432 RECT rt;
3433 int x = GET_X_LPARAM(lparam);
3435 GetClientRect(hwnd, &rt);
3437 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3438 last_split = child->split_pos;
3439 #ifdef _NO_EXTENSIONS
3440 draw_splitbar(hwnd, last_split);
3441 #endif
3442 SetCapture(hwnd);
3445 break;}
3447 case WM_LBUTTONUP:
3448 if (GetCapture() == hwnd) {
3449 #ifdef _NO_EXTENSIONS
3450 RECT rt;
3451 int x = LOWORD(lparam);
3452 draw_splitbar(hwnd, last_split);
3453 last_split = -1;
3454 GetClientRect(hwnd, &rt);
3455 child->split_pos = x;
3456 resize_tree(child, rt.right, rt.bottom);
3457 #endif
3458 ReleaseCapture();
3460 break;
3462 #ifdef _NO_EXTENSIONS
3463 case WM_CAPTURECHANGED:
3464 if (GetCapture()==hwnd && last_split>=0)
3465 draw_splitbar(hwnd, last_split);
3466 break;
3467 #endif
3469 case WM_KEYDOWN:
3470 if (wparam == VK_ESCAPE)
3471 if (GetCapture() == hwnd) {
3472 RECT rt;
3473 #ifdef _NO_EXTENSIONS
3474 draw_splitbar(hwnd, last_split);
3475 #else
3476 child->split_pos = last_split;
3477 #endif
3478 GetClientRect(hwnd, &rt);
3479 resize_tree(child, rt.right, rt.bottom);
3480 last_split = -1;
3481 ReleaseCapture();
3482 SetCursor(LoadCursor(0, IDC_ARROW));
3484 break;
3486 case WM_MOUSEMOVE:
3487 if (GetCapture() == hwnd) {
3488 RECT rt;
3489 int x = LOWORD(lparam);
3491 #ifdef _NO_EXTENSIONS
3492 HDC hdc = GetDC(hwnd);
3493 GetClientRect(hwnd, &rt);
3495 rt.left = last_split-SPLIT_WIDTH/2;
3496 rt.right = last_split+SPLIT_WIDTH/2+1;
3497 InvertRect(hdc, &rt);
3499 last_split = x;
3500 rt.left = x-SPLIT_WIDTH/2;
3501 rt.right = x+SPLIT_WIDTH/2+1;
3502 InvertRect(hdc, &rt);
3504 ReleaseDC(hwnd, hdc);
3505 #else
3506 GetClientRect(hwnd, &rt);
3508 if (x>=0 && x<rt.right) {
3509 child->split_pos = x;
3510 resize_tree(child, rt.right, rt.bottom);
3511 rt.left = x-SPLIT_WIDTH/2;
3512 rt.right = x+SPLIT_WIDTH/2+1;
3513 InvalidateRect(hwnd, &rt, FALSE);
3514 UpdateWindow(child->left.hwnd);
3515 UpdateWindow(hwnd);
3516 UpdateWindow(child->right.hwnd);
3518 #endif
3520 break;
3522 #ifndef _NO_EXTENSIONS
3523 case WM_GETMINMAXINFO:
3524 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3526 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3528 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3529 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3530 break;}
3531 #endif /* _NO_EXTENSIONS */
3533 case WM_SETFOCUS:
3534 SetCurrentDirectory(child->path);
3535 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3536 break;
3538 case WM_DISPATCH_COMMAND: {
3539 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3541 switch(LOWORD(wparam)) {
3542 case ID_WINDOW_NEW: {
3543 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3545 if (!create_child_window(new_child))
3546 free(new_child);
3548 break;}
3550 case ID_REFRESH:
3551 scan_entry(child, pane->cur, hwnd);
3552 break;
3554 case ID_ACTIVATE:
3555 activate_entry(child, pane, hwnd);
3556 break;
3558 case ID_FILE_MOVE: {
3559 TCHAR new_name[BUFFER_LEN], old_name[BUFFER_LEN];
3560 int len;
3562 int ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, DestinationDlgProc, (LPARAM)new_name);
3563 if (ret != IDOK)
3564 break;
3566 if (new_name[0]!='/' && new_name[1]!=':') {
3567 get_path(pane->cur->up, old_name);
3568 len = lstrlen(old_name);
3570 if (old_name[len-1]!='\\' && old_name[len-1]!='/') {
3571 old_name[len++] = '/';
3572 old_name[len] = '\n';
3575 lstrcpy(&old_name[len], new_name);
3576 lstrcpy(new_name, old_name);
3579 get_path(pane->cur, old_name);
3581 if (MoveFileEx(old_name, new_name, MOVEFILE_COPY_ALLOWED)) {
3582 if (pane->treePane) {
3583 pane->root->scanned = FALSE;
3584 pane->cur = pane->root;
3585 activate_entry(child, pane, hwnd);
3587 else
3588 scan_entry(child, pane->root, hwnd);
3590 else
3591 display_error(hwnd, GetLastError());
3592 break;}
3594 default:
3595 return pane_command(pane, LOWORD(wparam));
3598 return TRUE;}
3600 case WM_COMMAND: {
3601 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3603 switch(HIWORD(wparam)) {
3604 case LBN_SELCHANGE: {
3605 int idx = ListBox_GetCurSel(pane->hwnd);
3606 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3608 if (pane == &child->left)
3609 set_curdir(child, entry, hwnd);
3610 else
3611 pane->cur = entry;
3612 break;}
3614 case LBN_DBLCLK:
3615 activate_entry(child, pane, hwnd);
3616 break;
3618 break;}
3620 #ifndef _NO_EXTENSIONS
3621 case WM_NOTIFY: {
3622 NMHDR* pnmh = (NMHDR*) lparam;
3623 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3624 #endif
3626 #ifdef _SHELL_FOLDERS
3627 case WM_CONTEXTMENU: {
3628 Pane* pane;
3629 int idx;
3631 /* first select the current item in the listbox */
3632 HWND hpanel = (HWND) wparam;
3633 POINTS* ppos = &MAKEPOINTS(lparam);
3634 POINT pt; POINTSTOPOINT(pt, *ppos);
3635 ScreenToClient(hpanel, &pt);
3636 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y));
3637 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
3639 /* now create the popup menu using shell namespace and IContextMenu */
3640 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3641 idx = ListBox_GetCurSel(pane->hwnd);
3643 if (idx != -1) {
3644 HRESULT hr;
3645 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3647 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3649 if (pidl_abs) {
3650 IShellFolder* parentFolder;
3651 LPCITEMIDLIST pidlLast;
3653 /* get and use the parent folder to display correct context menu in all cases */
3654 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3655 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, ppos->x, ppos->y);
3657 (*parentFolder->lpVtbl->Release)(parentFolder);
3660 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
3663 break;}
3664 #endif
3666 case WM_SIZE:
3667 if (wparam != SIZE_MINIMIZED)
3668 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3669 /* fall through */
3671 default: def:
3672 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3675 return 0;
3679 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3681 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3682 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3683 ASSERT(child);
3685 switch(nmsg) {
3686 #ifndef _NO_EXTENSIONS
3687 case WM_HSCROLL:
3688 set_header(pane);
3689 break;
3690 #endif
3692 case WM_SETFOCUS:
3693 child->focus_pane = pane==&child->right? 1: 0;
3694 ListBox_SetSel(hwnd, TRUE, 1);
3695 /*TODO: check menu items */
3696 break;
3698 case WM_KEYDOWN:
3699 if (wparam == VK_TAB) {
3700 /*TODO: SetFocus(Globals.hdrivebar) */
3701 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3705 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3709 static void InitInstance(HINSTANCE hinstance)
3711 WNDCLASSEX wcFrame;
3712 WNDCLASS wcChild;
3713 ATOM hChildClass;
3715 INITCOMMONCONTROLSEX icc = {
3716 sizeof(INITCOMMONCONTROLSEX),
3717 ICC_BAR_CLASSES
3720 HDC hdc = GetDC(0);
3722 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3724 InitCommonControlsEx(&icc);
3727 /* register frame window class */
3729 wcFrame.cbSize = sizeof(WNDCLASSEX);
3730 wcFrame.style = 0;
3731 wcFrame.lpfnWndProc = FrameWndProc;
3732 wcFrame.cbClsExtra = 0;
3733 wcFrame.cbWndExtra = 0;
3734 wcFrame.hInstance = hinstance;
3735 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3736 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3737 wcFrame.hbrBackground = 0;
3738 wcFrame.lpszMenuName = 0;
3739 wcFrame.lpszClassName = WINEFILEFRAME;
3740 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3741 MAKEINTRESOURCE(IDI_WINEFILE),
3742 IMAGE_ICON,
3743 GetSystemMetrics(SM_CXSMICON),
3744 GetSystemMetrics(SM_CYSMICON),
3745 LR_SHARED);
3747 Globals.hframeClass = RegisterClassEx(&wcFrame);
3750 /* register tree windows class */
3752 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3753 wcChild.lpfnWndProc = ChildWndProc;
3754 wcChild.cbClsExtra = 0;
3755 wcChild.cbWndExtra = 0;
3756 wcChild.hInstance = hinstance;
3757 wcChild.hIcon = 0;
3758 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3759 wcChild.hbrBackground = 0;
3760 wcChild.lpszMenuName = 0;
3761 wcChild.lpszClassName = WINEFILETREE;
3763 hChildClass = RegisterClass(&wcChild);
3766 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3768 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Shell Dlg"));
3770 ReleaseDC(0, hdc);
3772 Globals.hInstance = hinstance;
3774 #ifdef _SHELL_FOLDERS
3775 CoInitialize(NULL);
3776 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3777 SHGetDesktopFolder(&Globals.iDesktop);
3778 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3779 #endif
3783 void show_frame(HWND hwndParent, int cmdshow)
3785 TCHAR path[MAX_PATH], b1[BUFFER_LEN];
3786 ChildWnd* child;
3787 HMENU hMenuFrame, hMenuWindow;
3789 CLIENTCREATESTRUCT ccs;
3791 if (Globals.hMainWnd)
3792 return;
3794 Globals.hwndParent = hwndParent;
3796 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3797 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3799 Globals.hMenuFrame = hMenuFrame;
3800 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3801 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3803 ccs.hWindowMenu = hMenuWindow;
3804 ccs.idFirstChild = IDW_FIRST_CHILD;
3807 /* create main window */
3808 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
3809 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3810 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3813 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3814 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3815 0, 0, 0, 0,
3816 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3820 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3821 int btn = 1;
3822 PTSTR p;
3824 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3825 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3826 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3827 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3829 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3831 drivebarBtn.fsStyle = BTNS_BUTTON;
3833 #ifndef _NO_EXTENSIONS
3834 #ifdef __WINE__
3835 /* insert unix file system button */
3836 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3838 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3839 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3840 drivebarBtn.iString++;
3841 #endif
3842 #ifdef _SHELL_FOLDERS
3843 /* insert shell namespace button */
3844 load_string(b1, IDS_SHELL);
3845 b1[lstrlen(b1)+1] = '\0';
3846 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3848 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3849 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3850 drivebarBtn.iString++;
3851 #endif
3853 /* register windows drive root strings */
3854 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3855 #endif
3857 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3859 for(p=Globals.drives; *p; ) {
3860 #ifdef _NO_EXTENSIONS
3861 /* insert drive letter */
3862 TCHAR b[3] = {tolower(*p)};
3863 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3864 #endif
3865 switch(GetDriveType(p)) {
3866 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3867 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3868 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3869 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3870 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3873 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3874 drivebarBtn.idCommand++;
3875 drivebarBtn.iString++;
3877 while(*p++);
3882 TBBUTTON toolbarBtns[] = {
3883 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3884 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3885 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3886 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3887 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3888 /*TODO
3889 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3890 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3891 */ };
3893 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3894 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3895 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3896 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3899 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3900 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3902 /* CreateStatusWindow does not accept WS_BORDER
3903 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3904 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3905 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3907 /*TODO: read paths and window placements from registry */
3908 GetCurrentDirectory(MAX_PATH, path);
3910 ShowWindow(Globals.hMainWnd, cmdshow);
3912 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3913 /* Shell Namespace as default: */
3914 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3915 #else
3916 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3917 #endif
3919 child->pos.showCmd = SW_SHOWMAXIMIZED;
3920 child->pos.rcNormalPosition.left = 0;
3921 child->pos.rcNormalPosition.top = 0;
3922 child->pos.rcNormalPosition.right = 320;
3923 child->pos.rcNormalPosition.bottom = 280;
3925 if (!create_child_window(child))
3926 free(child);
3928 SetWindowPlacement(child->hwnd, &child->pos);
3930 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3932 Globals.prescan_node = FALSE;
3934 UpdateWindow(Globals.hMainWnd);
3937 void ExitInstance()
3939 #ifdef _SHELL_FOLDERS
3940 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3941 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3942 CoUninitialize();
3943 #endif
3945 ImageList_Destroy(Globals.himl);
3949 /* search for already running win[e]files */
3951 static int g_foundPrevInstance = 0;
3953 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3955 TCHAR cls[128];
3957 GetClassName(hwnd, cls, 128);
3959 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3960 g_foundPrevInstance++;
3961 return FALSE;
3964 return TRUE;
3967 /* search for window of given class name to allow only one running instance */
3968 int find_window_class(LPCTSTR classname)
3970 EnumWindows(EnumWndProc, (LPARAM)classname);
3972 if (g_foundPrevInstance)
3973 return 1;
3975 return 0;
3979 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3981 MSG msg;
3983 InitInstance(hinstance);
3985 if (cmdshow == SW_SHOWNORMAL)
3986 /*TODO: read window placement from registry */
3987 cmdshow = SW_MAXIMIZE;
3989 show_frame(hwndParent, cmdshow);
3991 while(GetMessage(&msg, 0, 0, 0)) {
3992 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3993 continue;
3995 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3996 continue;
3998 TranslateMessage(&msg);
3999 DispatchMessage(&msg);
4002 ExitInstance();
4004 return msg.wParam;
4008 int APIENTRY WinMain(HINSTANCE hinstance,
4009 HINSTANCE previnstance,
4010 LPSTR cmdline,
4011 int cmdshow)
4013 #ifdef _NO_EXTENSIONS
4014 if (find_window_class(WINEFILEFRAME))
4015 return 1;
4016 #endif
4018 winefile_main(hinstance, 0, cmdshow);
4020 return 0;