winefile: Change choose_font() and init_output() to the W form.
[wine/multimedia.git] / programs / winefile / winefile.c
blob0574c3703cdd2069e8d1f34b3a0e9b2fbe194772
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'};
70 enum ENTRY_TYPE {
71 ET_WINDOWS,
72 ET_UNIX,
73 #ifdef _SHELL_FOLDERS
74 ET_SHELL
75 #endif
78 typedef struct _Entry {
79 struct _Entry* next;
80 struct _Entry* down;
81 struct _Entry* up;
83 BOOL expanded;
84 BOOL scanned;
85 int level;
87 WIN32_FIND_DATA data;
89 #ifndef _NO_EXTENSIONS
90 BY_HANDLE_FILE_INFORMATION bhfi;
91 BOOL bhfi_valid;
92 enum ENTRY_TYPE etype;
93 #endif
94 #ifdef _SHELL_FOLDERS
95 LPITEMIDLIST pidl;
96 IShellFolder* folder;
97 HICON hicon;
98 #endif
99 } Entry;
101 typedef struct {
102 Entry entry;
103 TCHAR path[MAX_PATH];
104 TCHAR volname[_MAX_FNAME];
105 TCHAR fs[_MAX_DIR];
106 DWORD drive_type;
107 DWORD fs_flags;
108 } Root;
110 enum COLUMN_FLAGS {
111 COL_SIZE = 0x01,
112 COL_DATE = 0x02,
113 COL_TIME = 0x04,
114 COL_ATTRIBUTES = 0x08,
115 COL_DOSNAMES = 0x10,
116 #ifdef _NO_EXTENSIONS
117 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
118 #else
119 COL_INDEX = 0x20,
120 COL_LINKS = 0x40,
121 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
122 #endif
125 typedef enum {
126 SORT_NAME,
127 SORT_EXT,
128 SORT_SIZE,
129 SORT_DATE
130 } SORT_ORDER;
132 typedef struct {
133 HWND hwnd;
134 #ifndef _NO_EXTENSIONS
135 HWND hwndHeader;
136 #endif
138 #ifndef _NO_EXTENSIONS
139 #define COLUMNS 10
140 #else
141 #define COLUMNS 5
142 #endif
143 int widths[COLUMNS];
144 int positions[COLUMNS+1];
146 BOOL treePane;
147 int visible_cols;
148 Entry* root;
149 Entry* cur;
150 } Pane;
152 typedef struct {
153 HWND hwnd;
154 Pane left;
155 Pane right;
156 int focus_pane; /* 0: left 1: right */
157 WINDOWPLACEMENT pos;
158 int split_pos;
159 BOOL header_wdths_ok;
161 TCHAR path[MAX_PATH];
162 TCHAR filter_pattern[MAX_PATH];
163 int filter_flags;
164 Root root;
166 SORT_ORDER sortOrder;
167 } ChildWnd;
171 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd);
172 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
173 static void refresh_child(ChildWnd* child);
174 static void refresh_drives(void);
175 static void get_path(Entry* dir, PTSTR path);
176 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols);
178 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
179 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
180 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
183 /* globals */
184 WINEFILE_GLOBALS Globals;
186 static int last_split;
188 /* some common string constants */
189 static const TCHAR sEmpty[] = {'\0'};
190 static const WCHAR sSpace[] = {' ', '\0'};
191 static const TCHAR sNumFmt[] = {'%','d','\0'};
192 static const TCHAR sQMarks[] = {'?','?','?','\0'};
194 /* window class names */
195 static const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
196 static const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
198 #ifdef _MSC_VER
199 /* #define LONGLONGARG _T("I64") */
200 static const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'};
201 static const TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'};
202 #else
203 /* #define LONGLONGARG _T("L") */
204 static const TCHAR sLongHexFmt[] = {'%','L','X','\0'};
205 static const TCHAR sLongNumFmt[] = {'%','L','d','\0'};
206 #endif
209 /* load resource string */
210 static LPTSTR load_string(LPTSTR buffer, UINT id)
212 LoadString(Globals.hInstance, id, buffer, BUFFER_LEN);
214 return buffer;
217 #define RS(b, i) load_string(b, i)
220 /* display error message for the specified WIN32 error code */
221 static void display_error(HWND hwnd, DWORD error)
223 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
224 PTSTR msg;
226 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
227 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
228 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
229 else
230 MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
232 LocalFree(msg);
236 /* display network error message using WNetGetLastError() */
237 static void display_network_error(HWND hwnd)
239 TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
240 DWORD error;
242 if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
243 MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
246 static VOID WineLicense(HWND Wnd)
248 WCHAR cap[20], text[1024];
249 LoadStringW(Globals.hInstance, IDS_LICENSE, text, 1024);
250 LoadStringW(Globals.hInstance, IDS_LICENSE_CAPTION, cap, 20);
251 MessageBoxW(Wnd, text, cap, MB_ICONINFORMATION | MB_OK);
254 static VOID WineWarranty(HWND Wnd)
256 WCHAR cap[20], text[1024];
257 LoadStringW(Globals.hInstance, IDS_WARRANTY, text, 1024);
258 LoadStringW(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, 20);
259 MessageBoxW(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
262 static inline BOOL get_check(HWND hwnd, INT id)
264 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
267 static inline INT set_check(HWND hwnd, INT id, BOOL on)
269 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
272 static inline void choose_font(HWND hwnd)
274 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
275 CHOOSEFONTW chFont;
276 LOGFONTW lFont;
278 HDC hdc = GetDC(hwnd);
279 chFont.lStructSize = sizeof(CHOOSEFONT);
280 chFont.hwndOwner = hwnd;
281 chFont.hDC = NULL;
282 chFont.lpLogFont = &lFont;
283 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
284 chFont.rgbColors = RGB(0,0,0);
285 chFont.lCustData = 0;
286 chFont.lpfnHook = NULL;
287 chFont.lpTemplateName = NULL;
288 chFont.hInstance = Globals.hInstance;
289 chFont.lpszStyle = NULL;
290 chFont.nFontType = SIMULATED_FONTTYPE;
291 chFont.nSizeMin = 0;
292 chFont.nSizeMax = 24;
294 if (ChooseFontW(&chFont)) {
295 HWND childWnd;
296 HFONT hFontOld;
298 DeleteObject(Globals.hfont);
299 Globals.hfont = CreateFontIndirectW(&lFont);
300 hFontOld = SelectObject(hdc, Globals.hfont);
301 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
303 /* change font in all open child windows */
304 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
305 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
306 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
307 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
308 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
309 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
310 InvalidateRect(child->left.hwnd, NULL, TRUE);
311 InvalidateRect(child->right.hwnd, NULL, TRUE);
314 SelectObject(hdc, hFontOld);
316 else if (CommDlgExtendedError()) {
317 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
318 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
319 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
322 ReleaseDC(hwnd, hdc);
325 #ifdef __WINE__
327 #ifdef UNICODE
329 /* call vswprintf() in msvcrt.dll */
330 /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */
331 static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...)
333 static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL;
334 va_list ap;
335 int ret;
337 if (!pvswprintf) {
338 HMODULE hModMsvcrt = LoadLibraryA("msvcrt");
339 pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf");
342 va_start(ap, fmt);
343 ret = (*pvswprintf)(buffer, fmt, ap);
344 va_end(ap);
346 return ret;
349 static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c)
351 LPCWSTR p = str;
353 while(*p)
354 ++p;
356 do {
357 if (--p < str)
358 return NULL;
359 } while(*p != c);
361 return p;
364 #define _tcsrchr my_wcsrchr
365 #else /* UNICODE */
366 #define _tcsrchr strrchr
367 #endif /* UNICODE */
369 #endif /* __WINE__ */
372 /* allocate and initialise a directory entry */
373 static Entry* alloc_entry(void)
375 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
377 #ifdef _SHELL_FOLDERS
378 entry->pidl = NULL;
379 entry->folder = NULL;
380 entry->hicon = 0;
381 #endif
383 return entry;
386 /* free a directory entry */
387 static void free_entry(Entry* entry)
389 #ifdef _SHELL_FOLDERS
390 if (entry->hicon && entry->hicon!=(HICON)-1)
391 DestroyIcon(entry->hicon);
393 if (entry->folder && entry->folder!=Globals.iDesktop)
394 IShellFolder_Release(entry->folder);
396 if (entry->pidl)
397 IMalloc_Free(Globals.iMalloc, entry->pidl);
398 #endif
400 HeapFree(GetProcessHeap(), 0, entry);
403 /* recursively free all child entries */
404 static void free_entries(Entry* dir)
406 Entry *entry, *next=dir->down;
408 if (next) {
409 dir->down = 0;
411 do {
412 entry = next;
413 next = entry->next;
415 free_entries(entry);
416 free_entry(entry);
417 } while(next);
422 static void read_directory_win(Entry* dir, LPCTSTR path)
424 Entry* first_entry = NULL;
425 Entry* last = NULL;
426 Entry* entry;
428 int level = dir->level + 1;
429 WIN32_FIND_DATA w32fd;
430 HANDLE hFind;
431 #ifndef _NO_EXTENSIONS
432 HANDLE hFile;
433 #endif
435 TCHAR buffer[MAX_PATH], *p;
436 for(p=buffer; *path; )
437 *p++ = *path++;
439 *p++ = '\\';
440 p[0] = '*';
441 p[1] = '\0';
443 hFind = FindFirstFile(buffer, &w32fd);
445 if (hFind != INVALID_HANDLE_VALUE) {
446 do {
447 #ifdef _NO_EXTENSIONS
448 /* hide directory entry "." */
449 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
450 LPCTSTR name = w32fd.cFileName;
452 if (name[0]=='.' && name[1]=='\0')
453 continue;
455 #endif
456 entry = alloc_entry();
458 if (!first_entry)
459 first_entry = entry;
461 if (last)
462 last->next = entry;
464 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATA));
465 entry->down = NULL;
466 entry->up = dir;
467 entry->expanded = FALSE;
468 entry->scanned = FALSE;
469 entry->level = level;
471 #ifndef _NO_EXTENSIONS
472 entry->etype = ET_WINDOWS;
473 entry->bhfi_valid = FALSE;
475 lstrcpy(p, entry->data.cFileName);
477 hFile = CreateFile(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
478 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
480 if (hFile != INVALID_HANDLE_VALUE) {
481 if (GetFileInformationByHandle(hFile, &entry->bhfi))
482 entry->bhfi_valid = TRUE;
484 CloseHandle(hFile);
486 #endif
488 last = entry;
489 } while(FindNextFile(hFind, &w32fd));
491 if (last)
492 last->next = NULL;
494 FindClose(hFind);
497 dir->down = first_entry;
498 dir->scanned = TRUE;
502 static Entry* find_entry_win(Entry* dir, LPCTSTR name)
504 Entry* entry;
506 for(entry=dir->down; entry; entry=entry->next) {
507 LPCTSTR p = name;
508 LPCTSTR q = entry->data.cFileName;
510 do {
511 if (!*p || *p == '\\' || *p == '/')
512 return entry;
513 } while(tolower(*p++) == tolower(*q++));
515 p = name;
516 q = entry->data.cAlternateFileName;
518 do {
519 if (!*p || *p == '\\' || *p == '/')
520 return entry;
521 } while(tolower(*p++) == tolower(*q++));
524 return 0;
528 static Entry* read_tree_win(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
530 TCHAR buffer[MAX_PATH];
531 Entry* entry = &root->entry;
532 LPCTSTR s = path;
533 PTSTR d = buffer;
535 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
537 #ifndef _NO_EXTENSIONS
538 entry->etype = ET_WINDOWS;
539 #endif
541 while(entry) {
542 while(*s && *s != '\\' && *s != '/')
543 *d++ = *s++;
545 while(*s == '\\' || *s == '/')
546 s++;
548 *d++ = '\\';
549 *d = '\0';
551 read_directory(entry, buffer, sortOrder, hwnd);
553 if (entry->down)
554 entry->expanded = TRUE;
556 if (!*s)
557 break;
559 entry = find_entry_win(entry, s);
562 SetCursor(old_cursor);
564 return entry;
568 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
570 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
572 struct tm* tm = gmtime(t);
573 SYSTEMTIME stime;
575 if (!tm)
576 return FALSE;
578 stime.wYear = tm->tm_year+1900;
579 stime.wMonth = tm->tm_mon+1;
580 /* stime.wDayOfWeek */
581 stime.wDay = tm->tm_mday;
582 stime.wHour = tm->tm_hour;
583 stime.wMinute = tm->tm_min;
584 stime.wSecond = tm->tm_sec;
586 return SystemTimeToFileTime(&stime, ftime);
589 static void read_directory_unix(Entry* dir, LPCTSTR path)
591 Entry* first_entry = NULL;
592 Entry* last = NULL;
593 Entry* entry;
594 DIR* pdir;
596 int level = dir->level + 1;
597 #ifdef UNICODE
598 char cpath[MAX_PATH];
600 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
601 #else
602 const char* cpath = path;
603 #endif
605 pdir = opendir(cpath);
607 if (pdir) {
608 struct stat st;
609 struct dirent* ent;
610 char buffer[MAX_PATH], *p;
611 const char* s;
613 for(p=buffer,s=cpath; *s; )
614 *p++ = *s++;
616 if (p==buffer || p[-1]!='/')
617 *p++ = '/';
619 while((ent=readdir(pdir))) {
620 entry = alloc_entry();
622 if (!first_entry)
623 first_entry = entry;
625 if (last)
626 last->next = entry;
628 entry->etype = ET_UNIX;
630 strcpy(p, ent->d_name);
631 #ifdef UNICODE
632 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
633 #else
634 lstrcpy(entry->data.cFileName, p);
635 #endif
637 if (!stat(buffer, &st)) {
638 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
640 if (S_ISDIR(st.st_mode))
641 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
643 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
644 entry->data.nFileSizeHigh = st.st_size >> 32;
646 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
647 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
648 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
650 entry->bhfi.nFileIndexLow = ent->d_ino;
651 entry->bhfi.nFileIndexHigh = 0;
653 entry->bhfi.nNumberOfLinks = st.st_nlink;
655 entry->bhfi_valid = TRUE;
656 } else {
657 entry->data.nFileSizeLow = 0;
658 entry->data.nFileSizeHigh = 0;
659 entry->bhfi_valid = FALSE;
662 entry->down = NULL;
663 entry->up = dir;
664 entry->expanded = FALSE;
665 entry->scanned = FALSE;
666 entry->level = level;
668 last = entry;
671 if (last)
672 last->next = NULL;
674 closedir(pdir);
677 dir->down = first_entry;
678 dir->scanned = TRUE;
681 static Entry* find_entry_unix(Entry* dir, LPCTSTR name)
683 Entry* entry;
685 for(entry=dir->down; entry; entry=entry->next) {
686 LPCTSTR p = name;
687 LPCTSTR q = entry->data.cFileName;
689 do {
690 if (!*p || *p == '/')
691 return entry;
692 } while(*p++ == *q++);
695 return 0;
698 static Entry* read_tree_unix(Root* root, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
700 TCHAR buffer[MAX_PATH];
701 Entry* entry = &root->entry;
702 LPCTSTR s = path;
703 PTSTR d = buffer;
705 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
707 entry->etype = ET_UNIX;
709 while(entry) {
710 while(*s && *s != '/')
711 *d++ = *s++;
713 while(*s == '/')
714 s++;
716 *d++ = '/';
717 *d = '\0';
719 read_directory(entry, buffer, sortOrder, hwnd);
721 if (entry->down)
722 entry->expanded = TRUE;
724 if (!*s)
725 break;
727 entry = find_entry_unix(entry, s);
730 SetCursor(old_cursor);
732 return entry;
735 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
738 #ifdef _SHELL_FOLDERS
740 #ifdef UNICODE
741 #define get_strret get_strretW
742 #define path_from_pidl path_from_pidlW
743 #else
744 #define get_strret get_strretA
745 #define path_from_pidl path_from_pidlA
746 #endif
749 static void free_strret(STRRET* str)
751 if (str->uType == STRRET_WSTR)
752 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
756 #ifndef UNICODE
758 static LPSTR strcpyn(LPSTR dest, LPCSTR source, size_t count)
760 LPCSTR s;
761 LPSTR d = dest;
763 for(s=source; count&&(*d++=*s++); )
764 count--;
766 return dest;
769 static void get_strretA(STRRET* str, const SHITEMID* shiid, LPSTR buffer, int len)
771 switch(str->uType) {
772 case STRRET_WSTR:
773 WideCharToMultiByte(CP_ACP, 0, str->UNION_MEMBER(pOleStr), -1, buffer, len, NULL, NULL);
774 break;
776 case STRRET_OFFSET:
777 strcpyn(buffer, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), len);
778 break;
780 case STRRET_CSTR:
781 strcpyn(buffer, str->UNION_MEMBER(cStr), len);
785 static HRESULT path_from_pidlA(IShellFolder* folder, LPITEMIDLIST pidl, LPSTR buffer, int len)
787 STRRET str;
789 /* SHGDN_FORPARSING: get full path of id list */
790 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
792 if (SUCCEEDED(hr)) {
793 get_strretA(&str, &pidl->mkid, buffer, len);
794 free_strret(&str);
795 } else
796 buffer[0] = '\0';
798 return hr;
801 #endif
803 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
805 LPCWSTR s;
806 LPWSTR d = dest;
808 for(s=source; count&&(*d++=*s++); )
809 count--;
811 return dest;
814 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
816 switch(str->uType) {
817 case STRRET_WSTR:
818 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
819 break;
821 case STRRET_OFFSET:
822 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
823 break;
825 case STRRET_CSTR:
826 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
831 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPTSTR buffer, int len, SHGDNF flags)
833 STRRET str;
835 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
837 if (SUCCEEDED(hr)) {
838 get_strret(&str, &pidl->mkid, buffer, len);
839 free_strret(&str);
840 } else
841 buffer[0] = '\0';
843 return hr;
847 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
849 STRRET str;
851 /* SHGDN_FORPARSING: get full path of id list */
852 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
854 if (SUCCEEDED(hr)) {
855 get_strretW(&str, &pidl->mkid, buffer, len);
856 free_strret(&str);
857 } else
858 buffer[0] = '\0';
860 return hr;
864 /* create an item id list from a file system path */
866 static LPITEMIDLIST get_path_pidl(LPTSTR path, HWND hwnd)
868 LPITEMIDLIST pidl;
869 HRESULT hr;
870 ULONG len;
872 #ifdef UNICODE
873 LPWSTR buffer = path;
874 #else
875 WCHAR buffer[MAX_PATH];
876 MultiByteToWideChar(CP_ACP, 0, path, -1, buffer, MAX_PATH);
877 #endif
879 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
880 if (FAILED(hr))
881 return NULL;
883 return pidl;
887 /* convert an item id list from relative to absolute (=relative to the desktop) format */
889 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
891 if (entry->up && entry->up->etype==ET_SHELL) {
892 IShellFolder* folder = entry->up->folder;
893 WCHAR buffer[MAX_PATH];
895 HRESULT hr = path_from_pidlW(folder, entry->pidl, buffer, MAX_PATH);
897 if (SUCCEEDED(hr)) {
898 LPITEMIDLIST pidl;
899 ULONG len;
901 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
903 if (SUCCEEDED(hr))
904 return pidl;
906 } else if (entry->etype == ET_WINDOWS) {
907 TCHAR path[MAX_PATH];
909 get_path(entry, path);
911 return get_path_pidl(path, hwnd);
912 } else if (entry->pidl)
913 return ILClone(entry->pidl);
915 return NULL;
919 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
921 IExtractIcon* pExtract;
923 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, 0, (LPVOID*)&pExtract))) {
924 TCHAR path[_MAX_PATH];
925 unsigned flags;
926 HICON hicon;
927 int idx;
929 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
930 if (!(flags & GIL_NOTFILENAME)) {
931 if (idx == -1)
932 idx = 0; /* special case for some control panel applications */
934 if ((int)ExtractIconEx(path, idx, 0, &hicon, 1) > 0)
935 flags &= ~GIL_DONTCACHE;
936 } else {
937 HICON hIconLarge = 0;
939 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
941 if (SUCCEEDED(hr))
942 DestroyIcon(hIconLarge);
945 return hicon;
949 return 0;
953 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
955 Entry* entry;
957 for(entry=dir->down; entry; entry=entry->next) {
958 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
959 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
960 return entry;
963 return 0;
966 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
968 Entry* entry = &root->entry;
969 Entry* next;
970 LPITEMIDLIST next_pidl = pidl;
971 IShellFolder* folder;
972 IShellFolder* child = NULL;
973 HRESULT hr;
975 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
977 #ifndef _NO_EXTENSIONS
978 entry->etype = ET_SHELL;
979 #endif
981 folder = Globals.iDesktop;
983 while(entry) {
984 entry->pidl = next_pidl;
985 entry->folder = folder;
987 if (!pidl->mkid.cb)
988 break;
990 /* copy first element of item idlist */
991 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
992 memcpy(next_pidl, pidl, pidl->mkid.cb);
993 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
995 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
996 if (!SUCCEEDED(hr))
997 break;
999 read_directory(entry, NULL, sortOrder, hwnd);
1001 if (entry->down)
1002 entry->expanded = TRUE;
1004 next = find_entry_shell(entry, next_pidl);
1005 if (!next)
1006 break;
1008 folder = child;
1009 entry = next;
1011 /* go to next element */
1012 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
1015 SetCursor(old_cursor);
1017 return entry;
1021 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* w32fdata)
1023 if (!(attribs & SFGAO_FILESYSTEM) ||
1024 FAILED(SHGetDataFromIDList(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATA)))) {
1025 WIN32_FILE_ATTRIBUTE_DATA fad;
1026 IDataObject* pDataObj;
1028 STGMEDIUM medium = {0, {0}, 0};
1029 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
1031 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
1033 if (SUCCEEDED(hr)) {
1034 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
1036 IDataObject_Release(pDataObj);
1038 if (SUCCEEDED(hr)) {
1039 LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal));
1040 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
1042 if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) {
1043 w32fdata->dwFileAttributes = fad.dwFileAttributes;
1044 w32fdata->ftCreationTime = fad.ftCreationTime;
1045 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
1046 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
1048 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1049 w32fdata->nFileSizeLow = fad.nFileSizeLow;
1050 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
1054 SetErrorMode(sem_org);
1056 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
1057 GlobalFree(medium.UNION_MEMBER(hGlobal));
1062 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
1063 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1065 if (attribs & SFGAO_READONLY)
1066 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
1068 if (attribs & SFGAO_COMPRESSED)
1069 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
1073 static void read_directory_shell(Entry* dir, HWND hwnd)
1075 IShellFolder* folder = dir->folder;
1076 int level = dir->level + 1;
1077 HRESULT hr;
1079 IShellFolder* child;
1080 IEnumIDList* idlist;
1082 Entry* first_entry = NULL;
1083 Entry* last = NULL;
1084 Entry* entry;
1086 if (!folder)
1087 return;
1089 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
1091 if (SUCCEEDED(hr)) {
1092 for(;;) {
1093 #define FETCH_ITEM_COUNT 32
1094 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
1095 SFGAOF attribs;
1096 ULONG cnt = 0;
1097 ULONG n;
1099 memset(pidls, 0, sizeof(pidls));
1101 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
1102 if (!SUCCEEDED(hr))
1103 break;
1105 if (hr == S_FALSE)
1106 break;
1108 for(n=0; n<cnt; ++n) {
1109 entry = alloc_entry();
1111 if (!first_entry)
1112 first_entry = entry;
1114 if (last)
1115 last->next = entry;
1117 memset(&entry->data, 0, sizeof(WIN32_FIND_DATA));
1118 entry->bhfi_valid = FALSE;
1120 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
1122 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
1124 if (SUCCEEDED(hr)) {
1125 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
1126 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
1128 entry->bhfi_valid = TRUE;
1129 } else
1130 attribs = 0;
1131 } else
1132 attribs = 0;
1134 entry->pidl = pidls[n];
1136 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1137 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1139 if (SUCCEEDED(hr))
1140 entry->folder = child;
1141 else
1142 entry->folder = NULL;
1144 else
1145 entry->folder = NULL;
1147 if (!entry->data.cFileName[0])
1148 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1150 /* get display icons for files and virtual objects */
1151 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1152 !(attribs & SFGAO_FILESYSTEM)) {
1153 entry->hicon = extract_icon(folder, pidls[n]);
1155 if (!entry->hicon)
1156 entry->hicon = (HICON)-1; /* don't try again later */
1159 entry->down = NULL;
1160 entry->up = dir;
1161 entry->expanded = FALSE;
1162 entry->scanned = FALSE;
1163 entry->level = level;
1165 #ifndef _NO_EXTENSIONS
1166 entry->etype = ET_SHELL;
1167 entry->bhfi_valid = FALSE;
1168 #endif
1170 last = entry;
1174 IEnumIDList_Release(idlist);
1177 if (last)
1178 last->next = NULL;
1180 dir->down = first_entry;
1181 dir->scanned = TRUE;
1184 #endif /* _SHELL_FOLDERS */
1187 /* sort order for different directory/file types */
1188 enum TYPE_ORDER {
1189 TO_DIR = 0,
1190 TO_DOT = 1,
1191 TO_DOTDOT = 2,
1192 TO_OTHER_DIR = 3,
1193 TO_FILE = 4
1196 /* distinguish between ".", ".." and any other directory names */
1197 static int TypeOrderFromDirname(LPCTSTR name)
1199 if (name[0] == '.') {
1200 if (name[1] == '\0')
1201 return TO_DOT; /* "." */
1203 if (name[1]=='.' && name[2]=='\0')
1204 return TO_DOTDOT; /* ".." */
1207 return TO_OTHER_DIR; /* anything else */
1210 /* directories first... */
1211 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
1213 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1214 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1216 /* Handle "." and ".." as special case and move them at the very first beginning. */
1217 if (order1==TO_DIR && order2==TO_DIR) {
1218 order1 = TypeOrderFromDirname(fd1->cFileName);
1219 order2 = TypeOrderFromDirname(fd2->cFileName);
1222 return order2==order1? 0: order1<order2? -1: 1;
1226 static int compareName(const void* arg1, const void* arg2)
1228 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1229 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1231 int cmp = compareType(fd1, fd2);
1232 if (cmp)
1233 return cmp;
1235 return lstrcmpi(fd1->cFileName, fd2->cFileName);
1238 static int compareExt(const void* arg1, const void* arg2)
1240 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1241 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1242 const TCHAR *name1, *name2, *ext1, *ext2;
1244 int cmp = compareType(fd1, fd2);
1245 if (cmp)
1246 return cmp;
1248 name1 = fd1->cFileName;
1249 name2 = fd2->cFileName;
1251 ext1 = _tcsrchr(name1, '.');
1252 ext2 = _tcsrchr(name2, '.');
1254 if (ext1)
1255 ext1++;
1256 else
1257 ext1 = sEmpty;
1259 if (ext2)
1260 ext2++;
1261 else
1262 ext2 = sEmpty;
1264 cmp = lstrcmpi(ext1, ext2);
1265 if (cmp)
1266 return cmp;
1268 return lstrcmpi(name1, name2);
1271 static int compareSize(const void* arg1, const void* arg2)
1273 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1274 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1276 int cmp = compareType(fd1, fd2);
1277 if (cmp)
1278 return cmp;
1280 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1282 if (cmp < 0)
1283 return -1;
1284 else if (cmp > 0)
1285 return 1;
1287 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1289 return cmp<0? -1: cmp>0? 1: 0;
1292 static int compareDate(const void* arg1, const void* arg2)
1294 const WIN32_FIND_DATA* fd1 = &(*(const Entry* const*)arg1)->data;
1295 const WIN32_FIND_DATA* fd2 = &(*(const Entry* const*)arg2)->data;
1297 int cmp = compareType(fd1, fd2);
1298 if (cmp)
1299 return cmp;
1301 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1305 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1306 compareName, /* SORT_NAME */
1307 compareExt, /* SORT_EXT */
1308 compareSize, /* SORT_SIZE */
1309 compareDate /* SORT_DATE */
1313 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1315 Entry* entry = dir->down;
1316 Entry** array, **p;
1317 int len;
1319 len = 0;
1320 for(entry=dir->down; entry; entry=entry->next)
1321 len++;
1323 if (len) {
1324 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1326 p = array;
1327 for(entry=dir->down; entry; entry=entry->next)
1328 *p++ = entry;
1330 /* call qsort with the appropriate compare function */
1331 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1333 dir->down = array[0];
1335 for(p=array; --len; p++)
1336 p[0]->next = p[1];
1338 (*p)->next = 0;
1340 HeapFree(GetProcessHeap(), 0, array);
1345 static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd)
1347 TCHAR buffer[MAX_PATH];
1348 Entry* entry;
1349 LPCTSTR s;
1350 PTSTR d;
1352 #ifdef _SHELL_FOLDERS
1353 if (dir->etype == ET_SHELL)
1355 read_directory_shell(dir, hwnd);
1357 if (Globals.prescan_node) {
1358 s = path;
1359 d = buffer;
1361 while(*s)
1362 *d++ = *s++;
1364 *d++ = '\\';
1366 for(entry=dir->down; entry; entry=entry->next)
1367 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1368 read_directory_shell(entry, hwnd);
1369 SortDirectory(entry, sortOrder);
1373 else
1374 #endif
1375 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1376 if (dir->etype == ET_UNIX)
1378 read_directory_unix(dir, path);
1380 if (Globals.prescan_node) {
1381 s = path;
1382 d = buffer;
1384 while(*s)
1385 *d++ = *s++;
1387 *d++ = '/';
1389 for(entry=dir->down; entry; entry=entry->next)
1390 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1391 lstrcpy(d, entry->data.cFileName);
1392 read_directory_unix(entry, buffer);
1393 SortDirectory(entry, sortOrder);
1397 else
1398 #endif
1400 read_directory_win(dir, path);
1402 if (Globals.prescan_node) {
1403 s = path;
1404 d = buffer;
1406 while(*s)
1407 *d++ = *s++;
1409 *d++ = '\\';
1411 for(entry=dir->down; entry; entry=entry->next)
1412 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1413 lstrcpy(d, entry->data.cFileName);
1414 read_directory_win(entry, buffer);
1415 SortDirectory(entry, sortOrder);
1420 SortDirectory(dir, sortOrder);
1424 static Entry* read_tree(Root* root, LPCTSTR path, LPITEMIDLIST pidl, LPTSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1426 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1427 static const TCHAR sSlash[] = {'/', '\0'};
1428 #endif
1429 static const TCHAR sBackslash[] = {'\\', '\0'};
1431 #ifdef _SHELL_FOLDERS
1432 if (pidl)
1434 /* read shell namespace tree */
1435 root->drive_type = DRIVE_UNKNOWN;
1436 drv[0] = '\\';
1437 drv[1] = '\0';
1438 load_string(root->volname, IDS_DESKTOP);
1439 root->fs_flags = 0;
1440 load_string(root->fs, IDS_SHELL);
1442 return read_tree_shell(root, pidl, sortOrder, hwnd);
1444 else
1445 #endif
1446 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1447 if (*path == '/')
1449 /* read unix file system tree */
1450 root->drive_type = GetDriveType(path);
1452 lstrcat(drv, sSlash);
1453 load_string(root->volname, IDS_ROOT_FS);
1454 root->fs_flags = 0;
1455 load_string(root->fs, IDS_UNIXFS);
1457 lstrcpy(root->path, sSlash);
1459 return read_tree_unix(root, path, sortOrder, hwnd);
1461 #endif
1463 /* read WIN32 file system tree */
1464 root->drive_type = GetDriveType(path);
1466 lstrcat(drv, sBackslash);
1467 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1469 lstrcpy(root->path, drv);
1471 return read_tree_win(root, path, sortOrder, hwnd);
1475 /* flags to filter different file types */
1476 enum TYPE_FILTER {
1477 TF_DIRECTORIES = 0x01,
1478 TF_PROGRAMS = 0x02,
1479 TF_DOCUMENTS = 0x04,
1480 TF_OTHERS = 0x08,
1481 TF_HIDDEN = 0x10,
1482 TF_ALL = 0x1F
1486 static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd)
1488 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1489 TCHAR dir_path[MAX_PATH];
1490 TCHAR b1[BUFFER_LEN];
1491 static const TCHAR sAsterics[] = {'*', '\0'};
1493 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1494 Root* root = &child->root;
1495 Entry* entry;
1497 memset(child, 0, sizeof(ChildWnd));
1499 child->left.treePane = TRUE;
1500 child->left.visible_cols = 0;
1502 child->right.treePane = FALSE;
1503 #ifndef _NO_EXTENSIONS
1504 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1505 #else
1506 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1507 #endif
1509 child->pos.length = sizeof(WINDOWPLACEMENT);
1510 child->pos.flags = 0;
1511 child->pos.showCmd = SW_SHOWNORMAL;
1512 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1513 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1514 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1515 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1517 child->focus_pane = 0;
1518 child->split_pos = DEFAULT_SPLIT_POS;
1519 child->sortOrder = SORT_NAME;
1520 child->header_wdths_ok = FALSE;
1522 if (path)
1524 lstrcpy(child->path, path);
1526 _tsplitpath(path, drv, dir, name, ext);
1529 lstrcpy(child->filter_pattern, sAsterics);
1530 child->filter_flags = TF_ALL;
1532 root->entry.level = 0;
1534 lstrcpy(dir_path, drv);
1535 lstrcat(dir_path, dir);
1536 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1538 #ifdef _SHELL_FOLDERS
1539 if (root->entry.etype == ET_SHELL)
1540 load_string(root->entry.data.cFileName, IDS_DESKTOP);
1541 else
1542 #endif
1543 wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1545 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1547 child->left.root = &root->entry;
1548 child->right.root = NULL;
1550 set_curdir(child, entry, 0, hwnd);
1552 return child;
1556 /* free all memory associated with a child window */
1557 static void free_child_window(ChildWnd* child)
1559 free_entries(&child->root.entry);
1560 HeapFree(GetProcessHeap(), 0, child);
1564 /* get full path of specified directory entry */
1565 static void get_path(Entry* dir, PTSTR path)
1567 Entry* entry;
1568 int len = 0;
1569 int level = 0;
1571 #ifdef _SHELL_FOLDERS
1572 if (dir->etype == ET_SHELL)
1574 SFGAOF attribs;
1575 HRESULT hr = S_OK;
1577 path[0] = '\0';
1579 attribs = 0;
1581 if (dir->folder)
1582 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1584 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1585 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1587 hr = path_from_pidl(parent, dir->pidl, path, MAX_PATH);
1590 else
1591 #endif
1593 for(entry=dir; entry; level++) {
1594 LPCTSTR name;
1595 int l;
1598 LPCTSTR s;
1599 name = entry->data.cFileName;
1600 s = name;
1602 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1603 l++;
1606 if (entry->up) {
1607 if (l > 0) {
1608 memmove(path+l+1, path, len*sizeof(TCHAR));
1609 memcpy(path+1, name, l*sizeof(TCHAR));
1610 len += l+1;
1612 #ifndef _NO_EXTENSIONS
1613 if (entry->etype == ET_UNIX)
1614 path[0] = '/';
1615 else
1616 #endif
1617 path[0] = '\\';
1620 entry = entry->up;
1621 } else {
1622 memmove(path+l, path, len*sizeof(TCHAR));
1623 memcpy(path, name, l*sizeof(TCHAR));
1624 len += l;
1625 break;
1629 if (!level) {
1630 #ifndef _NO_EXTENSIONS
1631 if (entry->etype == ET_UNIX)
1632 path[len++] = '/';
1633 else
1634 #endif
1635 path[len++] = '\\';
1638 path[len] = '\0';
1642 static windowOptions load_registry_settings(void)
1644 DWORD size;
1645 DWORD type;
1646 HKEY hKey;
1647 windowOptions opts;
1649 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1650 0, KEY_QUERY_VALUE, &hKey );
1652 size = sizeof(DWORD);
1654 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1655 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1656 opts.start_x = CW_USEDEFAULT;
1658 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1659 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1660 opts.start_y = CW_USEDEFAULT;
1662 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1663 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1664 opts.width = CW_USEDEFAULT;
1666 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1667 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1668 opts.height = CW_USEDEFAULT;
1670 RegCloseKey( hKey );
1672 return opts;
1675 static void save_registry_settings(void)
1677 WINDOWINFO wi;
1678 HKEY hKey;
1679 INT width, height;
1681 wi.cbSize = sizeof( WINDOWINFO );
1682 GetWindowInfo(Globals.hMainWnd, &wi);
1683 width = wi.rcWindow.right - wi.rcWindow.left;
1684 height = wi.rcWindow.bottom - wi.rcWindow.top;
1686 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1687 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1689 /* Unable to save registry settings - try to create key */
1690 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1691 0, NULL, REG_OPTION_NON_VOLATILE,
1692 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1694 /* FIXME: Cannot create key */
1695 return;
1698 /* Save all of the settings */
1699 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1700 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1701 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1702 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1703 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1704 (LPBYTE) &width, sizeof(DWORD) );
1705 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1706 (LPBYTE) &height, sizeof(DWORD) );
1708 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1709 RegCloseKey( hKey );
1712 static void resize_frame_rect(HWND hwnd, PRECT prect)
1714 int new_top;
1715 RECT rt;
1717 if (IsWindowVisible(Globals.htoolbar)) {
1718 SendMessage(Globals.htoolbar, WM_SIZE, 0, 0);
1719 GetClientRect(Globals.htoolbar, &rt);
1720 prect->top = rt.bottom+3;
1721 prect->bottom -= rt.bottom+3;
1724 if (IsWindowVisible(Globals.hdrivebar)) {
1725 SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0);
1726 GetClientRect(Globals.hdrivebar, &rt);
1727 new_top = --prect->top + rt.bottom+3;
1728 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1729 prect->top = new_top;
1730 prect->bottom -= rt.bottom+2;
1733 if (IsWindowVisible(Globals.hstatusbar)) {
1734 int parts[] = {300, 500};
1736 SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0);
1737 SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1738 GetClientRect(Globals.hstatusbar, &rt);
1739 prect->bottom -= rt.bottom;
1742 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1745 static void resize_frame(HWND hwnd, int cx, int cy)
1747 RECT rect;
1749 rect.left = 0;
1750 rect.top = 0;
1751 rect.right = cx;
1752 rect.bottom = cy;
1754 resize_frame_rect(hwnd, &rect);
1757 static void resize_frame_client(HWND hwnd)
1759 RECT rect;
1761 GetClientRect(hwnd, &rect);
1763 resize_frame_rect(hwnd, &rect);
1767 static HHOOK hcbthook;
1768 static ChildWnd* newchild = NULL;
1770 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1772 if (code==HCBT_CREATEWND && newchild) {
1773 ChildWnd* child = newchild;
1774 newchild = NULL;
1776 child->hwnd = (HWND) wparam;
1777 SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1780 return CallNextHookEx(hcbthook, code, wparam, lparam);
1783 static HWND create_child_window(ChildWnd* child)
1785 MDICREATESTRUCT mcs;
1786 int idx;
1788 mcs.szClass = sWINEFILETREE;
1789 mcs.szTitle = (LPTSTR)child->path;
1790 mcs.hOwner = Globals.hInstance;
1791 mcs.x = child->pos.rcNormalPosition.left;
1792 mcs.y = child->pos.rcNormalPosition.top;
1793 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1794 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1795 mcs.style = 0;
1796 mcs.lParam = 0;
1798 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1800 newchild = child;
1801 child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1802 if (!child->hwnd) {
1803 UnhookWindowsHookEx(hcbthook);
1804 return 0;
1807 UnhookWindowsHookEx(hcbthook);
1809 SendMessage(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1810 SendMessage(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1812 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1813 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
1815 return child->hwnd;
1819 struct ExecuteDialog {
1820 TCHAR cmd[MAX_PATH];
1821 int cmdshow;
1824 static INT_PTR CALLBACK ExecuteDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1826 static struct ExecuteDialog* dlg;
1828 switch(nmsg) {
1829 case WM_INITDIALOG:
1830 dlg = (struct ExecuteDialog*) lparam;
1831 return 1;
1833 case WM_COMMAND: {
1834 int id = (int)wparam;
1836 if (id == IDOK) {
1837 GetWindowText(GetDlgItem(hwnd, 201), dlg->cmd, MAX_PATH);
1838 dlg->cmdshow = get_check(hwnd,214) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL;
1839 EndDialog(hwnd, id);
1840 } else if (id == IDCANCEL)
1841 EndDialog(hwnd, id);
1843 return 1;}
1846 return 0;
1850 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1852 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1854 switch(nmsg) {
1855 case WM_INITDIALOG:
1856 SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
1857 SetWindowText(GetDlgItem(hwnd, 201), (LPCTSTR)lparam);
1858 return 1;
1860 case WM_COMMAND: {
1861 int id = (int)wparam;
1863 switch(id) {
1864 case IDOK: {
1865 LPTSTR dest = (LPTSTR) GetWindowLongPtr(hwnd, GWLP_USERDATA);
1866 GetWindowText(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1867 EndDialog(hwnd, id);
1868 break;}
1870 case IDCANCEL:
1871 EndDialog(hwnd, id);
1872 break;
1874 case 254:
1875 MessageBox(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1876 break;
1879 return 1;
1883 return 0;
1887 struct FilterDialog {
1888 TCHAR pattern[MAX_PATH];
1889 int flags;
1892 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1894 static struct FilterDialog* dlg;
1896 switch(nmsg) {
1897 case WM_INITDIALOG:
1898 dlg = (struct FilterDialog*) lparam;
1899 SetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1900 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1901 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1902 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1903 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1904 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1905 return 1;
1907 case WM_COMMAND: {
1908 int id = (int)wparam;
1910 if (id == IDOK) {
1911 int flags = 0;
1913 GetWindowText(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1915 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1916 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1917 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1918 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1919 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1921 dlg->flags = flags;
1923 EndDialog(hwnd, id);
1924 } else if (id == IDCANCEL)
1925 EndDialog(hwnd, id);
1927 return 1;}
1930 return 0;
1934 struct PropertiesDialog {
1935 TCHAR path[MAX_PATH];
1936 Entry entry;
1937 void* pVersionData;
1940 /* Structure used to store enumerated languages and code pages. */
1941 struct LANGANDCODEPAGE {
1942 WORD wLanguage;
1943 WORD wCodePage;
1944 } *lpTranslate;
1946 static LPCSTR InfoStrings[] = {
1947 "Comments",
1948 "CompanyName",
1949 "FileDescription",
1950 "FileVersion",
1951 "InternalName",
1952 "LegalCopyright",
1953 "LegalTrademarks",
1954 "OriginalFilename",
1955 "PrivateBuild",
1956 "ProductName",
1957 "ProductVersion",
1958 "SpecialBuild",
1959 NULL
1962 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1964 int idx = SendMessage(hlbox, LB_GETCURSEL, 0, 0);
1966 if (idx != LB_ERR) {
1967 LPCTSTR pValue = (LPCTSTR) SendMessage(hlbox, LB_GETITEMDATA, idx, 0);
1969 if (pValue)
1970 SetWindowText(hedit, pValue);
1974 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCTSTR strFilename)
1976 static TCHAR sBackSlash[] = {'\\','\0'};
1977 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'};
1978 static TCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1979 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1980 DWORD dwVersionDataLen = GetFileVersionInfoSize(strFilename, NULL);
1982 if (dwVersionDataLen) {
1983 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1985 if (GetFileVersionInfo(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1986 LPVOID pVal;
1987 UINT nValLen;
1989 if (VerQueryValue(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1990 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1991 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1992 char buffer[BUFFER_LEN];
1994 sprintf(buffer, "%d.%d.%d.%d",
1995 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1996 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1998 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
2002 /* Read the list of languages and code pages. */
2003 if (VerQueryValue(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
2004 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
2005 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
2007 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2009 /* Read the file description for each language and code page. */
2010 for(; pTranslate<pEnd; ++pTranslate) {
2011 LPCSTR* p;
2013 for(p=InfoStrings; *p; ++p) {
2014 TCHAR subblock[200];
2015 #ifdef UNICODE
2016 TCHAR infoStr[100];
2017 #endif
2018 LPCTSTR pTxt;
2019 UINT nValLen;
2021 LPCSTR pInfoString = *p;
2022 #ifdef UNICODE
2023 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
2024 #else
2025 #define infoStr pInfoString
2026 #endif
2027 wsprintf(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
2029 /* Retrieve file description for language and code page */
2030 if (VerQueryValue(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
2031 int idx = SendMessage(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
2032 SendMessage(hlbox, LB_SETITEMDATA, idx, (LPARAM) pTxt);
2037 SendMessage(hlbox, LB_SETCURSEL, 0, 0);
2039 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2045 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2047 static struct PropertiesDialog* dlg;
2049 switch(nmsg) {
2050 case WM_INITDIALOG: {
2051 static const TCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
2052 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2053 LPWIN32_FIND_DATA pWFD;
2054 ULONGLONG size;
2056 dlg = (struct PropertiesDialog*) lparam;
2057 pWFD = (LPWIN32_FIND_DATA) &dlg->entry.data;
2059 GetWindowText(hwnd, b1, MAX_PATH);
2060 wsprintf(b2, b1, pWFD->cFileName);
2061 SetWindowText(hwnd, b2);
2063 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
2064 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
2066 size = ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow;
2067 _stprintf(b1, sLongNumFmt, size);
2068 wsprintf(b2, sByteFmt, b1);
2069 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
2071 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
2072 SetWindowText(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
2074 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
2075 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
2076 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
2077 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
2078 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
2080 CheckForFileInfo(dlg, hwnd, dlg->path);
2081 return 1;}
2083 case WM_COMMAND: {
2084 int id = (int)wparam;
2086 switch(HIWORD(wparam)) {
2087 case LBN_SELCHANGE: {
2088 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
2089 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
2090 break;
2093 case BN_CLICKED:
2094 if (id==IDOK || id==IDCANCEL)
2095 EndDialog(hwnd, id);
2098 return 1;}
2100 case WM_NCDESTROY:
2101 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
2102 dlg->pVersionData = NULL;
2103 break;
2106 return 0;
2109 static void show_properties_dlg(Entry* entry, HWND hwnd)
2111 struct PropertiesDialog dlg;
2113 memset(&dlg, 0, sizeof(struct PropertiesDialog));
2114 get_path(entry, dlg.path);
2115 memcpy(&dlg.entry, entry, sizeof(Entry));
2117 DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
2121 #ifndef _NO_EXTENSIONS
2123 static struct FullScreenParameters {
2124 BOOL mode;
2125 RECT orgPos;
2126 BOOL wasZoomed;
2127 } g_fullscreen = {
2128 FALSE, /* mode */
2129 {0, 0, 0, 0},
2130 FALSE
2133 static void frame_get_clientspace(HWND hwnd, PRECT prect)
2135 RECT rt;
2137 if (!IsIconic(hwnd))
2138 GetClientRect(hwnd, prect);
2139 else {
2140 WINDOWPLACEMENT wp;
2142 GetWindowPlacement(hwnd, &wp);
2144 prect->left = prect->top = 0;
2145 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
2146 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
2147 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
2148 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
2149 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2152 if (IsWindowVisible(Globals.htoolbar)) {
2153 GetClientRect(Globals.htoolbar, &rt);
2154 prect->top += rt.bottom+2;
2157 if (IsWindowVisible(Globals.hdrivebar)) {
2158 GetClientRect(Globals.hdrivebar, &rt);
2159 prect->top += rt.bottom+2;
2162 if (IsWindowVisible(Globals.hstatusbar)) {
2163 GetClientRect(Globals.hstatusbar, &rt);
2164 prect->bottom -= rt.bottom;
2168 static BOOL toggle_fullscreen(HWND hwnd)
2170 RECT rt;
2172 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2173 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2174 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2176 Frame_CalcFrameClient(hwnd, &rt);
2177 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2178 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2180 rt.left = g_fullscreen.orgPos.left-rt.left;
2181 rt.top = g_fullscreen.orgPos.top-rt.top;
2182 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2183 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2185 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2186 } else {
2187 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2188 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2189 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2191 if (g_fullscreen.wasZoomed)
2192 ShowWindow(hwnd, WS_MAXIMIZE);
2195 return g_fullscreen.mode;
2198 static void fullscreen_move(HWND hwnd)
2200 RECT rt, pos;
2201 GetWindowRect(hwnd, &pos);
2203 Frame_CalcFrameClient(hwnd, &rt);
2204 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2205 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2207 rt.left = pos.left-rt.left;
2208 rt.top = pos.top-rt.top;
2209 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2210 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2212 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2215 #endif
2218 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2220 BOOL vis = IsWindowVisible(hchild);
2222 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2224 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2226 #ifndef _NO_EXTENSIONS
2227 if (g_fullscreen.mode)
2228 fullscreen_move(hwnd);
2229 #endif
2231 resize_frame_client(hwnd);
2234 static BOOL activate_drive_window(LPCTSTR path)
2236 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2237 HWND child_wnd;
2239 _tsplitpath(path, drv1, 0, 0, 0);
2241 /* search for a already open window for the same drive */
2242 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2243 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2245 if (child) {
2246 _tsplitpath(child->root.path, drv2, 0, 0, 0);
2248 if (!lstrcmpi(drv2, drv1)) {
2249 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2251 if (IsIconic(child_wnd))
2252 ShowWindow(child_wnd, SW_SHOWNORMAL);
2254 return TRUE;
2259 return FALSE;
2262 static BOOL activate_fs_window(LPCTSTR filesys)
2264 HWND child_wnd;
2266 /* search for a already open window of the given file system name */
2267 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2268 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA);
2270 if (child) {
2271 if (!lstrcmpi(child->root.fs, filesys)) {
2272 SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2274 if (IsIconic(child_wnd))
2275 ShowWindow(child_wnd, SW_SHOWNORMAL);
2277 return TRUE;
2282 return FALSE;
2285 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2287 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2289 switch(nmsg) {
2290 case WM_CLOSE:
2291 if (Globals.saveSettings)
2292 save_registry_settings();
2294 DestroyWindow(hwnd);
2296 /* clear handle variables */
2297 Globals.hMenuFrame = 0;
2298 Globals.hMenuView = 0;
2299 Globals.hMenuOptions = 0;
2300 Globals.hMainWnd = 0;
2301 Globals.hmdiclient = 0;
2302 Globals.hdrivebar = 0;
2303 break;
2305 case WM_DESTROY:
2306 PostQuitMessage(0);
2307 break;
2309 case WM_INITMENUPOPUP: {
2310 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2312 if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2313 return 0;
2314 break;}
2316 case WM_COMMAND: {
2317 UINT cmd = LOWORD(wparam);
2318 HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2320 if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2321 break;
2323 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2324 TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2325 ChildWnd* child;
2326 LPCTSTR root = Globals.drives;
2327 int i;
2329 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2330 while(*root)
2331 root++;
2333 if (activate_drive_window(root))
2334 return 0;
2336 _tsplitpath(root, drv, 0, 0, 0);
2338 if (!SetCurrentDirectory(drv)) {
2339 display_error(hwnd, GetLastError());
2340 return 0;
2343 GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */
2344 child = alloc_child_window(path, NULL, hwnd);
2346 if (!create_child_window(child))
2347 HeapFree(GetProcessHeap(), 0, child);
2348 } else switch(cmd) {
2349 case ID_FILE_EXIT:
2350 SendMessage(hwnd, WM_CLOSE, 0, 0);
2351 break;
2353 case ID_WINDOW_NEW: {
2354 TCHAR path[MAX_PATH];
2355 ChildWnd* child;
2357 GetCurrentDirectory(MAX_PATH, path);
2358 child = alloc_child_window(path, NULL, hwnd);
2360 if (!create_child_window(child))
2361 HeapFree(GetProcessHeap(), 0, child);
2362 break;}
2364 case ID_REFRESH:
2365 refresh_drives();
2366 break;
2368 case ID_WINDOW_CASCADE:
2369 SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2370 break;
2372 case ID_WINDOW_TILE_HORZ:
2373 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2374 break;
2376 case ID_WINDOW_TILE_VERT:
2377 SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2378 break;
2380 case ID_WINDOW_ARRANGE:
2381 SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2382 break;
2384 case ID_SELECT_FONT:
2385 choose_font(hwnd);
2386 break;
2388 case ID_VIEW_TOOL_BAR:
2389 toggle_child(hwnd, cmd, Globals.htoolbar);
2390 break;
2392 case ID_VIEW_DRIVE_BAR:
2393 toggle_child(hwnd, cmd, Globals.hdrivebar);
2394 break;
2396 case ID_VIEW_STATUSBAR:
2397 toggle_child(hwnd, cmd, Globals.hstatusbar);
2398 break;
2400 case ID_VIEW_SAVESETTINGS:
2401 Globals.saveSettings = !Globals.saveSettings;
2402 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2403 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2404 break;
2406 case ID_EXECUTE: {
2407 struct ExecuteDialog dlg;
2409 memset(&dlg, 0, sizeof(struct ExecuteDialog));
2411 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) {
2412 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
2414 if ((int)hinst <= 32)
2415 display_error(hwnd, GetLastError());
2417 break;}
2419 case ID_CONNECT_NETWORK_DRIVE: {
2420 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2421 if (ret == NO_ERROR)
2422 refresh_drives();
2423 else if (ret != (DWORD)-1) {
2424 if (ret == ERROR_EXTENDED_ERROR)
2425 display_network_error(hwnd);
2426 else
2427 display_error(hwnd, ret);
2429 break;}
2431 case ID_DISCONNECT_NETWORK_DRIVE: {
2432 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2433 if (ret == NO_ERROR)
2434 refresh_drives();
2435 else if (ret != (DWORD)-1) {
2436 if (ret == ERROR_EXTENDED_ERROR)
2437 display_network_error(hwnd);
2438 else
2439 display_error(hwnd, ret);
2441 break;}
2443 case ID_FORMAT_DISK: {
2444 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2445 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2446 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2447 SetErrorMode(sem_org); /* Put it back the way it was. */
2448 break;}
2450 case ID_HELP:
2451 WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2452 break;
2454 #ifndef _NO_EXTENSIONS
2455 case ID_VIEW_FULLSCREEN:
2456 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2457 break;
2459 #ifdef __WINE__
2460 case ID_DRIVE_UNIX_FS: {
2461 TCHAR path[MAX_PATH];
2462 #ifdef UNICODE
2463 char cpath[MAX_PATH];
2464 #endif
2465 ChildWnd* child;
2467 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2468 break;
2470 #ifdef UNICODE
2471 getcwd(cpath, MAX_PATH);
2472 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2473 #else
2474 getcwd(path, MAX_PATH);
2475 #endif
2476 child = alloc_child_window(path, NULL, hwnd);
2478 if (!create_child_window(child))
2479 HeapFree(GetProcessHeap(), 0, child);
2480 break;}
2481 #endif
2482 #ifdef _SHELL_FOLDERS
2483 case ID_DRIVE_SHELL_NS: {
2484 TCHAR path[MAX_PATH];
2485 ChildWnd* child;
2487 if (activate_fs_window(RS(b1,IDS_SHELL)))
2488 break;
2490 GetCurrentDirectory(MAX_PATH, path);
2491 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2493 if (!create_child_window(child))
2494 HeapFree(GetProcessHeap(), 0, child);
2495 break;}
2496 #endif
2497 #endif
2499 /*TODO: There are even more menu items! */
2501 #ifndef _NO_EXTENSIONS
2502 #ifdef __WINE__
2503 case ID_LICENSE:
2504 WineLicense(Globals.hMainWnd);
2505 break;
2507 case ID_NO_WARRANTY:
2508 WineWarranty(Globals.hMainWnd);
2509 break;
2511 case ID_ABOUT_WINE:
2512 ShellAbout(hwnd, RS(b2,IDS_WINE), RS(b1,IDS_WINEFILE), 0);
2513 break;
2514 #endif
2516 case ID_ABOUT:
2517 ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, 0);
2518 break;
2519 #endif /* _NO_EXTENSIONS */
2521 default:
2522 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2523 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2524 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2525 (cmd<SC_SIZE || cmd>SC_RESTORE))
2526 MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2528 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2530 break;}
2532 case WM_SIZE:
2533 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2534 break; /* do not pass message to DefFrameProc */
2536 case WM_DEVICECHANGE:
2537 SendMessage(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2538 break;
2540 #ifndef _NO_EXTENSIONS
2541 case WM_GETMINMAXINFO: {
2542 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2544 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2545 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2546 break;}
2548 case FRM_CALC_CLIENT:
2549 frame_get_clientspace(hwnd, (PRECT)lparam);
2550 return TRUE;
2551 #endif /* _NO_EXTENSIONS */
2553 default:
2554 return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2557 return 0;
2561 static TCHAR g_pos_names[COLUMNS][20] = {
2562 {'\0'} /* symbol */
2565 static const int g_pos_align[] = {
2567 HDF_LEFT, /* Name */
2568 HDF_RIGHT, /* Size */
2569 HDF_LEFT, /* CDate */
2570 #ifndef _NO_EXTENSIONS
2571 HDF_LEFT, /* ADate */
2572 HDF_LEFT, /* MDate */
2573 HDF_LEFT, /* Index */
2574 HDF_CENTER, /* Links */
2575 #endif
2576 HDF_CENTER, /* Attributes */
2577 #ifndef _NO_EXTENSIONS
2578 HDF_LEFT /* Security */
2579 #endif
2582 static void resize_tree(ChildWnd* child, int cx, int cy)
2584 HDWP hdwp = BeginDeferWindowPos(4);
2585 RECT rt;
2587 rt.left = 0;
2588 rt.top = 0;
2589 rt.right = cx;
2590 rt.bottom = cy;
2592 cx = child->split_pos + SPLIT_WIDTH/2;
2594 #ifndef _NO_EXTENSIONS
2596 WINDOWPOS wp;
2597 HD_LAYOUT hdl;
2599 hdl.prc = &rt;
2600 hdl.pwpos = &wp;
2602 SendMessage(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2604 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2605 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2606 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2607 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2609 #endif /* _NO_EXTENSIONS */
2611 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);
2612 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2614 EndDeferWindowPos(hdwp);
2618 #ifndef _NO_EXTENSIONS
2620 static HWND create_header(HWND parent, Pane* pane, int id)
2622 HD_ITEM hdi;
2623 int idx;
2625 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2626 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2627 if (!hwnd)
2628 return 0;
2630 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2632 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2634 for(idx=0; idx<COLUMNS; idx++) {
2635 hdi.pszText = g_pos_names[idx];
2636 hdi.fmt = HDF_STRING | g_pos_align[idx];
2637 hdi.cxy = pane->widths[idx];
2638 SendMessage(hwnd, HDM_INSERTITEM, idx, (LPARAM) &hdi);
2641 return hwnd;
2644 #endif /* _NO_EXTENSIONS */
2647 static void init_output(HWND hwnd)
2649 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2650 WCHAR b[16];
2651 HFONT old_font;
2652 HDC hdc = GetDC(hwnd);
2654 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2655 Globals.num_sep = b[1];
2656 else
2657 Globals.num_sep = '.';
2659 old_font = SelectObject(hdc, Globals.hfont);
2660 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2661 SelectObject(hdc, old_font);
2662 ReleaseDC(hwnd, hdc);
2665 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2668 /* calculate preferred width for all visible columns */
2670 static BOOL calc_widths(Pane* pane, BOOL anyway)
2672 int col, x, cx, spc=3*Globals.spaceSize.cx;
2673 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2674 int orgWidths[COLUMNS];
2675 int orgPositions[COLUMNS+1];
2676 HFONT hfontOld;
2677 HDC hdc;
2678 int cnt;
2680 if (!anyway) {
2681 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2682 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2685 for(col=0; col<COLUMNS; col++)
2686 pane->widths[col] = 0;
2688 hdc = GetDC(pane->hwnd);
2689 hfontOld = SelectObject(hdc, Globals.hfont);
2691 for(cnt=0; cnt<entries; cnt++) {
2692 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2694 DRAWITEMSTRUCT dis;
2696 dis.CtlType = 0;
2697 dis.CtlID = 0;
2698 dis.itemID = 0;
2699 dis.itemAction = 0;
2700 dis.itemState = 0;
2701 dis.hwndItem = pane->hwnd;
2702 dis.hDC = hdc;
2703 dis.rcItem.left = 0;
2704 dis.rcItem.top = 0;
2705 dis.rcItem.right = 0;
2706 dis.rcItem.bottom = 0;
2707 /*dis.itemData = 0; */
2709 draw_item(pane, &dis, entry, COLUMNS);
2712 SelectObject(hdc, hfontOld);
2713 ReleaseDC(pane->hwnd, hdc);
2715 x = 0;
2716 for(col=0; col<COLUMNS; col++) {
2717 pane->positions[col] = x;
2718 cx = pane->widths[col];
2720 if (cx) {
2721 cx += spc;
2723 if (cx < IMAGE_WIDTH)
2724 cx = IMAGE_WIDTH;
2726 pane->widths[col] = cx;
2729 x += cx;
2732 pane->positions[COLUMNS] = x;
2734 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2736 /* no change? */
2737 if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2738 return FALSE;
2740 /* don't move, if only collapsing an entry */
2741 if (!anyway && pane->widths[0]<orgWidths[0] &&
2742 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2743 pane->widths[0] = orgWidths[0];
2744 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2746 return FALSE;
2749 InvalidateRect(pane->hwnd, 0, TRUE);
2751 return TRUE;
2755 /* calculate one preferred column width */
2757 static void calc_single_width(Pane* pane, int col)
2759 HFONT hfontOld;
2760 int x, cx;
2761 int entries = SendMessage(pane->hwnd, LB_GETCOUNT, 0, 0);
2762 int cnt;
2763 HDC hdc;
2765 pane->widths[col] = 0;
2767 hdc = GetDC(pane->hwnd);
2768 hfontOld = SelectObject(hdc, Globals.hfont);
2770 for(cnt=0; cnt<entries; cnt++) {
2771 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2772 DRAWITEMSTRUCT dis;
2774 dis.CtlType = 0;
2775 dis.CtlID = 0;
2776 dis.itemID = 0;
2777 dis.itemAction = 0;
2778 dis.itemState = 0;
2779 dis.hwndItem = pane->hwnd;
2780 dis.hDC = hdc;
2781 dis.rcItem.left = 0;
2782 dis.rcItem.top = 0;
2783 dis.rcItem.right = 0;
2784 dis.rcItem.bottom = 0;
2785 /*dis.itemData = 0; */
2787 draw_item(pane, &dis, entry, col);
2790 SelectObject(hdc, hfontOld);
2791 ReleaseDC(pane->hwnd, hdc);
2793 cx = pane->widths[col];
2795 if (cx) {
2796 cx += 3*Globals.spaceSize.cx;
2798 if (cx < IMAGE_WIDTH)
2799 cx = IMAGE_WIDTH;
2802 pane->widths[col] = cx;
2804 x = pane->positions[col] + cx;
2806 for(; col<COLUMNS; ) {
2807 pane->positions[++col] = x;
2808 x += pane->widths[col];
2811 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2815 static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern)
2817 for( ; *str&&*pattern; str++,pattern++) {
2818 if (*pattern == '*') {
2819 do pattern++;
2820 while(*pattern == '*');
2822 if (!*pattern)
2823 return TRUE;
2825 for(; *str; str++)
2826 if (*str==*pattern && pattern_match(str, pattern))
2827 return TRUE;
2829 return FALSE;
2831 else if (*str!=*pattern && *pattern!='?')
2832 return FALSE;
2835 if (*str || *pattern)
2836 if (*pattern!='*' || pattern[1]!='\0')
2837 return FALSE;
2839 return TRUE;
2842 static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern)
2844 TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2846 lstrcpy(b1, str);
2847 lstrcpy(b2, pattern);
2848 CharUpper(b1);
2849 CharUpper(b2);
2851 return pattern_match(b1, b2);
2855 enum FILE_TYPE {
2856 FT_OTHER = 0,
2857 FT_EXECUTABLE = 1,
2858 FT_DOCUMENT = 2
2861 static enum FILE_TYPE get_file_type(LPCTSTR filename);
2864 /* insert listbox entries after index idx */
2866 static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx)
2868 Entry* entry = dir;
2870 if (!entry)
2871 return idx;
2873 ShowWindow(pane->hwnd, SW_HIDE);
2875 for(; entry; entry=entry->next) {
2876 #ifndef _LEFT_FILES
2877 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2878 continue;
2879 #endif
2881 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2882 /* don't display entries "." and ".." in the left pane */
2883 if (pane->treePane && entry->data.cFileName[0] == '.')
2884 if (
2885 #ifndef _NO_EXTENSIONS
2886 entry->data.cFileName[1] == '\0' ||
2887 #endif
2888 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2889 continue;
2891 /* filter directories in right pane */
2892 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2893 continue;
2896 /* filter using the file name pattern */
2897 if (pattern)
2898 if (!pattern_imatch(entry->data.cFileName, pattern))
2899 continue;
2901 /* filter system and hidden files */
2902 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2903 continue;
2905 /* filter looking at the file type */
2906 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2907 switch(get_file_type(entry->data.cFileName)) {
2908 case FT_EXECUTABLE:
2909 if (!(filter_flags & TF_PROGRAMS))
2910 continue;
2911 break;
2913 case FT_DOCUMENT:
2914 if (!(filter_flags & TF_DOCUMENTS))
2915 continue;
2916 break;
2918 default: /* TF_OTHERS */
2919 if (!(filter_flags & TF_OTHERS))
2920 continue;
2923 if (idx != -1)
2924 idx++;
2926 SendMessage(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM) entry);
2928 if (pane->treePane && entry->expanded)
2929 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2932 ShowWindow(pane->hwnd, SW_SHOW);
2934 return idx;
2938 static void format_bytes(LPTSTR buffer, LONGLONG bytes)
2940 static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2941 static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2942 static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2944 float fBytes = (float)bytes;
2946 if (bytes >= 1073741824) /* 1 GB */
2947 _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2948 else if (bytes >= 1048576) /* 1 MB */
2949 _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f);
2950 else if (bytes >= 1024) /* 1 kB */
2951 _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f);
2952 else
2953 _stprintf(buffer, sLongNumFmt, bytes);
2956 static void set_space_status(void)
2958 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2959 TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2961 if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2962 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2963 format_bytes(b2, ulTotalBytes.QuadPart);
2964 wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2965 } else
2966 lstrcpy(buffer, sQMarks);
2968 SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer);
2972 static WNDPROC g_orgTreeWndProc;
2974 static void create_tree_window(HWND parent, Pane* pane, int id, int id_header, LPCTSTR pattern, int filter_flags)
2976 static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2978 static int s_init = 0;
2979 Entry* entry = pane->root;
2981 pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2982 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2983 0, 0, 0, 0, parent, (HMENU)id, Globals.hInstance, 0);
2985 SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2986 g_orgTreeWndProc = (WNDPROC) SetWindowLongPtr(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2988 SendMessage(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2990 /* insert entries into listbox */
2991 if (entry)
2992 insert_entries(pane, entry, pattern, filter_flags, -1);
2994 /* calculate column widths */
2995 if (!s_init) {
2996 s_init = 1;
2997 init_output(pane->hwnd);
3000 calc_widths(pane, TRUE);
3002 #ifndef _NO_EXTENSIONS
3003 pane->hwndHeader = create_header(parent, pane, id_header);
3004 #endif
3008 static void InitChildWindow(ChildWnd* child)
3010 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
3011 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
3015 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
3017 SYSTEMTIME systime;
3018 FILETIME lft;
3019 int len = 0;
3021 *buffer = '\0';
3023 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
3024 return;
3026 if (!FileTimeToLocalFileTime(ft, &lft))
3027 {err: lstrcpy(buffer,sQMarks); return;}
3029 if (!FileTimeToSystemTime(&lft, &systime))
3030 goto err;
3032 if (visible_cols & COL_DATE) {
3033 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
3034 if (!len)
3035 goto err;
3038 if (visible_cols & COL_TIME) {
3039 if (len)
3040 buffer[len-1] = ' ';
3042 buffer[len++] = ' ';
3044 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
3045 buffer[len] = '\0';
3050 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3052 RECT rt = {0, 0, 0, 0};
3054 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3056 if (rt.right > pane->widths[col])
3057 pane->widths[col] = rt.right;
3060 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3062 RECT rt = {0, 0, 0, 0};
3064 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3065 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3067 DrawText(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3068 /*FIXME rt (0,0) ??? */
3070 if (rt.right > pane->widths[col])
3071 pane->widths[col] = rt.right;
3075 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags)
3077 int x = dis->rcItem.left;
3078 RECT rt;
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 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
3088 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3090 int x = dis->rcItem.left;
3091 RECT rt;
3093 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3094 rt.top = dis->rcItem.top;
3095 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3096 rt.bottom = dis->rcItem.bottom;
3098 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
3099 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
3101 DrawText(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
3104 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
3106 int x = dis->rcItem.left;
3107 RECT rt;
3108 LPCTSTR s = str;
3109 TCHAR b[128];
3110 LPTSTR d = b;
3111 int pos;
3113 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
3114 rt.top = dis->rcItem.top;
3115 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
3116 rt.bottom = dis->rcItem.bottom;
3118 if (*s)
3119 *d++ = *s++;
3121 /* insert number separator characters */
3122 pos = lstrlen(s) % 3;
3124 while(*s)
3125 if (pos--)
3126 *d++ = *s++;
3127 else {
3128 *d++ = Globals.num_sep;
3129 pos = 3;
3132 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
3136 static BOOL is_exe_file(LPCTSTR ext)
3138 static const TCHAR executable_extensions[][4] = {
3139 {'C','O','M','\0'},
3140 {'E','X','E','\0'},
3141 {'B','A','T','\0'},
3142 {'C','M','D','\0'},
3143 #ifndef _NO_EXTENSIONS
3144 {'C','M','M','\0'},
3145 {'B','T','M','\0'},
3146 {'A','W','K','\0'},
3147 #endif /* _NO_EXTENSIONS */
3148 {'\0'}
3151 TCHAR ext_buffer[_MAX_EXT];
3152 const TCHAR (*p)[4];
3153 LPCTSTR s;
3154 LPTSTR d;
3156 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
3157 d++;
3159 for(p=executable_extensions; (*p)[0]; p++)
3160 if (!lstrcmpi(ext_buffer, *p))
3161 return TRUE;
3163 return FALSE;
3166 static BOOL is_registered_type(LPCTSTR ext)
3168 /* check if there exists a classname for this file extension in the registry */
3169 if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL))
3170 return TRUE;
3172 return FALSE;
3175 static enum FILE_TYPE get_file_type(LPCTSTR filename)
3177 LPCTSTR ext = _tcsrchr(filename, '.');
3178 if (!ext)
3179 ext = sEmpty;
3181 if (is_exe_file(ext))
3182 return FT_EXECUTABLE;
3183 else if (is_registered_type(ext))
3184 return FT_DOCUMENT;
3185 else
3186 return FT_OTHER;
3190 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3192 TCHAR buffer[BUFFER_LEN];
3193 DWORD attrs;
3194 int visible_cols = pane->visible_cols;
3195 COLORREF bkcolor, textcolor;
3196 RECT focusRect = dis->rcItem;
3197 HBRUSH hbrush;
3198 enum IMAGE img;
3199 int img_pos, cx;
3200 int col = 0;
3202 if (entry) {
3203 attrs = entry->data.dwFileAttributes;
3205 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3206 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3207 && entry->data.cFileName[2] == '\0')
3208 img = IMG_FOLDER_UP;
3209 #ifndef _NO_EXTENSIONS
3210 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3211 img = IMG_FOLDER_CUR;
3212 #endif
3213 else if (
3214 #ifdef _NO_EXTENSIONS
3215 entry->expanded ||
3216 #endif
3217 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3218 img = IMG_OPEN_FOLDER;
3219 else
3220 img = IMG_FOLDER;
3221 } else {
3222 switch(get_file_type(entry->data.cFileName)) {
3223 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3224 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3225 default: img = IMG_FILE;
3228 } else {
3229 attrs = 0;
3230 img = IMG_NONE;
3233 if (pane->treePane) {
3234 if (entry) {
3235 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3237 if (calcWidthCol == -1) {
3238 int x;
3239 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3240 Entry* up;
3241 RECT rt_clip;
3242 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3243 HRGN hrgn;
3245 rt_clip.left = dis->rcItem.left;
3246 rt_clip.top = dis->rcItem.top;
3247 rt_clip.right = dis->rcItem.left+pane->widths[col];
3248 rt_clip.bottom = dis->rcItem.bottom;
3250 hrgn = CreateRectRgnIndirect(&rt_clip);
3252 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3253 DeleteObject(hrgn_org);
3254 hrgn_org = 0;
3257 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3258 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3259 DeleteObject(hrgn);
3261 if ((up=entry->up) != NULL) {
3262 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3263 LineTo(dis->hDC, img_pos-2, y);
3265 x = img_pos - IMAGE_WIDTH/2;
3267 do {
3268 x -= IMAGE_WIDTH+TREE_LINE_DX;
3270 if (up->next
3271 #ifndef _LEFT_FILES
3272 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3273 #endif
3275 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3276 LineTo(dis->hDC, x, dis->rcItem.bottom);
3278 } while((up=up->up) != NULL);
3281 x = img_pos - IMAGE_WIDTH/2;
3283 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3284 LineTo(dis->hDC, x, y);
3286 if (entry->next
3287 #ifndef _LEFT_FILES
3288 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3289 #endif
3291 LineTo(dis->hDC, x, dis->rcItem.bottom);
3293 SelectClipRgn(dis->hDC, hrgn_org);
3294 if (hrgn_org) DeleteObject(hrgn_org);
3295 /* SelectObject(dis->hDC, holdPen); */
3296 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3297 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3299 if (right > pane->widths[col])
3300 pane->widths[col] = right;
3302 } else {
3303 img_pos = dis->rcItem.left;
3305 } else {
3306 img_pos = dis->rcItem.left;
3308 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3309 pane->widths[col] = IMAGE_WIDTH;
3312 if (calcWidthCol == -1) {
3313 focusRect.left = img_pos -2;
3315 #ifdef _NO_EXTENSIONS
3316 if (pane->treePane && entry) {
3317 RECT rt = {0};
3319 DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3321 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3323 #else
3325 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3326 textcolor = COLOR_COMPRESSED;
3327 else
3328 #endif /* _NO_EXTENSIONS */
3329 textcolor = RGB(0,0,0);
3331 if (dis->itemState & ODS_FOCUS) {
3332 textcolor = RGB(255,255,255);
3333 bkcolor = COLOR_SELECTION;
3334 } else {
3335 bkcolor = RGB(255,255,255);
3338 hbrush = CreateSolidBrush(bkcolor);
3339 FillRect(dis->hDC, &focusRect, hbrush);
3340 DeleteObject(hbrush);
3342 SetBkMode(dis->hDC, TRANSPARENT);
3343 SetTextColor(dis->hDC, textcolor);
3345 cx = pane->widths[col];
3347 if (cx && img!=IMG_NONE) {
3348 if (cx > IMAGE_WIDTH)
3349 cx = IMAGE_WIDTH;
3351 #ifdef _SHELL_FOLDERS
3352 if (entry->hicon && entry->hicon!=(HICON)-1)
3353 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3354 else
3355 #endif
3356 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3357 img_pos, dis->rcItem.top, cx,
3358 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3362 if (!entry)
3363 return;
3365 #ifdef _NO_EXTENSIONS
3366 if (img >= IMG_FOLDER_UP)
3367 return;
3368 #endif
3370 col++;
3372 /* ouput file name */
3373 if (calcWidthCol == -1)
3374 output_text(pane, dis, col, entry->data.cFileName, 0);
3375 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3376 calc_width(pane, dis, col, entry->data.cFileName);
3378 col++;
3380 #ifdef _NO_EXTENSIONS
3381 if (!pane->treePane) {
3382 #endif
3384 /* display file size */
3385 if (visible_cols & COL_SIZE) {
3386 #ifdef _NO_EXTENSIONS
3387 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3388 #endif
3390 ULONGLONG size;
3392 size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow;
3394 _stprintf(buffer, sLongNumFmt, size);
3396 if (calcWidthCol == -1)
3397 output_number(pane, dis, col, buffer);
3398 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3399 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3402 col++;
3405 /* display file date */
3406 if (visible_cols & (COL_DATE|COL_TIME)) {
3407 #ifndef _NO_EXTENSIONS
3408 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3409 if (calcWidthCol == -1)
3410 output_text(pane, dis, col, buffer, 0);
3411 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3412 calc_width(pane, dis, col, buffer);
3413 col++;
3415 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3416 if (calcWidthCol == -1)
3417 output_text(pane, dis, col, buffer, 0);
3418 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3419 calc_width(pane, dis, col, buffer);
3420 col++;
3421 #endif /* _NO_EXTENSIONS */
3423 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3424 if (calcWidthCol == -1)
3425 output_text(pane, dis, col, buffer, 0);
3426 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3427 calc_width(pane, dis, col, buffer);
3428 col++;
3431 #ifndef _NO_EXTENSIONS
3432 if (entry->bhfi_valid) {
3433 ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow;
3435 if (visible_cols & COL_INDEX) {
3436 _stprintf(buffer, sLongHexFmt, index);
3438 if (calcWidthCol == -1)
3439 output_text(pane, dis, col, buffer, DT_RIGHT);
3440 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3441 calc_width(pane, dis, col, buffer);
3443 col++;
3446 if (visible_cols & COL_LINKS) {
3447 wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3449 if (calcWidthCol == -1)
3450 output_text(pane, dis, col, buffer, DT_CENTER);
3451 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3452 calc_width(pane, dis, col, buffer);
3454 col++;
3456 } else
3457 col += 2;
3458 #endif /* _NO_EXTENSIONS */
3460 /* show file attributes */
3461 if (visible_cols & COL_ATTRIBUTES) {
3462 #ifdef _NO_EXTENSIONS
3463 static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3464 lstrcpy(buffer, s4Tabs);
3465 #else
3466 static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3467 lstrcpy(buffer, s11Tabs);
3468 #endif
3470 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3471 else {
3472 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3473 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3474 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3475 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3476 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3477 #ifndef _NO_EXTENSIONS
3478 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3479 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3480 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3481 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3482 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3483 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3484 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3485 #endif /* _NO_EXTENSIONS */
3488 if (calcWidthCol == -1)
3489 output_tabbed_text(pane, dis, col, buffer);
3490 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3491 calc_tabbed_width(pane, dis, col, buffer);
3493 col++;
3496 /*TODO
3497 if (flags.security) {
3498 static const TCHAR sSecTabs[] = {
3499 ' ','\t',' ','\t',' ','\t',' ',
3500 ' ','\t',' ',
3501 ' ','\t',' ','\t',' ','\t',' ',
3502 ' ','\t',' ',
3503 ' ','\t',' ','\t',' ','\t',' ',
3504 '\0'
3507 DWORD rights = get_access_mask();
3509 lstrcpy(buffer, sSecTabs);
3511 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3512 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3513 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3514 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3515 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3516 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3517 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3518 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3519 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3520 if (rights & WRITE_DAC) buffer[22] = 'C';
3521 if (rights & WRITE_OWNER) buffer[24] = 'O';
3522 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3524 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3527 if (flags.description) {
3528 get_description(buffer);
3529 output_text(dis, col++, buffer, 0, psize);
3533 #ifdef _NO_EXTENSIONS
3536 /* draw focus frame */
3537 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3538 /* Currently [04/2000] Wine neither behaves exactly the same */
3539 /* way as WIN 95 nor like Windows NT... */
3540 HGDIOBJ lastBrush;
3541 HPEN lastPen;
3542 HPEN hpen;
3544 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3545 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3546 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3547 } else
3548 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3550 lastPen = SelectPen(dis->hDC, hpen);
3551 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3552 SetROP2(dis->hDC, R2_XORPEN);
3553 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3554 SelectObject(dis->hDC, lastBrush);
3555 SelectObject(dis->hDC, lastPen);
3556 DeleteObject(hpen);
3558 #endif /* _NO_EXTENSIONS */
3562 #ifdef _NO_EXTENSIONS
3564 static void draw_splitbar(HWND hwnd, int x)
3566 RECT rt;
3567 HDC hdc = GetDC(hwnd);
3569 GetClientRect(hwnd, &rt);
3571 rt.left = x - SPLIT_WIDTH/2;
3572 rt.right = x + SPLIT_WIDTH/2+1;
3574 InvertRect(hdc, &rt);
3576 ReleaseDC(hwnd, hdc);
3579 #endif /* _NO_EXTENSIONS */
3582 #ifndef _NO_EXTENSIONS
3584 static void set_header(Pane* pane)
3586 HD_ITEM item;
3587 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3588 int i=0, x=0;
3590 item.mask = HDI_WIDTH;
3591 item.cxy = 0;
3593 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3594 x += pane->widths[i];
3595 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3598 if (i < COLUMNS) {
3599 x += pane->widths[i];
3600 item.cxy = x - scroll_pos;
3601 SendMessage(pane->hwndHeader, HDM_SETITEM, i++, (LPARAM) &item);
3603 for(; i<COLUMNS; i++) {
3604 item.cxy = pane->widths[i];
3605 x += pane->widths[i];
3606 SendMessage(pane->hwndHeader, HDM_SETITEM, i, (LPARAM) &item);
3611 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3613 switch(pnmh->code) {
3614 case HDN_ITEMCHANGED: {
3615 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3616 int idx = phdn->iItem;
3617 int dx = phdn->pitem->cxy - pane->widths[idx];
3618 int i;
3620 RECT clnt;
3621 GetClientRect(pane->hwnd, &clnt);
3623 pane->widths[idx] += dx;
3625 for(i=idx; ++i<=COLUMNS; )
3626 pane->positions[i] += dx;
3629 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3630 RECT rt_scr;
3631 RECT rt_clip;
3633 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3634 rt_scr.top = 0;
3635 rt_scr.right = clnt.right;
3636 rt_scr.bottom = clnt.bottom;
3638 rt_clip.left = pane->positions[idx]-scroll_pos;
3639 rt_clip.top = 0;
3640 rt_clip.right = clnt.right;
3641 rt_clip.bottom = clnt.bottom;
3643 if (rt_scr.left < 0) rt_scr.left = 0;
3644 if (rt_clip.left < 0) rt_clip.left = 0;
3646 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3648 rt_clip.right = pane->positions[idx+1];
3649 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3651 if (pnmh->code == HDN_ENDTRACK) {
3652 SendMessage(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3654 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3655 set_header(pane);
3659 return FALSE;
3662 case HDN_DIVIDERDBLCLICK: {
3663 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
3664 HD_ITEM item;
3666 calc_single_width(pane, phdn->iItem);
3667 item.mask = HDI_WIDTH;
3668 item.cxy = pane->widths[phdn->iItem];
3670 SendMessage(pane->hwndHeader, HDM_SETITEM, phdn->iItem, (LPARAM) &item);
3671 InvalidateRect(pane->hwnd, 0, TRUE);
3672 break;}
3675 return 0;
3678 #endif /* _NO_EXTENSIONS */
3681 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3683 TCHAR path[MAX_PATH];
3684 HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
3686 /* delete sub entries in left pane */
3687 for(;;) {
3688 LRESULT res = SendMessage(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3689 Entry* sub = (Entry*) res;
3691 if (res==LB_ERR || !sub || sub->level<=entry->level)
3692 break;
3694 SendMessage(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3697 /* empty right pane */
3698 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3700 /* release memory */
3701 free_entries(entry);
3703 /* read contents from disk */
3704 #ifdef _SHELL_FOLDERS
3705 if (entry->etype == ET_SHELL)
3707 read_directory(entry, NULL, child->sortOrder, hwnd);
3709 else
3710 #endif
3712 get_path(entry, path);
3713 read_directory(entry, path, child->sortOrder, hwnd);
3716 /* insert found entries in right pane */
3717 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3718 calc_widths(&child->right, FALSE);
3719 #ifndef _NO_EXTENSIONS
3720 set_header(&child->right);
3721 #endif
3723 child->header_wdths_ok = FALSE;
3725 SetCursor(old_cursor);
3729 /* expand a directory entry */
3731 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3733 int idx;
3734 Entry* p;
3736 if (!dir || dir->expanded || !dir->down)
3737 return FALSE;
3739 p = dir->down;
3741 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3742 p = p->next;
3744 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3745 p->data.cFileName[2]=='\0' && p->next)
3746 p = p->next;
3749 /* no subdirectories ? */
3750 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3751 return FALSE;
3753 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3755 dir->expanded = TRUE;
3757 /* insert entries in left pane */
3758 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3760 if (!child->header_wdths_ok) {
3761 if (calc_widths(&child->left, FALSE)) {
3762 #ifndef _NO_EXTENSIONS
3763 set_header(&child->left);
3764 #endif
3766 child->header_wdths_ok = TRUE;
3770 return TRUE;
3774 static void collapse_entry(Pane* pane, Entry* dir)
3776 int idx = SendMessage(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3778 ShowWindow(pane->hwnd, SW_HIDE);
3780 /* hide sub entries */
3781 for(;;) {
3782 LRESULT res = SendMessage(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3783 Entry* sub = (Entry*) res;
3785 if (res==LB_ERR || !sub || sub->level<=dir->level)
3786 break;
3788 SendMessage(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3791 dir->expanded = FALSE;
3793 ShowWindow(pane->hwnd, SW_SHOW);
3797 static void refresh_right_pane(ChildWnd* child)
3799 SendMessage(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3800 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3801 calc_widths(&child->right, FALSE);
3803 #ifndef _NO_EXTENSIONS
3804 set_header(&child->right);
3805 #endif
3808 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3810 TCHAR path[MAX_PATH];
3812 if (!entry)
3813 return;
3815 path[0] = '\0';
3817 child->left.cur = entry;
3819 child->right.root = entry->down? entry->down: entry;
3820 child->right.cur = entry;
3822 if (!entry->scanned)
3823 scan_entry(child, entry, idx, hwnd);
3824 else
3825 refresh_right_pane(child);
3827 get_path(entry, path);
3828 lstrcpy(child->path, path);
3830 if (child->hwnd) /* only change window title, if the window already exists */
3831 SetWindowText(child->hwnd, path);
3833 if (path[0])
3834 if (SetCurrentDirectory(path))
3835 set_space_status();
3839 static void refresh_child(ChildWnd* child)
3841 TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3842 Entry* entry;
3843 int idx;
3845 get_path(child->left.cur, path);
3846 _tsplitpath(path, drv, NULL, NULL, NULL);
3848 child->right.root = NULL;
3850 scan_entry(child, &child->root.entry, 0, child->hwnd);
3852 #ifdef _SHELL_FOLDERS
3853 if (child->root.entry.etype == ET_SHELL)
3854 entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd);
3855 else
3856 #endif
3857 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3859 if (!entry)
3860 entry = &child->root.entry;
3862 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3864 set_curdir(child, entry, 0, child->hwnd);
3866 idx = SendMessage(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3867 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
3871 static void create_drive_bar(void)
3873 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3874 #ifndef _NO_EXTENSIONS
3875 TCHAR b1[BUFFER_LEN];
3876 #endif
3877 int btn = 1;
3878 PTSTR p;
3880 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
3882 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3883 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3884 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3886 #ifndef _NO_EXTENSIONS
3887 #ifdef __WINE__
3888 /* insert unix file system button */
3889 b1[0] = '/';
3890 b1[1] = '\0';
3891 b1[2] = '\0';
3892 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3894 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3895 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3896 drivebarBtn.iString++;
3897 #endif
3898 #ifdef _SHELL_FOLDERS
3899 /* insert shell namespace button */
3900 load_string(b1, IDS_SHELL);
3901 b1[lstrlen(b1)+1] = '\0';
3902 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1);
3904 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3905 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3906 drivebarBtn.iString++;
3907 #endif
3909 /* register windows drive root strings */
3910 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives);
3911 #endif
3913 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3915 for(p=Globals.drives; *p; ) {
3916 #ifdef _NO_EXTENSIONS
3917 /* insert drive letter */
3918 TCHAR b[3] = {tolower(*p)};
3919 SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b);
3920 #endif
3921 switch(GetDriveType(p)) {
3922 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3923 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3924 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3925 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3926 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3929 SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn);
3930 drivebarBtn.idCommand++;
3931 drivebarBtn.iString++;
3933 while(*p++);
3937 static void refresh_drives(void)
3939 RECT rect;
3941 /* destroy drive bar */
3942 DestroyWindow(Globals.hdrivebar);
3943 Globals.hdrivebar = 0;
3945 /* re-create drive bar */
3946 create_drive_bar();
3948 /* update window layout */
3949 GetClientRect(Globals.hMainWnd, &rect);
3950 SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3954 static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
3956 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3958 if ((int)hinst <= 32) {
3959 display_error(hwnd, GetLastError());
3960 return FALSE;
3963 return TRUE;
3967 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3969 TCHAR cmd[MAX_PATH];
3971 #ifdef _SHELL_FOLDERS
3972 if (entry->etype == ET_SHELL) {
3973 BOOL ret = TRUE;
3975 SHELLEXECUTEINFO shexinfo;
3977 shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
3978 shexinfo.fMask = SEE_MASK_IDLIST;
3979 shexinfo.hwnd = hwnd;
3980 shexinfo.lpVerb = NULL;
3981 shexinfo.lpFile = NULL;
3982 shexinfo.lpParameters = NULL;
3983 shexinfo.lpDirectory = NULL;
3984 shexinfo.nShow = nCmdShow;
3985 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3987 if (!ShellExecuteEx(&shexinfo)) {
3988 display_error(hwnd, GetLastError());
3989 ret = FALSE;
3992 if (shexinfo.lpIDList != entry->pidl)
3993 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3995 return ret;
3997 #endif
3999 get_path(entry, cmd);
4001 /* start program, open document... */
4002 return launch_file(hwnd, cmd, nCmdShow);
4006 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
4008 Entry* entry = pane->cur;
4010 if (!entry)
4011 return;
4013 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
4014 int scanned_old = entry->scanned;
4016 if (!scanned_old)
4018 int idx = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
4019 scan_entry(child, entry, idx, hwnd);
4022 #ifndef _NO_EXTENSIONS
4023 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
4024 return;
4025 #endif
4027 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
4028 entry = child->left.cur->up;
4029 collapse_entry(&child->left, entry);
4030 goto focus_entry;
4031 } else if (entry->expanded)
4032 collapse_entry(pane, child->left.cur);
4033 else {
4034 expand_entry(child, child->left.cur);
4036 if (!pane->treePane) focus_entry: {
4037 int idxstart = SendMessage(child->left.hwnd, LB_GETCURSEL, 0, 0);
4038 int idx = SendMessage(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
4039 SendMessage(child->left.hwnd, LB_SETCURSEL, idx, 0);
4040 set_curdir(child, entry, idx, hwnd);
4044 if (!scanned_old) {
4045 calc_widths(pane, FALSE);
4047 #ifndef _NO_EXTENSIONS
4048 set_header(pane);
4049 #endif
4051 } else {
4052 if (GetKeyState(VK_MENU) < 0)
4053 show_properties_dlg(entry, child->hwnd);
4054 else
4055 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
4060 static BOOL pane_command(Pane* pane, UINT cmd)
4062 switch(cmd) {
4063 case ID_VIEW_NAME:
4064 if (pane->visible_cols) {
4065 pane->visible_cols = 0;
4066 calc_widths(pane, TRUE);
4067 #ifndef _NO_EXTENSIONS
4068 set_header(pane);
4069 #endif
4070 InvalidateRect(pane->hwnd, 0, TRUE);
4071 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
4072 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
4073 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4075 break;
4077 case ID_VIEW_ALL_ATTRIBUTES:
4078 if (pane->visible_cols != COL_ALL) {
4079 pane->visible_cols = COL_ALL;
4080 calc_widths(pane, TRUE);
4081 #ifndef _NO_EXTENSIONS
4082 set_header(pane);
4083 #endif
4084 InvalidateRect(pane->hwnd, 0, TRUE);
4085 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
4086 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
4087 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
4089 break;
4091 #ifndef _NO_EXTENSIONS
4092 case ID_PREFERRED_SIZES: {
4093 calc_widths(pane, TRUE);
4094 set_header(pane);
4095 InvalidateRect(pane->hwnd, 0, TRUE);
4096 break;}
4097 #endif
4099 /* TODO: more command ids... */
4101 default:
4102 return FALSE;
4105 return TRUE;
4109 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
4111 if (child->sortOrder != sortOrder) {
4112 child->sortOrder = sortOrder;
4113 refresh_child(child);
4117 static void update_view_menu(ChildWnd* child)
4119 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
4120 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
4121 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
4122 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
4126 static BOOL is_directory(LPCTSTR target)
4128 /*TODO correctly handle UNIX paths */
4129 DWORD target_attr = GetFileAttributes(target);
4131 if (target_attr == INVALID_FILE_ATTRIBUTES)
4132 return FALSE;
4134 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
4137 static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target)
4139 TCHAR path[MAX_PATH];
4140 int len;
4142 get_path(pane->cur, path);
4144 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
4145 return FALSE;
4147 get_path(pane->cur, source);
4149 /* convert relative targets to absolute paths */
4150 if (path[0]!='/' && path[1]!=':') {
4151 get_path(pane->cur->up, target);
4152 len = lstrlen(target);
4154 if (target[len-1]!='\\' && target[len-1]!='/')
4155 target[len++] = '/';
4157 lstrcpy(target+len, path);
4158 } else
4159 lstrcpy(target, path);
4161 /* If the target already exists as directory, create a new target below this. */
4162 if (is_directory(path)) {
4163 TCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
4164 static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
4166 _tsplitpath(source, NULL, NULL, fname, ext);
4168 wsprintf(target, sAppend, path, fname, ext);
4171 return TRUE;
4175 static IContextMenu2* s_pctxmenu2 = NULL;
4176 static IContextMenu3* s_pctxmenu3 = NULL;
4178 static void CtxMenu_reset(void)
4180 s_pctxmenu2 = NULL;
4181 s_pctxmenu3 = NULL;
4184 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4186 IContextMenu* pcm = NULL;
4188 CtxMenu_reset();
4190 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4191 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4192 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4193 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4195 if (pcm) {
4196 IContextMenu_Release(pcm1);
4197 return pcm;
4198 } else
4199 return pcm1;
4202 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4204 if (s_pctxmenu3) {
4205 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4206 return TRUE;
4209 if (s_pctxmenu2)
4210 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4211 return TRUE;
4213 return FALSE;
4217 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4219 IContextMenu* pcm;
4220 BOOL executed = FALSE;
4222 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4223 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4225 if (SUCCEEDED(hr)) {
4226 HMENU hmenu = CreatePopupMenu();
4228 pcm = CtxMenu_query_interfaces(pcm);
4230 if (hmenu) {
4231 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4233 if (SUCCEEDED(hr)) {
4234 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4236 CtxMenu_reset();
4238 if (idCmd) {
4239 CMINVOKECOMMANDINFO cmi;
4241 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4242 cmi.fMask = 0;
4243 cmi.hwnd = hwndParent;
4244 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4245 cmi.lpParameters = NULL;
4246 cmi.lpDirectory = NULL;
4247 cmi.nShow = SW_SHOWNORMAL;
4248 cmi.dwHotKey = 0;
4249 cmi.hIcon = 0;
4251 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4252 executed = TRUE;
4254 } else
4255 CtxMenu_reset();
4258 IContextMenu_Release(pcm);
4261 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4265 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4267 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4268 ASSERT(child);
4270 switch(nmsg) {
4271 case WM_DRAWITEM: {
4272 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4273 Entry* entry = (Entry*) dis->itemData;
4275 if (dis->CtlID == IDW_TREE_LEFT)
4276 draw_item(&child->left, dis, entry, -1);
4277 else if (dis->CtlID == IDW_TREE_RIGHT)
4278 draw_item(&child->right, dis, entry, -1);
4279 else
4280 goto draw_menu_item;
4282 return TRUE;}
4284 case WM_CREATE:
4285 InitChildWindow(child);
4286 break;
4288 case WM_NCDESTROY:
4289 free_child_window(child);
4290 SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
4291 break;
4293 case WM_PAINT: {
4294 PAINTSTRUCT ps;
4295 HBRUSH lastBrush;
4296 RECT rt;
4297 GetClientRect(hwnd, &rt);
4298 BeginPaint(hwnd, &ps);
4299 rt.left = child->split_pos-SPLIT_WIDTH/2;
4300 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4301 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4302 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4303 SelectObject(ps.hdc, lastBrush);
4304 #ifdef _NO_EXTENSIONS
4305 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4306 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4307 #endif
4308 EndPaint(hwnd, &ps);
4309 break;}
4311 case WM_SETCURSOR:
4312 if (LOWORD(lparam) == HTCLIENT) {
4313 POINT pt;
4314 GetCursorPos(&pt);
4315 ScreenToClient(hwnd, &pt);
4317 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4318 SetCursor(LoadCursor(0, IDC_SIZEWE));
4319 return TRUE;
4322 goto def;
4324 case WM_LBUTTONDOWN: {
4325 RECT rt;
4326 int x = (short)LOWORD(lparam);
4328 GetClientRect(hwnd, &rt);
4330 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4331 last_split = child->split_pos;
4332 #ifdef _NO_EXTENSIONS
4333 draw_splitbar(hwnd, last_split);
4334 #endif
4335 SetCapture(hwnd);
4338 break;}
4340 case WM_LBUTTONUP:
4341 if (GetCapture() == hwnd) {
4342 #ifdef _NO_EXTENSIONS
4343 RECT rt;
4344 int x = (short)LOWORD(lparam);
4345 draw_splitbar(hwnd, last_split);
4346 last_split = -1;
4347 GetClientRect(hwnd, &rt);
4348 child->split_pos = x;
4349 resize_tree(child, rt.right, rt.bottom);
4350 #endif
4351 ReleaseCapture();
4353 break;
4355 #ifdef _NO_EXTENSIONS
4356 case WM_CAPTURECHANGED:
4357 if (GetCapture()==hwnd && last_split>=0)
4358 draw_splitbar(hwnd, last_split);
4359 break;
4360 #endif
4362 case WM_KEYDOWN:
4363 if (wparam == VK_ESCAPE)
4364 if (GetCapture() == hwnd) {
4365 RECT rt;
4366 #ifdef _NO_EXTENSIONS
4367 draw_splitbar(hwnd, last_split);
4368 #else
4369 child->split_pos = last_split;
4370 #endif
4371 GetClientRect(hwnd, &rt);
4372 resize_tree(child, rt.right, rt.bottom);
4373 last_split = -1;
4374 ReleaseCapture();
4375 SetCursor(LoadCursor(0, IDC_ARROW));
4377 break;
4379 case WM_MOUSEMOVE:
4380 if (GetCapture() == hwnd) {
4381 RECT rt;
4382 int x = (short)LOWORD(lparam);
4384 #ifdef _NO_EXTENSIONS
4385 HDC hdc = GetDC(hwnd);
4386 GetClientRect(hwnd, &rt);
4388 rt.left = last_split-SPLIT_WIDTH/2;
4389 rt.right = last_split+SPLIT_WIDTH/2+1;
4390 InvertRect(hdc, &rt);
4392 last_split = x;
4393 rt.left = x-SPLIT_WIDTH/2;
4394 rt.right = x+SPLIT_WIDTH/2+1;
4395 InvertRect(hdc, &rt);
4397 ReleaseDC(hwnd, hdc);
4398 #else
4399 GetClientRect(hwnd, &rt);
4401 if (x>=0 && x<rt.right) {
4402 child->split_pos = x;
4403 resize_tree(child, rt.right, rt.bottom);
4404 rt.left = x-SPLIT_WIDTH/2;
4405 rt.right = x+SPLIT_WIDTH/2+1;
4406 InvalidateRect(hwnd, &rt, FALSE);
4407 UpdateWindow(child->left.hwnd);
4408 UpdateWindow(hwnd);
4409 UpdateWindow(child->right.hwnd);
4411 #endif
4413 break;
4415 #ifndef _NO_EXTENSIONS
4416 case WM_GETMINMAXINFO:
4417 DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4419 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4421 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4422 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4423 break;}
4424 #endif /* _NO_EXTENSIONS */
4426 case WM_SETFOCUS:
4427 if (SetCurrentDirectory(child->path))
4428 set_space_status();
4429 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4430 break;
4432 case WM_DISPATCH_COMMAND: {
4433 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4435 switch(LOWORD(wparam)) {
4436 case ID_WINDOW_NEW: {
4437 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4439 if (!create_child_window(new_child))
4440 HeapFree(GetProcessHeap(), 0, new_child);
4442 break;}
4444 case ID_REFRESH:
4445 refresh_drives();
4446 refresh_child(child);
4447 break;
4449 case ID_ACTIVATE:
4450 activate_entry(child, pane, hwnd);
4451 break;
4453 case ID_FILE_MOVE: {
4454 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4456 if (prompt_target(pane, source, target)) {
4457 SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target};
4459 source[lstrlen(source)+1] = '\0';
4460 target[lstrlen(target)+1] = '\0';
4462 if (!SHFileOperation(&shfo))
4463 refresh_child(child);
4465 break;}
4467 case ID_FILE_COPY: {
4468 TCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4470 if (prompt_target(pane, source, target)) {
4471 SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target};
4473 source[lstrlen(source)+1] = '\0';
4474 target[lstrlen(target)+1] = '\0';
4476 if (!SHFileOperation(&shfo))
4477 refresh_child(child);
4479 break;}
4481 case ID_FILE_DELETE: {
4482 TCHAR path[BUFFER_LEN];
4483 SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path};
4485 get_path(pane->cur, path);
4487 path[lstrlen(path)+1] = '\0';
4489 if (!SHFileOperation(&shfo))
4490 refresh_child(child);
4491 break;}
4493 case ID_VIEW_SORT_NAME:
4494 set_sort_order(child, SORT_NAME);
4495 break;
4497 case ID_VIEW_SORT_TYPE:
4498 set_sort_order(child, SORT_EXT);
4499 break;
4501 case ID_VIEW_SORT_SIZE:
4502 set_sort_order(child, SORT_SIZE);
4503 break;
4505 case ID_VIEW_SORT_DATE:
4506 set_sort_order(child, SORT_DATE);
4507 break;
4509 case ID_VIEW_FILTER: {
4510 struct FilterDialog dlg;
4512 memset(&dlg, 0, sizeof(struct FilterDialog));
4513 lstrcpy(dlg.pattern, child->filter_pattern);
4514 dlg.flags = child->filter_flags;
4516 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4517 lstrcpy(child->filter_pattern, dlg.pattern);
4518 child->filter_flags = dlg.flags;
4519 refresh_right_pane(child);
4521 break;}
4523 case ID_VIEW_SPLIT: {
4524 last_split = child->split_pos;
4525 #ifdef _NO_EXTENSIONS
4526 draw_splitbar(hwnd, last_split);
4527 #endif
4528 SetCapture(hwnd);
4529 break;}
4531 case ID_EDIT_PROPERTIES:
4532 show_properties_dlg(pane->cur, child->hwnd);
4533 break;
4535 default:
4536 return pane_command(pane, LOWORD(wparam));
4539 return TRUE;}
4541 case WM_COMMAND: {
4542 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4544 switch(HIWORD(wparam)) {
4545 case LBN_SELCHANGE: {
4546 int idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4547 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4549 if (pane == &child->left)
4550 set_curdir(child, entry, idx, hwnd);
4551 else
4552 pane->cur = entry;
4553 break;}
4555 case LBN_DBLCLK:
4556 activate_entry(child, pane, hwnd);
4557 break;
4559 break;}
4561 #ifndef _NO_EXTENSIONS
4562 case WM_NOTIFY: {
4563 NMHDR* pnmh = (NMHDR*) lparam;
4564 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4565 #endif
4567 #ifdef _SHELL_FOLDERS
4568 case WM_CONTEXTMENU: {
4569 POINT pt, pt_clnt;
4570 Pane* pane;
4571 int idx;
4573 /* first select the current item in the listbox */
4574 HWND hpanel = (HWND) wparam;
4575 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4576 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4577 ScreenToClient(hpanel, &pt_clnt);
4578 SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4579 SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4581 /* now create the popup menu using shell namespace and IContextMenu */
4582 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4583 idx = SendMessage(pane->hwnd, LB_GETCURSEL, 0, 0);
4585 if (idx != -1) {
4586 Entry* entry = (Entry*) SendMessage(pane->hwnd, LB_GETITEMDATA, idx, 0);
4588 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4590 if (pidl_abs) {
4591 IShellFolder* parentFolder;
4592 LPCITEMIDLIST pidlLast;
4594 /* get and use the parent folder to display correct context menu in all cases */
4595 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4596 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4597 refresh_child(child);
4599 IShellFolder_Release(parentFolder);
4602 IMalloc_Free(Globals.iMalloc, pidl_abs);
4605 break;}
4606 #endif
4608 case WM_MEASUREITEM:
4609 draw_menu_item:
4610 if (!wparam) /* Is the message menu-related? */
4611 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4612 return TRUE;
4614 break;
4616 case WM_INITMENUPOPUP:
4617 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4618 return 0;
4620 update_view_menu(child);
4621 break;
4623 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4624 if (s_pctxmenu3) {
4625 LRESULT lResult = 0;
4627 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4629 return lResult;
4632 break;
4634 case WM_SIZE:
4635 if (wparam != SIZE_MINIMIZED)
4636 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4637 /* fall through */
4639 default: def:
4640 return DefMDIChildProc(hwnd, nmsg, wparam, lparam);
4643 return 0;
4647 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4649 ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
4650 Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
4651 ASSERT(child);
4653 switch(nmsg) {
4654 #ifndef _NO_EXTENSIONS
4655 case WM_HSCROLL:
4656 set_header(pane);
4657 break;
4658 #endif
4660 case WM_SETFOCUS:
4661 child->focus_pane = pane==&child->right? 1: 0;
4662 SendMessage(hwnd, LB_SETSEL, TRUE, 1);
4663 /*TODO: check menu items */
4664 break;
4666 case WM_KEYDOWN:
4667 if (wparam == VK_TAB) {
4668 /*TODO: SetFocus(Globals.hdrivebar) */
4669 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4673 return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4677 static void InitInstance(HINSTANCE hinstance)
4679 static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4681 WNDCLASSEX wcFrame;
4682 WNDCLASS wcChild;
4683 ATOM hChildClass;
4684 int col;
4686 INITCOMMONCONTROLSEX icc = {
4687 sizeof(INITCOMMONCONTROLSEX),
4688 ICC_BAR_CLASSES
4691 HDC hdc = GetDC(0);
4693 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4695 InitCommonControlsEx(&icc);
4698 /* register frame window class */
4700 wcFrame.cbSize = sizeof(WNDCLASSEX);
4701 wcFrame.style = 0;
4702 wcFrame.lpfnWndProc = FrameWndProc;
4703 wcFrame.cbClsExtra = 0;
4704 wcFrame.cbWndExtra = 0;
4705 wcFrame.hInstance = hinstance;
4706 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE));
4707 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
4708 wcFrame.hbrBackground = 0;
4709 wcFrame.lpszMenuName = 0;
4710 wcFrame.lpszClassName = sWINEFILEFRAME;
4711 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
4712 MAKEINTRESOURCE(IDI_WINEFILE),
4713 IMAGE_ICON,
4714 GetSystemMetrics(SM_CXSMICON),
4715 GetSystemMetrics(SM_CYSMICON),
4716 LR_SHARED);
4718 Globals.hframeClass = RegisterClassEx(&wcFrame);
4721 /* register tree windows class */
4723 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4724 wcChild.lpfnWndProc = ChildWndProc;
4725 wcChild.cbClsExtra = 0;
4726 wcChild.cbWndExtra = 0;
4727 wcChild.hInstance = hinstance;
4728 wcChild.hIcon = 0;
4729 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
4730 wcChild.hbrBackground = 0;
4731 wcChild.lpszMenuName = 0;
4732 wcChild.lpszClassName = sWINEFILETREE;
4734 hChildClass = RegisterClass(&wcChild);
4737 Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE));
4739 Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4741 ReleaseDC(0, hdc);
4743 Globals.hInstance = hinstance;
4745 #ifdef _SHELL_FOLDERS
4746 CoInitialize(NULL);
4747 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4748 SHGetDesktopFolder(&Globals.iDesktop);
4749 #ifdef __WINE__
4750 Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME);
4751 #else
4752 Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
4753 #endif
4754 #endif
4756 /* load column strings */
4757 col = 1;
4759 load_string(g_pos_names[col++], IDS_COL_NAME);
4760 load_string(g_pos_names[col++], IDS_COL_SIZE);
4761 load_string(g_pos_names[col++], IDS_COL_CDATE);
4762 #ifndef _NO_EXTENSIONS
4763 load_string(g_pos_names[col++], IDS_COL_ADATE);
4764 load_string(g_pos_names[col++], IDS_COL_MDATE);
4765 load_string(g_pos_names[col++], IDS_COL_IDX);
4766 load_string(g_pos_names[col++], IDS_COL_LINKS);
4767 #endif
4768 load_string(g_pos_names[col++], IDS_COL_ATTR);
4769 #ifndef _NO_EXTENSIONS
4770 load_string(g_pos_names[col++], IDS_COL_SEC);
4771 #endif
4775 static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path)
4777 static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4779 TCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4780 ChildWnd* child;
4781 HMENU hMenuFrame, hMenuWindow;
4782 windowOptions opts;
4784 CLIENTCREATESTRUCT ccs;
4786 if (Globals.hMainWnd)
4787 return;
4789 opts = load_registry_settings();
4790 hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE));
4791 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4793 Globals.hMenuFrame = hMenuFrame;
4794 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4795 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4797 ccs.hWindowMenu = hMenuWindow;
4798 ccs.idFirstChild = IDW_FIRST_CHILD;
4801 /* create main window */
4802 Globals.hMainWnd = CreateWindowEx(0, (LPCTSTR)(int)Globals.hframeClass, RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4803 opts.start_x, opts.start_y, opts.width, opts.height,
4804 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4807 Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL,
4808 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4809 0, 0, 0, 0,
4810 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4812 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4813 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4815 create_drive_bar();
4818 TBBUTTON toolbarBtns[] = {
4819 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4820 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4821 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4822 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4823 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4824 /*TODO
4825 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4826 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4827 */ };
4829 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4830 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4831 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4832 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4835 Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4836 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4838 /* CreateStatusWindow does not accept WS_BORDER
4839 Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4840 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4841 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4843 /*TODO: read paths from registry */
4845 if (!path || !*path) {
4846 GetCurrentDirectory(MAX_PATH, buffer);
4847 path = buffer;
4850 ShowWindow(Globals.hMainWnd, cmdshow);
4852 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4853 /* Shell Namespace as default: */
4854 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4855 #else
4856 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4857 #endif
4859 child->pos.showCmd = SW_SHOWMAXIMIZED;
4860 child->pos.rcNormalPosition.left = 0;
4861 child->pos.rcNormalPosition.top = 0;
4862 child->pos.rcNormalPosition.right = 320;
4863 child->pos.rcNormalPosition.bottom = 280;
4865 if (!create_child_window(child))
4866 HeapFree(GetProcessHeap(), 0, child);
4868 SetWindowPlacement(child->hwnd, &child->pos);
4870 Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
4872 Globals.prescan_node = FALSE;
4874 UpdateWindow(Globals.hMainWnd);
4876 if (path && path[0])
4878 int index,count;
4879 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4880 TCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4882 memset(name,0,sizeof(name));
4883 memset(name,0,sizeof(ext));
4884 _tsplitpath(path, drv, dir, name, ext);
4885 if (name[0])
4887 count = SendMessage(child->right.hwnd, LB_GETCOUNT, 0, 0);
4888 lstrcpy(fullname,name);
4889 lstrcat(fullname,ext);
4891 for (index = 0; index < count; index ++)
4893 Entry* entry = (Entry*) SendMessage(child->right.hwnd, LB_GETITEMDATA, index, 0);
4894 if (lstrcmp(entry->data.cFileName,fullname)==0 ||
4895 lstrcmp(entry->data.cAlternateFileName,fullname)==0)
4897 SendMessage(child->right.hwnd, LB_SETCURSEL, index, 0);
4898 SetFocus(child->right.hwnd);
4899 break;
4906 static void ExitInstance(void)
4908 #ifdef _SHELL_FOLDERS
4909 IShellFolder_Release(Globals.iDesktop);
4910 IMalloc_Release(Globals.iMalloc);
4911 CoUninitialize();
4912 #endif
4914 DeleteObject(Globals.hfont);
4915 ImageList_Destroy(Globals.himl);
4918 #ifdef _NO_EXTENSIONS
4920 /* search for already running win[e]files */
4922 static int g_foundPrevInstance = 0;
4924 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4926 TCHAR cls[128];
4928 GetClassName(hwnd, cls, 128);
4930 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
4931 g_foundPrevInstance++;
4932 return FALSE;
4935 return TRUE;
4938 /* search for window of given class name to allow only one running instance */
4939 static int find_window_class(LPCTSTR classname)
4941 EnumWindows(EnumWndProc, (LPARAM)classname);
4943 if (g_foundPrevInstance)
4944 return 1;
4946 return 0;
4949 #endif
4951 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path)
4953 MSG msg;
4955 InitInstance(hinstance);
4957 show_frame(0, cmdshow, path);
4959 while(GetMessage(&msg, 0, 0, 0)) {
4960 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4961 continue;
4963 if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg))
4964 continue;
4966 TranslateMessage(&msg);
4967 DispatchMessage(&msg);
4970 ExitInstance();
4972 return msg.wParam;
4976 #if defined(UNICODE) && defined(_MSC_VER)
4977 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4978 #else
4979 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4980 #endif
4982 #ifdef _NO_EXTENSIONS
4983 if (find_window_class(sWINEFILEFRAME))
4984 return 1;
4985 #endif
4987 #if defined(UNICODE) && !defined(_MSC_VER)
4988 { /* convert ANSI cmdline into WCS path string */
4989 TCHAR buffer[MAX_PATH];
4990 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4991 winefile_main(hinstance, cmdshow, buffer);
4993 #else
4994 winefile_main(hinstance, cmdshow, cmdline);
4995 #endif
4997 return 0;