comctl32/tests: Test that changing focus for edit controls doesn't repaint immediately.
[wine.git] / programs / winefile / winefile.c
blob8ad785b924ad6729cd7ba64eb0549c697b6fbc5f
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),
2409 (__ms_va_list*)args);
2410 } else
2411 lstrcpyW(buffer, sQMarks);
2413 SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
2417 static WNDPROC g_orgTreeWndProc;
2419 static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
2421 static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
2423 static BOOL s_init = FALSE;
2424 Entry* entry = pane->root;
2426 pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
2427 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
2428 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
2430 SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
2431 g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
2433 SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
2435 /* insert entries into listbox */
2436 if (entry)
2437 insert_entries(pane, entry, pattern, filter_flags, -1);
2439 /* calculate column widths */
2440 if (!s_init) {
2441 s_init = TRUE;
2442 init_output(pane->hwnd);
2445 calc_widths(pane, TRUE);
2447 pane->hwndHeader = create_header(parent, pane, id_header);
2451 static void InitChildWindow(ChildWnd* child)
2453 create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
2454 create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
2458 static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
2460 SYSTEMTIME systime;
2461 FILETIME lft;
2462 int len = 0;
2464 *buffer = '\0';
2466 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
2467 return;
2469 if (!FileTimeToLocalFileTime(ft, &lft))
2470 {err: lstrcpyW(buffer,sQMarks); return;}
2472 if (!FileTimeToSystemTime(&lft, &systime))
2473 goto err;
2475 if (visible_cols & COL_DATE) {
2476 len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
2477 if (!len)
2478 goto err;
2481 if (visible_cols & COL_TIME) {
2482 if (len)
2483 buffer[len-1] = ' ';
2485 buffer[len++] = ' ';
2487 if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
2488 buffer[len] = '\0';
2493 static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2495 RECT rt = {0, 0, 0, 0};
2497 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
2499 if (rt.right > pane->widths[col])
2500 pane->widths[col] = rt.right;
2503 static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2505 RECT rt = {0, 0, 0, 0};
2507 DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2508 /*FIXME rt (0,0) ??? */
2510 if (rt.right > pane->widths[col])
2511 pane->widths[col] = rt.right;
2515 static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
2517 int x = dis->rcItem.left;
2518 RECT rt;
2520 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2521 rt.top = dis->rcItem.top;
2522 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2523 rt.bottom = dis->rcItem.bottom;
2525 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
2528 static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2530 int x = dis->rcItem.left;
2531 RECT rt;
2533 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2534 rt.top = dis->rcItem.top;
2535 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2536 rt.bottom = dis->rcItem.bottom;
2538 DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
2541 static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
2543 int x = dis->rcItem.left;
2544 RECT rt;
2545 LPCWSTR s = str;
2546 WCHAR b[128];
2547 LPWSTR d = b;
2548 int pos;
2550 rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
2551 rt.top = dis->rcItem.top;
2552 rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
2553 rt.bottom = dis->rcItem.bottom;
2555 if (*s)
2556 *d++ = *s++;
2558 /* insert number separator characters */
2559 pos = lstrlenW(s) % 3;
2561 while(*s)
2562 if (pos--)
2563 *d++ = *s++;
2564 else {
2565 *d++ = Globals.num_sep;
2566 pos = 3;
2569 DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
2573 static BOOL is_exe_file(LPCWSTR ext)
2575 static const WCHAR executable_extensions[][4] = {
2576 {'C','O','M','\0'},
2577 {'E','X','E','\0'},
2578 {'B','A','T','\0'},
2579 {'C','M','D','\0'},
2580 {'C','M','M','\0'},
2581 {'B','T','M','\0'},
2582 {'A','W','K','\0'},
2583 {'\0'}
2586 WCHAR ext_buffer[_MAX_EXT];
2587 const WCHAR (*p)[4];
2588 LPCWSTR s;
2589 LPWSTR d;
2591 for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
2592 d++;
2594 for(p=executable_extensions; (*p)[0]; p++)
2595 if (!lstrcmpiW(ext_buffer, *p))
2596 return TRUE;
2598 return FALSE;
2601 static BOOL is_registered_type(LPCWSTR ext)
2603 /* check if there exists a classname for this file extension in the registry */
2604 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
2605 return TRUE;
2607 return FALSE;
2610 static enum FILE_TYPE get_file_type(LPCWSTR filename)
2612 LPCWSTR ext = wcsrchr(filename, '.');
2613 if (!ext)
2614 ext = sEmpty;
2616 if (is_exe_file(ext))
2617 return FT_EXECUTABLE;
2618 else if (is_registered_type(ext))
2619 return FT_DOCUMENT;
2620 else
2621 return FT_OTHER;
2625 static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
2627 WCHAR buffer[BUFFER_LEN];
2628 DWORD attrs;
2629 int visible_cols = pane->visible_cols;
2630 COLORREF bkcolor, textcolor;
2631 RECT focusRect = dis->rcItem;
2632 HBRUSH hbrush;
2633 enum IMAGE img;
2634 int img_pos, cx;
2635 int col = 0;
2637 if (entry) {
2638 attrs = entry->data.dwFileAttributes;
2640 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
2641 if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
2642 && entry->data.cFileName[2] == '\0')
2643 img = IMG_FOLDER_UP;
2644 else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
2645 img = IMG_FOLDER_CUR;
2646 else if (pane->treePane && (dis->itemState&ODS_FOCUS))
2647 img = IMG_OPEN_FOLDER;
2648 else
2649 img = IMG_FOLDER;
2650 } else {
2651 switch(get_file_type(entry->data.cFileName)) {
2652 case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
2653 case FT_DOCUMENT: img = IMG_DOCUMENT; break;
2654 default: img = IMG_FILE;
2657 } else {
2658 attrs = 0;
2659 img = IMG_NONE;
2662 if (pane->treePane) {
2663 if (entry) {
2664 img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
2666 if (calcWidthCol == -1) {
2667 int x;
2668 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
2669 Entry* up;
2670 RECT rt_clip;
2671 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
2672 HRGN hrgn;
2674 rt_clip.left = dis->rcItem.left;
2675 rt_clip.top = dis->rcItem.top;
2676 rt_clip.right = dis->rcItem.left+pane->widths[col];
2677 rt_clip.bottom = dis->rcItem.bottom;
2679 hrgn = CreateRectRgnIndirect(&rt_clip);
2681 if (!GetClipRgn(dis->hDC, hrgn_org)) {
2682 DeleteObject(hrgn_org);
2683 hrgn_org = 0;
2686 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
2687 DeleteObject(hrgn);
2689 if ((up=entry->up) != NULL) {
2690 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
2691 LineTo(dis->hDC, img_pos-2, y);
2693 x = img_pos - IMAGE_WIDTH/2;
2695 do {
2696 x -= IMAGE_WIDTH+TREE_LINE_DX;
2698 if (up->next
2699 && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2701 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2702 LineTo(dis->hDC, x, dis->rcItem.bottom);
2704 } while((up=up->up) != NULL);
2707 x = img_pos - IMAGE_WIDTH/2;
2709 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
2710 LineTo(dis->hDC, x, y);
2712 if (entry->next
2713 && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
2714 LineTo(dis->hDC, x, dis->rcItem.bottom);
2716 SelectClipRgn(dis->hDC, hrgn_org);
2717 if (hrgn_org) DeleteObject(hrgn_org);
2718 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
2719 int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
2721 if (right > pane->widths[col])
2722 pane->widths[col] = right;
2724 } else {
2725 img_pos = dis->rcItem.left;
2727 } else {
2728 img_pos = dis->rcItem.left;
2730 if (calcWidthCol==col || calcWidthCol==COLUMNS)
2731 pane->widths[col] = IMAGE_WIDTH;
2734 if (calcWidthCol == -1) {
2735 focusRect.left = img_pos -2;
2737 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
2738 textcolor = COLOR_COMPRESSED;
2739 else
2740 textcolor = RGB(0,0,0);
2742 if (dis->itemState & ODS_FOCUS) {
2743 textcolor = RGB(255,255,255);
2744 bkcolor = COLOR_SELECTION;
2745 } else {
2746 bkcolor = RGB(255,255,255);
2749 hbrush = CreateSolidBrush(bkcolor);
2750 FillRect(dis->hDC, &focusRect, hbrush);
2751 DeleteObject(hbrush);
2753 SetBkMode(dis->hDC, TRANSPARENT);
2754 SetTextColor(dis->hDC, textcolor);
2756 cx = pane->widths[col];
2758 if (cx && img!=IMG_NONE) {
2759 if (cx > IMAGE_WIDTH)
2760 cx = IMAGE_WIDTH;
2762 if (entry->hicon && entry->hicon!=(HICON)-1)
2763 DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
2764 else
2765 ImageList_DrawEx(Globals.himl, img, dis->hDC,
2766 img_pos, dis->rcItem.top, cx,
2767 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
2771 if (!entry)
2772 return;
2774 col++;
2776 /* output file name */
2777 if (calcWidthCol == -1)
2778 output_text(pane, dis, col, entry->data.cFileName, 0);
2779 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2780 calc_width(pane, dis, col, entry->data.cFileName);
2782 col++;
2784 /* display file size */
2785 if (visible_cols & COL_SIZE) {
2786 format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
2788 if (calcWidthCol == -1)
2789 output_number(pane, dis, col, buffer);
2790 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2791 calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
2793 col++;
2796 /* display file date */
2797 if (visible_cols & (COL_DATE|COL_TIME)) {
2798 format_date(&entry->data.ftCreationTime, buffer, visible_cols);
2799 if (calcWidthCol == -1)
2800 output_text(pane, dis, col, buffer, 0);
2801 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2802 calc_width(pane, dis, col, buffer);
2803 col++;
2805 format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
2806 if (calcWidthCol == -1)
2807 output_text(pane, dis, col, buffer, 0);
2808 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2809 calc_width(pane, dis, col, buffer);
2810 col++;
2812 format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
2813 if (calcWidthCol == -1)
2814 output_text(pane, dis, col, buffer, 0);
2815 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2816 calc_width(pane, dis, col, buffer);
2817 col++;
2820 if (entry->bhfi_valid) {
2821 if (visible_cols & COL_INDEX) {
2822 static const WCHAR fmtlow[] = {'%','X',0};
2823 static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
2825 if (entry->bhfi.nFileIndexHigh)
2826 wsprintfW(buffer, fmthigh,
2827 entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
2828 else
2829 wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
2831 if (calcWidthCol == -1)
2832 output_text(pane, dis, col, buffer, DT_RIGHT);
2833 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2834 calc_width(pane, dis, col, buffer);
2836 col++;
2839 if (visible_cols & COL_LINKS) {
2840 wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
2842 if (calcWidthCol == -1)
2843 output_text(pane, dis, col, buffer, DT_CENTER);
2844 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2845 calc_width(pane, dis, col, buffer);
2847 col++;
2849 } else
2850 col += 2;
2852 /* show file attributes */
2853 if (visible_cols & COL_ATTRIBUTES) {
2854 static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
2855 lstrcpyW(buffer, s11Tabs);
2857 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
2858 else {
2859 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
2860 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
2861 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
2862 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
2863 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
2864 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
2865 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
2866 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
2867 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
2868 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
2869 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
2870 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
2873 if (calcWidthCol == -1)
2874 output_tabbed_text(pane, dis, col, buffer);
2875 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
2876 calc_tabbed_width(pane, dis, col, buffer);
2878 col++;
2882 static void set_header(Pane* pane)
2884 HDITEMW item;
2885 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2886 int i;
2888 item.mask = HDI_WIDTH;
2890 for (i = 0; i < COLUMNS; ++i) {
2891 if (pane->positions[i] >= scroll_pos) {
2892 item.cxy = pane->widths[i];
2893 } else if (pane->positions[i+1] <= scroll_pos) {
2894 item.cxy = 0;
2895 } else {
2896 item.cxy = pane->positions[i+1] - scroll_pos;
2898 pane->widths_shown[i] = item.cxy;
2899 SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
2903 static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
2905 switch(pnmh->code) {
2906 case HDN_ITEMCHANGEDW: {
2907 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
2908 int idx = phdn->iItem;
2909 int dx = phdn->pitem->cxy - pane->widths_shown[idx];
2910 int i;
2912 RECT clnt;
2913 GetClientRect(pane->hwnd, &clnt);
2915 pane->widths[idx] += dx;
2916 pane->widths_shown[idx] += dx;
2918 for(i=idx; ++i<=COLUMNS; )
2919 pane->positions[i] += dx;
2922 int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
2923 RECT rt_scr;
2924 RECT rt_clip;
2926 rt_scr.left = pane->positions[idx+1]-scroll_pos;
2927 rt_scr.top = 0;
2928 rt_scr.right = clnt.right;
2929 rt_scr.bottom = clnt.bottom;
2931 rt_clip.left = pane->positions[idx]-scroll_pos;
2932 rt_clip.top = 0;
2933 rt_clip.right = clnt.right;
2934 rt_clip.bottom = clnt.bottom;
2936 if (rt_scr.left < 0) rt_scr.left = 0;
2937 if (rt_clip.left < 0) rt_clip.left = 0;
2939 ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
2941 rt_clip.right = pane->positions[idx+1];
2942 RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
2944 if (pnmh->code == HDN_ENDTRACKW) {
2945 SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
2947 if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
2948 set_header(pane);
2952 return FALSE;
2955 case HDN_DIVIDERDBLCLICKW: {
2956 LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
2957 HDITEMW item;
2959 calc_single_width(pane, phdn->iItem);
2960 item.mask = HDI_WIDTH;
2961 item.cxy = pane->widths[phdn->iItem];
2963 SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
2964 InvalidateRect(pane->hwnd, 0, TRUE);
2965 break;}
2968 return 0;
2971 static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
2973 WCHAR path[MAX_PATH];
2974 HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
2976 /* delete sub entries in left pane */
2977 for(;;) {
2978 LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
2979 Entry* sub = (Entry*) res;
2981 if (res==LB_ERR || !sub || sub->level<=entry->level)
2982 break;
2984 SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
2987 /* empty right pane */
2988 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
2990 /* release memory */
2991 free_entries(entry);
2993 /* read contents from disk */
2994 if (entry->etype == ET_SHELL)
2996 read_directory(entry, NULL, child->sortOrder, hwnd);
2998 else
3000 get_path(entry, path);
3001 read_directory(entry, path, child->sortOrder, hwnd);
3004 /* insert found entries in right pane */
3005 insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
3006 calc_widths(&child->right, FALSE);
3007 set_header(&child->right);
3009 child->header_wdths_ok = FALSE;
3011 SetCursor(old_cursor);
3015 /* expand a directory entry */
3017 static BOOL expand_entry(ChildWnd* child, Entry* dir)
3019 int idx;
3020 Entry* p;
3022 if (!dir || dir->expanded || !dir->down)
3023 return FALSE;
3025 p = dir->down;
3027 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
3028 p = p->next;
3030 if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
3031 p->data.cFileName[2]=='\0' && p->next)
3032 p = p->next;
3035 /* no subdirectories ? */
3036 if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
3037 return FALSE;
3039 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3041 dir->expanded = TRUE;
3043 /* insert entries in left pane */
3044 insert_entries(&child->left, p, NULL, TF_ALL, idx);
3046 if (!child->header_wdths_ok) {
3047 if (calc_widths(&child->left, FALSE)) {
3048 set_header(&child->left);
3050 child->header_wdths_ok = TRUE;
3054 return TRUE;
3058 static void collapse_entry(Pane* pane, Entry* dir)
3060 int idx;
3062 if (!dir) return;
3063 idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
3065 ShowWindow(pane->hwnd, SW_HIDE);
3067 /* hide sub entries */
3068 for(;;) {
3069 LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
3070 Entry* sub = (Entry*) res;
3072 if (res==LB_ERR || !sub || sub->level<=dir->level)
3073 break;
3075 SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
3078 dir->expanded = FALSE;
3080 ShowWindow(pane->hwnd, SW_SHOW);
3084 static void refresh_right_pane(ChildWnd* child)
3086 SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
3087 insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
3088 calc_widths(&child->right, FALSE);
3090 set_header(&child->right);
3093 static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
3095 WCHAR path[MAX_PATH];
3097 if (!entry)
3098 return;
3100 path[0] = '\0';
3102 child->left.cur = entry;
3104 child->right.root = entry->down? entry->down: entry;
3105 child->right.cur = entry;
3107 if (!entry->scanned)
3108 scan_entry(child, entry, idx, hwnd);
3109 else
3110 refresh_right_pane(child);
3112 get_path(entry, path);
3113 lstrcpyW(child->path, path);
3115 if (child->hwnd) /* only change window title, if the window already exists */
3116 SetWindowTextW(child->hwnd, path);
3118 if (path[0])
3119 if (SetCurrentDirectoryW(path))
3120 set_space_status();
3124 static void refresh_child(ChildWnd* child)
3126 WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
3127 Entry* entry;
3128 int idx;
3130 get_path(child->left.cur, path);
3131 _wsplitpath(path, drv, NULL, NULL, NULL);
3133 child->right.root = NULL;
3135 scan_entry(child, &child->root.entry, 0, child->hwnd);
3137 if (child->root.entry.etype == ET_SHELL)
3139 LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
3140 if (local_pidl)
3141 entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
3142 else
3143 entry = NULL;
3145 else
3146 entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
3148 if (!entry)
3149 entry = &child->root.entry;
3151 insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
3153 set_curdir(child, entry, 0, child->hwnd);
3155 idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
3156 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3160 static void create_drive_bar(void)
3162 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
3163 WCHAR b1[BUFFER_LEN];
3164 int btn = 1;
3165 PWSTR p;
3167 GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
3169 Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
3170 IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
3171 0, 16, 13, 16, 13, sizeof(TBBUTTON));
3173 /* insert shell namespace button */
3174 load_string(b1, ARRAY_SIZE(b1), IDS_SHELL);
3175 b1[lstrlenW(b1)+1] = '\0';
3176 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
3178 drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
3179 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3180 drivebarBtn.iString++;
3182 /* register windows drive root strings */
3183 SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
3185 drivebarBtn.idCommand = ID_DRIVE_FIRST;
3187 for(p=Globals.drives; *p; ) {
3188 switch(GetDriveTypeW(p)) {
3189 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
3190 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
3191 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
3192 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
3193 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
3196 SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
3197 drivebarBtn.idCommand++;
3198 drivebarBtn.iString++;
3200 while(*p++);
3204 static void refresh_drives(void)
3206 RECT rect;
3208 /* destroy drive bar */
3209 DestroyWindow(Globals.hdrivebar);
3210 Globals.hdrivebar = 0;
3212 /* re-create drive bar */
3213 create_drive_bar();
3215 /* update window layout */
3216 GetClientRect(Globals.hMainWnd, &rect);
3217 SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
3221 static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
3223 HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
3225 if (PtrToUlong(hinst) <= 32) {
3226 display_error(hwnd, GetLastError());
3227 return FALSE;
3230 return TRUE;
3234 static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
3236 WCHAR cmd[MAX_PATH];
3238 if (entry->etype == ET_SHELL) {
3239 BOOL ret = TRUE;
3241 SHELLEXECUTEINFOW shexinfo;
3243 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
3244 shexinfo.fMask = SEE_MASK_IDLIST;
3245 shexinfo.hwnd = hwnd;
3246 shexinfo.lpVerb = NULL;
3247 shexinfo.lpFile = NULL;
3248 shexinfo.lpParameters = NULL;
3249 shexinfo.lpDirectory = NULL;
3250 shexinfo.nShow = nCmdShow;
3251 shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
3253 if (!ShellExecuteExW(&shexinfo)) {
3254 display_error(hwnd, GetLastError());
3255 ret = FALSE;
3258 if (shexinfo.lpIDList != entry->pidl)
3259 IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
3261 return ret;
3264 get_path(entry, cmd);
3266 /* start program, open document... */
3267 return launch_file(hwnd, cmd, nCmdShow);
3271 static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
3273 Entry* entry = pane->cur;
3275 if (!entry)
3276 return;
3278 if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
3279 int scanned_old = entry->scanned;
3281 if (!scanned_old)
3283 int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3284 scan_entry(child, entry, idx, hwnd);
3287 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
3288 return;
3290 if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
3291 entry = child->left.cur->up;
3292 collapse_entry(&child->left, entry);
3293 goto focus_entry;
3294 } else if (entry->expanded)
3295 collapse_entry(pane, child->left.cur);
3296 else {
3297 expand_entry(child, child->left.cur);
3299 if (!pane->treePane) focus_entry: {
3300 int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
3301 int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
3302 SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
3303 set_curdir(child, entry, idx, hwnd);
3307 if (!scanned_old) {
3308 calc_widths(pane, FALSE);
3310 set_header(pane);
3312 } else {
3313 if (GetKeyState(VK_MENU) < 0)
3314 show_properties_dlg(entry, child->hwnd);
3315 else
3316 launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
3321 static BOOL pane_command(Pane* pane, UINT cmd)
3323 switch(cmd) {
3324 case ID_VIEW_NAME:
3325 if (pane->visible_cols) {
3326 pane->visible_cols = 0;
3327 calc_widths(pane, TRUE);
3328 set_header(pane);
3329 InvalidateRect(pane->hwnd, 0, TRUE);
3330 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
3331 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
3333 break;
3335 case ID_VIEW_ALL_ATTRIBUTES:
3336 if (pane->visible_cols != COL_ALL) {
3337 pane->visible_cols = COL_ALL;
3338 calc_widths(pane, TRUE);
3339 set_header(pane);
3340 InvalidateRect(pane->hwnd, 0, TRUE);
3341 CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
3342 CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
3344 break;
3346 case ID_PREFERRED_SIZES: {
3347 calc_widths(pane, TRUE);
3348 set_header(pane);
3349 InvalidateRect(pane->hwnd, 0, TRUE);
3350 break;}
3352 /* TODO: more command ids... */
3354 default:
3355 return FALSE;
3358 return TRUE;
3362 static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
3364 if (child->sortOrder != sortOrder) {
3365 child->sortOrder = sortOrder;
3366 refresh_child(child);
3370 static void update_view_menu(ChildWnd* child)
3372 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
3373 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
3374 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
3375 CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
3379 static BOOL is_directory(LPCWSTR target)
3381 DWORD target_attr = GetFileAttributesW(target);
3383 if (target_attr == INVALID_FILE_ATTRIBUTES)
3384 return FALSE;
3386 return (target_attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
3389 static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
3391 WCHAR path[MAX_PATH];
3392 int len;
3394 get_path(pane->cur, path);
3396 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
3397 return FALSE;
3399 get_path(pane->cur, source);
3401 /* convert relative targets to absolute paths */
3402 if (path[0]!='/' && path[1]!=':') {
3403 get_path(pane->cur->up, target);
3404 len = lstrlenW(target);
3406 if (target[len-1]!='\\' && target[len-1]!='/')
3407 target[len++] = '/';
3409 lstrcpyW(target+len, path);
3410 } else
3411 lstrcpyW(target, path);
3413 /* If the target already exists as directory, create a new target below this. */
3414 if (is_directory(path)) {
3415 WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
3416 static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
3418 _wsplitpath(source, NULL, NULL, fname, ext);
3420 wsprintfW(target, sAppend, path, fname, ext);
3423 return TRUE;
3427 static IContextMenu2* s_pctxmenu2 = NULL;
3428 static IContextMenu3* s_pctxmenu3 = NULL;
3430 static void CtxMenu_reset(void)
3432 s_pctxmenu2 = NULL;
3433 s_pctxmenu3 = NULL;
3436 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
3438 IContextMenu* pcm = NULL;
3440 CtxMenu_reset();
3442 if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
3443 s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
3444 else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
3445 s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
3447 if (pcm) {
3448 IContextMenu_Release(pcm1);
3449 return pcm;
3450 } else
3451 return pcm1;
3454 static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
3456 if (s_pctxmenu3) {
3457 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
3458 return TRUE;
3461 if (s_pctxmenu2)
3462 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
3463 return TRUE;
3465 return FALSE;
3468 static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
3470 IContextMenu* pcm;
3471 BOOL executed = FALSE;
3473 HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
3475 if (SUCCEEDED(hr)) {
3476 HMENU hmenu = CreatePopupMenu();
3478 pcm = CtxMenu_query_interfaces(pcm);
3480 if (hmenu) {
3481 hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
3483 if (SUCCEEDED(hr)) {
3484 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
3486 CtxMenu_reset();
3488 if (idCmd) {
3489 CMINVOKECOMMANDINFO cmi;
3491 cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
3492 cmi.fMask = 0;
3493 cmi.hwnd = hwndParent;
3494 cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
3495 cmi.lpParameters = NULL;
3496 cmi.lpDirectory = NULL;
3497 cmi.nShow = SW_SHOWNORMAL;
3498 cmi.dwHotKey = 0;
3499 cmi.hIcon = 0;
3501 hr = IContextMenu_InvokeCommand(pcm, &cmi);
3502 executed = TRUE;
3504 } else
3505 CtxMenu_reset();
3508 IContextMenu_Release(pcm);
3511 return FAILED(hr)? hr: executed? S_OK: S_FALSE;
3514 static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3516 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
3517 assert(child);
3519 switch(nmsg) {
3520 case WM_DRAWITEM: {
3521 LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
3522 Entry* entry = (Entry*) dis->itemData;
3524 if (dis->CtlID == IDW_TREE_LEFT)
3525 draw_item(&child->left, dis, entry, -1);
3526 else if (dis->CtlID == IDW_TREE_RIGHT)
3527 draw_item(&child->right, dis, entry, -1);
3528 else
3529 goto draw_menu_item;
3531 return TRUE;}
3533 case WM_CREATE:
3534 InitChildWindow(child);
3535 break;
3537 case WM_NCDESTROY:
3538 free_child_window(child);
3539 SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
3540 break;
3542 case WM_PAINT: {
3543 PAINTSTRUCT ps;
3544 HBRUSH lastBrush;
3545 RECT rt;
3546 GetClientRect(hwnd, &rt);
3547 BeginPaint(hwnd, &ps);
3548 rt.left = child->split_pos-SPLIT_WIDTH/2;
3549 rt.right = child->split_pos+SPLIT_WIDTH/2+1;
3550 lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
3551 Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
3552 SelectObject(ps.hdc, lastBrush);
3553 EndPaint(hwnd, &ps);
3554 break;}
3556 case WM_SETCURSOR:
3557 if (LOWORD(lparam) == HTCLIENT) {
3558 POINT pt;
3559 GetCursorPos(&pt);
3560 ScreenToClient(hwnd, &pt);
3562 if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
3563 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
3564 return TRUE;
3567 goto def;
3569 case WM_LBUTTONDOWN: {
3570 RECT rt;
3571 int x = (short)LOWORD(lparam);
3573 GetClientRect(hwnd, &rt);
3575 if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
3576 last_split = child->split_pos;
3577 SetCapture(hwnd);
3580 break;}
3582 case WM_LBUTTONUP:
3583 if (GetCapture() == hwnd)
3584 ReleaseCapture();
3585 break;
3587 case WM_KEYDOWN:
3588 if (wparam == VK_ESCAPE)
3589 if (GetCapture() == hwnd) {
3590 RECT rt;
3591 child->split_pos = last_split;
3592 GetClientRect(hwnd, &rt);
3593 resize_tree(child, rt.right, rt.bottom);
3594 last_split = -1;
3595 ReleaseCapture();
3596 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
3598 break;
3600 case WM_MOUSEMOVE:
3601 if (GetCapture() == hwnd) {
3602 RECT rt;
3603 int x = (short)LOWORD(lparam);
3605 GetClientRect(hwnd, &rt);
3607 if (x>=0 && x<rt.right) {
3608 child->split_pos = x;
3609 resize_tree(child, rt.right, rt.bottom);
3610 rt.left = x-SPLIT_WIDTH/2;
3611 rt.right = x+SPLIT_WIDTH/2+1;
3612 InvalidateRect(hwnd, &rt, FALSE);
3613 UpdateWindow(child->left.hwnd);
3614 UpdateWindow(hwnd);
3615 UpdateWindow(child->right.hwnd);
3618 break;
3620 case WM_GETMINMAXINFO:
3621 DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
3623 {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
3625 lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
3626 lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
3627 break;}
3629 case WM_SETFOCUS:
3630 if (SetCurrentDirectoryW(child->path))
3631 set_space_status();
3632 SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
3633 break;
3635 case WM_DISPATCH_COMMAND: {
3636 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3638 switch(LOWORD(wparam)) {
3639 case ID_WINDOW_NEW: {
3640 ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
3642 if (!create_child_window(new_child))
3643 HeapFree(GetProcessHeap(), 0, new_child);
3645 break;}
3647 case ID_REFRESH:
3648 refresh_drives();
3649 refresh_child(child);
3650 break;
3652 case ID_ACTIVATE:
3653 activate_entry(child, pane, hwnd);
3654 break;
3656 case ID_FILE_MOVE: {
3657 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
3659 if (prompt_target(pane, source, target)) {
3660 SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
3662 source[lstrlenW(source)+1] = '\0';
3663 target[lstrlenW(target)+1] = '\0';
3665 if (!SHFileOperationW(&shfo))
3666 refresh_child(child);
3668 break;}
3670 case ID_FILE_COPY: {
3671 WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
3673 if (prompt_target(pane, source, target)) {
3674 SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
3676 source[lstrlenW(source)+1] = '\0';
3677 target[lstrlenW(target)+1] = '\0';
3679 if (!SHFileOperationW(&shfo))
3680 refresh_child(child);
3682 break;}
3684 case ID_FILE_DELETE: {
3685 WCHAR path[BUFFER_LEN];
3686 SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
3688 get_path(pane->cur, path);
3690 path[lstrlenW(path)+1] = '\0';
3692 if (!SHFileOperationW(&shfo))
3693 refresh_child(child);
3694 break;}
3696 case ID_VIEW_SORT_NAME:
3697 set_sort_order(child, SORT_NAME);
3698 break;
3700 case ID_VIEW_SORT_TYPE:
3701 set_sort_order(child, SORT_EXT);
3702 break;
3704 case ID_VIEW_SORT_SIZE:
3705 set_sort_order(child, SORT_SIZE);
3706 break;
3708 case ID_VIEW_SORT_DATE:
3709 set_sort_order(child, SORT_DATE);
3710 break;
3712 case ID_VIEW_FILTER: {
3713 struct FilterDialog dlg;
3715 memset(&dlg, 0, sizeof(struct FilterDialog));
3716 lstrcpyW(dlg.pattern, child->filter_pattern);
3717 dlg.flags = child->filter_flags;
3719 if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
3720 lstrcpyW(child->filter_pattern, dlg.pattern);
3721 child->filter_flags = dlg.flags;
3722 refresh_right_pane(child);
3724 break;}
3726 case ID_VIEW_SPLIT: {
3727 last_split = child->split_pos;
3728 SetCapture(hwnd);
3729 break;}
3731 case ID_EDIT_PROPERTIES:
3732 show_properties_dlg(pane->cur, child->hwnd);
3733 break;
3735 default:
3736 return pane_command(pane, LOWORD(wparam));
3739 return TRUE;}
3741 case WM_COMMAND: {
3742 Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3744 switch(HIWORD(wparam)) {
3745 case LBN_SELCHANGE: {
3746 int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
3747 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
3749 if (pane == &child->left)
3750 set_curdir(child, entry, idx, hwnd);
3751 else
3752 pane->cur = entry;
3753 break;}
3755 case LBN_DBLCLK:
3756 activate_entry(child, pane, hwnd);
3757 break;
3759 break;}
3761 case WM_NOTIFY: {
3762 NMHDR* pnmh = (NMHDR*) lparam;
3763 return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
3765 case WM_CONTEXTMENU: {
3766 POINT pt, pt_clnt;
3767 Pane* pane;
3768 int idx;
3770 /* first select the current item in the listbox */
3771 HWND hpanel = (HWND) wparam;
3772 pt_clnt.x = pt.x = (short)LOWORD(lparam);
3773 pt_clnt.y = pt.y = (short)HIWORD(lparam);
3774 ScreenToClient(hpanel, &pt_clnt);
3775 SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
3776 SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
3778 /* now create the popup menu using shell namespace and IContextMenu */
3779 pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
3780 idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
3782 if (idx != -1) {
3783 Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
3785 LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
3787 if (pidl_abs) {
3788 IShellFolder* parentFolder;
3789 LPCITEMIDLIST pidlLast;
3791 /* get and use the parent folder to display correct context menu in all cases */
3792 if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
3793 if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
3794 refresh_child(child);
3796 IShellFolder_Release(parentFolder);
3799 IMalloc_Free(Globals.iMalloc, pidl_abs);
3802 break;}
3804 case WM_MEASUREITEM:
3805 draw_menu_item:
3806 if (!wparam) /* Is the message menu-related? */
3807 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
3808 return TRUE;
3810 break;
3812 case WM_INITMENUPOPUP:
3813 if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
3814 return 0;
3816 update_view_menu(child);
3817 break;
3819 case WM_MENUCHAR: /* only supported by IContextMenu3 */
3820 if (s_pctxmenu3) {
3821 LRESULT lResult = 0;
3823 IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
3825 return lResult;
3828 break;
3830 case WM_SIZE:
3831 if (wparam != SIZE_MINIMIZED)
3832 resize_tree(child, LOWORD(lparam), HIWORD(lparam));
3833 /* fall through */
3835 default: def:
3836 return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
3839 return 0;
3843 static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
3845 ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
3846 Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
3847 assert(child);
3849 switch(nmsg) {
3850 case WM_HSCROLL:
3851 set_header(pane);
3852 break;
3854 case WM_SETFOCUS:
3855 child->focus_pane = pane==&child->right? 1: 0;
3856 SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
3857 /*TODO: check menu items */
3858 break;
3860 case WM_KEYDOWN:
3861 if (wparam == VK_TAB) {
3862 /*TODO: SetFocus(Globals.hdrivebar) */
3863 SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
3867 return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
3871 static void InitInstance(HINSTANCE hinstance)
3873 static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
3875 WNDCLASSEXW wcFrame;
3876 WNDCLASSW wcChild;
3877 int col;
3879 INITCOMMONCONTROLSEX icc = {
3880 sizeof(INITCOMMONCONTROLSEX),
3881 ICC_BAR_CLASSES
3884 HDC hdc = GetDC(0);
3886 setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
3888 InitCommonControlsEx(&icc);
3891 /* register frame window class */
3893 wcFrame.cbSize = sizeof(WNDCLASSEXW);
3894 wcFrame.style = 0;
3895 wcFrame.lpfnWndProc = FrameWndProc;
3896 wcFrame.cbClsExtra = 0;
3897 wcFrame.cbWndExtra = 0;
3898 wcFrame.hInstance = hinstance;
3899 wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
3900 wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
3901 wcFrame.hbrBackground = 0;
3902 wcFrame.lpszMenuName = 0;
3903 wcFrame.lpszClassName = sWINEFILEFRAME;
3904 wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
3906 Globals.hframeClass = RegisterClassExW(&wcFrame);
3909 /* register tree windows class */
3911 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
3912 wcChild.lpfnWndProc = ChildWndProc;
3913 wcChild.cbClsExtra = 0;
3914 wcChild.cbWndExtra = 0;
3915 wcChild.hInstance = hinstance;
3916 wcChild.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
3917 wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
3918 wcChild.hbrBackground = 0;
3919 wcChild.lpszMenuName = 0;
3920 wcChild.lpszClassName = sWINEFILETREE;
3922 RegisterClassW(&wcChild);
3925 Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
3927 Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
3929 ReleaseDC(0, hdc);
3931 Globals.hInstance = hinstance;
3933 CoInitialize(NULL);
3934 CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
3935 SHGetDesktopFolder(&Globals.iDesktop);
3936 Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
3938 /* load column strings */
3939 col = 1;
3941 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_NAME);
3942 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SIZE);
3943 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_CDATE);
3944 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ADATE);
3945 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_MDATE);
3946 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_IDX);
3947 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_LINKS);
3948 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ATTR);
3949 load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SEC);
3953 static BOOL show_frame(HWND hwndParent, int cmdshow, LPWSTR path)
3955 static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
3957 WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
3958 ChildWnd* child;
3959 HMENU hMenuFrame, hMenuWindow;
3960 windowOptions opts;
3962 CLIENTCREATESTRUCT ccs;
3964 if (Globals.hMainWnd)
3965 return TRUE;
3967 opts = load_registry_settings();
3968 hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
3969 hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
3971 Globals.hMenuFrame = hMenuFrame;
3972 Globals.hMenuView = GetSubMenu(hMenuFrame, 2);
3973 Globals.hMenuOptions = GetSubMenu(hMenuFrame, 3);
3975 ccs.hWindowMenu = hMenuWindow;
3976 ccs.idFirstChild = IDW_FIRST_CHILD;
3979 /* create main window */
3980 Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINEFILE), WS_OVERLAPPEDWINDOW,
3981 opts.start_x, opts.start_y, opts.width, opts.height,
3982 hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
3985 Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
3986 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
3987 0, 0, 0, 0,
3988 Globals.hMainWnd, 0, Globals.hInstance, &ccs);
3990 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
3991 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
3993 create_drive_bar();
3996 TBBUTTON toolbarBtns[] = {
3997 {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
3998 {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
3999 {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4000 {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4001 {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
4004 Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
4005 IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
4006 ARRAY_SIZE(toolbarBtns), 16, 15, 16, 15, sizeof(TBBUTTON));
4007 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
4010 Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
4011 CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
4013 /*TODO: read paths from registry */
4015 if (!path || !*path) {
4016 GetCurrentDirectoryW(MAX_PATH, buffer);
4017 path = buffer;
4020 ShowWindow(Globals.hMainWnd, cmdshow);
4022 /* Shell Namespace as default: */
4023 child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
4025 child->pos.showCmd = SW_SHOWMAXIMIZED;
4026 child->pos.rcNormalPosition.left = 0;
4027 child->pos.rcNormalPosition.top = 0;
4028 child->pos.rcNormalPosition.right = 320;
4029 child->pos.rcNormalPosition.bottom = 280;
4031 if (!create_child_window(child)) {
4032 HeapFree(GetProcessHeap(), 0, child);
4033 return FALSE;
4036 SetWindowPlacement(child->hwnd, &child->pos);
4038 Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
4040 Globals.prescan_node = FALSE;
4042 UpdateWindow(Globals.hMainWnd);
4044 if (child->hwnd && path && path[0])
4046 int index,count;
4047 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
4048 WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
4050 memset(name,0,sizeof(name));
4051 memset(name,0,sizeof(ext));
4052 _wsplitpath(path, drv, dir, name, ext);
4053 if (name[0])
4055 count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
4056 lstrcpyW(fullname,name);
4057 lstrcatW(fullname,ext);
4059 for (index = 0; index < count; index ++)
4061 Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
4062 if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
4063 lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
4065 SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
4066 SetFocus(child->right.hwnd);
4067 break;
4072 return TRUE;
4075 static void ExitInstance(void)
4077 IShellFolder_Release(Globals.iDesktop);
4078 IMalloc_Release(Globals.iMalloc);
4079 CoUninitialize();
4081 DeleteObject(Globals.hfont);
4082 ImageList_Destroy(Globals.himl);
4085 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
4087 MSG msg;
4089 InitInstance(hinstance);
4091 if( !show_frame(0, cmdshow, cmdline) )
4093 ExitInstance();
4094 return 1;
4097 while(GetMessageW(&msg, 0, 0, 0)) {
4098 if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
4099 continue;
4101 if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
4102 continue;
4104 TranslateMessage(&msg);
4105 DispatchMessageW(&msg);
4108 ExitInstance();
4110 return msg.wParam;