winefile: Add Ukrainian translations.
[wine/hacks.git] / programs / winefile / winefile.c
blobb63144ce7e034589db8a13df46c1cbcf52520b10
1 /*
2 * Winefile
4 * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
5 * Copyright 2006 Jason Green
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifdef __WINE__
23 #include "config.h"
24 #include "wine/port.h"
26 /* for unix filesystem function calls */
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <dirent.h>
30 #endif
32 #define COBJMACROS
34 #include "winefile.h"
35 #include "resource.h"
36 #include "wine/unicode.h"
38 #ifdef _NO_EXTENSIONS
39 #undef _LEFT_FILES
40 #endif
42 #ifndef _MAX_PATH
43 #define _MAX_DRIVE 3
44 #define _MAX_FNAME 256
45 #define _MAX_DIR _MAX_FNAME
46 #define _MAX_EXT _MAX_FNAME
47 #define _MAX_PATH 260
48 #endif
50 #ifdef NONAMELESSUNION
51 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
52 #else
53 #define UNION_MEMBER(x) x
54 #endif
57 #ifdef _SHELL_FOLDERS
58 #define DEFAULT_SPLIT_POS 300
59 #else
60 #define DEFAULT_SPLIT_POS 200
61 #endif
63 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
64 'W','i','n','e','\\',
65 'W','i','n','e','F','i','l','e','\0'};
66 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
67 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
68 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
69 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
70 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
72 enum ENTRY_TYPE {
73 ET_WINDOWS,
74 ET_UNIX,
75 #ifdef _SHELL_FOLDERS
76 ET_SHELL
77 #endif
80 typedef struct _Entry {
81 struct _Entry* next;
82 struct _Entry* down;
83 struct _Entry* up;
85 BOOL expanded;
86 BOOL scanned;
87 int level;
89 WIN32_FIND_DATAW data;
91 #ifndef _NO_EXTENSIONS
92 BY_HANDLE_FILE_INFORMATION bhfi;
93 BOOL bhfi_valid;
94 enum ENTRY_TYPE etype;
95 #endif
96 #ifdef _SHELL_FOLDERS
97 LPITEMIDLIST pidl;
98 IShellFolder* folder;
99 HICON hicon;
100 #endif
101 } Entry;
103 typedef struct {
104 Entry entry;
105 WCHAR path[MAX_PATH];
106 WCHAR volname[_MAX_FNAME];
107 WCHAR fs[_MAX_DIR];
108 DWORD drive_type;
109 DWORD fs_flags;
110 } Root;
112 enum COLUMN_FLAGS {
113 COL_SIZE = 0x01,
114 COL_DATE = 0x02,
115 COL_TIME = 0x04,
116 COL_ATTRIBUTES = 0x08,
117 COL_DOSNAMES = 0x10,
118 #ifdef _NO_EXTENSIONS
119 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES
120 #else
121 COL_INDEX = 0x20,
122 COL_LINKS = 0x40,
123 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
124 #endif
127 typedef enum {
128 SORT_NAME,
129 SORT_EXT,
130 SORT_SIZE,
131 SORT_DATE
132 } SORT_ORDER;
134 typedef struct {
135 HWND hwnd;
136 #ifndef _NO_EXTENSIONS
137 HWND hwndHeader;
138 #endif
140 #ifndef _NO_EXTENSIONS
141 #define COLUMNS 10
142 #else
143 #define COLUMNS 5
144 #endif
145 int widths[COLUMNS];
146 int positions[COLUMNS+1];
148 BOOL treePane;
149 int visible_cols;
150 Entry* root;
151 Entry* cur;
152 } Pane;
154 typedef struct {
155 HWND hwnd;
156 Pane left;
157 Pane right;
158 int focus_pane; /* 0: left 1: right */
159 WINDOWPLACEMENT pos;
160 int split_pos;
161 BOOL header_wdths_ok;
163 WCHAR path[MAX_PATH];
164 WCHAR filter_pattern[MAX_PATH];
165 int filter_flags;
166 Root root;
168 SORT_ORDER sortOrder;
169 } ChildWnd;
173 static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd);
174 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
175 static void refresh_child(ChildWnd* child);
176 static void refresh_drives(void);
177 static void get_path(Entry* dir, PWSTR path);
178 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols);
180 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
181 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
182 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
185 /* globals */
186 WINEFILE_GLOBALS Globals;
188 static int last_split;
190 /* some common string constants */
191 static const WCHAR sEmpty[] = {'\0'};
192 static const WCHAR sSpace[] = {' ', '\0'};
193 static const WCHAR sNumFmt[] = {'%','d','\0'};
194 static const WCHAR sQMarks[] = {'?','?','?','\0'};
196 /* window class names */
197 static const WCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
198 static const WCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
200 static void format_longlong(LPWSTR ret, ULONGLONG val)
202 WCHAR buffer[65], *p = &buffer[64];
204 *p = 0;
205 do {
206 *(--p) = '0' + val % 10;
207 val /= 10;
208 } while (val);
209 lstrcpyW( ret, p );
213 /* load resource string */
214 static LPWSTR load_string(LPWSTR buffer, DWORD size, UINT id)
216 LoadStringW(Globals.hInstance, id, buffer, size);
217 return buffer;
220 #define RS(b, i) load_string(b, sizeof(b)/sizeof(b[0]), i)
223 /* display error message for the specified WIN32 error code */
224 static void display_error(HWND hwnd, DWORD error)
226 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
227 PWSTR msg;
229 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
230 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PWSTR)&msg, 0, NULL))
231 MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
232 else
233 MessageBoxW(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
235 LocalFree(msg);
239 /* display network error message using WNetGetLastErrorW() */
240 static void display_network_error(HWND hwnd)
242 WCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
243 DWORD error;
245 if (WNetGetLastErrorW(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
246 MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
249 static inline BOOL get_check(HWND hwnd, INT id)
251 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
254 static inline INT set_check(HWND hwnd, INT id, BOOL on)
256 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
259 static inline void choose_font(HWND hwnd)
261 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
262 CHOOSEFONTW chFont;
263 LOGFONTW lFont;
265 HDC hdc = GetDC(hwnd);
266 chFont.lStructSize = sizeof(CHOOSEFONTW);
267 chFont.hwndOwner = hwnd;
268 chFont.hDC = NULL;
269 chFont.lpLogFont = &lFont;
270 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL;
271 chFont.rgbColors = RGB(0,0,0);
272 chFont.lCustData = 0;
273 chFont.lpfnHook = NULL;
274 chFont.lpTemplateName = NULL;
275 chFont.hInstance = Globals.hInstance;
276 chFont.lpszStyle = NULL;
277 chFont.nFontType = SIMULATED_FONTTYPE;
278 chFont.nSizeMin = 0;
279 chFont.nSizeMax = 24;
281 if (ChooseFontW(&chFont)) {
282 HWND childWnd;
283 HFONT hFontOld;
285 DeleteObject(Globals.hfont);
286 Globals.hfont = CreateFontIndirectW(&lFont);
287 hFontOld = SelectObject(hdc, Globals.hfont);
288 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
290 /* change font in all open child windows */
291 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
292 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
293 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
294 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
295 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
296 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
297 InvalidateRect(child->left.hwnd, NULL, TRUE);
298 InvalidateRect(child->right.hwnd, NULL, TRUE);
301 SelectObject(hdc, hFontOld);
303 else if (CommDlgExtendedError()) {
304 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
305 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
306 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
309 ReleaseDC(hwnd, hdc);
313 /* allocate and initialise a directory entry */
314 static Entry* alloc_entry(void)
316 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
318 #ifdef _SHELL_FOLDERS
319 entry->pidl = NULL;
320 entry->folder = NULL;
321 entry->hicon = 0;
322 #endif
324 return entry;
327 /* free a directory entry */
328 static void free_entry(Entry* entry)
330 #ifdef _SHELL_FOLDERS
331 if (entry->hicon && entry->hicon!=(HICON)-1)
332 DestroyIcon(entry->hicon);
334 if (entry->folder && entry->folder!=Globals.iDesktop)
335 IShellFolder_Release(entry->folder);
337 if (entry->pidl)
338 IMalloc_Free(Globals.iMalloc, entry->pidl);
339 #endif
341 HeapFree(GetProcessHeap(), 0, entry);
344 /* recursively free all child entries */
345 static void free_entries(Entry* dir)
347 Entry *entry, *next=dir->down;
349 if (next) {
350 dir->down = 0;
352 do {
353 entry = next;
354 next = entry->next;
356 free_entries(entry);
357 free_entry(entry);
358 } while(next);
363 static void read_directory_win(Entry* dir, LPCWSTR path)
365 Entry* first_entry = NULL;
366 Entry* last = NULL;
367 Entry* entry;
369 int level = dir->level + 1;
370 WIN32_FIND_DATAW w32fd;
371 HANDLE hFind;
372 #ifndef _NO_EXTENSIONS
373 HANDLE hFile;
374 #endif
376 WCHAR buffer[MAX_PATH], *p;
377 for(p=buffer; *path; )
378 *p++ = *path++;
380 *p++ = '\\';
381 p[0] = '*';
382 p[1] = '\0';
384 hFind = FindFirstFileW(buffer, &w32fd);
386 if (hFind != INVALID_HANDLE_VALUE) {
387 do {
388 #ifdef _NO_EXTENSIONS
389 /* hide directory entry "." */
390 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
391 LPCWSTR name = w32fd.cFileName;
393 if (name[0]=='.' && name[1]=='\0')
394 continue;
396 #endif
397 entry = alloc_entry();
399 if (!first_entry)
400 first_entry = entry;
402 if (last)
403 last->next = entry;
405 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATAW));
406 entry->down = NULL;
407 entry->up = dir;
408 entry->expanded = FALSE;
409 entry->scanned = FALSE;
410 entry->level = level;
412 #ifndef _NO_EXTENSIONS
413 entry->etype = ET_WINDOWS;
414 entry->bhfi_valid = FALSE;
416 lstrcpyW(p, entry->data.cFileName);
418 hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
419 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
421 if (hFile != INVALID_HANDLE_VALUE) {
422 if (GetFileInformationByHandle(hFile, &entry->bhfi))
423 entry->bhfi_valid = TRUE;
425 CloseHandle(hFile);
427 #endif
429 last = entry;
430 } while(FindNextFileW(hFind, &w32fd));
432 if (last)
433 last->next = NULL;
435 FindClose(hFind);
438 dir->down = first_entry;
439 dir->scanned = TRUE;
443 static Entry* find_entry_win(Entry* dir, LPCWSTR name)
445 Entry* entry;
447 for(entry=dir->down; entry; entry=entry->next) {
448 LPCWSTR p = name;
449 LPCWSTR q = entry->data.cFileName;
451 do {
452 if (!*p || *p == '\\' || *p == '/')
453 return entry;
454 } while(tolower(*p++) == tolower(*q++));
456 p = name;
457 q = entry->data.cAlternateFileName;
459 do {
460 if (!*p || *p == '\\' || *p == '/')
461 return entry;
462 } while(tolower(*p++) == tolower(*q++));
465 return 0;
469 static Entry* read_tree_win(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
471 WCHAR buffer[MAX_PATH];
472 Entry* entry = &root->entry;
473 LPCWSTR s = path;
474 PWSTR d = buffer;
476 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
478 #ifndef _NO_EXTENSIONS
479 entry->etype = ET_WINDOWS;
480 #endif
482 while(entry) {
483 while(*s && *s != '\\' && *s != '/')
484 *d++ = *s++;
486 while(*s == '\\' || *s == '/')
487 s++;
489 *d++ = '\\';
490 *d = '\0';
492 read_directory(entry, buffer, sortOrder, hwnd);
494 if (entry->down)
495 entry->expanded = TRUE;
497 if (!*s)
498 break;
500 entry = find_entry_win(entry, s);
503 SetCursor(old_cursor);
505 return entry;
509 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
511 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
513 struct tm* tm = gmtime(t);
514 SYSTEMTIME stime;
516 if (!tm)
517 return FALSE;
519 stime.wYear = tm->tm_year+1900;
520 stime.wMonth = tm->tm_mon+1;
521 /* stime.wDayOfWeek */
522 stime.wDay = tm->tm_mday;
523 stime.wHour = tm->tm_hour;
524 stime.wMinute = tm->tm_min;
525 stime.wSecond = tm->tm_sec;
527 return SystemTimeToFileTime(&stime, ftime);
530 static void read_directory_unix(Entry* dir, LPCWSTR path)
532 Entry* first_entry = NULL;
533 Entry* last = NULL;
534 Entry* entry;
535 DIR* pdir;
537 int level = dir->level + 1;
538 char cpath[MAX_PATH];
540 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
541 pdir = opendir(cpath);
543 if (pdir) {
544 struct stat st;
545 struct dirent* ent;
546 char buffer[MAX_PATH], *p;
547 const char* s;
549 for(p=buffer,s=cpath; *s; )
550 *p++ = *s++;
552 if (p==buffer || p[-1]!='/')
553 *p++ = '/';
555 while((ent=readdir(pdir))) {
556 entry = alloc_entry();
558 if (!first_entry)
559 first_entry = entry;
561 if (last)
562 last->next = entry;
564 entry->etype = ET_UNIX;
566 strcpy(p, ent->d_name);
567 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
569 if (!stat(buffer, &st)) {
570 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
572 if (S_ISDIR(st.st_mode))
573 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
575 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
576 entry->data.nFileSizeHigh = st.st_size >> 32;
578 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
579 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
580 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
582 entry->bhfi.nFileIndexLow = ent->d_ino;
583 entry->bhfi.nFileIndexHigh = 0;
585 entry->bhfi.nNumberOfLinks = st.st_nlink;
587 entry->bhfi_valid = TRUE;
588 } else {
589 entry->data.nFileSizeLow = 0;
590 entry->data.nFileSizeHigh = 0;
591 entry->bhfi_valid = FALSE;
594 entry->down = NULL;
595 entry->up = dir;
596 entry->expanded = FALSE;
597 entry->scanned = FALSE;
598 entry->level = level;
600 last = entry;
603 if (last)
604 last->next = NULL;
606 closedir(pdir);
609 dir->down = first_entry;
610 dir->scanned = TRUE;
613 static Entry* find_entry_unix(Entry* dir, LPCWSTR name)
615 Entry* entry;
617 for(entry=dir->down; entry; entry=entry->next) {
618 LPCWSTR p = name;
619 LPCWSTR q = entry->data.cFileName;
621 do {
622 if (!*p || *p == '/')
623 return entry;
624 } while(*p++ == *q++);
627 return 0;
630 static Entry* read_tree_unix(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
632 WCHAR buffer[MAX_PATH];
633 Entry* entry = &root->entry;
634 LPCWSTR s = path;
635 PWSTR d = buffer;
637 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
639 entry->etype = ET_UNIX;
641 while(entry) {
642 while(*s && *s != '/')
643 *d++ = *s++;
645 while(*s == '/')
646 s++;
648 *d++ = '/';
649 *d = '\0';
651 read_directory(entry, buffer, sortOrder, hwnd);
653 if (entry->down)
654 entry->expanded = TRUE;
656 if (!*s)
657 break;
659 entry = find_entry_unix(entry, s);
662 SetCursor(old_cursor);
664 return entry;
667 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
670 #ifdef _SHELL_FOLDERS
672 static void free_strret(STRRET* str)
674 if (str->uType == STRRET_WSTR)
675 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
678 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
680 LPCWSTR s;
681 LPWSTR d = dest;
683 for(s=source; count&&(*d++=*s++); )
684 count--;
686 return dest;
689 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
691 switch(str->uType) {
692 case STRRET_WSTR:
693 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
694 break;
696 case STRRET_OFFSET:
697 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
698 break;
700 case STRRET_CSTR:
701 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
706 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len, SHGDNF flags)
708 STRRET str;
710 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
712 if (SUCCEEDED(hr)) {
713 get_strretW(&str, &pidl->mkid, buffer, len);
714 free_strret(&str);
715 } else
716 buffer[0] = '\0';
718 return hr;
722 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
724 STRRET str;
726 /* SHGDN_FORPARSING: get full path of id list */
727 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
729 if (SUCCEEDED(hr)) {
730 get_strretW(&str, &pidl->mkid, buffer, len);
731 free_strret(&str);
732 } else
733 buffer[0] = '\0';
735 return hr;
739 /* create an item id list from a file system path */
741 static LPITEMIDLIST get_path_pidl(LPWSTR path, HWND hwnd)
743 LPITEMIDLIST pidl;
744 HRESULT hr;
745 ULONG len;
746 LPWSTR buffer = path;
748 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
749 if (FAILED(hr))
750 return NULL;
752 return pidl;
756 /* convert an item id list from relative to absolute (=relative to the desktop) format */
758 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
760 if (entry->up && entry->up->etype==ET_SHELL) {
761 LPITEMIDLIST idl = NULL;
763 while (entry->up) {
764 idl = ILCombine(ILClone(entry->pidl), idl);
765 entry = entry->up;
768 return idl;
769 } else if (entry->etype == ET_WINDOWS) {
770 WCHAR path[MAX_PATH];
772 get_path(entry, path);
774 return get_path_pidl(path, hwnd);
775 } else if (entry->pidl)
776 return ILClone(entry->pidl);
778 return NULL;
782 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
784 IExtractIconW* pExtract;
786 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIconW, 0, (LPVOID*)&pExtract))) {
787 WCHAR path[_MAX_PATH];
788 unsigned flags;
789 HICON hicon;
790 int idx;
792 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
793 if (!(flags & GIL_NOTFILENAME)) {
794 if (idx == -1)
795 idx = 0; /* special case for some control panel applications */
797 if ((int)ExtractIconExW(path, idx, 0, &hicon, 1) > 0)
798 flags &= ~GIL_DONTCACHE;
799 } else {
800 HICON hIconLarge = 0;
802 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
804 if (SUCCEEDED(hr))
805 DestroyIcon(hIconLarge);
808 return hicon;
812 return 0;
816 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
818 Entry* entry;
820 for(entry=dir->down; entry; entry=entry->next) {
821 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
822 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
823 return entry;
826 return 0;
829 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
831 Entry* entry = &root->entry;
832 Entry* next;
833 LPITEMIDLIST next_pidl = pidl;
834 IShellFolder* folder;
835 IShellFolder* child = NULL;
836 HRESULT hr;
838 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
840 #ifndef _NO_EXTENSIONS
841 entry->etype = ET_SHELL;
842 #endif
844 folder = Globals.iDesktop;
846 while(entry) {
847 entry->pidl = next_pidl;
848 entry->folder = folder;
850 if (!pidl->mkid.cb)
851 break;
853 /* copy first element of item idlist */
854 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
855 memcpy(next_pidl, pidl, pidl->mkid.cb);
856 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
858 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
859 if (FAILED(hr))
860 break;
862 read_directory(entry, NULL, sortOrder, hwnd);
864 if (entry->down)
865 entry->expanded = TRUE;
867 next = find_entry_shell(entry, next_pidl);
868 if (!next)
869 break;
871 folder = child;
872 entry = next;
874 /* go to next element */
875 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
878 SetCursor(old_cursor);
880 return entry;
884 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATAW* w32fdata)
886 if (!(attribs & SFGAO_FILESYSTEM) ||
887 FAILED(SHGetDataFromIDListW(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATAW)))) {
888 WIN32_FILE_ATTRIBUTE_DATA fad;
889 IDataObject* pDataObj;
891 STGMEDIUM medium = {0, {0}, 0};
892 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
894 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
896 if (SUCCEEDED(hr)) {
897 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
899 IDataObject_Release(pDataObj);
901 if (SUCCEEDED(hr)) {
902 LPCWSTR path = GlobalLock(medium.UNION_MEMBER(hGlobal));
903 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
905 if (GetFileAttributesExW(path, GetFileExInfoStandard, &fad)) {
906 w32fdata->dwFileAttributes = fad.dwFileAttributes;
907 w32fdata->ftCreationTime = fad.ftCreationTime;
908 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
909 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
911 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
912 w32fdata->nFileSizeLow = fad.nFileSizeLow;
913 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
917 SetErrorMode(sem_org);
919 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
920 GlobalFree(medium.UNION_MEMBER(hGlobal));
925 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
926 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
928 if (attribs & SFGAO_READONLY)
929 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
931 if (attribs & SFGAO_COMPRESSED)
932 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
936 static void read_directory_shell(Entry* dir, HWND hwnd)
938 IShellFolder* folder = dir->folder;
939 int level = dir->level + 1;
940 HRESULT hr;
942 IShellFolder* child;
943 IEnumIDList* idlist;
945 Entry* first_entry = NULL;
946 Entry* last = NULL;
947 Entry* entry;
949 if (!folder)
950 return;
952 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
954 if (SUCCEEDED(hr)) {
955 for(;;) {
956 #define FETCH_ITEM_COUNT 32
957 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
958 SFGAOF attribs;
959 ULONG cnt = 0;
960 ULONG n;
962 memset(pidls, 0, sizeof(pidls));
964 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
965 if (FAILED(hr))
966 break;
968 if (hr == S_FALSE)
969 break;
971 for(n=0; n<cnt; ++n) {
972 entry = alloc_entry();
974 if (!first_entry)
975 first_entry = entry;
977 if (last)
978 last->next = entry;
980 memset(&entry->data, 0, sizeof(WIN32_FIND_DATAW));
981 entry->bhfi_valid = FALSE;
983 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
985 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
987 if (SUCCEEDED(hr)) {
988 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
989 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
991 entry->bhfi_valid = TRUE;
992 } else
993 attribs = 0;
994 } else
995 attribs = 0;
997 entry->pidl = pidls[n];
999 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1000 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1002 if (SUCCEEDED(hr))
1003 entry->folder = child;
1004 else
1005 entry->folder = NULL;
1007 else
1008 entry->folder = NULL;
1010 if (!entry->data.cFileName[0])
1011 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1013 /* get display icons for files and virtual objects */
1014 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1015 !(attribs & SFGAO_FILESYSTEM)) {
1016 entry->hicon = extract_icon(folder, pidls[n]);
1018 if (!entry->hicon)
1019 entry->hicon = (HICON)-1; /* don't try again later */
1022 entry->down = NULL;
1023 entry->up = dir;
1024 entry->expanded = FALSE;
1025 entry->scanned = FALSE;
1026 entry->level = level;
1028 #ifndef _NO_EXTENSIONS
1029 entry->etype = ET_SHELL;
1030 entry->bhfi_valid = FALSE;
1031 #endif
1033 last = entry;
1037 IEnumIDList_Release(idlist);
1040 if (last)
1041 last->next = NULL;
1043 dir->down = first_entry;
1044 dir->scanned = TRUE;
1047 #endif /* _SHELL_FOLDERS */
1050 /* sort order for different directory/file types */
1051 enum TYPE_ORDER {
1052 TO_DIR = 0,
1053 TO_DOT = 1,
1054 TO_DOTDOT = 2,
1055 TO_OTHER_DIR = 3,
1056 TO_FILE = 4
1059 /* distinguish between ".", ".." and any other directory names */
1060 static int TypeOrderFromDirname(LPCWSTR name)
1062 if (name[0] == '.') {
1063 if (name[1] == '\0')
1064 return TO_DOT; /* "." */
1066 if (name[1]=='.' && name[2]=='\0')
1067 return TO_DOTDOT; /* ".." */
1070 return TO_OTHER_DIR; /* anything else */
1073 /* directories first... */
1074 static int compareType(const WIN32_FIND_DATAW* fd1, const WIN32_FIND_DATAW* fd2)
1076 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1077 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1079 /* Handle "." and ".." as special case and move them at the very first beginning. */
1080 if (order1==TO_DIR && order2==TO_DIR) {
1081 order1 = TypeOrderFromDirname(fd1->cFileName);
1082 order2 = TypeOrderFromDirname(fd2->cFileName);
1085 return order2==order1? 0: order1<order2? -1: 1;
1089 static int compareName(const void* arg1, const void* arg2)
1091 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1092 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1094 int cmp = compareType(fd1, fd2);
1095 if (cmp)
1096 return cmp;
1098 return lstrcmpiW(fd1->cFileName, fd2->cFileName);
1101 static int compareExt(const void* arg1, const void* arg2)
1103 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1104 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1105 const WCHAR *name1, *name2, *ext1, *ext2;
1107 int cmp = compareType(fd1, fd2);
1108 if (cmp)
1109 return cmp;
1111 name1 = fd1->cFileName;
1112 name2 = fd2->cFileName;
1114 ext1 = strrchrW(name1, '.');
1115 ext2 = strrchrW(name2, '.');
1117 if (ext1)
1118 ext1++;
1119 else
1120 ext1 = sEmpty;
1122 if (ext2)
1123 ext2++;
1124 else
1125 ext2 = sEmpty;
1127 cmp = lstrcmpiW(ext1, ext2);
1128 if (cmp)
1129 return cmp;
1131 return lstrcmpiW(name1, name2);
1134 static int compareSize(const void* arg1, const void* arg2)
1136 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1137 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1139 int cmp = compareType(fd1, fd2);
1140 if (cmp)
1141 return cmp;
1143 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1145 if (cmp < 0)
1146 return -1;
1147 else if (cmp > 0)
1148 return 1;
1150 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1152 return cmp<0? -1: cmp>0? 1: 0;
1155 static int compareDate(const void* arg1, const void* arg2)
1157 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1158 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1160 int cmp = compareType(fd1, fd2);
1161 if (cmp)
1162 return cmp;
1164 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1168 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1169 compareName, /* SORT_NAME */
1170 compareExt, /* SORT_EXT */
1171 compareSize, /* SORT_SIZE */
1172 compareDate /* SORT_DATE */
1176 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1178 Entry* entry = dir->down;
1179 Entry** array, **p;
1180 int len;
1182 len = 0;
1183 for(entry=dir->down; entry; entry=entry->next)
1184 len++;
1186 if (len) {
1187 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1189 p = array;
1190 for(entry=dir->down; entry; entry=entry->next)
1191 *p++ = entry;
1193 /* call qsort with the appropriate compare function */
1194 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1196 dir->down = array[0];
1198 for(p=array; --len; p++)
1199 p[0]->next = p[1];
1201 (*p)->next = 0;
1203 HeapFree(GetProcessHeap(), 0, array);
1208 static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
1210 WCHAR buffer[MAX_PATH];
1211 Entry* entry;
1212 LPCWSTR s;
1213 PWSTR d;
1215 #ifdef _SHELL_FOLDERS
1216 if (dir->etype == ET_SHELL)
1218 read_directory_shell(dir, hwnd);
1220 if (Globals.prescan_node) {
1221 s = path;
1222 d = buffer;
1224 while(*s)
1225 *d++ = *s++;
1227 *d++ = '\\';
1229 for(entry=dir->down; entry; entry=entry->next)
1230 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1231 read_directory_shell(entry, hwnd);
1232 SortDirectory(entry, sortOrder);
1236 else
1237 #endif
1238 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1239 if (dir->etype == ET_UNIX)
1241 read_directory_unix(dir, path);
1243 if (Globals.prescan_node) {
1244 s = path;
1245 d = buffer;
1247 while(*s)
1248 *d++ = *s++;
1250 *d++ = '/';
1252 for(entry=dir->down; entry; entry=entry->next)
1253 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1254 lstrcpyW(d, entry->data.cFileName);
1255 read_directory_unix(entry, buffer);
1256 SortDirectory(entry, sortOrder);
1260 else
1261 #endif
1263 read_directory_win(dir, path);
1265 if (Globals.prescan_node) {
1266 s = path;
1267 d = buffer;
1269 while(*s)
1270 *d++ = *s++;
1272 *d++ = '\\';
1274 for(entry=dir->down; entry; entry=entry->next)
1275 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1276 lstrcpyW(d, entry->data.cFileName);
1277 read_directory_win(entry, buffer);
1278 SortDirectory(entry, sortOrder);
1283 SortDirectory(dir, sortOrder);
1287 static Entry* read_tree(Root* root, LPCWSTR path, LPITEMIDLIST pidl, LPWSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1289 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1290 static const WCHAR sSlash[] = {'/', '\0'};
1291 #endif
1292 static const WCHAR sBackslash[] = {'\\', '\0'};
1294 #ifdef _SHELL_FOLDERS
1295 if (pidl)
1297 /* read shell namespace tree */
1298 root->drive_type = DRIVE_UNKNOWN;
1299 drv[0] = '\\';
1300 drv[1] = '\0';
1301 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_DESKTOP);
1302 root->fs_flags = 0;
1303 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_SHELL);
1305 return read_tree_shell(root, pidl, sortOrder, hwnd);
1307 else
1308 #endif
1309 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1310 if (*path == '/')
1312 /* read unix file system tree */
1313 root->drive_type = GetDriveTypeW(path);
1315 lstrcatW(drv, sSlash);
1316 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_ROOT_FS);
1317 root->fs_flags = 0;
1318 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_UNIXFS);
1320 lstrcpyW(root->path, sSlash);
1322 return read_tree_unix(root, path, sortOrder, hwnd);
1324 #endif
1326 /* read WIN32 file system tree */
1327 root->drive_type = GetDriveTypeW(path);
1329 lstrcatW(drv, sBackslash);
1330 GetVolumeInformationW(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1332 lstrcpyW(root->path, drv);
1334 return read_tree_win(root, path, sortOrder, hwnd);
1338 /* flags to filter different file types */
1339 enum TYPE_FILTER {
1340 TF_DIRECTORIES = 0x01,
1341 TF_PROGRAMS = 0x02,
1342 TF_DOCUMENTS = 0x04,
1343 TF_OTHERS = 0x08,
1344 TF_HIDDEN = 0x10,
1345 TF_ALL = 0x1F
1349 static ChildWnd* alloc_child_window(LPCWSTR path, LPITEMIDLIST pidl, HWND hwnd)
1351 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1352 WCHAR dir_path[MAX_PATH];
1353 WCHAR b1[BUFFER_LEN];
1354 static const WCHAR sAsterics[] = {'*', '\0'};
1356 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1357 Root* root = &child->root;
1358 Entry* entry;
1360 memset(child, 0, sizeof(ChildWnd));
1362 child->left.treePane = TRUE;
1363 child->left.visible_cols = 0;
1365 child->right.treePane = FALSE;
1366 #ifndef _NO_EXTENSIONS
1367 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1368 #else
1369 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1370 #endif
1372 child->pos.length = sizeof(WINDOWPLACEMENT);
1373 child->pos.flags = 0;
1374 child->pos.showCmd = SW_SHOWNORMAL;
1375 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1376 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1377 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1378 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1380 child->focus_pane = 0;
1381 child->split_pos = DEFAULT_SPLIT_POS;
1382 child->sortOrder = SORT_NAME;
1383 child->header_wdths_ok = FALSE;
1385 if (path)
1387 lstrcpyW(child->path, path);
1389 _wsplitpath(path, drv, dir, name, ext);
1392 lstrcpyW(child->filter_pattern, sAsterics);
1393 child->filter_flags = TF_ALL;
1395 root->entry.level = 0;
1397 lstrcpyW(dir_path, drv);
1398 lstrcatW(dir_path, dir);
1399 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1401 #ifdef _SHELL_FOLDERS
1402 if (root->entry.etype == ET_SHELL)
1403 load_string(root->entry.data.cFileName, sizeof(root->entry.data.cFileName)/sizeof(root->entry.data.cFileName[0]), IDS_DESKTOP);
1404 else
1405 #endif
1406 wsprintfW(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs);
1408 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1410 child->left.root = &root->entry;
1411 child->right.root = NULL;
1413 set_curdir(child, entry, 0, hwnd);
1415 return child;
1419 /* free all memory associated with a child window */
1420 static void free_child_window(ChildWnd* child)
1422 free_entries(&child->root.entry);
1423 HeapFree(GetProcessHeap(), 0, child);
1427 /* get full path of specified directory entry */
1428 static void get_path(Entry* dir, PWSTR path)
1430 Entry* entry;
1431 int len = 0;
1432 int level = 0;
1434 #ifdef _SHELL_FOLDERS
1435 if (dir->etype == ET_SHELL)
1437 SFGAOF attribs;
1438 HRESULT hr = S_OK;
1440 path[0] = '\0';
1442 attribs = 0;
1444 if (dir->folder)
1445 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1447 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1448 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1450 hr = path_from_pidlW(parent, dir->pidl, path, MAX_PATH);
1453 else
1454 #endif
1456 for(entry=dir; entry; level++) {
1457 LPCWSTR name;
1458 int l;
1461 LPCWSTR s;
1462 name = entry->data.cFileName;
1463 s = name;
1465 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1466 l++;
1469 if (entry->up) {
1470 if (l > 0) {
1471 memmove(path+l+1, path, len*sizeof(WCHAR));
1472 memcpy(path+1, name, l*sizeof(WCHAR));
1473 len += l+1;
1475 #ifndef _NO_EXTENSIONS
1476 if (entry->etype == ET_UNIX)
1477 path[0] = '/';
1478 else
1479 #endif
1480 path[0] = '\\';
1483 entry = entry->up;
1484 } else {
1485 memmove(path+l, path, len*sizeof(WCHAR));
1486 memcpy(path, name, l*sizeof(WCHAR));
1487 len += l;
1488 break;
1492 if (!level) {
1493 #ifndef _NO_EXTENSIONS
1494 if (entry->etype == ET_UNIX)
1495 path[len++] = '/';
1496 else
1497 #endif
1498 path[len++] = '\\';
1501 path[len] = '\0';
1505 static windowOptions load_registry_settings(void)
1507 DWORD size;
1508 DWORD type;
1509 HKEY hKey;
1510 windowOptions opts;
1511 LOGFONTW logfont;
1513 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1514 0, KEY_QUERY_VALUE, &hKey );
1516 size = sizeof(DWORD);
1518 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1519 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1520 opts.start_x = CW_USEDEFAULT;
1522 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1523 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1524 opts.start_y = CW_USEDEFAULT;
1526 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1527 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1528 opts.width = CW_USEDEFAULT;
1530 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1531 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1532 opts.height = CW_USEDEFAULT;
1533 size=sizeof(logfont);
1534 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1535 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1536 GetObjectW(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1538 RegCloseKey( hKey );
1540 Globals.hfont = CreateFontIndirectW(&logfont);
1541 return opts;
1544 static void save_registry_settings(void)
1546 WINDOWINFO wi;
1547 HKEY hKey;
1548 INT width, height;
1549 LOGFONTW logfont;
1551 wi.cbSize = sizeof( WINDOWINFO );
1552 GetWindowInfo(Globals.hMainWnd, &wi);
1553 width = wi.rcWindow.right - wi.rcWindow.left;
1554 height = wi.rcWindow.bottom - wi.rcWindow.top;
1556 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1557 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1559 /* Unable to save registry settings - try to create key */
1560 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1561 0, NULL, REG_OPTION_NON_VOLATILE,
1562 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1564 /* FIXME: Cannot create key */
1565 return;
1568 /* Save all of the settings */
1569 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1570 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1571 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1572 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1573 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1574 (LPBYTE) &width, sizeof(DWORD) );
1575 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1576 (LPBYTE) &height, sizeof(DWORD) );
1577 GetObjectW(Globals.hfont, sizeof(logfont), &logfont);
1578 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1579 (LPBYTE)&logfont, sizeof(LOGFONTW) );
1581 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1582 RegCloseKey( hKey );
1585 static void resize_frame_rect(HWND hwnd, PRECT prect)
1587 int new_top;
1588 RECT rt;
1590 if (IsWindowVisible(Globals.htoolbar)) {
1591 SendMessageW(Globals.htoolbar, WM_SIZE, 0, 0);
1592 GetClientRect(Globals.htoolbar, &rt);
1593 prect->top = rt.bottom+3;
1594 prect->bottom -= rt.bottom+3;
1597 if (IsWindowVisible(Globals.hdrivebar)) {
1598 SendMessageW(Globals.hdrivebar, WM_SIZE, 0, 0);
1599 GetClientRect(Globals.hdrivebar, &rt);
1600 new_top = --prect->top + rt.bottom+3;
1601 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1602 prect->top = new_top;
1603 prect->bottom -= rt.bottom+2;
1606 if (IsWindowVisible(Globals.hstatusbar)) {
1607 int parts[] = {300, 500};
1609 SendMessageW(Globals.hstatusbar, WM_SIZE, 0, 0);
1610 SendMessageW(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1611 GetClientRect(Globals.hstatusbar, &rt);
1612 prect->bottom -= rt.bottom;
1615 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1618 static void resize_frame(HWND hwnd, int cx, int cy)
1620 RECT rect;
1622 rect.left = 0;
1623 rect.top = 0;
1624 rect.right = cx;
1625 rect.bottom = cy;
1627 resize_frame_rect(hwnd, &rect);
1630 static void resize_frame_client(HWND hwnd)
1632 RECT rect;
1634 GetClientRect(hwnd, &rect);
1636 resize_frame_rect(hwnd, &rect);
1640 static HHOOK hcbthook;
1641 static ChildWnd* newchild = NULL;
1643 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1645 if (code==HCBT_CREATEWND && newchild) {
1646 ChildWnd* child = newchild;
1647 newchild = NULL;
1649 child->hwnd = (HWND) wparam;
1650 SetWindowLongPtrW(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1653 return CallNextHookEx(hcbthook, code, wparam, lparam);
1656 static HWND create_child_window(ChildWnd* child)
1658 MDICREATESTRUCTW mcs;
1659 int idx;
1661 mcs.szClass = sWINEFILETREE;
1662 mcs.szTitle = child->path;
1663 mcs.hOwner = Globals.hInstance;
1664 mcs.x = child->pos.rcNormalPosition.left;
1665 mcs.y = child->pos.rcNormalPosition.top;
1666 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1667 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1668 mcs.style = 0;
1669 mcs.lParam = 0;
1671 hcbthook = SetWindowsHookExW(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1673 newchild = child;
1674 child->hwnd = (HWND)SendMessageW(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1675 if (!child->hwnd) {
1676 UnhookWindowsHookEx(hcbthook);
1677 return 0;
1680 UnhookWindowsHookEx(hcbthook);
1682 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1683 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1685 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1686 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
1688 return child->hwnd;
1691 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1693 static void WineFile_OnRun( HWND hwnd )
1695 static const WCHAR shell32_dll[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1696 void (WINAPI *pRunFileDlgAW )(HWND, HICON, LPWSTR, LPWSTR, LPWSTR, DWORD);
1697 HMODULE hshell = GetModuleHandleW( shell32_dll );
1699 pRunFileDlgAW = (void*)GetProcAddress(hshell, (LPCSTR)61);
1700 if (pRunFileDlgAW) pRunFileDlgAW( hwnd, 0, NULL, NULL, NULL, RFF_NODEFAULT);
1703 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1705 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1707 switch(nmsg) {
1708 case WM_INITDIALOG:
1709 SetWindowLongPtrW(hwnd, GWLP_USERDATA, lparam);
1710 SetWindowTextW(GetDlgItem(hwnd, 201), (LPCWSTR)lparam);
1711 return 1;
1713 case WM_COMMAND: {
1714 int id = (int)wparam;
1716 switch(id) {
1717 case IDOK: {
1718 LPWSTR dest = (LPWSTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
1719 GetWindowTextW(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1720 EndDialog(hwnd, id);
1721 break;}
1723 case IDCANCEL:
1724 EndDialog(hwnd, id);
1725 break;
1727 case 254:
1728 MessageBoxW(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1729 break;
1732 return 1;
1736 return 0;
1740 struct FilterDialog {
1741 WCHAR pattern[MAX_PATH];
1742 int flags;
1745 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1747 static struct FilterDialog* dlg;
1749 switch(nmsg) {
1750 case WM_INITDIALOG:
1751 dlg = (struct FilterDialog*) lparam;
1752 SetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1753 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1754 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1755 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1756 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1757 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1758 return 1;
1760 case WM_COMMAND: {
1761 int id = (int)wparam;
1763 if (id == IDOK) {
1764 int flags = 0;
1766 GetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1768 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1769 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1770 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1771 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1772 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1774 dlg->flags = flags;
1776 EndDialog(hwnd, id);
1777 } else if (id == IDCANCEL)
1778 EndDialog(hwnd, id);
1780 return 1;}
1783 return 0;
1787 struct PropertiesDialog {
1788 WCHAR path[MAX_PATH];
1789 Entry entry;
1790 void* pVersionData;
1793 /* Structure used to store enumerated languages and code pages. */
1794 struct LANGANDCODEPAGE {
1795 WORD wLanguage;
1796 WORD wCodePage;
1797 } *lpTranslate;
1799 static LPCSTR InfoStrings[] = {
1800 "Comments",
1801 "CompanyName",
1802 "FileDescription",
1803 "FileVersion",
1804 "InternalName",
1805 "LegalCopyright",
1806 "LegalTrademarks",
1807 "OriginalFilename",
1808 "PrivateBuild",
1809 "ProductName",
1810 "ProductVersion",
1811 "SpecialBuild",
1812 NULL
1815 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1817 int idx = SendMessageW(hlbox, LB_GETCURSEL, 0, 0);
1819 if (idx != LB_ERR) {
1820 LPCWSTR pValue = (LPCWSTR)SendMessageW(hlbox, LB_GETITEMDATA, idx, 0);
1822 if (pValue)
1823 SetWindowTextW(hedit, pValue);
1827 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCWSTR strFilename)
1829 static WCHAR sBackSlash[] = {'\\','\0'};
1830 static WCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
1831 static WCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1832 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1833 DWORD dwVersionDataLen = GetFileVersionInfoSizeW(strFilename, NULL);
1835 if (dwVersionDataLen) {
1836 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1838 if (GetFileVersionInfoW(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1839 LPVOID pVal;
1840 UINT nValLen;
1842 if (VerQueryValueW(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1843 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1844 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1845 char buffer[BUFFER_LEN];
1847 sprintf(buffer, "%d.%d.%d.%d",
1848 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1849 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1851 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1855 /* Read the list of languages and code pages. */
1856 if (VerQueryValueW(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1857 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1858 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1860 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1862 /* Read the file description for each language and code page. */
1863 for(; pTranslate<pEnd; ++pTranslate) {
1864 LPCSTR* p;
1866 for(p=InfoStrings; *p; ++p) {
1867 WCHAR subblock[200];
1868 WCHAR infoStr[100];
1869 LPCWSTR pTxt;
1870 UINT nValLen;
1872 LPCSTR pInfoString = *p;
1873 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1874 wsprintfW(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1876 /* Retrieve file description for language and code page */
1877 if (VerQueryValueW(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1878 int idx = SendMessageW(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
1879 SendMessageW(hlbox, LB_SETITEMDATA, idx, (LPARAM)pTxt);
1884 SendMessageW(hlbox, LB_SETCURSEL, 0, 0);
1886 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1892 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1894 static struct PropertiesDialog* dlg;
1896 switch(nmsg) {
1897 case WM_INITDIALOG: {
1898 static const WCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1899 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1900 LPWIN32_FIND_DATAW pWFD;
1902 dlg = (struct PropertiesDialog*) lparam;
1903 pWFD = (LPWIN32_FIND_DATAW)&dlg->entry.data;
1905 GetWindowTextW(hwnd, b1, MAX_PATH);
1906 wsprintfW(b2, b1, pWFD->cFileName);
1907 SetWindowTextW(hwnd, b2);
1909 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1910 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1912 format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
1913 wsprintfW(b2, sByteFmt, b1);
1914 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1916 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1917 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1919 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
1920 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
1921 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
1922 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
1923 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
1925 CheckForFileInfo(dlg, hwnd, dlg->path);
1926 return 1;}
1928 case WM_COMMAND: {
1929 int id = (int)wparam;
1931 switch(HIWORD(wparam)) {
1932 case LBN_SELCHANGE: {
1933 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1934 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1935 break;
1938 case BN_CLICKED:
1939 if (id==IDOK || id==IDCANCEL)
1940 EndDialog(hwnd, id);
1943 return 1;}
1945 case WM_NCDESTROY:
1946 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
1947 dlg->pVersionData = NULL;
1948 break;
1951 return 0;
1954 static void show_properties_dlg(Entry* entry, HWND hwnd)
1956 struct PropertiesDialog dlg;
1958 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1959 get_path(entry, dlg.path);
1960 memcpy(&dlg.entry, entry, sizeof(Entry));
1962 DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1966 #ifndef _NO_EXTENSIONS
1968 static struct FullScreenParameters {
1969 BOOL mode;
1970 RECT orgPos;
1971 BOOL wasZoomed;
1972 } g_fullscreen = {
1973 FALSE, /* mode */
1974 {0, 0, 0, 0},
1975 FALSE
1978 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1980 RECT rt;
1982 if (!IsIconic(hwnd))
1983 GetClientRect(hwnd, prect);
1984 else {
1985 WINDOWPLACEMENT wp;
1987 GetWindowPlacement(hwnd, &wp);
1989 prect->left = prect->top = 0;
1990 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1991 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1992 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1993 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1994 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1997 if (IsWindowVisible(Globals.htoolbar)) {
1998 GetClientRect(Globals.htoolbar, &rt);
1999 prect->top += rt.bottom+2;
2002 if (IsWindowVisible(Globals.hdrivebar)) {
2003 GetClientRect(Globals.hdrivebar, &rt);
2004 prect->top += rt.bottom+2;
2007 if (IsWindowVisible(Globals.hstatusbar)) {
2008 GetClientRect(Globals.hstatusbar, &rt);
2009 prect->bottom -= rt.bottom;
2013 static BOOL toggle_fullscreen(HWND hwnd)
2015 RECT rt;
2017 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2018 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2019 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2021 Frame_CalcFrameClient(hwnd, &rt);
2022 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2023 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2025 rt.left = g_fullscreen.orgPos.left-rt.left;
2026 rt.top = g_fullscreen.orgPos.top-rt.top;
2027 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2028 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2030 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2031 } else {
2032 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2033 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2034 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2036 if (g_fullscreen.wasZoomed)
2037 ShowWindow(hwnd, WS_MAXIMIZE);
2040 return g_fullscreen.mode;
2043 static void fullscreen_move(HWND hwnd)
2045 RECT rt, pos;
2046 GetWindowRect(hwnd, &pos);
2048 Frame_CalcFrameClient(hwnd, &rt);
2049 ClientToScreen(hwnd, (LPPOINT)&rt.left);
2050 ClientToScreen(hwnd, (LPPOINT)&rt.right);
2052 rt.left = pos.left-rt.left;
2053 rt.top = pos.top-rt.top;
2054 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2055 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2057 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2060 #endif
2063 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2065 BOOL vis = IsWindowVisible(hchild);
2067 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2069 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2071 #ifndef _NO_EXTENSIONS
2072 if (g_fullscreen.mode)
2073 fullscreen_move(hwnd);
2074 #endif
2076 resize_frame_client(hwnd);
2079 static BOOL activate_drive_window(LPCWSTR path)
2081 WCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2082 HWND child_wnd;
2084 _wsplitpath(path, drv1, 0, 0, 0);
2086 /* search for a already open window for the same drive */
2087 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2088 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
2090 if (child) {
2091 _wsplitpath(child->root.path, drv2, 0, 0, 0);
2093 if (!lstrcmpiW(drv2, drv1)) {
2094 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2096 if (IsIconic(child_wnd))
2097 ShowWindow(child_wnd, SW_SHOWNORMAL);
2099 return TRUE;
2104 return FALSE;
2107 static BOOL activate_fs_window(LPCWSTR filesys)
2109 HWND child_wnd;
2111 /* search for a already open window of the given file system name */
2112 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2113 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
2115 if (child) {
2116 if (!lstrcmpiW(child->root.fs, filesys)) {
2117 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2119 if (IsIconic(child_wnd))
2120 ShowWindow(child_wnd, SW_SHOWNORMAL);
2122 return TRUE;
2127 return FALSE;
2130 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2132 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2134 switch(nmsg) {
2135 case WM_CLOSE:
2136 if (Globals.saveSettings)
2137 save_registry_settings();
2139 DestroyWindow(hwnd);
2141 /* clear handle variables */
2142 Globals.hMenuFrame = 0;
2143 Globals.hMenuView = 0;
2144 Globals.hMenuOptions = 0;
2145 Globals.hMainWnd = 0;
2146 Globals.hmdiclient = 0;
2147 Globals.hdrivebar = 0;
2148 break;
2150 case WM_DESTROY:
2151 PostQuitMessage(0);
2152 break;
2154 case WM_INITMENUPOPUP: {
2155 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2157 if (!SendMessageW(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2158 return 0;
2159 break;}
2161 case WM_COMMAND: {
2162 UINT cmd = LOWORD(wparam);
2163 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2165 if (SendMessageW(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2166 break;
2168 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2169 WCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2170 ChildWnd* child;
2171 LPCWSTR root = Globals.drives;
2172 int i;
2174 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2175 while(*root)
2176 root++;
2178 if (activate_drive_window(root))
2179 return 0;
2181 _wsplitpath(root, drv, 0, 0, 0);
2183 if (!SetCurrentDirectoryW(drv)) {
2184 display_error(hwnd, GetLastError());
2185 return 0;
2188 GetCurrentDirectoryW(MAX_PATH, path); /*TODO: store last directory per drive */
2189 child = alloc_child_window(path, NULL, hwnd);
2191 if (!create_child_window(child))
2192 HeapFree(GetProcessHeap(), 0, child);
2193 } else switch(cmd) {
2194 case ID_FILE_EXIT:
2195 SendMessageW(hwnd, WM_CLOSE, 0, 0);
2196 break;
2198 case ID_WINDOW_NEW: {
2199 WCHAR path[MAX_PATH];
2200 ChildWnd* child;
2202 GetCurrentDirectoryW(MAX_PATH, path);
2203 child = alloc_child_window(path, NULL, hwnd);
2205 if (!create_child_window(child))
2206 HeapFree(GetProcessHeap(), 0, child);
2207 break;}
2209 case ID_REFRESH:
2210 refresh_drives();
2211 break;
2213 case ID_WINDOW_CASCADE:
2214 SendMessageW(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2215 break;
2217 case ID_WINDOW_TILE_HORZ:
2218 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2219 break;
2221 case ID_WINDOW_TILE_VERT:
2222 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2223 break;
2225 case ID_WINDOW_ARRANGE:
2226 SendMessageW(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2227 break;
2229 case ID_SELECT_FONT:
2230 choose_font(hwnd);
2231 break;
2233 case ID_VIEW_TOOL_BAR:
2234 toggle_child(hwnd, cmd, Globals.htoolbar);
2235 break;
2237 case ID_VIEW_DRIVE_BAR:
2238 toggle_child(hwnd, cmd, Globals.hdrivebar);
2239 break;
2241 case ID_VIEW_STATUSBAR:
2242 toggle_child(hwnd, cmd, Globals.hstatusbar);
2243 break;
2245 case ID_VIEW_SAVESETTINGS:
2246 Globals.saveSettings = !Globals.saveSettings;
2247 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2248 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2249 break;
2251 case ID_RUN:
2252 WineFile_OnRun( hwnd );
2253 break;
2255 case ID_CONNECT_NETWORK_DRIVE: {
2256 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2257 if (ret == NO_ERROR)
2258 refresh_drives();
2259 else if (ret != (DWORD)-1) {
2260 if (ret == ERROR_EXTENDED_ERROR)
2261 display_network_error(hwnd);
2262 else
2263 display_error(hwnd, ret);
2265 break;}
2267 case ID_DISCONNECT_NETWORK_DRIVE: {
2268 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2269 if (ret == NO_ERROR)
2270 refresh_drives();
2271 else if (ret != (DWORD)-1) {
2272 if (ret == ERROR_EXTENDED_ERROR)
2273 display_network_error(hwnd);
2274 else
2275 display_error(hwnd, ret);
2277 break;}
2279 case ID_FORMAT_DISK: {
2280 UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */
2281 SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */
2282 SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
2283 SetErrorMode(sem_org); /* Put it back the way it was. */
2284 break;}
2286 case ID_HELP:
2287 WinHelpW(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2288 break;
2290 #ifndef _NO_EXTENSIONS
2291 case ID_VIEW_FULLSCREEN:
2292 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2293 break;
2295 #ifdef __WINE__
2296 case ID_DRIVE_UNIX_FS: {
2297 WCHAR path[MAX_PATH];
2298 char cpath[MAX_PATH];
2299 ChildWnd* child;
2301 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2302 break;
2304 getcwd(cpath, MAX_PATH);
2305 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2306 child = alloc_child_window(path, NULL, hwnd);
2308 if (!create_child_window(child))
2309 HeapFree(GetProcessHeap(), 0, child);
2310 break;}
2311 #endif
2312 #ifdef _SHELL_FOLDERS
2313 case ID_DRIVE_SHELL_NS: {
2314 WCHAR path[MAX_PATH];
2315 ChildWnd* child;
2317 if (activate_fs_window(RS(b1,IDS_SHELL)))
2318 break;
2320 GetCurrentDirectoryW(MAX_PATH, path);
2321 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2323 if (!create_child_window(child))
2324 HeapFree(GetProcessHeap(), 0, child);
2325 break;}
2326 #endif
2327 #endif
2329 /*TODO: There are even more menu items! */
2331 case ID_ABOUT:
2332 ShellAboutW(hwnd, RS(b1,IDS_WINEFILE), NULL,
2333 LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE),
2334 IMAGE_ICON, 48, 48, LR_SHARED ));
2335 break;
2337 default:
2338 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2339 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2340 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2341 (cmd<SC_SIZE || cmd>SC_RESTORE))
2342 MessageBoxW(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2344 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2346 break;}
2348 case WM_SIZE:
2349 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2350 break; /* do not pass message to DefFrameProcW */
2352 case WM_DEVICECHANGE:
2353 SendMessageW(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2354 break;
2356 #ifndef _NO_EXTENSIONS
2357 case WM_GETMINMAXINFO: {
2358 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2360 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2361 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2362 break;}
2364 case FRM_CALC_CLIENT:
2365 frame_get_clientspace(hwnd, (PRECT)lparam);
2366 return TRUE;
2367 #endif /* _NO_EXTENSIONS */
2369 default:
2370 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2373 return 0;
2377 static WCHAR g_pos_names[COLUMNS][20] = {
2378 {'\0'} /* symbol */
2381 static const int g_pos_align[] = {
2383 HDF_LEFT, /* Name */
2384 HDF_RIGHT, /* Size */
2385 HDF_LEFT, /* CDate */
2386 #ifndef _NO_EXTENSIONS
2387 HDF_LEFT, /* ADate */
2388 HDF_LEFT, /* MDate */
2389 HDF_LEFT, /* Index */
2390 HDF_CENTER, /* Links */
2391 #endif
2392 HDF_CENTER, /* Attributes */
2393 #ifndef _NO_EXTENSIONS
2394 HDF_LEFT /* Security */
2395 #endif
2398 static void resize_tree(ChildWnd* child, int cx, int cy)
2400 HDWP hdwp = BeginDeferWindowPos(4);
2401 RECT rt;
2403 rt.left = 0;
2404 rt.top = 0;
2405 rt.right = cx;
2406 rt.bottom = cy;
2408 cx = child->split_pos + SPLIT_WIDTH/2;
2410 #ifndef _NO_EXTENSIONS
2412 WINDOWPOS wp;
2413 HD_LAYOUT hdl;
2415 hdl.prc = &rt;
2416 hdl.pwpos = &wp;
2418 SendMessageW(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2420 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2421 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2422 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2423 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2425 #endif /* _NO_EXTENSIONS */
2427 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);
2428 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2430 EndDeferWindowPos(hdwp);
2434 #ifndef _NO_EXTENSIONS
2436 static HWND create_header(HWND parent, Pane* pane, UINT id)
2438 HDITEMW hdi;
2439 int idx;
2441 HWND hwnd = CreateWindowW(WC_HEADERW, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2442 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2443 if (!hwnd)
2444 return 0;
2446 SendMessageW(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2448 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2450 for(idx=0; idx<COLUMNS; idx++) {
2451 hdi.pszText = g_pos_names[idx];
2452 hdi.fmt = HDF_STRING | g_pos_align[idx];
2453 hdi.cxy = pane->widths[idx];
2454 SendMessageW(hwnd, HDM_INSERTITEMW, idx, (LPARAM)&hdi);
2457 return hwnd;
2460 #endif /* _NO_EXTENSIONS */
2463 static void init_output(HWND hwnd)
2465 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2466 WCHAR b[16];
2467 HFONT old_font;
2468 HDC hdc = GetDC(hwnd);
2470 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2471 Globals.num_sep = b[1];
2472 else
2473 Globals.num_sep = '.';
2475 old_font = SelectObject(hdc, Globals.hfont);
2476 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2477 SelectObject(hdc, old_font);
2478 ReleaseDC(hwnd, hdc);
2481 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2484 /* calculate preferred width for all visible columns */
2486 static BOOL calc_widths(Pane* pane, BOOL anyway)
2488 int col, x, cx, spc=3*Globals.spaceSize.cx;
2489 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2490 int orgWidths[COLUMNS];
2491 int orgPositions[COLUMNS+1];
2492 HFONT hfontOld;
2493 HDC hdc;
2494 int cnt;
2496 if (!anyway) {
2497 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2498 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2501 for(col=0; col<COLUMNS; col++)
2502 pane->widths[col] = 0;
2504 hdc = GetDC(pane->hwnd);
2505 hfontOld = SelectObject(hdc, Globals.hfont);
2507 for(cnt=0; cnt<entries; cnt++) {
2508 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2510 DRAWITEMSTRUCT dis;
2512 dis.CtlType = 0;
2513 dis.CtlID = 0;
2514 dis.itemID = 0;
2515 dis.itemAction = 0;
2516 dis.itemState = 0;
2517 dis.hwndItem = pane->hwnd;
2518 dis.hDC = hdc;
2519 dis.rcItem.left = 0;
2520 dis.rcItem.top = 0;
2521 dis.rcItem.right = 0;
2522 dis.rcItem.bottom = 0;
2523 /*dis.itemData = 0; */
2525 draw_item(pane, &dis, entry, COLUMNS);
2528 SelectObject(hdc, hfontOld);
2529 ReleaseDC(pane->hwnd, hdc);
2531 x = 0;
2532 for(col=0; col<COLUMNS; col++) {
2533 pane->positions[col] = x;
2534 cx = pane->widths[col];
2536 if (cx) {
2537 cx += spc;
2539 if (cx < IMAGE_WIDTH)
2540 cx = IMAGE_WIDTH;
2542 pane->widths[col] = cx;
2545 x += cx;
2548 pane->positions[COLUMNS] = x;
2550 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2552 /* no change? */
2553 if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2554 return FALSE;
2556 /* don't move, if only collapsing an entry */
2557 if (!anyway && pane->widths[0]<orgWidths[0] &&
2558 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2559 pane->widths[0] = orgWidths[0];
2560 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2562 return FALSE;
2565 InvalidateRect(pane->hwnd, 0, TRUE);
2567 return TRUE;
2571 /* calculate one preferred column width */
2573 static void calc_single_width(Pane* pane, int col)
2575 HFONT hfontOld;
2576 int x, cx;
2577 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2578 int cnt;
2579 HDC hdc;
2581 pane->widths[col] = 0;
2583 hdc = GetDC(pane->hwnd);
2584 hfontOld = SelectObject(hdc, Globals.hfont);
2586 for(cnt=0; cnt<entries; cnt++) {
2587 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2588 DRAWITEMSTRUCT dis;
2590 dis.CtlType = 0;
2591 dis.CtlID = 0;
2592 dis.itemID = 0;
2593 dis.itemAction = 0;
2594 dis.itemState = 0;
2595 dis.hwndItem = pane->hwnd;
2596 dis.hDC = hdc;
2597 dis.rcItem.left = 0;
2598 dis.rcItem.top = 0;
2599 dis.rcItem.right = 0;
2600 dis.rcItem.bottom = 0;
2601 /*dis.itemData = 0; */
2603 draw_item(pane, &dis, entry, col);
2606 SelectObject(hdc, hfontOld);
2607 ReleaseDC(pane->hwnd, hdc);
2609 cx = pane->widths[col];
2611 if (cx) {
2612 cx += 3*Globals.spaceSize.cx;
2614 if (cx < IMAGE_WIDTH)
2615 cx = IMAGE_WIDTH;
2618 pane->widths[col] = cx;
2620 x = pane->positions[col] + cx;
2622 for(; col<COLUMNS-1; ) {
2623 pane->positions[++col] = x;
2624 x += pane->widths[col];
2627 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2631 static BOOL pattern_match(LPCWSTR str, LPCWSTR pattern)
2633 for( ; *str&&*pattern; str++,pattern++) {
2634 if (*pattern == '*') {
2635 do pattern++;
2636 while(*pattern == '*');
2638 if (!*pattern)
2639 return TRUE;
2641 for(; *str; str++)
2642 if (*str==*pattern && pattern_match(str, pattern))
2643 return TRUE;
2645 return FALSE;
2647 else if (*str!=*pattern && *pattern!='?')
2648 return FALSE;
2651 if (*str || *pattern)
2652 if (*pattern!='*' || pattern[1]!='\0')
2653 return FALSE;
2655 return TRUE;
2658 static BOOL pattern_imatch(LPCWSTR str, LPCWSTR pattern)
2660 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2662 lstrcpyW(b1, str);
2663 lstrcpyW(b2, pattern);
2664 CharUpperW(b1);
2665 CharUpperW(b2);
2667 return pattern_match(b1, b2);
2671 enum FILE_TYPE {
2672 FT_OTHER = 0,
2673 FT_EXECUTABLE = 1,
2674 FT_DOCUMENT = 2
2677 static enum FILE_TYPE get_file_type(LPCWSTR filename);
2680 /* insert listbox entries after index idx */
2682 static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_flags, int idx)
2684 Entry* entry = dir;
2686 if (!entry)
2687 return idx;
2689 ShowWindow(pane->hwnd, SW_HIDE);
2691 for(; entry; entry=entry->next) {
2692 #ifndef _LEFT_FILES
2693 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2694 continue;
2695 #endif
2697 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2698 /* don't display entries "." and ".." in the left pane */
2699 if (pane->treePane && entry->data.cFileName[0] == '.')
2700 if (
2701 #ifndef _NO_EXTENSIONS
2702 entry->data.cFileName[1] == '\0' ||
2703 #endif
2704 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2705 continue;
2707 /* filter directories in right pane */
2708 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2709 continue;
2712 /* filter using the file name pattern */
2713 if (pattern)
2714 if (!pattern_imatch(entry->data.cFileName, pattern))
2715 continue;
2717 /* filter system and hidden files */
2718 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2719 continue;
2721 /* filter looking at the file type */
2722 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2723 switch(get_file_type(entry->data.cFileName)) {
2724 case FT_EXECUTABLE:
2725 if (!(filter_flags & TF_PROGRAMS))
2726 continue;
2727 break;
2729 case FT_DOCUMENT:
2730 if (!(filter_flags & TF_DOCUMENTS))
2731 continue;
2732 break;
2734 default: /* TF_OTHERS */
2735 if (!(filter_flags & TF_OTHERS))
2736 continue;
2739 if (idx != -1)
2740 idx++;
2742 SendMessageW(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM)entry);
2744 if (pane->treePane && entry->expanded)
2745 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2748 ShowWindow(pane->hwnd, SW_SHOW);
2750 return idx;
2754 static void format_bytes(LPWSTR buffer, LONGLONG bytes)
2756 static const WCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'};
2757 static const WCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'};
2758 static const WCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'};
2759 static const WCHAR sFmtB[] = {'%', 'u', 0};
2761 float fBytes = (float)bytes;
2763 if (bytes >= 1073741824) /* 1 GB */
2764 sprintfW(buffer, sFmtGB, fBytes/1073741824.f+.5f);
2765 else if (bytes >= 1048576) /* 1 MB */
2766 sprintfW(buffer, sFmtMB, fBytes/1048576.f+.5f);
2767 else if (bytes >= 1024) /* 1 kB */
2768 sprintfW(buffer, sFmtkB, fBytes/1024.f+.5f);
2769 else
2770 sprintfW(buffer, sFmtB, (DWORD)bytes);
2773 static void set_space_status(void)
2775 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2776 WCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2778 if (GetDiskFreeSpaceExW(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2779 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2780 format_bytes(b2, ulTotalBytes.QuadPart);
2781 wsprintfW(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2);
2782 } else
2783 lstrcpyW(buffer, sQMarks);
2785 SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
2789 static WNDPROC g_orgTreeWndProc;
2791 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
2793 static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2795 static int s_init = 0;
2796 Entry* entry = pane->root;
2798 pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2799 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2800 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2802 SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2803 g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2805 SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2807 /* insert entries into listbox */
2808 if (entry)
2809 insert_entries(pane, entry, pattern, filter_flags, -1);
2811 /* calculate column widths */
2812 if (!s_init) {
2813 s_init = 1;
2814 init_output(pane->hwnd);
2817 calc_widths(pane, TRUE);
2819 #ifndef _NO_EXTENSIONS
2820 pane->hwndHeader = create_header(parent, pane, id_header);
2821 #endif
2825 static void InitChildWindow(ChildWnd* child)
2827 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2828 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2832 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
2834 SYSTEMTIME systime;
2835 FILETIME lft;
2836 int len = 0;
2838 *buffer = '\0';
2840 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2841 return;
2843 if (!FileTimeToLocalFileTime(ft, &lft))
2844 {err: lstrcpyW(buffer,sQMarks); return;}
2846 if (!FileTimeToSystemTime(&lft, &systime))
2847 goto err;
2849 if (visible_cols & COL_DATE) {
2850 len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2851 if (!len)
2852 goto err;
2855 if (visible_cols & COL_TIME) {
2856 if (len)
2857 buffer[len-1] = ' ';
2859 buffer[len++] = ' ';
2861 if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2862 buffer[len] = '\0';
2867 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2869 RECT rt = {0, 0, 0, 0};
2871 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2873 if (rt.right > pane->widths[col])
2874 pane->widths[col] = rt.right;
2877 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2879 RECT rt = {0, 0, 0, 0};
2881 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2882 DrawTextExW(dis->hDC, (LPWSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2884 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2885 /*FIXME rt (0,0) ??? */
2887 if (rt.right > pane->widths[col])
2888 pane->widths[col] = rt.right;
2892 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
2894 int x = dis->rcItem.left;
2895 RECT rt;
2897 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2898 rt.top = dis->rcItem.top;
2899 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2900 rt.bottom = dis->rcItem.bottom;
2902 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2905 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2907 int x = dis->rcItem.left;
2908 RECT rt;
2910 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2911 rt.top = dis->rcItem.top;
2912 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2913 rt.bottom = dis->rcItem.bottom;
2915 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
2916 DrawTextExW(dis->hDC, (LPWSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
2918 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2921 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2923 int x = dis->rcItem.left;
2924 RECT rt;
2925 LPCWSTR s = str;
2926 WCHAR b[128];
2927 LPWSTR d = b;
2928 int pos;
2930 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2931 rt.top = dis->rcItem.top;
2932 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2933 rt.bottom = dis->rcItem.bottom;
2935 if (*s)
2936 *d++ = *s++;
2938 /* insert number separator characters */
2939 pos = lstrlenW(s) % 3;
2941 while(*s)
2942 if (pos--)
2943 *d++ = *s++;
2944 else {
2945 *d++ = Globals.num_sep;
2946 pos = 3;
2949 DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2953 static BOOL is_exe_file(LPCWSTR ext)
2955 static const WCHAR executable_extensions[][4] = {
2956 {'C','O','M','\0'},
2957 {'E','X','E','\0'},
2958 {'B','A','T','\0'},
2959 {'C','M','D','\0'},
2960 #ifndef _NO_EXTENSIONS
2961 {'C','M','M','\0'},
2962 {'B','T','M','\0'},
2963 {'A','W','K','\0'},
2964 #endif /* _NO_EXTENSIONS */
2965 {'\0'}
2968 WCHAR ext_buffer[_MAX_EXT];
2969 const WCHAR (*p)[4];
2970 LPCWSTR s;
2971 LPWSTR d;
2973 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2974 d++;
2976 for(p=executable_extensions; (*p)[0]; p++)
2977 if (!lstrcmpiW(ext_buffer, *p))
2978 return TRUE;
2980 return FALSE;
2983 static BOOL is_registered_type(LPCWSTR ext)
2985 /* check if there exists a classname for this file extension in the registry */
2986 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2987 return TRUE;
2989 return FALSE;
2992 static enum FILE_TYPE get_file_type(LPCWSTR filename)
2994 LPCWSTR ext = strrchrW(filename, '.');
2995 if (!ext)
2996 ext = sEmpty;
2998 if (is_exe_file(ext))
2999 return FT_EXECUTABLE;
3000 else if (is_registered_type(ext))
3001 return FT_DOCUMENT;
3002 else
3003 return FT_OTHER;
3007 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3009 WCHAR buffer[BUFFER_LEN];
3010 DWORD attrs;
3011 int visible_cols = pane->visible_cols;
3012 COLORREF bkcolor, textcolor;
3013 RECT focusRect = dis->rcItem;
3014 HBRUSH hbrush;
3015 enum IMAGE img;
3016 int img_pos, cx;
3017 int col = 0;
3019 if (entry) {
3020 attrs = entry->data.dwFileAttributes;
3022 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3023 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3024 && entry->data.cFileName[2] == '\0')
3025 img = IMG_FOLDER_UP;
3026 #ifndef _NO_EXTENSIONS
3027 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3028 img = IMG_FOLDER_CUR;
3029 #endif
3030 else if (
3031 #ifdef _NO_EXTENSIONS
3032 entry->expanded ||
3033 #endif
3034 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3035 img = IMG_OPEN_FOLDER;
3036 else
3037 img = IMG_FOLDER;
3038 } else {
3039 switch(get_file_type(entry->data.cFileName)) {
3040 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3041 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3042 default: img = IMG_FILE;
3045 } else {
3046 attrs = 0;
3047 img = IMG_NONE;
3050 if (pane->treePane) {
3051 if (entry) {
3052 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3054 if (calcWidthCol == -1) {
3055 int x;
3056 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3057 Entry* up;
3058 RECT rt_clip;
3059 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3060 HRGN hrgn;
3062 rt_clip.left = dis->rcItem.left;
3063 rt_clip.top = dis->rcItem.top;
3064 rt_clip.right = dis->rcItem.left+pane->widths[col];
3065 rt_clip.bottom = dis->rcItem.bottom;
3067 hrgn = CreateRectRgnIndirect(&rt_clip);
3069 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3070 DeleteObject(hrgn_org);
3071 hrgn_org = 0;
3074 /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */
3075 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3076 DeleteObject(hrgn);
3078 if ((up=entry->up) != NULL) {
3079 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3080 LineTo(dis->hDC, img_pos-2, y);
3082 x = img_pos - IMAGE_WIDTH/2;
3084 do {
3085 x -= IMAGE_WIDTH+TREE_LINE_DX;
3087 if (up->next
3088 #ifndef _LEFT_FILES
3089 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3090 #endif
3092 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3093 LineTo(dis->hDC, x, dis->rcItem.bottom);
3095 } while((up=up->up) != NULL);
3098 x = img_pos - IMAGE_WIDTH/2;
3100 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3101 LineTo(dis->hDC, x, y);
3103 if (entry->next
3104 #ifndef _LEFT_FILES
3105 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3106 #endif
3108 LineTo(dis->hDC, x, dis->rcItem.bottom);
3110 SelectClipRgn(dis->hDC, hrgn_org);
3111 if (hrgn_org) DeleteObject(hrgn_org);
3112 /* SelectObject(dis->hDC, holdPen); */
3113 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3114 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3116 if (right > pane->widths[col])
3117 pane->widths[col] = right;
3119 } else {
3120 img_pos = dis->rcItem.left;
3122 } else {
3123 img_pos = dis->rcItem.left;
3125 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3126 pane->widths[col] = IMAGE_WIDTH;
3129 if (calcWidthCol == -1) {
3130 focusRect.left = img_pos -2;
3132 #ifdef _NO_EXTENSIONS
3133 if (pane->treePane && entry) {
3134 RECT rt = {0};
3136 DrawTextW(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3138 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3140 #else
3142 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3143 textcolor = COLOR_COMPRESSED;
3144 else
3145 #endif /* _NO_EXTENSIONS */
3146 textcolor = RGB(0,0,0);
3148 if (dis->itemState & ODS_FOCUS) {
3149 textcolor = RGB(255,255,255);
3150 bkcolor = COLOR_SELECTION;
3151 } else {
3152 bkcolor = RGB(255,255,255);
3155 hbrush = CreateSolidBrush(bkcolor);
3156 FillRect(dis->hDC, &focusRect, hbrush);
3157 DeleteObject(hbrush);
3159 SetBkMode(dis->hDC, TRANSPARENT);
3160 SetTextColor(dis->hDC, textcolor);
3162 cx = pane->widths[col];
3164 if (cx && img!=IMG_NONE) {
3165 if (cx > IMAGE_WIDTH)
3166 cx = IMAGE_WIDTH;
3168 #ifdef _SHELL_FOLDERS
3169 if (entry->hicon && entry->hicon!=(HICON)-1)
3170 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3171 else
3172 #endif
3173 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3174 img_pos, dis->rcItem.top, cx,
3175 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3179 if (!entry)
3180 return;
3182 #ifdef _NO_EXTENSIONS
3183 if (img >= IMG_FOLDER_UP)
3184 return;
3185 #endif
3187 col++;
3189 /* ouput file name */
3190 if (calcWidthCol == -1)
3191 output_text(pane, dis, col, entry->data.cFileName, 0);
3192 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3193 calc_width(pane, dis, col, entry->data.cFileName);
3195 col++;
3197 #ifdef _NO_EXTENSIONS
3198 if (!pane->treePane) {
3199 #endif
3201 /* display file size */
3202 if (visible_cols & COL_SIZE) {
3203 #ifdef _NO_EXTENSIONS
3204 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3205 #endif
3207 format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
3209 if (calcWidthCol == -1)
3210 output_number(pane, dis, col, buffer);
3211 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3212 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3215 col++;
3218 /* display file date */
3219 if (visible_cols & (COL_DATE|COL_TIME)) {
3220 #ifndef _NO_EXTENSIONS
3221 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3222 if (calcWidthCol == -1)
3223 output_text(pane, dis, col, buffer, 0);
3224 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3225 calc_width(pane, dis, col, buffer);
3226 col++;
3228 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3229 if (calcWidthCol == -1)
3230 output_text(pane, dis, col, buffer, 0);
3231 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3232 calc_width(pane, dis, col, buffer);
3233 col++;
3234 #endif /* _NO_EXTENSIONS */
3236 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3237 if (calcWidthCol == -1)
3238 output_text(pane, dis, col, buffer, 0);
3239 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3240 calc_width(pane, dis, col, buffer);
3241 col++;
3244 #ifndef _NO_EXTENSIONS
3245 if (entry->bhfi_valid) {
3246 if (visible_cols & COL_INDEX) {
3247 static const WCHAR fmtlow[] = {'%','X',0};
3248 static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
3250 if (entry->bhfi.nFileIndexHigh)
3251 wsprintfW(buffer, fmthigh,
3252 entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
3253 else
3254 wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
3256 if (calcWidthCol == -1)
3257 output_text(pane, dis, col, buffer, DT_RIGHT);
3258 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3259 calc_width(pane, dis, col, buffer);
3261 col++;
3264 if (visible_cols & COL_LINKS) {
3265 wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3267 if (calcWidthCol == -1)
3268 output_text(pane, dis, col, buffer, DT_CENTER);
3269 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3270 calc_width(pane, dis, col, buffer);
3272 col++;
3274 } else
3275 col += 2;
3276 #endif /* _NO_EXTENSIONS */
3278 /* show file attributes */
3279 if (visible_cols & COL_ATTRIBUTES) {
3280 #ifdef _NO_EXTENSIONS
3281 static const WCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3282 lstrcpyW(buffer, s4Tabs);
3283 #else
3284 static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3285 lstrcpyW(buffer, s11Tabs);
3286 #endif
3288 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3289 else {
3290 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3291 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3292 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3293 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3294 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3295 #ifndef _NO_EXTENSIONS
3296 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3297 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3298 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3299 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3300 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3301 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3302 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3303 #endif /* _NO_EXTENSIONS */
3306 if (calcWidthCol == -1)
3307 output_tabbed_text(pane, dis, col, buffer);
3308 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3309 calc_tabbed_width(pane, dis, col, buffer);
3311 col++;
3314 /*TODO
3315 if (flags.security) {
3316 static const WCHAR sSecTabs[] = {
3317 ' ','\t',' ','\t',' ','\t',' ',
3318 ' ','\t',' ',
3319 ' ','\t',' ','\t',' ','\t',' ',
3320 ' ','\t',' ',
3321 ' ','\t',' ','\t',' ','\t',' ',
3322 '\0'
3325 DWORD rights = get_access_mask();
3327 lstrcpyW(buffer, sSecTabs);
3329 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
3330 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
3331 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
3332 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
3333 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
3334 if (rights & FILE_EXECUTE) buffer[12] = 'X';
3335 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
3336 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
3337 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
3338 if (rights & WRITE_DAC) buffer[22] = 'C';
3339 if (rights & WRITE_OWNER) buffer[24] = 'O';
3340 if (rights & SYNCHRONIZE) buffer[26] = 'S';
3342 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
3345 if (flags.description) {
3346 get_description(buffer);
3347 output_text(dis, col++, buffer, 0, psize);
3351 #ifdef _NO_EXTENSIONS
3354 /* draw focus frame */
3355 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3356 /* Currently [04/2000] Wine neither behaves exactly the same */
3357 /* way as WIN 95 nor like Windows NT... */
3358 HGDIOBJ lastBrush;
3359 HPEN lastPen;
3360 HPEN hpen;
3362 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3363 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3364 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3365 } else
3366 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3368 lastPen = SelectPen(dis->hDC, hpen);
3369 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3370 SetROP2(dis->hDC, R2_XORPEN);
3371 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3372 SelectObject(dis->hDC, lastBrush);
3373 SelectObject(dis->hDC, lastPen);
3374 DeleteObject(hpen);
3376 #endif /* _NO_EXTENSIONS */
3380 #ifdef _NO_EXTENSIONS
3382 static void draw_splitbar(HWND hwnd, int x)
3384 RECT rt;
3385 HDC hdc = GetDC(hwnd);
3387 GetClientRect(hwnd, &rt);
3389 rt.left = x - SPLIT_WIDTH/2;
3390 rt.right = x + SPLIT_WIDTH/2+1;
3392 InvertRect(hdc, &rt);
3394 ReleaseDC(hwnd, hdc);
3397 #endif /* _NO_EXTENSIONS */
3400 #ifndef _NO_EXTENSIONS
3402 static void set_header(Pane* pane)
3404 HDITEMW item;
3405 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3406 int i=0, x=0;
3408 item.mask = HDI_WIDTH;
3409 item.cxy = 0;
3411 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3412 x += pane->widths[i];
3413 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
3416 if (i < COLUMNS) {
3417 x += pane->widths[i];
3418 item.cxy = x - scroll_pos;
3419 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i++, (LPARAM)&item);
3421 for(; i<COLUMNS; i++) {
3422 item.cxy = pane->widths[i];
3423 x += pane->widths[i];
3424 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
3429 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3431 switch(pnmh->code) {
3432 case HDN_ITEMCHANGEDW: {
3433 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
3434 int idx = phdn->iItem;
3435 int dx = phdn->pitem->cxy - pane->widths[idx];
3436 int i;
3438 RECT clnt;
3439 GetClientRect(pane->hwnd, &clnt);
3441 pane->widths[idx] += dx;
3443 for(i=idx; ++i<=COLUMNS; )
3444 pane->positions[i] += dx;
3447 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3448 RECT rt_scr;
3449 RECT rt_clip;
3451 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3452 rt_scr.top = 0;
3453 rt_scr.right = clnt.right;
3454 rt_scr.bottom = clnt.bottom;
3456 rt_clip.left = pane->positions[idx]-scroll_pos;
3457 rt_clip.top = 0;
3458 rt_clip.right = clnt.right;
3459 rt_clip.bottom = clnt.bottom;
3461 if (rt_scr.left < 0) rt_scr.left = 0;
3462 if (rt_clip.left < 0) rt_clip.left = 0;
3464 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3466 rt_clip.right = pane->positions[idx+1];
3467 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3469 if (pnmh->code == HDN_ENDTRACKW) {
3470 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3472 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3473 set_header(pane);
3477 return FALSE;
3480 case HDN_DIVIDERDBLCLICKW: {
3481 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
3482 HDITEMW item;
3484 calc_single_width(pane, phdn->iItem);
3485 item.mask = HDI_WIDTH;
3486 item.cxy = pane->widths[phdn->iItem];
3488 SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
3489 InvalidateRect(pane->hwnd, 0, TRUE);
3490 break;}
3493 return 0;
3496 #endif /* _NO_EXTENSIONS */
3499 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3501 WCHAR path[MAX_PATH];
3502 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
3504 /* delete sub entries in left pane */
3505 for(;;) {
3506 LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3507 Entry* sub = (Entry*) res;
3509 if (res==LB_ERR || !sub || sub->level<=entry->level)
3510 break;
3512 SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3515 /* empty right pane */
3516 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3518 /* release memory */
3519 free_entries(entry);
3521 /* read contents from disk */
3522 #ifdef _SHELL_FOLDERS
3523 if (entry->etype == ET_SHELL)
3525 read_directory(entry, NULL, child->sortOrder, hwnd);
3527 else
3528 #endif
3530 get_path(entry, path);
3531 read_directory(entry, path, child->sortOrder, hwnd);
3534 /* insert found entries in right pane */
3535 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3536 calc_widths(&child->right, FALSE);
3537 #ifndef _NO_EXTENSIONS
3538 set_header(&child->right);
3539 #endif
3541 child->header_wdths_ok = FALSE;
3543 SetCursor(old_cursor);
3547 /* expand a directory entry */
3549 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3551 int idx;
3552 Entry* p;
3554 if (!dir || dir->expanded || !dir->down)
3555 return FALSE;
3557 p = dir->down;
3559 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3560 p = p->next;
3562 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3563 p->data.cFileName[2]=='\0' && p->next)
3564 p = p->next;
3567 /* no subdirectories ? */
3568 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3569 return FALSE;
3571 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3573 dir->expanded = TRUE;
3575 /* insert entries in left pane */
3576 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3578 if (!child->header_wdths_ok) {
3579 if (calc_widths(&child->left, FALSE)) {
3580 #ifndef _NO_EXTENSIONS
3581 set_header(&child->left);
3582 #endif
3584 child->header_wdths_ok = TRUE;
3588 return TRUE;
3592 static void collapse_entry(Pane* pane, Entry* dir)
3594 int idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3596 ShowWindow(pane->hwnd, SW_HIDE);
3598 /* hide sub entries */
3599 for(;;) {
3600 LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3601 Entry* sub = (Entry*) res;
3603 if (res==LB_ERR || !sub || sub->level<=dir->level)
3604 break;
3606 SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3609 dir->expanded = FALSE;
3611 ShowWindow(pane->hwnd, SW_SHOW);
3615 static void refresh_right_pane(ChildWnd* child)
3617 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3618 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3619 calc_widths(&child->right, FALSE);
3621 #ifndef _NO_EXTENSIONS
3622 set_header(&child->right);
3623 #endif
3626 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3628 WCHAR path[MAX_PATH];
3630 if (!entry)
3631 return;
3633 path[0] = '\0';
3635 child->left.cur = entry;
3637 child->right.root = entry->down? entry->down: entry;
3638 child->right.cur = entry;
3640 if (!entry->scanned)
3641 scan_entry(child, entry, idx, hwnd);
3642 else
3643 refresh_right_pane(child);
3645 get_path(entry, path);
3646 lstrcpyW(child->path, path);
3648 if (child->hwnd) /* only change window title, if the window already exists */
3649 SetWindowTextW(child->hwnd, path);
3651 if (path[0])
3652 if (SetCurrentDirectoryW(path))
3653 set_space_status();
3657 static void refresh_child(ChildWnd* child)
3659 WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3660 Entry* entry;
3661 int idx;
3663 get_path(child->left.cur, path);
3664 _wsplitpath(path, drv, NULL, NULL, NULL);
3666 child->right.root = NULL;
3668 scan_entry(child, &child->root.entry, 0, child->hwnd);
3670 #ifdef _SHELL_FOLDERS
3672 if (child->root.entry.etype == ET_SHELL)
3674 LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
3675 if (local_pidl)
3676 entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
3677 else
3678 entry = NULL;
3680 else
3681 #endif
3682 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3684 if (!entry)
3685 entry = &child->root.entry;
3687 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3689 set_curdir(child, entry, 0, child->hwnd);
3691 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3692 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3696 static void create_drive_bar(void)
3698 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3699 #ifndef _NO_EXTENSIONS
3700 WCHAR b1[BUFFER_LEN];
3701 #endif
3702 int btn = 1;
3703 PWSTR p;
3705 GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
3707 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3708 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3709 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3711 #ifndef _NO_EXTENSIONS
3712 #ifdef __WINE__
3713 /* insert unix file system button */
3714 b1[0] = '/';
3715 b1[1] = '\0';
3716 b1[2] = '\0';
3717 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3719 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3720 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3721 drivebarBtn.iString++;
3722 #endif
3723 #ifdef _SHELL_FOLDERS
3724 /* insert shell namespace button */
3725 load_string(b1, sizeof(b1)/sizeof(b1[0]), IDS_SHELL);
3726 b1[lstrlenW(b1)+1] = '\0';
3727 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3729 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3730 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3731 drivebarBtn.iString++;
3732 #endif
3734 /* register windows drive root strings */
3735 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
3736 #endif
3738 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3740 for(p=Globals.drives; *p; ) {
3741 #ifdef _NO_EXTENSIONS
3742 /* insert drive letter */
3743 WCHAR b[3] = {tolower(*p)};
3744 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b);
3745 #endif
3746 switch(GetDriveTypeW(p)) {
3747 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3748 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3749 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3750 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3751 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3754 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3755 drivebarBtn.idCommand++;
3756 drivebarBtn.iString++;
3758 while(*p++);
3762 static void refresh_drives(void)
3764 RECT rect;
3766 /* destroy drive bar */
3767 DestroyWindow(Globals.hdrivebar);
3768 Globals.hdrivebar = 0;
3770 /* re-create drive bar */
3771 create_drive_bar();
3773 /* update window layout */
3774 GetClientRect(Globals.hMainWnd, &rect);
3775 SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3779 static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
3781 HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3783 if (PtrToUlong(hinst) <= 32) {
3784 display_error(hwnd, GetLastError());
3785 return FALSE;
3788 return TRUE;
3792 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3794 WCHAR cmd[MAX_PATH];
3796 #ifdef _SHELL_FOLDERS
3797 if (entry->etype == ET_SHELL) {
3798 BOOL ret = TRUE;
3800 SHELLEXECUTEINFOW shexinfo;
3802 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
3803 shexinfo.fMask = SEE_MASK_IDLIST;
3804 shexinfo.hwnd = hwnd;
3805 shexinfo.lpVerb = NULL;
3806 shexinfo.lpFile = NULL;
3807 shexinfo.lpParameters = NULL;
3808 shexinfo.lpDirectory = NULL;
3809 shexinfo.nShow = nCmdShow;
3810 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3812 if (!ShellExecuteExW(&shexinfo)) {
3813 display_error(hwnd, GetLastError());
3814 ret = FALSE;
3817 if (shexinfo.lpIDList != entry->pidl)
3818 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3820 return ret;
3822 #endif
3824 get_path(entry, cmd);
3826 /* start program, open document... */
3827 return launch_file(hwnd, cmd, nCmdShow);
3831 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3833 Entry* entry = pane->cur;
3835 if (!entry)
3836 return;
3838 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3839 int scanned_old = entry->scanned;
3841 if (!scanned_old)
3843 int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3844 scan_entry(child, entry, idx, hwnd);
3847 #ifndef _NO_EXTENSIONS
3848 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3849 return;
3850 #endif
3852 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3853 entry = child->left.cur->up;
3854 collapse_entry(&child->left, entry);
3855 goto focus_entry;
3856 } else if (entry->expanded)
3857 collapse_entry(pane, child->left.cur);
3858 else {
3859 expand_entry(child, child->left.cur);
3861 if (!pane->treePane) focus_entry: {
3862 int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3863 int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
3864 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3865 set_curdir(child, entry, idx, hwnd);
3869 if (!scanned_old) {
3870 calc_widths(pane, FALSE);
3872 #ifndef _NO_EXTENSIONS
3873 set_header(pane);
3874 #endif
3876 } else {
3877 if (GetKeyState(VK_MENU) < 0)
3878 show_properties_dlg(entry, child->hwnd);
3879 else
3880 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3885 static BOOL pane_command(Pane* pane, UINT cmd)
3887 switch(cmd) {
3888 case ID_VIEW_NAME:
3889 if (pane->visible_cols) {
3890 pane->visible_cols = 0;
3891 calc_widths(pane, TRUE);
3892 #ifndef _NO_EXTENSIONS
3893 set_header(pane);
3894 #endif
3895 InvalidateRect(pane->hwnd, 0, TRUE);
3896 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3897 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3898 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3900 break;
3902 case ID_VIEW_ALL_ATTRIBUTES:
3903 if (pane->visible_cols != COL_ALL) {
3904 pane->visible_cols = COL_ALL;
3905 calc_widths(pane, TRUE);
3906 #ifndef _NO_EXTENSIONS
3907 set_header(pane);
3908 #endif
3909 InvalidateRect(pane->hwnd, 0, TRUE);
3910 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3911 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3912 CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
3914 break;
3916 #ifndef _NO_EXTENSIONS
3917 case ID_PREFERRED_SIZES: {
3918 calc_widths(pane, TRUE);
3919 set_header(pane);
3920 InvalidateRect(pane->hwnd, 0, TRUE);
3921 break;}
3922 #endif
3924 /* TODO: more command ids... */
3926 default:
3927 return FALSE;
3930 return TRUE;
3934 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3936 if (child->sortOrder != sortOrder) {
3937 child->sortOrder = sortOrder;
3938 refresh_child(child);
3942 static void update_view_menu(ChildWnd* child)
3944 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3945 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3946 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3947 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3951 static BOOL is_directory(LPCWSTR target)
3953 /*TODO correctly handle UNIX paths */
3954 DWORD target_attr = GetFileAttributesW(target);
3956 if (target_attr == INVALID_FILE_ATTRIBUTES)
3957 return FALSE;
3959 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
3962 static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
3964 WCHAR path[MAX_PATH];
3965 int len;
3967 get_path(pane->cur, path);
3969 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
3970 return FALSE;
3972 get_path(pane->cur, source);
3974 /* convert relative targets to absolute paths */
3975 if (path[0]!='/' && path[1]!=':') {
3976 get_path(pane->cur->up, target);
3977 len = lstrlenW(target);
3979 if (target[len-1]!='\\' && target[len-1]!='/')
3980 target[len++] = '/';
3982 lstrcpyW(target+len, path);
3983 } else
3984 lstrcpyW(target, path);
3986 /* If the target already exists as directory, create a new target below this. */
3987 if (is_directory(path)) {
3988 WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
3989 static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
3991 _wsplitpath(source, NULL, NULL, fname, ext);
3993 wsprintfW(target, sAppend, path, fname, ext);
3996 return TRUE;
4000 static IContextMenu2* s_pctxmenu2 = NULL;
4001 static IContextMenu3* s_pctxmenu3 = NULL;
4003 static void CtxMenu_reset(void)
4005 s_pctxmenu2 = NULL;
4006 s_pctxmenu3 = NULL;
4009 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
4011 IContextMenu* pcm = NULL;
4013 CtxMenu_reset();
4015 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
4016 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
4017 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
4018 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
4020 if (pcm) {
4021 IContextMenu_Release(pcm1);
4022 return pcm;
4023 } else
4024 return pcm1;
4027 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
4029 if (s_pctxmenu3) {
4030 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4031 return TRUE;
4034 if (s_pctxmenu2)
4035 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4036 return TRUE;
4038 return FALSE;
4042 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4044 IContextMenu* pcm;
4045 BOOL executed = FALSE;
4047 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4048 /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
4050 if (SUCCEEDED(hr)) {
4051 HMENU hmenu = CreatePopupMenu();
4053 pcm = CtxMenu_query_interfaces(pcm);
4055 if (hmenu) {
4056 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4058 if (SUCCEEDED(hr)) {
4059 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4061 CtxMenu_reset();
4063 if (idCmd) {
4064 CMINVOKECOMMANDINFO cmi;
4066 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4067 cmi.fMask = 0;
4068 cmi.hwnd = hwndParent;
4069 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4070 cmi.lpParameters = NULL;
4071 cmi.lpDirectory = NULL;
4072 cmi.nShow = SW_SHOWNORMAL;
4073 cmi.dwHotKey = 0;
4074 cmi.hIcon = 0;
4076 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4077 executed = TRUE;
4079 } else
4080 CtxMenu_reset();
4083 IContextMenu_Release(pcm);
4086 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4090 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4092 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
4093 ASSERT(child);
4095 switch(nmsg) {
4096 case WM_DRAWITEM: {
4097 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4098 Entry* entry = (Entry*) dis->itemData;
4100 if (dis->CtlID == IDW_TREE_LEFT)
4101 draw_item(&child->left, dis, entry, -1);
4102 else if (dis->CtlID == IDW_TREE_RIGHT)
4103 draw_item(&child->right, dis, entry, -1);
4104 else
4105 goto draw_menu_item;
4107 return TRUE;}
4109 case WM_CREATE:
4110 InitChildWindow(child);
4111 break;
4113 case WM_NCDESTROY:
4114 free_child_window(child);
4115 SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
4116 break;
4118 case WM_PAINT: {
4119 PAINTSTRUCT ps;
4120 HBRUSH lastBrush;
4121 RECT rt;
4122 GetClientRect(hwnd, &rt);
4123 BeginPaint(hwnd, &ps);
4124 rt.left = child->split_pos-SPLIT_WIDTH/2;
4125 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4126 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4127 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4128 SelectObject(ps.hdc, lastBrush);
4129 #ifdef _NO_EXTENSIONS
4130 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4131 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4132 #endif
4133 EndPaint(hwnd, &ps);
4134 break;}
4136 case WM_SETCURSOR:
4137 if (LOWORD(lparam) == HTCLIENT) {
4138 POINT pt;
4139 GetCursorPos(&pt);
4140 ScreenToClient(hwnd, &pt);
4142 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4143 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
4144 return TRUE;
4147 goto def;
4149 case WM_LBUTTONDOWN: {
4150 RECT rt;
4151 int x = (short)LOWORD(lparam);
4153 GetClientRect(hwnd, &rt);
4155 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4156 last_split = child->split_pos;
4157 #ifdef _NO_EXTENSIONS
4158 draw_splitbar(hwnd, last_split);
4159 #endif
4160 SetCapture(hwnd);
4163 break;}
4165 case WM_LBUTTONUP:
4166 if (GetCapture() == hwnd) {
4167 #ifdef _NO_EXTENSIONS
4168 RECT rt;
4169 int x = (short)LOWORD(lparam);
4170 draw_splitbar(hwnd, last_split);
4171 last_split = -1;
4172 GetClientRect(hwnd, &rt);
4173 child->split_pos = x;
4174 resize_tree(child, rt.right, rt.bottom);
4175 #endif
4176 ReleaseCapture();
4178 break;
4180 #ifdef _NO_EXTENSIONS
4181 case WM_CAPTURECHANGED:
4182 if (GetCapture()==hwnd && last_split>=0)
4183 draw_splitbar(hwnd, last_split);
4184 break;
4185 #endif
4187 case WM_KEYDOWN:
4188 if (wparam == VK_ESCAPE)
4189 if (GetCapture() == hwnd) {
4190 RECT rt;
4191 #ifdef _NO_EXTENSIONS
4192 draw_splitbar(hwnd, last_split);
4193 #else
4194 child->split_pos = last_split;
4195 #endif
4196 GetClientRect(hwnd, &rt);
4197 resize_tree(child, rt.right, rt.bottom);
4198 last_split = -1;
4199 ReleaseCapture();
4200 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
4202 break;
4204 case WM_MOUSEMOVE:
4205 if (GetCapture() == hwnd) {
4206 RECT rt;
4207 int x = (short)LOWORD(lparam);
4209 #ifdef _NO_EXTENSIONS
4210 HDC hdc = GetDC(hwnd);
4211 GetClientRect(hwnd, &rt);
4213 rt.left = last_split-SPLIT_WIDTH/2;
4214 rt.right = last_split+SPLIT_WIDTH/2+1;
4215 InvertRect(hdc, &rt);
4217 last_split = x;
4218 rt.left = x-SPLIT_WIDTH/2;
4219 rt.right = x+SPLIT_WIDTH/2+1;
4220 InvertRect(hdc, &rt);
4222 ReleaseDC(hwnd, hdc);
4223 #else
4224 GetClientRect(hwnd, &rt);
4226 if (x>=0 && x<rt.right) {
4227 child->split_pos = x;
4228 resize_tree(child, rt.right, rt.bottom);
4229 rt.left = x-SPLIT_WIDTH/2;
4230 rt.right = x+SPLIT_WIDTH/2+1;
4231 InvalidateRect(hwnd, &rt, FALSE);
4232 UpdateWindow(child->left.hwnd);
4233 UpdateWindow(hwnd);
4234 UpdateWindow(child->right.hwnd);
4236 #endif
4238 break;
4240 #ifndef _NO_EXTENSIONS
4241 case WM_GETMINMAXINFO:
4242 DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
4244 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4246 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4247 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4248 break;}
4249 #endif /* _NO_EXTENSIONS */
4251 case WM_SETFOCUS:
4252 if (SetCurrentDirectoryW(child->path))
4253 set_space_status();
4254 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4255 break;
4257 case WM_DISPATCH_COMMAND: {
4258 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4260 switch(LOWORD(wparam)) {
4261 case ID_WINDOW_NEW: {
4262 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4264 if (!create_child_window(new_child))
4265 HeapFree(GetProcessHeap(), 0, new_child);
4267 break;}
4269 case ID_REFRESH:
4270 refresh_drives();
4271 refresh_child(child);
4272 break;
4274 case ID_ACTIVATE:
4275 activate_entry(child, pane, hwnd);
4276 break;
4278 case ID_FILE_MOVE: {
4279 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4281 if (prompt_target(pane, source, target)) {
4282 SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
4284 source[lstrlenW(source)+1] = '\0';
4285 target[lstrlenW(target)+1] = '\0';
4287 if (!SHFileOperationW(&shfo))
4288 refresh_child(child);
4290 break;}
4292 case ID_FILE_COPY: {
4293 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4295 if (prompt_target(pane, source, target)) {
4296 SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
4298 source[lstrlenW(source)+1] = '\0';
4299 target[lstrlenW(target)+1] = '\0';
4301 if (!SHFileOperationW(&shfo))
4302 refresh_child(child);
4304 break;}
4306 case ID_FILE_DELETE: {
4307 WCHAR path[BUFFER_LEN];
4308 SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
4310 get_path(pane->cur, path);
4312 path[lstrlenW(path)+1] = '\0';
4314 if (!SHFileOperationW(&shfo))
4315 refresh_child(child);
4316 break;}
4318 case ID_VIEW_SORT_NAME:
4319 set_sort_order(child, SORT_NAME);
4320 break;
4322 case ID_VIEW_SORT_TYPE:
4323 set_sort_order(child, SORT_EXT);
4324 break;
4326 case ID_VIEW_SORT_SIZE:
4327 set_sort_order(child, SORT_SIZE);
4328 break;
4330 case ID_VIEW_SORT_DATE:
4331 set_sort_order(child, SORT_DATE);
4332 break;
4334 case ID_VIEW_FILTER: {
4335 struct FilterDialog dlg;
4337 memset(&dlg, 0, sizeof(struct FilterDialog));
4338 lstrcpyW(dlg.pattern, child->filter_pattern);
4339 dlg.flags = child->filter_flags;
4341 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4342 lstrcpyW(child->filter_pattern, dlg.pattern);
4343 child->filter_flags = dlg.flags;
4344 refresh_right_pane(child);
4346 break;}
4348 case ID_VIEW_SPLIT: {
4349 last_split = child->split_pos;
4350 #ifdef _NO_EXTENSIONS
4351 draw_splitbar(hwnd, last_split);
4352 #endif
4353 SetCapture(hwnd);
4354 break;}
4356 case ID_EDIT_PROPERTIES:
4357 show_properties_dlg(pane->cur, child->hwnd);
4358 break;
4360 default:
4361 return pane_command(pane, LOWORD(wparam));
4364 return TRUE;}
4366 case WM_COMMAND: {
4367 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4369 switch(HIWORD(wparam)) {
4370 case LBN_SELCHANGE: {
4371 int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
4372 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
4374 if (pane == &child->left)
4375 set_curdir(child, entry, idx, hwnd);
4376 else
4377 pane->cur = entry;
4378 break;}
4380 case LBN_DBLCLK:
4381 activate_entry(child, pane, hwnd);
4382 break;
4384 break;}
4386 #ifndef _NO_EXTENSIONS
4387 case WM_NOTIFY: {
4388 NMHDR* pnmh = (NMHDR*) lparam;
4389 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4390 #endif
4392 #ifdef _SHELL_FOLDERS
4393 case WM_CONTEXTMENU: {
4394 POINT pt, pt_clnt;
4395 Pane* pane;
4396 int idx;
4398 /* first select the current item in the listbox */
4399 HWND hpanel = (HWND) wparam;
4400 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4401 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4402 ScreenToClient(hpanel, &pt_clnt);
4403 SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4404 SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4406 /* now create the popup menu using shell namespace and IContextMenu */
4407 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4408 idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
4410 if (idx != -1) {
4411 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
4413 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4415 if (pidl_abs) {
4416 IShellFolder* parentFolder;
4417 LPCITEMIDLIST pidlLast;
4419 /* get and use the parent folder to display correct context menu in all cases */
4420 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4421 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4422 refresh_child(child);
4424 IShellFolder_Release(parentFolder);
4427 IMalloc_Free(Globals.iMalloc, pidl_abs);
4430 break;}
4431 #endif
4433 case WM_MEASUREITEM:
4434 draw_menu_item:
4435 if (!wparam) /* Is the message menu-related? */
4436 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4437 return TRUE;
4439 break;
4441 case WM_INITMENUPOPUP:
4442 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4443 return 0;
4445 update_view_menu(child);
4446 break;
4448 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4449 if (s_pctxmenu3) {
4450 LRESULT lResult = 0;
4452 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4454 return lResult;
4457 break;
4459 case WM_SIZE:
4460 if (wparam != SIZE_MINIMIZED)
4461 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4462 /* fall through */
4464 default: def:
4465 return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
4468 return 0;
4472 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4474 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
4475 Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
4476 ASSERT(child);
4478 switch(nmsg) {
4479 #ifndef _NO_EXTENSIONS
4480 case WM_HSCROLL:
4481 set_header(pane);
4482 break;
4483 #endif
4485 case WM_SETFOCUS:
4486 child->focus_pane = pane==&child->right? 1: 0;
4487 SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
4488 /*TODO: check menu items */
4489 break;
4491 case WM_KEYDOWN:
4492 if (wparam == VK_TAB) {
4493 /*TODO: SetFocus(Globals.hdrivebar) */
4494 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4498 return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4502 static void InitInstance(HINSTANCE hinstance)
4504 static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4506 WNDCLASSEXW wcFrame;
4507 WNDCLASSW wcChild;
4508 ATOM hChildClass;
4509 int col;
4511 INITCOMMONCONTROLSEX icc = {
4512 sizeof(INITCOMMONCONTROLSEX),
4513 ICC_BAR_CLASSES
4516 HDC hdc = GetDC(0);
4518 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4520 InitCommonControlsEx(&icc);
4523 /* register frame window class */
4525 wcFrame.cbSize = sizeof(WNDCLASSEXW);
4526 wcFrame.style = 0;
4527 wcFrame.lpfnWndProc = FrameWndProc;
4528 wcFrame.cbClsExtra = 0;
4529 wcFrame.cbWndExtra = 0;
4530 wcFrame.hInstance = hinstance;
4531 wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
4532 wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
4533 wcFrame.hbrBackground = 0;
4534 wcFrame.lpszMenuName = 0;
4535 wcFrame.lpszClassName = sWINEFILEFRAME;
4536 wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
4538 Globals.hframeClass = RegisterClassExW(&wcFrame);
4541 /* register tree windows class */
4543 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4544 wcChild.lpfnWndProc = ChildWndProc;
4545 wcChild.cbClsExtra = 0;
4546 wcChild.cbWndExtra = 0;
4547 wcChild.hInstance = hinstance;
4548 wcChild.hIcon = 0;
4549 wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
4550 wcChild.hbrBackground = 0;
4551 wcChild.lpszMenuName = 0;
4552 wcChild.lpszClassName = sWINEFILETREE;
4554 hChildClass = RegisterClassW(&wcChild);
4557 Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
4559 Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4561 ReleaseDC(0, hdc);
4563 Globals.hInstance = hinstance;
4565 #ifdef _SHELL_FOLDERS
4566 CoInitialize(NULL);
4567 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4568 SHGetDesktopFolder(&Globals.iDesktop);
4569 Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
4570 #endif
4572 /* load column strings */
4573 col = 1;
4575 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_NAME);
4576 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SIZE);
4577 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_CDATE);
4578 #ifndef _NO_EXTENSIONS
4579 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ADATE);
4580 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_MDATE);
4581 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_IDX);
4582 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_LINKS);
4583 #endif
4584 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ATTR);
4585 #ifndef _NO_EXTENSIONS
4586 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SEC);
4587 #endif
4591 static BOOL show_frame(HWND hwndParent, int cmdshow, LPCWSTR path)
4593 static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4595 WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4596 ChildWnd* child;
4597 HMENU hMenuFrame, hMenuWindow;
4598 windowOptions opts;
4600 CLIENTCREATESTRUCT ccs;
4602 if (Globals.hMainWnd)
4603 return TRUE;
4605 opts = load_registry_settings();
4606 hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
4607 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4609 Globals.hMenuFrame = hMenuFrame;
4610 Globals.hMenuView = GetSubMenu(hMenuFrame, 3);
4611 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4);
4613 ccs.hWindowMenu = hMenuWindow;
4614 ccs.idFirstChild = IDW_FIRST_CHILD;
4617 /* create main window */
4618 Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW,
4619 opts.start_x, opts.start_y, opts.width, opts.height,
4620 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4623 Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
4624 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4625 0, 0, 0, 0,
4626 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4628 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4629 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4631 create_drive_bar();
4634 TBBUTTON toolbarBtns[] = {
4635 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4636 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4637 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4638 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4639 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4640 /*TODO
4641 {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4642 {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4643 */ };
4645 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4646 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4647 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4648 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4651 Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4652 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4654 /* CreateStatusWindowW does not accept WS_BORDER
4655 Globals.hstatusbar = CreateWindowExW(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
4656 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
4657 Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/
4659 /*TODO: read paths from registry */
4661 if (!path || !*path) {
4662 GetCurrentDirectoryW(MAX_PATH, buffer);
4663 path = buffer;
4666 ShowWindow(Globals.hMainWnd, cmdshow);
4668 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4669 /* Shell Namespace as default: */
4670 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4671 #else
4672 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4673 #endif
4675 child->pos.showCmd = SW_SHOWMAXIMIZED;
4676 child->pos.rcNormalPosition.left = 0;
4677 child->pos.rcNormalPosition.top = 0;
4678 child->pos.rcNormalPosition.right = 320;
4679 child->pos.rcNormalPosition.bottom = 280;
4681 if (!create_child_window(child)) {
4682 HeapFree(GetProcessHeap(), 0, child);
4683 return FALSE;
4686 SetWindowPlacement(child->hwnd, &child->pos);
4688 Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
4690 Globals.prescan_node = FALSE;
4692 UpdateWindow(Globals.hMainWnd);
4694 if (child->hwnd && path && path[0])
4696 int index,count;
4697 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4698 WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4700 memset(name,0,sizeof(name));
4701 memset(name,0,sizeof(ext));
4702 _wsplitpath(path, drv, dir, name, ext);
4703 if (name[0])
4705 count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
4706 lstrcpyW(fullname,name);
4707 lstrcatW(fullname,ext);
4709 for (index = 0; index < count; index ++)
4711 Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
4712 if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
4713 lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
4715 SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
4716 SetFocus(child->right.hwnd);
4717 break;
4722 return TRUE;
4725 static void ExitInstance(void)
4727 #ifdef _SHELL_FOLDERS
4728 IShellFolder_Release(Globals.iDesktop);
4729 IMalloc_Release(Globals.iMalloc);
4730 CoUninitialize();
4731 #endif
4733 DeleteObject(Globals.hfont);
4734 ImageList_Destroy(Globals.himl);
4737 #ifdef _NO_EXTENSIONS
4739 /* search for already running win[e]files */
4741 static int g_foundPrevInstance = 0;
4743 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4745 WCHAR cls[128];
4747 GetClassName(hwnd, cls, 128);
4749 if (!lstrcmpW(cls, (LPCWSTR)lparam)) {
4750 g_foundPrevInstance++;
4751 return FALSE;
4754 return TRUE;
4757 /* search for window of given class name to allow only one running instance */
4758 static int find_window_class(LPCWSTR classname)
4760 EnumWindows(EnumWndProc, (LPARAM)classname);
4762 if (g_foundPrevInstance)
4763 return 1;
4765 return 0;
4768 #endif
4770 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCWSTR path)
4772 MSG msg;
4774 InitInstance(hinstance);
4776 if( !show_frame(0, cmdshow, path) )
4778 ExitInstance();
4779 return 1;
4782 while(GetMessageW(&msg, 0, 0, 0)) {
4783 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4784 continue;
4786 if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
4787 continue;
4789 TranslateMessage(&msg);
4790 DispatchMessageW(&msg);
4793 ExitInstance();
4795 return msg.wParam;
4799 #if defined(_MSC_VER)
4800 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4801 #else
4802 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4803 #endif
4805 #ifdef _NO_EXTENSIONS
4806 if (find_window_class(sWINEFILEFRAME))
4807 return 1;
4808 #endif
4810 { /* convert ANSI cmdline into WCS path string */
4811 WCHAR buffer[MAX_PATH];
4812 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4813 winefile_main(hinstance, cmdshow, buffer);
4816 return 0;