winefile: Avoid uninitialized field in SYSTEMTIME structure (Coverity).
[wine/multimedia.git] / programs / winefile / winefile.c
blob63ce463dc0d10a7be8eef5f0d17dc69e390fd8cc
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);
267 GetObjectW(Globals.hfont, sizeof(LOGFONTW), &lFont);
269 chFont.lStructSize = sizeof(CHOOSEFONTW);
270 chFont.hwndOwner = hwnd;
271 chFont.hDC = NULL;
272 chFont.lpLogFont = &lFont;
273 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL | CF_INITTOLOGFONTSTRUCT;
274 chFont.rgbColors = RGB(0,0,0);
275 chFont.lCustData = 0;
276 chFont.lpfnHook = NULL;
277 chFont.lpTemplateName = NULL;
278 chFont.hInstance = Globals.hInstance;
279 chFont.lpszStyle = NULL;
280 chFont.nFontType = SIMULATED_FONTTYPE;
281 chFont.nSizeMin = 0;
282 chFont.nSizeMax = 24;
284 if (ChooseFontW(&chFont)) {
285 HWND childWnd;
286 HFONT hFontOld;
288 DeleteObject(Globals.hfont);
289 Globals.hfont = CreateFontIndirectW(&lFont);
290 hFontOld = SelectObject(hdc, Globals.hfont);
291 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
293 /* change font in all open child windows */
294 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
295 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
296 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
297 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
298 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
299 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
300 InvalidateRect(child->left.hwnd, NULL, TRUE);
301 InvalidateRect(child->right.hwnd, NULL, TRUE);
304 SelectObject(hdc, hFontOld);
306 else if (CommDlgExtendedError()) {
307 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
308 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
309 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
312 ReleaseDC(hwnd, hdc);
316 /* allocate and initialise a directory entry */
317 static Entry* alloc_entry(void)
319 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
321 #ifdef _SHELL_FOLDERS
322 entry->pidl = NULL;
323 entry->folder = NULL;
324 entry->hicon = 0;
325 #endif
327 return entry;
330 /* free a directory entry */
331 static void free_entry(Entry* entry)
333 #ifdef _SHELL_FOLDERS
334 if (entry->hicon && entry->hicon!=(HICON)-1)
335 DestroyIcon(entry->hicon);
337 if (entry->folder && entry->folder!=Globals.iDesktop)
338 IShellFolder_Release(entry->folder);
340 if (entry->pidl)
341 IMalloc_Free(Globals.iMalloc, entry->pidl);
342 #endif
344 HeapFree(GetProcessHeap(), 0, entry);
347 /* recursively free all child entries */
348 static void free_entries(Entry* dir)
350 Entry *entry, *next=dir->down;
352 if (next) {
353 dir->down = 0;
355 do {
356 entry = next;
357 next = entry->next;
359 free_entries(entry);
360 free_entry(entry);
361 } while(next);
366 static void read_directory_win(Entry* dir, LPCWSTR path)
368 Entry* first_entry = NULL;
369 Entry* last = NULL;
370 Entry* entry;
372 int level = dir->level + 1;
373 WIN32_FIND_DATAW w32fd;
374 HANDLE hFind;
375 #ifndef _NO_EXTENSIONS
376 HANDLE hFile;
377 #endif
379 WCHAR buffer[MAX_PATH], *p;
380 for(p=buffer; *path; )
381 *p++ = *path++;
383 *p++ = '\\';
384 p[0] = '*';
385 p[1] = '\0';
387 hFind = FindFirstFileW(buffer, &w32fd);
389 if (hFind != INVALID_HANDLE_VALUE) {
390 do {
391 #ifdef _NO_EXTENSIONS
392 /* hide directory entry "." */
393 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
394 LPCWSTR name = w32fd.cFileName;
396 if (name[0]=='.' && name[1]=='\0')
397 continue;
399 #endif
400 entry = alloc_entry();
402 if (!first_entry)
403 first_entry = entry;
405 if (last)
406 last->next = entry;
408 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATAW));
409 entry->down = NULL;
410 entry->up = dir;
411 entry->expanded = FALSE;
412 entry->scanned = FALSE;
413 entry->level = level;
415 #ifndef _NO_EXTENSIONS
416 entry->etype = ET_WINDOWS;
417 entry->bhfi_valid = FALSE;
419 lstrcpyW(p, entry->data.cFileName);
421 hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
422 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
424 if (hFile != INVALID_HANDLE_VALUE) {
425 if (GetFileInformationByHandle(hFile, &entry->bhfi))
426 entry->bhfi_valid = TRUE;
428 CloseHandle(hFile);
430 #endif
432 last = entry;
433 } while(FindNextFileW(hFind, &w32fd));
435 if (last)
436 last->next = NULL;
438 FindClose(hFind);
441 dir->down = first_entry;
442 dir->scanned = TRUE;
446 static Entry* find_entry_win(Entry* dir, LPCWSTR name)
448 Entry* entry;
450 for(entry=dir->down; entry; entry=entry->next) {
451 LPCWSTR p = name;
452 LPCWSTR q = entry->data.cFileName;
454 do {
455 if (!*p || *p == '\\' || *p == '/')
456 return entry;
457 } while(tolower(*p++) == tolower(*q++));
459 p = name;
460 q = entry->data.cAlternateFileName;
462 do {
463 if (!*p || *p == '\\' || *p == '/')
464 return entry;
465 } while(tolower(*p++) == tolower(*q++));
468 return 0;
472 static Entry* read_tree_win(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
474 WCHAR buffer[MAX_PATH];
475 Entry* entry = &root->entry;
476 LPCWSTR s = path;
477 PWSTR d = buffer;
479 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
481 #ifndef _NO_EXTENSIONS
482 entry->etype = ET_WINDOWS;
483 #endif
485 while(entry) {
486 while(*s && *s != '\\' && *s != '/')
487 *d++ = *s++;
489 while(*s == '\\' || *s == '/')
490 s++;
492 *d++ = '\\';
493 *d = '\0';
495 read_directory(entry, buffer, sortOrder, hwnd);
497 if (entry->down)
498 entry->expanded = TRUE;
500 if (!*s)
501 break;
503 entry = find_entry_win(entry, s);
506 SetCursor(old_cursor);
508 return entry;
512 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
514 static BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
516 struct tm* tm = gmtime(t);
517 SYSTEMTIME stime;
519 if (!tm)
520 return FALSE;
522 stime.wYear = tm->tm_year+1900;
523 stime.wMonth = tm->tm_mon+1;
524 /* stime.wDayOfWeek */
525 stime.wDay = tm->tm_mday;
526 stime.wHour = tm->tm_hour;
527 stime.wMinute = tm->tm_min;
528 stime.wSecond = tm->tm_sec;
529 stime.wMilliseconds = 0;
531 return SystemTimeToFileTime(&stime, ftime);
534 static void read_directory_unix(Entry* dir, LPCWSTR path)
536 Entry* first_entry = NULL;
537 Entry* last = NULL;
538 Entry* entry;
539 DIR* pdir;
541 int level = dir->level + 1;
542 char cpath[MAX_PATH];
544 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, cpath, MAX_PATH, NULL, NULL);
545 pdir = opendir(cpath);
547 if (pdir) {
548 struct stat st;
549 struct dirent* ent;
550 char buffer[MAX_PATH], *p;
551 const char* s;
553 for(p=buffer,s=cpath; *s; )
554 *p++ = *s++;
556 if (p==buffer || p[-1]!='/')
557 *p++ = '/';
559 while((ent=readdir(pdir))) {
560 entry = alloc_entry();
562 if (!first_entry)
563 first_entry = entry;
565 if (last)
566 last->next = entry;
568 entry->etype = ET_UNIX;
570 strcpy(p, ent->d_name);
571 MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH);
573 if (!stat(buffer, &st)) {
574 entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0;
576 if (S_ISDIR(st.st_mode))
577 entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
579 entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF;
580 entry->data.nFileSizeHigh = st.st_size >> 32;
582 memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME));
583 time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime);
584 time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime);
586 entry->bhfi.nFileIndexLow = ent->d_ino;
587 entry->bhfi.nFileIndexHigh = 0;
589 entry->bhfi.nNumberOfLinks = st.st_nlink;
591 entry->bhfi_valid = TRUE;
592 } else {
593 entry->data.nFileSizeLow = 0;
594 entry->data.nFileSizeHigh = 0;
595 entry->bhfi_valid = FALSE;
598 entry->down = NULL;
599 entry->up = dir;
600 entry->expanded = FALSE;
601 entry->scanned = FALSE;
602 entry->level = level;
604 last = entry;
607 if (last)
608 last->next = NULL;
610 closedir(pdir);
613 dir->down = first_entry;
614 dir->scanned = TRUE;
617 static Entry* find_entry_unix(Entry* dir, LPCWSTR name)
619 Entry* entry;
621 for(entry=dir->down; entry; entry=entry->next) {
622 LPCWSTR p = name;
623 LPCWSTR q = entry->data.cFileName;
625 do {
626 if (!*p || *p == '/')
627 return entry;
628 } while(*p++ == *q++);
631 return 0;
634 static Entry* read_tree_unix(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
636 WCHAR buffer[MAX_PATH];
637 Entry* entry = &root->entry;
638 LPCWSTR s = path;
639 PWSTR d = buffer;
641 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
643 entry->etype = ET_UNIX;
645 while(entry) {
646 while(*s && *s != '/')
647 *d++ = *s++;
649 while(*s == '/')
650 s++;
652 *d++ = '/';
653 *d = '\0';
655 read_directory(entry, buffer, sortOrder, hwnd);
657 if (entry->down)
658 entry->expanded = TRUE;
660 if (!*s)
661 break;
663 entry = find_entry_unix(entry, s);
666 SetCursor(old_cursor);
668 return entry;
671 #endif /* !defined(_NO_EXTENSIONS) && defined(__WINE__) */
674 #ifdef _SHELL_FOLDERS
676 static void free_strret(STRRET* str)
678 if (str->uType == STRRET_WSTR)
679 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
682 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
684 LPCWSTR s;
685 LPWSTR d = dest;
687 for(s=source; count&&(*d++=*s++); )
688 count--;
690 return dest;
693 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
695 switch(str->uType) {
696 case STRRET_WSTR:
697 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
698 break;
700 case STRRET_OFFSET:
701 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
702 break;
704 case STRRET_CSTR:
705 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
710 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len, SHGDNF flags)
712 STRRET str;
714 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
716 if (SUCCEEDED(hr)) {
717 get_strretW(&str, &pidl->mkid, buffer, len);
718 free_strret(&str);
719 } else
720 buffer[0] = '\0';
722 return hr;
726 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
728 STRRET str;
730 /* SHGDN_FORPARSING: get full path of id list */
731 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
733 if (SUCCEEDED(hr)) {
734 get_strretW(&str, &pidl->mkid, buffer, len);
735 free_strret(&str);
736 } else
737 buffer[0] = '\0';
739 return hr;
743 /* create an item id list from a file system path */
745 static LPITEMIDLIST get_path_pidl(LPWSTR path, HWND hwnd)
747 LPITEMIDLIST pidl;
748 HRESULT hr;
749 ULONG len;
750 LPWSTR buffer = path;
752 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
753 if (FAILED(hr))
754 return NULL;
756 return pidl;
760 /* convert an item id list from relative to absolute (=relative to the desktop) format */
762 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
764 if (entry->up && entry->up->etype==ET_SHELL) {
765 LPITEMIDLIST idl = NULL;
767 while (entry->up) {
768 idl = ILCombine(ILClone(entry->pidl), idl);
769 entry = entry->up;
772 return idl;
773 } else if (entry->etype == ET_WINDOWS) {
774 WCHAR path[MAX_PATH];
776 get_path(entry, path);
778 return get_path_pidl(path, hwnd);
779 } else if (entry->pidl)
780 return ILClone(entry->pidl);
782 return NULL;
786 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
788 IExtractIconW* pExtract;
790 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIconW, 0, (LPVOID*)&pExtract))) {
791 WCHAR path[_MAX_PATH];
792 unsigned flags;
793 HICON hicon;
794 int idx;
796 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
797 if (!(flags & GIL_NOTFILENAME)) {
798 if (idx == -1)
799 idx = 0; /* special case for some control panel applications */
801 if ((int)ExtractIconExW(path, idx, 0, &hicon, 1) > 0)
802 flags &= ~GIL_DONTCACHE;
803 } else {
804 HICON hIconLarge = 0;
806 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
808 if (SUCCEEDED(hr))
809 DestroyIcon(hIconLarge);
812 return hicon;
816 return 0;
820 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
822 Entry* entry;
824 for(entry=dir->down; entry; entry=entry->next) {
825 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
826 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
827 return entry;
830 return 0;
833 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
835 Entry* entry = &root->entry;
836 Entry* next;
837 LPITEMIDLIST next_pidl = pidl;
838 IShellFolder* folder;
839 IShellFolder* child = NULL;
840 HRESULT hr;
842 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
844 #ifndef _NO_EXTENSIONS
845 entry->etype = ET_SHELL;
846 #endif
848 folder = Globals.iDesktop;
850 while(entry) {
851 entry->pidl = next_pidl;
852 entry->folder = folder;
854 if (!pidl->mkid.cb)
855 break;
857 /* copy first element of item idlist */
858 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
859 memcpy(next_pidl, pidl, pidl->mkid.cb);
860 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
862 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
863 if (FAILED(hr))
864 break;
866 read_directory(entry, NULL, sortOrder, hwnd);
868 if (entry->down)
869 entry->expanded = TRUE;
871 next = find_entry_shell(entry, next_pidl);
872 if (!next)
873 break;
875 folder = child;
876 entry = next;
878 /* go to next element */
879 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
882 SetCursor(old_cursor);
884 return entry;
888 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATAW* w32fdata)
890 if (!(attribs & SFGAO_FILESYSTEM) ||
891 FAILED(SHGetDataFromIDListW(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATAW)))) {
892 WIN32_FILE_ATTRIBUTE_DATA fad;
893 IDataObject* pDataObj;
895 STGMEDIUM medium = {0, {0}, 0};
896 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
898 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
900 if (SUCCEEDED(hr)) {
901 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
903 IDataObject_Release(pDataObj);
905 if (SUCCEEDED(hr)) {
906 LPCWSTR path = GlobalLock(medium.UNION_MEMBER(hGlobal));
907 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
909 if (GetFileAttributesExW(path, GetFileExInfoStandard, &fad)) {
910 w32fdata->dwFileAttributes = fad.dwFileAttributes;
911 w32fdata->ftCreationTime = fad.ftCreationTime;
912 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
913 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
915 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
916 w32fdata->nFileSizeLow = fad.nFileSizeLow;
917 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
921 SetErrorMode(sem_org);
923 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
924 GlobalFree(medium.UNION_MEMBER(hGlobal));
929 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
930 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
932 if (attribs & SFGAO_READONLY)
933 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
935 if (attribs & SFGAO_COMPRESSED)
936 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
940 static void read_directory_shell(Entry* dir, HWND hwnd)
942 IShellFolder* folder = dir->folder;
943 int level = dir->level + 1;
944 HRESULT hr;
946 IShellFolder* child;
947 IEnumIDList* idlist;
949 Entry* first_entry = NULL;
950 Entry* last = NULL;
951 Entry* entry;
953 if (!folder)
954 return;
956 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
958 if (SUCCEEDED(hr)) {
959 for(;;) {
960 #define FETCH_ITEM_COUNT 32
961 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
962 SFGAOF attribs;
963 ULONG cnt = 0;
964 ULONG n;
966 memset(pidls, 0, sizeof(pidls));
968 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
969 if (FAILED(hr))
970 break;
972 if (hr == S_FALSE)
973 break;
975 for(n=0; n<cnt; ++n) {
976 entry = alloc_entry();
978 if (!first_entry)
979 first_entry = entry;
981 if (last)
982 last->next = entry;
984 memset(&entry->data, 0, sizeof(WIN32_FIND_DATAW));
985 entry->bhfi_valid = FALSE;
987 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
989 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
991 if (SUCCEEDED(hr)) {
992 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
993 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
995 entry->bhfi_valid = TRUE;
996 } else
997 attribs = 0;
998 } else
999 attribs = 0;
1001 entry->pidl = pidls[n];
1003 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1004 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
1006 if (SUCCEEDED(hr))
1007 entry->folder = child;
1008 else
1009 entry->folder = NULL;
1011 else
1012 entry->folder = NULL;
1014 if (!entry->data.cFileName[0])
1015 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
1017 /* get display icons for files and virtual objects */
1018 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1019 !(attribs & SFGAO_FILESYSTEM)) {
1020 entry->hicon = extract_icon(folder, pidls[n]);
1022 if (!entry->hicon)
1023 entry->hicon = (HICON)-1; /* don't try again later */
1026 entry->down = NULL;
1027 entry->up = dir;
1028 entry->expanded = FALSE;
1029 entry->scanned = FALSE;
1030 entry->level = level;
1032 #ifndef _NO_EXTENSIONS
1033 entry->etype = ET_SHELL;
1034 entry->bhfi_valid = FALSE;
1035 #endif
1037 last = entry;
1041 IEnumIDList_Release(idlist);
1044 if (last)
1045 last->next = NULL;
1047 dir->down = first_entry;
1048 dir->scanned = TRUE;
1051 #endif /* _SHELL_FOLDERS */
1054 /* sort order for different directory/file types */
1055 enum TYPE_ORDER {
1056 TO_DIR = 0,
1057 TO_DOT = 1,
1058 TO_DOTDOT = 2,
1059 TO_OTHER_DIR = 3,
1060 TO_FILE = 4
1063 /* distinguish between ".", ".." and any other directory names */
1064 static int TypeOrderFromDirname(LPCWSTR name)
1066 if (name[0] == '.') {
1067 if (name[1] == '\0')
1068 return TO_DOT; /* "." */
1070 if (name[1]=='.' && name[2]=='\0')
1071 return TO_DOTDOT; /* ".." */
1074 return TO_OTHER_DIR; /* anything else */
1077 /* directories first... */
1078 static int compareType(const WIN32_FIND_DATAW* fd1, const WIN32_FIND_DATAW* fd2)
1080 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1081 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
1083 /* Handle "." and ".." as special case and move them at the very first beginning. */
1084 if (order1==TO_DIR && order2==TO_DIR) {
1085 order1 = TypeOrderFromDirname(fd1->cFileName);
1086 order2 = TypeOrderFromDirname(fd2->cFileName);
1089 return order2==order1? 0: order1<order2? -1: 1;
1093 static int compareName(const void* arg1, const void* arg2)
1095 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1096 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1098 int cmp = compareType(fd1, fd2);
1099 if (cmp)
1100 return cmp;
1102 return lstrcmpiW(fd1->cFileName, fd2->cFileName);
1105 static int compareExt(const void* arg1, const void* arg2)
1107 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1108 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1109 const WCHAR *name1, *name2, *ext1, *ext2;
1111 int cmp = compareType(fd1, fd2);
1112 if (cmp)
1113 return cmp;
1115 name1 = fd1->cFileName;
1116 name2 = fd2->cFileName;
1118 ext1 = strrchrW(name1, '.');
1119 ext2 = strrchrW(name2, '.');
1121 if (ext1)
1122 ext1++;
1123 else
1124 ext1 = sEmpty;
1126 if (ext2)
1127 ext2++;
1128 else
1129 ext2 = sEmpty;
1131 cmp = lstrcmpiW(ext1, ext2);
1132 if (cmp)
1133 return cmp;
1135 return lstrcmpiW(name1, name2);
1138 static int compareSize(const void* arg1, const void* arg2)
1140 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1141 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1143 int cmp = compareType(fd1, fd2);
1144 if (cmp)
1145 return cmp;
1147 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
1149 if (cmp < 0)
1150 return -1;
1151 else if (cmp > 0)
1152 return 1;
1154 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
1156 return cmp<0? -1: cmp>0? 1: 0;
1159 static int compareDate(const void* arg1, const void* arg2)
1161 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
1162 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
1164 int cmp = compareType(fd1, fd2);
1165 if (cmp)
1166 return cmp;
1168 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
1172 static int (*sortFunctions[])(const void* arg1, const void* arg2) = {
1173 compareName, /* SORT_NAME */
1174 compareExt, /* SORT_EXT */
1175 compareSize, /* SORT_SIZE */
1176 compareDate /* SORT_DATE */
1180 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
1182 Entry* entry;
1183 Entry** array, **p;
1184 int len;
1186 len = 0;
1187 for(entry=dir->down; entry; entry=entry->next)
1188 len++;
1190 if (len) {
1191 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
1193 p = array;
1194 for(entry=dir->down; entry; entry=entry->next)
1195 *p++ = entry;
1197 /* call qsort with the appropriate compare function */
1198 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
1200 dir->down = array[0];
1202 for(p=array; --len; p++)
1203 p[0]->next = p[1];
1205 (*p)->next = 0;
1207 HeapFree(GetProcessHeap(), 0, array);
1212 static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
1214 WCHAR buffer[MAX_PATH];
1215 Entry* entry;
1216 LPCWSTR s;
1217 PWSTR d;
1219 #ifdef _SHELL_FOLDERS
1220 if (dir->etype == ET_SHELL)
1222 read_directory_shell(dir, hwnd);
1224 if (Globals.prescan_node) {
1225 s = path;
1226 d = buffer;
1228 while(*s)
1229 *d++ = *s++;
1231 *d++ = '\\';
1233 for(entry=dir->down; entry; entry=entry->next)
1234 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1235 read_directory_shell(entry, hwnd);
1236 SortDirectory(entry, sortOrder);
1240 else
1241 #endif
1242 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1243 if (dir->etype == ET_UNIX)
1245 read_directory_unix(dir, path);
1247 if (Globals.prescan_node) {
1248 s = path;
1249 d = buffer;
1251 while(*s)
1252 *d++ = *s++;
1254 *d++ = '/';
1256 for(entry=dir->down; entry; entry=entry->next)
1257 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1258 lstrcpyW(d, entry->data.cFileName);
1259 read_directory_unix(entry, buffer);
1260 SortDirectory(entry, sortOrder);
1264 else
1265 #endif
1267 read_directory_win(dir, path);
1269 if (Globals.prescan_node) {
1270 s = path;
1271 d = buffer;
1273 while(*s)
1274 *d++ = *s++;
1276 *d++ = '\\';
1278 for(entry=dir->down; entry; entry=entry->next)
1279 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1280 lstrcpyW(d, entry->data.cFileName);
1281 read_directory_win(entry, buffer);
1282 SortDirectory(entry, sortOrder);
1287 SortDirectory(dir, sortOrder);
1291 static Entry* read_tree(Root* root, LPCWSTR path, LPITEMIDLIST pidl, LPWSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1293 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1294 static const WCHAR sSlash[] = {'/', '\0'};
1295 #endif
1296 static const WCHAR sBackslash[] = {'\\', '\0'};
1298 #ifdef _SHELL_FOLDERS
1299 if (pidl)
1301 /* read shell namespace tree */
1302 root->drive_type = DRIVE_UNKNOWN;
1303 drv[0] = '\\';
1304 drv[1] = '\0';
1305 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_DESKTOP);
1306 root->fs_flags = 0;
1307 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_SHELL);
1309 return read_tree_shell(root, pidl, sortOrder, hwnd);
1311 else
1312 #endif
1313 #if !defined(_NO_EXTENSIONS) && defined(__WINE__)
1314 if (*path == '/')
1316 /* read unix file system tree */
1317 root->drive_type = GetDriveTypeW(path);
1319 lstrcatW(drv, sSlash);
1320 load_string(root->volname, sizeof(root->volname)/sizeof(root->volname[0]), IDS_ROOT_FS);
1321 root->fs_flags = 0;
1322 load_string(root->fs, sizeof(root->fs)/sizeof(root->fs[0]), IDS_UNIXFS);
1324 lstrcpyW(root->path, sSlash);
1326 return read_tree_unix(root, path, sortOrder, hwnd);
1328 #endif
1330 /* read WIN32 file system tree */
1331 root->drive_type = GetDriveTypeW(path);
1333 lstrcatW(drv, sBackslash);
1334 GetVolumeInformationW(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1336 lstrcpyW(root->path, drv);
1338 return read_tree_win(root, path, sortOrder, hwnd);
1342 /* flags to filter different file types */
1343 enum TYPE_FILTER {
1344 TF_DIRECTORIES = 0x01,
1345 TF_PROGRAMS = 0x02,
1346 TF_DOCUMENTS = 0x04,
1347 TF_OTHERS = 0x08,
1348 TF_HIDDEN = 0x10,
1349 TF_ALL = 0x1F
1353 static ChildWnd* alloc_child_window(LPCWSTR path, LPITEMIDLIST pidl, HWND hwnd)
1355 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1356 WCHAR dir_path[MAX_PATH];
1357 static const WCHAR sAsterics[] = {'*', '\0'};
1358 static const WCHAR sTitleFmt[] = {'%','s',' ','-',' ','%','s','\0'};
1360 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1361 Root* root = &child->root;
1362 Entry* entry;
1364 memset(child, 0, sizeof(ChildWnd));
1366 child->left.treePane = TRUE;
1367 child->left.visible_cols = 0;
1369 child->right.treePane = FALSE;
1370 #ifndef _NO_EXTENSIONS
1371 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1372 #else
1373 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
1374 #endif
1376 child->pos.length = sizeof(WINDOWPLACEMENT);
1377 child->pos.flags = 0;
1378 child->pos.showCmd = SW_SHOWNORMAL;
1379 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1380 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1381 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1382 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1384 child->focus_pane = 0;
1385 child->split_pos = DEFAULT_SPLIT_POS;
1386 child->sortOrder = SORT_NAME;
1387 child->header_wdths_ok = FALSE;
1389 if (path)
1391 lstrcpyW(child->path, path);
1393 _wsplitpath(path, drv, dir, name, ext);
1396 lstrcpyW(child->filter_pattern, sAsterics);
1397 child->filter_flags = TF_ALL;
1399 root->entry.level = 0;
1401 lstrcpyW(dir_path, drv);
1402 lstrcatW(dir_path, dir);
1403 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1405 #ifdef _SHELL_FOLDERS
1406 if (root->entry.etype == ET_SHELL)
1407 load_string(root->entry.data.cFileName, sizeof(root->entry.data.cFileName)/sizeof(root->entry.data.cFileName[0]), IDS_DESKTOP);
1408 else
1409 #endif
1410 wsprintfW(root->entry.data.cFileName, sTitleFmt, drv, root->fs);
1412 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1414 child->left.root = &root->entry;
1415 child->right.root = NULL;
1417 set_curdir(child, entry, 0, hwnd);
1419 return child;
1423 /* free all memory associated with a child window */
1424 static void free_child_window(ChildWnd* child)
1426 free_entries(&child->root.entry);
1427 HeapFree(GetProcessHeap(), 0, child);
1431 /* get full path of specified directory entry */
1432 static void get_path(Entry* dir, PWSTR path)
1434 Entry* entry;
1435 int len = 0;
1436 int level = 0;
1438 #ifdef _SHELL_FOLDERS
1439 if (dir->etype == ET_SHELL)
1441 SFGAOF attribs;
1442 HRESULT hr = S_OK;
1444 path[0] = '\0';
1446 attribs = 0;
1448 if (dir->folder)
1449 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1451 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1452 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1454 hr = path_from_pidlW(parent, dir->pidl, path, MAX_PATH);
1457 else
1458 #endif
1460 for(entry=dir; entry; level++) {
1461 LPCWSTR name;
1462 int l;
1465 LPCWSTR s;
1466 name = entry->data.cFileName;
1467 s = name;
1469 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1470 l++;
1473 if (entry->up) {
1474 if (l > 0) {
1475 memmove(path+l+1, path, len*sizeof(WCHAR));
1476 memcpy(path+1, name, l*sizeof(WCHAR));
1477 len += l+1;
1479 #ifndef _NO_EXTENSIONS
1480 if (entry->etype == ET_UNIX)
1481 path[0] = '/';
1482 else
1483 #endif
1484 path[0] = '\\';
1487 entry = entry->up;
1488 } else {
1489 memmove(path+l, path, len*sizeof(WCHAR));
1490 memcpy(path, name, l*sizeof(WCHAR));
1491 len += l;
1492 break;
1496 if (!level) {
1497 #ifndef _NO_EXTENSIONS
1498 if (entry->etype == ET_UNIX)
1499 path[len++] = '/';
1500 else
1501 #endif
1502 path[len++] = '\\';
1505 path[len] = '\0';
1509 static windowOptions load_registry_settings(void)
1511 DWORD size;
1512 DWORD type;
1513 HKEY hKey;
1514 windowOptions opts;
1515 LOGFONTW logfont;
1517 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1518 0, KEY_QUERY_VALUE, &hKey );
1520 size = sizeof(DWORD);
1522 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1523 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1524 opts.start_x = CW_USEDEFAULT;
1526 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1527 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1528 opts.start_y = CW_USEDEFAULT;
1530 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1531 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1532 opts.width = CW_USEDEFAULT;
1534 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1535 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1536 opts.height = CW_USEDEFAULT;
1537 size=sizeof(logfont);
1538 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1539 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1540 GetObjectW(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1542 RegCloseKey( hKey );
1544 Globals.hfont = CreateFontIndirectW(&logfont);
1545 return opts;
1548 static void save_registry_settings(void)
1550 WINDOWINFO wi;
1551 HKEY hKey;
1552 INT width, height;
1553 LOGFONTW logfont;
1555 wi.cbSize = sizeof( WINDOWINFO );
1556 GetWindowInfo(Globals.hMainWnd, &wi);
1557 width = wi.rcWindow.right - wi.rcWindow.left;
1558 height = wi.rcWindow.bottom - wi.rcWindow.top;
1560 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1561 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1563 /* Unable to save registry settings - try to create key */
1564 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1565 0, NULL, REG_OPTION_NON_VOLATILE,
1566 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1568 /* FIXME: Cannot create key */
1569 return;
1572 /* Save all of the settings */
1573 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1574 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1575 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1576 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1577 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1578 (LPBYTE) &width, sizeof(DWORD) );
1579 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1580 (LPBYTE) &height, sizeof(DWORD) );
1581 GetObjectW(Globals.hfont, sizeof(logfont), &logfont);
1582 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1583 (LPBYTE)&logfont, sizeof(LOGFONTW) );
1585 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1586 RegCloseKey( hKey );
1589 static void resize_frame_rect(HWND hwnd, PRECT prect)
1591 int new_top;
1592 RECT rt;
1594 if (IsWindowVisible(Globals.htoolbar)) {
1595 SendMessageW(Globals.htoolbar, WM_SIZE, 0, 0);
1596 GetClientRect(Globals.htoolbar, &rt);
1597 prect->top = rt.bottom+3;
1598 prect->bottom -= rt.bottom+3;
1601 if (IsWindowVisible(Globals.hdrivebar)) {
1602 SendMessageW(Globals.hdrivebar, WM_SIZE, 0, 0);
1603 GetClientRect(Globals.hdrivebar, &rt);
1604 new_top = --prect->top + rt.bottom+3;
1605 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1606 prect->top = new_top;
1607 prect->bottom -= rt.bottom+2;
1610 if (IsWindowVisible(Globals.hstatusbar)) {
1611 int parts[] = {300, 500};
1613 SendMessageW(Globals.hstatusbar, WM_SIZE, 0, 0);
1614 SendMessageW(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1615 GetClientRect(Globals.hstatusbar, &rt);
1616 prect->bottom -= rt.bottom;
1619 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1622 static void resize_frame(HWND hwnd, int cx, int cy)
1624 RECT rect;
1626 rect.left = 0;
1627 rect.top = 0;
1628 rect.right = cx;
1629 rect.bottom = cy;
1631 resize_frame_rect(hwnd, &rect);
1634 static void resize_frame_client(HWND hwnd)
1636 RECT rect;
1638 GetClientRect(hwnd, &rect);
1640 resize_frame_rect(hwnd, &rect);
1644 static HHOOK hcbthook;
1645 static ChildWnd* newchild = NULL;
1647 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1649 if (code==HCBT_CREATEWND && newchild) {
1650 ChildWnd* child = newchild;
1651 newchild = NULL;
1653 child->hwnd = (HWND) wparam;
1654 SetWindowLongPtrW(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1657 return CallNextHookEx(hcbthook, code, wparam, lparam);
1660 static HWND create_child_window(ChildWnd* child)
1662 MDICREATESTRUCTW mcs;
1663 int idx;
1665 mcs.szClass = sWINEFILETREE;
1666 mcs.szTitle = child->path;
1667 mcs.hOwner = Globals.hInstance;
1668 mcs.x = child->pos.rcNormalPosition.left;
1669 mcs.y = child->pos.rcNormalPosition.top;
1670 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1671 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1672 mcs.style = 0;
1673 mcs.lParam = 0;
1675 hcbthook = SetWindowsHookExW(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1677 newchild = child;
1678 child->hwnd = (HWND)SendMessageW(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1679 if (!child->hwnd) {
1680 UnhookWindowsHookEx(hcbthook);
1681 return 0;
1684 UnhookWindowsHookEx(hcbthook);
1686 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1687 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1689 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1690 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
1692 return child->hwnd;
1695 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1697 static void WineFile_OnRun( HWND hwnd )
1699 static const WCHAR shell32_dll[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1700 void (WINAPI *pRunFileDlgAW )(HWND, HICON, LPWSTR, LPWSTR, LPWSTR, DWORD);
1701 HMODULE hshell = GetModuleHandleW( shell32_dll );
1703 pRunFileDlgAW = (void*)GetProcAddress(hshell, (LPCSTR)61);
1704 if (pRunFileDlgAW) pRunFileDlgAW( hwnd, 0, NULL, NULL, NULL, RFF_NODEFAULT);
1707 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1709 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1711 switch(nmsg) {
1712 case WM_INITDIALOG:
1713 SetWindowLongPtrW(hwnd, GWLP_USERDATA, lparam);
1714 SetWindowTextW(GetDlgItem(hwnd, 201), (LPCWSTR)lparam);
1715 return 1;
1717 case WM_COMMAND: {
1718 int id = (int)wparam;
1720 switch(id) {
1721 case IDOK: {
1722 LPWSTR dest = (LPWSTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
1723 GetWindowTextW(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1724 EndDialog(hwnd, id);
1725 break;}
1727 case IDCANCEL:
1728 EndDialog(hwnd, id);
1729 break;
1731 case 254:
1732 MessageBoxW(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1733 break;
1736 return 1;
1740 return 0;
1744 struct FilterDialog {
1745 WCHAR pattern[MAX_PATH];
1746 int flags;
1749 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1751 static struct FilterDialog* dlg;
1753 switch(nmsg) {
1754 case WM_INITDIALOG:
1755 dlg = (struct FilterDialog*) lparam;
1756 SetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1757 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1758 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1759 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1760 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1761 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1762 return 1;
1764 case WM_COMMAND: {
1765 int id = (int)wparam;
1767 if (id == IDOK) {
1768 int flags = 0;
1770 GetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1772 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1773 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1774 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1775 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1776 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1778 dlg->flags = flags;
1780 EndDialog(hwnd, id);
1781 } else if (id == IDCANCEL)
1782 EndDialog(hwnd, id);
1784 return 1;}
1787 return 0;
1791 struct PropertiesDialog {
1792 WCHAR path[MAX_PATH];
1793 Entry entry;
1794 void* pVersionData;
1797 /* Structure used to store enumerated languages and code pages. */
1798 struct LANGANDCODEPAGE {
1799 WORD wLanguage;
1800 WORD wCodePage;
1801 } *lpTranslate;
1803 static LPCSTR InfoStrings[] = {
1804 "Comments",
1805 "CompanyName",
1806 "FileDescription",
1807 "FileVersion",
1808 "InternalName",
1809 "LegalCopyright",
1810 "LegalTrademarks",
1811 "OriginalFilename",
1812 "PrivateBuild",
1813 "ProductName",
1814 "ProductVersion",
1815 "SpecialBuild",
1816 NULL
1819 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1821 int idx = SendMessageW(hlbox, LB_GETCURSEL, 0, 0);
1823 if (idx != LB_ERR) {
1824 LPCWSTR pValue = (LPCWSTR)SendMessageW(hlbox, LB_GETITEMDATA, idx, 0);
1826 if (pValue)
1827 SetWindowTextW(hedit, pValue);
1831 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCWSTR strFilename)
1833 static WCHAR sBackSlash[] = {'\\','\0'};
1834 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'};
1835 static WCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1836 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1837 DWORD dwVersionDataLen = GetFileVersionInfoSizeW(strFilename, NULL);
1839 if (dwVersionDataLen) {
1840 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1842 if (GetFileVersionInfoW(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1843 LPVOID pVal;
1844 UINT nValLen;
1846 if (VerQueryValueW(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1847 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1848 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1849 char buffer[BUFFER_LEN];
1851 sprintf(buffer, "%d.%d.%d.%d",
1852 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1853 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1855 SetDlgItemTextA(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1859 /* Read the list of languages and code pages. */
1860 if (VerQueryValueW(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1861 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1862 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1864 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1866 /* Read the file description for each language and code page. */
1867 for(; pTranslate<pEnd; ++pTranslate) {
1868 LPCSTR* p;
1870 for(p=InfoStrings; *p; ++p) {
1871 WCHAR subblock[200];
1872 WCHAR infoStr[100];
1873 LPCWSTR pTxt;
1874 UINT nValLen;
1876 LPCSTR pInfoString = *p;
1877 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1878 wsprintfW(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1880 /* Retrieve file description for language and code page */
1881 if (VerQueryValueW(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1882 int idx = SendMessageW(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
1883 SendMessageW(hlbox, LB_SETITEMDATA, idx, (LPARAM)pTxt);
1888 SendMessageW(hlbox, LB_SETCURSEL, 0, 0);
1890 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1896 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1898 static struct PropertiesDialog* dlg;
1900 switch(nmsg) {
1901 case WM_INITDIALOG: {
1902 static const WCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1903 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1904 LPWIN32_FIND_DATAW pWFD;
1906 dlg = (struct PropertiesDialog*) lparam;
1907 pWFD = (LPWIN32_FIND_DATAW)&dlg->entry.data;
1909 GetWindowTextW(hwnd, b1, MAX_PATH);
1910 wsprintfW(b2, b1, pWFD->cFileName);
1911 SetWindowTextW(hwnd, b2);
1913 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1914 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1916 format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
1917 wsprintfW(b2, sByteFmt, b1);
1918 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1920 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1921 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1923 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
1924 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
1925 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
1926 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
1927 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
1929 CheckForFileInfo(dlg, hwnd, dlg->path);
1930 return 1;}
1932 case WM_COMMAND: {
1933 int id = (int)wparam;
1935 switch(HIWORD(wparam)) {
1936 case LBN_SELCHANGE: {
1937 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1938 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1939 break;
1942 case BN_CLICKED:
1943 if (id==IDOK || id==IDCANCEL)
1944 EndDialog(hwnd, id);
1947 return 1;}
1949 case WM_NCDESTROY:
1950 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
1951 dlg->pVersionData = NULL;
1952 break;
1955 return 0;
1958 static void show_properties_dlg(Entry* entry, HWND hwnd)
1960 struct PropertiesDialog dlg;
1962 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1963 get_path(entry, dlg.path);
1964 memcpy(&dlg.entry, entry, sizeof(Entry));
1966 DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1970 #ifndef _NO_EXTENSIONS
1972 static struct FullScreenParameters {
1973 BOOL mode;
1974 RECT orgPos;
1975 BOOL wasZoomed;
1976 } g_fullscreen = {
1977 FALSE, /* mode */
1978 {0, 0, 0, 0},
1979 FALSE
1982 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1984 RECT rt;
1986 if (!IsIconic(hwnd))
1987 GetClientRect(hwnd, prect);
1988 else {
1989 WINDOWPLACEMENT wp;
1991 GetWindowPlacement(hwnd, &wp);
1993 prect->left = prect->top = 0;
1994 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1995 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1996 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1997 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1998 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
2001 if (IsWindowVisible(Globals.htoolbar)) {
2002 GetClientRect(Globals.htoolbar, &rt);
2003 prect->top += rt.bottom+2;
2006 if (IsWindowVisible(Globals.hdrivebar)) {
2007 GetClientRect(Globals.hdrivebar, &rt);
2008 prect->top += rt.bottom+2;
2011 if (IsWindowVisible(Globals.hstatusbar)) {
2012 GetClientRect(Globals.hstatusbar, &rt);
2013 prect->bottom -= rt.bottom;
2017 static BOOL toggle_fullscreen(HWND hwnd)
2019 RECT rt;
2021 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
2022 GetWindowRect(hwnd, &g_fullscreen.orgPos);
2023 g_fullscreen.wasZoomed = IsZoomed(hwnd);
2025 Frame_CalcFrameClient(hwnd, &rt);
2026 MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
2028 rt.left = g_fullscreen.orgPos.left-rt.left;
2029 rt.top = g_fullscreen.orgPos.top-rt.top;
2030 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
2031 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
2033 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2034 } else {
2035 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
2036 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
2037 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
2039 if (g_fullscreen.wasZoomed)
2040 ShowWindow(hwnd, WS_MAXIMIZE);
2043 return g_fullscreen.mode;
2046 static void fullscreen_move(HWND hwnd)
2048 RECT rt, pos;
2049 GetWindowRect(hwnd, &pos);
2051 Frame_CalcFrameClient(hwnd, &rt);
2052 MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
2054 rt.left = pos.left-rt.left;
2055 rt.top = pos.top-rt.top;
2056 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
2057 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
2059 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
2062 #endif
2065 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
2067 BOOL vis = IsWindowVisible(hchild);
2069 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
2071 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
2073 #ifndef _NO_EXTENSIONS
2074 if (g_fullscreen.mode)
2075 fullscreen_move(hwnd);
2076 #endif
2078 resize_frame_client(hwnd);
2081 static BOOL activate_drive_window(LPCWSTR path)
2083 WCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
2084 HWND child_wnd;
2086 _wsplitpath(path, drv1, 0, 0, 0);
2088 /* search for a already open window for the same drive */
2089 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2090 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
2092 if (child) {
2093 _wsplitpath(child->root.path, drv2, 0, 0, 0);
2095 if (!lstrcmpiW(drv2, drv1)) {
2096 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2098 if (IsIconic(child_wnd))
2099 ShowWindow(child_wnd, SW_SHOWNORMAL);
2101 return TRUE;
2106 return FALSE;
2109 #ifndef _NO_EXTENSIONS
2110 static BOOL activate_fs_window(LPCWSTR filesys)
2112 HWND child_wnd;
2114 /* search for a already open window of the given file system name */
2115 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
2116 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
2118 if (child) {
2119 if (!lstrcmpiW(child->root.fs, filesys)) {
2120 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
2122 if (IsIconic(child_wnd))
2123 ShowWindow(child_wnd, SW_SHOWNORMAL);
2125 return TRUE;
2130 return FALSE;
2132 #endif /* _NO_EXTENSIONS */
2134 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
2136 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2138 switch(nmsg) {
2139 case WM_CLOSE:
2140 if (Globals.saveSettings)
2141 save_registry_settings();
2143 DestroyWindow(hwnd);
2145 /* clear handle variables */
2146 Globals.hMenuFrame = 0;
2147 Globals.hMenuView = 0;
2148 Globals.hMenuOptions = 0;
2149 Globals.hMainWnd = 0;
2150 Globals.hmdiclient = 0;
2151 Globals.hdrivebar = 0;
2152 break;
2154 case WM_DESTROY:
2155 PostQuitMessage(0);
2156 break;
2158 case WM_INITMENUPOPUP: {
2159 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2161 if (!SendMessageW(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
2162 return 0;
2163 break;}
2165 case WM_COMMAND: {
2166 UINT cmd = LOWORD(wparam);
2167 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
2169 if (SendMessageW(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
2170 break;
2172 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
2173 WCHAR drv[_MAX_DRIVE], path[MAX_PATH];
2174 ChildWnd* child;
2175 LPCWSTR root = Globals.drives;
2176 int i;
2178 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
2179 while(*root)
2180 root++;
2182 if (activate_drive_window(root))
2183 return 0;
2185 _wsplitpath(root, drv, 0, 0, 0);
2187 if (!SetCurrentDirectoryW(drv)) {
2188 display_error(hwnd, GetLastError());
2189 return 0;
2192 GetCurrentDirectoryW(MAX_PATH, path); /*TODO: store last directory per drive */
2193 child = alloc_child_window(path, NULL, hwnd);
2195 if (!create_child_window(child))
2196 HeapFree(GetProcessHeap(), 0, child);
2197 } else switch(cmd) {
2198 case ID_FILE_EXIT:
2199 SendMessageW(hwnd, WM_CLOSE, 0, 0);
2200 break;
2202 case ID_WINDOW_NEW: {
2203 WCHAR path[MAX_PATH];
2204 ChildWnd* child;
2206 GetCurrentDirectoryW(MAX_PATH, path);
2207 child = alloc_child_window(path, NULL, hwnd);
2209 if (!create_child_window(child))
2210 HeapFree(GetProcessHeap(), 0, child);
2211 break;}
2213 case ID_REFRESH:
2214 refresh_drives();
2215 break;
2217 case ID_WINDOW_CASCADE:
2218 SendMessageW(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
2219 break;
2221 case ID_WINDOW_TILE_HORZ:
2222 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
2223 break;
2225 case ID_WINDOW_TILE_VERT:
2226 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
2227 break;
2229 case ID_WINDOW_ARRANGE:
2230 SendMessageW(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
2231 break;
2233 case ID_SELECT_FONT:
2234 choose_font(hwnd);
2235 break;
2237 case ID_VIEW_TOOL_BAR:
2238 toggle_child(hwnd, cmd, Globals.htoolbar);
2239 break;
2241 case ID_VIEW_DRIVE_BAR:
2242 toggle_child(hwnd, cmd, Globals.hdrivebar);
2243 break;
2245 case ID_VIEW_STATUSBAR:
2246 toggle_child(hwnd, cmd, Globals.hstatusbar);
2247 break;
2249 case ID_VIEW_SAVESETTINGS:
2250 Globals.saveSettings = !Globals.saveSettings;
2251 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
2252 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
2253 break;
2255 case ID_RUN:
2256 WineFile_OnRun( hwnd );
2257 break;
2259 case ID_CONNECT_NETWORK_DRIVE: {
2260 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
2261 if (ret == NO_ERROR)
2262 refresh_drives();
2263 else if (ret != (DWORD)-1) {
2264 if (ret == ERROR_EXTENDED_ERROR)
2265 display_network_error(hwnd);
2266 else
2267 display_error(hwnd, ret);
2269 break;}
2271 case ID_DISCONNECT_NETWORK_DRIVE: {
2272 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
2273 if (ret == NO_ERROR)
2274 refresh_drives();
2275 else if (ret != (DWORD)-1) {
2276 if (ret == ERROR_EXTENDED_ERROR)
2277 display_network_error(hwnd);
2278 else
2279 display_error(hwnd, ret);
2281 break;}
2283 case ID_HELP:
2284 WinHelpW(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
2285 break;
2287 #ifndef _NO_EXTENSIONS
2288 case ID_VIEW_FULLSCREEN:
2289 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
2290 break;
2292 #ifdef __WINE__
2293 case ID_DRIVE_UNIX_FS: {
2294 WCHAR path[MAX_PATH];
2295 char cpath[MAX_PATH];
2296 ChildWnd* child;
2298 if (activate_fs_window(RS(b1,IDS_UNIXFS)))
2299 break;
2301 getcwd(cpath, MAX_PATH);
2302 MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH);
2303 child = alloc_child_window(path, NULL, hwnd);
2305 if (!create_child_window(child))
2306 HeapFree(GetProcessHeap(), 0, child);
2307 break;}
2308 #endif
2309 #ifdef _SHELL_FOLDERS
2310 case ID_DRIVE_SHELL_NS: {
2311 WCHAR path[MAX_PATH];
2312 ChildWnd* child;
2314 if (activate_fs_window(RS(b1,IDS_SHELL)))
2315 break;
2317 GetCurrentDirectoryW(MAX_PATH, path);
2318 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
2320 if (!create_child_window(child))
2321 HeapFree(GetProcessHeap(), 0, child);
2322 break;}
2323 #endif
2324 #endif
2326 /*TODO: There are even more menu items! */
2328 case ID_ABOUT:
2329 ShellAboutW(hwnd, RS(b1,IDS_WINEFILE), NULL,
2330 LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE),
2331 IMAGE_ICON, 48, 48, LR_SHARED ));
2332 break;
2334 default:
2335 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2336 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2337 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2338 (cmd<SC_SIZE || cmd>SC_RESTORE))
2339 MessageBoxW(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2341 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2343 break;}
2345 case WM_SIZE:
2346 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2347 break; /* do not pass message to DefFrameProcW */
2349 case WM_DEVICECHANGE:
2350 SendMessageW(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2351 break;
2353 #ifndef _NO_EXTENSIONS
2354 case WM_GETMINMAXINFO: {
2355 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2357 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2358 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2359 break;}
2361 case FRM_CALC_CLIENT:
2362 frame_get_clientspace(hwnd, (PRECT)lparam);
2363 return TRUE;
2364 #endif /* _NO_EXTENSIONS */
2366 default:
2367 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2370 return 0;
2374 static WCHAR g_pos_names[COLUMNS][20] = {
2375 {'\0'} /* symbol */
2378 static const int g_pos_align[] = {
2380 HDF_LEFT, /* Name */
2381 HDF_RIGHT, /* Size */
2382 HDF_LEFT, /* CDate */
2383 #ifndef _NO_EXTENSIONS
2384 HDF_LEFT, /* ADate */
2385 HDF_LEFT, /* MDate */
2386 HDF_LEFT, /* Index */
2387 HDF_CENTER, /* Links */
2388 #endif
2389 HDF_CENTER, /* Attributes */
2390 #ifndef _NO_EXTENSIONS
2391 HDF_LEFT /* Security */
2392 #endif
2395 static void resize_tree(ChildWnd* child, int cx, int cy)
2397 HDWP hdwp = BeginDeferWindowPos(4);
2398 RECT rt;
2400 rt.left = 0;
2401 rt.top = 0;
2402 rt.right = cx;
2403 rt.bottom = cy;
2405 cx = child->split_pos + SPLIT_WIDTH/2;
2407 #ifndef _NO_EXTENSIONS
2409 WINDOWPOS wp;
2410 HD_LAYOUT hdl;
2412 hdl.prc = &rt;
2413 hdl.pwpos = &wp;
2415 SendMessageW(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2417 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2418 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2419 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2420 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2422 #endif /* _NO_EXTENSIONS */
2424 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);
2425 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2427 EndDeferWindowPos(hdwp);
2431 #ifndef _NO_EXTENSIONS
2433 static HWND create_header(HWND parent, Pane* pane, UINT id)
2435 HDITEMW hdi;
2436 int idx;
2438 HWND hwnd = CreateWindowW(WC_HEADERW, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2439 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2440 if (!hwnd)
2441 return 0;
2443 SendMessageW(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2445 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2447 for(idx=0; idx<COLUMNS; idx++) {
2448 hdi.pszText = g_pos_names[idx];
2449 hdi.fmt = HDF_STRING | g_pos_align[idx];
2450 hdi.cxy = pane->widths[idx];
2451 SendMessageW(hwnd, HDM_INSERTITEMW, idx, (LPARAM)&hdi);
2454 return hwnd;
2457 #endif /* _NO_EXTENSIONS */
2460 static void init_output(HWND hwnd)
2462 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2463 WCHAR b[16];
2464 HFONT old_font;
2465 HDC hdc = GetDC(hwnd);
2467 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2468 Globals.num_sep = b[1];
2469 else
2470 Globals.num_sep = '.';
2472 old_font = SelectObject(hdc, Globals.hfont);
2473 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2474 SelectObject(hdc, old_font);
2475 ReleaseDC(hwnd, hdc);
2478 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2481 /* calculate preferred width for all visible columns */
2483 static BOOL calc_widths(Pane* pane, BOOL anyway)
2485 int col, x, cx, spc=3*Globals.spaceSize.cx;
2486 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2487 int orgWidths[COLUMNS];
2488 int orgPositions[COLUMNS+1];
2489 HFONT hfontOld;
2490 HDC hdc;
2491 int cnt;
2493 if (!anyway) {
2494 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2495 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2498 for(col=0; col<COLUMNS; col++)
2499 pane->widths[col] = 0;
2501 hdc = GetDC(pane->hwnd);
2502 hfontOld = SelectObject(hdc, Globals.hfont);
2504 for(cnt=0; cnt<entries; cnt++) {
2505 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2507 DRAWITEMSTRUCT dis;
2509 dis.CtlType = 0;
2510 dis.CtlID = 0;
2511 dis.itemID = 0;
2512 dis.itemAction = 0;
2513 dis.itemState = 0;
2514 dis.hwndItem = pane->hwnd;
2515 dis.hDC = hdc;
2516 dis.rcItem.left = 0;
2517 dis.rcItem.top = 0;
2518 dis.rcItem.right = 0;
2519 dis.rcItem.bottom = 0;
2520 /*dis.itemData = 0; */
2522 draw_item(pane, &dis, entry, COLUMNS);
2525 SelectObject(hdc, hfontOld);
2526 ReleaseDC(pane->hwnd, hdc);
2528 x = 0;
2529 for(col=0; col<COLUMNS; col++) {
2530 pane->positions[col] = x;
2531 cx = pane->widths[col];
2533 if (cx) {
2534 cx += spc;
2536 if (cx < IMAGE_WIDTH)
2537 cx = IMAGE_WIDTH;
2539 pane->widths[col] = cx;
2542 x += cx;
2545 pane->positions[COLUMNS] = x;
2547 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2549 /* no change? */
2550 if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2551 return FALSE;
2553 /* don't move, if only collapsing an entry */
2554 if (!anyway && pane->widths[0]<orgWidths[0] &&
2555 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2556 pane->widths[0] = orgWidths[0];
2557 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2559 return FALSE;
2562 InvalidateRect(pane->hwnd, 0, TRUE);
2564 return TRUE;
2568 #ifndef _NO_EXTENSIONS
2569 /* calculate one preferred column width */
2571 static void calc_single_width(Pane* pane, int col)
2573 HFONT hfontOld;
2574 int x, cx;
2575 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2576 int cnt;
2577 HDC hdc;
2579 pane->widths[col] = 0;
2581 hdc = GetDC(pane->hwnd);
2582 hfontOld = SelectObject(hdc, Globals.hfont);
2584 for(cnt=0; cnt<entries; cnt++) {
2585 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2586 DRAWITEMSTRUCT dis;
2588 dis.CtlType = 0;
2589 dis.CtlID = 0;
2590 dis.itemID = 0;
2591 dis.itemAction = 0;
2592 dis.itemState = 0;
2593 dis.hwndItem = pane->hwnd;
2594 dis.hDC = hdc;
2595 dis.rcItem.left = 0;
2596 dis.rcItem.top = 0;
2597 dis.rcItem.right = 0;
2598 dis.rcItem.bottom = 0;
2599 /*dis.itemData = 0; */
2601 draw_item(pane, &dis, entry, col);
2604 SelectObject(hdc, hfontOld);
2605 ReleaseDC(pane->hwnd, hdc);
2607 cx = pane->widths[col];
2609 if (cx) {
2610 cx += 3*Globals.spaceSize.cx;
2612 if (cx < IMAGE_WIDTH)
2613 cx = IMAGE_WIDTH;
2616 pane->widths[col] = cx;
2618 x = pane->positions[col] + cx;
2620 for(; col<COLUMNS-1; ) {
2621 pane->positions[++col] = x;
2622 x += pane->widths[col];
2625 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2627 #endif /* _NO_EXTENSIONS */
2630 static BOOL pattern_match(LPCWSTR str, LPCWSTR pattern)
2632 for( ; *str&&*pattern; str++,pattern++) {
2633 if (*pattern == '*') {
2634 do pattern++;
2635 while(*pattern == '*');
2637 if (!*pattern)
2638 return TRUE;
2640 for(; *str; str++)
2641 if (*str==*pattern && pattern_match(str, pattern))
2642 return TRUE;
2644 return FALSE;
2646 else if (*str!=*pattern && *pattern!='?')
2647 return FALSE;
2650 if (*str || *pattern)
2651 if (*pattern!='*' || pattern[1]!='\0')
2652 return FALSE;
2654 return TRUE;
2657 static BOOL pattern_imatch(LPCWSTR str, LPCWSTR pattern)
2659 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2661 lstrcpyW(b1, str);
2662 lstrcpyW(b2, pattern);
2663 CharUpperW(b1);
2664 CharUpperW(b2);
2666 return pattern_match(b1, b2);
2670 enum FILE_TYPE {
2671 FT_OTHER = 0,
2672 FT_EXECUTABLE = 1,
2673 FT_DOCUMENT = 2
2676 static enum FILE_TYPE get_file_type(LPCWSTR filename);
2679 /* insert listbox entries after index idx */
2681 static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_flags, int idx)
2683 Entry* entry = dir;
2685 if (!entry)
2686 return idx;
2688 ShowWindow(pane->hwnd, SW_HIDE);
2690 for(; entry; entry=entry->next) {
2691 #ifndef _LEFT_FILES
2692 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2693 continue;
2694 #endif
2696 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2697 /* don't display entries "." and ".." in the left pane */
2698 if (pane->treePane && entry->data.cFileName[0] == '.')
2699 if (
2700 #ifndef _NO_EXTENSIONS
2701 entry->data.cFileName[1] == '\0' ||
2702 #endif
2703 (entry->data.cFileName[1] == '.' && entry->data.cFileName[2] == '\0'))
2704 continue;
2706 /* filter directories in right pane */
2707 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2708 continue;
2711 /* filter using the file name pattern */
2712 if (pattern)
2713 if (!pattern_imatch(entry->data.cFileName, pattern))
2714 continue;
2716 /* filter system and hidden files */
2717 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2718 continue;
2720 /* filter looking at the file type */
2721 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2722 switch(get_file_type(entry->data.cFileName)) {
2723 case FT_EXECUTABLE:
2724 if (!(filter_flags & TF_PROGRAMS))
2725 continue;
2726 break;
2728 case FT_DOCUMENT:
2729 if (!(filter_flags & TF_DOCUMENTS))
2730 continue;
2731 break;
2733 default: /* TF_OTHERS */
2734 if (!(filter_flags & TF_OTHERS))
2735 continue;
2738 if (idx != -1)
2739 idx++;
2741 SendMessageW(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM)entry);
2743 if (pane->treePane && entry->expanded)
2744 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2747 ShowWindow(pane->hwnd, SW_SHOW);
2749 return idx;
2753 static void format_bytes(LPWSTR buffer, LONGLONG bytes)
2755 static const WCHAR sFmtSmall[] = {'%', 'u', 0};
2756 static const WCHAR sFmtBig[] = {'%', '.', '1', 'f', ' ', '%', 's', '\0'};
2758 if (bytes < 1024)
2759 sprintfW(buffer, sFmtSmall, (DWORD)bytes);
2760 else
2762 WCHAR unit[64];
2763 UINT resid;
2764 float fBytes;
2765 if (bytes >= 1073741824) /* 1 GB */
2767 fBytes = ((float)bytes)/1073741824.f+.5f;
2768 resid = IDS_UNIT_GB;
2770 else if (bytes >= 1048576) /* 1 MB */
2772 fBytes = ((float)bytes)/1048576.f+.5f;
2773 resid = IDS_UNIT_MB;
2775 else if (bytes >= 1024) /* 1 kB */
2777 fBytes = ((float)bytes)/1024.f+.5f;
2778 resid = IDS_UNIT_KB;
2780 LoadStringW(Globals.hInstance, resid, unit, sizeof(unit)/sizeof(*unit));
2781 sprintfW(buffer, sFmtBig, fBytes, unit);
2785 static void set_space_status(void)
2787 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2788 WCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2790 if (GetDiskFreeSpaceExW(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2791 DWORD_PTR args[2];
2792 format_bytes(b1, ulFreeBytesToCaller.QuadPart);
2793 format_bytes(b2, ulTotalBytes.QuadPart);
2794 args[0] = (DWORD_PTR)b1;
2795 args[1] = (DWORD_PTR)b2;
2796 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
2797 RS(fmt,IDS_FREE_SPACE_FMT), 0, 0, buffer,
2798 sizeof(buffer)/sizeof(*buffer), (__ms_va_list*)args);
2799 } else
2800 lstrcpyW(buffer, sQMarks);
2802 SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
2806 static WNDPROC g_orgTreeWndProc;
2808 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
2810 static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2812 static int s_init = 0;
2813 Entry* entry = pane->root;
2815 pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2816 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2817 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2819 SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2820 g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2822 SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2824 /* insert entries into listbox */
2825 if (entry)
2826 insert_entries(pane, entry, pattern, filter_flags, -1);
2828 /* calculate column widths */
2829 if (!s_init) {
2830 s_init = 1;
2831 init_output(pane->hwnd);
2834 calc_widths(pane, TRUE);
2836 #ifndef _NO_EXTENSIONS
2837 pane->hwndHeader = create_header(parent, pane, id_header);
2838 #endif
2842 static void InitChildWindow(ChildWnd* child)
2844 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2845 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2849 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
2851 SYSTEMTIME systime;
2852 FILETIME lft;
2853 int len = 0;
2855 *buffer = '\0';
2857 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2858 return;
2860 if (!FileTimeToLocalFileTime(ft, &lft))
2861 {err: lstrcpyW(buffer,sQMarks); return;}
2863 if (!FileTimeToSystemTime(&lft, &systime))
2864 goto err;
2866 if (visible_cols & COL_DATE) {
2867 len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2868 if (!len)
2869 goto err;
2872 if (visible_cols & COL_TIME) {
2873 if (len)
2874 buffer[len-1] = ' ';
2876 buffer[len++] = ' ';
2878 if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2879 buffer[len] = '\0';
2884 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2886 RECT rt = {0, 0, 0, 0};
2888 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2890 if (rt.right > pane->widths[col])
2891 pane->widths[col] = rt.right;
2894 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2896 RECT rt = {0, 0, 0, 0};
2898 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2899 /*FIXME rt (0,0) ??? */
2901 if (rt.right > pane->widths[col])
2902 pane->widths[col] = rt.right;
2906 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
2908 int x = dis->rcItem.left;
2909 RECT rt;
2911 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2912 rt.top = dis->rcItem.top;
2913 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2914 rt.bottom = dis->rcItem.bottom;
2916 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2919 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2921 int x = dis->rcItem.left;
2922 RECT rt;
2924 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2925 rt.top = dis->rcItem.top;
2926 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2927 rt.bottom = dis->rcItem.bottom;
2929 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2932 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2934 int x = dis->rcItem.left;
2935 RECT rt;
2936 LPCWSTR s = str;
2937 WCHAR b[128];
2938 LPWSTR d = b;
2939 int pos;
2941 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2942 rt.top = dis->rcItem.top;
2943 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2944 rt.bottom = dis->rcItem.bottom;
2946 if (*s)
2947 *d++ = *s++;
2949 /* insert number separator characters */
2950 pos = lstrlenW(s) % 3;
2952 while(*s)
2953 if (pos--)
2954 *d++ = *s++;
2955 else {
2956 *d++ = Globals.num_sep;
2957 pos = 3;
2960 DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2964 static BOOL is_exe_file(LPCWSTR ext)
2966 static const WCHAR executable_extensions[][4] = {
2967 {'C','O','M','\0'},
2968 {'E','X','E','\0'},
2969 {'B','A','T','\0'},
2970 {'C','M','D','\0'},
2971 #ifndef _NO_EXTENSIONS
2972 {'C','M','M','\0'},
2973 {'B','T','M','\0'},
2974 {'A','W','K','\0'},
2975 #endif /* _NO_EXTENSIONS */
2976 {'\0'}
2979 WCHAR ext_buffer[_MAX_EXT];
2980 const WCHAR (*p)[4];
2981 LPCWSTR s;
2982 LPWSTR d;
2984 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2985 d++;
2987 for(p=executable_extensions; (*p)[0]; p++)
2988 if (!lstrcmpiW(ext_buffer, *p))
2989 return TRUE;
2991 return FALSE;
2994 static BOOL is_registered_type(LPCWSTR ext)
2996 /* check if there exists a classname for this file extension in the registry */
2997 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2998 return TRUE;
3000 return FALSE;
3003 static enum FILE_TYPE get_file_type(LPCWSTR filename)
3005 LPCWSTR ext = strrchrW(filename, '.');
3006 if (!ext)
3007 ext = sEmpty;
3009 if (is_exe_file(ext))
3010 return FT_EXECUTABLE;
3011 else if (is_registered_type(ext))
3012 return FT_DOCUMENT;
3013 else
3014 return FT_OTHER;
3018 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
3020 WCHAR buffer[BUFFER_LEN];
3021 DWORD attrs;
3022 int visible_cols = pane->visible_cols;
3023 COLORREF bkcolor, textcolor;
3024 RECT focusRect = dis->rcItem;
3025 HBRUSH hbrush;
3026 enum IMAGE img;
3027 int img_pos, cx;
3028 int col = 0;
3030 if (entry) {
3031 attrs = entry->data.dwFileAttributes;
3033 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
3034 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
3035 && entry->data.cFileName[2] == '\0')
3036 img = IMG_FOLDER_UP;
3037 #ifndef _NO_EXTENSIONS
3038 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
3039 img = IMG_FOLDER_CUR;
3040 #endif
3041 else if (
3042 #ifdef _NO_EXTENSIONS
3043 entry->expanded ||
3044 #endif
3045 (pane->treePane && (dis->itemState&ODS_FOCUS)))
3046 img = IMG_OPEN_FOLDER;
3047 else
3048 img = IMG_FOLDER;
3049 } else {
3050 switch(get_file_type(entry->data.cFileName)) {
3051 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
3052 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
3053 default: img = IMG_FILE;
3056 } else {
3057 attrs = 0;
3058 img = IMG_NONE;
3061 if (pane->treePane) {
3062 if (entry) {
3063 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
3065 if (calcWidthCol == -1) {
3066 int x;
3067 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
3068 Entry* up;
3069 RECT rt_clip;
3070 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
3071 HRGN hrgn;
3073 rt_clip.left = dis->rcItem.left;
3074 rt_clip.top = dis->rcItem.top;
3075 rt_clip.right = dis->rcItem.left+pane->widths[col];
3076 rt_clip.bottom = dis->rcItem.bottom;
3078 hrgn = CreateRectRgnIndirect(&rt_clip);
3080 if (!GetClipRgn(dis->hDC, hrgn_org)) {
3081 DeleteObject(hrgn_org);
3082 hrgn_org = 0;
3085 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
3086 DeleteObject(hrgn);
3088 if ((up=entry->up) != NULL) {
3089 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
3090 LineTo(dis->hDC, img_pos-2, y);
3092 x = img_pos - IMAGE_WIDTH/2;
3094 do {
3095 x -= IMAGE_WIDTH+TREE_LINE_DX;
3097 if (up->next
3098 #ifndef _LEFT_FILES
3099 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3100 #endif
3102 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3103 LineTo(dis->hDC, x, dis->rcItem.bottom);
3105 } while((up=up->up) != NULL);
3108 x = img_pos - IMAGE_WIDTH/2;
3110 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
3111 LineTo(dis->hDC, x, y);
3113 if (entry->next
3114 #ifndef _LEFT_FILES
3115 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
3116 #endif
3118 LineTo(dis->hDC, x, dis->rcItem.bottom);
3120 SelectClipRgn(dis->hDC, hrgn_org);
3121 if (hrgn_org) DeleteObject(hrgn_org);
3122 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
3123 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
3125 if (right > pane->widths[col])
3126 pane->widths[col] = right;
3128 } else {
3129 img_pos = dis->rcItem.left;
3131 } else {
3132 img_pos = dis->rcItem.left;
3134 if (calcWidthCol==col || calcWidthCol==COLUMNS)
3135 pane->widths[col] = IMAGE_WIDTH;
3138 if (calcWidthCol == -1) {
3139 focusRect.left = img_pos -2;
3141 #ifdef _NO_EXTENSIONS
3142 if (pane->treePane && entry) {
3143 RECT rt = {0};
3145 DrawTextW(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
3147 focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2;
3149 #else
3151 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
3152 textcolor = COLOR_COMPRESSED;
3153 else
3154 #endif /* _NO_EXTENSIONS */
3155 textcolor = RGB(0,0,0);
3157 if (dis->itemState & ODS_FOCUS) {
3158 textcolor = RGB(255,255,255);
3159 bkcolor = COLOR_SELECTION;
3160 } else {
3161 bkcolor = RGB(255,255,255);
3164 hbrush = CreateSolidBrush(bkcolor);
3165 FillRect(dis->hDC, &focusRect, hbrush);
3166 DeleteObject(hbrush);
3168 SetBkMode(dis->hDC, TRANSPARENT);
3169 SetTextColor(dis->hDC, textcolor);
3171 cx = pane->widths[col];
3173 if (cx && img!=IMG_NONE) {
3174 if (cx > IMAGE_WIDTH)
3175 cx = IMAGE_WIDTH;
3177 #ifdef _SHELL_FOLDERS
3178 if (entry->hicon && entry->hicon!=(HICON)-1)
3179 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
3180 else
3181 #endif
3182 ImageList_DrawEx(Globals.himl, img, dis->hDC,
3183 img_pos, dis->rcItem.top, cx,
3184 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
3188 if (!entry)
3189 return;
3191 #ifdef _NO_EXTENSIONS
3192 if (img >= IMG_FOLDER_UP)
3193 return;
3194 #endif
3196 col++;
3198 /* output file name */
3199 if (calcWidthCol == -1)
3200 output_text(pane, dis, col, entry->data.cFileName, 0);
3201 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3202 calc_width(pane, dis, col, entry->data.cFileName);
3204 col++;
3206 #ifdef _NO_EXTENSIONS
3207 if (!pane->treePane) {
3208 #endif
3210 /* display file size */
3211 if (visible_cols & COL_SIZE) {
3212 #ifdef _NO_EXTENSIONS
3213 if (!(attrs&FILE_ATTRIBUTE_DIRECTORY))
3214 #endif
3216 format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
3218 if (calcWidthCol == -1)
3219 output_number(pane, dis, col, buffer);
3220 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3221 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
3224 col++;
3227 /* display file date */
3228 if (visible_cols & (COL_DATE|COL_TIME)) {
3229 #ifndef _NO_EXTENSIONS
3230 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
3231 if (calcWidthCol == -1)
3232 output_text(pane, dis, col, buffer, 0);
3233 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3234 calc_width(pane, dis, col, buffer);
3235 col++;
3237 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
3238 if (calcWidthCol == -1)
3239 output_text(pane, dis, col, buffer, 0);
3240 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3241 calc_width(pane, dis, col, buffer);
3242 col++;
3243 #endif /* _NO_EXTENSIONS */
3245 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
3246 if (calcWidthCol == -1)
3247 output_text(pane, dis, col, buffer, 0);
3248 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3249 calc_width(pane, dis, col, buffer);
3250 col++;
3253 #ifndef _NO_EXTENSIONS
3254 if (entry->bhfi_valid) {
3255 if (visible_cols & COL_INDEX) {
3256 static const WCHAR fmtlow[] = {'%','X',0};
3257 static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
3259 if (entry->bhfi.nFileIndexHigh)
3260 wsprintfW(buffer, fmthigh,
3261 entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
3262 else
3263 wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
3265 if (calcWidthCol == -1)
3266 output_text(pane, dis, col, buffer, DT_RIGHT);
3267 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3268 calc_width(pane, dis, col, buffer);
3270 col++;
3273 if (visible_cols & COL_LINKS) {
3274 wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
3276 if (calcWidthCol == -1)
3277 output_text(pane, dis, col, buffer, DT_CENTER);
3278 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3279 calc_width(pane, dis, col, buffer);
3281 col++;
3283 } else
3284 col += 2;
3285 #endif /* _NO_EXTENSIONS */
3287 /* show file attributes */
3288 if (visible_cols & COL_ATTRIBUTES) {
3289 #ifdef _NO_EXTENSIONS
3290 static const WCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3291 lstrcpyW(buffer, s4Tabs);
3292 #else
3293 static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
3294 lstrcpyW(buffer, s11Tabs);
3295 #endif
3297 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
3298 else {
3299 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
3300 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
3301 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
3302 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
3303 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
3304 #ifndef _NO_EXTENSIONS
3305 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
3306 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
3307 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
3308 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
3309 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
3310 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
3311 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
3312 #endif /* _NO_EXTENSIONS */
3315 if (calcWidthCol == -1)
3316 output_tabbed_text(pane, dis, col, buffer);
3317 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
3318 calc_tabbed_width(pane, dis, col, buffer);
3320 col++;
3323 #ifdef _NO_EXTENSIONS
3326 /* draw focus frame */
3327 if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) {
3328 /* Currently [04/2000] Wine neither behaves exactly the same */
3329 /* way as WIN 95 nor like Windows NT... */
3330 HGDIOBJ lastBrush;
3331 HPEN lastPen;
3332 HPEN hpen;
3334 if (!(GetVersion() & 0x80000000)) { /* Windows NT? */
3335 LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)};
3336 hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0);
3337 } else
3338 hpen = CreatePen(PS_DOT, 0, RGB(255,255,255));
3340 lastPen = SelectObject(dis->hDC, hpen);
3341 lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH));
3342 SetROP2(dis->hDC, R2_XORPEN);
3343 Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom);
3344 SelectObject(dis->hDC, lastBrush);
3345 SelectObject(dis->hDC, lastPen);
3346 DeleteObject(hpen);
3348 #endif /* _NO_EXTENSIONS */
3352 #ifdef _NO_EXTENSIONS
3354 static void draw_splitbar(HWND hwnd, int x)
3356 RECT rt;
3357 HDC hdc = GetDC(hwnd);
3359 GetClientRect(hwnd, &rt);
3361 rt.left = x - SPLIT_WIDTH/2;
3362 rt.right = x + SPLIT_WIDTH/2+1;
3364 InvertRect(hdc, &rt);
3366 ReleaseDC(hwnd, hdc);
3369 #endif /* _NO_EXTENSIONS */
3372 #ifndef _NO_EXTENSIONS
3374 static void set_header(Pane* pane)
3376 HDITEMW item;
3377 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3378 int i=0, x=0;
3380 item.mask = HDI_WIDTH;
3381 item.cxy = 0;
3383 for(; x+pane->widths[i]<scroll_pos && i<COLUMNS; i++) {
3384 x += pane->widths[i];
3385 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
3388 if (i < COLUMNS) {
3389 x += pane->widths[i];
3390 item.cxy = x - scroll_pos;
3391 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i++, (LPARAM)&item);
3393 for(; i<COLUMNS; i++) {
3394 item.cxy = pane->widths[i];
3395 x += pane->widths[i];
3396 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
3401 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
3403 switch(pnmh->code) {
3404 case HDN_ITEMCHANGEDW: {
3405 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
3406 int idx = phdn->iItem;
3407 int dx = phdn->pitem->cxy - pane->widths[idx];
3408 int i;
3410 RECT clnt;
3411 GetClientRect(pane->hwnd, &clnt);
3413 pane->widths[idx] += dx;
3415 for(i=idx; ++i<=COLUMNS; )
3416 pane->positions[i] += dx;
3419 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
3420 RECT rt_scr;
3421 RECT rt_clip;
3423 rt_scr.left = pane->positions[idx+1]-scroll_pos;
3424 rt_scr.top = 0;
3425 rt_scr.right = clnt.right;
3426 rt_scr.bottom = clnt.bottom;
3428 rt_clip.left = pane->positions[idx]-scroll_pos;
3429 rt_clip.top = 0;
3430 rt_clip.right = clnt.right;
3431 rt_clip.bottom = clnt.bottom;
3433 if (rt_scr.left < 0) rt_scr.left = 0;
3434 if (rt_clip.left < 0) rt_clip.left = 0;
3436 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
3438 rt_clip.right = pane->positions[idx+1];
3439 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
3441 if (pnmh->code == HDN_ENDTRACKW) {
3442 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
3444 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
3445 set_header(pane);
3449 return FALSE;
3452 case HDN_DIVIDERDBLCLICKW: {
3453 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
3454 HDITEMW item;
3456 calc_single_width(pane, phdn->iItem);
3457 item.mask = HDI_WIDTH;
3458 item.cxy = pane->widths[phdn->iItem];
3460 SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
3461 InvalidateRect(pane->hwnd, 0, TRUE);
3462 break;}
3465 return 0;
3468 #endif /* _NO_EXTENSIONS */
3471 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3473 WCHAR path[MAX_PATH];
3474 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
3476 /* delete sub entries in left pane */
3477 for(;;) {
3478 LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
3479 Entry* sub = (Entry*) res;
3481 if (res==LB_ERR || !sub || sub->level<=entry->level)
3482 break;
3484 SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
3487 /* empty right pane */
3488 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3490 /* release memory */
3491 free_entries(entry);
3493 /* read contents from disk */
3494 #ifdef _SHELL_FOLDERS
3495 if (entry->etype == ET_SHELL)
3497 read_directory(entry, NULL, child->sortOrder, hwnd);
3499 else
3500 #endif
3502 get_path(entry, path);
3503 read_directory(entry, path, child->sortOrder, hwnd);
3506 /* insert found entries in right pane */
3507 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3508 calc_widths(&child->right, FALSE);
3509 #ifndef _NO_EXTENSIONS
3510 set_header(&child->right);
3511 #endif
3513 child->header_wdths_ok = FALSE;
3515 SetCursor(old_cursor);
3519 /* expand a directory entry */
3521 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3523 int idx;
3524 Entry* p;
3526 if (!dir || dir->expanded || !dir->down)
3527 return FALSE;
3529 p = dir->down;
3531 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3532 p = p->next;
3534 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3535 p->data.cFileName[2]=='\0' && p->next)
3536 p = p->next;
3539 /* no subdirectories ? */
3540 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3541 return FALSE;
3543 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3545 dir->expanded = TRUE;
3547 /* insert entries in left pane */
3548 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3550 if (!child->header_wdths_ok) {
3551 if (calc_widths(&child->left, FALSE)) {
3552 #ifndef _NO_EXTENSIONS
3553 set_header(&child->left);
3554 #endif
3556 child->header_wdths_ok = TRUE;
3560 return TRUE;
3564 static void collapse_entry(Pane* pane, Entry* dir)
3566 int idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3568 ShowWindow(pane->hwnd, SW_HIDE);
3570 /* hide sub entries */
3571 for(;;) {
3572 LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3573 Entry* sub = (Entry*) res;
3575 if (res==LB_ERR || !sub || sub->level<=dir->level)
3576 break;
3578 SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3581 dir->expanded = FALSE;
3583 ShowWindow(pane->hwnd, SW_SHOW);
3587 static void refresh_right_pane(ChildWnd* child)
3589 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3590 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3591 calc_widths(&child->right, FALSE);
3593 #ifndef _NO_EXTENSIONS
3594 set_header(&child->right);
3595 #endif
3598 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3600 WCHAR path[MAX_PATH];
3602 if (!entry)
3603 return;
3605 path[0] = '\0';
3607 child->left.cur = entry;
3609 child->right.root = entry->down? entry->down: entry;
3610 child->right.cur = entry;
3612 if (!entry->scanned)
3613 scan_entry(child, entry, idx, hwnd);
3614 else
3615 refresh_right_pane(child);
3617 get_path(entry, path);
3618 lstrcpyW(child->path, path);
3620 if (child->hwnd) /* only change window title, if the window already exists */
3621 SetWindowTextW(child->hwnd, path);
3623 if (path[0])
3624 if (SetCurrentDirectoryW(path))
3625 set_space_status();
3629 static void refresh_child(ChildWnd* child)
3631 WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3632 Entry* entry;
3633 int idx;
3635 get_path(child->left.cur, path);
3636 _wsplitpath(path, drv, NULL, NULL, NULL);
3638 child->right.root = NULL;
3640 scan_entry(child, &child->root.entry, 0, child->hwnd);
3642 #ifdef _SHELL_FOLDERS
3644 if (child->root.entry.etype == ET_SHELL)
3646 LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
3647 if (local_pidl)
3648 entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
3649 else
3650 entry = NULL;
3652 else
3653 #endif
3654 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3656 if (!entry)
3657 entry = &child->root.entry;
3659 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3661 set_curdir(child, entry, 0, child->hwnd);
3663 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3664 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3668 static void create_drive_bar(void)
3670 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3671 #ifndef _NO_EXTENSIONS
3672 WCHAR b1[BUFFER_LEN];
3673 #endif
3674 int btn = 1;
3675 PWSTR p;
3677 GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
3679 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3680 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3681 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3683 #ifndef _NO_EXTENSIONS
3684 #ifdef __WINE__
3685 /* insert unix file system button */
3686 b1[0] = '/';
3687 b1[1] = '\0';
3688 b1[2] = '\0';
3689 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3691 drivebarBtn.idCommand = ID_DRIVE_UNIX_FS;
3692 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3693 drivebarBtn.iString++;
3694 #endif
3695 #ifdef _SHELL_FOLDERS
3696 /* insert shell namespace button */
3697 load_string(b1, sizeof(b1)/sizeof(b1[0]), IDS_SHELL);
3698 b1[lstrlenW(b1)+1] = '\0';
3699 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3701 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3702 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3703 drivebarBtn.iString++;
3704 #endif
3706 /* register windows drive root strings */
3707 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
3708 #endif
3710 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3712 for(p=Globals.drives; *p; ) {
3713 #ifdef _NO_EXTENSIONS
3714 /* insert drive letter */
3715 WCHAR b[3] = {tolower(*p)};
3716 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b);
3717 #endif
3718 switch(GetDriveTypeW(p)) {
3719 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3720 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3721 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3722 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3723 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3726 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3727 drivebarBtn.idCommand++;
3728 drivebarBtn.iString++;
3730 while(*p++);
3734 static void refresh_drives(void)
3736 RECT rect;
3738 /* destroy drive bar */
3739 DestroyWindow(Globals.hdrivebar);
3740 Globals.hdrivebar = 0;
3742 /* re-create drive bar */
3743 create_drive_bar();
3745 /* update window layout */
3746 GetClientRect(Globals.hMainWnd, &rect);
3747 SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3751 static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
3753 HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3755 if (PtrToUlong(hinst) <= 32) {
3756 display_error(hwnd, GetLastError());
3757 return FALSE;
3760 return TRUE;
3764 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3766 WCHAR cmd[MAX_PATH];
3768 #ifdef _SHELL_FOLDERS
3769 if (entry->etype == ET_SHELL) {
3770 BOOL ret = TRUE;
3772 SHELLEXECUTEINFOW shexinfo;
3774 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
3775 shexinfo.fMask = SEE_MASK_IDLIST;
3776 shexinfo.hwnd = hwnd;
3777 shexinfo.lpVerb = NULL;
3778 shexinfo.lpFile = NULL;
3779 shexinfo.lpParameters = NULL;
3780 shexinfo.lpDirectory = NULL;
3781 shexinfo.nShow = nCmdShow;
3782 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3784 if (!ShellExecuteExW(&shexinfo)) {
3785 display_error(hwnd, GetLastError());
3786 ret = FALSE;
3789 if (shexinfo.lpIDList != entry->pidl)
3790 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3792 return ret;
3794 #endif
3796 get_path(entry, cmd);
3798 /* start program, open document... */
3799 return launch_file(hwnd, cmd, nCmdShow);
3803 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3805 Entry* entry = pane->cur;
3807 if (!entry)
3808 return;
3810 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3811 int scanned_old = entry->scanned;
3813 if (!scanned_old)
3815 int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3816 scan_entry(child, entry, idx, hwnd);
3819 #ifndef _NO_EXTENSIONS
3820 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3821 return;
3822 #endif
3824 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3825 entry = child->left.cur->up;
3826 collapse_entry(&child->left, entry);
3827 goto focus_entry;
3828 } else if (entry->expanded)
3829 collapse_entry(pane, child->left.cur);
3830 else {
3831 expand_entry(child, child->left.cur);
3833 if (!pane->treePane) focus_entry: {
3834 int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3835 int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
3836 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3837 set_curdir(child, entry, idx, hwnd);
3841 if (!scanned_old) {
3842 calc_widths(pane, FALSE);
3844 #ifndef _NO_EXTENSIONS
3845 set_header(pane);
3846 #endif
3848 } else {
3849 if (GetKeyState(VK_MENU) < 0)
3850 show_properties_dlg(entry, child->hwnd);
3851 else
3852 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3857 static BOOL pane_command(Pane* pane, UINT cmd)
3859 switch(cmd) {
3860 case ID_VIEW_NAME:
3861 if (pane->visible_cols) {
3862 pane->visible_cols = 0;
3863 calc_widths(pane, TRUE);
3864 #ifndef _NO_EXTENSIONS
3865 set_header(pane);
3866 #endif
3867 InvalidateRect(pane->hwnd, 0, TRUE);
3868 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3869 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3871 break;
3873 case ID_VIEW_ALL_ATTRIBUTES:
3874 if (pane->visible_cols != COL_ALL) {
3875 pane->visible_cols = COL_ALL;
3876 calc_widths(pane, TRUE);
3877 #ifndef _NO_EXTENSIONS
3878 set_header(pane);
3879 #endif
3880 InvalidateRect(pane->hwnd, 0, TRUE);
3881 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3882 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3884 break;
3886 #ifndef _NO_EXTENSIONS
3887 case ID_PREFERRED_SIZES: {
3888 calc_widths(pane, TRUE);
3889 set_header(pane);
3890 InvalidateRect(pane->hwnd, 0, TRUE);
3891 break;}
3892 #endif
3894 /* TODO: more command ids... */
3896 default:
3897 return FALSE;
3900 return TRUE;
3904 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3906 if (child->sortOrder != sortOrder) {
3907 child->sortOrder = sortOrder;
3908 refresh_child(child);
3912 static void update_view_menu(ChildWnd* child)
3914 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3915 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3916 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3917 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3921 static BOOL is_directory(LPCWSTR target)
3923 /*TODO correctly handle UNIX paths */
3924 DWORD target_attr = GetFileAttributesW(target);
3926 if (target_attr == INVALID_FILE_ATTRIBUTES)
3927 return FALSE;
3929 return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE;
3932 static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
3934 WCHAR path[MAX_PATH];
3935 int len;
3937 get_path(pane->cur, path);
3939 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
3940 return FALSE;
3942 get_path(pane->cur, source);
3944 /* convert relative targets to absolute paths */
3945 if (path[0]!='/' && path[1]!=':') {
3946 get_path(pane->cur->up, target);
3947 len = lstrlenW(target);
3949 if (target[len-1]!='\\' && target[len-1]!='/')
3950 target[len++] = '/';
3952 lstrcpyW(target+len, path);
3953 } else
3954 lstrcpyW(target, path);
3956 /* If the target already exists as directory, create a new target below this. */
3957 if (is_directory(path)) {
3958 WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
3959 static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
3961 _wsplitpath(source, NULL, NULL, fname, ext);
3963 wsprintfW(target, sAppend, path, fname, ext);
3966 return TRUE;
3970 static IContextMenu2* s_pctxmenu2 = NULL;
3971 static IContextMenu3* s_pctxmenu3 = NULL;
3973 static void CtxMenu_reset(void)
3975 s_pctxmenu2 = NULL;
3976 s_pctxmenu3 = NULL;
3979 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
3981 IContextMenu* pcm = NULL;
3983 CtxMenu_reset();
3985 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
3986 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
3987 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
3988 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
3990 if (pcm) {
3991 IContextMenu_Release(pcm1);
3992 return pcm;
3993 } else
3994 return pcm1;
3997 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
3999 if (s_pctxmenu3) {
4000 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
4001 return TRUE;
4004 if (s_pctxmenu2)
4005 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
4006 return TRUE;
4008 return FALSE;
4012 #ifndef _NO_EXTENSIONS
4013 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
4015 IContextMenu* pcm;
4016 BOOL executed = FALSE;
4018 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
4020 if (SUCCEEDED(hr)) {
4021 HMENU hmenu = CreatePopupMenu();
4023 pcm = CtxMenu_query_interfaces(pcm);
4025 if (hmenu) {
4026 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
4028 if (SUCCEEDED(hr)) {
4029 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
4031 CtxMenu_reset();
4033 if (idCmd) {
4034 CMINVOKECOMMANDINFO cmi;
4036 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
4037 cmi.fMask = 0;
4038 cmi.hwnd = hwndParent;
4039 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
4040 cmi.lpParameters = NULL;
4041 cmi.lpDirectory = NULL;
4042 cmi.nShow = SW_SHOWNORMAL;
4043 cmi.dwHotKey = 0;
4044 cmi.hIcon = 0;
4046 hr = IContextMenu_InvokeCommand(pcm, &cmi);
4047 executed = TRUE;
4049 } else
4050 CtxMenu_reset();
4053 IContextMenu_Release(pcm);
4056 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
4058 #endif /* _NO_EXTENSIONS */
4061 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4063 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
4064 ASSERT(child);
4066 switch(nmsg) {
4067 case WM_DRAWITEM: {
4068 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
4069 Entry* entry = (Entry*) dis->itemData;
4071 if (dis->CtlID == IDW_TREE_LEFT)
4072 draw_item(&child->left, dis, entry, -1);
4073 else if (dis->CtlID == IDW_TREE_RIGHT)
4074 draw_item(&child->right, dis, entry, -1);
4075 else
4076 goto draw_menu_item;
4078 return TRUE;}
4080 case WM_CREATE:
4081 InitChildWindow(child);
4082 break;
4084 case WM_NCDESTROY:
4085 free_child_window(child);
4086 SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
4087 break;
4089 case WM_PAINT: {
4090 PAINTSTRUCT ps;
4091 HBRUSH lastBrush;
4092 RECT rt;
4093 GetClientRect(hwnd, &rt);
4094 BeginPaint(hwnd, &ps);
4095 rt.left = child->split_pos-SPLIT_WIDTH/2;
4096 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
4097 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
4098 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
4099 SelectObject(ps.hdc, lastBrush);
4100 #ifdef _NO_EXTENSIONS
4101 rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL);
4102 FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH));
4103 #endif
4104 EndPaint(hwnd, &ps);
4105 break;}
4107 case WM_SETCURSOR:
4108 if (LOWORD(lparam) == HTCLIENT) {
4109 POINT pt;
4110 GetCursorPos(&pt);
4111 ScreenToClient(hwnd, &pt);
4113 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
4114 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
4115 return TRUE;
4118 goto def;
4120 case WM_LBUTTONDOWN: {
4121 RECT rt;
4122 int x = (short)LOWORD(lparam);
4124 GetClientRect(hwnd, &rt);
4126 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
4127 last_split = child->split_pos;
4128 #ifdef _NO_EXTENSIONS
4129 draw_splitbar(hwnd, last_split);
4130 #endif
4131 SetCapture(hwnd);
4134 break;}
4136 case WM_LBUTTONUP:
4137 if (GetCapture() == hwnd) {
4138 #ifdef _NO_EXTENSIONS
4139 RECT rt;
4140 int x = (short)LOWORD(lparam);
4141 draw_splitbar(hwnd, last_split);
4142 last_split = -1;
4143 GetClientRect(hwnd, &rt);
4144 child->split_pos = x;
4145 resize_tree(child, rt.right, rt.bottom);
4146 #endif
4147 ReleaseCapture();
4149 break;
4151 #ifdef _NO_EXTENSIONS
4152 case WM_CAPTURECHANGED:
4153 if (GetCapture()==hwnd && last_split>=0)
4154 draw_splitbar(hwnd, last_split);
4155 break;
4156 #endif
4158 case WM_KEYDOWN:
4159 if (wparam == VK_ESCAPE)
4160 if (GetCapture() == hwnd) {
4161 RECT rt;
4162 #ifdef _NO_EXTENSIONS
4163 draw_splitbar(hwnd, last_split);
4164 #else
4165 child->split_pos = last_split;
4166 #endif
4167 GetClientRect(hwnd, &rt);
4168 resize_tree(child, rt.right, rt.bottom);
4169 last_split = -1;
4170 ReleaseCapture();
4171 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
4173 break;
4175 case WM_MOUSEMOVE:
4176 if (GetCapture() == hwnd) {
4177 RECT rt;
4178 int x = (short)LOWORD(lparam);
4180 #ifdef _NO_EXTENSIONS
4181 HDC hdc = GetDC(hwnd);
4182 GetClientRect(hwnd, &rt);
4184 rt.left = last_split-SPLIT_WIDTH/2;
4185 rt.right = last_split+SPLIT_WIDTH/2+1;
4186 InvertRect(hdc, &rt);
4188 last_split = x;
4189 rt.left = x-SPLIT_WIDTH/2;
4190 rt.right = x+SPLIT_WIDTH/2+1;
4191 InvertRect(hdc, &rt);
4193 ReleaseDC(hwnd, hdc);
4194 #else
4195 GetClientRect(hwnd, &rt);
4197 if (x>=0 && x<rt.right) {
4198 child->split_pos = x;
4199 resize_tree(child, rt.right, rt.bottom);
4200 rt.left = x-SPLIT_WIDTH/2;
4201 rt.right = x+SPLIT_WIDTH/2+1;
4202 InvalidateRect(hwnd, &rt, FALSE);
4203 UpdateWindow(child->left.hwnd);
4204 UpdateWindow(hwnd);
4205 UpdateWindow(child->right.hwnd);
4207 #endif
4209 break;
4211 #ifndef _NO_EXTENSIONS
4212 case WM_GETMINMAXINFO:
4213 DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
4215 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
4217 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
4218 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
4219 break;}
4220 #endif /* _NO_EXTENSIONS */
4222 case WM_SETFOCUS:
4223 if (SetCurrentDirectoryW(child->path))
4224 set_space_status();
4225 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
4226 break;
4228 case WM_DISPATCH_COMMAND: {
4229 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4231 switch(LOWORD(wparam)) {
4232 case ID_WINDOW_NEW: {
4233 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
4235 if (!create_child_window(new_child))
4236 HeapFree(GetProcessHeap(), 0, new_child);
4238 break;}
4240 case ID_REFRESH:
4241 refresh_drives();
4242 refresh_child(child);
4243 break;
4245 case ID_ACTIVATE:
4246 activate_entry(child, pane, hwnd);
4247 break;
4249 case ID_FILE_MOVE: {
4250 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4252 if (prompt_target(pane, source, target)) {
4253 SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
4255 source[lstrlenW(source)+1] = '\0';
4256 target[lstrlenW(target)+1] = '\0';
4258 if (!SHFileOperationW(&shfo))
4259 refresh_child(child);
4261 break;}
4263 case ID_FILE_COPY: {
4264 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
4266 if (prompt_target(pane, source, target)) {
4267 SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
4269 source[lstrlenW(source)+1] = '\0';
4270 target[lstrlenW(target)+1] = '\0';
4272 if (!SHFileOperationW(&shfo))
4273 refresh_child(child);
4275 break;}
4277 case ID_FILE_DELETE: {
4278 WCHAR path[BUFFER_LEN];
4279 SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
4281 get_path(pane->cur, path);
4283 path[lstrlenW(path)+1] = '\0';
4285 if (!SHFileOperationW(&shfo))
4286 refresh_child(child);
4287 break;}
4289 case ID_VIEW_SORT_NAME:
4290 set_sort_order(child, SORT_NAME);
4291 break;
4293 case ID_VIEW_SORT_TYPE:
4294 set_sort_order(child, SORT_EXT);
4295 break;
4297 case ID_VIEW_SORT_SIZE:
4298 set_sort_order(child, SORT_SIZE);
4299 break;
4301 case ID_VIEW_SORT_DATE:
4302 set_sort_order(child, SORT_DATE);
4303 break;
4305 case ID_VIEW_FILTER: {
4306 struct FilterDialog dlg;
4308 memset(&dlg, 0, sizeof(struct FilterDialog));
4309 lstrcpyW(dlg.pattern, child->filter_pattern);
4310 dlg.flags = child->filter_flags;
4312 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
4313 lstrcpyW(child->filter_pattern, dlg.pattern);
4314 child->filter_flags = dlg.flags;
4315 refresh_right_pane(child);
4317 break;}
4319 case ID_VIEW_SPLIT: {
4320 last_split = child->split_pos;
4321 #ifdef _NO_EXTENSIONS
4322 draw_splitbar(hwnd, last_split);
4323 #endif
4324 SetCapture(hwnd);
4325 break;}
4327 case ID_EDIT_PROPERTIES:
4328 show_properties_dlg(pane->cur, child->hwnd);
4329 break;
4331 default:
4332 return pane_command(pane, LOWORD(wparam));
4335 return TRUE;}
4337 case WM_COMMAND: {
4338 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4340 switch(HIWORD(wparam)) {
4341 case LBN_SELCHANGE: {
4342 int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
4343 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
4345 if (pane == &child->left)
4346 set_curdir(child, entry, idx, hwnd);
4347 else
4348 pane->cur = entry;
4349 break;}
4351 case LBN_DBLCLK:
4352 activate_entry(child, pane, hwnd);
4353 break;
4355 break;}
4357 #ifndef _NO_EXTENSIONS
4358 case WM_NOTIFY: {
4359 NMHDR* pnmh = (NMHDR*) lparam;
4360 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
4361 #endif
4363 #ifdef _SHELL_FOLDERS
4364 case WM_CONTEXTMENU: {
4365 POINT pt, pt_clnt;
4366 Pane* pane;
4367 int idx;
4369 /* first select the current item in the listbox */
4370 HWND hpanel = (HWND) wparam;
4371 pt_clnt.x = pt.x = (short)LOWORD(lparam);
4372 pt_clnt.y = pt.y = (short)HIWORD(lparam);
4373 ScreenToClient(hpanel, &pt_clnt);
4374 SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4375 SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
4377 /* now create the popup menu using shell namespace and IContextMenu */
4378 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
4379 idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
4381 if (idx != -1) {
4382 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
4384 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
4386 if (pidl_abs) {
4387 IShellFolder* parentFolder;
4388 LPCITEMIDLIST pidlLast;
4390 /* get and use the parent folder to display correct context menu in all cases */
4391 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
4392 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
4393 refresh_child(child);
4395 IShellFolder_Release(parentFolder);
4398 IMalloc_Free(Globals.iMalloc, pidl_abs);
4401 break;}
4402 #endif
4404 case WM_MEASUREITEM:
4405 draw_menu_item:
4406 if (!wparam) /* Is the message menu-related? */
4407 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4408 return TRUE;
4410 break;
4412 case WM_INITMENUPOPUP:
4413 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
4414 return 0;
4416 update_view_menu(child);
4417 break;
4419 case WM_MENUCHAR: /* only supported by IContextMenu3 */
4420 if (s_pctxmenu3) {
4421 LRESULT lResult = 0;
4423 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
4425 return lResult;
4428 break;
4430 case WM_SIZE:
4431 if (wparam != SIZE_MINIMIZED)
4432 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
4433 /* fall through */
4435 default: def:
4436 return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
4439 return 0;
4443 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
4445 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
4446 Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
4447 ASSERT(child);
4449 switch(nmsg) {
4450 #ifndef _NO_EXTENSIONS
4451 case WM_HSCROLL:
4452 set_header(pane);
4453 break;
4454 #endif
4456 case WM_SETFOCUS:
4457 child->focus_pane = pane==&child->right? 1: 0;
4458 SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
4459 /*TODO: check menu items */
4460 break;
4462 case WM_KEYDOWN:
4463 if (wparam == VK_TAB) {
4464 /*TODO: SetFocus(Globals.hdrivebar) */
4465 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
4469 return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
4473 static void InitInstance(HINSTANCE hinstance)
4475 static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
4477 WNDCLASSEXW wcFrame;
4478 WNDCLASSW wcChild;
4479 int col;
4481 INITCOMMONCONTROLSEX icc = {
4482 sizeof(INITCOMMONCONTROLSEX),
4483 ICC_BAR_CLASSES
4486 HDC hdc = GetDC(0);
4488 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
4490 InitCommonControlsEx(&icc);
4493 /* register frame window class */
4495 wcFrame.cbSize = sizeof(WNDCLASSEXW);
4496 wcFrame.style = 0;
4497 wcFrame.lpfnWndProc = FrameWndProc;
4498 wcFrame.cbClsExtra = 0;
4499 wcFrame.cbWndExtra = 0;
4500 wcFrame.hInstance = hinstance;
4501 wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
4502 wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
4503 wcFrame.hbrBackground = 0;
4504 wcFrame.lpszMenuName = 0;
4505 wcFrame.lpszClassName = sWINEFILEFRAME;
4506 wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
4508 Globals.hframeClass = RegisterClassExW(&wcFrame);
4511 /* register tree windows class */
4513 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
4514 wcChild.lpfnWndProc = ChildWndProc;
4515 wcChild.cbClsExtra = 0;
4516 wcChild.cbWndExtra = 0;
4517 wcChild.hInstance = hinstance;
4518 wcChild.hIcon = 0;
4519 wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
4520 wcChild.hbrBackground = 0;
4521 wcChild.lpszMenuName = 0;
4522 wcChild.lpszClassName = sWINEFILETREE;
4524 RegisterClassW(&wcChild);
4527 Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
4529 Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
4531 ReleaseDC(0, hdc);
4533 Globals.hInstance = hinstance;
4535 #ifdef _SHELL_FOLDERS
4536 CoInitialize(NULL);
4537 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
4538 SHGetDesktopFolder(&Globals.iDesktop);
4539 Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
4540 #endif
4542 /* load column strings */
4543 col = 1;
4545 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_NAME);
4546 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SIZE);
4547 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_CDATE);
4548 #ifndef _NO_EXTENSIONS
4549 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ADATE);
4550 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_MDATE);
4551 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_IDX);
4552 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_LINKS);
4553 #endif
4554 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_ATTR);
4555 #ifndef _NO_EXTENSIONS
4556 load_string(g_pos_names[col++], sizeof(g_pos_names[col])/sizeof(g_pos_names[col][0]), IDS_COL_SEC);
4557 #endif
4561 static BOOL show_frame(HWND hwndParent, int cmdshow, LPCWSTR path)
4563 static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
4565 WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
4566 ChildWnd* child;
4567 HMENU hMenuFrame, hMenuWindow;
4568 windowOptions opts;
4570 CLIENTCREATESTRUCT ccs;
4572 if (Globals.hMainWnd)
4573 return TRUE;
4575 opts = load_registry_settings();
4576 hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
4577 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
4579 Globals.hMenuFrame = hMenuFrame;
4580 Globals.hMenuView = GetSubMenu(hMenuFrame, 2);
4581 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 3);
4583 ccs.hWindowMenu = hMenuWindow;
4584 ccs.idFirstChild = IDW_FIRST_CHILD;
4587 /* create main window */
4588 Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINEFILE), WS_OVERLAPPEDWINDOW,
4589 opts.start_x, opts.start_y, opts.width, opts.height,
4590 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
4593 Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
4594 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
4595 0, 0, 0, 0,
4596 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
4598 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
4599 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
4601 create_drive_bar();
4604 TBBUTTON toolbarBtns[] = {
4605 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
4606 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4607 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4608 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4609 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4612 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4613 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4614 sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON));
4615 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4618 Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4619 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4621 /*TODO: read paths from registry */
4623 if (!path || !*path) {
4624 GetCurrentDirectoryW(MAX_PATH, buffer);
4625 path = buffer;
4628 ShowWindow(Globals.hMainWnd, cmdshow);
4630 #if defined(_SHELL_FOLDERS) && !defined(__WINE__)
4631 /* Shell Namespace as default: */
4632 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4633 #else
4634 child = alloc_child_window(path, NULL, Globals.hMainWnd);
4635 #endif
4637 child->pos.showCmd = SW_SHOWMAXIMIZED;
4638 child->pos.rcNormalPosition.left = 0;
4639 child->pos.rcNormalPosition.top = 0;
4640 child->pos.rcNormalPosition.right = 320;
4641 child->pos.rcNormalPosition.bottom = 280;
4643 if (!create_child_window(child)) {
4644 HeapFree(GetProcessHeap(), 0, child);
4645 return FALSE;
4648 SetWindowPlacement(child->hwnd, &child->pos);
4650 Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
4652 Globals.prescan_node = FALSE;
4654 UpdateWindow(Globals.hMainWnd);
4656 if (child->hwnd && path && path[0])
4658 int index,count;
4659 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4660 WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4662 memset(name,0,sizeof(name));
4663 memset(name,0,sizeof(ext));
4664 _wsplitpath(path, drv, dir, name, ext);
4665 if (name[0])
4667 count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
4668 lstrcpyW(fullname,name);
4669 lstrcatW(fullname,ext);
4671 for (index = 0; index < count; index ++)
4673 Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
4674 if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
4675 lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
4677 SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
4678 SetFocus(child->right.hwnd);
4679 break;
4684 return TRUE;
4687 static void ExitInstance(void)
4689 #ifdef _SHELL_FOLDERS
4690 IShellFolder_Release(Globals.iDesktop);
4691 IMalloc_Release(Globals.iMalloc);
4692 CoUninitialize();
4693 #endif
4695 DeleteObject(Globals.hfont);
4696 ImageList_Destroy(Globals.himl);
4699 #ifdef _NO_EXTENSIONS
4701 /* search for already running win[e]files */
4703 static int g_foundPrevInstance = 0;
4705 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
4707 WCHAR cls[128];
4709 GetClassNameW(hwnd, cls, 128);
4711 if (!lstrcmpW(cls, (LPCWSTR)lparam)) {
4712 g_foundPrevInstance++;
4713 return FALSE;
4716 return TRUE;
4719 /* search for window of given class name to allow only one running instance */
4720 static int find_window_class(LPCWSTR classname)
4722 EnumWindows(EnumWndProc, (LPARAM)classname);
4724 if (g_foundPrevInstance)
4725 return 1;
4727 return 0;
4730 #endif
4732 static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCWSTR path)
4734 MSG msg;
4736 InitInstance(hinstance);
4738 if( !show_frame(0, cmdshow, path) )
4740 ExitInstance();
4741 return 1;
4744 while(GetMessageW(&msg, 0, 0, 0)) {
4745 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4746 continue;
4748 if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
4749 continue;
4751 TranslateMessage(&msg);
4752 DispatchMessageW(&msg);
4755 ExitInstance();
4757 return msg.wParam;
4761 #if defined(_MSC_VER)
4762 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4763 #else
4764 int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
4765 #endif
4767 #ifdef _NO_EXTENSIONS
4768 if (find_window_class(sWINEFILEFRAME))
4769 return 1;
4770 #endif
4772 { /* convert ANSI cmdline into WCS path string */
4773 WCHAR buffer[MAX_PATH];
4774 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH);
4775 winefile_main(hinstance, cmdshow, buffer);
4778 return 0;