Add some new message names to the message spy.
[wine/dcerpc.git] / programs / winefile / winefile.c
blob4e775dbab81ea7f5cc1de5a19cd26a02a8712f87
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 /* directories first... */
991 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
993 int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
994 int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
996 return dir2==dir1? 0: dir2<dir1? -1: 1;
1000 static int compareName(const void* arg1, const void* arg2)
1002 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1003 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1005 int cmp = compareType(fd1, fd2);
1006 if (cmp)
1007 return cmp;
1009 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1012 static int compareExt(const void* arg1, const void* arg2)
1014 const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1015 const WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1016 const TCHAR *name1, *name2, *ext1, *ext2;
1018 int cmp = compareType(fd1, fd2);
1019 if (cmp)
1020 return cmp;
1022 name1 = fd1->cFileName;
1023 name2 = fd2->cFileName;
1025 ext1 = _tcsrchr(name1, TEXT('.'));
1026 ext2 = _tcsrchr(name2, TEXT('.'));
1028 if (ext1)
1029 ext1++;
1030 else
1031 ext1 = TEXT("");
1033 if (ext2)
1034 ext2++;
1035 else
1036 ext2 = TEXT("");
1038 cmp = lstrcmpi(ext1, ext2);
1039 if (cmp)
1040 return cmp;
1042 return lstrcmpi(name1, name2);
1045 static int compareSize(const void* arg1, const void* arg2)
1047 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1048 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1050 int cmp = compareType(fd1, fd2);
1051 if (cmp)
1052 return cmp;
1054 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1056 if (cmp < 0)
1057 return -1;
1058 else if (cmp > 0)
1059 return 1;
1061 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1063 return cmp<0? -1: cmp>0? 1: 0;
1066 static int compareDate(const void* arg1, const void* arg2)
1068 WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->data;
1069 WIN32_FIND_DATA* fd2 = &(*(Entry**)arg2)->data;
1071 int cmp = compareType(fd1, fd2);
1072 if (cmp)
1073 return cmp;
1075 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1079 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1080 compareName, /* SORT_NAME */
1081 compareExt, /* SORT_EXT */
1082 compareSize, /* SORT_SIZE */
1083 compareDate /* SORT_DATE */
1087 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1089 Entry* entry = dir->down;
1090 Entry** array, **p;
1091 int len;
1093 len = 0;
1094 for(entry=dir->down; entry; entry=entry->next)
1095 len++;
1097 if (len) {
1098 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1100 p = array;
1101 for(entry=dir->down; entry; entry=entry->next)
1102 *p++ = entry;
1104 /* call qsort with the appropriate compare function */
1105 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1107 dir->down = array[0];
1109 for(p=array; --len; p++)
1110 p[0]->next = p[1];
1112 (*p)->next = 0;
1113 HeapFree( GetProcessHeap(), 0, array );
1118 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1120 TCHAR buffer[MAX_PATH];
1121 Entry* entry;
1122 LPCTSTR s;
1123 PTSTR d;
1125 #ifdef _SHELL_FOLDERS
1126 if (dir->etype == ET_SHELL)
1128 read_directory_shell(dir, hwnd);
1130 if (Globals.prescan_node) {
1131 s = path;
1132 d = buffer;
1134 while(*s)
1135 *d++ = *s++;
1137 *d++ = TEXT('\\');
1139 for(entry=dir->down; entry; entry=entry->next)
1140 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1141 read_directory_shell(entry, hwnd);
1142 SortDirectory(entry, sortOrder);
1146 else
1147 #endif
1148 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1149 if (dir->etype == ET_UNIX)
1151 read_directory_unix(dir, path);
1153 if (Globals.prescan_node) {
1154 s = path;
1155 d = buffer;
1157 while(*s)
1158 *d++ = *s++;
1160 *d++ = TEXT('/');
1162 for(entry=dir->down; entry; entry=entry->next)
1163 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1164 lstrcpy(d, entry->data.cFileName);
1165 read_directory_unix(entry, buffer);
1166 SortDirectory(entry, sortOrder);
1170 else
1171 #endif
1173 read_directory_win(dir, path);
1175 if (Globals.prescan_node) {
1176 s = path;
1177 d = buffer;
1179 while(*s)
1180 *d++ = *s++;
1182 *d++ = TEXT('\\');
1184 for(entry=dir->down; entry; entry=entry->next)
1185 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1186 lstrcpy(d, entry->data.cFileName);
1187 read_directory_win(entry, buffer);
1188 SortDirectory(entry, sortOrder);
1193 SortDirectory(dir, sortOrder);
1197 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1199 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1200 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1201 Root* root = &child->root;
1202 Entry* entry;
1204 memset(child, 0, sizeof(ChildWnd));
1206 child->left.treePane = TRUE;
1207 child->left.visible_cols = 0;
1209 child->right.treePane = FALSE;
1210 #ifndef _NO_EXTENSIONS
1211 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1212 #else
1213 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1214 #endif
1216 child->pos.length = sizeof(WINDOWPLACEMENT);
1217 child->pos.flags = 0;
1218 child->pos.showCmd = SW_SHOWNORMAL;
1219 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1220 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1221 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1222 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1224 child->focus_pane = 0;
1225 child->split_pos = DEFAULT_SPLIT_POS;
1226 child->sortOrder = SORT_NAME;
1227 child->header_wdths_ok = FALSE;
1229 if (path)
1231 lstrcpy(child->path, path);
1233 _tsplitpath(path, drv, dir, name, ext);
1236 root->entry.level = 0;
1238 #ifdef _SHELL_FOLDERS
1239 if (pidl)
1241 root->drive_type = DRIVE_UNKNOWN;
1242 lstrcpy(drv, TEXT("\\"));
1243 lstrcpy(root->volname, TEXT("Desktop"));
1244 root->fs_flags = 0;
1245 lstrcpy(root->fs, TEXT("Shell"));
1247 entry = read_tree_shell(root, pidl, child->sortOrder, hwnd);
1249 else
1250 #endif
1251 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1252 if (*path == '/')
1254 root->drive_type = GetDriveType(path);
1256 lstrcat(drv, TEXT("/"));
1257 lstrcpy(root->volname, TEXT("root fs"));
1258 root->fs_flags = 0;
1259 lstrcpy(root->fs, TEXT("unixfs"));
1261 lstrcpy(root->path, TEXT("/"));
1262 entry = read_tree_unix(root, path, child->sortOrder, hwnd);
1264 else
1265 #endif
1267 root->drive_type = GetDriveType(path);
1269 lstrcat(drv, TEXT("\\"));
1270 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1272 lstrcpy(root->path, drv);
1273 entry = read_tree_win(root, path, child->sortOrder, hwnd);
1276 #ifdef _SHELL_FOLDERS
1277 if (root->entry.etype == ET_SHELL)
1278 lstrcpy(root->entry.data.cFileName, TEXT("Desktop"));
1279 else
1280 #endif
1281 wsprintf(root->entry.data.cFileName, TEXT("%s - %s"), drv, root->fs);
1283 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1285 child->left.root = &root->entry;
1286 child->right.root = NULL;
1288 set_curdir(child, entry, hwnd);
1290 return child;
1294 /* free all memory associated with a child window */
1295 static void free_child_window(ChildWnd* child)
1297 free_entries(&child->root.entry);
1298 free(child);
1302 /* get full path of specified directory entry */
1303 static void get_path(Entry* dir, PTSTR path)
1305 Entry* entry;
1306 int len = 0;
1307 int level = 0;
1309 #ifdef _SHELL_FOLDERS
1310 if (dir->etype == ET_SHELL)
1312 SFGAOF attribs;
1313 HRESULT hr = S_OK;
1315 path[0] = TEXT('\0');
1317 attribs = 0;
1319 if (dir->folder)
1320 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1322 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1323 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1325 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1328 else
1329 #endif
1331 for(entry=dir; entry; level++) {
1332 LPCTSTR name;
1333 int l;
1336 LPCTSTR s;
1337 name = entry->data.cFileName;
1338 s = name;
1340 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1341 l++;
1344 if (entry->up) {
1345 if (l > 0) {
1346 memmove(path+l+1, path, len*sizeof(TCHAR));
1347 memcpy(path+1, name, l*sizeof(TCHAR));
1348 len += l+1;
1350 #ifndef _NO_EXTENSIONS
1351 if (entry->etype == ET_UNIX)
1352 path[0] = TEXT('/');
1353 else
1354 #endif
1355 path[0] = TEXT('\\');
1358 entry = entry->up;
1359 } else {
1360 memmove(path+l, path, len*sizeof(TCHAR));
1361 memcpy(path, name, l*sizeof(TCHAR));
1362 len += l;
1363 break;
1367 if (!level) {
1368 #ifndef _NO_EXTENSIONS
1369 if (entry->etype == ET_UNIX)
1370 path[len++] = TEXT('/');
1371 else
1372 #endif
1373 path[len++] = TEXT('\\');
1376 path[len] = TEXT('\0');
1381 static void resize_frame_rect(HWND hwnd, PRECT prect)
1383 int new_top;
1384 RECT rt;
1386 if (IsWindowVisible(Globals.htoolbar)) {
1387 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1388 GetClientRect(Globals.htoolbar, &rt);
1389 prect->top = rt.bottom+3;
1390 prect->bottom -= rt.bottom+3;
1393 if (IsWindowVisible(Globals.hdrivebar)) {
1394 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1395 GetClientRect(Globals.hdrivebar, &rt);
1396 new_top = --prect->top + rt.bottom+3;
1397 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1398 prect->top = new_top;
1399 prect->bottom -= rt.bottom+2;
1402 if (IsWindowVisible(Globals.hstatusbar)) {
1403 int parts[] = {300, 500};
1405 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1406 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1407 GetClientRect(Globals.hstatusbar, &rt);
1408 prect->bottom -= rt.bottom;
1411 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1414 static void resize_frame(HWND hwnd, int cx, int cy)
1416 RECT rect;
1418 rect.left = 0;
1419 rect.top = 0;
1420 rect.right = cx;
1421 rect.bottom = cy;
1423 resize_frame_rect(hwnd, &rect);
1426 static void resize_frame_client(HWND hwnd)
1428 RECT rect;
1430 GetClientRect(hwnd, &rect);
1432 resize_frame_rect(hwnd, &rect);
1436 static HHOOK hcbthook;
1437 static ChildWnd* newchild = NULL;
1439 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1441 if (code==HCBT_CREATEWND && newchild) {
1442 ChildWnd* child = newchild;
1443 newchild = NULL;
1445 child->hwnd = (HWND) wparam;
1446 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1449 return CallNextHookEx(hcbthook, code, wparam, lparam);
1452 static HWND create_child_window(ChildWnd* child)
1454 MDICREATESTRUCT mcs;
1455 int idx;
1457 mcs.szClass = WINEFILETREE;
1458 mcs.szTitle = (LPTSTR)child->path;
1459 mcs.hOwner = Globals.hInstance;
1460 mcs.x = child->pos.rcNormalPosition.left;
1461 mcs.y = child->pos.rcNormalPosition.top;
1462 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1463 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1464 mcs.style = 0;
1465 mcs.lParam = 0;
1467 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1469 newchild = child;
1470 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1471 if (!child->hwnd) {
1472 UnhookWindowsHookEx(hcbthook);
1473 return 0;
1476 UnhookWindowsHookEx(hcbthook);
1478 idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), child->left.cur);
1479 ListBox_SetCurSel(child->left.hwnd, idx);
1481 return child->hwnd;
1485 struct ExecuteDialog {
1486 TCHAR cmd[MAX_PATH];
1487 int cmdshow;
1491 static BOOL CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1493 static struct ExecuteDialog* dlg;
1495 switch(nmsg) {
1496 case WM_INITDIALOG:
1497 dlg = (struct ExecuteDialog*) lparam;
1498 return 1;
1500 case WM_COMMAND: {
1501 int id = (int)wparam;
1503 if (id == IDOK) {
1504 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1505 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1506 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1507 EndDialog(hwnd, id);
1508 } else if (id == IDCANCEL)
1509 EndDialog(hwnd, id);
1511 return 1;}
1514 return 0;
1518 #ifndef _NO_EXTENSIONS
1520 static struct FullScreenParameters {
1521 BOOL mode;
1522 RECT orgPos;
1523 BOOL wasZoomed;
1524 } g_fullscreen = {
1525 FALSE, /* mode */
1526 {0, 0, 0, 0},
1527 FALSE
1530 void frame_get_clientspace(HWND hwnd, PRECT prect)
1532 RECT rt;
1534 if (!IsIconic(hwnd))
1535 GetClientRect(hwnd, prect);
1536 else {
1537 WINDOWPLACEMENT wp;
1539 GetWindowPlacement(hwnd, &wp);
1541 prect->left = prect->top = 0;
1542 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1543 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1544 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1545 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1546 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1549 if (IsWindowVisible(Globals.htoolbar)) {
1550 GetClientRect(Globals.htoolbar, &rt);
1551 prect->top += rt.bottom+2;
1554 if (IsWindowVisible(Globals.hdrivebar)) {
1555 GetClientRect(Globals.hdrivebar, &rt);
1556 prect->top += rt.bottom+2;
1559 if (IsWindowVisible(Globals.hstatusbar)) {
1560 GetClientRect(Globals.hstatusbar, &rt);
1561 prect->bottom -= rt.bottom;
1565 static BOOL toggle_fullscreen(HWND hwnd)
1567 RECT rt;
1569 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1570 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1571 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1573 Frame_CalcFrameClient(hwnd, &rt);
1574 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1575 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1577 rt.left = g_fullscreen.orgPos.left-rt.left;
1578 rt.top = g_fullscreen.orgPos.top-rt.top;
1579 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1580 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1582 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1583 } else {
1584 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1585 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1586 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1588 if (g_fullscreen.wasZoomed)
1589 ShowWindow(hwnd, WS_MAXIMIZE);
1592 return g_fullscreen.mode;
1595 static void fullscreen_move(HWND hwnd)
1597 RECT rt, pos;
1598 GetWindowRect(hwnd, &pos);
1600 Frame_CalcFrameClient(hwnd, &rt);
1601 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1602 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1604 rt.left = pos.left-rt.left;
1605 rt.top = pos.top-rt.top;
1606 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1607 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1609 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1612 #endif
1615 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1617 BOOL vis = IsWindowVisible(hchild);
1619 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1621 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1623 #ifndef _NO_EXTENSIONS
1624 if (g_fullscreen.mode)
1625 fullscreen_move(hwnd);
1626 #endif
1628 resize_frame_client(hwnd);
1631 BOOL activate_drive_window(LPCTSTR path)
1633 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1634 HWND child_wnd;
1636 _tsplitpath(path, drv1, 0, 0, 0);
1638 /* search for a already open window for the same drive */
1639 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1640 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1642 if (child) {
1643 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1645 if (!lstrcmpi(drv2, drv1)) {
1646 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1648 if (IsMinimized(child_wnd))
1649 ShowWindow(child_wnd, SW_SHOWNORMAL);
1651 return TRUE;
1656 return FALSE;
1659 BOOL activate_fs_window(LPCTSTR filesys)
1661 HWND child_wnd;
1663 /* search for a already open window of the given file system name */
1664 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1665 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1667 if (child) {
1668 if (!lstrcmpi(child->root.fs, filesys)) {
1669 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1671 if (IsMinimized(child_wnd))
1672 ShowWindow(child_wnd, SW_SHOWNORMAL);
1674 return TRUE;
1679 return FALSE;
1682 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1684 switch(nmsg) {
1685 case WM_CLOSE:
1686 DestroyWindow(hwnd);
1688 /* clear handle variables */
1689 Globals.hMenuFrame = 0;
1690 Globals.hMenuView = 0;
1691 Globals.hMenuOptions = 0;
1692 Globals.hMainWnd = 0;
1693 Globals.hmdiclient = 0;
1694 Globals.hdrivebar = 0;
1695 break;
1697 case WM_DESTROY:
1698 /* don't exit desktop when closing file manager window */
1699 if (!Globals.hwndParent)
1700 PostQuitMessage(0);
1701 break;
1703 case WM_COMMAND: {
1704 UINT cmd = LOWORD(wparam);
1705 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1707 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1708 break;
1710 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1711 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1712 ChildWnd* child;
1713 LPCTSTR root = Globals.drives;
1714 int i;
1716 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1717 while(*root)
1718 root++;
1720 if (activate_drive_window(root))
1721 return 0;
1723 _tsplitpath(root, drv, 0, 0, 0);
1725 if (!SetCurrentDirectory(drv)) {
1726 display_error(hwnd, GetLastError());
1727 return 0;
1730 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1731 child = alloc_child_window(path, NULL, hwnd);
1733 if (!create_child_window(child))
1734 free(child);
1735 } else switch(cmd) {
1736 case ID_FILE_EXIT:
1737 SendMessage(hwnd, WM_CLOSE, 0, 0);
1738 break;
1740 case ID_WINDOW_NEW: {
1741 TCHAR path[MAX_PATH];
1742 ChildWnd* child;
1744 GetCurrentDirectory(MAX_PATH, path);
1745 child = alloc_child_window(path, NULL, hwnd);
1747 if (!create_child_window(child))
1748 free(child);
1749 break;}
1751 case ID_WINDOW_CASCADE:
1752 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1753 break;
1755 case ID_WINDOW_TILE_HORZ:
1756 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1757 break;
1759 case ID_WINDOW_TILE_VERT:
1760 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1761 break;
1763 case ID_WINDOW_ARRANGE:
1764 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1765 break;
1767 case ID_VIEW_TOOL_BAR:
1768 toggle_child(hwnd, cmd, Globals.htoolbar);
1769 break;
1771 case ID_VIEW_DRIVE_BAR:
1772 toggle_child(hwnd, cmd, Globals.hdrivebar);
1773 break;
1775 case ID_VIEW_STATUSBAR:
1776 toggle_child(hwnd, cmd, Globals.hstatusbar);
1777 break;
1779 case ID_EXECUTE: {
1780 struct ExecuteDialog dlg;
1782 memset(&dlg, 0, sizeof(struct ExecuteDialog));
1784 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
1785 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
1787 if ((int)hinst <= 32)
1788 display_error(hwnd, GetLastError());
1790 break;}
1792 case ID_HELP:
1793 WinHelp(hwnd, TEXT("winfile"), HELP_INDEX, 0);
1794 break;
1796 #ifndef _NO_EXTENSIONS
1797 case ID_VIEW_FULLSCREEN:
1798 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1799 break;
1801 #ifdef __WINE__
1802 case ID_DRIVE_UNIX_FS: {
1803 TCHAR path[MAX_PATH];
1804 ChildWnd* child;
1806 if (activate_fs_window(TEXT("unixfs")))
1807 break;
1809 getcwd(path, MAX_PATH);
1810 child = alloc_child_window(path, NULL, hwnd);
1812 if (!create_child_window(child))
1813 free(child);
1814 break;}
1815 #endif
1816 #ifdef _SHELL_FOLDERS
1817 case ID_DRIVE_SHELL_NS: {
1818 TCHAR path[MAX_PATH];
1819 ChildWnd* child;
1821 if (activate_fs_window(TEXT("Shell")))
1822 break;
1824 GetCurrentDirectory(MAX_PATH, path);
1825 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1827 if (!create_child_window(child))
1828 free(child);
1829 break;}
1830 #endif
1831 #endif
1833 /*TODO: There are even more menu items! */
1835 #ifndef _NO_EXTENSIONS
1836 #ifdef __WINE__
1837 case ID_LICENSE:
1838 WineLicense(Globals.hMainWnd);
1839 break;
1841 case ID_NO_WARRANTY:
1842 WineWarranty(Globals.hMainWnd);
1843 break;
1844 #endif
1846 case ID_ABOUT_WINE:
1847 ShellAbout(hwnd, TEXT("WINE"), TEXT("Winefile"), 0);
1848 break;
1850 case ID_ABOUT: /*ID_ABOUT_WINE: */
1851 ShellAbout(hwnd, TEXT("Winefile"), NULL, 0);
1852 break;
1853 #endif /* _NO_EXTENSIONS */
1855 default:
1856 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
1857 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
1858 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
1859 (cmd<SC_SIZE || cmd>SC_RESTORE))
1860 MessageBox(hwnd, TEXT("Not yet implemented"), TEXT("Winefile"), MB_OK);
1862 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1864 break;}
1866 case WM_SIZE:
1867 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
1868 break; /* do not pass message to DefFrameProc */
1870 #ifndef _NO_EXTENSIONS
1871 case WM_GETMINMAXINFO: {
1872 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
1874 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
1875 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
1876 break;}
1878 case FRM_CALC_CLIENT:
1879 frame_get_clientspace(hwnd, (PRECT)lparam);
1880 return TRUE;
1881 #endif /* _NO_EXTENSIONS */
1883 default:
1884 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
1887 return 0;
1891 static const LPTSTR g_pos_names[COLUMNS] = {
1892 TEXT(""), /* symbol */
1893 TEXT("Name"),
1894 TEXT("Size"),
1895 TEXT("CDate"),
1896 #ifndef _NO_EXTENSIONS
1897 TEXT("ADate"),
1898 TEXT("MDate"),
1899 TEXT("Index/Inode"),
1900 TEXT("Links"),
1901 #endif /* _NO_EXTENSIONS */
1902 TEXT("Attributes"),
1903 #ifndef _NO_EXTENSIONS
1904 TEXT("Security")
1905 #endif
1908 static const int g_pos_align[] = {
1910 HDF_LEFT, /* Name */
1911 HDF_RIGHT, /* Size */
1912 HDF_LEFT, /* CDate */
1913 #ifndef _NO_EXTENSIONS
1914 HDF_LEFT, /* ADate */
1915 HDF_LEFT, /* MDate */
1916 HDF_LEFT, /* Index */
1917 HDF_CENTER, /* Links */
1918 #endif
1919 HDF_CENTER, /* Attributes */
1920 #ifndef _NO_EXTENSIONS
1921 HDF_LEFT /* Security */
1922 #endif
1925 static void resize_tree(ChildWnd* child, int cx, int cy)
1927 HDWP hdwp = BeginDeferWindowPos(4);
1928 RECT rt;
1930 rt.left = 0;
1931 rt.top = 0;
1932 rt.right = cx;
1933 rt.bottom = cy;
1935 cx = child->split_pos + SPLIT_WIDTH/2;
1937 #ifndef _NO_EXTENSIONS
1939 WINDOWPOS wp;
1940 HD_LAYOUT hdl;
1942 hdl.prc = &rt;
1943 hdl.pwpos = &wp;
1945 Header_Layout(child->left.hwndHeader, &hdl);
1947 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
1948 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
1949 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
1950 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
1952 #endif /* _NO_EXTENSIONS */
1954 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);
1955 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
1957 EndDeferWindowPos(hdwp);
1961 #ifndef _NO_EXTENSIONS
1963 static HWND create_header(HWND parent, Pane* pane, int id)
1965 HD_ITEM hdi;
1966 int idx;
1968 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
1969 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
1970 if (!hwnd)
1971 return 0;
1973 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
1975 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
1977 for(idx=0; idx<COLUMNS; idx++) {
1978 hdi.pszText = g_pos_names[idx];
1979 hdi.fmt = HDF_STRING | g_pos_align[idx];
1980 hdi.cxy = pane->widths[idx];
1981 Header_InsertItem(hwnd, idx, &hdi);
1984 return hwnd;
1987 #endif /* _NO_EXTENSIONS */
1990 static void init_output(HWND hwnd)
1992 TCHAR b[16];
1993 HFONT old_font;
1994 HDC hdc = GetDC(hwnd);
1996 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
1997 Globals.num_sep = b[1];
1998 else
1999 Globals.num_sep = TEXT('.');
2001 old_font = SelectFont(hdc, Globals.hfont);
2002 GetTextExtentPoint32(hdc, TEXT(" "), 1, &Globals.spaceSize);
2003 SelectFont(hdc, old_font);
2004 ReleaseDC(hwnd, hdc);
2007 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2010 /* calculate prefered width for all visible columns */
2012 static BOOL calc_widths(Pane* pane, BOOL anyway)
2014 int col, x, cx, spc=3*Globals.spaceSize.cx;
2015 int entries = ListBox_GetCount(pane->hwnd);
2016 int orgWidths[COLUMNS];
2017 int orgPositions[COLUMNS+1];
2018 HFONT hfontOld;
2019 HDC hdc;
2020 int cnt;
2022 if (!anyway) {
2023 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2024 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2027 for(col=0; col<COLUMNS; col++)
2028 pane->widths[col] = 0;
2030 hdc = GetDC(pane->hwnd);
2031 hfontOld = SelectFont(hdc, Globals.hfont);
2033 for(cnt=0; cnt<entries; cnt++) {
2034 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2036 DRAWITEMSTRUCT dis;
2038 dis.CtlType = 0;
2039 dis.CtlID = 0;
2040 dis.itemID = 0;
2041 dis.itemAction = 0;
2042 dis.itemState = 0;
2043 dis.hwndItem = pane->hwnd;
2044 dis.hDC = hdc;
2045 dis.rcItem.left = 0;
2046 dis.rcItem.top = 0;
2047 dis.rcItem.right = 0;
2048 dis.rcItem.bottom = 0;
2049 /*dis.itemData = 0; */
2051 draw_item(pane, &dis, entry, COLUMNS);
2054 SelectObject(hdc, hfontOld);
2055 ReleaseDC(pane->hwnd, hdc);
2057 x = 0;
2058 for(col=0; col<COLUMNS; col++) {
2059 pane->positions[col] = x;
2060 cx = pane->widths[col];
2062 if (cx) {
2063 cx += spc;
2065 if (cx < IMAGE_WIDTH)
2066 cx = IMAGE_WIDTH;
2068 pane->widths[col] = cx;
2071 x += cx;
2074 pane->positions[COLUMNS] = x;
2076 ListBox_SetHorizontalExtent(pane->hwnd, x);
2078 /* no change? */
2079 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2080 return FALSE;
2082 /* don't move, if only collapsing an entry */
2083 if (!anyway && pane->widths[0]<orgWidths[0] &&
2084 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2085 pane->widths[0] = orgWidths[0];
2086 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2088 return FALSE;
2091 InvalidateRect(pane->hwnd, 0, TRUE);
2093 return TRUE;
2097 /* calculate one prefered column width */
2099 static void calc_single_width(Pane* pane, int col)
2101 HFONT hfontOld;
2102 int x, cx;
2103 int entries = ListBox_GetCount(pane->hwnd);
2104 int cnt;
2105 HDC hdc;
2107 pane->widths[col] = 0;
2109 hdc = GetDC(pane->hwnd);
2110 hfontOld = SelectFont(hdc, Globals.hfont);
2112 for(cnt=0; cnt<entries; cnt++) {
2113 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2114 DRAWITEMSTRUCT dis;
2116 dis.CtlType = 0;
2117 dis.CtlID = 0;
2118 dis.itemID = 0;
2119 dis.itemAction = 0;
2120 dis.itemState = 0;
2121 dis.hwndItem = pane->hwnd;
2122 dis.hDC = hdc;
2123 dis.rcItem.left = 0;
2124 dis.rcItem.top = 0;
2125 dis.rcItem.right = 0;
2126 dis.rcItem.bottom = 0;
2127 /*dis.itemData = 0; */
2129 draw_item(pane, &dis, entry, col);
2132 SelectObject(hdc, hfontOld);
2133 ReleaseDC(pane->hwnd, hdc);
2135 cx = pane->widths[col];
2137 if (cx) {
2138 cx += 3*Globals.spaceSize.cx;
2140 if (cx < IMAGE_WIDTH)
2141 cx = IMAGE_WIDTH;
2144 pane->widths[col] = cx;
2146 x = pane->positions[col] + cx;
2148 for(; col<COLUMNS; ) {
2149 pane->positions[++col] = x;
2150 x += pane->widths[col];
2153 ListBox_SetHorizontalExtent(pane->hwnd, x);
2157 /* insert listbox entries after index idx */
2159 static void insert_entries(Pane* pane, Entry* dir, int idx)
2161 Entry* entry = dir;
2163 if (!entry)
2164 return;
2166 ShowWindow(pane->hwnd, SW_HIDE);
2168 for(; entry; entry=entry->next) {
2169 #ifndef _LEFT_FILES
2170 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2171 continue;
2172 #endif
2174 /* don't display entries "." and ".." in the left pane */
2175 if (pane->treePane && (entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2176 && entry->data.cFileName[0]==TEXT('.'))
2177 if (
2178 #ifndef _NO_EXTENSIONS
2179 entry->data.cFileName[1]==TEXT('\0') ||
2180 #endif
2181 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2182 continue;
2184 if (idx != -1)
2185 idx++;
2187 ListBox_InsertItemData(pane->hwnd, idx, entry);
2189 if (pane->treePane && entry->expanded)
2190 insert_entries(pane, entry->down, idx);
2193 ShowWindow(pane->hwnd, SW_SHOW);
2197 static WNDPROC g_orgTreeWndProc;
2199 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header)
2201 static int s_init = 0;
2202 Entry* entry = pane->root;
2204 pane->hwnd = CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2205 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2206 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2208 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2209 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2211 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2213 /* insert entries into listbox */
2214 if (entry)
2215 insert_entries(pane, entry, -1);
2217 /* calculate column widths */
2218 if (!s_init) {
2219 s_init = 1;
2220 init_output(pane->hwnd);
2223 calc_widths(pane, TRUE);
2225 #ifndef _NO_EXTENSIONS
2226 pane->hwndHeader = create_header(parent, pane, id_header);
2227 #endif
2231 static void InitChildWindow(ChildWnd* child)
2233 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT);
2234 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT);
2238 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2240 SYSTEMTIME systime;
2241 FILETIME lft;
2242 int len = 0;
2244 *buffer = TEXT('\0');
2246 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2247 return;
2249 if (!FileTimeToLocalFileTime(ft, &lft))
2250 {err: _tcscpy(buffer,TEXT("???")); return;}
2252 if (!FileTimeToSystemTime(&lft, &systime))
2253 goto err;
2255 if (visible_cols & COL_DATE) {
2256 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2257 if (!len)
2258 goto err;
2261 if (visible_cols & COL_TIME) {
2262 if (len)
2263 buffer[len-1] = ' ';
2265 buffer[len++] = ' ';
2267 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2268 buffer[len] = TEXT('\0');
2273 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2275 RECT rt = {0, 0, 0, 0};
2277 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2279 if (rt.right > pane->widths[col])
2280 pane->widths[col] = rt.right;
2283 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2285 RECT rt = {0, 0, 0, 0};
2287 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2288 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2290 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2291 /*FIXME rt (0,0) ??? */
2293 if (rt.right > pane->widths[col])
2294 pane->widths[col] = rt.right;
2298 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2300 int x = dis->rcItem.left;
2301 RECT rt;
2303 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2304 rt.top = dis->rcItem.top;
2305 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2306 rt.bottom = dis->rcItem.bottom;
2308 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2311 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2313 int x = dis->rcItem.left;
2314 RECT rt;
2316 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2317 rt.top = dis->rcItem.top;
2318 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2319 rt.bottom = dis->rcItem.bottom;
2321 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2322 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2324 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2327 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2329 int x = dis->rcItem.left;
2330 RECT rt;
2331 LPCTSTR s = str;
2332 TCHAR b[128];
2333 LPTSTR d = b;
2334 int pos;
2336 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2337 rt.top = dis->rcItem.top;
2338 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2339 rt.bottom = dis->rcItem.bottom;
2341 if (*s)
2342 *d++ = *s++;
2344 /* insert number separator characters */
2345 pos = lstrlen(s) % 3;
2347 while(*s)
2348 if (pos--)
2349 *d++ = *s++;
2350 else {
2351 *d++ = Globals.num_sep;
2352 pos = 3;
2355 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2359 static int is_exe_file(LPCTSTR ext)
2361 static const LPCTSTR executable_extensions[] = {
2362 TEXT("COM"),
2363 TEXT("EXE"),
2364 TEXT("BAT"),
2365 TEXT("CMD"),
2366 #ifndef _NO_EXTENSIONS
2367 TEXT("CMM"),
2368 TEXT("BTM"),
2369 TEXT("AWK"),
2370 #endif /* _NO_EXTENSIONS */
2374 TCHAR ext_buffer[_MAX_EXT];
2375 const LPCTSTR* p;
2376 LPCTSTR s;
2377 LPTSTR d;
2379 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2380 d++;
2382 for(p=executable_extensions; *p; p++)
2383 if (!_tcscmp(ext_buffer, *p))
2384 return 1;
2386 return 0;
2389 static int is_registered_type(LPCTSTR ext)
2391 /* TODO */
2393 return 1;
2397 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2399 TCHAR buffer[BUFFER_LEN];
2400 DWORD attrs;
2401 int visible_cols = pane->visible_cols;
2402 COLORREF bkcolor, textcolor;
2403 RECT focusRect = dis->rcItem;
2404 HBRUSH hbrush;
2405 enum IMAGE img;
2406 int img_pos, cx;
2407 int col = 0;
2409 if (entry) {
2410 attrs = entry->data.dwFileAttributes;
2412 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2413 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2414 && entry->data.cFileName[2]==TEXT('\0'))
2415 img = IMG_FOLDER_UP;
2416 #ifndef _NO_EXTENSIONS
2417 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2418 img = IMG_FOLDER_CUR;
2419 #endif
2420 else if (
2421 #ifdef _NO_EXTENSIONS
2422 entry->expanded ||
2423 #endif
2424 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2425 img = IMG_OPEN_FOLDER;
2426 else
2427 img = IMG_FOLDER;
2428 } else {
2429 LPCTSTR ext = _tcsrchr(entry->data.cFileName, '.');
2430 if (!ext)
2431 ext = TEXT("");
2433 if (is_exe_file(ext))
2434 img = IMG_EXECUTABLE;
2435 else if (is_registered_type(ext))
2436 img = IMG_DOCUMENT;
2437 else
2438 img = IMG_FILE;
2440 } else {
2441 attrs = 0;
2442 img = IMG_NONE;
2445 if (pane->treePane) {
2446 if (entry) {
2447 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+Globals.spaceSize.cx);
2449 if (calcWidthCol == -1) {
2450 int x;
2451 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2452 Entry* up;
2453 RECT rt_clip;
2454 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2455 HRGN hrgn;
2457 rt_clip.left = dis->rcItem.left;
2458 rt_clip.top = dis->rcItem.top;
2459 rt_clip.right = dis->rcItem.left+pane->widths[col];
2460 rt_clip.bottom = dis->rcItem.bottom;
2462 hrgn = CreateRectRgnIndirect(&rt_clip);
2464 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2465 DeleteObject(hrgn_org);
2466 hrgn_org = 0;
2469 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2470 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2471 DeleteObject(hrgn);
2473 if ((up=entry->up) != NULL) {
2474 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2475 LineTo(dis->hDC, img_pos-2, y);
2477 x = img_pos - IMAGE_WIDTH/2;
2479 do {
2480 x -= IMAGE_WIDTH+Globals.spaceSize.cx;
2482 if (up->next
2483 #ifndef _LEFT_FILES
2484 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2485 #endif
2487 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2488 LineTo(dis->hDC, x, dis->rcItem.bottom);
2490 } while((up=up->up) != NULL);
2493 x = img_pos - IMAGE_WIDTH/2;
2495 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2496 LineTo(dis->hDC, x, y);
2498 if (entry->next
2499 #ifndef _LEFT_FILES
2500 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2501 #endif
2503 LineTo(dis->hDC, x, dis->rcItem.bottom);
2505 if (entry->down && entry->expanded) {
2506 x += IMAGE_WIDTH+Globals.spaceSize.cx;
2507 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
2508 LineTo(dis->hDC, x, dis->rcItem.bottom);
2511 SelectClipRgn(dis->hDC, hrgn_org);
2512 if (hrgn_org) DeleteObject(hrgn_org);
2513 /* SelectObject(dis->hDC, holdPen); */
2514 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2515 int right = img_pos + IMAGE_WIDTH - Globals.spaceSize.cx;
2517 if (right > pane->widths[col])
2518 pane->widths[col] = right;
2520 } else {
2521 img_pos = dis->rcItem.left;
2523 } else {
2524 img_pos = dis->rcItem.left;
2526 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2527 pane->widths[col] = IMAGE_WIDTH;
2530 if (calcWidthCol == -1) {
2531 focusRect.left = img_pos -2;
2533 #ifdef _NO_EXTENSIONS
2534 if (pane->treePane && entry) {
2535 RECT rt = {0};
2537 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2539 focusRect.right = dis->rcItem.left+pane->positions[col+1]+Globals.spaceSize.cx + rt.right +2;
2541 #else
2543 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2544 textcolor = COLOR_COMPRESSED;
2545 else
2546 #endif /* _NO_EXTENSIONS */
2547 textcolor = RGB(0,0,0);
2549 if (dis->itemState & ODS_FOCUS) {
2550 textcolor = RGB(255,255,255);
2551 bkcolor = COLOR_SELECTION;
2552 } else {
2553 bkcolor = RGB(255,255,255);
2556 hbrush = CreateSolidBrush(bkcolor);
2557 FillRect(dis->hDC, &focusRect, hbrush);
2558 DeleteObject(hbrush);
2560 SetBkMode(dis->hDC, TRANSPARENT);
2561 SetTextColor(dis->hDC, textcolor);
2563 cx = pane->widths[col];
2565 if (cx && img!=IMG_NONE) {
2566 if (cx > IMAGE_WIDTH)
2567 cx = IMAGE_WIDTH;
2569 #ifdef _SHELL_FOLDERS
2570 if (entry->hicon && entry->hicon!=(HICON)-1)
2571 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2572 else
2573 #endif
2574 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2575 img_pos, dis->rcItem.top, cx,
2576 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2580 if (!entry)
2581 return;
2583 #ifdef _NO_EXTENSIONS
2584 if (img >= IMG_FOLDER_UP)
2585 return;
2586 #endif
2588 col++;
2590 /* ouput file name */
2591 if (calcWidthCol == -1)
2592 output_text(pane, dis, col, entry->data.cFileName, 0);
2593 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2594 calc_width(pane, dis, col, entry->data.cFileName);
2596 col++;
2598 #ifdef _NO_EXTENSIONS
2599 if (!pane->treePane) {
2600 #endif
2602 /* display file size */
2603 if (visible_cols & COL_SIZE) {
2604 #ifdef _NO_EXTENSIONS
2605 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
2606 #endif
2608 ULONGLONG size;
2610 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
2612 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
2614 if (calcWidthCol == -1)
2615 output_number(pane, dis, col, buffer);
2616 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2617 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2620 col++;
2623 /* display file date */
2624 if (visible_cols & (COL_DATE|COL_TIME)) {
2625 #ifndef _NO_EXTENSIONS
2626 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2627 if (calcWidthCol == -1)
2628 output_text(pane, dis, col, buffer, 0);
2629 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2630 calc_width(pane, dis, col, buffer);
2631 col++;
2633 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2634 if (calcWidthCol == -1)
2635 output_text(pane, dis, col, buffer, 0);
2636 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2637 calc_width(pane, dis, col, buffer);
2638 col++;
2639 #endif /* _NO_EXTENSIONS */
2641 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2642 if (calcWidthCol == -1)
2643 output_text(pane, dis, col, buffer, 0);
2644 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2645 calc_width(pane, dis, col, buffer);
2646 col++;
2649 #ifndef _NO_EXTENSIONS
2650 if (entry->bhfi_valid) {
2651 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
2653 if (visible_cols & COL_INDEX) {
2654 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
2655 if (calcWidthCol == -1)
2656 output_text(pane, dis, col, buffer, DT_RIGHT);
2657 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2658 calc_width(pane, dis, col, buffer);
2659 col++;
2662 if (visible_cols & COL_LINKS) {
2663 wsprintf(buffer, TEXT("%d"), entry->bhfi.nNumberOfLinks);
2664 if (calcWidthCol == -1)
2665 output_text(pane, dis, col, buffer, DT_CENTER);
2666 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2667 calc_width(pane, dis, col, buffer);
2668 col++;
2670 } else
2671 col += 2;
2672 #endif /* _NO_EXTENSIONS */
2674 /* show file attributes */
2675 if (visible_cols & COL_ATTRIBUTES) {
2676 #ifdef _NO_EXTENSIONS
2677 _tcscpy(buffer, TEXT(" \t \t \t \t "));
2678 #else
2679 _tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2680 #endif
2682 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2683 else {
2684 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2685 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2686 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2687 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2688 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2689 #ifndef _NO_EXTENSIONS
2690 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2691 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2692 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2693 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2694 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2695 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2696 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2697 #endif /* _NO_EXTENSIONS */
2700 if (calcWidthCol == -1)
2701 output_tabbed_text(pane, dis, col, buffer);
2702 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2703 calc_tabbed_width(pane, dis, col, buffer);
2705 col++;
2708 /*TODO
2709 if (flags.security) {
2710 DWORD rights = get_access_mask();
2712 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
2714 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
2715 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
2716 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
2717 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
2718 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
2719 if (rights & FILE_EXECUTE) buffer[12] = 'X';
2720 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
2721 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
2722 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
2723 if (rights & WRITE_DAC) buffer[22] = 'C';
2724 if (rights & WRITE_OWNER) buffer[24] = 'O';
2725 if (rights & SYNCHRONIZE) buffer[26] = 'S';
2727 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
2730 if (flags.description) {
2731 get_description(buffer);
2732 output_text(dis, col++, buffer, 0, psize);
2736 #ifdef _NO_EXTENSIONS
2739 /* draw focus frame */
2740 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
2741 /* Currently [04/2000] Wine neither behaves exactly the same */
2742 /* way as WIN 95 nor like Windows NT... */
2743 HGDIOBJ lastBrush;
2744 HPEN lastPen;
2745 HPEN hpen;
2747 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
2748 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
2749 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
2750 } else
2751 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
2753 lastPen = SelectPen(dis->hDC, hpen);
2754 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
2755 SetROP2(dis->hDC, R2_XORPEN);
2756 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
2757 SelectObject(dis->hDC, lastBrush);
2758 SelectObject(dis->hDC, lastPen);
2759 DeleteObject(hpen);
2761 #endif /* _NO_EXTENSIONS */
2765 #ifdef _NO_EXTENSIONS
2767 static void draw_splitbar(HWND hwnd, int x)
2769 RECT rt;
2770 HDC hdc = GetDC(hwnd);
2772 GetClientRect(hwnd, &rt);
2774 rt.left = x - SPLIT_WIDTH/2;
2775 rt.right = x + SPLIT_WIDTH/2+1;
2777 InvertRect(hdc, &rt);
2779 ReleaseDC(hwnd, hdc);
2782 #endif /* _NO_EXTENSIONS */
2785 #ifndef _NO_EXTENSIONS
2787 static void set_header(Pane* pane)
2789 HD_ITEM item;
2790 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2791 int i=0, x=0;
2793 item.mask = HDI_WIDTH;
2794 item.cxy = 0;
2796 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
2797 x += pane->widths[i];
2798 Header_SetItem(pane->hwndHeader, i, &item);
2801 if (i < COLUMNS) {
2802 x += pane->widths[i];
2803 item.cxy = x - scroll_pos;
2804 Header_SetItem(pane->hwndHeader, i++, &item);
2806 for(; i<COLUMNS; i++) {
2807 item.cxy = pane->widths[i];
2808 x += pane->widths[i];
2809 Header_SetItem(pane->hwndHeader, i, &item);
2814 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2816 switch(pnmh->code) {
2817 case HDN_TRACK:
2818 case HDN_ENDTRACK: {
2819 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2820 int idx = phdn->iItem;
2821 int dx = phdn->pitem->cxy - pane->widths[idx];
2822 int i;
2824 RECT clnt;
2825 GetClientRect(pane->hwnd, &clnt);
2827 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
2828 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
2830 pane->widths[idx] += dx;
2832 for(i=idx; ++i<=COLUMNS; )
2833 pane->positions[i] += dx;
2836 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2837 RECT rt_scr;
2838 RECT rt_clip;
2840 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2841 rt_scr.top = 0;
2842 rt_scr.right = clnt.right;
2843 rt_scr.bottom = clnt.bottom;
2845 rt_clip.left = pane->positions[idx]-scroll_pos;
2846 rt_clip.top = 0;
2847 rt_clip.right = clnt.right;
2848 rt_clip.bottom = clnt.bottom;
2850 if (rt_scr.left < 0) rt_scr.left = 0;
2851 if (rt_clip.left < 0) rt_clip.left = 0;
2853 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2855 rt_clip.right = pane->positions[idx+1];
2856 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2858 if (pnmh->code == HDN_ENDTRACK) {
2859 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
2861 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2862 set_header(pane);
2866 return FALSE;
2869 case HDN_DIVIDERDBLCLICK: {
2870 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
2871 HD_ITEM item;
2873 calc_single_width(pane, phdn->iItem);
2874 item.mask = HDI_WIDTH;
2875 item.cxy = pane->widths[phdn->iItem];
2877 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
2878 InvalidateRect(pane->hwnd, 0, TRUE);
2879 break;}
2882 return 0;
2885 #endif /* _NO_EXTENSIONS */
2888 static void scan_entry(ChildWnd* child, Entry* entry, HWND hwnd)
2890 TCHAR path[MAX_PATH];
2891 int idx = ListBox_GetCurSel(child->left.hwnd);
2892 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
2894 /* delete sub entries in left pane */
2895 for(;;) {
2896 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
2897 Entry* sub = (Entry*) res;
2899 if (res==LB_ERR || !sub || sub->level<=entry->level)
2900 break;
2902 ListBox_DeleteString(child->left.hwnd, idx+1);
2905 /* empty right pane */
2906 ListBox_ResetContent(child->right.hwnd);
2908 /* release memory */
2909 free_entries(entry);
2911 /* read contents from disk */
2912 #ifdef _SHELL_FOLDERS
2913 if (entry->etype == ET_SHELL)
2915 read_directory(entry, NULL, child->sortOrder, hwnd);
2917 else
2918 #endif
2920 get_path(entry, path);
2921 read_directory(entry, path, child->sortOrder, hwnd);
2924 /* insert found entries in right pane */
2925 insert_entries(&child->right, entry->down, -1);
2926 calc_widths(&child->right, FALSE);
2927 #ifndef _NO_EXTENSIONS
2928 set_header(&child->right);
2929 #endif
2931 child->header_wdths_ok = FALSE;
2933 SetCursor(old_cursor);
2937 /* expand a directory entry */
2939 static BOOL expand_entry(ChildWnd* child, Entry* dir)
2941 int idx;
2942 Entry* p;
2944 if (!dir || dir->expanded || !dir->down)
2945 return FALSE;
2947 p = dir->down;
2949 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
2950 p = p->next;
2952 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
2953 p->data.cFileName[2]=='\0' && p->next)
2954 p = p->next;
2957 /* no subdirectories ? */
2958 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2959 return FALSE;
2961 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
2963 dir->expanded = TRUE;
2965 /* insert entries in left pane */
2966 insert_entries(&child->left, p, idx);
2968 if (!child->header_wdths_ok) {
2969 if (calc_widths(&child->left, FALSE)) {
2970 #ifndef _NO_EXTENSIONS
2971 set_header(&child->left);
2972 #endif
2974 child->header_wdths_ok = TRUE;
2978 return TRUE;
2982 static void collapse_entry(Pane* pane, Entry* dir)
2984 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
2986 ShowWindow(pane->hwnd, SW_HIDE);
2988 /* hide sub entries */
2989 for(;;) {
2990 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
2991 Entry* sub = (Entry*) res;
2993 if (res==LB_ERR || !sub || sub->level<=dir->level)
2994 break;
2996 ListBox_DeleteString(pane->hwnd, idx+1);
2999 dir->expanded = FALSE;
3001 ShowWindow(pane->hwnd, SW_SHOW);
3005 static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd)
3007 TCHAR path[MAX_PATH];
3009 path[0] = '\0';
3011 child->left.cur = entry;
3012 child->right.root = entry->down? entry->down: entry;
3013 child->right.cur = entry;
3015 if (!entry->scanned)
3016 scan_entry(child, entry, hwnd);
3017 else {
3018 ListBox_ResetContent(child->right.hwnd);
3019 insert_entries(&child->right, entry->down, -1);
3020 calc_widths(&child->right, FALSE);
3021 #ifndef _NO_EXTENSIONS
3022 set_header(&child->right);
3023 #endif
3026 get_path(entry, path);
3027 lstrcpy(child->path, path);
3029 if (child->hwnd) /* only change window title, if the window already exists */
3030 SetWindowText(child->hwnd, path);
3032 if (path[0])
3033 SetCurrentDirectory(path);
3037 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3039 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3041 if ((int)hinst <= 32) {
3042 display_error(hwnd, GetLastError());
3043 return FALSE;
3046 return TRUE;
3049 #ifdef UNICODE
3050 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3052 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3054 if ((int)hinst <= 32) {
3055 display_error(hwnd, GetLastError());
3056 return FALSE;
3059 return TRUE;
3061 #endif
3064 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3066 TCHAR cmd[MAX_PATH];
3068 #ifdef _SHELL_FOLDERS
3069 if (entry->etype == ET_SHELL) {
3070 BOOL ret = TRUE;
3072 SHELLEXECUTEINFO shexinfo;
3074 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3075 shexinfo.fMask = SEE_MASK_IDLIST;
3076 shexinfo.hwnd = hwnd;
3077 shexinfo.lpVerb = NULL;
3078 shexinfo.lpFile = NULL;
3079 shexinfo.lpParameters = NULL;
3080 shexinfo.lpDirectory = NULL;
3081 shexinfo.nShow = nCmdShow;
3082 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3084 if (!ShellExecuteEx(&shexinfo)) {
3085 display_error(hwnd, GetLastError());
3086 ret = FALSE;
3089 if (shexinfo.lpIDList != entry->pidl)
3090 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3092 return ret;
3094 #endif
3096 get_path(entry, cmd);
3098 /* start program, open document... */
3099 return launch_file(hwnd, cmd, nCmdShow);
3103 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3105 Entry* entry = pane->cur;
3107 if (!entry)
3108 return;
3110 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3111 int scanned_old = entry->scanned;
3113 if (!scanned_old)
3114 scan_entry(child, entry, hwnd);
3116 #ifndef _NO_EXTENSIONS
3117 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3118 return;
3119 #endif
3121 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3122 entry = child->left.cur->up;
3123 collapse_entry(&child->left, entry);
3124 goto focus_entry;
3125 } else if (entry->expanded)
3126 collapse_entry(pane, child->left.cur);
3127 else {
3128 expand_entry(child, child->left.cur);
3130 if (!pane->treePane) focus_entry: {
3131 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3132 ListBox_SetCurSel(child->left.hwnd, idx);
3133 set_curdir(child, entry, hwnd);
3137 if (!scanned_old) {
3138 calc_widths(pane, FALSE);
3140 #ifndef _NO_EXTENSIONS
3141 set_header(pane);
3142 #endif
3144 } else {
3145 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3150 static BOOL pane_command(Pane* pane, UINT cmd)
3152 switch(cmd) {
3153 case ID_VIEW_NAME:
3154 if (pane->visible_cols) {
3155 pane->visible_cols = 0;
3156 calc_widths(pane, TRUE);
3157 #ifndef _NO_EXTENSIONS
3158 set_header(pane);
3159 #endif
3160 InvalidateRect(pane->hwnd, 0, TRUE);
3161 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3162 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3163 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3165 break;
3167 case ID_VIEW_ALL_ATTRIBUTES:
3168 if (pane->visible_cols != COL_ALL) {
3169 pane->visible_cols = COL_ALL;
3170 calc_widths(pane, TRUE);
3171 #ifndef _NO_EXTENSIONS
3172 set_header(pane);
3173 #endif
3174 InvalidateRect(pane->hwnd, 0, TRUE);
3175 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3176 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3177 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3179 break;
3181 #ifndef _NO_EXTENSIONS
3182 case ID_PREFERED_SIZES: {
3183 calc_widths(pane, TRUE);
3184 set_header(pane);
3185 InvalidateRect(pane->hwnd, 0, TRUE);
3186 break;}
3187 #endif
3189 /* TODO: more command ids... */
3191 default:
3192 return FALSE;
3195 return TRUE;
3199 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3201 IContextMenu* pcm;
3203 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3204 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3206 if (SUCCEEDED(hr)) {
3207 HMENU hmenu = CreatePopupMenu();
3209 if (hmenu) {
3210 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3212 if (SUCCEEDED(hr)) {
3213 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3215 if (idCmd) {
3216 CMINVOKECOMMANDINFO cmi;
3218 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3219 cmi.fMask = 0;
3220 cmi.hwnd = hwndParent;
3221 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3222 cmi.lpParameters = NULL;
3223 cmi.lpDirectory = NULL;
3224 cmi.nShow = SW_SHOWNORMAL;
3225 cmi.dwHotKey = 0;
3226 cmi.hIcon = 0;
3228 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3233 (*pcm->lpVtbl->Release)(pcm);
3236 return hr;
3240 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3242 static int last_split;
3244 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3245 ASSERT(child);
3247 switch(nmsg) {
3248 case WM_DRAWITEM: {
3249 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3250 Entry* entry = (Entry*) dis->itemData;
3252 if (dis->CtlID == IDW_TREE_LEFT)
3253 draw_item(&child->left, dis, entry, -1);
3254 else
3255 draw_item(&child->right, dis, entry, -1);
3257 return TRUE;}
3259 case WM_CREATE:
3260 InitChildWindow(child);
3261 break;
3263 case WM_NCDESTROY:
3264 free_child_window(child);
3265 SetWindowLong(hwnd, GWL_USERDATA, 0);
3266 break;
3268 case WM_PAINT: {
3269 PAINTSTRUCT ps;
3270 HBRUSH lastBrush;
3271 RECT rt;
3272 GetClientRect(hwnd, &rt);
3273 BeginPaint(hwnd, &ps);
3274 rt.left = child->split_pos-SPLIT_WIDTH/2;
3275 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3276 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3277 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3278 SelectObject(ps.hdc, lastBrush);
3279 #ifdef _NO_EXTENSIONS
3280 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3281 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3282 #endif
3283 EndPaint(hwnd, &ps);
3284 break;}
3286 case WM_SETCURSOR:
3287 if (LOWORD(lparam) == HTCLIENT) {
3288 POINT pt;
3289 GetCursorPos(&pt);
3290 ScreenToClient(hwnd, &pt);
3292 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3293 SetCursor(LoadCursor(0, IDC_SIZEWE));
3294 return TRUE;
3297 goto def;
3299 case WM_LBUTTONDOWN: {
3300 RECT rt;
3301 int x = LOWORD(lparam);
3303 GetClientRect(hwnd, &rt);
3305 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3306 last_split = child->split_pos;
3307 #ifdef _NO_EXTENSIONS
3308 draw_splitbar(hwnd, last_split);
3309 #endif
3310 SetCapture(hwnd);
3313 break;}
3315 case WM_LBUTTONUP:
3316 if (GetCapture() == hwnd) {
3317 #ifdef _NO_EXTENSIONS
3318 RECT rt;
3319 int x = LOWORD(lparam);
3320 draw_splitbar(hwnd, last_split);
3321 last_split = -1;
3322 GetClientRect(hwnd, &rt);
3323 child->split_pos = x;
3324 resize_tree(child, rt.right, rt.bottom);
3325 #endif
3326 ReleaseCapture();
3328 break;
3330 #ifdef _NO_EXTENSIONS
3331 case WM_CAPTURECHANGED:
3332 if (GetCapture()==hwnd && last_split>=0)
3333 draw_splitbar(hwnd, last_split);
3334 break;
3335 #endif
3337 case WM_KEYDOWN:
3338 if (wparam == VK_ESCAPE)
3339 if (GetCapture() == hwnd) {
3340 RECT rt;
3341 #ifdef _NO_EXTENSIONS
3342 draw_splitbar(hwnd, last_split);
3343 #else
3344 child->split_pos = last_split;
3345 #endif
3346 GetClientRect(hwnd, &rt);
3347 resize_tree(child, rt.right, rt.bottom);
3348 last_split = -1;
3349 ReleaseCapture();
3350 SetCursor(LoadCursor(0, IDC_ARROW));
3352 break;
3354 case WM_MOUSEMOVE:
3355 if (GetCapture() == hwnd) {
3356 RECT rt;
3357 int x = LOWORD(lparam);
3359 #ifdef _NO_EXTENSIONS
3360 HDC hdc = GetDC(hwnd);
3361 GetClientRect(hwnd, &rt);
3363 rt.left = last_split-SPLIT_WIDTH/2;
3364 rt.right = last_split+SPLIT_WIDTH/2+1;
3365 InvertRect(hdc, &rt);
3367 last_split = x;
3368 rt.left = x-SPLIT_WIDTH/2;
3369 rt.right = x+SPLIT_WIDTH/2+1;
3370 InvertRect(hdc, &rt);
3372 ReleaseDC(hwnd, hdc);
3373 #else
3374 GetClientRect(hwnd, &rt);
3376 if (x>=0 && x<rt.right) {
3377 child->split_pos = x;
3378 resize_tree(child, rt.right, rt.bottom);
3379 rt.left = x-SPLIT_WIDTH/2;
3380 rt.right = x+SPLIT_WIDTH/2+1;
3381 InvalidateRect(hwnd, &rt, FALSE);
3382 UpdateWindow(child->left.hwnd);
3383 UpdateWindow(hwnd);
3384 UpdateWindow(child->right.hwnd);
3386 #endif
3388 break;
3390 #ifndef _NO_EXTENSIONS
3391 case WM_GETMINMAXINFO:
3392 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3394 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3396 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3397 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3398 break;}
3399 #endif /* _NO_EXTENSIONS */
3401 case WM_SETFOCUS:
3402 SetCurrentDirectory(child->path);
3403 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3404 break;
3406 case WM_DISPATCH_COMMAND: {
3407 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3409 switch(LOWORD(wparam)) {
3410 case ID_WINDOW_NEW: {
3411 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3413 if (!create_child_window(new_child))
3414 free(new_child);
3416 break;}
3418 case ID_REFRESH:
3419 scan_entry(child, pane->cur, hwnd);
3420 break;
3422 case ID_ACTIVATE:
3423 activate_entry(child, pane, hwnd);
3424 break;
3426 default:
3427 return pane_command(pane, LOWORD(wparam));
3430 return TRUE;}
3432 case WM_COMMAND: {
3433 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3435 switch(HIWORD(wparam)) {
3436 case LBN_SELCHANGE: {
3437 int idx = ListBox_GetCurSel(pane->hwnd);
3438 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3440 if (pane == &child->left)
3441 set_curdir(child, entry, hwnd);
3442 else
3443 pane->cur = entry;
3444 break;}
3446 case LBN_DBLCLK:
3447 activate_entry(child, pane, hwnd);
3448 break;
3450 break;}
3452 #ifndef _NO_EXTENSIONS
3453 case WM_NOTIFY: {
3454 NMHDR* pnmh = (NMHDR*) lparam;
3455 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3456 #endif
3458 #ifdef _SHELL_FOLDERS
3459 case WM_CONTEXTMENU: {
3460 Pane* pane;
3461 int idx;
3463 /* first select the current item in the listbox */
3464 HWND hpanel = (HWND) wparam;
3465 POINTS* ppos = &MAKEPOINTS(lparam);
3466 POINT pt; POINTSTOPOINT(pt, *ppos);
3467 ScreenToClient(hpanel, &pt);
3468 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y));
3469 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt.x, pt.y));
3471 /* now create the popup menu using shell namespace and IContextMenu */
3472 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3473 idx = ListBox_GetCurSel(pane->hwnd);
3475 if (idx != -1) {
3476 HRESULT hr;
3477 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
3479 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3481 if (pidl_abs) {
3482 IShellFolder* parentFolder;
3483 LPCITEMIDLIST pidlLast;
3485 /* get and use the parent folder to display correct context menu in all cases */
3486 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3487 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, ppos->x, ppos->y);
3489 (*parentFolder->lpVtbl->Release)(parentFolder);
3492 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
3495 break;}
3496 #endif
3498 case WM_SIZE:
3499 if (wparam != SIZE_MINIMIZED)
3500 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3501 /* fall through */
3503 default: def:
3504 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3507 return 0;
3511 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3513 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
3514 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
3515 ASSERT(child);
3517 switch(nmsg) {
3518 #ifndef _NO_EXTENSIONS
3519 case WM_HSCROLL:
3520 set_header(pane);
3521 break;
3522 #endif
3524 case WM_SETFOCUS:
3525 child->focus_pane = pane==&child->right? 1: 0;
3526 ListBox_SetSel(hwnd, TRUE, 1);
3527 /*TODO: check menu items */
3528 break;
3530 case WM_KEYDOWN:
3531 if (wparam == VK_TAB) {
3532 /*TODO: SetFocus(Globals.hdrivebar) */
3533 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3537 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3541 static void InitInstance(HINSTANCE hinstance)
3543 WNDCLASSEX wcFrame;
3544 WNDCLASS wcChild;
3545 ATOM hChildClass;
3547 INITCOMMONCONTROLSEX icc = {
3548 sizeof(INITCOMMONCONTROLSEX),
3549 ICC_BAR_CLASSES
3552 HDC hdc = GetDC(0);
3554 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3556 InitCommonControlsEx(&icc);
3559 /* register frame window class */
3561 wcFrame.cbSize = sizeof(WNDCLASSEX);
3562 wcFrame.style = 0;
3563 wcFrame.lpfnWndProc = FrameWndProc;
3564 wcFrame.cbClsExtra = 0;
3565 wcFrame.cbWndExtra = 0;
3566 wcFrame.hInstance = hinstance;
3567 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
3568 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
3569 wcFrame.hbrBackground = 0;
3570 wcFrame.lpszMenuName = 0;
3571 wcFrame.lpszClassName = WINEFILEFRAME;
3572 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
3573 MAKEINTRESOURCE(IDI_WINEFILE),
3574 IMAGE_ICON,
3575 GetSystemMetrics(SM_CXSMICON),
3576 GetSystemMetrics(SM_CYSMICON),
3577 LR_SHARED);
3579 Globals.hframeClass = RegisterClassEx(&wcFrame);
3582 /* register tree windows class */
3584 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3585 wcChild.lpfnWndProc = ChildWndProc;
3586 wcChild.cbClsExtra = 0;
3587 wcChild.cbWndExtra = 0;
3588 wcChild.hInstance = hinstance;
3589 wcChild.hIcon = 0;
3590 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
3591 wcChild.hbrBackground = 0;
3592 wcChild.lpszMenuName = 0;
3593 wcChild.lpszClassName = WINEFILETREE;
3595 hChildClass = RegisterClass(&wcChild);
3598 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
3600 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
3602 ReleaseDC(0, hdc);
3604 Globals.hInstance = hinstance;
3606 #ifdef _SHELL_FOLDERS
3607 CoInitialize(NULL);
3608 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3609 SHGetDesktopFolder(&Globals.iDesktop);
3610 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
3611 #endif
3615 void show_frame(HWND hwndParent, int cmdshow)
3617 TCHAR path[MAX_PATH];
3618 ChildWnd* child;
3619 HMENU hMenuFrame, hMenuWindow;
3621 CLIENTCREATESTRUCT ccs;
3623 if (Globals.hMainWnd)
3624 return;
3626 Globals.hwndParent = hwndParent;
3628 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
3629 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3631 Globals.hMenuFrame = hMenuFrame;
3632 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
3633 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
3635 ccs.hWindowMenu = hMenuWindow;
3636 ccs.idFirstChild = IDW_FIRST_CHILD;
3639 /* create main window */
3640 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, TEXT("Wine File"), WS_OVERLAPPEDWINDOW,
3641 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3642 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3645 Globals.hmdiclient = CreateWindowEx(0, TEXT("MDICLIENT"), NULL,
3646 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3647 0, 0, 0, 0,
3648 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3652 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
3653 int btn = 1;
3654 PTSTR p;
3656 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3657 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3658 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3659 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3661 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3663 drivebarBtn.fsStyle = BTNS_BUTTON;
3665 #ifndef _NO_EXTENSIONS
3666 #ifdef __WINE__
3667 /* insert unix file system button */
3668 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
3670 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3671 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3672 drivebarBtn.iString++;
3673 #endif
3674 #ifdef _SHELL_FOLDERS
3675 /* insert shell namespace button */
3676 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
3678 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3679 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3680 drivebarBtn.iString++;
3681 #endif
3683 /* register windows drive root strings */
3684 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3685 #endif
3687 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3689 for(p=Globals.drives; *p; ) {
3690 #ifdef _NO_EXTENSIONS
3691 /* insert drive letter */
3692 TCHAR b[3] = {tolower(*p)};
3693 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3694 #endif
3695 switch(GetDriveType(p)) {
3696 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3697 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3698 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3699 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3700 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3703 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3704 drivebarBtn.idCommand++;
3705 drivebarBtn.iString++;
3707 while(*p++);
3712 TBBUTTON toolbarBtns[] = {
3713 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3714 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3715 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3716 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3717 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3718 /*TODO
3719 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3720 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON},
3721 */ };
3723 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
3724 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
3725 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
3726 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
3729 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
3730 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
3732 /* CreateStatusWindow does not accept WS_BORDER
3733 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
3734 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
3735 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
3737 /*TODO: read paths and window placements from registry */
3738 GetCurrentDirectory(MAX_PATH, path);
3740 ShowWindow(Globals.hMainWnd, cmdshow);
3742 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
3743 /* Shell Namespace as default: */
3744 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
3745 #else
3746 child = alloc_child_window(path, NULL, Globals.hMainWnd);
3747 #endif
3749 child->pos.showCmd = SW_SHOWMAXIMIZED;
3750 child->pos.rcNormalPosition.left = 0;
3751 child->pos.rcNormalPosition.top = 0;
3752 child->pos.rcNormalPosition.right = 320;
3753 child->pos.rcNormalPosition.bottom = 280;
3755 if (!create_child_window(child))
3756 free(child);
3758 SetWindowPlacement(child->hwnd, &child->pos);
3760 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
3762 Globals.prescan_node = FALSE;
3764 UpdateWindow(Globals.hMainWnd);
3767 void ExitInstance()
3769 #ifdef _SHELL_FOLDERS
3770 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
3771 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
3772 CoUninitialize();
3773 #endif
3775 ImageList_Destroy(Globals.himl);
3779 /* search for already running win[e]files */
3781 static int g_foundPrevInstance = 0;
3783 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
3785 TCHAR cls[128];
3787 GetClassName(hwnd, cls, 128);
3789 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
3790 g_foundPrevInstance++;
3791 return FALSE;
3794 return TRUE;
3797 /* search for window of given class name to allow only one running instance */
3798 int find_window_class(LPCTSTR classname)
3800 EnumWindows(EnumWndProc, (LPARAM)classname);
3802 if (g_foundPrevInstance)
3803 return 1;
3805 return 0;
3809 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
3811 MSG msg;
3813 InitInstance(hinstance);
3815 #ifndef _ROS_ /* don't maximize if being called from the ROS desktop */
3816 if (cmdshow == SW_SHOWNORMAL)
3817 /*TODO: read window placement from registry */
3818 cmdshow = SW_MAXIMIZE;
3819 #endif
3821 show_frame(hwndParent, cmdshow);
3823 while(GetMessage(&msg, 0, 0, 0)) {
3824 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
3825 continue;
3827 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
3828 continue;
3830 TranslateMessage(&msg);
3831 DispatchMessage(&msg);
3834 ExitInstance();
3836 return msg.wParam;
3840 #ifndef _ROS_
3842 int APIENTRY WinMain(HINSTANCE hinstance,
3843 HINSTANCE previnstance,
3844 LPSTR cmdline,
3845 int cmdshow)
3847 #ifdef _NO_EXTENSIONS
3848 if (find_window_class(WINEFILEFRAME))
3849 return 1;
3850 #endif
3852 winefile_main(hinstance, 0, cmdshow);
3854 return 0;
3857 #endif