Implement file filtering (matching of file name patterns and file
[wine/multimedia.git] / programs / winefile / winefile.c
blob8aaae98f57588b08a91d330b72cc520e4cfee019
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifdef __WINE__
22 #include "config.h"
23 #include "wine/port.h"
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 enum ENTRY_TYPE {
69 ET_WINDOWS,
70 ET_UNIX,
71 #ifdef _SHELL_FOLDERS
72 ET_SHELL
73 #endif
76 typedef struct _Entry {
77 struct _Entry* next;
78 struct _Entry* down;
79 struct _Entry* up;
81 BOOL expanded;
82 BOOL scanned;
83 int level;
85 WIN32_FIND_DATA data;
87 #ifndef _NO_EXTENSIONS
88 BY_HANDLE_FILE_INFORMATION bhfi;
89 BOOL bhfi_valid;
90 enum ENTRY_TYPE etype;
91 #endif
92 #ifdef _SHELL_FOLDERS
93 LPITEMIDLIST pidl;
94 IShellFolder* folder;
95 HICON hicon;
96 #endif
97 } Entry;
99 typedef struct {
100 Entry entry;
101 TCHAR path[MAX_PATH];
102 TCHAR volname[_MAX_FNAME];
103 TCHAR fs[_MAX_DIR];
104 DWORD drive_type;
105 DWORD fs_flags;
106 } Root;
108 enum COLUMN_FLAGS {
109 COL_SIZE = 0x01,
110 COL_DATE = 0x02,
111 COL_TIME = 0x04,
112 COL_ATTRIBUTES = 0x08,
113 COL_DOSNAMES = 0x10,
114 #ifdef _NO_EXTENSIONS
115 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
116 #else
117 COL_INDEX = 0x20,
118 COL_LINKS = 0x40,
119 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
120 #endif
123 typedef enum {
124 SORT_NAME,
125 SORT_EXT,
126 SORT_SIZE,
127 SORT_DATE
128 } SORT_ORDER;
130 typedef struct {
131 HWND hwnd;
132 #ifndef _NO_EXTENSIONS
133 HWND hwndHeader;
134 #endif
136 #ifndef _NO_EXTENSIONS
137 #define COLUMNS 10
138 #else
139 #define COLUMNS 5
140 #endif
141 int widths[COLUMNS];
142 int positions[COLUMNS+1];
144 BOOL treePane;
145 int visible_cols;
146 Entry* root;
147 Entry* cur;
148 } Pane;
150 typedef struct {
151 HWND hwnd;
152 Pane left;
153 Pane right;
154 int focus_pane; /* 0: left 1: right */
155 WINDOWPLACEMENT pos;
156 int split_pos;
157 BOOL header_wdths_ok;
159 TCHAR path[MAX_PATH];
160 TCHAR filter_pattern[MAX_PATH];
161 int filter_flags;
162 Root root;
164 SORT_ORDER sortOrder;
165 } ChildWnd;
168 extern void WineLicense(HWND hwnd);
169 extern void WineWarranty(HWND hwnd);
172 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
173 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
174 static void refresh_child(ChildWnd* child);
175 static void refresh_drives();
176 static void get_path(Entry* dir, PTSTR path);
178 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
179 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
183 /* globals */
184 WINEFILE_GLOBALS Globals;
186 static int last_split;
188 /* some common string constants */
189 const static TCHAR sEmpty[] = {'\0'};
190 const static TCHAR sSpace[] = {' ', '\0'};
191 const static TCHAR sNumFmt[] = {'%','d','\0'};
192 const static TCHAR sQMarks[] = {'?','?','?','\0'};
194 /* window class names */
195 const static TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
196 const static TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
198 #ifdef _MSC_VER
199 /* #define LONGLONGARG _T("I64") */
200 const static TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
201 const static TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
202 #else
203 /* #define LONGLONGARG _T("L") */
204 const static TCHAR sLongHexFmt[] = {'%','L','X','\0'};
205 const static TCHAR sLongNumFmt[] = {'%','L','d','\0'};
206 #endif
209 /* load resource string */
210 static LPTSTR load_string(LPTSTR buffer, UINT id)
212 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
214 return buffer;
217 #define RS(b, i) load_string(b, i)
220 /* display error message for the specified WIN32 error code */
221 static void display_error(HWND hwnd, DWORD error)
223 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
224 PTSTR msg;
226 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
227 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
228 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
229 else
230 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
232 LocalFree(msg);
236 /* display network error message using WNetGetLastError() */
237 static void display_network_error(HWND hwnd)
239 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
240 DWORD error;
242 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
243 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
247 /* allocate and initialise a directory entry */
248 static Entry* alloc_entry()
250 Entry* entry = (Entry*) malloc(sizeof(Entry));
252 #ifdef _SHELL_FOLDERS
253 entry->pidl = NULL;
254 entry->folder = NULL;
255 entry->hicon = 0;
256 #endif
258 return entry;
261 /* free a directory entry */
262 static void free_entry(Entry* entry)
264 #ifdef _SHELL_FOLDERS
265 if (entry->hicon && entry->hicon!=(HICON)-1)
266 DestroyIcon(entry->hicon);
268 if (entry->folder && entry->folder!=Globals.iDesktop)
269 (*entry->folder->lpVtbl->Release)(entry->folder);
271 if (entry->pidl)
272 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, entry->pidl);
273 #endif
275 free(entry);
278 /* recursively free all child entries */
279 static void free_entries(Entry* dir)
281 Entry *entry, *next=dir->down;
283 if (next) {
284 dir->down = 0;
286 do {
287 entry = next;
288 next = entry->next;
290 free_entries(entry);
291 free_entry(entry);
292 } while(next);
297 static void read_directory_win(Entry* dir, LPCTSTR path)
299 Entry* first_entry = NULL;
300 Entry* last = NULL;
301 Entry* entry;
303 int level = dir->level + 1;
304 WIN32_FIND_DATA w32fd;
305 HANDLE hFind;
306 #ifndef _NO_EXTENSIONS
307 HANDLE hFile;
308 #endif
310 TCHAR buffer[MAX_PATH], *p;
311 for(p=buffer; *path; )
312 *p++ = *path++;
314 *p++ = '\\';
315 p[0] = '*';
316 p[1] = '\0';
318 hFind = FindFirstFile(buffer, &w32fd);
320 if (hFind != INVALID_HANDLE_VALUE) {
321 do {
322 #ifdef _NO_EXTENSIONS
323 /* hide directory entry "." */
324 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
325 LPCTSTR name = w32fd.cFileName;
327 if (name[0]=='.' && name[1]=='\0')
328 continue;
330 #endif
331 entry = alloc_entry();
333 if (!first_entry)
334 first_entry = entry;
336 if (last)
337 last->next = entry;
339 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
340 entry->down = NULL;
341 entry->up = dir;
342 entry->expanded = FALSE;
343 entry->scanned = FALSE;
344 entry->level = level;
346 #ifndef _NO_EXTENSIONS
347 entry->etype = ET_WINDOWS;
348 entry->bhfi_valid = FALSE;
350 lstrcpy(p, entry->data.cFileName);
352 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
353 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
355 if (hFile != INVALID_HANDLE_VALUE) {
356 if (GetFileInformationByHandle(hFile, &entry->bhfi))
357 entry->bhfi_valid = TRUE;
359 CloseHandle(hFile);
361 #endif
363 last = entry;
364 } while(FindNextFile(hFind, &w32fd));
366 if (last)
367 last->next = NULL;
369 FindClose(hFind);
372 dir->down = first_entry;
373 dir->scanned = TRUE;
377 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
379 Entry* entry;
381 for(entry=dir->down; entry; entry=entry->next) {
382 LPCTSTR p = name;
383 LPCTSTR q = entry->data.cFileName;
385 do {
386 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
387 return entry;
388 } while(tolower(*p++) == tolower(*q++));
390 p = name;
391 q = entry->data.cAlternateFileName;
393 do {
394 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
395 return entry;
396 } while(tolower(*p++) == tolower(*q++));
399 return 0;
403 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
405 TCHAR buffer[MAX_PATH];
406 Entry* entry = &root->entry;
407 LPCTSTR s = path;
408 PTSTR d = buffer;
410 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
412 #ifndef _NO_EXTENSIONS
413 entry->etype = ET_WINDOWS;
414 #endif
416 while(entry) {
417 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
418 *d++ = *s++;
420 while(*s==TEXT('\\') || *s==TEXT('/'))
421 s++;
423 *d++ = TEXT('\\');
424 *d = TEXT('\0');
426 read_directory(entry, buffer, sortOrder, hwnd);
428 if (entry->down)
429 entry->expanded = TRUE;
431 if (!*s)
432 break;
434 entry = find_entry_win(entry, s);
437 SetCursor(old_cursor);
439 return entry;
443 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
445 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
447 struct tm* tm = gmtime(t);
448 SYSTEMTIME stime;
450 if (!tm)
451 return FALSE;
453 stime.wYear = tm->tm_year+1900;
454 stime.wMonth = tm->tm_mon+1;
455 /* stime.wDayOfWeek */
456 stime.wDay = tm->tm_mday;
457 stime.wHour = tm->tm_hour;
458 stime.wMinute = tm->tm_min;
459 stime.wSecond = tm->tm_sec;
461 return SystemTimeToFileTime(&stime, ftime);
464 static void read_directory_unix(Entry* dir, LPCTSTR path)
466 Entry* first_entry = NULL;
467 Entry* last = NULL;
468 Entry* entry;
470 int level = dir->level + 1;
472 DIR* pdir = opendir(path);
474 if (pdir) {
475 struct stat st;
476 struct dirent* ent;
477 TCHAR buffer[MAX_PATH], *p;
479 for(p=buffer; *path; )
480 *p++ = *path++;
482 if (p==buffer || p[-1]!='/')
483 *p++ = '/';
485 while((ent=readdir(pdir))) {
486 entry = alloc_entry();
488 if (!first_entry)
489 first_entry = entry;
491 if (last)
492 last->next = entry;
494 entry->etype = ET_UNIX;
496 lstrcpy(entry->data.cFileName, ent->d_name);
497 entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
499 strcpy(p, ent->d_name);
501 if (!stat(buffer, &st)) {
502 if (S_ISDIR(st.st_mode))
503 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
505 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
506 entry->data.nFileSizeHigh = st.st_size >> 32;
508 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
509 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
510 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
512 entry->bhfi.nFileIndexLow = ent->d_ino;
513 entry->bhfi.nFileIndexHigh = 0;
515 entry->bhfi.nNumberOfLinks = st.st_nlink;
517 entry->bhfi_valid = TRUE;
518 } else {
519 entry->data.nFileSizeLow = 0;
520 entry->data.nFileSizeHigh = 0;
521 entry->bhfi_valid = FALSE;
524 entry->down = NULL;
525 entry->up = dir;
526 entry->expanded = FALSE;
527 entry->scanned = FALSE;
528 entry->level = level;
530 last = entry;
533 if (last)
534 last->next = NULL;
536 closedir(pdir);
539 dir->down = first_entry;
540 dir->scanned = TRUE;
543 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
545 Entry* entry;
547 for(entry=dir->down; entry; entry=entry->next) {
548 LPCTSTR p = name;
549 LPCTSTR q = entry->data.cFileName;
551 do {
552 if (!*p || *p==TEXT('/'))
553 return entry;
554 } while(*p++ == *q++);
557 return 0;
560 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
562 TCHAR buffer[MAX_PATH];
563 Entry* entry = &root->entry;
564 LPCTSTR s = path;
565 PTSTR d = buffer;
567 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
569 entry->etype = ET_UNIX;
571 while(entry) {
572 while(*s && *s!=TEXT('/'))
573 *d++ = *s++;
575 while(*s == TEXT('/'))
576 s++;
578 *d++ = TEXT('/');
579 *d = TEXT('\0');
581 read_directory(entry, buffer, sortOrder, hwnd);
583 if (entry->down)
584 entry->expanded = TRUE;
586 if (!*s)
587 break;
589 entry = find_entry_unix(entry, s);
592 SetCursor(old_cursor);
594 return entry;
597 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
600 #ifdef _SHELL_FOLDERS
602 #ifdef UNICODE
603 #define tcscpyn strcpyn
604 #define get_strret get_strretW
605 #define path_from_pidl path_from_pidlW
606 #else
607 #define tcscpyn wcscpyn
608 #define get_strret get_strretA
609 #define path_from_pidl path_from_pidlA
610 #endif
613 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
615 LPCSTR s;
616 LPSTR d = dest;
618 for(s=source; count&&(*d++=*s++); )
619 count--;
621 return dest;
624 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
626 LPCWSTR s;
627 LPWSTR d = dest;
629 for(s=source; count&&(*d++=*s++); )
630 count--;
632 return dest;
636 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
638 switch(str->uType) {
639 case STRRET_WSTR:
640 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
641 break;
643 case STRRET_OFFSET:
644 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
645 break;
647 case STRRET_CSTR:
648 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
652 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
654 switch(str->uType) {
655 case STRRET_WSTR:
656 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
657 break;
659 case STRRET_OFFSET:
660 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
661 break;
663 case STRRET_CSTR:
664 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
669 static void free_strret(STRRET* str)
671 if (str->uType == STRRET_WSTR)
672 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
676 HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
678 STRRET str;
680 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, flags, &str);
682 if (SUCCEEDED(hr)) {
683 get_strret(&str, &pidl->mkid, buffer, len);
684 free_strret(&str);
685 } else
686 buffer[0] = '\0';
688 return hr;
692 HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
694 STRRET str;
696 /* SHGDN_FORPARSING: get full path of id list */
697 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
699 if (SUCCEEDED(hr)) {
700 get_strretA(&str, &pidl->mkid, buffer, len);
701 free_strret(&str);
702 } else
703 buffer[0] = '\0';
705 return hr;
708 HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
710 STRRET str;
712 /* SHGDN_FORPARSING: get full path of id list */
713 HRESULT hr = (*folder->lpVtbl->GetDisplayNameOf)(folder, pidl, SHGDN_FORPARSING, &str);
715 if (SUCCEEDED(hr)) {
716 get_strretW(&str, &pidl->mkid, buffer, len);
717 free_strret(&str);
718 } else
719 buffer[0] = '\0';
721 return hr;
725 /* create an item id list from a file system path */
727 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
729 LPITEMIDLIST pidl;
730 HRESULT hr;
731 ULONG len;
733 #ifdef UNICODE
734 LPWSTR buffer = path;
735 #else
736 WCHAR buffer[MAX_PATH];
737 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
738 #endif
740 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
741 if (FAILED(hr))
742 return NULL;
744 return pidl;
748 /* convert an item id list from relative to absolute (=relative to the desktop) format */
750 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
752 if (entry->up && entry->up->etype==ET_SHELL) {
753 IShellFolder* folder = entry->up->folder;
754 WCHAR buffer[MAX_PATH];
756 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
758 if (SUCCEEDED(hr)) {
759 LPITEMIDLIST pidl;
760 ULONG len;
762 hr = (*Globals.iDesktop->lpVtbl->ParseDisplayName)(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
764 if (SUCCEEDED(hr))
765 return pidl;
767 } else if (entry->etype == ET_WINDOWS) {
768 TCHAR path[MAX_PATH];
770 get_path(entry, path);
772 return get_path_pidl(path, hwnd);
773 } else if (entry->pidl)
774 return ILClone(entry->pidl);
776 return NULL;
780 HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
782 IExtractIcon* pExtract;
784 if (SUCCEEDED((*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
785 TCHAR path[_MAX_PATH];
786 unsigned flags;
787 HICON hicon;
788 int idx;
790 if (SUCCEEDED((*pExtract->lpVtbl->GetIconLocation)(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
791 if (!(flags & GIL_NOTFILENAME)) {
792 if (idx == -1)
793 idx = 0; /* special case for some control panel applications */
795 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
796 flags &= ~GIL_DONTCACHE;
797 } else {
798 HICON hIconLarge = 0;
800 HRESULT hr = (*pExtract->lpVtbl->Extract)(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
802 if (SUCCEEDED(hr))
803 DestroyIcon(hIconLarge);
806 return hicon;
810 return 0;
814 static Entry* find_entry_shell(Entry* dir, LPITEMIDLIST pidl)
816 Entry* entry;
818 for(entry=dir->down; entry; entry=entry->next) {
819 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
820 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
821 return entry;
824 return 0;
827 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
829 Entry* entry = &root->entry;
830 Entry* next;
831 LPITEMIDLIST next_pidl = pidl;
832 IShellFolder* folder;
833 IShellFolder* child = NULL;
834 HRESULT hr;
836 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
838 #ifndef _NO_EXTENSIONS
839 entry->etype = ET_SHELL;
840 #endif
842 folder = Globals.iDesktop;
844 while(entry) {
845 entry->pidl = next_pidl;
846 entry->folder = folder;
848 if (!pidl->mkid.cb)
849 break;
851 /* copy first element of item idlist */
852 next_pidl = (*Globals.iMalloc->lpVtbl->Alloc)(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
853 memcpy(next_pidl, pidl, pidl->mkid.cb);
854 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
856 hr = (*folder->lpVtbl->BindToObject)(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
857 if (!SUCCEEDED(hr))
858 break;
860 read_directory(entry, NULL, sortOrder, hwnd);
862 if (entry->down)
863 entry->expanded = TRUE;
865 next = find_entry_shell(entry, next_pidl);
866 if (!next)
867 break;
869 folder = child;
870 entry = next;
872 /* go to next element */
873 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
876 SetCursor(old_cursor);
878 return entry;
882 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
884 if (!(attribs & SFGAO_FILESYSTEM) ||
885 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
886 WIN32_FILE_ATTRIBUTE_DATA fad;
887 IDataObject* pDataObj;
889 STGMEDIUM medium = {0, {0}, 0};
890 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
892 HRESULT hr = (*folder->lpVtbl->GetUIObjectOf)(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
894 if (SUCCEEDED(hr)) {
895 hr = (*pDataObj->lpVtbl->GetData)(pDataObj, &fmt, &medium);
897 (*pDataObj->lpVtbl->Release)(pDataObj);
899 if (SUCCEEDED(hr)) {
900 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
901 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
903 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
904 w32fdata->dwFileAttributes = fad.dwFileAttributes;
905 w32fdata->ftCreationTime = fad.ftCreationTime;
906 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
907 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
909 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
910 w32fdata->nFileSizeLow = fad.nFileSizeLow;
911 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
915 SetErrorMode(sem_org);
917 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
918 GlobalFree(medium.UNION_MEMBER(hGlobal));
923 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
924 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
926 if (attribs & SFGAO_READONLY)
927 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
929 if (attribs & SFGAO_COMPRESSED)
930 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
934 static void read_directory_shell(Entry* dir, HWND hwnd)
936 IShellFolder* folder = dir->folder;
937 int level = dir->level + 1;
938 HRESULT hr;
940 IShellFolder* child;
941 IEnumIDList* idlist;
943 Entry* first_entry = NULL;
944 Entry* last = NULL;
945 Entry* entry;
947 if (!folder)
948 return;
950 hr = (*folder->lpVtbl->EnumObjects)(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
952 if (SUCCEEDED(hr)) {
953 for(;;) {
954 #define FETCH_ITEM_COUNT 32
955 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
956 SFGAOF attribs;
957 ULONG cnt = 0;
958 ULONG n;
960 memset(pidls, 0, sizeof(pidls));
962 hr = (*idlist->lpVtbl->Next)(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
963 if (!SUCCEEDED(hr))
964 break;
966 if (hr == S_FALSE)
967 break;
969 for(n=0; n<cnt; ++n) {
970 entry = alloc_entry();
972 if (!first_entry)
973 first_entry = entry;
975 if (last)
976 last->next = entry;
978 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
979 entry->bhfi_valid = FALSE;
981 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
983 hr = (*folder->lpVtbl->GetAttributesOf)(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
985 if (SUCCEEDED(hr)) {
986 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
987 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
989 entry->bhfi_valid = TRUE;
990 } else
991 attribs = 0;
992 } else
993 attribs = 0;
995 entry->pidl = pidls[n];
997 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
998 hr = (*folder->lpVtbl->BindToObject)(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1000 if (SUCCEEDED(hr))
1001 entry->folder = child;
1002 else
1003 entry->folder = NULL;
1005 else
1006 entry->folder = NULL;
1008 if (!entry->data.cFileName[0])
1009 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1011 /* get display icons for files and virtual objects */
1012 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1013 !(attribs & SFGAO_FILESYSTEM)) {
1014 entry->hicon = extract_icon(folder, pidls[n]);
1016 if (!entry->hicon)
1017 entry->hicon = (HICON)-1; /* don't try again later */
1020 entry->down = NULL;
1021 entry->up = dir;
1022 entry->expanded = FALSE;
1023 entry->scanned = FALSE;
1024 entry->level = level;
1026 #ifndef _NO_EXTENSIONS
1027 entry->etype = ET_SHELL;
1028 entry->bhfi_valid = FALSE;
1029 #endif
1031 last = entry;
1035 (*idlist->lpVtbl->Release)(idlist);
1038 if (last)
1039 last->next = NULL;
1041 dir->down = first_entry;
1042 dir->scanned = TRUE;
1045 #endif /* _SHELL_FOLDERS */
1048 /* sort order for different directory/file types */
1049 enum TYPE_ORDER {
1050 TO_DIR = 0,
1051 TO_DOT = 1,
1052 TO_DOTDOT = 2,
1053 TO_OTHER_DIR = 3,
1054 TO_FILE = 4
1057 /* distinguish between ".", ".." and any other directory names */
1058 static int TypeOrderFromDirname(LPCTSTR name)
1060 if (name[0] == '.') {
1061 if (name[1] == '\0')
1062 return TO_DOT; /* "." */
1064 if (name[1]=='.' && name[2]=='\0')
1065 return TO_DOTDOT; /* ".." */
1068 return TO_OTHER_DIR; /* anything else */
1071 /* directories first... */
1072 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1074 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1075 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1077 /* Handle "." and ".." as special case and move them at the very first beginning. */
1078 if (order1==TO_DIR && order2==TO_DIR) {
1079 order1 = TypeOrderFromDirname(fd1->cFileName);
1080 order2 = TypeOrderFromDirname(fd2->cFileName);
1083 return order2==order1? 0: order1<order2? -1: 1;
1087 static int compareName(const void* arg1, const void* arg2)
1089 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1090 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1092 int cmp = compareType(fd1, fd2);
1093 if (cmp)
1094 return cmp;
1096 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1099 static int compareExt(const void* arg1, const void* arg2)
1101 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1102 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1103 const TCHAR *name1, *name2, *ext1, *ext2;
1105 int cmp = compareType(fd1, fd2);
1106 if (cmp)
1107 return cmp;
1109 name1 = fd1->cFileName;
1110 name2 = fd2->cFileName;
1112 ext1 = _tcsrchr(name1, TEXT('.'));
1113 ext2 = _tcsrchr(name2, TEXT('.'));
1115 if (ext1)
1116 ext1++;
1117 else
1118 ext1 = sEmpty;
1120 if (ext2)
1121 ext2++;
1122 else
1123 ext2 = sEmpty;
1125 cmp = lstrcmpi(ext1, ext2);
1126 if (cmp)
1127 return cmp;
1129 return lstrcmpi(name1, name2);
1132 static int compareSize(const void* arg1, const void* arg2)
1134 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1135 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1137 int cmp = compareType(fd1, fd2);
1138 if (cmp)
1139 return cmp;
1141 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1143 if (cmp < 0)
1144 return -1;
1145 else if (cmp > 0)
1146 return 1;
1148 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1150 return cmp<0? -1: cmp>0? 1: 0;
1153 static int compareDate(const void* arg1, const void* arg2)
1155 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1156 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1158 int cmp = compareType(fd1, fd2);
1159 if (cmp)
1160 return cmp;
1162 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1166 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1167 compareName, /* SORT_NAME */
1168 compareExt, /* SORT_EXT */
1169 compareSize, /* SORT_SIZE */
1170 compareDate /* SORT_DATE */
1174 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1176 Entry* entry = dir->down;
1177 Entry** array, **p;
1178 int len;
1180 len = 0;
1181 for(entry=dir->down; entry; entry=entry->next)
1182 len++;
1184 if (len) {
1185 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1187 p = array;
1188 for(entry=dir->down; entry; entry=entry->next)
1189 *p++ = entry;
1191 /* call qsort with the appropriate compare function */
1192 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1194 dir->down = array[0];
1196 for(p=array; --len; p++)
1197 p[0]->next = p[1];
1199 (*p)->next = 0;
1200 HeapFree( GetProcessHeap(), 0, array );
1205 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1207 TCHAR buffer[MAX_PATH];
1208 Entry* entry;
1209 LPCTSTR s;
1210 PTSTR d;
1212 #ifdef _SHELL_FOLDERS
1213 if (dir->etype == ET_SHELL)
1215 read_directory_shell(dir, hwnd);
1217 if (Globals.prescan_node) {
1218 s = path;
1219 d = buffer;
1221 while(*s)
1222 *d++ = *s++;
1224 *d++ = TEXT('\\');
1226 for(entry=dir->down; entry; entry=entry->next)
1227 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1228 read_directory_shell(entry, hwnd);
1229 SortDirectory(entry, sortOrder);
1233 else
1234 #endif
1235 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1236 if (dir->etype == ET_UNIX)
1238 read_directory_unix(dir, path);
1240 if (Globals.prescan_node) {
1241 s = path;
1242 d = buffer;
1244 while(*s)
1245 *d++ = *s++;
1247 *d++ = TEXT('/');
1249 for(entry=dir->down; entry; entry=entry->next)
1250 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1251 lstrcpy(d, entry->data.cFileName);
1252 read_directory_unix(entry, buffer);
1253 SortDirectory(entry, sortOrder);
1257 else
1258 #endif
1260 read_directory_win(dir, path);
1262 if (Globals.prescan_node) {
1263 s = path;
1264 d = buffer;
1266 while(*s)
1267 *d++ = *s++;
1269 *d++ = TEXT('\\');
1271 for(entry=dir->down; entry; entry=entry->next)
1272 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1273 lstrcpy(d, entry->data.cFileName);
1274 read_directory_win(entry, buffer);
1275 SortDirectory(entry, sortOrder);
1280 SortDirectory(dir, sortOrder);
1284 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1286 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1287 const static TCHAR sSlash[] = {'/', '\0'};
1288 #endif
1289 const static TCHAR sBackslash[] = {'\\', '\0'};
1291 #ifdef _SHELL_FOLDERS
1292 if (pidl)
1294 /* read shell namespace tree */
1295 root->drive_type = DRIVE_UNKNOWN;
1296 drv[0] = '\\';
1297 drv[1] = '\0';
1298 load_string(root->volname, IDS_DESKTOP);
1299 root->fs_flags = 0;
1300 load_string(root->fs, IDS_SHELL);
1302 return read_tree_shell(root, pidl, sortOrder, hwnd);
1304 else
1305 #endif
1306 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1307 if (*path == '/')
1309 /* read unix file system tree */
1310 root->drive_type = GetDriveType(path);
1312 lstrcat(drv, sSlash);
1313 load_string(root->volname, IDS_ROOT_FS);
1314 root->fs_flags = 0;
1315 load_string(root->fs, IDS_UNIXFS);
1317 lstrcpy(root->path, sSlash);
1319 return read_tree_unix(root, path, sortOrder, hwnd);
1321 #endif
1323 /* read WIN32 file system tree */
1324 root->drive_type = GetDriveType(path);
1326 lstrcat(drv, sBackslash);
1327 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1329 lstrcpy(root->path, drv);
1331 return read_tree_win(root, path, sortOrder, hwnd);
1335 /* flags to filter different file types */
1336 enum TYPE_FILTER {
1337 TF_DIRECTORIES = 0x01,
1338 TF_PROGRAMS = 0x02,
1339 TF_DOCUMENTS = 0x04,
1340 TF_OTHERS = 0x08,
1341 TF_HIDDEN = 0x10,
1342 TF_ALL = 0x1F
1346 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1348 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1349 TCHAR b1[BUFFER_LEN];
1350 const static TCHAR sAsterics[] = {'*', '\0'};
1352 ChildWnd* child = (ChildWnd*) malloc(sizeof(ChildWnd));
1353 Root* root = &child->root;
1354 Entry* entry;
1356 memset(child, 0, sizeof(ChildWnd));
1358 child->left.treePane = TRUE;
1359 child->left.visible_cols = 0;
1361 child->right.treePane = FALSE;
1362 #ifndef _NO_EXTENSIONS
1363 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1364 #else
1365 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1366 #endif
1368 child->pos.length = sizeof(WINDOWPLACEMENT);
1369 child->pos.flags = 0;
1370 child->pos.showCmd = SW_SHOWNORMAL;
1371 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1372 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1373 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1374 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1376 child->focus_pane = 0;
1377 child->split_pos = DEFAULT_SPLIT_POS;
1378 child->sortOrder = SORT_NAME;
1379 child->header_wdths_ok = FALSE;
1381 if (path)
1383 lstrcpy(child->path, path);
1385 _tsplitpath(path, drv, dir, name, ext);
1388 _tcscpy(child->filter_pattern, sAsterics);
1389 child->filter_flags = TF_ALL;
1391 root->entry.level = 0;
1393 entry = read_tree(root, path, pidl, drv, child->sortOrder, hwnd);
1395 #ifdef _SHELL_FOLDERS
1396 if (root->entry.etype == ET_SHELL)
1397 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1398 else
1399 #endif
1400 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1402 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1404 child->left.root = &root->entry;
1405 child->right.root = NULL;
1407 set_curdir(child, entry, 0, hwnd);
1409 return child;
1413 /* free all memory associated with a child window */
1414 static void free_child_window(ChildWnd* child)
1416 free_entries(&child->root.entry);
1417 free(child);
1421 /* get full path of specified directory entry */
1422 static void get_path(Entry* dir, PTSTR path)
1424 Entry* entry;
1425 int len = 0;
1426 int level = 0;
1428 #ifdef _SHELL_FOLDERS
1429 if (dir->etype == ET_SHELL)
1431 SFGAOF attribs;
1432 HRESULT hr = S_OK;
1434 path[0] = TEXT('\0');
1436 attribs = 0;
1438 if (dir->folder)
1439 hr = (*dir->folder->lpVtbl->GetAttributesOf)(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1441 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1442 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1444 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1447 else
1448 #endif
1450 for(entry=dir; entry; level++) {
1451 LPCTSTR name;
1452 int l;
1455 LPCTSTR s;
1456 name = entry->data.cFileName;
1457 s = name;
1459 for(l=0; *s && *s!=TEXT('/') && *s!=TEXT('\\'); s++)
1460 l++;
1463 if (entry->up) {
1464 if (l > 0) {
1465 memmove(path+l+1, path, len*sizeof(TCHAR));
1466 memcpy(path+1, name, l*sizeof(TCHAR));
1467 len += l+1;
1469 #ifndef _NO_EXTENSIONS
1470 if (entry->etype == ET_UNIX)
1471 path[0] = TEXT('/');
1472 else
1473 #endif
1474 path[0] = TEXT('\\');
1477 entry = entry->up;
1478 } else {
1479 memmove(path+l, path, len*sizeof(TCHAR));
1480 memcpy(path, name, l*sizeof(TCHAR));
1481 len += l;
1482 break;
1486 if (!level) {
1487 #ifndef _NO_EXTENSIONS
1488 if (entry->etype == ET_UNIX)
1489 path[len++] = TEXT('/');
1490 else
1491 #endif
1492 path[len++] = TEXT('\\');
1495 path[len] = TEXT('\0');
1500 static void resize_frame_rect(HWND hwnd, PRECT prect)
1502 int new_top;
1503 RECT rt;
1505 if (IsWindowVisible(Globals.htoolbar)) {
1506 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1507 GetClientRect(Globals.htoolbar, &rt);
1508 prect->top = rt.bottom+3;
1509 prect->bottom -= rt.bottom+3;
1512 if (IsWindowVisible(Globals.hdrivebar)) {
1513 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1514 GetClientRect(Globals.hdrivebar, &rt);
1515 new_top = --prect->top + rt.bottom+3;
1516 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1517 prect->top = new_top;
1518 prect->bottom -= rt.bottom+2;
1521 if (IsWindowVisible(Globals.hstatusbar)) {
1522 int parts[] = {300, 500};
1524 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1525 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1526 GetClientRect(Globals.hstatusbar, &rt);
1527 prect->bottom -= rt.bottom;
1530 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1533 static void resize_frame(HWND hwnd, int cx, int cy)
1535 RECT rect;
1537 rect.left = 0;
1538 rect.top = 0;
1539 rect.right = cx;
1540 rect.bottom = cy;
1542 resize_frame_rect(hwnd, &rect);
1545 static void resize_frame_client(HWND hwnd)
1547 RECT rect;
1549 GetClientRect(hwnd, &rect);
1551 resize_frame_rect(hwnd, &rect);
1555 static HHOOK hcbthook;
1556 static ChildWnd* newchild = NULL;
1558 LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1560 if (code==HCBT_CREATEWND && newchild) {
1561 ChildWnd* child = newchild;
1562 newchild = NULL;
1564 child->hwnd = (HWND) wparam;
1565 SetWindowLong(child->hwnd, GWL_USERDATA, (LPARAM)child);
1568 return CallNextHookEx(hcbthook, code, wparam, lparam);
1571 static HWND create_child_window(ChildWnd* child)
1573 MDICREATESTRUCT mcs;
1574 int idx;
1576 mcs.szClass = sWINEFILETREE;
1577 mcs.szTitle = (LPTSTR)child->path;
1578 mcs.hOwner = Globals.hInstance;
1579 mcs.x = child->pos.rcNormalPosition.left;
1580 mcs.y = child->pos.rcNormalPosition.top;
1581 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1582 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1583 mcs.style = 0;
1584 mcs.lParam = 0;
1586 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1588 newchild = child;
1589 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1590 if (!child->hwnd) {
1591 UnhookWindowsHookEx(hcbthook);
1592 return 0;
1595 UnhookWindowsHookEx(hcbthook);
1597 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1598 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1600 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
1601 ListBox_SetCurSel(child->left.hwnd, idx);
1603 return child->hwnd;
1607 struct ExecuteDialog {
1608 TCHAR cmd[MAX_PATH];
1609 int cmdshow;
1612 static INT_PTR CALLBACK ExecuteDialogWndProg(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1614 static struct ExecuteDialog* dlg;
1616 switch(nmsg) {
1617 case WM_INITDIALOG:
1618 dlg = (struct ExecuteDialog*) lparam;
1619 return 1;
1621 case WM_COMMAND: {
1622 int id = (int)wparam;
1624 if (id == IDOK) {
1625 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1626 dlg->cmdshow = Button_GetState(GetDlgItem(hwnd,214))&BST_CHECKED?
1627 SW_SHOWMINIMIZED: SW_SHOWNORMAL;
1628 EndDialog(hwnd, id);
1629 } else if (id == IDCANCEL)
1630 EndDialog(hwnd, id);
1632 return 1;}
1635 return 0;
1639 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1641 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1643 switch(nmsg) {
1644 case WM_INITDIALOG:
1645 SetWindowLong(hwnd, GWL_USERDATA, lparam);
1646 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1647 return 1;
1649 case WM_COMMAND: {
1650 int id = (int)wparam;
1652 switch(id) {
1653 case IDOK: {
1654 LPTSTR dest = (LPTSTR) GetWindowLong(hwnd, GWL_USERDATA);
1655 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1656 EndDialog(hwnd, id);
1657 break;}
1659 case IDCANCEL:
1660 EndDialog(hwnd, id);
1661 break;
1663 case 254:
1664 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1665 break;
1668 return 1;
1672 return 0;
1676 struct FilterDialog {
1677 TCHAR pattern[MAX_PATH];
1678 int flags;
1681 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1683 static struct FilterDialog* dlg;
1685 switch(nmsg) {
1686 case WM_INITDIALOG:
1687 dlg = (struct FilterDialog*) lparam;
1688 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1689 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES), (dlg->flags&TF_DIRECTORIES? BST_CHECKED: BST_UNCHECKED));
1690 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS), dlg->flags&TF_PROGRAMS? BST_CHECKED: BST_UNCHECKED);
1691 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS), dlg->flags&TF_DOCUMENTS? BST_CHECKED: BST_UNCHECKED);
1692 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS), dlg->flags&TF_OTHERS? BST_CHECKED: BST_UNCHECKED);
1693 Button_SetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN), dlg->flags&TF_HIDDEN? BST_CHECKED: BST_UNCHECKED);
1694 return 1;
1696 case WM_COMMAND: {
1697 int id = (int)wparam;
1699 if (id == IDOK) {
1700 int flags = 0;
1702 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1704 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DIRECTORIES))&BST_CHECKED? TF_DIRECTORIES: 0;
1705 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_PROGRAMS))&BST_CHECKED? TF_PROGRAMS: 0;
1706 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_DOCUMENTS))&BST_CHECKED? TF_DOCUMENTS: 0;
1707 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_OTHERS))&BST_CHECKED? TF_OTHERS: 0;
1708 flags |= Button_GetCheck(GetDlgItem(hwnd,IDC_VIEW_TYPE_HIDDEN))&BST_CHECKED? TF_HIDDEN: 0;
1710 dlg->flags = flags;
1712 EndDialog(hwnd, id);
1713 } else if (id == IDCANCEL)
1714 EndDialog(hwnd, id);
1716 return 1;}
1719 return 0;
1723 #ifndef _NO_EXTENSIONS
1725 static struct FullScreenParameters {
1726 BOOL mode;
1727 RECT orgPos;
1728 BOOL wasZoomed;
1729 } g_fullscreen = {
1730 FALSE, /* mode */
1731 {0, 0, 0, 0},
1732 FALSE
1735 void frame_get_clientspace(HWND hwnd, PRECT prect)
1737 RECT rt;
1739 if (!IsIconic(hwnd))
1740 GetClientRect(hwnd, prect);
1741 else {
1742 WINDOWPLACEMENT wp;
1744 GetWindowPlacement(hwnd, &wp);
1746 prect->left = prect->top = 0;
1747 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1748 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1749 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1750 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1751 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1754 if (IsWindowVisible(Globals.htoolbar)) {
1755 GetClientRect(Globals.htoolbar, &rt);
1756 prect->top += rt.bottom+2;
1759 if (IsWindowVisible(Globals.hdrivebar)) {
1760 GetClientRect(Globals.hdrivebar, &rt);
1761 prect->top += rt.bottom+2;
1764 if (IsWindowVisible(Globals.hstatusbar)) {
1765 GetClientRect(Globals.hstatusbar, &rt);
1766 prect->bottom -= rt.bottom;
1770 static BOOL toggle_fullscreen(HWND hwnd)
1772 RECT rt;
1774 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1775 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1776 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1778 Frame_CalcFrameClient(hwnd, &rt);
1779 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1780 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1782 rt.left = g_fullscreen.orgPos.left-rt.left;
1783 rt.top = g_fullscreen.orgPos.top-rt.top;
1784 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1785 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1787 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1788 } else {
1789 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1790 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1791 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1793 if (g_fullscreen.wasZoomed)
1794 ShowWindow(hwnd, WS_MAXIMIZE);
1797 return g_fullscreen.mode;
1800 static void fullscreen_move(HWND hwnd)
1802 RECT rt, pos;
1803 GetWindowRect(hwnd, &pos);
1805 Frame_CalcFrameClient(hwnd, &rt);
1806 ClientToScreen(hwnd, (LPPOINT)&rt.left);
1807 ClientToScreen(hwnd, (LPPOINT)&rt.right);
1809 rt.left = pos.left-rt.left;
1810 rt.top = pos.top-rt.top;
1811 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1812 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1814 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1817 #endif
1820 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1822 BOOL vis = IsWindowVisible(hchild);
1824 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1826 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1828 #ifndef _NO_EXTENSIONS
1829 if (g_fullscreen.mode)
1830 fullscreen_move(hwnd);
1831 #endif
1833 resize_frame_client(hwnd);
1836 BOOL activate_drive_window(LPCTSTR path)
1838 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1839 HWND child_wnd;
1841 _tsplitpath(path, drv1, 0, 0, 0);
1843 /* search for a already open window for the same drive */
1844 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1845 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1847 if (child) {
1848 _tsplitpath(child->root.path, drv2, 0, 0, 0);
1850 if (!lstrcmpi(drv2, drv1)) {
1851 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1853 if (IsMinimized(child_wnd))
1854 ShowWindow(child_wnd, SW_SHOWNORMAL);
1856 return TRUE;
1861 return FALSE;
1864 BOOL activate_fs_window(LPCTSTR filesys)
1866 HWND child_wnd;
1868 /* search for a already open window of the given file system name */
1869 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1870 ChildWnd* child = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
1872 if (child) {
1873 if (!lstrcmpi(child->root.fs, filesys)) {
1874 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1876 if (IsMinimized(child_wnd))
1877 ShowWindow(child_wnd, SW_SHOWNORMAL);
1879 return TRUE;
1884 return FALSE;
1887 LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1889 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1891 switch(nmsg) {
1892 case WM_CLOSE:
1893 DestroyWindow(hwnd);
1895 /* clear handle variables */
1896 Globals.hMenuFrame = 0;
1897 Globals.hMenuView = 0;
1898 Globals.hMenuOptions = 0;
1899 Globals.hMainWnd = 0;
1900 Globals.hmdiclient = 0;
1901 Globals.hdrivebar = 0;
1902 break;
1904 case WM_DESTROY:
1905 /* don't exit desktop when closing file manager window */
1906 if (!Globals.hwndParent)
1907 PostQuitMessage(0);
1908 break;
1910 case WM_INITMENUPOPUP: {
1911 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1913 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
1914 return 0;
1915 break;}
1917 case WM_COMMAND: {
1918 UINT cmd = LOWORD(wparam);
1919 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1921 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1922 break;
1924 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1925 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1926 ChildWnd* child;
1927 LPCTSTR root = Globals.drives;
1928 int i;
1930 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1931 while(*root)
1932 root++;
1934 if (activate_drive_window(root))
1935 return 0;
1937 _tsplitpath(root, drv, 0, 0, 0);
1939 if (!SetCurrentDirectory(drv)) {
1940 display_error(hwnd, GetLastError());
1941 return 0;
1944 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
1945 child = alloc_child_window(path, NULL, hwnd);
1947 if (!create_child_window(child))
1948 free(child);
1949 } else switch(cmd) {
1950 case ID_FILE_EXIT:
1951 SendMessage(hwnd, WM_CLOSE, 0, 0);
1952 break;
1954 case ID_WINDOW_NEW: {
1955 TCHAR path[MAX_PATH];
1956 ChildWnd* child;
1958 GetCurrentDirectory(MAX_PATH, path);
1959 child = alloc_child_window(path, NULL, hwnd);
1961 if (!create_child_window(child))
1962 free(child);
1963 break;}
1965 case ID_REFRESH:
1966 refresh_drives();
1967 break;
1969 case ID_WINDOW_CASCADE:
1970 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1971 break;
1973 case ID_WINDOW_TILE_HORZ:
1974 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1975 break;
1977 case ID_WINDOW_TILE_VERT:
1978 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1979 break;
1981 case ID_WINDOW_ARRANGE:
1982 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1983 break;
1985 case ID_SELECT_FONT: {
1986 TCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
1987 CHOOSEFONT chFont;
1988 LOGFONT lFont;
1990 HDC hdc = GetDC(hwnd);
1991 chFont.lStructSize = sizeof(CHOOSEFONT);
1992 chFont.hwndOwner = hwnd;
1993 chFont.hDC = NULL;
1994 chFont.lpLogFont = &lFont;
1995 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
1996 chFont.rgbColors = RGB(0,0,0);
1997 chFont.lCustData = 0;
1998 chFont.lpfnHook = NULL;
1999 chFont.lpTemplateName = NULL;
2000 chFont.hInstance = Globals.hInstance;
2001 chFont.lpszStyle = NULL;
2002 chFont.nFontType = SIMULATED_FONTTYPE;
2003 chFont.nSizeMin = 0;
2004 chFont.nSizeMax = 24;
2006 if (ChooseFont(&chFont)) {
2007 HWND childWnd;
2009 Globals.hfont = CreateFontIndirect(&lFont);
2010 SelectFont(hdc, Globals.hfont);
2011 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2013 /* change font in all open child windows */
2014 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
2015 ChildWnd* child = (ChildWnd*) GetWindowLong(childWnd, GWL_USERDATA);
2016 SetWindowFont(child->left.hwnd, Globals.hfont, TRUE);
2017 SetWindowFont(child->right.hwnd, Globals.hfont, TRUE);
2018 ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2019 ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
2020 InvalidateRect(child->left.hwnd, NULL, TRUE);
2021 InvalidateRect(child->right.hwnd, NULL, TRUE);
2024 else if (CommDlgExtendedError()) {
2025 LoadString(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
2026 LoadString(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
2027 MessageBox(hwnd, dlg_info, dlg_name, MB_OK);
2030 ReleaseDC(hwnd, hdc);
2031 break;
2034 case ID_VIEW_TOOL_BAR:
2035 toggle_child(hwnd, cmd, Globals.htoolbar);
2036 break;
2038 case ID_VIEW_DRIVE_BAR:
2039 toggle_child(hwnd, cmd, Globals.hdrivebar);
2040 break;
2042 case ID_VIEW_STATUSBAR:
2043 toggle_child(hwnd, cmd, Globals.hstatusbar);
2044 break;
2046 case ID_EXECUTE: {
2047 struct ExecuteDialog dlg;
2049 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2051 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogWndProg, (LPARAM)&dlg) == IDOK) {
2052 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2054 if ((int)hinst <= 32)
2055 display_error(hwnd, GetLastError());
2057 break;}
2059 case ID_CONNECT_NETWORK_DRIVE: {
2060 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2061 if (ret == NO_ERROR)
2062 refresh_drives();
2063 else if (ret != (DWORD)-1) {
2064 if (ret == ERROR_EXTENDED_ERROR)
2065 display_network_error(hwnd);
2066 else
2067 display_error(hwnd, ret);
2069 break;}
2071 case ID_DISCONNECT_NETWORK_DRIVE: {
2072 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2073 if (ret == NO_ERROR)
2074 refresh_drives();
2075 else if (ret != (DWORD)-1) {
2076 if (ret == ERROR_EXTENDED_ERROR)
2077 display_network_error(hwnd);
2078 else
2079 display_error(hwnd, ret);
2081 break;}
2083 case ID_FORMAT_DISK: {
2084 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2085 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2086 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2087 SetErrorMode(sem_org); /* Put it back the way it was. */
2088 break;}
2090 case ID_HELP:
2091 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2092 break;
2094 #ifndef _NO_EXTENSIONS
2095 case ID_VIEW_FULLSCREEN:
2096 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2097 break;
2099 #ifdef __WINE__
2100 case ID_DRIVE_UNIX_FS: {
2101 TCHAR path[MAX_PATH];
2102 ChildWnd* child;
2104 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2105 break;
2107 getcwd(path, MAX_PATH);
2108 child = alloc_child_window(path, NULL, hwnd);
2110 if (!create_child_window(child))
2111 free(child);
2112 break;}
2113 #endif
2114 #ifdef _SHELL_FOLDERS
2115 case ID_DRIVE_SHELL_NS: {
2116 TCHAR path[MAX_PATH];
2117 ChildWnd* child;
2119 if (activate_fs_window(RS(b1,IDS_SHELL)))
2120 break;
2122 GetCurrentDirectory(MAX_PATH, path);
2123 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2125 if (!create_child_window(child))
2126 free(child);
2127 break;}
2128 #endif
2129 #endif
2131 /*TODO: There are even more menu items! */
2133 #ifndef _NO_EXTENSIONS
2134 #ifdef __WINE__
2135 case ID_LICENSE:
2136 WineLicense(Globals.hMainWnd);
2137 break;
2139 case ID_NO_WARRANTY:
2140 WineWarranty(Globals.hMainWnd);
2141 break;
2142 #endif
2144 case ID_ABOUT_WINE:
2145 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2146 break;
2148 case ID_ABOUT: /*ID_ABOUT_WINE: */
2149 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2150 break;
2151 #endif /* _NO_EXTENSIONS */
2153 default:
2154 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2155 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2156 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2157 (cmd<SC_SIZE || cmd>SC_RESTORE))
2158 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2160 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2162 break;}
2164 case WM_SIZE:
2165 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2166 break; /* do not pass message to DefFrameProc */
2168 #ifndef _NO_EXTENSIONS
2169 case WM_GETMINMAXINFO: {
2170 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2172 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2173 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2174 break;}
2176 case FRM_CALC_CLIENT:
2177 frame_get_clientspace(hwnd, (PRECT)lparam);
2178 return TRUE;
2179 #endif /* _NO_EXTENSIONS */
2181 default:
2182 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2185 return 0;
2189 static TCHAR g_pos_names[COLUMNS][20] = {
2190 {'\0'} /* symbol */
2193 static const int g_pos_align[] = {
2195 HDF_LEFT, /* Name */
2196 HDF_RIGHT, /* Size */
2197 HDF_LEFT, /* CDate */
2198 #ifndef _NO_EXTENSIONS
2199 HDF_LEFT, /* ADate */
2200 HDF_LEFT, /* MDate */
2201 HDF_LEFT, /* Index */
2202 HDF_CENTER, /* Links */
2203 #endif
2204 HDF_CENTER, /* Attributes */
2205 #ifndef _NO_EXTENSIONS
2206 HDF_LEFT /* Security */
2207 #endif
2210 static void resize_tree(ChildWnd* child, int cx, int cy)
2212 HDWP hdwp = BeginDeferWindowPos(4);
2213 RECT rt;
2215 rt.left = 0;
2216 rt.top = 0;
2217 rt.right = cx;
2218 rt.bottom = cy;
2220 cx = child->split_pos + SPLIT_WIDTH/2;
2222 #ifndef _NO_EXTENSIONS
2224 WINDOWPOS wp;
2225 HD_LAYOUT hdl;
2227 hdl.prc = &rt;
2228 hdl.pwpos = &wp;
2230 Header_Layout(child->left.hwndHeader, &hdl);
2232 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2233 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2234 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2235 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2237 #endif /* _NO_EXTENSIONS */
2239 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);
2240 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2242 EndDeferWindowPos(hdwp);
2246 #ifndef _NO_EXTENSIONS
2248 static HWND create_header(HWND parent, Pane* pane, int id)
2250 HD_ITEM hdi;
2251 int idx;
2253 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*TODO: |HDS_BUTTONS + sort orders*/,
2254 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2255 if (!hwnd)
2256 return 0;
2258 SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2260 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2262 for(idx=0; idx<COLUMNS; idx++) {
2263 hdi.pszText = g_pos_names[idx];
2264 hdi.fmt = HDF_STRING | g_pos_align[idx];
2265 hdi.cxy = pane->widths[idx];
2266 Header_InsertItem(hwnd, idx, &hdi);
2269 return hwnd;
2272 #endif /* _NO_EXTENSIONS */
2275 static void init_output(HWND hwnd)
2277 const static TCHAR s1000[] = {'1','0','0','0','\0'};
2279 TCHAR b[16];
2280 HFONT old_font;
2281 HDC hdc = GetDC(hwnd);
2283 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2284 Globals.num_sep = b[1];
2285 else
2286 Globals.num_sep = TEXT('.');
2288 old_font = SelectFont(hdc, Globals.hfont);
2289 GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize);
2290 SelectFont(hdc, old_font);
2291 ReleaseDC(hwnd, hdc);
2294 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2297 /* calculate preferred width for all visible columns */
2299 static BOOL calc_widths(Pane* pane, BOOL anyway)
2301 int col, x, cx, spc=3*Globals.spaceSize.cx;
2302 int entries = ListBox_GetCount(pane->hwnd);
2303 int orgWidths[COLUMNS];
2304 int orgPositions[COLUMNS+1];
2305 HFONT hfontOld;
2306 HDC hdc;
2307 int cnt;
2309 if (!anyway) {
2310 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2311 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2314 for(col=0; col<COLUMNS; col++)
2315 pane->widths[col] = 0;
2317 hdc = GetDC(pane->hwnd);
2318 hfontOld = SelectFont(hdc, Globals.hfont);
2320 for(cnt=0; cnt<entries; cnt++) {
2321 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2323 DRAWITEMSTRUCT dis;
2325 dis.CtlType = 0;
2326 dis.CtlID = 0;
2327 dis.itemID = 0;
2328 dis.itemAction = 0;
2329 dis.itemState = 0;
2330 dis.hwndItem = pane->hwnd;
2331 dis.hDC = hdc;
2332 dis.rcItem.left = 0;
2333 dis.rcItem.top = 0;
2334 dis.rcItem.right = 0;
2335 dis.rcItem.bottom = 0;
2336 /*dis.itemData = 0; */
2338 draw_item(pane, &dis, entry, COLUMNS);
2341 SelectObject(hdc, hfontOld);
2342 ReleaseDC(pane->hwnd, hdc);
2344 x = 0;
2345 for(col=0; col<COLUMNS; col++) {
2346 pane->positions[col] = x;
2347 cx = pane->widths[col];
2349 if (cx) {
2350 cx += spc;
2352 if (cx < IMAGE_WIDTH)
2353 cx = IMAGE_WIDTH;
2355 pane->widths[col] = cx;
2358 x += cx;
2361 pane->positions[COLUMNS] = x;
2363 ListBox_SetHorizontalExtent(pane->hwnd, x);
2365 /* no change? */
2366 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2367 return FALSE;
2369 /* don't move, if only collapsing an entry */
2370 if (!anyway && pane->widths[0]<orgWidths[0] &&
2371 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2372 pane->widths[0] = orgWidths[0];
2373 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2375 return FALSE;
2378 InvalidateRect(pane->hwnd, 0, TRUE);
2380 return TRUE;
2384 /* calculate one preferred column width */
2386 static void calc_single_width(Pane* pane, int col)
2388 HFONT hfontOld;
2389 int x, cx;
2390 int entries = ListBox_GetCount(pane->hwnd);
2391 int cnt;
2392 HDC hdc;
2394 pane->widths[col] = 0;
2396 hdc = GetDC(pane->hwnd);
2397 hfontOld = SelectFont(hdc, Globals.hfont);
2399 for(cnt=0; cnt<entries; cnt++) {
2400 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, cnt);
2401 DRAWITEMSTRUCT dis;
2403 dis.CtlType = 0;
2404 dis.CtlID = 0;
2405 dis.itemID = 0;
2406 dis.itemAction = 0;
2407 dis.itemState = 0;
2408 dis.hwndItem = pane->hwnd;
2409 dis.hDC = hdc;
2410 dis.rcItem.left = 0;
2411 dis.rcItem.top = 0;
2412 dis.rcItem.right = 0;
2413 dis.rcItem.bottom = 0;
2414 /*dis.itemData = 0; */
2416 draw_item(pane, &dis, entry, col);
2419 SelectObject(hdc, hfontOld);
2420 ReleaseDC(pane->hwnd, hdc);
2422 cx = pane->widths[col];
2424 if (cx) {
2425 cx += 3*Globals.spaceSize.cx;
2427 if (cx < IMAGE_WIDTH)
2428 cx = IMAGE_WIDTH;
2431 pane->widths[col] = cx;
2433 x = pane->positions[col] + cx;
2435 for(; col<COLUMNS; ) {
2436 pane->positions[++col] = x;
2437 x += pane->widths[col];
2440 ListBox_SetHorizontalExtent(pane->hwnd, x);
2444 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2446 for( ; *str&&*pattern; str++,pattern++) {
2447 if (*pattern == '*') {
2448 do pattern++;
2449 while(*pattern == '*');
2451 if (!*pattern)
2452 return TRUE;
2454 for(; *str; str++)
2455 if (_totupper(*str)==_totupper(*pattern) && pattern_match(str, pattern))
2456 return TRUE;
2458 return FALSE;
2460 else if (_totupper(*str)!=_totupper(*pattern) && *pattern!='?')
2461 return FALSE;
2464 if (*str || *pattern)
2465 if (*pattern!='*' || pattern[1]!='\0')
2466 return FALSE;
2468 return TRUE;
2472 enum FILE_TYPE {
2473 FT_OTHER = 0,
2474 FT_EXECUTABLE = 1,
2475 FT_DOCUMENT = 2
2478 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2481 /* insert listbox entries after index idx */
2483 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2485 Entry* entry = dir;
2487 if (!entry)
2488 return idx;
2490 ShowWindow(pane->hwnd, SW_HIDE);
2492 for(; entry; entry=entry->next) {
2493 #ifndef _LEFT_FILES
2494 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2495 continue;
2496 #endif
2498 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2499 /* don't display entries "." and ".." in the left pane */
2500 if (pane->treePane && entry->data.cFileName[0]==TEXT('.'))
2501 if (
2502 #ifndef _NO_EXTENSIONS
2503 entry->data.cFileName[1]==TEXT('\0') ||
2504 #endif
2505 (entry->data.cFileName[1]==TEXT('.') && entry->data.cFileName[2]==TEXT('\0')))
2506 continue;
2508 /* filter directories in right pane */
2509 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2510 continue;
2513 /* filter using the file name pattern */
2514 if (pattern)
2515 if (!pattern_match(entry->data.cFileName, pattern))
2516 continue;
2518 /* filter system and hidden files */
2519 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2520 continue;
2522 /* filter looking at the file type */
2523 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2524 switch(get_file_type(entry->data.cFileName)) {
2525 case FT_EXECUTABLE:
2526 if (!(filter_flags & TF_PROGRAMS))
2527 continue;
2528 break;
2530 case FT_DOCUMENT:
2531 if (!(filter_flags & TF_DOCUMENTS))
2532 continue;
2533 break;
2535 default: /* TF_OTHERS */
2536 if (!(filter_flags & TF_OTHERS))
2537 continue;
2540 if (idx != -1)
2541 idx++;
2543 ListBox_InsertItemData(pane->hwnd, idx, entry);
2545 if (pane->treePane && entry->expanded)
2546 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2549 ShowWindow(pane->hwnd, SW_SHOW);
2551 return idx;
2555 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2557 const static TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2558 const static TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2559 const static TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2561 float fBytes = (float)bytes;
2563 if (bytes >= 1073741824) /* 1 GB */
2564 _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2565 else if (bytes >= 1048576) /* 1 MB */
2566 _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2567 else if (bytes >= 1024) /* 1 kB */
2568 _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2569 else
2570 _stprintf(buffer, sLongNumFmt, bytes);
2573 static void set_space_status()
2575 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2576 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2578 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2579 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2580 format_bytes(b2, ulTotalBytes.QuadPart);
2581 _stprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2582 } else
2583 _tcscpy(buffer, sQMarks);
2585 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2589 static WNDPROC g_orgTreeWndProc;
2591 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2593 const static TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2595 static int s_init = 0;
2596 Entry* entry = pane->root;
2598 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2599 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2600 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2602 SetWindowLong(pane->hwnd, GWL_USERDATA, (LPARAM)pane);
2603 g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc);
2605 SetWindowFont(pane->hwnd, Globals.hfont, FALSE);
2607 /* insert entries into listbox */
2608 if (entry)
2609 insert_entries(pane, entry, pattern, filter_flags, -1);
2611 /* calculate column widths */
2612 if (!s_init) {
2613 s_init = 1;
2614 init_output(pane->hwnd);
2617 calc_widths(pane, TRUE);
2619 #ifndef _NO_EXTENSIONS
2620 pane->hwndHeader = create_header(parent, pane, id_header);
2621 #endif
2625 static void InitChildWindow(ChildWnd* child)
2627 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2628 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2632 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2634 SYSTEMTIME systime;
2635 FILETIME lft;
2636 int len = 0;
2638 *buffer = TEXT('\0');
2640 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2641 return;
2643 if (!FileTimeToLocalFileTime(ft, &lft))
2644 {err: _tcscpy(buffer,sQMarks); return;}
2646 if (!FileTimeToSystemTime(&lft, &systime))
2647 goto err;
2649 if (visible_cols & COL_DATE) {
2650 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2651 if (!len)
2652 goto err;
2655 if (visible_cols & COL_TIME) {
2656 if (len)
2657 buffer[len-1] = ' ';
2659 buffer[len++] = ' ';
2661 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2662 buffer[len] = TEXT('\0');
2667 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2669 RECT rt = {0, 0, 0, 0};
2671 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2673 if (rt.right > pane->widths[col])
2674 pane->widths[col] = rt.right;
2677 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2679 RECT rt = {0, 0, 0, 0};
2681 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2682 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2684 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2685 /*FIXME rt (0,0) ??? */
2687 if (rt.right > pane->widths[col])
2688 pane->widths[col] = rt.right;
2692 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
2694 int x = dis->rcItem.left;
2695 RECT rt;
2697 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2698 rt.top = dis->rcItem.top;
2699 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2700 rt.bottom = dis->rcItem.bottom;
2702 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2705 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2707 int x = dis->rcItem.left;
2708 RECT rt;
2710 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2711 rt.top = dis->rcItem.top;
2712 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2713 rt.bottom = dis->rcItem.bottom;
2715 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2716 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2718 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2721 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2723 int x = dis->rcItem.left;
2724 RECT rt;
2725 LPCTSTR s = str;
2726 TCHAR b[128];
2727 LPTSTR d = b;
2728 int pos;
2730 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2731 rt.top = dis->rcItem.top;
2732 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2733 rt.bottom = dis->rcItem.bottom;
2735 if (*s)
2736 *d++ = *s++;
2738 /* insert number separator characters */
2739 pos = lstrlen(s) % 3;
2741 while(*s)
2742 if (pos--)
2743 *d++ = *s++;
2744 else {
2745 *d++ = Globals.num_sep;
2746 pos = 3;
2749 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2753 static BOOL is_exe_file(LPCTSTR ext)
2755 static const TCHAR executable_extensions[][4] = {
2756 {'C','O','M','\0'},
2757 {'E','X','E','\0'},
2758 {'B','A','T','\0'},
2759 {'C','M','D','\0'},
2760 #ifndef _NO_EXTENSIONS
2761 {'C','M','M','\0'},
2762 {'B','T','M','\0'},
2763 {'A','W','K','\0'},
2764 #endif /* _NO_EXTENSIONS */
2765 {'\0'}
2768 TCHAR ext_buffer[_MAX_EXT];
2769 const TCHAR (*p)[4];
2770 LPCTSTR s;
2771 LPTSTR d;
2773 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2774 d++;
2776 for(p=executable_extensions; (*p)[0]; p++)
2777 if (!_tcsicmp(ext_buffer, *p))
2778 return TRUE;
2780 return FALSE;
2783 static BOOL is_registered_type(LPCTSTR ext)
2785 /* check if there exists a classname for this file extension in the registry */
2786 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2787 return TRUE;
2789 return FALSE;
2792 static enum FILE_TYPE get_file_type(LPCTSTR filename)
2794 LPCTSTR ext = _tcsrchr(filename, '.');
2795 if (!ext)
2796 ext = sEmpty;
2798 if (is_exe_file(ext))
2799 return FT_EXECUTABLE;
2800 else if (is_registered_type(ext))
2801 return FT_DOCUMENT;
2802 else
2803 return FT_OTHER;
2807 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2809 TCHAR buffer[BUFFER_LEN];
2810 DWORD attrs;
2811 int visible_cols = pane->visible_cols;
2812 COLORREF bkcolor, textcolor;
2813 RECT focusRect = dis->rcItem;
2814 HBRUSH hbrush;
2815 enum IMAGE img;
2816 int img_pos, cx;
2817 int col = 0;
2819 if (entry) {
2820 attrs = entry->data.dwFileAttributes;
2822 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2823 if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('.')
2824 && entry->data.cFileName[2]==TEXT('\0'))
2825 img = IMG_FOLDER_UP;
2826 #ifndef _NO_EXTENSIONS
2827 else if (entry->data.cFileName[0]==TEXT('.') && entry->data.cFileName[1]==TEXT('\0'))
2828 img = IMG_FOLDER_CUR;
2829 #endif
2830 else if (
2831 #ifdef _NO_EXTENSIONS
2832 entry->expanded ||
2833 #endif
2834 (pane->treePane && (dis->itemState&ODS_FOCUS)))
2835 img = IMG_OPEN_FOLDER;
2836 else
2837 img = IMG_FOLDER;
2838 } else {
2839 switch(get_file_type(entry->data.cFileName)) {
2840 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
2841 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
2842 default: img = IMG_FILE;
2845 } else {
2846 attrs = 0;
2847 img = IMG_NONE;
2850 if (pane->treePane) {
2851 if (entry) {
2852 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
2854 if (calcWidthCol == -1) {
2855 int x;
2856 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2857 Entry* up;
2858 RECT rt_clip;
2859 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2860 HRGN hrgn;
2862 rt_clip.left = dis->rcItem.left;
2863 rt_clip.top = dis->rcItem.top;
2864 rt_clip.right = dis->rcItem.left+pane->widths[col];
2865 rt_clip.bottom = dis->rcItem.bottom;
2867 hrgn = CreateRectRgnIndirect(&rt_clip);
2869 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2870 DeleteObject(hrgn_org);
2871 hrgn_org = 0;
2874 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
2875 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2876 DeleteObject(hrgn);
2878 if ((up=entry->up) != NULL) {
2879 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2880 LineTo(dis->hDC, img_pos-2, y);
2882 x = img_pos - IMAGE_WIDTH/2;
2884 do {
2885 x -= IMAGE_WIDTH+TREE_LINE_DX;
2887 if (up->next
2888 #ifndef _LEFT_FILES
2889 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2890 #endif
2892 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2893 LineTo(dis->hDC, x, dis->rcItem.bottom);
2895 } while((up=up->up) != NULL);
2898 x = img_pos - IMAGE_WIDTH/2;
2900 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2901 LineTo(dis->hDC, x, y);
2903 if (entry->next
2904 #ifndef _LEFT_FILES
2905 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
2906 #endif
2908 LineTo(dis->hDC, x, dis->rcItem.bottom);
2910 if (entry->down && entry->expanded) {
2911 x += IMAGE_WIDTH+TREE_LINE_DX;
2912 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT+2, 0);
2913 LineTo(dis->hDC, x, dis->rcItem.bottom);
2916 SelectClipRgn(dis->hDC, hrgn_org);
2917 if (hrgn_org) DeleteObject(hrgn_org);
2918 /* SelectObject(dis->hDC, holdPen); */
2919 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2920 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
2922 if (right > pane->widths[col])
2923 pane->widths[col] = right;
2925 } else {
2926 img_pos = dis->rcItem.left;
2928 } else {
2929 img_pos = dis->rcItem.left;
2931 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2932 pane->widths[col] = IMAGE_WIDTH;
2935 if (calcWidthCol == -1) {
2936 focusRect.left = img_pos -2;
2938 #ifdef _NO_EXTENSIONS
2939 if (pane->treePane && entry) {
2940 RECT rt = {0};
2942 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2944 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
2946 #else
2948 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2949 textcolor = COLOR_COMPRESSED;
2950 else
2951 #endif /* _NO_EXTENSIONS */
2952 textcolor = RGB(0,0,0);
2954 if (dis->itemState & ODS_FOCUS) {
2955 textcolor = RGB(255,255,255);
2956 bkcolor = COLOR_SELECTION;
2957 } else {
2958 bkcolor = RGB(255,255,255);
2961 hbrush = CreateSolidBrush(bkcolor);
2962 FillRect(dis->hDC, &focusRect, hbrush);
2963 DeleteObject(hbrush);
2965 SetBkMode(dis->hDC, TRANSPARENT);
2966 SetTextColor(dis->hDC, textcolor);
2968 cx = pane->widths[col];
2970 if (cx && img!=IMG_NONE) {
2972 if (cx > IMAGE_WIDTH)
2973 cx = IMAGE_WIDTH;
2975 #ifdef _SHELL_FOLDERS
2976 if (entry->hicon && entry->hicon!=(HICON)-1)
2977 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2978 else
2979 #endif
2980 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2981 img_pos, dis->rcItem.top, cx,
2982 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2986 if (!entry)
2987 return;
2989 #ifdef _NO_EXTENSIONS
2990 if (img >= IMG_FOLDER_UP)
2991 return;
2992 #endif
2994 col++;
2996 /* ouput file name */
2997 if (calcWidthCol == -1)
2998 output_text(pane, dis, col, entry->data.cFileName, 0);
2999 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3000 calc_width(pane, dis, col, entry->data.cFileName);
3002 col++;
3004 #ifdef _NO_EXTENSIONS
3005 if (!pane->treePane) {
3006 #endif
3008 /* display file size */
3009 if (visible_cols & COL_SIZE) {
3010 #ifdef _NO_EXTENSIONS
3011 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3012 #endif
3014 ULONGLONG size;
3016 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3018 _stprintf(buffer, sLongNumFmt, size);
3020 if (calcWidthCol == -1)
3021 output_number(pane, dis, col, buffer);
3022 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3023 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3026 col++;
3029 /* display file date */
3030 if (visible_cols & (COL_DATE|COL_TIME)) {
3031 #ifndef _NO_EXTENSIONS
3032 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3033 if (calcWidthCol == -1)
3034 output_text(pane, dis, col, buffer, 0);
3035 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3036 calc_width(pane, dis, col, buffer);
3037 col++;
3039 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3040 if (calcWidthCol == -1)
3041 output_text(pane, dis, col, buffer, 0);
3042 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3043 calc_width(pane, dis, col, buffer);
3044 col++;
3045 #endif /* _NO_EXTENSIONS */
3047 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3048 if (calcWidthCol == -1)
3049 output_text(pane, dis, col, buffer, 0);
3050 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3051 calc_width(pane, dis, col, buffer);
3052 col++;
3055 #ifndef _NO_EXTENSIONS
3056 if (entry->bhfi_valid) {
3057 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3059 if (visible_cols & COL_INDEX) {
3060 _stprintf(buffer, sLongHexFmt, index);
3062 if (calcWidthCol == -1)
3063 output_text(pane, dis, col, buffer, DT_RIGHT);
3064 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3065 calc_width(pane, dis, col, buffer);
3067 col++;
3070 if (visible_cols & COL_LINKS) {
3071 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3073 if (calcWidthCol == -1)
3074 output_text(pane, dis, col, buffer, DT_CENTER);
3075 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3076 calc_width(pane, dis, col, buffer);
3078 col++;
3080 } else
3081 col += 2;
3082 #endif /* _NO_EXTENSIONS */
3084 /* show file attributes */
3085 if (visible_cols & COL_ATTRIBUTES) {
3086 #ifdef _NO_EXTENSIONS
3087 const static TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3088 _tcscpy(buffer, s4Tabs);
3089 #else
3090 const static TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3091 _tcscpy(buffer, s11Tabs);
3092 #endif
3094 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3095 else {
3096 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3097 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3098 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3099 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3100 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3101 #ifndef _NO_EXTENSIONS
3102 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3103 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3104 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3105 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3106 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3107 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3108 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3109 #endif /* _NO_EXTENSIONS */
3112 if (calcWidthCol == -1)
3113 output_tabbed_text(pane, dis, col, buffer);
3114 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3115 calc_tabbed_width(pane, dis, col, buffer);
3117 col++;
3120 /*TODO
3121 if (flags.security) {
3122 const static TCHAR sSecTabs[] = {
3123 ' ','\t',' ','\t',' ','\t',' ',
3124 ' ','\t',' ',
3125 ' ','\t',' ','\t',' ','\t',' ',
3126 ' ','\t',' ',
3127 ' ','\t',' ','\t',' ','\t',' ',
3128 '\0'
3131 DWORD rights = get_access_mask();
3133 tcscpy(buffer, sSecTabs);
3135 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3136 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3137 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3138 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3139 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3140 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3141 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3142 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3143 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3144 if (rights & WRITE_DAC) buffer[22] = 'C';
3145 if (rights & WRITE_OWNER) buffer[24] = 'O';
3146 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3148 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3151 if (flags.description) {
3152 get_description(buffer);
3153 output_text(dis, col++, buffer, 0, psize);
3157 #ifdef _NO_EXTENSIONS
3160 /* draw focus frame */
3161 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3162 /* Currently [04/2000] Wine neither behaves exactly the same */
3163 /* way as WIN 95 nor like Windows NT... */
3164 HGDIOBJ lastBrush;
3165 HPEN lastPen;
3166 HPEN hpen;
3168 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3169 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3170 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3171 } else
3172 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3174 lastPen = SelectPen(dis->hDC, hpen);
3175 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3176 SetROP2(dis->hDC, R2_XORPEN);
3177 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3178 SelectObject(dis->hDC, lastBrush);
3179 SelectObject(dis->hDC, lastPen);
3180 DeleteObject(hpen);
3182 #endif /* _NO_EXTENSIONS */
3186 #ifdef _NO_EXTENSIONS
3188 static void draw_splitbar(HWND hwnd, int x)
3190 RECT rt;
3191 HDC hdc = GetDC(hwnd);
3193 GetClientRect(hwnd, &rt);
3195 rt.left = x - SPLIT_WIDTH/2;
3196 rt.right = x + SPLIT_WIDTH/2+1;
3198 InvertRect(hdc, &rt);
3200 ReleaseDC(hwnd, hdc);
3203 #endif /* _NO_EXTENSIONS */
3206 #ifndef _NO_EXTENSIONS
3208 static void set_header(Pane* pane)
3210 HD_ITEM item;
3211 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3212 int i=0, x=0;
3214 item.mask = HDI_WIDTH;
3215 item.cxy = 0;
3217 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3218 x += pane->widths[i];
3219 Header_SetItem(pane->hwndHeader, i, &item);
3222 if (i < COLUMNS) {
3223 x += pane->widths[i];
3224 item.cxy = x - scroll_pos;
3225 Header_SetItem(pane->hwndHeader, i++, &item);
3227 for(; i<COLUMNS; i++) {
3228 item.cxy = pane->widths[i];
3229 x += pane->widths[i];
3230 Header_SetItem(pane->hwndHeader, i, &item);
3235 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3237 switch(pnmh->code) {
3238 case HDN_TRACK:
3239 case HDN_ENDTRACK: {
3240 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3241 int idx = phdn->iItem;
3242 int dx = phdn->pitem->cxy - pane->widths[idx];
3243 int i;
3245 RECT clnt;
3246 GetClientRect(pane->hwnd, &clnt);
3248 /* move immediate to simulate HDS_FULLDRAG (for now [04/2000] not really needed with WINELIB) */
3249 Header_SetItem(pane->hwndHeader, idx, phdn->pitem);
3251 pane->widths[idx] += dx;
3253 for(i=idx; ++i<=COLUMNS; )
3254 pane->positions[i] += dx;
3257 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3258 RECT rt_scr;
3259 RECT rt_clip;
3261 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3262 rt_scr.top = 0;
3263 rt_scr.right = clnt.right;
3264 rt_scr.bottom = clnt.bottom;
3266 rt_clip.left = pane->positions[idx]-scroll_pos;
3267 rt_clip.top = 0;
3268 rt_clip.right = clnt.right;
3269 rt_clip.bottom = clnt.bottom;
3271 if (rt_scr.left < 0) rt_scr.left = 0;
3272 if (rt_clip.left < 0) rt_clip.left = 0;
3274 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3276 rt_clip.right = pane->positions[idx+1];
3277 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3279 if (pnmh->code == HDN_ENDTRACK) {
3280 ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]);
3282 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3283 set_header(pane);
3287 return FALSE;
3290 case HDN_DIVIDERDBLCLICK: {
3291 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3292 HD_ITEM item;
3294 calc_single_width(pane, phdn->iItem);
3295 item.mask = HDI_WIDTH;
3296 item.cxy = pane->widths[phdn->iItem];
3298 Header_SetItem(pane->hwndHeader, phdn->iItem, &item);
3299 InvalidateRect(pane->hwnd, 0, TRUE);
3300 break;}
3303 return 0;
3306 #endif /* _NO_EXTENSIONS */
3309 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3311 TCHAR path[MAX_PATH];
3312 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3314 /* delete sub entries in left pane */
3315 for(;;) {
3316 LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1);
3317 Entry* sub = (Entry*) res;
3319 if (res==LB_ERR || !sub || sub->level<=entry->level)
3320 break;
3322 ListBox_DeleteString(child->left.hwnd, idx+1);
3325 /* empty right pane */
3326 ListBox_ResetContent(child->right.hwnd);
3328 /* release memory */
3329 free_entries(entry);
3331 /* read contents from disk */
3332 #ifdef _SHELL_FOLDERS
3333 if (entry->etype == ET_SHELL)
3335 read_directory(entry, NULL, child->sortOrder, hwnd);
3337 else
3338 #endif
3340 get_path(entry, path);
3341 read_directory(entry, path, child->sortOrder, hwnd);
3344 /* insert found entries in right pane */
3345 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3346 calc_widths(&child->right, FALSE);
3347 #ifndef _NO_EXTENSIONS
3348 set_header(&child->right);
3349 #endif
3351 child->header_wdths_ok = FALSE;
3353 SetCursor(old_cursor);
3357 /* expand a directory entry */
3359 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3361 int idx;
3362 Entry* p;
3364 if (!dir || dir->expanded || !dir->down)
3365 return FALSE;
3367 p = dir->down;
3369 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3370 p = p->next;
3372 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3373 p->data.cFileName[2]=='\0' && p->next)
3374 p = p->next;
3377 /* no subdirectories ? */
3378 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3379 return FALSE;
3381 idx = ListBox_FindItemData(child->left.hwnd, 0, dir);
3383 dir->expanded = TRUE;
3385 /* insert entries in left pane */
3386 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3388 if (!child->header_wdths_ok) {
3389 if (calc_widths(&child->left, FALSE)) {
3390 #ifndef _NO_EXTENSIONS
3391 set_header(&child->left);
3392 #endif
3394 child->header_wdths_ok = TRUE;
3398 return TRUE;
3402 static void collapse_entry(Pane* pane, Entry* dir)
3404 int idx = ListBox_FindItemData(pane->hwnd, 0, dir);
3406 ShowWindow(pane->hwnd, SW_HIDE);
3408 /* hide sub entries */
3409 for(;;) {
3410 LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1);
3411 Entry* sub = (Entry*) res;
3413 if (res==LB_ERR || !sub || sub->level<=dir->level)
3414 break;
3416 ListBox_DeleteString(pane->hwnd, idx+1);
3419 dir->expanded = FALSE;
3421 ShowWindow(pane->hwnd, SW_SHOW);
3425 static void refresh_right_pane(ChildWnd* child)
3427 ListBox_ResetContent(child->right.hwnd);
3428 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3429 calc_widths(&child->right, FALSE);
3431 #ifndef _NO_EXTENSIONS
3432 set_header(&child->right);
3433 #endif
3436 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3438 TCHAR path[MAX_PATH];
3440 path[0] = '\0';
3442 child->left.cur = entry;
3444 child->right.root = entry->down? entry->down: entry;
3445 child->right.cur = entry;
3447 if (!entry->scanned)
3448 scan_entry(child, entry, idx, hwnd);
3449 else
3450 refresh_right_pane(child);
3452 get_path(entry, path);
3453 lstrcpy(child->path, path);
3455 if (child->hwnd) /* only change window title, if the window already exists */
3456 SetWindowText(child->hwnd, path);
3458 if (path[0])
3459 if (SetCurrentDirectory(path))
3460 set_space_status();
3464 static void refresh_child(ChildWnd* child)
3466 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3467 Entry* entry;
3468 int idx;
3470 get_path(child->left.cur, path);
3471 _tsplitpath(path, drv, NULL, NULL, NULL);
3473 child->right.root = NULL;
3475 scan_entry(child, &child->root.entry, 0, child->hwnd);
3477 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3479 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3481 set_curdir(child, entry, 0, child->hwnd);
3483 idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur);
3484 ListBox_SetCurSel(child->left.hwnd, idx);
3488 static void create_drive_bar()
3490 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3491 #ifndef _NO_EXTENSIONS
3492 TCHAR b1[BUFFER_LEN];
3493 #endif
3494 int btn = 1;
3495 PTSTR p;
3497 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3499 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3500 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3501 1, 16, 13, 16, 13, sizeof(TBBUTTON));
3503 #ifndef _NO_EXTENSIONS
3504 #ifdef __WINE__
3505 /* insert unix file system button */
3506 b1[0] = '/';
3507 b1[1] = '\0';
3508 b1[2] = '\0';
3509 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3511 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3512 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3513 drivebarBtn.iString++;
3514 #endif
3515 #ifdef _SHELL_FOLDERS
3516 /* insert shell namespace button */
3517 load_string(b1, IDS_SHELL);
3518 b1[lstrlen(b1)+1] = '\0';
3519 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3521 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3522 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3523 drivebarBtn.iString++;
3524 #endif
3526 /* register windows drive root strings */
3527 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3528 #endif
3530 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3532 for(p=Globals.drives; *p; ) {
3533 #ifdef _NO_EXTENSIONS
3534 /* insert drive letter */
3535 TCHAR b[3] = {tolower(*p)};
3536 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3537 #endif
3538 switch(GetDriveType(p)) {
3539 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3540 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3541 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3542 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3543 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3546 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3547 drivebarBtn.idCommand++;
3548 drivebarBtn.iString++;
3550 while(*p++);
3554 static void refresh_drives()
3556 RECT rect;
3558 /* destroy drive bar */
3559 DestroyWindow(Globals.hdrivebar);
3560 Globals.hdrivebar = 0;
3562 /* re-create drive bar */
3563 create_drive_bar();
3565 /* update window layout */
3566 GetClientRect(Globals.hMainWnd, &rect);
3567 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3571 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3573 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3575 if ((int)hinst <= 32) {
3576 display_error(hwnd, GetLastError());
3577 return FALSE;
3580 return TRUE;
3583 #ifdef UNICODE
3584 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
3586 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3588 if ((int)hinst <= 32) {
3589 display_error(hwnd, GetLastError());
3590 return FALSE;
3593 return TRUE;
3595 #endif
3598 BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3600 TCHAR cmd[MAX_PATH];
3602 #ifdef _SHELL_FOLDERS
3603 if (entry->etype == ET_SHELL) {
3604 BOOL ret = TRUE;
3606 SHELLEXECUTEINFO shexinfo;
3608 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3609 shexinfo.fMask = SEE_MASK_IDLIST;
3610 shexinfo.hwnd = hwnd;
3611 shexinfo.lpVerb = NULL;
3612 shexinfo.lpFile = NULL;
3613 shexinfo.lpParameters = NULL;
3614 shexinfo.lpDirectory = NULL;
3615 shexinfo.nShow = nCmdShow;
3616 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3618 if (!ShellExecuteEx(&shexinfo)) {
3619 display_error(hwnd, GetLastError());
3620 ret = FALSE;
3623 if (shexinfo.lpIDList != entry->pidl)
3624 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, shexinfo.lpIDList);
3626 return ret;
3628 #endif
3630 get_path(entry, cmd);
3632 /* start program, open document... */
3633 return launch_file(hwnd, cmd, nCmdShow);
3637 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3639 Entry* entry = pane->cur;
3641 if (!entry)
3642 return;
3644 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3645 int scanned_old = entry->scanned;
3647 if (!scanned_old)
3648 scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd);
3650 #ifndef _NO_EXTENSIONS
3651 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3652 return;
3653 #endif
3655 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3656 entry = child->left.cur->up;
3657 collapse_entry(&child->left, entry);
3658 goto focus_entry;
3659 } else if (entry->expanded)
3660 collapse_entry(pane, child->left.cur);
3661 else {
3662 expand_entry(child, child->left.cur);
3664 if (!pane->treePane) focus_entry: {
3665 int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry);
3666 ListBox_SetCurSel(child->left.hwnd, idx);
3667 set_curdir(child, entry, idx, hwnd);
3671 if (!scanned_old) {
3672 calc_widths(pane, FALSE);
3674 #ifndef _NO_EXTENSIONS
3675 set_header(pane);
3676 #endif
3678 } else {
3679 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3684 static BOOL pane_command(Pane* pane, UINT cmd)
3686 switch(cmd) {
3687 case ID_VIEW_NAME:
3688 if (pane->visible_cols) {
3689 pane->visible_cols = 0;
3690 calc_widths(pane, TRUE);
3691 #ifndef _NO_EXTENSIONS
3692 set_header(pane);
3693 #endif
3694 InvalidateRect(pane->hwnd, 0, TRUE);
3695 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3696 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3697 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3699 break;
3701 case ID_VIEW_ALL_ATTRIBUTES:
3702 if (pane->visible_cols != COL_ALL) {
3703 pane->visible_cols = COL_ALL;
3704 calc_widths(pane, TRUE);
3705 #ifndef _NO_EXTENSIONS
3706 set_header(pane);
3707 #endif
3708 InvalidateRect(pane->hwnd, 0, TRUE);
3709 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3710 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3711 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3713 break;
3715 #ifndef _NO_EXTENSIONS
3716 case ID_PREFERRED_SIZES: {
3717 calc_widths(pane, TRUE);
3718 set_header(pane);
3719 InvalidateRect(pane->hwnd, 0, TRUE);
3720 break;}
3721 #endif
3723 /* TODO: more command ids... */
3725 default:
3726 return FALSE;
3729 return TRUE;
3733 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3735 if (child->sortOrder != sortOrder) {
3736 child->sortOrder = sortOrder;
3737 refresh_child(child);
3741 static void update_view_menu(ChildWnd* child)
3743 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3744 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3745 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3746 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3750 static IContextMenu2* s_pctxmenu2 = NULL;
3751 static IContextMenu3* s_pctxmenu3 = NULL;
3753 static void CtxMenu_reset()
3755 s_pctxmenu2 = NULL;
3756 s_pctxmenu3 = NULL;
3759 IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
3761 IContextMenu* pcm = NULL;
3763 CtxMenu_reset();
3765 if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
3766 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
3767 else if ((*pcm1->lpVtbl->QueryInterface)(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
3768 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
3770 if (pcm) {
3771 (*pcm1->lpVtbl->Release)(pcm1);
3772 return pcm;
3773 } else
3774 return pcm1;
3777 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
3779 if (s_pctxmenu3) {
3780 if (SUCCEEDED((*s_pctxmenu3->lpVtbl->HandleMenuMsg)(s_pctxmenu3, nmsg, wparam, lparam)))
3781 return TRUE;
3784 if (s_pctxmenu2)
3785 if (SUCCEEDED((*s_pctxmenu2->lpVtbl->HandleMenuMsg)(s_pctxmenu2, nmsg, wparam, lparam)))
3786 return TRUE;
3788 return FALSE;
3792 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3794 IContextMenu* pcm;
3796 HRESULT hr = (*shell_folder->lpVtbl->GetUIObjectOf)(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3797 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
3799 if (SUCCEEDED(hr)) {
3800 HMENU hmenu = CreatePopupMenu();
3802 pcm = CtxMenu_query_interfaces(pcm);
3804 if (hmenu) {
3805 hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3807 if (SUCCEEDED(hr)) {
3808 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3810 CtxMenu_reset();
3812 if (idCmd) {
3813 CMINVOKECOMMANDINFO cmi;
3815 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3816 cmi.fMask = 0;
3817 cmi.hwnd = hwndParent;
3818 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3819 cmi.lpParameters = NULL;
3820 cmi.lpDirectory = NULL;
3821 cmi.nShow = SW_SHOWNORMAL;
3822 cmi.dwHotKey = 0;
3823 cmi.hIcon = 0;
3825 hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
3830 (*pcm->lpVtbl->Release)(pcm);
3833 return hr;
3837 LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3839 ChildWnd* child = (ChildWnd*) GetWindowLong(hwnd, GWL_USERDATA);
3840 ASSERT(child);
3842 switch(nmsg) {
3843 case WM_DRAWITEM: {
3844 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3845 Entry* entry = (Entry*) dis->itemData;
3847 if (dis->CtlID == IDW_TREE_LEFT)
3848 draw_item(&child->left, dis, entry, -1);
3849 else if (dis->CtlID == IDW_TREE_RIGHT)
3850 draw_item(&child->right, dis, entry, -1);
3851 else
3852 goto draw_menu_item;
3854 return TRUE;}
3856 case WM_CREATE:
3857 InitChildWindow(child);
3858 break;
3860 case WM_NCDESTROY:
3861 free_child_window(child);
3862 SetWindowLong(hwnd, GWL_USERDATA, 0);
3863 break;
3865 case WM_PAINT: {
3866 PAINTSTRUCT ps;
3867 HBRUSH lastBrush;
3868 RECT rt;
3869 GetClientRect(hwnd, &rt);
3870 BeginPaint(hwnd, &ps);
3871 rt.left = child->split_pos-SPLIT_WIDTH/2;
3872 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3873 lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR));
3874 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3875 SelectObject(ps.hdc, lastBrush);
3876 #ifdef _NO_EXTENSIONS
3877 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
3878 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
3879 #endif
3880 EndPaint(hwnd, &ps);
3881 break;}
3883 case WM_SETCURSOR:
3884 if (LOWORD(lparam) == HTCLIENT) {
3885 POINT pt;
3886 GetCursorPos(&pt);
3887 ScreenToClient(hwnd, &pt);
3889 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3890 SetCursor(LoadCursor(0, IDC_SIZEWE));
3891 return TRUE;
3894 goto def;
3896 case WM_LBUTTONDOWN: {
3897 RECT rt;
3898 int x = GET_X_LPARAM(lparam);
3900 GetClientRect(hwnd, &rt);
3902 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3903 last_split = child->split_pos;
3904 #ifdef _NO_EXTENSIONS
3905 draw_splitbar(hwnd, last_split);
3906 #endif
3907 SetCapture(hwnd);
3910 break;}
3912 case WM_LBUTTONUP:
3913 if (GetCapture() == hwnd) {
3914 #ifdef _NO_EXTENSIONS
3915 RECT rt;
3916 int x = LOWORD(lparam);
3917 draw_splitbar(hwnd, last_split);
3918 last_split = -1;
3919 GetClientRect(hwnd, &rt);
3920 child->split_pos = x;
3921 resize_tree(child, rt.right, rt.bottom);
3922 #endif
3923 ReleaseCapture();
3925 break;
3927 #ifdef _NO_EXTENSIONS
3928 case WM_CAPTURECHANGED:
3929 if (GetCapture()==hwnd && last_split>=0)
3930 draw_splitbar(hwnd, last_split);
3931 break;
3932 #endif
3934 case WM_KEYDOWN:
3935 if (wparam == VK_ESCAPE)
3936 if (GetCapture() == hwnd) {
3937 RECT rt;
3938 #ifdef _NO_EXTENSIONS
3939 draw_splitbar(hwnd, last_split);
3940 #else
3941 child->split_pos = last_split;
3942 #endif
3943 GetClientRect(hwnd, &rt);
3944 resize_tree(child, rt.right, rt.bottom);
3945 last_split = -1;
3946 ReleaseCapture();
3947 SetCursor(LoadCursor(0, IDC_ARROW));
3949 break;
3951 case WM_MOUSEMOVE:
3952 if (GetCapture() == hwnd) {
3953 RECT rt;
3954 int x = LOWORD(lparam);
3956 #ifdef _NO_EXTENSIONS
3957 HDC hdc = GetDC(hwnd);
3958 GetClientRect(hwnd, &rt);
3960 rt.left = last_split-SPLIT_WIDTH/2;
3961 rt.right = last_split+SPLIT_WIDTH/2+1;
3962 InvertRect(hdc, &rt);
3964 last_split = x;
3965 rt.left = x-SPLIT_WIDTH/2;
3966 rt.right = x+SPLIT_WIDTH/2+1;
3967 InvertRect(hdc, &rt);
3969 ReleaseDC(hwnd, hdc);
3970 #else
3971 GetClientRect(hwnd, &rt);
3973 if (x>=0 && x<rt.right) {
3974 child->split_pos = x;
3975 resize_tree(child, rt.right, rt.bottom);
3976 rt.left = x-SPLIT_WIDTH/2;
3977 rt.right = x+SPLIT_WIDTH/2+1;
3978 InvalidateRect(hwnd, &rt, FALSE);
3979 UpdateWindow(child->left.hwnd);
3980 UpdateWindow(hwnd);
3981 UpdateWindow(child->right.hwnd);
3983 #endif
3985 break;
3987 #ifndef _NO_EXTENSIONS
3988 case WM_GETMINMAXINFO:
3989 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
3991 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3993 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3994 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3995 break;}
3996 #endif /* _NO_EXTENSIONS */
3998 case WM_SETFOCUS:
3999 if (SetCurrentDirectory(child->path))
4000 set_space_status();
4001 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4002 break;
4004 case WM_DISPATCH_COMMAND: {
4005 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4007 switch(LOWORD(wparam)) {
4008 case ID_WINDOW_NEW: {
4009 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4011 if (!create_child_window(new_child))
4012 free(new_child);
4014 break;}
4016 case ID_REFRESH:
4017 refresh_drives();
4018 refresh_child(child);
4019 break;
4021 case ID_ACTIVATE:
4022 activate_entry(child, pane, hwnd);
4023 break;
4025 case ID_FILE_MOVE: {
4026 TCHAR new_name[BUFFER_LEN], old_name[BUFFER_LEN];
4027 int len, ret;
4029 get_path(pane->cur, new_name);
4031 ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), hwnd, DestinationDlgProc, (LPARAM)new_name);
4032 if (ret != IDOK)
4033 break;
4035 if (new_name[0]!='/' && new_name[1]!=':') {
4036 get_path(pane->cur->up, old_name);
4037 len = lstrlen(old_name);
4039 if (old_name[len-1]!='\\' && old_name[len-1]!='/')
4040 old_name[len++] = '/';
4042 lstrcpy(old_name+len, new_name);
4043 lstrcpy(new_name, old_name);
4046 get_path(pane->cur, old_name);
4048 if (MoveFileEx(old_name, new_name, MOVEFILE_COPY_ALLOWED)) {
4049 if (pane->treePane) {
4050 pane->root->scanned = FALSE;
4051 pane->cur = pane->root;
4052 activate_entry(child, pane, hwnd);
4054 else
4055 refresh_child(child);
4057 else
4058 display_error(hwnd, GetLastError());
4059 break;}
4061 case ID_VIEW_SORT_NAME:
4062 set_sort_order(child, SORT_NAME);
4063 break;
4065 case ID_VIEW_SORT_TYPE:
4066 set_sort_order(child, SORT_EXT);
4067 break;
4069 case ID_VIEW_SORT_SIZE:
4070 set_sort_order(child, SORT_SIZE);
4071 break;
4073 case ID_VIEW_SORT_DATE:
4074 set_sort_order(child, SORT_DATE);
4075 break;
4077 case ID_VIEW_FILTER: {
4078 struct FilterDialog dlg;
4080 memset(&dlg, 0, sizeof(struct FilterDialog));
4081 _tcscpy(dlg.pattern, child->filter_pattern);
4082 dlg.flags = child->filter_flags;
4084 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4085 _tcscpy(child->filter_pattern, dlg.pattern);
4086 child->filter_flags = dlg.flags;
4087 refresh_right_pane(child);
4089 break;}
4091 case ID_VIEW_SPLIT: {
4092 last_split = child->split_pos;
4093 #ifdef _NO_EXTENSIONS
4094 draw_splitbar(hwnd, last_split);
4095 #endif
4096 SetCapture(hwnd);
4097 break;}
4099 default:
4100 return pane_command(pane, LOWORD(wparam));
4103 return TRUE;}
4105 case WM_COMMAND: {
4106 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4108 switch(HIWORD(wparam)) {
4109 case LBN_SELCHANGE: {
4110 int idx = ListBox_GetCurSel(pane->hwnd);
4111 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4113 if (pane == &child->left)
4114 set_curdir(child, entry, idx, hwnd);
4115 else
4116 pane->cur = entry;
4117 break;}
4119 case LBN_DBLCLK:
4120 activate_entry(child, pane, hwnd);
4121 break;
4123 break;}
4125 #ifndef _NO_EXTENSIONS
4126 case WM_NOTIFY: {
4127 NMHDR* pnmh = (NMHDR*) lparam;
4128 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4129 #endif
4131 #ifdef _SHELL_FOLDERS
4132 case WM_CONTEXTMENU: {
4133 POINT pt, pt_clnt;
4134 Pane* pane;
4135 int idx;
4137 /* first select the current item in the listbox */
4138 HWND hpanel = (HWND) wparam;
4139 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4140 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4141 ScreenToClient(hpanel, &pt_clnt);
4142 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4143 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4145 /* now create the popup menu using shell namespace and IContextMenu */
4146 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4147 idx = ListBox_GetCurSel(pane->hwnd);
4149 if (idx != -1) {
4150 HRESULT hr;
4151 Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx);
4153 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4155 if (pidl_abs) {
4156 IShellFolder* parentFolder;
4157 LPCITEMIDLIST pidlLast;
4159 /* get and use the parent folder to display correct context menu in all cases */
4160 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4161 hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y);
4163 (*parentFolder->lpVtbl->Release)(parentFolder);
4166 (*Globals.iMalloc->lpVtbl->Free)(Globals.iMalloc, pidl_abs);
4169 break;}
4170 #endif
4172 case WM_MEASUREITEM:
4173 draw_menu_item:
4174 if (!wparam) /* Is the message menu-related? */
4175 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4176 return TRUE;
4178 break;
4180 case WM_INITMENUPOPUP:
4181 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4182 return 0;
4184 update_view_menu(child);
4185 break;
4187 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4188 if (s_pctxmenu3) {
4189 LRESULT lResult = 0;
4191 (*s_pctxmenu3->lpVtbl->HandleMenuMsg2)(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4193 return lResult;
4196 break;
4198 case WM_SIZE:
4199 if (wparam != SIZE_MINIMIZED)
4200 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4201 /* fall through */
4203 default: def:
4204 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4207 return 0;
4211 LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4213 ChildWnd* child = (ChildWnd*) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
4214 Pane* pane = (Pane*) GetWindowLong(hwnd, GWL_USERDATA);
4215 ASSERT(child);
4217 switch(nmsg) {
4218 #ifndef _NO_EXTENSIONS
4219 case WM_HSCROLL:
4220 set_header(pane);
4221 break;
4222 #endif
4224 case WM_SETFOCUS:
4225 child->focus_pane = pane==&child->right? 1: 0;
4226 ListBox_SetSel(hwnd, TRUE, 1);
4227 /*TODO: check menu items */
4228 break;
4230 case WM_KEYDOWN:
4231 if (wparam == VK_TAB) {
4232 /*TODO: SetFocus(Globals.hdrivebar) */
4233 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4237 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4241 static void InitInstance(HINSTANCE hinstance)
4243 const static TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4245 WNDCLASSEX wcFrame;
4246 WNDCLASS wcChild;
4247 ATOM hChildClass;
4248 int col;
4250 INITCOMMONCONTROLSEX icc = {
4251 sizeof(INITCOMMONCONTROLSEX),
4252 ICC_BAR_CLASSES
4255 HDC hdc = GetDC(0);
4257 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4259 InitCommonControlsEx(&icc);
4262 /* register frame window class */
4264 wcFrame.cbSize = sizeof(WNDCLASSEX);
4265 wcFrame.style = 0;
4266 wcFrame.lpfnWndProc = FrameWndProc;
4267 wcFrame.cbClsExtra = 0;
4268 wcFrame.cbWndExtra = 0;
4269 wcFrame.hInstance = hinstance;
4270 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4271 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4272 wcFrame.hbrBackground = 0;
4273 wcFrame.lpszMenuName = 0;
4274 wcFrame.lpszClassName = sWINEFILEFRAME;
4275 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4276 MAKEINTRESOURCE(IDI_WINEFILE),
4277 IMAGE_ICON,
4278 GetSystemMetrics(SM_CXSMICON),
4279 GetSystemMetrics(SM_CYSMICON),
4280 LR_SHARED);
4282 Globals.hframeClass = RegisterClassEx(&wcFrame);
4285 /* register tree windows class */
4287 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4288 wcChild.lpfnWndProc = ChildWndProc;
4289 wcChild.cbClsExtra = 0;
4290 wcChild.cbWndExtra = 0;
4291 wcChild.hInstance = hinstance;
4292 wcChild.hIcon = 0;
4293 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4294 wcChild.hbrBackground = 0;
4295 wcChild.lpszMenuName = 0;
4296 wcChild.lpszClassName = sWINEFILETREE;
4298 hChildClass = RegisterClass(&wcChild);
4301 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4303 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4305 ReleaseDC(0, hdc);
4307 Globals.hInstance = hinstance;
4309 #ifdef _SHELL_FOLDERS
4310 CoInitialize(NULL);
4311 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4312 SHGetDesktopFolder(&Globals.iDesktop);
4313 #ifdef __WINE__
4314 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4315 #else
4316 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4317 #endif
4318 #endif
4320 /* load column strings */
4321 col = 0;
4323 load_string(g_pos_names[col++], IDS_COL_NAME);
4324 load_string(g_pos_names[col++], IDS_COL_SIZE);
4325 load_string(g_pos_names[col++], IDS_COL_CDATE);
4326 #ifndef _NO_EXTENSIONS
4327 load_string(g_pos_names[col++], IDS_COL_ADATE);
4328 load_string(g_pos_names[col++], IDS_COL_MDATE);
4329 load_string(g_pos_names[col++], IDS_COL_IDX);
4330 load_string(g_pos_names[col++], IDS_COL_LINKS);
4331 #endif
4332 load_string(g_pos_names[col++], IDS_COL_ATTR);
4333 #ifndef _NO_EXTENSIONS
4334 load_string(g_pos_names[col++], IDS_COL_SEC);
4335 #endif
4339 void show_frame(HWND hwndParent, int cmdshow)
4341 const static TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4343 TCHAR path[MAX_PATH], b1[BUFFER_LEN];
4344 ChildWnd* child;
4345 HMENU hMenuFrame, hMenuWindow;
4347 CLIENTCREATESTRUCT ccs;
4349 if (Globals.hMainWnd)
4350 return;
4352 Globals.hwndParent = hwndParent;
4354 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4355 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4357 Globals.hMenuFrame = hMenuFrame;
4358 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4359 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4361 ccs.hWindowMenu = hMenuWindow;
4362 ccs.idFirstChild = IDW_FIRST_CHILD;
4365 /* create main window */
4366 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4367 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
4368 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4371 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4372 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4373 0, 0, 0, 0,
4374 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4377 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4379 create_drive_bar();
4382 TBBUTTON toolbarBtns[] = {
4383 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4384 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4385 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4386 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4387 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4388 /*TODO
4389 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4390 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4391 */ };
4393 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4394 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4395 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4396 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4399 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4400 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4402 /* CreateStatusWindow does not accept WS_BORDER
4403 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4404 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4405 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4407 /*TODO: read paths and window placements from registry */
4408 GetCurrentDirectory(MAX_PATH, path);
4410 ShowWindow(Globals.hMainWnd, cmdshow);
4412 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4413 /* Shell Namespace as default: */
4414 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4415 #else
4416 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4417 #endif
4419 child->pos.showCmd = SW_SHOWMAXIMIZED;
4420 child->pos.rcNormalPosition.left = 0;
4421 child->pos.rcNormalPosition.top = 0;
4422 child->pos.rcNormalPosition.right = 320;
4423 child->pos.rcNormalPosition.bottom = 280;
4425 if (!create_child_window(child))
4426 free(child);
4428 SetWindowPlacement(child->hwnd, &child->pos);
4430 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4432 Globals.prescan_node = FALSE;
4434 UpdateWindow(Globals.hMainWnd);
4437 void ExitInstance()
4439 #ifdef _SHELL_FOLDERS
4440 (*Globals.iDesktop->lpVtbl->Release)(Globals.iDesktop);
4441 (*Globals.iMalloc->lpVtbl->Release)(Globals.iMalloc);
4442 CoUninitialize();
4443 #endif
4445 ImageList_Destroy(Globals.himl);
4449 /* search for already running win[e]files */
4451 static int g_foundPrevInstance = 0;
4453 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4455 TCHAR cls[128];
4457 GetClassName(hwnd, cls, 128);
4459 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4460 g_foundPrevInstance++;
4461 return FALSE;
4464 return TRUE;
4467 /* search for window of given class name to allow only one running instance */
4468 int find_window_class(LPCTSTR classname)
4470 EnumWindows(EnumWndProc, (LPARAM)classname);
4472 if (g_foundPrevInstance)
4473 return 1;
4475 return 0;
4479 int winefile_main(HINSTANCE hinstance, HWND hwndParent, int cmdshow)
4481 MSG msg;
4483 InitInstance(hinstance);
4485 if (cmdshow == SW_SHOWNORMAL)
4486 /*TODO: read window placement from registry */
4487 cmdshow = SW_MAXIMIZE;
4489 show_frame(hwndParent, cmdshow);
4491 while(GetMessage(&msg, 0, 0, 0)) {
4492 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4493 continue;
4495 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4496 continue;
4498 TranslateMessage(&msg);
4499 DispatchMessage(&msg);
4502 ExitInstance();
4504 return msg.wParam;
4508 int APIENTRY WinMain(HINSTANCE hinstance,
4509 HINSTANCE previnstance,
4510 LPSTR cmdline,
4511 int cmdshow)
4513 #ifdef _NO_EXTENSIONS
4514 if (find_window_class(sWINEFILEFRAME))
4515 return 1;
4516 #endif
4518 winefile_main(hinstance, 0, cmdshow);
4520 return 0;