push d1f5df181c120dbe494f7c89b454752c2e0dcc04
[wine/hacks.git] / programs / winefile / winefile.c
blob0193c7b7f449484946413b9c8a540ca4580c9392
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifdef __WINE__
23 #include "config.h"
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <dirent.h>
30 #endif
32 #define COBJMACROS
34 #include "winefile.h"
35 #include "resource.h"
36 #include "wine/unicode.h"
38 #ifdef _NO_EXTENSIONS
39 #undef _LEFT_FILES
40 #endif
42 #ifndef _MAX_PATH
43 #define _MAX_DRIVE 3
44 #define _MAX_FNAME 256
45 #define _MAX_DIR _MAX_FNAME
46 #define _MAX_EXT _MAX_FNAME
47 #define _MAX_PATH 260
48 #endif
50 #ifdef NONAMELESSUNION
51 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #else
53 #define UNION_MEMBER(x) x
54 #endif
57 #ifdef _SHELL_FOLDERS
58 #define DEFAULT_SPLIT_POS 300
59 #else
60 #define DEFAULT_SPLIT_POS 200
61 #endif
63 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','\\',
65 'W','i','n','e','F','i','l','e','\0'};
66 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
67 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
68 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
69 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
70 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
72 enum ENTRY_TYPE {
73 ET_WINDOWS,
74 ET_UNIX,
75 #ifdef _SHELL_FOLDERS
76 ET_SHELL
77 #endif
80 typedef struct _Entry {
81 struct _Entry* next;
82 struct _Entry* down;
83 struct _Entry* up;
85 BOOL expanded;
86 BOOL scanned;
87 int level;
89 WIN32_FIND_DATA data;
91 #ifndef _NO_EXTENSIONS
92 BY_HANDLE_FILE_INFORMATION bhfi;
93 BOOL bhfi_valid;
94 enum ENTRY_TYPE etype;
95 #endif
96 #ifdef _SHELL_FOLDERS
97 LPITEMIDLIST pidl;
98 IShellFolder* folder;
99 HICON hicon;
100 #endif
101 } Entry;
103 typedef struct {
104 Entry entry;
105 TCHAR path[MAX_PATH];
106 TCHAR volname[_MAX_FNAME];
107 TCHAR fs[_MAX_DIR];
108 DWORD drive_type;
109 DWORD fs_flags;
110 } Root;
112 enum COLUMN_FLAGS {
113 COL_SIZE = 0x01,
114 COL_DATE = 0x02,
115 COL_TIME = 0x04,
116 COL_ATTRIBUTES = 0x08,
117 COL_DOSNAMES = 0x10,
118 #ifdef _NO_EXTENSIONS
119 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
120 #else
121 COL_INDEX = 0x20,
122 COL_LINKS = 0x40,
123 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
124 #endif
127 typedef enum {
128 SORT_NAME,
129 SORT_EXT,
130 SORT_SIZE,
131 SORT_DATE
132 } SORT_ORDER;
134 typedef struct {
135 HWND hwnd;
136 #ifndef _NO_EXTENSIONS
137 HWND hwndHeader;
138 #endif
140 #ifndef _NO_EXTENSIONS
141 #define COLUMNS 10
142 #else
143 #define COLUMNS 5
144 #endif
145 int widths[COLUMNS];
146 int positions[COLUMNS+1];
148 BOOL treePane;
149 int visible_cols;
150 Entry* root;
151 Entry* cur;
152 } Pane;
154 typedef struct {
155 HWND hwnd;
156 Pane left;
157 Pane right;
158 int focus_pane; /* 0: left 1: right */
159 WINDOWPLACEMENT pos;
160 int split_pos;
161 BOOL header_wdths_ok;
163 TCHAR path[MAX_PATH];
164 TCHAR filter_pattern[MAX_PATH];
165 int filter_flags;
166 Root root;
168 SORT_ORDER sortOrder;
169 } ChildWnd;
173 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
174 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
175 static void refresh_child(ChildWnd* child);
176 static void refresh_drives(void);
177 static void get_path(Entry* dir, PTSTR path);
178 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
180 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
181 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
182 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
185 /* globals */
186 WINEFILE_GLOBALS Globals;
188 static int last_split;
190 /* some common string constants */
191 static const TCHAR sEmpty[] = {'\0'};
192 static const WCHAR sSpace[] = {' ', '\0'};
193 static const TCHAR sNumFmt[] = {'%','d','\0'};
194 static const TCHAR sQMarks[] = {'?','?','?','\0'};
196 /* window class names */
197 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
198 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
200 static void format_longlong(LPWSTR ret, ULONGLONG val)
202 WCHAR buffer[65], *p = &buffer[64];
204 *p = 0;
205 do {
206 *(--p) = '0' + val % 10;
207 val /= 10;
208 } while (val);
209 lstrcpyW( ret, p );
213 /* load resource string */
214 static LPTSTR load_string(LPTSTR buffer, DWORD size, UINT id)
216 LoadString(Globals.hInstance, id, buffer, size);
217 return buffer;
220 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
223 /* display error message for the specified WIN32 error code */
224 static void display_error(HWND hwnd, DWORD error)
226 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
227 PTSTR msg;
229 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
230 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
231 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
232 else
233 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
235 LocalFree(msg);
239 /* display network error message using WNetGetLastError() */
240 static void display_network_error(HWND hwnd)
242 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
243 DWORD error;
245 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
246 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
249 static inline BOOL get_check(HWND hwnd, INT id)
251 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
254 static inline INT set_check(HWND hwnd, INT id, BOOL on)
256 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
259 static inline void choose_font(HWND hwnd)
261 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
262 CHOOSEFONTW chFont;
263 LOGFONTW lFont;
265 HDC hdc = GetDC(hwnd);
266 chFont.lStructSize = sizeof(CHOOSEFONT);
267 chFont.hwndOwner = hwnd;
268 chFont.hDC = NULL;
269 chFont.lpLogFont = &lFont;
270 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
271 chFont.rgbColors = RGB(0,0,0);
272 chFont.lCustData = 0;
273 chFont.lpfnHook = NULL;
274 chFont.lpTemplateName = NULL;
275 chFont.hInstance = Globals.hInstance;
276 chFont.lpszStyle = NULL;
277 chFont.nFontType = SIMULATED_FONTTYPE;
278 chFont.nSizeMin = 0;
279 chFont.nSizeMax = 24;
281 if (ChooseFontW(&chFont)) {
282 HWND childWnd;
283 HFONT hFontOld;
285 DeleteObject(Globals.hfont);
286 Globals.hfont = CreateFontIndirectW(&lFont);
287 hFontOld = SelectObject(hdc, Globals.hfont);
288 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
290 /* change font in all open child windows */
291 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
292 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
293 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
294 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
295 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
296 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
297 InvalidateRect(child->left.hwnd, NULL, TRUE);
298 InvalidateRect(child->right.hwnd, NULL, TRUE);
301 SelectObject(hdc, hFontOld);
303 else if (CommDlgExtendedError()) {
304 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
305 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
306 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
309 ReleaseDC(hwnd, hdc);
313 /* allocate and initialise a directory entry */
314 static Entry* alloc_entry(void)
316 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
318 #ifdef _SHELL_FOLDERS
319 entry->pidl = NULL;
320 entry->folder = NULL;
321 entry->hicon = 0;
322 #endif
324 return entry;
327 /* free a directory entry */
328 static void free_entry(Entry* entry)
330 #ifdef _SHELL_FOLDERS
331 if (entry->hicon && entry->hicon!=(HICON)-1)
332 DestroyIcon(entry->hicon);
334 if (entry->folder && entry->folder!=Globals.iDesktop)
335 IShellFolder_Release(entry->folder);
337 if (entry->pidl)
338 IMalloc_Free(Globals.iMalloc, entry->pidl);
339 #endif
341 HeapFree(GetProcessHeap(), 0, entry);
344 /* recursively free all child entries */
345 static void free_entries(Entry* dir)
347 Entry *entry, *next=dir->down;
349 if (next) {
350 dir->down = 0;
352 do {
353 entry = next;
354 next = entry->next;
356 free_entries(entry);
357 free_entry(entry);
358 } while(next);
363 static void read_directory_win(Entry* dir, LPCTSTR path)
365 Entry* first_entry = NULL;
366 Entry* last = NULL;
367 Entry* entry;
369 int level = dir->level + 1;
370 WIN32_FIND_DATA w32fd;
371 HANDLE hFind;
372 #ifndef _NO_EXTENSIONS
373 HANDLE hFile;
374 #endif
376 TCHAR buffer[MAX_PATH], *p;
377 for(p=buffer; *path; )
378 *p++ = *path++;
380 *p++ = '\\';
381 p[0] = '*';
382 p[1] = '\0';
384 hFind = FindFirstFile(buffer, &w32fd);
386 if (hFind != INVALID_HANDLE_VALUE) {
387 do {
388 #ifdef _NO_EXTENSIONS
389 /* hide directory entry "." */
390 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
391 LPCTSTR name = w32fd.cFileName;
393 if (name[0]=='.' && name[1]=='\0')
394 continue;
396 #endif
397 entry = alloc_entry();
399 if (!first_entry)
400 first_entry = entry;
402 if (last)
403 last->next = entry;
405 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
406 entry->down = NULL;
407 entry->up = dir;
408 entry->expanded = FALSE;
409 entry->scanned = FALSE;
410 entry->level = level;
412 #ifndef _NO_EXTENSIONS
413 entry->etype = ET_WINDOWS;
414 entry->bhfi_valid = FALSE;
416 lstrcpy(p, entry->data.cFileName);
418 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
419 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
421 if (hFile != INVALID_HANDLE_VALUE) {
422 if (GetFileInformationByHandle(hFile, &entry->bhfi))
423 entry->bhfi_valid = TRUE;
425 CloseHandle(hFile);
427 #endif
429 last = entry;
430 } while(FindNextFile(hFind, &w32fd));
432 if (last)
433 last->next = NULL;
435 FindClose(hFind);
438 dir->down = first_entry;
439 dir->scanned = TRUE;
443 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
445 Entry* entry;
447 for(entry=dir->down; entry; entry=entry->next) {
448 LPCTSTR p = name;
449 LPCTSTR q = entry->data.cFileName;
451 do {
452 if (!*p || *p == '\\' || *p == '/')
453 return entry;
454 } while(tolower(*p++) == tolower(*q++));
456 p = name;
457 q = entry->data.cAlternateFileName;
459 do {
460 if (!*p || *p == '\\' || *p == '/')
461 return entry;
462 } while(tolower(*p++) == tolower(*q++));
465 return 0;
469 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
471 TCHAR buffer[MAX_PATH];
472 Entry* entry = &root->entry;
473 LPCTSTR s = path;
474 PTSTR d = buffer;
476 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
478 #ifndef _NO_EXTENSIONS
479 entry->etype = ET_WINDOWS;
480 #endif
482 while(entry) {
483 while(*s && *s != '\\' && *s != '/')
484 *d++ = *s++;
486 while(*s == '\\' || *s == '/')
487 s++;
489 *d++ = '\\';
490 *d = '\0';
492 read_directory(entry, buffer, sortOrder, hwnd);
494 if (entry->down)
495 entry->expanded = TRUE;
497 if (!*s)
498 break;
500 entry = find_entry_win(entry, s);
503 SetCursor(old_cursor);
505 return entry;
509 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
511 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
513 struct tm* tm = gmtime(t);
514 SYSTEMTIME stime;
516 if (!tm)
517 return FALSE;
519 stime.wYear = tm->tm_year+1900;
520 stime.wMonth = tm->tm_mon+1;
521 /* stime.wDayOfWeek */
522 stime.wDay = tm->tm_mday;
523 stime.wHour = tm->tm_hour;
524 stime.wMinute = tm->tm_min;
525 stime.wSecond = tm->tm_sec;
527 return SystemTimeToFileTime(&stime, ftime);
530 static void read_directory_unix(Entry* dir, LPCTSTR path)
532 Entry* first_entry = NULL;
533 Entry* last = NULL;
534 Entry* entry;
535 DIR* pdir;
537 int level = dir->level + 1;
538 #ifdef UNICODE
539 char cpath[MAX_PATH];
541 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
542 #else
543 const char* cpath = path;
544 #endif
546 pdir = opendir(cpath);
548 if (pdir) {
549 struct stat st;
550 struct dirent* ent;
551 char buffer[MAX_PATH], *p;
552 const char* s;
554 for(p=buffer,s=cpath; *s; )
555 *p++ = *s++;
557 if (p==buffer || p[-1]!='/')
558 *p++ = '/';
560 while((ent=readdir(pdir))) {
561 entry = alloc_entry();
563 if (!first_entry)
564 first_entry = entry;
566 if (last)
567 last->next = entry;
569 entry->etype = ET_UNIX;
571 strcpy(p, ent->d_name);
572 #ifdef UNICODE
573 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
574 #else
575 lstrcpy(entry->data.cFileName, p);
576 #endif
578 if (!stat(buffer, &st)) {
579 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
581 if (S_ISDIR(st.st_mode))
582 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
584 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
585 entry->data.nFileSizeHigh = st.st_size >> 32;
587 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
588 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
589 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
591 entry->bhfi.nFileIndexLow = ent->d_ino;
592 entry->bhfi.nFileIndexHigh = 0;
594 entry->bhfi.nNumberOfLinks = st.st_nlink;
596 entry->bhfi_valid = TRUE;
597 } else {
598 entry->data.nFileSizeLow = 0;
599 entry->data.nFileSizeHigh = 0;
600 entry->bhfi_valid = FALSE;
603 entry->down = NULL;
604 entry->up = dir;
605 entry->expanded = FALSE;
606 entry->scanned = FALSE;
607 entry->level = level;
609 last = entry;
612 if (last)
613 last->next = NULL;
615 closedir(pdir);
618 dir->down = first_entry;
619 dir->scanned = TRUE;
622 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
624 Entry* entry;
626 for(entry=dir->down; entry; entry=entry->next) {
627 LPCTSTR p = name;
628 LPCTSTR q = entry->data.cFileName;
630 do {
631 if (!*p || *p == '/')
632 return entry;
633 } while(*p++ == *q++);
636 return 0;
639 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
641 TCHAR buffer[MAX_PATH];
642 Entry* entry = &root->entry;
643 LPCTSTR s = path;
644 PTSTR d = buffer;
646 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
648 entry->etype = ET_UNIX;
650 while(entry) {
651 while(*s && *s != '/')
652 *d++ = *s++;
654 while(*s == '/')
655 s++;
657 *d++ = '/';
658 *d = '\0';
660 read_directory(entry, buffer, sortOrder, hwnd);
662 if (entry->down)
663 entry->expanded = TRUE;
665 if (!*s)
666 break;
668 entry = find_entry_unix(entry, s);
671 SetCursor(old_cursor);
673 return entry;
676 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
679 #ifdef _SHELL_FOLDERS
681 #ifdef UNICODE
682 #define get_strret get_strretW
683 #define path_from_pidl path_from_pidlW
684 #else
685 #define get_strret get_strretA
686 #define path_from_pidl path_from_pidlA
687 #endif
690 static void free_strret(STRRET* str)
692 if (str->uType == STRRET_WSTR)
693 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
697 #ifndef UNICODE
699 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
701 LPCSTR s;
702 LPSTR d = dest;
704 for(s=source; count&&(*d++=*s++); )
705 count--;
707 return dest;
710 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
712 switch(str->uType) {
713 case STRRET_WSTR:
714 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
715 break;
717 case STRRET_OFFSET:
718 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
719 break;
721 case STRRET_CSTR:
722 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
726 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
728 STRRET str;
730 /* SHGDN_FORPARSING: get full path of id list */
731 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
733 if (SUCCEEDED(hr)) {
734 get_strretA(&str, &pidl->mkid, buffer, len);
735 free_strret(&str);
736 } else
737 buffer[0] = '\0';
739 return hr;
742 #endif
744 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
746 LPCWSTR s;
747 LPWSTR d = dest;
749 for(s=source; count&&(*d++=*s++); )
750 count--;
752 return dest;
755 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
757 switch(str->uType) {
758 case STRRET_WSTR:
759 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
760 break;
762 case STRRET_OFFSET:
763 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
764 break;
766 case STRRET_CSTR:
767 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
772 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
774 STRRET str;
776 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
778 if (SUCCEEDED(hr)) {
779 get_strret(&str, &pidl->mkid, buffer, len);
780 free_strret(&str);
781 } else
782 buffer[0] = '\0';
784 return hr;
788 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
790 STRRET str;
792 /* SHGDN_FORPARSING: get full path of id list */
793 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
795 if (SUCCEEDED(hr)) {
796 get_strretW(&str, &pidl->mkid, buffer, len);
797 free_strret(&str);
798 } else
799 buffer[0] = '\0';
801 return hr;
805 /* create an item id list from a file system path */
807 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
809 LPITEMIDLIST pidl;
810 HRESULT hr;
811 ULONG len;
813 #ifdef UNICODE
814 LPWSTR buffer = path;
815 #else
816 WCHAR buffer[MAX_PATH];
817 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
818 #endif
820 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
821 if (FAILED(hr))
822 return NULL;
824 return pidl;
828 /* convert an item id list from relative to absolute (=relative to the desktop) format */
830 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
832 if (entry->up && entry->up->etype==ET_SHELL) {
833 LPITEMIDLIST idl = NULL;
835 while (entry->up) {
836 idl = ILCombine(ILClone(entry->pidl), idl);
837 entry = entry->up;
840 return idl;
841 } else if (entry->etype == ET_WINDOWS) {
842 TCHAR path[MAX_PATH];
844 get_path(entry, path);
846 return get_path_pidl(path, hwnd);
847 } else if (entry->pidl)
848 return ILClone(entry->pidl);
850 return NULL;
854 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
856 IExtractIcon* pExtract;
858 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
859 TCHAR path[_MAX_PATH];
860 unsigned flags;
861 HICON hicon;
862 int idx;
864 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
865 if (!(flags & GIL_NOTFILENAME)) {
866 if (idx == -1)
867 idx = 0; /* special case for some control panel applications */
869 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
870 flags &= ~GIL_DONTCACHE;
871 } else {
872 HICON hIconLarge = 0;
874 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
876 if (SUCCEEDED(hr))
877 DestroyIcon(hIconLarge);
880 return hicon;
884 return 0;
888 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
890 Entry* entry;
892 for(entry=dir->down; entry; entry=entry->next) {
893 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
894 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
895 return entry;
898 return 0;
901 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
903 Entry* entry = &root->entry;
904 Entry* next;
905 LPITEMIDLIST next_pidl = pidl;
906 IShellFolder* folder;
907 IShellFolder* child = NULL;
908 HRESULT hr;
910 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
912 #ifndef _NO_EXTENSIONS
913 entry->etype = ET_SHELL;
914 #endif
916 folder = Globals.iDesktop;
918 while(entry) {
919 entry->pidl = next_pidl;
920 entry->folder = folder;
922 if (!pidl->mkid.cb)
923 break;
925 /* copy first element of item idlist */
926 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
927 memcpy(next_pidl, pidl, pidl->mkid.cb);
928 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
930 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
931 if (FAILED(hr))
932 break;
934 read_directory(entry, NULL, sortOrder, hwnd);
936 if (entry->down)
937 entry->expanded = TRUE;
939 next = find_entry_shell(entry, next_pidl);
940 if (!next)
941 break;
943 folder = child;
944 entry = next;
946 /* go to next element */
947 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
950 SetCursor(old_cursor);
952 return entry;
956 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
958 if (!(attribs & SFGAO_FILESYSTEM) ||
959 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
960 WIN32_FILE_ATTRIBUTE_DATA fad;
961 IDataObject* pDataObj;
963 STGMEDIUM medium = {0, {0}, 0};
964 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
966 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
968 if (SUCCEEDED(hr)) {
969 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
971 IDataObject_Release(pDataObj);
973 if (SUCCEEDED(hr)) {
974 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
975 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
977 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
978 w32fdata->dwFileAttributes = fad.dwFileAttributes;
979 w32fdata->ftCreationTime = fad.ftCreationTime;
980 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
981 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
983 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
984 w32fdata->nFileSizeLow = fad.nFileSizeLow;
985 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
989 SetErrorMode(sem_org);
991 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
992 GlobalFree(medium.UNION_MEMBER(hGlobal));
997 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
998 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1000 if (attribs & SFGAO_READONLY)
1001 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
1003 if (attribs & SFGAO_COMPRESSED)
1004 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
1008 static void read_directory_shell(Entry* dir, HWND hwnd)
1010 IShellFolder* folder = dir->folder;
1011 int level = dir->level + 1;
1012 HRESULT hr;
1014 IShellFolder* child;
1015 IEnumIDList* idlist;
1017 Entry* first_entry = NULL;
1018 Entry* last = NULL;
1019 Entry* entry;
1021 if (!folder)
1022 return;
1024 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1026 if (SUCCEEDED(hr)) {
1027 for(;;) {
1028 #define FETCH_ITEM_COUNT 32
1029 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1030 SFGAOF attribs;
1031 ULONG cnt = 0;
1032 ULONG n;
1034 memset(pidls, 0, sizeof(pidls));
1036 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1037 if (FAILED(hr))
1038 break;
1040 if (hr == S_FALSE)
1041 break;
1043 for(n=0; n<cnt; ++n) {
1044 entry = alloc_entry();
1046 if (!first_entry)
1047 first_entry = entry;
1049 if (last)
1050 last->next = entry;
1052 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1053 entry->bhfi_valid = FALSE;
1055 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1057 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1059 if (SUCCEEDED(hr)) {
1060 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1061 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1063 entry->bhfi_valid = TRUE;
1064 } else
1065 attribs = 0;
1066 } else
1067 attribs = 0;
1069 entry->pidl = pidls[n];
1071 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1072 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1074 if (SUCCEEDED(hr))
1075 entry->folder = child;
1076 else
1077 entry->folder = NULL;
1079 else
1080 entry->folder = NULL;
1082 if (!entry->data.cFileName[0])
1083 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1085 /* get display icons for files and virtual objects */
1086 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1087 !(attribs & SFGAO_FILESYSTEM)) {
1088 entry->hicon = extract_icon(folder, pidls[n]);
1090 if (!entry->hicon)
1091 entry->hicon = (HICON)-1; /* don't try again later */
1094 entry->down = NULL;
1095 entry->up = dir;
1096 entry->expanded = FALSE;
1097 entry->scanned = FALSE;
1098 entry->level = level;
1100 #ifndef _NO_EXTENSIONS
1101 entry->etype = ET_SHELL;
1102 entry->bhfi_valid = FALSE;
1103 #endif
1105 last = entry;
1109 IEnumIDList_Release(idlist);
1112 if (last)
1113 last->next = NULL;
1115 dir->down = first_entry;
1116 dir->scanned = TRUE;
1119 #endif /* _SHELL_FOLDERS */
1122 /* sort order for different directory/file types */
1123 enum TYPE_ORDER {
1124 TO_DIR = 0,
1125 TO_DOT = 1,
1126 TO_DOTDOT = 2,
1127 TO_OTHER_DIR = 3,
1128 TO_FILE = 4
1131 /* distinguish between ".", ".." and any other directory names */
1132 static int TypeOrderFromDirname(LPCTSTR name)
1134 if (name[0] == '.') {
1135 if (name[1] == '\0')
1136 return TO_DOT; /* "." */
1138 if (name[1]=='.' && name[2]=='\0')
1139 return TO_DOTDOT; /* ".." */
1142 return TO_OTHER_DIR; /* anything else */
1145 /* directories first... */
1146 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1148 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1149 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1151 /* Handle "." and ".." as special case and move them at the very first beginning. */
1152 if (order1==TO_DIR && order2==TO_DIR) {
1153 order1 = TypeOrderFromDirname(fd1->cFileName);
1154 order2 = TypeOrderFromDirname(fd2->cFileName);
1157 return order2==order1? 0: order1<order2? -1: 1;
1161 static int compareName(const void* arg1, const void* arg2)
1163 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1164 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1166 int cmp = compareType(fd1, fd2);
1167 if (cmp)
1168 return cmp;
1170 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1173 static int compareExt(const void* arg1, const void* arg2)
1175 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1176 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1177 const TCHAR *name1, *name2, *ext1, *ext2;
1179 int cmp = compareType(fd1, fd2);
1180 if (cmp)
1181 return cmp;
1183 name1 = fd1->cFileName;
1184 name2 = fd2->cFileName;
1186 ext1 = strrchrW(name1, '.');
1187 ext2 = strrchrW(name2, '.');
1189 if (ext1)
1190 ext1++;
1191 else
1192 ext1 = sEmpty;
1194 if (ext2)
1195 ext2++;
1196 else
1197 ext2 = sEmpty;
1199 cmp = lstrcmpi(ext1, ext2);
1200 if (cmp)
1201 return cmp;
1203 return lstrcmpi(name1, name2);
1206 static int compareSize(const void* arg1, const void* arg2)
1208 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1209 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1211 int cmp = compareType(fd1, fd2);
1212 if (cmp)
1213 return cmp;
1215 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1217 if (cmp < 0)
1218 return -1;
1219 else if (cmp > 0)
1220 return 1;
1222 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1224 return cmp<0? -1: cmp>0? 1: 0;
1227 static int compareDate(const void* arg1, const void* arg2)
1229 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1230 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1232 int cmp = compareType(fd1, fd2);
1233 if (cmp)
1234 return cmp;
1236 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1240 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1241 compareName, /* SORT_NAME */
1242 compareExt, /* SORT_EXT */
1243 compareSize, /* SORT_SIZE */
1244 compareDate /* SORT_DATE */
1248 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1250 Entry* entry = dir->down;
1251 Entry** array, **p;
1252 int len;
1254 len = 0;
1255 for(entry=dir->down; entry; entry=entry->next)
1256 len++;
1258 if (len) {
1259 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1261 p = array;
1262 for(entry=dir->down; entry; entry=entry->next)
1263 *p++ = entry;
1265 /* call qsort with the appropriate compare function */
1266 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1268 dir->down = array[0];
1270 for(p=array; --len; p++)
1271 p[0]->next = p[1];
1273 (*p)->next = 0;
1275 HeapFree(GetProcessHeap(), 0, array);
1280 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1282 TCHAR buffer[MAX_PATH];
1283 Entry* entry;
1284 LPCTSTR s;
1285 PTSTR d;
1287 #ifdef _SHELL_FOLDERS
1288 if (dir->etype == ET_SHELL)
1290 read_directory_shell(dir, hwnd);
1292 if (Globals.prescan_node) {
1293 s = path;
1294 d = buffer;
1296 while(*s)
1297 *d++ = *s++;
1299 *d++ = '\\';
1301 for(entry=dir->down; entry; entry=entry->next)
1302 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1303 read_directory_shell(entry, hwnd);
1304 SortDirectory(entry, sortOrder);
1308 else
1309 #endif
1310 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1311 if (dir->etype == ET_UNIX)
1313 read_directory_unix(dir, path);
1315 if (Globals.prescan_node) {
1316 s = path;
1317 d = buffer;
1319 while(*s)
1320 *d++ = *s++;
1322 *d++ = '/';
1324 for(entry=dir->down; entry; entry=entry->next)
1325 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1326 lstrcpy(d, entry->data.cFileName);
1327 read_directory_unix(entry, buffer);
1328 SortDirectory(entry, sortOrder);
1332 else
1333 #endif
1335 read_directory_win(dir, path);
1337 if (Globals.prescan_node) {
1338 s = path;
1339 d = buffer;
1341 while(*s)
1342 *d++ = *s++;
1344 *d++ = '\\';
1346 for(entry=dir->down; entry; entry=entry->next)
1347 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1348 lstrcpy(d, entry->data.cFileName);
1349 read_directory_win(entry, buffer);
1350 SortDirectory(entry, sortOrder);
1355 SortDirectory(dir, sortOrder);
1359 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1361 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1362 static const TCHAR sSlash[] = {'/', '\0'};
1363 #endif
1364 static const TCHAR sBackslash[] = {'\\', '\0'};
1366 #ifdef _SHELL_FOLDERS
1367 if (pidl)
1369 /* read shell namespace tree */
1370 root->drive_type = DRIVE_UNKNOWN;
1371 drv[0] = '\\';
1372 drv[1] = '\0';
1373 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_DESKTOP);
1374 root->fs_flags = 0;
1375 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_SHELL);
1377 return read_tree_shell(root, pidl, sortOrder, hwnd);
1379 else
1380 #endif
1381 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1382 if (*path == '/')
1384 /* read unix file system tree */
1385 root->drive_type = GetDriveType(path);
1387 lstrcat(drv, sSlash);
1388 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_ROOT_FS);
1389 root->fs_flags = 0;
1390 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_UNIXFS);
1392 lstrcpy(root->path, sSlash);
1394 return read_tree_unix(root, path, sortOrder, hwnd);
1396 #endif
1398 /* read WIN32 file system tree */
1399 root->drive_type = GetDriveType(path);
1401 lstrcat(drv, sBackslash);
1402 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1404 lstrcpy(root->path, drv);
1406 return read_tree_win(root, path, sortOrder, hwnd);
1410 /* flags to filter different file types */
1411 enum TYPE_FILTER {
1412 TF_DIRECTORIES = 0x01,
1413 TF_PROGRAMS = 0x02,
1414 TF_DOCUMENTS = 0x04,
1415 TF_OTHERS = 0x08,
1416 TF_HIDDEN = 0x10,
1417 TF_ALL = 0x1F
1421 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1423 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1424 TCHAR dir_path[MAX_PATH];
1425 TCHAR b1[BUFFER_LEN];
1426 static const TCHAR sAsterics[] = {'*', '\0'};
1428 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1429 Root* root = &child->root;
1430 Entry* entry;
1432 memset(child, 0, sizeof(ChildWnd));
1434 child->left.treePane = TRUE;
1435 child->left.visible_cols = 0;
1437 child->right.treePane = FALSE;
1438 #ifndef _NO_EXTENSIONS
1439 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1440 #else
1441 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1442 #endif
1444 child->pos.length = sizeof(WINDOWPLACEMENT);
1445 child->pos.flags = 0;
1446 child->pos.showCmd = SW_SHOWNORMAL;
1447 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1448 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1449 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1450 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1452 child->focus_pane = 0;
1453 child->split_pos = DEFAULT_SPLIT_POS;
1454 child->sortOrder = SORT_NAME;
1455 child->header_wdths_ok = FALSE;
1457 if (path)
1459 lstrcpy(child->path, path);
1461 _tsplitpath(path, drv, dir, name, ext);
1464 lstrcpy(child->filter_pattern, sAsterics);
1465 child->filter_flags = TF_ALL;
1467 root->entry.level = 0;
1469 lstrcpy(dir_path, drv);
1470 lstrcat(dir_path, dir);
1471 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1473 #ifdef _SHELL_FOLDERS
1474 if (root->entry.etype == ET_SHELL)
1475 load_string(root->entry.data.cFileName, sizeof(root->entry.data.cFileName)/sizeof(root->entry.data.cFileName[0]), IDS_DESKTOP);
1476 else
1477 #endif
1478 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1480 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1482 child->left.root = &root->entry;
1483 child->right.root = NULL;
1485 set_curdir(child, entry, 0, hwnd);
1487 return child;
1491 /* free all memory associated with a child window */
1492 static void free_child_window(ChildWnd* child)
1494 free_entries(&child->root.entry);
1495 HeapFree(GetProcessHeap(), 0, child);
1499 /* get full path of specified directory entry */
1500 static void get_path(Entry* dir, PTSTR path)
1502 Entry* entry;
1503 int len = 0;
1504 int level = 0;
1506 #ifdef _SHELL_FOLDERS
1507 if (dir->etype == ET_SHELL)
1509 SFGAOF attribs;
1510 HRESULT hr = S_OK;
1512 path[0] = '\0';
1514 attribs = 0;
1516 if (dir->folder)
1517 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1519 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1520 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1522 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1525 else
1526 #endif
1528 for(entry=dir; entry; level++) {
1529 LPCTSTR name;
1530 int l;
1533 LPCTSTR s;
1534 name = entry->data.cFileName;
1535 s = name;
1537 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1538 l++;
1541 if (entry->up) {
1542 if (l > 0) {
1543 memmove(path+l+1, path, len*sizeof(TCHAR));
1544 memcpy(path+1, name, l*sizeof(TCHAR));
1545 len += l+1;
1547 #ifndef _NO_EXTENSIONS
1548 if (entry->etype == ET_UNIX)
1549 path[0] = '/';
1550 else
1551 #endif
1552 path[0] = '\\';
1555 entry = entry->up;
1556 } else {
1557 memmove(path+l, path, len*sizeof(TCHAR));
1558 memcpy(path, name, l*sizeof(TCHAR));
1559 len += l;
1560 break;
1564 if (!level) {
1565 #ifndef _NO_EXTENSIONS
1566 if (entry->etype == ET_UNIX)
1567 path[len++] = '/';
1568 else
1569 #endif
1570 path[len++] = '\\';
1573 path[len] = '\0';
1577 static windowOptions load_registry_settings(void)
1579 DWORD size;
1580 DWORD type;
1581 HKEY hKey;
1582 windowOptions opts;
1583 LOGFONT logfont;
1585 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1586 0, KEY_QUERY_VALUE, &hKey );
1588 size = sizeof(DWORD);
1590 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1591 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1592 opts.start_x = CW_USEDEFAULT;
1594 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1595 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1596 opts.start_y = CW_USEDEFAULT;
1598 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1599 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1600 opts.width = CW_USEDEFAULT;
1602 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1603 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1604 opts.height = CW_USEDEFAULT;
1605 size=sizeof(logfont);
1606 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1607 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1608 GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1610 RegCloseKey( hKey );
1612 Globals.hfont = CreateFontIndirect(&logfont);
1613 return opts;
1616 static void save_registry_settings(void)
1618 WINDOWINFO wi;
1619 HKEY hKey;
1620 INT width, height;
1621 LOGFONT logfont;
1623 wi.cbSize = sizeof( WINDOWINFO );
1624 GetWindowInfo(Globals.hMainWnd, &wi);
1625 width = wi.rcWindow.right - wi.rcWindow.left;
1626 height = wi.rcWindow.bottom - wi.rcWindow.top;
1628 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1629 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1631 /* Unable to save registry settings - try to create key */
1632 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1633 0, NULL, REG_OPTION_NON_VOLATILE,
1634 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1636 /* FIXME: Cannot create key */
1637 return;
1640 /* Save all of the settings */
1641 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1642 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1643 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1644 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1645 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1646 (LPBYTE) &width, sizeof(DWORD) );
1647 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1648 (LPBYTE) &height, sizeof(DWORD) );
1649 GetObject(Globals.hfont, sizeof(logfont), &logfont);
1650 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1651 (LPBYTE) &logfont, sizeof(LOGFONT) );
1653 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1654 RegCloseKey( hKey );
1657 static void resize_frame_rect(HWND hwnd, PRECT prect)
1659 int new_top;
1660 RECT rt;
1662 if (IsWindowVisible(Globals.htoolbar)) {
1663 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1664 GetClientRect(Globals.htoolbar, &rt);
1665 prect->top = rt.bottom+3;
1666 prect->bottom -= rt.bottom+3;
1669 if (IsWindowVisible(Globals.hdrivebar)) {
1670 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1671 GetClientRect(Globals.hdrivebar, &rt);
1672 new_top = --prect->top + rt.bottom+3;
1673 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1674 prect->top = new_top;
1675 prect->bottom -= rt.bottom+2;
1678 if (IsWindowVisible(Globals.hstatusbar)) {
1679 int parts[] = {300, 500};
1681 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1682 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1683 GetClientRect(Globals.hstatusbar, &rt);
1684 prect->bottom -= rt.bottom;
1687 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1690 static void resize_frame(HWND hwnd, int cx, int cy)
1692 RECT rect;
1694 rect.left = 0;
1695 rect.top = 0;
1696 rect.right = cx;
1697 rect.bottom = cy;
1699 resize_frame_rect(hwnd, &rect);
1702 static void resize_frame_client(HWND hwnd)
1704 RECT rect;
1706 GetClientRect(hwnd, &rect);
1708 resize_frame_rect(hwnd, &rect);
1712 static HHOOK hcbthook;
1713 static ChildWnd* newchild = NULL;
1715 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1717 if (code==HCBT_CREATEWND && newchild) {
1718 ChildWnd* child = newchild;
1719 newchild = NULL;
1721 child->hwnd = (HWND) wparam;
1722 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1725 return CallNextHookEx(hcbthook, code, wparam, lparam);
1728 static HWND create_child_window(ChildWnd* child)
1730 MDICREATESTRUCT mcs;
1731 int idx;
1733 mcs.szClass = sWINEFILETREE;
1734 mcs.szTitle = (LPTSTR)child->path;
1735 mcs.hOwner = Globals.hInstance;
1736 mcs.x = child->pos.rcNormalPosition.left;
1737 mcs.y = child->pos.rcNormalPosition.top;
1738 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1739 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1740 mcs.style = 0;
1741 mcs.lParam = 0;
1743 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1745 newchild = child;
1746 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1747 if (!child->hwnd) {
1748 UnhookWindowsHookEx(hcbthook);
1749 return 0;
1752 UnhookWindowsHookEx(hcbthook);
1754 SendMessage(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1755 SendMessage(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1757 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1758 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
1760 return child->hwnd;
1764 struct ExecuteDialog {
1765 TCHAR cmd[MAX_PATH];
1766 int cmdshow;
1769 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1771 static struct ExecuteDialog* dlg;
1773 switch(nmsg) {
1774 case WM_INITDIALOG:
1775 dlg = (struct ExecuteDialog*) lparam;
1776 return 1;
1778 case WM_COMMAND: {
1779 int id = (int)wparam;
1781 if (id == IDOK) {
1782 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1783 dlg->cmdshow = get_check(hwnd,214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL;
1784 EndDialog(hwnd, id);
1785 } else if (id == IDCANCEL)
1786 EndDialog(hwnd, id);
1788 return 1;}
1791 return 0;
1795 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1797 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1799 switch(nmsg) {
1800 case WM_INITDIALOG:
1801 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1802 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1803 return 1;
1805 case WM_COMMAND: {
1806 int id = (int)wparam;
1808 switch(id) {
1809 case IDOK: {
1810 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1811 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1812 EndDialog(hwnd, id);
1813 break;}
1815 case IDCANCEL:
1816 EndDialog(hwnd, id);
1817 break;
1819 case 254:
1820 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1821 break;
1824 return 1;
1828 return 0;
1832 struct FilterDialog {
1833 TCHAR pattern[MAX_PATH];
1834 int flags;
1837 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1839 static struct FilterDialog* dlg;
1841 switch(nmsg) {
1842 case WM_INITDIALOG:
1843 dlg = (struct FilterDialog*) lparam;
1844 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1845 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1846 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1847 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1848 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1849 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1850 return 1;
1852 case WM_COMMAND: {
1853 int id = (int)wparam;
1855 if (id == IDOK) {
1856 int flags = 0;
1858 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1860 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1861 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1862 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1863 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1864 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1866 dlg->flags = flags;
1868 EndDialog(hwnd, id);
1869 } else if (id == IDCANCEL)
1870 EndDialog(hwnd, id);
1872 return 1;}
1875 return 0;
1879 struct PropertiesDialog {
1880 TCHAR path[MAX_PATH];
1881 Entry entry;
1882 void* pVersionData;
1885 /* Structure used to store enumerated languages and code pages. */
1886 struct LANGANDCODEPAGE {
1887 WORD wLanguage;
1888 WORD wCodePage;
1889 } *lpTranslate;
1891 static LPCSTR InfoStrings[] = {
1892 "Comments",
1893 "CompanyName",
1894 "FileDescription",
1895 "FileVersion",
1896 "InternalName",
1897 "LegalCopyright",
1898 "LegalTrademarks",
1899 "OriginalFilename",
1900 "PrivateBuild",
1901 "ProductName",
1902 "ProductVersion",
1903 "SpecialBuild",
1904 NULL
1907 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1909 int idx = SendMessage(hlbox, LB_GETCURSEL, 0, 0);
1911 if (idx != LB_ERR) {
1912 LPCTSTR pValue = (LPCTSTR) SendMessage(hlbox, LB_GETITEMDATA, idx, 0);
1914 if (pValue)
1915 SetWindowText(hedit, pValue);
1919 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1921 static TCHAR sBackSlash[] = {'\\','\0'};
1922 static TCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1923 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1924 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1925 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1927 if (dwVersionDataLen) {
1928 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1930 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1931 LPVOID pVal;
1932 UINT nValLen;
1934 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1935 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1936 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1937 char buffer[BUFFER_LEN];
1939 sprintf(buffer, "%d.%d.%d.%d",
1940 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1941 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1943 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1947 /* Read the list of languages and code pages. */
1948 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1949 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1950 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1952 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1954 /* Read the file description for each language and code page. */
1955 for(; pTranslate<pEnd; ++pTranslate) {
1956 LPCSTR* p;
1958 for(p=InfoStrings; *p; ++p) {
1959 TCHAR subblock[200];
1960 #ifdef UNICODE
1961 TCHAR infoStr[100];
1962 #endif
1963 LPCTSTR pTxt;
1964 UINT nValLen;
1966 LPCSTR pInfoString = *p;
1967 #ifdef UNICODE
1968 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1969 #else
1970 #define infoStr pInfoString
1971 #endif
1972 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1974 /* Retrieve file description for language and code page */
1975 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1976 int idx = SendMessage(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
1977 SendMessage(hlbox, LB_SETITEMDATA, idx, (LPARAM) pTxt);
1982 SendMessage(hlbox, LB_SETCURSEL, 0, 0);
1984 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1990 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1992 static struct PropertiesDialog* dlg;
1994 switch(nmsg) {
1995 case WM_INITDIALOG: {
1996 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1997 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1998 LPWIN32_FIND_DATA pWFD;
2000 dlg = (struct PropertiesDialog*) lparam;
2001 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
2003 GetWindowText(hwnd, b1, MAX_PATH);
2004 wsprintf(b2, b1, pWFD->cFileName);
2005 SetWindowText(hwnd, b2);
2007 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
2008 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
2010 format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
2011 wsprintf(b2, sByteFmt, b1);
2012 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
2014 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
2015 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
2017 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
2018 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
2019 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
2020 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
2021 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
2023 CheckForFileInfo(dlg, hwnd, dlg->path);
2024 return 1;}
2026 case WM_COMMAND: {
2027 int id = (int)wparam;
2029 switch(HIWORD(wparam)) {
2030 case LBN_SELCHANGE: {
2031 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2032 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2033 break;
2036 case BN_CLICKED:
2037 if (id==IDOK || id==IDCANCEL)
2038 EndDialog(hwnd, id);
2041 return 1;}
2043 case WM_NCDESTROY:
2044 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
2045 dlg->pVersionData = NULL;
2046 break;
2049 return 0;
2052 static void show_properties_dlg(Entry* entry, HWND hwnd)
2054 struct PropertiesDialog dlg;
2056 memset(&dlg, 0, sizeof(struct PropertiesDialog));
2057 get_path(entry, dlg.path);
2058 memcpy(&dlg.entry, entry, sizeof(Entry));
2060 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
2064 #ifndef _NO_EXTENSIONS
2066 static struct FullScreenParameters {
2067 BOOL mode;
2068 RECT orgPos;
2069 BOOL wasZoomed;
2070 } g_fullscreen = {
2071 FALSE, /* mode */
2072 {0, 0, 0, 0},
2073 FALSE
2076 static void frame_get_clientspace(HWND hwnd, PRECT prect)
2078 RECT rt;
2080 if (!IsIconic(hwnd))
2081 GetClientRect(hwnd, prect);
2082 else {
2083 WINDOWPLACEMENT wp;
2085 GetWindowPlacement(hwnd, &wp);
2087 prect->left = prect->top = 0;
2088 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
2089 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
2090 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
2091 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
2092 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2095 if (IsWindowVisible(Globals.htoolbar)) {
2096 GetClientRect(Globals.htoolbar, &rt);
2097 prect->top += rt.bottom+2;
2100 if (IsWindowVisible(Globals.hdrivebar)) {
2101 GetClientRect(Globals.hdrivebar, &rt);
2102 prect->top += rt.bottom+2;
2105 if (IsWindowVisible(Globals.hstatusbar)) {
2106 GetClientRect(Globals.hstatusbar, &rt);
2107 prect->bottom -= rt.bottom;
2111 static BOOL toggle_fullscreen(HWND hwnd)
2113 RECT rt;
2115 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2116 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2117 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2119 Frame_CalcFrameClient(hwnd, &rt);
2120 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2121 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2123 rt.left = g_fullscreen.orgPos.left-rt.left;
2124 rt.top = g_fullscreen.orgPos.top-rt.top;
2125 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2126 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2128 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2129 } else {
2130 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2131 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2132 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2134 if (g_fullscreen.wasZoomed)
2135 ShowWindow(hwnd, WS_MAXIMIZE);
2138 return g_fullscreen.mode;
2141 static void fullscreen_move(HWND hwnd)
2143 RECT rt, pos;
2144 GetWindowRect(hwnd, &pos);
2146 Frame_CalcFrameClient(hwnd, &rt);
2147 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2148 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2150 rt.left = pos.left-rt.left;
2151 rt.top = pos.top-rt.top;
2152 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2153 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2155 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2158 #endif
2161 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2163 BOOL vis = IsWindowVisible(hchild);
2165 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2167 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2169 #ifndef _NO_EXTENSIONS
2170 if (g_fullscreen.mode)
2171 fullscreen_move(hwnd);
2172 #endif
2174 resize_frame_client(hwnd);
2177 static BOOL activate_drive_window(LPCTSTR path)
2179 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2180 HWND child_wnd;
2182 _tsplitpath(path, drv1, 0, 0, 0);
2184 /* search for a already open window for the same drive */
2185 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2186 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2188 if (child) {
2189 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2191 if (!lstrcmpi(drv2, drv1)) {
2192 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2194 if (IsIconic(child_wnd))
2195 ShowWindow(child_wnd, SW_SHOWNORMAL);
2197 return TRUE;
2202 return FALSE;
2205 static BOOL activate_fs_window(LPCTSTR filesys)
2207 HWND child_wnd;
2209 /* search for a already open window of the given file system name */
2210 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2211 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2213 if (child) {
2214 if (!lstrcmpi(child->root.fs, filesys)) {
2215 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2217 if (IsIconic(child_wnd))
2218 ShowWindow(child_wnd, SW_SHOWNORMAL);
2220 return TRUE;
2225 return FALSE;
2228 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2230 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2232 switch(nmsg) {
2233 case WM_CLOSE:
2234 if (Globals.saveSettings)
2235 save_registry_settings();
2237 DestroyWindow(hwnd);
2239 /* clear handle variables */
2240 Globals.hMenuFrame = 0;
2241 Globals.hMenuView = 0;
2242 Globals.hMenuOptions = 0;
2243 Globals.hMainWnd = 0;
2244 Globals.hmdiclient = 0;
2245 Globals.hdrivebar = 0;
2246 break;
2248 case WM_DESTROY:
2249 PostQuitMessage(0);
2250 break;
2252 case WM_INITMENUPOPUP: {
2253 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2255 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2256 return 0;
2257 break;}
2259 case WM_COMMAND: {
2260 UINT cmd = LOWORD(wparam);
2261 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2263 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2264 break;
2266 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2267 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2268 ChildWnd* child;
2269 LPCTSTR root = Globals.drives;
2270 int i;
2272 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2273 while(*root)
2274 root++;
2276 if (activate_drive_window(root))
2277 return 0;
2279 _tsplitpath(root, drv, 0, 0, 0);
2281 if (!SetCurrentDirectory(drv)) {
2282 display_error(hwnd, GetLastError());
2283 return 0;
2286 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2287 child = alloc_child_window(path, NULL, hwnd);
2289 if (!create_child_window(child))
2290 HeapFree(GetProcessHeap(), 0, child);
2291 } else switch(cmd) {
2292 case ID_FILE_EXIT:
2293 SendMessage(hwnd, WM_CLOSE, 0, 0);
2294 break;
2296 case ID_WINDOW_NEW: {
2297 TCHAR path[MAX_PATH];
2298 ChildWnd* child;
2300 GetCurrentDirectory(MAX_PATH, path);
2301 child = alloc_child_window(path, NULL, hwnd);
2303 if (!create_child_window(child))
2304 HeapFree(GetProcessHeap(), 0, child);
2305 break;}
2307 case ID_REFRESH:
2308 refresh_drives();
2309 break;
2311 case ID_WINDOW_CASCADE:
2312 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2313 break;
2315 case ID_WINDOW_TILE_HORZ:
2316 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2317 break;
2319 case ID_WINDOW_TILE_VERT:
2320 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2321 break;
2323 case ID_WINDOW_ARRANGE:
2324 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2325 break;
2327 case ID_SELECT_FONT:
2328 choose_font(hwnd);
2329 break;
2331 case ID_VIEW_TOOL_BAR:
2332 toggle_child(hwnd, cmd, Globals.htoolbar);
2333 break;
2335 case ID_VIEW_DRIVE_BAR:
2336 toggle_child(hwnd, cmd, Globals.hdrivebar);
2337 break;
2339 case ID_VIEW_STATUSBAR:
2340 toggle_child(hwnd, cmd, Globals.hstatusbar);
2341 break;
2343 case ID_VIEW_SAVESETTINGS:
2344 Globals.saveSettings = !Globals.saveSettings;
2345 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2346 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2347 break;
2349 case ID_EXECUTE: {
2350 struct ExecuteDialog dlg;
2352 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2354 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2355 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2357 if (PtrToUlong(hinst) <= 32)
2358 display_error(hwnd, GetLastError());
2360 break;}
2362 case ID_CONNECT_NETWORK_DRIVE: {
2363 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2364 if (ret == NO_ERROR)
2365 refresh_drives();
2366 else if (ret != (DWORD)-1) {
2367 if (ret == ERROR_EXTENDED_ERROR)
2368 display_network_error(hwnd);
2369 else
2370 display_error(hwnd, ret);
2372 break;}
2374 case ID_DISCONNECT_NETWORK_DRIVE: {
2375 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2376 if (ret == NO_ERROR)
2377 refresh_drives();
2378 else if (ret != (DWORD)-1) {
2379 if (ret == ERROR_EXTENDED_ERROR)
2380 display_network_error(hwnd);
2381 else
2382 display_error(hwnd, ret);
2384 break;}
2386 case ID_FORMAT_DISK: {
2387 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2388 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2389 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2390 SetErrorMode(sem_org); /* Put it back the way it was. */
2391 break;}
2393 case ID_HELP:
2394 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2395 break;
2397 #ifndef _NO_EXTENSIONS
2398 case ID_VIEW_FULLSCREEN:
2399 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2400 break;
2402 #ifdef __WINE__
2403 case ID_DRIVE_UNIX_FS: {
2404 TCHAR path[MAX_PATH];
2405 #ifdef UNICODE
2406 char cpath[MAX_PATH];
2407 #endif
2408 ChildWnd* child;
2410 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2411 break;
2413 #ifdef UNICODE
2414 getcwd(cpath, MAX_PATH);
2415 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2416 #else
2417 getcwd(path, MAX_PATH);
2418 #endif
2419 child = alloc_child_window(path, NULL, hwnd);
2421 if (!create_child_window(child))
2422 HeapFree(GetProcessHeap(), 0, child);
2423 break;}
2424 #endif
2425 #ifdef _SHELL_FOLDERS
2426 case ID_DRIVE_SHELL_NS: {
2427 TCHAR path[MAX_PATH];
2428 ChildWnd* child;
2430 if (activate_fs_window(RS(b1,IDS_SHELL)))
2431 break;
2433 GetCurrentDirectory(MAX_PATH, path);
2434 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2436 if (!create_child_window(child))
2437 HeapFree(GetProcessHeap(), 0, child);
2438 break;}
2439 #endif
2440 #endif
2442 /*TODO: There are even more menu items! */
2444 case ID_ABOUT:
2445 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL,
2446 LoadImage( Globals.hInstance, MAKEINTRESOURCE(IDI_WINEFILE),
2447 IMAGE_ICON, 48, 48, LR_SHARED ));
2448 break;
2450 default:
2451 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2452 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2453 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2454 (cmd<SC_SIZE || cmd>SC_RESTORE))
2455 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2457 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2459 break;}
2461 case WM_SIZE:
2462 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2463 break; /* do not pass message to DefFrameProc */
2465 case WM_DEVICECHANGE:
2466 SendMessage(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2467 break;
2469 #ifndef _NO_EXTENSIONS
2470 case WM_GETMINMAXINFO: {
2471 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2473 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2474 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2475 break;}
2477 case FRM_CALC_CLIENT:
2478 frame_get_clientspace(hwnd, (PRECT)lparam);
2479 return TRUE;
2480 #endif /* _NO_EXTENSIONS */
2482 default:
2483 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2486 return 0;
2490 static TCHAR g_pos_names[COLUMNS][20] = {
2491 {'\0'} /* symbol */
2494 static const int g_pos_align[] = {
2496 HDF_LEFT, /* Name */
2497 HDF_RIGHT, /* Size */
2498 HDF_LEFT, /* CDate */
2499 #ifndef _NO_EXTENSIONS
2500 HDF_LEFT, /* ADate */
2501 HDF_LEFT, /* MDate */
2502 HDF_LEFT, /* Index */
2503 HDF_CENTER, /* Links */
2504 #endif
2505 HDF_CENTER, /* Attributes */
2506 #ifndef _NO_EXTENSIONS
2507 HDF_LEFT /* Security */
2508 #endif
2511 static void resize_tree(ChildWnd* child, int cx, int cy)
2513 HDWP hdwp = BeginDeferWindowPos(4);
2514 RECT rt;
2516 rt.left = 0;
2517 rt.top = 0;
2518 rt.right = cx;
2519 rt.bottom = cy;
2521 cx = child->split_pos + SPLIT_WIDTH/2;
2523 #ifndef _NO_EXTENSIONS
2525 WINDOWPOS wp;
2526 HD_LAYOUT hdl;
2528 hdl.prc = &rt;
2529 hdl.pwpos = &wp;
2531 SendMessage(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2533 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2534 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2535 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2536 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2538 #endif /* _NO_EXTENSIONS */
2540 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);
2541 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2543 EndDeferWindowPos(hdwp);
2547 #ifndef _NO_EXTENSIONS
2549 static HWND create_header(HWND parent, Pane* pane, UINT id)
2551 HD_ITEM hdi;
2552 int idx;
2554 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2555 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2556 if (!hwnd)
2557 return 0;
2559 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2561 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2563 for(idx=0; idx<COLUMNS; idx++) {
2564 hdi.pszText = g_pos_names[idx];
2565 hdi.fmt = HDF_STRING | g_pos_align[idx];
2566 hdi.cxy = pane->widths[idx];
2567 SendMessage(hwnd, HDM_INSERTITEM, idx, (LPARAM) &hdi);
2570 return hwnd;
2573 #endif /* _NO_EXTENSIONS */
2576 static void init_output(HWND hwnd)
2578 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2579 WCHAR b[16];
2580 HFONT old_font;
2581 HDC hdc = GetDC(hwnd);
2583 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2584 Globals.num_sep = b[1];
2585 else
2586 Globals.num_sep = '.';
2588 old_font = SelectObject(hdc, Globals.hfont);
2589 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2590 SelectObject(hdc, old_font);
2591 ReleaseDC(hwnd, hdc);
2594 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2597 /* calculate preferred width for all visible columns */
2599 static BOOL calc_widths(Pane* pane, BOOL anyway)
2601 int col, x, cx, spc=3*Globals.spaceSize.cx;
2602 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2603 int orgWidths[COLUMNS];
2604 int orgPositions[COLUMNS+1];
2605 HFONT hfontOld;
2606 HDC hdc;
2607 int cnt;
2609 if (!anyway) {
2610 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2611 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2614 for(col=0; col<COLUMNS; col++)
2615 pane->widths[col] = 0;
2617 hdc = GetDC(pane->hwnd);
2618 hfontOld = SelectObject(hdc, Globals.hfont);
2620 for(cnt=0; cnt<entries; cnt++) {
2621 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2623 DRAWITEMSTRUCT dis;
2625 dis.CtlType = 0;
2626 dis.CtlID = 0;
2627 dis.itemID = 0;
2628 dis.itemAction = 0;
2629 dis.itemState = 0;
2630 dis.hwndItem = pane->hwnd;
2631 dis.hDC = hdc;
2632 dis.rcItem.left = 0;
2633 dis.rcItem.top = 0;
2634 dis.rcItem.right = 0;
2635 dis.rcItem.bottom = 0;
2636 /*dis.itemData = 0; */
2638 draw_item(pane, &dis, entry, COLUMNS);
2641 SelectObject(hdc, hfontOld);
2642 ReleaseDC(pane->hwnd, hdc);
2644 x = 0;
2645 for(col=0; col<COLUMNS; col++) {
2646 pane->positions[col] = x;
2647 cx = pane->widths[col];
2649 if (cx) {
2650 cx += spc;
2652 if (cx < IMAGE_WIDTH)
2653 cx = IMAGE_WIDTH;
2655 pane->widths[col] = cx;
2658 x += cx;
2661 pane->positions[COLUMNS] = x;
2663 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2665 /* no change? */
2666 if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2667 return FALSE;
2669 /* don't move, if only collapsing an entry */
2670 if (!anyway && pane->widths[0]<orgWidths[0] &&
2671 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2672 pane->widths[0] = orgWidths[0];
2673 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2675 return FALSE;
2678 InvalidateRect(pane->hwnd, 0, TRUE);
2680 return TRUE;
2684 /* calculate one preferred column width */
2686 static void calc_single_width(Pane* pane, int col)
2688 HFONT hfontOld;
2689 int x, cx;
2690 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2691 int cnt;
2692 HDC hdc;
2694 pane->widths[col] = 0;
2696 hdc = GetDC(pane->hwnd);
2697 hfontOld = SelectObject(hdc, Globals.hfont);
2699 for(cnt=0; cnt<entries; cnt++) {
2700 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2701 DRAWITEMSTRUCT dis;
2703 dis.CtlType = 0;
2704 dis.CtlID = 0;
2705 dis.itemID = 0;
2706 dis.itemAction = 0;
2707 dis.itemState = 0;
2708 dis.hwndItem = pane->hwnd;
2709 dis.hDC = hdc;
2710 dis.rcItem.left = 0;
2711 dis.rcItem.top = 0;
2712 dis.rcItem.right = 0;
2713 dis.rcItem.bottom = 0;
2714 /*dis.itemData = 0; */
2716 draw_item(pane, &dis, entry, col);
2719 SelectObject(hdc, hfontOld);
2720 ReleaseDC(pane->hwnd, hdc);
2722 cx = pane->widths[col];
2724 if (cx) {
2725 cx += 3*Globals.spaceSize.cx;
2727 if (cx < IMAGE_WIDTH)
2728 cx = IMAGE_WIDTH;
2731 pane->widths[col] = cx;
2733 x = pane->positions[col] + cx;
2735 for(; col<COLUMNS-1; ) {
2736 pane->positions[++col] = x;
2737 x += pane->widths[col];
2740 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2744 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2746 for( ; *str&&*pattern; str++,pattern++) {
2747 if (*pattern == '*') {
2748 do pattern++;
2749 while(*pattern == '*');
2751 if (!*pattern)
2752 return TRUE;
2754 for(; *str; str++)
2755 if (*str==*pattern && pattern_match(str, pattern))
2756 return TRUE;
2758 return FALSE;
2760 else if (*str!=*pattern && *pattern!='?')
2761 return FALSE;
2764 if (*str || *pattern)
2765 if (*pattern!='*' || pattern[1]!='\0')
2766 return FALSE;
2768 return TRUE;
2771 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2773 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2775 lstrcpy(b1, str);
2776 lstrcpy(b2, pattern);
2777 CharUpper(b1);
2778 CharUpper(b2);
2780 return pattern_match(b1, b2);
2784 enum FILE_TYPE {
2785 FT_OTHER = 0,
2786 FT_EXECUTABLE = 1,
2787 FT_DOCUMENT = 2
2790 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2793 /* insert listbox entries after index idx */
2795 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2797 Entry* entry = dir;
2799 if (!entry)
2800 return idx;
2802 ShowWindow(pane->hwnd, SW_HIDE);
2804 for(; entry; entry=entry->next) {
2805 #ifndef _LEFT_FILES
2806 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2807 continue;
2808 #endif
2810 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2811 /* don't display entries "." and ".." in the left pane */
2812 if (pane->treePane && entry->data.cFileName[0] == '.')
2813 if (
2814 #ifndef _NO_EXTENSIONS
2815 entry->data.cFileName[1] == '\0' ||
2816 #endif
2817 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2818 continue;
2820 /* filter directories in right pane */
2821 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2822 continue;
2825 /* filter using the file name pattern */
2826 if (pattern)
2827 if (!pattern_imatch(entry->data.cFileName, pattern))
2828 continue;
2830 /* filter system and hidden files */
2831 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2832 continue;
2834 /* filter looking at the file type */
2835 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2836 switch(get_file_type(entry->data.cFileName)) {
2837 case FT_EXECUTABLE:
2838 if (!(filter_flags & TF_PROGRAMS))
2839 continue;
2840 break;
2842 case FT_DOCUMENT:
2843 if (!(filter_flags & TF_DOCUMENTS))
2844 continue;
2845 break;
2847 default: /* TF_OTHERS */
2848 if (!(filter_flags & TF_OTHERS))
2849 continue;
2852 if (idx != -1)
2853 idx++;
2855 SendMessage(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM) entry);
2857 if (pane->treePane && entry->expanded)
2858 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2861 ShowWindow(pane->hwnd, SW_SHOW);
2863 return idx;
2867 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2869 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2870 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2871 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2872 static const TCHAR sFmtB[] = {'%', 'u', 0};
2874 float fBytes = (float)bytes;
2876 if (bytes >= 1073741824) /* 1 GB */
2877 sprintfW(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2878 else if (bytes >= 1048576) /* 1 MB */
2879 sprintfW(buffer, sFmtMB, fBytes/1048576.f+.5f);
2880 else if (bytes >= 1024) /* 1 kB */
2881 sprintfW(buffer, sFmtkB, fBytes/1024.f+.5f);
2882 else
2883 sprintfW(buffer, sFmtB, (DWORD)bytes);
2886 static void set_space_status(void)
2888 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2889 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2891 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2892 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2893 format_bytes(b2, ulTotalBytes.QuadPart);
2894 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2895 } else
2896 lstrcpy(buffer, sQMarks);
2898 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2902 static WNDPROC g_orgTreeWndProc;
2904 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCTSTR pattern, int filter_flags)
2906 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2908 static int s_init = 0;
2909 Entry* entry = pane->root;
2911 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2912 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2913 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2915 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2916 g_orgTreeWndProc = (WNDPROC) SetWindowLongPtr(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2918 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2920 /* insert entries into listbox */
2921 if (entry)
2922 insert_entries(pane, entry, pattern, filter_flags, -1);
2924 /* calculate column widths */
2925 if (!s_init) {
2926 s_init = 1;
2927 init_output(pane->hwnd);
2930 calc_widths(pane, TRUE);
2932 #ifndef _NO_EXTENSIONS
2933 pane->hwndHeader = create_header(parent, pane, id_header);
2934 #endif
2938 static void InitChildWindow(ChildWnd* child)
2940 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2941 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2945 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2947 SYSTEMTIME systime;
2948 FILETIME lft;
2949 int len = 0;
2951 *buffer = '\0';
2953 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2954 return;
2956 if (!FileTimeToLocalFileTime(ft, &lft))
2957 {err: lstrcpy(buffer,sQMarks); return;}
2959 if (!FileTimeToSystemTime(&lft, &systime))
2960 goto err;
2962 if (visible_cols & COL_DATE) {
2963 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2964 if (!len)
2965 goto err;
2968 if (visible_cols & COL_TIME) {
2969 if (len)
2970 buffer[len-1] = ' ';
2972 buffer[len++] = ' ';
2974 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2975 buffer[len] = '\0';
2980 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2982 RECT rt = {0, 0, 0, 0};
2984 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2986 if (rt.right > pane->widths[col])
2987 pane->widths[col] = rt.right;
2990 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
2992 RECT rt = {0, 0, 0, 0};
2994 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2995 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2997 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2998 /*FIXME rt (0,0) ??? */
3000 if (rt.right > pane->widths[col])
3001 pane->widths[col] = rt.right;
3005 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
3007 int x = dis->rcItem.left;
3008 RECT rt;
3010 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3011 rt.top = dis->rcItem.top;
3012 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3013 rt.bottom = dis->rcItem.bottom;
3015 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
3018 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3020 int x = dis->rcItem.left;
3021 RECT rt;
3023 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3024 rt.top = dis->rcItem.top;
3025 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3026 rt.bottom = dis->rcItem.bottom;
3028 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3029 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3031 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3034 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3036 int x = dis->rcItem.left;
3037 RECT rt;
3038 LPCTSTR s = str;
3039 TCHAR b[128];
3040 LPTSTR d = b;
3041 int pos;
3043 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3044 rt.top = dis->rcItem.top;
3045 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3046 rt.bottom = dis->rcItem.bottom;
3048 if (*s)
3049 *d++ = *s++;
3051 /* insert number separator characters */
3052 pos = lstrlen(s) % 3;
3054 while(*s)
3055 if (pos--)
3056 *d++ = *s++;
3057 else {
3058 *d++ = Globals.num_sep;
3059 pos = 3;
3062 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3066 static BOOL is_exe_file(LPCTSTR ext)
3068 static const TCHAR executable_extensions[][4] = {
3069 {'C','O','M','\0'},
3070 {'E','X','E','\0'},
3071 {'B','A','T','\0'},
3072 {'C','M','D','\0'},
3073 #ifndef _NO_EXTENSIONS
3074 {'C','M','M','\0'},
3075 {'B','T','M','\0'},
3076 {'A','W','K','\0'},
3077 #endif /* _NO_EXTENSIONS */
3078 {'\0'}
3081 TCHAR ext_buffer[_MAX_EXT];
3082 const TCHAR (*p)[4];
3083 LPCTSTR s;
3084 LPTSTR d;
3086 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3087 d++;
3089 for(p=executable_extensions; (*p)[0]; p++)
3090 if (!lstrcmpi(ext_buffer, *p))
3091 return TRUE;
3093 return FALSE;
3096 static BOOL is_registered_type(LPCTSTR ext)
3098 /* check if there exists a classname for this file extension in the registry */
3099 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3100 return TRUE;
3102 return FALSE;
3105 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3107 LPCTSTR ext = strrchrW(filename, '.');
3108 if (!ext)
3109 ext = sEmpty;
3111 if (is_exe_file(ext))
3112 return FT_EXECUTABLE;
3113 else if (is_registered_type(ext))
3114 return FT_DOCUMENT;
3115 else
3116 return FT_OTHER;
3120 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3122 TCHAR buffer[BUFFER_LEN];
3123 DWORD attrs;
3124 int visible_cols = pane->visible_cols;
3125 COLORREF bkcolor, textcolor;
3126 RECT focusRect = dis->rcItem;
3127 HBRUSH hbrush;
3128 enum IMAGE img;
3129 int img_pos, cx;
3130 int col = 0;
3132 if (entry) {
3133 attrs = entry->data.dwFileAttributes;
3135 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3136 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3137 && entry->data.cFileName[2] == '\0')
3138 img = IMG_FOLDER_UP;
3139 #ifndef _NO_EXTENSIONS
3140 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3141 img = IMG_FOLDER_CUR;
3142 #endif
3143 else if (
3144 #ifdef _NO_EXTENSIONS
3145 entry->expanded ||
3146 #endif
3147 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3148 img = IMG_OPEN_FOLDER;
3149 else
3150 img = IMG_FOLDER;
3151 } else {
3152 switch(get_file_type(entry->data.cFileName)) {
3153 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3154 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3155 default: img = IMG_FILE;
3158 } else {
3159 attrs = 0;
3160 img = IMG_NONE;
3163 if (pane->treePane) {
3164 if (entry) {
3165 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3167 if (calcWidthCol == -1) {
3168 int x;
3169 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3170 Entry* up;
3171 RECT rt_clip;
3172 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3173 HRGN hrgn;
3175 rt_clip.left = dis->rcItem.left;
3176 rt_clip.top = dis->rcItem.top;
3177 rt_clip.right = dis->rcItem.left+pane->widths[col];
3178 rt_clip.bottom = dis->rcItem.bottom;
3180 hrgn = CreateRectRgnIndirect(&rt_clip);
3182 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3183 DeleteObject(hrgn_org);
3184 hrgn_org = 0;
3187 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3188 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3189 DeleteObject(hrgn);
3191 if ((up=entry->up) != NULL) {
3192 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3193 LineTo(dis->hDC, img_pos-2, y);
3195 x = img_pos - IMAGE_WIDTH/2;
3197 do {
3198 x -= IMAGE_WIDTH+TREE_LINE_DX;
3200 if (up->next
3201 #ifndef _LEFT_FILES
3202 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3203 #endif
3205 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3206 LineTo(dis->hDC, x, dis->rcItem.bottom);
3208 } while((up=up->up) != NULL);
3211 x = img_pos - IMAGE_WIDTH/2;
3213 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3214 LineTo(dis->hDC, x, y);
3216 if (entry->next
3217 #ifndef _LEFT_FILES
3218 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3219 #endif
3221 LineTo(dis->hDC, x, dis->rcItem.bottom);
3223 SelectClipRgn(dis->hDC, hrgn_org);
3224 if (hrgn_org) DeleteObject(hrgn_org);
3225 /* SelectObject(dis->hDC, holdPen); */
3226 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3227 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3229 if (right > pane->widths[col])
3230 pane->widths[col] = right;
3232 } else {
3233 img_pos = dis->rcItem.left;
3235 } else {
3236 img_pos = dis->rcItem.left;
3238 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3239 pane->widths[col] = IMAGE_WIDTH;
3242 if (calcWidthCol == -1) {
3243 focusRect.left = img_pos -2;
3245 #ifdef _NO_EXTENSIONS
3246 if (pane->treePane && entry) {
3247 RECT rt = {0};
3249 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3251 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3253 #else
3255 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3256 textcolor = COLOR_COMPRESSED;
3257 else
3258 #endif /* _NO_EXTENSIONS */
3259 textcolor = RGB(0,0,0);
3261 if (dis->itemState & ODS_FOCUS) {
3262 textcolor = RGB(255,255,255);
3263 bkcolor = COLOR_SELECTION;
3264 } else {
3265 bkcolor = RGB(255,255,255);
3268 hbrush = CreateSolidBrush(bkcolor);
3269 FillRect(dis->hDC, &focusRect, hbrush);
3270 DeleteObject(hbrush);
3272 SetBkMode(dis->hDC, TRANSPARENT);
3273 SetTextColor(dis->hDC, textcolor);
3275 cx = pane->widths[col];
3277 if (cx && img!=IMG_NONE) {
3278 if (cx > IMAGE_WIDTH)
3279 cx = IMAGE_WIDTH;
3281 #ifdef _SHELL_FOLDERS
3282 if (entry->hicon && entry->hicon!=(HICON)-1)
3283 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3284 else
3285 #endif
3286 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3287 img_pos, dis->rcItem.top, cx,
3288 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3292 if (!entry)
3293 return;
3295 #ifdef _NO_EXTENSIONS
3296 if (img >= IMG_FOLDER_UP)
3297 return;
3298 #endif
3300 col++;
3302 /* ouput file name */
3303 if (calcWidthCol == -1)
3304 output_text(pane, dis, col, entry->data.cFileName, 0);
3305 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3306 calc_width(pane, dis, col, entry->data.cFileName);
3308 col++;
3310 #ifdef _NO_EXTENSIONS
3311 if (!pane->treePane) {
3312 #endif
3314 /* display file size */
3315 if (visible_cols & COL_SIZE) {
3316 #ifdef _NO_EXTENSIONS
3317 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3318 #endif
3320 format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
3322 if (calcWidthCol == -1)
3323 output_number(pane, dis, col, buffer);
3324 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3325 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3328 col++;
3331 /* display file date */
3332 if (visible_cols & (COL_DATE|COL_TIME)) {
3333 #ifndef _NO_EXTENSIONS
3334 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3335 if (calcWidthCol == -1)
3336 output_text(pane, dis, col, buffer, 0);
3337 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3338 calc_width(pane, dis, col, buffer);
3339 col++;
3341 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3342 if (calcWidthCol == -1)
3343 output_text(pane, dis, col, buffer, 0);
3344 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3345 calc_width(pane, dis, col, buffer);
3346 col++;
3347 #endif /* _NO_EXTENSIONS */
3349 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3350 if (calcWidthCol == -1)
3351 output_text(pane, dis, col, buffer, 0);
3352 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3353 calc_width(pane, dis, col, buffer);
3354 col++;
3357 #ifndef _NO_EXTENSIONS
3358 if (entry->bhfi_valid) {
3359 if (visible_cols & COL_INDEX) {
3360 static const TCHAR fmtlow[] = {'%','X',0};
3361 static const TCHAR fmthigh[] = {'%','X','%','0','8','X',0};
3363 if (entry->bhfi.nFileIndexHigh)
3364 wsprintf(buffer, fmthigh,
3365 entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
3366 else
3367 wsprintf(buffer, fmtlow, entry->bhfi.nFileIndexLow );
3369 if (calcWidthCol == -1)
3370 output_text(pane, dis, col, buffer, DT_RIGHT);
3371 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3372 calc_width(pane, dis, col, buffer);
3374 col++;
3377 if (visible_cols & COL_LINKS) {
3378 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3380 if (calcWidthCol == -1)
3381 output_text(pane, dis, col, buffer, DT_CENTER);
3382 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3383 calc_width(pane, dis, col, buffer);
3385 col++;
3387 } else
3388 col += 2;
3389 #endif /* _NO_EXTENSIONS */
3391 /* show file attributes */
3392 if (visible_cols & COL_ATTRIBUTES) {
3393 #ifdef _NO_EXTENSIONS
3394 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3395 lstrcpy(buffer, s4Tabs);
3396 #else
3397 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3398 lstrcpy(buffer, s11Tabs);
3399 #endif
3401 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3402 else {
3403 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3404 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3405 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3406 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3407 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3408 #ifndef _NO_EXTENSIONS
3409 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3410 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3411 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3412 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3413 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3414 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3415 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3416 #endif /* _NO_EXTENSIONS */
3419 if (calcWidthCol == -1)
3420 output_tabbed_text(pane, dis, col, buffer);
3421 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3422 calc_tabbed_width(pane, dis, col, buffer);
3424 col++;
3427 /*TODO
3428 if (flags.security) {
3429 static const TCHAR sSecTabs[] = {
3430 ' ','\t',' ','\t',' ','\t',' ',
3431 ' ','\t',' ',
3432 ' ','\t',' ','\t',' ','\t',' ',
3433 ' ','\t',' ',
3434 ' ','\t',' ','\t',' ','\t',' ',
3435 '\0'
3438 DWORD rights = get_access_mask();
3440 lstrcpy(buffer, sSecTabs);
3442 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3443 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3444 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3445 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3446 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3447 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3448 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3449 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3450 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3451 if (rights & WRITE_DAC) buffer[22] = 'C';
3452 if (rights & WRITE_OWNER) buffer[24] = 'O';
3453 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3455 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3458 if (flags.description) {
3459 get_description(buffer);
3460 output_text(dis, col++, buffer, 0, psize);
3464 #ifdef _NO_EXTENSIONS
3467 /* draw focus frame */
3468 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3469 /* Currently [04/2000] Wine neither behaves exactly the same */
3470 /* way as WIN 95 nor like Windows NT... */
3471 HGDIOBJ lastBrush;
3472 HPEN lastPen;
3473 HPEN hpen;
3475 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3476 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3477 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3478 } else
3479 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3481 lastPen = SelectPen(dis->hDC, hpen);
3482 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3483 SetROP2(dis->hDC, R2_XORPEN);
3484 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3485 SelectObject(dis->hDC, lastBrush);
3486 SelectObject(dis->hDC, lastPen);
3487 DeleteObject(hpen);
3489 #endif /* _NO_EXTENSIONS */
3493 #ifdef _NO_EXTENSIONS
3495 static void draw_splitbar(HWND hwnd, int x)
3497 RECT rt;
3498 HDC hdc = GetDC(hwnd);
3500 GetClientRect(hwnd, &rt);
3502 rt.left = x - SPLIT_WIDTH/2;
3503 rt.right = x + SPLIT_WIDTH/2+1;
3505 InvertRect(hdc, &rt);
3507 ReleaseDC(hwnd, hdc);
3510 #endif /* _NO_EXTENSIONS */
3513 #ifndef _NO_EXTENSIONS
3515 static void set_header(Pane* pane)
3517 HD_ITEM item;
3518 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3519 int i=0, x=0;
3521 item.mask = HDI_WIDTH;
3522 item.cxy = 0;
3524 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3525 x += pane->widths[i];
3526 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3529 if (i < COLUMNS) {
3530 x += pane->widths[i];
3531 item.cxy = x - scroll_pos;
3532 SendMessage(pane->hwndHeader, HDM_SETITEM, i++, (LPARAM) &item);
3534 for(; i<COLUMNS; i++) {
3535 item.cxy = pane->widths[i];
3536 x += pane->widths[i];
3537 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3542 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3544 switch(pnmh->code) {
3545 case HDN_ITEMCHANGED: {
3546 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3547 int idx = phdn->iItem;
3548 int dx = phdn->pitem->cxy - pane->widths[idx];
3549 int i;
3551 RECT clnt;
3552 GetClientRect(pane->hwnd, &clnt);
3554 pane->widths[idx] += dx;
3556 for(i=idx; ++i<=COLUMNS; )
3557 pane->positions[i] += dx;
3560 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3561 RECT rt_scr;
3562 RECT rt_clip;
3564 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3565 rt_scr.top = 0;
3566 rt_scr.right = clnt.right;
3567 rt_scr.bottom = clnt.bottom;
3569 rt_clip.left = pane->positions[idx]-scroll_pos;
3570 rt_clip.top = 0;
3571 rt_clip.right = clnt.right;
3572 rt_clip.bottom = clnt.bottom;
3574 if (rt_scr.left < 0) rt_scr.left = 0;
3575 if (rt_clip.left < 0) rt_clip.left = 0;
3577 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3579 rt_clip.right = pane->positions[idx+1];
3580 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3582 if (pnmh->code == HDN_ENDTRACK) {
3583 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3585 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3586 set_header(pane);
3590 return FALSE;
3593 case HDN_DIVIDERDBLCLICK: {
3594 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3595 HD_ITEM item;
3597 calc_single_width(pane, phdn->iItem);
3598 item.mask = HDI_WIDTH;
3599 item.cxy = pane->widths[phdn->iItem];
3601 SendMessage(pane->hwndHeader, HDM_SETITEM, phdn->iItem, (LPARAM) &item);
3602 InvalidateRect(pane->hwnd, 0, TRUE);
3603 break;}
3606 return 0;
3609 #endif /* _NO_EXTENSIONS */
3612 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3614 TCHAR path[MAX_PATH];
3615 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3617 /* delete sub entries in left pane */
3618 for(;;) {
3619 LRESULT res = SendMessage(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3620 Entry* sub = (Entry*) res;
3622 if (res==LB_ERR || !sub || sub->level<=entry->level)
3623 break;
3625 SendMessage(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3628 /* empty right pane */
3629 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3631 /* release memory */
3632 free_entries(entry);
3634 /* read contents from disk */
3635 #ifdef _SHELL_FOLDERS
3636 if (entry->etype == ET_SHELL)
3638 read_directory(entry, NULL, child->sortOrder, hwnd);
3640 else
3641 #endif
3643 get_path(entry, path);
3644 read_directory(entry, path, child->sortOrder, hwnd);
3647 /* insert found entries in right pane */
3648 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3649 calc_widths(&child->right, FALSE);
3650 #ifndef _NO_EXTENSIONS
3651 set_header(&child->right);
3652 #endif
3654 child->header_wdths_ok = FALSE;
3656 SetCursor(old_cursor);
3660 /* expand a directory entry */
3662 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3664 int idx;
3665 Entry* p;
3667 if (!dir || dir->expanded || !dir->down)
3668 return FALSE;
3670 p = dir->down;
3672 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3673 p = p->next;
3675 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3676 p->data.cFileName[2]=='\0' && p->next)
3677 p = p->next;
3680 /* no subdirectories ? */
3681 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3682 return FALSE;
3684 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3686 dir->expanded = TRUE;
3688 /* insert entries in left pane */
3689 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3691 if (!child->header_wdths_ok) {
3692 if (calc_widths(&child->left, FALSE)) {
3693 #ifndef _NO_EXTENSIONS
3694 set_header(&child->left);
3695 #endif
3697 child->header_wdths_ok = TRUE;
3701 return TRUE;
3705 static void collapse_entry(Pane* pane, Entry* dir)
3707 int idx = SendMessage(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3709 ShowWindow(pane->hwnd, SW_HIDE);
3711 /* hide sub entries */
3712 for(;;) {
3713 LRESULT res = SendMessage(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3714 Entry* sub = (Entry*) res;
3716 if (res==LB_ERR || !sub || sub->level<=dir->level)
3717 break;
3719 SendMessage(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3722 dir->expanded = FALSE;
3724 ShowWindow(pane->hwnd, SW_SHOW);
3728 static void refresh_right_pane(ChildWnd* child)
3730 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3731 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3732 calc_widths(&child->right, FALSE);
3734 #ifndef _NO_EXTENSIONS
3735 set_header(&child->right);
3736 #endif
3739 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3741 TCHAR path[MAX_PATH];
3743 if (!entry)
3744 return;
3746 path[0] = '\0';
3748 child->left.cur = entry;
3750 child->right.root = entry->down? entry->down: entry;
3751 child->right.cur = entry;
3753 if (!entry->scanned)
3754 scan_entry(child, entry, idx, hwnd);
3755 else
3756 refresh_right_pane(child);
3758 get_path(entry, path);
3759 lstrcpy(child->path, path);
3761 if (child->hwnd) /* only change window title, if the window already exists */
3762 SetWindowText(child->hwnd, path);
3764 if (path[0])
3765 if (SetCurrentDirectory(path))
3766 set_space_status();
3770 static void refresh_child(ChildWnd* child)
3772 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3773 Entry* entry;
3774 int idx;
3776 get_path(child->left.cur, path);
3777 _tsplitpath(path, drv, NULL, NULL, NULL);
3779 child->right.root = NULL;
3781 scan_entry(child, &child->root.entry, 0, child->hwnd);
3783 #ifdef _SHELL_FOLDERS
3785 if (child->root.entry.etype == ET_SHELL)
3787 LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
3788 if (local_pidl)
3789 entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
3790 else
3791 entry = NULL;
3793 else
3794 #endif
3795 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3797 if (!entry)
3798 entry = &child->root.entry;
3800 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3802 set_curdir(child, entry, 0, child->hwnd);
3804 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3805 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
3809 static void create_drive_bar(void)
3811 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3812 #ifndef _NO_EXTENSIONS
3813 TCHAR b1[BUFFER_LEN];
3814 #endif
3815 int btn = 1;
3816 PTSTR p;
3818 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3820 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3821 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3822 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3824 #ifndef _NO_EXTENSIONS
3825 #ifdef __WINE__
3826 /* insert unix file system button */
3827 b1[0] = '/';
3828 b1[1] = '\0';
3829 b1[2] = '\0';
3830 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3832 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3833 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3834 drivebarBtn.iString++;
3835 #endif
3836 #ifdef _SHELL_FOLDERS
3837 /* insert shell namespace button */
3838 load_string(b1, sizeof(b1)/sizeof(b1[0]), IDS_SHELL);
3839 b1[lstrlen(b1)+1] = '\0';
3840 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3842 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3843 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3844 drivebarBtn.iString++;
3845 #endif
3847 /* register windows drive root strings */
3848 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3849 #endif
3851 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3853 for(p=Globals.drives; *p; ) {
3854 #ifdef _NO_EXTENSIONS
3855 /* insert drive letter */
3856 TCHAR b[3] = {tolower(*p)};
3857 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3858 #endif
3859 switch(GetDriveType(p)) {
3860 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3861 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3862 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3863 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3864 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3867 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3868 drivebarBtn.idCommand++;
3869 drivebarBtn.iString++;
3871 while(*p++);
3875 static void refresh_drives(void)
3877 RECT rect;
3879 /* destroy drive bar */
3880 DestroyWindow(Globals.hdrivebar);
3881 Globals.hdrivebar = 0;
3883 /* re-create drive bar */
3884 create_drive_bar();
3886 /* update window layout */
3887 GetClientRect(Globals.hMainWnd, &rect);
3888 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3892 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3894 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3896 if (PtrToUlong(hinst) <= 32) {
3897 display_error(hwnd, GetLastError());
3898 return FALSE;
3901 return TRUE;
3905 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3907 TCHAR cmd[MAX_PATH];
3909 #ifdef _SHELL_FOLDERS
3910 if (entry->etype == ET_SHELL) {
3911 BOOL ret = TRUE;
3913 SHELLEXECUTEINFO shexinfo;
3915 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3916 shexinfo.fMask = SEE_MASK_IDLIST;
3917 shexinfo.hwnd = hwnd;
3918 shexinfo.lpVerb = NULL;
3919 shexinfo.lpFile = NULL;
3920 shexinfo.lpParameters = NULL;
3921 shexinfo.lpDirectory = NULL;
3922 shexinfo.nShow = nCmdShow;
3923 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3925 if (!ShellExecuteEx(&shexinfo)) {
3926 display_error(hwnd, GetLastError());
3927 ret = FALSE;
3930 if (shexinfo.lpIDList != entry->pidl)
3931 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3933 return ret;
3935 #endif
3937 get_path(entry, cmd);
3939 /* start program, open document... */
3940 return launch_file(hwnd, cmd, nCmdShow);
3944 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3946 Entry* entry = pane->cur;
3948 if (!entry)
3949 return;
3951 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3952 int scanned_old = entry->scanned;
3954 if (!scanned_old)
3956 int idx = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
3957 scan_entry(child, entry, idx, hwnd);
3960 #ifndef _NO_EXTENSIONS
3961 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3962 return;
3963 #endif
3965 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3966 entry = child->left.cur->up;
3967 collapse_entry(&child->left, entry);
3968 goto focus_entry;
3969 } else if (entry->expanded)
3970 collapse_entry(pane, child->left.cur);
3971 else {
3972 expand_entry(child, child->left.cur);
3974 if (!pane->treePane) focus_entry: {
3975 int idxstart = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
3976 int idx = SendMessage(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
3977 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
3978 set_curdir(child, entry, idx, hwnd);
3982 if (!scanned_old) {
3983 calc_widths(pane, FALSE);
3985 #ifndef _NO_EXTENSIONS
3986 set_header(pane);
3987 #endif
3989 } else {
3990 if (GetKeyState(VK_MENU) < 0)
3991 show_properties_dlg(entry, child->hwnd);
3992 else
3993 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3998 static BOOL pane_command(Pane* pane, UINT cmd)
4000 switch(cmd) {
4001 case ID_VIEW_NAME:
4002 if (pane->visible_cols) {
4003 pane->visible_cols = 0;
4004 calc_widths(pane, TRUE);
4005 #ifndef _NO_EXTENSIONS
4006 set_header(pane);
4007 #endif
4008 InvalidateRect(pane->hwnd, 0, TRUE);
4009 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
4010 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
4011 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4013 break;
4015 case ID_VIEW_ALL_ATTRIBUTES:
4016 if (pane->visible_cols != COL_ALL) {
4017 pane->visible_cols = COL_ALL;
4018 calc_widths(pane, TRUE);
4019 #ifndef _NO_EXTENSIONS
4020 set_header(pane);
4021 #endif
4022 InvalidateRect(pane->hwnd, 0, TRUE);
4023 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
4024 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
4025 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4027 break;
4029 #ifndef _NO_EXTENSIONS
4030 case ID_PREFERRED_SIZES: {
4031 calc_widths(pane, TRUE);
4032 set_header(pane);
4033 InvalidateRect(pane->hwnd, 0, TRUE);
4034 break;}
4035 #endif
4037 /* TODO: more command ids... */
4039 default:
4040 return FALSE;
4043 return TRUE;
4047 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
4049 if (child->sortOrder != sortOrder) {
4050 child->sortOrder = sortOrder;
4051 refresh_child(child);
4055 static void update_view_menu(ChildWnd* child)
4057 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4058 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4059 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4060 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4064 static BOOL is_directory(LPCTSTR target)
4066 /*TODO correctly handle UNIX paths */
4067 DWORD target_attr = GetFileAttributes(target);
4069 if (target_attr == INVALID_FILE_ATTRIBUTES)
4070 return FALSE;
4072 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4075 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4077 TCHAR path[MAX_PATH];
4078 int len;
4080 get_path(pane->cur, path);
4082 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4083 return FALSE;
4085 get_path(pane->cur, source);
4087 /* convert relative targets to absolute paths */
4088 if (path[0]!='/' && path[1]!=':') {
4089 get_path(pane->cur->up, target);
4090 len = lstrlen(target);
4092 if (target[len-1]!='\\' && target[len-1]!='/')
4093 target[len++] = '/';
4095 lstrcpy(target+len, path);
4096 } else
4097 lstrcpy(target, path);
4099 /* If the target already exists as directory, create a new target below this. */
4100 if (is_directory(path)) {
4101 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4102 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4104 _tsplitpath(source, NULL, NULL, fname, ext);
4106 wsprintf(target, sAppend, path, fname, ext);
4109 return TRUE;
4113 static IContextMenu2* s_pctxmenu2 = NULL;
4114 static IContextMenu3* s_pctxmenu3 = NULL;
4116 static void CtxMenu_reset(void)
4118 s_pctxmenu2 = NULL;
4119 s_pctxmenu3 = NULL;
4122 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4124 IContextMenu* pcm = NULL;
4126 CtxMenu_reset();
4128 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4129 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4130 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4131 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4133 if (pcm) {
4134 IContextMenu_Release(pcm1);
4135 return pcm;
4136 } else
4137 return pcm1;
4140 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4142 if (s_pctxmenu3) {
4143 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4144 return TRUE;
4147 if (s_pctxmenu2)
4148 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4149 return TRUE;
4151 return FALSE;
4155 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4157 IContextMenu* pcm;
4158 BOOL executed = FALSE;
4160 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4161 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4163 if (SUCCEEDED(hr)) {
4164 HMENU hmenu = CreatePopupMenu();
4166 pcm = CtxMenu_query_interfaces(pcm);
4168 if (hmenu) {
4169 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4171 if (SUCCEEDED(hr)) {
4172 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4174 CtxMenu_reset();
4176 if (idCmd) {
4177 CMINVOKECOMMANDINFO cmi;
4179 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4180 cmi.fMask = 0;
4181 cmi.hwnd = hwndParent;
4182 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4183 cmi.lpParameters = NULL;
4184 cmi.lpDirectory = NULL;
4185 cmi.nShow = SW_SHOWNORMAL;
4186 cmi.dwHotKey = 0;
4187 cmi.hIcon = 0;
4189 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4190 executed = TRUE;
4192 } else
4193 CtxMenu_reset();
4196 IContextMenu_Release(pcm);
4199 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4203 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4205 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4206 ASSERT(child);
4208 switch(nmsg) {
4209 case WM_DRAWITEM: {
4210 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4211 Entry* entry = (Entry*) dis->itemData;
4213 if (dis->CtlID == IDW_TREE_LEFT)
4214 draw_item(&child->left, dis, entry, -1);
4215 else if (dis->CtlID == IDW_TREE_RIGHT)
4216 draw_item(&child->right, dis, entry, -1);
4217 else
4218 goto draw_menu_item;
4220 return TRUE;}
4222 case WM_CREATE:
4223 InitChildWindow(child);
4224 break;
4226 case WM_NCDESTROY:
4227 free_child_window(child);
4228 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4229 break;
4231 case WM_PAINT: {
4232 PAINTSTRUCT ps;
4233 HBRUSH lastBrush;
4234 RECT rt;
4235 GetClientRect(hwnd, &rt);
4236 BeginPaint(hwnd, &ps);
4237 rt.left = child->split_pos-SPLIT_WIDTH/2;
4238 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4239 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4240 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4241 SelectObject(ps.hdc, lastBrush);
4242 #ifdef _NO_EXTENSIONS
4243 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4244 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4245 #endif
4246 EndPaint(hwnd, &ps);
4247 break;}
4249 case WM_SETCURSOR:
4250 if (LOWORD(lparam) == HTCLIENT) {
4251 POINT pt;
4252 GetCursorPos(&pt);
4253 ScreenToClient(hwnd, &pt);
4255 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4256 SetCursor(LoadCursor(0, IDC_SIZEWE));
4257 return TRUE;
4260 goto def;
4262 case WM_LBUTTONDOWN: {
4263 RECT rt;
4264 int x = (short)LOWORD(lparam);
4266 GetClientRect(hwnd, &rt);
4268 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4269 last_split = child->split_pos;
4270 #ifdef _NO_EXTENSIONS
4271 draw_splitbar(hwnd, last_split);
4272 #endif
4273 SetCapture(hwnd);
4276 break;}
4278 case WM_LBUTTONUP:
4279 if (GetCapture() == hwnd) {
4280 #ifdef _NO_EXTENSIONS
4281 RECT rt;
4282 int x = (short)LOWORD(lparam);
4283 draw_splitbar(hwnd, last_split);
4284 last_split = -1;
4285 GetClientRect(hwnd, &rt);
4286 child->split_pos = x;
4287 resize_tree(child, rt.right, rt.bottom);
4288 #endif
4289 ReleaseCapture();
4291 break;
4293 #ifdef _NO_EXTENSIONS
4294 case WM_CAPTURECHANGED:
4295 if (GetCapture()==hwnd && last_split>=0)
4296 draw_splitbar(hwnd, last_split);
4297 break;
4298 #endif
4300 case WM_KEYDOWN:
4301 if (wparam == VK_ESCAPE)
4302 if (GetCapture() == hwnd) {
4303 RECT rt;
4304 #ifdef _NO_EXTENSIONS
4305 draw_splitbar(hwnd, last_split);
4306 #else
4307 child->split_pos = last_split;
4308 #endif
4309 GetClientRect(hwnd, &rt);
4310 resize_tree(child, rt.right, rt.bottom);
4311 last_split = -1;
4312 ReleaseCapture();
4313 SetCursor(LoadCursor(0, IDC_ARROW));
4315 break;
4317 case WM_MOUSEMOVE:
4318 if (GetCapture() == hwnd) {
4319 RECT rt;
4320 int x = (short)LOWORD(lparam);
4322 #ifdef _NO_EXTENSIONS
4323 HDC hdc = GetDC(hwnd);
4324 GetClientRect(hwnd, &rt);
4326 rt.left = last_split-SPLIT_WIDTH/2;
4327 rt.right = last_split+SPLIT_WIDTH/2+1;
4328 InvertRect(hdc, &rt);
4330 last_split = x;
4331 rt.left = x-SPLIT_WIDTH/2;
4332 rt.right = x+SPLIT_WIDTH/2+1;
4333 InvertRect(hdc, &rt);
4335 ReleaseDC(hwnd, hdc);
4336 #else
4337 GetClientRect(hwnd, &rt);
4339 if (x>=0 && x<rt.right) {
4340 child->split_pos = x;
4341 resize_tree(child, rt.right, rt.bottom);
4342 rt.left = x-SPLIT_WIDTH/2;
4343 rt.right = x+SPLIT_WIDTH/2+1;
4344 InvalidateRect(hwnd, &rt, FALSE);
4345 UpdateWindow(child->left.hwnd);
4346 UpdateWindow(hwnd);
4347 UpdateWindow(child->right.hwnd);
4349 #endif
4351 break;
4353 #ifndef _NO_EXTENSIONS
4354 case WM_GETMINMAXINFO:
4355 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4357 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4359 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4360 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4361 break;}
4362 #endif /* _NO_EXTENSIONS */
4364 case WM_SETFOCUS:
4365 if (SetCurrentDirectory(child->path))
4366 set_space_status();
4367 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4368 break;
4370 case WM_DISPATCH_COMMAND: {
4371 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4373 switch(LOWORD(wparam)) {
4374 case ID_WINDOW_NEW: {
4375 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4377 if (!create_child_window(new_child))
4378 HeapFree(GetProcessHeap(), 0, new_child);
4380 break;}
4382 case ID_REFRESH:
4383 refresh_drives();
4384 refresh_child(child);
4385 break;
4387 case ID_ACTIVATE:
4388 activate_entry(child, pane, hwnd);
4389 break;
4391 case ID_FILE_MOVE: {
4392 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4394 if (prompt_target(pane, source, target)) {
4395 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4397 source[lstrlen(source)+1] = '\0';
4398 target[lstrlen(target)+1] = '\0';
4400 if (!SHFileOperation(&shfo))
4401 refresh_child(child);
4403 break;}
4405 case ID_FILE_COPY: {
4406 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4408 if (prompt_target(pane, source, target)) {
4409 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4411 source[lstrlen(source)+1] = '\0';
4412 target[lstrlen(target)+1] = '\0';
4414 if (!SHFileOperation(&shfo))
4415 refresh_child(child);
4417 break;}
4419 case ID_FILE_DELETE: {
4420 TCHAR path[BUFFER_LEN];
4421 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
4423 get_path(pane->cur, path);
4425 path[lstrlen(path)+1] = '\0';
4427 if (!SHFileOperation(&shfo))
4428 refresh_child(child);
4429 break;}
4431 case ID_VIEW_SORT_NAME:
4432 set_sort_order(child, SORT_NAME);
4433 break;
4435 case ID_VIEW_SORT_TYPE:
4436 set_sort_order(child, SORT_EXT);
4437 break;
4439 case ID_VIEW_SORT_SIZE:
4440 set_sort_order(child, SORT_SIZE);
4441 break;
4443 case ID_VIEW_SORT_DATE:
4444 set_sort_order(child, SORT_DATE);
4445 break;
4447 case ID_VIEW_FILTER: {
4448 struct FilterDialog dlg;
4450 memset(&dlg, 0, sizeof(struct FilterDialog));
4451 lstrcpy(dlg.pattern, child->filter_pattern);
4452 dlg.flags = child->filter_flags;
4454 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4455 lstrcpy(child->filter_pattern, dlg.pattern);
4456 child->filter_flags = dlg.flags;
4457 refresh_right_pane(child);
4459 break;}
4461 case ID_VIEW_SPLIT: {
4462 last_split = child->split_pos;
4463 #ifdef _NO_EXTENSIONS
4464 draw_splitbar(hwnd, last_split);
4465 #endif
4466 SetCapture(hwnd);
4467 break;}
4469 case ID_EDIT_PROPERTIES:
4470 show_properties_dlg(pane->cur, child->hwnd);
4471 break;
4473 default:
4474 return pane_command(pane, LOWORD(wparam));
4477 return TRUE;}
4479 case WM_COMMAND: {
4480 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4482 switch(HIWORD(wparam)) {
4483 case LBN_SELCHANGE: {
4484 int idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4485 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4487 if (pane == &child->left)
4488 set_curdir(child, entry, idx, hwnd);
4489 else
4490 pane->cur = entry;
4491 break;}
4493 case LBN_DBLCLK:
4494 activate_entry(child, pane, hwnd);
4495 break;
4497 break;}
4499 #ifndef _NO_EXTENSIONS
4500 case WM_NOTIFY: {
4501 NMHDR* pnmh = (NMHDR*) lparam;
4502 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4503 #endif
4505 #ifdef _SHELL_FOLDERS
4506 case WM_CONTEXTMENU: {
4507 POINT pt, pt_clnt;
4508 Pane* pane;
4509 int idx;
4511 /* first select the current item in the listbox */
4512 HWND hpanel = (HWND) wparam;
4513 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4514 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4515 ScreenToClient(hpanel, &pt_clnt);
4516 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4517 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4519 /* now create the popup menu using shell namespace and IContextMenu */
4520 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4521 idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4523 if (idx != -1) {
4524 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4526 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4528 if (pidl_abs) {
4529 IShellFolder* parentFolder;
4530 LPCITEMIDLIST pidlLast;
4532 /* get and use the parent folder to display correct context menu in all cases */
4533 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4534 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4535 refresh_child(child);
4537 IShellFolder_Release(parentFolder);
4540 IMalloc_Free(Globals.iMalloc, pidl_abs);
4543 break;}
4544 #endif
4546 case WM_MEASUREITEM:
4547 draw_menu_item:
4548 if (!wparam) /* Is the message menu-related? */
4549 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4550 return TRUE;
4552 break;
4554 case WM_INITMENUPOPUP:
4555 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4556 return 0;
4558 update_view_menu(child);
4559 break;
4561 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4562 if (s_pctxmenu3) {
4563 LRESULT lResult = 0;
4565 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4567 return lResult;
4570 break;
4572 case WM_SIZE:
4573 if (wparam != SIZE_MINIMIZED)
4574 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4575 /* fall through */
4577 default: def:
4578 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4581 return 0;
4585 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4587 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4588 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4589 ASSERT(child);
4591 switch(nmsg) {
4592 #ifndef _NO_EXTENSIONS
4593 case WM_HSCROLL:
4594 set_header(pane);
4595 break;
4596 #endif
4598 case WM_SETFOCUS:
4599 child->focus_pane = pane==&child->right? 1: 0;
4600 SendMessage(hwnd, LB_SETSEL, TRUE, 1);
4601 /*TODO: check menu items */
4602 break;
4604 case WM_KEYDOWN:
4605 if (wparam == VK_TAB) {
4606 /*TODO: SetFocus(Globals.hdrivebar) */
4607 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4611 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4615 static void InitInstance(HINSTANCE hinstance)
4617 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4619 WNDCLASSEX wcFrame;
4620 WNDCLASS wcChild;
4621 ATOM hChildClass;
4622 int col;
4624 INITCOMMONCONTROLSEX icc = {
4625 sizeof(INITCOMMONCONTROLSEX),
4626 ICC_BAR_CLASSES
4629 HDC hdc = GetDC(0);
4631 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4633 InitCommonControlsEx(&icc);
4636 /* register frame window class */
4638 wcFrame.cbSize = sizeof(WNDCLASSEX);
4639 wcFrame.style = 0;
4640 wcFrame.lpfnWndProc = FrameWndProc;
4641 wcFrame.cbClsExtra = 0;
4642 wcFrame.cbWndExtra = 0;
4643 wcFrame.hInstance = hinstance;
4644 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4645 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4646 wcFrame.hbrBackground = 0;
4647 wcFrame.lpszMenuName = 0;
4648 wcFrame.lpszClassName = sWINEFILEFRAME;
4649 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4650 MAKEINTRESOURCE(IDI_WINEFILE),
4651 IMAGE_ICON,
4652 GetSystemMetrics(SM_CXSMICON),
4653 GetSystemMetrics(SM_CYSMICON),
4654 LR_SHARED);
4656 Globals.hframeClass = RegisterClassEx(&wcFrame);
4659 /* register tree windows class */
4661 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4662 wcChild.lpfnWndProc = ChildWndProc;
4663 wcChild.cbClsExtra = 0;
4664 wcChild.cbWndExtra = 0;
4665 wcChild.hInstance = hinstance;
4666 wcChild.hIcon = 0;
4667 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4668 wcChild.hbrBackground = 0;
4669 wcChild.lpszMenuName = 0;
4670 wcChild.lpszClassName = sWINEFILETREE;
4672 hChildClass = RegisterClass(&wcChild);
4675 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4677 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4679 ReleaseDC(0, hdc);
4681 Globals.hInstance = hinstance;
4683 #ifdef _SHELL_FOLDERS
4684 CoInitialize(NULL);
4685 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4686 SHGetDesktopFolder(&Globals.iDesktop);
4687 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4688 #endif
4690 /* load column strings */
4691 col = 1;
4693 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_NAME);
4694 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SIZE);
4695 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_CDATE);
4696 #ifndef _NO_EXTENSIONS
4697 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ADATE);
4698 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_MDATE);
4699 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_IDX);
4700 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_LINKS);
4701 #endif
4702 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ATTR);
4703 #ifndef _NO_EXTENSIONS
4704 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SEC);
4705 #endif
4709 static BOOL show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4711 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4713 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4714 ChildWnd* child;
4715 HMENU hMenuFrame, hMenuWindow;
4716 windowOptions opts;
4718 CLIENTCREATESTRUCT ccs;
4720 if (Globals.hMainWnd)
4721 return TRUE;
4723 opts = load_registry_settings();
4724 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4725 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4727 Globals.hMenuFrame = hMenuFrame;
4728 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4729 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4731 ccs.hWindowMenu = hMenuWindow;
4732 ccs.idFirstChild = IDW_FIRST_CHILD;
4735 /* create main window */
4736 Globals.hMainWnd = CreateWindowEx(0, MAKEINTRESOURCE(Globals.hframeClass), RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4737 opts.start_x, opts.start_y, opts.width, opts.height,
4738 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4741 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4742 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4743 0, 0, 0, 0,
4744 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4746 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4747 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4749 create_drive_bar();
4752 TBBUTTON toolbarBtns[] = {
4753 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4754 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4755 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4756 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4757 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4758 /*TODO
4759 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4760 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4761 */ };
4763 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4764 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4765 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4766 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4769 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4770 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4772 /* CreateStatusWindow does not accept WS_BORDER
4773 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4774 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4775 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4777 /*TODO: read paths from registry */
4779 if (!path || !*path) {
4780 GetCurrentDirectory(MAX_PATH, buffer);
4781 path = buffer;
4784 ShowWindow(Globals.hMainWnd, cmdshow);
4786 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4787 /* Shell Namespace as default: */
4788 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4789 #else
4790 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4791 #endif
4793 child->pos.showCmd = SW_SHOWMAXIMIZED;
4794 child->pos.rcNormalPosition.left = 0;
4795 child->pos.rcNormalPosition.top = 0;
4796 child->pos.rcNormalPosition.right = 320;
4797 child->pos.rcNormalPosition.bottom = 280;
4799 if (!create_child_window(child)) {
4800 HeapFree(GetProcessHeap(), 0, child);
4801 return FALSE;
4804 SetWindowPlacement(child->hwnd, &child->pos);
4806 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4808 Globals.prescan_node = FALSE;
4810 UpdateWindow(Globals.hMainWnd);
4812 if (child->hwnd && path && path[0])
4814 int index,count;
4815 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4816 TCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4818 memset(name,0,sizeof(name));
4819 memset(name,0,sizeof(ext));
4820 _tsplitpath(path, drv, dir, name, ext);
4821 if (name[0])
4823 count = SendMessage(child->right.hwnd, LB_GETCOUNT, 0, 0);
4824 lstrcpy(fullname,name);
4825 lstrcat(fullname,ext);
4827 for (index = 0; index < count; index ++)
4829 Entry* entry = (Entry*) SendMessage(child->right.hwnd, LB_GETITEMDATA, index, 0);
4830 if (lstrcmp(entry->data.cFileName,fullname)==0 ||
4831 lstrcmp(entry->data.cAlternateFileName,fullname)==0)
4833 SendMessage(child->right.hwnd, LB_SETCURSEL, index, 0);
4834 SetFocus(child->right.hwnd);
4835 break;
4840 return TRUE;
4843 static void ExitInstance(void)
4845 #ifdef _SHELL_FOLDERS
4846 IShellFolder_Release(Globals.iDesktop);
4847 IMalloc_Release(Globals.iMalloc);
4848 CoUninitialize();
4849 #endif
4851 DeleteObject(Globals.hfont);
4852 ImageList_Destroy(Globals.himl);
4855 #ifdef _NO_EXTENSIONS
4857 /* search for already running win[e]files */
4859 static int g_foundPrevInstance = 0;
4861 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4863 TCHAR cls[128];
4865 GetClassName(hwnd, cls, 128);
4867 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4868 g_foundPrevInstance++;
4869 return FALSE;
4872 return TRUE;
4875 /* search for window of given class name to allow only one running instance */
4876 static int find_window_class(LPCTSTR classname)
4878 EnumWindows(EnumWndProc, (LPARAM)classname);
4880 if (g_foundPrevInstance)
4881 return 1;
4883 return 0;
4886 #endif
4888 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4890 MSG msg;
4892 InitInstance(hinstance);
4894 if( !show_frame(0, cmdshow, path) )
4896 ExitInstance();
4897 return 1;
4900 while(GetMessage(&msg, 0, 0, 0)) {
4901 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4902 continue;
4904 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4905 continue;
4907 TranslateMessage(&msg);
4908 DispatchMessage(&msg);
4911 ExitInstance();
4913 return msg.wParam;
4917 #if defined(UNICODE) && defined(_MSC_VER)
4918 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4919 #else
4920 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4921 #endif
4923 #ifdef _NO_EXTENSIONS
4924 if (find_window_class(sWINEFILEFRAME))
4925 return 1;
4926 #endif
4928 #if defined(UNICODE) && !defined(_MSC_VER)
4929 { /* convert ANSI cmdline into WCS path string */
4930 TCHAR buffer[MAX_PATH];
4931 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4932 winefile_main(hinstance, cmdshow, buffer);
4934 #else
4935 winefile_main(hinstance, cmdshow, cmdline);
4936 #endif
4938 return 0;