oleacc: Add stub for AccessibleObjectFromPoint.
[wine/wine64.git] / programs / winefile / winefile.c
bloba49c2ab1929d7148bb4fb48958770ea5664042b6
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"
37 #ifdef _NO_EXTENSIONS
38 #undef _LEFT_FILES
39 #endif
41 #ifndef _MAX_PATH
42 #define _MAX_DRIVE 3
43 #define _MAX_FNAME 256
44 #define _MAX_DIR _MAX_FNAME
45 #define _MAX_EXT _MAX_FNAME
46 #define _MAX_PATH 260
47 #endif
49 #ifdef NONAMELESSUNION
50 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
51 #else
52 #define UNION_MEMBER(x) x
53 #endif
56 #ifdef _SHELL_FOLDERS
57 #define DEFAULT_SPLIT_POS 300
58 #else
59 #define DEFAULT_SPLIT_POS 200
60 #endif
62 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
63 'W','i','n','e','\\',
64 'W','i','n','e','F','i','l','e','\0'};
65 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
66 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
67 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
68 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
69 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
71 enum ENTRY_TYPE {
72 ET_WINDOWS,
73 ET_UNIX,
74 #ifdef _SHELL_FOLDERS
75 ET_SHELL
76 #endif
79 typedef struct _Entry {
80 struct _Entry* next;
81 struct _Entry* down;
82 struct _Entry* up;
84 BOOL expanded;
85 BOOL scanned;
86 int level;
88 WIN32_FIND_DATA data;
90 #ifndef _NO_EXTENSIONS
91 BY_HANDLE_FILE_INFORMATION bhfi;
92 BOOL bhfi_valid;
93 enum ENTRY_TYPE etype;
94 #endif
95 #ifdef _SHELL_FOLDERS
96 LPITEMIDLIST pidl;
97 IShellFolder* folder;
98 HICON hicon;
99 #endif
100 } Entry;
102 typedef struct {
103 Entry entry;
104 TCHAR path[MAX_PATH];
105 TCHAR volname[_MAX_FNAME];
106 TCHAR fs[_MAX_DIR];
107 DWORD drive_type;
108 DWORD fs_flags;
109 } Root;
111 enum COLUMN_FLAGS {
112 COL_SIZE = 0x01,
113 COL_DATE = 0x02,
114 COL_TIME = 0x04,
115 COL_ATTRIBUTES = 0x08,
116 COL_DOSNAMES = 0x10,
117 #ifdef _NO_EXTENSIONS
118 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
119 #else
120 COL_INDEX = 0x20,
121 COL_LINKS = 0x40,
122 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
123 #endif
126 typedef enum {
127 SORT_NAME,
128 SORT_EXT,
129 SORT_SIZE,
130 SORT_DATE
131 } SORT_ORDER;
133 typedef struct {
134 HWND hwnd;
135 #ifndef _NO_EXTENSIONS
136 HWND hwndHeader;
137 #endif
139 #ifndef _NO_EXTENSIONS
140 #define COLUMNS 10
141 #else
142 #define COLUMNS 5
143 #endif
144 int widths[COLUMNS];
145 int positions[COLUMNS+1];
147 BOOL treePane;
148 int visible_cols;
149 Entry* root;
150 Entry* cur;
151 } Pane;
153 typedef struct {
154 HWND hwnd;
155 Pane left;
156 Pane right;
157 int focus_pane; /* 0: left 1: right */
158 WINDOWPLACEMENT pos;
159 int split_pos;
160 BOOL header_wdths_ok;
162 TCHAR path[MAX_PATH];
163 TCHAR filter_pattern[MAX_PATH];
164 int filter_flags;
165 Root root;
167 SORT_ORDER sortOrder;
168 } ChildWnd;
172 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
173 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
174 static void refresh_child(ChildWnd* child);
175 static void refresh_drives(void);
176 static void get_path(Entry* dir, PTSTR path);
177 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
179 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
181 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
184 /* globals */
185 WINEFILE_GLOBALS Globals;
187 static int last_split;
189 /* some common string constants */
190 static const TCHAR sEmpty[] = {'\0'};
191 static const WCHAR sSpace[] = {' ', '\0'};
192 static const TCHAR sNumFmt[] = {'%','d','\0'};
193 static const TCHAR sQMarks[] = {'?','?','?','\0'};
195 /* window class names */
196 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
197 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
199 static const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
200 static const TCHAR sLongNumFmt[] = {'%','I','6','4','u','\0'};
203 /* load resource string */
204 static LPTSTR load_string(LPTSTR buffer, DWORD size, UINT id)
206 LoadString(Globals.hInstance, id, buffer, size);
207 return buffer;
210 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
213 /* display error message for the specified WIN32 error code */
214 static void display_error(HWND hwnd, DWORD error)
216 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
217 PTSTR msg;
219 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
220 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
221 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
222 else
223 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
225 LocalFree(msg);
229 /* display network error message using WNetGetLastError() */
230 static void display_network_error(HWND hwnd)
232 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
233 DWORD error;
235 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
236 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
239 static inline BOOL get_check(HWND hwnd, INT id)
241 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
244 static inline INT set_check(HWND hwnd, INT id, BOOL on)
246 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
249 static inline void choose_font(HWND hwnd)
251 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
252 CHOOSEFONTW chFont;
253 LOGFONTW lFont;
255 HDC hdc = GetDC(hwnd);
256 chFont.lStructSize = sizeof(CHOOSEFONT);
257 chFont.hwndOwner = hwnd;
258 chFont.hDC = NULL;
259 chFont.lpLogFont = &lFont;
260 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
261 chFont.rgbColors = RGB(0,0,0);
262 chFont.lCustData = 0;
263 chFont.lpfnHook = NULL;
264 chFont.lpTemplateName = NULL;
265 chFont.hInstance = Globals.hInstance;
266 chFont.lpszStyle = NULL;
267 chFont.nFontType = SIMULATED_FONTTYPE;
268 chFont.nSizeMin = 0;
269 chFont.nSizeMax = 24;
271 if (ChooseFontW(&chFont)) {
272 HWND childWnd;
273 HFONT hFontOld;
275 DeleteObject(Globals.hfont);
276 Globals.hfont = CreateFontIndirectW(&lFont);
277 hFontOld = SelectObject(hdc, Globals.hfont);
278 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
280 /* change font in all open child windows */
281 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
282 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
283 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
284 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
285 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
286 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
287 InvalidateRect(child->left.hwnd, NULL, TRUE);
288 InvalidateRect(child->right.hwnd, NULL, TRUE);
291 SelectObject(hdc, hFontOld);
293 else if (CommDlgExtendedError()) {
294 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
295 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
296 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
299 ReleaseDC(hwnd, hdc);
302 #ifdef __WINE__
304 #ifdef UNICODE
306 /* call vswprintf() in msvcrt.dll */
307 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
308 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
310 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
311 va_list ap;
312 int ret;
314 if (!pvswprintf) {
315 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
316 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
319 va_start(ap, fmt);
320 ret = (*pvswprintf)(buffer, fmt, ap);
321 va_end(ap);
323 return ret;
326 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
328 LPCWSTR p = str;
330 while(*p)
331 ++p;
333 do {
334 if (--p < str)
335 return NULL;
336 } while(*p != c);
338 return p;
341 #define _tcsrchr my_wcsrchr
342 #else /* UNICODE */
343 #define _tcsrchr strrchr
344 #endif /* UNICODE */
346 #endif /* __WINE__ */
349 /* allocate and initialise a directory entry */
350 static Entry* alloc_entry(void)
352 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
354 #ifdef _SHELL_FOLDERS
355 entry->pidl = NULL;
356 entry->folder = NULL;
357 entry->hicon = 0;
358 #endif
360 return entry;
363 /* free a directory entry */
364 static void free_entry(Entry* entry)
366 #ifdef _SHELL_FOLDERS
367 if (entry->hicon && entry->hicon!=(HICON)-1)
368 DestroyIcon(entry->hicon);
370 if (entry->folder && entry->folder!=Globals.iDesktop)
371 IShellFolder_Release(entry->folder);
373 if (entry->pidl)
374 IMalloc_Free(Globals.iMalloc, entry->pidl);
375 #endif
377 HeapFree(GetProcessHeap(), 0, entry);
380 /* recursively free all child entries */
381 static void free_entries(Entry* dir)
383 Entry *entry, *next=dir->down;
385 if (next) {
386 dir->down = 0;
388 do {
389 entry = next;
390 next = entry->next;
392 free_entries(entry);
393 free_entry(entry);
394 } while(next);
399 static void read_directory_win(Entry* dir, LPCTSTR path)
401 Entry* first_entry = NULL;
402 Entry* last = NULL;
403 Entry* entry;
405 int level = dir->level + 1;
406 WIN32_FIND_DATA w32fd;
407 HANDLE hFind;
408 #ifndef _NO_EXTENSIONS
409 HANDLE hFile;
410 #endif
412 TCHAR buffer[MAX_PATH], *p;
413 for(p=buffer; *path; )
414 *p++ = *path++;
416 *p++ = '\\';
417 p[0] = '*';
418 p[1] = '\0';
420 hFind = FindFirstFile(buffer, &w32fd);
422 if (hFind != INVALID_HANDLE_VALUE) {
423 do {
424 #ifdef _NO_EXTENSIONS
425 /* hide directory entry "." */
426 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
427 LPCTSTR name = w32fd.cFileName;
429 if (name[0]=='.' && name[1]=='\0')
430 continue;
432 #endif
433 entry = alloc_entry();
435 if (!first_entry)
436 first_entry = entry;
438 if (last)
439 last->next = entry;
441 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
442 entry->down = NULL;
443 entry->up = dir;
444 entry->expanded = FALSE;
445 entry->scanned = FALSE;
446 entry->level = level;
448 #ifndef _NO_EXTENSIONS
449 entry->etype = ET_WINDOWS;
450 entry->bhfi_valid = FALSE;
452 lstrcpy(p, entry->data.cFileName);
454 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
455 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
457 if (hFile != INVALID_HANDLE_VALUE) {
458 if (GetFileInformationByHandle(hFile, &entry->bhfi))
459 entry->bhfi_valid = TRUE;
461 CloseHandle(hFile);
463 #endif
465 last = entry;
466 } while(FindNextFile(hFind, &w32fd));
468 if (last)
469 last->next = NULL;
471 FindClose(hFind);
474 dir->down = first_entry;
475 dir->scanned = TRUE;
479 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
481 Entry* entry;
483 for(entry=dir->down; entry; entry=entry->next) {
484 LPCTSTR p = name;
485 LPCTSTR q = entry->data.cFileName;
487 do {
488 if (!*p || *p == '\\' || *p == '/')
489 return entry;
490 } while(tolower(*p++) == tolower(*q++));
492 p = name;
493 q = entry->data.cAlternateFileName;
495 do {
496 if (!*p || *p == '\\' || *p == '/')
497 return entry;
498 } while(tolower(*p++) == tolower(*q++));
501 return 0;
505 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
507 TCHAR buffer[MAX_PATH];
508 Entry* entry = &root->entry;
509 LPCTSTR s = path;
510 PTSTR d = buffer;
512 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
514 #ifndef _NO_EXTENSIONS
515 entry->etype = ET_WINDOWS;
516 #endif
518 while(entry) {
519 while(*s && *s != '\\' && *s != '/')
520 *d++ = *s++;
522 while(*s == '\\' || *s == '/')
523 s++;
525 *d++ = '\\';
526 *d = '\0';
528 read_directory(entry, buffer, sortOrder, hwnd);
530 if (entry->down)
531 entry->expanded = TRUE;
533 if (!*s)
534 break;
536 entry = find_entry_win(entry, s);
539 SetCursor(old_cursor);
541 return entry;
545 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
547 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
549 struct tm* tm = gmtime(t);
550 SYSTEMTIME stime;
552 if (!tm)
553 return FALSE;
555 stime.wYear = tm->tm_year+1900;
556 stime.wMonth = tm->tm_mon+1;
557 /* stime.wDayOfWeek */
558 stime.wDay = tm->tm_mday;
559 stime.wHour = tm->tm_hour;
560 stime.wMinute = tm->tm_min;
561 stime.wSecond = tm->tm_sec;
563 return SystemTimeToFileTime(&stime, ftime);
566 static void read_directory_unix(Entry* dir, LPCTSTR path)
568 Entry* first_entry = NULL;
569 Entry* last = NULL;
570 Entry* entry;
571 DIR* pdir;
573 int level = dir->level + 1;
574 #ifdef UNICODE
575 char cpath[MAX_PATH];
577 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
578 #else
579 const char* cpath = path;
580 #endif
582 pdir = opendir(cpath);
584 if (pdir) {
585 struct stat st;
586 struct dirent* ent;
587 char buffer[MAX_PATH], *p;
588 const char* s;
590 for(p=buffer,s=cpath; *s; )
591 *p++ = *s++;
593 if (p==buffer || p[-1]!='/')
594 *p++ = '/';
596 while((ent=readdir(pdir))) {
597 entry = alloc_entry();
599 if (!first_entry)
600 first_entry = entry;
602 if (last)
603 last->next = entry;
605 entry->etype = ET_UNIX;
607 strcpy(p, ent->d_name);
608 #ifdef UNICODE
609 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
610 #else
611 lstrcpy(entry->data.cFileName, p);
612 #endif
614 if (!stat(buffer, &st)) {
615 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
617 if (S_ISDIR(st.st_mode))
618 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
620 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
621 entry->data.nFileSizeHigh = st.st_size >> 32;
623 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
624 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
625 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
627 entry->bhfi.nFileIndexLow = ent->d_ino;
628 entry->bhfi.nFileIndexHigh = 0;
630 entry->bhfi.nNumberOfLinks = st.st_nlink;
632 entry->bhfi_valid = TRUE;
633 } else {
634 entry->data.nFileSizeLow = 0;
635 entry->data.nFileSizeHigh = 0;
636 entry->bhfi_valid = FALSE;
639 entry->down = NULL;
640 entry->up = dir;
641 entry->expanded = FALSE;
642 entry->scanned = FALSE;
643 entry->level = level;
645 last = entry;
648 if (last)
649 last->next = NULL;
651 closedir(pdir);
654 dir->down = first_entry;
655 dir->scanned = TRUE;
658 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
660 Entry* entry;
662 for(entry=dir->down; entry; entry=entry->next) {
663 LPCTSTR p = name;
664 LPCTSTR q = entry->data.cFileName;
666 do {
667 if (!*p || *p == '/')
668 return entry;
669 } while(*p++ == *q++);
672 return 0;
675 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
677 TCHAR buffer[MAX_PATH];
678 Entry* entry = &root->entry;
679 LPCTSTR s = path;
680 PTSTR d = buffer;
682 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
684 entry->etype = ET_UNIX;
686 while(entry) {
687 while(*s && *s != '/')
688 *d++ = *s++;
690 while(*s == '/')
691 s++;
693 *d++ = '/';
694 *d = '\0';
696 read_directory(entry, buffer, sortOrder, hwnd);
698 if (entry->down)
699 entry->expanded = TRUE;
701 if (!*s)
702 break;
704 entry = find_entry_unix(entry, s);
707 SetCursor(old_cursor);
709 return entry;
712 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
715 #ifdef _SHELL_FOLDERS
717 #ifdef UNICODE
718 #define get_strret get_strretW
719 #define path_from_pidl path_from_pidlW
720 #else
721 #define get_strret get_strretA
722 #define path_from_pidl path_from_pidlA
723 #endif
726 static void free_strret(STRRET* str)
728 if (str->uType == STRRET_WSTR)
729 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
733 #ifndef UNICODE
735 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
737 LPCSTR s;
738 LPSTR d = dest;
740 for(s=source; count&&(*d++=*s++); )
741 count--;
743 return dest;
746 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
748 switch(str->uType) {
749 case STRRET_WSTR:
750 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
751 break;
753 case STRRET_OFFSET:
754 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
755 break;
757 case STRRET_CSTR:
758 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
762 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
764 STRRET str;
766 /* SHGDN_FORPARSING: get full path of id list */
767 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
769 if (SUCCEEDED(hr)) {
770 get_strretA(&str, &pidl->mkid, buffer, len);
771 free_strret(&str);
772 } else
773 buffer[0] = '\0';
775 return hr;
778 #endif
780 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
782 LPCWSTR s;
783 LPWSTR d = dest;
785 for(s=source; count&&(*d++=*s++); )
786 count--;
788 return dest;
791 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
793 switch(str->uType) {
794 case STRRET_WSTR:
795 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
796 break;
798 case STRRET_OFFSET:
799 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
800 break;
802 case STRRET_CSTR:
803 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
808 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
810 STRRET str;
812 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
814 if (SUCCEEDED(hr)) {
815 get_strret(&str, &pidl->mkid, buffer, len);
816 free_strret(&str);
817 } else
818 buffer[0] = '\0';
820 return hr;
824 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
826 STRRET str;
828 /* SHGDN_FORPARSING: get full path of id list */
829 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
831 if (SUCCEEDED(hr)) {
832 get_strretW(&str, &pidl->mkid, buffer, len);
833 free_strret(&str);
834 } else
835 buffer[0] = '\0';
837 return hr;
841 /* create an item id list from a file system path */
843 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
845 LPITEMIDLIST pidl;
846 HRESULT hr;
847 ULONG len;
849 #ifdef UNICODE
850 LPWSTR buffer = path;
851 #else
852 WCHAR buffer[MAX_PATH];
853 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
854 #endif
856 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
857 if (FAILED(hr))
858 return NULL;
860 return pidl;
864 /* convert an item id list from relative to absolute (=relative to the desktop) format */
866 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
868 if (entry->up && entry->up->etype==ET_SHELL) {
869 LPITEMIDLIST idl = NULL;
871 while (entry->up) {
872 idl = ILCombine(ILClone(entry->pidl), idl);
873 entry = entry->up;
876 return idl;
877 } else if (entry->etype == ET_WINDOWS) {
878 TCHAR path[MAX_PATH];
880 get_path(entry, path);
882 return get_path_pidl(path, hwnd);
883 } else if (entry->pidl)
884 return ILClone(entry->pidl);
886 return NULL;
890 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
892 IExtractIcon* pExtract;
894 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
895 TCHAR path[_MAX_PATH];
896 unsigned flags;
897 HICON hicon;
898 int idx;
900 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
901 if (!(flags & GIL_NOTFILENAME)) {
902 if (idx == -1)
903 idx = 0; /* special case for some control panel applications */
905 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
906 flags &= ~GIL_DONTCACHE;
907 } else {
908 HICON hIconLarge = 0;
910 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
912 if (SUCCEEDED(hr))
913 DestroyIcon(hIconLarge);
916 return hicon;
920 return 0;
924 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
926 Entry* entry;
928 for(entry=dir->down; entry; entry=entry->next) {
929 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
930 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
931 return entry;
934 return 0;
937 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
939 Entry* entry = &root->entry;
940 Entry* next;
941 LPITEMIDLIST next_pidl = pidl;
942 IShellFolder* folder;
943 IShellFolder* child = NULL;
944 HRESULT hr;
946 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
948 #ifndef _NO_EXTENSIONS
949 entry->etype = ET_SHELL;
950 #endif
952 folder = Globals.iDesktop;
954 while(entry) {
955 entry->pidl = next_pidl;
956 entry->folder = folder;
958 if (!pidl->mkid.cb)
959 break;
961 /* copy first element of item idlist */
962 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
963 memcpy(next_pidl, pidl, pidl->mkid.cb);
964 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
966 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
967 if (FAILED(hr))
968 break;
970 read_directory(entry, NULL, sortOrder, hwnd);
972 if (entry->down)
973 entry->expanded = TRUE;
975 next = find_entry_shell(entry, next_pidl);
976 if (!next)
977 break;
979 folder = child;
980 entry = next;
982 /* go to next element */
983 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
986 SetCursor(old_cursor);
988 return entry;
992 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
994 if (!(attribs & SFGAO_FILESYSTEM) ||
995 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
996 WIN32_FILE_ATTRIBUTE_DATA fad;
997 IDataObject* pDataObj;
999 STGMEDIUM medium = {0, {0}, 0};
1000 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
1002 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
1004 if (SUCCEEDED(hr)) {
1005 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
1007 IDataObject_Release(pDataObj);
1009 if (SUCCEEDED(hr)) {
1010 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
1011 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
1013 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
1014 w32fdata->dwFileAttributes = fad.dwFileAttributes;
1015 w32fdata->ftCreationTime = fad.ftCreationTime;
1016 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
1017 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
1019 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1020 w32fdata->nFileSizeLow = fad.nFileSizeLow;
1021 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
1025 SetErrorMode(sem_org);
1027 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
1028 GlobalFree(medium.UNION_MEMBER(hGlobal));
1033 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
1034 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1036 if (attribs & SFGAO_READONLY)
1037 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
1039 if (attribs & SFGAO_COMPRESSED)
1040 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
1044 static void read_directory_shell(Entry* dir, HWND hwnd)
1046 IShellFolder* folder = dir->folder;
1047 int level = dir->level + 1;
1048 HRESULT hr;
1050 IShellFolder* child;
1051 IEnumIDList* idlist;
1053 Entry* first_entry = NULL;
1054 Entry* last = NULL;
1055 Entry* entry;
1057 if (!folder)
1058 return;
1060 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1062 if (SUCCEEDED(hr)) {
1063 for(;;) {
1064 #define FETCH_ITEM_COUNT 32
1065 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1066 SFGAOF attribs;
1067 ULONG cnt = 0;
1068 ULONG n;
1070 memset(pidls, 0, sizeof(pidls));
1072 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1073 if (FAILED(hr))
1074 break;
1076 if (hr == S_FALSE)
1077 break;
1079 for(n=0; n<cnt; ++n) {
1080 entry = alloc_entry();
1082 if (!first_entry)
1083 first_entry = entry;
1085 if (last)
1086 last->next = entry;
1088 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1089 entry->bhfi_valid = FALSE;
1091 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1093 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1095 if (SUCCEEDED(hr)) {
1096 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1097 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1099 entry->bhfi_valid = TRUE;
1100 } else
1101 attribs = 0;
1102 } else
1103 attribs = 0;
1105 entry->pidl = pidls[n];
1107 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1108 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1110 if (SUCCEEDED(hr))
1111 entry->folder = child;
1112 else
1113 entry->folder = NULL;
1115 else
1116 entry->folder = NULL;
1118 if (!entry->data.cFileName[0])
1119 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1121 /* get display icons for files and virtual objects */
1122 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1123 !(attribs & SFGAO_FILESYSTEM)) {
1124 entry->hicon = extract_icon(folder, pidls[n]);
1126 if (!entry->hicon)
1127 entry->hicon = (HICON)-1; /* don't try again later */
1130 entry->down = NULL;
1131 entry->up = dir;
1132 entry->expanded = FALSE;
1133 entry->scanned = FALSE;
1134 entry->level = level;
1136 #ifndef _NO_EXTENSIONS
1137 entry->etype = ET_SHELL;
1138 entry->bhfi_valid = FALSE;
1139 #endif
1141 last = entry;
1145 IEnumIDList_Release(idlist);
1148 if (last)
1149 last->next = NULL;
1151 dir->down = first_entry;
1152 dir->scanned = TRUE;
1155 #endif /* _SHELL_FOLDERS */
1158 /* sort order for different directory/file types */
1159 enum TYPE_ORDER {
1160 TO_DIR = 0,
1161 TO_DOT = 1,
1162 TO_DOTDOT = 2,
1163 TO_OTHER_DIR = 3,
1164 TO_FILE = 4
1167 /* distinguish between ".", ".." and any other directory names */
1168 static int TypeOrderFromDirname(LPCTSTR name)
1170 if (name[0] == '.') {
1171 if (name[1] == '\0')
1172 return TO_DOT; /* "." */
1174 if (name[1]=='.' && name[2]=='\0')
1175 return TO_DOTDOT; /* ".." */
1178 return TO_OTHER_DIR; /* anything else */
1181 /* directories first... */
1182 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1184 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1185 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1187 /* Handle "." and ".." as special case and move them at the very first beginning. */
1188 if (order1==TO_DIR && order2==TO_DIR) {
1189 order1 = TypeOrderFromDirname(fd1->cFileName);
1190 order2 = TypeOrderFromDirname(fd2->cFileName);
1193 return order2==order1? 0: order1<order2? -1: 1;
1197 static int compareName(const void* arg1, const void* arg2)
1199 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1200 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1202 int cmp = compareType(fd1, fd2);
1203 if (cmp)
1204 return cmp;
1206 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1209 static int compareExt(const void* arg1, const void* arg2)
1211 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1212 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1213 const TCHAR *name1, *name2, *ext1, *ext2;
1215 int cmp = compareType(fd1, fd2);
1216 if (cmp)
1217 return cmp;
1219 name1 = fd1->cFileName;
1220 name2 = fd2->cFileName;
1222 ext1 = _tcsrchr(name1, '.');
1223 ext2 = _tcsrchr(name2, '.');
1225 if (ext1)
1226 ext1++;
1227 else
1228 ext1 = sEmpty;
1230 if (ext2)
1231 ext2++;
1232 else
1233 ext2 = sEmpty;
1235 cmp = lstrcmpi(ext1, ext2);
1236 if (cmp)
1237 return cmp;
1239 return lstrcmpi(name1, name2);
1242 static int compareSize(const void* arg1, const void* arg2)
1244 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1245 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1247 int cmp = compareType(fd1, fd2);
1248 if (cmp)
1249 return cmp;
1251 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1253 if (cmp < 0)
1254 return -1;
1255 else if (cmp > 0)
1256 return 1;
1258 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1260 return cmp<0? -1: cmp>0? 1: 0;
1263 static int compareDate(const void* arg1, const void* arg2)
1265 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1266 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1268 int cmp = compareType(fd1, fd2);
1269 if (cmp)
1270 return cmp;
1272 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1276 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1277 compareName, /* SORT_NAME */
1278 compareExt, /* SORT_EXT */
1279 compareSize, /* SORT_SIZE */
1280 compareDate /* SORT_DATE */
1284 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1286 Entry* entry = dir->down;
1287 Entry** array, **p;
1288 int len;
1290 len = 0;
1291 for(entry=dir->down; entry; entry=entry->next)
1292 len++;
1294 if (len) {
1295 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1297 p = array;
1298 for(entry=dir->down; entry; entry=entry->next)
1299 *p++ = entry;
1301 /* call qsort with the appropriate compare function */
1302 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1304 dir->down = array[0];
1306 for(p=array; --len; p++)
1307 p[0]->next = p[1];
1309 (*p)->next = 0;
1311 HeapFree(GetProcessHeap(), 0, array);
1316 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1318 TCHAR buffer[MAX_PATH];
1319 Entry* entry;
1320 LPCTSTR s;
1321 PTSTR d;
1323 #ifdef _SHELL_FOLDERS
1324 if (dir->etype == ET_SHELL)
1326 read_directory_shell(dir, hwnd);
1328 if (Globals.prescan_node) {
1329 s = path;
1330 d = buffer;
1332 while(*s)
1333 *d++ = *s++;
1335 *d++ = '\\';
1337 for(entry=dir->down; entry; entry=entry->next)
1338 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1339 read_directory_shell(entry, hwnd);
1340 SortDirectory(entry, sortOrder);
1344 else
1345 #endif
1346 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1347 if (dir->etype == ET_UNIX)
1349 read_directory_unix(dir, path);
1351 if (Globals.prescan_node) {
1352 s = path;
1353 d = buffer;
1355 while(*s)
1356 *d++ = *s++;
1358 *d++ = '/';
1360 for(entry=dir->down; entry; entry=entry->next)
1361 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1362 lstrcpy(d, entry->data.cFileName);
1363 read_directory_unix(entry, buffer);
1364 SortDirectory(entry, sortOrder);
1368 else
1369 #endif
1371 read_directory_win(dir, path);
1373 if (Globals.prescan_node) {
1374 s = path;
1375 d = buffer;
1377 while(*s)
1378 *d++ = *s++;
1380 *d++ = '\\';
1382 for(entry=dir->down; entry; entry=entry->next)
1383 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1384 lstrcpy(d, entry->data.cFileName);
1385 read_directory_win(entry, buffer);
1386 SortDirectory(entry, sortOrder);
1391 SortDirectory(dir, sortOrder);
1395 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1397 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1398 static const TCHAR sSlash[] = {'/', '\0'};
1399 #endif
1400 static const TCHAR sBackslash[] = {'\\', '\0'};
1402 #ifdef _SHELL_FOLDERS
1403 if (pidl)
1405 /* read shell namespace tree */
1406 root->drive_type = DRIVE_UNKNOWN;
1407 drv[0] = '\\';
1408 drv[1] = '\0';
1409 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_DESKTOP);
1410 root->fs_flags = 0;
1411 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_SHELL);
1413 return read_tree_shell(root, pidl, sortOrder, hwnd);
1415 else
1416 #endif
1417 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1418 if (*path == '/')
1420 /* read unix file system tree */
1421 root->drive_type = GetDriveType(path);
1423 lstrcat(drv, sSlash);
1424 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_ROOT_FS);
1425 root->fs_flags = 0;
1426 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_UNIXFS);
1428 lstrcpy(root->path, sSlash);
1430 return read_tree_unix(root, path, sortOrder, hwnd);
1432 #endif
1434 /* read WIN32 file system tree */
1435 root->drive_type = GetDriveType(path);
1437 lstrcat(drv, sBackslash);
1438 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1440 lstrcpy(root->path, drv);
1442 return read_tree_win(root, path, sortOrder, hwnd);
1446 /* flags to filter different file types */
1447 enum TYPE_FILTER {
1448 TF_DIRECTORIES = 0x01,
1449 TF_PROGRAMS = 0x02,
1450 TF_DOCUMENTS = 0x04,
1451 TF_OTHERS = 0x08,
1452 TF_HIDDEN = 0x10,
1453 TF_ALL = 0x1F
1457 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1459 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1460 TCHAR dir_path[MAX_PATH];
1461 TCHAR b1[BUFFER_LEN];
1462 static const TCHAR sAsterics[] = {'*', '\0'};
1464 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1465 Root* root = &child->root;
1466 Entry* entry;
1468 memset(child, 0, sizeof(ChildWnd));
1470 child->left.treePane = TRUE;
1471 child->left.visible_cols = 0;
1473 child->right.treePane = FALSE;
1474 #ifndef _NO_EXTENSIONS
1475 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1476 #else
1477 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1478 #endif
1480 child->pos.length = sizeof(WINDOWPLACEMENT);
1481 child->pos.flags = 0;
1482 child->pos.showCmd = SW_SHOWNORMAL;
1483 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1484 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1485 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1486 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1488 child->focus_pane = 0;
1489 child->split_pos = DEFAULT_SPLIT_POS;
1490 child->sortOrder = SORT_NAME;
1491 child->header_wdths_ok = FALSE;
1493 if (path)
1495 lstrcpy(child->path, path);
1497 _tsplitpath(path, drv, dir, name, ext);
1500 lstrcpy(child->filter_pattern, sAsterics);
1501 child->filter_flags = TF_ALL;
1503 root->entry.level = 0;
1505 lstrcpy(dir_path, drv);
1506 lstrcat(dir_path, dir);
1507 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1509 #ifdef _SHELL_FOLDERS
1510 if (root->entry.etype == ET_SHELL)
1511 load_string(root->entry.data.cFileName, sizeof(root->entry.data.cFileName)/sizeof(root->entry.data.cFileName[0]), IDS_DESKTOP);
1512 else
1513 #endif
1514 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1516 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1518 child->left.root = &root->entry;
1519 child->right.root = NULL;
1521 set_curdir(child, entry, 0, hwnd);
1523 return child;
1527 /* free all memory associated with a child window */
1528 static void free_child_window(ChildWnd* child)
1530 free_entries(&child->root.entry);
1531 HeapFree(GetProcessHeap(), 0, child);
1535 /* get full path of specified directory entry */
1536 static void get_path(Entry* dir, PTSTR path)
1538 Entry* entry;
1539 int len = 0;
1540 int level = 0;
1542 #ifdef _SHELL_FOLDERS
1543 if (dir->etype == ET_SHELL)
1545 SFGAOF attribs;
1546 HRESULT hr = S_OK;
1548 path[0] = '\0';
1550 attribs = 0;
1552 if (dir->folder)
1553 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1555 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1556 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1558 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1561 else
1562 #endif
1564 for(entry=dir; entry; level++) {
1565 LPCTSTR name;
1566 int l;
1569 LPCTSTR s;
1570 name = entry->data.cFileName;
1571 s = name;
1573 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1574 l++;
1577 if (entry->up) {
1578 if (l > 0) {
1579 memmove(path+l+1, path, len*sizeof(TCHAR));
1580 memcpy(path+1, name, l*sizeof(TCHAR));
1581 len += l+1;
1583 #ifndef _NO_EXTENSIONS
1584 if (entry->etype == ET_UNIX)
1585 path[0] = '/';
1586 else
1587 #endif
1588 path[0] = '\\';
1591 entry = entry->up;
1592 } else {
1593 memmove(path+l, path, len*sizeof(TCHAR));
1594 memcpy(path, name, l*sizeof(TCHAR));
1595 len += l;
1596 break;
1600 if (!level) {
1601 #ifndef _NO_EXTENSIONS
1602 if (entry->etype == ET_UNIX)
1603 path[len++] = '/';
1604 else
1605 #endif
1606 path[len++] = '\\';
1609 path[len] = '\0';
1613 static windowOptions load_registry_settings(void)
1615 DWORD size;
1616 DWORD type;
1617 HKEY hKey;
1618 windowOptions opts;
1619 LOGFONT logfont;
1621 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1622 0, KEY_QUERY_VALUE, &hKey );
1624 size = sizeof(DWORD);
1626 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1627 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1628 opts.start_x = CW_USEDEFAULT;
1630 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1631 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1632 opts.start_y = CW_USEDEFAULT;
1634 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1635 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1636 opts.width = CW_USEDEFAULT;
1638 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1639 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1640 opts.height = CW_USEDEFAULT;
1641 size=sizeof(logfont);
1642 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1643 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1644 GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1646 RegCloseKey( hKey );
1648 Globals.hfont = CreateFontIndirect(&logfont);
1649 return opts;
1652 static void save_registry_settings(void)
1654 WINDOWINFO wi;
1655 HKEY hKey;
1656 INT width, height;
1657 LOGFONT logfont;
1659 wi.cbSize = sizeof( WINDOWINFO );
1660 GetWindowInfo(Globals.hMainWnd, &wi);
1661 width = wi.rcWindow.right - wi.rcWindow.left;
1662 height = wi.rcWindow.bottom - wi.rcWindow.top;
1664 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1665 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1667 /* Unable to save registry settings - try to create key */
1668 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1669 0, NULL, REG_OPTION_NON_VOLATILE,
1670 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1672 /* FIXME: Cannot create key */
1673 return;
1676 /* Save all of the settings */
1677 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1678 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1679 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1680 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1681 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1682 (LPBYTE) &width, sizeof(DWORD) );
1683 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1684 (LPBYTE) &height, sizeof(DWORD) );
1685 GetObject(Globals.hfont, sizeof(logfont), &logfont);
1686 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1687 (LPBYTE) &logfont, sizeof(LOGFONT) );
1689 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1690 RegCloseKey( hKey );
1693 static void resize_frame_rect(HWND hwnd, PRECT prect)
1695 int new_top;
1696 RECT rt;
1698 if (IsWindowVisible(Globals.htoolbar)) {
1699 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1700 GetClientRect(Globals.htoolbar, &rt);
1701 prect->top = rt.bottom+3;
1702 prect->bottom -= rt.bottom+3;
1705 if (IsWindowVisible(Globals.hdrivebar)) {
1706 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1707 GetClientRect(Globals.hdrivebar, &rt);
1708 new_top = --prect->top + rt.bottom+3;
1709 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1710 prect->top = new_top;
1711 prect->bottom -= rt.bottom+2;
1714 if (IsWindowVisible(Globals.hstatusbar)) {
1715 int parts[] = {300, 500};
1717 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1718 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1719 GetClientRect(Globals.hstatusbar, &rt);
1720 prect->bottom -= rt.bottom;
1723 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1726 static void resize_frame(HWND hwnd, int cx, int cy)
1728 RECT rect;
1730 rect.left = 0;
1731 rect.top = 0;
1732 rect.right = cx;
1733 rect.bottom = cy;
1735 resize_frame_rect(hwnd, &rect);
1738 static void resize_frame_client(HWND hwnd)
1740 RECT rect;
1742 GetClientRect(hwnd, &rect);
1744 resize_frame_rect(hwnd, &rect);
1748 static HHOOK hcbthook;
1749 static ChildWnd* newchild = NULL;
1751 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1753 if (code==HCBT_CREATEWND && newchild) {
1754 ChildWnd* child = newchild;
1755 newchild = NULL;
1757 child->hwnd = (HWND) wparam;
1758 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1761 return CallNextHookEx(hcbthook, code, wparam, lparam);
1764 static HWND create_child_window(ChildWnd* child)
1766 MDICREATESTRUCT mcs;
1767 int idx;
1769 mcs.szClass = sWINEFILETREE;
1770 mcs.szTitle = (LPTSTR)child->path;
1771 mcs.hOwner = Globals.hInstance;
1772 mcs.x = child->pos.rcNormalPosition.left;
1773 mcs.y = child->pos.rcNormalPosition.top;
1774 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1775 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1776 mcs.style = 0;
1777 mcs.lParam = 0;
1779 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1781 newchild = child;
1782 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1783 if (!child->hwnd) {
1784 UnhookWindowsHookEx(hcbthook);
1785 return 0;
1788 UnhookWindowsHookEx(hcbthook);
1790 SendMessage(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1791 SendMessage(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1793 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1794 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
1796 return child->hwnd;
1800 struct ExecuteDialog {
1801 TCHAR cmd[MAX_PATH];
1802 int cmdshow;
1805 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1807 static struct ExecuteDialog* dlg;
1809 switch(nmsg) {
1810 case WM_INITDIALOG:
1811 dlg = (struct ExecuteDialog*) lparam;
1812 return 1;
1814 case WM_COMMAND: {
1815 int id = (int)wparam;
1817 if (id == IDOK) {
1818 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1819 dlg->cmdshow = get_check(hwnd,214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL;
1820 EndDialog(hwnd, id);
1821 } else if (id == IDCANCEL)
1822 EndDialog(hwnd, id);
1824 return 1;}
1827 return 0;
1831 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1833 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1835 switch(nmsg) {
1836 case WM_INITDIALOG:
1837 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1838 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1839 return 1;
1841 case WM_COMMAND: {
1842 int id = (int)wparam;
1844 switch(id) {
1845 case IDOK: {
1846 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1847 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1848 EndDialog(hwnd, id);
1849 break;}
1851 case IDCANCEL:
1852 EndDialog(hwnd, id);
1853 break;
1855 case 254:
1856 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1857 break;
1860 return 1;
1864 return 0;
1868 struct FilterDialog {
1869 TCHAR pattern[MAX_PATH];
1870 int flags;
1873 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1875 static struct FilterDialog* dlg;
1877 switch(nmsg) {
1878 case WM_INITDIALOG:
1879 dlg = (struct FilterDialog*) lparam;
1880 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1881 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1882 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1883 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1884 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1885 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1886 return 1;
1888 case WM_COMMAND: {
1889 int id = (int)wparam;
1891 if (id == IDOK) {
1892 int flags = 0;
1894 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1896 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1897 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1898 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1899 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1900 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1902 dlg->flags = flags;
1904 EndDialog(hwnd, id);
1905 } else if (id == IDCANCEL)
1906 EndDialog(hwnd, id);
1908 return 1;}
1911 return 0;
1915 struct PropertiesDialog {
1916 TCHAR path[MAX_PATH];
1917 Entry entry;
1918 void* pVersionData;
1921 /* Structure used to store enumerated languages and code pages. */
1922 struct LANGANDCODEPAGE {
1923 WORD wLanguage;
1924 WORD wCodePage;
1925 } *lpTranslate;
1927 static LPCSTR InfoStrings[] = {
1928 "Comments",
1929 "CompanyName",
1930 "FileDescription",
1931 "FileVersion",
1932 "InternalName",
1933 "LegalCopyright",
1934 "LegalTrademarks",
1935 "OriginalFilename",
1936 "PrivateBuild",
1937 "ProductName",
1938 "ProductVersion",
1939 "SpecialBuild",
1940 NULL
1943 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1945 int idx = SendMessage(hlbox, LB_GETCURSEL, 0, 0);
1947 if (idx != LB_ERR) {
1948 LPCTSTR pValue = (LPCTSTR) SendMessage(hlbox, LB_GETITEMDATA, idx, 0);
1950 if (pValue)
1951 SetWindowText(hedit, pValue);
1955 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1957 static TCHAR sBackSlash[] = {'\\','\0'};
1958 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'};
1959 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1960 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1961 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1963 if (dwVersionDataLen) {
1964 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1966 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1967 LPVOID pVal;
1968 UINT nValLen;
1970 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1971 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1972 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1973 char buffer[BUFFER_LEN];
1975 sprintf(buffer, "%d.%d.%d.%d",
1976 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1977 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1979 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1983 /* Read the list of languages and code pages. */
1984 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1985 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1986 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1988 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1990 /* Read the file description for each language and code page. */
1991 for(; pTranslate<pEnd; ++pTranslate) {
1992 LPCSTR* p;
1994 for(p=InfoStrings; *p; ++p) {
1995 TCHAR subblock[200];
1996 #ifdef UNICODE
1997 TCHAR infoStr[100];
1998 #endif
1999 LPCTSTR pTxt;
2000 UINT nValLen;
2002 LPCSTR pInfoString = *p;
2003 #ifdef UNICODE
2004 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
2005 #else
2006 #define infoStr pInfoString
2007 #endif
2008 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
2010 /* Retrieve file description for language and code page */
2011 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
2012 int idx = SendMessage(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
2013 SendMessage(hlbox, LB_SETITEMDATA, idx, (LPARAM) pTxt);
2018 SendMessage(hlbox, LB_SETCURSEL, 0, 0);
2020 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2026 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2028 static struct PropertiesDialog* dlg;
2030 switch(nmsg) {
2031 case WM_INITDIALOG: {
2032 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
2033 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2034 LPWIN32_FIND_DATA pWFD;
2035 ULONGLONG size;
2037 dlg = (struct PropertiesDialog*) lparam;
2038 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
2040 GetWindowText(hwnd, b1, MAX_PATH);
2041 wsprintf(b2, b1, pWFD->cFileName);
2042 SetWindowText(hwnd, b2);
2044 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
2045 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
2047 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
2048 _stprintf(b1, sLongNumFmt, size);
2049 wsprintf(b2, sByteFmt, b1);
2050 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
2052 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
2053 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
2055 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
2056 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
2057 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
2058 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
2059 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
2061 CheckForFileInfo(dlg, hwnd, dlg->path);
2062 return 1;}
2064 case WM_COMMAND: {
2065 int id = (int)wparam;
2067 switch(HIWORD(wparam)) {
2068 case LBN_SELCHANGE: {
2069 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2070 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2071 break;
2074 case BN_CLICKED:
2075 if (id==IDOK || id==IDCANCEL)
2076 EndDialog(hwnd, id);
2079 return 1;}
2081 case WM_NCDESTROY:
2082 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
2083 dlg->pVersionData = NULL;
2084 break;
2087 return 0;
2090 static void show_properties_dlg(Entry* entry, HWND hwnd)
2092 struct PropertiesDialog dlg;
2094 memset(&dlg, 0, sizeof(struct PropertiesDialog));
2095 get_path(entry, dlg.path);
2096 memcpy(&dlg.entry, entry, sizeof(Entry));
2098 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
2102 #ifndef _NO_EXTENSIONS
2104 static struct FullScreenParameters {
2105 BOOL mode;
2106 RECT orgPos;
2107 BOOL wasZoomed;
2108 } g_fullscreen = {
2109 FALSE, /* mode */
2110 {0, 0, 0, 0},
2111 FALSE
2114 static void frame_get_clientspace(HWND hwnd, PRECT prect)
2116 RECT rt;
2118 if (!IsIconic(hwnd))
2119 GetClientRect(hwnd, prect);
2120 else {
2121 WINDOWPLACEMENT wp;
2123 GetWindowPlacement(hwnd, &wp);
2125 prect->left = prect->top = 0;
2126 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
2127 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
2128 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
2129 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
2130 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2133 if (IsWindowVisible(Globals.htoolbar)) {
2134 GetClientRect(Globals.htoolbar, &rt);
2135 prect->top += rt.bottom+2;
2138 if (IsWindowVisible(Globals.hdrivebar)) {
2139 GetClientRect(Globals.hdrivebar, &rt);
2140 prect->top += rt.bottom+2;
2143 if (IsWindowVisible(Globals.hstatusbar)) {
2144 GetClientRect(Globals.hstatusbar, &rt);
2145 prect->bottom -= rt.bottom;
2149 static BOOL toggle_fullscreen(HWND hwnd)
2151 RECT rt;
2153 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2154 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2155 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2157 Frame_CalcFrameClient(hwnd, &rt);
2158 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2159 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2161 rt.left = g_fullscreen.orgPos.left-rt.left;
2162 rt.top = g_fullscreen.orgPos.top-rt.top;
2163 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2164 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2166 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2167 } else {
2168 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2169 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2170 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2172 if (g_fullscreen.wasZoomed)
2173 ShowWindow(hwnd, WS_MAXIMIZE);
2176 return g_fullscreen.mode;
2179 static void fullscreen_move(HWND hwnd)
2181 RECT rt, pos;
2182 GetWindowRect(hwnd, &pos);
2184 Frame_CalcFrameClient(hwnd, &rt);
2185 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2186 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2188 rt.left = pos.left-rt.left;
2189 rt.top = pos.top-rt.top;
2190 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2191 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2193 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2196 #endif
2199 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2201 BOOL vis = IsWindowVisible(hchild);
2203 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2205 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2207 #ifndef _NO_EXTENSIONS
2208 if (g_fullscreen.mode)
2209 fullscreen_move(hwnd);
2210 #endif
2212 resize_frame_client(hwnd);
2215 static BOOL activate_drive_window(LPCTSTR path)
2217 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2218 HWND child_wnd;
2220 _tsplitpath(path, drv1, 0, 0, 0);
2222 /* search for a already open window for the same drive */
2223 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2224 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2226 if (child) {
2227 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2229 if (!lstrcmpi(drv2, drv1)) {
2230 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2232 if (IsIconic(child_wnd))
2233 ShowWindow(child_wnd, SW_SHOWNORMAL);
2235 return TRUE;
2240 return FALSE;
2243 static BOOL activate_fs_window(LPCTSTR filesys)
2245 HWND child_wnd;
2247 /* search for a already open window of the given file system name */
2248 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2249 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2251 if (child) {
2252 if (!lstrcmpi(child->root.fs, filesys)) {
2253 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2255 if (IsIconic(child_wnd))
2256 ShowWindow(child_wnd, SW_SHOWNORMAL);
2258 return TRUE;
2263 return FALSE;
2266 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2268 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2270 switch(nmsg) {
2271 case WM_CLOSE:
2272 if (Globals.saveSettings)
2273 save_registry_settings();
2275 DestroyWindow(hwnd);
2277 /* clear handle variables */
2278 Globals.hMenuFrame = 0;
2279 Globals.hMenuView = 0;
2280 Globals.hMenuOptions = 0;
2281 Globals.hMainWnd = 0;
2282 Globals.hmdiclient = 0;
2283 Globals.hdrivebar = 0;
2284 break;
2286 case WM_DESTROY:
2287 PostQuitMessage(0);
2288 break;
2290 case WM_INITMENUPOPUP: {
2291 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2293 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2294 return 0;
2295 break;}
2297 case WM_COMMAND: {
2298 UINT cmd = LOWORD(wparam);
2299 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2301 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2302 break;
2304 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2305 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2306 ChildWnd* child;
2307 LPCTSTR root = Globals.drives;
2308 int i;
2310 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2311 while(*root)
2312 root++;
2314 if (activate_drive_window(root))
2315 return 0;
2317 _tsplitpath(root, drv, 0, 0, 0);
2319 if (!SetCurrentDirectory(drv)) {
2320 display_error(hwnd, GetLastError());
2321 return 0;
2324 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2325 child = alloc_child_window(path, NULL, hwnd);
2327 if (!create_child_window(child))
2328 HeapFree(GetProcessHeap(), 0, child);
2329 } else switch(cmd) {
2330 case ID_FILE_EXIT:
2331 SendMessage(hwnd, WM_CLOSE, 0, 0);
2332 break;
2334 case ID_WINDOW_NEW: {
2335 TCHAR path[MAX_PATH];
2336 ChildWnd* child;
2338 GetCurrentDirectory(MAX_PATH, path);
2339 child = alloc_child_window(path, NULL, hwnd);
2341 if (!create_child_window(child))
2342 HeapFree(GetProcessHeap(), 0, child);
2343 break;}
2345 case ID_REFRESH:
2346 refresh_drives();
2347 break;
2349 case ID_WINDOW_CASCADE:
2350 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2351 break;
2353 case ID_WINDOW_TILE_HORZ:
2354 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2355 break;
2357 case ID_WINDOW_TILE_VERT:
2358 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2359 break;
2361 case ID_WINDOW_ARRANGE:
2362 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2363 break;
2365 case ID_SELECT_FONT:
2366 choose_font(hwnd);
2367 break;
2369 case ID_VIEW_TOOL_BAR:
2370 toggle_child(hwnd, cmd, Globals.htoolbar);
2371 break;
2373 case ID_VIEW_DRIVE_BAR:
2374 toggle_child(hwnd, cmd, Globals.hdrivebar);
2375 break;
2377 case ID_VIEW_STATUSBAR:
2378 toggle_child(hwnd, cmd, Globals.hstatusbar);
2379 break;
2381 case ID_VIEW_SAVESETTINGS:
2382 Globals.saveSettings = !Globals.saveSettings;
2383 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2384 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2385 break;
2387 case ID_EXECUTE: {
2388 struct ExecuteDialog dlg;
2390 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2392 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2393 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2395 if (PtrToUlong(hinst) <= 32)
2396 display_error(hwnd, GetLastError());
2398 break;}
2400 case ID_CONNECT_NETWORK_DRIVE: {
2401 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2402 if (ret == NO_ERROR)
2403 refresh_drives();
2404 else if (ret != (DWORD)-1) {
2405 if (ret == ERROR_EXTENDED_ERROR)
2406 display_network_error(hwnd);
2407 else
2408 display_error(hwnd, ret);
2410 break;}
2412 case ID_DISCONNECT_NETWORK_DRIVE: {
2413 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2414 if (ret == NO_ERROR)
2415 refresh_drives();
2416 else if (ret != (DWORD)-1) {
2417 if (ret == ERROR_EXTENDED_ERROR)
2418 display_network_error(hwnd);
2419 else
2420 display_error(hwnd, ret);
2422 break;}
2424 case ID_FORMAT_DISK: {
2425 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2426 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2427 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2428 SetErrorMode(sem_org); /* Put it back the way it was. */
2429 break;}
2431 case ID_HELP:
2432 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2433 break;
2435 #ifndef _NO_EXTENSIONS
2436 case ID_VIEW_FULLSCREEN:
2437 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2438 break;
2440 #ifdef __WINE__
2441 case ID_DRIVE_UNIX_FS: {
2442 TCHAR path[MAX_PATH];
2443 #ifdef UNICODE
2444 char cpath[MAX_PATH];
2445 #endif
2446 ChildWnd* child;
2448 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2449 break;
2451 #ifdef UNICODE
2452 getcwd(cpath, MAX_PATH);
2453 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2454 #else
2455 getcwd(path, MAX_PATH);
2456 #endif
2457 child = alloc_child_window(path, NULL, hwnd);
2459 if (!create_child_window(child))
2460 HeapFree(GetProcessHeap(), 0, child);
2461 break;}
2462 #endif
2463 #ifdef _SHELL_FOLDERS
2464 case ID_DRIVE_SHELL_NS: {
2465 TCHAR path[MAX_PATH];
2466 ChildWnd* child;
2468 if (activate_fs_window(RS(b1,IDS_SHELL)))
2469 break;
2471 GetCurrentDirectory(MAX_PATH, path);
2472 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2474 if (!create_child_window(child))
2475 HeapFree(GetProcessHeap(), 0, child);
2476 break;}
2477 #endif
2478 #endif
2480 /*TODO: There are even more menu items! */
2482 case ID_ABOUT:
2483 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL,
2484 LoadImage( Globals.hInstance, MAKEINTRESOURCE(IDI_WINEFILE),
2485 IMAGE_ICON, 48, 48, LR_SHARED ));
2486 break;
2488 default:
2489 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2490 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2491 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2492 (cmd<SC_SIZE || cmd>SC_RESTORE))
2493 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2495 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2497 break;}
2499 case WM_SIZE:
2500 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2501 break; /* do not pass message to DefFrameProc */
2503 case WM_DEVICECHANGE:
2504 SendMessage(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2505 break;
2507 #ifndef _NO_EXTENSIONS
2508 case WM_GETMINMAXINFO: {
2509 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2511 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2512 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2513 break;}
2515 case FRM_CALC_CLIENT:
2516 frame_get_clientspace(hwnd, (PRECT)lparam);
2517 return TRUE;
2518 #endif /* _NO_EXTENSIONS */
2520 default:
2521 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2524 return 0;
2528 static TCHAR g_pos_names[COLUMNS][20] = {
2529 {'\0'} /* symbol */
2532 static const int g_pos_align[] = {
2534 HDF_LEFT, /* Name */
2535 HDF_RIGHT, /* Size */
2536 HDF_LEFT, /* CDate */
2537 #ifndef _NO_EXTENSIONS
2538 HDF_LEFT, /* ADate */
2539 HDF_LEFT, /* MDate */
2540 HDF_LEFT, /* Index */
2541 HDF_CENTER, /* Links */
2542 #endif
2543 HDF_CENTER, /* Attributes */
2544 #ifndef _NO_EXTENSIONS
2545 HDF_LEFT /* Security */
2546 #endif
2549 static void resize_tree(ChildWnd* child, int cx, int cy)
2551 HDWP hdwp = BeginDeferWindowPos(4);
2552 RECT rt;
2554 rt.left = 0;
2555 rt.top = 0;
2556 rt.right = cx;
2557 rt.bottom = cy;
2559 cx = child->split_pos + SPLIT_WIDTH/2;
2561 #ifndef _NO_EXTENSIONS
2563 WINDOWPOS wp;
2564 HD_LAYOUT hdl;
2566 hdl.prc = &rt;
2567 hdl.pwpos = &wp;
2569 SendMessage(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2571 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2572 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2573 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2574 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2576 #endif /* _NO_EXTENSIONS */
2578 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);
2579 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2581 EndDeferWindowPos(hdwp);
2585 #ifndef _NO_EXTENSIONS
2587 static HWND create_header(HWND parent, Pane* pane, UINT id)
2589 HD_ITEM hdi;
2590 int idx;
2592 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2593 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2594 if (!hwnd)
2595 return 0;
2597 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2599 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2601 for(idx=0; idx<COLUMNS; idx++) {
2602 hdi.pszText = g_pos_names[idx];
2603 hdi.fmt = HDF_STRING | g_pos_align[idx];
2604 hdi.cxy = pane->widths[idx];
2605 SendMessage(hwnd, HDM_INSERTITEM, idx, (LPARAM) &hdi);
2608 return hwnd;
2611 #endif /* _NO_EXTENSIONS */
2614 static void init_output(HWND hwnd)
2616 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2617 WCHAR b[16];
2618 HFONT old_font;
2619 HDC hdc = GetDC(hwnd);
2621 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2622 Globals.num_sep = b[1];
2623 else
2624 Globals.num_sep = '.';
2626 old_font = SelectObject(hdc, Globals.hfont);
2627 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2628 SelectObject(hdc, old_font);
2629 ReleaseDC(hwnd, hdc);
2632 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2635 /* calculate preferred width for all visible columns */
2637 static BOOL calc_widths(Pane* pane, BOOL anyway)
2639 int col, x, cx, spc=3*Globals.spaceSize.cx;
2640 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2641 int orgWidths[COLUMNS];
2642 int orgPositions[COLUMNS+1];
2643 HFONT hfontOld;
2644 HDC hdc;
2645 int cnt;
2647 if (!anyway) {
2648 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2649 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2652 for(col=0; col<COLUMNS; col++)
2653 pane->widths[col] = 0;
2655 hdc = GetDC(pane->hwnd);
2656 hfontOld = SelectObject(hdc, Globals.hfont);
2658 for(cnt=0; cnt<entries; cnt++) {
2659 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2661 DRAWITEMSTRUCT dis;
2663 dis.CtlType = 0;
2664 dis.CtlID = 0;
2665 dis.itemID = 0;
2666 dis.itemAction = 0;
2667 dis.itemState = 0;
2668 dis.hwndItem = pane->hwnd;
2669 dis.hDC = hdc;
2670 dis.rcItem.left = 0;
2671 dis.rcItem.top = 0;
2672 dis.rcItem.right = 0;
2673 dis.rcItem.bottom = 0;
2674 /*dis.itemData = 0; */
2676 draw_item(pane, &dis, entry, COLUMNS);
2679 SelectObject(hdc, hfontOld);
2680 ReleaseDC(pane->hwnd, hdc);
2682 x = 0;
2683 for(col=0; col<COLUMNS; col++) {
2684 pane->positions[col] = x;
2685 cx = pane->widths[col];
2687 if (cx) {
2688 cx += spc;
2690 if (cx < IMAGE_WIDTH)
2691 cx = IMAGE_WIDTH;
2693 pane->widths[col] = cx;
2696 x += cx;
2699 pane->positions[COLUMNS] = x;
2701 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2703 /* no change? */
2704 if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2705 return FALSE;
2707 /* don't move, if only collapsing an entry */
2708 if (!anyway && pane->widths[0]<orgWidths[0] &&
2709 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2710 pane->widths[0] = orgWidths[0];
2711 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2713 return FALSE;
2716 InvalidateRect(pane->hwnd, 0, TRUE);
2718 return TRUE;
2722 /* calculate one preferred column width */
2724 static void calc_single_width(Pane* pane, int col)
2726 HFONT hfontOld;
2727 int x, cx;
2728 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2729 int cnt;
2730 HDC hdc;
2732 pane->widths[col] = 0;
2734 hdc = GetDC(pane->hwnd);
2735 hfontOld = SelectObject(hdc, Globals.hfont);
2737 for(cnt=0; cnt<entries; cnt++) {
2738 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2739 DRAWITEMSTRUCT dis;
2741 dis.CtlType = 0;
2742 dis.CtlID = 0;
2743 dis.itemID = 0;
2744 dis.itemAction = 0;
2745 dis.itemState = 0;
2746 dis.hwndItem = pane->hwnd;
2747 dis.hDC = hdc;
2748 dis.rcItem.left = 0;
2749 dis.rcItem.top = 0;
2750 dis.rcItem.right = 0;
2751 dis.rcItem.bottom = 0;
2752 /*dis.itemData = 0; */
2754 draw_item(pane, &dis, entry, col);
2757 SelectObject(hdc, hfontOld);
2758 ReleaseDC(pane->hwnd, hdc);
2760 cx = pane->widths[col];
2762 if (cx) {
2763 cx += 3*Globals.spaceSize.cx;
2765 if (cx < IMAGE_WIDTH)
2766 cx = IMAGE_WIDTH;
2769 pane->widths[col] = cx;
2771 x = pane->positions[col] + cx;
2773 for(; col<COLUMNS; ) {
2774 pane->positions[++col] = x;
2775 x += pane->widths[col];
2778 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2782 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2784 for( ; *str&&*pattern; str++,pattern++) {
2785 if (*pattern == '*') {
2786 do pattern++;
2787 while(*pattern == '*');
2789 if (!*pattern)
2790 return TRUE;
2792 for(; *str; str++)
2793 if (*str==*pattern && pattern_match(str, pattern))
2794 return TRUE;
2796 return FALSE;
2798 else if (*str!=*pattern && *pattern!='?')
2799 return FALSE;
2802 if (*str || *pattern)
2803 if (*pattern!='*' || pattern[1]!='\0')
2804 return FALSE;
2806 return TRUE;
2809 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2811 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2813 lstrcpy(b1, str);
2814 lstrcpy(b2, pattern);
2815 CharUpper(b1);
2816 CharUpper(b2);
2818 return pattern_match(b1, b2);
2822 enum FILE_TYPE {
2823 FT_OTHER = 0,
2824 FT_EXECUTABLE = 1,
2825 FT_DOCUMENT = 2
2828 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2831 /* insert listbox entries after index idx */
2833 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2835 Entry* entry = dir;
2837 if (!entry)
2838 return idx;
2840 ShowWindow(pane->hwnd, SW_HIDE);
2842 for(; entry; entry=entry->next) {
2843 #ifndef _LEFT_FILES
2844 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2845 continue;
2846 #endif
2848 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2849 /* don't display entries "." and ".." in the left pane */
2850 if (pane->treePane && entry->data.cFileName[0] == '.')
2851 if (
2852 #ifndef _NO_EXTENSIONS
2853 entry->data.cFileName[1] == '\0' ||
2854 #endif
2855 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2856 continue;
2858 /* filter directories in right pane */
2859 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2860 continue;
2863 /* filter using the file name pattern */
2864 if (pattern)
2865 if (!pattern_imatch(entry->data.cFileName, pattern))
2866 continue;
2868 /* filter system and hidden files */
2869 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2870 continue;
2872 /* filter looking at the file type */
2873 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2874 switch(get_file_type(entry->data.cFileName)) {
2875 case FT_EXECUTABLE:
2876 if (!(filter_flags & TF_PROGRAMS))
2877 continue;
2878 break;
2880 case FT_DOCUMENT:
2881 if (!(filter_flags & TF_DOCUMENTS))
2882 continue;
2883 break;
2885 default: /* TF_OTHERS */
2886 if (!(filter_flags & TF_OTHERS))
2887 continue;
2890 if (idx != -1)
2891 idx++;
2893 SendMessage(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM) entry);
2895 if (pane->treePane && entry->expanded)
2896 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2899 ShowWindow(pane->hwnd, SW_SHOW);
2901 return idx;
2905 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2907 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2908 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2909 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2911 float fBytes = (float)bytes;
2913 if (bytes >= 1073741824) /* 1 GB */
2914 _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2915 else if (bytes >= 1048576) /* 1 MB */
2916 _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2917 else if (bytes >= 1024) /* 1 kB */
2918 _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2919 else
2920 _stprintf(buffer, sLongNumFmt, bytes);
2923 static void set_space_status(void)
2925 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2926 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2928 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2929 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2930 format_bytes(b2, ulTotalBytes.QuadPart);
2931 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2932 } else
2933 lstrcpy(buffer, sQMarks);
2935 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2939 static WNDPROC g_orgTreeWndProc;
2941 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCTSTR pattern, int filter_flags)
2943 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2945 static int s_init = 0;
2946 Entry* entry = pane->root;
2948 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2949 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2950 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2952 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2953 g_orgTreeWndProc = (WNDPROC) SetWindowLongPtr(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2955 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2957 /* insert entries into listbox */
2958 if (entry)
2959 insert_entries(pane, entry, pattern, filter_flags, -1);
2961 /* calculate column widths */
2962 if (!s_init) {
2963 s_init = 1;
2964 init_output(pane->hwnd);
2967 calc_widths(pane, TRUE);
2969 #ifndef _NO_EXTENSIONS
2970 pane->hwndHeader = create_header(parent, pane, id_header);
2971 #endif
2975 static void InitChildWindow(ChildWnd* child)
2977 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2978 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2982 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
2984 SYSTEMTIME systime;
2985 FILETIME lft;
2986 int len = 0;
2988 *buffer = '\0';
2990 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2991 return;
2993 if (!FileTimeToLocalFileTime(ft, &lft))
2994 {err: lstrcpy(buffer,sQMarks); return;}
2996 if (!FileTimeToSystemTime(&lft, &systime))
2997 goto err;
2999 if (visible_cols & COL_DATE) {
3000 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
3001 if (!len)
3002 goto err;
3005 if (visible_cols & COL_TIME) {
3006 if (len)
3007 buffer[len-1] = ' ';
3009 buffer[len++] = ' ';
3011 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
3012 buffer[len] = '\0';
3017 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3019 RECT rt = {0, 0, 0, 0};
3021 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3023 if (rt.right > pane->widths[col])
3024 pane->widths[col] = rt.right;
3027 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3029 RECT rt = {0, 0, 0, 0};
3031 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3032 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3034 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3035 /*FIXME rt (0,0) ??? */
3037 if (rt.right > pane->widths[col])
3038 pane->widths[col] = rt.right;
3042 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
3044 int x = dis->rcItem.left;
3045 RECT rt;
3047 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3048 rt.top = dis->rcItem.top;
3049 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3050 rt.bottom = dis->rcItem.bottom;
3052 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
3055 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3057 int x = dis->rcItem.left;
3058 RECT rt;
3060 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3061 rt.top = dis->rcItem.top;
3062 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3063 rt.bottom = dis->rcItem.bottom;
3065 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3066 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3068 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3071 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3073 int x = dis->rcItem.left;
3074 RECT rt;
3075 LPCTSTR s = str;
3076 TCHAR b[128];
3077 LPTSTR d = b;
3078 int pos;
3080 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3081 rt.top = dis->rcItem.top;
3082 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3083 rt.bottom = dis->rcItem.bottom;
3085 if (*s)
3086 *d++ = *s++;
3088 /* insert number separator characters */
3089 pos = lstrlen(s) % 3;
3091 while(*s)
3092 if (pos--)
3093 *d++ = *s++;
3094 else {
3095 *d++ = Globals.num_sep;
3096 pos = 3;
3099 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3103 static BOOL is_exe_file(LPCTSTR ext)
3105 static const TCHAR executable_extensions[][4] = {
3106 {'C','O','M','\0'},
3107 {'E','X','E','\0'},
3108 {'B','A','T','\0'},
3109 {'C','M','D','\0'},
3110 #ifndef _NO_EXTENSIONS
3111 {'C','M','M','\0'},
3112 {'B','T','M','\0'},
3113 {'A','W','K','\0'},
3114 #endif /* _NO_EXTENSIONS */
3115 {'\0'}
3118 TCHAR ext_buffer[_MAX_EXT];
3119 const TCHAR (*p)[4];
3120 LPCTSTR s;
3121 LPTSTR d;
3123 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3124 d++;
3126 for(p=executable_extensions; (*p)[0]; p++)
3127 if (!lstrcmpi(ext_buffer, *p))
3128 return TRUE;
3130 return FALSE;
3133 static BOOL is_registered_type(LPCTSTR ext)
3135 /* check if there exists a classname for this file extension in the registry */
3136 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3137 return TRUE;
3139 return FALSE;
3142 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3144 LPCTSTR ext = _tcsrchr(filename, '.');
3145 if (!ext)
3146 ext = sEmpty;
3148 if (is_exe_file(ext))
3149 return FT_EXECUTABLE;
3150 else if (is_registered_type(ext))
3151 return FT_DOCUMENT;
3152 else
3153 return FT_OTHER;
3157 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3159 TCHAR buffer[BUFFER_LEN];
3160 DWORD attrs;
3161 int visible_cols = pane->visible_cols;
3162 COLORREF bkcolor, textcolor;
3163 RECT focusRect = dis->rcItem;
3164 HBRUSH hbrush;
3165 enum IMAGE img;
3166 int img_pos, cx;
3167 int col = 0;
3169 if (entry) {
3170 attrs = entry->data.dwFileAttributes;
3172 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3173 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3174 && entry->data.cFileName[2] == '\0')
3175 img = IMG_FOLDER_UP;
3176 #ifndef _NO_EXTENSIONS
3177 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3178 img = IMG_FOLDER_CUR;
3179 #endif
3180 else if (
3181 #ifdef _NO_EXTENSIONS
3182 entry->expanded ||
3183 #endif
3184 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3185 img = IMG_OPEN_FOLDER;
3186 else
3187 img = IMG_FOLDER;
3188 } else {
3189 switch(get_file_type(entry->data.cFileName)) {
3190 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3191 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3192 default: img = IMG_FILE;
3195 } else {
3196 attrs = 0;
3197 img = IMG_NONE;
3200 if (pane->treePane) {
3201 if (entry) {
3202 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3204 if (calcWidthCol == -1) {
3205 int x;
3206 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3207 Entry* up;
3208 RECT rt_clip;
3209 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3210 HRGN hrgn;
3212 rt_clip.left = dis->rcItem.left;
3213 rt_clip.top = dis->rcItem.top;
3214 rt_clip.right = dis->rcItem.left+pane->widths[col];
3215 rt_clip.bottom = dis->rcItem.bottom;
3217 hrgn = CreateRectRgnIndirect(&rt_clip);
3219 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3220 DeleteObject(hrgn_org);
3221 hrgn_org = 0;
3224 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3225 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3226 DeleteObject(hrgn);
3228 if ((up=entry->up) != NULL) {
3229 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3230 LineTo(dis->hDC, img_pos-2, y);
3232 x = img_pos - IMAGE_WIDTH/2;
3234 do {
3235 x -= IMAGE_WIDTH+TREE_LINE_DX;
3237 if (up->next
3238 #ifndef _LEFT_FILES
3239 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3240 #endif
3242 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3243 LineTo(dis->hDC, x, dis->rcItem.bottom);
3245 } while((up=up->up) != NULL);
3248 x = img_pos - IMAGE_WIDTH/2;
3250 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3251 LineTo(dis->hDC, x, y);
3253 if (entry->next
3254 #ifndef _LEFT_FILES
3255 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3256 #endif
3258 LineTo(dis->hDC, x, dis->rcItem.bottom);
3260 SelectClipRgn(dis->hDC, hrgn_org);
3261 if (hrgn_org) DeleteObject(hrgn_org);
3262 /* SelectObject(dis->hDC, holdPen); */
3263 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3264 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3266 if (right > pane->widths[col])
3267 pane->widths[col] = right;
3269 } else {
3270 img_pos = dis->rcItem.left;
3272 } else {
3273 img_pos = dis->rcItem.left;
3275 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3276 pane->widths[col] = IMAGE_WIDTH;
3279 if (calcWidthCol == -1) {
3280 focusRect.left = img_pos -2;
3282 #ifdef _NO_EXTENSIONS
3283 if (pane->treePane && entry) {
3284 RECT rt = {0};
3286 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3288 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3290 #else
3292 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3293 textcolor = COLOR_COMPRESSED;
3294 else
3295 #endif /* _NO_EXTENSIONS */
3296 textcolor = RGB(0,0,0);
3298 if (dis->itemState & ODS_FOCUS) {
3299 textcolor = RGB(255,255,255);
3300 bkcolor = COLOR_SELECTION;
3301 } else {
3302 bkcolor = RGB(255,255,255);
3305 hbrush = CreateSolidBrush(bkcolor);
3306 FillRect(dis->hDC, &focusRect, hbrush);
3307 DeleteObject(hbrush);
3309 SetBkMode(dis->hDC, TRANSPARENT);
3310 SetTextColor(dis->hDC, textcolor);
3312 cx = pane->widths[col];
3314 if (cx && img!=IMG_NONE) {
3315 if (cx > IMAGE_WIDTH)
3316 cx = IMAGE_WIDTH;
3318 #ifdef _SHELL_FOLDERS
3319 if (entry->hicon && entry->hicon!=(HICON)-1)
3320 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3321 else
3322 #endif
3323 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3324 img_pos, dis->rcItem.top, cx,
3325 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3329 if (!entry)
3330 return;
3332 #ifdef _NO_EXTENSIONS
3333 if (img >= IMG_FOLDER_UP)
3334 return;
3335 #endif
3337 col++;
3339 /* ouput file name */
3340 if (calcWidthCol == -1)
3341 output_text(pane, dis, col, entry->data.cFileName, 0);
3342 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3343 calc_width(pane, dis, col, entry->data.cFileName);
3345 col++;
3347 #ifdef _NO_EXTENSIONS
3348 if (!pane->treePane) {
3349 #endif
3351 /* display file size */
3352 if (visible_cols & COL_SIZE) {
3353 #ifdef _NO_EXTENSIONS
3354 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3355 #endif
3357 ULONGLONG size;
3359 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3361 _stprintf(buffer, sLongNumFmt, size);
3363 if (calcWidthCol == -1)
3364 output_number(pane, dis, col, buffer);
3365 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3366 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3369 col++;
3372 /* display file date */
3373 if (visible_cols & (COL_DATE|COL_TIME)) {
3374 #ifndef _NO_EXTENSIONS
3375 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3376 if (calcWidthCol == -1)
3377 output_text(pane, dis, col, buffer, 0);
3378 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3379 calc_width(pane, dis, col, buffer);
3380 col++;
3382 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3383 if (calcWidthCol == -1)
3384 output_text(pane, dis, col, buffer, 0);
3385 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3386 calc_width(pane, dis, col, buffer);
3387 col++;
3388 #endif /* _NO_EXTENSIONS */
3390 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3391 if (calcWidthCol == -1)
3392 output_text(pane, dis, col, buffer, 0);
3393 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3394 calc_width(pane, dis, col, buffer);
3395 col++;
3398 #ifndef _NO_EXTENSIONS
3399 if (entry->bhfi_valid) {
3400 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3402 if (visible_cols & COL_INDEX) {
3403 _stprintf(buffer, sLongHexFmt, index);
3405 if (calcWidthCol == -1)
3406 output_text(pane, dis, col, buffer, DT_RIGHT);
3407 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3408 calc_width(pane, dis, col, buffer);
3410 col++;
3413 if (visible_cols & COL_LINKS) {
3414 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3416 if (calcWidthCol == -1)
3417 output_text(pane, dis, col, buffer, DT_CENTER);
3418 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3419 calc_width(pane, dis, col, buffer);
3421 col++;
3423 } else
3424 col += 2;
3425 #endif /* _NO_EXTENSIONS */
3427 /* show file attributes */
3428 if (visible_cols & COL_ATTRIBUTES) {
3429 #ifdef _NO_EXTENSIONS
3430 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3431 lstrcpy(buffer, s4Tabs);
3432 #else
3433 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3434 lstrcpy(buffer, s11Tabs);
3435 #endif
3437 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3438 else {
3439 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3440 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3441 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3442 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3443 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3444 #ifndef _NO_EXTENSIONS
3445 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3446 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3447 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3448 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3449 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3450 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3451 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3452 #endif /* _NO_EXTENSIONS */
3455 if (calcWidthCol == -1)
3456 output_tabbed_text(pane, dis, col, buffer);
3457 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3458 calc_tabbed_width(pane, dis, col, buffer);
3460 col++;
3463 /*TODO
3464 if (flags.security) {
3465 static const TCHAR sSecTabs[] = {
3466 ' ','\t',' ','\t',' ','\t',' ',
3467 ' ','\t',' ',
3468 ' ','\t',' ','\t',' ','\t',' ',
3469 ' ','\t',' ',
3470 ' ','\t',' ','\t',' ','\t',' ',
3471 '\0'
3474 DWORD rights = get_access_mask();
3476 lstrcpy(buffer, sSecTabs);
3478 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3479 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3480 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3481 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3482 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3483 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3484 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3485 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3486 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3487 if (rights & WRITE_DAC) buffer[22] = 'C';
3488 if (rights & WRITE_OWNER) buffer[24] = 'O';
3489 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3491 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3494 if (flags.description) {
3495 get_description(buffer);
3496 output_text(dis, col++, buffer, 0, psize);
3500 #ifdef _NO_EXTENSIONS
3503 /* draw focus frame */
3504 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3505 /* Currently [04/2000] Wine neither behaves exactly the same */
3506 /* way as WIN 95 nor like Windows NT... */
3507 HGDIOBJ lastBrush;
3508 HPEN lastPen;
3509 HPEN hpen;
3511 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3512 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3513 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3514 } else
3515 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3517 lastPen = SelectPen(dis->hDC, hpen);
3518 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3519 SetROP2(dis->hDC, R2_XORPEN);
3520 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3521 SelectObject(dis->hDC, lastBrush);
3522 SelectObject(dis->hDC, lastPen);
3523 DeleteObject(hpen);
3525 #endif /* _NO_EXTENSIONS */
3529 #ifdef _NO_EXTENSIONS
3531 static void draw_splitbar(HWND hwnd, int x)
3533 RECT rt;
3534 HDC hdc = GetDC(hwnd);
3536 GetClientRect(hwnd, &rt);
3538 rt.left = x - SPLIT_WIDTH/2;
3539 rt.right = x + SPLIT_WIDTH/2+1;
3541 InvertRect(hdc, &rt);
3543 ReleaseDC(hwnd, hdc);
3546 #endif /* _NO_EXTENSIONS */
3549 #ifndef _NO_EXTENSIONS
3551 static void set_header(Pane* pane)
3553 HD_ITEM item;
3554 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3555 int i=0, x=0;
3557 item.mask = HDI_WIDTH;
3558 item.cxy = 0;
3560 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3561 x += pane->widths[i];
3562 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3565 if (i < COLUMNS) {
3566 x += pane->widths[i];
3567 item.cxy = x - scroll_pos;
3568 SendMessage(pane->hwndHeader, HDM_SETITEM, i++, (LPARAM) &item);
3570 for(; i<COLUMNS; i++) {
3571 item.cxy = pane->widths[i];
3572 x += pane->widths[i];
3573 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3578 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3580 switch(pnmh->code) {
3581 case HDN_ITEMCHANGED: {
3582 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3583 int idx = phdn->iItem;
3584 int dx = phdn->pitem->cxy - pane->widths[idx];
3585 int i;
3587 RECT clnt;
3588 GetClientRect(pane->hwnd, &clnt);
3590 pane->widths[idx] += dx;
3592 for(i=idx; ++i<=COLUMNS; )
3593 pane->positions[i] += dx;
3596 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3597 RECT rt_scr;
3598 RECT rt_clip;
3600 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3601 rt_scr.top = 0;
3602 rt_scr.right = clnt.right;
3603 rt_scr.bottom = clnt.bottom;
3605 rt_clip.left = pane->positions[idx]-scroll_pos;
3606 rt_clip.top = 0;
3607 rt_clip.right = clnt.right;
3608 rt_clip.bottom = clnt.bottom;
3610 if (rt_scr.left < 0) rt_scr.left = 0;
3611 if (rt_clip.left < 0) rt_clip.left = 0;
3613 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3615 rt_clip.right = pane->positions[idx+1];
3616 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3618 if (pnmh->code == HDN_ENDTRACK) {
3619 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3621 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3622 set_header(pane);
3626 return FALSE;
3629 case HDN_DIVIDERDBLCLICK: {
3630 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3631 HD_ITEM item;
3633 calc_single_width(pane, phdn->iItem);
3634 item.mask = HDI_WIDTH;
3635 item.cxy = pane->widths[phdn->iItem];
3637 SendMessage(pane->hwndHeader, HDM_SETITEM, phdn->iItem, (LPARAM) &item);
3638 InvalidateRect(pane->hwnd, 0, TRUE);
3639 break;}
3642 return 0;
3645 #endif /* _NO_EXTENSIONS */
3648 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3650 TCHAR path[MAX_PATH];
3651 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3653 /* delete sub entries in left pane */
3654 for(;;) {
3655 LRESULT res = SendMessage(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3656 Entry* sub = (Entry*) res;
3658 if (res==LB_ERR || !sub || sub->level<=entry->level)
3659 break;
3661 SendMessage(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3664 /* empty right pane */
3665 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3667 /* release memory */
3668 free_entries(entry);
3670 /* read contents from disk */
3671 #ifdef _SHELL_FOLDERS
3672 if (entry->etype == ET_SHELL)
3674 read_directory(entry, NULL, child->sortOrder, hwnd);
3676 else
3677 #endif
3679 get_path(entry, path);
3680 read_directory(entry, path, child->sortOrder, hwnd);
3683 /* insert found entries in right pane */
3684 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3685 calc_widths(&child->right, FALSE);
3686 #ifndef _NO_EXTENSIONS
3687 set_header(&child->right);
3688 #endif
3690 child->header_wdths_ok = FALSE;
3692 SetCursor(old_cursor);
3696 /* expand a directory entry */
3698 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3700 int idx;
3701 Entry* p;
3703 if (!dir || dir->expanded || !dir->down)
3704 return FALSE;
3706 p = dir->down;
3708 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3709 p = p->next;
3711 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3712 p->data.cFileName[2]=='\0' && p->next)
3713 p = p->next;
3716 /* no subdirectories ? */
3717 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3718 return FALSE;
3720 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3722 dir->expanded = TRUE;
3724 /* insert entries in left pane */
3725 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3727 if (!child->header_wdths_ok) {
3728 if (calc_widths(&child->left, FALSE)) {
3729 #ifndef _NO_EXTENSIONS
3730 set_header(&child->left);
3731 #endif
3733 child->header_wdths_ok = TRUE;
3737 return TRUE;
3741 static void collapse_entry(Pane* pane, Entry* dir)
3743 int idx = SendMessage(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3745 ShowWindow(pane->hwnd, SW_HIDE);
3747 /* hide sub entries */
3748 for(;;) {
3749 LRESULT res = SendMessage(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3750 Entry* sub = (Entry*) res;
3752 if (res==LB_ERR || !sub || sub->level<=dir->level)
3753 break;
3755 SendMessage(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3758 dir->expanded = FALSE;
3760 ShowWindow(pane->hwnd, SW_SHOW);
3764 static void refresh_right_pane(ChildWnd* child)
3766 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3767 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3768 calc_widths(&child->right, FALSE);
3770 #ifndef _NO_EXTENSIONS
3771 set_header(&child->right);
3772 #endif
3775 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3777 TCHAR path[MAX_PATH];
3779 if (!entry)
3780 return;
3782 path[0] = '\0';
3784 child->left.cur = entry;
3786 child->right.root = entry->down? entry->down: entry;
3787 child->right.cur = entry;
3789 if (!entry->scanned)
3790 scan_entry(child, entry, idx, hwnd);
3791 else
3792 refresh_right_pane(child);
3794 get_path(entry, path);
3795 lstrcpy(child->path, path);
3797 if (child->hwnd) /* only change window title, if the window already exists */
3798 SetWindowText(child->hwnd, path);
3800 if (path[0])
3801 if (SetCurrentDirectory(path))
3802 set_space_status();
3806 static void refresh_child(ChildWnd* child)
3808 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3809 Entry* entry;
3810 int idx;
3812 get_path(child->left.cur, path);
3813 _tsplitpath(path, drv, NULL, NULL, NULL);
3815 child->right.root = NULL;
3817 scan_entry(child, &child->root.entry, 0, child->hwnd);
3819 #ifdef _SHELL_FOLDERS
3820 if (child->root.entry.etype == ET_SHELL)
3821 entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd);
3822 else
3823 #endif
3824 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3826 if (!entry)
3827 entry = &child->root.entry;
3829 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3831 set_curdir(child, entry, 0, child->hwnd);
3833 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3834 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
3838 static void create_drive_bar(void)
3840 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3841 #ifndef _NO_EXTENSIONS
3842 TCHAR b1[BUFFER_LEN];
3843 #endif
3844 int btn = 1;
3845 PTSTR p;
3847 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3849 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3850 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3851 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3853 #ifndef _NO_EXTENSIONS
3854 #ifdef __WINE__
3855 /* insert unix file system button */
3856 b1[0] = '/';
3857 b1[1] = '\0';
3858 b1[2] = '\0';
3859 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3861 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3862 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3863 drivebarBtn.iString++;
3864 #endif
3865 #ifdef _SHELL_FOLDERS
3866 /* insert shell namespace button */
3867 load_string(b1, sizeof(b1)/sizeof(b1[0]), IDS_SHELL);
3868 b1[lstrlen(b1)+1] = '\0';
3869 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3871 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3872 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3873 drivebarBtn.iString++;
3874 #endif
3876 /* register windows drive root strings */
3877 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3878 #endif
3880 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3882 for(p=Globals.drives; *p; ) {
3883 #ifdef _NO_EXTENSIONS
3884 /* insert drive letter */
3885 TCHAR b[3] = {tolower(*p)};
3886 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3887 #endif
3888 switch(GetDriveType(p)) {
3889 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3890 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3891 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3892 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3893 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3896 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3897 drivebarBtn.idCommand++;
3898 drivebarBtn.iString++;
3900 while(*p++);
3904 static void refresh_drives(void)
3906 RECT rect;
3908 /* destroy drive bar */
3909 DestroyWindow(Globals.hdrivebar);
3910 Globals.hdrivebar = 0;
3912 /* re-create drive bar */
3913 create_drive_bar();
3915 /* update window layout */
3916 GetClientRect(Globals.hMainWnd, &rect);
3917 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3921 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3923 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3925 if (PtrToUlong(hinst) <= 32) {
3926 display_error(hwnd, GetLastError());
3927 return FALSE;
3930 return TRUE;
3934 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3936 TCHAR cmd[MAX_PATH];
3938 #ifdef _SHELL_FOLDERS
3939 if (entry->etype == ET_SHELL) {
3940 BOOL ret = TRUE;
3942 SHELLEXECUTEINFO shexinfo;
3944 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3945 shexinfo.fMask = SEE_MASK_IDLIST;
3946 shexinfo.hwnd = hwnd;
3947 shexinfo.lpVerb = NULL;
3948 shexinfo.lpFile = NULL;
3949 shexinfo.lpParameters = NULL;
3950 shexinfo.lpDirectory = NULL;
3951 shexinfo.nShow = nCmdShow;
3952 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3954 if (!ShellExecuteEx(&shexinfo)) {
3955 display_error(hwnd, GetLastError());
3956 ret = FALSE;
3959 if (shexinfo.lpIDList != entry->pidl)
3960 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3962 return ret;
3964 #endif
3966 get_path(entry, cmd);
3968 /* start program, open document... */
3969 return launch_file(hwnd, cmd, nCmdShow);
3973 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3975 Entry* entry = pane->cur;
3977 if (!entry)
3978 return;
3980 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3981 int scanned_old = entry->scanned;
3983 if (!scanned_old)
3985 int idx = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
3986 scan_entry(child, entry, idx, hwnd);
3989 #ifndef _NO_EXTENSIONS
3990 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3991 return;
3992 #endif
3994 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3995 entry = child->left.cur->up;
3996 collapse_entry(&child->left, entry);
3997 goto focus_entry;
3998 } else if (entry->expanded)
3999 collapse_entry(pane, child->left.cur);
4000 else {
4001 expand_entry(child, child->left.cur);
4003 if (!pane->treePane) focus_entry: {
4004 int idxstart = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
4005 int idx = SendMessage(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
4006 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
4007 set_curdir(child, entry, idx, hwnd);
4011 if (!scanned_old) {
4012 calc_widths(pane, FALSE);
4014 #ifndef _NO_EXTENSIONS
4015 set_header(pane);
4016 #endif
4018 } else {
4019 if (GetKeyState(VK_MENU) < 0)
4020 show_properties_dlg(entry, child->hwnd);
4021 else
4022 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
4027 static BOOL pane_command(Pane* pane, UINT cmd)
4029 switch(cmd) {
4030 case ID_VIEW_NAME:
4031 if (pane->visible_cols) {
4032 pane->visible_cols = 0;
4033 calc_widths(pane, TRUE);
4034 #ifndef _NO_EXTENSIONS
4035 set_header(pane);
4036 #endif
4037 InvalidateRect(pane->hwnd, 0, TRUE);
4038 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
4039 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
4040 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4042 break;
4044 case ID_VIEW_ALL_ATTRIBUTES:
4045 if (pane->visible_cols != COL_ALL) {
4046 pane->visible_cols = COL_ALL;
4047 calc_widths(pane, TRUE);
4048 #ifndef _NO_EXTENSIONS
4049 set_header(pane);
4050 #endif
4051 InvalidateRect(pane->hwnd, 0, TRUE);
4052 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
4053 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
4054 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4056 break;
4058 #ifndef _NO_EXTENSIONS
4059 case ID_PREFERRED_SIZES: {
4060 calc_widths(pane, TRUE);
4061 set_header(pane);
4062 InvalidateRect(pane->hwnd, 0, TRUE);
4063 break;}
4064 #endif
4066 /* TODO: more command ids... */
4068 default:
4069 return FALSE;
4072 return TRUE;
4076 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
4078 if (child->sortOrder != sortOrder) {
4079 child->sortOrder = sortOrder;
4080 refresh_child(child);
4084 static void update_view_menu(ChildWnd* child)
4086 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4087 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4088 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4089 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4093 static BOOL is_directory(LPCTSTR target)
4095 /*TODO correctly handle UNIX paths */
4096 DWORD target_attr = GetFileAttributes(target);
4098 if (target_attr == INVALID_FILE_ATTRIBUTES)
4099 return FALSE;
4101 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4104 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4106 TCHAR path[MAX_PATH];
4107 int len;
4109 get_path(pane->cur, path);
4111 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4112 return FALSE;
4114 get_path(pane->cur, source);
4116 /* convert relative targets to absolute paths */
4117 if (path[0]!='/' && path[1]!=':') {
4118 get_path(pane->cur->up, target);
4119 len = lstrlen(target);
4121 if (target[len-1]!='\\' && target[len-1]!='/')
4122 target[len++] = '/';
4124 lstrcpy(target+len, path);
4125 } else
4126 lstrcpy(target, path);
4128 /* If the target already exists as directory, create a new target below this. */
4129 if (is_directory(path)) {
4130 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4131 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4133 _tsplitpath(source, NULL, NULL, fname, ext);
4135 wsprintf(target, sAppend, path, fname, ext);
4138 return TRUE;
4142 static IContextMenu2* s_pctxmenu2 = NULL;
4143 static IContextMenu3* s_pctxmenu3 = NULL;
4145 static void CtxMenu_reset(void)
4147 s_pctxmenu2 = NULL;
4148 s_pctxmenu3 = NULL;
4151 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4153 IContextMenu* pcm = NULL;
4155 CtxMenu_reset();
4157 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4158 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4159 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4160 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4162 if (pcm) {
4163 IContextMenu_Release(pcm1);
4164 return pcm;
4165 } else
4166 return pcm1;
4169 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4171 if (s_pctxmenu3) {
4172 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4173 return TRUE;
4176 if (s_pctxmenu2)
4177 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4178 return TRUE;
4180 return FALSE;
4184 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4186 IContextMenu* pcm;
4187 BOOL executed = FALSE;
4189 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4190 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4192 if (SUCCEEDED(hr)) {
4193 HMENU hmenu = CreatePopupMenu();
4195 pcm = CtxMenu_query_interfaces(pcm);
4197 if (hmenu) {
4198 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4200 if (SUCCEEDED(hr)) {
4201 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4203 CtxMenu_reset();
4205 if (idCmd) {
4206 CMINVOKECOMMANDINFO cmi;
4208 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4209 cmi.fMask = 0;
4210 cmi.hwnd = hwndParent;
4211 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4212 cmi.lpParameters = NULL;
4213 cmi.lpDirectory = NULL;
4214 cmi.nShow = SW_SHOWNORMAL;
4215 cmi.dwHotKey = 0;
4216 cmi.hIcon = 0;
4218 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4219 executed = TRUE;
4221 } else
4222 CtxMenu_reset();
4225 IContextMenu_Release(pcm);
4228 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4232 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4234 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4235 ASSERT(child);
4237 switch(nmsg) {
4238 case WM_DRAWITEM: {
4239 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4240 Entry* entry = (Entry*) dis->itemData;
4242 if (dis->CtlID == IDW_TREE_LEFT)
4243 draw_item(&child->left, dis, entry, -1);
4244 else if (dis->CtlID == IDW_TREE_RIGHT)
4245 draw_item(&child->right, dis, entry, -1);
4246 else
4247 goto draw_menu_item;
4249 return TRUE;}
4251 case WM_CREATE:
4252 InitChildWindow(child);
4253 break;
4255 case WM_NCDESTROY:
4256 free_child_window(child);
4257 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4258 break;
4260 case WM_PAINT: {
4261 PAINTSTRUCT ps;
4262 HBRUSH lastBrush;
4263 RECT rt;
4264 GetClientRect(hwnd, &rt);
4265 BeginPaint(hwnd, &ps);
4266 rt.left = child->split_pos-SPLIT_WIDTH/2;
4267 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4268 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4269 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4270 SelectObject(ps.hdc, lastBrush);
4271 #ifdef _NO_EXTENSIONS
4272 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4273 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4274 #endif
4275 EndPaint(hwnd, &ps);
4276 break;}
4278 case WM_SETCURSOR:
4279 if (LOWORD(lparam) == HTCLIENT) {
4280 POINT pt;
4281 GetCursorPos(&pt);
4282 ScreenToClient(hwnd, &pt);
4284 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4285 SetCursor(LoadCursor(0, IDC_SIZEWE));
4286 return TRUE;
4289 goto def;
4291 case WM_LBUTTONDOWN: {
4292 RECT rt;
4293 int x = (short)LOWORD(lparam);
4295 GetClientRect(hwnd, &rt);
4297 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4298 last_split = child->split_pos;
4299 #ifdef _NO_EXTENSIONS
4300 draw_splitbar(hwnd, last_split);
4301 #endif
4302 SetCapture(hwnd);
4305 break;}
4307 case WM_LBUTTONUP:
4308 if (GetCapture() == hwnd) {
4309 #ifdef _NO_EXTENSIONS
4310 RECT rt;
4311 int x = (short)LOWORD(lparam);
4312 draw_splitbar(hwnd, last_split);
4313 last_split = -1;
4314 GetClientRect(hwnd, &rt);
4315 child->split_pos = x;
4316 resize_tree(child, rt.right, rt.bottom);
4317 #endif
4318 ReleaseCapture();
4320 break;
4322 #ifdef _NO_EXTENSIONS
4323 case WM_CAPTURECHANGED:
4324 if (GetCapture()==hwnd && last_split>=0)
4325 draw_splitbar(hwnd, last_split);
4326 break;
4327 #endif
4329 case WM_KEYDOWN:
4330 if (wparam == VK_ESCAPE)
4331 if (GetCapture() == hwnd) {
4332 RECT rt;
4333 #ifdef _NO_EXTENSIONS
4334 draw_splitbar(hwnd, last_split);
4335 #else
4336 child->split_pos = last_split;
4337 #endif
4338 GetClientRect(hwnd, &rt);
4339 resize_tree(child, rt.right, rt.bottom);
4340 last_split = -1;
4341 ReleaseCapture();
4342 SetCursor(LoadCursor(0, IDC_ARROW));
4344 break;
4346 case WM_MOUSEMOVE:
4347 if (GetCapture() == hwnd) {
4348 RECT rt;
4349 int x = (short)LOWORD(lparam);
4351 #ifdef _NO_EXTENSIONS
4352 HDC hdc = GetDC(hwnd);
4353 GetClientRect(hwnd, &rt);
4355 rt.left = last_split-SPLIT_WIDTH/2;
4356 rt.right = last_split+SPLIT_WIDTH/2+1;
4357 InvertRect(hdc, &rt);
4359 last_split = x;
4360 rt.left = x-SPLIT_WIDTH/2;
4361 rt.right = x+SPLIT_WIDTH/2+1;
4362 InvertRect(hdc, &rt);
4364 ReleaseDC(hwnd, hdc);
4365 #else
4366 GetClientRect(hwnd, &rt);
4368 if (x>=0 && x<rt.right) {
4369 child->split_pos = x;
4370 resize_tree(child, rt.right, rt.bottom);
4371 rt.left = x-SPLIT_WIDTH/2;
4372 rt.right = x+SPLIT_WIDTH/2+1;
4373 InvalidateRect(hwnd, &rt, FALSE);
4374 UpdateWindow(child->left.hwnd);
4375 UpdateWindow(hwnd);
4376 UpdateWindow(child->right.hwnd);
4378 #endif
4380 break;
4382 #ifndef _NO_EXTENSIONS
4383 case WM_GETMINMAXINFO:
4384 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4386 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4388 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4389 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4390 break;}
4391 #endif /* _NO_EXTENSIONS */
4393 case WM_SETFOCUS:
4394 if (SetCurrentDirectory(child->path))
4395 set_space_status();
4396 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4397 break;
4399 case WM_DISPATCH_COMMAND: {
4400 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4402 switch(LOWORD(wparam)) {
4403 case ID_WINDOW_NEW: {
4404 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4406 if (!create_child_window(new_child))
4407 HeapFree(GetProcessHeap(), 0, new_child);
4409 break;}
4411 case ID_REFRESH:
4412 refresh_drives();
4413 refresh_child(child);
4414 break;
4416 case ID_ACTIVATE:
4417 activate_entry(child, pane, hwnd);
4418 break;
4420 case ID_FILE_MOVE: {
4421 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4423 if (prompt_target(pane, source, target)) {
4424 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4426 source[lstrlen(source)+1] = '\0';
4427 target[lstrlen(target)+1] = '\0';
4429 if (!SHFileOperation(&shfo))
4430 refresh_child(child);
4432 break;}
4434 case ID_FILE_COPY: {
4435 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4437 if (prompt_target(pane, source, target)) {
4438 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4440 source[lstrlen(source)+1] = '\0';
4441 target[lstrlen(target)+1] = '\0';
4443 if (!SHFileOperation(&shfo))
4444 refresh_child(child);
4446 break;}
4448 case ID_FILE_DELETE: {
4449 TCHAR path[BUFFER_LEN];
4450 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
4452 get_path(pane->cur, path);
4454 path[lstrlen(path)+1] = '\0';
4456 if (!SHFileOperation(&shfo))
4457 refresh_child(child);
4458 break;}
4460 case ID_VIEW_SORT_NAME:
4461 set_sort_order(child, SORT_NAME);
4462 break;
4464 case ID_VIEW_SORT_TYPE:
4465 set_sort_order(child, SORT_EXT);
4466 break;
4468 case ID_VIEW_SORT_SIZE:
4469 set_sort_order(child, SORT_SIZE);
4470 break;
4472 case ID_VIEW_SORT_DATE:
4473 set_sort_order(child, SORT_DATE);
4474 break;
4476 case ID_VIEW_FILTER: {
4477 struct FilterDialog dlg;
4479 memset(&dlg, 0, sizeof(struct FilterDialog));
4480 lstrcpy(dlg.pattern, child->filter_pattern);
4481 dlg.flags = child->filter_flags;
4483 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4484 lstrcpy(child->filter_pattern, dlg.pattern);
4485 child->filter_flags = dlg.flags;
4486 refresh_right_pane(child);
4488 break;}
4490 case ID_VIEW_SPLIT: {
4491 last_split = child->split_pos;
4492 #ifdef _NO_EXTENSIONS
4493 draw_splitbar(hwnd, last_split);
4494 #endif
4495 SetCapture(hwnd);
4496 break;}
4498 case ID_EDIT_PROPERTIES:
4499 show_properties_dlg(pane->cur, child->hwnd);
4500 break;
4502 default:
4503 return pane_command(pane, LOWORD(wparam));
4506 return TRUE;}
4508 case WM_COMMAND: {
4509 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4511 switch(HIWORD(wparam)) {
4512 case LBN_SELCHANGE: {
4513 int idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4514 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4516 if (pane == &child->left)
4517 set_curdir(child, entry, idx, hwnd);
4518 else
4519 pane->cur = entry;
4520 break;}
4522 case LBN_DBLCLK:
4523 activate_entry(child, pane, hwnd);
4524 break;
4526 break;}
4528 #ifndef _NO_EXTENSIONS
4529 case WM_NOTIFY: {
4530 NMHDR* pnmh = (NMHDR*) lparam;
4531 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4532 #endif
4534 #ifdef _SHELL_FOLDERS
4535 case WM_CONTEXTMENU: {
4536 POINT pt, pt_clnt;
4537 Pane* pane;
4538 int idx;
4540 /* first select the current item in the listbox */
4541 HWND hpanel = (HWND) wparam;
4542 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4543 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4544 ScreenToClient(hpanel, &pt_clnt);
4545 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4546 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4548 /* now create the popup menu using shell namespace and IContextMenu */
4549 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4550 idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4552 if (idx != -1) {
4553 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4555 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4557 if (pidl_abs) {
4558 IShellFolder* parentFolder;
4559 LPCITEMIDLIST pidlLast;
4561 /* get and use the parent folder to display correct context menu in all cases */
4562 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4563 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4564 refresh_child(child);
4566 IShellFolder_Release(parentFolder);
4569 IMalloc_Free(Globals.iMalloc, pidl_abs);
4572 break;}
4573 #endif
4575 case WM_MEASUREITEM:
4576 draw_menu_item:
4577 if (!wparam) /* Is the message menu-related? */
4578 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4579 return TRUE;
4581 break;
4583 case WM_INITMENUPOPUP:
4584 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4585 return 0;
4587 update_view_menu(child);
4588 break;
4590 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4591 if (s_pctxmenu3) {
4592 LRESULT lResult = 0;
4594 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4596 return lResult;
4599 break;
4601 case WM_SIZE:
4602 if (wparam != SIZE_MINIMIZED)
4603 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4604 /* fall through */
4606 default: def:
4607 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4610 return 0;
4614 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4616 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4617 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4618 ASSERT(child);
4620 switch(nmsg) {
4621 #ifndef _NO_EXTENSIONS
4622 case WM_HSCROLL:
4623 set_header(pane);
4624 break;
4625 #endif
4627 case WM_SETFOCUS:
4628 child->focus_pane = pane==&child->right? 1: 0;
4629 SendMessage(hwnd, LB_SETSEL, TRUE, 1);
4630 /*TODO: check menu items */
4631 break;
4633 case WM_KEYDOWN:
4634 if (wparam == VK_TAB) {
4635 /*TODO: SetFocus(Globals.hdrivebar) */
4636 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4640 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4644 static void InitInstance(HINSTANCE hinstance)
4646 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4648 WNDCLASSEX wcFrame;
4649 WNDCLASS wcChild;
4650 ATOM hChildClass;
4651 int col;
4653 INITCOMMONCONTROLSEX icc = {
4654 sizeof(INITCOMMONCONTROLSEX),
4655 ICC_BAR_CLASSES
4658 HDC hdc = GetDC(0);
4660 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4662 InitCommonControlsEx(&icc);
4665 /* register frame window class */
4667 wcFrame.cbSize = sizeof(WNDCLASSEX);
4668 wcFrame.style = 0;
4669 wcFrame.lpfnWndProc = FrameWndProc;
4670 wcFrame.cbClsExtra = 0;
4671 wcFrame.cbWndExtra = 0;
4672 wcFrame.hInstance = hinstance;
4673 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4674 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4675 wcFrame.hbrBackground = 0;
4676 wcFrame.lpszMenuName = 0;
4677 wcFrame.lpszClassName = sWINEFILEFRAME;
4678 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4679 MAKEINTRESOURCE(IDI_WINEFILE),
4680 IMAGE_ICON,
4681 GetSystemMetrics(SM_CXSMICON),
4682 GetSystemMetrics(SM_CYSMICON),
4683 LR_SHARED);
4685 Globals.hframeClass = RegisterClassEx(&wcFrame);
4688 /* register tree windows class */
4690 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4691 wcChild.lpfnWndProc = ChildWndProc;
4692 wcChild.cbClsExtra = 0;
4693 wcChild.cbWndExtra = 0;
4694 wcChild.hInstance = hinstance;
4695 wcChild.hIcon = 0;
4696 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4697 wcChild.hbrBackground = 0;
4698 wcChild.lpszMenuName = 0;
4699 wcChild.lpszClassName = sWINEFILETREE;
4701 hChildClass = RegisterClass(&wcChild);
4704 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4706 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4708 ReleaseDC(0, hdc);
4710 Globals.hInstance = hinstance;
4712 #ifdef _SHELL_FOLDERS
4713 CoInitialize(NULL);
4714 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4715 SHGetDesktopFolder(&Globals.iDesktop);
4716 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4717 #endif
4719 /* load column strings */
4720 col = 1;
4722 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_NAME);
4723 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SIZE);
4724 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_CDATE);
4725 #ifndef _NO_EXTENSIONS
4726 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ADATE);
4727 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_MDATE);
4728 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_IDX);
4729 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_LINKS);
4730 #endif
4731 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ATTR);
4732 #ifndef _NO_EXTENSIONS
4733 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SEC);
4734 #endif
4738 static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4740 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4742 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4743 ChildWnd* child;
4744 HMENU hMenuFrame, hMenuWindow;
4745 windowOptions opts;
4747 CLIENTCREATESTRUCT ccs;
4749 if (Globals.hMainWnd)
4750 return;
4752 opts = load_registry_settings();
4753 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4754 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4756 Globals.hMenuFrame = hMenuFrame;
4757 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4758 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4760 ccs.hWindowMenu = hMenuWindow;
4761 ccs.idFirstChild = IDW_FIRST_CHILD;
4764 /* create main window */
4765 Globals.hMainWnd = CreateWindowEx(0, MAKEINTRESOURCE(Globals.hframeClass), RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4766 opts.start_x, opts.start_y, opts.width, opts.height,
4767 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4770 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4771 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4772 0, 0, 0, 0,
4773 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4775 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4776 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4778 create_drive_bar();
4781 TBBUTTON toolbarBtns[] = {
4782 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4783 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4784 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4785 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4786 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4787 /*TODO
4788 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4789 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4790 */ };
4792 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4793 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4794 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4795 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4798 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4799 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4801 /* CreateStatusWindow does not accept WS_BORDER
4802 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4803 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4804 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4806 /*TODO: read paths from registry */
4808 if (!path || !*path) {
4809 GetCurrentDirectory(MAX_PATH, buffer);
4810 path = buffer;
4813 ShowWindow(Globals.hMainWnd, cmdshow);
4815 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4816 /* Shell Namespace as default: */
4817 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4818 #else
4819 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4820 #endif
4822 child->pos.showCmd = SW_SHOWMAXIMIZED;
4823 child->pos.rcNormalPosition.left = 0;
4824 child->pos.rcNormalPosition.top = 0;
4825 child->pos.rcNormalPosition.right = 320;
4826 child->pos.rcNormalPosition.bottom = 280;
4828 if (!create_child_window(child))
4829 HeapFree(GetProcessHeap(), 0, child);
4831 SetWindowPlacement(child->hwnd, &child->pos);
4833 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4835 Globals.prescan_node = FALSE;
4837 UpdateWindow(Globals.hMainWnd);
4839 if (path && path[0])
4841 int index,count;
4842 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4843 TCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4845 memset(name,0,sizeof(name));
4846 memset(name,0,sizeof(ext));
4847 _tsplitpath(path, drv, dir, name, ext);
4848 if (name[0])
4850 count = SendMessage(child->right.hwnd, LB_GETCOUNT, 0, 0);
4851 lstrcpy(fullname,name);
4852 lstrcat(fullname,ext);
4854 for (index = 0; index < count; index ++)
4856 Entry* entry = (Entry*) SendMessage(child->right.hwnd, LB_GETITEMDATA, index, 0);
4857 if (lstrcmp(entry->data.cFileName,fullname)==0 ||
4858 lstrcmp(entry->data.cAlternateFileName,fullname)==0)
4860 SendMessage(child->right.hwnd, LB_SETCURSEL, index, 0);
4861 SetFocus(child->right.hwnd);
4862 break;
4869 static void ExitInstance(void)
4871 #ifdef _SHELL_FOLDERS
4872 IShellFolder_Release(Globals.iDesktop);
4873 IMalloc_Release(Globals.iMalloc);
4874 CoUninitialize();
4875 #endif
4877 DeleteObject(Globals.hfont);
4878 ImageList_Destroy(Globals.himl);
4881 #ifdef _NO_EXTENSIONS
4883 /* search for already running win[e]files */
4885 static int g_foundPrevInstance = 0;
4887 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4889 TCHAR cls[128];
4891 GetClassName(hwnd, cls, 128);
4893 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4894 g_foundPrevInstance++;
4895 return FALSE;
4898 return TRUE;
4901 /* search for window of given class name to allow only one running instance */
4902 static int find_window_class(LPCTSTR classname)
4904 EnumWindows(EnumWndProc, (LPARAM)classname);
4906 if (g_foundPrevInstance)
4907 return 1;
4909 return 0;
4912 #endif
4914 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4916 MSG msg;
4918 InitInstance(hinstance);
4920 show_frame(0, cmdshow, path);
4922 while(GetMessage(&msg, 0, 0, 0)) {
4923 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4924 continue;
4926 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4927 continue;
4929 TranslateMessage(&msg);
4930 DispatchMessage(&msg);
4933 ExitInstance();
4935 return msg.wParam;
4939 #if defined(UNICODE) && defined(_MSC_VER)
4940 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4941 #else
4942 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4943 #endif
4945 #ifdef _NO_EXTENSIONS
4946 if (find_window_class(sWINEFILEFRAME))
4947 return 1;
4948 #endif
4950 #if defined(UNICODE) && !defined(_MSC_VER)
4951 { /* convert ANSI cmdline into WCS path string */
4952 TCHAR buffer[MAX_PATH];
4953 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4954 winefile_main(hinstance, cmdshow, buffer);
4956 #else
4957 winefile_main(hinstance, cmdshow, cmdline);
4958 #endif
4960 return 0;