- Handle "." and ".." as special case and move them at the very first
[wine/multimedia.git] / programs / winefile / winefile.c
blobedca2f8acafcbf18fa046e2034e8e4d364637157
1 /*
2 * Winefile
4 * Copyright 2000 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 static void display_error(HWND hwnd, DWORD error)
182 PTSTR msg;
184 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
185 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
186 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
187 else
188 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
190 LocalFree(msg);
194 /* allocate and initialise a directory entry */
195 static Entry* alloc_entry()
197 Entry* entry = (Entry*) malloc(sizeof(Entry));
199 #ifdef _SHELL_FOLDERS
200 entry->pidl = NULL;
201 entry->folder = NULL;
202 entry->hicon = 0;
203 #endif
205 return entry;
208 /* free a directory entry */
209 static void free_entry(Entry* entry)
211 #ifdef _SHELL_FOLDERS
212 if (entry->hicon && entry->hicon!=(HICON)-1)
213 DestroyIcon(entry->hicon);
215 if (entry->folder && entry->folder!=Globals.iDesktop)
216 (*entry->folder->lpVtbl->Release)(entry->folder);
218 if (entry->pidl)
219 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
220 #endif
222 free(entry);
225 /* recursively free all child entries */
226 static void free_entries(Entry* dir)
228 Entry *entry, *next=dir->down;
230 if (next) {
231 dir->down = 0;
233 do {
234 entry = next;
235 next = entry->next;
237 free_entries(entry);
238 free_entry(entry);
239 } while(next);
244 static void read_directory_win(Entry* dir, LPCTSTR path)
246 Entry* first_entry = NULL;
247 Entry* last = NULL;
248 Entry* entry;
250 int level = dir->level + 1;
251 WIN32_FIND_DATA w32fd;
252 HANDLE hFind;
253 #ifndef _NO_EXTENSIONS
254 HANDLE hFile;
255 #endif
257 TCHAR buffer[MAX_PATH], *p;
258 for(p=buffer; *path; )
259 *p++ = *path++;
261 lstrcpy(p, TEXT("\\*"));
263 hFind = FindFirstFile(buffer, &w32fd);
265 if (hFind != INVALID_HANDLE_VALUE) {
266 do {
267 entry = alloc_entry();
269 if (!first_entry)
270 first_entry = entry;
272 if (last)
273 last->next = entry;
275 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
276 entry->down = NULL;
277 entry->up = dir;
278 entry->expanded = FALSE;
279 entry->scanned = FALSE;
280 entry->level = level;
282 #ifdef _NO_EXTENSIONS
283 /* hide directory entry "." */
284 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
285 LPCTSTR name = entry->data.cFileName;
287 if (name[0]=='.' && name[1]=='\0')
288 continue;
290 #else
291 entry->etype = ET_WINDOWS;
292 entry->bhfi_valid = FALSE;
294 lstrcpy(p+1, entry->data.cFileName);
296 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
297 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
299 if (hFile != INVALID_HANDLE_VALUE) {
300 if (GetFileInformationByHandle(hFile, &entry->bhfi))
301 entry->bhfi_valid = TRUE;
303 CloseHandle(hFile);
305 #endif
307 last = entry;
308 } while(FindNextFile(hFind, &entry->data));
310 last->next = NULL;
312 FindClose(hFind);
315 dir->down = first_entry;
316 dir->scanned = TRUE;
320 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
322 Entry* entry;
324 for(entry=dir->down; entry; entry=entry->next) {
325 LPCTSTR p = name;
326 LPCTSTR q = entry->data.cFileName;
328 do {
329 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
330 return entry;
331 } while(tolower(*p++) == tolower(*q++));
333 p = name;
334 q = entry->data.cAlternateFileName;
336 do {
337 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
338 return entry;
339 } while(tolower(*p++) == tolower(*q++));
342 return 0;
346 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
348 TCHAR buffer[MAX_PATH];
349 Entry* entry = &root->entry;
350 LPCTSTR s = path;
351 PTSTR d = buffer;
353 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
355 #ifndef _NO_EXTENSIONS
356 entry->etype = ET_WINDOWS;
357 #endif
359 while(entry) {
360 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
361 *d++ = *s++;
363 while(*s==TEXT('\\') || *s==TEXT('/'))
364 s++;
366 *d++ = TEXT('\\');
367 *d = TEXT('\0');
369 read_directory(entry, buffer, sortOrder, hwnd);
371 if (entry->down)
372 entry->expanded = TRUE;
374 if (!*s)
375 break;
377 entry = find_entry_win(entry, s);
380 SetCursor(old_cursor);
382 return entry;
386 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
388 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
390 struct tm* tm = gmtime(t);
391 SYSTEMTIME stime;
393 if (!tm)
394 return FALSE;
396 stime.wYear = tm->tm_year+1900;
397 stime.wMonth = tm->tm_mon+1;
398 /* stime.wDayOfWeek */
399 stime.wDay = tm->tm_mday;
400 stime.wHour = tm->tm_hour;
401 stime.wMinute = tm->tm_min;
402 stime.wSecond = tm->tm_sec;
404 return SystemTimeToFileTime(&stime, ftime);
407 static void read_directory_unix(Entry* dir, LPCTSTR path)
409 Entry* first_entry = NULL;
410 Entry* last = NULL;
411 Entry* entry;
413 int level = dir->level + 1;
415 DIR* pdir = opendir(path);
417 if (pdir) {
418 struct stat st;
419 struct dirent* ent;
420 TCHAR buffer[MAX_PATH], *p;
422 for(p=buffer; *path; )
423 *p++ = *path++;
425 if (p==buffer || p[-1]!='/')
426 *p++ = '/';
428 while((ent=readdir(pdir))) {
429 entry = alloc_entry();
431 if (!first_entry)
432 first_entry = entry;
434 if (last)
435 last->next = entry;
437 entry->etype = ET_UNIX;
439 lstrcpy(entry->data.cFileName, ent->d_name);
440 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
442 strcpy(p, ent->d_name);
444 if (!stat(buffer, &st)) {
445 if (S_ISDIR(st.st_mode))
446 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
448 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
449 entry->data.nFileSizeHigh = st.st_size >> 32;
451 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
452 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
453 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
455 entry->bhfi.nFileIndexLow = ent->d_ino;
456 entry->bhfi.nFileIndexHigh = 0;
458 entry->bhfi.nNumberOfLinks = st.st_nlink;
460 entry->bhfi_valid = TRUE;
461 } else {
462 entry->data.nFileSizeLow = 0;
463 entry->data.nFileSizeHigh = 0;
464 entry->bhfi_valid = FALSE;
467 entry->down = NULL;
468 entry->up = dir;
469 entry->expanded = FALSE;
470 entry->scanned = FALSE;
471 entry->level = level;
473 last = entry;
476 last->next = NULL;
478 closedir(pdir);
481 dir->down = first_entry;
482 dir->scanned = TRUE;
485 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
487 Entry* entry;
489 for(entry=dir->down; entry; entry=entry->next) {
490 LPCTSTR p = name;
491 LPCTSTR q = entry->data.cFileName;
493 do {
494 if (!*p || *p==TEXT('/'))
495 return entry;
496 } while(*p++ == *q++);
499 return 0;
502 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
504 TCHAR buffer[MAX_PATH];
505 Entry* entry = &root->entry;
506 LPCTSTR s = path;
507 PTSTR d = buffer;
509 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
511 entry->etype = ET_UNIX;
513 while(entry) {
514 while(*s && *s!=TEXT('/'))
515 *d++ = *s++;
517 while(*s == TEXT('/'))
518 s++;
520 *d++ = TEXT('/');
521 *d = TEXT('\0');
523 read_directory(entry, buffer, sortOrder, hwnd);
525 if (entry->down)
526 entry->expanded = TRUE;
528 if (!*s)
529 break;
531 entry = find_entry_unix(entry, s);
534 SetCursor(old_cursor);
536 return entry;
539 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
542 #ifdef _SHELL_FOLDERS
544 #ifdef UNICODE
545 #define tcscpyn strcpyn
546 #define get_strret get_strretW
547 #define path_from_pidl path_from_pidlW
548 #else
549 #define tcscpyn wcscpyn
550 #define get_strret get_strretA
551 #define path_from_pidl path_from_pidlA
552 #endif
555 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
557 LPCSTR s;
558 LPSTR d = dest;
560 for(s=source; count&&(*d++=*s++); )
561 count--;
563 return dest;
566 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
568 LPCWSTR s;
569 LPWSTR d = dest;
571 for(s=source; count&&(*d++=*s++); )
572 count--;
574 return dest;
578 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
580 switch(str->uType) {
581 case STRRET_WSTR:
582 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
583 break;
585 case STRRET_OFFSET:
586 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
587 break;
589 case STRRET_CSTR:
590 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
594 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
596 switch(str->uType) {
597 case STRRET_WSTR:
598 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
599 break;
601 case STRRET_OFFSET:
602 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
603 break;
605 case STRRET_CSTR:
606 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
611 static void free_strret(STRRET* str)
613 if (str->uType == STRRET_WSTR)
614 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
618 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
620 STRRET str;
622 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
624 if (SUCCEEDED(hr)) {
625 get_strret(&str, &pidl->mkid, buffer, len);
626 free_strret(&str);
627 } else
628 buffer[0] = '\0';
630 return hr;
634 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
636 STRRET str;
638 /* SHGDN_FORPARSING: get full path of id list */
639 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
641 if (SUCCEEDED(hr)) {
642 get_strretA(&str, &pidl->mkid, buffer, len);
643 free_strret(&str);
644 } else
645 buffer[0] = '\0';
647 return hr;
650 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
652 STRRET str;
654 /* SHGDN_FORPARSING: get full path of id list */
655 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
657 if (SUCCEEDED(hr)) {
658 get_strretW(&str, &pidl->mkid, buffer, len);
659 free_strret(&str);
660 } else
661 buffer[0] = '\0';
663 return hr;
667 /* create an item id list from a file system path */
669 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
671 LPITEMIDLIST pidl;
672 HRESULT hr;
673 ULONG len;
675 #ifdef UNICODE
676 LPWSTR buffer = path;
677 #else
678 WCHAR buffer[MAX_PATH];
679 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
680 #endif
682 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
683 if (FAILED(hr))
684 return NULL;
686 return pidl;
690 /* convert an item id list from relative to absolute (=relative to the desktop) format */
692 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
694 if (entry->up && entry->up->etype==ET_SHELL) {
695 IShellFolder* folder = entry->up->folder;
696 WCHAR buffer[MAX_PATH];
698 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
700 if (SUCCEEDED(hr)) {
701 LPITEMIDLIST pidl;
702 ULONG len;
704 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
706 if (SUCCEEDED(hr))
707 return pidl;
709 } else if (entry->etype == ET_WINDOWS) {
710 TCHAR path[MAX_PATH];
712 get_path(entry, path);
714 return get_path_pidl(path, hwnd);
715 } else if (entry->pidl)
716 return ILClone(entry->pidl);
718 return NULL;
722 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
724 IExtractIcon* pExtract;
726 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
727 TCHAR path[_MAX_PATH];
728 unsigned flags;
729 HICON hicon;
730 int idx;
732 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
733 if (!(flags & GIL_NOTFILENAME)) {
734 if (idx == -1)
735 idx = 0; /* special case for some control panel applications */
737 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
738 flags &= ~GIL_DONTCACHE;
739 } else {
740 HICON hIconLarge = 0;
742 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
744 if (SUCCEEDED(hr))
745 DestroyIcon(hIconLarge);
748 return hicon;
752 return 0;
756 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
758 Entry* entry;
760 for(entry=dir->down; entry; entry=entry->next) {
761 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
762 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
763 return entry;
766 return 0;
769 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
771 Entry* entry = &root->entry;
772 Entry* next;
773 LPITEMIDLIST next_pidl = pidl;
774 IShellFolder* folder;
775 IShellFolder* child = NULL;
776 HRESULT hr;
778 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
780 #ifndef _NO_EXTENSIONS
781 entry->etype = ET_SHELL;
782 #endif
784 folder = Globals.iDesktop;
786 while(entry) {
787 entry->pidl = next_pidl;
788 entry->folder = folder;
790 if (!pidl->mkid.cb)
791 break;
793 /* copy first element of item idlist */
794 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
795 memcpy(next_pidl, pidl, pidl->mkid.cb);
796 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
798 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
799 if (!SUCCEEDED(hr))
800 break;
802 read_directory(entry, NULL, sortOrder, hwnd);
804 if (entry->down)
805 entry->expanded = TRUE;
807 next = find_entry_shell(entry, next_pidl);
808 if (!next)
809 break;
811 folder = child;
812 entry = next;
814 /* go to next element */
815 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
818 SetCursor(old_cursor);
820 return entry;
824 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
826 if (!(attribs & SFGAO_FILESYSTEM) ||
827 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
828 WIN32_FILE_ATTRIBUTE_DATA fad;
829 IDataObject* pDataObj;
831 STGMEDIUM medium = {0, {0}, 0};
832 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
834 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
836 if (SUCCEEDED(hr)) {
837 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
839 (*pDataObj->lpVtbl->Release)(pDataObj);
841 if (SUCCEEDED(hr)) {
842 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
843 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
845 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
846 w32fdata->dwFileAttributes = fad.dwFileAttributes;
847 w32fdata->ftCreationTime = fad.ftCreationTime;
848 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
849 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
851 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
852 w32fdata->nFileSizeLow = fad.nFileSizeLow;
853 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
857 SetErrorMode(sem_org);
859 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
860 GlobalFree(medium.UNION_MEMBER(hGlobal));
865 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
866 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
868 if (attribs & SFGAO_READONLY)
869 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
871 if (attribs & SFGAO_COMPRESSED)
872 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
876 static void read_directory_shell(Entry* dir, HWND hwnd)
878 IShellFolder* folder = dir->folder;
879 int level = dir->level + 1;
880 HRESULT hr;
882 IShellFolder* child;
883 IEnumIDList* idlist;
885 Entry* first_entry = NULL;
886 Entry* last = NULL;
887 Entry* entry;
889 if (!folder)
890 return;
892 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
894 if (SUCCEEDED(hr)) {
895 for(;;) {
896 #define FETCH_ITEM_COUNT 32
897 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
898 SFGAOF attribs;
899 ULONG cnt = 0;
900 ULONG n;
902 memset(pidls, 0, sizeof(pidls));
904 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
905 if (!SUCCEEDED(hr))
906 break;
908 if (hr == S_FALSE)
909 break;
911 for(n=0; n<cnt; ++n) {
912 entry = alloc_entry();
914 if (!first_entry)
915 first_entry = entry;
917 if (last)
918 last->next = entry;
920 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
921 entry->bhfi_valid = FALSE;
923 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
925 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
927 if (SUCCEEDED(hr)) {
928 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
929 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
931 entry->bhfi_valid = TRUE;
932 } else
933 attribs = 0;
934 } else
935 attribs = 0;
937 entry->pidl = pidls[n];
939 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
940 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
942 if (SUCCEEDED(hr))
943 entry->folder = child;
944 else
945 entry->folder = NULL;
947 else
948 entry->folder = NULL;
950 if (!entry->data.cFileName[0])
951 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
953 /* get display icons for files and virtual objects */
954 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
955 !(attribs & SFGAO_FILESYSTEM)) {
956 entry->hicon = extract_icon(folder, pidls[n]);
958 if (!entry->hicon)
959 entry->hicon = (HICON)-1; /* don't try again later */
962 entry->down = NULL;
963 entry->up = dir;
964 entry->expanded = FALSE;
965 entry->scanned = FALSE;
966 entry->level = level;
968 #ifndef _NO_EXTENSIONS
969 entry->etype = ET_SHELL;
970 entry->bhfi_valid = FALSE;
971 #endif
973 last = entry;
977 (*idlist->lpVtbl->Release)(idlist);
980 if (last)
981 last->next = NULL;
983 dir->down = first_entry;
984 dir->scanned = TRUE;
987 #endif /* _SHELL_FOLDERS */
990 /* sort order for different directory/file types */
991 enum TYPE_ORDER {
992 TO_DIR = 0,
993 TO_DOT = 1,
994 TO_DOTDOT = 2,
995 TO_OTHER_DIR = 3,
996 TO_FILE = 4
999 /* distinguish between ".", ".." and any other directory names */
1000 static int TypeOrderFromDirname(LPCTSTR name)
1002 if (name[0] == '.') {
1003 if (name[1] == '\0')
1004 return TO_DOT; /* "." */
1006 if (name[1]=='.' && name[2]=='\0')
1007 return TO_DOTDOT; /* ".." */
1010 return TO_OTHER_DIR; /* anything else */
1013 /* directories first... */
1014 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1016 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1017 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1019 /* Handle "." and ".." as special case and move them at the very first beginning. */
1020 if (order1==TO_DIR && order2==TO_DIR) {
1021 order1 = TypeOrderFromDirname(fd1->cFileName);
1022 order2 = TypeOrderFromDirname(fd2->cFileName);
1025 return order2==order1? 0: order1<order2? -1: 1;
1029 static int compareName(const void* arg1, const void* arg2)
1031 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1032 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1034 int cmp = compareType(fd1, fd2);
1035 if (cmp)
1036 return cmp;
1038 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1041 static int compareExt(const void* arg1, const void* arg2)
1043 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1044 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1045 const TCHAR *name1, *name2, *ext1, *ext2;
1047 int cmp = compareType(fd1, fd2);
1048 if (cmp)
1049 return cmp;
1051 name1 = fd1->cFileName;
1052 name2 = fd2->cFileName;
1054 ext1 = _tcsrchr(name1, TEXT('.'));
1055 ext2 = _tcsrchr(name2, TEXT('.'));
1057 if (ext1)
1058 ext1++;
1059 else
1060 ext1 = TEXT("");
1062 if (ext2)
1063 ext2++;
1064 else
1065 ext2 = TEXT("");
1067 cmp = lstrcmpi(ext1, ext2);
1068 if (cmp)
1069 return cmp;
1071 return lstrcmpi(name1, name2);
1074 static int compareSize(const void* arg1, const void* arg2)
1076 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1077 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1079 int cmp = compareType(fd1, fd2);
1080 if (cmp)
1081 return cmp;
1083 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1085 if (cmp < 0)
1086 return -1;
1087 else if (cmp > 0)
1088 return 1;
1090 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1092 return cmp<0? -1: cmp>0? 1: 0;
1095 static int compareDate(const void* arg1, const void* arg2)
1097 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1098 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1100 int cmp = compareType(fd1, fd2);
1101 if (cmp)
1102 return cmp;
1104 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1108 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1109 compareName, /* SORT_NAME */
1110 compareExt, /* SORT_EXT */
1111 compareSize, /* SORT_SIZE */
1112 compareDate /* SORT_DATE */
1116 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1118 Entry* entry = dir->down;
1119 Entry** array, **p;
1120 int len;
1122 len = 0;
1123 for(entry=dir->down; entry; entry=entry->next)
1124 len++;
1126 if (len) {
1127 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1129 p = array;
1130 for(entry=dir->down; entry; entry=entry->next)
1131 *p++ = entry;
1133 /* call qsort with the appropriate compare function */
1134 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1136 dir->down = array[0];
1138 for(p=array; --len; p++)
1139 p[0]->next = p[1];
1141 (*p)->next = 0;
1142 HeapFree( GetProcessHeap(), 0, array );
1147 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1149 TCHAR buffer[MAX_PATH];
1150 Entry* entry;
1151 LPCTSTR s;
1152 PTSTR d;
1154 #ifdef _SHELL_FOLDERS
1155 if (dir->etype == ET_SHELL)
1157 read_directory_shell(dir, hwnd);
1159 if (Globals.prescan_node) {
1160 s = path;
1161 d = buffer;
1163 while(*s)
1164 *d++ = *s++;
1166 *d++ = TEXT('\\');
1168 for(entry=dir->down; entry; entry=entry->next)
1169 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1170 read_directory_shell(entry, hwnd);
1171 SortDirectory(entry, sortOrder);
1175 else
1176 #endif
1177 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1178 if (dir->etype == ET_UNIX)
1180 read_directory_unix(dir, path);
1182 if (Globals.prescan_node) {
1183 s = path;
1184 d = buffer;
1186 while(*s)
1187 *d++ = *s++;
1189 *d++ = TEXT('/');
1191 for(entry=dir->down; entry; entry=entry->next)
1192 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1193 lstrcpy(d, entry->data.cFileName);
1194 read_directory_unix(entry, buffer);
1195 SortDirectory(entry, sortOrder);
1199 else
1200 #endif
1202 read_directory_win(dir, path);
1204 if (Globals.prescan_node) {
1205 s = path;
1206 d = buffer;
1208 while(*s)
1209 *d++ = *s++;
1211 *d++ = TEXT('\\');
1213 for(entry=dir->down; entry; entry=entry->next)
1214 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1215 lstrcpy(d, entry->data.cFileName);
1216 read_directory_win(entry, buffer);
1217 SortDirectory(entry, sortOrder);
1222 SortDirectory(dir, sortOrder);
1226 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1228 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1229 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1230 Root* root = &child->root;
1231 Entry* entry;
1233 memset(child, 0, sizeof(ChildWnd));
1235 child->left.treePane = TRUE;
1236 child->left.visible_cols = 0;
1238 child->right.treePane = FALSE;
1239 #ifndef _NO_EXTENSIONS
1240 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1241 #else
1242 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1243 #endif
1245 child->pos.length = sizeof(WINDOWPLACEMENT);
1246 child->pos.flags = 0;
1247 child->pos.showCmd = SW_SHOWNORMAL;
1248 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1249 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1250 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1251 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1253 child->focus_pane = 0;
1254 child->split_pos = DEFAULT_SPLIT_POS;
1255 child->sortOrder = SORT_NAME;
1256 child->header_wdths_ok = FALSE;
1258 if (path)
1260 lstrcpy(child->path, path);
1262 _tsplitpath(path, drv, dir, name, ext);
1265 root->entry.level = 0;
1267 #ifdef _SHELL_FOLDERS
1268 if (pidl)
1270 root->drive_type = DRIVE_UNKNOWN;
1271 lstrcpy(drv, TEXT("\\"));
1272 lstrcpy(root->volname, TEXT("Desktop"));
1273 root->fs_flags = 0;
1274 lstrcpy(root->fs, TEXT("Shell"));
1276 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1278 else
1279 #endif
1280 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1281 if (*path == '/')
1283 root->drive_type = GetDriveType(path);
1285 lstrcat(drv, TEXT("/"));
1286 lstrcpy(root->volname, TEXT("root fs"));
1287 root->fs_flags = 0;
1288 lstrcpy(root->fs, TEXT("unixfs"));
1290 lstrcpy(root->path, TEXT("/"));
1291 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1293 else
1294 #endif
1296 root->drive_type = GetDriveType(path);
1298 lstrcat(drv, TEXT("\\"));
1299 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1301 lstrcpy(root->path, drv);
1302 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1305 #ifdef _SHELL_FOLDERS
1306 if (root->entry.etype == ET_SHELL)
1307 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1308 else
1309 #endif
1310 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1312 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1314 child->left.root = &root->entry;
1315 child->right.root = NULL;
1317 set_curdir(child, entry, hwnd);
1319 return child;
1323 /* free all memory associated with a child window */
1324 static void free_child_window(ChildWnd* child)
1326 free_entries(&child->root.entry);
1327 free(child);
1331 /* get full path of specified directory entry */
1332 static void get_path(Entry* dir, PTSTR path)
1334 Entry* entry;
1335 int len = 0;
1336 int level = 0;
1338 #ifdef _SHELL_FOLDERS
1339 if (dir->etype == ET_SHELL)
1341 SFGAOF attribs;
1342 HRESULT hr = S_OK;
1344 path[0] = TEXT('\0');
1346 attribs = 0;
1348 if (dir->folder)
1349 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1351 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1352 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1354 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1357 else
1358 #endif
1360 for(entry=dir; entry; level++) {
1361 LPCTSTR name;
1362 int l;
1365 LPCTSTR s;
1366 name = entry->data.cFileName;
1367 s = name;
1369 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1370 l++;
1373 if (entry->up) {
1374 if (l > 0) {
1375 memmove(path+l+1, path, len*sizeof(TCHAR));
1376 memcpy(path+1, name, l*sizeof(TCHAR));
1377 len += l+1;
1379 #ifndef _NO_EXTENSIONS
1380 if (entry->etype == ET_UNIX)
1381 path[0] = TEXT('/');
1382 else
1383 #endif
1384 path[0] = TEXT('\\');
1387 entry = entry->up;
1388 } else {
1389 memmove(path+l, path, len*sizeof(TCHAR));
1390 memcpy(path, name, l*sizeof(TCHAR));
1391 len += l;
1392 break;
1396 if (!level) {
1397 #ifndef _NO_EXTENSIONS
1398 if (entry->etype == ET_UNIX)
1399 path[len++] = TEXT('/');
1400 else
1401 #endif
1402 path[len++] = TEXT('\\');
1405 path[len] = TEXT('\0');
1410 static void resize_frame_rect(HWND hwnd, PRECT prect)
1412 int new_top;
1413 RECT rt;
1415 if (IsWindowVisible(Globals.htoolbar)) {
1416 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1417 GetClientRect(Globals.htoolbar, &rt);
1418 prect->top = rt.bottom+3;
1419 prect->bottom -= rt.bottom+3;
1422 if (IsWindowVisible(Globals.hdrivebar)) {
1423 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1424 GetClientRect(Globals.hdrivebar, &rt);
1425 new_top = --prect->top + rt.bottom+3;
1426 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1427 prect->top = new_top;
1428 prect->bottom -= rt.bottom+2;
1431 if (IsWindowVisible(Globals.hstatusbar)) {
1432 int parts[] = {300, 500};
1434 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1435 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1436 GetClientRect(Globals.hstatusbar, &rt);
1437 prect->bottom -= rt.bottom;
1440 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1443 static void resize_frame(HWND hwnd, int cx, int cy)
1445 RECT rect;
1447 rect.left = 0;
1448 rect.top = 0;
1449 rect.right = cx;
1450 rect.bottom = cy;
1452 resize_frame_rect(hwnd, &rect);
1455 static void resize_frame_client(HWND hwnd)
1457 RECT rect;
1459 GetClientRect(hwnd, &rect);
1461 resize_frame_rect(hwnd, &rect);
1465 static HHOOK hcbthook;
1466 static ChildWnd* newchild = NULL;
1468 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1470 if (code==HCBT_CREATEWND && newchild) {
1471 ChildWnd* child = newchild;
1472 newchild = NULL;
1474 child->hwnd = (HWND) wparam;
1475 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1478 return CallNextHookEx(hcbthook, code, wparam, lparam);
1481 static HWND create_child_window(ChildWnd* child)
1483 MDICREATESTRUCT mcs;
1484 int idx;
1486 mcs.szClass = WINEFILETREE;
1487 mcs.szTitle = (LPTSTR)child->path;
1488 mcs.hOwner = Globals.hInstance;
1489 mcs.x = child->pos.rcNormalPosition.left;
1490 mcs.y = child->pos.rcNormalPosition.top;
1491 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1492 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1493 mcs.style = 0;
1494 mcs.lParam = 0;
1496 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1498 newchild = child;
1499 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1500 if (!child->hwnd) {
1501 UnhookWindowsHookEx(hcbthook);
1502 return 0;
1505 UnhookWindowsHookEx(hcbthook);
1507 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1508 ListBox_SetCurSel(child->left.hwnd, idx);
1510 return child->hwnd;
1514 struct ExecuteDialog {
1515 TCHAR cmd[MAX_PATH];
1516 int cmdshow;
1520 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1522 static struct ExecuteDialog* dlg;
1524 switch(nmsg) {
1525 case WM_INITDIALOG:
1526 dlg = (struct ExecuteDialog*) lparam;
1527 return 1;
1529 case WM_COMMAND: {
1530 int id = (int)wparam;
1532 if (id == IDOK) {
1533 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1534 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1535 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1536 EndDialog(hwnd, id);
1537 } else if (id == IDCANCEL)
1538 EndDialog(hwnd, id);
1540 return 1;}
1543 return 0;
1547 #ifndef _NO_EXTENSIONS
1549 static struct FullScreenParameters {
1550 BOOL mode;
1551 RECT orgPos;
1552 BOOL wasZoomed;
1553 } g_fullscreen = {
1554 FALSE, /* mode */
1555 {0, 0, 0, 0},
1556 FALSE
1559 void frame_get_clientspace(HWND hwnd, PRECT prect)
1561 RECT rt;
1563 if (!IsIconic(hwnd))
1564 GetClientRect(hwnd, prect);
1565 else {
1566 WINDOWPLACEMENT wp;
1568 GetWindowPlacement(hwnd, &wp);
1570 prect->left = prect->top = 0;
1571 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1572 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1573 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1574 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1575 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1578 if (IsWindowVisible(Globals.htoolbar)) {
1579 GetClientRect(Globals.htoolbar, &rt);
1580 prect->top += rt.bottom+2;
1583 if (IsWindowVisible(Globals.hdrivebar)) {
1584 GetClientRect(Globals.hdrivebar, &rt);
1585 prect->top += rt.bottom+2;
1588 if (IsWindowVisible(Globals.hstatusbar)) {
1589 GetClientRect(Globals.hstatusbar, &rt);
1590 prect->bottom -= rt.bottom;
1594 static BOOL toggle_fullscreen(HWND hwnd)
1596 RECT rt;
1598 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1599 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1600 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1602 Frame_CalcFrameClient(hwnd, &rt);
1603 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1604 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1606 rt.left = g_fullscreen.orgPos.left-rt.left;
1607 rt.top = g_fullscreen.orgPos.top-rt.top;
1608 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1609 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1611 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1612 } else {
1613 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1614 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1615 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1617 if (g_fullscreen.wasZoomed)
1618 ShowWindow(hwnd, WS_MAXIMIZE);
1621 return g_fullscreen.mode;
1624 static void fullscreen_move(HWND hwnd)
1626 RECT rt, pos;
1627 GetWindowRect(hwnd, &pos);
1629 Frame_CalcFrameClient(hwnd, &rt);
1630 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1631 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1633 rt.left = pos.left-rt.left;
1634 rt.top = pos.top-rt.top;
1635 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1636 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1638 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1641 #endif
1644 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1646 BOOL vis = IsWindowVisible(hchild);
1648 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1650 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1652 #ifndef _NO_EXTENSIONS
1653 if (g_fullscreen.mode)
1654 fullscreen_move(hwnd);
1655 #endif
1657 resize_frame_client(hwnd);
1660 BOOL activate_drive_window(LPCTSTR path)
1662 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1663 HWND child_wnd;
1665 _tsplitpath(path, drv1, 0, 0, 0);
1667 /* search for a already open window for the same drive */
1668 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1669 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1671 if (child) {
1672 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1674 if (!lstrcmpi(drv2, drv1)) {
1675 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1677 if (IsMinimized(child_wnd))
1678 ShowWindow(child_wnd, SW_SHOWNORMAL);
1680 return TRUE;
1685 return FALSE;
1688 BOOL activate_fs_window(LPCTSTR filesys)
1690 HWND child_wnd;
1692 /* search for a already open window of the given file system name */
1693 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1694 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1696 if (child) {
1697 if (!lstrcmpi(child->root.fs, filesys)) {
1698 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1700 if (IsMinimized(child_wnd))
1701 ShowWindow(child_wnd, SW_SHOWNORMAL);
1703 return TRUE;
1708 return FALSE;
1711 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1713 switch(nmsg) {
1714 case WM_CLOSE:
1715 DestroyWindow(hwnd);
1717 /* clear handle variables */
1718 Globals.hMenuFrame = 0;
1719 Globals.hMenuView = 0;
1720 Globals.hMenuOptions = 0;
1721 Globals.hMainWnd = 0;
1722 Globals.hmdiclient = 0;
1723 Globals.hdrivebar = 0;
1724 break;
1726 case WM_DESTROY:
1727 /* don't exit desktop when closing file manager window */
1728 if (!Globals.hwndParent)
1729 PostQuitMessage(0);
1730 break;
1732 case WM_COMMAND: {
1733 UINT cmd = LOWORD(wparam);
1734 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1736 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1737 break;
1739 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1740 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1741 ChildWnd* child;
1742 LPCTSTR root = Globals.drives;
1743 int i;
1745 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1746 while(*root)
1747 root++;
1749 if (activate_drive_window(root))
1750 return 0;
1752 _tsplitpath(root, drv, 0, 0, 0);
1754 if (!SetCurrentDirectory(drv)) {
1755 display_error(hwnd, GetLastError());
1756 return 0;
1759 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1760 child = alloc_child_window(path, NULL, hwnd);
1762 if (!create_child_window(child))
1763 free(child);
1764 } else switch(cmd) {
1765 case ID_FILE_EXIT:
1766 SendMessage(hwnd, WM_CLOSE, 0, 0);
1767 break;
1769 case ID_WINDOW_NEW: {
1770 TCHAR path[MAX_PATH];
1771 ChildWnd* child;
1773 GetCurrentDirectory(MAX_PATH, path);
1774 child = alloc_child_window(path, NULL, hwnd);
1776 if (!create_child_window(child))
1777 free(child);
1778 break;}
1780 case ID_WINDOW_CASCADE:
1781 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1782 break;
1784 case ID_WINDOW_TILE_HORZ:
1785 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1786 break;
1788 case ID_WINDOW_TILE_VERT:
1789 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1790 break;
1792 case ID_WINDOW_ARRANGE:
1793 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1794 break;
1796 case ID_VIEW_TOOL_BAR:
1797 toggle_child(hwnd, cmd, Globals.htoolbar);
1798 break;
1800 case ID_VIEW_DRIVE_BAR:
1801 toggle_child(hwnd, cmd, Globals.hdrivebar);
1802 break;
1804 case ID_VIEW_STATUSBAR:
1805 toggle_child(hwnd, cmd, Globals.hstatusbar);
1806 break;
1808 case ID_EXECUTE: {
1809 struct ExecuteDialog dlg;
1811 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1813 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1814 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1816 if ((int)hinst <= 32)
1817 display_error(hwnd, GetLastError());
1819 break;}
1821 case ID_HELP:
1822 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1823 break;
1825 #ifndef _NO_EXTENSIONS
1826 case ID_VIEW_FULLSCREEN:
1827 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1828 break;
1830 #ifdef __WINE__
1831 case ID_DRIVE_UNIX_FS: {
1832 TCHAR path[MAX_PATH];
1833 ChildWnd* child;
1835 if (activate_fs_window(TEXT("unixfs")))
1836 break;
1838 getcwd(path, MAX_PATH);
1839 child = alloc_child_window(path, NULL, hwnd);
1841 if (!create_child_window(child))
1842 free(child);
1843 break;}
1844 #endif
1845 #ifdef _SHELL_FOLDERS
1846 case ID_DRIVE_SHELL_NS: {
1847 TCHAR path[MAX_PATH];
1848 ChildWnd* child;
1850 if (activate_fs_window(TEXT("Shell")))
1851 break;
1853 GetCurrentDirectory(MAX_PATH, path);
1854 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1856 if (!create_child_window(child))
1857 free(child);
1858 break;}
1859 #endif
1860 #endif
1862 /*TODO: There are even more menu items! */
1864 #ifndef _NO_EXTENSIONS
1865 #ifdef __WINE__
1866 case ID_LICENSE:
1867 WineLicense(Globals.hMainWnd);
1868 break;
1870 case ID_NO_WARRANTY:
1871 WineWarranty(Globals.hMainWnd);
1872 break;
1873 #endif
1875 case ID_ABOUT_WINE:
1876 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1877 break;
1879 case ID_ABOUT: /*ID_ABOUT_WINE: */
1880 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1881 break;
1882 #endif /* _NO_EXTENSIONS */
1884 default:
1885 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1886 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1887 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1888 (cmd<SC_SIZE || cmd>SC_RESTORE))
1889 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1891 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1893 break;}
1895 case WM_SIZE:
1896 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1897 break; /* do not pass message to DefFrameProc */
1899 #ifndef _NO_EXTENSIONS
1900 case WM_GETMINMAXINFO: {
1901 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1903 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1904 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1905 break;}
1907 case FRM_CALC_CLIENT:
1908 frame_get_clientspace(hwnd, (PRECT)lparam);
1909 return TRUE;
1910 #endif /* _NO_EXTENSIONS */
1912 default:
1913 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1916 return 0;
1920 static const LPTSTR g_pos_names[COLUMNS] = {
1921 TEXT(""), /* symbol */
1922 TEXT("Name"),
1923 TEXT("Size"),
1924 TEXT("CDate"),
1925 #ifndef _NO_EXTENSIONS
1926 TEXT("ADate"),
1927 TEXT("MDate"),
1928 TEXT("Index/Inode"),
1929 TEXT("Links"),
1930 #endif /* _NO_EXTENSIONS */
1931 TEXT("Attributes"),
1932 #ifndef _NO_EXTENSIONS
1933 TEXT("Security")
1934 #endif
1937 static const int g_pos_align[] = {
1939 HDF_LEFT, /* Name */
1940 HDF_RIGHT, /* Size */
1941 HDF_LEFT, /* CDate */
1942 #ifndef _NO_EXTENSIONS
1943 HDF_LEFT, /* ADate */
1944 HDF_LEFT, /* MDate */
1945 HDF_LEFT, /* Index */
1946 HDF_CENTER, /* Links */
1947 #endif
1948 HDF_CENTER, /* Attributes */
1949 #ifndef _NO_EXTENSIONS
1950 HDF_LEFT /* Security */
1951 #endif
1954 static void resize_tree(ChildWnd* child, int cx, int cy)
1956 HDWP hdwp = BeginDeferWindowPos(4);
1957 RECT rt;
1959 rt.left = 0;
1960 rt.top = 0;
1961 rt.right = cx;
1962 rt.bottom = cy;
1964 cx = child->split_pos + SPLIT_WIDTH/2;
1966 #ifndef _NO_EXTENSIONS
1968 WINDOWPOS wp;
1969 HD_LAYOUT hdl;
1971 hdl.prc = &rt;
1972 hdl.pwpos = &wp;
1974 Header_Layout(child->left.hwndHeader, &hdl);
1976 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1977 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1978 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1979 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1981 #endif /* _NO_EXTENSIONS */
1983 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);
1984 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1986 EndDeferWindowPos(hdwp);
1990 #ifndef _NO_EXTENSIONS
1992 static HWND create_header(HWND parent, Pane* pane, int id)
1994 HD_ITEM hdi;
1995 int idx;
1997 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1998 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1999 if (!hwnd)
2000 return 0;
2002 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2004 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2006 for(idx=0; idx<COLUMNS; idx++) {
2007 hdi.pszText = g_pos_names[idx];
2008 hdi.fmt = HDF_STRING | g_pos_align[idx];
2009 hdi.cxy = pane->widths[idx];
2010 Header_InsertItem(hwnd, idx, &hdi);
2013 return hwnd;
2016 #endif /* _NO_EXTENSIONS */
2019 static void init_output(HWND hwnd)
2021 TCHAR b[16];
2022 HFONT old_font;
2023 HDC hdc = GetDC(hwnd);
2025 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
2026 Globals.num_sep = b[1];
2027 else
2028 Globals.num_sep = TEXT('.');
2030 old_font = SelectFont(hdc, Globals.hfont);
2031 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
2032 SelectFont(hdc, old_font);
2033 ReleaseDC(hwnd, hdc);
2036 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2039 /* calculate prefered width for all visible columns */
2041 static BOOL calc_widths(Pane* pane, BOOL anyway)
2043 int col, x, cx, spc=3*Globals.spaceSize.cx;
2044 int entries = ListBox_GetCount(pane->hwnd);
2045 int orgWidths[COLUMNS];
2046 int orgPositions[COLUMNS+1];
2047 HFONT hfontOld;
2048 HDC hdc;
2049 int cnt;
2051 if (!anyway) {
2052 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2053 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2056 for(col=0; col<COLUMNS; col++)
2057 pane->widths[col] = 0;
2059 hdc = GetDC(pane->hwnd);
2060 hfontOld = SelectFont(hdc, Globals.hfont);
2062 for(cnt=0; cnt<entries; cnt++) {
2063 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2065 DRAWITEMSTRUCT dis;
2067 dis.CtlType = 0;
2068 dis.CtlID = 0;
2069 dis.itemID = 0;
2070 dis.itemAction = 0;
2071 dis.itemState = 0;
2072 dis.hwndItem = pane->hwnd;
2073 dis.hDC = hdc;
2074 dis.rcItem.left = 0;
2075 dis.rcItem.top = 0;
2076 dis.rcItem.right = 0;
2077 dis.rcItem.bottom = 0;
2078 /*dis.itemData = 0; */
2080 draw_item(pane, &dis, entry, COLUMNS);
2083 SelectObject(hdc, hfontOld);
2084 ReleaseDC(pane->hwnd, hdc);
2086 x = 0;
2087 for(col=0; col<COLUMNS; col++) {
2088 pane->positions[col] = x;
2089 cx = pane->widths[col];
2091 if (cx) {
2092 cx += spc;
2094 if (cx < IMAGE_WIDTH)
2095 cx = IMAGE_WIDTH;
2097 pane->widths[col] = cx;
2100 x += cx;
2103 pane->positions[COLUMNS] = x;
2105 ListBox_SetHorizontalExtent(pane->hwnd, x);
2107 /* no change? */
2108 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2109 return FALSE;
2111 /* don't move, if only collapsing an entry */
2112 if (!anyway && pane->widths[0]<orgWidths[0] &&
2113 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2114 pane->widths[0] = orgWidths[0];
2115 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2117 return FALSE;
2120 InvalidateRect(pane->hwnd, 0, TRUE);
2122 return TRUE;
2126 /* calculate one prefered column width */
2128 static void calc_single_width(Pane* pane, int col)
2130 HFONT hfontOld;
2131 int x, cx;
2132 int entries = ListBox_GetCount(pane->hwnd);
2133 int cnt;
2134 HDC hdc;
2136 pane->widths[col] = 0;
2138 hdc = GetDC(pane->hwnd);
2139 hfontOld = SelectFont(hdc, Globals.hfont);
2141 for(cnt=0; cnt<entries; cnt++) {
2142 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2143 DRAWITEMSTRUCT dis;
2145 dis.CtlType = 0;
2146 dis.CtlID = 0;
2147 dis.itemID = 0;
2148 dis.itemAction = 0;
2149 dis.itemState = 0;
2150 dis.hwndItem = pane->hwnd;
2151 dis.hDC = hdc;
2152 dis.rcItem.left = 0;
2153 dis.rcItem.top = 0;
2154 dis.rcItem.right = 0;
2155 dis.rcItem.bottom = 0;
2156 /*dis.itemData = 0; */
2158 draw_item(pane, &dis, entry, col);
2161 SelectObject(hdc, hfontOld);
2162 ReleaseDC(pane->hwnd, hdc);
2164 cx = pane->widths[col];
2166 if (cx) {
2167 cx += 3*Globals.spaceSize.cx;
2169 if (cx < IMAGE_WIDTH)
2170 cx = IMAGE_WIDTH;
2173 pane->widths[col] = cx;
2175 x = pane->positions[col] + cx;
2177 for(; col<COLUMNS; ) {
2178 pane->positions[++col] = x;
2179 x += pane->widths[col];
2182 ListBox_SetHorizontalExtent(pane->hwnd, x);
2186 /* insert listbox entries after index idx */
2188 static void insert_entries(Pane* pane, Entry* dir, int idx)
2190 Entry* entry = dir;
2192 if (!entry)
2193 return;
2195 ShowWindow(pane->hwnd, SW_HIDE);
2197 for(; entry; entry=entry->next) {
2198 #ifndef _LEFT_FILES
2199 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2200 continue;
2201 #endif
2203 /* don't display entries "." and ".." in the left pane */
2204 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2205 && entry->data.cFileName[0]==TEXT('.'))
2206 if (
2207 #ifndef _NO_EXTENSIONS
2208 entry->data.cFileName[1]==TEXT('\0') ||
2209 #endif
2210 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2211 continue;
2213 if (idx != -1)
2214 idx++;
2216 ListBox_InsertItemData(pane->hwnd, idx, entry);
2218 if (pane->treePane && entry->expanded)
2219 insert_entries(pane, entry->down, idx);
2222 ShowWindow(pane->hwnd, SW_SHOW);
2226 static WNDPROC g_orgTreeWndProc;
2228 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2230 static int s_init = 0;
2231 Entry* entry = pane->root;
2233 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2234 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2235 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2237 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2238 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2240 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2242 /* insert entries into listbox */
2243 if (entry)
2244 insert_entries(pane, entry, -1);
2246 /* calculate column widths */
2247 if (!s_init) {
2248 s_init = 1;
2249 init_output(pane->hwnd);
2252 calc_widths(pane, TRUE);
2254 #ifndef _NO_EXTENSIONS
2255 pane->hwndHeader = create_header(parent, pane, id_header);
2256 #endif
2260 static void InitChildWindow(ChildWnd* child)
2262 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2263 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2267 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2269 SYSTEMTIME systime;
2270 FILETIME lft;
2271 int len = 0;
2273 *buffer = TEXT('\0');
2275 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2276 return;
2278 if (!FileTimeToLocalFileTime(ft, &lft))
2279 {err: _tcscpy(buffer,TEXT("???")); return;}
2281 if (!FileTimeToSystemTime(&lft, &systime))
2282 goto err;
2284 if (visible_cols & COL_DATE) {
2285 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2286 if (!len)
2287 goto err;
2290 if (visible_cols & COL_TIME) {
2291 if (len)
2292 buffer[len-1] = ' ';
2294 buffer[len++] = ' ';
2296 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2297 buffer[len] = TEXT('\0');
2302 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2304 RECT rt = {0, 0, 0, 0};
2306 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2308 if (rt.right > pane->widths[col])
2309 pane->widths[col] = rt.right;
2312 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2314 RECT rt = {0, 0, 0, 0};
2316 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2317 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2319 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2320 /*FIXME rt (0,0) ??? */
2322 if (rt.right > pane->widths[col])
2323 pane->widths[col] = rt.right;
2327 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2329 int x = dis->rcItem.left;
2330 RECT rt;
2332 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2333 rt.top = dis->rcItem.top;
2334 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2335 rt.bottom = dis->rcItem.bottom;
2337 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2340 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2342 int x = dis->rcItem.left;
2343 RECT rt;
2345 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2346 rt.top = dis->rcItem.top;
2347 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2348 rt.bottom = dis->rcItem.bottom;
2350 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2351 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2353 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2356 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2358 int x = dis->rcItem.left;
2359 RECT rt;
2360 LPCTSTR s = str;
2361 TCHAR b[128];
2362 LPTSTR d = b;
2363 int pos;
2365 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2366 rt.top = dis->rcItem.top;
2367 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2368 rt.bottom = dis->rcItem.bottom;
2370 if (*s)
2371 *d++ = *s++;
2373 /* insert number separator characters */
2374 pos = lstrlen(s) % 3;
2376 while(*s)
2377 if (pos--)
2378 *d++ = *s++;
2379 else {
2380 *d++ = Globals.num_sep;
2381 pos = 3;
2384 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2388 static int is_exe_file(LPCTSTR ext)
2390 static const LPCTSTR executable_extensions[] = {
2391 TEXT("COM"),
2392 TEXT("EXE"),
2393 TEXT("BAT"),
2394 TEXT("CMD"),
2395 #ifndef _NO_EXTENSIONS
2396 TEXT("CMM"),
2397 TEXT("BTM"),
2398 TEXT("AWK"),
2399 #endif /* _NO_EXTENSIONS */
2403 TCHAR ext_buffer[_MAX_EXT];
2404 const LPCTSTR* p;
2405 LPCTSTR s;
2406 LPTSTR d;
2408 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2409 d++;
2411 for(p=executable_extensions; *p; p++)
2412 if (!_tcscmp(ext_buffer, *p))
2413 return 1;
2415 return 0;
2418 static int is_registered_type(LPCTSTR ext)
2420 /* TODO */
2422 return 1;
2426 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2428 TCHAR buffer[BUFFER_LEN];
2429 DWORD attrs;
2430 int visible_cols = pane->visible_cols;
2431 COLORREF bkcolor, textcolor;
2432 RECT focusRect = dis->rcItem;
2433 HBRUSH hbrush;
2434 enum IMAGE img;
2435 int img_pos, cx;
2436 int col = 0;
2438 if (entry) {
2439 attrs = entry->data.dwFileAttributes;
2441 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2442 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2443 && entry->data.cFileName[2]==TEXT('\0'))
2444 img = IMG_FOLDER_UP;
2445 #ifndef _NO_EXTENSIONS
2446 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2447 img = IMG_FOLDER_CUR;
2448 #endif
2449 else if (
2450 #ifdef _NO_EXTENSIONS
2451 entry->expanded ||
2452 #endif
2453 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2454 img = IMG_OPEN_FOLDER;
2455 else
2456 img = IMG_FOLDER;
2457 } else {
2458 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2459 if (!ext)
2460 ext = TEXT("");
2462 if (is_exe_file(ext))
2463 img = IMG_EXECUTABLE;
2464 else if (is_registered_type(ext))
2465 img = IMG_DOCUMENT;
2466 else
2467 img = IMG_FILE;
2469 } else {
2470 attrs = 0;
2471 img = IMG_NONE;
2474 if (pane->treePane) {
2475 if (entry) {
2476 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2478 if (calcWidthCol == -1) {
2479 int x;
2480 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2481 Entry* up;
2482 RECT rt_clip;
2483 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2484 HRGN hrgn;
2486 rt_clip.left = dis->rcItem.left;
2487 rt_clip.top = dis->rcItem.top;
2488 rt_clip.right = dis->rcItem.left+pane->widths[col];
2489 rt_clip.bottom = dis->rcItem.bottom;
2491 hrgn = CreateRectRgnIndirect(&rt_clip);
2493 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2494 DeleteObject(hrgn_org);
2495 hrgn_org = 0;
2498 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2499 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2500 DeleteObject(hrgn);
2502 if ((up=entry->up) != NULL) {
2503 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2504 LineTo(dis->hDC, img_pos-2, y);
2506 x = img_pos - IMAGE_WIDTH/2;
2508 do {
2509 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2511 if (up->next
2512 #ifndef _LEFT_FILES
2513 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2514 #endif
2516 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2517 LineTo(dis->hDC, x, dis->rcItem.bottom);
2519 } while((up=up->up) != NULL);
2522 x = img_pos - IMAGE_WIDTH/2;
2524 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2525 LineTo(dis->hDC, x, y);
2527 if (entry->next
2528 #ifndef _LEFT_FILES
2529 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2530 #endif
2532 LineTo(dis->hDC, x, dis->rcItem.bottom);
2534 if (entry->down && entry->expanded) {
2535 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2536 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2537 LineTo(dis->hDC, x, dis->rcItem.bottom);
2540 SelectClipRgn(dis->hDC, hrgn_org);
2541 if (hrgn_org) DeleteObject(hrgn_org);
2542 /* SelectObject(dis->hDC, holdPen); */
2543 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2544 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2546 if (right > pane->widths[col])
2547 pane->widths[col] = right;
2549 } else {
2550 img_pos = dis->rcItem.left;
2552 } else {
2553 img_pos = dis->rcItem.left;
2555 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2556 pane->widths[col] = IMAGE_WIDTH;
2559 if (calcWidthCol == -1) {
2560 focusRect.left = img_pos -2;
2562 #ifdef _NO_EXTENSIONS
2563 if (pane->treePane && entry) {
2564 RECT rt = {0};
2566 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2568 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2570 #else
2572 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2573 textcolor = COLOR_COMPRESSED;
2574 else
2575 #endif /* _NO_EXTENSIONS */
2576 textcolor = RGB(0,0,0);
2578 if (dis->itemState & ODS_FOCUS) {
2579 textcolor = RGB(255,255,255);
2580 bkcolor = COLOR_SELECTION;
2581 } else {
2582 bkcolor = RGB(255,255,255);
2585 hbrush = CreateSolidBrush(bkcolor);
2586 FillRect(dis->hDC, &focusRect, hbrush);
2587 DeleteObject(hbrush);
2589 SetBkMode(dis->hDC, TRANSPARENT);
2590 SetTextColor(dis->hDC, textcolor);
2592 cx = pane->widths[col];
2594 if (cx && img!=IMG_NONE) {
2595 if (cx > IMAGE_WIDTH)
2596 cx = IMAGE_WIDTH;
2598 #ifdef _SHELL_FOLDERS
2599 if (entry->hicon && entry->hicon!=(HICON)-1)
2600 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2601 else
2602 #endif
2603 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2604 img_pos, dis->rcItem.top, cx,
2605 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2609 if (!entry)
2610 return;
2612 #ifdef _NO_EXTENSIONS
2613 if (img >= IMG_FOLDER_UP)
2614 return;
2615 #endif
2617 col++;
2619 /* ouput file name */
2620 if (calcWidthCol == -1)
2621 output_text(pane, dis, col, entry->data.cFileName, 0);
2622 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2623 calc_width(pane, dis, col, entry->data.cFileName);
2625 col++;
2627 #ifdef _NO_EXTENSIONS
2628 if (!pane->treePane) {
2629 #endif
2631 /* display file size */
2632 if (visible_cols & COL_SIZE) {
2633 #ifdef _NO_EXTENSIONS
2634 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2635 #endif
2637 ULONGLONG size;
2639 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2641 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2643 if (calcWidthCol == -1)
2644 output_number(pane, dis, col, buffer);
2645 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2646 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2649 col++;
2652 /* display file date */
2653 if (visible_cols & (COL_DATE|COL_TIME)) {
2654 #ifndef _NO_EXTENSIONS
2655 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2656 if (calcWidthCol == -1)
2657 output_text(pane, dis, col, buffer, 0);
2658 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2659 calc_width(pane, dis, col, buffer);
2660 col++;
2662 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2663 if (calcWidthCol == -1)
2664 output_text(pane, dis, col, buffer, 0);
2665 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2666 calc_width(pane, dis, col, buffer);
2667 col++;
2668 #endif /* _NO_EXTENSIONS */
2670 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2671 if (calcWidthCol == -1)
2672 output_text(pane, dis, col, buffer, 0);
2673 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2674 calc_width(pane, dis, col, buffer);
2675 col++;
2678 #ifndef _NO_EXTENSIONS
2679 if (entry->bhfi_valid) {
2680 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2682 if (visible_cols & COL_INDEX) {
2683 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2684 if (calcWidthCol == -1)
2685 output_text(pane, dis, col, buffer, DT_RIGHT);
2686 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2687 calc_width(pane, dis, col, buffer);
2688 col++;
2691 if (visible_cols & COL_LINKS) {
2692 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2693 if (calcWidthCol == -1)
2694 output_text(pane, dis, col, buffer, DT_CENTER);
2695 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2696 calc_width(pane, dis, col, buffer);
2697 col++;
2699 } else
2700 col += 2;
2701 #endif /* _NO_EXTENSIONS */
2703 /* show file attributes */
2704 if (visible_cols & COL_ATTRIBUTES) {
2705 #ifdef _NO_EXTENSIONS
2706 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2707 #else
2708 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2709 #endif
2711 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2712 else {
2713 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2714 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2715 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2716 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2717 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2718 #ifndef _NO_EXTENSIONS
2719 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2720 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2721 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2722 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2723 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2724 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2725 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2726 #endif /* _NO_EXTENSIONS */
2729 if (calcWidthCol == -1)
2730 output_tabbed_text(pane, dis, col, buffer);
2731 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2732 calc_tabbed_width(pane, dis, col, buffer);
2734 col++;
2737 /*TODO
2738 if (flags.security) {
2739 DWORD rights = get_access_mask();
2741 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2743 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2744 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2745 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2746 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2747 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2748 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2749 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2750 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2751 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2752 if (rights & WRITE_DAC) buffer[22] = 'C';
2753 if (rights & WRITE_OWNER) buffer[24] = 'O';
2754 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2756 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2759 if (flags.description) {
2760 get_description(buffer);
2761 output_text(dis, col++, buffer, 0, psize);
2765 #ifdef _NO_EXTENSIONS
2768 /* draw focus frame */
2769 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2770 /* Currently [04/2000] Wine neither behaves exactly the same */
2771 /* way as WIN 95 nor like Windows NT... */
2772 HGDIOBJ lastBrush;
2773 HPEN lastPen;
2774 HPEN hpen;
2776 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2777 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2778 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2779 } else
2780 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2782 lastPen = SelectPen(dis->hDC, hpen);
2783 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2784 SetROP2(dis->hDC, R2_XORPEN);
2785 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2786 SelectObject(dis->hDC, lastBrush);
2787 SelectObject(dis->hDC, lastPen);
2788 DeleteObject(hpen);
2790 #endif /* _NO_EXTENSIONS */
2794 #ifdef _NO_EXTENSIONS
2796 static void draw_splitbar(HWND hwnd, int x)
2798 RECT rt;
2799 HDC hdc = GetDC(hwnd);
2801 GetClientRect(hwnd, &rt);
2803 rt.left = x - SPLIT_WIDTH/2;
2804 rt.right = x + SPLIT_WIDTH/2+1;
2806 InvertRect(hdc, &rt);
2808 ReleaseDC(hwnd, hdc);
2811 #endif /* _NO_EXTENSIONS */
2814 #ifndef _NO_EXTENSIONS
2816 static void set_header(Pane* pane)
2818 HD_ITEM item;
2819 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2820 int i=0, x=0;
2822 item.mask = HDI_WIDTH;
2823 item.cxy = 0;
2825 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2826 x += pane->widths[i];
2827 Header_SetItem(pane->hwndHeader, i, &item);
2830 if (i < COLUMNS) {
2831 x += pane->widths[i];
2832 item.cxy = x - scroll_pos;
2833 Header_SetItem(pane->hwndHeader, i++, &item);
2835 for(; i<COLUMNS; i++) {
2836 item.cxy = pane->widths[i];
2837 x += pane->widths[i];
2838 Header_SetItem(pane->hwndHeader, i, &item);
2843 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2845 switch(pnmh->code) {
2846 case HDN_TRACK:
2847 case HDN_ENDTRACK: {
2848 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2849 int idx = phdn->iItem;
2850 int dx = phdn->pitem->cxy - pane->widths[idx];
2851 int i;
2853 RECT clnt;
2854 GetClientRect(pane->hwnd, &clnt);
2856 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2857 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2859 pane->widths[idx] += dx;
2861 for(i=idx; ++i<=COLUMNS; )
2862 pane->positions[i] += dx;
2865 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2866 RECT rt_scr;
2867 RECT rt_clip;
2869 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2870 rt_scr.top = 0;
2871 rt_scr.right = clnt.right;
2872 rt_scr.bottom = clnt.bottom;
2874 rt_clip.left = pane->positions[idx]-scroll_pos;
2875 rt_clip.top = 0;
2876 rt_clip.right = clnt.right;
2877 rt_clip.bottom = clnt.bottom;
2879 if (rt_scr.left < 0) rt_scr.left = 0;
2880 if (rt_clip.left < 0) rt_clip.left = 0;
2882 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2884 rt_clip.right = pane->positions[idx+1];
2885 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2887 if (pnmh->code == HDN_ENDTRACK) {
2888 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2890 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2891 set_header(pane);
2895 return FALSE;
2898 case HDN_DIVIDERDBLCLICK: {
2899 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2900 HD_ITEM item;
2902 calc_single_width(pane, phdn->iItem);
2903 item.mask = HDI_WIDTH;
2904 item.cxy = pane->widths[phdn->iItem];
2906 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2907 InvalidateRect(pane->hwnd, 0, TRUE);
2908 break;}
2911 return 0;
2914 #endif /* _NO_EXTENSIONS */
2917 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2919 TCHAR path[MAX_PATH];
2920 int idx = ListBox_GetCurSel(child->left.hwnd);
2921 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2923 /* delete sub entries in left pane */
2924 for(;;) {
2925 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2926 Entry* sub = (Entry*) res;
2928 if (res==LB_ERR || !sub || sub->level<=entry->level)
2929 break;
2931 ListBox_DeleteString(child->left.hwnd, idx+1);
2934 /* empty right pane */
2935 ListBox_ResetContent(child->right.hwnd);
2937 /* release memory */
2938 free_entries(entry);
2940 /* read contents from disk */
2941 #ifdef _SHELL_FOLDERS
2942 if (entry->etype == ET_SHELL)
2944 read_directory(entry, NULL, child->sortOrder, hwnd);
2946 else
2947 #endif
2949 get_path(entry, path);
2950 read_directory(entry, path, child->sortOrder, hwnd);
2953 /* insert found entries in right pane */
2954 insert_entries(&child->right, entry->down, -1);
2955 calc_widths(&child->right, FALSE);
2956 #ifndef _NO_EXTENSIONS
2957 set_header(&child->right);
2958 #endif
2960 child->header_wdths_ok = FALSE;
2962 SetCursor(old_cursor);
2966 /* expand a directory entry */
2968 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2970 int idx;
2971 Entry* p;
2973 if (!dir || dir->expanded || !dir->down)
2974 return FALSE;
2976 p = dir->down;
2978 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2979 p = p->next;
2981 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2982 p->data.cFileName[2]=='\0' && p->next)
2983 p = p->next;
2986 /* no subdirectories ? */
2987 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2988 return FALSE;
2990 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2992 dir->expanded = TRUE;
2994 /* insert entries in left pane */
2995 insert_entries(&child->left, p, idx);
2997 if (!child->header_wdths_ok) {
2998 if (calc_widths(&child->left, FALSE)) {
2999 #ifndef _NO_EXTENSIONS
3000 set_header(&child->left);
3001 #endif
3003 child->header_wdths_ok = TRUE;
3007 return TRUE;
3011 static void collapse_entry(Pane* pane, Entry* dir)
3013 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3015 ShowWindow(pane->hwnd, SW_HIDE);
3017 /* hide sub entries */
3018 for(;;) {
3019 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3020 Entry* sub = (Entry*) res;
3022 if (res==LB_ERR || !sub || sub->level<=dir->level)
3023 break;
3025 ListBox_DeleteString(pane->hwnd, idx+1);
3028 dir->expanded = FALSE;
3030 ShowWindow(pane->hwnd, SW_SHOW);
3034 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
3036 TCHAR path[MAX_PATH];
3038 path[0] = '\0';
3040 child->left.cur = entry;
3041 child->right.root = entry->down? entry->down: entry;
3042 child->right.cur = entry;
3044 if (!entry->scanned)
3045 scan_entry(child, entry, hwnd);
3046 else {
3047 ListBox_ResetContent(child->right.hwnd);
3048 insert_entries(&child->right, entry->down, -1);
3049 calc_widths(&child->right, FALSE);
3050 #ifndef _NO_EXTENSIONS
3051 set_header(&child->right);
3052 #endif
3055 get_path(entry, path);
3056 lstrcpy(child->path, path);
3058 if (child->hwnd) /* only change window title, if the window already exists */
3059 SetWindowText(child->hwnd, path);
3061 if (path[0])
3062 SetCurrentDirectory(path);
3066 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3068 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3070 if ((int)hinst <= 32) {
3071 display_error(hwnd, GetLastError());
3072 return FALSE;
3075 return TRUE;
3078 #ifdef UNICODE
3079 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3081 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3083 if ((int)hinst <= 32) {
3084 display_error(hwnd, GetLastError());
3085 return FALSE;
3088 return TRUE;
3090 #endif
3093 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3095 TCHAR cmd[MAX_PATH];
3097 #ifdef _SHELL_FOLDERS
3098 if (entry->etype == ET_SHELL) {
3099 BOOL ret = TRUE;
3101 SHELLEXECUTEINFO shexinfo;
3103 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3104 shexinfo.fMask = SEE_MASK_IDLIST;
3105 shexinfo.hwnd = hwnd;
3106 shexinfo.lpVerb = NULL;
3107 shexinfo.lpFile = NULL;
3108 shexinfo.lpParameters = NULL;
3109 shexinfo.lpDirectory = NULL;
3110 shexinfo.nShow = nCmdShow;
3111 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3113 if (!ShellExecuteEx(&shexinfo)) {
3114 display_error(hwnd, GetLastError());
3115 ret = FALSE;
3118 if (shexinfo.lpIDList != entry->pidl)
3119 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3121 return ret;
3123 #endif
3125 get_path(entry, cmd);
3127 /* start program, open document... */
3128 return launch_file(hwnd, cmd, nCmdShow);
3132 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3134 Entry* entry = pane->cur;
3136 if (!entry)
3137 return;
3139 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3140 int scanned_old = entry->scanned;
3142 if (!scanned_old)
3143 scan_entry(child, entry, hwnd);
3145 #ifndef _NO_EXTENSIONS
3146 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3147 return;
3148 #endif
3150 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3151 entry = child->left.cur->up;
3152 collapse_entry(&child->left, entry);
3153 goto focus_entry;
3154 } else if (entry->expanded)
3155 collapse_entry(pane, child->left.cur);
3156 else {
3157 expand_entry(child, child->left.cur);
3159 if (!pane->treePane) focus_entry: {
3160 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3161 ListBox_SetCurSel(child->left.hwnd, idx);
3162 set_curdir(child, entry, hwnd);
3166 if (!scanned_old) {
3167 calc_widths(pane, FALSE);
3169 #ifndef _NO_EXTENSIONS
3170 set_header(pane);
3171 #endif
3173 } else {
3174 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3179 static BOOL pane_command(Pane* pane, UINT cmd)
3181 switch(cmd) {
3182 case ID_VIEW_NAME:
3183 if (pane->visible_cols) {
3184 pane->visible_cols = 0;
3185 calc_widths(pane, TRUE);
3186 #ifndef _NO_EXTENSIONS
3187 set_header(pane);
3188 #endif
3189 InvalidateRect(pane->hwnd, 0, TRUE);
3190 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3191 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3192 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3194 break;
3196 case ID_VIEW_ALL_ATTRIBUTES:
3197 if (pane->visible_cols != COL_ALL) {
3198 pane->visible_cols = COL_ALL;
3199 calc_widths(pane, TRUE);
3200 #ifndef _NO_EXTENSIONS
3201 set_header(pane);
3202 #endif
3203 InvalidateRect(pane->hwnd, 0, TRUE);
3204 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3205 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3206 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3208 break;
3210 #ifndef _NO_EXTENSIONS
3211 case ID_PREFERED_SIZES: {
3212 calc_widths(pane, TRUE);
3213 set_header(pane);
3214 InvalidateRect(pane->hwnd, 0, TRUE);
3215 break;}
3216 #endif
3218 /* TODO: more command ids... */
3220 default:
3221 return FALSE;
3224 return TRUE;
3228 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3230 IContextMenu* pcm;
3232 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3233 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3235 if (SUCCEEDED(hr)) {
3236 HMENU hmenu = CreatePopupMenu();
3238 if (hmenu) {
3239 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3241 if (SUCCEEDED(hr)) {
3242 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3244 if (idCmd) {
3245 CMINVOKECOMMANDINFO cmi;
3247 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3248 cmi.fMask = 0;
3249 cmi.hwnd = hwndParent;
3250 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3251 cmi.lpParameters = NULL;
3252 cmi.lpDirectory = NULL;
3253 cmi.nShow = SW_SHOWNORMAL;
3254 cmi.dwHotKey = 0;
3255 cmi.hIcon = 0;
3257 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3262 (*pcm->lpVtbl->Release)(pcm);
3265 return hr;
3269 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3271 static int last_split;
3273 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3274 ASSERT(child);
3276 switch(nmsg) {
3277 case WM_DRAWITEM: {
3278 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3279 Entry* entry = (Entry*) dis->itemData;
3281 if (dis->CtlID == IDW_TREE_LEFT)
3282 draw_item(&child->left, dis, entry, -1);
3283 else
3284 draw_item(&child->right, dis, entry, -1);
3286 return TRUE;}
3288 case WM_CREATE:
3289 InitChildWindow(child);
3290 break;
3292 case WM_NCDESTROY:
3293 free_child_window(child);
3294 SetWindowLong(hwnd, GWL_USERDATA, 0);
3295 break;
3297 case WM_PAINT: {
3298 PAINTSTRUCT ps;
3299 HBRUSH lastBrush;
3300 RECT rt;
3301 GetClientRect(hwnd, &rt);
3302 BeginPaint(hwnd, &ps);
3303 rt.left = child->split_pos-SPLIT_WIDTH/2;
3304 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3305 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3306 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3307 SelectObject(ps.hdc, lastBrush);
3308 #ifdef _NO_EXTENSIONS
3309 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3310 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3311 #endif
3312 EndPaint(hwnd, &ps);
3313 break;}
3315 case WM_SETCURSOR:
3316 if (LOWORD(lparam) == HTCLIENT) {
3317 POINT pt;
3318 GetCursorPos(&pt);
3319 ScreenToClient(hwnd, &pt);
3321 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3322 SetCursor(LoadCursor(0, IDC_SIZEWE));
3323 return TRUE;
3326 goto def;
3328 case WM_LBUTTONDOWN: {
3329 RECT rt;
3330 int x = LOWORD(lparam);
3332 GetClientRect(hwnd, &rt);
3334 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3335 last_split = child->split_pos;
3336 #ifdef _NO_EXTENSIONS
3337 draw_splitbar(hwnd, last_split);
3338 #endif
3339 SetCapture(hwnd);
3342 break;}
3344 case WM_LBUTTONUP:
3345 if (GetCapture() == hwnd) {
3346 #ifdef _NO_EXTENSIONS
3347 RECT rt;
3348 int x = LOWORD(lparam);
3349 draw_splitbar(hwnd, last_split);
3350 last_split = -1;
3351 GetClientRect(hwnd, &rt);
3352 child->split_pos = x;
3353 resize_tree(child, rt.right, rt.bottom);
3354 #endif
3355 ReleaseCapture();
3357 break;
3359 #ifdef _NO_EXTENSIONS
3360 case WM_CAPTURECHANGED:
3361 if (GetCapture()==hwnd && last_split>=0)
3362 draw_splitbar(hwnd, last_split);
3363 break;
3364 #endif
3366 case WM_KEYDOWN:
3367 if (wparam == VK_ESCAPE)
3368 if (GetCapture() == hwnd) {
3369 RECT rt;
3370 #ifdef _NO_EXTENSIONS
3371 draw_splitbar(hwnd, last_split);
3372 #else
3373 child->split_pos = last_split;
3374 #endif
3375 GetClientRect(hwnd, &rt);
3376 resize_tree(child, rt.right, rt.bottom);
3377 last_split = -1;
3378 ReleaseCapture();
3379 SetCursor(LoadCursor(0, IDC_ARROW));
3381 break;
3383 case WM_MOUSEMOVE:
3384 if (GetCapture() == hwnd) {
3385 RECT rt;
3386 int x = LOWORD(lparam);
3388 #ifdef _NO_EXTENSIONS
3389 HDC hdc = GetDC(hwnd);
3390 GetClientRect(hwnd, &rt);
3392 rt.left = last_split-SPLIT_WIDTH/2;
3393 rt.right = last_split+SPLIT_WIDTH/2+1;
3394 InvertRect(hdc, &rt);
3396 last_split = x;
3397 rt.left = x-SPLIT_WIDTH/2;
3398 rt.right = x+SPLIT_WIDTH/2+1;
3399 InvertRect(hdc, &rt);
3401 ReleaseDC(hwnd, hdc);
3402 #else
3403 GetClientRect(hwnd, &rt);
3405 if (x>=0 && x<rt.right) {
3406 child->split_pos = x;
3407 resize_tree(child, rt.right, rt.bottom);
3408 rt.left = x-SPLIT_WIDTH/2;
3409 rt.right = x+SPLIT_WIDTH/2+1;
3410 InvalidateRect(hwnd, &rt, FALSE);
3411 UpdateWindow(child->left.hwnd);
3412 UpdateWindow(hwnd);
3413 UpdateWindow(child->right.hwnd);
3415 #endif
3417 break;
3419 #ifndef _NO_EXTENSIONS
3420 case WM_GETMINMAXINFO:
3421 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3423 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3425 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3426 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3427 break;}
3428 #endif /* _NO_EXTENSIONS */
3430 case WM_SETFOCUS:
3431 SetCurrentDirectory(child->path);
3432 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3433 break;
3435 case WM_DISPATCH_COMMAND: {
3436 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3438 switch(LOWORD(wparam)) {
3439 case ID_WINDOW_NEW: {
3440 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3442 if (!create_child_window(new_child))
3443 free(new_child);
3445 break;}
3447 case ID_REFRESH:
3448 scan_entry(child, pane->cur, hwnd);
3449 break;
3451 case ID_ACTIVATE:
3452 activate_entry(child, pane, hwnd);
3453 break;
3455 default:
3456 return pane_command(pane, LOWORD(wparam));
3459 return TRUE;}
3461 case WM_COMMAND: {
3462 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3464 switch(HIWORD(wparam)) {
3465 case LBN_SELCHANGE: {
3466 int idx = ListBox_GetCurSel(pane->hwnd);
3467 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3469 if (pane == &child->left)
3470 set_curdir(child, entry, hwnd);
3471 else
3472 pane->cur = entry;
3473 break;}
3475 case LBN_DBLCLK:
3476 activate_entry(child, pane, hwnd);
3477 break;
3479 break;}
3481 #ifndef _NO_EXTENSIONS
3482 case WM_NOTIFY: {
3483 NMHDR* pnmh = (NMHDR*) lparam;
3484 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3485 #endif
3487 #ifdef _SHELL_FOLDERS
3488 case WM_CONTEXTMENU: {
3489 Pane* pane;
3490 int idx;
3492 /* first select the current item in the listbox */
3493 HWND hpanel = (HWND) wparam;
3494 POINTS* ppos = &MAKEPOINTS(lparam);
3495 POINT pt; POINTSTOPOINT(pt, *ppos);
3496 ScreenToClient(hpanel, &pt);
3497 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y));
3498 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
3500 /* now create the popup menu using shell namespace and IContextMenu */
3501 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3502 idx = ListBox_GetCurSel(pane->hwnd);
3504 if (idx != -1) {
3505 HRESULT hr;
3506 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3508 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3510 if (pidl_abs) {
3511 IShellFolder* parentFolder;
3512 LPCITEMIDLIST pidlLast;
3514 /* get and use the parent folder to display correct context menu in all cases */
3515 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3516 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, ppos->x, ppos->y);
3518 (*parentFolder->lpVtbl->Release)(parentFolder);
3521 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
3524 break;}
3525 #endif
3527 case WM_SIZE:
3528 if (wparam != SIZE_MINIMIZED)
3529 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3530 /* fall through */
3532 default: def:
3533 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3536 return 0;
3540 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3542 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3543 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3544 ASSERT(child);
3546 switch(nmsg) {
3547 #ifndef _NO_EXTENSIONS
3548 case WM_HSCROLL:
3549 set_header(pane);
3550 break;
3551 #endif
3553 case WM_SETFOCUS:
3554 child->focus_pane = pane==&child->right? 1: 0;
3555 ListBox_SetSel(hwnd, TRUE, 1);
3556 /*TODO: check menu items */
3557 break;
3559 case WM_KEYDOWN:
3560 if (wparam == VK_TAB) {
3561 /*TODO: SetFocus(Globals.hdrivebar) */
3562 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3566 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3570 static void InitInstance(HINSTANCE hinstance)
3572 WNDCLASSEX wcFrame;
3573 WNDCLASS wcChild;
3574 ATOM hChildClass;
3576 INITCOMMONCONTROLSEX icc = {
3577 sizeof(INITCOMMONCONTROLSEX),
3578 ICC_BAR_CLASSES
3581 HDC hdc = GetDC(0);
3583 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3585 InitCommonControlsEx(&icc);
3588 /* register frame window class */
3590 wcFrame.cbSize = sizeof(WNDCLASSEX);
3591 wcFrame.style = 0;
3592 wcFrame.lpfnWndProc = FrameWndProc;
3593 wcFrame.cbClsExtra = 0;
3594 wcFrame.cbWndExtra = 0;
3595 wcFrame.hInstance = hinstance;
3596 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3597 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3598 wcFrame.hbrBackground = 0;
3599 wcFrame.lpszMenuName = 0;
3600 wcFrame.lpszClassName = WINEFILEFRAME;
3601 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3602 MAKEINTRESOURCE(IDI_WINEFILE),
3603 IMAGE_ICON,
3604 GetSystemMetrics(SM_CXSMICON),
3605 GetSystemMetrics(SM_CYSMICON),
3606 LR_SHARED);
3608 Globals.hframeClass = RegisterClassEx(&wcFrame);
3611 /* register tree windows class */
3613 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3614 wcChild.lpfnWndProc = ChildWndProc;
3615 wcChild.cbClsExtra = 0;
3616 wcChild.cbWndExtra = 0;
3617 wcChild.hInstance = hinstance;
3618 wcChild.hIcon = 0;
3619 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3620 wcChild.hbrBackground = 0;
3621 wcChild.lpszMenuName = 0;
3622 wcChild.lpszClassName = WINEFILETREE;
3624 hChildClass = RegisterClass(&wcChild);
3627 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3629 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"));
3631 ReleaseDC(0, hdc);
3633 Globals.hInstance = hinstance;
3635 #ifdef _SHELL_FOLDERS
3636 CoInitialize(NULL);
3637 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3638 SHGetDesktopFolder(&Globals.iDesktop);
3639 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3640 #endif
3644 void show_frame(HWND hwndParent, int cmdshow)
3646 TCHAR path[MAX_PATH];
3647 ChildWnd* child;
3648 HMENU hMenuFrame, hMenuWindow;
3650 CLIENTCREATESTRUCT ccs;
3652 if (Globals.hMainWnd)
3653 return;
3655 Globals.hwndParent = hwndParent;
3657 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3658 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3660 Globals.hMenuFrame = hMenuFrame;
3661 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3662 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3664 ccs.hWindowMenu = hMenuWindow;
3665 ccs.idFirstChild = IDW_FIRST_CHILD;
3668 /* create main window */
3669 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3670 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3671 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3674 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3675 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3676 0, 0, 0, 0,
3677 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3681 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3682 int btn = 1;
3683 PTSTR p;
3685 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3686 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3687 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3688 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3690 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3692 drivebarBtn.fsStyle = BTNS_BUTTON;
3694 #ifndef _NO_EXTENSIONS
3695 #ifdef __WINE__
3696 /* insert unix file system button */
3697 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3699 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3700 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3701 drivebarBtn.iString++;
3702 #endif
3703 #ifdef _SHELL_FOLDERS
3704 /* insert shell namespace button */
3705 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3707 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3708 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3709 drivebarBtn.iString++;
3710 #endif
3712 /* register windows drive root strings */
3713 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3714 #endif
3716 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3718 for(p=Globals.drives; *p; ) {
3719 #ifdef _NO_EXTENSIONS
3720 /* insert drive letter */
3721 TCHAR b[3] = {tolower(*p)};
3722 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3723 #endif
3724 switch(GetDriveType(p)) {
3725 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3726 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3727 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3728 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3729 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3732 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3733 drivebarBtn.idCommand++;
3734 drivebarBtn.iString++;
3736 while(*p++);
3741 TBBUTTON toolbarBtns[] = {
3742 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3743 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3744 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3745 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3746 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3747 /*TODO
3748 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3749 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3750 */ };
3752 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3753 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3754 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3755 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3758 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3759 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3761 /* CreateStatusWindow does not accept WS_BORDER
3762 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3763 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3764 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3766 /*TODO: read paths and window placements from registry */
3767 GetCurrentDirectory(MAX_PATH, path);
3769 ShowWindow(Globals.hMainWnd, cmdshow);
3771 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3772 /* Shell Namespace as default: */
3773 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3774 #else
3775 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3776 #endif
3778 child->pos.showCmd = SW_SHOWMAXIMIZED;
3779 child->pos.rcNormalPosition.left = 0;
3780 child->pos.rcNormalPosition.top = 0;
3781 child->pos.rcNormalPosition.right = 320;
3782 child->pos.rcNormalPosition.bottom = 280;
3784 if (!create_child_window(child))
3785 free(child);
3787 SetWindowPlacement(child->hwnd, &child->pos);
3789 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3791 Globals.prescan_node = FALSE;
3793 UpdateWindow(Globals.hMainWnd);
3796 void ExitInstance()
3798 #ifdef _SHELL_FOLDERS
3799 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3800 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3801 CoUninitialize();
3802 #endif
3804 ImageList_Destroy(Globals.himl);
3808 /* search for already running win[e]files */
3810 static int g_foundPrevInstance = 0;
3812 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3814 TCHAR cls[128];
3816 GetClassName(hwnd, cls, 128);
3818 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3819 g_foundPrevInstance++;
3820 return FALSE;
3823 return TRUE;
3826 /* search for window of given class name to allow only one running instance */
3827 int find_window_class(LPCTSTR classname)
3829 EnumWindows(EnumWndProc, (LPARAM)classname);
3831 if (g_foundPrevInstance)
3832 return 1;
3834 return 0;
3838 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3840 MSG msg;
3842 InitInstance(hinstance);
3844 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3845 if (cmdshow == SW_SHOWNORMAL)
3846 /*TODO: read window placement from registry */
3847 cmdshow = SW_MAXIMIZE;
3848 #endif
3850 show_frame(hwndParent, cmdshow);
3852 while(GetMessage(&msg, 0, 0, 0)) {
3853 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3854 continue;
3856 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3857 continue;
3859 TranslateMessage(&msg);
3860 DispatchMessage(&msg);
3863 ExitInstance();
3865 return msg.wParam;
3869 #ifndef _ROS_
3871 int APIENTRY WinMain(HINSTANCE hinstance,
3872 HINSTANCE previnstance,
3873 LPSTR cmdline,
3874 int cmdshow)
3876 #ifdef _NO_EXTENSIONS
3877 if (find_window_class(WINEFILEFRAME))
3878 return 1;
3879 #endif
3881 winefile_main(hinstance, 0, cmdshow);
3883 return 0;
3886 #endif