msvcr100: Fix next writer unblocking in reader_writer_lock::unlock.
[wine.git] / programs / winefile / winefile.c
blob6d18954e05a24ee6d77ea101e807c5649a8c06a7
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 #define COBJMACROS
24 #include <assert.h>
25 #include <stdio.h>
26 #include "winefile.h"
27 #include "resource.h"
29 #ifdef NONAMELESSUNION
30 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
31 #else
32 #define UNION_MEMBER(x) x
33 #endif
35 #define DEFAULT_SPLIT_POS 300
37 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
38 'W','i','n','e','\\',
39 'W','i','n','e','F','i','l','e','\0'};
40 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
41 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
42 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
43 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
44 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
46 enum ENTRY_TYPE {
47 ET_WINDOWS,
48 ET_SHELL
51 typedef struct _Entry {
52 struct _Entry* next;
53 struct _Entry* down;
54 struct _Entry* up;
56 BOOL expanded;
57 BOOL scanned;
58 int level;
60 WIN32_FIND_DATAW data;
62 BY_HANDLE_FILE_INFORMATION bhfi;
63 BOOL bhfi_valid;
64 enum ENTRY_TYPE etype;
65 LPITEMIDLIST pidl;
66 IShellFolder* folder;
67 HICON hicon;
68 } Entry;
70 typedef struct {
71 Entry entry;
72 WCHAR path[MAX_PATH];
73 WCHAR volname[_MAX_FNAME];
74 WCHAR fs[_MAX_DIR];
75 DWORD drive_type;
76 DWORD fs_flags;
77 } Root;
79 enum COLUMN_FLAGS {
80 COL_SIZE = 0x01,
81 COL_DATE = 0x02,
82 COL_TIME = 0x04,
83 COL_ATTRIBUTES = 0x08,
84 COL_DOSNAMES = 0x10,
85 COL_INDEX = 0x20,
86 COL_LINKS = 0x40,
87 COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
90 typedef enum {
91 SORT_NAME,
92 SORT_EXT,
93 SORT_SIZE,
94 SORT_DATE
95 } SORT_ORDER;
97 typedef struct {
98 HWND hwnd;
99 HWND hwndHeader;
101 #define COLUMNS 10
102 int widths[COLUMNS];
103 int widths_shown[COLUMNS];
104 int positions[COLUMNS+1];
106 BOOL treePane;
107 int visible_cols;
108 Entry* root;
109 Entry* cur;
110 } Pane;
112 typedef struct {
113 HWND hwnd;
114 Pane left;
115 Pane right;
116 int focus_pane; /* 0: left 1: right */
117 WINDOWPLACEMENT pos;
118 int split_pos;
119 BOOL header_wdths_ok;
121 WCHAR path[MAX_PATH];
122 WCHAR filter_pattern[MAX_PATH];
123 int filter_flags;
124 Root root;
126 SORT_ORDER sortOrder;
127 } ChildWnd;
131 static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd);
132 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
133 static void refresh_child(ChildWnd* child);
134 static void refresh_drives(void);
135 static void get_path(Entry* dir, PWSTR path);
136 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols);
138 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
139 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
140 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
143 /* globals */
144 WINEFILE_GLOBALS Globals;
146 static int last_split;
148 /* some common string constants */
149 static const WCHAR sEmpty[] = {'\0'};
150 static const WCHAR sSpace[] = {' ', '\0'};
151 static const WCHAR sNumFmt[] = {'%','d','\0'};
152 static const WCHAR sQMarks[] = {'?','?','?','\0'};
154 /* window class names */
155 static const WCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
156 static const WCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
158 static void format_longlong(LPWSTR ret, ULONGLONG val)
160 WCHAR buffer[65], *p = &buffer[64];
162 *p = 0;
163 do {
164 *(--p) = '0' + val % 10;
165 val /= 10;
166 } while (val);
167 lstrcpyW( ret, p );
171 /* load resource string */
172 static LPWSTR load_string(LPWSTR buffer, DWORD size, UINT id)
174 LoadStringW(Globals.hInstance, id, buffer, size);
175 return buffer;
178 #define RS(b, i) load_string(b, ARRAY_SIZE(b), i)
181 /* display error message for the specified WIN32 error code */
182 static void display_error(HWND hwnd, DWORD error)
184 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
185 PWSTR msg;
187 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
188 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PWSTR)&msg, 0, NULL))
189 MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
190 else
191 MessageBoxW(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
193 LocalFree(msg);
197 /* display network error message using WNetGetLastErrorW() */
198 static void display_network_error(HWND hwnd)
200 WCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
201 DWORD error;
203 if (WNetGetLastErrorW(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
204 MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
207 static inline BOOL get_check(HWND hwnd, INT id)
209 return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
212 static inline INT set_check(HWND hwnd, INT id, BOOL on)
214 return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
217 static inline void choose_font(HWND hwnd)
219 WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
220 CHOOSEFONTW chFont;
221 LOGFONTW lFont;
223 HDC hdc = GetDC(hwnd);
225 GetObjectW(Globals.hfont, sizeof(LOGFONTW), &lFont);
227 chFont.lStructSize = sizeof(CHOOSEFONTW);
228 chFont.hwndOwner = hwnd;
229 chFont.hDC = NULL;
230 chFont.lpLogFont = &lFont;
231 chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL | CF_INITTOLOGFONTSTRUCT | CF_NOVERTFONTS;
232 chFont.rgbColors = RGB(0,0,0);
233 chFont.lCustData = 0;
234 chFont.lpfnHook = NULL;
235 chFont.lpTemplateName = NULL;
236 chFont.hInstance = Globals.hInstance;
237 chFont.lpszStyle = NULL;
238 chFont.nFontType = SIMULATED_FONTTYPE;
239 chFont.nSizeMin = 0;
240 chFont.nSizeMax = 24;
242 if (ChooseFontW(&chFont)) {
243 HWND childWnd;
244 HFONT hFontOld;
246 DeleteObject(Globals.hfont);
247 Globals.hfont = CreateFontIndirectW(&lFont);
248 hFontOld = SelectObject(hdc, Globals.hfont);
249 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
251 /* change font in all open child windows */
252 for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
253 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
254 SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
255 SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
256 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
257 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
258 InvalidateRect(child->left.hwnd, NULL, TRUE);
259 InvalidateRect(child->right.hwnd, NULL, TRUE);
262 SelectObject(hdc, hFontOld);
264 else if (CommDlgExtendedError()) {
265 LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
266 LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
267 MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
270 ReleaseDC(hwnd, hdc);
274 /* allocate and initialise a directory entry */
275 static Entry* alloc_entry(void)
277 Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
279 entry->pidl = NULL;
280 entry->folder = NULL;
281 entry->hicon = 0;
283 return entry;
286 /* free a directory entry */
287 static void free_entry(Entry* entry)
289 if (entry->hicon && entry->hicon!=(HICON)-1)
290 DestroyIcon(entry->hicon);
292 if (entry->folder && entry->folder!=Globals.iDesktop)
293 IShellFolder_Release(entry->folder);
295 if (entry->pidl)
296 IMalloc_Free(Globals.iMalloc, entry->pidl);
298 HeapFree(GetProcessHeap(), 0, entry);
301 /* recursively free all child entries */
302 static void free_entries(Entry* dir)
304 Entry *entry, *next=dir->down;
306 if (next) {
307 dir->down = 0;
309 do {
310 entry = next;
311 next = entry->next;
313 free_entries(entry);
314 free_entry(entry);
315 } while(next);
320 static void read_directory_win(Entry* dir, LPCWSTR path)
322 Entry* first_entry = NULL;
323 Entry* last = NULL;
324 Entry* entry;
326 int level = dir->level + 1;
327 WIN32_FIND_DATAW w32fd;
328 HANDLE hFind;
329 HANDLE hFile;
331 WCHAR buffer[MAX_PATH], *p;
332 for(p=buffer; *path; )
333 *p++ = *path++;
335 *p++ = '\\';
336 p[0] = '*';
337 p[1] = '\0';
339 hFind = FindFirstFileW(buffer, &w32fd);
341 if (hFind != INVALID_HANDLE_VALUE) {
342 do {
343 entry = alloc_entry();
345 if (!first_entry)
346 first_entry = entry;
348 if (last)
349 last->next = entry;
351 memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATAW));
352 entry->down = NULL;
353 entry->up = dir;
354 entry->expanded = FALSE;
355 entry->scanned = FALSE;
356 entry->level = level;
357 entry->etype = ET_WINDOWS;
358 entry->bhfi_valid = FALSE;
360 lstrcpyW(p, entry->data.cFileName);
362 hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
363 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
365 if (hFile != INVALID_HANDLE_VALUE) {
366 if (GetFileInformationByHandle(hFile, &entry->bhfi))
367 entry->bhfi_valid = TRUE;
369 CloseHandle(hFile);
372 last = entry;
373 } while(FindNextFileW(hFind, &w32fd));
375 if (last)
376 last->next = NULL;
378 FindClose(hFind);
381 dir->down = first_entry;
382 dir->scanned = TRUE;
386 static Entry* find_entry_win(Entry* dir, LPCWSTR name)
388 Entry* entry;
390 for(entry=dir->down; entry; entry=entry->next) {
391 LPCWSTR p = name;
392 LPCWSTR q = entry->data.cFileName;
394 do {
395 if (!*p || *p == '\\' || *p == '/')
396 return entry;
397 } while(tolower(*p++) == tolower(*q++));
399 p = name;
400 q = entry->data.cAlternateFileName;
402 do {
403 if (!*p || *p == '\\' || *p == '/')
404 return entry;
405 } while(tolower(*p++) == tolower(*q++));
408 return 0;
412 static Entry* read_tree_win(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
414 WCHAR buffer[MAX_PATH];
415 Entry* entry = &root->entry;
416 LPCWSTR s = path;
417 PWSTR d = buffer;
419 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
421 entry->etype = ET_WINDOWS;
422 while(entry) {
423 while(*s && *s != '\\' && *s != '/')
424 *d++ = *s++;
426 while(*s == '\\' || *s == '/')
427 s++;
429 *d++ = '\\';
430 *d = '\0';
432 read_directory(entry, buffer, sortOrder, hwnd);
434 if (entry->down)
435 entry->expanded = TRUE;
437 if (!*s)
438 break;
440 entry = find_entry_win(entry, s);
443 SetCursor(old_cursor);
445 return entry;
449 static void free_strret(STRRET* str)
451 if (str->uType == STRRET_WSTR)
452 IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
455 static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
457 LPCWSTR s;
458 LPWSTR d = dest;
460 for(s=source; count&&(*d++=*s++); )
461 count--;
463 return dest;
466 static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
468 switch(str->uType) {
469 case STRRET_WSTR:
470 wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
471 break;
473 case STRRET_OFFSET:
474 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
475 break;
477 case STRRET_CSTR:
478 MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
483 static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len, SHGDNF flags)
485 STRRET str;
487 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
489 if (SUCCEEDED(hr)) {
490 get_strretW(&str, &pidl->mkid, buffer, len);
491 free_strret(&str);
492 } else
493 buffer[0] = '\0';
495 return hr;
499 static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
501 STRRET str;
503 /* SHGDN_FORPARSING: get full path of id list */
504 HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
506 if (SUCCEEDED(hr)) {
507 get_strretW(&str, &pidl->mkid, buffer, len);
508 free_strret(&str);
509 } else
510 buffer[0] = '\0';
512 return hr;
516 /* create an item id list from a file system path */
518 static LPITEMIDLIST get_path_pidl(LPWSTR path, HWND hwnd)
520 LPITEMIDLIST pidl;
521 HRESULT hr;
522 ULONG len;
523 LPWSTR buffer = path;
525 hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
526 if (FAILED(hr))
527 return NULL;
529 return pidl;
533 /* convert an item id list from relative to absolute (=relative to the desktop) format */
535 static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
537 if (entry->up && entry->up->etype==ET_SHELL) {
538 LPITEMIDLIST idl = NULL;
540 while (entry->up) {
541 idl = ILCombine(ILClone(entry->pidl), idl);
542 entry = entry->up;
545 return idl;
546 } else if (entry->etype == ET_WINDOWS) {
547 WCHAR path[MAX_PATH];
549 get_path(entry, path);
551 return get_path_pidl(path, hwnd);
552 } else if (entry->pidl)
553 return ILClone(entry->pidl);
555 return NULL;
559 static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
561 IExtractIconW* pExtract;
563 if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IExtractIconW, 0, (void**)&pExtract))) {
564 WCHAR path[_MAX_PATH];
565 unsigned flags;
566 HICON hicon;
567 int idx;
569 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
570 if (!(flags & GIL_NOTFILENAME)) {
571 if (idx == -1)
572 idx = 0; /* special case for some control panel applications */
574 if ((int)ExtractIconExW(path, idx, 0, &hicon, 1) > 0)
575 flags &= ~GIL_DONTCACHE;
576 } else {
577 HICON hIconLarge = 0;
579 HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
581 if (SUCCEEDED(hr))
582 DestroyIcon(hIconLarge);
585 return hicon;
589 return 0;
593 static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
595 Entry* entry;
597 for(entry=dir->down; entry; entry=entry->next) {
598 if (entry->pidl->mkid.cb == pidl->mkid.cb &&
599 !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
600 return entry;
603 return 0;
606 static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
608 Entry* entry = &root->entry;
609 Entry* next;
610 LPITEMIDLIST next_pidl = pidl;
611 IShellFolder* folder;
612 IShellFolder* child = NULL;
613 HRESULT hr;
615 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
617 entry->etype = ET_SHELL;
618 folder = Globals.iDesktop;
620 while(entry) {
621 entry->pidl = next_pidl;
622 entry->folder = folder;
624 if (!pidl->mkid.cb)
625 break;
627 /* copy first element of item idlist */
628 next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
629 memcpy(next_pidl, pidl, pidl->mkid.cb);
630 ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
632 hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
633 if (FAILED(hr))
634 break;
636 read_directory(entry, NULL, sortOrder, hwnd);
638 if (entry->down)
639 entry->expanded = TRUE;
641 next = find_entry_shell(entry, next_pidl);
642 if (!next)
643 break;
645 folder = child;
646 entry = next;
648 /* go to next element */
649 pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
652 SetCursor(old_cursor);
654 return entry;
658 static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATAW* w32fdata)
660 if (!(attribs & SFGAO_FILESYSTEM) ||
661 FAILED(SHGetDataFromIDListW(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATAW)))) {
662 WIN32_FILE_ATTRIBUTE_DATA fad;
663 IDataObject* pDataObj;
665 STGMEDIUM medium = {0, {0}, 0};
666 FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
668 HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
670 if (SUCCEEDED(hr)) {
671 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
673 IDataObject_Release(pDataObj);
675 if (SUCCEEDED(hr)) {
676 LPCWSTR path = GlobalLock(medium.UNION_MEMBER(hGlobal));
677 UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
679 if (GetFileAttributesExW(path, GetFileExInfoStandard, &fad)) {
680 w32fdata->dwFileAttributes = fad.dwFileAttributes;
681 w32fdata->ftCreationTime = fad.ftCreationTime;
682 w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
683 w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
685 if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
686 w32fdata->nFileSizeLow = fad.nFileSizeLow;
687 w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
691 SetErrorMode(sem_org);
693 GlobalUnlock(medium.UNION_MEMBER(hGlobal));
694 GlobalFree(medium.UNION_MEMBER(hGlobal));
699 if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
700 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
702 if (attribs & SFGAO_READONLY)
703 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
705 if (attribs & SFGAO_COMPRESSED)
706 w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
710 static void read_directory_shell(Entry* dir, HWND hwnd)
712 IShellFolder* folder = dir->folder;
713 int level = dir->level + 1;
714 HRESULT hr;
716 IShellFolder* child;
717 IEnumIDList* idlist;
719 Entry* first_entry = NULL;
720 Entry* last = NULL;
721 Entry* entry;
723 if (!folder)
724 return;
726 hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
728 if (SUCCEEDED(hr)) {
729 for(;;) {
730 #define FETCH_ITEM_COUNT 32
731 LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
732 SFGAOF attribs;
733 ULONG cnt = 0;
734 ULONG n;
736 memset(pidls, 0, sizeof(pidls));
738 hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
739 if (FAILED(hr))
740 break;
742 if (hr == S_FALSE)
743 break;
745 for(n=0; n<cnt; ++n) {
746 entry = alloc_entry();
748 if (!first_entry)
749 first_entry = entry;
751 if (last)
752 last->next = entry;
754 memset(&entry->data, 0, sizeof(WIN32_FIND_DATAW));
755 entry->bhfi_valid = FALSE;
757 attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
759 hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
761 if (SUCCEEDED(hr)) {
762 if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
763 fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
765 entry->bhfi_valid = TRUE;
766 } else
767 attribs = 0;
768 } else
769 attribs = 0;
771 entry->pidl = pidls[n];
773 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
774 hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
776 if (SUCCEEDED(hr))
777 entry->folder = child;
778 else
779 entry->folder = NULL;
781 else
782 entry->folder = NULL;
784 if (!entry->data.cFileName[0])
785 /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
787 /* get display icons for files and virtual objects */
788 if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
789 !(attribs & SFGAO_FILESYSTEM)) {
790 entry->hicon = extract_icon(folder, pidls[n]);
792 if (!entry->hicon)
793 entry->hicon = (HICON)-1; /* don't try again later */
796 entry->down = NULL;
797 entry->up = dir;
798 entry->expanded = FALSE;
799 entry->scanned = FALSE;
800 entry->level = level;
802 entry->etype = ET_SHELL;
803 entry->bhfi_valid = FALSE;
805 last = entry;
809 IEnumIDList_Release(idlist);
812 if (last)
813 last->next = NULL;
815 dir->down = first_entry;
816 dir->scanned = TRUE;
819 /* sort order for different directory/file types */
820 enum TYPE_ORDER {
821 TO_DIR = 0,
822 TO_DOT = 1,
823 TO_DOTDOT = 2,
824 TO_OTHER_DIR = 3,
825 TO_FILE = 4
828 /* distinguish between ".", ".." and any other directory names */
829 static int TypeOrderFromDirname(LPCWSTR name)
831 if (name[0] == '.') {
832 if (name[1] == '\0')
833 return TO_DOT; /* "." */
835 if (name[1]=='.' && name[2]=='\0')
836 return TO_DOTDOT; /* ".." */
839 return TO_OTHER_DIR; /* anything else */
842 /* directories first... */
843 static int compareType(const WIN32_FIND_DATAW* fd1, const WIN32_FIND_DATAW* fd2)
845 int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
846 int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
848 /* Handle "." and ".." as special case and move them at the very first beginning. */
849 if (order1==TO_DIR && order2==TO_DIR) {
850 order1 = TypeOrderFromDirname(fd1->cFileName);
851 order2 = TypeOrderFromDirname(fd2->cFileName);
854 return order2==order1? 0: order1<order2? -1: 1;
858 static int __cdecl compareName(const void* arg1, const void* arg2)
860 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
861 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
863 int cmp = compareType(fd1, fd2);
864 if (cmp)
865 return cmp;
867 return lstrcmpiW(fd1->cFileName, fd2->cFileName);
870 static int __cdecl compareExt(const void* arg1, const void* arg2)
872 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
873 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
874 const WCHAR *name1, *name2, *ext1, *ext2;
876 int cmp = compareType(fd1, fd2);
877 if (cmp)
878 return cmp;
880 name1 = fd1->cFileName;
881 name2 = fd2->cFileName;
883 ext1 = wcsrchr(name1, '.');
884 ext2 = wcsrchr(name2, '.');
886 if (ext1)
887 ext1++;
888 else
889 ext1 = sEmpty;
891 if (ext2)
892 ext2++;
893 else
894 ext2 = sEmpty;
896 cmp = lstrcmpiW(ext1, ext2);
897 if (cmp)
898 return cmp;
900 return lstrcmpiW(name1, name2);
903 static int __cdecl compareSize(const void* arg1, const void* arg2)
905 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
906 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
908 int cmp = compareType(fd1, fd2);
909 if (cmp)
910 return cmp;
912 cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
914 if (cmp < 0)
915 return -1;
916 else if (cmp > 0)
917 return 1;
919 cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
921 return cmp<0? -1: cmp>0? 1: 0;
924 static int __cdecl compareDate(const void* arg1, const void* arg2)
926 const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
927 const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
929 int cmp = compareType(fd1, fd2);
930 if (cmp)
931 return cmp;
933 return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
937 static int (CDECL *sortFunctions[])(const void* arg1, const void* arg2) = {
938 compareName, /* SORT_NAME */
939 compareExt, /* SORT_EXT */
940 compareSize, /* SORT_SIZE */
941 compareDate /* SORT_DATE */
945 static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
947 Entry* entry;
948 Entry** array, **p;
949 int len;
951 len = 0;
952 for(entry=dir->down; entry; entry=entry->next)
953 len++;
955 if (len) {
956 array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
958 p = array;
959 for(entry=dir->down; entry; entry=entry->next)
960 *p++ = entry;
962 /* call qsort with the appropriate compare function */
963 qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
965 dir->down = array[0];
967 for(p=array; --len; p++)
968 p[0]->next = p[1];
970 (*p)->next = 0;
972 HeapFree(GetProcessHeap(), 0, array);
977 static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
979 WCHAR buffer[MAX_PATH];
980 Entry* entry;
981 LPCWSTR s;
982 PWSTR d;
984 if (dir->etype == ET_SHELL)
986 read_directory_shell(dir, hwnd);
988 if (Globals.prescan_node) {
989 s = path;
990 d = buffer;
992 while(*s)
993 *d++ = *s++;
995 *d++ = '\\';
997 for(entry=dir->down; entry; entry=entry->next)
998 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
999 read_directory_shell(entry, hwnd);
1000 SortDirectory(entry, sortOrder);
1004 else
1006 read_directory_win(dir, path);
1008 if (Globals.prescan_node) {
1009 s = path;
1010 d = buffer;
1012 while(*s)
1013 *d++ = *s++;
1015 *d++ = '\\';
1017 for(entry=dir->down; entry; entry=entry->next)
1018 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1019 lstrcpyW(d, entry->data.cFileName);
1020 read_directory_win(entry, buffer);
1021 SortDirectory(entry, sortOrder);
1026 SortDirectory(dir, sortOrder);
1030 static Entry* read_tree(Root* root, LPCWSTR path, LPITEMIDLIST pidl, LPWSTR drv, SORT_ORDER sortOrder, HWND hwnd)
1032 static const WCHAR sBackslash[] = {'\\', '\0'};
1034 if (pidl)
1036 /* read shell namespace tree */
1037 root->drive_type = DRIVE_UNKNOWN;
1038 drv[0] = '\\';
1039 drv[1] = '\0';
1040 load_string(root->volname, ARRAY_SIZE(root->volname), IDS_DESKTOP);
1041 root->fs_flags = 0;
1042 load_string(root->fs, ARRAY_SIZE(root->fs), IDS_SHELL);
1044 return read_tree_shell(root, pidl, sortOrder, hwnd);
1047 /* read WIN32 file system tree */
1048 root->drive_type = GetDriveTypeW(path);
1050 lstrcatW(drv, sBackslash);
1051 GetVolumeInformationW(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
1053 lstrcpyW(root->path, drv);
1055 return read_tree_win(root, path, sortOrder, hwnd);
1059 /* flags to filter different file types */
1060 enum TYPE_FILTER {
1061 TF_DIRECTORIES = 0x01,
1062 TF_PROGRAMS = 0x02,
1063 TF_DOCUMENTS = 0x04,
1064 TF_OTHERS = 0x08,
1065 TF_HIDDEN = 0x10,
1066 TF_ALL = 0x1F
1070 static ChildWnd* alloc_child_window(LPCWSTR path, LPITEMIDLIST pidl, HWND hwnd)
1072 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
1073 WCHAR dir_path[MAX_PATH];
1074 static const WCHAR sAsterics[] = {'*', '\0'};
1075 static const WCHAR sTitleFmt[] = {'%','s',' ','-',' ','%','s','\0'};
1077 ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
1078 Root* root = &child->root;
1079 Entry* entry;
1081 memset(child, 0, sizeof(ChildWnd));
1083 child->left.treePane = TRUE;
1084 child->left.visible_cols = 0;
1086 child->right.treePane = FALSE;
1087 child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
1089 child->pos.length = sizeof(WINDOWPLACEMENT);
1090 child->pos.flags = 0;
1091 child->pos.showCmd = SW_SHOWNORMAL;
1092 child->pos.rcNormalPosition.left = CW_USEDEFAULT;
1093 child->pos.rcNormalPosition.top = CW_USEDEFAULT;
1094 child->pos.rcNormalPosition.right = CW_USEDEFAULT;
1095 child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
1097 child->focus_pane = 0;
1098 child->split_pos = DEFAULT_SPLIT_POS;
1099 child->sortOrder = SORT_NAME;
1100 child->header_wdths_ok = FALSE;
1102 if (path)
1104 int pathlen = lstrlenW(path);
1105 const WCHAR *npath = path;
1107 if (path[0] == '"' && path[pathlen - 1] == '"')
1109 npath++;
1110 pathlen--;
1112 lstrcpynW(child->path, npath, pathlen + 1);
1114 _wsplitpath(child->path, drv, dir, name, ext);
1117 lstrcpyW(child->filter_pattern, sAsterics);
1118 child->filter_flags = TF_ALL;
1120 root->entry.level = 0;
1122 lstrcpyW(dir_path, drv);
1123 lstrcatW(dir_path, dir);
1124 entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
1126 if (root->entry.etype == ET_SHELL)
1127 load_string(root->entry.data.cFileName, ARRAY_SIZE(root->entry.data.cFileName), IDS_DESKTOP);
1128 else
1129 wsprintfW(root->entry.data.cFileName, sTitleFmt, drv, root->fs);
1131 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1133 child->left.root = &root->entry;
1134 child->right.root = NULL;
1136 set_curdir(child, entry, 0, hwnd);
1138 return child;
1142 /* free all memory associated with a child window */
1143 static void free_child_window(ChildWnd* child)
1145 free_entries(&child->root.entry);
1146 HeapFree(GetProcessHeap(), 0, child);
1150 /* get full path of specified directory entry */
1151 static void get_path(Entry* dir, PWSTR path)
1153 Entry* entry;
1154 int len = 0;
1155 int level = 0;
1157 if (dir->etype == ET_SHELL)
1159 SFGAOF attribs;
1160 HRESULT hr = S_OK;
1162 path[0] = '\0';
1164 attribs = 0;
1166 if (dir->folder)
1167 hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
1169 if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
1170 IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
1172 hr = path_from_pidlW(parent, dir->pidl, path, MAX_PATH);
1175 else
1177 for(entry=dir; entry; level++) {
1178 LPCWSTR name;
1179 int l;
1182 LPCWSTR s;
1183 name = entry->data.cFileName;
1184 s = name;
1186 for(l=0; *s && *s != '/' && *s != '\\'; s++)
1187 l++;
1190 if (entry->up) {
1191 if (l > 0) {
1192 memmove(path+l+1, path, len*sizeof(WCHAR));
1193 memcpy(path+1, name, l*sizeof(WCHAR));
1194 len += l+1;
1195 path[0] = '\\';
1198 entry = entry->up;
1199 } else {
1200 memmove(path+l, path, len*sizeof(WCHAR));
1201 memcpy(path, name, l*sizeof(WCHAR));
1202 len += l;
1203 break;
1207 if (!level) path[len++] = '\\';
1208 path[len] = '\0';
1212 static windowOptions load_registry_settings(void)
1214 DWORD size;
1215 DWORD type;
1216 HKEY hKey;
1217 windowOptions opts;
1218 LOGFONTW logfont;
1220 RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1221 0, KEY_QUERY_VALUE, &hKey );
1223 size = sizeof(opts.start_x);
1224 if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
1225 (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
1226 opts.start_x = CW_USEDEFAULT;
1228 size = sizeof(opts.start_y);
1229 if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
1230 (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
1231 opts.start_y = CW_USEDEFAULT;
1233 size = sizeof(opts.width);
1234 if( RegQueryValueExW( hKey, reg_width, NULL, &type,
1235 (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
1236 opts.width = CW_USEDEFAULT;
1238 size = sizeof(opts.height);
1239 if( RegQueryValueExW( hKey, reg_height, NULL, &type,
1240 (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
1241 opts.height = CW_USEDEFAULT;
1242 size=sizeof(logfont);
1243 if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
1244 (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
1245 GetObjectW(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
1247 RegCloseKey( hKey );
1249 Globals.hfont = CreateFontIndirectW(&logfont);
1250 return opts;
1253 static void save_registry_settings(void)
1255 WINDOWINFO wi;
1256 HKEY hKey;
1257 INT width, height;
1258 LOGFONTW logfont;
1260 wi.cbSize = sizeof( WINDOWINFO );
1261 GetWindowInfo(Globals.hMainWnd, &wi);
1262 width = wi.rcWindow.right - wi.rcWindow.left;
1263 height = wi.rcWindow.bottom - wi.rcWindow.top;
1265 if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
1266 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
1268 /* Unable to save registry settings - try to create key */
1269 if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
1270 0, NULL, REG_OPTION_NON_VOLATILE,
1271 KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
1273 /* FIXME: Cannot create key */
1274 return;
1277 /* Save all of the settings */
1278 RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
1279 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
1280 RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
1281 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
1282 RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
1283 (LPBYTE) &width, sizeof(DWORD) );
1284 RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
1285 (LPBYTE) &height, sizeof(DWORD) );
1286 GetObjectW(Globals.hfont, sizeof(logfont), &logfont);
1287 RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
1288 (LPBYTE)&logfont, sizeof(LOGFONTW) );
1290 /* TODO: Save more settings here (List vs. Detailed View, etc.) */
1291 RegCloseKey( hKey );
1294 static void resize_frame_rect(HWND hwnd, PRECT prect)
1296 int new_top;
1297 RECT rt;
1299 if (IsWindowVisible(Globals.htoolbar)) {
1300 SendMessageW(Globals.htoolbar, WM_SIZE, 0, 0);
1301 GetClientRect(Globals.htoolbar, &rt);
1302 prect->top = rt.bottom+3;
1303 prect->bottom -= rt.bottom+3;
1306 if (IsWindowVisible(Globals.hdrivebar)) {
1307 SendMessageW(Globals.hdrivebar, WM_SIZE, 0, 0);
1308 GetClientRect(Globals.hdrivebar, &rt);
1309 new_top = --prect->top + rt.bottom+3;
1310 MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
1311 prect->top = new_top;
1312 prect->bottom -= rt.bottom+2;
1315 if (IsWindowVisible(Globals.hstatusbar)) {
1316 int parts[] = {300, 500};
1318 SendMessageW(Globals.hstatusbar, WM_SIZE, 0, 0);
1319 SendMessageW(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1320 GetClientRect(Globals.hstatusbar, &rt);
1321 prect->bottom -= rt.bottom;
1324 MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
1327 static void resize_frame(HWND hwnd, int cx, int cy)
1329 RECT rect;
1331 rect.left = 0;
1332 rect.top = 0;
1333 rect.right = cx;
1334 rect.bottom = cy;
1336 resize_frame_rect(hwnd, &rect);
1339 static void resize_frame_client(HWND hwnd)
1341 RECT rect;
1343 GetClientRect(hwnd, &rect);
1345 resize_frame_rect(hwnd, &rect);
1349 static HHOOK hcbthook;
1350 static ChildWnd* newchild = NULL;
1352 static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
1354 if (code==HCBT_CREATEWND && newchild) {
1355 ChildWnd* child = newchild;
1356 newchild = NULL;
1358 child->hwnd = (HWND) wparam;
1359 SetWindowLongPtrW(child->hwnd, GWLP_USERDATA, (LPARAM)child);
1362 return CallNextHookEx(hcbthook, code, wparam, lparam);
1365 static HWND create_child_window(ChildWnd* child)
1367 MDICREATESTRUCTW mcs;
1368 int idx;
1370 mcs.szClass = sWINEFILETREE;
1371 mcs.szTitle = child->path;
1372 mcs.hOwner = Globals.hInstance;
1373 mcs.x = child->pos.rcNormalPosition.left;
1374 mcs.y = child->pos.rcNormalPosition.top;
1375 mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
1376 mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
1377 mcs.style = 0;
1378 mcs.lParam = 0;
1380 hcbthook = SetWindowsHookExW(WH_CBT, CBTProc, 0, GetCurrentThreadId());
1382 newchild = child;
1383 child->hwnd = (HWND)SendMessageW(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
1384 if (!child->hwnd) {
1385 UnhookWindowsHookEx(hcbthook);
1386 return 0;
1389 UnhookWindowsHookEx(hcbthook);
1391 SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1392 SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
1394 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
1395 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
1397 return child->hwnd;
1400 #define RFF_NODEFAULT 0x02 /* No default item selected. */
1402 static void WineFile_OnRun( HWND hwnd )
1404 static const WCHAR shell32_dll[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
1405 void (WINAPI *pRunFileDlgAW )(HWND, HICON, LPWSTR, LPWSTR, LPWSTR, DWORD);
1406 HMODULE hshell = GetModuleHandleW( shell32_dll );
1407 HICON hIcon = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE));
1409 pRunFileDlgAW = (void*)GetProcAddress(hshell, (LPCSTR)61);
1410 if (pRunFileDlgAW) pRunFileDlgAW( hwnd, hIcon, NULL, NULL, NULL, RFF_NODEFAULT);
1413 static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1415 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1417 switch(nmsg) {
1418 case WM_INITDIALOG:
1419 SetWindowLongPtrW(hwnd, GWLP_USERDATA, lparam);
1420 SetWindowTextW(GetDlgItem(hwnd, 201), (LPCWSTR)lparam);
1421 return 1;
1423 case WM_COMMAND: {
1424 int id = (int)wparam;
1426 switch(id) {
1427 case IDOK: {
1428 LPWSTR dest = (LPWSTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
1429 GetWindowTextW(GetDlgItem(hwnd, 201), dest, MAX_PATH);
1430 EndDialog(hwnd, id);
1431 break;}
1433 case IDCANCEL:
1434 EndDialog(hwnd, id);
1435 break;
1437 case 254:
1438 MessageBoxW(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
1439 break;
1442 return 1;
1446 return 0;
1450 struct FilterDialog {
1451 WCHAR pattern[MAX_PATH];
1452 int flags;
1455 static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1457 static struct FilterDialog* dlg;
1459 switch(nmsg) {
1460 case WM_INITDIALOG:
1461 dlg = (struct FilterDialog*) lparam;
1462 SetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
1463 set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
1464 set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
1465 set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
1466 set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
1467 set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
1468 return 1;
1470 case WM_COMMAND: {
1471 int id = (int)wparam;
1473 if (id == IDOK) {
1474 int flags = 0;
1476 GetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
1478 flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
1479 flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
1480 flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
1481 flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
1482 flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
1484 dlg->flags = flags;
1486 EndDialog(hwnd, id);
1487 } else if (id == IDCANCEL)
1488 EndDialog(hwnd, id);
1490 return 1;}
1493 return 0;
1497 struct PropertiesDialog {
1498 WCHAR path[MAX_PATH];
1499 Entry entry;
1500 void* pVersionData;
1503 /* Structure used to store enumerated languages and code pages. */
1504 struct LANGANDCODEPAGE {
1505 WORD wLanguage;
1506 WORD wCodePage;
1507 } *lpTranslate;
1509 static LPCSTR InfoStrings[] = {
1510 "Comments",
1511 "CompanyName",
1512 "FileDescription",
1513 "FileVersion",
1514 "InternalName",
1515 "LegalCopyright",
1516 "LegalTrademarks",
1517 "OriginalFilename",
1518 "PrivateBuild",
1519 "ProductName",
1520 "ProductVersion",
1521 "SpecialBuild",
1522 NULL
1525 static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
1527 int idx = SendMessageW(hlbox, LB_GETCURSEL, 0, 0);
1529 if (idx != LB_ERR) {
1530 LPCWSTR pValue = (LPCWSTR)SendMessageW(hlbox, LB_GETITEMDATA, idx, 0);
1532 if (pValue)
1533 SetWindowTextW(hedit, pValue);
1537 static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCWSTR strFilename)
1539 static const WCHAR sBackSlash[] = {'\\','\0'};
1540 static const 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'};
1541 static const WCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
1542 '%','0','4','x','%','0','4','x','\\','%','s','\0'};
1543 static const WCHAR sFmt[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
1544 DWORD dwVersionDataLen = GetFileVersionInfoSizeW(strFilename, NULL);
1546 if (dwVersionDataLen) {
1547 dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
1549 if (GetFileVersionInfoW(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
1550 LPVOID pVal;
1551 UINT nValLen;
1553 if (VerQueryValueW(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
1554 if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
1555 VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
1556 WCHAR buffer[BUFFER_LEN];
1558 swprintf(buffer, ARRAY_SIZE(buffer), sFmt,
1559 HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
1560 HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
1562 SetDlgItemTextW(hwnd, IDC_STATIC_PROP_VERSION, buffer);
1566 /* Read the list of languages and code pages. */
1567 if (VerQueryValueW(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
1568 struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
1569 struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
1571 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1573 /* Read the file description for each language and code page. */
1574 for(; pTranslate<pEnd; ++pTranslate) {
1575 LPCSTR* p;
1577 for(p=InfoStrings; *p; ++p) {
1578 WCHAR subblock[200];
1579 WCHAR infoStr[100];
1580 LPCWSTR pTxt;
1581 UINT nValLen;
1583 LPCSTR pInfoString = *p;
1584 MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
1585 wsprintfW(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
1587 /* Retrieve file description for language and code page */
1588 if (VerQueryValueW(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
1589 int idx = SendMessageW(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
1590 SendMessageW(hlbox, LB_SETITEMDATA, idx, (LPARAM)pTxt);
1595 SendMessageW(hlbox, LB_SETCURSEL, 0, 0);
1597 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1603 static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1605 static struct PropertiesDialog* dlg;
1607 switch(nmsg) {
1608 case WM_INITDIALOG: {
1609 static const WCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
1610 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1611 LPWIN32_FIND_DATAW pWFD;
1613 dlg = (struct PropertiesDialog*) lparam;
1614 pWFD = (LPWIN32_FIND_DATAW)&dlg->entry.data;
1616 GetWindowTextW(hwnd, b1, MAX_PATH);
1617 wsprintfW(b2, b1, pWFD->cFileName);
1618 SetWindowTextW(hwnd, b2);
1620 format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
1621 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
1623 format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
1624 wsprintfW(b2, sByteFmt, b1);
1625 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
1627 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
1628 SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
1630 set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
1631 set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
1632 set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
1633 set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
1634 set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
1636 CheckForFileInfo(dlg, hwnd, dlg->path);
1637 return 1;}
1639 case WM_COMMAND: {
1640 int id = (int)wparam;
1642 switch(HIWORD(wparam)) {
1643 case LBN_SELCHANGE: {
1644 HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
1645 PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
1646 break;
1649 case BN_CLICKED:
1650 if (id==IDOK || id==IDCANCEL)
1651 EndDialog(hwnd, id);
1654 return 1;}
1656 case WM_NCDESTROY:
1657 HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
1658 dlg->pVersionData = NULL;
1659 break;
1662 return 0;
1665 static void show_properties_dlg(Entry* entry, HWND hwnd)
1667 struct PropertiesDialog dlg;
1669 memset(&dlg, 0, sizeof(struct PropertiesDialog));
1670 get_path(entry, dlg.path);
1671 memcpy(&dlg.entry, entry, sizeof(Entry));
1673 DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
1676 static struct FullScreenParameters {
1677 BOOL mode;
1678 RECT orgPos;
1679 BOOL wasZoomed;
1680 } g_fullscreen = {
1681 FALSE, /* mode */
1682 {0, 0, 0, 0},
1683 FALSE
1686 static void frame_get_clientspace(HWND hwnd, PRECT prect)
1688 RECT rt;
1690 if (!IsIconic(hwnd))
1691 GetClientRect(hwnd, prect);
1692 else {
1693 WINDOWPLACEMENT wp;
1695 wp.length = sizeof(wp);
1696 GetWindowPlacement(hwnd, &wp);
1698 prect->left = prect->top = 0;
1699 prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
1700 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
1701 prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
1702 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
1703 GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
1706 if (IsWindowVisible(Globals.htoolbar)) {
1707 GetClientRect(Globals.htoolbar, &rt);
1708 prect->top += rt.bottom+2;
1711 if (IsWindowVisible(Globals.hdrivebar)) {
1712 GetClientRect(Globals.hdrivebar, &rt);
1713 prect->top += rt.bottom+2;
1716 if (IsWindowVisible(Globals.hstatusbar)) {
1717 GetClientRect(Globals.hstatusbar, &rt);
1718 prect->bottom -= rt.bottom;
1722 static BOOL toggle_fullscreen(HWND hwnd)
1724 RECT rt;
1726 if ((g_fullscreen.mode=!g_fullscreen.mode)) {
1727 GetWindowRect(hwnd, &g_fullscreen.orgPos);
1728 g_fullscreen.wasZoomed = IsZoomed(hwnd);
1730 Frame_CalcFrameClient(hwnd, &rt);
1731 MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
1733 rt.left = g_fullscreen.orgPos.left-rt.left;
1734 rt.top = g_fullscreen.orgPos.top-rt.top;
1735 rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
1736 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
1738 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1739 } else {
1740 MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
1741 g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
1742 g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
1744 if (g_fullscreen.wasZoomed)
1745 ShowWindow(hwnd, WS_MAXIMIZE);
1748 return g_fullscreen.mode;
1751 static void fullscreen_move(HWND hwnd)
1753 RECT rt, pos;
1754 GetWindowRect(hwnd, &pos);
1756 Frame_CalcFrameClient(hwnd, &rt);
1757 MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
1759 rt.left = pos.left-rt.left;
1760 rt.top = pos.top-rt.top;
1761 rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
1762 rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
1764 MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
1767 static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
1769 BOOL vis = IsWindowVisible(hchild);
1771 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
1773 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
1775 if (g_fullscreen.mode)
1776 fullscreen_move(hwnd);
1778 resize_frame_client(hwnd);
1781 static BOOL activate_drive_window(LPCWSTR path)
1783 WCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1784 HWND child_wnd;
1786 _wsplitpath(path, drv1, 0, 0, 0);
1788 /* search for an already open window for the same drive */
1789 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1790 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
1792 if (child) {
1793 _wsplitpath(child->root.path, drv2, 0, 0, 0);
1795 if (!lstrcmpiW(drv2, drv1)) {
1796 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1798 if (IsIconic(child_wnd))
1799 ShowWindow(child_wnd, SW_SHOWNORMAL);
1801 return TRUE;
1806 return FALSE;
1809 static BOOL activate_fs_window(LPCWSTR filesys)
1811 HWND child_wnd;
1813 /* search for an already open window of the given file system name */
1814 for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1815 ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
1817 if (child) {
1818 if (!lstrcmpiW(child->root.fs, filesys)) {
1819 SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1821 if (IsIconic(child_wnd))
1822 ShowWindow(child_wnd, SW_SHOWNORMAL);
1824 return TRUE;
1829 return FALSE;
1832 static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
1834 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
1836 switch(nmsg) {
1837 case WM_CLOSE:
1838 if (Globals.saveSettings)
1839 save_registry_settings();
1841 DestroyWindow(hwnd);
1843 /* clear handle variables */
1844 Globals.hMenuFrame = 0;
1845 Globals.hMenuView = 0;
1846 Globals.hMenuOptions = 0;
1847 Globals.hMainWnd = 0;
1848 Globals.hmdiclient = 0;
1849 Globals.hdrivebar = 0;
1850 break;
1852 case WM_DESTROY:
1853 PostQuitMessage(0);
1854 break;
1856 case WM_INITMENUPOPUP: {
1857 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1859 if (!SendMessageW(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
1860 return 0;
1861 break;}
1863 case WM_COMMAND: {
1864 UINT cmd = LOWORD(wparam);
1865 HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
1867 if (SendMessageW(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
1868 break;
1870 if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
1871 WCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1872 ChildWnd* child;
1873 LPCWSTR root = Globals.drives;
1874 int i;
1876 for(i=cmd-ID_DRIVE_FIRST; i--; root++)
1877 while(*root)
1878 root++;
1880 if (activate_drive_window(root))
1881 return 0;
1883 _wsplitpath(root, drv, 0, 0, 0);
1885 if (!SetCurrentDirectoryW(drv)) {
1886 display_error(hwnd, GetLastError());
1887 return 0;
1890 GetCurrentDirectoryW(MAX_PATH, path); /*TODO: store last directory per drive */
1891 child = alloc_child_window(path, NULL, hwnd);
1893 if (!create_child_window(child))
1894 HeapFree(GetProcessHeap(), 0, child);
1895 } else switch(cmd) {
1896 case ID_FILE_EXIT:
1897 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1898 break;
1900 case ID_WINDOW_NEW: {
1901 WCHAR path[MAX_PATH];
1902 ChildWnd* child;
1904 GetCurrentDirectoryW(MAX_PATH, path);
1905 child = alloc_child_window(path, NULL, hwnd);
1907 if (!create_child_window(child))
1908 HeapFree(GetProcessHeap(), 0, child);
1909 break;}
1911 case ID_REFRESH:
1912 refresh_drives();
1913 break;
1915 case ID_WINDOW_CASCADE:
1916 SendMessageW(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
1917 break;
1919 case ID_WINDOW_TILE_HORZ:
1920 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1921 break;
1923 case ID_WINDOW_TILE_VERT:
1924 SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1925 break;
1927 case ID_WINDOW_ARRANGE:
1928 SendMessageW(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
1929 break;
1931 case ID_SELECT_FONT:
1932 choose_font(hwnd);
1933 break;
1935 case ID_VIEW_TOOL_BAR:
1936 toggle_child(hwnd, cmd, Globals.htoolbar);
1937 break;
1939 case ID_VIEW_DRIVE_BAR:
1940 toggle_child(hwnd, cmd, Globals.hdrivebar);
1941 break;
1943 case ID_VIEW_STATUSBAR:
1944 toggle_child(hwnd, cmd, Globals.hstatusbar);
1945 break;
1947 case ID_VIEW_SAVESETTINGS:
1948 Globals.saveSettings = !Globals.saveSettings;
1949 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
1950 Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
1951 break;
1953 case ID_RUN:
1954 WineFile_OnRun( hwnd );
1955 break;
1957 case ID_CONNECT_NETWORK_DRIVE: {
1958 DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
1959 if (ret == NO_ERROR)
1960 refresh_drives();
1961 else if (ret != (DWORD)-1) {
1962 if (ret == ERROR_EXTENDED_ERROR)
1963 display_network_error(hwnd);
1964 else
1965 display_error(hwnd, ret);
1967 break;}
1969 case ID_DISCONNECT_NETWORK_DRIVE: {
1970 DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
1971 if (ret == NO_ERROR)
1972 refresh_drives();
1973 else if (ret != (DWORD)-1) {
1974 if (ret == ERROR_EXTENDED_ERROR)
1975 display_network_error(hwnd);
1976 else
1977 display_error(hwnd, ret);
1979 break;}
1981 case ID_HELP:
1982 WinHelpW(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
1983 break;
1985 case ID_VIEW_FULLSCREEN:
1986 CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
1987 break;
1989 case ID_DRIVE_SHELL_NS: {
1990 WCHAR path[MAX_PATH];
1991 ChildWnd* child;
1993 if (activate_fs_window(RS(b1,IDS_SHELL)))
1994 break;
1996 GetCurrentDirectoryW(MAX_PATH, path);
1997 child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
1999 if (!create_child_window(child))
2000 HeapFree(GetProcessHeap(), 0, child);
2001 break;}
2003 /*TODO: There are even more menu items! */
2005 case ID_ABOUT:
2006 ShellAboutW(hwnd, RS(b1,IDS_WINEFILE), NULL,
2007 LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE),
2008 IMAGE_ICON, 48, 48, LR_SHARED ));
2009 break;
2011 default:
2012 /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
2013 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
2014 else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
2015 (cmd<SC_SIZE || cmd>SC_RESTORE))
2016 MessageBoxW(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
2018 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2020 break;}
2022 case WM_SIZE:
2023 resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
2024 break; /* do not pass message to DefFrameProcW */
2026 case WM_DEVICECHANGE:
2027 SendMessageW(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
2028 break;
2030 case WM_GETMINMAXINFO: {
2031 LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
2033 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
2034 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
2035 break;}
2037 case FRM_CALC_CLIENT:
2038 frame_get_clientspace(hwnd, (PRECT)lparam);
2039 return TRUE;
2041 default:
2042 return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
2045 return 0;
2049 static WCHAR g_pos_names[COLUMNS][40] = {
2050 {'\0'} /* symbol */
2053 static const int g_pos_align[] = {
2055 HDF_LEFT, /* Name */
2056 HDF_RIGHT, /* Size */
2057 HDF_LEFT, /* CDate */
2058 HDF_LEFT, /* ADate */
2059 HDF_LEFT, /* MDate */
2060 HDF_LEFT, /* Index */
2061 HDF_CENTER, /* Links */
2062 HDF_CENTER, /* Attributes */
2063 HDF_LEFT /* Security */
2066 static void resize_tree(ChildWnd* child, int cx, int cy)
2068 HDWP hdwp = BeginDeferWindowPos(4);
2069 RECT rt;
2070 WINDOWPOS wp;
2071 HD_LAYOUT hdl;
2073 rt.left = 0;
2074 rt.top = 0;
2075 rt.right = cx;
2076 rt.bottom = cy;
2078 cx = child->split_pos + SPLIT_WIDTH/2;
2079 hdl.prc = &rt;
2080 hdl.pwpos = &wp;
2082 SendMessageW(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
2084 DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
2085 wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
2086 DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
2087 rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
2088 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);
2089 DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
2091 EndDeferWindowPos(hdwp);
2094 static HWND create_header(HWND parent, Pane* pane, UINT id)
2096 HDITEMW hdi;
2097 int idx;
2099 HWND hwnd = CreateWindowW(WC_HEADERW, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
2100 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2101 if (!hwnd)
2102 return 0;
2104 SendMessageW(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
2106 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
2108 for(idx=0; idx<COLUMNS; idx++) {
2109 hdi.pszText = g_pos_names[idx];
2110 hdi.fmt = HDF_STRING | g_pos_align[idx];
2111 hdi.cxy = pane->widths[idx];
2112 pane->widths_shown[idx] = hdi.cxy;
2113 SendMessageW(hwnd, HDM_INSERTITEMW, idx, (LPARAM)&hdi);
2116 return hwnd;
2119 static void init_output(HWND hwnd)
2121 static const WCHAR s1000[] = {'1','0','0','0','\0'};
2122 WCHAR b[16];
2123 HFONT old_font;
2124 HDC hdc = GetDC(hwnd);
2126 if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
2127 Globals.num_sep = b[1];
2128 else
2129 Globals.num_sep = '.';
2131 old_font = SelectObject(hdc, Globals.hfont);
2132 GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
2133 SelectObject(hdc, old_font);
2134 ReleaseDC(hwnd, hdc);
2137 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
2140 /* calculate preferred width for all visible columns */
2142 static BOOL calc_widths(Pane* pane, BOOL anyway)
2144 int col, x, cx, spc=3*Globals.spaceSize.cx;
2145 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2146 int orgWidths[COLUMNS];
2147 int orgPositions[COLUMNS+1];
2148 HFONT hfontOld;
2149 HDC hdc;
2150 int cnt;
2152 if (!anyway) {
2153 memcpy(orgWidths, pane->widths, sizeof(orgWidths));
2154 memcpy(orgPositions, pane->positions, sizeof(orgPositions));
2157 for(col=0; col<COLUMNS; col++)
2158 pane->widths[col] = 0;
2160 hdc = GetDC(pane->hwnd);
2161 hfontOld = SelectObject(hdc, Globals.hfont);
2163 for(cnt=0; cnt<entries; cnt++) {
2164 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2166 DRAWITEMSTRUCT dis;
2168 dis.CtlType = 0;
2169 dis.CtlID = 0;
2170 dis.itemID = 0;
2171 dis.itemAction = 0;
2172 dis.itemState = 0;
2173 dis.hwndItem = pane->hwnd;
2174 dis.hDC = hdc;
2175 SetRectEmpty(&dis.rcItem);
2176 /*dis.itemData = 0; */
2178 draw_item(pane, &dis, entry, COLUMNS);
2181 SelectObject(hdc, hfontOld);
2182 ReleaseDC(pane->hwnd, hdc);
2184 x = 0;
2185 for(col=0; col<COLUMNS; col++) {
2186 pane->positions[col] = x;
2187 cx = pane->widths[col];
2189 if (cx) {
2190 cx += spc;
2192 if (cx < IMAGE_WIDTH)
2193 cx = IMAGE_WIDTH;
2195 pane->widths[col] = cx;
2198 x += cx;
2201 pane->positions[COLUMNS] = x;
2203 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2205 /* no change? */
2206 if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
2207 return FALSE;
2209 /* don't move, if only collapsing an entry */
2210 if (!anyway && pane->widths[0]<orgWidths[0] &&
2211 !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
2212 pane->widths[0] = orgWidths[0];
2213 memcpy(pane->positions, orgPositions, sizeof(orgPositions));
2215 return FALSE;
2218 InvalidateRect(pane->hwnd, 0, TRUE);
2220 return TRUE;
2223 /* calculate one preferred column width */
2224 static void calc_single_width(Pane* pane, int col)
2226 HFONT hfontOld;
2227 int x, cx;
2228 int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
2229 int cnt;
2230 HDC hdc;
2232 pane->widths[col] = 0;
2234 hdc = GetDC(pane->hwnd);
2235 hfontOld = SelectObject(hdc, Globals.hfont);
2237 for(cnt=0; cnt<entries; cnt++) {
2238 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
2239 DRAWITEMSTRUCT dis;
2241 dis.CtlType = 0;
2242 dis.CtlID = 0;
2243 dis.itemID = 0;
2244 dis.itemAction = 0;
2245 dis.itemState = 0;
2246 dis.hwndItem = pane->hwnd;
2247 dis.hDC = hdc;
2248 SetRectEmpty(&dis.rcItem);
2249 /*dis.itemData = 0; */
2251 draw_item(pane, &dis, entry, col);
2254 SelectObject(hdc, hfontOld);
2255 ReleaseDC(pane->hwnd, hdc);
2257 cx = pane->widths[col];
2259 if (cx) {
2260 cx += 3*Globals.spaceSize.cx;
2262 if (cx < IMAGE_WIDTH)
2263 cx = IMAGE_WIDTH;
2266 pane->widths[col] = cx;
2268 x = pane->positions[col] + cx;
2270 for(; col<COLUMNS-1; ) {
2271 pane->positions[++col] = x;
2272 x += pane->widths[col];
2275 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
2278 static BOOL pattern_match(LPCWSTR str, LPCWSTR pattern)
2280 for( ; *str&&*pattern; str++,pattern++) {
2281 if (*pattern == '*') {
2282 do pattern++;
2283 while(*pattern == '*');
2285 if (!*pattern)
2286 return TRUE;
2288 for(; *str; str++)
2289 if (*str==*pattern && pattern_match(str, pattern))
2290 return TRUE;
2292 return FALSE;
2294 else if (*str!=*pattern && *pattern!='?')
2295 return FALSE;
2298 if (*str || *pattern)
2299 if (*pattern!='*' || pattern[1]!='\0')
2300 return FALSE;
2302 return TRUE;
2305 static BOOL pattern_imatch(LPCWSTR str, LPCWSTR pattern)
2307 WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
2309 lstrcpyW(b1, str);
2310 lstrcpyW(b2, pattern);
2311 CharUpperW(b1);
2312 CharUpperW(b2);
2314 return pattern_match(b1, b2);
2318 enum FILE_TYPE {
2319 FT_OTHER = 0,
2320 FT_EXECUTABLE = 1,
2321 FT_DOCUMENT = 2
2324 static enum FILE_TYPE get_file_type(LPCWSTR filename);
2327 /* insert listbox entries after index idx */
2329 static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_flags, int idx)
2331 Entry* entry = dir;
2333 if (!entry)
2334 return idx;
2336 ShowWindow(pane->hwnd, SW_HIDE);
2338 for(; entry; entry=entry->next) {
2339 if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2340 continue;
2342 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2343 /* don't display entries "." and ".." in the left pane */
2344 if (pane->treePane && entry->data.cFileName[0] == '.')
2345 if (entry->data.cFileName[1] == '\0' ||
2346 (entry->data.cFileName[1] == '.' &&
2347 entry->data.cFileName[2] == '\0'))
2348 continue;
2350 /* filter directories in right pane */
2351 if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
2352 continue;
2355 /* filter using the file name pattern */
2356 if (pattern)
2357 if (!pattern_imatch(entry->data.cFileName, pattern))
2358 continue;
2360 /* filter system and hidden files */
2361 if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
2362 continue;
2364 /* filter looking at the file type */
2365 if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
2366 switch(get_file_type(entry->data.cFileName)) {
2367 case FT_EXECUTABLE:
2368 if (!(filter_flags & TF_PROGRAMS))
2369 continue;
2370 break;
2372 case FT_DOCUMENT:
2373 if (!(filter_flags & TF_DOCUMENTS))
2374 continue;
2375 break;
2377 default: /* TF_OTHERS */
2378 if (!(filter_flags & TF_OTHERS))
2379 continue;
2382 if (idx != -1)
2383 idx++;
2385 SendMessageW(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM)entry);
2387 if (pane->treePane && entry->expanded)
2388 idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
2391 ShowWindow(pane->hwnd, SW_SHOW);
2393 return idx;
2396 static void set_space_status(void)
2398 ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
2399 WCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
2401 if (GetDiskFreeSpaceExW(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
2402 DWORD_PTR args[2];
2404 args[0] = (DWORD_PTR)StrFormatByteSizeW(ulFreeBytesToCaller.QuadPart, b1, ARRAY_SIZE(b1));
2405 args[1] = (DWORD_PTR)StrFormatByteSizeW(ulTotalBytes.QuadPart, b2, ARRAY_SIZE(b2));
2407 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
2408 RS(fmt,IDS_FREE_SPACE_FMT), 0, 0, buffer, ARRAY_SIZE(buffer), (va_list *)args);
2409 } else
2410 lstrcpyW(buffer, sQMarks);
2412 SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
2416 static WNDPROC g_orgTreeWndProc;
2418 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
2420 static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2422 static BOOL s_init = FALSE;
2423 Entry* entry = pane->root;
2425 pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2426 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2427 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2429 SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2430 g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2432 SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2434 /* insert entries into listbox */
2435 if (entry)
2436 insert_entries(pane, entry, pattern, filter_flags, -1);
2438 /* calculate column widths */
2439 if (!s_init) {
2440 s_init = TRUE;
2441 init_output(pane->hwnd);
2444 calc_widths(pane, TRUE);
2446 pane->hwndHeader = create_header(parent, pane, id_header);
2450 static void InitChildWindow(ChildWnd* child)
2452 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2453 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2457 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
2459 SYSTEMTIME systime;
2460 FILETIME lft;
2461 int len = 0;
2463 *buffer = '\0';
2465 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2466 return;
2468 if (!FileTimeToLocalFileTime(ft, &lft))
2469 {err: lstrcpyW(buffer,sQMarks); return;}
2471 if (!FileTimeToSystemTime(&lft, &systime))
2472 goto err;
2474 if (visible_cols & COL_DATE) {
2475 len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2476 if (!len)
2477 goto err;
2480 if (visible_cols & COL_TIME) {
2481 if (len)
2482 buffer[len-1] = ' ';
2484 buffer[len++] = ' ';
2486 if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2487 buffer[len] = '\0';
2492 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2494 RECT rt = {0, 0, 0, 0};
2496 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2498 if (rt.right > pane->widths[col])
2499 pane->widths[col] = rt.right;
2502 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2504 RECT rt = {0, 0, 0, 0};
2506 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2507 /*FIXME rt (0,0) ??? */
2509 if (rt.right > pane->widths[col])
2510 pane->widths[col] = rt.right;
2514 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
2516 int x = dis->rcItem.left;
2517 RECT rt;
2519 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2520 rt.top = dis->rcItem.top;
2521 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2522 rt.bottom = dis->rcItem.bottom;
2524 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2527 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2529 int x = dis->rcItem.left;
2530 RECT rt;
2532 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2533 rt.top = dis->rcItem.top;
2534 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2535 rt.bottom = dis->rcItem.bottom;
2537 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2540 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2542 int x = dis->rcItem.left;
2543 RECT rt;
2544 LPCWSTR s = str;
2545 WCHAR b[128];
2546 LPWSTR d = b;
2547 int pos;
2549 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2550 rt.top = dis->rcItem.top;
2551 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2552 rt.bottom = dis->rcItem.bottom;
2554 if (*s)
2555 *d++ = *s++;
2557 /* insert number separator characters */
2558 pos = lstrlenW(s) % 3;
2560 while(*s)
2561 if (pos--)
2562 *d++ = *s++;
2563 else {
2564 *d++ = Globals.num_sep;
2565 pos = 3;
2568 DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2572 static BOOL is_exe_file(LPCWSTR ext)
2574 static const WCHAR executable_extensions[][4] = {
2575 {'C','O','M','\0'},
2576 {'E','X','E','\0'},
2577 {'B','A','T','\0'},
2578 {'C','M','D','\0'},
2579 {'C','M','M','\0'},
2580 {'B','T','M','\0'},
2581 {'A','W','K','\0'},
2582 {'\0'}
2585 WCHAR ext_buffer[_MAX_EXT];
2586 const WCHAR (*p)[4];
2587 LPCWSTR s;
2588 LPWSTR d;
2590 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2591 d++;
2593 for(p=executable_extensions; (*p)[0]; p++)
2594 if (!lstrcmpiW(ext_buffer, *p))
2595 return TRUE;
2597 return FALSE;
2600 static BOOL is_registered_type(LPCWSTR ext)
2602 /* check if there exists a classname for this file extension in the registry */
2603 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2604 return TRUE;
2606 return FALSE;
2609 static enum FILE_TYPE get_file_type(LPCWSTR filename)
2611 LPCWSTR ext = wcsrchr(filename, '.');
2612 if (!ext)
2613 ext = sEmpty;
2615 if (is_exe_file(ext))
2616 return FT_EXECUTABLE;
2617 else if (is_registered_type(ext))
2618 return FT_DOCUMENT;
2619 else
2620 return FT_OTHER;
2624 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2626 WCHAR buffer[BUFFER_LEN];
2627 DWORD attrs;
2628 int visible_cols = pane->visible_cols;
2629 COLORREF bkcolor, textcolor;
2630 RECT focusRect = dis->rcItem;
2631 HBRUSH hbrush;
2632 enum IMAGE img;
2633 int img_pos, cx;
2634 int col = 0;
2636 if (entry) {
2637 attrs = entry->data.dwFileAttributes;
2639 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2640 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
2641 && entry->data.cFileName[2] == '\0')
2642 img = IMG_FOLDER_UP;
2643 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
2644 img = IMG_FOLDER_CUR;
2645 else if (pane->treePane && (dis->itemState&ODS_FOCUS))
2646 img = IMG_OPEN_FOLDER;
2647 else
2648 img = IMG_FOLDER;
2649 } else {
2650 switch(get_file_type(entry->data.cFileName)) {
2651 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
2652 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
2653 default: img = IMG_FILE;
2656 } else {
2657 attrs = 0;
2658 img = IMG_NONE;
2661 if (pane->treePane) {
2662 if (entry) {
2663 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
2665 if (calcWidthCol == -1) {
2666 int x;
2667 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2668 Entry* up;
2669 RECT rt_clip;
2670 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2671 HRGN hrgn;
2673 rt_clip.left = dis->rcItem.left;
2674 rt_clip.top = dis->rcItem.top;
2675 rt_clip.right = dis->rcItem.left+pane->widths[col];
2676 rt_clip.bottom = dis->rcItem.bottom;
2678 hrgn = CreateRectRgnIndirect(&rt_clip);
2680 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2681 DeleteObject(hrgn_org);
2682 hrgn_org = 0;
2685 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2686 DeleteObject(hrgn);
2688 if ((up=entry->up) != NULL) {
2689 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2690 LineTo(dis->hDC, img_pos-2, y);
2692 x = img_pos - IMAGE_WIDTH/2;
2694 do {
2695 x -= IMAGE_WIDTH+TREE_LINE_DX;
2697 if (up->next
2698 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2700 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2701 LineTo(dis->hDC, x, dis->rcItem.bottom);
2703 } while((up=up->up) != NULL);
2706 x = img_pos - IMAGE_WIDTH/2;
2708 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2709 LineTo(dis->hDC, x, y);
2711 if (entry->next
2712 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2713 LineTo(dis->hDC, x, dis->rcItem.bottom);
2715 SelectClipRgn(dis->hDC, hrgn_org);
2716 if (hrgn_org) DeleteObject(hrgn_org);
2717 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2718 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
2720 if (right > pane->widths[col])
2721 pane->widths[col] = right;
2723 } else {
2724 img_pos = dis->rcItem.left;
2726 } else {
2727 img_pos = dis->rcItem.left;
2729 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2730 pane->widths[col] = IMAGE_WIDTH;
2733 if (calcWidthCol == -1) {
2734 focusRect.left = img_pos -2;
2736 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2737 textcolor = COLOR_COMPRESSED;
2738 else
2739 textcolor = RGB(0,0,0);
2741 if (dis->itemState & ODS_FOCUS) {
2742 textcolor = RGB(255,255,255);
2743 bkcolor = COLOR_SELECTION;
2744 } else {
2745 bkcolor = RGB(255,255,255);
2748 hbrush = CreateSolidBrush(bkcolor);
2749 FillRect(dis->hDC, &focusRect, hbrush);
2750 DeleteObject(hbrush);
2752 SetBkMode(dis->hDC, TRANSPARENT);
2753 SetTextColor(dis->hDC, textcolor);
2755 cx = pane->widths[col];
2757 if (cx && img!=IMG_NONE) {
2758 if (cx > IMAGE_WIDTH)
2759 cx = IMAGE_WIDTH;
2761 if (entry->hicon && entry->hicon!=(HICON)-1)
2762 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2763 else
2764 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2765 img_pos, dis->rcItem.top, cx,
2766 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2770 if (!entry)
2771 return;
2773 col++;
2775 /* output file name */
2776 if (calcWidthCol == -1)
2777 output_text(pane, dis, col, entry->data.cFileName, 0);
2778 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2779 calc_width(pane, dis, col, entry->data.cFileName);
2781 col++;
2783 /* display file size */
2784 if (visible_cols & COL_SIZE) {
2785 format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
2787 if (calcWidthCol == -1)
2788 output_number(pane, dis, col, buffer);
2789 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2790 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2792 col++;
2795 /* display file date */
2796 if (visible_cols & (COL_DATE|COL_TIME)) {
2797 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2798 if (calcWidthCol == -1)
2799 output_text(pane, dis, col, buffer, 0);
2800 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2801 calc_width(pane, dis, col, buffer);
2802 col++;
2804 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2805 if (calcWidthCol == -1)
2806 output_text(pane, dis, col, buffer, 0);
2807 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2808 calc_width(pane, dis, col, buffer);
2809 col++;
2811 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2812 if (calcWidthCol == -1)
2813 output_text(pane, dis, col, buffer, 0);
2814 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2815 calc_width(pane, dis, col, buffer);
2816 col++;
2819 if (entry->bhfi_valid) {
2820 if (visible_cols & COL_INDEX) {
2821 static const WCHAR fmtlow[] = {'%','X',0};
2822 static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
2824 if (entry->bhfi.nFileIndexHigh)
2825 wsprintfW(buffer, fmthigh,
2826 entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
2827 else
2828 wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
2830 if (calcWidthCol == -1)
2831 output_text(pane, dis, col, buffer, DT_RIGHT);
2832 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2833 calc_width(pane, dis, col, buffer);
2835 col++;
2838 if (visible_cols & COL_LINKS) {
2839 wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
2841 if (calcWidthCol == -1)
2842 output_text(pane, dis, col, buffer, DT_CENTER);
2843 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2844 calc_width(pane, dis, col, buffer);
2846 col++;
2848 } else
2849 col += 2;
2851 /* show file attributes */
2852 if (visible_cols & COL_ATTRIBUTES) {
2853 static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2854 lstrcpyW(buffer, s11Tabs);
2856 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2857 else {
2858 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2859 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2860 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2861 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2862 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2863 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2864 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2865 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2866 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2867 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2868 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2869 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2872 if (calcWidthCol == -1)
2873 output_tabbed_text(pane, dis, col, buffer);
2874 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2875 calc_tabbed_width(pane, dis, col, buffer);
2877 col++;
2881 static void set_header(Pane* pane)
2883 HDITEMW item;
2884 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2885 int i;
2887 item.mask = HDI_WIDTH;
2889 for (i = 0; i < COLUMNS; ++i) {
2890 if (pane->positions[i] >= scroll_pos) {
2891 item.cxy = pane->widths[i];
2892 } else if (pane->positions[i+1] <= scroll_pos) {
2893 item.cxy = 0;
2894 } else {
2895 item.cxy = pane->positions[i+1] - scroll_pos;
2897 pane->widths_shown[i] = item.cxy;
2898 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
2902 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2904 switch(pnmh->code) {
2905 case HDN_ITEMCHANGEDW: {
2906 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
2907 int idx = phdn->iItem;
2908 int dx = phdn->pitem->cxy - pane->widths_shown[idx];
2909 int i;
2911 RECT clnt;
2912 GetClientRect(pane->hwnd, &clnt);
2914 pane->widths[idx] += dx;
2915 pane->widths_shown[idx] += dx;
2917 for(i=idx; ++i<=COLUMNS; )
2918 pane->positions[i] += dx;
2921 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2922 RECT rt_scr;
2923 RECT rt_clip;
2925 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2926 rt_scr.top = 0;
2927 rt_scr.right = clnt.right;
2928 rt_scr.bottom = clnt.bottom;
2930 rt_clip.left = pane->positions[idx]-scroll_pos;
2931 rt_clip.top = 0;
2932 rt_clip.right = clnt.right;
2933 rt_clip.bottom = clnt.bottom;
2935 if (rt_scr.left < 0) rt_scr.left = 0;
2936 if (rt_clip.left < 0) rt_clip.left = 0;
2938 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2940 rt_clip.right = pane->positions[idx+1];
2941 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2943 if (pnmh->code == HDN_ENDTRACKW) {
2944 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
2946 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2947 set_header(pane);
2951 return FALSE;
2954 case HDN_DIVIDERDBLCLICKW: {
2955 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
2956 HDITEMW item;
2958 calc_single_width(pane, phdn->iItem);
2959 item.mask = HDI_WIDTH;
2960 item.cxy = pane->widths[phdn->iItem];
2962 SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
2963 InvalidateRect(pane->hwnd, 0, TRUE);
2964 break;}
2967 return 0;
2970 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
2972 WCHAR path[MAX_PATH];
2973 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
2975 /* delete sub entries in left pane */
2976 for(;;) {
2977 LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
2978 Entry* sub = (Entry*) res;
2980 if (res==LB_ERR || !sub || sub->level<=entry->level)
2981 break;
2983 SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
2986 /* empty right pane */
2987 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
2989 /* release memory */
2990 free_entries(entry);
2992 /* read contents from disk */
2993 if (entry->etype == ET_SHELL)
2995 read_directory(entry, NULL, child->sortOrder, hwnd);
2997 else
2999 get_path(entry, path);
3000 read_directory(entry, path, child->sortOrder, hwnd);
3003 /* insert found entries in right pane */
3004 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3005 calc_widths(&child->right, FALSE);
3006 set_header(&child->right);
3008 child->header_wdths_ok = FALSE;
3010 SetCursor(old_cursor);
3014 /* expand a directory entry */
3016 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3018 int idx;
3019 Entry* p;
3021 if (!dir || dir->expanded || !dir->down)
3022 return FALSE;
3024 p = dir->down;
3026 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3027 p = p->next;
3029 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3030 p->data.cFileName[2]=='\0' && p->next)
3031 p = p->next;
3034 /* no subdirectories ? */
3035 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3036 return FALSE;
3038 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3040 dir->expanded = TRUE;
3042 /* insert entries in left pane */
3043 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3045 if (!child->header_wdths_ok) {
3046 if (calc_widths(&child->left, FALSE)) {
3047 set_header(&child->left);
3049 child->header_wdths_ok = TRUE;
3053 return TRUE;
3057 static void collapse_entry(Pane* pane, Entry* dir)
3059 int idx;
3061 if (!dir) return;
3062 idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3064 ShowWindow(pane->hwnd, SW_HIDE);
3066 /* hide sub entries */
3067 for(;;) {
3068 LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3069 Entry* sub = (Entry*) res;
3071 if (res==LB_ERR || !sub || sub->level<=dir->level)
3072 break;
3074 SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3077 dir->expanded = FALSE;
3079 ShowWindow(pane->hwnd, SW_SHOW);
3083 static void refresh_right_pane(ChildWnd* child)
3085 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3086 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3087 calc_widths(&child->right, FALSE);
3089 set_header(&child->right);
3092 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3094 WCHAR path[MAX_PATH];
3096 if (!entry)
3097 return;
3099 path[0] = '\0';
3101 child->left.cur = entry;
3103 child->right.root = entry->down? entry->down: entry;
3104 child->right.cur = entry;
3106 if (!entry->scanned)
3107 scan_entry(child, entry, idx, hwnd);
3108 else
3109 refresh_right_pane(child);
3111 get_path(entry, path);
3112 lstrcpyW(child->path, path);
3114 if (child->hwnd) /* only change window title, if the window already exists */
3115 SetWindowTextW(child->hwnd, path);
3117 if (path[0])
3118 if (SetCurrentDirectoryW(path))
3119 set_space_status();
3123 static void refresh_child(ChildWnd* child)
3125 WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3126 Entry* entry;
3127 int idx;
3129 get_path(child->left.cur, path);
3130 _wsplitpath(path, drv, NULL, NULL, NULL);
3132 child->right.root = NULL;
3134 scan_entry(child, &child->root.entry, 0, child->hwnd);
3136 if (child->root.entry.etype == ET_SHELL)
3138 LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
3139 if (local_pidl)
3140 entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
3141 else
3142 entry = NULL;
3144 else
3145 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3147 if (!entry)
3148 entry = &child->root.entry;
3150 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3152 set_curdir(child, entry, 0, child->hwnd);
3154 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3155 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3159 static void create_drive_bar(void)
3161 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3162 WCHAR b1[BUFFER_LEN];
3163 int btn = 1;
3164 PWSTR p;
3166 GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
3168 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3169 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3170 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3172 /* insert shell namespace button */
3173 load_string(b1, ARRAY_SIZE(b1), IDS_SHELL);
3174 b1[lstrlenW(b1)+1] = '\0';
3175 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3177 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3178 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3179 drivebarBtn.iString++;
3181 /* register windows drive root strings */
3182 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
3184 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3186 for(p=Globals.drives; *p; ) {
3187 switch(GetDriveTypeW(p)) {
3188 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3189 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3190 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3191 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3192 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3195 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3196 drivebarBtn.idCommand++;
3197 drivebarBtn.iString++;
3199 while(*p++);
3203 static void refresh_drives(void)
3205 RECT rect;
3207 /* destroy drive bar */
3208 DestroyWindow(Globals.hdrivebar);
3209 Globals.hdrivebar = 0;
3211 /* re-create drive bar */
3212 create_drive_bar();
3214 /* update window layout */
3215 GetClientRect(Globals.hMainWnd, &rect);
3216 SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3220 static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
3222 HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3224 if (PtrToUlong(hinst) <= 32) {
3225 display_error(hwnd, GetLastError());
3226 return FALSE;
3229 return TRUE;
3233 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3235 WCHAR cmd[MAX_PATH];
3237 if (entry->etype == ET_SHELL) {
3238 BOOL ret = TRUE;
3240 SHELLEXECUTEINFOW shexinfo;
3242 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
3243 shexinfo.fMask = SEE_MASK_IDLIST;
3244 shexinfo.hwnd = hwnd;
3245 shexinfo.lpVerb = NULL;
3246 shexinfo.lpFile = NULL;
3247 shexinfo.lpParameters = NULL;
3248 shexinfo.lpDirectory = NULL;
3249 shexinfo.nShow = nCmdShow;
3250 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3252 if (!ShellExecuteExW(&shexinfo)) {
3253 display_error(hwnd, GetLastError());
3254 ret = FALSE;
3257 if (shexinfo.lpIDList != entry->pidl)
3258 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3260 return ret;
3263 get_path(entry, cmd);
3265 /* start program, open document... */
3266 return launch_file(hwnd, cmd, nCmdShow);
3270 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3272 Entry* entry = pane->cur;
3274 if (!entry)
3275 return;
3277 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3278 int scanned_old = entry->scanned;
3280 if (!scanned_old)
3282 int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3283 scan_entry(child, entry, idx, hwnd);
3286 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3287 return;
3289 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3290 entry = child->left.cur->up;
3291 collapse_entry(&child->left, entry);
3292 goto focus_entry;
3293 } else if (entry->expanded)
3294 collapse_entry(pane, child->left.cur);
3295 else {
3296 expand_entry(child, child->left.cur);
3298 if (!pane->treePane) focus_entry: {
3299 int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3300 int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
3301 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3302 set_curdir(child, entry, idx, hwnd);
3306 if (!scanned_old) {
3307 calc_widths(pane, FALSE);
3309 set_header(pane);
3311 } else {
3312 if (GetKeyState(VK_MENU) < 0)
3313 show_properties_dlg(entry, child->hwnd);
3314 else
3315 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3320 static BOOL pane_command(Pane* pane, UINT cmd)
3322 switch(cmd) {
3323 case ID_VIEW_NAME:
3324 if (pane->visible_cols) {
3325 pane->visible_cols = 0;
3326 calc_widths(pane, TRUE);
3327 set_header(pane);
3328 InvalidateRect(pane->hwnd, 0, TRUE);
3329 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3330 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3332 break;
3334 case ID_VIEW_ALL_ATTRIBUTES:
3335 if (pane->visible_cols != COL_ALL) {
3336 pane->visible_cols = COL_ALL;
3337 calc_widths(pane, TRUE);
3338 set_header(pane);
3339 InvalidateRect(pane->hwnd, 0, TRUE);
3340 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3341 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3343 break;
3345 case ID_PREFERRED_SIZES: {
3346 calc_widths(pane, TRUE);
3347 set_header(pane);
3348 InvalidateRect(pane->hwnd, 0, TRUE);
3349 break;}
3351 /* TODO: more command ids... */
3353 default:
3354 return FALSE;
3357 return TRUE;
3361 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3363 if (child->sortOrder != sortOrder) {
3364 child->sortOrder = sortOrder;
3365 refresh_child(child);
3369 static void update_view_menu(ChildWnd* child)
3371 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3372 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3373 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3374 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3378 static BOOL is_directory(LPCWSTR target)
3380 DWORD target_attr = GetFileAttributesW(target);
3382 if (target_attr == INVALID_FILE_ATTRIBUTES)
3383 return FALSE;
3385 return (target_attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
3388 static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
3390 WCHAR path[MAX_PATH];
3391 int len;
3393 get_path(pane->cur, path);
3395 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
3396 return FALSE;
3398 get_path(pane->cur, source);
3400 /* convert relative targets to absolute paths */
3401 if (path[0]!='/' && path[1]!=':') {
3402 get_path(pane->cur->up, target);
3403 len = lstrlenW(target);
3405 if (target[len-1]!='\\' && target[len-1]!='/')
3406 target[len++] = '/';
3408 lstrcpyW(target+len, path);
3409 } else
3410 lstrcpyW(target, path);
3412 /* If the target already exists as directory, create a new target below this. */
3413 if (is_directory(path)) {
3414 WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
3415 static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
3417 _wsplitpath(source, NULL, NULL, fname, ext);
3419 wsprintfW(target, sAppend, path, fname, ext);
3422 return TRUE;
3426 static IContextMenu2* s_pctxmenu2 = NULL;
3427 static IContextMenu3* s_pctxmenu3 = NULL;
3429 static void CtxMenu_reset(void)
3431 s_pctxmenu2 = NULL;
3432 s_pctxmenu3 = NULL;
3435 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
3437 IContextMenu* pcm = NULL;
3439 CtxMenu_reset();
3441 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
3442 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
3443 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
3444 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
3446 if (pcm) {
3447 IContextMenu_Release(pcm1);
3448 return pcm;
3449 } else
3450 return pcm1;
3453 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
3455 if (s_pctxmenu3) {
3456 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
3457 return TRUE;
3460 if (s_pctxmenu2)
3461 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
3462 return TRUE;
3464 return FALSE;
3467 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3469 IContextMenu* pcm;
3470 BOOL executed = FALSE;
3472 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3474 if (SUCCEEDED(hr)) {
3475 HMENU hmenu = CreatePopupMenu();
3477 pcm = CtxMenu_query_interfaces(pcm);
3479 if (hmenu) {
3480 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3482 if (SUCCEEDED(hr)) {
3483 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3485 CtxMenu_reset();
3487 if (idCmd) {
3488 CMINVOKECOMMANDINFO cmi;
3490 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3491 cmi.fMask = 0;
3492 cmi.hwnd = hwndParent;
3493 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3494 cmi.lpParameters = NULL;
3495 cmi.lpDirectory = NULL;
3496 cmi.nShow = SW_SHOWNORMAL;
3497 cmi.dwHotKey = 0;
3498 cmi.hIcon = 0;
3500 hr = IContextMenu_InvokeCommand(pcm, &cmi);
3501 executed = TRUE;
3503 } else
3504 CtxMenu_reset();
3507 IContextMenu_Release(pcm);
3510 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
3513 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3515 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
3516 assert(child);
3518 switch(nmsg) {
3519 case WM_DRAWITEM: {
3520 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3521 Entry* entry = (Entry*) dis->itemData;
3523 if (dis->CtlID == IDW_TREE_LEFT)
3524 draw_item(&child->left, dis, entry, -1);
3525 else if (dis->CtlID == IDW_TREE_RIGHT)
3526 draw_item(&child->right, dis, entry, -1);
3527 else
3528 goto draw_menu_item;
3530 return TRUE;}
3532 case WM_CREATE:
3533 InitChildWindow(child);
3534 break;
3536 case WM_NCDESTROY:
3537 free_child_window(child);
3538 SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
3539 break;
3541 case WM_PAINT: {
3542 PAINTSTRUCT ps;
3543 HBRUSH lastBrush;
3544 RECT rt;
3545 GetClientRect(hwnd, &rt);
3546 BeginPaint(hwnd, &ps);
3547 rt.left = child->split_pos-SPLIT_WIDTH/2;
3548 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3549 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
3550 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3551 SelectObject(ps.hdc, lastBrush);
3552 EndPaint(hwnd, &ps);
3553 break;}
3555 case WM_SETCURSOR:
3556 if (LOWORD(lparam) == HTCLIENT) {
3557 POINT pt;
3558 GetCursorPos(&pt);
3559 ScreenToClient(hwnd, &pt);
3561 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3562 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
3563 return TRUE;
3566 goto def;
3568 case WM_LBUTTONDOWN: {
3569 RECT rt;
3570 int x = (short)LOWORD(lparam);
3572 GetClientRect(hwnd, &rt);
3574 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3575 last_split = child->split_pos;
3576 SetCapture(hwnd);
3579 break;}
3581 case WM_LBUTTONUP:
3582 if (GetCapture() == hwnd)
3583 ReleaseCapture();
3584 break;
3586 case WM_KEYDOWN:
3587 if (wparam == VK_ESCAPE)
3588 if (GetCapture() == hwnd) {
3589 RECT rt;
3590 child->split_pos = last_split;
3591 GetClientRect(hwnd, &rt);
3592 resize_tree(child, rt.right, rt.bottom);
3593 last_split = -1;
3594 ReleaseCapture();
3595 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
3597 break;
3599 case WM_MOUSEMOVE:
3600 if (GetCapture() == hwnd) {
3601 RECT rt;
3602 int x = (short)LOWORD(lparam);
3604 GetClientRect(hwnd, &rt);
3606 if (x>=0 && x<rt.right) {
3607 child->split_pos = x;
3608 resize_tree(child, rt.right, rt.bottom);
3609 rt.left = x-SPLIT_WIDTH/2;
3610 rt.right = x+SPLIT_WIDTH/2+1;
3611 InvalidateRect(hwnd, &rt, FALSE);
3612 UpdateWindow(child->left.hwnd);
3613 UpdateWindow(hwnd);
3614 UpdateWindow(child->right.hwnd);
3617 break;
3619 case WM_GETMINMAXINFO:
3620 DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
3622 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3624 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3625 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3626 break;}
3628 case WM_SETFOCUS:
3629 if (SetCurrentDirectoryW(child->path))
3630 set_space_status();
3631 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3632 break;
3634 case WM_DISPATCH_COMMAND: {
3635 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3637 switch(LOWORD(wparam)) {
3638 case ID_WINDOW_NEW: {
3639 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3641 if (!create_child_window(new_child))
3642 HeapFree(GetProcessHeap(), 0, new_child);
3644 break;}
3646 case ID_REFRESH:
3647 refresh_drives();
3648 refresh_child(child);
3649 break;
3651 case ID_ACTIVATE:
3652 activate_entry(child, pane, hwnd);
3653 break;
3655 case ID_FILE_MOVE: {
3656 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
3658 if (prompt_target(pane, source, target)) {
3659 SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
3661 source[lstrlenW(source)+1] = '\0';
3662 target[lstrlenW(target)+1] = '\0';
3664 if (!SHFileOperationW(&shfo))
3665 refresh_child(child);
3667 break;}
3669 case ID_FILE_COPY: {
3670 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
3672 if (prompt_target(pane, source, target)) {
3673 SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
3675 source[lstrlenW(source)+1] = '\0';
3676 target[lstrlenW(target)+1] = '\0';
3678 if (!SHFileOperationW(&shfo))
3679 refresh_child(child);
3681 break;}
3683 case ID_FILE_DELETE: {
3684 WCHAR path[BUFFER_LEN];
3685 SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
3687 get_path(pane->cur, path);
3689 path[lstrlenW(path)+1] = '\0';
3691 if (!SHFileOperationW(&shfo))
3692 refresh_child(child);
3693 break;}
3695 case ID_VIEW_SORT_NAME:
3696 set_sort_order(child, SORT_NAME);
3697 break;
3699 case ID_VIEW_SORT_TYPE:
3700 set_sort_order(child, SORT_EXT);
3701 break;
3703 case ID_VIEW_SORT_SIZE:
3704 set_sort_order(child, SORT_SIZE);
3705 break;
3707 case ID_VIEW_SORT_DATE:
3708 set_sort_order(child, SORT_DATE);
3709 break;
3711 case ID_VIEW_FILTER: {
3712 struct FilterDialog dlg;
3714 memset(&dlg, 0, sizeof(struct FilterDialog));
3715 lstrcpyW(dlg.pattern, child->filter_pattern);
3716 dlg.flags = child->filter_flags;
3718 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
3719 lstrcpyW(child->filter_pattern, dlg.pattern);
3720 child->filter_flags = dlg.flags;
3721 refresh_right_pane(child);
3723 break;}
3725 case ID_VIEW_SPLIT: {
3726 last_split = child->split_pos;
3727 SetCapture(hwnd);
3728 break;}
3730 case ID_EDIT_PROPERTIES:
3731 show_properties_dlg(pane->cur, child->hwnd);
3732 break;
3734 default:
3735 return pane_command(pane, LOWORD(wparam));
3738 return TRUE;}
3740 case WM_COMMAND: {
3741 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3743 switch(HIWORD(wparam)) {
3744 case LBN_SELCHANGE: {
3745 int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
3746 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
3748 if (pane == &child->left)
3749 set_curdir(child, entry, idx, hwnd);
3750 else
3751 pane->cur = entry;
3752 break;}
3754 case LBN_DBLCLK:
3755 activate_entry(child, pane, hwnd);
3756 break;
3758 break;}
3760 case WM_NOTIFY: {
3761 NMHDR* pnmh = (NMHDR*) lparam;
3762 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3764 case WM_CONTEXTMENU: {
3765 POINT pt, pt_clnt;
3766 Pane* pane;
3767 int idx;
3769 /* first select the current item in the listbox */
3770 HWND hpanel = (HWND) wparam;
3771 pt_clnt.x = pt.x = (short)LOWORD(lparam);
3772 pt_clnt.y = pt.y = (short)HIWORD(lparam);
3773 ScreenToClient(hpanel, &pt_clnt);
3774 SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
3775 SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
3777 /* now create the popup menu using shell namespace and IContextMenu */
3778 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3779 idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
3781 if (idx != -1) {
3782 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
3784 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3786 if (pidl_abs) {
3787 IShellFolder* parentFolder;
3788 LPCITEMIDLIST pidlLast;
3790 /* get and use the parent folder to display correct context menu in all cases */
3791 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3792 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
3793 refresh_child(child);
3795 IShellFolder_Release(parentFolder);
3798 IMalloc_Free(Globals.iMalloc, pidl_abs);
3801 break;}
3803 case WM_MEASUREITEM:
3804 draw_menu_item:
3805 if (!wparam) /* Is the message menu-related? */
3806 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
3807 return TRUE;
3809 break;
3811 case WM_INITMENUPOPUP:
3812 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
3813 return 0;
3815 update_view_menu(child);
3816 break;
3818 case WM_MENUCHAR: /* only supported by IContextMenu3 */
3819 if (s_pctxmenu3) {
3820 LRESULT lResult = 0;
3822 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
3824 return lResult;
3827 break;
3829 case WM_SIZE:
3830 if (wparam != SIZE_MINIMIZED)
3831 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3832 /* fall through */
3834 default: def:
3835 return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
3838 return 0;
3842 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3844 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
3845 Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
3846 assert(child);
3848 switch(nmsg) {
3849 case WM_HSCROLL:
3850 set_header(pane);
3851 break;
3853 case WM_SETFOCUS:
3854 child->focus_pane = pane==&child->right? 1: 0;
3855 SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
3856 /*TODO: check menu items */
3857 break;
3859 case WM_KEYDOWN:
3860 if (wparam == VK_TAB) {
3861 /*TODO: SetFocus(Globals.hdrivebar) */
3862 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3866 return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3870 static void InitInstance(HINSTANCE hinstance)
3872 static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3874 WNDCLASSEXW wcFrame;
3875 WNDCLASSW wcChild;
3876 int col;
3878 INITCOMMONCONTROLSEX icc = {
3879 sizeof(INITCOMMONCONTROLSEX),
3880 ICC_BAR_CLASSES
3883 HDC hdc = GetDC(0);
3885 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3887 InitCommonControlsEx(&icc);
3890 /* register frame window class */
3892 wcFrame.cbSize = sizeof(WNDCLASSEXW);
3893 wcFrame.style = 0;
3894 wcFrame.lpfnWndProc = FrameWndProc;
3895 wcFrame.cbClsExtra = 0;
3896 wcFrame.cbWndExtra = 0;
3897 wcFrame.hInstance = hinstance;
3898 wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
3899 wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
3900 wcFrame.hbrBackground = 0;
3901 wcFrame.lpszMenuName = 0;
3902 wcFrame.lpszClassName = sWINEFILEFRAME;
3903 wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
3905 Globals.hframeClass = RegisterClassExW(&wcFrame);
3908 /* register tree windows class */
3910 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3911 wcChild.lpfnWndProc = ChildWndProc;
3912 wcChild.cbClsExtra = 0;
3913 wcChild.cbWndExtra = 0;
3914 wcChild.hInstance = hinstance;
3915 wcChild.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
3916 wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
3917 wcChild.hbrBackground = 0;
3918 wcChild.lpszMenuName = 0;
3919 wcChild.lpszClassName = sWINEFILETREE;
3921 RegisterClassW(&wcChild);
3924 Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
3926 Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
3928 ReleaseDC(0, hdc);
3930 Globals.hInstance = hinstance;
3932 CoInitialize(NULL);
3933 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3934 SHGetDesktopFolder(&Globals.iDesktop);
3935 Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
3937 /* load column strings */
3938 col = 1;
3940 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_NAME);
3941 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SIZE);
3942 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_CDATE);
3943 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ADATE);
3944 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_MDATE);
3945 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_IDX);
3946 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_LINKS);
3947 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ATTR);
3948 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SEC);
3952 static BOOL show_frame(HWND hwndParent, int cmdshow, LPWSTR path)
3954 static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
3956 WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
3957 ChildWnd* child;
3958 HMENU hMenuFrame, hMenuWindow;
3959 windowOptions opts;
3961 CLIENTCREATESTRUCT ccs;
3963 if (Globals.hMainWnd)
3964 return TRUE;
3966 opts = load_registry_settings();
3967 hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
3968 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3970 Globals.hMenuFrame = hMenuFrame;
3971 Globals.hMenuView = GetSubMenu(hMenuFrame, 2);
3972 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 3);
3974 ccs.hWindowMenu = hMenuWindow;
3975 ccs.idFirstChild = IDW_FIRST_CHILD;
3978 /* create main window */
3979 Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINEFILE), WS_OVERLAPPEDWINDOW,
3980 opts.start_x, opts.start_y, opts.width, opts.height,
3981 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3984 Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
3985 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3986 0, 0, 0, 0,
3987 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3989 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3990 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
3992 create_drive_bar();
3995 TBBUTTON toolbarBtns[] = {
3996 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3997 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3998 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3999 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4000 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4003 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4004 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4005 ARRAY_SIZE(toolbarBtns), 16, 15, 16, 15, sizeof(TBBUTTON));
4006 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4009 Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4010 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4012 /*TODO: read paths from registry */
4014 if (!path || !*path) {
4015 GetCurrentDirectoryW(MAX_PATH, buffer);
4016 path = buffer;
4019 ShowWindow(Globals.hMainWnd, cmdshow);
4021 /* Shell Namespace as default: */
4022 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4024 child->pos.showCmd = SW_SHOWMAXIMIZED;
4025 child->pos.rcNormalPosition.left = 0;
4026 child->pos.rcNormalPosition.top = 0;
4027 child->pos.rcNormalPosition.right = 320;
4028 child->pos.rcNormalPosition.bottom = 280;
4030 if (!create_child_window(child)) {
4031 HeapFree(GetProcessHeap(), 0, child);
4032 return FALSE;
4035 SetWindowPlacement(child->hwnd, &child->pos);
4037 Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
4039 Globals.prescan_node = FALSE;
4041 UpdateWindow(Globals.hMainWnd);
4043 if (child->hwnd && path && path[0])
4045 int index,count;
4046 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4047 WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4049 memset(name,0,sizeof(name));
4050 memset(name,0,sizeof(ext));
4051 _wsplitpath(path, drv, dir, name, ext);
4052 if (name[0])
4054 count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
4055 lstrcpyW(fullname,name);
4056 lstrcatW(fullname,ext);
4058 for (index = 0; index < count; index ++)
4060 Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
4061 if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
4062 lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
4064 SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
4065 SetFocus(child->right.hwnd);
4066 break;
4071 return TRUE;
4074 static void ExitInstance(void)
4076 IShellFolder_Release(Globals.iDesktop);
4077 IMalloc_Release(Globals.iMalloc);
4078 CoUninitialize();
4080 DeleteObject(Globals.hfont);
4081 ImageList_Destroy(Globals.himl);
4084 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4086 MSG msg;
4088 InitInstance(hinstance);
4090 if( !show_frame(0, cmdshow, cmdline) )
4092 ExitInstance();
4093 return 1;
4096 while(GetMessageW(&msg, 0, 0, 0)) {
4097 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4098 continue;
4100 if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
4101 continue;
4103 TranslateMessage(&msg);
4104 DispatchMessageW(&msg);
4107 ExitInstance();
4109 return msg.wParam;