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
29 #ifdef NONAMELESSUNION
30 #define UNION_MEMBER(x) DUMMYUNIONNAME.x
32 #define UNION_MEMBER(x) x
35 #define DEFAULT_SPLIT_POS 300
37 static const WCHAR registry_key
[] = { 'S','o','f','t','w','a','r','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'};
51 typedef struct _Entry
{
60 WIN32_FIND_DATAW data
;
62 BY_HANDLE_FILE_INFORMATION bhfi
;
64 enum ENTRY_TYPE etype
;
73 WCHAR volname
[_MAX_FNAME
];
83 COL_ATTRIBUTES
= 0x08,
87 COL_ALL
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
|COL_DOSNAMES
|COL_INDEX
|COL_LINKS
103 int widths_shown
[COLUMNS
];
104 int positions
[COLUMNS
+1];
116 int focus_pane
; /* 0: left 1: right */
119 BOOL header_wdths_ok
;
121 WCHAR path
[MAX_PATH
];
122 WCHAR filter_pattern
[MAX_PATH
];
126 SORT_ORDER sortOrder
;
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
);
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];
164 *(--p
) = '0' + val
% 10;
171 /* load resource string */
172 static LPWSTR
load_string(LPWSTR buffer
, DWORD size
, UINT id
)
174 LoadStringW(Globals
.hInstance
, id
, buffer
, size
);
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
];
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
);
191 MessageBoxW(hwnd
, RS(b1
,IDS_ERROR
), RS(b2
,IDS_WINEFILE
), MB_OK
);
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
];
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
];
223 HDC hdc
= GetDC(hwnd
);
225 GetObjectW(Globals
.hfont
, sizeof(LOGFONTW
), &lFont
);
227 chFont
.lStructSize
= sizeof(CHOOSEFONTW
);
228 chFont
.hwndOwner
= hwnd
;
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
;
240 chFont
.nSizeMax
= 24;
242 if (ChooseFontW(&chFont
)) {
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
));
280 entry
->folder
= NULL
;
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
);
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
;
320 static void read_directory_win(Entry
* dir
, LPCWSTR path
)
322 Entry
* first_entry
= NULL
;
326 int level
= dir
->level
+ 1;
327 WIN32_FIND_DATAW w32fd
;
331 WCHAR buffer
[MAX_PATH
], *p
;
332 for(p
=buffer
; *path
; )
339 hFind
= FindFirstFileW(buffer
, &w32fd
);
341 if (hFind
!= INVALID_HANDLE_VALUE
) {
343 entry
= alloc_entry();
351 memcpy(&entry
->data
, &w32fd
, sizeof(WIN32_FIND_DATAW
));
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
;
373 } while(FindNextFileW(hFind
, &w32fd
));
381 dir
->down
= first_entry
;
386 static Entry
* find_entry_win(Entry
* dir
, LPCWSTR name
)
390 for(entry
=dir
->down
; entry
; entry
=entry
->next
) {
392 LPCWSTR q
= entry
->data
.cFileName
;
395 if (!*p
|| *p
== '\\' || *p
== '/')
397 } while(tolower(*p
++) == tolower(*q
++));
400 q
= entry
->data
.cAlternateFileName
;
403 if (!*p
|| *p
== '\\' || *p
== '/')
405 } while(tolower(*p
++) == tolower(*q
++));
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
;
419 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
421 entry
->etype
= ET_WINDOWS
;
423 while(*s
&& *s
!= '\\' && *s
!= '/')
426 while(*s
== '\\' || *s
== '/')
432 read_directory(entry
, buffer
, sortOrder
, hwnd
);
435 entry
->expanded
= TRUE
;
440 entry
= find_entry_win(entry
, s
);
443 SetCursor(old_cursor
);
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
)
460 for(s
=source
; count
&&(*d
++=*s
++); )
466 static void get_strretW(STRRET
* str
, const SHITEMID
* shiid
, LPWSTR buffer
, int len
)
470 wcscpyn(buffer
, str
->UNION_MEMBER(pOleStr
), len
);
474 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)shiid
+str
->UNION_MEMBER(uOffset
), -1, buffer
, len
);
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
)
487 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, flags
, &str
);
490 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
499 static HRESULT
path_from_pidlW(IShellFolder
* folder
, LPITEMIDLIST pidl
, LPWSTR buffer
, int len
)
503 /* SHGDN_FORPARSING: get full path of id list */
504 HRESULT hr
= IShellFolder_GetDisplayNameOf(folder
, pidl
, SHGDN_FORPARSING
, &str
);
507 get_strretW(&str
, &pidl
->mkid
, buffer
, len
);
516 /* create an item id list from a file system path */
518 static LPITEMIDLIST
get_path_pidl(LPWSTR path
, HWND hwnd
)
523 LPWSTR buffer
= path
;
525 hr
= IShellFolder_ParseDisplayName(Globals
.iDesktop
, hwnd
, NULL
, buffer
, &len
, &pidl
, NULL
);
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
;
541 idl
= ILCombine(ILClone(entry
->pidl
), 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
);
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
];
569 if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract
, GIL_FORSHELL
, path
, _MAX_PATH
, &idx
, &flags
))) {
570 if (!(flags
& GIL_NOTFILENAME
)) {
572 idx
= 0; /* special case for some control panel applications */
574 if ((int)ExtractIconExW(path
, idx
, 0, &hicon
, 1) > 0)
575 flags
&= ~GIL_DONTCACHE
;
577 HICON hIconLarge
= 0;
579 HRESULT hr
= IExtractIconW_Extract(pExtract
, path
, idx
, &hIconLarge
, &hicon
, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON
)));
582 DestroyIcon(hIconLarge
);
593 static Entry
* find_entry_shell(Entry
* dir
, LPCITEMIDLIST pidl
)
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
))
606 static Entry
* read_tree_shell(Root
* root
, LPITEMIDLIST pidl
, SORT_ORDER sortOrder
, HWND hwnd
)
608 Entry
* entry
= &root
->entry
;
610 LPITEMIDLIST next_pidl
= pidl
;
611 IShellFolder
* folder
;
612 IShellFolder
* child
= NULL
;
615 HCURSOR old_cursor
= SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_WAIT
));
617 entry
->etype
= ET_SHELL
;
618 folder
= Globals
.iDesktop
;
621 entry
->pidl
= next_pidl
;
622 entry
->folder
= folder
;
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
);
636 read_directory(entry
, NULL
, sortOrder
, hwnd
);
639 entry
->expanded
= TRUE
;
641 next
= find_entry_shell(entry
, next_pidl
);
648 /* go to next element */
649 pidl
= (LPITEMIDLIST
) ((LPBYTE
)pidl
+pidl
->mkid
.cb
);
652 SetCursor(old_cursor
);
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
);
671 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
673 IDataObject_Release(pDataObj
);
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;
719 Entry
* first_entry
= NULL
;
726 hr
= IShellFolder_EnumObjects(folder
, hwnd
, SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
|SHCONTF_SHAREABLE
|SHCONTF_STORAGE
, &idlist
);
730 #define FETCH_ITEM_COUNT 32
731 LPITEMIDLIST pidls
[FETCH_ITEM_COUNT
];
736 memset(pidls
, 0, sizeof(pidls
));
738 hr
= IEnumIDList_Next(idlist
, FETCH_ITEM_COUNT
, pidls
, &cnt
);
745 for(n
=0; n
<cnt
; ++n
) {
746 entry
= alloc_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
);
762 if (attribs
!= (SFGAOF
)~SFGAO_FILESYSTEM
) {
763 fill_w32fdata_shell(folder
, pidls
[n
], attribs
, &entry
->data
);
765 entry
->bhfi_valid
= TRUE
;
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
);
777 entry
->folder
= child
;
779 entry
->folder
= NULL
;
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
]);
793 entry
->hicon
= (HICON
)-1; /* don't try again later */
798 entry
->expanded
= FALSE
;
799 entry
->scanned
= FALSE
;
800 entry
->level
= level
;
802 entry
->etype
= ET_SHELL
;
803 entry
->bhfi_valid
= FALSE
;
809 IEnumIDList_Release(idlist
);
815 dir
->down
= first_entry
;
819 /* sort order for different directory/file types */
828 /* distinguish between ".", ".." and any other directory names */
829 static int TypeOrderFromDirname(LPCWSTR name
)
831 if (name
[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
);
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
);
880 name1
= fd1
->cFileName
;
881 name2
= fd2
->cFileName
;
883 ext1
= wcsrchr(name1
, '.');
884 ext2
= wcsrchr(name2
, '.');
896 cmp
= lstrcmpiW(ext1
, ext2
);
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
);
912 cmp
= fd2
->nFileSizeHigh
- fd1
->nFileSizeHigh
;
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
);
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
)
952 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
956 array
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(Entry
*));
959 for(entry
=dir
->down
; entry
; entry
=entry
->next
)
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
++)
972 HeapFree(GetProcessHeap(), 0, array
);
977 static void read_directory(Entry
* dir
, LPCWSTR path
, SORT_ORDER sortOrder
, HWND hwnd
)
979 WCHAR buffer
[MAX_PATH
];
984 if (dir
->etype
== ET_SHELL
)
986 read_directory_shell(dir
, hwnd
);
988 if (Globals
.prescan_node
) {
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
);
1006 read_directory_win(dir
, path
);
1008 if (Globals
.prescan_node
) {
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'};
1036 /* read shell namespace tree */
1037 root
->drive_type
= DRIVE_UNKNOWN
;
1040 load_string(root
->volname
, ARRAY_SIZE(root
->volname
), IDS_DESKTOP
);
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 */
1061 TF_DIRECTORIES
= 0x01,
1063 TF_DOCUMENTS
= 0x04,
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
;
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
;
1104 int pathlen
= lstrlenW(path
);
1105 const WCHAR
*npath
= path
;
1107 if (path
[0] == '"' && path
[pathlen
- 1] == '"')
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
);
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
);
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
)
1157 if (dir
->etype
== ET_SHELL
)
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
);
1177 for(entry
=dir
; entry
; level
++) {
1183 name
= entry
->data
.cFileName
;
1186 for(l
=0; *s
&& *s
!= '/' && *s
!= '\\'; s
++)
1192 memmove(path
+l
+1, path
, len
*sizeof(WCHAR
));
1193 memcpy(path
+1, name
, l
*sizeof(WCHAR
));
1200 memmove(path
+l
, path
, len
*sizeof(WCHAR
));
1201 memcpy(path
, name
, l
*sizeof(WCHAR
));
1207 if (!level
) path
[len
++] = '\\';
1212 static windowOptions
load_registry_settings(void)
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
);
1253 static void save_registry_settings(void)
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 */
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
)
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
)
1336 resize_frame_rect(hwnd
, &rect
);
1339 static void resize_frame_client(HWND hwnd
)
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
;
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
;
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
;
1380 hcbthook
= SetWindowsHookExW(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
1383 child
->hwnd
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
1385 UnhookWindowsHookEx(hcbthook
);
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);
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
];
1419 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, lparam
);
1420 SetWindowTextW(GetDlgItem(hwnd
, 201), (LPCWSTR
)lparam
);
1424 int id
= (int)wparam
;
1428 LPWSTR dest
= (LPWSTR
)GetWindowLongPtrW(hwnd
, GWLP_USERDATA
);
1429 GetWindowTextW(GetDlgItem(hwnd
, 201), dest
, MAX_PATH
);
1430 EndDialog(hwnd
, id
);
1434 EndDialog(hwnd
, id
);
1438 MessageBoxW(hwnd
, RS(b1
,IDS_NO_IMPL
), RS(b2
,IDS_WINEFILE
), MB_OK
);
1450 struct FilterDialog
{
1451 WCHAR pattern
[MAX_PATH
];
1455 static INT_PTR CALLBACK
FilterDialogDlgProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1457 static struct FilterDialog
* dlg
;
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
);
1471 int id
= (int)wparam
;
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;
1486 EndDialog(hwnd
, id
);
1487 } else if (id
== IDCANCEL
)
1488 EndDialog(hwnd
, id
);
1497 struct PropertiesDialog
{
1498 WCHAR path
[MAX_PATH
];
1503 /* Structure used to store enumerated languages and code pages. */
1504 struct LANGANDCODEPAGE
{
1509 static LPCSTR InfoStrings
[] = {
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);
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
)) {
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
) {
1577 for(p
=InfoStrings
; *p
; ++p
) {
1578 WCHAR subblock
[200];
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
;
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
);
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
));
1650 if (id
==IDOK
|| id
==IDCANCEL
)
1651 EndDialog(hwnd
, id
);
1657 HeapFree(GetProcessHeap(), 0, dlg
->pVersionData
);
1658 dlg
->pVersionData
= NULL
;
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
{
1686 static void frame_get_clientspace(HWND hwnd
, PRECT prect
)
1690 if (!IsIconic(hwnd
))
1691 GetClientRect(hwnd
, prect
);
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
)
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
);
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
)
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
];
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
);
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
);
1809 static BOOL
activate_fs_window(LPCWSTR filesys
)
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
);
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
);
1832 static LRESULT CALLBACK
FrameWndProc(HWND hwnd
, UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1834 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
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;
1856 case WM_INITMENUPOPUP
: {
1857 HWND hwndClient
= (HWND
)SendMessageW(Globals
.hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1859 if (!SendMessageW(hwndClient
, WM_INITMENUPOPUP
, wparam
, lparam
))
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
))
1870 if (cmd
>=ID_DRIVE_FIRST
&& cmd
<=ID_DRIVE_FIRST
+0xFF) {
1871 WCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1873 LPCWSTR root
= Globals
.drives
;
1876 for(i
=cmd
-ID_DRIVE_FIRST
; i
--; root
++)
1880 if (activate_drive_window(root
))
1883 _wsplitpath(root
, drv
, 0, 0, 0);
1885 if (!SetCurrentDirectoryW(drv
)) {
1886 display_error(hwnd
, GetLastError());
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
) {
1897 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
1900 case ID_WINDOW_NEW
: {
1901 WCHAR path
[MAX_PATH
];
1904 GetCurrentDirectoryW(MAX_PATH
, path
);
1905 child
= alloc_child_window(path
, NULL
, hwnd
);
1907 if (!create_child_window(child
))
1908 HeapFree(GetProcessHeap(), 0, child
);
1915 case ID_WINDOW_CASCADE
:
1916 SendMessageW(Globals
.hmdiclient
, WM_MDICASCADE
, 0, 0);
1919 case ID_WINDOW_TILE_HORZ
:
1920 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1923 case ID_WINDOW_TILE_VERT
:
1924 SendMessageW(Globals
.hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1927 case ID_WINDOW_ARRANGE
:
1928 SendMessageW(Globals
.hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1931 case ID_SELECT_FONT
:
1935 case ID_VIEW_TOOL_BAR
:
1936 toggle_child(hwnd
, cmd
, Globals
.htoolbar
);
1939 case ID_VIEW_DRIVE_BAR
:
1940 toggle_child(hwnd
, cmd
, Globals
.hdrivebar
);
1943 case ID_VIEW_STATUSBAR
:
1944 toggle_child(hwnd
, cmd
, Globals
.hstatusbar
);
1947 case ID_VIEW_SAVESETTINGS
:
1948 Globals
.saveSettings
= !Globals
.saveSettings
;
1949 CheckMenuItem(Globals
.hMenuOptions
, ID_VIEW_SAVESETTINGS
,
1950 Globals
.saveSettings
? MF_CHECKED
: MF_UNCHECKED
);
1954 WineFile_OnRun( hwnd
);
1957 case ID_CONNECT_NETWORK_DRIVE
: {
1958 DWORD ret
= WNetConnectionDialog(hwnd
, RESOURCETYPE_DISK
);
1959 if (ret
== NO_ERROR
)
1961 else if (ret
!= (DWORD
)-1) {
1962 if (ret
== ERROR_EXTENDED_ERROR
)
1963 display_network_error(hwnd
);
1965 display_error(hwnd
, ret
);
1969 case ID_DISCONNECT_NETWORK_DRIVE
: {
1970 DWORD ret
= WNetDisconnectDialog(hwnd
, RESOURCETYPE_DISK
);
1971 if (ret
== NO_ERROR
)
1973 else if (ret
!= (DWORD
)-1) {
1974 if (ret
== ERROR_EXTENDED_ERROR
)
1975 display_network_error(hwnd
);
1977 display_error(hwnd
, ret
);
1982 WinHelpW(hwnd
, RS(b1
,IDS_WINEFILE
), HELP_INDEX
, 0);
1985 case ID_VIEW_FULLSCREEN
:
1986 CheckMenuItem(Globals
.hMenuOptions
, cmd
, toggle_fullscreen(hwnd
)?MF_CHECKED
:0);
1989 case ID_DRIVE_SHELL_NS
: {
1990 WCHAR path
[MAX_PATH
];
1993 if (activate_fs_window(RS(b1
,IDS_SHELL
)))
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
);
2003 /*TODO: There are even more menu items! */
2006 ShellAboutW(hwnd
, RS(b1
,IDS_WINEFILE
), NULL
,
2007 LoadImageW( Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINEFILE
),
2008 IMAGE_ICON
, 48, 48, LR_SHARED
));
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
);
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);
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 */
2037 case FRM_CALC_CLIENT
:
2038 frame_get_clientspace(hwnd
, (PRECT
)lparam
);
2042 return DefFrameProcW(hwnd
, Globals
.hmdiclient
, nmsg
, wparam
, lparam
);
2049 static WCHAR g_pos_names
[COLUMNS
][40] = {
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);
2078 cx
= child
->split_pos
+ SPLIT_WIDTH
/2;
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
)
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);
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
);
2119 static void init_output(HWND hwnd
)
2121 static const WCHAR s1000
[] = {'1','0','0','0','\0'};
2124 HDC hdc
= GetDC(hwnd
);
2126 if (GetNumberFormatW(LOCALE_USER_DEFAULT
, 0, s1000
, 0, b
, 16) > 4)
2127 Globals
.num_sep
= b
[1];
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];
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);
2173 dis
.hwndItem
= pane
->hwnd
;
2175 SetRectEmpty(&dis
.rcItem
);
2176 /*dis.itemData = 0; */
2178 draw_item(pane
, &dis
, entry
, COLUMNS
);
2181 SelectObject(hdc
, hfontOld
);
2182 ReleaseDC(pane
->hwnd
, hdc
);
2185 for(col
=0; col
<COLUMNS
; col
++) {
2186 pane
->positions
[col
] = x
;
2187 cx
= pane
->widths
[col
];
2192 if (cx
< IMAGE_WIDTH
)
2195 pane
->widths
[col
] = cx
;
2201 pane
->positions
[COLUMNS
] = x
;
2203 SendMessageW(pane
->hwnd
, LB_SETHORIZONTALEXTENT
, x
, 0);
2206 if (!anyway
&& !memcmp(orgWidths
, pane
->widths
, sizeof(orgWidths
)))
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
));
2218 InvalidateRect(pane
->hwnd
, 0, TRUE
);
2223 /* calculate one preferred column width */
2224 static void calc_single_width(Pane
* pane
, int col
)
2228 int entries
= SendMessageW(pane
->hwnd
, LB_GETCOUNT
, 0, 0);
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);
2246 dis
.hwndItem
= pane
->hwnd
;
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
];
2260 cx
+= 3*Globals
.spaceSize
.cx
;
2262 if (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
== '*') {
2283 while(*pattern
== '*');
2289 if (*str
==*pattern
&& pattern_match(str
, pattern
))
2294 else if (*str
!=*pattern
&& *pattern
!='?')
2298 if (*str
|| *pattern
)
2299 if (*pattern
!='*' || pattern
[1]!='\0')
2305 static BOOL
pattern_imatch(LPCWSTR str
, LPCWSTR pattern
)
2307 WCHAR b1
[BUFFER_LEN
], b2
[BUFFER_LEN
];
2310 lstrcpyW(b2
, pattern
);
2314 return pattern_match(b1
, b2
);
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
)
2336 ShowWindow(pane
->hwnd
, SW_HIDE
);
2338 for(; entry
; entry
=entry
->next
) {
2339 if (pane
->treePane
&& !(entry
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
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'))
2350 /* filter directories in right pane */
2351 if (!pane
->treePane
&& !(filter_flags
&TF_DIRECTORIES
))
2355 /* filter using the file name pattern */
2357 if (!pattern_imatch(entry
->data
.cFileName
, pattern
))
2360 /* filter system and hidden files */
2361 if (!(filter_flags
&TF_HIDDEN
) && (entry
->data
.dwFileAttributes
&(FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
)))
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
)) {
2368 if (!(filter_flags
& TF_PROGRAMS
))
2373 if (!(filter_flags
& TF_DOCUMENTS
))
2377 default: /* TF_OTHERS */
2378 if (!(filter_flags
& TF_OTHERS
))
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
);
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
)) {
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
);
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 */
2437 insert_entries(pane
, entry
, pattern
, filter_flags
, -1);
2439 /* calculate column widths */
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
)
2466 if (!ft
->dwLowDateTime
&& !ft
->dwHighDateTime
)
2469 if (!FileTimeToLocalFileTime(ft
, &lft
))
2470 {err
: lstrcpyW(buffer
,sQMarks
); return;}
2472 if (!FileTimeToSystemTime(&lft
, &systime
))
2475 if (visible_cols
& COL_DATE
) {
2476 len
= GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
, BUFFER_LEN
);
2481 if (visible_cols
& COL_TIME
) {
2483 buffer
[len
-1] = ' ';
2485 buffer
[len
++] = ' ';
2487 if (!GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &systime
, 0, buffer
+len
, BUFFER_LEN
-len
))
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
;
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
;
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
;
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
;
2558 /* insert number separator characters */
2559 pos
= lstrlenW(s
) % 3;
2565 *d
++ = Globals
.num_sep
;
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] = {
2586 WCHAR ext_buffer
[_MAX_EXT
];
2587 const WCHAR (*p
)[4];
2591 for(s
=ext
+1,d
=ext_buffer
; (*d
=tolower(*s
)); s
++)
2594 for(p
=executable_extensions
; (*p
)[0]; p
++)
2595 if (!lstrcmpiW(ext_buffer
, *p
))
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
))
2610 static enum FILE_TYPE
get_file_type(LPCWSTR filename
)
2612 LPCWSTR ext
= wcsrchr(filename
, '.');
2616 if (is_exe_file(ext
))
2617 return FT_EXECUTABLE
;
2618 else if (is_registered_type(ext
))
2625 static void draw_item(Pane
* pane
, LPDRAWITEMSTRUCT dis
, Entry
* entry
, int calcWidthCol
)
2627 WCHAR buffer
[BUFFER_LEN
];
2629 int visible_cols
= pane
->visible_cols
;
2630 COLORREF bkcolor
, textcolor
;
2631 RECT focusRect
= dis
->rcItem
;
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
;
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
;
2662 if (pane
->treePane
) {
2664 img_pos
= dis
->rcItem
.left
+ entry
->level
*(IMAGE_WIDTH
+TREE_LINE_DX
);
2666 if (calcWidthCol
== -1) {
2668 int y
= dis
->rcItem
.top
+ IMAGE_HEIGHT
/2;
2671 HRGN hrgn_org
= CreateRectRgn(0, 0, 0, 0);
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
);
2686 ExtSelectClipRgn(dis
->hDC
, hrgn
, RGN_AND
);
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;
2696 x
-= IMAGE_WIDTH
+TREE_LINE_DX
;
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
);
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
;
2725 img_pos
= dis
->rcItem
.left
;
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
;
2740 textcolor
= RGB(0,0,0);
2742 if (dis
->itemState
& ODS_FOCUS
) {
2743 textcolor
= RGB(255,255,255);
2744 bkcolor
= COLOR_SELECTION
;
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
)
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
);
2765 ImageList_DrawEx(Globals
.himl
, img
, dis
->hDC
,
2766 img_pos
, dis
->rcItem
.top
, cx
,
2767 IMAGE_HEIGHT
, bkcolor
, CLR_DEFAULT
, ILD_NORMAL
);
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
);
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 */
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
);
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
);
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
);
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
);
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
);
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
);
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';
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
);
2882 static void set_header(Pane
* pane
)
2885 int scroll_pos
= GetScrollPos(pane
->hwnd
, SB_HORZ
);
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
) {
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
];
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
);
2926 rt_scr
.left
= pane
->positions
[idx
+1]-scroll_pos
;
2928 rt_scr
.right
= clnt
.right
;
2929 rt_scr
.bottom
= clnt
.bottom
;
2931 rt_clip
.left
= pane
->positions
[idx
]-scroll_pos
;
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
)
2955 case HDN_DIVIDERDBLCLICKW
: {
2956 LPNMHEADERW phdn
= (LPNMHEADERW
)pnmh
;
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
);
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 */
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
)
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
);
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
)
3022 if (!dir
|| dir
->expanded
|| !dir
->down
)
3027 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='\0' && p
->next
) {
3030 if (p
->data
.cFileName
[0]=='.' && p
->data
.cFileName
[1]=='.' &&
3031 p
->data
.cFileName
[2]=='\0' && p
->next
)
3035 /* no subdirectories ? */
3036 if (!(p
->data
.dwFileAttributes
&FILE_ATTRIBUTE_DIRECTORY
))
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
;
3058 static void collapse_entry(Pane
* pane
, Entry
* dir
)
3063 idx
= SendMessageW(pane
->hwnd
, LB_FINDSTRING
, 0, (LPARAM
)dir
);
3065 ShowWindow(pane
->hwnd
, SW_HIDE
);
3067 /* hide sub entries */
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
)
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
];
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
);
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
);
3119 if (SetCurrentDirectoryW(path
))
3124 static void refresh_child(ChildWnd
* child
)
3126 WCHAR path
[MAX_PATH
], drv
[_MAX_DRIVE
+1];
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
);
3141 entry
= read_tree(&child
->root
, NULL
, local_pidl
, drv
, child
->sortOrder
, child
->hwnd
);
3146 entry
= read_tree(&child
->root
, path
, NULL
, drv
, child
->sortOrder
, child
->hwnd
);
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
];
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
++;
3204 static void refresh_drives(void)
3208 /* destroy drive bar */
3209 DestroyWindow(Globals
.hdrivebar
);
3210 Globals
.hdrivebar
= 0;
3212 /* re-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());
3234 static BOOL
launch_entry(Entry
* entry
, HWND hwnd
, UINT nCmdShow
)
3236 WCHAR cmd
[MAX_PATH
];
3238 if (entry
->etype
== ET_SHELL
) {
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());
3258 if (shexinfo
.lpIDList
!= entry
->pidl
)
3259 IMalloc_Free(Globals
.iMalloc
, shexinfo
.lpIDList
);
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
;
3278 if (entry
->data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
3279 int scanned_old
= entry
->scanned
;
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')
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
);
3294 } else if (entry
->expanded
)
3295 collapse_entry(pane
, child
->left
.cur
);
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
);
3308 calc_widths(pane
, FALSE
);
3313 if (GetKeyState(VK_MENU
) < 0)
3314 show_properties_dlg(entry
, child
->hwnd
);
3316 launch_entry(entry
, child
->hwnd
, SW_SHOWNORMAL
);
3321 static BOOL
pane_command(Pane
* pane
, UINT cmd
)
3325 if (pane
->visible_cols
) {
3326 pane
->visible_cols
= 0;
3327 calc_widths(pane
, TRUE
);
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
);
3335 case ID_VIEW_ALL_ATTRIBUTES
:
3336 if (pane
->visible_cols
!= COL_ALL
) {
3337 pane
->visible_cols
= COL_ALL
;
3338 calc_widths(pane
, TRUE
);
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
);
3346 case ID_PREFERRED_SIZES
: {
3347 calc_widths(pane
, TRUE
);
3349 InvalidateRect(pane
->hwnd
, 0, TRUE
);
3352 /* TODO: more command ids... */
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
)
3386 return (target_attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
3389 static BOOL
prompt_target(Pane
* pane
, LPWSTR source
, LPWSTR target
)
3391 WCHAR path
[MAX_PATH
];
3394 get_path(pane
->cur
, path
);
3396 if (DialogBoxParamW(Globals
.hInstance
, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION
), pane
->hwnd
, DestinationDlgProc
, (LPARAM
)path
) != IDOK
)
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
);
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
);
3427 static IContextMenu2
* s_pctxmenu2
= NULL
;
3428 static IContextMenu3
* s_pctxmenu3
= NULL
;
3430 static void CtxMenu_reset(void)
3436 static IContextMenu
* CtxMenu_query_interfaces(IContextMenu
* pcm1
)
3438 IContextMenu
* pcm
= NULL
;
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
;
3448 IContextMenu_Release(pcm1
);
3454 static BOOL
CtxMenu_HandleMenuMsg(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
3457 if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3
, nmsg
, wparam
, lparam
)))
3462 if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2
, nmsg
, wparam
, lparam
)))
3468 static HRESULT
ShellFolderContextMenu(IShellFolder
* shell_folder
, HWND hwndParent
, int cidl
, LPCITEMIDLIST
* apidl
, int x
, int y
)
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
);
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
);
3489 CMINVOKECOMMANDINFO cmi
;
3491 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
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
;
3501 hr
= IContextMenu_InvokeCommand(pcm
, &cmi
);
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
);
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);
3529 goto draw_menu_item
;
3534 InitChildWindow(child
);
3538 free_child_window(child
);
3539 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, 0);
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
);
3557 if (LOWORD(lparam
) == HTCLIENT
) {
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
));
3569 case WM_LBUTTONDOWN
: {
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
;
3583 if (GetCapture() == hwnd
)
3588 if (wparam
== VK_ESCAPE
)
3589 if (GetCapture() == hwnd
) {
3591 child
->split_pos
= last_split
;
3592 GetClientRect(hwnd
, &rt
);
3593 resize_tree(child
, rt
.right
, rt
.bottom
);
3596 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
3601 if (GetCapture() == hwnd
) {
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
);
3615 UpdateWindow(child
->right
.hwnd
);
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 */
3630 if (SetCurrentDirectoryW(child
->path
))
3632 SetFocus(child
->focus_pane
? child
->right
.hwnd
: child
->left
.hwnd
);
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
);
3649 refresh_child(child
);
3653 activate_entry(child
, pane
, hwnd
);
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
);
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
);
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
);
3696 case ID_VIEW_SORT_NAME
:
3697 set_sort_order(child
, SORT_NAME
);
3700 case ID_VIEW_SORT_TYPE
:
3701 set_sort_order(child
, SORT_EXT
);
3704 case ID_VIEW_SORT_SIZE
:
3705 set_sort_order(child
, SORT_SIZE
);
3708 case ID_VIEW_SORT_DATE
:
3709 set_sort_order(child
, SORT_DATE
);
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
);
3726 case ID_VIEW_SPLIT
: {
3727 last_split
= child
->split_pos
;
3731 case ID_EDIT_PROPERTIES
:
3732 show_properties_dlg(pane
->cur
, child
->hwnd
);
3736 return pane_command(pane
, LOWORD(wparam
));
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
);
3756 activate_entry(child
, pane
, hwnd
);
3762 NMHDR
* pnmh
= (NMHDR
*) lparam
;
3763 return pane_notify(pnmh
->idFrom
==IDW_HEADER_LEFT
? &child
->left
: &child
->right
, pnmh
);}
3765 case WM_CONTEXTMENU
: {
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);
3783 Entry
* entry
= (Entry
*)SendMessageW(pane
->hwnd
, LB_GETITEMDATA
, idx
, 0);
3785 LPITEMIDLIST pidl_abs
= get_to_absolute_pidl(entry
, hwnd
);
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
);
3804 case WM_MEASUREITEM
:
3806 if (!wparam
) /* Is the message menu-related? */
3807 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3812 case WM_INITMENUPOPUP
:
3813 if (CtxMenu_HandleMenuMsg(nmsg
, wparam
, lparam
))
3816 update_view_menu(child
);
3819 case WM_MENUCHAR
: /* only supported by IContextMenu3 */
3821 LRESULT lResult
= 0;
3823 IContextMenu3_HandleMenuMsg2(s_pctxmenu3
, nmsg
, wparam
, lparam
, &lResult
);
3831 if (wparam
!= SIZE_MINIMIZED
)
3832 resize_tree(child
, LOWORD(lparam
), HIWORD(lparam
));
3836 return DefMDIChildProcW(hwnd
, nmsg
, wparam
, lparam
);
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
);
3855 child
->focus_pane
= pane
==&child
->right
? 1: 0;
3856 SendMessageW(hwnd
, LB_SETSEL
, TRUE
, 1);
3857 /*TODO: check menu items */
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
;
3879 INITCOMMONCONTROLSEX icc
= {
3880 sizeof(INITCOMMONCONTROLSEX
),
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
);
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
);
3931 Globals
.hInstance
= hinstance
;
3934 CoGetMalloc(MEMCTX_TASK
, &Globals
.iMalloc
);
3935 SHGetDesktopFolder(&Globals
.iDesktop
);
3936 Globals
.cfStrFName
= RegisterClipboardFormatW(CFSTR_FILENAMEW
);
3938 /* load column strings */
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
];
3959 HMENU hMenuFrame
, hMenuWindow
;
3962 CLIENTCREATESTRUCT ccs
;
3964 if (Globals
.hMainWnd
)
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
,
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
);
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
);
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
);
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])
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
);
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
);
4075 static void ExitInstance(void)
4077 IShellFolder_Release(Globals
.iDesktop
);
4078 IMalloc_Release(Globals
.iMalloc
);
4081 DeleteObject(Globals
.hfont
);
4082 ImageList_Destroy(Globals
.himl
);
4085 int APIENTRY
wWinMain(HINSTANCE hinstance
, HINSTANCE previnstance
, LPWSTR cmdline
, int cmdshow
)
4089 InitInstance(hinstance
);
4091 if( !show_frame(0, cmdshow
, cmdline
) )
4097 while(GetMessageW(&msg
, 0, 0, 0)) {
4098 if (Globals
.hmdiclient
&& TranslateMDISysAccel(Globals
.hmdiclient
, &msg
))
4101 if (Globals
.hMainWnd
&& TranslateAcceleratorW(Globals
.hMainWnd
, Globals
.haccel
, &msg
))
4104 TranslateMessage(&msg
);
4105 DispatchMessageW(&msg
);